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,230 @@
1
+ "use strict";
2
+ /**
3
+ * Messages lane — provider-neutral history → each provider family's native
4
+ * conversation shape (ARC-β, builder-prompt-02 §1.2). The single place every
5
+ * dialect is translated, so each adapter's diff is one branch:
6
+ * `req.history !== undefined ? <family mapper> : <today's literal>`.
7
+ *
8
+ * SEMANTICS (identical for every family, `AdapterRequest.history`):
9
+ * provider messages = [system(systemPrompt)] + map(history)
10
+ * + (userPrompt !== "" ? [user(userPrompt)] : [])
11
+ * The system prompt keeps its family-native slot (OpenAI `system` message,
12
+ * Anthropic top-level `system`, Gemini `systemInstruction`, Responses `system`
13
+ * input item) exactly as the single-turn path delivers it.
14
+ *
15
+ * Pure functions, no I/O. History is assumed VALID (run/messages.ts validates
16
+ * at every SDK entry): tool results answer a prior call, arguments are JSON.
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.userSideMentions = userSideMentions;
20
+ exports.toOpenAIChatMessages = toOpenAIChatMessages;
21
+ exports.toResponsesInput = toResponsesInput;
22
+ exports.toAnthropicMessages = toAnthropicMessages;
23
+ exports.toGeminiContents = toGeminiContents;
24
+ const messages_1 = require("../run/messages");
25
+ // ── shared ───────────────────────────────────────────────────────────────────
26
+ /** True when `word` appears in the user side of a request — the single-turn
27
+ * `userPrompt`, or (messages lane) any history text. The DeepSeek / compat
28
+ * JSON-guard keys on this so a one-turn history is guarded exactly like the
29
+ * legacy `userPrompt` it replaces. */
30
+ function userSideMentions(req, word) {
31
+ if (req.userPrompt.includes(word))
32
+ return true;
33
+ if (req.history === undefined)
34
+ return false;
35
+ return req.history.some((m) => (m.role === "tool" ? m.content : (0, messages_1.contentText)(m.content)).includes(word));
36
+ }
37
+ /** Parse a tool call's JSON-string arguments into the object Anthropic `input`
38
+ * / Gemini `args` require. Validation guarantees JSON; a non-object value is
39
+ * wrapped so the provider still receives an object (never dropped). */
40
+ function parseArgs(args) {
41
+ try {
42
+ const v = JSON.parse(args);
43
+ return typeof v === "object" && v !== null && !Array.isArray(v) ? v : { value: v };
44
+ }
45
+ catch {
46
+ return { value: args };
47
+ }
48
+ }
49
+ function chatContent(c, opts) {
50
+ if (typeof c === "string" || opts.flattenParts)
51
+ return (0, messages_1.contentText)(c);
52
+ return c.map((p) => ({ type: "text", text: p.text }));
53
+ }
54
+ /** History → OpenAI Chat Completions `messages` (tool_calls / role:"tool"). */
55
+ function toOpenAIChatMessages(systemPrompt, history, userPrompt, opts) {
56
+ const out = systemPrompt !== "" ? [{ role: "system", content: systemPrompt }] : [];
57
+ for (const m of history) {
58
+ if (m.role === "user") {
59
+ out.push({ role: "user", content: chatContent(m.content, opts) });
60
+ }
61
+ else if (m.role === "tool") {
62
+ out.push({ role: "tool", tool_call_id: m.toolCallId, content: m.content });
63
+ }
64
+ else {
65
+ const calls = m.toolCalls ?? [];
66
+ const text = (0, messages_1.contentText)(m.content);
67
+ out.push({
68
+ role: "assistant",
69
+ // OpenAI: an assistant turn that only called tools carries `content: null`.
70
+ content: calls.length > 0 && text === "" ? null : chatContent(m.content, opts),
71
+ ...(calls.length > 0
72
+ ? {
73
+ tool_calls: calls.map((c) => ({
74
+ id: c.id,
75
+ type: "function",
76
+ function: { name: c.function.name, arguments: c.function.arguments },
77
+ })),
78
+ }
79
+ : {}),
80
+ });
81
+ }
82
+ }
83
+ if (userPrompt !== "")
84
+ out.push({ role: "user", content: userPrompt });
85
+ return out;
86
+ }
87
+ /** History → Responses API `input` (messages + function_call /
88
+ * function_call_output items). */
89
+ function toResponsesInput(systemPrompt, history, userPrompt) {
90
+ const out = systemPrompt !== "" ? [{ role: "system", content: systemPrompt }] : [];
91
+ for (const m of history) {
92
+ if (m.role === "user") {
93
+ out.push(typeof m.content === "string"
94
+ ? { role: "user", content: m.content }
95
+ : { role: "user", content: m.content.map((p) => ({ type: "input_text", text: p.text })) });
96
+ }
97
+ else if (m.role === "tool") {
98
+ out.push({ type: "function_call_output", call_id: m.toolCallId, output: m.content });
99
+ }
100
+ else {
101
+ const text = (0, messages_1.contentText)(m.content);
102
+ if (text !== "" || (m.toolCalls ?? []).length === 0)
103
+ out.push({ role: "assistant", content: text });
104
+ for (const c of m.toolCalls ?? []) {
105
+ out.push({ type: "function_call", call_id: c.id, name: c.function.name, arguments: c.function.arguments });
106
+ }
107
+ }
108
+ }
109
+ if (userPrompt !== "")
110
+ out.push({ role: "user", content: userPrompt });
111
+ return out;
112
+ }
113
+ const toBlocks = (c) => typeof c === "string" ? [{ type: "text", text: c }] : c;
114
+ /** Push, merging into the previous message when the role repeats (Anthropic
115
+ * alternates user/assistant; tool results ride in a user turn, so tool results
116
+ * and a following user message share one user message). */
117
+ function pushAnthropic(out, msg) {
118
+ const prev = out[out.length - 1];
119
+ if (prev !== undefined && prev.role === msg.role) {
120
+ out[out.length - 1] = { role: msg.role, content: [...toBlocks(prev.content), ...toBlocks(msg.content)] };
121
+ return;
122
+ }
123
+ out.push(msg);
124
+ }
125
+ /** History → Anthropic Messages `messages` (the system prompt stays the
126
+ * top-level `system`, built by the adapter exactly as today). */
127
+ function toAnthropicMessages(history, userPrompt) {
128
+ const out = [];
129
+ for (const m of history) {
130
+ if (m.role === "user") {
131
+ pushAnthropic(out, {
132
+ role: "user",
133
+ content: typeof m.content === "string" ? m.content : m.content.map((p) => ({ type: "text", text: p.text })),
134
+ });
135
+ }
136
+ else if (m.role === "tool") {
137
+ pushAnthropic(out, { role: "user", content: [{ type: "tool_result", tool_use_id: m.toolCallId, content: m.content }] });
138
+ }
139
+ else {
140
+ const calls = m.toolCalls ?? [];
141
+ if (calls.length === 0) {
142
+ pushAnthropic(out, {
143
+ role: "assistant",
144
+ content: typeof m.content === "string" ? m.content : m.content.map((p) => ({ type: "text", text: p.text })),
145
+ });
146
+ continue;
147
+ }
148
+ const text = (0, messages_1.contentText)(m.content);
149
+ pushAnthropic(out, {
150
+ role: "assistant",
151
+ content: [
152
+ ...(text !== "" ? [{ type: "text", text }] : []),
153
+ ...calls.map((c) => ({ type: "tool_use", id: c.id, name: c.function.name, input: parseArgs(c.function.arguments) })),
154
+ ],
155
+ });
156
+ }
157
+ }
158
+ if (userPrompt !== "")
159
+ pushAnthropic(out, { role: "user", content: userPrompt });
160
+ return out;
161
+ }
162
+ function pushGemini(out, c) {
163
+ const prev = out[out.length - 1];
164
+ if (prev !== undefined && prev.role === c.role) {
165
+ out[out.length - 1] = { role: c.role, parts: [...prev.parts, ...c.parts] };
166
+ return;
167
+ }
168
+ out.push(c);
169
+ }
170
+ const textParts = (c) => typeof c === "string" ? [{ text: c }] : c.map((p) => ({ text: p.text }));
171
+ /** A tool result → Gemini `functionResponse.response` (must be an object): a
172
+ * JSON-object result passes through; anything else rides as `{ result }`. */
173
+ function functionResponseBody(content) {
174
+ try {
175
+ const v = JSON.parse(content);
176
+ if (typeof v === "object" && v !== null && !Array.isArray(v))
177
+ return v;
178
+ }
179
+ catch {
180
+ // not JSON — fall through to the text wrapper
181
+ }
182
+ return { result: content };
183
+ }
184
+ /**
185
+ * History → Gemini `contents`. `cachedPrefix` (non-empty) is the system prompt
186
+ * when a `cachedContent` handle forbids `systemInstruction` (issue #5 R1): it is
187
+ * delivered in the user turn exactly like the single-turn `cachedUserTurn` —
188
+ * folded into the first user message's first text part as `prefix\n\ntext`.
189
+ */
190
+ function toGeminiContents(history, userPrompt, cachedPrefix = "") {
191
+ const out = [];
192
+ // Gemini function calls carry no id — a tool result is matched to the NAME of
193
+ // the call it answers (validation guarantees the call precedes it).
194
+ const nameById = new Map();
195
+ for (const m of history) {
196
+ if (m.role === "user") {
197
+ pushGemini(out, { role: "user", parts: textParts(m.content) });
198
+ }
199
+ else if (m.role === "tool") {
200
+ pushGemini(out, {
201
+ role: "user",
202
+ parts: [{ functionResponse: { name: nameById.get(m.toolCallId) ?? m.toolCallId, response: functionResponseBody(m.content) } }],
203
+ });
204
+ }
205
+ else {
206
+ const calls = m.toolCalls ?? [];
207
+ for (const c of calls)
208
+ nameById.set(c.id, c.function.name);
209
+ const text = (0, messages_1.contentText)(m.content);
210
+ pushGemini(out, {
211
+ role: "model",
212
+ parts: [
213
+ ...(text !== "" || calls.length === 0 ? textParts(m.content) : []),
214
+ ...calls.map((c) => ({ functionCall: { name: c.function.name, args: parseArgs(c.function.arguments) } })),
215
+ ],
216
+ });
217
+ }
218
+ }
219
+ if (userPrompt !== "")
220
+ pushGemini(out, { role: "user", parts: [{ text: userPrompt }] });
221
+ if (cachedPrefix === "")
222
+ return out;
223
+ const first = out[0];
224
+ const firstPart = first?.parts[0];
225
+ if (first !== undefined && first.role === "user" && firstPart !== undefined && "text" in firstPart) {
226
+ out[0] = { role: "user", parts: [{ text: `${cachedPrefix}\n\n${firstPart.text}` }, ...first.parts.slice(1)] };
227
+ return out;
228
+ }
229
+ return [{ role: "user", parts: [{ text: cachedPrefix }] }, ...out];
230
+ }
@@ -20,6 +20,7 @@
20
20
  import type { CapabilityFlag, ProviderAdapter, ProviderId } from "../types/provider";
21
21
  import type { ClassifiedFailure, ShapingInput } from "./gemini";
22
22
  import type { OpenAIWireTool, OpenAIWireToolChoice } from "./tool-mapping";
23
+ import type { OpenAIChatWireMessage } from "./history-mapping";
23
24
  /** Fireworks serves models at accounts/fireworks/models/<short> — routes
24
25
  * declare the short name; the wire gets the full path (LiteLLM
25
26
  * fireworks_ai transformation, harvested). */
@@ -40,10 +41,7 @@ export interface OpenAICompatHost {
40
41
  * fail-closed (raw-support.ts) until B4b wires native GLM `web_search`. */
41
42
  export declare const OPENAI_COMPAT_HOSTS: Readonly<Record<"deepinfra" | "fireworks" | "zai", OpenAICompatHost>>;
42
43
  export declare function classifyCompatFailure(message: string, host: string): ClassifiedFailure;
43
- interface ChatMessage {
44
- readonly role: "system" | "user";
45
- readonly content: string;
46
- }
44
+ type ChatMessage = OpenAIChatWireMessage;
47
45
  export interface OpenAICompatShapedParams {
48
46
  readonly model: string;
49
47
  readonly max_tokens: number;
@@ -1 +1 @@
1
- {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EAAE,MAAM,KAAK,WAAW,CAAC,cAAc,CAAC,CAAC;CAC5E;AAED,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,yBAAyB,GAAG,eAAe,CA8L5F"}
@@ -32,6 +32,7 @@ const tool_mapping_1 = require("./tool-mapping");
32
32
  const openai_stream_1 = require("./openai-stream");
33
33
  const attempt_meta_map_1 = require("./attempt-meta-map");
34
34
  const sampling_1 = require("./sampling");
35
+ const history_mapping_1 = require("./history-mapping");
35
36
  const DEFAULT_MAX_TOKENS = 32000;
36
37
  /** Fireworks serves models at accounts/fireworks/models/<short> — routes
37
38
  * declare the short name; the wire gets the full path (LiteLLM
@@ -96,13 +97,16 @@ function buildOpenAICompatParams(model, req, profileFlags) {
96
97
  const wantJson = req.outputSchema !== null;
97
98
  const strict = wantJson && profileFlags.has("structured_native");
98
99
  let systemPrompt = req.systemPrompt;
99
- if (wantJson && !strict && !req.systemPrompt.includes("JSON") && !req.userPrompt.includes("JSON")) {
100
+ if (wantJson && !strict && !req.systemPrompt.includes("JSON") && !(0, history_mapping_1.userSideMentions)(req, "JSON")) {
100
101
  systemPrompt = systemPrompt === "" ? JSON_GUARD : `${systemPrompt}\n\n${JSON_GUARD}`;
101
102
  }
102
- const messages = [
103
- ...(systemPrompt !== "" ? [{ role: "system", content: systemPrompt }] : []),
104
- { role: "user", content: req.userPrompt },
105
- ];
103
+ // ARC-β: history present ⇒ mapped conversation; absent ⇒ today's literal (byte-identical).
104
+ const messages = req.history !== undefined
105
+ ? (0, history_mapping_1.toOpenAIChatMessages)(systemPrompt, req.history, req.userPrompt, { flattenParts: true })
106
+ : [
107
+ ...(systemPrompt !== "" ? [{ role: "system", content: systemPrompt }] : []),
108
+ { role: "user", content: req.userPrompt },
109
+ ];
106
110
  return {
107
111
  model,
108
112
  max_tokens: (0, sampling_1.effectiveMaxOutputTokens)(req, DEFAULT_MAX_TOKENS),
@@ -15,16 +15,14 @@ import type { CapabilityFlag, ProviderAdapter, ServiceTier } from "../types/prov
15
15
  import type { ClassifiedFailure, ShapingInput } from "./gemini";
16
16
  import type { OpenAIWireTool, OpenAIWireToolChoice } from "./tool-mapping";
17
17
  import type { ServedTierSource } from "../telemetry/attempt-meta";
18
+ import type { OpenAIChatWireMessage } from "./history-mapping";
18
19
  export interface OpenAIAdapterConfig {
19
20
  readonly apiKey: string;
20
21
  }
21
22
  export declare function isModelFlexEligible(modelName: string): boolean;
22
23
  export declare function openaiSupports(feature: CapabilityFlag, model: string): boolean;
23
24
  export declare function classifyOpenAIFailure(message: string): ClassifiedFailure;
24
- interface ChatMessage {
25
- readonly role: "system" | "user";
26
- readonly content: string;
27
- }
25
+ type ChatMessage = OpenAIChatWireMessage;
28
26
  export interface OpenAIShapedParams {
29
27
  readonly model: string;
30
28
  readonly max_completion_tokens: number;
@@ -1 +1 @@
1
- {"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../src/adapters/openai.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,KAAK,EAIV,cAAc,EACd,eAAe,EACf,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAMhE,OAAO,KAAK,EAAuB,cAAc,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAIhG,OAAO,KAAK,EAAiB,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAKjF,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAMD,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAI9D;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAe9E;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,iBAAiB,CA0CxE;AAED,UAAU,WAAW;IACnB,QAAQ,CAAC,IAAI,EAAE,Q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AAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAA;CAAE,CAKnE;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,mBAAmB,GAAG,eAAe,CAuQhF"}
@@ -28,6 +28,7 @@ const openai_stream_1 = require("./openai-stream");
28
28
  const attempt_meta_map_1 = require("./attempt-meta-map");
29
29
  const sampling_1 = require("./sampling");
30
30
  const responses_api_1 = require("./responses-api");
31
+ const history_mapping_1 = require("./history-mapping");
31
32
  /** OpenAI's documented flex-eligible allowlist as of 2026-05 (ported).
32
33
  * Mini and nano variants are silently downgraded to default tier. */
33
34
  const FLEX_ELIGIBLE_PREFIXES = ["gpt-5.4", "gpt-5.2", "gpt-5.1", "gpt-5", "gpt-4.1"];
@@ -101,10 +102,13 @@ function classifyOpenAIFailure(message) {
101
102
  }
102
103
  const DEFAULT_MAX_COMPLETION_TOKENS = 32000;
103
104
  function buildOpenAIParams(model, req) {
104
- const messages = [
105
- ...(req.systemPrompt !== "" ? [{ role: "system", content: req.systemPrompt }] : []),
106
- { role: "user", content: req.userPrompt },
107
- ];
105
+ // ARC-β: history present ⇒ mapped conversation; absent ⇒ today's literal (byte-identical).
106
+ const messages = req.history !== undefined
107
+ ? (0, history_mapping_1.toOpenAIChatMessages)(req.systemPrompt, req.history, req.userPrompt, { flattenParts: false })
108
+ : [
109
+ ...(req.systemPrompt !== "" ? [{ role: "system", content: req.systemPrompt }] : []),
110
+ { role: "user", content: req.userPrompt },
111
+ ];
108
112
  return {
109
113
  model,
110
114
  max_completion_tokens: (0, sampling_1.effectiveMaxOutputTokens)(req, DEFAULT_MAX_COMPLETION_TOKENS),
@@ -1 +1 @@
1
- {"version":3,"file":"responses-api.d.ts","sourceRoot":"","sources":["../../src/adapters/responses-api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,KAAK,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CAAC,EAAE,MAAM,CAAC;CAC/B;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,cAAc,GAAG,qBAAqB,CAkC/E;AA6BD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,OAAO,GAAG,eAAe,CAyDrE"}
@@ -21,6 +21,7 @@ exports.buildResponsesParams = buildResponsesParams;
21
21
  exports.mapResponsesResult = mapResponsesResult;
22
22
  const sampling_1 = require("./sampling");
23
23
  const raw_support_1 = require("../run/raw-support");
24
+ const history_mapping_1 = require("./history-mapping");
24
25
  /** Parity with the Chat Completions default output cap (openai.ts / grok.ts). */
25
26
  const DEFAULT_MAX_OUTPUT_TOKENS = 32000;
26
27
  /**
@@ -33,10 +34,14 @@ const DEFAULT_MAX_OUTPUT_TOKENS = 32000;
33
34
  * (the SAME disclosed mapping the Chat Completions path uses — never a silent drop).
34
35
  */
35
36
  function buildResponsesParams(req) {
36
- const input = [
37
- ...(req.systemPrompt !== "" ? [{ role: "system", content: req.systemPrompt }] : []),
38
- { role: "user", content: req.userPrompt },
39
- ];
37
+ // ARC-β: history present ⇒ messages + function_call / function_call_output
38
+ // items (history-mapping.ts); absent ⇒ today's literal (byte-identical).
39
+ const input = req.history !== undefined
40
+ ? (0, history_mapping_1.toResponsesInput)(req.systemPrompt, req.history, req.userPrompt)
41
+ : [
42
+ ...(req.systemPrompt !== "" ? [{ role: "system", content: req.systemPrompt }] : []),
43
+ { role: "user", content: req.userPrompt },
44
+ ];
40
45
  const reasoning = req.reasoning !== undefined
41
46
  ? {
42
47
  reasoning: {
@@ -1 +1 @@
1
- {"version":3,"file":"artifact.d.ts","sourceRoot":"","sources":["../../src/artifacts/artifact.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGz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settings/task-settings");
25
25
  const manifest_1 = require("../prompts/manifest");
26
+ const media_1 = require("./media");
26
27
  /** The configured scrub mode for one artifact save (BEFORE the S8-c PII/PHI
27
28
  * floor). Resolved EXACTLY as capture-write.ts / samples.ts do: a configured
28
29
  * control plane WINS (`resolver.get(task).scrub`), else the rig's default. A
@@ -47,6 +48,8 @@ function contentTypeFor(type) {
47
48
  // PSR-1: a structure-only assembly manifest is stored as a linked JSON artifact.
48
49
  if (t === "manifest")
49
50
  return "application/json";
51
+ if ((0, media_1.isMediaType)(t))
52
+ return t; // ARC-4: generated media keeps its own MIME type
50
53
  return "application/octet-stream";
51
54
  }
52
55
  function idOf(ref) {
@@ -165,6 +168,78 @@ function createArtifactApi(deps) {
165
168
  }
166
169
  }
167
170
  }
171
+ /** ARC-4: save a generated image/video/audio artifact. Same row, lineage and
172
+ * classification rules as `save`; the bytes are hashed as bytes, the row
173
+ * carries the unscreened-media scrub flag, and custody uploads the bytes
174
+ * verbatim under their own MIME type — unless the effective scrub mode is
175
+ * redact/block, which bytes cannot honour (fail-closed: no upload, counted). */
176
+ const saveMedia = (value, opts, ctx) => {
177
+ // F6: only allowlisted media types are stored (svg can carry script).
178
+ if (!(0, media_1.isAllowedMediaType)(opts.type))
179
+ return (0, media_1.warnRefusedMediaType)(opts.name, opts.type);
180
+ const body = (0, media_1.mediaBytes)(value);
181
+ const contentHash = `sha256:${(0, node_crypto_1.createHash)("sha256").update(body).digest("hex")}`;
182
+ const id = (0, node_crypto_1.randomUUID)();
183
+ const version = opts.supersedes !== undefined ? opts.supersedes.version + 1 : 1;
184
+ const stepKey = opts.stepKey ?? ctx?.currentStepKey() ?? null;
185
+ const norm = (0, classification_1.normalizeClassification)(opts.classification);
186
+ const classification = norm !== null && (0, classification_1.isDataClassification)(norm) ? norm : null;
187
+ if (opts.classification !== undefined && norm !== null && classification === null) {
188
+ console.warn(`[modelrig artifacts] artifact "${opts.name}" has an unknown data_classification — label dropped (artifact still saved). ` +
189
+ `fix_hint: use one of ${classification_1.DATA_CLASSIFICATIONS.join(", ")}.`);
190
+ }
191
+ // Custody decision BEFORE the row, so the row's scrub record is truthful (F5).
192
+ const custody = content !== undefined && opts.contentRef === undefined;
193
+ const mode = custody && content !== undefined ? (0, task_settings_1.effectiveScrubMode)(resolveContentScrubMode(content, opts.task), classification) : null;
194
+ const refused = mode !== null && !(0, media_1.mediaUploadAllowed)(mode);
195
+ try {
196
+ store.recordArtifact({
197
+ id,
198
+ runId: ctx?.runId ?? null,
199
+ stepKey,
200
+ attemptNo: opts.attemptNo ?? null,
201
+ task: opts.task ?? null,
202
+ name: opts.name,
203
+ type: opts.type,
204
+ version,
205
+ supersedesArtifactId: opts.supersedes?.id ?? null,
206
+ declaredSchema: null,
207
+ fingerprintCell: null,
208
+ contentRef: opts.contentRef ?? null,
209
+ contentHash,
210
+ contentBytes: body.byteLength,
211
+ dataClassification: classification,
212
+ expiresAt: opts.expiresAt ?? null,
213
+ scrub: refused && mode !== null ? (0, media_1.refusedMediaScrub)(mode) : (0, media_1.unscreenedMediaScrub)(),
214
+ });
215
+ saves += 1;
216
+ if (opts.task !== undefined)
217
+ savedTasks.set(id, opts.task);
218
+ if (ctx !== null) {
219
+ for (const loadedId of ctx.takeLoadedIds()) {
220
+ if (loadedId === id)
221
+ continue;
222
+ store.recordArtifactEdge({ fromArtifactId: id, toArtifactId: loadedId, kind: "derived_from" });
223
+ inferredEdges += 1;
224
+ }
225
+ }
226
+ }
227
+ catch (err) {
228
+ warn("save (media)", err);
229
+ return null;
230
+ }
231
+ if (content !== undefined && mode !== null) {
232
+ if (!refused) {
233
+ fireUpload({ artifactId: id, contentType: contentTypeFor(opts.type), body, contentHash }, content.upload);
234
+ }
235
+ else {
236
+ contentBlocked += 1;
237
+ console.warn(`[modelrig artifacts] media artifact "${opts.name}" NOT uploaded: scrub mode "${mode}" cannot be applied to ` +
238
+ "image/video/audio bytes (the scrub engine reads text only); metadata + hash kept.");
239
+ }
240
+ }
241
+ return { id, name: opts.name, type: opts.type, version };
242
+ };
168
243
  // Extracted so `saveManifest` (PSR-1) can compose them without re-implementing
169
244
  // the custody/lineage save path or the edges_no_self link. The bodies are the
170
245
  // original `save`/`link` verbatim — the returned object references these.
@@ -177,6 +252,10 @@ function createArtifactApi(deps) {
177
252
  "(fail-closed at the SDK gate; no metadata, no hash persisted).");
178
253
  return null;
179
254
  }
255
+ // ARC-4: generated media (image/video/audio) takes its own path — binary
256
+ // bytes, flagged unscreened (media.ts). Text keeps the path below.
257
+ if ((0, media_1.isMediaType)(opts.type))
258
+ return saveMedia(value, opts, ctx);
180
259
  // Hash the serialization, then DISCARD the bytes — metadata + hash only.
181
260
  const serialized = typeof value === "string" ? value : JSON.stringify(value ?? null);
182
261
  const bytes = Buffer.byteLength(serialized, "utf8");
@@ -0,0 +1,128 @@
1
+ /**
2
+ * ARC-1 — conversations as runs: `rig.conversation(id, { agent, user?, tenant? })`.
3
+ *
4
+ * A conversation (support chat, sales thread, agent task loop) is ONE `runs`
5
+ * row: `pipeline = agent`, `episode_key = <your conversation id>`,
6
+ * `meta.trigger = "conversation"`. Each turn is a set of `steps` in that run.
7
+ * No new table (ARC-D1). The returned handle IS the run handle `run.start`
8
+ * returns (`runId`, `end`), plus `turn(fn)` and the conversation id.
9
+ *
10
+ * ── TURN STEPS — THE RULE ─────────────────────────────────────────────────
11
+ * - `conversation.turn(fn)` opens turn n+1 (n starts at 0 — or, on re-entry,
12
+ * at the highest turn already recorded for this run) and every `rig.run` /
13
+ * `rig.runRaw` / `rig.recordCall` inside `fn` records under step key
14
+ * `turn:<n>.<k>`, where k = 1, 2, … is the call's index WITHIN the turn.
15
+ * (Why `.k`: a repeated step key inside one run is read as a RETRY — the
16
+ * context bumps `attempt_no` for the same key — so two calls in one turn
17
+ * must not share `turn:<n>`. `turn:<n>.<k>` keeps every call its own step
18
+ * while the turn number stays the prefix every reader groups on.)
19
+ * - A call made on the conversation OUTSIDE any `turn()` attaches to the
20
+ * CURRENT turn (turn 1 if none was opened yet).
21
+ * - An explicit `stepKey` (or `tags.step`) from the caller always wins — the
22
+ * turn rule only replaces the auto-minted key.
23
+ * - Retries/fallbacks of ONE call reuse its key (attempt_no distinguishes them).
24
+ *
25
+ * ── RE-ENTRY ──────────────────────────────────────────────────────────────
26
+ * A later request with the same `(agent, id)` re-enters the open run instead of
27
+ * starting a new one: first this process's open conversations, then the LOCAL
28
+ * store's newest `running` run for `(agent, id)` (so a restarted worker
29
+ * continues the run and its turn numbering). Cross-process re-entry (another
30
+ * HTTP worker with its own store) is OUT OF SCOPE for the SDK: a race or a
31
+ * second worker produces a second run with the same episode_key, which 00031
32
+ * already tolerates and the console groups by conversation id. Pin with the
33
+ * returned `runId` if you need one run.
34
+ *
35
+ * ── CLOSING ───────────────────────────────────────────────────────────────
36
+ * `conversation.end(status = "succeeded")`. Conversations rarely end cleanly, so
37
+ * the server's idle sweep (`conversation-idle-close`) also closes `running`
38
+ * conversations idle past the org's `idle_close_minutes` (default 30).
39
+ *
40
+ * ── CONCURRENCY ───────────────────────────────────────────────────────────
41
+ * `rig.conversation()` makes the run ambient on the current async path (like
42
+ * `run.start`, via `enterWith`). `turn(fn)` runs `fn` inside its OWN scope
43
+ * (`AsyncLocalStorage.run`), so overlapping turns of DIFFERENT conversations in
44
+ * one process never cross-attribute.
45
+ *
46
+ * Inert (a pass-through `turn`, no rows) when the run namespace is disabled.
47
+ */
48
+ import type { RunEndOptions, RunHandle, RunStatus } from "./run-context";
49
+ import type { RunLimits } from "../run/limits";
50
+ /** The step-key prefix of a conversation turn. */
51
+ export declare const TURN_STEP_PREFIX = "turn:";
52
+ /** `turn:<n>.<k>` — turn n, k-th call within it. */
53
+ export declare function turnStepKey(turn: number, call: number): string;
54
+ /** The turn number a step key belongs to, or null when it is not a turn key.
55
+ * Accepts `turn:<n>` (an explicit caller key) and `turn:<n>.<k>`. */
56
+ export declare function turnNumberOf(stepKey: string): number | null;
57
+ /** The highest turn among recorded step keys (0 when none). */
58
+ export declare function maxTurnOf(stepKeys: Iterable<string>): number;
59
+ /** The highest turn AND the highest call index within it — the counter seed on
60
+ * re-entry, so a call that attaches to the current turn never reuses a recorded
61
+ * `turn:<n>.<k>` key (a reused key would read as a retry). */
62
+ export declare function turnStateOf(stepKeys: Iterable<string>): {
63
+ readonly turn: number;
64
+ readonly call: number;
65
+ };
66
+ /** Per-conversation turn bookkeeping: which turn is current and the next call
67
+ * index within it. Pure; one per conversation context. */
68
+ export declare class TurnCounter {
69
+ private turnNo;
70
+ private callNo;
71
+ /** Seed from a re-entered run: the current turn and its highest call index. */
72
+ constructor(startAfterTurn?: number, startAfterCall?: number);
73
+ /** Open the next turn; returns its number. */
74
+ open(): number;
75
+ /** The current turn (0 before any). */
76
+ current(): number;
77
+ /** Mint the step key for the next call: the current turn (turn 1 if none was
78
+ * opened yet), next call index. */
79
+ mint(): string;
80
+ }
81
+ export interface ConversationOptions {
82
+ /** The agent / bot name — the run's `pipeline`. Required. */
83
+ readonly agent: string;
84
+ /** Your end user's opaque id → `tags.user` on every call (never a name/email). */
85
+ readonly user?: string;
86
+ /** Your end customer (Tenant Ledger subject) → `tags.subject` on every call. */
87
+ readonly tenant?: string;
88
+ readonly environment?: string;
89
+ /** ARC-5 run limits for the conversation's run (see run/limits.ts). Applied
90
+ * when the run is STARTED; a re-entry keeps the open run's limits. */
91
+ readonly limits?: RunLimits;
92
+ }
93
+ /** The handle `rig.conversation` returns — the run handle plus turns. */
94
+ export interface ConversationHandle extends RunHandle {
95
+ /** Your conversation id (the run's episode_key). */
96
+ readonly conversationId: string;
97
+ /** True when this call re-entered an already-open run. */
98
+ readonly resumed: boolean;
99
+ /** The current turn number (0 before the first). */
100
+ currentTurn(): number;
101
+ /** Open the next turn and run `fn` inside it (see the turn rule above). */
102
+ turn<T>(fn: () => Promise<T> | T): Promise<T>;
103
+ /** Close the conversation (default "succeeded"). */
104
+ end(status?: RunStatus, opts?: RunEndOptions): void;
105
+ }
106
+ /** What `rig.conversation` needs from the run namespace — implemented in
107
+ * run-context.ts, which owns the ambient storage. */
108
+ export interface ConversationHost<Ctx> {
109
+ readonly enabled: boolean;
110
+ /** Find (in-process, then local store) or start the conversation's run. */
111
+ openOrResume(id: string, opts: ConversationOptions): {
112
+ readonly ctx: Ctx;
113
+ readonly resumed: boolean;
114
+ };
115
+ runIdOf(ctx: Ctx): string;
116
+ counterOf(ctx: Ctx): TurnCounter;
117
+ /** Make `ctx` ambient on the current async path (enterWith). */
118
+ enter(ctx: Ctx): void;
119
+ /** Run `fn` with `ctx` ambient in its own scope (storage.run). */
120
+ runIn<T>(ctx: Ctx, fn: () => Promise<T>): Promise<T>;
121
+ end(ctx: Ctx, status?: RunStatus, opts?: RunEndOptions): void;
122
+ }
123
+ /** The step tags a conversation stamps on every call (caller tags win). */
124
+ export declare function conversationTags(opts: ConversationOptions): Readonly<Record<string, string>>;
125
+ /** Build a conversation handle over a host. Bad `id`/`agent` is a caller bug and
126
+ * throws (like `buildGradeRow`); a disabled namespace is inert. */
127
+ export declare function createConversation<Ctx>(host: ConversationHost<Ctx>, id: string, opts: ConversationOptions): ConversationHandle;
128
+ //# sourceMappingURL=conversation.d.ts.map