modelrig 0.9.0 → 0.10.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 (223) hide show
  1. package/CHANGELOG.md +179 -0
  2. package/README.md +51 -27
  3. package/data/PROVENANCE.md +14 -0
  4. package/data/pricing-map.json +26 -0
  5. package/dist/adapters/attempt-meta-map.d.ts +8 -1
  6. package/dist/adapters/attempt-meta-map.d.ts.map +1 -1
  7. package/dist/adapters/attempt-meta-map.js +4 -0
  8. package/dist/adapters/build-adapters.js +2 -2
  9. package/dist/adapters/gemini.d.ts +28 -1
  10. package/dist/adapters/gemini.d.ts.map +1 -1
  11. package/dist/adapters/gemini.js +38 -9
  12. package/dist/adapters/grok.d.ts.map +1 -1
  13. package/dist/adapters/grok.js +53 -4
  14. package/dist/adapters/openai-compat.d.ts +8 -2
  15. package/dist/adapters/openai-compat.d.ts.map +1 -1
  16. package/dist/adapters/openai-compat.js +8 -1
  17. package/dist/adapters/openai-stream.d.ts +10 -2
  18. package/dist/adapters/openai-stream.d.ts.map +1 -1
  19. package/dist/adapters/openai-stream.js +5 -1
  20. package/dist/adapters/openai.d.ts +10 -1
  21. package/dist/adapters/openai.d.ts.map +1 -1
  22. package/dist/adapters/openai.js +57 -7
  23. package/dist/adapters/responses-api.d.ts +61 -0
  24. package/dist/adapters/responses-api.d.ts.map +1 -0
  25. package/dist/adapters/responses-api.js +124 -0
  26. package/dist/artifacts/artifact.d.ts +20 -0
  27. package/dist/artifacts/artifact.d.ts.map +1 -1
  28. package/dist/artifacts/artifact.js +207 -171
  29. package/dist/artifacts/index.d.ts +3 -1
  30. package/dist/artifacts/index.d.ts.map +1 -1
  31. package/dist/artifacts/index.js +8 -1
  32. package/dist/bakeoff/groundedness.d.ts +58 -0
  33. package/dist/bakeoff/groundedness.d.ts.map +1 -0
  34. package/dist/bakeoff/groundedness.js +165 -0
  35. package/dist/bakeoff/quality.d.ts +14 -1
  36. package/dist/bakeoff/quality.d.ts.map +1 -1
  37. package/dist/bakeoff/quality.js +10 -0
  38. package/dist/bakeoff/replay.d.ts.map +1 -1
  39. package/dist/bakeoff/replay.js +4 -0
  40. package/dist/cli.d.ts.map +1 -1
  41. package/dist/cli.js +8 -0
  42. package/dist/config.d.ts +31 -0
  43. package/dist/config.d.ts.map +1 -1
  44. package/dist/config.js +23 -0
  45. package/dist/doctor-cli.d.ts +7 -0
  46. package/dist/doctor-cli.d.ts.map +1 -0
  47. package/dist/doctor-cli.js +67 -0
  48. package/dist/doctor-preflight.d.ts +52 -0
  49. package/dist/doctor-preflight.d.ts.map +1 -0
  50. package/dist/doctor-preflight.js +112 -0
  51. package/dist/feedback/grade.d.ts +8 -1
  52. package/dist/feedback/grade.d.ts.map +1 -1
  53. package/dist/feedback/grade.js +4 -0
  54. package/dist/gateway/http-protocol.d.ts +19 -0
  55. package/dist/gateway/http-protocol.d.ts.map +1 -1
  56. package/dist/gateway/serve-client.d.ts +99 -0
  57. package/dist/gateway/serve-client.d.ts.map +1 -0
  58. package/dist/gateway/serve-client.js +360 -0
  59. package/dist/index.d.ts +25 -3
  60. package/dist/index.d.ts.map +1 -1
  61. package/dist/index.js +62 -8
  62. package/dist/prompts/manifest.d.ts +128 -0
  63. package/dist/prompts/manifest.d.ts.map +1 -0
  64. package/dist/prompts/manifest.js +214 -0
  65. package/dist/prompts/prompt-fetch.d.ts +84 -0
  66. package/dist/prompts/prompt-fetch.d.ts.map +1 -0
  67. package/dist/prompts/prompt-fetch.js +120 -0
  68. package/dist/prompts/prompt-resolve.d.ts +76 -0
  69. package/dist/prompts/prompt-resolve.d.ts.map +1 -0
  70. package/dist/prompts/prompt-resolve.js +93 -0
  71. package/dist/prompts/slot-resolver.d.ts +91 -0
  72. package/dist/prompts/slot-resolver.d.ts.map +1 -0
  73. package/dist/prompts/slot-resolver.js +135 -0
  74. package/dist/prompts/tools-register.d.ts +60 -0
  75. package/dist/prompts/tools-register.d.ts.map +1 -0
  76. package/dist/prompts/tools-register.js +48 -0
  77. package/dist/prompts/version-hash.d.ts +29 -0
  78. package/dist/prompts/version-hash.d.ts.map +1 -0
  79. package/dist/prompts/version-hash.js +54 -0
  80. package/dist/prompts-export-cli.d.ts +21 -0
  81. package/dist/prompts-export-cli.d.ts.map +1 -0
  82. package/dist/prompts-export-cli.js +130 -0
  83. package/dist/registry/cache-policy.d.ts.map +1 -1
  84. package/dist/registry/cache-policy.js +22 -0
  85. package/dist/registry/pricing-shape.d.ts +38 -8
  86. package/dist/registry/pricing-shape.d.ts.map +1 -1
  87. package/dist/registry/pricing-shape.js +40 -12
  88. package/dist/registry/pricing.d.ts +6 -5
  89. package/dist/registry/pricing.d.ts.map +1 -1
  90. package/dist/registry/pricing.js +9 -5
  91. package/dist/routes/destination-loader.d.ts +16 -0
  92. package/dist/routes/destination-loader.d.ts.map +1 -0
  93. package/dist/routes/destination-loader.js +29 -0
  94. package/dist/routes/draft.d.ts +7 -0
  95. package/dist/routes/draft.d.ts.map +1 -1
  96. package/dist/routes/draft.js +12 -0
  97. package/dist/routes/loader.d.ts.map +1 -1
  98. package/dist/routes/loader.js +27 -54
  99. package/dist/routes/output-loader.d.ts +42 -0
  100. package/dist/routes/output-loader.d.ts.map +1 -0
  101. package/dist/routes/output-loader.js +112 -0
  102. package/dist/routes/prompt-loader.d.ts +49 -0
  103. package/dist/routes/prompt-loader.d.ts.map +1 -0
  104. package/dist/routes/prompt-loader.js +113 -0
  105. package/dist/routes/resolved-bundle.d.ts +19 -0
  106. package/dist/routes/resolved-bundle.d.ts.map +1 -1
  107. package/dist/routes/resolved-bundle.js +24 -0
  108. package/dist/routes/screen-loader.d.ts +1 -1
  109. package/dist/routes/screen-loader.d.ts.map +1 -1
  110. package/dist/routes/screen-loader.js +8 -1
  111. package/dist/run/accept.d.ts +3 -0
  112. package/dist/run/accept.d.ts.map +1 -1
  113. package/dist/run/accept.js +1 -0
  114. package/dist/run/cost.d.ts +31 -2
  115. package/dist/run/cost.d.ts.map +1 -1
  116. package/dist/run/cost.js +57 -2
  117. package/dist/run/destination.d.ts +39 -0
  118. package/dist/run/destination.d.ts.map +1 -0
  119. package/dist/run/destination.js +45 -0
  120. package/dist/run/dispatch.d.ts +25 -3
  121. package/dist/run/dispatch.d.ts.map +1 -1
  122. package/dist/run/dispatch.js +26 -4
  123. package/dist/run/raw-defaults.d.ts.map +1 -1
  124. package/dist/run/raw-defaults.js +6 -1
  125. package/dist/run/raw-finalize.d.ts +50 -0
  126. package/dist/run/raw-finalize.d.ts.map +1 -0
  127. package/dist/run/raw-finalize.js +266 -0
  128. package/dist/run/raw-knobs.d.ts +36 -0
  129. package/dist/run/raw-knobs.d.ts.map +1 -0
  130. package/dist/run/raw-knobs.js +99 -0
  131. package/dist/run/raw-request.d.ts +24 -0
  132. package/dist/run/raw-request.d.ts.map +1 -0
  133. package/dist/run/raw-request.js +69 -0
  134. package/dist/run/raw-schema.d.ts +76 -0
  135. package/dist/run/raw-schema.d.ts.map +1 -0
  136. package/dist/run/raw-schema.js +166 -0
  137. package/dist/run/raw-search-cost.d.ts +48 -0
  138. package/dist/run/raw-search-cost.d.ts.map +1 -0
  139. package/dist/run/raw-search-cost.js +78 -0
  140. package/dist/run/raw-support.d.ts +64 -6
  141. package/dist/run/raw-support.d.ts.map +1 -1
  142. package/dist/run/raw-support.js +84 -11
  143. package/dist/run/raw.d.ts +25 -26
  144. package/dist/run/raw.d.ts.map +1 -1
  145. package/dist/run/raw.js +30 -351
  146. package/dist/run/record-attempt.d.ts +8 -0
  147. package/dist/run/record-attempt.d.ts.map +1 -1
  148. package/dist/run/record-attempt.js +26 -12
  149. package/dist/run/repair-attempt.d.ts +68 -0
  150. package/dist/run/repair-attempt.d.ts.map +1 -0
  151. package/dist/run/repair-attempt.js +180 -0
  152. package/dist/run/resolve-destination.d.ts +49 -0
  153. package/dist/run/resolve-destination.d.ts.map +1 -0
  154. package/dist/run/resolve-destination.js +76 -0
  155. package/dist/run/routing-docs.d.ts.map +1 -1
  156. package/dist/run/routing-docs.js +9 -4
  157. package/dist/run/run.d.ts +30 -1
  158. package/dist/run/run.d.ts.map +1 -1
  159. package/dist/run/run.js +75 -148
  160. package/dist/run/telemetry-row.d.ts +92 -0
  161. package/dist/run/telemetry-row.d.ts.map +1 -0
  162. package/dist/run/telemetry-row.js +81 -0
  163. package/dist/run/validate.d.ts +12 -1
  164. package/dist/run/validate.d.ts.map +1 -1
  165. package/dist/run/validate.js +31 -0
  166. package/dist/run/web-search-pricing.d.ts +43 -0
  167. package/dist/run/web-search-pricing.d.ts.map +1 -0
  168. package/dist/run/web-search-pricing.js +56 -0
  169. package/dist/settings/grading-guide.d.ts +27 -1
  170. package/dist/settings/grading-guide.d.ts.map +1 -1
  171. package/dist/status.d.ts +6 -0
  172. package/dist/status.d.ts.map +1 -1
  173. package/dist/status.js +4 -1
  174. package/dist/telemetry/artifact-store.d.ts.map +1 -1
  175. package/dist/telemetry/artifact-store.js +11 -0
  176. package/dist/telemetry/attempt-meta.d.ts +55 -1
  177. package/dist/telemetry/attempt-meta.d.ts.map +1 -1
  178. package/dist/telemetry/attempt-meta.js +24 -1
  179. package/dist/telemetry/exporter-setup.d.ts +2 -0
  180. package/dist/telemetry/exporter-setup.d.ts.map +1 -1
  181. package/dist/telemetry/exporter-setup.js +6 -1
  182. package/dist/telemetry/grade-mappers.d.ts +5 -2
  183. package/dist/telemetry/grade-mappers.d.ts.map +1 -1
  184. package/dist/telemetry/grade-mappers.js +8 -2
  185. package/dist/telemetry/grades-sql.d.ts +4 -1
  186. package/dist/telemetry/grades-sql.d.ts.map +1 -1
  187. package/dist/telemetry/grades-sql.js +26 -3
  188. package/dist/telemetry/ingest-protocol.d.ts +26 -2
  189. package/dist/telemetry/ingest-protocol.d.ts.map +1 -1
  190. package/dist/telemetry/ingest-protocol.js +32 -29
  191. package/dist/telemetry/org-identity.d.ts +44 -0
  192. package/dist/telemetry/org-identity.d.ts.map +1 -0
  193. package/dist/telemetry/org-identity.js +98 -0
  194. package/dist/telemetry/route-registration.d.ts +48 -0
  195. package/dist/telemetry/route-registration.d.ts.map +1 -0
  196. package/dist/telemetry/route-registration.js +77 -0
  197. package/dist/telemetry/sinks.d.ts +10 -1
  198. package/dist/telemetry/sinks.d.ts.map +1 -1
  199. package/dist/telemetry/sinks.js +52 -6
  200. package/dist/telemetry/store-migrations.d.ts.map +1 -1
  201. package/dist/telemetry/store-migrations.js +13 -0
  202. package/dist/tenancy/api-key-format.d.ts +16 -1
  203. package/dist/tenancy/api-key-format.d.ts.map +1 -1
  204. package/dist/tenancy/api-key-format.js +17 -0
  205. package/dist/types/provider.d.ts +20 -3
  206. package/dist/types/provider.d.ts.map +1 -1
  207. package/dist/types/provider.js +1 -0
  208. package/dist/types/route.d.ts +76 -0
  209. package/dist/types/route.d.ts.map +1 -1
  210. package/dist/types/telemetry.d.ts +30 -2
  211. package/dist/types/telemetry.d.ts.map +1 -1
  212. package/docs/agent-skill/SKILL.md +73 -5
  213. package/docs/instrumentation.md +81 -36
  214. package/docs/llms.txt +95 -16
  215. package/docs/managed-serving.md +150 -0
  216. package/docs/mcp-oracle.md +75 -2
  217. package/docs/migration-playbook.md +5 -4
  218. package/docs/quickstart.md +169 -83
  219. package/package.json +3 -2
  220. package/registry/registry.json +82 -0
  221. package/dist/feedback/feedback.d.ts +0 -35
  222. package/dist/feedback/feedback.d.ts.map +0 -1
  223. package/dist/feedback/feedback.js +0 -39
@@ -0,0 +1,266 @@
1
+ "use strict";
2
+ /**
3
+ * Raw-lane finalize + telemetry (spec §4.2/§4.3), extracted from raw.ts (Unified
4
+ * Route U4) to keep raw.ts under the 700-LOC cap (dev-rule P1). PURE MOVE in
5
+ * Phase A — `prepareRawStep`, `finalizeRaw`, `recordRawRow`, and the tier-aware
6
+ * timeout fixHint are byte-identical to their former raw.ts definitions.
7
+ *
8
+ * Raw-lane no-hard-hot-path-dependency invariant preserved: this module imports
9
+ * cost/telemetry/run-context/attempt-meta helpers and the native-search cost
10
+ * recorder — NO route/registry/capability-gate dependency.
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.rawTimeoutFixHint = rawTimeoutFixHint;
14
+ exports.prepareRawStep = prepareRawStep;
15
+ exports.finalizeRaw = finalizeRaw;
16
+ const node_crypto_1 = require("node:crypto");
17
+ const cost_1 = require("./cost");
18
+ const raw_defaults_1 = require("./raw-defaults");
19
+ const raw_request_1 = require("./raw-request");
20
+ const raw_search_cost_1 = require("./raw-search-cost");
21
+ const raw_schema_1 = require("./raw-schema");
22
+ const failures_1 = require("../types/failures");
23
+ const run_context_1 = require("../artifacts/run-context");
24
+ const manifest_1 = require("../routes/manifest");
25
+ const attempt_meta_1 = require("../telemetry/attempt-meta");
26
+ const telemetry_row_1 = require("./telemetry-row");
27
+ /** R1 — the teaching `fixHint` attached to a `timeout` failure on the raw lane:
28
+ * it names the elapsed budget, the tier, that tier's advertised target, and the
29
+ * two fixes (raise `timeoutMs`, or drop to `standard`). Built from
30
+ * `RAW_TIMEOUT_DEFAULT_MS` so the default it quotes can never drift. */
31
+ function rawTimeoutFixHint(input, tier) {
32
+ const deadlineSec = (0, raw_request_1.resolveRawTimeoutMs)(input) / 1000;
33
+ const budgetMin = raw_defaults_1.RAW_TIMEOUT_DEFAULT_MS[tier] / 60000;
34
+ const defaultSec = raw_defaults_1.RAW_TIMEOUT_DEFAULT_MS[tier] / 1000;
35
+ // Only flex has a cheaper-latency tier to drop to; at standard/priority the
36
+ // only fix is a longer deadline (never tell a caller to switch to the tier
37
+ // they are already on).
38
+ const tail = tier === "flex" ? ' or use serviceTier: "standard"' : "";
39
+ return `timed out at the ${deadlineSec}s deadline at tier ${tier} — ${tier} targets up to ${budgetMin} min; raise timeoutMs (default ${defaultSec}s)${tail}`;
40
+ }
41
+ /** Write the metered raw-lane telemetry row. Mirrors the run loop's minimal
42
+ * `recordSearchCostRow` shape: only load-bearing fields set, route = the
43
+ * `provider/model` handle the caller used, lane + key_ownership riding in
44
+ * `tags_json`. The exporter mirrors it on its normal cadence — no lane column,
45
+ * no schema change (telemetry map, 2026-08-10). */
46
+ function recordRawRow(telemetry, p) {
47
+ // U4: assembled by the ONE shared builder (./telemetry-row.ts). The raw lane's
48
+ // former hardcodes are now EXPLICIT inputs to the shared builder rather than
49
+ // literals hidden here: routeVersion 0, attemptsJson "{}", servedVariant null,
50
+ // rung "primary", attemptSeq 1, candidateIndex 0. `lane: "raw"` rides p.tags.
51
+ const row = (0, telemetry_row_1.buildTelemetryRow)({
52
+ id: p.id,
53
+ route: p.rawModelId,
54
+ routeVersion: 0,
55
+ provider: p.provider,
56
+ model: p.model,
57
+ requestedTier: p.requestedTier,
58
+ servedTier: p.usage?.servedTier ?? "standard",
59
+ tokensIn: p.usage?.tokensIn ?? 0,
60
+ tokensOut: p.usage?.tokensOut ?? 0,
61
+ tokensCached: p.usage?.tokensCached ?? 0,
62
+ tokensCacheWrite: p.usage?.tokensCacheWrite ?? 0,
63
+ tokensCacheWrite1h: p.usage?.tokensCacheWrite1h ?? 0,
64
+ costEstimateUsd: p.costUsd,
65
+ latencyMs: p.latencyMs,
66
+ ttfbMs: p.usage?.ttfbMs ?? null,
67
+ failureClass: p.failureClass,
68
+ attemptsJson: "{}",
69
+ // Rung tag (R1 review, F1): the raw lane is a single primary dispatch. Raw
70
+ // rows carry `lane: "raw"` (in p.tags) and are excluded from route rollups,
71
+ // but every row gets a rung for a uniform contract.
72
+ baseTags: p.tags,
73
+ rung: "primary",
74
+ fingerprintCell: null,
75
+ servedVariant: null,
76
+ repairedBy: null,
77
+ pricingMissing: p.pricingMissing,
78
+ // CE-1: a customer cache handle (if supplied) stamps `cache_key`; the raw
79
+ // lane runs no WS-C stamping, so `prefix_fingerprint` is always null and the
80
+ // provenance rule reads any non-null key here as `customer`.
81
+ cacheKey: p.cacheKey ?? null,
82
+ prefixFingerprint: null,
83
+ // Ladder key (spec §2.1 R0): raw lane = one row per call, seq 1, index 0.
84
+ callId: p.callId,
85
+ attemptSeq: 1,
86
+ candidateIndex: 0,
87
+ meta: p.meta,
88
+ });
89
+ telemetry.record(row);
90
+ }
91
+ /**
92
+ * Read the ambient run context at the ENTRY of a raw call (spec §4) and, if
93
+ * present, resolve the step key `input.stepKey ?? tags.step ?? provider/model#n`
94
+ * (validated) — so `finalizeRaw` records a ground-truth step exactly like the
95
+ * routed lane. Also runs the required-dimension hygiene warning (spec §4),
96
+ * unconditionally, as the routed lane does. Fail-open: no context ⇒ null and no
97
+ * step is ever recorded; the dispatch is byte-identical to pre-G1.
98
+ */
99
+ function prepareRawStep(deps, input) {
100
+ const runCtx = (0, run_context_1.getActiveRunContext)();
101
+ // Warn on the EFFECTIVE tags: an auto-stamped run_id (RC-1) is not missing.
102
+ (0, manifest_1.warnMissingRequiredDimensions)(deps.manifest ?? null, (0, run_context_1.withRunIdTag)(input.tags ?? {}, runCtx));
103
+ if (runCtx === null)
104
+ return null;
105
+ const rawModelId = `${input.provider}/${input.model}`;
106
+ const stepKey = (0, run_context_1.resolveStepKey)(input.stepKey, input.tags?.step, () => runCtx.nextStepKey(rawModelId));
107
+ return { runCtx, stepKey, startedAtIso: new Date().toISOString() };
108
+ }
109
+ /**
110
+ * Turn an `AdapterResult` into a RunResult, recording exactly one telemetry row.
111
+ * Shared by the buffered and streaming paths so cost/telemetry are byte-identical.
112
+ * On a failure result: record the (possibly billed) row, then throw
113
+ * `RigFailureError` — the server maps it to a status exactly like the slug lane.
114
+ *
115
+ * G1: when a run context was captured at entry (`step`), a ground-truth step is
116
+ * emitted after the telemetry row on BOTH branches (success and failure) —
117
+ * fail-open, so a buffer error there never affects the returned result. No
118
+ * artifact CONTENT is written on the raw lane (spec F3): steps are metadata.
119
+ */
120
+ function finalizeRaw(deps, input, result, latencyMs, step) {
121
+ const unpricedRatePerTok = (deps.unpricedRateUsdPerMTok ?? cost_1.DEFAULT_UNPRICED_RATE_USD_PER_MTOK) / 1000000;
122
+ const rawModelId = `${input.provider}/${input.model}`;
123
+ // One call_id for this raw invocation — shared by the (single) recorded row and
124
+ // the returned meta (spec §2.1 R0).
125
+ const callId = (0, node_crypto_1.randomUUID)();
126
+ // CE-2 F2: the declared tier is reported truthfully on the row AND the meta.
127
+ const requestedTier = input.serviceTier ?? "standard";
128
+ // RC-1: `run_id` from the ambient run (caller's value wins); lane is SDK-owned
129
+ // and cannot be overridden by a caller-supplied tag.
130
+ // GS-1: `tags.step` from the ambient step key (step.stepKey = caller's stepKey
131
+ // ?? tags.step ?? the auto provider/model#n key) when a run is active and the
132
+ // caller set none — spread FIRST so a caller value wins, and omitted entirely
133
+ // outside a run context so the row stays byte-identical (parity with RC-1).
134
+ const stepTag = step !== null ? { step: step.stepKey } : {};
135
+ const tags = { ...stepTag, ...(0, run_context_1.withRunIdTag)(input.tags ?? {}, step?.runCtx ?? null), lane: "raw" };
136
+ // WI-1 (spec §2, §6.3 lane parity): the attempt envelope, built by the SAME
137
+ // producer + rendered-request canonicalization the routed lane uses. R2: a
138
+ // declared `responseSchema` joins the input_hash exactly as a route schema
139
+ // does (lane parity), and its canonical sha rides `meta.schema_sha`; absent ⇒
140
+ // schema null and no key — byte-identical to pre-R2.
141
+ const schema = input.responseSchema ?? null;
142
+ const schemaSha = schema !== null ? (0, raw_schema_1.rawSchemaSha)(schema) : undefined;
143
+ const declaredToolNames = input.tools?.map((t) => t.function.name);
144
+ const rawMeta = (usage) => (0, attempt_meta_1.summarizeAttemptMeta)({
145
+ ...(result.meta !== undefined ? { adapterMeta: result.meta } : {}),
146
+ renderedRequest: (0, attempt_meta_1.renderRequestForHash)({ system: input.systemPrompt, user: input.userPrompt, schema }),
147
+ outputText: result.ok ? result.text : null,
148
+ ...(declaredToolNames !== undefined ? { declaredToolNames } : {}),
149
+ ...(schemaSha !== undefined ? { schemaSha } : {}),
150
+ provider: input.provider,
151
+ model: input.model,
152
+ ...(usage !== undefined ? { usage } : {}),
153
+ });
154
+ // G1: mirror this raw inference into a ground-truth step (parity with the
155
+ // routed lane's record-attempt). task = tags.step ?? provider/model (spec F1).
156
+ // Fail-open is handled inside emitGroundTruthStep (buffer errors are swallowed).
157
+ const emitStep = (inferenceId, failureClass) => {
158
+ if (step === null)
159
+ return;
160
+ step.runCtx.emitGroundTruthStep({
161
+ stepKey: step.stepKey,
162
+ task: input.tags?.step ?? rawModelId,
163
+ inferenceId,
164
+ startedAt: step.startedAtIso,
165
+ endedAt: new Date().toISOString(),
166
+ failureClass,
167
+ });
168
+ };
169
+ if (!result.ok) {
170
+ let costUsd = 0;
171
+ let pricingMissing = false;
172
+ if (result.usage !== undefined) {
173
+ const settled = (0, cost_1.attemptCost)(input.provider, input.model, result.usage, unpricedRatePerTok);
174
+ costUsd = settled.costUsd;
175
+ pricingMissing = settled.pricingMissing;
176
+ }
177
+ const failId = (0, node_crypto_1.randomUUID)();
178
+ recordRawRow(deps.telemetry, {
179
+ id: failId,
180
+ rawModelId,
181
+ provider: input.provider,
182
+ model: input.model,
183
+ ...(result.usage !== undefined ? { usage: result.usage } : {}),
184
+ costUsd,
185
+ latencyMs,
186
+ requestedTier,
187
+ failureClass: result.failure.class,
188
+ tags,
189
+ pricingMissing,
190
+ callId,
191
+ meta: rawMeta(result.usage),
192
+ ...(input.cache !== undefined ? { cacheKey: input.cache.key } : {}),
193
+ });
194
+ emitStep(failId, result.failure.class);
195
+ // R1: a raw-lane timeout is the #245 footgun — attach the tier-aware teaching
196
+ // hint (the customer is looking at THIS error). Any other failure surfaces
197
+ // unchanged. Overrides any adapter-set hint: the tier + budget is the fix.
198
+ if (result.failure.class === "timeout") {
199
+ throw new failures_1.RigFailureError({
200
+ ...result.failure,
201
+ fixHint: rawTimeoutFixHint(input, requestedTier),
202
+ });
203
+ }
204
+ throw new failures_1.RigFailureError(result.failure);
205
+ }
206
+ const { costUsd, pricingMissing } = (0, cost_1.attemptCost)(input.provider, input.model, result.usage, unpricedRatePerTok);
207
+ const id = (0, node_crypto_1.randomUUID)();
208
+ const toolCalls = result.toolCalls;
209
+ const isToolTurn = toolCalls !== undefined && toolCalls.length > 0;
210
+ // R2 (issue #6): a declared responseSchema is checked HERE, client-side, on a
211
+ // text turn (a tool-call turn is not schema-validated — parity with the run
212
+ // loop). A miss is a BILLED row of class content_invalid (the provider served
213
+ // and charged) + a thrown RigFailureError; the raw lane never repairs/retries.
214
+ const schemaOutcome = schema !== null && !isToolTurn ? (0, raw_schema_1.validateRawOutput)(schema, result.text) : { ok: true };
215
+ recordRawRow(deps.telemetry, {
216
+ id,
217
+ rawModelId,
218
+ provider: input.provider,
219
+ model: input.model,
220
+ usage: result.usage,
221
+ costUsd,
222
+ latencyMs,
223
+ requestedTier,
224
+ failureClass: schemaOutcome.ok ? null : "content_invalid",
225
+ tags,
226
+ pricingMissing,
227
+ callId,
228
+ meta: rawMeta(result.usage),
229
+ ...(input.cache !== undefined ? { cacheKey: input.cache.key } : {}),
230
+ });
231
+ emitStep(id, schemaOutcome.ok ? null : "content_invalid");
232
+ if (!schemaOutcome.ok)
233
+ throw new failures_1.RigFailureError((0, raw_schema_1.rawSchemaMismatchFailure)(input, schemaOutcome.errors));
234
+ // NWS N3: a NATIVE-grounded success writes one extra, legible `rung:"search"`
235
+ // cost row (the `web_search` surcharge) beside the token row — ZERO DDL,
236
+ // recorder in raw-search-cost.ts. Gated on native grounding (a non-grounded
237
+ // success writes none); searchCalls from the Responses usage, else 1 (disclosed).
238
+ if (input.grounding?.mode === "native") {
239
+ (0, raw_search_cost_1.recordRawSearchCostRow)(deps.telemetry, { provider: input.provider, rawModelId, tags, callId, searchCalls: result.searchCalls ?? 1 });
240
+ }
241
+ const meta = {
242
+ inferenceId: id,
243
+ route: rawModelId,
244
+ routeVersion: 0,
245
+ provider: input.provider,
246
+ model: input.model,
247
+ requestedTier,
248
+ servedTier: result.usage.servedTier,
249
+ tokensIn: result.usage.tokensIn,
250
+ tokensOut: result.usage.tokensOut,
251
+ tokensCached: result.usage.tokensCached,
252
+ costEstimateUsd: costUsd,
253
+ latencyMs,
254
+ validated: false, // raw is NEVER validated — the central product claim
255
+ attemptsByClass: {},
256
+ servedVariant: null,
257
+ repairedBy: null,
258
+ callId,
259
+ ...(isToolTurn ? { toolCalls } : {}),
260
+ // NWS N2: first native citations on the raw lane (url_citation shape; a
261
+ // grounded response may carry an empty array — surfaced, never thrown). Absent
262
+ // on every non-grounded call ⇒ key omitted (byte-identical meta).
263
+ ...(result.citations !== undefined ? { citations: result.citations } : {}),
264
+ };
265
+ return { output: isToolTurn ? null : result.text, meta };
266
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Raw-lane fail-closed knob guard (CE-2/CE-9, spec §3 F1/F3, CE-9 R1/R2/R4),
3
+ * extracted from raw.ts (Unified Route U4) to keep raw.ts under the 700-LOC cap
4
+ * (dev-rule P1). PURE MOVE — behavior-preserving: the guard's checks, throw
5
+ * conditions, and teaching fixHints are byte-identical to the former inline
6
+ * `assertRawKnobsSupported`. Re-exported from ./raw so existing importers
7
+ * (`import { assertRawKnobsSupported } from "./raw"`) are unchanged.
8
+ *
9
+ * The raw lane's no-hard-hot-path-dependency invariant is preserved: this module
10
+ * pulls in only the capability vocabulary (`raw-support.ts`) and failure types —
11
+ * no route/registry/capability-gate dependency.
12
+ */
13
+ import type { RawRunInput } from "./raw";
14
+ /**
15
+ * CE-2/CE-9 fail-closed guard (spec §3 F1/F3, CE-9 R1/R2/R4). A DECLARED
16
+ * directive is NEVER silently dropped: a `grounding`/`responseFormat` on a
17
+ * provider that cannot honor it, a `reasoning` on a provider with NO effort
18
+ * control (deepseek/anthropic), or a `grounding.mode` other than the
19
+ * v1-supported `"native"` throws `RigFailureError` `invariant_violation` (the
20
+ * existing TERMINAL class; no new FailureClass member) BEFORE any adapter is
21
+ * built, any provider call is made, or any telemetry row is written.
22
+ *
23
+ * The support facts come from `RAW_KNOB_SUPPORT` (run/raw-support.ts) — the ONE
24
+ * table the published docs matrix also reads, so the guard and the docs can
25
+ * never disagree (R5). What the guard does NOT reject (and why):
26
+ * - reasoning on openai/deepinfra/fireworks is FORWARDED verbatim
27
+ * (`kind: "forward"`) and the provider enforces — a rejection is classified
28
+ * teachably by the adapter (no per-model allowlist, R1).
29
+ * - reasoning on grok is a DISCLOSED coarsening (`kind: "coarsen"`).
30
+ * - reasoning on gemini is model-gated (`kind: "model-gated"`) — the adapter
31
+ * rejects a non-thinking model (`geminiReasoningUnsupported`).
32
+ * Exported so the guard is unit-testable without a network. Idempotent and
33
+ * side-effect-free.
34
+ */
35
+ export declare function assertRawKnobsSupported(input: RawRunInput): void;
36
+ //# sourceMappingURL=raw-knobs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"raw-knobs.d.ts","sourceRoot":"","sources":["../../src/run/raw-knobs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAUH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,CAkEhE"}
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ /**
3
+ * Raw-lane fail-closed knob guard (CE-2/CE-9, spec §3 F1/F3, CE-9 R1/R2/R4),
4
+ * extracted from raw.ts (Unified Route U4) to keep raw.ts under the 700-LOC cap
5
+ * (dev-rule P1). PURE MOVE — behavior-preserving: the guard's checks, throw
6
+ * conditions, and teaching fixHints are byte-identical to the former inline
7
+ * `assertRawKnobsSupported`. Re-exported from ./raw so existing importers
8
+ * (`import { assertRawKnobsSupported } from "./raw"`) are unchanged.
9
+ *
10
+ * The raw lane's no-hard-hot-path-dependency invariant is preserved: this module
11
+ * pulls in only the capability vocabulary (`raw-support.ts`) and failure types —
12
+ * no route/registry/capability-gate dependency.
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.assertRawKnobsSupported = assertRawKnobsSupported;
16
+ const failures_1 = require("../types/failures");
17
+ const raw_support_1 = require("./raw-support");
18
+ const raw_schema_1 = require("./raw-schema");
19
+ /**
20
+ * CE-2/CE-9 fail-closed guard (spec §3 F1/F3, CE-9 R1/R2/R4). A DECLARED
21
+ * directive is NEVER silently dropped: a `grounding`/`responseFormat` on a
22
+ * provider that cannot honor it, a `reasoning` on a provider with NO effort
23
+ * control (deepseek/anthropic), or a `grounding.mode` other than the
24
+ * v1-supported `"native"` throws `RigFailureError` `invariant_violation` (the
25
+ * existing TERMINAL class; no new FailureClass member) BEFORE any adapter is
26
+ * built, any provider call is made, or any telemetry row is written.
27
+ *
28
+ * The support facts come from `RAW_KNOB_SUPPORT` (run/raw-support.ts) — the ONE
29
+ * table the published docs matrix also reads, so the guard and the docs can
30
+ * never disagree (R5). What the guard does NOT reject (and why):
31
+ * - reasoning on openai/deepinfra/fireworks is FORWARDED verbatim
32
+ * (`kind: "forward"`) and the provider enforces — a rejection is classified
33
+ * teachably by the adapter (no per-model allowlist, R1).
34
+ * - reasoning on grok is a DISCLOSED coarsening (`kind: "coarsen"`).
35
+ * - reasoning on gemini is model-gated (`kind: "model-gated"`) — the adapter
36
+ * rejects a non-thinking model (`geminiReasoningUnsupported`).
37
+ * Exported so the guard is unit-testable without a network. Idempotent and
38
+ * side-effect-free.
39
+ */
40
+ function assertRawKnobsSupported(input) {
41
+ const support = raw_support_1.RAW_KNOB_SUPPORT[input.provider];
42
+ const groundingMode = input.grounding?.mode;
43
+ if (groundingMode !== undefined) {
44
+ if (groundingMode !== "native") {
45
+ throw new failures_1.RigFailureError({
46
+ class: "invariant_violation",
47
+ message: `unsupported raw-lane grounding mode "${groundingMode}"`,
48
+ provider: input.provider,
49
+ model: input.model,
50
+ fixHint: 'only { mode: "native" } grounding is supported on the raw lane in v1',
51
+ });
52
+ }
53
+ if (!support.grounding.supported) {
54
+ throw new failures_1.RigFailureError({
55
+ class: "invariant_violation",
56
+ message: `native grounding on the raw lane is not supported for provider "${input.provider}"`,
57
+ provider: input.provider,
58
+ model: input.model,
59
+ fixHint: `native grounding on the raw lane is supported on ${(0, raw_support_1.groundingSupportedProviders)().join(", ")} only; remove grounding or switch provider`,
60
+ });
61
+ }
62
+ }
63
+ if (input.reasoning !== undefined && support.reasoning.kind === "fail-closed") {
64
+ throw new failures_1.RigFailureError({
65
+ class: "invariant_violation",
66
+ message: `reasoning control on the raw lane is not supported for provider "${input.provider}"`,
67
+ provider: input.provider,
68
+ model: input.model,
69
+ // Provider-specific teaching straight from the matrix (deepseek →
70
+ // deepseek-reasoner; anthropic → extended thinking unwired).
71
+ fixHint: support.reasoning.fixHint ??
72
+ "reasoning control is not available for this provider on the raw lane; remove reasoning",
73
+ });
74
+ }
75
+ if (input.responseFormat !== undefined && !support.responseFormat.supported) {
76
+ throw new failures_1.RigFailureError({
77
+ class: "invariant_violation",
78
+ message: `responseFormat on the raw lane is not supported for provider "${input.provider}"`,
79
+ provider: input.provider,
80
+ model: input.model,
81
+ fixHint: `responseFormat: "json_object" on the raw lane is supported on ${(0, raw_support_1.responseFormatSupportedProviders)().join(", ")} only; remove responseFormat or switch provider`,
82
+ });
83
+ }
84
+ // R2 (issue #6): a declared JSON Schema on a provider whose adapter has no
85
+ // NATIVE schema path (deepseek, the compat hosts) is rejected here — it would
86
+ // otherwise be silently dropped or degraded to json_object. Provider list from
87
+ // the matrix, so widening a cell widens the error. Then the SHAPE check (plain
88
+ // object, compiles, not alongside responseFormat) — raw-schema.ts.
89
+ if (input.responseSchema !== undefined && !support.responseSchema.supported) {
90
+ throw new failures_1.RigFailureError({
91
+ class: "invariant_violation",
92
+ message: `responseSchema on the raw lane is not supported for provider "${input.provider}"`,
93
+ provider: input.provider,
94
+ model: input.model,
95
+ fixHint: `responseSchema on the raw lane is supported on ${(0, raw_support_1.responseSchemaSupportedProviders)().join(", ")} only (native structured output); remove responseSchema, use responseFormat: "json_object" (mime-shaping only), or switch provider`,
96
+ });
97
+ }
98
+ (0, raw_schema_1.assertRawResponseSchemaShape)(input);
99
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Raw-lane request shaping (spec §4.2), extracted from raw.ts (Unified Route U4)
3
+ * to keep raw.ts under the 700-LOC cap (dev-rule P1). PURE MOVE — the effective
4
+ * timeout resolution and the `AdapterRequest` shaping are byte-identical to the
5
+ * former inline `resolveRawTimeoutMs` / `buildRawRequest`. `buildRawRequest` is
6
+ * re-exported from ./raw so existing importers are unchanged.
7
+ *
8
+ * No route/registry/capability-gate dependency (raw-lane invariant preserved):
9
+ * only the tier-aware timeout table and provider types.
10
+ */
11
+ import type { AdapterRequest, CandidateRef } from "../types/provider";
12
+ import type { RawRunInput } from "./raw";
13
+ /**
14
+ * R1 — resolve the effective raw-lane timeout. An explicit `timeoutMs` always
15
+ * wins; absent, the fallback is TIER-AWARE (`RAW_TIMEOUT_DEFAULT_MS`), because a
16
+ * passthrough should not be shorter-fused than the tier it advertises (a flex
17
+ * grounded prompt needs minutes, not the old 120 s). No pre-dispatch rejection —
18
+ * a short explicit timeout is a choice, and the teaching arrives on the first
19
+ * `timeout` failure (`rawTimeoutFixHint`), which is when the caller is looking.
20
+ */
21
+ export declare function resolveRawTimeoutMs(input: RawRunInput): number;
22
+ /** Pure raw-lane request shaping — exported for unit tests (no network). */
23
+ export declare function buildRawRequest(candidate: CandidateRef, input: RawRunInput): AdapterRequest;
24
+ //# sourceMappingURL=raw-request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"raw-request.d.ts","sourceRoot":"","sources":["../../src/run/raw-request.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAEzC;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAE9D;AAED,4EAA4E;AAC5E,wBAAgB,eAAe,CAAC,SAAS,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,GAAG,cAAc,CA0C3F"}
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ /**
3
+ * Raw-lane request shaping (spec §4.2), extracted from raw.ts (Unified Route U4)
4
+ * to keep raw.ts under the 700-LOC cap (dev-rule P1). PURE MOVE — the effective
5
+ * timeout resolution and the `AdapterRequest` shaping are byte-identical to the
6
+ * former inline `resolveRawTimeoutMs` / `buildRawRequest`. `buildRawRequest` is
7
+ * re-exported from ./raw so existing importers are unchanged.
8
+ *
9
+ * No route/registry/capability-gate dependency (raw-lane invariant preserved):
10
+ * only the tier-aware timeout table and provider types.
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.resolveRawTimeoutMs = resolveRawTimeoutMs;
14
+ exports.buildRawRequest = buildRawRequest;
15
+ const raw_defaults_1 = require("./raw-defaults");
16
+ /**
17
+ * R1 — resolve the effective raw-lane timeout. An explicit `timeoutMs` always
18
+ * wins; absent, the fallback is TIER-AWARE (`RAW_TIMEOUT_DEFAULT_MS`), because a
19
+ * passthrough should not be shorter-fused than the tier it advertises (a flex
20
+ * grounded prompt needs minutes, not the old 120 s). No pre-dispatch rejection —
21
+ * a short explicit timeout is a choice, and the teaching arrives on the first
22
+ * `timeout` failure (`rawTimeoutFixHint`), which is when the caller is looking.
23
+ */
24
+ function resolveRawTimeoutMs(input) {
25
+ return input.timeoutMs ?? raw_defaults_1.RAW_TIMEOUT_DEFAULT_MS[input.serviceTier ?? "standard"];
26
+ }
27
+ /** Pure raw-lane request shaping — exported for unit tests (no network). */
28
+ function buildRawRequest(candidate, input) {
29
+ // CE-6: forward temperature/topP through AdapterRequest.sampling ONLY when the
30
+ // caller declared at least one — absent, no `sampling` key is added and the
31
+ // request is byte-identical to pre-CE-6. maxOutputTokens keeps its top-level
32
+ // channel (the adapter resolves sampling.maxOutputTokens ?? maxOutputTokens).
33
+ const sampling = input.temperature !== undefined || input.topP !== undefined
34
+ ? {
35
+ ...(input.temperature !== undefined ? { temperature: input.temperature } : {}),
36
+ ...(input.topP !== undefined ? { topP: input.topP } : {}),
37
+ }
38
+ : undefined;
39
+ return {
40
+ candidate,
41
+ systemPrompt: input.systemPrompt,
42
+ userPrompt: input.userPrompt,
43
+ // R2 (issue #6): a declared `responseSchema` rides the adapters' existing
44
+ // NATIVE schema path (outputSchema) — gemini responseJsonSchema, openai/grok
45
+ // strict json_schema, anthropic forced tool. Absent ⇒ null, byte-identical:
46
+ // the raw lane stays unvalidated unless the caller declares a schema.
47
+ outputSchema: input.responseSchema ?? null,
48
+ // CE-2 F2: forward the DECLARED tier (default "standard"); the meta/row
49
+ // honesty fix in finalizeRaw reports this same value, never a hardcode.
50
+ requestedTier: input.serviceTier ?? "standard",
51
+ // R1: tier-aware default (RAW_TIMEOUT_DEFAULT_MS); explicit timeoutMs wins.
52
+ timeoutMs: resolveRawTimeoutMs(input),
53
+ ...(input.maxOutputTokens !== undefined ? { maxOutputTokens: input.maxOutputTokens } : {}),
54
+ ...(sampling !== undefined ? { sampling } : {}),
55
+ // CE-2 F1: `{ mode: "native" }` → the adapter's native-grounding directive.
56
+ // Any other mode / unsupported provider never reaches here — the guard
57
+ // (assertRawKnobsSupported) rejects it pre-dispatch. Absent ⇒ no key added.
58
+ ...(input.grounding?.mode === "native" ? { grounding: true } : {}),
59
+ // CE-2 F3: forward reasoning verbatim; absent ⇒ no key added (byte-identical).
60
+ ...(input.reasoning !== undefined ? { reasoning: input.reasoning } : {}),
61
+ // CE-9 R4: forward the json_object directive verbatim; absent ⇒ no key added
62
+ // (byte-identical). An unsupported provider (anthropic) never reaches here —
63
+ // the guard (assertRawKnobsSupported) rejects it pre-dispatch.
64
+ ...(input.responseFormat !== undefined ? { responseFormat: input.responseFormat } : {}),
65
+ ...(input.tools !== undefined ? { tools: input.tools } : {}),
66
+ ...(input.toolChoice !== undefined ? { toolChoice: input.toolChoice } : {}),
67
+ ...(input.cache !== undefined ? { cache: input.cache } : {}),
68
+ };
69
+ }
@@ -0,0 +1,76 @@
1
+ /**
2
+ * R2 (GitLab issue #6) — `responseSchema` on the raw lane: the schema helpers
3
+ * the guard (raw-knobs.ts) and the finalize path (raw-finalize.ts) share.
4
+ *
5
+ * What the knob IS: a JSON Schema the caller declares on `rig.runRaw`. It is
6
+ * forwarded as the provider's NATIVE structured-output directive (the adapters'
7
+ * existing `AdapterRequest.outputSchema` path — gemini `responseJsonSchema`,
8
+ * openai/grok strict `json_schema`, anthropic a forced tool call) AND the
9
+ * returned text is checked client-side by the SAME Ajv instance the routed lane
10
+ * uses (`createModelrigAjv`, 2020-12 + draft-07). A miss is `content_invalid`.
11
+ *
12
+ * What the knob is NOT: a ladder. The raw lane never repairs, never retries,
13
+ * and never falls through — a schema miss is a terminal, billed `content_invalid`
14
+ * row and a thrown `RigFailureError` whose `fixHint` names the first errors. F4
15
+ * is narrowed, not reversed: `meta.validated` stays `false` because no ladder
16
+ * stands behind the check (routing-docs.ts B2 states the boundary).
17
+ *
18
+ * Why its own file: raw-finalize.ts and raw-knobs.ts both sit under the 700-LOC
19
+ * cap (P1) and neither should pull Ajv + hashing into its header story; this
20
+ * module keeps the raw lane's no-route/registry dependency invariant (it imports
21
+ * only the shared Ajv factory and failure types).
22
+ */
23
+ import type { RigFailure } from "../types/failures";
24
+ import type { ProviderId } from "../types/provider";
25
+ /** Canonical JSON — object keys sorted recursively, arrays in order, no
26
+ * whitespace — so two authored spellings of ONE schema hash identically and a
27
+ * reordered key never reads as drift. Pure; exported for the hash tests. */
28
+ export declare function canonicalJson(value: unknown): string;
29
+ /** `sha256:<hex>` of the canonical schema JSON — the value stamped on
30
+ * `inferences.meta.schema_sha` (a hash, never content; meta-safe by shape). */
31
+ export declare function rawSchemaSha(schema: object): string;
32
+ /** Root `type` of a schema when it declares one (the openai strict-mode
33
+ * object-root check reads this). `undefined` when absent or non-string. */
34
+ export declare function schemaRootType(schema: object): string | undefined;
35
+ /**
36
+ * Pre-dispatch SHAPE check (called from the knob guard): the schema must be a
37
+ * plain JSON-Schema object that Ajv can compile. Anything else throws the
38
+ * existing terminal class `invariant_violation` BEFORE any adapter is built —
39
+ * no meter, no provider call, no telemetry row — with a teaching fixHint. Also
40
+ * the one place the openai strict-root warning lives: strict `json_schema`
41
+ * requires an object root; a non-object root is WARNED (the provider enforces
42
+ * and its rejection is classified teachably by the adapter), never silently
43
+ * rewritten. Idempotent; side-effect-free apart from the warning + compile cache.
44
+ */
45
+ export declare function assertRawResponseSchemaShape(input: {
46
+ readonly provider: ProviderId;
47
+ readonly model: string;
48
+ readonly responseSchema?: object;
49
+ readonly responseFormat?: string;
50
+ }): void;
51
+ export type RawSchemaOutcome = {
52
+ readonly ok: true;
53
+ } | {
54
+ readonly ok: false;
55
+ readonly errors: readonly string[];
56
+ };
57
+ /** The one terminal-error rendering the raw lane makes (parity with run.ts's
58
+ * `content_invalid` message shape); exported for the finalize tests. */
59
+ export declare const RAW_SCHEMA_MAX_ERRORS = 5;
60
+ /**
61
+ * Validate the raw output text against the declared schema with the shared
62
+ * Ajv. Parity with the routed lane's `validateOutput`: a non-JSON body is a
63
+ * schema miss (one `parse` error), and Ajv errors render as `instancePath
64
+ * message`. Never throws — the shape check above already compiled the schema;
65
+ * a late compile failure (cache cleared + a schema that stopped compiling, which
66
+ * cannot happen for the same object) is reported as a miss, not a crash.
67
+ */
68
+ export declare function validateRawOutput(schema: object, text: string): RawSchemaOutcome;
69
+ /** The `content_invalid` failure a raw schema miss raises — the EXISTING class
70
+ * (its table teaching + docsUrl apply via `teach()`), with a raw-lane fixHint:
71
+ * this lane never repairs, so the fix is the prompt/schema or a route. */
72
+ export declare function rawSchemaMismatchFailure(input: {
73
+ readonly provider: ProviderId;
74
+ readonly model: string;
75
+ }, errors: readonly string[]): RigFailure;
76
+ //# sourceMappingURL=raw-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"raw-schema.d.ts","sourceRoot":"","sources":["../../src/run/raw-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAMH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;4EAE4E;AAC5E,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CASpD;AAED;+EAC+E;AAC/E,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;2EAC2E;AAC3E,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAGjE;AAmBD;;;;;;;;;GASG;AACH,wBAAgB,4BAA4B,CAAC,KAAK,EAAE;IAClD,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;CAClC,GAAG,IAAI,CAqCP;AAED,MAAM,MAAM,gBAAgB,GAAG;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAAC;AAElH;wEACwE;AACxE,eAAO,MAAM,qBAAqB,IAAI,CAAC;AAEvC;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,gBAAgB,CAgBhF;AAED;;0EAE0E;AAC1E,wBAAgB,wBAAwB,CACtC,KAAK,EAAE;IAAE,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EAChE,MAAM,EAAE,SAAS,MAAM,EAAE,GACxB,UAAU,CAWZ"}