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,112 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runAuthPreflight = runAuthPreflight;
4
+ exports.whoamiPreflight = whoamiPreflight;
5
+ exports.resolvedOrgSlug = resolvedOrgSlug;
6
+ exports.expectedOrgMismatch = expectedOrgMismatch;
7
+ /**
8
+ * Auth preflight — one legible line where there used to be silent 401 drops.
9
+ *
10
+ * Telemetry export is fire-and-forget by design: a rejected batch only logs a
11
+ * warning, never fails the pipeline. That is correct, but it means a WRONG key
12
+ * (revoked, or belonging to a different org than the console you watch) drops
13
+ * every run silently — the failure mode that cost InferWealth days of invisible
14
+ * telemetry. This module turns that into one line, by asking `GET /v1/whoami`
15
+ * (server-side companion) which org the key actually resolves to.
16
+ *
17
+ * `runAuthPreflight` is the pure worker: given the resolved config (config.ts is
18
+ * the only env reader) it returns a legible result and NEVER throws. `modelrig
19
+ * doctor` (doctor-cli.ts) calls it and prints the line — ✓ on success, a loud
20
+ * line on a rejected key.
21
+ *
22
+ * `--expect-org <slug>` (doctor) and `createRig({ expectOrg })` (the sink's
23
+ * first-flush line) compare the resolved slug with `expectedOrgMismatch` below.
24
+ *
25
+ * NOTE: there is no automatic boot-time preflight. The automatic safety net lives
26
+ * on the export path itself — the api sink emits a loud once-per-failure-streak
27
+ * "AUTH FAILED" warning when an ingest POST is rejected (telemetry/sinks.ts) — so
28
+ * a customer needs no extra env var: the one key they set is enough.
29
+ */
30
+ const api_key_format_1 = require("./tenancy/api-key-format");
31
+ /**
32
+ * Ask the configured api-mode sink who the key is. Returns null when there is
33
+ * nothing to check (no export, or a direct/local sink — whoami is an api-mode
34
+ * concept). Never throws: a network error is a `PreflightResult`, not an
35
+ * exception, so no caller can be broken by turning this on.
36
+ */
37
+ async function runAuthPreflight(config, fetchFn = fetch) {
38
+ const exp = config.export;
39
+ if (exp === undefined || exp.mode !== "api")
40
+ return null;
41
+ return whoamiPreflight(exp.ingestUrl, exp.apiKey, fetchFn);
42
+ }
43
+ /**
44
+ * The shared whoami worker: `runAuthPreflight` (doctor) and the api sink's
45
+ * first-flush org line (telemetry/org-identity.ts) both call it, so the two
46
+ * surfaces can never disagree about what a key resolves to. Never throws.
47
+ */
48
+ async function whoamiPreflight(ingestUrl, apiKey, fetchFn = fetch,
49
+ /** Abort the request (e.g. `AbortSignal.timeout(ms)`) — the sink passes one so
50
+ * a hanging whoami can never hold the process open. An abort is a network_error. */
51
+ signal) {
52
+ const base = new URL(ingestUrl).origin;
53
+ const redacted = (0, api_key_format_1.redactApiKey)(apiKey);
54
+ try {
55
+ const res = await fetchFn(`${base}/v1/whoami`, {
56
+ headers: { authorization: `Bearer ${apiKey}` },
57
+ ...(signal !== undefined ? { signal } : {}),
58
+ });
59
+ if (res.status === 401 || res.status === 403) {
60
+ return {
61
+ ok: false,
62
+ status: res.status,
63
+ line: `[modelrig] AUTH FAILED (${res.status}) at ${base} — key ${redacted} is not recognized ` +
64
+ "by this server/org. Check MODELRIG_API_KEY, and that the key belongs to the org you " +
65
+ "expect (mint it in that org at app.modelrig.ai). Telemetry is dropping silently until this is fixed.",
66
+ };
67
+ }
68
+ if (!res.ok) {
69
+ return {
70
+ ok: false,
71
+ status: res.status,
72
+ line: `[modelrig] whoami ${res.status} at ${base} — could not confirm the key's org (retry \`modelrig doctor\`).`,
73
+ };
74
+ }
75
+ const who = (await res.json().catch(() => null));
76
+ const org = who?.org ?? null;
77
+ const orgLabel = org !== null && org !== undefined ? `«${org.name ?? org.id ?? "?"}»` : "(unknown org)";
78
+ const posture = who?.posture?.telemetry;
79
+ const postureLabel = typeof posture === "string" ? `, telemetry: ${posture}` : "";
80
+ return {
81
+ ok: true,
82
+ status: res.status,
83
+ line: `[modelrig] key ${redacted} → org ${orgLabel} ✓ (ingest ${base}${postureLabel})`,
84
+ ...(who !== null ? { whoami: who } : {}),
85
+ };
86
+ }
87
+ catch (err) {
88
+ return {
89
+ ok: false,
90
+ status: "network_error",
91
+ line: `[modelrig] whoami unreachable at ${base} (${err instanceof Error ? err.message : String(err)}) — ` +
92
+ "export is fire-and-forget, so this only means the preflight could not confirm your key.",
93
+ };
94
+ }
95
+ }
96
+ /** The org slug a successful preflight resolved, or null when unknown. */
97
+ function resolvedOrgSlug(result) {
98
+ const slug = result.whoami?.org?.slug;
99
+ return typeof slug === "string" && slug !== "" ? slug : null;
100
+ }
101
+ /**
102
+ * Compare a resolved org with the slug the caller expects (`--expect-org`,
103
+ * `createRig({ expectOrg })`). Returns null when they match, or the resolved
104
+ * slug (`"(unknown org)"` when the server did not name one) when they do not.
105
+ * Comparison is exact on the slug, case-insensitive — slugs are lowercase.
106
+ */
107
+ function expectedOrgMismatch(result, expectOrg) {
108
+ const actual = resolvedOrgSlug(result);
109
+ if (actual !== null && actual.toLowerCase() === expectOrg.trim().toLowerCase())
110
+ return null;
111
+ return actual ?? "(unknown org)";
112
+ }
@@ -11,7 +11,7 @@
11
11
  * (`rig.feedback` / `artifact.evaluate` / `run.evaluate`) and their adapters were
12
12
  * removed in GP-3 — every judgment now builds a grade directly.
13
13
  */
14
- import type { GradeRow, GradeSubject } from "../types/telemetry";
14
+ import type { GradeCriterion, GradeRow, GradeSubject } from "../types/telemetry";
15
15
  /** Options for `rig.grade(subject, opts)`. `score` is the 0–1 primitive and is
16
16
  * required; everything else is optional display / provenance. */
17
17
  export interface GradeOpts {
@@ -31,6 +31,13 @@ export interface GradeOpts {
31
31
  readonly grader?: string;
32
32
  /** Provenance (e.g. "sdk", "console", a review-agent name). */
33
33
  readonly source?: string;
34
+ /** OPTIONAL per-criterion breakdown (call-qa F4). When present on a human
35
+ * grade it rides the wire to the server, which persists it to `grade_criteria`
36
+ * (kind=human) so per-criterion agreement can pair the human vs model
37
+ * scorecards. Absent ⇒ today's single-score grade, unchanged. The server owns
38
+ * the scrub + dedup/drop-empty-id/clamp guard at persist; this is carried
39
+ * verbatim. */
40
+ readonly criteria?: readonly GradeCriterion[];
34
41
  /** The grade's own org — server-supplied ONLY, already authorized (T3). Omit
35
42
  * from application code (a rig has one org and the exporter knows it). */
36
43
  readonly orgId?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"grade.d.ts","sourceRoot":"","sources":["../../src/feedback/grade.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEjE;iEACiE;AACjE,MAAM,WAAW,SAAS;IACxB,mFAAmF;IACnF,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB;6EACyE;IACzE,QAAQ,CAAC,KAAK,CAAC,EAAE;QA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,CAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACvE,kFAAkF;IAClF,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,aAAa,GAAG,eAAe,CAAC;IACzD,0EAA0E;IAC1E,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,+DAA+D;IAC/D,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB;;;;;mBAKe;IACf,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,cAAc,EAAE,CAAC;IAC9C;8EAC0E;IAC1E,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,4EAA4E;IAC5E,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACpC;AAQD;oFACoF;AACpF,wBAAgB,aAAa,CAAC,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,GAAG,QAAQ,CA2B9E;AAED;;+DAE+D;AAC/D,wBAAgB,YAAY,CAAC,KAAK,EAAE;IAAE,WAAW,CAAC,GAAG,EAAE,QAAQ,GAAG,IAAI,CAAA;CAAE,GAAG;IACzE,KAAK,CAAC,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,GAAG,QAAQ,CAAC;CACzD,CAQA"}
@@ -47,6 +47,10 @@ function buildGradeRow(subject, opts) {
47
47
  orgId: opts.orgId !== undefined && opts.orgId !== "" ? opts.orgId : null,
48
48
  createdBy: opts.createdBy ?? null,
49
49
  ts: new Date().toISOString(),
50
+ // F4: carry the per-criterion breakdown verbatim iff present (spread-iff so
51
+ // a single-score grade's row is byte-identical to pre-F4). Structural
52
+ // normalization (dedup/clamp/scrub) is the server's job at persist.
53
+ ...(opts.criteria !== undefined ? { criteria: opts.criteria } : {}),
50
54
  };
51
55
  }
52
56
  /** Build the rig's `grade` surface over a grade writer (the telemetry store).
@@ -114,6 +114,25 @@ export interface ChatCompletionRequest {
114
114
  readonly envelope?: string;
115
115
  readonly variant?: string;
116
116
  readonly stream?: "buffered";
117
+ /**
118
+ * K1b (managed-serving-keyless) — the FAITHFUL carrier for a TEMPLATED /
119
+ * NON-CHAT route's named template variables. A provider-neutral JSON object
120
+ * of the route's `{{variable}}` bindings, DISTINCT from OpenAI `messages`:
121
+ * `messages` is the chat-relay bridge (the server derives `message`/`messages`
122
+ * from it), whereas `input` carries the route's OWN declared variables
123
+ * verbatim (e.g. a report route's structured `{ topic, holdings, … }`), so the
124
+ * server renders the route template exactly as a local `rig.run` would — no
125
+ * lossy messages round-trip.
126
+ *
127
+ * PRECEDENCE (server bind): when present, `modelrig.input` WINS — the run's
128
+ * `input` is these named variables; the chat `messages` binding is the
129
+ * fallback used only when it is absent. The server validates the object shape
130
+ * fail-closed (a non-object, or a prototype-polluting key, is a teaching 422)
131
+ * — a request that cannot be faithfully served is refused, never served with
132
+ * a silently-wrong prompt. ADDITIVE: a chat request that omits it is
133
+ * byte-identical to the K1 wire.
134
+ */
135
+ readonly input?: Readonly<Record<string, unknown>>;
117
136
  };
118
137
  }
119
138
  export interface ChatCompletionUsage {
@@ -1 +1 @@
1
- {"version":3,"file":"http-protocol.d.ts","sourceRoot":"","sources":["../../src/gateway/http-protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAE9E,uCAAuC;AACvC,eAAO,MAAM,qBAAqB,yBAAyB,CAAC;AAC5D,2EAA2E;AAC3E,eAAO,MAAM,WAAW,eAAe,CAAC;AAExC,6DAA6D;AAC7D,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAO1C,eAAO,MAAM,gBAAgB;IAC3B,0EAA0E;;IAE1E;;;;eAIW;;;;IAIX,yEAAyE;;IAEzE,oEAAoE;;;IAGpE,mEAAmE;;CAE3D,CAAC;AAGX,e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+ *
4
+ * This is the client half of `destination: modelrig-served`: instead of the
5
+ * local adapter dispatch, a served run is POSTed to the HOSTED gateway's
6
+ * `POST /v1/chat/completions` (the org's mirrored bundle, resolved BY SLUG and
7
+ * driven server-side through `runBundle` — see modelrig-server
8
+ * `handleMirroredSlugLane`). The gateway spends ModelRig's OWN managed provider
9
+ * key; the SDK sends ONLY its `rig_sk_` control-plane key (Bearer), NEVER a
10
+ * provider key.
11
+ *
12
+ * ONE wire contract: everything here is expressed in the SHARED
13
+ * `gateway/http-protocol.ts` shapes (`CHAT_COMPLETIONS_PATH`,
14
+ * `ChatCompletionRequest`, `ChatCompletionResponse`, `MODELRIG_HEADERS`,
15
+ * `MODELRIG_REQUEST_HEADERS`) — the same module `modelrig-server` compiles
16
+ * against, so the request this produces is exactly the one the endpoint
17
+ * consumes and the response it parses is exactly the one the endpoint emits.
18
+ *
19
+ * FAIL-CLOSED-BUT-DISCOVERABLE (spec §3 K1, ruling R3): a transport error, a
20
+ * non-2xx, a 402 (no prepaid balance), or a 403 (no serve entitlement) throws a
21
+ * TEACHING `RigFailureError` (class `invariant_violation`, TERMINAL) whose
22
+ * `fixHint` names the cause and the fix — NEVER a silent fall back to `direct`
23
+ * or a local key. `fetch` is injected (`fetchFn`) so tests mock the transport
24
+ * with no live network and no real key.
25
+ *
26
+ * TRANSPORT + MAPPING ONLY. The flag/capability gate + the run.ts branch point
27
+ * live in `run/resolve-destination.ts` / `run/run.ts`; this module is reached
28
+ * only AFTER the guard has passed.
29
+ */
30
+ import type { ChatMessage } from "./http-protocol";
31
+ import type { RouteBundle, RunOptions, RunResult } from "../types/route";
32
+ /** Injected transport — the global `fetch` in production, a mock in tests. */
33
+ export type ServeFetch = typeof fetch;
34
+ /**
35
+ * Where + how to reach the hosted gateway. Resolved (in `index.ts`) from the
36
+ * SAME `api`-mode export config the telemetry sink uses: `baseUrl` is the ingest
37
+ * host (`MODELRIG_INGEST_URL` ‖ `DEFAULT_INGEST_URL`) and `apiKey` is the
38
+ * `rig_sk_` key. ABSENT ⇒ no hosted control plane is configured ⇒ a served run
39
+ * fails closed (there is nowhere to serve it, and we never invent a key).
40
+ */
41
+ export interface ServeTransportConfig {
42
+ /** Ingest host base, e.g. `https://api.modelrig.ai` (no path). */
43
+ readonly baseUrl: string;
44
+ /** `rig_sk_…` control-plane key. The ONLY credential sent — never a provider key. */
45
+ readonly apiKey: string;
46
+ }
47
+ export interface ServeRunInput {
48
+ readonly route: RouteBundle;
49
+ readonly opts: RunOptions;
50
+ /** The resolved variant name (Phase 3 WS1) — served via `x-modelrig-variant`. */
51
+ readonly servedVariant: string | null;
52
+ /** Resolved transport; `undefined` ⇒ fail closed (no hosted control plane). */
53
+ readonly serve: ServeTransportConfig | undefined;
54
+ /** Injected fetch (tests); defaults to the global `fetch`. */
55
+ readonly fetchFn?: ServeFetch;
56
+ }
57
+ /**
58
+ * Is this run's `input` a CHAT-SHAPED input — the shape the OpenAI `messages`
59
+ * bridge carries faithfully (`input.messages` a transcript, or `input.message` a
60
+ * single user turn)? A route authored for the OpenAI-compatible surface declares
61
+ * exactly these variables (PROXY_RELAYED_VARS, server-side). Anything else is a
62
+ * NAMED-variable input carried by `modelrig.input` (K1b) instead.
63
+ */
64
+ export declare function isChatShapedInput(input: RunOptions["input"]): boolean;
65
+ /**
66
+ * Map the run's CHAT-shaped `input` into OpenAI `messages` — the chat-relay
67
+ * bridge (the server rebuilds `message`/`messages` from it). Faithful for a
68
+ * chat-shaped route:
69
+ * - `input.messages` (an array of `{role, content}`) → the transcript verbatim;
70
+ * - else `input.message` (a string) → a single user turn.
71
+ *
72
+ * K1b: a route that templates over OTHER named variables is NO LONGER fails-closed
73
+ * here — `serveViaGateway` carries those faithfully via `modelrig.input`
74
+ * (`buildServedNamedInput`). This function is reached only for a chat-shaped
75
+ * input, so the final fail-closed branch stays as a defensive teaching error for
76
+ * a caller who invokes it directly on a non-chat input.
77
+ */
78
+ export declare function buildServedMessages(route: RouteBundle, input: RunOptions["input"]): readonly ChatMessage[];
79
+ /**
80
+ * K1b — carry a NAMED-variable route's `input` faithfully as `modelrig.input`,
81
+ * INSTEAD of the K1 fail-closed. A templated/non-chat route (an InferWealth
82
+ * report route, say) declares structured variables (`{ topic, holdings, … }`),
83
+ * not `message`/`messages`; this is the provider-neutral object the server binds
84
+ * so the route template renders exactly as a local `rig.run` would.
85
+ *
86
+ * Still fail-closed-but-discoverable (K1's guarantee preserved): the only reason
87
+ * to refuse now is a genuinely UN-SERIALIZABLE input — one JSON cannot carry
88
+ * losslessly, which would degrade to a silently-wrong prompt server-side.
89
+ * `assertJsonFaithful` names the exact offending value; we wrap it as a teaching
90
+ * error, never a silent drop.
91
+ */
92
+ export declare function buildServedNamedInput(route: RouteBundle, input: RunOptions["input"]): Readonly<Record<string, unknown>>;
93
+ /**
94
+ * Serve a run through the hosted gateway and map the completion back into a
95
+ * normal `RunResult`. Reached only after `assertDestinationServable` has passed
96
+ * (flag on + served-capable provider). Fail-closed-but-discoverable throughout.
97
+ */
98
+ export declare function serveViaGateway(input: ServeRunInput): Promise<RunResult>;
99
+ //# sourceMappingURL=serve-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serve-client.d.ts","sourceRoot":"","sources":["../../src/gateway/serve-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAOH,OAAO,KAAK,EAGV,WAAW,EACZ,MAAM,iBAAiB,CAAC;AAIzB,OAAO,KAAK,EAAE,WAAW,EAAW,UAAU,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAElF,8EAA8E;AAC9E,MAAM,MAAM,UAAU,GAAG,OAAO,KAAK,CAAC;AAEtC;;;;;;GAMG;AACH,MAAM,WAAW,oBAAoB;IACnC,kEAAkE;IAClE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,qFAAqF;IACrF,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,aAAa;IAC5B,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