@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xai.d.ts","sourceRoot":"","sources":["../../src/providers/xai.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"xai.d.ts","sourceRoot":"","sources":["../../src/providers/xai.ts"],"names":[],"mappings":"AAIA,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAG7D,wBAAgB,WAAW,IAAI,QAAQ,CAAC,oBAAoB,GAAG,kBAAkB,CAAC,CAmBjF"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { openAICompletionsApi } from "../api/openai-completions.lazy.js";
|
|
2
|
-
import {
|
|
2
|
+
import { openAIResponsesApi } from "../api/openai-responses.lazy.js";
|
|
3
|
+
import { envApiKeyAuth, lazyOAuth } from "../auth/helpers.js";
|
|
4
|
+
import { loadXaiOAuth } from "../auth/oauth/load.js";
|
|
3
5
|
import { createProvider } from "../models.js";
|
|
4
6
|
import { XAI_MODELS } from "./xai.models.js";
|
|
5
7
|
export function xaiProvider() {
|
|
@@ -7,9 +9,19 @@ export function xaiProvider() {
|
|
|
7
9
|
id: "xai",
|
|
8
10
|
name: "xAI",
|
|
9
11
|
baseUrl: "https://api.x.ai/v1",
|
|
10
|
-
auth: {
|
|
12
|
+
auth: {
|
|
13
|
+
apiKey: envApiKeyAuth("xAI API key", ["XAI_API_KEY"]),
|
|
14
|
+
oauth: lazyOAuth({
|
|
15
|
+
name: "xAI (Grok/X subscription)",
|
|
16
|
+
loginLabel: "Sign in with SuperGrok or X Premium",
|
|
17
|
+
load: loadXaiOAuth,
|
|
18
|
+
}),
|
|
19
|
+
},
|
|
11
20
|
models: Object.values(XAI_MODELS),
|
|
12
|
-
api:
|
|
21
|
+
api: {
|
|
22
|
+
"openai-completions": openAICompletionsApi(),
|
|
23
|
+
"openai-responses": openAIResponsesApi(),
|
|
24
|
+
},
|
|
13
25
|
});
|
|
14
26
|
}
|
|
15
27
|
//# sourceMappingURL=xai.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xai.js","sourceRoot":"","sources":["../../src/providers/xai.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"xai.js","sourceRoot":"","sources":["../../src/providers/xai.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAiB,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,MAAM,UAAU,WAAW;IAC1B,OAAO,cAAc,CAAC;QACrB,EAAE,EAAE,KAAK;QACT,IAAI,EAAE,KAAK;QACX,OAAO,EAAE,qBAAqB;QAC9B,IAAI,EAAE;YACL,MAAM,EAAE,aAAa,CAAC,aAAa,EAAE,CAAC,aAAa,CAAC,CAAC;YACrD,KAAK,EAAE,SAAS,CAAC;gBAChB,IAAI,EAAE,2BAA2B;gBACjC,UAAU,EAAE,qCAAqC;gBACjD,IAAI,EAAE,YAAY;aAClB,CAAC;SACF;QACD,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC;QACjC,GAAG,EAAE;YACJ,oBAAoB,EAAE,oBAAoB,EAAE;YAC5C,kBAAkB,EAAE,kBAAkB,EAAE;SACxC;KACD,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { openAICompletionsApi } from \"../api/openai-completions.lazy.ts\";\nimport { openAIResponsesApi } from \"../api/openai-responses.lazy.ts\";\nimport { envApiKeyAuth, lazyOAuth } from \"../auth/helpers.ts\";\nimport { loadXaiOAuth } from \"../auth/oauth/load.ts\";\nimport { createProvider, type Provider } from \"../models.ts\";\nimport { XAI_MODELS } from \"./xai.models.ts\";\n\nexport function xaiProvider(): Provider<\"openai-completions\" | \"openai-responses\"> {\n\treturn createProvider({\n\t\tid: \"xai\",\n\t\tname: \"xAI\",\n\t\tbaseUrl: \"https://api.x.ai/v1\",\n\t\tauth: {\n\t\t\tapiKey: envApiKeyAuth(\"xAI API key\", [\"XAI_API_KEY\"]),\n\t\t\toauth: lazyOAuth({\n\t\t\t\tname: \"xAI (Grok/X subscription)\",\n\t\t\t\tloginLabel: \"Sign in with SuperGrok or X Premium\",\n\t\t\t\tload: loadXaiOAuth,\n\t\t\t}),\n\t\t},\n\t\tmodels: Object.values(XAI_MODELS),\n\t\tapi: {\n\t\t\t\"openai-completions\": openAICompletionsApi(),\n\t\t\t\"openai-responses\": openAIResponsesApi(),\n\t\t},\n\t});\n}\n"]}
|
|
@@ -1,92 +1,4 @@
|
|
|
1
1
|
export declare const XAI_MODELS: {
|
|
2
|
-
readonly "grok-3": {
|
|
3
|
-
id: string;
|
|
4
|
-
name: string;
|
|
5
|
-
api: "openai-completions";
|
|
6
|
-
provider: string;
|
|
7
|
-
baseUrl: string;
|
|
8
|
-
compat: {
|
|
9
|
-
supportsStore: false;
|
|
10
|
-
supportsDeveloperRole: false;
|
|
11
|
-
supportsReasoningEffort: false;
|
|
12
|
-
};
|
|
13
|
-
reasoning: false;
|
|
14
|
-
input: "text"[];
|
|
15
|
-
cost: {
|
|
16
|
-
input: number;
|
|
17
|
-
output: number;
|
|
18
|
-
cacheRead: number;
|
|
19
|
-
cacheWrite: number;
|
|
20
|
-
};
|
|
21
|
-
contextWindow: number;
|
|
22
|
-
maxTokens: number;
|
|
23
|
-
};
|
|
24
|
-
readonly "grok-3-fast": {
|
|
25
|
-
id: string;
|
|
26
|
-
name: string;
|
|
27
|
-
api: "openai-completions";
|
|
28
|
-
provider: string;
|
|
29
|
-
baseUrl: string;
|
|
30
|
-
compat: {
|
|
31
|
-
supportsStore: false;
|
|
32
|
-
supportsDeveloperRole: false;
|
|
33
|
-
supportsReasoningEffort: false;
|
|
34
|
-
};
|
|
35
|
-
reasoning: false;
|
|
36
|
-
input: "text"[];
|
|
37
|
-
cost: {
|
|
38
|
-
input: number;
|
|
39
|
-
output: number;
|
|
40
|
-
cacheRead: number;
|
|
41
|
-
cacheWrite: number;
|
|
42
|
-
};
|
|
43
|
-
contextWindow: number;
|
|
44
|
-
maxTokens: number;
|
|
45
|
-
};
|
|
46
|
-
readonly "grok-4.20-0309-non-reasoning": {
|
|
47
|
-
id: string;
|
|
48
|
-
name: string;
|
|
49
|
-
api: "openai-completions";
|
|
50
|
-
provider: string;
|
|
51
|
-
baseUrl: string;
|
|
52
|
-
compat: {
|
|
53
|
-
supportsStore: false;
|
|
54
|
-
supportsDeveloperRole: false;
|
|
55
|
-
supportsReasoningEffort: false;
|
|
56
|
-
};
|
|
57
|
-
reasoning: false;
|
|
58
|
-
input: ("image" | "text")[];
|
|
59
|
-
cost: {
|
|
60
|
-
input: number;
|
|
61
|
-
output: number;
|
|
62
|
-
cacheRead: number;
|
|
63
|
-
cacheWrite: number;
|
|
64
|
-
};
|
|
65
|
-
contextWindow: number;
|
|
66
|
-
maxTokens: number;
|
|
67
|
-
};
|
|
68
|
-
readonly "grok-4.20-0309-reasoning": {
|
|
69
|
-
id: string;
|
|
70
|
-
name: string;
|
|
71
|
-
api: "openai-completions";
|
|
72
|
-
provider: string;
|
|
73
|
-
baseUrl: string;
|
|
74
|
-
compat: {
|
|
75
|
-
supportsStore: false;
|
|
76
|
-
supportsDeveloperRole: false;
|
|
77
|
-
supportsReasoningEffort: false;
|
|
78
|
-
};
|
|
79
|
-
reasoning: true;
|
|
80
|
-
input: ("image" | "text")[];
|
|
81
|
-
cost: {
|
|
82
|
-
input: number;
|
|
83
|
-
output: number;
|
|
84
|
-
cacheRead: number;
|
|
85
|
-
cacheWrite: number;
|
|
86
|
-
};
|
|
87
|
-
contextWindow: number;
|
|
88
|
-
maxTokens: number;
|
|
89
|
-
};
|
|
90
2
|
readonly "grok-4.3": {
|
|
91
3
|
id: string;
|
|
92
4
|
name: string;
|
|
@@ -112,15 +24,17 @@ export declare const XAI_MODELS: {
|
|
|
112
24
|
readonly "grok-4.5": {
|
|
113
25
|
id: string;
|
|
114
26
|
name: string;
|
|
115
|
-
api: "openai-
|
|
27
|
+
api: "openai-responses";
|
|
116
28
|
provider: string;
|
|
117
29
|
baseUrl: string;
|
|
118
30
|
compat: {
|
|
119
|
-
|
|
120
|
-
supportsDeveloperRole: false;
|
|
121
|
-
supportsReasoningEffort: false;
|
|
31
|
+
supportsLongCacheRetention: false;
|
|
122
32
|
};
|
|
123
33
|
reasoning: true;
|
|
34
|
+
thinkingLevelMap: {
|
|
35
|
+
off: null;
|
|
36
|
+
minimal: null;
|
|
37
|
+
};
|
|
124
38
|
input: ("image" | "text")[];
|
|
125
39
|
cost: {
|
|
126
40
|
input: number;
|
|
@@ -153,27 +67,5 @@ export declare const XAI_MODELS: {
|
|
|
153
67
|
contextWindow: number;
|
|
154
68
|
maxTokens: number;
|
|
155
69
|
};
|
|
156
|
-
readonly "grok-code-fast-1": {
|
|
157
|
-
id: string;
|
|
158
|
-
name: string;
|
|
159
|
-
api: "openai-completions";
|
|
160
|
-
provider: string;
|
|
161
|
-
baseUrl: string;
|
|
162
|
-
compat: {
|
|
163
|
-
supportsStore: false;
|
|
164
|
-
supportsDeveloperRole: false;
|
|
165
|
-
supportsReasoningEffort: false;
|
|
166
|
-
};
|
|
167
|
-
reasoning: false;
|
|
168
|
-
input: "text"[];
|
|
169
|
-
cost: {
|
|
170
|
-
input: number;
|
|
171
|
-
output: number;
|
|
172
|
-
cacheRead: number;
|
|
173
|
-
cacheWrite: number;
|
|
174
|
-
};
|
|
175
|
-
contextWindow: number;
|
|
176
|
-
maxTokens: number;
|
|
177
|
-
};
|
|
178
70
|
};
|
|
179
71
|
//# sourceMappingURL=xai.models.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xai.models.d.ts","sourceRoot":"","sources":["../../src/providers/xai.models.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;YAWpB,KAAK;YACL,MAAM;YACN,SAAS;YACT,UAAU
|
|
1
|
+
{"version":3,"file":"xai.models.d.ts","sourceRoot":"","sources":["../../src/providers/xai.models.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;YAWpB,KAAK;YACL,MAAM;YACN,SAAS;YACT,UAAU;;;;;;;;;;;;;;;;YAaQ,GAAK;YAAM,OAAS;;;;YAGtC,KAAK;YACL,MAAM;YACN,SAAS;YACT,UAAU;;;;;;;;;;;;;;;;;;;YAeV,KAAK;YACL,MAAM;YACN,SAAS;YACT,UAAU;;;;;CAKH,CAAC"}
|
|
@@ -1,78 +1,6 @@
|
|
|
1
1
|
// This file is auto-generated by scripts/generate-models.ts
|
|
2
2
|
// Do not edit manually - run 'npm run generate-models' to update
|
|
3
3
|
export const XAI_MODELS = {
|
|
4
|
-
"grok-3": {
|
|
5
|
-
id: "grok-3",
|
|
6
|
-
name: "Grok 3",
|
|
7
|
-
api: "openai-completions",
|
|
8
|
-
provider: "xai",
|
|
9
|
-
baseUrl: "https://api.x.ai/v1",
|
|
10
|
-
compat: { "supportsStore": false, "supportsDeveloperRole": false, "supportsReasoningEffort": false },
|
|
11
|
-
reasoning: false,
|
|
12
|
-
input: ["text"],
|
|
13
|
-
cost: {
|
|
14
|
-
input: 3,
|
|
15
|
-
output: 15,
|
|
16
|
-
cacheRead: 0.75,
|
|
17
|
-
cacheWrite: 0,
|
|
18
|
-
},
|
|
19
|
-
contextWindow: 131072,
|
|
20
|
-
maxTokens: 8192,
|
|
21
|
-
},
|
|
22
|
-
"grok-3-fast": {
|
|
23
|
-
id: "grok-3-fast",
|
|
24
|
-
name: "Grok 3 Fast",
|
|
25
|
-
api: "openai-completions",
|
|
26
|
-
provider: "xai",
|
|
27
|
-
baseUrl: "https://api.x.ai/v1",
|
|
28
|
-
compat: { "supportsStore": false, "supportsDeveloperRole": false, "supportsReasoningEffort": false },
|
|
29
|
-
reasoning: false,
|
|
30
|
-
input: ["text"],
|
|
31
|
-
cost: {
|
|
32
|
-
input: 5,
|
|
33
|
-
output: 25,
|
|
34
|
-
cacheRead: 1.25,
|
|
35
|
-
cacheWrite: 0,
|
|
36
|
-
},
|
|
37
|
-
contextWindow: 131072,
|
|
38
|
-
maxTokens: 8192,
|
|
39
|
-
},
|
|
40
|
-
"grok-4.20-0309-non-reasoning": {
|
|
41
|
-
id: "grok-4.20-0309-non-reasoning",
|
|
42
|
-
name: "Grok 4.20 (Non-Reasoning)",
|
|
43
|
-
api: "openai-completions",
|
|
44
|
-
provider: "xai",
|
|
45
|
-
baseUrl: "https://api.x.ai/v1",
|
|
46
|
-
compat: { "supportsStore": false, "supportsDeveloperRole": false, "supportsReasoningEffort": false },
|
|
47
|
-
reasoning: false,
|
|
48
|
-
input: ["text", "image"],
|
|
49
|
-
cost: {
|
|
50
|
-
input: 1.25,
|
|
51
|
-
output: 2.5,
|
|
52
|
-
cacheRead: 0.2,
|
|
53
|
-
cacheWrite: 0,
|
|
54
|
-
},
|
|
55
|
-
contextWindow: 1000000,
|
|
56
|
-
maxTokens: 30000,
|
|
57
|
-
},
|
|
58
|
-
"grok-4.20-0309-reasoning": {
|
|
59
|
-
id: "grok-4.20-0309-reasoning",
|
|
60
|
-
name: "Grok 4.20 (Reasoning)",
|
|
61
|
-
api: "openai-completions",
|
|
62
|
-
provider: "xai",
|
|
63
|
-
baseUrl: "https://api.x.ai/v1",
|
|
64
|
-
compat: { "supportsStore": false, "supportsDeveloperRole": false, "supportsReasoningEffort": false },
|
|
65
|
-
reasoning: true,
|
|
66
|
-
input: ["text", "image"],
|
|
67
|
-
cost: {
|
|
68
|
-
input: 1.25,
|
|
69
|
-
output: 2.5,
|
|
70
|
-
cacheRead: 0.2,
|
|
71
|
-
cacheWrite: 0,
|
|
72
|
-
},
|
|
73
|
-
contextWindow: 1000000,
|
|
74
|
-
maxTokens: 30000,
|
|
75
|
-
},
|
|
76
4
|
"grok-4.3": {
|
|
77
5
|
id: "grok-4.3",
|
|
78
6
|
name: "Grok 4.3",
|
|
@@ -94,11 +22,12 @@ export const XAI_MODELS = {
|
|
|
94
22
|
"grok-4.5": {
|
|
95
23
|
id: "grok-4.5",
|
|
96
24
|
name: "Grok 4.5",
|
|
97
|
-
api: "openai-
|
|
25
|
+
api: "openai-responses",
|
|
98
26
|
provider: "xai",
|
|
99
27
|
baseUrl: "https://api.x.ai/v1",
|
|
100
|
-
compat: { "
|
|
28
|
+
compat: { "supportsLongCacheRetention": false },
|
|
101
29
|
reasoning: true,
|
|
30
|
+
thinkingLevelMap: { "off": null, "minimal": null },
|
|
102
31
|
input: ["text", "image"],
|
|
103
32
|
cost: {
|
|
104
33
|
input: 2,
|
|
@@ -127,23 +56,5 @@ export const XAI_MODELS = {
|
|
|
127
56
|
contextWindow: 256000,
|
|
128
57
|
maxTokens: 256000,
|
|
129
58
|
},
|
|
130
|
-
"grok-code-fast-1": {
|
|
131
|
-
id: "grok-code-fast-1",
|
|
132
|
-
name: "Grok Code Fast 1",
|
|
133
|
-
api: "openai-completions",
|
|
134
|
-
provider: "xai",
|
|
135
|
-
baseUrl: "https://api.x.ai/v1",
|
|
136
|
-
compat: { "supportsStore": false, "supportsDeveloperRole": false, "supportsReasoningEffort": false },
|
|
137
|
-
reasoning: false,
|
|
138
|
-
input: ["text"],
|
|
139
|
-
cost: {
|
|
140
|
-
input: 0.2,
|
|
141
|
-
output: 1.5,
|
|
142
|
-
cacheRead: 0.02,
|
|
143
|
-
cacheWrite: 0,
|
|
144
|
-
},
|
|
145
|
-
contextWindow: 32768,
|
|
146
|
-
maxTokens: 8192,
|
|
147
|
-
},
|
|
148
59
|
};
|
|
149
60
|
//# sourceMappingURL=xai.models.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xai.models.js","sourceRoot":"","sources":["../../src/providers/xai.models.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,iEAAiE;AAIjE,MAAM,CAAC,MAAM,UAA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,GAAG,EAAE,oBAAoB;QACzB,QAAQ,EAAE,KAAK;QACf,OAAO,EAAE,qBAAqB;QAC9B,MAAM,EAAE,EAAC,eAAe,EAAC,KAAK,EAAC,uBAAuB,EAAC,KAAK,EAAC,yBAAyB,EAAC,KAAK,EAAC;QAC7F,SAAS,EAAE,IAAI;QACf,KAAK,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC;QACxB,IAAI,EAAE;YACL,KAAK,EAAE,CAAC;YACR,MAAM,EAAE,CAAC;YACT,SAAS,EAAE,GAAG;YACd,UAAU,EAAE,CAAC;SACb;QACD,aAAa,EAAE,MAAM;QACrB,SAAS,EAAE,MAAM;KACqB;CAC9B,CAAC","sourcesContent":["// This file is auto-generated by scripts/generate-models.ts\n// Do not edit manually - run 'npm run generate-models' to update\n\nimport type { Model } from \"../types.ts\";\n\nexport const XAI_MODELS = {\n\t\"grok-4.3\": {\n\t\tid: \"grok-4.3\",\n\t\tname: \"Grok 4.3\",\n\t\tapi: \"openai-completions\",\n\t\tprovider: \"xai\",\n\t\tbaseUrl: \"https://api.x.ai/v1\",\n\t\tcompat: {\"supportsStore\":false,\"supportsDeveloperRole\":false,\"supportsReasoningEffort\":false},\n\t\treasoning: true,\n\t\tinput: [\"text\", \"image\"],\n\t\tcost: {\n\t\t\tinput: 1.25,\n\t\t\toutput: 2.5,\n\t\t\tcacheRead: 0.2,\n\t\t\tcacheWrite: 0,\n\t\t},\n\t\tcontextWindow: 1000000,\n\t\tmaxTokens: 30000,\n\t} satisfies Model<\"openai-completions\">,\n\t\"grok-4.5\": {\n\t\tid: \"grok-4.5\",\n\t\tname: \"Grok 4.5\",\n\t\tapi: \"openai-responses\",\n\t\tprovider: \"xai\",\n\t\tbaseUrl: \"https://api.x.ai/v1\",\n\t\tcompat: {\"supportsLongCacheRetention\":false},\n\t\treasoning: true,\n\t\tthinkingLevelMap: {\"off\":null,\"minimal\":null},\n\t\tinput: [\"text\", \"image\"],\n\t\tcost: {\n\t\t\tinput: 2,\n\t\t\toutput: 6,\n\t\t\tcacheRead: 0.5,\n\t\t\tcacheWrite: 0,\n\t\t},\n\t\tcontextWindow: 500000,\n\t\tmaxTokens: 500000,\n\t} satisfies Model<\"openai-responses\">,\n\t\"grok-build-0.1\": {\n\t\tid: \"grok-build-0.1\",\n\t\tname: \"Grok Build 0.1\",\n\t\tapi: \"openai-completions\",\n\t\tprovider: \"xai\",\n\t\tbaseUrl: \"https://api.x.ai/v1\",\n\t\tcompat: {\"supportsStore\":false,\"supportsDeveloperRole\":false,\"supportsReasoningEffort\":false},\n\t\treasoning: true,\n\t\tinput: [\"text\", \"image\"],\n\t\tcost: {\n\t\t\tinput: 1,\n\t\t\toutput: 2,\n\t\t\tcacheRead: 0.2,\n\t\t\tcacheWrite: 0,\n\t\t},\n\t\tcontextWindow: 256000,\n\t\tmaxTokens: 256000,\n\t} satisfies Model<\"openai-completions\">,\n} as const;\n"]}
|
package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/context-transformer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-transformer.d.ts","sourceRoot":"","sources":["../../src/tool-call-middleware/context-transformer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEX,OAAO,EAMP,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"context-transformer.d.ts","sourceRoot":"","sources":["../../src/tool-call-middleware/context-transformer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEX,OAAO,EAMP,MAAM,aAAa,CAAC;AAoCrB,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AA8DnE;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,cAAc,GAAG,gBAAgB,CAMpE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,gBAAgB,GAAG,OAAO,CAiBtF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { anthropicXmlFormatToolCall, anthropicXmlFormatToolResponse, anthropicXmlFormatToolsSystemPrompt, createAnthropicXmlStreamParser, parseAnthropicXmlGeneratedText, } from "./protocols/anthropic-xml/index.js";
|
|
1
2
|
import { gemma4CreateStreamParser, gemma4FormatToolCall, gemma4FormatToolResponse, gemma4FormatToolsSystemPrompt, gemma4ParseGeneratedText, } from "./protocols/gemma4.js";
|
|
2
3
|
import { hermesCreateStreamParser, hermesFormatToolCall, hermesFormatToolResponse, hermesFormatToolsSystemPrompt, hermesParseGeneratedText, } from "./protocols/hermes.js";
|
|
3
4
|
import { createMorphXmlStreamParser, morphXmlFormatToolCall, morphXmlFormatToolResponse, morphXmlFormatToolsSystemPrompt, parseMorphXmlGeneratedText, } from "./protocols/morph-xml.js";
|
|
@@ -39,10 +40,18 @@ const gemma4Protocol = {
|
|
|
39
40
|
parseGeneratedText: gemma4ParseGeneratedText,
|
|
40
41
|
createStreamParser: gemma4CreateStreamParser,
|
|
41
42
|
};
|
|
43
|
+
const anthropicXmlProtocol = {
|
|
44
|
+
formatToolsSystemPrompt: anthropicXmlFormatToolsSystemPrompt,
|
|
45
|
+
formatToolResponse: anthropicXmlFormatToolResponse,
|
|
46
|
+
formatToolCall: anthropicXmlFormatToolCall,
|
|
47
|
+
parseGeneratedText: parseAnthropicXmlGeneratedText,
|
|
48
|
+
createStreamParser: createAnthropicXmlStreamParser,
|
|
49
|
+
};
|
|
42
50
|
/**
|
|
43
51
|
* Protocol registry mapping format strings to protocol implementations.
|
|
44
52
|
*/
|
|
45
53
|
const protocolRegistry = {
|
|
54
|
+
"anthropic-xml": anthropicXmlProtocol,
|
|
46
55
|
hermes: hermesProtocol,
|
|
47
56
|
xml: morphXmlProtocol,
|
|
48
57
|
"yaml-xml": yamlXmlProtocol,
|
package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/context-transformer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-transformer.js","sourceRoot":"","sources":["../../src/tool-call-middleware/context-transformer.ts"],"names":[],"mappings":"AASA,OAAO,EACN,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,EACxB,6BAA6B,EAC7B,wBAAwB,GACxB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,EACxB,6BAA6B,EAC7B,wBAAwB,GACxB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,0BAA0B,EAC1B,sBAAsB,EACtB,0BAA0B,EAC1B,+BAA+B,EAC/B,0BAA0B,GAC1B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACN,yBAAyB,EACzB,yBAAyB,EACzB,qBAAqB,EACrB,yBAAyB,EACzB,8BAA8B,GAC9B,MAAM,yBAAyB,CAAC;AAGjC;;GAEG;AACH,MAAM,cAAc,GAAqB;IACxC,uBAAuB,EAAE,6BAA6B;IACtD,kBAAkB,EAAE,wBAAwB;IAC5C,cAAc,EAAE,oBAAoB;IACpC,kBAAkB,EAAE,wBAAwB;IAC5C,kBAAkB,EAAE,wBAAwB;CAC5C,CAAC;AAEF;;GAEG;AACH,MAAM,gBAAgB,GAAqB;IAC1C,uBAAuB,EAAE,+BAA+B;IACxD,kBAAkB,EAAE,0BAA0B;IAC9C,cAAc,EAAE,sBAAsB;IACtC,kBAAkB,EAAE,0BAA0B;IAC9C,kBAAkB,EAAE,0BAA0B;CAC9C,CAAC;AAEF,MAAM,eAAe,GAAqB;IACzC,uBAAuB,EAAE,8BAA8B;IACvD,kBAAkB,EAAE,yBAAyB;IAC7C,cAAc,EAAE,qBAAqB;IACrC,kBAAkB,EAAE,yBAAyB;IAC7C,kBAAkB,EAAE,yBAAyB;CAC7C,CAAC;AAEF;;GAEG;AACH,MAAM,cAAc,GAAqB;IACxC,uBAAuB,EAAE,6BAA6B;IACtD,kBAAkB,EAAE,wBAAwB;IAC5C,cAAc,EAAE,oBAAoB;IACpC,kBAAkB,EAA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BAClB,CAAC,CAAC;gBACH,MAAM;YACP,CAAC;QACF,CAAC;IACF,CAAC;IAED,uDAAuD;IACvD,OAAO;QACN,GAAG,OAAO;QACV,OAAO,EAAE,UAAU;KACnB,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,0BAA0B,CAAC,OAA0B,EAAE,QAA0B;IACzF,sDAAsD;IACtD,MAAM,iBAAiB,GAAG,QAAQ,CAAC,kBAAkB,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAE7G,0CAA0C;IAC1C,OAAO;QACN,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,iBAAiB;QAC1B,SAAS,EAAE,OAAO,CAAC,SAAS;KAC5B,CAAC;AACH,CAAC","sourcesContent":["import type {\n\tAssistantMessage,\n\tContext,\n\tMessage,\n\tTextContent,\n\tThinkingContent,\n\tToolResultMessage,\n\tUserMessage,\n} from \"../types.ts\";\nimport {\n\tgemma4CreateStreamParser,\n\tgemma4FormatToolCall,\n\tgemma4FormatToolResponse,\n\tgemma4FormatToolsSystemPrompt,\n\tgemma4ParseGeneratedText,\n} from \"./protocols/gemma4.ts\";\nimport {\n\thermesCreateStreamParser,\n\thermesFormatToolCall,\n\thermesFormatToolResponse,\n\thermesFormatToolsSystemPrompt,\n\thermesParseGeneratedText,\n} from \"./protocols/hermes.ts\";\nimport {\n\tcreateMorphXmlStreamParser,\n\tmorphXmlFormatToolCall,\n\tmorphXmlFormatToolResponse,\n\tmorphXmlFormatToolsSystemPrompt,\n\tparseMorphXmlGeneratedText,\n} from \"./protocols/morph-xml.ts\";\nimport {\n\tcreateYamlXmlStreamParser,\n\tparseYamlXmlGeneratedText,\n\tyamlXmlFormatToolCall,\n\tyamlXmlFormatToolResponse,\n\tyamlXmlFormatToolsSystemPrompt,\n} from \"./protocols/yaml-xml.ts\";\nimport type { ToolCallFormat, ToolCallProtocol } from \"./types.ts\";\n\n/**\n * Hermes protocol implementation for tool call formatting and parsing.\n */\nconst hermesProtocol: ToolCallProtocol = {\n\tformatToolsSystemPrompt: hermesFormatToolsSystemPrompt,\n\tformatToolResponse: hermesFormatToolResponse,\n\tformatToolCall: hermesFormatToolCall,\n\tparseGeneratedText: hermesParseGeneratedText,\n\tcreateStreamParser: hermesCreateStreamParser,\n};\n\n/**\n * MorphXml protocol implementation for tool call formatting and parsing.\n */\nconst morphXmlProtocol: ToolCallProtocol = {\n\tformatToolsSystemPrompt: morphXmlFormatToolsSystemPrompt,\n\tformatToolResponse: morphXmlFormatToolResponse,\n\tformatToolCall: morphXmlFormatToolCall,\n\tparseGeneratedText: parseMorphXmlGeneratedText,\n\tcreateStreamParser: createMorphXmlStreamParser,\n};\n\nconst yamlXmlProtocol: ToolCallProtocol = {\n\tformatToolsSystemPrompt: yamlXmlFormatToolsSystemPrompt,\n\tformatToolResponse: yamlXmlFormatToolResponse,\n\tformatToolCall: yamlXmlFormatToolCall,\n\tparseGeneratedText: parseYamlXmlGeneratedText,\n\tcreateStreamParser: createYamlXmlStreamParser,\n};\n\n/**\n * Gemma 4 protocol implementation for tool call formatting and parsing.\n */\nconst gemma4Protocol: ToolCallProtocol = {\n\tformatToolsSystemPrompt: gemma4FormatToolsSystemPrompt,\n\tformatToolResponse: gemma4FormatToolResponse,\n\tformatToolCall: gemma4FormatToolCall,\n\tparseGeneratedText: gemma4ParseGeneratedText,\n\tcreateStreamParser: gemma4CreateStreamParser,\n};\n\n/**\n * Protocol registry mapping format strings to protocol implementations.\n */\nconst protocolRegistry: Record<ToolCallFormat, ToolCallProtocol> = {\n\thermes: hermesProtocol,\n\txml: morphXmlProtocol,\n\t\"yaml-xml\": yamlXmlProtocol,\n\t\"gemma4-delimiter\": gemma4Protocol,\n};\n\n/**\n * Gets the protocol implementation for a given tool call format.\n * @param format - The tool call format\n * @returns The protocol implementation\n * @throws Error if the format is not supported\n */\nexport function getProtocol(format: ToolCallFormat): ToolCallProtocol {\n\tconst protocol = protocolRegistry[format];\n\tif (!protocol) {\n\t\tthrow new Error(`Unsupported tool call format: ${format}`);\n\t}\n\treturn protocol;\n}\n\n/**\n * Transforms a context for text-based tool calling.\n * - Strips tools from context (provider sees tool-free request)\n * - Injects tool definitions into system prompt\n * - Converts tool call messages in history to text format\n * - Converts tool result messages to user messages with text content\n *\n * @param context - The original context\n * @param protocol - The protocol to use for formatting\n * @returns A new transformed context (original is not mutated)\n */\nexport function transformContext(context: Context, protocol: ToolCallProtocol): Context {\n\t// Build new context without mutating original\n\tconst transformed: Context = {\n\t\tsystemPrompt: context.systemPrompt,\n\t\tmessages: context.messages.map((msg) => transformMessage(msg, protocol)),\n\t\ttools: undefined, // Strip tools - provider sees tool-free request\n\t};\n\n\t// Inject tool definitions into system prompt if tools exist\n\tif (context.tools && context.tools.length > 0) {\n\t\tconst toolPrompt = protocol.formatToolsSystemPrompt(context.tools);\n\t\tif (toolPrompt) {\n\t\t\ttransformed.systemPrompt = context.systemPrompt ? `${toolPrompt}\\n\\n${context.systemPrompt}` : toolPrompt;\n\t\t}\n\t}\n\n\treturn transformed;\n}\n\n/**\n * Transforms a single message for text-based tool calling.\n * - AssistantMessage with ToolCall blocks: convert to text\n * - ToolResultMessage: convert to UserMessage with text content\n * - Other messages: pass through unchanged\n */\nfunction transformMessage(message: Message, protocol: ToolCallProtocol): Message {\n\tswitch (message.role) {\n\t\tcase \"assistant\": {\n\t\t\treturn transformAssistantMessage(message, protocol);\n\t\t}\n\t\tcase \"toolResult\": {\n\t\t\treturn transformToolResultMessage(message, protocol);\n\t\t}\n\t\tdefault: {\n\t\t\treturn message;\n\t\t}\n\t}\n}\n\n/**\n * Transforms an AssistantMessage, converting ToolCall content blocks to text.\n */\nfunction transformAssistantMessage(message: AssistantMessage, protocol: ToolCallProtocol): AssistantMessage {\n\t// Check if message has any ToolCall content blocks\n\tconst hasToolCalls = message.content.some((block) => block.type === \"toolCall\");\n\tif (!hasToolCalls) {\n\t\t// No tool calls - pass through unchanged\n\t\treturn message;\n\t}\n\n\t// Transform content blocks\n\tconst newContent: (TextContent | ThinkingContent)[] = [];\n\n\tfor (const block of message.content) {\n\t\tswitch (block.type) {\n\t\t\tcase \"text\": {\n\t\t\t\tnewContent.push(block);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"thinking\": {\n\t\t\t\tnewContent.push(block);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"toolCall\": {\n\t\t\t\tconst toolCallText = protocol.formatToolCall(block.name, block.arguments);\n\t\t\t\tnewContent.push({\n\t\t\t\t\ttype: \"text\",\n\t\t\t\t\ttext: toolCallText,\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\t// Return new AssistantMessage with transformed content\n\treturn {\n\t\t...message,\n\t\tcontent: newContent,\n\t};\n}\n\n/**\n * Transforms a ToolResultMessage to a UserMessage with text content.\n */\nfunction transformToolResultMessage(message: ToolResultMessage, protocol: ToolCallProtocol): UserMessage {\n\t// Format tool result as text using protocol formatter\n\tconst formattedResponse = protocol.formatToolResponse(message.toolName, message.toolCallId, message.content);\n\n\t// Return as UserMessage with text content\n\treturn {\n\t\trole: \"user\",\n\t\tcontent: formattedResponse,\n\t\ttimestamp: message.timestamp,\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"context-transformer.js","sourceRoot":"","sources":["../../src/tool-call-middleware/context-transformer.ts"],"names":[],"mappings":"AASA,OAAO,EACN,0BAA0B,EAC1B,8BAA8B,EAC9B,mCAAmC,EACnC,8BAA8B,EAC9B,8BAA8B,GAC9B,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACN,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,EACxB,6BAA6B,EAC7B,wBAAwB,GACxB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,EACxB,6BAA6B,EAC7B,wBAAwB,GACxB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,0BA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,OAAO;QACV,OAAO,EAAE,UAAU;KACnB,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,0BAA0B,CAAC,OAA0B,EAAE,QAA0B;IACzF,sDAAsD;IACtD,MAAM,iBAAiB,GAAG,QAAQ,CAAC,kBAAkB,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAE7G,0CAA0C;IAC1C,OAAO;QACN,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,iBAAiB;QAC1B,SAAS,EAAE,OAAO,CAAC,SAAS;KAC5B,CAAC;AACH,CAAC","sourcesContent":["import type {\n\tAssistantMessage,\n\tContext,\n\tMessage,\n\tTextContent,\n\tThinkingContent,\n\tToolResultMessage,\n\tUserMessage,\n} from \"../types.ts\";\nimport {\n\tanthropicXmlFormatToolCall,\n\tanthropicXmlFormatToolResponse,\n\tanthropicXmlFormatToolsSystemPrompt,\n\tcreateAnthropicXmlStreamParser,\n\tparseAnthropicXmlGeneratedText,\n} from \"./protocols/anthropic-xml/index.ts\";\nimport {\n\tgemma4CreateStreamParser,\n\tgemma4FormatToolCall,\n\tgemma4FormatToolResponse,\n\tgemma4FormatToolsSystemPrompt,\n\tgemma4ParseGeneratedText,\n} from \"./protocols/gemma4.ts\";\nimport {\n\thermesCreateStreamParser,\n\thermesFormatToolCall,\n\thermesFormatToolResponse,\n\thermesFormatToolsSystemPrompt,\n\thermesParseGeneratedText,\n} from \"./protocols/hermes.ts\";\nimport {\n\tcreateMorphXmlStreamParser,\n\tmorphXmlFormatToolCall,\n\tmorphXmlFormatToolResponse,\n\tmorphXmlFormatToolsSystemPrompt,\n\tparseMorphXmlGeneratedText,\n} from \"./protocols/morph-xml.ts\";\nimport {\n\tcreateYamlXmlStreamParser,\n\tparseYamlXmlGeneratedText,\n\tyamlXmlFormatToolCall,\n\tyamlXmlFormatToolResponse,\n\tyamlXmlFormatToolsSystemPrompt,\n} from \"./protocols/yaml-xml.ts\";\nimport type { ToolCallFormat, ToolCallProtocol } from \"./types.ts\";\n\n/**\n * Hermes protocol implementation for tool call formatting and parsing.\n */\nconst hermesProtocol: ToolCallProtocol = {\n\tformatToolsSystemPrompt: hermesFormatToolsSystemPrompt,\n\tformatToolResponse: hermesFormatToolResponse,\n\tformatToolCall: hermesFormatToolCall,\n\tparseGeneratedText: hermesParseGeneratedText,\n\tcreateStreamParser: hermesCreateStreamParser,\n};\n\n/**\n * MorphXml protocol implementation for tool call formatting and parsing.\n */\nconst morphXmlProtocol: ToolCallProtocol = {\n\tformatToolsSystemPrompt: morphXmlFormatToolsSystemPrompt,\n\tformatToolResponse: morphXmlFormatToolResponse,\n\tformatToolCall: morphXmlFormatToolCall,\n\tparseGeneratedText: parseMorphXmlGeneratedText,\n\tcreateStreamParser: createMorphXmlStreamParser,\n};\n\nconst yamlXmlProtocol: ToolCallProtocol = {\n\tformatToolsSystemPrompt: yamlXmlFormatToolsSystemPrompt,\n\tformatToolResponse: yamlXmlFormatToolResponse,\n\tformatToolCall: yamlXmlFormatToolCall,\n\tparseGeneratedText: parseYamlXmlGeneratedText,\n\tcreateStreamParser: createYamlXmlStreamParser,\n};\n\n/**\n * Gemma 4 protocol implementation for tool call formatting and parsing.\n */\nconst gemma4Protocol: ToolCallProtocol = {\n\tformatToolsSystemPrompt: gemma4FormatToolsSystemPrompt,\n\tformatToolResponse: gemma4FormatToolResponse,\n\tformatToolCall: gemma4FormatToolCall,\n\tparseGeneratedText: gemma4ParseGeneratedText,\n\tcreateStreamParser: gemma4CreateStreamParser,\n};\n\nconst anthropicXmlProtocol: ToolCallProtocol = {\n\tformatToolsSystemPrompt: anthropicXmlFormatToolsSystemPrompt,\n\tformatToolResponse: anthropicXmlFormatToolResponse,\n\tformatToolCall: anthropicXmlFormatToolCall,\n\tparseGeneratedText: parseAnthropicXmlGeneratedText,\n\tcreateStreamParser: createAnthropicXmlStreamParser,\n};\n\n/**\n * Protocol registry mapping format strings to protocol implementations.\n */\nconst protocolRegistry: Record<ToolCallFormat, ToolCallProtocol> = {\n\t\"anthropic-xml\": anthropicXmlProtocol,\n\thermes: hermesProtocol,\n\txml: morphXmlProtocol,\n\t\"yaml-xml\": yamlXmlProtocol,\n\t\"gemma4-delimiter\": gemma4Protocol,\n};\n\n/**\n * Gets the protocol implementation for a given tool call format.\n * @param format - The tool call format\n * @returns The protocol implementation\n * @throws Error if the format is not supported\n */\nexport function getProtocol(format: ToolCallFormat): ToolCallProtocol {\n\tconst protocol = protocolRegistry[format];\n\tif (!protocol) {\n\t\tthrow new Error(`Unsupported tool call format: ${format}`);\n\t}\n\treturn protocol;\n}\n\n/**\n * Transforms a context for text-based tool calling.\n * - Strips tools from context (provider sees tool-free request)\n * - Injects tool definitions into system prompt\n * - Converts tool call messages in history to text format\n * - Converts tool result messages to user messages with text content\n *\n * @param context - The original context\n * @param protocol - The protocol to use for formatting\n * @returns A new transformed context (original is not mutated)\n */\nexport function transformContext(context: Context, protocol: ToolCallProtocol): Context {\n\t// Build new context without mutating original\n\tconst transformed: Context = {\n\t\tsystemPrompt: context.systemPrompt,\n\t\tmessages: context.messages.map((msg) => transformMessage(msg, protocol)),\n\t\ttools: undefined, // Strip tools - provider sees tool-free request\n\t};\n\n\t// Inject tool definitions into system prompt if tools exist\n\tif (context.tools && context.tools.length > 0) {\n\t\tconst toolPrompt = protocol.formatToolsSystemPrompt(context.tools);\n\t\tif (toolPrompt) {\n\t\t\ttransformed.systemPrompt = context.systemPrompt ? `${toolPrompt}\\n\\n${context.systemPrompt}` : toolPrompt;\n\t\t}\n\t}\n\n\treturn transformed;\n}\n\n/**\n * Transforms a single message for text-based tool calling.\n * - AssistantMessage with ToolCall blocks: convert to text\n * - ToolResultMessage: convert to UserMessage with text content\n * - Other messages: pass through unchanged\n */\nfunction transformMessage(message: Message, protocol: ToolCallProtocol): Message {\n\tswitch (message.role) {\n\t\tcase \"assistant\": {\n\t\t\treturn transformAssistantMessage(message, protocol);\n\t\t}\n\t\tcase \"toolResult\": {\n\t\t\treturn transformToolResultMessage(message, protocol);\n\t\t}\n\t\tdefault: {\n\t\t\treturn message;\n\t\t}\n\t}\n}\n\n/**\n * Transforms an AssistantMessage, converting ToolCall content blocks to text.\n */\nfunction transformAssistantMessage(message: AssistantMessage, protocol: ToolCallProtocol): AssistantMessage {\n\t// Check if message has any ToolCall content blocks\n\tconst hasToolCalls = message.content.some((block) => block.type === \"toolCall\");\n\tif (!hasToolCalls) {\n\t\t// No tool calls - pass through unchanged\n\t\treturn message;\n\t}\n\n\t// Transform content blocks\n\tconst newContent: (TextContent | ThinkingContent)[] = [];\n\n\tfor (const block of message.content) {\n\t\tswitch (block.type) {\n\t\t\tcase \"text\": {\n\t\t\t\tnewContent.push(block);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"thinking\": {\n\t\t\t\tnewContent.push(block);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"toolCall\": {\n\t\t\t\tconst toolCallText = protocol.formatToolCall(block.name, block.arguments);\n\t\t\t\tnewContent.push({\n\t\t\t\t\ttype: \"text\",\n\t\t\t\t\ttext: toolCallText,\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\t// Return new AssistantMessage with transformed content\n\treturn {\n\t\t...message,\n\t\tcontent: newContent,\n\t};\n}\n\n/**\n * Transforms a ToolResultMessage to a UserMessage with text content.\n */\nfunction transformToolResultMessage(message: ToolResultMessage, protocol: ToolCallProtocol): UserMessage {\n\t// Format tool result as text using protocol formatter\n\tconst formattedResponse = protocol.formatToolResponse(message.toolName, message.toolCallId, message.content);\n\n\t// Return as UserMessage with text content\n\treturn {\n\t\trole: \"user\",\n\t\tcontent: formattedResponse,\n\t\ttimestamp: message.timestamp,\n\t};\n}\n"]}
|
|
@@ -7,7 +7,7 @@ export type { ParsedToolCall, StreamParser, StreamParserEvent, ToolCallFormat, T
|
|
|
7
7
|
* Extracts the tool call format from a model's compatibility settings.
|
|
8
8
|
* Only applies to models using the "openai-completions" API with compat settings.
|
|
9
9
|
* @param model - The model to check
|
|
10
|
-
* @returns The tool call format
|
|
10
|
+
* @returns The configured supported tool call format, or undefined if not set
|
|
11
11
|
*/
|
|
12
12
|
export declare function getToolCallFormat<TApi extends Api>(model: Model<TApi>): ToolCallFormat | undefined;
|
|
13
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tool-call-middleware/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAA2B,MAAM,aAAa,CAAC;AACvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,EAAE,gCAAgC,EAAE,MAAM,qBAAqB,CAAC;AACvE,YAAY,EACX,cAAc,EACd,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,iBAAiB,GACjB,MAAM,YAAY,CAAC;AAEpB;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,SAAS,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,cAAc,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tool-call-middleware/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAA2B,MAAM,aAAa,CAAC;AACvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,EAAE,gCAAgC,EAAE,MAAM,qBAAqB,CAAC;AACvE,YAAY,EACX,cAAc,EACd,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,iBAAiB,GACjB,MAAM,YAAY,CAAC;AAEpB;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,SAAS,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,cAAc,GAAG,SAAS,CAmBlG"}
|
|
@@ -4,7 +4,7 @@ export { wrapStreamWithToolCallMiddleware } from "./stream-wrapper.js";
|
|
|
4
4
|
* Extracts the tool call format from a model's compatibility settings.
|
|
5
5
|
* Only applies to models using the "openai-completions" API with compat settings.
|
|
6
6
|
* @param model - The model to check
|
|
7
|
-
* @returns The tool call format
|
|
7
|
+
* @returns The configured supported tool call format, or undefined if not set
|
|
8
8
|
*/
|
|
9
9
|
export function getToolCallFormat(model) {
|
|
10
10
|
if (model.api !== "openai-completions") {
|
|
@@ -15,7 +15,11 @@ export function getToolCallFormat(model) {
|
|
|
15
15
|
if (!format) {
|
|
16
16
|
return undefined;
|
|
17
17
|
}
|
|
18
|
-
if (format === "hermes" ||
|
|
18
|
+
if (format === "hermes" ||
|
|
19
|
+
format === "xml" ||
|
|
20
|
+
format === "yaml-xml" ||
|
|
21
|
+
format === "gemma4-delimiter" ||
|
|
22
|
+
format === "anthropic-xml") {
|
|
19
23
|
return format;
|
|
20
24
|
}
|
|
21
25
|
return undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tool-call-middleware/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,EAAE,gCAAgC,EAAE,MAAM,qBAAqB,CAAC;AAUvE;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAmB,KAAkB;IACrE,IAAI,KAAK,CAAC,GAAG,KAAK,oBAAoB,EAAE,CAAC;QACxC,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,MAAM,MAAM,GAAG,KAAK,CAAC,MAA6C,CAAC;IACnE,MAAM,MAAM,GAAG,MAAM,EAAE,cAAc,CAAC;IACtC,IAAI,CAAC,MAAM,EAAE,CAAC;QACb,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tool-call-middleware/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,EAAE,gCAAgC,EAAE,MAAM,qBAAqB,CAAC;AAUvE;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAmB,KAAkB;IACrE,IAAI,KAAK,CAAC,GAAG,KAAK,oBAAoB,EAAE,CAAC;QACxC,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,MAAM,MAAM,GAAG,KAAK,CAAC,MAA6C,CAAC;IACnE,MAAM,MAAM,GAAG,MAAM,EAAE,cAAc,CAAC;IACtC,IAAI,CAAC,MAAM,EAAE,CAAC;QACb,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,IACC,MAAM,KAAK,QAAQ;QACnB,MAAM,KAAK,KAAK;QAChB,MAAM,KAAK,UAAU;QACrB,MAAM,KAAK,kBAAkB;QAC7B,MAAM,KAAK,eAAe,EACzB,CAAC;QACF,OAAO,MAAM,CAAC;IACf,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC","sourcesContent":["import type { Api, Model, OpenAICompletionsCompat } from \"../types.ts\";\nimport type { ToolCallFormat } from \"./types.ts\";\n\nexport { getProtocol, transformContext } from \"./context-transformer.ts\";\nexport { wrapStreamWithToolCallMiddleware } from \"./stream-wrapper.ts\";\nexport type {\n\tParsedToolCall,\n\tStreamParser,\n\tStreamParserEvent,\n\tToolCallFormat,\n\tToolCallProtocol,\n\tToolResultContent,\n} from \"./types.ts\";\n\n/**\n * Extracts the tool call format from a model's compatibility settings.\n * Only applies to models using the \"openai-completions\" API with compat settings.\n * @param model - The model to check\n * @returns The configured supported tool call format, or undefined if not set\n */\nexport function getToolCallFormat<TApi extends Api>(model: Model<TApi>): ToolCallFormat | undefined {\n\tif (model.api !== \"openai-completions\") {\n\t\treturn undefined;\n\t}\n\tconst compat = model.compat as OpenAICompletionsCompat | undefined;\n\tconst format = compat?.toolCallFormat;\n\tif (!format) {\n\t\treturn undefined;\n\t}\n\tif (\n\t\tformat === \"hermes\" ||\n\t\tformat === \"xml\" ||\n\t\tformat === \"yaml-xml\" ||\n\t\tformat === \"gemma4-delimiter\" ||\n\t\tformat === \"anthropic-xml\"\n\t) {\n\t\treturn format;\n\t}\n\treturn undefined;\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Tool } from "../../../types.ts";
|
|
2
|
+
type RawParameter = {
|
|
3
|
+
readonly name: string;
|
|
4
|
+
readonly rawValue: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function coerceParameters(rawParams: readonly RawParameter[], tool: Tool): Record<string, unknown> | null;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=coerce-parameters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coerce-parameters.d.ts","sourceRoot":"","sources":["../../../../src/tool-call-middleware/protocols/anthropic-xml/coerce-parameters.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAG9C,KAAK,YAAY,GAAG;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC1B,CAAC;AAYF,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,SAAS,YAAY,EAAE,EAAE,IAAI,EAAE,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CA6B/G"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { IsArray, IsBoolean, IsInteger, IsNumber, IsObject, IsString } from "typebox";
|
|
2
|
+
import { Value } from "typebox/value";
|
|
3
|
+
import { decodeXmlEntities } from "./xml-entities.js";
|
|
4
|
+
const INVALID = { ok: false };
|
|
5
|
+
const LEADING_RAW_NEWLINE = /^(?:\r\n|\r|\n)/;
|
|
6
|
+
const TRAILING_RAW_NEWLINE = /(?:\r\n|\r|\n)$/;
|
|
7
|
+
function trimRawBoundaryNewlines(value) {
|
|
8
|
+
return value.replace(LEADING_RAW_NEWLINE, "").replace(TRAILING_RAW_NEWLINE, "");
|
|
9
|
+
}
|
|
10
|
+
export function coerceParameters(rawParams, tool) {
|
|
11
|
+
if (!IsObject(tool.parameters)) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
const argumentsRecord = {};
|
|
15
|
+
for (const rawParam of rawParams) {
|
|
16
|
+
if (Object.hasOwn(argumentsRecord, rawParam.name)) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
const propertySchema = tool.parameters.properties[rawParam.name];
|
|
20
|
+
const rawValue = trimRawBoundaryNewlines(rawParam.rawValue);
|
|
21
|
+
const result = propertySchema
|
|
22
|
+
? coerceKnownValue(rawValue, propertySchema)
|
|
23
|
+
: { ok: true, value: coerceUnknownValue(rawValue) };
|
|
24
|
+
if (!result.ok) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
Object.defineProperty(argumentsRecord, rawParam.name, {
|
|
28
|
+
configurable: true,
|
|
29
|
+
enumerable: true,
|
|
30
|
+
value: result.value,
|
|
31
|
+
writable: true,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return passesToolValidation(tool, argumentsRecord) ? argumentsRecord : null;
|
|
35
|
+
}
|
|
36
|
+
function coerceKnownValue(rawValue, schema) {
|
|
37
|
+
const value = decodeXmlEntities(rawValue);
|
|
38
|
+
if (IsString(schema)) {
|
|
39
|
+
return { ok: true, value };
|
|
40
|
+
}
|
|
41
|
+
if (IsNumber(schema) || IsInteger(schema)) {
|
|
42
|
+
if (value.trim().length === 0) {
|
|
43
|
+
return INVALID;
|
|
44
|
+
}
|
|
45
|
+
const parsed = Number(value);
|
|
46
|
+
if (!Number.isFinite(parsed) || (IsInteger(schema) && !Number.isInteger(parsed))) {
|
|
47
|
+
return INVALID;
|
|
48
|
+
}
|
|
49
|
+
return { ok: true, value: parsed };
|
|
50
|
+
}
|
|
51
|
+
if (IsBoolean(schema)) {
|
|
52
|
+
if (value === "true") {
|
|
53
|
+
return { ok: true, value: true };
|
|
54
|
+
}
|
|
55
|
+
if (value === "false") {
|
|
56
|
+
return { ok: true, value: false };
|
|
57
|
+
}
|
|
58
|
+
return INVALID;
|
|
59
|
+
}
|
|
60
|
+
if (IsArray(schema)) {
|
|
61
|
+
const parsed = tryParseJson(value);
|
|
62
|
+
return parsed.ok && Array.isArray(parsed.value) ? parsed : INVALID;
|
|
63
|
+
}
|
|
64
|
+
if (IsObject(schema)) {
|
|
65
|
+
const parsed = tryParseJson(value);
|
|
66
|
+
return parsed.ok && isJsonObject(parsed.value) ? parsed : INVALID;
|
|
67
|
+
}
|
|
68
|
+
return { ok: true, value: coerceUnknownValue(rawValue) };
|
|
69
|
+
}
|
|
70
|
+
function coerceUnknownValue(rawValue) {
|
|
71
|
+
const value = decodeXmlEntities(rawValue);
|
|
72
|
+
const parsed = tryParseJson(value);
|
|
73
|
+
return parsed.ok ? parsed.value : value;
|
|
74
|
+
}
|
|
75
|
+
function tryParseJson(value) {
|
|
76
|
+
try {
|
|
77
|
+
return { ok: true, value: JSON.parse(value) };
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
if (error instanceof SyntaxError) {
|
|
81
|
+
return INVALID;
|
|
82
|
+
}
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function isJsonObject(value) {
|
|
87
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
88
|
+
}
|
|
89
|
+
function passesToolValidation(tool, argumentsRecord) {
|
|
90
|
+
return Value.Check(tool.parameters, argumentsRecord);
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=coerce-parameters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coerce-parameters.js","sourceRoot":"","sources":["../../../../src/tool-call-middleware/protocols/anthropic-xml/coerce-parameters.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACtF,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAStD,MAAM,OAAO,GAAmB,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC;AAC9C,MAAM,mBAAmB,GAAG,iBAAiB,CAAC;AAC9C,MAAM,oBAAoB,GAAG,iBAAiB,CAAC;AAE/C,SAAS,uBAAuB,CAAC,KAAa;IAC7C,OAAO,KAAK,CAAC,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,oBAAoB,EAAE,EAAE,CAAC,CAAC;AACjF,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,SAAkC,EAAE,IAAU;IAC9E,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;QAChC,OAAO,IAAI,CAAC;IACb,CAAC;IAED,MAAM,eAAe,GAA4B,EAAE,CAAC;IACpD,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QAClC,IAAI,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YACnD,OAAO,IAAI,CAAC;QACb,CAAC;QAED,MAAM,cAAc,GAAG,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACjE,MAAM,QAAQ,GAAG,uBAAuB,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAC5D,MAAM,MAAM,GAAG,cAAc;YAC5B,CAAC,CAA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AAC;AACzC,CAAC;AAED,SAAS,YAAY,CAAC,KAAa;IAClC,IAAI,CAAC;QACJ,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;IAC/C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;YAClC,OAAO,OAAO,CAAC;QAChB,CAAC;QACD,MAAM,KAAK,CAAC;IACb,CAAC;AACF,CAAC;AAED,SAAS,YAAY,CAAC,KAAc;IACnC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC7E,CAAC;AAED,SAAS,oBAAoB,CAAC,IAAU,EAAE,eAAwC;IACjF,OAAO,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC;AACtD,CAAC","sourcesContent":["import type { TSchema } from \"typebox\";\nimport { IsArray, IsBoolean, IsInteger, IsNumber, IsObject, IsString } from \"typebox\";\nimport { Value } from \"typebox/value\";\nimport type { Tool } from \"../../../types.ts\";\nimport { decodeXmlEntities } from \"./xml-entities.ts\";\n\ntype RawParameter = {\n\treadonly name: string;\n\treadonly rawValue: string;\n};\n\ntype CoercionResult = { readonly ok: true; readonly value: unknown } | { readonly ok: false };\n\nconst INVALID: CoercionResult = { ok: false };\nconst LEADING_RAW_NEWLINE = /^(?:\\r\\n|\\r|\\n)/;\nconst TRAILING_RAW_NEWLINE = /(?:\\r\\n|\\r|\\n)$/;\n\nfunction trimRawBoundaryNewlines(value: string): string {\n\treturn value.replace(LEADING_RAW_NEWLINE, \"\").replace(TRAILING_RAW_NEWLINE, \"\");\n}\n\nexport function coerceParameters(rawParams: readonly RawParameter[], tool: Tool): Record<string, unknown> | null {\n\tif (!IsObject(tool.parameters)) {\n\t\treturn null;\n\t}\n\n\tconst argumentsRecord: Record<string, unknown> = {};\n\tfor (const rawParam of rawParams) {\n\t\tif (Object.hasOwn(argumentsRecord, rawParam.name)) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst propertySchema = tool.parameters.properties[rawParam.name];\n\t\tconst rawValue = trimRawBoundaryNewlines(rawParam.rawValue);\n\t\tconst result = propertySchema\n\t\t\t? coerceKnownValue(rawValue, propertySchema)\n\t\t\t: { ok: true, value: coerceUnknownValue(rawValue) };\n\t\tif (!result.ok) {\n\t\t\treturn null;\n\t\t}\n\n\t\tObject.defineProperty(argumentsRecord, rawParam.name, {\n\t\t\tconfigurable: true,\n\t\t\tenumerable: true,\n\t\t\tvalue: result.value,\n\t\t\twritable: true,\n\t\t});\n\t}\n\n\treturn passesToolValidation(tool, argumentsRecord) ? argumentsRecord : null;\n}\n\nfunction coerceKnownValue(rawValue: string, schema: TSchema): CoercionResult {\n\tconst value = decodeXmlEntities(rawValue);\n\n\tif (IsString(schema)) {\n\t\treturn { ok: true, value };\n\t}\n\n\tif (IsNumber(schema) || IsInteger(schema)) {\n\t\tif (value.trim().length === 0) {\n\t\t\treturn INVALID;\n\t\t}\n\t\tconst parsed = Number(value);\n\t\tif (!Number.isFinite(parsed) || (IsInteger(schema) && !Number.isInteger(parsed))) {\n\t\t\treturn INVALID;\n\t\t}\n\t\treturn { ok: true, value: parsed };\n\t}\n\n\tif (IsBoolean(schema)) {\n\t\tif (value === \"true\") {\n\t\t\treturn { ok: true, value: true };\n\t\t}\n\t\tif (value === \"false\") {\n\t\t\treturn { ok: true, value: false };\n\t\t}\n\t\treturn INVALID;\n\t}\n\n\tif (IsArray(schema)) {\n\t\tconst parsed = tryParseJson(value);\n\t\treturn parsed.ok && Array.isArray(parsed.value) ? parsed : INVALID;\n\t}\n\n\tif (IsObject(schema)) {\n\t\tconst parsed = tryParseJson(value);\n\t\treturn parsed.ok && isJsonObject(parsed.value) ? parsed : INVALID;\n\t}\n\n\treturn { ok: true, value: coerceUnknownValue(rawValue) };\n}\n\nfunction coerceUnknownValue(rawValue: string): unknown {\n\tconst value = decodeXmlEntities(rawValue);\n\tconst parsed = tryParseJson(value);\n\treturn parsed.ok ? parsed.value : value;\n}\n\nfunction tryParseJson(value: string): CoercionResult {\n\ttry {\n\t\treturn { ok: true, value: JSON.parse(value) };\n\t} catch (error) {\n\t\tif (error instanceof SyntaxError) {\n\t\t\treturn INVALID;\n\t\t}\n\t\tthrow error;\n\t}\n}\n\nfunction isJsonObject(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction passesToolValidation(tool: Tool, argumentsRecord: Record<string, unknown>): boolean {\n\treturn Value.Check(tool.parameters, argumentsRecord);\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Tool } from "../../../types.ts";
|
|
2
|
+
import type { ToolResultContent } from "../../types.ts";
|
|
3
|
+
export declare function anthropicXmlFormatToolsSystemPrompt(tools: Tool[]): string;
|
|
4
|
+
export declare function anthropicXmlFormatToolCall(name: string, args: Record<string, unknown>): string;
|
|
5
|
+
export declare function anthropicXmlFormatToolResponse(toolName: string, _toolCallId: string, content: ToolResultContent[]): string;
|
|
6
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../../../src/tool-call-middleware/protocols/anthropic-xml/format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAuBxD,wBAAgB,mCAAmC,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,MAAM,CAoBzE;AAED,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAO9F;AAED,wBAAgB,8BAA8B,CAC7C,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,iBAAiB,EAAE,GAC1B,MAAM,CAcR"}
|