modelrig 0.11.0 → 0.12.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 (199) hide show
  1. package/CHANGELOG.md +82 -0
  2. package/dist/adapters/anthropic.d.ts +4 -4
  3. package/dist/adapters/anthropic.d.ts.map +1 -1
  4. package/dist/adapters/anthropic.js +8 -1
  5. package/dist/adapters/deepseek.d.ts +2 -4
  6. package/dist/adapters/deepseek.d.ts.map +1 -1
  7. package/dist/adapters/deepseek.js +9 -5
  8. package/dist/adapters/gemini.d.ts +4 -1
  9. package/dist/adapters/gemini.d.ts.map +1 -1
  10. package/dist/adapters/gemini.js +16 -1
  11. package/dist/adapters/grok.d.ts +2 -4
  12. package/dist/adapters/grok.d.ts.map +1 -1
  13. package/dist/adapters/grok.js +8 -4
  14. package/dist/adapters/history-mapping.d.ts +126 -0
  15. package/dist/adapters/history-mapping.d.ts.map +1 -0
  16. package/dist/adapters/history-mapping.js +230 -0
  17. package/dist/adapters/openai-compat.d.ts +2 -4
  18. package/dist/adapters/openai-compat.d.ts.map +1 -1
  19. package/dist/adapters/openai-compat.js +9 -5
  20. package/dist/adapters/openai.d.ts +2 -4
  21. package/dist/adapters/openai.d.ts.map +1 -1
  22. package/dist/adapters/openai.js +8 -4
  23. package/dist/adapters/responses-api.d.ts.map +1 -1
  24. package/dist/adapters/responses-api.js +9 -4
  25. package/dist/artifacts/artifact.d.ts.map +1 -1
  26. package/dist/artifacts/artifact.js +79 -0
  27. package/dist/artifacts/conversation.d.ts +128 -0
  28. package/dist/artifacts/conversation.d.ts.map +1 -0
  29. package/dist/artifacts/conversation.js +172 -0
  30. package/dist/artifacts/index.d.ts +1 -1
  31. package/dist/artifacts/index.d.ts.map +1 -1
  32. package/dist/artifacts/media.d.ts +46 -0
  33. package/dist/artifacts/media.d.ts.map +1 -0
  34. package/dist/artifacts/media.js +88 -0
  35. package/dist/artifacts/run-context.d.ts +61 -2
  36. package/dist/artifacts/run-context.d.ts.map +1 -1
  37. package/dist/artifacts/run-context.js +183 -12
  38. package/dist/artifacts/scrub.d.ts +3 -0
  39. package/dist/artifacts/scrub.d.ts.map +1 -1
  40. package/dist/bakeoff/engine.d.ts.map +1 -1
  41. package/dist/bakeoff/engine.js +34 -7
  42. package/dist/bakeoff/eval-cases.d.ts +5 -0
  43. package/dist/bakeoff/eval-cases.d.ts.map +1 -1
  44. package/dist/bakeoff/eval-cases.js +10 -1
  45. package/dist/bakeoff/replay.d.ts +15 -0
  46. package/dist/bakeoff/replay.d.ts.map +1 -1
  47. package/dist/bakeoff/replay.js +19 -1
  48. package/dist/bakeoff/report.d.ts.map +1 -1
  49. package/dist/bakeoff/report.js +9 -2
  50. package/dist/bakeoff/turn-replay.d.ts +93 -0
  51. package/dist/bakeoff/turn-replay.d.ts.map +1 -0
  52. package/dist/bakeoff/turn-replay.js +150 -0
  53. package/dist/bakeoff/types.d.ts +12 -0
  54. package/dist/bakeoff/types.d.ts.map +1 -1
  55. package/dist/cli.d.ts.map +1 -1
  56. package/dist/cli.js +1 -0
  57. package/dist/config.d.ts +18 -0
  58. package/dist/config.d.ts.map +1 -1
  59. package/dist/config.js +23 -3
  60. package/dist/doctor-preflight.d.ts.map +1 -1
  61. package/dist/doctor-preflight.js +6 -1
  62. package/dist/feedback/grade.d.ts +7 -2
  63. package/dist/feedback/grade.d.ts.map +1 -1
  64. package/dist/feedback/grade.js +14 -0
  65. package/dist/feedback/outcome.d.ts +103 -0
  66. package/dist/feedback/outcome.d.ts.map +1 -0
  67. package/dist/feedback/outcome.js +175 -0
  68. package/dist/gateway/history-bridge.d.ts +32 -0
  69. package/dist/gateway/history-bridge.d.ts.map +1 -0
  70. package/dist/gateway/history-bridge.js +64 -0
  71. package/dist/gateway/serve-client.d.ts.map +1 -1
  72. package/dist/gateway/serve-client.js +6 -0
  73. package/dist/index.d.ts +44 -1
  74. package/dist/index.d.ts.map +1 -1
  75. package/dist/index.js +110 -9
  76. package/dist/init/init-cli.d.ts.map +1 -1
  77. package/dist/init/init-cli.js +21 -4
  78. package/dist/init/observe-cli.js +1 -1
  79. package/dist/init/observe.d.ts +7 -1
  80. package/dist/init/observe.d.ts.map +1 -1
  81. package/dist/init/observe.js +74 -22
  82. package/dist/init/starter.d.ts +36 -0
  83. package/dist/init/starter.d.ts.map +1 -0
  84. package/dist/init/starter.js +85 -0
  85. package/dist/registry/build.d.ts +4 -0
  86. package/dist/registry/build.d.ts.map +1 -1
  87. package/dist/registry/generation-models.d.ts +68 -0
  88. package/dist/registry/generation-models.d.ts.map +1 -0
  89. package/dist/registry/generation-models.js +168 -0
  90. package/dist/registry/model-kind.d.ts +34 -0
  91. package/dist/registry/model-kind.d.ts.map +1 -0
  92. package/dist/registry/model-kind.js +40 -0
  93. package/dist/registry/pricing-shape.d.ts +29 -1
  94. package/dist/registry/pricing-shape.d.ts.map +1 -1
  95. package/dist/registry/pricing-shape.js +9 -0
  96. package/dist/registry/pricing.d.ts +26 -0
  97. package/dist/registry/pricing.d.ts.map +1 -1
  98. package/dist/registry/pricing.js +29 -0
  99. package/dist/registry/rows.d.ts.map +1 -1
  100. package/dist/registry/rows.js +3 -1
  101. package/dist/registry/unit-pricing.d.ts +32 -0
  102. package/dist/registry/unit-pricing.d.ts.map +1 -0
  103. package/dist/registry/unit-pricing.js +62 -0
  104. package/dist/routes/input-loader.d.ts +38 -0
  105. package/dist/routes/input-loader.d.ts.map +1 -0
  106. package/dist/routes/input-loader.js +80 -0
  107. package/dist/routes/loader.d.ts.map +1 -1
  108. package/dist/routes/loader.js +3 -0
  109. package/dist/routes/resolved-bundle.d.ts +2 -0
  110. package/dist/routes/resolved-bundle.d.ts.map +1 -1
  111. package/dist/routes/resolved-bundle.js +3 -0
  112. package/dist/run/cost.d.ts +28 -0
  113. package/dist/run/cost.d.ts.map +1 -1
  114. package/dist/run/cost.js +74 -0
  115. package/dist/run/dispatch.d.ts +4 -1
  116. package/dist/run/dispatch.d.ts.map +1 -1
  117. package/dist/run/dispatch.js +3 -0
  118. package/dist/run/limits.d.ts +88 -0
  119. package/dist/run/limits.d.ts.map +1 -0
  120. package/dist/run/limits.js +155 -0
  121. package/dist/run/messages.d.ts +199 -0
  122. package/dist/run/messages.d.ts.map +1 -0
  123. package/dist/run/messages.js +430 -0
  124. package/dist/run/raw-finalize.d.ts +5 -2
  125. package/dist/run/raw-finalize.d.ts.map +1 -1
  126. package/dist/run/raw-finalize.js +8 -5
  127. package/dist/run/raw-request.d.ts.map +1 -1
  128. package/dist/run/raw-request.js +2 -1
  129. package/dist/run/raw.d.ts +10 -4
  130. package/dist/run/raw.d.ts.map +1 -1
  131. package/dist/run/raw.js +11 -3
  132. package/dist/run/rawonly.d.ts +29 -5
  133. package/dist/run/rawonly.d.ts.map +1 -1
  134. package/dist/run/rawonly.js +54 -19
  135. package/dist/run/record-attempt.d.ts.map +1 -1
  136. package/dist/run/record-attempt.js +16 -6
  137. package/dist/run/record-call.d.ts +13 -2
  138. package/dist/run/record-call.d.ts.map +1 -1
  139. package/dist/run/record-call.js +50 -7
  140. package/dist/run/run.d.ts.map +1 -1
  141. package/dist/run/run.js +12 -8
  142. package/dist/telemetry/attempt-meta.d.ts +49 -1
  143. package/dist/telemetry/attempt-meta.d.ts.map +1 -1
  144. package/dist/telemetry/attempt-meta.js +45 -1
  145. package/dist/telemetry/exporter.d.ts.map +1 -1
  146. package/dist/telemetry/exporter.js +2 -1
  147. package/dist/telemetry/grade-mappers.d.ts +1 -1
  148. package/dist/telemetry/grade-mappers.d.ts.map +1 -1
  149. package/dist/telemetry/grade-mappers.js +7 -1
  150. package/dist/telemetry/grade-task.d.ts +49 -0
  151. package/dist/telemetry/grade-task.d.ts.map +1 -0
  152. package/dist/telemetry/grade-task.js +85 -0
  153. package/dist/telemetry/grades-sql.d.ts +16 -1
  154. package/dist/telemetry/grades-sql.d.ts.map +1 -1
  155. package/dist/telemetry/grades-sql.js +64 -4
  156. package/dist/telemetry/ingest-protocol.d.ts +24 -1
  157. package/dist/telemetry/ingest-protocol.d.ts.map +1 -1
  158. package/dist/telemetry/ingest-protocol.js +72 -43
  159. package/dist/telemetry/otel-content.d.ts +31 -0
  160. package/dist/telemetry/otel-content.d.ts.map +1 -0
  161. package/dist/telemetry/otel-content.js +106 -0
  162. package/dist/telemetry/otel-hierarchy.d.ts +57 -0
  163. package/dist/telemetry/otel-hierarchy.d.ts.map +1 -0
  164. package/dist/telemetry/otel-hierarchy.js +155 -0
  165. package/dist/telemetry/otel-normalize.d.ts +15 -1
  166. package/dist/telemetry/otel-normalize.d.ts.map +1 -1
  167. package/dist/telemetry/otel-normalize.js +24 -39
  168. package/dist/telemetry/sinks.d.ts +4 -1
  169. package/dist/telemetry/sinks.d.ts.map +1 -1
  170. package/dist/telemetry/sinks.js +53 -34
  171. package/dist/telemetry/store-migrations.d.ts.map +1 -1
  172. package/dist/telemetry/store-migrations.js +8 -0
  173. package/dist/telemetry/store.d.ts +9 -0
  174. package/dist/telemetry/store.d.ts.map +1 -1
  175. package/dist/telemetry/store.js +10 -0
  176. package/dist/telemetry/uniform-rows.d.ts +43 -0
  177. package/dist/telemetry/uniform-rows.d.ts.map +1 -0
  178. package/dist/telemetry/uniform-rows.js +139 -0
  179. package/dist/types/failures-teaching.d.ts.map +1 -1
  180. package/dist/types/failures-teaching.js +11 -0
  181. package/dist/types/failures.d.ts +1 -1
  182. package/dist/types/failures.d.ts.map +1 -1
  183. package/dist/types/failures.js +2 -0
  184. package/dist/types/provider.d.ts +12 -0
  185. package/dist/types/provider.d.ts.map +1 -1
  186. package/dist/types/route.d.ts +13 -0
  187. package/dist/types/route.d.ts.map +1 -1
  188. package/dist/types/telemetry.d.ts +14 -1
  189. package/dist/types/telemetry.d.ts.map +1 -1
  190. package/docs/agent-skill/SKILL.md +122 -12
  191. package/docs/how-it-fits.md +4 -4
  192. package/docs/instrumentation.md +148 -44
  193. package/docs/llms.txt +143 -13
  194. package/docs/mcp-oracle.md +15 -4
  195. package/docs/quickstart.md +129 -16
  196. package/package.json +4 -2
  197. package/registry/registry.json +456 -0
  198. package/templates/creative-approval.json +81 -0
  199. package/templates/support-conversation.json +82 -0
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ /**
3
+ * ARC-5 — run limits: an inline loop and budget guard, per run, in-process.
4
+ *
5
+ * run.start({ pipeline, limits: { maxUsd, maxCalls, maxWallMs, maxRepeatToolCall } })
6
+ * rig.conversation(id, { agent, limits })
7
+ *
8
+ * Every call inside an ambient run passes through the SDK, so the SDK can refuse
9
+ * the NEXT dispatch once a limit is reached — something an observability tool
10
+ * structurally cannot. On breach the dispatch throws a typed
11
+ * {@link RunLimitExceeded} (`failureClass: "limit_exceeded"`, terminal), the
12
+ * run's `RunMeta.failure_reason` becomes `limit:<which>`, and the run ends
13
+ * `failed`. A run that stopped at a limit keeps refusing on that async path.
14
+ *
15
+ * `recordCall` cannot prevent a call it did not dispatch: it ACCUMULATES (cost,
16
+ * call count) and the next `run`/`runRaw` throws. Distinct from envelopes (org /
17
+ * route money budgets, server-side, monthly): limits are per run and immediate.
18
+ *
19
+ * `maxRepeatToolCall: n` trips when the SAME tool name + argument hash is
20
+ * requested n times IN A ROW (a stuck agent loop). Only a SHA-256 of the
21
+ * canonical JSON arguments is kept — never the argument content.
22
+ *
23
+ * Everything here is PURE (state in, state out); run-context.ts holds the state.
24
+ */
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.RunLimitExceeded = void 0;
27
+ exports.initialLimitState = initialLimitState;
28
+ exports.toolCallSignature = toolCallSignature;
29
+ exports.accumulate = accumulate;
30
+ exports.checkRunLimits = checkRunLimits;
31
+ exports.limitFailureReason = limitFailureReason;
32
+ exports.validateRunLimits = validateRunLimits;
33
+ exports.limitsForMeta = limitsForMeta;
34
+ const node_crypto_1 = require("node:crypto");
35
+ const failures_1 = require("../types/failures");
36
+ const failures_teaching_1 = require("../types/failures-teaching");
37
+ function initialLimitState(startedAtMs) {
38
+ return { costUsd: 0, calls: 0, startedAtMs, lastToolSig: null, repeatCount: 0 };
39
+ }
40
+ /** Canonical JSON (sorted keys) so `{a:1,b:2}` and `{b:2,a:1}` hash alike. A
41
+ * non-JSON argument string hashes as the raw string. */
42
+ function canonical(value) {
43
+ if (Array.isArray(value))
44
+ return `[${value.map(canonical).join(",")}]`;
45
+ if (value !== null && typeof value === "object") {
46
+ const obj = value;
47
+ return `{${Object.keys(obj).sort().map((k) => `${JSON.stringify(k)}:${canonical(obj[k])}`).join(",")}}`;
48
+ }
49
+ return JSON.stringify(value) ?? "null";
50
+ }
51
+ /** `<name>:<sha256(canonical JSON args)>` — the ONLY form a tool call is kept in. */
52
+ function toolCallSignature(name, argsJson) {
53
+ let body;
54
+ try {
55
+ body = canonical(JSON.parse(argsJson));
56
+ }
57
+ catch {
58
+ body = argsJson;
59
+ }
60
+ return `${name}:${(0, node_crypto_1.createHash)("sha256").update(body, "utf8").digest("hex")}`;
61
+ }
62
+ /** Fold one recorded call into the state (pure). */
63
+ function accumulate(state, call) {
64
+ if (call.notDispatched === true)
65
+ return state;
66
+ let { lastToolSig, repeatCount } = state;
67
+ if (call.toolCalls !== undefined) {
68
+ if (call.toolCalls.length === 0) {
69
+ lastToolSig = null;
70
+ repeatCount = 0;
71
+ }
72
+ for (const tc of call.toolCalls) {
73
+ const sig = toolCallSignature(tc.name, tc.arguments);
74
+ if (sig === lastToolSig)
75
+ repeatCount += 1;
76
+ else {
77
+ lastToolSig = sig;
78
+ repeatCount = 1;
79
+ }
80
+ }
81
+ }
82
+ const cost = typeof call.costUsd === "number" && Number.isFinite(call.costUsd) && call.costUsd > 0 ? call.costUsd : 0;
83
+ return { ...state, costUsd: state.costUsd + cost, calls: state.calls + 1, lastToolSig, repeatCount };
84
+ }
85
+ /** PURE pre-dispatch check: the first limit already reached, or null. Order:
86
+ * money, calls, wall clock, repeat loop. */
87
+ function checkRunLimits(state, limits, nowMs) {
88
+ if (limits.maxUsd !== undefined && state.costUsd >= limits.maxUsd) {
89
+ return { which: "max_usd", limit: limits.maxUsd, observed: state.costUsd };
90
+ }
91
+ if (limits.maxCalls !== undefined && state.calls >= limits.maxCalls) {
92
+ return { which: "max_calls", limit: limits.maxCalls, observed: state.calls };
93
+ }
94
+ const elapsed = nowMs - state.startedAtMs;
95
+ if (limits.maxWallMs !== undefined && elapsed >= limits.maxWallMs) {
96
+ return { which: "max_wall_ms", limit: limits.maxWallMs, observed: elapsed };
97
+ }
98
+ if (limits.maxRepeatToolCall !== undefined && state.repeatCount >= limits.maxRepeatToolCall) {
99
+ return { which: "max_repeat_tool_call", limit: limits.maxRepeatToolCall, observed: state.repeatCount };
100
+ }
101
+ return null;
102
+ }
103
+ /** `limit:<which>` — the RunMeta.failure_reason a breach writes. */
104
+ function limitFailureReason(which) {
105
+ return `limit:${which}`;
106
+ }
107
+ /** Validate caller limits (a caller bug throws with the fix). Returns null for
108
+ * an empty / absent object — no limits, no state, byte-identical runs. */
109
+ function validateRunLimits(limits) {
110
+ if (limits === undefined)
111
+ return null;
112
+ const out = {};
113
+ const check = (key, integer) => {
114
+ const v = limits[key];
115
+ if (v === undefined)
116
+ return;
117
+ if (typeof v !== "number" || !Number.isFinite(v) || v <= 0 || (integer && !Number.isInteger(v))) {
118
+ throw new Error(`run limits: ${key} must be a positive ${integer ? "integer" : "number"}, got ${String(v)} — ` +
119
+ "omit the field to leave that limit off");
120
+ }
121
+ out[key] = v;
122
+ };
123
+ check("maxUsd", false);
124
+ check("maxCalls", true);
125
+ check("maxWallMs", false);
126
+ check("maxRepeatToolCall", true);
127
+ return Object.keys(out).length > 0 ? out : null;
128
+ }
129
+ /** The snake_case copy recorded on `RunMeta.limits` (metadata-safe numbers). */
130
+ function limitsForMeta(limits) {
131
+ return {
132
+ ...(limits.maxUsd !== undefined ? { max_usd: limits.maxUsd } : {}),
133
+ ...(limits.maxCalls !== undefined ? { max_calls: limits.maxCalls } : {}),
134
+ ...(limits.maxWallMs !== undefined ? { max_wall_ms: limits.maxWallMs } : {}),
135
+ ...(limits.maxRepeatToolCall !== undefined ? { max_repeat_tool_call: limits.maxRepeatToolCall } : {}),
136
+ };
137
+ }
138
+ /** The typed error a refused dispatch throws. A `RigFailureError` (class
139
+ * `limit_exceeded`, terminal) carrying which limit, its value and the observed one. */
140
+ class RunLimitExceeded extends failures_1.RigFailureError {
141
+ constructor(breach, runId) {
142
+ super({
143
+ class: "limit_exceeded",
144
+ message: `run ${runId} stopped at its ${breach.which} limit (limit ${breach.limit}, observed ` +
145
+ `${Number.isInteger(breach.observed) ? breach.observed : breach.observed.toFixed(6)}) — the next call was not dispatched`,
146
+ fixHint: failures_teaching_1.FAILURE_TEACHING.limit_exceeded.fixHint,
147
+ });
148
+ this.name = "RunLimitExceeded";
149
+ this.which = breach.which;
150
+ this.limit = breach.limit;
151
+ this.observed = breach.observed;
152
+ this.runId = runId;
153
+ }
154
+ }
155
+ exports.RunLimitExceeded = RunLimitExceeded;
@@ -0,0 +1,199 @@
1
+ /**
2
+ * The messages-native lane — ARC-β (agent-archetypes spec §4, builder-prompt-02
3
+ * §1.1). A provider-neutral conversation HISTORY that every adapter maps to its
4
+ * native shape (adapters/history-mapping.ts), so a chat turn or a tool loop can
5
+ * be routed, captured and replayed on a cheaper model.
6
+ *
7
+ * Design rules (binding):
8
+ * - NO `system` role in history. The system prompt stays
9
+ * `AdapterRequest.systemPrompt`, rendered by the route template exactly as
10
+ * today. A `system` message in caller input is rejected with a teaching error.
11
+ * - Tool calls reuse the existing normalized {@link ToolCall} (OpenAI
12
+ * `tool_calls` shape) — there is no second tool-call vocabulary.
13
+ * - `history` absent ⇒ every adapter takes today's code path, byte-identical
14
+ * (pinned by adapters/one-turn-parity.test.ts).
15
+ *
16
+ * NAMING NOTE: the spec calls the type `ChatMessage`, but `ChatMessage` is
17
+ * already a public export (the gateway's OpenAI wire message,
18
+ * gateway/http-protocol.ts). To keep that export stable the lane's type is
19
+ * exported as {@link HistoryMessage} (it is what `AdapterRequest.history` holds).
20
+ *
21
+ * Pure module: types, validation, canonicalization and the capture codec. No I/O.
22
+ */
23
+ import type { ToolCall, ToolChoice, ToolDefinition } from "../types/provider";
24
+ import type { RouteBundle, RunOptions } from "../types/route";
25
+ import type { CapabilityFlag } from "../types/provider";
26
+ import { RouteConfigError } from "../routes/loader";
27
+ /** A text part of a message's content. */
28
+ export interface HistoryTextPart {
29
+ readonly type: "text";
30
+ readonly text: string;
31
+ }
32
+ /** A content part. TEXT ONLY in ARC-β — image parts are UC-3 M1's job and join
33
+ * this union there (EXTENSION POINT: add `| HistoryImagePart` and teach each
34
+ * mapper in adapters/history-mapping.ts; validation below rejects any other
35
+ * `type` with a teaching problem until then). */
36
+ export type HistoryPart = HistoryTextPart;
37
+ export type HistoryContent = string | readonly HistoryPart[];
38
+ export interface HistoryUserMessage {
39
+ readonly role: "user";
40
+ readonly content: HistoryContent;
41
+ }
42
+ export interface HistoryAssistantMessage {
43
+ readonly role: "assistant";
44
+ readonly content: HistoryContent;
45
+ /** The tool calls this assistant turn emitted (exactly what `meta.toolCalls`
46
+ * returned on that turn). Only assistant messages carry them. */
47
+ readonly toolCalls?: readonly ToolCall[];
48
+ }
49
+ export interface HistoryToolMessage {
50
+ readonly role: "tool";
51
+ /** The `ToolCall.id` this message answers — must match a PRIOR assistant
52
+ * message's tool call. */
53
+ readonly toolCallId: string;
54
+ readonly content: string;
55
+ }
56
+ /** One turn of a conversation (spec's `ChatMessage`; see the naming note). */
57
+ export type HistoryMessage = HistoryUserMessage | HistoryAssistantMessage | HistoryToolMessage;
58
+ /** Where every messages-lane teaching message points. */
59
+ export declare const MESSAGES_DOCS_ANCHOR = "messages-lane.md";
60
+ /** A caller-contract breach in a `messages` input. Subclasses RouteConfigError
61
+ * so every surface that already maps config errors (the gateway's 422, the CLI)
62
+ * treats it the same way: thrown pre-dispatch, nothing billed, no telemetry. */
63
+ export declare class MessagesInputError extends RouteConfigError {
64
+ constructor(problems: readonly string[]);
65
+ }
66
+ /**
67
+ * Validate a caller-supplied history. Returns the list of teaching problems
68
+ * (empty ⇒ valid). Rules: a non-empty array; roles user | assistant | tool only
69
+ * (a `system` message is rejected, pointing at the route template /
70
+ * `systemPrompt`); `toolCalls` only on assistant messages; every tool message
71
+ * answers a PRIOR assistant tool call by id; the last message is `user` or
72
+ * `tool` (the model answers it).
73
+ */
74
+ export declare function historyProblems(messages: unknown): string[];
75
+ /** Throw a {@link MessagesInputError} when `messages` is not a valid history;
76
+ * otherwise return it typed. */
77
+ export declare function assertValidHistory(messages: unknown): readonly HistoryMessage[];
78
+ /** The text of a content value (parts concatenated in order, no separator —
79
+ * the same joining OpenAI applies to multi-part text content). */
80
+ export declare function contentText(content: HistoryContent): string;
81
+ /** Total characters across every message's text and tool-call arguments — the
82
+ * history's contribution to the envelope's pre-dispatch input estimate. */
83
+ export declare function historyChars(history: readonly HistoryMessage[] | undefined): number;
84
+ /**
85
+ * Canonical text of a history, for hashing and cache-prefix reasoning: one
86
+ * sorted-key JSON line per message. PREFIX-STABLE by construction —
87
+ * `canonicalize(h.slice(0, n))` is a string prefix of `canonicalize(h)` — so a
88
+ * conversation that grows by appending turns keeps every earlier turn's bytes
89
+ * (the property provider prefix caches key on).
90
+ */
91
+ export declare function canonicalize(history: readonly HistoryMessage[]): string;
92
+ /** The marker that tells a capture row's `variablesJson` holds a messages call. */
93
+ export declare const MESSAGES_CAPTURE_KIND = "modelrig.messages";
94
+ export interface MessagesCapture {
95
+ readonly kind: typeof MESSAGES_CAPTURE_KIND;
96
+ readonly v: 1;
97
+ /** The route's template variables (`RunOptions.input`). */
98
+ readonly variables: Record<string, unknown>;
99
+ /** The history the model answered — up to and including the turn's final
100
+ * user/tool message. The captured output is the reference assistant reply. */
101
+ readonly history: readonly HistoryMessage[];
102
+ /** The tool definitions the live call declared (R2-1) — present ONLY when it
103
+ * declared them, so a capture without tools is byte-identical to before. */
104
+ readonly tools?: readonly ToolDefinition[];
105
+ readonly toolChoice?: ToolChoice;
106
+ }
107
+ /** The live call's tool surface, recorded on the capture so turn replay answers
108
+ * the final turn with the SAME tool definitions. */
109
+ export interface CapturedTools {
110
+ readonly tools?: readonly ToolDefinition[];
111
+ readonly toolChoice?: ToolChoice;
112
+ }
113
+ /** Render a messages call's replay input for the capture row (JSON). */
114
+ export declare function renderForCapture(history: readonly HistoryMessage[], variables?: Record<string, unknown>, tools?: CapturedTools): string;
115
+ /** The replay input a capture row encodes: the route variables, plus the
116
+ * history when the row came from a messages call. A legacy (variables-only)
117
+ * row parses exactly as before. */
118
+ export interface CaptureReplayInput {
119
+ readonly input: Record<string, unknown>;
120
+ readonly messages?: readonly HistoryMessage[];
121
+ /** The live call's tools (R2-1), when it declared any — replayed verbatim. */
122
+ readonly tools?: readonly ToolDefinition[];
123
+ readonly toolChoice?: ToolChoice;
124
+ }
125
+ export declare function parseCaptureInput(variablesJson: string): CaptureReplayInput;
126
+ /** The capture-row input for a run: the variables alone (legacy, byte-identical)
127
+ * or the messages envelope. Returned as a value for `JSON.stringify` by the
128
+ * capture writer. */
129
+ export declare function captureInputFor(input: Record<string, unknown>, messages: readonly HistoryMessage[] | undefined, tools?: CapturedTools): unknown;
130
+ /**
131
+ * The routed lane's history for one run (rig.run / runStream / runBundle), or
132
+ * `undefined` for a variables route — BYTE-IDENTICAL then. Throws pre-dispatch
133
+ * (nothing billed, no telemetry — a config error, like every RouteConfigError):
134
+ * `messages` on a route that does not declare `input: messages`; a messages
135
+ * route called without `messages`; a messages route that also declares
136
+ * mask/screen (mirror bundles skip the loader, so the pairing is re-checked);
137
+ * an invalid history.
138
+ */
139
+ export interface RoutedHistory<R> {
140
+ readonly history: readonly HistoryMessage[] | undefined;
141
+ /** The route the ladder runs on: the SAME object unless candidates were
142
+ * skipped for this history (ruling R2-2). */
143
+ readonly route: R;
144
+ /** Telemetry tag for the skipped candidates (`provider/model=code,…`), or {}. */
145
+ readonly skipTag: Record<string, string>;
146
+ }
147
+ export declare function routedHistory<R extends Pick<RouteBundle, "route" | "inputKind" | "mask" | "screen" | "repair" | "variants" | "candidates">>(route: R, opts: Pick<RunOptions, "messages" | "tools">): RoutedHistory<R>;
148
+ /** The `history_skipped` tag key (the precedent is `zdr_enforced`). */
149
+ export declare const HISTORY_SKIPPED_TAG = "history_skipped";
150
+ /** Merge the skip tag onto the run's tags; the SAME object when there is none. */
151
+ export declare function withSkipTag<T extends RunOptions["tags"]>(tags: T, skipTag: Record<string, string>): T;
152
+ /** A messages route's final user instruction: its rendered `prompt.user` when
153
+ * declared, else nothing (the history's last turn IS the prompt — the fixed
154
+ * single-turn trigger is never appended to a conversation). */
155
+ export declare function messagesUserTurn(route: Pick<RouteBundle, "userTemplate">, ctx: {
156
+ readonly variables: Record<string, unknown>;
157
+ readonly capabilities: ReadonlySet<CapabilityFlag>;
158
+ readonly variableTrust?: Readonly<Record<string, "untrusted">>;
159
+ }): string;
160
+ /** Prefix of every "this provider cannot take this history natively" refusal —
161
+ * the stable marker turn replay keys on to mark a case INCOMPARABLE for a
162
+ * candidate (bakeoff/turn-replay.ts) rather than score it as a failure. */
163
+ export declare const HISTORY_INCOMPATIBLE_PREFIX = "history not accepted natively";
164
+ /**
165
+ * Why `provider/model` cannot be sent this history natively, or null. Fail-closed
166
+ * PRE-DISPATCH (no provider call) on two documented provider rules:
167
+ * - Anthropic rejects `tool_use` / `tool_result` blocks unless the request
168
+ * declares `tools`;
169
+ * - Gemini 3 models require thought signatures on earlier `functionCall` parts,
170
+ * which ModelRig neither captures nor invents (no placeholder signatures).
171
+ * Every other provider/model proceeds.
172
+ */
173
+ export declare function historyIncompatibility(provider: string, model: string, history: readonly HistoryMessage[] | undefined, declaredTools: readonly unknown[] | undefined): string | null;
174
+ /** Short reason code (telemetry tag value) + the teaching message. */
175
+ export interface HistoryIncompatibility {
176
+ readonly code: "tools_required" | "thought_signatures";
177
+ readonly message: string;
178
+ }
179
+ /** R2-4: `models/gemini-3…` and case variants normalize to `gemini-3…`. An
180
+ * unregistered alias (e.g. `gemini-pro-latest`) does not match and falls
181
+ * through to the provider's own 400 — documented, never guessed. */
182
+ export declare function isGemini3Model(model: string): boolean;
183
+ export declare function historyIncompatibilityCode(provider: string, model: string, history: readonly HistoryMessage[] | undefined, declaredTools: readonly unknown[] | undefined): HistoryIncompatibility | null;
184
+ /** The raw lane's history (runRaw / runRawStream), or `undefined` for the
185
+ * single-turn call. `userPrompt` is optional only when `messages` is given;
186
+ * neither is a teaching error. A history the target provider cannot take
187
+ * natively is refused here, pre-dispatch (no provider call, no telemetry row). */
188
+ export declare function rawHistory(input: {
189
+ readonly provider: string;
190
+ readonly model: string;
191
+ readonly userPrompt?: string;
192
+ readonly messages?: unknown;
193
+ readonly tools?: readonly unknown[];
194
+ }): readonly HistoryMessage[] | undefined;
195
+ /** The user side of the rendered request for the attempt envelope's
196
+ * input_hash / size (WI-1): the canonical history followed by the final user
197
+ * instruction; exactly `userPrompt` when there is no history (byte-identical). */
198
+ export declare function userSideForHash(userPrompt: string, history: readonly HistoryMessage[] | undefined): string;
199
+ //# sourceMappingURL=messages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/run/messages.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC9E,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAKpD,0CAA0C;AAC1C,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;;iDAGiD;AACjD,MAAM,MAAM,WAAW,GAAG,eAAe,CAAC;AAE1C,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,SAAS,WAAW,EAAE,CAAC;AAE7D,MAAM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