pi-namespace-patch 0.87.1-namespace.1 → 1.0.0-namespace.2
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 +183 -0
- package/README.md +100 -25
- package/dist/bun/cli.d.ts.map +1 -1
- package/dist/bun/restore-sandbox-env.d.ts.map +1 -1
- package/dist/bun/restore-sandbox-env.js.map +1 -1
- package/dist/bun/runtime-setup.d.ts.map +1 -1
- package/dist/bun/runtime-setup.js +4 -1
- package/dist/bun/runtime-setup.js.map +1 -1
- package/dist/bun/sandbox-env-setup.d.ts.map +1 -1
- package/dist/bundle/chunks/anthropic-messages-UID2PALB.js +6 -0
- package/dist/bundle/chunks/anthropic.js +2 -2
- package/dist/bundle/chunks/azure-openai-responses-AFMVM6NP.js +2 -0
- package/dist/bundle/chunks/bedrock-converse-stream.js +2 -2
- package/dist/bundle/chunks/chunk-2KTBZM5G.js +132 -0
- package/dist/bundle/chunks/{chunk-WIUZI2CJ.js → chunk-2VNGUWBO.js} +3 -3
- package/dist/bundle/chunks/{chunk-FUXEF6JQ.js → chunk-3LH3ZQKY.js} +1 -1
- package/dist/bundle/chunks/chunk-4N5K4RKC.js +1204 -0
- package/dist/bundle/chunks/chunk-6D7LHLKG.js +2 -0
- package/dist/bundle/chunks/chunk-7FH3BDRG.js +82 -0
- package/dist/bundle/chunks/chunk-7JGR3GZN.js +11 -0
- package/dist/bundle/chunks/chunk-H3QXYIF7.js +31 -0
- package/dist/bundle/chunks/chunk-IBCPYVFK.js +19 -0
- package/dist/bundle/chunks/chunk-KDN6RCEQ.js +4 -0
- package/dist/bundle/chunks/chunk-LD2P6SFZ.js +2 -0
- package/dist/bundle/chunks/chunk-LTXEMVMA.js +127 -0
- package/dist/bundle/chunks/chunk-MJOHEBV7.js +2 -0
- package/dist/bundle/chunks/chunk-OSKPX3Z5.js +2 -0
- package/dist/bundle/chunks/chunk-PRD6WYBT.js +16 -0
- package/dist/bundle/chunks/{chunk-XDUWOHPL.js → chunk-S3GGRYIO.js} +2 -2
- package/dist/bundle/chunks/chunk-UTB4DTYQ.js +2 -0
- package/dist/bundle/chunks/chunk-VIV3CWXG.js +2 -0
- package/dist/bundle/chunks/cli-QOMC26IJ.js +51 -0
- package/dist/bundle/chunks/cloudflare-workers-ai-system-one-NPQN263E.js +2 -0
- package/dist/bundle/chunks/codemode-worker.js +354 -0
- package/dist/bundle/chunks/execute-GVRSEGHL.js +367 -0
- package/dist/bundle/chunks/github-copilot.js +1 -1
- package/dist/bundle/chunks/google-generative-ai-APTPZOQL.js +2 -0
- package/dist/bundle/chunks/google-vertex-MXCOSOY3.js +2 -0
- package/dist/bundle/chunks/{lib-HGQMNYVT.js → lib-TEDK3E5I.js} +2 -2
- package/dist/bundle/chunks/llama-cpp-classify-XT44PI3C.js +22 -0
- package/dist/bundle/chunks/mistral-conversations-DKVFNQL6.js +5 -0
- package/dist/bundle/chunks/openai-chatgpt.js +75 -0
- package/dist/bundle/chunks/{openai-codex-responses-QDSOTBBO.js → openai-codex-responses-GK67DQQJ.js} +2 -2
- package/dist/bundle/chunks/openai-codex.js +2 -2
- package/dist/bundle/chunks/{openai-completions-OBX42CLD.js → openai-completions-JXDDPZ23.js} +2 -2
- package/dist/bundle/chunks/openai-responses-CQDDLDQF.js +3 -0
- package/dist/bundle/chunks/{openrouter-images-N4XVVFSD.js → openrouter-images-ZVXWCSIM.js} +1 -1
- package/dist/bundle/chunks/openrouter.js +2 -2
- package/dist/bundle/chunks/pi-logo-animation-MPKZE4EK.js +2 -0
- package/dist/bundle/chunks/{pi-messages-GFKBWJHZ.js → pi-messages-TM5SOOIW.js} +2 -2
- package/dist/bundle/chunks/radius.js +2 -2
- package/dist/bundle/chunks/runtime-2SO2JDWM.js +2 -0
- package/dist/bundle/chunks/typesafe-system-one-A4CZTQWZ.js +2 -0
- package/dist/bundle/chunks/virtual-modules-3THEGRQQ.js +2 -0
- package/dist/bundle/cli-runtime.js +1 -1
- package/dist/bundle/index.js +1 -1
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +6 -5
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/auth-check.d.ts.map +1 -1
- package/dist/cli/auth-check.js.map +1 -1
- package/dist/cli/auth-command.d.ts.map +1 -1
- package/dist/cli/auth-command.js.map +1 -1
- package/dist/cli/config-selector.d.ts.map +1 -1
- package/dist/cli/config-selector.js.map +1 -1
- package/dist/cli/credential-print.d.ts.map +1 -1
- package/dist/cli/credential-print.js.map +1 -1
- package/dist/cli/file-processor.d.ts.map +1 -1
- package/dist/cli/file-processor.js.map +1 -1
- package/dist/cli/initial-message.d.ts +1 -1
- package/dist/cli/initial-message.d.ts.map +1 -1
- package/dist/cli/initial-message.js.map +1 -1
- package/dist/cli/list-models.d.ts.map +1 -1
- package/dist/cli/list-models.js.map +1 -1
- package/dist/cli/project-trust.d.ts.map +1 -1
- package/dist/cli/project-trust.js.map +1 -1
- package/dist/cli/session-picker.d.ts.map +1 -1
- package/dist/cli/session-picker.js.map +1 -1
- package/dist/cli/setup.d.ts.map +1 -1
- package/dist/cli/setup.js.map +1 -1
- package/dist/cli/startup-ui.d.ts.map +1 -1
- package/dist/cli/startup-ui.js +38 -30
- package/dist/cli/startup-ui.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/config.d.ts +15 -4
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +33 -4
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +1 -1
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +13 -0
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +150 -12
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +560 -263
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-guidance.d.ts.map +1 -1
- package/dist/core/auth-guidance.js.map +1 -1
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/bug-report-upload.d.ts.map +1 -1
- package/dist/core/bug-report-upload.js.map +1 -1
- package/dist/core/bug-report.d.ts +1 -1
- package/dist/core/bug-report.d.ts.map +1 -1
- package/dist/core/bug-report.js +1 -1
- package/dist/core/bug-report.js.map +1 -1
- package/dist/core/cache-stats.d.ts.map +1 -1
- package/dist/core/cache-stats.js.map +1 -1
- package/dist/core/cache-warmer.d.ts.map +1 -1
- package/dist/core/cache-warmer.js.map +1 -1
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +1 -22
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/compaction/index.d.ts.map +1 -1
- package/dist/core/compaction/utils.d.ts +2 -1
- package/dist/core/compaction/utils.d.ts.map +1 -1
- package/dist/core/compaction/utils.js +25 -18
- package/dist/core/compaction/utils.js.map +1 -1
- package/dist/core/crash-log.d.ts.map +1 -1
- package/dist/core/crash-log.js +2 -1
- package/dist/core/crash-log.js.map +1 -1
- package/dist/core/defaults.d.ts.map +1 -1
- package/dist/core/diagnostics.d.ts.map +1 -1
- package/dist/core/event-bus.d.ts.map +1 -1
- package/dist/core/event-bus.js.map +1 -1
- package/dist/core/exec.d.ts.map +1 -1
- package/dist/core/exec.js.map +1 -1
- package/dist/core/experimental.d.ts.map +1 -1
- package/dist/core/experimental.js.map +1 -1
- package/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
- package/dist/core/export-html/ansi-to-html.js.map +1 -1
- package/dist/core/export-html/index.d.ts.map +1 -1
- package/dist/core/export-html/index.js.map +1 -1
- package/dist/core/export-html/template.css +10 -0
- package/dist/core/export-html/template.js +66 -17
- package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
- package/dist/core/export-html/tool-renderer.js.map +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/jiti-loader.d.ts.map +1 -1
- package/dist/core/extensions/jiti-static-loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +67 -5
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +18 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +99 -0
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +301 -22
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/extensions/virtual-modules.d.ts.map +1 -1
- package/dist/core/extensions/wrapper.d.ts +2 -2
- package/dist/core/extensions/wrapper.d.ts.map +1 -1
- package/dist/core/extensions/wrapper.js +3 -3
- package/dist/core/extensions/wrapper.js.map +1 -1
- package/dist/core/footer-data-provider.d.ts.map +1 -1
- package/dist/core/footer-data-provider.js.map +1 -1
- package/dist/core/http-dispatcher.d.ts.map +1 -1
- package/dist/core/http-dispatcher.js.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/keybindings.d.ts +1 -1
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +1 -1
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/mcp-servers.d.ts +125 -0
- package/dist/core/mcp-servers.d.ts.map +1 -0
- package/dist/core/mcp-servers.js +198 -0
- package/dist/core/mcp-servers.js.map +1 -0
- package/dist/core/messages.d.ts.map +1 -1
- package/dist/core/messages.js.map +1 -1
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/model-registry.d.ts +15 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +29 -0
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts +2 -2
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +5 -5
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-runtime.d.ts +47 -3
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +189 -35
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/models-store.d.ts.map +1 -1
- package/dist/core/models-store.js.map +1 -1
- package/dist/core/nested-tool-calls.d.ts +102 -0
- package/dist/core/nested-tool-calls.d.ts.map +1 -0
- package/dist/core/nested-tool-calls.js +178 -0
- package/dist/core/nested-tool-calls.js.map +1 -0
- package/dist/core/output-guard.d.ts.map +1 -1
- package/dist/core/output-guard.js.map +1 -1
- package/dist/core/package-manager.d.ts +4 -0
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +59 -12
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/pi-manifest.d.ts.map +1 -1
- package/dist/core/pi-manifest.js.map +1 -1
- package/dist/core/project-trust.d.ts.map +1 -1
- package/dist/core/project-trust.js.map +1 -1
- package/dist/core/prompt-templates.d.ts.map +1 -1
- package/dist/core/prompt-templates.js.map +1 -1
- package/dist/core/provider-attribution.d.ts.map +1 -1
- package/dist/core/provider-attribution.js.map +1 -1
- package/dist/core/provider-composer.d.ts +40 -21
- package/dist/core/provider-composer.d.ts.map +1 -1
- package/dist/core/provider-composer.js +92 -40
- package/dist/core/provider-composer.js.map +1 -1
- package/dist/core/radius.d.ts +2 -0
- package/dist/core/radius.d.ts.map +1 -1
- package/dist/core/radius.js +2 -0
- package/dist/core/radius.js.map +1 -1
- package/dist/core/remote-catalog-provider.d.ts +8 -1
- package/dist/core/remote-catalog-provider.d.ts.map +1 -1
- package/dist/core/remote-catalog-provider.js +21 -11
- package/dist/core/remote-catalog-provider.js.map +1 -1
- package/dist/core/resolve-config-value.d.ts.map +1 -1
- package/dist/core/resolve-config-value.js.map +1 -1
- package/dist/core/resource-loader.d.ts +7 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +161 -35
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/runtime-credentials.d.ts.map +1 -1
- package/dist/core/runtime-credentials.js.map +1 -1
- package/dist/core/sdk.d.ts +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +25 -6
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-cwd.d.ts.map +1 -1
- package/dist/core/session-cwd.js.map +1 -1
- package/dist/core/session-export.d.ts.map +1 -1
- package/dist/core/session-export.js.map +1 -1
- package/dist/core/session-manager.d.ts +9 -0
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +22 -22
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-diagnostics.d.ts.map +1 -1
- package/dist/core/settings-diagnostics.js.map +1 -1
- package/dist/core/settings-manager.d.ts +36 -4
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +75 -4
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/source-info.d.ts +8 -0
- package/dist/core/source-info.d.ts.map +1 -1
- package/dist/core/source-info.js +16 -0
- package/dist/core/source-info.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +1 -1
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/telemetry.d.ts.map +1 -1
- package/dist/core/telemetry.js.map +1 -1
- package/dist/core/timings.d.ts.map +1 -1
- package/dist/core/timings.js.map +1 -1
- package/dist/core/tools/bash.d.ts +12 -0
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +33 -2
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit-diff.d.ts.map +1 -1
- package/dist/core/tools/edit-diff.js.map +1 -1
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
- package/dist/core/tools/file-mutation-queue.js.map +1 -1
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/core/tools/output-accumulator.d.ts +11 -0
- package/dist/core/tools/output-accumulator.d.ts.map +1 -1
- package/dist/core/tools/output-accumulator.js +36 -0
- package/dist/core/tools/output-accumulator.js.map +1 -1
- package/dist/core/tools/path-utils.d.ts.map +1 -1
- package/dist/core/tools/path-utils.js.map +1 -1
- package/dist/core/tools/powershell.d.ts.map +1 -1
- package/dist/core/tools/powershell.js.map +1 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/render-utils.d.ts +6 -0
- package/dist/core/tools/render-utils.d.ts.map +1 -1
- package/dist/core/tools/render-utils.js +26 -0
- package/dist/core/tools/render-utils.js.map +1 -1
- package/dist/core/tools/renderers/bash.d.ts.map +1 -1
- package/dist/core/tools/renderers/bash.js +11 -32
- package/dist/core/tools/renderers/bash.js.map +1 -1
- package/dist/core/tools/renderers/edit.d.ts.map +1 -1
- package/dist/core/tools/renderers/edit.js.map +1 -1
- package/dist/core/tools/renderers/find.d.ts.map +1 -1
- package/dist/core/tools/renderers/find.js.map +1 -1
- package/dist/core/tools/renderers/grep.d.ts.map +1 -1
- package/dist/core/tools/renderers/grep.js.map +1 -1
- package/dist/core/tools/renderers/index.d.ts.map +1 -1
- package/dist/core/tools/renderers/index.js.map +1 -1
- package/dist/core/tools/renderers/ls.d.ts.map +1 -1
- package/dist/core/tools/renderers/ls.js.map +1 -1
- package/dist/core/tools/renderers/read.d.ts.map +1 -1
- package/dist/core/tools/renderers/read.js +3 -2
- package/dist/core/tools/renderers/read.js.map +1 -1
- package/dist/core/tools/renderers/write.d.ts.map +1 -1
- package/dist/core/tools/renderers/write.js.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.d.ts +5 -3
- package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.js +3 -1
- package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
- package/dist/core/tools/truncate.d.ts +14 -0
- package/dist/core/tools/truncate.d.ts.map +1 -1
- package/dist/core/tools/truncate.js +29 -0
- package/dist/core/tools/truncate.js.map +1 -1
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js.map +1 -1
- package/dist/core/trust-manager.d.ts.map +1 -1
- package/dist/core/trust-manager.js +1 -0
- package/dist/core/trust-manager.js.map +1 -1
- package/dist/core/usage-totals.d.ts +2 -0
- package/dist/core/usage-totals.d.ts.map +1 -1
- package/dist/core/usage-totals.js +23 -0
- package/dist/core/usage-totals.js.map +1 -1
- package/dist/core/virtual-models.d.ts +117 -0
- package/dist/core/virtual-models.d.ts.map +1 -0
- package/dist/core/virtual-models.js +124 -0
- package/dist/core/virtual-models.js.map +1 -0
- package/dist/extensions/codemode/execute.d.ts +16 -0
- package/dist/extensions/codemode/execute.d.ts.map +1 -0
- package/dist/extensions/codemode/execute.js +536 -0
- package/dist/extensions/codemode/execute.js.map +1 -0
- package/dist/extensions/codemode/execute.lazy.d.ts +3 -0
- package/dist/extensions/codemode/execute.lazy.d.ts.map +1 -0
- package/dist/extensions/codemode/execute.lazy.js +3 -0
- package/dist/extensions/codemode/execute.lazy.js.map +1 -0
- package/dist/extensions/codemode/index.d.ts +21 -0
- package/dist/extensions/codemode/index.d.ts.map +1 -0
- package/dist/extensions/codemode/index.js +31 -0
- package/dist/extensions/codemode/index.js.map +1 -0
- package/dist/extensions/codemode/renderer.d.ts +12 -0
- package/dist/extensions/codemode/renderer.d.ts.map +1 -0
- package/dist/extensions/codemode/renderer.js +137 -0
- package/dist/extensions/codemode/renderer.js.map +1 -0
- package/dist/extensions/codemode/tool.d.ts +123 -0
- package/dist/extensions/codemode/tool.d.ts.map +1 -0
- package/dist/extensions/codemode/tool.js +268 -0
- package/dist/extensions/codemode/tool.js.map +1 -0
- package/dist/extensions/codemode/worker.d.ts +7 -0
- package/dist/extensions/codemode/worker.d.ts.map +1 -0
- package/dist/extensions/codemode/worker.js +7 -0
- package/dist/extensions/codemode/worker.js.map +1 -0
- package/dist/extensions/index.d.ts.map +1 -1
- package/dist/extensions/index.js +11 -1
- package/dist/extensions/index.js.map +1 -1
- package/dist/extensions/llama/client.d.ts.map +1 -1
- package/dist/extensions/llama/client.js.map +1 -1
- package/dist/extensions/llama/huggingface.d.ts.map +1 -1
- package/dist/extensions/llama/huggingface.js.map +1 -1
- package/dist/extensions/llama/index.d.ts.map +1 -1
- package/dist/extensions/llama/index.js.map +1 -1
- package/dist/extensions/llama/provider.d.ts +1 -1
- package/dist/extensions/llama/provider.d.ts.map +1 -1
- package/dist/extensions/llama/provider.js +65 -13
- package/dist/extensions/llama/provider.js.map +1 -1
- package/dist/extensions/llama/ui.d.ts.map +1 -1
- package/dist/extensions/llama/ui.js.map +1 -1
- package/dist/extensions/mcp/cli.d.ts +21 -0
- package/dist/extensions/mcp/cli.d.ts.map +1 -0
- package/dist/extensions/mcp/cli.js +500 -0
- package/dist/extensions/mcp/cli.js.map +1 -0
- package/dist/extensions/mcp/cli.lazy.d.ts +3 -0
- package/dist/extensions/mcp/cli.lazy.d.ts.map +1 -0
- package/dist/extensions/mcp/cli.lazy.js +3 -0
- package/dist/extensions/mcp/cli.lazy.js.map +1 -0
- package/dist/extensions/mcp/config.d.ts +72 -0
- package/dist/extensions/mcp/config.d.ts.map +1 -0
- package/dist/extensions/mcp/config.js +158 -0
- package/dist/extensions/mcp/config.js.map +1 -0
- package/dist/extensions/mcp/index.d.ts +76 -0
- package/dist/extensions/mcp/index.d.ts.map +1 -0
- package/dist/extensions/mcp/index.js +1066 -0
- package/dist/extensions/mcp/index.js.map +1 -0
- package/dist/extensions/mcp/log.d.ts +16 -0
- package/dist/extensions/mcp/log.d.ts.map +1 -0
- package/dist/extensions/mcp/log.js +66 -0
- package/dist/extensions/mcp/log.js.map +1 -0
- package/dist/extensions/mcp/oauth.d.ts +97 -0
- package/dist/extensions/mcp/oauth.d.ts.map +1 -0
- package/dist/extensions/mcp/oauth.js +358 -0
- package/dist/extensions/mcp/oauth.js.map +1 -0
- package/dist/extensions/mcp/resources.d.ts +43 -0
- package/dist/extensions/mcp/resources.d.ts.map +1 -0
- package/dist/extensions/mcp/resources.js +262 -0
- package/dist/extensions/mcp/resources.js.map +1 -0
- package/dist/extensions/mcp/runtime.d.ts +98 -0
- package/dist/extensions/mcp/runtime.d.ts.map +1 -0
- package/dist/extensions/mcp/runtime.js +395 -0
- package/dist/extensions/mcp/runtime.js.map +1 -0
- package/dist/extensions/mcp/runtime.lazy.d.ts +3 -0
- package/dist/extensions/mcp/runtime.lazy.d.ts.map +1 -0
- package/dist/extensions/mcp/runtime.lazy.js +3 -0
- package/dist/extensions/mcp/runtime.lazy.js.map +1 -0
- package/dist/extensions/mcp/tools.d.ts +84 -0
- package/dist/extensions/mcp/tools.d.ts.map +1 -0
- package/dist/extensions/mcp/tools.js +251 -0
- package/dist/extensions/mcp/tools.js.map +1 -0
- package/dist/extensions/mcp/ui.d.ts +60 -0
- package/dist/extensions/mcp/ui.d.ts.map +1 -0
- package/dist/extensions/mcp/ui.js +174 -0
- package/dist/extensions/mcp/ui.js.map +1 -0
- package/dist/extensions/tool-search/index.d.ts +12 -0
- package/dist/extensions/tool-search/index.d.ts.map +1 -0
- package/dist/extensions/tool-search/index.js +15 -0
- package/dist/extensions/tool-search/index.js.map +1 -0
- package/dist/extensions/tool-search/tool.d.ts +73 -0
- package/dist/extensions/tool-search/tool.d.ts.map +1 -0
- package/dist/extensions/tool-search/tool.js +189 -0
- package/dist/extensions/tool-search/tool.js.map +1 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +16 -0
- package/dist/main.js.map +1 -1
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js.map +1 -1
- package/dist/modes/index.d.ts.map +1 -1
- package/dist/modes/interactive/bug-report.d.ts.map +1 -1
- package/dist/modes/interactive/bug-report.js.map +1 -1
- package/dist/modes/interactive/chat-viewport.d.ts.map +1 -1
- package/dist/modes/interactive/chat-viewport.js.map +1 -1
- package/dist/modes/interactive/components/armin.d.ts.map +1 -1
- package/dist/modes/interactive/components/armin.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/bash-execution.js.map +1 -1
- package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -1
- package/dist/modes/interactive/components/bordered-loader.js.map +1 -1
- package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
- package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/config-selector.js +13 -3
- package/dist/modes/interactive/components/config-selector.js.map +1 -1
- package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -1
- package/dist/modes/interactive/components/countdown-timer.js.map +1 -1
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-editor.js.map +1 -1
- package/dist/modes/interactive/components/custom-entry.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-entry.js.map +1 -1
- package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-message.js.map +1 -1
- package/dist/modes/interactive/components/daxnuts.d.ts.map +1 -1
- package/dist/modes/interactive/components/daxnuts.js.map +1 -1
- package/dist/modes/interactive/components/diff.d.ts.map +1 -1
- package/dist/modes/interactive/components/diff.js.map +1 -1
- package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
- package/dist/modes/interactive/components/dynamic-border.js.map +1 -1
- package/dist/modes/interactive/components/earendil-announcement.d.ts.map +1 -1
- package/dist/modes/interactive/components/earendil-announcement.js.map +1 -1
- package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-editor.js.map +1 -1
- package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-input.js.map +1 -1
- package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-selector.js.map +1 -1
- package/dist/modes/interactive/components/first-time-setup.d.ts +4 -4
- package/dist/modes/interactive/components/first-time-setup.d.ts.map +1 -1
- package/dist/modes/interactive/components/first-time-setup.js +8 -2
- package/dist/modes/interactive/components/first-time-setup.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts +7 -0
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +43 -3
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/index.d.ts.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
- package/dist/modes/interactive/components/login-dialog.js.map +1 -1
- package/dist/modes/interactive/components/markdown-transform.d.ts.map +1 -1
- package/dist/modes/interactive/components/markdown-transform.js.map +1 -1
- package/dist/modes/interactive/components/mermaid.d.ts.map +1 -1
- package/dist/modes/interactive/components/mermaid.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.d.ts +8 -2
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.js +24 -21
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
- package/dist/modes/interactive/components/pi-logo-animation.d.ts +68 -0
- package/dist/modes/interactive/components/pi-logo-animation.d.ts.map +1 -0
- package/dist/modes/interactive/components/pi-logo-animation.js +1086 -0
- package/dist/modes/interactive/components/pi-logo-animation.js.map +1 -0
- package/dist/modes/interactive/components/pi-logo-animation.lazy.d.ts +7 -0
- package/dist/modes/interactive/components/pi-logo-animation.lazy.d.ts.map +1 -0
- package/dist/modes/interactive/components/pi-logo-animation.lazy.js +12 -0
- package/dist/modes/interactive/components/pi-logo-animation.lazy.js.map +1 -0
- package/dist/modes/interactive/components/pi-logo.d.ts +19 -0
- package/dist/modes/interactive/components/pi-logo.d.ts.map +1 -0
- package/dist/modes/interactive/components/pi-logo.js +37 -0
- package/dist/modes/interactive/components/pi-logo.js.map +1 -0
- package/dist/modes/interactive/components/radius-login-selector.d.ts +15 -0
- package/dist/modes/interactive/components/radius-login-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/radius-login-selector.js +85 -0
- package/dist/modes/interactive/components/radius-login-selector.js.map +1 -0
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
- package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector-search.js.map +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +6 -4
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +33 -11
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-submenu.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-submenu.js.map +1 -1
- package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/show-images-selector.js.map +1 -1
- package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
- package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -1
- package/dist/modes/interactive/components/status-indicator.js.map +1 -1
- package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/theme-selector.js.map +1 -1
- package/dist/modes/interactive/components/themed-text.d.ts +17 -0
- package/dist/modes/interactive/components/themed-text.d.ts.map +1 -0
- package/dist/modes/interactive/components/themed-text.js +29 -0
- package/dist/modes/interactive/components/themed-text.js.map +1 -0
- package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +2 -2
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector.js.map +1 -1
- package/dist/modes/interactive/components/trust-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/trust-selector.js.map +1 -1
- package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message-selector.js.map +1 -1
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message.js +5 -4
- package/dist/modes/interactive/components/user-message.js.map +1 -1
- package/dist/modes/interactive/components/visual-truncate.d.ts +27 -3
- package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -1
- package/dist/modes/interactive/components/visual-truncate.js +39 -6
- package/dist/modes/interactive/components/visual-truncate.js.map +1 -1
- package/dist/modes/interactive/external-editor.d.ts.map +1 -1
- package/dist/modes/interactive/external-editor.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +21 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +348 -197
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/model-catalog-refresh.d.ts.map +1 -1
- package/dist/modes/interactive/model-catalog-refresh.js.map +1 -1
- package/dist/modes/interactive/model-search.d.ts.map +1 -1
- package/dist/modes/interactive/model-search.js.map +1 -1
- package/dist/modes/interactive/session-share.d.ts.map +1 -1
- package/dist/modes/interactive/session-share.js.map +1 -1
- package/dist/modes/interactive/theme/dark.json +59 -72
- package/dist/modes/interactive/theme/light.json +57 -69
- package/dist/modes/interactive/theme/system-theme.d.ts +55 -0
- package/dist/modes/interactive/theme/system-theme.d.ts.map +1 -0
- package/dist/modes/interactive/theme/system-theme.js +546 -0
- package/dist/modes/interactive/theme/system-theme.js.map +1 -0
- package/dist/modes/interactive/theme/theme-controller.d.ts +46 -6
- package/dist/modes/interactive/theme/theme-controller.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme-controller.js +127 -47
- package/dist/modes/interactive/theme/theme-controller.js.map +1 -1
- package/dist/modes/interactive/theme/theme-json.d.ts +1 -0
- package/dist/modes/interactive/theme/theme-json.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme-json.js +3 -1
- package/dist/modes/interactive/theme/theme-json.js.map +1 -1
- package/dist/modes/interactive/theme/theme-schema.json +7 -2
- package/dist/modes/interactive/theme/theme.d.ts +66 -39
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +238 -317
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/modes/interactive/tui-renderer.d.ts +2 -1
- package/dist/modes/interactive/tui-renderer.d.ts.map +1 -1
- package/dist/modes/interactive/tui-renderer.js +1 -0
- package/dist/modes/interactive/tui-renderer.js.map +1 -1
- package/dist/modes/json-event.d.ts.map +1 -1
- package/dist/modes/json-event.js.map +1 -1
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/modes/rpc/jsonl.d.ts.map +1 -1
- package/dist/modes/rpc/jsonl.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +6 -6
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +12 -8
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +7 -9
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +10 -1
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +6 -2
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/rpc-entry.d.ts.map +1 -1
- package/dist/rpc-entry.js.map +1 -1
- package/dist/utils/abort.d.ts.map +1 -1
- package/dist/utils/abort.js.map +1 -1
- package/dist/utils/ansi.d.ts.map +1 -1
- package/dist/utils/ansi.js.map +1 -1
- package/dist/utils/changelog.d.ts.map +1 -1
- package/dist/utils/changelog.js.map +1 -1
- package/dist/utils/child-process.d.ts.map +1 -1
- package/dist/utils/child-process.js.map +1 -1
- package/dist/utils/clipboard-command.d.ts.map +1 -1
- package/dist/utils/clipboard-command.js.map +1 -1
- package/dist/utils/clipboard-image.d.ts.map +1 -1
- package/dist/utils/clipboard-image.js +14 -17
- package/dist/utils/clipboard-image.js.map +1 -1
- package/dist/utils/clipboard.d.ts +2 -0
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js +5 -0
- package/dist/utils/clipboard.js.map +1 -1
- package/dist/utils/deprecation.d.ts.map +1 -1
- package/dist/utils/deprecation.js.map +1 -1
- package/dist/utils/exif-orientation.d.ts.map +1 -1
- package/dist/utils/exif-orientation.js.map +1 -1
- package/dist/utils/frontmatter.d.ts.map +1 -1
- package/dist/utils/frontmatter.js.map +1 -1
- package/dist/utils/fs-watch.d.ts.map +1 -1
- package/dist/utils/fs-watch.js.map +1 -1
- package/dist/utils/git.d.ts.map +1 -1
- package/dist/utils/git.js.map +1 -1
- package/dist/utils/html.d.ts.map +1 -1
- package/dist/utils/html.js.map +1 -1
- package/dist/utils/image-convert.d.ts.map +1 -1
- package/dist/utils/image-convert.js.map +1 -1
- package/dist/utils/image-process.d.ts.map +1 -1
- package/dist/utils/image-process.js.map +1 -1
- package/dist/utils/image-resize-core.d.ts.map +1 -1
- package/dist/utils/image-resize-core.js.map +1 -1
- package/dist/utils/image-resize-worker.d.ts.map +1 -1
- package/dist/utils/image-resize-worker.js.map +1 -1
- package/dist/utils/image-resize.d.ts.map +1 -1
- package/dist/utils/image-resize.js.map +1 -1
- package/dist/utils/json.d.ts.map +1 -1
- package/dist/utils/json.js.map +1 -1
- package/dist/utils/management-http.d.ts.map +1 -1
- package/dist/utils/management-http.js.map +1 -1
- package/dist/utils/mime.d.ts.map +1 -1
- package/dist/utils/mime.js.map +1 -1
- package/dist/utils/open-browser.d.ts.map +1 -1
- package/dist/utils/open-browser.js.map +1 -1
- package/dist/utils/paths.d.ts +3 -3
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +5 -4
- package/dist/utils/paths.js.map +1 -1
- package/dist/utils/photon.d.ts.map +1 -1
- package/dist/utils/photon.js.map +1 -1
- package/dist/utils/pi-user-agent.d.ts.map +1 -1
- package/dist/utils/pi-user-agent.js.map +1 -1
- package/dist/utils/shell.d.ts +1 -3
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +3 -30
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/sleep.d.ts.map +1 -1
- package/dist/utils/sleep.js.map +1 -1
- package/dist/utils/syntax-highlight.d.ts.map +1 -1
- package/dist/utils/syntax-highlight.js +2 -0
- package/dist/utils/syntax-highlight.js.map +1 -1
- package/dist/utils/text.d.ts.map +1 -1
- package/dist/utils/text.js.map +1 -1
- package/dist/utils/tool-result-images.d.ts.map +1 -1
- package/dist/utils/tool-result-images.js.map +1 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js.map +1 -1
- package/dist/utils/version-check.d.ts.map +1 -1
- package/dist/utils/version-check.js.map +1 -1
- package/dist/utils/windows-self-update.d.ts.map +1 -1
- package/dist/utils/windows-self-update.js.map +1 -1
- package/dist/utils/wsl.d.ts.map +1 -1
- package/dist/utils/wsl.js.map +1 -1
- package/dist/utils/zip.d.ts.map +1 -1
- package/dist/utils/zip.js.map +1 -1
- package/docs/cli.md +58 -7
- package/docs/codemode.md +207 -0
- package/docs/configuration.md +2 -0
- package/docs/custom-provider.md +43 -4
- package/docs/docs.json +13 -1
- package/docs/environment-variables.md +2 -2
- package/docs/extensions.md +55 -0
- package/docs/index.md +1 -1
- package/docs/keybindings.md +1 -1
- package/docs/llama-cpp.md +13 -0
- package/docs/mcp.md +248 -0
- package/docs/models.md +57 -1
- package/docs/packages.md +4 -2
- package/docs/providers.md +19 -6
- package/docs/rpc-commands.md +9 -3
- package/docs/rpc.md +3 -1
- package/docs/sdk.md +8 -3
- package/docs/security.md +2 -0
- package/docs/session-format.md +5 -1
- package/docs/settings.md +24 -5
- package/docs/themes.md +33 -7
- package/docs/tui.md +18 -0
- package/docs/usage.md +1 -1
- package/docs/virtual-models.md +114 -0
- package/docs/windows.md +2 -0
- package/examples/README.md +1 -1
- package/examples/extensions/README.md +2 -0
- package/examples/extensions/built-in-tool-renderer.ts +16 -40
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/test.ts +5 -5
- package/examples/extensions/debug-provider.ts +90 -0
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/jev-router.ts +113 -0
- package/examples/extensions/minimal-mode.ts +24 -96
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/rpc-client.ts +1 -1
- package/examples/rpc-extension-ui.ts +1 -1
- package/examples/sdk/14-codemode-mcp.ts +61 -0
- package/examples/sdk/README.md +2 -1
- package/npm-shrinkwrap.json +88 -43
- package/package.json +14 -12
- package/dist/bundle/chunks/anthropic-messages-J5WXPPPC.js +0 -6
- package/dist/bundle/chunks/azure-openai-responses-HUSQ3GP2.js +0 -2
- package/dist/bundle/chunks/chunk-6R7UI4IY.js +0 -2
- package/dist/bundle/chunks/chunk-FN7P5NHX.js +0 -1568
- package/dist/bundle/chunks/chunk-NUHFSC37.js +0 -25
- package/dist/bundle/chunks/chunk-RCZIEVGO.js +0 -11
- package/dist/bundle/chunks/chunk-S7SZN6Z3.js +0 -2
- package/dist/bundle/chunks/chunk-UXY3GQU2.js +0 -2
- package/dist/bundle/chunks/chunk-XNGRGP62.js +0 -2
- package/dist/bundle/chunks/google-generative-ai-IMS5EK2Y.js +0 -2
- package/dist/bundle/chunks/google-vertex-O4YJEQUW.js +0 -2
- package/dist/bundle/chunks/mistral-conversations-NOSQHBEY.js +0 -5
- package/dist/bundle/chunks/openai-responses-HWEUZ6WZ.js +0 -2
- package/dist/bundle/chunks/virtual-modules-WS3GCBF2.js +0 -2
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import { readFileSync } from "node:fs";
|
|
16
16
|
import { basename, dirname } from "node:path";
|
|
17
|
+
import { runToolCall, } from "@earendil-works/pi-agent-core";
|
|
17
18
|
import { contentText, getCurrentSystemMessage, retryDelayMs } from "@earendil-works/pi-ai";
|
|
18
19
|
import { clampThinkingLevel, cleanupSessionResources, getSupportedThinkingLevels, isContextOverflow, isRecoverableLength, isRetryableAssistantError, modelsAreEqual, resetApiProviders, streamSimple, } from "@earendil-works/pi-ai/compat";
|
|
19
20
|
import { getThemeByName, theme } from "../modes/interactive/theme/theme.js";
|
|
@@ -32,16 +33,19 @@ import { ExtensionRunner, wrapRegisteredTools, } from "./extensions/index.js";
|
|
|
32
33
|
import { emitSessionShutdownEvent } from "./extensions/runner.js";
|
|
33
34
|
import { convertToLlm } from "./messages.js";
|
|
34
35
|
import { ModelRegistry } from "./model-registry.js";
|
|
36
|
+
import { NestedToolCallRunner } from "./nested-tool-calls.js";
|
|
35
37
|
import { expandPromptTemplate } from "./prompt-templates.js";
|
|
36
38
|
import { exportSessionToJsonl } from "./session-export.js";
|
|
37
39
|
import { getLatestCompactionEntry, SessionManager, } from "./session-manager.js";
|
|
40
|
+
import { DEFAULT_TOOL_NAMES } from "./settings-manager.js";
|
|
38
41
|
import { findSkillByInvocationName, resolveBareNamespaceSkill } from "./skills.js";
|
|
39
|
-
import { createSyntheticSourceInfo } from "./source-info.js";
|
|
42
|
+
import { BUILTIN_PATH_PREFIX, createSyntheticSourceInfo, isSyntheticPath } from "./source-info.js";
|
|
40
43
|
import { buildSystemPrompt, buildSystemPromptSections, diffSystemPromptSections, normalizeBuildSystemPromptOptions, } from "./system-prompt.js";
|
|
41
44
|
import { createLocalBashOperations } from "./tools/bash.js";
|
|
42
45
|
import { createAllToolDefinitions } from "./tools/index.js";
|
|
43
46
|
import { createToolDefinitionFromAgentTool } from "./tools/tool-definition-wrapper.js";
|
|
44
|
-
import { addUsageToTotals, createUsageTotals } from "./usage-totals.js";
|
|
47
|
+
import { addUsageToTotals, combineUsage, createUsageTotals } from "./usage-totals.js";
|
|
48
|
+
import { findLatestResponse, getBranchSelection, getVirtualModelState, isVirtualModel, VIRTUAL_MODEL_STATE_ENTRY, } from "./virtual-models.js";
|
|
45
49
|
/**
|
|
46
50
|
* Parse a skill block from message text.
|
|
47
51
|
* Returns null if the text doesn't contain a skill block.
|
|
@@ -104,6 +108,11 @@ export class AgentSession {
|
|
|
104
108
|
// Retry state
|
|
105
109
|
_retryAbortController = undefined;
|
|
106
110
|
_retryAttempt = 0;
|
|
111
|
+
/**
|
|
112
|
+
* Failed response that the next request repeats, set by auto-retry and overflow recovery. The
|
|
113
|
+
* retry is routed with it as `failed`, since the context no longer contains it.
|
|
114
|
+
*/
|
|
115
|
+
_failedResponse;
|
|
107
116
|
// Bash execution state
|
|
108
117
|
_bashAbortControllers = new Set();
|
|
109
118
|
_pendingBashMessages = [];
|
|
@@ -125,6 +134,13 @@ export class AgentSession {
|
|
|
125
134
|
_cwd;
|
|
126
135
|
_extensionRunnerRef;
|
|
127
136
|
_initialActiveToolNames;
|
|
137
|
+
/**
|
|
138
|
+
* Tools of the restored or reloaded loadout that are not registered yet, such as tools of MCP
|
|
139
|
+
* servers that are still connecting. They are activated when they are registered, and dropped when
|
|
140
|
+
* `setActiveToolsByName()` deactivates a tool or the next agent run starts.
|
|
141
|
+
*/
|
|
142
|
+
_pendingToolNames = new Set();
|
|
143
|
+
_usesDefaultTools;
|
|
128
144
|
_allowedToolNames;
|
|
129
145
|
_excludedToolNames;
|
|
130
146
|
_baseToolsOverride;
|
|
@@ -140,6 +156,10 @@ export class AgentSession {
|
|
|
140
156
|
_cacheWarmer;
|
|
141
157
|
// Tool registry for extension getTools/setTools
|
|
142
158
|
_toolRegistry = new Map();
|
|
159
|
+
/** Created on the first `ctx.executeTool()` call. */
|
|
160
|
+
_nestedToolCalls;
|
|
161
|
+
/** Declared tools whose declarations requests leave out, from `prepareLoadout` hooks. */
|
|
162
|
+
_hiddenDeclarations = new Set();
|
|
143
163
|
_toolDefinitions = new Map();
|
|
144
164
|
_toolPromptSnippets = new Map();
|
|
145
165
|
_toolPromptGuidelines = new Map();
|
|
@@ -161,6 +181,7 @@ export class AgentSession {
|
|
|
161
181
|
}
|
|
162
182
|
this._extensionRunnerRef = config.extensionRunnerRef;
|
|
163
183
|
this._initialActiveToolNames = config.initialActiveToolNames;
|
|
184
|
+
this._usesDefaultTools = config.usesDefaultTools ?? false;
|
|
164
185
|
this._allowedToolNames = config.allowedToolNames ? new Set(config.allowedToolNames) : undefined;
|
|
165
186
|
this._excludedToolNames = config.excludedToolNames ? new Set(config.excludedToolNames) : undefined;
|
|
166
187
|
this._baseToolsOverride = config.baseToolsOverride;
|
|
@@ -172,6 +193,7 @@ export class AgentSession {
|
|
|
172
193
|
this._installAgentNextTurnRefresh();
|
|
173
194
|
this._installAgentRequestProjection();
|
|
174
195
|
this._installAgentBoundaryHooks();
|
|
196
|
+
this._installHiddenDeclarationsProjection();
|
|
175
197
|
this._installAgentForcedPromptProjection();
|
|
176
198
|
this._buildRuntime({
|
|
177
199
|
activeToolNames: this._initialActiveToolNames,
|
|
@@ -212,28 +234,71 @@ export class AgentSession {
|
|
|
212
234
|
}
|
|
213
235
|
throw new Error(formatNoApiKeyFoundMessage(model.provider));
|
|
214
236
|
}
|
|
215
|
-
async _getSummarizationRequestAuth(
|
|
237
|
+
async _getSummarizationRequestAuth(selectedModel, signal) {
|
|
238
|
+
// Route a virtual model first: summaries size their input and output from the model they get.
|
|
239
|
+
const { model, thinkingLevel } = isVirtualModel(selectedModel)
|
|
240
|
+
? await this._modelRuntime.resolveModel(selectedModel, convertToLlm(this.messages), {
|
|
241
|
+
reason: "direct",
|
|
242
|
+
thinkingLevel: this.thinkingLevel,
|
|
243
|
+
signal,
|
|
244
|
+
})
|
|
245
|
+
: { model: selectedModel, thinkingLevel: this.thinkingLevel };
|
|
216
246
|
if (this.agent.streamFunction === streamSimple) {
|
|
217
|
-
return this._getRequiredRequestAuth(model, signal);
|
|
247
|
+
return { ...(await this._getRequiredRequestAuth(model, signal)), thinkingLevel };
|
|
218
248
|
}
|
|
219
249
|
try {
|
|
220
250
|
const result = await this._modelRuntime.getAuth(model, { signal });
|
|
221
251
|
if (!result)
|
|
222
|
-
return { model };
|
|
252
|
+
return { model, thinkingLevel };
|
|
223
253
|
const requestModel = result.auth.baseUrl ? { ...model, baseUrl: result.auth.baseUrl } : model;
|
|
224
254
|
return {
|
|
225
255
|
model: requestModel,
|
|
226
256
|
apiKey: result.auth.apiKey,
|
|
227
257
|
headers: withoutDeletedHeaders(result.auth.headers),
|
|
228
258
|
env: result.env,
|
|
259
|
+
thinkingLevel,
|
|
229
260
|
};
|
|
230
261
|
}
|
|
231
262
|
catch (error) {
|
|
232
263
|
if (signal?.aborted)
|
|
233
264
|
throw error;
|
|
234
|
-
return { model };
|
|
265
|
+
return { model, thinkingLevel };
|
|
235
266
|
}
|
|
236
267
|
}
|
|
268
|
+
/**
|
|
269
|
+
* The model whose limits apply to `message`, or undefined when the message came from another
|
|
270
|
+
* model. Under a virtual selection, that is the physical model that produced it.
|
|
271
|
+
*/
|
|
272
|
+
_modelForMessage(message) {
|
|
273
|
+
const model = this.model;
|
|
274
|
+
if (model && isVirtualModel(model))
|
|
275
|
+
return this._modelRuntime.getPhysicalModel(message.provider, message.model);
|
|
276
|
+
return model?.provider === message.provider && model.id === message.model ? model : undefined;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Record the selection on the current branch when the branch implies another one, so a resume
|
|
280
|
+
* restores it. Tree navigation can leave the latest `model_change` on another branch; responses
|
|
281
|
+
* cannot record a virtual selection because they name physical models. Responses do record a
|
|
282
|
+
* physical selection unless the branch holds a virtual one; checking a physical selection against
|
|
283
|
+
* responses would record it on every prompt while `prepareRequest` redirects to another model.
|
|
284
|
+
*/
|
|
285
|
+
_recordSelection() {
|
|
286
|
+
const model = this.model;
|
|
287
|
+
if (!model)
|
|
288
|
+
return;
|
|
289
|
+
const getModel = (provider, modelId) => this._modelRuntime.getModel(provider, modelId);
|
|
290
|
+
const recorded = getBranchSelection(this.sessionManager.getBranch(), getModel);
|
|
291
|
+
if (!recorded || (recorded.provider === model.provider && recorded.modelId === model.id))
|
|
292
|
+
return;
|
|
293
|
+
const recordedModel = getModel(recorded.provider, recorded.modelId);
|
|
294
|
+
if (!isVirtualModel(model) && !(recordedModel && isVirtualModel(recordedModel)))
|
|
295
|
+
return;
|
|
296
|
+
this.sessionManager.appendModelChange(model.provider, model.id);
|
|
297
|
+
}
|
|
298
|
+
/** The model whose limits apply to the conversation. */
|
|
299
|
+
_limitsModel() {
|
|
300
|
+
return this.routedModel?.model ?? this.model;
|
|
301
|
+
}
|
|
237
302
|
/**
|
|
238
303
|
* Install tool hooks once on the Agent instance.
|
|
239
304
|
*
|
|
@@ -243,65 +308,112 @@ export class AgentSession {
|
|
|
243
308
|
* happens here instead of in wrappers.
|
|
244
309
|
*/
|
|
245
310
|
_installAgentToolHooks() {
|
|
246
|
-
this.agent.beforeToolCall =
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
}
|
|
263
|
-
throw new Error(`Extension failed, blocking execution: ${String(err)}`);
|
|
264
|
-
}
|
|
265
|
-
};
|
|
266
|
-
this.agent.afterToolCall = async ({ toolCall, args, result, isError }) => {
|
|
267
|
-
const runner = this._extensionRunner;
|
|
268
|
-
const hookResult = runner.hasHandlers("tool_result")
|
|
269
|
-
? await runner.emitToolResult({
|
|
270
|
-
type: "tool_result",
|
|
271
|
-
toolName: toolCall.name,
|
|
272
|
-
toolCallId: toolCall.id,
|
|
273
|
-
input: args,
|
|
274
|
-
content: result.content,
|
|
275
|
-
details: result.details,
|
|
276
|
-
isError,
|
|
277
|
-
usage: result.usage,
|
|
278
|
-
})
|
|
279
|
-
: undefined;
|
|
280
|
-
const content = hookResult?.content ?? result.content ?? [];
|
|
281
|
-
// Runs after the extension hook so images injected or replaced by extensions are normalized too.
|
|
282
|
-
const resizeOptions = this.model?.inputLimits?.images?.resize;
|
|
283
|
-
const normalizedContent = await normalizeToolResultImages(content, {
|
|
284
|
-
autoResizeImages: this.settingsManager.getImageAutoResize(),
|
|
285
|
-
...(resizeOptions ? { resizeOptions } : {}),
|
|
311
|
+
this.agent.beforeToolCall = (context) => this._beforeToolCall(context);
|
|
312
|
+
this.agent.afterToolCall = (context) => this._afterToolCall(context);
|
|
313
|
+
}
|
|
314
|
+
/** `tool_call` handlers. `parentToolCallId` is set for calls another tool made. */
|
|
315
|
+
async _beforeToolCall({ toolCall, args }, parentToolCallId) {
|
|
316
|
+
const runner = this._extensionRunner;
|
|
317
|
+
if (!runner.hasHandlers("tool_call")) {
|
|
318
|
+
return undefined;
|
|
319
|
+
}
|
|
320
|
+
try {
|
|
321
|
+
return await runner.emitToolCall({
|
|
322
|
+
type: "tool_call",
|
|
323
|
+
toolName: toolCall.name,
|
|
324
|
+
toolCallId: toolCall.id,
|
|
325
|
+
...(parentToolCallId ? { parentToolCallId } : {}),
|
|
326
|
+
input: args,
|
|
286
327
|
});
|
|
287
|
-
|
|
288
|
-
|
|
328
|
+
}
|
|
329
|
+
catch (err) {
|
|
330
|
+
if (err instanceof Error) {
|
|
331
|
+
throw err;
|
|
289
332
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
333
|
+
throw new Error(`Extension failed, blocking execution: ${String(err)}`);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
/** `tool_result` handlers and image normalization. `parentToolCallId` is set for calls another tool made. */
|
|
337
|
+
async _afterToolCall({ toolCall, args, result, isError }, parentToolCallId) {
|
|
338
|
+
const runner = this._extensionRunner;
|
|
339
|
+
const hookResult = runner.hasHandlers("tool_result")
|
|
340
|
+
? await runner.emitToolResult({
|
|
341
|
+
type: "tool_result",
|
|
342
|
+
toolName: toolCall.name,
|
|
343
|
+
toolCallId: toolCall.id,
|
|
344
|
+
...(parentToolCallId ? { parentToolCallId } : {}),
|
|
345
|
+
input: args,
|
|
346
|
+
content: result.content,
|
|
347
|
+
details: result.details,
|
|
348
|
+
...(result.structuredContent === undefined ? {} : { structuredContent: result.structuredContent }),
|
|
349
|
+
isError,
|
|
350
|
+
usage: result.usage,
|
|
351
|
+
})
|
|
352
|
+
: undefined;
|
|
353
|
+
const content = hookResult?.content ?? result.content ?? [];
|
|
354
|
+
// Runs after the extension hook so images injected or replaced by extensions are normalized too.
|
|
355
|
+
const resizeOptions = this._limitsModel()?.inputLimits?.images?.resize;
|
|
356
|
+
const normalizedContent = await normalizeToolResultImages(content, {
|
|
357
|
+
autoResizeImages: this.settingsManager.getImageAutoResize(),
|
|
358
|
+
...(resizeOptions ? { resizeOptions } : {}),
|
|
359
|
+
});
|
|
360
|
+
if (!hookResult && normalizedContent === content) {
|
|
361
|
+
return undefined;
|
|
362
|
+
}
|
|
363
|
+
// The hook result already dropped structured content that replaced content no longer matches.
|
|
364
|
+
return {
|
|
365
|
+
content: normalizedContent,
|
|
366
|
+
details: hookResult?.details,
|
|
367
|
+
structuredContent: hookResult ? hookResult.structuredContent : result.structuredContent,
|
|
368
|
+
isError: hookResult?.isError ?? isError,
|
|
369
|
+
usage: hookResult?.usage,
|
|
296
370
|
};
|
|
297
371
|
}
|
|
372
|
+
/**
|
|
373
|
+
* Run a call that the tool call `parentToolCallId` made through `ctx.executeTool()`. It goes
|
|
374
|
+
* through the agent's tool pipeline with the session's hooks, against the callable tools.
|
|
375
|
+
*/
|
|
376
|
+
async _executeNestedToolCall(parentToolCallId, name, args, options) {
|
|
377
|
+
this._nestedToolCalls ??= new NestedToolCallRunner({
|
|
378
|
+
getTools: () => this._getCallableTools(),
|
|
379
|
+
isSequential: () => this.agent.toolExecution === "sequential",
|
|
380
|
+
runToolCall: (toolCall, parentId, signal, onUpdate) => {
|
|
381
|
+
const assistantMessage = this._findLastAssistantMessage();
|
|
382
|
+
if (!assistantMessage) {
|
|
383
|
+
return Promise.resolve({
|
|
384
|
+
toolCall,
|
|
385
|
+
result: { content: [{ type: "text", text: "No assistant message issued this call" }], details: {} },
|
|
386
|
+
isError: true,
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
return runToolCall(toolCall, {
|
|
390
|
+
tools: this._getCallableTools(),
|
|
391
|
+
assistantMessage,
|
|
392
|
+
context: { messages: this.agent.state.messages, tools: this.agent.state.tools },
|
|
393
|
+
beforeToolCall: (context) => this._beforeToolCall(context, parentId),
|
|
394
|
+
afterToolCall: (context) => this._afterToolCall(context, parentId),
|
|
395
|
+
signal,
|
|
396
|
+
onUpdate,
|
|
397
|
+
});
|
|
398
|
+
},
|
|
399
|
+
emit: async (event) => {
|
|
400
|
+
await this._extensionRunner.emit(event);
|
|
401
|
+
this._emit(event);
|
|
402
|
+
},
|
|
403
|
+
});
|
|
404
|
+
return this._nestedToolCalls.execute(parentToolCallId, name, args, options);
|
|
405
|
+
}
|
|
406
|
+
/** Whether `projection`, the current session projection, exceeds the compaction threshold of `model`. */
|
|
407
|
+
_exceedsCompactionThreshold(model, projection) {
|
|
408
|
+
if (model.contextWindow <= 0)
|
|
409
|
+
return false;
|
|
410
|
+
return shouldCompact(estimateProjectedContextTokens(projection, this.sessionManager.getBranch()).tokens, model.contextWindow, this.settingsManager.getCompactionSettings(this.model));
|
|
411
|
+
}
|
|
298
412
|
async _compactBeforeNextAssistantResponse(context) {
|
|
299
|
-
const model = this.model;
|
|
300
|
-
const settings = this.settingsManager.getCompactionSettings(model);
|
|
301
413
|
const projection = this.sessionManager.buildSessionProjection();
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
414
|
+
// A virtual selection is checked in prepareRequest, against the model the request is routed to.
|
|
415
|
+
const model = this.model;
|
|
416
|
+
if (!model || isVirtualModel(model) || !this._exceedsCompactionThreshold(model, projection)) {
|
|
305
417
|
return { ...context, messages: projection.messages };
|
|
306
418
|
}
|
|
307
419
|
await this._runAutoCompaction("threshold", false);
|
|
@@ -310,24 +422,55 @@ export class AgentSession {
|
|
|
310
422
|
_installAgentRequestProjection() {
|
|
311
423
|
const previousPrepareRequest = this.agent.prepareRequest;
|
|
312
424
|
this.agent.prepareRequest = async (request, signal) => {
|
|
313
|
-
const
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
425
|
+
const failed = this._failedResponse;
|
|
426
|
+
this._failedResponse = undefined;
|
|
427
|
+
const prepare = async () => {
|
|
428
|
+
const projection = this.sessionManager.buildSessionProjection();
|
|
429
|
+
const canonicalContext = {
|
|
430
|
+
...request.context,
|
|
431
|
+
messages: projection.messages,
|
|
432
|
+
// Messages declare the provider-visible loadout; context.tools keeps executable implementations.
|
|
433
|
+
tools: this.agent.state.tools.slice(),
|
|
434
|
+
};
|
|
435
|
+
const previous = await previousPrepareRequest?.({
|
|
436
|
+
...request,
|
|
437
|
+
context: canonicalContext,
|
|
438
|
+
model: this.agent.state.model,
|
|
439
|
+
thinkingLevel: this.agent.state.thinkingLevel,
|
|
440
|
+
}, signal);
|
|
441
|
+
return { previous, context: previous?.context ?? canonicalContext, projection };
|
|
330
442
|
};
|
|
443
|
+
let { previous, context, projection } = await prepare();
|
|
444
|
+
const model = previous?.model ?? this.agent.state.model;
|
|
445
|
+
const thinkingLevel = previous?.thinkingLevel ?? this.agent.state.thinkingLevel;
|
|
446
|
+
if (!isVirtualModel(model))
|
|
447
|
+
return { ...previous, context, model, thinkingLevel };
|
|
448
|
+
// The selection stays in agent state; only this request uses the routed model. A routing
|
|
449
|
+
// failure rejects, which ends the run with an error response. Only messages the user wrote
|
|
450
|
+
// start a turn; extension messages can follow them, e.g. from before_agent_start.
|
|
451
|
+
const lastResponse = context.messages.findLastIndex((message) => message.role === "assistant");
|
|
452
|
+
const userTurn = context.messages.slice(lastResponse + 1).some((message) => message.role === "user");
|
|
453
|
+
const state = getVirtualModelState(this.sessionManager.getBranch(), model.provider, model.id);
|
|
454
|
+
const route = await this._modelRuntime.resolveModel(model, convertToLlm(context.messages), {
|
|
455
|
+
reason: failed ? "retry" : userTurn ? "user" : "continuation",
|
|
456
|
+
thinkingLevel,
|
|
457
|
+
signal,
|
|
458
|
+
failed,
|
|
459
|
+
state,
|
|
460
|
+
});
|
|
461
|
+
if (route.state !== undefined && route.state !== state) {
|
|
462
|
+
const data = { provider: model.provider, modelId: model.id, state: route.state };
|
|
463
|
+
const entry = this.sessionManager.getEntry(this.sessionManager.appendCustomEntry(VIRTUAL_MODEL_STATE_ENTRY, data));
|
|
464
|
+
if (entry)
|
|
465
|
+
this._emit({ type: "entry_appended", entry });
|
|
466
|
+
}
|
|
467
|
+
// The route stands: the router already decided this request. The state entry does not change
|
|
468
|
+
// the projection.
|
|
469
|
+
if (this._exceedsCompactionThreshold(route.model, projection)) {
|
|
470
|
+
await this._runAutoCompaction("threshold", false);
|
|
471
|
+
({ previous, context } = await prepare());
|
|
472
|
+
}
|
|
473
|
+
return { ...previous, context, model: route.model, thinkingLevel: route.thinkingLevel };
|
|
331
474
|
};
|
|
332
475
|
}
|
|
333
476
|
async _dispatchTurnEndBoundary(message, toolResults) {
|
|
@@ -383,10 +526,7 @@ export class AgentSession {
|
|
|
383
526
|
? async (_turn, signal) => await this.agent.prepareNextTurn?.(signal)
|
|
384
527
|
: undefined);
|
|
385
528
|
this.agent.prepareNextTurnWithContext = async (turn, signal) => {
|
|
386
|
-
const context = await this._compactBeforeNextAssistantResponse(
|
|
387
|
-
...turn.context,
|
|
388
|
-
messages: this.sessionManager.buildSessionProjection().messages,
|
|
389
|
-
});
|
|
529
|
+
const context = await this._compactBeforeNextAssistantResponse(turn.context);
|
|
390
530
|
const previousSnapshot = await previousPrepareNextTurnWithContext?.({ ...turn, context }, signal);
|
|
391
531
|
const nextContext = previousSnapshot?.context ?? context;
|
|
392
532
|
const runOptions = this._runSystemPromptOptions ?? this._baseSystemPromptOptions;
|
|
@@ -555,6 +695,21 @@ export class AgentSession {
|
|
|
555
695
|
}
|
|
556
696
|
/** Internal handler for agent events - shared by subscribe and reconnect */
|
|
557
697
|
_handleAgentEvent = async (event) => {
|
|
698
|
+
// Record the calls a tool made through ctx.executeTool() and their usage on its result message.
|
|
699
|
+
if (this._nestedToolCalls) {
|
|
700
|
+
if (event.type === "message_start" && event.message.role === "toolResult") {
|
|
701
|
+
const message = event.message;
|
|
702
|
+
const summary = this._nestedToolCalls.takeRecord(message.toolCallId);
|
|
703
|
+
if (summary?.calls)
|
|
704
|
+
message.nestedCalls = summary.calls;
|
|
705
|
+
if (summary?.usage) {
|
|
706
|
+
message.usage = message.usage ? combineUsage(message.usage, summary.usage) : summary.usage;
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
else if (event.type === "agent_end") {
|
|
710
|
+
this._nestedToolCalls.clear();
|
|
711
|
+
}
|
|
712
|
+
}
|
|
558
713
|
// When a user message starts, check if it's from either queue and remove it BEFORE emitting
|
|
559
714
|
// This ensures the UI sees the updated queue state
|
|
560
715
|
if (event.type === "message_start" && event.message.role === "user") {
|
|
@@ -868,6 +1023,14 @@ export class AgentSession {
|
|
|
868
1023
|
get thinkingLevel() {
|
|
869
1024
|
return this.agent.state.thinkingLevel;
|
|
870
1025
|
}
|
|
1026
|
+
/** Under a virtual selection, the physical model and thinking level of the latest successful response. */
|
|
1027
|
+
get routedModel() {
|
|
1028
|
+
if (!this.model || !isVirtualModel(this.model))
|
|
1029
|
+
return undefined;
|
|
1030
|
+
const latest = findLatestResponse(this.agent.state.messages);
|
|
1031
|
+
const model = latest && this._modelRuntime.getPhysicalModel(latest.provider, latest.model);
|
|
1032
|
+
return model && { model, thinkingLevel: latest?.thinkingLevel };
|
|
1033
|
+
}
|
|
871
1034
|
/** Whether the session is currently processing an agent run or post-run continuation. */
|
|
872
1035
|
get isStreaming() {
|
|
873
1036
|
return this._isAgentRunActive;
|
|
@@ -885,12 +1048,16 @@ export class AgentSession {
|
|
|
885
1048
|
return this._retryAttempt;
|
|
886
1049
|
}
|
|
887
1050
|
/**
|
|
888
|
-
* Get the names of currently active tools.
|
|
889
|
-
*
|
|
1051
|
+
* Get the names of currently active tools, which are the tools declared to the model.
|
|
1052
|
+
* Tools with `codemode` or `deferred` exposure are callable from other tools without being active.
|
|
890
1053
|
*/
|
|
891
1054
|
getActiveToolNames() {
|
|
892
1055
|
return this.agent.state.tools.map((t) => t.name);
|
|
893
1056
|
}
|
|
1057
|
+
/** Get the names of the tools that tools can call through `ctx.executeTool()`. */
|
|
1058
|
+
getCallableToolNames() {
|
|
1059
|
+
return this._getCallableTools().map((t) => t.name);
|
|
1060
|
+
}
|
|
894
1061
|
/**
|
|
895
1062
|
* Get all configured tools with name, description, parameter schema, prompt guidelines, and source metadata.
|
|
896
1063
|
*/
|
|
@@ -900,6 +1067,9 @@ export class AgentSession {
|
|
|
900
1067
|
description: definition.description,
|
|
901
1068
|
parameters: definition.parameters,
|
|
902
1069
|
promptGuidelines: definition.promptGuidelines,
|
|
1070
|
+
exposure: this._getToolExposure(definition.name),
|
|
1071
|
+
...(definition.namespace ? { namespace: definition.namespace } : {}),
|
|
1072
|
+
...(definition.annotations ? { annotations: { ...definition.annotations } } : {}),
|
|
903
1073
|
sourceInfo,
|
|
904
1074
|
}));
|
|
905
1075
|
}
|
|
@@ -908,22 +1078,93 @@ export class AgentSession {
|
|
|
908
1078
|
}
|
|
909
1079
|
/**
|
|
910
1080
|
* Set active tools by name.
|
|
911
|
-
* Only tools in the registry can be enabled. Unknown tool names are ignored.
|
|
1081
|
+
* Only tools in the registry can be enabled. Unknown and hidden tool names are ignored.
|
|
912
1082
|
* Also rebuilds the system prompt to reflect the new tool set.
|
|
913
1083
|
* Changes take effect on the next agent turn.
|
|
914
1084
|
*/
|
|
915
1085
|
setActiveToolsByName(toolNames) {
|
|
916
|
-
const
|
|
917
|
-
|
|
918
|
-
|
|
1086
|
+
const previous = this.getActiveToolNames();
|
|
1087
|
+
this._setActiveTools(toolNames);
|
|
1088
|
+
// A loadout that deactivates a tool replaces the restored one, whose pending tools are dropped.
|
|
1089
|
+
// One that only adds tools, like activating tool_search, keeps them.
|
|
1090
|
+
const active = new Set(this.getActiveToolNames());
|
|
1091
|
+
if (previous.some((name) => !active.has(name)))
|
|
1092
|
+
this._pendingToolNames.clear();
|
|
1093
|
+
}
|
|
1094
|
+
_setActiveTools(toolNames) {
|
|
1095
|
+
const tools = this._applyToolLoadout(toolNames);
|
|
1096
|
+
for (const tool of tools)
|
|
1097
|
+
this._pendingToolNames.delete(tool.name);
|
|
1098
|
+
this._rebuildSystemPrompt(tools.map((tool) => tool.name));
|
|
1099
|
+
}
|
|
1100
|
+
_isAllowedTool(name) {
|
|
1101
|
+
return (!this._allowedToolNames || this._allowedToolNames.has(name)) && !this._excludedToolNames?.has(name);
|
|
1102
|
+
}
|
|
1103
|
+
_getToolExposure(name) {
|
|
1104
|
+
return this._toolDefinitions.get(name)?.definition.exposure ?? "direct";
|
|
1105
|
+
}
|
|
1106
|
+
/**
|
|
1107
|
+
* Tools callable through `ctx.executeTool()`: the active `direct` tools and every registered
|
|
1108
|
+
* `codemode` or `deferred` tool.
|
|
1109
|
+
*/
|
|
1110
|
+
_getCallableTools(active = new Set(this.getActiveToolNames())) {
|
|
1111
|
+
return [...this._toolRegistry.values()].filter((tool) => {
|
|
1112
|
+
const exposure = this._getToolExposure(tool.name);
|
|
1113
|
+
return exposure === "codemode" || exposure === "deferred" || (exposure === "direct" && active.has(tool.name));
|
|
1114
|
+
});
|
|
1115
|
+
}
|
|
1116
|
+
/**
|
|
1117
|
+
* Set the agent's tools for the given active tool names and return them. The active tools are
|
|
1118
|
+
* the registered, non-hidden ones; they are declared to the model. Active tools with a
|
|
1119
|
+
* `prepareLoadout` hook can change the declared descriptions and hide declarations from
|
|
1120
|
+
* requests (see {@link _installHiddenDeclarationsProjection}).
|
|
1121
|
+
*/
|
|
1122
|
+
_applyToolLoadout(toolNames) {
|
|
1123
|
+
const tools = [...new Set(toolNames)].flatMap((name) => {
|
|
919
1124
|
const tool = this._toolRegistry.get(name);
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
1125
|
+
return tool && this._getToolExposure(name) !== "hidden" ? [tool] : [];
|
|
1126
|
+
});
|
|
1127
|
+
const hooks = tools.flatMap((tool) => {
|
|
1128
|
+
const entry = this._toolDefinitions.get(tool.name);
|
|
1129
|
+
return entry?.definition.prepareLoadout ? [entry] : [];
|
|
1130
|
+
});
|
|
1131
|
+
const hidden = new Set();
|
|
1132
|
+
let declared = tools;
|
|
1133
|
+
if (hooks.length > 0) {
|
|
1134
|
+
const loadout = {
|
|
1135
|
+
declared: tools,
|
|
1136
|
+
callable: this._getCallableTools(new Set(tools.map((tool) => tool.name))),
|
|
1137
|
+
registered: [...this._toolRegistry.values()],
|
|
1138
|
+
getExposure: (name) => this._getToolExposure(name),
|
|
1139
|
+
getNamespace: (name) => this._toolDefinitions.get(name)?.definition.namespace,
|
|
1140
|
+
};
|
|
1141
|
+
const descriptions = new Map();
|
|
1142
|
+
for (const { definition, sourceInfo } of hooks) {
|
|
1143
|
+
try {
|
|
1144
|
+
const changes = definition.prepareLoadout?.(loadout);
|
|
1145
|
+
for (const [name, description] of Object.entries(changes?.descriptions ?? {})) {
|
|
1146
|
+
descriptions.set(name, description);
|
|
1147
|
+
}
|
|
1148
|
+
for (const name of changes?.hiddenDeclarations ?? [])
|
|
1149
|
+
hidden.add(name);
|
|
1150
|
+
}
|
|
1151
|
+
catch (error) {
|
|
1152
|
+
this._extensionRunner.emitError({
|
|
1153
|
+
extensionPath: sourceInfo.path,
|
|
1154
|
+
event: "prepare_loadout",
|
|
1155
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1156
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
1157
|
+
});
|
|
1158
|
+
}
|
|
923
1159
|
}
|
|
1160
|
+
declared = tools.map((tool) => {
|
|
1161
|
+
const description = descriptions.get(tool.name);
|
|
1162
|
+
return description === undefined ? tool : { ...tool, description };
|
|
1163
|
+
});
|
|
924
1164
|
}
|
|
925
|
-
this.
|
|
926
|
-
this.
|
|
1165
|
+
this._hiddenDeclarations = hidden;
|
|
1166
|
+
this.agent.state.tools = declared;
|
|
1167
|
+
return declared;
|
|
927
1168
|
}
|
|
928
1169
|
/** Whether compaction or branch summarization is currently running */
|
|
929
1170
|
get isCompacting() {
|
|
@@ -994,7 +1235,8 @@ export class AgentSession {
|
|
|
994
1235
|
const toolSnippets = {};
|
|
995
1236
|
for (const name of this._toolRegistry.keys()) {
|
|
996
1237
|
const snippet = this._toolPromptSnippets.get(name);
|
|
997
|
-
|
|
1238
|
+
// Tools without a snippet are not listed. Hidden tools are only callable through another tool.
|
|
1239
|
+
if (snippet && !this._hiddenDeclarations.has(name))
|
|
998
1240
|
toolSnippets[name] = snippet;
|
|
999
1241
|
}
|
|
1000
1242
|
const loaderSystemPrompt = this._resourceLoader.getSystemPrompt();
|
|
@@ -1024,11 +1266,9 @@ export class AgentSession {
|
|
|
1024
1266
|
* {@link _installAgentForcedPromptProjection}.
|
|
1025
1267
|
*/
|
|
1026
1268
|
_preparePromptAndToolLoadout(options, messages = this.agent.state.messages) {
|
|
1027
|
-
options.selectedTools =
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
return tool ? [tool] : [];
|
|
1031
|
-
});
|
|
1269
|
+
options.selectedTools = this._applyToolLoadout(options.selectedTools).map((tool) => tool.name);
|
|
1270
|
+
// The tool list must match the declarations the request carries, so hidden tools are not listed.
|
|
1271
|
+
options.toolSnippets = Object.fromEntries(Object.entries(options.toolSnippets).filter(([name]) => !this._hiddenDeclarations.has(name)));
|
|
1032
1272
|
const sections = diffSystemPromptSections(getCurrentSystemMessage(messages)?.sections ?? {}, buildSystemPromptSections(options));
|
|
1033
1273
|
return sections ? { role: "system", content: "", sections, timestamp: Date.now() } : undefined;
|
|
1034
1274
|
}
|
|
@@ -1042,6 +1282,32 @@ export class AgentSession {
|
|
|
1042
1282
|
* collapse into one head holding the forced text and the current tools. Runs after the
|
|
1043
1283
|
* `context` extension handlers.
|
|
1044
1284
|
*/
|
|
1285
|
+
/**
|
|
1286
|
+
* Remove the declarations that `prepareLoadout` hooks hide from every request. The whole
|
|
1287
|
+
* transcript is filtered with the current set, so the projected declarations stay consistent
|
|
1288
|
+
* across requests and only change when the loadout does.
|
|
1289
|
+
*/
|
|
1290
|
+
_installHiddenDeclarationsProjection() {
|
|
1291
|
+
const previousTransformContext = this.agent.transformContext;
|
|
1292
|
+
this.agent.transformContext = async (messages, signal) => {
|
|
1293
|
+
const transformed = previousTransformContext ? await previousTransformContext(messages, signal) : messages;
|
|
1294
|
+
const hidden = this._hiddenDeclarations;
|
|
1295
|
+
if (hidden.size === 0)
|
|
1296
|
+
return transformed;
|
|
1297
|
+
return transformed.map((message) => {
|
|
1298
|
+
if (message.role !== "system" || (!message.toolsAdded && !message.toolsRemoved))
|
|
1299
|
+
return message;
|
|
1300
|
+
const { toolsAdded, toolsRemoved, ...rest } = message;
|
|
1301
|
+
const added = toolsAdded?.filter((tool) => !hidden.has(tool.name)) ?? [];
|
|
1302
|
+
const removed = toolsRemoved?.filter((tool) => !hidden.has(tool.name)) ?? [];
|
|
1303
|
+
return {
|
|
1304
|
+
...rest,
|
|
1305
|
+
...(added.length > 0 ? { toolsAdded: added } : {}),
|
|
1306
|
+
...(removed.length > 0 ? { toolsRemoved: removed } : {}),
|
|
1307
|
+
};
|
|
1308
|
+
});
|
|
1309
|
+
};
|
|
1310
|
+
}
|
|
1045
1311
|
_installAgentForcedPromptProjection() {
|
|
1046
1312
|
const previousTransformContext = this.agent.transformContext;
|
|
1047
1313
|
this.agent.transformContext = async (messages, signal) => {
|
|
@@ -1059,25 +1325,31 @@ export class AgentSession {
|
|
|
1059
1325
|
return [head, ...transformed.filter((message) => message.role !== "system")];
|
|
1060
1326
|
};
|
|
1061
1327
|
}
|
|
1062
|
-
/**
|
|
1328
|
+
/**
|
|
1329
|
+
* Restore the active tool loadout declared by the session transcript, if it declares one.
|
|
1330
|
+
* Tools reachable only from other tools are never declared, but they do not depend on the active
|
|
1331
|
+
* set, so the transcript's declarations are the whole loadout.
|
|
1332
|
+
*/
|
|
1063
1333
|
_restoreToolsFromTranscript() {
|
|
1334
|
+
this._pendingToolNames.clear();
|
|
1064
1335
|
const current = getCurrentSystemMessage(this.sessionManager.buildSessionContext().messages);
|
|
1065
1336
|
if (!current)
|
|
1066
1337
|
return;
|
|
1067
|
-
const
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
this.agent.state.tools = toolNames.flatMap((name) => {
|
|
1071
|
-
const registered = this._toolRegistry.get(name);
|
|
1072
|
-
return registered ? [registered] : [];
|
|
1073
|
-
});
|
|
1074
|
-
this._rebuildSystemPrompt(toolNames);
|
|
1338
|
+
const names = (current.toolsAdded ?? []).map((tool) => tool.name);
|
|
1339
|
+
this._pendingToolNames = new Set(names.filter((name) => this._isAllowedTool(name)));
|
|
1340
|
+
this._setActiveTools(names);
|
|
1075
1341
|
}
|
|
1076
1342
|
// =========================================================================
|
|
1077
1343
|
// Prompting
|
|
1078
1344
|
// =========================================================================
|
|
1079
1345
|
async _runAgentPrompt(messages) {
|
|
1080
1346
|
this._agentRunAbortRequested = false;
|
|
1347
|
+
// Compaction before the prompt may have scheduled a retry; the new prompt replaces it.
|
|
1348
|
+
this._failedResponse = undefined;
|
|
1349
|
+
this._recordSelection();
|
|
1350
|
+
// The run records the loadout in the transcript; restored tools that did not register by now
|
|
1351
|
+
// are dropped, so a tool that never registers does not stay pending.
|
|
1352
|
+
this._pendingToolNames.clear();
|
|
1081
1353
|
this._isAgentRunActive = true;
|
|
1082
1354
|
try {
|
|
1083
1355
|
await this.agent.prompt(messages);
|
|
@@ -1098,6 +1370,7 @@ export class AgentSession {
|
|
|
1098
1370
|
finally {
|
|
1099
1371
|
if (this._agentRunAbortRequested)
|
|
1100
1372
|
this._finishCancelledRetry();
|
|
1373
|
+
this._failedResponse = undefined;
|
|
1101
1374
|
this._runSystemPromptOptions = undefined;
|
|
1102
1375
|
this._flushPendingBashMessages();
|
|
1103
1376
|
this._flushPendingCustomMessages();
|
|
@@ -1118,6 +1391,7 @@ export class AgentSession {
|
|
|
1118
1391
|
if (this._isRetryableError(message) && (await this._prepareRetry(message))) {
|
|
1119
1392
|
if (this._agentRunAbortRequested)
|
|
1120
1393
|
this._finishCancelledRetry();
|
|
1394
|
+
this._failedResponse = message;
|
|
1121
1395
|
return !this._agentRunAbortRequested;
|
|
1122
1396
|
}
|
|
1123
1397
|
if (this._agentRunAbortRequested) {
|
|
@@ -1185,7 +1459,7 @@ export class AgentSession {
|
|
|
1185
1459
|
for (const image of images) {
|
|
1186
1460
|
const processed = await processImage(Buffer.from(image.data, "base64"), image.mimeType, {
|
|
1187
1461
|
autoResizeImages: this.settingsManager.getImageAutoResize(),
|
|
1188
|
-
resizeOptions: this.
|
|
1462
|
+
resizeOptions: this._limitsModel()?.inputLimits?.images?.resize,
|
|
1189
1463
|
});
|
|
1190
1464
|
if (!processed.ok) {
|
|
1191
1465
|
hints.push(processed.message);
|
|
@@ -1212,124 +1486,114 @@ export class AgentSession {
|
|
|
1212
1486
|
}
|
|
1213
1487
|
const expandPromptTemplates = options?.expandPromptTemplates ?? true;
|
|
1214
1488
|
const preflightResult = options?.preflightResult;
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
if (
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
// Extension command executed, no prompt to send
|
|
1223
|
-
preflightResult?.(true);
|
|
1224
|
-
return;
|
|
1225
|
-
}
|
|
1226
|
-
}
|
|
1227
|
-
if (this._compactionAbortController !== undefined) {
|
|
1228
|
-
throw new Error("Cannot submit a prompt while compaction is in progress. Wait for compaction to finish and retry.");
|
|
1229
|
-
}
|
|
1230
|
-
// Emit input event for extension interception (before skill/template expansion)
|
|
1231
|
-
const processedInput = await this._runInputHandlers(text, options?.images, options?.source ?? "interactive", this.isStreaming ? options?.streamingBehavior : undefined);
|
|
1232
|
-
if (!processedInput) {
|
|
1233
|
-
preflightResult?.(true);
|
|
1489
|
+
// Handle extension commands first (execute immediately, even during streaming)
|
|
1490
|
+
// Extension commands manage their own LLM interaction via pi.sendMessage()
|
|
1491
|
+
if (expandPromptTemplates && text.startsWith("/")) {
|
|
1492
|
+
const handled = await this._tryExecuteExtensionCommand(text);
|
|
1493
|
+
if (handled) {
|
|
1494
|
+
// Extension command executed, no prompt to send
|
|
1495
|
+
preflightResult?.("handled");
|
|
1234
1496
|
return;
|
|
1235
1497
|
}
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1498
|
+
}
|
|
1499
|
+
if (this._compactionAbortController !== undefined) {
|
|
1500
|
+
throw new Error("Cannot submit a prompt while compaction is in progress. Wait for compaction to finish and retry.");
|
|
1501
|
+
}
|
|
1502
|
+
// Emit input event for extension interception (before skill/template expansion)
|
|
1503
|
+
const processedInput = await this._runInputHandlers(text, options?.images, options?.source ?? "interactive", this.isStreaming ? options?.streamingBehavior : undefined);
|
|
1504
|
+
if (!processedInput) {
|
|
1505
|
+
preflightResult?.("handled");
|
|
1506
|
+
return;
|
|
1507
|
+
}
|
|
1508
|
+
const { text: currentText, images: currentImages } = processedInput;
|
|
1509
|
+
// Expand skill commands (/skill:name args) and prompt templates (/template args)
|
|
1510
|
+
let expandedText = currentText;
|
|
1511
|
+
if (expandPromptTemplates) {
|
|
1512
|
+
expandedText = this._expandSkillCommand(expandedText);
|
|
1513
|
+
expandedText = this._expandBareNamespaceSkillCommand(expandedText);
|
|
1514
|
+
expandedText = expandPromptTemplate(expandedText, [...this.promptTemplates]);
|
|
1515
|
+
}
|
|
1516
|
+
// If streaming, queue via steer() or followUp() based on option
|
|
1517
|
+
if (this.isStreaming) {
|
|
1518
|
+
if (!options?.streamingBehavior) {
|
|
1519
|
+
throw new Error("Agent is already processing. Specify streamingBehavior ('steer' or 'followUp') to queue the message.");
|
|
1257
1520
|
}
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
this._flushPendingCustomMessages();
|
|
1261
|
-
// Validate model
|
|
1262
|
-
if (!this.model) {
|
|
1263
|
-
throw new Error(formatNoModelSelectedMessage());
|
|
1521
|
+
if (options.streamingBehavior === "followUp") {
|
|
1522
|
+
await this._queueFollowUp(expandedText, currentImages);
|
|
1264
1523
|
}
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
if (!hasConfiguredAuth) {
|
|
1268
|
-
const isOAuth = this._modelRuntime.isUsingOAuth(this.model.provider);
|
|
1269
|
-
if (isOAuth) {
|
|
1270
|
-
throw new Error(`Authentication failed for "${this.model.provider}". ` +
|
|
1271
|
-
`Credentials may have expired or network is unavailable. ` +
|
|
1272
|
-
`Run '/login ${this.model.provider}' to re-authenticate.`);
|
|
1273
|
-
}
|
|
1274
|
-
throw new Error(formatNoApiKeyFoundMessage(this.model.provider));
|
|
1275
|
-
}
|
|
1276
|
-
// Check if we need to compact before sending (catches aborted responses).
|
|
1277
|
-
// The user's new prompt is sent below, so do not call agent.continue() here.
|
|
1278
|
-
const lastAssistant = this._findLastAssistantMessage();
|
|
1279
|
-
if (lastAssistant) {
|
|
1280
|
-
await this._checkCompaction(lastAssistant, false);
|
|
1281
|
-
}
|
|
1282
|
-
// Emit before_agent_start before normalizing images so extension-driven model
|
|
1283
|
-
// selection determines the resize profile used for the request and history.
|
|
1284
|
-
const selectedToolsBefore = this._baseSystemPromptOptions.selectedTools;
|
|
1285
|
-
const result = await this._extensionRunner.emitBeforeAgentStart(expandedText, currentImages, this._baseSystemPromptOptions);
|
|
1286
|
-
// Handlers may edit event.systemPromptOptions.selectedTools or call setActiveTools(),
|
|
1287
|
-
// which updates the live loadout instead. An explicit edit wins; otherwise the live
|
|
1288
|
-
// loadout is authoritative, so a setActiveTools() call is not undone here.
|
|
1289
|
-
const handlerEditedTools = result.systemPromptOptions.selectedTools.length !== selectedToolsBefore.length ||
|
|
1290
|
-
result.systemPromptOptions.selectedTools.some((name, index) => name !== selectedToolsBefore[index]);
|
|
1291
|
-
if (!handlerEditedTools)
|
|
1292
|
-
result.systemPromptOptions.selectedTools = this.getActiveToolNames();
|
|
1293
|
-
const normalized = await this._normalizePromptImages(currentImages);
|
|
1294
|
-
const userText = normalized.hints.length > 0 ? `${expandedText}\n\n${normalized.hints.join("\n")}` : expandedText;
|
|
1295
|
-
// Build messages only after hooks and image normalization have completed.
|
|
1296
|
-
messages = [];
|
|
1297
|
-
const userContent = [{ type: "text", text: userText }];
|
|
1298
|
-
userContent.push(...normalized.images);
|
|
1299
|
-
messages.push({
|
|
1300
|
-
role: "user",
|
|
1301
|
-
content: userContent,
|
|
1302
|
-
timestamp: Date.now(),
|
|
1303
|
-
});
|
|
1304
|
-
// Inject any pending "nextTurn" messages as context alongside the user message
|
|
1305
|
-
for (const msg of this._pendingNextTurnMessages) {
|
|
1306
|
-
messages.push(msg);
|
|
1307
|
-
}
|
|
1308
|
-
this._pendingNextTurnMessages = [];
|
|
1309
|
-
for (const msg of result.messages) {
|
|
1310
|
-
messages.push({
|
|
1311
|
-
role: "custom",
|
|
1312
|
-
customType: msg.customType,
|
|
1313
|
-
// Untyped extensions can pass null/missing content; normalize at ingestion.
|
|
1314
|
-
content: msg.content ?? [],
|
|
1315
|
-
display: msg.display,
|
|
1316
|
-
details: msg.details,
|
|
1317
|
-
timestamp: Date.now(),
|
|
1318
|
-
});
|
|
1524
|
+
else {
|
|
1525
|
+
await this._queueSteer(expandedText, currentImages);
|
|
1319
1526
|
}
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
if (updateMessage)
|
|
1323
|
-
messages.unshift(updateMessage);
|
|
1527
|
+
preflightResult?.("queued");
|
|
1528
|
+
return;
|
|
1324
1529
|
}
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1530
|
+
// Flush any pending bash and custom messages before the new prompt
|
|
1531
|
+
this._flushPendingBashMessages();
|
|
1532
|
+
this._flushPendingCustomMessages();
|
|
1533
|
+
// Validate model
|
|
1534
|
+
if (!this.model) {
|
|
1535
|
+
throw new Error(formatNoModelSelectedMessage());
|
|
1536
|
+
}
|
|
1537
|
+
const hasConfiguredAuth = this._modelRuntime.hasConfiguredAuth(this.model.provider) ||
|
|
1538
|
+
(await this._modelRuntime.checkAuth(this.model.provider)) !== undefined;
|
|
1539
|
+
if (!hasConfiguredAuth) {
|
|
1540
|
+
const isOAuth = this._modelRuntime.isUsingOAuth(this.model.provider);
|
|
1541
|
+
if (isOAuth) {
|
|
1542
|
+
throw new Error(`Authentication failed for "${this.model.provider}". ` +
|
|
1543
|
+
`Credentials may have expired or network is unavailable. ` +
|
|
1544
|
+
`Run '/login ${this.model.provider}' to re-authenticate.`);
|
|
1545
|
+
}
|
|
1546
|
+
throw new Error(formatNoApiKeyFoundMessage(this.model.provider));
|
|
1547
|
+
}
|
|
1548
|
+
// Check if we need to compact before sending (catches aborted responses).
|
|
1549
|
+
// The user's new prompt is sent below, so do not call agent.continue() here.
|
|
1550
|
+
const lastAssistant = this._findLastAssistantMessage();
|
|
1551
|
+
if (lastAssistant) {
|
|
1552
|
+
await this._checkCompaction(lastAssistant, false);
|
|
1553
|
+
}
|
|
1554
|
+
// Emit before_agent_start before normalizing images so extension-driven model
|
|
1555
|
+
// selection determines the resize profile used for the request and history.
|
|
1556
|
+
const selectedToolsBefore = this._baseSystemPromptOptions.selectedTools;
|
|
1557
|
+
const result = await this._extensionRunner.emitBeforeAgentStart(expandedText, currentImages, this._baseSystemPromptOptions);
|
|
1558
|
+
// Handlers may edit event.systemPromptOptions.selectedTools or call setActiveTools(),
|
|
1559
|
+
// which updates the live loadout instead. An explicit edit wins; otherwise the live
|
|
1560
|
+
// loadout is authoritative, so a setActiveTools() call is not undone here.
|
|
1561
|
+
const handlerEditedTools = result.systemPromptOptions.selectedTools.length !== selectedToolsBefore.length ||
|
|
1562
|
+
result.systemPromptOptions.selectedTools.some((name, index) => name !== selectedToolsBefore[index]);
|
|
1563
|
+
if (!handlerEditedTools)
|
|
1564
|
+
result.systemPromptOptions.selectedTools = this.getActiveToolNames();
|
|
1565
|
+
const normalized = await this._normalizePromptImages(currentImages);
|
|
1566
|
+
const userText = normalized.hints.length > 0 ? `${expandedText}\n\n${normalized.hints.join("\n")}` : expandedText;
|
|
1567
|
+
// Build messages only after hooks and image normalization have completed.
|
|
1568
|
+
const messages = [];
|
|
1569
|
+
const userContent = [{ type: "text", text: userText }];
|
|
1570
|
+
userContent.push(...normalized.images);
|
|
1571
|
+
messages.push({
|
|
1572
|
+
role: "user",
|
|
1573
|
+
content: userContent,
|
|
1574
|
+
timestamp: Date.now(),
|
|
1575
|
+
});
|
|
1576
|
+
// Inject any pending "nextTurn" messages as context alongside the user message
|
|
1577
|
+
for (const msg of this._pendingNextTurnMessages) {
|
|
1578
|
+
messages.push(msg);
|
|
1328
1579
|
}
|
|
1329
|
-
|
|
1330
|
-
|
|
1580
|
+
this._pendingNextTurnMessages = [];
|
|
1581
|
+
for (const msg of result.messages) {
|
|
1582
|
+
messages.push({
|
|
1583
|
+
role: "custom",
|
|
1584
|
+
customType: msg.customType,
|
|
1585
|
+
// Untyped extensions can pass null/missing content; normalize at ingestion.
|
|
1586
|
+
content: msg.content ?? [],
|
|
1587
|
+
display: msg.display,
|
|
1588
|
+
details: msg.details,
|
|
1589
|
+
timestamp: Date.now(),
|
|
1590
|
+
});
|
|
1331
1591
|
}
|
|
1332
|
-
|
|
1592
|
+
const updateMessage = this._preparePromptAndToolLoadout(result.systemPromptOptions);
|
|
1593
|
+
this._runSystemPromptOptions = result.systemPromptOptions;
|
|
1594
|
+
if (updateMessage)
|
|
1595
|
+
messages.unshift(updateMessage);
|
|
1596
|
+
preflightResult?.("started");
|
|
1333
1597
|
await this._runAgentPrompt(messages);
|
|
1334
1598
|
}
|
|
1335
1599
|
/**
|
|
@@ -1415,7 +1679,7 @@ export class AgentSession {
|
|
|
1415
1679
|
}
|
|
1416
1680
|
const processedInput = await this._runInputHandlers(text, images, source, this.isStreaming ? behavior : undefined);
|
|
1417
1681
|
if (!processedInput)
|
|
1418
|
-
return;
|
|
1682
|
+
return "handled";
|
|
1419
1683
|
let expandedText = this._expandSkillCommand(processedInput.text);
|
|
1420
1684
|
expandedText = this._expandBareNamespaceSkillCommand(expandedText);
|
|
1421
1685
|
expandedText = expandPromptTemplate(expandedText, [...this.promptTemplates]);
|
|
@@ -1425,6 +1689,7 @@ export class AgentSession {
|
|
|
1425
1689
|
else {
|
|
1426
1690
|
await this._queueFollowUp(expandedText, processedInput.images);
|
|
1427
1691
|
}
|
|
1692
|
+
return "queued";
|
|
1428
1693
|
}
|
|
1429
1694
|
/**
|
|
1430
1695
|
* Queue a steering message while the agent is running.
|
|
@@ -1436,7 +1701,7 @@ export class AgentSession {
|
|
|
1436
1701
|
* @throws Error if text is an extension command
|
|
1437
1702
|
*/
|
|
1438
1703
|
async steer(text, images, options) {
|
|
1439
|
-
|
|
1704
|
+
return this._queueUserInput(text, images, "steer", options?.source ?? "interactive");
|
|
1440
1705
|
}
|
|
1441
1706
|
/**
|
|
1442
1707
|
* Queue a follow-up message to be processed after the agent finishes.
|
|
@@ -1447,7 +1712,7 @@ export class AgentSession {
|
|
|
1447
1712
|
* @throws Error if text is an extension command
|
|
1448
1713
|
*/
|
|
1449
1714
|
async followUp(text, images, options) {
|
|
1450
|
-
|
|
1715
|
+
return this._queueUserInput(text, images, "followUp", options?.source ?? "interactive");
|
|
1451
1716
|
}
|
|
1452
1717
|
/**
|
|
1453
1718
|
* Internal: Queue a steering message (already expanded, no extension command check).
|
|
@@ -1863,8 +2128,10 @@ export class AgentSession {
|
|
|
1863
2128
|
// Compaction
|
|
1864
2129
|
// =========================================================================
|
|
1865
2130
|
/** Generate Pi's built-in compaction summary for manual and automatic compaction. */
|
|
1866
|
-
async _runDefaultCompaction(preparation,
|
|
1867
|
-
|
|
2131
|
+
async _runDefaultCompaction(preparation, model, customInstructions, signal, reason) {
|
|
2132
|
+
// Resolve the request only when Pi summarizes itself: routing may call models or fail.
|
|
2133
|
+
const request = await this._getSummarizationRequestAuth(model, signal);
|
|
2134
|
+
return compact(preparation, request.model, request.apiKey, request.headers, customInstructions, signal, request.thinkingLevel, this.agent.streamFunction, request.env, this.settingsManager.getRetrySettings(), this._summarizationRetryCallbacks({ source: "compaction", reason }), undefined);
|
|
1868
2135
|
}
|
|
1869
2136
|
_clearManualCompactionState() {
|
|
1870
2137
|
this._compactionAbortController = undefined;
|
|
@@ -1897,7 +2164,6 @@ export class AgentSession {
|
|
|
1897
2164
|
throw new Error(formatNoModelSelectedMessage());
|
|
1898
2165
|
}
|
|
1899
2166
|
const settings = this.settingsManager.getCompactionSettings(model);
|
|
1900
|
-
const { model: requestModel, apiKey, headers, env, } = await this._getSummarizationRequestAuth(model, this._compactionAbortController.signal);
|
|
1901
2167
|
const pathEntries = this.sessionManager.getBranch();
|
|
1902
2168
|
const preparation = prepareCompaction(pathEntries, settings);
|
|
1903
2169
|
if (!preparation) {
|
|
@@ -1943,7 +2209,7 @@ export class AgentSession {
|
|
|
1943
2209
|
}
|
|
1944
2210
|
else {
|
|
1945
2211
|
// Shared default summary generator, also used by automatic compaction.
|
|
1946
|
-
const result = await this._runDefaultCompaction(preparation,
|
|
2212
|
+
const result = await this._runDefaultCompaction(preparation, model, customInstructions, this._compactionAbortController.signal, "manual");
|
|
1947
2213
|
summary = result.summary;
|
|
1948
2214
|
firstKeptEntryId = result.firstKeptEntryId;
|
|
1949
2215
|
tokensBefore = result.tokensBefore;
|
|
@@ -2054,12 +2320,14 @@ export class AgentSession {
|
|
|
2054
2320
|
// Skip if message was aborted (user cancelled) - unless skipAbortedCheck is false
|
|
2055
2321
|
if (skipAbortedCheck && assistantMessage.stopReason === "aborted")
|
|
2056
2322
|
return false;
|
|
2057
|
-
const contextWindow = this.model?.contextWindow ?? 0;
|
|
2058
2323
|
// Skip overflow check if the message came from a different model.
|
|
2059
2324
|
// This handles the case where user switched from a smaller-context model (e.g. opus)
|
|
2060
2325
|
// to a larger-context model (e.g. codex) - the overflow error from the old model
|
|
2061
|
-
// shouldn't trigger compaction for the new model.
|
|
2062
|
-
|
|
2326
|
+
// shouldn't trigger compaction for the new model. Under a virtual selection, the
|
|
2327
|
+
// physical model that produced the message supplies the limits.
|
|
2328
|
+
const messageModel = this._modelForMessage(assistantMessage);
|
|
2329
|
+
const sameModel = messageModel !== undefined;
|
|
2330
|
+
const contextWindow = (messageModel ?? this.model)?.contextWindow ?? 0;
|
|
2063
2331
|
// Skip compaction checks if this assistant message is older than the latest
|
|
2064
2332
|
// compaction boundary. This prevents a stale pre-compaction usage/error
|
|
2065
2333
|
// from retriggering compaction on the first prompt after compaction.
|
|
@@ -2091,7 +2359,7 @@ export class AgentSession {
|
|
|
2091
2359
|
const contextOverflow = sameModel &&
|
|
2092
2360
|
((explicitOverflow && assistantRetainedForExplicitRecovery) ||
|
|
2093
2361
|
(assistantUsageMatchesProjection && isContextOverflow(assistantMessage, contextWindow)));
|
|
2094
|
-
const recoverableLength = sameModel && assistantIsProjected && isRecoverableLength(assistantMessage,
|
|
2362
|
+
const recoverableLength = sameModel && assistantIsProjected && isRecoverableLength(assistantMessage, messageModel.maxTokens);
|
|
2095
2363
|
if (contextOverflow || recoverableLength) {
|
|
2096
2364
|
const willRetry = assistantMessage.stopReason !== "stop";
|
|
2097
2365
|
// Case 2: the response completed successfully. Compact, but do not retry because
|
|
@@ -2123,7 +2391,10 @@ export class AgentSession {
|
|
|
2123
2391
|
// Persistently omit the selected final attempt before post-run recovery compaction.
|
|
2124
2392
|
this._overflowRecoveryAttempted = true;
|
|
2125
2393
|
this._omitRecoveryAttempt(assistantMessage, toolResults);
|
|
2126
|
-
|
|
2394
|
+
const retry = await this._runAutoCompaction("overflow", willRetry);
|
|
2395
|
+
if (retry)
|
|
2396
|
+
this._failedResponse = assistantMessage;
|
|
2397
|
+
return retry;
|
|
2127
2398
|
}
|
|
2128
2399
|
// Case 3: threshold compaction without retry.
|
|
2129
2400
|
// For error messages or all-zero usage messages, estimate from the last valid response.
|
|
@@ -2193,8 +2464,6 @@ export class AgentSession {
|
|
|
2193
2464
|
started = true;
|
|
2194
2465
|
this._emit({ type: "compaction_start", reason });
|
|
2195
2466
|
abortController.signal.throwIfAborted();
|
|
2196
|
-
const { model: requestModel, apiKey, headers, env, } = await this._getSummarizationRequestAuth(model, abortController.signal);
|
|
2197
|
-
abortController.signal.throwIfAborted();
|
|
2198
2467
|
let extensionCompaction;
|
|
2199
2468
|
if (this._extensionRunner.hasHandlers("session_before_compact")) {
|
|
2200
2469
|
const extensionResult = (await this._extensionRunner.emit({
|
|
@@ -2231,7 +2500,7 @@ export class AgentSession {
|
|
|
2231
2500
|
}
|
|
2232
2501
|
else {
|
|
2233
2502
|
// Shared default summary generator, also used by manual compaction.
|
|
2234
|
-
const compactResult = await this._runDefaultCompaction(preparation,
|
|
2503
|
+
const compactResult = await this._runDefaultCompaction(preparation, model, undefined, abortController.signal, reason);
|
|
2235
2504
|
summary = compactResult.summary;
|
|
2236
2505
|
firstKeptEntryId = compactResult.firstKeptEntryId;
|
|
2237
2506
|
tokensBefore = compactResult.tokensBefore;
|
|
@@ -2334,6 +2603,7 @@ export class AgentSession {
|
|
|
2334
2603
|
}
|
|
2335
2604
|
this._applyExtensionBindings(this._extensionRunner);
|
|
2336
2605
|
await this._extensionRunner.emit(this._sessionStartEvent);
|
|
2606
|
+
this._extensionRunner.reportUnhandledMcpServers();
|
|
2337
2607
|
await this.extendResourcesFromExtensions(this._sessionStartEvent.reason === "reload" ? "reload" : "startup");
|
|
2338
2608
|
}
|
|
2339
2609
|
async extendResourcesFromExtensions(reason) {
|
|
@@ -2355,7 +2625,7 @@ export class AgentSession {
|
|
|
2355
2625
|
buildExtensionResourcePaths(entries) {
|
|
2356
2626
|
return entries.map((entry) => {
|
|
2357
2627
|
const source = this.getExtensionSourceLabel(entry.extensionPath);
|
|
2358
|
-
const baseDir = entry.extensionPath
|
|
2628
|
+
const baseDir = isSyntheticPath(entry.extensionPath) ? undefined : dirname(entry.extensionPath);
|
|
2359
2629
|
return {
|
|
2360
2630
|
path: entry.path,
|
|
2361
2631
|
metadata: {
|
|
@@ -2368,7 +2638,7 @@ export class AgentSession {
|
|
|
2368
2638
|
});
|
|
2369
2639
|
}
|
|
2370
2640
|
getExtensionSourceLabel(extensionPath) {
|
|
2371
|
-
if (extensionPath
|
|
2641
|
+
if (isSyntheticPath(extensionPath)) {
|
|
2372
2642
|
return `extension:${extensionPath.replace(/[<>]/g, "")}`;
|
|
2373
2643
|
}
|
|
2374
2644
|
const base = basename(extensionPath);
|
|
@@ -2453,6 +2723,7 @@ export class AgentSession {
|
|
|
2453
2723
|
},
|
|
2454
2724
|
getActiveTools: () => this.getActiveToolNames(),
|
|
2455
2725
|
getAllTools: () => this.getAllTools(),
|
|
2726
|
+
getSettings: () => this.settingsManager.getSettings(),
|
|
2456
2727
|
setActiveTools: (toolNames) => this.setActiveToolsByName(toolNames),
|
|
2457
2728
|
refreshTools: () => this._refreshToolRegistry(),
|
|
2458
2729
|
getCommands,
|
|
@@ -2496,6 +2767,8 @@ export class AgentSession {
|
|
|
2496
2767
|
},
|
|
2497
2768
|
getSystemPrompt: () => this.systemPrompt,
|
|
2498
2769
|
getSystemPromptOptions: () => this._baseSystemPromptOptions,
|
|
2770
|
+
executeTool: (callerId, name, args, options) => this._executeNestedToolCall(callerId, name, args, options),
|
|
2771
|
+
getCallableTools: () => this._getCallableTools(),
|
|
2499
2772
|
}, {
|
|
2500
2773
|
registerProvider: (name, config) => {
|
|
2501
2774
|
this._modelRuntime.registerProvider(name, config);
|
|
@@ -2509,14 +2782,22 @@ export class AgentSession {
|
|
|
2509
2782
|
this._modelRuntime.unregisterProvider(name);
|
|
2510
2783
|
this._refreshCurrentModelFromRegistry();
|
|
2511
2784
|
},
|
|
2785
|
+
registerVirtualModel: (definition) => {
|
|
2786
|
+
this._modelRuntime.registerVirtualModel(definition);
|
|
2787
|
+
this._refreshCurrentModelFromRegistry();
|
|
2788
|
+
},
|
|
2789
|
+
unregisterVirtualModel: (provider, id) => {
|
|
2790
|
+
this._modelRuntime.unregisterVirtualModel(provider, id);
|
|
2791
|
+
this._refreshCurrentModelFromRegistry();
|
|
2792
|
+
},
|
|
2512
2793
|
});
|
|
2513
2794
|
}
|
|
2514
2795
|
_refreshToolRegistry(options) {
|
|
2515
|
-
|
|
2796
|
+
// Tools that were already activated on registration. A tool whose exposure changes to
|
|
2797
|
+
// `direct` or `model-only` (for example from `hidden`) is activated like a new tool.
|
|
2798
|
+
const previousActivatedOnRegistration = new Set([...this._toolRegistry.keys()].filter((name) => this._isActivatedOnRegistration(name)));
|
|
2516
2799
|
const previousActiveToolNames = this.getActiveToolNames();
|
|
2517
2800
|
const allowedToolNames = this._allowedToolNames;
|
|
2518
|
-
const excludedToolNames = this._excludedToolNames;
|
|
2519
|
-
const isAllowedTool = (name) => (!allowedToolNames || allowedToolNames.has(name)) && !excludedToolNames?.has(name);
|
|
2520
2801
|
const registeredTools = this._extensionRunner.getAllRegisteredTools();
|
|
2521
2802
|
const allCustomTools = [
|
|
2522
2803
|
...registeredTools,
|
|
@@ -2524,14 +2805,14 @@ export class AgentSession {
|
|
|
2524
2805
|
definition,
|
|
2525
2806
|
sourceInfo: createSyntheticSourceInfo(`<sdk:${definition.name}>`, { source: "sdk" }),
|
|
2526
2807
|
})),
|
|
2527
|
-
].filter((tool) =>
|
|
2808
|
+
].filter((tool) => this._isAllowedTool(tool.definition.name));
|
|
2528
2809
|
const definitionRegistry = new Map(Array.from(this._baseToolDefinitions.entries())
|
|
2529
|
-
.filter(([name]) =>
|
|
2810
|
+
.filter(([name]) => this._isAllowedTool(name))
|
|
2530
2811
|
.map(([name, definition]) => [
|
|
2531
2812
|
name,
|
|
2532
2813
|
{
|
|
2533
2814
|
definition,
|
|
2534
|
-
sourceInfo: createSyntheticSourceInfo(
|
|
2815
|
+
sourceInfo: createSyntheticSourceInfo(`${BUILTIN_PATH_PREFIX}${name}`, { source: "builtin" }),
|
|
2535
2816
|
},
|
|
2536
2817
|
]));
|
|
2537
2818
|
for (const tool of allCustomTools) {
|
|
@@ -2556,37 +2837,52 @@ export class AgentSession {
|
|
|
2556
2837
|
const runner = this._extensionRunner;
|
|
2557
2838
|
const wrappedExtensionTools = wrapRegisteredTools(allCustomTools, runner);
|
|
2558
2839
|
const wrappedBuiltInTools = wrapRegisteredTools(Array.from(this._baseToolDefinitions.values())
|
|
2559
|
-
.filter((definition) =>
|
|
2840
|
+
.filter((definition) => this._isAllowedTool(definition.name))
|
|
2560
2841
|
.map((definition) => ({
|
|
2561
2842
|
definition,
|
|
2562
|
-
sourceInfo: createSyntheticSourceInfo(
|
|
2843
|
+
sourceInfo: createSyntheticSourceInfo(`${BUILTIN_PATH_PREFIX}${definition.name}`, {
|
|
2844
|
+
source: "builtin",
|
|
2845
|
+
}),
|
|
2563
2846
|
})), runner);
|
|
2564
2847
|
const toolRegistry = new Map(wrappedBuiltInTools.map((tool) => [tool.name, tool]));
|
|
2565
2848
|
for (const tool of wrappedExtensionTools) {
|
|
2566
2849
|
toolRegistry.set(tool.name, tool);
|
|
2567
2850
|
}
|
|
2568
2851
|
this._toolRegistry = toolRegistry;
|
|
2569
|
-
const nextActiveToolNames = (options?.activeToolNames ? [...options.activeToolNames] : [...previousActiveToolNames]).filter((name) =>
|
|
2852
|
+
const nextActiveToolNames = (options?.activeToolNames ? [...options.activeToolNames] : [...previousActiveToolNames]).filter((name) => this._isAllowedTool(name));
|
|
2570
2853
|
if (allowedToolNames) {
|
|
2571
2854
|
for (const toolName of this._toolRegistry.keys()) {
|
|
2572
|
-
|
|
2855
|
+
// Naming a tool activates it even when it is not active by default.
|
|
2856
|
+
if (allowedToolNames.has(toolName) && this._isDeclarable(toolName)) {
|
|
2573
2857
|
nextActiveToolNames.push(toolName);
|
|
2574
2858
|
}
|
|
2575
2859
|
}
|
|
2576
2860
|
}
|
|
2577
2861
|
else if (options?.includeAllExtensionTools) {
|
|
2578
2862
|
for (const tool of wrappedExtensionTools) {
|
|
2579
|
-
|
|
2863
|
+
if (this._isActivatedOnRegistration(tool.name))
|
|
2864
|
+
nextActiveToolNames.push(tool.name);
|
|
2580
2865
|
}
|
|
2581
2866
|
}
|
|
2582
2867
|
else if (!options?.activeToolNames) {
|
|
2583
2868
|
for (const toolName of this._toolRegistry.keys()) {
|
|
2584
|
-
if (!
|
|
2869
|
+
if (!previousActivatedOnRegistration.has(toolName) && this._isActivatedOnRegistration(toolName)) {
|
|
2585
2870
|
nextActiveToolNames.push(toolName);
|
|
2586
2871
|
}
|
|
2587
2872
|
}
|
|
2588
2873
|
}
|
|
2589
|
-
|
|
2874
|
+
// Pending tools that are registered now become active.
|
|
2875
|
+
nextActiveToolNames.push(...this._pendingToolNames);
|
|
2876
|
+
this._setActiveTools([...new Set(nextActiveToolNames)]);
|
|
2877
|
+
}
|
|
2878
|
+
/** Whether activating the tool declares it to the model. */
|
|
2879
|
+
_isDeclarable(name) {
|
|
2880
|
+
const exposure = this._getToolExposure(name);
|
|
2881
|
+
return exposure === "direct" || exposure === "model-only";
|
|
2882
|
+
}
|
|
2883
|
+
/** Whether registering the tool activates it, which declares it to the model. */
|
|
2884
|
+
_isActivatedOnRegistration(name) {
|
|
2885
|
+
return this._isDeclarable(name) && this._toolDefinitions.get(name)?.definition.defaultActive !== false;
|
|
2590
2886
|
}
|
|
2591
2887
|
_buildRuntime(options) {
|
|
2592
2888
|
const autoResizeImages = this.settingsManager.getImageAutoResize();
|
|
@@ -2628,12 +2924,21 @@ export class AgentSession {
|
|
|
2628
2924
|
const previousFlagValues = oldRunner.getFlagValues();
|
|
2629
2925
|
await emitSessionShutdownEvent(oldRunner, { type: "session_shutdown", reason: "reload" });
|
|
2630
2926
|
oldRunner.invalidate();
|
|
2927
|
+
const previousDefaultTools = new Set(this._usesDefaultTools ? (this.settingsManager.getDefaultTools() ?? DEFAULT_TOOL_NAMES) : []);
|
|
2631
2928
|
await this.settingsManager.reload();
|
|
2632
2929
|
this.syncQueueModesFromSettings();
|
|
2633
2930
|
resetApiProviders();
|
|
2634
2931
|
await this._resourceLoader.reload();
|
|
2932
|
+
// Activate tools newly added to defaultTools. Removed ones stay active, and tools disabled
|
|
2933
|
+
// during the session stay disabled unless the setting newly adds them.
|
|
2934
|
+
const addedDefaultTools = this._usesDefaultTools
|
|
2935
|
+
? (this.settingsManager.getDefaultTools() ?? DEFAULT_TOOL_NAMES).filter((name) => !previousDefaultTools.has(name))
|
|
2936
|
+
: [];
|
|
2937
|
+
// Tools the new extensions register later, such as MCP tools, are pending until then.
|
|
2938
|
+
for (const name of this.getActiveToolNames())
|
|
2939
|
+
this._pendingToolNames.add(name);
|
|
2635
2940
|
this._buildRuntime({
|
|
2636
|
-
activeToolNames: this.getActiveToolNames(),
|
|
2941
|
+
activeToolNames: [...this.getActiveToolNames(), ...addedDefaultTools],
|
|
2637
2942
|
flagValues: previousFlagValues,
|
|
2638
2943
|
includeAllExtensionTools: true,
|
|
2639
2944
|
});
|
|
@@ -2644,6 +2949,7 @@ export class AgentSession {
|
|
|
2644
2949
|
if (hasBindings) {
|
|
2645
2950
|
await options?.beforeSessionStart?.();
|
|
2646
2951
|
await this._extensionRunner.emit({ type: "session_start", reason: "reload" });
|
|
2952
|
+
this._extensionRunner.reportUnhandledMcpServers();
|
|
2647
2953
|
await this.extendResourcesFromExtensions("reload");
|
|
2648
2954
|
}
|
|
2649
2955
|
}
|
|
@@ -2656,7 +2962,7 @@ export class AgentSession {
|
|
|
2656
2962
|
*/
|
|
2657
2963
|
_isRetryableError(message) {
|
|
2658
2964
|
// Context overflow is handled by compaction, not retry.
|
|
2659
|
-
if (isContextOverflow(message, this.model?.contextWindow ?? 0))
|
|
2965
|
+
if (isContextOverflow(message, (this._modelForMessage(message) ?? this.model)?.contextWindow ?? 0))
|
|
2660
2966
|
return false;
|
|
2661
2967
|
return isRetryableAssistantError(message);
|
|
2662
2968
|
}
|
|
@@ -2946,15 +3252,11 @@ export class AgentSession {
|
|
|
2946
3252
|
let summaryDetails;
|
|
2947
3253
|
let summaryUsage;
|
|
2948
3254
|
if (options.summarize && entriesToSummarize.length > 0 && !extensionSummary) {
|
|
2949
|
-
const
|
|
2950
|
-
const { model: requestModel, apiKey, headers, env } = await this._getSummarizationRequestAuth(model);
|
|
3255
|
+
const signal = this._branchSummaryAbortController.signal;
|
|
2951
3256
|
const branchSummarySettings = this.settingsManager.getBranchSummarySettings();
|
|
2952
3257
|
const result = await generateBranchSummary(entriesToSummarize, {
|
|
2953
|
-
model
|
|
2954
|
-
|
|
2955
|
-
headers,
|
|
2956
|
-
env,
|
|
2957
|
-
signal: this._branchSummaryAbortController.signal,
|
|
3258
|
+
...(await this._getSummarizationRequestAuth(this.model, signal)),
|
|
3259
|
+
signal,
|
|
2958
3260
|
customInstructions,
|
|
2959
3261
|
replaceInstructions,
|
|
2960
3262
|
reserveTokens: branchSummarySettings.reserveTokens,
|
|
@@ -3119,7 +3421,7 @@ export class AgentSession {
|
|
|
3119
3421
|
};
|
|
3120
3422
|
}
|
|
3121
3423
|
getContextUsage() {
|
|
3122
|
-
const model = this.
|
|
3424
|
+
const model = this._limitsModel();
|
|
3123
3425
|
if (!model)
|
|
3124
3426
|
return undefined;
|
|
3125
3427
|
const contextWindow = model.contextWindow ?? 0;
|
|
@@ -3191,16 +3493,11 @@ export class AgentSession {
|
|
|
3191
3493
|
if (!model) {
|
|
3192
3494
|
throw new Error("No model selected");
|
|
3193
3495
|
}
|
|
3194
|
-
const { model: requestModel, apiKey, headers, env } = await this._getSummarizationRequestAuth(model);
|
|
3195
3496
|
return generateBugReportSummary({
|
|
3497
|
+
...(await this._getSummarizationRequestAuth(model, options.signal)),
|
|
3196
3498
|
messages: this.messages,
|
|
3197
3499
|
hint: options.hint,
|
|
3198
|
-
model: requestModel,
|
|
3199
|
-
apiKey,
|
|
3200
|
-
headers,
|
|
3201
|
-
env,
|
|
3202
3500
|
signal: options.signal,
|
|
3203
|
-
thinkingLevel: this.thinkingLevel,
|
|
3204
3501
|
streamFn: this.agent.streamFunction,
|
|
3205
3502
|
retry: this.settingsManager.getRetrySettings(),
|
|
3206
3503
|
sessionId: this.sessionId,
|