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
@@ -1,141 +1,65 @@
1
- import { proxiedFetch, resolveProxyUrl } from '../utils/proxy.js';
2
- import { emitUpstreamRequestOnce, emitUpstreamResponseOnce, emitUpstreamFailureOnce, withUpstreamFailureGuard, } from '../observability/upstream-events.js';
1
+ import { DEFAULT_PROVIDER_TIMEOUT_MS } from '../config/defaults.js';
2
+ import { postProviderJson } from './http-json.js';
3
+ function partText(part) {
4
+ if (part.type === 'text' || part.type === 'refusal')
5
+ return part.text;
6
+ if (part.type === 'image')
7
+ return part.source.kind === 'url' ? `[image: ${part.source.url}]` : '[image: base64]';
8
+ if (part.type === 'file')
9
+ return part.source.kind === 'url' ? `[file: ${part.source.url}]` : '[file]';
10
+ if (part.type === 'audio')
11
+ return '[audio]';
12
+ return '[extension]';
13
+ }
3
14
  export class OpenCodeProxyProvider {
4
- name = 'opencode-proxy';
5
15
  config;
16
+ name = 'opencode-proxy';
6
17
  constructor(config) {
7
18
  this.config = config;
8
19
  }
9
20
  async createCompletion(request, model, upstreamEventContext) {
10
- const url = `${this.config.baseUrl.replace(/\/+$/, '')}/api/experimental/generate`;
11
- // Flatten messages into conversational prompt
12
- let prompt = '';
13
- for (const msg of request.messages) {
14
- const content = typeof msg.content === 'string'
15
- ? msg.content
16
- : Array.isArray(msg.content)
17
- ? msg.content.map(p => p.text || '').join(' ')
18
- : '';
19
- prompt += `${msg.role.toUpperCase()}: ${content}\n\n`;
20
- }
21
- prompt += 'ASSISTANT:';
22
- const payload = {
23
- prompt: prompt.trim(),
24
- model: {
25
- providerID: model.provider,
26
- id: model.upstreamModel,
27
- },
28
- };
29
- const outboundHeaders = {
30
- Authorization: this.config.authHeader,
31
- 'Content-Type': 'application/json',
32
- };
33
- // Event-stream emit BEFORE the fetch fires. Independent of the response.
34
- const exchangeId = emitUpstreamRequestOnce(upstreamEventContext, {
35
- url,
36
- method: 'POST',
37
- requestHeaders: outboundHeaders,
38
- requestBody: JSON.stringify(payload),
39
- model: model.upstreamModel,
40
- proxy: resolveProxyUrl(url, { provider: this.name, model: model.id }),
41
- });
42
- // The guard emits a paired failure response event on ANY thrown error so
43
- // console readers never see a dangling request event.
44
- const res = await withUpstreamFailureGuard(upstreamEventContext, exchangeId, url, 'POST',
45
- // Loopback URLs skip the proxy (see isLoopbackUrl in proxy.ts), so this
46
- // also keeps local daemon calls from being routed via the gateway.
47
- () => proxiedFetch(url, {
48
- method: 'POST',
49
- headers: outboundHeaders,
50
- body: JSON.stringify(payload),
51
- }, { provider: this.name, model: model.id }), model.upstreamModel);
52
- if (!res.ok) {
53
- // Body read can fail mid-stream (connection reset) — pair the request
54
- // event with a failure response before rethrowing.
55
- let errText;
56
- try {
57
- errText = await res.text();
21
+ const lines = [];
22
+ if (request.instructions)
23
+ lines.push(`SYSTEM: ${request.instructions}`);
24
+ for (const item of request.input) {
25
+ if (item.type === 'message') {
26
+ lines.push(`${item.role.toUpperCase()}: ${item.content.map(partText).join(' ')}`);
58
27
  }
59
- catch (err) {
60
- emitUpstreamFailureOnce(upstreamEventContext, {
61
- model: model.upstreamModel,
62
- exchangeId,
63
- url,
64
- method: 'POST',
65
- status: res.status,
66
- statusText: res.statusText,
67
- error: `Response body read failed: ${err?.message ?? err}`,
68
- });
69
- throw err;
28
+ else if (item.type === 'reasoning') {
29
+ lines.push(`ASSISTANT: ${item.text ?? ''}`);
30
+ }
31
+ else if (item.type === 'tool_call') {
32
+ lines.push(`ASSISTANT: [tool_call ${item.name}] ${item.arguments}`);
33
+ }
34
+ else if (item.type === 'tool_result') {
35
+ lines.push(`TOOL: ${item.content.map(partText).join(' ')}`);
70
36
  }
71
- emitUpstreamFailureOnce(upstreamEventContext, {
72
- model: model.upstreamModel,
73
- exchangeId,
74
- url,
75
- method: 'POST',
76
- status: res.status,
77
- statusText: res.statusText,
78
- responseHeaders: res.headers,
79
- responseBody: errText,
80
- error: `OpenCode Proxy error [${res.status}]`,
81
- });
82
- throw new Error(`OpenCode Proxy failed [${res.status}]: ${errText}`);
83
- }
84
- // Emit the response event the moment the body BYTES arrive — before
85
- // JSON.parse (see anthropic.ts for the rationale).
86
- let rawBody;
87
- try {
88
- rawBody = await res.text();
89
- }
90
- catch (err) {
91
- emitUpstreamFailureOnce(upstreamEventContext, {
92
- model: model.upstreamModel,
93
- exchangeId,
94
- url,
95
- method: 'POST',
96
- status: res.status,
97
- statusText: res.statusText,
98
- error: `Response body read failed: ${err?.message ?? err}`,
99
- });
100
- throw err;
101
37
  }
102
- // The shape is `{ data: { text: string } }` (private HTTP API; not
103
- // OpenAI-compatible).
104
- emitUpstreamResponseOnce(upstreamEventContext, {
105
- model: model.upstreamModel,
106
- exchangeId,
107
- url,
108
- method: 'POST',
109
- status: res.status,
110
- statusText: res.statusText,
111
- responseHeaders: res.headers,
112
- responseBody: rawBody,
38
+ const prompt = `${lines.join('\n\n')}\n\nASSISTANT:`.trim();
39
+ const payload = {
40
+ prompt,
41
+ model: { providerID: model.provider, id: model.upstreamModel },
42
+ };
43
+ const data = await postProviderJson({
44
+ url: `${this.config.baseUrl.replace(/\/+$/, '')}/api/experimental/generate`,
45
+ headers: { Authorization: this.config.authHeader, 'Content-Type': 'application/json' },
46
+ payload,
47
+ model,
48
+ provider: this.name,
49
+ label: 'generate',
50
+ timeoutMs: DEFAULT_PROVIDER_TIMEOUT_MS,
51
+ upstreamEventContext,
113
52
  });
114
- const data = JSON.parse(rawBody);
115
- const text = data.data?.text || '';
116
- // Estimate tokens
117
- const promptTokens = Math.ceil(prompt.length / 3);
118
- const completionTokens = Math.ceil(text.length / 3);
53
+ const text = data.data?.text ?? '';
54
+ const inputTokens = Math.ceil(prompt.length / 3);
55
+ const outputTokens = Math.ceil(text.length / 3);
119
56
  return {
120
57
  id: `opencode-cmpl-${Date.now()}`,
121
- object: 'chat.completion',
122
- created: Math.floor(Date.now() / 1000),
58
+ createdAt: Math.floor(Date.now() / 1000),
123
59
  model: model.id,
124
- choices: [
125
- {
126
- index: 0,
127
- message: {
128
- role: 'assistant',
129
- content: text,
130
- },
131
- finish_reason: 'stop',
132
- },
133
- ],
134
- usage: {
135
- prompt_tokens: promptTokens,
136
- completion_tokens: completionTokens,
137
- total_tokens: promptTokens + completionTokens,
138
- },
60
+ status: 'completed',
61
+ output: [{ type: 'message', role: 'assistant', content: [{ type: 'text', text }] }],
62
+ usage: { inputTokens, outputTokens, totalTokens: inputTokens + outputTokens },
139
63
  };
140
64
  }
141
65
  }
@@ -0,0 +1,9 @@
1
+ import type { ModelServicePlugin } from '../plugins/types.js';
2
+ import type { ProviderConfig } from '../config/types.js';
3
+ import type { LLMProvider } from './base.js';
4
+ /**
5
+ * Versioned model-service plugins expose Chat as their EXTERNAL contract.
6
+ * This is the only core-owned Chat bridge on a non-Chat wire; orchestration and
7
+ * every built-in provider remain canonical throughout.
8
+ */
9
+ export declare function createPluginProvider(plugin: ModelServicePlugin, config: ProviderConfig): LLMProvider;
@@ -0,0 +1,31 @@
1
+ import { chatResponseToIR, irToChatRequest } from '../ir/adapters/openai-chat.js';
2
+ import { ChatStreamDecoder } from '../ir/adapters/openai-chat-stream.js';
3
+ /**
4
+ * Versioned model-service plugins expose Chat as their EXTERNAL contract.
5
+ * This is the only core-owned Chat bridge on a non-Chat wire; orchestration and
6
+ * every built-in provider remain canonical throughout.
7
+ */
8
+ export function createPluginProvider(plugin, config) {
9
+ const provider = plugin.createProvider(config);
10
+ return {
11
+ name: provider.name,
12
+ supportsStreaming: () => typeof provider.createStream === 'function',
13
+ async createCompletion(request, model, upstreamEventContext, credential) {
14
+ const response = await provider.createCompletion(irToChatRequest(request, model.upstreamModel, { carrierExtensions: false }), model, upstreamEventContext, credential);
15
+ return chatResponseToIR(response);
16
+ },
17
+ async createStream(request, model, upstreamEventContext, credential) {
18
+ if (!provider.createStream)
19
+ throw new Error(`Plugin provider '${provider.name}' has no stream executor`);
20
+ const stream = await provider.createStream(irToChatRequest(request, model.upstreamModel, { carrierExtensions: false }), model, upstreamEventContext, credential);
21
+ return {
22
+ async *[Symbol.asyncIterator]() {
23
+ const decoder = new ChatStreamDecoder();
24
+ for await (const chunk of stream)
25
+ yield* decoder.push(chunk);
26
+ yield* decoder.finish();
27
+ },
28
+ };
29
+ },
30
+ };
31
+ }
@@ -5,6 +5,17 @@ import type { CanonicalRequest, CanonicalResponse } from '../ir/types.js';
5
5
  import type { StreamRelay } from '../utils/stream-relay.js';
6
6
  import { CircuitBreakerManager, type ModelAvailability, type ModelHealthView } from '../resilience/index.js';
7
7
  import { type ExpandedMembers } from './member-match.js';
8
+ /**
9
+ * Outbound egress of ONE dial attempt (ADR-0018 vocabulary): straight out of
10
+ * the machine, or through the operator's outbound proxy (ADR-0022), whose
11
+ * redacted endpoint rides along. Absent = unknown — never read as direct.
12
+ */
13
+ export type AttemptEgress = {
14
+ mode: 'direct';
15
+ } | {
16
+ mode: 'proxy';
17
+ origin: string;
18
+ };
8
19
  export declare class ProviderRegistry {
9
20
  private providers;
10
21
  private models;
@@ -47,8 +58,8 @@ export declare class ProviderRegistry {
47
58
  */
48
59
  private credentialChains;
49
60
  private mockMode;
50
- private autoRefreshTierMatch;
51
- private lastMatchRefreshAt;
61
+ private autoRefreshMembers;
62
+ private lastMembersRefreshAt;
52
63
  constructor(config: RouterConfig, mockMode?: boolean, providerConfigs?: ProviderConfig[]);
53
64
  registerProvider(name: string, provider: LLMProvider, credentialChain?: CallCredential[],
54
65
  /** Boot config for the provider (baseUrl/headers/…). Required for wires
@@ -141,9 +152,8 @@ export declare class ProviderRegistry {
141
152
  getActiveCredential(name: string): CallCredential | undefined;
142
153
  /**
143
154
  * Why a model is rejected from every pool ('' = allowed). The ONLY pool
144
- * filter left: the GLOBAL denylist (tiers.exclude) — unconditional, it
145
- * outranks even an explicit pin. Per-tier vetoes (match.exclude)
146
- * and the model-side excludeTiers live inside the classification gate.
155
+ * filter: the GLOBAL denylist (tiers.exclude) — unconditional, it outranks
156
+ * even an explicit pin.
147
157
  */
148
158
  private policyRejectionReason;
149
159
  /** Weight of a model inside a tier: from THIS tier's claiming member rule
@@ -170,9 +180,10 @@ export declare class ProviderRegistry {
170
180
  * Membership is a PER-TIER projection of the member lists: every rule in
171
181
  * THIS tier's list claims models independently of the other tiers, so a
172
182
  * model (or a combo's expanded members) may join several pools at once.
173
- * Hand-configured models (no tierMatch) are reclassification-immune: they
174
- * join exactly their explicit tier, with weight from this tier's matching
175
- * rule when one exists (default 1). Chain order = claiming-rule weight
183
+ * Hand-configured models (no autoTier stamp) never move: their explicit
184
+ * tier is permanent. They join exactly their explicit tier, with weight
185
+ * from this tier's matching rule when one exists (default 1). Chain order =
186
+ * claiming-rule weight
176
187
  * (desc) then rule list position (asc); entries carry the claiming rule's
177
188
  * weight and effortMap — the translation that applies when the model
178
189
  * serves from THIS pool.
@@ -182,9 +193,9 @@ export declare class ProviderRegistry {
182
193
  * The effort translation that applies when `model` serves from `tier`'s
183
194
  * pool: the claiming rule's effortMap in THAT tier (a model holding
184
195
  * membership in several tiers translates differently per pool).
185
- * Hand-configured models keep their stored translation
186
- * (reclassification-immune); a model absent from this tier (escalation-tail
187
- * resolution) falls back to the stored home-tier translation.
196
+ * Hand-configured models keep their stored translation; a model absent from
197
+ * this tier (escalation-tail resolution) falls back to the stored home-tier
198
+ * translation.
188
199
  */
189
200
  effortMapFor(model: ModelRegistration, tier: TierLevel): EffortMap | undefined;
190
201
  /**
@@ -194,17 +205,17 @@ export declare class ProviderRegistry {
194
205
  */
195
206
  tiersOf(model: ModelRegistration): TierLevel[];
196
207
  /**
197
- * Runtime tier reclassification — tier membership is pure file-derived data
208
+ * Runtime tier membership replay — membership is pure file-derived data
198
209
  * (config `tiers[t].members`), replayed against each model id on
199
210
  * pool resolution instead of waiting for a gateway restart. Model UNIVERSE
200
211
  * (providers/credentials/wire) stays a boot snapshot.
201
212
  */
202
213
  /** Hot-path guard: replay member lists + the combo map + policies at most every 2 seconds. */
203
- private maybeRefreshTierMatch;
204
- /** Latest committed `tiers` config (snapshot; updated by applyTierConfigNow / maybeRefreshTierMatch). */
214
+ private maybeRefreshMembers;
215
+ /** Latest committed `tiers` config (snapshot; updated by applyTierConfigNow / maybeRefreshMembers). */
205
216
  getTierPolicies(): TiersConfig;
206
217
  /** Test hook: silence the lazy config re-read (explicit reclassifyTiers still works). */
207
- setAutoRefreshTierMatch(on: boolean): void;
218
+ setAutoRefreshMembers(on: boolean): void;
208
219
  /** Registered member refs of one combo (config order, deduped, unregistered
209
220
  dropped) — null when the ref is dead: unknown id, operator-disabled, or
210
221
  shadowed by a registered model. */
@@ -219,11 +230,11 @@ export declare class ProviderRegistry {
219
230
  /**
220
231
  * COMMIT path — the only one that rewrites live pool membership. Called on
221
232
  * every config-save event (console routes) so edits take effect immediately;
222
- * the lazy maybeRefreshTierMatch replay (tiers AND combos) remains only as
233
+ * the lazy maybeRefreshMembers replay (tiers AND combos) remains only as
223
234
  * the out-of-band (hand-edited YAML) safety net.
224
235
  */
225
236
  applyTierConfigNow(): void;
226
- /** Replays the member lists over every reclassifiable model and stores
237
+ /** Replays the member lists over every stamped model and stores
227
238
  * them as the committed pool view (buildTierPoolEntries reads exactly this
228
239
  * snapshot). What is stored per model is the DERIVED HOME view used by
229
240
  * single-tier consumers (pinned force_tier, tier-keyed reporting,
@@ -235,9 +246,9 @@ export declare class ProviderRegistry {
235
246
  * Returns all candidate models registered for a given tier, in chain order
236
247
  * (member-list order). If healthyOnly is true, only returns models
237
248
  * where the circuit breaker allows execution. The global denylist
238
- * (tiers.exclude) is applied first; unclaimed (`unclassified`) models join no
239
- * pool. Membership is the per-tier projection (buildTierPoolEntries) —
240
- * a model may serve in several tiers at once.
249
+ * (tiers.exclude) is applied first; models no member list claims (no home
250
+ * tier) join no pool. Membership is the per-tier projection
251
+ * (buildTierPoolEntries) — a model may serve in several tiers at once.
241
252
  */
242
253
  getCandidateModelsForTier(tier: TierLevel, healthyOnly?: boolean, opts?: {
243
254
  decisionSurface?: boolean;
@@ -321,7 +332,7 @@ export declare class ProviderRegistry {
321
332
  }[];
322
333
  /**
323
334
  * (Re)register combo definitions — used at boot, for hot-apply on console
324
- * config saves, and by the lazy maybeRefreshTierMatch safety net. A section
335
+ * config saves, and by the lazy maybeRefreshMembers safety net. A section
325
336
  * byte-identical to the last applied one is a no-op (keeps round-robin
326
337
  * cursors, avoids repeat skip warnings): skip outcomes depend only on the
327
338
  * section plus the monotonically grown model map, and every read path
@@ -355,9 +366,10 @@ export declare class ProviderRegistry {
355
366
  * freshly-edited form state for previews without committing; runtime
356
367
  * callers omit it and get the construction-time snapshot. Pool order =
357
368
  * rule weight (desc) then member-list order; entries carry the claiming
358
- * rule's weight (default 1). `unclassified` is the diagnostic fourth state:
369
+ * rule's weight (default 1). `'unclassified'` is the diagnostic fourth state:
359
370
  * models claimed by NO tier (it is never hidden by the denylist — the
360
- * console must show it for the unpooled view / one-click join).
371
+ * console must show it for the unpooled view / one-click join). A model is
372
+ * in this view exactly when its home tier is undefined.
361
373
  */
362
374
  resolveTierPool(tier: PoolMembership, policiesOverride?: TiersConfig): {
363
375
  pool: {
@@ -369,6 +381,17 @@ export declare class ProviderRegistry {
369
381
  reason: string;
370
382
  }[];
371
383
  };
384
+ /**
385
+ * Outbound egress the CORE transport will take for `model`, resolved from
386
+ * the same `resolveProxyUrl` the executors call at dial time (ADR-0018 /
387
+ * ADR-0022). Call this IMMEDIATELY before `execute()` and keep the value
388
+ * with the attempt: the proxy config hot-applies, so a read after a long
389
+ * stream can describe a different dial.
390
+ *
391
+ * `undefined` = UNKNOWN, never direct: nothing was dialed (mock mode) or
392
+ * the transport does not report its dial base (plugin-owned executors).
393
+ */
394
+ egressFor(model: ModelRegistration): AttemptEgress | undefined;
372
395
  /**
373
396
  * Execute one completion. `credentialKeyHashPrefix`
374
397
  * selects one credential of the provider's registered chain by its Decision 5
@@ -378,6 +401,8 @@ export declare class ProviderRegistry {
378
401
  * when a chain is registered — the attribution seam for the P3 pair-level
379
402
  * breaker work (no classification changes here).
380
403
  */
381
- execute(request: CanonicalRequest, model: ModelRegistration, upstreamEventContext?: UpstreamEventContext, credentialKeyHashPrefix?: string, relay?: StreamRelay): Promise<CanonicalResponse>;
404
+ execute(request: CanonicalRequest, model: ModelRegistration, upstreamEventContext?: UpstreamEventContext, credentialKeyHashPrefix?: string, relay?: StreamRelay,
405
+ /** Resolved OCR conversation id. Not a capture field. */
406
+ sessionId?: string): Promise<CanonicalResponse>;
382
407
  private mockExecute;
383
408
  }