dal-code 1.0.50 → 1.0.52
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 +1050 -5
- package/NOTICE +17 -1
- package/dist/bundle/chunks/anthropic-messages-NK5NGKAI.js +5 -0
- package/dist/bundle/chunks/anthropic.js +74 -0
- package/dist/bundle/chunks/azure-openai-responses-VEASENYL.js +1 -0
- package/dist/bundle/chunks/bedrock-converse-stream.js +88 -0
- package/dist/bundle/chunks/chunk-3YGHTGYM.js +7 -0
- package/dist/bundle/chunks/chunk-4LDEEFCY.js +1 -0
- package/dist/bundle/chunks/chunk-4UTLMBZZ.js +13 -0
- package/dist/bundle/chunks/chunk-4VJJ6NXH.js +8 -0
- package/dist/bundle/chunks/chunk-567OJLS7.js +1 -0
- package/dist/bundle/chunks/chunk-5AGIVGSV.js +5 -0
- package/dist/bundle/chunks/chunk-6EEJ4MZH.js +1 -0
- package/dist/bundle/chunks/chunk-6QGV3IWD.js +5 -0
- package/dist/bundle/chunks/chunk-723ZGEZ2.js +1 -0
- package/dist/bundle/chunks/chunk-7DDKXS2Q.js +1 -0
- package/dist/bundle/chunks/chunk-7ZC4UXSL.js +1 -0
- package/dist/bundle/chunks/chunk-A5CI3CVQ.js +1 -0
- package/dist/bundle/chunks/chunk-AAQZXQA7.js +1 -0
- package/dist/bundle/chunks/chunk-ANL2BCIQ.js +15 -0
- package/dist/bundle/chunks/chunk-CF5GWZHW.js +30 -0
- package/dist/bundle/chunks/chunk-CS4T4O5O.js +1 -0
- package/dist/bundle/chunks/chunk-D2WTLI2T.js +19 -0
- package/dist/bundle/chunks/chunk-DLKRCASW.js +17 -0
- package/dist/bundle/chunks/chunk-EH7SFF47.js +129 -0
- package/dist/bundle/chunks/chunk-FFMDRXC4.js +9 -0
- package/dist/bundle/chunks/chunk-HEFI7NO7.js +1 -0
- package/dist/bundle/chunks/chunk-IEBK4HQA.js +1 -0
- package/dist/bundle/chunks/chunk-JXWJOIH4.js +1 -0
- package/dist/bundle/chunks/chunk-K7VBBYTT.js +1 -0
- package/dist/bundle/chunks/chunk-KJW3E2CB.js +9 -0
- package/dist/bundle/chunks/chunk-L2ZPNLYD.js +1 -0
- package/dist/bundle/chunks/chunk-LVVZS2NO.js +11 -0
- package/dist/bundle/chunks/chunk-ML5DIOWR.js +1 -0
- package/dist/bundle/chunks/chunk-ON7ZX67F.js +30 -0
- package/dist/bundle/chunks/chunk-OQWPBJCS.js +81 -0
- package/dist/bundle/chunks/chunk-P7FPUEYA.js +1 -0
- package/dist/bundle/chunks/chunk-PGXDEOVV.js +1 -0
- package/dist/bundle/chunks/chunk-PJACZCIR.js +1 -0
- package/dist/bundle/chunks/chunk-PRRNXB7S.js +1 -0
- package/dist/bundle/chunks/chunk-R47JBGS3.js +1 -0
- package/dist/bundle/chunks/chunk-RDZVAGPR.js +1 -0
- package/dist/bundle/chunks/chunk-SE42OS3U.js +21 -0
- package/dist/bundle/chunks/chunk-TK2WJTRC.js +3 -0
- package/dist/bundle/chunks/chunk-TMTOQ7H7.js +1 -0
- package/dist/bundle/chunks/chunk-UTB4DTYQ.js +1 -0
- package/dist/bundle/chunks/chunk-UVKMBM5X.js +56 -0
- package/dist/bundle/chunks/chunk-WIZGOHKY.js +9 -0
- package/dist/bundle/chunks/chunk-XAS5HHBW.js +1180 -0
- package/dist/bundle/chunks/chunk-XDBGA662.js +43 -0
- package/dist/bundle/chunks/chunk-XJFQKN3N.js +2 -0
- package/dist/bundle/chunks/chunk-YWNDPXVM.js +25 -0
- package/dist/bundle/chunks/chunk-ZG74NES2.js +1 -0
- package/dist/bundle/chunks/cli-GXB5WYKG.js +52 -0
- package/dist/bundle/chunks/cli-YPE3BB5X.js +30 -0
- package/dist/bundle/chunks/cloudflare-workers-ai-system-one-B7WOBGWO.js +1 -0
- package/dist/bundle/chunks/codemode-worker.js +480 -0
- package/dist/bundle/chunks/dist-D3WIBXB5.js +10 -0
- package/dist/bundle/chunks/easter-egg-3d-5TFBCTIS.js +1 -0
- package/dist/bundle/chunks/execute-27QCJECT.js +506 -0
- package/dist/bundle/chunks/github-copilot.js +1 -0
- package/dist/bundle/chunks/google-generative-ai-MBMRBHSZ.js +1 -0
- package/dist/bundle/chunks/google-vertex-S2ZFBDPP.js +1 -0
- package/dist/bundle/chunks/http-proxy-KF35JLJN.js +1 -0
- package/dist/bundle/chunks/https-proxy-agent-LVOO5TPL.js +12 -0
- package/dist/bundle/chunks/image-resize-worker.js +1 -0
- package/dist/bundle/chunks/jiti-loader-GL4HJFAD.js +20 -0
- package/dist/bundle/chunks/jiti-static-loader-2RCDI6B4.js +1 -0
- package/dist/bundle/chunks/kimi-coding.js +1 -0
- package/dist/bundle/chunks/lib-4AVRLBHM.js +8 -0
- package/dist/bundle/chunks/llama-cpp-classify-S4LVGNNY.js +21 -0
- package/dist/bundle/chunks/mcp-6LJKGKJQ.js +10 -0
- package/dist/bundle/chunks/meta.js +1 -0
- package/dist/bundle/chunks/mistral-conversations-C7LUXIEY.js +4 -0
- package/dist/bundle/chunks/multipart-parser-FMGQ7342.js +2 -0
- package/dist/bundle/chunks/node-AUOGOBCN.js +1 -0
- package/dist/bundle/chunks/node-ZTHARAQV.js +15 -0
- package/dist/bundle/chunks/office-5OWKTZOA.js +419 -0
- package/dist/bundle/chunks/openai-chatgpt.js +74 -0
- package/dist/bundle/chunks/openai-codex-responses-YQQXJ24E.js +9 -0
- package/dist/bundle/chunks/openai-codex.js +74 -0
- package/dist/bundle/chunks/openai-completions-7CMH2FKD.js +6 -0
- package/dist/bundle/chunks/openai-decisions-AOGZTREY.js +4 -0
- package/dist/bundle/chunks/openai-responses-ZSOGZ3MK.js +3 -0
- package/dist/bundle/chunks/openrouter-images-AHXST2TH.js +1 -0
- package/dist/bundle/chunks/openrouter.js +74 -0
- package/dist/bundle/chunks/pi-messages-QERJLMZ6.js +7 -0
- package/dist/bundle/chunks/radius.js +74 -0
- package/dist/bundle/chunks/review-5G56KIWY.js +80 -0
- package/dist/bundle/chunks/rewind-2OYLDDHH.js +8 -0
- package/dist/bundle/chunks/router-776Z7G7G.js +3 -0
- package/dist/bundle/chunks/runtime-NKPT25KD.js +1 -0
- package/dist/bundle/chunks/sdk-TVC4GDUX.js +1 -0
- package/dist/bundle/chunks/src-QKGKDFSU.js +3 -0
- package/dist/bundle/chunks/sync-JBDC3YBK.js +7 -0
- package/dist/bundle/chunks/typesafe-system-one-MMNGGQ46.js +1 -0
- package/dist/bundle/chunks/usage-BDCIALHO.js +1 -0
- package/dist/bundle/chunks/virtual-modules-25RQ6XTV.js +1 -0
- package/dist/bundle/chunks/xai.js +1 -0
- package/dist/bundle/cli-runtime.js +2 -0
- package/dist/bundle/cli.js +2 -0
- package/dist/bundle/index.js +1 -0
- package/dist/bundle/rpc-entry.js +2 -0
- package/dist/cli/args.js +1 -1
- package/dist/cli/auth-command.js +9 -6
- package/dist/cli/auth-login.js +2 -0
- package/dist/cli/auth-logout.js +1 -0
- package/dist/cli/auth-terminal.js +5 -0
- package/dist/cli/config-selector.js +1 -1
- package/dist/config.d.ts +5 -0
- package/dist/config.js +1 -1
- package/dist/core/agent-session-runtime.js +1 -1
- package/dist/core/agent-session-services.js +1 -1
- package/dist/core/agent-session.d.ts +8 -1
- package/dist/core/agent-session.js +12 -9
- package/dist/core/auth-storage.js +1 -1
- package/dist/core/bash-executor.js +1 -1
- package/dist/core/bug-report.js +3 -3
- package/dist/core/cache-warmer.d.ts +3 -15
- package/dist/core/cache-warmer.js +1 -1
- package/dist/core/compaction/branch-summarization.d.ts +3 -2
- package/dist/core/compaction/branch-summarization.js +5 -5
- package/dist/core/compaction/compaction.d.ts +1 -0
- package/dist/core/compaction/compaction.js +14 -14
- package/dist/core/compaction/tool-output-pruning.js +1 -1
- package/dist/core/compaction/utils.d.ts +0 -1
- package/dist/core/compaction/utils.js +8 -8
- package/dist/core/exec.d.ts +2 -0
- package/dist/core/exec.js +1 -1
- package/dist/core/export-html/template.css +9 -0
- package/dist/core/export-html/template.js +46 -39
- package/dist/core/export-html/tool-renderer.js +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/loader.js +1 -1
- package/dist/core/extensions/pi-ai-extension-view.js +1 -0
- package/dist/core/extensions/runner.js +1 -1
- package/dist/core/extensions/types.d.ts +25 -7
- package/dist/core/extensions/virtual-modules.js +1 -1
- package/dist/core/keybindings.d.ts +1 -1
- package/dist/core/keybindings.js +1 -1
- package/dist/core/mcp-servers.d.ts +6 -17
- package/dist/core/mcp-servers.js +1 -1
- package/dist/core/model-config.d.ts +1912 -2211
- package/dist/core/model-config.js +4 -4
- package/dist/core/model-resolver.js +1 -1
- package/dist/core/model-runtime.d.ts +1 -0
- package/dist/core/model-runtime.js +1 -1
- package/dist/core/package-manager.d.ts +10 -1
- package/dist/core/package-manager.js +2 -2
- package/dist/core/pi-ai-schemas.js +1 -0
- package/dist/core/pi-manifest.js +1 -1
- package/dist/core/preferred-providers.js +1 -0
- package/dist/core/project-trust.js +2 -2
- package/dist/core/prompt-templates.js +2 -2
- package/dist/core/provider-composer.js +1 -1
- package/dist/core/provider-matching.js +1 -0
- package/dist/core/radius-mcp.js +1 -0
- package/dist/core/remote-catalog-provider.js +1 -1
- package/dist/core/resource-loader.d.ts +3 -1
- package/dist/core/resource-loader.js +1 -1
- package/dist/core/runtime-credentials.js +1 -1
- package/dist/core/sdk.js +1 -1
- package/dist/core/session-cwd.js +3 -7
- package/dist/core/session-manager.d.ts +1 -0
- package/dist/core/session-manager.js +12 -12
- package/dist/core/settings-defaults.js +1 -1
- package/dist/core/settings-manager.d.ts +4 -0
- package/dist/core/settings-manager.js +1 -1
- package/dist/core/settings-schema.d.ts +4 -2
- package/dist/core/settings-schema.js +1 -1
- package/dist/core/skills.js +3 -3
- package/dist/core/slash-commands.js +1 -1
- package/dist/core/source-info.d.ts +8 -0
- package/dist/core/source-info.js +1 -1
- package/dist/core/system-prompt.js +3 -3
- package/dist/core/tools/bash.d.ts +2 -2
- package/dist/core/tools/bash.js +15 -15
- package/dist/core/tools/edit-diff.d.ts +9 -4
- package/dist/core/tools/edit-diff.js +22 -15
- package/dist/core/tools/edit.d.ts +3 -3
- package/dist/core/tools/edit.js +3 -3
- package/dist/core/tools/find.d.ts +2 -2
- package/dist/core/tools/find.js +10 -11
- package/dist/core/tools/grep.d.ts +3 -3
- package/dist/core/tools/grep.js +8 -12
- package/dist/core/tools/ls.d.ts +2 -2
- package/dist/core/tools/ls.js +4 -4
- package/dist/core/tools/powershell.js +6 -2
- package/dist/core/tools/read.d.ts +5 -2
- package/dist/core/tools/read.js +20 -19
- package/dist/core/tools/render-utils.js +5 -5
- package/dist/core/tools/renderers/write.js +10 -10
- package/dist/core/tools/tool-definition-wrapper.d.ts +11 -0
- package/dist/core/tools/truncate.d.ts +2 -8
- package/dist/core/tools/truncate.js +10 -10
- package/dist/core/tools/write.d.ts +2 -2
- package/dist/core/trust-manager.js +2 -2
- package/dist/core/usage-totals.js +1 -1
- package/dist/dal/builtins.js +2 -2
- package/dist/dal/manifest.d.ts +1 -0
- package/dist/dal/manifest.js +1 -1
- package/dist/dal/safety-net.js +11 -3
- package/dist/extensions/codemode/execute.js +12 -12
- package/dist/extensions/codemode/renderer.js +6 -6
- package/dist/extensions/codemode/tool.d.ts +2 -1
- package/dist/extensions/codemode/tool.js +11 -10
- package/dist/extensions/llama/client.js +5 -5
- package/dist/extensions/llama/ui.js +2 -2
- package/dist/extensions/mcp/cli.js +21 -19
- package/dist/extensions/mcp/config.js +2 -2
- package/dist/extensions/mcp/index.js +7 -7
- package/dist/extensions/mcp/oauth.d.ts +3 -22
- package/dist/extensions/mcp/oauth.js +2 -2
- package/dist/extensions/mcp/resources.d.ts +1 -1
- package/dist/extensions/mcp/resources.js +1 -1
- package/dist/extensions/mcp/runtime.d.ts +2 -2
- package/dist/extensions/mcp/runtime.js +3 -3
- package/dist/extensions/mcp/tools.d.ts +1 -8
- package/dist/extensions/mcp/tools.js +4 -9
- package/dist/extensions/mcp/ui.js +1 -1
- package/dist/extensions/tool-search/tool.js +4 -4
- package/dist/index.d.ts +2 -2
- package/dist/main.js +4 -4
- package/dist/modes/interactive/components/assistant-message.d.ts +4 -1
- package/dist/modes/interactive/components/assistant-message.js +2 -2
- package/dist/modes/interactive/components/branch-summary-message.d.ts +5 -1
- package/dist/modes/interactive/components/branch-summary-message.js +2 -2
- package/dist/modes/interactive/components/compaction-summary-message.d.ts +5 -1
- package/dist/modes/interactive/components/compaction-summary-message.js +2 -2
- package/dist/modes/interactive/components/config-selector.js +1 -1
- package/dist/modes/interactive/components/custom-editor.js +1 -1
- package/dist/modes/interactive/components/custom-entry.js +1 -1
- package/dist/modes/interactive/components/custom-message.d.ts +5 -2
- package/dist/modes/interactive/components/custom-message.js +3 -3
- package/dist/modes/interactive/components/diff.js +3 -3
- package/dist/modes/interactive/components/extension-editor.d.ts +1 -0
- package/dist/modes/interactive/components/extension-editor.js +1 -1
- package/dist/modes/interactive/components/extension-selector.js +2 -2
- package/dist/modes/interactive/components/login-dialog.d.ts +5 -0
- package/dist/modes/interactive/components/login-dialog.js +1 -1
- package/dist/modes/interactive/components/markdown-transform.js +1 -1
- package/dist/modes/interactive/components/mermaid.js +4 -4
- package/dist/modes/interactive/components/model-selector.d.ts +1 -0
- package/dist/modes/interactive/components/model-selector.js +2 -2
- package/dist/modes/interactive/components/oauth-selector.d.ts +2 -1
- package/dist/modes/interactive/components/oauth-selector.js +1 -1
- package/dist/modes/interactive/components/provider-brand.js +1 -0
- package/dist/modes/interactive/components/radius-login-selector.js +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.d.ts +1 -0
- package/dist/modes/interactive/components/scoped-models-selector.js +1 -1
- package/dist/modes/interactive/components/session-selector-search.js +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts +2 -1
- package/dist/modes/interactive/components/session-selector.js +2 -2
- package/dist/modes/interactive/components/settings-submenu.js +1 -1
- package/dist/modes/interactive/components/skill-invocation-message.d.ts +5 -1
- package/dist/modes/interactive/components/skill-invocation-message.js +2 -2
- package/dist/modes/interactive/components/tool-execution.d.ts +1 -0
- package/dist/modes/interactive/components/tool-execution.js +3 -3
- package/dist/modes/interactive/components/tree-selector.d.ts +2 -0
- package/dist/modes/interactive/components/tree-selector.js +1 -1
- package/dist/modes/interactive/components/user-message-selector.d.ts +1 -0
- package/dist/modes/interactive/components/user-message-selector.js +1 -1
- package/dist/modes/interactive/components/user-message.d.ts +2 -1
- package/dist/modes/interactive/components/user-message.js +1 -1
- package/dist/modes/interactive/external-editor.js +3 -3
- package/dist/modes/interactive/interactive-mode.d.ts +10 -1
- package/dist/modes/interactive/interactive-mode.js +45 -40
- package/dist/modes/interactive/model-search.js +1 -1
- package/dist/modes/interactive/theme/theme.d.ts +4 -0
- package/dist/modes/interactive/theme/theme.js +3 -6
- package/dist/modes/print-mode.js +7 -7
- package/dist/modes/rpc/rpc-mode.js +1 -1
- package/dist/node_modules/@dalcode/dal-advisor/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-awake/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-bridge/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-capabilities/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-codeindex/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-compat/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-dap/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-gateway/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-goal/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-guard/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-halo/package.json +1 -1
- package/dist/node_modules/@dalcode/dal-interactive/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-lang/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-learn/package.json +5 -2
- package/dist/node_modules/@dalcode/dal-learn/src/engine.js +4 -4
- package/dist/node_modules/@dalcode/dal-learn/src/extract.js +31 -5
- package/dist/node_modules/@dalcode/dal-learn/src/index.js +16 -16
- package/dist/node_modules/@dalcode/dal-learn/src/learn-mode.js +1 -0
- package/dist/node_modules/@dalcode/dal-learn/src/lesson-events.js +1 -0
- package/dist/node_modules/@dalcode/dal-learn/src/lessons.js +4 -3
- package/dist/node_modules/@dalcode/dal-learn/src/project-map.js +2 -2
- package/dist/node_modules/@dalcode/dal-learn/src/safety.js +2 -2
- package/dist/node_modules/@dalcode/dal-learn/src/signals.js +6 -5
- package/dist/node_modules/@dalcode/dal-learn/src/store.js +3 -2
- package/dist/node_modules/@dalcode/dal-lsp/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-mcp/package.json +6 -6
- package/dist/node_modules/@dalcode/dal-office/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.js +4 -3
- package/dist/node_modules/@dalcode/dal-pi-kit/package.json +1 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/src/i18n.js +4 -3
- package/dist/node_modules/@dalcode/dal-plugins/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-recall/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-remote/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-review/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-rewind/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-router/package.json +6 -6
- package/dist/node_modules/@dalcode/dal-rtk/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-skills/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-statusline/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-structured/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-subagent/package.json +5 -5
- package/dist/node_modules/@dalcode/dal-sync/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-sync/src/core.js +2 -2
- package/dist/node_modules/@dalcode/dal-telemetry/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-terminal/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-tool-catalog/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-usage/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-web/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-workflow/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-workflow/src/todo-snapshot.js +2 -2
- package/dist/node_modules/@dalcode/dal-workflow/src/todo.js +3 -3
- package/dist/node_modules/@dalcode/deepailab/package.json +3 -3
- package/dist/node_modules/@earendil-works/pi-agent-core/README.md +8 -6
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/proxy.d.ts +1 -1
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/proxy.js +2 -2
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/types.d.ts +8 -5
- package/dist/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
- package/dist/node_modules/@earendil-works/pi-ai/README.md +58 -39
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js +5 -5
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/azure-openai-responses.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.lazy.d.ts +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.lazy.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/constrained-sampling.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-generative-ai.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-shared.js +2 -2
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-vertex.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/lazy.d.ts +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/lazy.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.js +4 -4
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.d.ts +2 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js +5 -5
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-responses-shared.js +9 -9
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.js +3 -3
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openrouter-images.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.d.ts +2 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.js +3 -3
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/simple-options.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/strict-tool-limits.js +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-coding.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/auth/oauth/load.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/auth/oauth/meta.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/auth/oauth/radius.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/auth/oauth/trusted-url.js +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/auth/types.d.ts +2 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/cache-warming.d.ts +21 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/cache-warming.js +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/cli.js +5 -5
- package/dist/node_modules/@earendil-works/pi-ai/dist/compat/extension-oauth-types.d.ts +2 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/env-api-keys.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/index.d.ts +3 -3
- package/dist/node_modules/@earendil-works/pi-ai/dist/index.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/lazy-bedrock-provider.js +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/lazy-oauth.js +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/models.d.ts +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/models.generated.d.ts +4 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/models.generated.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/models.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/all.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/compat-schema.d.ts +485 -498
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/compat-schema.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/amazon-bedrock.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/anthropic.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/azure.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/baseten.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-ai-gateway.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-workers-ai.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/fireworks.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/github-copilot.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/google-vertex.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/google.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/huggingface.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/kimi-coding.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/meta.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/mistral.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/moonshotai-cn.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/moonshotai.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/nvidia.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openai-codex.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openai.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode-go.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan-cn.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan-individual-cn.json +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan-individual.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/radius.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/together.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/xai.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-ams.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-cn.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-sgp.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/zai-coding-cn.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/zai.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/faux.js +5 -5
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/model-schema.d.ts +65 -65
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/model-schema.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/qwen-token-plan-individual-cn.js +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/qwen-token-plan-individual-cn.models.d.ts +5 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/qwen-token-plan-individual-cn.models.js +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/radius-config.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/schema-builders.js +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/telemetry.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/types.d.ts +4 -3
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/error-body.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/openrouter-cost.js +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/retry.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/streaming-json.d.ts +26 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/streaming-json.js +4 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/{typebox-helpers.d.ts → string-enum.d.ts} +2 -2
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/string-enum.js +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/text.d.ts +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/text.js +2 -2
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/validation.js +4 -4
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/version.d.ts +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/version.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/package.json +12 -5
- package/dist/node_modules/@earendil-works/pi-codemode/README.md +2 -2
- package/dist/node_modules/@earendil-works/pi-codemode/dist/declarations.d.ts +1 -0
- package/dist/node_modules/@earendil-works/pi-codemode/dist/declarations.js +4 -4
- package/dist/node_modules/@earendil-works/pi-codemode/dist/index.d.ts +1 -1
- package/dist/node_modules/@earendil-works/pi-codemode/dist/index.js +1 -1
- package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/prelude-source.js +2 -0
- package/dist/node_modules/@earendil-works/pi-codemode/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-coding-agent/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-mcp/CHANGELOG.md +32 -0
- package/dist/node_modules/@earendil-works/pi-mcp/README.md +60 -5
- package/dist/node_modules/@earendil-works/pi-mcp/dist/config.d.ts +45 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/config.js +1 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/index.d.ts +5 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/index.js +1 -1
- package/dist/node_modules/@earendil-works/pi-mcp/dist/input-schema.d.ts +1 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/input-schema.js +1 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/naming.d.ts +2 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/naming.js +1 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/auth-provider.d.ts +18 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/auth-provider.js +1 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/callback.js +1 -1
- package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/client-settings.d.ts +42 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/client-settings.js +1 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/errors.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/errors.js +1 -1
- package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/flow.d.ts +2 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/flow.js +1 -1
- package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/index.d.ts +5 -1
- package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/index.js +1 -1
- package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/loopback.d.ts +22 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/loopback.js +1 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/sign-in.d.ts +28 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/sign-in.js +1 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/types.d.ts +1 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/types.js +1 -1
- package/dist/node_modules/@earendil-works/pi-mcp/dist/output-limit.d.ts +8 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/output-limit.js +11 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/transports/lines.js +1 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/transports/pipe.d.ts +34 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/transports/pipe.js +2 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/transports/stdio.d.ts +1 -4
- package/dist/node_modules/@earendil-works/pi-mcp/dist/transports/stdio.js +2 -2
- package/dist/node_modules/@earendil-works/pi-mcp/dist/transports/streamable-http.js +6 -4
- package/dist/node_modules/@earendil-works/pi-mcp/package.json +2 -2
- package/dist/node_modules/@earendil-works/pi-schema/CHANGELOG.md +37 -0
- package/dist/node_modules/@earendil-works/pi-schema/LICENSE +21 -0
- package/dist/node_modules/@earendil-works/pi-schema/README.md +319 -0
- package/dist/node_modules/@earendil-works/pi-schema/THIRD_PARTY_NOTICES/typebox-LICENSE +23 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/annotations.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/builders.d.ts +89 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/builders.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/checks.d.ts +51 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/checks.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/coerce.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/compiler.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/explain.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/index.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/date.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/date_time.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/duration.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/email.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/hostname.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/idn_email.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/idn_hostname.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/idna/format/bidi.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/idna/format/puny.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/idna/hostname.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/idna/idn-hostname.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/idna/index.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/idna/label/ascii.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/idna/label/puny.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/idna/label/unicode.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/idna/pattern/pattern.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/ipv4.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/ipv6.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/iri.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/iri_reference.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/json_pointer.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/json_pointer_uri_fragment.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/regex.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/relative_json_pointer.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/time.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/uri.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/uri_reference.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/uri_template.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/url.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/formats/typebox/uuid.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/index.d.ts +4 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/index.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/resolver.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/shared.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/typebox-static.d.ts +54 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/typebox-static.js +0 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/types.d.ts +25 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/types.js +0 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/validator.d.ts +20 -0
- package/dist/node_modules/@earendil-works/pi-schema/dist/validator.js +1 -0
- package/dist/node_modules/@earendil-works/pi-schema/package.json +43 -0
- package/dist/node_modules/@earendil-works/pi-telemetry/dist/index.d.ts +1 -1
- package/dist/node_modules/@earendil-works/pi-telemetry/dist/index.js +1 -1
- package/dist/node_modules/@earendil-works/pi-telemetry/dist/memory.d.ts +1 -0
- package/dist/node_modules/@earendil-works/pi-telemetry/dist/memory.js +1 -1
- package/dist/node_modules/@earendil-works/pi-telemetry/dist/render.js +2 -2
- package/dist/node_modules/@earendil-works/pi-telemetry/package.json +3 -1
- package/dist/node_modules/@earendil-works/pi-tui/README.md +2 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/editor.d.ts +1 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/editor.js +3 -3
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/markdown.d.ts +4 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/markdown.js +11 -10
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/select-list.d.ts +1 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/select-list.js +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/settings-list.d.ts +1 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/settings-list.js +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/text.js +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/fuzzy.js +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/index.d.ts +2 -2
- package/dist/node_modules/@earendil-works/pi-tui/dist/index.js +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/keybindings.d.ts +1 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/keybindings.js +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/keys.js +5 -5
- package/dist/node_modules/@earendil-works/pi-tui/dist/layout.js +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/program-status.js +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/terminal-image.d.ts +1 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/terminal-image.js +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/terminal.js +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.d.ts +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.js +4 -4
- package/dist/node_modules/@earendil-works/pi-tui/dist/tui-main-screen.js +13 -13
- package/dist/node_modules/@earendil-works/pi-tui/dist/tui.d.ts +1 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/tui.js +2 -2
- package/dist/node_modules/@earendil-works/pi-tui/dist/utils.d.ts +1 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/utils.js +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/package.json +1 -1
- package/dist/package-manager-cli.js +17 -16
- package/dist/utils/ansi.js +1 -1
- package/dist/utils/changelog.js +3 -3
- package/dist/utils/clipboard-command.js +1 -1
- package/dist/utils/image-resize-core.js +1 -1
- package/dist/utils/image-resize.js +1 -1
- package/dist/utils/open-browser.js +1 -1
- package/dist/utils/paths.js +1 -1
- package/dist/utils/shell.js +3 -3
- package/dist/utils/syntax-highlight.js +4 -4
- package/dist/utils/terminal-question.js +1 -0
- package/dist/utils/tools-manager.js +1 -1
- package/dist/utils/web-url.js +1 -0
- package/examples/extensions/README.md +2 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +14 -14
- package/examples/extensions/debug-provider.ts +2 -2
- package/examples/extensions/gondolin/package-lock.json +19 -29
- package/examples/extensions/gondolin/package.json +2 -2
- package/examples/extensions/plan-mode/index.ts +20 -9
- package/examples/extensions/plan-mode/utils.ts +42 -16
- package/examples/extensions/preset.ts +2 -0
- package/examples/extensions/reload-runtime.ts +17 -5
- package/examples/extensions/subagent/README.md +14 -11
- package/examples/extensions/subagent/index.ts +392 -171
- package/examples/extensions/todo.ts +7 -0
- package/examples/extensions/tools.ts +2 -0
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +20 -20
- package/examples/tsconfig.json +208 -0
- package/npm-shrinkwrap.json +407 -383
- package/package.json +6 -7
- package/examples/extensions/sandbox/index.ts +0 -327
- package/examples/extensions/sandbox/package-lock.json +0 -92
- package/examples/extensions/sandbox/package.json +0 -19
- /package/dist/node_modules/@earendil-works/pi-mcp/{LICENSES → THIRD_PARTY_NOTICES}/modelcontextprotocol-typescript-sdk.txt +0 -0
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
var C=Object.defineProperty;var
|
|
2
|
-
`)}
|
|
1
|
+
var C=Object.defineProperty;var d=(e,t)=>C(e,"name",{value:t,configurable:!0});import{join as _}from"node:path";import{renderToolOutputType as $,renderToolSample as v,resolveSchemaRef as x,toCodemodeIdentifier as b}from"@earendil-works/pi-codemode/declarations";import{CODEMODE_SOURCE_GRAMMAR as D}from"@earendil-works/pi-codemode/source";import{Type as O}from"typebox";import{getDocsPath as N}from"../../config.js";import{SETTINGS_DEFAULTS as y}from"../../core/settings-defaults.js";import{wrapToolDefinition as j}from"../../core/tools/tool-definition-wrapper.js";import{loadCodemodeExecutor as M}from"./execute.lazy.js";import{codemodeRenderers as R}from"./renderer.js";const f="codemode",ie="codemode-store",A={type:"string"},k=O.Object({code:O.String({description:"Raw JavaScript source."})}),T={snippet:"Run JavaScript that calls other tools",guidelines:["Use codemode to batch independent tool calls (Promise.allSettled), chain them, or filter large output, instead of many separate calls."]},L=_(N(),"codemode.md"),G='Run JavaScript that calls other tools. The input is raw JavaScript (not JSON, no code fence), run as an async function body in a QuickJS sandbox: top-level `await` and `return` work. No Node, file system, network, or timers.\n- `await tools.<name>({ ...args })` resolves to a string, or an object if the tool\'s declaration says so, and rejects with an Error on failure. A tool whose declaration returns an object resolves on failure too when it returned that object; check its fields. Calls still running when the script ends are cancelled.\n- Optional first line: `// @options: {"max_output_tokens": 10000, "timeout_ms": 60000}`';function I(e){const t=["Globals:","- `text(value)`, `image(dataUrlOrImageBlock)`, `console.log(...)`, and top-level `return` add output; `exit()` ends the script. With several text items, each starts with a `==> text N/M <==` line, and `console` lines follow the other output in one `<console_output>` block. `image()` also saves the image to a temp file and the result names its path.","- `store(key, value)` and `load(key)` keep JSON values across codemode calls.","- `ALL_TOOLS`, `await searchTools(query, { limit?, namespace? })`, `await describeTool(name)`, `await describeNamespace(name)`: find unlisted tools, such as MCP tools."];return e&&t.push(`- \`models\`: classifiers and image generation. Read ${L} first.`),t.join(`
|
|
2
|
+
`)}d(I,"describeGlobals");const P=y.codemode.inlineBudget,J=4;function w(e,t=[]){const r=t.flatMap(o=>o.trim()?[`- ${o.trim()}`]:[]);return{name:e.name,description:r.length>0?`${e.description.trim()}
|
|
3
3
|
|
|
4
|
-
${
|
|
5
|
-
`)}`:e.description,inputSchema:e.parameters,outputSchema:e.outputSchema??
|
|
6
|
-
${
|
|
4
|
+
${r.join(`
|
|
5
|
+
`)}`:e.description,inputSchema:e.parameters,outputSchema:e.outputSchema??A}}d(w,"toCodemodeDeclaration");function E(e){return e.filter(t=>t.name!==f)}d(E,"getCodemodeCallableTools");function U(e){const t=b(e.name);return`${t===e.name?`### \`${t}\``:`### \`${t}\` (\`${e.name}\`)`}
|
|
6
|
+
${v(e).trim()}`}d(U,"renderToolSection");function B(e,t){if(t===void 0)return new Set(e.flatMap(s=>s.entries.map(i=>i.name)));const r=e.map(s=>[...s.entries].sort((i,c)=>i.cost-c.cost)),o=new Set;let l=t,a=r.filter(s=>s.length>0);for(;a.length>0;)a=a.filter(s=>{const i=s[0];return i.cost>l?!1:(l-=i.cost,o.add(i.name),s.shift(),s.length>0)});return o}d(B,"selectCatalog");function h(e,t={}){const r=E(e).filter(c=>!t.deferred?.has(c.name)).map(c=>w(c,t.guidelines?.get(c.name))),o=new Map([["",{namespace:void 0,entries:[]}]]);for(const c of r){const m=t.namespaces?.get(c.name),p=m?`ns:${m.name}`:"",n=o.get(p)??{namespace:m,entries:[]};o.set(p,n);const u=U(c);n.entries.push({name:c.name,section:u,cost:Math.ceil(u.length/J)})}const l=[...o.values()].sort((c,m)=>c.namespace===void 0?-1:m.namespace===void 0?1:c.namespace.name.localeCompare(m.namespace.name)),a=B(l,t.inlineBudget),s=[G,I(t.models===!0)];if(r.length===0)return s.join(`
|
|
7
7
|
|
|
8
|
-
`);const
|
|
9
|
-
${u}`:""}`)}for(const n of p)
|
|
8
|
+
`);const i=["Nested tools:"];for(const{namespace:c,entries:m}of l){const p=m.filter(n=>a.has(n.name));if(c){const n=p.length===m.length?"":p.length===0?" (tools not listed)":" (some tools not listed)",u=c.description?.trim();i.push(`## ${c.name}${n}${u?`
|
|
9
|
+
${u}`:""}`)}for(const n of p)i.push(n.section)}return s.push(i.join(`
|
|
10
10
|
|
|
11
|
-
`)),
|
|
11
|
+
`)),s.join(`
|
|
12
12
|
|
|
13
|
-
`)}
|
|
13
|
+
`)}d(h,"createCodemodeDescription");function g(e,t,r){const o=S(e,t);if(typeof o!="object"||o===null)return;const{type:l,properties:a,required:s}=o;if(l!=="object"||typeof a!="object"||a===null)return;const i=new Set(Array.isArray(s)?s:[]);return`{ ${Object.entries(a).map(([m,p])=>{const n=S(p,t)?.const,u=n!==void 0?JSON.stringify(n):r>0?g(p,t,r-1):void 0;return`${m}${i.has(m)?"":"?"}${u?`: ${u}`:""}`}).join(", ")} }`}d(g,"describeFields");function F(e,t){const r=$(t);if(r==="string")return"a string";const o=t===void 0?void 0:g(t,t,1)??H(t,t);return o?`\`${o}\``:r.includes(`
|
|
14
|
+
`)?`a value; \`await describeTool(${JSON.stringify(e)})\` shows its type`:`\`${r}\``}d(F,"describeOutput");function H(e,t){const r=S(e,t);if(typeof r!="object"||r===null)return;const{anyOf:o,oneOf:l}=r,a=o??l;if(!Array.isArray(a)||a.length===0)return;const s=a.map(i=>g(i,t,0));return s.every(i=>i!==void 0)?s.join(" | "):void 0}d(H,"describeUnionFields");function S(e,t){const r=new Set;let o=e;for(;typeof o=="object"&&o!==null&&!r.has(o);){const l=o.$ref;if(typeof l!="string")break;const a=x(l,t);if(a===void 0)break;r.add(o),o=a}return o}d(S,"followRef");function Y(e){return`${e.description.trim()}
|
|
14
15
|
|
|
15
|
-
Codemode: \`tools.${
|
|
16
|
+
Codemode: \`tools.${b(e.name)}(args)\` resolves to ${F(e.name,w(e).outputSchema)}.`}d(Y,"describeScriptCall");function q(e,t){const r=t.getMode?.()??y.codemode.mode,o=d(n=>e.getExposure(n.name)==="direct","isDirect"),l=E(e.callable),a=new Set(l.map(n=>n.name)),s={};if(r==="on")for(const n of e.declared)a.has(n.name)&&(s[n.name]=Y(n));const i=r==="only"?l:l.filter(n=>!o(n)),c=new Map(i.flatMap(n=>{const u=e.getNamespace(n.name);return u?[[n.name,u]]:[]})),m=new Map(i.map(n=>[n.name,e.getPromptGuidelines(n.name)]));s[f]=h(i,{models:t.models===!0,namespaces:c,guidelines:m,deferred:new Set(i.filter(n=>e.getExposure(n.name)==="deferred").map(n=>n.name)),inlineBudget:t.getInlineBudget?.()??P});const p=new Set(e.declared.map(n=>n.name));return{descriptions:s,hiddenDeclarations:r==="only"?l.filter(n=>o(n)&&p.has(n.name)).map(n=>n.name):[]}}d(q,"prepareCodemodeLoadout");const V=/\b(searchTools|describeNamespace|describeTool|ALL_TOOLS)\b/;function K(e){return typeof e!="string"?[]:V.test(e)?"all":e.match(/\w+/g)??[]}d(K,"getScriptReach");function Q(e={}){return{name:f,label:f,description:h([],{models:e.models===!0}),promptSnippet:T.snippet,promptGuidelines:[...T.guidelines],parameters:k,exposure:"model-only",prepareLoadout:d(t=>q(t,e),"prepareLoadout"),reachesTools:d(t=>K(t.code),"reachesTools"),constrainedSampling:{type:"grammar",variants:{openai_lark:D}},execute:d(async(t,r,o,l,a)=>(await M()).executeCodemode(t,r,o,l,a,e),"execute"),...R}}d(Q,"createCodemodeToolDefinition");function ae(e=[],t={}){const r=Q(t),o=j(r);return Object.assign(o,{description:h(e,{models:t.models===!0}),promptSnippet:r.promptSnippet,promptGuidelines:r.promptGuidelines}),o}d(ae,"createCodemodeTool");export{L as CODEMODE_DOCS_PATH,ie as CODEMODE_STORE_ENTRY_TYPE,f as CODEMODE_TOOL_NAME,P as DEFAULT_CODEMODE_INLINE_BUDGET,k as codemodeSchema,T as codemodeToolSystemPromptContribution,h as createCodemodeDescription,ae as createCodemodeTool,Q as createCodemodeToolDefinition,E as getCodemodeCallableTools,w as toCodemodeDeclaration};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
var S=Object.defineProperty;var
|
|
1
|
+
var S=Object.defineProperty;var d=(n,e)=>S(n,"name",{value:e,configurable:!0});import{fill as w,t as p}from"../../dal/i18n.js";function m(n,e){if(typeof n!="object"||n===null)return e;const t=n.error;if(typeof t!="object"||t===null)return e;const r=t.message;return typeof r=="string"&&r?r:e}d(m,"errorMessage");function $(n){if(typeof n!="object"||n===null)return!1;const e=n;return typeof e.id=="string"&&typeof e.status?.value=="string"}d($,"isModelInfo");function g(n,e){if(!n)return()=>{};if(n.aborted)return e.abort(n.reason),()=>{};const t=d(()=>e.abort(n.reason),"abort");return n.addEventListener("abort",t,{once:!0}),()=>n.removeEventListener("abort",t)}d(g,"linkSignal");function y(n,e){return new Promise((t,r)=>{if(e?.aborted){r(e.reason??new Error("Cancelled"));return}const o=d(()=>{clearTimeout(s),r(e?.reason??new Error("Cancelled"))},"abort"),s=setTimeout(()=>{e?.removeEventListener("abort",o),t()},n);e?.addEventListener("abort",o,{once:!0})})}d(y,"sleep");function A(n){if(typeof n!="object"||n===null)return;const e=n.progress;if(typeof e!="object"||e===null)return;const t=e,r=typeof t.current=="string"?t.current:typeof t.stage=="string"?t.stage:void 0,o=Array.isArray(t.stages)?t.stages.filter(a=>typeof a=="string"):[],s=typeof t.value=="number"?Math.max(0,Math.min(1,t.value)):void 0;let i=s;if(r&&o.length>0){const a=o.indexOf(r);a>=0&&(i=(a+(s??0))/o.length)}return{message:r?w(p("\u6B63\u5728\u52A0\u8F7D {stage}"),{stage:r.replaceAll("_"," ")}):p("\u6B63\u5728\u52A0\u8F7D\u6A21\u578B"),ratio:i}}d(A,"parseLoadProgress");function b(n){if(typeof n!="object"||n===null)return;const e=n.progress,t=typeof e=="object"&&e!==null?e:n;let r=0,o=0;for(const s of Object.values(t)){if(typeof s!="object"||s===null)continue;const i=s;typeof i.done!="number"||typeof i.total!="number"||(r+=i.done,o+=i.total)}if(!(o<=0))return{message:p("\u6B63\u5728\u4E0B\u8F7D\u6A21\u578B"),ratio:r/o,detail:`${v(r)} / ${v(o)}`}}d(b,"parseDownloadProgress");function v(n){if(n<1024)return`${n} B`;const e=["KiB","MiB","GiB","TiB"];let t=n/1024,r=e[0];for(let o=1;o<e.length&&t>=1024;o++)t/=1024,r=e[o];return`${t>=10?t.toFixed(1):t.toFixed(2)} ${r}`}d(v,"formatBytes");function E(n){const e=new URL(n.trim());if(e.protocol!=="http:"&&e.protocol!=="https:")throw new Error("Server URL must use http or https");return e.hash="",e.search="",e.pathname=e.pathname.replace(/\/+$/u,"").replace(/\/v1$/u,"")||"/",e.toString().replace(/\/$/u,"")}d(E,"normalizeLlamaServerUrl");function _(n){return`${E(n)}/v1`}d(_,"llamaInferenceUrl");function x(n){const e=n instanceof Error?n.cause:void 0;return e instanceof Error&&e.message?e.message:e&&typeof e=="object"&&"code"in e&&typeof e.code=="string"?e.code:n instanceof Error?n.message:String(n)}d(x,"connectionErrorDetail");class L{static{d(this,"LlamaClient")}serverUrl;apiKey;constructor(e,t){this.serverUrl=E(e),this.apiKey=t}async fetchServer(e,t){try{return await fetch(`${this.serverUrl}${e}`,t)}catch(r){throw t.signal?.aborted?r:new Error(`Could not reach llama.cpp server at ${this.serverUrl}: ${x(r)}`,{cause:r})}}async request(e,t={}){const r=new Headers(t.headers);t.body!==void 0&&r.set("Content-Type","application/json"),this.apiKey&&r.set("Authorization",`Bearer ${this.apiKey}`);const o=AbortSignal.timeout(15e3),s=t.signal?AbortSignal.any([t.signal,o]):o,i=await this.fetchServer(e,{...t,headers:r,signal:s});let a;try{a=await i.json()}catch{a=void 0}if(!i.ok)throw new Error(m(a,`llama.cpp returned HTTP ${i.status}`));return a}async list(e={}){const t=await this.request(`/models${e.reload?"?reload=1":""}`,{signal:e.signal});if(typeof t!="object"||t===null||!Array.isArray(t.data))throw new Error("llama.cpp returned an invalid model catalog");const r=t.data;if(!r.every($))throw new Error("Server is not running in llama.cpp router mode");return r}async props(e={}){const t=e.model?`?${new URLSearchParams({model:e.model,autoload:"false"})}`:"",r=await this.request(`/props${t}`,{signal:e.signal});if(typeof r!="object"||r===null)return{};const{models_autoload:o,chat_template:s}=r;return{...typeof o=="boolean"?{models_autoload:o}:{},...typeof s=="string"?{chat_template:s}:{}}}async load(e,t){await this.request("/models/load",{method:"POST",body:JSON.stringify({model:e}),signal:t})}async unload(e,t){await this.request("/models/unload",{method:"POST",body:JSON.stringify({model:e}),signal:t})}async unloadAndWait(e,t){for(await this.unload(e,t);;){const r=(await this.list({signal:t})).find(o=>o.id===e);if(!r||r.status.value==="unloaded")return;await y(100,t)}}async download(e,t){await this.request("/models",{method:"POST",body:JSON.stringify({model:e}),signal:t})}async watch(e,t){const r=new Headers;this.apiKey&&r.set("Authorization",`Bearer ${this.apiKey}`);const o=await this.fetchServer("/models/sse",{headers:r,signal:t});if(!o.ok||!o.body)throw new Error(`llama.cpp SSE returned HTTP ${o.status}`);const s=o.body.getReader(),i=new TextDecoder;let a="";for(;;){const l=await s.read();if(l.done)break;a+=i.decode(l.value,{stream:!0}).replaceAll(`\r
|
|
2
2
|
`,`
|
|
3
3
|
`);let f=a.indexOf(`
|
|
4
4
|
|
|
5
|
-
`);for(;f>=0;){const
|
|
6
|
-
`).filter(
|
|
7
|
-
`);if(
|
|
5
|
+
`);for(;f>=0;){const u=a.slice(0,f);a=a.slice(f+2);const h=u.split(`
|
|
6
|
+
`).filter(c=>c.startsWith("data:")).map(c=>c.slice(5).trimStart()).join(`
|
|
7
|
+
`);if(h)try{const c=JSON.parse(h);c&&typeof c.model=="string"&&typeof c.event=="string"&&e(c)}catch{}f=a.indexOf(`
|
|
8
8
|
|
|
9
|
-
`)}}}async loadAndWait(e,t,r){const
|
|
9
|
+
`)}}}async loadAndWait(e,t,r){const o=new AbortController,s=g(r,o);let i=!1,a;this.watch(l=>{if(l.model!==e||l.event!=="model_status"&&l.event!=="status_change")return;const f=l.data;f?.status==="loaded"&&(i=!0),f?.status==="unloaded"&&(a=p("\u6A21\u578B\u52A0\u8F7D\u5931\u8D25"));const u=A(l.data);u&&t(u)},o.signal).catch(()=>{});try{for(await this.load(e,r),t({message:p("\u6B63\u5728\u52A0\u8F7D\u6A21\u578B")});;){if(r?.aborted)throw r.reason??new Error("Cancelled");const l=(await this.list({signal:r})).find(f=>f.id===e);if(l?.status.value==="loaded")return l;if(i&&!l)return{id:e,status:{value:"loaded"}};if(l?.status.failed||a)throw new Error(l?.status.exit_code===void 0?a??p("\u6A21\u578B\u52A0\u8F7D\u5931\u8D25"):w(p("\u6A21\u578B\u8FDB\u7A0B\u5DF2\u9000\u51FA\uFF0C\u9000\u51FA\u7801 {code}"),{code:l.status.exit_code}));await y(250,r)}}finally{s(),o.abort()}}async downloadAndWait(e,t,r){const o=new AbortController,s=g(r,o);let i=!1,a,l=!1,f=0;this.watch(u=>{if(u.model===e&&(u.event==="download_finished"&&(i=!0),u.event==="download_failed"&&(a=m(u.data,p("\u4E0B\u8F7D\u5931\u8D25"))),u.event==="download_progress")){l=!0;const h=b(u.data);h&&t(h)}},o.signal).catch(()=>{});try{for(await this.download(e,r),t({message:p("\u6B63\u5728\u4E0B\u8F7D\u6A21\u578B")});;){if(r?.aborted)throw r.reason??new Error("Cancelled");if(a)throw new Error(a);const u=await this.list({signal:r});f++;const h=u.find(c=>c.id===e);if(h?.status.value==="downloading"){l=!0;const c=b(h.status.progress);c&&t(c)}else if(i||h&&(l||f>=2))return this.list({reload:!0,signal:r});await y(500,r)}}finally{s(),o.abort()}}}export{L as LlamaClient,v as formatBytes,_ as llamaInferenceUrl,E as normalizeLlamaServerUrl};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var
|
|
1
|
+
var I=Object.defineProperty;var o=(n,e)=>I(n,"name",{value:e,configurable:!0});import{Container as p,fuzzyFilter as $,getSelectPageIndex as M,Input as q,SelectList as x,Spacer as d,Text as c,truncateToWidth as P,visibleWidth as S}from"@earendil-works/pi-tui";import{fill as y,t as h}from"../../dal/i18n.js";import{DynamicBorder as C}from"../../modes/interactive/components/dynamic-border.js";import{keyHint as a}from"../../modes/interactive/components/keybinding-hints.js";const R="\0download",m=10;function T(n){const e=n.meta?.n_ctx??n.meta?.n_ctx_train;if(e)return e>=1e3?`${Math.round(e/1e3)}k`:String(e);const t=n.status.args??[];for(let s=0;s<t.length-1;s++){if(t[s]!=="--ctx-size"&&t[s]!=="-c"&&t[s]!=="-ctx")continue;const i=Number(t[s+1]);if(Number.isFinite(i)&&i>0)return i>=1e3?`${Math.round(i/1e3)}k`:String(i)}}o(T,"contextLabel");function _(n){const e=[],t=n.status.value==="loaded"||n.status.value==="sleeping";t?e.push(h("\u5DF2\u52A0\u8F7D")):n.status.value!=="unloaded"&&e.push(n.status.value);const s=t?T(n):void 0;return s&&e.push(y(h("{context} \u4E0A\u4E0B\u6587"),{context:s})),e.join(" \xB7 ")}o(_,"modelDescription");function b(n){return{selectedPrefix:o(e=>n.fg("accent",e),"selectedPrefix"),selectedText:o(e=>n.fg("accent",e),"selectedText"),description:o(e=>n.fg("muted",e),"description"),scrollInfo:o(e=>n.fg("dim",e),"scrollInfo"),noMatch:o(e=>n.fg("warning",e),"noMatch")}}o(b,"selectTheme");function f(n,e,t,s){const i=new p;i.addChild(new C(r=>n.fg("accent",r))),i.addChild(new c(n.fg("accent",n.bold(e)),1,0));for(const r of t)i.addChild(r);return s&&(i.addChild(new d(1)),i.addChild(new c(n.fg("dim",s),1,0))),i.addChild(new C(r=>n.fg("accent",r))),i}o(f,"frame");function v(n){return n>=1e6?`${(n/1e6).toFixed(n>=1e7?0:1)}M`:n>=1e3?`${(n/1e3).toFixed(n>=1e5?0:1)}k`:String(n)}o(v,"compactCount");class k extends p{static{o(this,"HuggingFaceSearch")}capturesViewportInput=!0;tui;theme;keybindings;search;cache;onSelectModel;input=new q;resultsContainer=new p;results=[];filteredResults=[];selectedIndex=0;selectionTouched=!1;query="";status=h("\u81F3\u5C11\u8F93\u5165 2 \u4E2A\u5B57\u7B26");debounce;request;closed=!1;_focused=!1;constructor(e,t,s,i,r,l){super(),this.tui=e,this.theme=t,this.keybindings=s,this.search=i,this.cache=r,this.onSelectModel=l,this.addChild(new c(t.fg("dim",h("\u6A21\u578B\u540D\u79F0\u6216 owner/repository[:quant]")),1,0)),this.addChild(this.input),this.addChild(new d(1)),this.addChild(this.resultsContainer),this.updateResults()}get focused(){return this._focused}set focused(e){this._focused=e,this.input.focused=e}updateResults(){this.resultsContainer.clear();const e=Math.max(0,Math.min(this.selectedIndex-Math.floor(m/2),this.filteredResults.length-m)),t=Math.min(e+m,this.filteredResults.length);for(let s=e;s<t;s++){const i=this.filteredResults[s];if(!i)continue;const r=s===this.selectedIndex?"\u2192 ":" ",l=y(h("{count} \u6B21\u4E0B\u8F7D"),{count:v(i.downloads)});this.resultsContainer.addChild(new c(s===this.selectedIndex?this.theme.fg("accent",`${r}${i.id} ${l}`):`${r}${i.id}${this.theme.fg("muted",` ${l}`)}`,0,0))}(e>0||t<this.filteredResults.length)&&this.resultsContainer.addChild(new c(this.theme.fg("dim",` (${this.selectedIndex+1}/${this.filteredResults.length})`),0,0)),this.filteredResults.length===0?this.resultsContainer.addChild(new c(this.theme.fg("dim",` ${this.status}`),0,0)):this.status===h("\u6B63\u5728\u641C\u7D22 Hugging Face\u2026")&&this.resultsContainer.addChild(new c(this.theme.fg("dim",` ${this.status}`),0,0)),this.tui.requestRender()}filterResults(e){if(this.query){const s=new Set($(this.results,this.query,i=>i.id).map(i=>i.id));this.filteredResults=this.results.filter(i=>s.has(i.id))}else this.filteredResults=this.results;const t=e?this.filteredResults.findIndex(s=>s.id===e):-1;t>=0?this.selectedIndex=t:this.selectedIndex=Math.min(this.selectedIndex,Math.max(0,this.filteredResults.length-1)),this.updateResults()}scheduleSearch(){if(this.debounce&&clearTimeout(this.debounce),this.request?.abort(),this.request=void 0,this.query.length<2){this.status=h("\u81F3\u5C11\u8F93\u5165 2 \u4E2A\u5B57\u7B26"),this.filterResults();return}const e=this.cache.get(this.query.toLowerCase());if(e){this.results=e,this.status=e.length===0?h("\u6CA1\u6709\u627E\u5230 GGUF \u6A21\u578B"):"",this.filterResults();return}this.status=h("\u6B63\u5728\u641C\u7D22 Hugging Face\u2026"),this.filterResults(),this.debounce=setTimeout(()=>{this.runSearch(this.query)},500)}async runSearch(e){const t=new AbortController;this.request=t;try{const s=await this.search(e,t.signal);if(this.cache.set(e.toLowerCase(),s),this.closed||t.signal.aborted||this.query!==e)return;const i=this.selectionTouched?this.filteredResults[this.selectedIndex]?.id:void 0;this.results=s,this.selectedIndex=0,this.status=s.length===0?h("\u6CA1\u6709\u627E\u5230 GGUF \u6A21\u578B"):"",this.filterResults(i)}catch(s){if(this.closed||t.signal.aborted||this.query!==e)return;this.results=[],this.status=s instanceof Error?s.message:String(s),this.filterResults()}finally{this.request===t&&(this.request=void 0)}}close(e){this.closed||(this.closed=!0,this.debounce&&clearTimeout(this.debounce),this.request?.abort(),this.onSelectModel(e))}handleInput(e){if(this.keybindings.matches(e,"tui.select.up")){this.filteredResults.length>0&&(this.selectedIndex=this.selectedIndex===0?this.filteredResults.length-1:this.selectedIndex-1,this.selectionTouched=!0,this.updateResults());return}if(this.keybindings.matches(e,"tui.select.down")){this.filteredResults.length>0&&(this.selectedIndex=this.selectedIndex===this.filteredResults.length-1?0:this.selectedIndex+1,this.selectionTouched=!0,this.updateResults());return}const t=M(this.keybindings,e,this.selectedIndex,this.filteredResults.length,m);if(t!==void 0){this.filteredResults.length>0&&(this.selectedIndex=t,this.selectionTouched=!0,this.updateResults());return}if(this.keybindings.matches(e,"tui.select.confirm")){const r=(/^[^/\s]+\/[^:\s]+(?::[^\s:]+)?$/u.test(this.query)?this.query:void 0)??this.filteredResults[this.selectedIndex]?.id;r&&this.close(r);return}if(this.keybindings.matches(e,"tui.select.cancel")){this.close(void 0);return}this.input.handleInput(e);const s=this.input.getValue().trim();s!==this.query&&(this.query=s,this.selectionTouched=!1,this.scheduleSearch())}}class L{static{o(this,"LlamaView")}tui;theme;keybindings;searchCache=new Map;content;inputHandler;inputTarget;progressPromise;progressResolver;showingProgress=!1;_focused=!1;constructor(e,t,s){this.tui=e,this.theme=t,this.keybindings=s,this.content=f(t,h("llama.cpp \u6A21\u578B"),[new c(t.fg("muted",h("\u52A0\u8F7D\u4E2D\u2026")),1,1)])}get focused(){return this._focused}set focused(e){this._focused=e,this.inputTarget&&(this.inputTarget.focused=e)}get capturesViewportInput(){return this.inputHandler?.capturesViewportInput===!0}setContent(e,t,s){this.inputTarget&&(this.inputTarget.focused=!1),this.progressPromise=void 0,this.progressResolver=void 0,this.showingProgress=!1,this.content=e,this.inputHandler=t,this.inputTarget=s,this.inputTarget&&(this.inputTarget.focused=this._focused),this.tui.requestRender()}showModels(e,t){const s=[...t].sort((l,u)=>+(u.status.value==="loaded")-+(l.status.value==="loaded")||l.id.localeCompare(u.id)),i=new Map(s.map(l=>[l.id,l])),r=[...s.map(l=>({value:l.id,label:l.id,description:_(l)})),{value:R,label:h("\u4E0B\u8F7D\u6A21\u578B\u2026"),description:"Hugging Face owner/repository[:quant]"}];return new Promise(l=>{const u=new x(r,Math.min(r.length,12),b(this.theme),{minPrimaryColumnWidth:36,maxPrimaryColumnWidth:56});u.onSelect=g=>{if(g.value===R)l({type:"download"});else{const w=i.get(g.value);w&&l({type:"model",model:w})}},u.onCancel=()=>l({type:"close"}),this.setContent(f(this.theme,h("llama.cpp \u6A21\u578B"),[new c(this.theme.fg("dim",e),1,0),new d(1),u],`${a("tui.select.confirm",h("\u52A0\u8F7D/\u5378\u8F7D/\u4E0B\u8F7D"))} \u2022 ${a("tui.select.cancel",h("\u5173\u95ED"))}`),u)})}select(e,t){return new Promise(s=>{const i=new x(t.map(r=>({value:r,label:r})),Math.min(t.length,12),b(this.theme));i.onSelect=r=>s(r.value),i.onCancel=()=>s(void 0),this.setContent(f(this.theme,e,[new d(1),i],`${a("tui.select.confirm",h("\u9009\u62E9").toLowerCase())} \u2022 ${a("tui.select.cancel",h("\u53D6\u6D88").toLowerCase())}`),i)})}async confirm(e,t){const s=h("\u662F");return await this.select(`${e}
|
|
2
2
|
${t}`,[s,h("\u5426")])===s}async connectionError(e,t){const s=h("\u91CD\u8BD5");return await this.select(`${h("llama.cpp \u4E0D\u53EF\u7528")}
|
|
3
3
|
${e}
|
|
4
4
|
|
|
5
|
-
${t}`,[s,h("\u5173\u95ED\u9762\u677F")])===s?"retry":"close"}searchModels(e){return new Promise(t=>{const s=new
|
|
5
|
+
${t}`,[s,h("\u5173\u95ED\u9762\u677F")])===s?"retry":"close"}searchModels(e){return new Promise(t=>{const s=new k(this.tui,this.theme,this.keybindings,e,this.searchCache,t);this.setContent(f(this.theme,h("\u4E0B\u8F7D\u6A21\u578B"),[new d(1),s],`${a("tui.select.confirm",h("\u9009\u62E9").toLowerCase())} \u2022 ${a("tui.select.cancel",h("\u8FD4\u56DE").toLowerCase())}`),s,s)})}showStatus(e,t){this.setContent(f(this.theme,e,[new d(1),new c(this.theme.fg("muted",t),1,0)]))}progress(e){return this.progressPromise||(this.progressPromise=new Promise(t=>{this.progressResolver=t})),this.showingProgress=!0,this.updateProgress(e),this.progressPromise}updateProgress(e){if(!this.showingProgress)return;const t=[new c(this.theme.fg("text",e.model),1,0),new d(1),new c(this.theme.fg("muted",e.message),1,0)];if(e.ratio!==void 0){const i=Math.round(Math.max(0,Math.min(1,e.ratio))*40);t.push(new c(this.theme.fg("accent",`${"\u2588".repeat(i)}${"\u2500".repeat(40-i)} ${Math.round(e.ratio*100)}%`),1,0))}e.detail&&t.push(new c(this.theme.fg("dim",e.detail),1,0)),this.content=f(this.theme,e.title,t,a("tui.select.cancel",h("\u505C\u6B62").toLowerCase())),this.inputHandler=void 0,this.tui.requestRender()}handleInput(e){if(this.progressResolver&&this.keybindings.matches(e,"tui.select.cancel")){const t=this.progressResolver;this.progressPromise=void 0,this.progressResolver=void 0,t();return}this.inputHandler?.handleInput?.(e),this.tui.requestRender()}render(e){return this.content.render(e).map(t=>S(t)>e?P(t,e,""):t)}invalidate(){this.content.invalidate()}}async function W(n,e){await n.ui.custom((t,s,i,r)=>{const l=new L(t,s,i);return e(l).then(()=>r(),u=>{n.ui.notify(u instanceof Error?u.message:String(u),"error"),r()}),l})}o(W,"showLlamaUi");async function N(n,e){const t=new AbortController,s={title:e.title,model:e.model,message:e.initialMessage},i=e.run(t.signal,u=>{Object.assign(s,u),n.updateProgress(s)}).then(u=>({ok:!0,value:u}),u=>({ok:!1,error:u}));let r=!1;for(i.finally(()=>{r=!0});!r&&await Promise.race([i.then(()=>"settled"),n.progress(s).then(()=>"stop")])!=="settled";)if(!(!await n.confirm(e.cancelTitle,e.cancelMessage)||r)){try{await e.cancel()}finally{t.abort(new Error("Cancelled"))}return await i,{cancelled:!0}}const l=await i;if(!l.ok)throw l.error;return{cancelled:!1,value:l.value}}o(N,"runWithProgress");export{N as runWithProgress,W as showLlamaUi};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
var
|
|
2
|
-
${
|
|
3
|
-
${
|
|
4
|
-
${
|
|
5
|
-
${
|
|
6
|
-
${
|
|
7
|
-
${
|
|
1
|
+
var K=Object.defineProperty;var p=(r,t)=>K(r,"name",{value:t,configurable:!0});import{existsSync as V}from"node:fs";import{join as C}from"node:path";import I from"chalk";import{APP_NAME as h,CONFIG_DIR_NAME as T}from"../../config.js";import{validateMcpServerConfig as B}from"../../core/mcp-servers.js";import{ModelRuntime as W}from"../../core/model-runtime.js";import{ProjectTrustStore as D}from"../../core/trust-manager.js";import{fill as q,t as R}from"../../dal/i18n.js";import{openBrowser as G}from"../../utils/open-browser.js";import{questionTerminal as J}from"../../utils/terminal-question.js";import{addMcpServerConfig as Q,getMcpToolExposure as X,loadMcpConfig as L,removeMcpServerConfig as Z}from"./config.js";import{createDefaultTransport as ee,McpOAuthCredentialStore as te,McpServerConnection as re,McpServerLog as ne,McpSignInCancelledError as oe,signInMcpServer as se}from"./runtime.js";const ie=`${I.bold(R("\u7528\u6CD5\uFF1A"))}
|
|
2
|
+
${h} mcp add <server> [options] -- <command> [args...]
|
|
3
|
+
${h} mcp add <server> [options] --url <url>
|
|
4
|
+
${h} mcp remove <server> [-l]
|
|
5
|
+
${h} mcp list [--json]
|
|
6
|
+
${h} mcp login <server> [-l] [--timeout <seconds>]
|
|
7
|
+
${h} mcp logout <server> [-l]
|
|
8
8
|
|
|
9
9
|
Configure and check MCP servers and sign in to OAuth servers without starting a session.
|
|
10
|
-
Reads ~/${
|
|
10
|
+
Reads ~/${T}/agent/mcp.json and, in trusted projects, ${T}/mcp.json.
|
|
11
11
|
|
|
12
12
|
Commands:
|
|
13
13
|
add <server> Add or replace a server in mcp.json
|
|
@@ -16,8 +16,8 @@ Commands:
|
|
|
16
16
|
login <server> Sign in through the browser
|
|
17
17
|
logout <server> Delete the stored OAuth credentials
|
|
18
18
|
|
|
19
|
-
Options for add and
|
|
20
|
-
-l, --local Use ${
|
|
19
|
+
Options for add, remove, login, and logout:
|
|
20
|
+
-l, --local Use ${T}/mcp.json in the current project instead of the global file
|
|
21
21
|
|
|
22
22
|
Options for add:
|
|
23
23
|
--url <url> Streamable HTTP server URL (instead of a command)
|
|
@@ -33,18 +33,20 @@ Options for add:
|
|
|
33
33
|
Fixed OAuth callback port
|
|
34
34
|
--oauth-client-name <name>
|
|
35
35
|
Client name sent when registering with the OAuth server
|
|
36
|
+
--oauth-client-registration <mode>
|
|
37
|
+
auto (default), cimd, or dcr
|
|
36
38
|
--exposure <mode> codemode (default), deferred, direct, or hidden
|
|
37
39
|
--description <text> What the server offers, shown in the system prompt
|
|
38
40
|
|
|
39
41
|
Other options:
|
|
40
42
|
--json Print the list as JSON
|
|
41
|
-
--timeout <seconds> Time limit for the whole sign-in (default: 300)`,
|
|
42
|
-
${
|
|
43
|
-
${
|
|
44
|
-
${
|
|
45
|
-
${
|
|
46
|
-
${
|
|
47
|
-
${
|
|
43
|
+
--timeout <seconds> Time limit for the whole sign-in (default: 300)`,O=I.dim(q(R('\u7528\u6CD5\u89C1 "{app} mcp --help"\u3002'),{app:h})),ae=300;function k(r){return r instanceof Error?r.message:String(r)}p(k,"errorMessage");function ce(r){const{config:t}=r;return"url"in t?t.url:[t.command,...t.args??[]].join(" ")}p(ce,"describeTransport");function _(r){return"url"in r.config?r.config.auth?.provider:void 0}p(_,"getAuthProvider");function F(r,t,s,i){return new re({entry:r,cwd:t.cwd,createTransport:ee,credentials:s,providerToken:i,log:new ne(C(t.agentDir,"mcp.log")),onTools:p(()=>{},"onTools")})}p(F,"createConnection");function le(r){let t;return async s=>{t??=W.create({authPath:C(r,"auth.json"),modelsPath:C(r,"models.json"),refreshOnCreate:!1});try{return(await(await t).getAuth(s))?.auth.apiKey}catch{return}}}p(le,"createProviderTokenReader");const ue=new Map([["-l","--local"]]);function x(r,t,s,i=Number.POSITIVE_INFINITY){const n=[],u=new Map,l=new Map;for(let m=0;m<r.length;m++){const f=r[m],e=ue.get(f)??f;if(e==="--"||n.length>=i){n.push(...r.slice(e==="--"?m+1:m));break}if(!e.startsWith("--")){n.push(e);continue}const d=e.slice(2),a=t[d];if(!a){s(`Unknown option ${f}.
|
|
44
|
+
${O}`);return}if(a==="flag"){u.set(d,!0);continue}const o=r[++m];if(o===void 0){s(`${e} needs a value.`);return}a==="list"?l.set(d,[...l.get(d)??[],o]):u.set(d,o)}return{positional:n,values:u,lists:l}}p(x,"parseOptions");async function Te(r,t){const s=t.log??(o=>console.log(o)),i=t.error??(o=>console.error(o)),[n,...u]=r;if(n===void 0||n==="help"||r.includes("--help")||r.includes("-h"))return s(ie),0;const l=C(t.cwd,T,"mcp.json");if(n==="add"||n==="remove")return n==="add"?fe(u,l,t,s,i):me(u,l,t,s,i);const m=new D(t.agentDir).get(t.cwd)===!0,f=L({agentDir:t.agentDir,cwd:t.cwd,projectTrusted:m}),e=!m&&V(l)?`${l} is ignored because the project is not trusted. Start ${h} in the project to trust it.`:void 0,d=t.credentials??new te,a=t.providerToken??le(t.agentDir);switch(n){case"list":{const o=x(u,{json:"flag"},i);return o?o.positional.length>0?(i(`Usage: ${h} mcp list [--json]
|
|
45
|
+
${O}`),1):pe(f,o.values.has("json"),e,t,d,a,s):1}case"login":case"logout":{const o=x(u,n==="login"?{local:"flag",timeout:"value"}:{local:"flag"},i);if(!o)return 1;const[c,...v]=o.positional;if(!c||v.length>0)return i(`Usage: ${h} mcp ${n} <server> [-l]
|
|
46
|
+
${O}`),1;const w=f.servers.find($=>$.name===c);if(!w){const $=f.servers.map(j=>j.name),A=$.find(j=>de(j,c)<=2);return i(`No MCP server named "${c}".${A?` Did you mean "${A}"?`:""}${e?` ${e}`:""} Configured: ${$.join(", ")||"none"}.`),1}if(o.values.has("local")&&w.scope!=="project")return i(`MCP server "${c}" is defined in ${w.source}, not in the project; omit --local.`),1;const E=_(w);if(E)return i(`MCP server "${c}" uses the credentials of provider "${E}". Run "${h} auth ${n} ${E}".`),1;const M=F(w,t,d,a),b=M.oauthUrl;if(!b)return i(`MCP server "${c}" does not use OAuth. Only HTTP servers without an Authorization header do.`),1;if(n==="logout"){const $=d.remove(c,b);return s($?`Signed out of MCP server "${c}".`:`No stored credentials for MCP server "${c}".`),0}const S=Number(o.values.get("timeout")??ae);if(!Number.isFinite(S)||S<=0)return i("--timeout must be a positive number of seconds."),1;try{return await he(w,M,b,S*1e3,t,d,s,i)}finally{await M.close()}}default:return i(`Unknown mcp command "${n}".
|
|
47
|
+
${O}`),1}}p(Te,"runMcpCommand");function de(r,t){let s=Array.from({length:t.length+1},(i,n)=>n);for(let i=1;i<=r.length;i++){const n=[i];for(let u=1;u<=t.length;u++)n[u]=Math.min(s[u]+1,n[u-1]+1,s[u-1]+(r[i-1]===t[u-1]?0:1));s=n}return s[t.length]}p(de,"editDistance");function H(r,t,s){if(!t)return{};const i={};for(const n of t){const u=n.indexOf("=");if(u<=0){s(`--${r} expects KEY=VALUE, got "${n}".`);return}i[n.slice(0,u)]=n.slice(u+1)}return i}p(H,"parsePairs");function fe(r,t,s,i,n){const u=`Usage: ${h} mcp add <server> [options] (--url <url> | -- <command> [args...])
|
|
48
|
+
${O}`,l=x(r,{local:"flag",url:"value",env:"list",cwd:"value",header:"list","bearer-token-env-var":"value","oauth-client-id":"value","oauth-client-secret":"value","oauth-callback-port":"value","oauth-client-name":"value","oauth-client-registration":"value",exposure:"value",description:"value"},n,2);if(!l)return 1;const{positional:m,values:f,lists:e}=l,[d,...a]=m,o=f.get("url");if(!d||o===void 0==(a.length===0))return n(u),1;const c=p(g=>{const P=f.get(g);return typeof P=="string"?P:void 0},"value"),v=c("exposure"),M=(o===void 0?["header","bearer-token-env-var","oauth-client-id","oauth-client-secret","oauth-callback-port","oauth-client-name","oauth-client-registration"]:["env","cwd"]).find(g=>f.has(g)||e.has(g));if(M)return n(`--${M} only applies to ${o===void 0?"HTTP servers (--url)":"stdio servers"}.`),1;let b;if(typeof o=="string"){const g=H("header",e.get("header"),n);if(!g)return 1;const P=c("bearer-token-env-var");P!==void 0&&(g.Authorization=`Bearer \${${P}}`);const y=c("oauth-callback-port"),U={...c("oauth-client-id")===void 0?{}:{clientId:c("oauth-client-id")},...c("oauth-client-secret")===void 0?{}:{clientSecret:c("oauth-client-secret")},...y===void 0?{}:{callbackPort:Number(y)},...c("oauth-client-name")===void 0?{}:{clientName:c("oauth-client-name")},...c("oauth-client-registration")===void 0?{}:{clientRegistration:c("oauth-client-registration")}};b={url:o,...Object.keys(g).length>0?{headers:g}:{},...Object.keys(U).length>0?{oauth:U}:{}}}else{const g=H("env",e.get("env"),n);if(!g)return 1;const[P,...y]=a;b={command:P,...y.length>0?{args:y}:{},...Object.keys(g).length>0?{env:g}:{},...c("cwd")===void 0?{}:{cwd:c("cwd")}}}v!==void 0&&(b.exposure=v);const S=c("description");S!==void 0&&(b.description=S);const $=B(d,b);if(typeof $=="string")return n($),1;const A=f.has("local"),j=A?t:C(s.agentDir,"mcp.json"),Y=A?"project":"global";let N;try{N=Q(j,d,$)}catch(g){return n(`Could not update ${j}: ${k(g)}`),1}i(`${N?"Replaced":"Added"} ${Y} MCP server "${d}" in ${j}.`),A&&new D(s.agentDir).get(s.cwd)!==!0&&i(`The project is not trusted, so ${j} is ignored until you start ${h} in the project and trust it.`);const z="url"in $&&!Object.keys($.headers??{}).some(g=>g.toLowerCase()==="authorization");return i(`Check it with: ${h} mcp list${z?`. If it requires sign-in: ${h} mcp login ${d}`:""}`),0}p(fe,"add");function me(r,t,s,i,n){const u=x(r,{local:"flag"},n);if(!u)return 1;const[l,...m]=u.positional;if(!l||m.length>0)return n(`Usage: ${h} mcp remove <server> [-l]
|
|
49
|
+
${O}`),1;const f=u.values.has("local"),e=C(s.agentDir,"mcp.json"),d=f?t:e,a=f?"project":"global";let o;try{o=Z(d,l)}catch(v){return n(`Could not update ${d}: ${k(v)}`),1}if(o)return i(`Removed ${a} MCP server "${l}" from ${d}.`),0;const c=L({agentDir:s.agentDir,cwd:s.cwd,projectTrusted:!0}).servers.find(v=>v.name===l&&v.scope!==a);return n(`No ${a} MCP server named "${l}" in ${d}.${c?` It is defined in ${c.source}${c.scope==="project"?"; use --local":"; omit --local"}.`:""}`),1}p(me,"remove");async function pe(r,t,s,i,n,u,l){const m=await Promise.all(r.servers.map(async e=>{const d=_(e),a={name:e.name,scope:e.scope??"global",source:e.source,...e.override?{override:e.override}:{},enabled:e.config.enabled!==!1,exposure:e.config.exposure??"codemode",transport:ce(e),...d?{authProvider:d}:{},state:"disabled",tools:[]};if(!a.enabled)return a;const o=F(e,i,n,u);try{await o.getClient()}catch{}a.state=o.state,a.tools=o.tools.map(v=>v.name);const c=o.tools.flatMap(v=>{const w=X(e.config,v.name);return w===a.exposure?[]:[[v.name,w]]});return c.length>0&&(a.toolExposure=Object.fromEntries(c)),o.hasResources&&(a.resources=!0),o.state!=="connected"&&o.error&&(a.error=o.error),await o.close(),a})),f=r.errors.length>0||m.some(e=>e.enabled&&e.state!=="connected");if(t)return l(JSON.stringify({servers:m,errors:r.errors,...s?{note:s}:{}},null,2)),f?1:0;m.length===0&&r.errors.length===0&&l(`No MCP servers configured. Add them to ${C(i.agentDir,"mcp.json")} or .pi/mcp.json.`);for(const e of m){const d=e.state==="connected"?`connected, ${e.tools.length} tool${e.tools.length===1?"":"s"}`:e.state==="needs-auth"?"needs sign-in":e.state;if(l(`${e.name}: ${d} (${e.exposure}, ${e.scope})`),l(` ${e.transport}`),e.override&&l(` project override: ${e.override}`),e.state==="needs-auth"&&l(e.authProvider?` sign in with: /login ${e.authProvider} in ${h}`:` sign in with: ${h} mcp login ${e.name}`),e.tools.length>0){const a=e.tools.map(o=>{const c=e.toolExposure?.[o];return c?`${o} [${c}]`:o});l(` tools: ${a.join(", ")}`)}e.resources&&l(" offers resources"),e.error&&l(` ${e.error.split(`
|
|
48
50
|
`).join(`
|
|
49
|
-
`)}`)}for(const e of
|
|
50
|
-
${
|
|
51
|
+
`)}`)}for(const e of r.errors)l(`config error: ${e}`);return s&&l(s),f?1:0}p(pe,"list");async function he(r,t,s,i,n,u,l,m){const{name:f}=r;try{return await t.getClient(),l(`Already signed in to MCP server "${f}" (${t.tools.length} tools).`),0}catch{if(t.state!=="needs-auth")return m(`MCP server "${f}" failed to connect: ${t.error??"unknown error"}`),1}const e=n.openUrl??G,d=process.stdin.isTTY===!0&&n.openUrl===void 0;try{await se({serverUrl:s,store:u.forServer(f,s),settings:t.oauthSettings(),challenge:t.challenge,prompt:{showAuthorizationUrl:p(a=>{l(`Sign in to MCP server "${f}" in your browser:
|
|
52
|
+
${a.href}`),e(a.href)},"showAuthorizationUrl"),promptForRedirectUrl:p(a=>ge(a,d),"promptForRedirectUrl")},signal:AbortSignal.timeout(i)})}catch(a){return m(a instanceof oe?`Sign-in to MCP server "${f}" was cancelled or not completed within ${Math.round(i/1e3)} seconds.`:`Sign-in to MCP server "${f}" failed: ${k(a)}`),1}t.challenge=void 0;try{await t.reconnect()}catch(a){return m(`Signed in, but ${k(a)}`),1}return l(`Signed in to MCP server "${f}" (${t.tools.length} tools).`),0}p(he,"login");async function ge(r,t){if(!t){r.aborted||await new Promise(s=>r.addEventListener("abort",s,{once:!0}));return}try{return await J("If the browser cannot reach this machine, paste the URL it was redirected to: ",{signal:r,output:process.stderr})}catch{return}}p(ge,"waitForRedirectUrl");export{Te as runMcpCommand};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var w=Object.defineProperty;var
|
|
2
|
-
`)})}
|
|
1
|
+
var w=Object.defineProperty;var c=(e,o)=>w(e,"name",{value:o,configurable:!0});import{existsSync as p,readFileSync as b}from"node:fs";import{join as S}from"node:path";import{isMcpServerOverride as g,mcpNamespace as $}from"@earendil-works/pi-mcp";import{CONFIG_DIR_NAME as M}from"../../config.js";import{validateMcpServerConfig as x}from"../../core/mcp-servers.js";import{withFileLockSync as O,writeFileAtomicSync as N}from"../../core/shared-data.js";import{stripBom as j}from"../../utils/text.js";import{getMcpToolExposure as V}from"../../core/mcp-servers.js";const C=["enabled","exposure","toolExposure"];function u(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}c(u,"isRecord");function E(e,o,n){const{servers:t,errors:s}=n;if(!p(e))return;let i;try{i=JSON.parse(j(b(e,"utf8")))}catch(r){s.push(`${e}: ${r instanceof Error?r.message:String(r)}`);return}if(!u(i)||i.mcpServers!==void 0&&!u(i.mcpServers)){s.push(`${e}: expected an object with an "mcpServers" object`);return}typeof i.autoEnableCodemode=="boolean"?n.autoEnableCodemode=i.autoEnableCodemode:i.autoEnableCodemode!==void 0&&s.push(`${e}: autoEnableCodemode must be a boolean`);for(const[r,d]of Object.entries(i.mcpServers??{})){if(o==="project"&&u(d)&&g(d)){const f=t.get(r),y=Object.keys(d).filter(m=>!C.includes(m));if(!f)s.push(`${e}: server "${r}" needs "command" or "url", or a global server to override`);else if(y.length>0)s.push(`${e}: server "${r}": an override can only set ${C.join(", ")}`);else{const m=x(r,{...f.config,...d});typeof m=="string"?s.push(`${e}: ${m}`):t.set(r,{...f,config:m,override:e})}continue}const l=x(r,d);if(typeof l=="string"){s.push(`${e}: ${l}`);continue}const v=[...t.keys()].find(f=>f!==r&&$(f)===$(r));if(v){s.push(`${e}: server "${r}" conflicts with "${v}"`);continue}if(o==="project"&&"url"in l&&l.auth){s.push(`${e}: server "${r}": auth is only allowed in the global mcp.json`);continue}t.set(r,{name:r,config:l,source:e,scope:o})}}c(E,"readConfigFile");function T(e){const o={servers:new Map,errors:[]};E(S(e.agentDir,"mcp.json"),"global",o);const n=e.projectTrusted?S(e.cwd,M,"mcp.json"):void 0;return n&&E(n,"project",o),{servers:[...o.servers.values()],...o.autoEnableCodemode===void 0?{}:{autoEnableCodemode:o.autoEnableCodemode},errors:o.errors,...n?{projectConfig:n}:{}}}c(T,"loadMcpConfig");function B(e,o,n,t={}){a(e,(s,i)=>{let r=s?.[o];if(r===void 0&&t.override&&(r={},i.mcpServers={...s,[o]:r}),!u(r))throw new Error(`${e} does not define MCP server "${o}"`);const d=g(r);return n.enabled!==void 0&&(n.enabled&&!d?delete r.enabled:r.enabled=n.enabled),n.exposure!==void 0&&(n.exposure==="codemode"&&!d?delete r.exposure:r.exposure=n.exposure),!0})}c(B,"updateMcpServerConfig");function G(e,o,n){let t=!1;return a(e,(s,i)=>{const r=s??{};return t=r[o]!==void 0,r[o]=n,i.mcpServers=r,!0}),t}c(G,"addMcpServerConfig");function K(e,o){if(!p(e))return!1;let n=!1;return a(e,t=>!t||t[o]===void 0?!1:(delete t[o],n=!0,!0)),n}c(K,"removeMcpServerConfig");function a(e,o){O(e,()=>{const n=p(e)?j(b(e,"utf8")):void 0,t=n===void 0?{}:JSON.parse(n);if(!u(t)||t.mcpServers!==void 0&&!u(t.mcpServers))throw new Error(`${e}: expected an object with an "mcpServers" object`);const s=u(t.mcpServers)?t.mcpServers:void 0;if(!o(s,t))return;const i=n&&/^([ \t]+)\S/m.exec(n)?.[1]||" ";N(e,`${JSON.stringify(t,null,i)}
|
|
2
|
+
`)})}c(a,"editMcpServers");export{G as addMcpServerConfig,V as getMcpToolExposure,T as loadMcpConfig,K as removeMcpServerConfig,B as updateMcpServerConfig};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
var Ge=Object.defineProperty;var i=(l,a)=>Ge(l,"name",{value:a,configurable:!0});import{join as Ke,resolve as Ce}from"node:path";import{getAgentDir as z}from"../../config.js";import{
|
|
2
|
-
`,1)[0]??""}i(Te,"firstLine");function p(l){return l.entry.config.enabled!==!1}i(p,"isEnabled");function P(l){return l.config.exposure??"codemode"}i(P,"exposureOf");function V(l){return new Set([P(l),...Object.values(l.config.toolExposure??{})])}i(V,"configuredExposures");function
|
|
3
|
-
`,1)[0]??"").trim()}i(
|
|
4
|
-
`).length,"size");let b=a.length;for(;b>0&&T(b)>Pe;)b--;const j=b===0?0:Math.min(
|
|
5
|
-
`)}i(
|
|
1
|
+
var Ge=Object.defineProperty;var i=(l,a)=>Ge(l,"name",{value:a,configurable:!0});import{join as Ke,resolve as Ce}from"node:path";import{createMcpToolName as ve,mcpNamespace as N}from"@earendil-works/pi-mcp";import{getAgentDir as z}from"../../config.js";import{sliceHead as Qe}from"../../core/tools/truncate.js";import{openBrowser as Ye}from"../../utils/open-browser.js";import{CODEMODE_TOOL_NAME as F}from"../codemode/tool.js";import{TOOL_SEARCH_TOOL_NAME as H}from"../tool-search/tool.js";import{getMcpToolExposure as ne,loadMcpConfig as Ze,updateMcpServerConfig as en}from"./config.js";import{createMcpResourceToolDefinitions as nn,LIST_MCP_RESOURCE_TEMPLATES_TOOL as tn,LIST_MCP_RESOURCES_TOOL as on,READ_MCP_RESOURCE_TOOL as rn}from"./resources.js";import{loadMcpRuntime as B}from"./runtime.lazy.js";import{createMcpToolDefinition as sn,createMcpToolRenderers as cn}from"./tools.js";import{showMcpManager as Me}from"./ui.js";const an=1e4,ln=new Set([on,tn,rn]),te={codemode:"called from codemode scripts, which find them with searchTools()",deferred:"not declared until tool_search loads them, then called directly; no codemode needed",direct:"declared to the model like built-in tools"};function O(l){return l instanceof Error?l.message:String(l)}i(O,"errorMessage");function Te(l){return l.split(`
|
|
2
|
+
`,1)[0]??""}i(Te,"firstLine");function p(l){return l.entry.config.enabled!==!1}i(p,"isEnabled");function P(l){return l.config.exposure??"codemode"}i(P,"exposureOf");function V(l){return new Set([P(l),...Object.values(l.config.toolExposure??{})])}i(V,"configuredExposures");function dn(l){return V(l).has("direct")}i(dn,"hasDirectTools");function un(l){const a=V(l);return a.has("codemode")||a.has("deferred")}i(un,"hasIndirectTools");const Ee="mcp_servers",fn=250,Pe=4096;function mn(l){let a="MCP servers whose tools are not declared to you.";return l.has("codemode")&&(a+=" Call the tools of `codemode` servers from codemode scripts."),l.has("tool_search")&&(a+=" Load the tools of `tool_search` servers with `tool_search`."),a}i(mn,"serversSectionIntro");function gn(l,a){return l.length<=a?l:a<=1?"":`${Qe(l,a-1).trimEnd()}\u2026`}i(gn,"truncate");function hn(l){return((l.entry.config.description?.trim()||l.connection?.instructions||"").split(`
|
|
3
|
+
`,1)[0]??"").trim()}i(hn,"serverSummary");function pn(l){const a=l.filter(h=>p(h)&&un(h.entry)).sort((h,E)=>h.entry.name.localeCompare(E.entry.name));if(a.length===0)return;const u=a.map(h=>V(h.entry).has("codemode")?"codemode":"tool_search"),C=mn(new Set(u)),S=a.map((h,E)=>`- ${N(h.entry.name)} (${u[E]})`),R=i(h=>h>0?[`- \u2026 ${h} more server${h===1?"":"s"}; find their tools with searchTools()`]:[],"omitted"),T=i(h=>[C,...S.slice(0,h),...R(a.length-h)].join(`
|
|
4
|
+
`).length,"size");let b=a.length;for(;b>0&&T(b)>Pe;)b--;const j=b===0?0:Math.min(fn,Math.floor((Pe-T(b))/b)-2),k=a.slice(0,b).map((h,E)=>{const U=j>0?gn(hn(h),j):"";return U?`${S[E]}: ${U}`:S[E]});return[C,...k,...R(a.length-b)].join(`
|
|
5
|
+
`)}i(pn,"renderServersSection");function yn(l,a){if(l==="all")return!0;const u=N(a);return l.some(C=>C.includes(u))}i(yn,"reachesServer");function D(l,a=!0){if(!p(l))return"disabled";const u=l.connection;if(!u)return"starting";switch(u.state){case"needs-auth":return"needs sign-in";case"failed":return a?`failed: ${Te(u.error??"unknown error")}`:"failed";case"connected":{const{tools:C,hasResources:S}=u;return`connected \xB7 ${C.length} tool${C.length===1?"":"s"}${S?" \xB7 resources":""}`}case"connecting":return"connecting\u2026";default:return u.state}}i(D,"describeState");function _e(l){if(!p(l))return 5;switch(l.connection?.state){case"needs-auth":return 0;case"failed":return 1;case"disconnected":return 2;case"connected":return 4;default:return 3}}i(_e,"attentionRank");function bn(l){const{config:a}=l;return"url"in a?a.url:[a.command,...a.args??[]].join(" ")}i(bn,"describeTransport");const Ae="Usage: /mcp, /mcp login [server], /mcp logout [server], /mcp reconnect [server]";function wn(l={}){return a=>{let u=[],C=[],S=[],R,T=[],b=!0,j=!1,k,h=!1;const E=l.startupWaitMs??an;let U=process.cwd(),x=l.credentials,oe,re;const se=l.openUrl??Ye,Oe=l.updateConfig??((e,n)=>en(e.override??e.source,e.name,n,{override:e.override!==void 0}));let $=new AbortController;$.abort();const X=new Set,ie=i(e=>{const n=e.then(()=>{},()=>{});return X.add(n),n.finally(()=>X.delete(n)),e},"track"),J=new Set,v=i(()=>{for(const e of J)e()},"emitChange"),ce=i(e=>(J.add(e),()=>{J.delete(e)}),"subscribe"),Re=i(()=>u.flatMap(e=>e.connection?[e.connection]:[]),"connections"),L=i(e=>u.find(n=>n.entry.name===e),"findServer"),ae=i(()=>{const e=[],n=[];for(const{name:t,config:r,extensionPath:o}of a.getMcpServers()){const s=C.find(c=>N(c.name)===N(t));if(s){n.push(`"${t}" registered by ${o} is overridden by "${s.name}" in ${s.source}`);continue}e.push({entry:{name:t,config:r,source:o,scope:"extension"},registeredConfig:JSON.stringify(r)})}return{servers:e,overridden:n}},"registeredServers"),q=i(e=>(x??=new e.McpOAuthCredentialStore,x),"getCredentials"),je=i(e=>(re??=new e.McpServerLog(l.logPath??Ke(z(),"mcp.log")),re),"getServerLog"),G=new Map,I=new Map,K=new Map;a.registerToolRenderer((e,n)=>{const t=/^mcp__(.+?)__(.+)$/.exec(e);return n()??(t?cn(`${t[1]}/${t[2]}`):void 0)});const le=i(e=>{const n=e.entry.name,t=L(n)?.entry??e.entry,r=t.config.description?.trim(),o={name:N(n),aliases:[n],...r?{description:r}:{},...e.instructions?{instructions:e.instructions}:{}},s=I.get(n)??new Set,c=new Set,d=[...new Set(e.tools.map(m=>m.name))].map(m=>ve(n,m)),f=i((m,g)=>{const w=ve(n,m,y=>{const M=G.get(y);return M!==void 0&&M!==g||c.has(y)||d.indexOf(y)!==d.lastIndexOf(y)});return G.set(w,g),c.add(w),w},"assignName");for(const m of e.tools){const g=sn({server:n,tool:m,name:f(m.name,`${n}\0${m.name}`),exposure:ne(t.config,m.name),namespace:o,timeoutMs:e.timeoutMs,getClient:i(async()=>{const w=L(n);if(!w||!p(w))throw new Error(`MCP server "${n}" is disabled.`);const y=w.connection;if(!y)throw new Error(`MCP server "${n}" is still starting.`);if(ne(w.entry.config,m.name)==="hidden"||y.state==="connected"&&!y.tools.some(M=>M.name===m.name))throw new Error(`MCP tool "${n}/${m.name}" is no longer available.`);return y},"getClient"),readableResources:i(()=>fe().some(w=>w.name===n),"readableResources")});K.set(g.name,g),a.registerTool(g)}I.set(n,c);for(const m of s){const g=K.get(m);!c.has(m)&&g&&a.registerTool({...g,exposure:"hidden"})}Q()},"registerTools"),de=i(e=>{for(const n of I.get(e)??[]){const t=K.get(n);t&&a.registerTool({...t,exposure:"hidden"})}I.set(e,new Set),Q()},"hideTools"),ue=i(()=>u.filter(e=>e.connection?.hasResources&&p(e)&&P(e.entry)!=="hidden"),"serversWithResources"),fe=i(()=>ue().flatMap(e=>e.connection?[e.connection]:[]),"resourceServers");let W;const Q=i(()=>{const e=new Set(ue().map(s=>P(s.entry))),t=["direct","codemode","deferred"].find(s=>e.has(s))??"hidden";if(t===W||W===void 0&&t==="hidden")return;const r=W==="direct";W=t;const o=nn({exposure:t,servers:fe});for(const s of o)a.registerTool(s);if(r){const s=new Set(o.map(c=>c.name));a.setActiveTools(a.getActiveTools().filter(c=>!s.has(c)))}},"syncResourceTools"),_=i(e=>{const n=new Set;for(const y of u)if(p(y))for(const M of V(y.entry))n.add(M);const t=n.has("codemode"),r=n.has("deferred");if(!t&&!r)return;const o=a.getAllTools(),s=i(y=>o.some(M=>M.name===y&&M.reachesTools),"hasReachingTool"),c=s(F),d=s(H),f=a.getActiveTools(),m=[];t&&c&&b&&!f.includes(F)&&m.push(F),r&&d&&!f.includes(H)&&m.push(H),m.length>0&&a.setActiveTools([...f,...m]);const g=[...f,...m];if(c&&g.includes(F)||d&&g.includes(H)||j)return;j=!0;const w=t&&c&&!b?" (autoEnableCodemode is false)":"";e.ui.notify(`MCP tools are only reachable from the codemode or tool_search tool, but neither is active${w}; they cannot be called.`,"warning")},"ensureDiscoveryActive"),A=new Map,me=i(e=>{const n=e.oauthUrl;return n&&x?JSON.stringify(x.tokens(e.name,n)??null):"null"},"storedTokens"),Le=i(e=>{e.state!=="needs-auth"?A.delete(e):A.has(e)||A.set(e,me(e)),v()},"onConnectionChange"),ke=i(async e=>{const n=[...A].filter(([t,r])=>me(t)!==r);if(n.length!==0){for(const[t]of n)A.delete(t);await Promise.allSettled(n.map(([t])=>t.reconnect())),_(e)}},"reconnectSignedIn"),Ue=i(async(e,n)=>{const t=await B();if(!n())return;const r=new t.McpServerConnection({entry:e.entry,cwd:U,createTransport:l.createTransport??t.createDefaultTransport,credentials:q(t),providerToken:i(async o=>oe?.getApiKeyForProvider(o),"providerToken"),log:je(t),onTools:i(o=>{n()&&le(o)},"onTools"),onChange:i(o=>{n()?Le(o):A.delete(o)},"onChange")});return e.connection=r,v(),r},"createConnection"),Y=i((e,n)=>{const{signal:t}=$,r=Symbol();e.attempt=r;const o=i(()=>!t.aborted&&e.attempt===r&&p(e)&&u.includes(e),"isCurrent"),s=(async()=>{if(await n,!o())return;const c=await Ue(e,o);!c||!o()||await c.getClient().catch(()=>{})})();return e.ready=s.catch(()=>{}),s},"startConnection"),Ie=i(async(e,n)=>{for(;;){const t=e.flatMap(o=>p(o)&&u.includes(o)&&o.ready?[{server:o,ready:o.ready}]:[]);if(t.length===0||n?.aborted)return;let r;if(await Promise.race([Promise.all(t.map(o=>o.ready)),new Promise(o=>{r=i(()=>o(),"onAbort"),n?.addEventListener("abort",r,{once:!0})})]),r&&n?.removeEventListener("abort",r),n?.aborted||t.every(o=>!p(o.server)||!u.includes(o.server)||o.ready===o.server.ready))return}},"waitForServers"),Z=i((e,n)=>{const t=n?[]:S.map(r=>`config: ${r}`);for(const r of n??u){const o=r.connection?.state;(o==="needs-auth"||o==="failed")&&t.push(`${r.entry.name}: ${D(r)}`)}t.length!==0&&e.ui.notify(`MCP servers need attention:
|
|
6
6
|
${t.map(r=>` ${r}`).join(`
|
|
7
7
|
`)}
|
|
8
8
|
Run /mcp to fix.`,"warning")},"reportProblems"),ge=i((e,n,t=!1)=>{const r=t?R:e.entry.override,o=r?{...e.entry,override:r}:e.entry;if(o.scope!=="extension")try{Oe(o,n)}catch(s){return`Could not update ${o.override??o.source}: ${O(s)}`}e.entry={...o,config:{...o.config,...n}}},"saveConfig"),he=i(async(e,n,t)=>{const r=e.connection,o=r?.oauthUrl;if(!r||!o)return`MCP server "${e.entry.name}" does not use OAuth.`;const s=await B(),c=t?AbortSignal.any([$.signal,t]):$.signal;try{await ie(s.signInMcpServer({serverUrl:o,store:q(s).forServer(e.entry.name,o),settings:r.oauthSettings(),challenge:r.challenge,prompt:n,signal:c}))}catch(d){return d instanceof s.McpSignInCancelledError?"Sign-in cancelled.":`Sign-in failed: ${O(d)}`}r.challenge=void 0;try{await r.reconnect()}catch(d){return`Signed in, but ${O(d)}`}},"signIn"),pe=i(async e=>{const n=e.connection,t=n?.oauthUrl;if(!n||!t)return!1;const r=q(await B()).remove(e.entry.name,t);return await n.signOut(),r},"signOut"),ye=i(async e=>{const n=e.connection;if(!n)return`MCP server "${e.entry.name}" is disabled.`;const t=e.ready,r=(async()=>{await t,await n.reconnect()})();e.ready=r.catch(()=>{});try{await r;return}catch(o){return O(o)}},"reconnect"),Ne=i(async(e,n,t=!1)=>{const r=ge(e,{enabled:n},t);if(r)return r;if(!n){const o=e.connection;e.attempt=void 0,e.connection=void 0,o&&(e.closing=Promise.all([o.close(),e.ready]).then(()=>{}));const s=e.closing;de(e.entry.name),v();try{await s}finally{e.closing===s&&(e.closing=void 0)}return}await Y(e,e.closing)},"setEnabled"),De=i((e,n)=>{const t=ge(e,{exposure:n});if(t)return t;e.connection?.state==="connected"&&le(e.connection),Q();const r=new Set(a.getAllTools().filter(s=>s.exposure!=="direct").map(s=>s.name)),o=I.get(e.entry.name)??new Set;a.setActiveTools(a.getActiveTools().filter(s=>!o.has(s)||!r.has(s))),v()},"setExposure"),xe=i(()=>[...S.map(e=>`config: ${e}`),...T.map(e=>`overridden: ${e}`)],"notices"),We=i(()=>({title:"MCP servers",error:xe().join(`
|
|
9
|
-
`)||void 0,items:[...u].sort((e,n)=>_e(e)-_e(n)||e.entry.name.localeCompare(n.entry.name)).map(e=>({value:e.entry.name,label:e.entry.name,description:`${D(e)} \xB7 ${P(e.entry)} \xB7 ${e.entry.override?"global, project override":e.entry.scope??e.entry.source}`})),empty:`No MCP servers configured. Add them to ${Ce(z(),"mcp.json")} or .pi/mcp.json.`,confirmLabel:"manage",cancelLabel:"close"}),"serversMenu"),ze=i(e=>{const n=L(e);if(!n)return{title:e,items:[],empty:"This server is no longer configured.",confirmLabel:"",cancelLabel:"back"};const{entry:t,connection:r}=n,o=t.scope==="extension"?"for this session":t.override?"saved to the project mcp.json":t.scope?`saved to the ${t.scope} mcp.json`:"saved to mcp.json",s=t.scope==="global"&&!t.override&&R!==void 0,c="saved to the project mcp.json",d=[];if(!p(n))d.push({value:"enable",label:"Enable",description:o}),s&&d.push({value:"enable-project",label:"Enable in this project",description:c});else{const g=r?.state;g==="needs-auth"&&d.push({value:"signin",label:"Sign in",description:"opens the browser"}),g==="connected"&&r&&d.push({value:"tools",label:"Tools",description:`${r.tools.length} offered`}),(g==="failed"||g==="disconnected"||g==="connected"||g==="needs-auth")&&d.push({value:"reconnect",label:"Reconnect"}),g==="connected"&&r?.oauthUrl&&d.push({value:"signout",label:"Sign out",description:"deletes the stored credentials"}),d.push({value:"exposure",label:"Exposure",description:P(t)}),d.push({value:"disable",label:"Disable",description:o}),s&&d.push({value:"disable-project",label:"Disable in this project",description:c})}const f=[
|
|
9
|
+
`)||void 0,items:[...u].sort((e,n)=>_e(e)-_e(n)||e.entry.name.localeCompare(n.entry.name)).map(e=>({value:e.entry.name,label:e.entry.name,description:`${D(e)} \xB7 ${P(e.entry)} \xB7 ${e.entry.override?"global, project override":e.entry.scope??e.entry.source}`})),empty:`No MCP servers configured. Add them to ${Ce(z(),"mcp.json")} or .pi/mcp.json.`,confirmLabel:"manage",cancelLabel:"close"}),"serversMenu"),ze=i(e=>{const n=L(e);if(!n)return{title:e,items:[],empty:"This server is no longer configured.",confirmLabel:"",cancelLabel:"back"};const{entry:t,connection:r}=n,o=t.scope==="extension"?"for this session":t.override?"saved to the project mcp.json":t.scope?`saved to the ${t.scope} mcp.json`:"saved to mcp.json",s=t.scope==="global"&&!t.override&&R!==void 0,c="saved to the project mcp.json",d=[];if(!p(n))d.push({value:"enable",label:"Enable",description:o}),s&&d.push({value:"enable-project",label:"Enable in this project",description:c});else{const g=r?.state;g==="needs-auth"&&d.push({value:"signin",label:"Sign in",description:"opens the browser"}),g==="connected"&&r&&d.push({value:"tools",label:"Tools",description:`${r.tools.length} offered`}),(g==="failed"||g==="disconnected"||g==="connected"||g==="needs-auth")&&d.push({value:"reconnect",label:"Reconnect"}),g==="connected"&&r?.oauthUrl&&d.push({value:"signout",label:"Sign out",description:"deletes the stored credentials"}),d.push({value:"exposure",label:"Exposure",description:P(t)}),d.push({value:"disable",label:"Disable",description:o}),s&&d.push({value:"disable-project",label:"Disable in this project",description:c})}const f=[bn(t),`${t.scope??"config"}: ${t.source}`,...t.override?[`project override: ${t.override}`]:[],`State: ${D(n,!1)}`],m=[n.message,r?.state==="connected"?void 0:r?.error].filter(g=>g!==void 0).join(`
|
|
10
10
|
`);return{title:`MCP server ${e}`,details:f.join(`
|
|
11
11
|
`),error:m||void 0,items:d,selected:d[0]?.value,confirmLabel:"select",cancelLabel:"back"}},"serverMenu"),Fe=i(async(e,n)=>{const t=P(n.entry),r=Object.keys(n.entry.config.toolExposure??{}).length>0;await e.menu(()=>({title:`Tools of ${n.entry.name}`,details:`Exposure ${t}: ${t==="hidden"?"unreachable":te[t]}${r?`
|
|
12
12
|
Some tools override it with toolExposure.`:""}`,items:(n.connection?.tools??[]).map(o=>{const s=ne(n.entry.config,o.name),c=Te(o.description??"");return{value:o.name,label:o.name,description:s===t?c:`[${s}] ${c}`}}),empty:"The server offers no tools.",confirmLabel:"back",cancelLabel:"back"}))},"showTools"),He=i(async(e,n)=>{const t=P(n.entry),r=await e.menu(()=>({title:`Exposure of ${n.entry.name}`,details:n.entry.scope==="extension"?`Applies to this session; the server is registered by ${n.entry.source}.`:`Saved to ${n.entry.override??n.entry.source}.`,items:Object.keys(te).map(o=>({value:o,label:`${o===t?"\u2713 ":" "}${o}`,description:te[o]})),selected:t,confirmLabel:"save",cancelLabel:"back"}));if(!(!r||r===t))return De(n,r)},"chooseExposure"),be=i((e,n)=>{const t=`Sign in to ${n.entry.name}`,r=new AbortController,o=i(c=>e.status(t,c,()=>r.abort()),"status");let s="";return o("Contacting the authorization server\u2026"),he(n,{showAuthorizationUrl:i(c=>{s=c.href,se(c.href)},"showAuthorizationUrl"),promptForRedirectUrl:i(async c=>{const d=await e.redirectUrl(t,s,c);return o("Connecting\u2026"),d},"promptForRedirectUrl")},r.signal)},"signInWithUi"),we=i((e,n,t)=>{const r=t(),o=n.attempt,{signal:s}=$,c=i(d=>{s.aborted||n.attempt!==o||!u.includes(n)||(n.message=d,_(e),v())},"finish");ie(r.then(c,d=>c(O(d))))},"runInBackground"),Be=i(async(e,n,t,r)=>{const{signal:o}=$;let s;switch(r){case"signin":s=await be(e,t);break;case"reconnect":we(n,t,async()=>{await ye(t)});break;case"signout":await pe(t);break;case"tools":await Fe(e,t);break;case"exposure":s=await He(e,t);break;case"enable":case"disable":case"enable-project":case"disable-project":{const c=r.startsWith("enable");we(n,t,()=>Ne(t,c,r.endsWith("-project")));break}}o.aborted||(t.message=s,_(n),v())},"runAction"),Ve=i(async(e,n)=>{for(;;){const t=await e.menu(We,ce);if(!t)return;for(;;){const r=await e.menu(()=>ze(t),ce),o=L(t);if(!r||!o)break;await Be(e,n,o,r)}}},"manage"),Xe=i(()=>{if(u.length===0&&S.length===0&&T.length===0)return`No MCP servers configured. Add them to ${Ce(z(),"mcp.json")} or .pi/mcp.json.`;const e=u.map(n=>{const{name:t}=n.entry,r=P(n.entry),o=n.connection;if(o?.state==="needs-auth")return`${t}: needs sign-in, run /mcp login ${t} (${r})`;const s=o?.state==="connected"?`, ${o.tools.length} tools`:"",c=p(n)?o?.state==="disconnected"?"disconnected, reconnects on next call":o?.state??"starting":"disabled",d=o?.error&&o.state!=="connected"?`
|
|
@@ -14,4 +14,4 @@ Some tools override it with toolExposure.`:""}`,items:(n.connection?.tools??[]).
|
|
|
14
14
|
`).join(`
|
|
15
15
|
`)}`:"";return`${t}: ${c}${s} (${r})${d}`});for(const n of S)e.push(`config error: ${n}`);for(const n of T)e.push(`overridden: ${n}`);return e.join(`
|
|
16
16
|
`)},"formatStatus"),ee=i(async(e,n,t)=>{if(e){const c=L(e);return c?t.eligible(c)||n.ui.notify(t.none,"error"):n.ui.notify(`No MCP server named "${e}".`,"error"),c&&t.eligible(c)?c:void 0}const r=u.filter(t.eligible);if(r.length===0){n.ui.notify(t.none,"info");return}const o=r.filter(t.preferred);if(r.length===1)return r[0];if(o.length===1)return o[0];const s=await n.ui.select("MCP server",r.map(c=>c.entry.name));return r.find(c=>c.entry.name===s)},"pickServer"),Se=i(e=>e.connection?.oauthUrl!==void 0,"usesOAuth"),$e={eligible:Se,preferred:i(e=>e.connection?.state==="needs-auth","preferred"),none:"No enabled MCP server uses OAuth. Only HTTP servers without an Authorization header do."},Je=i(async(e,n)=>{const{name:t}=e.entry;if(!n.hasUI){n.ui.notify(`Signing in to MCP server "${t}" requires interactive mode.`,"error");return}const{signal:r}=$;let o;if(n.mode==="tui"?await Me(n,async s=>{o=await be(s,e)}):o=await he(e,{showAuthorizationUrl:i(s=>{n.ui.notify(`Sign in to MCP server "${t}" in your browser:
|
|
17
|
-
${s.href}`,"info"),se(s.href)},"showAuthorizationUrl"),promptForRedirectUrl:i(s=>n.ui.input(`Waiting for sign-in to "${t}". If the browser cannot reach this machine, paste the URL it was redirected to.`,"http://127.0.0.1:.../callback?code=...",{signal:s}),"promptForRedirectUrl")}),!r.aborted){if(o){n.ui.notify(o,o==="Sign-in cancelled."?"info":"error");return}_(n),n.ui.notify(`Signed in to MCP server "${t}" (${e.connection?.tools.length??0} tools).`,"info")}},"loginCommand");a.on("session_start",(e,n)=>{const t=(l.loadConfig??
|
|
17
|
+
${s.href}`,"info"),se(s.href)},"showAuthorizationUrl"),promptForRedirectUrl:i(s=>n.ui.input(`Waiting for sign-in to "${t}". If the browser cannot reach this machine, paste the URL it was redirected to.`,"http://127.0.0.1:.../callback?code=...",{signal:s}),"promptForRedirectUrl")}),!r.aborted){if(o){n.ui.notify(o,o==="Sign-in cancelled."?"info":"error");return}_(n),n.ui.notify(`Signed in to MCP server "${t}" (${e.connection?.tools.length??0} tools).`,"info")}},"loginCommand");a.on("session_start",(e,n)=>{const t=(l.loadConfig??Sn)(n);S=t.errors,R=t.projectConfig,b=t.autoEnableCodemode??!0,j=!1,h=!1,U=n.cwd,oe=n.modelRegistry,$=new AbortController;const{signal:r}=$;C=t.servers;const o=ae();T=o.overridden,u=[...t.servers.map(d=>({entry:d})),...o.servers],v(),_(n);const s=u.filter(p);if(s.length===0){Z(n);return}const c=new Promise(d=>setImmediate(d)).then(()=>B());k=Promise.all(s.map(d=>Y(d,c))).then(()=>{r.aborted||Z(n)}).catch(d=>{try{n.ui.notify(`MCP failed to load: ${O(d)}`,"error")}catch{}})});const qe=i(async e=>{if(h)return;h=!0;const n=u.flatMap(o=>p(o)&&dn(o.entry)&&o.ready?[o.ready]:[]);if(n.length===0)return;let t;const r=await Promise.race([Promise.all(n).then(()=>!0),new Promise(o=>{t=setTimeout(()=>o(!1),E)})]);clearTimeout(t),r||e.ui.notify("MCP servers are still connecting; their tools become available once connected.","info")},"waitForDirectServers");a.on("before_agent_start",async(e,n)=>{await qe(n);const{sections:t}=e.systemPromptOptions,r=pn(u);r?t[Ee]=r:delete t[Ee]}),a.on("tool_call",async(e,n)=>{const t=a.getAllTools().find(c=>c.name===e.toolName);if(!t)return;const r=u.filter(c=>p(c)&&c.ready);if(r.length===0)return;let o=[];const s=t.reachesTools?.(e.input);if(s!==void 0)o=r.filter(c=>yn(s,c.entry.name));else if(ln.has(t.name))o=r;else{const c=G.get(e.toolName)?.split("\0",1)[0];o=r.filter(d=>d.entry.name===c)}await Ie(o,n.signal)}),a.on("turn_start",async(e,n)=>{A.size>0&&await ke(n)}),a.on("mcp_servers_change",async(e,n)=>{const{signal:t}=$;if(t.aborted)return;const r=ae();T=r.overridden;const o=new Map(r.servers.map(f=>[f.entry.name,f])),s=u.filter(f=>f.entry.scope==="extension"&&o.get(f.entry.name)?.registeredConfig!==f.registeredConfig);u=u.filter(f=>!s.includes(f));for(const f of s)de(f.entry.name);const c=r.servers.filter(f=>!L(f.entry.name));u.push(...c),v(),_(n),await Promise.all(s.map(f=>f.connection?.close()));const d=c.filter(p);if(!(t.aborted||d.length===0)){try{if(await Promise.all(d.map(f=>Y(f))),t.aborted){await Promise.all(d.map(f=>f.connection?.close()));return}}catch(f){n.ui.notify(`MCP failed to load: ${O(f)}`,"error");return}t.aborted||Z(n,d)}}),a.on("session_shutdown",async()=>{$.abort();const e=Re();u=[],v(),await Promise.all([...X,...e.map(n=>n.close())])}),a.registerCommand("mcp",{description:"Manage MCP servers: sign in, reconnect, enable or disable, and change exposure",getArgumentCompletions:i(e=>{const[n,t,...r]=e.trimStart().split(/\s+/);if(r.length>0)return null;if(t===void 0)return["login","logout","reconnect"].filter(s=>s.startsWith(n??"")).map(s=>({value:`${s} `,label:s}));if(n!=="login"&&n!=="logout"&&n!=="reconnect")return null;const o=u.filter(s=>n==="reconnect"?s.connection!==void 0:Se(s)).filter(s=>s.entry.name.startsWith(t)).map(s=>({value:`${n} ${s.entry.name}`,label:s.entry.name,description:D(s)}));return o.length>0?o:null},"getArgumentCompletions"),handler:i(async(e,n)=>{const[t,r,...o]=e.trim().split(/\s+/).filter(Boolean);if(t===void 0){n.mode==="tui"?await Me(n,s=>Ve(s,n)):(await k,n.ui.notify(Xe(),"info"));return}if(o.length>0){n.ui.notify(Ae,"warning");return}switch(await k,t){case"login":{const s=await ee(r,n,$e);s&&await Je(s,n);return}case"logout":{const s=await ee(r,n,$e);if(!s)return;const c=await pe(s);n.ui.notify(c?`Signed out of MCP server "${s.entry.name}".`:`No stored credentials for MCP server "${s.entry.name}".`,"info");return}case"reconnect":{const s=await ee(r,n,{eligible:i(d=>d.connection!==void 0,"eligible"),preferred:i(d=>d.connection?.state==="failed"||d.connection?.state==="disconnected","preferred"),none:"No enabled MCP server to reconnect."});if(!s)return;const c=await ye(s);c?n.ui.notify(c,"error"):(_(n),n.ui.notify(`Reconnected to MCP server "${s.entry.name}" (${D(s)}).`,"info"));return}default:n.ui.notify(Ae,"warning")}},"handler")})}}i(wn,"createMcpExtension");function Sn(l){return Ze({agentDir:z(),cwd:l.cwd,projectTrusted:l.isProjectTrusted()})}i(Sn,"defaultLoadConfig");var kn=wn();export{Pe as MAX_SERVERS_SECTION_CHARS,Ee as MCP_SERVERS_SECTION,wn as createMcpExtension,kn as default,pn as renderServersSection};
|
|
@@ -1,19 +1,6 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { type McpOAuthState, type McpOAuthStateStore, type OAuthChallenge } from "@earendil-works/pi-mcp/oauth";
|
|
1
|
+
import { type McpAuthProvider, type McpOAuthServerStore, type McpOAuthSettings, type McpOAuthState, type OAuthChallenge } from "@earendil-works/pi-mcp/oauth";
|
|
3
2
|
import { type AuthStorageBackend } from "../../core/auth-storage.ts";
|
|
4
|
-
export
|
|
5
|
-
clientId?: string;
|
|
6
|
-
clientSecret?: string;
|
|
7
|
-
callbackPort?: number;
|
|
8
|
-
callbackUrl?: string;
|
|
9
|
-
scope?: string;
|
|
10
|
-
clientName?: string;
|
|
11
|
-
clientRegistration?: "dcr" | "cimd";
|
|
12
|
-
authServerMetadataUrl?: URL;
|
|
13
|
-
}
|
|
14
|
-
export interface McpOAuthServerStore extends McpOAuthStateStore {
|
|
15
|
-
withRefreshLock<T>(fn: () => Promise<T>): Promise<T>;
|
|
16
|
-
}
|
|
3
|
+
export { type McpAuthProvider, type McpOAuthServerStore, type McpOAuthSettings, McpSignInCancelledError, } from "@earendil-works/pi-mcp/oauth";
|
|
17
4
|
export declare class McpOAuthCredentialStore {
|
|
18
5
|
private readonly backend;
|
|
19
6
|
private readonly lockDir;
|
|
@@ -24,9 +11,6 @@ export declare class McpOAuthCredentialStore {
|
|
|
24
11
|
remove(name: string, serverUrl: string): boolean;
|
|
25
12
|
private write;
|
|
26
13
|
}
|
|
27
|
-
export interface McpAuthProvider extends AuthProvider {
|
|
28
|
-
settled(): Promise<void>;
|
|
29
|
-
}
|
|
30
14
|
export declare function createMcpAuthProvider(options: {
|
|
31
15
|
serverUrl: string;
|
|
32
16
|
store: McpOAuthServerStore;
|
|
@@ -37,12 +21,9 @@ export interface McpSignInPrompt {
|
|
|
37
21
|
showAuthorizationUrl(url: URL): void;
|
|
38
22
|
promptForRedirectUrl(signal: AbortSignal): Promise<string | undefined>;
|
|
39
23
|
}
|
|
40
|
-
export declare class McpSignInCancelledError extends Error {
|
|
41
|
-
constructor();
|
|
42
|
-
}
|
|
43
24
|
export declare function signInMcpServer(options: {
|
|
44
25
|
serverUrl: string;
|
|
45
|
-
store:
|
|
26
|
+
store: McpOAuthServerStore;
|
|
46
27
|
settings: McpOAuthSettings;
|
|
47
28
|
challenge?: OAuthChallenge;
|
|
48
29
|
prompt: McpSignInPrompt;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
2
|
-
`}s(
|
|
1
|
+
var M=Object.defineProperty;var s=(i,t)=>M(i,"name",{value:t,configurable:!0});import{createHash as R}from"node:crypto";import{mkdirSync as A}from"node:fs";import{join as f}from"node:path";import{oauthErrorHtml as C,oauthSuccessHtml as _}from"@earendil-works/pi-ai/utils/oauth-page";import{mcpNamespace as b}from"@earendil-works/pi-mcp";import{completeMcpSignIn as D,createMcpAuthProvider as v,listenForLoopbackSignIn as U,McpRefreshLockBusyError as I,startMcpSignIn as T,waitForLoopbackSignIn as x}from"@earendil-works/pi-mcp/oauth";import K from"proper-lockfile";import{APP_NAME as k,getAgentDir as w}from"../../config.js";import{FileAuthStorageBackend as F}from"../../core/auth-storage.js";import{isClientMetadataDocumentCallback as N}from"../../core/mcp-servers.js";import{McpSignInCancelledError as ot}from"@earendil-works/pi-mcp/oauth";const O=2e4,P=25e3,h=100;function u(i){if(!i?.trim())return{};const t=JSON.parse(i);return typeof t=="object"&&t!==null&&!Array.isArray(t)?t:{}}s(u,"parseStates");function m(i){return`${JSON.stringify(i,null,2)}
|
|
2
|
+
`}s(m,"serializeStates");function p(i,t){const o=String(new URL(t));return{key:`${b(i)}|${o}`,legacyKey:o}}s(p,"storeKeys");class X{static{s(this,"McpOAuthCredentialStore")}backend;lockDir;constructor(t,o){this.backend=t??new F(f(w(),"mcp-auth.json")),this.lockDir=t?o:w()}forServer(t,o){const{key:r,legacyKey:a}=p(t,o);return{load:s(()=>this.backend.withLock(n=>{const e=u(n);return e[r]||!e[a]?{result:e[r]}:(e[r]=e[a],delete e[a],{result:e[r],next:m(e)})}),"load"),save:s(n=>this.write(e=>{e[r]=n}),"save"),withRefreshLock:s(n=>this.withRefreshLock(r,n),"withRefreshLock")}}async withRefreshLock(t,o){if(!this.lockDir)return o();A(this.lockDir,{recursive:!0,mode:448});const r=R("sha256").update(t).digest("hex").slice(0,16),a=await K.lock(f(this.lockDir,`mcp-auth-refresh-${r}`),{realpath:!1,stale:O,retries:{retries:P/h,factor:1,minTimeout:h,maxTimeout:h},onCompromised:s(()=>{},"onCompromised")}).catch(n=>{throw n instanceof Error&&"code"in n&&n.code==="ELOCKED"?new I:n});try{return await o()}finally{await a().catch(()=>{})}}tokens(t,o){const{key:r,legacyKey:a}=p(t,o),n=this.backend.withLock(e=>({result:u(e)}));return(n[r]??n[a])?.tokens}remove(t,o){const{key:r,legacyKey:a}=p(t,o);return this.backend.withLock(n=>{const e=u(n),c=r in e?r:a in e?a:void 0;return c?(delete e[c],{result:!0,next:m(e)}):{result:!1}})}write(t){this.backend.withLock(o=>{const r=u(o);return t(r),{result:void 0,next:m(r)}})}}const y={baseUrl:k==="pi"?"https://pi.dev/oauth":"https://dal.codes/oauth",listsRedirectUrl:N},S={clientName:k,clientMetadataDocuments:y};function Z(i){return v({...i,...S})}s(Z,"createMcpAuthProvider");function H(i){return i.ok?_("Signed in to the MCP server. You may now close this page."):C(i.message,i.details)}s(H,"renderCallbackPage");async function tt(i){const{serverUrl:t,store:o,settings:r,challenge:a,prompt:n,signal:e}=i,{callback:c,redirectUrl:g}=await U({serverUrl:t,store:o,settings:r,clientMetadataDocuments:y,renderPage:H});try{const d={serverUrl:t,store:o,settings:r,redirectUrl:g,challenge:a,signal:e,...S},l=await T(d);if(l.kind==="authorized")return;n.showAuthorizationUrl(new URL(l.authorizationUrl));const E=await x({callback:c,authorization:l,promptForRedirectUrl:s(L=>n.promptForRedirectUrl(L),"promptForRedirectUrl"),signal:e});await D({...d,authorization:l,response:E})}finally{await c.close()}}s(tt,"signInMcpServer");export{X as McpOAuthCredentialStore,ot as McpSignInCancelledError,Z as createMcpAuthProvider,tt as signInMcpServer};
|