@code-yeongyu/senpi 2026.9.3 → 2026.9.4
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/CHANGELOG.md +75 -0
- package/dist/core/agent-session.d.ts +2 -5
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +32 -29
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/dynamic-prompt/style.js +1 -1
- package/dist/core/dynamic-prompt/style.js.map +1 -1
- package/dist/core/dynamic-prompt/working-task.js +1 -1
- package/dist/core/dynamic-prompt/working-task.js.map +1 -1
- package/dist/core/extensions/builtin/bash-timeout/index.d.ts +1 -1
- package/dist/core/extensions/builtin/bash-timeout/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/bash-timeout/index.js +7 -1
- package/dist/core/extensions/builtin/bash-timeout/index.js.map +1 -1
- package/dist/core/extensions/builtin/bash-timeout/timeout.d.ts +11 -7
- package/dist/core/extensions/builtin/bash-timeout/timeout.d.ts.map +1 -1
- package/dist/core/extensions/builtin/bash-timeout/timeout.js +4 -8
- package/dist/core/extensions/builtin/bash-timeout/timeout.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/auth-lane.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/auth-lane.js +15 -18
- package/dist/core/extensions/builtin/claude-sdk-oauth/auth-lane.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/content-blocks.d.ts +3 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/content-blocks.d.ts.map +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/content-blocks.js +80 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/content-blocks.js.map +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/errors.d.ts +18 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/errors.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/errors.js +57 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/errors.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/guidance.d.ts +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/guidance.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/guidance.js +13 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/guidance.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/oauth-login.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/oauth-login.js +6 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/oauth-login.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/prompt-bridge.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/prompt-bridge.js +2 -23
- package/dist/core/extensions/builtin/claude-sdk-oauth/prompt-bridge.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-binding.d.ts +2 -2
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-binding.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-binding.js +30 -24
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-binding.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-continuity.d.ts +2 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-continuity.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-continuity.js +15 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-continuity.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-observability.d.ts +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-observability.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-observability.js +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-observability.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-reattach.d.ts +6 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-reattach.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-reattach.js +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-reattach.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry-pump.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry-pump.js +19 -3
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry-pump.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry-wiring.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry-wiring.js +31 -13
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry-wiring.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry.d.ts +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry.js +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-sync.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-sync.js +8 -14
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-sync.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-turn-attempt.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-turn-attempt.js +23 -6
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-turn-attempt.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/stream-guidance.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/stream-guidance.js +4 -2
- package/dist/core/extensions/builtin/claude-sdk-oauth/stream-guidance.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/stream-protocol.d.ts +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/stream-protocol.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/stream.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/stream.js +13 -6
- package/dist/core/extensions/builtin/claude-sdk-oauth/stream.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/tools.d.ts +11 -3
- package/dist/core/extensions/builtin/claude-sdk-oauth/tools.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/tools.js +12 -3
- package/dist/core/extensions/builtin/claude-sdk-oauth/tools.js.map +1 -1
- package/dist/core/extensions/builtin/eval-only-routing.d.ts +10 -0
- package/dist/core/extensions/builtin/eval-only-routing.d.ts.map +1 -0
- package/dist/core/extensions/builtin/eval-only-routing.js +16 -0
- package/dist/core/extensions/builtin/eval-only-routing.js.map +1 -0
- package/dist/core/extensions/builtin/gpt-account.d.ts +3 -0
- package/dist/core/extensions/builtin/gpt-account.d.ts.map +1 -0
- package/dist/core/extensions/builtin/gpt-account.js +115 -0
- package/dist/core/extensions/builtin/gpt-account.js.map +1 -0
- package/dist/core/extensions/builtin/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/index.js +2 -0
- package/dist/core/extensions/builtin/index.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-5.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-5.js +1 -3
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-5.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-6.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-6.js +1 -11
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-6.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-7.js +2 -2
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-7.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-8.js +3 -3
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-8.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-5.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-5.js +56 -43
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-5.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/execution-tooling.d.ts +4 -15
- package/dist/core/extensions/builtin/prompt-preset/execution-tooling.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/execution-tooling.js +12 -21
- package/dist/core/extensions/builtin/prompt-preset/execution-tooling.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/glm-5-2.d.ts +1 -1
- package/dist/core/extensions/builtin/prompt-preset/glm-5-2.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/glm-5-2.js +2 -11
- package/dist/core/extensions/builtin/prompt-preset/glm-5-2.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/glm-5-3.d.ts +1 -1
- package/dist/core/extensions/builtin/prompt-preset/glm-5-3.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/glm-5-3.js +2 -11
- package/dist/core/extensions/builtin/prompt-preset/glm-5-3.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/glm-5.d.ts +4 -0
- package/dist/core/extensions/builtin/prompt-preset/glm-5.d.ts.map +1 -0
- package/dist/core/extensions/builtin/prompt-preset/glm-5.js +16 -0
- package/dist/core/extensions/builtin/prompt-preset/glm-5.js.map +1 -0
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.d.ts +1 -5
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.js +1 -6
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/gpt-6-astra.d.ts +123 -0
- package/dist/core/extensions/builtin/prompt-preset/gpt-6-astra.d.ts.map +1 -0
- package/dist/core/extensions/builtin/prompt-preset/gpt-6-astra.js +202 -0
- package/dist/core/extensions/builtin/prompt-preset/gpt-6-astra.js.map +1 -0
- package/dist/core/extensions/builtin/prompt-preset/gpt-eval-routing.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/gpt-eval-routing.js +1 -2
- package/dist/core/extensions/builtin/prompt-preset/gpt-eval-routing.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k3.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k3.js +60 -76
- package/dist/core/extensions/builtin/prompt-preset/kimi-k3.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/presets.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/presets.js +17 -0
- package/dist/core/extensions/builtin/prompt-preset/presets.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/settings.d.ts +1 -1
- package/dist/core/extensions/builtin/prompt-preset/settings.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/settings.js +1 -0
- package/dist/core/extensions/builtin/prompt-preset/settings.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/extension.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/extension.js +5 -2
- package/dist/core/extensions/builtin/terminal/extension.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/prompt.d.ts +13 -2
- package/dist/core/extensions/builtin/terminal/prompt.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/prompt.js +18 -7
- package/dist/core/extensions/builtin/terminal/prompt.js.map +1 -1
- package/dist/core/extensions/builtin/tool-search/native-search.d.ts +1 -1
- package/dist/core/extensions/builtin/tool-search/native-search.d.ts.map +1 -1
- package/dist/core/extensions/builtin/tool-search/native-search.js +1 -1
- package/dist/core/extensions/builtin/tool-search/native-search.js.map +1 -1
- package/dist/core/extensions/builtin/ttsr/detectors/collapse-paragraphs.d.ts +34 -0
- package/dist/core/extensions/builtin/ttsr/detectors/collapse-paragraphs.d.ts.map +1 -0
- package/dist/core/extensions/builtin/ttsr/detectors/collapse-paragraphs.js +121 -0
- package/dist/core/extensions/builtin/ttsr/detectors/collapse-paragraphs.js.map +1 -0
- package/dist/core/extensions/builtin/ttsr/detectors/collapse.d.ts +2 -0
- package/dist/core/extensions/builtin/ttsr/detectors/collapse.d.ts.map +1 -1
- package/dist/core/extensions/builtin/ttsr/detectors/collapse.js +6 -2
- package/dist/core/extensions/builtin/ttsr/detectors/collapse.js.map +1 -1
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +18 -1
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager.d.ts +0 -4
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +0 -6
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +9 -0
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/modes/rpc/connection-handler.d.ts +2 -0
- package/dist/modes/rpc/connection-handler.d.ts.map +1 -1
- package/dist/modes/rpc/connection-handler.js +71 -12
- package/dist/modes/rpc/connection-handler.js.map +1 -1
- package/dist/modes/rpc/custom-capability.d.ts +5 -0
- package/dist/modes/rpc/custom-capability.d.ts.map +1 -1
- package/dist/modes/rpc/custom-capability.js +5 -0
- package/dist/modes/rpc/custom-capability.js.map +1 -1
- package/dist/modes/rpc/login-prompts.d.ts +24 -0
- package/dist/modes/rpc/login-prompts.d.ts.map +1 -0
- package/dist/modes/rpc/login-prompts.js +44 -0
- package/dist/modes/rpc/login-prompts.js.map +1 -0
- package/dist/modes/rpc/media-placeholders.d.ts +49 -0
- package/dist/modes/rpc/media-placeholders.d.ts.map +1 -0
- package/dist/modes/rpc/media-placeholders.js +151 -0
- package/dist/modes/rpc/media-placeholders.js.map +1 -0
- package/dist/modes/rpc/multi-session-host.js +3 -0
- package/dist/modes/rpc/multi-session-host.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +8 -0
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +11 -0
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +23 -1
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js +1 -0
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/modes/rpc/session-command-router.d.ts.map +1 -1
- package/dist/modes/rpc/session-command-router.js +2 -1
- package/dist/modes/rpc/session-command-router.js.map +1 -1
- package/dist/modes/rpc/session-event-fanout.d.ts +13 -2
- package/dist/modes/rpc/session-event-fanout.d.ts.map +1 -1
- package/dist/modes/rpc/session-event-fanout.js +36 -12
- package/dist/modes/rpc/session-event-fanout.js.map +1 -1
- package/dist/modes/rpc/session-event-writer.d.ts +3 -1
- package/dist/modes/rpc/session-event-writer.d.ts.map +1 -1
- package/dist/modes/rpc/session-event-writer.js +23 -13
- package/dist/modes/rpc/session-event-writer.js.map +1 -1
- package/dist/modes/rpc/socket-event-fanout.d.ts +8 -1
- package/dist/modes/rpc/socket-event-fanout.d.ts.map +1 -1
- package/dist/modes/rpc/socket-event-fanout.js +32 -9
- package/dist/modes/rpc/socket-event-fanout.js.map +1 -1
- package/docs/rpc.md +104 -0
- package/docs/settings.md +5 -27
- package/docs/windows.md +1 -1
- package/node_modules/@anthropic-ai/claude-agent-sdk/bridge.d.ts +18 -1
- package/node_modules/@anthropic-ai/claude-agent-sdk/bridge.mjs +155 -106
- package/node_modules/@anthropic-ai/claude-agent-sdk/browser-sdk.js +144 -83
- package/node_modules/@anthropic-ai/claude-agent-sdk/manifest.json +21 -32
- package/node_modules/@anthropic-ai/claude-agent-sdk/manifest.zst.json +25 -36
- package/node_modules/@anthropic-ai/claude-agent-sdk/package.json +2 -2
- package/node_modules/@anthropic-ai/claude-agent-sdk/sdk-tools.d.ts +93 -31
- package/node_modules/@anthropic-ai/claude-agent-sdk/sdk.d.ts +473 -31
- package/node_modules/@anthropic-ai/claude-agent-sdk/sdk.mjs +140 -93
- package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +38 -0
- package/node_modules/@code-yeongyu/senpi-codemode/package.json +4 -4
- package/node_modules/@code-yeongyu/senpi-codemode/src/index.ts +17 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-runtime.js +6 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-shell-capture.d.ts +10 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-shell-capture.js +126 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/prompt/eval-prompt.ts +14 -6
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/eval-tool-options.ts +2 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/eval-tool.ts +1 -0
- package/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
- package/node_modules/@earendil-works/pi-ai/dist/api/context-room.d.ts +20 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/context-room.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/context-room.js +40 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/context-room.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/simple-options.d.ts +1 -3
- package/node_modules/@earendil-works/pi-ai/dist/api/simple-options.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/simple-options.js +2 -16
- package/node_modules/@earendil-works/pi-ai/dist/api/simple-options.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.d.ts +16 -3
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.js +40 -6
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/compat/extension-oauth-types.d.ts +8 -0
- package/node_modules/@earendil-works/pi-ai/dist/compat/extension-oauth-types.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/compat/extension-oauth-types.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/models.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/models.js +3 -2
- package/node_modules/@earendil-works/pi-ai/dist/models.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/azure-openai-responses.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/huggingface.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/nvidia.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/openai-codex.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/openai.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js +2 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/package.json +2 -2
- package/node_modules/@earendil-works/pi-pty/package.json +1 -1
- package/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
- package/node_modules/@earendil-works/pi-tui/package.json +1 -1
- package/package.json +16 -16
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc-types.js","sourceRoot":"","sources":["../../../src/modes/rpc/rpc-types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAwJH,iDAAiD;AACjD,MAAM,CAAC,MAAM,yBAAyB,GAAG,iBAAiB,CAAC;AAC3D,MAAM,CAAC,MAAM,yBAAyB,GAAG,iBAAiB,CAAC;AAC3D,MAAM,CAAC,MAAM,6BAA6B,GAAG,qBAAqB,CAAC;AACnE,MAAM,CAAC,MAAM,4BAA4B,GAAG,oBAAoB,CAAC;AACjE,MAAM,CAAC,MAAM,gCAAgC,GAAG,wBAAwB,CAAC;AACzE,MAAM,CAAC,MAAM,sBAAsB,GAAG,cAAc,CAAC;AACrD,MAAM,CAAC,MAAM,qBAAqB,GAAG,aAAa,CAAC;AACnD,MAAM,CAAC,MAAM,2BAA2B,GAAG,mBAAmB,CAAC","sourcesContent":["/**\n * RPC protocol types for headless operation.\n *\n * Commands are sent as JSON lines on stdin.\n * Responses and events are emitted as JSON lines on stdout.\n */\n\nimport type { AgentMessage, ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport type { ImageContent, Model, ThinkingSelection } from \"@earendil-works/pi-ai\";\nimport type { AgentAbortSource } from \"../../core/agent-abort-provenance.ts\";\nimport type { PromptDisposition, SessionStats } from \"../../core/agent-session.ts\";\nimport type { BashResult } from \"../../core/bash-executor.ts\";\nimport type { CompactionResult } from \"../../core/compaction/index.ts\";\nimport type { ServiceTier } from \"../../core/extensions/builtin/service-tier.ts\";\nimport type { ContextUsage } from \"../../core/extensions/types.ts\";\nimport type { SessionEntry, SessionTreeNode, UsageTotals } from \"../../core/session-manager.ts\";\nimport type { SourceInfo } from \"../../core/source-info.ts\";\nimport type { RpcSlashCommand } from \"./rpc-command-surface.ts\";\n\nexport type { RpcCommandInvocationEvent } from \"./rpc-command-invocation.ts\";\nexport type { RpcCommandsChangedEvent, RpcSlashCommand } from \"./rpc-command-surface.ts\";\n\n// ============================================================================\n// RPC Commands (stdin)\n// ============================================================================\n\ntype RpcSessionCommand =\n\t// Prompting\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"prompt\";\n\t\t\tmessage: string;\n\t\t\timages?: ImageContent[];\n\t\t\tstreamingBehavior?: \"steer\" | \"followUp\";\n\t\t\tthinkingLevel?: ThinkingLevel;\n\t\t\tsessionTitlePrompt?: string | false;\n\t\t\texpandPromptTemplates?: boolean;\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"send_custom_message\";\n\t\t\tcustomType: string;\n\t\t\tcontent: unknown;\n\t\t\tdisplay: boolean;\n\t\t\tdetails?: unknown;\n\t\t\ttriggerTurn?: boolean;\n\t\t\tdeliverAs?: \"steer\" | \"followUp\" | \"nextTurn\";\n\t }\n\t| { id?: string; type: \"append_user_message\"; content: unknown }\n\t| { id?: string; type: \"append_session_entry\"; entry: SessionEntry }\n\t| { id?: string; type: \"steer\"; message: string; images?: ImageContent[]; enqueueOrder?: number }\n\t| { id?: string; type: \"follow_up\"; message: string; images?: ImageContent[]; enqueueOrder?: number }\n\t| { id?: string; type: \"abort\" }\n\t| { id?: string; type: \"abort_compaction\" }\n\t| { id?: string; type: \"reload\" }\n\t| { id?: string; type: \"check_reload_veto\" }\n\t| { id?: string; type: \"clear_queue\"; abortWillFollow?: boolean }\n\t| { id?: string; type: \"get_steering_messages\" }\n\t| { id?: string; type: \"get_follow_up_messages\" }\n\t| { id?: string; type: \"abort_branch_summary\" }\n\t| { id?: string; type: \"new_session\"; parentSession?: string }\n\n\t// State\n\t| { id?: string; type: \"get_state\" }\n\n\t// Model\n\t| { id?: string; type: \"set_model\"; provider: string; modelId: string }\n\t| { id?: string; type: \"set_favorite_models\"; models: RpcSessionModelEntry[] }\n\t| { id?: string; type: \"set_scoped_models\"; models: RpcSessionModelEntry[] }\n\t| { id?: string; type: \"cycle_model\"; direction?: \"forward\" | \"backward\" }\n\t| { id?: string; type: \"get_available_models\" }\n\n\t// Thinking\n\t| { id?: string; type: \"set_thinking_level\"; level: ThinkingLevel; scope?: \"turn\" }\n\t| { id?: string; type: \"cycle_thinking_level\" }\n\t| { id?: string; type: \"get_available_thinking_levels\" }\n\n\t// Fast mode (OpenAI Codex priority service tier)\n\t| { id?: string; type: \"set_fast_mode\"; enabled: boolean }\n\t| { id?: string; type: \"get_fast_mode\" }\n\n\t// Queue modes\n\t| { id?: string; type: \"set_steering_mode\"; mode: \"all\" | \"one-at-a-time\" }\n\t| { id?: string; type: \"set_follow_up_mode\"; mode: \"all\" | \"one-at-a-time\" }\n\n\t// Compaction\n\t| { id?: string; type: \"compact\"; customInstructions?: string }\n\t| { id?: string; type: \"set_auto_compaction\"; enabled: boolean }\n\n\t// Retry\n\t| { id?: string; type: \"set_auto_retry\"; enabled: boolean }\n\t| { id?: string; type: \"abort_retry\" }\n\n\t// Bash\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"bash\";\n\t\t\tcommand: string;\n\t\t\t/** Identifies output chunks to the requesting client. */\n\t\t\tbashId?: string;\n\t\t\texcludeFromContext?: boolean;\n\t\t\texecutionId?: string;\n\t\t\toperations?: Record<string, unknown>;\n\t }\n\t| { id?: string; type: \"record_bash_result\"; command: string; result: BashResult; excludeFromContext?: boolean }\n\t| { id?: string; type: \"abort_bash\" }\n\t| { id?: string; type: \"cleanup_bash_output\"; path: string }\n\t| { id?: string; type: \"set_label\"; entryId: string; label?: string }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"navigate_tree\";\n\t\t\ttargetId: string;\n\t\t\tsummarize?: boolean;\n\t\t\tcustomInstructions?: string;\n\t\t\treplaceInstructions?: boolean;\n\t\t\tlabel?: string;\n\t }\n\n\t// Session\n\t| { id?: string; type: \"get_session_stats\" }\n\t| { id?: string; type: \"export_html\"; outputPath?: string; themeName?: string }\n\t| { id?: string; type: \"export_jsonl\"; outputPath?: string }\n\t| { id?: string; type: \"switch_session\"; sessionPath: string; cwdOverride?: string }\n\t| { id?: string; type: \"fork\"; entryId: string; position?: \"before\" | \"at\" }\n\t| { id?: string; type: \"clone\" }\n\t| { id?: string; type: \"get_fork_messages\" }\n\t| { id?: string; type: \"get_entries\"; since?: string }\n\t| { id?: string; type: \"get_tree\" }\n\t| { id?: string; type: \"get_last_assistant_text\" }\n\t| { id?: string; type: \"set_session_name\"; name: string }\n\t| { id?: string; type: \"import_jsonl\"; inputPath: string; cwdOverride?: string }\n\n\t// Messages\n\t| { id?: string; type: \"get_messages\" }\n\n\t// Commands and loaded runtime surfaces\n\t| { id?: string; type: \"get_commands\" }\n\t| { id?: string; type: \"get_loaded_surfaces\" }\n\t| { id?: string; type: \"extension_request\"; name: string; data?: unknown }\n\n\t// Auth (task 13) is additive. get_auth_providers, login_api_key and logout\n\t// answer synchronously. login_start responds immediately (flow-started) and\n\t// completion is delivered via auth_login_url / auth_login_end EVENTS, because\n\t// an interactive OAuth round-trip cannot fit the 30s request timeout.\n\t| { id?: string; type: \"get_auth_providers\" }\n\t| { id?: string; type: \"login_start\"; provider: string }\n\t| { id?: string; type: \"login_cancel\"; provider: string }\n\t| { id?: string; type: \"login_api_key\"; provider: string; key: string }\n\t| { id?: string; type: \"logout\"; provider: string }\n\n\t// Provider accounts (task 13) are additive. The desktop consumer contract\n\t// lives in ../omo-desktop-app/packages/contracts/src/rpc.ts and is updated separately.\n\t| { id?: string; type: \"get_provider_accounts\"; provider: string }\n\t| { id?: string; type: \"account_pin\"; provider: string; name: string | null }\n\t| { id?: string; type: \"account_remove\"; provider: string; name: string }\n\t| { id?: string; type: \"set_client_info\"; width: number; capabilities?: string[] };\n\n/** Stable multi-session protocol error codes. */\nexport const RPC_ERROR_UNKNOWN_SESSION = \"unknown_session\";\nexport const RPC_ERROR_SESSION_CLOSING = \"session_closing\";\nexport const RPC_ERROR_SESSION_PATH_IN_USE = \"session_path_in_use\";\nexport const RPC_ERROR_MISSING_SESSION_ID = \"missing_session_id\";\nexport const RPC_ERROR_MULTI_SESSION_DISABLED = \"multi_session_disabled\";\nexport const RPC_ERROR_INVALID_PATH = \"invalid_path\";\nexport const RPC_ERROR_OPEN_FAILED = \"open_failed\";\nexport const RPC_ERROR_TOO_MANY_SESSIONS = \"too_many_sessions\";\n\nexport type RpcErrorCode =\n\t| typeof RPC_ERROR_UNKNOWN_SESSION\n\t| typeof RPC_ERROR_SESSION_CLOSING\n\t| typeof RPC_ERROR_SESSION_PATH_IN_USE\n\t| typeof RPC_ERROR_MISSING_SESSION_ID\n\t| typeof RPC_ERROR_MULTI_SESSION_DISABLED\n\t| typeof RPC_ERROR_INVALID_PATH\n\t| typeof RPC_ERROR_OPEN_FAILED\n\t| typeof RPC_ERROR_TOO_MANY_SESSIONS;\n\n/** Every established command accepts an additive routing envelope. */\nexport type RpcCommand =\n\t| (RpcSessionCommand & { sessionId?: string })\n\t| { id?: string; type: \"get_protocol_info\" }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"open_session\";\n\t\t\tsessionPath?: string;\n\t\t\tcwd?: string;\n\t\t\tprovider?: string;\n\t\t\tmodelId?: string;\n\t\t\tthinkingLevel?: ThinkingLevel;\n\t\t\tpermissionPreset?: string;\n\t }\n\t| { id?: string; type: \"close_session\"; sessionId: string }\n\t| { id?: string; type: \"list_sessions\" };\n\n// ============================================================================\n// Auth provider info (get_auth_providers response)\n// ============================================================================\n\n/** One provider row for the /login and /logout selectors. */\nexport interface RpcAuthProvider {\n\t/** Provider id (e.g. \"anthropic\", \"openai\"). */\n\tid: string;\n\t/** Human-readable display name. */\n\tname: string;\n\t/** How this provider authenticates. */\n\tauthType: \"oauth\" | \"api_key\";\n\t/** Auth status without exposing or refreshing any credential. */\n\tstatus: RpcAuthStatus;\n}\n\n/** Auth status mirror (no credential values), from getProviderAuthStatus. */\nexport interface RpcAuthStatus {\n\tconfigured: boolean;\n\tsource?:\n\t\t| \"stored\"\n\t\t| \"runtime\"\n\t\t| \"environment\"\n\t\t| \"fallback\"\n\t\t| \"models_json_key\"\n\t\t| \"models_json_command\"\n\t\t| \"models_json_headers\"\n\t\t| \"extension_headers\";\n\tlabel?: string;\n}\n\n/** Account-slot metadata safe to send to desktop clients. */\nexport interface RpcProviderAccount {\n\tname: string;\n\tsource: \"login\" | \"import\" | \"env\";\n\tblocked: boolean;\n\tpinned: boolean;\n}\n\n// ============================================================================\n// RPC Slash Command (for get_commands response)\n// ============================================================================\n\n/** One extension module loaded by the session resource loader. */\nexport interface RpcLoadedExtension {\n\tname: string;\n\tpath: string;\n\tsourceInfo: SourceInfo;\n\tenabled: boolean;\n}\n\nexport type RpcMcpServerStatus =\n\t| \"enabled\"\n\t| \"disabled\"\n\t| \"untrusted\"\n\t| \"idle\"\n\t| \"connecting\"\n\t| \"connected\"\n\t| \"degraded\"\n\t| \"suspended\"\n\t| \"needs_auth\"\n\t| \"needs_client_registration\";\n\n/** Runtime MCP server state projected from the session-owned MCP service. */\nexport interface RpcLoadedMcpServer {\n\tname: string;\n\ttoolCount: number;\n\tstatus: RpcMcpServerStatus;\n\tauthStatus: \"unsupported\" | \"notLoggedIn\" | \"bearerToken\" | \"oAuth\";\n}\n\n// ============================================================================\n// RPC State\n// ============================================================================\n\nexport interface RpcSessionModelEntry {\n\tmodel: Model<any>;\n\tthinkingLevel?: ThinkingLevel;\n\tthinkingSelection?: ThinkingSelection;\n\tserviceTier?: ServiceTier;\n}\n\nexport interface RpcSessionState {\n\tmodel?: Model<any>;\n\tthinkingLevel: ThinkingLevel;\n\t/**\n\t * Explicit selector provenance for `thinkingLevel`, absent for SDK-defaulted\n\t * effective levels. An attached client cannot distinguish \"the user chose high\"\n\t * from \"high is simply the effective level\" without it.\n\t */\n\tthinkingSelection?: ThinkingSelection;\n\t/**\n\t * Abort owner of the most recent aborted turn, or the in-flight one while it is\n\t * still settling. Retained after settle: the live session getter is transient, so a\n\t * client that snapshots state after the turn ends would otherwise see nothing and\n\t * fall back to generic wording instead of \"Operation aborted\".\n\t */\n\tlastAbortSource?: AgentAbortSource;\n\t/** Service tier the session resolved for the active model, if any. */\n\tserviceTier?: ServiceTier;\n\t/** True when the active model is served at the priority (\"fast\") tier. */\n\tfastMode: boolean;\n\tisStreaming: boolean;\n\tisCompacting: boolean;\n\tsteeringMode: \"all\" | \"one-at-a-time\";\n\tfollowUpMode: \"all\" | \"one-at-a-time\";\n\tsessionFile?: string;\n\tsessionId: string;\n\tsessionName?: string;\n\tcwd: string;\n\t/** Whether project-scoped settings and resources are trusted by the host. */\n\tprojectTrusted: boolean;\n\t/** Authoritative entries for setup-only sessions whose deferred file does not exist yet. */\n\tentries?: SessionEntry[];\n\tfavoriteModels: RpcSessionModelEntry[];\n\tscopedModels: RpcSessionModelEntry[];\n\tsteering: string[];\n\tfollowUp: string[];\n\tordered: Array<{ text: string; mode: \"steer\" | \"followUp\"; enqueueOrder: number }>;\n\tautoCompactionEnabled: boolean;\n\tmessageCount: number;\n\tpendingMessageCount: number;\n\tusageTotals: UsageTotals;\n\tcontextUsage?: ContextUsage;\n\tretryAttempt: number;\n\tisBashRunning: boolean;\n}\n\n// ============================================================================\n// RPC Responses (stdout)\n// ============================================================================\n\n// Success responses with data\nexport type RpcResponse =\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_protocol_info\";\n\t\t\tsuccess: true;\n\t\t\tdata: {\n\t\t\t\tprotocolVersion: 1;\n\t\t\t\tserverVersion: string;\n\t\t\t\tcapabilities: string[];\n\t\t\t\tmode: \"classic\" | \"multi\";\n\t\t\t};\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"open_session\";\n\t\t\tsuccess: true;\n\t\t\tdata: { sessionId: string; state: RpcSessionState; attached?: boolean };\n\t }\n\t| { id?: string; type: \"response\"; command: \"close_session\"; success: true; data: Record<string, never> }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"list_sessions\";\n\t\t\tsuccess: true;\n\t\t\tdata: {\n\t\t\t\tsessions: Array<{\n\t\t\t\t\tsessionId: string;\n\t\t\t\t\tdurableSessionId?: string;\n\t\t\t\t\tsessionPath?: string;\n\t\t\t\t\tcwd: string;\n\t\t\t\t\tname?: string;\n\t\t\t\t\tstatus: \"opening\" | \"open\" | \"closing\" | \"closed\";\n\t\t\t\t}>;\n\t\t\t};\n\t }\n\t// Prompting (async - events follow)\n\t// data.disposition reports how the host disposed the prompt (started/queued/handled)\n\t// so proxied optimistic-echo contracts resolve exactly like the local path; older\n\t// hosts omit it and clients must degrade to canonical-only rendering.\n\t| { id?: string; type: \"response\"; command: \"prompt\"; success: true; data?: { disposition?: PromptDisposition } }\n\t| { id?: string; type: \"response\"; command: \"send_custom_message\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"append_user_message\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"append_session_entry\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"steer\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"follow_up\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"abort\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"abort_compaction\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"reload\"; success: true; data: { cancelled: boolean; reason?: string } }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"check_reload_veto\";\n\t\t\tsuccess: true;\n\t\t\tdata: { cancelled: boolean; reason?: string };\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"clear_queue\";\n\t\t\tsuccess: true;\n\t\t\tdata: {\n\t\t\t\tsteering: string[];\n\t\t\t\tfollowUp: string[];\n\t\t\t\tordered: Array<{ text: string; mode: \"steer\" | \"followUp\"; enqueueOrder: number }>;\n\t\t\t};\n\t }\n\t| { id?: string; type: \"response\"; command: \"new_session\"; success: true; data: { cancelled: boolean } }\n\n\t// State\n\t| { id?: string; type: \"response\"; command: \"get_state\"; success: true; data: RpcSessionState }\n\n\t// Model\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"set_model\";\n\t\t\tsuccess: true;\n\t\t\tdata: Model<any> & { systemPromptName?: string };\n\t }\n\t| { id?: string; type: \"response\"; command: \"set_favorite_models\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"set_scoped_models\"; success: true }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"cycle_model\";\n\t\t\tsuccess: true;\n\t\t\tdata: { model: Model<any>; thinkingLevel: ThinkingLevel; isScoped: boolean } | null;\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_available_models\";\n\t\t\tsuccess: true;\n\t\t\tdata: { models: Array<Model<any> & { supportedThinkingLevels: ThinkingLevel[] }> };\n\t }\n\n\t// Thinking\n\t| { id?: string; type: \"response\"; command: \"set_thinking_level\"; success: true }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"cycle_thinking_level\";\n\t\t\tsuccess: true;\n\t\t\tdata: { level: ThinkingLevel } | null;\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_available_thinking_levels\";\n\t\t\tsuccess: true;\n\t\t\tdata: { levels: ThinkingLevel[] };\n\t }\n\n\t// Fast mode\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"set_fast_mode\";\n\t\t\tsuccess: true;\n\t\t\tdata: { enabled: boolean; serviceTier: ServiceTier; provider: string; modelId: string };\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_fast_mode\";\n\t\t\tsuccess: true;\n\t\t\tdata: { enabled: boolean; serviceTier: ServiceTier | null };\n\t }\n\n\t// Queue modes\n\t| { id?: string; type: \"response\"; command: \"set_steering_mode\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"set_follow_up_mode\"; success: true }\n\n\t// Compaction\n\t| { id?: string; type: \"response\"; command: \"compact\"; success: true; data: CompactionResult }\n\t| { id?: string; type: \"response\"; command: \"set_auto_compaction\"; success: true }\n\n\t// Retry\n\t| { id?: string; type: \"response\"; command: \"set_auto_retry\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"abort_retry\"; success: true }\n\n\t// Bash\n\t| { id?: string; type: \"response\"; command: \"bash\"; success: true; data: BashResult }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"navigate_tree\";\n\t\t\tsuccess: true;\n\t\t\tdata: { cancelled: boolean; editorText?: string; aborted?: boolean; summaryEntry?: unknown };\n\t }\n\t| { id?: string; type: \"response\"; command: \"abort_bash\"; success: true }\n\n\t// Session\n\t| { id?: string; type: \"response\"; command: \"get_session_stats\"; success: true; data: SessionStats }\n\t| { id?: string; type: \"response\"; command: \"export_html\"; success: true; data: { path: string } }\n\t| { id?: string; type: \"response\"; command: \"export_jsonl\"; success: true; data: { path: string } }\n\t| { id?: string; type: \"response\"; command: \"switch_session\"; success: true; data: { cancelled: boolean } }\n\t| { id?: string; type: \"response\"; command: \"fork\"; success: true; data: { text: string; cancelled: boolean } }\n\t| { id?: string; type: \"response\"; command: \"clone\"; success: true; data: { cancelled: boolean } }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_fork_messages\";\n\t\t\tsuccess: true;\n\t\t\tdata: { messages: Array<{ entryId: string; text: string }> };\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_entries\";\n\t\t\tsuccess: true;\n\t\t\tdata: { entries: SessionEntry[]; leafId: string | null };\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_tree\";\n\t\t\tsuccess: true;\n\t\t\tdata: { tree: SessionTreeNode[]; leafId: string | null };\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_last_assistant_text\";\n\t\t\tsuccess: true;\n\t\t\tdata: { text: string | null };\n\t }\n\t| { id?: string; type: \"response\"; command: \"set_session_name\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"import_jsonl\"; success: true; data: { cancelled: boolean } }\n\n\t// Messages\n\t| { id?: string; type: \"response\"; command: \"get_messages\"; success: true; data: { messages: AgentMessage[] } }\n\n\t// Commands and loaded runtime surfaces\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_commands\";\n\t\t\tsuccess: true;\n\t\t\tdata: { commands: RpcSlashCommand[] };\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_loaded_surfaces\";\n\t\t\tsuccess: true;\n\t\t\tdata: { extensions: RpcLoadedExtension[]; mcpServers: RpcLoadedMcpServer[] };\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"extension_request\";\n\t\t\tsuccess: true;\n\t\t\tdata: unknown;\n\t }\n\n\t// Auth (task 13)\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_auth_providers\";\n\t\t\tsuccess: true;\n\t\t\tdata: { providers: RpcAuthProvider[] };\n\t }\n\t// login_start returns immediately: success:true means the flow has started.\n\t// The URL and completion arrive as auth_login_url / auth_login_end events.\n\t| { id?: string; type: \"response\"; command: \"login_start\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"login_cancel\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"login_api_key\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"logout\"; success: true }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_provider_accounts\";\n\t\t\tsuccess: true;\n\t\t\tdata: { accounts: RpcProviderAccount[] };\n\t }\n\t| { id?: string; type: \"response\"; command: \"account_pin\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"account_remove\"; success: true }\n\n\t// Error response (any command can fail)\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: string;\n\t\t\tsuccess: false;\n\t\t\terror: string;\n\t\t\terrorCode?: string;\n\t\t\terrorData?: unknown;\n\t };\n\n// ============================================================================\n// Extension UI Events (stdout)\n// ============================================================================\n\n/** Emitted when an extension needs user input */\nexport type RpcExtensionUIRequest =\n\t| { type: \"extension_ui_request\"; id: string; method: \"select\"; title: string; options: string[]; timeout?: number }\n\t| { type: \"extension_ui_request\"; id: string; method: \"confirm\"; title: string; message: string; timeout?: number }\n\t| {\n\t\t\ttype: \"extension_ui_request\";\n\t\t\tid: string;\n\t\t\tmethod: \"input\";\n\t\t\ttitle: string;\n\t\t\tplaceholder?: string;\n\t\t\ttimeout?: number;\n\t }\n\t| { type: \"extension_ui_request\"; id: string; method: \"editor\"; title: string; prefill?: string }\n\t| {\n\t\t\ttype: \"extension_ui_request\";\n\t\t\tid: string;\n\t\t\tmethod: \"notify\";\n\t\t\tmessage: string;\n\t\t\tnotifyType?: \"info\" | \"warning\" | \"error\";\n\t }\n\t| {\n\t\t\ttype: \"extension_ui_request\";\n\t\t\tid: string;\n\t\t\tmethod: \"setStatus\";\n\t\t\tstatusKey: string;\n\t\t\tstatusText: string | undefined;\n\t }\n\t| {\n\t\t\ttype: \"extension_ui_request\";\n\t\t\tid: string;\n\t\t\tmethod: \"setWidget\";\n\t\t\twidgetKey: string;\n\t\t\twidgetLines: string[] | undefined;\n\t\t\twidgetPlacement?: \"aboveEditor\" | \"belowEditor\";\n\t }\n\t| {\n\t\t\ttype: \"extension_ui_request\";\n\t\t\tid: string;\n\t\t\tmethod: \"setHeader\" | \"setFooter\";\n\t\t\twidgetLines: string[] | undefined;\n\t }\n\t| { type: \"extension_ui_request\"; id: string; method: \"setTitle\"; title: string }\n\t| { type: \"extension_ui_request\"; id: string; method: \"set_editor_text\"; text: string }\n\t// Additive (task 13/14): emitted ONLY when the client advertised the\n\t// \"custom_unsupported\" capability. ctx.ui.custom cannot render a third-party\n\t// component in RPC mode, so a flagged client gets this notice before custom()\n\t// returns undefined. Default clients never see it (byte-identical behavior).\n\t| { type: \"extension_ui_request\"; id: string; method: \"custom_unsupported\"; extensionName: string };\n\nexport type RpcExtensionEvent = {\n\ttype: \"extension_event\";\n\tname: string;\n\tdata: unknown;\n};\n\n// ============================================================================\n// Extension UI Commands (stdin)\n// ============================================================================\n\n/** Response to an extension UI request */\nexport type RpcExtensionUIResponse =\n\t| { type: \"extension_ui_response\"; id: string; value: string }\n\t| { type: \"extension_ui_response\"; id: string; confirmed: boolean }\n\t| { type: \"extension_ui_response\"; id: string; cancelled: true };\n\n/** Emitted when the effective session thinking level changes. */\nexport interface RpcThinkingLevelChangedEvent {\n\ttype: \"thinking_level_changed\";\n\tlevel: ThinkingLevel;\n\t/**\n\t * Selector provenance in force after the change; absent when the level is an\n\t * SDK-defaulted effective level rather than an explicit choice. Additive: an old\n\t * client that does not know the field ignores it.\n\t */\n\tthinkingSelection?: ThinkingSelection;\n}\n\nexport interface RpcHighReasoningWarningEvent {\n\ttype: \"high_reasoning_warning\";\n\tmodelId: string;\n\tprovider: string;\n\tthinkingLevel: ThinkingLevel;\n}\n\n/** Emitted after explicit skill tokens are expanded for a user-authored request. */\nexport interface RpcSkillInvocationEvent {\n\ttype: \"skill_invocation\";\n\tskills: readonly {\n\t\tname: string;\n\t\tpath: string;\n\t\tsyntax: \"dollar\" | \"slash\";\n\t}[];\n}\n\n/** Emitted when startup or reload selects an existing settings file. */\nexport interface RpcSettingsSourceSelectedEvent {\n\ttype: \"settings_source_selected\";\n\tpath: string;\n\tformat: \"jsonc\" | \"json\";\n\treason: \"explicit-jsonc\" | \"json-only\";\n\tscope: \"global\" | \"project\";\n}\n\n/**\n * Emitted after the session's active model changed, with the thinking level in force AFTER\n * the switch (per-model memory, a favorite's pinned level, or the clamped previous level).\n *\n * Clients that tracked the model by inferring it from `entry_appended` can consume this\n * instead. Additive: an old client that does not know the type filters it out.\n */\nexport interface RpcModelChangedEvent {\n\ttype: \"model_changed\";\n\tmodel: Model<any>;\n\tthinkingLevel: ThinkingLevel;\n\t/** Why the model changed: \"set\", \"cycle\", \"restore\", \"fallback\", or \"fallback-revert\". */\n\tsource: string;\n\t/** Selector provenance for `thinkingLevel` after the switch, when one was explicit. */\n\tthinkingSelection?: ThinkingSelection;\n}\n\n/** Emitted when the effective service tier or fast-mode state of the session changes. */\nexport interface RpcServiceTierChangedEvent {\n\ttype: \"service_tier_changed\";\n\ttier?: ServiceTier;\n\tfastMode: boolean;\n}\n/**\n * Emitted after the host swapped the live session behind this connection (new session,\n * fork, or switch), carrying the new authoritative identity.\n *\n * A replacement can be initiated by ANY attached client. Without this event the other\n * attached clients keep their stale identity and keep routing replacement-dependent\n * actions at the session that no longer exists. Additive: an old client that does not\n * know the type filters it out.\n */\nexport interface RpcSessionReplacedEvent {\n\ttype: \"session_replaced\";\n\t/**\n\t * Durable session id of the session now bound to this connection.\n\t *\n\t * Deliberately NOT `sessionId`: top-level `sessionId` is reserved for the\n\t * per-connection routing handle that multi-session hosts tag every record\n\t * with, and that tag is applied last - it would overwrite this value and\n\t * leave the event carrying no identity at all.\n\t */\n\tdurableSessionId: string;\n\t/** Session file backing the new session, absent for a deferred setup-only session. */\n\tsessionFile?: string;\n\tcwd: string;\n\tsessionName?: string;\n}\n\n/** Emitted after the loaded skill, extension, or MCP inventory changes. */\nexport interface RpcLoadedSurfacesChangedEvent {\n\ttype: \"loaded_surfaces_changed\";\n}\n\n/** Emitted after an account is added, removed, pinned, or blocked by refresh failure. */\nexport interface RpcAuthAccountsChangedEvent {\n\ttype: \"auth_accounts_changed\";\n\tprovider: string;\n}\n\n/** Emitted when the SDK failover engine advances to a different account slot. */\nexport interface RpcAccountFailoverEvent {\n\ttype: \"account_failover\";\n\tprovider: string;\n\tfrom: string;\n\tto: string;\n\treason: string;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"rpc-types.js","sourceRoot":"","sources":["../../../src/modes/rpc/rpc-types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA8JH,iDAAiD;AACjD,MAAM,CAAC,MAAM,yBAAyB,GAAG,iBAAiB,CAAC;AAC3D,MAAM,CAAC,MAAM,yBAAyB,GAAG,iBAAiB,CAAC;AAC3D,MAAM,CAAC,MAAM,6BAA6B,GAAG,qBAAqB,CAAC;AACnE,MAAM,CAAC,MAAM,4BAA4B,GAAG,oBAAoB,CAAC;AACjE,MAAM,CAAC,MAAM,gCAAgC,GAAG,wBAAwB,CAAC;AACzE,MAAM,CAAC,MAAM,sBAAsB,GAAG,cAAc,CAAC;AACrD,MAAM,CAAC,MAAM,qBAAqB,GAAG,aAAa,CAAC;AACnD,MAAM,CAAC,MAAM,2BAA2B,GAAG,mBAAmB,CAAC;AAC/D,MAAM,CAAC,MAAM,yBAAyB,GAAG,iBAAiB,CAAC","sourcesContent":["/**\n * RPC protocol types for headless operation.\n *\n * Commands are sent as JSON lines on stdin.\n * Responses and events are emitted as JSON lines on stdout.\n */\n\nimport type { AgentMessage, ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport type { ImageContent, Model, ThinkingSelection } from \"@earendil-works/pi-ai\";\nimport type { AgentAbortSource } from \"../../core/agent-abort-provenance.ts\";\nimport type { PromptDisposition, SessionStats } from \"../../core/agent-session.ts\";\nimport type { BashResult } from \"../../core/bash-executor.ts\";\nimport type { CompactionResult } from \"../../core/compaction/index.ts\";\nimport type { ServiceTier } from \"../../core/extensions/builtin/service-tier.ts\";\nimport type { ContextUsage } from \"../../core/extensions/types.ts\";\nimport type { SessionEntry, SessionTreeNode, UsageTotals } from \"../../core/session-manager.ts\";\nimport type { SourceInfo } from \"../../core/source-info.ts\";\nimport type { RpcSlashCommand } from \"./rpc-command-surface.ts\";\n\nexport type { RpcCommandInvocationEvent } from \"./rpc-command-invocation.ts\";\nexport type { RpcCommandsChangedEvent, RpcSlashCommand } from \"./rpc-command-surface.ts\";\n\n// ============================================================================\n// RPC Commands (stdin)\n// ============================================================================\n\ntype RpcSessionCommand =\n\t// Prompting\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"prompt\";\n\t\t\tmessage: string;\n\t\t\timages?: ImageContent[];\n\t\t\tstreamingBehavior?: \"steer\" | \"followUp\";\n\t\t\tthinkingLevel?: ThinkingLevel;\n\t\t\tsessionTitlePrompt?: string | false;\n\t\t\texpandPromptTemplates?: boolean;\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"send_custom_message\";\n\t\t\tcustomType: string;\n\t\t\tcontent: unknown;\n\t\t\tdisplay: boolean;\n\t\t\tdetails?: unknown;\n\t\t\ttriggerTurn?: boolean;\n\t\t\tdeliverAs?: \"steer\" | \"followUp\" | \"nextTurn\";\n\t }\n\t| { id?: string; type: \"append_user_message\"; content: unknown }\n\t| { id?: string; type: \"append_session_entry\"; entry: SessionEntry }\n\t| { id?: string; type: \"steer\"; message: string; images?: ImageContent[]; enqueueOrder?: number }\n\t| { id?: string; type: \"follow_up\"; message: string; images?: ImageContent[]; enqueueOrder?: number }\n\t| { id?: string; type: \"abort\" }\n\t| { id?: string; type: \"abort_compaction\" }\n\t| { id?: string; type: \"reload\" }\n\t| { id?: string; type: \"check_reload_veto\" }\n\t| { id?: string; type: \"clear_queue\"; abortWillFollow?: boolean }\n\t| { id?: string; type: \"get_steering_messages\" }\n\t| { id?: string; type: \"get_follow_up_messages\" }\n\t| { id?: string; type: \"abort_branch_summary\" }\n\t| { id?: string; type: \"new_session\"; parentSession?: string }\n\n\t// State\n\t| { id?: string; type: \"get_state\" }\n\n\t// Model\n\t| { id?: string; type: \"set_model\"; provider: string; modelId: string }\n\t| { id?: string; type: \"set_favorite_models\"; models: RpcSessionModelEntry[] }\n\t| { id?: string; type: \"set_scoped_models\"; models: RpcSessionModelEntry[] }\n\t| { id?: string; type: \"cycle_model\"; direction?: \"forward\" | \"backward\" }\n\t| { id?: string; type: \"get_available_models\" }\n\n\t// Thinking\n\t| { id?: string; type: \"set_thinking_level\"; level: ThinkingLevel; scope?: \"turn\" }\n\t| { id?: string; type: \"cycle_thinking_level\" }\n\t| { id?: string; type: \"get_available_thinking_levels\" }\n\n\t// Fast mode (OpenAI Codex priority service tier)\n\t| { id?: string; type: \"set_fast_mode\"; enabled: boolean }\n\t| { id?: string; type: \"get_fast_mode\" }\n\n\t// Queue modes\n\t| { id?: string; type: \"set_steering_mode\"; mode: \"all\" | \"one-at-a-time\" }\n\t| { id?: string; type: \"set_follow_up_mode\"; mode: \"all\" | \"one-at-a-time\" }\n\n\t// Compaction\n\t| { id?: string; type: \"compact\"; customInstructions?: string }\n\t| { id?: string; type: \"set_auto_compaction\"; enabled: boolean }\n\n\t// Retry\n\t| { id?: string; type: \"set_auto_retry\"; enabled: boolean }\n\t| { id?: string; type: \"abort_retry\" }\n\n\t// Bash\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"bash\";\n\t\t\tcommand: string;\n\t\t\t/** Identifies output chunks to the requesting client. */\n\t\t\tbashId?: string;\n\t\t\texcludeFromContext?: boolean;\n\t\t\texecutionId?: string;\n\t\t\toperations?: Record<string, unknown>;\n\t }\n\t| { id?: string; type: \"record_bash_result\"; command: string; result: BashResult; excludeFromContext?: boolean }\n\t| { id?: string; type: \"abort_bash\" }\n\t| { id?: string; type: \"cleanup_bash_output\"; path: string }\n\t| { id?: string; type: \"set_label\"; entryId: string; label?: string }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"navigate_tree\";\n\t\t\ttargetId: string;\n\t\t\tsummarize?: boolean;\n\t\t\tcustomInstructions?: string;\n\t\t\treplaceInstructions?: boolean;\n\t\t\tlabel?: string;\n\t }\n\n\t// Session\n\t| { id?: string; type: \"get_session_stats\" }\n\t| { id?: string; type: \"export_html\"; outputPath?: string; themeName?: string }\n\t| { id?: string; type: \"export_jsonl\"; outputPath?: string }\n\t| { id?: string; type: \"switch_session\"; sessionPath: string; cwdOverride?: string }\n\t| { id?: string; type: \"fork\"; entryId: string; position?: \"before\" | \"at\" }\n\t| { id?: string; type: \"clone\" }\n\t| { id?: string; type: \"get_fork_messages\" }\n\t| { id?: string; type: \"get_entries\"; since?: string }\n\t| { id?: string; type: \"get_tree\" }\n\t| { id?: string; type: \"get_last_assistant_text\" }\n\t| { id?: string; type: \"set_session_name\"; name: string }\n\t| { id?: string; type: \"import_jsonl\"; inputPath: string; cwdOverride?: string }\n\n\t// Messages\n\t| { id?: string; type: \"get_messages\" }\n\t/**\n\t * Fetch one media block a `media_placeholders` client received as an `image_ref`\n\t * stub. `contentIndex` indexes the toolResult's `content` array and must point at\n\t * an image block; anything else answers `media_not_found`.\n\t */\n\t| { id?: string; type: \"get_media\"; toolCallId: string; contentIndex: number }\n\n\t// Commands and loaded runtime surfaces\n\t| { id?: string; type: \"get_commands\" }\n\t| { id?: string; type: \"get_loaded_surfaces\" }\n\t| { id?: string; type: \"extension_request\"; name: string; data?: unknown }\n\n\t// Auth (task 13) is additive. get_auth_providers, login_api_key and logout\n\t// answer synchronously. login_start responds immediately (flow-started) and\n\t// completion is delivered via auth_login_url / auth_login_end EVENTS, because\n\t// an interactive OAuth round-trip cannot fit the 30s request timeout.\n\t| { id?: string; type: \"get_auth_providers\" }\n\t| { id?: string; type: \"login_start\"; provider: string }\n\t| { id?: string; type: \"login_cancel\"; provider: string }\n\t| { id?: string; type: \"login_api_key\"; provider: string; key: string }\n\t| { id?: string; type: \"logout\"; provider: string }\n\n\t// Provider accounts (task 13) are additive. The desktop consumer contract\n\t// lives in ../omo-desktop-app/packages/contracts/src/rpc.ts and is updated separately.\n\t| { id?: string; type: \"get_provider_accounts\"; provider: string }\n\t| { id?: string; type: \"account_pin\"; provider: string; name: string | null }\n\t| { id?: string; type: \"account_remove\"; provider: string; name: string }\n\t| { id?: string; type: \"set_client_info\"; width: number; capabilities?: string[] };\n\n/** Stable multi-session protocol error codes. */\nexport const RPC_ERROR_UNKNOWN_SESSION = \"unknown_session\";\nexport const RPC_ERROR_SESSION_CLOSING = \"session_closing\";\nexport const RPC_ERROR_SESSION_PATH_IN_USE = \"session_path_in_use\";\nexport const RPC_ERROR_MISSING_SESSION_ID = \"missing_session_id\";\nexport const RPC_ERROR_MULTI_SESSION_DISABLED = \"multi_session_disabled\";\nexport const RPC_ERROR_INVALID_PATH = \"invalid_path\";\nexport const RPC_ERROR_OPEN_FAILED = \"open_failed\";\nexport const RPC_ERROR_TOO_MANY_SESSIONS = \"too_many_sessions\";\nexport const RPC_ERROR_MEDIA_NOT_FOUND = \"media_not_found\";\n\nexport type RpcErrorCode =\n\t| typeof RPC_ERROR_UNKNOWN_SESSION\n\t| typeof RPC_ERROR_SESSION_CLOSING\n\t| typeof RPC_ERROR_SESSION_PATH_IN_USE\n\t| typeof RPC_ERROR_MISSING_SESSION_ID\n\t| typeof RPC_ERROR_MULTI_SESSION_DISABLED\n\t| typeof RPC_ERROR_INVALID_PATH\n\t| typeof RPC_ERROR_OPEN_FAILED\n\t| typeof RPC_ERROR_TOO_MANY_SESSIONS\n\t| typeof RPC_ERROR_MEDIA_NOT_FOUND;\n\n/** Every established command accepts an additive routing envelope. */\nexport type RpcCommand =\n\t| (RpcSessionCommand & { sessionId?: string })\n\t| { id?: string; type: \"get_protocol_info\" }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"open_session\";\n\t\t\tsessionPath?: string;\n\t\t\tcwd?: string;\n\t\t\tprovider?: string;\n\t\t\tmodelId?: string;\n\t\t\tthinkingLevel?: ThinkingLevel;\n\t\t\tpermissionPreset?: string;\n\t }\n\t| { id?: string; type: \"close_session\"; sessionId: string }\n\t| { id?: string; type: \"list_sessions\" };\n\n// ============================================================================\n// Auth provider info (get_auth_providers response)\n// ============================================================================\n\n/** One provider row for the /login and /logout selectors. */\nexport interface RpcAuthProvider {\n\t/** Provider id (e.g. \"anthropic\", \"openai\"). */\n\tid: string;\n\t/** Human-readable display name. */\n\tname: string;\n\t/** How this provider authenticates. */\n\tauthType: \"oauth\" | \"api_key\";\n\t/** Auth status without exposing or refreshing any credential. */\n\tstatus: RpcAuthStatus;\n}\n\n/** Auth status mirror (no credential values), from getProviderAuthStatus. */\nexport interface RpcAuthStatus {\n\tconfigured: boolean;\n\tsource?:\n\t\t| \"stored\"\n\t\t| \"runtime\"\n\t\t| \"environment\"\n\t\t| \"fallback\"\n\t\t| \"models_json_key\"\n\t\t| \"models_json_command\"\n\t\t| \"models_json_headers\"\n\t\t| \"extension_headers\";\n\tlabel?: string;\n}\n\n/** Account-slot metadata safe to send to desktop clients. */\nexport interface RpcProviderAccount {\n\tname: string;\n\tsource: \"login\" | \"import\" | \"env\";\n\tblocked: boolean;\n\tpinned: boolean;\n}\n\n// ============================================================================\n// RPC Slash Command (for get_commands response)\n// ============================================================================\n\n/** One extension module loaded by the session resource loader. */\nexport interface RpcLoadedExtension {\n\tname: string;\n\tpath: string;\n\tsourceInfo: SourceInfo;\n\tenabled: boolean;\n}\n\nexport type RpcMcpServerStatus =\n\t| \"enabled\"\n\t| \"disabled\"\n\t| \"untrusted\"\n\t| \"idle\"\n\t| \"connecting\"\n\t| \"connected\"\n\t| \"degraded\"\n\t| \"suspended\"\n\t| \"needs_auth\"\n\t| \"needs_client_registration\";\n\n/** Runtime MCP server state projected from the session-owned MCP service. */\nexport interface RpcLoadedMcpServer {\n\tname: string;\n\ttoolCount: number;\n\tstatus: RpcMcpServerStatus;\n\tauthStatus: \"unsupported\" | \"notLoggedIn\" | \"bearerToken\" | \"oAuth\";\n}\n\n// ============================================================================\n// RPC State\n// ============================================================================\n\nexport interface RpcSessionModelEntry {\n\tmodel: Model<any>;\n\tthinkingLevel?: ThinkingLevel;\n\tthinkingSelection?: ThinkingSelection;\n\tserviceTier?: ServiceTier;\n}\n\nexport interface RpcSessionState {\n\tmodel?: Model<any>;\n\tthinkingLevel: ThinkingLevel;\n\t/**\n\t * Explicit selector provenance for `thinkingLevel`, absent for SDK-defaulted\n\t * effective levels. An attached client cannot distinguish \"the user chose high\"\n\t * from \"high is simply the effective level\" without it.\n\t */\n\tthinkingSelection?: ThinkingSelection;\n\t/**\n\t * Abort owner of the most recent aborted turn, or the in-flight one while it is\n\t * still settling. Retained after settle: the live session getter is transient, so a\n\t * client that snapshots state after the turn ends would otherwise see nothing and\n\t * fall back to generic wording instead of \"Operation aborted\".\n\t */\n\tlastAbortSource?: AgentAbortSource;\n\t/** Service tier the session resolved for the active model, if any. */\n\tserviceTier?: ServiceTier;\n\t/** True when the active model is served at the priority (\"fast\") tier. */\n\tfastMode: boolean;\n\tisStreaming: boolean;\n\tisCompacting: boolean;\n\tsteeringMode: \"all\" | \"one-at-a-time\";\n\tfollowUpMode: \"all\" | \"one-at-a-time\";\n\tsessionFile?: string;\n\tsessionId: string;\n\tsessionName?: string;\n\tcwd: string;\n\t/** Whether project-scoped settings and resources are trusted by the host. */\n\tprojectTrusted: boolean;\n\t/** Authoritative entries for setup-only sessions whose deferred file does not exist yet. */\n\tentries?: SessionEntry[];\n\tfavoriteModels: RpcSessionModelEntry[];\n\tscopedModels: RpcSessionModelEntry[];\n\tsteering: string[];\n\tfollowUp: string[];\n\tordered: Array<{ text: string; mode: \"steer\" | \"followUp\"; enqueueOrder: number }>;\n\tautoCompactionEnabled: boolean;\n\tmessageCount: number;\n\tpendingMessageCount: number;\n\tusageTotals: UsageTotals;\n\tcontextUsage?: ContextUsage;\n\tretryAttempt: number;\n\tisBashRunning: boolean;\n}\n\n// ============================================================================\n// RPC Responses (stdout)\n// ============================================================================\n\n// Success responses with data\nexport type RpcResponse =\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_protocol_info\";\n\t\t\tsuccess: true;\n\t\t\tdata: {\n\t\t\t\tprotocolVersion: 1;\n\t\t\t\tserverVersion: string;\n\t\t\t\tcapabilities: string[];\n\t\t\t\tmode: \"classic\" | \"multi\";\n\t\t\t};\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"open_session\";\n\t\t\tsuccess: true;\n\t\t\tdata: { sessionId: string; state: RpcSessionState; attached?: boolean };\n\t }\n\t| { id?: string; type: \"response\"; command: \"close_session\"; success: true; data: Record<string, never> }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"list_sessions\";\n\t\t\tsuccess: true;\n\t\t\tdata: {\n\t\t\t\tsessions: Array<{\n\t\t\t\t\tsessionId: string;\n\t\t\t\t\tdurableSessionId?: string;\n\t\t\t\t\tsessionPath?: string;\n\t\t\t\t\tcwd: string;\n\t\t\t\t\tname?: string;\n\t\t\t\t\tstatus: \"opening\" | \"open\" | \"closing\" | \"closed\";\n\t\t\t\t}>;\n\t\t\t};\n\t }\n\t// Prompting (async - events follow)\n\t// data.disposition reports how the host disposed the prompt (started/queued/handled)\n\t// so proxied optimistic-echo contracts resolve exactly like the local path; older\n\t// hosts omit it and clients must degrade to canonical-only rendering.\n\t| { id?: string; type: \"response\"; command: \"prompt\"; success: true; data?: { disposition?: PromptDisposition } }\n\t| { id?: string; type: \"response\"; command: \"send_custom_message\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"append_user_message\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"append_session_entry\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"steer\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"follow_up\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"abort\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"abort_compaction\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"reload\"; success: true; data: { cancelled: boolean; reason?: string } }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"check_reload_veto\";\n\t\t\tsuccess: true;\n\t\t\tdata: { cancelled: boolean; reason?: string };\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"clear_queue\";\n\t\t\tsuccess: true;\n\t\t\tdata: {\n\t\t\t\tsteering: string[];\n\t\t\t\tfollowUp: string[];\n\t\t\t\tordered: Array<{ text: string; mode: \"steer\" | \"followUp\"; enqueueOrder: number }>;\n\t\t\t};\n\t }\n\t| { id?: string; type: \"response\"; command: \"new_session\"; success: true; data: { cancelled: boolean } }\n\n\t// State\n\t| { id?: string; type: \"response\"; command: \"get_state\"; success: true; data: RpcSessionState }\n\n\t// Model\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"set_model\";\n\t\t\tsuccess: true;\n\t\t\tdata: Model<any> & { systemPromptName?: string };\n\t }\n\t| { id?: string; type: \"response\"; command: \"set_favorite_models\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"set_scoped_models\"; success: true }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"cycle_model\";\n\t\t\tsuccess: true;\n\t\t\tdata: { model: Model<any>; thinkingLevel: ThinkingLevel; isScoped: boolean } | null;\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_available_models\";\n\t\t\tsuccess: true;\n\t\t\tdata: { models: Array<Model<any> & { supportedThinkingLevels: ThinkingLevel[] }> };\n\t }\n\n\t// Thinking\n\t| { id?: string; type: \"response\"; command: \"set_thinking_level\"; success: true }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"cycle_thinking_level\";\n\t\t\tsuccess: true;\n\t\t\tdata: { level: ThinkingLevel } | null;\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_available_thinking_levels\";\n\t\t\tsuccess: true;\n\t\t\tdata: { levels: ThinkingLevel[] };\n\t }\n\n\t// Fast mode\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"set_fast_mode\";\n\t\t\tsuccess: true;\n\t\t\tdata: { enabled: boolean; serviceTier: ServiceTier; provider: string; modelId: string };\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_fast_mode\";\n\t\t\tsuccess: true;\n\t\t\tdata: { enabled: boolean; serviceTier: ServiceTier | null };\n\t }\n\n\t// Queue modes\n\t| { id?: string; type: \"response\"; command: \"set_steering_mode\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"set_follow_up_mode\"; success: true }\n\n\t// Compaction\n\t| { id?: string; type: \"response\"; command: \"compact\"; success: true; data: CompactionResult }\n\t| { id?: string; type: \"response\"; command: \"set_auto_compaction\"; success: true }\n\n\t// Retry\n\t| { id?: string; type: \"response\"; command: \"set_auto_retry\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"abort_retry\"; success: true }\n\n\t// Bash\n\t| { id?: string; type: \"response\"; command: \"bash\"; success: true; data: BashResult }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"navigate_tree\";\n\t\t\tsuccess: true;\n\t\t\tdata: { cancelled: boolean; editorText?: string; aborted?: boolean; summaryEntry?: unknown };\n\t }\n\t| { id?: string; type: \"response\"; command: \"abort_bash\"; success: true }\n\n\t// Session\n\t| { id?: string; type: \"response\"; command: \"get_session_stats\"; success: true; data: SessionStats }\n\t| { id?: string; type: \"response\"; command: \"export_html\"; success: true; data: { path: string } }\n\t| { id?: string; type: \"response\"; command: \"export_jsonl\"; success: true; data: { path: string } }\n\t| { id?: string; type: \"response\"; command: \"switch_session\"; success: true; data: { cancelled: boolean } }\n\t| { id?: string; type: \"response\"; command: \"fork\"; success: true; data: { text: string; cancelled: boolean } }\n\t| { id?: string; type: \"response\"; command: \"clone\"; success: true; data: { cancelled: boolean } }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_fork_messages\";\n\t\t\tsuccess: true;\n\t\t\tdata: { messages: Array<{ entryId: string; text: string }> };\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_entries\";\n\t\t\tsuccess: true;\n\t\t\tdata: { entries: SessionEntry[]; leafId: string | null };\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_tree\";\n\t\t\tsuccess: true;\n\t\t\tdata: { tree: SessionTreeNode[]; leafId: string | null };\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_last_assistant_text\";\n\t\t\tsuccess: true;\n\t\t\tdata: { text: string | null };\n\t }\n\t| { id?: string; type: \"response\"; command: \"set_session_name\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"import_jsonl\"; success: true; data: { cancelled: boolean } }\n\n\t// Messages\n\t| { id?: string; type: \"response\"; command: \"get_messages\"; success: true; data: { messages: AgentMessage[] } }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_media\";\n\t\t\tsuccess: true;\n\t\t\tdata: { toolCallId: string; contentIndex: number; content: ImageContent };\n\t }\n\n\t// Commands and loaded runtime surfaces\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_commands\";\n\t\t\tsuccess: true;\n\t\t\tdata: { commands: RpcSlashCommand[] };\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_loaded_surfaces\";\n\t\t\tsuccess: true;\n\t\t\tdata: { extensions: RpcLoadedExtension[]; mcpServers: RpcLoadedMcpServer[] };\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"extension_request\";\n\t\t\tsuccess: true;\n\t\t\tdata: unknown;\n\t }\n\n\t// Auth (task 13)\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_auth_providers\";\n\t\t\tsuccess: true;\n\t\t\tdata: { providers: RpcAuthProvider[] };\n\t }\n\t// login_start returns immediately: success:true means the flow has started.\n\t// The URL and completion arrive as auth_login_url / auth_login_end events.\n\t| { id?: string; type: \"response\"; command: \"login_start\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"login_cancel\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"login_api_key\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"logout\"; success: true }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_provider_accounts\";\n\t\t\tsuccess: true;\n\t\t\tdata: { accounts: RpcProviderAccount[] };\n\t }\n\t| { id?: string; type: \"response\"; command: \"account_pin\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"account_remove\"; success: true }\n\n\t// Error response (any command can fail)\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: string;\n\t\t\tsuccess: false;\n\t\t\terror: string;\n\t\t\terrorCode?: string;\n\t\t\terrorData?: unknown;\n\t };\n\n// ============================================================================\n// Extension UI Events (stdout)\n// ============================================================================\n\n/** Emitted when an extension needs user input */\nexport type RpcExtensionUIRequest =\n\t| { type: \"extension_ui_request\"; id: string; method: \"select\"; title: string; options: string[]; timeout?: number }\n\t| { type: \"extension_ui_request\"; id: string; method: \"confirm\"; title: string; message: string; timeout?: number }\n\t| {\n\t\t\ttype: \"extension_ui_request\";\n\t\t\tid: string;\n\t\t\tmethod: \"input\";\n\t\t\ttitle: string;\n\t\t\tplaceholder?: string;\n\t\t\ttimeout?: number;\n\t }\n\t| { type: \"extension_ui_request\"; id: string; method: \"editor\"; title: string; prefill?: string }\n\t| {\n\t\t\ttype: \"extension_ui_request\";\n\t\t\tid: string;\n\t\t\tmethod: \"notify\";\n\t\t\tmessage: string;\n\t\t\tnotifyType?: \"info\" | \"warning\" | \"error\";\n\t }\n\t| {\n\t\t\ttype: \"extension_ui_request\";\n\t\t\tid: string;\n\t\t\tmethod: \"setStatus\";\n\t\t\tstatusKey: string;\n\t\t\tstatusText: string | undefined;\n\t }\n\t| {\n\t\t\ttype: \"extension_ui_request\";\n\t\t\tid: string;\n\t\t\tmethod: \"setWidget\";\n\t\t\twidgetKey: string;\n\t\t\twidgetLines: string[] | undefined;\n\t\t\twidgetPlacement?: \"aboveEditor\" | \"belowEditor\";\n\t }\n\t| {\n\t\t\ttype: \"extension_ui_request\";\n\t\t\tid: string;\n\t\t\tmethod: \"setHeader\" | \"setFooter\";\n\t\t\twidgetLines: string[] | undefined;\n\t }\n\t| { type: \"extension_ui_request\"; id: string; method: \"setTitle\"; title: string }\n\t| { type: \"extension_ui_request\"; id: string; method: \"set_editor_text\"; text: string }\n\t// Additive (task 13/14): emitted ONLY when the client advertised the\n\t// \"custom_unsupported\" capability. ctx.ui.custom cannot render a third-party\n\t// component in RPC mode, so a flagged client gets this notice before custom()\n\t// returns undefined. Default clients never see it (byte-identical behavior).\n\t| { type: \"extension_ui_request\"; id: string; method: \"custom_unsupported\"; extensionName: string };\n\nexport type RpcExtensionEvent = {\n\ttype: \"extension_event\";\n\tname: string;\n\tdata: unknown;\n};\n\n// ============================================================================\n// Extension UI Commands (stdin)\n// ============================================================================\n\n/** Response to an extension UI request */\nexport type RpcExtensionUIResponse =\n\t| { type: \"extension_ui_response\"; id: string; value: string }\n\t| { type: \"extension_ui_response\"; id: string; confirmed: boolean }\n\t| { type: \"extension_ui_response\"; id: string; cancelled: true };\n\n/** Emitted when the effective session thinking level changes. */\nexport interface RpcThinkingLevelChangedEvent {\n\ttype: \"thinking_level_changed\";\n\tlevel: ThinkingLevel;\n\t/**\n\t * Selector provenance in force after the change; absent when the level is an\n\t * SDK-defaulted effective level rather than an explicit choice. Additive: an old\n\t * client that does not know the field ignores it.\n\t */\n\tthinkingSelection?: ThinkingSelection;\n}\n\nexport interface RpcHighReasoningWarningEvent {\n\ttype: \"high_reasoning_warning\";\n\tmodelId: string;\n\tprovider: string;\n\tthinkingLevel: ThinkingLevel;\n}\n\n/** Emitted after explicit skill tokens are expanded for a user-authored request. */\nexport interface RpcSkillInvocationEvent {\n\ttype: \"skill_invocation\";\n\tskills: readonly {\n\t\tname: string;\n\t\tpath: string;\n\t\tsyntax: \"dollar\" | \"slash\";\n\t}[];\n}\n\n/** Emitted when startup or reload selects an existing settings file. */\nexport interface RpcSettingsSourceSelectedEvent {\n\ttype: \"settings_source_selected\";\n\tpath: string;\n\tformat: \"jsonc\" | \"json\";\n\treason: \"explicit-jsonc\" | \"json-only\";\n\tscope: \"global\" | \"project\";\n}\n\n/**\n * Emitted after the session's active model changed, with the thinking level in force AFTER\n * the switch (per-model memory, a favorite's pinned level, or the clamped previous level).\n *\n * Clients that tracked the model by inferring it from `entry_appended` can consume this\n * instead. Additive: an old client that does not know the type filters it out.\n */\nexport interface RpcModelChangedEvent {\n\ttype: \"model_changed\";\n\tmodel: Model<any>;\n\tthinkingLevel: ThinkingLevel;\n\t/** Why the model changed: \"set\", \"cycle\", \"restore\", \"fallback\", or \"fallback-revert\". */\n\tsource: string;\n\t/** Selector provenance for `thinkingLevel` after the switch, when one was explicit. */\n\tthinkingSelection?: ThinkingSelection;\n}\n\n/** Emitted when the effective service tier or fast-mode state of the session changes. */\nexport interface RpcServiceTierChangedEvent {\n\ttype: \"service_tier_changed\";\n\ttier?: ServiceTier;\n\tfastMode: boolean;\n}\n/**\n * Emitted after the host swapped the live session behind this connection (new session,\n * fork, or switch), carrying the new authoritative identity.\n *\n * A replacement can be initiated by ANY attached client. Without this event the other\n * attached clients keep their stale identity and keep routing replacement-dependent\n * actions at the session that no longer exists. Additive: an old client that does not\n * know the type filters it out.\n */\nexport interface RpcSessionReplacedEvent {\n\ttype: \"session_replaced\";\n\t/**\n\t * Durable session id of the session now bound to this connection.\n\t *\n\t * Deliberately NOT `sessionId`: top-level `sessionId` is reserved for the\n\t * per-connection routing handle that multi-session hosts tag every record\n\t * with, and that tag is applied last - it would overwrite this value and\n\t * leave the event carrying no identity at all.\n\t */\n\tdurableSessionId: string;\n\t/** Session file backing the new session, absent for a deferred setup-only session. */\n\tsessionFile?: string;\n\tcwd: string;\n\tsessionName?: string;\n}\n\n/** Emitted after the loaded skill, extension, or MCP inventory changes. */\nexport interface RpcLoadedSurfacesChangedEvent {\n\ttype: \"loaded_surfaces_changed\";\n}\n\n/** Emitted after an account is added, removed, pinned, or blocked by refresh failure. */\nexport interface RpcAuthAccountsChangedEvent {\n\ttype: \"auth_accounts_changed\";\n\tprovider: string;\n}\n\n/** Emitted when the SDK failover engine advances to a different account slot. */\nexport interface RpcAccountFailoverEvent {\n\ttype: \"account_failover\";\n\tprovider: string;\n\tfrom: string;\n\tto: string;\n\treason: string;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-command-router.d.ts","sourceRoot":"","sources":["../../../src/modes/rpc/session-command-router.ts"],"names":[],"mappings":"AAGA,OAAO,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EAAE,IAAI,CAAC,uBAAuB,EAAE,KAAK,GAAG,kBAAkB,GAAG,eAAe,GAAG,sBAAsB,CAAC,EAC9G,aAAa,GAAE,OAAO,uBAAiD,EACvE,iBAAiB,GAAE,UAAU,CAAC,OAAO,uBAAuB,CAAC,CAAC,CAAC,CAAM,EACrE,IAAI,CAAC,EAAE,oBAAoB;IAoBtB,MAAM,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAoD7D,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAa9B;;;;;;;;;OASG;IACH,iBAAiB,IAAI,IAAI;IA4BzB;;;;;OAKG;YACW,gBAAgB;IAyB9B,4EAA4E;IAC5E,OAAO,CAAC,sBAAsB;IAQ9B,OAAO,CAAC,SAAS;IAMjB,OAAO,CAAC,eAAe;YAiBT,IAAI;IA8GlB;;;;OAIG;IACG,iBAAiB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAgD5D;;;;;;;OAOG;YACW,mBAAmB;IAQjC;;;;;;OAMG;IACH,OAAO,CAAC,UAAU;IAYlB,kFAAkF;IAClF,OAAO,CAAC,aAAa;YAWP,KAAK;IA6BnB,qGAAqG;IACrG,OAAO,CAAC,sBAAsB;IAkB9B;;;;;;OAMG;YACW,aAAa;IA0B3B,OAAO,CAAC,kBAAkB;IAQ1B,OAAO,CAAC,IAAI;CAWZ"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { VERSION } from "../../config.js";
|
|
2
2
|
import { buildRpcSessionState } from "./connection-handler.js";
|
|
3
|
-
import { AUTO_TITLE_SESSIONS_CAPABILITY } from "./custom-capability.js";
|
|
3
|
+
import { AUTO_TITLE_SESSIONS_CAPABILITY, MEDIA_PLACEHOLDERS_CAPABILITY } from "./custom-capability.js";
|
|
4
4
|
import { RPC_ERROR_MISSING_SESSION_ID, RPC_ERROR_OPEN_FAILED, RPC_ERROR_SESSION_CLOSING, RPC_ERROR_UNKNOWN_SESSION, } from "./rpc-types.js";
|
|
5
5
|
import { createRpcSessionBinding } from "./session-binding.js";
|
|
6
6
|
import { RpcSessionRegistryError } from "./session-registry.js";
|
|
@@ -43,6 +43,7 @@ export class SessionCommandRouter {
|
|
|
43
43
|
const capabilities = new Set([
|
|
44
44
|
"multi_session",
|
|
45
45
|
AUTO_TITLE_SESSIONS_CAPABILITY,
|
|
46
|
+
MEDIA_PLACEHOLDERS_CAPABILITY,
|
|
46
47
|
...(this.connectionOptions?.capabilities ?? []),
|
|
47
48
|
]);
|
|
48
49
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-command-router.js","sourceRoot":"","sources":["../../../src/modes/rpc/session-command-router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,8BAA8B,EAAE,MAAM,wBAAwB,CAAC;AAExE,OAAO,EACN,4BAA4B,EAC5B,qBAAqB,EACrB,yBAAyB,EACzB,yBAAyB,GACzB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,uBAAuB,EAA0B,MAAM,sBAAsB,CAAC;AAGvF,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAEhE,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,CAAC,mBAAmB,EAAE,cAAc,EAAE,eAAe,EAAE,eAAe,CAAC,CAAC,CAAC;AA2BlG,SAAS,KAAK,CAAC,EAAsB,EAAE,OAAe,EAAE,IAAY;IACnE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AACvE,CAAC;AAED,uFAAuF;AACvF,MAAM,OAAO,oBAAoB;IA2BhC,YACC,QAA4B,EAC5B,MAA0B,EAC1B,QAA8G,EAC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AAC;CACD","sourcesContent":["import { VERSION } from \"../../config.ts\";\nimport { buildRpcSessionState } from \"./connection-handler.ts\";\nimport { AUTO_TITLE_SESSIONS_CAPABILITY } from \"./custom-capability.ts\";\nimport type { RpcCommand, RpcResponse } from \"./rpc-types.ts\";\nimport {\n\tRPC_ERROR_MISSING_SESSION_ID,\n\tRPC_ERROR_OPEN_FAILED,\n\tRPC_ERROR_SESSION_CLOSING,\n\tRPC_ERROR_UNKNOWN_SESSION,\n} from \"./rpc-types.ts\";\nimport { createRpcSessionBinding, type RpcSessionBinding } from \"./session-binding.ts\";\nimport type { SessionEventWriter } from \"./session-event-writer.ts\";\nimport type { OpenRpcSession, RpcSessionLaunchProfile, RpcSessionRegistry } from \"./session-registry.ts\";\nimport { RpcSessionRegistryError } from \"./session-registry.ts\";\n\nconst controls = new Set([\"get_protocol_info\", \"open_session\", \"close_session\", \"list_sessions\"]);\n\n/** Binding factory seam, injectable so host wiring is testable without a full runtime stack. */\nexport type RpcBindingFactory = typeof createRpcSessionBinding;\n\n/**\n * Occupancy policy for the shared multi-session host. All fields are opt-in:\n * a router constructed without a policy keeps today's behavior (sessions live\n * until close_session; the host never self-exits).\n */\nexport interface RpcSessionIdlePolicy {\n\t/** Injectable clock (defaults to Date.now) for deterministic tests. */\n\tnow?: () => number;\n\t/** Evict open sessions whose last routed command or session-owned work settled longer ago than this. */\n\tidleEvictionMs?: number;\n\t/** Invoke onEmptyExit once the registry has stayed empty for this long. */\n\temptyExitMs?: number;\n\t/** Host shutdown hook fired by the empty-exit window; called at most once. */\n\tonEmptyExit?: () => void;\n\t/**\n\t * Consulted every tick before the empty-exit window advances. Returning false\n\t * both blocks the exit and resets the window, so a host with a connected but\n\t * sessionless client stays up instead of exiting under its supervisor.\n\t */\n\tcanExitWhenEmpty?: () => boolean;\n}\n\nfunction error(id: string | undefined, command: string, code: string): RpcResponse {\n\treturn { id, type: \"response\", command, success: false, error: code };\n}\n\n/** Routes control messages and enforces a routing handle for every session command. */\nexport class SessionCommandRouter {\n\tprivate readonly bindings = new Map<string, RpcSessionBinding>();\n\t/** Session handles opened by each connection, with one count per attachment. */\n\tprivate readonly sessionsByConnection = new Map<string, Map<string, number>>();\n\t/** Opens currently awaiting runtime/binding setup, keyed by connection. */\n\tprivate readonly opensByConnection = new Map<string, Set<Promise<void>>>();\n\t/** Connections whose socket has already been detached. */\n\tprivate readonly releasedConnections = new Set<string>();\n\tprivate readonly registry: RpcSessionRegistry;\n\tprivate readonly writer: SessionEventWriter;\n\tprivate readonly defaults: Pick<\n\t\tRpcSessionLaunchProfile,\n\t\t\"cwd\" | \"permissionPreset\" | \"creationModel\" | \"initialThinkingLevel\"\n\t>;\n\tprivate readonly createBinding: typeof createRpcSessionBinding;\n\tprivate readonly connectionOptions: Parameters<typeof createRpcSessionBinding>[4];\n\tprivate readonly widths = new Map<string, Map<string, number>>();\n\tprivate readonly pendingCapabilities = new Map<string, string[]>();\n\tprivate readonly finalizations = new Map<string, { promise: Promise<void>; resolve: () => void }>();\n\tprivate readonly idleNow: () => number;\n\tprivate readonly idleEvictionMs: number;\n\tprivate readonly emptyExitMs: number;\n\tprivate readonly onEmptyExit?: () => void;\n\tprivate readonly canExitWhenEmpty?: () => boolean;\n\tprivate sweepTimer: ReturnType<typeof setInterval> | undefined;\n\tprivate emptySince: number | undefined;\n\n\tconstructor(\n\t\tregistry: RpcSessionRegistry,\n\t\twriter: SessionEventWriter,\n\t\tdefaults: Pick<RpcSessionLaunchProfile, \"cwd\" | \"permissionPreset\" | \"creationModel\" | \"initialThinkingLevel\">,\n\t\tcreateBinding: typeof createRpcSessionBinding = createRpcSessionBinding,\n\t\tconnectionOptions: Parameters<typeof createRpcSessionBinding>[4] = {},\n\t\tidle?: RpcSessionIdlePolicy,\n\t) {\n\t\tthis.registry = registry;\n\t\tthis.writer = writer;\n\t\tthis.defaults = defaults;\n\t\tthis.createBinding = createBinding;\n\t\tthis.connectionOptions = connectionOptions;\n\t\tthis.idleNow = idle?.now ?? Date.now;\n\t\tthis.idleEvictionMs = idle?.idleEvictionMs ?? Number.POSITIVE_INFINITY;\n\t\tthis.emptyExitMs = idle?.emptyExitMs ?? Number.POSITIVE_INFINITY;\n\t\tthis.onEmptyExit = idle?.onEmptyExit;\n\t\tthis.canExitWhenEmpty = idle?.canExitWhenEmpty;\n\t\tif (Number.isFinite(this.idleEvictionMs) || Number.isFinite(this.emptyExitMs)) {\n\t\t\t// Unref'd: occupancy hygiene must never be the reason the event loop stays open.\n\t\t\tconst tickMs = Math.max(20, Math.min(5_000, Math.min(this.idleEvictionMs, this.emptyExitMs) / 4));\n\t\t\tthis.sweepTimer = setInterval(() => this.sweepIdleSessions(), tickMs);\n\t\t\tthis.sweepTimer.unref?.();\n\t\t}\n\t}\n\n\tasync handle(command: RpcCommand): Promise<RpcResponse | undefined> {\n\t\tif (command.type === \"get_protocol_info\") {\n\t\t\tconst capabilities = new Set([\n\t\t\t\t\"multi_session\",\n\t\t\t\tAUTO_TITLE_SESSIONS_CAPABILITY,\n\t\t\t\t...(this.connectionOptions?.capabilities ?? []),\n\t\t\t]);\n\t\t\treturn {\n\t\t\t\tid: command.id,\n\t\t\t\ttype: \"response\",\n\t\t\t\tcommand: \"get_protocol_info\",\n\t\t\t\tsuccess: true,\n\t\t\t\tdata: {\n\t\t\t\t\tprotocolVersion: 1,\n\t\t\t\t\tserverVersion: VERSION,\n\t\t\t\t\tcapabilities: [...capabilities],\n\t\t\t\t\tmode: \"multi\",\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\tif (command.type === \"list_sessions\")\n\t\t\treturn {\n\t\t\t\tid: command.id,\n\t\t\t\ttype: \"response\",\n\t\t\t\tcommand: \"list_sessions\",\n\t\t\t\tsuccess: true,\n\t\t\t\tdata: { sessions: this.registry.list() },\n\t\t\t};\n\t\tif (command.type === \"open_session\") return this.openWithBarrier(command);\n\t\tif (command.type === \"close_session\") return this.close(command);\n\t\tif (command.type === \"set_client_info\" && !command.sessionId) {\n\t\t\tconst connection = this.writer.currentConnection();\n\t\t\tif (connection !== undefined) {\n\t\t\t\tthis.pendingCapabilities.set(connection, command.capabilities ?? []);\n\t\t\t\tthis.writer.setConnectionCapabilities(connection, command.capabilities ?? []);\n\t\t\t}\n\t\t\treturn { id: command.id, type: \"response\", command: \"set_client_info\", success: true } as RpcResponse;\n\t\t}\n\t\tif (controls.has(command.type)) return undefined;\n\t\tif (!command.sessionId) return error(command.id, command.type, RPC_ERROR_MISSING_SESSION_ID);\n\t\ttry {\n\t\t\tthis.registry.getForCommand(command.sessionId, command.type);\n\t\t\tconst binding = this.bindings.get(command.sessionId);\n\t\t\tif (!binding) return error(command.id, command.type, RPC_ERROR_UNKNOWN_SESSION);\n\t\t\tawait binding.handle(command);\n\t\t\treturn undefined;\n\t\t} catch (cause) {\n\t\t\treturn error(command.id, command.type, this.code(cause));\n\t\t}\n\t}\n\n\tasync dispose(): Promise<void> {\n\t\tthis.stopSweep();\n\t\tawait Promise.all(\n\t\t\t[...this.bindings.entries()].map(async ([sessionId, binding]) => {\n\t\t\t\tconst claim = this.tryClaimClose(sessionId, { drainAttachments: true });\n\t\t\t\tif (!claim) return;\n\t\t\t\tif (claim.finalizer) await this.finalizeClose(sessionId, binding);\n\t\t\t\telse await this.finalizations.get(sessionId)?.promise;\n\t\t\t}),\n\t\t);\n\t\tthis.bindings.clear();\n\t}\n\n\t/**\n\t * One occupancy sweep. Evicts open sessions idle longer than idleEvictionMs,\n\t * where \"idle\" is the COMPLETE session-owned activity contract\n\t * (`AgentSession.isSessionBusy`: agent run, bash, background terminal jobs and\n\t * other published wake sources, compaction, barrier-held session work) - busy\n\t * sessions restart their idle clock instead, so work that outlives a turn is\n\t * never killed. Fires onEmptyExit once the registry has STAYED empty for\n\t * emptyExitMs with the exit permitted; any live session or connected client\n\t * resets that window. Runs on an unref'd interval and is safe to call directly.\n\t */\n\tsweepIdleSessions(): void {\n\t\tconst now = this.idleNow();\n\t\tif (Number.isFinite(this.idleEvictionMs)) {\n\t\t\tfor (const { sessionId, status } of this.registry.list()) {\n\t\t\t\tif (status !== \"open\") continue;\n\t\t\t\tconst entry = this.registry.peek(sessionId);\n\t\t\t\tif (!entry) continue;\n\t\t\t\tif (entry.runtime?.session.isSessionBusy) {\n\t\t\t\t\t// Session-owned work defers eviction; the window restarts when it settles.\n\t\t\t\t\tentry.lastCommandAt = now;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (now - entry.lastCommandAt >= this.idleEvictionMs) void this.evictIdleSession(sessionId);\n\t\t\t}\n\t\t}\n\t\tif (Number.isFinite(this.emptyExitMs)) {\n\t\t\tif (this.registry.size === 0 && (this.canExitWhenEmpty?.() ?? true)) {\n\t\t\t\tif (this.emptySince === undefined) this.emptySince = now;\n\t\t\t\telse if (now - this.emptySince >= this.emptyExitMs) {\n\t\t\t\t\tthis.stopSweep();\n\t\t\t\t\tthis.onEmptyExit?.();\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tthis.emptySince = undefined;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Idle-session eviction: the same refcounted close sequence as an explicit\n\t * close_session, draining every attachment because eviction ends the shared\n\t * session, not one client's claim. Races with concurrent lifecycle paths are\n\t * tolerated the same way releaseOwnedSession tolerates them.\n\t */\n\tprivate async evictIdleSession(sessionId: string): Promise<void> {\n\t\t// A failed claim means an explicit close raced us and owns the entry now.\n\t\tconst claim = this.tryClaimClose(sessionId, { drainAttachments: true });\n\t\tif (!claim) return;\n\t\tconst binding = this.bindings.get(sessionId);\n\t\tbinding?.cancelPendingExtensionUiRequests?.();\n\t\tthis.forgetSessionOwnership(sessionId);\n\t\tif (claim.finalizer) {\n\t\t\tawait this.finalizeClose(sessionId, binding, () =>\n\t\t\t\tthis.writer.closeSession(sessionId, {\n\t\t\t\t\ttype: \"response\",\n\t\t\t\t\tcommand: \"close_session\",\n\t\t\t\t\tsuccess: true,\n\t\t\t\t\tdata: {},\n\t\t\t\t}),\n\t\t\t);\n\t\t} else {\n\t\t\tawait this.finalizations.get(sessionId)?.promise;\n\t\t}\n\t\t// The runtime is disposed and routing handles are unique per process\n\t\t// epoch, so nothing can emit under this id again: drop the writer's\n\t\t// per-session bookkeeping instead of retaining it for the host's life.\n\t\tthis.writer.forgetSession(sessionId);\n\t}\n\n\t/** Drops per-connection records for a handle the host closed on its own. */\n\tprivate forgetSessionOwnership(sessionId: string): void {\n\t\tfor (const [connection, owned] of this.sessionsByConnection) {\n\t\t\towned.delete(sessionId);\n\t\t\tif (owned.size === 0) this.sessionsByConnection.delete(connection);\n\t\t}\n\t\tthis.widths.delete(sessionId);\n\t}\n\n\tprivate stopSweep(): void {\n\t\tif (this.sweepTimer === undefined) return;\n\t\tclearInterval(this.sweepTimer);\n\t\tthis.sweepTimer = undefined;\n\t}\n\n\tprivate openWithBarrier(command: Extract<RpcCommand, { type: \"open_session\" }>): Promise<RpcResponse | undefined> {\n\t\tconst owner = this.writer.currentConnection();\n\t\tif (owner === undefined) return this.open(command);\n\t\tlet resolveBarrier!: () => void;\n\t\tconst barrier = new Promise<void>((resolve) => {\n\t\t\tresolveBarrier = resolve;\n\t\t});\n\t\tconst opens = this.opensByConnection.get(owner) ?? new Set<Promise<void>>();\n\t\topens.add(barrier);\n\t\tthis.opensByConnection.set(owner, opens);\n\t\treturn this.open(command, owner).finally(() => {\n\t\t\tresolveBarrier();\n\t\t\topens.delete(barrier);\n\t\t\tif (opens.size === 0) this.opensByConnection.delete(owner);\n\t\t});\n\t}\n\n\tprivate async open(\n\t\tcommand: Extract<RpcCommand, { type: \"open_session\" }>,\n\t\towner?: string,\n\t): Promise<RpcResponse | undefined> {\n\t\tlet opened: OpenRpcSession | undefined;\n\t\ttry {\n\t\t\topened = await this.registry.openSession({\n\t\t\t\tcwd: command.cwd ?? this.defaults.cwd,\n\t\t\t\tsessionPath: command.sessionPath,\n\t\t\t\tpermissionPreset: command.permissionPreset ?? this.defaults.permissionPreset,\n\t\t\t\tcreationModel:\n\t\t\t\t\tcommand.provider && command.modelId\n\t\t\t\t\t\t? { provider: command.provider, modelId: command.modelId }\n\t\t\t\t\t\t: this.defaults.creationModel,\n\t\t\t\tinitialThinkingLevel: command.thinkingLevel ?? this.defaults.initialThinkingLevel,\n\t\t\t});\n\t\t\tconst openedSession = opened;\n\t\t\tconst entry = this.registry.getForCommand(openedSession.sessionId, \"open_session\");\n\t\t\tif (owner !== undefined) {\n\t\t\t\tif (!this.writer.hasRegisteredConnectionCapabilities(owner))\n\t\t\t\t\tthis.writer.setConnectionCapabilities(\n\t\t\t\t\t\towner,\n\t\t\t\t\t\tthis.pendingCapabilities.get(owner) ?? this.connectionOptions?.capabilities ?? [],\n\t\t\t\t\t);\n\t\t\t\tthis.writer.attachConnectionToSession(owner, openedSession.sessionId);\n\t\t\t}\n\t\t\t// A client that dies without close_session (terminal closed, SIGKILL, dropped\n\t\t\t// SSH) still holds this handle's attachment and its path reservation. Remember\n\t\t\t// which connection owns it so releaseConnection() can close exactly that.\n\t\t\tif (owner !== undefined) {\n\t\t\t\tconst owned = this.sessionsByConnection.get(owner) ?? new Map<string, number>();\n\t\t\t\towned.set(openedSession.sessionId, (owned.get(openedSession.sessionId) ?? 0) + 1);\n\t\t\t\tthis.sessionsByConnection.set(owner, owned);\n\t\t\t}\n\t\t\tif (!this.bindings.has(openedSession.sessionId)) {\n\t\t\t\tthis.bindings.set(\n\t\t\t\t\topenedSession.sessionId,\n\t\t\t\t\tawait this.createBinding(\n\t\t\t\t\t\topenedSession.sessionId,\n\t\t\t\t\t\tentry,\n\t\t\t\t\t\tthis.writer,\n\t\t\t\t\t\t() => void this.close({ type: \"close_session\", sessionId: openedSession.sessionId }),\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t...this.connectionOptions,\n\t\t\t\t\t\t\tcapabilities:\n\t\t\t\t\t\t\t\towner !== undefined\n\t\t\t\t\t\t\t\t\t? (this.pendingCapabilities.get(owner) ?? this.connectionOptions?.capabilities ?? [])\n\t\t\t\t\t\t\t\t\t: this.connectionOptions?.capabilities,\n\t\t\t\t\t\t\tsharedWidth: {\n\t\t\t\t\t\t\t\tgetWidth: () => {\n\t\t\t\t\t\t\t\t\tconst widths = this.widths.get(openedSession.sessionId);\n\t\t\t\t\t\t\t\t\treturn widths?.size ? Math.min(...widths.values()) : 80;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tsetWidth: (connectionId, width) => {\n\t\t\t\t\t\t\t\t\tif (connectionId !== undefined) {\n\t\t\t\t\t\t\t\t\t\tconst widths = this.widths.get(openedSession.sessionId) ?? new Map<string, number>();\n\t\t\t\t\t\t\t\t\t\twidths.set(connectionId, width);\n\t\t\t\t\t\t\t\t\t\tthis.widths.set(openedSession.sessionId, widths);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tclearWidth: (connectionId) => {\n\t\t\t\t\t\t\t\t\tconst widths = this.widths.get(openedSession.sessionId);\n\t\t\t\t\t\t\t\t\tif (connectionId !== undefined) widths?.delete(connectionId);\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tsetCapabilities: (connectionId, capabilities) => {\n\t\t\t\t\t\t\t\t\tif (connectionId !== undefined) {\n\t\t\t\t\t\t\t\t\t\tthis.writer.setConnectionCapabilities(connectionId, capabilities);\n\t\t\t\t\t\t\t\t\t\tthis.pendingCapabilities.set(connectionId, [...capabilities]);\n\t\t\t\t\t\t\t\t\t\tfor (const binding of this.bindings.values()) binding.rerenderComponents?.();\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\thasRenderedComponents: (sessionId) => this.writer.hasCapableConnection(sessionId),\n\n\t\t\t\t\t\t\t\tconnectionId: () => this.writer.currentConnection(),\n\t\t\t\t\t\t\t\tonChange: () => {\n\t\t\t\t\t\t\t\t\tfor (const binding of this.bindings.values()) binding.rerenderComponents?.();\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (owner !== undefined && this.releasedConnections.has(owner)) {\n\t\t\t\tawait this.releaseOwnedSession(openedSession.sessionId);\n\t\t\t}\n\t\t\tconst state = entry.runtime!.session;\n\t\t\tthis.writer.enqueue(opened.sessionId, {\n\t\t\t\tid: command.id,\n\t\t\t\ttype: \"response\",\n\t\t\t\tcommand: \"open_session\",\n\t\t\t\tsuccess: true,\n\t\t\t\tdata: {\n\t\t\t\t\tsessionId: opened.sessionId,\n\t\t\t\t\tstate: buildRpcSessionState(state),\n\t\t\t\t\t...(opened.attached ? { attached: true } : {}),\n\t\t\t\t},\n\t\t\t});\n\t\t\treturn undefined;\n\t\t} catch (cause) {\n\t\t\tif (opened) {\n\t\t\t\ttry {\n\t\t\t\t\tawait this.registry.close(opened.sessionId);\n\t\t\t\t} catch {\n\t\t\t\t\t/* The open rollback has already removed the entry. */\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn error(command.id, \"open_session\", this.code(cause));\n\t\t}\n\t}\n\n\t/**\n\t * Releases every session a dropped connection still owned. Each handle goes through\n\t * the same refcounted close as an explicit close_session, so a session another\n\t * connection is still attached to keeps running and only the last owner tears it down.\n\t */\n\tasync releaseConnection(connectionId: string): Promise<void> {\n\t\tthis.releasedConnections.add(connectionId);\n\t\tthis.writer.clearConnectionCapabilities(connectionId);\n\t\tfor (const sessionId of this.sessionsByConnection.get(connectionId)?.keys() ?? [])\n\t\t\tthis.writer.detachConnectionFromSession(connectionId, sessionId);\n\t\tfor (const widths of this.widths.values()) widths.delete(connectionId);\n\t\tfor (const binding of this.bindings.values()) binding.rerenderComponents?.();\n\t\tconst opens = this.opensByConnection.get(connectionId);\n\t\tif (opens) await Promise.all([...opens]);\n\t\tconst owned = this.sessionsByConnection.get(connectionId);\n\t\tthis.sessionsByConnection.delete(connectionId);\n\t\tif (owned === undefined) {\n\t\t\tthis.releasedConnections.delete(connectionId);\n\t\t\treturn;\n\t\t}\n\t\tfor (const [sessionId, count] of owned) {\n\t\t\tthis.bindings.get(sessionId)?.cancelPendingExtensionUiRequests?.();\n\t\t\tfor (let attachment = 0; attachment < count; attachment++) {\n\t\t\t\t// Headless completion contract: a turn survives its client's death and\n\t\t\t\t// runs to settlement (the host lifecycle keeps the process alive on\n\t\t\t\t// active turns even with zero connections). Releasing mid-turn aborts\n\t\t\t\t// the run and seals the session before agent_settled reaches the\n\t\t\t\t// lifecycle observer, leaking the busy counter so the host never\n\t\t\t\t// idle-exits. Defer - never skip - the release until the turn settles,\n\t\t\t\t// so the dropped owner's reservation still frees afterwards.\n\t\t\t\tconst live = this.registry.peek(sessionId);\n\t\t\t\tconst session = live?.state === \"open\" ? live.runtime?.session : undefined;\n\t\t\t\tif (session?.isStreaming) {\n\t\t\t\t\tlet released = false;\n\t\t\t\t\tconst unsubscribe = session.subscribe((event) => {\n\t\t\t\t\t\tif (event.type !== \"agent_settled\" && event.type !== \"agent_idle\") return;\n\t\t\t\t\t\tif (released) return;\n\t\t\t\t\t\treleased = true;\n\t\t\t\t\t\tunsubscribe();\n\t\t\t\t\t\tvoid this.releaseOwnedSession(sessionId).catch((cause) => {\n\t\t\t\t\t\t\tprocess.stderr.write(\n\t\t\t\t\t\t\t\t`senpi rpc deferred release for session ${sessionId} failed: ${String(cause)}\\n`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tawait this.releaseOwnedSession(sessionId);\n\t\t\t}\n\t\t}\n\t\tthis.releasedConnections.delete(connectionId);\n\t}\n\n\t/**\n\t * One owned handle's refcounted close: the same sequence as an explicit\n\t * close_session, tolerant of races with other lifecycle paths (an entry\n\t * already closed or claimed elsewhere is simply skipped). Disposal and\n\t * binding removal happen only when this was the LAST attachment (the entry\n\t * transitioned to \"closing\"): surviving attachments keep the shared binding\n\t * and their event stream.\n\t */\n\tprivate async releaseOwnedSession(sessionId: string): Promise<void> {\n\t\t// A failed claim means the entry is already closed or owned by another path.\n\t\tconst claim = this.tryClaimClose(sessionId, { drainAttachments: false });\n\t\tif (!claim) return;\n\t\tif (claim.finalizer) await this.finalizeClose(sessionId, this.bindings.get(sessionId));\n\t\telse await this.finalizations.get(sessionId)?.promise;\n\t}\n\n\t/**\n\t * Releases one attachment (or every attachment when draining) and reports\n\t * whether this caller became the finalizer. The join token is installed inside\n\t * the registry callback, before any await, so a close that lands between the\n\t * claim and finalizeClose() always finds a token to wait on instead of\n\t * answering ahead of the terminal records.\n\t */\n\tprivate claimClose(sessionId: string, options: { drainAttachments: boolean }): { finalizer: boolean } {\n\t\tlet finalizer = true;\n\t\tconst onRole = (isFinalizer: boolean): void => {\n\t\t\tfinalizer = isFinalizer;\n\t\t\tif (isFinalizer && !this.finalizations.has(sessionId))\n\t\t\t\tthis.finalizations.set(sessionId, this.createFinalization());\n\t\t};\n\t\tlet entry = this.registry.beginClose(sessionId, onRole);\n\t\twhile (options.drainAttachments && entry.state === \"open\") entry = this.registry.beginClose(sessionId, onRole);\n\t\treturn { finalizer: finalizer && entry.state === \"closing\" };\n\t}\n\n\t/** claimClose() for lifecycle paths that treat a lost race as \"nothing to do\". */\n\tprivate tryClaimClose(\n\t\tsessionId: string,\n\t\toptions: { drainAttachments: boolean },\n\t): { finalizer: boolean } | undefined {\n\t\ttry {\n\t\t\treturn this.claimClose(sessionId, options);\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\tprivate async close(command: Extract<RpcCommand, { type: \"close_session\" }>): Promise<RpcResponse | undefined> {\n\t\t// This must be the first operation: binding.dispose() awaits teardown and\n\t\t// otherwise leaves a window where commands can enter the old handler.\n\t\tlet claim: { finalizer: boolean };\n\t\ttry {\n\t\t\tclaim = this.claimClose(command.sessionId, { drainAttachments: false });\n\t\t} catch (cause) {\n\t\t\treturn error(command.id, \"close_session\", this.code(cause));\n\t\t}\n\t\tconst response = {\n\t\t\tid: command.id,\n\t\t\ttype: \"response\" as const,\n\t\t\tcommand: \"close_session\" as const,\n\t\t\tsuccess: true as const,\n\t\t\tdata: {},\n\t\t};\n\t\tconst owner = this.writer.currentConnection();\n\t\tif (owner !== undefined) this.releaseOwnerAttachment(owner, command.sessionId);\n\t\tif (claim.finalizer) {\n\t\t\tawait this.finalizeClose(command.sessionId, this.bindings.get(command.sessionId), () =>\n\t\t\t\tthis.writer.closeSession(command.sessionId, response),\n\t\t\t);\n\t\t} else {\n\t\t\tawait this.finalizations.get(command.sessionId)?.promise;\n\t\t\tthis.writer.enqueueClosedResponse(command.sessionId, response);\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/** Detaches the closing connection's UI/width state; a rerender failure must not abort the close. */\n\tprivate releaseOwnerAttachment(owner: string, sessionId: string): void {\n\t\tthis.widths.get(sessionId)?.delete(owner);\n\t\tthis.writer.detachConnectionFromSession(owner, sessionId);\n\t\tfor (const binding of this.bindings.values()) {\n\t\t\ttry {\n\t\t\t\tbinding.rerenderComponents?.();\n\t\t\t} catch (cause) {\n\t\t\t\tprocess.stderr.write(`senpi rpc rerender after close of session ${sessionId} failed: ${String(cause)}\\n`);\n\t\t\t}\n\t\t}\n\t\tconst owned = this.sessionsByConnection.get(owner);\n\t\tconst count = owned?.get(sessionId);\n\t\tif (!owned || count === undefined) return;\n\t\tif (count === 1) owned.delete(sessionId);\n\t\telse owned.set(sessionId, count - 1);\n\t\tif (owned.size === 0) this.sessionsByConnection.delete(owner);\n\t}\n\n\t/**\n\t * Runs the finalizer side of a close for a handle whose beginClose() made this\n\t * caller the owner: dispose the binding, complete the registry teardown, emit\n\t * the terminal records, then release joiners. Every step is guarded so the join\n\t * token always resolves and a failing binding yields one logged line, never a\n\t * second response or an escaped rejection.\n\t */\n\tprivate async finalizeClose(\n\t\tsessionId: string,\n\t\tbinding: RpcSessionBinding | undefined,\n\t\tterminal?: () => void,\n\t): Promise<void> {\n\t\tconst finalization = this.finalizations.get(sessionId) ?? this.createFinalization();\n\t\tthis.finalizations.set(sessionId, finalization);\n\t\ttry {\n\t\t\ttry {\n\t\t\t\tawait binding?.dispose();\n\t\t\t} catch (cause) {\n\t\t\t\tprocess.stderr.write(`senpi rpc binding dispose for session ${sessionId} failed: ${String(cause)}\\n`);\n\t\t\t}\n\t\t\tthis.bindings.delete(sessionId);\n\t\t\ttry {\n\t\t\t\tawait this.registry.closeMarked(sessionId);\n\t\t\t} catch (cause) {\n\t\t\t\tprocess.stderr.write(`senpi rpc close for session ${sessionId} failed: ${String(cause)}\\n`);\n\t\t\t}\n\t\t\tterminal?.();\n\t\t} finally {\n\t\t\tfinalization.resolve();\n\t\t\tthis.finalizations.delete(sessionId);\n\t\t}\n\t}\n\n\tprivate createFinalization(): { promise: Promise<void>; resolve: () => void } {\n\t\tlet resolveFinalization: (() => void) | undefined;\n\t\tconst promise = new Promise<void>((resolve) => {\n\t\t\tresolveFinalization = resolve;\n\t\t});\n\t\treturn { promise, resolve: () => resolveFinalization?.() };\n\t}\n\n\tprivate code(cause: unknown): string {\n\t\tif (cause instanceof RpcSessionRegistryError) {\n\t\t\treturn cause.code === RPC_ERROR_OPEN_FAILED ? cause.message : cause.code;\n\t\t}\n\t\tif (cause instanceof Error && [RPC_ERROR_UNKNOWN_SESSION, RPC_ERROR_SESSION_CLOSING].includes(cause.message)) {\n\t\t\treturn cause.message;\n\t\t}\n\t\treturn cause instanceof Error && cause.message\n\t\t\t? `${RPC_ERROR_OPEN_FAILED}: ${cause.message}`\n\t\t\t: RPC_ERROR_UNKNOWN_SESSION;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"session-command-router.js","sourceRoot":"","sources":["../../../src/modes/rpc/session-command-router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,8BAA8B,EAAE,6BAA6B,EAAE,MAAM,wBAAwB,CAAC;AAEvG,OAAO,EACN,4BAA4B,EAC5B,qBAAqB,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AAE,EAAE,EAAE,CAAC;IAC5D,CAAC;IAEO,IAAI,CAAC,KAAc;QAC1B,IAAI,KAAK,YAAY,uBAAuB,EAAE,CAAC;YAC9C,OAAO,KAAK,CAAC,IAAI,KAAK,qBAAqB,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;QAC1E,CAAC;QACD,IAAI,KAAK,YAAY,KAAK,IAAI,CAAC,yBAAyB,EAAE,yBAAyB,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;YAC9G,OAAO,KAAK,CAAC,OAAO,CAAC;QACtB,CAAC;QACD,OAAO,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,OAAO;YAC7C,CAAC,CAAC,GAAG,qBAAqB,KAAK,KAAK,CAAC,OAAO,EAAE;YAC9C,CAAC,CAAC,yBAAyB,CAAC;IAC9B,CAAC;CACD","sourcesContent":["import { VERSION } from \"../../config.ts\";\nimport { buildRpcSessionState } from \"./connection-handler.ts\";\nimport { AUTO_TITLE_SESSIONS_CAPABILITY, MEDIA_PLACEHOLDERS_CAPABILITY } from \"./custom-capability.ts\";\nimport type { RpcCommand, RpcResponse } from \"./rpc-types.ts\";\nimport {\n\tRPC_ERROR_MISSING_SESSION_ID,\n\tRPC_ERROR_OPEN_FAILED,\n\tRPC_ERROR_SESSION_CLOSING,\n\tRPC_ERROR_UNKNOWN_SESSION,\n} from \"./rpc-types.ts\";\nimport { createRpcSessionBinding, type RpcSessionBinding } from \"./session-binding.ts\";\nimport type { SessionEventWriter } from \"./session-event-writer.ts\";\nimport type { OpenRpcSession, RpcSessionLaunchProfile, RpcSessionRegistry } from \"./session-registry.ts\";\nimport { RpcSessionRegistryError } from \"./session-registry.ts\";\n\nconst controls = new Set([\"get_protocol_info\", \"open_session\", \"close_session\", \"list_sessions\"]);\n\n/** Binding factory seam, injectable so host wiring is testable without a full runtime stack. */\nexport type RpcBindingFactory = typeof createRpcSessionBinding;\n\n/**\n * Occupancy policy for the shared multi-session host. All fields are opt-in:\n * a router constructed without a policy keeps today's behavior (sessions live\n * until close_session; the host never self-exits).\n */\nexport interface RpcSessionIdlePolicy {\n\t/** Injectable clock (defaults to Date.now) for deterministic tests. */\n\tnow?: () => number;\n\t/** Evict open sessions whose last routed command or session-owned work settled longer ago than this. */\n\tidleEvictionMs?: number;\n\t/** Invoke onEmptyExit once the registry has stayed empty for this long. */\n\temptyExitMs?: number;\n\t/** Host shutdown hook fired by the empty-exit window; called at most once. */\n\tonEmptyExit?: () => void;\n\t/**\n\t * Consulted every tick before the empty-exit window advances. Returning false\n\t * both blocks the exit and resets the window, so a host with a connected but\n\t * sessionless client stays up instead of exiting under its supervisor.\n\t */\n\tcanExitWhenEmpty?: () => boolean;\n}\n\nfunction error(id: string | undefined, command: string, code: string): RpcResponse {\n\treturn { id, type: \"response\", command, success: false, error: code };\n}\n\n/** Routes control messages and enforces a routing handle for every session command. */\nexport class SessionCommandRouter {\n\tprivate readonly bindings = new Map<string, RpcSessionBinding>();\n\t/** Session handles opened by each connection, with one count per attachment. */\n\tprivate readonly sessionsByConnection = new Map<string, Map<string, number>>();\n\t/** Opens currently awaiting runtime/binding setup, keyed by connection. */\n\tprivate readonly opensByConnection = new Map<string, Set<Promise<void>>>();\n\t/** Connections whose socket has already been detached. */\n\tprivate readonly releasedConnections = new Set<string>();\n\tprivate readonly registry: RpcSessionRegistry;\n\tprivate readonly writer: SessionEventWriter;\n\tprivate readonly defaults: Pick<\n\t\tRpcSessionLaunchProfile,\n\t\t\"cwd\" | \"permissionPreset\" | \"creationModel\" | \"initialThinkingLevel\"\n\t>;\n\tprivate readonly createBinding: typeof createRpcSessionBinding;\n\tprivate readonly connectionOptions: Parameters<typeof createRpcSessionBinding>[4];\n\tprivate readonly widths = new Map<string, Map<string, number>>();\n\tprivate readonly pendingCapabilities = new Map<string, string[]>();\n\tprivate readonly finalizations = new Map<string, { promise: Promise<void>; resolve: () => void }>();\n\tprivate readonly idleNow: () => number;\n\tprivate readonly idleEvictionMs: number;\n\tprivate readonly emptyExitMs: number;\n\tprivate readonly onEmptyExit?: () => void;\n\tprivate readonly canExitWhenEmpty?: () => boolean;\n\tprivate sweepTimer: ReturnType<typeof setInterval> | undefined;\n\tprivate emptySince: number | undefined;\n\n\tconstructor(\n\t\tregistry: RpcSessionRegistry,\n\t\twriter: SessionEventWriter,\n\t\tdefaults: Pick<RpcSessionLaunchProfile, \"cwd\" | \"permissionPreset\" | \"creationModel\" | \"initialThinkingLevel\">,\n\t\tcreateBinding: typeof createRpcSessionBinding = createRpcSessionBinding,\n\t\tconnectionOptions: Parameters<typeof createRpcSessionBinding>[4] = {},\n\t\tidle?: RpcSessionIdlePolicy,\n\t) {\n\t\tthis.registry = registry;\n\t\tthis.writer = writer;\n\t\tthis.defaults = defaults;\n\t\tthis.createBinding = createBinding;\n\t\tthis.connectionOptions = connectionOptions;\n\t\tthis.idleNow = idle?.now ?? Date.now;\n\t\tthis.idleEvictionMs = idle?.idleEvictionMs ?? Number.POSITIVE_INFINITY;\n\t\tthis.emptyExitMs = idle?.emptyExitMs ?? Number.POSITIVE_INFINITY;\n\t\tthis.onEmptyExit = idle?.onEmptyExit;\n\t\tthis.canExitWhenEmpty = idle?.canExitWhenEmpty;\n\t\tif (Number.isFinite(this.idleEvictionMs) || Number.isFinite(this.emptyExitMs)) {\n\t\t\t// Unref'd: occupancy hygiene must never be the reason the event loop stays open.\n\t\t\tconst tickMs = Math.max(20, Math.min(5_000, Math.min(this.idleEvictionMs, this.emptyExitMs) / 4));\n\t\t\tthis.sweepTimer = setInterval(() => this.sweepIdleSessions(), tickMs);\n\t\t\tthis.sweepTimer.unref?.();\n\t\t}\n\t}\n\n\tasync handle(command: RpcCommand): Promise<RpcResponse | undefined> {\n\t\tif (command.type === \"get_protocol_info\") {\n\t\t\tconst capabilities = new Set([\n\t\t\t\t\"multi_session\",\n\t\t\t\tAUTO_TITLE_SESSIONS_CAPABILITY,\n\t\t\t\tMEDIA_PLACEHOLDERS_CAPABILITY,\n\t\t\t\t...(this.connectionOptions?.capabilities ?? []),\n\t\t\t]);\n\t\t\treturn {\n\t\t\t\tid: command.id,\n\t\t\t\ttype: \"response\",\n\t\t\t\tcommand: \"get_protocol_info\",\n\t\t\t\tsuccess: true,\n\t\t\t\tdata: {\n\t\t\t\t\tprotocolVersion: 1,\n\t\t\t\t\tserverVersion: VERSION,\n\t\t\t\t\tcapabilities: [...capabilities],\n\t\t\t\t\tmode: \"multi\",\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\tif (command.type === \"list_sessions\")\n\t\t\treturn {\n\t\t\t\tid: command.id,\n\t\t\t\ttype: \"response\",\n\t\t\t\tcommand: \"list_sessions\",\n\t\t\t\tsuccess: true,\n\t\t\t\tdata: { sessions: this.registry.list() },\n\t\t\t};\n\t\tif (command.type === \"open_session\") return this.openWithBarrier(command);\n\t\tif (command.type === \"close_session\") return this.close(command);\n\t\tif (command.type === \"set_client_info\" && !command.sessionId) {\n\t\t\tconst connection = this.writer.currentConnection();\n\t\t\tif (connection !== undefined) {\n\t\t\t\tthis.pendingCapabilities.set(connection, command.capabilities ?? []);\n\t\t\t\tthis.writer.setConnectionCapabilities(connection, command.capabilities ?? []);\n\t\t\t}\n\t\t\treturn { id: command.id, type: \"response\", command: \"set_client_info\", success: true } as RpcResponse;\n\t\t}\n\t\tif (controls.has(command.type)) return undefined;\n\t\tif (!command.sessionId) return error(command.id, command.type, RPC_ERROR_MISSING_SESSION_ID);\n\t\ttry {\n\t\t\tthis.registry.getForCommand(command.sessionId, command.type);\n\t\t\tconst binding = this.bindings.get(command.sessionId);\n\t\t\tif (!binding) return error(command.id, command.type, RPC_ERROR_UNKNOWN_SESSION);\n\t\t\tawait binding.handle(command);\n\t\t\treturn undefined;\n\t\t} catch (cause) {\n\t\t\treturn error(command.id, command.type, this.code(cause));\n\t\t}\n\t}\n\n\tasync dispose(): Promise<void> {\n\t\tthis.stopSweep();\n\t\tawait Promise.all(\n\t\t\t[...this.bindings.entries()].map(async ([sessionId, binding]) => {\n\t\t\t\tconst claim = this.tryClaimClose(sessionId, { drainAttachments: true });\n\t\t\t\tif (!claim) return;\n\t\t\t\tif (claim.finalizer) await this.finalizeClose(sessionId, binding);\n\t\t\t\telse await this.finalizations.get(sessionId)?.promise;\n\t\t\t}),\n\t\t);\n\t\tthis.bindings.clear();\n\t}\n\n\t/**\n\t * One occupancy sweep. Evicts open sessions idle longer than idleEvictionMs,\n\t * where \"idle\" is the COMPLETE session-owned activity contract\n\t * (`AgentSession.isSessionBusy`: agent run, bash, background terminal jobs and\n\t * other published wake sources, compaction, barrier-held session work) - busy\n\t * sessions restart their idle clock instead, so work that outlives a turn is\n\t * never killed. Fires onEmptyExit once the registry has STAYED empty for\n\t * emptyExitMs with the exit permitted; any live session or connected client\n\t * resets that window. Runs on an unref'd interval and is safe to call directly.\n\t */\n\tsweepIdleSessions(): void {\n\t\tconst now = this.idleNow();\n\t\tif (Number.isFinite(this.idleEvictionMs)) {\n\t\t\tfor (const { sessionId, status } of this.registry.list()) {\n\t\t\t\tif (status !== \"open\") continue;\n\t\t\t\tconst entry = this.registry.peek(sessionId);\n\t\t\t\tif (!entry) continue;\n\t\t\t\tif (entry.runtime?.session.isSessionBusy) {\n\t\t\t\t\t// Session-owned work defers eviction; the window restarts when it settles.\n\t\t\t\t\tentry.lastCommandAt = now;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (now - entry.lastCommandAt >= this.idleEvictionMs) void this.evictIdleSession(sessionId);\n\t\t\t}\n\t\t}\n\t\tif (Number.isFinite(this.emptyExitMs)) {\n\t\t\tif (this.registry.size === 0 && (this.canExitWhenEmpty?.() ?? true)) {\n\t\t\t\tif (this.emptySince === undefined) this.emptySince = now;\n\t\t\t\telse if (now - this.emptySince >= this.emptyExitMs) {\n\t\t\t\t\tthis.stopSweep();\n\t\t\t\t\tthis.onEmptyExit?.();\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tthis.emptySince = undefined;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Idle-session eviction: the same refcounted close sequence as an explicit\n\t * close_session, draining every attachment because eviction ends the shared\n\t * session, not one client's claim. Races with concurrent lifecycle paths are\n\t * tolerated the same way releaseOwnedSession tolerates them.\n\t */\n\tprivate async evictIdleSession(sessionId: string): Promise<void> {\n\t\t// A failed claim means an explicit close raced us and owns the entry now.\n\t\tconst claim = this.tryClaimClose(sessionId, { drainAttachments: true });\n\t\tif (!claim) return;\n\t\tconst binding = this.bindings.get(sessionId);\n\t\tbinding?.cancelPendingExtensionUiRequests?.();\n\t\tthis.forgetSessionOwnership(sessionId);\n\t\tif (claim.finalizer) {\n\t\t\tawait this.finalizeClose(sessionId, binding, () =>\n\t\t\t\tthis.writer.closeSession(sessionId, {\n\t\t\t\t\ttype: \"response\",\n\t\t\t\t\tcommand: \"close_session\",\n\t\t\t\t\tsuccess: true,\n\t\t\t\t\tdata: {},\n\t\t\t\t}),\n\t\t\t);\n\t\t} else {\n\t\t\tawait this.finalizations.get(sessionId)?.promise;\n\t\t}\n\t\t// The runtime is disposed and routing handles are unique per process\n\t\t// epoch, so nothing can emit under this id again: drop the writer's\n\t\t// per-session bookkeeping instead of retaining it for the host's life.\n\t\tthis.writer.forgetSession(sessionId);\n\t}\n\n\t/** Drops per-connection records for a handle the host closed on its own. */\n\tprivate forgetSessionOwnership(sessionId: string): void {\n\t\tfor (const [connection, owned] of this.sessionsByConnection) {\n\t\t\towned.delete(sessionId);\n\t\t\tif (owned.size === 0) this.sessionsByConnection.delete(connection);\n\t\t}\n\t\tthis.widths.delete(sessionId);\n\t}\n\n\tprivate stopSweep(): void {\n\t\tif (this.sweepTimer === undefined) return;\n\t\tclearInterval(this.sweepTimer);\n\t\tthis.sweepTimer = undefined;\n\t}\n\n\tprivate openWithBarrier(command: Extract<RpcCommand, { type: \"open_session\" }>): Promise<RpcResponse | undefined> {\n\t\tconst owner = this.writer.currentConnection();\n\t\tif (owner === undefined) return this.open(command);\n\t\tlet resolveBarrier!: () => void;\n\t\tconst barrier = new Promise<void>((resolve) => {\n\t\t\tresolveBarrier = resolve;\n\t\t});\n\t\tconst opens = this.opensByConnection.get(owner) ?? new Set<Promise<void>>();\n\t\topens.add(barrier);\n\t\tthis.opensByConnection.set(owner, opens);\n\t\treturn this.open(command, owner).finally(() => {\n\t\t\tresolveBarrier();\n\t\t\topens.delete(barrier);\n\t\t\tif (opens.size === 0) this.opensByConnection.delete(owner);\n\t\t});\n\t}\n\n\tprivate async open(\n\t\tcommand: Extract<RpcCommand, { type: \"open_session\" }>,\n\t\towner?: string,\n\t): Promise<RpcResponse | undefined> {\n\t\tlet opened: OpenRpcSession | undefined;\n\t\ttry {\n\t\t\topened = await this.registry.openSession({\n\t\t\t\tcwd: command.cwd ?? this.defaults.cwd,\n\t\t\t\tsessionPath: command.sessionPath,\n\t\t\t\tpermissionPreset: command.permissionPreset ?? this.defaults.permissionPreset,\n\t\t\t\tcreationModel:\n\t\t\t\t\tcommand.provider && command.modelId\n\t\t\t\t\t\t? { provider: command.provider, modelId: command.modelId }\n\t\t\t\t\t\t: this.defaults.creationModel,\n\t\t\t\tinitialThinkingLevel: command.thinkingLevel ?? this.defaults.initialThinkingLevel,\n\t\t\t});\n\t\t\tconst openedSession = opened;\n\t\t\tconst entry = this.registry.getForCommand(openedSession.sessionId, \"open_session\");\n\t\t\tif (owner !== undefined) {\n\t\t\t\tif (!this.writer.hasRegisteredConnectionCapabilities(owner))\n\t\t\t\t\tthis.writer.setConnectionCapabilities(\n\t\t\t\t\t\towner,\n\t\t\t\t\t\tthis.pendingCapabilities.get(owner) ?? this.connectionOptions?.capabilities ?? [],\n\t\t\t\t\t);\n\t\t\t\tthis.writer.attachConnectionToSession(owner, openedSession.sessionId);\n\t\t\t}\n\t\t\t// A client that dies without close_session (terminal closed, SIGKILL, dropped\n\t\t\t// SSH) still holds this handle's attachment and its path reservation. Remember\n\t\t\t// which connection owns it so releaseConnection() can close exactly that.\n\t\t\tif (owner !== undefined) {\n\t\t\t\tconst owned = this.sessionsByConnection.get(owner) ?? new Map<string, number>();\n\t\t\t\towned.set(openedSession.sessionId, (owned.get(openedSession.sessionId) ?? 0) + 1);\n\t\t\t\tthis.sessionsByConnection.set(owner, owned);\n\t\t\t}\n\t\t\tif (!this.bindings.has(openedSession.sessionId)) {\n\t\t\t\tthis.bindings.set(\n\t\t\t\t\topenedSession.sessionId,\n\t\t\t\t\tawait this.createBinding(\n\t\t\t\t\t\topenedSession.sessionId,\n\t\t\t\t\t\tentry,\n\t\t\t\t\t\tthis.writer,\n\t\t\t\t\t\t() => void this.close({ type: \"close_session\", sessionId: openedSession.sessionId }),\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t...this.connectionOptions,\n\t\t\t\t\t\t\tcapabilities:\n\t\t\t\t\t\t\t\towner !== undefined\n\t\t\t\t\t\t\t\t\t? (this.pendingCapabilities.get(owner) ?? this.connectionOptions?.capabilities ?? [])\n\t\t\t\t\t\t\t\t\t: this.connectionOptions?.capabilities,\n\t\t\t\t\t\t\tsharedWidth: {\n\t\t\t\t\t\t\t\tgetWidth: () => {\n\t\t\t\t\t\t\t\t\tconst widths = this.widths.get(openedSession.sessionId);\n\t\t\t\t\t\t\t\t\treturn widths?.size ? Math.min(...widths.values()) : 80;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tsetWidth: (connectionId, width) => {\n\t\t\t\t\t\t\t\t\tif (connectionId !== undefined) {\n\t\t\t\t\t\t\t\t\t\tconst widths = this.widths.get(openedSession.sessionId) ?? new Map<string, number>();\n\t\t\t\t\t\t\t\t\t\twidths.set(connectionId, width);\n\t\t\t\t\t\t\t\t\t\tthis.widths.set(openedSession.sessionId, widths);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tclearWidth: (connectionId) => {\n\t\t\t\t\t\t\t\t\tconst widths = this.widths.get(openedSession.sessionId);\n\t\t\t\t\t\t\t\t\tif (connectionId !== undefined) widths?.delete(connectionId);\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tsetCapabilities: (connectionId, capabilities) => {\n\t\t\t\t\t\t\t\t\tif (connectionId !== undefined) {\n\t\t\t\t\t\t\t\t\t\tthis.writer.setConnectionCapabilities(connectionId, capabilities);\n\t\t\t\t\t\t\t\t\t\tthis.pendingCapabilities.set(connectionId, [...capabilities]);\n\t\t\t\t\t\t\t\t\t\tfor (const binding of this.bindings.values()) binding.rerenderComponents?.();\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\thasRenderedComponents: (sessionId) => this.writer.hasCapableConnection(sessionId),\n\n\t\t\t\t\t\t\t\tconnectionId: () => this.writer.currentConnection(),\n\t\t\t\t\t\t\t\tonChange: () => {\n\t\t\t\t\t\t\t\t\tfor (const binding of this.bindings.values()) binding.rerenderComponents?.();\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (owner !== undefined && this.releasedConnections.has(owner)) {\n\t\t\t\tawait this.releaseOwnedSession(openedSession.sessionId);\n\t\t\t}\n\t\t\tconst state = entry.runtime!.session;\n\t\t\tthis.writer.enqueue(opened.sessionId, {\n\t\t\t\tid: command.id,\n\t\t\t\ttype: \"response\",\n\t\t\t\tcommand: \"open_session\",\n\t\t\t\tsuccess: true,\n\t\t\t\tdata: {\n\t\t\t\t\tsessionId: opened.sessionId,\n\t\t\t\t\tstate: buildRpcSessionState(state),\n\t\t\t\t\t...(opened.attached ? { attached: true } : {}),\n\t\t\t\t},\n\t\t\t});\n\t\t\treturn undefined;\n\t\t} catch (cause) {\n\t\t\tif (opened) {\n\t\t\t\ttry {\n\t\t\t\t\tawait this.registry.close(opened.sessionId);\n\t\t\t\t} catch {\n\t\t\t\t\t/* The open rollback has already removed the entry. */\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn error(command.id, \"open_session\", this.code(cause));\n\t\t}\n\t}\n\n\t/**\n\t * Releases every session a dropped connection still owned. Each handle goes through\n\t * the same refcounted close as an explicit close_session, so a session another\n\t * connection is still attached to keeps running and only the last owner tears it down.\n\t */\n\tasync releaseConnection(connectionId: string): Promise<void> {\n\t\tthis.releasedConnections.add(connectionId);\n\t\tthis.writer.clearConnectionCapabilities(connectionId);\n\t\tfor (const sessionId of this.sessionsByConnection.get(connectionId)?.keys() ?? [])\n\t\t\tthis.writer.detachConnectionFromSession(connectionId, sessionId);\n\t\tfor (const widths of this.widths.values()) widths.delete(connectionId);\n\t\tfor (const binding of this.bindings.values()) binding.rerenderComponents?.();\n\t\tconst opens = this.opensByConnection.get(connectionId);\n\t\tif (opens) await Promise.all([...opens]);\n\t\tconst owned = this.sessionsByConnection.get(connectionId);\n\t\tthis.sessionsByConnection.delete(connectionId);\n\t\tif (owned === undefined) {\n\t\t\tthis.releasedConnections.delete(connectionId);\n\t\t\treturn;\n\t\t}\n\t\tfor (const [sessionId, count] of owned) {\n\t\t\tthis.bindings.get(sessionId)?.cancelPendingExtensionUiRequests?.();\n\t\t\tfor (let attachment = 0; attachment < count; attachment++) {\n\t\t\t\t// Headless completion contract: a turn survives its client's death and\n\t\t\t\t// runs to settlement (the host lifecycle keeps the process alive on\n\t\t\t\t// active turns even with zero connections). Releasing mid-turn aborts\n\t\t\t\t// the run and seals the session before agent_settled reaches the\n\t\t\t\t// lifecycle observer, leaking the busy counter so the host never\n\t\t\t\t// idle-exits. Defer - never skip - the release until the turn settles,\n\t\t\t\t// so the dropped owner's reservation still frees afterwards.\n\t\t\t\tconst live = this.registry.peek(sessionId);\n\t\t\t\tconst session = live?.state === \"open\" ? live.runtime?.session : undefined;\n\t\t\t\tif (session?.isStreaming) {\n\t\t\t\t\tlet released = false;\n\t\t\t\t\tconst unsubscribe = session.subscribe((event) => {\n\t\t\t\t\t\tif (event.type !== \"agent_settled\" && event.type !== \"agent_idle\") return;\n\t\t\t\t\t\tif (released) return;\n\t\t\t\t\t\treleased = true;\n\t\t\t\t\t\tunsubscribe();\n\t\t\t\t\t\tvoid this.releaseOwnedSession(sessionId).catch((cause) => {\n\t\t\t\t\t\t\tprocess.stderr.write(\n\t\t\t\t\t\t\t\t`senpi rpc deferred release for session ${sessionId} failed: ${String(cause)}\\n`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tawait this.releaseOwnedSession(sessionId);\n\t\t\t}\n\t\t}\n\t\tthis.releasedConnections.delete(connectionId);\n\t}\n\n\t/**\n\t * One owned handle's refcounted close: the same sequence as an explicit\n\t * close_session, tolerant of races with other lifecycle paths (an entry\n\t * already closed or claimed elsewhere is simply skipped). Disposal and\n\t * binding removal happen only when this was the LAST attachment (the entry\n\t * transitioned to \"closing\"): surviving attachments keep the shared binding\n\t * and their event stream.\n\t */\n\tprivate async releaseOwnedSession(sessionId: string): Promise<void> {\n\t\t// A failed claim means the entry is already closed or owned by another path.\n\t\tconst claim = this.tryClaimClose(sessionId, { drainAttachments: false });\n\t\tif (!claim) return;\n\t\tif (claim.finalizer) await this.finalizeClose(sessionId, this.bindings.get(sessionId));\n\t\telse await this.finalizations.get(sessionId)?.promise;\n\t}\n\n\t/**\n\t * Releases one attachment (or every attachment when draining) and reports\n\t * whether this caller became the finalizer. The join token is installed inside\n\t * the registry callback, before any await, so a close that lands between the\n\t * claim and finalizeClose() always finds a token to wait on instead of\n\t * answering ahead of the terminal records.\n\t */\n\tprivate claimClose(sessionId: string, options: { drainAttachments: boolean }): { finalizer: boolean } {\n\t\tlet finalizer = true;\n\t\tconst onRole = (isFinalizer: boolean): void => {\n\t\t\tfinalizer = isFinalizer;\n\t\t\tif (isFinalizer && !this.finalizations.has(sessionId))\n\t\t\t\tthis.finalizations.set(sessionId, this.createFinalization());\n\t\t};\n\t\tlet entry = this.registry.beginClose(sessionId, onRole);\n\t\twhile (options.drainAttachments && entry.state === \"open\") entry = this.registry.beginClose(sessionId, onRole);\n\t\treturn { finalizer: finalizer && entry.state === \"closing\" };\n\t}\n\n\t/** claimClose() for lifecycle paths that treat a lost race as \"nothing to do\". */\n\tprivate tryClaimClose(\n\t\tsessionId: string,\n\t\toptions: { drainAttachments: boolean },\n\t): { finalizer: boolean } | undefined {\n\t\ttry {\n\t\t\treturn this.claimClose(sessionId, options);\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\tprivate async close(command: Extract<RpcCommand, { type: \"close_session\" }>): Promise<RpcResponse | undefined> {\n\t\t// This must be the first operation: binding.dispose() awaits teardown and\n\t\t// otherwise leaves a window where commands can enter the old handler.\n\t\tlet claim: { finalizer: boolean };\n\t\ttry {\n\t\t\tclaim = this.claimClose(command.sessionId, { drainAttachments: false });\n\t\t} catch (cause) {\n\t\t\treturn error(command.id, \"close_session\", this.code(cause));\n\t\t}\n\t\tconst response = {\n\t\t\tid: command.id,\n\t\t\ttype: \"response\" as const,\n\t\t\tcommand: \"close_session\" as const,\n\t\t\tsuccess: true as const,\n\t\t\tdata: {},\n\t\t};\n\t\tconst owner = this.writer.currentConnection();\n\t\tif (owner !== undefined) this.releaseOwnerAttachment(owner, command.sessionId);\n\t\tif (claim.finalizer) {\n\t\t\tawait this.finalizeClose(command.sessionId, this.bindings.get(command.sessionId), () =>\n\t\t\t\tthis.writer.closeSession(command.sessionId, response),\n\t\t\t);\n\t\t} else {\n\t\t\tawait this.finalizations.get(command.sessionId)?.promise;\n\t\t\tthis.writer.enqueueClosedResponse(command.sessionId, response);\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/** Detaches the closing connection's UI/width state; a rerender failure must not abort the close. */\n\tprivate releaseOwnerAttachment(owner: string, sessionId: string): void {\n\t\tthis.widths.get(sessionId)?.delete(owner);\n\t\tthis.writer.detachConnectionFromSession(owner, sessionId);\n\t\tfor (const binding of this.bindings.values()) {\n\t\t\ttry {\n\t\t\t\tbinding.rerenderComponents?.();\n\t\t\t} catch (cause) {\n\t\t\t\tprocess.stderr.write(`senpi rpc rerender after close of session ${sessionId} failed: ${String(cause)}\\n`);\n\t\t\t}\n\t\t}\n\t\tconst owned = this.sessionsByConnection.get(owner);\n\t\tconst count = owned?.get(sessionId);\n\t\tif (!owned || count === undefined) return;\n\t\tif (count === 1) owned.delete(sessionId);\n\t\telse owned.set(sessionId, count - 1);\n\t\tif (owned.size === 0) this.sessionsByConnection.delete(owner);\n\t}\n\n\t/**\n\t * Runs the finalizer side of a close for a handle whose beginClose() made this\n\t * caller the owner: dispose the binding, complete the registry teardown, emit\n\t * the terminal records, then release joiners. Every step is guarded so the join\n\t * token always resolves and a failing binding yields one logged line, never a\n\t * second response or an escaped rejection.\n\t */\n\tprivate async finalizeClose(\n\t\tsessionId: string,\n\t\tbinding: RpcSessionBinding | undefined,\n\t\tterminal?: () => void,\n\t): Promise<void> {\n\t\tconst finalization = this.finalizations.get(sessionId) ?? this.createFinalization();\n\t\tthis.finalizations.set(sessionId, finalization);\n\t\ttry {\n\t\t\ttry {\n\t\t\t\tawait binding?.dispose();\n\t\t\t} catch (cause) {\n\t\t\t\tprocess.stderr.write(`senpi rpc binding dispose for session ${sessionId} failed: ${String(cause)}\\n`);\n\t\t\t}\n\t\t\tthis.bindings.delete(sessionId);\n\t\t\ttry {\n\t\t\t\tawait this.registry.closeMarked(sessionId);\n\t\t\t} catch (cause) {\n\t\t\t\tprocess.stderr.write(`senpi rpc close for session ${sessionId} failed: ${String(cause)}\\n`);\n\t\t\t}\n\t\t\tterminal?.();\n\t\t} finally {\n\t\t\tfinalization.resolve();\n\t\t\tthis.finalizations.delete(sessionId);\n\t\t}\n\t}\n\n\tprivate createFinalization(): { promise: Promise<void>; resolve: () => void } {\n\t\tlet resolveFinalization: (() => void) | undefined;\n\t\tconst promise = new Promise<void>((resolve) => {\n\t\t\tresolveFinalization = resolve;\n\t\t});\n\t\treturn { promise, resolve: () => resolveFinalization?.() };\n\t}\n\n\tprivate code(cause: unknown): string {\n\t\tif (cause instanceof RpcSessionRegistryError) {\n\t\t\treturn cause.code === RPC_ERROR_OPEN_FAILED ? cause.message : cause.code;\n\t\t}\n\t\tif (cause instanceof Error && [RPC_ERROR_UNKNOWN_SESSION, RPC_ERROR_SESSION_CLOSING].includes(cause.message)) {\n\t\t\treturn cause.message;\n\t\t}\n\t\treturn cause instanceof Error && cause.message\n\t\t\t? `${RPC_ERROR_OPEN_FAILED}: ${cause.message}`\n\t\t\t: RPC_ERROR_UNKNOWN_SESSION;\n\t}\n}\n"]}
|
|
@@ -4,6 +4,13 @@ export type BackpressureWaiter = () => Promise<void>;
|
|
|
4
4
|
export interface SessionEventWriterConnection {
|
|
5
5
|
readonly writeRaw: RawWriter;
|
|
6
6
|
readonly waitForBackpressure: BackpressureWaiter;
|
|
7
|
+
/**
|
|
8
|
+
* Tears the transport down. Called when this connection's event queue fails
|
|
9
|
+
* (overflow, write error): the actor has already stopped delivering records
|
|
10
|
+
* AND command responses, so a socket left open would strand the client on a
|
|
11
|
+
* connection that can never answer again. Closing it lets the client resync.
|
|
12
|
+
*/
|
|
13
|
+
readonly close?: () => void;
|
|
7
14
|
}
|
|
8
15
|
export declare const RENDERED_COMPONENT_RECORD = "__senpiRenderedComponent";
|
|
9
16
|
type RegisteredConnection = {
|
|
@@ -16,7 +23,9 @@ export declare class SessionEventFanout {
|
|
|
16
23
|
private readonly connectionCapabilities;
|
|
17
24
|
private readonly connectionSessions;
|
|
18
25
|
private readonly registeredCapabilityConnections;
|
|
19
|
-
registerConnection(id: string, connection: SessionEventWriterConnection
|
|
26
|
+
registerConnection(id: string, connection: SessionEventWriterConnection, options?: {
|
|
27
|
+
readonly maxQueueBytes?: number;
|
|
28
|
+
}): void;
|
|
20
29
|
unregisterConnection(id: string): void;
|
|
21
30
|
attachConnectionToSession(id: string, sessionId: string): void;
|
|
22
31
|
detachConnectionFromSession(id: string, sessionId: string): void;
|
|
@@ -25,13 +34,15 @@ export declare class SessionEventFanout {
|
|
|
25
34
|
hasRegisteredConnectionCapabilities(id: string): boolean;
|
|
26
35
|
getConnectionCapabilities(id: string): readonly string[] | undefined;
|
|
27
36
|
hasCapableConnection(sessionId: string): boolean;
|
|
37
|
+
/** Whether a connection advertised a capability. The only capability lookup in this file. */
|
|
38
|
+
connectionHas(id: string | undefined, capability: string): boolean;
|
|
28
39
|
targets(sessionId: string, targetId: string | undefined, isTargeted: boolean, rendered: boolean, recordType: unknown): readonly (string | undefined)[];
|
|
29
40
|
get(id: string): RegisteredConnection | undefined;
|
|
30
41
|
values(): IterableIterator<RegisteredConnection>;
|
|
31
42
|
/** True when no socket connection is registered, i.e. records must fall back to the stdio lane. */
|
|
32
43
|
isEmpty(): boolean;
|
|
33
44
|
broadcast(line: string): void;
|
|
34
|
-
rememberSnapshot(sessionId: string, value: Record<string, unknown>, line: string): void;
|
|
45
|
+
rememberSnapshot(sessionId: string, value: Record<string, unknown>, line: string, placeholderLine?: string, source?: Record<string, unknown>): void;
|
|
35
46
|
forgetSession(sessionId: string): void;
|
|
36
47
|
private replaySnapshot;
|
|
37
48
|
private replayRendered;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-event-fanout.d.ts","sourceRoot":"","sources":["../../../src/modes/rpc/session-event-fanout.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"session-event-fanout.d.ts","sourceRoot":"","sources":["../../../src/modes/rpc/session-event-fanout.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAEhE,MAAM,MAAM,SAAS,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;AAChD,MAAM,MAAM,kBAAkB,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;AAErD,MAAM,WAAW,4BAA4B;IAC5C,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;IAC7B,QAAQ,CAAC,mBAAmB,EAAE,kBAAkB,CAAC;IACjD;;;;;OA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AAE,UAAU,EAAE,MAAM,GAAG,OAAO;IAIlE,OAAO,CACN,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,UAAU,EAAE,OAAO,EACnB,QAAQ,EAAE,OAAO,EACjB,UAAU,EAAE,OAAO,GACjB,SAAS,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE;IAiBlC,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,oBAAoB,GAAG,SAAS;IAIjD,MAAM,IAAI,gBAAgB,CAAC,oBAAoB,CAAC;IAIhD,mGAAmG;IACnG,OAAO,IAAI,OAAO;IAIlB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAI7B,gBAAgB,CACf,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,IAAI,EAAE,MAAM,EACZ,eAAe,CAAC,EAAE,MAAM,EACxB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,IAAI;IAgBP,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAItC,OAAO,CAAC,cAAc;IAStB,OAAO,CAAC,cAAc;CAKtB"}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { MEDIA_PLACEHOLDERS_CAPABILITY, RENDERED_COMPONENTS_CAPABILITY } from "./custom-capability.js";
|
|
2
|
+
import { serializeJsonLine } from "./jsonl.js";
|
|
3
|
+
import { omitInlineMedia } from "./media-placeholders.js";
|
|
1
4
|
import { SocketEventSinkActor } from "./socket-event-fanout.js";
|
|
2
5
|
export const RENDERED_COMPONENT_RECORD = "__senpiRenderedComponent";
|
|
3
6
|
const BROADCAST_LIFECYCLE_RECORDS = new Set([
|
|
@@ -7,6 +10,15 @@ const BROADCAST_LIFECYCLE_RECORDS = new Set([
|
|
|
7
10
|
"session_opened",
|
|
8
11
|
"session_closed",
|
|
9
12
|
]);
|
|
13
|
+
/** The placeholder variant of a remembered record, derived and memoized on first use. */
|
|
14
|
+
function snapshotPlaceholderLine(record) {
|
|
15
|
+
if (record.placeholderLine !== undefined)
|
|
16
|
+
return record.placeholderLine;
|
|
17
|
+
const redacted = record.source === undefined ? undefined : omitInlineMedia(record.source);
|
|
18
|
+
record.placeholderLine =
|
|
19
|
+
redacted === undefined || redacted === record.source ? record.line : serializeJsonLine(redacted);
|
|
20
|
+
return record.placeholderLine;
|
|
21
|
+
}
|
|
10
22
|
export class SessionEventFanout {
|
|
11
23
|
constructor() {
|
|
12
24
|
this.connections = new Map();
|
|
@@ -15,15 +27,17 @@ export class SessionEventFanout {
|
|
|
15
27
|
this.connectionSessions = new Map();
|
|
16
28
|
this.registeredCapabilityConnections = new Set();
|
|
17
29
|
}
|
|
18
|
-
registerConnection(id, connection) {
|
|
19
|
-
const actor = new SocketEventSinkActor(connection, () => {
|
|
30
|
+
registerConnection(id, connection, options = {}) {
|
|
31
|
+
const actor = new SocketEventSinkActor(connection, (cause) => {
|
|
20
32
|
if (this.connections.get(id)?.actor === actor) {
|
|
21
33
|
this.connections.delete(id);
|
|
22
34
|
this.connectionCapabilities.delete(id);
|
|
23
35
|
this.connectionSessions.delete(id);
|
|
24
36
|
this.registeredCapabilityConnections.delete(id);
|
|
25
37
|
}
|
|
26
|
-
|
|
38
|
+
process.stderr.write(`senpi rpc connection ${id} event queue failed; closing: ${cause instanceof Error ? cause.message : String(cause)}\n`);
|
|
39
|
+
connection.close?.();
|
|
40
|
+
}, options.maxQueueBytes);
|
|
27
41
|
this.connections.set(id, { connection, actor });
|
|
28
42
|
this.connectionCapabilities.set(id, new Set());
|
|
29
43
|
this.connectionSessions.set(id, new Set());
|
|
@@ -55,10 +69,10 @@ export class SessionEventFanout {
|
|
|
55
69
|
const registered = this.connections.get(id);
|
|
56
70
|
if (!registered)
|
|
57
71
|
return;
|
|
58
|
-
const wasCapable = this.connectionCapabilities.get(id)?.has(
|
|
72
|
+
const wasCapable = this.connectionCapabilities.get(id)?.has(RENDERED_COMPONENTS_CAPABILITY) ?? false;
|
|
59
73
|
this.connectionCapabilities.set(id, new Set(capabilities));
|
|
60
74
|
this.registeredCapabilityConnections.add(id);
|
|
61
|
-
if (!wasCapable && capabilities.includes(
|
|
75
|
+
if (!wasCapable && capabilities.includes(RENDERED_COMPONENTS_CAPABILITY))
|
|
62
76
|
for (const sessionId of this.connectionSessions.get(id) ?? [])
|
|
63
77
|
this.replayRendered(id, sessionId);
|
|
64
78
|
}
|
|
@@ -77,11 +91,15 @@ export class SessionEventFanout {
|
|
|
77
91
|
return [...(this.connectionCapabilities.get(id) ?? [])];
|
|
78
92
|
}
|
|
79
93
|
hasCapableConnection(sessionId) {
|
|
80
|
-
for (const
|
|
81
|
-
if (
|
|
94
|
+
for (const id of this.connectionCapabilities.keys())
|
|
95
|
+
if (this.connectionHas(id, RENDERED_COMPONENTS_CAPABILITY) && this.connectionSessions.get(id)?.has(sessionId))
|
|
82
96
|
return true;
|
|
83
97
|
return false;
|
|
84
98
|
}
|
|
99
|
+
/** Whether a connection advertised a capability. The only capability lookup in this file. */
|
|
100
|
+
connectionHas(id, capability) {
|
|
101
|
+
return id === undefined ? false : (this.connectionCapabilities.get(id)?.has(capability) ?? false);
|
|
102
|
+
}
|
|
85
103
|
targets(sessionId, targetId, isTargeted, rendered, recordType) {
|
|
86
104
|
if (isTargeted)
|
|
87
105
|
return [targetId];
|
|
@@ -89,7 +107,7 @@ export class SessionEventFanout {
|
|
|
89
107
|
return this.connections.size > 0 ? [...this.connections.keys()] : [undefined];
|
|
90
108
|
if (rendered)
|
|
91
109
|
return this.connections.size > 0
|
|
92
|
-
? [...this.connections.keys()].filter((id) => this.
|
|
110
|
+
? [...this.connections.keys()].filter((id) => this.connectionHas(id, RENDERED_COMPONENTS_CAPABILITY) &&
|
|
93
111
|
this.connectionSessions.get(id)?.has(sessionId))
|
|
94
112
|
: [undefined];
|
|
95
113
|
return this.connections.size > 0
|
|
@@ -110,9 +128,14 @@ export class SessionEventFanout {
|
|
|
110
128
|
for (const { actor } of this.connections.values())
|
|
111
129
|
actor.enqueue(line);
|
|
112
130
|
}
|
|
113
|
-
rememberSnapshot(sessionId, value, line) {
|
|
131
|
+
rememberSnapshot(sessionId, value, line, placeholderLine, source) {
|
|
114
132
|
const event = value.assistantMessageEvent;
|
|
115
|
-
const record = {
|
|
133
|
+
const record = {
|
|
134
|
+
line,
|
|
135
|
+
placeholderLine,
|
|
136
|
+
source,
|
|
137
|
+
rendered: value[RENDERED_COMPONENT_RECORD] === true,
|
|
138
|
+
};
|
|
116
139
|
if (value.type === "message_start" || (value.type === "message_update" && event?.type === "text_start")) {
|
|
117
140
|
this.sessionSnapshots.set(sessionId, [record]);
|
|
118
141
|
}
|
|
@@ -129,10 +152,11 @@ export class SessionEventFanout {
|
|
|
129
152
|
const actor = this.connections.get(id)?.actor;
|
|
130
153
|
if (!actor)
|
|
131
154
|
return;
|
|
132
|
-
const capable = this.
|
|
155
|
+
const capable = this.connectionHas(id, RENDERED_COMPONENTS_CAPABILITY);
|
|
156
|
+
const placeholders = this.connectionHas(id, MEDIA_PLACEHOLDERS_CAPABILITY);
|
|
133
157
|
for (const record of this.sessionSnapshots.get(sessionId) ?? [])
|
|
134
158
|
if (!record.rendered || capable)
|
|
135
|
-
actor.enqueue(record.line);
|
|
159
|
+
actor.enqueue(placeholders ? snapshotPlaceholderLine(record) : record.line);
|
|
136
160
|
}
|
|
137
161
|
replayRendered(id, sessionId) {
|
|
138
162
|
const actor = this.connections.get(id)?.actor;
|