@bastani/atomic 0.9.11-alpha.6 → 0.9.11-alpha.8
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 +38 -0
- package/README.md +3 -5
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/mcp/sampling-handler.ts +1 -5
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/CHANGELOG.md +1 -0
- package/dist/builtin/workflows/README.md +1 -1
- package/dist/builtin/workflows/package.json +1 -1
- package/dist/builtin/workflows/skills/impeccable/SKILL.md +33 -129
- package/dist/builtin/workflows/skills/impeccable/agents/impeccable_asset_producer.toml +11 -3
- package/dist/builtin/workflows/skills/impeccable/agents/impeccable_documenter.toml +26 -0
- package/dist/builtin/workflows/skills/impeccable/agents/impeccable_finish_reviewer.toml +35 -0
- package/dist/builtin/workflows/skills/impeccable/reference/android.md +1 -1
- package/dist/builtin/workflows/skills/impeccable/reference/animate.md +72 -189
- package/dist/builtin/workflows/skills/impeccable/reference/audit.md +10 -9
- package/dist/builtin/workflows/skills/impeccable/reference/audit.native.md +2 -2
- package/dist/builtin/workflows/skills/impeccable/reference/bolder.md +19 -108
- package/dist/builtin/workflows/skills/impeccable/reference/clarify.md +59 -253
- package/dist/builtin/workflows/skills/impeccable/reference/colorize.md +51 -222
- package/dist/builtin/workflows/skills/impeccable/reference/craft-floor.md +45 -0
- package/dist/builtin/workflows/skills/impeccable/reference/craft.md +3 -121
- package/dist/builtin/workflows/skills/impeccable/reference/critique.md +28 -20
- package/dist/builtin/workflows/skills/impeccable/reference/degraded/asset-producer.md +97 -0
- package/dist/builtin/workflows/skills/impeccable/reference/degraded/documenter.md +23 -0
- package/dist/builtin/workflows/skills/impeccable/reference/degraded/finish-reviewer.md +32 -0
- package/dist/builtin/workflows/skills/impeccable/reference/degraded/manual-edit-applier.md +92 -0
- package/dist/builtin/workflows/skills/impeccable/reference/delight.md +47 -279
- package/dist/builtin/workflows/skills/impeccable/reference/distill.md +2 -2
- package/dist/builtin/workflows/skills/impeccable/reference/doctor.md +53 -0
- package/dist/builtin/workflows/skills/impeccable/reference/document.md +60 -73
- package/dist/builtin/workflows/skills/impeccable/reference/harden.md +1 -12
- package/dist/builtin/workflows/skills/impeccable/reference/hooks.md +17 -4
- package/dist/builtin/workflows/skills/impeccable/reference/init.md +64 -163
- package/dist/builtin/workflows/skills/impeccable/reference/ios.md +1 -1
- package/dist/builtin/workflows/skills/impeccable/reference/layout.md +52 -153
- package/dist/builtin/workflows/skills/impeccable/reference/live.md +44 -32
- package/dist/builtin/workflows/skills/impeccable/reference/new-work.md +105 -0
- package/dist/builtin/workflows/skills/impeccable/reference/{product.md → operate.md} +6 -5
- package/dist/builtin/workflows/skills/impeccable/reference/optimize.md +4 -4
- package/dist/builtin/workflows/skills/impeccable/reference/overdrive.md +1 -4
- package/dist/builtin/workflows/skills/impeccable/reference/polish.md +68 -212
- package/dist/builtin/workflows/skills/impeccable/reference/quieter.md +3 -3
- package/dist/builtin/workflows/skills/impeccable/reference/routing.md +18 -0
- package/dist/builtin/workflows/skills/impeccable/reference/shape.md +38 -144
- package/dist/builtin/workflows/skills/impeccable/reference/typeset.md +48 -269
- package/dist/builtin/workflows/skills/impeccable/reference/visualize.md +38 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/command-metadata.json +1 -1
- package/dist/builtin/workflows/skills/impeccable/scripts/concept-seed.mjs +584 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/context-signals.mjs +117 -9
- package/dist/builtin/workflows/skills/impeccable/scripts/context.mjs +486 -59
- package/dist/builtin/workflows/skills/impeccable/scripts/critique-storage.mjs +16 -45
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/browser/injected/index.mjs +96 -10
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/cli/main.mjs +143 -26
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/design-system.mjs +181 -12
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/detect-antipatterns-browser.js +3187 -182
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/engines/browser/detect-url.mjs +102 -7
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/engines/regex/detect-text.mjs +282 -70
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/engines/static-html/css-cascade.mjs +183 -15
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/engines/static-html/detect-html.mjs +22 -7
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/findings.mjs +7 -1
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/node/file-system.mjs +16 -2
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/registry/antipatterns.mjs +155 -42
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/rules/checks.mjs +2988 -155
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/shared/constants.mjs +11 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/doctor.mjs +336 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/generate-image.mjs +232 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/hook-admin.mjs +90 -10
- package/dist/builtin/workflows/skills/impeccable/scripts/hook-lib.mjs +410 -78
- package/dist/builtin/workflows/skills/impeccable/scripts/hook.mjs +25 -8
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/artifact-schema.mjs +93 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/composition-catalog.mjs +165 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/concept-catalog.mjs +329 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/impeccable-config.mjs +20 -5
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/impeccable-paths.mjs +16 -8
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/provider.mjs +1 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/staleness-deep.mjs +455 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/staleness-notice.mjs +169 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/staleness.mjs +457 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/surface-briefs.mjs +151 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/target-slug.mjs +33 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/template-extensions.mjs +146 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live/completion.mjs +10 -1
- package/dist/builtin/workflows/skills/impeccable/scripts/live/event-validation.mjs +15 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live/generation-preflight.mjs +149 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live/poll-lanes.mjs +14 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live/session-store.mjs +109 -32
- package/dist/builtin/workflows/skills/impeccable/scripts/live/source-lock.mjs +105 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live/source-search.mjs +105 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live/sveltekit-adapter.mjs +8 -6
- package/dist/builtin/workflows/skills/impeccable/scripts/live/tanstack-adapter.mjs +280 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live-accept.mjs +208 -68
- package/dist/builtin/workflows/skills/impeccable/scripts/live-browser.js +563 -112
- package/dist/builtin/workflows/skills/impeccable/scripts/live-commit-manual-edits.mjs +3 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live-inject.mjs +198 -13
- package/dist/builtin/workflows/skills/impeccable/scripts/live-insert.mjs +24 -6
- package/dist/builtin/workflows/skills/impeccable/scripts/live-manual-edit-evidence.mjs +6 -1
- package/dist/builtin/workflows/skills/impeccable/scripts/live-poll.mjs +44 -14
- package/dist/builtin/workflows/skills/impeccable/scripts/live-server.mjs +398 -33
- package/dist/builtin/workflows/skills/impeccable/scripts/live-status.mjs +9 -5
- package/dist/builtin/workflows/skills/impeccable/scripts/live-wrap.mjs +81 -67
- package/dist/builtin/workflows/skills/impeccable/scripts/live.mjs +7 -2
- package/dist/builtin/workflows/skills/impeccable/scripts/palette.mjs +76 -81
- package/dist/builtin/workflows/skills/impeccable/scripts/pin.mjs +2 -2
- package/dist/builtin/workflows/skills/impeccable/scripts/serve-question.mjs +890 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/surface-brief.mjs +74 -0
- package/dist/builtin/workflows/src/extension/extension-runtime-state.ts +1 -24
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +232 -50
- package/dist/builtin/workflows/src/extension/workflow-model-catalog.ts +26 -0
- package/dist/builtin/workflows/src/extension/workflow-prompts.ts +3 -2
- package/dist/builtin/workflows/src/runs/foreground/executor-stage-control.ts +23 -9
- package/dist/builtin/workflows/src/runs/foreground/executor-stage-replay.ts +1 -0
- package/dist/builtin/workflows/src/runs/foreground/postmortem-stage-chat.ts +20 -5
- package/dist/builtin/workflows/src/runs/foreground/stage-control-registry.ts +10 -0
- package/dist/builtin/workflows/src/runs/foreground/stage-delivery-activity.ts +86 -0
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-context.ts +6 -2
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-controller.ts +24 -18
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-send-user-message.ts +8 -0
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-session-options.ts +3 -3
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-session.ts +2 -2
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-types.ts +16 -0
- package/dist/builtin/workflows/src/tui/stage-chat-view-delivery-activity.ts +121 -0
- package/dist/builtin/workflows/src/tui/stage-chat-view-live-events.ts +42 -0
- package/dist/builtin/workflows/src/tui/stage-chat-view-state.ts +16 -0
- package/dist/builtin/workflows/src/tui/stage-chat-view-types.ts +4 -0
- package/dist/cli/list-models.d.ts +2 -2
- package/dist/cli/list-models.d.ts.map +1 -1
- package/dist/cli/list-models.js +5 -5
- package/dist/cli/list-models.js.map +1 -1
- package/dist/core/agent-session-accessors.js +1 -1
- package/dist/core/agent-session-accessors.js.map +1 -1
- package/dist/core/agent-session-auto-compaction.d.ts.map +1 -1
- package/dist/core/agent-session-auto-compaction.js +2 -5
- package/dist/core/agent-session-auto-compaction.js.map +1 -1
- package/dist/core/agent-session-compaction.js +1 -1
- package/dist/core/agent-session-compaction.js.map +1 -1
- package/dist/core/agent-session-extension-bindings.js +5 -5
- package/dist/core/agent-session-extension-bindings.js.map +1 -1
- package/dist/core/agent-session-methods.d.ts +4 -4
- 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-models.d.ts +1 -1
- package/dist/core/agent-session-models.d.ts.map +1 -1
- package/dist/core/agent-session-models.js +18 -14
- package/dist/core/agent-session-models.js.map +1 -1
- package/dist/core/agent-session-post-tool-compaction.d.ts.map +1 -1
- package/dist/core/agent-session-post-tool-compaction.js +2 -4
- package/dist/core/agent-session-post-tool-compaction.js.map +1 -1
- package/dist/core/agent-session-prompt.d.ts.map +1 -1
- package/dist/core/agent-session-prompt.js +3 -7
- package/dist/core/agent-session-prompt.js.map +1 -1
- package/dist/core/agent-session-retry.js +1 -1
- package/dist/core/agent-session-retry.js.map +1 -1
- package/dist/core/agent-session-runtime-auth.d.ts +3 -3
- package/dist/core/agent-session-runtime-auth.d.ts.map +1 -1
- package/dist/core/agent-session-runtime-auth.js +4 -14
- package/dist/core/agent-session-runtime-auth.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +1 -1
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +3 -3
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +3 -8
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +16 -23
- package/dist/core/agent-session-services.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-types.d.ts +2 -2
- package/dist/core/agent-session-types.d.ts.map +1 -1
- package/dist/core/agent-session-types.js.map +1 -1
- package/dist/core/agent-session.d.ts +2 -2
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +1 -1
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage-backends.d.ts +1 -0
- package/dist/core/auth-storage-backends.d.ts.map +1 -1
- package/dist/core/auth-storage-backends.js +18 -4
- package/dist/core/auth-storage-backends.js.map +1 -1
- package/dist/core/auth-storage.d.ts +12 -139
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +68 -374
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/copilot-env-routing.d.ts +36 -0
- package/dist/core/copilot-env-routing.d.ts.map +1 -0
- package/dist/core/copilot-env-routing.js +94 -0
- package/dist/core/copilot-env-routing.js.map +1 -0
- package/dist/core/extensions/loader-virtual-modules.d.ts.map +1 -1
- package/dist/core/extensions/loader-virtual-modules.js +10 -2
- package/dist/core/extensions/loader-virtual-modules.js.map +1 -1
- package/dist/core/extensions/provider-types.d.ts +0 -40
- package/dist/core/extensions/provider-types.d.ts.map +1 -1
- package/dist/core/extensions/provider-types.js.map +1 -1
- package/dist/core/fallback-models.d.ts +4 -4
- package/dist/core/fallback-models.d.ts.map +1 -1
- package/dist/core/fallback-models.js +3 -3
- package/dist/core/fallback-models.js.map +1 -1
- package/dist/core/model-config.d.ts +542 -0
- package/dist/core/model-config.d.ts.map +1 -0
- package/dist/core/{model-registry-schemas.js → model-config.js} +85 -34
- package/dist/core/model-config.js.map +1 -0
- package/dist/core/model-registry.d.ts +25 -85
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +65 -388
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver-cli.d.ts +2 -2
- package/dist/core/model-resolver-cli.d.ts.map +1 -1
- package/dist/core/model-resolver-cli.js +2 -2
- package/dist/core/model-resolver-cli.js.map +1 -1
- package/dist/core/model-resolver-initial.d.ts +4 -4
- package/dist/core/model-resolver-initial.d.ts.map +1 -1
- package/dist/core/model-resolver-initial.js +17 -17
- package/dist/core/model-resolver-initial.js.map +1 -1
- package/dist/core/model-resolver-scope.d.ts +3 -3
- package/dist/core/model-resolver-scope.d.ts.map +1 -1
- package/dist/core/model-resolver-scope.js +4 -4
- package/dist/core/model-resolver-scope.js.map +1 -1
- package/dist/core/model-runtime-auth.d.ts +7 -0
- package/dist/core/model-runtime-auth.d.ts.map +1 -0
- package/dist/core/model-runtime-auth.js +14 -0
- package/dist/core/model-runtime-auth.js.map +1 -0
- package/dist/core/model-runtime-providers.d.ts +6 -0
- package/dist/core/model-runtime-providers.d.ts.map +1 -0
- package/dist/core/model-runtime-providers.js +22 -0
- package/dist/core/model-runtime-providers.js.map +1 -0
- package/dist/core/model-runtime-restoration.d.ts +6 -0
- package/dist/core/model-runtime-restoration.d.ts.map +1 -0
- package/dist/core/model-runtime-restoration.js +21 -0
- package/dist/core/model-runtime-restoration.js.map +1 -0
- package/dist/core/model-runtime-snapshot.d.ts +16 -0
- package/dist/core/model-runtime-snapshot.d.ts.map +1 -0
- package/dist/core/model-runtime-snapshot.js +52 -0
- package/dist/core/model-runtime-snapshot.js.map +1 -0
- package/dist/core/model-runtime-streaming.d.ts +17 -0
- package/dist/core/model-runtime-streaming.d.ts.map +1 -0
- package/dist/core/model-runtime-streaming.js +66 -0
- package/dist/core/model-runtime-streaming.js.map +1 -0
- package/dist/core/model-runtime-types.d.ts +21 -0
- package/dist/core/model-runtime-types.d.ts.map +1 -0
- package/dist/core/model-runtime-types.js +2 -0
- package/dist/core/model-runtime-types.js.map +1 -0
- package/dist/core/model-runtime.d.ts +50 -29
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +330 -90
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/models-store.d.ts +2 -10
- package/dist/core/models-store.d.ts.map +1 -1
- package/dist/core/models-store.js +2 -29
- package/dist/core/models-store.js.map +1 -1
- package/dist/core/oauth-login.d.ts +24 -0
- package/dist/core/oauth-login.d.ts.map +1 -0
- package/dist/core/oauth-login.js +87 -0
- package/dist/core/oauth-login.js.map +1 -0
- package/dist/core/oauth-provider-metadata.d.ts +5 -0
- package/dist/core/oauth-provider-metadata.d.ts.map +1 -0
- package/dist/core/oauth-provider-metadata.js +19 -0
- package/dist/core/oauth-provider-metadata.js.map +1 -0
- package/dist/core/provider-composer-internal.d.ts +53 -0
- package/dist/core/provider-composer-internal.d.ts.map +1 -0
- package/dist/core/provider-composer-internal.js +273 -0
- package/dist/core/provider-composer-internal.js.map +1 -0
- package/dist/core/provider-composer.d.ts +16 -0
- package/dist/core/provider-composer.d.ts.map +1 -0
- package/dist/core/provider-composer.js +108 -0
- package/dist/core/provider-composer.js.map +1 -0
- package/dist/core/remote-catalog-provider.d.ts.map +1 -1
- package/dist/core/remote-catalog-provider.js +74 -122
- package/dist/core/remote-catalog-provider.js.map +1 -1
- package/dist/core/resolve-config-value.d.ts +8 -7
- package/dist/core/resolve-config-value.d.ts.map +1 -1
- package/dist/core/resolve-config-value.js +26 -23
- package/dist/core/resolve-config-value.js.map +1 -1
- package/dist/core/runtime-credentials.d.ts +16 -0
- package/dist/core/runtime-credentials.d.ts.map +1 -0
- package/dist/core/runtime-credentials.js +42 -0
- package/dist/core/runtime-credentials.js.map +1 -0
- package/dist/core/sdk-types.d.ts +1 -7
- package/dist/core/sdk-types.d.ts.map +1 -1
- package/dist/core/sdk-types.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +27 -28
- package/dist/core/sdk.js.map +1 -1
- package/dist/extensions/llama/index.js +1 -1
- package/dist/extensions/llama/index.js.map +1 -1
- package/dist/extensions/llama/provider.d.ts +2 -4
- package/dist/extensions/llama/provider.d.ts.map +1 -1
- package/dist/extensions/llama/provider.js +25 -17
- package/dist/extensions/llama/provider.js.map +1 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -4
- package/dist/index.js.map +1 -1
- package/dist/main-runtime-api-key.d.ts +6 -0
- package/dist/main-runtime-api-key.d.ts.map +1 -0
- package/dist/main-runtime-api-key.js +6 -0
- package/dist/main-runtime-api-key.js.map +1 -0
- package/dist/main-session-options.d.ts +2 -2
- package/dist/main-session-options.d.ts.map +1 -1
- package/dist/main-session-options.js +3 -3
- package/dist/main-session-options.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +9 -11
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-actions.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-actions.js +2 -14
- package/dist/modes/interactive/components/chat-session-host-actions.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-events.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-events.js +9 -0
- package/dist/modes/interactive/components/chat-session-host-events.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-runtime.d.ts +25 -0
- package/dist/modes/interactive/components/chat-session-host-runtime.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-runtime.js +53 -0
- package/dist/modes/interactive/components/chat-session-host-runtime.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host.d.ts +13 -0
- package/dist/modes/interactive/components/chat-session-host.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host.js +22 -1
- package/dist/modes/interactive/components/chat-session-host.js.map +1 -1
- package/dist/modes/interactive/components/footer.js +1 -1
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
- package/dist/modes/interactive/components/login-dialog.js +1 -3
- package/dist/modes/interactive/components/login-dialog.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts +4 -3
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +56 -73
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.d.ts +4 -3
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.js +15 -24
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-agent-events.js +10 -4
- package/dist/modes/interactive/interactive-agent-events.js.map +1 -1
- package/dist/modes/interactive/interactive-auth-login.js +20 -31
- package/dist/modes/interactive/interactive-auth-login.js.map +1 -1
- package/dist/modes/interactive/interactive-auth-routing.d.ts +1 -1
- package/dist/modes/interactive/interactive-auth-routing.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-auth-routing.js +21 -47
- package/dist/modes/interactive/interactive-auth-routing.js.map +1 -1
- package/dist/modes/interactive/interactive-autocomplete.js +3 -3
- package/dist/modes/interactive/interactive-autocomplete.js.map +1 -1
- package/dist/modes/interactive/interactive-deferred-startup.js +8 -8
- package/dist/modes/interactive/interactive-deferred-startup.js.map +1 -1
- package/dist/modes/interactive/interactive-extension-runtime.js +2 -1
- package/dist/modes/interactive/interactive-extension-runtime.js.map +1 -1
- package/dist/modes/interactive/interactive-model-catalog-startup.js +2 -2
- package/dist/modes/interactive/interactive-model-catalog-startup.js.map +1 -1
- package/dist/modes/interactive/interactive-model-routing.js +11 -11
- package/dist/modes/interactive/interactive-model-routing.js.map +1 -1
- package/dist/modes/interactive/interactive-render-chat.js +1 -1
- package/dist/modes/interactive/interactive-render-chat.js.map +1 -1
- package/dist/modes/interactive/interactive-slash-commands.js +2 -2
- package/dist/modes/interactive/interactive-slash-commands.js.map +1 -1
- package/dist/modes/interactive/interactive-startup.js +1 -1
- package/dist/modes/interactive/interactive-startup.js.map +1 -1
- package/dist/modes/interactive-engine/isolated-auth.d.ts +2 -2
- package/dist/modes/interactive-engine/isolated-auth.d.ts.map +1 -1
- package/dist/modes/interactive-engine/isolated-auth.js +4 -3
- package/dist/modes/interactive-engine/isolated-auth.js.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.js +4 -3
- package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
- package/dist/modes/interactive-engine/remote-model-catalog.d.ts +0 -1
- package/dist/modes/interactive-engine/remote-model-catalog.d.ts.map +1 -1
- package/dist/modes/interactive-engine/remote-model-catalog.js +11 -50
- package/dist/modes/interactive-engine/remote-model-catalog.js.map +1 -1
- package/dist/modes/rpc/rpc-client-api.d.ts +2 -2
- 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-command-handler.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-command-handler.js +26 -19
- package/dist/modes/rpc/rpc-command-handler.js.map +1 -1
- package/dist/modes/rpc/rpc-oauth-client.d.ts +1 -1
- package/dist/modes/rpc/rpc-oauth-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-oauth-client.js +1 -1
- package/dist/modes/rpc/rpc-oauth-client.js.map +1 -1
- package/dist/modes/rpc/rpc-oauth-interaction.d.ts +1 -1
- package/dist/modes/rpc/rpc-oauth-interaction.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-oauth-interaction.js +1 -1
- package/dist/modes/rpc/rpc-oauth-interaction.js.map +1 -1
- package/dist/modes/rpc/rpc-provider-auth.d.ts +4 -5
- package/dist/modes/rpc/rpc-provider-auth.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-provider-auth.js +19 -66
- package/dist/modes/rpc/rpc-provider-auth.js.map +1 -1
- package/dist/modes/rpc/rpc-session-binding.js +1 -1
- package/dist/modes/rpc/rpc-session-binding.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +7 -4
- 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 +5 -7
- package/dist/package-manager-cli.js.map +1 -1
- package/docs/changelog.mdx +1 -1
- package/docs/custom-provider.md +1 -1
- package/docs/models.md +4 -6
- package/docs/providers.md +13 -0
- package/docs/quickstart.md +2 -1
- package/docs/sdk.md +32 -49
- package/docs/tui.md +7 -2
- package/docs/workflows.md +4 -4
- package/examples/sdk/02-custom-model.ts +8 -10
- package/examples/sdk/09-api-keys-and-oauth.ts +17 -23
- package/examples/sdk/12-full-control.ts +9 -11
- package/examples/sdk/README.md +17 -21
- package/npm-shrinkwrap.json +23 -23
- package/package.json +2 -2
- package/dist/builtin/workflows/skills/impeccable/reference/brand.md +0 -108
- package/dist/builtin/workflows/skills/impeccable/reference/codex.md +0 -105
- package/dist/builtin/workflows/skills/impeccable/reference/interaction-design.md +0 -189
- package/dist/core/model-registry-auth.d.ts +0 -10
- package/dist/core/model-registry-auth.d.ts.map +0 -1
- package/dist/core/model-registry-auth.js +0 -98
- package/dist/core/model-registry-auth.js.map +0 -1
- package/dist/core/model-registry-builtins.d.ts +0 -8
- package/dist/core/model-registry-builtins.d.ts.map +0 -1
- package/dist/core/model-registry-builtins.js +0 -104
- package/dist/core/model-registry-builtins.js.map +0 -1
- package/dist/core/model-registry-custom-loader.d.ts +0 -3
- package/dist/core/model-registry-custom-loader.d.ts.map +0 -1
- package/dist/core/model-registry-custom-loader.js +0 -255
- package/dist/core/model-registry-custom-loader.js.map +0 -1
- package/dist/core/model-registry-dynamic.d.ts +0 -7
- package/dist/core/model-registry-dynamic.d.ts.map +0 -1
- package/dist/core/model-registry-dynamic.js +0 -189
- package/dist/core/model-registry-dynamic.js.map +0 -1
- package/dist/core/model-registry-extension-refresh.d.ts +0 -23
- package/dist/core/model-registry-extension-refresh.d.ts.map +0 -1
- package/dist/core/model-registry-extension-refresh.js +0 -32
- package/dist/core/model-registry-extension-refresh.js.map +0 -1
- package/dist/core/model-registry-loader.d.ts +0 -5
- package/dist/core/model-registry-loader.d.ts.map +0 -1
- package/dist/core/model-registry-loader.js +0 -29
- package/dist/core/model-registry-loader.js.map +0 -1
- package/dist/core/model-registry-schemas.d.ts +0 -1399
- package/dist/core/model-registry-schemas.d.ts.map +0 -1
- package/dist/core/model-registry-schemas.js.map +0 -1
- package/dist/core/model-registry-types.d.ts +0 -91
- package/dist/core/model-registry-types.d.ts.map +0 -1
- package/dist/core/model-registry-types.js +0 -2
- package/dist/core/model-registry-types.js.map +0 -1
- package/dist/core/model-registry-validation.d.ts +0 -7
- package/dist/core/model-registry-validation.d.ts.map +0 -1
- package/dist/core/model-registry-validation.js +0 -12
- package/dist/core/model-registry-validation.js.map +0 -1
- package/dist/core/oauth-compat.d.ts +0 -17
- package/dist/core/oauth-compat.d.ts.map +0 -1
- package/dist/core/oauth-compat.js +0 -2
- package/dist/core/oauth-compat.js.map +0 -1
- package/dist/core/oauth-provider-bridge.d.ts +0 -63
- package/dist/core/oauth-provider-bridge.d.ts.map +0 -1
- package/dist/core/oauth-provider-bridge.js +0 -232
- package/dist/core/oauth-provider-bridge.js.map +0 -1
|
@@ -1,426 +1,103 @@
|
|
|
1
|
+
export { clearApiKeyCache } from "./provider-composer.js";
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
-
|
|
4
|
-
import { createModels, } from "@earendil-works/pi-ai";
|
|
5
|
-
import { builtinProviders, getBuiltinModelDataGeneratedAt } from "@earendil-works/pi-ai/providers/all";
|
|
6
|
-
import { dirname, join } from "node:path";
|
|
7
|
-
import { isDeepStrictEqual } from "node:util";
|
|
8
|
-
import { getAgentConfigPaths } from "../config.js";
|
|
9
|
-
import { normalizePath } from "../utils/paths.js";
|
|
10
|
-
import { getModelRequestAuth, getApiKeyForProviderFromConfig, getProviderAuthStatusFromConfig, getProviderResolvedAuth } from "./model-registry-auth.js";
|
|
11
|
-
import { applyProviderConfigToModels, migrateLegacyRegisterProviderConfigValues, unregisterProviderRuntime, validateProviderConfig } from "./model-registry-dynamic.js";
|
|
12
|
-
import { loadModelRegistryModels } from "./model-registry-loader.js";
|
|
13
|
-
import { refreshExtensionProvider } from "./model-registry-extension-refresh.js";
|
|
14
|
-
import { BUILT_IN_PROVIDER_DISPLAY_NAMES } from "./provider-display-names.js";
|
|
15
|
-
import { FileModelsStore, InMemoryCodingAgentModelsStore } from "./models-store.js";
|
|
16
|
-
import { getLegacyOAuthProvider, oauthCredentialToAuth } from "./oauth-provider-bridge.js";
|
|
17
|
-
import { withRemoteCatalog } from "./remote-catalog-provider.js";
|
|
18
|
-
import { clearConfigValueCache, isConfigValueConfigured } from "./resolve-config-value.js";
|
|
19
|
-
const REMOTE_CATALOG_PROVIDERS = new Set(["github-copilot", "openrouter", "vercel-ai-gateway"]);
|
|
20
|
-
const OPENAI_COMPATIBLE_APIS = new Set(["openai-completions", "openai-responses"]);
|
|
21
|
-
let nextRegistryRegistrationId = 0;
|
|
22
|
-
function overlayRuntimeApiKey(runtimeApiKey, resolvedAuth, storedOAuthAuth, runtimeBaseUrl) {
|
|
23
|
-
const headers = storedOAuthAuth?.headers || resolvedAuth?.headers
|
|
24
|
-
? { ...storedOAuthAuth?.headers, ...resolvedAuth?.headers }
|
|
25
|
-
: undefined;
|
|
26
|
-
return {
|
|
27
|
-
...storedOAuthAuth,
|
|
28
|
-
...resolvedAuth,
|
|
29
|
-
apiKey: runtimeApiKey,
|
|
30
|
-
headers,
|
|
31
|
-
baseUrl: runtimeBaseUrl ?? storedOAuthAuth?.baseUrl ?? resolvedAuth?.baseUrl,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
function createProviderCredentialStore(credentials) {
|
|
35
|
-
return {
|
|
36
|
-
...credentials,
|
|
37
|
-
read: async (providerId) => {
|
|
38
|
-
const credential = await credentials.read(providerId);
|
|
39
|
-
if (credential?.type !== "oauth" || !getLegacyOAuthProvider(providerId))
|
|
40
|
-
return credential;
|
|
41
|
-
const auth = await oauthCredentialToAuth(providerId, credential);
|
|
42
|
-
return auth?.apiKey === undefined ? undefined : { type: "api_key", key: auth.apiKey };
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
/** Clear the config value command cache. Exported for testing. */
|
|
47
|
-
export const clearApiKeyCache = clearConfigValueCache;
|
|
48
|
-
/**
|
|
49
|
-
* Model registry - loads and manages models, resolves API keys via AuthStorage.
|
|
3
|
+
* Synchronous compatibility facade exposed to extensions.
|
|
4
|
+
* Coding-agent internals use ModelRuntime directly.
|
|
50
5
|
*/
|
|
51
6
|
export class ModelRegistry {
|
|
52
|
-
constructor(
|
|
53
|
-
this.
|
|
54
|
-
this.modelOverrides = new Map();
|
|
55
|
-
this.providerRequestConfigs = new Map();
|
|
56
|
-
this.modelRequestHeaders = new Map();
|
|
57
|
-
this.registeredProviders = new Map();
|
|
58
|
-
this.nativeProviders = new Map();
|
|
59
|
-
this.builtInProviders = new Set();
|
|
60
|
-
this.customOpenAICompatibleProviders = new Set();
|
|
61
|
-
this.loadError = undefined;
|
|
62
|
-
this.refreshGeneration = 0;
|
|
63
|
-
this.resolvedCustomAuthProviders = new Set();
|
|
64
|
-
this.registrationSource = `atomic:model-registry:${++nextRegistryRegistrationId}`;
|
|
65
|
-
this.defaultProviders = new Map();
|
|
66
|
-
this.configuredProviderIds = new Set();
|
|
67
|
-
this.authStorage = authStorage;
|
|
68
|
-
this.modelsJsonPaths = modelsJsonPaths.map((path) => normalizePath(path));
|
|
69
|
-
this.modelDataDir = modelDataDir ? normalizePath(modelDataDir) : this.modelsJsonPaths[0] ? dirname(this.modelsJsonPaths[0]) : undefined;
|
|
70
|
-
this.modelsStore = this.modelDataDir ? new FileModelsStore(join(this.modelDataDir, "models-store.json")) : new InMemoryCodingAgentModelsStore();
|
|
71
|
-
this.credentialStore = authStorage.asCredentialStore();
|
|
72
|
-
this.providerModels = createModels({
|
|
73
|
-
credentials: createProviderCredentialStore(this.credentialStore),
|
|
74
|
-
modelsStore: this.modelsStore,
|
|
75
|
-
});
|
|
76
|
-
const builtinModelDataGeneratedAt = getBuiltinModelDataGeneratedAt();
|
|
77
|
-
for (const provider of builtinProviders()) {
|
|
78
|
-
const configured = provider.id === "radius"
|
|
79
|
-
? provider
|
|
80
|
-
: withRemoteCatalog(provider, undefined, builtinModelDataGeneratedAt);
|
|
81
|
-
this.defaultProviders.set(provider.id, configured);
|
|
82
|
-
this.providerModels.setProvider(configured);
|
|
83
|
-
}
|
|
84
|
-
this.loadModels();
|
|
7
|
+
constructor(runtime) {
|
|
8
|
+
this.runtime = runtime;
|
|
85
9
|
}
|
|
86
|
-
|
|
87
|
-
|
|
10
|
+
/** Reload models.json asynchronously. Await before making synchronous registry reads. */
|
|
11
|
+
async refresh() {
|
|
12
|
+
await this.runtime.refresh();
|
|
88
13
|
}
|
|
89
|
-
static inMemory(authStorage) { return new ModelRegistry(authStorage, []); }
|
|
90
|
-
async refresh(options = {}) {
|
|
91
|
-
const generation = ++this.refreshGeneration;
|
|
92
|
-
this.loadError = undefined;
|
|
93
|
-
this.rebuildProviderModels();
|
|
94
|
-
const controller = new AbortController();
|
|
95
|
-
const abort = () => controller.abort();
|
|
96
|
-
options.signal?.addEventListener("abort", abort, { once: true });
|
|
97
|
-
if (options.signal?.aborted)
|
|
98
|
-
controller.abort(options.signal.reason);
|
|
99
|
-
const timeout = setTimeout(abort, options.timeoutMs ?? 15_000);
|
|
100
|
-
const errors = new Map();
|
|
101
|
-
const aborted = new Promise((resolve) => {
|
|
102
|
-
if (controller.signal.aborted)
|
|
103
|
-
resolve();
|
|
104
|
-
else
|
|
105
|
-
controller.signal.addEventListener("abort", () => resolve(), { once: true });
|
|
106
|
-
});
|
|
107
|
-
try {
|
|
108
|
-
const restore = this.providerModels
|
|
109
|
-
.refresh({ allowNetwork: false, signal: controller.signal })
|
|
110
|
-
.then((result) => {
|
|
111
|
-
if (controller.signal.aborted || generation !== this.refreshGeneration)
|
|
112
|
-
return;
|
|
113
|
-
for (const [provider, error] of result.errors)
|
|
114
|
-
errors.set(provider, error);
|
|
115
|
-
this.publishProviderModels();
|
|
116
|
-
});
|
|
117
|
-
await Promise.race([restore, aborted]);
|
|
118
|
-
if (options.allowNetwork !== false && !controller.signal.aborted) {
|
|
119
|
-
const legacyOAuthProviders = new Set([
|
|
120
|
-
...this.models.map((model) => model.provider),
|
|
121
|
-
...[...this.registeredProviders]
|
|
122
|
-
.filter(([, config]) => config.oauth !== undefined)
|
|
123
|
-
.map(([providerId]) => providerId),
|
|
124
|
-
].filter((providerId) => getLegacyOAuthProvider(providerId) !== undefined));
|
|
125
|
-
const refreshLegacyOAuth = Promise.all([...legacyOAuthProviders].map(async (providerId) => {
|
|
126
|
-
const credential = this.authStorage.get(providerId);
|
|
127
|
-
if (credential?.type !== "oauth" || Date.now() < credential.expires)
|
|
128
|
-
return;
|
|
129
|
-
await this.authStorage.getModelAuth(providerId, { includeFallback: false });
|
|
130
|
-
}));
|
|
131
|
-
await Promise.race([refreshLegacyOAuth, aborted]);
|
|
132
|
-
}
|
|
133
|
-
const extensionRefreshes = controller.signal.aborted ? [] : [...this.registeredProviders].map(async ([providerName, config]) => {
|
|
134
|
-
if (!config.refreshModels)
|
|
135
|
-
return;
|
|
136
|
-
const isCurrentExtensionRefresh = () => !controller.signal.aborted
|
|
137
|
-
&& generation === this.refreshGeneration
|
|
138
|
-
&& this.registeredProviders.get(providerName) === config;
|
|
139
|
-
const store = {
|
|
140
|
-
read: () => this.modelsStore.read(providerName),
|
|
141
|
-
write: (entry) => this.modelsStore.writeIf(providerName, entry, isCurrentExtensionRefresh),
|
|
142
|
-
delete: () => this.modelsStore.deleteIf(providerName, isCurrentExtensionRefresh),
|
|
143
|
-
};
|
|
144
|
-
try {
|
|
145
|
-
let credential = await this.credentialStore.read(providerName);
|
|
146
|
-
if (credential?.type === "api_key") {
|
|
147
|
-
const effectiveApiKey = await this.authStorage.getApiKey(providerName, { includeFallback: false });
|
|
148
|
-
credential = { ...credential, key: effectiveApiKey };
|
|
149
|
-
}
|
|
150
|
-
if (credential === undefined) {
|
|
151
|
-
const customAuth = await getProviderResolvedAuth(providerName, this.authStorage, this.providerRequestConfigs);
|
|
152
|
-
if (customAuth) {
|
|
153
|
-
this.resolvedCustomAuthProviders.add(providerName);
|
|
154
|
-
credential = { type: "api_key", key: customAuth.auth.apiKey, env: customAuth.env };
|
|
155
|
-
}
|
|
156
|
-
else
|
|
157
|
-
this.resolvedCustomAuthProviders.delete(providerName);
|
|
158
|
-
const configuredApiKey = customAuth ? undefined : await getApiKeyForProviderFromConfig(providerName, this.authStorage, this.providerRequestConfigs);
|
|
159
|
-
if (configuredApiKey !== undefined)
|
|
160
|
-
credential = { type: "api_key", key: configuredApiKey };
|
|
161
|
-
}
|
|
162
|
-
if (!isCurrentExtensionRefresh())
|
|
163
|
-
return;
|
|
164
|
-
const refreshed = await refreshExtensionProvider({
|
|
165
|
-
config,
|
|
166
|
-
credential,
|
|
167
|
-
store,
|
|
168
|
-
allowNetwork: options.allowNetwork ?? true,
|
|
169
|
-
force: options.force,
|
|
170
|
-
signal: controller.signal,
|
|
171
|
-
isCurrent: isCurrentExtensionRefresh,
|
|
172
|
-
});
|
|
173
|
-
if (!isCurrentExtensionRefresh())
|
|
174
|
-
return;
|
|
175
|
-
if (refreshed.error)
|
|
176
|
-
errors.set(providerName, refreshed.error);
|
|
177
|
-
if (!refreshed.models)
|
|
178
|
-
return;
|
|
179
|
-
this.registeredProviders.set(providerName, { ...config, models: refreshed.models });
|
|
180
|
-
this.rebuildProviderModels();
|
|
181
|
-
}
|
|
182
|
-
catch (error) {
|
|
183
|
-
if (isCurrentExtensionRefresh())
|
|
184
|
-
errors.set(providerName, error instanceof Error ? error : new Error(String(error)));
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
const builtinRefresh = controller.signal.aborted
|
|
188
|
-
? Promise.resolve()
|
|
189
|
-
: this.providerModels
|
|
190
|
-
.refresh({ allowNetwork: options.allowNetwork ?? true, force: options.force, signal: controller.signal })
|
|
191
|
-
.then((result) => {
|
|
192
|
-
if (controller.signal.aborted || generation !== this.refreshGeneration)
|
|
193
|
-
return;
|
|
194
|
-
for (const [provider, error] of result.errors)
|
|
195
|
-
errors.set(provider, error);
|
|
196
|
-
this.publishProviderModels();
|
|
197
|
-
});
|
|
198
|
-
await Promise.race([Promise.all(extensionRefreshes), aborted]);
|
|
199
|
-
await Promise.race([builtinRefresh, aborted]);
|
|
200
|
-
}
|
|
201
|
-
finally {
|
|
202
|
-
clearTimeout(timeout);
|
|
203
|
-
options.signal?.removeEventListener("abort", abort);
|
|
204
|
-
}
|
|
205
|
-
return { aborted: controller.signal.aborted, errors };
|
|
206
|
-
}
|
|
207
|
-
publishProviderModels() {
|
|
208
|
-
this.rebuildProviderModels();
|
|
209
|
-
}
|
|
210
|
-
rebuildProviderModels() {
|
|
211
|
-
this.loadModels(this.providerModels.getModels());
|
|
212
|
-
for (const [providerName, config] of this.registeredProviders) {
|
|
213
|
-
this.applyProviderConfig(providerName, config);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
providerRegistrationSource(providerName) { return `${this.registrationSource}:${providerName}`; }
|
|
217
14
|
getError() {
|
|
218
|
-
return this.
|
|
15
|
+
return this.runtime.getError();
|
|
219
16
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
for (const providerId of this.configuredProviderIds) {
|
|
223
|
-
const fallback = this.defaultProviders.get(providerId);
|
|
224
|
-
if (fallback)
|
|
225
|
-
this.providerModels.setProvider(fallback);
|
|
226
|
-
else
|
|
227
|
-
this.providerModels.deleteProvider(providerId);
|
|
228
|
-
}
|
|
229
|
-
for (const provider of loaded.configuredProviders.values())
|
|
230
|
-
this.providerModels.setProvider(provider);
|
|
231
|
-
this.configuredProviderIds = new Set(loaded.configuredProviders.keys());
|
|
232
|
-
this.modelOverrides = loaded.modelOverrides;
|
|
233
|
-
const previousModels = new Map(this.models.map((model) => [`${model.provider}\0${model.id}`, model]));
|
|
234
|
-
this.models = loaded.models.map((model) => {
|
|
235
|
-
const previous = previousModels.get(`${model.provider}\0${model.id}`);
|
|
236
|
-
return previous && isDeepStrictEqual(previous, model) ? previous : model;
|
|
237
|
-
});
|
|
238
|
-
this.providerRequestConfigs = loaded.providerRequestConfigs;
|
|
239
|
-
this.modelRequestHeaders = loaded.modelRequestHeaders;
|
|
240
|
-
this.builtInProviders = loaded.builtInProviders;
|
|
241
|
-
this.customOpenAICompatibleProviders = loaded.customOpenAICompatibleProviders;
|
|
242
|
-
this.loadError = loaded.loadError;
|
|
17
|
+
getAll() {
|
|
18
|
+
return [...this.runtime.getModels()];
|
|
243
19
|
}
|
|
244
|
-
getAll() { return this.models; }
|
|
245
20
|
getAvailable() {
|
|
246
|
-
|
|
247
|
-
const allowedByProvider = new Map();
|
|
248
|
-
for (const provider of this.providerModels.getProviders()) {
|
|
249
|
-
const extension = this.registeredProviders.get(provider.id);
|
|
250
|
-
if (!provider.filterModels || extension?.models || extension?.oauth)
|
|
251
|
-
continue;
|
|
252
|
-
const providerModels = configured.filter((model) => model.provider === provider.id);
|
|
253
|
-
const runtimeApiKey = this.authStorage.getRuntimeApiKey(provider.id);
|
|
254
|
-
const credential = runtimeApiKey === undefined
|
|
255
|
-
? this.authStorage.get(provider.id)
|
|
256
|
-
: { type: "api_key", key: runtimeApiKey };
|
|
257
|
-
allowedByProvider.set(provider.id, new Set(provider.filterModels(providerModels, credential).map((model) => model.id)));
|
|
258
|
-
}
|
|
259
|
-
return configured.filter((model) => allowedByProvider.get(model.provider)?.has(model.id) ?? true);
|
|
260
|
-
}
|
|
261
|
-
find(provider, modelId) { return this.models.find((model) => model.provider === provider && model.id === modelId); }
|
|
262
|
-
getProviders() { return this.providerModels.getProviders(); }
|
|
263
|
-
getProvider(providerId) { return this.providerModels.getProvider(providerId); }
|
|
264
|
-
/** Whether an exact provider id belongs to a built-in, configured, or extension registration. */
|
|
265
|
-
hasProvider(providerId) {
|
|
266
|
-
return this.registeredProviders.has(providerId)
|
|
267
|
-
|| this.providerModels.getProvider(providerId) !== undefined
|
|
268
|
-
|| this.models.some((model) => model.provider === providerId);
|
|
269
|
-
}
|
|
270
|
-
checkAuth(providerId) { return this.providerModels.checkAuth(providerId); }
|
|
271
|
-
getAuth(providerOrModel, overrides) {
|
|
272
|
-
return typeof providerOrModel === "string" ? this.providerModels.getAuth(providerOrModel, overrides) : this.providerModels.getAuth(providerOrModel, overrides);
|
|
21
|
+
return [...this.runtime.getAvailableSnapshot()];
|
|
273
22
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
/** Whether an authenticated provider may reconstruct an absent saved model ID. */
|
|
277
|
-
canRestoreUnknownModel(provider) {
|
|
278
|
-
if (REMOTE_CATALOG_PROVIDERS.has(provider))
|
|
279
|
-
return true;
|
|
280
|
-
if (this.customOpenAICompatibleProviders.has(provider))
|
|
281
|
-
return true;
|
|
282
|
-
if (this.builtInProviders.has(provider))
|
|
283
|
-
return false;
|
|
284
|
-
const config = this.registeredProviders.get(provider);
|
|
285
|
-
return (config?.models?.some((model) => {
|
|
286
|
-
const api = model.api ?? config.api;
|
|
287
|
-
return api !== undefined && OPENAI_COMPATIBLE_APIS.has(api);
|
|
288
|
-
}) === true);
|
|
23
|
+
find(provider, modelId) {
|
|
24
|
+
return this.runtime.getModel(provider, modelId);
|
|
289
25
|
}
|
|
290
26
|
hasConfiguredAuth(model) {
|
|
291
|
-
|
|
292
|
-
return (this.authStorage.hasAuth(model.provider) ||
|
|
293
|
-
(providerApiKey !== undefined && isConfigValueConfigured(providerApiKey)));
|
|
27
|
+
return this.runtime.hasConfiguredAuth(model.provider);
|
|
294
28
|
}
|
|
295
|
-
getModelRequestKey(provider, modelId) {
|
|
296
|
-
return `${provider}:${modelId}`;
|
|
297
|
-
}
|
|
298
|
-
storeProviderRequestConfig(providerName, config) {
|
|
299
|
-
if (config.apiKey || config.headers || config.authHeader || config.auth?.apiKey)
|
|
300
|
-
this.providerRequestConfigs.set(providerName, config);
|
|
301
|
-
}
|
|
302
|
-
storeModelHeaders(providerName, modelId, headers) {
|
|
303
|
-
const key = this.getModelRequestKey(providerName, modelId);
|
|
304
|
-
if (!headers || Object.keys(headers).length === 0) {
|
|
305
|
-
this.modelRequestHeaders.delete(key);
|
|
306
|
-
return;
|
|
307
|
-
}
|
|
308
|
-
this.modelRequestHeaders.set(key, headers);
|
|
309
|
-
}
|
|
310
|
-
/**
|
|
311
|
-
* Get API key and request headers for a model.
|
|
312
|
-
*/
|
|
313
29
|
async getApiKeyAndHeaders(model) {
|
|
314
30
|
try {
|
|
315
|
-
const
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
31
|
+
const resolution = await this.runtime.getAuth(model);
|
|
32
|
+
if (!resolution) {
|
|
33
|
+
const compatibility = this.runtime.getCompatibilityRequestConfig(model);
|
|
34
|
+
if (compatibility.authHeader) {
|
|
35
|
+
return { ok: false, error: `No API key found for "${model.provider}"` };
|
|
36
|
+
}
|
|
37
|
+
const headers = compatibility.headers
|
|
38
|
+
? Object.fromEntries(Object.entries(compatibility.headers).filter((entry) => entry[1] !== null))
|
|
39
|
+
: undefined;
|
|
40
|
+
return { ok: true, headers };
|
|
41
|
+
}
|
|
42
|
+
const headers = resolution.auth.headers
|
|
43
|
+
? Object.fromEntries(Object.entries(resolution.auth.headers).filter((entry) => entry[1] !== null))
|
|
324
44
|
: undefined;
|
|
325
|
-
|
|
326
|
-
? resolvedProviderAuth
|
|
327
|
-
: overlayRuntimeApiKey(runtimeApiKey, resolvedProviderAuth, storedOAuthAuth, undefined);
|
|
328
|
-
return getModelRequestAuth(model, this.authStorage, this.providerRequestConfigs, this.modelRequestHeaders, providerAuth);
|
|
45
|
+
return { ok: true, apiKey: resolution.auth.apiKey, headers, env: resolution.env };
|
|
329
46
|
}
|
|
330
47
|
catch (error) {
|
|
331
|
-
|
|
48
|
+
const cause = error instanceof Error ? error.cause : undefined;
|
|
49
|
+
const message = cause instanceof Error ? cause.message : error instanceof Error ? error.message : String(error);
|
|
50
|
+
return {
|
|
51
|
+
ok: false,
|
|
52
|
+
error: message === "authHeader requires a resolved API key"
|
|
53
|
+
? `No API key found for "${model.provider}"`
|
|
54
|
+
: message,
|
|
55
|
+
};
|
|
332
56
|
}
|
|
333
57
|
}
|
|
334
|
-
/**
|
|
335
|
-
* Return auth status for a provider, including request auth configured in models.json.
|
|
336
|
-
* This intentionally does not execute command-backed config values.
|
|
337
|
-
*/
|
|
338
58
|
getProviderAuthStatus(provider) {
|
|
339
|
-
|
|
340
|
-
|
|
59
|
+
return this.runtime.getProviderAuthStatus(provider);
|
|
60
|
+
}
|
|
61
|
+
getProvider(provider) {
|
|
62
|
+
return this.runtime.getProvider(provider);
|
|
341
63
|
}
|
|
342
|
-
/** Registered extension providers with a custom API-key login contract. */
|
|
343
|
-
getCustomApiKeyAuthProviders() { return [...this.registeredProviders].flatMap(([id, config]) => config.auth?.apiKey ? [{ id, name: config.auth.apiKey.name || this.getProviderDisplayName(id) }] : []); }
|
|
344
|
-
getCustomApiKeyAuth(provider) { return this.registeredProviders.get(provider)?.auth?.apiKey; }
|
|
345
|
-
async getProviderAuth(provider) { return getProviderResolvedAuth(provider, this.authStorage, this.providerRequestConfigs); }
|
|
346
|
-
/**
|
|
347
|
-
* Get display name for a provider.
|
|
348
|
-
*/
|
|
349
64
|
getProviderDisplayName(provider) {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
oauthProvider?.name ??
|
|
355
|
-
BUILT_IN_PROVIDER_DISPLAY_NAMES[provider] ??
|
|
356
|
-
provider);
|
|
65
|
+
return this.runtime.getProvider(provider)?.name ?? provider;
|
|
66
|
+
}
|
|
67
|
+
getProviderAuth(provider) {
|
|
68
|
+
return this.runtime.getAuth(provider);
|
|
357
69
|
}
|
|
358
70
|
async getApiKeyForProvider(provider) {
|
|
359
|
-
|
|
71
|
+
try {
|
|
72
|
+
return (await this.runtime.getAuth(provider))?.auth.apiKey;
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
360
77
|
}
|
|
361
78
|
isUsingOAuth(model) {
|
|
362
|
-
|
|
363
|
-
return cred?.type === "oauth";
|
|
79
|
+
return this.runtime.isUsingOAuth(model.provider);
|
|
364
80
|
}
|
|
365
81
|
registerProvider(providerOrName, config) {
|
|
366
|
-
if (typeof providerOrName
|
|
367
|
-
if (!
|
|
368
|
-
throw new Error("Provider
|
|
369
|
-
this.
|
|
370
|
-
this.nativeProviders.set(providerOrName.id, providerOrName);
|
|
371
|
-
this.providerModels.setProvider(providerOrName);
|
|
372
|
-
this.rebuildProviderModels();
|
|
82
|
+
if (typeof providerOrName === "string") {
|
|
83
|
+
if (!config)
|
|
84
|
+
throw new Error("Provider config is required when registering by name");
|
|
85
|
+
this.runtime.registerProvider(providerOrName, config);
|
|
373
86
|
return;
|
|
374
87
|
}
|
|
375
|
-
|
|
376
|
-
throw new Error("Provider config is required");
|
|
377
|
-
this.nativeProviders.delete(providerOrName);
|
|
378
|
-
const migratedConfig = migrateLegacyRegisterProviderConfigValues(providerOrName, config);
|
|
379
|
-
validateProviderConfig(providerOrName, migratedConfig);
|
|
380
|
-
const mergedConfig = this.upsertRegisteredProvider(providerOrName, migratedConfig);
|
|
381
|
-
unregisterProviderRuntime(this.providerRegistrationSource(providerOrName));
|
|
382
|
-
this.rebuildProviderModels();
|
|
383
|
-
this.applyProviderConfig(providerOrName, mergedConfig, true);
|
|
384
|
-
}
|
|
385
|
-
hasRegisteredStreamSimpleForApi(api) {
|
|
386
|
-
for (const config of this.registeredProviders.values()) {
|
|
387
|
-
if (config.api === api && config.streamSimple) {
|
|
388
|
-
return true;
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
return false;
|
|
88
|
+
this.runtime.registerNativeProvider(providerOrName);
|
|
392
89
|
}
|
|
393
90
|
unregisterProvider(providerName) {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
unregisterProviderRuntime(this.providerRegistrationSource(providerName));
|
|
399
|
-
const fallback = this.defaultProviders.get(providerName);
|
|
400
|
-
if (fallback)
|
|
401
|
-
this.providerModels.setProvider(fallback);
|
|
402
|
-
else
|
|
403
|
-
this.providerModels.deleteProvider(providerName);
|
|
404
|
-
this.rebuildProviderModels();
|
|
91
|
+
this.runtime.unregisterProvider(providerName);
|
|
92
|
+
}
|
|
93
|
+
getRegisteredProviderConfig(providerName) {
|
|
94
|
+
return this.runtime.getRegisteredProviderConfig(providerName);
|
|
405
95
|
}
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
const merged = { ...this.registeredProviders.get(providerName), ...definedConfig };
|
|
409
|
-
this.registeredProviders.set(providerName, merged);
|
|
410
|
-
return merged;
|
|
96
|
+
getRegisteredNativeProvider(providerName) {
|
|
97
|
+
return this.runtime.getRegisteredNativeProvider(providerName);
|
|
411
98
|
}
|
|
412
|
-
|
|
413
|
-
this.
|
|
414
|
-
registrationSource: this.providerRegistrationSource(providerName),
|
|
415
|
-
registerRuntime,
|
|
416
|
-
providerName,
|
|
417
|
-
config,
|
|
418
|
-
models: this.models,
|
|
419
|
-
modelOverrides: this.modelOverrides,
|
|
420
|
-
authStorage: this.authStorage,
|
|
421
|
-
storeProviderRequestConfig: (name, requestConfig) => this.storeProviderRequestConfig(name, requestConfig),
|
|
422
|
-
storeModelHeaders: (name, modelId, headers) => this.storeModelHeaders(name, modelId, headers),
|
|
423
|
-
});
|
|
99
|
+
getRegisteredProviderIds() {
|
|
100
|
+
return this.runtime.getRegisteredProviderIds();
|
|
424
101
|
}
|
|
425
102
|
}
|
|
426
103
|
//# sourceMappingURL=model-registry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-registry.js","sourceRoot":"","sources":["../../src/core/model-registry.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACN,YAAY,GAUZ,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,gBAAgB,EAAE,8BAA8B,EAAE,MAAM,qCAAqC,CAAC;AAEvG,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,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,MAAM;YACN,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,cAAc,EAAE,IAAI,CAAC,cAAc;YACnC,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,0BAA0B,EAAE,CAAC,IAAI,EAAE,aAAa,EAAE,EAAE,CAAC,IAAI,CAAC,0BAA0B,CAAC,IAAI,EAAE,aAAa,CAAC;YACzG,iBAAiB,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,iBAAiB,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC;SAC7F,CAAC,CAAC;IACJ,CAAC;CACD","sourcesContent":["/**\n * Model registry - manages built-in and custom models, provides API key resolution.\n */\n\nimport {\n\tcreateModels,\n\ttype AuthInteraction,\n\ttype AuthResult,\n\ttype AuthType,\n\ttype Credential,\n\ttype CredentialStore,\n\ttype ModelAuth,\n\ttype ModelsRefreshResult,\n\ttype MutableModels,\n\ttype Provider,\n} from \"@earendil-works/pi-ai\";\nimport { builtinProviders, getBuiltinModelDataGeneratedAt } from \"@earendil-works/pi-ai/providers/all\";\nimport { type Api, type Model } from \"@earendil-works/pi-ai/compat\";\nimport { dirname, join } from \"node:path\";\nimport { isDeepStrictEqual } from \"node:util\";\nimport { getAgentConfigPaths } from \"../config.ts\";\nimport { normalizePath } from \"../utils/paths.ts\";\nimport type { AuthStatus, AuthStorage } from \"./auth-storage.ts\";\nimport { getModelRequestAuth, getApiKeyForProviderFromConfig, getProviderAuthStatusFromConfig, getProviderResolvedAuth } from \"./model-registry-auth.ts\";\nimport { applyProviderConfigToModels, migrateLegacyRegisterProviderConfigValues, unregisterProviderRuntime, validateProviderConfig } from \"./model-registry-dynamic.ts\";\nimport { loadModelRegistryModels } from \"./model-registry-loader.ts\";\nimport { refreshExtensionProvider } from \"./model-registry-extension-refresh.ts\";\nimport type { ProviderConfigInput, ProviderRequestConfig, ResolvedRequestAuth } from \"./model-registry-types.ts\";\nimport type { ModelOverride } from \"./model-registry-schemas.ts\";\nimport { BUILT_IN_PROVIDER_DISPLAY_NAMES } from \"./provider-display-names.ts\";\nimport { type CodingAgentModelsStore, FileModelsStore, InMemoryCodingAgentModelsStore } from \"./models-store.ts\";\nimport { getLegacyOAuthProvider, oauthCredentialToAuth } from \"./oauth-provider-bridge.ts\";\nimport { withRemoteCatalog } from \"./remote-catalog-provider.ts\";\nimport { clearConfigValueCache, isConfigValueConfigured } from \"./resolve-config-value.ts\";\nconst REMOTE_CATALOG_PROVIDERS = new Set([\"github-copilot\", \"openrouter\", \"vercel-ai-gateway\"]);\nconst OPENAI_COMPATIBLE_APIS = new Set<Api>([\"openai-completions\", \"openai-responses\"]);\nlet nextRegistryRegistrationId = 0;\n\nfunction overlayRuntimeApiKey(\n\truntimeApiKey: string,\n\tresolvedAuth: ModelAuth | undefined,\n\tstoredOAuthAuth: ModelAuth | undefined,\n\truntimeBaseUrl: string | undefined,\n): ModelAuth {\n\tconst headers = storedOAuthAuth?.headers || resolvedAuth?.headers\n\t\t? { ...storedOAuthAuth?.headers, ...resolvedAuth?.headers }\n\t\t: undefined;\n\treturn {\n\t\t...storedOAuthAuth,\n\t\t...resolvedAuth,\n\t\tapiKey: runtimeApiKey,\n\t\theaders,\n\t\tbaseUrl: runtimeBaseUrl ?? storedOAuthAuth?.baseUrl ?? resolvedAuth?.baseUrl,\n\t};\n}\n\nfunction createProviderCredentialStore(credentials: CredentialStore): CredentialStore {\n\treturn {\n\t\t...credentials,\n\t\tread: async (providerId) => {\n\t\t\tconst credential = await credentials.read(providerId);\n\t\t\tif (credential?.type !== \"oauth\" || !getLegacyOAuthProvider(providerId)) return credential;\n\t\t\tconst auth = await oauthCredentialToAuth(providerId, credential);\n\t\t\treturn auth?.apiKey === undefined ? undefined : { type: \"api_key\", key: auth.apiKey };\n\t\t},\n\t};\n}\n\nexport type { ProviderConfigInput, ResolvedRequestAuth } from \"./model-registry-types.ts\";\n/** Clear the config value command cache. Exported for testing. */\nexport const clearApiKeyCache = clearConfigValueCache;\n/**\n * Model registry - loads and manages models, resolves API keys via AuthStorage.\n */\nexport class ModelRegistry {\n\tprivate models: Model<Api>[] = [];\n\tprivate modelOverrides: Map<string, Map<string, ModelOverride>> = new Map();\n\tprivate providerRequestConfigs: Map<string, ProviderRequestConfig> = new Map();\n\tprivate modelRequestHeaders: Map<string, Record<string, string>> = new Map();\n\tprivate registeredProviders: Map<string, ProviderConfigInput> = new Map();\n\tprivate nativeProviders: Map<string, Provider> = new Map();\n\tprivate builtInProviders: Set<string> = new Set();\n\tprivate customOpenAICompatibleProviders: Set<string> = new Set();\n\tprivate loadError: string | undefined = undefined;\n\tprivate refreshGeneration = 0;\n\tprivate resolvedCustomAuthProviders = new Set<string>();\n\tprivate readonly registrationSource = `atomic:model-registry:${++nextRegistryRegistrationId}`;\n\tdeclare private readonly modelsStore: CodingAgentModelsStore;\n\tdeclare private readonly credentialStore: CredentialStore;\n\tdeclare private readonly providerModels: MutableModels;\n\tprivate readonly defaultProviders = new Map<string, Provider>();\n\tprivate configuredProviderIds = new Set<string>();\n\n\tdeclare readonly authStorage: AuthStorage;\n\tdeclare private readonly modelsJsonPaths: string[];\n\tdeclare private readonly modelDataDir: string | undefined;\n\n\tprivate constructor(\n\t\tauthStorage: AuthStorage,\n\t\tmodelsJsonPaths: string[],\n\t\tmodelDataDir?: string,\n\t) {\n\t\tthis.authStorage = authStorage;\n\t\tthis.modelsJsonPaths = modelsJsonPaths.map((path) => normalizePath(path));\n\t\tthis.modelDataDir = modelDataDir ? normalizePath(modelDataDir) : this.modelsJsonPaths[0] ? dirname(this.modelsJsonPaths[0]) : undefined;\n\t\tthis.modelsStore = this.modelDataDir ? new FileModelsStore(join(this.modelDataDir, \"models-store.json\")) : new InMemoryCodingAgentModelsStore();\n\t\tthis.credentialStore = authStorage.asCredentialStore();\n\t\tthis.providerModels = createModels({\n\t\t\tcredentials: createProviderCredentialStore(this.credentialStore),\n\t\t\tmodelsStore: this.modelsStore,\n\t\t});\n\t\tconst builtinModelDataGeneratedAt = getBuiltinModelDataGeneratedAt();\n\t\tfor (const provider of builtinProviders()) {\n\t\t\tconst configured = provider.id === \"radius\"\n\t\t\t\t? provider\n\t\t\t\t: withRemoteCatalog(provider, undefined, builtinModelDataGeneratedAt);\n\t\t\tthis.defaultProviders.set(provider.id, configured);\n\t\t\tthis.providerModels.setProvider(configured);\n\t\t}\n\t\tthis.loadModels();\n\t}\n\n\tstatic create(\n\t\tauthStorage: AuthStorage,\n\t\tmodelsJsonPath: string | string[] = getAgentConfigPaths(\"models.json\"),\n\t\tmodelDataDir?: string,\n\t): ModelRegistry {\n\t\treturn new ModelRegistry(authStorage, Array.isArray(modelsJsonPath) ? modelsJsonPath : [modelsJsonPath], modelDataDir);\n\t}\n\n\tstatic inMemory(authStorage: AuthStorage): ModelRegistry { return new ModelRegistry(authStorage, []); }\n\n\tasync refresh(options: { signal?: AbortSignal; timeoutMs?: number; force?: boolean; allowNetwork?: boolean } = {}): Promise<ModelsRefreshResult> {\n\t\tconst generation = ++this.refreshGeneration;\n\t\tthis.loadError = undefined;\n\t\tthis.rebuildProviderModels();\n\n\t\tconst controller = new AbortController();\n\t\tconst abort = () => controller.abort();\n\t\toptions.signal?.addEventListener(\"abort\", abort, { once: true });\n\t\tif (options.signal?.aborted) controller.abort(options.signal.reason);\n\t\tconst timeout = setTimeout(abort, options.timeoutMs ?? 15_000);\n\t\tconst errors = new Map<string, Error>();\n\t\tconst aborted = new Promise<void>((resolve) => {\n\t\t\tif (controller.signal.aborted) resolve();\n\t\t\telse controller.signal.addEventListener(\"abort\", () => resolve(), { once: true });\n\t\t});\n\t\ttry {\n\t\t\tconst restore = this.providerModels\n\t\t\t\t.refresh({ allowNetwork: false, signal: controller.signal })\n\t\t\t\t.then((result) => {\n\t\t\t\t\tif (controller.signal.aborted || generation !== this.refreshGeneration) return;\n\t\t\t\t\tfor (const [provider, error] of result.errors) errors.set(provider, error);\n\t\t\t\t\tthis.publishProviderModels();\n\t\t\t\t});\n\t\t\tawait Promise.race([restore, aborted]);\n\n\t\t\tif (options.allowNetwork !== false && !controller.signal.aborted) {\n\t\t\t\tconst legacyOAuthProviders = new Set([\n\t\t\t\t\t...this.models.map((model) => model.provider),\n\t\t\t\t\t...[...this.registeredProviders]\n\t\t\t\t\t\t.filter(([, config]) => config.oauth !== undefined)\n\t\t\t\t\t\t.map(([providerId]) => providerId),\n\t\t\t\t].filter((providerId) => getLegacyOAuthProvider(providerId) !== undefined));\n\t\t\t\tconst refreshLegacyOAuth = Promise.all([...legacyOAuthProviders].map(async (providerId) => {\n\t\t\t\t\tconst credential = this.authStorage.get(providerId);\n\t\t\t\t\tif (credential?.type !== \"oauth\" || Date.now() < credential.expires) return;\n\t\t\t\t\tawait this.authStorage.getModelAuth(providerId, { includeFallback: false });\n\t\t\t\t}));\n\t\t\t\tawait Promise.race([refreshLegacyOAuth, aborted]);\n\t\t\t}\n\n\t\t\tconst extensionRefreshes = controller.signal.aborted ? [] : [...this.registeredProviders].map(async ([providerName, config]) => {\n\t\t\t\tif (!config.refreshModels) return;\n\t\t\t\tconst isCurrentExtensionRefresh = () => !controller.signal.aborted\n\t\t\t\t\t&& generation === this.refreshGeneration\n\t\t\t\t\t&& this.registeredProviders.get(providerName) === config;\n\t\t\t\tconst store = {\n\t\t\t\t\tread: () => this.modelsStore.read(providerName),\n\t\t\t\t\twrite: (entry: Parameters<typeof this.modelsStore.write>[1]) =>\n\t\t\t\t\t\tthis.modelsStore.writeIf(providerName, entry, isCurrentExtensionRefresh),\n\t\t\t\t\tdelete: () => this.modelsStore.deleteIf(providerName, isCurrentExtensionRefresh),\n\t\t\t\t};\n\t\t\t\ttry {\n\t\t\t\t\tlet credential = await this.credentialStore.read(providerName);\n\t\t\t\t\tif (credential?.type === \"api_key\") {\n\t\t\t\t\t\tconst effectiveApiKey = await this.authStorage.getApiKey(providerName, { includeFallback: false });\n\t\t\t\t\t\tcredential = { ...credential, key: effectiveApiKey };\n\t\t\t\t\t}\n\t\t\t\t\tif (credential === undefined) {\n\t\t\t\t\t\tconst customAuth = await getProviderResolvedAuth(providerName, this.authStorage, this.providerRequestConfigs);\n\t\t\t\t\t\tif (customAuth) { this.resolvedCustomAuthProviders.add(providerName); credential = { type: \"api_key\", key: customAuth.auth.apiKey, env: customAuth.env }; }\n\t\t\t\t\t\telse this.resolvedCustomAuthProviders.delete(providerName);\n\t\t\t\t\t\tconst configuredApiKey = customAuth ? undefined : await getApiKeyForProviderFromConfig(providerName, this.authStorage, this.providerRequestConfigs);\n\t\t\t\t\t\tif (configuredApiKey !== undefined) credential = { type: \"api_key\", key: configuredApiKey };\n\t\t\t\t\t}\n\t\t\t\t\tif (!isCurrentExtensionRefresh()) return;\n\t\t\t\t\tconst refreshed = await refreshExtensionProvider({\n\t\t\t\t\t\tconfig,\n\t\t\t\t\t\tcredential,\n\t\t\t\t\t\tstore,\n\t\t\t\t\t\tallowNetwork: options.allowNetwork ?? true,\n\t\t\t\t\t\tforce: options.force,\n\t\t\t\t\t\tsignal: controller.signal,\n\t\t\t\t\t\tisCurrent: isCurrentExtensionRefresh,\n\t\t\t\t\t});\n\t\t\t\t\tif (!isCurrentExtensionRefresh()) return;\n\t\t\t\t\tif (refreshed.error) errors.set(providerName, refreshed.error);\n\t\t\t\t\tif (!refreshed.models) return;\n\t\t\t\t\tthis.registeredProviders.set(providerName, { ...config, models: refreshed.models });\n\t\t\t\t\tthis.rebuildProviderModels();\n\t\t\t\t} catch (error) { if (isCurrentExtensionRefresh()) errors.set(providerName, error instanceof Error ? error : new Error(String(error))); }\n\t\t\t});\n\t\t\tconst builtinRefresh = controller.signal.aborted\n\t\t\t\t? Promise.resolve()\n\t\t\t\t: this.providerModels\n\t\t\t\t\t.refresh({ allowNetwork: options.allowNetwork ?? true, force: options.force, signal: controller.signal })\n\t\t\t\t\t.then((result) => {\n\t\t\t\t\t\tif (controller.signal.aborted || generation !== this.refreshGeneration) return;\n\t\t\t\t\t\tfor (const [provider, error] of result.errors) errors.set(provider, error);\n\t\t\t\t\t\tthis.publishProviderModels();\n\t\t\t\t\t});\n\t\t\tawait Promise.race([Promise.all(extensionRefreshes), aborted]);\n\t\t\tawait Promise.race([builtinRefresh, aborted]);\n\t\t} finally {\n\t\t\tclearTimeout(timeout);\n\t\t\toptions.signal?.removeEventListener(\"abort\", abort);\n\t\t}\n\t\treturn { aborted: controller.signal.aborted, errors };\n\t}\n\n\tprivate publishProviderModels(): void {\n\t\tthis.rebuildProviderModels();\n\t}\n\n\tprivate rebuildProviderModels(): void {\n\t\tthis.loadModels(this.providerModels.getModels());\n\t\tfor (const [providerName, config] of this.registeredProviders) {\n\t\t\tthis.applyProviderConfig(providerName, config);\n\t\t}\n\t}\n\n\tprivate providerRegistrationSource(providerName: string): string { return `${this.registrationSource}:${providerName}`; }\n\n\tgetError(): string | undefined {\n\t\treturn this.loadError;\n\t}\n\n\tprivate loadModels(baseModels?: readonly Model<Api>[]): void {\n\t\tconst loaded = loadModelRegistryModels(this.authStorage, this.modelsJsonPaths, baseModels);\n\t\tfor (const providerId of this.configuredProviderIds) {\n\t\t\tconst fallback = this.defaultProviders.get(providerId);\n\t\t\tif (fallback) this.providerModels.setProvider(fallback);\n\t\t\telse this.providerModels.deleteProvider(providerId);\n\t\t}\n\t\tfor (const provider of loaded.configuredProviders.values()) this.providerModels.setProvider(provider);\n\t\tthis.configuredProviderIds = new Set(loaded.configuredProviders.keys());\n\t\tthis.modelOverrides = loaded.modelOverrides;\n\t\tconst previousModels = new Map(this.models.map((model) => [`${model.provider}\\0${model.id}`, model]));\n\t\tthis.models = loaded.models.map((model) => {\n\t\t\tconst previous = previousModels.get(`${model.provider}\\0${model.id}`);\n\t\t\treturn previous && isDeepStrictEqual(previous, model) ? previous : model;\n\t\t});\n\t\tthis.providerRequestConfigs = loaded.providerRequestConfigs;\n\t\tthis.modelRequestHeaders = loaded.modelRequestHeaders;\n\t\tthis.builtInProviders = loaded.builtInProviders;\n\t\tthis.customOpenAICompatibleProviders = loaded.customOpenAICompatibleProviders;\n\t\tthis.loadError = loaded.loadError;\n\t}\n\n\tgetAll(): Model<Api>[] { return this.models; }\n\n\tgetAvailable(): Model<Api>[] {\n\t\tconst configured = this.models.filter((model) => this.hasConfiguredAuth(model));\n\t\tconst allowedByProvider = new Map<string, ReadonlySet<string>>();\n\t\tfor (const provider of this.providerModels.getProviders()) {\n\t\t\tconst extension = this.registeredProviders.get(provider.id);\n\t\t\tif (!provider.filterModels || extension?.models || extension?.oauth) continue;\n\t\t\tconst providerModels = configured.filter((model) => model.provider === provider.id);\n\t\t\tconst runtimeApiKey = this.authStorage.getRuntimeApiKey(provider.id);\n\t\t\tconst credential: Credential | undefined = runtimeApiKey === undefined\n\t\t\t\t? this.authStorage.get(provider.id) as Credential | undefined\n\t\t\t\t: { type: \"api_key\", key: runtimeApiKey };\n\t\t\tallowedByProvider.set(\n\t\t\t\tprovider.id,\n\t\t\t\tnew Set(provider.filterModels(providerModels, credential).map((model) => model.id)),\n\t\t\t);\n\t\t}\n\t\treturn configured.filter((model) => allowedByProvider.get(model.provider)?.has(model.id) ?? true);\n\t}\n\n\tfind(provider: string, modelId: string): Model<Api> | undefined { return this.models.find((model) => model.provider === provider && model.id === modelId); }\n\tgetProviders(): readonly Provider[] { return this.providerModels.getProviders(); }\n\tgetProvider(providerId: string): Provider | undefined { return this.providerModels.getProvider(providerId); }\n\t/** Whether an exact provider id belongs to a built-in, configured, or extension registration. */\n\thasProvider(providerId: string): boolean {\n\t\treturn this.registeredProviders.has(providerId)\n\t\t\t|| this.providerModels.getProvider(providerId) !== undefined\n\t\t\t|| this.models.some((model) => model.provider === providerId);\n\t}\n\tcheckAuth(providerId: string) { return this.providerModels.checkAuth(providerId); }\n\tgetAuth(providerId: string, overrides?: { apiKey?: string; env?: Record<string, string> }): Promise<AuthResult | undefined>;\n\tgetAuth(model: Model<Api>, overrides?: { apiKey?: string; env?: Record<string, string> }): Promise<AuthResult | undefined>;\n\tgetAuth(providerOrModel: string | Model<Api>, overrides?: { apiKey?: string; env?: Record<string, string> }): Promise<AuthResult | undefined> {\n\t\treturn typeof providerOrModel === \"string\" ? this.providerModels.getAuth(providerOrModel, overrides) : this.providerModels.getAuth(providerOrModel, overrides);\n\t}\n\tlogin(providerId: string, type: AuthType, interaction: AuthInteraction): Promise<Credential> { return this.providerModels.login(providerId, type, interaction); }\n\tasync logoutProvider(providerId: string): Promise<void> { await this.providerModels.logout(providerId); this.authStorage.reload(); }\n\n\t/** Whether an authenticated provider may reconstruct an absent saved model ID. */\n\tcanRestoreUnknownModel(provider: string): boolean {\n\t\tif (REMOTE_CATALOG_PROVIDERS.has(provider)) return true;\n\t\tif (this.customOpenAICompatibleProviders.has(provider)) return true;\n\t\tif (this.builtInProviders.has(provider)) return false;\n\n\t\tconst config = this.registeredProviders.get(provider);\n\t\treturn (\n\t\t\tconfig?.models?.some((model) => {\n\t\t\t\tconst api = model.api ?? config.api;\n\t\t\t\treturn api !== undefined && OPENAI_COMPATIBLE_APIS.has(api);\n\t\t\t}) === true\n\t\t);\n\t}\n\n\thasConfiguredAuth(model: Model<Api>): boolean {\n\t\tconst providerApiKey = this.providerRequestConfigs.get(model.provider)?.apiKey;\n\t\treturn (\n\t\t\tthis.authStorage.hasAuth(model.provider) ||\n\t\t\t(providerApiKey !== undefined && isConfigValueConfigured(providerApiKey))\n\t\t);\n\t}\n\n\tprivate getModelRequestKey(provider: string, modelId: string): string {\n\t\treturn `${provider}:${modelId}`;\n\t}\n\n\tprivate storeProviderRequestConfig(providerName: string, config: ProviderRequestConfig): void {\n\t\tif (config.apiKey || config.headers || config.authHeader || config.auth?.apiKey) this.providerRequestConfigs.set(providerName, config);\n\t}\n\n\tprivate storeModelHeaders(providerName: string, modelId: string, headers?: Record<string, string>): void {\n\t\tconst key = this.getModelRequestKey(providerName, modelId);\n\t\tif (!headers || Object.keys(headers).length === 0) {\n\t\t\tthis.modelRequestHeaders.delete(key);\n\t\t\treturn;\n\t\t}\n\t\tthis.modelRequestHeaders.set(key, headers);\n\t}\n\n\t/**\n\t * Get API key and request headers for a model.\n\t */\n\tasync getApiKeyAndHeaders(model: Model<Api>): Promise<ResolvedRequestAuth> {\n\t\ttry {\n\t\t\tconst runtimeApiKey = this.authStorage.getRuntimeApiKey(model.provider);\n\t\t\tconst extensionReplacesOAuth = this.registeredProviders.get(model.provider)?.oauth !== undefined\n\t\t\t\t|| getLegacyOAuthProvider(model.provider) !== undefined;\n\t\t\tconst resolvedProviderAuth = this.providerModels.getProvider(model.provider) && !extensionReplacesOAuth\n\t\t\t\t? (await this.providerModels.getAuth(\n\t\t\t\t\tmodel,\n\t\t\t\t\truntimeApiKey === undefined ? undefined : { apiKey: runtimeApiKey },\n\t\t\t\t))?.auth\n\t\t\t\t: undefined;\n\t\t\tconst storedCredential = this.authStorage.get(model.provider);\n\t\t\tconst storedOAuthAuth = runtimeApiKey !== undefined && !extensionReplacesOAuth && storedCredential?.type === \"oauth\"\n\t\t\t\t? await oauthCredentialToAuth(model.provider, storedCredential)\n\t\t\t\t: undefined;\n\t\t\tconst providerAuth = runtimeApiKey === undefined\n\t\t\t\t? resolvedProviderAuth\n\t\t\t\t: overlayRuntimeApiKey(runtimeApiKey, resolvedProviderAuth, storedOAuthAuth, undefined);\n\t\t\treturn getModelRequestAuth(\n\t\t\t\tmodel,\n\t\t\t\tthis.authStorage,\n\t\t\t\tthis.providerRequestConfigs,\n\t\t\t\tthis.modelRequestHeaders,\n\t\t\t\tproviderAuth,\n\t\t\t);\n\t\t} catch (error) {\n\t\t\treturn { ok: false, error: error instanceof Error ? error.message : String(error) };\n\t\t}\n\t}\n\n\t/**\n\t * Return auth status for a provider, including request auth configured in models.json.\n\t * This intentionally does not execute command-backed config values.\n\t */\n\tgetProviderAuthStatus(provider: string): AuthStatus {\n\t\tconst status = getProviderAuthStatusFromConfig(provider, this.authStorage, this.providerRequestConfigs);\n\t\treturn status.source || !this.resolvedCustomAuthProviders.has(provider) ? status : { configured: true, source: \"environment\" };\n\t}\n\t/** Registered extension providers with a custom API-key login contract. */\n\tgetCustomApiKeyAuthProviders(): Array<{ id: string; name: string }> { return [...this.registeredProviders].flatMap(([id, config]) => config.auth?.apiKey ? [{ id, name: config.auth.apiKey.name || this.getProviderDisplayName(id) }] : []); }\n\tgetCustomApiKeyAuth(provider: string) { return this.registeredProviders.get(provider)?.auth?.apiKey; }\n\tasync getProviderAuth(provider: string) { return getProviderResolvedAuth(provider, this.authStorage, this.providerRequestConfigs); }\n\t/**\n\t * Get display name for a provider.\n\t */\n\tgetProviderDisplayName(provider: string): string {\n\t\tconst registeredProvider = this.registeredProviders.get(provider);\n\t\tconst oauthProvider = this.authStorage.getOAuthProviders().find((p) => p.id === provider);\n\n\t\treturn (\n\t\t\tregisteredProvider?.name ??\n\t\t\tregisteredProvider?.oauth?.name ??\n\t\t\toauthProvider?.name ??\n\t\t\tBUILT_IN_PROVIDER_DISPLAY_NAMES[provider] ??\n\t\t\tprovider\n\t\t);\n\t}\n\n\tasync getApiKeyForProvider(provider: string): Promise<string | undefined> {\n\t\treturn getApiKeyForProviderFromConfig(provider, this.authStorage, this.providerRequestConfigs);\n\t}\n\n\tisUsingOAuth(model: Model<Api>): boolean {\n\t\tconst cred = this.authStorage.get(model.provider);\n\t\treturn cred?.type === \"oauth\";\n\t}\n\n\tregisterProvider(provider: Provider): void;\n\tregisterProvider(providerName: string, config: ProviderConfigInput): void;\n\tregisterProvider(providerOrName: Provider | string, config?: ProviderConfigInput): void {\n\t\tif (typeof providerOrName !== \"string\") {\n\t\t\tif (!providerOrName.id.trim()) throw new Error(\"Provider id must not be empty.\");\n\t\t\tthis.registeredProviders.delete(providerOrName.id);\n\t\t\tthis.nativeProviders.set(providerOrName.id, providerOrName);\n\t\t\tthis.providerModels.setProvider(providerOrName);\n\t\t\tthis.rebuildProviderModels();\n\t\t\treturn;\n\t\t}\n\t\tif (!config) throw new Error(\"Provider config is required\");\n\t\tthis.nativeProviders.delete(providerOrName);\n\t\tconst migratedConfig = migrateLegacyRegisterProviderConfigValues(providerOrName, config);\n\t\tvalidateProviderConfig(providerOrName, migratedConfig);\n\t\tconst mergedConfig = this.upsertRegisteredProvider(providerOrName, migratedConfig);\n\t\tunregisterProviderRuntime(this.providerRegistrationSource(providerOrName));\n\t\tthis.rebuildProviderModels();\n\t\tthis.applyProviderConfig(providerOrName, mergedConfig, true);\n\t}\n\n\thasRegisteredStreamSimpleForApi(api: Api): boolean {\n\t\tfor (const config of this.registeredProviders.values()) {\n\t\t\tif (config.api === api && config.streamSimple) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\tunregisterProvider(providerName: string): void {\n\t\tconst hadLegacy = this.registeredProviders.delete(providerName);\n\t\tconst hadNative = this.nativeProviders.delete(providerName);\n\t\tif (!hadLegacy && !hadNative) return;\n\t\tunregisterProviderRuntime(this.providerRegistrationSource(providerName));\n\t\tconst fallback = this.defaultProviders.get(providerName);\n\t\tif (fallback) this.providerModels.setProvider(fallback);\n\t\telse this.providerModels.deleteProvider(providerName);\n\t\tthis.rebuildProviderModels();\n\t}\n\n\tprivate upsertRegisteredProvider(providerName: string, config: ProviderConfigInput): ProviderConfigInput {\n\t\tconst definedConfig = Object.fromEntries(\n\t\t\tObject.entries(config).filter(([, value]) => value !== undefined),\n\t\t) as ProviderConfigInput;\n\t\tconst merged = { ...this.registeredProviders.get(providerName), ...definedConfig };\n\t\tthis.registeredProviders.set(providerName, merged);\n\t\treturn merged;\n\t}\n\n\tprivate applyProviderConfig(providerName: string, config: ProviderConfigInput, registerRuntime = false): void {\n\t\tthis.models = applyProviderConfigToModels({\n\t\t\tregistrationSource: this.providerRegistrationSource(providerName),\n\t\t\tregisterRuntime,\n\t\t\tproviderName,\n\t\t\tconfig,\n\t\t\tmodels: this.models,\n\t\t\tmodelOverrides: this.modelOverrides,\n\t\t\tauthStorage: this.authStorage,\n\t\t\tstoreProviderRequestConfig: (name, requestConfig) => this.storeProviderRequestConfig(name, requestConfig),\n\t\t\tstoreModelHeaders: (name, modelId, headers) => this.storeModelHeaders(name, modelId, headers),\n\t\t});\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"model-registry.js","sourceRoot":"","sources":["../../src/core/model-registry.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D;;;GAGG;AACH,MAAM,OAAO,aAAa;IAGzB,YAAY,OAAqB;QAChC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;IAED,yFAAyF;IACzF,KAAK,CAAC,OAAO;QACZ,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;IAC9B,CAAC;IAED,QAAQ;QACP,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;IAChC,CAAC;IAED,MAAM;QACL,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;IACtC,CAAC;IAED,YAAY;QACX,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,oBAAoB,EAAE,CAAC,CAAC;IACjD,CAAC;IAED,IAAI,CAAC,QAAgB,EAAE,OAAe;QACrC,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACjD,CAAC;IAED,iBAAiB,CAAC,KAAiB;QAClC,OAAO,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACvD,CAAC;IAED,KAAK,CAAC,mBAAmB,CAAC,KAAiB;QAC1C,IAAI,CAAC;YACJ,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YACrD,IAAI,CAAC,UAAU,EAAE,CAAC;gBACjB,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,6BAA6B,CAAC,KAAK,CAAC,CAAC;gBACxE,IAAI,aAAa,CAAC,UAAU,EAAE,CAAC;oBAC9B,OAAO,EAAE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CAAC;QACD,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,cAAc,CAAC,CAAC;IACrD,CAAC;IAED,kBAAkB,CAAC,YAAoB;QACtC,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAC;IAC/C,CAAC;IAED,2BAA2B,CAAC,YAAoB;QAC/C,OAAO,IAAI,CAAC,OAAO,CAAC,2BAA2B,CAAC,YAAY,CAAC,CAAC;IAC/D,CAAC;IAED,2BAA2B,CAAC,YAAoB;QAC/C,OAAO,IAAI,CAAC,OAAO,CAAC,2BAA2B,CAAC,YAAY,CAAC,CAAC;IAC/D,CAAC;IAED,wBAAwB;QACvB,OAAO,IAAI,CAAC,OAAO,CAAC,wBAAwB,EAAE,CAAC;IAChD,CAAC;CACD","sourcesContent":["import type { Api, AuthResult, Model, Provider } from \"@earendil-works/pi-ai\";\nimport type { ModelRuntime } from \"./model-runtime.ts\";\nimport type { AuthStatus, ProviderConfigInput } from \"./provider-composer.ts\";\n\nexport type { ProviderConfigInput } from \"./provider-composer.ts\";\nexport type ResolvedRequestAuth =\n\t| {\n\t\t\tok: true;\n\t\t\tapiKey?: string;\n\t\t\theaders?: Record<string, string>;\n\t\t\tenv?: Record<string, string>;\n\t }\n\t| { ok: false; error: string };\nexport { clearApiKeyCache } from \"./provider-composer.ts\";\n\n/**\n * Synchronous compatibility facade exposed to extensions.\n * Coding-agent internals use ModelRuntime directly.\n */\nexport class ModelRegistry {\n\tprivate readonly runtime: ModelRuntime;\n\n\tconstructor(runtime: ModelRuntime) {\n\t\tthis.runtime = runtime;\n\t}\n\n\t/** Reload models.json asynchronously. Await before making synchronous registry reads. */\n\tasync refresh(): Promise<void> {\n\t\tawait this.runtime.refresh();\n\t}\n\n\tgetError(): string | undefined {\n\t\treturn this.runtime.getError();\n\t}\n\n\tgetAll(): Model<Api>[] {\n\t\treturn [...this.runtime.getModels()];\n\t}\n\n\tgetAvailable(): Model<Api>[] {\n\t\treturn [...this.runtime.getAvailableSnapshot()];\n\t}\n\n\tfind(provider: string, modelId: string): Model<Api> | undefined {\n\t\treturn this.runtime.getModel(provider, modelId);\n\t}\n\n\thasConfiguredAuth(model: Model<Api>): boolean {\n\t\treturn this.runtime.hasConfiguredAuth(model.provider);\n\t}\n\n\tasync getApiKeyAndHeaders(model: Model<Api>): Promise<ResolvedRequestAuth> {\n\t\ttry {\n\t\t\tconst resolution = await this.runtime.getAuth(model);\n\t\t\tif (!resolution) {\n\t\t\t\tconst compatibility = this.runtime.getCompatibilityRequestConfig(model);\n\t\t\t\tif (compatibility.authHeader) {\n\t\t\t\t\treturn { ok: false, error: `No API key found for \"${model.provider}\"` };\n\t\t\t\t}\n\t\t\t\tconst headers = compatibility.headers\n\t\t\t\t\t? Object.fromEntries(\n\t\t\t\t\t\t\tObject.entries(compatibility.headers).filter(\n\t\t\t\t\t\t\t\t(entry): entry is [string, string] => entry[1] !== null,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t)\n\t\t\t\t\t: undefined;\n\t\t\t\treturn { ok: true, headers };\n\t\t\t}\n\t\t\tconst headers = resolution.auth.headers\n\t\t\t\t? Object.fromEntries(\n\t\t\t\t\t\tObject.entries(resolution.auth.headers).filter(\n\t\t\t\t\t\t\t(entry): entry is [string, string] => entry[1] !== null,\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\t: undefined;\n\t\t\treturn { ok: true, apiKey: resolution.auth.apiKey, headers, env: resolution.env };\n\t\t} catch (error) {\n\t\t\tconst cause = error instanceof Error ? error.cause : undefined;\n\t\t\tconst message =\n\t\t\t\tcause instanceof Error ? cause.message : error instanceof Error ? error.message : String(error);\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\terror:\n\t\t\t\t\tmessage === \"authHeader requires a resolved API key\"\n\t\t\t\t\t\t? `No API key found for \"${model.provider}\"`\n\t\t\t\t\t\t: message,\n\t\t\t};\n\t\t}\n\t}\n\n\tgetProviderAuthStatus(provider: string): AuthStatus {\n\t\treturn this.runtime.getProviderAuthStatus(provider);\n\t}\n\n\tgetProvider(provider: string): Provider | undefined {\n\t\treturn this.runtime.getProvider(provider);\n\t}\n\n\tgetProviderDisplayName(provider: string): string {\n\t\treturn this.runtime.getProvider(provider)?.name ?? provider;\n\t}\n\n\tgetProviderAuth(provider: string): Promise<AuthResult | undefined> {\n\t\treturn this.runtime.getAuth(provider);\n\t}\n\n\tasync getApiKeyForProvider(provider: string): Promise<string | undefined> {\n\t\ttry {\n\t\t\treturn (await this.runtime.getAuth(provider))?.auth.apiKey;\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\tisUsingOAuth(model: Model<Api>): boolean {\n\t\treturn this.runtime.isUsingOAuth(model.provider);\n\t}\n\n\tregisterProvider(provider: Provider): void;\n\tregisterProvider(providerName: string, config: ProviderConfigInput): void;\n\tregisterProvider(providerOrName: Provider | string, config?: ProviderConfigInput): void {\n\t\tif (typeof providerOrName === \"string\") {\n\t\t\tif (!config) throw new Error(\"Provider config is required when registering by name\");\n\t\t\tthis.runtime.registerProvider(providerOrName, config);\n\t\t\treturn;\n\t\t}\n\t\tthis.runtime.registerNativeProvider(providerOrName);\n\t}\n\n\tunregisterProvider(providerName: string): void {\n\t\tthis.runtime.unregisterProvider(providerName);\n\t}\n\n\tgetRegisteredProviderConfig(providerName: string): ProviderConfigInput | undefined {\n\t\treturn this.runtime.getRegisteredProviderConfig(providerName);\n\t}\n\n\tgetRegisteredNativeProvider(providerName: string): Provider | undefined {\n\t\treturn this.runtime.getRegisteredNativeProvider(providerName);\n\t}\n\n\tgetRegisteredProviderIds(): readonly string[] {\n\t\treturn this.runtime.getRegisteredProviderIds();\n\t}\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ResolveCliModelResult } from "./model-resolver-types.ts";
|
|
2
|
-
import type {
|
|
2
|
+
import type { ModelRuntime } from "./model-runtime.ts";
|
|
3
3
|
/**
|
|
4
4
|
* Resolve a single model from CLI flags.
|
|
5
5
|
*
|
|
@@ -14,6 +14,6 @@ import type { ModelRegistry } from "./model-registry.ts";
|
|
|
14
14
|
export declare function resolveCliModel(options: {
|
|
15
15
|
cliProvider?: string;
|
|
16
16
|
cliModel?: string;
|
|
17
|
-
|
|
17
|
+
modelRuntime: ModelRuntime;
|
|
18
18
|
}): ResolveCliModelResult;
|
|
19
19
|
//# sourceMappingURL=model-resolver-cli.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-resolver-cli.d.ts","sourceRoot":"","sources":["../../src/core/model-resolver-cli.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"model-resolver-cli.d.ts","sourceRoot":"","sources":["../../src/core/model-resolver-cli.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAiCvD;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE;IACvC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,YAAY,CAAC;CAC5B,GAAG,qBAAqB,CA4HxB"}
|