omnicell-router 0.8.4 → 0.10.0
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.
- package/README.md +26 -7
- package/README.zh-CN.md +18 -5
- package/backend/dist/capture/recorder.d.ts +4 -10
- package/backend/dist/capture/recorder.js +6 -58
- package/backend/dist/cli/clients/base.d.ts +36 -11
- package/backend/dist/cli/clients/base.js +31 -15
- package/backend/dist/cli/clients/claude.d.ts +9 -0
- package/backend/dist/cli/clients/claude.js +6 -0
- package/backend/dist/cli/clients/codex.d.ts +8 -0
- package/backend/dist/cli/clients/codex.js +5 -0
- package/backend/dist/cli/clients/core-adapters.d.ts +1 -1
- package/backend/dist/cli/clients/core-adapters.js +1 -1
- package/backend/dist/cli/clients/dsh.d.ts +8 -0
- package/backend/dist/cli/clients/dsh.js +5 -0
- package/backend/dist/cli/clients/grok.d.ts +15 -1
- package/backend/dist/cli/clients/grok.js +16 -2
- package/backend/dist/cli/clients/index.d.ts +13 -1
- package/backend/dist/cli/clients/index.js +97 -19
- package/backend/dist/cli/clients/kimi.d.ts +6 -0
- package/backend/dist/cli/clients/kimi.js +3 -0
- package/backend/dist/cli/clients/launcher.d.ts +1 -1
- package/backend/dist/cli/clients/model-meta.js +6 -3
- package/backend/dist/cli/clients/omp.d.ts +6 -0
- package/backend/dist/cli/clients/omp.js +3 -0
- package/backend/dist/cli/clients/openclaw.d.ts +6 -0
- package/backend/dist/cli/clients/openclaw.js +3 -0
- package/backend/dist/cli/clients/opencode.d.ts +8 -0
- package/backend/dist/cli/clients/opencode.js +5 -0
- package/backend/dist/cli/clients/pi.d.ts +6 -0
- package/backend/dist/cli/clients/pi.js +3 -0
- package/backend/dist/cli/clients/update-check.d.ts +37 -0
- package/backend/dist/cli/clients/update-check.js +309 -0
- package/backend/dist/cli/clients/workbuddy.d.ts +19 -0
- package/backend/dist/cli/clients/workbuddy.js +66 -0
- package/backend/dist/cli/index.js +5 -4
- package/backend/dist/cli/paths.js +8 -0
- package/backend/dist/cli/types.d.ts +92 -16
- package/backend/dist/config/comments-en.js +31 -26
- package/backend/dist/config/comments-zh.js +29 -24
- package/backend/dist/config/defaults.d.ts +194 -33
- package/backend/dist/config/defaults.js +193 -32
- package/backend/dist/config/env.d.ts +10 -0
- package/backend/dist/config/env.js +3 -2
- package/backend/dist/config/index.d.ts +7 -0
- package/backend/dist/config/index.js +184 -43
- package/backend/dist/config/migrations/v0-to-v1.d.ts +2 -2
- package/backend/dist/config/migrations/v10-to-v11.d.ts +38 -0
- package/backend/dist/config/migrations/v10-to-v11.js +43 -0
- package/backend/dist/config/migrations/v6-to-v7.d.ts +45 -0
- package/backend/dist/config/migrations/v6-to-v7.js +97 -0
- package/backend/dist/config/migrations/v7-to-v8.d.ts +36 -0
- package/backend/dist/config/migrations/v7-to-v8.js +43 -0
- package/backend/dist/config/migrations/v8-to-v9.d.ts +38 -0
- package/backend/dist/config/migrations/v8-to-v9.js +43 -0
- package/backend/dist/config/migrations/v9-to-v10.d.ts +51 -0
- package/backend/dist/config/migrations/v9-to-v10.js +71 -0
- package/backend/dist/config/runtime.js +1 -1
- package/backend/dist/config/schema.d.ts +3 -3
- package/backend/dist/config/schema.js +14 -4
- package/backend/dist/config/types.d.ts +167 -38
- package/backend/dist/egress-proxy/asset-download.d.ts +54 -0
- package/backend/dist/egress-proxy/asset-download.js +420 -0
- package/backend/dist/egress-proxy/manual-node-spec.d.ts +92 -0
- package/backend/dist/egress-proxy/manual-node-spec.js +408 -0
- package/backend/dist/egress-proxy/mihomo-binary.d.ts +54 -0
- package/backend/dist/egress-proxy/mihomo-binary.js +278 -0
- package/backend/dist/egress-proxy/mihomo-client.d.ts +94 -0
- package/backend/dist/egress-proxy/mihomo-client.js +308 -0
- package/backend/dist/egress-proxy/mihomo-config.d.ts +40 -0
- package/backend/dist/egress-proxy/mihomo-config.js +161 -0
- package/backend/dist/egress-proxy/mihomo-geo.d.ts +87 -0
- package/backend/dist/egress-proxy/mihomo-geo.js +213 -0
- package/backend/dist/egress-proxy/mihomo-logs.d.ts +43 -0
- package/backend/dist/egress-proxy/mihomo-logs.js +84 -0
- package/backend/dist/egress-proxy/mihomo-pac.d.ts +37 -0
- package/backend/dist/egress-proxy/mihomo-pac.js +75 -0
- package/backend/dist/egress-proxy/mihomo-rules-import.d.ts +43 -0
- package/backend/dist/egress-proxy/mihomo-rules-import.js +193 -0
- package/backend/dist/egress-proxy/mihomo-sidecar.d.ts +81 -0
- package/backend/dist/egress-proxy/mihomo-sidecar.js +637 -0
- package/backend/dist/forward-proxy/egress.d.ts +50 -11
- package/backend/dist/forward-proxy/egress.js +50 -17
- package/backend/dist/forward-proxy/h2-forward.js +36 -10
- package/backend/dist/forward-proxy/index.d.ts +11 -8
- package/backend/dist/forward-proxy/index.js +22 -60
- package/backend/dist/forward-proxy/interceptor.d.ts +3 -2
- package/backend/dist/forward-proxy/interceptor.js +4 -4
- package/backend/dist/forward-proxy/relay.js +3 -3
- package/backend/dist/forward-proxy/rules.d.ts +4 -4
- package/backend/dist/forward-proxy/rules.js +25 -4
- package/backend/dist/forward-proxy/server.d.ts +0 -16
- package/backend/dist/forward-proxy/server.js +124 -156
- package/backend/dist/harness/host/hosts.js +3 -2
- package/backend/dist/index.js +53 -18
- package/backend/dist/ingress-proxy/access-log.d.ts +176 -0
- package/backend/dist/ingress-proxy/access-log.js +774 -0
- package/backend/dist/ingress-proxy/ca-inventory.d.ts +106 -0
- package/backend/dist/ingress-proxy/ca-inventory.js +525 -0
- package/backend/dist/ingress-proxy/ca-trust.d.ts +96 -0
- package/backend/dist/ingress-proxy/ca-trust.js +315 -0
- package/backend/dist/ingress-proxy/ca.d.ts +104 -0
- package/backend/dist/ingress-proxy/ca.js +273 -0
- package/backend/dist/ingress-proxy/data-dir.d.ts +28 -0
- package/backend/dist/ingress-proxy/data-dir.js +45 -0
- package/backend/dist/ingress-proxy/egress.d.ts +151 -0
- package/backend/dist/ingress-proxy/egress.js +364 -0
- package/backend/dist/ingress-proxy/h2-forward.d.ts +66 -0
- package/backend/dist/ingress-proxy/h2-forward.js +561 -0
- package/backend/dist/ingress-proxy/index.d.ts +24 -0
- package/backend/dist/ingress-proxy/index.js +144 -0
- package/backend/dist/ingress-proxy/interceptor.d.ts +25 -0
- package/backend/dist/ingress-proxy/interceptor.js +52 -0
- package/backend/dist/ingress-proxy/ordered-relay.d.ts +29 -0
- package/backend/dist/ingress-proxy/ordered-relay.js +46 -0
- package/backend/dist/ingress-proxy/relay.d.ts +54 -0
- package/backend/dist/ingress-proxy/relay.js +188 -0
- package/backend/dist/ingress-proxy/rules.d.ts +195 -0
- package/backend/dist/ingress-proxy/rules.js +348 -0
- package/backend/dist/ingress-proxy/server.d.ts +153 -0
- package/backend/dist/ingress-proxy/server.js +2065 -0
- package/backend/dist/ingress-proxy/sni.d.ts +35 -0
- package/backend/dist/ingress-proxy/sni.js +124 -0
- package/backend/dist/ingress-proxy/status.d.ts +32 -0
- package/backend/dist/ingress-proxy/status.js +15 -0
- package/backend/dist/ingress-proxy/system-proxy.d.ts +112 -0
- package/backend/dist/ingress-proxy/system-proxy.js +481 -0
- package/backend/dist/ingress-proxy/traffic-delete.d.ts +21 -0
- package/backend/dist/ingress-proxy/traffic-delete.js +64 -0
- package/backend/dist/ingress-proxy/traffic-delete.worker.d.ts +44 -0
- package/backend/dist/ingress-proxy/traffic-delete.worker.js +228 -0
- package/backend/dist/ingress-proxy/traffic-files.d.ts +10 -0
- package/backend/dist/ingress-proxy/traffic-files.js +10 -0
- package/backend/dist/ingress-proxy/upstream-tls.d.ts +46 -0
- package/backend/dist/ingress-proxy/upstream-tls.js +105 -0
- package/backend/dist/ingress-proxy/ws-frames.d.ts +45 -0
- package/backend/dist/ingress-proxy/ws-frames.js +153 -0
- package/backend/dist/ir/adapters/anthropic-messages-stream.js +6 -1
- package/backend/dist/ir/adapters/anthropic-messages.js +12 -5
- package/backend/dist/ir/adapters/google-gemini-stream.js +7 -2
- package/backend/dist/ir/adapters/google-gemini.js +5 -2
- package/backend/dist/ir/adapters/openai-chat-stream.js +5 -1
- package/backend/dist/ir/adapters/openai-chat.d.ts +25 -0
- package/backend/dist/ir/adapters/openai-chat.js +45 -3
- package/backend/dist/ir/adapters/openai-responses-output.d.ts +1 -0
- package/backend/dist/ir/adapters/openai-responses-output.js +67 -21
- package/backend/dist/ir/adapters/openai-responses-stream.d.ts +13 -0
- package/backend/dist/ir/adapters/openai-responses-stream.js +34 -1
- package/backend/dist/ir/adapters/openai-responses.d.ts +82 -24
- package/backend/dist/ir/adapters/openai-responses.js +146 -37
- package/backend/dist/ir/media.d.ts +20 -0
- package/backend/dist/ir/media.js +41 -0
- package/backend/dist/ir/tool-identity.d.ts +35 -0
- package/backend/dist/ir/tool-identity.js +40 -0
- package/backend/dist/ir/types.d.ts +9 -1
- package/backend/dist/local/build-jobs.d.ts +66 -0
- package/backend/dist/local/build-jobs.js +243 -0
- package/backend/dist/local/detect.d.ts +32 -0
- package/backend/dist/local/detect.js +145 -0
- package/backend/dist/local/draft-match.d.ts +58 -0
- package/backend/dist/local/draft-match.js +124 -0
- package/backend/dist/local/engine-runtime.d.ts +522 -0
- package/backend/dist/local/engine-runtime.js +1 -0
- package/backend/dist/local/engines.d.ts +241 -0
- package/backend/dist/local/engines.js +651 -0
- package/backend/dist/local/gguf.d.ts +35 -0
- package/backend/dist/local/gguf.js +314 -0
- package/backend/dist/local/hf.d.ts +120 -0
- package/backend/dist/local/hf.js +304 -0
- package/backend/dist/local/install.d.ts +90 -0
- package/backend/dist/local/install.js +421 -0
- package/backend/dist/local/llamacpp.d.ts +55 -0
- package/backend/dist/local/llamacpp.js +177 -0
- package/backend/dist/local/local-provider.d.ts +81 -0
- package/backend/dist/local/local-provider.js +301 -0
- package/backend/dist/local/machine-stats.d.ts +87 -0
- package/backend/dist/local/machine-stats.js +332 -0
- package/backend/dist/local/model-store.d.ts +347 -0
- package/backend/dist/local/model-store.js +1215 -0
- package/backend/dist/local/part-sweep.d.ts +32 -0
- package/backend/dist/local/part-sweep.js +156 -0
- package/backend/dist/local/plan.d.ts +65 -0
- package/backend/dist/local/plan.js +146 -0
- package/backend/dist/local/resources.d.ts +49 -0
- package/backend/dist/local/resources.js +64 -0
- package/backend/dist/local/run-stats.d.ts +95 -0
- package/backend/dist/local/run-stats.js +195 -0
- package/backend/dist/local/runner.d.ts +235 -0
- package/backend/dist/local/runner.js +1392 -0
- package/backend/dist/local/settings.d.ts +79 -0
- package/backend/dist/local/settings.js +180 -0
- package/backend/dist/local/strata-catalog.d.ts +30 -0
- package/backend/dist/local/strata-catalog.js +511 -0
- package/backend/dist/local/strata-drafting.d.ts +46 -0
- package/backend/dist/local/strata-drafting.js +265 -0
- package/backend/dist/local/strata.d.ts +278 -0
- package/backend/dist/local/strata.js +1392 -0
- package/backend/dist/local/tar.d.ts +20 -0
- package/backend/dist/local/tar.js +367 -0
- package/backend/dist/local/transport.d.ts +35 -0
- package/backend/dist/local/transport.js +89 -0
- package/backend/dist/local/tune.d.ts +58 -0
- package/backend/dist/local/tune.js +324 -0
- package/backend/dist/observability/http-exchange.d.ts +2 -2
- package/backend/dist/opencode/catalog/auto-pull.d.ts +14 -3
- package/backend/dist/opencode/catalog/auto-pull.js +276 -70
- package/backend/dist/opencode/catalog/ocr-store.js +3 -1
- package/backend/dist/opencode/catalog/overrides-store.d.ts +10 -1
- package/backend/dist/opencode/catalog/overrides-store.js +6 -0
- package/backend/dist/opencode/catalog/reasoning-declaration.d.ts +35 -0
- package/backend/dist/opencode/catalog/reasoning-declaration.js +66 -0
- package/backend/dist/opencode/catalog/repository.js +25 -2
- package/backend/dist/opencode/catalog/sources/models-dev.js +13 -3
- package/backend/dist/opencode/catalog/types.d.ts +35 -3
- package/backend/dist/opencode/catalog/types.js +38 -1
- package/backend/dist/opencode/credentials/ocr-store.js +11 -2
- package/backend/dist/opencode/credentials/sync.js +12 -3
- package/backend/dist/opencode/credentials/types.d.ts +31 -4
- package/backend/dist/opencode/credentials/types.js +25 -0
- package/backend/dist/opencode/probe.d.ts +21 -4
- package/backend/dist/opencode/probe.js +34 -10
- package/backend/dist/pipeline/directives.d.ts +9 -4
- package/backend/dist/pipeline/directives.js +14 -10
- package/backend/dist/pipeline/orchestrator.d.ts +42 -13
- package/backend/dist/pipeline/orchestrator.js +497 -165
- package/backend/dist/plugins/environment-ack.d.ts +51 -0
- package/backend/dist/plugins/environment-ack.js +81 -0
- package/backend/dist/plugins/gateways.d.ts +6 -6
- package/backend/dist/plugins/gateways.js +2 -2
- package/backend/dist/plugins/host.d.ts +98 -14
- package/backend/dist/plugins/host.js +622 -87
- package/backend/dist/plugins/install-run.d.ts +27 -0
- package/backend/dist/plugins/install-run.js +99 -0
- package/backend/dist/plugins/manifest.d.ts +84 -32
- package/backend/dist/plugins/manifest.js +149 -45
- package/backend/dist/plugins/market-install.d.ts +18 -0
- package/backend/dist/plugins/market-install.js +111 -0
- package/backend/dist/plugins/market-source.d.ts +100 -0
- package/backend/dist/plugins/market-source.js +449 -0
- package/backend/dist/plugins/market-updates.d.ts +70 -0
- package/backend/dist/plugins/market-updates.js +97 -0
- package/backend/dist/plugins/market.d.ts +677 -0
- package/backend/dist/plugins/market.js +2113 -0
- package/backend/dist/plugins/source-index.d.ts +155 -0
- package/backend/dist/plugins/source-index.js +217 -0
- package/backend/dist/plugins/types.d.ts +402 -37
- package/backend/dist/projects/worktrees.d.ts +88 -0
- package/backend/dist/projects/worktrees.js +220 -0
- package/backend/dist/providers/boot-direct.d.ts +41 -7
- package/backend/dist/providers/boot-direct.js +252 -36
- package/backend/dist/providers/compat/tool-markup-recovery.js +31 -6
- package/backend/dist/providers/executors/dispatch.d.ts +17 -7
- package/backend/dist/providers/executors/dispatch.js +28 -9
- package/backend/dist/providers/executors/openai-chat.js +14 -2
- package/backend/dist/providers/executors/plugin-adapter.d.ts +23 -1
- package/backend/dist/providers/executors/plugin-adapter.js +59 -3
- package/backend/dist/providers/member-match.d.ts +32 -9
- package/backend/dist/providers/member-match.js +65 -21
- package/backend/dist/providers/model-resolution.d.ts +62 -0
- package/backend/dist/providers/model-resolution.js +62 -0
- package/backend/dist/providers/price-order.d.ts +51 -0
- package/backend/dist/providers/price-order.js +54 -0
- package/backend/dist/providers/provider-takedown.d.ts +5 -2
- package/backend/dist/providers/registry.d.ts +84 -25
- package/backend/dist/providers/registry.js +209 -114
- package/backend/dist/providers/selection.d.ts +91 -0
- package/backend/dist/providers/selection.js +158 -0
- package/backend/dist/providers/virtual-meta.d.ts +33 -2
- package/backend/dist/providers/virtual-meta.js +74 -18
- package/backend/dist/quota/cli-login.d.ts +25 -4
- package/backend/dist/quota/cli-login.js +35 -5
- package/backend/dist/quota/coverage-generation.d.ts +24 -0
- package/backend/dist/quota/coverage-generation.js +29 -0
- package/backend/dist/quota/declarations.js +8 -4
- package/backend/dist/quota/engine.js +2 -2
- package/backend/dist/quota/prober.d.ts +43 -2
- package/backend/dist/quota/prober.js +97 -22
- package/backend/dist/ratelimit/rate-limiter.d.ts +1 -1
- package/backend/dist/resilience/error-classifier.js +29 -0
- package/backend/dist/router/index.d.ts +1 -1
- package/backend/dist/router/index.js +17 -1
- package/backend/dist/router/layer2-decision.d.ts +1 -1
- package/backend/dist/router/layer2-decision.js +2 -2
- package/backend/dist/routes/console.js +928 -310
- package/backend/dist/routes/environments.js +1 -1
- package/backend/dist/routes/local-models.d.ts +2 -0
- package/backend/dist/routes/local-models.js +1414 -0
- package/backend/dist/routes/mihomo.d.ts +2 -2
- package/backend/dist/routes/mihomo.js +20 -11
- package/backend/dist/routes/projects.js +121 -0
- package/backend/dist/server.js +318 -13
- package/backend/dist/session/session-manager.d.ts +42 -5
- package/backend/dist/session/session-manager.js +64 -11
- package/backend/dist/session/session-row.d.ts +29 -8
- package/backend/dist/session/session-row.js +18 -13
- package/backend/dist/snapshot/bundle.d.ts +40 -0
- package/backend/dist/snapshot/bundle.js +177 -0
- package/backend/dist/snapshot/handoff/compress.d.ts +46 -0
- package/backend/dist/snapshot/handoff/compress.js +77 -0
- package/backend/dist/snapshot/handoff/index.d.ts +119 -0
- package/backend/dist/snapshot/handoff/index.js +160 -0
- package/backend/dist/snapshot/handoff/jsonl-writer.d.ts +78 -0
- package/backend/dist/snapshot/handoff/jsonl-writer.js +175 -0
- package/backend/dist/snapshot/handoff/opencode-writer.d.ts +51 -0
- package/backend/dist/snapshot/handoff/opencode-writer.js +214 -0
- package/backend/dist/snapshot/handoff/summarize.d.ts +39 -0
- package/backend/dist/snapshot/handoff/summarize.js +118 -0
- package/backend/dist/snapshot/handoff/transcript.d.ts +71 -0
- package/backend/dist/snapshot/handoff/transcript.js +167 -0
- package/backend/dist/snapshot/media-fs.d.ts +10 -0
- package/backend/dist/snapshot/media-fs.js +50 -0
- package/backend/dist/snapshot/media.d.ts +32 -0
- package/backend/dist/snapshot/media.js +87 -0
- package/backend/dist/snapshot/store.d.ts +226 -0
- package/backend/dist/snapshot/store.js +887 -0
- package/backend/dist/snapshot/tree.d.ts +112 -0
- package/backend/dist/snapshot/tree.js +207 -0
- package/backend/dist/snapshot/types.d.ts +212 -0
- package/backend/dist/snapshot/types.js +14 -0
- package/backend/dist/snapshot/view.d.ts +19 -0
- package/backend/dist/snapshot/view.js +57 -0
- package/backend/dist/snapshot/write-worker.d.ts +67 -0
- package/backend/dist/snapshot/write-worker.js +129 -0
- package/backend/dist/surfaces/body-admission.d.ts +67 -2
- package/backend/dist/surfaces/body-admission.js +218 -13
- package/backend/dist/surfaces/chat-pipeline.js +8 -0
- package/backend/dist/surfaces/decision-pipeline.js +10 -7
- package/backend/dist/surfaces/gateway-catalog.d.ts +26 -0
- package/backend/dist/surfaces/gateway-catalog.js +202 -0
- package/backend/dist/surfaces/gateway-chat.d.ts +7 -11
- package/backend/dist/surfaces/gateway-chat.js +50 -12
- package/backend/dist/surfaces/ocr-headers.d.ts +6 -4
- package/backend/dist/surfaces/ocr-headers.js +11 -7
- package/backend/dist/surfaces/systemone.js +1 -1
- package/backend/dist/surfaces/transport-fastify.js +32 -5
- package/backend/dist/surfaces/transport-node-http.d.ts +9 -3
- package/backend/dist/surfaces/transport-node-http.js +6 -19
- package/backend/dist/surfaces/types.d.ts +11 -3
- package/backend/dist/trace/persist.js +21 -1
- package/backend/dist/trace/tracker.d.ts +35 -3
- package/backend/dist/trace/tracker.js +23 -0
- package/backend/dist/types/openai.d.ts +8 -0
- package/backend/dist/types/router.d.ts +17 -6
- package/backend/dist/types/router.js +14 -2
- package/backend/dist/utils/client-families.d.ts +66 -0
- package/backend/dist/utils/client-families.js +127 -0
- package/backend/dist/utils/event-ring.d.ts +1 -1
- package/backend/dist/utils/event-ring.js +1 -1
- package/backend/dist/utils/proxy-node.js +1 -1
- package/backend/dist/utils/proxy.d.ts +135 -11
- package/backend/dist/utils/proxy.js +144 -29
- package/backend/dist/utils/run-command.d.ts +21 -1
- package/backend/dist/utils/run-command.js +64 -4
- package/backend/dist/utils/server-liveness.d.ts +3 -2
- package/backend/dist/utils/server-liveness.js +3 -2
- package/backend/dist/utils/session-file.d.ts +28 -0
- package/backend/dist/utils/session-file.js +34 -0
- package/frontend/dist/assets/antigravity.color-DXFfVr6X.svg +39 -0
- package/frontend/dist/assets/gemini-cli.color-BfquLd1p.svg +1 -0
- package/frontend/dist/assets/index-CTZNvn1d.js +1707 -0
- package/frontend/dist/assets/{index-KI1OW5x6.css → index-CqDSOPQ0.css} +1 -1
- package/frontend/dist/index.html +2 -2
- package/package.json +3 -1
- package/frontend/dist/assets/index-Dk76uc7e.js +0 -1522
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import crypto from 'node:crypto';
|
|
2
|
-
import { RESPONSES_CALL_ID_MAX_LEN } from '../../config/defaults.js';
|
|
2
|
+
import { RESPONSES_CALL_ID_MAX_LEN, RESPONSES_TOOL_ITEM_ID_MAX_LEN } from '../../config/defaults.js';
|
|
3
3
|
import { IrUnsupportedError } from '../errors.js';
|
|
4
4
|
import { DATA_URL_RE } from '../media.js';
|
|
5
5
|
import { assertCanonicalRequestSupported } from '../validate.js';
|
|
6
|
+
import { CALL_ID_PREFIX, upstreamToolCallId } from '../tool-identity.js';
|
|
6
7
|
const PROTOCOL = 'openai-responses';
|
|
7
8
|
function record(value) {
|
|
8
9
|
return value && typeof value === 'object' ? value : {};
|
|
@@ -111,7 +112,11 @@ export function responsesPartToWire(part, role) {
|
|
|
111
112
|
if (part.type === 'extension') {
|
|
112
113
|
if (part.protocol !== PROTOCOL)
|
|
113
114
|
throw new IrUnsupportedError('content_part', `Cannot convert ${part.protocol} content.`, PROTOCOL);
|
|
114
|
-
|
|
115
|
+
// A COPY, exactly as at item level (`openai-responses-output.ts`): rendering must never
|
|
116
|
+
// alias the canonical object the session store and capture hold, or the next field the
|
|
117
|
+
// encoder stamps onto the wire shape would edit the operator's record of the upstream
|
|
118
|
+
// body. The item copy and this one are ONE rule, not two conventions.
|
|
119
|
+
return { ...record(part.payload) };
|
|
115
120
|
}
|
|
116
121
|
if (part.type === 'text') {
|
|
117
122
|
return {
|
|
@@ -178,62 +183,157 @@ export function responsesToolToWire(tool) {
|
|
|
178
183
|
* - Injective: distinct tool-call ids MUST NOT collapse onto one item id. The
|
|
179
184
|
* chat client controls `tool_calls[].id`, so an id that is not safe both in
|
|
180
185
|
* charset and length is hashed instead of sanitized/truncated — dropping
|
|
181
|
-
* characters or a tail would silently merge two calls into one id.
|
|
186
|
+
* characters or a tail would silently merge two calls into one id. What MAY be
|
|
187
|
+
* shortened is the DIGEST (to RESPONSES_TOOL_ITEM_ID_MAX_LEN, because the
|
|
188
|
+
* item-type prefix eats the room RESPONSES_CALL_ID_MAX_LEN gives a bare
|
|
189
|
+
* correlation id), never the original string.
|
|
182
190
|
*/
|
|
191
|
+
/**
|
|
192
|
+
* The item-id namespace for a tool call (`fc_` for a function call, `ctc_` for a custom one).
|
|
193
|
+
* Declared once because the anchor mint in `openai-responses-output.ts` has to agree with it:
|
|
194
|
+
* a minted id that missed this prefix would come back double-prefixed.
|
|
195
|
+
*/
|
|
196
|
+
export function toolItemPrefix(custom) {
|
|
197
|
+
return custom ? 'ctc_' : 'fc_';
|
|
198
|
+
}
|
|
183
199
|
export function responsesToolItemId(id, custom) {
|
|
184
|
-
const prefix = custom
|
|
200
|
+
const prefix = toolItemPrefix(custom);
|
|
185
201
|
if (id.startsWith(prefix))
|
|
186
202
|
return id;
|
|
187
|
-
if (
|
|
203
|
+
if (idShape(RESPONSES_TOOL_ITEM_ID_MAX_LEN).test(id))
|
|
188
204
|
return prefix + id;
|
|
189
|
-
return prefix +
|
|
205
|
+
return prefix + idDigest(id, RESPONSES_TOOL_ITEM_ID_MAX_LEN);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* The one id charset both Responses id fields share, written once so the two
|
|
209
|
+
* budgets can never grow different rules (sha256 hex is inside it, which is what
|
|
210
|
+
* makes a hashed id legal).
|
|
211
|
+
*/
|
|
212
|
+
function idShape(maxLen) {
|
|
213
|
+
return new RegExp(`^[A-Za-z0-9_-]{1,${maxLen}}$`);
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* sha256 hex, shortened only as far as the destination field requires — callers
|
|
217
|
+
* subtract their own prefix (and any suffix they append) from the budget first.
|
|
218
|
+
* A budget above sha256's own 64 hex chars is satisfied by the full digest, so only
|
|
219
|
+
* the LOW side needs a guard: `slice(0, 0)` returns the whole digest and a NEGATIVE
|
|
220
|
+
* length returns `64 - n` characters, so an unguarded non-positive budget hands back
|
|
221
|
+
* a 64-char id when the caller asked for none. The floor makes a zero/negative budget
|
|
222
|
+
* yield ONE character — a caller that over-subtracts then gets an id that is still too
|
|
223
|
+
* long for its field (visible, and our own gate rewrites it), which is honest in a way
|
|
224
|
+
* a silent 64-char digest would not be.
|
|
225
|
+
*/
|
|
226
|
+
export function idDigest(id, maxLen) {
|
|
227
|
+
return crypto.createHash('sha256').update(id).digest('hex').slice(0, Math.max(maxLen, 1));
|
|
190
228
|
}
|
|
191
229
|
/** Charset + length budget for `call_id` (see RESPONSES_CALL_ID_MAX_LEN). */
|
|
192
|
-
const CALL_ID_SHAPE =
|
|
230
|
+
const CALL_ID_SHAPE = idShape(RESPONSES_CALL_ID_MAX_LEN);
|
|
193
231
|
/**
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
|
|
232
|
+
* Whether an id is ALREADY a legal `call_id`, so any projector can keep it byte-identical.
|
|
233
|
+
* Exported because the markup-recovery mint (`providers/compat/tool-markup-recovery.ts`) has
|
|
234
|
+
* to answer the same question about a response id it is about to embed — and because
|
|
235
|
+
* `slice`/`replace` on an id is never the right answer there (sanitising a response id is
|
|
236
|
+
* lossy, so it can alias two responses onto one correlation id). One charset, one predicate.
|
|
237
|
+
*/
|
|
238
|
+
export function isCanonicalResponsesCallId(id) {
|
|
239
|
+
return CALL_ID_SHAPE.test(id);
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* The `call_` correlation namespace is declared once, in `ir/tool-identity.ts`, because the
|
|
243
|
+
* upstream readers mint ids there and the markup-recovery mint builds ids in the same
|
|
244
|
+
* namespace — two declarations would be two drift twins of one rule.
|
|
245
|
+
*/
|
|
246
|
+
/**
|
|
247
|
+
* Canonical correlation id -> Responses `call_id`, with the same two invariants as
|
|
248
|
+
* `responsesToolItemId` plus the one it lacked: a FIELD BUDGET. Upstream Responses
|
|
249
|
+
* APIs validate this string's length, and a client id that arrived from another
|
|
250
|
+
* carrier (chat owns `tool_calls[].id`; the cursor-gateway loop re-injects the id a
|
|
251
|
+
* PREVIOUS upstream minted) would otherwise leave here verbatim and answer 400
|
|
252
|
+
* `Invalid 'input[N].call_id': string too long, maximum 64 characters`.
|
|
253
|
+
*
|
|
254
|
+
* THIS IS THE ONLY PROJECTION POINT, and that is load-bearing. Canonical state —
|
|
255
|
+
* `CanonicalResponse.output[].callId`, the session store a `store: true` Responses
|
|
256
|
+
* chain replays, and the capture rows — keeps the ORIGINAL id, because projecting
|
|
257
|
+
* there would break the other carriers (Anthropic `tool_use.id` has its own length
|
|
258
|
+
* rule). If the outbound RESPONSE leg projected too, a client would hold digests
|
|
259
|
+
* while the chain replays originals, and the two would meet as one history: an
|
|
260
|
+
* unpaired orphan, `repairToolCallPairing` synthesising
|
|
261
|
+
* "Tool call was cancelled before returning a result." over the client's real
|
|
262
|
+
* result, and no error anywhere. One projector on one leg keeps every plane in one
|
|
263
|
+
* naming system: a client replays the original it was handed, and this function
|
|
264
|
+
* turns it into the same digest on every turn.
|
|
200
265
|
*
|
|
201
266
|
* Four properties, all load-bearing:
|
|
202
267
|
*
|
|
203
|
-
* -
|
|
204
|
-
* that key on the `call_` / `toolu_`
|
|
205
|
-
* item-type prefix
|
|
206
|
-
* this does not), so the
|
|
207
|
-
* not.
|
|
268
|
+
* - Inside the field (its charset AND its length) -> BYTE-IDENTICAL. Most traffic
|
|
269
|
+
* never sees a rewrite, so carriers that key on the `call_` / `toolu_` shape keep
|
|
270
|
+
* seeing it. `call_id` needs no item-type prefix (that is why `responsesToolItemId`
|
|
271
|
+
* adds one and this does not have to), so the budget is spent entirely on the id.
|
|
208
272
|
* - Deterministic: the same history yields the same id on every turn, or the
|
|
209
|
-
* replayed prefix busts the upstream prompt cache.
|
|
210
|
-
* - Injective: truncating to the budget is NOT the fallback — ids
|
|
211
|
-
* 64-char prefix would silently merge, and a merged correlation id
|
|
212
|
-
* tool results onto one call with no error anywhere. The
|
|
213
|
-
*
|
|
273
|
+
* replayed prompt prefix busts the upstream prompt cache.
|
|
274
|
+
* - Injective: truncating the ORIGINAL to the budget is NOT the fallback — ids
|
|
275
|
+
* that share a 64-char prefix would silently merge, and a merged correlation id
|
|
276
|
+
* merges two tool results onto one call with no error anywhere. The replacement
|
|
277
|
+
* is a `sha256` digest (`call_` + 59 hex = 64, so 236 bits and no realistic
|
|
278
|
+
* collision), and it keeps the `call_` shape because consumers, session stores
|
|
279
|
+
* and operator greps key on it.
|
|
214
280
|
* - A PROJECTION: `responsesCallId(responsesCallId(x)) === responsesCallId(x)`,
|
|
215
|
-
* because the hashed form is itself
|
|
216
|
-
* through the gateway (a client replays whatever id it was handed, and
|
|
217
|
-
* extension item may carry one verbatim), so a map that is not idempotent
|
|
281
|
+
* because the hashed form is itself inside the field. The correlation id
|
|
282
|
+
* flows back through the gateway (a client replays whatever id it was handed, and
|
|
283
|
+
* an extension item may carry one verbatim), so a map that is not idempotent
|
|
218
284
|
* would name the same call differently on two turns of one session.
|
|
219
285
|
*
|
|
220
|
-
* An empty id has no faithful representation — pairing is impossible without it
|
|
221
|
-
* so it is refused in the plane's own envelope
|
|
222
|
-
*
|
|
223
|
-
* the upstream to reject in a language the
|
|
286
|
+
* An empty id has no faithful representation — pairing is impossible without it —
|
|
287
|
+
* so it is refused in the plane's own envelope (`tool_call_id` is the machine code the
|
|
288
|
+
* client sees) rather than minted a placeholder, which would merge every unlabelled
|
|
289
|
+
* call onto one id, or relayed as `""` for the upstream to reject in a language the
|
|
290
|
+
* client cannot read. An EMPTY `call_id` counts as absent and falls back to the item
|
|
291
|
+
* id **when the caller has one to offer** — that is the tool-call branch, which passes
|
|
292
|
+
* `item.id`; a tool RESULT has no id of its own, so there the refusal above is what
|
|
293
|
+
* happens. The two carriers agree on the anchor because `chat`
|
|
294
|
+
* writes `callId = id`, and the inbound Responses reader does `call_id ?? id`; a
|
|
295
|
+
* stored turn from before the minting fix can carry `call_id: ""` beside a real item
|
|
296
|
+
* id. This is the LAST-MILE half of that contract: an empty correlation id is legal on
|
|
297
|
+
* the Chat and Anthropic outbound wires, so it is refused only when the dialed carrier
|
|
298
|
+
* requires one. The consequence is that the refusal is an `IrUnsupportedError`, which is
|
|
299
|
+
* NOT failover-eligible — correct for a malformed body every candidate would receive
|
|
300
|
+
* alike, but it means such a request ends here instead of trying the next model.
|
|
224
301
|
*/
|
|
225
302
|
export function responsesCallId(callId, fallback) {
|
|
226
|
-
const id =
|
|
303
|
+
const id = callId || fallback || '';
|
|
227
304
|
if (!id) {
|
|
228
305
|
throw new IrUnsupportedError('tool_call_id', 'Responses tool items require a non-empty correlation id.', PROTOCOL);
|
|
229
306
|
}
|
|
230
|
-
return
|
|
307
|
+
return isCanonicalResponsesCallId(id)
|
|
308
|
+
? id
|
|
309
|
+
: CALL_ID_PREFIX + idDigest(id, RESPONSES_CALL_ID_MAX_LEN - CALL_ID_PREFIX.length);
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Passthrough is not exemption on the leg we control. A built-in Responses item
|
|
313
|
+
* (`web_search_call`, `mcp_call`, `image_generation_call`, a `computer_call` a
|
|
314
|
+
* plugin parsed as an extension) carries `call_id` too, and an over-budget one
|
|
315
|
+
* answers 400 for exactly the reason a tool item does — so an outbound extension
|
|
316
|
+
* payload's correlation id goes through the same map. The payload is COPIED, never
|
|
317
|
+
* mutated in place: the same object is what capture and the session store read, and
|
|
318
|
+
* rewriting the original there would silently edit the client's prompt and put the
|
|
319
|
+
* two naming planes out of step. A NESTED `call_id` is deliberately not walked: a foreign
|
|
320
|
+
* built-in shape is not ours to relabel, and rewriting unknown payload keys would put the
|
|
321
|
+
* map's idempotence on the vendor's structure rather than on our own field. An absent or
|
|
322
|
+
* empty `call_id` is left alone, because
|
|
323
|
+
* this payload is not ours to label — refusing a foreign built-in item over a field
|
|
324
|
+
* shape we merely inferred would reject requests that work today.
|
|
325
|
+
*/
|
|
326
|
+
function withNormalizedCallId(payload) {
|
|
327
|
+
const callId = payload.call_id;
|
|
328
|
+
if (typeof callId !== 'string' || callId === '')
|
|
329
|
+
return payload;
|
|
330
|
+
return { ...payload, call_id: responsesCallId(callId) };
|
|
231
331
|
}
|
|
232
332
|
function itemToWire(item) {
|
|
233
333
|
if (item.type === 'extension') {
|
|
234
334
|
if (item.protocol !== PROTOCOL)
|
|
235
335
|
throw new IrUnsupportedError('input_item', `Cannot convert ${item.protocol} item.`, PROTOCOL);
|
|
236
|
-
return record(item.payload);
|
|
336
|
+
return withNormalizedCallId(record(item.payload));
|
|
237
337
|
}
|
|
238
338
|
if (item.type === 'item_reference')
|
|
239
339
|
return { type: 'item_reference', id: item.id };
|
|
@@ -537,8 +637,16 @@ export function responsesInputToIR(raw) {
|
|
|
537
637
|
}];
|
|
538
638
|
}
|
|
539
639
|
if (type === 'function_call' || type === 'custom_tool_call') {
|
|
540
|
-
|
|
541
|
-
|
|
640
|
+
// The REQUEST plane keeps the name the client sent. This is the one reader that must NOT
|
|
641
|
+
// mint: a harness resends the whole history every turn, so a random name invented here
|
|
642
|
+
// would make the canonical envelope differ per resend and the outbound prefix would
|
|
643
|
+
// change bytes on every turn — a cache miss the client can neither see nor fix. An item
|
|
644
|
+
// id is a legitimate fallback because the client wrote it. A call named by NOTHING is
|
|
645
|
+
// refused at the outbound gate (`responsesCallId`), never silently renamed here.
|
|
646
|
+
const wireCallId = typeof item.call_id === 'string' ? item.call_id : '';
|
|
647
|
+
const wireItemId = typeof item.id === 'string' ? item.id : '';
|
|
648
|
+
const callId = wireCallId || wireItemId;
|
|
649
|
+
const id = wireItemId || callId;
|
|
542
650
|
const args = type === 'custom_tool_call' ? item.input : item.arguments;
|
|
543
651
|
return [{
|
|
544
652
|
type: 'tool_call', id, callId,
|
|
@@ -694,10 +802,11 @@ export function responsesResponseToIR(data) {
|
|
|
694
802
|
});
|
|
695
803
|
}
|
|
696
804
|
else if (item.type === 'function_call' || item.type === 'custom_tool_call') {
|
|
697
|
-
const callId = typeof item.call_id === 'string' ? item.call_id
|
|
805
|
+
const callId = upstreamToolCallId(typeof item.call_id === 'string' ? item.call_id
|
|
806
|
+
: typeof item.id === 'string' ? item.id : undefined);
|
|
698
807
|
const args = item.type === 'custom_tool_call' ? item.input : item.arguments;
|
|
699
808
|
output.push({
|
|
700
|
-
type: 'tool_call', id:
|
|
809
|
+
type: 'tool_call', id: typeof item.id === 'string' && item.id ? item.id : callId, callId,
|
|
701
810
|
name: String(item.name ?? ''),
|
|
702
811
|
arguments: typeof args === 'string' ? args : JSON.stringify(args ?? {}),
|
|
703
812
|
...(item.status ? { status: item.status } : {}),
|
|
@@ -1,2 +1,22 @@
|
|
|
1
1
|
/** Inline base64 media URL shared by protocol adapters. */
|
|
2
2
|
export declare const DATA_URL_RE: RegExp;
|
|
3
|
+
/**
|
|
4
|
+
* media_type → file extension for an offloaded payload (unknown → bin).
|
|
5
|
+
* ONE table: the capture archive and the session-snapshot store both offload
|
|
6
|
+
* base64 with the same content-addressed naming, so a payload offloaded by one
|
|
7
|
+
* plane must be readable by the other's rules.
|
|
8
|
+
*/
|
|
9
|
+
export declare const MIME_TO_EXT: Record<string, string>;
|
|
10
|
+
/** Reverse map for a read route's Content-Type. */
|
|
11
|
+
export declare const EXT_TO_MIME: Record<string, string>;
|
|
12
|
+
/**
|
|
13
|
+
* A bare (no data-URL prefix) base64 payload worth offloading: ≥256 chars of
|
|
14
|
+
* strict alphabet. Prose, code, or paths carry spaces/punctuation and never
|
|
15
|
+
* match — the guard's false-positive class is "long base64-ish token", which is
|
|
16
|
+
* exactly what image/audio/document blobs look like.
|
|
17
|
+
*/
|
|
18
|
+
export declare const BASE64_SHAPE_RE: RegExp;
|
|
19
|
+
/** Content-addressed media file name: `<sha256>.<ext>`. */
|
|
20
|
+
export declare const MEDIA_FILE_RE: RegExp;
|
|
21
|
+
/** A hash prefix accepted by a media read route (16–64 hex). */
|
|
22
|
+
export declare const MEDIA_HASH_RE: RegExp;
|
package/backend/dist/ir/media.js
CHANGED
|
@@ -1,2 +1,43 @@
|
|
|
1
1
|
/** Inline base64 media URL shared by protocol adapters. */
|
|
2
2
|
export const DATA_URL_RE = /^data:(.+?);base64,(.*)$/;
|
|
3
|
+
/**
|
|
4
|
+
* media_type → file extension for an offloaded payload (unknown → bin).
|
|
5
|
+
* ONE table: the capture archive and the session-snapshot store both offload
|
|
6
|
+
* base64 with the same content-addressed naming, so a payload offloaded by one
|
|
7
|
+
* plane must be readable by the other's rules.
|
|
8
|
+
*/
|
|
9
|
+
export const MIME_TO_EXT = {
|
|
10
|
+
'image/png': 'png',
|
|
11
|
+
'image/jpeg': 'jpg',
|
|
12
|
+
'image/jpg': 'jpg',
|
|
13
|
+
'image/gif': 'gif',
|
|
14
|
+
'image/webp': 'webp',
|
|
15
|
+
'image/svg+xml': 'svg',
|
|
16
|
+
'image/bmp': 'bmp',
|
|
17
|
+
'image/avif': 'avif',
|
|
18
|
+
'application/pdf': 'pdf',
|
|
19
|
+
'text/plain': 'txt',
|
|
20
|
+
};
|
|
21
|
+
/** Reverse map for a read route's Content-Type. */
|
|
22
|
+
export const EXT_TO_MIME = {
|
|
23
|
+
png: 'image/png',
|
|
24
|
+
jpg: 'image/jpeg',
|
|
25
|
+
gif: 'image/gif',
|
|
26
|
+
webp: 'image/webp',
|
|
27
|
+
svg: 'image/svg+xml',
|
|
28
|
+
bmp: 'image/bmp',
|
|
29
|
+
avif: 'image/avif',
|
|
30
|
+
pdf: 'application/pdf',
|
|
31
|
+
txt: 'text/plain',
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* A bare (no data-URL prefix) base64 payload worth offloading: ≥256 chars of
|
|
35
|
+
* strict alphabet. Prose, code, or paths carry spaces/punctuation and never
|
|
36
|
+
* match — the guard's false-positive class is "long base64-ish token", which is
|
|
37
|
+
* exactly what image/audio/document blobs look like.
|
|
38
|
+
*/
|
|
39
|
+
export const BASE64_SHAPE_RE = /^[A-Za-z0-9+/]{256,}={0,2}$/;
|
|
40
|
+
/** Content-addressed media file name: `<sha256>.<ext>`. */
|
|
41
|
+
export const MEDIA_FILE_RE = /^[0-9a-f]{16,64}\.[a-z0-9]{1,8}$/;
|
|
42
|
+
/** A hash prefix accepted by a media read route (16–64 hex). */
|
|
43
|
+
export const MEDIA_HASH_RE = /^[0-9a-f]{16,64}$/;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ONE namespace for a tool correlation id the gateway itself has to supply.
|
|
3
|
+
*
|
|
4
|
+
* Why this lives in the IR layer instead of an adapter: every upstream READER can meet a
|
|
5
|
+
* tool call that arrived with no id — a lenient OpenAI-compatible server returns
|
|
6
|
+
* `tool_calls[]` without one, a Responses server can omit both `id` and `call_id`, Gemini
|
|
7
|
+
* has no correlation field at all, and a markup-recovered call has no native id either.
|
|
8
|
+
* Each reader used to patch that differently (`call_<16hex>`, `call_<candidate>_<index>`,
|
|
9
|
+
* or nothing at all, which left `''`), and the three spellings were three drift twins of
|
|
10
|
+
* one idea — one of them positional, which collides with the SAME position of the PREVIOUS
|
|
11
|
+
* turn inside one replayed history.
|
|
12
|
+
*
|
|
13
|
+
* The id is minted in CANONICAL state, at the moment the upstream response is read, not at
|
|
14
|
+
* wire-render time. That placement is the point: canonical state is what the session store
|
|
15
|
+
* records for a `store: true` chain, what capture archives, and what every outbound carrier
|
|
16
|
+
* renders from, so the client, the operator's record and the next turn's replay all speak ONE
|
|
17
|
+
* name for one call. A render-time mint would leave the stored turn with an empty id, and the
|
|
18
|
+
* next turn would then fail on the gateway's own history (`400 tool_call_id`) or orphan the
|
|
19
|
+
* client's real tool result.
|
|
20
|
+
*
|
|
21
|
+
* 24 hex chars (12 bytes, 96 bits) keeps the id inside every carrier's field budget — the
|
|
22
|
+
* Responses correlation budget is `RESPONSES_CALL_ID_MAX_LEN` = 64 — and inside the charset
|
|
23
|
+
* `[A-Za-z0-9_-]` both Responses id fields share, so a minted id never needs the outbound
|
|
24
|
+
* projection and never truncates.
|
|
25
|
+
*/
|
|
26
|
+
export declare const CALL_ID_PREFIX = "call_";
|
|
27
|
+
/** A fresh, carrier-legal correlation id for an upstream call that arrived unnamed. */
|
|
28
|
+
export declare function mintToolCallId(): string;
|
|
29
|
+
/**
|
|
30
|
+
* The id an upstream tool call carries, or a minted one when it carries none. An EMPTY
|
|
31
|
+
* string counts as none: a field the vendor sent as `""` names nothing, which is exactly
|
|
32
|
+
* the case this exists for. Callers assign the RESULT to both `id` and `callId` so the two
|
|
33
|
+
* slots of one call never disagree.
|
|
34
|
+
*/
|
|
35
|
+
export declare function upstreamToolCallId(id: string | undefined | null): string;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
/**
|
|
3
|
+
* The ONE namespace for a tool correlation id the gateway itself has to supply.
|
|
4
|
+
*
|
|
5
|
+
* Why this lives in the IR layer instead of an adapter: every upstream READER can meet a
|
|
6
|
+
* tool call that arrived with no id — a lenient OpenAI-compatible server returns
|
|
7
|
+
* `tool_calls[]` without one, a Responses server can omit both `id` and `call_id`, Gemini
|
|
8
|
+
* has no correlation field at all, and a markup-recovered call has no native id either.
|
|
9
|
+
* Each reader used to patch that differently (`call_<16hex>`, `call_<candidate>_<index>`,
|
|
10
|
+
* or nothing at all, which left `''`), and the three spellings were three drift twins of
|
|
11
|
+
* one idea — one of them positional, which collides with the SAME position of the PREVIOUS
|
|
12
|
+
* turn inside one replayed history.
|
|
13
|
+
*
|
|
14
|
+
* The id is minted in CANONICAL state, at the moment the upstream response is read, not at
|
|
15
|
+
* wire-render time. That placement is the point: canonical state is what the session store
|
|
16
|
+
* records for a `store: true` chain, what capture archives, and what every outbound carrier
|
|
17
|
+
* renders from, so the client, the operator's record and the next turn's replay all speak ONE
|
|
18
|
+
* name for one call. A render-time mint would leave the stored turn with an empty id, and the
|
|
19
|
+
* next turn would then fail on the gateway's own history (`400 tool_call_id`) or orphan the
|
|
20
|
+
* client's real tool result.
|
|
21
|
+
*
|
|
22
|
+
* 24 hex chars (12 bytes, 96 bits) keeps the id inside every carrier's field budget — the
|
|
23
|
+
* Responses correlation budget is `RESPONSES_CALL_ID_MAX_LEN` = 64 — and inside the charset
|
|
24
|
+
* `[A-Za-z0-9_-]` both Responses id fields share, so a minted id never needs the outbound
|
|
25
|
+
* projection and never truncates.
|
|
26
|
+
*/
|
|
27
|
+
export const CALL_ID_PREFIX = 'call_';
|
|
28
|
+
/** A fresh, carrier-legal correlation id for an upstream call that arrived unnamed. */
|
|
29
|
+
export function mintToolCallId() {
|
|
30
|
+
return `${CALL_ID_PREFIX}${crypto.randomBytes(12).toString('hex')}`;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The id an upstream tool call carries, or a minted one when it carries none. An EMPTY
|
|
34
|
+
* string counts as none: a field the vendor sent as `""` names nothing, which is exactly
|
|
35
|
+
* the case this exists for. Callers assign the RESULT to both `id` and `callId` so the two
|
|
36
|
+
* slots of one call never disagree.
|
|
37
|
+
*/
|
|
38
|
+
export function upstreamToolCallId(id) {
|
|
39
|
+
return id || mintToolCallId();
|
|
40
|
+
}
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* cannot express a component simply omit it.
|
|
17
17
|
* - Streaming is an event union with item lifecycle, not a chat chunk.
|
|
18
18
|
*/
|
|
19
|
+
import type { ReasoningEffort } from '../types/router.js';
|
|
19
20
|
/** Conversion-surface protocol ids. The core shapes are literal for readers;
|
|
20
21
|
* the plugin half is OPEN — an OCR-native bare protocol name or any wire a
|
|
21
22
|
* loaded model-service plugin declares is a valid carrier (ADR-0033
|
|
@@ -69,7 +70,7 @@ export interface TextConfig {
|
|
|
69
70
|
verbosity?: 'low' | 'medium' | 'high';
|
|
70
71
|
}
|
|
71
72
|
export interface ReasoningParams {
|
|
72
|
-
effort?:
|
|
73
|
+
effort?: ReasoningEffort;
|
|
73
74
|
/** Explicit token budget (Anthropic thinking.budget_tokens / Responses max_tokens). */
|
|
74
75
|
budgetTokens?: number;
|
|
75
76
|
include?: boolean;
|
|
@@ -370,6 +371,13 @@ export interface Usage {
|
|
|
370
371
|
audioOutputTokens?: number;
|
|
371
372
|
acceptedPredictionTokens?: number;
|
|
372
373
|
rejectedPredictionTokens?: number;
|
|
374
|
+
/**
|
|
375
|
+
* What the VENDOR says this exchange committed, in USD (stamped by a
|
|
376
|
+
* model-service plugin from the upstream's own billing). When present it
|
|
377
|
+
* wins over token-count x catalog pricing for every cost booking — a static
|
|
378
|
+
* price table is an estimate, this is the invoice.
|
|
379
|
+
*/
|
|
380
|
+
vendorCostUsd?: number;
|
|
373
381
|
}
|
|
374
382
|
export interface AssistantMessageItem {
|
|
375
383
|
type: 'message';
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { type LocalRunLogLine, type LocalRunSpawnLike } from './runner.js';
|
|
2
|
+
export type BuildJobStatus = 'building' | 'done' | 'failed';
|
|
3
|
+
export interface BuildJob {
|
|
4
|
+
id: string;
|
|
5
|
+
modelId: string;
|
|
6
|
+
engine: string;
|
|
7
|
+
status: BuildJobStatus;
|
|
8
|
+
startedAt: number;
|
|
9
|
+
finishedAt?: number;
|
|
10
|
+
error?: string;
|
|
11
|
+
/** Machine-readable error class for `error` (`build-leg-exited`), so the
|
|
12
|
+
* console localizes instead of showing the backend sentence raw — the same
|
|
13
|
+
* `code` + `error` pair `LocalRun.lastErrorCode` carries (ADR-0046). */
|
|
14
|
+
errorCode?: string;
|
|
15
|
+
}
|
|
16
|
+
/** Test seam, mirroring setLocalRunnerDepsForTests. */
|
|
17
|
+
export declare function setBuildJobDepsForTests(deps: {
|
|
18
|
+
spawnImpl?: LocalRunSpawnLike;
|
|
19
|
+
} | null): void;
|
|
20
|
+
export declare function appendBuildLog(id: string, stream: LocalRunLogLine['stream'], raw: string): void;
|
|
21
|
+
export declare function buildLogs(id: string, limit?: number): LocalRunLogLine[];
|
|
22
|
+
/** Newest first; finished history is capped, building jobs are always listed. */
|
|
23
|
+
export declare function listBuildJobs(): BuildJob[];
|
|
24
|
+
export declare function getBuildJob(id: string): BuildJob | null;
|
|
25
|
+
export type StartBuildResult = {
|
|
26
|
+
ok: true;
|
|
27
|
+
job: BuildJob;
|
|
28
|
+
} | {
|
|
29
|
+
ok: false;
|
|
30
|
+
code: string;
|
|
31
|
+
error: string;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Start one build for one (model, engine). The legs come from the engine's
|
|
35
|
+
* runtime; a refusal (incomplete workspace, missing tool) surfaces as the
|
|
36
|
+
* error rather than spawning something half-formed.
|
|
37
|
+
*/
|
|
38
|
+
export declare function startBuildJob(opts: {
|
|
39
|
+
modelId: string;
|
|
40
|
+
engine: string;
|
|
41
|
+
}): Promise<StartBuildResult>;
|
|
42
|
+
/**
|
|
43
|
+
* What a catalog download does next, once its files are on disk.
|
|
44
|
+
*
|
|
45
|
+
* "Downloaded" is not "runnable": a model whose launch input the ENGINE derives
|
|
46
|
+
* (a pack, or the in-place tokenizer) is still `serves: false` until that input
|
|
47
|
+
* exists. Asking the engine's own verdict (`buildable`) is what keeps this
|
|
48
|
+
* engine-agnostic — the gateway never decides by name that a model "needs a
|
|
49
|
+
* pack". `null` means nothing to do: the model already runs, or no engine can
|
|
50
|
+
* derive what it is missing (the console's Pack button covers that case).
|
|
51
|
+
*
|
|
52
|
+
* A start that fails is returned, not thrown, and it changes nothing about the
|
|
53
|
+
* model: `startBuildJob` only registers a job on success, so a failure leaves
|
|
54
|
+
* the model `buildable` and its Pack button in place — that IS the retry path.
|
|
55
|
+
*/
|
|
56
|
+
export declare function prepareAfterDownload(model: {
|
|
57
|
+
id: string;
|
|
58
|
+
filePath: string;
|
|
59
|
+
}, engineId: string): Promise<{
|
|
60
|
+
status: 'started';
|
|
61
|
+
jobId: string;
|
|
62
|
+
} | {
|
|
63
|
+
status: 'refused';
|
|
64
|
+
code: string;
|
|
65
|
+
error: string;
|
|
66
|
+
} | undefined>;
|