modelrig 0.0.1 → 0.2.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 (420) hide show
  1. package/CHANGELOG.md +94 -0
  2. package/LICENSE +201 -0
  3. package/README.md +145 -8
  4. package/data/PROVENANCE.md +19 -0
  5. package/data/pricing-manual.json +22 -0
  6. package/data/pricing-map.json +46362 -0
  7. package/data/pricing-overlay.json +419 -0
  8. package/dist/adapters/anthropic.d.ts +90 -0
  9. package/dist/adapters/anthropic.d.ts.map +1 -0
  10. package/dist/adapters/anthropic.js +296 -0
  11. package/dist/adapters/build-adapters.d.ts +11 -0
  12. package/dist/adapters/build-adapters.d.ts.map +1 -0
  13. package/dist/adapters/build-adapters.js +45 -0
  14. package/dist/adapters/deepseek.d.ts +47 -0
  15. package/dist/adapters/deepseek.d.ts.map +1 -0
  16. package/dist/adapters/deepseek.js +216 -0
  17. package/dist/adapters/gemini.d.ts +44 -0
  18. package/dist/adapters/gemini.d.ts.map +1 -0
  19. package/dist/adapters/gemini.js +262 -0
  20. package/dist/adapters/grok.d.ts +53 -0
  21. package/dist/adapters/grok.d.ts.map +1 -0
  22. package/dist/adapters/grok.js +232 -0
  23. package/dist/adapters/openai-compat.d.ts +80 -0
  24. package/dist/adapters/openai-compat.d.ts.map +1 -0
  25. package/dist/adapters/openai-compat.js +244 -0
  26. package/dist/adapters/openai-stream.d.ts +58 -0
  27. package/dist/adapters/openai-stream.d.ts.map +1 -0
  28. package/dist/adapters/openai-stream.js +120 -0
  29. package/dist/adapters/openai.d.ts +55 -0
  30. package/dist/adapters/openai.d.ts.map +1 -0
  31. package/dist/adapters/openai.js +281 -0
  32. package/dist/adapters/sampling.d.ts +28 -0
  33. package/dist/adapters/sampling.d.ts.map +1 -0
  34. package/dist/adapters/sampling.js +34 -0
  35. package/dist/adapters/tool-mapping.d.ts +92 -0
  36. package/dist/adapters/tool-mapping.d.ts.map +1 -0
  37. package/dist/adapters/tool-mapping.js +143 -0
  38. package/dist/artifacts/artifact.d.ts +137 -0
  39. package/dist/artifacts/artifact.d.ts.map +1 -0
  40. package/dist/artifacts/artifact.js +377 -0
  41. package/dist/artifacts/content-uploader.d.ts +87 -0
  42. package/dist/artifacts/content-uploader.d.ts.map +1 -0
  43. package/dist/artifacts/content-uploader.js +124 -0
  44. package/dist/artifacts/index.d.ts +63 -0
  45. package/dist/artifacts/index.d.ts.map +1 -0
  46. package/dist/artifacts/index.js +80 -0
  47. package/dist/artifacts/run-context.d.ts +129 -0
  48. package/dist/artifacts/run-context.d.ts.map +1 -0
  49. package/dist/artifacts/run-context.js +208 -0
  50. package/dist/artifacts/scrub.d.ts +60 -0
  51. package/dist/artifacts/scrub.d.ts.map +1 -0
  52. package/dist/artifacts/scrub.js +139 -0
  53. package/dist/artifacts/step.d.ts +26 -0
  54. package/dist/artifacts/step.d.ts.map +1 -0
  55. package/dist/artifacts/step.js +37 -0
  56. package/dist/artifacts/taint.d.ts +63 -0
  57. package/dist/artifacts/taint.d.ts.map +1 -0
  58. package/dist/artifacts/taint.js +76 -0
  59. package/dist/bakeoff/cache-sim.d.ts +99 -0
  60. package/dist/bakeoff/cache-sim.d.ts.map +1 -0
  61. package/dist/bakeoff/cache-sim.js +126 -0
  62. package/dist/bakeoff/engine.d.ts +52 -0
  63. package/dist/bakeoff/engine.d.ts.map +1 -0
  64. package/dist/bakeoff/engine.js +163 -0
  65. package/dist/bakeoff/eval-cases.d.ts +96 -0
  66. package/dist/bakeoff/eval-cases.d.ts.map +1 -0
  67. package/dist/bakeoff/eval-cases.js +105 -0
  68. package/dist/bakeoff/replay.d.ts +52 -0
  69. package/dist/bakeoff/replay.d.ts.map +1 -0
  70. package/dist/bakeoff/replay.js +94 -0
  71. package/dist/bakeoff/report.d.ts +41 -0
  72. package/dist/bakeoff/report.d.ts.map +1 -0
  73. package/dist/bakeoff/report.js +142 -0
  74. package/dist/bakeoff/samples.d.ts +77 -0
  75. package/dist/bakeoff/samples.d.ts.map +1 -0
  76. package/dist/bakeoff/samples.js +148 -0
  77. package/dist/bakeoff/stats.d.ts +13 -0
  78. package/dist/bakeoff/stats.d.ts.map +1 -0
  79. package/dist/bakeoff/stats.js +48 -0
  80. package/dist/bakeoff/types.d.ts +37 -0
  81. package/dist/bakeoff/types.d.ts.map +1 -0
  82. package/dist/bakeoff/types.js +10 -0
  83. package/dist/cli.d.ts +25 -0
  84. package/dist/cli.d.ts.map +1 -0
  85. package/dist/cli.js +590 -0
  86. package/dist/config.d.ts +204 -0
  87. package/dist/config.d.ts.map +1 -0
  88. package/dist/config.js +252 -0
  89. package/dist/deprecations.d.ts +32 -0
  90. package/dist/deprecations.d.ts.map +1 -0
  91. package/dist/deprecations.js +59 -0
  92. package/dist/feedback/coverage.d.ts +32 -0
  93. package/dist/feedback/coverage.d.ts.map +1 -0
  94. package/dist/feedback/coverage.js +95 -0
  95. package/dist/feedback/feedback.d.ts +35 -0
  96. package/dist/feedback/feedback.d.ts.map +1 -0
  97. package/dist/feedback/feedback.js +39 -0
  98. package/dist/gateway/http-protocol.d.ts +175 -0
  99. package/dist/gateway/http-protocol.d.ts.map +1 -0
  100. package/dist/gateway/http-protocol.js +105 -0
  101. package/dist/index.d.ts +242 -0
  102. package/dist/index.d.ts.map +1 -0
  103. package/dist/index.js +576 -0
  104. package/dist/init/finder.d.ts +94 -0
  105. package/dist/init/finder.d.ts.map +1 -0
  106. package/dist/init/finder.js +343 -0
  107. package/dist/init/init-cli.d.ts +10 -0
  108. package/dist/init/init-cli.d.ts.map +1 -0
  109. package/dist/init/init-cli.js +86 -0
  110. package/dist/init/observe-cli.d.ts +19 -0
  111. package/dist/init/observe-cli.d.ts.map +1 -0
  112. package/dist/init/observe-cli.js +73 -0
  113. package/dist/init/observe.d.ts +81 -0
  114. package/dist/init/observe.d.ts.map +1 -0
  115. package/dist/init/observe.js +245 -0
  116. package/dist/init/run.d.ts +99 -0
  117. package/dist/init/run.d.ts.map +1 -0
  118. package/dist/init/run.js +281 -0
  119. package/dist/init/signatures.d.ts +39 -0
  120. package/dist/init/signatures.d.ts.map +1 -0
  121. package/dist/init/signatures.js +116 -0
  122. package/dist/matrix/aggregate.d.ts +89 -0
  123. package/dist/matrix/aggregate.d.ts.map +1 -0
  124. package/dist/matrix/aggregate.js +186 -0
  125. package/dist/query/grammar.d.ts +35 -0
  126. package/dist/query/grammar.d.ts.map +1 -0
  127. package/dist/query/grammar.js +279 -0
  128. package/dist/query/run.d.ts +8 -0
  129. package/dist/query/run.d.ts.map +1 -0
  130. package/dist/query/run.js +21 -0
  131. package/dist/registry/build.d.ts +219 -0
  132. package/dist/registry/build.d.ts.map +1 -0
  133. package/dist/registry/build.js +313 -0
  134. package/dist/registry/cache-policy.d.ts +94 -0
  135. package/dist/registry/cache-policy.d.ts.map +1 -0
  136. package/dist/registry/cache-policy.js +238 -0
  137. package/dist/registry/call-notes.d.ts +11 -0
  138. package/dist/registry/call-notes.d.ts.map +1 -0
  139. package/dist/registry/call-notes.js +110 -0
  140. package/dist/registry/claims.d.ts +63 -0
  141. package/dist/registry/claims.d.ts.map +1 -0
  142. package/dist/registry/claims.js +107 -0
  143. package/dist/registry/effective-rate.d.ts +151 -0
  144. package/dist/registry/effective-rate.d.ts.map +1 -0
  145. package/dist/registry/effective-rate.js +156 -0
  146. package/dist/registry/facts.d.ts +32 -0
  147. package/dist/registry/facts.d.ts.map +1 -0
  148. package/dist/registry/facts.js +136 -0
  149. package/dist/registry/fingerprint.d.ts +20 -0
  150. package/dist/registry/fingerprint.d.ts.map +1 -0
  151. package/dist/registry/fingerprint.js +150 -0
  152. package/dist/registry/parity.d.ts +52 -0
  153. package/dist/registry/parity.d.ts.map +1 -0
  154. package/dist/registry/parity.js +82 -0
  155. package/dist/registry/pricing-shape.d.ts +113 -0
  156. package/dist/registry/pricing-shape.d.ts.map +1 -0
  157. package/dist/registry/pricing-shape.js +123 -0
  158. package/dist/registry/pricing.d.ts +43 -0
  159. package/dist/registry/pricing.d.ts.map +1 -0
  160. package/dist/registry/pricing.js +127 -0
  161. package/dist/registry/rows.d.ts +16 -0
  162. package/dist/registry/rows.d.ts.map +1 -0
  163. package/dist/registry/rows.js +57 -0
  164. package/dist/registry/seed.d.ts +43 -0
  165. package/dist/registry/seed.d.ts.map +1 -0
  166. package/dist/registry/seed.js +97 -0
  167. package/dist/registry/select.d.ts +68 -0
  168. package/dist/registry/select.d.ts.map +1 -0
  169. package/dist/registry/select.js +141 -0
  170. package/dist/registry/staleness.d.ts +18 -0
  171. package/dist/registry/staleness.d.ts.map +1 -0
  172. package/dist/registry/staleness.js +39 -0
  173. package/dist/rigindex/bootstrap.d.ts +36 -0
  174. package/dist/rigindex/bootstrap.d.ts.map +1 -0
  175. package/dist/rigindex/bootstrap.js +97 -0
  176. package/dist/rigindex/fit.d.ts +24 -0
  177. package/dist/rigindex/fit.d.ts.map +1 -0
  178. package/dist/rigindex/fit.js +76 -0
  179. package/dist/rigindex/gates.d.ts +52 -0
  180. package/dist/rigindex/gates.d.ts.map +1 -0
  181. package/dist/rigindex/gates.js +109 -0
  182. package/dist/rigindex/graph.d.ts +31 -0
  183. package/dist/rigindex/graph.d.ts.map +1 -0
  184. package/dist/rigindex/graph.js +120 -0
  185. package/dist/rigindex/index.d.ts +23 -0
  186. package/dist/rigindex/index.d.ts.map +1 -0
  187. package/dist/rigindex/index.js +112 -0
  188. package/dist/rigindex/types.d.ts +76 -0
  189. package/dist/rigindex/types.d.ts.map +1 -0
  190. package/dist/rigindex/types.js +8 -0
  191. package/dist/routes/cache-lint.d.ts +41 -0
  192. package/dist/routes/cache-lint.d.ts.map +1 -0
  193. package/dist/routes/cache-lint.js +81 -0
  194. package/dist/routes/draft.d.ts +83 -0
  195. package/dist/routes/draft.d.ts.map +1 -0
  196. package/dist/routes/draft.js +135 -0
  197. package/dist/routes/loader.d.ts +63 -0
  198. package/dist/routes/loader.d.ts.map +1 -0
  199. package/dist/routes/loader.js +574 -0
  200. package/dist/routes/manifest.d.ts +24 -0
  201. package/dist/routes/manifest.d.ts.map +1 -0
  202. package/dist/routes/manifest.js +118 -0
  203. package/dist/routes/resolved-bundle.d.ts +79 -0
  204. package/dist/routes/resolved-bundle.d.ts.map +1 -0
  205. package/dist/routes/resolved-bundle.js +148 -0
  206. package/dist/routes/sampling-config.d.ts +32 -0
  207. package/dist/routes/sampling-config.d.ts.map +1 -0
  208. package/dist/routes/sampling-config.js +91 -0
  209. package/dist/routes/serveability.d.ts +52 -0
  210. package/dist/routes/serveability.d.ts.map +1 -0
  211. package/dist/routes/serveability.js +73 -0
  212. package/dist/routes/template.d.ts +18 -0
  213. package/dist/routes/template.d.ts.map +1 -0
  214. package/dist/routes/template.js +94 -0
  215. package/dist/run/ajv.d.ts +22 -0
  216. package/dist/run/ajv.d.ts.map +1 -0
  217. package/dist/run/ajv.js +32 -0
  218. package/dist/run/cache-handle.d.ts +58 -0
  219. package/dist/run/cache-handle.d.ts.map +1 -0
  220. package/dist/run/cache-handle.js +54 -0
  221. package/dist/run/cache-stamp.d.ts +65 -0
  222. package/dist/run/cache-stamp.d.ts.map +1 -0
  223. package/dist/run/cache-stamp.js +0 -0
  224. package/dist/run/capture-write.d.ts +33 -0
  225. package/dist/run/capture-write.d.ts.map +1 -0
  226. package/dist/run/capture-write.js +55 -0
  227. package/dist/run/cost.d.ts +26 -0
  228. package/dist/run/cost.d.ts.map +1 -0
  229. package/dist/run/cost.js +41 -0
  230. package/dist/run/dispatch.d.ts +99 -0
  231. package/dist/run/dispatch.d.ts.map +1 -0
  232. package/dist/run/dispatch.js +191 -0
  233. package/dist/run/envelope.d.ts +21 -0
  234. package/dist/run/envelope.d.ts.map +1 -0
  235. package/dist/run/envelope.js +45 -0
  236. package/dist/run/grounding.d.ts +56 -0
  237. package/dist/run/grounding.d.ts.map +1 -0
  238. package/dist/run/grounding.js +89 -0
  239. package/dist/run/raw.d.ts +88 -0
  240. package/dist/run/raw.d.ts.map +1 -0
  241. package/dist/run/raw.js +286 -0
  242. package/dist/run/record-attempt.d.ts +40 -0
  243. package/dist/run/record-attempt.d.ts.map +1 -0
  244. package/dist/run/record-attempt.js +99 -0
  245. package/dist/run/repair.d.ts +36 -0
  246. package/dist/run/repair.d.ts.map +1 -0
  247. package/dist/run/repair.js +61 -0
  248. package/dist/run/resolve.d.ts +99 -0
  249. package/dist/run/resolve.d.ts.map +1 -0
  250. package/dist/run/resolve.js +203 -0
  251. package/dist/run/retry.d.ts +19 -0
  252. package/dist/run/retry.d.ts.map +1 -0
  253. package/dist/run/retry.js +50 -0
  254. package/dist/run/run.d.ts +55 -0
  255. package/dist/run/run.d.ts.map +1 -0
  256. package/dist/run/run.js +540 -0
  257. package/dist/run/stream.d.ts +49 -0
  258. package/dist/run/stream.d.ts.map +1 -0
  259. package/dist/run/stream.js +87 -0
  260. package/dist/run/validate.d.ts +15 -0
  261. package/dist/run/validate.d.ts.map +1 -0
  262. package/dist/run/validate.js +55 -0
  263. package/dist/savings/cache-ledger.d.ts +108 -0
  264. package/dist/savings/cache-ledger.d.ts.map +1 -0
  265. package/dist/savings/cache-ledger.js +174 -0
  266. package/dist/savings/cache-reconcile.d.ts +64 -0
  267. package/dist/savings/cache-reconcile.d.ts.map +1 -0
  268. package/dist/savings/cache-reconcile.js +59 -0
  269. package/dist/savings/cache-stats.d.ts +63 -0
  270. package/dist/savings/cache-stats.d.ts.map +1 -0
  271. package/dist/savings/cache-stats.js +108 -0
  272. package/dist/savings/emit.d.ts +38 -0
  273. package/dist/savings/emit.d.ts.map +1 -0
  274. package/dist/savings/emit.js +100 -0
  275. package/dist/savings/odometer.d.ts +32 -0
  276. package/dist/savings/odometer.d.ts.map +1 -0
  277. package/dist/savings/odometer.js +70 -0
  278. package/dist/savings/swap-execute.d.ts +58 -0
  279. package/dist/savings/swap-execute.d.ts.map +1 -0
  280. package/dist/savings/swap-execute.js +130 -0
  281. package/dist/savings/swaps-client.d.ts +55 -0
  282. package/dist/savings/swaps-client.d.ts.map +1 -0
  283. package/dist/savings/swaps-client.js +95 -0
  284. package/dist/settings/api-fetcher.d.ts +39 -0
  285. package/dist/settings/api-fetcher.d.ts.map +1 -0
  286. package/dist/settings/api-fetcher.js +92 -0
  287. package/dist/settings/index.d.ts +10 -0
  288. package/dist/settings/index.d.ts.map +1 -0
  289. package/dist/settings/index.js +15 -0
  290. package/dist/settings/task-settings.d.ts +91 -0
  291. package/dist/settings/task-settings.d.ts.map +1 -0
  292. package/dist/settings/task-settings.js +116 -0
  293. package/dist/status.d.ts +77 -0
  294. package/dist/status.d.ts.map +1 -0
  295. package/dist/status.js +113 -0
  296. package/dist/telemetry/artifact-store.d.ts +48 -0
  297. package/dist/telemetry/artifact-store.d.ts.map +1 -0
  298. package/dist/telemetry/artifact-store.js +189 -0
  299. package/dist/telemetry/cache-miss-streak.d.ts +79 -0
  300. package/dist/telemetry/cache-miss-streak.d.ts.map +1 -0
  301. package/dist/telemetry/cache-miss-streak.js +99 -0
  302. package/dist/telemetry/capture.d.ts +31 -0
  303. package/dist/telemetry/capture.d.ts.map +1 -0
  304. package/dist/telemetry/capture.js +81 -0
  305. package/dist/telemetry/exporter-setup.d.ts +28 -0
  306. package/dist/telemetry/exporter-setup.d.ts.map +1 -0
  307. package/dist/telemetry/exporter-setup.js +34 -0
  308. package/dist/telemetry/exporter.d.ts +137 -0
  309. package/dist/telemetry/exporter.d.ts.map +1 -0
  310. package/dist/telemetry/exporter.js +510 -0
  311. package/dist/telemetry/health.d.ts +76 -0
  312. package/dist/telemetry/health.d.ts.map +1 -0
  313. package/dist/telemetry/health.js +92 -0
  314. package/dist/telemetry/ingest-protocol.d.ts +310 -0
  315. package/dist/telemetry/ingest-protocol.d.ts.map +1 -0
  316. package/dist/telemetry/ingest-protocol.js +363 -0
  317. package/dist/telemetry/load-error-report.d.ts +24 -0
  318. package/dist/telemetry/load-error-report.d.ts.map +1 -0
  319. package/dist/telemetry/load-error-report.js +50 -0
  320. package/dist/telemetry/otel-map.d.ts +121 -0
  321. package/dist/telemetry/otel-map.d.ts.map +1 -0
  322. package/dist/telemetry/otel-map.js +224 -0
  323. package/dist/telemetry/otel-normalize.d.ts +104 -0
  324. package/dist/telemetry/otel-normalize.d.ts.map +1 -0
  325. package/dist/telemetry/otel-normalize.js +530 -0
  326. package/dist/telemetry/otlp-emitter.d.ts +52 -0
  327. package/dist/telemetry/otlp-emitter.d.ts.map +1 -0
  328. package/dist/telemetry/otlp-emitter.js +144 -0
  329. package/dist/telemetry/otlp-proto.d.ts +29 -0
  330. package/dist/telemetry/otlp-proto.d.ts.map +1 -0
  331. package/dist/telemetry/otlp-proto.js +266 -0
  332. package/dist/telemetry/sinks.d.ts +90 -0
  333. package/dist/telemetry/sinks.d.ts.map +1 -0
  334. package/dist/telemetry/sinks.js +180 -0
  335. package/dist/telemetry/store.d.ts +65 -0
  336. package/dist/telemetry/store.d.ts.map +1 -0
  337. package/dist/telemetry/store.js +547 -0
  338. package/dist/tenancy/api-key-format.d.ts +77 -0
  339. package/dist/tenancy/api-key-format.d.ts.map +1 -0
  340. package/dist/tenancy/api-key-format.js +110 -0
  341. package/dist/tenancy/constants.d.ts +23 -0
  342. package/dist/tenancy/constants.d.ts.map +1 -0
  343. package/dist/tenancy/constants.js +25 -0
  344. package/dist/tenancy/scrub.d.ts +47 -0
  345. package/dist/tenancy/scrub.d.ts.map +1 -0
  346. package/dist/tenancy/scrub.js +85 -0
  347. package/dist/types/config-teaching.d.ts +62 -0
  348. package/dist/types/config-teaching.d.ts.map +1 -0
  349. package/dist/types/config-teaching.js +183 -0
  350. package/dist/types/failures-teaching.d.ts +56 -0
  351. package/dist/types/failures-teaching.d.ts.map +1 -0
  352. package/dist/types/failures-teaching.js +177 -0
  353. package/dist/types/failures.d.ts +27 -0
  354. package/dist/types/failures.d.ts.map +1 -0
  355. package/dist/types/failures.js +41 -0
  356. package/dist/types/provider.d.ts +200 -0
  357. package/dist/types/provider.d.ts.map +1 -0
  358. package/dist/types/provider.js +40 -0
  359. package/dist/types/route.d.ts +205 -0
  360. package/dist/types/route.d.ts.map +1 -0
  361. package/dist/types/route.js +6 -0
  362. package/dist/types/telemetry.d.ts +206 -0
  363. package/dist/types/telemetry.d.ts.map +1 -0
  364. package/dist/types/telemetry.js +6 -0
  365. package/dist/validate-cli.d.ts +12 -0
  366. package/dist/validate-cli.d.ts.map +1 -0
  367. package/dist/validate-cli.js +57 -0
  368. package/dist/verify/capture.d.ts +66 -0
  369. package/dist/verify/capture.d.ts.map +1 -0
  370. package/dist/verify/capture.js +180 -0
  371. package/dist/verify/cli-run.d.ts +23 -0
  372. package/dist/verify/cli-run.d.ts.map +1 -0
  373. package/dist/verify/cli-run.js +57 -0
  374. package/dist/verify/diff.d.ts +48 -0
  375. package/dist/verify/diff.d.ts.map +1 -0
  376. package/dist/verify/diff.js +157 -0
  377. package/dist/verify/index.d.ts +17 -0
  378. package/dist/verify/index.d.ts.map +1 -0
  379. package/dist/verify/index.js +24 -0
  380. package/dist/verify/report.d.ts +14 -0
  381. package/dist/verify/report.d.ts.map +1 -0
  382. package/dist/verify/report.js +88 -0
  383. package/dist/verify/types.d.ts +101 -0
  384. package/dist/verify/types.d.ts.map +1 -0
  385. package/dist/verify/types.js +17 -0
  386. package/dist/verify/verify.d.ts +29 -0
  387. package/dist/verify/verify.d.ts.map +1 -0
  388. package/dist/verify/verify.js +148 -0
  389. package/dist/watch/budget.d.ts +19 -0
  390. package/dist/watch/budget.d.ts.map +1 -0
  391. package/dist/watch/budget.js +35 -0
  392. package/dist/watch/evaluate.d.ts +225 -0
  393. package/dist/watch/evaluate.d.ts.map +1 -0
  394. package/dist/watch/evaluate.js +155 -0
  395. package/dist/watch/monitor.d.ts +116 -0
  396. package/dist/watch/monitor.d.ts.map +1 -0
  397. package/dist/watch/monitor.js +199 -0
  398. package/dist/watch/proposals.d.ts +89 -0
  399. package/dist/watch/proposals.d.ts.map +1 -0
  400. package/dist/watch/proposals.js +197 -0
  401. package/dist/watch/run-record.d.ts +64 -0
  402. package/dist/watch/run-record.d.ts.map +1 -0
  403. package/dist/watch/run-record.js +86 -0
  404. package/dist/watch/run-reported.d.ts +20 -0
  405. package/dist/watch/run-reported.d.ts.map +1 -0
  406. package/dist/watch/run-reported.js +53 -0
  407. package/dist/watch/run.d.ts +73 -0
  408. package/dist/watch/run.d.ts.map +1 -0
  409. package/dist/watch/run.js +83 -0
  410. package/dist/watch/state-store.d.ts +48 -0
  411. package/dist/watch/state-store.d.ts.map +1 -0
  412. package/dist/watch/state-store.js +86 -0
  413. package/dist/watch/state.d.ts +21 -0
  414. package/dist/watch/state.d.ts.map +1 -0
  415. package/dist/watch/state.js +93 -0
  416. package/package.json +56 -14
  417. package/registry/LICENSE +20 -0
  418. package/registry/leaderboard.json +3639 -0
  419. package/registry/registry.json +7263 -0
  420. package/index.js +0 -3
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ /**
3
+ * Managed content upload path — E2-C chunk A (spec §2.4).
4
+ *
5
+ * When a rig has opted a route into content custody, `save` records the metadata
6
+ * row (as always) and THEN hands the serialized bytes here. This module talks to
7
+ * modelrig-server's grant endpoint, receives a short-lived presigned PUT, and
8
+ * uploads the bytes straight to the object store — the bytes NEVER touch our
9
+ * control-plane database, only the customer-designated store.
10
+ *
11
+ * ── THE POISON LESSON, APPLIED ────────────────────────────────────────────
12
+ * A deterministic refusal (403 posture-off, 409 already has content, 413 too
13
+ * big, 422 malformed) is NOT retried — it will fail identically forever, and
14
+ * retrying a poison request is how a fail-closed refusal turns into a hot loop.
15
+ * Every refusal DEGRADES to metadata-only: the artifact still exists (its row
16
+ * was written before we were called), it simply has no stored content.
17
+ * Degradation is counted and warned, never thrown — this runs off the
18
+ * customer's hot path and must never surface as a failed run.
19
+ *
20
+ * ── THE 404-UNTIL-DURABLE RACE (E4 chunk 0, flag 2) ───────────────────────
21
+ * A 404 is the ONE 4xx that is NOT deterministic. The grant endpoint verifies
22
+ * the artifact metadata row exists (and belongs to the org — T11) before
23
+ * issuing a URL, but that row reaches the control plane on the exporter's NEXT
24
+ * flush — so a content upload fired during `save` races ahead of its own
25
+ * metadata and 404s until the row lands. TRANSIENT by nature: it clears once
26
+ * the metadata is durable. So a 404 returns a distinct `pending` outcome that
27
+ * the exporter's post-flush hook re-attempts (bounded: 2 retries, then a
28
+ * counted skip). A genuinely foreign/missing artifact 404s the same way and
29
+ * simply exhausts those retries into the metadata-only end state — delayed, but
30
+ * never a hot loop.
31
+ *
32
+ * ── C2 ────────────────────────────────────────────────────────────────────
33
+ * The api key rides in an Authorization header, never a URL. The presigned URL
34
+ * and the content hash are NEVER logged. Warnings name the artifact + a status,
35
+ * nothing else.
36
+ */
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.uploadArtifactContent = uploadArtifactContent;
39
+ /** A 4xx is a deterministic refusal — the request will fail identically forever,
40
+ * so it must never be retried (the poison lesson) — with ONE exception: 404,
41
+ * the metadata-not-yet-durable race, handled separately as `pending`. */
42
+ function isDeterministicRefusal(status) {
43
+ return status >= 400 && status < 500;
44
+ }
45
+ /**
46
+ * Upload one artifact's content. NEVER throws — every failure resolves to a
47
+ * `degraded` outcome the caller records as a metadata-only skip.
48
+ */
49
+ async function uploadArtifactContent(input, config, fetchFn = fetch) {
50
+ // Client-side ceiling short-circuit: the server would 413 this; skip the trip.
51
+ if (input.body.byteLength > config.maxBytes) {
52
+ return {
53
+ kind: "degraded",
54
+ reason: `content is ${input.body.byteLength} bytes, over the ${config.maxBytes} ceiling`,
55
+ status: 413,
56
+ };
57
+ }
58
+ // 1) Request the grant. A 4xx is deterministic → degrade, no retry.
59
+ let grantRes;
60
+ try {
61
+ grantRes = await fetchFn(config.uploadsUrl, {
62
+ method: "POST",
63
+ headers: {
64
+ "content-type": "application/json",
65
+ authorization: `Bearer ${config.apiKey}`,
66
+ },
67
+ body: JSON.stringify({
68
+ artifact_id: input.artifactId,
69
+ content_type: input.contentType,
70
+ bytes: input.body.byteLength,
71
+ content_hash: input.contentHash,
72
+ }),
73
+ });
74
+ }
75
+ catch (err) {
76
+ // Transient (network) — degrade without retry this pass; the next save's
77
+ // upload is an independent attempt. We do NOT loop here.
78
+ return { kind: "degraded", reason: `grant request failed: ${errMsg(err)}`, status: null };
79
+ }
80
+ if (!grantRes.ok) {
81
+ // 404 is the metadata-not-yet-durable race (T11), the ONE transient 4xx: the
82
+ // row reaches the control plane on the exporter's next flush, so we hand back
83
+ // `pending` for the post-flush hook to re-attempt (bounded). Every other 4xx
84
+ // is a deterministic refusal and 5xx a server error — both degrade here, no
85
+ // retry this pass. The distinction is only in the reason we log.
86
+ if (grantRes.status === 404) {
87
+ return { kind: "pending", reason: "artifact metadata not yet durable (grant 404)", status: 404 };
88
+ }
89
+ const kind = isDeterministicRefusal(grantRes.status) ? "refused" : "unavailable";
90
+ return { kind: "degraded", reason: `grant ${kind} (status ${grantRes.status})`, status: grantRes.status };
91
+ }
92
+ let grant;
93
+ try {
94
+ grant = (await grantRes.json());
95
+ }
96
+ catch {
97
+ return { kind: "degraded", reason: "grant response was not JSON", status: grantRes.status };
98
+ }
99
+ if (typeof grant.upload_url !== "string" || typeof grant.content_ref !== "string") {
100
+ return { kind: "degraded", reason: "grant response missing upload_url/content_ref", status: grantRes.status };
101
+ }
102
+ const putHeaders = isStringRecord(grant.headers) ? grant.headers : {};
103
+ // 2) PUT the bytes straight to the store. Non-2xx or network → degrade.
104
+ let putRes;
105
+ try {
106
+ putRes = await fetchFn(grant.upload_url, { method: "PUT", headers: putHeaders, body: input.body });
107
+ }
108
+ catch (err) {
109
+ return { kind: "degraded", reason: `content PUT failed: ${errMsg(err)}`, status: null };
110
+ }
111
+ if (!putRes.ok) {
112
+ return { kind: "degraded", reason: `content PUT rejected (status ${putRes.status})`, status: putRes.status };
113
+ }
114
+ return { kind: "uploaded", contentRef: grant.content_ref };
115
+ }
116
+ function errMsg(err) {
117
+ return err instanceof Error ? err.message : String(err);
118
+ }
119
+ function isStringRecord(v) {
120
+ return (typeof v === "object" &&
121
+ v !== null &&
122
+ !Array.isArray(v) &&
123
+ Object.values(v).every((x) => typeof x === "string"));
124
+ }
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Artifact / execution-graph namespace (Expansion E2) — the public barrel.
3
+ *
4
+ * Lives here (not spread through `index.ts`) so the SDK entrypoint stays under
5
+ * the LOC cap and the run/artifact surface has one home. Chunk A ships the run
6
+ * lifecycle + `@step`; chunk B adds the artifact primitives (save/load/evaluate).
7
+ */
8
+ import type { ArtifactBuffer, RunNamespace } from "./run-context";
9
+ import type { ArtifactApi, ArtifactContentDeps } from "./artifact";
10
+ import type { ArtifactContentConfig, ArtifactsConfig } from "../config";
11
+ import type { ArtifactStore } from "../telemetry/artifact-store";
12
+ export { getActiveRunContext, createRunNamespace } from "./run-context";
13
+ export type { RunNamespace, RunHandle, RunStartOptions, RunEvaluateOptions, RunStatus, ActiveRunContext, ArtifactBuffer, GroundTruthStepInput, } from "./run-context";
14
+ export { step } from "./step";
15
+ export { createArtifactApi } from "./artifact";
16
+ export { openArtifactStore } from "../telemetry/artifact-store";
17
+ export type { ArtifactStore } from "../telemetry/artifact-store";
18
+ export type { ArtifactApi, ArtifactHandle, ArtifactSaveOptions, ArtifactEvaluateOptions, ArtifactPromoteOptions, ArtifactContentDeps, ArtifactContentUploader, } from "./artifact";
19
+ export { uploadArtifactContent } from "./content-uploader";
20
+ export type { ContentUploadConfig, ContentUploadInput, ContentUploadOutcome, } from "./content-uploader";
21
+ export { scrubContent, luhnValid } from "./scrub";
22
+ export type { ScrubMode, ScrubFinding, ScrubResult, ScrubDetectorType } from "./scrub";
23
+ export { computeDownstreamClosure, TAINT_DEFAULT_MAX_DEPTH, TAINT_DEFAULT_CAP, } from "./taint";
24
+ export type { TaintEdge, Supersession, TaintNode, TaintClosure, TaintOptions, } from "./taint";
25
+ export type { RunRow, StepRow, ArtifactRow, ArtifactEdgeRow, ArtifactEvaluationRow, EvalCaseRow, EvalCaseOrigin, } from "../types/telemetry";
26
+ /** The rig-bound artifact surface exposed as `rig.artifacts`: the run lifecycle
27
+ * (chunk A) + the artifact primitives (chunk B). */
28
+ export interface ArtifactNamespace {
29
+ readonly run: RunNamespace;
30
+ readonly artifact: ArtifactApi;
31
+ }
32
+ /** Build the rig-bound artifact namespace AND the exporter's post-flush retry
33
+ * hook from resolved config (E4 chunk 0, flag 2). Lives here so the SDK
34
+ * entrypoint stays under the LOC cap. The hook is present only when content
35
+ * custody is configured; otherwise it would be a no-op. */
36
+ export declare function wireRigArtifacts(deps: {
37
+ readonly buffer: ArtifactBuffer;
38
+ readonly enabled: boolean;
39
+ readonly artifactStore: ArtifactStore | null;
40
+ readonly artifacts?: ArtifactsConfig;
41
+ }): {
42
+ readonly namespace: ArtifactNamespace;
43
+ readonly onArtifactsFlushed?: () => Promise<void>;
44
+ };
45
+ /**
46
+ * Build the content-custody deps (E2-C) from resolved config, or undefined when
47
+ * custody is off. Kept here (not in the SDK entrypoint) so index.ts stays under
48
+ * the LOC cap (P1) and the content wiring lives beside the namespace it feeds.
49
+ */
50
+ export declare function buildArtifactContentDeps(content: ArtifactContentConfig | undefined): ArtifactContentDeps | undefined;
51
+ /** Build the rig-bound artifact namespace. Disabled ⇒ every entry is inert
52
+ * (run.start is a no-op, save returns null, no rows written) — spec §1.4. The
53
+ * artifact store is present only when enabled (index.ts opens it then). */
54
+ export declare function createArtifactNamespace(deps: {
55
+ readonly buffer: ArtifactBuffer;
56
+ readonly artifactStore?: ArtifactStore;
57
+ readonly enabled: boolean;
58
+ /** Content-custody config (E2-C). Absent = metadata + hash only; the upload
59
+ * deps are built here (buildArtifactContentDeps) so the SDK entrypoint stays
60
+ * under the LOC cap. */
61
+ readonly content?: ArtifactContentConfig;
62
+ }): ArtifactNamespace;
63
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/artifacts/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElE,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAGnE,OAAO,KAAK,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACxE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAEjE,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACxE,YAAY,EACV,YAAY,EACZ,SAAS,EACT,eAAe,EACf,kBAAkB,EAClB,SAAS,EACT,gBAAgB,EAChB,cAAc,EACd,oBAAoB,GACrB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,YAAY,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACjE,YAAY,EACV,WAAW,EACX,cAAc,EACd,mBAAmB,EACnB,uBAAuB,EACvB,sBAAsB,EACtB,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,YAAY,EACV,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAClD,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AACvF,OAAO,EACL,wBAAwB,EACxB,uBAAuB,EACvB,iBAAiB,GAClB,MAAM,SAAS,CAAC;AACjB,YAAY,EACV,SAAS,EACT,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,YAAY,GACb,MAAM,SAAS,CAAC;AACjB,YAAY,EACV,MAAM,EACN,OAAO,EACP,WAAW,EACX,eAAe,EACf,qBAAqB,EACrB,WAAW,EACX,cAAc,GACf,MAAM,oBAAoB,CAAC;AAE5B;oDACoD;AACpD,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,GAAG,EAAE,YAAY,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;CAChC;AAED;;;2DAG2D;AAC3D,wBAAgB,gBAAgB,CAAC,IAAI,EAAE;IACrC,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,aAAa,EAAE,aAAa,GAAG,IAAI,CAAC;IAC7C,QAAQ,CAAC,SAAS,CAAC,EAAE,eAAe,CAAC;CACtC,GAAG;IAAE,QAAQ,CAAC,SAAS,EAAE,iBAAiB,CAAC;IAAC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,CAY/F;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,qBAAqB,GAAG,SAAS,GACzC,mBAAmB,GAAG,SAAS,CAWjC;AAED;;2EAE2E;AAC3E,wBAAgB,uBAAuB,CAAC,IAAI,EAAE;IAC5C,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAChC,QAAQ,CAAC,aAAa,CAAC,EAAE,aAAa,CAAC;IACvC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B;;4BAEwB;IACxB,QAAQ,CAAC,OAAO,CAAC,EAAE,qBAAqB,CAAC;CAC1C,GAAG,iBAAiB,CAYpB"}
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ /**
3
+ * Artifact / execution-graph namespace (Expansion E2) — the public barrel.
4
+ *
5
+ * Lives here (not spread through `index.ts`) so the SDK entrypoint stays under
6
+ * the LOC cap and the run/artifact surface has one home. Chunk A ships the run
7
+ * lifecycle + `@step`; chunk B adds the artifact primitives (save/load/evaluate).
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.TAINT_DEFAULT_CAP = exports.TAINT_DEFAULT_MAX_DEPTH = exports.computeDownstreamClosure = exports.luhnValid = exports.scrubContent = exports.uploadArtifactContent = exports.openArtifactStore = exports.createArtifactApi = exports.step = exports.createRunNamespace = exports.getActiveRunContext = void 0;
11
+ exports.wireRigArtifacts = wireRigArtifacts;
12
+ exports.buildArtifactContentDeps = buildArtifactContentDeps;
13
+ exports.createArtifactNamespace = createArtifactNamespace;
14
+ const run_context_1 = require("./run-context");
15
+ const artifact_1 = require("./artifact");
16
+ const content_uploader_1 = require("./content-uploader");
17
+ var run_context_2 = require("./run-context");
18
+ Object.defineProperty(exports, "getActiveRunContext", { enumerable: true, get: function () { return run_context_2.getActiveRunContext; } });
19
+ Object.defineProperty(exports, "createRunNamespace", { enumerable: true, get: function () { return run_context_2.createRunNamespace; } });
20
+ var step_1 = require("./step");
21
+ Object.defineProperty(exports, "step", { enumerable: true, get: function () { return step_1.step; } });
22
+ var artifact_2 = require("./artifact");
23
+ Object.defineProperty(exports, "createArtifactApi", { enumerable: true, get: function () { return artifact_2.createArtifactApi; } });
24
+ var artifact_store_1 = require("../telemetry/artifact-store");
25
+ Object.defineProperty(exports, "openArtifactStore", { enumerable: true, get: function () { return artifact_store_1.openArtifactStore; } });
26
+ var content_uploader_2 = require("./content-uploader");
27
+ Object.defineProperty(exports, "uploadArtifactContent", { enumerable: true, get: function () { return content_uploader_2.uploadArtifactContent; } });
28
+ var scrub_1 = require("./scrub");
29
+ Object.defineProperty(exports, "scrubContent", { enumerable: true, get: function () { return scrub_1.scrubContent; } });
30
+ Object.defineProperty(exports, "luhnValid", { enumerable: true, get: function () { return scrub_1.luhnValid; } });
31
+ var taint_1 = require("./taint");
32
+ Object.defineProperty(exports, "computeDownstreamClosure", { enumerable: true, get: function () { return taint_1.computeDownstreamClosure; } });
33
+ Object.defineProperty(exports, "TAINT_DEFAULT_MAX_DEPTH", { enumerable: true, get: function () { return taint_1.TAINT_DEFAULT_MAX_DEPTH; } });
34
+ Object.defineProperty(exports, "TAINT_DEFAULT_CAP", { enumerable: true, get: function () { return taint_1.TAINT_DEFAULT_CAP; } });
35
+ /** Build the rig-bound artifact namespace AND the exporter's post-flush retry
36
+ * hook from resolved config (E4 chunk 0, flag 2). Lives here so the SDK
37
+ * entrypoint stays under the LOC cap. The hook is present only when content
38
+ * custody is configured; otherwise it would be a no-op. */
39
+ function wireRigArtifacts(deps) {
40
+ const namespace = createArtifactNamespace({
41
+ buffer: deps.buffer,
42
+ enabled: deps.enabled,
43
+ ...(deps.artifactStore !== null ? { artifactStore: deps.artifactStore } : {}),
44
+ ...(deps.artifacts?.content !== undefined ? { content: deps.artifacts.content } : {}),
45
+ });
46
+ const hookOn = deps.enabled && deps.artifacts?.content !== undefined;
47
+ return {
48
+ namespace,
49
+ ...(hookOn ? { onArtifactsFlushed: () => namespace.artifact.retryPendingContent() } : {}),
50
+ };
51
+ }
52
+ /**
53
+ * Build the content-custody deps (E2-C) from resolved config, or undefined when
54
+ * custody is off. Kept here (not in the SDK entrypoint) so index.ts stays under
55
+ * the LOC cap (P1) and the content wiring lives beside the namespace it feeds.
56
+ */
57
+ function buildArtifactContentDeps(content) {
58
+ if (content === undefined)
59
+ return undefined;
60
+ return {
61
+ scrub: content.scrub,
62
+ upload: (input) => (0, content_uploader_1.uploadArtifactContent)(input, { uploadsUrl: content.uploadsUrl, apiKey: content.apiKey, maxBytes: content.maxBytes }, fetch),
63
+ };
64
+ }
65
+ /** Build the rig-bound artifact namespace. Disabled ⇒ every entry is inert
66
+ * (run.start is a no-op, save returns null, no rows written) — spec §1.4. The
67
+ * artifact store is present only when enabled (index.ts opens it then). */
68
+ function createArtifactNamespace(deps) {
69
+ const contentDeps = deps.enabled ? buildArtifactContentDeps(deps.content) : undefined;
70
+ return {
71
+ run: (0, run_context_1.createRunNamespace)(deps),
72
+ artifact: (0, artifact_1.createArtifactApi)({
73
+ // A disabled namespace never opens a store; createArtifactApi(enabled:false)
74
+ // ignores the store and returns an inert api, so the cast is never reached.
75
+ store: deps.artifactStore,
76
+ enabled: deps.enabled && deps.artifactStore !== undefined,
77
+ ...(contentDeps !== undefined ? { content: contentDeps } : {}),
78
+ }),
79
+ };
80
+ }
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Run context — Expansion E2 chunk A (spec §1.4, §9).
3
+ *
4
+ * A RUN is one execution of a customer pipeline; instrumentation hangs off an
5
+ * ambient run context held in an `AsyncLocalStorage` (a Node builtin — NO new
6
+ * npm dependency). `run.start()` mints the context and `run.end()` closes it;
7
+ * everything that happens in between — `rig.run()` auto-steps, `@step` scopes,
8
+ * and (chunk B) artifact save/load lineage — reads the SAME ambient context.
9
+ *
10
+ * ── FAIL-OPEN, ALWAYS ─────────────────────────────────────────────────────
11
+ * Instrumentation NEVER changes return values and NEVER throws into customer
12
+ * code (the exporter's swallow-and-log doctrine, extended). A telemetry-buffer
13
+ * write that fails is logged and dropped; the customer's pipeline is untouched.
14
+ *
15
+ * ── GATING ────────────────────────────────────────────────────────────────
16
+ * The namespace is inert unless the rig enabled it (`MODELRIG_ARTIFACTS=1`).
17
+ * A disabled namespace's `run.start()` sets NO context, so `getActiveRunContext`
18
+ * returns null everywhere and the run loop's auto-step is never reached —
19
+ * v1 wire, zero new rows, zero behaviour change (spec §1.4).
20
+ */
21
+ import type { ArtifactEvaluationRow, RunRow, StepRow } from "../types/telemetry";
22
+ /** The narrow buffer the run/artifact namespace writes through — the local
23
+ * telemetry store satisfies it. Kept narrow so this module depends on the row
24
+ * shapes, not the whole store surface (and cannot reach captures). */
25
+ export interface ArtifactBuffer {
26
+ recordRun(row: RunRow): void;
27
+ recordStep(row: StepRow): void;
28
+ }
29
+ export type RunStatus = RunRow["status"];
30
+ export interface RunStartOptions {
31
+ /** Customer's pipeline name — the run's semantic identity. */
32
+ readonly pipeline: string;
33
+ readonly pipelineVersion?: string;
34
+ readonly environment?: string;
35
+ /** Bridges feedback.episode_key (run-level verdicts). Optional. */
36
+ readonly episodeKey?: string;
37
+ /** W3C traceparent for cross-service correlation (spec §1.4). When present the
38
+ * run adopts its trace id, so artifacts crossing a service boundary (chunk B)
39
+ * can be tied back to this run. Never changes the (uuid) run id. */
40
+ readonly traceparent?: string;
41
+ /** Zero-retention run (chunk B, ratified invariant): NO artifact rows of any
42
+ * kind are emitted — artifact.save refuses fail-closed at the SDK gate with a
43
+ * counted, logged skip. Set by the caller or derived from a route's
44
+ * `require: zero_retention`. */
45
+ readonly zeroRetention?: boolean;
46
+ }
47
+ /** One ground-truth step attempt the run loop asks the context to record. The
48
+ * context assigns `attempt_no` per step key so the caller need not track it. */
49
+ export interface GroundTruthStepInput {
50
+ readonly stepKey: string;
51
+ readonly task: string | null;
52
+ readonly inferenceId: string;
53
+ readonly startedAt: string;
54
+ readonly endedAt: string;
55
+ readonly failureClass: string | null;
56
+ }
57
+ export interface ActiveRunContext {
58
+ readonly runId: string;
59
+ /** Trace id adopted from a traceparent at run.start, if any (chunk B use). */
60
+ readonly traceId: string | null;
61
+ /** Zero-retention gate (chunk B): true ⇒ artifact.save refuses fail-closed. */
62
+ readonly zeroRetention: boolean;
63
+ /** Record that an artifact was loaded in the current run (chunk B lineage). */
64
+ noteLoad(artifactId: string): void;
65
+ /** Return AND clear the loaded-artifact ids — the set a subsequent save
66
+ * derives `derived_from` edges to (loads "consumed" by that save). v0
67
+ * lineage: run-scoped, cleared on each save; coverage measured, never promised. */
68
+ takeLoadedIds(): string[];
69
+ /** Mint a unique step key for ONE rig.run()/@step invocation. Retries of that
70
+ * invocation reuse the returned key (attempt_no distinguishes them); a later
71
+ * invocation gets a fresh key, so two calls never collapse into one step. */
72
+ nextStepKey(label: string): string;
73
+ /** Record one ground-truth step attempt (the rig.run auto-step). attempt_no is
74
+ * assigned here, per step key. Fail-open — a buffer error is logged, dropped,
75
+ * and never thrown into the run loop. */
76
+ emitGroundTruthStep(input: GroundTruthStepInput): void;
77
+ }
78
+ /** The active run context, or null when none is set (namespace disabled, or no
79
+ * run.start on this async path). Read by the run loop's auto-step seam. */
80
+ export declare function getActiveRunContext(): ActiveRunContext | null;
81
+ /** A run-level evaluation the caller attaches (E5 chunk V.2) — the run-subject
82
+ * mirror of ArtifactEvaluateOptions. The subject is the run, so there is no ref. */
83
+ export interface RunEvaluateOptions {
84
+ readonly evaluator: string;
85
+ readonly kind: "deterministic" | "model-judge" | "human";
86
+ readonly score?: number;
87
+ readonly passed?: boolean;
88
+ readonly label?: string;
89
+ readonly explanation?: string;
90
+ }
91
+ /** A handle a caller holds to end a run it started. */
92
+ export interface RunHandle {
93
+ readonly runId: string;
94
+ end(status?: RunStatus): void;
95
+ /** Attach a run-level evaluation to THIS run (E5 V.2). Works after end() —
96
+ * verdicts are often post-hoc. Fail-open + inert when the namespace is off. */
97
+ evaluate(opts: RunEvaluateOptions): void;
98
+ }
99
+ /** The `run` namespace, bound to one rig's buffer + gate. Disabled ⇒ inert. */
100
+ export interface RunNamespace {
101
+ /** Begin a run via the imperative handle API. Uses `AsyncLocalStorage.enterWith`,
102
+ * which has NO lexical exit — safe for one run at a time on a request/async
103
+ * path, but CONCURRENT overlapping `start()` calls (e.g. `Promise.all` over
104
+ * items) clobber each other's ambient context and cross-attribute steps.
105
+ * For concurrent runs use `scope()`. Disabled ⇒ no-op inert handle. */
106
+ start(opts: RunStartOptions): RunHandle;
107
+ /** End the active run with a terminal status (default "succeeded"). */
108
+ end(status?: RunStatus): void;
109
+ /** Attach a run-level evaluation to the ACTIVE run (E5 V.2) — the run-subject
110
+ * mirror of `artifact.evaluate`. No active run ⇒ a warned no-op (fail-open). */
111
+ evaluate(opts: RunEvaluateOptions): void;
112
+ /** Concurrency-safe run scope. Runs `fn` inside `AsyncLocalStorage.run`, so
113
+ * overlapping `scope()` calls each keep their OWN ambient run context — the
114
+ * correct primitive for `Promise.all` over items. Ends the run "succeeded" on
115
+ * return, "failed" if `fn` throws (then rethrows). Disabled ⇒ runs `fn` with
116
+ * no context. */
117
+ scope<T>(opts: RunStartOptions, fn: () => Promise<T>): Promise<T>;
118
+ }
119
+ export declare function createRunNamespace(deps: {
120
+ readonly buffer: ArtifactBuffer;
121
+ readonly enabled: boolean;
122
+ /** The evaluation writer (E5 V.2) — the artifact store's recordArtifactEvaluation.
123
+ * Absent (disabled / no store) ⇒ run.evaluate is inert. Kept OFF the narrow
124
+ * ArtifactBuffer so that contract stays "cannot reach anything but run/step". */
125
+ readonly artifactStore?: {
126
+ recordArtifactEvaluation(row: ArtifactEvaluationRow): void;
127
+ };
128
+ }): RunNamespace;
129
+ //# sourceMappingURL=run-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-context.d.ts","sourceRoot":"","sources":["../../src/artifacts/run-context.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,208 @@
1
+ "use strict";
2
+ /**
3
+ * Run context — Expansion E2 chunk A (spec §1.4, §9).
4
+ *
5
+ * A RUN is one execution of a customer pipeline; instrumentation hangs off an
6
+ * ambient run context held in an `AsyncLocalStorage` (a Node builtin — NO new
7
+ * npm dependency). `run.start()` mints the context and `run.end()` closes it;
8
+ * everything that happens in between — `rig.run()` auto-steps, `@step` scopes,
9
+ * and (chunk B) artifact save/load lineage — reads the SAME ambient context.
10
+ *
11
+ * ── FAIL-OPEN, ALWAYS ─────────────────────────────────────────────────────
12
+ * Instrumentation NEVER changes return values and NEVER throws into customer
13
+ * code (the exporter's swallow-and-log doctrine, extended). A telemetry-buffer
14
+ * write that fails is logged and dropped; the customer's pipeline is untouched.
15
+ *
16
+ * ── GATING ────────────────────────────────────────────────────────────────
17
+ * The namespace is inert unless the rig enabled it (`MODELRIG_ARTIFACTS=1`).
18
+ * A disabled namespace's `run.start()` sets NO context, so `getActiveRunContext`
19
+ * returns null everywhere and the run loop's auto-step is never reached —
20
+ * v1 wire, zero new rows, zero behaviour change (spec §1.4).
21
+ */
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.getActiveRunContext = getActiveRunContext;
24
+ exports.createRunNamespace = createRunNamespace;
25
+ const node_async_hooks_1 = require("node:async_hooks");
26
+ const node_crypto_1 = require("node:crypto");
27
+ const otel_map_1 = require("../telemetry/otel-map");
28
+ const storage = new node_async_hooks_1.AsyncLocalStorage();
29
+ /** The active run context, or null when none is set (namespace disabled, or no
30
+ * run.start on this async path). Read by the run loop's auto-step seam. */
31
+ function getActiveRunContext() {
32
+ const ctx = storage.getStore();
33
+ return ctx !== undefined && !ctx.ended ? ctx : null;
34
+ }
35
+ function warnOnce(scope, err) {
36
+ console.warn(`[modelrig artifacts] ${scope} buffer write failed (dropped, run unaffected): ` +
37
+ `${err instanceof Error ? err.message : String(err)}`);
38
+ }
39
+ function createRunNamespace(deps) {
40
+ const { buffer, enabled } = deps;
41
+ const evalStore = deps.artifactStore;
42
+ /** Write ONE run-subject evaluation (artifactId null, runId set). Fail-open. */
43
+ function writeRunEvaluation(runId, opts) {
44
+ if (!enabled || evalStore === undefined || runId === "")
45
+ return;
46
+ try {
47
+ evalStore.recordArtifactEvaluation({
48
+ id: (0, node_crypto_1.randomUUID)(),
49
+ artifactId: null,
50
+ runId,
51
+ evaluator: opts.evaluator,
52
+ evaluatorKind: opts.kind,
53
+ score: opts.score ?? null,
54
+ passed: opts.passed ?? null,
55
+ label: opts.label ?? null,
56
+ explanation: opts.explanation ?? null,
57
+ createdBy: null,
58
+ });
59
+ }
60
+ catch (err) {
61
+ warnOnce("run.evaluate", err);
62
+ }
63
+ }
64
+ const inertHandle = { runId: "", end() { }, evaluate() { } };
65
+ function buildContext(startRow, traceId, zeroRetention) {
66
+ const runId = startRow.id;
67
+ const attemptByStep = new Map();
68
+ const loaded = new Set();
69
+ let stepSeq = 0;
70
+ return {
71
+ runId,
72
+ traceId,
73
+ zeroRetention,
74
+ ended: false,
75
+ buffer,
76
+ startRow,
77
+ noteLoad(artifactId) {
78
+ loaded.add(artifactId);
79
+ },
80
+ takeLoadedIds() {
81
+ const ids = [...loaded];
82
+ loaded.clear();
83
+ return ids;
84
+ },
85
+ nextStepKey(label) {
86
+ stepSeq += 1;
87
+ return `${label}#${stepSeq}`;
88
+ },
89
+ emitGroundTruthStep(input) {
90
+ const attemptNo = (attemptByStep.get(input.stepKey) ?? 0) + 1;
91
+ attemptByStep.set(input.stepKey, attemptNo);
92
+ try {
93
+ buffer.recordStep({
94
+ runId,
95
+ stepKey: input.stepKey,
96
+ attemptNo,
97
+ task: input.task,
98
+ provenance: "ground-truth",
99
+ inferenceId: input.inferenceId,
100
+ spanTraceId: null,
101
+ spanId: null,
102
+ startedAt: input.startedAt,
103
+ endedAt: input.endedAt,
104
+ failureClass: input.failureClass,
105
+ });
106
+ }
107
+ catch (err) {
108
+ warnOnce("step", err);
109
+ }
110
+ },
111
+ };
112
+ }
113
+ /** Build the context + record the `running` row. Shared by start() and
114
+ * scope() so the two entry points agree on identity + buffering. */
115
+ function newRun(opts) {
116
+ const startRow = {
117
+ id: (0, node_crypto_1.randomUUID)(),
118
+ pipeline: opts.pipeline,
119
+ pipelineVersion: opts.pipelineVersion ?? null,
120
+ environment: opts.environment ?? null,
121
+ episodeKey: opts.episodeKey ?? null,
122
+ startedAt: new Date().toISOString(),
123
+ endedAt: null,
124
+ status: "running",
125
+ };
126
+ const traceId = opts.traceparent !== undefined
127
+ ? ((0, otel_map_1.parseTraceparent)(opts.traceparent)?.traceId ?? null)
128
+ : null;
129
+ const ctx = buildContext(startRow, traceId, opts.zeroRetention === true);
130
+ try {
131
+ buffer.recordRun(startRow);
132
+ }
133
+ catch (err) {
134
+ warnOnce("run", err);
135
+ }
136
+ return ctx;
137
+ }
138
+ return {
139
+ start(opts) {
140
+ if (!enabled)
141
+ return inertHandle;
142
+ const ctx = newRun(opts);
143
+ storage.enterWith(ctx);
144
+ return {
145
+ runId: ctx.runId,
146
+ end: (status) => endContext(ctx, status),
147
+ evaluate: (opts2) => writeRunEvaluation(ctx.runId, opts2),
148
+ };
149
+ },
150
+ end(status) {
151
+ const ctx = storage.getStore();
152
+ if (ctx !== undefined)
153
+ endContext(ctx, status);
154
+ },
155
+ evaluate(opts) {
156
+ const ctx = storage.getStore();
157
+ // `ended` counts as gone — same rule as getActiveRunContext. `enterWith`
158
+ // has no lexical exit, so an ended run's context stays ambient on this
159
+ // async path; without this check ns.evaluate re-attributes verdicts to
160
+ // the ended run (post-end verdicts belong to the HANDLE, which closes
161
+ // over its runId — that path is unaffected).
162
+ if (ctx === undefined || ctx.ended) {
163
+ console.warn("[modelrig artifacts] run.evaluate() with no active run — dropped");
164
+ return;
165
+ }
166
+ writeRunEvaluation(ctx.runId, opts);
167
+ },
168
+ async scope(opts, fn) {
169
+ if (!enabled)
170
+ return fn();
171
+ const ctx = newRun(opts);
172
+ // storage.run gives THIS run its own ambient context for the whole of fn,
173
+ // isolated from any sibling scope() running concurrently — no enterWith
174
+ // cross-attribution. End on the way out, success or failure.
175
+ return storage.run(ctx, async () => {
176
+ try {
177
+ const result = await fn();
178
+ endContext(ctx, "succeeded");
179
+ return result;
180
+ }
181
+ catch (err) {
182
+ endContext(ctx, "failed");
183
+ throw err;
184
+ }
185
+ });
186
+ },
187
+ };
188
+ function endContext(ctx, status) {
189
+ if (ctx.ended)
190
+ return;
191
+ ctx.ended = true;
192
+ // Update the projection in place: same identity as the start row, now with
193
+ // an ended_at and a terminal status. recordRun bumps export_seq so this
194
+ // terminal state re-exports past the `:runs` watermark. Emitting the full
195
+ // row (not a sparse one) is required — the server upsert overwrites every
196
+ // column it carries, so a blank pipeline here would clobber the real one.
197
+ try {
198
+ buffer.recordRun({
199
+ ...ctx.startRow,
200
+ endedAt: new Date().toISOString(),
201
+ status: status ?? "succeeded",
202
+ });
203
+ }
204
+ catch (err) {
205
+ warnOnce("run", err);
206
+ }
207
+ }
208
+ }