modelrig 0.3.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 (111) hide show
  1. package/CHANGELOG.md +269 -0
  2. package/README.md +79 -14
  3. package/dist/adapters/deepseek.d.ts.map +1 -1
  4. package/dist/adapters/deepseek.js +8 -1
  5. package/dist/adapters/gemini.d.ts +45 -0
  6. package/dist/adapters/gemini.d.ts.map +1 -1
  7. package/dist/adapters/gemini.js +67 -6
  8. package/dist/adapters/grok.d.ts +7 -0
  9. package/dist/adapters/grok.d.ts.map +1 -1
  10. package/dist/adapters/grok.js +23 -1
  11. package/dist/adapters/openai-compat.d.ts +7 -0
  12. package/dist/adapters/openai-compat.d.ts.map +1 -1
  13. package/dist/adapters/openai-compat.js +24 -1
  14. package/dist/adapters/openai.d.ts +7 -0
  15. package/dist/adapters/openai.d.ts.map +1 -1
  16. package/dist/adapters/openai.js +23 -1
  17. package/dist/artifacts/artifact.d.ts +3 -2
  18. package/dist/artifacts/artifact.d.ts.map +1 -1
  19. package/dist/artifacts/artifact.js +11 -4
  20. package/dist/artifacts/run-context.d.ts +21 -2
  21. package/dist/artifacts/run-context.d.ts.map +1 -1
  22. package/dist/artifacts/run-context.js +46 -1
  23. package/dist/bakeoff/replay.d.ts.map +1 -1
  24. package/dist/bakeoff/replay.js +17 -1
  25. package/dist/cli.d.ts.map +1 -1
  26. package/dist/cli.js +26 -5
  27. package/dist/config.d.ts +7 -1
  28. package/dist/config.d.ts.map +1 -1
  29. package/dist/index.d.ts +21 -15
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +39 -26
  32. package/dist/init/init-cli.d.ts.map +1 -1
  33. package/dist/init/init-cli.js +2 -1
  34. package/dist/init/observe-cli.d.ts.map +1 -1
  35. package/dist/init/observe-cli.js +2 -1
  36. package/dist/registry/select.d.ts +59 -0
  37. package/dist/registry/select.d.ts.map +1 -1
  38. package/dist/registry/select.js +66 -0
  39. package/dist/routes/loader-warnings.d.ts +28 -0
  40. package/dist/routes/loader-warnings.d.ts.map +1 -0
  41. package/dist/routes/loader-warnings.js +56 -0
  42. package/dist/routes/loader.d.ts +1 -11
  43. package/dist/routes/loader.d.ts.map +1 -1
  44. package/dist/routes/loader.js +44 -26
  45. package/dist/routes/sampling-config.d.ts.map +1 -1
  46. package/dist/routes/sampling-config.js +11 -0
  47. package/dist/run/dispatch.d.ts +14 -2
  48. package/dist/run/dispatch.d.ts.map +1 -1
  49. package/dist/run/dispatch.js +31 -2
  50. package/dist/run/ladder-key.d.ts +40 -0
  51. package/dist/run/ladder-key.d.ts.map +1 -0
  52. package/dist/run/ladder-key.js +39 -0
  53. package/dist/run/raw-defaults.d.ts +52 -0
  54. package/dist/run/raw-defaults.d.ts.map +1 -0
  55. package/dist/run/raw-defaults.js +123 -0
  56. package/dist/run/raw-support.d.ts +123 -0
  57. package/dist/run/raw-support.d.ts.map +1 -0
  58. package/dist/run/raw-support.js +150 -0
  59. package/dist/run/raw.d.ts +53 -11
  60. package/dist/run/raw.d.ts.map +1 -1
  61. package/dist/run/raw.js +157 -31
  62. package/dist/run/rawonly.d.ts +60 -0
  63. package/dist/run/rawonly.d.ts.map +1 -0
  64. package/dist/run/rawonly.js +120 -0
  65. package/dist/run/record-attempt.d.ts +14 -1
  66. package/dist/run/record-attempt.d.ts.map +1 -1
  67. package/dist/run/record-attempt.js +43 -2
  68. package/dist/run/resolve.d.ts +21 -1
  69. package/dist/run/resolve.d.ts.map +1 -1
  70. package/dist/run/resolve.js +29 -6
  71. package/dist/run/routing-docs.d.ts +73 -0
  72. package/dist/run/routing-docs.d.ts.map +1 -0
  73. package/dist/run/routing-docs.js +222 -0
  74. package/dist/run/run.d.ts +7 -1
  75. package/dist/run/run.d.ts.map +1 -1
  76. package/dist/run/run.js +38 -55
  77. package/dist/run/variant.d.ts +43 -0
  78. package/dist/run/variant.d.ts.map +1 -0
  79. package/dist/run/variant.js +86 -0
  80. package/dist/savings/emit.d.ts +33 -0
  81. package/dist/savings/emit.d.ts.map +1 -1
  82. package/dist/savings/emit.js +75 -3
  83. package/dist/telemetry/exporter.d.ts.map +1 -1
  84. package/dist/telemetry/exporter.js +6 -0
  85. package/dist/telemetry/ingest-protocol.d.ts +7 -0
  86. package/dist/telemetry/ingest-protocol.d.ts.map +1 -1
  87. package/dist/telemetry/load-error-report.d.ts.map +1 -1
  88. package/dist/telemetry/load-error-report.js +4 -1
  89. package/dist/telemetry/otel-map.d.ts.map +1 -1
  90. package/dist/telemetry/otel-map.js +8 -0
  91. package/dist/telemetry/store-migrations.d.ts +15 -0
  92. package/dist/telemetry/store-migrations.d.ts.map +1 -0
  93. package/dist/telemetry/store-migrations.js +119 -0
  94. package/dist/telemetry/store.d.ts.map +1 -1
  95. package/dist/telemetry/store.js +26 -93
  96. package/dist/types/failures-teaching.js +1 -1
  97. package/dist/types/provider.d.ts +13 -0
  98. package/dist/types/provider.d.ts.map +1 -1
  99. package/dist/types/route.d.ts +37 -1
  100. package/dist/types/route.d.ts.map +1 -1
  101. package/dist/types/telemetry.d.ts +31 -0
  102. package/dist/types/telemetry.d.ts.map +1 -1
  103. package/dist/validate-cli.d.ts.map +1 -1
  104. package/dist/validate-cli.js +17 -4
  105. package/dist/watch/evaluate.d.ts +27 -1
  106. package/dist/watch/evaluate.d.ts.map +1 -1
  107. package/dist/watch/evaluate.js +13 -0
  108. package/dist/watch/proposals.d.ts +28 -0
  109. package/dist/watch/proposals.d.ts.map +1 -1
  110. package/dist/watch/proposals.js +51 -0
  111. package/package.json +1 -1
@@ -0,0 +1,123 @@
1
+ /**
2
+ * CE-9 (spec R5) — the raw-lane provider × knob support matrix, the SINGLE
3
+ * source of truth for which knobs each provider honors on `rig.runRaw`.
4
+ *
5
+ * BOTH the runtime guard (`assertRawKnobsSupported`, run/raw.ts) and the docs
6
+ * generator (scripts/build-docs-site.ts) import `RAW_KNOB_SUPPORT` — so the
7
+ * fail-closed behavior a customer hits at runtime and the published matrix they
8
+ * read beforehand can never disagree. The guard's provider sets are no longer
9
+ * inline literals; adding a provider (or widening a knob) is one edit here.
10
+ *
11
+ * The knob discipline this table encodes (spec R1/R2/R4):
12
+ * - grounding: gemini honors native web grounding (grok's Live Search was retired by
13
+ * xAI — 410 on the CE-9 live gate — so grok is fail-closed until CE-9b lands the
14
+ * Responses-API web_search path); every other provider
15
+ * FAILS CLOSED pre-dispatch (guarded).
16
+ * - reasoning: NO per-model allowlist outside gemini (the drift cost the
17
+ * customer flagged). openai/deepinfra/fireworks forward `level` verbatim as
18
+ * `reasoning_effort` and let the provider enforce (a rejection is classified
19
+ * teachably in each adapter); grok forwards a DISCLOSED coarsening
20
+ * (`coarsenGrokReasoningEffort`); gemini stays model-gated (the adapter
21
+ * rejects a non-thinking model); deepseek + anthropic FAIL CLOSED at the
22
+ * guard with a provider-specific fixHint.
23
+ * - responseFormat ("json_object"): the OpenAI-dialect providers + gemini
24
+ * (mime-shaping only) honor it; anthropic FAILS CLOSED (guarded). This is
25
+ * mime-shaping, NOT schema enforcement — F4 stands (no validation/repair,
26
+ * `meta.validated` stays false).
27
+ * - cache + serviceTier are INFORMATIONAL here (never a hard fail): the cache
28
+ * directive is provider-neutral (a resource HANDLE on gemini, a routing HINT
29
+ * on the prompt_cache_key providers) and serviceTier forwards everywhere.
30
+ */
31
+ import type { ProviderId, ReasoningLevel } from "../types/provider";
32
+ /** How a provider treats a declared `reasoning.level` on the raw lane (R1). */
33
+ export type ReasoningSupportKind =
34
+ /** openai / deepinfra / fireworks — `level` → `reasoning_effort` 1:1,
35
+ * forwarded verbatim; an "unsupported parameter" rejection is classified
36
+ * teachably by the adapter (no per-model allowlist). */
37
+ "forward"
38
+ /** grok — `level` coarsened to xAI's `low|high` via
39
+ * `coarsenGrokReasoningEffort` (a DISCLOSED lossy mapping, never silent). */
40
+ | "coarsen"
41
+ /** gemini — honored only on a thinking-capable model; the adapter rejects a
42
+ * non-thinking model classified (`geminiReasoningUnsupported`). */
43
+ | "model-gated"
44
+ /** deepseek / anthropic — no effort control exists; rejected pre-dispatch by
45
+ * the guard with a provider-specific fixHint. */
46
+ | "fail-closed";
47
+ /** Cache-directive semantics per provider (R3) — documentation only; the raw
48
+ * lane never fails a call over the cache directive. */
49
+ export type CacheSemantics =
50
+ /** gemini — `cache.key` is a `cachedContent` resource HANDLE (customer-owned;
51
+ * ModelRig never creates/refreshes/deletes it). */
52
+ "handle"
53
+ /** openai / grok / deepinfra / fireworks — `cache.key` → `prompt_cache_key`, a
54
+ * routing HINT (openai also maps `ttlSeconds ≥ 86400` → 24h retention). */
55
+ | "hint"
56
+ /** deepseek — automatic prefix cache; the key is not used. */
57
+ | "implicit"
58
+ /** anthropic — prefix caching via `cache_control` markers; the key is not
59
+ * used (out of scope for the raw lane). */
60
+ | "marker";
61
+ /** A guarded knob (grounding / responseFormat): boolean support + the matrix
62
+ * cell text. The guard computes its thrown fixHint from the matrix (the list of
63
+ * supported providers), so widening the matrix updates the error too. */
64
+ export interface KnobFact {
65
+ readonly supported: boolean;
66
+ /** Human teaching string rendered in the docs matrix cell. */
67
+ readonly note: string;
68
+ }
69
+ /** Reasoning support per provider (R1) — `kind` drives the guard (only
70
+ * `fail-closed` throws) and the docs. */
71
+ export interface ReasoningFact {
72
+ readonly kind: ReasoningSupportKind;
73
+ readonly note: string;
74
+ /** Rendered by the guard's thrown error when `kind === "fail-closed"`. */
75
+ readonly fixHint?: string;
76
+ }
77
+ export interface CacheFact {
78
+ readonly semantics: CacheSemantics;
79
+ readonly note: string;
80
+ }
81
+ export interface RawKnobSupport {
82
+ /** GUARDED — a declared `grounding` on an unsupported provider throws. */
83
+ readonly grounding: KnobFact;
84
+ /** GUARDED only when `kind === "fail-closed"` (deepseek/anthropic). */
85
+ readonly reasoning: ReasoningFact;
86
+ /** GUARDED — a declared `responseFormat` on an unsupported provider throws. */
87
+ readonly responseFormat: KnobFact;
88
+ /** INFORMATIONAL — the cache directive never hard-fails on the raw lane. */
89
+ readonly cache: CacheFact;
90
+ /** INFORMATIONAL — serviceTier forwards to every adapter; the served tier
91
+ * reports the truth. */
92
+ readonly serviceTier: KnobFact;
93
+ }
94
+ /**
95
+ * The grok reasoning coarsening (R1): xAI's `reasoning_effort` accepts only
96
+ * `"low" | "high"`, so the four-level neutral vocabulary is coarsened —
97
+ * `minimal, low → "low"`; `medium, high → "high"`. This is a DISCLOSED, lossy
98
+ * mapping (it appears in the matrix note, the grok field's doc comment, and the
99
+ * `grok.test.ts` test), never a silent semantic drop. Kept here — beside the
100
+ * matrix that documents it — as the ONE place the algorithm lives (grok.ts
101
+ * imports it).
102
+ */
103
+ export declare function coarsenGrokReasoningEffort(level: ReasoningLevel): "low" | "high";
104
+ /** The matrix. Exhaustive over ProviderId — a new provider forces a compile
105
+ * error here (Record<ProviderId, …>), so it can never be silently unlisted. */
106
+ export declare const RAW_KNOB_SUPPORT: Record<ProviderId, RawKnobSupport>;
107
+ /** Pure lookup into the matrix (spec R6, exported from the package root). A
108
+ * customer's multi-provider dispatcher ASKS this instead of duplicating the
109
+ * provider lists. */
110
+ export declare function rawKnobSupport(provider: ProviderId): RawKnobSupport;
111
+ /** Providers that honor a knob, in PROVIDER_IDS order — used by the guard to
112
+ * build a "supported on X, Y only" fixHint from the matrix (so the error text
113
+ * can never drift from the table). */
114
+ export declare function groundingSupportedProviders(): readonly ProviderId[];
115
+ export declare function responseFormatSupportedProviders(): readonly ProviderId[];
116
+ /** Matrix-level notes rendered below the table (spec §3.2 restated in docs). */
117
+ export declare const RAW_KNOB_MATRIX_NOTES: readonly string[];
118
+ /** Render the provider × knob matrix as a Markdown table + notes, FROM the
119
+ * matrix (never a hand-written table — R5). Consumed by the docs generator
120
+ * (scripts/build-docs-site.ts) so the published matrix and the runtime guard
121
+ * derive from the same source. */
122
+ export declare function renderRawKnobMatrix(): string;
123
+ //# sourceMappingURL=raw-support.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"raw-support.d.ts","sourceRoot":"","sources":["../../src/run/raw-support.ts"],"names":[],"mappings":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ACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,cAAc,GAAG,KAAK,GAAG,MAAM,CAEhF;AAED;+EAC+E;AAC/E,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,UAAU,EAAE,cAAc,CA+D/D,CAAC;AAEF;;qBAEqB;AACrB,wBAAgB,cAAc,CAAC,QAAQ,EAAE,UAAU,GAAG,cAAc,CAEnE;AAED;;sCAEsC;AACtC,wBAAgB,2BAA2B,IAAI,SAAS,UAAU,EAAE,CAEnE;AAED,wBAAgB,gCAAgC,IAAI,SAAS,UAAU,EAAE,CAExE;AAED,gFAAgF;AAChF,eAAO,MAAM,qBAAqB,EAAE,SAAS,MAAM,EAKlD,CAAC;AAEF;;;kCAGkC;AAClC,wBAAgB,mBAAmB,IAAI,MAAM,CAQ5C"}
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ /**
3
+ * CE-9 (spec R5) — the raw-lane provider × knob support matrix, the SINGLE
4
+ * source of truth for which knobs each provider honors on `rig.runRaw`.
5
+ *
6
+ * BOTH the runtime guard (`assertRawKnobsSupported`, run/raw.ts) and the docs
7
+ * generator (scripts/build-docs-site.ts) import `RAW_KNOB_SUPPORT` — so the
8
+ * fail-closed behavior a customer hits at runtime and the published matrix they
9
+ * read beforehand can never disagree. The guard's provider sets are no longer
10
+ * inline literals; adding a provider (or widening a knob) is one edit here.
11
+ *
12
+ * The knob discipline this table encodes (spec R1/R2/R4):
13
+ * - grounding: gemini honors native web grounding (grok's Live Search was retired by
14
+ * xAI — 410 on the CE-9 live gate — so grok is fail-closed until CE-9b lands the
15
+ * Responses-API web_search path); every other provider
16
+ * FAILS CLOSED pre-dispatch (guarded).
17
+ * - reasoning: NO per-model allowlist outside gemini (the drift cost the
18
+ * customer flagged). openai/deepinfra/fireworks forward `level` verbatim as
19
+ * `reasoning_effort` and let the provider enforce (a rejection is classified
20
+ * teachably in each adapter); grok forwards a DISCLOSED coarsening
21
+ * (`coarsenGrokReasoningEffort`); gemini stays model-gated (the adapter
22
+ * rejects a non-thinking model); deepseek + anthropic FAIL CLOSED at the
23
+ * guard with a provider-specific fixHint.
24
+ * - responseFormat ("json_object"): the OpenAI-dialect providers + gemini
25
+ * (mime-shaping only) honor it; anthropic FAILS CLOSED (guarded). This is
26
+ * mime-shaping, NOT schema enforcement — F4 stands (no validation/repair,
27
+ * `meta.validated` stays false).
28
+ * - cache + serviceTier are INFORMATIONAL here (never a hard fail): the cache
29
+ * directive is provider-neutral (a resource HANDLE on gemini, a routing HINT
30
+ * on the prompt_cache_key providers) and serviceTier forwards everywhere.
31
+ */
32
+ Object.defineProperty(exports, "__esModule", { value: true });
33
+ exports.RAW_KNOB_MATRIX_NOTES = exports.RAW_KNOB_SUPPORT = void 0;
34
+ exports.coarsenGrokReasoningEffort = coarsenGrokReasoningEffort;
35
+ exports.rawKnobSupport = rawKnobSupport;
36
+ exports.groundingSupportedProviders = groundingSupportedProviders;
37
+ exports.responseFormatSupportedProviders = responseFormatSupportedProviders;
38
+ exports.renderRawKnobMatrix = renderRawKnobMatrix;
39
+ const provider_1 = require("../types/provider");
40
+ /**
41
+ * The grok reasoning coarsening (R1): xAI's `reasoning_effort` accepts only
42
+ * `"low" | "high"`, so the four-level neutral vocabulary is coarsened —
43
+ * `minimal, low → "low"`; `medium, high → "high"`. This is a DISCLOSED, lossy
44
+ * mapping (it appears in the matrix note, the grok field's doc comment, and the
45
+ * `grok.test.ts` test), never a silent semantic drop. Kept here — beside the
46
+ * matrix that documents it — as the ONE place the algorithm lives (grok.ts
47
+ * imports it).
48
+ */
49
+ function coarsenGrokReasoningEffort(level) {
50
+ return level === "minimal" || level === "low" ? "low" : "high";
51
+ }
52
+ /** The matrix. Exhaustive over ProviderId — a new provider forces a compile
53
+ * error here (Record<ProviderId, …>), so it can never be silently unlisted. */
54
+ exports.RAW_KNOB_SUPPORT = {
55
+ gemini: {
56
+ grounding: { supported: true, note: "native — Google Search (`googleSearch` tool)" },
57
+ reasoning: { kind: "model-gated", note: "`level` → `thinkingConfig.thinkingLevel`, thinking-capable models only (see `GEMINI_THINKING_CAPABLE_MODELS`)" },
58
+ responseFormat: { supported: true, note: "`responseMimeType: application/json` (mime-shaping only — no schema, `validated` stays false)" },
59
+ cache: { semantics: "handle", note: "`cache.key` = a `cachedContent` resource handle (customer-owned lifecycle)" },
60
+ serviceTier: { supported: true, note: "`flex` / `standard` / `priority` honored" },
61
+ },
62
+ openai: {
63
+ grounding: { supported: false, note: "fail-closed" },
64
+ reasoning: { kind: "forward", note: "`level` → `reasoning_effort` (1:1); a non-reasoning model's rejection is classified teachably" },
65
+ responseFormat: { supported: true, note: "`response_format: { type: json_object }`" },
66
+ cache: { semantics: "hint", note: "`cache.key` → `prompt_cache_key`; `ttlSeconds ≥ 86400` → `prompt_cache_retention: 24h`" },
67
+ serviceTier: { supported: true, note: "`flex` (allowlist) / `priority`; flex→standard is a customer-side degrade (§3.2)" },
68
+ },
69
+ grok: {
70
+ grounding: { supported: false, note: "fail-closed — xAI retired Live Search (HTTP 410, 2026-08-21); native `web_search` needs the Responses API, tracked as CE-9b" },
71
+ reasoning: { kind: "coarsen", note: 'coarsened (disclosed): `minimal,low → "low"`; `medium,high → "high"` → `reasoning_effort`' },
72
+ responseFormat: { supported: true, note: "`response_format: { type: json_object }`" },
73
+ cache: { semantics: "hint", note: "`cache.key` → `prompt_cache_key` (routing hint)" },
74
+ serviceTier: { supported: false, note: "no tiers — always `standard`" },
75
+ },
76
+ deepseek: {
77
+ grounding: { supported: false, note: "fail-closed" },
78
+ reasoning: {
79
+ kind: "fail-closed",
80
+ note: "no effort control — reasoning is model selection (`deepseek-reasoner`)",
81
+ fixHint: "DeepSeek has no reasoning-effort control — select the deepseek-reasoner model instead and remove reasoning",
82
+ },
83
+ responseFormat: { supported: true, note: "`response_format: { type: json_object }` — the prompt must contain the word \"JSON\" (caller's responsibility on the raw lane)" },
84
+ cache: { semantics: "implicit", note: "automatic prefix cache — the key is not used" },
85
+ serviceTier: { supported: false, note: "no tiers — always `standard`" },
86
+ },
87
+ anthropic: {
88
+ grounding: { supported: false, note: "fail-closed" },
89
+ reasoning: {
90
+ kind: "fail-closed",
91
+ note: "extended thinking is not wired on the raw lane (future work)",
92
+ fixHint: "Anthropic extended thinking is not wired on the raw lane in v1 — remove reasoning",
93
+ },
94
+ responseFormat: {
95
+ supported: false,
96
+ note: "fail-closed — no json_object equivalent (structured output is a forced tool call)",
97
+ },
98
+ cache: { semantics: "marker", note: "prefix caching via `cache_control` markers — the key is not used" },
99
+ serviceTier: { supported: false, note: "no tiers — always `standard`" },
100
+ },
101
+ deepinfra: {
102
+ grounding: { supported: false, note: "fail-closed" },
103
+ reasoning: { kind: "forward", note: "`level` → `reasoning_effort` (1:1); a non-reasoning model's rejection is classified teachably" },
104
+ responseFormat: { supported: true, note: "`response_format: { type: json_object }`" },
105
+ cache: { semantics: "hint", note: "`cache.key` → `prompt_cache_key` (routing hint)" },
106
+ serviceTier: { supported: false, note: "no tiers — always `standard`" },
107
+ },
108
+ fireworks: {
109
+ grounding: { supported: false, note: "fail-closed" },
110
+ reasoning: { kind: "forward", note: "`level` → `reasoning_effort` (1:1); a non-reasoning model's rejection is classified teachably" },
111
+ responseFormat: { supported: true, note: "`response_format: { type: json_object }`" },
112
+ cache: { semantics: "hint", note: "`cache.key` → `prompt_cache_key` (routing hint; caching is automatic host-side)" },
113
+ serviceTier: { supported: false, note: "no tiers — always `standard`" },
114
+ },
115
+ };
116
+ /** Pure lookup into the matrix (spec R6, exported from the package root). A
117
+ * customer's multi-provider dispatcher ASKS this instead of duplicating the
118
+ * provider lists. */
119
+ function rawKnobSupport(provider) {
120
+ return exports.RAW_KNOB_SUPPORT[provider];
121
+ }
122
+ /** Providers that honor a knob, in PROVIDER_IDS order — used by the guard to
123
+ * build a "supported on X, Y only" fixHint from the matrix (so the error text
124
+ * can never drift from the table). */
125
+ function groundingSupportedProviders() {
126
+ return provider_1.PROVIDER_IDS.filter((p) => exports.RAW_KNOB_SUPPORT[p].grounding.supported);
127
+ }
128
+ function responseFormatSupportedProviders() {
129
+ return provider_1.PROVIDER_IDS.filter((p) => exports.RAW_KNOB_SUPPORT[p].responseFormat.supported);
130
+ }
131
+ /** Matrix-level notes rendered below the table (spec §3.2 restated in docs). */
132
+ exports.RAW_KNOB_MATRIX_NOTES = [
133
+ "**Fail-closed is discoverable, not a surprise.** A knob a provider cannot honor throws `RigFailureError` `invariant_violation` PRE-DISPATCH (no meter, no provider call, no telemetry row) — read this table before you call, not after.",
134
+ "**reasoning has NO per-model allowlist outside gemini.** openai/deepinfra/fireworks forward `level` verbatim and let the provider enforce; a rejection surfaces as a classified failure that names the fix. grok coarsens (disclosed above). deepseek reasoning is model selection (`deepseek-reasoner`); anthropic extended thinking is unwired.",
135
+ "**responseFormat is mime-shaping, not schema enforcement.** `json_object` forces syntactic JSON only — the raw lane still never validates or repairs, and `meta.validated` stays `false` (F4).",
136
+ "**§3.2 flex degrade is customer-side.** ModelRig does not replicate the gemini direct-path infra-retry wrapper on the raw lane; under `flex` a capacity rejection surfaces classified (`capacity_shed`) for your own `→ standard` retry ladder — a NAMED difference for your migration record, not a silent one.",
137
+ ];
138
+ /** Render the provider × knob matrix as a Markdown table + notes, FROM the
139
+ * matrix (never a hand-written table — R5). Consumed by the docs generator
140
+ * (scripts/build-docs-site.ts) so the published matrix and the runtime guard
141
+ * derive from the same source. */
142
+ function renderRawKnobMatrix() {
143
+ const header = "| Provider | grounding | reasoning | responseFormat | cache | serviceTier |";
144
+ const sep = "|---|---|---|---|---|---|";
145
+ const rows = provider_1.PROVIDER_IDS.map((p) => {
146
+ const s = exports.RAW_KNOB_SUPPORT[p];
147
+ return `| \`${p}\` | ${s.grounding.note} | ${s.reasoning.note} | ${s.responseFormat.note} | ${s.cache.note} | ${s.serviceTier.note} |`;
148
+ });
149
+ return [header, sep, ...rows, "", ...exports.RAW_KNOB_MATRIX_NOTES].join("\n");
150
+ }
package/dist/run/raw.d.ts CHANGED
@@ -28,11 +28,20 @@
28
28
  * Each is ADDITIVE: absent ⇒ byte-identical dispatch. A DECLARED directive is
29
29
  * never silently dropped — `grounding`/`reasoning` on a provider that cannot
30
30
  * honor it are rejected fail-closed PRE-DISPATCH (`assertRawKnobsSupported`),
31
- * with no meter, no provider call, and no telemetry row. v1 support set for
32
- * both = { gemini }. `serviceTier` forwards to every adapter's tier path and
33
- * `meta.requestedTier` now reports the DECLARED tier (an honesty fix — it
34
- * previously hardcoded `"standard"`).
31
+ * with no meter, no provider call, and no telemetry row. `serviceTier`
32
+ * forwards to every adapter's tier path and `meta.requestedTier` now reports
33
+ * the DECLARED tier (an honesty fix — it previously hardcoded `"standard"`).
34
+ * - CE-9: multi-provider parity. `grounding` now also serves grok (xAI Live
35
+ * Search); `reasoning` generalizes beyond gemini WITHOUT a per-model
36
+ * allowlist — openai/deepinfra/fireworks forward `level` → `reasoning_effort`
37
+ * verbatim (provider enforces, rejection classified teachably), grok coarsens
38
+ * (disclosed), gemini stays model-gated, deepseek/anthropic fail closed; a
39
+ * new `responseFormat: "json_object"` knob mime-shapes on the OpenAI-dialect
40
+ * providers + gemini (anthropic fails closed). The provider×knob support set
41
+ * is ONE table (`run/raw-support.ts`) the guard AND the published docs matrix
42
+ * both read — they can never disagree (R5).
35
43
  */
44
+ import { type RigManifest } from "../routes/manifest";
36
45
  import type { AdapterRequest, CandidateRef, ProviderId, ReasoningParams, ServiceTier, ToolChoice, ToolDefinition } from "../types/provider";
37
46
  import type { RunResult, RunTags } from "../types/route";
38
47
  import type { RunStreamHandle } from "./stream";
@@ -50,6 +59,13 @@ export interface RawRunInput {
50
59
  readonly systemPrompt: string;
51
60
  readonly userPrompt: string;
52
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;
53
69
  readonly maxOutputTokens?: number;
54
70
  /** CE-6 sampling on the raw lane (spec §2). `temperature`/`topP` are the raw
55
71
  * lane's exposure of the same knobs `RoutePolicy.sampling` gives the routed
@@ -95,6 +111,16 @@ export interface RawRunInput {
95
111
  * pre-dispatch (`assertRawKnobsSupported`); declared on a non-thinking gemini
96
112
  * model is rejected classified by the adapter (`geminiReasoningUnsupported`). */
97
113
  readonly reasoning?: ReasoningParams;
114
+ /** CE-9 R4 — syntactic-JSON response shaping on the raw lane. `"json_object"`
115
+ * maps to each provider's json_object / json-mime directive (OpenAI-dialect
116
+ * providers + gemini); ABSENT ⇒ byte-identical (no key added). This is
117
+ * MIME-SHAPING, NOT schema enforcement — F4 stands: no validation, no repair,
118
+ * `meta.validated` stays false. GUARDED: anthropic has no equivalent and is
119
+ * rejected fail-closed pre-dispatch (`assertRawKnobsSupported`). DeepSeek's
120
+ * documented wrinkle — its json_object mode 400s when the literal word "JSON"
121
+ * appears nowhere in the prompt — is the CALLER's prompt responsibility on the
122
+ * raw lane (documented in the R5 matrix, never injected here). */
123
+ readonly responseFormat?: "json_object";
98
124
  }
99
125
  export interface RawRunDeps {
100
126
  readonly telemetry: TelemetryStore;
@@ -102,15 +128,31 @@ export interface RawRunDeps {
102
128
  * Used only to keep `attemptCost` honest — the raw lane has no envelope, so
103
129
  * it never charges the unpriced fallback; a missing price records `$0`. */
104
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;
105
135
  }
106
136
  /**
107
- * CE-2 fail-closed guard (spec §3 F1/F3). A DECLARED directive is NEVER silently
108
- * dropped: `grounding`/`reasoning` on a provider that cannot honor it — or a
109
- * `grounding.mode` other than the v1-supported `"native"` — throws
110
- * `RigFailureError` `invariant_violation` (the existing TERMINAL class; no new
111
- * FailureClass member, spec §3 rationale) BEFORE any adapter is built, any
112
- * provider call is made, or any telemetry row is written. Exported so the guard
113
- * is unit-testable without a network. Idempotent and side-effect-free.
137
+ * CE-2/CE-9 fail-closed guard (spec §3 F1/F3, CE-9 R1/R2/R4). A DECLARED
138
+ * directive is NEVER silently dropped: a `grounding`/`responseFormat` on a
139
+ * provider that cannot honor it, a `reasoning` on a provider with NO effort
140
+ * control (deepseek/anthropic), or a `grounding.mode` other than the
141
+ * v1-supported `"native"` throws `RigFailureError` `invariant_violation` (the
142
+ * existing TERMINAL class; no new FailureClass member) BEFORE any adapter is
143
+ * built, any provider call is made, or any telemetry row is written.
144
+ *
145
+ * The support facts come from `RAW_KNOB_SUPPORT` (run/raw-support.ts) — the ONE
146
+ * table the published docs matrix also reads, so the guard and the docs can
147
+ * never disagree (R5). What the guard does NOT reject (and why):
148
+ * - reasoning on openai/deepinfra/fireworks is FORWARDED verbatim
149
+ * (`kind: "forward"`) and the provider enforces — a rejection is classified
150
+ * teachably by the adapter (no per-model allowlist, R1).
151
+ * - reasoning on grok is a DISCLOSED coarsening (`kind: "coarsen"`).
152
+ * - reasoning on gemini is model-gated (`kind: "model-gated"`) — the adapter
153
+ * rejects a non-thinking model (`geminiReasoningUnsupported`).
154
+ * Exported so the guard is unit-testable without a network. Idempotent and
155
+ * side-effect-free.
114
156
  */
115
157
  export declare function assertRawKnobsSupported(input: RawRunInput): void;
116
158
  /** Pure raw-lane request shaping — exported for unit tests (no network). */
@@ -1 +1 @@
1
- {"version":3,"file":"raw.d.ts","sourceRoot":"","sources":["../../src/run/raw.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAYH,OAAO,KAAK,EACV,cAAc,EAGd,YAAY,EAGZ,UAAU,EACV,eAAe,EACf,WAAW,EACX,UAAU,EACV,cAAc,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