@aibyzero/byz 0.0.0 → 0.1.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 +15 -0
- package/LICENSE +21 -0
- package/README.md +148 -5
- package/dist/cli.js +55 -0
- package/dist/runtime/bun/cli.d.ts +3 -0
- package/dist/runtime/bun/cli.d.ts.map +1 -0
- package/dist/runtime/bun/cli.js +11 -0
- package/dist/runtime/bun/cli.js.map +1 -0
- package/dist/runtime/bun/register-bedrock.d.ts +2 -0
- package/dist/runtime/bun/register-bedrock.d.ts.map +1 -0
- package/dist/runtime/bun/register-bedrock.js +4 -0
- package/dist/runtime/bun/register-bedrock.js.map +1 -0
- package/dist/runtime/bun/restore-sandbox-env.d.ts +17 -0
- package/dist/runtime/bun/restore-sandbox-env.d.ts.map +1 -0
- package/dist/runtime/bun/restore-sandbox-env.js +36 -0
- package/dist/runtime/bun/restore-sandbox-env.js.map +1 -0
- package/dist/runtime/bundle/chunks/anthropic-messages-JWX2WP65.js +45 -0
- package/dist/runtime/bundle/chunks/anthropic.js +75 -0
- package/dist/runtime/bundle/chunks/azure-openai-responses-5ENVCQ7U.js +2 -0
- package/dist/runtime/bundle/chunks/bedrock-converse-stream.js +74 -0
- package/dist/runtime/bundle/chunks/chunk-4L3WN2XY.js +2 -0
- package/dist/runtime/bundle/chunks/chunk-6CYCI3EJ.js +12 -0
- package/dist/runtime/bundle/chunks/chunk-6R7UI4IY.js +2 -0
- package/dist/runtime/bundle/chunks/chunk-AXIIZGTV.js +2 -0
- package/dist/runtime/bundle/chunks/chunk-CCRJHU72.js +1547 -0
- package/dist/runtime/bundle/chunks/chunk-DRQDKNXA.js +2 -0
- package/dist/runtime/bundle/chunks/chunk-GMWCTUPB.js +2 -0
- package/dist/runtime/bundle/chunks/chunk-GPPBJGBU.js +50 -0
- package/dist/runtime/bundle/chunks/chunk-JUUC5AZY.js +2 -0
- package/dist/runtime/bundle/chunks/chunk-L2ZPNLYD.js +2 -0
- package/dist/runtime/bundle/chunks/chunk-MNAIPA3J.js +2 -0
- package/dist/runtime/bundle/chunks/chunk-NBBFIJUL.js +11 -0
- package/dist/runtime/bundle/chunks/chunk-NUHFSC37.js +25 -0
- package/dist/runtime/bundle/chunks/chunk-PGXDEOVV.js +2 -0
- package/dist/runtime/bundle/chunks/chunk-PJACZCIR.js +2 -0
- package/dist/runtime/bundle/chunks/chunk-PRRNXB7S.js +2 -0
- package/dist/runtime/bundle/chunks/chunk-TEPMHNKQ.js +2 -0
- package/dist/runtime/bundle/chunks/chunk-TRDNDS6A.js +4 -0
- package/dist/runtime/bundle/chunks/chunk-UAQELI3K.js +2 -0
- package/dist/runtime/bundle/chunks/chunk-XDUWOHPL.js +6 -0
- package/dist/runtime/bundle/chunks/chunk-XNGRGP62.js +2 -0
- package/dist/runtime/bundle/chunks/dist-RDWOYWHR.js +13 -0
- package/dist/runtime/bundle/chunks/github-copilot.js +2 -0
- package/dist/runtime/bundle/chunks/google-generative-ai-XDKMGBCJ.js +2 -0
- package/dist/runtime/bundle/chunks/google-vertex-D5FGEO3Y.js +2 -0
- package/dist/runtime/bundle/chunks/image-resize-worker.js +2 -0
- package/dist/runtime/bundle/chunks/kimi-coding.js +2 -0
- package/dist/runtime/bundle/chunks/lib-HGQMNYVT.js +9 -0
- package/dist/runtime/bundle/chunks/mistral-conversations-YK73UAOZ.js +5 -0
- package/dist/runtime/bundle/chunks/multipart-parser-SQ6GDJL7.js +3 -0
- package/dist/runtime/bundle/chunks/openai-codex-responses-GJVBJXLB.js +8 -0
- package/dist/runtime/bundle/chunks/openai-codex.js +75 -0
- package/dist/runtime/bundle/chunks/openai-completions-XGHMB3UO.js +7 -0
- package/dist/runtime/bundle/chunks/openai-responses-BSOJMSEV.js +2 -0
- package/dist/runtime/bundle/chunks/openrouter-images-N4XVVFSD.js +2 -0
- package/dist/runtime/bundle/chunks/openrouter.js +75 -0
- package/dist/runtime/bundle/chunks/pi-messages-TPFH44NP.js +8 -0
- package/dist/runtime/bundle/chunks/radius.js +75 -0
- package/dist/runtime/bundle/chunks/src-UK77SYZE.js +4 -0
- package/dist/runtime/bundle/chunks/xai.js +2 -0
- package/dist/runtime/bundle/cli.js +3 -0
- package/dist/runtime/bundle/client.js +2 -0
- package/dist/runtime/bundle/index.js +2 -0
- package/dist/runtime/bundle/rpc-entry.js +3 -0
- package/dist/runtime/cli/args.d.ts +61 -0
- package/dist/runtime/cli/args.d.ts.map +1 -0
- package/dist/runtime/cli/args.js +439 -0
- package/dist/runtime/cli/args.js.map +1 -0
- package/dist/runtime/cli/auth-check.d.ts +19 -0
- package/dist/runtime/cli/auth-check.d.ts.map +1 -0
- package/dist/runtime/cli/auth-check.js +50 -0
- package/dist/runtime/cli/auth-check.js.map +1 -0
- package/dist/runtime/cli/auth-command.d.ts +24 -0
- package/dist/runtime/cli/auth-command.d.ts.map +1 -0
- package/dist/runtime/cli/auth-command.js +103 -0
- package/dist/runtime/cli/auth-command.js.map +1 -0
- package/dist/runtime/cli/config-selector.d.ts +16 -0
- package/dist/runtime/cli/config-selector.d.ts.map +1 -0
- package/dist/runtime/cli/config-selector.js +31 -0
- package/dist/runtime/cli/config-selector.js.map +1 -0
- package/dist/runtime/cli/credential-print.d.ts +13 -0
- package/dist/runtime/cli/credential-print.d.ts.map +1 -0
- package/dist/runtime/cli/credential-print.js +76 -0
- package/dist/runtime/cli/credential-print.js.map +1 -0
- package/dist/runtime/cli/experimental/auth.d.ts +16 -0
- package/dist/runtime/cli/experimental/auth.d.ts.map +1 -0
- package/dist/runtime/cli/experimental/auth.js +13 -0
- package/dist/runtime/cli/experimental/auth.js.map +1 -0
- package/dist/runtime/cli/experimental/cli.d.ts +6 -0
- package/dist/runtime/cli/experimental/cli.d.ts.map +1 -0
- package/dist/runtime/cli/experimental/cli.js +5 -0
- package/dist/runtime/cli/experimental/cli.js.map +1 -0
- package/dist/runtime/cli/experimental/command-options.d.ts +17 -0
- package/dist/runtime/cli/experimental/command-options.d.ts.map +1 -0
- package/dist/runtime/cli/experimental/command-options.js +35 -0
- package/dist/runtime/cli/experimental/command-options.js.map +1 -0
- package/dist/runtime/cli/experimental/command.d.ts +63 -0
- package/dist/runtime/cli/experimental/command.d.ts.map +1 -0
- package/dist/runtime/cli/experimental/command.js +130 -0
- package/dist/runtime/cli/experimental/command.js.map +1 -0
- package/dist/runtime/cli/experimental/commands/client.d.ts +13 -0
- package/dist/runtime/cli/experimental/commands/client.d.ts.map +1 -0
- package/dist/runtime/cli/experimental/commands/client.js +25 -0
- package/dist/runtime/cli/experimental/commands/client.js.map +1 -0
- package/dist/runtime/cli/experimental/commands/pi.d.ts +15 -0
- package/dist/runtime/cli/experimental/commands/pi.d.ts.map +1 -0
- package/dist/runtime/cli/experimental/commands/pi.js +28 -0
- package/dist/runtime/cli/experimental/commands/pi.js.map +1 -0
- package/dist/runtime/cli/experimental/commands/server.d.ts +13 -0
- package/dist/runtime/cli/experimental/commands/server.d.ts.map +1 -0
- package/dist/runtime/cli/experimental/commands/server.js +25 -0
- package/dist/runtime/cli/experimental/commands/server.js.map +1 -0
- package/dist/runtime/cli/experimental/transport-address.d.ts +10 -0
- package/dist/runtime/cli/experimental/transport-address.d.ts.map +1 -0
- package/dist/runtime/cli/experimental/transport-address.js +38 -0
- package/dist/runtime/cli/experimental/transport-address.js.map +1 -0
- package/dist/runtime/cli/file-processor.d.ts +15 -0
- package/dist/runtime/cli/file-processor.d.ts.map +1 -0
- package/dist/runtime/cli/file-processor.js +71 -0
- package/dist/runtime/cli/file-processor.js.map +1 -0
- package/dist/runtime/cli/initial-message.d.ts +18 -0
- package/dist/runtime/cli/initial-message.d.ts.map +1 -0
- package/dist/runtime/cli/initial-message.js +22 -0
- package/dist/runtime/cli/initial-message.js.map +1 -0
- package/dist/runtime/cli/list-models.d.ts +9 -0
- package/dist/runtime/cli/list-models.d.ts.map +1 -0
- package/dist/runtime/cli/list-models.js +98 -0
- package/dist/runtime/cli/list-models.js.map +1 -0
- package/dist/runtime/cli/project-trust.d.ts +10 -0
- package/dist/runtime/cli/project-trust.d.ts.map +1 -0
- package/dist/runtime/cli/project-trust.js +48 -0
- package/dist/runtime/cli/project-trust.js.map +1 -0
- package/dist/runtime/cli/session-picker.d.ts +10 -0
- package/dist/runtime/cli/session-picker.d.ts.map +1 -0
- package/dist/runtime/cli/session-picker.js +36 -0
- package/dist/runtime/cli/session-picker.js.map +1 -0
- package/dist/runtime/cli/startup-ui.d.ts +20 -0
- package/dist/runtime/cli/startup-ui.d.ts.map +1 -0
- package/dist/runtime/cli/startup-ui.js +184 -0
- package/dist/runtime/cli/startup-ui.js.map +1 -0
- package/dist/runtime/cli.d.ts +3 -0
- package/dist/runtime/cli.d.ts.map +1 -0
- package/dist/runtime/cli.js +19 -0
- package/dist/runtime/cli.js.map +1 -0
- package/dist/runtime/client/index.d.ts +3 -0
- package/dist/runtime/client/index.d.ts.map +1 -0
- package/dist/runtime/client/index.js +3 -0
- package/dist/runtime/client/index.js.map +1 -0
- package/dist/runtime/client/remote-session.d.ts +53 -0
- package/dist/runtime/client/remote-session.d.ts.map +1 -0
- package/dist/runtime/client/remote-session.js +340 -0
- package/dist/runtime/client/remote-session.js.map +1 -0
- package/dist/runtime/client/transcript.d.ts +12 -0
- package/dist/runtime/client/transcript.d.ts.map +1 -0
- package/dist/runtime/client/transcript.js +98 -0
- package/dist/runtime/client/transcript.js.map +1 -0
- package/dist/runtime/config.d.ts +98 -0
- package/dist/runtime/config.d.ts.map +1 -0
- package/dist/runtime/config.js +469 -0
- package/dist/runtime/config.js.map +1 -0
- package/dist/runtime/core/agent-session-runtime.d.ts +119 -0
- package/dist/runtime/core/agent-session-runtime.d.ts.map +1 -0
- package/dist/runtime/core/agent-session-runtime.js +309 -0
- package/dist/runtime/core/agent-session-runtime.js.map +1 -0
- package/dist/runtime/core/agent-session-services.d.ts +86 -0
- package/dist/runtime/core/agent-session-services.d.ts.map +1 -0
- package/dist/runtime/core/agent-session-services.js +134 -0
- package/dist/runtime/core/agent-session-services.js.map +1 -0
- package/dist/runtime/core/agent-session.d.ts +678 -0
- package/dist/runtime/core/agent-session.d.ts.map +1 -0
- package/dist/runtime/core/agent-session.js +2808 -0
- package/dist/runtime/core/agent-session.js.map +1 -0
- package/dist/runtime/core/auth-guidance.d.ts +5 -0
- package/dist/runtime/core/auth-guidance.d.ts.map +1 -0
- package/dist/runtime/core/auth-guidance.js +21 -0
- package/dist/runtime/core/auth-guidance.js.map +1 -0
- package/dist/runtime/core/auth-storage.d.ts +72 -0
- package/dist/runtime/core/auth-storage.d.ts.map +1 -0
- package/dist/runtime/core/auth-storage.js +426 -0
- package/dist/runtime/core/auth-storage.js.map +1 -0
- package/dist/runtime/core/bash-executor.d.ts +32 -0
- package/dist/runtime/core/bash-executor.d.ts.map +1 -0
- package/dist/runtime/core/bash-executor.js +111 -0
- package/dist/runtime/core/bash-executor.js.map +1 -0
- package/dist/runtime/core/cache-stats.d.ts +49 -0
- package/dist/runtime/core/cache-stats.d.ts.map +1 -0
- package/dist/runtime/core/cache-stats.js +101 -0
- package/dist/runtime/core/cache-stats.js.map +1 -0
- package/dist/runtime/core/compaction/branch-summarization.d.ts +98 -0
- package/dist/runtime/core/compaction/branch-summarization.d.ts.map +1 -0
- package/dist/runtime/core/compaction/branch-summarization.js +250 -0
- package/dist/runtime/core/compaction/branch-summarization.js.map +1 -0
- package/dist/runtime/core/compaction/compaction.d.ts +143 -0
- package/dist/runtime/core/compaction/compaction.d.ts.map +1 -0
- package/dist/runtime/core/compaction/compaction.js +669 -0
- package/dist/runtime/core/compaction/compaction.js.map +1 -0
- package/dist/runtime/core/compaction/index.d.ts +7 -0
- package/dist/runtime/core/compaction/index.d.ts.map +1 -0
- package/dist/runtime/core/compaction/index.js +7 -0
- package/dist/runtime/core/compaction/index.js.map +1 -0
- package/dist/runtime/core/compaction/utils.d.ts +38 -0
- package/dist/runtime/core/compaction/utils.d.ts.map +1 -0
- package/dist/runtime/core/compaction/utils.js +142 -0
- package/dist/runtime/core/compaction/utils.js.map +1 -0
- package/dist/runtime/core/defaults.d.ts +4 -0
- package/dist/runtime/core/defaults.d.ts.map +1 -0
- package/dist/runtime/core/defaults.js +11 -0
- package/dist/runtime/core/defaults.js.map +1 -0
- package/dist/runtime/core/diagnostics.d.ts +15 -0
- package/dist/runtime/core/diagnostics.d.ts.map +1 -0
- package/dist/runtime/core/diagnostics.js +2 -0
- package/dist/runtime/core/diagnostics.js.map +1 -0
- package/dist/runtime/core/event-bus.d.ts +9 -0
- package/dist/runtime/core/event-bus.d.ts.map +1 -0
- package/dist/runtime/core/event-bus.js +25 -0
- package/dist/runtime/core/event-bus.js.map +1 -0
- package/dist/runtime/core/exec.d.ts +29 -0
- package/dist/runtime/core/exec.d.ts.map +1 -0
- package/dist/runtime/core/exec.js +75 -0
- package/dist/runtime/core/exec.js.map +1 -0
- package/dist/runtime/core/experimental.d.ts +6 -0
- package/dist/runtime/core/experimental.d.ts.map +1 -0
- package/dist/runtime/core/experimental.js +8 -0
- package/dist/runtime/core/experimental.js.map +1 -0
- package/dist/runtime/core/export-html/ansi-to-html.d.ts +22 -0
- package/dist/runtime/core/export-html/ansi-to-html.d.ts.map +1 -0
- package/dist/runtime/core/export-html/ansi-to-html.js +249 -0
- package/dist/runtime/core/export-html/ansi-to-html.js.map +1 -0
- package/dist/runtime/core/export-html/index.d.ts +37 -0
- package/dist/runtime/core/export-html/index.d.ts.map +1 -0
- package/dist/runtime/core/export-html/index.js +226 -0
- package/dist/runtime/core/export-html/index.js.map +1 -0
- package/dist/runtime/core/export-html/template.css +1066 -0
- package/dist/runtime/core/export-html/template.html +55 -0
- package/dist/runtime/core/export-html/template.js +1864 -0
- package/dist/runtime/core/export-html/tool-renderer.d.ts +34 -0
- package/dist/runtime/core/export-html/tool-renderer.d.ts.map +1 -0
- package/dist/runtime/core/export-html/tool-renderer.js +108 -0
- package/dist/runtime/core/export-html/tool-renderer.js.map +1 -0
- package/dist/runtime/core/export-html/vendor/highlight.min.js +1213 -0
- package/dist/runtime/core/export-html/vendor/marked.min.js +78 -0
- package/dist/runtime/core/extensions/index.d.ts +12 -0
- package/dist/runtime/core/extensions/index.d.ts.map +1 -0
- package/dist/runtime/core/extensions/index.js +9 -0
- package/dist/runtime/core/extensions/index.js.map +1 -0
- package/dist/runtime/core/extensions/loader.d.ts +23 -0
- package/dist/runtime/core/extensions/loader.d.ts.map +1 -0
- package/dist/runtime/core/extensions/loader.js +648 -0
- package/dist/runtime/core/extensions/loader.js.map +1 -0
- package/dist/runtime/core/extensions/runner.d.ts +173 -0
- package/dist/runtime/core/extensions/runner.d.ts.map +1 -0
- package/dist/runtime/core/extensions/runner.js +967 -0
- package/dist/runtime/core/extensions/runner.js.map +1 -0
- package/dist/runtime/core/extensions/types.d.ts +1328 -0
- package/dist/runtime/core/extensions/types.d.ts.map +1 -0
- package/dist/runtime/core/extensions/types.js +48 -0
- package/dist/runtime/core/extensions/types.js.map +1 -0
- package/dist/runtime/core/extensions/wrapper.d.ts +20 -0
- package/dist/runtime/core/extensions/wrapper.d.ts.map +1 -0
- package/dist/runtime/core/extensions/wrapper.js +41 -0
- package/dist/runtime/core/extensions/wrapper.js.map +1 -0
- package/dist/runtime/core/footer-data-provider.d.ts +64 -0
- package/dist/runtime/core/footer-data-provider.d.ts.map +1 -0
- package/dist/runtime/core/footer-data-provider.js +338 -0
- package/dist/runtime/core/footer-data-provider.js.map +1 -0
- package/dist/runtime/core/http-dispatcher.d.ts +22 -0
- package/dist/runtime/core/http-dispatcher.d.ts.map +1 -0
- package/dist/runtime/core/http-dispatcher.js +96 -0
- package/dist/runtime/core/http-dispatcher.js.map +1 -0
- package/dist/runtime/core/index.d.ts +13 -0
- package/dist/runtime/core/index.d.ts.map +1 -0
- package/dist/runtime/core/index.js +13 -0
- package/dist/runtime/core/index.js.map +1 -0
- package/dist/runtime/core/keybindings.d.ts +423 -0
- package/dist/runtime/core/keybindings.d.ts.map +1 -0
- package/dist/runtime/core/keybindings.js +317 -0
- package/dist/runtime/core/keybindings.js.map +1 -0
- package/dist/runtime/core/messages.d.ts +77 -0
- package/dist/runtime/core/messages.d.ts.map +1 -0
- package/dist/runtime/core/messages.js +123 -0
- package/dist/runtime/core/messages.js.map +1 -0
- package/dist/runtime/core/model-config.d.ts +576 -0
- package/dist/runtime/core/model-config.d.ts.map +1 -0
- package/dist/runtime/core/model-config.js +256 -0
- package/dist/runtime/core/model-config.js.map +1 -0
- package/dist/runtime/core/model-registry.d.ts +45 -0
- package/dist/runtime/core/model-registry.d.ts.map +1 -0
- package/dist/runtime/core/model-registry.js +107 -0
- package/dist/runtime/core/model-registry.js.map +1 -0
- package/dist/runtime/core/model-resolver.d.ts +124 -0
- package/dist/runtime/core/model-resolver.d.ts.map +1 -0
- package/dist/runtime/core/model-resolver.js +589 -0
- package/dist/runtime/core/model-resolver.js.map +1 -0
- package/dist/runtime/core/model-runtime.d.ts +100 -0
- package/dist/runtime/core/model-runtime.d.ts.map +1 -0
- package/dist/runtime/core/model-runtime.js +599 -0
- package/dist/runtime/core/model-runtime.js.map +1 -0
- package/dist/runtime/core/models-store.d.ts +22 -0
- package/dist/runtime/core/models-store.d.ts.map +1 -0
- package/dist/runtime/core/models-store.js +115 -0
- package/dist/runtime/core/models-store.js.map +1 -0
- package/dist/runtime/core/output-guard.d.ts +7 -0
- package/dist/runtime/core/output-guard.d.ts.map +1 -0
- package/dist/runtime/core/output-guard.js +89 -0
- package/dist/runtime/core/output-guard.js.map +1 -0
- package/dist/runtime/core/package-manager.d.ts +213 -0
- package/dist/runtime/core/package-manager.d.ts.map +1 -0
- package/dist/runtime/core/package-manager.js +2177 -0
- package/dist/runtime/core/package-manager.js.map +1 -0
- package/dist/runtime/core/pi-manifest.d.ts +8 -0
- package/dist/runtime/core/pi-manifest.d.ts.map +1 -0
- package/dist/runtime/core/pi-manifest.js +26 -0
- package/dist/runtime/core/pi-manifest.js.map +1 -0
- package/dist/runtime/core/project-trust.d.ts +15 -0
- package/dist/runtime/core/project-trust.d.ts.map +1 -0
- package/dist/runtime/core/project-trust.js +59 -0
- package/dist/runtime/core/project-trust.js.map +1 -0
- package/dist/runtime/core/prompt-templates.d.ts +54 -0
- package/dist/runtime/core/prompt-templates.d.ts.map +1 -0
- package/dist/runtime/core/prompt-templates.js +236 -0
- package/dist/runtime/core/prompt-templates.js.map +1 -0
- package/dist/runtime/core/provider-attribution.d.ts +4 -0
- package/dist/runtime/core/provider-attribution.d.ts.map +1 -0
- package/dist/runtime/core/provider-attribution.js +72 -0
- package/dist/runtime/core/provider-attribution.js.map +1 -0
- package/dist/runtime/core/provider-composer.d.ts +58 -0
- package/dist/runtime/core/provider-composer.d.ts.map +1 -0
- package/dist/runtime/core/provider-composer.js +396 -0
- package/dist/runtime/core/provider-composer.js.map +1 -0
- package/dist/runtime/core/radius.d.ts +2 -0
- package/dist/runtime/core/radius.d.ts.map +1 -0
- package/dist/runtime/core/radius.js +2 -0
- package/dist/runtime/core/radius.js.map +1 -0
- package/dist/runtime/core/remote-catalog-provider.d.ts +5 -0
- package/dist/runtime/core/remote-catalog-provider.d.ts.map +1 -0
- package/dist/runtime/core/remote-catalog-provider.js +122 -0
- package/dist/runtime/core/remote-catalog-provider.js.map +1 -0
- package/dist/runtime/core/resolve-config-value.d.ts +30 -0
- package/dist/runtime/core/resolve-config-value.d.ts.map +1 -0
- package/dist/runtime/core/resolve-config-value.js +247 -0
- package/dist/runtime/core/resolve-config-value.js.map +1 -0
- package/dist/runtime/core/resource-loader.d.ts +221 -0
- package/dist/runtime/core/resource-loader.d.ts.map +1 -0
- package/dist/runtime/core/resource-loader.js +875 -0
- package/dist/runtime/core/resource-loader.js.map +1 -0
- package/dist/runtime/core/runtime-credentials.d.ts +15 -0
- package/dist/runtime/core/runtime-credentials.d.ts.map +1 -0
- package/dist/runtime/core/runtime-credentials.js +39 -0
- package/dist/runtime/core/runtime-credentials.js.map +1 -0
- package/dist/runtime/core/sdk.d.ts +108 -0
- package/dist/runtime/core/sdk.d.ts.map +1 -0
- package/dist/runtime/core/sdk.js +275 -0
- package/dist/runtime/core/sdk.js.map +1 -0
- package/dist/runtime/core/session-cwd.d.ts +19 -0
- package/dist/runtime/core/session-cwd.d.ts.map +1 -0
- package/dist/runtime/core/session-cwd.js +38 -0
- package/dist/runtime/core/session-cwd.js.map +1 -0
- package/dist/runtime/core/session-export.d.ts +4 -0
- package/dist/runtime/core/session-export.d.ts.map +1 -0
- package/dist/runtime/core/session-export.js +32 -0
- package/dist/runtime/core/session-export.js.map +1 -0
- package/dist/runtime/core/session-manager.d.ts +356 -0
- package/dist/runtime/core/session-manager.d.ts.map +1 -0
- package/dist/runtime/core/session-manager.js +1341 -0
- package/dist/runtime/core/session-manager.js.map +1 -0
- package/dist/runtime/core/settings-diagnostics.d.ts +9 -0
- package/dist/runtime/core/settings-diagnostics.d.ts.map +1 -0
- package/dist/runtime/core/settings-diagnostics.js +21 -0
- package/dist/runtime/core/settings-diagnostics.js.map +1 -0
- package/dist/runtime/core/settings-manager.d.ts +324 -0
- package/dist/runtime/core/settings-manager.d.ts.map +1 -0
- package/dist/runtime/core/settings-manager.js +980 -0
- package/dist/runtime/core/settings-manager.js.map +1 -0
- package/dist/runtime/core/skills.d.ts +60 -0
- package/dist/runtime/core/skills.d.ts.map +1 -0
- package/dist/runtime/core/skills.js +405 -0
- package/dist/runtime/core/skills.js.map +1 -0
- package/dist/runtime/core/slash-commands.d.ts +15 -0
- package/dist/runtime/core/slash-commands.d.ts.map +1 -0
- package/dist/runtime/core/slash-commands.js +27 -0
- package/dist/runtime/core/slash-commands.js.map +1 -0
- package/dist/runtime/core/source-info.d.ts +18 -0
- package/dist/runtime/core/source-info.d.ts.map +1 -0
- package/dist/runtime/core/source-info.js +19 -0
- package/dist/runtime/core/source-info.js.map +1 -0
- package/dist/runtime/core/system-prompt.d.ts +28 -0
- package/dist/runtime/core/system-prompt.d.ts.map +1 -0
- package/dist/runtime/core/system-prompt.js +119 -0
- package/dist/runtime/core/system-prompt.js.map +1 -0
- package/dist/runtime/core/telemetry.d.ts +3 -0
- package/dist/runtime/core/telemetry.d.ts.map +1 -0
- package/dist/runtime/core/telemetry.js +9 -0
- package/dist/runtime/core/telemetry.js.map +1 -0
- package/dist/runtime/core/timings.d.ts +10 -0
- package/dist/runtime/core/timings.d.ts.map +1 -0
- package/dist/runtime/core/timings.js +41 -0
- package/dist/runtime/core/timings.js.map +1 -0
- package/dist/runtime/core/tools/bash.d.ts +87 -0
- package/dist/runtime/core/tools/bash.d.ts.map +1 -0
- package/dist/runtime/core/tools/bash.js +410 -0
- package/dist/runtime/core/tools/bash.js.map +1 -0
- package/dist/runtime/core/tools/edit-diff.d.ts +101 -0
- package/dist/runtime/core/tools/edit-diff.d.ts.map +1 -0
- package/dist/runtime/core/tools/edit-diff.js +421 -0
- package/dist/runtime/core/tools/edit-diff.js.map +1 -0
- package/dist/runtime/core/tools/edit.d.ts +55 -0
- package/dist/runtime/core/tools/edit.d.ts.map +1 -0
- package/dist/runtime/core/tools/edit.js +306 -0
- package/dist/runtime/core/tools/edit.js.map +1 -0
- package/dist/runtime/core/tools/file-mutation-queue.d.ts +6 -0
- package/dist/runtime/core/tools/file-mutation-queue.d.ts.map +1 -0
- package/dist/runtime/core/tools/file-mutation-queue.js +52 -0
- package/dist/runtime/core/tools/file-mutation-queue.js.map +1 -0
- package/dist/runtime/core/tools/find.d.ts +42 -0
- package/dist/runtime/core/tools/find.d.ts.map +1 -0
- package/dist/runtime/core/tools/find.js +302 -0
- package/dist/runtime/core/tools/find.js.map +1 -0
- package/dist/runtime/core/tools/grep.d.ts +41 -0
- package/dist/runtime/core/tools/grep.d.ts.map +1 -0
- package/dist/runtime/core/tools/grep.js +308 -0
- package/dist/runtime/core/tools/grep.js.map +1 -0
- package/dist/runtime/core/tools/index.d.ts +43 -0
- package/dist/runtime/core/tools/index.d.ts.map +1 -0
- package/dist/runtime/core/tools/index.js +129 -0
- package/dist/runtime/core/tools/index.js.map +1 -0
- package/dist/runtime/core/tools/ls.d.ts +41 -0
- package/dist/runtime/core/tools/ls.d.ts.map +1 -0
- package/dist/runtime/core/tools/ls.js +171 -0
- package/dist/runtime/core/tools/ls.js.map +1 -0
- package/dist/runtime/core/tools/output-accumulator.d.ts +52 -0
- package/dist/runtime/core/tools/output-accumulator.d.ts.map +1 -0
- package/dist/runtime/core/tools/output-accumulator.js +184 -0
- package/dist/runtime/core/tools/output-accumulator.js.map +1 -0
- package/dist/runtime/core/tools/path-utils.d.ts +10 -0
- package/dist/runtime/core/tools/path-utils.d.ts.map +1 -0
- package/dist/runtime/core/tools/path-utils.js +99 -0
- package/dist/runtime/core/tools/path-utils.js.map +1 -0
- package/dist/runtime/core/tools/powershell.d.ts +16 -0
- package/dist/runtime/core/tools/powershell.d.ts.map +1 -0
- package/dist/runtime/core/tools/powershell.js +39 -0
- package/dist/runtime/core/tools/powershell.js.map +1 -0
- package/dist/runtime/core/tools/read.d.ts +39 -0
- package/dist/runtime/core/tools/read.d.ts.map +1 -0
- package/dist/runtime/core/tools/read.js +282 -0
- package/dist/runtime/core/tools/read.js.map +1 -0
- package/dist/runtime/core/tools/render-utils.d.ts +24 -0
- package/dist/runtime/core/tools/render-utils.d.ts.map +1 -0
- package/dist/runtime/core/tools/render-utils.js +65 -0
- package/dist/runtime/core/tools/render-utils.js.map +1 -0
- package/dist/runtime/core/tools/tool-definition-wrapper.d.ts +14 -0
- package/dist/runtime/core/tools/tool-definition-wrapper.d.ts.map +1 -0
- package/dist/runtime/core/tools/tool-definition-wrapper.js +36 -0
- package/dist/runtime/core/tools/tool-definition-wrapper.js.map +1 -0
- package/dist/runtime/core/tools/truncate.d.ts +70 -0
- package/dist/runtime/core/tools/truncate.d.ts.map +1 -0
- package/dist/runtime/core/tools/truncate.js +215 -0
- package/dist/runtime/core/tools/truncate.js.map +1 -0
- package/dist/runtime/core/tools/write.d.ts +30 -0
- package/dist/runtime/core/tools/write.d.ts.map +1 -0
- package/dist/runtime/core/tools/write.js +203 -0
- package/dist/runtime/core/tools/write.js.map +1 -0
- package/dist/runtime/core/trust-manager.d.ts +36 -0
- package/dist/runtime/core/trust-manager.d.ts.map +1 -0
- package/dist/runtime/core/trust-manager.js +203 -0
- package/dist/runtime/core/trust-manager.js.map +1 -0
- package/dist/runtime/core/usage-totals.d.ts +19 -0
- package/dist/runtime/core/usage-totals.d.ts.map +1 -0
- package/dist/runtime/core/usage-totals.js +52 -0
- package/dist/runtime/core/usage-totals.js.map +1 -0
- package/dist/runtime/extensions/index.d.ts +3 -0
- package/dist/runtime/extensions/index.d.ts.map +1 -0
- package/dist/runtime/extensions/index.js +3 -0
- package/dist/runtime/extensions/index.js.map +1 -0
- package/dist/runtime/extensions/llama/client.d.ts +67 -0
- package/dist/runtime/extensions/llama/client.d.ts.map +1 -0
- package/dist/runtime/extensions/llama/client.js +309 -0
- package/dist/runtime/extensions/llama/client.js.map +1 -0
- package/dist/runtime/extensions/llama/huggingface.d.ts +23 -0
- package/dist/runtime/extensions/llama/huggingface.d.ts.map +1 -0
- package/dist/runtime/extensions/llama/huggingface.js +141 -0
- package/dist/runtime/extensions/llama/huggingface.js.map +1 -0
- package/dist/runtime/extensions/llama/index.d.ts +3 -0
- package/dist/runtime/extensions/llama/index.d.ts.map +1 -0
- package/dist/runtime/extensions/llama/index.js +219 -0
- package/dist/runtime/extensions/llama/index.js.map +1 -0
- package/dist/runtime/extensions/llama/provider.d.ts +12 -0
- package/dist/runtime/extensions/llama/provider.d.ts.map +1 -0
- package/dist/runtime/extensions/llama/provider.js +146 -0
- package/dist/runtime/extensions/llama/provider.js.map +1 -0
- package/dist/runtime/extensions/llama/ui.d.ts +42 -0
- package/dist/runtime/extensions/llama/ui.d.ts.map +1 -0
- package/dist/runtime/extensions/llama/ui.js +416 -0
- package/dist/runtime/extensions/llama/ui.js.map +1 -0
- package/dist/runtime/index.d.ts +37 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +49 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/main.d.ts +16 -0
- package/dist/runtime/main.d.ts.map +1 -0
- package/dist/runtime/main.js +799 -0
- package/dist/runtime/main.js.map +1 -0
- package/dist/runtime/migrations.d.ts +33 -0
- package/dist/runtime/migrations.d.ts.map +1 -0
- package/dist/runtime/migrations.js +282 -0
- package/dist/runtime/migrations.js.map +1 -0
- package/dist/runtime/modes/index.d.ts +10 -0
- package/dist/runtime/modes/index.d.ts.map +1 -0
- package/dist/runtime/modes/index.js +8 -0
- package/dist/runtime/modes/index.js.map +1 -0
- package/dist/runtime/modes/interactive/assets/clankolas.png +0 -0
- package/dist/runtime/modes/interactive/components/armin.d.ts +34 -0
- package/dist/runtime/modes/interactive/components/armin.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/armin.js +333 -0
- package/dist/runtime/modes/interactive/components/armin.js.map +1 -0
- package/dist/runtime/modes/interactive/components/assistant-message.d.ts +25 -0
- package/dist/runtime/modes/interactive/components/assistant-message.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/assistant-message.js +150 -0
- package/dist/runtime/modes/interactive/components/assistant-message.js.map +1 -0
- package/dist/runtime/modes/interactive/components/bash-execution.d.ts +34 -0
- package/dist/runtime/modes/interactive/components/bash-execution.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/bash-execution.js +175 -0
- package/dist/runtime/modes/interactive/components/bash-execution.js.map +1 -0
- package/dist/runtime/modes/interactive/components/bordered-loader.d.ts +16 -0
- package/dist/runtime/modes/interactive/components/bordered-loader.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/bordered-loader.js +54 -0
- package/dist/runtime/modes/interactive/components/bordered-loader.js.map +1 -0
- package/dist/runtime/modes/interactive/components/branch-summary-message.d.ts +16 -0
- package/dist/runtime/modes/interactive/components/branch-summary-message.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/branch-summary-message.js +44 -0
- package/dist/runtime/modes/interactive/components/branch-summary-message.js.map +1 -0
- package/dist/runtime/modes/interactive/components/compaction-summary-message.d.ts +16 -0
- package/dist/runtime/modes/interactive/components/compaction-summary-message.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/compaction-summary-message.js +45 -0
- package/dist/runtime/modes/interactive/components/compaction-summary-message.js.map +1 -0
- package/dist/runtime/modes/interactive/components/config-selector.d.ts +102 -0
- package/dist/runtime/modes/interactive/components/config-selector.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/config-selector.js +761 -0
- package/dist/runtime/modes/interactive/components/config-selector.js.map +1 -0
- package/dist/runtime/modes/interactive/components/countdown-timer.d.ts +14 -0
- package/dist/runtime/modes/interactive/components/countdown-timer.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/countdown-timer.js +33 -0
- package/dist/runtime/modes/interactive/components/countdown-timer.js.map +1 -0
- package/dist/runtime/modes/interactive/components/custom-editor.d.ts +21 -0
- package/dist/runtime/modes/interactive/components/custom-editor.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/custom-editor.js +77 -0
- package/dist/runtime/modes/interactive/components/custom-editor.js.map +1 -0
- package/dist/runtime/modes/interactive/components/custom-entry.d.ts +19 -0
- package/dist/runtime/modes/interactive/components/custom-entry.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/custom-entry.js +52 -0
- package/dist/runtime/modes/interactive/components/custom-entry.js.map +1 -0
- package/dist/runtime/modes/interactive/components/custom-message.d.ts +22 -0
- package/dist/runtime/modes/interactive/components/custom-message.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/custom-message.js +87 -0
- package/dist/runtime/modes/interactive/components/custom-message.js.map +1 -0
- package/dist/runtime/modes/interactive/components/daxnuts.d.ts +23 -0
- package/dist/runtime/modes/interactive/components/daxnuts.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/daxnuts.js +140 -0
- package/dist/runtime/modes/interactive/components/daxnuts.js.map +1 -0
- package/dist/runtime/modes/interactive/components/diff.d.ts +12 -0
- package/dist/runtime/modes/interactive/components/diff.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/diff.js +133 -0
- package/dist/runtime/modes/interactive/components/diff.js.map +1 -0
- package/dist/runtime/modes/interactive/components/dynamic-border.d.ts +15 -0
- package/dist/runtime/modes/interactive/components/dynamic-border.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/dynamic-border.js +21 -0
- package/dist/runtime/modes/interactive/components/dynamic-border.js.map +1 -0
- package/dist/runtime/modes/interactive/components/earendil-announcement.d.ts +5 -0
- package/dist/runtime/modes/interactive/components/earendil-announcement.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/earendil-announcement.js +40 -0
- package/dist/runtime/modes/interactive/components/earendil-announcement.js.map +1 -0
- package/dist/runtime/modes/interactive/components/extension-editor.d.ts +21 -0
- package/dist/runtime/modes/interactive/components/extension-editor.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/extension-editor.js +98 -0
- package/dist/runtime/modes/interactive/components/extension-editor.js.map +1 -0
- package/dist/runtime/modes/interactive/components/extension-input.d.ts +23 -0
- package/dist/runtime/modes/interactive/components/extension-input.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/extension-input.js +61 -0
- package/dist/runtime/modes/interactive/components/extension-input.js.map +1 -0
- package/dist/runtime/modes/interactive/components/extension-selector.d.ts +26 -0
- package/dist/runtime/modes/interactive/components/extension-selector.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/extension-selector.js +83 -0
- package/dist/runtime/modes/interactive/components/extension-selector.js.map +1 -0
- package/dist/runtime/modes/interactive/components/first-time-setup.d.ts +25 -0
- package/dist/runtime/modes/interactive/components/first-time-setup.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/first-time-setup.js +103 -0
- package/dist/runtime/modes/interactive/components/first-time-setup.js.map +1 -0
- package/dist/runtime/modes/interactive/components/footer.d.ts +32 -0
- package/dist/runtime/modes/interactive/components/footer.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/footer.js +222 -0
- package/dist/runtime/modes/interactive/components/footer.js.map +1 -0
- package/dist/runtime/modes/interactive/components/index.d.ts +34 -0
- package/dist/runtime/modes/interactive/components/index.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/index.js +35 -0
- package/dist/runtime/modes/interactive/components/index.js.map +1 -0
- package/dist/runtime/modes/interactive/components/keybinding-hints.d.ts +13 -0
- package/dist/runtime/modes/interactive/components/keybinding-hints.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/keybinding-hints.js +36 -0
- package/dist/runtime/modes/interactive/components/keybinding-hints.js.map +1 -0
- package/dist/runtime/modes/interactive/components/login-dialog.d.ts +52 -0
- package/dist/runtime/modes/interactive/components/login-dialog.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/login-dialog.js +188 -0
- package/dist/runtime/modes/interactive/components/login-dialog.js.map +1 -0
- package/dist/runtime/modes/interactive/components/markdown-transform.d.ts +3 -0
- package/dist/runtime/modes/interactive/components/markdown-transform.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/markdown-transform.js +19 -0
- package/dist/runtime/modes/interactive/components/markdown-transform.js.map +1 -0
- package/dist/runtime/modes/interactive/components/mermaid.d.ts +11 -0
- package/dist/runtime/modes/interactive/components/mermaid.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/mermaid.js +75 -0
- package/dist/runtime/modes/interactive/components/mermaid.js.map +1 -0
- package/dist/runtime/modes/interactive/components/model-selector.d.ts +60 -0
- package/dist/runtime/modes/interactive/components/model-selector.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/model-selector.js +370 -0
- package/dist/runtime/modes/interactive/components/model-selector.js.map +1 -0
- package/dist/runtime/modes/interactive/components/oauth-selector.d.ts +33 -0
- package/dist/runtime/modes/interactive/components/oauth-selector.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/oauth-selector.js +163 -0
- package/dist/runtime/modes/interactive/components/oauth-selector.js.map +1 -0
- package/dist/runtime/modes/interactive/components/scoped-models-selector.d.ts +46 -0
- package/dist/runtime/modes/interactive/components/scoped-models-selector.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/scoped-models-selector.js +328 -0
- package/dist/runtime/modes/interactive/components/scoped-models-selector.js.map +1 -0
- package/dist/runtime/modes/interactive/components/session-selector-search.d.ts +23 -0
- package/dist/runtime/modes/interactive/components/session-selector-search.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/session-selector-search.js +155 -0
- package/dist/runtime/modes/interactive/components/session-selector-search.js.map +1 -0
- package/dist/runtime/modes/interactive/components/session-selector.d.ts +95 -0
- package/dist/runtime/modes/interactive/components/session-selector.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/session-selector.js +867 -0
- package/dist/runtime/modes/interactive/components/session-selector.js.map +1 -0
- package/dist/runtime/modes/interactive/components/settings-selector.d.ts +90 -0
- package/dist/runtime/modes/interactive/components/settings-selector.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/settings-selector.js +695 -0
- package/dist/runtime/modes/interactive/components/settings-selector.js.map +1 -0
- package/dist/runtime/modes/interactive/components/settings-submenu.d.ts +72 -0
- package/dist/runtime/modes/interactive/components/settings-submenu.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/settings-submenu.js +165 -0
- package/dist/runtime/modes/interactive/components/settings-submenu.js.map +1 -0
- package/dist/runtime/modes/interactive/components/show-images-selector.d.ts +10 -0
- package/dist/runtime/modes/interactive/components/show-images-selector.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/show-images-selector.js +39 -0
- package/dist/runtime/modes/interactive/components/show-images-selector.js.map +1 -0
- package/dist/runtime/modes/interactive/components/skill-invocation-message.d.ts +17 -0
- package/dist/runtime/modes/interactive/components/skill-invocation-message.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/skill-invocation-message.js +47 -0
- package/dist/runtime/modes/interactive/components/skill-invocation-message.js.map +1 -0
- package/dist/runtime/modes/interactive/components/status-indicator.d.ts +28 -0
- package/dist/runtime/modes/interactive/components/status-indicator.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/status-indicator.js +60 -0
- package/dist/runtime/modes/interactive/components/status-indicator.js.map +1 -0
- package/dist/runtime/modes/interactive/components/theme-selector.d.ts +11 -0
- package/dist/runtime/modes/interactive/components/theme-selector.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/theme-selector.js +50 -0
- package/dist/runtime/modes/interactive/components/theme-selector.js.map +1 -0
- package/dist/runtime/modes/interactive/components/thinking-selector.d.ts +23 -0
- package/dist/runtime/modes/interactive/components/thinking-selector.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/thinking-selector.js +109 -0
- package/dist/runtime/modes/interactive/components/thinking-selector.js.map +1 -0
- package/dist/runtime/modes/interactive/components/tool-execution.d.ts +63 -0
- package/dist/runtime/modes/interactive/components/tool-execution.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/tool-execution.js +326 -0
- package/dist/runtime/modes/interactive/components/tool-execution.js.map +1 -0
- package/dist/runtime/modes/interactive/components/tree-selector.d.ts +94 -0
- package/dist/runtime/modes/interactive/components/tree-selector.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/tree-selector.js +1245 -0
- package/dist/runtime/modes/interactive/components/tree-selector.js.map +1 -0
- package/dist/runtime/modes/interactive/components/trust-selector.d.ts +23 -0
- package/dist/runtime/modes/interactive/components/trust-selector.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/trust-selector.js +91 -0
- package/dist/runtime/modes/interactive/components/trust-selector.js.map +1 -0
- package/dist/runtime/modes/interactive/components/user-message-selector.d.ts +30 -0
- package/dist/runtime/modes/interactive/components/user-message-selector.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/user-message-selector.js +114 -0
- package/dist/runtime/modes/interactive/components/user-message-selector.js.map +1 -0
- package/dist/runtime/modes/interactive/components/user-message.d.ts +16 -0
- package/dist/runtime/modes/interactive/components/user-message.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/user-message.js +49 -0
- package/dist/runtime/modes/interactive/components/user-message.js.map +1 -0
- package/dist/runtime/modes/interactive/components/visual-truncate.d.ts +24 -0
- package/dist/runtime/modes/interactive/components/visual-truncate.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/components/visual-truncate.js +33 -0
- package/dist/runtime/modes/interactive/components/visual-truncate.js.map +1 -0
- package/dist/runtime/modes/interactive/external-editor.d.ts +12 -0
- package/dist/runtime/modes/interactive/external-editor.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/external-editor.js +38 -0
- package/dist/runtime/modes/interactive/external-editor.js.map +1 -0
- package/dist/runtime/modes/interactive/interactive-mode.d.ts +446 -0
- package/dist/runtime/modes/interactive/interactive-mode.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/interactive-mode.js +5509 -0
- package/dist/runtime/modes/interactive/interactive-mode.js.map +1 -0
- package/dist/runtime/modes/interactive/model-catalog-refresh.d.ts +7 -0
- package/dist/runtime/modes/interactive/model-catalog-refresh.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/model-catalog-refresh.js +34 -0
- package/dist/runtime/modes/interactive/model-catalog-refresh.js.map +1 -0
- package/dist/runtime/modes/interactive/model-search.d.ts +12 -0
- package/dist/runtime/modes/interactive/model-search.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/model-search.js +15 -0
- package/dist/runtime/modes/interactive/model-search.js.map +1 -0
- package/dist/runtime/modes/interactive/session-share.d.ts +16 -0
- package/dist/runtime/modes/interactive/session-share.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/session-share.js +188 -0
- package/dist/runtime/modes/interactive/session-share.js.map +1 -0
- package/dist/runtime/modes/interactive/theme/dark.json +90 -0
- package/dist/runtime/modes/interactive/theme/light.json +89 -0
- package/dist/runtime/modes/interactive/theme/theme-controller.d.ts +40 -0
- package/dist/runtime/modes/interactive/theme/theme-controller.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/theme/theme-controller.js +125 -0
- package/dist/runtime/modes/interactive/theme/theme-controller.js.map +1 -0
- package/dist/runtime/modes/interactive/theme/theme-schema.json +352 -0
- package/dist/runtime/modes/interactive/theme/theme.d.ts +122 -0
- package/dist/runtime/modes/interactive/theme/theme.d.ts.map +1 -0
- package/dist/runtime/modes/interactive/theme/theme.js +1092 -0
- package/dist/runtime/modes/interactive/theme/theme.js.map +1 -0
- package/dist/runtime/modes/json-event.d.ts +34 -0
- package/dist/runtime/modes/json-event.d.ts.map +1 -0
- package/dist/runtime/modes/json-event.js +29 -0
- package/dist/runtime/modes/json-event.js.map +1 -0
- package/dist/runtime/modes/print-mode.d.ts +28 -0
- package/dist/runtime/modes/print-mode.d.ts.map +1 -0
- package/dist/runtime/modes/print-mode.js +142 -0
- package/dist/runtime/modes/print-mode.js.map +1 -0
- package/dist/runtime/modes/rpc/jsonl.d.ts +17 -0
- package/dist/runtime/modes/rpc/jsonl.d.ts.map +1 -0
- package/dist/runtime/modes/rpc/jsonl.js +49 -0
- package/dist/runtime/modes/rpc/jsonl.js.map +1 -0
- package/dist/runtime/modes/rpc/rpc-client.d.ts +254 -0
- package/dist/runtime/modes/rpc/rpc-client.d.ts.map +1 -0
- package/dist/runtime/modes/rpc/rpc-client.js +495 -0
- package/dist/runtime/modes/rpc/rpc-client.js.map +1 -0
- package/dist/runtime/modes/rpc/rpc-mode.d.ts +20 -0
- package/dist/runtime/modes/rpc/rpc-mode.d.ts.map +1 -0
- package/dist/runtime/modes/rpc/rpc-mode.js +657 -0
- package/dist/runtime/modes/rpc/rpc-mode.js.map +1 -0
- package/dist/runtime/modes/rpc/rpc-types.d.ts +469 -0
- package/dist/runtime/modes/rpc/rpc-types.d.ts.map +1 -0
- package/dist/runtime/modes/rpc/rpc-types.js +8 -0
- package/dist/runtime/modes/rpc/rpc-types.js.map +1 -0
- package/dist/runtime/package-manager-cli.d.ts +9 -0
- package/dist/runtime/package-manager-cli.d.ts.map +1 -0
- package/dist/runtime/package-manager-cli.js +961 -0
- package/dist/runtime/package-manager-cli.js.map +1 -0
- package/dist/runtime/rpc-entry.d.ts +3 -0
- package/dist/runtime/rpc-entry.d.ts.map +1 -0
- package/dist/runtime/rpc-entry.js +11 -0
- package/dist/runtime/rpc-entry.js.map +1 -0
- package/dist/runtime/server/create-harness.d.ts +26 -0
- package/dist/runtime/server/create-harness.d.ts.map +1 -0
- package/dist/runtime/server/create-harness.js +106 -0
- package/dist/runtime/server/create-harness.js.map +1 -0
- package/dist/runtime/utils/abort.d.ts +5 -0
- package/dist/runtime/utils/abort.d.ts.map +1 -0
- package/dist/runtime/utils/abort.js +48 -0
- package/dist/runtime/utils/abort.js.map +1 -0
- package/dist/runtime/utils/ansi.d.ts +2 -0
- package/dist/runtime/utils/ansi.d.ts.map +1 -0
- package/dist/runtime/utils/ansi.js +52 -0
- package/dist/runtime/utils/ansi.js.map +1 -0
- package/dist/runtime/utils/changelog.d.ts +22 -0
- package/dist/runtime/utils/changelog.d.ts.map +1 -0
- package/dist/runtime/utils/changelog.js +165 -0
- package/dist/runtime/utils/changelog.js.map +1 -0
- package/dist/runtime/utils/child-process.d.ts +18 -0
- package/dist/runtime/utils/child-process.d.ts.map +1 -0
- package/dist/runtime/utils/child-process.js +106 -0
- package/dist/runtime/utils/child-process.js.map +1 -0
- package/dist/runtime/utils/clipboard-image.d.ts +11 -0
- package/dist/runtime/utils/clipboard-image.d.ts.map +1 -0
- package/dist/runtime/utils/clipboard-image.js +245 -0
- package/dist/runtime/utils/clipboard-image.js.map +1 -0
- package/dist/runtime/utils/clipboard-native.d.ts +11 -0
- package/dist/runtime/utils/clipboard-native.d.ts.map +1 -0
- package/dist/runtime/utils/clipboard-native.js +20 -0
- package/dist/runtime/utils/clipboard-native.js.map +1 -0
- package/dist/runtime/utils/clipboard.d.ts +4 -0
- package/dist/runtime/utils/clipboard.d.ts.map +1 -0
- package/dist/runtime/utils/clipboard.js +161 -0
- package/dist/runtime/utils/clipboard.js.map +1 -0
- package/dist/runtime/utils/deprecation.d.ts +4 -0
- package/dist/runtime/utils/deprecation.d.ts.map +1 -0
- package/dist/runtime/utils/deprecation.js +13 -0
- package/dist/runtime/utils/deprecation.js.map +1 -0
- package/dist/runtime/utils/exif-orientation.d.ts +5 -0
- package/dist/runtime/utils/exif-orientation.d.ts.map +1 -0
- package/dist/runtime/utils/exif-orientation.js +158 -0
- package/dist/runtime/utils/exif-orientation.js.map +1 -0
- package/dist/runtime/utils/frontmatter.d.ts +8 -0
- package/dist/runtime/utils/frontmatter.d.ts.map +1 -0
- package/dist/runtime/utils/frontmatter.js +27 -0
- package/dist/runtime/utils/frontmatter.js.map +1 -0
- package/dist/runtime/utils/fs-watch.d.ts +5 -0
- package/dist/runtime/utils/fs-watch.d.ts.map +1 -0
- package/dist/runtime/utils/fs-watch.js +25 -0
- package/dist/runtime/utils/fs-watch.js.map +1 -0
- package/dist/runtime/utils/git.d.ts +26 -0
- package/dist/runtime/utils/git.d.ts.map +1 -0
- package/dist/runtime/utils/git.js +195 -0
- package/dist/runtime/utils/git.js.map +1 -0
- package/dist/runtime/utils/html.d.ts +7 -0
- package/dist/runtime/utils/html.d.ts.map +1 -0
- package/dist/runtime/utils/html.js +40 -0
- package/dist/runtime/utils/html.js.map +1 -0
- package/dist/runtime/utils/image-convert.d.ts +10 -0
- package/dist/runtime/utils/image-convert.d.ts.map +1 -0
- package/dist/runtime/utils/image-convert.js +45 -0
- package/dist/runtime/utils/image-convert.js.map +1 -0
- package/dist/runtime/utils/image-process.d.ts +18 -0
- package/dist/runtime/utils/image-process.d.ts.map +1 -0
- package/dist/runtime/utils/image-process.js +83 -0
- package/dist/runtime/utils/image-process.js.map +1 -0
- package/dist/runtime/utils/image-resize-core.d.ts +30 -0
- package/dist/runtime/utils/image-resize-core.d.ts.map +1 -0
- package/dist/runtime/utils/image-resize-core.js +124 -0
- package/dist/runtime/utils/image-resize-core.js.map +1 -0
- package/dist/runtime/utils/image-resize-worker.d.ts +2 -0
- package/dist/runtime/utils/image-resize-worker.d.ts.map +1 -0
- package/dist/runtime/utils/image-resize-worker.js +31 -0
- package/dist/runtime/utils/image-resize-worker.js.map +1 -0
- package/dist/runtime/utils/image-resize.d.ts +16 -0
- package/dist/runtime/utils/image-resize.d.ts.map +1 -0
- package/dist/runtime/utils/image-resize.js +97 -0
- package/dist/runtime/utils/image-resize.js.map +1 -0
- package/dist/runtime/utils/json.d.ts +3 -0
- package/dist/runtime/utils/json.d.ts.map +1 -0
- package/dist/runtime/utils/json.js +7 -0
- package/dist/runtime/utils/json.js.map +1 -0
- package/dist/runtime/utils/management-http.d.ts +25 -0
- package/dist/runtime/utils/management-http.d.ts.map +1 -0
- package/dist/runtime/utils/management-http.js +54 -0
- package/dist/runtime/utils/management-http.js.map +1 -0
- package/dist/runtime/utils/mime.d.ts +3 -0
- package/dist/runtime/utils/mime.d.ts.map +1 -0
- package/dist/runtime/utils/mime.js +110 -0
- package/dist/runtime/utils/mime.js.map +1 -0
- package/dist/runtime/utils/open-browser.d.ts +9 -0
- package/dist/runtime/utils/open-browser.d.ts.map +1 -0
- package/dist/runtime/utils/open-browser.js +22 -0
- package/dist/runtime/utils/open-browser.js.map +1 -0
- package/dist/runtime/utils/paths.d.ts +34 -0
- package/dist/runtime/utils/paths.d.ts.map +1 -0
- package/dist/runtime/utils/paths.js +114 -0
- package/dist/runtime/utils/paths.js.map +1 -0
- package/dist/runtime/utils/photon.d.ts +21 -0
- package/dist/runtime/utils/photon.d.ts.map +1 -0
- package/dist/runtime/utils/photon.js +121 -0
- package/dist/runtime/utils/photon.js.map +1 -0
- package/dist/runtime/utils/pi-user-agent.d.ts +2 -0
- package/dist/runtime/utils/pi-user-agent.d.ts.map +1 -0
- package/dist/runtime/utils/pi-user-agent.js +5 -0
- package/dist/runtime/utils/pi-user-agent.js.map +1 -0
- package/dist/runtime/utils/shell.d.ts +34 -0
- package/dist/runtime/utils/shell.d.ts.map +1 -0
- package/dist/runtime/utils/shell.js +214 -0
- package/dist/runtime/utils/shell.js.map +1 -0
- package/dist/runtime/utils/sleep.d.ts +5 -0
- package/dist/runtime/utils/sleep.d.ts.map +1 -0
- package/dist/runtime/utils/sleep.js +17 -0
- package/dist/runtime/utils/sleep.js.map +1 -0
- package/dist/runtime/utils/syntax-highlight.d.ts +13 -0
- package/dist/runtime/utils/syntax-highlight.d.ts.map +1 -0
- package/dist/runtime/utils/syntax-highlight.js +177 -0
- package/dist/runtime/utils/syntax-highlight.js.map +1 -0
- package/dist/runtime/utils/text.d.ts +8 -0
- package/dist/runtime/utils/text.d.ts.map +1 -0
- package/dist/runtime/utils/text.js +9 -0
- package/dist/runtime/utils/text.js.map +1 -0
- package/dist/runtime/utils/tool-result-images.d.ts +19 -0
- package/dist/runtime/utils/tool-result-images.d.ts.map +1 -0
- package/dist/runtime/utils/tool-result-images.js +45 -0
- package/dist/runtime/utils/tool-result-images.js.map +1 -0
- package/dist/runtime/utils/tools-manager.d.ts +12 -0
- package/dist/runtime/utils/tools-manager.d.ts.map +1 -0
- package/dist/runtime/utils/tools-manager.js +321 -0
- package/dist/runtime/utils/tools-manager.js.map +1 -0
- package/dist/runtime/utils/version-check.d.ts +19 -0
- package/dist/runtime/utils/version-check.d.ts.map +1 -0
- package/dist/runtime/utils/version-check.js +79 -0
- package/dist/runtime/utils/version-check.js.map +1 -0
- package/dist/runtime/utils/windows-self-update.d.ts +3 -0
- package/dist/runtime/utils/windows-self-update.d.ts.map +1 -0
- package/dist/runtime/utils/windows-self-update.js +77 -0
- package/dist/runtime/utils/windows-self-update.js.map +1 -0
- package/dist/update.js +134 -0
- package/dist/workflows.js +391 -0
- package/docs/compaction.md +416 -0
- package/docs/containerization.md +111 -0
- package/docs/custom-provider.md +777 -0
- package/docs/development.md +71 -0
- package/docs/docs.json +156 -0
- package/docs/environment-variables.md +94 -0
- package/docs/extensions.md +3002 -0
- package/docs/images/doom-extension.png +0 -0
- package/docs/images/exy.png +0 -0
- package/docs/images/interactive-mode.png +0 -0
- package/docs/images/tree-view.png +0 -0
- package/docs/index.md +84 -0
- package/docs/json.md +98 -0
- package/docs/keybindings.md +236 -0
- package/docs/llama-cpp.md +101 -0
- package/docs/models.md +571 -0
- package/docs/packages.md +228 -0
- package/docs/prompt-templates.md +96 -0
- package/docs/providers.md +317 -0
- package/docs/quickstart.md +167 -0
- package/docs/rpc.md +1618 -0
- package/docs/sdk.md +1219 -0
- package/docs/security.md +59 -0
- package/docs/session-format.md +438 -0
- package/docs/sessions.md +145 -0
- package/docs/settings.md +361 -0
- package/docs/shell-aliases.md +13 -0
- package/docs/skills.md +232 -0
- package/docs/terminal-setup.md +165 -0
- package/docs/termux.md +127 -0
- package/docs/themes.md +320 -0
- package/docs/tmux.md +63 -0
- package/docs/tui.md +942 -0
- package/docs/usage.md +310 -0
- package/docs/windows.md +39 -0
- package/examples/README.md +25 -0
- package/examples/extensions/README.md +213 -0
- package/examples/extensions/auto-commit-on-exit.ts +49 -0
- package/examples/extensions/bash-spawn-hook.ts +30 -0
- package/examples/extensions/bookmark.ts +50 -0
- package/examples/extensions/border-status-editor.ts +150 -0
- package/examples/extensions/built-in-tool-renderer.ts +249 -0
- package/examples/extensions/claude-rules.ts +86 -0
- package/examples/extensions/commands.ts +72 -0
- package/examples/extensions/confirm-destructive.ts +59 -0
- package/examples/extensions/custom-compaction.ts +117 -0
- package/examples/extensions/custom-footer.ts +64 -0
- package/examples/extensions/custom-header.ts +73 -0
- package/examples/extensions/custom-provider-anthropic/index.ts +611 -0
- package/examples/extensions/custom-provider-anthropic/package-lock.json +24 -0
- package/examples/extensions/custom-provider-anthropic/package.json +19 -0
- package/examples/extensions/custom-provider-gitlab-duo/index.ts +405 -0
- package/examples/extensions/custom-provider-gitlab-duo/package.json +16 -0
- package/examples/extensions/custom-provider-gitlab-duo/test.ts +82 -0
- package/examples/extensions/dirty-repo-guard.ts +56 -0
- package/examples/extensions/doom-overlay/README.md +46 -0
- package/examples/extensions/doom-overlay/doom/build/doom.js +21 -0
- package/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
- package/examples/extensions/doom-overlay/doom/build.sh +152 -0
- package/examples/extensions/doom-overlay/doom/doomgeneric_pi.c +72 -0
- package/examples/extensions/doom-overlay/doom-component.ts +132 -0
- package/examples/extensions/doom-overlay/doom-engine.ts +173 -0
- package/examples/extensions/doom-overlay/doom-keys.ts +104 -0
- package/examples/extensions/doom-overlay/index.ts +74 -0
- package/examples/extensions/doom-overlay/wad-finder.ts +55 -0
- package/examples/extensions/dynamic-resources/SKILL.md +8 -0
- package/examples/extensions/dynamic-resources/dynamic.json +79 -0
- package/examples/extensions/dynamic-resources/dynamic.md +5 -0
- package/examples/extensions/dynamic-resources/index.ts +15 -0
- package/examples/extensions/dynamic-tools.ts +74 -0
- package/examples/extensions/entry-renderer.ts +41 -0
- package/examples/extensions/event-bus.ts +43 -0
- package/examples/extensions/file-trigger.ts +41 -0
- package/examples/extensions/git-checkpoint.ts +53 -0
- package/examples/extensions/git-merge-and-resolve.ts +115 -0
- package/examples/extensions/github-issue-autocomplete.ts +185 -0
- package/examples/extensions/gondolin/index.ts +531 -0
- package/examples/extensions/gondolin/package-lock.json +185 -0
- package/examples/extensions/gondolin/package.json +19 -0
- package/examples/extensions/handoff.ts +190 -0
- package/examples/extensions/hello.ts +26 -0
- package/examples/extensions/hidden-thinking-label.ts +53 -0
- package/examples/extensions/inline-bash.ts +94 -0
- package/examples/extensions/input-transform-streaming.ts +39 -0
- package/examples/extensions/input-transform.ts +43 -0
- package/examples/extensions/interactive-shell.ts +196 -0
- package/examples/extensions/kimi-deferred-tools.ts +61 -0
- package/examples/extensions/mac-system-theme.ts +47 -0
- package/examples/extensions/message-renderer.ts +59 -0
- package/examples/extensions/minimal-mode.ts +426 -0
- package/examples/extensions/modal-editor.ts +85 -0
- package/examples/extensions/model-status.ts +31 -0
- package/examples/extensions/notify.ts +57 -0
- package/examples/extensions/overlay-qa-tests.ts +1450 -0
- package/examples/extensions/overlay-test.ts +153 -0
- package/examples/extensions/permission-gate.ts +34 -0
- package/examples/extensions/pirate.ts +47 -0
- package/examples/extensions/plan-mode/README.md +66 -0
- package/examples/extensions/plan-mode/index.ts +390 -0
- package/examples/extensions/plan-mode/utils.ts +168 -0
- package/examples/extensions/preset.ts +436 -0
- package/examples/extensions/project-trust.ts +64 -0
- package/examples/extensions/prompt-customizer.ts +97 -0
- package/examples/extensions/protected-paths.ts +30 -0
- package/examples/extensions/provider-payload.ts +18 -0
- package/examples/extensions/qna.ts +118 -0
- package/examples/extensions/question.ts +286 -0
- package/examples/extensions/questionnaire.ts +448 -0
- package/examples/extensions/rainbow-editor.ts +88 -0
- package/examples/extensions/reload-runtime.ts +37 -0
- package/examples/extensions/rpc-demo.ts +118 -0
- package/examples/extensions/sandbox/index.ts +321 -0
- package/examples/extensions/sandbox/package-lock.json +92 -0
- package/examples/extensions/sandbox/package.json +19 -0
- package/examples/extensions/send-user-message.ts +97 -0
- package/examples/extensions/session-name.ts +27 -0
- package/examples/extensions/shutdown-command.ts +63 -0
- package/examples/extensions/snake.ts +343 -0
- package/examples/extensions/space-invaders.ts +560 -0
- package/examples/extensions/ssh.ts +220 -0
- package/examples/extensions/status-line.ts +32 -0
- package/examples/extensions/structured-output.ts +65 -0
- package/examples/extensions/subagent/README.md +177 -0
- package/examples/extensions/subagent/agents/planner.md +37 -0
- package/examples/extensions/subagent/agents/reviewer.md +35 -0
- package/examples/extensions/subagent/agents/scout.md +50 -0
- package/examples/extensions/subagent/agents/worker.md +24 -0
- package/examples/extensions/subagent/agents.ts +157 -0
- package/examples/extensions/subagent/index.ts +1038 -0
- package/examples/extensions/subagent/prompts/implement-and-review.md +10 -0
- package/examples/extensions/subagent/prompts/implement.md +10 -0
- package/examples/extensions/subagent/prompts/scout-and-plan.md +9 -0
- package/examples/extensions/summarize.ts +199 -0
- package/examples/extensions/system-prompt-header.ts +17 -0
- package/examples/extensions/tic-tac-toe.ts +1008 -0
- package/examples/extensions/timed-confirm.ts +70 -0
- package/examples/extensions/titlebar-spinner.ts +58 -0
- package/examples/extensions/todo.ts +297 -0
- package/examples/extensions/tool-override.ts +144 -0
- package/examples/extensions/tools.ts +146 -0
- package/examples/extensions/trigger-compact.ts +50 -0
- package/examples/extensions/truncated-tool.ts +195 -0
- package/examples/extensions/widget-placement.ts +9 -0
- package/examples/extensions/with-deps/index.ts +32 -0
- package/examples/extensions/with-deps/package-lock.json +31 -0
- package/examples/extensions/with-deps/package.json +22 -0
- package/examples/extensions/working-indicator.ts +123 -0
- package/examples/extensions/working-message-test.ts +25 -0
- package/examples/rpc-extension-ui.ts +641 -0
- package/examples/sdk/01-minimal.ts +26 -0
- package/examples/sdk/02-custom-model.ts +49 -0
- package/examples/sdk/03-custom-prompt.ts +75 -0
- package/examples/sdk/04-skills.ts +55 -0
- package/examples/sdk/05-tools.ts +48 -0
- package/examples/sdk/06-extensions.ts +99 -0
- package/examples/sdk/07-context-files.ts +47 -0
- package/examples/sdk/08-prompt-templates.ts +51 -0
- package/examples/sdk/09-api-keys-and-oauth.ts +34 -0
- package/examples/sdk/10-settings.ts +53 -0
- package/examples/sdk/11-sessions.ts +52 -0
- package/examples/sdk/12-full-control.ts +74 -0
- package/examples/sdk/13-session-runtime.ts +67 -0
- package/examples/sdk/README.md +140 -0
- package/package.json +65 -12
- package/upstream.json +6 -0
- package/workflows/cm/LICENSE +21 -0
- package/workflows/cm/README.md +333 -0
- package/workflows/cm/THIRD_PARTY_NOTICES.md +29 -0
- package/workflows/cm/VERSION +1 -0
- package/workflows/cm/agents/cm-backend-agent.md +34 -0
- package/workflows/cm/agents/cm-contract-agent.md +34 -0
- package/workflows/cm/agents/cm-database-agent.md +34 -0
- package/workflows/cm/agents/cm-frontend-agent.md +33 -0
- package/workflows/cm/agents/cm-miniprogram-agent.md +33 -0
- package/workflows/cm/agents/cm-ui-agent.md +34 -0
- package/workflows/cm/assets/docs/command-picker-mobile.svg +56 -0
- package/workflows/cm/assets/docs/command-picker.svg +56 -0
- package/workflows/cm/assets/docs/user-guide-hero-mobile.svg +35 -0
- package/workflows/cm/assets/docs/user-guide-hero.svg +36 -0
- package/workflows/cm/assets/readme/delivery-flow.svg +86 -0
- package/workflows/cm/assets/readme/hero.svg +77 -0
- package/workflows/cm/assets/readme/recovery-record.svg +73 -0
- package/workflows/cm/assets/readme/test-evidence.svg +64 -0
- package/workflows/cm/compat/claude-commands/cm-ai.md +3 -0
- package/workflows/cm/compat/claude-commands/cm-check.md +3 -0
- package/workflows/cm/compat/claude-commands/cm-fix.md +3 -0
- package/workflows/cm/compat/claude-commands/cm-idea.md +3 -0
- package/workflows/cm/compat/claude-commands/cm-init.md +3 -0
- package/workflows/cm/compat/claude-commands/cm-prd.md +3 -0
- package/workflows/cm/compat/claude-commands/cm-refactor.md +3 -0
- package/workflows/cm/compat/claude-commands/cm-test.md +3 -0
- package/workflows/cm/docs/architecture.md +130 -0
- package/workflows/cm/docs/fixes/.reviews/fix-manifest-runtime-checkbox-drift-r1.md +33 -0
- package/workflows/cm/docs/fixes/.reviews/fix-manifest-runtime-checkbox-drift-r2.md +31 -0
- package/workflows/cm/docs/fixes/.reviews/fix-model-call-boundary-identity-T-FIX-model-call-boundary-identity-a1-handoff.json +56 -0
- package/workflows/cm/docs/fixes/.reviews/fix-model-call-boundary-identity-T-FIX-model-call-boundary-identity-a2-handoff.json +85 -0
- package/workflows/cm/docs/fixes/.reviews/fix-model-call-boundary-identity-T-FIX-model-call-boundary-identity-r1.md +53 -0
- package/workflows/cm/docs/fixes/.reviews/fix-model-call-boundary-identity-T-FIX-model-call-boundary-identity-r2.md +80 -0
- package/workflows/cm/docs/fixes/.reviews/fix-review-evidence-scope-honesty-T-FIX-review-evidence-scope-honesty-a1-handoff.json +35 -0
- package/workflows/cm/docs/fixes/.reviews/fix-review-evidence-scope-honesty-T-FIX-review-evidence-scope-honesty-r1.md +33 -0
- package/workflows/cm/docs/fixes/.reviews/fix-windows-cp1252-log-output-r1.md +30 -0
- package/workflows/cm/docs/fixes/.reviews/fix-windows-cp1252-log-output-r2.md +16 -0
- package/workflows/cm/docs/fixes/.reviews/openai-compatible-depth-fixture-T-FIX-openai-compatible-depth-fixture-a1-handoff.json +40 -0
- package/workflows/cm/docs/fixes/.reviews/openai-compatible-depth-fixture-T-FIX-openai-compatible-depth-fixture-r1.md +30 -0
- package/workflows/cm/docs/fixes/20260729-windows-cp1252-log-output.md +65 -0
- package/workflows/cm/docs/fixes/20260804-manifest-runtime-checkbox-drift.md +67 -0
- package/workflows/cm/docs/fixes/20260806-model-call-boundary-identity.md +80 -0
- package/workflows/cm/docs/fixes/20260807-prelanding-integrity.md +58 -0
- package/workflows/cm/docs/fixes/20260826-openai-compatible-depth-fixture.md +39 -0
- package/workflows/cm/docs/installation.md +149 -0
- package/workflows/cm/docs/sample-prd/prd-funding-rate-alert.md +42 -0
- package/workflows/cm/docs/sample-specs/docs//351/234/200/346/261/202/347/244/272/344/276/213.md +24 -0
- package/workflows/cm/docs/user-guide.md +521 -0
- package/workflows/cm/docs//351/207/215/346/236/204/346/265/201/347/250/213/350/256/276/350/256/241/README.md +19 -0
- package/workflows/cm/docs//351/207/215/346/236/204/346/265/201/347/250/213/350/256/276/350/256/241/refactor-flow.excalidraw +3650 -0
- package/workflows/cm/docs//351/207/215/346/236/204/346/265/201/347/250/213/350/256/276/350/256/241/refactor-flow.mp4 +0 -0
- package/workflows/cm/docs//351/207/215/346/236/204/346/265/201/347/250/213/350/256/276/350/256/241/refactor-flow.png +0 -0
- package/workflows/cm/docs//351/207/215/346/236/204/346/265/201/347/250/213/350/256/276/350/256/241/refactor-flow.spec.json +223 -0
- package/workflows/cm/package.json +45 -0
- package/workflows/cm/runtime/external-expert.md +302 -0
- package/workflows/cm/runtime/logging.md +206 -0
- package/workflows/cm/runtime/model-efficiency.md +201 -0
- package/workflows/cm/runtime/orchestration.md +113 -0
- package/workflows/cm/runtime/project-context.md +37 -0
- package/workflows/cm/runtime/review.md +114 -0
- package/workflows/cm/runtime/task-gates.md +114 -0
- package/workflows/cm/runtime/task-handoff.schema.json +103 -0
- package/workflows/cm/runtime/test-contract.md +212 -0
- package/workflows/cm/runtime/workflow-config.md +115 -0
- package/workflows/cm/runtime/workflow-routing.md +82 -0
- package/workflows/cm/scripts/cm-check-runtime.ps1 +69 -0
- package/workflows/cm/scripts/cm-check-runtime.sh +866 -0
- package/workflows/cm/scripts/cm-log-event.py +1270 -0
- package/workflows/cm/scripts/cm-openai-compatible-call.py +661 -0
- package/workflows/cm/scripts/cm-prd-review-gate.py +319 -0
- package/workflows/cm/scripts/cm-prd-timing.py +272 -0
- package/workflows/cm/scripts/cm-spec-manifest.py +171 -0
- package/workflows/cm/scripts/cm-task-gate.py +760 -0
- package/workflows/cm/scripts/cm-usage-report.py +516 -0
- package/workflows/cm/scripts/cm_workflow_config.py +612 -0
- package/workflows/cm/scripts/scan-public-safety.py +89 -0
- package/workflows/cm/scripts/test-cm-log-event.py +1213 -0
- package/workflows/cm/scripts/test-cm-openai-compatible-call.py +1185 -0
- package/workflows/cm/scripts/test-cm-prd-review-gate.py +243 -0
- package/workflows/cm/scripts/test-cm-prd-timing.py +168 -0
- package/workflows/cm/scripts/test-cm-usage-report.py +584 -0
- package/workflows/cm/scripts/test-shell-compat.sh +338 -0
- package/workflows/cm/scripts/test-spec-manifest.py +220 -0
- package/workflows/cm/scripts/test-task-gate.py +540 -0
- package/workflows/cm/scripts/test-workflow-config.py +394 -0
- package/workflows/cm/scripts/validate-public-repo.py +200 -0
- package/workflows/cm/scripts/validate-test-cases.py +127 -0
- package/workflows/cm/skills/cm-ai/SKILL.md +120 -0
- package/workflows/cm/skills/cm-ai/references/N1-init.md +92 -0
- package/workflows/cm/skills/cm-ai/references/N2-enter-feature.md +38 -0
- package/workflows/cm/skills/cm-ai/references/N3-execute-task.md +99 -0
- package/workflows/cm/skills/cm-ai/references/N4-review.md +96 -0
- package/workflows/cm/skills/cm-ai/references/N5-mark-done.md +107 -0
- package/workflows/cm/skills/cm-ai/references/N6-qa-eval.md +102 -0
- package/workflows/cm/skills/cm-ai/references/N7-context.md +23 -0
- package/workflows/cm/skills/cm-ai/references/N8-finish.md +97 -0
- package/workflows/cm/skills/cm-backend-engineer/SKILL.md +100 -0
- package/workflows/cm/skills/cm-check/SKILL.md +60 -0
- package/workflows/cm/skills/cm-contract-engineer/SKILL.md +136 -0
- package/workflows/cm/skills/cm-database-engineer/SKILL.md +89 -0
- package/workflows/cm/skills/cm-devops-engineer/SKILL.md +137 -0
- package/workflows/cm/skills/cm-doc-syncer/SKILL.md +150 -0
- package/workflows/cm/skills/cm-finance-expert/SKILL.md +85 -0
- package/workflows/cm/skills/cm-fix/SKILL.md +159 -0
- package/workflows/cm/skills/cm-frontend-engineer/SKILL.md +127 -0
- package/workflows/cm/skills/cm-idea/SKILL.md +42 -0
- package/workflows/cm/skills/cm-idea/references/domains/trading.md +97 -0
- package/workflows/cm/skills/cm-idea/references/example-prd.md +92 -0
- package/workflows/cm/skills/cm-idea/references/idea-to-prd.md +282 -0
- package/workflows/cm/skills/cm-init/SKILL.md +158 -0
- package/workflows/cm/skills/cm-miniprogram-engineer/SKILL.md +141 -0
- package/workflows/cm/skills/cm-miniprogram-engineer/references/platform-readiness.md +58 -0
- package/workflows/cm/skills/cm-miniprogram-engineer/references/release-checklist.md +59 -0
- package/workflows/cm/skills/cm-prd/SKILL.md +521 -0
- package/workflows/cm/skills/cm-prd/references/brownfield.md +13 -0
- package/workflows/cm/skills/cm-prd/references/change-mode.md +145 -0
- package/workflows/cm/skills/cm-prd/references/context-scope.md +62 -0
- package/workflows/cm/skills/cm-prd/references/greenfield.md +80 -0
- package/workflows/cm/skills/cm-prd/references/phase-timing.md +60 -0
- package/workflows/cm/skills/cm-prd/references/spec-self-check.md +22 -0
- package/workflows/cm/skills/cm-product-manager/SKILL.md +83 -0
- package/workflows/cm/skills/cm-qa-engineer/SKILL.md +142 -0
- package/workflows/cm/skills/cm-refactor/SKILL.md +209 -0
- package/workflows/cm/skills/cm-test/SKILL.md +259 -0
- package/workflows/cm/skills/cm-ui-engineer/SKILL.md +105 -0
- package/workflows/cm/skills/codebase-context/SKILL.md +489 -0
- package/workflows/cm/skills/darwin-skill/NOTICE.md +26 -0
- package/workflows/cm/skills/darwin-skill/README.md +272 -0
- package/workflows/cm/skills/darwin-skill/SKILL.md +492 -0
- package/workflows/cm/skills/darwin-skill/references/runtime-neutrality.md +68 -0
- package/workflows/cm/skills/darwin-skill/references/skilllens-evidence.md +142 -0
- package/workflows/cm/skills/darwin-skill/scripts/screenshot.mjs +71 -0
- package/workflows/cm/skills/darwin-skill/templates/result-card-dark.html +698 -0
- package/workflows/cm/skills/darwin-skill/templates/result-card-white.html +444 -0
- package/workflows/cm/skills/darwin-skill/templates/result-card.html +616 -0
- package/workflows/cm/skills/external-expert/SKILL.md +250 -0
- package/workflows/cm/templates/arch-reference.md +68 -0
- package/workflows/cm/templates/auto-update/cm-announce.sh +19 -0
- package/workflows/cm/templates/auto-update/cm-update.sh +274 -0
- package/workflows/cm/templates/cm-workflow.yml +52 -0
- package/workflows/cm/templates/dashboard/dashboard.html +153 -0
- package/workflows/cm/templates/dashboard/serve.sh +10 -0
- package/workflows/cm/templates/hooks/pre-commit-cm-task-check +67 -0
- package/workflows/cm/templates/pixel/cm-pixel.html +388 -0
- package/workflows/cm/templates/pixel/cm-pixel.sh +212 -0
- package/workflows/cm/templates/pixel/dev/README.md +20 -0
- package/workflows/cm/templates/pixel/dev/atlas-preview.png +0 -0
- package/workflows/cm/templates/pixel/dev/build.py +55 -0
- package/workflows/cm/templates/pixel/dev/sheets/roguelikeChar_transparent.png +0 -0
- package/workflows/cm/templates/pixel/dev/sheets/roguelikeCity_tilemap.png +0 -0
- package/workflows/cm/templates/pixel/dev/sheets/roguelikeIndoor_transparent.png +0 -0
- package/workflows/cm/templates/pixel/dev/template.html +388 -0
- package/workflows/cm/templates/pixel/serve.sh +12 -0
- package/workflows/cm/templates/refactor/cm-refactor-denies.json +14 -0
- package/workflows/cm/templates/rules/backend-api.md +36 -0
- package/workflows/cm/templates/rules/coding-style.md +44 -0
- package/workflows/cm/templates/rules/database.md +27 -0
- package/workflows/cm/templates/rules/finance.md +32 -0
- package/workflows/cm/templates/rules/frontend.md +32 -0
- package/workflows/cm/templates/rules/git-workflow.md +25 -0
- package/workflows/cm/templates/rules/miniprogram.md +31 -0
- package/workflows/cm/templates/rules/security.md +31 -0
- package/workflows/cm/templates/rules/smart-contract.md +28 -0
- package/workflows/cm/templates/rules/testing.md +36 -0
- package/workflows/cm/templates/statusline/cm-statusline.sh +73 -0
- package/workflows/cm/templates/ui-lens/cm-ui-lens-extract.mjs +55 -0
- package/workflows.lock.json +39 -0
|
@@ -0,0 +1,53 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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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,WAAW,CAKpE;IAED,uBAAuB,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,qBAAqB,KAAK,IAAI,GAAG,WAAW,CAGtF;IAED,OAAa,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,GAAE,oBAAyB,GAAG,OAAO,CAAC,aAAa,CAAC,CASjH;IAEK,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAG3C;IAED,OAAa,MAAM,CAClB,MAAM,EAAE,QAAQ,EAChB,aAAa,EAAE,0BAA0B,EACzC,OAAO,GAAE,oBAAyB,GAChC,OAAO,CAAC,aAAa,CAAC,CASxB;IAEK,MAAM,CAAC,OAAO,EAAE,0BAA0B,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"]}
|
|
@@ -0,0 +1,340 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,CAAC;AA0BzB,MAAM,0BAA2B,SAAQ,KAAK;IAC7C,cAAc;QACb,KAAK,CAAC,4BAA4B,CAAC,CAAC;QACpC,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;IAAA,CACzC;CACD;AAED,KAAK,UAAU,2BAA2B,CAAC,OAAiC,EAAiB;IAC5F,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAClD,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CACzC,MAAM,CAAC,MAAM,KAAK,UAAU,IAAI,CAAC,CAAC,MAAM,CAAC,MAAM,YAAY,0BAA0B,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAC7G,CAAC;IACF,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,MAAM,CAAC,CAAC,CAAC,CAAC;IACzC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;QAAE,MAAM,IAAI,cAAc,CAAC,MAAM,EAAE,kCAAkC,CAAC,CAAC;AAAA,CAC5F;AAED,MAAM,OAAO,aAAa;IAChB,OAAO,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O,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"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SessionSnapshot, TranscriptItem, TranscriptProgress } from "@earendil-works/pi-protocol";
|
|
2
|
+
export interface TranscriptState {
|
|
3
|
+
readonly snapshot: SessionSnapshot;
|
|
4
|
+
readonly progressItems: ReadonlyMap<string, TranscriptItem>;
|
|
5
|
+
readonly progressOrder: readonly string[];
|
|
6
|
+
readonly toolCallBuffers: ReadonlyMap<string, string>;
|
|
7
|
+
}
|
|
8
|
+
export declare function createTranscriptState(snapshot: SessionSnapshot): TranscriptState;
|
|
9
|
+
export declare function applyTranscriptSnapshot(state: TranscriptState, snapshot: SessionSnapshot): TranscriptState;
|
|
10
|
+
export declare function applyTranscriptProgress(state: TranscriptState, progress: TranscriptProgress): TranscriptState;
|
|
11
|
+
export declare function selectTranscript(state: TranscriptState): readonly TranscriptItem[];
|
|
12
|
+
//# sourceMappingURL=transcript.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transcript.d.ts","sourceRoot":"","sources":["../../src/client/transcript.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,eAAe,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAElH,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC;IACnC,QAAQ,CAAC,aAAa,EAAE,WAAW,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAC5D,QAAQ,CAAC,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1C,QAAQ,CAAC,eAAe,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtD;AAoBD,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,eAAe,GAAG,eAAe,CAOhF;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,eAAe,GAAG,eAAe,CAG1G;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,kBAAkB,GAAG,eAAe,CAiC7G;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,eAAe,GAAG,SAAS,cAAc,EAAE,CAiBlF","sourcesContent":["import type { JsonValue, SessionSnapshot, TranscriptItem, TranscriptProgress } from \"@earendil-works/pi-protocol\";\n\nexport interface TranscriptState {\n\treadonly snapshot: SessionSnapshot;\n\treadonly progressItems: ReadonlyMap<string, TranscriptItem>;\n\treadonly progressOrder: readonly string[];\n\treadonly toolCallBuffers: ReadonlyMap<string, string>;\n}\n\nfunction isJsonValue(value: unknown): value is JsonValue {\n\tif (value === null || typeof value === \"boolean\" || typeof value === \"string\") return true;\n\tif (typeof value === \"number\") return Number.isFinite(value);\n\tif (Array.isArray(value)) return value.every(isJsonValue);\n\tif (typeof value !== \"object\" || Object.getPrototypeOf(value) !== Object.prototype) return false;\n\treturn Object.values(value).every(isJsonValue);\n}\n\nfunction parsePartialToolInput(value: string): JsonValue {\n\ttry {\n\t\tconst parsed: unknown = JSON.parse(value);\n\t\tif (isJsonValue(parsed)) return parsed;\n\t} catch {\n\t\t// Tool arguments are incomplete while streaming. Preserve their raw prefix until they form valid JSON.\n\t}\n\treturn value;\n}\n\nexport function createTranscriptState(snapshot: SessionSnapshot): TranscriptState {\n\treturn {\n\t\tsnapshot: structuredClone(snapshot),\n\t\tprogressItems: new Map(),\n\t\tprogressOrder: [],\n\t\ttoolCallBuffers: new Map(),\n\t};\n}\n\nexport function applyTranscriptSnapshot(state: TranscriptState, snapshot: SessionSnapshot): TranscriptState {\n\tif (state.snapshot.id === snapshot.id && snapshot.revision < state.snapshot.revision) return state;\n\treturn createTranscriptState(snapshot);\n}\n\nexport function applyTranscriptProgress(state: TranscriptState, progress: TranscriptProgress): TranscriptState {\n\tif (progress.type === \"item_started\" || progress.type === \"item_updated\") {\n\t\treturn setProgressItem(state, progress.item);\n\t}\n\tif (progress.type === \"item_finished\") {\n\t\tconst toolCallBuffers = new Map(state.toolCallBuffers);\n\t\tfor (const key of toolCallBuffers.keys()) {\n\t\t\tif (key.startsWith(`${progress.item.id}:`)) toolCallBuffers.delete(key);\n\t\t}\n\t\treturn setProgressItem({ ...state, toolCallBuffers }, progress.item);\n\t}\n\n\tconst item =\n\t\tstate.progressItems.get(progress.messageId) ??\n\t\tstate.snapshot.transcript.find(({ id }) => id === progress.messageId);\n\tif (!item || item.role !== \"assistant\") return state;\n\tlet toolCallBuffers = state.toolCallBuffers;\n\tconst content = item.content.map((part, index) => {\n\t\tif (index !== progress.contentIndex) return structuredClone(part);\n\t\tif (progress.kind === \"text\" && part.type === \"text\") return { ...part, text: part.text + progress.delta };\n\t\tif (progress.kind === \"thinking\" && part.type === \"thinking\") {\n\t\t\treturn { ...part, thinking: part.thinking + progress.delta };\n\t\t}\n\t\tif (progress.kind === \"toolCall\" && part.type === \"toolCall\") {\n\t\t\tconst key = `${progress.messageId}:${progress.contentIndex}`;\n\t\t\tconst existing = state.toolCallBuffers.get(key) ?? (typeof part.input === \"string\" ? part.input : \"\");\n\t\t\tconst buffer = existing + progress.delta;\n\t\t\ttoolCallBuffers = new Map(state.toolCallBuffers).set(key, buffer);\n\t\t\treturn { ...part, input: parsePartialToolInput(buffer) };\n\t\t}\n\t\treturn structuredClone(part);\n\t});\n\treturn setProgressItem({ ...state, toolCallBuffers }, { ...item, content });\n}\n\nexport function selectTranscript(state: TranscriptState): readonly TranscriptItem[] {\n\tconst transcript = state.snapshot.transcript.map((item) => state.progressItems.get(item.id) ?? item);\n\tconst ids = new Set(transcript.map((item) => item.id));\n\tfor (const id of state.progressOrder) {\n\t\tif (ids.has(id)) continue;\n\t\tconst item = state.progressItems.get(id);\n\t\tif (item) {\n\t\t\ttranscript.push(item);\n\t\t\tids.add(id);\n\t\t}\n\t}\n\tfor (const item of state.snapshot.queuedSteer) {\n\t\tif (ids.has(item.id)) continue;\n\t\ttranscript.push(item);\n\t\tids.add(item.id);\n\t}\n\treturn transcript;\n}\n\nfunction setProgressItem(state: TranscriptState, item: TranscriptItem): TranscriptState {\n\tconst progressItems = new Map(state.progressItems);\n\tconst progressOrder = progressItems.has(item.id) ? state.progressOrder : [...state.progressOrder, item.id];\n\tprogressItems.set(item.id, structuredClone(item));\n\treturn { ...state, progressItems, progressOrder };\n}\n"]}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
function isJsonValue(value) {
|
|
2
|
+
if (value === null || typeof value === "boolean" || typeof value === "string")
|
|
3
|
+
return true;
|
|
4
|
+
if (typeof value === "number")
|
|
5
|
+
return Number.isFinite(value);
|
|
6
|
+
if (Array.isArray(value))
|
|
7
|
+
return value.every(isJsonValue);
|
|
8
|
+
if (typeof value !== "object" || Object.getPrototypeOf(value) !== Object.prototype)
|
|
9
|
+
return false;
|
|
10
|
+
return Object.values(value).every(isJsonValue);
|
|
11
|
+
}
|
|
12
|
+
function parsePartialToolInput(value) {
|
|
13
|
+
try {
|
|
14
|
+
const parsed = JSON.parse(value);
|
|
15
|
+
if (isJsonValue(parsed))
|
|
16
|
+
return parsed;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
// Tool arguments are incomplete while streaming. Preserve their raw prefix until they form valid JSON.
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
export function createTranscriptState(snapshot) {
|
|
24
|
+
return {
|
|
25
|
+
snapshot: structuredClone(snapshot),
|
|
26
|
+
progressItems: new Map(),
|
|
27
|
+
progressOrder: [],
|
|
28
|
+
toolCallBuffers: new Map(),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export function applyTranscriptSnapshot(state, snapshot) {
|
|
32
|
+
if (state.snapshot.id === snapshot.id && snapshot.revision < state.snapshot.revision)
|
|
33
|
+
return state;
|
|
34
|
+
return createTranscriptState(snapshot);
|
|
35
|
+
}
|
|
36
|
+
export function applyTranscriptProgress(state, progress) {
|
|
37
|
+
if (progress.type === "item_started" || progress.type === "item_updated") {
|
|
38
|
+
return setProgressItem(state, progress.item);
|
|
39
|
+
}
|
|
40
|
+
if (progress.type === "item_finished") {
|
|
41
|
+
const toolCallBuffers = new Map(state.toolCallBuffers);
|
|
42
|
+
for (const key of toolCallBuffers.keys()) {
|
|
43
|
+
if (key.startsWith(`${progress.item.id}:`))
|
|
44
|
+
toolCallBuffers.delete(key);
|
|
45
|
+
}
|
|
46
|
+
return setProgressItem({ ...state, toolCallBuffers }, progress.item);
|
|
47
|
+
}
|
|
48
|
+
const item = state.progressItems.get(progress.messageId) ??
|
|
49
|
+
state.snapshot.transcript.find(({ id }) => id === progress.messageId);
|
|
50
|
+
if (!item || item.role !== "assistant")
|
|
51
|
+
return state;
|
|
52
|
+
let toolCallBuffers = state.toolCallBuffers;
|
|
53
|
+
const content = item.content.map((part, index) => {
|
|
54
|
+
if (index !== progress.contentIndex)
|
|
55
|
+
return structuredClone(part);
|
|
56
|
+
if (progress.kind === "text" && part.type === "text")
|
|
57
|
+
return { ...part, text: part.text + progress.delta };
|
|
58
|
+
if (progress.kind === "thinking" && part.type === "thinking") {
|
|
59
|
+
return { ...part, thinking: part.thinking + progress.delta };
|
|
60
|
+
}
|
|
61
|
+
if (progress.kind === "toolCall" && part.type === "toolCall") {
|
|
62
|
+
const key = `${progress.messageId}:${progress.contentIndex}`;
|
|
63
|
+
const existing = state.toolCallBuffers.get(key) ?? (typeof part.input === "string" ? part.input : "");
|
|
64
|
+
const buffer = existing + progress.delta;
|
|
65
|
+
toolCallBuffers = new Map(state.toolCallBuffers).set(key, buffer);
|
|
66
|
+
return { ...part, input: parsePartialToolInput(buffer) };
|
|
67
|
+
}
|
|
68
|
+
return structuredClone(part);
|
|
69
|
+
});
|
|
70
|
+
return setProgressItem({ ...state, toolCallBuffers }, { ...item, content });
|
|
71
|
+
}
|
|
72
|
+
export function selectTranscript(state) {
|
|
73
|
+
const transcript = state.snapshot.transcript.map((item) => state.progressItems.get(item.id) ?? item);
|
|
74
|
+
const ids = new Set(transcript.map((item) => item.id));
|
|
75
|
+
for (const id of state.progressOrder) {
|
|
76
|
+
if (ids.has(id))
|
|
77
|
+
continue;
|
|
78
|
+
const item = state.progressItems.get(id);
|
|
79
|
+
if (item) {
|
|
80
|
+
transcript.push(item);
|
|
81
|
+
ids.add(id);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
for (const item of state.snapshot.queuedSteer) {
|
|
85
|
+
if (ids.has(item.id))
|
|
86
|
+
continue;
|
|
87
|
+
transcript.push(item);
|
|
88
|
+
ids.add(item.id);
|
|
89
|
+
}
|
|
90
|
+
return transcript;
|
|
91
|
+
}
|
|
92
|
+
function setProgressItem(state, item) {
|
|
93
|
+
const progressItems = new Map(state.progressItems);
|
|
94
|
+
const progressOrder = progressItems.has(item.id) ? state.progressOrder : [...state.progressOrder, item.id];
|
|
95
|
+
progressItems.set(item.id, structuredClone(item));
|
|
96
|
+
return { ...state, progressItems, progressOrder };
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=transcript.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transcript.js","sourceRoot":"","sources":["../../src/client/transcript.ts"],"names":[],"mappings":"AASA,SAAS,WAAW,CAAC,KAAc,EAAsB;IACxD,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,SAAS,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC3F,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC7D,IAAI,KAAK,CAAC,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AAC,IAAI,CAAC,CAAC,CAAC;IAClD,OAAO,EAAE,GAAG,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,CAAC;AAAA,CAClD","sourcesContent":["import type { JsonValue, SessionSnapshot, TranscriptItem, TranscriptProgress } from \"@earendil-works/pi-protocol\";\n\nexport interface TranscriptState {\n\treadonly snapshot: SessionSnapshot;\n\treadonly progressItems: ReadonlyMap<string, TranscriptItem>;\n\treadonly progressOrder: readonly string[];\n\treadonly toolCallBuffers: ReadonlyMap<string, string>;\n}\n\nfunction isJsonValue(value: unknown): value is JsonValue {\n\tif (value === null || typeof value === \"boolean\" || typeof value === \"string\") return true;\n\tif (typeof value === \"number\") return Number.isFinite(value);\n\tif (Array.isArray(value)) return value.every(isJsonValue);\n\tif (typeof value !== \"object\" || Object.getPrototypeOf(value) !== Object.prototype) return false;\n\treturn Object.values(value).every(isJsonValue);\n}\n\nfunction parsePartialToolInput(value: string): JsonValue {\n\ttry {\n\t\tconst parsed: unknown = JSON.parse(value);\n\t\tif (isJsonValue(parsed)) return parsed;\n\t} catch {\n\t\t// Tool arguments are incomplete while streaming. Preserve their raw prefix until they form valid JSON.\n\t}\n\treturn value;\n}\n\nexport function createTranscriptState(snapshot: SessionSnapshot): TranscriptState {\n\treturn {\n\t\tsnapshot: structuredClone(snapshot),\n\t\tprogressItems: new Map(),\n\t\tprogressOrder: [],\n\t\ttoolCallBuffers: new Map(),\n\t};\n}\n\nexport function applyTranscriptSnapshot(state: TranscriptState, snapshot: SessionSnapshot): TranscriptState {\n\tif (state.snapshot.id === snapshot.id && snapshot.revision < state.snapshot.revision) return state;\n\treturn createTranscriptState(snapshot);\n}\n\nexport function applyTranscriptProgress(state: TranscriptState, progress: TranscriptProgress): TranscriptState {\n\tif (progress.type === \"item_started\" || progress.type === \"item_updated\") {\n\t\treturn setProgressItem(state, progress.item);\n\t}\n\tif (progress.type === \"item_finished\") {\n\t\tconst toolCallBuffers = new Map(state.toolCallBuffers);\n\t\tfor (const key of toolCallBuffers.keys()) {\n\t\t\tif (key.startsWith(`${progress.item.id}:`)) toolCallBuffers.delete(key);\n\t\t}\n\t\treturn setProgressItem({ ...state, toolCallBuffers }, progress.item);\n\t}\n\n\tconst item =\n\t\tstate.progressItems.get(progress.messageId) ??\n\t\tstate.snapshot.transcript.find(({ id }) => id === progress.messageId);\n\tif (!item || item.role !== \"assistant\") return state;\n\tlet toolCallBuffers = state.toolCallBuffers;\n\tconst content = item.content.map((part, index) => {\n\t\tif (index !== progress.contentIndex) return structuredClone(part);\n\t\tif (progress.kind === \"text\" && part.type === \"text\") return { ...part, text: part.text + progress.delta };\n\t\tif (progress.kind === \"thinking\" && part.type === \"thinking\") {\n\t\t\treturn { ...part, thinking: part.thinking + progress.delta };\n\t\t}\n\t\tif (progress.kind === \"toolCall\" && part.type === \"toolCall\") {\n\t\t\tconst key = `${progress.messageId}:${progress.contentIndex}`;\n\t\t\tconst existing = state.toolCallBuffers.get(key) ?? (typeof part.input === \"string\" ? part.input : \"\");\n\t\t\tconst buffer = existing + progress.delta;\n\t\t\ttoolCallBuffers = new Map(state.toolCallBuffers).set(key, buffer);\n\t\t\treturn { ...part, input: parsePartialToolInput(buffer) };\n\t\t}\n\t\treturn structuredClone(part);\n\t});\n\treturn setProgressItem({ ...state, toolCallBuffers }, { ...item, content });\n}\n\nexport function selectTranscript(state: TranscriptState): readonly TranscriptItem[] {\n\tconst transcript = state.snapshot.transcript.map((item) => state.progressItems.get(item.id) ?? item);\n\tconst ids = new Set(transcript.map((item) => item.id));\n\tfor (const id of state.progressOrder) {\n\t\tif (ids.has(id)) continue;\n\t\tconst item = state.progressItems.get(id);\n\t\tif (item) {\n\t\t\ttranscript.push(item);\n\t\t\tids.add(id);\n\t\t}\n\t}\n\tfor (const item of state.snapshot.queuedSteer) {\n\t\tif (ids.has(item.id)) continue;\n\t\ttranscript.push(item);\n\t\tids.add(item.id);\n\t}\n\treturn transcript;\n}\n\nfunction setProgressItem(state: TranscriptState, item: TranscriptItem): TranscriptState {\n\tconst progressItems = new Map(state.progressItems);\n\tconst progressOrder = progressItems.has(item.id) ? state.progressOrder : [...state.progressOrder, item.id];\n\tprogressItems.set(item.id, structuredClone(item));\n\treturn { ...state, progressItems, progressOrder };\n}\n"]}
|