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
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { SessionSnapshotStore } from '../store.js';
|
|
2
|
+
import { type CompressionStats, type HandoffMode } from './compress.js';
|
|
3
|
+
export type { HandoffMode } from './compress.js';
|
|
4
|
+
import { type HandoffSummarizer } from './summarize.js';
|
|
5
|
+
import { type JsonlTarget } from './jsonl-writer.js';
|
|
6
|
+
/**
|
|
7
|
+
* Conversation handoff service (ADR-0039) — turn a stored snapshot into a NEW
|
|
8
|
+
* session in another client, without ever mutating the gateway's own state.
|
|
9
|
+
*
|
|
10
|
+
* Three targets share one pipeline:
|
|
11
|
+
* snapshot turns → neutral transcript → mode preparation → per-client writer.
|
|
12
|
+
* The only per-target differences are where the client keeps its sessions and
|
|
13
|
+
* how it spells a session file, both isolated in the writers.
|
|
14
|
+
*
|
|
15
|
+
* Three modes (ADR-0039 §8):
|
|
16
|
+
* fork — the transcript verbatim (a true branch of the conversation).
|
|
17
|
+
* compact — a MODEL summarizes it agent-style; the summary replaces the
|
|
18
|
+
* transcript as ONE user message. Mechanical trimming bounds the
|
|
19
|
+
* summarizer's input only.
|
|
20
|
+
* trim — mechanical trimming (no model calls, deterministic): thinking
|
|
21
|
+
* and images dropped, tool results truncated.
|
|
22
|
+
*
|
|
23
|
+
* FAIL-VISIBLE, NEVER PARTIAL: a migration either creates a complete session or
|
|
24
|
+
* throws with the target's own message. There is no "imported 8 of 12 turns"
|
|
25
|
+
* state — that would be a conversation the user believes is whole.
|
|
26
|
+
*/
|
|
27
|
+
/** Every target the console can migrate into. */
|
|
28
|
+
export type HandoffTarget = 'pi' | 'omp' | 'opencode';
|
|
29
|
+
export declare const HANDOFF_TARGETS: readonly HandoffTarget[];
|
|
30
|
+
/** The three migration modes (ADR-0039 §8). */
|
|
31
|
+
export declare const HANDOFF_MODES: readonly HandoffMode[];
|
|
32
|
+
/** What a non-fork mode did; `null` on fork. Discriminated by `kind`. */
|
|
33
|
+
export type HandoffCompression = ({
|
|
34
|
+
kind: 'trim';
|
|
35
|
+
} & CompressionStats) | {
|
|
36
|
+
kind: 'compact';
|
|
37
|
+
model: string;
|
|
38
|
+
messagesBefore: number;
|
|
39
|
+
charsBefore: number;
|
|
40
|
+
charsAfter: number;
|
|
41
|
+
};
|
|
42
|
+
/** Where each client keeps its agent data (override for tests / non-default homes). */
|
|
43
|
+
export declare function defaultAgentDir(target: JsonlTarget): string;
|
|
44
|
+
export interface HandoffRequest {
|
|
45
|
+
sessionId: string;
|
|
46
|
+
target: HandoffTarget;
|
|
47
|
+
/**
|
|
48
|
+
* Working directory the new session is filed under. Only used by pi/omp (they
|
|
49
|
+
* bucket sessions by cwd slug); opencode records it in the session row. The
|
|
50
|
+
* gateway never sees the client's cwd, so the operator picks it.
|
|
51
|
+
*/
|
|
52
|
+
workingDir: string;
|
|
53
|
+
/** Override the client's agent dir (pi/omp) or share dir (opencode). */
|
|
54
|
+
agentDir?: string;
|
|
55
|
+
/** `fork` (default) keeps every part verbatim; see the mode table above. */
|
|
56
|
+
mode?: HandoffMode;
|
|
57
|
+
/** `compact` only: the model ref the operator picked to write the summary. */
|
|
58
|
+
model?: string;
|
|
59
|
+
/** `compact` only: the gateway call seam (server wires the real one; tests inject a fake). */
|
|
60
|
+
summarize?: HandoffSummarizer;
|
|
61
|
+
/** Injectable for opencode — lets a test assert the argv without a daemon. */
|
|
62
|
+
run?: (args: string[]) => {
|
|
63
|
+
code: number;
|
|
64
|
+
stdout: string;
|
|
65
|
+
stderr: string;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export interface HandoffResult {
|
|
69
|
+
target: HandoffTarget;
|
|
70
|
+
mode: HandoffMode;
|
|
71
|
+
sessionId: string;
|
|
72
|
+
/** The path a human can open (the JSONL file, or the opencode db). */
|
|
73
|
+
location: string;
|
|
74
|
+
messages: number;
|
|
75
|
+
/** Media the transcript referenced but the store could not resolve. */
|
|
76
|
+
skippedMedia: string[];
|
|
77
|
+
/** What the mode changed; `null` on fork. */
|
|
78
|
+
compression: HandoffCompression | null;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Migrate one stored session into a target client. Throws `HandoffError` with a
|
|
82
|
+
* user-facing message on any refusal (missing/incomplete transcript, target
|
|
83
|
+
* write failure, compaction failure) — the route maps it to a status code.
|
|
84
|
+
*/
|
|
85
|
+
export declare function migrateSession(store: SessionSnapshotStore, req: HandoffRequest): Promise<HandoffResult>;
|
|
86
|
+
/** A refusal the route can turn into an HTTP status + message. */
|
|
87
|
+
export declare class HandoffError extends Error {
|
|
88
|
+
readonly code: number;
|
|
89
|
+
constructor(message: string, code?: number);
|
|
90
|
+
}
|
|
91
|
+
export interface JsonlExportRequest {
|
|
92
|
+
sessionId: string;
|
|
93
|
+
target: JsonlTarget;
|
|
94
|
+
/** Embedded as the session `cwd`; defaults to the gateway's own cwd. */
|
|
95
|
+
workingDir?: string;
|
|
96
|
+
/** `fork` (default) keeps every part verbatim; see the mode table above. */
|
|
97
|
+
mode?: HandoffMode;
|
|
98
|
+
/** `compact` only: the model ref the operator picked to write the summary. */
|
|
99
|
+
model?: string;
|
|
100
|
+
/** `compact` only: the gateway call seam. */
|
|
101
|
+
summarize?: HandoffSummarizer;
|
|
102
|
+
}
|
|
103
|
+
export interface JsonlExportResult {
|
|
104
|
+
fileName: string;
|
|
105
|
+
body: string;
|
|
106
|
+
messages: number;
|
|
107
|
+
skippedMedia: string[];
|
|
108
|
+
compression: HandoffCompression | null;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Render a session as the pi/omp session JSONL a migration would write, and
|
|
112
|
+
* hand the bytes back instead of filing them under the client's home. Same
|
|
113
|
+
* snapshot gates (and the same mode preparation) as the migration itself — an
|
|
114
|
+
* export of a truncated conversation would be a file the operator believes is
|
|
115
|
+
* whole.
|
|
116
|
+
*/
|
|
117
|
+
export declare function exportJsonlSession(store: SessionSnapshotStore, req: JsonlExportRequest): Promise<JsonlExportResult>;
|
|
118
|
+
/** Whether a media ref is one the writers will resolve (used by the preview route). */
|
|
119
|
+
export declare function isMediaRef(value: unknown): value is string;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import os from 'node:os';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { EXT_TO_MIME } from '../../ir/media.js';
|
|
4
|
+
import { SNAPSHOT_MEDIA_REF_PREFIX } from '../types.js';
|
|
5
|
+
import { buildHandoffTranscript } from './transcript.js';
|
|
6
|
+
import { compressTranscript } from './compress.js';
|
|
7
|
+
import { renderHistory } from './summarize.js';
|
|
8
|
+
import { renderJsonlSession, writeJsonlSession } from './jsonl-writer.js';
|
|
9
|
+
import { defaultOpencodeShareDir, writeOpencodeSession } from './opencode-writer.js';
|
|
10
|
+
export const HANDOFF_TARGETS = ['pi', 'omp', 'opencode'];
|
|
11
|
+
/** The three migration modes (ADR-0039 §8). */
|
|
12
|
+
export const HANDOFF_MODES = ['fork', 'compact', 'trim'];
|
|
13
|
+
/** Where each client keeps its agent data (override for tests / non-default homes). */
|
|
14
|
+
export function defaultAgentDir(target) {
|
|
15
|
+
return path.join(os.homedir(), target === 'pi' ? '.pi' : '.omp', 'agent');
|
|
16
|
+
}
|
|
17
|
+
/** First line the compacted conversation opens with — the model must not re-ask. */
|
|
18
|
+
const COMPACT_FRAMING = 'This session was compacted when it was handed off from OmniCellRouter. The summary below replaces the original conversation — continue from it without asking the user to repeat anything it covers.';
|
|
19
|
+
/** Resolve a `sha.ext` key to base64 for the writers to inline. */
|
|
20
|
+
function makeResolver(store, media) {
|
|
21
|
+
void media;
|
|
22
|
+
return (key) => {
|
|
23
|
+
const raw = store.readMediaByKey(key);
|
|
24
|
+
if (!raw)
|
|
25
|
+
return null;
|
|
26
|
+
const ext = key.slice(key.lastIndexOf('.') + 1);
|
|
27
|
+
// ONE MIME table for the whole gateway (`ir/media.ts`): a second, hand-written
|
|
28
|
+
// copy here would drift from the capture archive's — the two planes name the
|
|
29
|
+
// same payloads and must agree on what `png` means.
|
|
30
|
+
const mime = EXT_TO_MIME[ext] ?? 'application/octet-stream';
|
|
31
|
+
return { data: Buffer.from(raw).toString('base64'), mimeType: mime };
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Load a session's neutral transcript, applying every snapshot gate the
|
|
36
|
+
* migration and the export share. Throws `HandoffError` on any refusal.
|
|
37
|
+
*/
|
|
38
|
+
function loadTranscript(store, sessionId) {
|
|
39
|
+
const snap = store.read(sessionId);
|
|
40
|
+
if (!snap) {
|
|
41
|
+
throw new HandoffError(`Session '${sessionId}' has no snapshot transcript — enable sessionSnapshots and run a turn first`, 404);
|
|
42
|
+
}
|
|
43
|
+
if (snap.incomplete) {
|
|
44
|
+
// A halted session may have ZERO stored turns (the very turn that overflowed
|
|
45
|
+
// was refused), so this check must precede any "has turns" test — otherwise
|
|
46
|
+
// a truncated conversation would be reported as merely missing.
|
|
47
|
+
throw new HandoffError(`Session '${sessionId}' is incomplete (${snap.incomplete.reason}) — a truncated transcript cannot be migrated`, 409);
|
|
48
|
+
}
|
|
49
|
+
if (!snap.turns.length) {
|
|
50
|
+
throw new HandoffError(`Session '${sessionId}' has no snapshot turns yet`, 404);
|
|
51
|
+
}
|
|
52
|
+
const transcript = buildHandoffTranscript(snap.turns, makeResolver(store, snap.turns[snap.turns.length - 1].media));
|
|
53
|
+
if (!transcript.messages.length) {
|
|
54
|
+
throw new HandoffError(`Session '${sessionId}' produced no migratable messages`, 422);
|
|
55
|
+
}
|
|
56
|
+
return transcript;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Apply the chosen mode to the neutral transcript. `compact` REPLACES the
|
|
60
|
+
* messages with one user message (framing + model summary); the title stays the
|
|
61
|
+
* original first user text so the target client still files the session under
|
|
62
|
+
* the conversation's own name.
|
|
63
|
+
*/
|
|
64
|
+
async function applyHandoffMode(transcript, mode, opts) {
|
|
65
|
+
if (mode === 'fork')
|
|
66
|
+
return { transcript, compression: null };
|
|
67
|
+
if (mode === 'trim') {
|
|
68
|
+
const { transcript: trimmed, stats } = compressTranscript(transcript);
|
|
69
|
+
return { transcript: trimmed, compression: { kind: 'trim', ...stats } };
|
|
70
|
+
}
|
|
71
|
+
const model = opts.model?.trim();
|
|
72
|
+
if (!model) {
|
|
73
|
+
throw new HandoffError('compact mode needs a summarizer model (model)', 400);
|
|
74
|
+
}
|
|
75
|
+
if (!opts.summarize) {
|
|
76
|
+
throw new HandoffError('compact mode is not wired to a summarizer', 500);
|
|
77
|
+
}
|
|
78
|
+
const charsBefore = JSON.stringify(transcript.messages).length;
|
|
79
|
+
const out = await opts.summarize({ history: renderHistory(transcript), model });
|
|
80
|
+
if ('error' in out) {
|
|
81
|
+
throw new HandoffError(out.error, out.status);
|
|
82
|
+
}
|
|
83
|
+
const text = `${COMPACT_FRAMING}\n\n${out.summary}`;
|
|
84
|
+
return {
|
|
85
|
+
transcript: {
|
|
86
|
+
...transcript,
|
|
87
|
+
messages: [{ role: 'user', content: [{ type: 'text', text }], ts: Date.now() }],
|
|
88
|
+
},
|
|
89
|
+
compression: { kind: 'compact', model, messagesBefore: transcript.messages.length, charsBefore, charsAfter: text.length },
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Migrate one stored session into a target client. Throws `HandoffError` with a
|
|
94
|
+
* user-facing message on any refusal (missing/incomplete transcript, target
|
|
95
|
+
* write failure, compaction failure) — the route maps it to a status code.
|
|
96
|
+
*/
|
|
97
|
+
export async function migrateSession(store, req) {
|
|
98
|
+
if (!req.workingDir || !path.isAbsolute(req.workingDir)) {
|
|
99
|
+
throw new HandoffError('workingDir must be an absolute path (the gateway cannot infer the client\'s working directory)', 400);
|
|
100
|
+
}
|
|
101
|
+
const mode = req.mode ?? 'fork';
|
|
102
|
+
const { transcript, compression } = await applyHandoffMode(loadTranscript(store, req.sessionId), mode, {
|
|
103
|
+
model: req.model,
|
|
104
|
+
summarize: req.summarize,
|
|
105
|
+
});
|
|
106
|
+
if (req.target === 'opencode') {
|
|
107
|
+
const out = writeOpencodeSession({
|
|
108
|
+
shareDir: req.agentDir ?? defaultOpencodeShareDir(),
|
|
109
|
+
workingDir: req.workingDir,
|
|
110
|
+
transcript,
|
|
111
|
+
...(req.run ? { run: req.run } : {}),
|
|
112
|
+
});
|
|
113
|
+
return { target: 'opencode', mode, sessionId: out.sessionId, location: out.file, messages: out.messages, skippedMedia: out.skippedMedia, compression };
|
|
114
|
+
}
|
|
115
|
+
const agentDir = req.agentDir ?? defaultAgentDir(req.target);
|
|
116
|
+
const out = writeJsonlSession({
|
|
117
|
+
target: req.target,
|
|
118
|
+
agentDir,
|
|
119
|
+
workingDir: req.workingDir,
|
|
120
|
+
transcript,
|
|
121
|
+
});
|
|
122
|
+
return { target: req.target, mode, sessionId: out.sessionId, location: out.file, messages: out.messages, skippedMedia: out.skippedMedia, compression };
|
|
123
|
+
}
|
|
124
|
+
/** A refusal the route can turn into an HTTP status + message. */
|
|
125
|
+
export class HandoffError extends Error {
|
|
126
|
+
code;
|
|
127
|
+
constructor(message, code = 400) {
|
|
128
|
+
super(message);
|
|
129
|
+
this.code = code;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Render a session as the pi/omp session JSONL a migration would write, and
|
|
134
|
+
* hand the bytes back instead of filing them under the client's home. Same
|
|
135
|
+
* snapshot gates (and the same mode preparation) as the migration itself — an
|
|
136
|
+
* export of a truncated conversation would be a file the operator believes is
|
|
137
|
+
* whole.
|
|
138
|
+
*/
|
|
139
|
+
export async function exportJsonlSession(store, req) {
|
|
140
|
+
const { transcript, compression } = await applyHandoffMode(loadTranscript(store, req.sessionId), req.mode ?? 'fork', {
|
|
141
|
+
model: req.model,
|
|
142
|
+
summarize: req.summarize,
|
|
143
|
+
});
|
|
144
|
+
const rendered = renderJsonlSession({
|
|
145
|
+
target: req.target,
|
|
146
|
+
workingDir: req.workingDir?.trim() || process.cwd(),
|
|
147
|
+
transcript,
|
|
148
|
+
});
|
|
149
|
+
return {
|
|
150
|
+
fileName: rendered.fileName,
|
|
151
|
+
body: rendered.body,
|
|
152
|
+
messages: rendered.messages,
|
|
153
|
+
skippedMedia: rendered.skippedMedia,
|
|
154
|
+
compression,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/** Whether a media ref is one the writers will resolve (used by the preview route). */
|
|
158
|
+
export function isMediaRef(value) {
|
|
159
|
+
return typeof value === 'string' && value.startsWith(SNAPSHOT_MEDIA_REF_PREFIX);
|
|
160
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { type HandoffTranscript } from './transcript.js';
|
|
2
|
+
/**
|
|
3
|
+
* pi / omp session writers (ADR-0039).
|
|
4
|
+
*
|
|
5
|
+
* Both read `~/.<client>/agent/sessions/<slug>/<ISO>_<uuid>.jsonl`: one JSON
|
|
6
|
+
* object per line, linked by `id` / `parentId` into a TREE. They differ in only
|
|
7
|
+
* two places, both verified against real session files on disk:
|
|
8
|
+
* - omp writes a `title` header line BEFORE `session`; pi does not;
|
|
9
|
+
* - pi's `model_change` names `{provider, modelId}` while omp names a single
|
|
10
|
+
* `{model: "provider/model"}` string.
|
|
11
|
+
* Everything else (message roles, `content[]` part kinds, toolCall arguments as
|
|
12
|
+
* a JSON OBJECT, toolResult carrying `toolCallId` + `toolName`, image parts as
|
|
13
|
+
* `{type, data, mimeType}` with raw base64) is identical, so one writer body
|
|
14
|
+
* serves both with a small per-client `profile`.
|
|
15
|
+
*
|
|
16
|
+
* WHY WRITE THE FILE DIRECTLY instead of scripting the interactive CLI: the
|
|
17
|
+
* clients expose no "import a transcript" verb (pi/omp only have `--from-claude`
|
|
18
|
+
* / `--from-codex`), and driving a TUI to replay a conversation would consume
|
|
19
|
+
* real model tokens and could not reproduce historical tool results. The file
|
|
20
|
+
* IS the session; writing it is the same thing the client does.
|
|
21
|
+
*/
|
|
22
|
+
export type JsonlTarget = 'pi' | 'omp';
|
|
23
|
+
/**
|
|
24
|
+
* Session directory slug for a working directory — the clients' OWN encoder.
|
|
25
|
+
*
|
|
26
|
+
* Measured against real pi/omp session trees on Windows: `:` and each separator
|
|
27
|
+
* each become ONE `-`, wrapped in `--`
|
|
28
|
+
* (`D:\OpenHub\omnicell-router` → `--D--OpenHub-omnicell-router--`,
|
|
29
|
+
* `C:\WINDOWS\system32` → `--C--WINDOWS--system32--`).
|
|
30
|
+
* Getting this wrong files the session where the client never looks.
|
|
31
|
+
*/
|
|
32
|
+
export declare function sessionDirSlug(workingDir: string): string;
|
|
33
|
+
/** `<ISO with '-' instead of ':'>_<uuid>` — the file name half of a session. */
|
|
34
|
+
export declare function jsonlSessionFileName(ts: number, uuid: string): string;
|
|
35
|
+
export interface RenderJsonlOptions {
|
|
36
|
+
target: JsonlTarget;
|
|
37
|
+
/** Working directory the session is filed under (embedded as `cwd`). */
|
|
38
|
+
workingDir: string;
|
|
39
|
+
transcript: HandoffTranscript;
|
|
40
|
+
/** Epoch ms; defaults to now. */
|
|
41
|
+
now?: number;
|
|
42
|
+
}
|
|
43
|
+
export interface RenderedJsonl {
|
|
44
|
+
/** The clients' own name convention: `<ISO with '-' instead of ':'>_<uuid>.jsonl`. */
|
|
45
|
+
fileName: string;
|
|
46
|
+
sessionId: string;
|
|
47
|
+
/** The complete file body (newline-terminated). */
|
|
48
|
+
body: string;
|
|
49
|
+
nodes: number;
|
|
50
|
+
messages: number;
|
|
51
|
+
skippedMedia: string[];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Render one session JSONL body WITHOUT touching any client directory — the
|
|
55
|
+
* export route hands these bytes straight to the browser, and the writer below
|
|
56
|
+
* files them under the client's session tree. One generator serves both so a
|
|
57
|
+
* downloaded file and a migrated one can never drift apart.
|
|
58
|
+
*/
|
|
59
|
+
export declare function renderJsonlSession(opts: RenderJsonlOptions): RenderedJsonl;
|
|
60
|
+
export interface WriteJsonlOptions {
|
|
61
|
+
target: JsonlTarget;
|
|
62
|
+
/** Client home dir (e.g. `~/.pi/agent` — the caller passes the AGENT dir). */
|
|
63
|
+
agentDir: string;
|
|
64
|
+
/** Working directory the session is filed under. */
|
|
65
|
+
workingDir: string;
|
|
66
|
+
transcript: HandoffTranscript;
|
|
67
|
+
/** Epoch ms; defaults to now. */
|
|
68
|
+
now?: number;
|
|
69
|
+
}
|
|
70
|
+
export interface WriteJsonlResult {
|
|
71
|
+
file: string;
|
|
72
|
+
sessionId: string;
|
|
73
|
+
nodes: number;
|
|
74
|
+
messages: number;
|
|
75
|
+
skippedMedia: string[];
|
|
76
|
+
}
|
|
77
|
+
/** Write one session JSONL under `<agentDir>/sessions/<slug>/`. */
|
|
78
|
+
export declare function writeJsonlSession(opts: WriteJsonlOptions): WriteJsonlResult;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { renameWithRetry } from '../../utils/atomic-write.js';
|
|
5
|
+
import { clipTitle } from './transcript.js';
|
|
6
|
+
const PROFILES = {
|
|
7
|
+
pi: {
|
|
8
|
+
writesTitleNode: false,
|
|
9
|
+
modelChange: (ref) => {
|
|
10
|
+
const slash = ref.indexOf('/');
|
|
11
|
+
return slash > 0
|
|
12
|
+
? { provider: ref.slice(0, slash), modelId: ref.slice(slash + 1) }
|
|
13
|
+
: { provider: ref, modelId: ref };
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
omp: {
|
|
17
|
+
writesTitleNode: true,
|
|
18
|
+
modelChange: (ref) => ({ model: ref }),
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Session directory slug for a working directory — the clients' OWN encoder.
|
|
23
|
+
*
|
|
24
|
+
* Measured against real pi/omp session trees on Windows: `:` and each separator
|
|
25
|
+
* each become ONE `-`, wrapped in `--`
|
|
26
|
+
* (`D:\OpenHub\omnicell-router` → `--D--OpenHub-omnicell-router--`,
|
|
27
|
+
* `C:\WINDOWS\system32` → `--C--WINDOWS--system32--`).
|
|
28
|
+
* Getting this wrong files the session where the client never looks.
|
|
29
|
+
*/
|
|
30
|
+
export function sessionDirSlug(workingDir) {
|
|
31
|
+
return '--' + path.resolve(workingDir).replace(/[:\\/]/g, '-') + '--';
|
|
32
|
+
}
|
|
33
|
+
/** `<ISO with '-' instead of ':'>_<uuid>` — the file name half of a session. */
|
|
34
|
+
export function jsonlSessionFileName(ts, uuid) {
|
|
35
|
+
return `${new Date(ts).toISOString().replace(/:/g, '-')}_${uuid}.jsonl`;
|
|
36
|
+
}
|
|
37
|
+
const randomHex = (chars) => crypto.randomBytes(Math.ceil(chars / 2)).toString('hex').slice(0, chars);
|
|
38
|
+
function renderPart(part) {
|
|
39
|
+
switch (part.type) {
|
|
40
|
+
case 'text':
|
|
41
|
+
return { type: 'text', text: part.text };
|
|
42
|
+
case 'thinking':
|
|
43
|
+
return {
|
|
44
|
+
type: 'thinking',
|
|
45
|
+
thinking: part.thinking,
|
|
46
|
+
...(part.thinkingSignature ? { thinkingSignature: part.thinkingSignature } : {}),
|
|
47
|
+
};
|
|
48
|
+
case 'toolCall':
|
|
49
|
+
return {
|
|
50
|
+
type: 'toolCall',
|
|
51
|
+
id: part.id,
|
|
52
|
+
name: part.name,
|
|
53
|
+
// pi/omp store arguments as a JSON OBJECT, not a string.
|
|
54
|
+
arguments: part.arguments,
|
|
55
|
+
};
|
|
56
|
+
case 'image':
|
|
57
|
+
return { type: 'image', data: part.data, mimeType: part.mimeType };
|
|
58
|
+
default:
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function renderMessage(msg, model) {
|
|
63
|
+
const content = msg.content.map(renderPart).filter((p) => p !== null);
|
|
64
|
+
if (!content.length)
|
|
65
|
+
return null;
|
|
66
|
+
if (msg.role === 'toolResult') {
|
|
67
|
+
return {
|
|
68
|
+
role: 'toolResult',
|
|
69
|
+
content,
|
|
70
|
+
extra: {
|
|
71
|
+
...(msg.toolCallId ? { toolCallId: msg.toolCallId } : {}),
|
|
72
|
+
...(msg.toolName ? { toolName: msg.toolName } : {}),
|
|
73
|
+
isError: msg.isError === true,
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
if (msg.role === 'assistant') {
|
|
78
|
+
const slash = model.indexOf('/');
|
|
79
|
+
const provider = slash > 0 ? model.slice(0, slash) : 'omnicell-router';
|
|
80
|
+
const modelId = slash > 0 ? model.slice(slash + 1) : model;
|
|
81
|
+
return {
|
|
82
|
+
role: 'assistant',
|
|
83
|
+
content,
|
|
84
|
+
extra: {
|
|
85
|
+
api: 'openai-completions',
|
|
86
|
+
provider,
|
|
87
|
+
model: modelId,
|
|
88
|
+
// `cost` is REQUIRED even though every migrated token count is 0: pi's
|
|
89
|
+
// footer stats sum `usage.cost.total` unconditionally and crash on a
|
|
90
|
+
// usage object without it (`Cannot read properties of undefined
|
|
91
|
+
// (reading 'total')`). This mirrors the clients' own empty-usage shape.
|
|
92
|
+
usage: {
|
|
93
|
+
input: 0,
|
|
94
|
+
output: 0,
|
|
95
|
+
cacheRead: 0,
|
|
96
|
+
cacheWrite: 0,
|
|
97
|
+
totalTokens: 0,
|
|
98
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
99
|
+
},
|
|
100
|
+
stopReason: content.some((p) => p.type === 'toolCall') ? 'toolUse' : 'stop',
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
if (msg.role === 'system') {
|
|
105
|
+
return { role: 'system', content, extra: {} };
|
|
106
|
+
}
|
|
107
|
+
return { role: 'user', content, extra: {} };
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Render one session JSONL body WITHOUT touching any client directory — the
|
|
111
|
+
* export route hands these bytes straight to the browser, and the writer below
|
|
112
|
+
* files them under the client's session tree. One generator serves both so a
|
|
113
|
+
* downloaded file and a migrated one can never drift apart.
|
|
114
|
+
*/
|
|
115
|
+
export function renderJsonlSession(opts) {
|
|
116
|
+
const profile = PROFILES[opts.target];
|
|
117
|
+
const now = opts.now ?? Date.now();
|
|
118
|
+
const uuid = crypto.randomUUID();
|
|
119
|
+
const fileName = jsonlSessionFileName(now, uuid);
|
|
120
|
+
const iso = new Date(now).toISOString();
|
|
121
|
+
const ref = opts.transcript.models[0] || 'omnicell-router/auto';
|
|
122
|
+
const title = clipTitle(opts.transcript.title) || 'Imported conversation';
|
|
123
|
+
const lines = [];
|
|
124
|
+
let seq = 0;
|
|
125
|
+
const nextId = () => `n${(++seq).toString(36).padStart(6, '0')}${randomHex(2)}`;
|
|
126
|
+
let parent = null;
|
|
127
|
+
const push = (node) => {
|
|
128
|
+
const id = nextId();
|
|
129
|
+
lines.push({ ...node, id, parentId: parent, timestamp: iso });
|
|
130
|
+
parent = id;
|
|
131
|
+
return id;
|
|
132
|
+
};
|
|
133
|
+
if (profile.writesTitleNode) {
|
|
134
|
+
lines.push({ type: 'title', v: 1, title, updatedAt: iso, pad: ' '.repeat(110) });
|
|
135
|
+
}
|
|
136
|
+
lines.push({ type: 'session', version: 3, id: uuid, timestamp: iso, cwd: opts.workingDir });
|
|
137
|
+
// model_change carries NO parentId in real files (it roots the chain).
|
|
138
|
+
lines.push({ type: 'model_change', id: nextId(), parentId: null, timestamp: iso, ...profile.modelChange(ref) });
|
|
139
|
+
parent = lines[lines.length - 1].id;
|
|
140
|
+
let messageCount = 0;
|
|
141
|
+
for (const msg of opts.transcript.messages) {
|
|
142
|
+
const rendered = renderMessage(msg, ref);
|
|
143
|
+
if (!rendered)
|
|
144
|
+
continue;
|
|
145
|
+
push({
|
|
146
|
+
type: 'message',
|
|
147
|
+
message: {
|
|
148
|
+
role: rendered.role,
|
|
149
|
+
content: rendered.content,
|
|
150
|
+
...(rendered.extra ?? {}),
|
|
151
|
+
...(msg.ts ? { timestamp: msg.ts } : {}),
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
messageCount++;
|
|
155
|
+
}
|
|
156
|
+
const body = lines.map((l) => JSON.stringify(l)).join('\n') + '\n';
|
|
157
|
+
return { fileName, sessionId: uuid, body, nodes: lines.length, messages: messageCount, skippedMedia: opts.transcript.unresolvedMedia };
|
|
158
|
+
}
|
|
159
|
+
/** Write one session JSONL under `<agentDir>/sessions/<slug>/`. */
|
|
160
|
+
export function writeJsonlSession(opts) {
|
|
161
|
+
const rendered = renderJsonlSession(opts);
|
|
162
|
+
const dir = path.join(opts.agentDir, 'sessions', sessionDirSlug(opts.workingDir));
|
|
163
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
164
|
+
const file = path.join(dir, rendered.fileName);
|
|
165
|
+
const tmp = `${file}.${process.pid}.${randomHex(8)}.tmp`;
|
|
166
|
+
fs.writeFileSync(tmp, rendered.body, 'utf8');
|
|
167
|
+
renameWithRetry(tmp, file);
|
|
168
|
+
return {
|
|
169
|
+
file,
|
|
170
|
+
sessionId: rendered.sessionId,
|
|
171
|
+
nodes: rendered.nodes,
|
|
172
|
+
messages: rendered.messages,
|
|
173
|
+
skippedMedia: rendered.skippedMedia,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type HandoffTranscript } from './transcript.js';
|
|
2
|
+
/**
|
|
3
|
+
* opencode session writer (ADR-0039).
|
|
4
|
+
*
|
|
5
|
+
* opencode has NO writable session file: its sessions live in a daemon-held
|
|
6
|
+
* sqlite db (`<share>/opencode.db`, `session_v2` / `session_message` /
|
|
7
|
+
* `session_part`), so writing files — or touching the db from outside — would
|
|
8
|
+
* fight a live process and couple us to an internal schema. It DOES ship a
|
|
9
|
+
* first-class transfer verb, `opencode session import <file.json>`, which takes
|
|
10
|
+
* exactly the shape `opencode session export` produces. We therefore
|
|
11
|
+
* synthesize that shape and hand it to the CLI.
|
|
12
|
+
*
|
|
13
|
+
* TWO CONSTRAINTS, both measured against a live install (2026-12-02):
|
|
14
|
+
* - `session_message.id` is a GLOBAL primary key. Re-importing an export that
|
|
15
|
+
* keeps its ids fails with `UNIQUE constraint failed: session_message.id`,
|
|
16
|
+
* so every message id (and the session id) is regenerated.
|
|
17
|
+
* - an import whose `info.id` already exists prints "Session already exists"
|
|
18
|
+
* and is a no-op, which is why a fresh session id is minted every time.
|
|
19
|
+
*
|
|
20
|
+
* Message content is a FLAT projection of the neutral transcript: user turns
|
|
21
|
+
* carry `text`, assistant turns carry `content[]` with `text` / `reasoning` /
|
|
22
|
+
* `tool` parts. opencode's tool part carries its own `state` (input + content),
|
|
23
|
+
* which is how a historical tool result is represented without a re-execution.
|
|
24
|
+
*/
|
|
25
|
+
export interface WriteOpencodeOptions {
|
|
26
|
+
/** Share dir that holds `opencode.db` (the caller resolves it, or passes the default). */
|
|
27
|
+
shareDir: string;
|
|
28
|
+
workingDir: string;
|
|
29
|
+
transcript: HandoffTranscript;
|
|
30
|
+
now?: number;
|
|
31
|
+
/** Injectable runner so tests can assert the argv without a live daemon. */
|
|
32
|
+
run?: (args: string[]) => {
|
|
33
|
+
code: number;
|
|
34
|
+
stdout: string;
|
|
35
|
+
stderr: string;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export interface WriteOpencodeResult {
|
|
39
|
+
sessionId: string;
|
|
40
|
+
file: string;
|
|
41
|
+
messages: number;
|
|
42
|
+
skippedMedia: string[];
|
|
43
|
+
}
|
|
44
|
+
/** Default opencode share dir, matching its own XDG-on-Windows layout. */
|
|
45
|
+
export declare function defaultOpencodeShareDir(): string;
|
|
46
|
+
/**
|
|
47
|
+
* Write the session by generating the export shape and importing it. Throws with
|
|
48
|
+
* the CLI's own message when the import is refused, so the console can show the
|
|
49
|
+
* real cause instead of a generic failure.
|
|
50
|
+
*/
|
|
51
|
+
export declare function writeOpencodeSession(opts: WriteOpencodeOptions): WriteOpencodeResult;
|