dal-code 1.0.50 → 1.0.51
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 +1039 -5
- package/dist/bundle/chunks/anthropic-messages-2P3UGLIO.js +5 -0
- package/dist/bundle/chunks/anthropic.js +74 -0
- package/dist/bundle/chunks/azure-openai-responses-S4GNH2XC.js +1 -0
- package/dist/bundle/chunks/bedrock-converse-stream.js +88 -0
- package/dist/bundle/chunks/chunk-2KOJ4RNS.js +43 -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-567OJLS7.js +1 -0
- package/dist/bundle/chunks/chunk-5AGIVGSV.js +5 -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-AL7NZVPP.js +1 -0
- package/dist/bundle/chunks/chunk-ATQJO2OE.js +3 -0
- package/dist/bundle/chunks/chunk-B7NRFMLU.js +8 -0
- package/dist/bundle/chunks/chunk-BEDAM2M7.js +81 -0
- package/dist/bundle/chunks/chunk-CF5GWZHW.js +30 -0
- package/dist/bundle/chunks/chunk-CFPQOC7P.js +1 -0
- package/dist/bundle/chunks/chunk-D2WTLI2T.js +19 -0
- package/dist/bundle/chunks/chunk-EH7SFF47.js +129 -0
- package/dist/bundle/chunks/chunk-FCKLBLA4.js +1 -0
- package/dist/bundle/chunks/chunk-FFMDRXC4.js +9 -0
- package/dist/bundle/chunks/chunk-GSGE3ULF.js +15 -0
- package/dist/bundle/chunks/chunk-H5FHS6BV.js +1 -0
- package/dist/bundle/chunks/chunk-HXK5EFBE.js +1172 -0
- package/dist/bundle/chunks/chunk-IEBK4HQA.js +1 -0
- package/dist/bundle/chunks/chunk-JE6UXK35.js +30 -0
- package/dist/bundle/chunks/chunk-JXWJOIH4.js +1 -0
- package/dist/bundle/chunks/chunk-K7VBBYTT.js +1 -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-NUIR7PPD.js +25 -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-PWZRJWNP.js +17 -0
- package/dist/bundle/chunks/chunk-R44HF4S5.js +9 -0
- package/dist/bundle/chunks/chunk-R47JBGS3.js +1 -0
- package/dist/bundle/chunks/chunk-RCVVRHMF.js +9 -0
- package/dist/bundle/chunks/chunk-RDZVAGPR.js +1 -0
- package/dist/bundle/chunks/chunk-RR3ZP63P.js +56 -0
- package/dist/bundle/chunks/chunk-SE42OS3U.js +21 -0
- package/dist/bundle/chunks/chunk-TMTOQ7H7.js +1 -0
- package/dist/bundle/chunks/chunk-UTB4DTYQ.js +1 -0
- package/dist/bundle/chunks/chunk-VNHNHA4V.js +1 -0
- package/dist/bundle/chunks/chunk-XJFQKN3N.js +2 -0
- package/dist/bundle/chunks/chunk-ZG74NES2.js +1 -0
- package/dist/bundle/chunks/cli-FWMQKBFA.js +30 -0
- package/dist/bundle/chunks/cli-ZEDY5U67.js +52 -0
- package/dist/bundle/chunks/cloudflare-workers-ai-system-one-E6TEENDO.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-62LDYHXA.js +506 -0
- package/dist/bundle/chunks/github-copilot.js +1 -0
- package/dist/bundle/chunks/google-generative-ai-V5DLXTF7.js +1 -0
- package/dist/bundle/chunks/google-vertex-K3KYGGLI.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-JCTIEHTL.js +21 -0
- package/dist/bundle/chunks/mcp-VF7EY5WC.js +10 -0
- package/dist/bundle/chunks/meta.js +1 -0
- package/dist/bundle/chunks/mistral-conversations-LVBXTF6R.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-PONBADQP.js +419 -0
- package/dist/bundle/chunks/openai-chatgpt.js +74 -0
- package/dist/bundle/chunks/openai-codex-responses-WBZKNYLX.js +9 -0
- package/dist/bundle/chunks/openai-codex.js +74 -0
- package/dist/bundle/chunks/openai-completions-HMHQRGX4.js +6 -0
- package/dist/bundle/chunks/openai-decisions-R7OFRKLL.js +4 -0
- package/dist/bundle/chunks/openai-responses-BHXRQFCI.js +3 -0
- package/dist/bundle/chunks/openrouter-images-BIMNIXQZ.js +1 -0
- package/dist/bundle/chunks/openrouter.js +74 -0
- package/dist/bundle/chunks/pi-messages-X5YTLXQJ.js +7 -0
- package/dist/bundle/chunks/radius.js +74 -0
- package/dist/bundle/chunks/review-WCGIBVLM.js +80 -0
- package/dist/bundle/chunks/rewind-2OYLDDHH.js +8 -0
- package/dist/bundle/chunks/router-7E5LU7US.js +3 -0
- package/dist/bundle/chunks/runtime-5PTUOEM2.js +1 -0
- package/dist/bundle/chunks/sdk-ZUFIGPSS.js +1 -0
- package/dist/bundle/chunks/src-QKGKDFSU.js +3 -0
- package/dist/bundle/chunks/sync-LOX6TIM6.js +4 -0
- package/dist/bundle/chunks/typesafe-system-one-KOIOG3HP.js +1 -0
- package/dist/bundle/chunks/usage-2EVEFGNI.js +1 -0
- package/dist/bundle/chunks/virtual-modules-MYMONT3Y.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/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 +3 -2
- package/dist/node_modules/@dalcode/dal-learn/src/index.js +16 -16
- package/dist/node_modules/@dalcode/dal-learn/src/lesson-events.js +1 -0
- 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 +3 -2
- 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-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
|
@@ -0,0 +1,506 @@
|
|
|
1
|
+
var ve=Object.defineProperty;var s=(e,t)=>ve(e,"name",{value:t,configurable:!0});import{createRequire as Ee}from"node:module";const Et=Ee(import.meta.url);import{Bm25Ranker as Oe,CODEMODE_DOCS_PATH as Q,CODEMODE_STORE_ENTRY_TYPE as Z,DEFAULT_TOOL_SEARCH_LIMIT as ke,combineUsage as Te,createToolSearchDocument as je,getCodemodeCallableTools as xe,parseCodemodeSource as Se,renderToolSample as $e,toCodemodeDeclaration as Ae,toCodemodeIdentifier as S,writeOutputFile as ee}from"./chunk-RR3ZP63P.js";import"./chunk-3YGHTGYM.js";import{formatSize as Ne,sliceHead as te,sliceTail as Ce}from"./chunk-SE42OS3U.js";import"./chunk-EH7SFF47.js";import"./chunk-6QGV3IWD.js";import{getCodemodeWorkerSpecifier as Me,getQuickJSWasmPath as Ie}from"./chunk-R47JBGS3.js";import"./chunk-NUIR7PPD.js";import"./chunk-5AGIVGSV.js";import"./chunk-JXWJOIH4.js";function Pe(e){if(typeof e!="object"||e===null)return!1;let t=e.type;return t==="call"||t==="output"||t==="done"||t==="crash"||t==="started"||t==="idle"}s(Pe,"isWorkerToHostMessage");var Re=3e5,_e=/^[A-Za-z_$][A-Za-z0-9_$]*$/,Le=new Set(["tools","ALL_TOOLS","console","text","image","exit","globalThis","store","load"]);function N(e){return e instanceof Error?e.message:String(e)}s(N,"errorMessage");function re(e){let t={};for(let[o,r]of Object.entries(e??{})){let n=JSON.stringify(r);n!==void 0&&(t[o]=n)}return t}s(re,"serializeStore");var j=class extends Error{static{s(this,"BridgeError")}};function M(e,t){try{return JSON.parse(e)}catch{throw new j(`${t} is not valid JSON`)}}s(M,"parseBridgeJson");function Je(e){let t=M(e,"store writes");if(!Array.isArray(t))throw new j("store writes are not an array");let o={set:{},delete:[]};for(let r of t){if(!Array.isArray(r)||typeof r[0]!="string"||(r.length===2?typeof r[1]!="string":r.length!==1))throw new j("store writes contain a malformed entry");let[n,a]=r;a===void 0?o.delete.push(n):o.set[n]=M(a,`store value for ${JSON.stringify(n)}`)}return o}s(Je,"parseStoreWrites");function De(e){let t=M(e,"script error");if(typeof t!="object"||t===null)throw new j("script error is not an object");let{name:o,message:r,stack:n}=t;if(typeof r!="string"||o!==void 0&&typeof o!="string"||n!==void 0&&typeof n!="string")throw new j("script error is malformed");return{kind:"script",name:o,message:r,stack:n}}s(De,"parseScriptError");function oe(e){let t=new Set,o=new Set;for(let r of e){let n=r.name.split(".");if(n.length>2||!n.every(a=>_e.test(a))||Le.has(n[0]))throw new Error(`Invalid global name "${r.name}"`);if(t.has(r.name))throw new Error(`Global "${r.name}" is already registered`);n.length===2&&o.add(n[0]),t.add(r.name)}for(let r of o)if(t.has(r))throw new Error(`Global "${r}" conflicts with the namespace "${r}"`)}s(oe,"checkGlobals");var ne=class{static{s(this,"Execution")}promise;resolveResult;channel;unsent=[];executors;control;delivered=new Set;signal;timer;output=[];calls=[];pending=new Map;finished=!1;constructor(e){if(this.promise=new Promise(r=>{this.resolveResult=r}),this.executors=e.executors,this.control=e.control,this.signal=e.signal,Number.isFinite(e.timeoutMs)&&(this.timer=setTimeout(()=>{this.finish({kind:"timeout",message:`Execution timed out after ${e.timeoutMs} ms`})},e.timeoutMs)),e.signal&&(e.signal.aborted?this.onAbort():e.signal.addEventListener("abort",this.onAbort,{once:!0})),this.finished)return;let t={code:e.code,tools:e.tools.map(r=>({name:r.name,jsName:r.jsName??S(r.name),description:r.description??""})),globals:e.globals.map(r=>({name:r.name,spread:r.spread===!0})),memoryLimitBytes:e.memoryLimitBytes,store:e.store,...e.deterministic?{deterministic:e.deterministic}:{}},o={message:s(r=>this.receive(r),"message"),failure:s(r=>this.finish(r),"failure")};new Promise(r=>r(e.launch(t,o))).then(r=>{if(this.finished){r.stop().catch(()=>{});return}this.channel=r;for(let n of this.unsent.splice(0))r.post(n)},r=>{this.finish({kind:"sandbox",message:N(r)})})}deliver(e,t,o,r){if(this.finished)return;if(!Number.isFinite(t))throw new Error(`The clock value of result ${e} is not a finite number`);if(!Number.isInteger(e)||e<1||this.delivered.has(e))throw new Error(`Result number ${e} is not a positive integer used once`);let n=this.pending.get(o);if(n===void 0)throw new Error(`Call ${o} is not waiting for a result`);if(!r.ok&&r.properties!==void 0){let{properties:c}=r;if(typeof c!="object"||c===null||Array.isArray(c))throw new Error(`The properties of result ${e} are not an object`)}let a=r.ok?r.value===void 0?void 0:JSON.stringify(r.value):r.message,l=!r.ok&&r.properties!==void 0?JSON.stringify(r.properties):void 0;this.delivered.add(e),this.pending.delete(o),n.record&&(n.record.status=r.ok?"ok":"error",n.record.durationMs=performance.now()-n.startedAt),this.post({type:"result",id:o,ok:r.ok,payload:a,seq:e,now:t,...l===void 0?{}:{properties:l}})}abort(e){return this.finish({kind:"aborted",message:e}),this.promise}onAbort=s(()=>{let e=this.signal?.reason;this.finish({kind:"aborted",message:e instanceof Error?e.message:"Execution aborted"})},"onAbort");post(e){this.channel?this.channel.post(e):this.unsent.push(e)}receive(e){try{this.handleMessage(e)}catch(t){this.finish({kind:"sandbox",message:t instanceof j?`Sandbox bridge broken: ${t.message}. The script may have modified built-ins such as a prototype's toJSON.`:`Sandbox host failed: ${N(t)}`})}}handleMessage(e){if(!this.finished){if(!Pe(e))throw new j("unknown message from the worker");switch(e.type){case"output":this.output.push(e.item);break;case"call":if(this.pending.has(e.id))throw new j(`duplicate call id ${e.id}`);this.control?this.forwardCall(e,this.control):this.handleCall(e);break;case"started":this.control?.onStarted?.(e.fingerprint);break;case"idle":this.control?.onIdle?.(e.seq,e.issued);break;case"done":this.handleDone(e);break;case"crash":this.finish({kind:"sandbox",message:e.message});break}}}handleDone(e){if(!e.ok){this.finish(De(e.error),void 0,void 0,e.during);return}let t=e.value===void 0?void 0:M(e.value,"return value");this.finish(void 0,t,Je(e.writes),e.during)}forwardCall(e,t){let{id:o,name:r,target:n}=e,a=e.args===void 0?void 0:M(e.args,"call arguments"),l=n==="tool"?{name:r,status:"cancelled",durationMs:0}:void 0;l&&this.calls.push(l),this.pending.set(o,{record:l,startedAt:performance.now(),controller:new AbortController}),t.onCall({id:o,target:n,name:r,args:a})}async handleCall(e){let{id:t,name:o}=e,r=e.target==="tool",n=r?{name:o,status:"cancelled",durationMs:0}:void 0;n&&this.calls.push(n);let a={record:n,startedAt:performance.now(),controller:new AbortController};this.pending.set(t,a);let l,c;try{let u=(r?this.executors.tools:this.executors.globals).get(o);if(!u)throw new Error(`Unknown ${r?"tool":"global"} "${o}"`);let i=e.args===void 0?void 0:JSON.parse(e.args),d=await u.execute(i,{signal:a.controller.signal});c={type:"result",id:t,ok:!0,payload:d===void 0?void 0:JSON.stringify(d)},l="ok"}catch(u){c={type:"result",id:t,ok:!1,payload:N(u)},l="error"}this.pending.delete(t)&&(n&&(n.status=l,n.durationMs=performance.now()-a.startedAt),this.post(c))}finish(e,t,o,r){if(this.finished)return;this.finished=!0,clearTimeout(this.timer),this.signal?.removeEventListener("abort",this.onAbort);let n=performance.now();for(let c of this.pending.values())c.record&&(c.record.durationMs=n-c.startedAt),c.controller.abort();this.pending.clear(),this.unsent=[];let a=r===void 0?{}:{during:{seq:r.seq,issued:r.issued}},l=e?{ok:!1,error:e,output:this.output,calls:this.calls,...a}:{ok:!0,value:t,output:this.output,calls:this.calls,storeWrites:o??{set:{},delete:[]},...a};if(!this.channel){this.resolveResult(l);return}this.channel.stop().catch(()=>{}).then(()=>this.resolveResult(l))}},We=class{static{s(this,"CodemodeSandboxBase")}toolsByName=new Map;globalsByName=new Map;timeoutMs;memoryLimitBytes;launch;running=new Set;closed=!1;constructor(e,t){this.timeoutMs=e.timeoutMs??Re,this.memoryLimitBytes=e.memoryLimitBytes,this.launch=t;for(let o of e.tools??[])this.registerTool(o);oe(e.globals??[]);for(let o of e.globals??[])this.globalsByName.set(o.name,o)}registerTool(e){if(this.toolsByName.has(e.name))throw new Error(`Tool "${e.name}" is already registered`);this.toolsByName.set(e.name,e)}unregisterTool(e){return this.toolsByName.delete(e)}get tools(){return[...this.toolsByName.values()]}get globals(){return[...this.globalsByName.values()]}execute(e,t={}){if(this.closed)return Promise.reject(new Error("Sandbox is closed"));let o=new Map(this.toolsByName),r=new ne({code:e,tools:[...o.values()],globals:[...this.globalsByName.values()],executors:{tools:o,globals:this.globalsByName},timeoutMs:t.timeoutMs??this.timeoutMs,signal:t.signal,memoryLimitBytes:this.memoryLimitBytes,store:re(t.store),launch:this.launch});return this.running.add(r),r.promise.finally(()=>this.running.delete(r))}start(e,t){if(this.closed)throw new Error("Sandbox is closed");if(!Number.isFinite(t.startedAt)||t.startedAt<0)throw new Error("startedAt must be a non-negative number of milliseconds since the epoch");if(!Number.isInteger(t.seed)||t.seed<0||t.seed>4294967295)throw new Error("seed must be a 32-bit unsigned integer");let o=t.tools??[];if(new Set(o.map(l=>l.name)).size!==o.length)throw new Error("Tool names must be unique");let r=o.map(l=>l.jsName??S(l.name));if(new Set(r).size!==o.length)throw new Error("Tool script names must be unique");let n=t.globals??[];oe(n);let a=new ne({code:e,tools:o,globals:n,executors:{tools:new Map,globals:new Map},timeoutMs:t.timeoutMs??Number.POSITIVE_INFINITY,signal:t.signal,memoryLimitBytes:this.memoryLimitBytes,store:re(t.store),deterministic:{startedAt:t.startedAt,seed:t.seed},control:{onStarted:t.onStarted,onCall:t.onCall,onIdle:t.onIdle},launch:this.launch});return this.running.add(a),{result:a.promise.finally(()=>this.running.delete(a)),deliver:s((l,c,u,i)=>a.deliver(l,c,u,i),"deliver"),get finished(){return a.finished}}}async close(){this.closed=!0,await Promise.all([...this.running].map(e=>e.abort("Sandbox closed")))}};import{Worker as Be}from"node:worker_threads";import{readFile as Ue}from"node:fs/promises";import{createRequire as ze}from"node:module";var U=new Map;function se(e){let t=e??ze(import.meta.url).resolve("quickjs-wasi/quickjs.wasm"),o=U.get(t);if(!o){let{WebAssembly:r}=globalThis;o=Ue(t).then(n=>r.compile(n)).catch(n=>{throw U.delete(t),n}),U.set(t,o)}return o}s(se,"loadQuickJSWasm");function qe(){return new URL(import.meta.url.endsWith(".ts")?"./worker.ts":"./worker.js",import.meta.url)}s(qe,"defaultWorkerUrl");function Ge(e){return async(t,o)=>{let r;try{r=await(e.wasm??se())}catch(i){throw new Error(`Failed to load QuickJS: ${N(i)}`)}let n=new SharedArrayBuffer(4),a={...t,wasm:r,interrupt:n},l=e.acquireWorker?.(),c;try{c=new Be(e.workerUrl??qe(),{workerData:a})}catch(i){throw l?.(),new Error(`Failed to start worker: ${N(i)}`)}l&&c.once("exit",l),c.on("message",i=>{typeof i=="object"&&i!==null&&("watch:import"in i||"watch:require"in i)||o.message(i)}),c.on("error",i=>{o.failure({kind:"sandbox",name:i instanceof Error?i.name:void 0,message:N(i)})}),c.on("exit",i=>{o.failure({kind:"sandbox",message:`Worker exited with code ${i} before the script settled`})});let u=s(async()=>{Atomics.store(new Int32Array(n),0,1),c.terminate().catch(()=>{}),c.unref()},"stop");try{e.onWorkerStarted?.(new Promise(i=>c.once("exit",()=>i())))}catch(i){throw u(),i}return{post:s(i=>c.postMessage(i),"post"),stop:u}}}s(Ge,"workerLauncher");var Fe=class extends We{static{s(this,"CodemodeSandbox")}constructor(e={}){super(e,Ge(e))}},Pt=new TextDecoder,Rt=512*1024,_t=new TextDecoder,Lt=new TextEncoder,J='image expects a non-empty image URL string, an object with image_url, or an image block { type: "image", data, mimeType }',He=`(function (bridge, toolsJson, globalsJson, storeJson) {
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
// Freeze every object reachable from the built-in globals, plus the intrinsics that are only
|
|
5
|
+
// reachable from instances (iterator and generator prototypes, %TypedArray%).
|
|
6
|
+
//
|
|
7
|
+
// Freezing alone breaks ordinary code through the "override mistake": a data property that is
|
|
8
|
+
// read-only on a prototype cannot be assigned on an instance either, so
|
|
9
|
+
// this.name = "MyError" in an Error subclass would throw. Commonly overridden properties
|
|
10
|
+
// become accessors whose setter defines an own property on the instance instead.
|
|
11
|
+
(function lockdown() {
|
|
12
|
+
const OVERRIDABLE = new Set(["constructor", "name", "message", "toString", "toLocaleString", "valueOf", "toJSON"]);
|
|
13
|
+
const seen = new Set([globalThis]);
|
|
14
|
+
const queue = [];
|
|
15
|
+
const add = (value) => {
|
|
16
|
+
if ((typeof value === "object" && value !== null) || typeof value === "function") {
|
|
17
|
+
if (!seen.has(value)) {
|
|
18
|
+
seen.add(value);
|
|
19
|
+
queue.push(value);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// Accessors from an object literal have no own prototype object, unlike function expressions,
|
|
25
|
+
// whose prototype.constructor would be converted again without end.
|
|
26
|
+
function allowOverride(object, key, value, enumerable) {
|
|
27
|
+
const { get, set } = Object.getOwnPropertyDescriptor(
|
|
28
|
+
{
|
|
29
|
+
get accessor() {
|
|
30
|
+
return value;
|
|
31
|
+
},
|
|
32
|
+
set accessor(next) {
|
|
33
|
+
if (this === object) {
|
|
34
|
+
throw new TypeError("Cannot assign to read only property '" + String(key) + "' of a built-in");
|
|
35
|
+
}
|
|
36
|
+
if ((typeof this !== "object" || this === null) && typeof this !== "function") return;
|
|
37
|
+
Object.defineProperty(this, key, { value: next, writable: true, enumerable: true, configurable: true });
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
"accessor",
|
|
41
|
+
);
|
|
42
|
+
Object.defineProperty(object, key, { get, set, enumerable, configurable: false });
|
|
43
|
+
add(get);
|
|
44
|
+
add(set);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
for (const key of Reflect.ownKeys(globalThis)) {
|
|
48
|
+
const descriptor = Object.getOwnPropertyDescriptor(globalThis, key);
|
|
49
|
+
add(descriptor.value);
|
|
50
|
+
add(descriptor.get);
|
|
51
|
+
add(descriptor.set);
|
|
52
|
+
if ("value" in descriptor && descriptor.configurable) {
|
|
53
|
+
Object.defineProperty(globalThis, key, { writable: false, configurable: false });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
add(Object.getPrototypeOf(function* () {}));
|
|
57
|
+
add(Object.getPrototypeOf(async function () {}));
|
|
58
|
+
add(Object.getPrototypeOf(async function* () {}));
|
|
59
|
+
add(Object.getPrototypeOf(Int8Array));
|
|
60
|
+
add(Object.getPrototypeOf([][Symbol.iterator]()));
|
|
61
|
+
add(Object.getPrototypeOf(new Map()[Symbol.iterator]()));
|
|
62
|
+
add(Object.getPrototypeOf(new Set()[Symbol.iterator]()));
|
|
63
|
+
add(Object.getPrototypeOf(""[Symbol.iterator]()));
|
|
64
|
+
add(Object.getPrototypeOf(/a/[Symbol.matchAll]("")));
|
|
65
|
+
if (typeof Iterator === "function") {
|
|
66
|
+
if (typeof Iterator.prototype.map === "function") add(Object.getPrototypeOf([].values().map((x) => x)));
|
|
67
|
+
if (typeof Iterator.from === "function") add(Object.getPrototypeOf(Iterator.from({ next() {} })));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
while (queue.length > 0) {
|
|
71
|
+
const object = queue.pop();
|
|
72
|
+
add(Object.getPrototypeOf(object));
|
|
73
|
+
const descriptors = Object.getOwnPropertyDescriptors(object);
|
|
74
|
+
for (const key of Reflect.ownKeys(descriptors)) {
|
|
75
|
+
const descriptor = descriptors[key];
|
|
76
|
+
if ("value" in descriptor) {
|
|
77
|
+
add(descriptor.value);
|
|
78
|
+
if (
|
|
79
|
+
descriptor.writable &&
|
|
80
|
+
descriptor.configurable &&
|
|
81
|
+
(object === Object.prototype || OVERRIDABLE.has(key))
|
|
82
|
+
) {
|
|
83
|
+
allowOverride(object, key, descriptor.value, descriptor.enumerable);
|
|
84
|
+
}
|
|
85
|
+
} else {
|
|
86
|
+
add(descriptor.get);
|
|
87
|
+
add(descriptor.set);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
Object.freeze(object);
|
|
91
|
+
}
|
|
92
|
+
})();
|
|
93
|
+
const stringify = JSON.stringify;
|
|
94
|
+
const parse = JSON.parse;
|
|
95
|
+
const promiseThen = Promise.prototype.then;
|
|
96
|
+
const ErrorCtor = Error;
|
|
97
|
+
const TypeErrorCtor = TypeError;
|
|
98
|
+
const RangeErrorCtor = RangeError;
|
|
99
|
+
const pending = new Map();
|
|
100
|
+
let nextId = 1;
|
|
101
|
+
let finished = false;
|
|
102
|
+
// Thrown by exit() to unwind the script after it already reported success.
|
|
103
|
+
const EXIT = Object.freeze({});
|
|
104
|
+
|
|
105
|
+
function done(ok, payload, writes) {
|
|
106
|
+
if (finished) return;
|
|
107
|
+
finished = true;
|
|
108
|
+
bridge("done", ok, payload, writes);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function serialize(value) {
|
|
112
|
+
return value === undefined ? undefined : stringify(value);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// QuickJS stacks list frames only. Prefix "Name: message" like V8 so the
|
|
116
|
+
// text reads the same as a Node error, and drop this prelude's frames.
|
|
117
|
+
function errorText(error) {
|
|
118
|
+
const head = error.message ? error.name + ": " + error.message : String(error.name);
|
|
119
|
+
const frames =
|
|
120
|
+
typeof error.stack === "string"
|
|
121
|
+
? error.stack.split("\\n").filter((line) => line.trim() && !line.includes("codemode-prelude.js"))
|
|
122
|
+
: [];
|
|
123
|
+
return [head, ...frames].join("\\n");
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function format(value) {
|
|
127
|
+
if (typeof value === "string") return value;
|
|
128
|
+
if (value instanceof ErrorCtor) return errorText(value);
|
|
129
|
+
// JSON.stringify turns NaN and Infinity into "null".
|
|
130
|
+
if (typeof value === "number") return String(value);
|
|
131
|
+
try {
|
|
132
|
+
const json = stringify(value);
|
|
133
|
+
return json === undefined ? String(value) : json;
|
|
134
|
+
} catch {
|
|
135
|
+
return String(value);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// The host requires string fields. A script can set an error's name or message to anything, so
|
|
140
|
+
// they are coerced, and a value whose coercion throws gets a placeholder.
|
|
141
|
+
function describeError(error) {
|
|
142
|
+
try {
|
|
143
|
+
if (error instanceof ErrorCtor) {
|
|
144
|
+
return stringify({ name: String(error.name), message: String(error.message), stack: errorText(error) });
|
|
145
|
+
}
|
|
146
|
+
return stringify({ message: String(format(error)) });
|
|
147
|
+
} catch {
|
|
148
|
+
return stringify({ message: "The script threw a value that cannot be described" });
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function caller(kind, name, spread) {
|
|
153
|
+
return (...args) =>
|
|
154
|
+
new Promise((resolve, reject) => {
|
|
155
|
+
let json;
|
|
156
|
+
try {
|
|
157
|
+
json = serialize(spread ? args : args[0]);
|
|
158
|
+
} catch (error) {
|
|
159
|
+
reject(error);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const id = nextId++;
|
|
163
|
+
pending.set(id, { resolve, reject });
|
|
164
|
+
bridge(kind, id, name, json);
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const tools = Object.create(null);
|
|
169
|
+
const allTools = [];
|
|
170
|
+
for (const { name, jsName, description } of parse(toolsJson)) {
|
|
171
|
+
const fn = caller("call", name);
|
|
172
|
+
// The first tool wins when two names normalize to the same identifier.
|
|
173
|
+
if (!(jsName in tools)) {
|
|
174
|
+
tools[jsName] = fn;
|
|
175
|
+
allTools.push(Object.freeze({ name: jsName, description }));
|
|
176
|
+
}
|
|
177
|
+
if (!(name in tools)) tools[name] = fn;
|
|
178
|
+
}
|
|
179
|
+
Object.freeze(tools);
|
|
180
|
+
Object.freeze(allTools);
|
|
181
|
+
|
|
182
|
+
// Reading a member that does not exist throws an error that names the close matches, instead of
|
|
183
|
+
// a later "not a function". \`in\` checks still work.
|
|
184
|
+
const comparable = (name) => name.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
185
|
+
function guard(target, label, names, hint) {
|
|
186
|
+
return new Proxy(target, {
|
|
187
|
+
get(object, property, receiver) {
|
|
188
|
+
if (typeof property !== "string" || property in object || property in Object.prototype || property === "then" || property === "toJSON") {
|
|
189
|
+
return Reflect.get(object, property, receiver);
|
|
190
|
+
}
|
|
191
|
+
const wanted = comparable(property);
|
|
192
|
+
const exact = names.filter((name) => comparable(name) === wanted);
|
|
193
|
+
const close = exact.length > 0 ? exact : names.filter((name) => wanted && (comparable(name).includes(wanted) || wanted.includes(comparable(name))));
|
|
194
|
+
let message = label + "." + property + " does not exist.";
|
|
195
|
+
if (close.length > 0) message += " Did you mean " + close.slice(0, 5).map((name) => label + "." + name).join(", ") + "?";
|
|
196
|
+
else if (names.length <= 20) message += " Available: " + names.join(", ") + ".";
|
|
197
|
+
if (hint) message += " " + hint;
|
|
198
|
+
message += ' Check for a member with "' + property + '" in ' + label + ".";
|
|
199
|
+
throw new TypeErrorCtor(message);
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
const toolsProxy = guard(
|
|
204
|
+
tools,
|
|
205
|
+
"tools",
|
|
206
|
+
allTools.map((tool) => tool.name),
|
|
207
|
+
"ALL_TOOLS lists every tool; searchTools(query) finds tools by topic.",
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
const namespaces = new Map();
|
|
211
|
+
for (const { name, spread } of parse(globalsJson)) {
|
|
212
|
+
const fn = caller("global", name, spread);
|
|
213
|
+
const dot = name.indexOf(".");
|
|
214
|
+
if (dot === -1) {
|
|
215
|
+
Object.defineProperty(globalThis, name, { value: fn, enumerable: true });
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
const namespace = name.slice(0, dot);
|
|
219
|
+
if (!namespaces.has(namespace)) namespaces.set(namespace, Object.create(null));
|
|
220
|
+
namespaces.get(namespace)[name.slice(dot + 1)] = fn;
|
|
221
|
+
}
|
|
222
|
+
for (const [namespace, members] of namespaces) {
|
|
223
|
+
Object.freeze(members);
|
|
224
|
+
const value = guard(members, namespace, Object.keys(members));
|
|
225
|
+
Object.defineProperty(globalThis, namespace, { value, enumerable: true });
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// key -> JSON text. Sizes count key and JSON characters.
|
|
229
|
+
const stored = new Map(Object.entries(parse(storeJson)));
|
|
230
|
+
const writes = new Map();
|
|
231
|
+
let storedChars = 0;
|
|
232
|
+
for (const [key, json] of stored) storedChars += key.length + json.length;
|
|
233
|
+
|
|
234
|
+
const STORE_HINT =
|
|
235
|
+
"store() is for small state such as IDs or summaries. Show images with image(), keep large data in variables, or write it to a file with a tool.";
|
|
236
|
+
|
|
237
|
+
function checkKey(name, key) {
|
|
238
|
+
if (typeof key !== "string") throw new TypeError(name + "() key must be a string");
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function store(key, value) {
|
|
242
|
+
checkKey("store", key);
|
|
243
|
+
const previous = stored.has(key) ? key.length + stored.get(key).length : 0;
|
|
244
|
+
if (value === undefined) {
|
|
245
|
+
stored.delete(key);
|
|
246
|
+
storedChars -= previous;
|
|
247
|
+
writes.set(key, undefined);
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
let json;
|
|
251
|
+
try {
|
|
252
|
+
json = stringify(value);
|
|
253
|
+
} catch (error) {
|
|
254
|
+
throw new TypeError("store(" + stringify(key) + ") value is not JSON-serializable: " + format(error));
|
|
255
|
+
}
|
|
256
|
+
if (json === undefined) {
|
|
257
|
+
throw new TypeError("store(" + stringify(key) + ") value is not JSON-serializable");
|
|
258
|
+
}
|
|
259
|
+
if (json.length > 262144) {
|
|
260
|
+
throw new RangeError(
|
|
261
|
+
"store(" + stringify(key) + ") value has " + json.length + " characters of JSON, more than the limit of 262144. " +
|
|
262
|
+
STORE_HINT,
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
const next = storedChars - previous + key.length + json.length;
|
|
266
|
+
if (next > 1048576) {
|
|
267
|
+
throw new RangeError(
|
|
268
|
+
"store is full: stored values would exceed 1048576 characters of JSON. Delete keys with store(key, undefined). " +
|
|
269
|
+
STORE_HINT,
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
stored.set(key, json);
|
|
273
|
+
storedChars = next;
|
|
274
|
+
writes.set(key, json);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function load(key) {
|
|
278
|
+
checkKey("load", key);
|
|
279
|
+
const json = stored.get(key);
|
|
280
|
+
return json === undefined ? undefined : parse(json);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function serializeWrites() {
|
|
284
|
+
const entries = [];
|
|
285
|
+
for (const [key, json] of writes) entries.push(json === undefined ? [key] : [key, json]);
|
|
286
|
+
return stringify(entries);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
Object.defineProperty(globalThis, "store", { value: store, enumerable: true });
|
|
290
|
+
Object.defineProperty(globalThis, "load", { value: load, enumerable: true });
|
|
291
|
+
|
|
292
|
+
let outputChars = 0;
|
|
293
|
+
let outputItems = 0;
|
|
294
|
+
|
|
295
|
+
// Past the output limits the script fails: done() reports the error, so catching it does not
|
|
296
|
+
// resume output, and the host ends the script.
|
|
297
|
+
function output(kind, data, mimeType) {
|
|
298
|
+
if (finished) return;
|
|
299
|
+
outputChars += data.length;
|
|
300
|
+
outputItems++;
|
|
301
|
+
if (outputChars > 16777216 || outputItems > 100000) {
|
|
302
|
+
const error = new RangeErrorCtor(
|
|
303
|
+
"script output exceeded the limit of 16777216 characters or 100000 text(), image(), and console calls. " +
|
|
304
|
+
"Print a summary instead, or write large data to a file with a tool.",
|
|
305
|
+
);
|
|
306
|
+
done(false, describeError(error));
|
|
307
|
+
throw error;
|
|
308
|
+
}
|
|
309
|
+
bridge("output", kind, data, mimeType);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// Primitives become their string form, everything else JSON.
|
|
313
|
+
function outputText(value) {
|
|
314
|
+
if (value === undefined || value === null || typeof value !== "object" && typeof value !== "function") {
|
|
315
|
+
return String(value);
|
|
316
|
+
}
|
|
317
|
+
const json = stringify(value);
|
|
318
|
+
return json === undefined ? String(value) : json;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function text(value) {
|
|
322
|
+
let rendered;
|
|
323
|
+
try {
|
|
324
|
+
rendered = outputText(value);
|
|
325
|
+
} catch (error) {
|
|
326
|
+
throw new TypeErrorCtor(error instanceof ErrorCtor ? error.message : String(error));
|
|
327
|
+
}
|
|
328
|
+
output("text", rendered);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function imageUrl(value) {
|
|
332
|
+
if (typeof value === "string") return value;
|
|
333
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
334
|
+
throw new TypeErrorCtor(${JSON.stringify(J)});
|
|
335
|
+
}
|
|
336
|
+
if (value.image_url !== undefined) {
|
|
337
|
+
if (typeof value.image_url !== "string") throw new TypeErrorCtor(${JSON.stringify(J)});
|
|
338
|
+
return value.image_url;
|
|
339
|
+
}
|
|
340
|
+
if (typeof value.type !== "string") throw new TypeErrorCtor(${JSON.stringify(J)});
|
|
341
|
+
if (value.type !== "image") {
|
|
342
|
+
throw new TypeErrorCtor('image only accepts image blocks, got "' + value.type + '"');
|
|
343
|
+
}
|
|
344
|
+
if (typeof value.data !== "string" || value.data === "") throw new TypeErrorCtor("image expected image block data");
|
|
345
|
+
if (value.data.toLowerCase().startsWith("data:")) return value.data;
|
|
346
|
+
return "data:;base64," + value.data;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// Base64 of the signatures of the formats providers accept inline (PNG, JPEG except
|
|
350
|
+
// JPEG-LS, GIF, "RIFF....WEBP"). Signatures start at byte 0, so their encodings are prefixes.
|
|
351
|
+
const IMAGE_SIGNATURES = [
|
|
352
|
+
["image/png", /^iVBORw0KGg/],
|
|
353
|
+
["image/jpeg", /^[/]9j[/](?!9)/],
|
|
354
|
+
["image/gif", /^R0lGOD[dl]h/],
|
|
355
|
+
["image/webp", /^UklG.{8}RUJQ/],
|
|
356
|
+
];
|
|
357
|
+
|
|
358
|
+
function image(value) {
|
|
359
|
+
const url = imageUrl(value);
|
|
360
|
+
if (url === "") throw new TypeErrorCtor(${JSON.stringify(J)});
|
|
361
|
+
const colon = url.indexOf(":");
|
|
362
|
+
const scheme = colon === -1 ? "" : url.slice(0, colon).toLowerCase();
|
|
363
|
+
if (scheme === "http" || scheme === "https") {
|
|
364
|
+
throw new TypeErrorCtor("remote image URLs are not supported in tool outputs. Pass a base64 data URI instead");
|
|
365
|
+
}
|
|
366
|
+
const comma = url.indexOf(",");
|
|
367
|
+
const header = comma === -1 ? [] : url.slice(colon + 1, comma).split(";");
|
|
368
|
+
if (scheme !== "data" || comma === -1 || header.slice(1).every((part) => part.toLowerCase() !== "base64")) {
|
|
369
|
+
throw new TypeErrorCtor("invalid image output. Pass a base64 data URI instead");
|
|
370
|
+
}
|
|
371
|
+
// Providers reject the whole request on a bad image, and a persisted image block would be
|
|
372
|
+
// resent on every later turn. Line breaks from wrapped base64 are dropped. The declared type
|
|
373
|
+
// is ignored in favor of the detected one, as providers also reject mismatches.
|
|
374
|
+
const data = url.slice(comma + 1).replace(/\\s+/g, "");
|
|
375
|
+
if (data.length % 4 !== 0 || !/^[A-Za-z0-9+/]+={0,2}$/.test(data)) {
|
|
376
|
+
throw new TypeErrorCtor("invalid image output. The image data is not valid base64 (truncated or corrupted?)");
|
|
377
|
+
}
|
|
378
|
+
const head = data.slice(0, 16);
|
|
379
|
+
const signature = IMAGE_SIGNATURES.find(([, pattern]) => pattern.test(head));
|
|
380
|
+
if (!signature) {
|
|
381
|
+
throw new TypeErrorCtor("invalid image output. The image data is not a PNG, JPEG, GIF, or WebP image");
|
|
382
|
+
}
|
|
383
|
+
output("image", data, signature[0]);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
function exit() {
|
|
387
|
+
let writesJson;
|
|
388
|
+
try {
|
|
389
|
+
writesJson = serializeWrites();
|
|
390
|
+
} catch (error) {
|
|
391
|
+
done(false, describeError(error));
|
|
392
|
+
throw EXIT;
|
|
393
|
+
}
|
|
394
|
+
done(true, undefined, writesJson);
|
|
395
|
+
throw EXIT;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
const console = {};
|
|
399
|
+
for (const level of ["log", "info", "warn", "error", "debug"]) {
|
|
400
|
+
console[level] = (...args) => {
|
|
401
|
+
output("console", args.map(format).join(" "));
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
Object.freeze(console);
|
|
405
|
+
|
|
406
|
+
Object.defineProperty(globalThis, "tools", { value: toolsProxy, enumerable: true });
|
|
407
|
+
Object.defineProperty(globalThis, "ALL_TOOLS", { value: allTools, enumerable: true });
|
|
408
|
+
Object.defineProperty(globalThis, "console", { value: console, enumerable: true });
|
|
409
|
+
Object.defineProperty(globalThis, "text", { value: text, enumerable: true });
|
|
410
|
+
Object.defineProperty(globalThis, "image", { value: image, enumerable: true });
|
|
411
|
+
Object.defineProperty(globalThis, "exit", { value: exit, enumerable: true });
|
|
412
|
+
|
|
413
|
+
return {
|
|
414
|
+
settle(id, ok, payload, propertiesJson) {
|
|
415
|
+
const entry = pending.get(id);
|
|
416
|
+
if (!entry) return;
|
|
417
|
+
pending.delete(id);
|
|
418
|
+
if (!ok) {
|
|
419
|
+
const error = new ErrorCtor(payload);
|
|
420
|
+
if (propertiesJson !== undefined) {
|
|
421
|
+
const properties = parse(propertiesJson);
|
|
422
|
+
for (const key of Object.keys(properties)) {
|
|
423
|
+
if (key === "name" || key === "message" || key === "stack") continue;
|
|
424
|
+
Object.defineProperty(error, key, { value: properties[key], writable: true, enumerable: true, configurable: true });
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
entry.reject(error);
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
let value;
|
|
431
|
+
try {
|
|
432
|
+
value = payload === undefined ? undefined : parse(payload);
|
|
433
|
+
} catch (error) {
|
|
434
|
+
entry.reject(error);
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
entry.resolve(value);
|
|
438
|
+
},
|
|
439
|
+
run(fn) {
|
|
440
|
+
let promise;
|
|
441
|
+
try {
|
|
442
|
+
promise = fn(toolsProxy, console);
|
|
443
|
+
} catch (error) {
|
|
444
|
+
done(false, describeError(error));
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
promiseThen.call(
|
|
448
|
+
promise,
|
|
449
|
+
(value) => {
|
|
450
|
+
let json;
|
|
451
|
+
try {
|
|
452
|
+
json = serialize(value);
|
|
453
|
+
} catch (error) {
|
|
454
|
+
done(false, describeError(error));
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
done(true, json, serializeWrites());
|
|
458
|
+
},
|
|
459
|
+
(error) => {
|
|
460
|
+
done(false, describeError(error));
|
|
461
|
+
},
|
|
462
|
+
);
|
|
463
|
+
},
|
|
464
|
+
stalled() {
|
|
465
|
+
if (finished || pending.size > 0) return false;
|
|
466
|
+
done(
|
|
467
|
+
false,
|
|
468
|
+
stringify({
|
|
469
|
+
name: "Error",
|
|
470
|
+
message:
|
|
471
|
+
"The script is waiting on a promise that can never settle: no tool call is pending, and timers do not exist here.",
|
|
472
|
+
}),
|
|
473
|
+
);
|
|
474
|
+
return true;
|
|
475
|
+
},
|
|
476
|
+
};
|
|
477
|
+
})`;function Ke(e){let t=2166136261;for(let o=0;o<e.length;o++)t^=e.charCodeAt(o),t=Math.imul(t,16777619);return(t>>>0).toString(16).padStart(8,"0")}s(Ke,"fnv1a");var Jt=Ke(He),Dt=256*1024,Wt=1<<20,Xe=200,ae=500,Ve=4,Ye=256*1024*1024,Qe=2;function ie(){let e=Number(process.env.PI_CODEMODE_MAX_WORKERS);return Number.isInteger(e)&&e>0?e:Qe}s(ie,"maxCodemodeWorkers");var z=6e4,q=0,I=[];function Ze(e,t){return e?.aborted?Promise.resolve("aborted"):new Promise(o=>{let r=s(c=>{clearTimeout(l),e?.removeEventListener("abort",a);let u=I.indexOf(n);u>=0&&I.splice(u,1),o(c)},"settle"),n=s(()=>r("reserved"),"grant"),a=s(()=>r("aborted"),"onAbort"),l=setTimeout(()=>r("timeout"),t);I.push(n),e?.addEventListener("abort",a,{once:!0}),le()})}s(Ze,"reserveCodemodeWorker");function le(){for(;I.length>0&&q<ie();)q++,I.shift()?.()}s(le,"admitCodemodeWorkers");function ce(){q--,le()}s(ce,"releaseCodemodeWorker");var ue=new Set(["chat","image","classifier"]);function G(e,t){return e.length>t?`${te(e,t-3)}...`:e}s(G,"truncateText");function et(e){if(e===void 0)return"";try{return G(JSON.stringify(e)??"",Xe)}catch{return""}}s(et,"previewArgs");function de(e){return(e.content??[]).filter(t=>t.type==="text").map(t=>t.text).join(`
|
|
478
|
+
`)}s(de,"textOf");function F(e){if(typeof e=="string"&&ue.has(e))return e;throw new Error(`Unknown model type ${JSON.stringify(e)}. Use "chat", "image", or "classifier".`)}s(F,"toModelType");function fe(e){if(e!=null){if(typeof e!="string")throw new Error("provider must be a string");return e}}s(fe,"toProvider");function H(e){let t={...e};return delete t.headers,t}s(H,"toModelInfo");function K(e){return`${/^[aeiou]/.test(e)?"an":"a"} ${e}`}s(K,"withArticle");function y(e){if(e==null)return String(e);if(Array.isArray(e))return e.length===0?"an empty array":"an array";if(typeof e=="object"){let t=Object.keys(e);return t.length===0?"{}":`{ ${t.slice(0,6).join(", ")}${t.length>6?", ...":""} }`}return typeof e=="string"?"a string":`a ${typeof e}`}s(y,"describeValue");var tt='{ state: { ... }, images?: [{ type: "image", data: <base64>, mimeType }], questions: { <id>: { type: "choice", instructions, criteria: { <label>: <meaning> } } | { type: "score", instructions, criteria: [<lowest level>, ..., <highest level>] } | { type: "bool", instructions, criteria: { true: <meaning>, false: <meaning> } } } }';function rt(e){let t=s(l=>new Error(`models.classify() ${l}. Expected context: ${tt}. See "Classify" in ${Q}.`),"fail");if(typeof e!="object"||e===null||Array.isArray(e))throw t(`expects a context object as its second argument, got ${y(e)}`);let{state:o,images:r,questions:n}=e;if(typeof o!="object"||o===null||Array.isArray(o))throw t(`context.state must be an object, got ${y(o)}`);if(r!==void 0){if(!Array.isArray(r))throw t(`context.images must be an array, got ${y(r)}`);r.forEach((l,c)=>{if(l?.type!=="image"||typeof l.data!="string"||typeof l.mimeType!="string")throw t(`context.images[${c}] must be an image block, got ${y(l)}`)})}if(typeof n!="object"||n===null||Array.isArray(n)||Object.keys(n).length===0)throw t(`context.questions must map question IDs to questions, got ${y(n)}`);let a=s(l=>l.length>0&&l.every(c=>typeof c=="string"),"isStrings");for(let[l,c]of Object.entries(n)){let u=`context.questions.${l}`;if(typeof c!="object"||c===null||Array.isArray(c))throw t(`${u} must be a question object, got ${y(c)}`);let{type:i,instructions:d,criteria:f}=c;if(typeof d!="string")throw t(`${u}.instructions must be a string`);if(i==="choice"){if(typeof f!="object"||f===null||Array.isArray(f)||!a(Object.values(f)))throw t(`${u} is a "choice" question, so criteria must map each label to its meaning`)}else if(i==="score"){if(!Array.isArray(f)||!a(f))throw t(`${u} is a "score" question, so criteria must list the levels as strings, lowest first`)}else if(i==="bool"){let m=f;if(typeof m?.true!="string"||typeof m.false!="string")throw t(`${u} is a "bool" question, so criteria must be { true: string, false: string }`)}else throw t(`${u}.type must be "choice", "score", or "bool", got ${JSON.stringify(i)}`)}return e}s(rt,"checkClassifierContext");function ot(e){let t=s(r=>new Error(`models.generateImages() ${r}. Expected context: { input: [{ type: "text", text: <prompt> }, ...optional { type: "image", data: <base64>, mimeType } references] }. See "Generate images" in ${Q}.`),"fail");if(typeof e!="object"||e===null||Array.isArray(e))throw t(`expects a context object as its second argument, got ${y(e)}`);let{input:o}=e;if(!Array.isArray(o)||o.length===0)throw t(`context.input must be a non-empty array of blocks, got ${y(o)}`);return o.forEach((r,n)=>{if(!(r?.type==="text"&&typeof r.text=="string")&&!(r?.type==="image"&&typeof r.data=="string"&&typeof r.mimeType=="string"))throw t(`context.input[${n}] must be a text or image block, got ${y(r)}`)}),e}s(ot,"checkImagesContext");function nt(e){let t=0,o=[];return async r=>{t>=e&&await new Promise(n=>o.push(n)),t++;try{return await r()}finally{t--,o.shift()?.()}}}s(nt,"createLimiter");function st(e){if(typeof e!="object"||e===null)return!1;let{set:t,delete:o}=e;return typeof t=="object"&&t!==null&&Array.isArray(o)&&o.every(r=>typeof r=="string")}s(st,"isStoreEntryData");function pe(e){let t=new Map;for(let o of e)if(!(o.type!=="custom"||o.customType!==Z||!st(o.data))){for(let r of o.data.delete)t.delete(r);for(let[r,n]of Object.entries(o.data.set))t.set(r,n)}return Object.fromEntries(t)}s(pe,"readCodemodeStore");var at=1e4,X=4;function it(e){return typeof e=="string"?e:JSON.stringify(e)??String(e)}s(it,"valueText");function lt(e){let t=e.filter(a=>a.type==="text"&&!a.console).length,o=[],r=[],n=0;for(let a of e)a.type==="image"?o.push(a):a.console?r.push(a.text):(n++,o.push({type:"text",text:t>1?`==> text ${n}/${t} <==
|
|
479
|
+
${a.text}`:a.text}));return r.length>0&&o.push({type:"text",text:`<console_output>
|
|
480
|
+
${r.join(`
|
|
481
|
+
`)}
|
|
482
|
+
</console_output>`}),o}s(lt,"formatOutput");function me(e){let t=[],o=[],r="",n=s(()=>{o.length>0&&t.push({type:"text",text:o.join("")}),o=[],r=""},"flush");for(let a of e){if(a.type!=="text"){n(),t.push(a);continue}r!==""&&!r.endsWith(`
|
|
483
|
+
`)&&(o.push(`
|
|
484
|
+
`),r=`
|
|
485
|
+
`),o.push(a.text),a.text!==""&&(r=a.text)}return n(),t}s(me,"joinAdjacentText");function ct(e){return e.length===0?"No tool calls were made.":`Tool calls made before the failure (they are not undone): ${e.map(t=>`${t.name} (${t.status})`).join(", ")}`}s(ct,"formatCallSummary");function ut(e,t){let{error:o}=e;return`${o.kind==="script"?o.stack??`${o.name??"Error"}: ${o.message}`:o.kind==="timeout"?`Script timed out: ${o.message}`:o.kind==="aborted"?`Script aborted: ${o.message}`:`Script sandbox failed: ${o.message}`}
|
|
486
|
+
|
|
487
|
+
${ct(t)}`}s(ut,"formatError");async function dt(e){try{return{path:await ee("dal-codemode",".txt",e)}}catch(t){return{error:t instanceof Error?t.message:String(t)}}}s(dt,"spillOutput");var ft={"image/png":".png","image/jpeg":".jpg","image/gif":".gif","image/webp":".webp"};async function pt(e){let t=new Map,o=s(async({data:r,mimeType:n})=>{let a=Buffer.from(r,"base64"),l=`${n}, ${Ne(a.length)}`,c=ft[n];if(!c)throw new Error(`No file extension for image type ${n}`);try{return`[Image saved to ${await ee("dal-codemode",c,a)} (${l})]`}catch(u){return`[Image (${l}) could not be saved: ${u instanceof Error?u.message:String(u)}]`}},"label");return(await Promise.all(e.map(async r=>{if(r.type!=="image")return[r];let n=t.get(r.data);return n||(n=o(r),t.set(r.data,n)),[{type:"text",text:await n},r]}))).flat()}s(pt,"saveImages");async function mt(e,t){let o=e.filter(m=>m.type==="text").map(m=>m.text),r=o.join(`
|
|
488
|
+
`),n=t*X;if(o.length===0||r.length<=n)return{items:e};let a=Math.floor(n/2),l=n-a,c=r.length-a-l,u=te(r,a),i=Ce(r,l),d=`Warning: truncated output (original token count: ${Math.ceil(r.length/X)})
|
|
489
|
+
Total output lines: ${r.split(`
|
|
490
|
+
`).length}
|
|
491
|
+
|
|
492
|
+
${u}\u2026${Math.ceil(c/X)} tokens truncated\u2026${i}`,f=await dt(r);return d+="path"in f?`
|
|
493
|
+
|
|
494
|
+
[Full output: ${f.path} (read with offset/limit)]`:`
|
|
495
|
+
|
|
496
|
+
[Could not save the full output: ${f.error}]`,{items:[{type:"text",text:d},...e.filter(m=>m.type==="image")],..."path"in f?{fullOutputPath:f.path}:{}}}s(mt,"truncateOutput");function ht(e,t){let{result:o}=t;if(e.outputSchema&&o.structuredContent!==void 0)return o.structuredContent;let r=de(o);if(t.isError)throw new Error(r||`Tool "${e.name}" failed`);return r}s(ht,"toScriptValue");async function gt(e,t,o,r,n,a={}){let l=performance.now(),{code:c,options:u}=Se(t.code),i=[],d,f=0,m=s(p=>{f+=p},"addGeneratedImages"),b=s(p=>{d=d?Te(d,p):p},"addModelUsage"),x=s(()=>({calls:i.map(p=>({...p}))}),"snapshot"),v=s(()=>r?.({content:[],details:x()}),"publish");v();let E=n?xe(n.tools):[],C=a.getToolGuidelines?.(),$=new Map(E.map(p=>[p.name,$e(Ae(p,C?.get(p.name)))])),P=E.map(p=>({name:p.name,description:$.get(p.name),execute:s(async(T,{signal:_})=>{let A={id:`${e}/?`,name:p.name,args:et(T),status:"running"};i.push(A),v();let we=performance.now();if(!n)throw new Error("Tool calls need a session");let L=await n.executeTool(p.name,T,{signal:_});return A.id=L.toolCall.id,A.durationMs=performance.now()-we,L.isError?(A.status=_.aborted?"cancelled":"error",A.error=G(de(L.result)||`Tool "${p.name}" failed`,ae)):A.status="ok",v(),ht(p,L)},"execute")})),w=u.timeoutMs??Number.POSITIVE_INFINITY,D=performance.now(),O=await Ze(o,Math.min(w,z)),W=performance.now()-D;if(O!=="reserved"){let p=((performance.now()-l)/1e3).toFixed(1),T=o?.reason,_=O==="aborted"?`Script aborted: ${T instanceof Error?T.message:"Execution aborted"}`:w<=z?`Script timed out: Execution timed out after ${w} ms while waiting for a free codemode worker`:`No codemode worker became free within ${z/1e3} seconds. All ${ie()} workers, shared by every session in this process, are held by other scripts. Retry after they finish.`;return{content:[{type:"text",text:`Script failed
|
|
497
|
+
Wall time ${p} seconds
|
|
498
|
+
Output:
|
|
499
|
+
`},{type:"text",text:`Script error:
|
|
500
|
+
${_}
|
|
501
|
+
|
|
502
|
+
The script did not start.`}],details:x(),isError:!0}}let h=!0,k,g;try{k=new Fe({tools:P,globals:[...yt(E,$,a),...a.models&&n?bt(n.modelRegistry,e,i,v,b,m):[]],timeoutMs:Math.max(1,Math.round(w-W)),memoryLimitBytes:Ye,wasm:se(Ie()),workerUrl:Me(),acquireWorker:s(()=>{if(!h)throw new Error("The script already settled");return h=!1,ce},"acquireWorker")});let p=n?pe(n.sessionManager.getBranch()):{};g=await k.execute(c,{signal:o,store:p})}finally{await k?.close(),h&&(h=!1,ce())}for(let p of i)p.status==="running"&&(p.status="cancelled");let V=[...g.output];if(g.ok){let{set:p,delete:T}=g.storeWrites;(Object.keys(p).length>0||T.length>0)&&a.appendEntry?.(Z,{set:p,delete:T}),g.value!==void 0&&V.push({type:"text",text:it(g.value)})}let R=lt(V);g.ok||R.push({type:"text",text:`Script error:
|
|
503
|
+
${ut(g,i)}`}),f>0&&!R.some(p=>p.type==="image")&&R.push({type:"text",text:`Note: models.generateImages() returned ${f} image${f===1?"":"s"} that the script did not show. Show each image block of result.output with image(block).`});let B=await mt(me(R),u.maxOutputTokens??at),ge=me(await pt(B.items)),ye=((performance.now()-l)/1e3).toFixed(1),be=`${g.ok?"Script completed":"Script failed"}
|
|
504
|
+
Wall time ${ye} seconds
|
|
505
|
+
Output:
|
|
506
|
+
`,Y=x();return B.fullOutputPath&&(Y.fullOutputPath=B.fullOutputPath),{content:[{type:"text",text:be},...ge],details:Y,...d?{usage:d}:{},...g.ok?{}:{isError:!0}}}s(gt,"executeCodemode");function he(e,t){let o=S(t);return[e.name,...e.aliases??[]].some(r=>r===t||S(r)===o)}s(he,"isNamespaceName");function yt(e,t,o){let r=new Oe,n=s(a=>({name:S(a),description:t.get(a)??""}),"entry");return[{name:"searchTools",spread:!0,execute:s(a=>{let[l,c]=a;if(typeof l!="string")throw new Error("searchTools() expects a query string");let u=c?.limit??ke;if(typeof u!="number"||!Number.isInteger(u)||u<=0)throw new Error("searchTools() limit must be a positive integer");let i=c?.namespace;if(i!=null&&typeof i!="string")throw new Error("searchTools() namespace must be a string");let d=e.flatMap(f=>{let m=o.getToolNamespace?.(f.name);return i&&(!m||!he(m,i))?[]:[je(f,m)]});return r.rank(l,d,u).map(f=>n(f.name))},"execute")},{name:"describeTool",spread:!0,execute:s(a=>{let[l]=a;if(typeof l!="string")throw new Error("describeTool() expects a tool name");let c=e.find(u=>u.name===l||S(u.name)===l);return c?t.get(c.name):void 0},"execute")},{name:"describeNamespace",spread:!0,execute:s(a=>{let[l]=a;if(typeof l!="string")throw new Error("describeNamespace() expects a namespace name");let c,u=[];for(let i of e){let d=o.getToolNamespace?.(i.name);!d||!he(d,l)||(c??=d,u.push(S(i.name)))}if(c)return{name:c.name,...c.description?{description:c.description}:{},...c.instructions?{instructions:c.instructions}:{},tools:u}},"execute")}]}s(yt,"createDiscoveryGlobals");function bt(e,t,o,r,n,a){let l=nt(Ve),c=0,u=s(async(i,d,[f,m],b,x)=>{let v=`List the ${d} models you can use with models.getAvailableOfType("${d}").`,E=f;if(typeof E?.provider!="string"||typeof E.id!="string"){let k=f==null?" models.getModelOfType() returns undefined for an unknown provider or id.":"";throw new Error(`${i}() expects ${K(d)} model as its first argument, got ${y(f)}.${k} ${v}`)}let C=E.provider,$=E.id,P=`${C}/${$}`,w=e.getModelOfType(d,C,$);if(!w){let k=[...ue].find(g=>g!==d&&e.getModelOfType(g,C,$)!==void 0);throw new Error(k?`"${P}" is ${K(k)} model, not ${K(d)} model. ${v}`:`Unknown ${d} model "${P}". ${v}`)}let D=b(m),O={id:`${t}/${i}/${++c}`,name:i,args:`${w.provider}/${w.id}`,status:"running"};o.push(O),r();let W=performance.now(),h=await l(()=>x(w,D));return O.durationMs=performance.now()-W,O.status=h.stopReason==="stop"?"ok":h.stopReason==="aborted"?"cancelled":"error",h.errorMessage&&(O.error=G(h.errorMessage,ae)),h.usage&&(O.cost=h.usage.cost.total,n(h.usage)),r(),h},"runModelCall");return Object.entries({"models.getModelsOfType":s(i=>{let[d,f]=i;return e.getModelsOfType(F(d),fe(f)).map(H)},"models.getModelsOfType"),"models.getAvailableOfType":s(async(i,{signal:d})=>{let[f,m]=i;return(await e.getAvailableOfType(F(f),fe(m),{signal:d})).map(H)},"models.getAvailableOfType"),"models.getModelOfType":s(i=>{let[d,f,m]=i;if(typeof f!="string"||typeof m!="string")throw new Error(`models.getModelOfType(type, provider, id) expects three strings, got (${i.map(y).join(", ")}). The provider and the id are separate arguments, for example models.getModelOfType("classifier", "typesafe", "jev-latest").`);let b=e.getModelOfType(F(d),f,m);return b===void 0?void 0:H(b)},"models.getModelOfType"),"models.classify":s((i,{signal:d})=>u("models.classify","classifier",i,rt,(f,m)=>e.classify(f,m,{signal:d})),"models.classify"),"models.generateImages":s((i,{signal:d})=>u("models.generateImages","image",i,ot,async(f,m)=>{let b=await e.generateImages(f,m,{signal:d});return a(b.output.filter(x=>x.type==="image").length),b}),"models.generateImages")}).map(([i,d])=>({name:i,spread:!0,execute:d}))}s(bt,"createModelGlobals");export{gt as executeCodemode,pe as readCodemodeStore};
|