modelrig 0.4.0 → 0.5.0

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.
Files changed (55) hide show
  1. package/CHANGELOG.md +129 -0
  2. package/README.md +13 -0
  3. package/dist/adapters/gemini.d.ts +39 -0
  4. package/dist/adapters/gemini.d.ts.map +1 -1
  5. package/dist/adapters/gemini.js +53 -2
  6. package/dist/artifacts/artifact.d.ts +3 -2
  7. package/dist/artifacts/artifact.d.ts.map +1 -1
  8. package/dist/artifacts/artifact.js +11 -4
  9. package/dist/artifacts/run-context.d.ts +21 -2
  10. package/dist/artifacts/run-context.d.ts.map +1 -1
  11. package/dist/artifacts/run-context.js +46 -1
  12. package/dist/bakeoff/replay.d.ts.map +1 -1
  13. package/dist/bakeoff/replay.js +17 -1
  14. package/dist/cli.d.ts.map +1 -1
  15. package/dist/cli.js +21 -1
  16. package/dist/index.d.ts +15 -9
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +15 -5
  19. package/dist/registry/select.d.ts +59 -0
  20. package/dist/registry/select.d.ts.map +1 -1
  21. package/dist/registry/select.js +66 -0
  22. package/dist/routes/loader-warnings.d.ts +28 -0
  23. package/dist/routes/loader-warnings.d.ts.map +1 -0
  24. package/dist/routes/loader-warnings.js +56 -0
  25. package/dist/routes/loader.d.ts +1 -11
  26. package/dist/routes/loader.d.ts.map +1 -1
  27. package/dist/routes/loader.js +44 -26
  28. package/dist/run/raw-defaults.d.ts +52 -0
  29. package/dist/run/raw-defaults.d.ts.map +1 -0
  30. package/dist/run/raw-defaults.js +123 -0
  31. package/dist/run/raw.d.ts +12 -0
  32. package/dist/run/raw.d.ts.map +1 -1
  33. package/dist/run/raw.js +90 -8
  34. package/dist/run/resolve.d.ts +17 -1
  35. package/dist/run/resolve.d.ts.map +1 -1
  36. package/dist/run/resolve.js +20 -4
  37. package/dist/run/routing-docs.js +1 -1
  38. package/dist/run/run.d.ts +7 -1
  39. package/dist/run/run.d.ts.map +1 -1
  40. package/dist/run/run.js +14 -33
  41. package/dist/run/variant.d.ts +43 -0
  42. package/dist/run/variant.d.ts.map +1 -0
  43. package/dist/run/variant.js +86 -0
  44. package/dist/savings/emit.d.ts +33 -0
  45. package/dist/savings/emit.d.ts.map +1 -1
  46. package/dist/savings/emit.js +75 -3
  47. package/dist/types/route.d.ts +31 -0
  48. package/dist/types/route.d.ts.map +1 -1
  49. package/dist/watch/evaluate.d.ts +27 -1
  50. package/dist/watch/evaluate.d.ts.map +1 -1
  51. package/dist/watch/evaluate.js +13 -0
  52. package/dist/watch/proposals.d.ts +28 -0
  53. package/dist/watch/proposals.d.ts.map +1 -1
  54. package/dist/watch/proposals.js +51 -0
  55. package/package.json +1 -1
@@ -5,8 +5,7 @@
5
5
  * resolves schema/prompt paths relative to the bundle file, freezes.
6
6
  */
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.RouteConfigError = void 0;
9
- exports.arrayRootSchemaWarning = arrayRootSchemaWarning;
8
+ exports.RouteConfigError = exports.unreferencedTrialCandidatesWarning = exports.arrayRootSchemaWarning = void 0;
10
9
  exports.loadRoutesWithExtra = loadRoutesWithExtra;
11
10
  exports.mergeLoadedRoutes = mergeLoadedRoutes;
12
11
  exports.validateRoutesDir = validateRoutesDir;
@@ -19,28 +18,13 @@ const fingerprint_1 = require("../registry/fingerprint");
19
18
  const template_1 = require("./template");
20
19
  const cache_lint_1 = require("./cache-lint");
21
20
  const sampling_config_1 = require("./sampling-config");
22
- /**
23
- * CE-2 A5 co-item: warn (non-fatal) when a route's output schema has an ARRAY
24
- * root. OpenAI strict structured output (`response_format: json_schema`, strict)
25
- * requires a top-level OBJECT — an array-root schema cannot use strict
26
- * enforcement on OpenAI candidates and silently falls back to non-strict there
27
- * (the walkthrough §10 provider-matrix gap). The route still LOADS and serves as
28
- * declared; the fix is to wrap the array in an object property so strict
29
- * enforcement holds across every provider. Returns the warning line, or null.
30
- * Pure — unit-tested directly.
31
- */
32
- function arrayRootSchemaWarning(route, outputSchema) {
33
- if (outputSchema === null)
34
- return null;
35
- const rootType = outputSchema.type;
36
- if (rootType !== "array")
37
- return null;
38
- return (`route "${route}" declares an output schema whose ROOT is type: "array". OpenAI strict ` +
39
- `structured output requires a top-level object, so strict enforcement cannot apply on OpenAI ` +
40
- `candidates (they fall back to non-strict there). Wrap the array in an object property ` +
41
- `(e.g. { "type": "object", "properties": { "items": <your array> } }) to keep strict ` +
42
- `enforcement across providers. The route loads and serves as declared.`);
43
- }
21
+ const loader_warnings_1 = require("./loader-warnings");
22
+ // Re-exported so existing importers of "./loader" keep resolving these pure
23
+ // advisories (they now live in ./loader-warnings to hold loader.ts under the
24
+ // 700-LOC cap).
25
+ var loader_warnings_2 = require("./loader-warnings");
26
+ Object.defineProperty(exports, "arrayRootSchemaWarning", { enumerable: true, get: function () { return loader_warnings_2.arrayRootSchemaWarning; } });
27
+ Object.defineProperty(exports, "unreferencedTrialCandidatesWarning", { enumerable: true, get: function () { return loader_warnings_2.unreferencedTrialCandidatesWarning; } });
44
28
  /**
45
29
  * Structured config error thrown for any invalid bundle (never a raw Error).
46
30
  * Load-time problems are deliberately NOT RigFailures — the failure taxonomy
@@ -101,7 +85,18 @@ function parseCandidates(raw, problems) {
101
85
  problems.push(`candidates[${i}].provider "${c.provider}" is not a known provider`);
102
86
  continue;
103
87
  }
104
- out.push(Object.freeze({ provider: c.provider, model: c.model }));
88
+ // Declare-first `trial` flag (routing-console spec §4.4): declared, never
89
+ // live-served. Optional; only `true` is carried so an absent/false flag
90
+ // leaves the candidate byte-identical to a pre-R3 candidate.
91
+ if (c.trial !== undefined && typeof c.trial !== "boolean") {
92
+ problems.push(`candidates[${i}].trial must be a boolean`);
93
+ continue;
94
+ }
95
+ out.push(Object.freeze({
96
+ provider: c.provider,
97
+ model: c.model,
98
+ ...(c.trial === true ? { trial: true } : {}),
99
+ }));
105
100
  }
106
101
  return out;
107
102
  }
@@ -223,6 +218,13 @@ function parseRepair(raw, field, candidates, problems) {
223
218
  problems.push(`${field}.repair_model (${repairModel.provider}/${repairModel.model}) is not in the route's declared candidates`);
224
219
  repairModel = null;
225
220
  }
221
+ // Declare-first (spec §4.4): the repair model dispatches LIVE, so a `trial`
222
+ // candidate (declared, never live-served) must not be one — reject at load.
223
+ const rm = repairModel;
224
+ if (rm !== null && candidates.some((c) => c.provider === rm.provider && c.model === rm.model && c.trial === true)) {
225
+ problems.push(`${field}.repair_model (${rm.provider}/${rm.model}) is a trial candidate and cannot be a live repair model`);
226
+ repairModel = null;
227
+ }
226
228
  }
227
229
  if (maxRepairs === 2 && repairModel === null) {
228
230
  problems.push(`${field}.max_repairs=2 requires repair_model (attempt 2 is the designated repair model)`);
@@ -271,6 +273,14 @@ function parseVariants(raw, routeCandidates, problems) {
271
273
  }
272
274
  }
273
275
  }
276
+ // trialOnly (routing-console spec §4.4): a variant whose candidates ALL map
277
+ // to declared `trial` candidates is a trial variant — valid for a bake-off,
278
+ // a live config error. Computed from the route-level trial flags (a variant
279
+ // narrows a subset; the flag lives on the declared candidate), so an empty
280
+ // or inherited candidate list is never trial-only.
281
+ const trialOnly = candidates !== undefined &&
282
+ candidates.length > 0 &&
283
+ candidates.every((vc) => routeCandidates.some((rc) => rc.provider === vc.provider && rc.model === vc.model && rc.trial === true));
274
284
  if (v.prompt_override !== undefined && v.prompt_append !== undefined) {
275
285
  problems.push(`${field} sets both prompt_override and prompt_append — they are mutually exclusive`);
276
286
  }
@@ -293,6 +303,7 @@ function parseVariants(raw, routeCandidates, problems) {
293
303
  ? { json: v.json }
294
304
  : {}),
295
305
  ...(repair !== undefined ? { repair } : {}),
306
+ ...(trialOnly ? { trialOnly: true } : {}),
296
307
  }));
297
308
  }
298
309
  return out;
@@ -440,10 +451,17 @@ function loadBundleFile(filePath) {
440
451
  }
441
452
  // CE-2 A5 co-item: an array-root schema cannot use OpenAI strict enforcement —
442
453
  // warn once at load so the incompatibility is deliberate, never silent.
443
- const arrayRootWarning = arrayRootSchemaWarning(route, outputSchema);
454
+ const arrayRootWarning = (0, loader_warnings_1.arrayRootSchemaWarning)(route, outputSchema);
444
455
  if (arrayRootWarning !== null) {
445
456
  console.warn(`modelrig: ${arrayRootWarning}`);
446
457
  }
458
+ // Declare-first dead-declaration warning (spec §4.4): a trial candidate no
459
+ // variant references is unreachable — warn so the dangling declaration is
460
+ // deliberate, never silent.
461
+ const trialWarning = (0, loader_warnings_1.unreferencedTrialCandidatesWarning)(route, candidates, variants);
462
+ if (trialWarning !== null) {
463
+ console.warn(`modelrig: ${trialWarning}`);
464
+ }
447
465
  return Object.freeze({
448
466
  route: route,
449
467
  version: version,
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Raw-lane defaults (#245, spec R1–R3) — the SINGLE source of truth for what
3
+ * `rig.runRaw` sends when the caller omits a knob, and the generator behind the
4
+ * published defaults table.
5
+ *
6
+ * WHY ITS OWN FILE: `raw.ts` sits near the 700-LOC invariant cap, and this table
7
+ * is the CE-9/`raw-support.ts` pattern — a code constant the runtime reads AND
8
+ * the docs generator renders, so the published table can never drift from the
9
+ * behaviour. `raw.ts` imports `RAW_TIMEOUT_DEFAULT_MS` and resolves the effective
10
+ * timeout from it; the docs builder injects `renderRawDefaults()` at the
11
+ * `<!-- RAW_DEFAULTS -->` marker in `route-bundles.md` and into llms.txt. The
12
+ * drift test asserts the rendered `timeoutMs` default is read from THIS constant
13
+ * (never retyped), so the table and the dispatch agree by construction.
14
+ */
15
+ import type { ServiceTier } from "../types/provider";
16
+ /**
17
+ * R1 — the tier-aware raw-lane timeout default (ms). A raw passthrough should not
18
+ * be shorter-fused than the tier it advertises: `standard`/`priority` target up
19
+ * to 5 min (grounded + large prompts routinely exceed the old 120 s even at
20
+ * standard), `flex` targets the 15-minute budget ModelRig advertises. An explicit
21
+ * `RawRunInput.timeoutMs` always wins; this is only the fallback, and a `timeout`
22
+ * failure on the raw lane teaches the tier + budget in its `fixHint`.
23
+ */
24
+ export declare const RAW_TIMEOUT_DEFAULT_MS: Record<ServiceTier, number>;
25
+ /** One row of the generated defaults table (R2/R3). */
26
+ export interface RawDefaultRow {
27
+ /** The `RawRunInput` field this row documents. */
28
+ readonly knob: string;
29
+ /** The value sent when the caller omits the knob — DERIVED from the constant
30
+ * the runtime uses where one exists (timeoutMs), so it cannot drift. */
31
+ readonly default: string;
32
+ /** The teaching note rendered in the table cell. */
33
+ readonly note: string;
34
+ }
35
+ /**
36
+ * The defaults table (R2/R3) — every behavioural `RawRunInput` knob and what the
37
+ * raw lane does when the caller omits it. `provider`/`model`/`apiKey`/
38
+ * `systemPrompt`/`userPrompt` are the call itself, not defaultable knobs, so they
39
+ * are not listed. Exhaustive over the optional knobs the raw lane exposes; a new
40
+ * knob added to `RawRunInput` should gain a row here (and the `route-bundles`
41
+ * coverage test guards the important ones).
42
+ */
43
+ export declare const RAW_DEFAULTS: readonly RawDefaultRow[];
44
+ /**
45
+ * Render the defaults table as a Markdown table, FROM `RAW_DEFAULTS` (never a
46
+ * hand-written twin — R2/R3). Consumed by the docs generator
47
+ * (scripts/build-docs-site.ts) at the `<!-- RAW_DEFAULTS -->` marker and in
48
+ * llms.txt, so the published table and the runtime defaults derive from one
49
+ * source.
50
+ */
51
+ export declare function renderRawDefaults(): string;
52
+ //# sourceMappingURL=raw-defaults.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"raw-defaults.d.ts","sourceRoot":"","sources":["../../src/run/raw-defaults.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAI9D,CAAC;AAEF,uDAAuD;AACvD,MAAM,WAAW,aAAa;IAC5B,kDAAkD;IAClD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;4EACwE;IACxE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,oDAAoD;IACpD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAeD;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,EAAE,SAAS,aAAa,EA6DhD,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAK1C"}
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ /**
3
+ * Raw-lane defaults (#245, spec R1–R3) — the SINGLE source of truth for what
4
+ * `rig.runRaw` sends when the caller omits a knob, and the generator behind the
5
+ * published defaults table.
6
+ *
7
+ * WHY ITS OWN FILE: `raw.ts` sits near the 700-LOC invariant cap, and this table
8
+ * is the CE-9/`raw-support.ts` pattern — a code constant the runtime reads AND
9
+ * the docs generator renders, so the published table can never drift from the
10
+ * behaviour. `raw.ts` imports `RAW_TIMEOUT_DEFAULT_MS` and resolves the effective
11
+ * timeout from it; the docs builder injects `renderRawDefaults()` at the
12
+ * `<!-- RAW_DEFAULTS -->` marker in `route-bundles.md` and into llms.txt. The
13
+ * drift test asserts the rendered `timeoutMs` default is read from THIS constant
14
+ * (never retyped), so the table and the dispatch agree by construction.
15
+ */
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.RAW_DEFAULTS = exports.RAW_TIMEOUT_DEFAULT_MS = void 0;
18
+ exports.renderRawDefaults = renderRawDefaults;
19
+ /**
20
+ * R1 — the tier-aware raw-lane timeout default (ms). A raw passthrough should not
21
+ * be shorter-fused than the tier it advertises: `standard`/`priority` target up
22
+ * to 5 min (grounded + large prompts routinely exceed the old 120 s even at
23
+ * standard), `flex` targets the 15-minute budget ModelRig advertises. An explicit
24
+ * `RawRunInput.timeoutMs` always wins; this is only the fallback, and a `timeout`
25
+ * failure on the raw lane teaches the tier + budget in its `fixHint`.
26
+ */
27
+ exports.RAW_TIMEOUT_DEFAULT_MS = {
28
+ standard: 300000,
29
+ priority: 300000,
30
+ flex: 900000,
31
+ };
32
+ /** Render `${ms} ms` as whole seconds (both defaults are whole-second values). */
33
+ function secs(ms) {
34
+ return `${ms / 1000} s`;
35
+ }
36
+ /** The tier-aware `timeoutMs` default, rendered FROM `RAW_TIMEOUT_DEFAULT_MS`
37
+ * (never a retyped literal — the drift test locks this to the constant). */
38
+ function timeoutDefaultCell() {
39
+ return `${secs(exports.RAW_TIMEOUT_DEFAULT_MS.standard)} (standard, priority) · ${secs(exports.RAW_TIMEOUT_DEFAULT_MS.flex)} (flex)`;
40
+ }
41
+ /**
42
+ * The defaults table (R2/R3) — every behavioural `RawRunInput` knob and what the
43
+ * raw lane does when the caller omits it. `provider`/`model`/`apiKey`/
44
+ * `systemPrompt`/`userPrompt` are the call itself, not defaultable knobs, so they
45
+ * are not listed. Exhaustive over the optional knobs the raw lane exposes; a new
46
+ * knob added to `RawRunInput` should gain a row here (and the `route-bundles`
47
+ * coverage test guards the important ones).
48
+ */
49
+ exports.RAW_DEFAULTS = [
50
+ {
51
+ knob: "timeoutMs",
52
+ default: timeoutDefaultCell(),
53
+ note: "tier-aware wall-clock deadline; an explicit `timeoutMs` always wins, and a `timeout` failure carries a `fixHint` naming the tier + budget",
54
+ },
55
+ {
56
+ knob: "serviceTier",
57
+ default: "standard",
58
+ note: "forwarded to the adapter; `meta.servedTier` reports what actually served. On `flex`, set `timeoutMs` in minutes (default 900 s)",
59
+ },
60
+ {
61
+ knob: "temperature",
62
+ default: "adapter default — not sent",
63
+ note: "absent ⇒ no `temperature` on the request (byte-identical dispatch)",
64
+ },
65
+ {
66
+ knob: "topP",
67
+ default: "adapter default — not sent",
68
+ note: "absent ⇒ no `topP` on the request (byte-identical dispatch)",
69
+ },
70
+ {
71
+ knob: "maxOutputTokens",
72
+ default: "adapter default — not sent",
73
+ note: "absent ⇒ no output-token cap on the request (byte-identical dispatch)",
74
+ },
75
+ {
76
+ knob: "grounding",
77
+ default: "absent ⇒ byte-identical",
78
+ note: "native provider grounding; provider support per the raw-lane knob matrix",
79
+ },
80
+ {
81
+ knob: "reasoning",
82
+ default: "absent ⇒ byte-identical",
83
+ note: "reasoning/thinking effort; provider support per the raw-lane knob matrix",
84
+ },
85
+ {
86
+ knob: "responseFormat",
87
+ default: "absent ⇒ byte-identical",
88
+ note: "syntactic-JSON forcing (mime-shaping only); provider support per the raw-lane knob matrix",
89
+ },
90
+ {
91
+ knob: "cache",
92
+ default: "none",
93
+ note: "customer cache handle passed through verbatim when supplied; ModelRig never creates, refreshes, or deletes the resource",
94
+ },
95
+ {
96
+ knob: "tags",
97
+ default: "none",
98
+ note: "`lane=raw` and `rung=primary` are stamped by the SDK and cannot be overridden by a caller tag",
99
+ },
100
+ {
101
+ knob: "tools / toolChoice",
102
+ default: "none",
103
+ note: "absent ⇒ no tools declared; on the raw lane a grounding-originated `functionCall` part is NOT a tool-call turn",
104
+ },
105
+ {
106
+ knob: "stepKey",
107
+ default: "auto — `tags.step`, else `<provider>/<model>#<n>` inside a run context",
108
+ note: "names the ground-truth step a run context records for this call (G1); explicit key wins; no run context ⇒ no step",
109
+ },
110
+ ];
111
+ /**
112
+ * Render the defaults table as a Markdown table, FROM `RAW_DEFAULTS` (never a
113
+ * hand-written twin — R2/R3). Consumed by the docs generator
114
+ * (scripts/build-docs-site.ts) at the `<!-- RAW_DEFAULTS -->` marker and in
115
+ * llms.txt, so the published table and the runtime defaults derive from one
116
+ * source.
117
+ */
118
+ function renderRawDefaults() {
119
+ const header = "| Knob | Default | Note |";
120
+ const sep = "|---|---|---|";
121
+ const rows = exports.RAW_DEFAULTS.map((r) => `| \`${r.knob}\` | ${r.default} | ${r.note} |`);
122
+ return [header, sep, ...rows].join("\n");
123
+ }
package/dist/run/raw.d.ts CHANGED
@@ -41,6 +41,7 @@
41
41
  * is ONE table (`run/raw-support.ts`) the guard AND the published docs matrix
42
42
  * both read — they can never disagree (R5).
43
43
  */
44
+ import { type RigManifest } from "../routes/manifest";
44
45
  import type { AdapterRequest, CandidateRef, ProviderId, ReasoningParams, ServiceTier, ToolChoice, ToolDefinition } from "../types/provider";
45
46
  import type { RunResult, RunTags } from "../types/route";
46
47
  import type { RunStreamHandle } from "./stream";
@@ -58,6 +59,13 @@ export interface RawRunInput {
58
59
  readonly systemPrompt: string;
59
60
  readonly userPrompt: string;
60
61
  readonly tags?: RunTags;
62
+ /** G1 (spec §3): names the ground-truth step this raw call records inside an
63
+ * active `run.start` context — the SAME field the routed lane exposes, so a
64
+ * raw call, a routed call, and an `artifact.save` can be composed into ONE
65
+ * step group. Resolution: `stepKey ?? tags.step ?? provider/model#n` (auto).
66
+ * Validated `[A-Za-z0-9_.:#-]{1,128}`; an invalid value is warned and dropped
67
+ * to the auto key. Outside a run context ⇒ ignored (no step is recorded). */
68
+ readonly stepKey?: string;
61
69
  readonly maxOutputTokens?: number;
62
70
  /** CE-6 sampling on the raw lane (spec §2). `temperature`/`topP` are the raw
63
71
  * lane's exposure of the same knobs `RoutePolicy.sampling` gives the routed
@@ -120,6 +128,10 @@ export interface RawRunDeps {
120
128
  * Used only to keep `attemptCost` honest — the raw lane has no envelope, so
121
129
  * it never charges the unpriced fallback; a missing price records `$0`. */
122
130
  readonly unpricedRateUsdPerMTok?: number;
131
+ /** G1 (spec §4): the rig manifest, so the raw lane runs the SAME
132
+ * required-dimension hygiene warning the routed lane does. Null/absent (e.g. a
133
+ * `routesDir: null` runRaw-only rig) ⇒ the warning is a no-op. */
134
+ readonly manifest?: RigManifest | null;
123
135
  }
124
136
  /**
125
137
  * CE-2/CE-9 fail-closed guard (spec §3 F1/F3, CE-9 R1/R2/R4). A DECLARED
@@ -1 +1 @@
1
- {"version":3,"file":"raw.d.ts","sourceRoot":"","sources":["../../src/run/raw.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAiBH,OAAO,KAAK,EACV,cAAc,EAGd,YAAY,EAGZ,UAAU,EACV,eAAe,EACf,WAAW,EACX,UAAU,EACV,cAAc,EACf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAW,SAAS,EAAE,OAAO,EAAE,MAAM,g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AAE,MAAM,CAAC;IACzC;;sEAEkE;IAClE,QAAQ,CAAC,QAAQ,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;CACxC;AAiED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,CAiDhE;AAED,4EAA4E;AAC5E,wBAAgB,eAAe,CAAC,SAAS,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,GAAG,cAAc,CAsC3F;AAoOD;wDACwD;AACxD,wBAAsB,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,SAAS,CAAC,CAYrF;AAcD;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,GAAG,eAAe,CAiDlF"}
package/dist/run/raw.js CHANGED
@@ -55,12 +55,37 @@ const grok_1 = require("../adapters/grok");
55
55
  const openai_1 = require("../adapters/openai");
56
56
  const openai_compat_1 = require("../adapters/openai-compat");
57
57
  const cost_1 = require("./cost");
58
+ const raw_defaults_1 = require("./raw-defaults");
58
59
  const resolve_1 = require("./resolve");
59
60
  const raw_support_1 = require("./raw-support");
60
61
  const failures_1 = require("../types/failures");
61
- /** Absent a route timeout, the raw lane uses a generous default — a passthrough
62
- * should not be shorter-fused than the underlying provider SDK. */
63
- const DEFAULT_RAW_TIMEOUT_MS = 120000;
62
+ const run_context_1 = require("../artifacts/run-context");
63
+ const manifest_1 = require("../routes/manifest");
64
+ /**
65
+ * R1 — resolve the effective raw-lane timeout. An explicit `timeoutMs` always
66
+ * wins; absent, the fallback is TIER-AWARE (`RAW_TIMEOUT_DEFAULT_MS`), because a
67
+ * passthrough should not be shorter-fused than the tier it advertises (a flex
68
+ * grounded prompt needs minutes, not the old 120 s). No pre-dispatch rejection —
69
+ * a short explicit timeout is a choice, and the teaching arrives on the first
70
+ * `timeout` failure (`rawTimeoutFixHint`), which is when the caller is looking.
71
+ */
72
+ function resolveRawTimeoutMs(input) {
73
+ return input.timeoutMs ?? raw_defaults_1.RAW_TIMEOUT_DEFAULT_MS[input.serviceTier ?? "standard"];
74
+ }
75
+ /** R1 — the teaching `fixHint` attached to a `timeout` failure on the raw lane:
76
+ * it names the elapsed budget, the tier, that tier's advertised target, and the
77
+ * two fixes (raise `timeoutMs`, or drop to `standard`). Built from
78
+ * `RAW_TIMEOUT_DEFAULT_MS` so the default it quotes can never drift. */
79
+ function rawTimeoutFixHint(input, tier) {
80
+ const deadlineSec = resolveRawTimeoutMs(input) / 1000;
81
+ const budgetMin = raw_defaults_1.RAW_TIMEOUT_DEFAULT_MS[tier] / 60000;
82
+ const defaultSec = raw_defaults_1.RAW_TIMEOUT_DEFAULT_MS[tier] / 1000;
83
+ // Only flex has a cheaper-latency tier to drop to; at standard/priority the
84
+ // only fix is a longer deadline (never tell a caller to switch to the tier
85
+ // they are already on).
86
+ const tail = tier === "flex" ? ' or use serviceTier: "standard"' : "";
87
+ return `timed out at the ${deadlineSec}s deadline at tier ${tier} — ${tier} targets up to ${budgetMin} min; raise timeoutMs (default ${defaultSec}s)${tail}`;
88
+ }
64
89
  /** Conservative compat-host capability baseline — parity with createRig's
65
90
  * COMPAT_STATIC. Inconsequential for raw calls (outputSchema is always null, so
66
91
  * no JSON shaping fires), kept aligned so a raw and a routed compat call shape
@@ -181,7 +206,8 @@ function buildRawRequest(candidate, input) {
181
206
  // CE-2 F2: forward the DECLARED tier (default "standard"); the meta/row
182
207
  // honesty fix in finalizeRaw reports this same value, never a hardcode.
183
208
  requestedTier: input.serviceTier ?? "standard",
184
- timeoutMs: input.timeoutMs ?? DEFAULT_RAW_TIMEOUT_MS,
209
+ // R1: tier-aware default (RAW_TIMEOUT_DEFAULT_MS); explicit timeoutMs wins.
210
+ timeoutMs: resolveRawTimeoutMs(input),
185
211
  ...(input.maxOutputTokens !== undefined ? { maxOutputTokens: input.maxOutputTokens } : {}),
186
212
  ...(sampling !== undefined ? { sampling } : {}),
187
213
  // CE-2 F1: `{ mode: "native" }` → the adapter's native-grounding directive.
@@ -244,13 +270,35 @@ function recordRawRow(telemetry, p) {
244
270
  };
245
271
  telemetry.record(row);
246
272
  }
273
+ /**
274
+ * Read the ambient run context at the ENTRY of a raw call (spec §4) and, if
275
+ * present, resolve the step key `input.stepKey ?? tags.step ?? provider/model#n`
276
+ * (validated) — so `finalizeRaw` records a ground-truth step exactly like the
277
+ * routed lane. Also runs the required-dimension hygiene warning (spec §4),
278
+ * unconditionally, as the routed lane does. Fail-open: no context ⇒ null and no
279
+ * step is ever recorded; the dispatch is byte-identical to pre-G1.
280
+ */
281
+ function prepareRawStep(deps, input) {
282
+ (0, manifest_1.warnMissingRequiredDimensions)(deps.manifest ?? null, input.tags ?? {});
283
+ const runCtx = (0, run_context_1.getActiveRunContext)();
284
+ if (runCtx === null)
285
+ return null;
286
+ const rawModelId = `${input.provider}/${input.model}`;
287
+ const stepKey = (0, run_context_1.resolveStepKey)(input.stepKey, input.tags?.step, () => runCtx.nextStepKey(rawModelId));
288
+ return { runCtx, stepKey, startedAtIso: new Date().toISOString() };
289
+ }
247
290
  /**
248
291
  * Turn an `AdapterResult` into a RunResult, recording exactly one telemetry row.
249
292
  * Shared by the buffered and streaming paths so cost/telemetry are byte-identical.
250
293
  * On a failure result: record the (possibly billed) row, then throw
251
294
  * `RigFailureError` — the server maps it to a status exactly like the slug lane.
295
+ *
296
+ * G1: when a run context was captured at entry (`step`), a ground-truth step is
297
+ * emitted after the telemetry row on BOTH branches (success and failure) —
298
+ * fail-open, so a buffer error there never affects the returned result. No
299
+ * artifact CONTENT is written on the raw lane (spec F3): steps are metadata.
252
300
  */
253
- function finalizeRaw(deps, input, result, latencyMs) {
301
+ function finalizeRaw(deps, input, result, latencyMs, step) {
254
302
  const unpricedRatePerTok = (deps.unpricedRateUsdPerMTok ?? cost_1.DEFAULT_UNPRICED_RATE_USD_PER_MTOK) / 1000000;
255
303
  const rawModelId = `${input.provider}/${input.model}`;
256
304
  // One call_id for this raw invocation — shared by the (single) recorded row and
@@ -260,6 +308,21 @@ function finalizeRaw(deps, input, result, latencyMs) {
260
308
  const requestedTier = input.serviceTier ?? "standard";
261
309
  // lane is SDK-owned and cannot be overridden by a caller-supplied tag.
262
310
  const tags = { ...(input.tags ?? {}), lane: "raw" };
311
+ // G1: mirror this raw inference into a ground-truth step (parity with the
312
+ // routed lane's record-attempt). task = tags.step ?? provider/model (spec F1).
313
+ // Fail-open is handled inside emitGroundTruthStep (buffer errors are swallowed).
314
+ const emitStep = (inferenceId, failureClass) => {
315
+ if (step === null)
316
+ return;
317
+ step.runCtx.emitGroundTruthStep({
318
+ stepKey: step.stepKey,
319
+ task: input.tags?.step ?? rawModelId,
320
+ inferenceId,
321
+ startedAt: step.startedAtIso,
322
+ endedAt: new Date().toISOString(),
323
+ failureClass,
324
+ });
325
+ };
263
326
  if (!result.ok) {
264
327
  let costUsd = 0;
265
328
  let pricingMissing = false;
@@ -268,8 +331,9 @@ function finalizeRaw(deps, input, result, latencyMs) {
268
331
  costUsd = settled.costUsd;
269
332
  pricingMissing = settled.pricingMissing;
270
333
  }
334
+ const failId = (0, node_crypto_1.randomUUID)();
271
335
  recordRawRow(deps.telemetry, {
272
- id: (0, node_crypto_1.randomUUID)(),
336
+ id: failId,
273
337
  rawModelId,
274
338
  provider: input.provider,
275
339
  model: input.model,
@@ -283,6 +347,16 @@ function finalizeRaw(deps, input, result, latencyMs) {
283
347
  callId,
284
348
  ...(input.cache !== undefined ? { cacheKey: input.cache.key } : {}),
285
349
  });
350
+ emitStep(failId, result.failure.class);
351
+ // R1: a raw-lane timeout is the #245 footgun — attach the tier-aware teaching
352
+ // hint (the customer is looking at THIS error). Any other failure surfaces
353
+ // unchanged. Overrides any adapter-set hint: the tier + budget is the fix.
354
+ if (result.failure.class === "timeout") {
355
+ throw new failures_1.RigFailureError({
356
+ ...result.failure,
357
+ fixHint: rawTimeoutFixHint(input, requestedTier),
358
+ });
359
+ }
286
360
  throw new failures_1.RigFailureError(result.failure);
287
361
  }
288
362
  const { costUsd, pricingMissing } = (0, cost_1.attemptCost)(input.provider, input.model, result.usage, unpricedRatePerTok);
@@ -302,6 +376,7 @@ function finalizeRaw(deps, input, result, latencyMs) {
302
376
  callId,
303
377
  ...(input.cache !== undefined ? { cacheKey: input.cache.key } : {}),
304
378
  });
379
+ emitStep(id, null);
305
380
  const toolCalls = result.toolCalls;
306
381
  const isToolTurn = toolCalls !== undefined && toolCalls.length > 0;
307
382
  const meta = {
@@ -332,11 +407,14 @@ async function runRaw(deps, input) {
332
407
  // CE-2 F1/F3: fail closed on an unsupported declared directive BEFORE building
333
408
  // an adapter — no meter, no provider call, no telemetry row.
334
409
  assertRawKnobsSupported(input);
410
+ // G1: bind the ambient run context at ENTRY (ALS boundary) so a raw call inside
411
+ // a run.start records a ground-truth step (spec §4). Null ⇒ uninstrumented.
412
+ const step = prepareRawStep(deps, input);
335
413
  const adapter = buildRawAdapter(input.provider, input.apiKey);
336
414
  const candidate = (0, resolve_1.mintRawCandidate)(input.provider, input.model);
337
415
  const started = Date.now();
338
416
  const result = await adapter.call(buildRawRequest(candidate, input));
339
- return finalizeRaw(deps, input, result, Date.now() - started);
417
+ return finalizeRaw(deps, input, result, Date.now() - started, step);
340
418
  }
341
419
  function streamEndedFailure(input) {
342
420
  return {
@@ -358,6 +436,10 @@ function streamEndedFailure(input) {
358
436
  * the raw lane has no schema and the streamed bytes ARE the answer.
359
437
  */
360
438
  function runRawStream(deps, input) {
439
+ // G1: read the ambient run context HERE — at the synchronous entry, the ALS
440
+ // boundary — NOT inside the async generator below (which defers to drain time,
441
+ // possibly on a different async context, where getActiveRunContext would miss).
442
+ const step = prepareRawStep(deps, input);
361
443
  let settle;
362
444
  let fail;
363
445
  const result = new Promise((res, rej) => {
@@ -394,7 +476,7 @@ function runRawStream(deps, input) {
394
476
  else {
395
477
  adapterResult = await adapter.call(req);
396
478
  }
397
- const runResult = finalizeRaw(deps, input, adapterResult, Date.now() - started);
479
+ const runResult = finalizeRaw(deps, input, adapterResult, Date.now() - started, step);
398
480
  settle(runResult);
399
481
  yield { type: "final", result: runResult };
400
482
  }
@@ -9,6 +9,16 @@ import type { RouteBundle, RunOptions } from "../types/route";
9
9
  import type { CandidateRef, CapabilityFlag, ProviderId } from "../types/provider";
10
10
  /** Static capability stub — replaced by the probed registry in Phase 2. */
11
11
  export type CapabilityLookup = (provider: ProviderId, model: string) => ReadonlySet<CapabilityFlag>;
12
+ /**
13
+ * Resolution mode (routing-console spec §4.4, R3). `live` is every production
14
+ * path (`rig.run`, `runStream`, `runBundle`, the hosted gateway slug lane) and
15
+ * DROPS `trial` candidates before minting — a declared trial candidate is never
16
+ * served live. `trial` is the bake-off replay path ONLY (`replayVariant`), which
17
+ * keeps trial candidates so a customer can measure a new model on captured
18
+ * traffic before promoting it. Default `live` — every existing caller is
19
+ * byte-for-byte unchanged (no trial candidates ⇒ the filter is a no-op anyway).
20
+ */
21
+ export type RunMode = "live" | "trial";
12
22
  export interface CandidateIterator {
13
23
  /** Next eligible candidate, or null when the set is exhausted. */
14
24
  next(): CandidateRef | null;
@@ -17,6 +27,12 @@ export interface CandidateIterator {
17
27
  * the first `next()`; unchanged by a `next()` that returns null. */
18
28
  readonly index: number;
19
29
  }
30
+ /** The live-resolver capability filter. Exported so the declare-first challenger
31
+ * eligibility (`registry/select.ts` `requirementPredicates` +
32
+ * `evaluateChallengerEligibility`) can pin itself in agreement with what would
33
+ * actually serve — an eligibility that drifted from the live filter would offer
34
+ * a challenger the route could never dispatch. */
35
+ export declare function satisfiesRequirements(route: RouteBundle, flags: ReadonlySet<CapabilityFlag>, searchAvailable: boolean): boolean;
20
36
  /**
21
37
  * Request-time candidate filters (G-2) — optional, applied by resolveCandidates
22
38
  * BEFORE the prefer:[cost] sort. Distinct from route.require (capability + ZDR):
@@ -60,7 +76,7 @@ export interface WarmthShadowLog {
60
76
  }[];
61
77
  readonly diverged: boolean;
62
78
  }
63
- export declare function resolveCandidates(route: RouteBundle, capabilities: CapabilityLookup, costUsdPerMTok: (provider: ProviderId, model: string) => number | null, searchAvailable?: boolean, filter?: CandidateFilter, shadowWarmth?: WarmthShadowOptions): CandidateIterator;
79
+ export declare function resolveCandidates(route: RouteBundle, capabilities: CapabilityLookup, costUsdPerMTok: (provider: ProviderId, model: string) => number | null, searchAvailable?: boolean, filter?: CandidateFilter, shadowWarmth?: WarmthShadowOptions, mode?: RunMode): CandidateIterator;
64
80
  /**
65
81
  * Per-run requirement opt-ins (G-3). A caller can demand zero-retention routing
66
82
  * for a single run without editing the route bundle: `zero_retention` is unioned
@@ -1 +1 @@
1
- {"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/run/resolve.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAElF,2EAA2E;AAC3E,MAAM,MAAM,gBAAgB,GAAG,CAC7B,QAAQ,EAAE,UAAU,EACpB,KAAK,EAAE,MAAM,KACV,WAAW,CAAC,cAAc,CAAC,CAAC;AAEjC,MAAM,WAAW,iBAAiB;IAChC,kEAAkE;IAClE,IAAI,IAAI,YAAY,GAAG,IAAI,CAAC;IAC5B;;wEAEoE;IACpE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AA6CD;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IACrC,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,UAAU,EAAE,CAAC;IACtC,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,UAAU,EAAE,CAAC;CACzC;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,mBAAmB;IAClC;;oFAEgF;IAChF,QAAQ,CAAC,uBAAuB,EAAE,CA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;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,YAAY,CAElF;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,WAAW,EAClB,IAAI,EAAE;IAAE,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC9D,YAAY,GAAG,IAAI,CAMrB"}
@@ -7,12 +7,18 @@
7
7
  * retryable failure the run loop asks for the next candidate.
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.satisfiesRequirements = satisfiesRequirements;
10
11
  exports.resolveCandidates = resolveCandidates;
11
12
  exports.applyRunRequirements = applyRunRequirements;
12
13
  exports.candidateFilterFromOptions = candidateFilterFromOptions;
13
14
  exports.filterSummary = filterSummary;
14
15
  exports.mintRawCandidate = mintRawCandidate;
15
16
  exports.resolveDeclaredCandidate = resolveDeclaredCandidate;
17
+ /** The live-resolver capability filter. Exported so the declare-first challenger
18
+ * eligibility (`registry/select.ts` `requirementPredicates` +
19
+ * `evaluateChallengerEligibility`) can pin itself in agreement with what would
20
+ * actually serve — an eligibility that drifted from the live filter would offer
21
+ * a challenger the route could never dispatch. */
16
22
  function satisfiesRequirements(route, flags, searchAvailable) {
17
23
  for (const requirement of route.require) {
18
24
  switch (requirement) {
@@ -56,11 +62,21 @@ function satisfiesRequirements(route, flags, searchAvailable) {
56
62
  }
57
63
  return true;
58
64
  }
59
- function resolveCandidates(route, capabilities, costUsdPerMTok, searchAvailable = false, filter, shadowWarmth) {
60
- // Filter order (spec §4.1): provider only → provider ignore → capability+ZDR
61
- // → maxPrice → prefer:[cost]. When `filter` is absent every step is a no-op,
62
- // so the path is byte-for-byte the pre-G-2 behavior (back-compat).
65
+ function resolveCandidates(route, capabilities, costUsdPerMTok, searchAvailable = false, filter, shadowWarmth, mode = "live") {
66
+ // Filter order (spec §4.1): trial-drop → provider only → provider ignore →
67
+ // capability+ZDR → maxPrice → prefer:[cost]. When `filter` is absent every
68
+ // step is a no-op, so the path is byte-for-byte the pre-G-2 behavior
69
+ // (back-compat).
63
70
  let pool = route.candidates;
71
+ // Declare-first (spec §4.4): a `trial` candidate is declared but NEVER served
72
+ // live — drop it first, exactly as a `providers.ignore` entry is dropped, on
73
+ // every live path. Only bake-off replay (`mode: "trial"`) keeps it. The
74
+ // candidate-set invariant is untouched: `route.candidates` (the declared set
75
+ // the run loop's runtime guard checks against) still includes trial entries;
76
+ // they are simply never minted into a CandidateRef on a live path.
77
+ if (mode === "live") {
78
+ pool = pool.filter((c) => c.trial !== true);
79
+ }
64
80
  if (filter?.only && filter.only.length > 0) {
65
81
  const only = new Set(filter.only);
66
82
  pool = pool.filter((c) => only.has(c.provider));
@@ -47,7 +47,7 @@ exports.ROUTING_BOUNDARY = [
47
47
  id: "B2",
48
48
  status: "not_built",
49
49
  capability: "Structure on the raw lane",
50
- statement: '`runRaw` never validates or repairs; `responseFormat: "json_object"` shapes MIME, not schema, so `meta.validated` stays false (ruled schema-free in CE-2 F4b; re-requested #223 R2).',
50
+ statement: '`runRaw` never validates or repairs; `responseFormat: "json_object"` shapes MIME, not schema, so `meta.validated` stays false — structure on the raw lane is ruled out by design, and the path is to graduate that step to a route.',
51
51
  tracking: "ruled schema-free on the raw lane; re-request on file",
52
52
  tripwire: { file: "src/run/raw.ts", mustNotMatch: /readonly outputSchema\??:/ },
53
53
  },