@earendil-works/pi-coding-agent 0.84.4 → 0.85.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +57 -5
- package/README.md +3 -1
- package/dist/bun/cli.d.ts.map +1 -1
- package/dist/bun/cli.js +10 -7
- package/dist/bun/cli.js.map +1 -1
- package/dist/bun/runtime-setup.d.ts +2 -0
- package/dist/bun/runtime-setup.d.ts.map +1 -0
- package/dist/bun/runtime-setup.js +9 -0
- package/dist/bun/runtime-setup.js.map +1 -0
- package/dist/bundle/chunks/anthropic-messages-QAQLEQIY.js +6 -0
- package/dist/bundle/chunks/{azure-openai-responses-5ENVCQ7U.js → azure-openai-responses-Q7MJBRE6.js} +1 -1
- package/dist/bundle/chunks/bedrock-converse-stream.js +1 -1
- package/dist/bundle/chunks/chunk-7ZC4UXSL.js +2 -0
- package/dist/bundle/chunks/chunk-EQ6DR6XK.js +5 -0
- package/dist/bundle/chunks/{chunk-MNAIPA3J.js → chunk-IDDQWTHI.js} +1 -1
- package/dist/bundle/chunks/chunk-LZKJTKCT.js +2 -0
- package/dist/bundle/chunks/{chunk-NBBFIJUL.js → chunk-OUXLLA64.js} +2 -2
- package/dist/bundle/chunks/chunk-R7UUJ4C2.js +42 -0
- package/dist/bundle/chunks/chunk-USJZMAIR.js +2 -0
- package/dist/bundle/chunks/chunk-WBE4J4AU.js +9 -0
- package/dist/bundle/chunks/chunk-WZB2R5YO.js +1558 -0
- package/dist/bundle/chunks/github-copilot.js +1 -1
- package/dist/bundle/chunks/{google-generative-ai-YMUPJBKR.js → google-generative-ai-BSMTYDAM.js} +1 -1
- package/dist/bundle/chunks/{google-vertex-MPWMV4OF.js → google-vertex-5C3HASOJ.js} +1 -1
- package/dist/bundle/chunks/image-resize-worker.js +1 -1
- package/dist/bundle/chunks/{mistral-conversations-Q3AWZJAZ.js → mistral-conversations-4M6BZBX6.js} +1 -1
- package/dist/bundle/chunks/node-EM5FIVUN.js +16 -0
- package/dist/bundle/chunks/node-TWVVAGPO.js +2 -0
- package/dist/bundle/chunks/openai-codex-responses-YJOO52RW.js +10 -0
- package/dist/bundle/chunks/{openai-completions-ERMU2SS7.js → openai-completions-QOT3QX7D.js} +3 -3
- package/dist/bundle/chunks/openai-responses-U7LNPQN4.js +2 -0
- package/dist/bundle/chunks/{pi-messages-TPFH44NP.js → pi-messages-EGZIFQGG.js} +1 -1
- package/dist/bundle/cli.js +1 -1
- package/dist/bundle/client.js +1 -1
- package/dist/bundle/coordinator.js +3 -0
- package/dist/bundle/index.js +1 -1
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +2 -0
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/config-selector.d.ts.map +1 -1
- package/dist/cli/config-selector.js +2 -1
- package/dist/cli/config-selector.js.map +1 -1
- package/dist/cli/experimental/cli.d.ts +7 -3
- package/dist/cli/experimental/cli.d.ts.map +1 -1
- package/dist/cli/experimental/cli.js +6 -2
- package/dist/cli/experimental/cli.js.map +1 -1
- package/dist/cli/experimental/command-options.d.ts +23 -12
- package/dist/cli/experimental/command-options.d.ts.map +1 -1
- package/dist/cli/experimental/command-options.js +69 -20
- package/dist/cli/experimental/command-options.js.map +1 -1
- package/dist/cli/experimental/command.d.ts +10 -3
- package/dist/cli/experimental/command.d.ts.map +1 -1
- package/dist/cli/experimental/command.js +28 -14
- package/dist/cli/experimental/command.js.map +1 -1
- package/dist/cli/experimental/commands/client.d.ts +8 -2
- package/dist/cli/experimental/commands/client.d.ts.map +1 -1
- package/dist/cli/experimental/commands/client.js +43 -5
- package/dist/cli/experimental/commands/client.js.map +1 -1
- package/dist/cli/experimental/commands/server.d.ts +7 -3
- package/dist/cli/experimental/commands/server.d.ts.map +1 -1
- package/dist/cli/experimental/commands/server.js +27 -8
- package/dist/cli/experimental/commands/server.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +23 -14
- package/dist/cli.js.map +1 -1
- package/dist/client/index.d.ts +1 -2
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +1 -2
- package/dist/client/index.js.map +1 -1
- package/dist/config.d.ts +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -0
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +15 -7
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session.d.ts +2 -6
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +14 -6
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/compaction/branch-summarization.d.ts +1 -1
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +2 -1
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +1 -2
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/types.d.ts +8 -2
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/http-dispatcher.d.ts.map +1 -1
- package/dist/core/http-dispatcher.js +2 -0
- package/dist/core/http-dispatcher.js.map +1 -1
- package/dist/core/messages.d.ts +1 -1
- package/dist/core/messages.d.ts.map +1 -1
- package/dist/core/messages.js.map +1 -1
- package/dist/core/model-config.d.ts +15 -0
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +3 -0
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/model-runtime.d.ts +1 -0
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +5 -2
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/provider-composer.d.ts.map +1 -1
- package/dist/core/provider-composer.js +8 -2
- package/dist/core/provider-composer.js.map +1 -1
- package/dist/core/session-manager.d.ts +3 -2
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +40 -13
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/skills.d.ts +1 -1
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +4 -2
- package/dist/core/skills.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +8 -9
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +3 -117
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit.d.ts +1 -12
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +5 -163
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +4 -55
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +4 -60
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js +4 -49
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +4 -120
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/renderers/bash.d.ts +12 -0
- package/dist/core/tools/renderers/bash.d.ts.map +1 -0
- package/dist/core/tools/renderers/bash.js +130 -0
- package/dist/core/tools/renderers/bash.js.map +1 -0
- package/dist/core/tools/renderers/edit.d.ts +23 -0
- package/dist/core/tools/renderers/edit.d.ts.map +1 -0
- package/dist/core/tools/renderers/edit.js +167 -0
- package/dist/core/tools/renderers/edit.js.map +1 -0
- package/dist/core/tools/renderers/find.d.ts +10 -0
- package/dist/core/tools/renderers/find.d.ts.map +1 -0
- package/dist/core/tools/renderers/find.js +64 -0
- package/dist/core/tools/renderers/find.js.map +1 -0
- package/dist/core/tools/renderers/grep.d.ts +10 -0
- package/dist/core/tools/renderers/grep.d.ts.map +1 -0
- package/dist/core/tools/renderers/grep.js +69 -0
- package/dist/core/tools/renderers/grep.js.map +1 -0
- package/dist/core/tools/renderers/index.d.ts +28 -0
- package/dist/core/tools/renderers/index.d.ts.map +1 -0
- package/dist/core/tools/renderers/index.js +47 -0
- package/dist/core/tools/renderers/index.js.map +1 -0
- package/dist/core/tools/renderers/ls.d.ts +10 -0
- package/dist/core/tools/renderers/ls.d.ts.map +1 -0
- package/dist/core/tools/renderers/ls.js +58 -0
- package/dist/core/tools/renderers/ls.js.map +1 -0
- package/dist/core/tools/renderers/read.d.ts +11 -0
- package/dist/core/tools/renderers/read.d.ts.map +1 -0
- package/dist/core/tools/renderers/read.js +129 -0
- package/dist/core/tools/renderers/read.js.map +1 -0
- package/dist/core/tools/renderers/write.d.ts +10 -0
- package/dist/core/tools/renderers/write.d.ts.map +1 -0
- package/dist/core/tools/renderers/write.js +153 -0
- package/dist/core/tools/renderers/write.js.map +1 -0
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +5 -146
- package/dist/core/tools/write.js.map +1 -1
- package/dist/experimental/client-runtime.d.ts +43 -0
- package/dist/experimental/client-runtime.d.ts.map +1 -0
- package/dist/experimental/client-runtime.js +183 -0
- package/dist/experimental/client-runtime.js.map +1 -0
- package/dist/experimental/client-tui-chat.d.ts +14 -0
- package/dist/experimental/client-tui-chat.d.ts.map +1 -0
- package/dist/experimental/client-tui-chat.js +171 -0
- package/dist/experimental/client-tui-chat.js.map +1 -0
- package/dist/experimental/client-tui.d.ts +37 -0
- package/dist/experimental/client-tui.d.ts.map +1 -0
- package/dist/experimental/client-tui.js +702 -0
- package/dist/experimental/client-tui.js.map +1 -0
- package/dist/experimental/client.d.ts +25 -0
- package/dist/experimental/client.d.ts.map +1 -0
- package/dist/experimental/client.js +99 -0
- package/dist/experimental/client.js.map +1 -0
- package/dist/experimental/coordinator-entry.d.ts +3 -0
- package/dist/experimental/coordinator-entry.d.ts.map +1 -0
- package/dist/experimental/coordinator-entry.js +11 -0
- package/dist/experimental/coordinator-entry.js.map +1 -0
- package/dist/experimental/coordinator.d.ts +38 -0
- package/dist/experimental/coordinator.d.ts.map +1 -0
- package/dist/experimental/coordinator.js +570 -0
- package/dist/experimental/coordinator.js.map +1 -0
- package/dist/experimental/mini/main.d.ts +7 -0
- package/dist/experimental/mini/main.d.ts.map +1 -0
- package/dist/experimental/mini/main.js +21 -0
- package/dist/experimental/mini/main.js.map +1 -0
- package/dist/experimental/mini/server/entry.d.ts +3 -0
- package/dist/experimental/mini/server/entry.d.ts.map +1 -0
- package/dist/experimental/mini/server/entry.js +11 -0
- package/dist/experimental/mini/server/entry.js.map +1 -0
- package/dist/experimental/mini/server/run.d.ts +13 -0
- package/dist/experimental/mini/server/run.d.ts.map +1 -0
- package/dist/experimental/mini/server/run.js +150 -0
- package/dist/experimental/mini/server/run.js.map +1 -0
- package/dist/experimental/mini/shared/protocol.d.ts +127 -0
- package/dist/experimental/mini/shared/protocol.d.ts.map +1 -0
- package/dist/experimental/mini/shared/protocol.js +13 -0
- package/dist/experimental/mini/shared/protocol.js.map +1 -0
- package/dist/experimental/mini/shared/rpc.d.ts +49 -0
- package/dist/experimental/mini/shared/rpc.d.ts.map +1 -0
- package/dist/experimental/mini/shared/rpc.js +171 -0
- package/dist/experimental/mini/shared/rpc.js.map +1 -0
- package/dist/experimental/mini/shared/transport.d.ts +35 -0
- package/dist/experimental/mini/shared/transport.d.ts.map +1 -0
- package/dist/experimental/mini/shared/transport.js +94 -0
- package/dist/experimental/mini/shared/transport.js.map +1 -0
- package/dist/experimental/mini/tui/run.d.ts +9 -0
- package/dist/experimental/mini/tui/run.d.ts.map +1 -0
- package/dist/experimental/mini/tui/run.js +62 -0
- package/dist/experimental/mini/tui/run.js.map +1 -0
- package/dist/experimental/mini/tui/session.d.ts +26 -0
- package/dist/experimental/mini/tui/session.d.ts.map +1 -0
- package/dist/experimental/mini/tui/session.js +94 -0
- package/dist/experimental/mini/tui/session.js.map +1 -0
- package/dist/experimental/mini/tui/view.d.ts +10 -0
- package/dist/experimental/mini/tui/view.d.ts.map +1 -0
- package/dist/experimental/mini/tui/view.js +459 -0
- package/dist/experimental/mini/tui/view.js.map +1 -0
- package/dist/experimental/mini/worker/entry.d.ts +3 -0
- package/dist/experimental/mini/worker/entry.d.ts.map +1 -0
- package/dist/experimental/mini/worker/entry.js +10 -0
- package/dist/experimental/mini/worker/entry.js.map +1 -0
- package/dist/experimental/mini/worker/lane-service.d.ts +44 -0
- package/dist/experimental/mini/worker/lane-service.d.ts.map +1 -0
- package/dist/experimental/mini/worker/lane-service.js +97 -0
- package/dist/experimental/mini/worker/lane-service.js.map +1 -0
- package/dist/experimental/mini/worker/models-service.d.ts +19 -0
- package/dist/experimental/mini/worker/models-service.d.ts.map +1 -0
- package/dist/experimental/mini/worker/models-service.js +136 -0
- package/dist/experimental/mini/worker/models-service.js.map +1 -0
- package/dist/experimental/mini/worker/run.d.ts +14 -0
- package/dist/experimental/mini/worker/run.d.ts.map +1 -0
- package/dist/experimental/mini/worker/run.js +88 -0
- package/dist/experimental/mini/worker/run.js.map +1 -0
- package/dist/experimental/plugin.d.ts +4 -0
- package/dist/experimental/plugin.d.ts.map +1 -0
- package/dist/experimental/plugin.js +4 -0
- package/dist/experimental/plugin.js.map +1 -0
- package/dist/experimental/plugins/bundled.d.ts +7 -0
- package/dist/experimental/plugins/bundled.d.ts.map +1 -0
- package/dist/experimental/plugins/bundled.js +48 -0
- package/dist/experimental/plugins/bundled.js.map +1 -0
- package/dist/experimental/plugins/package.d.ts +18 -0
- package/dist/experimental/plugins/package.d.ts.map +1 -0
- package/dist/experimental/plugins/package.js +113 -0
- package/dist/experimental/plugins/package.js.map +1 -0
- package/dist/experimental/process.d.ts +20 -0
- package/dist/experimental/process.d.ts.map +1 -0
- package/dist/experimental/process.js +85 -0
- package/dist/experimental/process.js.map +1 -0
- package/dist/experimental/radius-auth.d.ts +17 -0
- package/dist/experimental/radius-auth.d.ts.map +1 -0
- package/dist/experimental/radius-auth.js +52 -0
- package/dist/experimental/radius-auth.js.map +1 -0
- package/dist/experimental/radius-relay.d.ts +90 -0
- package/dist/experimental/radius-relay.d.ts.map +1 -0
- package/dist/experimental/radius-relay.js +582 -0
- package/dist/experimental/radius-relay.js.map +1 -0
- package/dist/experimental/server.d.ts +75 -0
- package/dist/experimental/server.d.ts.map +1 -0
- package/dist/experimental/server.js +682 -0
- package/dist/experimental/server.js.map +1 -0
- package/dist/experimental/services/agent-controller-provider.d.ts +4 -0
- package/dist/experimental/services/agent-controller-provider.d.ts.map +1 -0
- package/dist/experimental/services/agent-controller-provider.js +84 -0
- package/dist/experimental/services/agent-controller-provider.js.map +1 -0
- package/dist/experimental/services/agent-controller.d.ts +57 -0
- package/dist/experimental/services/agent-controller.d.ts.map +1 -0
- package/dist/experimental/services/agent-controller.js +3 -0
- package/dist/experimental/services/agent-controller.js.map +1 -0
- package/dist/experimental/services/connection.d.ts +40 -0
- package/dist/experimental/services/connection.d.ts.map +1 -0
- package/dist/experimental/services/connection.js +300 -0
- package/dist/experimental/services/connection.js.map +1 -0
- package/dist/experimental/services/models-provider.d.ts +16 -0
- package/dist/experimental/services/models-provider.d.ts.map +1 -0
- package/dist/experimental/services/models-provider.js +116 -0
- package/dist/experimental/services/models-provider.js.map +1 -0
- package/dist/experimental/services/models.d.ts +36 -0
- package/dist/experimental/services/models.d.ts.map +1 -0
- package/dist/experimental/services/models.js +3 -0
- package/dist/experimental/services/models.js.map +1 -0
- package/dist/experimental/services/plugins.d.ts +16 -0
- package/dist/experimental/services/plugins.d.ts.map +1 -0
- package/dist/experimental/services/plugins.js +4 -0
- package/dist/experimental/services/plugins.js.map +1 -0
- package/dist/experimental/services/presentation-ui.d.ts +13 -0
- package/dist/experimental/services/presentation-ui.d.ts.map +1 -0
- package/dist/experimental/services/presentation-ui.js +3 -0
- package/dist/experimental/services/presentation-ui.js.map +1 -0
- package/dist/experimental/services/server.d.ts +19 -0
- package/dist/experimental/services/server.d.ts.map +1 -0
- package/dist/experimental/services/server.js +104 -0
- package/dist/experimental/services/server.js.map +1 -0
- package/dist/experimental/services/sessions.d.ts +28 -0
- package/dist/experimental/services/sessions.d.ts.map +1 -0
- package/dist/experimental/services/sessions.js +4 -0
- package/dist/experimental/services/sessions.js.map +1 -0
- package/dist/experimental/services/slash-commands-provider.d.ts +14 -0
- package/dist/experimental/services/slash-commands-provider.d.ts.map +1 -0
- package/dist/experimental/services/slash-commands-provider.js +200 -0
- package/dist/experimental/services/slash-commands-provider.js.map +1 -0
- package/dist/experimental/services/slash-commands.d.ts +24 -0
- package/dist/experimental/services/slash-commands.d.ts.map +1 -0
- package/dist/experimental/services/slash-commands.js +3 -0
- package/dist/experimental/services/slash-commands.js.map +1 -0
- package/dist/experimental/services/transcript-provider.d.ts +12 -0
- package/dist/experimental/services/transcript-provider.d.ts.map +1 -0
- package/dist/experimental/services/transcript-provider.js +109 -0
- package/dist/experimental/services/transcript-provider.js.map +1 -0
- package/dist/experimental/services/transcript.d.ts +13 -0
- package/dist/experimental/services/transcript.d.ts.map +1 -0
- package/dist/experimental/services/transcript.js +3 -0
- package/dist/experimental/services/transcript.js.map +1 -0
- package/dist/experimental/services/worker.d.ts +28 -0
- package/dist/experimental/services/worker.d.ts.map +1 -0
- package/dist/experimental/services/worker.js +107 -0
- package/dist/experimental/services/worker.js.map +1 -0
- package/dist/experimental/session-worker-manager.d.ts +24 -0
- package/dist/experimental/session-worker-manager.d.ts.map +1 -0
- package/dist/experimental/session-worker-manager.js +691 -0
- package/dist/experimental/session-worker-manager.js.map +1 -0
- package/dist/experimental/session-worker.d.ts +188 -0
- package/dist/experimental/session-worker.d.ts.map +1 -0
- package/dist/experimental/session-worker.js +785 -0
- package/dist/experimental/session-worker.js.map +1 -0
- package/dist/experimental/source-resolver.d.ts +2 -0
- package/dist/experimental/source-resolver.d.ts.map +1 -0
- package/dist/experimental/source-resolver.js +71 -0
- package/dist/experimental/source-resolver.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +126 -1
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/chat-viewport.d.ts +20 -0
- package/dist/modes/interactive/chat-viewport.d.ts.map +1 -0
- package/dist/modes/interactive/chat-viewport.js +28 -0
- package/dist/modes/interactive/chat-viewport.js.map +1 -0
- package/dist/modes/interactive/components/assistant-message.d.ts +1 -0
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +18 -10
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/custom-editor.d.ts +10 -1
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-editor.js +39 -1
- package/dist/modes/interactive/components/custom-editor.js.map +1 -1
- package/dist/modes/interactive/components/index.d.ts +1 -1
- package/dist/modes/interactive/components/index.d.ts.map +1 -1
- package/dist/modes/interactive/components/index.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +5 -14
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.js +13 -15
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +14 -10
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/status-indicator.d.ts +3 -1
- package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -1
- package/dist/modes/interactive/components/status-indicator.js +10 -3
- package/dist/modes/interactive/components/status-indicator.js.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.js +2 -2
- package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +21 -4
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +35 -33
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/trust-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/trust-selector.js +2 -2
- package/dist/modes/interactive/components/trust-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +8 -15
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +95 -80
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/session-share.d.ts.map +1 -1
- package/dist/modes/interactive/session-share.js +8 -12
- package/dist/modes/interactive/session-share.js.map +1 -1
- package/dist/modes/interactive/theme/dark.json +2 -1
- package/dist/modes/interactive/theme/light.json +2 -1
- package/dist/modes/interactive/theme/theme-controller.d.ts +1 -0
- package/dist/modes/interactive/theme/theme-controller.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme-controller.js +5 -0
- package/dist/modes/interactive/theme/theme-controller.js.map +1 -1
- package/dist/modes/interactive/theme/theme-json.d.ts +84 -0
- package/dist/modes/interactive/theme/theme-json.d.ts.map +1 -0
- package/dist/modes/interactive/theme/theme-json.js +130 -0
- package/dist/modes/interactive/theme/theme-json.js.map +1 -0
- package/dist/modes/interactive/theme/theme-schema.json +6 -2
- package/dist/modes/interactive/theme/theme.d.ts +14 -5
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +18 -119
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/modes/interactive/tui-renderer.d.ts +21 -0
- package/dist/modes/interactive/tui-renderer.d.ts.map +1 -0
- package/dist/modes/interactive/tui-renderer.js +66 -0
- package/dist/modes/interactive/tui-renderer.js.map +1 -0
- package/dist/utils/exif-orientation.d.ts.map +1 -1
- package/dist/utils/exif-orientation.js +2 -3
- package/dist/utils/exif-orientation.js.map +1 -1
- package/dist/utils/tools-manager.d.ts +1 -0
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +41 -19
- package/dist/utils/tools-manager.js.map +1 -1
- package/docs/environment-variables.md +2 -0
- package/docs/extensions.md +5 -2
- package/docs/keybindings.md +3 -1
- package/docs/models.md +3 -0
- package/docs/rpc.md +1 -1
- package/docs/sdk.md +5 -0
- package/docs/settings.md +5 -5
- package/docs/skills.md +1 -1
- package/docs/terminal-setup.md +15 -0
- package/docs/themes.md +8 -6
- package/docs/tui.md +20 -1
- package/examples/README.md +3 -0
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/dynamic-resources/dynamic.json +2 -0
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/plugins/pi-example-plugin/README.md +38 -0
- package/examples/plugins/pi-example-plugin/package.json +10 -0
- package/examples/plugins/pi-example-plugin/src/contract.ts +13 -0
- package/examples/plugins/pi-example-plugin/src/session.ts +23 -0
- package/examples/plugins/pi-example-plugin/src/tui.ts +31 -0
- package/npm-shrinkwrap.json +523 -28
- package/package.json +12 -6
- package/dist/bun/register-bedrock.d.ts +0 -2
- package/dist/bun/register-bedrock.d.ts.map +0 -1
- package/dist/bun/register-bedrock.js +0 -4
- package/dist/bun/register-bedrock.js.map +0 -1
- package/dist/bundle/chunks/anthropic-messages-JWX2WP65.js +0 -45
- package/dist/bundle/chunks/chunk-JUUC5AZY.js +0 -2
- package/dist/bundle/chunks/chunk-OMWWHBTG.js +0 -1548
- package/dist/bundle/chunks/openai-codex-responses-GJVBJXLB.js +0 -8
- package/dist/bundle/chunks/openai-responses-BSOJMSEV.js +0 -2
- package/dist/cli/experimental/auth.d.ts +0 -16
- package/dist/cli/experimental/auth.d.ts.map +0 -1
- package/dist/cli/experimental/auth.js +0 -13
- package/dist/cli/experimental/auth.js.map +0 -1
- package/dist/cli/experimental/commands/pi.d.ts +0 -15
- package/dist/cli/experimental/commands/pi.d.ts.map +0 -1
- package/dist/cli/experimental/commands/pi.js +0 -28
- package/dist/cli/experimental/commands/pi.js.map +0 -1
- package/dist/cli/experimental/transport-address.d.ts +0 -10
- package/dist/cli/experimental/transport-address.d.ts.map +0 -1
- package/dist/cli/experimental/transport-address.js +0 -38
- package/dist/cli/experimental/transport-address.js.map +0 -1
- package/dist/client/remote-session.d.ts +0 -53
- package/dist/client/remote-session.d.ts.map +0 -1
- package/dist/client/remote-session.js +0 -340
- package/dist/client/remote-session.js.map +0 -1
- package/dist/client/transcript.d.ts +0 -12
- package/dist/client/transcript.d.ts.map +0 -1
- package/dist/client/transcript.js +0 -98
- package/dist/client/transcript.js.map +0 -1
- package/dist/server/create-harness.d.ts +0 -26
- package/dist/server/create-harness.d.ts.map +0 -1
- package/dist/server/create-harness.js +0 -106
- package/dist/server/create-harness.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/experimental/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAG7C,OAAO,EACN,kBAAkB,EAElB,gBAAgB,EAChB,YAAY,GACZ,MAAM,+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,CAAC;IAC1C,IAAI,IAAI,KAAK,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;IACnG,KAAK,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE,CAAC;QACtE,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAAA,CAChB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { chmod, lstat, mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { homedir } from \"node:os\";\nimport { isAbsolute, join } from \"node:path\";\nimport type { Context } from \"@earendil-works/chord\";\nimport type { FacetBundleArtifact } from \"@earendil-works/chord/node\";\nimport {\n\tBACKGROUND_CONTEXT,\n\ttype JsonlSessionMetadata,\n\tJsonlSessionRepo,\n\tTODO_CONTEXT,\n} from \"@earendil-works/pi-agent-core\";\nimport { NodeExecutionEnv } from \"@earendil-works/pi-agent-core/node\";\nimport { Client, ServerError as ClientServerError, DisconnectedError } from \"@earendil-works/pi-client\";\nimport { createUnixTransportFactory, type UnixServerRoute } from \"@earendil-works/pi-client/unix\";\nimport { isServerId, type ServerId } from \"@earendil-works/pi-protocol\";\nimport {\n\tServerError as RoutedServerError,\n\ttype Server,\n\ttype ServerHost,\n\tSessionAmbiguousError,\n\tSessionNotFoundError,\n} from \"@earendil-works/pi-server\";\nimport { createUnixServer, getUnixSocketPath } from \"@earendil-works/pi-server/unix\";\nimport lockfile from \"proper-lockfile\";\nimport type { AuthInput } from \"../cli/experimental/command-options.ts\";\nimport { getAgentDir } from \"../config.ts\";\nimport { resolvePath } from \"../utils/paths.ts\";\nimport { CoordinatorConnection, type CoordinatorStartupLease, ensureCoordinator } from \"./coordinator.ts\";\nimport { createPresentationFacetData } from \"./plugins/bundled.ts\";\nimport {\n\tcreateServerPluginPackage,\n\tnormalizePluginPackagePaths,\n\treadSessionPluginPackageProfile,\n\tremoveSessionPluginPackageProfile,\n\trestoreServerPluginPackageProfile,\n\twriteSessionPluginPackageProfile,\n} from \"./plugins/package.ts\";\nimport {\n\tconsumeInternalProcessRole,\n\tisDirectInternalProcessEntry,\n\tspawnInternalProcess,\n\tterminateInternalProcess,\n} from \"./process.ts\";\nimport { RadiusRelayAuthResolver } from \"./radius-auth.ts\";\nimport { RadiusRelayHost, type RadiusRelayHostStatus } from \"./radius-relay.ts\";\nimport { createExperimentalServerServices } from \"./services/server.ts\";\nimport type { SessionCreateOptions, SessionSummary } from \"./services/sessions.ts\";\nimport { SessionPluginSelectionConflictError, SessionWorkerManager } from \"./session-worker-manager.ts\";\n\nexport const ENV_SERVER_DIR = \"PI_SERVER_DIR\";\nexport const ENV_SERVER_ID = \"PI_SERVER_ID\";\n\nexport function resolveServerDirectory(directory?: string): string {\n\treturn resolvePath(directory ?? process.env[ENV_SERVER_DIR] ?? join(homedir(), \".pi\", \"server\"));\n}\n\nexport async function ensurePrivateServerDirectory(directory: string): Promise<void> {\n\tif (typeof process.getuid !== \"function\") throw new Error(\"Unix socket directory requires a POSIX user ID\");\n\tawait mkdir(directory, { recursive: true, mode: 0o700 });\n\tconst stats = await lstat(directory);\n\tif (!stats.isDirectory()) throw new Error(`Unix socket directory is not a directory: ${directory}`);\n\tif (stats.uid !== process.getuid()) {\n\t\tthrow new Error(`Unix socket directory is not owned by the current user: ${directory}`);\n\t}\n\tawait chmod(directory, 0o700);\n}\n\nexport function resolveSessionDirectory(sessionDir?: string): string {\n\treturn resolvePath(sessionDir ?? join(getAgentDir(), \"experimental\", \"sessions\"));\n}\n\nconst LOCK_STALE_MS = 30_000;\nconst LOCK_RETRY_MS = 25;\nconst LOCK_WAIT_MS = 30_000;\nconst DEFAULT_SERVER_ID_FILE = \"default-server-id\";\n\nexport interface ServerProfile {\n\treadonly serverId: ServerId;\n\trelease(): Promise<void>;\n}\n\n/** Lock one logical server ID in a shared experimental server directory. */\nexport async function acquireServerProfile(directory: string, requestedServerId?: string): Promise<ServerProfile> {\n\tawait mkdir(directory, { recursive: true, mode: 0o700 });\n\tlet serverId: ServerId;\n\tif (requestedServerId !== undefined) {\n\t\tif (!isServerId(requestedServerId)) throw new Error(`Invalid experimental server ID: ${requestedServerId}`);\n\t\tserverId = requestedServerId;\n\t} else {\n\t\tconst path = join(directory, DEFAULT_SERVER_ID_FILE);\n\t\ttry {\n\t\t\tconst value = (await readFile(path, \"utf8\")).trim();\n\t\t\tif (!isServerId(value)) throw new Error(`Invalid default experimental server identity in ${path}`);\n\t\t\tserverId = value;\n\t\t} catch (error) {\n\t\t\tconst code = error instanceof Error && \"code\" in error ? error.code : undefined;\n\t\t\tif (code !== \"ENOENT\") throw error;\n\t\t\tconst candidate = randomUUID();\n\t\t\ttry {\n\t\t\t\tawait writeFile(path, candidate, { encoding: \"utf8\", mode: 0o600, flag: \"wx\" });\n\t\t\t\tserverId = candidate;\n\t\t\t} catch (writeError) {\n\t\t\t\tconst writeCode = writeError instanceof Error && \"code\" in writeError ? writeError.code : undefined;\n\t\t\t\tif (writeCode !== \"EEXIST\") throw writeError;\n\t\t\t\tconst value = (await readFile(path, \"utf8\")).trim();\n\t\t\t\tif (!isServerId(value)) throw new Error(`Invalid default experimental server identity in ${path}`);\n\t\t\t\tserverId = value;\n\t\t\t}\n\t\t}\n\t}\n\n\tconst release = await lockfile.lock(join(directory, `launcher-${serverId}`), {\n\t\trealpath: false,\n\t\tstale: LOCK_STALE_MS,\n\t\tupdate: LOCK_STALE_MS / 3,\n\t\tretries: {\n\t\t\tretries: Math.ceil(LOCK_WAIT_MS / LOCK_RETRY_MS),\n\t\t\tfactor: 1,\n\t\t\tminTimeout: LOCK_RETRY_MS,\n\t\t\tmaxTimeout: LOCK_RETRY_MS,\n\t\t\tmaxRetryTime: LOCK_WAIT_MS,\n\t\t},\n\t});\n\treturn { serverId, release };\n}\n\nconst ACTIVATION_TIMEOUT_MS = 10_000;\nconst ACTIVATION_RETRY_MS = 10;\n\nexport interface ActivatedServer {\n\treadonly client: Client;\n\treadonly route: UnixServerRoute;\n}\n\nexport interface ActivateServerOptions {\n\treadonly directory: string;\n\treadonly requestedServerId?: ServerId | string;\n\treadonly sessionDir: string;\n\treadonly provider?: string;\n\treadonly model?: string;\n}\n\n/** Ensure the selected logical server is reachable, launching the current Pi installation if needed. */\nexport async function activateServer(options: ActivateServerOptions): Promise<ActivatedServer> {\n\tif (options.provider !== undefined && options.model === undefined) {\n\t\tthrow new Error(\"Server model provider requires a model\");\n\t}\n\tawait ensurePrivateServerDirectory(options.directory);\n\tconst profile = await acquireServerProfile(options.directory, options.requestedServerId);\n\tconst serverId = profile.serverId;\n\tawait profile.release();\n\tconst route = { serverId, path: getUnixSocketPath(serverId, options.directory) };\n\tconst release = await acquireServerActivation(options.directory, serverId);\n\ttry {\n\t\tconst existing = await connect(route);\n\t\tif (existing) {\n\t\t\t// Another activator won the race, so startup-only selections can no longer be applied.\n\t\t\tif (options.model !== undefined) {\n\t\t\t\tawait existing.dispose();\n\t\t\t\tthrow new Error(\"Model selection is only valid when automatically activating a new server\");\n\t\t\t}\n\t\t\treturn { client: existing, route };\n\t\t}\n\t\tconst modelArgs =\n\t\t\toptions.model === undefined\n\t\t\t\t? []\n\t\t\t\t: [\n\t\t\t\t\t\tJSON.stringify({\n\t\t\t\t\t\t\t...(options.provider === undefined ? {} : { provider: options.provider }),\n\t\t\t\t\t\t\tmodel: options.model,\n\t\t\t\t\t\t}),\n\t\t\t\t\t];\n\t\tconst child = spawnInternalProcess(\"server\", [options.directory, serverId, options.sessionDir, ...modelArgs]);\n\t\tlet spawnError: Error | undefined;\n\t\tchild.once(\"error\", (error) => {\n\t\t\tspawnError = error;\n\t\t});\n\t\ttry {\n\t\t\tconst deadline = Date.now() + ACTIVATION_TIMEOUT_MS;\n\t\t\twhile (true) {\n\t\t\t\tconst client = await connect(route);\n\t\t\t\tif (client) return { client, route };\n\t\t\t\tif (spawnError) throw new Error(\"Failed to automatically activate server\", { cause: spawnError });\n\t\t\t\tif (child.exitCode !== null || child.signalCode !== null) {\n\t\t\t\t\tthrow new Error(\"Automatically activated server exited during startup\");\n\t\t\t\t}\n\t\t\t\tif (Date.now() >= deadline) throw new Error(\"Timed out waiting for automatically activated server\");\n\t\t\t\tawait new Promise<void>((resolve) => setTimeout(resolve, ACTIVATION_RETRY_MS));\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tawait terminateInternalProcess(child);\n\t\t\tthrow error;\n\t\t}\n\t} finally {\n\t\tawait release();\n\t}\n}\n\nexport function acquireServerActivation(directory: string, serverId: ServerId): Promise<() => Promise<void>> {\n\treturn lockfile.lock(join(directory, `activation-${serverId}`), {\n\t\trealpath: false,\n\t\tstale: ACTIVATION_TIMEOUT_MS * 2,\n\t\tupdate: ACTIVATION_TIMEOUT_MS,\n\t\tretries: {\n\t\t\tretries: Math.ceil(ACTIVATION_TIMEOUT_MS / 25),\n\t\t\tfactor: 1,\n\t\t\tminTimeout: 25,\n\t\t\tmaxTimeout: 25,\n\t\t\tmaxRetryTime: ACTIVATION_TIMEOUT_MS,\n\t\t},\n\t});\n}\n\nasync function connect(route: UnixServerRoute): Promise<Client | undefined> {\n\tconst client = new Client({\n\t\tserverId: route.serverId,\n\t\ttransportFactory: createUnixTransportFactory({ path: route.path }),\n\t});\n\ttry {\n\t\tawait client.connect();\n\t\treturn client;\n\t} catch (error) {\n\t\tawait client.dispose();\n\t\tif (error instanceof DisconnectedError || (error instanceof ClientServerError && error.code === \"version\")) {\n\t\t\treturn undefined;\n\t\t}\n\t\tlet current = error;\n\t\tconst seen = new Set<unknown>();\n\t\twhile (current instanceof Error && !seen.has(current)) {\n\t\t\tseen.add(current);\n\t\t\tif (\n\t\t\t\t\"code\" in current &&\n\t\t\t\t[\"ENOENT\", \"ECONNREFUSED\", \"ECONNRESET\", \"EPIPE\", \"ETIMEDOUT\"].includes(String(current.code))\n\t\t\t) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tcurrent = current.cause;\n\t\t}\n\t\tthrow error;\n\t}\n}\n\nconst AUTO_SERVER_STARTUP_GRACE_MS = 10_000;\nconst AUTO_SERVER_IDLE_GRACE_MS = 1_000;\n\n/** Reconcile operator, startup, client, and worker holds for one server generation. */\nexport class ServerLifetime {\n\treadonly #keepAlive: boolean;\n\t#connectionCount = 0;\n\t#workerCount = 0;\n\t#startupHeld: boolean;\n\t#startupTimer: NodeJS.Timeout | undefined;\n\t#retirementTimer: NodeJS.Timeout | undefined;\n\t#retire: (() => void) | undefined;\n\t#stopped = false;\n\n\tconstructor(keepAlive: boolean) {\n\t\tthis.#keepAlive = keepAlive;\n\t\tthis.#startupHeld = !keepAlive;\n\t}\n\n\tstart(retire: () => void): void {\n\t\tthis.#retire = retire;\n\t\tif (this.#startupHeld) {\n\t\t\tthis.#startupTimer = setTimeout(() => {\n\t\t\t\tthis.#startupTimer = undefined;\n\t\t\t\tthis.#startupHeld = false;\n\t\t\t\tthis.#reconcile();\n\t\t\t}, AUTO_SERVER_STARTUP_GRACE_MS);\n\t\t\tthis.#startupTimer.unref();\n\t\t}\n\t\tthis.#reconcile();\n\t}\n\n\tsetConnectionCount(count: number): void {\n\t\tthis.#connectionCount = count;\n\t\tif (count > 0 && this.#startupHeld) {\n\t\t\tthis.#startupHeld = false;\n\t\t\tif (this.#startupTimer) clearTimeout(this.#startupTimer);\n\t\t\tthis.#startupTimer = undefined;\n\t\t}\n\t\tthis.#reconcile();\n\t}\n\n\tsetWorkerCount(count: number): void {\n\t\tthis.#workerCount = count;\n\t\tthis.#reconcile();\n\t}\n\n\tstop(): void {\n\t\tthis.#stopped = true;\n\t\tif (this.#startupTimer) clearTimeout(this.#startupTimer);\n\t\tif (this.#retirementTimer) clearTimeout(this.#retirementTimer);\n\t\tthis.#startupTimer = undefined;\n\t\tthis.#retirementTimer = undefined;\n\t}\n\n\t#reconcile(): void {\n\t\tif (\n\t\t\tthis.#stopped ||\n\t\t\tthis.#keepAlive ||\n\t\t\tthis.#startupHeld ||\n\t\t\tthis.#connectionCount !== 0 ||\n\t\t\tthis.#workerCount !== 0\n\t\t) {\n\t\t\tif (this.#retirementTimer) clearTimeout(this.#retirementTimer);\n\t\t\tthis.#retirementTimer = undefined;\n\t\t\treturn;\n\t\t}\n\t\tconst retire = this.#retire;\n\t\tif (this.#retirementTimer || !retire) return;\n\t\tthis.#retirementTimer = setTimeout(() => {\n\t\t\tthis.#retirementTimer = undefined;\n\t\t\tif (!this.#stopped && !this.#startupHeld && this.#connectionCount === 0 && this.#workerCount === 0) {\n\t\t\t\tretire();\n\t\t\t}\n\t\t}, AUTO_SERVER_IDLE_GRACE_MS);\n\t\tthis.#retirementTimer.unref();\n\t}\n}\n\nexport interface RunningServer {\n\treadonly serverId: string;\n\treadonly sessionDir: string;\n\treadonly socketPath: string;\n\treadonly server: Server;\n\treadonly workerPids: ReadonlyMap<string, number>;\n\treadonly closed: Promise<void>;\n\tclose(): Promise<void>;\n}\n\nexport interface StartServerOptions {\n\t/** Server profile and socket directory. Defaults to PI_SERVER_DIR or ~/.pi/server. */\n\treadonly directory?: string;\n\t/** Logical service ID. Defaults to PI_SERVER_ID or the directory's default-server-id. */\n\treadonly serverId?: ServerId;\n\t/** Durable session directory. Defaults to the experimental directory under the configured agent directory. */\n\treadonly sessionDir?: string;\n\t/** Optional provider for an explicitly selected Session worker model. */\n\treadonly provider?: string;\n\t/** Optional model override for newly started Session workers. */\n\treadonly model?: string;\n\t/** Hold the server open without client or Session demand. Defaults to true for foreground servers. */\n\treadonly keepAlive?: boolean;\n\t/** Optional explicit Radius credential. Stored Radius auth is used when omitted. */\n\treadonly relayAuth?: AuthInput;\n\t/** Explicit plugin packages. Undefined restores the logical server profile; an empty list clears it. */\n\treadonly pluginPackages?: readonly string[];\n\treadonly onRelayStatus?: (status: RadiusRelayHostStatus) => void;\n}\n\ninterface ResolvedSessionPlugins {\n\treadonly packagePaths: readonly string[];\n\treadonly manifestPaths: readonly string[];\n\treadonly presentationArtifacts: readonly FacetBundleArtifact[];\n}\n\ninterface StartServerBackendOptions {\n\treadonly path: string;\n\treadonly serverId: ServerId;\n\treadonly sessionDir?: string;\n\tresolveSessionPlugins(\n\t\tmetadata: JsonlSessionMetadata,\n\t\tpackagePaths: readonly string[] | undefined,\n\t\tcontext: Context,\n\t): Promise<ResolvedSessionPlugins>;\n\tremoveSessionPlugins(metadata: JsonlSessionMetadata): Promise<void>;\n\treloadPresentationFacetBundles(packagePaths: readonly string[]): Promise<readonly FacetBundleArtifact[]>;\n}\n\ninterface RunningServerBackend extends RunningServer {\n\trefreshSessions(): Promise<void>;\n}\n\nasync function startServerBackend(\n\toptions: StartServerBackendOptions,\n\tworkers: SessionWorkerManager,\n\tonConnectionCountChanged?: (count: number) => void,\n): Promise<RunningServerBackend> {\n\tconst serverId = options.serverId;\n\tconst sessionDir = resolveSessionDirectory(options.sessionDir);\n\tconst executionEnv = new NodeExecutionEnv({ cwd: process.cwd() });\n\tconst repo = new JsonlSessionRepo({ fileSystem: executionEnv, sessionsRoot: sessionDir });\n\tconst listSessions = async (context: Context): Promise<JsonlSessionMetadata[]> => {\n\t\tconst sessions = new Map((await repo.list(undefined, context)).map((metadata) => [metadata.path, metadata]));\n\t\tfor (const metadata of workers.trackedSessions) sessions.set(metadata.path, metadata);\n\t\treturn [...sessions.values()];\n\t};\n\tconst resolveSession = async (sessionId: string, context: Context): Promise<JsonlSessionMetadata> => {\n\t\tconst matches = (await listSessions(context)).filter((metadata) => metadata.id === sessionId);\n\t\tif (matches.length === 0) throw new SessionNotFoundError(`Unknown session: ${sessionId}`);\n\t\tif (matches.length > 1) throw new SessionAmbiguousError();\n\t\treturn matches[0]!;\n\t};\n\tconst createSession = async (\n\t\tcreateOptions: SessionCreateOptions,\n\t\tcontext: Context,\n\t): Promise<JsonlSessionMetadata> => {\n\t\tconst session = await repo.create({ ...createOptions, cwd: process.cwd() }, context);\n\t\ttry {\n\t\t\treturn session.metadata;\n\t\t} finally {\n\t\t\tawait session.close(context);\n\t\t}\n\t};\n\tconst summarize = (metadata: JsonlSessionMetadata): SessionSummary => ({\n\t\tserverId,\n\t\tsessionId: metadata.id,\n\t\tcreatedAt: metadata.createdAt,\n\t});\n\tconst closeStorage = async (): Promise<void> => {\n\t\tconst cleanup = await Promise.allSettled([repo.close(TODO_CONTEXT), executionEnv.cleanup(TODO_CONTEXT)]);\n\t\tconst errors = cleanup.flatMap((result) => (result.status === \"rejected\" ? [result.reason] : []));\n\t\tif (errors.length === 1) throw errors[0];\n\t\tif (errors.length > 1) throw new AggregateError(errors, \"Experimental session storage cleanup failed\");\n\t};\n\tconst serverServices = await createExperimentalServerServices({\n\t\tlist: async (context) =>\n\t\t\t(await listSessions(context))\n\t\t\t\t.map(summarize)\n\t\t\t\t.sort((left, right) => left.sessionId.localeCompare(right.sessionId) || left.createdAt - right.createdAt),\n\t\tcreate: async (createOptions, context) => summarize(await createSession(createOptions, context)),\n\t\tremove: async (sessionId, context) => {\n\t\t\tconst metadata = await resolveSession(sessionId, context);\n\t\t\tawait workers.closeSession(metadata, context);\n\t\t\tawait repo.delete(metadata, context);\n\t\t\tawait options.removeSessionPlugins(metadata);\n\t\t},\n\t\tasync prepareSessionPlugins(sessionId, packagePaths, context) {\n\t\t\tconst metadata = await resolveSession(sessionId, context);\n\t\t\tlet selected: ResolvedSessionPlugins;\n\t\t\ttry {\n\t\t\t\tselected = await options.resolveSessionPlugins(metadata, packagePaths, context);\n\t\t\t\tworkers.assertSessionPluginManifestPaths(metadata, selected.manifestPaths);\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof SessionPluginSelectionConflictError) {\n\t\t\t\t\tthrow new RoutedServerError(\"service_invalid_value\", error.message);\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tpackagePaths: selected.packagePaths,\n\t\t\t\tpresentationPlugins: createPresentationFacetData(selected.presentationArtifacts),\n\t\t\t};\n\t\t},\n\t\tasync reloadPresentationPlugins(packagePaths) {\n\t\t\treturn createPresentationFacetData(await options.reloadPresentationFacetBundles(packagePaths));\n\t\t},\n\t}).catch(async (error: unknown) => {\n\t\ttry {\n\t\t\tawait closeStorage();\n\t\t} catch (cleanupError) {\n\t\t\tthrow new AggregateError([error, cleanupError], \"Server service startup and cleanup failed\");\n\t\t}\n\t\tthrow error;\n\t});\n\tconst host: ServerHost<JsonlSessionMetadata> = {\n\t\tserverServices: serverServices.host,\n\t\tresolveSession,\n\t\topenSession: async (metadata, context) => {\n\t\t\tconst selected = await options.resolveSessionPlugins(metadata, undefined, context);\n\t\t\treturn workers.openSession(metadata, context, selected.manifestPaths);\n\t\t},\n\t};\n\tconst socketPath = options.path;\n\tconst closeCatalog = async (): Promise<void> => {\n\t\tconst cleanup = await Promise.allSettled([serverServices.dispose(), closeStorage()]);\n\t\tconst errors = cleanup.flatMap((result) => (result.status === \"rejected\" ? [result.reason] : []));\n\t\tif (errors.length === 1) throw errors[0];\n\t\tif (errors.length > 1) throw new AggregateError(errors, \"Experimental session catalog cleanup failed\");\n\t};\n\tconst server = createUnixServer(host, {\n\t\tserverId,\n\t\tpath: socketPath,\n\t\tmode: 0o600,\n\t\tonConnectionCountChanged,\n\t});\n\ttry {\n\t\tawait server.start();\n\t} catch (error) {\n\t\tconst cleanup = await Promise.allSettled([server.close(), closeCatalog()]);\n\t\tconst cleanupErrors = cleanup.flatMap((result) => (result.status === \"rejected\" ? [result.reason] : []));\n\t\tif (cleanupErrors.length > 0) {\n\t\t\tthrow new AggregateError([error, ...cleanupErrors], \"Experimental server startup and cleanup failed\");\n\t\t}\n\t\tthrow error;\n\t}\n\n\tlet closePromise: Promise<void> | undefined;\n\tconst closed = server.closed.then(\n\t\t() => closeCatalog(),\n\t\tasync (serverError: unknown) => {\n\t\t\ttry {\n\t\t\t\tawait closeCatalog();\n\t\t\t} catch (repoError) {\n\t\t\t\tthrow new AggregateError([serverError, repoError], \"Server and repository shutdown failed\");\n\t\t\t}\n\t\t\tthrow serverError;\n\t\t},\n\t);\n\treturn {\n\t\tserverId,\n\t\tsessionDir,\n\t\tsocketPath,\n\t\tserver,\n\t\tworkerPids: workers.workerPids,\n\t\tclosed,\n\t\trefreshSessions: () => serverServices.refresh(BACKGROUND_CONTEXT),\n\t\tclose() {\n\t\t\tclosePromise ??= server.close().then(\n\t\t\t\t() => closed,\n\t\t\t\t() => closed,\n\t\t\t);\n\t\t\treturn closePromise;\n\t\t},\n\t};\n}\n\n/** Start a replaceable experimental server behind the stable coordinator endpoint. */\nexport async function startServer(options: StartServerOptions = {}): Promise<RunningServer> {\n\tif (options.provider !== undefined && options.model === undefined) {\n\t\tthrow new Error(\"Server model provider requires a model\");\n\t}\n\tconst workerModel =\n\t\toptions.model === undefined\n\t\t\t? undefined\n\t\t\t: { ...(options.provider === undefined ? {} : { provider: options.provider }), model: options.model };\n\tconst directory = resolveServerDirectory(options.directory);\n\tconst { serverId, release } = await acquireServerProfile(directory, options.serverId ?? process.env[ENV_SERVER_ID]);\n\tconst lifetime = new ServerLifetime(options.keepAlive ?? true);\n\tlet backend: RunningServerBackend | undefined;\n\tlet coordinator: CoordinatorConnection | undefined;\n\tlet startupLease: CoordinatorStartupLease | undefined;\n\tlet workers: SessionWorkerManager | undefined;\n\tlet relay: RadiusRelayHost | undefined;\n\tlet released = false;\n\ttry {\n\t\tawait ensurePrivateServerDirectory(directory);\n\t\tconst pluginPackagePaths = await restoreServerPluginPackageProfile(directory, serverId, options.pluginPackages);\n\t\tconst pluginPackages = new Map<string, ReturnType<typeof createServerPluginPackage>>();\n\t\tconst getPluginPackage = (packagePath: string): ReturnType<typeof createServerPluginPackage> => {\n\t\t\tlet plugin = pluginPackages.get(packagePath);\n\t\t\tif (plugin === undefined) {\n\t\t\t\tplugin = createServerPluginPackage(directory, serverId, packagePath);\n\t\t\t\tpluginPackages.set(packagePath, plugin);\n\t\t\t}\n\t\t\treturn plugin;\n\t\t};\n\t\tconst buildPluginSelection = async (packagePaths: readonly string[]): Promise<ResolvedSessionPlugins> => {\n\t\t\tconst normalizedPackagePaths = normalizePluginPackagePaths(packagePaths);\n\t\t\tconst plugins = normalizedPackagePaths.map(getPluginPackage);\n\t\t\tconst built = (await Promise.all(plugins.map((plugin) => plugin.build()))).flat();\n\t\t\treturn {\n\t\t\t\tpackagePaths: normalizedPackagePaths,\n\t\t\t\tmanifestPaths: plugins.map((plugin) => plugin.manifestPath),\n\t\t\t\tpresentationArtifacts: built,\n\t\t\t};\n\t\t};\n\t\tlet defaultPluginSelection = await buildPluginSelection(pluginPackagePaths);\n\t\tconst sessionPluginSelections = new Map<string, ResolvedSessionPlugins>();\n\t\tconst resolveSessionPlugins = async (\n\t\t\tmetadata: JsonlSessionMetadata,\n\t\t\trequestedPackagePaths: readonly string[] | undefined,\n\t\t\t_context: Context,\n\t\t): Promise<ResolvedSessionPlugins> => {\n\t\t\tif (requestedPackagePaths !== undefined) {\n\t\t\t\tconst normalizedPackagePaths = normalizePluginPackagePaths(requestedPackagePaths);\n\t\t\t\tconst current = sessionPluginSelections.get(metadata.path);\n\t\t\t\tif (current !== undefined && sameStrings(current.packagePaths, normalizedPackagePaths)) return current;\n\t\t\t\tconst requestedManifestPaths = normalizedPackagePaths.map(\n\t\t\t\t\t(packagePath) => getPluginPackage(packagePath).manifestPath,\n\t\t\t\t);\n\t\t\t\tworkers?.assertSessionPluginManifestPaths(metadata, requestedManifestPaths);\n\t\t\t\tconst candidate = await buildPluginSelection(normalizedPackagePaths);\n\t\t\t\tworkers?.assertSessionPluginManifestPaths(metadata, candidate.manifestPaths);\n\t\t\t\tawait writeSessionPluginPackageProfile(directory, serverId, metadata.path, candidate.packagePaths);\n\t\t\t\tsessionPluginSelections.set(metadata.path, candidate);\n\t\t\t\treturn candidate;\n\t\t\t}\n\t\t\tconst cached = sessionPluginSelections.get(metadata.path);\n\t\t\tif (cached !== undefined) return cached;\n\t\t\tconst storedPackagePaths = await readSessionPluginPackageProfile(directory, serverId, metadata.path);\n\t\t\tconst selected =\n\t\t\t\tstoredPackagePaths === undefined ? defaultPluginSelection : await buildPluginSelection(storedPackagePaths);\n\t\t\tif (storedPackagePaths === undefined) {\n\t\t\t\tawait writeSessionPluginPackageProfile(directory, serverId, metadata.path, selected.packagePaths);\n\t\t\t}\n\t\t\tsessionPluginSelections.set(metadata.path, selected);\n\t\t\treturn selected;\n\t\t};\n\t\tconst removeSessionPlugins = async (metadata: JsonlSessionMetadata): Promise<void> => {\n\t\t\tsessionPluginSelections.delete(metadata.path);\n\t\t\tawait removeSessionPluginPackageProfile(directory, serverId, metadata.path);\n\t\t};\n\t\tconst reloadPresentationFacetBundles = async (\n\t\t\tpackagePaths: readonly string[],\n\t\t): Promise<readonly FacetBundleArtifact[]> => {\n\t\t\tconst reloaded = await buildPluginSelection(packagePaths);\n\t\t\tif (sameStrings(defaultPluginSelection.packagePaths, reloaded.packagePaths)) {\n\t\t\t\tdefaultPluginSelection = reloaded;\n\t\t\t}\n\t\t\tfor (const [sessionPath, selected] of sessionPluginSelections) {\n\t\t\t\tif (sameStrings(selected.packagePaths, reloaded.packagePaths)) {\n\t\t\t\t\tsessionPluginSelections.set(sessionPath, reloaded);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn reloaded.presentationArtifacts;\n\t\t};\n\t\tconst socketPath = getUnixSocketPath(serverId, directory);\n\t\tconst controlPath = join(directory, `control-${serverId}.sock`);\n\t\tconst serverNonce = randomUUID().replaceAll(\"-\", \"\").slice(0, 12);\n\t\tconst serverPath = join(directory, `server-${serverId}-${serverNonce}.sock`);\n\t\tstartupLease = await ensureCoordinator(socketPath, controlPath);\n\t\tcoordinator = new CoordinatorConnection({ controlPath, endpoint: serverPath });\n\t\tconst sessionDir = resolveSessionDirectory(options.sessionDir);\n\t\tworkers = new SessionWorkerManager(coordinator, sessionDir, workerModel, (count) =>\n\t\t\tlifetime.setWorkerCount(count),\n\t\t);\n\t\tbackend = await startServerBackend(\n\t\t\t{\n\t\t\t\tpath: serverPath,\n\t\t\t\tserverId,\n\t\t\t\tsessionDir: options.sessionDir,\n\t\t\t\tresolveSessionPlugins,\n\t\t\t\tremoveSessionPlugins,\n\t\t\t\treloadPresentationFacetBundles,\n\t\t\t},\n\t\t\tworkers,\n\t\t\t(count) => lifetime.setConnectionCount(count),\n\t\t);\n\t\tawait coordinator.connect();\n\t\tstartupLease.close();\n\t\tstartupLease = undefined;\n\t\tawait workers.discover(coordinator.peerIds);\n\t\tawait backend.refreshSessions();\n\t\trelay = new RadiusRelayHost({\n\t\t\tserverId,\n\t\t\tserver: backend.server,\n\t\t\tauth: new RadiusRelayAuthResolver(options.relayAuth),\n\t\t\tonStatus: options.onRelayStatus,\n\t\t});\n\t\trelay.start();\n\n\t\tconst activeBackend = backend;\n\t\tconst activeCoordinator = coordinator;\n\t\tconst activeWorkers = workers;\n\t\tconst activeRelay = relay;\n\t\tvoid activeCoordinator.replaced\n\t\t\t.then(async () => {\n\t\t\t\tlifetime.stop();\n\t\t\t\tactiveWorkers.detach();\n\t\t\t\tawait activeRelay.close();\n\t\t\t\tawait activeBackend.close();\n\t\t\t})\n\t\t\t.finally(() => activeCoordinator.close())\n\t\t\t.catch(() => {});\n\t\tlet closePromise: Promise<void> | undefined;\n\t\tconst runtime: RunningServer = {\n\t\t\tserverId,\n\t\t\tsessionDir: activeBackend.sessionDir,\n\t\t\tsocketPath,\n\t\t\tserver: activeBackend.server,\n\t\t\tworkerPids: activeWorkers.workerPids,\n\t\t\tclosed: activeBackend.closed.finally(() => activeRelay.close()),\n\t\t\tclose() {\n\t\t\t\tlifetime.stop();\n\t\t\t\tclosePromise ??= (async () => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait activeRelay.close();\n\t\t\t\t\t\tawait activeBackend.close();\n\t\t\t\t\t} finally {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tif (activeCoordinator.wasReplaced) activeWorkers.detach();\n\t\t\t\t\t\t\telse await activeWorkers.shutdown();\n\t\t\t\t\t\t} finally {\n\t\t\t\t\t\t\tactiveCoordinator.close();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t})();\n\t\t\t\treturn closePromise;\n\t\t\t},\n\t\t};\n\t\tlifetime.start(() => {\n\t\t\tvoid runtime.close().catch(() => {});\n\t\t});\n\t\treleased = true;\n\t\tawait release();\n\t\treturn runtime;\n\t} catch (error) {\n\t\tlifetime.stop();\n\t\tstartupLease?.close();\n\t\tif (coordinator?.wasReplaced) workers?.detach();\n\t\tconst cleanup = await Promise.allSettled([\n\t\t\trelay?.close(),\n\t\t\tbackend?.close(),\n\t\t\tcoordinator?.wasReplaced ? undefined : workers?.shutdown(),\n\t\t\tPromise.resolve(coordinator?.close()),\n\t\t\treleased ? undefined : release(),\n\t\t]);\n\t\tconst cleanupErrors = cleanup.flatMap((result) => (result.status === \"rejected\" ? [result.reason] : []));\n\t\tif (cleanupErrors.length > 0) {\n\t\t\tthrow new AggregateError([error, ...cleanupErrors], \"Server runtime startup and cleanup failed\");\n\t\t}\n\t\tthrow error;\n\t}\n}\n\n/** Start an operator-held server while serializing against automatic cold activation. */\nexport async function startForegroundServer(\n\toptions: Omit<StartServerOptions, \"keepAlive\"> = {},\n): Promise<RunningServer> {\n\tconst directory = resolveServerDirectory(options.directory);\n\tawait ensurePrivateServerDirectory(directory);\n\tconst profile = await acquireServerProfile(directory, options.serverId ?? process.env[ENV_SERVER_ID]);\n\tconst serverId = profile.serverId;\n\tawait profile.release();\n\tconst release = await acquireServerActivation(directory, serverId);\n\ttry {\n\t\treturn await startServer({\n\t\t\t...options,\n\t\t\tdirectory,\n\t\t\tserverId,\n\t\t\tkeepAlive: true,\n\t\t});\n\t} finally {\n\t\tawait release();\n\t}\n}\n\nfunction parseServerModelOptions(value: string | undefined): { provider?: string; model: string } | undefined {\n\tif (value === undefined) return undefined;\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(value);\n\t} catch (error) {\n\t\tthrow new Error(\"Internal server received invalid model options\", { cause: error });\n\t}\n\tif (typeof parsed !== \"object\" || parsed === null || Array.isArray(parsed)) {\n\t\tthrow new Error(\"Internal server received invalid model options\");\n\t}\n\tconst keys = Object.keys(parsed);\n\tconst model = \"model\" in parsed ? parsed.model : undefined;\n\tconst provider = \"provider\" in parsed ? parsed.provider : undefined;\n\tif (\n\t\tkeys.some((key) => key !== \"provider\" && key !== \"model\") ||\n\t\ttypeof model !== \"string\" ||\n\t\tmodel.length === 0 ||\n\t\t(provider !== undefined && (typeof provider !== \"string\" || provider.length === 0))\n\t) {\n\t\tthrow new Error(\"Internal server received invalid model options\");\n\t}\n\treturn provider === undefined ? { model } : { provider, model };\n}\n\n/** Run an automatically activated server until its client and Session demand disappears. */\nexport async function runServerProcess(args: readonly string[]): Promise<void> {\n\tconst [directory, serverId, sessionDir, serializedModel] = args;\n\tif (args.length > 4) throw new Error(\"Internal server received unexpected arguments\");\n\tif (!directory || !isAbsolute(directory)) throw new Error(\"Internal server requires an absolute server directory\");\n\tif (!isServerId(serverId)) throw new Error(\"Internal server requires a canonical server ID\");\n\tif (!sessionDir || !isAbsolute(sessionDir))\n\t\tthrow new Error(\"Internal server requires an absolute Session directory\");\n\tconst workerModel = parseServerModelOptions(serializedModel);\n\n\tconst runtime = await startServer({\n\t\tdirectory,\n\t\tserverId,\n\t\tsessionDir,\n\t\tkeepAlive: false,\n\t\t...workerModel,\n\t});\n\tconst close = (): void => {\n\t\tvoid runtime.close().catch(() => {});\n\t};\n\tprocess.once(\"SIGINT\", close);\n\tprocess.once(\"SIGTERM\", close);\n\ttry {\n\t\tawait runtime.closed;\n\t} finally {\n\t\tprocess.off(\"SIGINT\", close);\n\t\tprocess.off(\"SIGTERM\", close);\n\t\tawait runtime.close();\n\t}\n}\n\nfunction sameStrings(left: readonly string[], right: readonly string[]): boolean {\n\treturn left.length === right.length && left.every((value, index) => value === right[index]);\n}\n\nif (isDirectInternalProcessEntry(import.meta.url)) {\n\tconst role = consumeInternalProcessRole();\n\tif (role !== \"server\") throw new Error(\"Server entrypoint requires an internal server invocation\");\n\tvoid runServerProcess(process.argv.slice(2)).catch((error: unknown) => {\n\t\tconsole.error(error);\n\t\tprocess.exit(1);\n\t});\n}\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AgentLane } from "@earendil-works/pi-agent-core";
|
|
2
|
+
import type { AgentController as AgentControllerService } from "./agent-controller.ts";
|
|
3
|
+
export declare function createAgentController(lane: AgentLane): AgentControllerService;
|
|
4
|
+
//# sourceMappingURL=agent-controller-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-controller-provider.d.ts","sourceRoot":"","sources":["../../../src/experimental/services/agent-controller-provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAuC,MAAM,+BAA+B,CAAC;AAEpG,OAAO,KAAK,EACX,eAAe,IAAI,sBAAsB,EAKzC,MAAM,uBAAuB,CAAC;AAE/B,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,SAAS,GAAG,sBAAsB,CA+D7E","sourcesContent":["import type { AgentLane, OperationResultRecord, SuspendedRun } from \"@earendil-works/pi-agent-core\";\nimport type { ImageContent } from \"@earendil-works/pi-ai\";\nimport type {\n\tAgentController as AgentControllerService,\n\tAgentOperationError,\n\tAgentOperationResponse,\n\tAgentPromptRequest,\n\tAgentQueueResponse,\n} from \"./agent-controller.ts\";\n\nexport function createAgentController(lane: AgentLane): AgentControllerService {\n\tconst queue = async (\n\t\toperation: \"steer\" | \"followUp\" | \"nextRun\",\n\t\trequest: AgentPromptRequest,\n\t\tcontext: Parameters<AgentControllerService[\"steer\"]>[1],\n\t): Promise<AgentQueueResponse> => {\n\t\tconst [message, images] = toTextPrompt(request);\n\t\tconst result = await lane[operation](message, images, context);\n\t\treturn result.ok\n\t\t\t? { accepted: true, entryId: result.value.entryId, error: null }\n\t\t\t: { accepted: false, entryId: null, error: toAgentError(result.error) };\n\t};\n\n\treturn {\n\t\tasync prompt(request, context) {\n\t\t\tconst [message, images] = toTextPrompt(request);\n\t\t\tconst result = await lane.prompt(message, images, context);\n\t\t\treturn result.ok\n\t\t\t\t? toOperationResponse(result.value)\n\t\t\t\t: { accepted: false, operationId: operationId(result.error), error: toAgentError(result.error) };\n\t\t},\n\t\tasync requestAbort(operationId, context) {\n\t\t\tconst result = await lane.requestAbort(operationId, context);\n\t\t\tif (!result.ok) throw new Error(result.error.message);\n\t\t},\n\t\tsteer: (request, context) => queue(\"steer\", request, context),\n\t\tfollowUp: (request, context) => queue(\"followUp\", request, context),\n\t\tnextRun: (request, context) => queue(\"nextRun\", request, context),\n\t\tasync cancelQueued(entryId, context) {\n\t\t\tconst result = await lane.cancelQueued(entryId, context);\n\t\t\tif (!result.ok) throw new Error(result.error.message);\n\t\t\treturn { outcome: result.value.kind };\n\t\t},\n\t\tasync resume(context) {\n\t\t\tconst result = await lane.resume(context);\n\t\t\treturn result.ok\n\t\t\t\t? toOperationResponse(result.value)\n\t\t\t\t: { accepted: false, operationId: null, error: toAgentError(result.error) };\n\t\t},\n\t\tasync compact(request, context) {\n\t\t\tconst result = await lane.compact(\n\t\t\t\trequest.customInstructions === null ? undefined : { customInstructions: request.customInstructions },\n\t\t\t\tcontext,\n\t\t\t);\n\t\t\treturn result.ok\n\t\t\t\t? toOperationResponse(result.value.compaction)\n\t\t\t\t: { accepted: false, operationId: operationId(result.error), error: toAgentError(result.error) };\n\t\t},\n\t\tasync navigate(request, context) {\n\t\t\tconst result = await lane.navigateTree(\n\t\t\t\trequest.targetId,\n\t\t\t\t{\n\t\t\t\t\tsummarize: request.summarize,\n\t\t\t\t\t...(request.label === null ? {} : { label: request.label }),\n\t\t\t\t\t...(request.customInstructions === null ? {} : { customInstructions: request.customInstructions }),\n\t\t\t\t},\n\t\t\t\tcontext,\n\t\t\t);\n\t\t\treturn result.ok\n\t\t\t\t? toOperationResponse(result.value.navigation)\n\t\t\t\t: { accepted: false, operationId: operationId(result.error), error: toAgentError(result.error) };\n\t\t},\n\t};\n}\n\nfunction toOperationResponse(value: OperationResultRecord | SuspendedRun): AgentOperationResponse {\n\treturn {\n\t\taccepted: true,\n\t\toperationId: value.operationId,\n\t\terror:\n\t\t\t\"status\" in value && value.status === \"failed\" && value.error !== undefined\n\t\t\t\t? { code: value.error.code, message: value.error.message }\n\t\t\t\t: null,\n\t};\n}\n\nfunction operationId(error: { readonly _tag: string }): string | null {\n\treturn \"operationId\" in error && typeof error.operationId === \"string\" ? error.operationId : null;\n}\n\nfunction toAgentError(error: { readonly _tag: string; readonly message: string }): AgentOperationError {\n\tconst code =\n\t\t{\n\t\t\tLaneBusy: \"lane_busy\",\n\t\t\tInvalidMessage: \"invalid_message\",\n\t\t\tUnknownSkill: \"unknown_skill\",\n\t\t\tUnknownTemplate: \"unknown_template\",\n\t\t\tNothingToCompact: \"nothing_to_compact\",\n\t\t\tNothingToResume: \"nothing_to_resume\",\n\t\t\tInvalidNavigation: \"invalid_navigation\",\n\t\t\tUnknownTarget: \"unknown_target\",\n\t\t\tClosed: \"closed\",\n\t\t}[error._tag] ?? \"operation_failed\";\n\treturn { code, message: error.message };\n}\n\nfunction toTextPrompt(request: AgentPromptRequest): [message: string, images: ImageContent[] | undefined] {\n\treturn [request.message, request.images ?? undefined];\n}\n"]}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export function createAgentController(lane) {
|
|
2
|
+
const queue = async (operation, request, context) => {
|
|
3
|
+
const [message, images] = toTextPrompt(request);
|
|
4
|
+
const result = await lane[operation](message, images, context);
|
|
5
|
+
return result.ok
|
|
6
|
+
? { accepted: true, entryId: result.value.entryId, error: null }
|
|
7
|
+
: { accepted: false, entryId: null, error: toAgentError(result.error) };
|
|
8
|
+
};
|
|
9
|
+
return {
|
|
10
|
+
async prompt(request, context) {
|
|
11
|
+
const [message, images] = toTextPrompt(request);
|
|
12
|
+
const result = await lane.prompt(message, images, context);
|
|
13
|
+
return result.ok
|
|
14
|
+
? toOperationResponse(result.value)
|
|
15
|
+
: { accepted: false, operationId: operationId(result.error), error: toAgentError(result.error) };
|
|
16
|
+
},
|
|
17
|
+
async requestAbort(operationId, context) {
|
|
18
|
+
const result = await lane.requestAbort(operationId, context);
|
|
19
|
+
if (!result.ok)
|
|
20
|
+
throw new Error(result.error.message);
|
|
21
|
+
},
|
|
22
|
+
steer: (request, context) => queue("steer", request, context),
|
|
23
|
+
followUp: (request, context) => queue("followUp", request, context),
|
|
24
|
+
nextRun: (request, context) => queue("nextRun", request, context),
|
|
25
|
+
async cancelQueued(entryId, context) {
|
|
26
|
+
const result = await lane.cancelQueued(entryId, context);
|
|
27
|
+
if (!result.ok)
|
|
28
|
+
throw new Error(result.error.message);
|
|
29
|
+
return { outcome: result.value.kind };
|
|
30
|
+
},
|
|
31
|
+
async resume(context) {
|
|
32
|
+
const result = await lane.resume(context);
|
|
33
|
+
return result.ok
|
|
34
|
+
? toOperationResponse(result.value)
|
|
35
|
+
: { accepted: false, operationId: null, error: toAgentError(result.error) };
|
|
36
|
+
},
|
|
37
|
+
async compact(request, context) {
|
|
38
|
+
const result = await lane.compact(request.customInstructions === null ? undefined : { customInstructions: request.customInstructions }, context);
|
|
39
|
+
return result.ok
|
|
40
|
+
? toOperationResponse(result.value.compaction)
|
|
41
|
+
: { accepted: false, operationId: operationId(result.error), error: toAgentError(result.error) };
|
|
42
|
+
},
|
|
43
|
+
async navigate(request, context) {
|
|
44
|
+
const result = await lane.navigateTree(request.targetId, {
|
|
45
|
+
summarize: request.summarize,
|
|
46
|
+
...(request.label === null ? {} : { label: request.label }),
|
|
47
|
+
...(request.customInstructions === null ? {} : { customInstructions: request.customInstructions }),
|
|
48
|
+
}, context);
|
|
49
|
+
return result.ok
|
|
50
|
+
? toOperationResponse(result.value.navigation)
|
|
51
|
+
: { accepted: false, operationId: operationId(result.error), error: toAgentError(result.error) };
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function toOperationResponse(value) {
|
|
56
|
+
return {
|
|
57
|
+
accepted: true,
|
|
58
|
+
operationId: value.operationId,
|
|
59
|
+
error: "status" in value && value.status === "failed" && value.error !== undefined
|
|
60
|
+
? { code: value.error.code, message: value.error.message }
|
|
61
|
+
: null,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function operationId(error) {
|
|
65
|
+
return "operationId" in error && typeof error.operationId === "string" ? error.operationId : null;
|
|
66
|
+
}
|
|
67
|
+
function toAgentError(error) {
|
|
68
|
+
const code = {
|
|
69
|
+
LaneBusy: "lane_busy",
|
|
70
|
+
InvalidMessage: "invalid_message",
|
|
71
|
+
UnknownSkill: "unknown_skill",
|
|
72
|
+
UnknownTemplate: "unknown_template",
|
|
73
|
+
NothingToCompact: "nothing_to_compact",
|
|
74
|
+
NothingToResume: "nothing_to_resume",
|
|
75
|
+
InvalidNavigation: "invalid_navigation",
|
|
76
|
+
UnknownTarget: "unknown_target",
|
|
77
|
+
Closed: "closed",
|
|
78
|
+
}[error._tag] ?? "operation_failed";
|
|
79
|
+
return { code, message: error.message };
|
|
80
|
+
}
|
|
81
|
+
function toTextPrompt(request) {
|
|
82
|
+
return [request.message, request.images ?? undefined];
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=agent-controller-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-controller-provider.js","sourceRoot":"","sources":["../../../src/experimental/services/agent-controller-provider.ts"],"names":[],"mappings":"AAUA,MAAM,UAAU,qBAAqB,CAAC,IAAe,EAA0B;IAC9E,MAAM,KAAK,GAAG,KAAK,EAClB,SAA2C,EAC3C,OAA2B,EAC3B,OAAuD,EACzB,EAAE,CAAC;QACjC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;QAChD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QAC/D,OAAO,MAAM,CAAC,EAAE;YACf,CAAC,CAAC,EAAE,QAAQ,EA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,CAAC;AAAA,CACF;AAED,SAAS,WAAW,CAAC,KAAgC,EAAiB;IACrE,OAAO,aAAa,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,WAAW,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC;AAAA,CAClG;AAED,SAAS,YAAY,CAAC,KAA0D,EAAuB;IACtG,MAAM,IAAI,GACT;QACC,QAAQ,EAAE,WAAW;QACrB,cAAc,EAAE,iBAAiB;QACjC,YAAY,EAAE,eAAe;QAC7B,eAAe,EAAE,kBAAkB;QACnC,gBAAgB,EAAE,oBAAoB;QACtC,eAAe,EAAE,mBAAmB;QACpC,iBAAiB,EAAE,oBAAoB;QACvC,aAAa,EAAE,gBAAgB;QAC/B,MAAM,EAAE,QAAQ;KAChB,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,kBAAkB,CAAC;IACrC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;AAAA,CACxC;AAED,SAAS,YAAY,CAAC,OAA2B,EAAyD;IACzG,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,MAAM,IAAI,SAAS,CAAC,CAAC;AAAA,CACtD","sourcesContent":["import type { AgentLane, OperationResultRecord, SuspendedRun } from \"@earendil-works/pi-agent-core\";\nimport type { ImageContent } from \"@earendil-works/pi-ai\";\nimport type {\n\tAgentController as AgentControllerService,\n\tAgentOperationError,\n\tAgentOperationResponse,\n\tAgentPromptRequest,\n\tAgentQueueResponse,\n} from \"./agent-controller.ts\";\n\nexport function createAgentController(lane: AgentLane): AgentControllerService {\n\tconst queue = async (\n\t\toperation: \"steer\" | \"followUp\" | \"nextRun\",\n\t\trequest: AgentPromptRequest,\n\t\tcontext: Parameters<AgentControllerService[\"steer\"]>[1],\n\t): Promise<AgentQueueResponse> => {\n\t\tconst [message, images] = toTextPrompt(request);\n\t\tconst result = await lane[operation](message, images, context);\n\t\treturn result.ok\n\t\t\t? { accepted: true, entryId: result.value.entryId, error: null }\n\t\t\t: { accepted: false, entryId: null, error: toAgentError(result.error) };\n\t};\n\n\treturn {\n\t\tasync prompt(request, context) {\n\t\t\tconst [message, images] = toTextPrompt(request);\n\t\t\tconst result = await lane.prompt(message, images, context);\n\t\t\treturn result.ok\n\t\t\t\t? toOperationResponse(result.value)\n\t\t\t\t: { accepted: false, operationId: operationId(result.error), error: toAgentError(result.error) };\n\t\t},\n\t\tasync requestAbort(operationId, context) {\n\t\t\tconst result = await lane.requestAbort(operationId, context);\n\t\t\tif (!result.ok) throw new Error(result.error.message);\n\t\t},\n\t\tsteer: (request, context) => queue(\"steer\", request, context),\n\t\tfollowUp: (request, context) => queue(\"followUp\", request, context),\n\t\tnextRun: (request, context) => queue(\"nextRun\", request, context),\n\t\tasync cancelQueued(entryId, context) {\n\t\t\tconst result = await lane.cancelQueued(entryId, context);\n\t\t\tif (!result.ok) throw new Error(result.error.message);\n\t\t\treturn { outcome: result.value.kind };\n\t\t},\n\t\tasync resume(context) {\n\t\t\tconst result = await lane.resume(context);\n\t\t\treturn result.ok\n\t\t\t\t? toOperationResponse(result.value)\n\t\t\t\t: { accepted: false, operationId: null, error: toAgentError(result.error) };\n\t\t},\n\t\tasync compact(request, context) {\n\t\t\tconst result = await lane.compact(\n\t\t\t\trequest.customInstructions === null ? undefined : { customInstructions: request.customInstructions },\n\t\t\t\tcontext,\n\t\t\t);\n\t\t\treturn result.ok\n\t\t\t\t? toOperationResponse(result.value.compaction)\n\t\t\t\t: { accepted: false, operationId: operationId(result.error), error: toAgentError(result.error) };\n\t\t},\n\t\tasync navigate(request, context) {\n\t\t\tconst result = await lane.navigateTree(\n\t\t\t\trequest.targetId,\n\t\t\t\t{\n\t\t\t\t\tsummarize: request.summarize,\n\t\t\t\t\t...(request.label === null ? {} : { label: request.label }),\n\t\t\t\t\t...(request.customInstructions === null ? {} : { customInstructions: request.customInstructions }),\n\t\t\t\t},\n\t\t\t\tcontext,\n\t\t\t);\n\t\t\treturn result.ok\n\t\t\t\t? toOperationResponse(result.value.navigation)\n\t\t\t\t: { accepted: false, operationId: operationId(result.error), error: toAgentError(result.error) };\n\t\t},\n\t};\n}\n\nfunction toOperationResponse(value: OperationResultRecord | SuspendedRun): AgentOperationResponse {\n\treturn {\n\t\taccepted: true,\n\t\toperationId: value.operationId,\n\t\terror:\n\t\t\t\"status\" in value && value.status === \"failed\" && value.error !== undefined\n\t\t\t\t? { code: value.error.code, message: value.error.message }\n\t\t\t\t: null,\n\t};\n}\n\nfunction operationId(error: { readonly _tag: string }): string | null {\n\treturn \"operationId\" in error && typeof error.operationId === \"string\" ? error.operationId : null;\n}\n\nfunction toAgentError(error: { readonly _tag: string; readonly message: string }): AgentOperationError {\n\tconst code =\n\t\t{\n\t\t\tLaneBusy: \"lane_busy\",\n\t\t\tInvalidMessage: \"invalid_message\",\n\t\t\tUnknownSkill: \"unknown_skill\",\n\t\t\tUnknownTemplate: \"unknown_template\",\n\t\t\tNothingToCompact: \"nothing_to_compact\",\n\t\t\tNothingToResume: \"nothing_to_resume\",\n\t\t\tInvalidNavigation: \"invalid_navigation\",\n\t\t\tUnknownTarget: \"unknown_target\",\n\t\t\tClosed: \"closed\",\n\t\t}[error._tag] ?? \"operation_failed\";\n\treturn { code, message: error.message };\n}\n\nfunction toTextPrompt(request: AgentPromptRequest): [message: string, images: ImageContent[] | undefined] {\n\treturn [request.message, request.images ?? undefined];\n}\n"]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { type Context } from "@earendil-works/chord";
|
|
2
|
+
export interface AgentPromptImage {
|
|
3
|
+
type: "image";
|
|
4
|
+
data: string;
|
|
5
|
+
mimeType: string;
|
|
6
|
+
}
|
|
7
|
+
export interface AgentPromptRequest {
|
|
8
|
+
message: string;
|
|
9
|
+
images: AgentPromptImage[] | null;
|
|
10
|
+
}
|
|
11
|
+
export interface AgentOperationError {
|
|
12
|
+
code: string;
|
|
13
|
+
message: string;
|
|
14
|
+
}
|
|
15
|
+
export type AgentOperationResponse = {
|
|
16
|
+
accepted: true;
|
|
17
|
+
operationId: string;
|
|
18
|
+
error: AgentOperationError | null;
|
|
19
|
+
} | {
|
|
20
|
+
accepted: false;
|
|
21
|
+
operationId: string | null;
|
|
22
|
+
error: AgentOperationError;
|
|
23
|
+
};
|
|
24
|
+
export type AgentQueueResponse = {
|
|
25
|
+
accepted: true;
|
|
26
|
+
entryId: string;
|
|
27
|
+
error: null;
|
|
28
|
+
} | {
|
|
29
|
+
accepted: false;
|
|
30
|
+
entryId: null;
|
|
31
|
+
error: AgentOperationError;
|
|
32
|
+
};
|
|
33
|
+
export interface AgentCompactionRequest {
|
|
34
|
+
customInstructions: string | null;
|
|
35
|
+
}
|
|
36
|
+
export interface AgentNavigationRequest {
|
|
37
|
+
targetId: string | null;
|
|
38
|
+
summarize: boolean;
|
|
39
|
+
label: string | null;
|
|
40
|
+
customInstructions: string | null;
|
|
41
|
+
}
|
|
42
|
+
/** Presentation-safe command facade over the worker-owned main AgentLane. */
|
|
43
|
+
export interface AgentController {
|
|
44
|
+
prompt(request: AgentPromptRequest, context: Context): Promise<AgentOperationResponse>;
|
|
45
|
+
requestAbort(operationId: string, context: Context): Promise<void>;
|
|
46
|
+
steer(request: AgentPromptRequest, context: Context): Promise<AgentQueueResponse>;
|
|
47
|
+
followUp(request: AgentPromptRequest, context: Context): Promise<AgentQueueResponse>;
|
|
48
|
+
nextRun(request: AgentPromptRequest, context: Context): Promise<AgentQueueResponse>;
|
|
49
|
+
cancelQueued(entryId: string, context: Context): Promise<{
|
|
50
|
+
outcome: "cancelled" | "already_consumed" | "not_found";
|
|
51
|
+
}>;
|
|
52
|
+
resume(context: Context): Promise<AgentOperationResponse>;
|
|
53
|
+
compact(request: AgentCompactionRequest, context: Context): Promise<AgentOperationResponse>;
|
|
54
|
+
navigate(request: AgentNavigationRequest, context: Context): Promise<AgentOperationResponse>;
|
|
55
|
+
}
|
|
56
|
+
export declare const AgentController: import("@earendil-works/chord").Service<AgentController>;
|
|
57
|
+
//# sourceMappingURL=agent-controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-controller.d.ts","sourceRoot":"","sources":["../../../src/experimental/services/agent-controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAiB,MAAM,uBAAuB,CAAC;AAEpE,MAAM,WAAW,gBAAgB;IAChC,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,kBAAkB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,gBAAgB,EAAE,GAAG,IAAI,CAAC;CAClC;AAED,MAAM,WAAW,mBAAmB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,sBAAsB,GAC/B;IAAE,QAAQ,EAAE,IAAI,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,mBAAmB,GAAG,IAAI,CAAA;CAAE,GAC1E;IAAE,QAAQ,EAAE,KAAK,CAAC;IAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,KAAK,EAAE,mBAAmB,CAAA;CAAE,CAAC;AAE/E,MAAM,MAAM,kBAAkB,GAC3B;IAAE,QAAQ,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,IAAI,CAAA;CAAE,GAChD;IAAE,QAAQ,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,mBAAmB,CAAA;CAAE,CAAC;AAElE,MAAM,WAAW,sBAAsB;IACtC,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;CAClC;AAED,MAAM,WAAW,sBAAsB;IACtC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;CAClC;AAED,6EAA6E;AAC7E,MAAM,WAAW,eAAe;IAC/B,MAAM,CAAC,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC;IACvF,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnE,KAAK,CAAC,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAClF,QAAQ,CAAC,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACrF,OAAO,CAAC,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACpF,YAAY,CACX,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,GACd,OAAO,CAAC;QAAE,OAAO,EAAE,WAAW,GAAG,kBAAkB,GAAG,WAAW,CAAA;KAAE,CAAC,CAAC;IACxE,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC;IAC1D,OAAO,CAAC,OAAO,EAAE,sBAAsB,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC;IAC5F,QAAQ,CAAC,OAAO,EAAE,sBAAsB,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC;CAC7F;AAED,eAAO,MAAM,eAAe,0DAAwD,CAAC","sourcesContent":["import { type Context, defineService } from \"@earendil-works/chord\";\n\nexport interface AgentPromptImage {\n\ttype: \"image\";\n\tdata: string;\n\tmimeType: string;\n}\n\nexport interface AgentPromptRequest {\n\tmessage: string;\n\timages: AgentPromptImage[] | null;\n}\n\nexport interface AgentOperationError {\n\tcode: string;\n\tmessage: string;\n}\n\nexport type AgentOperationResponse =\n\t| { accepted: true; operationId: string; error: AgentOperationError | null }\n\t| { accepted: false; operationId: string | null; error: AgentOperationError };\n\nexport type AgentQueueResponse =\n\t| { accepted: true; entryId: string; error: null }\n\t| { accepted: false; entryId: null; error: AgentOperationError };\n\nexport interface AgentCompactionRequest {\n\tcustomInstructions: string | null;\n}\n\nexport interface AgentNavigationRequest {\n\ttargetId: string | null;\n\tsummarize: boolean;\n\tlabel: string | null;\n\tcustomInstructions: string | null;\n}\n\n/** Presentation-safe command facade over the worker-owned main AgentLane. */\nexport interface AgentController {\n\tprompt(request: AgentPromptRequest, context: Context): Promise<AgentOperationResponse>;\n\trequestAbort(operationId: string, context: Context): Promise<void>;\n\tsteer(request: AgentPromptRequest, context: Context): Promise<AgentQueueResponse>;\n\tfollowUp(request: AgentPromptRequest, context: Context): Promise<AgentQueueResponse>;\n\tnextRun(request: AgentPromptRequest, context: Context): Promise<AgentQueueResponse>;\n\tcancelQueued(\n\t\tentryId: string,\n\t\tcontext: Context,\n\t): Promise<{ outcome: \"cancelled\" | \"already_consumed\" | \"not_found\" }>;\n\tresume(context: Context): Promise<AgentOperationResponse>;\n\tcompact(request: AgentCompactionRequest, context: Context): Promise<AgentOperationResponse>;\n\tnavigate(request: AgentNavigationRequest, context: Context): Promise<AgentOperationResponse>;\n}\n\nexport const AgentController = defineService<AgentController>(\"pi.agent-controller\");\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-controller.js","sourceRoot":"","sources":["../../../src/experimental/services/agent-controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAqDpE,MAAM,CAAC,MAAM,eAAe,GAAG,aAAa,CAAkB,qBAAqB,CAAC,CAAC","sourcesContent":["import { type Context, defineService } from \"@earendil-works/chord\";\n\nexport interface AgentPromptImage {\n\ttype: \"image\";\n\tdata: string;\n\tmimeType: string;\n}\n\nexport interface AgentPromptRequest {\n\tmessage: string;\n\timages: AgentPromptImage[] | null;\n}\n\nexport interface AgentOperationError {\n\tcode: string;\n\tmessage: string;\n}\n\nexport type AgentOperationResponse =\n\t| { accepted: true; operationId: string; error: AgentOperationError | null }\n\t| { accepted: false; operationId: string | null; error: AgentOperationError };\n\nexport type AgentQueueResponse =\n\t| { accepted: true; entryId: string; error: null }\n\t| { accepted: false; entryId: null; error: AgentOperationError };\n\nexport interface AgentCompactionRequest {\n\tcustomInstructions: string | null;\n}\n\nexport interface AgentNavigationRequest {\n\ttargetId: string | null;\n\tsummarize: boolean;\n\tlabel: string | null;\n\tcustomInstructions: string | null;\n}\n\n/** Presentation-safe command facade over the worker-owned main AgentLane. */\nexport interface AgentController {\n\tprompt(request: AgentPromptRequest, context: Context): Promise<AgentOperationResponse>;\n\trequestAbort(operationId: string, context: Context): Promise<void>;\n\tsteer(request: AgentPromptRequest, context: Context): Promise<AgentQueueResponse>;\n\tfollowUp(request: AgentPromptRequest, context: Context): Promise<AgentQueueResponse>;\n\tnextRun(request: AgentPromptRequest, context: Context): Promise<AgentQueueResponse>;\n\tcancelQueued(\n\t\tentryId: string,\n\t\tcontext: Context,\n\t): Promise<{ outcome: \"cancelled\" | \"already_consumed\" | \"not_found\" }>;\n\tresume(context: Context): Promise<AgentOperationResponse>;\n\tcompact(request: AgentCompactionRequest, context: Context): Promise<AgentOperationResponse>;\n\tnavigate(request: AgentNavigationRequest, context: Context): Promise<AgentOperationResponse>;\n}\n\nexport const AgentController = defineService<AgentController>(\"pi.agent-controller\");\n"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type Context, type RemoteServiceSource, type ReplicatedState } from "@earendil-works/chord";
|
|
2
|
+
import { type Client } from "@earendil-works/pi-client";
|
|
3
|
+
export type ServerConnectionState = {
|
|
4
|
+
status: "connecting";
|
|
5
|
+
attempt: number;
|
|
6
|
+
} | {
|
|
7
|
+
status: "connected";
|
|
8
|
+
since: string;
|
|
9
|
+
} | {
|
|
10
|
+
status: "disconnected";
|
|
11
|
+
since: string;
|
|
12
|
+
reason: string;
|
|
13
|
+
retryAt: string | null;
|
|
14
|
+
};
|
|
15
|
+
export type SessionAttachmentState = {
|
|
16
|
+
status: "detached";
|
|
17
|
+
} | {
|
|
18
|
+
status: "attaching" | "attached" | "degraded";
|
|
19
|
+
sessionId: string;
|
|
20
|
+
};
|
|
21
|
+
export interface ServerServiceSource extends RemoteServiceSource {
|
|
22
|
+
readonly connection: ReplicatedState<ServerConnectionState>;
|
|
23
|
+
dispose(context: Context): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export interface SessionServiceSource extends RemoteServiceSource {
|
|
26
|
+
readonly attachment: ReplicatedState<SessionAttachmentState>;
|
|
27
|
+
/** Wait for the exact current attachment generation to finish hydrating. */
|
|
28
|
+
whenAttached(sessionId: string, context: Context): Promise<void>;
|
|
29
|
+
/** Wait for every binding to finish releasing the previous attachment. */
|
|
30
|
+
whenDetached(context: Context): Promise<void>;
|
|
31
|
+
dispose(context: Context): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
export interface ServiceSourceOptions {
|
|
34
|
+
readonly onError?: (error: Error) => void;
|
|
35
|
+
}
|
|
36
|
+
/** Create the server-scoped remote service source for one presentation client. */
|
|
37
|
+
export declare function createServerServiceSource(client: Client, options?: ServiceSourceOptions): ServerServiceSource;
|
|
38
|
+
/** Create the selected-Session remote service source for one presentation client. */
|
|
39
|
+
export declare function createSessionServiceSource(client: Client, options?: ServiceSourceOptions): SessionServiceSource;
|
|
40
|
+
//# sourceMappingURL=connection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../../src/experimental/services/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,OAAO,EAIZ,KAAK,mBAAmB,EAGxB,K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,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAC1C;AAsTD,kFAAkF;AAClF,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,oBAAyB,GAAG,mBAAmB,CAEjH;AAED,qFAAqF;AACrF,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,oBAAyB,GAAG,oBAAoB,CAEnH","sourcesContent":["import {\n\ttype Context,\n\tcreateRemoteServiceBinding,\n\ttype MutableReplicatedState,\n\ttype RemoteServiceBinding,\n\ttype RemoteServiceSource,\n\ttype RemoteServices,\n\ttype RemoteServiceTransport,\n\ttype ReplicatedState,\n\treplicatedState,\n\ttype Service,\n\ttype ServiceCatalogueEntry,\n} from \"@earendil-works/chord\";\nimport { BACKGROUND_CONTEXT } from \"@earendil-works/chord/context\";\nimport { type Client, createClientServiceTransport } from \"@earendil-works/pi-client\";\nimport type { SessionTarget } from \"@earendil-works/pi-protocol\";\n\nexport type ServerConnectionState =\n\t| { status: \"connecting\"; attempt: number }\n\t| { status: \"connected\"; since: string }\n\t| { status: \"disconnected\"; since: string; reason: string; retryAt: string | null };\n\nexport type SessionAttachmentState =\n\t| { status: \"detached\" }\n\t| { status: \"attaching\" | \"attached\" | \"degraded\"; sessionId: string };\n\nexport interface ServerServiceSource extends RemoteServiceSource {\n\treadonly connection: ReplicatedState<ServerConnectionState>;\n\tdispose(context: Context): Promise<void>;\n}\n\nexport interface SessionServiceSource extends RemoteServiceSource {\n\treadonly attachment: ReplicatedState<SessionAttachmentState>;\n\t/** Wait for the exact current attachment generation to finish hydrating. */\n\twhenAttached(sessionId: string, context: Context): Promise<void>;\n\t/** Wait for every binding to finish releasing the previous attachment. */\n\twhenDetached(context: Context): Promise<void>;\n\tdispose(context: Context): Promise<void>;\n}\n\nexport interface ServiceSourceOptions {\n\treadonly onError?: (error: Error) => void;\n}\n\nclass RoutedServiceBinding implements RemoteServices {\n\treadonly #services: RemoteServiceBinding;\n\treadonly #getBound: () => boolean;\n\treadonly #onActivate: (context: Context) => Promise<void>;\n\treadonly #remove: () => void;\n\t#activated = false;\n\t#activationComplete = false;\n\n\tconstructor(options: {\n\t\treadonly services: readonly { readonly id: string }[];\n\t\treadonly transport: RemoteServiceTransport;\n\t\treadonly getBound: () => boolean;\n\t\treadonly assertAccess: () => void;\n\t\treadonly onError: (error: Error) => void;\n\t\treadonly onActivate?: (context: Context) => Promise<void>;\n\t\treadonly remove: () => void;\n\t}) {\n\t\tthis.#services = createRemoteServiceBinding({\n\t\t\tservices: options.services,\n\t\t\ttransport: options.transport,\n\t\t\tbound: false,\n\t\t\tassertAccess: options.assertAccess,\n\t\t\tonError: options.onError,\n\t\t});\n\t\tthis.#getBound = options.getBound;\n\t\tthis.#onActivate = options.onActivate ?? (() => Promise.resolve());\n\t\tthis.#remove = options.remove;\n\t}\n\n\tuse<T>(service: Service<T>): T {\n\t\treturn this.#services.use(service);\n\t}\n\n\tobserve<T>(service: Service<T>, handler: (service: T, context: Context) => void | Promise<void>): () => void {\n\t\treturn this.#services.observe(service, handler);\n\t}\n\n\tasync ready(context: Context): Promise<void> {\n\t\tif (!this.#activated) {\n\t\t\tthis.#activated = true;\n\t\t\tawait this.#services.rebind(this.#getBound(), context);\n\t\t}\n\t\tawait this.serviceReady(context);\n\t\tif (!this.#activationComplete) {\n\t\t\tawait this.#onActivate(context);\n\t\t\tthis.#activationComplete = true;\n\t\t}\n\t}\n\n\tserviceReady(context: Context): Promise<void> {\n\t\treturn this.#services.ready(context);\n\t}\n\n\tupdateBound(bound: boolean, context: Context): Promise<void> {\n\t\treturn this.#activated ? this.#services.rebind(bound, context) : Promise.resolve();\n\t}\n\n\tasync dispose(context: Context): Promise<void> {\n\t\tthis.#remove();\n\t\tawait this.#services.dispose(context);\n\t}\n}\n\nclass ServerServiceSourceImpl implements ServerServiceSource {\n\treadonly acceptsUnavailableServices = false;\n\treadonly connection: ReplicatedState<ServerConnectionState>;\n\treadonly #client: Client;\n\treadonly #transport: RemoteServiceTransport;\n\treadonly #bindings = new Set<RoutedServiceBinding>();\n\treadonly #removeConnectionListener: () => void;\n\treadonly #onError: (error: Error) => void;\n\t#transition = Promise.resolve();\n\t#connectionAttempt: number;\n\t#disposed = false;\n\n\tconstructor(client: Client, options: ServiceSourceOptions) {\n\t\tthis.#client = client;\n\t\tthis.#transport = createClientServiceTransport(client, () => ({ serverId: client.serverId }));\n\t\tthis.#onError = options.onError ?? (() => {});\n\t\tthis.#connectionAttempt = client.connectionState === \"connecting\" ? 1 : 0;\n\t\tconst connectionState = replicatedState<ServerConnectionState>(\n\t\t\ttoServerConnectionState(client, this.#connectionAttempt),\n\t\t);\n\t\tthis.connection = connectionState;\n\t\tthis.#removeConnectionListener = client.onConnectionStateChange(({ state, error }) => {\n\t\t\tif (state === \"connecting\") this.#connectionAttempt += 1;\n\t\t\tpublishReplacement(\n\t\t\t\tconnectionState,\n\t\t\t\ttoServerConnectionState(client, this.#connectionAttempt, error),\n\t\t\t\tBACKGROUND_CONTEXT,\n\t\t\t);\n\t\t\tthis.#transition = this.#transition\n\t\t\t\t.then(async () => {\n\t\t\t\t\tconst results = await Promise.allSettled(\n\t\t\t\t\t\t[...this.#bindings].map((binding) => binding.updateBound(state === \"connected\", BACKGROUND_CONTEXT)),\n\t\t\t\t\t);\n\t\t\t\t\tconst failures = results.filter(\n\t\t\t\t\t\t(result): result is PromiseRejectedResult => result.status === \"rejected\",\n\t\t\t\t\t);\n\t\t\t\t\tif (failures.length > 0) throw new AggregateError(failures.map(({ reason }) => reason));\n\t\t\t\t})\n\t\t\t\t.catch((transitionError: unknown) => this.#onError(toError(transitionError)));\n\t\t});\n\t}\n\n\tcatalogue(context: Context) {\n\t\treturn this.#client.serviceCatalogue({ serverId: this.#client.serverId }, context.abortSignal);\n\t}\n\n\topen(options: {\n\t\treadonly services: readonly { readonly id: string }[];\n\t\tassertAccess(): void;\n\t\tonError(error: Error): void;\n\t}): RemoteServices {\n\t\tif (this.#disposed) throw new Error(\"Server service source is disposed\");\n\t\tlet binding!: RoutedServiceBinding;\n\t\tbinding = new RoutedServiceBinding({\n\t\t\tservices: options.services,\n\t\t\ttransport: this.#transport,\n\t\t\tgetBound: () => this.#client.connected,\n\t\t\tassertAccess: options.assertAccess,\n\t\t\tonError: options.onError,\n\t\t\tremove: () => this.#bindings.delete(binding),\n\t\t});\n\t\tthis.#bindings.add(binding);\n\t\treturn binding;\n\t}\n\n\tasync dispose(context: Context): Promise<void> {\n\t\tif (this.#disposed) return;\n\t\tthis.#disposed = true;\n\t\tthis.#removeConnectionListener();\n\t\tawait this.#transition;\n\t\tconst bindings = [...this.#bindings];\n\t\tthis.#bindings.clear();\n\t\tconst results = await Promise.allSettled(bindings.map((binding) => binding.dispose(context)));\n\t\tthrowFailures(results, \"Failed to dispose server service source\");\n\t}\n}\n\nclass SessionServiceSourceImpl implements SessionServiceSource {\n\treadonly attachment: ReplicatedState<SessionAttachmentState>;\n\treadonly #client: Client;\n\treadonly #transport: RemoteServiceTransport;\n\treadonly #attachmentState: MutableReplicatedState<SessionAttachmentState>;\n\treadonly #bindings = new Set<RoutedServiceBinding>();\n\treadonly #removeAttachmentListener: () => void;\n\treadonly #onError: (error: Error) => void;\n\treadonly #transitions = new Set<Promise<void>>();\n\t#catalogue: readonly ServiceCatalogueEntry[] | undefined;\n\t#attachmentRevision = 0;\n\t#disposed = false;\n\n\tget acceptsUnavailableServices(): boolean {\n\t\treturn this.#client.attachment === undefined && this.#catalogue === undefined;\n\t}\n\n\tconstructor(client: Client, options: ServiceSourceOptions) {\n\t\tthis.#client = client;\n\t\tthis.#transport = createClientServiceTransport(client, () => client.attachment);\n\t\tthis.#onError = options.onError ?? (() => {});\n\t\tthis.#attachmentState = replicatedState<SessionAttachmentState>(\n\t\t\tclient.attachment === undefined\n\t\t\t\t? { status: \"detached\" }\n\t\t\t\t: { status: \"attaching\", sessionId: client.attachment.sessionId },\n\t\t);\n\t\tthis.attachment = this.#attachmentState;\n\t\tthis.#removeAttachmentListener = client.onAttachmentChange((attachment) => {\n\t\t\tconst revision = ++this.#attachmentRevision;\n\t\t\tif (attachment !== undefined) {\n\t\t\t\tpublishReplacement(\n\t\t\t\t\tthis.#attachmentState,\n\t\t\t\t\t{ status: \"attaching\", sessionId: attachment.sessionId },\n\t\t\t\t\tBACKGROUND_CONTEXT,\n\t\t\t\t);\n\t\t\t\tvoid this.#client.serviceCatalogue(attachment).then(\n\t\t\t\t\t(catalogue) => {\n\t\t\t\t\t\tif (this.#attachmentRevision === revision && sameAttachment(this.#client.attachment, attachment)) {\n\t\t\t\t\t\t\tthis.#catalogue = catalogue;\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\t(error: unknown) => this.#onError(toError(error)),\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst transition = this.#rebind(attachment !== undefined, BACKGROUND_CONTEXT);\n\t\t\tthis.#transitions.add(transition);\n\t\t\tvoid transition.then(\n\t\t\t\t() => {\n\t\t\t\t\tthis.#transitions.delete(transition);\n\t\t\t\t\tif (this.#attachmentRevision !== revision || !sameAttachment(this.#client.attachment, attachment))\n\t\t\t\t\t\treturn;\n\t\t\t\t\tpublishReplacement(\n\t\t\t\t\t\tthis.#attachmentState,\n\t\t\t\t\t\tattachment === undefined\n\t\t\t\t\t\t\t? { status: \"detached\" }\n\t\t\t\t\t\t\t: { status: \"attached\", sessionId: attachment.sessionId },\n\t\t\t\t\t\tBACKGROUND_CONTEXT,\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\t(error: unknown) => {\n\t\t\t\t\tthis.#transitions.delete(transition);\n\t\t\t\t\tif (this.#attachmentRevision !== revision || !sameAttachment(this.#client.attachment, attachment))\n\t\t\t\t\t\treturn;\n\t\t\t\t\tpublishReplacement(\n\t\t\t\t\t\tthis.#attachmentState,\n\t\t\t\t\t\tattachment === undefined\n\t\t\t\t\t\t\t? { status: \"detached\" }\n\t\t\t\t\t\t\t: { status: \"degraded\", sessionId: attachment.sessionId },\n\t\t\t\t\t\tBACKGROUND_CONTEXT,\n\t\t\t\t\t);\n\t\t\t\t\tthis.#onError(toError(error));\n\t\t\t\t},\n\t\t\t);\n\t\t});\n\t}\n\n\tasync catalogue(context: Context): Promise<readonly ServiceCatalogueEntry[]> {\n\t\tconst target = this.#client.attachment;\n\t\tif (target === undefined) return this.#catalogue ?? [];\n\t\tconst catalogue = await this.#client.serviceCatalogue(target, context.abortSignal);\n\t\tthis.#catalogue = catalogue;\n\t\treturn catalogue;\n\t}\n\n\topen(options: {\n\t\treadonly services: readonly { readonly id: string }[];\n\t\tassertAccess(): void;\n\t\tonError(error: Error): void;\n\t}): RemoteServices {\n\t\tif (this.#disposed) throw new Error(\"Session service source is disposed\");\n\t\tlet binding!: RoutedServiceBinding;\n\t\tbinding = new RoutedServiceBinding({\n\t\t\tservices: options.services,\n\t\t\ttransport: this.#transport,\n\t\t\tgetBound: () => this.#client.attachment !== undefined,\n\t\t\tonActivate: async (context) => {\n\t\t\t\tconst attachment = this.#client.attachment;\n\t\t\t\tif (attachment === undefined) await this.#whenDetached(this.#attachmentRevision, context);\n\t\t\t\telse await this.#whenAttached(attachment, this.#attachmentRevision, context);\n\t\t\t},\n\t\t\tassertAccess: options.assertAccess,\n\t\t\tonError: options.onError,\n\t\t\tremove: () => this.#bindings.delete(binding),\n\t\t});\n\t\tthis.#bindings.add(binding);\n\t\treturn binding;\n\t}\n\n\tasync whenAttached(sessionId: string, context: Context): Promise<void> {\n\t\tconst attachment = this.#client.attachment;\n\t\tif (attachment === undefined || attachment.sessionId !== sessionId) {\n\t\t\tthrow new Error(`Session ${sessionId} is not the current attachment`);\n\t\t}\n\t\tawait this.#whenAttached(attachment, this.#attachmentRevision, context);\n\t}\n\n\tasync whenDetached(context: Context): Promise<void> {\n\t\tif (this.#client.attachment !== undefined) throw new Error(\"A Session is still attached\");\n\t\tawait this.#whenDetached(this.#attachmentRevision, context);\n\t}\n\n\tasync dispose(context: Context): Promise<void> {\n\t\tif (this.#disposed) return;\n\t\tthis.#disposed = true;\n\t\tthis.#removeAttachmentListener();\n\t\tawait Promise.allSettled(this.#transitions);\n\t\tconst bindings = [...this.#bindings];\n\t\tthis.#bindings.clear();\n\t\tconst results = await Promise.allSettled(bindings.map((binding) => binding.dispose(context)));\n\t\tthrowFailures(results, \"Failed to dispose Session service source\");\n\t}\n\n\tasync #rebind(bound: boolean, context: Context): Promise<void> {\n\t\tconst results = await Promise.allSettled(\n\t\t\t[...this.#bindings].map((binding) => binding.updateBound(bound, context)),\n\t\t);\n\t\tthrowFailures(results, \"Failed to rebind Session services\");\n\t}\n\n\tasync #whenAttached(attachment: SessionTarget, revision: number, context: Context): Promise<void> {\n\t\ttry {\n\t\t\tawait Promise.all([...this.#bindings].map((binding) => binding.serviceReady(context)));\n\t\t} catch (error) {\n\t\t\tif (this.#attachmentRevision === revision && sameAttachment(this.#client.attachment, attachment)) {\n\t\t\t\tpublishReplacement(this.#attachmentState, { status: \"degraded\", sessionId: attachment.sessionId }, context);\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t\tif (this.#attachmentRevision !== revision || !sameAttachment(this.#client.attachment, attachment)) {\n\t\t\tthrow new Error(`Session ${attachment.sessionId} was replaced while attaching`);\n\t\t}\n\t\tconst state = this.#attachmentState.value;\n\t\tif (state.status !== \"attached\" || state.sessionId !== attachment.sessionId) {\n\t\t\tpublishReplacement(this.#attachmentState, { status: \"attached\", sessionId: attachment.sessionId }, context);\n\t\t}\n\t}\n\n\tasync #whenDetached(revision: number, context: Context): Promise<void> {\n\t\tawait Promise.all([...this.#bindings].map((binding) => binding.serviceReady(context)));\n\t\tif (this.#attachmentRevision !== revision || this.#client.attachment !== undefined) {\n\t\t\tthrow new Error(\"The Session attachment changed while detaching\");\n\t\t}\n\t\tif (this.#attachmentState.value.status !== \"detached\") {\n\t\t\tpublishReplacement(this.#attachmentState, { status: \"detached\" }, context);\n\t\t}\n\t}\n}\n\n/** Create the server-scoped remote service source for one presentation client. */\nexport function createServerServiceSource(client: Client, options: ServiceSourceOptions = {}): ServerServiceSource {\n\treturn new ServerServiceSourceImpl(client, options);\n}\n\n/** Create the selected-Session remote service source for one presentation client. */\nexport function createSessionServiceSource(client: Client, options: ServiceSourceOptions = {}): SessionServiceSource {\n\treturn new SessionServiceSourceImpl(client, options);\n}\n\nfunction publishReplacement<T extends object>(state: MutableReplicatedState<T>, value: T, context: Context): void {\n\tconst target = state.state as Record<string, unknown>;\n\tconst replacement = value as Record<string, unknown>;\n\tfor (const key of Object.keys(target)) {\n\t\tif (!Object.hasOwn(replacement, key)) delete target[key];\n\t}\n\tObject.assign(target, replacement);\n\tstate.publish(context);\n}\n\nfunction toServerConnectionState(client: Client, attempt: number, error?: Error): ServerConnectionState {\n\tconst since = new Date().toISOString();\n\tswitch (client.connectionState) {\n\t\tcase \"connecting\":\n\t\t\treturn { status: \"connecting\", attempt };\n\t\tcase \"connected\":\n\t\t\treturn { status: \"connected\", since };\n\t\tcase \"disconnected\":\n\t\t\treturn {\n\t\t\t\tstatus: \"disconnected\",\n\t\t\t\tsince,\n\t\t\t\treason: error?.message ?? \"Client is disconnected\",\n\t\t\t\tretryAt: null,\n\t\t\t};\n\t}\n}\n\nfunction sameAttachment(left: SessionTarget | undefined, right: SessionTarget | undefined): boolean {\n\tif (left === undefined || right === undefined) return left === right;\n\treturn (\n\t\tleft.serverId === right.serverId && left.sessionId === right.sessionId && left.attachmentId === right.attachmentId\n\t);\n}\n\nfunction throwFailures(results: readonly PromiseSettledResult<unknown>[], message: string): void {\n\tconst errors = results.flatMap((result) => (result.status === \"rejected\" ? [result.reason] : []));\n\tif (errors.length === 1) throw errors[0];\n\tif (errors.length > 1) throw new AggregateError(errors, message);\n}\n\nfunction toError(error: unknown): Error {\n\treturn error instanceof Error ? error : new Error(String(error));\n}\n"]}
|