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
|
@@ -223,7 +223,13 @@ export declare class SessionManager {
|
|
|
223
223
|
* arguments on resend, so raw JSON.stringify of the whole object would
|
|
224
224
|
* miss every tool-call boundary on the next turn.
|
|
225
225
|
*/
|
|
226
|
-
|
|
226
|
+
/**
|
|
227
|
+
* PUBLIC on purpose: the snapshot message tree (ADR-0038 §8) derives node
|
|
228
|
+
* identity from THIS canonical form, so two branches that share an ancestry
|
|
229
|
+
* must collapse onto the same node ids it would produce. Exposing it keeps ONE
|
|
230
|
+
* canonicalization instead of a second copy that could drift from the anchors.
|
|
231
|
+
*/
|
|
232
|
+
static serializeMessage(item: InputItem | OutputItem): string;
|
|
227
233
|
private static contentText;
|
|
228
234
|
private static canonicalToolArgs;
|
|
229
235
|
/** One canonical string per item: no content-tree clone on the request path. */
|
|
@@ -268,9 +274,10 @@ export declare class SessionManager {
|
|
|
268
274
|
* is no second namespace to map, while the body channel below covers wires
|
|
269
275
|
* that have no HTTP headers at all). Returns the alphabetically first
|
|
270
276
|
* matching header's value (array header → first entry), or null. The bare
|
|
271
|
-
* `x-session-id
|
|
272
|
-
*
|
|
273
|
-
*
|
|
277
|
+
* explicit forms (`x-session-id`, `x-conversation-id`, `x-session-affinity`,
|
|
278
|
+
* `session_id`, `session-id`, `conversation-id`) never match (the app
|
|
279
|
+
* segment must be non-empty) — they are step 1's explicit_header territory.
|
|
280
|
+
* Two namespace guards bind each value: a value
|
|
274
281
|
* claiming the reserved `ocr-internal:` prefix (a gateway-internal row
|
|
275
282
|
* marker — a client must not be able to hide its row from the console) or
|
|
276
283
|
* exceeding `VENDOR_SESSION_ID_MAX` is skipped, falling through to the next
|
|
@@ -294,9 +301,32 @@ export declare class SessionManager {
|
|
|
294
301
|
* and the session it names can never disagree.
|
|
295
302
|
*/
|
|
296
303
|
/**
|
|
297
|
-
*
|
|
304
|
+
* Header names that carry a client conversation id, in precedence order.
|
|
305
|
+
* Every entry is conversation-scoped on the clients that emit it, and none
|
|
306
|
+
* is reachable by the vendor probe: `x-session-id` (explicit contract,
|
|
307
|
+
* console, billion-context proxy — proven 1:1 in the capture archive),
|
|
308
|
+
* `x-conversation-id` (same explicit namespace, backward compatibility),
|
|
309
|
+
* `x-session-affinity` (pi chat on a non-OpenRouter endpoint and the
|
|
310
|
+
* Anthropic leg — an affinity key only works per-conversation; the probe
|
|
311
|
+
* regex needs a trailing `-id`, so this spelling is never claimed twice),
|
|
312
|
+
* `session_id` (pi's openai-format id on the chat and Responses HTTP legs;
|
|
313
|
+
* underscore, so the hyphen-only probe can never match it), then the legacy
|
|
314
|
+
* `session-id` / `conversation-id`.
|
|
315
|
+
*/
|
|
316
|
+
private static readonly EXPLICIT_SESSION_HEADERS;
|
|
317
|
+
/** Trimmed first entry of a possibly-array header value, else ''. */
|
|
318
|
+
private static headerValue;
|
|
319
|
+
/**
|
|
320
|
+
* Caller-supplied conversation id. Reads the explicit header list and
|
|
298
321
|
* nothing else: no mint, no anchor, no session-manager write. Archive code
|
|
299
322
|
* uses this when it needs a file name and the request is not a conversation.
|
|
323
|
+
*
|
|
324
|
+
* A blank value falls through to the next name — a truthy-but-empty header
|
|
325
|
+
* must never mask a real id later in the list. `session-id` is skipped when
|
|
326
|
+
* it equals the request's `x-client-request-id`: pi's Codex Responses
|
|
327
|
+
* websocket leg stamps both with the PER-REQUEST id, so that pair is a
|
|
328
|
+
* correlation id, not a conversation id (a legitimate client never names a
|
|
329
|
+
* conversation after its own per-request id).
|
|
300
330
|
*/
|
|
301
331
|
static explicitSessionId(headers?: Record<string, string | string[] | undefined>): string | undefined;
|
|
302
332
|
static clientRefOf(request: CanonicalRequest): ClientConversationRef | null;
|
|
@@ -356,6 +386,13 @@ export declare class SessionManager {
|
|
|
356
386
|
private bindClientRef;
|
|
357
387
|
/** FIFO-bounded map set (Map preserves insertion order). */
|
|
358
388
|
private setBounded;
|
|
389
|
+
/**
|
|
390
|
+
* True when a ratchet call actually persists a per-session model pin.
|
|
391
|
+
* `applyRatchet` still resolves a representative model in the stateless /
|
|
392
|
+
* disabled branch, but that representative is thrown away with the dummy
|
|
393
|
+
* session — callers must not let it consume a rotation pick.
|
|
394
|
+
*/
|
|
395
|
+
pinsModels(): boolean;
|
|
359
396
|
/**
|
|
360
397
|
* Applies the Monotonic Session Ratchet policy.
|
|
361
398
|
*
|
|
@@ -182,6 +182,12 @@ export class SessionManager {
|
|
|
182
182
|
* arguments on resend, so raw JSON.stringify of the whole object would
|
|
183
183
|
* miss every tool-call boundary on the next turn.
|
|
184
184
|
*/
|
|
185
|
+
/**
|
|
186
|
+
* PUBLIC on purpose: the snapshot message tree (ADR-0038 §8) derives node
|
|
187
|
+
* identity from THIS canonical form, so two branches that share an ancestry
|
|
188
|
+
* must collapse onto the same node ids it would produce. Exposing it keeps ONE
|
|
189
|
+
* canonicalization instead of a second copy that could drift from the anchors.
|
|
190
|
+
*/
|
|
185
191
|
static serializeMessage(item) {
|
|
186
192
|
if (item.type === 'message') {
|
|
187
193
|
const name = 'name' in item ? item.name : undefined;
|
|
@@ -315,9 +321,10 @@ export class SessionManager {
|
|
|
315
321
|
* is no second namespace to map, while the body channel below covers wires
|
|
316
322
|
* that have no HTTP headers at all). Returns the alphabetically first
|
|
317
323
|
* matching header's value (array header → first entry), or null. The bare
|
|
318
|
-
* `x-session-id
|
|
319
|
-
*
|
|
320
|
-
*
|
|
324
|
+
* explicit forms (`x-session-id`, `x-conversation-id`, `x-session-affinity`,
|
|
325
|
+
* `session_id`, `session-id`, `conversation-id`) never match (the app
|
|
326
|
+
* segment must be non-empty) — they are step 1's explicit_header territory.
|
|
327
|
+
* Two namespace guards bind each value: a value
|
|
321
328
|
* claiming the reserved `ocr-internal:` prefix (a gateway-internal row
|
|
322
329
|
* marker — a client must not be able to hide its row from the console) or
|
|
323
330
|
* exceeding `VENDOR_SESSION_ID_MAX` is skipped, falling through to the next
|
|
@@ -367,19 +374,56 @@ export class SessionManager {
|
|
|
367
374
|
* and the session it names can never disagree.
|
|
368
375
|
*/
|
|
369
376
|
/**
|
|
370
|
-
*
|
|
377
|
+
* Header names that carry a client conversation id, in precedence order.
|
|
378
|
+
* Every entry is conversation-scoped on the clients that emit it, and none
|
|
379
|
+
* is reachable by the vendor probe: `x-session-id` (explicit contract,
|
|
380
|
+
* console, billion-context proxy — proven 1:1 in the capture archive),
|
|
381
|
+
* `x-conversation-id` (same explicit namespace, backward compatibility),
|
|
382
|
+
* `x-session-affinity` (pi chat on a non-OpenRouter endpoint and the
|
|
383
|
+
* Anthropic leg — an affinity key only works per-conversation; the probe
|
|
384
|
+
* regex needs a trailing `-id`, so this spelling is never claimed twice),
|
|
385
|
+
* `session_id` (pi's openai-format id on the chat and Responses HTTP legs;
|
|
386
|
+
* underscore, so the hyphen-only probe can never match it), then the legacy
|
|
387
|
+
* `session-id` / `conversation-id`.
|
|
388
|
+
*/
|
|
389
|
+
static EXPLICIT_SESSION_HEADERS = [
|
|
390
|
+
'x-session-id',
|
|
391
|
+
'x-conversation-id',
|
|
392
|
+
'x-session-affinity',
|
|
393
|
+
'session_id',
|
|
394
|
+
'session-id',
|
|
395
|
+
'conversation-id',
|
|
396
|
+
];
|
|
397
|
+
/** Trimmed first entry of a possibly-array header value, else ''. */
|
|
398
|
+
static headerValue(raw) {
|
|
399
|
+
const id = (Array.isArray(raw) ? raw[0] : raw)?.trim();
|
|
400
|
+
return id ?? '';
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Caller-supplied conversation id. Reads the explicit header list and
|
|
371
404
|
* nothing else: no mint, no anchor, no session-manager write. Archive code
|
|
372
405
|
* uses this when it needs a file name and the request is not a conversation.
|
|
406
|
+
*
|
|
407
|
+
* A blank value falls through to the next name — a truthy-but-empty header
|
|
408
|
+
* must never mask a real id later in the list. `session-id` is skipped when
|
|
409
|
+
* it equals the request's `x-client-request-id`: pi's Codex Responses
|
|
410
|
+
* websocket leg stamps both with the PER-REQUEST id, so that pair is a
|
|
411
|
+
* correlation id, not a conversation id (a legitimate client never names a
|
|
412
|
+
* conversation after its own per-request id).
|
|
373
413
|
*/
|
|
374
414
|
static explicitSessionId(headers) {
|
|
375
|
-
|
|
376
|
-
headers?.['x-conversation-id'] ||
|
|
377
|
-
headers?.['session-id'] ||
|
|
378
|
-
headers?.['conversation-id'];
|
|
379
|
-
if (!raw)
|
|
415
|
+
if (!headers)
|
|
380
416
|
return undefined;
|
|
381
|
-
const
|
|
382
|
-
|
|
417
|
+
const requestId = SessionManager.headerValue(headers['x-client-request-id']);
|
|
418
|
+
for (const name of SessionManager.EXPLICIT_SESSION_HEADERS) {
|
|
419
|
+
const id = SessionManager.headerValue(headers[name]);
|
|
420
|
+
if (!id)
|
|
421
|
+
continue;
|
|
422
|
+
if (name === 'session-id' && requestId && id === requestId)
|
|
423
|
+
continue;
|
|
424
|
+
return id;
|
|
425
|
+
}
|
|
426
|
+
return undefined;
|
|
383
427
|
}
|
|
384
428
|
static clientRefOf(request) {
|
|
385
429
|
return SessionManager.normalizeClientRef(request.routerOptions?.clientRef);
|
|
@@ -595,6 +639,15 @@ export class SessionManager {
|
|
|
595
639
|
map.delete(oldest);
|
|
596
640
|
}
|
|
597
641
|
}
|
|
642
|
+
/**
|
|
643
|
+
* True when a ratchet call actually persists a per-session model pin.
|
|
644
|
+
* `applyRatchet` still resolves a representative model in the stateless /
|
|
645
|
+
* disabled branch, but that representative is thrown away with the dummy
|
|
646
|
+
* session — callers must not let it consume a rotation pick.
|
|
647
|
+
*/
|
|
648
|
+
pinsModels() {
|
|
649
|
+
return this.config.enabled && this.config.strategy !== 'stateless';
|
|
650
|
+
}
|
|
598
651
|
/**
|
|
599
652
|
* Applies the Monotonic Session Ratchet policy.
|
|
600
653
|
*
|
|
@@ -18,6 +18,7 @@ import type { CallCredential } from '../opencode/credentials/types.js';
|
|
|
18
18
|
import type { ClientConversationRef, ConversationSession } from './session-manager.js';
|
|
19
19
|
import type { ExecutionTrace, TraceTracker } from '../trace/tracker.js';
|
|
20
20
|
import type { CaptureKeyIdentity } from '../capture/recorder.js';
|
|
21
|
+
import type { SessionClientFamily } from '../utils/client-families.js';
|
|
21
22
|
/**
|
|
22
23
|
* How the client addressed a session's turns, derived from persisted traces
|
|
23
24
|
* (observability reconstruction — never routing state):
|
|
@@ -131,10 +132,23 @@ export interface SessionRow extends SessionEntityView, SessionAggregates {
|
|
|
131
132
|
* in that provider's chain; the console then falls back to the prefix.
|
|
132
133
|
*/
|
|
133
134
|
boundCredentialLabel?: string;
|
|
135
|
+
/**
|
|
136
|
+
* True when the bound credential is this machine's own CLI login. Its NAME is fixed
|
|
137
|
+
* (the console refuses to rename it) and it has no stored label, so without this flag
|
|
138
|
+
* a caller could not tell it apart from an unnamed credential.
|
|
139
|
+
*/
|
|
140
|
+
boundCredentialMachineLogin?: boolean;
|
|
134
141
|
/** Distinct client API-key identities, write order (first = display anchor). */
|
|
135
142
|
apiKeys?: CaptureKeyIdentity[];
|
|
136
143
|
/** Distinct client User-Agents, write order (console display only). */
|
|
137
144
|
clients?: string[];
|
|
145
|
+
/**
|
|
146
|
+
* Distinct client FAMILIES derived from `clients` (write order), the axis the
|
|
147
|
+
* console filters on. Ids are machine keys (`opencode`, `claude-code`, `pi`,
|
|
148
|
+
* `unknown`, …) from the canonical classifier in utils/client-families.ts;
|
|
149
|
+
* labels are English fallbacks. Display/filter only — never identity.
|
|
150
|
+
*/
|
|
151
|
+
clientFamilies?: SessionClientFamily[];
|
|
138
152
|
/**
|
|
139
153
|
* Client-minted conversation ids seen on this session's turns (write order,
|
|
140
154
|
* first = display anchor), derived from the traces' `request.clientRef`. The
|
|
@@ -145,13 +159,20 @@ export interface SessionRow extends SessionEntityView, SessionAggregates {
|
|
|
145
159
|
clientRefs?: ClientConversationRef[];
|
|
146
160
|
}
|
|
147
161
|
/**
|
|
148
|
-
*
|
|
149
|
-
* provider's LIVE registry chain at serialization time. The session entity
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
162
|
+
* Display identity of the credential a session is bound to, matched against the serving
|
|
163
|
+
* provider's LIVE registry chain at serialization time. The session entity persists only
|
|
164
|
+
* the display-safe `boundKeyHashPrefix` (ADR-0002 §3); labels are credential-store
|
|
165
|
+
* metadata that can be renamed without touching any session, so the join happens on read.
|
|
166
|
+
* No entry / an entry with no label = unnamed — the console then falls back to the prefix.
|
|
167
|
+
*
|
|
168
|
+
* `machineLogin` rides along because that row's NAME is fixed (the console refuses to
|
|
169
|
+
* rename it) and it carries no stored label, so a caller given only `label` could never
|
|
170
|
+
* tell "unnamed" from "this machine's login". It is detected from the marker VALUE
|
|
171
|
+
* (`isMachineLoginValue`) — the whole identity of that chain member — so `CallCredential`
|
|
172
|
+
* needs no extra field.
|
|
155
173
|
*/
|
|
156
|
-
export declare function
|
|
174
|
+
export declare function boundCredentialOf(chain: readonly CallCredential[] | undefined, keyHashPrefix: string | undefined): {
|
|
175
|
+
label?: string;
|
|
176
|
+
machineLogin: boolean;
|
|
177
|
+
};
|
|
157
178
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isMachineLoginValue } from '../opencode/credentials/types.js';
|
|
1
2
|
/** Classify a session from its traces (chronological order irrelevant). */
|
|
2
3
|
export function deriveSessionEntryMode(traces) {
|
|
3
4
|
// Virtual auto aliases: bare auto plus the four tier-forced aliases
|
|
@@ -83,7 +84,7 @@ export function sessionTitleOf(traces) {
|
|
|
83
84
|
* `SessionLookupType` (types/router.ts) and the resolver's layer comments.
|
|
84
85
|
*/
|
|
85
86
|
const CLIENT_NAMED_LOOKUP_TYPES = new Set([
|
|
86
|
-
'explicit_header', // 1. x-session-id / x-
|
|
87
|
+
'explicit_header', // 1. x-session-id / x-session-affinity / session_id / router_options.session_id
|
|
87
88
|
'embedded_user_id', // 2. Claude Code metadata.user_id → cc_<uuid>
|
|
88
89
|
'request_user', // 3. RETIRED — bare OpenAI request.user, still read for pre-removal trace rows
|
|
89
90
|
'header_fallback', // 9. vendor x-<app>-session-id rename of a fresh mint
|
|
@@ -104,17 +105,21 @@ export function sessionIdSourceOf(traces, birthLookupType) {
|
|
|
104
105
|
return CLIENT_NAMED_LOOKUP_TYPES.has(lookup) ? 'client' : 'gateway';
|
|
105
106
|
}
|
|
106
107
|
/**
|
|
107
|
-
*
|
|
108
|
-
* provider's LIVE registry chain at serialization time. The session entity
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
108
|
+
* Display identity of the credential a session is bound to, matched against the serving
|
|
109
|
+
* provider's LIVE registry chain at serialization time. The session entity persists only
|
|
110
|
+
* the display-safe `boundKeyHashPrefix` (ADR-0002 §3); labels are credential-store
|
|
111
|
+
* metadata that can be renamed without touching any session, so the join happens on read.
|
|
112
|
+
* No entry / an entry with no label = unnamed — the console then falls back to the prefix.
|
|
113
|
+
*
|
|
114
|
+
* `machineLogin` rides along because that row's NAME is fixed (the console refuses to
|
|
115
|
+
* rename it) and it carries no stored label, so a caller given only `label` could never
|
|
116
|
+
* tell "unnamed" from "this machine's login". It is detected from the marker VALUE
|
|
117
|
+
* (`isMachineLoginValue`) — the whole identity of that chain member — so `CallCredential`
|
|
118
|
+
* needs no extra field.
|
|
114
119
|
*/
|
|
115
|
-
export function
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const label =
|
|
119
|
-
return label
|
|
120
|
+
export function boundCredentialOf(chain, keyHashPrefix) {
|
|
121
|
+
const entry = keyHashPrefix ? chain?.find((c) => c.keyHashPrefix === keyHashPrefix) : undefined;
|
|
122
|
+
const machineLogin = entry ? isMachineLoginValue(entry.key) : false;
|
|
123
|
+
const label = entry?.label?.trim();
|
|
124
|
+
return { ...(label ? { label } : {}), machineLogin };
|
|
120
125
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { SessionSnapshotStore } from './store.js';
|
|
2
|
+
import { type SnapshotBundleManifest, type SnapshotTurn } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Portable session handoff bundle (ADR-0038) — format `ocr-session` v1.
|
|
5
|
+
*
|
|
6
|
+
* A zip of `manifest.json` + `transcript.jsonl` (the exact per-record lines the
|
|
7
|
+
* store already holds) + `media/<sha256>.<ext>` for every payload the
|
|
8
|
+
* transcript references. Deliberately its OWN envelope, not the env book-set
|
|
9
|
+
* (`ocr-env`): that archive's payload whitelist is a closed two-key set and
|
|
10
|
+
* explicitly excludes captured/session bytes (ADR-0007), so folding a
|
|
11
|
+
* transcript into it would require reopening a decision that exists precisely
|
|
12
|
+
* to keep secrets out of a shared book-set. A session bundle carries
|
|
13
|
+
* conversation text, is operator-initiated per session, and never touches the
|
|
14
|
+
* env archive pipeline.
|
|
15
|
+
*
|
|
16
|
+
* Integrity: every payload key gets a `sha256:<hex>` in the manifest and the
|
|
17
|
+
* import re-verifies it byte-for-byte before writing anything — a truncated or
|
|
18
|
+
* tampered bundle is refused whole, never half-imported.
|
|
19
|
+
*/
|
|
20
|
+
export declare const TRANSCRIPT_ENTRY = "transcript.jsonl";
|
|
21
|
+
export declare const MANIFEST_ENTRY = "manifest.json";
|
|
22
|
+
export declare class SessionBundleError extends Error {
|
|
23
|
+
readonly code: number;
|
|
24
|
+
constructor(message: string, code?: number);
|
|
25
|
+
}
|
|
26
|
+
/** Build a bundle from a stored session. Refuses an incomplete session. */
|
|
27
|
+
export declare function buildSessionBundle(store: SessionSnapshotStore, sessionId: string): Uint8Array;
|
|
28
|
+
export interface ParsedSessionBundle {
|
|
29
|
+
manifest: SnapshotBundleManifest;
|
|
30
|
+
turns: SnapshotTurn[];
|
|
31
|
+
media: Map<string, Uint8Array>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Parse + verify a bundle. Everything is checked before the caller writes:
|
|
35
|
+
* manifest shape, schema match, per-entry checksums, then turn validity. A
|
|
36
|
+
* bundle that fails any check is refused whole.
|
|
37
|
+
*/
|
|
38
|
+
export declare function parseSessionBundle(bytes: Uint8Array): ParsedSessionBundle;
|
|
39
|
+
/** Suggested download file name for a session bundle. */
|
|
40
|
+
export declare function sessionBundleName(sessionId: string): string;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import { strToU8, unzipSync, zipSync } from 'fflate';
|
|
3
|
+
import { APP_VERSION } from '../version.js';
|
|
4
|
+
import { mediaKeysOf } from './media.js';
|
|
5
|
+
import { SNAPSHOT_BUNDLE_FORMAT, SNAPSHOT_BUNDLE_VERSION, SNAPSHOT_SCHEMA, } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Portable session handoff bundle (ADR-0038) — format `ocr-session` v1.
|
|
8
|
+
*
|
|
9
|
+
* A zip of `manifest.json` + `transcript.jsonl` (the exact per-record lines the
|
|
10
|
+
* store already holds) + `media/<sha256>.<ext>` for every payload the
|
|
11
|
+
* transcript references. Deliberately its OWN envelope, not the env book-set
|
|
12
|
+
* (`ocr-env`): that archive's payload whitelist is a closed two-key set and
|
|
13
|
+
* explicitly excludes captured/session bytes (ADR-0007), so folding a
|
|
14
|
+
* transcript into it would require reopening a decision that exists precisely
|
|
15
|
+
* to keep secrets out of a shared book-set. A session bundle carries
|
|
16
|
+
* conversation text, is operator-initiated per session, and never touches the
|
|
17
|
+
* env archive pipeline.
|
|
18
|
+
*
|
|
19
|
+
* Integrity: every payload key gets a `sha256:<hex>` in the manifest and the
|
|
20
|
+
* import re-verifies it byte-for-byte before writing anything — a truncated or
|
|
21
|
+
* tampered bundle is refused whole, never half-imported.
|
|
22
|
+
*/
|
|
23
|
+
export const TRANSCRIPT_ENTRY = 'transcript.jsonl';
|
|
24
|
+
export const MANIFEST_ENTRY = 'manifest.json';
|
|
25
|
+
const MEDIA_PREFIX = 'media/';
|
|
26
|
+
const MAX_ENTRY_BYTES = 32 * 1024 * 1024;
|
|
27
|
+
const MAX_TOTAL_BYTES = 128 * 1024 * 1024;
|
|
28
|
+
const sha256Entry = (text) => 'sha256:' + crypto.createHash('sha256').update(strToU8(text)).digest('hex');
|
|
29
|
+
const sha256Bytes = (bytes) => 'sha256:' + crypto.createHash('sha256').update(bytes).digest('hex');
|
|
30
|
+
export class SessionBundleError extends Error {
|
|
31
|
+
code;
|
|
32
|
+
constructor(message, code = 400) {
|
|
33
|
+
super(message);
|
|
34
|
+
this.code = code;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** Build a bundle from a stored session. Refuses an incomplete session. */
|
|
38
|
+
export function buildSessionBundle(store, sessionId) {
|
|
39
|
+
const snap = store.read(sessionId);
|
|
40
|
+
if (!snap || !snap.turns.length) {
|
|
41
|
+
throw new SessionBundleError(`Session '${sessionId}' has no snapshot transcript`, 404);
|
|
42
|
+
}
|
|
43
|
+
if (snap.incomplete) {
|
|
44
|
+
// A cap-halted session is NOT exportable: its transcript stops mid-turn, so
|
|
45
|
+
// replaying it would either fail upstream or silently drop a step. Say so
|
|
46
|
+
// instead of shipping a broken conversation.
|
|
47
|
+
throw new SessionBundleError(`Session '${sessionId}' is incomplete (${snap.incomplete.reason} at turn ${snap.incomplete.turnIndex ?? 'none'}) — it cannot be exported as a faithful transcript`, 409);
|
|
48
|
+
}
|
|
49
|
+
const transcript = snap.turns.map((t) => JSON.stringify(t)).join('\n') + '\n';
|
|
50
|
+
const entries = { [TRANSCRIPT_ENTRY]: strToU8(transcript) };
|
|
51
|
+
const checksums = { [TRANSCRIPT_ENTRY]: sha256Entry(transcript) };
|
|
52
|
+
// Collect every media key referenced across the whole transcript.
|
|
53
|
+
const keys = new Set();
|
|
54
|
+
for (const turn of snap.turns)
|
|
55
|
+
for (const k of mediaKeysOf(turn.media))
|
|
56
|
+
keys.add(k);
|
|
57
|
+
let mediaCount = 0;
|
|
58
|
+
for (const key of keys) {
|
|
59
|
+
const raw = store.readMediaByKey(key);
|
|
60
|
+
if (!raw)
|
|
61
|
+
continue; // payload evicted by the sweep — the transcript still references it, import will surface the gap
|
|
62
|
+
const name = MEDIA_PREFIX + key;
|
|
63
|
+
const body = new Uint8Array(raw);
|
|
64
|
+
entries[name] = body;
|
|
65
|
+
checksums[name] = sha256Bytes(body);
|
|
66
|
+
mediaCount++;
|
|
67
|
+
}
|
|
68
|
+
const manifest = {
|
|
69
|
+
format: SNAPSHOT_BUNDLE_FORMAT,
|
|
70
|
+
version: SNAPSHOT_BUNDLE_VERSION,
|
|
71
|
+
schema: SNAPSHOT_SCHEMA,
|
|
72
|
+
sessionId,
|
|
73
|
+
exportedAt: new Date().toISOString(),
|
|
74
|
+
appVersion: APP_VERSION,
|
|
75
|
+
turns: snap.turns.length,
|
|
76
|
+
media: mediaCount,
|
|
77
|
+
checksums,
|
|
78
|
+
};
|
|
79
|
+
entries[MANIFEST_ENTRY] = strToU8(JSON.stringify(manifest, null, 2));
|
|
80
|
+
return zipSync(entries, { level: 6 });
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Parse + verify a bundle. Everything is checked before the caller writes:
|
|
84
|
+
* manifest shape, schema match, per-entry checksums, then turn validity. A
|
|
85
|
+
* bundle that fails any check is refused whole.
|
|
86
|
+
*/
|
|
87
|
+
export function parseSessionBundle(bytes) {
|
|
88
|
+
if (bytes.byteLength > MAX_TOTAL_BYTES) {
|
|
89
|
+
throw new SessionBundleError(`Session bundle exceeds the ${Math.round(MAX_TOTAL_BYTES / 1024 / 1024)} MB limit`, 413);
|
|
90
|
+
}
|
|
91
|
+
let files;
|
|
92
|
+
try {
|
|
93
|
+
files = unzipSync(bytes);
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
throw new SessionBundleError('Session bundle is not a readable zip', 400);
|
|
97
|
+
}
|
|
98
|
+
const manifestRaw = files[MANIFEST_ENTRY];
|
|
99
|
+
const transcriptRaw = files[TRANSCRIPT_ENTRY];
|
|
100
|
+
if (!manifestRaw || !transcriptRaw) {
|
|
101
|
+
throw new SessionBundleError(`Session bundle must contain ${MANIFEST_ENTRY} and ${TRANSCRIPT_ENTRY}`, 400);
|
|
102
|
+
}
|
|
103
|
+
let manifest;
|
|
104
|
+
try {
|
|
105
|
+
manifest = JSON.parse(Buffer.from(manifestRaw).toString('utf8'));
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
throw new SessionBundleError(`${MANIFEST_ENTRY} is not valid JSON`, 400);
|
|
109
|
+
}
|
|
110
|
+
if (manifest?.format !== SNAPSHOT_BUNDLE_FORMAT) {
|
|
111
|
+
throw new SessionBundleError(`Not an ${SNAPSHOT_BUNDLE_FORMAT} bundle (format=${String(manifest?.format)})`, 400);
|
|
112
|
+
}
|
|
113
|
+
if (manifest.version > SNAPSHOT_BUNDLE_VERSION) {
|
|
114
|
+
throw new SessionBundleError(`Session bundle version ${manifest.version} is newer than this build supports`, 400);
|
|
115
|
+
}
|
|
116
|
+
if (manifest.schema !== SNAPSHOT_SCHEMA) {
|
|
117
|
+
throw new SessionBundleError(`Session bundle schema ${String(manifest.schema)} is not supported (expected ${SNAPSHOT_SCHEMA})`, 400);
|
|
118
|
+
}
|
|
119
|
+
// Verify checksums for every declared entry, and refuse unknown entries so a
|
|
120
|
+
// bundle cannot smuggle files past the whitelist (mirrors the env-archive
|
|
121
|
+
// import guard's spirit).
|
|
122
|
+
const declared = manifest.checksums ?? {};
|
|
123
|
+
for (const [name, checksum] of Object.entries(declared)) {
|
|
124
|
+
const body = files[name];
|
|
125
|
+
if (!body)
|
|
126
|
+
throw new SessionBundleError(`Session bundle is missing a declared entry '${name}'`, 400);
|
|
127
|
+
if (body.byteLength > MAX_ENTRY_BYTES)
|
|
128
|
+
throw new SessionBundleError(`Session bundle entry '${name}' is too large`, 413);
|
|
129
|
+
if (sha256Bytes(body) !== checksum) {
|
|
130
|
+
throw new SessionBundleError(`Session bundle entry '${name}' failed its checksum — truncated or tampered`, 400);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
for (const name of Object.keys(files)) {
|
|
134
|
+
if (name === MANIFEST_ENTRY || name === TRANSCRIPT_ENTRY)
|
|
135
|
+
continue;
|
|
136
|
+
if (!declared[name])
|
|
137
|
+
throw new SessionBundleError(`Session bundle carries an undeclared entry '${name}'`, 400);
|
|
138
|
+
if (!name.startsWith(MEDIA_PREFIX))
|
|
139
|
+
throw new SessionBundleError(`Session bundle entry '${name}' is outside the whitelist`, 400);
|
|
140
|
+
}
|
|
141
|
+
const turns = [];
|
|
142
|
+
for (const line of Buffer.from(transcriptRaw).toString('utf8').split(/\r?\n/)) {
|
|
143
|
+
const trimmed = line.trim();
|
|
144
|
+
if (!trimmed)
|
|
145
|
+
continue;
|
|
146
|
+
let parsed;
|
|
147
|
+
try {
|
|
148
|
+
parsed = JSON.parse(trimmed);
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
throw new SessionBundleError('Transcript contains a malformed line', 400);
|
|
152
|
+
}
|
|
153
|
+
const t = parsed;
|
|
154
|
+
if (t?.kind !== 'turn' || t.schema !== SNAPSHOT_SCHEMA || typeof t.sessionId !== 'string') {
|
|
155
|
+
throw new SessionBundleError('Transcript contains an invalid turn record', 400);
|
|
156
|
+
}
|
|
157
|
+
turns.push(t);
|
|
158
|
+
}
|
|
159
|
+
if (!turns.length)
|
|
160
|
+
throw new SessionBundleError('Transcript carries no turns', 400);
|
|
161
|
+
if (manifest.turns !== turns.length) {
|
|
162
|
+
throw new SessionBundleError(`Manifest declares ${manifest.turns} turns but the transcript carries ${turns.length}`, 400);
|
|
163
|
+
}
|
|
164
|
+
const media = new Map();
|
|
165
|
+
for (const name of Object.keys(declared)) {
|
|
166
|
+
if (!name.startsWith(MEDIA_PREFIX))
|
|
167
|
+
continue;
|
|
168
|
+
media.set(name.slice(MEDIA_PREFIX.length), files[name]);
|
|
169
|
+
}
|
|
170
|
+
return { manifest, turns, media };
|
|
171
|
+
}
|
|
172
|
+
/** Suggested download file name for a session bundle. */
|
|
173
|
+
export function sessionBundleName(sessionId) {
|
|
174
|
+
const safe = sessionId.replace(/[^\w.@:-]/g, '_').slice(0, 80) || 'session';
|
|
175
|
+
const today = new Date().toISOString().slice(0, 10).replace(/-/g, '');
|
|
176
|
+
return `${safe}-${today}.ocr_session.zip`;
|
|
177
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { HandoffTranscript } from './transcript.js';
|
|
2
|
+
/**
|
|
3
|
+
* Handoff modes (ADR-0039 §8).
|
|
4
|
+
*
|
|
5
|
+
* `fork` keeps every stored part verbatim — the target receives a true branch
|
|
6
|
+
* of the conversation. `compact` is the agent-client semantics: a MODEL reads
|
|
7
|
+
* the conversation and writes a structured handoff summary that replaces it
|
|
8
|
+
* (`summarize.ts`); this module supplies the input bounding for that call.
|
|
9
|
+
* `trim` is the mechanical compression applied to the neutral transcript
|
|
10
|
+
* before any writer runs: zero model calls, deterministic (same input → same
|
|
11
|
+
* file), and honest about what it removes (omission placeholders stay in the
|
|
12
|
+
* text stream).
|
|
13
|
+
*
|
|
14
|
+
* Trim rules (each one targets bulk that carries no continuation value):
|
|
15
|
+
* - `thinking` parts are dropped — reasoning is neither reproducible nor
|
|
16
|
+
* resendable (clients never resend prior thinking), so it only inflates.
|
|
17
|
+
* - `image` parts become a `[image omitted]` text placeholder — the count of
|
|
18
|
+
* attachments stays visible, the base64 payload does not travel.
|
|
19
|
+
* - `toolResult` text is truncated to the limit with a marker naming the
|
|
20
|
+
* original size. The message SHELL (toolCallId / toolName / isError) is
|
|
21
|
+
* always kept so the call/result pairing stays valid.
|
|
22
|
+
* - `toolCall` parts, user/assistant/system text, and message order are kept
|
|
23
|
+
* verbatim — that is the narrative being handed off.
|
|
24
|
+
*/
|
|
25
|
+
export type HandoffMode = 'fork' | 'compact' | 'trim';
|
|
26
|
+
export interface CompressionStats {
|
|
27
|
+
thinkingParts: number;
|
|
28
|
+
imageParts: number;
|
|
29
|
+
truncatedToolResults: number;
|
|
30
|
+
/** JSON size of the message list before/after, for the console's "-X%" line. */
|
|
31
|
+
charsBefore: number;
|
|
32
|
+
charsAfter: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Tool results longer than this are cut with a size marker. The trim MODE uses
|
|
36
|
+
* the small limit (bulk is what it exists to remove); the compact mode's
|
|
37
|
+
* summarizer-input pass uses a larger one, because the model can still mine
|
|
38
|
+
* detail out of a long result that a target client would merely re-read.
|
|
39
|
+
*/
|
|
40
|
+
export declare const TRIM_TOOL_RESULT_LIMIT = 500;
|
|
41
|
+
export declare function compressTranscript(t: HandoffTranscript, opts?: {
|
|
42
|
+
toolResultLimit?: number;
|
|
43
|
+
}): {
|
|
44
|
+
transcript: HandoffTranscript;
|
|
45
|
+
stats: CompressionStats;
|
|
46
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool results longer than this are cut with a size marker. The trim MODE uses
|
|
3
|
+
* the small limit (bulk is what it exists to remove); the compact mode's
|
|
4
|
+
* summarizer-input pass uses a larger one, because the model can still mine
|
|
5
|
+
* detail out of a long result that a target client would merely re-read.
|
|
6
|
+
*/
|
|
7
|
+
export const TRIM_TOOL_RESULT_LIMIT = 500;
|
|
8
|
+
const OMITTED_IMAGE = '[image omitted]';
|
|
9
|
+
function truncateToolText(text, limit) {
|
|
10
|
+
if (text.length <= limit)
|
|
11
|
+
return { text, truncated: false };
|
|
12
|
+
return {
|
|
13
|
+
text: `${text.slice(0, limit)}\n…[truncated, ${text.length} chars total]`,
|
|
14
|
+
truncated: true,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export function compressTranscript(t, opts = {}) {
|
|
18
|
+
const limit = opts.toolResultLimit ?? TRIM_TOOL_RESULT_LIMIT;
|
|
19
|
+
let thinkingParts = 0;
|
|
20
|
+
let imageParts = 0;
|
|
21
|
+
let truncatedToolResults = 0;
|
|
22
|
+
const charsBefore = JSON.stringify(t.messages).length;
|
|
23
|
+
const messages = [];
|
|
24
|
+
for (const msg of t.messages) {
|
|
25
|
+
const content = [];
|
|
26
|
+
let resultTruncated = false;
|
|
27
|
+
for (const part of msg.content) {
|
|
28
|
+
switch (part.type) {
|
|
29
|
+
case 'thinking':
|
|
30
|
+
thinkingParts++;
|
|
31
|
+
break;
|
|
32
|
+
case 'image':
|
|
33
|
+
imageParts++;
|
|
34
|
+
content.push({ type: 'text', text: OMITTED_IMAGE });
|
|
35
|
+
break;
|
|
36
|
+
case 'text': {
|
|
37
|
+
if (msg.role === 'toolResult') {
|
|
38
|
+
const cut = truncateToolText(part.text, limit);
|
|
39
|
+
if (cut.truncated)
|
|
40
|
+
resultTruncated = true;
|
|
41
|
+
content.push({ type: 'text', text: cut.text });
|
|
42
|
+
}
|
|
43
|
+
else if (part.text) {
|
|
44
|
+
content.push(part);
|
|
45
|
+
}
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
case 'toolCall':
|
|
49
|
+
content.push(part);
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (resultTruncated)
|
|
54
|
+
truncatedToolResults++;
|
|
55
|
+
if (!content.length) {
|
|
56
|
+
// A message that was ONLY thinking disappears entirely. An emptied
|
|
57
|
+
// toolResult keeps a shell — dropping it would orphan the tool call.
|
|
58
|
+
if (msg.role === 'toolResult') {
|
|
59
|
+
content.push({ type: 'text', text: '[result omitted]' });
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
messages.push({ ...msg, content });
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
transcript: { ...t, messages },
|
|
69
|
+
stats: {
|
|
70
|
+
thinkingParts,
|
|
71
|
+
imageParts,
|
|
72
|
+
truncatedToolResults,
|
|
73
|
+
charsBefore,
|
|
74
|
+
charsAfter: JSON.stringify(messages).length,
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|