@bastani/atomic 0.9.80 → 0.9.81-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/dist/builtin/intercom/CHANGELOG.md +6 -0
- package/dist/builtin/intercom/broker/client.ts +12 -1
- package/dist/builtin/intercom/index.bundle.mjs +16 -4
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/CHANGELOG.md +10 -0
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/skills/agent-desktop/SKILL.md +40 -2
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +123 -25
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/CHANGELOG.md +10 -0
- package/dist/builtin/workflows/builtin/{chunk-m56qhe4b.js → chunk-zpkcqyhr.js} +2 -0
- package/dist/builtin/workflows/builtin/index.js +1 -1
- package/dist/builtin/workflows/builtin/ralph.js +1 -1
- package/dist/builtin/workflows/package.json +1 -1
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +16 -4
- package/dist/builtin/workflows/src/extension/local-worker-entry.mjs +12 -2
- package/dist/builtin/workflows/src/index.js +12 -2
- package/dist/builtin/workflows/src/local-worker-entry.mjs +12 -2
- package/dist/builtin/workflows/src/shared/authoring-contract-stage.d.ts +8 -1
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +4 -2
- package/dist/cli/args.js.map +1 -1
- package/dist/core/cache-stats.d.ts +21 -0
- package/dist/core/cache-stats.d.ts.map +1 -1
- package/dist/core/cache-stats.js +42 -2
- package/dist/core/cache-stats.js.map +1 -1
- package/dist/core/exec.d.ts +1 -0
- package/dist/core/exec.d.ts.map +1 -1
- package/dist/core/exec.js +2 -1
- package/dist/core/exec.js.map +1 -1
- package/dist/core/execution-model-router.d.ts +17 -0
- package/dist/core/execution-model-router.d.ts.map +1 -1
- package/dist/core/execution-model-router.js +52 -23
- package/dist/core/execution-model-router.js.map +1 -1
- package/dist/core/model-fallback-failures.d.ts.map +1 -1
- package/dist/core/model-fallback-failures.js +1 -0
- package/dist/core/model-fallback-failures.js.map +1 -1
- package/dist/core/model-resolver-scope.d.ts +0 -1
- package/dist/core/model-resolver-scope.d.ts.map +1 -1
- package/dist/core/model-resolver-scope.js +0 -8
- package/dist/core/model-resolver-scope.js.map +1 -1
- package/dist/core/model-resolver.d.ts +1 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +1 -1
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-routing-candidates.d.ts +30 -5
- package/dist/core/model-routing-candidates.d.ts.map +1 -1
- package/dist/core/model-routing-candidates.js +381 -105
- package/dist/core/model-routing-candidates.js.map +1 -1
- package/dist/core/model-routing-estimates.d.ts +70 -0
- package/dist/core/model-routing-estimates.d.ts.map +1 -0
- package/dist/core/model-routing-estimates.js +244 -0
- package/dist/core/model-routing-estimates.js.map +1 -0
- package/dist/core/model-routing-needs.d.ts +1 -0
- package/dist/core/model-routing-needs.d.ts.map +1 -1
- package/dist/core/model-routing-needs.js +1 -1
- package/dist/core/model-routing-needs.js.map +1 -1
- package/dist/core/provider-display-names.js +2 -2
- package/dist/core/provider-display-names.js.map +1 -1
- package/dist/core/remote-catalog-provider.d.ts.map +1 -1
- package/dist/core/remote-catalog-provider.js +6 -0
- package/dist/core/remote-catalog-provider.js.map +1 -1
- package/dist/core/tasks/supervisor.d.ts +1 -1
- package/dist/core/tasks/supervisor.d.ts.map +1 -1
- package/dist/core/tasks/supervisor.js.map +1 -1
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +20 -11
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/output-accumulator.d.ts.map +1 -1
- package/dist/core/tools/output-accumulator.js +2 -1
- package/dist/core/tools/output-accumulator.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +30 -10
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-actions.d.ts +5 -0
- package/dist/modes/interactive/components/chat-session-host-actions.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-actions.js +86 -9
- package/dist/modes/interactive/components/chat-session-host-actions.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-events.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-events.js +6 -3
- package/dist/modes/interactive/components/chat-session-host-events.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-rendering.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-rendering.js +5 -2
- package/dist/modes/interactive/components/chat-session-host-rendering.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-state.d.ts +5 -0
- package/dist/modes/interactive/components/chat-session-host-state.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-state.js +2 -0
- package/dist/modes/interactive/components/chat-session-host-state.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts +4 -2
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +11 -4
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/session-selector-list.d.ts +4 -1
- package/dist/modes/interactive/components/session-selector-list.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector-list.js +24 -1
- package/dist/modes/interactive/components/session-selector-list.js.map +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts +1 -0
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +29 -36
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-agent-events.js +6 -6
- package/dist/modes/interactive/interactive-agent-events.js.map +1 -1
- package/dist/modes/interactive/interactive-deferred-startup.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-deferred-startup.js +11 -3
- package/dist/modes/interactive/interactive-deferred-startup.js.map +1 -1
- package/dist/modes/interactive/interactive-input-handling.js +11 -1
- package/dist/modes/interactive/interactive-input-handling.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-deps.d.ts +1 -1
- package/dist/modes/interactive/interactive-mode-deps.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-deps.js +1 -1
- package/dist/modes/interactive/interactive-mode-deps.js.map +1 -1
- package/dist/modes/interactive/interactive-process-lifecycle.js +34 -7
- package/dist/modes/interactive/interactive-process-lifecycle.js.map +1 -1
- package/dist/modes/interactive/interactive-queueing.d.ts +24 -0
- package/dist/modes/interactive/interactive-queueing.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-queueing.js +61 -0
- package/dist/modes/interactive/interactive-queueing.js.map +1 -1
- package/dist/modes/interactive/interactive-render-chat.js +2 -3
- package/dist/modes/interactive/interactive-render-chat.js.map +1 -1
- package/dist/modes/interactive/interactive-slash-commands.js +2 -2
- package/dist/modes/interactive/interactive-slash-commands.js.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.d.ts +2 -0
- package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.js +10 -0
- package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts +2 -0
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +1 -0
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-session-binding.d.ts +3 -1
- package/dist/modes/rpc/rpc-session-binding.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-session-binding.js +4 -1
- package/dist/modes/rpc/rpc-session-binding.js.map +1 -1
- package/docs/background-tasks.md +2 -2
- package/docs/extensions/api-reference.md +1 -1
- package/docs/models/model-selection.md +7 -7
- package/docs/providers.md +12 -17
- package/docs/skills.md +1 -1
- package/docs/subagents.md +3 -1
- package/docs/tools.md +1 -1
- package/docs/usage.md +1 -1
- package/docs/workflows/authoring.md +2 -0
- package/docs/workflows/operations.md +1 -1
- package/npm-shrinkwrap.json +57 -33
- package/package.json +3 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-routing-estimates.js","sourceRoot":"","sources":["../../src/core/model-routing-estimates.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,oGAAoG;AACpG,MAAM,IAAI,GAAG,CAAC,CAAC;AACf,iEAAiE;AACjE,MAAM,KAAK,GAAG,CAAC,CAAC;AAChB,MAAM,MAAM,GAAG,EAAE,CAAC;AAClB,MAAM,IAAI,GAAG,MAAM,CAAC;AACpB,mGAAmG;AACnG,MAAM,qBAAqB,GAAG,IAAI,CAAC;AAKnC,wEAAwE;AACxE,SAAS,YAAY,CAAC,IAAY;IACjC,IAAI,KAAK,GAAG,IAAI,KAAK,CAAC,CAAC;IACvB,MAAM,OAAO,GAAG,GAAG,EAAE;QACpB,KAAK,GAAG,CAAC,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;QACnC,IAAI,CAAC,GAAG,KAAK,CAAC;QACd,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QACrC,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;QAC1C,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,UAAU,CAAC;IAC9C,CAAC,CAAC;IACF,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,OAAO,EAA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**\n * Low-rank completion of the benchmark table in `evals.md`.\n *\n * Benchmarks are strongly correlated, so a model's missing results can be\n * estimated from the results it has. Each benchmark (column) is standardized\n * to z-scores over the measured results, and the partially observed\n * (model, reasoning effort) × benchmark matrix is factored with regularized\n * alternating least squares. A row is one model at one effort; its factor is\n * `a + t·b`, where `t` is the effort's position on the reasoning scale and\n * `a`, `b` belong to the model, so every effort of a model, measured or not,\n * shares its evidence: rows the catalog never measured are interpolated from\n * the model's measured efforts and the effort trend of other models. The\n * benchmark factors, the residual variance and the spread of model factors\n * then define a Gaussian model: a model's factors have the empirical prior of\n * the catalog's models, and its own results update that prior by Bayesian\n * linear regression. The posterior gives every\n * result, measured or missing, a mean and a variance, so a model measured on\n * one benchmark carries more uncertainty than one measured on many, and one\n * outlying result moves the estimate only as far as the model's other results\n * support. Estimates stay within the range measured results span.\n *\n * Everything is deterministic: a fixed-seed initialization and a fixed number\n * of sweeps. A fit over the shipped catalog takes tens of milliseconds and runs\n * once per parsed catalog.\n */\n\n/** Latent dimensions of the fit. Rank 3 predicts held-out results about as well as larger ranks. */\nconst RANK = 3;\n/** Ridge penalty on factors during alternating least squares. */\nconst RIDGE = 1;\nconst SWEEPS = 60;\nconst SEED = 0x4689;\n/** Floor on the residual variance, in squared z units, so in-sample fit never claims certainty. */\nconst MIN_RESIDUAL_VARIANCE = 0.05;\n\ntype Vector = number[];\ntype Matrix = number[][];\n\n/** Deterministic standard normal draws (mulberry32 with Box-Muller). */\nfunction normalSource(seed: number): () => number {\n\tlet state = seed >>> 0;\n\tconst uniform = () => {\n\t\tstate = (state + 0x6d2b79f5) >>> 0;\n\t\tlet t = state;\n\t\tt = Math.imul(t ^ (t >>> 15), t | 1);\n\t\tt ^= t + Math.imul(t ^ (t >>> 7), t | 61);\n\t\treturn ((t ^ (t >>> 14)) >>> 0) / 4294967296;\n\t};\n\treturn () => Math.sqrt(-2 * Math.log(1 - uniform())) * Math.cos(2 * Math.PI * uniform());\n}\n\nconst zeros = (size: number): Vector => new Array<number>(size).fill(0);\nconst identity = (size: number, scale = 1): Matrix =>\n\tArray.from({ length: size }, (_, row) => Array.from({ length: size }, (_, col) => (row === col ? scale : 0)));\nconst dot = (a: readonly number[], b: readonly number[]) => a.reduce((sum, value, index) => sum + value * b[index]!, 0);\n\n/** Solve `A x = b` for a small symmetric positive-definite `A` by Gaussian elimination with partial pivoting. */\nfunction solve(matrix: Matrix, rhs: Vector): Vector {\n\tconst size = rhs.length;\n\tconst a = matrix.map((row, index) => [...row, rhs[index]!]);\n\tfor (let col = 0; col < size; col++) {\n\t\tlet pivot = col;\n\t\tfor (let row = col + 1; row < size; row++) if (Math.abs(a[row]![col]!) > Math.abs(a[pivot]![col]!)) pivot = row;\n\t\t[a[col], a[pivot]] = [a[pivot]!, a[col]!];\n\t\tconst lead = a[col]![col]!;\n\t\tfor (let row = 0; row < size; row++) {\n\t\t\tif (row === col) continue;\n\t\t\tconst factor = a[row]![col]! / lead;\n\t\t\tfor (let k = col; k <= size; k++) a[row]![k]! -= factor * a[col]![k]!;\n\t\t}\n\t}\n\treturn a.map((row, index) => row[size]! / row[index]!);\n}\n\nconst inverse = (matrix: Matrix): Matrix => {\n\tconst columns = identity(matrix.length).map((unit) => solve(matrix, unit));\n\treturn matrix.map((_, row) => columns.map((column) => column[row]!));\n};\n\n/** `Σ_k x_k x_kᵀ + diag`, the normal-equation matrix of a ridge regression. */\nfunction gram(vectors: readonly Vector[], diagonal: Matrix): Matrix {\n\tconst result = diagonal.map((row) => [...row]);\n\tfor (const vector of vectors)\n\t\tfor (let i = 0; i < vector.length; i++)\n\t\t\tfor (let j = 0; j < vector.length; j++) result[i]![j]! += vector[i]! * vector[j]!;\n\treturn result;\n}\n\nfunction ridgeFit(features: readonly Vector[], targets: readonly number[], size: number): Vector {\n\tconst rhs = zeros(size);\n\tfeatures.forEach((feature, index) => {\n\t\tfor (let k = 0; k < size; k++) rhs[k]! += feature[k]! * targets[index]!;\n\t});\n\treturn solve(gram(features, identity(size, RIDGE)), rhs);\n}\n\n/** One result a model has for a benchmark. */\nexport interface Observation {\n\treadonly key: string;\n\treadonly value: number;\n\t/** Position of the result's reasoning effort on the effort scale. */\n\treadonly effort: number;\n\t/** Multiple of the residual variance this result carries; 1, the default, is a direct measurement. */\n\treadonly noise?: number;\n}\n\n/** A model's estimated result on one benchmark, in the benchmark's own unit. */\nexport interface EstimatedResult {\n\treadonly key: string;\n\treadonly value: number;\n\t/** Standard error of `value`, in the benchmark's own unit. */\n\treadonly error: number;\n}\n\n/** A model's estimated quality for one weighting of benchmarks. */\nexport interface QualityEstimate {\n\t/** Weighted mean z-score over the weighted benchmarks at the requested effort. */\n\treadonly mean: number;\n\t/** Standard error of `mean`. */\n\treadonly error: number;\n\t/** Weighted benchmarks the model has a direct result for at the requested effort. */\n\treadonly measured: readonly string[];\n\t/** Weighted benchmarks the model lacks at the requested effort, with the completion's estimate. */\n\treadonly estimated: readonly EstimatedResult[];\n}\n\n/** The fitted completion for one catalog. */\nexport interface BenchmarkCompletion {\n\t/** Benchmarks with enough results to take part in the fit. */\n\treadonly keys: ReadonlySet<string>;\n\t/**\n\t * Estimate quality at `effort` from a model's own results under\n\t * per-benchmark `weights`. An observation with `noise` above 1, such as a\n\t * result reported under another harness, carries that many times the\n\t * residual variance and is not counted as measured.\n\t */\n\testimate(\n\t\tobservations: readonly Observation[],\n\t\tweights: ReadonlyMap<string, number>,\n\t\teffort: number,\n\t): QualityEstimate | undefined;\n}\n\ninterface Entry {\n\treadonly column: number;\n\treadonly z: number;\n\treadonly effort: number;\n\treadonly noise: number;\n}\n\n/** Regression features of one entry for a model's factors `[a, b]`: the benchmark loading, and it scaled by effort. */\nconst features = (loading: Vector, effort: number): Vector => [...loading, ...loading.map((x) => x * effort)];\n\n/**\n * Fit the completion to each catalog model's direct results. Benchmarks\n * measured on fewer than `minModels` models, or without spread, are left out.\n */\nexport function completeBenchmarks(\n\tmodels: ReadonlyMap<string, readonly Observation[]>,\n\tminModels: number,\n): BenchmarkCompletion {\n\tconst byKey = new Map<string, { values: number[]; models: Set<string> }>();\n\tfor (const [model, observations] of models)\n\t\tfor (const { key, value } of observations) {\n\t\t\tconst entry = byKey.get(key) ?? { values: [], models: new Set<string>() };\n\t\t\tentry.values.push(value);\n\t\t\tentry.models.add(model);\n\t\t\tbyKey.set(key, entry);\n\t\t}\n\tconst keys: string[] = [];\n\tconst center: number[] = [];\n\tconst scale: number[] = [];\n\tconst low: number[] = [];\n\tconst high: number[] = [];\n\tfor (const [key, { values, models: measured }] of byKey) {\n\t\tif (measured.size < minModels) continue;\n\t\tconst mean = values.reduce((a, b) => a + b, 0) / values.length;\n\t\tconst sd = Math.sqrt(values.reduce((sum, value) => sum + (value - mean) ** 2, 0) / values.length);\n\t\tif (!(sd > 0)) continue;\n\t\tkeys.push(key);\n\t\tcenter.push(mean);\n\t\tscale.push(sd);\n\t\tlow.push((Math.min(...values) - mean) / sd);\n\t\thigh.push((Math.max(...values) - mean) / sd);\n\t}\n\tconst column = new Map(keys.map((key, index) => [key, index]));\n\tconst z = (key: string, value: number) => {\n\t\tconst index = column.get(key)!;\n\t\treturn (value - center[index]!) / scale[index]!;\n\t};\n\tconst toEntries = (observations: readonly Observation[]): Entry[] =>\n\t\tobservations\n\t\t\t.filter((observation) => column.has(observation.key))\n\t\t\t.map((observation) => ({\n\t\t\t\tcolumn: column.get(observation.key)!,\n\t\t\t\tz: z(observation.key, observation.value),\n\t\t\t\teffort: observation.effort,\n\t\t\t\tnoise: observation.noise ?? 1,\n\t\t\t}));\n\tconst rows = [...models.values()].map(toEntries).filter((entries) => entries.length > 0);\n\tconst byColumn: { row: number; entry: Entry }[][] = keys.map(() => []);\n\trows.forEach((entries, row) => {\n\t\tfor (const entry of entries) byColumn[entry.column]!.push({ row, entry });\n\t});\n\n\tconst size = 2 * RANK;\n\tconst draw = normalSource(SEED);\n\tconst u: Matrix = rows.map(() => Array.from({ length: size }, () => 0.1 * draw()));\n\tconst v: Matrix = keys.map(() => Array.from({ length: RANK }, () => 0.1 * draw()));\n\t/** A model's factor at one effort: `a + t·b`. */\n\tconst at = (factors: Vector, effort: number) =>\n\t\tArray.from({ length: RANK }, (_, k) => factors[k]! + effort * factors[RANK + k]!);\n\tfor (let sweep = 0; sweep < SWEEPS && keys.length > 0; sweep++) {\n\t\trows.forEach((entries, row) => {\n\t\t\tu[row] = ridgeFit(\n\t\t\t\tentries.map((entry) => features(v[entry.column]!, entry.effort)),\n\t\t\t\tentries.map((entry) => entry.z),\n\t\t\t\tsize,\n\t\t\t);\n\t\t});\n\t\tbyColumn.forEach((entries, col) => {\n\t\t\tv[col] = ridgeFit(\n\t\t\t\tentries.map(({ row, entry }) => at(u[row]!, entry.effort)),\n\t\t\t\tentries.map(({ entry }) => entry.z),\n\t\t\t\tRANK,\n\t\t\t);\n\t\t});\n\t}\n\n\t// Empirical prior of a model's factors: the mean and covariance of the fitted model factors.\n\tconst priorMean = zeros(size);\n\tfor (const factor of u) for (let k = 0; k < size; k++) priorMean[k]! += factor[k]! / Math.max(1, u.length);\n\tconst priorCovariance = identity(size, 1e-6);\n\tfor (const factor of u)\n\t\tfor (let i = 0; i < size; i++)\n\t\t\tfor (let j = 0; j < size; j++)\n\t\t\t\tpriorCovariance[i]![j]! +=\n\t\t\t\t\t((factor[i]! - priorMean[i]!) * (factor[j]! - priorMean[j]!)) / Math.max(1, u.length - 1);\n\tconst priorPrecision = inverse(priorCovariance);\n\tconst priorShift = priorPrecision.map((row) => dot(row, priorMean));\n\n\t/** Posterior mean and covariance of a model's factors given its standardized results. */\n\tconst posterior = (entries: readonly Entry[], residual: number) => {\n\t\tconst precision = gram(\n\t\t\tentries.map((entry) =>\n\t\t\t\tfeatures(v[entry.column]!, entry.effort).map((x) => x / Math.sqrt(residual * entry.noise)),\n\t\t\t),\n\t\t\tpriorPrecision,\n\t\t);\n\t\tconst shift = [...priorShift];\n\t\tfor (const entry of entries) {\n\t\t\tconst feature = features(v[entry.column]!, entry.effort);\n\t\t\tfor (let k = 0; k < size; k++) shift[k]! += (feature[k]! * entry.z) / (residual * entry.noise);\n\t\t}\n\t\tconst covariance = inverse(precision);\n\t\treturn { factor: covariance.map((row) => dot(row, shift)), covariance };\n\t};\n\tconst quadratic = (covariance: Matrix, vector: Vector) =>\n\t\tdot(\n\t\t\tvector,\n\t\t\tcovariance.map((row) => dot(row, vector)),\n\t\t);\n\n\t// Residual variance from leave-one-out predictions, which unlike the in-sample\n\t// fit do not reward a model for matching the result it was fitted to. Each\n\t// left-out residual is the in-sample one inflated by the result's leverage.\n\tlet residual = 1;\n\tfor (let pass = 0; pass < 3 && keys.length > 0; pass++) {\n\t\tlet squared = 0;\n\t\tlet count = 0;\n\t\tfor (const entries of rows) {\n\t\t\tconst { factor, covariance } = posterior(entries, residual);\n\t\t\tfor (const entry of entries) {\n\t\t\t\tconst feature = features(v[entry.column]!, entry.effort);\n\t\t\t\tconst leverage = Math.min(0.99, quadratic(covariance, feature) / residual);\n\t\t\t\tsquared += ((entry.z - dot(factor, feature)) / (1 - leverage)) ** 2;\n\t\t\t\tcount++;\n\t\t\t}\n\t\t}\n\t\tresidual = Math.max(MIN_RESIDUAL_VARIANCE, count ? squared / count : 1);\n\t}\n\n\treturn {\n\t\tkeys: new Set(keys),\n\t\testimate(observations, weights, effort) {\n\t\t\tconst weighted = [...weights].filter(([key, weight]) => weight > 0 && column.has(key));\n\t\t\tconst total = weighted.reduce((sum, [, weight]) => sum + weight, 0);\n\t\t\tif (total === 0) return undefined;\n\t\t\tconst entries = toEntries(observations);\n\t\t\tconst { factor, covariance } = posterior(entries, residual);\n\t\t\tconst direct = new Set(\n\t\t\t\tentries.filter((entry) => entry.noise === 1 && entry.effort === effort).map((entry) => keys[entry.column]!),\n\t\t\t);\n\t\t\t// Quality is the model's inferred ability on each weighted benchmark at\n\t\t\t// this effort: a measured result is weighed with everything else the\n\t\t\t// model scored, so one outlying result moves the estimate only as far as\n\t\t\t// the rest supports. Estimates stay within the range measured results span.\n\t\t\tlet sum = 0;\n\t\t\tlet missingNoise = 0;\n\t\t\tconst direction = zeros(size);\n\t\t\tconst measured: string[] = [];\n\t\t\tconst estimated: EstimatedResult[] = [];\n\t\t\tfor (const [key, weight] of weighted) {\n\t\t\t\tconst index = column.get(key)!;\n\t\t\t\tconst feature = features(v[index]!, effort);\n\t\t\t\tconst ability = Math.min(high[index]!, Math.max(low[index]!, dot(factor, feature)));\n\t\t\t\tsum += weight * ability;\n\t\t\t\tfor (let k = 0; k < size; k++) direction[k]! += weight * feature[k]!;\n\t\t\t\tif (direct.has(key)) {\n\t\t\t\t\tmeasured.push(key);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t// A result nobody measured also varies from the model's ability by the residual.\n\t\t\t\tmissingNoise += weight * weight * residual;\n\t\t\t\testimated.push({\n\t\t\t\t\tkey,\n\t\t\t\t\tvalue: center[index]! + ability * scale[index]!,\n\t\t\t\t\terror: Math.sqrt(quadratic(covariance, feature) + residual) * scale[index]!,\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst variance = quadratic(covariance, direction) + missingNoise;\n\t\t\treturn { mean: sum / total, error: Math.sqrt(variance) / total, measured, estimated };\n\t\t},\n\t};\n}\n"]}
|
|
@@ -65,6 +65,7 @@ export declare function missingNeedsQuestions(stated: TaskNeeds | undefined): Ne
|
|
|
65
65
|
export declare function resolveTaskNeeds(stated: TaskNeeds | undefined, answers: Record<string, string>): ResolvedTaskNeeds;
|
|
66
66
|
/** 0 for the easiest or cheapest-to-get-wrong task, 1 for the hardest or costliest. */
|
|
67
67
|
export declare function taskDemand(needs: ResolvedTaskNeeds): number;
|
|
68
|
+
export declare const EFFORT_ORDER: string[];
|
|
68
69
|
/**
|
|
69
70
|
* Effort for a model from the task's difficulty, one level lower (never below
|
|
70
71
|
* `minimal`) when speed matters: the supported level closest to the target,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-routing-needs.d.ts","sourceRoot":"","sources":["../../src/core/model-routing-needs.ts"],"names":[],"mappings":"AAAA,OAA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,EAAE,GAAG,SAAS,GAAG,SAAS,CAGlG;AAED,MAAM,WAAW,aAAa;IAC7B,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,YAAY,GAAG,cAAc,GAAG,cAAc,GAAG,cAAc,GAAG,mBAAmB,CAAC;IAC5G,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC1C;AAED,+EAA+E;AAC/E,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,aAAa,EAAE,CAgDpF;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,iBAAiB,CAYlH;AAED,uFAAuF;AACvF,wBAAgB,UAAU,CAAC,KAAK,EAAE,iBAAiB,GAAG,MAAM,CAI3D;AAED,eAAO,MAAM,YAAY,UAA8D,CAAC;AASxF;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAClC,OAAO,EAAE,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,EACnC,UAAU,EAAE,UAAU,EACtB,gBAAgB,UAAQ,GACtB,MAAM,GAAG,IAAI,CASf"}
|
|
@@ -151,7 +151,7 @@ export function taskDemand(needs) {
|
|
|
151
151
|
const mistake = MISTAKE_COST_KEYS.indexOf(needs.mistakeCost) / (MISTAKE_COST_KEYS.length - 1);
|
|
152
152
|
return Math.max(difficulty, mistake);
|
|
153
153
|
}
|
|
154
|
-
const EFFORT_ORDER = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
154
|
+
export const EFFORT_ORDER = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
155
155
|
const EFFORT_FOR_DIFFICULTY = {
|
|
156
156
|
trivial: "minimal",
|
|
157
157
|
easy: "low",
|
|
@@ -1 +1 @@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,gBAAgB,GAAG,KAAK;IAExB,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,EAAoB,EAAE,CAAC,MAAM,KAAK,IAAI,IAAI,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;IACjH,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC;IACxF,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,qBAAqB,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACjH,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC,IAAI,CACzB,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CACR,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;QACvF,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,CAClD,CAAC,CAAC,CAAE,CAAC;AACP,CAAC","sourcesContent":["import { Type } from \"typebox\";\n\n/** Kinds of work a routed task can be, each described for the router in plain words. */\nexport const WORK_KINDS = {\n\tcomputer_use: \"Operating desktop or mobile apps through screenshots, clicks and typing\",\n\tcoding: \"Writing, changing or debugging code in a repository\",\n\tcode_review: \"Reviewing code or systems for defects or security problems\",\n\tcodebase_lookup: \"Finding files, definitions or facts in a codebase without changing anything\",\n\tresearch: \"Reading documents or the web and summarizing findings\",\n\tbusiness_workflow: \"Multi-step work across business tools or APIs\",\n\tmath_science: \"Math, physics or scientific computation\",\n\twriting: \"Writing or editing prose, documents or slides\",\n} as const;\n\nexport const DIFFICULTY_LEVELS = {\n\ttrivial: \"One obvious step\",\n\teasy: \"A few simple steps\",\n\tmoderate: \"Several steps with some judgment\",\n\thard: \"Many dependent steps, debugging or verification\",\n\tvery_hard: \"Long work across many tools with frequent recovery\",\n} as const;\n\nexport const MISTAKE_COST_LEVELS = {\n\tnegligible: \"Easily noticed and redone\",\n\tlow: \"Minor rework\",\n\tmoderate: \"Wasted time or a confusing result\",\n\thigh: \"Broken builds, bad data or wrong conclusions\",\n\tsevere: \"Security, money, data loss or production impact\",\n} as const;\n\nexport type WorkKind = keyof typeof WORK_KINDS;\nexport type Difficulty = keyof typeof DIFFICULTY_LEVELS;\nexport type MistakeCost = keyof typeof MISTAKE_COST_LEVELS;\n\n/** What a caller may state about a task so routing need not infer it. Every field is optional. */\nexport interface TaskNeeds {\n\treadonly work?: WorkKind;\n\treadonly difficulty?: Difficulty;\n\treadonly mistakeCost?: MistakeCost;\n\treadonly needsImages?: boolean;\n\treadonly longContext?: boolean;\n\treadonly latencySensitive?: boolean;\n}\n\nexport type ResolvedTaskNeeds = Required<TaskNeeds>;\n\nconst enumOf = <T extends string>(values: Record<T, string>, description: string) =>\n\tType.Unsafe<T>(Type.String({ enum: Object.keys(values), description }));\n\n/** Tool and stage schema for caller-stated task needs. */\nexport const TaskNeedsSchema = Type.Object(\n\t{\n\t\twork: Type.Optional(enumOf(WORK_KINDS, `Main kind of work: ${Object.keys(WORK_KINDS).join(\", \")}.`)),\n\t\tdifficulty: Type.Optional(enumOf(DIFFICULTY_LEVELS, \"How hard the task is for a capable agent.\")),\n\t\tmistakeCost: Type.Optional(enumOf(MISTAKE_COST_LEVELS, \"How bad a wrong result would be.\")),\n\t\tneedsImages: Type.Optional(Type.Boolean({ description: \"Whether the agent must read screenshots or images.\" })),\n\t\tlongContext: Type.Optional(\n\t\t\tType.Boolean({ description: \"Whether the agent must hold a very large codebase or document set in context.\" }),\n\t\t),\n\t\tlatencySensitive: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription: \"Whether a fast answer matters more than extra reasoning, for example quick lookups.\",\n\t\t\t}),\n\t\t),\n\t},\n\t{\n\t\tadditionalProperties: false,\n\t\tdescription:\n\t\t\t\"For model 'auto': what you know about the task. Fill in every field you can judge; routing uses these answers instead of reading the task, and a language model reads the task only for omitted fields.\",\n\t},\n);\n\nconst WORK_KEYS = Object.keys(WORK_KINDS) as WorkKind[];\nconst DIFFICULTY_KEYS = Object.keys(DIFFICULTY_LEVELS) as Difficulty[];\nconst MISTAKE_COST_KEYS = Object.keys(MISTAKE_COST_LEVELS) as MistakeCost[];\n\nconst CHOICE_FIELDS = [\"work\", \"difficulty\", \"mistakeCost\"] as const;\nconst BOOLEAN_FIELDS = [\"needsImages\", \"longContext\", \"latencySensitive\"] as const;\n\nconst oneOf = <T extends string>(keys: readonly T[], value: unknown, field: string): T => {\n\tif (typeof value === \"string\" && (keys as readonly string[]).includes(value)) return value as T;\n\tthrow new Error(`Invalid taskNeeds.${field}: expected one of ${keys.join(\", \")}.`);\n};\n\n/** Validate caller-stated needs. Unknown keys and values fail rather than being guessed. */\nexport function parseTaskNeeds(value: unknown): TaskNeeds | undefined {\n\tif (value === undefined) return undefined;\n\tif (value === null || typeof value !== \"object\" || Array.isArray(value))\n\t\tthrow new Error(\n\t\t\t\"Invalid taskNeeds: expected an object with work, difficulty, mistakeCost, needsImages, longContext or latencySensitive.\",\n\t\t);\n\tconst record = value as Record<string, unknown>;\n\tfor (const key of Object.keys(record))\n\t\tif (!([...CHOICE_FIELDS, ...BOOLEAN_FIELDS] as readonly string[]).includes(key))\n\t\t\tthrow new Error(`Invalid taskNeeds: unknown field ${key}.`);\n\tfor (const field of BOOLEAN_FIELDS)\n\t\tif (record[field] !== undefined && typeof record[field] !== \"boolean\")\n\t\t\tthrow new Error(`Invalid taskNeeds.${field}: expected true or false.`);\n\treturn {\n\t\t...(record.work !== undefined ? { work: oneOf(WORK_KEYS, record.work, \"work\") } : {}),\n\t\t...(record.difficulty !== undefined\n\t\t\t? { difficulty: oneOf(DIFFICULTY_KEYS, record.difficulty, \"difficulty\") }\n\t\t\t: {}),\n\t\t...(record.mistakeCost !== undefined\n\t\t\t? { mistakeCost: oneOf(MISTAKE_COST_KEYS, record.mistakeCost, \"mistakeCost\") }\n\t\t\t: {}),\n\t\t...Object.fromEntries(\n\t\t\tBOOLEAN_FIELDS.flatMap((field) => (record[field] === undefined ? [] : [[field, record[field]]])),\n\t\t),\n\t};\n}\n\n/** Later stated needs win field by field (for example a call over an agent default). */\nexport function mergeTaskNeeds(...needs: readonly (TaskNeeds | undefined)[]): TaskNeeds | undefined {\n\tconst merged = Object.assign({}, ...needs.filter((entry) => entry !== undefined)) as TaskNeeds;\n\treturn Object.keys(merged).length ? merged : undefined;\n}\n\nexport interface NeedsQuestion {\n\treadonly id: \"work\" | \"difficulty\" | \"mistake_cost\" | \"needs_images\" | \"long_context\" | \"latency_sensitive\";\n\treadonly instructions: string;\n\treadonly criteria: Record<string, string>;\n}\n\n/** Questions for only the needs the caller did not state, in a fixed order. */\nexport function missingNeedsQuestions(stated: TaskNeeds | undefined): NeedsQuestion[] {\n\tconst questions: NeedsQuestion[] = [];\n\tif (!stated?.work)\n\t\tquestions.push({\n\t\t\tid: \"work\",\n\t\t\tinstructions: \"What kind of work is this task mainly?\",\n\t\t\tcriteria: { ...WORK_KINDS },\n\t\t});\n\tif (!stated?.difficulty)\n\t\tquestions.push({\n\t\t\tid: \"difficulty\",\n\t\t\tinstructions: \"How hard is this task for a capable AI agent to complete correctly?\",\n\t\t\tcriteria: { ...DIFFICULTY_LEVELS },\n\t\t});\n\tif (!stated?.mistakeCost)\n\t\tquestions.push({\n\t\t\tid: \"mistake_cost\",\n\t\t\tinstructions: \"How bad is it if the agent gets this task wrong?\",\n\t\t\tcriteria: { ...MISTAKE_COST_LEVELS },\n\t\t});\n\tif (stated?.needsImages === undefined)\n\t\tquestions.push({\n\t\t\tid: \"needs_images\",\n\t\t\tinstructions: \"Does doing this task require the agent to look at screenshots or images?\",\n\t\t\tcriteria: {\n\t\t\t\tyes: \"The agent must read screenshots, images or a GUI\",\n\t\t\t\tno: \"Text and tool output are enough\",\n\t\t\t},\n\t\t});\n\tif (stated?.longContext === undefined)\n\t\tquestions.push({\n\t\t\tid: \"long_context\",\n\t\t\tinstructions: \"Must the agent hold a very large codebase, log or document set in context at once?\",\n\t\t\tcriteria: {\n\t\t\t\tyes: \"Hundreds of thousands of tokens of material at once\",\n\t\t\t\tno: \"Ordinary amounts, read piece by piece\",\n\t\t\t},\n\t\t});\n\tif (stated?.latencySensitive === undefined)\n\t\tquestions.push({\n\t\t\tid: \"latency_sensitive\",\n\t\t\tinstructions: \"Does a fast answer matter more than extra reasoning?\",\n\t\t\tcriteria: {\n\t\t\t\tyes: \"Speed matters: a quick lookup, an interactive step or many small calls\",\n\t\t\t\tno: \"Quality matters more than speed\",\n\t\t\t},\n\t\t});\n\treturn questions;\n}\n\n/**\n * Combine stated needs with the router's answers keyed by question id. Computer\n * use always works from screenshots, so it needs image input unless the caller\n * explicitly said otherwise.\n */\nexport function resolveTaskNeeds(stated: TaskNeeds | undefined, answers: Record<string, string>): ResolvedTaskNeeds {\n\tconst work = stated?.work ?? oneOf(WORK_KEYS, answers.work, \"work\");\n\tconst yes = (answer: string | undefined, field: string) =>\n\t\tanswer !== undefined && oneOf([\"yes\", \"no\"], answer, field) === \"yes\";\n\treturn {\n\t\twork,\n\t\tdifficulty: stated?.difficulty ?? oneOf(DIFFICULTY_KEYS, answers.difficulty, \"difficulty\"),\n\t\tmistakeCost: stated?.mistakeCost ?? oneOf(MISTAKE_COST_KEYS, answers.mistake_cost, \"mistakeCost\"),\n\t\tneedsImages: stated?.needsImages ?? (work === \"computer_use\" || yes(answers.needs_images, \"needsImages\")),\n\t\tlongContext: stated?.longContext ?? yes(answers.long_context, \"longContext\"),\n\t\tlatencySensitive: stated?.latencySensitive ?? yes(answers.latency_sensitive, \"latencySensitive\"),\n\t};\n}\n\n/** 0 for the easiest or cheapest-to-get-wrong task, 1 for the hardest or costliest. */\nexport function taskDemand(needs: ResolvedTaskNeeds): number {\n\tconst difficulty = DIFFICULTY_KEYS.indexOf(needs.difficulty) / (DIFFICULTY_KEYS.length - 1);\n\tconst mistake = MISTAKE_COST_KEYS.indexOf(needs.mistakeCost) / (MISTAKE_COST_KEYS.length - 1);\n\treturn Math.max(difficulty, mistake);\n}\n\nconst EFFORT_ORDER = [\"off\", \"minimal\", \"low\", \"medium\", \"high\", \"xhigh\", \"max\"];\nconst EFFORT_FOR_DIFFICULTY: Record<Difficulty, string> = {\n\ttrivial: \"minimal\",\n\teasy: \"low\",\n\tmoderate: \"medium\",\n\thard: \"high\",\n\tvery_hard: \"xhigh\",\n};\n\n/**\n * Effort for a model from the task's difficulty, one level lower (never below\n * `minimal`) when speed matters: the supported level closest to the target,\n * preferring the lower one on a tie. `null` for models without\n * configurable reasoning.\n */\nexport function effortForDifficulty(\n\tefforts: readonly (string | null)[],\n\tdifficulty: Difficulty,\n\tlatencySensitive = false,\n): string | null {\n\tconst supported = efforts.filter((effort): effort is string => effort !== null && EFFORT_ORDER.includes(effort));\n\tif (supported.length === 0) return efforts.includes(null) ? null : (efforts[0] ?? null);\n\tconst target = Math.max(1, EFFORT_ORDER.indexOf(EFFORT_FOR_DIFFICULTY[difficulty]) - (latencySensitive ? 1 : 0));\n\treturn [...supported].sort(\n\t\t(a, b) =>\n\t\t\tMath.abs(EFFORT_ORDER.indexOf(a) - target) - Math.abs(EFFORT_ORDER.indexOf(b) - target) ||\n\t\t\tEFFORT_ORDER.indexOf(a) - EFFORT_ORDER.indexOf(b),\n\t)[0]!;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"model-routing-needs.js","sourceRoot":"","sources":["../../src/core/model-routing-needs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SA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I,IAAI,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;IACjH,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC;IACxF,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,qBAAqB,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACjH,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC,IAAI,CACzB,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CACR,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;QACvF,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,CAClD,CAAC,CAAC,CAAE,CAAC;AACP,CAAC","sourcesContent":["import { Type } from \"typebox\";\n\n/** Kinds of work a routed task can be, each described for the router in plain words. */\nexport const WORK_KINDS = {\n\tcomputer_use: \"Operating desktop or mobile apps through screenshots, clicks and typing\",\n\tcoding: \"Writing, changing or debugging code in a repository\",\n\tcode_review: \"Reviewing code or systems for defects or security problems\",\n\tcodebase_lookup: \"Finding files, definitions or facts in a codebase without changing anything\",\n\tresearch: \"Reading documents or the web and summarizing findings\",\n\tbusiness_workflow: \"Multi-step work across business tools or APIs\",\n\tmath_science: \"Math, physics or scientific computation\",\n\twriting: \"Writing or editing prose, documents or slides\",\n} as const;\n\nexport const DIFFICULTY_LEVELS = {\n\ttrivial: \"One obvious step\",\n\teasy: \"A few simple steps\",\n\tmoderate: \"Several steps with some judgment\",\n\thard: \"Many dependent steps, debugging or verification\",\n\tvery_hard: \"Long work across many tools with frequent recovery\",\n} as const;\n\nexport const MISTAKE_COST_LEVELS = {\n\tnegligible: \"Easily noticed and redone\",\n\tlow: \"Minor rework\",\n\tmoderate: \"Wasted time or a confusing result\",\n\thigh: \"Broken builds, bad data or wrong conclusions\",\n\tsevere: \"Security, money, data loss or production impact\",\n} as const;\n\nexport type WorkKind = keyof typeof WORK_KINDS;\nexport type Difficulty = keyof typeof DIFFICULTY_LEVELS;\nexport type MistakeCost = keyof typeof MISTAKE_COST_LEVELS;\n\n/** What a caller may state about a task so routing need not infer it. Every field is optional. */\nexport interface TaskNeeds {\n\treadonly work?: WorkKind;\n\treadonly difficulty?: Difficulty;\n\treadonly mistakeCost?: MistakeCost;\n\treadonly needsImages?: boolean;\n\treadonly longContext?: boolean;\n\treadonly latencySensitive?: boolean;\n}\n\nexport type ResolvedTaskNeeds = Required<TaskNeeds>;\n\nconst enumOf = <T extends string>(values: Record<T, string>, description: string) =>\n\tType.Unsafe<T>(Type.String({ enum: Object.keys(values), description }));\n\n/** Tool and stage schema for caller-stated task needs. */\nexport const TaskNeedsSchema = Type.Object(\n\t{\n\t\twork: Type.Optional(enumOf(WORK_KINDS, `Main kind of work: ${Object.keys(WORK_KINDS).join(\", \")}.`)),\n\t\tdifficulty: Type.Optional(enumOf(DIFFICULTY_LEVELS, \"How hard the task is for a capable agent.\")),\n\t\tmistakeCost: Type.Optional(enumOf(MISTAKE_COST_LEVELS, \"How bad a wrong result would be.\")),\n\t\tneedsImages: Type.Optional(Type.Boolean({ description: \"Whether the agent must read screenshots or images.\" })),\n\t\tlongContext: Type.Optional(\n\t\t\tType.Boolean({ description: \"Whether the agent must hold a very large codebase or document set in context.\" }),\n\t\t),\n\t\tlatencySensitive: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription: \"Whether a fast answer matters more than extra reasoning, for example quick lookups.\",\n\t\t\t}),\n\t\t),\n\t},\n\t{\n\t\tadditionalProperties: false,\n\t\tdescription:\n\t\t\t\"For model 'auto': what you know about the task. Fill in every field you can judge; routing uses these answers instead of reading the task, and a language model reads the task only for omitted fields.\",\n\t},\n);\n\nconst WORK_KEYS = Object.keys(WORK_KINDS) as WorkKind[];\nconst DIFFICULTY_KEYS = Object.keys(DIFFICULTY_LEVELS) as Difficulty[];\nconst MISTAKE_COST_KEYS = Object.keys(MISTAKE_COST_LEVELS) as MistakeCost[];\n\nconst CHOICE_FIELDS = [\"work\", \"difficulty\", \"mistakeCost\"] as const;\nconst BOOLEAN_FIELDS = [\"needsImages\", \"longContext\", \"latencySensitive\"] as const;\n\nconst oneOf = <T extends string>(keys: readonly T[], value: unknown, field: string): T => {\n\tif (typeof value === \"string\" && (keys as readonly string[]).includes(value)) return value as T;\n\tthrow new Error(`Invalid taskNeeds.${field}: expected one of ${keys.join(\", \")}.`);\n};\n\n/** Validate caller-stated needs. Unknown keys and values fail rather than being guessed. */\nexport function parseTaskNeeds(value: unknown): TaskNeeds | undefined {\n\tif (value === undefined) return undefined;\n\tif (value === null || typeof value !== \"object\" || Array.isArray(value))\n\t\tthrow new Error(\n\t\t\t\"Invalid taskNeeds: expected an object with work, difficulty, mistakeCost, needsImages, longContext or latencySensitive.\",\n\t\t);\n\tconst record = value as Record<string, unknown>;\n\tfor (const key of Object.keys(record))\n\t\tif (!([...CHOICE_FIELDS, ...BOOLEAN_FIELDS] as readonly string[]).includes(key))\n\t\t\tthrow new Error(`Invalid taskNeeds: unknown field ${key}.`);\n\tfor (const field of BOOLEAN_FIELDS)\n\t\tif (record[field] !== undefined && typeof record[field] !== \"boolean\")\n\t\t\tthrow new Error(`Invalid taskNeeds.${field}: expected true or false.`);\n\treturn {\n\t\t...(record.work !== undefined ? { work: oneOf(WORK_KEYS, record.work, \"work\") } : {}),\n\t\t...(record.difficulty !== undefined\n\t\t\t? { difficulty: oneOf(DIFFICULTY_KEYS, record.difficulty, \"difficulty\") }\n\t\t\t: {}),\n\t\t...(record.mistakeCost !== undefined\n\t\t\t? { mistakeCost: oneOf(MISTAKE_COST_KEYS, record.mistakeCost, \"mistakeCost\") }\n\t\t\t: {}),\n\t\t...Object.fromEntries(\n\t\t\tBOOLEAN_FIELDS.flatMap((field) => (record[field] === undefined ? [] : [[field, record[field]]])),\n\t\t),\n\t};\n}\n\n/** Later stated needs win field by field (for example a call over an agent default). */\nexport function mergeTaskNeeds(...needs: readonly (TaskNeeds | undefined)[]): TaskNeeds | undefined {\n\tconst merged = Object.assign({}, ...needs.filter((entry) => entry !== undefined)) as TaskNeeds;\n\treturn Object.keys(merged).length ? merged : undefined;\n}\n\nexport interface NeedsQuestion {\n\treadonly id: \"work\" | \"difficulty\" | \"mistake_cost\" | \"needs_images\" | \"long_context\" | \"latency_sensitive\";\n\treadonly instructions: string;\n\treadonly criteria: Record<string, string>;\n}\n\n/** Questions for only the needs the caller did not state, in a fixed order. */\nexport function missingNeedsQuestions(stated: TaskNeeds | undefined): NeedsQuestion[] {\n\tconst questions: NeedsQuestion[] = [];\n\tif (!stated?.work)\n\t\tquestions.push({\n\t\t\tid: \"work\",\n\t\t\tinstructions: \"What kind of work is this task mainly?\",\n\t\t\tcriteria: { ...WORK_KINDS },\n\t\t});\n\tif (!stated?.difficulty)\n\t\tquestions.push({\n\t\t\tid: \"difficulty\",\n\t\t\tinstructions: \"How hard is this task for a capable AI agent to complete correctly?\",\n\t\t\tcriteria: { ...DIFFICULTY_LEVELS },\n\t\t});\n\tif (!stated?.mistakeCost)\n\t\tquestions.push({\n\t\t\tid: \"mistake_cost\",\n\t\t\tinstructions: \"How bad is it if the agent gets this task wrong?\",\n\t\t\tcriteria: { ...MISTAKE_COST_LEVELS },\n\t\t});\n\tif (stated?.needsImages === undefined)\n\t\tquestions.push({\n\t\t\tid: \"needs_images\",\n\t\t\tinstructions: \"Does doing this task require the agent to look at screenshots or images?\",\n\t\t\tcriteria: {\n\t\t\t\tyes: \"The agent must read screenshots, images or a GUI\",\n\t\t\t\tno: \"Text and tool output are enough\",\n\t\t\t},\n\t\t});\n\tif (stated?.longContext === undefined)\n\t\tquestions.push({\n\t\t\tid: \"long_context\",\n\t\t\tinstructions: \"Must the agent hold a very large codebase, log or document set in context at once?\",\n\t\t\tcriteria: {\n\t\t\t\tyes: \"Hundreds of thousands of tokens of material at once\",\n\t\t\t\tno: \"Ordinary amounts, read piece by piece\",\n\t\t\t},\n\t\t});\n\tif (stated?.latencySensitive === undefined)\n\t\tquestions.push({\n\t\t\tid: \"latency_sensitive\",\n\t\t\tinstructions: \"Does a fast answer matter more than extra reasoning?\",\n\t\t\tcriteria: {\n\t\t\t\tyes: \"Speed matters: a quick lookup, an interactive step or many small calls\",\n\t\t\t\tno: \"Quality matters more than speed\",\n\t\t\t},\n\t\t});\n\treturn questions;\n}\n\n/**\n * Combine stated needs with the router's answers keyed by question id. Computer\n * use always works from screenshots, so it needs image input unless the caller\n * explicitly said otherwise.\n */\nexport function resolveTaskNeeds(stated: TaskNeeds | undefined, answers: Record<string, string>): ResolvedTaskNeeds {\n\tconst work = stated?.work ?? oneOf(WORK_KEYS, answers.work, \"work\");\n\tconst yes = (answer: string | undefined, field: string) =>\n\t\tanswer !== undefined && oneOf([\"yes\", \"no\"], answer, field) === \"yes\";\n\treturn {\n\t\twork,\n\t\tdifficulty: stated?.difficulty ?? oneOf(DIFFICULTY_KEYS, answers.difficulty, \"difficulty\"),\n\t\tmistakeCost: stated?.mistakeCost ?? oneOf(MISTAKE_COST_KEYS, answers.mistake_cost, \"mistakeCost\"),\n\t\tneedsImages: stated?.needsImages ?? (work === \"computer_use\" || yes(answers.needs_images, \"needsImages\")),\n\t\tlongContext: stated?.longContext ?? yes(answers.long_context, \"longContext\"),\n\t\tlatencySensitive: stated?.latencySensitive ?? yes(answers.latency_sensitive, \"latencySensitive\"),\n\t};\n}\n\n/** 0 for the easiest or cheapest-to-get-wrong task, 1 for the hardest or costliest. */\nexport function taskDemand(needs: ResolvedTaskNeeds): number {\n\tconst difficulty = DIFFICULTY_KEYS.indexOf(needs.difficulty) / (DIFFICULTY_KEYS.length - 1);\n\tconst mistake = MISTAKE_COST_KEYS.indexOf(needs.mistakeCost) / (MISTAKE_COST_KEYS.length - 1);\n\treturn Math.max(difficulty, mistake);\n}\n\nexport const EFFORT_ORDER = [\"off\", \"minimal\", \"low\", \"medium\", \"high\", \"xhigh\", \"max\"];\nconst EFFORT_FOR_DIFFICULTY: Record<Difficulty, string> = {\n\ttrivial: \"minimal\",\n\teasy: \"low\",\n\tmoderate: \"medium\",\n\thard: \"high\",\n\tvery_hard: \"xhigh\",\n};\n\n/**\n * Effort for a model from the task's difficulty, one level lower (never below\n * `minimal`) when speed matters: the supported level closest to the target,\n * preferring the lower one on a tie. `null` for models without\n * configurable reasoning.\n */\nexport function effortForDifficulty(\n\tefforts: readonly (string | null)[],\n\tdifficulty: Difficulty,\n\tlatencySensitive = false,\n): string | null {\n\tconst supported = efforts.filter((effort): effort is string => effort !== null && EFFORT_ORDER.includes(effort));\n\tif (supported.length === 0) return efforts.includes(null) ? null : (efforts[0] ?? null);\n\tconst target = Math.max(1, EFFORT_ORDER.indexOf(EFFORT_FOR_DIFFICULTY[difficulty]) - (latencySensitive ? 1 : 0));\n\treturn [...supported].sort(\n\t\t(a, b) =>\n\t\t\tMath.abs(EFFORT_ORDER.indexOf(a) - target) - Math.abs(EFFORT_ORDER.indexOf(b) - target) ||\n\t\t\tEFFORT_ORDER.indexOf(a) - EFFORT_ORDER.indexOf(b),\n\t)[0]!;\n}\n"]}
|
|
@@ -24,9 +24,9 @@ export const BUILT_IN_PROVIDER_DISPLAY_NAMES = {
|
|
|
24
24
|
opencode: "OpenCode Zen",
|
|
25
25
|
"opencode-go": "OpenCode Go",
|
|
26
26
|
openai: "OpenAI",
|
|
27
|
-
"qwen-token-plan": "Qwen Token Plan",
|
|
27
|
+
"qwen-token-plan": "Qwen Token Plan (Team)",
|
|
28
28
|
"qwen-token-plan-individual": "Qwen Token Plan (Individual)",
|
|
29
|
-
"qwen-token-plan-cn": "Qwen Token Plan (China)",
|
|
29
|
+
"qwen-token-plan-cn": "Qwen Token Plan (Team, China)",
|
|
30
30
|
"qwen-token-plan-individual-cn": "Qwen Token Plan (Individual, China)",
|
|
31
31
|
radius: "Radius",
|
|
32
32
|
openrouter: "OpenRouter",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-display-names.js","sourceRoot":"","sources":["../../src/core/provider-display-names.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,+BAA+B,GAA2B;IACtE,SAAS,EAAE,WAAW;IACtB,gBAAgB,EAAE,gBAAgB;IAClC,UAAU,EAAE,UAAU;IACtB,KAAK,EAAE,OAAO;IACd,QAAQ,EAAE,UAAU;IACpB,uBAAuB,EAAE,uBAAuB;IAChD,uBAAuB,EAAE,uBAAuB;IAChD,QAAQ,EAAE,UAAU;IACpB,OAAO,EAAE,SAAS;IAClB,SAAS,EAAE,WAAW;IACtB,MAAM,EAAE,eAAe;IACvB,eAAe,EAAE,kBAAkB;IACnC,IAAI,EAAE,MAAM;IACZ,gBAAgB,EAAE,gBAAgB;IAClC,WAAW,EAAE,cAAc;IAC3B,aAAa,EAAE,iBAAiB;IAChC,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;IAClB,YAAY,EAAE,iBAAiB;IAC/B,UAAU,EAAE,aAAa;IACzB,eAAe,EAAE,qBAAqB;IACtC,MAAM,EAAE,YAAY;IACpB,QAAQ,EAAE,cAAc;IACxB,aAAa,EAAE,aAAa;IAC5B,MAAM,EAAE,QAAQ;IAChB,iBAAiB,EAAE,
|
|
1
|
+
{"version":3,"file":"provider-display-names.js","sourceRoot":"","sources":["../../src/core/provider-display-names.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,+BAA+B,GAA2B;IACtE,SAAS,EAAE,WAAW;IACtB,gBAAgB,EAAE,gBAAgB;IAClC,UAAU,EAAE,UAAU;IACtB,KAAK,EAAE,OAAO;IACd,QAAQ,EAAE,UAAU;IACpB,uBAAuB,EAAE,uBAAuB;IAChD,uBAAuB,EAAE,uBAAuB;IAChD,QAAQ,EAAE,UAAU;IACpB,OAAO,EAAE,SAAS;IAClB,SAAS,EAAE,WAAW;IACtB,MAAM,EAAE,eAAe;IACvB,eAAe,EAAE,kBAAkB;IACnC,IAAI,EAAE,MAAM;IACZ,gBAAgB,EAAE,gBAAgB;IAClC,WAAW,EAAE,cAAc;IAC3B,aAAa,EAAE,iBAAiB;IAChC,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;IAClB,YAAY,EAAE,iBAAiB;IAC/B,UAAU,EAAE,aAAa;IACzB,eAAe,EAAE,qBAAqB;IACtC,MAAM,EAAE,YAAY;IACpB,QAAQ,EAAE,cAAc;IACxB,aAAa,EAAE,aAAa;IAC5B,MAAM,EAAE,QAAQ;IAChB,iBAAiB,EAAE,wBAAwB;IAC3C,4BAA4B,EAAE,8BAA8B;IAC5D,oBAAoB,EAAE,+BAA+B;IACrD,+BAA+B,EAAE,qCAAqC;IACtE,MAAM,EAAE,QAAQ;IAChB,UAAU,EAAE,YAAY;IACxB,QAAQ,EAAE,aAAa;IACvB,mBAAmB,EAAE,mBAAmB;IACxC,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,eAAe,EAAE,yBAAyB;IAC1C,MAAM,EAAE,aAAa;IACrB,sBAAsB,EAAE,gCAAgC;IACxD,uBAAuB,EAAE,oCAAoC;IAC7D,uBAAuB,EAAE,oCAAoC;CAC7D,CAAC","sourcesContent":["export const BUILT_IN_PROVIDER_DISPLAY_NAMES: Record<string, string> = {\n\tanthropic: \"Anthropic\",\n\t\"amazon-bedrock\": \"Amazon Bedrock\",\n\t\"ant-ling\": \"Ant Ling\",\n\tazure: \"Azure\",\n\tcerebras: \"Cerebras\",\n\t\"cloudflare-ai-gateway\": \"Cloudflare AI Gateway\",\n\t\"cloudflare-workers-ai\": \"Cloudflare Workers AI\",\n\tdeepseek: \"DeepSeek\",\n\tbaseten: \"Baseten\",\n\tfireworks: \"Fireworks\",\n\tgoogle: \"Google Gemini\",\n\t\"google-vertex\": \"Google Vertex AI\",\n\tgroq: \"Groq\",\n\t\"github-copilot\": \"GitHub Copilot\",\n\thuggingface: \"Hugging Face\",\n\t\"kimi-coding\": \"Kimi For Coding\",\n\tmistral: \"Mistral\",\n\tminimax: \"MiniMax\",\n\t\"minimax-cn\": \"MiniMax (China)\",\n\tmoonshotai: \"Moonshot AI\",\n\t\"moonshotai-cn\": \"Moonshot AI (China)\",\n\tnvidia: \"NVIDIA NIM\",\n\topencode: \"OpenCode Zen\",\n\t\"opencode-go\": \"OpenCode Go\",\n\topenai: \"OpenAI\",\n\t\"qwen-token-plan\": \"Qwen Token Plan (Team)\",\n\t\"qwen-token-plan-individual\": \"Qwen Token Plan (Individual)\",\n\t\"qwen-token-plan-cn\": \"Qwen Token Plan (Team, China)\",\n\t\"qwen-token-plan-individual-cn\": \"Qwen Token Plan (Individual, China)\",\n\tradius: \"Radius\",\n\topenrouter: \"OpenRouter\",\n\ttogether: \"Together AI\",\n\t\"vercel-ai-gateway\": \"Vercel AI Gateway\",\n\txai: \"xAI\",\n\tzai: \"ZAI\",\n\t\"zai-coding-cn\": \"ZAI Coding Plan (China)\",\n\txiaomi: \"Xiaomi MiMo\",\n\t\"xiaomi-token-plan-cn\": \"Xiaomi MiMo Token Plan (China)\",\n\t\"xiaomi-token-plan-ams\": \"Xiaomi MiMo Token Plan (Amsterdam)\",\n\t\"xiaomi-token-plan-sgp\": \"Xiaomi MiMo Token Plan (Singapore)\",\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote-catalog-provider.d.ts","sourceRoot":"","sources":["../../src/core/remote-catalog-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,QAAQ,EAIb,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,KAAK,oBA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}
|
|
@@ -94,6 +94,12 @@ function isNewer(lastModified, localGeneratedAt) {
|
|
|
94
94
|
function remoteModels(entry, localGeneratedAt) {
|
|
95
95
|
return entry && isNewer(entry.lastModified, localGeneratedAt) ? entry.models : [];
|
|
96
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Request one provider's catalog from pi.dev. The User-Agent carries the tracked pi version, and
|
|
99
|
+
* pi.dev serves the newest catalog published for a minimum version at or below it. So a client
|
|
100
|
+
* receives catalogs published after its release, and those catalogs must work with this client's
|
|
101
|
+
* code.
|
|
102
|
+
*/
|
|
97
103
|
function requestCatalog(providerId, catalogBaseUrl, signal, validator) {
|
|
98
104
|
const url = new URL(`/api/models/providers/${encodeURIComponent(providerId)}`, catalogBaseUrl);
|
|
99
105
|
url.searchParams.set("types", REMOTE_CATALOG_MODEL_TYPES.join(","));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote-catalog-provider.js","sourceRoot":"","sources":["../../src/core/remote-catalog-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,YAAY,EACZ,WAAW,GAKX,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,MAAM,wBAAwB,GAAG,gBAAgB,CAAC;AAClD,MAAM,iCAAiC,GAAG,KAAK,CAAC;AAChD,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AACrE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAyB,CAAC,MAAM,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;AAEhG,SAAS,oBAAoB,CAAC,KAAyB;IACtD,OAAO,CACN,KAAK,CAAC,IAAI,KAAK,SAAS;QACxB,CAAC,OAAO,KAAK,CAA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CAAC,WAAW,EAAE,EAAE;wBACxB,IAAI,WAAW,CAAC,OAAO,KAAK,SAAS;4BAAE,OAAO,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;wBAC3E,YAAY,GAAG,WAAW,CAAC,OAAO,IAAI,SAAS,CAAC;wBAChD,OAAO,OAAO,CAAC,OAAO,CAAC;4BACtB,GAAG,WAAW;4BACd,OAAO,EAAE,eAAe,CAAC,WAAW,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,KAAK,CAAC;yBACtE,CAAC,CAAC;oBACJ,CAAC;iBACD,CAAC,CAAC;YACJ,CAAC;oBAAS,CAAC;gBACV,IAAI,OAAO,CAAC,YAAY,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;oBACrD,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,aAAa,EAAE,EAAE,OAAO,CAAC,CAAC;oBACvD,IAAI,KAAK,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;wBACtC,MAAM,OAAO,CAAC,OAAO,CAAC;4BACrB,OAAO,EAAE,eAAe,CAAC,YAAY,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,KAAK,CAAC;4BAC/D,MAAM,EAAE,GAAG,EAAE;gCACZ,UAAU,GAAG,KAAK,CAAC;4BACpB,CAAC;yBACD,CAAC,CAAC;oBACJ,CAAC;gBACF,CAAC;YACF,CAAC;QACF,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import {\n\ttype AnyModel,\n\tgetModelType,\n\tisModelType,\n\ttype ModelsStoreEntry,\n\ttype ModelType,\n\ttype Provider,\n\ttype RefreshModelsContext,\n} from \"@bastani/pi-ai\";\nimport { VERSION } from \"../config.js\";\nimport { fetchWithRetry } from \"../utils/management-http.ts\";\nimport { getPiUserAgent } from \"../utils/pi-user-agent.ts\";\n\nconst DEFAULT_CATALOG_BASE_URL = \"https://pi.dev\";\nconst REMOTE_CATALOG_ATTEMPT_TIMEOUT_MS = 4_000;\nexport const REMOTE_CATALOG_REFRESH_INTERVAL_MS = 4 * 60 * 60 * 1000;\n/**\n * Model types this client can consume. Sent as `?types=` so the catalog server\n * returns the full-type shard instead of the chat-only one served to clients\n * that predate model types. A server that ignores the parameter still returns\n * the chat-only shard, which this client handles unchanged.\n */\nexport const REMOTE_CATALOG_MODEL_TYPES: readonly ModelType[] = [\"chat\", \"image\", \"classifier\"];\n\nfunction isSupportedModelType(model: { type?: unknown }): boolean {\n\treturn (\n\t\tmodel.type === undefined ||\n\t\t(typeof model.type === \"string\" && REMOTE_CATALOG_MODEL_TYPES.includes(model.type as ModelType))\n\t);\n}\n\nfunction hasOperationShape(model: unknown): boolean {\n\tif (typeof model !== \"object\" || model === null) return false;\n\tif (!(\"type\" in model) || (model.type !== \"image\" && model.type !== \"classifier\")) return true;\n\tif (!(\"cost\" in model)) return false;\n\tconst cost = model.cost;\n\treturn (\n\t\t\"id\" in model &&\n\t\ttypeof model.id === \"string\" &&\n\t\tmodel.id.length > 0 &&\n\t\t\"name\" in model &&\n\t\ttypeof model.name === \"string\" &&\n\t\t\"api\" in model &&\n\t\ttypeof model.api === \"string\" &&\n\t\t\"baseUrl\" in model &&\n\t\ttypeof model.baseUrl === \"string\" &&\n\t\t\"input\" in model &&\n\t\tArray.isArray(model.input) &&\n\t\tcost !== null &&\n\t\ttypeof cost === \"object\" &&\n\t\t[\"input\", \"output\", \"cacheRead\", \"cacheWrite\"].every(\n\t\t\t(key) => key in cost && typeof (cost as Record<string, unknown>)[key] === \"number\",\n\t\t) &&\n\t\t(model.type === \"image\"\n\t\t\t? \"output\" in model && Array.isArray(model.output) && model.output.includes(\"image\")\n\t\t\t: \"contextWindow\" in model && typeof model.contextWindow === \"number\" && model.contextWindow > 0)\n\t);\n}\n\nfunction mergeModels<TModel extends AnyModel>(baseline: readonly TModel[], dynamic: readonly TModel[]): TModel[] {\n\tconst merged = new Map<string, TModel>();\n\tfor (const model of baseline) merged.set(`${getModelType(model)}\\0${model.id}`, model);\n\tfor (const model of dynamic) {\n\t\tconst key = `${getModelType(model)}\\0${model.id}`;\n\t\tconst bundled = merged.get(key);\n\t\tif (\n\t\t\tbundled &&\n\t\t\tisModelType(bundled, \"chat\") &&\n\t\t\tisModelType(model, \"chat\") &&\n\t\t\tmodel.serviceTiers === undefined &&\n\t\t\tbundled.serviceTiers !== undefined\n\t\t) {\n\t\t\tmerged.set(key, { ...model, serviceTiers: bundled.serviceTiers });\n\t\t} else {\n\t\t\tmerged.set(key, model);\n\t\t}\n\t}\n\treturn [...merged.values()];\n}\n\nfunction parseCatalog(providerId: string, value: unknown): AnyModel[] {\n\tconst entries = Array.isArray(value)\n\t\t? value\n\t\t: typeof value === \"object\" && value !== null && \"models\" in value && Array.isArray(value.models)\n\t\t\t? value.models\n\t\t\t: typeof value === \"object\" && value !== null\n\t\t\t\t? Object.values(value)\n\t\t\t\t: undefined;\n\tif (!entries) throw new Error(`Invalid model catalog for provider \"${providerId}\"`);\n\treturn entries\n\t\t.filter((entry): entry is Record<string, unknown> => typeof entry === \"object\" && entry !== null && \"id\" in entry)\n\t\t.filter(isSupportedModelType)\n\t\t.filter(hasOperationShape)\n\t\t.map((model) => ({ ...model, provider: providerId }) as AnyModel);\n}\n\n/** Read a successful pi.dev catalog response. A missing or invalid Last-Modified header is 0. */\nasync function readCatalog(\n\tproviderId: string,\n\tresponse: Response,\n): Promise<{ models: AnyModel[]; lastModified: number; etag: string | undefined }> {\n\tconst lastModified = Date.parse(response.headers.get(\"last-modified\") ?? \"\");\n\treturn {\n\t\tmodels: parseCatalog(providerId, await response.json()),\n\t\tlastModified: Number.isNaN(lastModified) ? 0 : lastModified,\n\t\tetag: response.headers.get(\"etag\") ?? undefined,\n\t};\n}\n\n/** Whether a pi.dev catalog is newer than the model data shipped with Atomic. */\nfunction isNewer(lastModified: number | undefined, localGeneratedAt: number | undefined): boolean {\n\treturn localGeneratedAt === undefined || (lastModified !== undefined && lastModified > localGeneratedAt);\n}\n\nfunction remoteModels(entry: ModelsStoreEntry | undefined, localGeneratedAt: number | undefined): readonly AnyModel[] {\n\treturn entry && isNewer(entry.lastModified, localGeneratedAt) ? entry.models : [];\n}\n\nfunction requestCatalog(\n\tproviderId: string,\n\tcatalogBaseUrl: string,\n\tsignal: AbortSignal,\n\tvalidator?: string,\n): Promise<Response> {\n\tconst url = new URL(`/api/models/providers/${encodeURIComponent(providerId)}`, catalogBaseUrl);\n\turl.searchParams.set(\"types\", REMOTE_CATALOG_MODEL_TYPES.join(\",\"));\n\treturn fetchWithRetry(\n\t\turl,\n\t\t{\n\t\t\theaders: {\n\t\t\t\taccept: \"application/json\",\n\t\t\t\t\"User-Agent\": getPiUserAgent(VERSION),\n\t\t\t\t...(validator ? { \"if-none-match\": validator } : {}),\n\t\t\t},\n\t\t\tsignal,\n\t\t},\n\t\t{ attemptTimeoutMs: REMOTE_CATALOG_ATTEMPT_TIMEOUT_MS },\n\t);\n}\n\n/** Replaces the catalog with a credential-specific model list. */\nexport type PersonalizeCatalog = (\n\tcatalog: readonly AnyModel[],\n\tcontext: RefreshModelsContext,\n) => Promise<readonly AnyModel[]>;\n\n/** Add a persisted pi.dev catalog overlay to a static built-in provider. */\nexport function withRemoteCatalog(\n\tprovider: Provider,\n\tcatalogBaseUrl: string = DEFAULT_CATALOG_BASE_URL,\n\tlocalGeneratedAt?: number,\n): Provider {\n\tconst models = provider.getAllModels?.() ?? provider.getModels();\n\tif (models.length > 0 && !models.some(isSupportedModelType)) return provider;\n\n\tlet dynamicModels: readonly AnyModel[] = [];\n\n\treturn {\n\t\t...provider,\n\t\tgetModels: () =>\n\t\t\tmergeModels(\n\t\t\t\tprovider.getModels(),\n\t\t\t\tdynamicModels.filter((model) => isModelType(model, \"chat\")),\n\t\t\t),\n\t\tgetAllModels: () => mergeModels(provider.getAllModels?.() ?? provider.getModels(), dynamicModels),\n\t\trefreshModelsAuth: \"configured\",\n\t\trefreshModels: async (context) => {\n\t\t\t// 0.84.1 hands the snapshot in directly and coalesces concurrent refreshes\n\t\t\t// itself, so the old inflight-promise dedup is gone. Every mutation of\n\t\t\t// dynamicModels now runs inside a generation-checked publish; a false return\n\t\t\t// means a newer refresh already superseded this pass, so it must not continue.\n\t\t\tconst stored = context.stored;\n\t\t\tconst restored = remoteModels(stored, localGeneratedAt).filter(\n\t\t\t\t(model) => model.provider === provider.id && hasOperationShape(model),\n\t\t\t);\n\t\t\tif (\n\t\t\t\t!(await context.publish({\n\t\t\t\t\tupdate: () => {\n\t\t\t\t\t\tdynamicModels = restored;\n\t\t\t\t\t},\n\t\t\t\t}))\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!context.allowNetwork || context.signal.aborted) return;\n\t\t\t// Skip the request if pi.dev was checked less than REMOTE_CATALOG_REFRESH_INTERVAL_MS ago.\n\t\t\t// An entry without lastModified (saved by an older version, or after a failed first request) is\n\t\t\t// always refetched: remoteModels() ignores it, so waiting would leave the overlay empty.\n\t\t\tif (\n\t\t\t\t!context.force &&\n\t\t\t\tstored?.checkedAt !== undefined &&\n\t\t\t\tstored.lastModified !== undefined &&\n\t\t\t\tDate.now() - stored.checkedAt < REMOTE_CATALOG_REFRESH_INTERVAL_MS\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Only revalidate when a cached body backs the validator, so a 304 can never\n\t\t\t// leave the overlay empty.\n\t\t\tconst validator = stored && stored.models.length > 0 ? stored.etag : undefined;\n\t\t\tconst response = await requestCatalog(provider.id, catalogBaseUrl, context.signal, validator);\n\t\t\tif (context.signal.aborted) return;\n\t\t\tconst checkedAt = Date.now();\n\t\t\t// Unchanged: dynamicModels already holds the stored overlay, so only the\n\t\t\t// freshness window moves.\n\t\t\tif (response.status === 304 && stored) {\n\t\t\t\tawait context.publish({ persist: { ...stored, checkedAt } });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (response.status === 404 || response.status === 501) {\n\t\t\t\tawait context.publish({\n\t\t\t\t\tpersist: {\n\t\t\t\t\t\t...(stored ?? { models: [] }),\n\t\t\t\t\t\tcheckedAt,\n\t\t\t\t\t\tlastModified: 0,\n\t\t\t\t\t\tetag: undefined,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!response.ok) {\n\t\t\t\t// Transient failure: the cached body and its validator stay valid, so keep the\n\t\t\t\t// etag and let the next refresh revalidate instead of downloading the catalog.\n\t\t\t\tawait context.publish({ persist: { ...(stored ?? { models: [] }), checkedAt } });\n\t\t\t\tthrow new Error(`Model catalog request failed for ${provider.id}: ${response.status}`);\n\t\t\t}\n\t\t\tconst catalog = await readCatalog(provider.id, response);\n\t\t\tif (context.signal.aborted) return;\n\t\t\tconst entry: ModelsStoreEntry = { ...catalog, checkedAt };\n\t\t\tconst published = remoteModels(entry, localGeneratedAt);\n\t\t\tawait context.publish({\n\t\t\t\tpersist: entry,\n\t\t\t\tupdate: () => {\n\t\t\t\t\tdynamicModels = published;\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t};\n}\n\n/**\n * Like `withRemoteCatalog`, but on each network refresh the catalog (built-in models plus a newer\n * pi.dev catalog) is passed through `personalize` and the result is saved. The saved entry holds\n * the personalized list, not the pi.dev catalog, and replaces the catalog, including offline.\n * The refresh interval and etag revalidation are skipped. An empty list (nothing saved yet, or an\n * empty catalog saved by an older version after a failed or missing pi.dev catalog) falls back to\n * the built-in models.\n */\nexport function withPersonalizedCatalog(\n\tprovider: Provider,\n\tpersonalize: PersonalizeCatalog,\n\tcatalogBaseUrl: string = DEFAULT_CATALOG_BASE_URL,\n\tlocalGeneratedAt?: number,\n): Provider {\n\tlet personalModels: readonly AnyModel[] = [];\n\tconst builtinModels = (): readonly AnyModel[] => provider.getAllModels?.() ?? provider.getModels();\n\tconst getAllModels = (): readonly AnyModel[] => (personalModels.length > 0 ? personalModels : builtinModels());\n\n\treturn {\n\t\t...provider,\n\t\tgetModels: () => getAllModels().filter((model) => isModelType(model, \"chat\")),\n\t\tgetAllModels,\n\t\trefreshModelsAuth: \"credential\",\n\t\trefreshModels: async (context) => {\n\t\t\tconst restored = (context.stored?.models ?? []).filter(\n\t\t\t\t(model) => model.provider === provider.id && hasOperationShape(model),\n\t\t\t);\n\t\t\tif (\n\t\t\t\t!(await context.publish({\n\t\t\t\t\tupdate: () => {\n\t\t\t\t\t\tpersonalModels = restored;\n\t\t\t\t\t},\n\t\t\t\t}))\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!context.allowNetwork || context.signal.aborted) return;\n\n\t\t\tlet remote: readonly AnyModel[] = [];\n\t\t\ttry {\n\t\t\t\tconst response = await requestCatalog(provider.id, catalogBaseUrl, context.signal);\n\t\t\t\tif (response.ok) {\n\t\t\t\t\tconst catalog = await readCatalog(provider.id, response);\n\t\t\t\t\tif (isNewer(catalog.lastModified, localGeneratedAt)) remote = catalog.models;\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\tremote = [];\n\t\t\t}\n\t\t\tif (context.signal.aborted) return;\n\t\t\tconst personalized = await personalize(mergeModels(builtinModels(), remote), context);\n\t\t\tif (context.signal.aborted) return;\n\t\t\tawait context.publish({\n\t\t\t\tpersist: { models: personalized, checkedAt: Date.now() },\n\t\t\t\tupdate: () => {\n\t\t\t\t\tpersonalModels = personalized;\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t};\n}\n\n/**\n * Lists the models an account offers that `catalog` lacks, or undefined when the account's list\n * could not be read, which keeps the models saved before.\n */\nexport type DiscoverModels = (\n\tcatalog: readonly AnyModel[],\n\tcontext: RefreshModelsContext,\n) => Promise<readonly AnyModel[] | undefined>;\n\nfunction isDiscoveredModel(model: AnyModel): boolean {\n\treturn isModelType(model, \"chat\") && model.discovered === true;\n}\n\nfunction modelKey(model: AnyModel): string {\n\treturn `${getModelType(model)}\\0${model.id}`;\n}\n\nfunction withSavedModels(entry: ModelsStoreEntry, saved: readonly AnyModel[]): ModelsStoreEntry {\n\treturn { ...entry, models: [...entry.models, ...saved] };\n}\n\n/**\n * Add the models an account offers beyond the provider's catalog. Each network refresh runs the\n * wrapped provider's own refresh first, then `discover`. Discovered models are saved in the\n * provider's stored entry beside the wrapped provider's data, so a later start restores them without\n * the network. They are replaced only by a list `discover` read; when it could not read one, the saved\n * models stay. The catalog always wins: a discovered ID the catalog also lists is dropped, so a\n * curated entry is never replaced.\n */\nexport function withDiscoveredModels(provider: Provider, discover: DiscoverModels): Provider {\n\tlet discovered: readonly AnyModel[] = [];\n\tconst catalogModels = (): readonly AnyModel[] => provider.getAllModels?.() ?? provider.getModels();\n\tconst withDiscovered = (catalog: readonly AnyModel[]): AnyModel[] => {\n\t\tconst owned = new Set(catalog.map(modelKey));\n\t\treturn [...catalog, ...discovered.filter((model) => !owned.has(modelKey(model)))];\n\t};\n\n\treturn {\n\t\t...provider,\n\t\tgetModels: () => withDiscovered(provider.getModels()).filter((model) => isModelType(model, \"chat\")),\n\t\tgetAllModels: () => withDiscovered(catalogModels()),\n\t\trefreshModelsAuth: \"credential\",\n\t\trefreshModels: async (context) => {\n\t\t\tconst stored = context.stored;\n\t\t\tconst saved = (stored?.models ?? []).filter(\n\t\t\t\t(model) => model.provider === provider.id && isDiscoveredModel(model),\n\t\t\t);\n\t\t\tlet catalogEntry: ModelsStoreEntry | undefined = stored && {\n\t\t\t\t...stored,\n\t\t\t\tmodels: stored.models.filter((model) => !isDiscoveredModel(model)),\n\t\t\t};\n\t\t\tif (\n\t\t\t\t!(await context.publish({\n\t\t\t\t\tupdate: () => {\n\t\t\t\t\t\tdiscovered = saved;\n\t\t\t\t\t},\n\t\t\t\t}))\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tawait provider.refreshModels?.({\n\t\t\t\t\t...context,\n\t\t\t\t\tstored: catalogEntry,\n\t\t\t\t\tpublish: (publication) => {\n\t\t\t\t\t\tif (publication.persist === undefined) return context.publish(publication);\n\t\t\t\t\t\tcatalogEntry = publication.persist ?? undefined;\n\t\t\t\t\t\treturn context.publish({\n\t\t\t\t\t\t\t...publication,\n\t\t\t\t\t\t\tpersist: withSavedModels(publication.persist ?? { models: [] }, saved),\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t} finally {\n\t\t\t\tif (context.allowNetwork && !context.signal.aborted) {\n\t\t\t\t\tconst found = await discover(catalogModels(), context);\n\t\t\t\t\tif (found && !context.signal.aborted) {\n\t\t\t\t\t\tawait context.publish({\n\t\t\t\t\t\t\tpersist: withSavedModels(catalogEntry ?? { models: [] }, found),\n\t\t\t\t\t\t\tupdate: () => {\n\t\t\t\t\t\t\t\tdiscovered = found;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"remote-catalog-provider.js","sourceRoot":"","sources":["../../src/core/remote-catalog-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,YAAY,EACZ,WAAW,GAKX,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,MAAM,wBAAwB,GAAG,gBAAgB,CAAC;AAClD,MAAM,iCAAiC,GAAG,KAAK,CAAC;AAChD,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AACrE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAyB,CAAC,MAAM,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;AAEhG,SAAS,oBAAoB,CAAC,KAAyB;IACtD,OAAO,CACN,KAAK,CAAC,IAAI,KAAK,SAAS;QACxB,CAAC,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,IAA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W,EAAE,EAAE;wBACxB,IAAI,WAAW,CAAC,OAAO,KAAK,SAAS;4BAAE,OAAO,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;wBAC3E,YAAY,GAAG,WAAW,CAAC,OAAO,IAAI,SAAS,CAAC;wBAChD,OAAO,OAAO,CAAC,OAAO,CAAC;4BACtB,GAAG,WAAW;4BACd,OAAO,EAAE,eAAe,CAAC,WAAW,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,KAAK,CAAC;yBACtE,CAAC,CAAC;oBACJ,CAAC;iBACD,CAAC,CAAC;YACJ,CAAC;oBAAS,CAAC;gBACV,IAAI,OAAO,CAAC,YAAY,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;oBACrD,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,aAAa,EAAE,EAAE,OAAO,CAAC,CAAC;oBACvD,IAAI,KAAK,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;wBACtC,MAAM,OAAO,CAAC,OAAO,CAAC;4BACrB,OAAO,EAAE,eAAe,CAAC,YAAY,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,KAAK,CAAC;4BAC/D,MAAM,EAAE,GAAG,EAAE;gCACZ,UAAU,GAAG,KAAK,CAAC;4BACpB,CAAC;yBACD,CAAC,CAAC;oBACJ,CAAC;gBACF,CAAC;YACF,CAAC;QACF,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import {\n\ttype AnyModel,\n\tgetModelType,\n\tisModelType,\n\ttype ModelsStoreEntry,\n\ttype ModelType,\n\ttype Provider,\n\ttype RefreshModelsContext,\n} from \"@bastani/pi-ai\";\nimport { VERSION } from \"../config.js\";\nimport { fetchWithRetry } from \"../utils/management-http.ts\";\nimport { getPiUserAgent } from \"../utils/pi-user-agent.ts\";\n\nconst DEFAULT_CATALOG_BASE_URL = \"https://pi.dev\";\nconst REMOTE_CATALOG_ATTEMPT_TIMEOUT_MS = 4_000;\nexport const REMOTE_CATALOG_REFRESH_INTERVAL_MS = 4 * 60 * 60 * 1000;\n/**\n * Model types this client can consume. Sent as `?types=` so the catalog server\n * returns the full-type shard instead of the chat-only one served to clients\n * that predate model types. A server that ignores the parameter still returns\n * the chat-only shard, which this client handles unchanged.\n */\nexport const REMOTE_CATALOG_MODEL_TYPES: readonly ModelType[] = [\"chat\", \"image\", \"classifier\"];\n\nfunction isSupportedModelType(model: { type?: unknown }): boolean {\n\treturn (\n\t\tmodel.type === undefined ||\n\t\t(typeof model.type === \"string\" && REMOTE_CATALOG_MODEL_TYPES.includes(model.type as ModelType))\n\t);\n}\n\nfunction hasOperationShape(model: unknown): boolean {\n\tif (typeof model !== \"object\" || model === null) return false;\n\tif (!(\"type\" in model) || (model.type !== \"image\" && model.type !== \"classifier\")) return true;\n\tif (!(\"cost\" in model)) return false;\n\tconst cost = model.cost;\n\treturn (\n\t\t\"id\" in model &&\n\t\ttypeof model.id === \"string\" &&\n\t\tmodel.id.length > 0 &&\n\t\t\"name\" in model &&\n\t\ttypeof model.name === \"string\" &&\n\t\t\"api\" in model &&\n\t\ttypeof model.api === \"string\" &&\n\t\t\"baseUrl\" in model &&\n\t\ttypeof model.baseUrl === \"string\" &&\n\t\t\"input\" in model &&\n\t\tArray.isArray(model.input) &&\n\t\tcost !== null &&\n\t\ttypeof cost === \"object\" &&\n\t\t[\"input\", \"output\", \"cacheRead\", \"cacheWrite\"].every(\n\t\t\t(key) => key in cost && typeof (cost as Record<string, unknown>)[key] === \"number\",\n\t\t) &&\n\t\t(model.type === \"image\"\n\t\t\t? \"output\" in model && Array.isArray(model.output) && model.output.includes(\"image\")\n\t\t\t: \"contextWindow\" in model && typeof model.contextWindow === \"number\" && model.contextWindow > 0)\n\t);\n}\n\nfunction mergeModels<TModel extends AnyModel>(baseline: readonly TModel[], dynamic: readonly TModel[]): TModel[] {\n\tconst merged = new Map<string, TModel>();\n\tfor (const model of baseline) merged.set(`${getModelType(model)}\\0${model.id}`, model);\n\tfor (const model of dynamic) {\n\t\tconst key = `${getModelType(model)}\\0${model.id}`;\n\t\tconst bundled = merged.get(key);\n\t\tif (\n\t\t\tbundled &&\n\t\t\tisModelType(bundled, \"chat\") &&\n\t\t\tisModelType(model, \"chat\") &&\n\t\t\tmodel.serviceTiers === undefined &&\n\t\t\tbundled.serviceTiers !== undefined\n\t\t) {\n\t\t\tmerged.set(key, { ...model, serviceTiers: bundled.serviceTiers });\n\t\t} else {\n\t\t\tmerged.set(key, model);\n\t\t}\n\t}\n\treturn [...merged.values()];\n}\n\nfunction parseCatalog(providerId: string, value: unknown): AnyModel[] {\n\tconst entries = Array.isArray(value)\n\t\t? value\n\t\t: typeof value === \"object\" && value !== null && \"models\" in value && Array.isArray(value.models)\n\t\t\t? value.models\n\t\t\t: typeof value === \"object\" && value !== null\n\t\t\t\t? Object.values(value)\n\t\t\t\t: undefined;\n\tif (!entries) throw new Error(`Invalid model catalog for provider \"${providerId}\"`);\n\treturn entries\n\t\t.filter((entry): entry is Record<string, unknown> => typeof entry === \"object\" && entry !== null && \"id\" in entry)\n\t\t.filter(isSupportedModelType)\n\t\t.filter(hasOperationShape)\n\t\t.map((model) => ({ ...model, provider: providerId }) as AnyModel);\n}\n\n/** Read a successful pi.dev catalog response. A missing or invalid Last-Modified header is 0. */\nasync function readCatalog(\n\tproviderId: string,\n\tresponse: Response,\n): Promise<{ models: AnyModel[]; lastModified: number; etag: string | undefined }> {\n\tconst lastModified = Date.parse(response.headers.get(\"last-modified\") ?? \"\");\n\treturn {\n\t\tmodels: parseCatalog(providerId, await response.json()),\n\t\tlastModified: Number.isNaN(lastModified) ? 0 : lastModified,\n\t\tetag: response.headers.get(\"etag\") ?? undefined,\n\t};\n}\n\n/** Whether a pi.dev catalog is newer than the model data shipped with Atomic. */\nfunction isNewer(lastModified: number | undefined, localGeneratedAt: number | undefined): boolean {\n\treturn localGeneratedAt === undefined || (lastModified !== undefined && lastModified > localGeneratedAt);\n}\n\nfunction remoteModels(entry: ModelsStoreEntry | undefined, localGeneratedAt: number | undefined): readonly AnyModel[] {\n\treturn entry && isNewer(entry.lastModified, localGeneratedAt) ? entry.models : [];\n}\n\n/**\n * Request one provider's catalog from pi.dev. The User-Agent carries the tracked pi version, and\n * pi.dev serves the newest catalog published for a minimum version at or below it. So a client\n * receives catalogs published after its release, and those catalogs must work with this client's\n * code.\n */\nfunction requestCatalog(\n\tproviderId: string,\n\tcatalogBaseUrl: string,\n\tsignal: AbortSignal,\n\tvalidator?: string,\n): Promise<Response> {\n\tconst url = new URL(`/api/models/providers/${encodeURIComponent(providerId)}`, catalogBaseUrl);\n\turl.searchParams.set(\"types\", REMOTE_CATALOG_MODEL_TYPES.join(\",\"));\n\treturn fetchWithRetry(\n\t\turl,\n\t\t{\n\t\t\theaders: {\n\t\t\t\taccept: \"application/json\",\n\t\t\t\t\"User-Agent\": getPiUserAgent(VERSION),\n\t\t\t\t...(validator ? { \"if-none-match\": validator } : {}),\n\t\t\t},\n\t\t\tsignal,\n\t\t},\n\t\t{ attemptTimeoutMs: REMOTE_CATALOG_ATTEMPT_TIMEOUT_MS },\n\t);\n}\n\n/** Replaces the catalog with a credential-specific model list. */\nexport type PersonalizeCatalog = (\n\tcatalog: readonly AnyModel[],\n\tcontext: RefreshModelsContext,\n) => Promise<readonly AnyModel[]>;\n\n/** Add a persisted pi.dev catalog overlay to a static built-in provider. */\nexport function withRemoteCatalog(\n\tprovider: Provider,\n\tcatalogBaseUrl: string = DEFAULT_CATALOG_BASE_URL,\n\tlocalGeneratedAt?: number,\n): Provider {\n\tconst models = provider.getAllModels?.() ?? provider.getModels();\n\tif (models.length > 0 && !models.some(isSupportedModelType)) return provider;\n\n\tlet dynamicModels: readonly AnyModel[] = [];\n\n\treturn {\n\t\t...provider,\n\t\tgetModels: () =>\n\t\t\tmergeModels(\n\t\t\t\tprovider.getModels(),\n\t\t\t\tdynamicModels.filter((model) => isModelType(model, \"chat\")),\n\t\t\t),\n\t\tgetAllModels: () => mergeModels(provider.getAllModels?.() ?? provider.getModels(), dynamicModels),\n\t\trefreshModelsAuth: \"configured\",\n\t\trefreshModels: async (context) => {\n\t\t\t// 0.84.1 hands the snapshot in directly and coalesces concurrent refreshes\n\t\t\t// itself, so the old inflight-promise dedup is gone. Every mutation of\n\t\t\t// dynamicModels now runs inside a generation-checked publish; a false return\n\t\t\t// means a newer refresh already superseded this pass, so it must not continue.\n\t\t\tconst stored = context.stored;\n\t\t\tconst restored = remoteModels(stored, localGeneratedAt).filter(\n\t\t\t\t(model) => model.provider === provider.id && hasOperationShape(model),\n\t\t\t);\n\t\t\tif (\n\t\t\t\t!(await context.publish({\n\t\t\t\t\tupdate: () => {\n\t\t\t\t\t\tdynamicModels = restored;\n\t\t\t\t\t},\n\t\t\t\t}))\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!context.allowNetwork || context.signal.aborted) return;\n\t\t\t// Skip the request if pi.dev was checked less than REMOTE_CATALOG_REFRESH_INTERVAL_MS ago.\n\t\t\t// An entry without lastModified (saved by an older version, or after a failed first request) is\n\t\t\t// always refetched: remoteModels() ignores it, so waiting would leave the overlay empty.\n\t\t\tif (\n\t\t\t\t!context.force &&\n\t\t\t\tstored?.checkedAt !== undefined &&\n\t\t\t\tstored.lastModified !== undefined &&\n\t\t\t\tDate.now() - stored.checkedAt < REMOTE_CATALOG_REFRESH_INTERVAL_MS\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Only revalidate when a cached body backs the validator, so a 304 can never\n\t\t\t// leave the overlay empty.\n\t\t\tconst validator = stored && stored.models.length > 0 ? stored.etag : undefined;\n\t\t\tconst response = await requestCatalog(provider.id, catalogBaseUrl, context.signal, validator);\n\t\t\tif (context.signal.aborted) return;\n\t\t\tconst checkedAt = Date.now();\n\t\t\t// Unchanged: dynamicModels already holds the stored overlay, so only the\n\t\t\t// freshness window moves.\n\t\t\tif (response.status === 304 && stored) {\n\t\t\t\tawait context.publish({ persist: { ...stored, checkedAt } });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (response.status === 404 || response.status === 501) {\n\t\t\t\tawait context.publish({\n\t\t\t\t\tpersist: {\n\t\t\t\t\t\t...(stored ?? { models: [] }),\n\t\t\t\t\t\tcheckedAt,\n\t\t\t\t\t\tlastModified: 0,\n\t\t\t\t\t\tetag: undefined,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!response.ok) {\n\t\t\t\t// Transient failure: the cached body and its validator stay valid, so keep the\n\t\t\t\t// etag and let the next refresh revalidate instead of downloading the catalog.\n\t\t\t\tawait context.publish({ persist: { ...(stored ?? { models: [] }), checkedAt } });\n\t\t\t\tthrow new Error(`Model catalog request failed for ${provider.id}: ${response.status}`);\n\t\t\t}\n\t\t\tconst catalog = await readCatalog(provider.id, response);\n\t\t\tif (context.signal.aborted) return;\n\t\t\tconst entry: ModelsStoreEntry = { ...catalog, checkedAt };\n\t\t\tconst published = remoteModels(entry, localGeneratedAt);\n\t\t\tawait context.publish({\n\t\t\t\tpersist: entry,\n\t\t\t\tupdate: () => {\n\t\t\t\t\tdynamicModels = published;\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t};\n}\n\n/**\n * Like `withRemoteCatalog`, but on each network refresh the catalog (built-in models plus a newer\n * pi.dev catalog) is passed through `personalize` and the result is saved. The saved entry holds\n * the personalized list, not the pi.dev catalog, and replaces the catalog, including offline.\n * The refresh interval and etag revalidation are skipped. An empty list (nothing saved yet, or an\n * empty catalog saved by an older version after a failed or missing pi.dev catalog) falls back to\n * the built-in models.\n */\nexport function withPersonalizedCatalog(\n\tprovider: Provider,\n\tpersonalize: PersonalizeCatalog,\n\tcatalogBaseUrl: string = DEFAULT_CATALOG_BASE_URL,\n\tlocalGeneratedAt?: number,\n): Provider {\n\tlet personalModels: readonly AnyModel[] = [];\n\tconst builtinModels = (): readonly AnyModel[] => provider.getAllModels?.() ?? provider.getModels();\n\tconst getAllModels = (): readonly AnyModel[] => (personalModels.length > 0 ? personalModels : builtinModels());\n\n\treturn {\n\t\t...provider,\n\t\tgetModels: () => getAllModels().filter((model) => isModelType(model, \"chat\")),\n\t\tgetAllModels,\n\t\trefreshModelsAuth: \"credential\",\n\t\trefreshModels: async (context) => {\n\t\t\tconst restored = (context.stored?.models ?? []).filter(\n\t\t\t\t(model) => model.provider === provider.id && hasOperationShape(model),\n\t\t\t);\n\t\t\tif (\n\t\t\t\t!(await context.publish({\n\t\t\t\t\tupdate: () => {\n\t\t\t\t\t\tpersonalModels = restored;\n\t\t\t\t\t},\n\t\t\t\t}))\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!context.allowNetwork || context.signal.aborted) return;\n\n\t\t\tlet remote: readonly AnyModel[] = [];\n\t\t\ttry {\n\t\t\t\tconst response = await requestCatalog(provider.id, catalogBaseUrl, context.signal);\n\t\t\t\tif (response.ok) {\n\t\t\t\t\tconst catalog = await readCatalog(provider.id, response);\n\t\t\t\t\tif (isNewer(catalog.lastModified, localGeneratedAt)) remote = catalog.models;\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\tremote = [];\n\t\t\t}\n\t\t\tif (context.signal.aborted) return;\n\t\t\tconst personalized = await personalize(mergeModels(builtinModels(), remote), context);\n\t\t\tif (context.signal.aborted) return;\n\t\t\tawait context.publish({\n\t\t\t\tpersist: { models: personalized, checkedAt: Date.now() },\n\t\t\t\tupdate: () => {\n\t\t\t\t\tpersonalModels = personalized;\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t};\n}\n\n/**\n * Lists the models an account offers that `catalog` lacks, or undefined when the account's list\n * could not be read, which keeps the models saved before.\n */\nexport type DiscoverModels = (\n\tcatalog: readonly AnyModel[],\n\tcontext: RefreshModelsContext,\n) => Promise<readonly AnyModel[] | undefined>;\n\nfunction isDiscoveredModel(model: AnyModel): boolean {\n\treturn isModelType(model, \"chat\") && model.discovered === true;\n}\n\nfunction modelKey(model: AnyModel): string {\n\treturn `${getModelType(model)}\\0${model.id}`;\n}\n\nfunction withSavedModels(entry: ModelsStoreEntry, saved: readonly AnyModel[]): ModelsStoreEntry {\n\treturn { ...entry, models: [...entry.models, ...saved] };\n}\n\n/**\n * Add the models an account offers beyond the provider's catalog. Each network refresh runs the\n * wrapped provider's own refresh first, then `discover`. Discovered models are saved in the\n * provider's stored entry beside the wrapped provider's data, so a later start restores them without\n * the network. They are replaced only by a list `discover` read; when it could not read one, the saved\n * models stay. The catalog always wins: a discovered ID the catalog also lists is dropped, so a\n * curated entry is never replaced.\n */\nexport function withDiscoveredModels(provider: Provider, discover: DiscoverModels): Provider {\n\tlet discovered: readonly AnyModel[] = [];\n\tconst catalogModels = (): readonly AnyModel[] => provider.getAllModels?.() ?? provider.getModels();\n\tconst withDiscovered = (catalog: readonly AnyModel[]): AnyModel[] => {\n\t\tconst owned = new Set(catalog.map(modelKey));\n\t\treturn [...catalog, ...discovered.filter((model) => !owned.has(modelKey(model)))];\n\t};\n\n\treturn {\n\t\t...provider,\n\t\tgetModels: () => withDiscovered(provider.getModels()).filter((model) => isModelType(model, \"chat\")),\n\t\tgetAllModels: () => withDiscovered(catalogModels()),\n\t\trefreshModelsAuth: \"credential\",\n\t\trefreshModels: async (context) => {\n\t\t\tconst stored = context.stored;\n\t\t\tconst saved = (stored?.models ?? []).filter(\n\t\t\t\t(model) => model.provider === provider.id && isDiscoveredModel(model),\n\t\t\t);\n\t\t\tlet catalogEntry: ModelsStoreEntry | undefined = stored && {\n\t\t\t\t...stored,\n\t\t\t\tmodels: stored.models.filter((model) => !isDiscoveredModel(model)),\n\t\t\t};\n\t\t\tif (\n\t\t\t\t!(await context.publish({\n\t\t\t\t\tupdate: () => {\n\t\t\t\t\t\tdiscovered = saved;\n\t\t\t\t\t},\n\t\t\t\t}))\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tawait provider.refreshModels?.({\n\t\t\t\t\t...context,\n\t\t\t\t\tstored: catalogEntry,\n\t\t\t\t\tpublish: (publication) => {\n\t\t\t\t\t\tif (publication.persist === undefined) return context.publish(publication);\n\t\t\t\t\t\tcatalogEntry = publication.persist ?? undefined;\n\t\t\t\t\t\treturn context.publish({\n\t\t\t\t\t\t\t...publication,\n\t\t\t\t\t\t\tpersist: withSavedModels(publication.persist ?? { models: [] }, saved),\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t} finally {\n\t\t\t\tif (context.allowNetwork && !context.signal.aborted) {\n\t\t\t\t\tconst found = await discover(catalogModels(), context);\n\t\t\t\t\tif (found && !context.signal.aborted) {\n\t\t\t\t\t\tawait context.publish({\n\t\t\t\t\t\t\tpersist: withSavedModels(catalogEntry ?? { models: [] }, found),\n\t\t\t\t\t\t\tupdate: () => {\n\t\t\t\t\t\t\t\tdiscovered = found;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t};\n}\n"]}
|
|
@@ -29,7 +29,7 @@ export type TaskMessageDelivery = {
|
|
|
29
29
|
* What a chat's usage meter and footer read of a live session: its model, entries, context use and streaming state.
|
|
30
30
|
* A task's transcript offers it while the task runs, so a chat of the task shows them without owning the session.
|
|
31
31
|
*/
|
|
32
|
-
export type ChatBoxSession = Pick<AgentSession, "state" | "model" | "sessionManager" | "getContextUsage" | "modelRuntime" | "isStreaming">;
|
|
32
|
+
export type ChatBoxSession = Pick<AgentSession, "state" | "model" | "sessionManager" | "getContextUsage" | "modelRuntime" | "isStreaming" | "isCompacting" | "isRetrying" | "isBashRunning">;
|
|
33
33
|
/** Messages a live session holds back until its turn ends. */
|
|
34
34
|
export interface QueuedTaskMessages {
|
|
35
35
|
readonly steering: readonly string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"supervisor.d.ts","sourceRoot":"","sources":["../../../src/core/tasks/supervisor.ts"],"names":[],"mappings":"AAEA,OAAO,KAA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