@earendil-works/pi-coding-agent 0.85.0 → 0.86.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 +104 -0
- package/README.md +2 -3
- package/dist/bun/cli.d.ts +3 -1
- package/dist/bun/cli.d.ts.map +1 -1
- package/dist/bun/cli.js +3 -12
- package/dist/bun/cli.js.map +1 -1
- package/dist/bun/sandbox-env-setup.d.ts +2 -0
- package/dist/bun/sandbox-env-setup.d.ts.map +1 -0
- package/dist/bun/sandbox-env-setup.js +4 -0
- package/dist/bun/sandbox-env-setup.js.map +1 -0
- package/dist/bundle/chunks/anthropic-messages-MYU5ZMRF.js +6 -0
- package/dist/bundle/chunks/azure-openai-responses-HUSQ3GP2.js +2 -0
- package/dist/bundle/chunks/bedrock-converse-stream.js +47 -38
- package/dist/bundle/chunks/chunk-7IOYH2SY.js +2 -0
- package/dist/bundle/chunks/chunk-7YM6BE7Y.js +1561 -0
- package/dist/bundle/chunks/chunk-A3JYRWB6.js +2 -0
- package/dist/bundle/chunks/chunk-DTD7JQ7Y.js +42 -0
- package/dist/bundle/chunks/chunk-FUXEF6JQ.js +44 -0
- package/dist/bundle/chunks/{chunk-IDDQWTHI.js → chunk-RCZIEVGO.js} +10 -1
- package/dist/bundle/chunks/chunk-S7SZN6Z3.js +2 -0
- package/dist/bundle/chunks/chunk-WIUZI2CJ.js +11 -0
- package/dist/bundle/chunks/github-copilot.js +1 -1
- package/dist/bundle/chunks/google-generative-ai-IMS5EK2Y.js +2 -0
- package/dist/bundle/chunks/google-vertex-O4YJEQUW.js +2 -0
- package/dist/bundle/chunks/jiti-loader-C3NU2SDH.js +21 -0
- package/dist/bundle/chunks/jiti-static-loader-E6ANQD5T.js +2 -0
- package/dist/bundle/chunks/mistral-conversations-NOSQHBEY.js +5 -0
- package/dist/bundle/chunks/{node-EM5FIVUN.js → node-O3RIBJRH.js} +1 -1
- package/dist/bundle/chunks/openai-codex-responses-QDSOTBBO.js +10 -0
- package/dist/bundle/chunks/openai-completions-KQPOPEVM.js +7 -0
- package/dist/bundle/chunks/openai-responses-HWEUZ6WZ.js +2 -0
- package/dist/bundle/chunks/{pi-messages-EGZIFQGG.js → pi-messages-GFKBWJHZ.js} +1 -1
- package/dist/bundle/chunks/virtual-modules-XW5APVUE.js +2 -0
- package/dist/bundle/cli.js +1 -1
- 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 +0 -2
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/session-picker.d.ts +1 -1
- package/dist/cli/session-picker.d.ts.map +1 -1
- package/dist/cli/session-picker.js.map +1 -1
- package/dist/cli/setup.d.ts +2 -0
- package/dist/cli/setup.d.ts.map +1 -0
- package/dist/cli/setup.js +12 -0
- package/dist/cli/setup.js.map +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +3 -25
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -1
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session.d.ts +56 -6
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +293 -155
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/bug-report-upload.d.ts +12 -0
- package/dist/core/bug-report-upload.d.ts.map +1 -0
- package/dist/core/bug-report-upload.js +22 -0
- package/dist/core/bug-report-upload.js.map +1 -0
- package/dist/core/bug-report.d.ts +176 -0
- package/dist/core/bug-report.d.ts.map +1 -0
- package/dist/core/bug-report.js +292 -0
- package/dist/core/bug-report.js.map +1 -0
- package/dist/core/cache-stats.d.ts.map +1 -1
- package/dist/core/cache-stats.js +12 -1
- package/dist/core/cache-stats.js.map +1 -1
- package/dist/core/cache-warmer.d.ts +102 -0
- package/dist/core/cache-warmer.d.ts.map +1 -0
- package/dist/core/cache-warmer.js +342 -0
- package/dist/core/cache-warmer.js.map +1 -0
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +2 -2
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +2 -2
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +11 -12
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/crash-log.d.ts +22 -0
- package/dist/core/crash-log.d.ts.map +1 -0
- package/dist/core/crash-log.js +71 -0
- package/dist/core/crash-log.js.map +1 -0
- package/dist/core/experimental.d.ts +0 -4
- package/dist/core/experimental.d.ts.map +1 -1
- package/dist/core/experimental.js +0 -4
- package/dist/core/experimental.js.map +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/jiti-loader.d.ts +2 -0
- package/dist/core/extensions/jiti-loader.d.ts.map +1 -0
- package/dist/core/extensions/jiti-loader.js +4 -0
- package/dist/core/extensions/jiti-loader.js.map +1 -0
- package/dist/core/extensions/jiti-static-loader.d.ts +2 -0
- package/dist/core/extensions/jiti-static-loader.d.ts.map +1 -0
- package/dist/core/extensions/jiti-static-loader.js +4 -0
- package/dist/core/extensions/jiti-static-loader.js.map +1 -0
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +38 -51
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +10 -7
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +85 -67
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +60 -50
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/extensions/virtual-modules.d.ts +3 -0
- package/dist/core/extensions/virtual-modules.d.ts.map +1 -0
- package/dist/core/extensions/virtual-modules.js +38 -0
- package/dist/core/extensions/virtual-modules.js.map +1 -0
- package/dist/core/extensions/wrapper.d.ts.map +1 -1
- package/dist/core/extensions/wrapper.js +1 -20
- package/dist/core/extensions/wrapper.js.map +1 -1
- package/dist/core/index.d.ts +2 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/keybindings.d.ts +6 -1
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +5 -1
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/messages.d.ts.map +1 -1
- package/dist/core/messages.js +1 -0
- package/dist/core/messages.js.map +1 -1
- package/dist/core/model-config.d.ts +101 -20
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +25 -18
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/model-registry.d.ts +5 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +8 -0
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +1 -1
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +5 -3
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/provider-composer.d.ts +3 -2
- package/dist/core/provider-composer.d.ts.map +1 -1
- package/dist/core/provider-composer.js +2 -0
- package/dist/core/provider-composer.js.map +1 -1
- package/dist/core/radius.d.ts +3 -0
- package/dist/core/radius.d.ts.map +1 -1
- package/dist/core/radius.js +6 -0
- package/dist/core/radius.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +60 -38
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-export.d.ts +6 -2
- package/dist/core/session-export.d.ts.map +1 -1
- package/dist/core/session-export.js +14 -13
- package/dist/core/session-export.js.map +1 -1
- package/dist/core/session-manager.d.ts +29 -6
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +159 -96
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager.d.ts +20 -4
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +43 -7
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +1 -0
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/system-prompt.d.ts +49 -6
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +121 -92
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/bash.d.ts +2 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +10 -4
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +1 -2
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +1 -2
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/renderers/bash.d.ts.map +1 -1
- package/dist/core/tools/renderers/bash.js +9 -1
- package/dist/core/tools/renderers/bash.js.map +1 -1
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +1 -2
- package/dist/core/tools/write.js.map +1 -1
- package/dist/core/usage-totals.d.ts +1 -1
- package/dist/core/usage-totals.d.ts.map +1 -1
- package/dist/core/usage-totals.js +5 -1
- package/dist/core/usage-totals.js.map +1 -1
- package/dist/extensions/llama/client.d.ts +2 -0
- package/dist/extensions/llama/client.d.ts.map +1 -1
- package/dist/extensions/llama/client.js +7 -3
- package/dist/extensions/llama/client.js.map +1 -1
- package/dist/extensions/llama/provider.d.ts.map +1 -1
- package/dist/extensions/llama/provider.js +20 -5
- package/dist/extensions/llama/provider.js.map +1 -1
- package/dist/index.d.ts +3 -2
- 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 +13 -131
- package/dist/main.js.map +1 -1
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +2 -2
- package/dist/migrations.js.map +1 -1
- package/dist/modes/interactive/bug-report.d.ts +14 -0
- package/dist/modes/interactive/bug-report.d.ts.map +1 -0
- package/dist/modes/interactive/bug-report.js +209 -0
- package/dist/modes/interactive/bug-report.js.map +1 -0
- package/dist/modes/interactive/chat-viewport.d.ts.map +1 -1
- package/dist/modes/interactive/chat-viewport.js +1 -1
- package/dist/modes/interactive/chat-viewport.js.map +1 -1
- package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/branch-summary-message.js +12 -5
- package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
- package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/compaction-summary-message.js +12 -5
- package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
- package/dist/modes/interactive/components/custom-editor.d.ts +3 -3
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-editor.js.map +1 -1
- package/dist/modes/interactive/components/extension-input.d.ts +2 -0
- package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-input.js +6 -0
- package/dist/modes/interactive/components/extension-input.js.map +1 -1
- package/dist/modes/interactive/components/extension-selector.d.ts +1 -0
- package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-selector.js +4 -0
- package/dist/modes/interactive/components/extension-selector.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +4 -1
- package/dist/modes/interactive/components/footer.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 -5
- 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 +8 -8
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts +5 -5
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +74 -48
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +3 -1
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +11 -0
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/skill-invocation-message.js +11 -4
- package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
- package/dist/modes/interactive/components/status-indicator.d.ts +2 -2
- package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -1
- package/dist/modes/interactive/components/status-indicator.js +7 -7
- 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 +4 -4
- package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +18 -9
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector.js +2 -0
- package/dist/modes/interactive/components/tree-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +13 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +220 -84
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/session-share.d.ts +2 -0
- package/dist/modes/interactive/session-share.d.ts.map +1 -1
- package/dist/modes/interactive/session-share.js +8 -4
- package/dist/modes/interactive/session-share.js.map +1 -1
- package/dist/modes/interactive/tui-renderer.d.ts.map +1 -1
- package/dist/modes/interactive/tui-renderer.js +2 -2
- package/dist/modes/interactive/tui-renderer.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +2 -2
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/utils/clipboard-command.d.ts +7 -0
- package/dist/utils/clipboard-command.d.ts.map +1 -0
- package/dist/utils/clipboard-command.js +45 -0
- package/dist/utils/clipboard-command.js.map +1 -0
- package/dist/utils/clipboard-image.d.ts.map +1 -1
- package/dist/utils/clipboard-image.js +52 -69
- package/dist/utils/clipboard-image.js.map +1 -1
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js +61 -125
- package/dist/utils/clipboard.js.map +1 -1
- package/dist/utils/zip.d.ts +7 -0
- package/dist/utils/zip.d.ts.map +1 -0
- package/dist/utils/zip.js +60 -0
- package/dist/utils/zip.js.map +1 -0
- package/docs/compaction.md +39 -13
- package/docs/containerization.md +45 -0
- package/docs/custom-provider.md +22 -13
- package/docs/development.md +23 -4
- package/docs/docs.json +4 -0
- package/docs/environment-variables.md +3 -2
- package/docs/extensions.md +57 -43
- package/docs/json.md +4 -4
- package/docs/keybindings.md +2 -1
- package/docs/models.md +34 -3
- package/docs/providers.md +2 -2
- package/docs/sdk.md +4 -2
- package/docs/security.md +1 -1
- package/docs/session-format.md +82 -40
- package/docs/sessions.md +27 -0
- package/docs/settings.md +60 -1
- package/docs/termux.md +0 -1
- package/docs/tui.md +2 -2
- package/docs/usage.md +1 -0
- package/examples/extensions/README.md +0 -1
- package/examples/extensions/custom-provider-anthropic/index.ts +18 -12
- 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/index.ts +2 -2
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/prompt-customizer.ts +19 -67
- 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/npm-shrinkwrap.json +425 -778
- package/package.json +22 -27
- package/dist/bundle/chunks/anthropic-messages-QAQLEQIY.js +0 -6
- package/dist/bundle/chunks/azure-openai-responses-Q7MJBRE6.js +0 -2
- package/dist/bundle/chunks/chunk-2KVJKXS2.js +0 -50
- package/dist/bundle/chunks/chunk-AXIIZGTV.js +0 -2
- package/dist/bundle/chunks/chunk-EQ6DR6XK.js +0 -5
- package/dist/bundle/chunks/chunk-GMWCTUPB.js +0 -2
- package/dist/bundle/chunks/chunk-LZKJTKCT.js +0 -2
- package/dist/bundle/chunks/chunk-OUXLLA64.js +0 -11
- package/dist/bundle/chunks/chunk-R7UUJ4C2.js +0 -42
- package/dist/bundle/chunks/chunk-UAQELI3K.js +0 -2
- package/dist/bundle/chunks/chunk-WBE4J4AU.js +0 -9
- package/dist/bundle/chunks/chunk-WZB2R5YO.js +0 -1558
- package/dist/bundle/chunks/google-generative-ai-BSMTYDAM.js +0 -2
- package/dist/bundle/chunks/google-vertex-5C3HASOJ.js +0 -2
- package/dist/bundle/chunks/mistral-conversations-4M6BZBX6.js +0 -5
- package/dist/bundle/chunks/openai-codex-responses-YJOO52RW.js +0 -10
- package/dist/bundle/chunks/openai-completions-QOT3QX7D.js +0 -7
- package/dist/bundle/chunks/openai-responses-U7LNPQN4.js +0 -2
- package/dist/bundle/client.js +0 -2
- package/dist/bundle/coordinator.js +0 -3
- package/dist/cli/experimental/cli.d.ts +0 -10
- package/dist/cli/experimental/cli.d.ts.map +0 -1
- package/dist/cli/experimental/cli.js +0 -9
- package/dist/cli/experimental/cli.js.map +0 -1
- package/dist/cli/experimental/command-options.d.ts +0 -28
- package/dist/cli/experimental/command-options.d.ts.map +0 -1
- package/dist/cli/experimental/command-options.js +0 -84
- package/dist/cli/experimental/command-options.js.map +0 -1
- package/dist/cli/experimental/command.d.ts +0 -70
- package/dist/cli/experimental/command.d.ts.map +0 -1
- package/dist/cli/experimental/command.js +0 -144
- package/dist/cli/experimental/command.js.map +0 -1
- package/dist/cli/experimental/commands/client.d.ts +0 -19
- package/dist/cli/experimental/commands/client.d.ts.map +0 -1
- package/dist/cli/experimental/commands/client.js +0 -63
- package/dist/cli/experimental/commands/client.js.map +0 -1
- package/dist/cli/experimental/commands/server.d.ts +0 -17
- package/dist/cli/experimental/commands/server.d.ts.map +0 -1
- package/dist/cli/experimental/commands/server.js +0 -44
- package/dist/cli/experimental/commands/server.js.map +0 -1
- package/dist/client/index.d.ts +0 -2
- package/dist/client/index.d.ts.map +0 -1
- package/dist/client/index.js +0 -2
- package/dist/client/index.js.map +0 -1
- package/dist/experimental/client-runtime.d.ts +0 -43
- package/dist/experimental/client-runtime.d.ts.map +0 -1
- package/dist/experimental/client-runtime.js +0 -183
- package/dist/experimental/client-runtime.js.map +0 -1
- package/dist/experimental/client-tui-chat.d.ts +0 -14
- package/dist/experimental/client-tui-chat.d.ts.map +0 -1
- package/dist/experimental/client-tui-chat.js +0 -171
- package/dist/experimental/client-tui-chat.js.map +0 -1
- package/dist/experimental/client-tui.d.ts +0 -37
- package/dist/experimental/client-tui.d.ts.map +0 -1
- package/dist/experimental/client-tui.js +0 -702
- package/dist/experimental/client-tui.js.map +0 -1
- package/dist/experimental/client.d.ts +0 -25
- package/dist/experimental/client.d.ts.map +0 -1
- package/dist/experimental/client.js +0 -99
- package/dist/experimental/client.js.map +0 -1
- package/dist/experimental/coordinator-entry.d.ts +0 -3
- package/dist/experimental/coordinator-entry.d.ts.map +0 -1
- package/dist/experimental/coordinator-entry.js +0 -11
- package/dist/experimental/coordinator-entry.js.map +0 -1
- package/dist/experimental/coordinator.d.ts +0 -38
- package/dist/experimental/coordinator.d.ts.map +0 -1
- package/dist/experimental/coordinator.js +0 -570
- package/dist/experimental/coordinator.js.map +0 -1
- package/dist/experimental/mini/main.d.ts +0 -7
- package/dist/experimental/mini/main.d.ts.map +0 -1
- package/dist/experimental/mini/main.js +0 -21
- package/dist/experimental/mini/main.js.map +0 -1
- package/dist/experimental/mini/server/entry.d.ts +0 -3
- package/dist/experimental/mini/server/entry.d.ts.map +0 -1
- package/dist/experimental/mini/server/entry.js +0 -11
- package/dist/experimental/mini/server/entry.js.map +0 -1
- package/dist/experimental/mini/server/run.d.ts +0 -13
- package/dist/experimental/mini/server/run.d.ts.map +0 -1
- package/dist/experimental/mini/server/run.js +0 -150
- package/dist/experimental/mini/server/run.js.map +0 -1
- package/dist/experimental/mini/shared/protocol.d.ts +0 -127
- package/dist/experimental/mini/shared/protocol.d.ts.map +0 -1
- package/dist/experimental/mini/shared/protocol.js +0 -13
- package/dist/experimental/mini/shared/protocol.js.map +0 -1
- package/dist/experimental/mini/shared/rpc.d.ts +0 -49
- package/dist/experimental/mini/shared/rpc.d.ts.map +0 -1
- package/dist/experimental/mini/shared/rpc.js +0 -171
- package/dist/experimental/mini/shared/rpc.js.map +0 -1
- package/dist/experimental/mini/shared/transport.d.ts +0 -35
- package/dist/experimental/mini/shared/transport.d.ts.map +0 -1
- package/dist/experimental/mini/shared/transport.js +0 -94
- package/dist/experimental/mini/shared/transport.js.map +0 -1
- package/dist/experimental/mini/tui/run.d.ts +0 -9
- package/dist/experimental/mini/tui/run.d.ts.map +0 -1
- package/dist/experimental/mini/tui/run.js +0 -62
- package/dist/experimental/mini/tui/run.js.map +0 -1
- package/dist/experimental/mini/tui/session.d.ts +0 -26
- package/dist/experimental/mini/tui/session.d.ts.map +0 -1
- package/dist/experimental/mini/tui/session.js +0 -94
- package/dist/experimental/mini/tui/session.js.map +0 -1
- package/dist/experimental/mini/tui/view.d.ts +0 -10
- package/dist/experimental/mini/tui/view.d.ts.map +0 -1
- package/dist/experimental/mini/tui/view.js +0 -459
- package/dist/experimental/mini/tui/view.js.map +0 -1
- package/dist/experimental/mini/worker/entry.d.ts +0 -3
- package/dist/experimental/mini/worker/entry.d.ts.map +0 -1
- package/dist/experimental/mini/worker/entry.js +0 -10
- package/dist/experimental/mini/worker/entry.js.map +0 -1
- package/dist/experimental/mini/worker/lane-service.d.ts +0 -44
- package/dist/experimental/mini/worker/lane-service.d.ts.map +0 -1
- package/dist/experimental/mini/worker/lane-service.js +0 -97
- package/dist/experimental/mini/worker/lane-service.js.map +0 -1
- package/dist/experimental/mini/worker/models-service.d.ts +0 -19
- package/dist/experimental/mini/worker/models-service.d.ts.map +0 -1
- package/dist/experimental/mini/worker/models-service.js +0 -136
- package/dist/experimental/mini/worker/models-service.js.map +0 -1
- package/dist/experimental/mini/worker/run.d.ts +0 -14
- package/dist/experimental/mini/worker/run.d.ts.map +0 -1
- package/dist/experimental/mini/worker/run.js +0 -88
- package/dist/experimental/mini/worker/run.js.map +0 -1
- package/dist/experimental/plugin.d.ts +0 -4
- package/dist/experimental/plugin.d.ts.map +0 -1
- package/dist/experimental/plugin.js +0 -4
- package/dist/experimental/plugin.js.map +0 -1
- package/dist/experimental/plugins/bundled.d.ts +0 -7
- package/dist/experimental/plugins/bundled.d.ts.map +0 -1
- package/dist/experimental/plugins/bundled.js +0 -48
- package/dist/experimental/plugins/bundled.js.map +0 -1
- package/dist/experimental/plugins/package.d.ts +0 -18
- package/dist/experimental/plugins/package.d.ts.map +0 -1
- package/dist/experimental/plugins/package.js +0 -113
- package/dist/experimental/plugins/package.js.map +0 -1
- package/dist/experimental/process.d.ts +0 -20
- package/dist/experimental/process.d.ts.map +0 -1
- package/dist/experimental/process.js +0 -85
- package/dist/experimental/process.js.map +0 -1
- package/dist/experimental/radius-auth.d.ts +0 -17
- package/dist/experimental/radius-auth.d.ts.map +0 -1
- package/dist/experimental/radius-auth.js +0 -52
- package/dist/experimental/radius-auth.js.map +0 -1
- package/dist/experimental/radius-relay.d.ts +0 -90
- package/dist/experimental/radius-relay.d.ts.map +0 -1
- package/dist/experimental/radius-relay.js +0 -582
- package/dist/experimental/radius-relay.js.map +0 -1
- package/dist/experimental/server.d.ts +0 -75
- package/dist/experimental/server.d.ts.map +0 -1
- package/dist/experimental/server.js +0 -682
- package/dist/experimental/server.js.map +0 -1
- package/dist/experimental/services/agent-controller-provider.d.ts +0 -4
- package/dist/experimental/services/agent-controller-provider.d.ts.map +0 -1
- package/dist/experimental/services/agent-controller-provider.js +0 -84
- package/dist/experimental/services/agent-controller-provider.js.map +0 -1
- package/dist/experimental/services/agent-controller.d.ts +0 -57
- package/dist/experimental/services/agent-controller.d.ts.map +0 -1
- package/dist/experimental/services/agent-controller.js +0 -3
- package/dist/experimental/services/agent-controller.js.map +0 -1
- package/dist/experimental/services/connection.d.ts +0 -40
- package/dist/experimental/services/connection.d.ts.map +0 -1
- package/dist/experimental/services/connection.js +0 -300
- package/dist/experimental/services/connection.js.map +0 -1
- package/dist/experimental/services/models-provider.d.ts +0 -16
- package/dist/experimental/services/models-provider.d.ts.map +0 -1
- package/dist/experimental/services/models-provider.js +0 -116
- package/dist/experimental/services/models-provider.js.map +0 -1
- package/dist/experimental/services/models.d.ts +0 -36
- package/dist/experimental/services/models.d.ts.map +0 -1
- package/dist/experimental/services/models.js +0 -3
- package/dist/experimental/services/models.js.map +0 -1
- package/dist/experimental/services/plugins.d.ts +0 -16
- package/dist/experimental/services/plugins.d.ts.map +0 -1
- package/dist/experimental/services/plugins.js +0 -4
- package/dist/experimental/services/plugins.js.map +0 -1
- package/dist/experimental/services/presentation-ui.d.ts +0 -13
- package/dist/experimental/services/presentation-ui.d.ts.map +0 -1
- package/dist/experimental/services/presentation-ui.js +0 -3
- package/dist/experimental/services/presentation-ui.js.map +0 -1
- package/dist/experimental/services/server.d.ts +0 -19
- package/dist/experimental/services/server.d.ts.map +0 -1
- package/dist/experimental/services/server.js +0 -104
- package/dist/experimental/services/server.js.map +0 -1
- package/dist/experimental/services/sessions.d.ts +0 -28
- package/dist/experimental/services/sessions.d.ts.map +0 -1
- package/dist/experimental/services/sessions.js +0 -4
- package/dist/experimental/services/sessions.js.map +0 -1
- package/dist/experimental/services/slash-commands-provider.d.ts +0 -14
- package/dist/experimental/services/slash-commands-provider.d.ts.map +0 -1
- package/dist/experimental/services/slash-commands-provider.js +0 -200
- package/dist/experimental/services/slash-commands-provider.js.map +0 -1
- package/dist/experimental/services/slash-commands.d.ts +0 -24
- package/dist/experimental/services/slash-commands.d.ts.map +0 -1
- package/dist/experimental/services/slash-commands.js +0 -3
- package/dist/experimental/services/slash-commands.js.map +0 -1
- package/dist/experimental/services/transcript-provider.d.ts +0 -12
- package/dist/experimental/services/transcript-provider.d.ts.map +0 -1
- package/dist/experimental/services/transcript-provider.js +0 -109
- package/dist/experimental/services/transcript-provider.js.map +0 -1
- package/dist/experimental/services/transcript.d.ts +0 -13
- package/dist/experimental/services/transcript.d.ts.map +0 -1
- package/dist/experimental/services/transcript.js +0 -3
- package/dist/experimental/services/transcript.js.map +0 -1
- package/dist/experimental/services/worker.d.ts +0 -28
- package/dist/experimental/services/worker.d.ts.map +0 -1
- package/dist/experimental/services/worker.js +0 -107
- package/dist/experimental/services/worker.js.map +0 -1
- package/dist/experimental/session-worker-manager.d.ts +0 -24
- package/dist/experimental/session-worker-manager.d.ts.map +0 -1
- package/dist/experimental/session-worker-manager.js +0 -691
- package/dist/experimental/session-worker-manager.js.map +0 -1
- package/dist/experimental/session-worker.d.ts +0 -188
- package/dist/experimental/session-worker.d.ts.map +0 -1
- package/dist/experimental/session-worker.js +0 -785
- package/dist/experimental/session-worker.js.map +0 -1
- package/dist/experimental/source-resolver.d.ts +0 -2
- package/dist/experimental/source-resolver.d.ts.map +0 -1
- package/dist/experimental/source-resolver.js +0 -71
- package/dist/experimental/source-resolver.js.map +0 -1
- package/dist/utils/clipboard-native.d.ts +0 -11
- package/dist/utils/clipboard-native.d.ts.map +0 -1
- package/dist/utils/clipboard-native.js +0 -20
- package/dist/utils/clipboard-native.js.map +0 -1
- package/examples/extensions/kimi-deferred-tools.ts +0 -61
|
@@ -1,582 +0,0 @@
|
|
|
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
|