@bastani/atomic 0.9.74 → 0.9.75
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 +136 -0
- package/dist/builtin/intercom/package.json +2 -2
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/CHANGELOG.md +21 -0
- package/dist/builtin/subagents/package.json +3 -3
- package/dist/builtin/subagents/skills/agent-browser/SKILL.md +8 -10
- package/dist/builtin/subagents/skills/agent-desktop/SKILL.md +9 -5
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +7 -1
- package/dist/builtin/web-access/package.json +2 -2
- package/dist/builtin/workflows/CHANGELOG.md +64 -0
- package/dist/builtin/workflows/README.md +5 -2
- package/dist/builtin/workflows/builtin/{chunk-m8eg152f.js → chunk-89we7r4p.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-a4fdm2cw.js → chunk-8yfssw01.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-774myqzs.js → chunk-v8mb0005.js} +366 -45
- package/dist/builtin/workflows/builtin/{chunk-d5cxskkp.js → chunk-wh2p4qjg.js} +2 -2
- package/dist/builtin/workflows/builtin/goal.js +2 -2
- package/dist/builtin/workflows/builtin/index.d.ts +10 -0
- package/dist/builtin/workflows/builtin/index.js +4 -4
- package/dist/builtin/workflows/builtin/open-claude-design.d.ts +12 -0
- package/dist/builtin/workflows/builtin/open-claude-design.js +1 -1
- package/dist/builtin/workflows/builtin/ralph.js +2 -2
- package/dist/builtin/workflows/package.json +2 -2
- package/dist/builtin/workflows/skills/impeccable/SKILL.md +4 -4
- package/dist/builtin/workflows/skills/impeccable/reference/android.md +1 -1
- package/dist/builtin/workflows/skills/impeccable/reference/audit.md +2 -2
- package/dist/builtin/workflows/skills/impeccable/reference/craft-floor.md +1 -1
- package/dist/builtin/workflows/skills/impeccable/reference/degraded/asset-producer.md +1 -1
- package/dist/builtin/workflows/skills/impeccable/reference/degraded/documenter.md +4 -4
- package/dist/builtin/workflows/skills/impeccable/reference/degraded/finish-reviewer.md +2 -2
- package/dist/builtin/workflows/skills/impeccable/reference/degraded/manual-edit-applier.md +3 -2
- package/dist/builtin/workflows/skills/impeccable/reference/distill.md +3 -3
- package/dist/builtin/workflows/skills/impeccable/reference/doctor.md +1 -1
- package/dist/builtin/workflows/skills/impeccable/reference/document.md +3 -3
- package/dist/builtin/workflows/skills/impeccable/reference/harden.md +19 -0
- package/dist/builtin/workflows/skills/impeccable/reference/hooks.md +15 -8
- package/dist/builtin/workflows/skills/impeccable/reference/init.md +2 -0
- package/dist/builtin/workflows/skills/impeccable/reference/live.md +8 -6
- package/dist/builtin/workflows/skills/impeccable/reference/new-work.md +4 -4
- package/dist/builtin/workflows/skills/impeccable/reference/optimize.md +0 -1
- package/dist/builtin/workflows/skills/impeccable/reference/visualize.md +1 -1
- package/dist/builtin/workflows/skills/impeccable/scripts/VERSION +1 -1
- package/dist/builtin/workflows/skills/impeccable/scripts/command-metadata.json +2 -2
- package/dist/builtin/workflows/skills/impeccable/scripts/engine-checksums.txt +9 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/impeccable +98 -44
- package/dist/builtin/workflows/skills/impeccable/scripts/impeccable.cmd +101 -34
- package/dist/builtin/workflows/skills/impeccable/scripts/live-browser-ignores.js +6 -2
- package/dist/builtin/workflows/skills/impeccable/scripts/live-browser-session.js +4 -1
- package/dist/builtin/workflows/skills/impeccable/scripts/live-browser.js +444 -144
- package/dist/builtin/workflows/skills/prompt-engineer/SKILL.md +3 -1
- package/dist/builtin/workflows/skills/prompt-engineer/references/advanced_patterns.md +2 -2
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_fable_5.md +13 -11
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_fable_5_1.md +10 -8
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_fable_5_2.md +143 -0
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_haiku_5_5.md +11 -7
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_opus_4_8.md +3 -3
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_opus_5.md +6 -2
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_opus_5_5.md +7 -7
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_sonnet_5.md +2 -2
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_sonnet_5_5.md +3 -3
- package/dist/builtin/workflows/skills/prompt-engineer/references/gpt_5_5.md +2 -2
- package/dist/builtin/workflows/skills/prompt-engineer/references/gpt_5_6.md +2 -2
- package/dist/builtin/workflows/skills/prompt-engineer/references/gpt_6.md +6 -5
- package/dist/builtin/workflows/skills/prompt-engineer/references/gpt_6_1_sol.md +4 -4
- package/dist/builtin/workflows/skills/prompt-engineer/references/gpt_6_1_terra.md +2 -2
- package/dist/builtin/workflows/skills/prompt-engineer/references/quality_improvement.md +4 -3
- package/dist/builtin/workflows/skills/skill-creator/scripts/aggregate_benchmark.py +0 -0
- package/dist/builtin/workflows/skills/skill-creator/scripts/generate_report.py +0 -0
- package/dist/builtin/workflows/skills/skill-creator/scripts/improve_description.py +0 -0
- package/dist/builtin/workflows/skills/skill-creator/scripts/package_skill.py +0 -0
- package/dist/builtin/workflows/skills/skill-creator/scripts/quick_validate.py +0 -0
- package/dist/builtin/workflows/skills/skill-creator/scripts/run_eval.py +0 -0
- package/dist/builtin/workflows/skills/skill-creator/scripts/run_loop.py +0 -0
- package/dist/builtin/workflows/skills/unslop/SKILL.md +15 -34
- package/dist/builtin/workflows/src/durable/journal/memory-run-journal.d.ts +1 -0
- package/dist/builtin/workflows/src/durable/journal/values.d.ts +2 -0
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +809 -410
- package/dist/builtin/workflows/src/extension/local-worker-entry.mjs +695 -305
- package/dist/builtin/workflows/src/index.js +685 -295
- package/dist/builtin/workflows/src/local-worker-entry.mjs +695 -305
- package/dist/builtin/workflows/src/shared/authoring-contract-stage.d.ts +6 -6
- package/dist/builtin/workflows/src/shared/authoring-contract-ui.d.ts +2 -2
- package/dist/builtin/workflows/src/shared/serializable-error-families.d.ts +2 -0
- package/dist/bun/app-host-modules.d.ts +1 -1
- package/dist/bun/app-host-modules.d.ts.map +1 -1
- package/dist/bun/app-host-modules.js.map +1 -1
- package/dist/bun/internal-workflow-worker.d.ts +2 -0
- package/dist/bun/internal-workflow-worker.d.ts.map +1 -1
- package/dist/bun/internal-workflow-worker.js +2 -1
- package/dist/bun/internal-workflow-worker.js.map +1 -1
- package/dist/codemode-worker.js +2 -0
- package/dist/config.d.ts +8 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +14 -0
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-bash.d.ts.map +1 -1
- package/dist/core/agent-session-bash.js +2 -1
- package/dist/core/agent-session-bash.js.map +1 -1
- package/dist/core/agent-session-blueprint-environment.d.ts +10 -0
- package/dist/core/agent-session-blueprint-environment.d.ts.map +1 -0
- package/dist/core/agent-session-blueprint-environment.js +28 -0
- package/dist/core/agent-session-blueprint-environment.js.map +1 -0
- package/dist/core/agent-session-events.d.ts.map +1 -1
- package/dist/core/agent-session-events.js +2 -0
- package/dist/core/agent-session-events.js.map +1 -1
- package/dist/core/agent-session-methods.d.ts +1 -0
- package/dist/core/agent-session-methods.d.ts.map +1 -1
- package/dist/core/agent-session-methods.js.map +1 -1
- package/dist/core/agent-session-retry.d.ts.map +1 -1
- package/dist/core/agent-session-retry.js +14 -4
- package/dist/core/agent-session-retry.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +20 -0
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +55 -6
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-tool-registry.d.ts.map +1 -1
- package/dist/core/agent-session-tool-registry.js +2 -1
- package/dist/core/agent-session-tool-registry.js.map +1 -1
- package/dist/core/agent-session.d.ts +2 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +2 -0
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/async-scope.d.ts +13 -0
- package/dist/core/async-scope.d.ts.map +1 -0
- package/dist/core/async-scope.js +20 -0
- package/dist/core/async-scope.js.map +1 -0
- package/dist/core/cache-warmer.d.ts +3 -14
- package/dist/core/cache-warmer.d.ts.map +1 -1
- package/dist/core/cache-warmer.js +8 -60
- package/dist/core/cache-warmer.js.map +1 -1
- package/dist/core/extensions/extension-work.js +2 -2
- package/dist/core/extensions/extension-work.js.map +1 -1
- package/dist/core/extensions/loader-host-modules.d.ts.map +1 -1
- package/dist/core/extensions/loader-host-modules.js +3 -1
- package/dist/core/extensions/loader-host-modules.js.map +1 -1
- package/dist/core/extensions/ui-types.d.ts +2 -1
- package/dist/core/extensions/ui-types.d.ts.map +1 -1
- package/dist/core/extensions/ui-types.js.map +1 -1
- package/dist/core/extensions/workflow-events.d.ts +1 -1
- package/dist/core/extensions/workflow-events.d.ts.map +1 -1
- package/dist/core/extensions/workflow-events.js.map +1 -1
- package/dist/core/extensions/workflow-run-control.d.ts +4 -2
- package/dist/core/extensions/workflow-run-control.d.ts.map +1 -1
- package/dist/core/extensions/workflow-run-control.js.map +1 -1
- package/dist/core/model-fallback-failures.d.ts +6 -0
- package/dist/core/model-fallback-failures.d.ts.map +1 -1
- package/dist/core/model-fallback-failures.js +10 -1
- package/dist/core/model-fallback-failures.js.map +1 -1
- package/dist/core/preferred-providers.d.ts +19 -0
- package/dist/core/preferred-providers.d.ts.map +1 -0
- package/dist/core/preferred-providers.js +25 -0
- package/dist/core/preferred-providers.js.map +1 -0
- package/dist/core/provider-alias.d.ts.map +1 -1
- package/dist/core/provider-alias.js +4 -0
- package/dist/core/provider-alias.js.map +1 -1
- package/dist/core/provider-composer.d.ts.map +1 -1
- package/dist/core/provider-composer.js +1 -0
- package/dist/core/provider-composer.js.map +1 -1
- package/dist/core/remote-catalog-provider.d.ts.map +1 -1
- package/dist/core/remote-catalog-provider.js +3 -0
- package/dist/core/remote-catalog-provider.js.map +1 -1
- package/dist/core/resume/blueprint/action-expressions.d.ts +32 -0
- package/dist/core/resume/blueprint/action-expressions.d.ts.map +1 -0
- package/dist/core/resume/blueprint/action-expressions.js +389 -0
- package/dist/core/resume/blueprint/action-expressions.js.map +1 -0
- package/dist/core/resume/blueprint/actions.d.ts +90 -0
- package/dist/core/resume/blueprint/actions.d.ts.map +1 -0
- package/dist/core/resume/blueprint/actions.js +818 -0
- package/dist/core/resume/blueprint/actions.js.map +1 -0
- package/dist/core/resume/blueprint/build.d.ts +102 -0
- package/dist/core/resume/blueprint/build.d.ts.map +1 -0
- package/dist/core/resume/blueprint/build.js +535 -0
- package/dist/core/resume/blueprint/build.js.map +1 -0
- package/dist/core/resume/blueprint/context.d.ts +11 -0
- package/dist/core/resume/blueprint/context.d.ts.map +1 -0
- package/dist/core/resume/blueprint/context.js +106 -0
- package/dist/core/resume/blueprint/context.js.map +1 -0
- package/dist/core/resume/blueprint/envrc.d.ts +19 -0
- package/dist/core/resume/blueprint/envrc.d.ts.map +1 -0
- package/dist/core/resume/blueprint/envrc.js +77 -0
- package/dist/core/resume/blueprint/envrc.js.map +1 -0
- package/dist/core/resume/blueprint/errors.d.ts +179 -0
- package/dist/core/resume/blueprint/errors.d.ts.map +1 -0
- package/dist/core/resume/blueprint/errors.js +169 -0
- package/dist/core/resume/blueprint/errors.js.map +1 -0
- package/dist/core/resume/blueprint/ledger.d.ts +51 -0
- package/dist/core/resume/blueprint/ledger.d.ts.map +1 -0
- package/dist/core/resume/blueprint/ledger.js +119 -0
- package/dist/core/resume/blueprint/ledger.js.map +1 -0
- package/dist/core/resume/blueprint/notices.d.ts +14 -0
- package/dist/core/resume/blueprint/notices.d.ts.map +1 -0
- package/dist/core/resume/blueprint/notices.js +44 -0
- package/dist/core/resume/blueprint/notices.js.map +1 -0
- package/dist/core/resume/blueprint/process.d.ts +44 -0
- package/dist/core/resume/blueprint/process.d.ts.map +1 -0
- package/dist/core/resume/blueprint/process.js +142 -0
- package/dist/core/resume/blueprint/process.js.map +1 -0
- package/dist/core/resume/blueprint/resume.d.ts +73 -0
- package/dist/core/resume/blueprint/resume.d.ts.map +1 -0
- package/dist/core/resume/blueprint/resume.js +206 -0
- package/dist/core/resume/blueprint/resume.js.map +1 -0
- package/dist/core/resume/blueprint/schema.d.ts +26 -0
- package/dist/core/resume/blueprint/schema.d.ts.map +1 -0
- package/dist/core/resume/blueprint/schema.js +243 -0
- package/dist/core/resume/blueprint/schema.js.map +1 -0
- package/dist/core/resume/blueprint/steps.d.ts +54 -0
- package/dist/core/resume/blueprint/steps.d.ts.map +1 -0
- package/dist/core/resume/blueprint/steps.js +155 -0
- package/dist/core/resume/blueprint/steps.js.map +1 -0
- package/dist/core/resume/blueprint/types.d.ts +63 -0
- package/dist/core/resume/blueprint/types.d.ts.map +1 -0
- package/dist/core/resume/blueprint/types.js +2 -0
- package/dist/core/resume/blueprint/types.js.map +1 -0
- package/dist/core/resume/errors.d.ts +7 -35
- package/dist/core/resume/errors.d.ts.map +1 -1
- package/dist/core/resume/errors.js +1 -21
- package/dist/core/resume/errors.js.map +1 -1
- package/dist/core/resume/index.d.ts +12 -4
- package/dist/core/resume/index.d.ts.map +1 -1
- package/dist/core/resume/index.js +11 -4
- package/dist/core/resume/index.js.map +1 -1
- package/dist/core/resume/run-setup.d.ts +36 -15
- package/dist/core/resume/run-setup.d.ts.map +1 -1
- package/dist/core/resume/run-setup.js +70 -54
- package/dist/core/resume/run-setup.js.map +1 -1
- package/dist/core/resume/session-resume.d.ts +34 -20
- package/dist/core/resume/session-resume.d.ts.map +1 -1
- package/dist/core/resume/session-resume.js +244 -106
- package/dist/core/resume/session-resume.js.map +1 -1
- package/dist/core/retry-policy.d.ts +19 -1
- package/dist/core/retry-policy.d.ts.map +1 -1
- package/dist/core/retry-policy.js +26 -1
- package/dist/core/retry-policy.js.map +1 -1
- package/dist/core/sdk.js +1 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-cwd.d.ts +56 -1
- package/dist/core/session-cwd.d.ts.map +1 -1
- package/dist/core/session-cwd.js +94 -4
- package/dist/core/session-cwd.js.map +1 -1
- package/dist/core/session-manager-core.d.ts +1 -1
- package/dist/core/session-manager-core.d.ts.map +1 -1
- package/dist/core/session-manager-core.js +10 -5
- package/dist/core/session-manager-core.js.map +1 -1
- package/dist/core/session-worktree-snapshots.d.ts +11 -0
- package/dist/core/session-worktree-snapshots.d.ts.map +1 -1
- package/dist/core/session-worktree-snapshots.js +10 -4
- package/dist/core/session-worktree-snapshots.js.map +1 -1
- package/dist/core/settings-defaults.d.ts +1 -1
- package/dist/core/settings-defaults.d.ts.map +1 -1
- package/dist/core/settings-defaults.js +1 -1
- package/dist/core/settings-defaults.js.map +1 -1
- package/dist/core/settings-manager-basic-accessors.d.ts +3 -2
- package/dist/core/settings-manager-basic-accessors.d.ts.map +1 -1
- package/dist/core/settings-manager-basic-accessors.js.map +1 -1
- package/dist/core/settings-schema.d.ts.map +1 -1
- package/dist/core/settings-schema.js +2 -1
- package/dist/core/settings-schema.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +4 -0
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/storage/write-ahead-log.d.ts +2 -1
- package/dist/core/storage/write-ahead-log.d.ts.map +1 -1
- package/dist/core/storage/write-ahead-log.js +27 -6
- package/dist/core/storage/write-ahead-log.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +10 -0
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/file-tool-errors.d.ts +1 -1
- package/dist/core/tools/file-tool-errors.js +1 -1
- package/dist/core/tools/file-tool-errors.js.map +1 -1
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +52 -26
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/grep.d.ts +2 -0
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/powershell.d.ts.map +1 -1
- package/dist/core/tools/powershell.js +10 -2
- package/dist/core/tools/powershell.js.map +1 -1
- package/dist/core/tools/tool-concurrency.d.ts.map +1 -1
- package/dist/core/tools/tool-concurrency.js +2 -2
- package/dist/core/tools/tool-concurrency.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/main-session.d.ts +12 -4
- package/dist/main-session.d.ts.map +1 -1
- package/dist/main-session.js +28 -4
- package/dist/main-session.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +6 -8
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host.d.ts +5 -1
- package/dist/modes/interactive/components/chat-session-host.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host.js +6 -1
- package/dist/modes/interactive/components/chat-session-host.js.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.d.ts +10 -3
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.js +34 -13
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
- package/dist/modes/interactive/components/provider-brand.d.ts +16 -0
- package/dist/modes/interactive/components/provider-brand.d.ts.map +1 -0
- package/dist/modes/interactive/components/provider-brand.js +67 -0
- package/dist/modes/interactive/components/provider-brand.js.map +1 -0
- package/dist/modes/interactive/interactive-auth-routing.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-auth-routing.js +8 -6
- package/dist/modes/interactive/interactive-auth-routing.js.map +1 -1
- package/dist/modes/interactive/interactive-extension-dialogs.js +4 -3
- package/dist/modes/interactive/interactive-extension-dialogs.js.map +1 -1
- package/dist/modes/interactive/interactive-extension-runtime.js +8 -3
- package/dist/modes/interactive/interactive-extension-runtime.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-deps.d.ts +1 -1
- package/dist/modes/interactive/interactive-mode-deps.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-deps.js +1 -1
- package/dist/modes/interactive/interactive-mode-deps.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-surface.d.ts +12 -2
- package/dist/modes/interactive/interactive-mode-surface.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-surface.js.map +1 -1
- package/dist/modes/interactive/interactive-session-routing.js +59 -21
- package/dist/modes/interactive/interactive-session-routing.js.map +1 -1
- package/dist/modes/interactive/interactive-slash-commands.js +23 -12
- package/dist/modes/interactive/interactive-slash-commands.js.map +1 -1
- package/dist/modes/interactive/login-provider-options.d.ts.map +1 -1
- package/dist/modes/interactive/login-provider-options.js +2 -1
- package/dist/modes/interactive/login-provider-options.js.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.d.ts +2 -0
- package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.js +8 -3
- package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
- package/dist/modes/rpc/rpc-client-api.d.ts +2 -1
- package/dist/modes/rpc/rpc-client-api.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client-api.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +0 -1
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +2 -18
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-command-handler.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-command-handler.js +8 -2
- package/dist/modes/rpc/rpc-command-handler.js.map +1 -1
- package/dist/modes/rpc/rpc-error-decoding.d.ts +7 -0
- package/dist/modes/rpc/rpc-error-decoding.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-error-decoding.js +25 -0
- package/dist/modes/rpc/rpc-error-decoding.js.map +1 -0
- package/dist/modes/rpc/rpc-responses.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-responses.js +12 -0
- package/dist/modes/rpc/rpc-responses.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +11 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +12 -3
- package/dist/package-manager-cli.js.map +1 -1
- package/docs/background-tasks.md +1 -1
- package/docs/codemode.md +22 -0
- package/docs/extensions/api-reference.md +27 -1
- package/docs/extensions/authoring.md +1 -1
- package/docs/extensions/ui.md +1 -1
- package/docs/getting-started/first-session.md +1 -1
- package/docs/guides/resume-on-any-machine.md +72 -19
- package/docs/models/evals.md +85 -17
- package/docs/models/reference.md +1 -1
- package/docs/providers.md +38 -5
- package/docs/reference/cli.md +2 -0
- package/docs/rpc/protocol.md +11 -1
- package/docs/sdk/reference.md +36 -4
- package/docs/sdk.md +2 -2
- package/docs/sessions.md +11 -1
- package/docs/settings.md +7 -2
- package/docs/skills.md +3 -3
- package/docs/storage.md +1 -1
- package/docs/tools.md +3 -1
- package/docs/workflows/api-reference.md +14 -12
- package/docs/workflows/authoring.md +29 -1
- package/docs/workflows/builtins.md +9 -1
- package/docs/workflows/operations.md +8 -8
- package/docs/worktree-snapshots.md +3 -2
- package/npm-shrinkwrap.json +83 -67
- package/package.json +7 -7
- package/schemas/settings.schema.json +3 -2
- package/dist/core/resume/setup-hook.d.ts +0 -69
- package/dist/core/resume/setup-hook.d.ts.map +0 -1
- package/dist/core/resume/setup-hook.js +0 -261
- package/dist/core/resume/setup-hook.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-fallback-failures.js","sourceRoot":"","sources":["../../src/core/model-fallback-failures.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,sBAAsB,EAAwD,MAAM,gBAAgB,CAAC;AAC9G,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAE3E,MAAM,gCAAgC,GAAsB;IAC3D,eAAe;IACf,wBAAwB;IAC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AC;IACzF,YAAY;IACZ,sBAAsB;IACtB,iBAAiB;IACjB,iBAAiB;CACjB,CAAC,CAAC;AAEH;;;GAGG;AACH,SAAS,oBAAoB,CAAC,MAAkC;IAC/D,OAAO,CACN,MAAM,CAAC,IAAI,KAAK,sBAAsB;QACtC,MAAM,CAAC,MAAM,KAAK,mBAAmB;QACrC,MAAM,CAAC,MAAM,KAAK,SAAS;QAC3B,MAAM,CAAC,IAAI,KAAK,SAAS;QACzB,MAAM,CAAC,IAAI,KAAK,SAAS;QACzB,CAAC,gCAAgC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CACjF,CAAC;AACH,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,2BAA2B,CAAC,KAAc;IACzD,IAAI,CAAC,uBAAuB,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAClD,MAAM,MAAM,GAAG,2BAA2B,CAAC,KAAK,CAAC,CAAC;IAClD,OAAO,kCAAkC,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC;AAC7F,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,0BAA0B,CAAC,KAAc;IACxD,OAAO,uBAAuB,CAAC,KAAK,CAAC,IAAI,oBAAoB,CAAC,2BAA2B,CAAC,KAAK,CAAC,CAAC,CAAC;AACnG,CAAC","sourcesContent":["/**\n * Shared model/provider failure classification.\n *\n * Workflows, subagents, and the main chat all need the same decision about\n * whether a provider failure may spend another model candidate. Keep this\n * module free of AgentSession and workflow imports so the published SDK can\n * expose it to the raw-TypeScript companion packages without a cycle.\n */\n\nimport { findGitHubCopilotError, type GitHubCopilotError, type GitHubCopilotErrorCode } from \"@bastani/pi-ai\";\nimport { isExtensionStartupFailure } from \"./extension-startup-failure.ts\";\n\nconst RETRYABLE_MODEL_FAILURE_PATTERNS: readonly RegExp[] = [\n\t/rate\\s*limit/i,\n\t/too\\s*many\\s*requests/i,\n\t/\\bthrottl(?:ing|ed)\\b/i,\n\t/\\b429\\b/,\n\t/quota/i,\n\t/usage[\\s_-]*limit/i,\n\t/billing/i,\n\t/credit/i,\n\t/auth(?:entication|orization)?/i,\n\t/unauthori[sz]ed/i,\n\t/\\b40[13]\\b/,\n\t/api[_\\s-]*key/i,\n\t/token[_\\s-]*expired/i,\n\t/token[_\\s-]*(?:revoked|invalidated)/i,\n\t/invalidated[_\\s-]+(?:oauth|auth)[_\\s-]+token/i,\n\t/forbidden/i,\n\t/invalid\\s*key/i,\n\t/overloaded/i,\n\t/temporarily\\s*unavailable/i,\n\t/service\\s*unavailable/i,\n\t/network/i,\n\t/fetch/i,\n\t/getaddrinfo/i,\n\t/ENOTFOUND/i,\n\t/EAI_AGAIN/i,\n\t/socket/i,\n\t/connection\\s*refused/i,\n\t/upstream/i,\n\t/timeout/i,\n\t/timed\\s*out/i,\n\t/\\b50[0-4]\\b/,\n\t/\\b52[0-4]\\b/,\n\t/\\b529\\b/,\n\t/provider.?returned.?error/i,\n\t/server.?error/i,\n\t/internal.?error/i,\n\t/connection.?error/i,\n\t/connection.?lost/i,\n\t/connection.?reset/i,\n\t/ECONNRESET/i,\n\t/other side closed/i,\n\t/websocket.?closed/i,\n\t/websocket.?error/i,\n\t/reset before headers/i,\n\t/socket hang up/i,\n\t/ended without/i,\n\t/stream ended before message_stop/i,\n\t/stream ended before a terminal response event/i,\n\t/http2 request did not get a response/i,\n\t/pending stream has been canceled/i,\n\t/retry delay/i,\n\t/finish.?reason:?\\s*error/i,\n\t/terminated/i,\n\t/you can retry your request/i,\n\t/try your request again/i,\n\t/please retry your request/i,\n\t// gRPC based providers (e.g. NVIDIA NIM); upstream pi-ai retries this too.\n\t/ResourceExhausted/i,\n];\n\nconst NON_RETRYABLE_FAILURE_PATTERNS: readonly RegExp[] = [\n\t/command failed/i,\n\t/tests? failed/i,\n\t/shell/i,\n\t/missing file/i,\n\t/no such file/i,\n\t/cancel/i,\n\t/abort/i,\n\t/interrupted/i,\n];\n\nconst CANCELLED_FAILURE_PATTERNS: readonly RegExp[] = [/cancel/i, /abort/i, /interrupted/i];\n\nconst TRANSPORT_CANCELLATION_FAILURE_PATTERNS: readonly RegExp[] = [\n\t/getaddrinfo|ENOTFOUND|EAI_AGAIN/i,\n\t/pending stream has been canceled/i,\n];\n\nexport type ModelFallbackFailureKind =\n\t| \"auth_on_candidate_provider\"\n\t| \"rate_limit\"\n\t| \"quota_exhausted\"\n\t| \"provider_unavailable\"\n\t| \"network_timeout\"\n\t| \"transport_error\"\n\t| \"model_unavailable\"\n\t| \"request_incompatible\"\n\t| \"content_filter\"\n\t| \"cancelled\"\n\t| \"task_failure\"\n\t| \"unknown\";\n\nexport type ModelFallbackFailureSource =\n\t| \"assistant_message\"\n\t| \"diagnostic\"\n\t| \"throw\"\n\t| \"structured\"\n\t| \"string_fallback\";\n\nexport interface ModelFallbackFailureSignal {\n\treadonly kind: ModelFallbackFailureKind;\n\treadonly message: string;\n\treadonly source: ModelFallbackFailureSource;\n\treadonly stopReason?: string;\n\treadonly status?: number;\n\treadonly code?: string | number;\n\treadonly name?: string;\n}\n\n/** How a caller treats a provider content-filter refusal; `retry.fallbackOnContentFilter` in settings. */\nexport interface ModelFallbackFailureOptions {\n\t/** Whether a content-filter refusal may spend the next fallback candidate. Defaults to true. */\n\treadonly fallbackOnContentFilter?: boolean;\n}\n\nconst FALLBACKABLE_FAILURE_KINDS: ReadonlySet<ModelFallbackFailureKind> = new Set([\n\t\"auth_on_candidate_provider\",\n\t\"rate_limit\",\n\t\"quota_exhausted\",\n\t\"provider_unavailable\",\n\t\"network_timeout\",\n\t\"transport_error\",\n\t\"model_unavailable\",\n\t\"request_incompatible\",\n]);\n\nfunction asRecord(value: unknown): Record<string, unknown> | undefined {\n\treturn value !== null && typeof value === \"object\" ? (value as Record<string, unknown>) : undefined;\n}\n\nfunction field(value: unknown, key: string): unknown {\n\treturn asRecord(value)?.[key];\n}\n\nfunction stringField(value: unknown, key: string): string | undefined {\n\tconst raw = field(value, key);\n\treturn typeof raw === \"string\" && raw.trim().length > 0 ? raw : undefined;\n}\n\nfunction errorName(value: unknown): string | undefined {\n\treturn value instanceof Error ? value.name : stringField(value, \"name\");\n}\n\nfunction directMessageFrom(value: unknown): string | undefined {\n\treturn stringField(value, \"errorMessage\") ?? stringField(value, \"message\") ?? stringField(value, \"statusText\");\n}\n\nfunction integerFrom(value: unknown): number | undefined {\n\tif (typeof value === \"number\" && Number.isInteger(value)) return value;\n\tif (typeof value !== \"string\" || value.trim().length === 0) return undefined;\n\tconst parsed = Number(value.trim());\n\treturn Number.isInteger(parsed) ? parsed : undefined;\n}\n\nfunction statusFrom(value: unknown): number | undefined {\n\treturn (\n\t\tintegerFrom(field(value, \"status\")) ??\n\t\tintegerFrom(field(value, \"statusCode\")) ??\n\t\tintegerFrom(field(value, \"httpStatus\"))\n\t);\n}\n\nfunction codeFrom(value: unknown): string | number | undefined {\n\tconst rawCode = field(value, \"code\");\n\tif (typeof rawCode === \"string\" || typeof rawCode === \"number\") return rawCode;\n\t// Provider failure diagnostics (`bedrock_response_failure`) keep the modeled error code in `details.errorCode`,\n\t// because the provider's display message replaces the exception name with a readable prefix.\n\tconst detailsCode = field(field(value, \"details\"), \"errorCode\");\n\treturn typeof detailsCode === \"string\" ? detailsCode : undefined;\n}\n\nfunction stopReasonFrom(value: unknown): string | undefined {\n\treturn stringField(value, \"stopReason\");\n}\n\nfunction finishReasonFrom(value: unknown): string | undefined {\n\treturn stringField(value, \"finish_reason\") ?? stringField(value, \"finishReason\");\n}\n\nfunction causeOf(value: unknown): unknown {\n\treturn value instanceof Error ? value.cause : field(value, \"cause\");\n}\n\nfunction diagnosticErrors(value: unknown): readonly unknown[] {\n\tconst diagnostics = field(value, \"diagnostics\");\n\tif (!Array.isArray(diagnostics)) return [];\n\tconst errors: unknown[] = [];\n\tfor (const diagnostic of diagnostics) {\n\t\tconst diagnosticType = stringField(diagnostic, \"type\");\n\t\tconst diagnosticError = field(diagnostic, \"error\");\n\t\terrors.push(\n\t\t\tnormalizeCode(diagnosticType) === \"provider_transport_failure\" ? diagnostic : (diagnosticError ?? diagnostic),\n\t\t);\n\t}\n\treturn errors;\n}\n\nfunction normalizeCode(value: string | number | undefined): string | undefined {\n\tif (value === undefined) return undefined;\n\tconst raw = String(value).trim().toLowerCase();\n\tif (!raw) return undefined;\n\tlet normalized = \"\";\n\tlet needsSeparator = false;\n\tfor (const char of raw) {\n\t\tconst code = char.charCodeAt(0);\n\t\tconst isLowerAlpha = code >= 97 && code <= 122;\n\t\tconst isDigit = code >= 48 && code <= 57;\n\t\tif (isLowerAlpha || isDigit) {\n\t\t\tnormalized += char;\n\t\t\tneedsSeparator = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (needsSeparator && normalized[normalized.length - 1] !== \"_\") normalized += \"_\";\n\t}\n\tif (normalized.endsWith(\"_\")) normalized = normalized.slice(0, -1);\n\treturn normalized.length > 0 ? normalized : undefined;\n}\n\nfunction messageLooksLikeModelUnavailable(message: string): boolean {\n\tconst lower = message.toLowerCase();\n\treturn (\n\t\tlower.includes(\"model\") &&\n\t\t(lower.includes(\"unavailable\") ||\n\t\t\tlower.includes(\"disabled\") ||\n\t\t\tlower.includes(\"not found\") ||\n\t\t\tlower.includes(\"unknown\"))\n\t);\n}\n\nfunction kindFromStatus(status: number | undefined): ModelFallbackFailureKind | undefined {\n\tswitch (status) {\n\t\tcase 400:\n\t\tcase 413:\n\t\tcase 422:\n\t\t\treturn \"request_incompatible\";\n\t\tcase 401:\n\t\tcase 403:\n\t\t\treturn \"auth_on_candidate_provider\";\n\t\tcase 408:\n\t\t\treturn \"network_timeout\";\n\t\tcase 404:\n\t\t\treturn \"model_unavailable\";\n\t\tcase 402:\n\t\t\treturn \"quota_exhausted\";\n\t\tcase 429:\n\t\t\treturn \"rate_limit\";\n\t\tdefault:\n\t\t\tif (status !== undefined && status >= 500 && status <= 599) return \"provider_unavailable\";\n\t\t\treturn undefined;\n\t}\n}\n\nfunction refusalKindFromCode(code: string | number | undefined): ModelFallbackFailureKind | undefined {\n\tconst normalizedCode = normalizeCode(code);\n\tif (normalizedCode === undefined) return undefined;\n\t// A refused tool call, such as `tool_call_refusal` or `tool_use_refused_by_policy`, before the policy words.\n\tif (/(?:^|_)tool(?:_|$)/.test(normalizedCode) && normalizedCode.includes(\"refus\")) return \"task_failure\";\n\tif (normalizedCode.includes(\"content_filter\") || normalizedCode.includes(\"contentfilter\")) return \"content_filter\";\n\t// Includes OpenAI's `cyber_policy`.\n\tif (normalizedCode.includes(\"safety\") || normalizedCode.includes(\"policy\")) return \"content_filter\";\n\tswitch (normalizedCode) {\n\t\tcase \"blocked\":\n\t\tcase \"blocked_by_provider\":\n\t\tcase \"blocked_by_safety\":\n\t\tcase \"blocked_by_policy\":\n\t\tcase \"provider_refusal\":\n\t\tcase \"refusal\":\n\t\t\treturn \"content_filter\";\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n}\n\nconst REQUEST_INCOMPATIBLE_CODES: ReadonlySet<string> = new Set([\n\t\"invalid_request\",\n\t\"invalid_request_error\",\n\t\"bad_request\",\n\t\"context_length_exceeded\",\n\t\"request_too_large\",\n\t\"too_large\",\n\t\"request_entity_too_large\",\n\t\"max_tokens\",\n\t\"max_context_length\",\n\t\"context_window_exceeded\",\n]);\n\nfunction requestIncompatibleKindFromCode(code: string | number | undefined): ModelFallbackFailureKind | undefined {\n\tconst normalized = normalizeCode(code);\n\treturn normalized !== undefined && REQUEST_INCOMPATIBLE_CODES.has(normalized) ? \"request_incompatible\" : undefined;\n}\n\nfunction kindFromCode(code: string | number | undefined): ModelFallbackFailureKind | undefined {\n\tconst normalizedCode = normalizeCode(code);\n\tif (normalizedCode === undefined) return undefined;\n\tconst refusalKind = refusalKindFromCode(code);\n\tif (refusalKind !== undefined) return refusalKind;\n\tconst httpStatusKind = kindFromStatus(integerFrom(code));\n\tif (httpStatusKind !== undefined) return httpStatusKind;\n\tconst requestIncompatibleKind = requestIncompatibleKindFromCode(code);\n\tif (requestIncompatibleKind !== undefined) return requestIncompatibleKind;\n\n\tswitch (normalizedCode) {\n\t\tcase \"auth\":\n\t\tcase \"auth_required\":\n\t\tcase \"authentication_required\":\n\t\tcase \"unauthorized\":\n\t\tcase \"forbidden\":\n\t\tcase \"invalid_api_key\":\n\t\tcase \"missing_api_key\":\n\t\tcase \"invalid_key\":\n\t\tcase \"token_expired\":\n\t\tcase \"token_revoked\":\n\t\tcase \"token_invalidated\":\n\t\tcase \"oauth_token_invalidated\":\n\t\t\treturn \"auth_on_candidate_provider\";\n\t\tcase \"etimedout\":\n\t\tcase \"econnreset\":\n\t\tcase \"econnrefused\":\n\t\tcase \"enotfound\":\n\t\tcase \"eai_again\":\n\t\tcase \"fetch_failed\":\n\t\tcase \"network_error\":\n\t\tcase \"timeout\":\n\t\tcase \"timeout_error\":\n\t\tcase \"und_err_connect_timeout\":\n\t\t\treturn \"network_timeout\";\n\t\tcase \"rate_limit\":\n\t\tcase \"rate_limit_exceeded\":\n\t\tcase \"too_many_requests\":\n\t\tcase \"throttlingexception\":\n\t\t\treturn \"rate_limit\";\n\t\tcase \"quota_exceeded\":\n\t\tcase \"insufficient_quota\":\n\t\tcase \"usage_limit\":\n\t\tcase \"usage_limit_reached\":\n\t\tcase \"usage_limit_exceeded\":\n\t\tcase \"payment_required\":\n\t\tcase \"servicequotaexceededexception\":\n\t\t\treturn \"quota_exhausted\";\n\t\tcase \"aborterror\":\n\t\tcase \"aborted\":\n\t\tcase \"cancelled\":\n\t\tcase \"canceled\":\n\t\t\treturn \"cancelled\";\n\t\tcase \"model_not_found\":\n\t\tcase \"model_unavailable\":\n\t\tcase \"model_disabled\":\n\t\tcase \"unknown_model\":\n\t\tcase \"model_not_available_for_integrator\":\n\t\t\treturn \"model_unavailable\";\n\t\tcase \"provider_error\":\n\t\tcase \"api_error\":\n\t\tcase \"service_unavailable\":\n\t\tcase \"temporarily_unavailable\":\n\t\tcase \"overloaded\":\n\t\t\treturn \"provider_unavailable\";\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n}\n\nconst REQUEST_INCOMPATIBLE_FAILURE_PATTERNS: readonly RegExp[] = [\n\t/\\bcontext[_\\s-]?length(?:[_\\s-]?exceeded)?\\b/i,\n\t/\\bcontext[_\\s-]?window(?:[_\\s-]?exceeded)?\\b/i,\n\t/\\bmax[_\\s-]?context\\b/i,\n\t/\\bmax[_\\s-]?tokens?\\b/i,\n\t/\\brequest(?:[_\\s-]?entity)?[_\\s-]?too[_\\s-]?large\\b/i,\n\t/\\btoo[_\\s-]?large\\b/i,\n\t/\\b(?:unsupported|unknown|invalid)\\s+(?:tool|parameter|function)\\b/i,\n\t/\\b(?:tool|parameter|function)\\s+(?:not\\s+(?:supported|found|allowed)|unknown|invalid)\\b/i,\n\t/\\binvalid[_\\s-]?request(?:[_\\s-]?error)?\\b/i,\n\t/\\bbad[_\\s-]?request\\b/i,\n];\n\n/** A provider declined the request's content under its usage policy: the model will refuse it again. */\nconst CONTENT_FILTER_FAILURE_PATTERNS: readonly RegExp[] = [\n\t/\\bthe\\s+model\\s+refused\\s+to\\s+complete\\s+the\\s+request\\b/i,\n\t/\\bfinish[_\\s-]?reason\\b[^\\n]*\\bcontent[_\\s-]?filter\\b/i,\n\t/\\bcontent[_\\s-]?filter(?:ed|ing)?\\b/i,\n\t/\\bcyber[_\\s-]?policy\\b/i,\n\t// OpenAI's cyber safeguard: \"This content was flagged for possible cybersecurity risk.\"\n\t/\\bflagged\\s+for\\s+(?:possible|potential(?:ly)?)\\b[^\\n]*\\b(?:risk|harm(?:ful)?|safety|policy|cyber\\w*)\\b/i,\n\t/\\b(?:safety|policy)\\b[^\\n]*\\b(?:refus(?:e|al|ed|es|ing)?|block(?:ed|ing)?|filter(?:ed|ing)?|violat(?:e|ion|ed|ing)?|disallow(?:ed|ing)?|reject(?:ed|ion|ing)?)\\b/i,\n\t/\\b(?:refus(?:e|al|ed|es|ing)?|block(?:ed|ing)?|filter(?:ed|ing)?|violat(?:e|ion|ed|ing)?|disallow(?:ed|ing)?|reject(?:ed|ion|ing)?)\\b[^\\n]*\\b(?:safety|policy)\\b/i,\n\t/\\bprovider[_\\s-]?refus(?:e|al|ed|es|ing)?\\b/i,\n\t/\\bprovider\\b[^\\n]*\\brefus(?:e|al|ed|es|ing)?\\b[^\\n]*\\b(?:prompt|request|content|policy|safety)\\b/i,\n];\n\nconst TOOL_REFUSAL_FAILURE_PATTERNS: readonly RegExp[] = [\n\t/\\btool[_\\s-]?(?:call|use)?[_\\s-]?refus(?:e|al|ed|es|ing)?\\b/i,\n\t/\\btool(?:\\s+call|\\s+use)?\\b[^\\n]*\\brefus(?:e|al|ed|es|ing)?\\b/i,\n\t/\\brefus(?:e|al|ed|es|ing)?\\b[^\\n]*\\btool(?:\\s+call|\\s+use)?\\b/i,\n];\n\nconst PROVIDER_REFUSAL_FAILURE_PATTERNS: readonly RegExp[] = [\n\t...CONTENT_FILTER_FAILURE_PATTERNS,\n\t...TOOL_REFUSAL_FAILURE_PATTERNS,\n];\n\nconst TRANSPORT_OUTAGE_FAILURE_PATTERNS: readonly RegExp[] = [\n\t/^connection\\s+error\\.?$/i,\n\t/^fetch\\s+failed\\.?$/i,\n\t// Response-body decompression failures reported by Node/Bun zlib, optionally\n\t// behind the fetch/WebSocket layer's \"Library error:\" wrapper. GitHub Copilot\n\t// on the default `transport: \"auto\"` surfaces this as\n\t// \"Library error: zlib error: incorrect header check\" (#2553). These are\n\t// unanchored because the wrapper text varies by runtime and transport. `zlib`\n\t// has no trailing word boundary on purpose: Bun 1.4.0, the shipped runtime\n\t// when verified, throws `ZlibError fetching \"...\"` as one word.\n\t/\\bzlib/i,\n\t/\\bincorrect\\s+header\\s+check\\b/i,\n\t/\\bdecompress(?:ion|ing|ed)?\\b/i,\n\t/^library\\s+error\\b/i,\n\t// Idle-stream deadline enforced below the HTTP layer by pi-ai's\n\t// `withStreamDeadline`, so a stalled stream fails over instead of hanging.\n\t/\\bstream\\s+deadline\\s+exceeded\\b/i,\n\t// A streamed response cut off before its finish reason, as GitHub Copilot's Gemini models do now and then: the\n\t// same request normally completes when sent again (#4223).\n\t/\\bstream\\s+ended\\s+without\\s+finish[_\\s-]?reason\\b/i,\n];\n\n// HTTP 402 and explicit quota exhaustion: the account cannot be served again until its quota resets.\n// Codes that also appear as free-text wording for short limits (\"quota exceeded\", \"usage limit reached\")\n// count only as a JSON `code`/`type` value, as in a raw error body some providers put in the message.\n// A service-quota exception and a per-day quota violation in a JSON error body (`\"quotaId\": \"...PerDay...\"`)\n// also last until the quota resets.\nconst QUOTA_EXHAUSTED_FAILURE_PATTERN =\n\t/(?<![a-z0-9.])402(?![a-z0-9.])|payment[_\\s-]*required|insufficient[_\\s-]*quota|\\bServiceQuotaExceededException\\b|\"quotaId\"\\s*:\\s*\"[^\"]*PerDay|\"(?:code|type|error_code)\"\\s*:\\s*\"(?:quota_exceeded|usage_limit|usage_limit_reached|usage_limit_exceeded)\"/i;\n\nfunction transportOutageKindFromMessage(message: string): ModelFallbackFailureKind | undefined {\n\treturn TRANSPORT_OUTAGE_FAILURE_PATTERNS.some((pattern) => pattern.test(message.trim()))\n\t\t? \"transport_error\"\n\t\t: undefined;\n}\n\nfunction refusalKindFromMessage(message: string): ModelFallbackFailureKind | undefined {\n\tif (TRANSPORT_CANCELLATION_FAILURE_PATTERNS.some((pattern) => pattern.test(message))) return \"network_timeout\";\n\tif (CANCELLED_FAILURE_PATTERNS.some((pattern) => pattern.test(message))) return \"cancelled\";\n\tif (NON_RETRYABLE_FAILURE_PATTERNS.some((pattern) => pattern.test(message))) return \"task_failure\";\n\t// A refused tool call is about that call, whatever policy the provider names: another model is asked the same\n\t// tool call. So it is checked before the content-filter grammar, which \"refused ... safety policy\" also matches.\n\tif (TOOL_REFUSAL_FAILURE_PATTERNS.some((pattern) => pattern.test(message))) return \"task_failure\";\n\tif (CONTENT_FILTER_FAILURE_PATTERNS.some((pattern) => pattern.test(message))) return \"content_filter\";\n\treturn undefined;\n}\n\nfunction fallbackKindFromMessage(message: string, name: string | undefined): ModelFallbackFailureKind | undefined {\n\tconst refusalKind = refusalKindFromMessage(message);\n\tif (refusalKind !== undefined) return refusalKind;\n\tconst transportOutageKind = transportOutageKindFromMessage(message);\n\tif (transportOutageKind !== undefined) return transportOutageKind;\n\tif (REQUEST_INCOMPATIBLE_FAILURE_PATTERNS.some((pattern) => pattern.test(message))) return \"request_incompatible\";\n\tconst nameKind = kindFromCode(name);\n\tif (nameKind !== undefined) return nameKind;\n\tif (QUOTA_EXHAUSTED_FAILURE_PATTERN.test(message)) return \"quota_exhausted\";\n\tconst hasRetryablePattern =\n\t\tRETRYABLE_MODEL_FAILURE_PATTERNS.some((pattern) => pattern.test(message)) ||\n\t\tmessageLooksLikeModelUnavailable(message);\n\tif (!hasRetryablePattern) return undefined;\n\tif (\n\t\t/rate\\s*limit|too\\s*many\\s*requests|\\bthrottl(?:ing|ed)\\b|\\b429\\b|quota|usage[\\s_-]*limit|billing|credit/i.test(\n\t\t\tmessage,\n\t\t)\n\t)\n\t\treturn \"rate_limit\";\n\tif (\n\t\t/auth|unauthori[sz]ed|\\b40[13]\\b|api[_\\s-]*key|token[_\\s-]*(?:expired|revoked|invalidated|rejected)|forbidden|invalid[_\\s-]*key/i.test(\n\t\t\tmessage,\n\t\t)\n\t)\n\t\treturn \"auth_on_candidate_provider\";\n\tif (messageLooksLikeModelUnavailable(message)) return \"model_unavailable\";\n\tif (/network|fetch|socket|connection\\s*refused|getaddrinfo|ENOTFOUND|EAI_AGAIN|timeout|timed\\s*out/i.test(message))\n\t\treturn \"network_timeout\";\n\treturn \"provider_unavailable\";\n}\n\nfunction signalSource(value: unknown, fallback: ModelFallbackFailureSource | undefined): ModelFallbackFailureSource {\n\tif (fallback !== undefined) return fallback;\n\tif (stopReasonFrom(value) !== undefined || diagnosticErrors(value).length > 0) return \"assistant_message\";\n\tif (value instanceof Error) return \"throw\";\n\treturn \"structured\";\n}\n\nfunction makeSignal(\n\tkind: ModelFallbackFailureKind,\n\tvalue: unknown,\n\tsource: ModelFallbackFailureSource | undefined,\n): ModelFallbackFailureSignal {\n\tconst status = statusFrom(value);\n\tconst code = codeFrom(value);\n\tconst name = errorName(value);\n\tconst stopReason = stopReasonFrom(value);\n\treturn {\n\t\tkind,\n\t\tmessage: errorMessage(value),\n\t\tsource: signalSource(value, source),\n\t\t...(stopReason !== undefined ? { stopReason } : {}),\n\t\t...(status !== undefined ? { status } : {}),\n\t\t...(code !== undefined ? { code } : {}),\n\t\t...(name !== undefined ? { name } : {}),\n\t};\n}\n\nfunction fallbackSignalFromDirectMessage(\n\tvalue: unknown,\n\tsource: ModelFallbackFailureSource | undefined,\n): ModelFallbackFailureSignal | undefined {\n\tconst message = directMessageFrom(value);\n\tif (message === undefined) return undefined;\n\tconst kind = fallbackKindFromMessage(message, errorName(value));\n\treturn kind === undefined ? undefined : makeSignal(kind, value, source);\n}\n\nfunction fallbackSignalFromMessage(\n\tvalue: unknown,\n\tsource: ModelFallbackFailureSource | undefined,\n): ModelFallbackFailureSignal | undefined {\n\tconst message = errorMessage(value);\n\tif (!message.trim()) return undefined;\n\tconst kind = fallbackKindFromMessage(message, errorName(value));\n\treturn kind === undefined ? undefined : makeSignal(kind, value, source);\n}\n\nfunction classifyAssistantRefusalSignal(\n\tvalue: unknown,\n\tsource: ModelFallbackFailureSource | undefined,\n): ModelFallbackFailureSignal | undefined {\n\tconst codeRefusalKind =\n\t\trefusalKindFromCode(codeFrom(value)) ??\n\t\trefusalKindFromCode(errorName(value)) ??\n\t\trefusalKindFromCode(finishReasonFrom(value));\n\tif (codeRefusalKind !== undefined) return makeSignal(codeRefusalKind, value, source);\n\n\tconst messageRefusalKind = refusalKindFromMessage(directMessageFrom(value) ?? \"\");\n\treturn messageRefusalKind === undefined ? undefined : makeSignal(messageRefusalKind, value, source);\n}\n\nfunction isRefusalSignal(signal: ModelFallbackFailureSignal): boolean {\n\treturn signal.kind === \"cancelled\" || signal.kind === \"task_failure\" || signal.kind === \"content_filter\";\n}\n\nfunction nestedSignalPriority(signal: ModelFallbackFailureSignal): number {\n\tswitch (signal.kind) {\n\t\tcase \"cancelled\":\n\t\tcase \"task_failure\":\n\t\tcase \"content_filter\":\n\t\t\treturn 100;\n\t\tcase \"auth_on_candidate_provider\":\n\t\t\treturn 90;\n\t\tcase \"request_incompatible\":\n\t\t\treturn 85;\n\t\tcase \"model_unavailable\":\n\t\t\treturn 80;\n\t\tcase \"quota_exhausted\":\n\t\t\treturn 75;\n\t\tcase \"rate_limit\":\n\t\t\treturn 70;\n\t\tcase \"provider_unavailable\":\n\t\t\treturn 60;\n\t\tcase \"network_timeout\":\n\t\t\treturn 50;\n\t\tcase \"transport_error\":\n\t\t\treturn 82;\n\t\tcase \"unknown\":\n\t\t\treturn 0;\n\t}\n}\nfunction structuredSignal(\n\tvalue: unknown,\n\tseen: Set<unknown>,\n\tsource?: ModelFallbackFailureSource,\n): ModelFallbackFailureSignal | undefined {\n\tif (value === undefined || value === null || seen.has(value)) return undefined;\n\tif (typeof value === \"object\") seen.add(value);\n\n\tconst stopReason = stopReasonFrom(value)?.toLowerCase();\n\tconst diagnosticType = stringField(value, \"type\");\n\tconst providerTransportSignal =\n\t\tdiagnosticType !== undefined && normalizeCode(diagnosticType) === \"provider_transport_failure\"\n\t\t\t? makeSignal(\"transport_error\", value, source)\n\t\t\t: undefined;\n\tif (stopReason === \"aborted\") return makeSignal(\"cancelled\", value, source);\n\n\t// Defer direct refusal/cancellation signals until nested diagnostics and\n\t// causes have been inspected. A transport wrapper can carry a cancellation\n\t// or provider refusal that must win over the wrapper's transport label.\n\tconst directRefusalSignal = classifyAssistantRefusalSignal(value, source);\n\tconst codeKind = kindFromCode(codeFrom(value));\n\tconst nameKind = kindFromCode(errorName(value));\n\tconst directCancellationSignal =\n\t\tcodeKind === \"cancelled\" || nameKind === \"cancelled\" ? makeSignal(\"cancelled\", value, source) : undefined;\n\n\tlet bestNestedFallbackSignal: ModelFallbackFailureSignal | undefined;\n\tconst nestedSeen = new Set(seen);\n\tconst nestedValues: readonly { value: unknown; source?: ModelFallbackFailureSource }[] = [\n\t\t...diagnosticErrors(value).map((diagnosticError) => ({ value: diagnosticError, source: \"diagnostic\" as const })),\n\t\t...(field(value, \"error\") === undefined ? [] : [{ value: field(value, \"error\"), source }]),\n\t];\n\tfor (const nested of nestedValues) {\n\t\tconst nestedSignal =\n\t\t\tstructuredSignal(nested.value, nestedSeen, nested.source) ??\n\t\t\tfallbackSignalFromMessage(nested.value, nested.source);\n\t\tif (nestedSignal === undefined) continue;\n\t\tif (isRefusalSignal(nestedSignal)) return nestedSignal;\n\t\tif (\n\t\t\tbestNestedFallbackSignal === undefined ||\n\t\t\tnestedSignalPriority(nestedSignal) > nestedSignalPriority(bestNestedFallbackSignal)\n\t\t) {\n\t\t\tbestNestedFallbackSignal = nestedSignal;\n\t\t}\n\t}\n\tconst cause = causeOf(value);\n\tconst causeSignal = structuredSignal(cause, nestedSeen, source) ?? fallbackSignalFromMessage(cause, source);\n\tif (causeSignal !== undefined) {\n\t\tif (isRefusalSignal(causeSignal)) return causeSignal;\n\t\tif (\n\t\t\tbestNestedFallbackSignal === undefined ||\n\t\t\tnestedSignalPriority(causeSignal) > nestedSignalPriority(bestNestedFallbackSignal)\n\t\t) {\n\t\t\tbestNestedFallbackSignal = causeSignal;\n\t\t}\n\t}\n\n\t// This code names the exact cause, so the generic 400 status and its request-error text must not outrank it.\n\tif (\n\t\tdirectRefusalSignal === undefined &&\n\t\tdirectCancellationSignal === undefined &&\n\t\tnormalizeCode(codeFrom(value)) === \"model_not_available_for_integrator\"\n\t)\n\t\treturn makeSignal(\"model_unavailable\", value, source);\n\n\tconst directSignals = [\n\t\tdirectRefusalSignal,\n\t\tdirectCancellationSignal,\n\t\tproviderTransportSignal,\n\t\tfallbackSignalFromDirectMessage(value, source),\n\t\tkindFromStatus(statusFrom(value)) === undefined\n\t\t\t? undefined\n\t\t\t: makeSignal(kindFromStatus(statusFrom(value))!, value, source),\n\t\tkindFromCode(codeFrom(value)) === undefined\n\t\t\t? undefined\n\t\t\t: makeSignal(kindFromCode(codeFrom(value))!, value, source),\n\t\tkindFromCode(errorName(value)) === undefined\n\t\t\t? undefined\n\t\t\t: makeSignal(kindFromCode(errorName(value))!, value, source),\n\t].filter((signal): signal is ModelFallbackFailureSignal => signal !== undefined);\n\tfor (const directSignal of directSignals) {\n\t\tif (isRefusalSignal(directSignal)) return directSignal;\n\t\tif (\n\t\t\tbestNestedFallbackSignal === undefined ||\n\t\t\tnestedSignalPriority(directSignal) > nestedSignalPriority(bestNestedFallbackSignal)\n\t\t) {\n\t\t\tbestNestedFallbackSignal = directSignal;\n\t\t}\n\t}\n\n\tif (bestNestedFallbackSignal !== undefined) return bestNestedFallbackSignal;\n\tif (stopReason === \"error\") return makeSignal(\"provider_unavailable\", value, source);\n\treturn undefined;\n}\n\nfunction messageFromUnknown(value: unknown, seen: Set<unknown>): string | undefined {\n\tif (value === undefined || value === null || seen.has(value)) return undefined;\n\tif (typeof value === \"string\") return value.trim().length > 0 ? value : undefined;\n\tif (typeof value === \"number\" || typeof value === \"boolean\" || typeof value === \"bigint\") return String(value);\n\tif (typeof value === \"symbol\" || typeof value === \"function\") return undefined;\n\tseen.add(value);\n\n\tif (value instanceof Error && value.message.trim().length > 0) return value.message;\n\tconst directMessage = directMessageFrom(value);\n\tif (directMessage !== undefined) return directMessage;\n\tfor (const diagnosticError of diagnosticErrors(value)) {\n\t\tconst diagnosticMessage = messageFromUnknown(diagnosticError, seen);\n\t\tif (diagnosticMessage !== undefined) return diagnosticMessage;\n\t}\n\tconst causeMessage = messageFromUnknown(causeOf(value), seen);\n\tif (causeMessage !== undefined) return causeMessage;\n\tconst finishReason = finishReasonFrom(value);\n\tif (finishReason !== undefined) return `Model request finished with finish_reason:${finishReason}`;\n\tconst stopReason = stopReasonFrom(value);\n\tif (stopReason !== undefined) return `Assistant message ended with stopReason:${stopReason}`;\n\tconst status = statusFrom(value);\n\tif (status !== undefined) return `Model request failed with status ${status}`;\n\tconst code = codeFrom(value);\n\tif (code !== undefined) return `Model request failed with code ${String(code)}`;\n\treturn undefined;\n}\n\nexport function errorMessage(error: unknown): string {\n\tconst structuredMessage = messageFromUnknown(error, new Set());\n\tif (structuredMessage !== undefined) return structuredMessage;\n\tconst rendered = String(error);\n\treturn rendered === \"[object Object]\" ? \"Model request failed\" : rendered;\n}\n\n/** Alias used by the subagent package's older public helper name. */\nexport const modelFailureMessage = errorMessage;\n\n/** The fallback decision each typed GitHub Copilot failure stands for. */\nconst GITHUB_COPILOT_FAILURE_KINDS: Readonly<Record<GitHubCopilotErrorCode, ModelFallbackFailureKind>> = {\n\t\"model-unavailable\": \"model_unavailable\",\n\t\"rate-limited\": \"rate_limit\",\n\t\"quota-exhausted\": \"quota_exhausted\",\n\t\"content-filtered\": \"content_filter\",\n\t\"prompt-too-large\": \"request_incompatible\",\n\t\"invalid-request\": \"request_incompatible\",\n\t\"authentication-failed\": \"auth_on_candidate_provider\",\n\t\"service-unavailable\": \"provider_unavailable\",\n\t\"stream-ended-early\": \"transport_error\",\n\t\"empty-response\": \"transport_error\",\n\t\"unrecognized-response\": \"provider_unavailable\",\n};\n\n/**\n * A GitHub Copilot failure is typed at the provider: its code decides, never its text. The typed error is found on\n * the failure, anywhere in its cause chain, or in the diagnostics of a failed assistant message in that chain, as\n * when a workflow wraps the message.\n */\nfunction githubCopilotSignal(error: unknown): ModelFallbackFailureSignal | undefined {\n\tconst copilotError: GitHubCopilotError | undefined = findGitHubCopilotError(error);\n\tif (copilotError === undefined) return undefined;\n\treturn makeSignal(GITHUB_COPILOT_FAILURE_KINDS[copilotError.code], copilotError, signalSource(error, undefined));\n}\n\nexport function normalizeModelFailureSignal(error: unknown): ModelFallbackFailureSignal {\n\t// Extension startup is not a model request. Its message names extension paths\n\t// and their own errors, which must not read as a provider failure.\n\tif (isExtensionStartupFailure(error)) {\n\t\tconst name = errorName(error);\n\t\treturn {\n\t\t\tkind: \"unknown\",\n\t\t\tmessage: errorMessage(error),\n\t\t\tsource: \"string_fallback\",\n\t\t\t...(name !== undefined ? { name } : {}),\n\t\t};\n\t}\n\tconst copilot = githubCopilotSignal(error);\n\tif (copilot !== undefined) return copilot;\n\tconst structured = structuredSignal(error, new Set());\n\tif (structured !== undefined) return structured;\n\tconst message = errorMessage(error);\n\tconst name = errorName(error);\n\tconst fallbackKind = message.trim().length > 0 ? fallbackKindFromMessage(message, name) : undefined;\n\treturn {\n\t\tkind: fallbackKind ?? \"unknown\",\n\t\tmessage,\n\t\tsource: \"string_fallback\",\n\t\t...(name !== undefined ? { name } : {}),\n\t};\n}\n\n/** Whether a failure is a provider safety/refusal response: a content-filter refusal, or a refused tool call. */\nexport function isSafetyRefusalFailure(error: unknown): boolean {\n\tconst signal = normalizeModelFailureSignal(error);\n\tif (signal.kind === \"content_filter\") return true;\n\tif (signal.kind !== \"task_failure\") return false;\n\tconst text = `${signal.message}\\n${signal.code ?? \"\"}\\n${signal.name ?? \"\"}`;\n\treturn PROVIDER_REFUSAL_FAILURE_PATTERNS.some((pattern) => pattern.test(text));\n}\n\n/** Whether a provider's content filter refused the request, as OpenAI's HTTP 422 `cyber_policy` does. */\nexport function isContentFilterRefusal(error: unknown): boolean {\n\treturn normalizeModelFailureSignal(error).kind === \"content_filter\";\n}\n\n/**\n * True when this failure may spend a configured model fallback candidate. A content-filter refusal does unless\n * `options.fallbackOnContentFilter` is false.\n */\nexport function isRetryableModelFailure(error: unknown, options?: ModelFallbackFailureOptions): boolean {\n\tif (error === undefined) return false;\n\tconst kind = normalizeModelFailureSignal(error).kind;\n\tif (kind === \"content_filter\") return options?.fallbackOnContentFilter !== false;\n\treturn FALLBACKABLE_FAILURE_KINDS.has(kind);\n}\n\nconst SAME_MODEL_RETRYABLE_FAILURE_KINDS: ReadonlySet<ModelFallbackFailureKind> = new Set([\n\t\"rate_limit\",\n\t\"provider_unavailable\",\n\t\"network_timeout\",\n\t\"transport_error\",\n]);\n\n/**\n * An assistant error that only its `stopReason` marks as a model failure: no status, code or name, and text that no\n * pattern recognizes. It may spend a fallback candidate, but it is not retried on the same model on its own.\n */\nfunction isUnrecognizedSignal(signal: ModelFallbackFailureSignal): boolean {\n\treturn (\n\t\tsignal.kind === \"provider_unavailable\" &&\n\t\tsignal.source === \"assistant_message\" &&\n\t\tsignal.status === undefined &&\n\t\tsignal.code === undefined &&\n\t\tsignal.name === undefined &&\n\t\t!RETRYABLE_MODEL_FAILURE_PATTERNS.some((pattern) => pattern.test(signal.message))\n\t);\n}\n\n/** True when the same model may be requested again before fallback advances. */\nexport function isRetryableSameModelFailure(error: unknown): boolean {\n\tif (!isRetryableModelFailure(error)) return false;\n\tconst signal = normalizeModelFailureSignal(error);\n\treturn SAME_MODEL_RETRYABLE_FAILURE_KINDS.has(signal.kind) && !isUnrecognizedSignal(signal);\n}\n\n/**\n * True for a failure that may spend a fallback candidate although nothing recognizes it: an assistant error with no\n * status, code or name whose text matches no known pattern. A session with a fallback chain retries it on the same\n * model first, so such an error never switches models on its first occurrence (#4223).\n */\nexport function isUnrecognizedModelFailure(error: unknown): boolean {\n\treturn isRetryableModelFailure(error) && isUnrecognizedSignal(normalizeModelFailureSignal(error));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"model-fallback-failures.js","sourceRoot":"","sources":["../../src/core/model-fallback-failures.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACN,sBAAsB,EAGtB,kCAAkC,GAClC,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAE3E,MAAM,gCAAgC,GAAsB;IAC3D,eAAe;IACf,wBAAwB;IACxB,wBAAwB;IACxB,SAAS;IACT,QAAQ;IACR,oBAAoB;IACpB,UAAU;IACV,SAAS;IACT,gCAAgC;IAChC,kBAAkB;IAClB,YAAY;IACZ,gBAAgB;IAChB,sBAAsB;IACtB,sCAAsC;IACtC,+CAA+C;IAC/C,Y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AAED,MAAM,kCAAkC,GAA0C,IAAI,GAAG,CAAC;IACzF,YAAY;IACZ,sBAAsB;IACtB,iBAAiB;IACjB,iBAAiB;CACjB,CAAC,CAAC;AAEH;;;GAGG;AACH,SAAS,oBAAoB,CAAC,MAAkC;IAC/D,OAAO,CACN,MAAM,CAAC,IAAI,KAAK,sBAAsB;QACtC,MAAM,CAAC,MAAM,KAAK,mBAAmB;QACrC,MAAM,CAAC,MAAM,KAAK,SAAS;QAC3B,MAAM,CAAC,IAAI,KAAK,SAAS;QACzB,MAAM,CAAC,IAAI,KAAK,SAAS;QACzB,CAAC,gCAAgC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CACjF,CAAC;AACH,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,2BAA2B,CAAC,KAAc;IACzD,IAAI,CAAC,uBAAuB,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAClD,MAAM,MAAM,GAAG,2BAA2B,CAAC,KAAK,CAAC,CAAC;IAClD,OAAO,kCAAkC,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC;AAC7F,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,0BAA0B,CAAC,KAAc;IACxD,OAAO,uBAAuB,CAAC,KAAK,CAAC,IAAI,oBAAoB,CAAC,2BAA2B,CAAC,KAAK,CAAC,CAAC,CAAC;AACnG,CAAC","sourcesContent":["/**\n * Shared model/provider failure classification.\n *\n * Workflows, subagents, and the main chat all need the same decision about\n * whether a provider failure may spend another model candidate. Keep this\n * module free of AgentSession and workflow imports so the published SDK can\n * expose it to the raw-TypeScript companion packages without a cycle.\n */\n\nimport {\n\tfindGitHubCopilotError,\n\ttype GitHubCopilotError,\n\ttype GitHubCopilotErrorCode,\n\tGitHubCopilotStreamEndedEarlyError,\n} from \"@bastani/pi-ai\";\nimport { isExtensionStartupFailure } from \"./extension-startup-failure.ts\";\n\nconst RETRYABLE_MODEL_FAILURE_PATTERNS: readonly RegExp[] = [\n\t/rate\\s*limit/i,\n\t/too\\s*many\\s*requests/i,\n\t/\\bthrottl(?:ing|ed)\\b/i,\n\t/\\b429\\b/,\n\t/quota/i,\n\t/usage[\\s_-]*limit/i,\n\t/billing/i,\n\t/credit/i,\n\t/auth(?:entication|orization)?/i,\n\t/unauthori[sz]ed/i,\n\t/\\b40[13]\\b/,\n\t/api[_\\s-]*key/i,\n\t/token[_\\s-]*expired/i,\n\t/token[_\\s-]*(?:revoked|invalidated)/i,\n\t/invalidated[_\\s-]+(?:oauth|auth)[_\\s-]+token/i,\n\t/forbidden/i,\n\t/invalid\\s*key/i,\n\t/overloaded/i,\n\t/temporarily\\s*unavailable/i,\n\t/service\\s*unavailable/i,\n\t/network/i,\n\t/fetch/i,\n\t/getaddrinfo/i,\n\t/ENOTFOUND/i,\n\t/EAI_AGAIN/i,\n\t/socket/i,\n\t/connection\\s*refused/i,\n\t/upstream/i,\n\t/timeout/i,\n\t/timed\\s*out/i,\n\t/\\b50[0-4]\\b/,\n\t/\\b52[0-4]\\b/,\n\t/\\b529\\b/,\n\t/provider.?returned.?error/i,\n\t/server.?error/i,\n\t/internal.?error/i,\n\t/connection.?error/i,\n\t/connection.?lost/i,\n\t/connection.?reset/i,\n\t/ECONNRESET/i,\n\t/other side closed/i,\n\t/websocket.?closed/i,\n\t/websocket.?error/i,\n\t/reset before headers/i,\n\t/socket hang up/i,\n\t/ended without/i,\n\t/stream ended before message_stop/i,\n\t/stream ended before a terminal response event/i,\n\t/http2 request did not get a response/i,\n\t/pending stream has been canceled/i,\n\t/retry delay/i,\n\t/finish.?reason:?\\s*error/i,\n\t/terminated/i,\n\t/you can retry your request/i,\n\t/try your request again/i,\n\t/please retry your request/i,\n\t// gRPC based providers (e.g. NVIDIA NIM); upstream pi-ai retries this too.\n\t/ResourceExhausted/i,\n];\n\nconst NON_RETRYABLE_FAILURE_PATTERNS: readonly RegExp[] = [\n\t/command failed/i,\n\t/tests? failed/i,\n\t/shell/i,\n\t/missing file/i,\n\t/no such file/i,\n\t/cancel/i,\n\t/abort/i,\n\t/interrupted/i,\n];\n\nconst CANCELLED_FAILURE_PATTERNS: readonly RegExp[] = [/cancel/i, /abort/i, /interrupted/i];\n\nconst TRANSPORT_CANCELLATION_FAILURE_PATTERNS: readonly RegExp[] = [\n\t/getaddrinfo|ENOTFOUND|EAI_AGAIN/i,\n\t/pending stream has been canceled/i,\n];\n\nexport type ModelFallbackFailureKind =\n\t| \"auth_on_candidate_provider\"\n\t| \"rate_limit\"\n\t| \"quota_exhausted\"\n\t| \"provider_unavailable\"\n\t| \"network_timeout\"\n\t| \"transport_error\"\n\t| \"model_unavailable\"\n\t| \"request_incompatible\"\n\t| \"content_filter\"\n\t| \"cancelled\"\n\t| \"task_failure\"\n\t| \"unknown\";\n\nexport type ModelFallbackFailureSource =\n\t| \"assistant_message\"\n\t| \"diagnostic\"\n\t| \"throw\"\n\t| \"structured\"\n\t| \"string_fallback\";\n\nexport interface ModelFallbackFailureSignal {\n\treadonly kind: ModelFallbackFailureKind;\n\treadonly message: string;\n\treadonly source: ModelFallbackFailureSource;\n\treadonly stopReason?: string;\n\treadonly status?: number;\n\treadonly code?: string | number;\n\treadonly name?: string;\n}\n\n/** How a caller treats a provider content-filter refusal; `retry.fallbackOnContentFilter` in settings. */\nexport interface ModelFallbackFailureOptions {\n\t/** Whether a content-filter refusal may spend the next fallback candidate. Defaults to true. */\n\treadonly fallbackOnContentFilter?: boolean;\n}\n\nconst FALLBACKABLE_FAILURE_KINDS: ReadonlySet<ModelFallbackFailureKind> = new Set([\n\t\"auth_on_candidate_provider\",\n\t\"rate_limit\",\n\t\"quota_exhausted\",\n\t\"provider_unavailable\",\n\t\"network_timeout\",\n\t\"transport_error\",\n\t\"model_unavailable\",\n\t\"request_incompatible\",\n]);\n\nfunction asRecord(value: unknown): Record<string, unknown> | undefined {\n\treturn value !== null && typeof value === \"object\" ? (value as Record<string, unknown>) : undefined;\n}\n\nfunction field(value: unknown, key: string): unknown {\n\treturn asRecord(value)?.[key];\n}\n\nfunction stringField(value: unknown, key: string): string | undefined {\n\tconst raw = field(value, key);\n\treturn typeof raw === \"string\" && raw.trim().length > 0 ? raw : undefined;\n}\n\nfunction errorName(value: unknown): string | undefined {\n\treturn value instanceof Error ? value.name : stringField(value, \"name\");\n}\n\nfunction directMessageFrom(value: unknown): string | undefined {\n\treturn stringField(value, \"errorMessage\") ?? stringField(value, \"message\") ?? stringField(value, \"statusText\");\n}\n\nfunction integerFrom(value: unknown): number | undefined {\n\tif (typeof value === \"number\" && Number.isInteger(value)) return value;\n\tif (typeof value !== \"string\" || value.trim().length === 0) return undefined;\n\tconst parsed = Number(value.trim());\n\treturn Number.isInteger(parsed) ? parsed : undefined;\n}\n\nfunction statusFrom(value: unknown): number | undefined {\n\treturn (\n\t\tintegerFrom(field(value, \"status\")) ??\n\t\tintegerFrom(field(value, \"statusCode\")) ??\n\t\tintegerFrom(field(value, \"httpStatus\"))\n\t);\n}\n\nfunction codeFrom(value: unknown): string | number | undefined {\n\tconst rawCode = field(value, \"code\");\n\tif (typeof rawCode === \"string\" || typeof rawCode === \"number\") return rawCode;\n\t// Provider failure diagnostics (`bedrock_response_failure`) keep the modeled error code in `details.errorCode`,\n\t// because the provider's display message replaces the exception name with a readable prefix.\n\tconst detailsCode = field(field(value, \"details\"), \"errorCode\");\n\treturn typeof detailsCode === \"string\" ? detailsCode : undefined;\n}\n\nfunction stopReasonFrom(value: unknown): string | undefined {\n\treturn stringField(value, \"stopReason\");\n}\n\nfunction finishReasonFrom(value: unknown): string | undefined {\n\treturn stringField(value, \"finish_reason\") ?? stringField(value, \"finishReason\");\n}\n\nfunction causeOf(value: unknown): unknown {\n\treturn value instanceof Error ? value.cause : field(value, \"cause\");\n}\n\nfunction diagnosticErrors(value: unknown): readonly unknown[] {\n\tconst diagnostics = field(value, \"diagnostics\");\n\tif (!Array.isArray(diagnostics)) return [];\n\tconst errors: unknown[] = [];\n\tfor (const diagnostic of diagnostics) {\n\t\tconst diagnosticType = stringField(diagnostic, \"type\");\n\t\tconst diagnosticError = field(diagnostic, \"error\");\n\t\terrors.push(\n\t\t\tnormalizeCode(diagnosticType) === \"provider_transport_failure\" ? diagnostic : (diagnosticError ?? diagnostic),\n\t\t);\n\t}\n\treturn errors;\n}\n\nfunction normalizeCode(value: string | number | undefined): string | undefined {\n\tif (value === undefined) return undefined;\n\tconst raw = String(value).trim().toLowerCase();\n\tif (!raw) return undefined;\n\tlet normalized = \"\";\n\tlet needsSeparator = false;\n\tfor (const char of raw) {\n\t\tconst code = char.charCodeAt(0);\n\t\tconst isLowerAlpha = code >= 97 && code <= 122;\n\t\tconst isDigit = code >= 48 && code <= 57;\n\t\tif (isLowerAlpha || isDigit) {\n\t\t\tnormalized += char;\n\t\t\tneedsSeparator = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (needsSeparator && normalized[normalized.length - 1] !== \"_\") normalized += \"_\";\n\t}\n\tif (normalized.endsWith(\"_\")) normalized = normalized.slice(0, -1);\n\treturn normalized.length > 0 ? normalized : undefined;\n}\n\nfunction messageLooksLikeModelUnavailable(message: string): boolean {\n\tconst lower = message.toLowerCase();\n\treturn (\n\t\tlower.includes(\"model\") &&\n\t\t(lower.includes(\"unavailable\") ||\n\t\t\tlower.includes(\"disabled\") ||\n\t\t\tlower.includes(\"not found\") ||\n\t\t\tlower.includes(\"unknown\"))\n\t);\n}\n\nfunction kindFromStatus(status: number | undefined): ModelFallbackFailureKind | undefined {\n\tswitch (status) {\n\t\tcase 400:\n\t\tcase 413:\n\t\tcase 422:\n\t\t\treturn \"request_incompatible\";\n\t\tcase 401:\n\t\tcase 403:\n\t\t\treturn \"auth_on_candidate_provider\";\n\t\tcase 408:\n\t\t\treturn \"network_timeout\";\n\t\tcase 404:\n\t\t\treturn \"model_unavailable\";\n\t\tcase 402:\n\t\t\treturn \"quota_exhausted\";\n\t\tcase 429:\n\t\t\treturn \"rate_limit\";\n\t\tdefault:\n\t\t\tif (status !== undefined && status >= 500 && status <= 599) return \"provider_unavailable\";\n\t\t\treturn undefined;\n\t}\n}\n\nfunction refusalKindFromCode(code: string | number | undefined): ModelFallbackFailureKind | undefined {\n\tconst normalizedCode = normalizeCode(code);\n\tif (normalizedCode === undefined) return undefined;\n\t// A refused tool call, such as `tool_call_refusal` or `tool_use_refused_by_policy`, before the policy words.\n\tif (/(?:^|_)tool(?:_|$)/.test(normalizedCode) && normalizedCode.includes(\"refus\")) return \"task_failure\";\n\tif (normalizedCode.includes(\"content_filter\") || normalizedCode.includes(\"contentfilter\")) return \"content_filter\";\n\t// Includes OpenAI's `cyber_policy`.\n\tif (normalizedCode.includes(\"safety\") || normalizedCode.includes(\"policy\")) return \"content_filter\";\n\tswitch (normalizedCode) {\n\t\tcase \"blocked\":\n\t\tcase \"blocked_by_provider\":\n\t\tcase \"blocked_by_safety\":\n\t\tcase \"blocked_by_policy\":\n\t\tcase \"provider_refusal\":\n\t\tcase \"refusal\":\n\t\t\treturn \"content_filter\";\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n}\n\nconst REQUEST_INCOMPATIBLE_CODES: ReadonlySet<string> = new Set([\n\t\"invalid_request\",\n\t\"invalid_request_error\",\n\t\"bad_request\",\n\t\"context_length_exceeded\",\n\t\"request_too_large\",\n\t\"too_large\",\n\t\"request_entity_too_large\",\n\t\"max_tokens\",\n\t\"max_context_length\",\n\t\"context_window_exceeded\",\n]);\n\nfunction requestIncompatibleKindFromCode(code: string | number | undefined): ModelFallbackFailureKind | undefined {\n\tconst normalized = normalizeCode(code);\n\treturn normalized !== undefined && REQUEST_INCOMPATIBLE_CODES.has(normalized) ? \"request_incompatible\" : undefined;\n}\n\nfunction kindFromCode(code: string | number | undefined): ModelFallbackFailureKind | undefined {\n\tconst normalizedCode = normalizeCode(code);\n\tif (normalizedCode === undefined) return undefined;\n\tconst refusalKind = refusalKindFromCode(code);\n\tif (refusalKind !== undefined) return refusalKind;\n\tconst httpStatusKind = kindFromStatus(integerFrom(code));\n\tif (httpStatusKind !== undefined) return httpStatusKind;\n\tconst requestIncompatibleKind = requestIncompatibleKindFromCode(code);\n\tif (requestIncompatibleKind !== undefined) return requestIncompatibleKind;\n\n\tswitch (normalizedCode) {\n\t\tcase \"auth\":\n\t\tcase \"auth_required\":\n\t\tcase \"authentication_required\":\n\t\tcase \"unauthorized\":\n\t\tcase \"forbidden\":\n\t\tcase \"invalid_api_key\":\n\t\tcase \"missing_api_key\":\n\t\tcase \"invalid_key\":\n\t\tcase \"token_expired\":\n\t\tcase \"token_revoked\":\n\t\tcase \"token_invalidated\":\n\t\tcase \"oauth_token_invalidated\":\n\t\t\treturn \"auth_on_candidate_provider\";\n\t\tcase \"etimedout\":\n\t\tcase \"econnreset\":\n\t\tcase \"econnrefused\":\n\t\tcase \"enotfound\":\n\t\tcase \"eai_again\":\n\t\tcase \"fetch_failed\":\n\t\tcase \"network_error\":\n\t\tcase \"timeout\":\n\t\tcase \"timeout_error\":\n\t\tcase \"und_err_connect_timeout\":\n\t\t\treturn \"network_timeout\";\n\t\tcase \"rate_limit\":\n\t\tcase \"rate_limit_exceeded\":\n\t\tcase \"too_many_requests\":\n\t\tcase \"throttlingexception\":\n\t\t\treturn \"rate_limit\";\n\t\tcase \"quota_exceeded\":\n\t\tcase \"insufficient_quota\":\n\t\tcase \"usage_limit\":\n\t\tcase \"usage_limit_reached\":\n\t\tcase \"usage_limit_exceeded\":\n\t\tcase \"payment_required\":\n\t\tcase \"servicequotaexceededexception\":\n\t\t\treturn \"quota_exhausted\";\n\t\tcase \"aborterror\":\n\t\tcase \"aborted\":\n\t\tcase \"cancelled\":\n\t\tcase \"canceled\":\n\t\t\treturn \"cancelled\";\n\t\tcase \"model_not_found\":\n\t\tcase \"model_unavailable\":\n\t\tcase \"model_disabled\":\n\t\tcase \"unknown_model\":\n\t\tcase \"model_not_available_for_integrator\":\n\t\t\treturn \"model_unavailable\";\n\t\tcase \"provider_error\":\n\t\tcase \"api_error\":\n\t\tcase \"service_unavailable\":\n\t\tcase \"temporarily_unavailable\":\n\t\tcase \"overloaded\":\n\t\t\treturn \"provider_unavailable\";\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n}\n\nconst REQUEST_INCOMPATIBLE_FAILURE_PATTERNS: readonly RegExp[] = [\n\t/\\bcontext[_\\s-]?length(?:[_\\s-]?exceeded)?\\b/i,\n\t/\\bcontext[_\\s-]?window(?:[_\\s-]?exceeded)?\\b/i,\n\t/\\bmax[_\\s-]?context\\b/i,\n\t/\\bmax[_\\s-]?tokens?\\b/i,\n\t/\\brequest(?:[_\\s-]?entity)?[_\\s-]?too[_\\s-]?large\\b/i,\n\t/\\btoo[_\\s-]?large\\b/i,\n\t/\\b(?:unsupported|unknown|invalid)\\s+(?:tool|parameter|function)\\b/i,\n\t/\\b(?:tool|parameter|function)\\s+(?:not\\s+(?:supported|found|allowed)|unknown|invalid)\\b/i,\n\t/\\binvalid[_\\s-]?request(?:[_\\s-]?error)?\\b/i,\n\t/\\bbad[_\\s-]?request\\b/i,\n];\n\n/** A provider declined the request's content under its usage policy: the model will refuse it again. */\nconst CONTENT_FILTER_FAILURE_PATTERNS: readonly RegExp[] = [\n\t/\\bthe\\s+model\\s+refused\\s+to\\s+complete\\s+the\\s+request\\b/i,\n\t/\\bfinish[_\\s-]?reason\\b[^\\n]*\\bcontent[_\\s-]?filter\\b/i,\n\t/\\bcontent[_\\s-]?filter(?:ed|ing)?\\b/i,\n\t/\\bcyber[_\\s-]?policy\\b/i,\n\t// OpenAI's cyber safeguard: \"This content was flagged for possible cybersecurity risk.\"\n\t/\\bflagged\\s+for\\s+(?:possible|potential(?:ly)?)\\b[^\\n]*\\b(?:risk|harm(?:ful)?|safety|policy|cyber\\w*)\\b/i,\n\t/\\b(?:safety|policy)\\b[^\\n]*\\b(?:refus(?:e|al|ed|es|ing)?|block(?:ed|ing)?|filter(?:ed|ing)?|violat(?:e|ion|ed|ing)?|disallow(?:ed|ing)?|reject(?:ed|ion|ing)?)\\b/i,\n\t/\\b(?:refus(?:e|al|ed|es|ing)?|block(?:ed|ing)?|filter(?:ed|ing)?|violat(?:e|ion|ed|ing)?|disallow(?:ed|ing)?|reject(?:ed|ion|ing)?)\\b[^\\n]*\\b(?:safety|policy)\\b/i,\n\t/\\bprovider[_\\s-]?refus(?:e|al|ed|es|ing)?\\b/i,\n\t/\\bprovider\\b[^\\n]*\\brefus(?:e|al|ed|es|ing)?\\b[^\\n]*\\b(?:prompt|request|content|policy|safety)\\b/i,\n];\n\nconst TOOL_REFUSAL_FAILURE_PATTERNS: readonly RegExp[] = [\n\t/\\btool[_\\s-]?(?:call|use)?[_\\s-]?refus(?:e|al|ed|es|ing)?\\b/i,\n\t/\\btool(?:\\s+call|\\s+use)?\\b[^\\n]*\\brefus(?:e|al|ed|es|ing)?\\b/i,\n\t/\\brefus(?:e|al|ed|es|ing)?\\b[^\\n]*\\btool(?:\\s+call|\\s+use)?\\b/i,\n];\n\nconst PROVIDER_REFUSAL_FAILURE_PATTERNS: readonly RegExp[] = [\n\t...CONTENT_FILTER_FAILURE_PATTERNS,\n\t...TOOL_REFUSAL_FAILURE_PATTERNS,\n];\n\nconst TRANSPORT_OUTAGE_FAILURE_PATTERNS: readonly RegExp[] = [\n\t/^connection\\s+error\\.?$/i,\n\t/^fetch\\s+failed\\.?$/i,\n\t// Response-body decompression failures reported by Node/Bun zlib, optionally\n\t// behind the fetch/WebSocket layer's \"Library error:\" wrapper. GitHub Copilot\n\t// on the default `transport: \"auto\"` surfaces this as\n\t// \"Library error: zlib error: incorrect header check\" (#2553). These are\n\t// unanchored because the wrapper text varies by runtime and transport. `zlib`\n\t// has no trailing word boundary on purpose: Bun 1.4.0, the shipped runtime\n\t// when verified, throws `ZlibError fetching \"...\"` as one word.\n\t/\\bzlib/i,\n\t/\\bincorrect\\s+header\\s+check\\b/i,\n\t/\\bdecompress(?:ion|ing|ed)?\\b/i,\n\t/^library\\s+error\\b/i,\n\t// Idle-stream deadline enforced below the HTTP layer by pi-ai's\n\t// `withStreamDeadline`, so a stalled stream fails over instead of hanging.\n\t/\\bstream\\s+deadline\\s+exceeded\\b/i,\n\t// A streamed response cut off before its finish reason, as GitHub Copilot's Gemini models do now and then: the\n\t// same request normally completes when sent again (#4223).\n\t/\\bstream\\s+ended\\s+without\\s+finish[_\\s-]?reason\\b/i,\n];\n\n// HTTP 402 and explicit quota exhaustion: the account cannot be served again until its quota resets.\n// Codes that also appear as free-text wording for short limits (\"quota exceeded\", \"usage limit reached\")\n// count only as a JSON `code`/`type` value, as in a raw error body some providers put in the message.\n// A service-quota exception and a per-day quota violation in a JSON error body (`\"quotaId\": \"...PerDay...\"`)\n// also last until the quota resets.\nconst QUOTA_EXHAUSTED_FAILURE_PATTERN =\n\t/(?<![a-z0-9.])402(?![a-z0-9.])|payment[_\\s-]*required|insufficient[_\\s-]*quota|\\bServiceQuotaExceededException\\b|\"quotaId\"\\s*:\\s*\"[^\"]*PerDay|\"(?:code|type|error_code)\"\\s*:\\s*\"(?:quota_exceeded|usage_limit|usage_limit_reached|usage_limit_exceeded)\"/i;\n\nfunction transportOutageKindFromMessage(message: string): ModelFallbackFailureKind | undefined {\n\treturn TRANSPORT_OUTAGE_FAILURE_PATTERNS.some((pattern) => pattern.test(message.trim()))\n\t\t? \"transport_error\"\n\t\t: undefined;\n}\n\nfunction refusalKindFromMessage(message: string): ModelFallbackFailureKind | undefined {\n\tif (TRANSPORT_CANCELLATION_FAILURE_PATTERNS.some((pattern) => pattern.test(message))) return \"network_timeout\";\n\tif (CANCELLED_FAILURE_PATTERNS.some((pattern) => pattern.test(message))) return \"cancelled\";\n\tif (NON_RETRYABLE_FAILURE_PATTERNS.some((pattern) => pattern.test(message))) return \"task_failure\";\n\t// A refused tool call is about that call, whatever policy the provider names: another model is asked the same\n\t// tool call. So it is checked before the content-filter grammar, which \"refused ... safety policy\" also matches.\n\tif (TOOL_REFUSAL_FAILURE_PATTERNS.some((pattern) => pattern.test(message))) return \"task_failure\";\n\tif (CONTENT_FILTER_FAILURE_PATTERNS.some((pattern) => pattern.test(message))) return \"content_filter\";\n\treturn undefined;\n}\n\nfunction fallbackKindFromMessage(message: string, name: string | undefined): ModelFallbackFailureKind | undefined {\n\tconst refusalKind = refusalKindFromMessage(message);\n\tif (refusalKind !== undefined) return refusalKind;\n\tconst transportOutageKind = transportOutageKindFromMessage(message);\n\tif (transportOutageKind !== undefined) return transportOutageKind;\n\tif (REQUEST_INCOMPATIBLE_FAILURE_PATTERNS.some((pattern) => pattern.test(message))) return \"request_incompatible\";\n\tconst nameKind = kindFromCode(name);\n\tif (nameKind !== undefined) return nameKind;\n\tif (QUOTA_EXHAUSTED_FAILURE_PATTERN.test(message)) return \"quota_exhausted\";\n\tconst hasRetryablePattern =\n\t\tRETRYABLE_MODEL_FAILURE_PATTERNS.some((pattern) => pattern.test(message)) ||\n\t\tmessageLooksLikeModelUnavailable(message);\n\tif (!hasRetryablePattern) return undefined;\n\tif (\n\t\t/rate\\s*limit|too\\s*many\\s*requests|\\bthrottl(?:ing|ed)\\b|\\b429\\b|quota|usage[\\s_-]*limit|billing|credit/i.test(\n\t\t\tmessage,\n\t\t)\n\t)\n\t\treturn \"rate_limit\";\n\tif (\n\t\t/auth|unauthori[sz]ed|\\b40[13]\\b|api[_\\s-]*key|token[_\\s-]*(?:expired|revoked|invalidated|rejected)|forbidden|invalid[_\\s-]*key/i.test(\n\t\t\tmessage,\n\t\t)\n\t)\n\t\treturn \"auth_on_candidate_provider\";\n\tif (messageLooksLikeModelUnavailable(message)) return \"model_unavailable\";\n\tif (/network|fetch|socket|connection\\s*refused|getaddrinfo|ENOTFOUND|EAI_AGAIN|timeout|timed\\s*out/i.test(message))\n\t\treturn \"network_timeout\";\n\treturn \"provider_unavailable\";\n}\n\nfunction signalSource(value: unknown, fallback: ModelFallbackFailureSource | undefined): ModelFallbackFailureSource {\n\tif (fallback !== undefined) return fallback;\n\tif (stopReasonFrom(value) !== undefined || diagnosticErrors(value).length > 0) return \"assistant_message\";\n\tif (value instanceof Error) return \"throw\";\n\treturn \"structured\";\n}\n\nfunction makeSignal(\n\tkind: ModelFallbackFailureKind,\n\tvalue: unknown,\n\tsource: ModelFallbackFailureSource | undefined,\n): ModelFallbackFailureSignal {\n\tconst status = statusFrom(value);\n\tconst code = codeFrom(value);\n\tconst name = errorName(value);\n\tconst stopReason = stopReasonFrom(value);\n\treturn {\n\t\tkind,\n\t\tmessage: errorMessage(value),\n\t\tsource: signalSource(value, source),\n\t\t...(stopReason !== undefined ? { stopReason } : {}),\n\t\t...(status !== undefined ? { status } : {}),\n\t\t...(code !== undefined ? { code } : {}),\n\t\t...(name !== undefined ? { name } : {}),\n\t};\n}\n\nfunction fallbackSignalFromDirectMessage(\n\tvalue: unknown,\n\tsource: ModelFallbackFailureSource | undefined,\n): ModelFallbackFailureSignal | undefined {\n\tconst message = directMessageFrom(value);\n\tif (message === undefined) return undefined;\n\tconst kind = fallbackKindFromMessage(message, errorName(value));\n\treturn kind === undefined ? undefined : makeSignal(kind, value, source);\n}\n\nfunction fallbackSignalFromMessage(\n\tvalue: unknown,\n\tsource: ModelFallbackFailureSource | undefined,\n): ModelFallbackFailureSignal | undefined {\n\tconst message = errorMessage(value);\n\tif (!message.trim()) return undefined;\n\tconst kind = fallbackKindFromMessage(message, errorName(value));\n\treturn kind === undefined ? undefined : makeSignal(kind, value, source);\n}\n\nfunction classifyAssistantRefusalSignal(\n\tvalue: unknown,\n\tsource: ModelFallbackFailureSource | undefined,\n): ModelFallbackFailureSignal | undefined {\n\tconst codeRefusalKind =\n\t\trefusalKindFromCode(codeFrom(value)) ??\n\t\trefusalKindFromCode(errorName(value)) ??\n\t\trefusalKindFromCode(finishReasonFrom(value));\n\tif (codeRefusalKind !== undefined) return makeSignal(codeRefusalKind, value, source);\n\n\tconst messageRefusalKind = refusalKindFromMessage(directMessageFrom(value) ?? \"\");\n\treturn messageRefusalKind === undefined ? undefined : makeSignal(messageRefusalKind, value, source);\n}\n\nfunction isRefusalSignal(signal: ModelFallbackFailureSignal): boolean {\n\treturn signal.kind === \"cancelled\" || signal.kind === \"task_failure\" || signal.kind === \"content_filter\";\n}\n\nfunction nestedSignalPriority(signal: ModelFallbackFailureSignal): number {\n\tswitch (signal.kind) {\n\t\tcase \"cancelled\":\n\t\tcase \"task_failure\":\n\t\tcase \"content_filter\":\n\t\t\treturn 100;\n\t\tcase \"auth_on_candidate_provider\":\n\t\t\treturn 90;\n\t\tcase \"request_incompatible\":\n\t\t\treturn 85;\n\t\tcase \"model_unavailable\":\n\t\t\treturn 80;\n\t\tcase \"quota_exhausted\":\n\t\t\treturn 75;\n\t\tcase \"rate_limit\":\n\t\t\treturn 70;\n\t\tcase \"provider_unavailable\":\n\t\t\treturn 60;\n\t\tcase \"network_timeout\":\n\t\t\treturn 50;\n\t\tcase \"transport_error\":\n\t\t\treturn 82;\n\t\tcase \"unknown\":\n\t\t\treturn 0;\n\t}\n}\nfunction structuredSignal(\n\tvalue: unknown,\n\tseen: Set<unknown>,\n\tsource?: ModelFallbackFailureSource,\n): ModelFallbackFailureSignal | undefined {\n\tif (value === undefined || value === null || seen.has(value)) return undefined;\n\tif (typeof value === \"object\") seen.add(value);\n\n\tconst stopReason = stopReasonFrom(value)?.toLowerCase();\n\tconst diagnosticType = stringField(value, \"type\");\n\tconst providerTransportSignal =\n\t\tdiagnosticType !== undefined && normalizeCode(diagnosticType) === \"provider_transport_failure\"\n\t\t\t? makeSignal(\"transport_error\", value, source)\n\t\t\t: undefined;\n\tif (stopReason === \"aborted\") return makeSignal(\"cancelled\", value, source);\n\n\t// Defer direct refusal/cancellation signals until nested diagnostics and\n\t// causes have been inspected. A transport wrapper can carry a cancellation\n\t// or provider refusal that must win over the wrapper's transport label.\n\tconst directRefusalSignal = classifyAssistantRefusalSignal(value, source);\n\tconst codeKind = kindFromCode(codeFrom(value));\n\tconst nameKind = kindFromCode(errorName(value));\n\tconst directCancellationSignal =\n\t\tcodeKind === \"cancelled\" || nameKind === \"cancelled\" ? makeSignal(\"cancelled\", value, source) : undefined;\n\n\tlet bestNestedFallbackSignal: ModelFallbackFailureSignal | undefined;\n\tconst nestedSeen = new Set(seen);\n\tconst nestedValues: readonly { value: unknown; source?: ModelFallbackFailureSource }[] = [\n\t\t...diagnosticErrors(value).map((diagnosticError) => ({ value: diagnosticError, source: \"diagnostic\" as const })),\n\t\t...(field(value, \"error\") === undefined ? [] : [{ value: field(value, \"error\"), source }]),\n\t];\n\tfor (const nested of nestedValues) {\n\t\tconst nestedSignal =\n\t\t\tstructuredSignal(nested.value, nestedSeen, nested.source) ??\n\t\t\tfallbackSignalFromMessage(nested.value, nested.source);\n\t\tif (nestedSignal === undefined) continue;\n\t\tif (isRefusalSignal(nestedSignal)) return nestedSignal;\n\t\tif (\n\t\t\tbestNestedFallbackSignal === undefined ||\n\t\t\tnestedSignalPriority(nestedSignal) > nestedSignalPriority(bestNestedFallbackSignal)\n\t\t) {\n\t\t\tbestNestedFallbackSignal = nestedSignal;\n\t\t}\n\t}\n\tconst cause = causeOf(value);\n\tconst causeSignal = structuredSignal(cause, nestedSeen, source) ?? fallbackSignalFromMessage(cause, source);\n\tif (causeSignal !== undefined) {\n\t\tif (isRefusalSignal(causeSignal)) return causeSignal;\n\t\tif (\n\t\t\tbestNestedFallbackSignal === undefined ||\n\t\t\tnestedSignalPriority(causeSignal) > nestedSignalPriority(bestNestedFallbackSignal)\n\t\t) {\n\t\t\tbestNestedFallbackSignal = causeSignal;\n\t\t}\n\t}\n\n\t// This code names the exact cause, so the generic 400 status and its request-error text must not outrank it.\n\tif (\n\t\tdirectRefusalSignal === undefined &&\n\t\tdirectCancellationSignal === undefined &&\n\t\tnormalizeCode(codeFrom(value)) === \"model_not_available_for_integrator\"\n\t)\n\t\treturn makeSignal(\"model_unavailable\", value, source);\n\n\tconst directSignals = [\n\t\tdirectRefusalSignal,\n\t\tdirectCancellationSignal,\n\t\tproviderTransportSignal,\n\t\tfallbackSignalFromDirectMessage(value, source),\n\t\tkindFromStatus(statusFrom(value)) === undefined\n\t\t\t? undefined\n\t\t\t: makeSignal(kindFromStatus(statusFrom(value))!, value, source),\n\t\tkindFromCode(codeFrom(value)) === undefined\n\t\t\t? undefined\n\t\t\t: makeSignal(kindFromCode(codeFrom(value))!, value, source),\n\t\tkindFromCode(errorName(value)) === undefined\n\t\t\t? undefined\n\t\t\t: makeSignal(kindFromCode(errorName(value))!, value, source),\n\t].filter((signal): signal is ModelFallbackFailureSignal => signal !== undefined);\n\tfor (const directSignal of directSignals) {\n\t\tif (isRefusalSignal(directSignal)) return directSignal;\n\t\tif (\n\t\t\tbestNestedFallbackSignal === undefined ||\n\t\t\tnestedSignalPriority(directSignal) > nestedSignalPriority(bestNestedFallbackSignal)\n\t\t) {\n\t\t\tbestNestedFallbackSignal = directSignal;\n\t\t}\n\t}\n\n\tif (bestNestedFallbackSignal !== undefined) return bestNestedFallbackSignal;\n\tif (stopReason === \"error\") return makeSignal(\"provider_unavailable\", value, source);\n\treturn undefined;\n}\n\nfunction messageFromUnknown(value: unknown, seen: Set<unknown>): string | undefined {\n\tif (value === undefined || value === null || seen.has(value)) return undefined;\n\tif (typeof value === \"string\") return value.trim().length > 0 ? value : undefined;\n\tif (typeof value === \"number\" || typeof value === \"boolean\" || typeof value === \"bigint\") return String(value);\n\tif (typeof value === \"symbol\" || typeof value === \"function\") return undefined;\n\tseen.add(value);\n\n\tif (value instanceof Error && value.message.trim().length > 0) return value.message;\n\tconst directMessage = directMessageFrom(value);\n\tif (directMessage !== undefined) return directMessage;\n\tfor (const diagnosticError of diagnosticErrors(value)) {\n\t\tconst diagnosticMessage = messageFromUnknown(diagnosticError, seen);\n\t\tif (diagnosticMessage !== undefined) return diagnosticMessage;\n\t}\n\tconst causeMessage = messageFromUnknown(causeOf(value), seen);\n\tif (causeMessage !== undefined) return causeMessage;\n\tconst finishReason = finishReasonFrom(value);\n\tif (finishReason !== undefined) return `Model request finished with finish_reason:${finishReason}`;\n\tconst stopReason = stopReasonFrom(value);\n\tif (stopReason !== undefined) return `Assistant message ended with stopReason:${stopReason}`;\n\tconst status = statusFrom(value);\n\tif (status !== undefined) return `Model request failed with status ${status}`;\n\tconst code = codeFrom(value);\n\tif (code !== undefined) return `Model request failed with code ${String(code)}`;\n\treturn undefined;\n}\n\nexport function errorMessage(error: unknown): string {\n\tconst structuredMessage = messageFromUnknown(error, new Set());\n\tif (structuredMessage !== undefined) return structuredMessage;\n\tconst rendered = String(error);\n\treturn rendered === \"[object Object]\" ? \"Model request failed\" : rendered;\n}\n\n/** Alias used by the subagent package's older public helper name. */\nexport const modelFailureMessage = errorMessage;\n\n/** The fallback decision each typed GitHub Copilot failure stands for. */\nconst GITHUB_COPILOT_FAILURE_KINDS: Readonly<Record<GitHubCopilotErrorCode, ModelFallbackFailureKind>> = {\n\t\"model-unavailable\": \"model_unavailable\",\n\t\"rate-limited\": \"rate_limit\",\n\t\"quota-exhausted\": \"quota_exhausted\",\n\t\"content-filtered\": \"content_filter\",\n\t\"prompt-too-large\": \"request_incompatible\",\n\t\"invalid-request\": \"request_incompatible\",\n\t\"authentication-failed\": \"auth_on_candidate_provider\",\n\t\"service-unavailable\": \"provider_unavailable\",\n\t\"stream-ended-early\": \"transport_error\",\n\t\"empty-response\": \"transport_error\",\n\t\"unrecognized-response\": \"provider_unavailable\",\n};\n\n/**\n * A GitHub Copilot failure is typed at the provider: its code decides, never its text. The typed error is found on\n * the failure, anywhere in its cause chain, or in the diagnostics of a failed assistant message in that chain, as\n * when a workflow wraps the message.\n */\nfunction githubCopilotSignal(error: unknown): ModelFallbackFailureSignal | undefined {\n\tconst copilotError: GitHubCopilotError | undefined = findGitHubCopilotError(error);\n\tif (copilotError === undefined) return undefined;\n\treturn makeSignal(GITHUB_COPILOT_FAILURE_KINDS[copilotError.code], copilotError, signalSource(error, undefined));\n}\n\n/**\n * How long the attempt ran, in milliseconds, before its response stream ended early. It is read from the typed GitHub\n * Copilot failure, never from message text: on the error, anywhere in its cause chain, or in the diagnostics of a\n * failed assistant message. Undefined for any other failure, and for a stream-cut error that carries no duration.\n */\nexport function streamCutDurationMs(error: unknown): number | undefined {\n\tconst copilotError = findGitHubCopilotError(error);\n\treturn copilotError instanceof GitHubCopilotStreamEndedEarlyError ? copilotError.durationMs : undefined;\n}\n\nexport function normalizeModelFailureSignal(error: unknown): ModelFallbackFailureSignal {\n\t// Extension startup is not a model request. Its message names extension paths\n\t// and their own errors, which must not read as a provider failure.\n\tif (isExtensionStartupFailure(error)) {\n\t\tconst name = errorName(error);\n\t\treturn {\n\t\t\tkind: \"unknown\",\n\t\t\tmessage: errorMessage(error),\n\t\t\tsource: \"string_fallback\",\n\t\t\t...(name !== undefined ? { name } : {}),\n\t\t};\n\t}\n\tconst copilot = githubCopilotSignal(error);\n\tif (copilot !== undefined) return copilot;\n\tconst structured = structuredSignal(error, new Set());\n\tif (structured !== undefined) return structured;\n\tconst message = errorMessage(error);\n\tconst name = errorName(error);\n\tconst fallbackKind = message.trim().length > 0 ? fallbackKindFromMessage(message, name) : undefined;\n\treturn {\n\t\tkind: fallbackKind ?? \"unknown\",\n\t\tmessage,\n\t\tsource: \"string_fallback\",\n\t\t...(name !== undefined ? { name } : {}),\n\t};\n}\n\n/** Whether a failure is a provider safety/refusal response: a content-filter refusal, or a refused tool call. */\nexport function isSafetyRefusalFailure(error: unknown): boolean {\n\tconst signal = normalizeModelFailureSignal(error);\n\tif (signal.kind === \"content_filter\") return true;\n\tif (signal.kind !== \"task_failure\") return false;\n\tconst text = `${signal.message}\\n${signal.code ?? \"\"}\\n${signal.name ?? \"\"}`;\n\treturn PROVIDER_REFUSAL_FAILURE_PATTERNS.some((pattern) => pattern.test(text));\n}\n\n/** Whether a provider's content filter refused the request, as OpenAI's HTTP 422 `cyber_policy` does. */\nexport function isContentFilterRefusal(error: unknown): boolean {\n\treturn normalizeModelFailureSignal(error).kind === \"content_filter\";\n}\n\n/**\n * True when this failure may spend a configured model fallback candidate. A content-filter refusal does unless\n * `options.fallbackOnContentFilter` is false.\n */\nexport function isRetryableModelFailure(error: unknown, options?: ModelFallbackFailureOptions): boolean {\n\tif (error === undefined) return false;\n\tconst kind = normalizeModelFailureSignal(error).kind;\n\tif (kind === \"content_filter\") return options?.fallbackOnContentFilter !== false;\n\treturn FALLBACKABLE_FAILURE_KINDS.has(kind);\n}\n\nconst SAME_MODEL_RETRYABLE_FAILURE_KINDS: ReadonlySet<ModelFallbackFailureKind> = new Set([\n\t\"rate_limit\",\n\t\"provider_unavailable\",\n\t\"network_timeout\",\n\t\"transport_error\",\n]);\n\n/**\n * An assistant error that only its `stopReason` marks as a model failure: no status, code or name, and text that no\n * pattern recognizes. It may spend a fallback candidate, but it is not retried on the same model on its own.\n */\nfunction isUnrecognizedSignal(signal: ModelFallbackFailureSignal): boolean {\n\treturn (\n\t\tsignal.kind === \"provider_unavailable\" &&\n\t\tsignal.source === \"assistant_message\" &&\n\t\tsignal.status === undefined &&\n\t\tsignal.code === undefined &&\n\t\tsignal.name === undefined &&\n\t\t!RETRYABLE_MODEL_FAILURE_PATTERNS.some((pattern) => pattern.test(signal.message))\n\t);\n}\n\n/** True when the same model may be requested again before fallback advances. */\nexport function isRetryableSameModelFailure(error: unknown): boolean {\n\tif (!isRetryableModelFailure(error)) return false;\n\tconst signal = normalizeModelFailureSignal(error);\n\treturn SAME_MODEL_RETRYABLE_FAILURE_KINDS.has(signal.kind) && !isUnrecognizedSignal(signal);\n}\n\n/**\n * True for a failure that may spend a fallback candidate although nothing recognizes it: an assistant error with no\n * status, code or name whose text matches no known pattern. A session with a fallback chain retries it on the same\n * model first, so such an error never switches models on its first occurrence (#4223).\n */\nexport function isUnrecognizedModelFailure(error: unknown): boolean {\n\treturn isRetryableModelFailure(error) && isUnrecognizedSignal(normalizeModelFailureSignal(error));\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Preferred partner providers and the order provider lists show them in. Kept free of UI code so the list can move
|
|
3
|
+
* to pi-ai once provider lists are offered there.
|
|
4
|
+
*/
|
|
5
|
+
/** Id of the Radius provider. */
|
|
6
|
+
export declare const RADIUS_PROVIDER_ID = "radius";
|
|
7
|
+
/** Ids of the preferred partner providers, most preferred first. */
|
|
8
|
+
export declare const PREFERRED_PROVIDER_IDS: readonly string[];
|
|
9
|
+
/** Whether the provider is a preferred partner. */
|
|
10
|
+
export declare function isPreferredProvider(providerId: string): boolean;
|
|
11
|
+
/** Orders providers: preferred partners first, in their order, then all others alphabetically by name. */
|
|
12
|
+
export declare function compareProviders(a: {
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
}, b: {
|
|
16
|
+
id: string;
|
|
17
|
+
name: string;
|
|
18
|
+
}): number;
|
|
19
|
+
//# sourceMappingURL=preferred-providers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preferred-providers.d.ts","sourceRoot":"","sources":["../../src/core/preferred-providers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,iCAAiC;AACjC,eAAO,MAAM,kBAAkB,WAAW,CAAC;AAE3C,oEAAoE;AACpE,eAAO,MAAM,sBAAsB,EAAE,SAAS,MAAM,EAAuC,CAAC;AAE5F,mDAAmD;AACnD,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAE/D;AAED,0GAA0G;AAC1G,wBAAgB,gBAAgB,CAAC,CAAC,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE,CAAC,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAKzG"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Preferred partner providers and the order provider lists show them in. Kept free of UI code so the list can move
|
|
3
|
+
* to pi-ai once provider lists are offered there.
|
|
4
|
+
*/
|
|
5
|
+
/** Id of the Radius provider. */
|
|
6
|
+
export const RADIUS_PROVIDER_ID = "radius";
|
|
7
|
+
/** Ids of the preferred partner providers, most preferred first. */
|
|
8
|
+
export const PREFERRED_PROVIDER_IDS = [RADIUS_PROVIDER_ID, "openrouter"];
|
|
9
|
+
/** Whether the provider is a preferred partner. */
|
|
10
|
+
export function isPreferredProvider(providerId) {
|
|
11
|
+
return PREFERRED_PROVIDER_IDS.includes(providerId);
|
|
12
|
+
}
|
|
13
|
+
/** Orders providers: preferred partners first, in their order, then all others alphabetically by name. */
|
|
14
|
+
export function compareProviders(a, b) {
|
|
15
|
+
const rankA = preferredRank(a.id);
|
|
16
|
+
const rankB = preferredRank(b.id);
|
|
17
|
+
if (rankA !== rankB)
|
|
18
|
+
return rankA - rankB;
|
|
19
|
+
return a.name.localeCompare(b.name);
|
|
20
|
+
}
|
|
21
|
+
function preferredRank(providerId) {
|
|
22
|
+
const index = PREFERRED_PROVIDER_IDS.indexOf(providerId);
|
|
23
|
+
return index === -1 ? PREFERRED_PROVIDER_IDS.length : index;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=preferred-providers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preferred-providers.js","sourceRoot":"","sources":["../../src/core/preferred-providers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,iCAAiC;AACjC,MAAM,CAAC,MAAM,kBAAkB,GAAG,QAAQ,CAAC;AAE3C,oEAAoE;AACpE,MAAM,CAAC,MAAM,sBAAsB,GAAsB,CAAC,kBAAkB,EAAE,YAAY,CAAC,CAAC;AAE5F,mDAAmD;AACnD,MAAM,UAAU,mBAAmB,CAAC,UAAkB;IACrD,OAAO,sBAAsB,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;AACpD,CAAC;AAED,0GAA0G;AAC1G,MAAM,UAAU,gBAAgB,CAAC,CAA+B,EAAE,CAA+B;IAChG,MAAM,KAAK,GAAG,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAClC,MAAM,KAAK,GAAG,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAClC,IAAI,KAAK,KAAK,KAAK;QAAE,OAAO,KAAK,GAAG,KAAK,CAAC;IAC1C,OAAO,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AACrC,CAAC;AAED,SAAS,aAAa,CAAC,UAAkB;IACxC,MAAM,KAAK,GAAG,sBAAsB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACzD,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC;AAC7D,CAAC","sourcesContent":["/**\n * Preferred partner providers and the order provider lists show them in. Kept free of UI code so the list can move\n * to pi-ai once provider lists are offered there.\n */\n\n/** Id of the Radius provider. */\nexport const RADIUS_PROVIDER_ID = \"radius\";\n\n/** Ids of the preferred partner providers, most preferred first. */\nexport const PREFERRED_PROVIDER_IDS: readonly string[] = [RADIUS_PROVIDER_ID, \"openrouter\"];\n\n/** Whether the provider is a preferred partner. */\nexport function isPreferredProvider(providerId: string): boolean {\n\treturn PREFERRED_PROVIDER_IDS.includes(providerId);\n}\n\n/** Orders providers: preferred partners first, in their order, then all others alphabetically by name. */\nexport function compareProviders(a: { id: string; name: string }, b: { id: string; name: string }): number {\n\tconst rankA = preferredRank(a.id);\n\tconst rankB = preferredRank(b.id);\n\tif (rankA !== rankB) return rankA - rankB;\n\treturn a.name.localeCompare(b.name);\n}\n\nfunction preferredRank(providerId: string): number {\n\tconst index = PREFERRED_PROVIDER_IDS.indexOf(providerId);\n\treturn index === -1 ? PREFERRED_PROVIDER_IDS.length : index;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-alias.d.ts","sourceRoot":"","sources":["../../src/core/provider-alias.ts"],"names":[],"mappings":"AAAA,OAAO,EAQN,KAAK,QAAQ,EAIb,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"provider-alias.d.ts","sourceRoot":"","sources":["../../src/core/provider-alias.ts"],"names":[],"mappings":"AAAA,OAAO,EAQN,KAAK,QAAQ,EAIb,MAAM,gBAAgB,CAAC;AAGxB,MAAM,WAAW,mBAAmB;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CACjB;AA4FD,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,QAAQ,GAAG,QAAQ,CA6ElG"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { lazyStream, } from "@bastani/pi-ai";
|
|
2
|
+
import { refreshGitHubCopilotAccountModelLists } from "@bastani/pi-ai/providers/github-copilot";
|
|
2
3
|
function withProvider(value, provider) {
|
|
3
4
|
return { ...value, provider };
|
|
4
5
|
}
|
|
@@ -110,6 +111,9 @@ export function createProviderAlias(config, resolve) {
|
|
|
110
111
|
stream: (model, context, options) => aliasStream(model, () => resolve().stream(sourceModel(model), sourceContext(context, config.id, config.provider), aliasChatOptions(options, model)), options?.signal),
|
|
111
112
|
streamSimple: (model, context, options) => aliasStream(model, () => resolve().streamSimple(sourceModel(model), sourceContext(context, config.id, config.provider), aliasChatOptions(options, model)), options?.signal),
|
|
112
113
|
};
|
|
114
|
+
if (config.provider === "github-copilot") {
|
|
115
|
+
alias.refreshModels = refreshGitHubCopilotAccountModelLists;
|
|
116
|
+
}
|
|
113
117
|
if (source.fetchDeferred) {
|
|
114
118
|
alias.fetchDeferred = (model, handle, options) => aliasStream(model, () => resolve().fetchDeferred(sourceModel(model), handle, aliasChatOptions(options, model)), options?.signal);
|
|
115
119
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-alias.js","sourceRoot":"","sources":["../../src/core/provider-alias.ts"],"names":[],"mappings":"AAAA,OAAO,EAMN,UAAU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istantMessageEvent,\n\ttype AssistantMessageEventStream,\n\tlazyStream,\n\ttype Model,\n\ttype Provider,\n\ttype ProviderRequestOptions,\n\ttype StreamOptions,\n\ttype TranscriptContext,\n} from \"@bastani/pi-ai\";\n\nexport interface ProviderAliasConfig {\n\tid: string;\n\tname?: string;\n\tprovider: string;\n}\n\nfunction withProvider<T extends { provider: string }>(value: T, provider: string): T {\n\treturn { ...value, provider };\n}\n\nfunction aliasApiKey(auth: ApiKeyAuth): ApiKeyAuth {\n\treturn {\n\t\t...auth,\n\t\tborrowCredentialsFrom: undefined,\n\t\tlogin:\n\t\t\tauth.login ??\n\t\t\t(async (interaction) => {\n\t\t\t\tinteraction.signal.throwIfAborted();\n\t\t\t\tconst key = await interaction.prompt({ type: \"secret\", message: `Enter ${auth.name}` });\n\t\t\t\tinteraction.signal.throwIfAborted();\n\t\t\t\treturn { type: \"api_key\", key };\n\t\t\t}),\n\t\tcheck: async (input) => {\n\t\t\tif (!input.credential?.key?.trim()) return undefined;\n\t\t\tif (auth.check) return auth.check(input);\n\t\t\tconst result = await auth.resolve(input);\n\t\t\treturn result ? { type: \"api_key\", source: result.source } : undefined;\n\t\t},\n\t\tresolve: async (input) => (input.credential?.key?.trim() ? auth.resolve(input) : undefined),\n\t};\n}\n\nfunction sourceContext(context: TranscriptContext, alias: string, source: string): TranscriptContext {\n\treturn {\n\t\t...context,\n\t\tmessages: context.messages.map((message) => {\n\t\t\tif (message.role !== \"assistant\") return message;\n\t\t\tif (message.provider === alias) return withProvider(message, source);\n\t\t\tif (message.provider === source) return withProvider(message, `${source}:other-account`);\n\t\t\treturn message;\n\t\t}),\n\t};\n}\n\nfunction aliasOptions<TModel extends AnyModel, T extends ProviderRequestOptions<TModel>>(\n\toptions: T | undefined,\n\tmodel: TModel,\n): T | undefined {\n\tif (!options) return undefined;\n\treturn {\n\t\t...options,\n\t\tonPayload: options.onPayload ? (payload) => options.onPayload!(payload, model) : undefined,\n\t\tonResponse: options.onResponse ? (response) => options.onResponse!(response, model) : undefined,\n\t};\n}\n\nfunction aliasChatOptions<T extends StreamOptions>(options: T | undefined, model: Model<Api>): T | undefined {\n\tconst mapped = aliasOptions(options, model);\n\tif (!mapped) return undefined;\n\treturn {\n\t\t...mapped,\n\t\tonProviderStreamEvent: mapped.onProviderStreamEvent\n\t\t\t? (data) => mapped.onProviderStreamEvent!(data, model)\n\t\t\t: undefined,\n\t};\n}\n\nfunction aliasStream(\n\tmodel: Model<Api>,\n\tstart: () => AssistantMessageEventStream,\n\tsignal: AbortSignal | undefined,\n): AssistantMessageEventStream {\n\treturn lazyStream(\n\t\tmodel,\n\t\tasync () => {\n\t\t\tconst source = start();\n\t\t\tasync function* events(): AsyncGenerator<AssistantMessageEvent> {\n\t\t\t\tfor await (const event of source) {\n\t\t\t\t\tif (event.type === \"done\") {\n\t\t\t\t\t\tyield { ...event, message: withProvider(event.message, model.provider) };\n\t\t\t\t\t} else if (event.type === \"error\") {\n\t\t\t\t\t\tyield { ...event, error: withProvider(event.error, model.provider) };\n\t\t\t\t\t} else {\n\t\t\t\t\t\tyield { ...event, partial: withProvider(event.partial, model.provider) };\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn {\n\t\t\t\t[Symbol.asyncIterator]: events,\n\t\t\t\tresult: async () => withProvider(await source.result(), model.provider),\n\t\t\t};\n\t\t},\n\t\tsignal,\n\t);\n}\n\nexport function createProviderAlias(config: ProviderAliasConfig, resolve: () => Provider): Provider {\n\tconst source = resolve();\n\tconst sourceModel = <T extends AnyModel>(model: T): T => withProvider(model, config.provider);\n\tconst aliasModel = <T extends AnyModel>(model: T): T => withProvider(model, config.id);\n\tconst apiKey = source.auth.apiKey;\n\tconst oauth = source.auth.oauth;\n\tconst alias: Provider = {\n\t\tid: config.id,\n\t\tname: config.name ?? config.id,\n\t\tbaseUrl: source.baseUrl,\n\t\theaders: source.headers,\n\t\tauth: {\n\t\t\t...(apiKey ? { apiKey: aliasApiKey(apiKey) } : {}),\n\t\t\t...(oauth ? { oauth: { ...oauth, name: config.name ?? config.id } } : {}),\n\t\t},\n\t\tgetModels: () => resolve().getModels().map(aliasModel),\n\t\tgetAllModels: () => {\n\t\t\tconst current = resolve();\n\t\t\treturn (current.getAllModels?.() ?? current.getModels()).map(aliasModel);\n\t\t},\n\t\tfilterModels: (models, credential) => {\n\t\t\tconst current = resolve();\n\t\t\treturn (current.filterModels?.(models.map(sourceModel), credential) ?? models).map(aliasModel);\n\t\t},\n\t\tfilterAllModels: source.filterAllModels\n\t\t\t? (models, credential) => resolve().filterAllModels!(models.map(sourceModel), credential).map(aliasModel)\n\t\t\t: undefined,\n\t\tstream: (model, context, options) =>\n\t\t\taliasStream(\n\t\t\t\tmodel,\n\t\t\t\t() =>\n\t\t\t\t\tresolve().stream(\n\t\t\t\t\t\tsourceModel(model),\n\t\t\t\t\t\tsourceContext(context, config.id, config.provider),\n\t\t\t\t\t\taliasChatOptions(options, model),\n\t\t\t\t\t),\n\t\t\t\toptions?.signal,\n\t\t\t),\n\t\tstreamSimple: (model, context, options) =>\n\t\t\taliasStream(\n\t\t\t\tmodel,\n\t\t\t\t() =>\n\t\t\t\t\tresolve().streamSimple(\n\t\t\t\t\t\tsourceModel(model),\n\t\t\t\t\t\tsourceContext(context, config.id, config.provider),\n\t\t\t\t\t\taliasChatOptions(options, model),\n\t\t\t\t\t),\n\t\t\t\toptions?.signal,\n\t\t\t),\n\t};\n\tif (source.fetchDeferred) {\n\t\talias.fetchDeferred = (model, handle, options) =>\n\t\t\taliasStream(\n\t\t\t\tmodel,\n\t\t\t\t() => resolve().fetchDeferred!(sourceModel(model), handle, aliasChatOptions(options, model)),\n\t\t\t\toptions?.signal,\n\t\t\t);\n\t}\n\tif (source.cancelDeferred) {\n\t\talias.cancelDeferred = (model, handle, options) =>\n\t\t\tresolve().cancelDeferred!(sourceModel(model), handle, aliasOptions(options, model));\n\t}\n\tif (source.generateImages) {\n\t\talias.generateImages = async (model, context, options) =>\n\t\t\twithProvider(\n\t\t\t\tawait resolve().generateImages!(sourceModel(model), context, aliasOptions(options, model)),\n\t\t\t\tconfig.id,\n\t\t\t);\n\t}\n\tif (source.classify) {\n\t\talias.classify = async (model, context, options) =>\n\t\t\twithProvider(await resolve().classify!(sourceModel(model), context, aliasOptions(options, model)), config.id);\n\t}\n\treturn alias;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"provider-alias.js","sourceRoot":"","sources":["../../src/core/provider-alias.ts"],"names":[],"mappings":"AAAA,OAAO,EAMN,UAAU,GAMV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,qCAAqC,EAAE,MAAM,yCAAyC,CAAC;AAQhG,SAAS,YAAY,CAAiC,KAAQ,EAAE,QAAgB;IAC/E,OAAO,EAAE,GAAG,KAAK,EAAE,QAAQ,EAAE,CAAC;AAC/B,CAAC;AAED,SAAS,WAAW,CAAC,IAAgB;IACpC,OAAO;QACN,GAAG,IAAI;QACP,qBAAqB,EAAE,SAAS;QAChC,KAAK,EACJ,IAAI,CAAC,KAAK;YACV,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE;gBACtB,WAAW,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;gBACpC,MAAM,GAAG,GAAG,MAAM,WAAW,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;gBACxF,WAAW,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;gBACpC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC;YACjC,CAAC,CAAC;QACH,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;YACtB,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE;gBAAE,OAAO,SAAS,CAAC;YACrD,IAAI,IAAI,CAAC,KAAK;gBAAE,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YACzC,MAAM,M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KAAK,CAAC,CAAC,EAC1F,MAAM,CAAC,EAAE,CACT,CAAC;IACJ,CAAC;IACD,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;QACrB,KAAK,CAAC,QAAQ,GAAG,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,CAClD,YAAY,CAAC,MAAM,OAAO,EAAE,CAAC,QAAS,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;IAChH,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC","sourcesContent":["import {\n\ttype AnyModel,\n\ttype Api,\n\ttype ApiKeyAuth,\n\ttype AssistantMessageEvent,\n\ttype AssistantMessageEventStream,\n\tlazyStream,\n\ttype Model,\n\ttype Provider,\n\ttype ProviderRequestOptions,\n\ttype StreamOptions,\n\ttype TranscriptContext,\n} from \"@bastani/pi-ai\";\nimport { refreshGitHubCopilotAccountModelLists } from \"@bastani/pi-ai/providers/github-copilot\";\n\nexport interface ProviderAliasConfig {\n\tid: string;\n\tname?: string;\n\tprovider: string;\n}\n\nfunction withProvider<T extends { provider: string }>(value: T, provider: string): T {\n\treturn { ...value, provider };\n}\n\nfunction aliasApiKey(auth: ApiKeyAuth): ApiKeyAuth {\n\treturn {\n\t\t...auth,\n\t\tborrowCredentialsFrom: undefined,\n\t\tlogin:\n\t\t\tauth.login ??\n\t\t\t(async (interaction) => {\n\t\t\t\tinteraction.signal.throwIfAborted();\n\t\t\t\tconst key = await interaction.prompt({ type: \"secret\", message: `Enter ${auth.name}` });\n\t\t\t\tinteraction.signal.throwIfAborted();\n\t\t\t\treturn { type: \"api_key\", key };\n\t\t\t}),\n\t\tcheck: async (input) => {\n\t\t\tif (!input.credential?.key?.trim()) return undefined;\n\t\t\tif (auth.check) return auth.check(input);\n\t\t\tconst result = await auth.resolve(input);\n\t\t\treturn result ? { type: \"api_key\", source: result.source } : undefined;\n\t\t},\n\t\tresolve: async (input) => (input.credential?.key?.trim() ? auth.resolve(input) : undefined),\n\t};\n}\n\nfunction sourceContext(context: TranscriptContext, alias: string, source: string): TranscriptContext {\n\treturn {\n\t\t...context,\n\t\tmessages: context.messages.map((message) => {\n\t\t\tif (message.role !== \"assistant\") return message;\n\t\t\tif (message.provider === alias) return withProvider(message, source);\n\t\t\tif (message.provider === source) return withProvider(message, `${source}:other-account`);\n\t\t\treturn message;\n\t\t}),\n\t};\n}\n\nfunction aliasOptions<TModel extends AnyModel, T extends ProviderRequestOptions<TModel>>(\n\toptions: T | undefined,\n\tmodel: TModel,\n): T | undefined {\n\tif (!options) return undefined;\n\treturn {\n\t\t...options,\n\t\tonPayload: options.onPayload ? (payload) => options.onPayload!(payload, model) : undefined,\n\t\tonResponse: options.onResponse ? (response) => options.onResponse!(response, model) : undefined,\n\t};\n}\n\nfunction aliasChatOptions<T extends StreamOptions>(options: T | undefined, model: Model<Api>): T | undefined {\n\tconst mapped = aliasOptions(options, model);\n\tif (!mapped) return undefined;\n\treturn {\n\t\t...mapped,\n\t\tonProviderStreamEvent: mapped.onProviderStreamEvent\n\t\t\t? (data) => mapped.onProviderStreamEvent!(data, model)\n\t\t\t: undefined,\n\t};\n}\n\nfunction aliasStream(\n\tmodel: Model<Api>,\n\tstart: () => AssistantMessageEventStream,\n\tsignal: AbortSignal | undefined,\n): AssistantMessageEventStream {\n\treturn lazyStream(\n\t\tmodel,\n\t\tasync () => {\n\t\t\tconst source = start();\n\t\t\tasync function* events(): AsyncGenerator<AssistantMessageEvent> {\n\t\t\t\tfor await (const event of source) {\n\t\t\t\t\tif (event.type === \"done\") {\n\t\t\t\t\t\tyield { ...event, message: withProvider(event.message, model.provider) };\n\t\t\t\t\t} else if (event.type === \"error\") {\n\t\t\t\t\t\tyield { ...event, error: withProvider(event.error, model.provider) };\n\t\t\t\t\t} else {\n\t\t\t\t\t\tyield { ...event, partial: withProvider(event.partial, model.provider) };\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn {\n\t\t\t\t[Symbol.asyncIterator]: events,\n\t\t\t\tresult: async () => withProvider(await source.result(), model.provider),\n\t\t\t};\n\t\t},\n\t\tsignal,\n\t);\n}\n\nexport function createProviderAlias(config: ProviderAliasConfig, resolve: () => Provider): Provider {\n\tconst source = resolve();\n\tconst sourceModel = <T extends AnyModel>(model: T): T => withProvider(model, config.provider);\n\tconst aliasModel = <T extends AnyModel>(model: T): T => withProvider(model, config.id);\n\tconst apiKey = source.auth.apiKey;\n\tconst oauth = source.auth.oauth;\n\tconst alias: Provider = {\n\t\tid: config.id,\n\t\tname: config.name ?? config.id,\n\t\tbaseUrl: source.baseUrl,\n\t\theaders: source.headers,\n\t\tauth: {\n\t\t\t...(apiKey ? { apiKey: aliasApiKey(apiKey) } : {}),\n\t\t\t...(oauth ? { oauth: { ...oauth, name: config.name ?? config.id } } : {}),\n\t\t},\n\t\tgetModels: () => resolve().getModels().map(aliasModel),\n\t\tgetAllModels: () => {\n\t\t\tconst current = resolve();\n\t\t\treturn (current.getAllModels?.() ?? current.getModels()).map(aliasModel);\n\t\t},\n\t\tfilterModels: (models, credential) => {\n\t\t\tconst current = resolve();\n\t\t\treturn (current.filterModels?.(models.map(sourceModel), credential) ?? models).map(aliasModel);\n\t\t},\n\t\tfilterAllModels: source.filterAllModels\n\t\t\t? (models, credential) => resolve().filterAllModels!(models.map(sourceModel), credential).map(aliasModel)\n\t\t\t: undefined,\n\t\tstream: (model, context, options) =>\n\t\t\taliasStream(\n\t\t\t\tmodel,\n\t\t\t\t() =>\n\t\t\t\t\tresolve().stream(\n\t\t\t\t\t\tsourceModel(model),\n\t\t\t\t\t\tsourceContext(context, config.id, config.provider),\n\t\t\t\t\t\taliasChatOptions(options, model),\n\t\t\t\t\t),\n\t\t\t\toptions?.signal,\n\t\t\t),\n\t\tstreamSimple: (model, context, options) =>\n\t\t\taliasStream(\n\t\t\t\tmodel,\n\t\t\t\t() =>\n\t\t\t\t\tresolve().streamSimple(\n\t\t\t\t\t\tsourceModel(model),\n\t\t\t\t\t\tsourceContext(context, config.id, config.provider),\n\t\t\t\t\t\taliasChatOptions(options, model),\n\t\t\t\t\t),\n\t\t\t\toptions?.signal,\n\t\t\t),\n\t};\n\tif (config.provider === \"github-copilot\") {\n\t\talias.refreshModels = refreshGitHubCopilotAccountModelLists;\n\t}\n\tif (source.fetchDeferred) {\n\t\talias.fetchDeferred = (model, handle, options) =>\n\t\t\taliasStream(\n\t\t\t\tmodel,\n\t\t\t\t() => resolve().fetchDeferred!(sourceModel(model), handle, aliasChatOptions(options, model)),\n\t\t\t\toptions?.signal,\n\t\t\t);\n\t}\n\tif (source.cancelDeferred) {\n\t\talias.cancelDeferred = (model, handle, options) =>\n\t\t\tresolve().cancelDeferred!(sourceModel(model), handle, aliasOptions(options, model));\n\t}\n\tif (source.generateImages) {\n\t\talias.generateImages = async (model, context, options) =>\n\t\t\twithProvider(\n\t\t\t\tawait resolve().generateImages!(sourceModel(model), context, aliasOptions(options, model)),\n\t\t\t\tconfig.id,\n\t\t\t);\n\t}\n\tif (source.classify) {\n\t\talias.classify = async (model, context, options) =>\n\t\t\twithProvider(await resolve().classify!(sourceModel(model), context, aliasOptions(options, model)), config.id);\n\t}\n\treturn alias;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-composer.d.ts","sourceRoot":"","sources":["../../src/core/provider-composer.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,QAAQ,EAUb,KAAK,QAAQ,EACb,KAAK,eAAe,EAIpB,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,KAAK,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAkBvF,YAAY,EAAE,UAAU,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,iCAAi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B,6BAA6B,CAC5C,KAAK,EAAE,QAAQ,EACf,MAAM,EAAE,kBAAkB,GAAG,SAAS,EACtC,SAAS,EAAE,mBAAmB,GAAG,SAAS,EAC1C,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC1B,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAMpC;AAED,MAAM,WAAW,0BAA0B;IAC1C,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,UAAU,EAAE,OAAO,CAAC;CACpB;AAED,wBAAgB,iCAAiC,CAChD,KAAK,EAAE,QAAQ,EACf,MAAM,EAAE,kBAAkB,GAAG,SAAS,EACtC,SAAS,EAAE,mBAAmB,GAAG,SAAS,GACxC,0BAA0B,CAS5B;AAED,wBAAgB,2BAA2B,CAC1C,MAAM,EAAE,kBAAkB,GAAG,SAAS,EACtC,SAAS,EAAE,mBAAmB,GAAG,SAAS,GACxC,UAAU,GAAG,SAAS,CAWxB"}
|
|
@@ -74,6 +74,7 @@ export function composeModelProvider(providerId, base, modelConfig, extension) {
|
|
|
74
74
|
auth: { ...(apiKey ? { apiKey } : {}), ...(oauth ? { oauth } : {}) },
|
|
75
75
|
getModels: () => getAllModels().filter((model) => isModelType(model, "chat")),
|
|
76
76
|
getAllModels,
|
|
77
|
+
refreshModelsAuth: extension?.refreshModels || extension?.oauth?.modifyModels ? undefined : base?.refreshModelsAuth,
|
|
77
78
|
refreshModels: base?.refreshModels || extension?.refreshModels || extension?.oauth?.modifyModels
|
|
78
79
|
? async (context) => {
|
|
79
80
|
await base?.refreshModels?.(context);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-composer.js","sourceRoot":"","sources":["../../src/core/provider-composer.ts"],"names":[],"mappings":"AAAA,OAAO,EAKN,qBAAqB,EACrB,gBAAgB,EAChB,WAAW,EACX,UAAU,GAQV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB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,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,iBAAiB,EAAE,CAAC;AACvG,CAAC","sourcesContent":["import {\n\ttype AnyModel,\n\ttype Api,\n\ttype AssistantMessageEventStream,\n\ttype Credential,\n\tclassifierErrorResult,\n\timageErrorResult,\n\tisModelType,\n\tlazyStream,\n\ttype Model,\n\ttype OAuthCredentials,\n\ttype Provider,\n\ttype ProviderHeaders,\n\ttype SimpleStreamOptions,\n\ttype StreamOptions,\n\ttype TranscriptContext,\n} from \"@bastani/pi-ai\";\nimport { getApiProvider } from \"@bastani/pi-ai/compat\";\nimport type { ModelConfig, ModelsJsonProvider } from \"./model-config.ts\";\nimport type { AuthStatus, ProviderConfigInput } from \"./provider-composer-internal.ts\";\nimport {\n\tapplyExtension,\n\tapplyModelOverride,\n\tapplyModelsJson,\n\tcomposeApiKeyAuth,\n\tcomposeOAuthAuth,\n\tconfiguredApiKey,\n\tconfiguredHeaders,\n\trawModelHeaders,\n} from \"./provider-composer-internal.ts\";\nimport {\n\tgetConfigValueEnvVarNames,\n\tisCommandConfigValue,\n\tisConfigValueConfigured,\n\tresolveHeadersOrThrow,\n} from \"./resolve-config-value.ts\";\n\nexport type { AuthStatus, ExtensionOAuthConfig, ProviderConfigInput } from \"./provider-composer-internal.ts\";\nexport { clearApiKeyCache } from \"./provider-composer-internal.ts\";\n\nfunction getAllProviderModels(provider: Provider | undefined): readonly AnyModel[] {\n\treturn provider ? (provider.getAllModels?.() ?? provider.getModels()) : [];\n}\n\nexport function validateExtensionProvider(\n\tproviderId: string,\n\tbase: Provider | undefined,\n\tmodelsConfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput,\n): void {\n\tif (extension.aliasOf !== undefined) {\n\t\tif (!providerId.trim() || !extension.aliasOf.trim() || providerId === extension.aliasOf) {\n\t\t\tthrow new Error(\"A provider alias needs distinct, non-empty alias and source IDs.\");\n\t\t}\n\t\tif (Object.keys(extension).some((key) => ![\"aliasOf\", \"name\"].includes(key))) {\n\t\t\tthrow new Error(\"Provider aliases accept only aliasOf and name; configure the source provider instead.\");\n\t\t}\n\t\treturn;\n\t}\n\tif (extension.streamSimple && !extension.api) {\n\t\tthrow new Error(`Provider ${providerId}: \"api\" is required when registering streamSimple.`);\n\t}\n\tapplyExtension(providerId, applyModelsJson(providerId, getAllProviderModels(base), modelsConfig), extension);\n}\n\n/** Compose built-in, models.json, and extension layers without reading credentials. */\nexport function composeModelProvider(\n\tproviderId: string,\n\tbase: Provider | undefined,\n\tmodelConfig: ModelConfig,\n\textension: ProviderConfigInput | undefined,\n): Provider {\n\tconst config = modelConfig.getProvider(providerId);\n\tlet extensionOAuthCredential: OAuthCredentials | undefined;\n\tlet refreshedExtensionModels: ProviderConfigInput[\"models\"];\n\tconst currentExtension = (): ProviderConfigInput | undefined =>\n\t\textension && refreshedExtensionModels ? { ...extension, models: refreshedExtensionModels } : extension;\n\t// models.json modelOverrides are the topmost user-config layer: they apply once,\n\t// after custom-model upserts, extension model replacement, and legacy OAuth projection.\n\tconst getAllModels = (): AnyModel[] => {\n\t\tlet models = applyExtension(\n\t\t\tproviderId,\n\t\t\tapplyModelsJson(providerId, getAllProviderModels(base), config),\n\t\t\tcurrentExtension(),\n\t\t);\n\t\tif (extensionOAuthCredential && extension?.oauth?.modifyModels) {\n\t\t\t// The extension hook is chat-only; other model types pass through untouched.\n\t\t\tmodels = [\n\t\t\t\t...extension.oauth.modifyModels(\n\t\t\t\t\tmodels.filter((model) => isModelType(model, \"chat\")),\n\t\t\t\t\textensionOAuthCredential,\n\t\t\t\t),\n\t\t\t\t...models.filter((model) => !isModelType(model, \"chat\")),\n\t\t\t];\n\t\t}\n\t\treturn models.map((model) => {\n\t\t\tconst override = config?.modelOverrides?.[model.id];\n\t\t\treturn override && isModelType(model, \"chat\") ? applyModelOverride(model, override) : model;\n\t\t});\n\t};\n\t// Validate eagerly so registration/reload reports structural errors immediately.\n\tgetAllModels();\n\tconst apiKey = composeApiKeyAuth(providerId, base, config, extension);\n\tconst oauth = composeOAuthAuth(providerId, base, config, extension);\n\tif (!apiKey && !oauth) throw new Error(`Provider ${providerId}: no authentication method configured.`);\n\n\tconst supportsBaseApi = (model: Model<Api>) => base?.getModels().some((entry) => entry.api === model.api) ?? false;\n\tconst streamWith = (\n\t\tmodel: Model<Api>,\n\t\tcontext: TranscriptContext,\n\t\toptions: StreamOptions | undefined,\n\t\tsimple: boolean,\n\t): AssistantMessageEventStream =>\n\t\tlazyStream(\n\t\t\tmodel,\n\t\t\tasync () => {\n\t\t\t\tif (extension?.streamSimple && model.api === extension.api) {\n\t\t\t\t\treturn extension.streamSimple(model, context, options as SimpleStreamOptions);\n\t\t\t\t}\n\t\t\t\tif (base && supportsBaseApi(model)) {\n\t\t\t\t\treturn simple\n\t\t\t\t\t\t? base.streamSimple(model, context, options as SimpleStreamOptions)\n\t\t\t\t\t\t: base.stream(model, context, options);\n\t\t\t\t}\n\t\t\t\tconst api = getApiProvider(model.api);\n\t\t\t\tif (!api) throw new Error(`No API provider registered for api: ${model.api}`);\n\t\t\t\treturn simple\n\t\t\t\t\t? api.streamSimple(model, context, options as SimpleStreamOptions)\n\t\t\t\t\t: api.stream(model, context, options);\n\t\t\t},\n\t\t\toptions?.signal,\n\t\t);\n\n\tconst provider: Provider = {\n\t\tid: providerId,\n\t\tname: extension?.name ?? config?.name ?? base?.name ?? extension?.oauth?.name ?? providerId,\n\t\tbaseUrl: extension?.baseUrl ?? config?.baseUrl ?? base?.baseUrl,\n\t\theaders: base?.headers,\n\t\tauth: { ...(apiKey ? { apiKey } : {}), ...(oauth ? { oauth } : {}) },\n\t\tgetModels: () => getAllModels().filter((model) => isModelType(model, \"chat\")),\n\t\tgetAllModels,\n\t\trefreshModels:\n\t\t\tbase?.refreshModels || extension?.refreshModels || extension?.oauth?.modifyModels\n\t\t\t\t? async (context) => {\n\t\t\t\t\t\tawait base?.refreshModels?.(context);\n\t\t\t\t\t\tlet refreshed: NonNullable<ProviderConfigInput[\"models\"]> | undefined;\n\t\t\t\t\t\tif (extension?.refreshModels) refreshed = await extension.refreshModels(context);\n\t\t\t\t\t\tif (context.signal.aborted) return;\n\t\t\t\t\t\tconst oauthCredential = context.credential?.type === \"oauth\" ? context.credential : undefined;\n\t\t\t\t\t\tawait context.publish({\n\t\t\t\t\t\t\tupdate: () => {\n\t\t\t\t\t\t\t\tif (refreshed) {\n\t\t\t\t\t\t\t\t\t// Validate before publishing the new synchronous list.\n\t\t\t\t\t\t\t\t\tapplyExtension(providerId, applyModelsJson(providerId, getAllProviderModels(base), config), {\n\t\t\t\t\t\t\t\t\t\t...extension,\n\t\t\t\t\t\t\t\t\t\tmodels: refreshed,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\trefreshedExtensionModels = refreshed;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\textensionOAuthCredential = oauthCredential;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t: undefined,\n\t\tfilterModels: base?.filterModels\n\t\t\t? (models, credential: Credential | undefined) => {\n\t\t\t\t\t// Models the user defines in models.json are an explicit choice: the base provider's\n\t\t\t\t\t// account filter (such as GitHub Copilot's model list) must not hide them.\n\t\t\t\t\tconst isConfigured = (model: Model<Api>) =>\n\t\t\t\t\t\tconfig?.models?.some((entry) => entry.id === model.id) === true;\n\t\t\t\t\tconst filtered = new Map(base.filterModels!(models, credential).map((model) => [model.id, model]));\n\t\t\t\t\treturn models.flatMap((original) => {\n\t\t\t\t\t\tif (isConfigured(original)) return [original];\n\t\t\t\t\t\tconst model = filtered.get(original.id);\n\t\t\t\t\t\tif (model === undefined) return [];\n\t\t\t\t\t\tconst inheritedContext = model.fastRoute\n\t\t\t\t\t\t\t? config?.modelOverrides?.[model.fastRoute.baseModelId]?.contextWindow\n\t\t\t\t\t\t\t: undefined;\n\t\t\t\t\t\tconst personalized =\n\t\t\t\t\t\t\tinheritedContext === undefined ? model : { ...model, contextWindow: inheritedContext };\n\t\t\t\t\t\tconst override = config?.modelOverrides?.[model.id];\n\t\t\t\t\t\treturn [override ? applyModelOverride(personalized, override) : personalized];\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t: undefined,\n\t\tfilterAllModels: base?.filterAllModels\n\t\t\t? (models, credential: Credential | undefined) => base.filterAllModels!(models, credential)\n\t\t\t: undefined,\n\t\tstream: (model, context, options) => streamWith(model, context, options, false),\n\t\tstreamSimple: (model, context, options) => streamWith(model, context, options, true),\n\t};\n\n\tconst fetchDeferred = base?.fetchDeferred;\n\tif (fetchDeferred) {\n\t\tprovider.fetchDeferred = (model, handle, options) => fetchDeferred(model, handle, options);\n\t}\n\tconst cancelDeferred = base?.cancelDeferred;\n\tif (cancelDeferred) {\n\t\tprovider.cancelDeferred = (model, handle, options) => cancelDeferred(model, handle, options);\n\t}\n\tconst extensionImages = extension?.images;\n\tconst generateImages = base?.generateImages;\n\tif (generateImages || Object.keys(extensionImages ?? {}).length > 0) {\n\t\tprovider.generateImages = (model, context, options) => {\n\t\t\tconst implementation = extensionImages?.[model.api];\n\t\t\tif (implementation) return implementation.generateImages(model, context, options);\n\t\t\tif (generateImages) return generateImages(model, context, options);\n\t\t\treturn Promise.resolve(\n\t\t\t\timageErrorResult(model, new Error(`Provider ${providerId} has no image implementation for \"${model.api}\"`)),\n\t\t\t);\n\t\t};\n\t}\n\tconst extensionClassifiers = extension?.classifiers;\n\tconst classify = base?.classify;\n\tif (classify || Object.keys(extensionClassifiers ?? {}).length > 0) {\n\t\tprovider.classify = (model, context, options) => {\n\t\t\tconst implementation = extensionClassifiers?.[model.api];\n\t\t\tif (implementation) return implementation.classify(model, context, options);\n\t\t\tif (classify) return classify(model, context, options);\n\t\t\treturn Promise.resolve(\n\t\t\t\tclassifierErrorResult(\n\t\t\t\t\tmodel,\n\t\t\t\t\tnew Error(`Provider ${providerId} has no classifier implementation for \"${model.api}\"`),\n\t\t\t\t),\n\t\t\t);\n\t\t};\n\t}\n\n\treturn provider;\n}\n\nexport function resolveConfiguredModelHeaders(\n\tmodel: AnyModel,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n\tenv?: Record<string, string>,\n): Record<string, string> | undefined {\n\treturn resolveHeadersOrThrow(\n\t\trawModelHeaders(model, config, extension),\n\t\t`model \"${model.provider}/${model.id}\"`,\n\t\tenv,\n\t);\n}\n\nexport interface CompatibilityRequestConfig {\n\theaders?: ProviderHeaders;\n\tauthHeader: boolean;\n}\n\nexport function resolveCompatibilityRequestConfig(\n\tmodel: AnyModel,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): CompatibilityRequestConfig {\n\tconst configured = resolveHeadersOrThrow(\n\t\t{ ...configuredHeaders(config, extension), ...rawModelHeaders(model, config, extension) },\n\t\t`model \"${model.provider}/${model.id}\"`,\n\t);\n\treturn {\n\t\theaders: model.headers || configured ? { ...model.headers, ...configured } : undefined,\n\t\tauthHeader: extension?.authHeader ?? config?.authHeader ?? false,\n\t};\n}\n\nexport function configuredRequestAuthStatus(\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): AuthStatus | undefined {\n\tconst value = configuredApiKey(config, extension);\n\tif (value === undefined) return undefined;\n\tif (isCommandConfigValue(value)) return { configured: true, source: \"models_json_command\" };\n\tconst names = getConfigValueEnvVarNames(value);\n\tif (names.length > 0) {\n\t\treturn isConfigValueConfigured(value)\n\t\t\t? { configured: true, source: \"environment\", label: names.join(\", \") }\n\t\t\t: { configured: false };\n\t}\n\treturn { configured: true, source: extension?.apiKey !== undefined ? \"fallback\" : \"models_json_key\" };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"provider-composer.js","sourceRoot":"","sources":["../../src/core/provider-composer.ts"],"names":[],"mappings":"AAAA,OAAO,EAKN,qBAAqB,EACrB,gBAAgB,EAChB,WAAW,EACX,UAAU,GAQV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MA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AAI,CAAC,EAAE;YACtE,CAAC,CAAC,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;IAC1B,CAAC;IACD,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,iBAAiB,EAAE,CAAC;AACvG,CAAC","sourcesContent":["import {\n\ttype AnyModel,\n\ttype Api,\n\ttype AssistantMessageEventStream,\n\ttype Credential,\n\tclassifierErrorResult,\n\timageErrorResult,\n\tisModelType,\n\tlazyStream,\n\ttype Model,\n\ttype OAuthCredentials,\n\ttype Provider,\n\ttype ProviderHeaders,\n\ttype SimpleStreamOptions,\n\ttype StreamOptions,\n\ttype TranscriptContext,\n} from \"@bastani/pi-ai\";\nimport { getApiProvider } from \"@bastani/pi-ai/compat\";\nimport type { ModelConfig, ModelsJsonProvider } from \"./model-config.ts\";\nimport type { AuthStatus, ProviderConfigInput } from \"./provider-composer-internal.ts\";\nimport {\n\tapplyExtension,\n\tapplyModelOverride,\n\tapplyModelsJson,\n\tcomposeApiKeyAuth,\n\tcomposeOAuthAuth,\n\tconfiguredApiKey,\n\tconfiguredHeaders,\n\trawModelHeaders,\n} from \"./provider-composer-internal.ts\";\nimport {\n\tgetConfigValueEnvVarNames,\n\tisCommandConfigValue,\n\tisConfigValueConfigured,\n\tresolveHeadersOrThrow,\n} from \"./resolve-config-value.ts\";\n\nexport type { AuthStatus, ExtensionOAuthConfig, ProviderConfigInput } from \"./provider-composer-internal.ts\";\nexport { clearApiKeyCache } from \"./provider-composer-internal.ts\";\n\nfunction getAllProviderModels(provider: Provider | undefined): readonly AnyModel[] {\n\treturn provider ? (provider.getAllModels?.() ?? provider.getModels()) : [];\n}\n\nexport function validateExtensionProvider(\n\tproviderId: string,\n\tbase: Provider | undefined,\n\tmodelsConfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput,\n): void {\n\tif (extension.aliasOf !== undefined) {\n\t\tif (!providerId.trim() || !extension.aliasOf.trim() || providerId === extension.aliasOf) {\n\t\t\tthrow new Error(\"A provider alias needs distinct, non-empty alias and source IDs.\");\n\t\t}\n\t\tif (Object.keys(extension).some((key) => ![\"aliasOf\", \"name\"].includes(key))) {\n\t\t\tthrow new Error(\"Provider aliases accept only aliasOf and name; configure the source provider instead.\");\n\t\t}\n\t\treturn;\n\t}\n\tif (extension.streamSimple && !extension.api) {\n\t\tthrow new Error(`Provider ${providerId}: \"api\" is required when registering streamSimple.`);\n\t}\n\tapplyExtension(providerId, applyModelsJson(providerId, getAllProviderModels(base), modelsConfig), extension);\n}\n\n/** Compose built-in, models.json, and extension layers without reading credentials. */\nexport function composeModelProvider(\n\tproviderId: string,\n\tbase: Provider | undefined,\n\tmodelConfig: ModelConfig,\n\textension: ProviderConfigInput | undefined,\n): Provider {\n\tconst config = modelConfig.getProvider(providerId);\n\tlet extensionOAuthCredential: OAuthCredentials | undefined;\n\tlet refreshedExtensionModels: ProviderConfigInput[\"models\"];\n\tconst currentExtension = (): ProviderConfigInput | undefined =>\n\t\textension && refreshedExtensionModels ? { ...extension, models: refreshedExtensionModels } : extension;\n\t// models.json modelOverrides are the topmost user-config layer: they apply once,\n\t// after custom-model upserts, extension model replacement, and legacy OAuth projection.\n\tconst getAllModels = (): AnyModel[] => {\n\t\tlet models = applyExtension(\n\t\t\tproviderId,\n\t\t\tapplyModelsJson(providerId, getAllProviderModels(base), config),\n\t\t\tcurrentExtension(),\n\t\t);\n\t\tif (extensionOAuthCredential && extension?.oauth?.modifyModels) {\n\t\t\t// The extension hook is chat-only; other model types pass through untouched.\n\t\t\tmodels = [\n\t\t\t\t...extension.oauth.modifyModels(\n\t\t\t\t\tmodels.filter((model) => isModelType(model, \"chat\")),\n\t\t\t\t\textensionOAuthCredential,\n\t\t\t\t),\n\t\t\t\t...models.filter((model) => !isModelType(model, \"chat\")),\n\t\t\t];\n\t\t}\n\t\treturn models.map((model) => {\n\t\t\tconst override = config?.modelOverrides?.[model.id];\n\t\t\treturn override && isModelType(model, \"chat\") ? applyModelOverride(model, override) : model;\n\t\t});\n\t};\n\t// Validate eagerly so registration/reload reports structural errors immediately.\n\tgetAllModels();\n\tconst apiKey = composeApiKeyAuth(providerId, base, config, extension);\n\tconst oauth = composeOAuthAuth(providerId, base, config, extension);\n\tif (!apiKey && !oauth) throw new Error(`Provider ${providerId}: no authentication method configured.`);\n\n\tconst supportsBaseApi = (model: Model<Api>) => base?.getModels().some((entry) => entry.api === model.api) ?? false;\n\tconst streamWith = (\n\t\tmodel: Model<Api>,\n\t\tcontext: TranscriptContext,\n\t\toptions: StreamOptions | undefined,\n\t\tsimple: boolean,\n\t): AssistantMessageEventStream =>\n\t\tlazyStream(\n\t\t\tmodel,\n\t\t\tasync () => {\n\t\t\t\tif (extension?.streamSimple && model.api === extension.api) {\n\t\t\t\t\treturn extension.streamSimple(model, context, options as SimpleStreamOptions);\n\t\t\t\t}\n\t\t\t\tif (base && supportsBaseApi(model)) {\n\t\t\t\t\treturn simple\n\t\t\t\t\t\t? base.streamSimple(model, context, options as SimpleStreamOptions)\n\t\t\t\t\t\t: base.stream(model, context, options);\n\t\t\t\t}\n\t\t\t\tconst api = getApiProvider(model.api);\n\t\t\t\tif (!api) throw new Error(`No API provider registered for api: ${model.api}`);\n\t\t\t\treturn simple\n\t\t\t\t\t? api.streamSimple(model, context, options as SimpleStreamOptions)\n\t\t\t\t\t: api.stream(model, context, options);\n\t\t\t},\n\t\t\toptions?.signal,\n\t\t);\n\n\tconst provider: Provider = {\n\t\tid: providerId,\n\t\tname: extension?.name ?? config?.name ?? base?.name ?? extension?.oauth?.name ?? providerId,\n\t\tbaseUrl: extension?.baseUrl ?? config?.baseUrl ?? base?.baseUrl,\n\t\theaders: base?.headers,\n\t\tauth: { ...(apiKey ? { apiKey } : {}), ...(oauth ? { oauth } : {}) },\n\t\tgetModels: () => getAllModels().filter((model) => isModelType(model, \"chat\")),\n\t\tgetAllModels,\n\t\trefreshModelsAuth:\n\t\t\textension?.refreshModels || extension?.oauth?.modifyModels ? undefined : base?.refreshModelsAuth,\n\t\trefreshModels:\n\t\t\tbase?.refreshModels || extension?.refreshModels || extension?.oauth?.modifyModels\n\t\t\t\t? async (context) => {\n\t\t\t\t\t\tawait base?.refreshModels?.(context);\n\t\t\t\t\t\tlet refreshed: NonNullable<ProviderConfigInput[\"models\"]> | undefined;\n\t\t\t\t\t\tif (extension?.refreshModels) refreshed = await extension.refreshModels(context);\n\t\t\t\t\t\tif (context.signal.aborted) return;\n\t\t\t\t\t\tconst oauthCredential = context.credential?.type === \"oauth\" ? context.credential : undefined;\n\t\t\t\t\t\tawait context.publish({\n\t\t\t\t\t\t\tupdate: () => {\n\t\t\t\t\t\t\t\tif (refreshed) {\n\t\t\t\t\t\t\t\t\t// Validate before publishing the new synchronous list.\n\t\t\t\t\t\t\t\t\tapplyExtension(providerId, applyModelsJson(providerId, getAllProviderModels(base), config), {\n\t\t\t\t\t\t\t\t\t\t...extension,\n\t\t\t\t\t\t\t\t\t\tmodels: refreshed,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\trefreshedExtensionModels = refreshed;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\textensionOAuthCredential = oauthCredential;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t: undefined,\n\t\tfilterModels: base?.filterModels\n\t\t\t? (models, credential: Credential | undefined) => {\n\t\t\t\t\t// Models the user defines in models.json are an explicit choice: the base provider's\n\t\t\t\t\t// account filter (such as GitHub Copilot's model list) must not hide them.\n\t\t\t\t\tconst isConfigured = (model: Model<Api>) =>\n\t\t\t\t\t\tconfig?.models?.some((entry) => entry.id === model.id) === true;\n\t\t\t\t\tconst filtered = new Map(base.filterModels!(models, credential).map((model) => [model.id, model]));\n\t\t\t\t\treturn models.flatMap((original) => {\n\t\t\t\t\t\tif (isConfigured(original)) return [original];\n\t\t\t\t\t\tconst model = filtered.get(original.id);\n\t\t\t\t\t\tif (model === undefined) return [];\n\t\t\t\t\t\tconst inheritedContext = model.fastRoute\n\t\t\t\t\t\t\t? config?.modelOverrides?.[model.fastRoute.baseModelId]?.contextWindow\n\t\t\t\t\t\t\t: undefined;\n\t\t\t\t\t\tconst personalized =\n\t\t\t\t\t\t\tinheritedContext === undefined ? model : { ...model, contextWindow: inheritedContext };\n\t\t\t\t\t\tconst override = config?.modelOverrides?.[model.id];\n\t\t\t\t\t\treturn [override ? applyModelOverride(personalized, override) : personalized];\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t: undefined,\n\t\tfilterAllModels: base?.filterAllModels\n\t\t\t? (models, credential: Credential | undefined) => base.filterAllModels!(models, credential)\n\t\t\t: undefined,\n\t\tstream: (model, context, options) => streamWith(model, context, options, false),\n\t\tstreamSimple: (model, context, options) => streamWith(model, context, options, true),\n\t};\n\n\tconst fetchDeferred = base?.fetchDeferred;\n\tif (fetchDeferred) {\n\t\tprovider.fetchDeferred = (model, handle, options) => fetchDeferred(model, handle, options);\n\t}\n\tconst cancelDeferred = base?.cancelDeferred;\n\tif (cancelDeferred) {\n\t\tprovider.cancelDeferred = (model, handle, options) => cancelDeferred(model, handle, options);\n\t}\n\tconst extensionImages = extension?.images;\n\tconst generateImages = base?.generateImages;\n\tif (generateImages || Object.keys(extensionImages ?? {}).length > 0) {\n\t\tprovider.generateImages = (model, context, options) => {\n\t\t\tconst implementation = extensionImages?.[model.api];\n\t\t\tif (implementation) return implementation.generateImages(model, context, options);\n\t\t\tif (generateImages) return generateImages(model, context, options);\n\t\t\treturn Promise.resolve(\n\t\t\t\timageErrorResult(model, new Error(`Provider ${providerId} has no image implementation for \"${model.api}\"`)),\n\t\t\t);\n\t\t};\n\t}\n\tconst extensionClassifiers = extension?.classifiers;\n\tconst classify = base?.classify;\n\tif (classify || Object.keys(extensionClassifiers ?? {}).length > 0) {\n\t\tprovider.classify = (model, context, options) => {\n\t\t\tconst implementation = extensionClassifiers?.[model.api];\n\t\t\tif (implementation) return implementation.classify(model, context, options);\n\t\t\tif (classify) return classify(model, context, options);\n\t\t\treturn Promise.resolve(\n\t\t\t\tclassifierErrorResult(\n\t\t\t\t\tmodel,\n\t\t\t\t\tnew Error(`Provider ${providerId} has no classifier implementation for \"${model.api}\"`),\n\t\t\t\t),\n\t\t\t);\n\t\t};\n\t}\n\n\treturn provider;\n}\n\nexport function resolveConfiguredModelHeaders(\n\tmodel: AnyModel,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n\tenv?: Record<string, string>,\n): Record<string, string> | undefined {\n\treturn resolveHeadersOrThrow(\n\t\trawModelHeaders(model, config, extension),\n\t\t`model \"${model.provider}/${model.id}\"`,\n\t\tenv,\n\t);\n}\n\nexport interface CompatibilityRequestConfig {\n\theaders?: ProviderHeaders;\n\tauthHeader: boolean;\n}\n\nexport function resolveCompatibilityRequestConfig(\n\tmodel: AnyModel,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): CompatibilityRequestConfig {\n\tconst configured = resolveHeadersOrThrow(\n\t\t{ ...configuredHeaders(config, extension), ...rawModelHeaders(model, config, extension) },\n\t\t`model \"${model.provider}/${model.id}\"`,\n\t);\n\treturn {\n\t\theaders: model.headers || configured ? { ...model.headers, ...configured } : undefined,\n\t\tauthHeader: extension?.authHeader ?? config?.authHeader ?? false,\n\t};\n}\n\nexport function configuredRequestAuthStatus(\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): AuthStatus | undefined {\n\tconst value = configuredApiKey(config, extension);\n\tif (value === undefined) return undefined;\n\tif (isCommandConfigValue(value)) return { configured: true, source: \"models_json_command\" };\n\tconst names = getConfigValueEnvVarNames(value);\n\tif (names.length > 0) {\n\t\treturn isConfigValueConfigured(value)\n\t\t\t? { configured: true, source: \"environment\", label: names.join(\", \") }\n\t\t\t: { configured: false };\n\t}\n\treturn { configured: true, source: extension?.apiKey !== undefined ? \"fallback\" : \"models_json_key\" };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote-catalog-provider.d.ts","sourceRoot":"","sources":["../../src/core/remote-catalog-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,QAAQ,EAIb,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,KAAK,oBAAoB,EACzB,MAAM,gBAAgB,CAAC;AAOxB,eAAO,MAAM,kCAAkC,QAAqB,CAAC;AACrE;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,EAAE,SAAS,SAAS,EAAoC,CAAC;AAsHhG,kEAAkE;AAClE,MAAM,MAAM,kBAAkB,GAAG,CAChC,OAAO,EAAE,SAAS,QAAQ,EAAE,EAC5B,OAAO,EAAE,oBAAoB,KACzB,OAAO,CAAC,SAAS,QAAQ,EAAE,CAAC,CAAC;AAElC,4EAA4E;AAC5E,wBAAgB,iBAAiB,CAChC,QAAQ,EAAE,QAAQ,EAClB,cAAc,GAAE,MAAiC,EACjD,gBAAgB,CAAC,EAAE,MAAM,GACvB,QAAQ,
|
|
1
|
+
{"version":3,"file":"remote-catalog-provider.d.ts","sourceRoot":"","sources":["../../src/core/remote-catalog-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,QAAQ,EAIb,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,KAAK,oBAAoB,EACzB,MAAM,gBAAgB,CAAC;AAOxB,eAAO,MAAM,kCAAkC,QAAqB,CAAC;AACrE;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,EAAE,SAAS,SAAS,EAAoC,CAAC;AAsHhG,kEAAkE;AAClE,MAAM,MAAM,kBAAkB,GAAG,CAChC,OAAO,EAAE,SAAS,QAAQ,EAAE,EAC5B,OAAO,EAAE,oBAAoB,KACzB,OAAO,CAAC,SAAS,QAAQ,EAAE,CAAC,CAAC;AAElC,4EAA4E;AAC5E,wBAAgB,iBAAiB,CAChC,QAAQ,EAAE,QAAQ,EAClB,cAAc,GAAE,MAAiC,EACjD,gBAAgB,CAAC,EAAE,MAAM,GACvB,QAAQ,CAuFV;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACtC,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,kBAAkB,EAC/B,cAAc,GAAE,MAAiC,EACjD,gBAAgB,CAAC,EAAE,MAAM,GACvB,QAAQ,CA8CV;AAED;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,CAC5B,OAAO,EAAE,SAAS,QAAQ,EAAE,EAC5B,OAAO,EAAE,oBAAoB,KACzB,OAAO,CAAC,SAAS,QAAQ,EAAE,GAAG,SAAS,CAAC,CAAC;AAc9C;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,cAAc,GAAG,QAAQ,CA2D3F"}
|
|
@@ -116,6 +116,7 @@ export function withRemoteCatalog(provider, catalogBaseUrl = DEFAULT_CATALOG_BAS
|
|
|
116
116
|
...provider,
|
|
117
117
|
getModels: () => mergeModels(provider.getModels(), dynamicModels.filter((model) => isModelType(model, "chat"))),
|
|
118
118
|
getAllModels: () => mergeModels(provider.getAllModels?.() ?? provider.getModels(), dynamicModels),
|
|
119
|
+
refreshModelsAuth: "configured",
|
|
119
120
|
refreshModels: async (context) => {
|
|
120
121
|
// 0.84.1 hands the snapshot in directly and coalesces concurrent refreshes
|
|
121
122
|
// itself, so the old inflight-promise dedup is gone. Every mutation of
|
|
@@ -201,6 +202,7 @@ export function withPersonalizedCatalog(provider, personalize, catalogBaseUrl =
|
|
|
201
202
|
...provider,
|
|
202
203
|
getModels: () => getAllModels().filter((model) => isModelType(model, "chat")),
|
|
203
204
|
getAllModels,
|
|
205
|
+
refreshModelsAuth: "credential",
|
|
204
206
|
refreshModels: async (context) => {
|
|
205
207
|
const restored = (context.stored?.models ?? []).filter((model) => model.provider === provider.id && hasOperationShape(model));
|
|
206
208
|
if (!(await context.publish({
|
|
@@ -266,6 +268,7 @@ export function withDiscoveredModels(provider, discover) {
|
|
|
266
268
|
...provider,
|
|
267
269
|
getModels: () => withDiscovered(provider.getModels()).filter((model) => isModelType(model, "chat")),
|
|
268
270
|
getAllModels: () => withDiscovered(catalogModels()),
|
|
271
|
+
refreshModelsAuth: "credential",
|
|
269
272
|
refreshModels: async (context) => {
|
|
270
273
|
const stored = context.stored;
|
|
271
274
|
const saved = (stored?.models ?? []).filter((model) => model.provider === provider.id && isDiscoveredModel(model));
|