@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,582 @@
|
|
|
1
|
+
import { DEFAULT_MAX_FRAME_LENGTH } from "@earendil-works/pi-protocol";
|
|
2
|
+
import { WebSocket } from "undici";
|
|
3
|
+
export const RADIUS_RELAY_HOST_SUBPROTOCOL = "pi-session-relay.host.v1";
|
|
4
|
+
export const RADIUS_RELAY_CLIENT_SUBPROTOCOL = "pi-session-relay.client.v1";
|
|
5
|
+
const RELAY_DATA_HEADER_BYTES = 18;
|
|
6
|
+
const RELAY_DATA_FRAME_VERSION = 1;
|
|
7
|
+
const RELAY_DATA_FRAME_TYPE = 1;
|
|
8
|
+
const CONNECTION_ID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/u;
|
|
9
|
+
const MAX_PENDING_BYTES = DEFAULT_MAX_FRAME_LENGTH * 4;
|
|
10
|
+
const DRAIN_THRESHOLD_BYTES = 1024 * 1024;
|
|
11
|
+
const HOST_RETRY_INITIAL_MS = 1_000;
|
|
12
|
+
const HOST_RETRY_MAX_MS = 30_000;
|
|
13
|
+
const MISSING_AUTH_RETRY_MS = 30_000;
|
|
14
|
+
const CLIENT_RETRY_INITIAL_MS = 1_000;
|
|
15
|
+
const CLIENT_RETRY_MAX_MS = 30_000;
|
|
16
|
+
// Undici implements the browser WebSocket API, which permits callers to send
|
|
17
|
+
// only code 1000 or application codes from 3000 through 4999. RFC protocol
|
|
18
|
+
// codes such as 1002 and 1011 may be received but cannot be passed to close().
|
|
19
|
+
const LOCAL_PROTOCOL_ERROR_CLOSE_CODE = 4000;
|
|
20
|
+
const LOCAL_TRANSPORT_ERROR_CLOSE_CODE = 4001;
|
|
21
|
+
/** Maintain the experimental server's multiplexed, authenticated Radius host connection. */
|
|
22
|
+
export class RadiusRelayHost {
|
|
23
|
+
#options;
|
|
24
|
+
#abortController = new AbortController();
|
|
25
|
+
#connections = new Map();
|
|
26
|
+
#socket;
|
|
27
|
+
#writer;
|
|
28
|
+
#loop;
|
|
29
|
+
#closed = false;
|
|
30
|
+
constructor(options) {
|
|
31
|
+
this.#options = options;
|
|
32
|
+
}
|
|
33
|
+
start() {
|
|
34
|
+
if (this.#loop !== undefined)
|
|
35
|
+
return;
|
|
36
|
+
this.#loop = this.#run();
|
|
37
|
+
}
|
|
38
|
+
async close() {
|
|
39
|
+
if (this.#closed)
|
|
40
|
+
return;
|
|
41
|
+
this.#closed = true;
|
|
42
|
+
this.#abortController.abort();
|
|
43
|
+
this.#writer?.close();
|
|
44
|
+
this.#socket?.close(1000, "Pi server stopped");
|
|
45
|
+
this.#dropConnections();
|
|
46
|
+
await this.#loop;
|
|
47
|
+
}
|
|
48
|
+
async #run() {
|
|
49
|
+
let retryMs = HOST_RETRY_INITIAL_MS;
|
|
50
|
+
while (!this.#closed) {
|
|
51
|
+
try {
|
|
52
|
+
const auth = await this.#options.auth.resolve({
|
|
53
|
+
required: false,
|
|
54
|
+
signal: this.#abortController.signal,
|
|
55
|
+
});
|
|
56
|
+
if (auth === undefined) {
|
|
57
|
+
this.#options.onStatus?.({ status: "not_authenticated" });
|
|
58
|
+
await delay(MISSING_AUTH_RETRY_MS, this.#abortController.signal, true);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
this.#options.onStatus?.({ status: "connecting" });
|
|
62
|
+
const socket = await openRadiusRelayWebSocket(relayWebSocketUrl(auth.gateway, this.#options.serverId), RADIUS_RELAY_HOST_SUBPROTOCOL, auth.token, this.#options.webSocketFactory ?? defaultWebSocketFactory, this.#abortController.signal);
|
|
63
|
+
retryMs = HOST_RETRY_INITIAL_MS;
|
|
64
|
+
this.#options.onStatus?.({ status: "connected" });
|
|
65
|
+
await this.#serve(socket);
|
|
66
|
+
if (!this.#closed)
|
|
67
|
+
throw new Error("Radius relay host disconnected");
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
if (this.#closed || this.#abortController.signal.aborted)
|
|
71
|
+
break;
|
|
72
|
+
this.#options.onStatus?.({ status: "retrying", error: errorMessage(error) });
|
|
73
|
+
try {
|
|
74
|
+
await delay(retryMs, this.#abortController.signal, true);
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
retryMs = Math.min(retryMs * 2, HOST_RETRY_MAX_MS);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
#serve(socket) {
|
|
84
|
+
this.#socket = socket;
|
|
85
|
+
this.#writer = new OrderedWebSocketWriter(socket);
|
|
86
|
+
return new Promise((resolve, reject) => {
|
|
87
|
+
let terminal = false;
|
|
88
|
+
const cleanup = () => {
|
|
89
|
+
socket.removeEventListener("message", onMessage);
|
|
90
|
+
socket.removeEventListener("close", onClose);
|
|
91
|
+
socket.removeEventListener("error", onError);
|
|
92
|
+
this.#writer?.close();
|
|
93
|
+
if (this.#socket === socket) {
|
|
94
|
+
this.#socket = undefined;
|
|
95
|
+
this.#writer = undefined;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
const finish = (error) => {
|
|
99
|
+
if (terminal)
|
|
100
|
+
return;
|
|
101
|
+
terminal = true;
|
|
102
|
+
cleanup();
|
|
103
|
+
this.#dropConnections(error);
|
|
104
|
+
if (error)
|
|
105
|
+
reject(error);
|
|
106
|
+
else
|
|
107
|
+
resolve();
|
|
108
|
+
};
|
|
109
|
+
const onMessage = (event) => {
|
|
110
|
+
try {
|
|
111
|
+
this.#handleHostMessage(event.data);
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
closeWebSocket(socket, LOCAL_PROTOCOL_ERROR_CLOSE_CODE, "Radius relay protocol error");
|
|
115
|
+
finish(toError(error));
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
const onClose = (event) => {
|
|
119
|
+
finish(event.code === 1000
|
|
120
|
+
? undefined
|
|
121
|
+
: new Error(`Radius relay host closed (${event.code}${event.reason ? `: ${event.reason}` : ""})`));
|
|
122
|
+
};
|
|
123
|
+
const onError = (event) => finish(webSocketError(event));
|
|
124
|
+
socket.addEventListener("message", onMessage);
|
|
125
|
+
socket.addEventListener("close", onClose);
|
|
126
|
+
socket.addEventListener("error", onError);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
#handleHostMessage(value) {
|
|
130
|
+
if (typeof value === "string") {
|
|
131
|
+
const control = parseHostControlMessage(value);
|
|
132
|
+
switch (control.type) {
|
|
133
|
+
case "ping":
|
|
134
|
+
void this.#sendControl({ version: 1, type: "pong" }).catch(() => {
|
|
135
|
+
if (this.#socket !== undefined) {
|
|
136
|
+
closeWebSocket(this.#socket, LOCAL_TRANSPORT_ERROR_CLOSE_CODE, "Radius relay send failed");
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
return;
|
|
140
|
+
case "pong":
|
|
141
|
+
return;
|
|
142
|
+
case "connection_open":
|
|
143
|
+
this.#openConnection(control.connection_id);
|
|
144
|
+
return;
|
|
145
|
+
case "connection_close":
|
|
146
|
+
this.#remoteCloseConnection(control.connection_id);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (!(value instanceof ArrayBuffer))
|
|
151
|
+
throw new Error("Radius relay data message must be binary");
|
|
152
|
+
const frame = parseRelayDataFrame(value);
|
|
153
|
+
if (!frame)
|
|
154
|
+
throw new Error("Invalid Radius relay data frame");
|
|
155
|
+
const active = this.#connections.get(frame.connectionId);
|
|
156
|
+
if (!active) {
|
|
157
|
+
void this.#sendControl({
|
|
158
|
+
version: 1,
|
|
159
|
+
type: "connection_close",
|
|
160
|
+
connection_id: frame.connectionId,
|
|
161
|
+
code: 1000,
|
|
162
|
+
});
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
active.handler.onData(new Uint8Array(frame.payload));
|
|
166
|
+
}
|
|
167
|
+
#openConnection(connectionId) {
|
|
168
|
+
if (this.#connections.has(connectionId))
|
|
169
|
+
throw new Error("Radius relay reused a connection ID");
|
|
170
|
+
const connection = new RelayServerByteConnection((chunk) => this.#sendData(connectionId, chunk), (finalChunk) => this.#serverCloseConnection(connectionId, finalChunk));
|
|
171
|
+
const handler = this.#options.server.accept(connection);
|
|
172
|
+
if (connection.closed) {
|
|
173
|
+
void this.#sendControl({ version: 1, type: "connection_close", connection_id: connectionId, code: 1012 });
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
this.#connections.set(connectionId, { connection, handler });
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
#remoteCloseConnection(connectionId) {
|
|
180
|
+
const active = this.#connections.get(connectionId);
|
|
181
|
+
if (!active)
|
|
182
|
+
return;
|
|
183
|
+
this.#connections.delete(connectionId);
|
|
184
|
+
active.connection.markClosed();
|
|
185
|
+
active.handler.onClose();
|
|
186
|
+
}
|
|
187
|
+
async #serverCloseConnection(connectionId, finalChunk) {
|
|
188
|
+
if (!this.#connections.delete(connectionId))
|
|
189
|
+
return;
|
|
190
|
+
if (finalChunk !== undefined)
|
|
191
|
+
await this.#requireWriter().send(encodeRelayDataFrame(connectionId, finalChunk));
|
|
192
|
+
await this.#sendControl({
|
|
193
|
+
version: 1,
|
|
194
|
+
type: "connection_close",
|
|
195
|
+
connection_id: connectionId,
|
|
196
|
+
code: 1000,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
#sendData(connectionId, chunk) {
|
|
200
|
+
if (!this.#connections.has(connectionId))
|
|
201
|
+
return Promise.reject(new Error("Radius relay connection is closed"));
|
|
202
|
+
return this.#requireWriter().send(encodeRelayDataFrame(connectionId, chunk));
|
|
203
|
+
}
|
|
204
|
+
#sendControl(message) {
|
|
205
|
+
return this.#requireWriter().send(JSON.stringify(message));
|
|
206
|
+
}
|
|
207
|
+
#requireWriter() {
|
|
208
|
+
if (!this.#writer)
|
|
209
|
+
throw new Error("Radius relay host is disconnected");
|
|
210
|
+
return this.#writer;
|
|
211
|
+
}
|
|
212
|
+
#dropConnections(error) {
|
|
213
|
+
const connections = [...this.#connections.values()];
|
|
214
|
+
this.#connections.clear();
|
|
215
|
+
for (const active of connections) {
|
|
216
|
+
active.connection.markClosed();
|
|
217
|
+
if (error)
|
|
218
|
+
active.handler.onError(error);
|
|
219
|
+
else
|
|
220
|
+
active.handler.onClose();
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
export function createRadiusClientTransportFactory(options) {
|
|
225
|
+
return async (handlers) => {
|
|
226
|
+
const auth = await options.auth.resolve({ required: true });
|
|
227
|
+
if (!auth)
|
|
228
|
+
throw new Error("Radius authentication is required");
|
|
229
|
+
const socket = await openRadiusRelayWebSocket(relayWebSocketUrl(auth.gateway, options.serverId), RADIUS_RELAY_CLIENT_SUBPROTOCOL, auth.token, options.webSocketFactory ?? defaultWebSocketFactory);
|
|
230
|
+
return new RadiusClientByteTransport(socket, handlers);
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
/** Reconnect one established Radius client and restore its last selected Session. */
|
|
234
|
+
export class RadiusClientReconnect {
|
|
235
|
+
#client;
|
|
236
|
+
#reattach;
|
|
237
|
+
#abortController = new AbortController();
|
|
238
|
+
#removeConnectionListener;
|
|
239
|
+
#removeAttachmentListener;
|
|
240
|
+
#desiredSessionId;
|
|
241
|
+
#reconnecting;
|
|
242
|
+
#disposed = false;
|
|
243
|
+
constructor(client, reattach) {
|
|
244
|
+
this.#client = client;
|
|
245
|
+
this.#reattach = reattach;
|
|
246
|
+
this.#desiredSessionId = client.attachment?.sessionId;
|
|
247
|
+
this.#removeAttachmentListener = client.onAttachmentChange((attachment) => {
|
|
248
|
+
if (attachment !== undefined)
|
|
249
|
+
this.#desiredSessionId = attachment.sessionId;
|
|
250
|
+
else if (client.connected)
|
|
251
|
+
this.#desiredSessionId = undefined;
|
|
252
|
+
});
|
|
253
|
+
this.#removeConnectionListener = client.onConnectionStateChange(({ state }) => {
|
|
254
|
+
if (state === "disconnected" && !this.#disposed)
|
|
255
|
+
this.#startReconnect();
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
async dispose() {
|
|
259
|
+
if (this.#disposed)
|
|
260
|
+
return;
|
|
261
|
+
this.#disposed = true;
|
|
262
|
+
this.#removeConnectionListener();
|
|
263
|
+
this.#removeAttachmentListener();
|
|
264
|
+
this.#abortController.abort();
|
|
265
|
+
if (this.#client.connectionState !== "disconnected") {
|
|
266
|
+
this.#client.disconnect("Radius reconnect stopped");
|
|
267
|
+
}
|
|
268
|
+
await this.#reconnecting;
|
|
269
|
+
}
|
|
270
|
+
#startReconnect() {
|
|
271
|
+
if (this.#reconnecting !== undefined)
|
|
272
|
+
return;
|
|
273
|
+
this.#reconnecting = this.#runReconnect().finally(() => {
|
|
274
|
+
this.#reconnecting = undefined;
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
async #runReconnect() {
|
|
278
|
+
let retryMs = CLIENT_RETRY_INITIAL_MS;
|
|
279
|
+
while (!this.#disposed && !this.#client.connected) {
|
|
280
|
+
try {
|
|
281
|
+
await delay(retryMs, this.#abortController.signal, false);
|
|
282
|
+
await this.#client.reconnect();
|
|
283
|
+
const sessionId = this.#desiredSessionId;
|
|
284
|
+
if (sessionId !== undefined)
|
|
285
|
+
await this.#reattach(sessionId);
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
catch (error) {
|
|
289
|
+
if (this.#disposed || this.#abortController.signal.aborted)
|
|
290
|
+
return;
|
|
291
|
+
if (this.#client.connected)
|
|
292
|
+
this.#client.disconnect(errorMessage(error));
|
|
293
|
+
retryMs = Math.min(retryMs * 2, CLIENT_RETRY_MAX_MS);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
class RelayServerByteConnection {
|
|
299
|
+
#sendChunk;
|
|
300
|
+
#closeConnection;
|
|
301
|
+
#closed = false;
|
|
302
|
+
constructor(sendChunk, closeConnection) {
|
|
303
|
+
this.#sendChunk = sendChunk;
|
|
304
|
+
this.#closeConnection = closeConnection;
|
|
305
|
+
}
|
|
306
|
+
get closed() {
|
|
307
|
+
return this.#closed;
|
|
308
|
+
}
|
|
309
|
+
send(chunk) {
|
|
310
|
+
if (this.#closed)
|
|
311
|
+
return Promise.reject(new Error("Radius relay connection is closed"));
|
|
312
|
+
return this.#sendChunk(chunk);
|
|
313
|
+
}
|
|
314
|
+
async close(finalChunk) {
|
|
315
|
+
if (this.#closed)
|
|
316
|
+
return;
|
|
317
|
+
this.#closed = true;
|
|
318
|
+
await this.#closeConnection(finalChunk);
|
|
319
|
+
}
|
|
320
|
+
markClosed() {
|
|
321
|
+
this.#closed = true;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
class RadiusClientByteTransport {
|
|
325
|
+
#socket;
|
|
326
|
+
#handlers;
|
|
327
|
+
#writer;
|
|
328
|
+
#onMessage;
|
|
329
|
+
#onClose;
|
|
330
|
+
#onError;
|
|
331
|
+
#closed = false;
|
|
332
|
+
constructor(socket, handlers) {
|
|
333
|
+
this.#socket = socket;
|
|
334
|
+
this.#handlers = handlers;
|
|
335
|
+
this.#writer = new OrderedWebSocketWriter(socket);
|
|
336
|
+
this.#onMessage = (event) => {
|
|
337
|
+
if (this.#closed)
|
|
338
|
+
return;
|
|
339
|
+
if (!(event.data instanceof ArrayBuffer)) {
|
|
340
|
+
this.#fail(new Error("Radius relay client received a non-binary message"));
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
this.#handlers.onData(new Uint8Array(event.data));
|
|
344
|
+
};
|
|
345
|
+
this.#onClose = () => {
|
|
346
|
+
if (this.#markClosed())
|
|
347
|
+
this.#handlers.onClose();
|
|
348
|
+
};
|
|
349
|
+
this.#onError = (event) => this.#fail(webSocketError(event));
|
|
350
|
+
socket.addEventListener("message", this.#onMessage);
|
|
351
|
+
socket.addEventListener("close", this.#onClose);
|
|
352
|
+
socket.addEventListener("error", this.#onError);
|
|
353
|
+
}
|
|
354
|
+
send(chunk) {
|
|
355
|
+
if (!(chunk instanceof Uint8Array))
|
|
356
|
+
return Promise.reject(new TypeError("Radius relay chunks must be Uint8Array"));
|
|
357
|
+
if (this.#closed)
|
|
358
|
+
return Promise.reject(new Error("Radius relay client is closed"));
|
|
359
|
+
return this.#writer.send(chunk.slice().buffer);
|
|
360
|
+
}
|
|
361
|
+
close() {
|
|
362
|
+
if (!this.#markClosed())
|
|
363
|
+
return;
|
|
364
|
+
this.#socket.close(1000, "Pi client closed");
|
|
365
|
+
}
|
|
366
|
+
#fail(error) {
|
|
367
|
+
if (!this.#markClosed())
|
|
368
|
+
return;
|
|
369
|
+
closeWebSocket(this.#socket, LOCAL_TRANSPORT_ERROR_CLOSE_CODE, "Radius relay transport error");
|
|
370
|
+
this.#handlers.onError(error);
|
|
371
|
+
}
|
|
372
|
+
#markClosed() {
|
|
373
|
+
if (this.#closed)
|
|
374
|
+
return false;
|
|
375
|
+
this.#closed = true;
|
|
376
|
+
this.#writer.close();
|
|
377
|
+
this.#socket.removeEventListener("message", this.#onMessage);
|
|
378
|
+
this.#socket.removeEventListener("close", this.#onClose);
|
|
379
|
+
this.#socket.removeEventListener("error", this.#onError);
|
|
380
|
+
return true;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
class OrderedWebSocketWriter {
|
|
384
|
+
#socket;
|
|
385
|
+
#tail = Promise.resolve();
|
|
386
|
+
#pendingBytes = 0;
|
|
387
|
+
#closed = false;
|
|
388
|
+
constructor(socket) {
|
|
389
|
+
this.#socket = socket;
|
|
390
|
+
}
|
|
391
|
+
send(value) {
|
|
392
|
+
if (this.#closed)
|
|
393
|
+
return Promise.reject(new Error("Radius relay WebSocket is closed"));
|
|
394
|
+
const copied = typeof value === "string" ? value : value.slice(0);
|
|
395
|
+
const byteLength = typeof copied === "string" ? Buffer.byteLength(copied) : copied.byteLength;
|
|
396
|
+
if (this.#pendingBytes + byteLength > MAX_PENDING_BYTES) {
|
|
397
|
+
return Promise.reject(new Error("Radius relay exceeded its pending byte limit"));
|
|
398
|
+
}
|
|
399
|
+
this.#pendingBytes += byteLength;
|
|
400
|
+
const operation = this.#tail.then(async () => {
|
|
401
|
+
if (this.#closed || this.#socket.readyState !== this.#socket.OPEN) {
|
|
402
|
+
throw new Error("Radius relay WebSocket is closed");
|
|
403
|
+
}
|
|
404
|
+
this.#socket.send(copied);
|
|
405
|
+
while (this.#socket.bufferedAmount > DRAIN_THRESHOLD_BYTES) {
|
|
406
|
+
if (this.#closed || this.#socket.readyState !== this.#socket.OPEN) {
|
|
407
|
+
throw new Error("Radius relay WebSocket closed during write");
|
|
408
|
+
}
|
|
409
|
+
await delay(5, undefined, false);
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
const tracked = operation.finally(() => {
|
|
413
|
+
this.#pendingBytes -= byteLength;
|
|
414
|
+
});
|
|
415
|
+
this.#tail = tracked.catch(() => { });
|
|
416
|
+
return tracked;
|
|
417
|
+
}
|
|
418
|
+
close() {
|
|
419
|
+
this.#closed = true;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
function parseHostControlMessage(value) {
|
|
423
|
+
let parsed;
|
|
424
|
+
try {
|
|
425
|
+
parsed = JSON.parse(value);
|
|
426
|
+
}
|
|
427
|
+
catch {
|
|
428
|
+
throw new Error("Invalid Radius relay control message");
|
|
429
|
+
}
|
|
430
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
431
|
+
throw new Error("Invalid Radius relay control message");
|
|
432
|
+
}
|
|
433
|
+
const message = parsed;
|
|
434
|
+
if (message.version !== 1)
|
|
435
|
+
throw new Error("Unsupported Radius relay control version");
|
|
436
|
+
if (message.type === "ping" || message.type === "pong")
|
|
437
|
+
return { version: 1, type: message.type };
|
|
438
|
+
if ((message.type === "connection_open" || message.type === "connection_close") &&
|
|
439
|
+
typeof message.connection_id === "string" &&
|
|
440
|
+
CONNECTION_ID_PATTERN.test(message.connection_id) &&
|
|
441
|
+
(message.code === undefined ||
|
|
442
|
+
(typeof message.code === "number" &&
|
|
443
|
+
Number.isInteger(message.code) &&
|
|
444
|
+
message.code >= 1000 &&
|
|
445
|
+
message.code <= 4999))) {
|
|
446
|
+
return message.type === "connection_open"
|
|
447
|
+
? { version: 1, type: "connection_open", connection_id: message.connection_id }
|
|
448
|
+
: {
|
|
449
|
+
version: 1,
|
|
450
|
+
type: "connection_close",
|
|
451
|
+
connection_id: message.connection_id,
|
|
452
|
+
...(message.code === undefined ? {} : { code: message.code }),
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
throw new Error("Invalid Radius relay control message");
|
|
456
|
+
}
|
|
457
|
+
export function encodeRelayDataFrame(connectionId, payload) {
|
|
458
|
+
if (!CONNECTION_ID_PATTERN.test(connectionId))
|
|
459
|
+
throw new TypeError("Invalid Radius relay connection ID");
|
|
460
|
+
const frame = new Uint8Array(RELAY_DATA_HEADER_BYTES + payload.byteLength);
|
|
461
|
+
frame[0] = RELAY_DATA_FRAME_VERSION;
|
|
462
|
+
frame[1] = RELAY_DATA_FRAME_TYPE;
|
|
463
|
+
const hex = connectionId.replaceAll("-", "");
|
|
464
|
+
for (let index = 0; index < 16; index++) {
|
|
465
|
+
frame[index + 2] = Number.parseInt(hex.slice(index * 2, index * 2 + 2), 16);
|
|
466
|
+
}
|
|
467
|
+
frame.set(payload, RELAY_DATA_HEADER_BYTES);
|
|
468
|
+
return frame.buffer;
|
|
469
|
+
}
|
|
470
|
+
export function parseRelayDataFrame(frame) {
|
|
471
|
+
if (frame.byteLength < RELAY_DATA_HEADER_BYTES)
|
|
472
|
+
return undefined;
|
|
473
|
+
const bytes = new Uint8Array(frame);
|
|
474
|
+
if (bytes[0] !== RELAY_DATA_FRAME_VERSION || bytes[1] !== RELAY_DATA_FRAME_TYPE)
|
|
475
|
+
return undefined;
|
|
476
|
+
let hex = "";
|
|
477
|
+
for (const byte of bytes.subarray(2, RELAY_DATA_HEADER_BYTES))
|
|
478
|
+
hex += byte.toString(16).padStart(2, "0");
|
|
479
|
+
const connectionId = `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
480
|
+
if (!CONNECTION_ID_PATTERN.test(connectionId))
|
|
481
|
+
return undefined;
|
|
482
|
+
return { connectionId, payload: frame.slice(RELAY_DATA_HEADER_BYTES) };
|
|
483
|
+
}
|
|
484
|
+
function relayWebSocketUrl(gateway, serverId) {
|
|
485
|
+
const url = new URL(`/v1/session-relays/${serverId}/connect`, gateway);
|
|
486
|
+
if (url.protocol === "https:")
|
|
487
|
+
url.protocol = "wss:";
|
|
488
|
+
else if (url.protocol === "http:")
|
|
489
|
+
url.protocol = "ws:";
|
|
490
|
+
else
|
|
491
|
+
throw new Error(`Unsupported Radius gateway protocol: ${url.protocol}`);
|
|
492
|
+
return url.toString();
|
|
493
|
+
}
|
|
494
|
+
function defaultWebSocketFactory(options) {
|
|
495
|
+
return new WebSocket(options.url, {
|
|
496
|
+
protocols: [options.protocol],
|
|
497
|
+
headers: { authorization: options.authorization },
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
function openRadiusRelayWebSocket(url, protocol, token, factory, signal) {
|
|
501
|
+
signal?.throwIfAborted();
|
|
502
|
+
return new Promise((resolve, reject) => {
|
|
503
|
+
const socket = factory({ url, protocol, authorization: `Bearer ${token}` });
|
|
504
|
+
socket.binaryType = "arraybuffer";
|
|
505
|
+
let settled = false;
|
|
506
|
+
const cleanup = () => {
|
|
507
|
+
socket.removeEventListener("open", onOpen);
|
|
508
|
+
socket.removeEventListener("close", onClose);
|
|
509
|
+
socket.removeEventListener("error", onError);
|
|
510
|
+
signal?.removeEventListener("abort", onAbort);
|
|
511
|
+
};
|
|
512
|
+
const fail = (error) => {
|
|
513
|
+
if (settled)
|
|
514
|
+
return;
|
|
515
|
+
settled = true;
|
|
516
|
+
cleanup();
|
|
517
|
+
closeWebSocket(socket, 1000, "Radius relay connection failed");
|
|
518
|
+
reject(error);
|
|
519
|
+
};
|
|
520
|
+
const onOpen = () => {
|
|
521
|
+
if (settled)
|
|
522
|
+
return;
|
|
523
|
+
if (socket.protocol !== protocol) {
|
|
524
|
+
fail(new Error(`Radius relay selected unexpected WebSocket protocol ${JSON.stringify(socket.protocol)}`));
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
settled = true;
|
|
528
|
+
cleanup();
|
|
529
|
+
resolve(socket);
|
|
530
|
+
};
|
|
531
|
+
const onClose = (event) => fail(new Error(`Radius relay closed before connecting (${event.code})`));
|
|
532
|
+
const onError = (event) => fail(webSocketError(event));
|
|
533
|
+
const onAbort = () => fail(new Error("Radius relay connection cancelled"));
|
|
534
|
+
socket.addEventListener("open", onOpen, { once: true });
|
|
535
|
+
socket.addEventListener("close", onClose, { once: true });
|
|
536
|
+
socket.addEventListener("error", onError, { once: true });
|
|
537
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
function closeWebSocket(socket, code, reason) {
|
|
541
|
+
try {
|
|
542
|
+
socket.close(code, reason);
|
|
543
|
+
}
|
|
544
|
+
catch {
|
|
545
|
+
// A WebSocket can reject close() while its opening handshake is still pending.
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
function webSocketError(event) {
|
|
549
|
+
if (event.error instanceof Error && event.error.message.trim().length > 0)
|
|
550
|
+
return event.error;
|
|
551
|
+
return new Error(event.message?.trim() || "Radius WebSocket connection failed");
|
|
552
|
+
}
|
|
553
|
+
function delay(milliseconds, signal, unref) {
|
|
554
|
+
signal?.throwIfAborted();
|
|
555
|
+
return new Promise((resolve, reject) => {
|
|
556
|
+
const timer = setTimeout(() => {
|
|
557
|
+
cleanup();
|
|
558
|
+
resolve();
|
|
559
|
+
}, milliseconds);
|
|
560
|
+
if (unref)
|
|
561
|
+
timer.unref();
|
|
562
|
+
const onAbort = () => {
|
|
563
|
+
clearTimeout(timer);
|
|
564
|
+
cleanup();
|
|
565
|
+
try {
|
|
566
|
+
signal?.throwIfAborted();
|
|
567
|
+
}
|
|
568
|
+
catch (error) {
|
|
569
|
+
reject(error);
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
const cleanup = () => signal?.removeEventListener("abort", onAbort);
|
|
573
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
function toError(error) {
|
|
577
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
578
|
+
}
|
|
579
|
+
function errorMessage(error) {
|
|
580
|
+
return toError(error).message;
|
|
581
|
+
}
|
|
582
|
+
//# sourceMappingURL=radius-relay.js.map
|