types.d.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /**
  2. * Some interface for clash api
  3. */
  4. interface IConfigData {
  5. port: number;
  6. mode: string;
  7. ipv6: boolean;
  8. "socket-port": number;
  9. "allow-lan": boolean;
  10. "log-level": string;
  11. "mixed-port": number;
  12. "redir-port": number;
  13. "socks-port": number;
  14. "tproxy-port": number;
  15. "external-controller": string;
  16. secret: string;
  17. }
  18. interface IRuleItem {
  19. type: string;
  20. payload: string;
  21. proxy: string;
  22. }
  23. interface IProxyItem {
  24. name: string;
  25. type: string;
  26. udp: boolean;
  27. history: {
  28. time: string;
  29. delay: number;
  30. }[];
  31. all?: string[];
  32. now?: string;
  33. provider?: string; // 记录是否来自provider
  34. }
  35. type IProxyGroupItem = Omit<IProxyItem, "all"> & {
  36. all: IProxyItem[];
  37. };
  38. interface IProviderItem {
  39. name: string;
  40. type: string;
  41. proxies: IProxyItem[];
  42. updatedAt: string;
  43. vehicleType: string;
  44. }
  45. interface ITrafficItem {
  46. up: number;
  47. down: number;
  48. }
  49. interface ILogItem {
  50. type: string;
  51. time?: string;
  52. payload: string;
  53. }
  54. interface IConnectionsItem {
  55. id: string;
  56. metadata: {
  57. network: string;
  58. type: string;
  59. host: string;
  60. sourceIP: string;
  61. sourcePort: string;
  62. destinationPort: string;
  63. destinationIP?: string;
  64. process?: string;
  65. processPath?: string;
  66. };
  67. upload: number;
  68. download: number;
  69. start: string;
  70. chains: string[];
  71. rule: string;
  72. rulePayload: string;
  73. curUpload?: number; // upload speed, calculate at runtime
  74. curDownload?: number; // download speed, calculate at runtime
  75. }
  76. interface IConnections {
  77. downloadTotal: number;
  78. uploadTotal: number;
  79. connections: IConnectionsItem[];
  80. }
  81. /**
  82. * Some interface for command
  83. */
  84. interface IClashInfo {
  85. // status: string;
  86. port?: number; // clash mixed port
  87. server?: string; // external-controller
  88. secret?: string;
  89. }
  90. interface IProfileItem {
  91. uid: string;
  92. type?: "local" | "remote" | "merge" | "script";
  93. name?: string;
  94. desc?: string;
  95. file?: string;
  96. url?: string;
  97. updated?: number;
  98. selected?: {
  99. name?: string;
  100. now?: string;
  101. }[];
  102. extra?: {
  103. upload: number;
  104. download: number;
  105. total: number;
  106. expire: number;
  107. };
  108. option?: IProfileOption;
  109. }
  110. interface IProfileOption {
  111. user_agent?: string;
  112. with_proxy?: boolean;
  113. self_proxy?: boolean;
  114. update_interval?: number;
  115. }
  116. interface IProfilesConfig {
  117. current?: string;
  118. chain?: string[];
  119. valid?: string[];
  120. items?: IProfileItem[];
  121. }
  122. interface IVergeConfig {
  123. language?: string;
  124. clash_core?: string;
  125. theme_mode?: "light" | "dark" | "system";
  126. theme_blur?: boolean;
  127. traffic_graph?: boolean;
  128. enable_tun_mode?: boolean;
  129. enable_auto_launch?: boolean;
  130. enable_service_mode?: boolean;
  131. enable_silent_start?: boolean;
  132. enable_system_proxy?: boolean;
  133. enable_proxy_guard?: boolean;
  134. proxy_guard_duration?: number;
  135. system_proxy_bypass?: string;
  136. web_ui_list?: string[];
  137. hotkeys?: string[];
  138. theme_setting?: {
  139. primary_color?: string;
  140. secondary_color?: string;
  141. primary_text?: string;
  142. secondary_text?: string;
  143. info_color?: string;
  144. error_color?: string;
  145. warning_color?: string;
  146. success_color?: string;
  147. font_family?: string;
  148. css_injection?: string;
  149. };
  150. auto_close_connection?: boolean;
  151. default_latency_test?: string;
  152. }
  153. type IClashConfigValue = any;
  154. interface IProfileMerge {
  155. // clash config fields (default supports)
  156. rules?: IClashConfigValue;
  157. proxies?: IClashConfigValue;
  158. "proxy-groups"?: IClashConfigValue;
  159. "proxy-providers"?: IClashConfigValue;
  160. "rule-providers"?: IClashConfigValue;
  161. // clash config fields (use flag)
  162. tun?: IClashConfigValue;
  163. dns?: IClashConfigValue;
  164. hosts?: IClashConfigValue;
  165. script?: IClashConfigValue;
  166. profile?: IClashConfigValue;
  167. payload?: IClashConfigValue;
  168. "interface-name"?: IClashConfigValue;
  169. "routing-mark"?: IClashConfigValue;
  170. // functional fields
  171. use?: string[];
  172. "prepend-rules"?: any[];
  173. "append-rules"?: any[];
  174. "prepend-proxies"?: any[];
  175. "append-proxies"?: any[];
  176. "prepend-proxy-groups"?: any[];
  177. "append-proxy-groups"?: any[];
  178. // fix
  179. ebpf?: any;
  180. experimental?: any;
  181. iptables?: any;
  182. sniffer?: any;
  183. authentication?: any;
  184. "bind-address"?: any;
  185. "external-ui"?: any;
  186. "auto-redir"?: any;
  187. "socks-port"?: any;
  188. "redir-port"?: any;
  189. "tproxy-port"?: any;
  190. "geodata-mode"?: any;
  191. "tcp-concurrent"?: any;
  192. }
  193. // partial of the clash config
  194. type IProfileData = Partial<{
  195. rules: any[];
  196. proxies: any[];
  197. "proxy-groups": any[];
  198. "proxy-providers": any[];
  199. "rule-providers": any[];
  200. [k: string]: any;
  201. }>;
  202. interface IChainItem {
  203. item: IProfileItem;
  204. merge?: IProfileMerge;
  205. script?: string;
  206. }
  207. interface IEnhancedPayload {
  208. chain: IChainItem[];
  209. valid: string[];
  210. current: IProfileData;
  211. callback: string;
  212. }
  213. interface IEnhancedResult {
  214. data: IProfileData;
  215. status: string;
  216. error?: string;
  217. }