@code-yeongyu/senpi 2026.8.28 → 2026.8.29
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 +74 -0
- package/dist/cli/args.d.ts +2 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +4 -0
- package/dist/cli/args.js.map +1 -1
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +2 -0
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +5 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +1 -0
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts +1 -0
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +3 -0
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/credential-accounts.d.ts.map +1 -1
- package/dist/core/credential-accounts.js +22 -12
- package/dist/core/credential-accounts.js.map +1 -1
- package/dist/core/credential-pool/classify.d.ts +6 -1
- package/dist/core/credential-pool/classify.d.ts.map +1 -1
- package/dist/core/credential-pool/classify.js +22 -5
- package/dist/core/credential-pool/classify.js.map +1 -1
- package/dist/core/credential-pool/failover.d.ts +8 -0
- package/dist/core/credential-pool/failover.d.ts.map +1 -1
- package/dist/core/credential-pool/failover.js +24 -6
- package/dist/core/credential-pool/failover.js.map +1 -1
- package/dist/core/credential-pool/rotation-stream.d.ts +13 -2
- package/dist/core/credential-pool/rotation-stream.d.ts.map +1 -1
- package/dist/core/credential-pool/rotation-stream.js +97 -10
- package/dist/core/credential-pool/rotation-stream.js.map +1 -1
- package/dist/core/extensions/builtin/goal/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/index.js +7 -0
- package/dist/core/extensions/builtin/goal/index.js.map +1 -1
- package/dist/core/extensions/builtin/service-tier.d.ts.map +1 -1
- package/dist/core/extensions/builtin/service-tier.js +13 -0
- package/dist/core/extensions/builtin/service-tier.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/extension.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/extension.js +4 -2
- package/dist/core/extensions/builtin/terminal/extension.js.map +1 -1
- package/dist/core/model-config-schema.d.ts +4 -4
- package/dist/core/model-runtime.d.ts +2 -0
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +74 -37
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/retry-fallback/chains.d.ts +23 -1
- package/dist/core/retry-fallback/chains.d.ts.map +1 -1
- package/dist/core/retry-fallback/chains.js +59 -3
- package/dist/core/retry-fallback/chains.js.map +1 -1
- package/dist/core/retry-fallback/controller.d.ts.map +1 -1
- package/dist/core/retry-fallback/controller.js +9 -2
- package/dist/core/retry-fallback/controller.js.map +1 -1
- package/dist/core/retry-fallback/settings.d.ts.map +1 -1
- package/dist/core/retry-fallback/settings.js +9 -0
- package/dist/core/retry-fallback/settings.js.map +1 -1
- package/dist/core/retry-fallback/validate.js +1 -1
- package/dist/core/retry-fallback/validate.js.map +1 -1
- package/dist/core/sdk.js +1 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager.d.ts +9 -0
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +31 -0
- package/dist/core/session-manager.js.map +1 -1
- package/dist/main.d.ts +7 -0
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +10 -1
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/favorite-models-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/favorite-models-selector.js +2 -2
- package/dist/modes/interactive/components/favorite-models-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-host-runtime.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-host-runtime.js +323 -33
- package/dist/modes/interactive/interactive-host-runtime.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +276 -237
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/rpc/connection-handler.d.ts.map +1 -1
- package/dist/modes/rpc/connection-handler.js +133 -24
- package/dist/modes/rpc/connection-handler.js.map +1 -1
- package/dist/modes/rpc/multi-session-host.js +14 -4
- package/dist/modes/rpc/multi-session-host.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +82 -13
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +85 -28
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts +3 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +3 -1
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +162 -2
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/modes/rpc/session-command-router.d.ts +22 -0
- package/dist/modes/rpc/session-command-router.d.ts.map +1 -1
- package/dist/modes/rpc/session-command-router.js +147 -16
- package/dist/modes/rpc/session-command-router.js.map +1 -1
- package/dist/modes/rpc/session-event-writer.d.ts +2 -0
- package/dist/modes/rpc/session-event-writer.d.ts.map +1 -1
- package/dist/modes/rpc/session-event-writer.js +4 -0
- package/dist/modes/rpc/session-event-writer.js.map +1 -1
- package/dist/modes/rpc/session-registry.d.ts +7 -0
- package/dist/modes/rpc/session-registry.d.ts.map +1 -1
- package/dist/modes/rpc/session-registry.js +9 -0
- package/dist/modes/rpc/session-registry.js.map +1 -1
- package/docs/rpc.md +37 -0
- package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +24 -0
- package/node_modules/@code-yeongyu/senpi-codemode/package.json +4 -4
- package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js +6 -3
- package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/amazon-bedrock.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/baseten.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-ai-gateway.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-workers-ai.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/fireworks.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/huggingface.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/nvidia.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode-go.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/node_modules/@earendil-works/pi-ai/package.json +2 -2
- package/node_modules/@earendil-works/pi-pty/package.json +1 -1
- package/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
- package/node_modules/@earendil-works/pi-tui/package.json +1 -1
- package/package.json +7 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service-tier.js","sourceRoot":"","sources":["../../../../src/core/extensions/builtin/service-tier.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAO5D,MAAM,0BAA0B,GAAG,wBAAwB,CAAC;AAC5D,MAAM,CAAC,MAAM,mBAAmB,GAAG,0BAA0B,CAAC;AAC9D,MAAM,iBAAiB,GAAG,OAAO,CAAC;AAClC,MAAM,aAAa,GAAgB,UAAU,CAAC;AAC9C,MAAM,iBAAiB,GAAqB,IAAI,GAAG,CAAC,CAAC,kBA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AsF;gBACtF,wFAAwF;gBACxF,uFAAuF;gBACvF,oFAAoF;gBACpF,+EAA+E;gBAC/E,MAAM,uBAAuB,GAC5B,GAAG,CAAC,KAAK,KAAK,SAAS,IAAI,GAAG,CAAC,aAAa,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,aAAa,CAAC;gBAC1F,IACC,cAAc,KAAK,MAAM;oBACzB,aAAa,KAAK,aAAa;oBAC/B,GAAG,CAAC,WAAW,KAAK,aAAa;oBACjC,uBAAuB,EACtB,CAAC;oBACF,oBAAoB,GAAG,SAAS,CAAC;gBAClC,CAAC;qBAAM,CAAC;oBACP,oBAAoB,GAAG,GAAG,CAAC,WAAW,CAAC;gBACxC,CAAC;YACF,CAAC;QACF,CAAC;aAAM,CAAC;YACP,oBAAoB,GAAG,GAAG,CAAC,WAAW,IAAI,mBAAmB,CAAC;QAC/D,CAAC;QACD,OAAO,uBAAuB,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,CAAC,OAAO,EAAE,oBAAoB,CAAC,CAAC;IACrF,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { Api, Model } from \"@earendil-works/pi-ai\";\nimport type { AutocompleteItem } from \"@earendil-works/pi-tui\";\nimport type { ModelRegistry } from \"../../model-registry.ts\";\nimport { SettingsManager } from \"../../settings-manager.ts\";\nimport type { ExtensionAPI, ExtensionCommandContext, ServiceTier } from \"../types.ts\";\n\nexport type { ServiceTier };\n\ntype ProviderPayload = Record<string, unknown>;\n\nconst OPENAI_CODEX_RESPONSES_API = \"openai-codex-responses\";\nexport const CODEX_RESPONSES_API = OPENAI_CODEX_RESPONSES_API;\nconst FAST_MODEL_SUFFIX = \"-fast\";\nconst PRIORITY_TIER: ServiceTier = \"priority\";\nconst SERVICE_TIER_APIS: ReadonlySet<Api> = new Set([\"openai-responses\", OPENAI_CODEX_RESPONSES_API]);\nconst FAST_ARGUMENTS = [\"on\", \"off\"] as const;\nconst FAST_USAGE = \"Usage: /fast [on|off]\";\n\ntype FastArgument = (typeof FAST_ARGUMENTS)[number];\n\nfunction isRecord(value: unknown): value is ProviderPayload {\n\treturn typeof value === \"object\" && value !== null;\n}\n\nexport function addServiceTierToPayload(api: Api | undefined, payload: unknown, serviceTier?: ServiceTier): unknown {\n\tif (!api || !SERVICE_TIER_APIS.has(api) || !serviceTier) {\n\t\treturn payload;\n\t}\n\n\tif (!isRecord(payload) || payload.service_tier !== undefined) {\n\t\treturn payload;\n\t}\n\n\treturn {\n\t\t...payload,\n\t\tservice_tier: serviceTier,\n\t};\n}\n\nfunction getRequestModelId(modelRegistry: ModelRegistry, model: Model<Api>): string {\n\treturn modelRegistry.getUpstreamModelId(model) ?? model.id;\n}\n\nfunction isCompatibleFastVariant(modelRegistry: ModelRegistry, baseModel: Model<Api>, fastModel: Model<Api>): boolean {\n\treturn (\n\t\tfastModel.provider === baseModel.provider &&\n\t\tfastModel.api === baseModel.api &&\n\t\tmodelRegistry.getServiceTier(fastModel) === \"priority\" &&\n\t\tgetRequestModelId(modelRegistry, fastModel) === getRequestModelId(modelRegistry, baseModel)\n\t);\n}\n\nfunction findBaseModel(modelRegistry: ModelRegistry, fastModel: Model<Api>): Model<Api> | undefined {\n\tif (!fastModel.id.endsWith(FAST_MODEL_SUFFIX)) {\n\t\treturn undefined;\n\t}\n\n\tconst baseModelId = fastModel.id.slice(0, -FAST_MODEL_SUFFIX.length);\n\tconst baseModel = modelRegistry.find(fastModel.provider, baseModelId);\n\treturn baseModel && isCompatibleFastVariant(modelRegistry, baseModel, fastModel) ? baseModel : undefined;\n}\n\nfunction findFastModel(modelRegistry: ModelRegistry, baseModel: Model<Api>): Model<Api> | undefined {\n\tif (baseModel.id.endsWith(FAST_MODEL_SUFFIX)) {\n\t\treturn undefined;\n\t}\n\n\tconst fastModel = modelRegistry.find(baseModel.provider, `${baseModel.id}${FAST_MODEL_SUFFIX}`);\n\treturn fastModel && isCompatibleFastVariant(modelRegistry, baseModel, fastModel) ? fastModel : undefined;\n}\n\n/**\n * The model that owns this model's persisted service-tier preference.\n *\n * A `-fast` catalog variant and its base model are one model to the user (`/fast` just swaps\n * between them), so both must read and write ONE key. Anything else can hold contradictory\n * preferences for the same choice.\n */\nexport function resolveServiceTierMemoryModel(modelRegistry: ModelRegistry, model: Model<Api>): Model<Api> {\n\treturn findBaseModel(modelRegistry, model) ?? model;\n}\n\n/** Remembered service tier for this model, normalized onto its base-model key. */\nexport function getRememberedServiceTier(\n\tsettingsManager: SettingsManager,\n\tmodelRegistry: ModelRegistry,\n\tmodel: Model<Api>,\n): ServiceTier | undefined {\n\tconst memoryModel = resolveServiceTierMemoryModel(modelRegistry, model);\n\treturn settingsManager.getModelServiceTier(memoryModel.provider, memoryModel.id);\n}\n\n/** Host capabilities `applyFastMode` needs; satisfied by an extension context plus `pi`. */\nexport interface FastModeContext {\n\tcwd: string;\n\tagentDir: string;\n\tmodel: Model<Api> | undefined;\n\tmodelRegistry: ModelRegistry;\n\t/** Tier the host resolved for the active model (scoped/favorite pin or catalog). */\n\tserviceTier: ServiceTier | undefined;\n\tisProjectTrusted(): boolean;\n\tnotify(message: string, level: \"info\" | \"warning\" | \"error\"): void;\n\tsetSessionModel(model: Model<Api>): Promise<boolean>;\n\tsetSessionFastMode(enabled: boolean): void;\n}\n\nexport interface FastModeResult {\n\t/** Fast mode state after the call; unchanged when the request was refused. */\n\tenabled: boolean;\n\t/** False when the request was refused (non-Codex model, active pin, failed model switch). */\n\tapplied: boolean;\n\t/** The just-persisted tier (or the unchanged one when refused); `\"priority\"` on, `\"auto\"` off. */\n\trecordedTier: ServiceTier;\n\tmessage: string;\n}\n\n/**\n * Whether the active model's priority tier is PINNED by the user's model selection (a scoped\n * or favorite `provider/id:priority` pattern) rather than inherited from the catalog.\n *\n * `ctx.serviceTier` merges both sources, so a priority the catalog does not explain must have\n * come from a `:priority` decorator; checking `scopedModels` alone would miss favorite pins,\n * which the session resolves the same way.\n */\nfunction hasPriorityPin(ctx: FastModeContext, model: Model<Api>): boolean {\n\tif (ctx.serviceTier !== PRIORITY_TIER) return false;\n\treturn ctx.modelRegistry.getServiceTier(model) !== PRIORITY_TIER;\n}\n\n/**\n * Single entry point for turning fast mode on/off: the `/fast` command and any other surface\n * (RPC) must go through this so persistence and `-fast` key normalization exist exactly once.\n *\n * `off` persists an explicit `\"auto\"` rather than deleting the key: deletion re-inherits the\n * catalog/global tier, which is what the user just asked to turn off.\n */\nexport async function applyFastMode(ctx: FastModeContext, enabled: boolean): Promise<FastModeResult> {\n\tconst model = ctx.model;\n\tif (model?.api !== OPENAI_CODEX_RESPONSES_API) {\n\t\tconst message = \"Fast mode is only available for OpenAI Codex models.\";\n\t\tctx.notify(message, \"warning\");\n\t\treturn { enabled: false, applied: false, recordedTier: \"auto\", message };\n\t}\n\n\tif (!enabled && hasPriorityPin(ctx, model)) {\n\t\t// The pin outranks the memory, so writing \"auto\" here would be a silent no-op on the wire.\n\t\tconst message = \"Fast mode is fixed by the active model selection's priority tier.\";\n\t\tctx.notify(message, \"info\");\n\t\t// The pin keeps the model on priority no matter what the memory says, so that is the honest\n\t\t// tier to report; nothing was written, and no caller reads this field when `applied` is false.\n\t\treturn { enabled: true, applied: false, recordedTier: PRIORITY_TIER, message };\n\t}\n\n\tconst settingsManager = SettingsManager.create(ctx.cwd, ctx.agentDir, { projectTrusted: ctx.isProjectTrusted() });\n\tconst memoryModel = resolveServiceTierMemoryModel(ctx.modelRegistry, model);\n\tconst tier: ServiceTier = enabled ? PRIORITY_TIER : \"auto\";\n\tsettingsManager.setModelServiceTier(memoryModel.provider, memoryModel.id, tier);\n\tawait settingsManager.flush();\n\n\tconst baseModel = findBaseModel(ctx.modelRegistry, model);\n\tconst targetModel = enabled ? findFastModel(ctx.modelRegistry, model) : baseModel;\n\tif (targetModel) {\n\t\tif (!(await ctx.setSessionModel(targetModel))) {\n\t\t\tconst message = `Could not switch to ${targetModel.provider}/${targetModel.id}.`;\n\t\t\tctx.notify(message, \"error\");\n\t\t\treturn { enabled: baseModel === undefined, applied: false, recordedTier: \"auto\", message };\n\t\t}\n\t}\n\n\tctx.setSessionFastMode(enabled);\n\tconst labelModel = targetModel ?? model;\n\tconst message = `Fast mode ${enabled ? \"enabled\" : \"disabled\"}: ${labelModel.id}`;\n\tctx.notify(message, \"info\");\n\treturn { enabled, applied: true, recordedTier: tier, message };\n}\n\nfunction toCompletions(values: readonly string[], prefix: string): AutocompleteItem[] | null {\n\tconst matches = values.filter((value) => value.startsWith(prefix.trim()));\n\treturn matches.length > 0 ? matches.map((value) => ({ value, label: value })) : null;\n}\n\nfunction toFastModeContext(pi: ExtensionAPI, ctx: ExtensionCommandContext): FastModeContext {\n\treturn {\n\t\tcwd: ctx.cwd,\n\t\tagentDir: ctx.agentDir,\n\t\tmodel: ctx.model,\n\t\tmodelRegistry: ctx.modelRegistry,\n\t\tserviceTier: ctx.serviceTier,\n\t\tisProjectTrusted: () => ctx.isProjectTrusted(),\n\t\tnotify: (message, level) => ctx.ui.notify(message, level),\n\t\tsetSessionModel: (model) => pi.setSessionModel(model),\n\t\tsetSessionFastMode: (enabled) => pi.setSessionFastMode(enabled),\n\t};\n}\n\nexport default function serviceTierExtension(pi: ExtensionAPI): void {\n\tlet settingsServiceTier: ServiceTier | undefined;\n\t/**\n\t * Session-level fast mode for Codex models that have no `-fast` catalog sibling.\n\t *\n\t * The catalog generator emits `-fast` priority variants only for the direct\n\t * `openai` provider, so `openai-codex` models never have a switch target. The\n\t * ChatGPT backend still offers the tier to subscriptions:\n\t * `chatgpt.com/backend-api/codex/models` advertises a `priority` service tier\n\t * labelled \"Fast\" (\"1.5x speed, increased usage\")\n\t * for gpt-5.4/5.5/5.6-*, and the first-party Codex CLI sends\n\t * `service_tier: \"priority\"` on subscription OAuth. The response echo is not a\n\t * confirmation channel — it reads `auto`/`default` whether or not a tier was\n\t * sent — so this toggle drives the request field directly. See issue #545.\n\t */\n\tlet sessionFastMode = false;\n\t/**\n\t * The per-model memory tier `/fast` last wrote or read for the active base model this\n\t * session. Lives only to suppress an inherited priority when the user turns fast off in\n\t * the SAME session: the host's resolved `ctx.serviceTier` is recomputed on model switch,\n\t * not on a memory write, so without this an in-session `/fast off` (no model swap) would\n\t * keep sending `priority` until a restart. Scoped to the active base key (re-derived on\n\t * model_select for the incoming model) so it never leaks across models.\n\t */\n\tlet liveMemoryTier: ServiceTier | undefined;\n\tlet liveMemoryKey: string | undefined;\n\n\tpi.on(\"session_start\", async (_event, ctx) => {\n\t\tconst settingsManager = SettingsManager.create(ctx.cwd, ctx.agentDir, { projectTrusted: ctx.isProjectTrusted() });\n\t\tsettingsServiceTier = settingsManager.getOpenAIServiceTier();\n\n\t\tconst model = ctx.model;\n\t\tif (model?.api !== OPENAI_CODEX_RESPONSES_API) {\n\t\t\tsessionFastMode = false;\n\t\t\tpi.setSessionFastMode(false);\n\t\t\treturn;\n\t\t}\n\n\t\t// Fast mode is remembered per model, so a new session inherits the user's last choice for\n\t\t// THIS model instead of silently starting off. A model whose catalog/scoped tier is already\n\t\t// `priority` (a models.json priority entry, or a `-fast`-less codex model) is treated as\n\t\t// fast-active when nothing is remembered; an explicit remembered `\"auto\"` (`/fast off`)\n\t\t// wins over that inheritance. Malformed values read back as undefined.\n\t\t//\n\t\t// The flag is derived from the POST-swap model: a `-fast` catalog variant swaps down to\n\t\t// its base before this reads `ctx.serviceTier`, so inheritance is judged on the model the\n\t\t// user actually ends up on.\n\t\tconst remembered = getRememberedServiceTier(settingsManager, ctx.modelRegistry, model);\n\n\t\tconst baseModel = findBaseModel(ctx.modelRegistry, model);\n\t\tif (baseModel) {\n\t\t\tawait pi.setSessionModel(baseModel);\n\t\t}\n\n\t\tsessionFastMode = remembered === PRIORITY_TIER || (remembered === undefined && ctx.serviceTier === PRIORITY_TIER);\n\t\tpi.setSessionFastMode(sessionFastMode);\n\t\tconst memoryModel = resolveServiceTierMemoryModel(ctx.modelRegistry, model);\n\t\tliveMemoryKey = `${memoryModel.provider}/${memoryModel.id}`;\n\t\tliveMemoryTier = remembered;\n\t});\n\n\tpi.on(\"model_select\", (event, ctx) => {\n\t\t// A model switch changes the base key the memory lives under, so the live tier is RE-DERIVED\n\t\t// for the incoming model instead of merely dropped: dropping it would leave a remembered\n\t\t// \"auto\" unable to suppress a catalog-inherited priority after switching away and back in one\n\t\t// session, silently re-sending the tier `/fast off` turned off. Per-key scoping is preserved —\n\t\t// each model reads ITS OWN memory, never the previous model's.\n\t\tconst settingsManager = SettingsManager.create(ctx.cwd, ctx.agentDir, { projectTrusted: ctx.isProjectTrusted() });\n\t\tconst memoryModel = resolveServiceTierMemoryModel(ctx.modelRegistry, event.model);\n\t\tliveMemoryKey = `${memoryModel.provider}/${memoryModel.id}`;\n\t\tliveMemoryTier = getRememberedServiceTier(settingsManager, ctx.modelRegistry, event.model);\n\t});\n\n\tpi.registerCommand(\"fast\", {\n\t\tdescription: \"Turn OpenAI Codex fast mode on or off for the current model\",\n\t\targumentHint: \"[on|off]\",\n\t\tgetArgumentCompletions: (prefix) => toCompletions(FAST_ARGUMENTS, prefix),\n\t\thandler: async (args, ctx) => {\n\t\t\tconst argument = args.trim().toLowerCase();\n\t\t\tif (argument !== \"\" && !FAST_ARGUMENTS.includes(argument as FastArgument)) {\n\t\t\t\tctx.ui.notify(FAST_USAGE, \"error\");\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// No argument keeps the established toggle UX.\n\t\t\tconst active = sessionFastMode || ctx.serviceTier === PRIORITY_TIER;\n\t\t\tconst enabled = argument === \"\" ? !active : argument === \"on\";\n\t\t\tconst result = await applyFastMode(toFastModeContext(pi, ctx), enabled);\n\t\t\tsessionFastMode = result.enabled;\n\t\t\t// Track this session's own write AFTER applyFastMode's internal model switch (which fires\n\t\t\t// model_select and clears the live tier). Keyed to the active base model so a later switch\n\t\t\t// cannot carry it across models.\n\t\t\tif (result.applied && ctx.model) {\n\t\t\t\tconst memoryModel = resolveServiceTierMemoryModel(ctx.modelRegistry, ctx.model);\n\t\t\t\tliveMemoryKey = `${memoryModel.provider}/${memoryModel.id}`;\n\t\t\t\tliveMemoryTier = result.recordedTier;\n\t\t\t}\n\t\t},\n\t});\n\n\tpi.on(\"before_provider_request\", (event, ctx) => {\n\t\tlet effectiveServiceTier: ServiceTier | undefined;\n\t\tif (ctx.model?.api === OPENAI_CODEX_RESPONSES_API) {\n\t\t\tif (sessionFastMode) {\n\t\t\t\teffectiveServiceTier = PRIORITY_TIER;\n\t\t\t} else {\n\t\t\t\tconst memoryModel = ctx.model ? resolveServiceTierMemoryModel(ctx.modelRegistry, ctx.model) : undefined;\n\t\t\t\tconst activeBaseKey = memoryModel ? `${memoryModel.provider}/${memoryModel.id}` : undefined;\n\t\t\t\t// Same-session /fast off: the host's resolved ctx.serviceTier is only recomputed on a\n\t\t\t\t// model switch, so an inherited priority would otherwise keep emitting until a restart.\n\t\t\t\t// Only a CATALOG-explained priority may be suppressed: a priority the catalog does not\n\t\t\t\t// explain is an explicit scoped/favorite `:priority` pin, which outranks the memory\n\t\t\t\t// (same discriminator `applyFastMode` uses to refuse `/fast off` under a pin).\n\t\t\t\tconst catalogExplainsPriority =\n\t\t\t\t\tctx.model !== undefined && ctx.modelRegistry.getServiceTier(ctx.model) === PRIORITY_TIER;\n\t\t\t\tif (\n\t\t\t\t\tliveMemoryTier === \"auto\" &&\n\t\t\t\t\tactiveBaseKey === liveMemoryKey &&\n\t\t\t\t\tctx.serviceTier === PRIORITY_TIER &&\n\t\t\t\t\tcatalogExplainsPriority\n\t\t\t\t) {\n\t\t\t\t\teffectiveServiceTier = undefined;\n\t\t\t\t} else {\n\t\t\t\t\teffectiveServiceTier = ctx.serviceTier;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\teffectiveServiceTier = ctx.serviceTier ?? settingsServiceTier;\n\t\t}\n\t\treturn addServiceTierToPayload(ctx.model?.api, event.payload, effectiveServiceTier);\n\t});\n}\n"]}
|
|
1
|
+
{"version":3,"file":"service-tier.js","sourceRoot":"","sources":["../../../../src/core/extensions/builtin/service-tier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AC,OAAO,EAAE,oBAAoB,CAAC,CAAC;IACrF,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { Api, Model } from \"@earendil-works/pi-ai\";\nimport type { AutocompleteItem } from \"@earendil-works/pi-tui\";\nimport type { ModelRegistry } from \"../../model-registry.ts\";\nimport { SettingsManager } from \"../../settings-manager.ts\";\nimport type { ExtensionAPI, ExtensionCommandContext, ServiceTier } from \"../types.ts\";\n\nexport type { ServiceTier };\n\ntype ProviderPayload = Record<string, unknown>;\n\nconst OPENAI_CODEX_RESPONSES_API = \"openai-codex-responses\";\nexport const CODEX_RESPONSES_API = OPENAI_CODEX_RESPONSES_API;\nconst FAST_MODEL_SUFFIX = \"-fast\";\nconst PRIORITY_TIER: ServiceTier = \"priority\";\nconst SERVICE_TIER_APIS: ReadonlySet<Api> = new Set([\"openai-responses\", OPENAI_CODEX_RESPONSES_API]);\nconst FAST_ARGUMENTS = [\"on\", \"off\"] as const;\nconst FAST_USAGE = \"Usage: /fast [on|off]\";\n\ntype FastArgument = (typeof FAST_ARGUMENTS)[number];\n\nfunction isRecord(value: unknown): value is ProviderPayload {\n\treturn typeof value === \"object\" && value !== null;\n}\n\nexport function addServiceTierToPayload(api: Api | undefined, payload: unknown, serviceTier?: ServiceTier): unknown {\n\tif (!api || !SERVICE_TIER_APIS.has(api) || !serviceTier) {\n\t\treturn payload;\n\t}\n\n\tif (!isRecord(payload) || payload.service_tier !== undefined) {\n\t\treturn payload;\n\t}\n\n\treturn {\n\t\t...payload,\n\t\tservice_tier: serviceTier,\n\t};\n}\n\nfunction getRequestModelId(modelRegistry: ModelRegistry, model: Model<Api>): string {\n\treturn modelRegistry.getUpstreamModelId(model) ?? model.id;\n}\n\nfunction isCompatibleFastVariant(modelRegistry: ModelRegistry, baseModel: Model<Api>, fastModel: Model<Api>): boolean {\n\treturn (\n\t\tfastModel.provider === baseModel.provider &&\n\t\tfastModel.api === baseModel.api &&\n\t\tmodelRegistry.getServiceTier(fastModel) === \"priority\" &&\n\t\tgetRequestModelId(modelRegistry, fastModel) === getRequestModelId(modelRegistry, baseModel)\n\t);\n}\n\nfunction findBaseModel(modelRegistry: ModelRegistry, fastModel: Model<Api>): Model<Api> | undefined {\n\tif (!fastModel.id.endsWith(FAST_MODEL_SUFFIX)) {\n\t\treturn undefined;\n\t}\n\n\tconst baseModelId = fastModel.id.slice(0, -FAST_MODEL_SUFFIX.length);\n\tconst baseModel = modelRegistry.find(fastModel.provider, baseModelId);\n\treturn baseModel && isCompatibleFastVariant(modelRegistry, baseModel, fastModel) ? baseModel : undefined;\n}\n\nfunction findFastModel(modelRegistry: ModelRegistry, baseModel: Model<Api>): Model<Api> | undefined {\n\tif (baseModel.id.endsWith(FAST_MODEL_SUFFIX)) {\n\t\treturn undefined;\n\t}\n\n\tconst fastModel = modelRegistry.find(baseModel.provider, `${baseModel.id}${FAST_MODEL_SUFFIX}`);\n\treturn fastModel && isCompatibleFastVariant(modelRegistry, baseModel, fastModel) ? fastModel : undefined;\n}\n\n/**\n * The model that owns this model's persisted service-tier preference.\n *\n * A `-fast` catalog variant and its base model are one model to the user (`/fast` just swaps\n * between them), so both must read and write ONE key. Anything else can hold contradictory\n * preferences for the same choice.\n */\nexport function resolveServiceTierMemoryModel(modelRegistry: ModelRegistry, model: Model<Api>): Model<Api> {\n\treturn findBaseModel(modelRegistry, model) ?? model;\n}\n\n/** Remembered service tier for this model, normalized onto its base-model key. */\nexport function getRememberedServiceTier(\n\tsettingsManager: SettingsManager,\n\tmodelRegistry: ModelRegistry,\n\tmodel: Model<Api>,\n): ServiceTier | undefined {\n\tconst memoryModel = resolveServiceTierMemoryModel(modelRegistry, model);\n\treturn settingsManager.getModelServiceTier(memoryModel.provider, memoryModel.id);\n}\n\n/** Host capabilities `applyFastMode` needs; satisfied by an extension context plus `pi`. */\nexport interface FastModeContext {\n\tcwd: string;\n\tagentDir: string;\n\tmodel: Model<Api> | undefined;\n\tmodelRegistry: ModelRegistry;\n\t/** Tier the host resolved for the active model (scoped/favorite pin or catalog). */\n\tserviceTier: ServiceTier | undefined;\n\tisProjectTrusted(): boolean;\n\tnotify(message: string, level: \"info\" | \"warning\" | \"error\"): void;\n\tsetSessionModel(model: Model<Api>): Promise<boolean>;\n\tsetSessionFastMode(enabled: boolean): void;\n}\n\nexport interface FastModeResult {\n\t/** Fast mode state after the call; unchanged when the request was refused. */\n\tenabled: boolean;\n\t/** False when the request was refused (non-Codex model, active pin, failed model switch). */\n\tapplied: boolean;\n\t/** The just-persisted tier (or the unchanged one when refused); `\"priority\"` on, `\"auto\"` off. */\n\trecordedTier: ServiceTier;\n\tmessage: string;\n}\n\n/**\n * Whether the active model's priority tier is PINNED by the user's model selection (a scoped\n * or favorite `provider/id:priority` pattern) rather than inherited from the catalog.\n *\n * `ctx.serviceTier` merges both sources, so a priority the catalog does not explain must have\n * come from a `:priority` decorator; checking `scopedModels` alone would miss favorite pins,\n * which the session resolves the same way.\n */\nfunction hasPriorityPin(ctx: FastModeContext, model: Model<Api>): boolean {\n\tif (ctx.serviceTier !== PRIORITY_TIER) return false;\n\treturn ctx.modelRegistry.getServiceTier(model) !== PRIORITY_TIER;\n}\n\n/**\n * Single entry point for turning fast mode on/off: the `/fast` command and any other surface\n * (RPC) must go through this so persistence and `-fast` key normalization exist exactly once.\n *\n * `off` persists an explicit `\"auto\"` rather than deleting the key: deletion re-inherits the\n * catalog/global tier, which is what the user just asked to turn off.\n */\nexport async function applyFastMode(ctx: FastModeContext, enabled: boolean): Promise<FastModeResult> {\n\tconst model = ctx.model;\n\tif (model?.api !== OPENAI_CODEX_RESPONSES_API) {\n\t\tconst message = \"Fast mode is only available for OpenAI Codex models.\";\n\t\tctx.notify(message, \"warning\");\n\t\treturn { enabled: false, applied: false, recordedTier: \"auto\", message };\n\t}\n\n\tif (!enabled && hasPriorityPin(ctx, model)) {\n\t\t// The pin outranks the memory, so writing \"auto\" here would be a silent no-op on the wire.\n\t\tconst message = \"Fast mode is fixed by the active model selection's priority tier.\";\n\t\tctx.notify(message, \"info\");\n\t\t// The pin keeps the model on priority no matter what the memory says, so that is the honest\n\t\t// tier to report; nothing was written, and no caller reads this field when `applied` is false.\n\t\treturn { enabled: true, applied: false, recordedTier: PRIORITY_TIER, message };\n\t}\n\n\tconst settingsManager = SettingsManager.create(ctx.cwd, ctx.agentDir, { projectTrusted: ctx.isProjectTrusted() });\n\tconst memoryModel = resolveServiceTierMemoryModel(ctx.modelRegistry, model);\n\tconst tier: ServiceTier = enabled ? PRIORITY_TIER : \"auto\";\n\tsettingsManager.setModelServiceTier(memoryModel.provider, memoryModel.id, tier);\n\tawait settingsManager.flush();\n\n\tconst baseModel = findBaseModel(ctx.modelRegistry, model);\n\tconst targetModel = enabled ? findFastModel(ctx.modelRegistry, model) : baseModel;\n\tif (targetModel) {\n\t\tif (!(await ctx.setSessionModel(targetModel))) {\n\t\t\tconst message = `Could not switch to ${targetModel.provider}/${targetModel.id}.`;\n\t\t\tctx.notify(message, \"error\");\n\t\t\treturn { enabled: baseModel === undefined, applied: false, recordedTier: \"auto\", message };\n\t\t}\n\t}\n\n\tctx.setSessionFastMode(enabled);\n\tconst labelModel = targetModel ?? model;\n\tconst message = `Fast mode ${enabled ? \"enabled\" : \"disabled\"}: ${labelModel.id}`;\n\tctx.notify(message, \"info\");\n\treturn { enabled, applied: true, recordedTier: tier, message };\n}\n\nfunction toCompletions(values: readonly string[], prefix: string): AutocompleteItem[] | null {\n\tconst matches = values.filter((value) => value.startsWith(prefix.trim()));\n\treturn matches.length > 0 ? matches.map((value) => ({ value, label: value })) : null;\n}\n\nfunction toFastModeContext(pi: ExtensionAPI, ctx: ExtensionCommandContext): FastModeContext {\n\treturn {\n\t\tcwd: ctx.cwd,\n\t\tagentDir: ctx.agentDir,\n\t\tmodel: ctx.model,\n\t\tmodelRegistry: ctx.modelRegistry,\n\t\tserviceTier: ctx.serviceTier,\n\t\tisProjectTrusted: () => ctx.isProjectTrusted(),\n\t\tnotify: (message, level) => ctx.ui.notify(message, level),\n\t\tsetSessionModel: (model) => pi.setSessionModel(model),\n\t\tsetSessionFastMode: (enabled) => pi.setSessionFastMode(enabled),\n\t};\n}\n\nexport default function serviceTierExtension(pi: ExtensionAPI): void {\n\tlet settingsServiceTier: ServiceTier | undefined;\n\t/**\n\t * Session-level fast mode for Codex models that have no `-fast` catalog sibling.\n\t *\n\t * The catalog generator emits `-fast` priority variants only for the direct\n\t * `openai` provider, so `openai-codex` models never have a switch target. The\n\t * ChatGPT backend still offers the tier to subscriptions:\n\t * `chatgpt.com/backend-api/codex/models` advertises a `priority` service tier\n\t * labelled \"Fast\" (\"1.5x speed, increased usage\")\n\t * for gpt-5.4/5.5/5.6-*, and the first-party Codex CLI sends\n\t * `service_tier: \"priority\"` on subscription OAuth. The response echo is not a\n\t * confirmation channel — it reads `auto`/`default` whether or not a tier was\n\t * sent — so this toggle drives the request field directly. See issue #545.\n\t */\n\tlet sessionFastMode = false;\n\t/**\n\t * The per-model memory tier `/fast` last wrote or read for the active base model this\n\t * session. Lives only to suppress an inherited priority when the user turns fast off in\n\t * the SAME session: the host's resolved `ctx.serviceTier` is recomputed on model switch,\n\t * not on a memory write, so without this an in-session `/fast off` (no model swap) would\n\t * keep sending `priority` until a restart. Scoped to the active base key (re-derived on\n\t * model_select for the incoming model) so it never leaks across models.\n\t */\n\tlet liveMemoryTier: ServiceTier | undefined;\n\tlet liveMemoryKey: string | undefined;\n\n\tpi.on(\"session_start\", async (_event, ctx) => {\n\t\tconst settingsManager = SettingsManager.create(ctx.cwd, ctx.agentDir, { projectTrusted: ctx.isProjectTrusted() });\n\t\tsettingsServiceTier = settingsManager.getOpenAIServiceTier();\n\n\t\tconst model = ctx.model;\n\t\tif (model?.api !== OPENAI_CODEX_RESPONSES_API) {\n\t\t\tsessionFastMode = false;\n\t\t\tpi.setSessionFastMode(false);\n\t\t\treturn;\n\t\t}\n\n\t\t// Fast mode is remembered per model, so a new session inherits the user's last choice for\n\t\t// THIS model instead of silently starting off. A model whose catalog/scoped tier is already\n\t\t// `priority` (a models.json priority entry, or a `-fast`-less codex model) is treated as\n\t\t// fast-active when nothing is remembered; an explicit remembered `\"auto\"` (`/fast off`)\n\t\t// wins over that inheritance. Malformed values read back as undefined.\n\t\t//\n\t\t// The flag is derived from the POST-swap model: a `-fast` catalog variant swaps down to\n\t\t// its base before this reads `ctx.serviceTier`, so inheritance is judged on the model the\n\t\t// user actually ends up on.\n\t\tconst remembered = getRememberedServiceTier(settingsManager, ctx.modelRegistry, model);\n\n\t\tconst baseModel = findBaseModel(ctx.modelRegistry, model);\n\t\tif (baseModel) {\n\t\t\tawait pi.setSessionModel(baseModel);\n\t\t}\n\n\t\tsessionFastMode = remembered === PRIORITY_TIER || (remembered === undefined && ctx.serviceTier === PRIORITY_TIER);\n\t\tpi.setSessionFastMode(sessionFastMode);\n\t\tconst memoryModel = resolveServiceTierMemoryModel(ctx.modelRegistry, model);\n\t\tliveMemoryKey = `${memoryModel.provider}/${memoryModel.id}`;\n\t\tliveMemoryTier = remembered;\n\t});\n\n\tpi.on(\"model_select\", (event, ctx) => {\n\t\t// A model switch changes the base key the memory lives under, so the live tier is RE-DERIVED\n\t\t// for the incoming model instead of merely dropped: dropping it would leave a remembered\n\t\t// \"auto\" unable to suppress a catalog-inherited priority after switching away and back in one\n\t\t// session, silently re-sending the tier `/fast off` turned off. Per-key scoping is preserved —\n\t\t// each model reads ITS OWN memory, never the previous model's.\n\t\tconst settingsManager = SettingsManager.create(ctx.cwd, ctx.agentDir, { projectTrusted: ctx.isProjectTrusted() });\n\t\tconst memoryModel = resolveServiceTierMemoryModel(ctx.modelRegistry, event.model);\n\t\tliveMemoryKey = `${memoryModel.provider}/${memoryModel.id}`;\n\t\tliveMemoryTier = getRememberedServiceTier(settingsManager, ctx.modelRegistry, event.model);\n\n\t\t// `service_tier` is an OpenAI-family request field, so hopping to a non-Codex model leaves the\n\t\t// intent with nothing to act on: `before_provider_request` already refuses to emit the tier\n\t\t// there, but the session flag kept `isFastModeActive()` (and with it the RPC `fastMode` and the\n\t\t// lightning indicator) claiming fast for a model that can never be served at that tier.\n\t\t//\n\t\t// Codex -> Codex is deliberately untouched: fast mode is a SESSION intent that survives a\n\t\t// mid-session Codex switch (see service-tier-extension.test.ts \"keeps session fast mode on\n\t\t// across a mid-session switch to another Codex model\"), and an incoming model's remembered\n\t\t// \"auto\" is honored on the wire by `liveMemoryTier` below, not by clearing the flag here.\n\t\tif (sessionFastMode && event.model.api !== OPENAI_CODEX_RESPONSES_API) {\n\t\t\tsessionFastMode = false;\n\t\t\tpi.setSessionFastMode(false);\n\t\t}\n\t});\n\n\tpi.registerCommand(\"fast\", {\n\t\tdescription: \"Turn OpenAI Codex fast mode on or off for the current model\",\n\t\targumentHint: \"[on|off]\",\n\t\tgetArgumentCompletions: (prefix) => toCompletions(FAST_ARGUMENTS, prefix),\n\t\thandler: async (args, ctx) => {\n\t\t\tconst argument = args.trim().toLowerCase();\n\t\t\tif (argument !== \"\" && !FAST_ARGUMENTS.includes(argument as FastArgument)) {\n\t\t\t\tctx.ui.notify(FAST_USAGE, \"error\");\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// No argument keeps the established toggle UX.\n\t\t\tconst active = sessionFastMode || ctx.serviceTier === PRIORITY_TIER;\n\t\t\tconst enabled = argument === \"\" ? !active : argument === \"on\";\n\t\t\tconst result = await applyFastMode(toFastModeContext(pi, ctx), enabled);\n\t\t\tsessionFastMode = result.enabled;\n\t\t\t// Track this session's own write AFTER applyFastMode's internal model switch (which fires\n\t\t\t// model_select and clears the live tier). Keyed to the active base model so a later switch\n\t\t\t// cannot carry it across models.\n\t\t\tif (result.applied && ctx.model) {\n\t\t\t\tconst memoryModel = resolveServiceTierMemoryModel(ctx.modelRegistry, ctx.model);\n\t\t\t\tliveMemoryKey = `${memoryModel.provider}/${memoryModel.id}`;\n\t\t\t\tliveMemoryTier = result.recordedTier;\n\t\t\t}\n\t\t},\n\t});\n\n\tpi.on(\"before_provider_request\", (event, ctx) => {\n\t\tlet effectiveServiceTier: ServiceTier | undefined;\n\t\tif (ctx.model?.api === OPENAI_CODEX_RESPONSES_API) {\n\t\t\tif (sessionFastMode) {\n\t\t\t\teffectiveServiceTier = PRIORITY_TIER;\n\t\t\t} else {\n\t\t\t\tconst memoryModel = ctx.model ? resolveServiceTierMemoryModel(ctx.modelRegistry, ctx.model) : undefined;\n\t\t\t\tconst activeBaseKey = memoryModel ? `${memoryModel.provider}/${memoryModel.id}` : undefined;\n\t\t\t\t// Same-session /fast off: the host's resolved ctx.serviceTier is only recomputed on a\n\t\t\t\t// model switch, so an inherited priority would otherwise keep emitting until a restart.\n\t\t\t\t// Only a CATALOG-explained priority may be suppressed: a priority the catalog does not\n\t\t\t\t// explain is an explicit scoped/favorite `:priority` pin, which outranks the memory\n\t\t\t\t// (same discriminator `applyFastMode` uses to refuse `/fast off` under a pin).\n\t\t\t\tconst catalogExplainsPriority =\n\t\t\t\t\tctx.model !== undefined && ctx.modelRegistry.getServiceTier(ctx.model) === PRIORITY_TIER;\n\t\t\t\tif (\n\t\t\t\t\tliveMemoryTier === \"auto\" &&\n\t\t\t\t\tactiveBaseKey === liveMemoryKey &&\n\t\t\t\t\tctx.serviceTier === PRIORITY_TIER &&\n\t\t\t\t\tcatalogExplainsPriority\n\t\t\t\t) {\n\t\t\t\t\teffectiveServiceTier = undefined;\n\t\t\t\t} else {\n\t\t\t\t\teffectiveServiceTier = ctx.serviceTier;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\teffectiveServiceTier = ctx.serviceTier ?? settingsServiceTier;\n\t\t}\n\t\treturn addServiceTierToPayload(ctx.model?.api, event.payload, effectiveServiceTier);\n\t});\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extension.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/extension.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAoB,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"extension.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/extension.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAoB,MAAM,gBAAgB,CAAC;AAoKrE,wBAAgB,yBAAyB,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CAsGhE;AAED,eAAe,yBAAyB,CAAC"}
|
|
@@ -32,7 +32,7 @@ function bundleSinks(pi, state) {
|
|
|
32
32
|
onMonitorEvent: (event) => state.monitorNotifier?.notifyEvent(event),
|
|
33
33
|
onMonitorState: (snapshot) => {
|
|
34
34
|
state.statusTicker.sync(snapshot);
|
|
35
|
-
|
|
35
|
+
const payload = {
|
|
36
36
|
activeCount: snapshot.length,
|
|
37
37
|
monitors: snapshot.map((entry) => ({
|
|
38
38
|
id: entry.id,
|
|
@@ -40,7 +40,9 @@ function bundleSinks(pi, state) {
|
|
|
40
40
|
paused: entry.paused,
|
|
41
41
|
startedAtMs: entry.startedAtMs,
|
|
42
42
|
})),
|
|
43
|
-
}
|
|
43
|
+
};
|
|
44
|
+
pi.events?.emit(TERMINAL_MONITOR_STATE_EVENT, payload);
|
|
45
|
+
pi.rpc?.emit(TERMINAL_MONITOR_STATE_EVENT, payload);
|
|
44
46
|
pi.events?.emit(WAKE_SOURCE_STATE_EVENT, {
|
|
45
47
|
source: "terminal-monitors",
|
|
46
48
|
activeCount: snapshot.length,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/extension.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAE/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,4BAA4B,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAClG,OAAO,EAAE,eAAe,EAAE,MAAM,q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ellEnv } from \"../../../../utils/shell.ts\";\nimport { SettingsManager } from \"../../../settings-manager.ts\";\nimport type { ExtensionAPI, ExtensionContext } from \"../../types.ts\";\nimport { isAnthropicBashEnabled } from \"../anthropic-bash/index.ts\";\nimport { TERMINAL_MONITOR_STATE_EVENT, WAKE_SOURCE_STATE_EVENT } from \"../monitor-state-event.ts\";\nimport { MonitorNotifier } from \"./monitor-notify.ts\";\nimport { MONITOR_STATUS_KEY } from \"./monitor-status.ts\";\nimport { MonitorStatusTicker } from \"./monitor-status-ticker.ts\";\nimport { TerminalNotifier } from \"./notify.ts\";\nimport { TERMINAL_PROMPT_SECTION } from \"./prompt.ts\";\nimport type { TerminalRuntimeSession } from \"./runtime-session.ts\";\nimport {\n\tclaimParkedBundle,\n\tparkBundle,\n\ttype TerminalEventSinks,\n\tTerminalSessionBundle,\n\tteardownParkedBundle,\n} from \"./session-bundle.ts\";\nimport { loadTerminalSettings, type ResolvedTerminalSettings, TERMINAL_SETTINGS_DEFAULTS } from \"./settings.ts\";\nimport { TERMINAL_BASH_TOOL, TERMINAL_COMPANION_TOOLS } from \"./shared.ts\";\nimport { createPtyBashTool } from \"./tools/bash.ts\";\nimport { createBashInputTool } from \"./tools/bash-input.ts\";\nimport { createBashOutputTool } from \"./tools/bash-output.ts\";\nimport { createBashResizeTool } from \"./tools/bash-resize.ts\";\nimport type { TerminalToolContext } from \"./tools/context.ts\";\nimport { createKillBashTool } from \"./tools/kill-bash.ts\";\nimport { createMonitorTool } from \"./tools/monitor.ts\";\n\ninterface TerminalExtensionState {\n\tbundle: TerminalSessionBundle | null;\n\tsettings: ResolvedTerminalSettings;\n\tnotifier: TerminalNotifier | null;\n\tmonitorNotifier: MonitorNotifier | null;\n\tstatusTicker: MonitorStatusTicker;\n\tctx: ExtensionContext | undefined;\n\tshellPath: string | undefined;\n\tsteppedAside: boolean;\n\tnoticeShown: boolean;\n}\n\n/** Tests and SDK callers may hand partial contexts without a session manager. */\nfunction sessionKeyOf(ctx: ExtensionContext | undefined): string | undefined {\n\treturn ctx?.sessionManager?.getSessionId?.();\n}\n\nfunction createBundle(state: TerminalExtensionState): TerminalSessionBundle {\n\treturn new TerminalSessionBundle({\n\t\tmaxSessions: state.settings.maxSessions,\n\t\tscrollback: state.settings.scrollback,\n\t});\n}\n\n/** Sinks read the live instance state at call time, so notifier swaps need no re-bind. */\nfunction bundleSinks(pi: ExtensionAPI, state: TerminalExtensionState): TerminalEventSinks {\n\treturn {\n\t\tonMonitorEvent: (event) => state.monitorNotifier?.notifyEvent(event),\n\t\tonMonitorState: (snapshot) => {\n\t\t\tstate.statusTicker.sync(snapshot);\n\t\t\tpi.events?.emit(TERMINAL_MONITOR_STATE_EVENT, {\n\t\t\t\tactiveCount: snapshot.length,\n\t\t\t\tmonitors: snapshot.map((entry) => ({\n\t\t\t\t\tid: entry.id,\n\t\t\t\t\tdescription: entry.description,\n\t\t\t\t\tpaused: entry.paused,\n\t\t\t\t\tstartedAtMs: entry.startedAtMs,\n\t\t\t\t})),\n\t\t\t});\n\t\t\tpi.events?.emit(WAKE_SOURCE_STATE_EVENT, {\n\t\t\t\tsource: \"terminal-monitors\",\n\t\t\t\tactiveCount: snapshot.length,\n\t\t\t\tmonitors: snapshot.map((entry) => ({\n\t\t\t\t\tid: entry.id,\n\t\t\t\t\tdescription: entry.description,\n\t\t\t\t\tstartedAtMs: entry.startedAtMs,\n\t\t\t\t})),\n\t\t\t});\n\t\t},\n\t\tonBackgroundState: (snapshot) => {\n\t\t\tpi.events?.emit(WAKE_SOURCE_STATE_EVENT, {\n\t\t\t\tsource: \"terminal-background-sessions\",\n\t\t\t\tactiveCount: snapshot.length,\n\t\t\t\titems: snapshot,\n\t\t\t});\n\t\t},\n\t\tonBackgroundExit: (id, runtime) => state.notifier?.notifyCompletion(id, runtime),\n\t};\n}\n\nfunction buildToolContext(pi: ExtensionAPI, state: TerminalExtensionState): TerminalToolContext {\n\tconst requireBundle = (): TerminalSessionBundle => {\n\t\t// Lazily create a bundle so the tools work even when invoked directly (e.g. via the\n\t\t// SDK) before `session_start` initializes one. `session_start` replaces it with a\n\t\t// settings-configured bundle and tears down any earlier one.\n\t\tif (!state.bundle) {\n\t\t\tstate.bundle = createBundle(state);\n\t\t\tstate.bundle.bind(bundleSinks(pi, state));\n\t\t}\n\t\treturn state.bundle;\n\t};\n\treturn {\n\t\tget manager() {\n\t\t\treturn requireBundle().manager;\n\t\t},\n\t\tget cwd() {\n\t\t\treturn state.ctx?.cwd ?? process.cwd();\n\t\t},\n\t\tget shellPath() {\n\t\t\treturn state.shellPath;\n\t\t},\n\t\tget defaultCols() {\n\t\t\treturn state.settings.defaultCols;\n\t\t},\n\t\tget defaultRows() {\n\t\t\treturn state.settings.defaultRows;\n\t\t},\n\t\tget timeoutAction() {\n\t\t\treturn state.settings.timeoutAction;\n\t\t},\n\t\tget monitorRegistry() {\n\t\t\treturn requireBundle().monitors;\n\t\t},\n\t\tgetEnv: () => getShellEnv(),\n\t\tgetSessionContext: () => state.ctx,\n\t\t// Exit listeners registered before a reload reach the post-reload owner through the\n\t\t// shared bundle, so this must dispatch via the bundle, never the instance notifier.\n\t\tonBackgroundStart: (id: string, description: string, startedAtMs: number) => {\n\t\t\tstate.bundle?.notifyBackgroundStart(id, description, startedAtMs);\n\t\t},\n\t\tonBackgroundExit: (id: string, runtime: TerminalRuntimeSession) => {\n\t\t\tstate.bundle?.notifyBackgroundExit(id, runtime);\n\t\t},\n\t\tonMonitorRearmed: (id: string) => state.monitorNotifier?.rearm(id),\n\t};\n}\n\nfunction shouldStepAside(ctx: ExtensionContext | undefined): boolean {\n\treturn isAnthropicBashEnabled() && ctx?.model?.api === \"anthropic-messages\";\n}\n\n/**\n * Keep the tool surface consistent with anthropic-bash. When native Anthropic bash is active,\n * the provider replaces the PTY `bash` function, but the companions stay active because `monitor`\n * creates its own PTY session and bash_output/input/resize/kill operate on that shared registry.\n * Otherwise the PTY `bash` + companions are (re)activated. Re-evaluated on session_start AND\n * model_select.\n */\nfunction syncToolset(pi: ExtensionAPI, state: TerminalExtensionState): void {\n\tconst stepAside = shouldStepAside(state.ctx);\n\tconst active = new Set(pi.getActiveTools());\n\tif (stepAside) {\n\t\tfor (const companion of TERMINAL_COMPANION_TOOLS) active.add(companion);\n\t\tif (!state.noticeShown) {\n\t\t\tstate.ctx?.ui.notify(\"native Anthropic bash active — monitor sessions remain available\", \"info\");\n\t\t\tstate.noticeShown = true;\n\t\t}\n\t} else {\n\t\tactive.add(TERMINAL_BASH_TOOL);\n\t\tfor (const companion of TERMINAL_COMPANION_TOOLS) active.add(companion);\n\t\tstate.noticeShown = false;\n\t}\n\tstate.steppedAside = stepAside;\n\tpi.setActiveTools([...active]);\n}\n\nexport function registerTerminalExtension(pi: ExtensionAPI): void {\n\tconst state: TerminalExtensionState = {\n\t\tbundle: null,\n\t\tsettings: TERMINAL_SETTINGS_DEFAULTS,\n\t\tnotifier: null,\n\t\tmonitorNotifier: null,\n\t\tstatusTicker: new MonitorStatusTicker({\n\t\t\trender: (status) => {\n\t\t\t\tconst ctx = state.ctx;\n\t\t\t\tctx?.ui.setStatus(\n\t\t\t\t\tMONITOR_STATUS_KEY,\n\t\t\t\t\tstatus === undefined || ctx.mode !== \"tui\"\n\t\t\t\t\t\t? status\n\t\t\t\t\t\t: ctx.ui.theme.bg(\"selectedBg\", ctx.ui.theme.fg(\"text\", status)),\n\t\t\t\t);\n\t\t\t},\n\t\t}),\n\t\tctx: undefined,\n\t\tshellPath: undefined,\n\t\tsteppedAside: false,\n\t\tnoticeShown: false,\n\t};\n\tconst toolCtx = buildToolContext(pi, state);\n\n\tpi.registerTool(createPtyBashTool(toolCtx));\n\tpi.registerTool(createBashOutputTool(toolCtx));\n\tpi.registerTool(createBashInputTool(toolCtx));\n\tpi.registerTool(createBashResizeTool(toolCtx));\n\tpi.registerTool(createKillBashTool(toolCtx));\n\tpi.registerTool(createMonitorTool(toolCtx));\n\n\tpi.on(\"session_start\", async (event, ctx) => {\n\t\tstate.ctx = ctx;\n\t\tconst settingsManager = SettingsManager.create(ctx.cwd);\n\t\tstate.settings = loadTerminalSettings(settingsManager);\n\t\tstate.shellPath = settingsManager.getShellPath();\n\t\tstate.notifier = new TerminalNotifier({\n\t\t\tsendMessage: (message, options) => pi.sendMessage(message, options),\n\t\t\tgetContext: () => state.ctx,\n\t\t\tgetMode: () => state.settings.notify,\n\t\t});\n\t\tstate.monitorNotifier?.dispose();\n\t\tstate.monitorNotifier = new MonitorNotifier({\n\t\t\tsendMessage: (message, options) => pi.sendMessage(message, options),\n\t\t\tgetContext: () => state.ctx,\n\t\t\tgetMode: () => state.settings.notify,\n\t\t\tgetSettings: () => state.settings.monitor,\n\t\t\tpauseMonitors: () => state.bundle?.monitors.pauseAll() ?? [],\n\t\t});\n\t\tconst sessionKey = sessionKeyOf(ctx);\n\t\tif (event.reason === \"reload\") {\n\t\t\tconst claimed = sessionKey === undefined ? undefined : claimParkedBundle(sessionKey);\n\t\t\tif (claimed) {\n\t\t\t\tawait state.bundle?.teardown();\n\t\t\t\tstate.bundle = claimed;\n\t\t\t}\n\t\t} else {\n\t\t\tif (sessionKey !== undefined) await teardownParkedBundle(sessionKey);\n\t\t\tawait state.bundle?.teardown();\n\t\t\tstate.bundle = createBundle(state);\n\t\t}\n\t\tstate.bundle ??= createBundle(state);\n\t\tstate.bundle.bind(bundleSinks(pi, state));\n\t\tsyncToolset(pi, state);\n\t});\n\n\tpi.on(\"model_select\", async (event, ctx) => {\n\t\tstate.ctx = { ...ctx, model: event.model };\n\t\tsyncToolset(pi, state);\n\t});\n\n\tpi.on(\"input\", (event) => {\n\t\tif (event.source !== \"extension\") state.monitorNotifier?.noteActivity();\n\t});\n\n\tpi.on(\"tool_call\", () => {\n\t\tstate.monitorNotifier?.noteActivity();\n\t});\n\n\tpi.on(\"before_agent_start\", async (event) => {\n\t\tif (state.steppedAside) return undefined;\n\t\treturn { systemPrompt: `${event.systemPrompt}\\n${TERMINAL_PROMPT_SECTION}` };\n\t});\n\n\tpi.on(\"session_shutdown\", async (event, ctx) => {\n\t\tstate.monitorNotifier?.dispose();\n\t\tstate.monitorNotifier = null;\n\t\tstate.notifier = null;\n\t\tstate.statusTicker.stop();\n\t\tconst sessionKey = sessionKeyOf(ctx) ?? sessionKeyOf(state.ctx);\n\t\tif (event.reason === \"reload\" && state.bundle && sessionKey !== undefined) {\n\t\t\t// Keep state.bundle referenced: exit listeners captured by this instance's tool\n\t\t\t// context still route through the shared bundle after the new owner claims it.\n\t\t\tstate.bundle.park();\n\t\t\tawait parkBundle(sessionKey, state.bundle);\n\t\t\treturn;\n\t\t}\n\t\tconst bundle = state.bundle;\n\t\tstate.bundle = null;\n\t\tawait bundle?.teardown();\n\t\tif (sessionKey !== undefined) await teardownParkedBundle(sessionKey);\n\t});\n}\n\nexport default registerTerminalExtension;\n"]}
|
|
1
|
+
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/extension.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAE/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,4BAA4B,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAClG,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEtD,OAAO,EACN,iBAAiB,EACjB,UAAU,EAEV,qBAAqB,EACrB,oBAAoB,GACpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,oBAAoB,EAAiC,0BAA0B,EAAE,MAAM,eAAe,CAAC;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,CAAC;IAC9E,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,EAAE,CAAC,kBAAkB,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;QAC9C,KAAK,CAAC,eAAe,EAAE,OAAO,EAAE,CAAC;QACjC,KAAK,CAAC,eAAe,GAAG,IAAI,CAAC;QAC7B,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC;QACtB,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;QAC1B,MAAM,UAAU,GAAG,YAAY,CAAC,GAAG,CAAC,IAAI,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAChE,IAAI,KAAK,CAAC,MAAM,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;YAC3E,gFAAgF;YAChF,+EAA+E;YAC/E,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YACpB,MAAM,UAAU,CAAC,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;YAC3C,OAAO;QACR,CAAC;QACD,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;QAC5B,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC;QACpB,MAAM,MAAM,EAAE,QAAQ,EAAE,CAAC;QACzB,IAAI,UAAU,KAAK,SAAS;YAAE,MAAM,oBAAoB,CAAC,UAAU,CAAC,CAAC;IACtE,CAAC,CAAC,CAAC;AACJ,CAAC;AAED,eAAe,yBAAyB,CAAC","sourcesContent":["import { getShellEnv } from \"../../../../utils/shell.ts\";\nimport { SettingsManager } from \"../../../settings-manager.ts\";\nimport type { ExtensionAPI, ExtensionContext } from \"../../types.ts\";\nimport { isAnthropicBashEnabled } from \"../anthropic-bash/index.ts\";\nimport { TERMINAL_MONITOR_STATE_EVENT, WAKE_SOURCE_STATE_EVENT } from \"../monitor-state-event.ts\";\nimport { MonitorNotifier } from \"./monitor-notify.ts\";\nimport { MONITOR_STATUS_KEY } from \"./monitor-status.ts\";\nimport { MonitorStatusTicker } from \"./monitor-status-ticker.ts\";\nimport { TerminalNotifier } from \"./notify.ts\";\nimport { TERMINAL_PROMPT_SECTION } from \"./prompt.ts\";\nimport type { TerminalRuntimeSession } from \"./runtime-session.ts\";\nimport {\n\tclaimParkedBundle,\n\tparkBundle,\n\ttype TerminalEventSinks,\n\tTerminalSessionBundle,\n\tteardownParkedBundle,\n} from \"./session-bundle.ts\";\nimport { loadTerminalSettings, type ResolvedTerminalSettings, TERMINAL_SETTINGS_DEFAULTS } from \"./settings.ts\";\nimport { TERMINAL_BASH_TOOL, TERMINAL_COMPANION_TOOLS } from \"./shared.ts\";\nimport { createPtyBashTool } from \"./tools/bash.ts\";\nimport { createBashInputTool } from \"./tools/bash-input.ts\";\nimport { createBashOutputTool } from \"./tools/bash-output.ts\";\nimport { createBashResizeTool } from \"./tools/bash-resize.ts\";\nimport type { TerminalToolContext } from \"./tools/context.ts\";\nimport { createKillBashTool } from \"./tools/kill-bash.ts\";\nimport { createMonitorTool } from \"./tools/monitor.ts\";\n\ninterface TerminalExtensionState {\n\tbundle: TerminalSessionBundle | null;\n\tsettings: ResolvedTerminalSettings;\n\tnotifier: TerminalNotifier | null;\n\tmonitorNotifier: MonitorNotifier | null;\n\tstatusTicker: MonitorStatusTicker;\n\tctx: ExtensionContext | undefined;\n\tshellPath: string | undefined;\n\tsteppedAside: boolean;\n\tnoticeShown: boolean;\n}\n\n/** Tests and SDK callers may hand partial contexts without a session manager. */\nfunction sessionKeyOf(ctx: ExtensionContext | undefined): string | undefined {\n\treturn ctx?.sessionManager?.getSessionId?.();\n}\n\nfunction createBundle(state: TerminalExtensionState): TerminalSessionBundle {\n\treturn new TerminalSessionBundle({\n\t\tmaxSessions: state.settings.maxSessions,\n\t\tscrollback: state.settings.scrollback,\n\t});\n}\n\n/** Sinks read the live instance state at call time, so notifier swaps need no re-bind. */\nfunction bundleSinks(pi: ExtensionAPI, state: TerminalExtensionState): TerminalEventSinks {\n\treturn {\n\t\tonMonitorEvent: (event) => state.monitorNotifier?.notifyEvent(event),\n\t\tonMonitorState: (snapshot) => {\n\t\t\tstate.statusTicker.sync(snapshot);\n\t\t\tconst payload = {\n\t\t\t\tactiveCount: snapshot.length,\n\t\t\t\tmonitors: snapshot.map((entry) => ({\n\t\t\t\t\tid: entry.id,\n\t\t\t\t\tdescription: entry.description,\n\t\t\t\t\tpaused: entry.paused,\n\t\t\t\t\tstartedAtMs: entry.startedAtMs,\n\t\t\t\t})),\n\t\t\t};\n\t\t\tpi.events?.emit(TERMINAL_MONITOR_STATE_EVENT, payload);\n\t\t\tpi.rpc?.emit(TERMINAL_MONITOR_STATE_EVENT, payload);\n\t\t\tpi.events?.emit(WAKE_SOURCE_STATE_EVENT, {\n\t\t\t\tsource: \"terminal-monitors\",\n\t\t\t\tactiveCount: snapshot.length,\n\t\t\t\tmonitors: snapshot.map((entry) => ({\n\t\t\t\t\tid: entry.id,\n\t\t\t\t\tdescription: entry.description,\n\t\t\t\t\tstartedAtMs: entry.startedAtMs,\n\t\t\t\t})),\n\t\t\t});\n\t\t},\n\t\tonBackgroundState: (snapshot) => {\n\t\t\tpi.events?.emit(WAKE_SOURCE_STATE_EVENT, {\n\t\t\t\tsource: \"terminal-background-sessions\",\n\t\t\t\tactiveCount: snapshot.length,\n\t\t\t\titems: snapshot,\n\t\t\t});\n\t\t},\n\t\tonBackgroundExit: (id, runtime) => state.notifier?.notifyCompletion(id, runtime),\n\t};\n}\n\nfunction buildToolContext(pi: ExtensionAPI, state: TerminalExtensionState): TerminalToolContext {\n\tconst requireBundle = (): TerminalSessionBundle => {\n\t\t// Lazily create a bundle so the tools work even when invoked directly (e.g. via the\n\t\t// SDK) before `session_start` initializes one. `session_start` replaces it with a\n\t\t// settings-configured bundle and tears down any earlier one.\n\t\tif (!state.bundle) {\n\t\t\tstate.bundle = createBundle(state);\n\t\t\tstate.bundle.bind(bundleSinks(pi, state));\n\t\t}\n\t\treturn state.bundle;\n\t};\n\treturn {\n\t\tget manager() {\n\t\t\treturn requireBundle().manager;\n\t\t},\n\t\tget cwd() {\n\t\t\treturn state.ctx?.cwd ?? process.cwd();\n\t\t},\n\t\tget shellPath() {\n\t\t\treturn state.shellPath;\n\t\t},\n\t\tget defaultCols() {\n\t\t\treturn state.settings.defaultCols;\n\t\t},\n\t\tget defaultRows() {\n\t\t\treturn state.settings.defaultRows;\n\t\t},\n\t\tget timeoutAction() {\n\t\t\treturn state.settings.timeoutAction;\n\t\t},\n\t\tget monitorRegistry() {\n\t\t\treturn requireBundle().monitors;\n\t\t},\n\t\tgetEnv: () => getShellEnv(),\n\t\tgetSessionContext: () => state.ctx,\n\t\t// Exit listeners registered before a reload reach the post-reload owner through the\n\t\t// shared bundle, so this must dispatch via the bundle, never the instance notifier.\n\t\tonBackgroundStart: (id: string, description: string, startedAtMs: number) => {\n\t\t\tstate.bundle?.notifyBackgroundStart(id, description, startedAtMs);\n\t\t},\n\t\tonBackgroundExit: (id: string, runtime: TerminalRuntimeSession) => {\n\t\t\tstate.bundle?.notifyBackgroundExit(id, runtime);\n\t\t},\n\t\tonMonitorRearmed: (id: string) => state.monitorNotifier?.rearm(id),\n\t};\n}\n\nfunction shouldStepAside(ctx: ExtensionContext | undefined): boolean {\n\treturn isAnthropicBashEnabled() && ctx?.model?.api === \"anthropic-messages\";\n}\n\n/**\n * Keep the tool surface consistent with anthropic-bash. When native Anthropic bash is active,\n * the provider replaces the PTY `bash` function, but the companions stay active because `monitor`\n * creates its own PTY session and bash_output/input/resize/kill operate on that shared registry.\n * Otherwise the PTY `bash` + companions are (re)activated. Re-evaluated on session_start AND\n * model_select.\n */\nfunction syncToolset(pi: ExtensionAPI, state: TerminalExtensionState): void {\n\tconst stepAside = shouldStepAside(state.ctx);\n\tconst active = new Set(pi.getActiveTools());\n\tif (stepAside) {\n\t\tfor (const companion of TERMINAL_COMPANION_TOOLS) active.add(companion);\n\t\tif (!state.noticeShown) {\n\t\t\tstate.ctx?.ui.notify(\"native Anthropic bash active — monitor sessions remain available\", \"info\");\n\t\t\tstate.noticeShown = true;\n\t\t}\n\t} else {\n\t\tactive.add(TERMINAL_BASH_TOOL);\n\t\tfor (const companion of TERMINAL_COMPANION_TOOLS) active.add(companion);\n\t\tstate.noticeShown = false;\n\t}\n\tstate.steppedAside = stepAside;\n\tpi.setActiveTools([...active]);\n}\n\nexport function registerTerminalExtension(pi: ExtensionAPI): void {\n\tconst state: TerminalExtensionState = {\n\t\tbundle: null,\n\t\tsettings: TERMINAL_SETTINGS_DEFAULTS,\n\t\tnotifier: null,\n\t\tmonitorNotifier: null,\n\t\tstatusTicker: new MonitorStatusTicker({\n\t\t\trender: (status) => {\n\t\t\t\tconst ctx = state.ctx;\n\t\t\t\tctx?.ui.setStatus(\n\t\t\t\t\tMONITOR_STATUS_KEY,\n\t\t\t\t\tstatus === undefined || ctx.mode !== \"tui\"\n\t\t\t\t\t\t? status\n\t\t\t\t\t\t: ctx.ui.theme.bg(\"selectedBg\", ctx.ui.theme.fg(\"text\", status)),\n\t\t\t\t);\n\t\t\t},\n\t\t}),\n\t\tctx: undefined,\n\t\tshellPath: undefined,\n\t\tsteppedAside: false,\n\t\tnoticeShown: false,\n\t};\n\tconst toolCtx = buildToolContext(pi, state);\n\n\tpi.registerTool(createPtyBashTool(toolCtx));\n\tpi.registerTool(createBashOutputTool(toolCtx));\n\tpi.registerTool(createBashInputTool(toolCtx));\n\tpi.registerTool(createBashResizeTool(toolCtx));\n\tpi.registerTool(createKillBashTool(toolCtx));\n\tpi.registerTool(createMonitorTool(toolCtx));\n\n\tpi.on(\"session_start\", async (event, ctx) => {\n\t\tstate.ctx = ctx;\n\t\tconst settingsManager = SettingsManager.create(ctx.cwd);\n\t\tstate.settings = loadTerminalSettings(settingsManager);\n\t\tstate.shellPath = settingsManager.getShellPath();\n\t\tstate.notifier = new TerminalNotifier({\n\t\t\tsendMessage: (message, options) => pi.sendMessage(message, options),\n\t\t\tgetContext: () => state.ctx,\n\t\t\tgetMode: () => state.settings.notify,\n\t\t});\n\t\tstate.monitorNotifier?.dispose();\n\t\tstate.monitorNotifier = new MonitorNotifier({\n\t\t\tsendMessage: (message, options) => pi.sendMessage(message, options),\n\t\t\tgetContext: () => state.ctx,\n\t\t\tgetMode: () => state.settings.notify,\n\t\t\tgetSettings: () => state.settings.monitor,\n\t\t\tpauseMonitors: () => state.bundle?.monitors.pauseAll() ?? [],\n\t\t});\n\t\tconst sessionKey = sessionKeyOf(ctx);\n\t\tif (event.reason === \"reload\") {\n\t\t\tconst claimed = sessionKey === undefined ? undefined : claimParkedBundle(sessionKey);\n\t\t\tif (claimed) {\n\t\t\t\tawait state.bundle?.teardown();\n\t\t\t\tstate.bundle = claimed;\n\t\t\t}\n\t\t} else {\n\t\t\tif (sessionKey !== undefined) await teardownParkedBundle(sessionKey);\n\t\t\tawait state.bundle?.teardown();\n\t\t\tstate.bundle = createBundle(state);\n\t\t}\n\t\tstate.bundle ??= createBundle(state);\n\t\tstate.bundle.bind(bundleSinks(pi, state));\n\t\tsyncToolset(pi, state);\n\t});\n\n\tpi.on(\"model_select\", async (event, ctx) => {\n\t\tstate.ctx = { ...ctx, model: event.model };\n\t\tsyncToolset(pi, state);\n\t});\n\n\tpi.on(\"input\", (event) => {\n\t\tif (event.source !== \"extension\") state.monitorNotifier?.noteActivity();\n\t});\n\n\tpi.on(\"tool_call\", () => {\n\t\tstate.monitorNotifier?.noteActivity();\n\t});\n\n\tpi.on(\"before_agent_start\", async (event) => {\n\t\tif (state.steppedAside) return undefined;\n\t\treturn { systemPrompt: `${event.systemPrompt}\\n${TERMINAL_PROMPT_SECTION}` };\n\t});\n\n\tpi.on(\"session_shutdown\", async (event, ctx) => {\n\t\tstate.monitorNotifier?.dispose();\n\t\tstate.monitorNotifier = null;\n\t\tstate.notifier = null;\n\t\tstate.statusTicker.stop();\n\t\tconst sessionKey = sessionKeyOf(ctx) ?? sessionKeyOf(state.ctx);\n\t\tif (event.reason === \"reload\" && state.bundle && sessionKey !== undefined) {\n\t\t\t// Keep state.bundle referenced: exit listeners captured by this instance's tool\n\t\t\t// context still route through the shared bundle after the new owner claims it.\n\t\t\tstate.bundle.park();\n\t\t\tawait parkBundle(sessionKey, state.bundle);\n\t\t\treturn;\n\t\t}\n\t\tconst bundle = state.bundle;\n\t\tstate.bundle = null;\n\t\tawait bundle?.teardown();\n\t\tif (sessionKey !== undefined) await teardownParkedBundle(sessionKey);\n\t});\n}\n\nexport default registerTerminalExtension;\n"]}
|
|
@@ -1674,10 +1674,10 @@ export declare const validateModelsConfig: import("typebox/compile").Validator<{
|
|
|
1674
1674
|
env?: string | undefined;
|
|
1675
1675
|
value?: string | undefined;
|
|
1676
1676
|
}> | undefined;
|
|
1677
|
-
rotation?: boolean | undefined;
|
|
1678
|
-
affinity?: boolean | undefined;
|
|
1679
1677
|
cooldownBaseMs?: number | undefined;
|
|
1680
1678
|
cooldownCapMs?: number | undefined;
|
|
1679
|
+
affinity?: boolean | undefined;
|
|
1680
|
+
rotation?: boolean | undefined;
|
|
1681
1681
|
} | undefined;
|
|
1682
1682
|
}>;
|
|
1683
1683
|
}, {
|
|
@@ -2028,10 +2028,10 @@ export declare const validateModelsConfig: import("typebox/compile").Validator<{
|
|
|
2028
2028
|
env?: string | undefined;
|
|
2029
2029
|
value?: string | undefined;
|
|
2030
2030
|
}> | undefined;
|
|
2031
|
-
rotation?: boolean | undefined;
|
|
2032
|
-
affinity?: boolean | undefined;
|
|
2033
2031
|
cooldownBaseMs?: number | undefined;
|
|
2034
2032
|
cooldownCapMs?: number | undefined;
|
|
2033
|
+
affinity?: boolean | undefined;
|
|
2034
|
+
rotation?: boolean | undefined;
|
|
2035
2035
|
} | undefined;
|
|
2036
2036
|
}>;
|
|
2037
2037
|
}>;
|
|
@@ -4,6 +4,7 @@ export interface CreateModelRuntimeOptions {
|
|
|
4
4
|
/** Credential storage. Defaults to the file at authPath. */
|
|
5
5
|
credentials?: CredentialStore;
|
|
6
6
|
authPath?: string;
|
|
7
|
+
agentDir?: string;
|
|
7
8
|
modelsPath?: string | null;
|
|
8
9
|
modelsStore?: ModelsStore;
|
|
9
10
|
modelsStorePath?: string;
|
|
@@ -68,6 +69,7 @@ export declare class ModelRuntime implements Models {
|
|
|
68
69
|
* validator - and its module-level global registry - into every consumer of
|
|
69
70
|
* ModelRuntime, which the import-graph guard forbids.
|
|
70
71
|
*/
|
|
72
|
+
private readonly poolStatePath;
|
|
71
73
|
private credentialPoolModules;
|
|
72
74
|
private constructor();
|
|
73
75
|
static create(options?: CreateModelRuntimeOptions): Promise<ModelRuntime>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-runtime.d.ts","sourceRoot":"","sources":["../../src/core/model-runtime.ts"],"names":[],"mappings":"AACA,OAAO,EACN,KAAK,GAAG,EAER,KAAK,gBAAgB,EACrB,KAAK,2BAA2B,EAChC,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,UAAU,EACf,KAAK,QAAQ,EACb,KAAK,OAAO,EACZ,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,eAAe,EAIpB,KAAK,cAAc,
|
|
1
|
+
{"version":3,"file":"model-runtime.d.ts","sourceRoot":"","sources":["../../src/core/model-runtime.ts"],"names":[],"mappings":"AACA,OAAO,EACN,KAAK,GAAG,EAER,KAAK,gBAAgB,EACrB,KAAK,2BAA2B,EAChC,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,UAAU,EACf,KAAK,QAAQ,EACb,KAAK,OAAO,EACZ,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,eAAe,EAIpB,KAAK,cAAc,EAEnB,KAAK,KAAK,EACV,KAAK,MAAM,EACX,KAAK,sBAAsB,EAC3B,KAAK,2BAA2B,EAChC,KAAK,0BAA0B,EAE/B,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,uBAAuB,EAC5B,KAAK,yBAAyB,EAC9B,KAA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mB,CAAC;IAgBzG,gBAAgB,CACf,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,mBAAmB,EAC3B,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,GAC7B,OAAO,CAAC,mBAAmB,CAAC;IA6C/B,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;CAQ5C"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { dirname, join } from "node:path";
|
|
2
|
-
import { createModels,
|
|
2
|
+
import { createModels, lazyStream, ModelsError, setWireIdentity, wrapStreamWithModelRecovery, } from "@earendil-works/pi-ai";
|
|
3
3
|
import * as builtinProviderCatalog from "@earendil-works/pi-ai/providers/all";
|
|
4
4
|
import { APP_NAME, BRAND, getAgentDir } from "../config.js";
|
|
5
5
|
import { operationSignal, raceWithAbortSignal } from "../utils/abort.js";
|
|
6
6
|
import { AuthStorage as DefaultAuthStorage } from "./auth-storage.js";
|
|
7
7
|
import { envValue } from "./brand.js";
|
|
8
|
+
import { discoverEnvSlots } from "./credential-pool/env-slots.js";
|
|
8
9
|
import { ModelConfig } from "./model-config.js";
|
|
9
10
|
import { FileModelsStore, InMemoryCodingAgentModelsStore } from "./models-store.js";
|
|
10
11
|
import { composeModelProvider, configuredRequestAuthStatus, resolveCompatibilityRequestConfig, resolveConfiguredModelHeaders, validateExtensionProvider, } from "./provider-composer.js";
|
|
@@ -13,30 +14,12 @@ import { RuntimeCredentials } from "./runtime-credentials.js";
|
|
|
13
14
|
// The product's identity must ride outgoing requests. This lives here because the AI package
|
|
14
15
|
// is already part of this module's graph; the CLI bootstrap deliberately does not import it.
|
|
15
16
|
setWireIdentity(BRAND?.userAgent ?? APP_NAME);
|
|
16
|
-
|
|
17
|
-
* Cheap pre-check answering "could this provider hold more than one credential
|
|
18
|
-
* at all?" without loading the credential pool. A stored entry pools only
|
|
19
|
-
* through `accounts`; env slots participate only when nothing is stored, and a
|
|
20
|
-
* lone primary variable is still a single credential.
|
|
21
|
-
*/
|
|
22
|
-
function mightHoldEnvCredentialPool(providerId, env) {
|
|
23
|
-
const envVars = getApiKeyEnvVars(providerId);
|
|
24
|
-
const primary = envVars?.find((name) => name.endsWith("_API_KEY")) ?? envVars?.[0];
|
|
25
|
-
if (primary === undefined)
|
|
26
|
-
return false;
|
|
27
|
-
let found = env(primary) ? 1 : 0;
|
|
28
|
-
for (let index = 2; index <= 16 && found < 2; index++) {
|
|
29
|
-
if (env(`${primary}_${index}`))
|
|
30
|
-
found++;
|
|
31
|
-
}
|
|
32
|
-
return found > 1;
|
|
33
|
-
}
|
|
34
|
-
function mightHoldCredentialPool(providerId, credential, env) {
|
|
17
|
+
function mightHoldCredentialPool(providerId, credential, env, policySlots) {
|
|
35
18
|
if (credential) {
|
|
36
19
|
const accounts = Object.entries(credential).find(([key]) => key === "accounts")?.[1];
|
|
37
|
-
return Array.isArray(accounts) && accounts.length > 1;
|
|
20
|
+
return (Array.isArray(accounts) && accounts.length > 1) || Object.keys(policySlots ?? {}).length > 0;
|
|
38
21
|
}
|
|
39
|
-
return
|
|
22
|
+
return discoverEnvSlots(providerId, env).length + Object.keys(policySlots ?? {}).length > 1;
|
|
40
23
|
}
|
|
41
24
|
/** Credentials changed successfully, but the local model/auth snapshot could not be synchronized. */
|
|
42
25
|
export class CredentialSynchronizationError extends Error {
|
|
@@ -68,12 +51,15 @@ function withPayloadRequestMetadata(options, model) {
|
|
|
68
51
|
const onPayload = options.onPayload;
|
|
69
52
|
return {
|
|
70
53
|
...options,
|
|
71
|
-
onPayload: async (payload, providerModel) => await onPayload(payload, providerModel, {
|
|
54
|
+
onPayload: async (payload, providerModel) => await onPayload(payload, providerModel, {
|
|
55
|
+
model,
|
|
56
|
+
headers: options.headers ?? {},
|
|
57
|
+
}),
|
|
72
58
|
};
|
|
73
59
|
}
|
|
74
60
|
/** Configured pi-ai Models collection used by coding-agent and SDK consumers. */
|
|
75
61
|
export class ModelRuntime {
|
|
76
|
-
constructor(credentials, config, modelsPath, modelsStore, providers, modelNetworkEnabled, modelRefreshTimeoutMs) {
|
|
62
|
+
constructor(credentials, config, modelsPath, modelsStore, providers, modelNetworkEnabled, modelRefreshTimeoutMs, poolStatePath) {
|
|
77
63
|
this.builtins = new Map();
|
|
78
64
|
this.nativeExtensionProviders = new Map();
|
|
79
65
|
this.extensionProviders = new Map();
|
|
@@ -91,6 +77,7 @@ export class ModelRuntime {
|
|
|
91
77
|
this.providerAvailabilitySeq = new Map();
|
|
92
78
|
this.credentialOperations = new Map();
|
|
93
79
|
this.credentials = credentials;
|
|
80
|
+
this.poolStatePath = poolStatePath;
|
|
94
81
|
this.config = config;
|
|
95
82
|
this.modelsPath = modelsPath;
|
|
96
83
|
this.modelNetworkEnabled = modelNetworkEnabled;
|
|
@@ -115,7 +102,11 @@ export class ModelRuntime {
|
|
|
115
102
|
.map((provider) => provider.refreshModels || !remoteCatalogServesProvider(provider.id, options.catalogBaseUrl)
|
|
116
103
|
? provider
|
|
117
104
|
: withRemoteCatalog(provider, options.catalogBaseUrl, builtinModelDataGeneratedAt));
|
|
118
|
-
const runtime = new ModelRuntime(credentials, config, modelsPath, modelsStore, providers, envValue("OFFLINE") === undefined && options.allowModelNetwork === true, options.modelRefreshTimeoutMs ?? 15_000
|
|
105
|
+
const runtime = new ModelRuntime(credentials, config, modelsPath, modelsStore, providers, envValue("OFFLINE") === undefined && options.allowModelNetwork === true, options.modelRefreshTimeoutMs ?? 15_000, options.agentDir
|
|
106
|
+
? join(options.agentDir, "credential-pool-state.json")
|
|
107
|
+
: options.authPath
|
|
108
|
+
? join(dirname(options.authPath), "credential-pool-state.json")
|
|
109
|
+
: undefined);
|
|
119
110
|
runtime.rebuildProviders();
|
|
120
111
|
const refreshFromNetwork = runtime.modelNetworkEnabled && options.allowModelNetwork === true;
|
|
121
112
|
const controller = refreshFromNetwork && options.modelRefreshTimeoutMs !== undefined ? new AbortController() : undefined;
|
|
@@ -150,7 +141,11 @@ export class ModelRuntime {
|
|
|
150
141
|
.map((provider) => provider.refreshModels || !remoteCatalogServesProvider(provider.id, options.catalogBaseUrl)
|
|
151
142
|
? provider
|
|
152
143
|
: withRemoteCatalog(provider, options.catalogBaseUrl));
|
|
153
|
-
const runtime = new ModelRuntime(credentials, config, modelsPath, modelsStore, providers, options.allowModelNetwork ?? false, options.modelRefreshTimeoutMs ?? 15_000
|
|
144
|
+
const runtime = new ModelRuntime(credentials, config, modelsPath, modelsStore, providers, options.allowModelNetwork ?? false, options.modelRefreshTimeoutMs ?? 15_000, options.agentDir
|
|
145
|
+
? join(options.agentDir, "credential-pool-state.json")
|
|
146
|
+
: options.authPath
|
|
147
|
+
? join(dirname(options.authPath), "credential-pool-state.json")
|
|
148
|
+
: undefined);
|
|
154
149
|
runtime.rebuildProviders();
|
|
155
150
|
return runtime;
|
|
156
151
|
}
|
|
@@ -440,7 +435,11 @@ export class ModelRuntime {
|
|
|
440
435
|
const compositionError = this.compositionErrors.get(providerId);
|
|
441
436
|
if (compositionError)
|
|
442
437
|
throw new Error(compositionError);
|
|
443
|
-
const result = await this.models.refresh({
|
|
438
|
+
const result = await this.models.refresh({
|
|
439
|
+
allowNetwork: false,
|
|
440
|
+
providers: [providerId],
|
|
441
|
+
signal,
|
|
442
|
+
});
|
|
444
443
|
if (result.aborted)
|
|
445
444
|
signal.throwIfAborted();
|
|
446
445
|
const refreshError = result.errors.get(providerId);
|
|
@@ -537,7 +536,10 @@ export class ModelRuntime {
|
|
|
537
536
|
import("./credential-pool/rotation-stream.js"),
|
|
538
537
|
import("./credential-pool/state-store.js"),
|
|
539
538
|
]);
|
|
540
|
-
return {
|
|
539
|
+
return {
|
|
540
|
+
rotation,
|
|
541
|
+
repository: new stateStore.CredentialSlotRepository(this.poolStatePath),
|
|
542
|
+
};
|
|
541
543
|
})();
|
|
542
544
|
return this.credentialPoolModules;
|
|
543
545
|
}
|
|
@@ -557,12 +559,16 @@ export class ModelRuntime {
|
|
|
557
559
|
const env = (name) => options?.env?.[name] ?? process.env[name];
|
|
558
560
|
if (this.snapshot.storedProviders.has(model.provider))
|
|
559
561
|
return true;
|
|
560
|
-
|
|
562
|
+
const policySlots = this.config.getProvider(model.provider)?.credentials?.slots;
|
|
563
|
+
return discoverEnvSlots(model.provider, env).length + Object.keys(policySlots ?? {}).length > 1;
|
|
561
564
|
}
|
|
562
565
|
async credentialRotationSources(model, options) {
|
|
563
566
|
const env = (name) => options?.env?.[name] ?? process.env[name];
|
|
564
|
-
const credential = await this.credentials.read(model.provider, {
|
|
565
|
-
|
|
567
|
+
const credential = await this.credentials.read(model.provider, {
|
|
568
|
+
signal: options?.signal,
|
|
569
|
+
});
|
|
570
|
+
const policy = this.config.getProvider(model.provider)?.credentials;
|
|
571
|
+
if (!mightHoldCredentialPool(model.provider, credential, env, policy?.slots))
|
|
566
572
|
return undefined;
|
|
567
573
|
const pool = await this.loadCredentialPool();
|
|
568
574
|
const sources = {
|
|
@@ -570,8 +576,9 @@ export class ModelRuntime {
|
|
|
570
576
|
credential,
|
|
571
577
|
env,
|
|
572
578
|
repository: pool.repository,
|
|
579
|
+
policy,
|
|
573
580
|
};
|
|
574
|
-
const slots = await pool.rotation.listRotationSlots(sources);
|
|
581
|
+
const slots = await pool.rotation.listRotationSlots(sources, { acquireLeases: false });
|
|
575
582
|
return slots.length > 1 ? sources : undefined;
|
|
576
583
|
}
|
|
577
584
|
stream(model, context, options) {
|
|
@@ -584,10 +591,16 @@ export class ModelRuntime {
|
|
|
584
591
|
const { rotation } = await this.loadCredentialPool();
|
|
585
592
|
return rotation.streamWithCredentialRotation({
|
|
586
593
|
sources,
|
|
587
|
-
...(streamOptions?.affinityKey
|
|
594
|
+
...(streamOptions?.affinityKey !== undefined
|
|
595
|
+
? { affinityKey: streamOptions.affinityKey }
|
|
596
|
+
: streamOptions?.sessionId !== undefined
|
|
597
|
+
? { affinityKey: streamOptions.sessionId }
|
|
598
|
+
: {}),
|
|
588
599
|
runAttempt: async (slot) => {
|
|
589
600
|
const prepared = await this.prepareRequest(model, streamOptions, slot.lane === "env"
|
|
590
|
-
? {
|
|
601
|
+
? {
|
|
602
|
+
...(slot.envKey === undefined ? {} : { apiKey: slot.envKey }),
|
|
603
|
+
}
|
|
591
604
|
: { slotName: slot.name });
|
|
592
605
|
const attempt = prepared.provider.stream(prepared.model, context, withPayloadRequestMetadata(prepared.options, prepared.model));
|
|
593
606
|
return wrapStreamWithModelRecovery(attempt, model, context.tools ?? []);
|
|
@@ -604,6 +617,21 @@ export class ModelRuntime {
|
|
|
604
617
|
}
|
|
605
618
|
streamSimple(model, context, options) {
|
|
606
619
|
return lazyStream(model, async () => {
|
|
620
|
+
const streamOptions = options;
|
|
621
|
+
const sources = this.couldRotateCredentials(model, streamOptions)
|
|
622
|
+
? await this.credentialRotationSources(model, streamOptions)
|
|
623
|
+
: undefined;
|
|
624
|
+
if (sources) {
|
|
625
|
+
const { rotation } = await this.loadCredentialPool();
|
|
626
|
+
return rotation.streamWithCredentialRotation({
|
|
627
|
+
sources,
|
|
628
|
+
...(streamOptions?.sessionId === undefined ? {} : { affinityKey: streamOptions.sessionId }),
|
|
629
|
+
runAttempt: async (slot) => {
|
|
630
|
+
const prepared = await this.prepareRequest(model, streamOptions, slot.lane === "env" ? { apiKey: slot.envKey } : { slotName: slot.name });
|
|
631
|
+
return wrapStreamWithModelRecovery(prepared.provider.streamSimple(prepared.model, context, withPayloadRequestMetadata(prepared.options, prepared.model)), model, context.tools ?? []);
|
|
632
|
+
},
|
|
633
|
+
});
|
|
634
|
+
}
|
|
607
635
|
const prepared = await this.prepareRequest(model, options);
|
|
608
636
|
const inner = prepared.provider.streamSimple(prepared.model, context, withPayloadRequestMetadata(prepared.options, prepared.model));
|
|
609
637
|
return wrapStreamWithModelRecovery(inner, model, context.tools ?? []);
|
|
@@ -631,7 +659,10 @@ export class ModelRuntime {
|
|
|
631
659
|
login(providerId, type, interaction) {
|
|
632
660
|
const signal = operationSignal(interaction.signal);
|
|
633
661
|
return this.enqueueCredentialOperation(providerId, signal, async () => {
|
|
634
|
-
const credential = await this.models.login(providerId, type, {
|
|
662
|
+
const credential = await this.models.login(providerId, type, {
|
|
663
|
+
...interaction,
|
|
664
|
+
signal,
|
|
665
|
+
});
|
|
635
666
|
await this.synchronizeCredentialState(providerId, "login", credential, signal);
|
|
636
667
|
return credential;
|
|
637
668
|
});
|
|
@@ -688,7 +719,10 @@ export class ModelRuntime {
|
|
|
688
719
|
// Availability errors are recorded by the latest pass; refreshed models remain usable.
|
|
689
720
|
}
|
|
690
721
|
}
|
|
691
|
-
return {
|
|
722
|
+
return {
|
|
723
|
+
aborted: result.aborted || (options.signal?.aborted ?? false),
|
|
724
|
+
errors,
|
|
725
|
+
};
|
|
692
726
|
}
|
|
693
727
|
/**
|
|
694
728
|
* Providers registered after startup missed the create() refresh. Load their catalogs
|
|
@@ -705,7 +739,10 @@ export class ModelRuntime {
|
|
|
705
739
|
return this.refresh({ allowNetwork: false });
|
|
706
740
|
const controller = new AbortController();
|
|
707
741
|
const timeout = setTimeout(() => controller.abort(), this.modelRefreshTimeoutMs);
|
|
708
|
-
return this.refresh({
|
|
742
|
+
return this.refresh({
|
|
743
|
+
allowNetwork: true,
|
|
744
|
+
signal: controller.signal,
|
|
745
|
+
}).finally(() => clearTimeout(timeout));
|
|
709
746
|
}
|
|
710
747
|
registerNativeProvider(provider, options) {
|
|
711
748
|
if (!provider.id.trim())
|