@code-yeongyu/senpi 2026.7.14 → 2026.7.16-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +143 -0
- package/README.md +6 -6
- package/dist/bun/cli.js +2 -0
- package/dist/bun/cli.js.map +1 -1
- package/dist/cli/args.js +1 -1
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/list-models.d.ts +2 -2
- package/dist/cli/list-models.d.ts.map +1 -1
- package/dist/cli/list-models.js +3 -3
- package/dist/cli/list-models.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +3 -0
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +4 -3
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +14 -5
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +8 -4
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +81 -30
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-providers.js +1 -1
- package/dist/core/auth-providers.js.map +1 -1
- package/dist/core/auth-storage.d.ts +32 -87
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +158 -221
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/cache-stats.d.ts +2 -2
- package/dist/core/cache-stats.d.ts.map +1 -1
- package/dist/core/cache-stats.js +1 -1
- package/dist/core/cache-stats.js.map +1 -1
- package/dist/core/compaction/branch-summarization.d.ts +1 -1
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/dynamic-prompt/build.d.ts.map +1 -1
- package/dist/core/dynamic-prompt/build.js +6 -1
- package/dist/core/dynamic-prompt/build.js.map +1 -1
- package/dist/core/extensions/builtin/bash-timeout/timeout.js +2 -2
- package/dist/core/extensions/builtin/bash-timeout/timeout.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.js +22 -13
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/runtime-session.d.ts +1 -1
- package/dist/core/extensions/builtin/terminal/runtime-session.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/runtime-session.js +3 -2
- package/dist/core/extensions/builtin/terminal/runtime-session.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +8 -2
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +1 -0
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +3 -0
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +15 -2
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/model-config.d.ts +589 -0
- package/dist/core/model-config.d.ts.map +1 -0
- package/dist/core/model-config.js +288 -0
- package/dist/core/model-config.js.map +1 -0
- package/dist/core/model-registry.d.ts +17 -146
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +69 -943
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts +8 -5
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +19 -18
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-runtime.d.ts +81 -0
- package/dist/core/model-runtime.d.ts.map +1 -0
- package/dist/core/model-runtime.js +442 -0
- package/dist/core/model-runtime.js.map +1 -0
- package/dist/core/models-store.d.ts +17 -0
- package/dist/core/models-store.d.ts.map +1 -0
- package/dist/core/models-store.js +46 -0
- package/dist/core/models-store.js.map +1 -0
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +7 -2
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/provider-composer.d.ts +64 -0
- package/dist/core/provider-composer.d.ts.map +1 -0
- package/dist/core/provider-composer.js +406 -0
- package/dist/core/provider-composer.js.map +1 -0
- package/dist/core/provider-display-names.d.ts.map +1 -1
- package/dist/core/provider-display-names.js +2 -1
- package/dist/core/provider-display-names.js.map +1 -1
- package/dist/core/radius.d.ts +2 -0
- package/dist/core/radius.d.ts.map +1 -0
- package/dist/core/radius.js +2 -0
- package/dist/core/radius.js.map +1 -0
- package/dist/core/remote-catalog-provider.d.ts +5 -0
- package/dist/core/remote-catalog-provider.d.ts.map +1 -0
- package/dist/core/remote-catalog-provider.js +83 -0
- package/dist/core/remote-catalog-provider.js.map +1 -0
- package/dist/core/runtime-credentials.d.ts +15 -0
- package/dist/core/runtime-credentials.d.ts.map +1 -0
- package/dist/core/runtime-credentials.js +35 -0
- package/dist/core/runtime-credentials.js.map +1 -0
- package/dist/core/sdk.d.ts +11 -20
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +61 -89
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/skills.js +1 -1
- package/dist/core/skills.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +1 -11
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +10 -13
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +22 -10
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/footer.js +1 -1
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts +4 -8
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
- package/dist/modes/interactive/components/login-dialog.js +14 -12
- package/dist/modes/interactive/components/login-dialog.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts +13 -4
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +84 -41
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.d.ts +4 -4
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.js +14 -25
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +5 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +155 -129
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +70 -8
- package/dist/package-manager-cli.js.map +1 -1
- package/docs/custom-provider.md +8 -11
- package/docs/extensions.md +78 -555
- package/docs/models.md +4 -0
- package/docs/packages.md +1 -0
- package/docs/providers.md +23 -11
- package/docs/sdk.md +79 -105
- package/docs/usage.md +1 -0
- package/examples/AGENTS.md +34 -0
- package/examples/extensions/README.md +1 -0
- package/examples/extensions/custom-provider-anthropic/index.ts +1 -1
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/kimi-deferred-tools.ts +61 -0
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/sdk/02-custom-model.ts +5 -8
- package/examples/sdk/09-api-keys-and-oauth.ts +13 -31
- package/examples/sdk/12-full-control.ts +8 -13
- package/examples/sdk/README.md +14 -18
- package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +32 -0
- package/node_modules/@code-yeongyu/senpi-codemode/package.json +3 -3
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/local-module-loader.ts +2 -2
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/rewrite-imports.ts +4 -4
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/render.ts +32 -32
- package/node_modules/@earendil-works/pi-agent-core/package.json +4 -4
- package/node_modules/@earendil-works/pi-ai/README.md +80 -25
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js +23 -42
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.js +10 -6
- package/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/lazy.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/lazy.js +9 -10
- package/node_modules/@earendil-works/pi-ai/dist/api/lazy.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.d.ts +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js +4 -3
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.d.ts +2 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js +54 -5
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses-shared.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses-shared.js +23 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses-shared.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.d.ts +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.js +24 -6
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.d.ts +97 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.js +307 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.lazy.d.ts +3 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.lazy.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.lazy.js +3 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.lazy.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/credential-store.d.ts +2 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/credential-store.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/credential-store.js +3 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/credential-store.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/helpers.d.ts +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/helpers.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/helpers.js +4 -3
- package/node_modules/@earendil-works/pi-ai/dist/auth/helpers.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/anthropic.d.ts +9 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/anthropic.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/{utils → auth}/oauth/anthropic.js +51 -116
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/anthropic.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/device-code.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/device-code.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/github-copilot.d.ts +6 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/github-copilot.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/{utils → auth}/oauth/github-copilot.js +18 -77
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/github-copilot.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/load.d.ts +23 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/load.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/load.js +49 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/load.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/oauth-page.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/oauth-page.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/openai-codex.d.ts +9 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/openai-codex.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/{utils → auth}/oauth/openai-codex.js +61 -155
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/openai-codex.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/pkce.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/pkce.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/radius.d.ts +16 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/radius.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/radius.js +316 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/radius.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/xai.d.ts +6 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/xai.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/xai.js +189 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/xai.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.d.ts +2 -4
- package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.js +9 -7
- package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/types.d.ts +49 -10
- package/node_modules/@earendil-works/pi-ai/dist/auth/types.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/types.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/bun-oauth.d.ts +3 -0
- package/node_modules/@earendil-works/pi-ai/dist/bun-oauth.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/bun-oauth.js +17 -0
- package/node_modules/@earendil-works/pi-ai/dist/bun-oauth.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/cli.js +58 -76
- package/node_modules/@earendil-works/pi-ai/dist/cli.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/compat/extension-oauth-types.d.ts +42 -0
- package/node_modules/@earendil-works/pi-ai/dist/compat/extension-oauth-types.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/compat/extension-oauth-types.js +2 -0
- package/node_modules/@earendil-works/pi-ai/dist/compat/extension-oauth-types.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/compat.d.ts +2 -0
- package/node_modules/@earendil-works/pi-ai/dist/compat.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/compat.js +49 -22
- package/node_modules/@earendil-works/pi-ai/dist/compat.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.js +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/images-models.d.ts +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/images-models.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/images-models.js +5 -4
- package/node_modules/@earendil-works/pi-ai/dist/images-models.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/index.d.ts +3 -1
- package/node_modules/@earendil-works/pi-ai/dist/index.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/index.js +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/index.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/models-store.d.ts +25 -0
- package/node_modules/@earendil-works/pi-ai/dist/models-store.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/models-store.js +16 -0
- package/node_modules/@earendil-works/pi-ai/dist/models-store.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/models.d.ts +69 -30
- package/node_modules/@earendil-works/pi-ai/dist/models.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/models.generated.d.ts +328 -120
- package/node_modules/@earendil-works/pi-ai/dist/models.generated.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/models.js +217 -31
- package/node_modules/@earendil-works/pi-ai/dist/models.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/oauth.d.ts +2 -1
- package/node_modules/@earendil-works/pi-ai/dist/oauth.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/oauth.js +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/oauth.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/all.d.ts +11 -6
- package/node_modules/@earendil-works/pi-ai/dist/providers/all.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/all.js +3 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/all.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.js +51 -10
- package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/anthropic.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/anthropic.js +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/anthropic.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-ai-gateway.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-ai-gateway.js +4 -3
- package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-ai-gateway.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-auth.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-auth.js +13 -20
- package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-auth.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-stream.d.ts +8 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-stream.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-stream.js +21 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-stream.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-workers-ai.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-workers-ai.js +2 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-workers-ai.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot.js +11 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot.models.d.ts +1 -6
- package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot.models.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot.models.js +1 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot.models.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/google-vertex.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/google-vertex.js +56 -5
- package/node_modules/@earendil-works/pi-ai/dist/providers/google-vertex.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.models.d.ts +66 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.models.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.models.js +42 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.models.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai-cn.models.d.ts +36 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai-cn.models.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai-cn.models.js +19 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai-cn.models.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai.models.d.ts +36 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai.models.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai.models.js +19 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai.models.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex.js +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/opencode.models.d.ts +57 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/opencode.models.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/opencode.models.js +19 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/opencode.models.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.models.d.ts +42 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.models.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.models.js +175 -139
- package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.models.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/radius-config.d.ts +26 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/radius-config.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/radius-config.js +59 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/radius-config.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/radius.d.ts +9 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/radius.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/radius.js +54 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/radius.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/vercel-ai-gateway.models.d.ts +84 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/vercel-ai-gateway.models.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/vercel-ai-gateway.models.js +74 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/vercel-ai-gateway.models.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/xai.d.ts +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/xai.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/xai.js +15 -3
- package/node_modules/@earendil-works/pi-ai/dist/providers/xai.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/xai.models.d.ts +6 -114
- package/node_modules/@earendil-works/pi-ai/dist/providers/xai.models.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/xai.models.js +3 -92
- package/node_modules/@earendil-works/pi-ai/dist/providers/xai.models.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/context-transformer.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/context-transformer.js +9 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/context-transformer.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/index.d.ts +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/index.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/index.js +6 -2
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/index.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/coerce-parameters.d.ts +8 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/coerce-parameters.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/coerce-parameters.js +92 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/coerce-parameters.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/format.d.ts +6 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/format.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/format.js +54 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/format.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/index.d.ts +4 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/index.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/index.js +4 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/index.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-match.d.ts +7 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-match.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-match.js +16 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-match.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-tag-scanner.d.ts +19 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-tag-scanner.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-tag-scanner.js +217 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-tag-scanner.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/parse.d.ts +4 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/parse.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/parse.js +46 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/parse.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream-boundary.d.ts +13 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream-boundary.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream-boundary.js +144 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream-boundary.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream.d.ts +5 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream.js +208 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/tool-resolver.d.ts +4 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/tool-resolver.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/tool-resolver.js +17 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/tool-resolver.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/xml-entities.d.ts +5 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/xml-entities.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/xml-entities.js +34 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/xml-entities.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/types.d.ts +3 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/types.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/types.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/types.d.ts +12 -5
- package/node_modules/@earendil-works/pi-ai/dist/types.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/types.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/package.json +6 -1
- package/node_modules/@earendil-works/pi-pty/native/prebuilds/darwin-arm64/senpi_pty.darwin-arm64.node +0 -0
- package/node_modules/@earendil-works/pi-pty/package.json +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/utils.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/utils.js +22 -4
- package/node_modules/@earendil-works/pi-tui/dist/utils.js.map +1 -1
- package/node_modules/@earendil-works/pi-tui/package.json +1 -1
- package/package.json +6 -6
- package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/anthropic.d.ts +0 -27
- package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/anthropic.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/anthropic.js.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/device-code.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/device-code.js.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/github-copilot.d.ts +0 -32
- package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/github-copilot.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/github-copilot.js.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/index.d.ts +0 -58
- package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/index.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/index.js +0 -122
- package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/index.js.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/load.d.ts +0 -5
- package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/load.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/load.js +0 -22
- package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/load.js.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/oauth-page.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/oauth-page.js.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/openai-codex.d.ts +0 -45
- package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/openai-codex.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/openai-codex.js.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/pkce.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/pkce.js.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/types.d.ts +0 -64
- package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/types.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/types.js +0 -2
- package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/types.js.map +0 -1
- /package/node_modules/@earendil-works/pi-ai/dist/{utils → auth}/oauth/device-code.d.ts +0 -0
- /package/node_modules/@earendil-works/pi-ai/dist/{utils → auth}/oauth/device-code.js +0 -0
- /package/node_modules/@earendil-works/pi-ai/dist/{utils → auth}/oauth/oauth-page.d.ts +0 -0
- /package/node_modules/@earendil-works/pi-ai/dist/{utils → auth}/oauth/oauth-page.js +0 -0
- /package/node_modules/@earendil-works/pi-ai/dist/{utils → auth}/oauth/pkce.d.ts +0 -0
- /package/node_modules/@earendil-works/pi-ai/dist/{utils → auth}/oauth/pkce.js +0 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Provider } from "@earendil-works/pi-ai";
|
|
2
|
+
export declare const REMOTE_CATALOG_REFRESH_INTERVAL_MS: number;
|
|
3
|
+
/** Add a persisted pi.dev catalog overlay to a static built-in provider. */
|
|
4
|
+
export declare function withRemoteCatalog(provider: Provider, catalogBaseUrl?: string): Provider;
|
|
5
|
+
//# sourceMappingURL=remote-catalog-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remote-catalog-provider.d.ts","sourceRoot":"","sources":["../../src/core/remote-catalog-provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAc,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAKlE,eAAO,MAAM,kCAAkC,QAAqB,CAAC;AA0BrE,4EAA4E;AAC5E,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,EAAE,cAAc,GAAE,MAAiC,GAAG,QAAQ,CAkDjH"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { VERSION } from "../config.js";
|
|
2
|
+
import { getPiUserAgent } from "../utils/pi-user-agent.js";
|
|
3
|
+
const DEFAULT_CATALOG_BASE_URL = "https://pi.dev";
|
|
4
|
+
export const REMOTE_CATALOG_REFRESH_INTERVAL_MS = 4 * 60 * 60 * 1000;
|
|
5
|
+
function mergeModels(baseline, dynamic) {
|
|
6
|
+
const merged = [...baseline];
|
|
7
|
+
for (const model of dynamic) {
|
|
8
|
+
const index = merged.findIndex((entry) => entry.id === model.id);
|
|
9
|
+
if (index >= 0)
|
|
10
|
+
merged[index] = model;
|
|
11
|
+
else
|
|
12
|
+
merged.push(model);
|
|
13
|
+
}
|
|
14
|
+
return merged;
|
|
15
|
+
}
|
|
16
|
+
function parseCatalog(providerId, value) {
|
|
17
|
+
const entries = Array.isArray(value)
|
|
18
|
+
? value
|
|
19
|
+
: typeof value === "object" && value !== null && "models" in value && Array.isArray(value.models)
|
|
20
|
+
? value.models
|
|
21
|
+
: typeof value === "object" && value !== null
|
|
22
|
+
? Object.values(value)
|
|
23
|
+
: undefined;
|
|
24
|
+
if (!entries)
|
|
25
|
+
throw new Error(`Invalid model catalog for provider "${providerId}"`);
|
|
26
|
+
return entries
|
|
27
|
+
.filter((entry) => typeof entry === "object" && entry !== null && "id" in entry)
|
|
28
|
+
.map((model) => ({ ...model, provider: providerId }));
|
|
29
|
+
}
|
|
30
|
+
/** Add a persisted pi.dev catalog overlay to a static built-in provider. */
|
|
31
|
+
export function withRemoteCatalog(provider, catalogBaseUrl = DEFAULT_CATALOG_BASE_URL) {
|
|
32
|
+
let dynamicModels = [];
|
|
33
|
+
let inflightRefresh;
|
|
34
|
+
return {
|
|
35
|
+
...provider,
|
|
36
|
+
getModels: () => mergeModels(provider.getModels(), dynamicModels),
|
|
37
|
+
refreshModels: (context) => {
|
|
38
|
+
inflightRefresh ??= (async () => {
|
|
39
|
+
try {
|
|
40
|
+
const stored = await context.store.read();
|
|
41
|
+
if (stored)
|
|
42
|
+
dynamicModels = stored.models.filter((model) => model.provider === provider.id);
|
|
43
|
+
if (!context.allowNetwork || context.signal?.aborted)
|
|
44
|
+
return;
|
|
45
|
+
if (!context.force &&
|
|
46
|
+
stored?.checkedAt !== undefined &&
|
|
47
|
+
Date.now() - stored.checkedAt < REMOTE_CATALOG_REFRESH_INTERVAL_MS) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const url = new URL(`/api/models/providers/${encodeURIComponent(provider.id)}`, catalogBaseUrl);
|
|
51
|
+
const response = await fetch(url, {
|
|
52
|
+
headers: {
|
|
53
|
+
accept: "application/json",
|
|
54
|
+
"User-Agent": getPiUserAgent(VERSION),
|
|
55
|
+
},
|
|
56
|
+
signal: context.signal,
|
|
57
|
+
});
|
|
58
|
+
if (context.signal?.aborted)
|
|
59
|
+
return;
|
|
60
|
+
const checkedAt = Date.now();
|
|
61
|
+
if (response.status === 404 || response.status === 501) {
|
|
62
|
+
await context.store.write({ models: dynamicModels, checkedAt });
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (!response.ok) {
|
|
66
|
+
await context.store.write({ models: dynamicModels, checkedAt });
|
|
67
|
+
throw new Error(`Model catalog request failed for ${provider.id}: ${response.status}`);
|
|
68
|
+
}
|
|
69
|
+
const refreshed = parseCatalog(provider.id, await response.json());
|
|
70
|
+
if (context.signal?.aborted)
|
|
71
|
+
return;
|
|
72
|
+
dynamicModels = refreshed;
|
|
73
|
+
await context.store.write({ models: refreshed, checkedAt });
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
inflightRefresh = undefined;
|
|
77
|
+
}
|
|
78
|
+
})();
|
|
79
|
+
return inflightRefresh;
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=remote-catalog-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remote-catalog-provider.js","sourceRoot":"","sources":["../../src/core/remote-catalog-provider.ts"],"names":[],"mappings":"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","sourcesContent":["import type { Api, Model, Provider } from \"@earendil-works/pi-ai\";\nimport { VERSION } from \"../config.ts\";\nimport { getPiUserAgent } from \"../utils/pi-user-agent.ts\";\n\nconst DEFAULT_CATALOG_BASE_URL = \"https://pi.dev\";\nexport const REMOTE_CATALOG_REFRESH_INTERVAL_MS = 4 * 60 * 60 * 1000;\n\nfunction mergeModels(baseline: readonly Model<Api>[], dynamic: readonly Model<Api>[]): Model<Api>[] {\n\tconst merged = [...baseline];\n\tfor (const model of dynamic) {\n\t\tconst index = merged.findIndex((entry) => entry.id === model.id);\n\t\tif (index >= 0) merged[index] = model;\n\t\telse merged.push(model);\n\t}\n\treturn merged;\n}\n\nfunction parseCatalog(providerId: string, value: unknown): Model<Api>[] {\n\tconst entries = Array.isArray(value)\n\t\t? value\n\t\t: typeof value === \"object\" && value !== null && \"models\" in value && Array.isArray(value.models)\n\t\t\t? value.models\n\t\t\t: typeof value === \"object\" && value !== null\n\t\t\t\t? Object.values(value)\n\t\t\t\t: undefined;\n\tif (!entries) throw new Error(`Invalid model catalog for provider \"${providerId}\"`);\n\treturn entries\n\t\t.filter((entry): entry is Model<Api> => typeof entry === \"object\" && entry !== null && \"id\" in entry)\n\t\t.map((model) => ({ ...model, provider: providerId }));\n}\n\n/** Add a persisted pi.dev catalog overlay to a static built-in provider. */\nexport function withRemoteCatalog(provider: Provider, catalogBaseUrl: string = DEFAULT_CATALOG_BASE_URL): Provider {\n\tlet dynamicModels: readonly Model<Api>[] = [];\n\tlet inflightRefresh: Promise<void> | undefined;\n\n\treturn {\n\t\t...provider,\n\t\tgetModels: () => mergeModels(provider.getModels(), dynamicModels),\n\t\trefreshModels: (context) => {\n\t\t\tinflightRefresh ??= (async () => {\n\t\t\t\ttry {\n\t\t\t\t\tconst stored = await context.store.read();\n\t\t\t\t\tif (stored) dynamicModels = stored.models.filter((model) => model.provider === provider.id);\n\t\t\t\t\tif (!context.allowNetwork || context.signal?.aborted) return;\n\t\t\t\t\tif (\n\t\t\t\t\t\t!context.force &&\n\t\t\t\t\t\tstored?.checkedAt !== undefined &&\n\t\t\t\t\t\tDate.now() - stored.checkedAt < REMOTE_CATALOG_REFRESH_INTERVAL_MS\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst url = new URL(`/api/models/providers/${encodeURIComponent(provider.id)}`, catalogBaseUrl);\n\t\t\t\t\tconst response = await fetch(url, {\n\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\taccept: \"application/json\",\n\t\t\t\t\t\t\t\"User-Agent\": getPiUserAgent(VERSION),\n\t\t\t\t\t\t},\n\t\t\t\t\t\tsignal: context.signal,\n\t\t\t\t\t});\n\t\t\t\t\tif (context.signal?.aborted) return;\n\t\t\t\t\tconst checkedAt = Date.now();\n\t\t\t\t\tif (response.status === 404 || response.status === 501) {\n\t\t\t\t\t\tawait context.store.write({ models: dynamicModels, checkedAt });\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (!response.ok) {\n\t\t\t\t\t\tawait context.store.write({ models: dynamicModels, checkedAt });\n\t\t\t\t\t\tthrow new Error(`Model catalog request failed for ${provider.id}: ${response.status}`);\n\t\t\t\t\t}\n\t\t\t\t\tconst refreshed = parseCatalog(provider.id, await response.json());\n\t\t\t\t\tif (context.signal?.aborted) return;\n\t\t\t\t\tdynamicModels = refreshed;\n\t\t\t\t\tawait context.store.write({ models: refreshed, checkedAt });\n\t\t\t\t} finally {\n\t\t\t\t\tinflightRefresh = undefined;\n\t\t\t\t}\n\t\t\t})();\n\t\t\treturn inflightRefresh;\n\t\t},\n\t};\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Credential, CredentialInfo, CredentialStore } from "@earendil-works/pi-ai";
|
|
2
|
+
/** Async credential store overlay for non-persistent runtime API keys. */
|
|
3
|
+
export declare class RuntimeCredentials implements CredentialStore {
|
|
4
|
+
private readonly store;
|
|
5
|
+
private readonly overrides;
|
|
6
|
+
constructor(store: CredentialStore);
|
|
7
|
+
setRuntimeApiKey(providerId: string, apiKey: string): void;
|
|
8
|
+
removeRuntimeApiKey(providerId: string): void;
|
|
9
|
+
hasRuntimeApiKey(providerId: string): boolean;
|
|
10
|
+
read(providerId: string): Promise<Credential | undefined>;
|
|
11
|
+
list(): Promise<readonly CredentialInfo[]>;
|
|
12
|
+
modify(providerId: string, fn: (current: Credential | undefined) => Promise<Credential | undefined>): Promise<Credential | undefined>;
|
|
13
|
+
delete(providerId: string): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=runtime-credentials.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-credentials.d.ts","sourceRoot":"","sources":["../../src/core/runtime-credentials.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAEzF,0EAA0E;AAC1E,qBAAa,kBAAmB,YAAW,eAAe;IACzD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAkB;IACxC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA6B;IAEvD,YAAY,KAAK,EAAE,eAAe,EAEjC;IAED,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAEzD;IAED,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAE5C;IAED,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAE5C;IAEK,IAAI,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAG9D;IAEK,IAAI,IAAI,OAAO,CAAC,SAAS,cAAc,EAAE,CAAC,CAM/C;IAED,MAAM,CACL,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,CAAC,OAAO,EAAE,UAAU,GAAG,SAAS,KAAK,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,GACtE,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAEjC;IAEK,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAG9C;CACD"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** Async credential store overlay for non-persistent runtime API keys. */
|
|
2
|
+
export class RuntimeCredentials {
|
|
3
|
+
constructor(store) {
|
|
4
|
+
this.overrides = new Map();
|
|
5
|
+
this.store = store;
|
|
6
|
+
}
|
|
7
|
+
setRuntimeApiKey(providerId, apiKey) {
|
|
8
|
+
this.overrides.set(providerId, apiKey);
|
|
9
|
+
}
|
|
10
|
+
removeRuntimeApiKey(providerId) {
|
|
11
|
+
this.overrides.delete(providerId);
|
|
12
|
+
}
|
|
13
|
+
hasRuntimeApiKey(providerId) {
|
|
14
|
+
return this.overrides.has(providerId);
|
|
15
|
+
}
|
|
16
|
+
async read(providerId) {
|
|
17
|
+
const override = this.overrides.get(providerId);
|
|
18
|
+
return override ? { type: "api_key", key: override } : this.store.read(providerId);
|
|
19
|
+
}
|
|
20
|
+
async list() {
|
|
21
|
+
const entries = new Map((await this.store.list()).map((entry) => [entry.providerId, entry]));
|
|
22
|
+
for (const providerId of this.overrides.keys()) {
|
|
23
|
+
entries.set(providerId, { providerId, type: "api_key" });
|
|
24
|
+
}
|
|
25
|
+
return [...entries.values()];
|
|
26
|
+
}
|
|
27
|
+
modify(providerId, fn) {
|
|
28
|
+
return this.store.modify(providerId, fn);
|
|
29
|
+
}
|
|
30
|
+
async delete(providerId) {
|
|
31
|
+
this.overrides.delete(providerId);
|
|
32
|
+
await this.store.delete(providerId);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=runtime-credentials.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-credentials.js","sourceRoot":"","sources":["../../src/core/runtime-credentials.ts"],"names":[],"mappings":"AAEA,0EAA0E;AAC1E,MAAM,OAAO,kBAAkB;IAI9B,YAAY,KAAsB;QAFjB,cAAS,GAAG,IAAI,GAAG,EAAkB,CAAC;QAGtD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACpB,CAAC;IAED,gBAAgB,CAAC,UAAkB,EAAE,MAAc;QAClD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IACxC,CAAC;IAED,mBAAmB,CAAC,UAAkB;QACrC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IACnC,CAAC;IAED,gBAAgB,CAAC,UAAkB;QAClC,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,UAAkB;QAC5B,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAChD,OAAO,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACpF,CAAC;IAED,KAAK,CAAC,IAAI;QACT,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;QAC7F,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,CAAC;YAChD,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;QAC1D,CAAC;QACD,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAC9B,CAAC;IAED,MAAM,CACL,UAAkB,EAClB,EAAwE;QAExE,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAC1C,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,UAAkB;QAC9B,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAClC,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IACrC,CAAC;CACD","sourcesContent":["import type { Credential, CredentialInfo, CredentialStore } from \"@earendil-works/pi-ai\";\n\n/** Async credential store overlay for non-persistent runtime API keys. */\nexport class RuntimeCredentials implements CredentialStore {\n\tprivate readonly store: CredentialStore;\n\tprivate readonly overrides = new Map<string, string>();\n\n\tconstructor(store: CredentialStore) {\n\t\tthis.store = store;\n\t}\n\n\tsetRuntimeApiKey(providerId: string, apiKey: string): void {\n\t\tthis.overrides.set(providerId, apiKey);\n\t}\n\n\tremoveRuntimeApiKey(providerId: string): void {\n\t\tthis.overrides.delete(providerId);\n\t}\n\n\thasRuntimeApiKey(providerId: string): boolean {\n\t\treturn this.overrides.has(providerId);\n\t}\n\n\tasync read(providerId: string): Promise<Credential | undefined> {\n\t\tconst override = this.overrides.get(providerId);\n\t\treturn override ? { type: \"api_key\", key: override } : this.store.read(providerId);\n\t}\n\n\tasync list(): Promise<readonly CredentialInfo[]> {\n\t\tconst entries = new Map((await this.store.list()).map((entry) => [entry.providerId, entry]));\n\t\tfor (const providerId of this.overrides.keys()) {\n\t\t\tentries.set(providerId, { providerId, type: \"api_key\" });\n\t\t}\n\t\treturn [...entries.values()];\n\t}\n\n\tmodify(\n\t\tproviderId: string,\n\t\tfn: (current: Credential | undefined) => Promise<Credential | undefined>,\n\t): Promise<Credential | undefined> {\n\t\treturn this.store.modify(providerId, fn);\n\t}\n\n\tasync delete(providerId: string): Promise<void> {\n\t\tthis.overrides.delete(providerId);\n\t\tawait this.store.delete(providerId);\n\t}\n}\n"]}
|
package/dist/core/sdk.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { type ThinkingLevel } from "@earendil-works/pi-agent-core";
|
|
2
|
-
import
|
|
2
|
+
import type { Model } from "@earendil-works/pi-ai/compat";
|
|
3
3
|
import { AgentSession } from "./agent-session.ts";
|
|
4
4
|
import { AuthStorage } from "./auth-storage.ts";
|
|
5
5
|
import type { ServiceTier } from "./extensions/builtin/service-tier.ts";
|
|
6
6
|
import type { LoadExtensionsResult, SessionStartEvent, ToolDefinition } from "./extensions/index.ts";
|
|
7
7
|
import { ModelRegistry } from "./model-registry.ts";
|
|
8
|
+
import { ModelRuntime } from "./model-runtime.ts";
|
|
8
9
|
import type { ResourceLoader } from "./resource-loader.ts";
|
|
9
10
|
import { SessionManager } from "./session-manager.ts";
|
|
10
11
|
import { SettingsManager } from "./settings-manager.ts";
|
|
@@ -12,23 +13,25 @@ import { createBashTool, createCodingTools, createEditTool, createFindTool, crea
|
|
|
12
13
|
export interface CreateAgentSessionOptions {
|
|
13
14
|
/** Working directory for project-local discovery. Default: process.cwd() */
|
|
14
15
|
cwd?: string;
|
|
15
|
-
/** Global config directory. Default: ~/.
|
|
16
|
+
/** Global config directory. Default: ~/.pi/agent */
|
|
16
17
|
agentDir?: string;
|
|
17
|
-
/**
|
|
18
|
+
/** Canonical model/auth runtime. Defaults to a runtime using agentDir/auth.json and models.json. */
|
|
19
|
+
modelRuntime?: ModelRuntime;
|
|
20
|
+
/** Legacy credential facade retained for SDK compatibility. */
|
|
18
21
|
authStorage?: AuthStorage;
|
|
19
|
-
/**
|
|
22
|
+
/** Legacy model facade retained for SDK compatibility. */
|
|
20
23
|
modelRegistry?: ModelRegistry;
|
|
21
24
|
/** Model to use. Default: from settings, else first available */
|
|
22
25
|
model?: Model<any>;
|
|
23
26
|
/** Thinking level. Default: from settings, else 'medium' (clamped to model capabilities) */
|
|
24
27
|
thinkingLevel?: ThinkingLevel;
|
|
25
|
-
/**
|
|
28
|
+
/** Models available for cycling (Ctrl+P in interactive mode) */
|
|
26
29
|
scopedModels?: Array<{
|
|
27
30
|
model: Model<any>;
|
|
28
31
|
thinkingLevel?: ThinkingLevel;
|
|
29
32
|
serviceTier?: ServiceTier;
|
|
30
33
|
}>;
|
|
31
|
-
/** Favorite models for Ctrl+P cycling */
|
|
34
|
+
/** Favorite models for Ctrl+P cycling. */
|
|
32
35
|
favoriteModels?: Array<{
|
|
33
36
|
model: Model<any>;
|
|
34
37
|
thinkingLevel?: ThinkingLevel;
|
|
@@ -62,6 +65,7 @@ export interface CreateAgentSessionOptions {
|
|
|
62
65
|
settingsManager?: SettingsManager;
|
|
63
66
|
/** Session start event metadata for extension runtime startup. */
|
|
64
67
|
sessionStartEvent?: SessionStartEvent;
|
|
68
|
+
/** Generate a session title after the first successful turn. */
|
|
65
69
|
autoTitleSessions?: boolean;
|
|
66
70
|
}
|
|
67
71
|
/** Result from createAgentSession */
|
|
@@ -79,6 +83,7 @@ export type { PromptTemplate } from "./prompt-templates.ts";
|
|
|
79
83
|
export type { Skill } from "./skills.ts";
|
|
80
84
|
export type { Tool } from "./tools/index.ts";
|
|
81
85
|
export { createBashTool, createCodingTools, createEditTool, createFindTool, createGrepTool, createLsTool, createReadOnlyTools, createReadTool, createWriteTool, withFileMutationQueue, };
|
|
86
|
+
export declare function clampThinkingLevelToModel(level: ThinkingLevel | undefined, model: Model<any> | undefined): ThinkingLevel;
|
|
82
87
|
/**
|
|
83
88
|
* Create an AgentSession with the specified options.
|
|
84
89
|
*
|
|
@@ -115,18 +120,4 @@ export { createBashTool, createCodingTools, createEditTool, createFindTool, crea
|
|
|
115
120
|
* ```
|
|
116
121
|
*/
|
|
117
122
|
export declare function createAgentSession(options?: CreateAgentSessionOptions): Promise<CreateAgentSessionResult>;
|
|
118
|
-
/**
|
|
119
|
-
* Clamp a requested thinking level to what the resolved model actually exposes.
|
|
120
|
-
*
|
|
121
|
-
* Capability tiers:
|
|
122
|
-
* - Non-reasoning model: everything collapses to "off".
|
|
123
|
-
* - Model metadata can disable individual levels via thinkingLevelMap.
|
|
124
|
-
* - No xhigh support: xhigh and max both collapse to "high".
|
|
125
|
-
* - xhigh but no max: max collapses to "xhigh" (currently GPT-5.2/5.3/5.4).
|
|
126
|
-
* - Native max support: xhigh and max are both preserved (Opus 4.6 / 4.7).
|
|
127
|
-
*
|
|
128
|
-
* This keeps session state aligned with `getAvailableThinkingLevels()` so the
|
|
129
|
-
* UI never claims a tier the provider will silently downgrade at request time.
|
|
130
|
-
*/
|
|
131
|
-
export declare function clampThinkingLevelToModel(level: ThinkingLevel | undefined, model: Model<Api> | undefined): ThinkingLevel;
|
|
132
123
|
//# sourceMappingURL=sdk.d.ts.map
|
package/dist/core/sdk.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../../src/core/sdk.ts"],"names":[],"mappings":"AACA,OAAO,EAA4B,KAAK,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC7F,OAAO,
|
|
1
|
+
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../../src/core/sdk.ts"],"names":[],"mappings":"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"}
|
package/dist/core/sdk.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
2
|
import { Agent } from "@earendil-works/pi-agent-core";
|
|
3
|
-
import { streamSimple } from "@earendil-works/pi-ai/compat";
|
|
4
3
|
import { getAgentDir } from "../config.js";
|
|
5
4
|
import { resolvePath } from "../utils/paths.js";
|
|
6
5
|
import { AgentSession } from "./agent-session.js";
|
|
@@ -10,6 +9,7 @@ import { DEFAULT_THINKING_LEVEL } from "./defaults.js";
|
|
|
10
9
|
import { convertToLlm } from "./messages.js";
|
|
11
10
|
import { ModelRegistry } from "./model-registry.js";
|
|
12
11
|
import { findInitialModel, getModelNarrowingPatterns, resolveModelScope } from "./model-resolver.js";
|
|
12
|
+
import { ModelRuntime } from "./model-runtime.js";
|
|
13
13
|
import { mergeProviderAttributionHeaders } from "./provider-attribution.js";
|
|
14
14
|
import { DefaultResourceLoader } from "./resource-loader.js";
|
|
15
15
|
import { getDefaultSessionDir, SessionManager } from "./session-manager.js";
|
|
@@ -19,9 +19,30 @@ import { time } from "./timings.js";
|
|
|
19
19
|
import { createBashTool, createCodingTools, createEditTool, createFindTool, createGrepTool, createLsTool, createReadOnlyTools, createReadTool, createWriteTool, withFileMutationQueue, } from "./tools/index.js";
|
|
20
20
|
// Re-exports
|
|
21
21
|
export * from "./agent-session-runtime.js";
|
|
22
|
-
export {
|
|
22
|
+
export { createBashTool,
|
|
23
23
|
// Tool factories (for custom cwd)
|
|
24
|
-
|
|
24
|
+
createCodingTools, createEditTool, createFindTool, createGrepTool, createLsTool, createReadOnlyTools, createReadTool, createWriteTool, withFileMutationQueue, };
|
|
25
|
+
export function clampThinkingLevelToModel(level, model) {
|
|
26
|
+
if (!model?.reasoning)
|
|
27
|
+
return "off";
|
|
28
|
+
const requested = level ?? "off";
|
|
29
|
+
const available = getSupportedThinkingLevels(model);
|
|
30
|
+
if (available.includes(requested))
|
|
31
|
+
return requested;
|
|
32
|
+
const ordered = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
33
|
+
const requestedIndex = ordered.indexOf(requested);
|
|
34
|
+
for (let index = requestedIndex - 1; index >= 0; index--) {
|
|
35
|
+
const candidate = ordered[index];
|
|
36
|
+
if (candidate !== undefined && available.includes(candidate))
|
|
37
|
+
return candidate;
|
|
38
|
+
}
|
|
39
|
+
for (let index = requestedIndex + 1; index < ordered.length; index++) {
|
|
40
|
+
const candidate = ordered[index];
|
|
41
|
+
if (candidate !== undefined && available.includes(candidate))
|
|
42
|
+
return candidate;
|
|
43
|
+
}
|
|
44
|
+
return available[0] ?? "off";
|
|
45
|
+
}
|
|
25
46
|
// Helper Functions
|
|
26
47
|
function getDefaultAgentDir() {
|
|
27
48
|
return getAgentDir();
|
|
@@ -65,43 +86,37 @@ export async function createAgentSession(options = {}) {
|
|
|
65
86
|
const cwd = resolvePath(options.cwd ?? options.sessionManager?.getCwd() ?? process.cwd());
|
|
66
87
|
const agentDir = options.agentDir ? resolvePath(options.agentDir) : getDefaultAgentDir();
|
|
67
88
|
let resourceLoader = options.resourceLoader;
|
|
68
|
-
// Use provided or create AuthStorage and ModelRegistry
|
|
69
89
|
const authPath = options.agentDir ? join(agentDir, "auth.json") : undefined;
|
|
70
90
|
const modelsPath = options.agentDir ? join(agentDir, "models.json") : undefined;
|
|
71
|
-
const authStorage = options.authStorage ?? AuthStorage.create(authPath);
|
|
72
|
-
const
|
|
91
|
+
const authStorage = options.authStorage ?? options.modelRegistry?.authStorage ?? AuthStorage.create(authPath);
|
|
92
|
+
const modelRuntime = options.modelRuntime ??
|
|
93
|
+
options.modelRegistry?.modelRuntime ??
|
|
94
|
+
(await ModelRuntime.create({ credentials: authStorage, modelsPath }));
|
|
95
|
+
const modelRegistry = options.modelRegistry ?? new ModelRegistry(modelRuntime, authStorage);
|
|
73
96
|
const settingsManager = options.settingsManager ?? SettingsManager.create(cwd, agentDir);
|
|
74
97
|
const sessionManager = options.sessionManager ?? SessionManager.create(cwd, getDefaultSessionDir(cwd, agentDir));
|
|
75
98
|
const scopedModels = options.scopedModels ??
|
|
76
|
-
(await resolveModelScope(getModelNarrowingPatterns({
|
|
77
|
-
|
|
78
|
-
}), modelRegistry));
|
|
79
|
-
const favoriteModels = options.favoriteModels ?? (await resolveModelScope(settingsManager.getFavoriteModels() ?? [], modelRegistry));
|
|
99
|
+
(await resolveModelScope(getModelNarrowingPatterns({ legacyEnabledPatterns: settingsManager.getEnabledModels() }), modelRuntime));
|
|
100
|
+
const favoriteModels = options.favoriteModels ?? (await resolveModelScope(settingsManager.getFavoriteModels() ?? [], modelRuntime));
|
|
80
101
|
if (!resourceLoader) {
|
|
81
102
|
resourceLoader = new DefaultResourceLoader({ cwd, agentDir, settingsManager });
|
|
82
103
|
await resourceLoader.reload();
|
|
83
104
|
time("resourceLoader.reload");
|
|
84
105
|
}
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
const
|
|
89
|
-
existingSession ??= sessionManager.buildSessionContext();
|
|
90
|
-
return existingSession;
|
|
91
|
-
};
|
|
106
|
+
// Check if session has existing data to restore
|
|
107
|
+
const existingSession = sessionManager.buildSessionContext();
|
|
108
|
+
const hasExistingSession = existingSession.messages.length > 0;
|
|
109
|
+
const hasThinkingEntry = sessionManager.getBranch().some((entry) => entry.type === "thinking_level_change");
|
|
92
110
|
let model = options.model;
|
|
93
111
|
let modelFallbackMessage;
|
|
94
112
|
// If session has data, try to restore model from it
|
|
95
|
-
if (!model && hasExistingSession) {
|
|
96
|
-
const
|
|
97
|
-
if (
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
if (!model) {
|
|
103
|
-
modelFallbackMessage = `Could not restore model ${sessionContext.model.provider}/${sessionContext.model.modelId}`;
|
|
104
|
-
}
|
|
113
|
+
if (!model && hasExistingSession && existingSession.model) {
|
|
114
|
+
const restoredModel = modelRuntime.getModel(existingSession.model.provider, existingSession.model.modelId);
|
|
115
|
+
if (restoredModel && modelRuntime.hasConfiguredAuth(restoredModel.provider)) {
|
|
116
|
+
model = restoredModel;
|
|
117
|
+
}
|
|
118
|
+
if (!model) {
|
|
119
|
+
modelFallbackMessage = `Could not restore model ${existingSession.model.provider}/${existingSession.model.modelId}`;
|
|
105
120
|
}
|
|
106
121
|
}
|
|
107
122
|
// If still no model, use findInitialModel (checks settings default, then provider defaults)
|
|
@@ -112,7 +127,7 @@ export async function createAgentSession(options = {}) {
|
|
|
112
127
|
defaultProvider: settingsManager.getDefaultProvider(),
|
|
113
128
|
defaultModelId: settingsManager.getDefaultModel(),
|
|
114
129
|
defaultThinkingLevel: settingsManager.getDefaultThinkingLevel(),
|
|
115
|
-
|
|
130
|
+
modelRuntime,
|
|
116
131
|
});
|
|
117
132
|
model = result.model;
|
|
118
133
|
if (!model) {
|
|
@@ -126,7 +141,7 @@ export async function createAgentSession(options = {}) {
|
|
|
126
141
|
// If session has data, restore thinking level from it
|
|
127
142
|
if (thinkingLevel === undefined && hasExistingSession) {
|
|
128
143
|
thinkingLevel = hasThinkingEntry
|
|
129
|
-
?
|
|
144
|
+
? existingSession.thinkingLevel
|
|
130
145
|
: (settingsManager.getDefaultThinkingLevel() ?? DEFAULT_THINKING_LEVEL);
|
|
131
146
|
}
|
|
132
147
|
// Fall back to settings default
|
|
@@ -134,7 +149,12 @@ export async function createAgentSession(options = {}) {
|
|
|
134
149
|
thinkingLevel = settingsManager.getDefaultThinkingLevel() ?? DEFAULT_THINKING_LEVEL;
|
|
135
150
|
}
|
|
136
151
|
// Clamp to model capabilities
|
|
137
|
-
|
|
152
|
+
if (!model) {
|
|
153
|
+
thinkingLevel = "off";
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
thinkingLevel = clampThinkingLevelToModel(thinkingLevel, model);
|
|
157
|
+
}
|
|
138
158
|
const defaultActiveToolNames = ["read", "bash", "edit", "write"];
|
|
139
159
|
const allowedToolNames = options.tools ?? (options.noTools === "all" ? [] : undefined);
|
|
140
160
|
const excludedToolNames = options.excludeTools;
|
|
@@ -172,7 +192,6 @@ export async function createAgentSession(options = {}) {
|
|
|
172
192
|
});
|
|
173
193
|
};
|
|
174
194
|
const extensionRunnerRef = {};
|
|
175
|
-
const providerRetrySettings = settingsManager.getProviderRetrySettings();
|
|
176
195
|
agent = new Agent({
|
|
177
196
|
initialState: {
|
|
178
197
|
systemPrompt: "",
|
|
@@ -182,11 +201,6 @@ export async function createAgentSession(options = {}) {
|
|
|
182
201
|
},
|
|
183
202
|
convertToLlm: convertToLlmWithBlockImages,
|
|
184
203
|
streamFn: async (model, context, options) => {
|
|
185
|
-
const auth = await modelRegistry.getApiKeyAndHeaders(model);
|
|
186
|
-
if (!auth.ok) {
|
|
187
|
-
throw new Error(auth.error);
|
|
188
|
-
}
|
|
189
|
-
const requestModel = auth.upstreamModelId ? { ...model, id: auth.upstreamModelId } : model;
|
|
190
204
|
const providerRetrySettings = settingsManager.getProviderRetrySettings();
|
|
191
205
|
const httpIdleTimeoutMs = settingsManager.getHttpIdleTimeoutMs();
|
|
192
206
|
// SDKs treat timeout=0 as 0ms (immediate timeout), not "no timeout".
|
|
@@ -194,27 +208,20 @@ export async function createAgentSession(options = {}) {
|
|
|
194
208
|
const effectiveTimeoutMs = httpIdleTimeoutMs === 0 ? 2147483647 : httpIdleTimeoutMs;
|
|
195
209
|
const timeoutMs = options?.timeoutMs ?? providerRetrySettings.timeoutMs ?? effectiveTimeoutMs;
|
|
196
210
|
const websocketConnectTimeoutMs = options?.websocketConnectTimeoutMs ?? settingsManager.getWebSocketConnectTimeoutMs();
|
|
197
|
-
const env = auth.env || options?.env ? { ...(auth.env ?? {}), ...(options?.env ?? {}) } : undefined;
|
|
198
|
-
let headers = mergeProviderAttributionHeaders(model, settingsManager, options?.sessionId, auth.headers, options?.headers);
|
|
199
|
-
// Let extensions inject/adjust per-request headers (e.g. tracing, session correlation)
|
|
200
|
-
// after static assembly, before the provider HTTP call.
|
|
201
211
|
const headerRunner = extensionRunnerRef.current;
|
|
202
|
-
|
|
203
|
-
headers = await headerRunner.emitBeforeProviderHeaders(headers ?? {});
|
|
204
|
-
}
|
|
205
|
-
const streamOptions = {
|
|
212
|
+
return modelRuntime.streamSimple(model, context, {
|
|
206
213
|
...options,
|
|
207
|
-
apiKey: auth.apiKey,
|
|
208
|
-
serviceTier: auth.serviceTier,
|
|
209
|
-
env,
|
|
210
214
|
timeoutMs,
|
|
211
215
|
websocketConnectTimeoutMs,
|
|
212
216
|
maxRetries: options?.maxRetries ?? providerRetrySettings.maxRetries,
|
|
213
217
|
maxRetryDelayMs: options?.maxRetryDelayMs ?? providerRetrySettings.maxRetryDelayMs,
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
+
transformHeaders: async (requestHeaders) => {
|
|
219
|
+
const headers = mergeProviderAttributionHeaders(model, settingsManager, options?.sessionId, requestHeaders);
|
|
220
|
+
return headerRunner?.hasHandlers("before_provider_headers")
|
|
221
|
+
? headerRunner.emitBeforeProviderHeaders(headers ?? {})
|
|
222
|
+
: (headers ?? {});
|
|
223
|
+
},
|
|
224
|
+
});
|
|
218
225
|
},
|
|
219
226
|
onPayload: async (payload, _model) => {
|
|
220
227
|
const runner = extensionRunnerRef.current;
|
|
@@ -246,11 +253,11 @@ export async function createAgentSession(options = {}) {
|
|
|
246
253
|
transport: settingsManager.getTransport(),
|
|
247
254
|
thinkingBudgets: settingsManager.getThinkingBudgets(),
|
|
248
255
|
timeoutMs: settingsManager.getAgentStreamIdleTimeoutMs(),
|
|
249
|
-
maxRetryDelayMs:
|
|
256
|
+
maxRetryDelayMs: settingsManager.getProviderRetrySettings().maxRetryDelayMs,
|
|
250
257
|
});
|
|
251
258
|
// Restore messages if session has existing data
|
|
252
259
|
if (hasExistingSession) {
|
|
253
|
-
agent.state.messages =
|
|
260
|
+
agent.state.messages = existingSession.messages;
|
|
254
261
|
if (!hasThinkingEntry) {
|
|
255
262
|
sessionManager.appendThinkingLevelChange(thinkingLevel);
|
|
256
263
|
}
|
|
@@ -271,6 +278,7 @@ export async function createAgentSession(options = {}) {
|
|
|
271
278
|
favoriteModels,
|
|
272
279
|
resourceLoader,
|
|
273
280
|
customTools: options.customTools,
|
|
281
|
+
modelRuntime,
|
|
274
282
|
modelRegistry,
|
|
275
283
|
initialActiveToolNames,
|
|
276
284
|
allowedToolNames,
|
|
@@ -286,40 +294,4 @@ export async function createAgentSession(options = {}) {
|
|
|
286
294
|
modelFallbackMessage,
|
|
287
295
|
};
|
|
288
296
|
}
|
|
289
|
-
/**
|
|
290
|
-
* Clamp a requested thinking level to what the resolved model actually exposes.
|
|
291
|
-
*
|
|
292
|
-
* Capability tiers:
|
|
293
|
-
* - Non-reasoning model: everything collapses to "off".
|
|
294
|
-
* - Model metadata can disable individual levels via thinkingLevelMap.
|
|
295
|
-
* - No xhigh support: xhigh and max both collapse to "high".
|
|
296
|
-
* - xhigh but no max: max collapses to "xhigh" (currently GPT-5.2/5.3/5.4).
|
|
297
|
-
* - Native max support: xhigh and max are both preserved (Opus 4.6 / 4.7).
|
|
298
|
-
*
|
|
299
|
-
* This keeps session state aligned with `getAvailableThinkingLevels()` so the
|
|
300
|
-
* UI never claims a tier the provider will silently downgrade at request time.
|
|
301
|
-
*/
|
|
302
|
-
export function clampThinkingLevelToModel(level, model) {
|
|
303
|
-
if (!model?.reasoning)
|
|
304
|
-
return "off";
|
|
305
|
-
const requestedLevel = level ?? "off";
|
|
306
|
-
const availableLevels = getSupportedThinkingLevels(model);
|
|
307
|
-
if (availableLevels.includes(requestedLevel))
|
|
308
|
-
return requestedLevel;
|
|
309
|
-
const clampedLevels = ["off", "minimal", "low", "medium", "high", "xhigh"];
|
|
310
|
-
const requestedIndex = clampedLevels.indexOf(requestedLevel === "max" ? "xhigh" : requestedLevel);
|
|
311
|
-
if (requestedIndex === -1)
|
|
312
|
-
return availableLevels[0] ?? "off";
|
|
313
|
-
for (let index = requestedIndex; index < clampedLevels.length; index++) {
|
|
314
|
-
const candidate = clampedLevels[index];
|
|
315
|
-
if (candidate !== undefined && availableLevels.includes(candidate))
|
|
316
|
-
return candidate;
|
|
317
|
-
}
|
|
318
|
-
for (let index = requestedIndex - 1; index >= 0; index--) {
|
|
319
|
-
const candidate = clampedLevels[index];
|
|
320
|
-
if (candidate !== undefined && availableLevels.includes(candidate))
|
|
321
|
-
return candidate;
|
|
322
|
-
}
|
|
323
|
-
return availableLevels[0] ?? "off";
|
|
324
|
-
}
|
|
325
297
|
//# sourceMappingURL=sdk.js.map
|