apex-code 0.4.0 → 0.5.1
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 +280 -6
- package/README.md +624 -0
- package/dist/bun/cli.d.ts +3 -1
- package/dist/bun/cli.d.ts.map +1 -1
- package/dist/bun/cli.js +3 -9
- 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/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/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +16 -5
- 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/file-processor.d.ts +1 -1
- package/dist/cli/file-processor.d.ts.map +1 -1
- package/dist/cli/file-processor.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 +13 -0
- package/dist/cli/setup.js.map +1 -0
- 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 +16 -8
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session.d.ts +85 -15
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +685 -266
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts +4 -0
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +55 -0
- package/dist/core/auth-storage.js.map +1 -1
- 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 +291 -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 +103 -0
- package/dist/core/cache-warmer.d.ts.map +1 -0
- package/dist/core/cache-warmer.js +356 -0
- package/dist/core/cache-warmer.js.map +1 -0
- 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 +4 -3
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +5 -3
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +163 -66
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/context/pipeline.d.ts +8 -8
- package/dist/core/context/pipeline.d.ts.map +1 -1
- package/dist/core/context/pipeline.js +21 -12
- package/dist/core/context/pipeline.js.map +1 -1
- package/dist/core/crash-log.d.ts +27 -0
- package/dist/core/crash-log.d.ts.map +1 -0
- package/dist/core/crash-log.js +139 -0
- package/dist/core/crash-log.js.map +1 -0
- package/dist/core/export-html/template.js +6 -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 +40 -59
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +24 -8
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +195 -72
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +142 -55
- 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 +41 -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/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/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 +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 +168 -20
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +44 -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 +4 -3
- package/dist/core/model-resolver.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 +12 -6
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/permissions/store.d.ts.map +1 -1
- package/dist/core/permissions/store.js +11 -8
- package/dist/core/permissions/store.js.map +1 -1
- package/dist/core/prompt-templates.d.ts +6 -1
- package/dist/core/prompt-templates.d.ts.map +1 -1
- package/dist/core/prompt-templates.js +61 -35
- package/dist/core/prompt-templates.js.map +1 -1
- package/dist/core/provider-composer.d.ts +4 -2
- package/dist/core/provider-composer.d.ts.map +1 -1
- package/dist/core/provider-composer.js +29 -2
- 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/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +6 -2
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +63 -42
- 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 +66 -15
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +295 -115
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager.d.ts +27 -4
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +56 -8
- 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 +5 -4
- package/dist/core/skills.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 +140 -79
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/bash.d.ts +9 -15
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +20 -137
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/delegate.d.ts.map +1 -1
- package/dist/core/tools/delegate.js +2 -2
- package/dist/core/tools/delegate.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 +6 -204
- 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 +4 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +10 -122
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/renderers/bash.d.ts +18 -0
- package/dist/core/tools/renderers/bash.d.ts.map +1 -0
- package/dist/core/tools/renderers/bash.js +126 -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 +207 -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 +34 -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 +132 -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 +152 -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 +6 -147
- 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/extensions/llama/ui.d.ts.map +1 -1
- package/dist/extensions/llama/ui.js +3 -2
- package/dist/extensions/llama/ui.js.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +21 -13
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/bug-report.d.ts +16 -0
- package/dist/modes/interactive/bug-report.d.ts.map +1 -0
- package/dist/modes/interactive/bug-report.js +167 -0
- package/dist/modes/interactive/bug-report.js.map +1 -0
- 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 +7 -0
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +63 -27
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/autocomplete-source.d.ts +8 -0
- package/dist/modes/interactive/components/autocomplete-source.d.ts.map +1 -0
- package/dist/modes/interactive/components/autocomplete-source.js +23 -0
- package/dist/modes/interactive/components/autocomplete-source.js.map +1 -0
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/bash-execution.js +6 -4
- package/dist/modes/interactive/components/bash-execution.js.map +1 -1
- package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -1
- package/dist/modes/interactive/components/bordered-loader.js +1 -1
- package/dist/modes/interactive/components/bordered-loader.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/composer-dock.d.ts +12 -0
- package/dist/modes/interactive/components/composer-dock.d.ts.map +1 -0
- package/dist/modes/interactive/components/composer-dock.js +24 -0
- package/dist/modes/interactive/components/composer-dock.js.map +1 -0
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/config-selector.js +11 -9
- package/dist/modes/interactive/components/config-selector.js.map +1 -1
- package/dist/modes/interactive/components/custom-editor.d.ts +12 -0
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-editor.js +38 -0
- package/dist/modes/interactive/components/custom-editor.js.map +1 -1
- package/dist/modes/interactive/components/error-summary.d.ts +11 -0
- package/dist/modes/interactive/components/error-summary.d.ts.map +1 -0
- package/dist/modes/interactive/components/error-summary.js +31 -0
- package/dist/modes/interactive/components/error-summary.js.map +1 -0
- package/dist/modes/interactive/components/extension-editor.d.ts +4 -1
- package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-editor.js +15 -10
- package/dist/modes/interactive/components/extension-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 +15 -5
- package/dist/modes/interactive/components/extension-input.js.map +1 -1
- package/dist/modes/interactive/components/extension-selector.d.ts +2 -0
- package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-selector.js +15 -10
- package/dist/modes/interactive/components/extension-selector.js.map +1 -1
- package/dist/modes/interactive/components/first-time-setup.d.ts.map +1 -1
- package/dist/modes/interactive/components/first-time-setup.js +6 -6
- package/dist/modes/interactive/components/first-time-setup.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +12 -4
- package/dist/modes/interactive/components/footer.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/keybinding-hints.d.ts +21 -0
- package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.js +34 -0
- package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
- package/dist/modes/interactive/components/login-dialog.js +27 -23
- package/dist/modes/interactive/components/login-dialog.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +16 -20
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.js +7 -6
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
- package/dist/modes/interactive/components/permission-preview.d.ts.map +1 -1
- package/dist/modes/interactive/components/permission-preview.js +3 -3
- package/dist/modes/interactive/components/permission-preview.js.map +1 -1
- package/dist/modes/interactive/components/prompt-input.d.ts +12 -0
- package/dist/modes/interactive/components/prompt-input.d.ts.map +1 -0
- package/dist/modes/interactive/components/prompt-input.js +18 -0
- package/dist/modes/interactive/components/prompt-input.js.map +1 -0
- package/dist/modes/interactive/components/scoped-models-selector.d.ts +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.js +17 -18
- 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 +100 -67
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +5 -1
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +74 -16
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-submenu.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-submenu.js +8 -6
- package/dist/modes/interactive/components/settings-submenu.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 +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 +14 -9
- package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +28 -16
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +73 -80
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tool-panel.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-panel.js +7 -2
- package/dist/modes/interactive/components/tool-panel.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector.js +18 -5
- package/dist/modes/interactive/components/tree-selector.js.map +1 -1
- package/dist/modes/interactive/components/trust-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/trust-selector.js +12 -12
- package/dist/modes/interactive/components/trust-selector.js.map +1 -1
- package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message-selector.js +2 -2
- package/dist/modes/interactive/components/user-message-selector.js.map +1 -1
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message.js +6 -3
- package/dist/modes/interactive/components/user-message.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +50 -31
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +494 -229
- package/dist/modes/interactive/interactive-mode.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/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +49 -23
- package/dist/modes/print-mode.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/testing/replay/recorded-provider.d.ts +2 -2
- package/dist/testing/replay/recorded-provider.d.ts.map +1 -1
- package/dist/testing/replay/recorded-provider.js +2 -5
- package/dist/testing/replay/recorded-provider.js.map +1 -1
- package/dist/testing/replay/runner.d.ts.map +1 -1
- package/dist/testing/replay/runner.js +0 -1
- package/dist/testing/replay/runner.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 +53 -81
- package/dist/utils/clipboard-image.js.map +1 -1
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js +111 -121
- package/dist/utils/clipboard.js.map +1 -1
- 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/mime.d.ts.map +1 -1
- package/dist/utils/mime.js +1 -1
- package/dist/utils/mime.js.map +1 -1
- package/dist/utils/syntax-highlight.d.ts.map +1 -1
- package/dist/utils/syntax-highlight.js +21 -21
- package/dist/utils/syntax-highlight.js.map +1 -1
- package/dist/utils/tool-result-images.d.ts +3 -1
- package/dist/utils/tool-result-images.d.ts.map +1 -1
- package/dist/utils/tool-result-images.js +4 -1
- package/dist/utils/tool-result-images.js.map +1 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +11 -2
- package/dist/utils/tools-manager.js.map +1 -1
- package/dist/utils/wsl.d.ts +3 -0
- package/dist/utils/wsl.d.ts.map +1 -0
- package/dist/utils/wsl.js +15 -0
- package/dist/utils/wsl.js.map +1 -0
- 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/cli-integration.md +107 -0
- package/docs/cli.md +269 -0
- package/docs/compaction.md +73 -24
- package/docs/configuration.md +45 -0
- package/docs/containerization.md +22 -21
- package/docs/custom-provider.md +21 -12
- package/docs/development.md +19 -0
- package/docs/docs.json +139 -95
- package/docs/extensions.md +243 -371
- package/docs/how-pi-works.md +49 -0
- package/docs/images/interactive-mode.png +0 -0
- package/docs/index.md +3 -3
- package/docs/json.md +43 -3
- package/docs/keybindings.md +57 -54
- package/docs/llama-cpp.md +2 -2
- package/docs/message-types.md +261 -0
- package/docs/models.md +103 -49
- package/docs/packages.md +49 -47
- package/docs/prompt-templates.md +29 -56
- package/docs/providers.md +91 -139
- package/docs/quickstart.md +42 -14
- package/docs/rpc-commands.md +854 -0
- package/docs/rpc-extension-ui.md +200 -0
- package/docs/rpc.md +121 -223
- package/docs/sdk.md +99 -124
- package/docs/security.md +7 -7
- package/docs/session-format.md +85 -82
- package/docs/sessions.md +41 -57
- package/docs/settings.md +95 -88
- package/docs/shell-aliases.md +68 -3
- package/docs/skills.md +62 -49
- package/docs/slash-commands.md +60 -0
- package/docs/terminal-setup.md +86 -55
- package/docs/termux.md +65 -75
- package/docs/themes.md +64 -86
- package/docs/tmux.md +29 -7
- package/docs/tui.md +67 -122
- package/docs/usage.md +31 -42
- package/docs/windows.md +41 -13
- package/examples/README.md +16 -2
- 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/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/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/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 +24 -0
- package/examples/plugins/pi-example-plugin/src/tui.ts +31 -0
- package/examples/rpc-client.ts +35 -0
- package/examples/rpc-extension-ui.ts +25 -5
- package/examples/sdk/README.md +1 -1
- package/npm-shrinkwrap.json +861 -513
- package/package.json +27 -18
- 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/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/cli.d.ts +0 -6
- package/dist/cli/experimental/cli.d.ts.map +0 -1
- package/dist/cli/experimental/cli.js +0 -5
- package/dist/cli/experimental/cli.js.map +0 -1
- package/dist/cli/experimental/command-options.d.ts +0 -17
- package/dist/cli/experimental/command-options.d.ts.map +0 -1
- package/dist/cli/experimental/command-options.js +0 -35
- package/dist/cli/experimental/command-options.js.map +0 -1
- package/dist/cli/experimental/command.d.ts +0 -63
- package/dist/cli/experimental/command.d.ts.map +0 -1
- package/dist/cli/experimental/command.js +0 -130
- package/dist/cli/experimental/command.js.map +0 -1
- package/dist/cli/experimental/commands/client.d.ts +0 -13
- package/dist/cli/experimental/commands/client.d.ts.map +0 -1
- package/dist/cli/experimental/commands/client.js +0 -25
- package/dist/cli/experimental/commands/client.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/commands/server.d.ts +0 -13
- package/dist/cli/experimental/commands/server.d.ts.map +0 -1
- package/dist/cli/experimental/commands/server.js +0 -25
- package/dist/cli/experimental/commands/server.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/index.d.ts +0 -3
- package/dist/client/index.d.ts.map +0 -1
- package/dist/client/index.js +0 -3
- package/dist/client/index.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/modes/interactive/components/message-spine.d.ts +0 -14
- package/dist/modes/interactive/components/message-spine.d.ts.map +0 -1
- package/dist/modes/interactive/components/message-spine.js +0 -19
- package/dist/modes/interactive/components/message-spine.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
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { AuthInput } from "../auth.ts";
|
|
2
|
-
import { Command } from "../command.ts";
|
|
3
|
-
import type { TransportAddress } from "../transport-address.ts";
|
|
4
|
-
export interface ServerCommand {
|
|
5
|
-
readonly command: "server";
|
|
6
|
-
readonly auth?: AuthInput;
|
|
7
|
-
readonly listen?: readonly TransportAddress[];
|
|
8
|
-
}
|
|
9
|
-
export interface ServerCommandContext {
|
|
10
|
-
runServer(command: ServerCommand): void | Promise<void>;
|
|
11
|
-
}
|
|
12
|
-
export declare const serverCommand: Command<ServerCommand, ServerCommandContext, ServerCommand>;
|
|
13
|
-
//# sourceMappingURL=server.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../../src/cli/experimental/commands/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AASxC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,MAAM,WAAW,aAAa;IAC7B,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;IAC3B,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,gBAAgB,EAAE,CAAC;CAC9C;AAED,MAAM,WAAW,oBAAoB;IACpC,SAAS,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxD;AAID,eAAO,MAAM,aAAa,6DAmBgC,CAAC","sourcesContent":["import type { AuthInput } from \"../auth.ts\";\nimport { Command } from \"../command.ts\";\nimport {\n\tauthTokenFileOption,\n\tauthTokenOption,\n\tparseAuth,\n\tparseLegacyOptions,\n\ttransportOption,\n\tunsupportedLegacyOptions,\n} from \"../command-options.ts\";\nimport type { TransportAddress } from \"../transport-address.ts\";\n\nexport interface ServerCommand {\n\treadonly command: \"server\";\n\treadonly auth?: AuthInput;\n\treadonly listen?: readonly TransportAddress[];\n}\n\nexport interface ServerCommandContext {\n\trunServer(command: ServerCommand): void | Promise<void>;\n}\n\nconst listenOption = transportOption(\"--listen\");\n\nexport const serverCommand = new Command<ServerCommand, ServerCommandContext>(\"server\")\n\t.option(listenOption)\n\t.option(authTokenOption)\n\t.option(authTokenFileOption)\n\t.build((input) => {\n\t\tconst { auth, errors: authErrors } = parseAuth(input);\n\t\tconst listen = input.values(listenOption);\n\t\tconst { errors: optionErrors } = parseLegacyOptions(input);\n\t\tconst errors = [...authErrors, ...optionErrors, ...unsupportedLegacyOptions(\"server\", input)];\n\t\tif (errors.length > 0) return { ok: false, errors };\n\t\treturn {\n\t\t\tok: true,\n\t\t\tcommand: {\n\t\t\t\tcommand: \"server\",\n\t\t\t\t...(auth === undefined ? {} : { auth }),\n\t\t\t\t...(listen.length === 0 ? {} : { listen }),\n\t\t\t},\n\t\t};\n\t})\n\t.action((command, context) => context.runServer(command));\n"]}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Command } from "../command.js";
|
|
2
|
-
import { authTokenFileOption, authTokenOption, parseAuth, parseLegacyOptions, transportOption, unsupportedLegacyOptions, } from "../command-options.js";
|
|
3
|
-
const listenOption = transportOption("--listen");
|
|
4
|
-
export const serverCommand = new Command("server")
|
|
5
|
-
.option(listenOption)
|
|
6
|
-
.option(authTokenOption)
|
|
7
|
-
.option(authTokenFileOption)
|
|
8
|
-
.build((input) => {
|
|
9
|
-
const { auth, errors: authErrors } = parseAuth(input);
|
|
10
|
-
const listen = input.values(listenOption);
|
|
11
|
-
const { errors: optionErrors } = parseLegacyOptions(input);
|
|
12
|
-
const errors = [...authErrors, ...optionErrors, ...unsupportedLegacyOptions("server", input)];
|
|
13
|
-
if (errors.length > 0)
|
|
14
|
-
return { ok: false, errors };
|
|
15
|
-
return {
|
|
16
|
-
ok: true,
|
|
17
|
-
command: {
|
|
18
|
-
command: "server",
|
|
19
|
-
...(auth === undefined ? {} : { auth }),
|
|
20
|
-
...(listen.length === 0 ? {} : { listen }),
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
})
|
|
24
|
-
.action((command, context) => context.runServer(command));
|
|
25
|
-
//# sourceMappingURL=server.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../../src/cli/experimental/commands/server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EACN,mBAAmB,EACnB,eAAe,EACf,SAAS,EACT,kBAAkB,EAClB,eAAe,EACf,wBAAwB,GACxB,MAAM,uBAAuB,CAAC;AAa/B,MAAM,YAAY,GAAG,eAAe,CAAC,UAAU,CAAC,CAAC;AAEjD,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,OAAO,CAAsC,QAAQ,CAAC;KACrF,MAAM,CAAC,YAAY,CAAC;KACpB,MAAM,CAAC,eAAe,CAAC;KACvB,MAAM,CAAC,mBAAmB,CAAC;KAC3B,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC;IACjB,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;IACtD,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IAC1C,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;IAC3D,MAAM,MAAM,GAAG,CAAC,GAAG,UAAU,EAAE,GAAG,YAAY,EAAE,GAAG,wBAAwB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC;IAC9F,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IACpD,OAAO;QACN,EAAE,EAAE,IAAI;QACR,OAAO,EAAE;YACR,OAAO,EAAE,QAAQ;YACjB,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;YACvC,GAAG,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC;SAC1C;KACD,CAAC;AAAA,CACF,CAAC;KACD,MAAM,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC","sourcesContent":["import type { AuthInput } from \"../auth.ts\";\nimport { Command } from \"../command.ts\";\nimport {\n\tauthTokenFileOption,\n\tauthTokenOption,\n\tparseAuth,\n\tparseLegacyOptions,\n\ttransportOption,\n\tunsupportedLegacyOptions,\n} from \"../command-options.ts\";\nimport type { TransportAddress } from \"../transport-address.ts\";\n\nexport interface ServerCommand {\n\treadonly command: \"server\";\n\treadonly auth?: AuthInput;\n\treadonly listen?: readonly TransportAddress[];\n}\n\nexport interface ServerCommandContext {\n\trunServer(command: ServerCommand): void | Promise<void>;\n}\n\nconst listenOption = transportOption(\"--listen\");\n\nexport const serverCommand = new Command<ServerCommand, ServerCommandContext>(\"server\")\n\t.option(listenOption)\n\t.option(authTokenOption)\n\t.option(authTokenFileOption)\n\t.build((input) => {\n\t\tconst { auth, errors: authErrors } = parseAuth(input);\n\t\tconst listen = input.values(listenOption);\n\t\tconst { errors: optionErrors } = parseLegacyOptions(input);\n\t\tconst errors = [...authErrors, ...optionErrors, ...unsupportedLegacyOptions(\"server\", input)];\n\t\tif (errors.length > 0) return { ok: false, errors };\n\t\treturn {\n\t\t\tok: true,\n\t\t\tcommand: {\n\t\t\t\tcommand: \"server\",\n\t\t\t\t...(auth === undefined ? {} : { auth }),\n\t\t\t\t...(listen.length === 0 ? {} : { listen }),\n\t\t\t},\n\t\t};\n\t})\n\t.action((command, context) => context.runServer(command));\n"]}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export interface UnixTransportAddress {
|
|
2
|
-
readonly transport: "unix";
|
|
3
|
-
readonly path: string;
|
|
4
|
-
}
|
|
5
|
-
export type TransportAddress = UnixTransportAddress;
|
|
6
|
-
export declare function parseTransportAddress(value: string, option: "--listen" | "--connect"): {
|
|
7
|
-
address?: TransportAddress;
|
|
8
|
-
error?: string;
|
|
9
|
-
};
|
|
10
|
-
//# sourceMappingURL=transport-address.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transport-address.d.ts","sourceRoot":"","sources":["../../../src/cli/experimental/transport-address.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,oBAAoB;IACpC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,MAAM,gBAAgB,GAAG,oBAAoB,CAAC;AAEpD,wBAAgB,qBAAqB,CACpC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,UAAU,GAAG,WAAW,GAC9B;IAAE,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAmChD","sourcesContent":["import { posix } from \"node:path\";\n\nexport interface UnixTransportAddress {\n\treadonly transport: \"unix\";\n\treadonly path: string;\n}\n\nexport type TransportAddress = UnixTransportAddress;\n\nexport function parseTransportAddress(\n\tvalue: string,\n\toption: \"--listen\" | \"--connect\",\n): { address?: TransportAddress; error?: string } {\n\tlet url: URL;\n\ttry {\n\t\turl = new URL(value);\n\t} catch {\n\t\treturn { error: `Invalid ${option} address \"${value}\"` };\n\t}\n\tif (url.protocol !== \"unix:\") {\n\t\treturn { error: `Unsupported ${option} transport \"${url.protocol}\"` };\n\t}\n\tif (url.hostname || url.port || url.username || url.password) {\n\t\treturn { error: \"Unix transport address must not include an authority\" };\n\t}\n\tif (\n\t\t!value.startsWith(\"unix:///\") ||\n\t\tvalue.startsWith(\"unix:////\") ||\n\t\tvalue.includes(\"?\") ||\n\t\tvalue.includes(\"#\") ||\n\t\turl.href !== value\n\t) {\n\t\treturn { error: `Invalid ${option} address \"${value}\"` };\n\t}\n\tlet path: string;\n\ttry {\n\t\tpath = decodeURIComponent(url.pathname);\n\t} catch {\n\t\treturn { error: `Invalid ${option} address \"${value}\"` };\n\t}\n\tif (path.includes(\"\\0\")) {\n\t\treturn { error: `Invalid ${option} address \"${value}\"` };\n\t}\n\tif (!posix.isAbsolute(path)) {\n\t\treturn { error: \"Unix transport address requires an absolute path\" };\n\t}\n\treturn { address: { transport: \"unix\", path } };\n}\n"]}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { posix } from "node:path";
|
|
2
|
-
export function parseTransportAddress(value, option) {
|
|
3
|
-
let url;
|
|
4
|
-
try {
|
|
5
|
-
url = new URL(value);
|
|
6
|
-
}
|
|
7
|
-
catch {
|
|
8
|
-
return { error: `Invalid ${option} address "${value}"` };
|
|
9
|
-
}
|
|
10
|
-
if (url.protocol !== "unix:") {
|
|
11
|
-
return { error: `Unsupported ${option} transport "${url.protocol}"` };
|
|
12
|
-
}
|
|
13
|
-
if (url.hostname || url.port || url.username || url.password) {
|
|
14
|
-
return { error: "Unix transport address must not include an authority" };
|
|
15
|
-
}
|
|
16
|
-
if (!value.startsWith("unix:///") ||
|
|
17
|
-
value.startsWith("unix:////") ||
|
|
18
|
-
value.includes("?") ||
|
|
19
|
-
value.includes("#") ||
|
|
20
|
-
url.href !== value) {
|
|
21
|
-
return { error: `Invalid ${option} address "${value}"` };
|
|
22
|
-
}
|
|
23
|
-
let path;
|
|
24
|
-
try {
|
|
25
|
-
path = decodeURIComponent(url.pathname);
|
|
26
|
-
}
|
|
27
|
-
catch {
|
|
28
|
-
return { error: `Invalid ${option} address "${value}"` };
|
|
29
|
-
}
|
|
30
|
-
if (path.includes("\0")) {
|
|
31
|
-
return { error: `Invalid ${option} address "${value}"` };
|
|
32
|
-
}
|
|
33
|
-
if (!posix.isAbsolute(path)) {
|
|
34
|
-
return { error: "Unix transport address requires an absolute path" };
|
|
35
|
-
}
|
|
36
|
-
return { address: { transport: "unix", path } };
|
|
37
|
-
}
|
|
38
|
-
//# sourceMappingURL=transport-address.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transport-address.js","sourceRoot":"","sources":["../../../src/cli/experimental/transport-address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AASlC,MAAM,UAAU,qBAAqB,CACpC,KAAa,EACb,MAAgC,EACiB;IACjD,IAAI,GAAQ,CAAC;IACb,IAAI,CAAC;QACJ,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,EAAE,KAAK,EAAE,WAAW,MAAM,aAAa,KAAK,GAAG,EAAE,CAAC;IAC1D,CAAC;IACD,IAAI,GAAG,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QAC9B,OAAO,EAAE,KAAK,EAAE,eAAe,MAAM,eAAe,GAAG,CAAC,QAAQ,GAAG,EAAE,CAAC;IACvE,CAAC;IACD,IAAI,GAAG,CAAC,QAAQ,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,QAAQ,IAAI,GAAG,CAAC,QAAQ,EAAE,CAAC;QAC9D,OAAO,EAAE,KAAK,EAAE,sDAAsD,EAAE,CAAC;IAC1E,CAAC;IACD,IACC,CAAC,KAAK,CAAC,UAAU,CAAC,UAAU,CAAC;QAC7B,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC;QAC7B,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC;QACnB,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC;QACnB,GAAG,CAAC,IAAI,KAAK,KAAK,EACjB,CAAC;QACF,OAAO,EAAE,KAAK,EAAE,WAAW,MAAM,aAAa,KAAK,GAAG,EAAE,CAAC;IAC1D,CAAC;IACD,IAAI,IAAY,CAAC;IACjB,IAAI,CAAC;QACJ,IAAI,GAAG,kBAAkB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACzC,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,EAAE,KAAK,EAAE,WAAW,MAAM,aAAa,KAAK,GAAG,EAAE,CAAC;IAC1D,CAAC;IACD,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QACzB,OAAO,EAAE,KAAK,EAAE,WAAW,MAAM,aAAa,KAAK,GAAG,EAAE,CAAC;IAC1D,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QAC7B,OAAO,EAAE,KAAK,EAAE,kDAAkD,EAAE,CAAC;IACtE,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC;AAAA,CAChD","sourcesContent":["import { posix } from \"node:path\";\n\nexport interface UnixTransportAddress {\n\treadonly transport: \"unix\";\n\treadonly path: string;\n}\n\nexport type TransportAddress = UnixTransportAddress;\n\nexport function parseTransportAddress(\n\tvalue: string,\n\toption: \"--listen\" | \"--connect\",\n): { address?: TransportAddress; error?: string } {\n\tlet url: URL;\n\ttry {\n\t\turl = new URL(value);\n\t} catch {\n\t\treturn { error: `Invalid ${option} address \"${value}\"` };\n\t}\n\tif (url.protocol !== \"unix:\") {\n\t\treturn { error: `Unsupported ${option} transport \"${url.protocol}\"` };\n\t}\n\tif (url.hostname || url.port || url.username || url.password) {\n\t\treturn { error: \"Unix transport address must not include an authority\" };\n\t}\n\tif (\n\t\t!value.startsWith(\"unix:///\") ||\n\t\tvalue.startsWith(\"unix:////\") ||\n\t\tvalue.includes(\"?\") ||\n\t\tvalue.includes(\"#\") ||\n\t\turl.href !== value\n\t) {\n\t\treturn { error: `Invalid ${option} address \"${value}\"` };\n\t}\n\tlet path: string;\n\ttry {\n\t\tpath = decodeURIComponent(url.pathname);\n\t} catch {\n\t\treturn { error: `Invalid ${option} address \"${value}\"` };\n\t}\n\tif (path.includes(\"\\0\")) {\n\t\treturn { error: `Invalid ${option} address \"${value}\"` };\n\t}\n\tif (!posix.isAbsolute(path)) {\n\t\treturn { error: \"Unix transport address requires an absolute path\" };\n\t}\n\treturn { address: { transport: \"unix\", path } };\n}\n"]}
|
package/dist/client/index.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export { type CreateRemoteSessionOptions, RemoteSession, type RemoteSessionLifecycle, type RemoteSessionOperation, type RemoteSessionOptions, type RemoteSessionState, } from "./remote-session.ts";
|
|
2
|
-
export { applyTranscriptProgress, applyTranscriptSnapshot, createTranscriptState, selectTranscript, type TranscriptState, } from "./transcript.ts";
|
|
3
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,0BAA0B,EAC/B,aAAa,EACb,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,GACvB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACN,uBAAuB,EACvB,uBAAuB,EACvB,qBAAqB,EACrB,gBAAgB,EAChB,KAAK,eAAe,GACpB,MAAM,iBAAiB,CAAC","sourcesContent":["export {\n\ttype CreateRemoteSessionOptions,\n\tRemoteSession,\n\ttype RemoteSessionLifecycle,\n\ttype RemoteSessionOperation,\n\ttype RemoteSessionOptions,\n\ttype RemoteSessionState,\n} from \"./remote-session.ts\";\nexport {\n\tapplyTranscriptProgress,\n\tapplyTranscriptSnapshot,\n\tcreateTranscriptState,\n\tselectTranscript,\n\ttype TranscriptState,\n} from \"./transcript.ts\";\n"]}
|
package/dist/client/index.js
DELETED
package/dist/client/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,aAAa,GAKb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACN,uBAAuB,EACvB,uBAAuB,EACvB,qBAAqB,EACrB,gBAAgB,GAEhB,MAAM,iBAAiB,CAAC","sourcesContent":["export {\n\ttype CreateRemoteSessionOptions,\n\tRemoteSession,\n\ttype RemoteSessionLifecycle,\n\ttype RemoteSessionOperation,\n\ttype RemoteSessionOptions,\n\ttype RemoteSessionState,\n} from \"./remote-session.ts\";\nexport {\n\tapplyTranscriptProgress,\n\tapplyTranscriptSnapshot,\n\tcreateTranscriptState,\n\tselectTranscript,\n\ttype TranscriptState,\n} from \"./transcript.ts\";\n"]}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import type { ConnectionState, ConnectionStateChange, PiClient, Unsubscribe } from "@earendil-works/pi-client";
|
|
2
|
-
import type { ModelMetadata, ModelRef, SessionMetadata, SessionPhase, SessionSnapshot, ThinkingLevel, TranscriptItem } from "@earendil-works/pi-protocol";
|
|
3
|
-
export type RemoteSessionOperation = "open" | "create" | "submit" | "abort" | "setModel" | "setThinking" | "reconnect";
|
|
4
|
-
export type RemoteSessionLifecycle = {
|
|
5
|
-
readonly status: "unbound";
|
|
6
|
-
} | {
|
|
7
|
-
readonly status: "ready";
|
|
8
|
-
} | {
|
|
9
|
-
readonly status: "busy";
|
|
10
|
-
readonly operation: RemoteSessionOperation;
|
|
11
|
-
} | {
|
|
12
|
-
readonly status: "disposed";
|
|
13
|
-
};
|
|
14
|
-
export interface RemoteSessionState {
|
|
15
|
-
readonly lifecycle: RemoteSessionLifecycle;
|
|
16
|
-
readonly snapshot?: SessionSnapshot;
|
|
17
|
-
readonly transcript: readonly TranscriptItem[];
|
|
18
|
-
}
|
|
19
|
-
export interface CreateRemoteSessionOptions {
|
|
20
|
-
cwd: string;
|
|
21
|
-
model?: ModelRef;
|
|
22
|
-
thinkingLevel?: ThinkingLevel;
|
|
23
|
-
}
|
|
24
|
-
export interface RemoteSessionOptions {
|
|
25
|
-
onListenerError?: (error: Error) => void;
|
|
26
|
-
}
|
|
27
|
-
export declare class RemoteSession {
|
|
28
|
-
#private;
|
|
29
|
-
private constructor();
|
|
30
|
-
get id(): string | undefined;
|
|
31
|
-
get state(): RemoteSessionState;
|
|
32
|
-
get snapshot(): SessionSnapshot | undefined;
|
|
33
|
-
get phase(): SessionPhase | undefined;
|
|
34
|
-
get operation(): RemoteSessionOperation | undefined;
|
|
35
|
-
get models(): readonly ModelMetadata[];
|
|
36
|
-
get sessions(): readonly SessionMetadata[];
|
|
37
|
-
get connectionState(): ConnectionState;
|
|
38
|
-
get disposed(): boolean;
|
|
39
|
-
subscribe(listener: (state: RemoteSessionState) => void): Unsubscribe;
|
|
40
|
-
onConnectionStateChange(listener: (change: ConnectionStateChange) => void): Unsubscribe;
|
|
41
|
-
static open(client: PiClient, sessionId: string, options?: RemoteSessionOptions): Promise<RemoteSession>;
|
|
42
|
-
open(sessionId: string): Promise<void>;
|
|
43
|
-
static create(client: PiClient, createOptions: CreateRemoteSessionOptions, options?: RemoteSessionOptions): Promise<RemoteSession>;
|
|
44
|
-
create(options: CreateRemoteSessionOptions): Promise<void>;
|
|
45
|
-
submit(text: string): Promise<void>;
|
|
46
|
-
abort(): Promise<void>;
|
|
47
|
-
setModel(model: ModelRef): Promise<void>;
|
|
48
|
-
setThinking(thinkingLevel: ThinkingLevel): Promise<void>;
|
|
49
|
-
reconnect(): Promise<void>;
|
|
50
|
-
dispose(): Promise<void>;
|
|
51
|
-
[Symbol.asyncDispose](): Promise<void>;
|
|
52
|
-
}
|
|
53
|
-
//# sourceMappingURL=remote-session.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"remote-session.d.ts","sourceRoot":"","sources":["../../src/client/remote-session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,eAAe,EACf,qBAAqB,EACrB,QAAQ,EAER,WAAW,EACX,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EACX,aAAa,EACb,QAAQ,EAER,eAAe,EACf,YAAY,EACZ,eAAe,EACf,aAAa,EACb,cAAc,EACd,MAAM,6BAA6B,CAAC;AASrC,MAAM,MAAM,sBAAsB,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,UAAU,GAAG,aAAa,GAAG,WAAW,CAAC;AAEvH,MAAM,MAAM,sBAAsB,GAC/B;IAAE,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAA;CAAE,GAC9B;IAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;CAAE,GAC5B;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,sBAAsB,CAAA;CAAE,GACvE;IAAE,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAA;CAAE,CAAC;AAEnC,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,SAAS,EAAE,sBAAsB,CAAC;IAC3C,QAAQ,CAAC,QAAQ,CAAC,EAAE,eAAe,CAAC;IACpC,QAAQ,CAAC,UAAU,EAAE,SAAS,cAAc,EAAE,CAAC;CA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,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/D;IAEK,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAWxC;IAEK,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAO3B;IAEK,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAM7C;IAEK,WAAW,CAAC,aAAa,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAM7D;IAEK,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAW/B;IAED,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAcvB;IAED,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAErC;CAgLD","sourcesContent":["import type {\n\tConnectionState,\n\tConnectionStateChange,\n\tPiClient,\n\tSessionLease,\n\tUnsubscribe,\n} from \"@earendil-works/pi-client\";\nimport type {\n\tModelMetadata,\n\tModelRef,\n\tServerEvent,\n\tSessionMetadata,\n\tSessionPhase,\n\tSessionSnapshot,\n\tThinkingLevel,\n\tTranscriptItem,\n} from \"@earendil-works/pi-protocol\";\nimport {\n\tapplyTranscriptProgress,\n\tapplyTranscriptSnapshot,\n\tcreateTranscriptState,\n\tselectTranscript,\n\ttype TranscriptState,\n} from \"./transcript.ts\";\n\nexport type RemoteSessionOperation = \"open\" | \"create\" | \"submit\" | \"abort\" | \"setModel\" | \"setThinking\" | \"reconnect\";\n\nexport type RemoteSessionLifecycle =\n\t| { readonly status: \"unbound\" }\n\t| { readonly status: \"ready\" }\n\t| { readonly status: \"busy\"; readonly operation: RemoteSessionOperation }\n\t| { readonly status: \"disposed\" };\n\nexport interface RemoteSessionState {\n\treadonly lifecycle: RemoteSessionLifecycle;\n\treadonly snapshot?: SessionSnapshot;\n\treadonly transcript: readonly TranscriptItem[];\n}\n\nexport interface CreateRemoteSessionOptions {\n\tcwd: string;\n\tmodel?: ModelRef;\n\tthinkingLevel?: ThinkingLevel;\n}\n\nexport interface RemoteSessionOptions {\n\tonListenerError?: (error: Error) => void;\n}\n\nclass RemoteSessionDisposedError extends Error {\n\tconstructor() {\n\t\tsuper(\"Remote session is disposed\");\n\t\tthis.name = \"RemoteSessionDisposedError\";\n\t}\n}\n\nasync function settleRemoteSessionDisposal(cleanup: readonly Promise<void>[]): Promise<void> {\n\tconst results = await Promise.allSettled(cleanup);\n\tconst errors = results.flatMap((result) =>\n\t\tresult.status === \"rejected\" && !(result.reason instanceof RemoteSessionDisposedError) ? [result.reason] : [],\n\t);\n\tif (errors.length === 1) throw errors[0];\n\tif (errors.length > 1) throw new AggregateError(errors, \"Failed to dispose remote session\");\n}\n\nexport class RemoteSession {\n\treadonly #client: PiClient;\n\treadonly #onListenerError: ((error: Error) => void) | undefined;\n\t#lifecycle: RemoteSessionLifecycle = { status: \"unbound\" };\n\t#handle: SessionLease | undefined;\n\t#transcript: TranscriptState | undefined;\n\t#unsubscribeSnapshot: Unsubscribe | undefined;\n\t#unsubscribeEvents: Unsubscribe | undefined;\n\treadonly #listeners = new Set<(state: RemoteSessionState) => void>();\n\treadonly #pendingAttachmentOperations = new Set<Promise<void>>();\n\treadonly #activeOperationStates = new Set<RemoteSessionLifecycle>();\n\t#disposePromise: Promise<void> | undefined;\n\t#resolveDisposeSignal: () => void = () => {};\n\treadonly #disposeSignal = new Promise<void>((resolve) => {\n\t\tthis.#resolveDisposeSignal = resolve;\n\t});\n\n\tprivate constructor(client: PiClient, options: RemoteSessionOptions = {}) {\n\t\tthis.#client = client;\n\t\tthis.#onListenerError = options.onListenerError;\n\t}\n\n\tget id(): string | undefined {\n\t\treturn this.#handle?.id;\n\t}\n\n\tget state(): RemoteSessionState {\n\t\treturn {\n\t\t\tlifecycle: this.#lifecycle,\n\t\t\tsnapshot: this.#transcript?.snapshot,\n\t\t\ttranscript: this.#transcript ? selectTranscript(this.#transcript) : [],\n\t\t};\n\t}\n\n\tget snapshot(): SessionSnapshot | undefined {\n\t\treturn this.#transcript?.snapshot;\n\t}\n\n\tget phase(): SessionPhase | undefined {\n\t\treturn this.snapshot?.phase;\n\t}\n\n\tget operation(): RemoteSessionOperation | undefined {\n\t\treturn this.#lifecycle.status === \"busy\" ? this.#lifecycle.operation : undefined;\n\t}\n\n\tget models(): readonly ModelMetadata[] {\n\t\treturn this.#client.snapshot?.models ?? [];\n\t}\n\n\tget sessions(): readonly SessionMetadata[] {\n\t\treturn this.#client.snapshot?.sessions ?? [];\n\t}\n\n\tget connectionState(): ConnectionState {\n\t\treturn this.#client.connectionState;\n\t}\n\n\tget disposed(): boolean {\n\t\treturn this.#lifecycle.status === \"disposed\";\n\t}\n\n\tsubscribe(listener: (state: RemoteSessionState) => void): Unsubscribe {\n\t\tthis.#assertNotDisposed();\n\t\tthis.#listeners.add(listener);\n\t\tthis.#callListener(listener, this.state);\n\t\treturn () => this.#listeners.delete(listener);\n\t}\n\n\tonConnectionStateChange(listener: (change: ConnectionStateChange) => void): Unsubscribe {\n\t\tthis.#assertNotDisposed();\n\t\treturn this.#client.onConnectionStateChange(listener);\n\t}\n\n\tstatic async open(client: PiClient, sessionId: string, options: RemoteSessionOptions = {}): Promise<RemoteSession> {\n\t\tconst session = new RemoteSession(client, options);\n\t\ttry {\n\t\t\tawait session.open(sessionId);\n\t\t\treturn session;\n\t\t} catch (error) {\n\t\t\tawait session.dispose();\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tasync open(sessionId: string): Promise<void> {\n\t\tif (this.#handle?.id === sessionId && this.#lifecycle.status === \"ready\") return;\n\t\tawait this.#replace(\"open\", () => this.#client.acquireSession(sessionId, { mode: \"exclusive\" }));\n\t}\n\n\tstatic async create(\n\t\tclient: PiClient,\n\t\tcreateOptions: CreateRemoteSessionOptions,\n\t\toptions: RemoteSessionOptions = {},\n\t): Promise<RemoteSession> {\n\t\tconst session = new RemoteSession(client, options);\n\t\ttry {\n\t\t\tawait session.create(createOptions);\n\t\t\treturn session;\n\t\t} catch (error) {\n\t\t\tawait session.dispose();\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tasync create(options: CreateRemoteSessionOptions): Promise<void> {\n\t\tawait this.#replace(\"create\", () => this.#client.createSession(options));\n\t}\n\n\tasync submit(text: string): Promise<void> {\n\t\tconst normalized = text.trim();\n\t\tif (!normalized) return;\n\t\tthis.#assertAvailable();\n\t\tconst handle = this.#requireHandle();\n\t\tif (this.phase !== \"idle\" && this.phase !== \"turn\") {\n\t\t\tthrow new Error(`Session cannot accept input during ${this.phase ?? \"unknown\"} phase`);\n\t\t}\n\t\tawait this.#runOperation(\"submit\", () =>\n\t\t\t(this.phase === \"idle\" ? handle.prompt(normalized) : handle.steer(normalized)).then(() => undefined),\n\t\t);\n\t}\n\n\tasync abort(): Promise<void> {\n\t\tconst preemptingSubmit = this.#lifecycle.status === \"busy\" && this.#lifecycle.operation === \"submit\";\n\t\tif (preemptingSubmit) this.#assertNotDisposed();\n\t\telse this.#assertAvailable();\n\t\tconst handle = this.#requireHandle();\n\t\tif (this.phase === \"idle\" && !preemptingSubmit) return;\n\t\tawait this.#runOperation(\"abort\", () => handle.abort().then(() => undefined), preemptingSubmit);\n\t}\n\n\tasync setModel(model: ModelRef): Promise<void> {\n\t\tawait this.#runIdleOperation(\"setModel\", \"change model\", () =>\n\t\t\tthis.#requireHandle()\n\t\t\t\t.setModel(model)\n\t\t\t\t.then(() => undefined),\n\t\t);\n\t}\n\n\tasync setThinking(thinkingLevel: ThinkingLevel): Promise<void> {\n\t\tawait this.#runIdleOperation(\"setThinking\", \"change thinking level\", () =>\n\t\t\tthis.#requireHandle()\n\t\t\t\t.setThinking(thinkingLevel)\n\t\t\t\t.then(() => undefined),\n\t\t);\n\t}\n\n\tasync reconnect(): Promise<void> {\n\t\tthis.#assertAvailable();\n\t\tconst sessionId = this.#requireHandle().id;\n\t\tawait this.#runOperation(\"reconnect\", () =>\n\t\t\tthis.#trackAttachmentOperation(async () => {\n\t\t\t\tawait this.#client.reconnect();\n\t\t\t\tconst handle = await this.#client.acquireSession(sessionId, { mode: \"exclusive\" });\n\t\t\t\tawait this.#assertNotDisposedAfterAwait(handle);\n\t\t\t\tthis.#bind(handle);\n\t\t\t}),\n\t\t);\n\t}\n\n\tdispose(): Promise<void> {\n\t\tif (this.#disposePromise) return this.#disposePromise;\n\t\tconst handle = this.#handle;\n\t\tthis.#lifecycle = { status: \"disposed\" };\n\t\tthis.#resolveDisposeSignal();\n\t\tthis.#clearSubscriptions();\n\t\tthis.#handle = undefined;\n\t\tthis.#transcript = undefined;\n\t\tconst cleanup = [...this.#pendingAttachmentOperations];\n\t\tif (handle) cleanup.push(handle.dispose());\n\t\tthis.#disposePromise = settleRemoteSessionDisposal(cleanup);\n\t\tthis.#notify();\n\t\tthis.#listeners.clear();\n\t\treturn this.#disposePromise;\n\t}\n\n\t[Symbol.asyncDispose](): Promise<void> {\n\t\treturn this.dispose();\n\t}\n\n\tasync #replace(operation: \"open\" | \"create\", prepare: () => Promise<SessionLease>): Promise<void> {\n\t\tthis.#assertAvailable();\n\t\tif (this.#handle && this.phase !== \"idle\") {\n\t\t\tthrow new Error(`Cannot ${operation} a session while session is ${this.phase ?? \"unavailable\"}`);\n\t\t}\n\t\tawait this.#runOperation(operation, () =>\n\t\t\tthis.#trackAttachmentOperation(() => this.#prepareReplacement(operation, prepare)),\n\t\t);\n\t}\n\n\tasync #trackAttachmentOperation(run: () => Promise<void>): Promise<void> {\n\t\tconst pending = run();\n\t\tthis.#pendingAttachmentOperations.add(pending);\n\t\ttry {\n\t\t\tawait pending;\n\t\t} finally {\n\t\t\tthis.#pendingAttachmentOperations.delete(pending);\n\t\t}\n\t}\n\n\tasync #prepareReplacement(operation: \"open\" | \"create\", prepare: () => Promise<SessionLease>): Promise<void> {\n\t\tconst previous = this.#handle;\n\t\tconst next = await prepare();\n\t\tawait this.#assertNotDisposedAfterAwait(next);\n\t\tconst snapshot = next.snapshot;\n\t\tif (!snapshot) {\n\t\t\tawait this.#detach(next);\n\t\t\tthrow new Error(`Session ${next.id} did not provide a snapshot`);\n\t\t}\n\t\tif (previous && previous.id !== next.id && previous.attached && this.phase !== \"idle\") {\n\t\t\tawait this.#detach(next);\n\t\t\tthrow new Error(`Cannot ${operation} a session while session is ${this.phase ?? \"unavailable\"}`);\n\t\t}\n\t\tif (previous && previous.id !== next.id && previous.attached) {\n\t\t\ttry {\n\t\t\t\tawait previous.detach();\n\t\t\t} catch (error) {\n\t\t\t\ttry {\n\t\t\t\t\tawait this.#detach(next);\n\t\t\t\t} catch (cleanupError) {\n\t\t\t\t\tthrow new AggregateError([error, cleanupError], \"Failed to replace remote session attachment\");\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t\tawait this.#assertNotDisposedAfterAwait(next);\n\t\tthis.#bind(next, snapshot);\n\t}\n\n\tasync #runIdleOperation(\n\t\toperation: \"setModel\" | \"setThinking\",\n\t\tdescription: string,\n\t\trun: () => Promise<void>,\n\t): Promise<void> {\n\t\tthis.#assertAvailable();\n\t\tthis.#requireHandle();\n\t\tif (this.phase !== \"idle\") {\n\t\t\tthrow new Error(`Cannot ${description} while session is ${this.phase ?? \"unavailable\"}`);\n\t\t}\n\t\tawait this.#runOperation(operation, run);\n\t}\n\n\tasync #runOperation(operation: RemoteSessionOperation, run: () => Promise<void>, preempt = false): Promise<void> {\n\t\tif (preempt) this.#assertNotDisposed();\n\t\telse this.#assertAvailable();\n\t\tconst previous = this.#lifecycle;\n\t\tconst busy: RemoteSessionLifecycle = { status: \"busy\", operation };\n\t\tthis.#lifecycle = busy;\n\t\tthis.#activeOperationStates.add(busy);\n\t\tthis.#notify();\n\t\tconst running = run();\n\t\ttry {\n\t\t\tawait Promise.race([\n\t\t\t\trunning,\n\t\t\t\tthis.#disposeSignal.then(() => {\n\t\t\t\t\tthrow new Error(\"Remote session is disposed\");\n\t\t\t\t}),\n\t\t\t]);\n\t\t} finally {\n\t\t\tthis.#activeOperationStates.delete(busy);\n\t\t\tif (!this.disposed && this.#lifecycle === busy) {\n\t\t\t\tthis.#lifecycle =\n\t\t\t\t\tpreempt && this.#activeOperationStates.has(previous)\n\t\t\t\t\t\t? previous\n\t\t\t\t\t\t: this.#handle\n\t\t\t\t\t\t\t? { status: \"ready\" }\n\t\t\t\t\t\t\t: { status: \"unbound\" };\n\t\t\t\tthis.#notify();\n\t\t\t}\n\t\t}\n\t}\n\n\t#bind(handle: SessionLease, knownSnapshot?: SessionSnapshot): void {\n\t\tconst snapshot = knownSnapshot ?? handle.snapshot;\n\t\tif (!snapshot) throw new Error(`Session ${handle.id} did not provide a snapshot`);\n\t\tthis.#clearSubscriptions();\n\t\tthis.#handle = handle;\n\t\tthis.#transcript = createTranscriptState(snapshot);\n\t\tthis.#unsubscribeSnapshot = handle.subscribe((next) => {\n\t\t\tif (!this.#transcript) return;\n\t\t\tthis.#transcript = applyTranscriptSnapshot(this.#transcript, next);\n\t\t\tthis.#notify();\n\t\t});\n\t\tthis.#unsubscribeEvents = handle.onEvent((event) => this.#handleEvent(event));\n\t}\n\n\t#handleEvent(event: ServerEvent): void {\n\t\tif (event.type === \"session_removed\") {\n\t\t\tthis.#clearSubscriptions();\n\t\t\tthis.#handle = undefined;\n\t\t\tthis.#transcript = undefined;\n\t\t\tif (this.#lifecycle.status !== \"busy\") this.#lifecycle = { status: \"unbound\" };\n\t\t\tthis.#notify();\n\t\t\treturn;\n\t\t}\n\t\tif (event.type !== \"session_progress\" || !this.#transcript) return;\n\t\tthis.#transcript = applyTranscriptProgress(this.#transcript, event.progress);\n\t\tthis.#notify();\n\t}\n\n\t#notify(): void {\n\t\tconst state = this.state;\n\t\tfor (const listener of this.#listeners) this.#callListener(listener, state);\n\t}\n\n\t#callListener(listener: (state: RemoteSessionState) => void, state: RemoteSessionState): void {\n\t\ttry {\n\t\t\tlistener(state);\n\t\t} catch (error) {\n\t\t\tthis.#reportListenerError(error);\n\t\t}\n\t}\n\n\t#reportListenerError(error: unknown): void {\n\t\tif (!this.#onListenerError) return;\n\t\ttry {\n\t\t\tthis.#onListenerError(error instanceof Error ? error : new Error(String(error)));\n\t\t} catch {\n\t\t\t// Diagnostics cannot affect session or transport state.\n\t\t}\n\t}\n\n\t#clearSubscriptions(): void {\n\t\tthis.#unsubscribeSnapshot?.();\n\t\tthis.#unsubscribeEvents?.();\n\t\tthis.#unsubscribeSnapshot = undefined;\n\t\tthis.#unsubscribeEvents = undefined;\n\t}\n\n\t#requireHandle(): SessionLease {\n\t\tif (!this.#handle) throw new Error(\"No remote session is attached\");\n\t\treturn this.#handle;\n\t}\n\n\t#assertAvailable(): void {\n\t\tthis.#assertNotDisposed();\n\t\tif (this.#lifecycle.status === \"busy\") {\n\t\t\tthrow new Error(`Remote session is busy with ${this.#lifecycle.operation}`);\n\t\t}\n\t}\n\n\t#assertNotDisposed(): void {\n\t\tif (this.disposed) throw new Error(\"Remote session is disposed\");\n\t}\n\n\tasync #assertNotDisposedAfterAwait(handle: SessionLease): Promise<void> {\n\t\tif (!this.disposed) return;\n\t\tawait this.#detach(handle);\n\t\tthrow new RemoteSessionDisposedError();\n\t}\n\n\tasync #detach(handle: SessionLease): Promise<void> {\n\t\tawait handle.dispose();\n\t}\n}\n"]}
|
|
@@ -1,340 +0,0 @@
|
|
|
1
|
-
import { applyTranscriptProgress, applyTranscriptSnapshot, createTranscriptState, selectTranscript, } from "./transcript.js";
|
|
2
|
-
class RemoteSessionDisposedError extends Error {
|
|
3
|
-
constructor() {
|
|
4
|
-
super("Remote session is disposed");
|
|
5
|
-
this.name = "RemoteSessionDisposedError";
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
async function settleRemoteSessionDisposal(cleanup) {
|
|
9
|
-
const results = await Promise.allSettled(cleanup);
|
|
10
|
-
const errors = results.flatMap((result) => result.status === "rejected" && !(result.reason instanceof RemoteSessionDisposedError) ? [result.reason] : []);
|
|
11
|
-
if (errors.length === 1)
|
|
12
|
-
throw errors[0];
|
|
13
|
-
if (errors.length > 1)
|
|
14
|
-
throw new AggregateError(errors, "Failed to dispose remote session");
|
|
15
|
-
}
|
|
16
|
-
export class RemoteSession {
|
|
17
|
-
#client;
|
|
18
|
-
#onListenerError;
|
|
19
|
-
#lifecycle = { status: "unbound" };
|
|
20
|
-
#handle;
|
|
21
|
-
#transcript;
|
|
22
|
-
#unsubscribeSnapshot;
|
|
23
|
-
#unsubscribeEvents;
|
|
24
|
-
#listeners = new Set();
|
|
25
|
-
#pendingAttachmentOperations = new Set();
|
|
26
|
-
#activeOperationStates = new Set();
|
|
27
|
-
#disposePromise;
|
|
28
|
-
#resolveDisposeSignal = () => { };
|
|
29
|
-
#disposeSignal = new Promise((resolve) => {
|
|
30
|
-
this.#resolveDisposeSignal = resolve;
|
|
31
|
-
});
|
|
32
|
-
constructor(client, options = {}) {
|
|
33
|
-
this.#client = client;
|
|
34
|
-
this.#onListenerError = options.onListenerError;
|
|
35
|
-
}
|
|
36
|
-
get id() {
|
|
37
|
-
return this.#handle?.id;
|
|
38
|
-
}
|
|
39
|
-
get state() {
|
|
40
|
-
return {
|
|
41
|
-
lifecycle: this.#lifecycle,
|
|
42
|
-
snapshot: this.#transcript?.snapshot,
|
|
43
|
-
transcript: this.#transcript ? selectTranscript(this.#transcript) : [],
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
get snapshot() {
|
|
47
|
-
return this.#transcript?.snapshot;
|
|
48
|
-
}
|
|
49
|
-
get phase() {
|
|
50
|
-
return this.snapshot?.phase;
|
|
51
|
-
}
|
|
52
|
-
get operation() {
|
|
53
|
-
return this.#lifecycle.status === "busy" ? this.#lifecycle.operation : undefined;
|
|
54
|
-
}
|
|
55
|
-
get models() {
|
|
56
|
-
return this.#client.snapshot?.models ?? [];
|
|
57
|
-
}
|
|
58
|
-
get sessions() {
|
|
59
|
-
return this.#client.snapshot?.sessions ?? [];
|
|
60
|
-
}
|
|
61
|
-
get connectionState() {
|
|
62
|
-
return this.#client.connectionState;
|
|
63
|
-
}
|
|
64
|
-
get disposed() {
|
|
65
|
-
return this.#lifecycle.status === "disposed";
|
|
66
|
-
}
|
|
67
|
-
subscribe(listener) {
|
|
68
|
-
this.#assertNotDisposed();
|
|
69
|
-
this.#listeners.add(listener);
|
|
70
|
-
this.#callListener(listener, this.state);
|
|
71
|
-
return () => this.#listeners.delete(listener);
|
|
72
|
-
}
|
|
73
|
-
onConnectionStateChange(listener) {
|
|
74
|
-
this.#assertNotDisposed();
|
|
75
|
-
return this.#client.onConnectionStateChange(listener);
|
|
76
|
-
}
|
|
77
|
-
static async open(client, sessionId, options = {}) {
|
|
78
|
-
const session = new RemoteSession(client, options);
|
|
79
|
-
try {
|
|
80
|
-
await session.open(sessionId);
|
|
81
|
-
return session;
|
|
82
|
-
}
|
|
83
|
-
catch (error) {
|
|
84
|
-
await session.dispose();
|
|
85
|
-
throw error;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
async open(sessionId) {
|
|
89
|
-
if (this.#handle?.id === sessionId && this.#lifecycle.status === "ready")
|
|
90
|
-
return;
|
|
91
|
-
await this.#replace("open", () => this.#client.acquireSession(sessionId, { mode: "exclusive" }));
|
|
92
|
-
}
|
|
93
|
-
static async create(client, createOptions, options = {}) {
|
|
94
|
-
const session = new RemoteSession(client, options);
|
|
95
|
-
try {
|
|
96
|
-
await session.create(createOptions);
|
|
97
|
-
return session;
|
|
98
|
-
}
|
|
99
|
-
catch (error) {
|
|
100
|
-
await session.dispose();
|
|
101
|
-
throw error;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
async create(options) {
|
|
105
|
-
await this.#replace("create", () => this.#client.createSession(options));
|
|
106
|
-
}
|
|
107
|
-
async submit(text) {
|
|
108
|
-
const normalized = text.trim();
|
|
109
|
-
if (!normalized)
|
|
110
|
-
return;
|
|
111
|
-
this.#assertAvailable();
|
|
112
|
-
const handle = this.#requireHandle();
|
|
113
|
-
if (this.phase !== "idle" && this.phase !== "turn") {
|
|
114
|
-
throw new Error(`Session cannot accept input during ${this.phase ?? "unknown"} phase`);
|
|
115
|
-
}
|
|
116
|
-
await this.#runOperation("submit", () => (this.phase === "idle" ? handle.prompt(normalized) : handle.steer(normalized)).then(() => undefined));
|
|
117
|
-
}
|
|
118
|
-
async abort() {
|
|
119
|
-
const preemptingSubmit = this.#lifecycle.status === "busy" && this.#lifecycle.operation === "submit";
|
|
120
|
-
if (preemptingSubmit)
|
|
121
|
-
this.#assertNotDisposed();
|
|
122
|
-
else
|
|
123
|
-
this.#assertAvailable();
|
|
124
|
-
const handle = this.#requireHandle();
|
|
125
|
-
if (this.phase === "idle" && !preemptingSubmit)
|
|
126
|
-
return;
|
|
127
|
-
await this.#runOperation("abort", () => handle.abort().then(() => undefined), preemptingSubmit);
|
|
128
|
-
}
|
|
129
|
-
async setModel(model) {
|
|
130
|
-
await this.#runIdleOperation("setModel", "change model", () => this.#requireHandle()
|
|
131
|
-
.setModel(model)
|
|
132
|
-
.then(() => undefined));
|
|
133
|
-
}
|
|
134
|
-
async setThinking(thinkingLevel) {
|
|
135
|
-
await this.#runIdleOperation("setThinking", "change thinking level", () => this.#requireHandle()
|
|
136
|
-
.setThinking(thinkingLevel)
|
|
137
|
-
.then(() => undefined));
|
|
138
|
-
}
|
|
139
|
-
async reconnect() {
|
|
140
|
-
this.#assertAvailable();
|
|
141
|
-
const sessionId = this.#requireHandle().id;
|
|
142
|
-
await this.#runOperation("reconnect", () => this.#trackAttachmentOperation(async () => {
|
|
143
|
-
await this.#client.reconnect();
|
|
144
|
-
const handle = await this.#client.acquireSession(sessionId, { mode: "exclusive" });
|
|
145
|
-
await this.#assertNotDisposedAfterAwait(handle);
|
|
146
|
-
this.#bind(handle);
|
|
147
|
-
}));
|
|
148
|
-
}
|
|
149
|
-
dispose() {
|
|
150
|
-
if (this.#disposePromise)
|
|
151
|
-
return this.#disposePromise;
|
|
152
|
-
const handle = this.#handle;
|
|
153
|
-
this.#lifecycle = { status: "disposed" };
|
|
154
|
-
this.#resolveDisposeSignal();
|
|
155
|
-
this.#clearSubscriptions();
|
|
156
|
-
this.#handle = undefined;
|
|
157
|
-
this.#transcript = undefined;
|
|
158
|
-
const cleanup = [...this.#pendingAttachmentOperations];
|
|
159
|
-
if (handle)
|
|
160
|
-
cleanup.push(handle.dispose());
|
|
161
|
-
this.#disposePromise = settleRemoteSessionDisposal(cleanup);
|
|
162
|
-
this.#notify();
|
|
163
|
-
this.#listeners.clear();
|
|
164
|
-
return this.#disposePromise;
|
|
165
|
-
}
|
|
166
|
-
[Symbol.asyncDispose]() {
|
|
167
|
-
return this.dispose();
|
|
168
|
-
}
|
|
169
|
-
async #replace(operation, prepare) {
|
|
170
|
-
this.#assertAvailable();
|
|
171
|
-
if (this.#handle && this.phase !== "idle") {
|
|
172
|
-
throw new Error(`Cannot ${operation} a session while session is ${this.phase ?? "unavailable"}`);
|
|
173
|
-
}
|
|
174
|
-
await this.#runOperation(operation, () => this.#trackAttachmentOperation(() => this.#prepareReplacement(operation, prepare)));
|
|
175
|
-
}
|
|
176
|
-
async #trackAttachmentOperation(run) {
|
|
177
|
-
const pending = run();
|
|
178
|
-
this.#pendingAttachmentOperations.add(pending);
|
|
179
|
-
try {
|
|
180
|
-
await pending;
|
|
181
|
-
}
|
|
182
|
-
finally {
|
|
183
|
-
this.#pendingAttachmentOperations.delete(pending);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
async #prepareReplacement(operation, prepare) {
|
|
187
|
-
const previous = this.#handle;
|
|
188
|
-
const next = await prepare();
|
|
189
|
-
await this.#assertNotDisposedAfterAwait(next);
|
|
190
|
-
const snapshot = next.snapshot;
|
|
191
|
-
if (!snapshot) {
|
|
192
|
-
await this.#detach(next);
|
|
193
|
-
throw new Error(`Session ${next.id} did not provide a snapshot`);
|
|
194
|
-
}
|
|
195
|
-
if (previous && previous.id !== next.id && previous.attached && this.phase !== "idle") {
|
|
196
|
-
await this.#detach(next);
|
|
197
|
-
throw new Error(`Cannot ${operation} a session while session is ${this.phase ?? "unavailable"}`);
|
|
198
|
-
}
|
|
199
|
-
if (previous && previous.id !== next.id && previous.attached) {
|
|
200
|
-
try {
|
|
201
|
-
await previous.detach();
|
|
202
|
-
}
|
|
203
|
-
catch (error) {
|
|
204
|
-
try {
|
|
205
|
-
await this.#detach(next);
|
|
206
|
-
}
|
|
207
|
-
catch (cleanupError) {
|
|
208
|
-
throw new AggregateError([error, cleanupError], "Failed to replace remote session attachment");
|
|
209
|
-
}
|
|
210
|
-
throw error;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
await this.#assertNotDisposedAfterAwait(next);
|
|
214
|
-
this.#bind(next, snapshot);
|
|
215
|
-
}
|
|
216
|
-
async #runIdleOperation(operation, description, run) {
|
|
217
|
-
this.#assertAvailable();
|
|
218
|
-
this.#requireHandle();
|
|
219
|
-
if (this.phase !== "idle") {
|
|
220
|
-
throw new Error(`Cannot ${description} while session is ${this.phase ?? "unavailable"}`);
|
|
221
|
-
}
|
|
222
|
-
await this.#runOperation(operation, run);
|
|
223
|
-
}
|
|
224
|
-
async #runOperation(operation, run, preempt = false) {
|
|
225
|
-
if (preempt)
|
|
226
|
-
this.#assertNotDisposed();
|
|
227
|
-
else
|
|
228
|
-
this.#assertAvailable();
|
|
229
|
-
const previous = this.#lifecycle;
|
|
230
|
-
const busy = { status: "busy", operation };
|
|
231
|
-
this.#lifecycle = busy;
|
|
232
|
-
this.#activeOperationStates.add(busy);
|
|
233
|
-
this.#notify();
|
|
234
|
-
const running = run();
|
|
235
|
-
try {
|
|
236
|
-
await Promise.race([
|
|
237
|
-
running,
|
|
238
|
-
this.#disposeSignal.then(() => {
|
|
239
|
-
throw new Error("Remote session is disposed");
|
|
240
|
-
}),
|
|
241
|
-
]);
|
|
242
|
-
}
|
|
243
|
-
finally {
|
|
244
|
-
this.#activeOperationStates.delete(busy);
|
|
245
|
-
if (!this.disposed && this.#lifecycle === busy) {
|
|
246
|
-
this.#lifecycle =
|
|
247
|
-
preempt && this.#activeOperationStates.has(previous)
|
|
248
|
-
? previous
|
|
249
|
-
: this.#handle
|
|
250
|
-
? { status: "ready" }
|
|
251
|
-
: { status: "unbound" };
|
|
252
|
-
this.#notify();
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
#bind(handle, knownSnapshot) {
|
|
257
|
-
const snapshot = knownSnapshot ?? handle.snapshot;
|
|
258
|
-
if (!snapshot)
|
|
259
|
-
throw new Error(`Session ${handle.id} did not provide a snapshot`);
|
|
260
|
-
this.#clearSubscriptions();
|
|
261
|
-
this.#handle = handle;
|
|
262
|
-
this.#transcript = createTranscriptState(snapshot);
|
|
263
|
-
this.#unsubscribeSnapshot = handle.subscribe((next) => {
|
|
264
|
-
if (!this.#transcript)
|
|
265
|
-
return;
|
|
266
|
-
this.#transcript = applyTranscriptSnapshot(this.#transcript, next);
|
|
267
|
-
this.#notify();
|
|
268
|
-
});
|
|
269
|
-
this.#unsubscribeEvents = handle.onEvent((event) => this.#handleEvent(event));
|
|
270
|
-
}
|
|
271
|
-
#handleEvent(event) {
|
|
272
|
-
if (event.type === "session_removed") {
|
|
273
|
-
this.#clearSubscriptions();
|
|
274
|
-
this.#handle = undefined;
|
|
275
|
-
this.#transcript = undefined;
|
|
276
|
-
if (this.#lifecycle.status !== "busy")
|
|
277
|
-
this.#lifecycle = { status: "unbound" };
|
|
278
|
-
this.#notify();
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
|
-
if (event.type !== "session_progress" || !this.#transcript)
|
|
282
|
-
return;
|
|
283
|
-
this.#transcript = applyTranscriptProgress(this.#transcript, event.progress);
|
|
284
|
-
this.#notify();
|
|
285
|
-
}
|
|
286
|
-
#notify() {
|
|
287
|
-
const state = this.state;
|
|
288
|
-
for (const listener of this.#listeners)
|
|
289
|
-
this.#callListener(listener, state);
|
|
290
|
-
}
|
|
291
|
-
#callListener(listener, state) {
|
|
292
|
-
try {
|
|
293
|
-
listener(state);
|
|
294
|
-
}
|
|
295
|
-
catch (error) {
|
|
296
|
-
this.#reportListenerError(error);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
#reportListenerError(error) {
|
|
300
|
-
if (!this.#onListenerError)
|
|
301
|
-
return;
|
|
302
|
-
try {
|
|
303
|
-
this.#onListenerError(error instanceof Error ? error : new Error(String(error)));
|
|
304
|
-
}
|
|
305
|
-
catch {
|
|
306
|
-
// Diagnostics cannot affect session or transport state.
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
#clearSubscriptions() {
|
|
310
|
-
this.#unsubscribeSnapshot?.();
|
|
311
|
-
this.#unsubscribeEvents?.();
|
|
312
|
-
this.#unsubscribeSnapshot = undefined;
|
|
313
|
-
this.#unsubscribeEvents = undefined;
|
|
314
|
-
}
|
|
315
|
-
#requireHandle() {
|
|
316
|
-
if (!this.#handle)
|
|
317
|
-
throw new Error("No remote session is attached");
|
|
318
|
-
return this.#handle;
|
|
319
|
-
}
|
|
320
|
-
#assertAvailable() {
|
|
321
|
-
this.#assertNotDisposed();
|
|
322
|
-
if (this.#lifecycle.status === "busy") {
|
|
323
|
-
throw new Error(`Remote session is busy with ${this.#lifecycle.operation}`);
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
#assertNotDisposed() {
|
|
327
|
-
if (this.disposed)
|
|
328
|
-
throw new Error("Remote session is disposed");
|
|
329
|
-
}
|
|
330
|
-
async #assertNotDisposedAfterAwait(handle) {
|
|
331
|
-
if (!this.disposed)
|
|
332
|
-
return;
|
|
333
|
-
await this.#detach(handle);
|
|
334
|
-
throw new RemoteSessionDisposedError();
|
|
335
|
-
}
|
|
336
|
-
async #detach(handle) {
|
|
337
|
-
await handle.dispose();
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
//# sourceMappingURL=remote-session.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"remote-session.js","sourceRoot":"","sources":["../../src/client/remote-session.ts"],"names":[],"mappings":"AAiBA,OAAO,EACN,uBAAuB,EACvB,uBAAuB,EACvB,qBAAqB,EACrB,gBAAgB,GAEhB,MAAM,iBAAiB,CA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C9B,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;QACpE,OAAO,IAAI,CAAC,OAAO,CAAC;IAAA,CACpB;IAED,gBAAgB,GAAS;QACxB,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAC1B,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;YACvC,MAAM,IAAI,KAAK,CAAC,+BAA+B,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC,CAAC;QAC7E,CAAC;IAAA,CACD;IAED,kBAAkB,GAAS;QAC1B,IAAI,IAAI,CAAC,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IAAA,CACjE;IAED,KAAK,CAAC,4BAA4B,CAAC,MAAoB,EAAiB;QACvE,IAAI,CAAC,IAAI,CAAC,QAAQ;YAAE,OAAO;QAC3B,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC3B,MAAM,IAAI,0BAA0B,EAAE,CAAC;IAAA,CACvC;IAED,KAAK,CAAC,OAAO,CAAC,MAAoB,EAAiB;QAClD,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;IAAA,CACvB;CACD","sourcesContent":["import type {\n\tConnectionState,\n\tConnectionStateChange,\n\tPiClient,\n\tSessionLease,\n\tUnsubscribe,\n} from \"@earendil-works/pi-client\";\nimport type {\n\tModelMetadata,\n\tModelRef,\n\tServerEvent,\n\tSessionMetadata,\n\tSessionPhase,\n\tSessionSnapshot,\n\tThinkingLevel,\n\tTranscriptItem,\n} from \"@earendil-works/pi-protocol\";\nimport {\n\tapplyTranscriptProgress,\n\tapplyTranscriptSnapshot,\n\tcreateTranscriptState,\n\tselectTranscript,\n\ttype TranscriptState,\n} from \"./transcript.ts\";\n\nexport type RemoteSessionOperation = \"open\" | \"create\" | \"submit\" | \"abort\" | \"setModel\" | \"setThinking\" | \"reconnect\";\n\nexport type RemoteSessionLifecycle =\n\t| { readonly status: \"unbound\" }\n\t| { readonly status: \"ready\" }\n\t| { readonly status: \"busy\"; readonly operation: RemoteSessionOperation }\n\t| { readonly status: \"disposed\" };\n\nexport interface RemoteSessionState {\n\treadonly lifecycle: RemoteSessionLifecycle;\n\treadonly snapshot?: SessionSnapshot;\n\treadonly transcript: readonly TranscriptItem[];\n}\n\nexport interface CreateRemoteSessionOptions {\n\tcwd: string;\n\tmodel?: ModelRef;\n\tthinkingLevel?: ThinkingLevel;\n}\n\nexport interface RemoteSessionOptions {\n\tonListenerError?: (error: Error) => void;\n}\n\nclass RemoteSessionDisposedError extends Error {\n\tconstructor() {\n\t\tsuper(\"Remote session is disposed\");\n\t\tthis.name = \"RemoteSessionDisposedError\";\n\t}\n}\n\nasync function settleRemoteSessionDisposal(cleanup: readonly Promise<void>[]): Promise<void> {\n\tconst results = await Promise.allSettled(cleanup);\n\tconst errors = results.flatMap((result) =>\n\t\tresult.status === \"rejected\" && !(result.reason instanceof RemoteSessionDisposedError) ? [result.reason] : [],\n\t);\n\tif (errors.length === 1) throw errors[0];\n\tif (errors.length > 1) throw new AggregateError(errors, \"Failed to dispose remote session\");\n}\n\nexport class RemoteSession {\n\treadonly #client: PiClient;\n\treadonly #onListenerError: ((error: Error) => void) | undefined;\n\t#lifecycle: RemoteSessionLifecycle = { status: \"unbound\" };\n\t#handle: SessionLease | undefined;\n\t#transcript: TranscriptState | undefined;\n\t#unsubscribeSnapshot: Unsubscribe | undefined;\n\t#unsubscribeEvents: Unsubscribe | undefined;\n\treadonly #listeners = new Set<(state: RemoteSessionState) => void>();\n\treadonly #pendingAttachmentOperations = new Set<Promise<void>>();\n\treadonly #activeOperationStates = new Set<RemoteSessionLifecycle>();\n\t#disposePromise: Promise<void> | undefined;\n\t#resolveDisposeSignal: () => void = () => {};\n\treadonly #disposeSignal = new Promise<void>((resolve) => {\n\t\tthis.#resolveDisposeSignal = resolve;\n\t});\n\n\tprivate constructor(client: PiClient, options: RemoteSessionOptions = {}) {\n\t\tthis.#client = client;\n\t\tthis.#onListenerError = options.onListenerError;\n\t}\n\n\tget id(): string | undefined {\n\t\treturn this.#handle?.id;\n\t}\n\n\tget state(): RemoteSessionState {\n\t\treturn {\n\t\t\tlifecycle: this.#lifecycle,\n\t\t\tsnapshot: this.#transcript?.snapshot,\n\t\t\ttranscript: this.#transcript ? selectTranscript(this.#transcript) : [],\n\t\t};\n\t}\n\n\tget snapshot(): SessionSnapshot | undefined {\n\t\treturn this.#transcript?.snapshot;\n\t}\n\n\tget phase(): SessionPhase | undefined {\n\t\treturn this.snapshot?.phase;\n\t}\n\n\tget operation(): RemoteSessionOperation | undefined {\n\t\treturn this.#lifecycle.status === \"busy\" ? this.#lifecycle.operation : undefined;\n\t}\n\n\tget models(): readonly ModelMetadata[] {\n\t\treturn this.#client.snapshot?.models ?? [];\n\t}\n\n\tget sessions(): readonly SessionMetadata[] {\n\t\treturn this.#client.snapshot?.sessions ?? [];\n\t}\n\n\tget connectionState(): ConnectionState {\n\t\treturn this.#client.connectionState;\n\t}\n\n\tget disposed(): boolean {\n\t\treturn this.#lifecycle.status === \"disposed\";\n\t}\n\n\tsubscribe(listener: (state: RemoteSessionState) => void): Unsubscribe {\n\t\tthis.#assertNotDisposed();\n\t\tthis.#listeners.add(listener);\n\t\tthis.#callListener(listener, this.state);\n\t\treturn () => this.#listeners.delete(listener);\n\t}\n\n\tonConnectionStateChange(listener: (change: ConnectionStateChange) => void): Unsubscribe {\n\t\tthis.#assertNotDisposed();\n\t\treturn this.#client.onConnectionStateChange(listener);\n\t}\n\n\tstatic async open(client: PiClient, sessionId: string, options: RemoteSessionOptions = {}): Promise<RemoteSession> {\n\t\tconst session = new RemoteSession(client, options);\n\t\ttry {\n\t\t\tawait session.open(sessionId);\n\t\t\treturn session;\n\t\t} catch (error) {\n\t\t\tawait session.dispose();\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tasync open(sessionId: string): Promise<void> {\n\t\tif (this.#handle?.id === sessionId && this.#lifecycle.status === \"ready\") return;\n\t\tawait this.#replace(\"open\", () => this.#client.acquireSession(sessionId, { mode: \"exclusive\" }));\n\t}\n\n\tstatic async create(\n\t\tclient: PiClient,\n\t\tcreateOptions: CreateRemoteSessionOptions,\n\t\toptions: RemoteSessionOptions = {},\n\t): Promise<RemoteSession> {\n\t\tconst session = new RemoteSession(client, options);\n\t\ttry {\n\t\t\tawait session.create(createOptions);\n\t\t\treturn session;\n\t\t} catch (error) {\n\t\t\tawait session.dispose();\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tasync create(options: CreateRemoteSessionOptions): Promise<void> {\n\t\tawait this.#replace(\"create\", () => this.#client.createSession(options));\n\t}\n\n\tasync submit(text: string): Promise<void> {\n\t\tconst normalized = text.trim();\n\t\tif (!normalized) return;\n\t\tthis.#assertAvailable();\n\t\tconst handle = this.#requireHandle();\n\t\tif (this.phase !== \"idle\" && this.phase !== \"turn\") {\n\t\t\tthrow new Error(`Session cannot accept input during ${this.phase ?? \"unknown\"} phase`);\n\t\t}\n\t\tawait this.#runOperation(\"submit\", () =>\n\t\t\t(this.phase === \"idle\" ? handle.prompt(normalized) : handle.steer(normalized)).then(() => undefined),\n\t\t);\n\t}\n\n\tasync abort(): Promise<void> {\n\t\tconst preemptingSubmit = this.#lifecycle.status === \"busy\" && this.#lifecycle.operation === \"submit\";\n\t\tif (preemptingSubmit) this.#assertNotDisposed();\n\t\telse this.#assertAvailable();\n\t\tconst handle = this.#requireHandle();\n\t\tif (this.phase === \"idle\" && !preemptingSubmit) return;\n\t\tawait this.#runOperation(\"abort\", () => handle.abort().then(() => undefined), preemptingSubmit);\n\t}\n\n\tasync setModel(model: ModelRef): Promise<void> {\n\t\tawait this.#runIdleOperation(\"setModel\", \"change model\", () =>\n\t\t\tthis.#requireHandle()\n\t\t\t\t.setModel(model)\n\t\t\t\t.then(() => undefined),\n\t\t);\n\t}\n\n\tasync setThinking(thinkingLevel: ThinkingLevel): Promise<void> {\n\t\tawait this.#runIdleOperation(\"setThinking\", \"change thinking level\", () =>\n\t\t\tthis.#requireHandle()\n\t\t\t\t.setThinking(thinkingLevel)\n\t\t\t\t.then(() => undefined),\n\t\t);\n\t}\n\n\tasync reconnect(): Promise<void> {\n\t\tthis.#assertAvailable();\n\t\tconst sessionId = this.#requireHandle().id;\n\t\tawait this.#runOperation(\"reconnect\", () =>\n\t\t\tthis.#trackAttachmentOperation(async () => {\n\t\t\t\tawait this.#client.reconnect();\n\t\t\t\tconst handle = await this.#client.acquireSession(sessionId, { mode: \"exclusive\" });\n\t\t\t\tawait this.#assertNotDisposedAfterAwait(handle);\n\t\t\t\tthis.#bind(handle);\n\t\t\t}),\n\t\t);\n\t}\n\n\tdispose(): Promise<void> {\n\t\tif (this.#disposePromise) return this.#disposePromise;\n\t\tconst handle = this.#handle;\n\t\tthis.#lifecycle = { status: \"disposed\" };\n\t\tthis.#resolveDisposeSignal();\n\t\tthis.#clearSubscriptions();\n\t\tthis.#handle = undefined;\n\t\tthis.#transcript = undefined;\n\t\tconst cleanup = [...this.#pendingAttachmentOperations];\n\t\tif (handle) cleanup.push(handle.dispose());\n\t\tthis.#disposePromise = settleRemoteSessionDisposal(cleanup);\n\t\tthis.#notify();\n\t\tthis.#listeners.clear();\n\t\treturn this.#disposePromise;\n\t}\n\n\t[Symbol.asyncDispose](): Promise<void> {\n\t\treturn this.dispose();\n\t}\n\n\tasync #replace(operation: \"open\" | \"create\", prepare: () => Promise<SessionLease>): Promise<void> {\n\t\tthis.#assertAvailable();\n\t\tif (this.#handle && this.phase !== \"idle\") {\n\t\t\tthrow new Error(`Cannot ${operation} a session while session is ${this.phase ?? \"unavailable\"}`);\n\t\t}\n\t\tawait this.#runOperation(operation, () =>\n\t\t\tthis.#trackAttachmentOperation(() => this.#prepareReplacement(operation, prepare)),\n\t\t);\n\t}\n\n\tasync #trackAttachmentOperation(run: () => Promise<void>): Promise<void> {\n\t\tconst pending = run();\n\t\tthis.#pendingAttachmentOperations.add(pending);\n\t\ttry {\n\t\t\tawait pending;\n\t\t} finally {\n\t\t\tthis.#pendingAttachmentOperations.delete(pending);\n\t\t}\n\t}\n\n\tasync #prepareReplacement(operation: \"open\" | \"create\", prepare: () => Promise<SessionLease>): Promise<void> {\n\t\tconst previous = this.#handle;\n\t\tconst next = await prepare();\n\t\tawait this.#assertNotDisposedAfterAwait(next);\n\t\tconst snapshot = next.snapshot;\n\t\tif (!snapshot) {\n\t\t\tawait this.#detach(next);\n\t\t\tthrow new Error(`Session ${next.id} did not provide a snapshot`);\n\t\t}\n\t\tif (previous && previous.id !== next.id && previous.attached && this.phase !== \"idle\") {\n\t\t\tawait this.#detach(next);\n\t\t\tthrow new Error(`Cannot ${operation} a session while session is ${this.phase ?? \"unavailable\"}`);\n\t\t}\n\t\tif (previous && previous.id !== next.id && previous.attached) {\n\t\t\ttry {\n\t\t\t\tawait previous.detach();\n\t\t\t} catch (error) {\n\t\t\t\ttry {\n\t\t\t\t\tawait this.#detach(next);\n\t\t\t\t} catch (cleanupError) {\n\t\t\t\t\tthrow new AggregateError([error, cleanupError], \"Failed to replace remote session attachment\");\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t\tawait this.#assertNotDisposedAfterAwait(next);\n\t\tthis.#bind(next, snapshot);\n\t}\n\n\tasync #runIdleOperation(\n\t\toperation: \"setModel\" | \"setThinking\",\n\t\tdescription: string,\n\t\trun: () => Promise<void>,\n\t): Promise<void> {\n\t\tthis.#assertAvailable();\n\t\tthis.#requireHandle();\n\t\tif (this.phase !== \"idle\") {\n\t\t\tthrow new Error(`Cannot ${description} while session is ${this.phase ?? \"unavailable\"}`);\n\t\t}\n\t\tawait this.#runOperation(operation, run);\n\t}\n\n\tasync #runOperation(operation: RemoteSessionOperation, run: () => Promise<void>, preempt = false): Promise<void> {\n\t\tif (preempt) this.#assertNotDisposed();\n\t\telse this.#assertAvailable();\n\t\tconst previous = this.#lifecycle;\n\t\tconst busy: RemoteSessionLifecycle = { status: \"busy\", operation };\n\t\tthis.#lifecycle = busy;\n\t\tthis.#activeOperationStates.add(busy);\n\t\tthis.#notify();\n\t\tconst running = run();\n\t\ttry {\n\t\t\tawait Promise.race([\n\t\t\t\trunning,\n\t\t\t\tthis.#disposeSignal.then(() => {\n\t\t\t\t\tthrow new Error(\"Remote session is disposed\");\n\t\t\t\t}),\n\t\t\t]);\n\t\t} finally {\n\t\t\tthis.#activeOperationStates.delete(busy);\n\t\t\tif (!this.disposed && this.#lifecycle === busy) {\n\t\t\t\tthis.#lifecycle =\n\t\t\t\t\tpreempt && this.#activeOperationStates.has(previous)\n\t\t\t\t\t\t? previous\n\t\t\t\t\t\t: this.#handle\n\t\t\t\t\t\t\t? { status: \"ready\" }\n\t\t\t\t\t\t\t: { status: \"unbound\" };\n\t\t\t\tthis.#notify();\n\t\t\t}\n\t\t}\n\t}\n\n\t#bind(handle: SessionLease, knownSnapshot?: SessionSnapshot): void {\n\t\tconst snapshot = knownSnapshot ?? handle.snapshot;\n\t\tif (!snapshot) throw new Error(`Session ${handle.id} did not provide a snapshot`);\n\t\tthis.#clearSubscriptions();\n\t\tthis.#handle = handle;\n\t\tthis.#transcript = createTranscriptState(snapshot);\n\t\tthis.#unsubscribeSnapshot = handle.subscribe((next) => {\n\t\t\tif (!this.#transcript) return;\n\t\t\tthis.#transcript = applyTranscriptSnapshot(this.#transcript, next);\n\t\t\tthis.#notify();\n\t\t});\n\t\tthis.#unsubscribeEvents = handle.onEvent((event) => this.#handleEvent(event));\n\t}\n\n\t#handleEvent(event: ServerEvent): void {\n\t\tif (event.type === \"session_removed\") {\n\t\t\tthis.#clearSubscriptions();\n\t\t\tthis.#handle = undefined;\n\t\t\tthis.#transcript = undefined;\n\t\t\tif (this.#lifecycle.status !== \"busy\") this.#lifecycle = { status: \"unbound\" };\n\t\t\tthis.#notify();\n\t\t\treturn;\n\t\t}\n\t\tif (event.type !== \"session_progress\" || !this.#transcript) return;\n\t\tthis.#transcript = applyTranscriptProgress(this.#transcript, event.progress);\n\t\tthis.#notify();\n\t}\n\n\t#notify(): void {\n\t\tconst state = this.state;\n\t\tfor (const listener of this.#listeners) this.#callListener(listener, state);\n\t}\n\n\t#callListener(listener: (state: RemoteSessionState) => void, state: RemoteSessionState): void {\n\t\ttry {\n\t\t\tlistener(state);\n\t\t} catch (error) {\n\t\t\tthis.#reportListenerError(error);\n\t\t}\n\t}\n\n\t#reportListenerError(error: unknown): void {\n\t\tif (!this.#onListenerError) return;\n\t\ttry {\n\t\t\tthis.#onListenerError(error instanceof Error ? error : new Error(String(error)));\n\t\t} catch {\n\t\t\t// Diagnostics cannot affect session or transport state.\n\t\t}\n\t}\n\n\t#clearSubscriptions(): void {\n\t\tthis.#unsubscribeSnapshot?.();\n\t\tthis.#unsubscribeEvents?.();\n\t\tthis.#unsubscribeSnapshot = undefined;\n\t\tthis.#unsubscribeEvents = undefined;\n\t}\n\n\t#requireHandle(): SessionLease {\n\t\tif (!this.#handle) throw new Error(\"No remote session is attached\");\n\t\treturn this.#handle;\n\t}\n\n\t#assertAvailable(): void {\n\t\tthis.#assertNotDisposed();\n\t\tif (this.#lifecycle.status === \"busy\") {\n\t\t\tthrow new Error(`Remote session is busy with ${this.#lifecycle.operation}`);\n\t\t}\n\t}\n\n\t#assertNotDisposed(): void {\n\t\tif (this.disposed) throw new Error(\"Remote session is disposed\");\n\t}\n\n\tasync #assertNotDisposedAfterAwait(handle: SessionLease): Promise<void> {\n\t\tif (!this.disposed) return;\n\t\tawait this.#detach(handle);\n\t\tthrow new RemoteSessionDisposedError();\n\t}\n\n\tasync #detach(handle: SessionLease): Promise<void> {\n\t\tawait handle.dispose();\n\t}\n}\n"]}
|