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
@@ -20,8 +20,8 @@ import { ClientHookStatus } from '../types.js';
20
20
  * rewritten.
21
21
  */
22
22
  export declare class OpenClawClientAdapter implements ClientAdapter {
23
- name: 'openclaw';
24
- hookKind: 'config';
23
+ name: "openclaw";
24
+ hookKind: "config";
25
25
  displayName: string;
26
26
  versionCmd: string[];
27
27
  /** Provider entry this adapter owns inside `models.providers`. */
@@ -0,0 +1,11 @@
1
+ import { ClientAdapter, ClientActionResult } from './base.js';
2
+ import { ClientHookStatus } from '../types.js';
3
+ export declare class OpenCodeProxyClientAdapter implements ClientAdapter {
4
+ name: "opencode-proxy";
5
+ hookKind: "service-env";
6
+ displayName: string;
7
+ getConfigPath(): string;
8
+ getStatus(): Promise<Omit<ClientHookStatus, 'hookKind'>>;
9
+ setup(): Promise<ClientActionResult>;
10
+ teardown(): Promise<ClientActionResult>;
11
+ }
@@ -0,0 +1,351 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { resolveForwardProxyEndpoint } from './base.js';
4
+ import { runCommand } from '../../utils/run-command.js';
5
+ import { getOcrHomeDir } from '../paths.js';
6
+ import { caCertPath } from '../../forward-proxy/ca.js';
7
+ /**
8
+ * OpenCode "proxy mode" client adapter.
9
+ *
10
+ * Unlike OpenCodeClientAdapter (provider injection into opencode.json(c)),
11
+ * this hook leaves the client config file untouched and points OpenCode's OWN
12
+ * outbound traffic at OCR's inbound forward proxy by persisting managed
13
+ * service environment variables (OpenCode v2 managed service):
14
+ *
15
+ * opencode service set env HTTPS_PROXY http://127.0.0.1:<forwardProxy.port>
16
+ * opencode service set env HTTP_PROXY http://127.0.0.1:<forwardProxy.port>
17
+ * opencode service set env NO_PROXY localhost,127.0.0.1,::1 (REQUIRED:
18
+ * the opencode CLI talks to its background service over local HTTP —
19
+ * routing that through any proxy breaks opencode itself)
20
+ * opencode service set env NODE_EXTRA_CA_CERTS <forwardProxy.caDir>/ca.pem
21
+ * (the forward proxy is a full-capture MITM — its CA must be trusted)
22
+ *
23
+ * The forward proxy intercepts only canonical LLM endpoints
24
+ * (/v1/chat/completions, /v1/messages, /v1/responses) into the routing
25
+ * pipeline; every other destination is forwarded transparently, so pointing
26
+ * ALL of opencode's HTTPS traffic at it is safe. Models and API keys stay
27
+ * opencode-native — the gateway key / provider-injection model picker do not
28
+ * apply to this mode (modelSlots stays empty).
29
+ *
30
+ * Every value is resolved from the RUNTIME config snapshot
31
+ * (getRuntimeConfigRef() || loadConfig()) — never hardcoded — so what gets
32
+ * written into opencode always matches the RUNNING forward proxy. A fresh
33
+ * loadConfig() after a hot reload could advertise a port the running proxy
34
+ * no longer listens on.
35
+ *
36
+ * Scope caveat (opencode v2 docs): `service set env` configures the managed
37
+ * background service ONLY. `opencode --standalone`, `opencode serve` and
38
+ * shell-launched CLIs read their own process environment — the setup message
39
+ * tells the user to set the same variables there manually.
40
+ */
41
+ const PROXY_ENV_KEYS = ['HTTPS_PROXY', 'HTTP_PROXY', 'NO_PROXY', 'NODE_EXTRA_CA_CERTS'];
42
+ const LOOPBACK_NO_PROXY = 'localhost,127.0.0.1,::1';
43
+ /** Stable sidecar recording the service env values we replaced (teardown restores them). */
44
+ function metaPath() {
45
+ return path.join(getOcrHomeDir(), 'opencode-proxy.env-meta.json');
46
+ }
47
+ function readMeta() {
48
+ try {
49
+ if (fs.existsSync(metaPath()))
50
+ return JSON.parse(fs.readFileSync(metaPath(), 'utf8'));
51
+ }
52
+ catch {
53
+ // ignore — treated as "no originals recorded"
54
+ }
55
+ return {};
56
+ }
57
+ function writeMeta(meta) {
58
+ try {
59
+ fs.writeFileSync(metaPath(), JSON.stringify(meta, null, 2), 'utf8');
60
+ }
61
+ catch {
62
+ // best effort — teardown then just unsets whatever we set
63
+ }
64
+ }
65
+ /**
66
+ * Run `opencode <args>` ASYNCHRONOUSLY — getStatus is polled (~4s) by the
67
+ * console, so a sync spawn here would block the whole gateway event loop.
68
+ */
69
+ function runOpenCode(args) {
70
+ return runCommand('opencode', args, 20_000);
71
+ }
72
+ /**
73
+ * `opencode service get env` probe with a 30s TTL — the console polls status
74
+ * every ~4s and spawning the CLI that often is wasteful. Invalidated by
75
+ * setup/teardown so hook-state changes reflect immediately.
76
+ */
77
+ const PROBE_TTL_MS = 30_000;
78
+ let probeCache = null;
79
+ function probeServiceEnv() {
80
+ if (probeCache && Date.now() - probeCache.at < PROBE_TTL_MS)
81
+ return Promise.resolve(probeCache.result);
82
+ return runOpenCode(['service', 'get', 'env']).then(result => {
83
+ probeCache = { at: Date.now(), result };
84
+ return result;
85
+ });
86
+ }
87
+ function invalidateProbe() {
88
+ probeCache = null;
89
+ }
90
+ /**
91
+ * Substring test for our proxy URL with a digit-boundary guard — plain
92
+ * `includes` would collide on port prefixes (4555 vs 45550).
93
+ */
94
+ function urlMentioned(raw, url) {
95
+ const escaped = url.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
96
+ return new RegExp(escaped + '(?![0-9])').test(raw);
97
+ }
98
+ /**
99
+ * Parse `opencode service get env` output. The exact rendering is not a
100
+ * stable contract (JSON object, KEY=value lines or bullet lists), so accept
101
+ * JSON (flat or one level of wrapper objects) and per-line `KEY[=:] value`
102
+ * pairs. Only OUR four keys are ever read back, so extra output is harmless.
103
+ */
104
+ function parseServiceEnv(raw) {
105
+ const out = {};
106
+ const trimmed = (raw || '').trim();
107
+ if (!trimmed)
108
+ return out;
109
+ if (trimmed.startsWith('{') || trimmed.startsWith('[')) {
110
+ try {
111
+ const obj = JSON.parse(trimmed);
112
+ const collect = (input, depth) => {
113
+ if (!input || typeof input !== 'object' || depth > 1)
114
+ return;
115
+ for (const [k, v] of Object.entries(input)) {
116
+ if (typeof v === 'string')
117
+ out[k.toUpperCase()] = v;
118
+ else
119
+ collect(v, depth + 1);
120
+ }
121
+ };
122
+ collect(obj, 0);
123
+ if (Object.keys(out).length > 0)
124
+ return out;
125
+ }
126
+ catch {
127
+ // fall through to line parsing
128
+ }
129
+ }
130
+ for (const line of trimmed.split(/\r?\n/)) {
131
+ const m = line.match(/^\s*\*?\s*-?\s*([A-Za-z_][A-Za-z0-9_]*)\s*[=:]\s*(.*)$/);
132
+ if (m)
133
+ out[m[1].toUpperCase()] = m[2].trim().replace(/^['"]|['"]$/g, '');
134
+ }
135
+ return out;
136
+ }
137
+ /**
138
+ * Heuristic: does this env value belong to OUR hook (vs the user's own proxy
139
+ * like clash)? Used by teardown when no sidecar originals were recorded —
140
+ * only then is it safe to unset.
141
+ */
142
+ function looksLikeOurs(key, value, fp) {
143
+ if (!value)
144
+ return false;
145
+ const v = value.trim();
146
+ if (fp && v === fp.url)
147
+ return true;
148
+ if (key === 'NO_PROXY')
149
+ return v.replace(/\s/g, '') === LOOPBACK_NO_PROXY;
150
+ if (key === 'NODE_EXTRA_CA_CERTS') {
151
+ const ours = path.resolve(fp?.caPath || caCertPath());
152
+ try {
153
+ return path.resolve(v) === ours;
154
+ }
155
+ catch {
156
+ return false;
157
+ }
158
+ }
159
+ return false;
160
+ }
161
+ export class OpenCodeProxyClientAdapter {
162
+ name = 'opencode-proxy';
163
+ hookKind = 'service-env';
164
+ displayName = 'OpenCode (Proxy Mode)';
165
+ getConfigPath() {
166
+ // Proxy mode owns no client config file; the meaningful artifact is the
167
+ // MITM CA written into opencode's trust store (NODE_EXTRA_CA_CERTS).
168
+ return resolveForwardProxyEndpoint()?.caPath || caCertPath();
169
+ }
170
+ async getStatus() {
171
+ const fp = resolveForwardProxyEndpoint();
172
+ const probe = await probeServiceEnv();
173
+ const exists = probe.ok; // CLI reachable AND the v2 `service` subcommand works
174
+ const backupExists = fs.existsSync(metaPath());
175
+ let hooked = false;
176
+ let details;
177
+ if (!probe.ok) {
178
+ details = /not recognized|ENOENT|not found/i.test(probe.stderr)
179
+ ? 'opencode CLI not detected on PATH'
180
+ : 'opencode detected but `service` command unavailable (OpenCode v2 required)';
181
+ }
182
+ else if (!fp) {
183
+ details = 'forwardProxy disabled in config.yaml — enable it before hooking proxy mode';
184
+ }
185
+ else {
186
+ const env = parseServiceEnv(probe.stdout);
187
+ const proxyValue = (env.HTTPS_PROXY || env.HTTP_PROXY || '').trim();
188
+ const oursProxy = proxyValue === fp.url || urlMentioned(probe.stdout, fp.url);
189
+ const oursCa = (env.NODE_EXTRA_CA_CERTS || '').trim().length > 0 || /NODE_EXTRA_CA_CERTS/i.test(probe.stdout);
190
+ if (oursProxy && oursCa) {
191
+ hooked = true;
192
+ details = `Proxied through OCR forward proxy (${fp.url}); CA: ${env.NODE_EXTRA_CA_CERTS || fp.caPath}`;
193
+ }
194
+ else if (proxyValue) {
195
+ details = `Active with another proxy (${proxyValue}) — setup will replace it (previous value kept for teardown)`;
196
+ }
197
+ else {
198
+ details = 'opencode service env has no proxy configured';
199
+ }
200
+ }
201
+ return {
202
+ name: this.name,
203
+ displayName: this.displayName,
204
+ configPath: this.getConfigPath(),
205
+ exists,
206
+ hooked,
207
+ backupExists,
208
+ details,
209
+ modelSlots: [], // no model picker — models/keys stay opencode-native in proxy mode
210
+ };
211
+ }
212
+ async setup() {
213
+ invalidateProbe();
214
+ const fp = resolveForwardProxyEndpoint();
215
+ if (!fp) {
216
+ return {
217
+ success: false,
218
+ reasonCode: 'forwardProxyDisabled',
219
+ message: 'forwardProxy is not enabled in config.yaml — set `forwardProxy.enabled: true` (and keep the gateway running) before enabling OpenCode proxy mode.',
220
+ };
221
+ }
222
+ if (!fs.existsSync(fp.caPath)) {
223
+ return {
224
+ success: false,
225
+ reasonCode: 'forwardProxyCaMissing',
226
+ params: { path: fp.caPath },
227
+ message: `Forward-proxy MITM CA not found at ${fp.caPath} — it is generated when the gateway boots with forwardProxy enabled. Start the gateway and retry.`,
228
+ };
229
+ }
230
+ const probe = await probeServiceEnv();
231
+ if (!probe.ok) {
232
+ return {
233
+ success: false,
234
+ reasonCode: 'serviceProbeFailed',
235
+ params: { detail: (probe.stderr || probe.stdout).trim() },
236
+ message: `\`opencode service get env\` failed — OpenCode v2 with the managed service is required for proxy mode. ${(probe.stderr || probe.stdout).trim()}`.trim(),
237
+ };
238
+ }
239
+ // Record originals BEFORE overwriting: if a later `set env` fails midway,
240
+ // teardown must still restore what setup replaced — the looksLikeOurs
241
+ // fallback can only unset OUR values, which would lose the user's
242
+ // original. Restoring an identical value on a never-replaced key is
243
+ // harmless; data preservation wins over the stale-restore edge case.
244
+ const current = parseServiceEnv(probe.stdout);
245
+ const previous = {};
246
+ for (const k of PROXY_ENV_KEYS) {
247
+ const v = current[k];
248
+ if (typeof v === 'string' && v.length > 0)
249
+ previous[k] = v;
250
+ }
251
+ writeMeta({ previous });
252
+ for (const [k, v] of [
253
+ ['HTTPS_PROXY', fp.url],
254
+ ['HTTP_PROXY', fp.url],
255
+ ['NO_PROXY', LOOPBACK_NO_PROXY],
256
+ ['NODE_EXTRA_CA_CERTS', fp.caPath],
257
+ ]) {
258
+ const r = await runOpenCode(['service', 'set', 'env', k, v]);
259
+ if (!r.ok) {
260
+ return {
261
+ success: false,
262
+ reasonCode: 'serviceSetEnvFailed',
263
+ params: { key: k, detail: (r.stderr || r.stdout).trim() },
264
+ message: `\`opencode service set env ${k}\` failed: ${(r.stderr || r.stdout).trim()}`,
265
+ };
266
+ }
267
+ }
268
+ const start = await runOpenCode(['service', 'start']);
269
+ if (!start.ok) {
270
+ return {
271
+ success: false,
272
+ reasonCode: 'serviceStartFailed',
273
+ params: { url: fp.url, detail: (start.stderr || start.stdout).trim() },
274
+ message: `Proxy env persisted (${fp.url}) but \`opencode service start\` failed: ${(start.stderr || start.stdout).trim()} — run it manually, or teardown to revert.`,
275
+ };
276
+ }
277
+ return {
278
+ success: true,
279
+ message: `OpenCode proxy mode enabled: HTTPS_PROXY/HTTP_PROXY → ${fp.url}, NO_PROXY → ${LOOPBACK_NO_PROXY}, NODE_EXTRA_CA_CERTS → ${fp.caPath}. LLM endpoints are intercepted into the OCR pipeline, other traffic forwards transparently. NOTE: \`opencode --standalone\`/\`serve\` and shell-launched CLIs read their own process env — set the same variables there manually if you use those modes.`,
280
+ };
281
+ }
282
+ async teardown() {
283
+ invalidateProbe();
284
+ const probe = await probeServiceEnv();
285
+ if (!probe.ok) {
286
+ return {
287
+ success: false,
288
+ reasonCode: 'serviceProbeFailed',
289
+ params: { detail: (probe.stderr || probe.stdout).trim() },
290
+ message: `\`opencode service get env\` failed — cannot inspect opencode service env. ${(probe.stderr || probe.stdout).trim()}`.trim(),
291
+ };
292
+ }
293
+ const { previous } = readMeta();
294
+ const current = parseServiceEnv(probe.stdout);
295
+ const fp = resolveForwardProxyEndpoint();
296
+ const touched = [];
297
+ let oursPresent = false;
298
+ for (const k of PROXY_ENV_KEYS) {
299
+ const prev = previous?.[k];
300
+ const cur = current[k] || '';
301
+ if (prev !== undefined) {
302
+ const r = await runOpenCode(['service', 'set', 'env', k, prev]);
303
+ if (!r.ok) {
304
+ return {
305
+ success: false,
306
+ reasonCode: 'serviceSetEnvFailed',
307
+ params: { key: k, detail: (r.stderr || r.stdout).trim() },
308
+ message: `\`opencode service set env ${k}\` failed: ${(r.stderr || r.stdout).trim()}`,
309
+ };
310
+ }
311
+ touched.push(`${k} (restored)`);
312
+ oursPresent = true;
313
+ }
314
+ else if (cur && looksLikeOurs(k, cur, fp)) {
315
+ const r = await runOpenCode(['service', 'unset', 'env', k]);
316
+ if (!r.ok) {
317
+ return {
318
+ success: false,
319
+ reasonCode: 'serviceSetEnvFailed',
320
+ params: { key: k, detail: (r.stderr || r.stdout).trim() },
321
+ message: `\`opencode service unset env ${k}\` failed: ${(r.stderr || r.stdout).trim()}`,
322
+ };
323
+ }
324
+ touched.push(`${k} (removed)`);
325
+ oursPresent = true;
326
+ }
327
+ }
328
+ try {
329
+ fs.unlinkSync(metaPath());
330
+ }
331
+ catch {
332
+ // best effort
333
+ }
334
+ if (!oursPresent) {
335
+ return { success: false, reasonCode: 'notActive', message: 'OpenCode proxy mode is not active — nothing to tear down.' };
336
+ }
337
+ const start = await runOpenCode(['service', 'start']);
338
+ if (!start.ok) {
339
+ return {
340
+ success: false,
341
+ reasonCode: 'serviceStartFailed',
342
+ params: { detail: (start.stderr || start.stdout).trim() },
343
+ message: `Env restored (${touched.join(', ')}) but \`opencode service start\` failed: ${(start.stderr || start.stdout).trim()} — run it manually.`,
344
+ };
345
+ }
346
+ return {
347
+ success: true,
348
+ message: `OpenCode proxy mode disabled: ${touched.join(', ')}. Service restarted with the previous environment.`,
349
+ };
350
+ }
351
+ }
@@ -1,8 +1,8 @@
1
1
  import { ClientAdapter } from './base.js';
2
2
  import { ClientHookStatus } from '../types.js';
3
3
  export declare class OpenCodeClientAdapter implements ClientAdapter {
4
- name: 'opencode';
5
- hookKind: 'config';
4
+ name: "opencode";
5
+ hookKind: "config";
6
6
  displayName: string;
7
7
  getConfigPath(): string;
8
8
  getStatus(): Promise<Omit<ClientHookStatus, 'hookKind'>>;
@@ -1,8 +1,8 @@
1
1
  import { ClientAdapter } from './base.js';
2
2
  import { ClientHookStatus } from '../types.js';
3
3
  export declare class PiClientAdapter implements ClientAdapter {
4
- name: 'pi';
5
- hookKind: 'config';
4
+ name: "pi";
5
+ hookKind: "config";
6
6
  displayName: string;
7
7
  getConfigPath(): string;
8
8
  /**
@@ -11,10 +11,12 @@ export declare function clearPluginClientAdapters(): void;
11
11
  * must surface as a load error on the plugin's own console row, never as a
12
12
  * silent override.
13
13
  */
14
- export declare function registerPluginClientAdapter(pluginId: string, adapter: ClientAdapter): void;
14
+ export declare function registerPluginClientAdapter(pluginId: string, adapter: ClientAdapter, rank?: number): void;
15
15
  /** One plugin-contributed adapter by client id (core lookup already missed). */
16
16
  export declare function getPluginClientAdapter(name: string): ClientAdapter | undefined;
17
17
  /** Which package provides this client hook — undefined for a core hook. */
18
18
  export declare function pluginIdForClient(name: string): string | undefined;
19
19
  /** All plugin-contributed adapters, registration order. */
20
20
  export declare function listPluginClientAdapters(): ClientAdapter[];
21
+ /** Manifest `clientRank` for a contributed hook — undefined = unranked tail. */
22
+ export declare function pluginClientRank(name: string): number | undefined;
@@ -1,31 +1,4 @@
1
1
  import { isCoreClientId, RETIRED_CLIENT_IDS } from './reserved.js';
2
- /**
3
- * Client adapters contributed by PLUGINS (`type: 'client-adapter'`, ADR-0027).
4
- *
5
- * Kept apart from the core registry on purpose:
6
- *
7
- * - the core registry is the answer to "what can this build hook?", a fixed
8
- * map keyed by the reserved id list in `reserved.ts` — compile-time
9
- * knowledge the CLI help text, the console roster and the i18n labels are
10
- * built on;
11
- * - this map is the answer to "what has this install additionally hooked?",
12
- * which changes at runtime (install / uninstall / disable / a failed load)
13
- * and must never be able to shadow a core id.
14
- *
15
- * The lookup order in `clients/index.ts` is core first, so a package can never
16
- * silently replace a built-in hook — a colliding id is REFUSED at load with the
17
- * package's own error message instead of becoming a row whose behaviour
18
- * depends on which copy happened to register last.
19
- *
20
- * The plugin host owns the write side and rebuilds TRANSACTIONALLY, exactly
21
- * like the gateway registry: `beginPluginClientAdapterRebuild()` opens a
22
- * staging map, each loaded package registers into it, and
23
- * `commitPluginClientAdapterRebuild()` swaps it in. A rebuild that throws
24
- * before the commit therefore leaves the PREVIOUS adapter set live instead of
25
- * an empty one — a failed scan must not blind the Client Hub while the proxy
26
- * legs keep serving. Registration outside a rebuild (tests, callers without a
27
- * host) writes to the live map.
28
- */
29
2
  const byName = new Map();
30
3
  /** Staging target while a rebuild is open; undefined = write live. */
31
4
  let staged;
@@ -53,7 +26,7 @@ export function clearPluginClientAdapters() {
53
26
  * must surface as a load error on the plugin's own console row, never as a
54
27
  * silent override.
55
28
  */
56
- export function registerPluginClientAdapter(pluginId, adapter) {
29
+ export function registerPluginClientAdapter(pluginId, adapter, rank) {
57
30
  const name = String(adapter?.name ?? '').trim().toLowerCase();
58
31
  if (!name)
59
32
  throw new Error('client-adapter plugin returned no adapter name');
@@ -72,7 +45,7 @@ export function registerPluginClientAdapter(pluginId, adapter) {
72
45
  if (existing && existing.pluginId !== pluginId) {
73
46
  throw new Error(`client '${name}' is already provided by plugin '${existing.pluginId}'`);
74
47
  }
75
- target.set(name, { pluginId, adapter });
48
+ target.set(name, { pluginId, adapter, ...(rank !== undefined ? { rank } : {}) });
76
49
  }
77
50
  /** One plugin-contributed adapter by client id (core lookup already missed). */
78
51
  export function getPluginClientAdapter(name) {
@@ -86,3 +59,7 @@ export function pluginIdForClient(name) {
86
59
  export function listPluginClientAdapters() {
87
60
  return [...byName.values()].map((entry) => entry.adapter);
88
61
  }
62
+ /** Manifest `clientRank` for a contributed hook — undefined = unranked tail. */
63
+ export function pluginClientRank(name) {
64
+ return byName.get(String(name ?? '').trim().toLowerCase())?.rank;
65
+ }
@@ -0,0 +1,84 @@
1
+ import { ClientAdapter, ClientActionResult } from './base.js';
2
+ import { ClientHookStatus } from '../types.js';
3
+ /**
4
+ * Qoder's agent serves the model catalog from `<qoderHome>/.models/<uid>/catalog-v<N>`
5
+ * and only refreshes it in the BACKGROUND when that file is present but STALE.
6
+ * A missing file is not a miss it recovers from: `get_models` returns an empty
7
+ * list and never touches the network, which leaves the composer stuck on
8
+ * "this account cannot use the model for this task".
9
+ *
10
+ * So: keep the file, backdate its mtime. The client then serves the old list
11
+ * immediately (nothing is disabled) and refetches through the gateway, which
12
+ * merges the `ocr/*` entries into the reply.
13
+ */
14
+ export declare function staleModelCatalog(home?: string): string[];
15
+ /** Count catalogs the client would serve without a background refresh. */
16
+ export declare function countFreshCatalogs(home?: string, maxAgeMs?: number): number;
17
+ export declare function launcherPath(): string;
18
+ /** The CLI launcher — written only while `qodercli` is installed. */
19
+ export declare function cliLauncherPath(): string;
20
+ /**
21
+ * The `qodercli` executable, resolved from `PATH` (npm installs a `.cmd` shim
22
+ * on Windows). `QODERCLI_BIN` wins for non-standard installs. The CLI is a
23
+ * plain Node program, so its launcher can use the CLEAN trust switch
24
+ * (`NODE_OPTIONS=--use-system-ca`), unlike the Electron daemon.
25
+ */
26
+ export declare function detectQoderCliBin(env?: NodeJS.ProcessEnv): string | null;
27
+ /**
28
+ * CLI launcher text. Unlike the desktop launcher this one forwards argv and
29
+ * returns the CLI's exit status; `NODE_OPTIONS=--use-system-ca` makes Node use
30
+ * the OS root store, where the gateway CA lives, without disabling
31
+ * verification (the SDK ignores `NODE_EXTRA_CA_CERTS`).
32
+ */
33
+ export declare function buildQoderCliLauncher(args: {
34
+ platform: NodeJS.Platform;
35
+ binary: string;
36
+ port: number;
37
+ caPath?: string;
38
+ proxyCredential?: string;
39
+ }): string;
40
+ /**
41
+ * Loopback never enters the proxy hop. Both spellings are set on POSIX because
42
+ * libraries differ on which one they read; Windows env blocks are
43
+ * case-insensitive, so `set` emits ONE variable there.
44
+ */
45
+ export declare const QODER_NO_PROXY = "localhost,127.0.0.1,::1";
46
+ /**
47
+ * The launcher text for one platform. Pure so the env contract is testable
48
+ * without a real Qoder install. Windows bodies open with `setlocal` so the
49
+ * `set` lines cannot rewrite the CALLING shell's proxy env.
50
+ */
51
+ export declare function buildQoderLauncher(args: {
52
+ platform: NodeJS.Platform;
53
+ binary: string;
54
+ port: number;
55
+ caPath?: string;
56
+ proxyCredential?: string;
57
+ }): string;
58
+ export declare class QoderProxyClientAdapter implements ClientAdapter {
59
+ name: "qoder-proxy";
60
+ hookKind: "launcher";
61
+ displayName: string;
62
+ versionCmd: string[];
63
+ getConfigPath(): string;
64
+ getStatus(): Promise<Omit<ClientHookStatus, 'hookKind'>>;
65
+ setup(options?: {
66
+ port?: number;
67
+ apiKey?: string;
68
+ }): Promise<ClientActionResult>;
69
+ teardown(): Promise<ClientActionResult>;
70
+ }
71
+ export interface QoderLaunchResult {
72
+ ok: boolean;
73
+ code: number;
74
+ /** The desktop launcher returns before Qoder exits (win32/darwin `start`). */
75
+ detached: boolean;
76
+ message?: string;
77
+ }
78
+ /**
79
+ * Run one of the managed launchers, forwarding stdio and the launcher's exit
80
+ * code — the `ocr qoder` / `ocr qoder-cli` contract, identical to Cursor's.
81
+ * The CLI is interactive (`-p`, or a full TUI), so it must keep the caller's
82
+ * stdio; the desktop launcher detaches by itself via `start`.
83
+ */
84
+ export declare function runQoderLauncher(kind: 'desktop' | 'cli', argv: string[]): Promise<QoderLaunchResult>;