@bastani/atomic 0.9.41-alpha.1 → 0.9.41-alpha.3
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 +39 -0
- package/dist/builtin/intercom/package.json +2 -2
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/package.json +3 -3
- package/dist/builtin/web-access/package.json +2 -2
- package/dist/builtin/workflows/CHANGELOG.md +8 -0
- package/dist/builtin/workflows/builtin/adversarial-verification.js +2 -2
- package/dist/builtin/workflows/builtin/{chunk-qjqn389g.js → chunk-2jfst7e4.js} +72 -10
- package/dist/builtin/workflows/builtin/{chunk-4bwtzyjq.js → chunk-49kkbdpr.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-qdd897wm.js → chunk-apagcs4r.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-454hz1qt.js → chunk-dcxscfnb.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-bjva9j5k.js → chunk-hx8v4p97.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-85mx6wcf.js → chunk-k5q3t7je.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-8kkv04hz.js → chunk-n2gkzkty.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-y45tkftg.js → chunk-txbc93t6.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-x0vvjyzg.js → chunk-w4xp1w1f.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-5eh0brtd.js → chunk-z3pajrfs.js} +1 -1
- package/dist/builtin/workflows/builtin/classify-and-act.js +2 -2
- package/dist/builtin/workflows/builtin/fan-out-and-synthesize.js +2 -2
- package/dist/builtin/workflows/builtin/generate-and-filter.js +2 -2
- package/dist/builtin/workflows/builtin/goal.js +2 -2
- package/dist/builtin/workflows/builtin/index.js +10 -10
- package/dist/builtin/workflows/builtin/loop-until-done.js +2 -2
- package/dist/builtin/workflows/builtin/open-claude-design.js +2 -2
- package/dist/builtin/workflows/builtin/ralph.js +2 -2
- package/dist/builtin/workflows/builtin/tournament.js +2 -2
- package/dist/builtin/workflows/package.json +2 -2
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +511 -28
- package/dist/builtin/workflows/src/index.js +582 -99
- package/dist/core/compaction/compaction-runner.d.ts.map +1 -1
- package/dist/core/compaction/compaction-runner.js +1 -0
- package/dist/core/compaction/compaction-runner.js.map +1 -1
- package/dist/core/model-config.d.ts +28 -0
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/provider-composer-internal.d.ts +2 -1
- package/dist/core/provider-composer-internal.d.ts.map +1 -1
- package/dist/core/provider-composer-internal.js +8 -6
- package/dist/core/provider-composer-internal.js.map +1 -1
- package/dist/core/tools/grep.js +1 -1
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/usage-totals.d.ts.map +1 -1
- package/dist/core/usage-totals.js +2 -0
- package/dist/core/usage-totals.js.map +1 -1
- package/docs/getting-started/installation.md +19 -1
- package/docs/models-configuration.md +9 -0
- package/docs/models.md +3 -1
- package/docs/providers.md +1 -1
- package/docs/quickstart.md +1 -1
- package/docs/windows.md +1 -1
- package/docs/workflows/authoring.md +1 -1
- package/npm-shrinkwrap.json +67 -54
- package/package.json +6 -6
- package/schemas/models.schema.json +21 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compaction-runner.d.ts","sourceRoot":"","sources":["../../../src/core/compaction/compaction-runner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC7E,OAAO,KAAK,EAAE,YAAY,E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AAS,CAAC;IACzD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE;QAAE,SAAS,EAAE,MAAM,EAAE,CAAC;QAAC,aAAa,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;IAC3D,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC7B,CAAC;AA+BF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAAC,WAAW,EAAE,6BAA6B,GAAG,MAAM,CAGlF;AAwDD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,6BAA6B,GAAG,mBAAmB,CAErG;AA4ID;;;;;;;;;;;GAWG;AACH,wBAAsB,qBAAqB,CAC1C,WAAW,EAAE,6BAA6B,EAC1C,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EACjB,OAAO,EAAE,oBAAoB,GAC3B,OAAO,CAAC,oBAAoB,CAAC,CA+J/B"}
|
|
@@ -26,6 +26,7 @@ function addUsage(total, usage) {
|
|
|
26
26
|
cacheRead: (total?.cost.cacheRead ?? 0) + usage.cost.cacheRead,
|
|
27
27
|
cacheWrite: (total?.cost.cacheWrite ?? 0) + usage.cost.cacheWrite,
|
|
28
28
|
total: (total?.cost.total ?? 0) + usage.cost.total,
|
|
29
|
+
totalFromProvider: (total === undefined || total.cost.totalFromProvider === true) && usage.cost.totalFromProvider === true,
|
|
29
30
|
},
|
|
30
31
|
};
|
|
31
32
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compaction-runner.js","sourceRoot":"","sources":["../../../src/core/compaction/compaction-runner.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AAU9F,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC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AAC,CAAC;AAC/D,CAAC","sourcesContent":["import type {\n\tClassifierApi,\n\tClassifierContext,\n\tClassifierModel,\n\tClassifierOptions,\n\tClassifierResult,\n\tRetryCallbacks,\n\tRetryPolicy,\n} from \"@bastani/pi-ai\";\nimport type { Api, Model, Usage } from \"@bastani/pi-ai/compat\";\nimport type { StreamFn, ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport type { SessionEntry } from \"../session-manager-types.ts\";\nimport { planClassifierRanges } from \"./classifier-compaction.js\";\nimport { getKeptTailTokenEstimate, hasKeptTailTokenEstimate } from \"./compaction-boundary.js\";\nimport type {\n\tBorrowedPlanner,\n\tCompactedTranscript,\n\tCompactionPlannerModel,\n\tCompactionUrgency,\n\tPlannerAuth,\n\tRawLineRange,\n\tVerbatimCompactionPreparation,\n} from \"./compaction-types.js\";\nimport { MIN_COMPACTABLE_REGION_LINES } from \"./compaction-types.js\";\nimport { reconstructCompactedTranscript, validateDeletedRanges } from \"./deleted-ranges.js\";\nimport {\n\ttype BorrowFallbackPlanner,\n\tcreateFallbackPlannerBorrower,\n\ttype FallbackPlannerContext,\n\tplannerAttemptKey,\n} from \"./fallback-planner.js\";\nimport type { CompactionModelSelection } from \"./model-resolver.js\";\nimport { planMorphRanges } from \"./morph-compaction.js\";\nimport { runPiSummaryFallback } from \"./pi-summary-fallback.js\";\nimport type { TerminalPlannerOutcome } from \"./planner-outcome.js\";\nimport {\n\tMALFORMED_OUTPUT_MESSAGE,\n\tNO_USABLE_RANGES_MESSAGE,\n\tplanDeletedLineRanges,\n\tRangePlanError,\n\tresolvePlannerRequest,\n} from \"./range-planner.js\";\nimport { writeMorphDiagnosticSidecar, writeSuccessDiagnosticSidecar } from \"./range-planner-diagnostics.js\";\nimport { nextTrimOffset, rebaseTrimmedRanges, trimRegionHead } from \"./region-trimming.js\";\nimport { widenToWholeContextStats } from \"./whole-context-stats.js\";\n\nexport interface CompactionPlanOptions {\n\tstreamFn: StreamFn;\n\t/** Absolute path of the persisted session file. Undefined for in-memory sessions. */\n\tsessionFilePath?: string;\n\tretry?: RetryPolicy;\n\tcallbacks?: RetryCallbacks;\n}\n\n/** One compaction run's request. Urgency is required; there is no default. */\nexport interface CompactionRunRequest extends CompactionPlanOptions {\n\t/** Per-model credentials; a borrowed candidate uses its own, never the session model's. */\n\tresolveAuth: (model: Model<Api>) => Promise<PlannerAuth | undefined>;\n\tsignal?: AbortSignal;\n\t/** Inherited by the planner and never modified across attempts. */\n\tthinkingLevel: ThinkingLevel | undefined;\n\turgency: CompactionUrgency;\n\t/** Configured fallback candidates. Omitted means borrowing is impossible. */\n\tfallback?: FallbackPlannerContext;\n\tcompactionModel?: CompactionModelSelection;\n\tresolveMorphApiKey?: () => Promise<string | undefined>;\n\tmorphFetchFn?: typeof fetch;\n\tclassify?: (\n\t\tmodel: ClassifierModel<ClassifierApi>,\n\t\tcontext: ClassifierContext,\n\t\toptions?: ClassifierOptions,\n\t) => Promise<ClassifierResult>;\n\tsummaryEntries?: SessionEntry[];\n\tcwd?: string;\n}\n\nexport type CompactionRungResult = CompactedTranscript & {\n\trung: \"planned\" | \"fresh\";\n\t/** Present only when a borrowed fallback model ranked the lines. */\n\tplannerModel?: CompactionPlannerModel;\n\t/** False only when the fresh rung had to drop the protected tail. */\n\tkeptTail: boolean;\n\t/** Aggregate usage across every planner request and retry in this run. */\n\tusage?: Usage;\n\tbackend?: \"planner\" | \"classifier\" | \"morph\" | \"summary\";\n\tmodel?: string;\n\tsummary?: { readFiles: string[]; modifiedFiles: string[] };\n\tsummaryFirstKeptEntryId?: string;\n\tsummaryTokensBefore?: number;\n};\n\n/** Runner-internal fresh-window build: the transcript plus the tail decision. */\ninterface FreshWindowBuild {\n\ttranscript: CompactedTranscript;\n\tkeptTail: boolean;\n}\n\nfunction addUsage(total: Usage | undefined, usage: Usage): Usage {\n\tconst cacheWrite1h = (total?.cacheWrite1h ?? 0) + (usage.cacheWrite1h ?? 0);\n\tconst reasoning = (total?.reasoning ?? 0) + (usage.reasoning ?? 0);\n\treturn {\n\t\tinput: (total?.input ?? 0) + usage.input,\n\t\toutput: (total?.output ?? 0) + usage.output,\n\t\tcacheRead: (total?.cacheRead ?? 0) + usage.cacheRead,\n\t\tcacheWrite: (total?.cacheWrite ?? 0) + usage.cacheWrite,\n\t\t...(total?.cacheWrite1h !== undefined || usage.cacheWrite1h !== undefined ? { cacheWrite1h } : {}),\n\t\t...(total?.reasoning !== undefined || usage.reasoning !== undefined ? { reasoning } : {}),\n\t\ttotalTokens: (total?.totalTokens ?? 0) + usage.totalTokens,\n\t\tcost: {\n\t\t\tinput: (total?.cost.input ?? 0) + usage.cost.input,\n\t\t\toutput: (total?.cost.output ?? 0) + usage.cost.output,\n\t\t\tcacheRead: (total?.cost.cacheRead ?? 0) + usage.cost.cacheRead,\n\t\t\tcacheWrite: (total?.cost.cacheWrite ?? 0) + usage.cost.cacheWrite,\n\t\t\ttotal: (total?.cost.total ?? 0) + usage.cost.total,\n\t\t},\n\t};\n}\n\n/**\n * Calculate the single global line threshold from the prepared setting.\n *\n * Protected lines count *against* this target rather than raising it: keeping 40% under a 0.5\n * ratio leaves the remaining 60% to compress harder to hit the same total. That keeps the\n * compression ratio a real bound on output size, so protection can never enlarge the result.\n *\n * This is the untrimmed target. Overflow trimming does NOT reuse it:\n * `planWithTrimming` recomputes the threshold against each trimmed view, so the\n * planner is always asked to keep a proportion of the lines it actually\n * received rather than a proportion of a region it never saw.\n *\n * Retained as an exported helper for tests and consumers that need the\n * pre-trim target; production planning goes through `planWithTrimming`.\n */\nexport function targetKeepLines(preparation: VerbatimCompactionPreparation): number {\n\tconst region = preparation.region;\n\treturn Math.round(region.lines.length * preparation.parameters.compression_ratio);\n}\n\nfunction hardInputLimitFor(model: Model<Api>): number {\n\treturn model.contextWindow > 0 ? model.contextWindow : Number.POSITIVE_INFINITY;\n}\n\n/**\n * Widen region-level transcript stats to whole-context stats (#2052).\n *\n * `result.stats` must be the symmetric region-only stats produced by\n * `reconstructCompactedTranscript`; this adds the independently estimated kept\n * tail to the heuristic before count on both sides — and, only when the tail is\n * kept, to the after count — via the shared `widenToWholeContextStats`. The\n * authoritative `preparation.tokensBefore` is deliberately absent from this\n * comparison and travels separately for budgeting/display.\n */\nfunction withWholeContextStats(\n\tresult: CompactedTranscript,\n\tpreparation: VerbatimCompactionPreparation,\n\tkeptTail: boolean,\n): CompactedTranscript {\n\treturn {\n\t\t...result,\n\t\tstats: widenToWholeContextStats(result.stats, getKeptTailTokenEstimate(preparation), keptTail),\n\t};\n}\n\n/**\n * Build a fresh context window and the tail decision that goes with it.\n *\n * Private on purpose: `keptTail` is runner bookkeeping that persistence needs in\n * order to write `firstKeptEntryId: null` when the protected tail is dropped. It\n * is deliberately absent from the public door's return value, which is exactly a\n * `CompactedTranscript`.\n */\nfunction buildFreshTranscript(preparation: VerbatimCompactionPreparation): CompactedTranscript {\n\tconst region = preparation.region;\n\tconst whole: RawLineRange[] = region.lines.length > 0 ? [{ start: 1, end: region.lines.length }] : [];\n\treturn reconstructCompactedTranscript(region, validateDeletedRanges(whole, region));\n}\n\nfunction buildFreshContextWindow(preparation: VerbatimCompactionPreparation, hardInputLimit: number): FreshWindowBuild {\n\tconst limit = Number.isFinite(hardInputLimit) && hardInputLimit > 0 ? hardInputLimit : Number.POSITIVE_INFINITY;\n\t// The rule is \"tail under the limit ⇒ tail kept\", so the comparison is the\n\t// tail alone. Explicit protected lines are a hard floor that survives either\n\t// way, and counting the reconstructed protected/marker text here would drop a\n\t// tail that fits. A rebuilt context that still cannot be sent is the post-tool\n\t// gate's problem, not a reason for this rung to discard more.\n\t// A kept tail with no registered estimate (a directly constructed\n\t// preparation) is dropped conservatively rather than assumed to fit (P1 #3010).\n\tconst keptTail =\n\t\tpreparation.keptTailMessageCount === 0 ||\n\t\t(hasKeptTailTokenEstimate(preparation) && getKeptTailTokenEstimate(preparation) <= limit);\n\treturn { transcript: buildFreshTranscript(preparation), keptTail };\n}\n\n/**\n * Discard every compactable line and start a fresh context window.\n *\n * TOTAL. No provider, no credentials, no network, no signal, no failure mode,\n * no `Promise`. Port of codex `compact_token_budget` →\n * `Session::start_new_context_window`. Atomic's system prompt, context files,\n * and skills are rebuilt per request and were never in the transcript, so they\n * survive automatically.\n *\n * The whole region is emitted as one deletion range and handed to the unchanged\n * `validateDeletedRanges` → `reconstructCompactedTranscript` path, which splits\n * around protected spans and folds prior markers.\n *\n * Returns exactly a `CompactedTranscript` — `text`, `ranges`, `stats` and\n * nothing else. Whether the `preserve_recent` tail survives is a persistence\n * concern and travels on `CompactionRungResult.keptTail`, not on this door.\n */\nexport function startNewContextWindow(preparation: VerbatimCompactionPreparation): CompactedTranscript {\n\treturn buildFreshTranscript(preparation);\n}\n\nfunction plannedResult(\n\tpreparation: VerbatimCompactionPreparation,\n\tranges: RawLineRange[],\n\tplannerModel: CompactionPlannerModel | undefined,\n\tusage: Usage | undefined,\n\tmodel: string,\n): CompactionRungResult {\n\tconst reconstructed = reconstructCompactedTranscript(\n\t\tpreparation.region,\n\t\tvalidateDeletedRanges(ranges, preparation.region),\n\t);\n\treturn {\n\t\t...withWholeContextStats(reconstructed, preparation, true),\n\t\trung: \"planned\",\n\t\tbackend: \"planner\",\n\t\tmodel,\n\t\t...(plannerModel ? { plannerModel } : {}),\n\t\tkeptTail: true,\n\t\t...(usage ? { usage } : {}),\n\t};\n}\n\nfunction borrowedIdentity(planner: BorrowedPlanner): CompactionPlannerModel {\n\treturn {\n\t\tprovider: planner.model.provider,\n\t\tid: planner.model.id,\n\t\t...(planner.budget.reasoning ? { thinkingLevel: planner.budget.reasoning } : {}),\n\t};\n}\n\nfunction terminalError(outcome: TerminalPlannerOutcome | undefined): RangePlanError {\n\tif (!outcome) return new RangePlanError(MALFORMED_OUTPUT_MESSAGE, 1, \"\", false);\n\tif (outcome.kind === \"rateLimited\") {\n\t\treturn new RangePlanError(outcome.message, 1, \"\", false, outcome.diagnosticPath, outcome);\n\t}\n\tif (outcome.kind === \"overflowed\") {\n\t\treturn new RangePlanError(\n\t\t\t\"Compaction range planning exceeded the model context window\",\n\t\t\t1,\n\t\t\t\"\",\n\t\t\ttrue,\n\t\t\toutcome.diagnosticPath,\n\t\t\toutcome,\n\t\t);\n\t}\n\tif (outcome.kind === \"providerError\" || outcome.kind === \"policyRefusal\") {\n\t\treturn new RangePlanError(outcome.message, 1, \"\", false, outcome.diagnosticPath, outcome);\n\t}\n\tconst message = outcome.category === \"malformed_output\" ? MALFORMED_OUTPUT_MESSAGE : NO_USABLE_RANGES_MESSAGE;\n\treturn new RangePlanError(message, 1, outcome.excerpt, false, outcome.diagnosticPath, outcome);\n}\n\ntype PlannerAttempt =\n\t| { kind: \"planned\"; ranges: RawLineRange[] }\n\t| { kind: \"terminal\"; outcome: TerminalPlannerOutcome };\n\n/**\n * Run one planner model, retrying the same model after oldest-first input\n * trimming when the request itself overflows the context window.\n *\n * Trimming continues until no strictly smaller view exists; `nextTrimOffset`\n * halves the remaining suffix, so the walk is finite. Only then is `overflowed`\n * terminal and the ladder advances.\n *\n * Each view gets its own keep target from `compression_ratio`. Reusing the\n * original whole-preparation target is what asked a halved 20-line region to\n * keep 10 of its 10 visible lines — a request for zero deletions, whose obedient\n * empty answer then hits the non-negotiable zero-range rejection. Extra\n * reduction still comes only from the head the runner withheld.\n */\nasync function planWithTrimming(\n\tpreparation: VerbatimCompactionPreparation,\n\tplanner: BorrowedPlanner,\n\toptions: CompactionPlanOptions & { signal?: AbortSignal },\n): Promise<PlannerAttempt> {\n\tlet offset = 0;\n\tfor (;;) {\n\t\tconst region = offset === 0 ? preparation.region : trimRegionHead(preparation.region, offset);\n\t\tif (!region) return { kind: \"terminal\", outcome: { kind: \"overflowed\" } };\n\t\tconst keepTarget = Math.max(\n\t\t\tregion.protectedLineNumbers?.size ?? 0,\n\t\t\tMath.round(region.lines.length * preparation.parameters.compression_ratio),\n\t\t);\n\t\tconst outcome = await planDeletedLineRanges(region, preparation.parameters, planner, keepTarget, options);\n\t\tif (outcome.kind === \"ranked\" || outcome.kind === \"recovered\") {\n\t\t\tif (offset === 0) return { kind: \"planned\", ranges: outcome.ranges };\n\t\t\tconst validated = validateDeletedRanges(outcome.ranges, region);\n\t\t\treturn { kind: \"planned\", ranges: rebaseTrimmedRanges(validated, offset) };\n\t\t}\n\t\tif (outcome.kind !== \"overflowed\") return { kind: \"terminal\", outcome };\n\t\tif (options.signal?.aborted) throw new Error(\"Compaction cancelled\");\n\t\tconst next = nextTrimOffset(preparation.region, offset);\n\t\tif (next === undefined) return { kind: \"terminal\", outcome };\n\t\toffset = next;\n\t}\n}\n\nconst MISSING_AUTH_MESSAGE = \"Compaction provider authentication is unavailable\";\n\n/**\n * A runner-local terminal cause with no provider attempt behind it.\n *\n * Missing credentials are not a provider outcome — no request was made — so no\n * synthetic response is fabricated and no diagnostic sidecar is written. It is\n * carried as `providerError` purely so the ladder can advance past it.\n */\nfunction authFailureOutcome(error: unknown): TerminalPlannerOutcome {\n\tconst message = error instanceof Error ? error.message : error === undefined ? MISSING_AUTH_MESSAGE : String(error);\n\treturn { kind: \"providerError\", message: message || MISSING_AUTH_MESSAGE };\n}\n\n/** Resolve one model's credentials, normalizing a rejection and `undefined` alike. */\nasync function resolvePlannerAuth(\n\tresolveAuth: CompactionRunRequest[\"resolveAuth\"],\n\tmodel: Model<Api>,\n): Promise<{ auth: PlannerAuth } | { failure: TerminalPlannerOutcome }> {\n\ttry {\n\t\tconst auth = await resolveAuth(model);\n\t\treturn auth ? { auth } : { failure: authFailureOutcome(undefined) };\n\t} catch (error) {\n\t\treturn { failure: authFailureOutcome(error) };\n\t}\n}\n\nfunction freshResult(\n\tpreparation: VerbatimCompactionPreparation,\n\thardInputLimit: number,\n\tusage?: Usage,\n): CompactionRungResult {\n\tconst fresh = buildFreshContextWindow(preparation, hardInputLimit);\n\treturn {\n\t\t...withWholeContextStats(fresh.transcript, preparation, fresh.keptTail),\n\t\trung: \"fresh\",\n\t\tkeptTail: fresh.keptTail,\n\t\t...(usage ? { usage } : {}),\n\t};\n}\n\n/**\n * Produce one compacted transcript, tagged with the rung that produced it.\n *\n * The ladder is: the session model, then each configured fallback model\n * borrowed for one planner request, then — only under `load_bearing` urgency —\n * a fresh context window. A manual `/compact` runs at `recoverable` urgency and\n * therefore cannot reach the context-destroying rung; it fails honestly instead.\n *\n * Unavailable credentials are ladder control flow, not an early throw: a\n * borrowed candidate with its own working credentials can still rank the lines,\n * and a load-bearing caller still reaches the credential-free fresh rung.\n */\nexport async function runVerbatimCompaction(\n\tpreparation: VerbatimCompactionPreparation,\n\tmodel: Model<Api>,\n\trequest: CompactionRunRequest,\n): Promise<CompactionRungResult> {\n\tconst signal = request.signal;\n\tif (signal?.aborted) throw new Error(\"Compaction cancelled\");\n\tlet plannerUsage: Usage | undefined;\n\tconst plannerOptions = {\n\t\tstreamFn: request.streamFn,\n\t\tsessionFilePath: request.sessionFilePath,\n\t\tretry: request.retry,\n\t\tcallbacks: request.callbacks,\n\t\tsignal,\n\t\tonUsage: (usage: Usage) => {\n\t\t\tplannerUsage = addUsage(plannerUsage, usage);\n\t\t},\n\t};\n\tconst hardInputLimit = hardInputLimitFor(model);\n\n\t// A region below the planner minimum cannot be made rankable by changing\n\t// models, so no planner is invoked. Only a load-bearing caller can reach a\n\t// preparation this small; recoverable callers were refused before the runner.\n\tif (preparation.region.lines.length < MIN_COMPACTABLE_REGION_LINES) {\n\t\tif (request.urgency !== \"load_bearing\") throw new RangePlanError(NO_USABLE_RANGES_MESSAGE, 0, \"\", false);\n\t\treturn freshResult(preparation, hardInputLimit);\n\t}\n\n\tconst selection = request.compactionModel ?? { kind: \"chat\", fullId: `${model.provider}/${model.id}`, model };\n\tconst attempted = new Set<string>();\n\t// One borrower per run owns the monotonic cursor, so the configured list is\n\t// walked exactly once no matter how many terminal outcomes occur.\n\tconst borrow: BorrowFallbackPlanner | undefined = request.fallback\n\t\t? createFallbackPlannerBorrower({ ...request.fallback, selectedModelId: selection.fullId })\n\t\t: undefined;\n\tlet backendFailure: TerminalPlannerOutcome | undefined;\n\tif (selection.kind === \"classifier\") {\n\t\ttry {\n\t\t\tconst classify = request.classify;\n\t\t\tif (!classify) throw new Error(\"Compaction classifier is unavailable\");\n\t\t\tconst ranges = await planClassifierRanges(\n\t\t\t\tpreparation.region,\n\t\t\t\tpreparation.parameters,\n\t\t\t\t(context) => classify(selection.model, context, { signal }),\n\t\t\t\tplannerOptions,\n\t\t\t);\n\t\t\treturn {\n\t\t\t\t...plannedResult(preparation, ranges, undefined, plannerUsage, selection.fullId),\n\t\t\t\tbackend: \"classifier\",\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tif (signal?.aborted) throw new Error(\"Compaction cancelled\");\n\t\t\tbackendFailure = { kind: \"providerError\", message: error instanceof Error ? error.message : String(error) };\n\t\t}\n\t}\n\tif (selection.kind === \"morph\") {\n\t\ttry {\n\t\t\tconst ranges = await planMorphRanges(preparation.region, preparation.parameters, {\n\t\t\t\tapiKey: await request.resolveMorphApiKey?.(),\n\t\t\t\tsignal,\n\t\t\t\tfetchFn: request.morphFetchFn,\n\t\t\t\tonDiagnostics: (diagnostics) => writeMorphDiagnosticSidecar(request.sessionFilePath, diagnostics),\n\t\t\t});\n\t\t\treturn {\n\t\t\t\t...plannedResult(preparation, ranges, undefined, undefined, selection.fullId),\n\t\t\t\tbackend: \"morph\",\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tif (signal?.aborted) throw new Error(\"Compaction cancelled\");\n\t\t\tbackendFailure = { kind: \"providerError\", message: error instanceof Error ? error.message : String(error) };\n\t\t}\n\t}\n\tconst primaryModel = selection.kind === \"chat\" ? selection.model : undefined;\n\tconst primaryBudget = resolvePlannerRequest(primaryModel ?? model, request.thinkingLevel);\n\tconst primaryAuth = primaryModel\n\t\t? await resolvePlannerAuth(request.resolveAuth, primaryModel)\n\t\t: {\n\t\t\t\tfailure: {\n\t\t\t\t\tkind: \"providerError\" as const,\n\t\t\t\t\tmessage:\n\t\t\t\t\t\tbackendFailure?.kind === \"providerError\"\n\t\t\t\t\t\t\t? backendFailure.message\n\t\t\t\t\t\t\t: `Compaction backend ${selection.kind} is not yet available`,\n\t\t\t\t},\n\t\t\t};\n\tlet lastTerminal: TerminalPlannerOutcome | undefined = \"failure\" in primaryAuth ? primaryAuth.failure : undefined;\n\tlet borrowed = primaryModel !== model;\n\tlet planner: BorrowedPlanner | undefined;\n\n\tif (primaryModel && \"auth\" in primaryAuth) {\n\t\tplanner = { model: primaryModel, budget: primaryBudget, auth: primaryAuth.auth };\n\t} else {\n\t\tif (primaryModel) attempted.add(plannerAttemptKey({ model: primaryModel, budget: primaryBudget, auth: {} }));\n\t\tplanner = borrow ? await borrow(attempted, request.resolveAuth) : undefined;\n\t\tborrowed = planner !== undefined;\n\t}\n\n\twhile (planner) {\n\t\tconst attempt = await planWithTrimming(preparation, planner, plannerOptions);\n\t\tif (signal?.aborted) throw new Error(\"Compaction cancelled\");\n\t\tif (attempt.kind === \"planned\") {\n\t\t\tconst plannerModel = borrowed ? borrowedIdentity(planner) : undefined;\n\t\t\tif (plannerModel) {\n\t\t\t\t// Best-effort: the durable entry already records the borrowed model;\n\t\t\t\t// a sidecar write failure never affects compaction success.\n\t\t\t\twriteSuccessDiagnosticSidecar({\n\t\t\t\t\tsessionFilePath: request.sessionFilePath,\n\t\t\t\t\tmodel: planner.model,\n\t\t\t\t\tsuccessCategory: \"borrowed_planner\",\n\t\t\t\t\t...(plannerModel.thinkingLevel === undefined ? {} : { thinkingLevel: plannerModel.thinkingLevel }),\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn plannedResult(\n\t\t\t\tpreparation,\n\t\t\t\tattempt.ranges,\n\t\t\t\tplannerModel,\n\t\t\t\tplannerUsage,\n\t\t\t\t`${planner.model.provider}/${planner.model.id}`,\n\t\t\t);\n\t\t}\n\t\tlastTerminal = attempt.outcome;\n\t\tif (attempt.outcome.kind === \"policyRefusal\" && request.summaryEntries) {\n\t\t\ttry {\n\t\t\t\tconst summary = await runPiSummaryFallback(request.summaryEntries, preparation.settings, planner, {\n\t\t\t\t\t...plannerOptions,\n\t\t\t\t\tcwd: request.cwd,\n\t\t\t\t});\n\t\t\t\treturn {\n\t\t\t\t\ttext: summary.summary,\n\t\t\t\t\tranges: [],\n\t\t\t\t\tkeptRanges: [],\n\t\t\t\t\tstats: {\n\t\t\t\t\t\tlinesBefore: preparation.region.lines.length,\n\t\t\t\t\t\tlinesDeleted: 0,\n\t\t\t\t\t\tlinesKept: summary.summary.split(\"\\n\").length,\n\t\t\t\t\t\trangeCount: 0,\n\t\t\t\t\t\ttokensBefore: summary.tokensBefore,\n\t\t\t\t\t\ttokensAfter: summary.tokensAfter,\n\t\t\t\t\t\tpercentReduction:\n\t\t\t\t\t\t\tsummary.tokensBefore > 0 ? 100 * (1 - summary.tokensAfter / summary.tokensBefore) : 0,\n\t\t\t\t\t},\n\t\t\t\t\trung: \"planned\",\n\t\t\t\t\tkeptTail: true,\n\t\t\t\t\tbackend: \"summary\",\n\t\t\t\t\tmodel: `${planner.model.provider}/${planner.model.id}`,\n\t\t\t\t\tsummary: { readFiles: summary.readFiles, modifiedFiles: summary.modifiedFiles },\n\t\t\t\t\tsummaryFirstKeptEntryId: summary.firstKeptEntryId,\n\t\t\t\t\tsummaryTokensBefore: summary.tokensBefore,\n\t\t\t\t\t...(plannerUsage ? { usage: plannerUsage } : {}),\n\t\t\t\t};\n\t\t\t} catch (error) {\n\t\t\t\tif (signal?.aborted) throw new Error(\"Compaction cancelled\");\n\t\t\t\tlastTerminal = { kind: \"providerError\", message: error instanceof Error ? error.message : String(error) };\n\t\t\t}\n\t\t}\n\t\tattempted.add(plannerAttemptKey(planner));\n\t\tplanner = borrow ? await borrow(attempted, request.resolveAuth) : undefined;\n\t\tborrowed = planner !== undefined;\n\t\tif (signal?.aborted) throw new Error(\"Compaction cancelled\");\n\t}\n\n\tif (request.urgency !== \"load_bearing\") throw terminalError(lastTerminal);\n\treturn freshResult(preparation, hardInputLimit, plannerUsage);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"compaction-runner.js","sourceRoot":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AC,CAAC,MAAM,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAC5E,QAAQ,GAAG,OAAO,KAAK,SAAS,CAAC;QACjC,IAAI,MAAM,EAAE,OAAO;YAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC9D,CAAC;IAED,IAAI,OAAO,CAAC,OAAO,KAAK,cAAc;QAAE,MAAM,aAAa,CAAC,YAAY,CAAC,CAAC;IAC1E,OAAO,WAAW,CAAC,WAAW,EAAE,cAAc,EAAE,YAAY,CAAC,CAAC;AAC/D,CAAC","sourcesContent":["import type {\n\tClassifierApi,\n\tClassifierContext,\n\tClassifierModel,\n\tClassifierOptions,\n\tClassifierResult,\n\tRetryCallbacks,\n\tRetryPolicy,\n} from \"@bastani/pi-ai\";\nimport type { Api, Model, Usage } from \"@bastani/pi-ai/compat\";\nimport type { StreamFn, ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport type { SessionEntry } from \"../session-manager-types.ts\";\nimport { planClassifierRanges } from \"./classifier-compaction.js\";\nimport { getKeptTailTokenEstimate, hasKeptTailTokenEstimate } from \"./compaction-boundary.js\";\nimport type {\n\tBorrowedPlanner,\n\tCompactedTranscript,\n\tCompactionPlannerModel,\n\tCompactionUrgency,\n\tPlannerAuth,\n\tRawLineRange,\n\tVerbatimCompactionPreparation,\n} from \"./compaction-types.js\";\nimport { MIN_COMPACTABLE_REGION_LINES } from \"./compaction-types.js\";\nimport { reconstructCompactedTranscript, validateDeletedRanges } from \"./deleted-ranges.js\";\nimport {\n\ttype BorrowFallbackPlanner,\n\tcreateFallbackPlannerBorrower,\n\ttype FallbackPlannerContext,\n\tplannerAttemptKey,\n} from \"./fallback-planner.js\";\nimport type { CompactionModelSelection } from \"./model-resolver.js\";\nimport { planMorphRanges } from \"./morph-compaction.js\";\nimport { runPiSummaryFallback } from \"./pi-summary-fallback.js\";\nimport type { TerminalPlannerOutcome } from \"./planner-outcome.js\";\nimport {\n\tMALFORMED_OUTPUT_MESSAGE,\n\tNO_USABLE_RANGES_MESSAGE,\n\tplanDeletedLineRanges,\n\tRangePlanError,\n\tresolvePlannerRequest,\n} from \"./range-planner.js\";\nimport { writeMorphDiagnosticSidecar, writeSuccessDiagnosticSidecar } from \"./range-planner-diagnostics.js\";\nimport { nextTrimOffset, rebaseTrimmedRanges, trimRegionHead } from \"./region-trimming.js\";\nimport { widenToWholeContextStats } from \"./whole-context-stats.js\";\n\nexport interface CompactionPlanOptions {\n\tstreamFn: StreamFn;\n\t/** Absolute path of the persisted session file. Undefined for in-memory sessions. */\n\tsessionFilePath?: string;\n\tretry?: RetryPolicy;\n\tcallbacks?: RetryCallbacks;\n}\n\n/** One compaction run's request. Urgency is required; there is no default. */\nexport interface CompactionRunRequest extends CompactionPlanOptions {\n\t/** Per-model credentials; a borrowed candidate uses its own, never the session model's. */\n\tresolveAuth: (model: Model<Api>) => Promise<PlannerAuth | undefined>;\n\tsignal?: AbortSignal;\n\t/** Inherited by the planner and never modified across attempts. */\n\tthinkingLevel: ThinkingLevel | undefined;\n\turgency: CompactionUrgency;\n\t/** Configured fallback candidates. Omitted means borrowing is impossible. */\n\tfallback?: FallbackPlannerContext;\n\tcompactionModel?: CompactionModelSelection;\n\tresolveMorphApiKey?: () => Promise<string | undefined>;\n\tmorphFetchFn?: typeof fetch;\n\tclassify?: (\n\t\tmodel: ClassifierModel<ClassifierApi>,\n\t\tcontext: ClassifierContext,\n\t\toptions?: ClassifierOptions,\n\t) => Promise<ClassifierResult>;\n\tsummaryEntries?: SessionEntry[];\n\tcwd?: string;\n}\n\nexport type CompactionRungResult = CompactedTranscript & {\n\trung: \"planned\" | \"fresh\";\n\t/** Present only when a borrowed fallback model ranked the lines. */\n\tplannerModel?: CompactionPlannerModel;\n\t/** False only when the fresh rung had to drop the protected tail. */\n\tkeptTail: boolean;\n\t/** Aggregate usage across every planner request and retry in this run. */\n\tusage?: Usage;\n\tbackend?: \"planner\" | \"classifier\" | \"morph\" | \"summary\";\n\tmodel?: string;\n\tsummary?: { readFiles: string[]; modifiedFiles: string[] };\n\tsummaryFirstKeptEntryId?: string;\n\tsummaryTokensBefore?: number;\n};\n\n/** Runner-internal fresh-window build: the transcript plus the tail decision. */\ninterface FreshWindowBuild {\n\ttranscript: CompactedTranscript;\n\tkeptTail: boolean;\n}\n\nfunction addUsage(total: Usage | undefined, usage: Usage): Usage {\n\tconst cacheWrite1h = (total?.cacheWrite1h ?? 0) + (usage.cacheWrite1h ?? 0);\n\tconst reasoning = (total?.reasoning ?? 0) + (usage.reasoning ?? 0);\n\treturn {\n\t\tinput: (total?.input ?? 0) + usage.input,\n\t\toutput: (total?.output ?? 0) + usage.output,\n\t\tcacheRead: (total?.cacheRead ?? 0) + usage.cacheRead,\n\t\tcacheWrite: (total?.cacheWrite ?? 0) + usage.cacheWrite,\n\t\t...(total?.cacheWrite1h !== undefined || usage.cacheWrite1h !== undefined ? { cacheWrite1h } : {}),\n\t\t...(total?.reasoning !== undefined || usage.reasoning !== undefined ? { reasoning } : {}),\n\t\ttotalTokens: (total?.totalTokens ?? 0) + usage.totalTokens,\n\t\tcost: {\n\t\t\tinput: (total?.cost.input ?? 0) + usage.cost.input,\n\t\t\toutput: (total?.cost.output ?? 0) + usage.cost.output,\n\t\t\tcacheRead: (total?.cost.cacheRead ?? 0) + usage.cost.cacheRead,\n\t\t\tcacheWrite: (total?.cost.cacheWrite ?? 0) + usage.cost.cacheWrite,\n\t\t\ttotal: (total?.cost.total ?? 0) + usage.cost.total,\n\t\t\ttotalFromProvider:\n\t\t\t\t(total === undefined || total.cost.totalFromProvider === true) && usage.cost.totalFromProvider === true,\n\t\t},\n\t};\n}\n\n/**\n * Calculate the single global line threshold from the prepared setting.\n *\n * Protected lines count *against* this target rather than raising it: keeping 40% under a 0.5\n * ratio leaves the remaining 60% to compress harder to hit the same total. That keeps the\n * compression ratio a real bound on output size, so protection can never enlarge the result.\n *\n * This is the untrimmed target. Overflow trimming does NOT reuse it:\n * `planWithTrimming` recomputes the threshold against each trimmed view, so the\n * planner is always asked to keep a proportion of the lines it actually\n * received rather than a proportion of a region it never saw.\n *\n * Retained as an exported helper for tests and consumers that need the\n * pre-trim target; production planning goes through `planWithTrimming`.\n */\nexport function targetKeepLines(preparation: VerbatimCompactionPreparation): number {\n\tconst region = preparation.region;\n\treturn Math.round(region.lines.length * preparation.parameters.compression_ratio);\n}\n\nfunction hardInputLimitFor(model: Model<Api>): number {\n\treturn model.contextWindow > 0 ? model.contextWindow : Number.POSITIVE_INFINITY;\n}\n\n/**\n * Widen region-level transcript stats to whole-context stats (#2052).\n *\n * `result.stats` must be the symmetric region-only stats produced by\n * `reconstructCompactedTranscript`; this adds the independently estimated kept\n * tail to the heuristic before count on both sides — and, only when the tail is\n * kept, to the after count — via the shared `widenToWholeContextStats`. The\n * authoritative `preparation.tokensBefore` is deliberately absent from this\n * comparison and travels separately for budgeting/display.\n */\nfunction withWholeContextStats(\n\tresult: CompactedTranscript,\n\tpreparation: VerbatimCompactionPreparation,\n\tkeptTail: boolean,\n): CompactedTranscript {\n\treturn {\n\t\t...result,\n\t\tstats: widenToWholeContextStats(result.stats, getKeptTailTokenEstimate(preparation), keptTail),\n\t};\n}\n\n/**\n * Build a fresh context window and the tail decision that goes with it.\n *\n * Private on purpose: `keptTail` is runner bookkeeping that persistence needs in\n * order to write `firstKeptEntryId: null` when the protected tail is dropped. It\n * is deliberately absent from the public door's return value, which is exactly a\n * `CompactedTranscript`.\n */\nfunction buildFreshTranscript(preparation: VerbatimCompactionPreparation): CompactedTranscript {\n\tconst region = preparation.region;\n\tconst whole: RawLineRange[] = region.lines.length > 0 ? [{ start: 1, end: region.lines.length }] : [];\n\treturn reconstructCompactedTranscript(region, validateDeletedRanges(whole, region));\n}\n\nfunction buildFreshContextWindow(preparation: VerbatimCompactionPreparation, hardInputLimit: number): FreshWindowBuild {\n\tconst limit = Number.isFinite(hardInputLimit) && hardInputLimit > 0 ? hardInputLimit : Number.POSITIVE_INFINITY;\n\t// The rule is \"tail under the limit ⇒ tail kept\", so the comparison is the\n\t// tail alone. Explicit protected lines are a hard floor that survives either\n\t// way, and counting the reconstructed protected/marker text here would drop a\n\t// tail that fits. A rebuilt context that still cannot be sent is the post-tool\n\t// gate's problem, not a reason for this rung to discard more.\n\t// A kept tail with no registered estimate (a directly constructed\n\t// preparation) is dropped conservatively rather than assumed to fit (P1 #3010).\n\tconst keptTail =\n\t\tpreparation.keptTailMessageCount === 0 ||\n\t\t(hasKeptTailTokenEstimate(preparation) && getKeptTailTokenEstimate(preparation) <= limit);\n\treturn { transcript: buildFreshTranscript(preparation), keptTail };\n}\n\n/**\n * Discard every compactable line and start a fresh context window.\n *\n * TOTAL. No provider, no credentials, no network, no signal, no failure mode,\n * no `Promise`. Port of codex `compact_token_budget` →\n * `Session::start_new_context_window`. Atomic's system prompt, context files,\n * and skills are rebuilt per request and were never in the transcript, so they\n * survive automatically.\n *\n * The whole region is emitted as one deletion range and handed to the unchanged\n * `validateDeletedRanges` → `reconstructCompactedTranscript` path, which splits\n * around protected spans and folds prior markers.\n *\n * Returns exactly a `CompactedTranscript` — `text`, `ranges`, `stats` and\n * nothing else. Whether the `preserve_recent` tail survives is a persistence\n * concern and travels on `CompactionRungResult.keptTail`, not on this door.\n */\nexport function startNewContextWindow(preparation: VerbatimCompactionPreparation): CompactedTranscript {\n\treturn buildFreshTranscript(preparation);\n}\n\nfunction plannedResult(\n\tpreparation: VerbatimCompactionPreparation,\n\tranges: RawLineRange[],\n\tplannerModel: CompactionPlannerModel | undefined,\n\tusage: Usage | undefined,\n\tmodel: string,\n): CompactionRungResult {\n\tconst reconstructed = reconstructCompactedTranscript(\n\t\tpreparation.region,\n\t\tvalidateDeletedRanges(ranges, preparation.region),\n\t);\n\treturn {\n\t\t...withWholeContextStats(reconstructed, preparation, true),\n\t\trung: \"planned\",\n\t\tbackend: \"planner\",\n\t\tmodel,\n\t\t...(plannerModel ? { plannerModel } : {}),\n\t\tkeptTail: true,\n\t\t...(usage ? { usage } : {}),\n\t};\n}\n\nfunction borrowedIdentity(planner: BorrowedPlanner): CompactionPlannerModel {\n\treturn {\n\t\tprovider: planner.model.provider,\n\t\tid: planner.model.id,\n\t\t...(planner.budget.reasoning ? { thinkingLevel: planner.budget.reasoning } : {}),\n\t};\n}\n\nfunction terminalError(outcome: TerminalPlannerOutcome | undefined): RangePlanError {\n\tif (!outcome) return new RangePlanError(MALFORMED_OUTPUT_MESSAGE, 1, \"\", false);\n\tif (outcome.kind === \"rateLimited\") {\n\t\treturn new RangePlanError(outcome.message, 1, \"\", false, outcome.diagnosticPath, outcome);\n\t}\n\tif (outcome.kind === \"overflowed\") {\n\t\treturn new RangePlanError(\n\t\t\t\"Compaction range planning exceeded the model context window\",\n\t\t\t1,\n\t\t\t\"\",\n\t\t\ttrue,\n\t\t\toutcome.diagnosticPath,\n\t\t\toutcome,\n\t\t);\n\t}\n\tif (outcome.kind === \"providerError\" || outcome.kind === \"policyRefusal\") {\n\t\treturn new RangePlanError(outcome.message, 1, \"\", false, outcome.diagnosticPath, outcome);\n\t}\n\tconst message = outcome.category === \"malformed_output\" ? MALFORMED_OUTPUT_MESSAGE : NO_USABLE_RANGES_MESSAGE;\n\treturn new RangePlanError(message, 1, outcome.excerpt, false, outcome.diagnosticPath, outcome);\n}\n\ntype PlannerAttempt =\n\t| { kind: \"planned\"; ranges: RawLineRange[] }\n\t| { kind: \"terminal\"; outcome: TerminalPlannerOutcome };\n\n/**\n * Run one planner model, retrying the same model after oldest-first input\n * trimming when the request itself overflows the context window.\n *\n * Trimming continues until no strictly smaller view exists; `nextTrimOffset`\n * halves the remaining suffix, so the walk is finite. Only then is `overflowed`\n * terminal and the ladder advances.\n *\n * Each view gets its own keep target from `compression_ratio`. Reusing the\n * original whole-preparation target is what asked a halved 20-line region to\n * keep 10 of its 10 visible lines — a request for zero deletions, whose obedient\n * empty answer then hits the non-negotiable zero-range rejection. Extra\n * reduction still comes only from the head the runner withheld.\n */\nasync function planWithTrimming(\n\tpreparation: VerbatimCompactionPreparation,\n\tplanner: BorrowedPlanner,\n\toptions: CompactionPlanOptions & { signal?: AbortSignal },\n): Promise<PlannerAttempt> {\n\tlet offset = 0;\n\tfor (;;) {\n\t\tconst region = offset === 0 ? preparation.region : trimRegionHead(preparation.region, offset);\n\t\tif (!region) return { kind: \"terminal\", outcome: { kind: \"overflowed\" } };\n\t\tconst keepTarget = Math.max(\n\t\t\tregion.protectedLineNumbers?.size ?? 0,\n\t\t\tMath.round(region.lines.length * preparation.parameters.compression_ratio),\n\t\t);\n\t\tconst outcome = await planDeletedLineRanges(region, preparation.parameters, planner, keepTarget, options);\n\t\tif (outcome.kind === \"ranked\" || outcome.kind === \"recovered\") {\n\t\t\tif (offset === 0) return { kind: \"planned\", ranges: outcome.ranges };\n\t\t\tconst validated = validateDeletedRanges(outcome.ranges, region);\n\t\t\treturn { kind: \"planned\", ranges: rebaseTrimmedRanges(validated, offset) };\n\t\t}\n\t\tif (outcome.kind !== \"overflowed\") return { kind: \"terminal\", outcome };\n\t\tif (options.signal?.aborted) throw new Error(\"Compaction cancelled\");\n\t\tconst next = nextTrimOffset(preparation.region, offset);\n\t\tif (next === undefined) return { kind: \"terminal\", outcome };\n\t\toffset = next;\n\t}\n}\n\nconst MISSING_AUTH_MESSAGE = \"Compaction provider authentication is unavailable\";\n\n/**\n * A runner-local terminal cause with no provider attempt behind it.\n *\n * Missing credentials are not a provider outcome — no request was made — so no\n * synthetic response is fabricated and no diagnostic sidecar is written. It is\n * carried as `providerError` purely so the ladder can advance past it.\n */\nfunction authFailureOutcome(error: unknown): TerminalPlannerOutcome {\n\tconst message = error instanceof Error ? error.message : error === undefined ? MISSING_AUTH_MESSAGE : String(error);\n\treturn { kind: \"providerError\", message: message || MISSING_AUTH_MESSAGE };\n}\n\n/** Resolve one model's credentials, normalizing a rejection and `undefined` alike. */\nasync function resolvePlannerAuth(\n\tresolveAuth: CompactionRunRequest[\"resolveAuth\"],\n\tmodel: Model<Api>,\n): Promise<{ auth: PlannerAuth } | { failure: TerminalPlannerOutcome }> {\n\ttry {\n\t\tconst auth = await resolveAuth(model);\n\t\treturn auth ? { auth } : { failure: authFailureOutcome(undefined) };\n\t} catch (error) {\n\t\treturn { failure: authFailureOutcome(error) };\n\t}\n}\n\nfunction freshResult(\n\tpreparation: VerbatimCompactionPreparation,\n\thardInputLimit: number,\n\tusage?: Usage,\n): CompactionRungResult {\n\tconst fresh = buildFreshContextWindow(preparation, hardInputLimit);\n\treturn {\n\t\t...withWholeContextStats(fresh.transcript, preparation, fresh.keptTail),\n\t\trung: \"fresh\",\n\t\tkeptTail: fresh.keptTail,\n\t\t...(usage ? { usage } : {}),\n\t};\n}\n\n/**\n * Produce one compacted transcript, tagged with the rung that produced it.\n *\n * The ladder is: the session model, then each configured fallback model\n * borrowed for one planner request, then — only under `load_bearing` urgency —\n * a fresh context window. A manual `/compact` runs at `recoverable` urgency and\n * therefore cannot reach the context-destroying rung; it fails honestly instead.\n *\n * Unavailable credentials are ladder control flow, not an early throw: a\n * borrowed candidate with its own working credentials can still rank the lines,\n * and a load-bearing caller still reaches the credential-free fresh rung.\n */\nexport async function runVerbatimCompaction(\n\tpreparation: VerbatimCompactionPreparation,\n\tmodel: Model<Api>,\n\trequest: CompactionRunRequest,\n): Promise<CompactionRungResult> {\n\tconst signal = request.signal;\n\tif (signal?.aborted) throw new Error(\"Compaction cancelled\");\n\tlet plannerUsage: Usage | undefined;\n\tconst plannerOptions = {\n\t\tstreamFn: request.streamFn,\n\t\tsessionFilePath: request.sessionFilePath,\n\t\tretry: request.retry,\n\t\tcallbacks: request.callbacks,\n\t\tsignal,\n\t\tonUsage: (usage: Usage) => {\n\t\t\tplannerUsage = addUsage(plannerUsage, usage);\n\t\t},\n\t};\n\tconst hardInputLimit = hardInputLimitFor(model);\n\n\t// A region below the planner minimum cannot be made rankable by changing\n\t// models, so no planner is invoked. Only a load-bearing caller can reach a\n\t// preparation this small; recoverable callers were refused before the runner.\n\tif (preparation.region.lines.length < MIN_COMPACTABLE_REGION_LINES) {\n\t\tif (request.urgency !== \"load_bearing\") throw new RangePlanError(NO_USABLE_RANGES_MESSAGE, 0, \"\", false);\n\t\treturn freshResult(preparation, hardInputLimit);\n\t}\n\n\tconst selection = request.compactionModel ?? { kind: \"chat\", fullId: `${model.provider}/${model.id}`, model };\n\tconst attempted = new Set<string>();\n\t// One borrower per run owns the monotonic cursor, so the configured list is\n\t// walked exactly once no matter how many terminal outcomes occur.\n\tconst borrow: BorrowFallbackPlanner | undefined = request.fallback\n\t\t? createFallbackPlannerBorrower({ ...request.fallback, selectedModelId: selection.fullId })\n\t\t: undefined;\n\tlet backendFailure: TerminalPlannerOutcome | undefined;\n\tif (selection.kind === \"classifier\") {\n\t\ttry {\n\t\t\tconst classify = request.classify;\n\t\t\tif (!classify) throw new Error(\"Compaction classifier is unavailable\");\n\t\t\tconst ranges = await planClassifierRanges(\n\t\t\t\tpreparation.region,\n\t\t\t\tpreparation.parameters,\n\t\t\t\t(context) => classify(selection.model, context, { signal }),\n\t\t\t\tplannerOptions,\n\t\t\t);\n\t\t\treturn {\n\t\t\t\t...plannedResult(preparation, ranges, undefined, plannerUsage, selection.fullId),\n\t\t\t\tbackend: \"classifier\",\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tif (signal?.aborted) throw new Error(\"Compaction cancelled\");\n\t\t\tbackendFailure = { kind: \"providerError\", message: error instanceof Error ? error.message : String(error) };\n\t\t}\n\t}\n\tif (selection.kind === \"morph\") {\n\t\ttry {\n\t\t\tconst ranges = await planMorphRanges(preparation.region, preparation.parameters, {\n\t\t\t\tapiKey: await request.resolveMorphApiKey?.(),\n\t\t\t\tsignal,\n\t\t\t\tfetchFn: request.morphFetchFn,\n\t\t\t\tonDiagnostics: (diagnostics) => writeMorphDiagnosticSidecar(request.sessionFilePath, diagnostics),\n\t\t\t});\n\t\t\treturn {\n\t\t\t\t...plannedResult(preparation, ranges, undefined, undefined, selection.fullId),\n\t\t\t\tbackend: \"morph\",\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tif (signal?.aborted) throw new Error(\"Compaction cancelled\");\n\t\t\tbackendFailure = { kind: \"providerError\", message: error instanceof Error ? error.message : String(error) };\n\t\t}\n\t}\n\tconst primaryModel = selection.kind === \"chat\" ? selection.model : undefined;\n\tconst primaryBudget = resolvePlannerRequest(primaryModel ?? model, request.thinkingLevel);\n\tconst primaryAuth = primaryModel\n\t\t? await resolvePlannerAuth(request.resolveAuth, primaryModel)\n\t\t: {\n\t\t\t\tfailure: {\n\t\t\t\t\tkind: \"providerError\" as const,\n\t\t\t\t\tmessage:\n\t\t\t\t\t\tbackendFailure?.kind === \"providerError\"\n\t\t\t\t\t\t\t? backendFailure.message\n\t\t\t\t\t\t\t: `Compaction backend ${selection.kind} is not yet available`,\n\t\t\t\t},\n\t\t\t};\n\tlet lastTerminal: TerminalPlannerOutcome | undefined = \"failure\" in primaryAuth ? primaryAuth.failure : undefined;\n\tlet borrowed = primaryModel !== model;\n\tlet planner: BorrowedPlanner | undefined;\n\n\tif (primaryModel && \"auth\" in primaryAuth) {\n\t\tplanner = { model: primaryModel, budget: primaryBudget, auth: primaryAuth.auth };\n\t} else {\n\t\tif (primaryModel) attempted.add(plannerAttemptKey({ model: primaryModel, budget: primaryBudget, auth: {} }));\n\t\tplanner = borrow ? await borrow(attempted, request.resolveAuth) : undefined;\n\t\tborrowed = planner !== undefined;\n\t}\n\n\twhile (planner) {\n\t\tconst attempt = await planWithTrimming(preparation, planner, plannerOptions);\n\t\tif (signal?.aborted) throw new Error(\"Compaction cancelled\");\n\t\tif (attempt.kind === \"planned\") {\n\t\t\tconst plannerModel = borrowed ? borrowedIdentity(planner) : undefined;\n\t\t\tif (plannerModel) {\n\t\t\t\t// Best-effort: the durable entry already records the borrowed model;\n\t\t\t\t// a sidecar write failure never affects compaction success.\n\t\t\t\twriteSuccessDiagnosticSidecar({\n\t\t\t\t\tsessionFilePath: request.sessionFilePath,\n\t\t\t\t\tmodel: planner.model,\n\t\t\t\t\tsuccessCategory: \"borrowed_planner\",\n\t\t\t\t\t...(plannerModel.thinkingLevel === undefined ? {} : { thinkingLevel: plannerModel.thinkingLevel }),\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn plannedResult(\n\t\t\t\tpreparation,\n\t\t\t\tattempt.ranges,\n\t\t\t\tplannerModel,\n\t\t\t\tplannerUsage,\n\t\t\t\t`${planner.model.provider}/${planner.model.id}`,\n\t\t\t);\n\t\t}\n\t\tlastTerminal = attempt.outcome;\n\t\tif (attempt.outcome.kind === \"policyRefusal\" && request.summaryEntries) {\n\t\t\ttry {\n\t\t\t\tconst summary = await runPiSummaryFallback(request.summaryEntries, preparation.settings, planner, {\n\t\t\t\t\t...plannerOptions,\n\t\t\t\t\tcwd: request.cwd,\n\t\t\t\t});\n\t\t\t\treturn {\n\t\t\t\t\ttext: summary.summary,\n\t\t\t\t\tranges: [],\n\t\t\t\t\tkeptRanges: [],\n\t\t\t\t\tstats: {\n\t\t\t\t\t\tlinesBefore: preparation.region.lines.length,\n\t\t\t\t\t\tlinesDeleted: 0,\n\t\t\t\t\t\tlinesKept: summary.summary.split(\"\\n\").length,\n\t\t\t\t\t\trangeCount: 0,\n\t\t\t\t\t\ttokensBefore: summary.tokensBefore,\n\t\t\t\t\t\ttokensAfter: summary.tokensAfter,\n\t\t\t\t\t\tpercentReduction:\n\t\t\t\t\t\t\tsummary.tokensBefore > 0 ? 100 * (1 - summary.tokensAfter / summary.tokensBefore) : 0,\n\t\t\t\t\t},\n\t\t\t\t\trung: \"planned\",\n\t\t\t\t\tkeptTail: true,\n\t\t\t\t\tbackend: \"summary\",\n\t\t\t\t\tmodel: `${planner.model.provider}/${planner.model.id}`,\n\t\t\t\t\tsummary: { readFiles: summary.readFiles, modifiedFiles: summary.modifiedFiles },\n\t\t\t\t\tsummaryFirstKeptEntryId: summary.firstKeptEntryId,\n\t\t\t\t\tsummaryTokensBefore: summary.tokensBefore,\n\t\t\t\t\t...(plannerUsage ? { usage: plannerUsage } : {}),\n\t\t\t\t};\n\t\t\t} catch (error) {\n\t\t\t\tif (signal?.aborted) throw new Error(\"Compaction cancelled\");\n\t\t\t\tlastTerminal = { kind: \"providerError\", message: error instanceof Error ? error.message : String(error) };\n\t\t\t}\n\t\t}\n\t\tattempted.add(plannerAttemptKey(planner));\n\t\tplanner = borrow ? await borrow(attempted, request.resolveAuth) : undefined;\n\t\tborrowed = planner !== undefined;\n\t\tif (signal?.aborted) throw new Error(\"Compaction cancelled\");\n\t}\n\n\tif (request.urgency !== \"load_bearing\") throw terminalError(lastTerminal);\n\treturn freshResult(preparation, hardInputLimit, plannerUsage);\n}\n"]}
|
|
@@ -93,6 +93,8 @@ export declare const ModelsJsonCompatSchema: Type.TObject<{
|
|
|
93
93
|
}>>>;
|
|
94
94
|
enforcesPreservedThinkingBinding: Type.TOptional<Type.TBoolean>;
|
|
95
95
|
delegatesThinkingModelBinding: Type.TOptional<Type.TBoolean>;
|
|
96
|
+
imageInput: Type.TOptional<Type.TUnion<[Type.TLiteral<"assets">, Type.TLiteral<"images">, Type.TLiteral<"state-image-urls">]>>;
|
|
97
|
+
sendImageOptInHeader: Type.TOptional<Type.TBoolean>;
|
|
96
98
|
supportsDeveloperRole: Type.TOptional<Type.TBoolean>;
|
|
97
99
|
supportsMidConvoSystemMessages: Type.TOptional<Type.TBoolean>;
|
|
98
100
|
sessionAffinityFormat: Type.TOptional<Type.TUnion<[Type.TLiteral<"openai">, Type.TLiteral<"openai-nosession">, Type.TLiteral<"openrouter">]>>;
|
|
@@ -256,6 +258,8 @@ declare const ModelDefinitionSchema: Type.TObject<{
|
|
|
256
258
|
}>>>;
|
|
257
259
|
enforcesPreservedThinkingBinding: Type.TOptional<Type.TBoolean>;
|
|
258
260
|
delegatesThinkingModelBinding: Type.TOptional<Type.TBoolean>;
|
|
261
|
+
imageInput: Type.TOptional<Type.TUnion<[Type.TLiteral<"assets">, Type.TLiteral<"images">, Type.TLiteral<"state-image-urls">]>>;
|
|
262
|
+
sendImageOptInHeader: Type.TOptional<Type.TBoolean>;
|
|
259
263
|
supportsDeveloperRole: Type.TOptional<Type.TBoolean>;
|
|
260
264
|
supportsMidConvoSystemMessages: Type.TOptional<Type.TBoolean>;
|
|
261
265
|
sessionAffinityFormat: Type.TOptional<Type.TUnion<[Type.TLiteral<"openai">, Type.TLiteral<"openai-nosession">, Type.TLiteral<"openrouter">]>>;
|
|
@@ -417,6 +421,8 @@ declare const ModelOverrideSchema: Type.TObject<{
|
|
|
417
421
|
}>>>;
|
|
418
422
|
enforcesPreservedThinkingBinding: Type.TOptional<Type.TBoolean>;
|
|
419
423
|
delegatesThinkingModelBinding: Type.TOptional<Type.TBoolean>;
|
|
424
|
+
imageInput: Type.TOptional<Type.TUnion<[Type.TLiteral<"assets">, Type.TLiteral<"images">, Type.TLiteral<"state-image-urls">]>>;
|
|
425
|
+
sendImageOptInHeader: Type.TOptional<Type.TBoolean>;
|
|
420
426
|
supportsDeveloperRole: Type.TOptional<Type.TBoolean>;
|
|
421
427
|
supportsMidConvoSystemMessages: Type.TOptional<Type.TBoolean>;
|
|
422
428
|
sessionAffinityFormat: Type.TOptional<Type.TUnion<[Type.TLiteral<"openai">, Type.TLiteral<"openai-nosession">, Type.TLiteral<"openrouter">]>>;
|
|
@@ -529,6 +535,8 @@ declare const ProviderConfigSchema: Type.TObject<{
|
|
|
529
535
|
}>>>;
|
|
530
536
|
enforcesPreservedThinkingBinding: Type.TOptional<Type.TBoolean>;
|
|
531
537
|
delegatesThinkingModelBinding: Type.TOptional<Type.TBoolean>;
|
|
538
|
+
imageInput: Type.TOptional<Type.TUnion<[Type.TLiteral<"assets">, Type.TLiteral<"images">, Type.TLiteral<"state-image-urls">]>>;
|
|
539
|
+
sendImageOptInHeader: Type.TOptional<Type.TBoolean>;
|
|
532
540
|
supportsDeveloperRole: Type.TOptional<Type.TBoolean>;
|
|
533
541
|
supportsMidConvoSystemMessages: Type.TOptional<Type.TBoolean>;
|
|
534
542
|
sessionAffinityFormat: Type.TOptional<Type.TUnion<[Type.TLiteral<"openai">, Type.TLiteral<"openai-nosession">, Type.TLiteral<"openrouter">]>>;
|
|
@@ -693,6 +701,8 @@ declare const ProviderConfigSchema: Type.TObject<{
|
|
|
693
701
|
}>>>;
|
|
694
702
|
enforcesPreservedThinkingBinding: Type.TOptional<Type.TBoolean>;
|
|
695
703
|
delegatesThinkingModelBinding: Type.TOptional<Type.TBoolean>;
|
|
704
|
+
imageInput: Type.TOptional<Type.TUnion<[Type.TLiteral<"assets">, Type.TLiteral<"images">, Type.TLiteral<"state-image-urls">]>>;
|
|
705
|
+
sendImageOptInHeader: Type.TOptional<Type.TBoolean>;
|
|
696
706
|
supportsDeveloperRole: Type.TOptional<Type.TBoolean>;
|
|
697
707
|
supportsMidConvoSystemMessages: Type.TOptional<Type.TBoolean>;
|
|
698
708
|
sessionAffinityFormat: Type.TOptional<Type.TUnion<[Type.TLiteral<"openai">, Type.TLiteral<"openai-nosession">, Type.TLiteral<"openrouter">]>>;
|
|
@@ -854,6 +864,8 @@ declare const ProviderConfigSchema: Type.TObject<{
|
|
|
854
864
|
}>>>;
|
|
855
865
|
enforcesPreservedThinkingBinding: Type.TOptional<Type.TBoolean>;
|
|
856
866
|
delegatesThinkingModelBinding: Type.TOptional<Type.TBoolean>;
|
|
867
|
+
imageInput: Type.TOptional<Type.TUnion<[Type.TLiteral<"assets">, Type.TLiteral<"images">, Type.TLiteral<"state-image-urls">]>>;
|
|
868
|
+
sendImageOptInHeader: Type.TOptional<Type.TBoolean>;
|
|
857
869
|
supportsDeveloperRole: Type.TOptional<Type.TBoolean>;
|
|
858
870
|
supportsMidConvoSystemMessages: Type.TOptional<Type.TBoolean>;
|
|
859
871
|
sessionAffinityFormat: Type.TOptional<Type.TUnion<[Type.TLiteral<"openai">, Type.TLiteral<"openai-nosession">, Type.TLiteral<"openrouter">]>>;
|
|
@@ -969,6 +981,8 @@ export declare const ModelsConfigSchema: Type.TObject<{
|
|
|
969
981
|
}>>>;
|
|
970
982
|
enforcesPreservedThinkingBinding: Type.TOptional<Type.TBoolean>;
|
|
971
983
|
delegatesThinkingModelBinding: Type.TOptional<Type.TBoolean>;
|
|
984
|
+
imageInput: Type.TOptional<Type.TUnion<[Type.TLiteral<"assets">, Type.TLiteral<"images">, Type.TLiteral<"state-image-urls">]>>;
|
|
985
|
+
sendImageOptInHeader: Type.TOptional<Type.TBoolean>;
|
|
972
986
|
supportsDeveloperRole: Type.TOptional<Type.TBoolean>;
|
|
973
987
|
supportsMidConvoSystemMessages: Type.TOptional<Type.TBoolean>;
|
|
974
988
|
sessionAffinityFormat: Type.TOptional<Type.TUnion<[Type.TLiteral<"openai">, Type.TLiteral<"openai-nosession">, Type.TLiteral<"openrouter">]>>;
|
|
@@ -1133,6 +1147,8 @@ export declare const ModelsConfigSchema: Type.TObject<{
|
|
|
1133
1147
|
}>>>;
|
|
1134
1148
|
enforcesPreservedThinkingBinding: Type.TOptional<Type.TBoolean>;
|
|
1135
1149
|
delegatesThinkingModelBinding: Type.TOptional<Type.TBoolean>;
|
|
1150
|
+
imageInput: Type.TOptional<Type.TUnion<[Type.TLiteral<"assets">, Type.TLiteral<"images">, Type.TLiteral<"state-image-urls">]>>;
|
|
1151
|
+
sendImageOptInHeader: Type.TOptional<Type.TBoolean>;
|
|
1136
1152
|
supportsDeveloperRole: Type.TOptional<Type.TBoolean>;
|
|
1137
1153
|
supportsMidConvoSystemMessages: Type.TOptional<Type.TBoolean>;
|
|
1138
1154
|
sessionAffinityFormat: Type.TOptional<Type.TUnion<[Type.TLiteral<"openai">, Type.TLiteral<"openai-nosession">, Type.TLiteral<"openrouter">]>>;
|
|
@@ -1294,6 +1310,8 @@ export declare const ModelsConfigSchema: Type.TObject<{
|
|
|
1294
1310
|
}>>>;
|
|
1295
1311
|
enforcesPreservedThinkingBinding: Type.TOptional<Type.TBoolean>;
|
|
1296
1312
|
delegatesThinkingModelBinding: Type.TOptional<Type.TBoolean>;
|
|
1313
|
+
imageInput: Type.TOptional<Type.TUnion<[Type.TLiteral<"assets">, Type.TLiteral<"images">, Type.TLiteral<"state-image-urls">]>>;
|
|
1314
|
+
sendImageOptInHeader: Type.TOptional<Type.TBoolean>;
|
|
1297
1315
|
supportsDeveloperRole: Type.TOptional<Type.TBoolean>;
|
|
1298
1316
|
supportsMidConvoSystemMessages: Type.TOptional<Type.TBoolean>;
|
|
1299
1317
|
sessionAffinityFormat: Type.TOptional<Type.TUnion<[Type.TLiteral<"openai">, Type.TLiteral<"openai-nosession">, Type.TLiteral<"openrouter">]>>;
|
|
@@ -1409,6 +1427,8 @@ export declare const ModelsJsonSchemas: {
|
|
|
1409
1427
|
}>>>;
|
|
1410
1428
|
enforcesPreservedThinkingBinding: Type.TOptional<Type.TBoolean>;
|
|
1411
1429
|
delegatesThinkingModelBinding: Type.TOptional<Type.TBoolean>;
|
|
1430
|
+
imageInput: Type.TOptional<Type.TUnion<[Type.TLiteral<"assets">, Type.TLiteral<"images">, Type.TLiteral<"state-image-urls">]>>;
|
|
1431
|
+
sendImageOptInHeader: Type.TOptional<Type.TBoolean>;
|
|
1412
1432
|
supportsDeveloperRole: Type.TOptional<Type.TBoolean>;
|
|
1413
1433
|
supportsMidConvoSystemMessages: Type.TOptional<Type.TBoolean>;
|
|
1414
1434
|
sessionAffinityFormat: Type.TOptional<Type.TUnion<[Type.TLiteral<"openai">, Type.TLiteral<"openai-nosession">, Type.TLiteral<"openrouter">]>>;
|
|
@@ -1573,6 +1593,8 @@ export declare const ModelsJsonSchemas: {
|
|
|
1573
1593
|
}>>>;
|
|
1574
1594
|
enforcesPreservedThinkingBinding: Type.TOptional<Type.TBoolean>;
|
|
1575
1595
|
delegatesThinkingModelBinding: Type.TOptional<Type.TBoolean>;
|
|
1596
|
+
imageInput: Type.TOptional<Type.TUnion<[Type.TLiteral<"assets">, Type.TLiteral<"images">, Type.TLiteral<"state-image-urls">]>>;
|
|
1597
|
+
sendImageOptInHeader: Type.TOptional<Type.TBoolean>;
|
|
1576
1598
|
supportsDeveloperRole: Type.TOptional<Type.TBoolean>;
|
|
1577
1599
|
supportsMidConvoSystemMessages: Type.TOptional<Type.TBoolean>;
|
|
1578
1600
|
sessionAffinityFormat: Type.TOptional<Type.TUnion<[Type.TLiteral<"openai">, Type.TLiteral<"openai-nosession">, Type.TLiteral<"openrouter">]>>;
|
|
@@ -1734,6 +1756,8 @@ export declare const ModelsJsonSchemas: {
|
|
|
1734
1756
|
}>>>;
|
|
1735
1757
|
enforcesPreservedThinkingBinding: Type.TOptional<Type.TBoolean>;
|
|
1736
1758
|
delegatesThinkingModelBinding: Type.TOptional<Type.TBoolean>;
|
|
1759
|
+
imageInput: Type.TOptional<Type.TUnion<[Type.TLiteral<"assets">, Type.TLiteral<"images">, Type.TLiteral<"state-image-urls">]>>;
|
|
1760
|
+
sendImageOptInHeader: Type.TOptional<Type.TBoolean>;
|
|
1737
1761
|
supportsDeveloperRole: Type.TOptional<Type.TBoolean>;
|
|
1738
1762
|
supportsMidConvoSystemMessages: Type.TOptional<Type.TBoolean>;
|
|
1739
1763
|
sessionAffinityFormat: Type.TOptional<Type.TUnion<[Type.TLiteral<"openai">, Type.TLiteral<"openai-nosession">, Type.TLiteral<"openrouter">]>>;
|
|
@@ -1899,6 +1923,8 @@ export declare const ModelsJsonSchemas: {
|
|
|
1899
1923
|
}>>>;
|
|
1900
1924
|
enforcesPreservedThinkingBinding: Type.TOptional<Type.TBoolean>;
|
|
1901
1925
|
delegatesThinkingModelBinding: Type.TOptional<Type.TBoolean>;
|
|
1926
|
+
imageInput: Type.TOptional<Type.TUnion<[Type.TLiteral<"assets">, Type.TLiteral<"images">, Type.TLiteral<"state-image-urls">]>>;
|
|
1927
|
+
sendImageOptInHeader: Type.TOptional<Type.TBoolean>;
|
|
1902
1928
|
supportsDeveloperRole: Type.TOptional<Type.TBoolean>;
|
|
1903
1929
|
supportsMidConvoSystemMessages: Type.TOptional<Type.TBoolean>;
|
|
1904
1930
|
sessionAffinityFormat: Type.TOptional<Type.TUnion<[Type.TLiteral<"openai">, Type.TLiteral<"openai-nosession">, Type.TLiteral<"openrouter">]>>;
|
|
@@ -2060,6 +2086,8 @@ export declare const ModelsJsonSchemas: {
|
|
|
2060
2086
|
}>>>;
|
|
2061
2087
|
enforcesPreservedThinkingBinding: Type.TOptional<Type.TBoolean>;
|
|
2062
2088
|
delegatesThinkingModelBinding: Type.TOptional<Type.TBoolean>;
|
|
2089
|
+
imageInput: Type.TOptional<Type.TUnion<[Type.TLiteral<"assets">, Type.TLiteral<"images">, Type.TLiteral<"state-image-urls">]>>;
|
|
2090
|
+
sendImageOptInHeader: Type.TOptional<Type.TBoolean>;
|
|
2063
2091
|
supportsDeveloperRole: Type.TOptional<Type.TBoolean>;
|
|
2064
2092
|
supportsMidConvoSystemMessages: Type.TOptional<Type.TBoolean>;
|
|
2065
2093
|
sessionAffinityFormat: Type.TOptional<Type.TUnion<[Type.TLiteral<"openai">, Type.TLiteral<"openai-nosession">, Type.TLiteral<"openrouter">]>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-config.d.ts","sourceRoot":"","sources":["../../src/core/model-config.ts"],"names":[],"mappings":"AAAA,wDAAwD;AAWxD,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAoC5C,uGAAuG;AACvG,eAAO,MAAM,sBAAsB
|
|
1
|
+
{"version":3,"file":"model-config.d.ts","sourceRoot":"","sources":["../../src/core/model-config.ts"],"names":[],"mappings":"AAAA,wDAAwD;AAWxD,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAoC5C,uGAAuG;AACvG,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAUlC,CAAC;AAEF,QAAA,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACb,CAAC;AAIF,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,OAAO,qBAAqB,CAAC,CAAC;AACnE,MAAM,MAAM,uBAAuB,GAAG,MAAM,CAAC,OAAO,mBAAmB,CAAC,CAAC;AACzE,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAqBrE,yCAAyC;AACzC,qBAAa,WAAW;IACvB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA0C;IACpE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqB;IAE3C,OAAO,eAGN;IAED,OAAa,IAAI,CAAC,cAAc,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAsC1E;IAED,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS,CAE9D;IAED,cAAc,IAAI,SAAS,MAAM,EAAE,CAElC;IAED,QAAQ,IAAI,MAAM,GAAG,SAAS,CAE7B;CACD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AnyModel, Api, ApiKeyAuth, AssistantMessageEventStream, ClassifierApi, ImageApi, Model, OAuthAuth, OAuthCredentials, OAuthLoginCallbacks, Provider, ProviderClassifier, ProviderImages, RefreshModelsContext, SimpleStreamOptions, TranscriptContext } from "@bastani/pi-ai";
|
|
1
|
+
import type { AnyModel, Api, ApiKeyAuth, AssistantMessageEventStream, ClassifierApi, ClassifierModel, ImageApi, Model, OAuthAuth, OAuthCredentials, OAuthLoginCallbacks, Provider, ProviderClassifier, ProviderImages, RefreshModelsContext, SimpleStreamOptions, TranscriptContext } from "@bastani/pi-ai";
|
|
2
2
|
import type { ModelsJsonModelOverride, ModelsJsonProvider } from "./model-config.ts";
|
|
3
3
|
import { clearConfigValueCache } from "./resolve-config-value.ts";
|
|
4
4
|
export interface ExtensionOAuthConfig {
|
|
@@ -49,6 +49,7 @@ export interface ProviderClassifierModelConfig extends ProviderModelConfigBase {
|
|
|
49
49
|
type: "classifier";
|
|
50
50
|
api?: ClassifierApi;
|
|
51
51
|
contextWindow: number;
|
|
52
|
+
compat?: ClassifierModel<ClassifierApi>["compat"];
|
|
52
53
|
}
|
|
53
54
|
export type ProviderModelConfig = ProviderChatModelConfig | ProviderImageModelConfig | ProviderClassifierModelConfig;
|
|
54
55
|
/** Input type for the extension registerProvider API. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-composer-internal.d.ts","sourceRoot":"","sources":["../../src/core/provider-composer-internal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,QAAQ,EACR,GAAG,EACH,UAAU,EACV,2BAA2B,EAG3B,aAAa,EACb,QAAQ,EACR,KAAK,EAEL,SAAS,EACT,gBAAgB,EAChB,mBAAmB,EACnB,QAAQ,EAER,kBAAkB,EAElB,cAAc,EACd,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,KAAK,EAAmB,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACtG,OAAO,EACN,qBAAqB,EAMrB,MAAM,2BAA2B,CAAC;AAEnC,MAAM,WAAW,oBAAoB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,KAAK,CAAC,SAAS,EAAE,mBAAmB,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IACtF;;;;;;;OAOG;IACH,YAAY,CAAC,WAAW,EAAE,gBAAgB,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC5F,SAAS,CAAC,WAAW,EAAE,gBAAgB,GAAG,MAAM,CAAC;IACjD,YAAY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AAO,CAAC,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,6BAA8B,SAAQ,uBAAuB;IAC7E,IAAI,EAAE,YAAY,CAAC;IACnB,GAAG,CAAC,EAAE,aAAa,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"provider-composer-internal.d.ts","sourceRoot":"","sources":["../../src/core/provider-composer-internal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,QAAQ,EACR,GAAG,EACH,UAAU,EACV,2BAA2B,EAG3B,aAAa,EACb,eAAe,EACf,QAAQ,EACR,KAAK,EAEL,SAAS,EACT,gBAAgB,EAChB,mBAAmB,EACnB,QAAQ,EAER,kBAAkB,EAElB,cAAc,EACd,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,KAAK,EAAmB,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACtG,OAAO,EACN,qBAAqB,EAMrB,MAAM,2BAA2B,CAAC;AAEnC,MAAM,WAAW,oBAAoB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,KAAK,CAAC,SAAS,EAAE,mBAAmB,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IACtF;;;;;;;OAOG;IACH,YAAY,CAAC,WAAW,EAAE,gBAAgB,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC5F,SAAS,CAAC,WAAW,EAAE,gBAAgB,GAAG,MAAM,CAAC;IACjD,YAAY,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,EAAE,WAAW,EAAE,gBAAgB,GAAG,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;CACjF;AAED,UAAU,uBAAuB;IAChC,EAAE,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ACtC,SAAS,EAAE,mBAAmB,GAAG,SAAS,GACxC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAWpC"}
|
|
@@ -133,13 +133,15 @@ export function applyModelsJson(providerId, baseModels, config) {
|
|
|
133
133
|
config.authHeader === undefined) {
|
|
134
134
|
throw new Error(`Provider ${providerId}: must specify "baseUrl", "headers", "compat", "modelOverrides", or "models".`);
|
|
135
135
|
}
|
|
136
|
-
const models = baseModels.map((model) =>
|
|
137
|
-
?
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
136
|
+
const models = baseModels.map((model) => {
|
|
137
|
+
const baseUrl = config.oauth === "radius" ? model.baseUrl : (config.baseUrl ?? model.baseUrl);
|
|
138
|
+
if (isModelType(model, "chat"))
|
|
139
|
+
return { ...model, baseUrl, compat: mergeCompat(model.compat, config.compat) };
|
|
140
|
+
if (isModelType(model, "classifier") && config.compat) {
|
|
141
|
+
return { ...model, baseUrl, compat: { ...model.compat, ...config.compat } };
|
|
141
142
|
}
|
|
142
|
-
|
|
143
|
+
return { ...model, baseUrl };
|
|
144
|
+
});
|
|
143
145
|
for (const definition of config.models ?? []) {
|
|
144
146
|
const existingIndex = models.findIndex((model) => isModelType(model, "chat") && model.id === definition.id);
|
|
145
147
|
const defaults = findModelDefaults(models.filter((model) => isModelType(model, "chat")), definition.id, definition.api ?? config.api ?? (providerId === "azure" ? "azure-openai-responses" : undefined));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-composer-internal.js","sourceRoot":"","sources":["../../src/core/provider-composer-internal.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,yBAAyB,EAAE,MAAM,wCAAwC,CAAC;AAEnF,OAAO,EACN,qBAAqB,EACrB,yBAAyB,EACzB,oBAAoB,EACpB,uBAAuB,EACvB,yBAAyB,EACzB,qBAAqB,GACrB,MAAM,2BAA2B,CAAC;AAqF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AAC,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACnH,MAAM,cAAc,GAAG,SAAS,EAAE,MAAM,EAAE,IAAI,CAC7C,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,KAAK,CAAC,EAAE,KAAK,KAAK,CAAC,EAAE,CACrF,CAAC;IACF,MAAM,OAAO,GAAG;QACf,GAAG,CAAC,WAAW,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;QACzF,GAAG,UAAU,EAAE,OAAO;QACtB,GAAG,cAAc,EAAE,OAAO;KAC1B,CAAC;IACF,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;AAC9D,CAAC","sourcesContent":["import type {\n\tAnyModel,\n\tApi,\n\tApiKeyAuth,\n\tAssistantMessageEventStream,\n\tAuthContext,\n\tAuthResult,\n\tClassifierApi,\n\tImageApi,\n\tModel,\n\tModelAuth,\n\tOAuthAuth,\n\tOAuthCredentials,\n\tOAuthLoginCallbacks,\n\tProvider,\n\tProviderAuthInteraction,\n\tProviderClassifier,\n\tProviderHeaders,\n\tProviderImages,\n\tRefreshModelsContext,\n\tSimpleStreamOptions,\n\tTranscriptContext,\n} from \"@bastani/pi-ai\";\nimport { isModelType } from \"@bastani/pi-ai\";\nimport { extensionRefreshRejection } from \"./extension-oauth-refresh-rejection.ts\";\nimport type { ModelsJsonModel, ModelsJsonModelOverride, ModelsJsonProvider } from \"./model-config.ts\";\nimport {\n\tclearConfigValueCache,\n\tgetConfigValueEnvVarNames,\n\tisCommandConfigValue,\n\tisConfigValueConfigured,\n\tresolveConfigValueOrThrow,\n\tresolveHeadersOrThrow,\n} from \"./resolve-config-value.ts\";\n\nexport interface ExtensionOAuthConfig {\n\tname: string;\n\tloginLabel?: string;\n\tusesCallbackServer?: boolean;\n\tlogin(callbacks: OAuthLoginCallbacks, signal: AbortSignal): Promise<OAuthCredentials>;\n\t/**\n\t * Refresh expired credentials. Pass `signal` to the network call, but add no timeout or abort of your own: Atomic\n\t * never aborts it on a timeout, because once the request is sent the provider may already have rotated the\n\t * refresh token. The caller stops waiting after 60 seconds; a later result is still saved, and a graceful exit\n\t * waits briefly for it. It is a required parameter so the contract is stated in the type.\n\t * Throw `OAuthRefreshRejectedError` when the provider rejected the stored login; common error shapes are mapped\n\t * onto it (see `extensionRefreshRejection`).\n\t */\n\trefreshToken(credentials: OAuthCredentials, signal: AbortSignal): Promise<OAuthCredentials>;\n\tgetApiKey(credentials: OAuthCredentials): string;\n\tmodifyModels?(models: Model<Api>[], credentials: OAuthCredentials): Model<Api>[];\n}\n\ninterface ProviderModelConfigBase {\n\tid: string;\n\tname: string;\n\tapi?: string;\n\tbaseUrl?: string;\n\tinput: AnyModel[\"input\"];\n\tinputLimits?: AnyModel[\"inputLimits\"];\n\tcost: AnyModel[\"cost\"];\n\theaders?: Record<string, string>;\n}\n\nexport interface ProviderChatModelConfig extends ProviderModelConfigBase {\n\ttype?: \"chat\";\n\tapi?: Api;\n\treasoning: boolean;\n\tthinkingLevelMap?: Model<Api>[\"thinkingLevelMap\"];\n\tpromptCache?: Model<Api>[\"promptCache\"];\n\tcontextWindow: number;\n\tmaxTokens: number;\n\tsamplingParams?: Model<Api>[\"samplingParams\"];\n\tsamplingParamsByThinkingLevel?: Model<Api>[\"samplingParamsByThinkingLevel\"];\n\tcompat?: Model<Api>[\"compat\"];\n}\n\nexport interface ProviderImageModelConfig extends ProviderModelConfigBase {\n\ttype: \"image\";\n\tapi?: ImageApi;\n\toutput: (\"text\" | \"image\")[];\n}\n\nexport interface ProviderClassifierModelConfig extends ProviderModelConfigBase {\n\ttype: \"classifier\";\n\tapi?: ClassifierApi;\n\tcontextWindow: number;\n}\n\nexport type ProviderModelConfig = ProviderChatModelConfig | ProviderImageModelConfig | ProviderClassifierModelConfig;\n\n/** Input type for the extension registerProvider API. */\nexport interface ProviderConfigInput {\n\tname?: string;\n\taliasOf?: string;\n\tbaseUrl?: string;\n\tapiKey?: string;\n\tapi?: Api;\n\tstreamSimple?: (\n\t\tmodel: Model<Api>,\n\t\tcontext: TranscriptContext,\n\t\toptions?: SimpleStreamOptions,\n\t) => AssistantMessageEventStream;\n\timages?: Partial<Record<ImageApi, ProviderImages>>;\n\tclassifiers?: Partial<Record<ClassifierApi, ProviderClassifier>>;\n\theaders?: Record<string, string>;\n\tauthHeader?: boolean;\n\toauth?: ExtensionOAuthConfig;\n\tmodels?: ProviderModelConfig[];\n\trefreshModels?(context: RefreshModelsContext): Promise<NonNullable<ProviderConfigInput[\"models\"]>>;\n}\n\nexport type AuthStatus = {\n\tconfigured: boolean;\n\tsource?: \"stored\" | \"runtime\" | \"environment\" | \"fallback\" | \"models_json_key\" | \"models_json_command\";\n\tlabel?: string;\n};\n\nexport const clearApiKeyCache = clearConfigValueCache;\n\nfunction mergeCompat(\n\tbase: Model<Api>[\"compat\"],\n\toverride: Model<Api>[\"compat\"] | ModelsJsonModelOverride[\"compat\"],\n): Model<Api>[\"compat\"] {\n\tif (!override) return base;\n\tconst merged = { ...base, ...override } as NonNullable<Model<Api>[\"compat\"]>;\n\tconst baseNested = base as Record<string, unknown> | undefined;\n\tconst overrideNested = override as Record<string, unknown>;\n\tconst mergedNested = merged as Record<string, unknown>;\n\tfor (const key of [\"openRouterRouting\", \"vercelGatewayRouting\", \"chatTemplateKwargs\", \"chatTemplateArgs\"] as const) {\n\t\tconst baseValue = baseNested?.[key];\n\t\tconst overrideValue = overrideNested[key];\n\t\tif (\n\t\t\t(typeof baseValue === \"object\" && baseValue !== null) ||\n\t\t\t(typeof overrideValue === \"object\" && overrideValue !== null)\n\t\t) {\n\t\t\tmergedNested[key] = { ...(baseValue as object | undefined), ...(overrideValue as object | undefined) };\n\t\t}\n\t}\n\treturn merged;\n}\n\nfunction mergeInputLimits(\n\tbase: Model<Api>[\"inputLimits\"],\n\toverride: ModelsJsonModelOverride[\"inputLimits\"],\n): Model<Api>[\"inputLimits\"] {\n\tif (!override) return base;\n\treturn {\n\t\t...base,\n\t\t...override,\n\t\timages: override.images\n\t\t\t? {\n\t\t\t\t\t...base?.images,\n\t\t\t\t\t...override.images,\n\t\t\t\t\tresize: override.images.resize\n\t\t\t\t\t\t? { ...base?.images?.resize, ...override.images.resize }\n\t\t\t\t\t\t: base?.images?.resize,\n\t\t\t\t}\n\t\t\t: base?.images,\n\t};\n}\n\nfunction mergeSamplingParamsByThinkingLevel(\n\tbase: Model<Api>[\"samplingParamsByThinkingLevel\"],\n\toverride: Model<Api>[\"samplingParamsByThinkingLevel\"],\n): Model<Api>[\"samplingParamsByThinkingLevel\"] {\n\tif (!override) return base;\n\tconst merged = { ...base };\n\tfor (const level of [\"off\", \"minimal\", \"low\", \"medium\", \"high\", \"xhigh\", \"max\"] as const) {\n\t\tconst params = override[level];\n\t\tif (params) merged[level] = { ...base?.[level], ...params };\n\t}\n\treturn merged;\n}\n\nexport function applyModelOverride(model: Model<Api>, override: ModelsJsonModelOverride): Model<Api> {\n\treturn {\n\t\t...model,\n\t\tpromptCache: override.promptCache ? { ...model.promptCache, ...override.promptCache } : model.promptCache,\n\t\tname: override.name ?? model.name,\n\t\treasoning: override.reasoning ?? model.reasoning,\n\t\tthinkingLevelMap: override.thinkingLevelMap\n\t\t\t? { ...model.thinkingLevelMap, ...override.thinkingLevelMap }\n\t\t\t: model.thinkingLevelMap,\n\t\tinput: (override.input as Model<Api>[\"input\"] | undefined) ?? model.input,\n\t\tinputLimits: mergeInputLimits(model.inputLimits, override.inputLimits),\n\t\tcost: override.cost\n\t\t\t? {\n\t\t\t\t\tinput: override.cost.input ?? model.cost.input,\n\t\t\t\t\toutput: override.cost.output ?? model.cost.output,\n\t\t\t\t\tcacheRead: override.cost.cacheRead ?? model.cost.cacheRead,\n\t\t\t\t\tcacheWrite: override.cost.cacheWrite ?? model.cost.cacheWrite,\n\t\t\t\t\ttiers: override.cost.tiers ?? model.cost.tiers,\n\t\t\t\t}\n\t\t\t: model.cost,\n\t\tcontextWindow: override.contextWindow ?? model.contextWindow,\n\t\tmaxTokens: override.maxTokens ?? model.maxTokens,\n\t\tsamplingParams: override.samplingParams\n\t\t\t? { ...model.samplingParams, ...override.samplingParams }\n\t\t\t: model.samplingParams,\n\t\tsamplingParamsByThinkingLevel: mergeSamplingParamsByThinkingLevel(\n\t\t\tmodel.samplingParamsByThinkingLevel,\n\t\t\toverride.samplingParamsByThinkingLevel,\n\t\t),\n\t\tcompat: mergeCompat(model.compat, override.compat),\n\t};\n}\n\nfunction modelFromJson(\n\tproviderId: string,\n\tdefinition: ModelsJsonModel,\n\tproviderConfig: ModelsJsonProvider,\n\tdefaults: Model<Api> | undefined,\n): Model<Api> {\n\tconst api = definition.api ?? providerConfig.api ?? defaults?.api;\n\tif (!api) {\n\t\tthrow new Error(\n\t\t\t`Provider ${providerId}, model ${definition.id}: no \"api\" specified. Set at provider or model level.`,\n\t\t);\n\t}\n\tconst baseUrl = definition.baseUrl ?? providerConfig.baseUrl ?? defaults?.baseUrl;\n\tif (!baseUrl) throw new Error(`Provider ${providerId}: \"baseUrl\" is required when defining custom models.`);\n\tif (definition.contextWindow !== undefined && definition.contextWindow <= 0) {\n\t\tthrow new Error(`Provider ${providerId}, model ${definition.id}: invalid contextWindow`);\n\t}\n\tif (definition.maxTokens !== undefined && definition.maxTokens <= 0) {\n\t\tthrow new Error(`Provider ${providerId}, model ${definition.id}: invalid maxTokens`);\n\t}\n\treturn {\n\t\tid: definition.id,\n\t\tname: definition.name ?? definition.id,\n\t\tapi: api as Api,\n\t\tprovider: providerId,\n\t\tbaseUrl,\n\t\treasoning: definition.reasoning ?? false,\n\t\tthinkingLevelMap: definition.thinkingLevelMap,\n\t\tinput: (definition.input ?? [\"text\"]) as Model<Api>[\"input\"],\n\t\tinputLimits: definition.inputLimits,\n\t\tcost: definition.cost ?? { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },\n\t\tpromptCache: definition.promptCache,\n\t\tcontextWindow: definition.contextWindow ?? 128000,\n\t\tmaxTokens: definition.maxTokens ?? 16384,\n\t\tsamplingParams: definition.samplingParams,\n\t\tsamplingParamsByThinkingLevel: definition.samplingParamsByThinkingLevel,\n\t\theaders: undefined,\n\t\tcompat: mergeCompat(providerConfig.compat, definition.compat),\n\t};\n}\n\nfunction findModelDefaults(models: readonly Model<Api>[], modelId: string, api?: Api): Model<Api> | undefined {\n\treturn (\n\t\tmodels.find((model) => model.id === modelId) ??\n\t\t(api ? models.find((model) => model.api === api) : undefined) ??\n\t\tmodels.find((model) => model.api === \"openai-completions\") ??\n\t\tmodels[0]\n\t);\n}\n\nexport function applyModelsJson(\n\tproviderId: string,\n\tbaseModels: readonly AnyModel[],\n\tconfig: ModelsJsonProvider | undefined,\n): AnyModel[] {\n\tif (!config) return [...baseModels];\n\tif (config.oauth && !config.baseUrl) {\n\t\tthrow new Error(`Provider ${providerId}: \"baseUrl\" is required when \"oauth\" is set.`);\n\t}\n\tconst hasOverrides = config.modelOverrides && Object.keys(config.modelOverrides).length > 0;\n\tif (\n\t\t!config.models?.length &&\n\t\t!config.baseUrl &&\n\t\t!config.headers &&\n\t\t!config.compat &&\n\t\t!hasOverrides &&\n\t\t!config.apiKey &&\n\t\t!config.oauth &&\n\t\tconfig.authHeader === undefined\n\t) {\n\t\tthrow new Error(\n\t\t\t`Provider ${providerId}: must specify \"baseUrl\", \"headers\", \"compat\", \"modelOverrides\", or \"models\".`,\n\t\t);\n\t}\n\n\tconst models: AnyModel[] = baseModels.map((model) =>\n\t\tisModelType(model, \"chat\")\n\t\t\t? {\n\t\t\t\t\t...model,\n\t\t\t\t\tbaseUrl: config.oauth === \"radius\" ? model.baseUrl : (config.baseUrl ?? model.baseUrl),\n\t\t\t\t\tcompat: mergeCompat(model.compat, config.compat),\n\t\t\t\t}\n\t\t\t: { ...model, baseUrl: config.oauth === \"radius\" ? model.baseUrl : (config.baseUrl ?? model.baseUrl) },\n\t);\n\tfor (const definition of config.models ?? []) {\n\t\tconst existingIndex = models.findIndex((model) => isModelType(model, \"chat\") && model.id === definition.id);\n\t\tconst defaults = findModelDefaults(\n\t\t\tmodels.filter((model) => isModelType(model, \"chat\")),\n\t\t\tdefinition.id,\n\t\t\tdefinition.api ?? config.api ?? (providerId === \"azure\" ? \"azure-openai-responses\" : undefined),\n\t\t);\n\t\tconst model = modelFromJson(providerId, definition, config, defaults);\n\t\tif (existingIndex >= 0) models[existingIndex] = model;\n\t\telse models.push(model);\n\t}\n\treturn models;\n}\n\nexport function applyExtension(\n\tproviderId: string,\n\tmodels: readonly AnyModel[],\n\tconfig: ProviderConfigInput | undefined,\n): AnyModel[] {\n\tif (!config) return [...models];\n\tif (!config.models) {\n\t\treturn config.baseUrl ? models.map((model) => ({ ...model, baseUrl: config.baseUrl! })) : [...models];\n\t}\n\treturn config.models.map((definition) => {\n\t\tconst type = definition.type ?? \"chat\";\n\t\tconst candidates = models.filter((model) => isModelType(model, type));\n\t\tconst defaults =\n\t\t\tcandidates.find((model) => model.id === definition.id) ??\n\t\t\t(definition.api ? candidates.find((model) => model.api === definition.api) : undefined) ??\n\t\t\t(type === \"chat\" && providerId === \"azure\"\n\t\t\t\t? candidates.find((model) => model.api === \"azure-openai-responses\")\n\t\t\t\t: undefined) ??\n\t\t\t(type === \"chat\" ? candidates.find((model) => model.api === \"openai-completions\") : undefined) ??\n\t\t\tcandidates[0];\n\t\tconst api = definition.api ?? (type === \"chat\" ? config.api : undefined) ?? defaults?.api;\n\t\tif (!api) {\n\t\t\tthrow new Error(\n\t\t\t\t`Provider ${providerId}, model ${definition.id}: no \"api\" specified. Set it at model level${type === \"chat\" ? \" or provider level\" : \"\"}.`,\n\t\t\t);\n\t\t}\n\t\tconst baseUrl = definition.baseUrl ?? config.baseUrl ?? defaults?.baseUrl;\n\t\tif (!baseUrl) throw new Error(`Provider ${providerId}: \"baseUrl\" is required when defining custom models.`);\n\t\treturn { ...definition, api, provider: providerId, baseUrl, headers: undefined } as AnyModel;\n\t});\n}\n\nfunction adaptOAuth(config: ExtensionOAuthConfig): OAuthAuth {\n\treturn {\n\t\tname: config.name,\n\t\tlogin: async (callbacks) => {\n\t\t\tconst legacyCallbacks: OAuthLoginCallbacks & {\n\t\t\t\tonInfo(message: string, links: readonly { label?: string; url: string }[]): void;\n\t\t\t} = {\n\t\t\t\tonAuth: (info) => callbacks.notify({ type: \"auth_url\", ...info }),\n\t\t\t\tonDeviceCode: (info) => callbacks.notify({ type: \"device_code\", ...info }),\n\t\t\t\tonPrompt: (prompt) => callbacks.prompt({ type: \"text\", ...prompt }),\n\t\t\t\tonProgress: (message) => callbacks.notify({ type: \"progress\", message }),\n\t\t\t\tonInfo: (message, links) => callbacks.notify({ type: \"info\", message, links }),\n\t\t\t\tonManualCodeInput: () => callbacks.prompt({ type: \"manual_code\", message: \"Paste the authorization code\" }),\n\t\t\t\tonSelect: (prompt) => callbacks.prompt({ type: \"select\", ...prompt }),\n\t\t\t\tsignal: callbacks.signal,\n\t\t\t};\n\t\t\tconst credential = await config.login(legacyCallbacks, callbacks.signal);\n\t\t\treturn { ...credential, type: \"oauth\" };\n\t\t},\n\t\trefresh: async (credential, signal) => {\n\t\t\ttry {\n\t\t\t\treturn { ...(await config.refreshToken(credential, signal)), type: \"oauth\" };\n\t\t\t} catch (error) {\n\t\t\t\tthrow extensionRefreshRejection(error, credential, config.name) ?? error;\n\t\t\t}\n\t\t},\n\t\ttoAuth: async (credential) => ({ apiKey: config.getApiKey(credential) }),\n\t};\n}\n\nfunction withConfiguredAuth(\n\tauth: ModelAuth,\n\theaders: Record<string, string> | undefined,\n\tauthHeader: boolean,\n): ModelAuth {\n\tlet mergedHeaders: ProviderHeaders | undefined =\n\t\tauth.headers || headers ? { ...auth.headers, ...headers } : undefined;\n\tif (authHeader) {\n\t\tif (!auth.apiKey) throw new Error(\"authHeader requires a resolved API key\");\n\t\tmergedHeaders = { ...mergedHeaders, Authorization: `Bearer ${auth.apiKey}` };\n\t}\n\treturn { ...auth, headers: mergedHeaders };\n}\n\nexport function configuredApiKey(\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): string | undefined {\n\treturn extension?.apiKey ?? config?.apiKey;\n}\n\nexport function configuredHeaders(\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): Record<string, string> | undefined {\n\tif (!config?.headers && !extension?.headers) return undefined;\n\treturn { ...config?.headers, ...extension?.headers };\n}\n\nasync function configContextEnv(\n\tvalues: readonly string[],\n\tctx: AuthContext,\n\texplicit?: Record<string, string>,\n): Promise<Record<string, string> | undefined> {\n\tconst env = { ...explicit };\n\tfor (const name of new Set(values.flatMap(getConfigValueEnvVarNames))) {\n\t\tif (env[name] !== undefined) continue;\n\t\tconst value = await ctx.env(name);\n\t\tif (value !== undefined) env[name] = value;\n\t}\n\treturn Object.keys(env).length > 0 ? env : undefined;\n}\n\nexport function composeApiKeyAuth(\n\tproviderId: string,\n\tbase: Provider | undefined,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): ApiKeyAuth | undefined {\n\tconst inherited = base?.auth.apiKey;\n\tconst rawKey = configuredApiKey(config, extension);\n\tconst oauth = extension?.oauth ?? base?.auth.oauth;\n\t// OAuth-only providers get no fabricated API-key login method.\n\tif (!inherited && rawKey === undefined && oauth) return undefined;\n\tconst rawHeaders = configuredHeaders(config, extension);\n\tconst authHeader = extension?.authHeader ?? config?.authHeader ?? false;\n\treturn {\n\t\tname: inherited?.name ?? \"API key\",\n\t\t// A configured key replaces borrowed credentials; a base without a login gains none.\n\t\tborrowCredentialsFrom: rawKey === undefined ? inherited?.borrowCredentialsFrom : undefined,\n\t\tlogin: inherited\n\t\t\t? inherited.login\n\t\t\t: async (interaction: ProviderAuthInteraction) => ({\n\t\t\t\t\ttype: \"api_key\",\n\t\t\t\t\tkey: await interaction.prompt({ type: \"secret\", message: \"Enter API key\" }),\n\t\t\t\t}),\n\t\tcheck: async (input) => {\n\t\t\tif (input.credential) {\n\t\t\t\tif (inherited?.check) return inherited.check(input);\n\t\t\t\tif (input.credential.key) return { type: \"api_key\", source: \"stored credential\" };\n\t\t\t\tconst resolved = await inherited?.resolve(input);\n\t\t\t\treturn resolved ? { type: \"api_key\", source: resolved.source } : undefined;\n\t\t\t}\n\t\t\tif (rawKey !== undefined) {\n\t\t\t\tif (isCommandConfigValue(rawKey)) return { type: \"api_key\", source: \"configured API key\" };\n\t\t\t\tconst envNames = getConfigValueEnvVarNames(rawKey);\n\t\t\t\tfor (const name of envNames) {\n\t\t\t\t\tif ((await input.ctx.env(name)) === undefined) return undefined;\n\t\t\t\t}\n\t\t\t\treturn { type: \"api_key\", source: \"configured API key\" };\n\t\t\t}\n\t\t\tif (inherited?.check) return inherited.check(input);\n\t\t\tconst resolved = await inherited?.resolve(input);\n\t\t\treturn resolved ? { type: \"api_key\", source: resolved.source } : undefined;\n\t\t},\n\t\tresolve: async (input) => {\n\t\t\tlet result: AuthResult | undefined;\n\t\t\tif (input.credential) {\n\t\t\t\tresult = inherited\n\t\t\t\t\t? await inherited.resolve(input)\n\t\t\t\t\t: input.credential.key\n\t\t\t\t\t\t? { auth: { apiKey: input.credential.key }, env: input.credential.env, source: \"stored credential\" }\n\t\t\t\t\t\t: undefined;\n\t\t\t} else if (rawKey !== undefined) {\n\t\t\t\tconst env = await configContextEnv([rawKey], input.ctx);\n\t\t\t\t// Like a built-in whose key variable is unset, an unset `$VAR` key means no credential, not an error.\n\t\t\t\tif (!isCommandConfigValue(rawKey) && !isConfigValueConfigured(rawKey, env)) return undefined;\n\t\t\t\tconst key = resolveConfigValueOrThrow(rawKey, `API key for provider \"${providerId}\"`, env);\n\t\t\t\tresult = inherited\n\t\t\t\t\t? await inherited.resolve({ ...input, credential: { type: \"api_key\", key } })\n\t\t\t\t\t: { auth: { apiKey: key }, source: \"configured API key\" };\n\t\t\t} else {\n\t\t\t\tresult = await inherited?.resolve(input);\n\t\t\t}\n\t\t\tif (!result) return undefined;\n\t\t\tconst explicitEnv = { ...(input.credential?.env ?? {}), ...(result.env ?? {}) };\n\t\t\tconst headerEnv = await configContextEnv(Object.values(rawHeaders ?? {}), input.ctx, explicitEnv);\n\t\t\tconst headers = resolveHeadersOrThrow(rawHeaders, `provider \"${providerId}\"`, headerEnv);\n\t\t\treturn { ...result, auth: withConfiguredAuth(result.auth, headers, authHeader) };\n\t\t},\n\t};\n}\n\nexport function composeOAuthAuth(\n\tproviderId: string,\n\tbase: Provider | undefined,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): OAuthAuth | undefined {\n\tconst oauth = extension?.oauth ? adaptOAuth(extension.oauth) : base?.auth.oauth;\n\tif (!oauth) return undefined;\n\tconst rawHeaders = configuredHeaders(config, extension);\n\tconst authHeader = extension?.authHeader ?? config?.authHeader ?? false;\n\treturn {\n\t\t...oauth,\n\t\ttoAuth: async (credential) => {\n\t\t\tconst auth = await oauth.toAuth(credential);\n\t\t\tconst env = credential.env;\n\t\t\tconst headers = resolveHeadersOrThrow(\n\t\t\t\trawHeaders,\n\t\t\t\t`provider \"${providerId}\"`,\n\t\t\t\ttypeof env === \"object\" && env !== null ? (env as Record<string, string>) : undefined,\n\t\t\t);\n\t\t\treturn withConfiguredAuth(auth, headers, authHeader);\n\t\t},\n\t};\n}\n\nexport function rawModelHeaders(\n\tmodel: AnyModel,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): Record<string, string> | undefined {\n\tconst definition = isModelType(model, \"chat\") ? config?.models?.find((entry) => entry.id === model.id) : undefined;\n\tconst extensionModel = extension?.models?.find(\n\t\t(entry) => (entry.type ?? \"chat\") === (model.type ?? \"chat\") && entry.id === model.id,\n\t);\n\tconst headers = {\n\t\t...(isModelType(model, \"chat\") ? config?.modelOverrides?.[model.id]?.headers : undefined),\n\t\t...definition?.headers,\n\t\t...extensionModel?.headers,\n\t};\n\treturn Object.keys(headers).length > 0 ? headers : undefined;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"provider-composer-internal.js","sourceRoot":"","sources":["../../src/core/provider-composer-internal.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,yBAAyB,EAAE,MAAM,wCAAwC,CAAC;AAEnF,OAAO,EACN,qBAAqB,EACrB,yBAAyB,EACzB,oBAAoB,EACpB,uBAAuB,EACvB,yBAAyB,EACzB,qBAAqB,GACrB,MAAM,2BAA2B,CAAC;AAsFnC,MAAM,CAAC,MAAM,gBAAgB,GAAG,qBAAqB,CAAC;AAEtD,SAAS,WAAW,CACnB,IAA0B,EAC1B,QAAkE;IAElE,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC3B,MAAM,MAAM,GAAG,EAAE,GAAG,IAAI,EAAE,GAAG,QAAQ,EAAuC,CAAC;IAC7E,MAAM,UAAU,GAAG,IAA2C,CAAC;IAC/D,MAAM,cAAc,GAAG,QAAmC,CAAC;IAC3D,MAAM,YAAY,GAAG,MAAiC,CAAC;IACvD,KAAK,MAAM,GAAG,IAAI,CAAC,mBAAmB,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,kBAAkB,CAAU,EAAE,CAAC;QACpH,MAAM,SAAS,GAAG,UAAU,EAAE,CAAC,GAAG,CAAC,CAAC;QACpC,MAAM,aAAa,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC;QAC1C,IACC,CAAC,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,KAAK,IAAI,CAAC;YACr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EAAE,cAAc,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;QACzF,GAAG,UAAU,EAAE,OAAO;QACtB,GAAG,cAAc,EAAE,OAAO;KAC1B,CAAC;IACF,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;AAC9D,CAAC","sourcesContent":["import type {\n\tAnyModel,\n\tApi,\n\tApiKeyAuth,\n\tAssistantMessageEventStream,\n\tAuthContext,\n\tAuthResult,\n\tClassifierApi,\n\tClassifierModel,\n\tImageApi,\n\tModel,\n\tModelAuth,\n\tOAuthAuth,\n\tOAuthCredentials,\n\tOAuthLoginCallbacks,\n\tProvider,\n\tProviderAuthInteraction,\n\tProviderClassifier,\n\tProviderHeaders,\n\tProviderImages,\n\tRefreshModelsContext,\n\tSimpleStreamOptions,\n\tTranscriptContext,\n} from \"@bastani/pi-ai\";\nimport { isModelType } from \"@bastani/pi-ai\";\nimport { extensionRefreshRejection } from \"./extension-oauth-refresh-rejection.ts\";\nimport type { ModelsJsonModel, ModelsJsonModelOverride, ModelsJsonProvider } from \"./model-config.ts\";\nimport {\n\tclearConfigValueCache,\n\tgetConfigValueEnvVarNames,\n\tisCommandConfigValue,\n\tisConfigValueConfigured,\n\tresolveConfigValueOrThrow,\n\tresolveHeadersOrThrow,\n} from \"./resolve-config-value.ts\";\n\nexport interface ExtensionOAuthConfig {\n\tname: string;\n\tloginLabel?: string;\n\tusesCallbackServer?: boolean;\n\tlogin(callbacks: OAuthLoginCallbacks, signal: AbortSignal): Promise<OAuthCredentials>;\n\t/**\n\t * Refresh expired credentials. Pass `signal` to the network call, but add no timeout or abort of your own: Atomic\n\t * never aborts it on a timeout, because once the request is sent the provider may already have rotated the\n\t * refresh token. The caller stops waiting after 60 seconds; a later result is still saved, and a graceful exit\n\t * waits briefly for it. It is a required parameter so the contract is stated in the type.\n\t * Throw `OAuthRefreshRejectedError` when the provider rejected the stored login; common error shapes are mapped\n\t * onto it (see `extensionRefreshRejection`).\n\t */\n\trefreshToken(credentials: OAuthCredentials, signal: AbortSignal): Promise<OAuthCredentials>;\n\tgetApiKey(credentials: OAuthCredentials): string;\n\tmodifyModels?(models: Model<Api>[], credentials: OAuthCredentials): Model<Api>[];\n}\n\ninterface ProviderModelConfigBase {\n\tid: string;\n\tname: string;\n\tapi?: string;\n\tbaseUrl?: string;\n\tinput: AnyModel[\"input\"];\n\tinputLimits?: AnyModel[\"inputLimits\"];\n\tcost: AnyModel[\"cost\"];\n\theaders?: Record<string, string>;\n}\n\nexport interface ProviderChatModelConfig extends ProviderModelConfigBase {\n\ttype?: \"chat\";\n\tapi?: Api;\n\treasoning: boolean;\n\tthinkingLevelMap?: Model<Api>[\"thinkingLevelMap\"];\n\tpromptCache?: Model<Api>[\"promptCache\"];\n\tcontextWindow: number;\n\tmaxTokens: number;\n\tsamplingParams?: Model<Api>[\"samplingParams\"];\n\tsamplingParamsByThinkingLevel?: Model<Api>[\"samplingParamsByThinkingLevel\"];\n\tcompat?: Model<Api>[\"compat\"];\n}\n\nexport interface ProviderImageModelConfig extends ProviderModelConfigBase {\n\ttype: \"image\";\n\tapi?: ImageApi;\n\toutput: (\"text\" | \"image\")[];\n}\n\nexport interface ProviderClassifierModelConfig extends ProviderModelConfigBase {\n\ttype: \"classifier\";\n\tapi?: ClassifierApi;\n\tcontextWindow: number;\n\tcompat?: ClassifierModel<ClassifierApi>[\"compat\"];\n}\n\nexport type ProviderModelConfig = ProviderChatModelConfig | ProviderImageModelConfig | ProviderClassifierModelConfig;\n\n/** Input type for the extension registerProvider API. */\nexport interface ProviderConfigInput {\n\tname?: string;\n\taliasOf?: string;\n\tbaseUrl?: string;\n\tapiKey?: string;\n\tapi?: Api;\n\tstreamSimple?: (\n\t\tmodel: Model<Api>,\n\t\tcontext: TranscriptContext,\n\t\toptions?: SimpleStreamOptions,\n\t) => AssistantMessageEventStream;\n\timages?: Partial<Record<ImageApi, ProviderImages>>;\n\tclassifiers?: Partial<Record<ClassifierApi, ProviderClassifier>>;\n\theaders?: Record<string, string>;\n\tauthHeader?: boolean;\n\toauth?: ExtensionOAuthConfig;\n\tmodels?: ProviderModelConfig[];\n\trefreshModels?(context: RefreshModelsContext): Promise<NonNullable<ProviderConfigInput[\"models\"]>>;\n}\n\nexport type AuthStatus = {\n\tconfigured: boolean;\n\tsource?: \"stored\" | \"runtime\" | \"environment\" | \"fallback\" | \"models_json_key\" | \"models_json_command\";\n\tlabel?: string;\n};\n\nexport const clearApiKeyCache = clearConfigValueCache;\n\nfunction mergeCompat(\n\tbase: Model<Api>[\"compat\"],\n\toverride: Model<Api>[\"compat\"] | ModelsJsonModelOverride[\"compat\"],\n): Model<Api>[\"compat\"] {\n\tif (!override) return base;\n\tconst merged = { ...base, ...override } as NonNullable<Model<Api>[\"compat\"]>;\n\tconst baseNested = base as Record<string, unknown> | undefined;\n\tconst overrideNested = override as Record<string, unknown>;\n\tconst mergedNested = merged as Record<string, unknown>;\n\tfor (const key of [\"openRouterRouting\", \"vercelGatewayRouting\", \"chatTemplateKwargs\", \"chatTemplateArgs\"] as const) {\n\t\tconst baseValue = baseNested?.[key];\n\t\tconst overrideValue = overrideNested[key];\n\t\tif (\n\t\t\t(typeof baseValue === \"object\" && baseValue !== null) ||\n\t\t\t(typeof overrideValue === \"object\" && overrideValue !== null)\n\t\t) {\n\t\t\tmergedNested[key] = { ...(baseValue as object | undefined), ...(overrideValue as object | undefined) };\n\t\t}\n\t}\n\treturn merged;\n}\n\nfunction mergeInputLimits(\n\tbase: Model<Api>[\"inputLimits\"],\n\toverride: ModelsJsonModelOverride[\"inputLimits\"],\n): Model<Api>[\"inputLimits\"] {\n\tif (!override) return base;\n\treturn {\n\t\t...base,\n\t\t...override,\n\t\timages: override.images\n\t\t\t? {\n\t\t\t\t\t...base?.images,\n\t\t\t\t\t...override.images,\n\t\t\t\t\tresize: override.images.resize\n\t\t\t\t\t\t? { ...base?.images?.resize, ...override.images.resize }\n\t\t\t\t\t\t: base?.images?.resize,\n\t\t\t\t}\n\t\t\t: base?.images,\n\t};\n}\n\nfunction mergeSamplingParamsByThinkingLevel(\n\tbase: Model<Api>[\"samplingParamsByThinkingLevel\"],\n\toverride: Model<Api>[\"samplingParamsByThinkingLevel\"],\n): Model<Api>[\"samplingParamsByThinkingLevel\"] {\n\tif (!override) return base;\n\tconst merged = { ...base };\n\tfor (const level of [\"off\", \"minimal\", \"low\", \"medium\", \"high\", \"xhigh\", \"max\"] as const) {\n\t\tconst params = override[level];\n\t\tif (params) merged[level] = { ...base?.[level], ...params };\n\t}\n\treturn merged;\n}\n\nexport function applyModelOverride(model: Model<Api>, override: ModelsJsonModelOverride): Model<Api> {\n\treturn {\n\t\t...model,\n\t\tpromptCache: override.promptCache ? { ...model.promptCache, ...override.promptCache } : model.promptCache,\n\t\tname: override.name ?? model.name,\n\t\treasoning: override.reasoning ?? model.reasoning,\n\t\tthinkingLevelMap: override.thinkingLevelMap\n\t\t\t? { ...model.thinkingLevelMap, ...override.thinkingLevelMap }\n\t\t\t: model.thinkingLevelMap,\n\t\tinput: (override.input as Model<Api>[\"input\"] | undefined) ?? model.input,\n\t\tinputLimits: mergeInputLimits(model.inputLimits, override.inputLimits),\n\t\tcost: override.cost\n\t\t\t? {\n\t\t\t\t\tinput: override.cost.input ?? model.cost.input,\n\t\t\t\t\toutput: override.cost.output ?? model.cost.output,\n\t\t\t\t\tcacheRead: override.cost.cacheRead ?? model.cost.cacheRead,\n\t\t\t\t\tcacheWrite: override.cost.cacheWrite ?? model.cost.cacheWrite,\n\t\t\t\t\ttiers: override.cost.tiers ?? model.cost.tiers,\n\t\t\t\t}\n\t\t\t: model.cost,\n\t\tcontextWindow: override.contextWindow ?? model.contextWindow,\n\t\tmaxTokens: override.maxTokens ?? model.maxTokens,\n\t\tsamplingParams: override.samplingParams\n\t\t\t? { ...model.samplingParams, ...override.samplingParams }\n\t\t\t: model.samplingParams,\n\t\tsamplingParamsByThinkingLevel: mergeSamplingParamsByThinkingLevel(\n\t\t\tmodel.samplingParamsByThinkingLevel,\n\t\t\toverride.samplingParamsByThinkingLevel,\n\t\t),\n\t\tcompat: mergeCompat(model.compat, override.compat),\n\t};\n}\n\nfunction modelFromJson(\n\tproviderId: string,\n\tdefinition: ModelsJsonModel,\n\tproviderConfig: ModelsJsonProvider,\n\tdefaults: Model<Api> | undefined,\n): Model<Api> {\n\tconst api = definition.api ?? providerConfig.api ?? defaults?.api;\n\tif (!api) {\n\t\tthrow new Error(\n\t\t\t`Provider ${providerId}, model ${definition.id}: no \"api\" specified. Set at provider or model level.`,\n\t\t);\n\t}\n\tconst baseUrl = definition.baseUrl ?? providerConfig.baseUrl ?? defaults?.baseUrl;\n\tif (!baseUrl) throw new Error(`Provider ${providerId}: \"baseUrl\" is required when defining custom models.`);\n\tif (definition.contextWindow !== undefined && definition.contextWindow <= 0) {\n\t\tthrow new Error(`Provider ${providerId}, model ${definition.id}: invalid contextWindow`);\n\t}\n\tif (definition.maxTokens !== undefined && definition.maxTokens <= 0) {\n\t\tthrow new Error(`Provider ${providerId}, model ${definition.id}: invalid maxTokens`);\n\t}\n\treturn {\n\t\tid: definition.id,\n\t\tname: definition.name ?? definition.id,\n\t\tapi: api as Api,\n\t\tprovider: providerId,\n\t\tbaseUrl,\n\t\treasoning: definition.reasoning ?? false,\n\t\tthinkingLevelMap: definition.thinkingLevelMap,\n\t\tinput: (definition.input ?? [\"text\"]) as Model<Api>[\"input\"],\n\t\tinputLimits: definition.inputLimits,\n\t\tcost: definition.cost ?? { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },\n\t\tpromptCache: definition.promptCache,\n\t\tcontextWindow: definition.contextWindow ?? 128000,\n\t\tmaxTokens: definition.maxTokens ?? 16384,\n\t\tsamplingParams: definition.samplingParams,\n\t\tsamplingParamsByThinkingLevel: definition.samplingParamsByThinkingLevel,\n\t\theaders: undefined,\n\t\tcompat: mergeCompat(providerConfig.compat, definition.compat),\n\t};\n}\n\nfunction findModelDefaults(models: readonly Model<Api>[], modelId: string, api?: Api): Model<Api> | undefined {\n\treturn (\n\t\tmodels.find((model) => model.id === modelId) ??\n\t\t(api ? models.find((model) => model.api === api) : undefined) ??\n\t\tmodels.find((model) => model.api === \"openai-completions\") ??\n\t\tmodels[0]\n\t);\n}\n\nexport function applyModelsJson(\n\tproviderId: string,\n\tbaseModels: readonly AnyModel[],\n\tconfig: ModelsJsonProvider | undefined,\n): AnyModel[] {\n\tif (!config) return [...baseModels];\n\tif (config.oauth && !config.baseUrl) {\n\t\tthrow new Error(`Provider ${providerId}: \"baseUrl\" is required when \"oauth\" is set.`);\n\t}\n\tconst hasOverrides = config.modelOverrides && Object.keys(config.modelOverrides).length > 0;\n\tif (\n\t\t!config.models?.length &&\n\t\t!config.baseUrl &&\n\t\t!config.headers &&\n\t\t!config.compat &&\n\t\t!hasOverrides &&\n\t\t!config.apiKey &&\n\t\t!config.oauth &&\n\t\tconfig.authHeader === undefined\n\t) {\n\t\tthrow new Error(\n\t\t\t`Provider ${providerId}: must specify \"baseUrl\", \"headers\", \"compat\", \"modelOverrides\", or \"models\".`,\n\t\t);\n\t}\n\n\tconst models: AnyModel[] = baseModels.map((model) => {\n\t\tconst baseUrl = config.oauth === \"radius\" ? model.baseUrl : (config.baseUrl ?? model.baseUrl);\n\t\tif (isModelType(model, \"chat\")) return { ...model, baseUrl, compat: mergeCompat(model.compat, config.compat) };\n\t\tif (isModelType(model, \"classifier\") && config.compat) {\n\t\t\treturn { ...model, baseUrl, compat: { ...model.compat, ...config.compat } };\n\t\t}\n\t\treturn { ...model, baseUrl };\n\t});\n\tfor (const definition of config.models ?? []) {\n\t\tconst existingIndex = models.findIndex((model) => isModelType(model, \"chat\") && model.id === definition.id);\n\t\tconst defaults = findModelDefaults(\n\t\t\tmodels.filter((model) => isModelType(model, \"chat\")),\n\t\t\tdefinition.id,\n\t\t\tdefinition.api ?? config.api ?? (providerId === \"azure\" ? \"azure-openai-responses\" : undefined),\n\t\t);\n\t\tconst model = modelFromJson(providerId, definition, config, defaults);\n\t\tif (existingIndex >= 0) models[existingIndex] = model;\n\t\telse models.push(model);\n\t}\n\treturn models;\n}\n\nexport function applyExtension(\n\tproviderId: string,\n\tmodels: readonly AnyModel[],\n\tconfig: ProviderConfigInput | undefined,\n): AnyModel[] {\n\tif (!config) return [...models];\n\tif (!config.models) {\n\t\treturn config.baseUrl ? models.map((model) => ({ ...model, baseUrl: config.baseUrl! })) : [...models];\n\t}\n\treturn config.models.map((definition) => {\n\t\tconst type = definition.type ?? \"chat\";\n\t\tconst candidates = models.filter((model) => isModelType(model, type));\n\t\tconst defaults =\n\t\t\tcandidates.find((model) => model.id === definition.id) ??\n\t\t\t(definition.api ? candidates.find((model) => model.api === definition.api) : undefined) ??\n\t\t\t(type === \"chat\" && providerId === \"azure\"\n\t\t\t\t? candidates.find((model) => model.api === \"azure-openai-responses\")\n\t\t\t\t: undefined) ??\n\t\t\t(type === \"chat\" ? candidates.find((model) => model.api === \"openai-completions\") : undefined) ??\n\t\t\tcandidates[0];\n\t\tconst api = definition.api ?? (type === \"chat\" ? config.api : undefined) ?? defaults?.api;\n\t\tif (!api) {\n\t\t\tthrow new Error(\n\t\t\t\t`Provider ${providerId}, model ${definition.id}: no \"api\" specified. Set it at model level${type === \"chat\" ? \" or provider level\" : \"\"}.`,\n\t\t\t);\n\t\t}\n\t\tconst baseUrl = definition.baseUrl ?? config.baseUrl ?? defaults?.baseUrl;\n\t\tif (!baseUrl) throw new Error(`Provider ${providerId}: \"baseUrl\" is required when defining custom models.`);\n\t\treturn { ...definition, api, provider: providerId, baseUrl, headers: undefined } as AnyModel;\n\t});\n}\n\nfunction adaptOAuth(config: ExtensionOAuthConfig): OAuthAuth {\n\treturn {\n\t\tname: config.name,\n\t\tlogin: async (callbacks) => {\n\t\t\tconst legacyCallbacks: OAuthLoginCallbacks & {\n\t\t\t\tonInfo(message: string, links: readonly { label?: string; url: string }[]): void;\n\t\t\t} = {\n\t\t\t\tonAuth: (info) => callbacks.notify({ type: \"auth_url\", ...info }),\n\t\t\t\tonDeviceCode: (info) => callbacks.notify({ type: \"device_code\", ...info }),\n\t\t\t\tonPrompt: (prompt) => callbacks.prompt({ type: \"text\", ...prompt }),\n\t\t\t\tonProgress: (message) => callbacks.notify({ type: \"progress\", message }),\n\t\t\t\tonInfo: (message, links) => callbacks.notify({ type: \"info\", message, links }),\n\t\t\t\tonManualCodeInput: () => callbacks.prompt({ type: \"manual_code\", message: \"Paste the authorization code\" }),\n\t\t\t\tonSelect: (prompt) => callbacks.prompt({ type: \"select\", ...prompt }),\n\t\t\t\tsignal: callbacks.signal,\n\t\t\t};\n\t\t\tconst credential = await config.login(legacyCallbacks, callbacks.signal);\n\t\t\treturn { ...credential, type: \"oauth\" };\n\t\t},\n\t\trefresh: async (credential, signal) => {\n\t\t\ttry {\n\t\t\t\treturn { ...(await config.refreshToken(credential, signal)), type: \"oauth\" };\n\t\t\t} catch (error) {\n\t\t\t\tthrow extensionRefreshRejection(error, credential, config.name) ?? error;\n\t\t\t}\n\t\t},\n\t\ttoAuth: async (credential) => ({ apiKey: config.getApiKey(credential) }),\n\t};\n}\n\nfunction withConfiguredAuth(\n\tauth: ModelAuth,\n\theaders: Record<string, string> | undefined,\n\tauthHeader: boolean,\n): ModelAuth {\n\tlet mergedHeaders: ProviderHeaders | undefined =\n\t\tauth.headers || headers ? { ...auth.headers, ...headers } : undefined;\n\tif (authHeader) {\n\t\tif (!auth.apiKey) throw new Error(\"authHeader requires a resolved API key\");\n\t\tmergedHeaders = { ...mergedHeaders, Authorization: `Bearer ${auth.apiKey}` };\n\t}\n\treturn { ...auth, headers: mergedHeaders };\n}\n\nexport function configuredApiKey(\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): string | undefined {\n\treturn extension?.apiKey ?? config?.apiKey;\n}\n\nexport function configuredHeaders(\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): Record<string, string> | undefined {\n\tif (!config?.headers && !extension?.headers) return undefined;\n\treturn { ...config?.headers, ...extension?.headers };\n}\n\nasync function configContextEnv(\n\tvalues: readonly string[],\n\tctx: AuthContext,\n\texplicit?: Record<string, string>,\n): Promise<Record<string, string> | undefined> {\n\tconst env = { ...explicit };\n\tfor (const name of new Set(values.flatMap(getConfigValueEnvVarNames))) {\n\t\tif (env[name] !== undefined) continue;\n\t\tconst value = await ctx.env(name);\n\t\tif (value !== undefined) env[name] = value;\n\t}\n\treturn Object.keys(env).length > 0 ? env : undefined;\n}\n\nexport function composeApiKeyAuth(\n\tproviderId: string,\n\tbase: Provider | undefined,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): ApiKeyAuth | undefined {\n\tconst inherited = base?.auth.apiKey;\n\tconst rawKey = configuredApiKey(config, extension);\n\tconst oauth = extension?.oauth ?? base?.auth.oauth;\n\t// OAuth-only providers get no fabricated API-key login method.\n\tif (!inherited && rawKey === undefined && oauth) return undefined;\n\tconst rawHeaders = configuredHeaders(config, extension);\n\tconst authHeader = extension?.authHeader ?? config?.authHeader ?? false;\n\treturn {\n\t\tname: inherited?.name ?? \"API key\",\n\t\t// A configured key replaces borrowed credentials; a base without a login gains none.\n\t\tborrowCredentialsFrom: rawKey === undefined ? inherited?.borrowCredentialsFrom : undefined,\n\t\tlogin: inherited\n\t\t\t? inherited.login\n\t\t\t: async (interaction: ProviderAuthInteraction) => ({\n\t\t\t\t\ttype: \"api_key\",\n\t\t\t\t\tkey: await interaction.prompt({ type: \"secret\", message: \"Enter API key\" }),\n\t\t\t\t}),\n\t\tcheck: async (input) => {\n\t\t\tif (input.credential) {\n\t\t\t\tif (inherited?.check) return inherited.check(input);\n\t\t\t\tif (input.credential.key) return { type: \"api_key\", source: \"stored credential\" };\n\t\t\t\tconst resolved = await inherited?.resolve(input);\n\t\t\t\treturn resolved ? { type: \"api_key\", source: resolved.source } : undefined;\n\t\t\t}\n\t\t\tif (rawKey !== undefined) {\n\t\t\t\tif (isCommandConfigValue(rawKey)) return { type: \"api_key\", source: \"configured API key\" };\n\t\t\t\tconst envNames = getConfigValueEnvVarNames(rawKey);\n\t\t\t\tfor (const name of envNames) {\n\t\t\t\t\tif ((await input.ctx.env(name)) === undefined) return undefined;\n\t\t\t\t}\n\t\t\t\treturn { type: \"api_key\", source: \"configured API key\" };\n\t\t\t}\n\t\t\tif (inherited?.check) return inherited.check(input);\n\t\t\tconst resolved = await inherited?.resolve(input);\n\t\t\treturn resolved ? { type: \"api_key\", source: resolved.source } : undefined;\n\t\t},\n\t\tresolve: async (input) => {\n\t\t\tlet result: AuthResult | undefined;\n\t\t\tif (input.credential) {\n\t\t\t\tresult = inherited\n\t\t\t\t\t? await inherited.resolve(input)\n\t\t\t\t\t: input.credential.key\n\t\t\t\t\t\t? { auth: { apiKey: input.credential.key }, env: input.credential.env, source: \"stored credential\" }\n\t\t\t\t\t\t: undefined;\n\t\t\t} else if (rawKey !== undefined) {\n\t\t\t\tconst env = await configContextEnv([rawKey], input.ctx);\n\t\t\t\t// Like a built-in whose key variable is unset, an unset `$VAR` key means no credential, not an error.\n\t\t\t\tif (!isCommandConfigValue(rawKey) && !isConfigValueConfigured(rawKey, env)) return undefined;\n\t\t\t\tconst key = resolveConfigValueOrThrow(rawKey, `API key for provider \"${providerId}\"`, env);\n\t\t\t\tresult = inherited\n\t\t\t\t\t? await inherited.resolve({ ...input, credential: { type: \"api_key\", key } })\n\t\t\t\t\t: { auth: { apiKey: key }, source: \"configured API key\" };\n\t\t\t} else {\n\t\t\t\tresult = await inherited?.resolve(input);\n\t\t\t}\n\t\t\tif (!result) return undefined;\n\t\t\tconst explicitEnv = { ...(input.credential?.env ?? {}), ...(result.env ?? {}) };\n\t\t\tconst headerEnv = await configContextEnv(Object.values(rawHeaders ?? {}), input.ctx, explicitEnv);\n\t\t\tconst headers = resolveHeadersOrThrow(rawHeaders, `provider \"${providerId}\"`, headerEnv);\n\t\t\treturn { ...result, auth: withConfiguredAuth(result.auth, headers, authHeader) };\n\t\t},\n\t};\n}\n\nexport function composeOAuthAuth(\n\tproviderId: string,\n\tbase: Provider | undefined,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): OAuthAuth | undefined {\n\tconst oauth = extension?.oauth ? adaptOAuth(extension.oauth) : base?.auth.oauth;\n\tif (!oauth) return undefined;\n\tconst rawHeaders = configuredHeaders(config, extension);\n\tconst authHeader = extension?.authHeader ?? config?.authHeader ?? false;\n\treturn {\n\t\t...oauth,\n\t\ttoAuth: async (credential) => {\n\t\t\tconst auth = await oauth.toAuth(credential);\n\t\t\tconst env = credential.env;\n\t\t\tconst headers = resolveHeadersOrThrow(\n\t\t\t\trawHeaders,\n\t\t\t\t`provider \"${providerId}\"`,\n\t\t\t\ttypeof env === \"object\" && env !== null ? (env as Record<string, string>) : undefined,\n\t\t\t);\n\t\t\treturn withConfiguredAuth(auth, headers, authHeader);\n\t\t},\n\t};\n}\n\nexport function rawModelHeaders(\n\tmodel: AnyModel,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): Record<string, string> | undefined {\n\tconst definition = isModelType(model, \"chat\") ? config?.models?.find((entry) => entry.id === model.id) : undefined;\n\tconst extensionModel = extension?.models?.find(\n\t\t(entry) => (entry.type ?? \"chat\") === (model.type ?? \"chat\") && entry.id === model.id,\n\t);\n\tconst headers = {\n\t\t...(isModelType(model, \"chat\") ? config?.modelOverrides?.[model.id]?.headers : undefined),\n\t\t...definition?.headers,\n\t\t...extensionModel?.headers,\n\t};\n\treturn Object.keys(headers).length > 0 ? headers : undefined;\n}\n"]}
|