omnicell-router 0.7.0 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (246) hide show
  1. package/backend/dist/cli/clients/activity.d.ts +35 -0
  2. package/backend/dist/cli/clients/activity.js +67 -0
  3. package/backend/dist/cli/clients/base.d.ts +13 -2
  4. package/backend/dist/cli/clients/claude.d.ts +2 -2
  5. package/backend/dist/cli/clients/codex.d.ts +2 -2
  6. package/backend/dist/cli/clients/core-adapters.d.ts +3 -4
  7. package/backend/dist/cli/clients/core-adapters.js +3 -4
  8. package/backend/dist/cli/clients/cursor-proxy.d.ts +88 -0
  9. package/backend/dist/cli/clients/cursor-proxy.js +421 -0
  10. package/backend/dist/cli/clients/dsh.d.ts +2 -2
  11. package/backend/dist/cli/clients/grok.d.ts +2 -2
  12. package/backend/dist/cli/clients/index.d.ts +8 -1
  13. package/backend/dist/cli/clients/index.js +55 -21
  14. package/backend/dist/cli/clients/kimi.d.ts +2 -2
  15. package/backend/dist/cli/clients/launcher.d.ts +8 -0
  16. package/backend/dist/cli/clients/model-meta.js +1 -1
  17. package/backend/dist/cli/clients/omp.d.ts +2 -2
  18. package/backend/dist/cli/clients/openclaw.d.ts +2 -2
  19. package/backend/dist/cli/clients/opencode-proxy.d.ts +11 -0
  20. package/backend/dist/cli/clients/opencode-proxy.js +351 -0
  21. package/backend/dist/cli/clients/opencode.d.ts +2 -2
  22. package/backend/dist/cli/clients/pi.d.ts +2 -2
  23. package/backend/dist/cli/clients/plugin-adapters.d.ts +3 -1
  24. package/backend/dist/cli/clients/plugin-adapters.js +6 -29
  25. package/backend/dist/cli/clients/qoder-proxy.d.ts +84 -0
  26. package/backend/dist/cli/clients/qoder-proxy.js +497 -0
  27. package/backend/dist/cli/clients/reserved.d.ts +2 -6
  28. package/backend/dist/cli/clients/reserved.js +2 -0
  29. package/backend/dist/cli/clients/workbuddy.d.ts +2 -2
  30. package/backend/dist/cli/index.js +60 -9
  31. package/backend/dist/cli/types.d.ts +29 -8
  32. package/backend/dist/compression/caveman-prompts.d.ts +1 -1
  33. package/backend/dist/config/comments-en.js +6 -12
  34. package/backend/dist/config/comments-zh.js +6 -12
  35. package/backend/dist/config/defaults.d.ts +56 -1
  36. package/backend/dist/config/defaults.js +68 -0
  37. package/backend/dist/config/index.d.ts +9 -2
  38. package/backend/dist/config/index.js +26 -3
  39. package/backend/dist/config/types.d.ts +55 -43
  40. package/backend/dist/forward-proxy/egress.d.ts +10 -2
  41. package/backend/dist/forward-proxy/egress.js +42 -4
  42. package/backend/dist/forward-proxy/ordered-relay.d.ts +29 -0
  43. package/backend/dist/forward-proxy/ordered-relay.js +46 -0
  44. package/backend/dist/forward-proxy/rules.d.ts +66 -19
  45. package/backend/dist/forward-proxy/rules.js +61 -14
  46. package/backend/dist/forward-proxy/server.js +226 -77
  47. package/backend/dist/forward-proxy/system-proxy.d.ts +42 -2
  48. package/backend/dist/forward-proxy/system-proxy.js +199 -22
  49. package/backend/dist/harness/common/market.d.ts +3 -3
  50. package/backend/dist/harness/host/adapters/amp.d.ts +1 -1
  51. package/backend/dist/harness/host/adapters/antigravity.d.ts +1 -1
  52. package/backend/dist/harness/host/adapters/claude.d.ts +1 -1
  53. package/backend/dist/harness/host/adapters/cline.d.ts +1 -1
  54. package/backend/dist/harness/host/adapters/codex.d.ts +1 -1
  55. package/backend/dist/harness/host/adapters/cursor.d.ts +1 -1
  56. package/backend/dist/harness/host/adapters/dsh.d.ts +2 -2
  57. package/backend/dist/harness/host/adapters/factory.d.ts +1 -1
  58. package/backend/dist/harness/host/adapters/gemini-cli.d.ts +1 -1
  59. package/backend/dist/harness/host/adapters/grok.d.ts +1 -1
  60. package/backend/dist/harness/host/adapters/kimi.d.ts +1 -1
  61. package/backend/dist/harness/host/adapters/omp.d.ts +1 -1
  62. package/backend/dist/harness/host/adapters/openclaw.d.ts +1 -1
  63. package/backend/dist/harness/host/adapters/opencode.d.ts +1 -1
  64. package/backend/dist/harness/host/adapters/pi.d.ts +1 -1
  65. package/backend/dist/harness/host/adapters/universal.d.ts +1 -1
  66. package/backend/dist/harness/host/adapters/windsurf.d.ts +1 -1
  67. package/backend/dist/harness/host/adapters/zed.d.ts +1 -1
  68. package/backend/dist/harness/skill/skills-sh.d.ts +1 -1
  69. package/backend/dist/harness/translation.js +64 -21
  70. package/backend/dist/harness/types.d.ts +1 -1
  71. package/backend/dist/harness/types.js +1 -1
  72. package/backend/dist/index.js +31 -18
  73. package/backend/dist/ir/adapters/anthropic-stream.d.ts +18 -0
  74. package/backend/dist/ir/adapters/anthropic-stream.js +247 -0
  75. package/backend/dist/ir/adapters/anthropic.d.ts +29 -0
  76. package/backend/dist/ir/adapters/anthropic.js +788 -0
  77. package/backend/dist/ir/adapters/chat.d.ts +15 -0
  78. package/backend/dist/ir/adapters/chat.js +602 -0
  79. package/backend/dist/ir/adapters/google-stream.d.ts +22 -0
  80. package/backend/dist/ir/adapters/google-stream.js +242 -0
  81. package/backend/dist/ir/adapters/google.d.ts +9 -0
  82. package/backend/dist/ir/adapters/google.js +317 -0
  83. package/backend/dist/ir/adapters/openai-responses-output.js +8 -5
  84. package/backend/dist/ir/adapters/openai-responses.d.ts +15 -0
  85. package/backend/dist/ir/adapters/openai-responses.js +26 -1
  86. package/backend/dist/ir/adapters/responses-output.d.ts +50 -0
  87. package/backend/dist/ir/adapters/responses-output.js +348 -0
  88. package/backend/dist/ir/adapters/responses-stream.d.ts +12 -0
  89. package/backend/dist/ir/adapters/responses-stream.js +178 -0
  90. package/backend/dist/ir/adapters/responses.d.ts +14 -0
  91. package/backend/dist/ir/adapters/responses.js +646 -0
  92. package/backend/dist/ir/errors.d.ts +2 -2
  93. package/backend/dist/ir/types.d.ts +2 -1
  94. package/backend/dist/metrics/request-cost.d.ts +11 -2
  95. package/backend/dist/metrics/request-cost.js +12 -3
  96. package/backend/dist/observability/request-identity.d.ts +1 -1
  97. package/backend/dist/observability/trace-id.d.ts +40 -0
  98. package/backend/dist/observability/trace-id.js +134 -0
  99. package/backend/dist/observability/upstream-events.d.ts +82 -60
  100. package/backend/dist/observability/upstream-events.js +142 -67
  101. package/backend/dist/opencode/catalog/types.d.ts +9 -0
  102. package/backend/dist/opencode/credentials/types.d.ts +2 -2
  103. package/backend/dist/opencode/probe.d.ts +24 -1
  104. package/backend/dist/opencode/probe.js +28 -4
  105. package/backend/dist/opencode/user-config.d.ts +5 -0
  106. package/backend/dist/pipeline/directives.d.ts +6 -2
  107. package/backend/dist/pipeline/directives.js +7 -3
  108. package/backend/dist/pipeline/orchestrator.d.ts +28 -27
  109. package/backend/dist/pipeline/orchestrator.js +220 -194
  110. package/backend/dist/pipeline/unresolved-model.d.ts +33 -0
  111. package/backend/dist/pipeline/unresolved-model.js +43 -0
  112. package/backend/dist/plugins/catalog-def.d.ts +143 -0
  113. package/backend/dist/plugins/catalog-def.js +177 -0
  114. package/backend/dist/plugins/gateways.d.ts +62 -3
  115. package/backend/dist/plugins/gateways.js +139 -2
  116. package/backend/dist/plugins/host.d.ts +42 -5
  117. package/backend/dist/plugins/host.js +454 -38
  118. package/backend/dist/plugins/manifest.d.ts +119 -10
  119. package/backend/dist/plugins/manifest.js +265 -14
  120. package/backend/dist/plugins/pack.js +26 -0
  121. package/backend/dist/plugins/types.d.ts +187 -21
  122. package/backend/dist/protocols/systemone/convert.d.ts +1 -0
  123. package/backend/dist/protocols/systemone/convert.js +6 -1
  124. package/backend/dist/protocols/systemone/decide.js +18 -8
  125. package/backend/dist/providers/anthropic-messages.d.ts +12 -0
  126. package/backend/dist/providers/anthropic-messages.js +53 -0
  127. package/backend/dist/providers/anthropic.d.ts +7 -8
  128. package/backend/dist/providers/anthropic.js +36 -324
  129. package/backend/dist/providers/base.d.ts +14 -2
  130. package/backend/dist/providers/boot-direct.js +68 -38
  131. package/backend/dist/providers/dispatch.d.ts +5 -19
  132. package/backend/dist/providers/dispatch.js +46 -58
  133. package/backend/dist/providers/executors/anthropic-messages.d.ts +1 -0
  134. package/backend/dist/providers/executors/anthropic-messages.js +3 -0
  135. package/backend/dist/providers/executors/dispatch.d.ts +16 -2
  136. package/backend/dist/providers/executors/dispatch.js +39 -9
  137. package/backend/dist/providers/executors/google-gemini.d.ts +1 -0
  138. package/backend/dist/providers/executors/google-gemini.js +3 -0
  139. package/backend/dist/providers/executors/http-stream.js +16 -3
  140. package/backend/dist/providers/executors/openai-chat.d.ts +1 -0
  141. package/backend/dist/providers/executors/openai-chat.js +3 -0
  142. package/backend/dist/providers/executors/openai-responses.d.ts +1 -0
  143. package/backend/dist/providers/executors/openai-responses.js +3 -0
  144. package/backend/dist/providers/executors/plugin-adapter.js +4 -4
  145. package/backend/dist/providers/google-gemini.d.ts +12 -0
  146. package/backend/dist/providers/google-gemini.js +50 -0
  147. package/backend/dist/providers/google.d.ts +7 -8
  148. package/backend/dist/providers/google.js +35 -308
  149. package/backend/dist/providers/http-json.d.ts +19 -0
  150. package/backend/dist/providers/http-json.js +104 -0
  151. package/backend/dist/providers/http-stream.d.ts +52 -0
  152. package/backend/dist/providers/http-stream.js +423 -0
  153. package/backend/dist/providers/member-match.d.ts +4 -5
  154. package/backend/dist/providers/member-match.js +4 -5
  155. package/backend/dist/providers/openai-chat.d.ts +13 -0
  156. package/backend/dist/providers/openai-chat.js +99 -0
  157. package/backend/dist/providers/openai-compatible.d.ts +7 -4
  158. package/backend/dist/providers/openai-compatible.js +71 -368
  159. package/backend/dist/providers/openai-responses.d.ts +12 -0
  160. package/backend/dist/providers/openai-responses.js +68 -0
  161. package/backend/dist/providers/opencode-proxy.d.ts +5 -5
  162. package/backend/dist/providers/opencode-proxy.js +49 -125
  163. package/backend/dist/providers/plugin-adapter.d.ts +9 -0
  164. package/backend/dist/providers/plugin-adapter.js +31 -0
  165. package/backend/dist/providers/registry.d.ts +49 -24
  166. package/backend/dist/providers/registry.js +97 -55
  167. package/backend/dist/providers/responses.d.ts +7 -28
  168. package/backend/dist/providers/responses.js +45 -253
  169. package/backend/dist/providers/tool-markup-leak.d.ts +41 -0
  170. package/backend/dist/providers/tool-markup-leak.js +57 -0
  171. package/backend/dist/providers/tool-markup-recovery.d.ts +27 -0
  172. package/backend/dist/providers/tool-markup-recovery.js +786 -0
  173. package/backend/dist/providers/virtual-meta.d.ts +21 -2
  174. package/backend/dist/providers/virtual-meta.js +49 -9
  175. package/backend/dist/proxy/asset-download.d.ts +54 -0
  176. package/backend/dist/proxy/asset-download.js +420 -0
  177. package/backend/dist/proxy/manual-node-spec.d.ts +16 -16
  178. package/backend/dist/proxy/mihomo-binary.d.ts +17 -2
  179. package/backend/dist/proxy/mihomo-binary.js +62 -51
  180. package/backend/dist/proxy/mihomo-client.js +15 -1
  181. package/backend/dist/proxy/mihomo-config.js +11 -2
  182. package/backend/dist/proxy/mihomo-geo.d.ts +87 -0
  183. package/backend/dist/proxy/mihomo-geo.js +213 -0
  184. package/backend/dist/proxy/mihomo-logs.d.ts +27 -0
  185. package/backend/dist/proxy/mihomo-logs.js +70 -0
  186. package/backend/dist/proxy/mihomo-pac.d.ts +11 -0
  187. package/backend/dist/proxy/mihomo-pac.js +15 -0
  188. package/backend/dist/proxy/mihomo-rules-import.d.ts +1 -1
  189. package/backend/dist/proxy/mihomo-rules-import.js +7 -7
  190. package/backend/dist/proxy/mihomo-sidecar.d.ts +17 -1
  191. package/backend/dist/proxy/mihomo-sidecar.js +148 -26
  192. package/backend/dist/quota/adapters/minimax.js +36 -13
  193. package/backend/dist/quota/cli-login.d.ts +8 -0
  194. package/backend/dist/quota/cli-login.js +18 -0
  195. package/backend/dist/quota/declarations.js +10 -0
  196. package/backend/dist/quota/dsl.js +18 -5
  197. package/backend/dist/quota/engine.d.ts +22 -1
  198. package/backend/dist/quota/engine.js +170 -29
  199. package/backend/dist/quota/prober.d.ts +5 -0
  200. package/backend/dist/quota/prober.js +11 -2
  201. package/backend/dist/quota/types.d.ts +87 -8
  202. package/backend/dist/quota/verdict.d.ts +35 -0
  203. package/backend/dist/quota/verdict.js +135 -0
  204. package/backend/dist/ratelimit/admission.d.ts +131 -0
  205. package/backend/dist/ratelimit/admission.js +233 -0
  206. package/backend/dist/ratelimit/rate-limiter.js +6 -0
  207. package/backend/dist/resilience/types.d.ts +2 -2
  208. package/backend/dist/router/layer2-decision.d.ts +1 -1
  209. package/backend/dist/router/layer2-decision.js +5 -8
  210. package/backend/dist/routes/console.js +248 -52
  211. package/backend/dist/routes/mihomo.d.ts +2 -0
  212. package/backend/dist/routes/mihomo.js +334 -29
  213. package/backend/dist/routes/responses.d.ts +87 -8
  214. package/backend/dist/routes/responses.js +314 -33
  215. package/backend/dist/server.js +34 -6
  216. package/backend/dist/session/session-manager.d.ts +6 -0
  217. package/backend/dist/session/session-manager.js +20 -9
  218. package/backend/dist/surfaces/chat-pipeline.d.ts +2 -2
  219. package/backend/dist/surfaces/chat-pipeline.js +17 -7
  220. package/backend/dist/surfaces/chat.js +15 -0
  221. package/backend/dist/surfaces/decision-pipeline.js +7 -10
  222. package/backend/dist/surfaces/direct-forward.d.ts +3 -0
  223. package/backend/dist/surfaces/direct-forward.js +206 -0
  224. package/backend/dist/surfaces/rate-limit-response.d.ts +17 -0
  225. package/backend/dist/surfaces/rate-limit-response.js +57 -0
  226. package/backend/dist/surfaces/types.d.ts +11 -0
  227. package/backend/dist/trace/tracker.d.ts +32 -1
  228. package/backend/dist/trace/tracker.js +29 -4
  229. package/backend/dist/types/router.d.ts +34 -12
  230. package/backend/dist/types/router.js +35 -6
  231. package/backend/dist/utils/chat-stream.d.ts +21 -8
  232. package/backend/dist/utils/chat-stream.js +46 -9
  233. package/backend/dist/utils/event-ring.d.ts +4 -0
  234. package/backend/dist/utils/event-ring.js +4 -0
  235. package/backend/dist/utils/popularity.js +29 -4
  236. package/backend/dist/utils/proxy.d.ts +7 -0
  237. package/backend/dist/utils/proxy.js +35 -10
  238. package/backend/dist/utils/retry-after.d.ts +21 -0
  239. package/backend/dist/utils/retry-after.js +36 -0
  240. package/bin/ocr.js +2 -2
  241. package/frontend/dist/assets/index-55VVwfFQ.js +1521 -0
  242. package/frontend/dist/assets/{index-CQSLGFTV.css → index-DxZ9MHKB.css} +1 -1
  243. package/frontend/dist/assets/workbuddy.color-DOMpQkxJ.svg +29 -0
  244. package/frontend/dist/index.html +2 -2
  245. package/package.json +1 -1
  246. package/frontend/dist/assets/index-CLvxJjp_.js +0 -1476
@@ -12,16 +12,16 @@
12
12
  */
13
13
  import type { MihomoManualNode } from '../config/types.js';
14
14
  /** Protocol whitelist. Order is the console's dropdown order. */
15
- export declare const MANUAL_NODE_PROTOCOLS: readonly ['ss', 'vmess', 'vless', 'trojan', 'hysteria2', 'http', 'socks5'];
15
+ export declare const MANUAL_NODE_PROTOCOLS: readonly ["ss", "vmess", "vless", "trojan", "hysteria2", "http", "socks5"];
16
16
  export type ManualNodeProtocol = typeof MANUAL_NODE_PROTOCOLS[number];
17
- export declare const MANUAL_NODE_SS_CIPHERS: readonly ['aes-128-gcm', 'aes-192-gcm', 'aes-256-gcm', 'chacha20-ietf-poly1305', 'xchacha20-ietf-poly1305', '2022-blake3-aes-128-gcm', '2022-blake3-aes-256-gcm', '2022-blake3-chacha20-poly1305'];
18
- export declare const MANUAL_NODE_VMESS_CIPHERS: readonly ['auto', 'aes-128-gcm', 'chacha20-poly1305', 'none'];
19
- export declare const MANUAL_NODE_NETWORKS: readonly ['tcp', 'ws', 'grpc', 'h2'];
20
- export declare const MANUAL_NODE_FINGERPRINTS: readonly ['chrome', 'firefox', 'safari', 'ios', 'android', 'edge', '360', 'qq', 'random', 'randomized'];
21
- export declare const MANUAL_NODE_SS_PLUGINS: readonly ['obfs', 'v2ray-plugin'];
22
- export declare const MANUAL_NODE_OBFS_MODES: readonly ['http', 'tls'];
23
- export declare const MANUAL_NODE_IP_VERSIONS: readonly ['dual', 'ipv4', 'ipv6', 'ipv4-prefer', 'ipv6-prefer'];
24
- export declare const MANUAL_NODE_OBFS_TYPES: readonly ['salamander'];
17
+ export declare const MANUAL_NODE_SS_CIPHERS: readonly ["aes-128-gcm", "aes-192-gcm", "aes-256-gcm", "chacha20-ietf-poly1305", "xchacha20-ietf-poly1305", "2022-blake3-aes-128-gcm", "2022-blake3-aes-256-gcm", "2022-blake3-chacha20-poly1305"];
18
+ export declare const MANUAL_NODE_VMESS_CIPHERS: readonly ["auto", "aes-128-gcm", "chacha20-poly1305", "none"];
19
+ export declare const MANUAL_NODE_NETWORKS: readonly ["tcp", "ws", "grpc", "h2"];
20
+ export declare const MANUAL_NODE_FINGERPRINTS: readonly ["chrome", "firefox", "safari", "ios", "android", "edge", "360", "qq", "random", "randomized"];
21
+ export declare const MANUAL_NODE_SS_PLUGINS: readonly ["obfs", "v2ray-plugin"];
22
+ export declare const MANUAL_NODE_OBFS_MODES: readonly ["http", "tls"];
23
+ export declare const MANUAL_NODE_IP_VERSIONS: readonly ["dual", "ipv4", "ipv6", "ipv4-prefer", "ipv6-prefer"];
24
+ export declare const MANUAL_NODE_OBFS_TYPES: readonly ["salamander"];
25
25
  type Kind = 'text' | 'host' | 'uuid' | 'bool' | 'int' | 'enum' | 'alpn';
26
26
  export interface ManualNodeFieldSpec {
27
27
  key: keyof MihomoManualNode;
@@ -47,7 +47,7 @@ export declare const MANUAL_NODE_FIELDS: Record<ManualNodeProtocol, readonly (ke
47
47
  export declare function isManualNodeProtocol(type: string): type is ManualNodeProtocol;
48
48
  export declare function manualNodeFieldsFor(type: string): readonly (keyof MihomoManualNode)[];
49
49
  /** Mapping keys the form owns, for the overlay's clear-a-field path. */
50
- export declare const MANUAL_NODE_FORM_KEYS: readonly ['name', 'type', 'server', 'port', 'cipher', 'vmessCipher', 'password', 'username', 'uuid', 'alterId', 'network', 'ws-opts', 'grpc-opts', 'h2-opts', 'tls', 'servername', 'sni', 'flow', 'reality-opts', 'alpn', 'client-fingerprint', 'skip-cert-verify', 'udp', 'tfo', 'ip-version', 'plugin', 'plugin-opts', 'obfs', 'obfs-password', 'up', 'down', 'ports'];
50
+ export declare const MANUAL_NODE_FORM_KEYS: readonly ["name", "type", "server", "port", "cipher", "vmessCipher", "password", "username", "uuid", "alterId", "network", "ws-opts", "grpc-opts", "h2-opts", "tls", "servername", "sni", "flow", "reality-opts", "alpn", "client-fingerprint", "skip-cert-verify", "udp", "tfo", "ip-version", "plugin", "plugin-opts", "obfs", "obfs-password", "up", "down", "ports"];
51
51
  /**
52
52
  * Coerce + validate one typed draft. Returns null when the row must be
53
53
  * rejected; `errorField` names the offending field for the API's 400.
@@ -74,18 +74,18 @@ export declare function manualNodeFields(mapping: Record<string, unknown>): Part
74
74
  export declare function missingNodeCredential(mapping: Record<string, unknown>): string | null;
75
75
  /** Protocol + enum catalogs, so the console never mirrors a whitelist. */
76
76
  export declare function manualNodeCatalog(): {
77
- protocols: ("http" | "hysteria2" | "socks5" | "ss" | "trojan" | "vless" | "vmess")[];
77
+ protocols: ("http" | "ss" | "vmess" | "vless" | "trojan" | "hysteria2" | "socks5")[];
78
78
  fields: {
79
79
  [k: string]: readonly (keyof MihomoManualNode)[];
80
80
  };
81
81
  enums: {
82
- ssCiphers: ("2022-blake3-aes-128-gcm" | "2022-blake3-aes-256-gcm" | "2022-blake3-chacha20-poly1305" | "aes-128-gcm" | "aes-192-gcm" | "aes-256-gcm" | "chacha20-ietf-poly1305" | "xchacha20-ietf-poly1305")[];
83
- vmessCiphers: ("aes-128-gcm" | "auto" | "chacha20-poly1305" | "none")[];
84
- networks: ("grpc" | "h2" | "tcp" | "ws")[];
85
- fingerprints: ("360" | "android" | "chrome" | "edge" | "firefox" | "ios" | "qq" | "random" | "randomized" | "safari")[];
82
+ ssCiphers: ("aes-128-gcm" | "aes-192-gcm" | "aes-256-gcm" | "chacha20-ietf-poly1305" | "xchacha20-ietf-poly1305" | "2022-blake3-aes-128-gcm" | "2022-blake3-aes-256-gcm" | "2022-blake3-chacha20-poly1305")[];
83
+ vmessCiphers: ("none" | "auto" | "aes-128-gcm" | "chacha20-poly1305")[];
84
+ networks: ("h2" | "tcp" | "ws" | "grpc")[];
85
+ fingerprints: ("android" | "chrome" | "firefox" | "safari" | "ios" | "edge" | "360" | "qq" | "random" | "randomized")[];
86
86
  ssPlugins: ("obfs" | "v2ray-plugin")[];
87
87
  obfsModes: ("http" | "tls")[];
88
- ipVersions: ("dual" | "ipv4" | "ipv4-prefer" | "ipv6" | "ipv6-prefer")[];
88
+ ipVersions: ("dual" | "ipv4" | "ipv6" | "ipv4-prefer" | "ipv6-prefer")[];
89
89
  obfsTypes: "salamander"[];
90
90
  };
91
91
  };
@@ -25,9 +25,14 @@ export interface InstallMihomoOptions {
25
25
  fetchImpl?: typeof fetch;
26
26
  platform?: NodeJS.Platform;
27
27
  arch?: string;
28
- /** Download progress in bytes. `total` is 0 when the host sends no
29
- * Content-Length (GitHub's object host usually does). */
28
+ /** Download progress in bytes of the WHOLE asset, so a resumed run starts off
29
+ * the origin. `total` is 0 when the host sends no Content-Length (GitHub's
30
+ * object host usually does). */
30
31
  onProgress?: (downloaded: number, total: number) => void;
32
+ /** Cancels the lookup and the transfer. The downloaded prefix is KEPT, so the
33
+ * next attempt continues (ADR-0022) — cancelling an install is a pause, not
34
+ * a restart. */
35
+ signal?: AbortSignal;
31
36
  }
32
37
  export interface InstallMihomoResult {
33
38
  ok: boolean;
@@ -35,5 +40,15 @@ export interface InstallMihomoResult {
35
40
  version?: string;
36
41
  error?: string;
37
42
  code?: string;
43
+ /** Bytes reused from an interrupted transfer instead of refetched. */
44
+ resumedFrom?: number;
45
+ /** True when the published asset digest was checked over the downloaded file. */
46
+ verified?: boolean;
38
47
  }
48
+ /**
49
+ * Install the Clash core binary (ADR-0022). Serialised per destination: the
50
+ * release lookup, the download, the unpack and the rename are ONE critical
51
+ * section, so two clicks (or two console tabs) cannot interleave writes into the
52
+ * same staging file and rename a half-written binary into place.
53
+ */
39
54
  export declare function installMihomoBinary(opts?: InstallMihomoOptions): Promise<InstallMihomoResult>;
@@ -9,7 +9,11 @@
9
9
  *
10
10
  * The downloader fetches a MetaCubeX/mihomo GitHub release asset that matches
11
11
  * OS/arch, unpacks gzip (unix) or zip (windows), and installs it under
12
- * `<ocrHome>/bin`. `fetchImpl` is injectable so tests never touch the network.
12
+ * `<ocrHome>/bin`. The asset streams into a sidecar-backed `.part` file, so an
13
+ * interrupted transfer continues where it stopped instead of starting over, and
14
+ * a published `sha256` is verified before anything is unpacked
15
+ * (see `proxy/asset-download.ts`). `fetchImpl` is injectable so tests never
16
+ * touch the network.
13
17
  */
14
18
  import fs from 'node:fs';
15
19
  import path from 'node:path';
@@ -18,6 +22,7 @@ import { unzipSync } from 'fflate';
18
22
  import { githubHeaders } from '../harness/common/github.js';
19
23
  import { getOcrHomeDir } from '../cli/paths.js';
20
24
  import { renameWithRetry } from '../utils/atomic-write.js';
25
+ import { assetPartPaths, cleanupAssetPart, downloadAssetToFile, parseAssetDigest, withAssetLock, } from './asset-download.js';
21
26
  const RELEASE_API = 'https://api.github.com/repos/MetaCubeX/mihomo/releases';
22
27
  /** Unauthenticated api.github.com is capped at 60 requests/hour (403 past the cap).
23
28
  * The release page redirect carries the same tag without the API quota, so it is
@@ -108,11 +113,12 @@ function unpack(buf, gzip) {
108
113
  * `redirect: 'manual'` exposes the 3xx Location; a runtime that followed the
109
114
  * redirect anyway leaves the tag in the final page's HTML.
110
115
  */
111
- async function resolveTagFromReleasePage(fetchImpl) {
116
+ async function resolveTagFromReleasePage(fetchImpl, signal) {
112
117
  try {
113
118
  const res = await fetchImpl(LATEST_RELEASE_PAGE, {
114
119
  headers: { 'User-Agent': USER_AGENT },
115
120
  redirect: 'manual',
121
+ ...(signal ? { signal } : {}),
116
122
  });
117
123
  const fromLocation = (res.headers.get('location') || '').match(/\/releases\/tag\/([^/?#]+)/);
118
124
  if (fromLocation)
@@ -129,7 +135,17 @@ async function resolveTagFromReleasePage(fetchImpl) {
129
135
  }
130
136
  return null;
131
137
  }
138
+ /**
139
+ * Install the Clash core binary (ADR-0022). Serialised per destination: the
140
+ * release lookup, the download, the unpack and the rename are ONE critical
141
+ * section, so two clicks (or two console tabs) cannot interleave writes into the
142
+ * same staging file and rename a half-written binary into place.
143
+ */
132
144
  export async function installMihomoBinary(opts = {}) {
145
+ const dest = opts.destPath ?? defaultMihomoBinaryPath(opts.platform ?? process.platform);
146
+ return withAssetLock(dest, () => installUnlocked(opts, dest));
147
+ }
148
+ async function installUnlocked(opts, dest) {
133
149
  const fetchImpl = opts.fetchImpl ?? fetchOverride ?? fetch;
134
150
  const platform = opts.platform ?? process.platform;
135
151
  const arch = opts.arch ?? process.arch;
@@ -143,7 +159,7 @@ export async function installMihomoBinary(opts = {}) {
143
159
  error: 'Clash core release lookup failed',
144
160
  };
145
161
  try {
146
- const res = await fetchImpl(api, { headers: githubHeaders() });
162
+ const res = await fetchImpl(api, { headers: githubHeaders(), ...(opts.signal ? { signal: opts.signal } : {}) });
147
163
  if (res.ok) {
148
164
  release = (await res.json());
149
165
  }
@@ -163,6 +179,7 @@ export async function installMihomoBinary(opts = {}) {
163
179
  let version = '';
164
180
  let wanted = null;
165
181
  let downloadUrl = '';
182
+ let assetDigest;
166
183
  if (release) {
167
184
  version = typeof release.tag_name === 'string' && release.tag_name.trim() ? release.tag_name.trim() : tag;
168
185
  if (!version)
@@ -171,9 +188,13 @@ export async function installMihomoBinary(opts = {}) {
171
188
  if (!wanted) {
172
189
  return { ok: false, code: 'unsupported-platform', error: `no Clash core build for ${platform}/${arch}` };
173
190
  }
174
- const assets = Array.isArray(release.assets) ? release.assets : [];
191
+ const assets = Array.isArray(release.assets)
192
+ ? release.assets
193
+ : [];
175
194
  const asset = assets.find((item) => item.name === wanted.name);
176
195
  downloadUrl = asset && typeof asset.browser_download_url === 'string' ? asset.browser_download_url : '';
196
+ // GitHub publishes the asset digest; the page-derived URL below has none.
197
+ assetDigest = parseAssetDigest(asset?.digest);
177
198
  if (!downloadUrl) {
178
199
  return { ok: false, code: 'asset-missing', error: `release ${version} has no ${wanted.name}` };
179
200
  }
@@ -181,7 +202,7 @@ export async function installMihomoBinary(opts = {}) {
181
202
  else {
182
203
  // API refused: take the tag from the release page and build the canonical
183
204
  // download URL — the asset spelling is derived from the tag, not listed.
184
- version = tag || (await resolveTagFromReleasePage(fetchImpl)) || '';
205
+ version = tag || (await resolveTagFromReleasePage(fetchImpl, opts.signal)) || '';
185
206
  if (!version)
186
207
  return lookupFailure;
187
208
  wanted = mihomoAssetName(platform, arch, version);
@@ -190,65 +211,49 @@ export async function installMihomoBinary(opts = {}) {
190
211
  }
191
212
  downloadUrl = `${DOWNLOAD_BASE}/${encodeURIComponent(version)}/${encodeURIComponent(wanted.name)}`;
192
213
  }
214
+ // The asset lands in a `.part` file beside the destination: a transfer that
215
+ // dies keeps its progress, the next attempt asks the host for the missing
216
+ // tail, and nothing is unpacked until the digest (when published) matches.
217
+ const { partPath } = assetPartPaths(dest);
218
+ const downloaded = await downloadAssetToFile({
219
+ url: downloadUrl,
220
+ partPath,
221
+ fetchImpl,
222
+ maxBytes: MAX_DOWNLOAD_BYTES,
223
+ ...(assetDigest ? { sha256: assetDigest } : {}),
224
+ headers: { 'User-Agent': USER_AGENT },
225
+ ...(opts.signal ? { signal: opts.signal } : {}),
226
+ ...(opts.onProgress ? { onProgress: opts.onProgress } : {}),
227
+ });
228
+ if (!downloaded.ok) {
229
+ if (downloaded.code === 'download-too-large') {
230
+ return { ok: false, code: 'download-too-large', error: 'Clash core download exceeded 80MB' };
231
+ }
232
+ return { ok: false, code: downloaded.code, error: `Clash core ${downloaded.error}` };
233
+ }
193
234
  let packed;
194
235
  try {
195
- const res = await fetchImpl(downloadUrl, {
196
- headers: { 'User-Agent': USER_AGENT, Accept: 'application/octet-stream' },
197
- });
198
- if (!res.ok)
199
- return { ok: false, code: 'download-failed', error: `Clash core download failed (${res.status})` };
200
- const total = Number(res.headers.get('content-length') ?? '') || 0;
201
- if (!res.body) {
202
- packed = Buffer.from(await res.arrayBuffer());
203
- opts.onProgress?.(packed.length, total || packed.length);
204
- }
205
- else {
206
- // Stream so the console can show a percentage: a release binary is tens of
207
- // MB and a buffered arrayBuffer would report nothing until it finished.
208
- const reader = res.body.getReader();
209
- const chunks = [];
210
- let downloaded = 0;
211
- let lastReport = 0;
212
- opts.onProgress?.(0, total);
213
- for (;;) {
214
- const { done, value } = await reader.read();
215
- if (done)
216
- break;
217
- if (!value)
218
- continue;
219
- chunks.push(value);
220
- downloaded += value.byteLength;
221
- if (downloaded > MAX_DOWNLOAD_BYTES) {
222
- await reader.cancel().catch(() => undefined);
223
- return { ok: false, code: 'download-too-large', error: 'Clash core download exceeded 80MB' };
224
- }
225
- const now = Date.now();
226
- if (now - lastReport >= 100) {
227
- lastReport = now;
228
- opts.onProgress?.(downloaded, total);
229
- }
230
- }
231
- packed = Buffer.concat(chunks);
232
- opts.onProgress?.(downloaded, total || downloaded);
233
- }
236
+ packed = fs.readFileSync(partPath);
234
237
  }
235
238
  catch (err) {
236
- const message = err instanceof Error ? err.message : 'network error';
237
- return { ok: false, code: 'download-failed', error: `Clash core download failed (${message})` };
238
- }
239
- if (packed.length > MAX_DOWNLOAD_BYTES) {
240
- return { ok: false, code: 'download-too-large', error: 'Clash core download exceeded 80MB' };
239
+ cleanupAssetPart(partPath);
240
+ const message = err instanceof Error ? err.message : 'read failed';
241
+ return { ok: false, code: 'download-failed', error: `could not read the downloaded asset (${message})` };
241
242
  }
242
243
  let bytes;
243
244
  try {
244
245
  bytes = unpack(packed, wanted.gzip);
245
246
  }
246
247
  catch {
248
+ // The asset arrived whole (and digest-verified when the API published one),
249
+ // so a second copy would unpack just as badly — drop the part and let the
250
+ // next attempt refetch rather than replay the same bad bytes.
251
+ cleanupAssetPart(partPath);
247
252
  return { ok: false, code: 'unpack-failed', error: 'Clash core archive could not be unpacked' };
248
253
  }
254
+ cleanupAssetPart(partPath);
249
255
  if (bytes.length === 0)
250
256
  return { ok: false, code: 'unpack-failed', error: 'mihomo archive was empty' };
251
- const dest = opts.destPath ?? defaultMihomoBinaryPath(platform);
252
257
  try {
253
258
  fs.mkdirSync(path.dirname(dest), { recursive: true });
254
259
  const tmp = `${dest}.download`;
@@ -263,5 +268,11 @@ export async function installMihomoBinary(opts = {}) {
263
268
  const message = err instanceof Error ? err.message : 'write failed';
264
269
  return { ok: false, code: 'install-failed', error: `could not install mihomo (${message})` };
265
270
  }
266
- return { ok: true, path: dest, version };
271
+ return {
272
+ ok: true,
273
+ path: dest,
274
+ version,
275
+ resumedFrom: downloaded.resumedFrom,
276
+ verified: downloaded.verified,
277
+ };
267
278
  }
@@ -120,7 +120,21 @@ export class MihomoClient {
120
120
  timeout: String(timeoutMs),
121
121
  url: testUrl,
122
122
  });
123
- const body = await this.request('GET', `/group/${encodeURIComponent(name)}/delay?${q}`, undefined, timeoutMs + 2000);
123
+ let body;
124
+ try {
125
+ body = await this.request('GET', `/group/${encodeURIComponent(name)}/delay?${q}`, undefined, timeoutMs + 2000);
126
+ }
127
+ catch (err) {
128
+ // mihomo answers a batch whose members ALL failed with 504 and the
129
+ // "get delay: all proxies timeout" message — a failed test, not a
130
+ // controller fault, so it keeps the stable `timeout` code the single
131
+ // node route uses. 408 is kept for builds that answer the request
132
+ // timeout status instead.
133
+ if (err instanceof MihomoControllerError && (err.status === 504 || err.status === 408)) {
134
+ throw new MihomoControllerError('delay test timed out (no member answered)', err.status, 'timeout');
135
+ }
136
+ throw err;
137
+ }
124
138
  const out = {};
125
139
  if (body && typeof body === 'object') {
126
140
  for (const [node, value] of Object.entries(body)) {
@@ -92,7 +92,11 @@ function renderGroup(input, group, use, manualNames) {
92
92
  * renaming the group never orphans a rule. IP rules carry `no-resolve`: without
93
93
  * it every IP rule forces mihomo to resolve a candidate hostname first, which
94
94
  * both costs a DNS round-trip and lets a resolved IP match a rule that the
95
- * operator wrote against literal addresses.
95
+ * operator wrote against literal addresses. `GEOIP` deliberately does NOT carry
96
+ * it — matching a CONNECT hostname against the country database is the whole
97
+ * point. Geo payloads are normalized to the spelling mihomo expects (country
98
+ * codes upper-case, geosite categories lower-case) whatever casing the operator
99
+ * typed.
96
100
  */
97
101
  function renderCustomRules(input) {
98
102
  const group = input.group || DEFAULT_MIHOMO_GROUP;
@@ -100,7 +104,10 @@ function renderCustomRules(input) {
100
104
  for (const rule of input.rules ?? []) {
101
105
  const target = rule.target === 'PROXY' ? group : rule.target;
102
106
  const noResolve = rule.type === 'IP-CIDR' || rule.type === 'IP-CIDR6' ? ',no-resolve' : '';
103
- out.push(`${rule.type},${rule.payload},${target}${noResolve}`);
107
+ const payload = rule.type === 'GEOIP'
108
+ ? rule.payload.toUpperCase()
109
+ : rule.type === 'GEOSITE' ? rule.payload.toLowerCase() : rule.payload;
110
+ out.push(`${rule.type},${payload},${target}${noResolve}`);
104
111
  }
105
112
  return out;
106
113
  }
@@ -121,6 +128,8 @@ export function renderMihomoConfig(input) {
121
128
  url: sub.url,
122
129
  interval: sub.interval ?? DEFAULT_MIHOMO_SUB_INTERVAL_SEC,
123
130
  path: `./providers/${sub.id}.yaml`,
131
+ // Forces the download through one proxy/group instead of the rule set.
132
+ ...(sub.proxy ? { proxy: sub.proxy } : {}),
124
133
  // Disabled on purpose: the group's own url-test already walks every
125
134
  // member, so a second provider-level probe would only double the test
126
135
  // traffic. The cadence still comes from the shared resolver — the old
@@ -0,0 +1,87 @@
1
+ import type { MihomoCustomRule } from '../config/types.js';
2
+ import type { OsProxyEndpoint } from '../forward-proxy/system-proxy.js';
3
+ export declare const MIHOMO_GEO_ASSETS: readonly [{
4
+ readonly key: "geoip";
5
+ readonly file: "geoip.metadb";
6
+ readonly url: "https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip.metadb";
7
+ }, {
8
+ readonly key: "geosite";
9
+ readonly file: "GeoSite.dat";
10
+ readonly url: "https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geosite.dat";
11
+ }];
12
+ export type MihomoGeoKey = typeof MIHOMO_GEO_ASSETS[number]['key'];
13
+ export interface MihomoGeoFileInfo {
14
+ key: MihomoGeoKey;
15
+ file: string;
16
+ exists: boolean;
17
+ size: number;
18
+ /** mtime (epoch ms) of the installed copy; absent while the file does not. */
19
+ updatedAt?: number;
20
+ /** Installed but older than `MIHOMO_GEO_STALE_DAYS` — advisory only. */
21
+ stale: boolean;
22
+ }
23
+ export interface MihomoGeoReport {
24
+ /** Both files exist and are non-empty — everything a geo rule needs. */
25
+ present: boolean;
26
+ files: MihomoGeoFileInfo[];
27
+ }
28
+ /** True when any row needs the geo databases. */
29
+ export declare function rulesNeedGeo(rules: MihomoCustomRule[] | undefined): boolean;
30
+ export declare function geoReport(dir: string): MihomoGeoReport;
31
+ export declare function geoAssetsPresent(dir: string): boolean;
32
+ /** Which egress the download takes (ADR-0022): the machine's own network or
33
+ * the Clash core's selected node. */
34
+ export type MihomoGeoLeg = 'machine' | 'node';
35
+ export interface GeoLegFetchOptions {
36
+ /** `node` leg only: the core's mixed port — the exit it already listens on. */
37
+ mixedPort?: number;
38
+ /** Test seam — a CI box's own OS settings are not the fixture. */
39
+ osProxyReader?: () => Promise<OsProxyEndpoint | undefined>;
40
+ }
41
+ /**
42
+ * The proxy URL the machine leg should dial for `url`: the OS system proxy
43
+ * unless the host sits on its bypass list. `undefined` means connect directly.
44
+ */
45
+ export declare function machineLegProxy(endpoint: OsProxyEndpoint | undefined, url: string): string | undefined;
46
+ /**
47
+ * The fetch implementation the geo download runs on.
48
+ *
49
+ * - `machine` — the way this box's other applications leave: through the OS
50
+ * system proxy when one is enabled (bypass list honoured), directly when
51
+ * none is. Needs no running core. The check runs per request, so the
52
+ * redirect to `objects.githubusercontent.com` is judged on its own host.
53
+ * - `node` — through the core's mixed port, i.e. the operator's selected
54
+ * node. The caller must refuse this leg while the core is down; by the time
55
+ * a request lands here the core is expected to be listening.
56
+ */
57
+ export declare function geoFetchForLeg(leg: MihomoGeoLeg, opts?: GeoLegFetchOptions): Promise<typeof fetch>;
58
+ export interface DownloadMihomoGeoOptions {
59
+ /** Test seam — suites never touch GitHub. */
60
+ fetchImpl?: typeof fetch;
61
+ /** Re-fetch files that already exist (the console's "sync" action). Without
62
+ * it a present file is kept, so a retry after a partial failure only
63
+ * fetches the missing one. */
64
+ refresh?: boolean;
65
+ /** Per-file byte progress of the WHOLE asset (resumed prefix included);
66
+ * `total` is 0 when the host sends no Content-Length. */
67
+ onProgress?: (file: MihomoGeoKey, downloaded: number, total: number) => void;
68
+ /** Cancels the transfer. The bytes written so far are kept for the next
69
+ * attempt, so closing the console tab pauses a geo sync rather than
70
+ * discarding it. */
71
+ signal?: AbortSignal;
72
+ }
73
+ export interface DownloadMihomoGeoResult {
74
+ ok: boolean;
75
+ present: boolean;
76
+ files: MihomoGeoFileInfo[];
77
+ error?: string;
78
+ code?: string;
79
+ }
80
+ /**
81
+ * Install the geo databases into the core's work directory. Existing non-empty
82
+ * files are kept unless `refresh` asks for replacement (a retry after a partial
83
+ * failure only fetches the missing one); a file that fails to download or write
84
+ * never replaces a working copy. Each asset is one critical section (ADR-0022):
85
+ * a second click waits instead of writing the same part file underneath it.
86
+ */
87
+ export declare function downloadMihomoGeoAssets(dir: string, opts?: DownloadMihomoGeoOptions): Promise<DownloadMihomoGeoResult>;