types.d.ts 5.1 KB

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