gemi 0.216.0 → 0.218.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 (257) hide show
  1. package/dist/ai/AgentController.d.ts +85 -2
  2. package/dist/ai/AgentController.d.ts.map +1 -1
  3. package/dist/ai/AgentProvider.d.ts +20 -0
  4. package/dist/ai/AgentProvider.d.ts.map +1 -1
  5. package/dist/ai/FallbackProvider.d.ts +2 -0
  6. package/dist/ai/FallbackProvider.d.ts.map +1 -1
  7. package/dist/ai/index.d.ts +2 -1
  8. package/dist/ai/index.d.ts.map +1 -1
  9. package/dist/ai/index.js +42 -42
  10. package/dist/ai/index.js.map +5 -5
  11. package/dist/ai/live/harness.d.ts +1 -0
  12. package/dist/ai/live/harness.d.ts.map +1 -1
  13. package/dist/ai/providers/call.d.ts +10 -0
  14. package/dist/ai/providers/call.d.ts.map +1 -1
  15. package/dist/ai/providers/fakeProvider.d.ts +3 -0
  16. package/dist/ai/providers/fakeProvider.d.ts.map +1 -1
  17. package/dist/ai/store/Attachments.d.ts +98 -2
  18. package/dist/ai/store/Attachments.d.ts.map +1 -1
  19. package/dist/ai/store/FileOwners.d.ts +18 -0
  20. package/dist/ai/store/FileOwners.d.ts.map +1 -1
  21. package/dist/ai/store/index.d.ts +1 -1
  22. package/dist/ai/store/index.d.ts.map +1 -1
  23. package/dist/ai/testing/RecordingProvider.d.ts +2 -0
  24. package/dist/ai/testing/RecordingProvider.d.ts.map +1 -1
  25. package/dist/ai/testing/index.js +3 -3
  26. package/dist/ai/testing/index.js.map +3 -3
  27. package/dist/app/index.js +1 -1
  28. package/dist/bin/ai-client/kotlin.d.ts +13 -1
  29. package/dist/bin/ai-client/kotlin.d.ts.map +1 -1
  30. package/dist/bin/ai-client/swift.d.ts +10 -1
  31. package/dist/bin/ai-client/swift.d.ts.map +1 -1
  32. package/dist/bin/gemi.js +40 -22
  33. package/dist/bin/gemi.js.map +4 -4
  34. package/dist/bin/http-client/render.d.ts +5 -0
  35. package/dist/bin/http-client/render.d.ts.map +1 -0
  36. package/dist/bun/plugin.js +1 -1
  37. package/dist/bun/preload.js +1 -1
  38. package/dist/{chunk-0ah98rf4.js → chunk-17agj0r3.js} +2 -2
  39. package/dist/{chunk-0ah98rf4.js.map → chunk-17agj0r3.js.map} +1 -1
  40. package/dist/{chunk-c2c21b6g.js → chunk-1nw9jhpt.js} +2 -2
  41. package/dist/{chunk-c2c21b6g.js.map → chunk-1nw9jhpt.js.map} +1 -1
  42. package/dist/{chunk-362a52jj.js → chunk-3r7z4kc0.js} +2 -2
  43. package/dist/{chunk-362a52jj.js.map → chunk-3r7z4kc0.js.map} +1 -1
  44. package/dist/{chunk-t0519abr.js → chunk-4k3r37be.js} +2 -2
  45. package/dist/{chunk-t0519abr.js.map → chunk-4k3r37be.js.map} +1 -1
  46. package/dist/{chunk-2crfg0m7.js → chunk-4s72m6zx.js} +3 -3
  47. package/dist/{chunk-2crfg0m7.js.map → chunk-4s72m6zx.js.map} +1 -1
  48. package/dist/{chunk-v7bbn1m0.js → chunk-4sbrvmz9.js} +5 -5
  49. package/dist/{chunk-v7bbn1m0.js.map → chunk-4sbrvmz9.js.map} +3 -3
  50. package/dist/{chunk-5294qsfq.js → chunk-5gp49wph.js} +2 -2
  51. package/dist/{chunk-0z8h6t7k.js.map → chunk-5gp49wph.js.map} +1 -1
  52. package/dist/{chunk-w1my1q4q.js → chunk-5vdkqv17.js} +2 -2
  53. package/dist/{chunk-w1my1q4q.js.map → chunk-5vdkqv17.js.map} +1 -1
  54. package/dist/{chunk-dqw432zh.js → chunk-5wh3cw2x.js} +3 -3
  55. package/dist/{chunk-dqw432zh.js.map → chunk-5wh3cw2x.js.map} +1 -1
  56. package/dist/{chunk-ttz05z12.js → chunk-6b7z5h54.js} +2 -2
  57. package/dist/{chunk-ttz05z12.js.map → chunk-6b7z5h54.js.map} +1 -1
  58. package/dist/{chunk-mw4c05vw.js → chunk-6ncn8rdn.js} +2 -2
  59. package/dist/{chunk-mw4c05vw.js.map → chunk-6ncn8rdn.js.map} +1 -1
  60. package/dist/chunk-7081awrd.js +11 -0
  61. package/dist/{chunk-rqa04dtq.js.map → chunk-7081awrd.js.map} +4 -4
  62. package/dist/{chunk-j6j0qxam.js → chunk-7rmb1v9c.js} +2 -2
  63. package/dist/{chunk-j6j0qxam.js.map → chunk-7rmb1v9c.js.map} +1 -1
  64. package/dist/{chunk-wcj083k2.js → chunk-7t13vyzg.js} +3 -3
  65. package/dist/{chunk-wcj083k2.js.map → chunk-7t13vyzg.js.map} +1 -1
  66. package/dist/{chunk-bk1e8sah.js → chunk-7xe5vd4w.js} +2 -2
  67. package/dist/{chunk-bk1e8sah.js.map → chunk-7xe5vd4w.js.map} +1 -1
  68. package/dist/{chunk-cws2tsxg.js → chunk-8524ejgk.js} +2 -2
  69. package/dist/{chunk-cws2tsxg.js.map → chunk-8524ejgk.js.map} +1 -1
  70. package/dist/{chunk-twb7x8j8.js → chunk-9c8e4nkz.js} +2 -2
  71. package/dist/{chunk-twb7x8j8.js.map → chunk-9c8e4nkz.js.map} +1 -1
  72. package/dist/{chunk-p5n1tqqg.js → chunk-9g5qh1ya.js} +2 -2
  73. package/dist/{chunk-p5n1tqqg.js.map → chunk-9g5qh1ya.js.map} +1 -1
  74. package/dist/{chunk-yjshg4e5.js → chunk-9pvxexh1.js} +2 -2
  75. package/dist/{chunk-yjshg4e5.js.map → chunk-9pvxexh1.js.map} +1 -1
  76. package/dist/{chunk-kd6z1t9z.js → chunk-aes0ecnp.js} +3 -3
  77. package/dist/{chunk-kd6z1t9z.js.map → chunk-aes0ecnp.js.map} +1 -1
  78. package/dist/{chunk-0a796avj.js → chunk-at6zjajz.js} +2 -2
  79. package/dist/{chunk-0a796avj.js.map → chunk-at6zjajz.js.map} +1 -1
  80. package/dist/{chunk-htkw9qbv.js → chunk-b1pps9bj.js} +2 -2
  81. package/dist/{chunk-htkw9qbv.js.map → chunk-b1pps9bj.js.map} +1 -1
  82. package/dist/{chunk-btf3t4qa.js → chunk-b8tmmpcf.js} +2 -2
  83. package/dist/{chunk-btf3t4qa.js.map → chunk-b8tmmpcf.js.map} +1 -1
  84. package/dist/chunk-bcfwa370.js +5 -0
  85. package/dist/chunk-bcfwa370.js.map +13 -0
  86. package/dist/{chunk-ybmy1rts.js → chunk-c95ds04p.js} +2 -2
  87. package/dist/{chunk-ybmy1rts.js.map → chunk-c95ds04p.js.map} +1 -1
  88. package/dist/{chunk-y9fye7az.js → chunk-cwm5x7rf.js} +2 -2
  89. package/dist/{chunk-y9fye7az.js.map → chunk-cwm5x7rf.js.map} +1 -1
  90. package/dist/{chunk-djwmrvsq.js → chunk-d6056zme.js} +2 -2
  91. package/dist/{chunk-djwmrvsq.js.map → chunk-d6056zme.js.map} +1 -1
  92. package/dist/chunk-d6bgh2nr.js +5 -0
  93. package/dist/{chunk-texzdarz.js.map → chunk-d6bgh2nr.js.map} +1 -1
  94. package/dist/{chunk-z03ds1qe.js → chunk-dgna0e7g.js} +2 -2
  95. package/dist/{chunk-z03ds1qe.js.map → chunk-dgna0e7g.js.map} +1 -1
  96. package/dist/{chunk-1k6dn4ba.js → chunk-ee7xb9qr.js} +1 -1
  97. package/dist/{chunk-5ya7fbfg.js → chunk-eh3ktv8k.js} +2 -2
  98. package/dist/{chunk-5ya7fbfg.js.map → chunk-eh3ktv8k.js.map} +1 -1
  99. package/dist/{chunk-aqjjknyk.js → chunk-evgs2tr8.js} +2 -2
  100. package/dist/{chunk-aqjjknyk.js.map → chunk-evgs2tr8.js.map} +1 -1
  101. package/dist/{chunk-mv2d2njy.js → chunk-fhb00fjx.js} +2 -2
  102. package/dist/{chunk-mv2d2njy.js.map → chunk-fhb00fjx.js.map} +1 -1
  103. package/dist/{chunk-py69zwwv.js → chunk-fq7wkefg.js} +2 -2
  104. package/dist/{chunk-py69zwwv.js.map → chunk-fq7wkefg.js.map} +1 -1
  105. package/dist/{chunk-01r2cx3k.js → chunk-g178aect.js} +4 -4
  106. package/dist/{chunk-01r2cx3k.js.map → chunk-g178aect.js.map} +1 -1
  107. package/dist/{chunk-jr9f5r65.js → chunk-gt6eq1p2.js} +3 -3
  108. package/dist/{chunk-jr9f5r65.js.map → chunk-gt6eq1p2.js.map} +1 -1
  109. package/dist/{chunk-z54zefss.js → chunk-gxd1388t.js} +2 -2
  110. package/dist/{chunk-z54zefss.js.map → chunk-gxd1388t.js.map} +1 -1
  111. package/dist/{chunk-dpm875be.js → chunk-gxfyd8wr.js} +3 -3
  112. package/dist/{chunk-dpm875be.js.map → chunk-gxfyd8wr.js.map} +1 -1
  113. package/dist/{chunk-gkjsanjh.js → chunk-h6knw9f0.js} +1 -1
  114. package/dist/{chunk-shn9t4vg.js → chunk-hmtn7996.js} +2 -2
  115. package/dist/{chunk-shn9t4vg.js.map → chunk-hmtn7996.js.map} +1 -1
  116. package/dist/{chunk-6s48nq83.js → chunk-jzqywxpj.js} +2 -2
  117. package/dist/{chunk-6s48nq83.js.map → chunk-jzqywxpj.js.map} +1 -1
  118. package/dist/{chunk-mnfk2r8z.js → chunk-k8nsefzb.js} +2 -2
  119. package/dist/{chunk-mnfk2r8z.js.map → chunk-k8nsefzb.js.map} +1 -1
  120. package/dist/{chunk-xw241q0q.js → chunk-kggwk7hz.js} +1 -1
  121. package/dist/chunk-ktee4gy4.js +484 -0
  122. package/dist/chunk-ktee4gy4.js.map +23 -0
  123. package/dist/{chunk-hknnxxg6.js → chunk-m0pfdc1n.js} +3 -3
  124. package/dist/{chunk-hknnxxg6.js.map → chunk-m0pfdc1n.js.map} +1 -1
  125. package/dist/{chunk-yak9kt1x.js → chunk-m68cxnbv.js} +2 -2
  126. package/dist/{chunk-yak9kt1x.js.map → chunk-m68cxnbv.js.map} +1 -1
  127. package/dist/{chunk-5m0vh0rg.js → chunk-ncw3zjxm.js} +2 -2
  128. package/dist/{chunk-5m0vh0rg.js.map → chunk-ncw3zjxm.js.map} +1 -1
  129. package/dist/{chunk-6cge785m.js → chunk-nhebjh6n.js} +1 -1
  130. package/dist/{chunk-djpqt7kh.js → chunk-ppdfwnqw.js} +1 -1
  131. package/dist/{chunk-62b7paq5.js → chunk-prc4bcgp.js} +2 -2
  132. package/dist/{chunk-62b7paq5.js.map → chunk-prc4bcgp.js.map} +1 -1
  133. package/dist/{chunk-hea3rwj3.js → chunk-q0d45r2j.js} +2 -2
  134. package/dist/{chunk-hea3rwj3.js.map → chunk-q0d45r2j.js.map} +1 -1
  135. package/dist/{chunk-6669vjve.js → chunk-qa528feb.js} +2 -2
  136. package/dist/{chunk-6669vjve.js.map → chunk-qa528feb.js.map} +1 -1
  137. package/dist/{chunk-4zw9gaey.js → chunk-qstjm3cb.js} +2 -2
  138. package/dist/{chunk-4zw9gaey.js.map → chunk-qstjm3cb.js.map} +1 -1
  139. package/dist/{chunk-t5af0fjq.js → chunk-r90djdx6.js} +2 -2
  140. package/dist/{chunk-t5af0fjq.js.map → chunk-r90djdx6.js.map} +1 -1
  141. package/dist/{chunk-bw1mvk6n.js → chunk-rp2f9mq1.js} +2 -2
  142. package/dist/{chunk-bw1mvk6n.js.map → chunk-rp2f9mq1.js.map} +1 -1
  143. package/dist/{chunk-9k6swvf1.js → chunk-s7jwsbfd.js} +3 -3
  144. package/dist/{chunk-9k6swvf1.js.map → chunk-s7jwsbfd.js.map} +1 -1
  145. package/dist/{chunk-3pfrqzw8.js → chunk-sba3s380.js} +2 -2
  146. package/dist/{chunk-3pfrqzw8.js.map → chunk-sba3s380.js.map} +1 -1
  147. package/dist/{chunk-naj8bmj5.js → chunk-snt0523y.js} +2 -2
  148. package/dist/{chunk-naj8bmj5.js.map → chunk-snt0523y.js.map} +1 -1
  149. package/dist/{chunk-5cf59esb.js → chunk-sqqh78tf.js} +2 -2
  150. package/dist/{chunk-5cf59esb.js.map → chunk-sqqh78tf.js.map} +1 -1
  151. package/dist/{chunk-9pjvetym.js → chunk-sxxkkx75.js} +4 -4
  152. package/dist/{chunk-9pjvetym.js.map → chunk-sxxkkx75.js.map} +1 -1
  153. package/dist/{chunk-1hs2fxxx.js → chunk-tw338bbv.js} +2 -2
  154. package/dist/{chunk-1hs2fxxx.js.map → chunk-tw338bbv.js.map} +1 -1
  155. package/dist/{chunk-rzhgcajs.js → chunk-v0sgcy87.js} +1 -1
  156. package/dist/{chunk-8q3pnwtj.js → chunk-vawqmdh4.js} +2 -2
  157. package/dist/{chunk-8q3pnwtj.js.map → chunk-vawqmdh4.js.map} +1 -1
  158. package/dist/{chunk-c231j2e7.js → chunk-vck02shp.js} +2 -2
  159. package/dist/{chunk-c231j2e7.js.map → chunk-vck02shp.js.map} +1 -1
  160. package/dist/{chunk-knmh8ynk.js → chunk-vewxnk3g.js} +2 -2
  161. package/dist/{chunk-knmh8ynk.js.map → chunk-vewxnk3g.js.map} +1 -1
  162. package/dist/{chunk-7bywa721.js → chunk-w3ks9nz7.js} +2 -2
  163. package/dist/{chunk-7bywa721.js.map → chunk-w3ks9nz7.js.map} +1 -1
  164. package/dist/{chunk-k9pch3e6.js → chunk-w85wrer7.js} +2 -2
  165. package/dist/{chunk-k9pch3e6.js.map → chunk-w85wrer7.js.map} +1 -1
  166. package/dist/{chunk-g7vyn179.js → chunk-w9sw2kn7.js} +3 -3
  167. package/dist/{chunk-g7vyn179.js.map → chunk-w9sw2kn7.js.map} +1 -1
  168. package/dist/{chunk-95yr9y9v.js → chunk-ww62b10k.js} +2 -2
  169. package/dist/{chunk-95yr9y9v.js.map → chunk-ww62b10k.js.map} +1 -1
  170. package/dist/{chunk-a6yge4kh.js → chunk-xb0evp2m.js} +2 -2
  171. package/dist/{chunk-a6yge4kh.js.map → chunk-xb0evp2m.js.map} +1 -1
  172. package/dist/{chunk-g1th1dfa.js → chunk-xese0rng.js} +3 -3
  173. package/dist/{chunk-g1th1dfa.js.map → chunk-xese0rng.js.map} +1 -1
  174. package/dist/{chunk-cgkp0ypn.js → chunk-xf3wke41.js} +2 -2
  175. package/dist/{chunk-cgkp0ypn.js.map → chunk-xf3wke41.js.map} +1 -1
  176. package/dist/{chunk-mjyr8at2.js → chunk-xn7azkgd.js} +3 -3
  177. package/dist/{chunk-mjyr8at2.js.map → chunk-xn7azkgd.js.map} +1 -1
  178. package/dist/{chunk-gwe9hbds.js → chunk-xp5mmgfp.js} +2 -2
  179. package/dist/{chunk-gwe9hbds.js.map → chunk-xp5mmgfp.js.map} +1 -1
  180. package/dist/{chunk-kc1y747c.js → chunk-xyv3y476.js} +3 -3
  181. package/dist/{chunk-kc1y747c.js.map → chunk-xyv3y476.js.map} +1 -1
  182. package/dist/{chunk-0z8h6t7k.js → chunk-yedb5vvg.js} +2 -2
  183. package/dist/{chunk-5294qsfq.js.map → chunk-yedb5vvg.js.map} +1 -1
  184. package/dist/{chunk-b02yzfpk.js → chunk-ykshxc5k.js} +2 -2
  185. package/dist/{chunk-b02yzfpk.js.map → chunk-ykshxc5k.js.map} +1 -1
  186. package/dist/{chunk-zbxvyanj.js → chunk-yxtfg4wy.js} +2 -2
  187. package/dist/{chunk-zbxvyanj.js.map → chunk-yxtfg4wy.js.map} +1 -1
  188. package/dist/{chunk-7mg2ash8.js → chunk-zy6hj5cc.js} +2 -2
  189. package/dist/{chunk-7mg2ash8.js.map → chunk-zy6hj5cc.js.map} +1 -1
  190. package/dist/{chunk-xg5r0383.js → chunk-zyvmbqcx.js} +3 -3
  191. package/dist/{chunk-xg5r0383.js.map → chunk-zyvmbqcx.js.map} +1 -1
  192. package/dist/config/index.js +1 -1
  193. package/dist/console/run.js +2 -2
  194. package/dist/console/run.js.map +1 -1
  195. package/dist/container/index.js +2 -2
  196. package/dist/container/index.js.map +1 -1
  197. package/dist/database/index.js +2 -2
  198. package/dist/database/index.js.map +1 -1
  199. package/dist/email/index.js +2 -2
  200. package/dist/email/index.js.map +1 -1
  201. package/dist/facades/index.js +2 -2
  202. package/dist/facades/index.js.map +1 -1
  203. package/dist/foundation/index.js +2 -2
  204. package/dist/foundation/index.js.map +1 -1
  205. package/dist/http/index.js +2 -2
  206. package/dist/http/index.js.map +1 -1
  207. package/dist/i18n/dictionaryRuntime.js +2 -2
  208. package/dist/i18n/dictionaryRuntime.js.map +1 -1
  209. package/dist/i18n/index.js +2 -2
  210. package/dist/i18n/index.js.map +1 -1
  211. package/dist/kernel/index.js +2 -2
  212. package/dist/kernel/index.js.map +1 -1
  213. package/dist/orm/index.js +2 -2
  214. package/dist/orm/index.js.map +1 -1
  215. package/dist/probe/index.js +2 -2
  216. package/dist/probe/index.js.map +1 -1
  217. package/dist/server/index.js +2 -2
  218. package/dist/server/index.js.map +1 -1
  219. package/dist/services/index.d.ts +2 -2
  220. package/dist/services/index.d.ts.map +1 -1
  221. package/dist/services/index.js +2 -2
  222. package/dist/services/index.js.map +1 -1
  223. package/dist/services/queue/DatabaseQueueDriver.d.ts +8 -1
  224. package/dist/services/queue/DatabaseQueueDriver.d.ts.map +1 -1
  225. package/dist/services/queue/work.js +2 -2
  226. package/dist/services/queue/work.js.map +1 -1
  227. package/dist/services/queue/workflow/DatabaseWorkflowStore.d.ts +20 -1
  228. package/dist/services/queue/workflow/DatabaseWorkflowStore.d.ts.map +1 -1
  229. package/dist/services/queue/workflow/MemoryWorkflowStore.d.ts +12 -1
  230. package/dist/services/queue/workflow/MemoryWorkflowStore.d.ts.map +1 -1
  231. package/dist/services/queue/workflow/Step.d.ts +131 -2
  232. package/dist/services/queue/workflow/Step.d.ts.map +1 -1
  233. package/dist/services/queue/workflow/Workflow.d.ts +18 -2
  234. package/dist/services/queue/workflow/Workflow.d.ts.map +1 -1
  235. package/dist/services/queue/workflow/WorkflowRuntime.d.ts +6 -0
  236. package/dist/services/queue/workflow/WorkflowRuntime.d.ts.map +1 -1
  237. package/dist/services/queue/workflow/WorkflowStore.d.ts +67 -3
  238. package/dist/services/queue/workflow/WorkflowStore.d.ts.map +1 -1
  239. package/dist/services/queue/workflow/workflowContract.d.ts +2 -0
  240. package/dist/services/queue/workflow/workflowContract.d.ts.map +1 -1
  241. package/dist/stats/route-table.js +1 -1
  242. package/dist/support/index.js +2 -2
  243. package/dist/support/index.js.map +1 -1
  244. package/dist/vitest/index.js +1 -1
  245. package/package.json +1 -1
  246. package/dist/chunk-g1b6zetz.js +0 -5
  247. package/dist/chunk-g1b6zetz.js.map +0 -13
  248. package/dist/chunk-q677pnq5.js +0 -416
  249. package/dist/chunk-q677pnq5.js.map +0 -23
  250. package/dist/chunk-rqa04dtq.js +0 -11
  251. package/dist/chunk-texzdarz.js +0 -5
  252. /package/dist/{chunk-1k6dn4ba.js.map → chunk-ee7xb9qr.js.map} +0 -0
  253. /package/dist/{chunk-gkjsanjh.js.map → chunk-h6knw9f0.js.map} +0 -0
  254. /package/dist/{chunk-xw241q0q.js.map → chunk-kggwk7hz.js.map} +0 -0
  255. /package/dist/{chunk-6cge785m.js.map → chunk-nhebjh6n.js.map} +0 -0
  256. /package/dist/{chunk-djpqt7kh.js.map → chunk-ppdfwnqw.js.map} +0 -0
  257. /package/dist/{chunk-rzhgcajs.js.map → chunk-v0sgcy87.js.map} +0 -0
@@ -2,11 +2,11 @@
2
2
  "version": 3,
3
3
  "sources": ["../ai/testing/RecordingProvider.ts", "../ai/testing/Fingerprints.ts", "../ai/testing/pinClock.ts"],
4
4
  "sourcesContent": [
5
- "import { createHash } from \"node:crypto\";\n\nimport {\n AgentProvider,\n type ProviderCapabilities,\n type ProviderEvent,\n type ProviderStreamParams,\n type ProviderToolSpec,\n} from \"../AgentProvider\";\nimport { JSONSchemaError, s } from \"../Schema\";\nimport { type FingerprintOptions, Fingerprints, type RecordingFingerprints } from \"./Fingerprints\";\n\n/**\n * One model call, as a recording keeps it: what was sent (normalised, see\n * `RecordingProvider`) and what the model streamed back.\n */\nexport type RecordedCall = {\n request: RecordedRequest;\n events: ProviderEvent[];\n /** When it started among all the calls of the recording, its sub-runs' too (`ordered`). */\n at?: number;\n /** The app's position (`position`) the call's prompt was pinned to (`pin`). */\n read?: number;\n /** The app's position once the call's answer had streamed in full, before its tools ran. */\n ended?: number;\n};\n\n/**\n * A request as recorded. `messages` are the messages new since the call\n * before it (`after` says how many of that call's it resent), each without\n * the parts minted per run; `tools` is a hash of the tool list, and\n * `toolNames` the names it offered.\n */\nexport type RecordedRequest = {\n messages: { role: string; content: unknown }[];\n after?: number;\n tools?: string;\n toolNames?: string[];\n [field: string]: unknown;\n};\n\n/** What a `RecordingProvider` records, and replays from. Plain JSON: write it where you like. */\nexport type Recording = {\n version: 1;\n model: string;\n capabilities: ProviderCapabilities;\n /** When the recording started (ISO). A replay can run at that time: see `pinClock`. */\n recordedAt: string;\n calls: RecordedCall[];\n /** Sub-runs' calls (`nested(key)`), each in its own order. */\n nested?: Record<string, RecordedCall[]>;\n /** What it was made with, when recorded with `fingerprints`. See `Fingerprints`. */\n fingerprints?: RecordingFingerprints;\n};\n\n/** How `replay` matches a request against the recorded one. See `RecordingProviderOptions.match`. */\nexport type RecordingMatch = \"exact\" | \"wording\" | \"shape\";\n\nexport type RecordingProviderOptions = {\n /**\n * What a replayed request may differ in from the recorded one and still\n * replay, counted as `stale` with the reason:\n *\n * - `\"wording\"` (the default): the wording of the prompt files changed since\n * the recording, and nothing else. The static text of those files is cut\n * out of both requests (see `Fingerprints.cutters`), so the messages, the\n * tool calls and results and every value filled into the prompts must\n * still be the same. Needs a recording made with `fingerprints`, and\n * `fingerprints` on the replay to find the files.\n * - `\"shape\"`: anything but the shape of the conversation (its roles, tool\n * calls with their inputs, tool results with their status): instructions,\n * settings and message text. For an app whose prompts are not files.\n * - `\"exact\"`: nothing.\n *\n * In `\"wording\"` and `\"shape\"`, the tools offered may differ too, as long as\n * every tool call the recorded answer makes is to a tool still offered and\n * fits its schema today.\n */\n match?: RecordingMatch;\n /**\n * Fingerprint what the recording is made with (the prompt files its\n * requests carried, its tools' definitions, `inputs`), and, replaying, tell\n * a reworded prompt by them. See `Fingerprints`.\n */\n fingerprints?: FingerprintOptions;\n /**\n * Ids minted per run (a record's id, say), which a replay mints anew. Each\n * recorded id matches the id at its place in the request, the same one\n * wherever it shows, and the recorded answer is given the replay's ids.\n * Default: UUIDs.\n */\n ids?: RegExp;\n /**\n * Replays the calls, the sub-runs' too, in the order they started when\n * recorded (`at`), for runs that go side by side and whose order shows.\n * Off, each run and sub-run replays in its own order, in any interleaving.\n */\n ordered?: boolean;\n /**\n * A position in the app's own state that moves as tools run (an edit log's\n * head, say). Recording, each call keeps where it was; replaying, a call's\n * answer waits until the app gets there again, so tool calls running side by\n * side write in the recorded order. See also `pin`.\n */\n position?: () => number | Promise<number>;\n /** How long a replay waits for `ordered` or `position` before it gives up. Default 60 s. */\n waitMs?: number;\n};\n\n/** A replayed request that is not the recorded one, beyond what `match` tolerates. */\nexport class RecordingMismatchError extends Error {\n constructor(message: string) {\n super(`${message} Record again.`);\n this.name = \"RecordingMismatchError\";\n }\n}\n\nconst UUIDS = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/g;\n\n/** `value` with each of its strings passed through `change`. */\nfunction mapStrings(value: unknown, change: (text: string) => string): unknown {\n if (typeof value === \"string\") return change(value);\n if (Array.isArray(value)) return value.map((item) => mapStrings(item, change));\n if (value && typeof value === \"object\") {\n return Object.fromEntries(\n Object.entries(value).map(([key, inner]) => [key, mapStrings(inner, change)]),\n );\n }\n return value;\n}\n\n/**\n * A message's content without what a run mints and the model is not sent: a\n * tool call's sub-run transcript (`nested`, recorded on its own), and the full\n * output of a tool whose model reads a projection (`modelOutput`).\n */\nfunction withoutTranscripts<T>(value: T): T {\n return JSON.parse(\n JSON.stringify(value, function (this: Record<string, unknown>, key, inner) {\n if (key === \"nested\") return undefined;\n if (key === \"output\" && this.type === \"tool-result\" && \"modelOutput\" in this) {\n return undefined;\n }\n return inner;\n }),\n );\n}\n\nfunction resolvers(): { promise: Promise<void>; resolve: () => void } {\n let resolve!: () => void;\n const promise = new Promise<void>((done) => (resolve = done));\n return { promise, resolve };\n}\n\nconst sha256 = (text: string) => createHash(\"sha256\").update(text).digest(\"hex\");\n\nconst flatTools = (tools: NonNullable<ProviderStreamParams[\"tools\"]>): ProviderToolSpec[] =>\n tools.flatMap((tool) => (\"tools\" in tool ? tool.tools : [tool]));\n\n/**\n * The shape of a conversation, which `match: \"shape\"` keeps: each message's\n * role, its tool calls with their inputs and its tool results with their\n * status, but not its text.\n */\nfunction shapeOf(messages: { role: string; content: unknown }[]): unknown {\n return messages.map(({ role, content }) => ({\n role,\n parts: (Array.isArray(content) ? content : []).flatMap((part: any): unknown[] => {\n if (part?.type === \"tool-call\") return [{ call: part.name, input: part.input ?? part.args }];\n if (part?.type === \"tool-result\") return [{ result: part.name, status: part.status }];\n if (part?.type === \"file\") return [{ file: true }];\n return [];\n }),\n }));\n}\n\ntype Shared = {\n ids: Map<string, string>;\n stale: Set<string>;\n staleCalls: number;\n started: number;\n pending?: number[];\n moved: { promise: Promise<void>; resolve: () => void };\n};\n\n/**\n * A provider that records a live provider's calls, and replays them later\n * without one: model-backed tests and evals that run in CI, offline and for\n * free, and stay the same from run to run.\n *\n * // Recording: every call goes to `live`, and is kept.\n * const recorder = RecordingProvider.record(live);\n * await runTheCase(recorder);\n * await Bun.write(file, JSON.stringify(recorder.recording()));\n *\n * // Replaying: each call is answered with what was recorded for it.\n * const replay = RecordingProvider.replay(await Bun.file(file).json());\n * await runTheCase(replay);\n * replay.stale; // why the recording should be made again, if it should\n *\n * WHAT IS MATCHED. The n-th call replays the n-th recorded call (per run and\n * per sub-run, see `nested`), and it has to be the same request:\n *\n * - Messages are compared without ids and times, which differ per run: only\n * `role` and `content` are kept, without sub-run transcripts. A call resends\n * the messages of the one before it, so only the new ones are recorded\n * (`after`), and a recording grows with the run, not with its square.\n * - Ids minted per run (`ids`, UUIDs by default) are matched by place, and the\n * recorded answer is given the replay's ids.\n * - The tool list is compared by its hash.\n *\n * A request that differs is stale rather than a mismatch only as far as\n * `match` allows. With `\"wording\"` (the default) that is the rewording of\n * prompt files changed since the recording: their static text is cut out of\n * both requests and the rest must be the same (see `Fingerprints`). The tools\n * offered may differ too, as long as each tool call the recorded answer makes\n * still exists and fits its schema today: replaying a call that doesn't\n * would test nothing. A stale call replays and is counted in `stale` with the\n * reason. Anything else throws a `RecordingMismatchError` that shows where\n * the two differ.\n *\n * UPLOADS are answered `upload_<n>`, by order, so a file need not be the same\n * bytes on another machine for its call to replay. A sub-run counts its own,\n * `upload_<key>_<n>`, so the ids stay the same however sub-runs interleave.\n * Recording, the file goes to the live provider, and the calls show the model\n * the provider's id.\n *\n * TIME. `recordedAt` is when the recording started. `pinClock(recordedAt)`\n * runs a replay at that time, so dates relative to today come out as recorded.\n */\nexport class RecordingProvider extends AgentProvider {\n readonly model: string;\n readonly capabilities: ProviderCapabilities;\n /** When the recording started. */\n readonly recordedAt: Date;\n private readonly calls: RecordedCall[];\n /** Replaying: the recorded calls of the sub-runs, by key. */\n private readonly recordedNested: Record<string, RecordedCall[]>;\n private readonly children = new Map<string, RecordingProvider>();\n private parent?: RecordingProvider;\n private readonly key?: string;\n /** The messages of the previous call, which the next call's are recorded after. */\n private sent: unknown[] = [];\n /** Recording: the live provider's file id of each upload, by the id answered here. */\n private readonly uploads: Map<string, string>;\n /** Uploads answered so far, counted per run and per sub-run. */\n private uploadCount = 0;\n /** Recording: the position the next call's prompt was pinned to. */\n private read?: number;\n private readonly shared: Shared;\n private readonly options: Required<Pick<RecordingProviderOptions, \"match\" | \"ids\" | \"waitMs\">> &\n RecordingProviderOptions;\n /** What the calls sent, for the fingerprints: every string, and each tool's definition hashes. */\n private readonly texts = new Set<string>();\n private readonly toolHashes = new Map<string, Set<string>>();\n private readonly toolLists = new Set<string>();\n /** Replaying: the recording's fingerprints, and how a differing request is cut by them. */\n private recorded?: Fingerprints;\n private cuts?: ReturnType<Fingerprints[\"cutters\"]>;\n\n private constructor(\n private readonly live: AgentProvider | undefined,\n recording: Recording | undefined,\n options: RecordingProviderOptions,\n child?: { parent: RecordingProvider; key: string; calls: RecordedCall[] },\n ) {\n super();\n this.options = {\n ...options,\n match: options.match ?? \"wording\",\n ids: new RegExp(options.ids ?? UUIDS, \"g\"),\n waitMs: options.waitMs ?? 60_000,\n };\n if (child) {\n const { parent } = child;\n this.parent = parent;\n this.key = child.key;\n this.model = parent.model;\n this.capabilities = parent.capabilities;\n this.recordedAt = parent.recordedAt;\n this.calls = child.calls;\n this.recordedNested = {};\n this.uploads = parent.uploads;\n this.shared = parent.shared;\n return;\n }\n this.shared = {\n ids: new Map(),\n stale: new Set(),\n staleCalls: 0,\n started: 0,\n moved: resolvers(),\n };\n this.uploads = new Map();\n if (live) {\n this.model = live.model;\n this.capabilities = live.capabilities;\n this.recordedAt = new Date();\n this.calls = [];\n this.recordedNested = {};\n return;\n }\n if (!recording || recording.version !== 1 || !Array.isArray(recording.calls)) {\n throw new Error(\"RecordingProvider.replay needs a recording made by RecordingProvider.\");\n }\n this.model = recording.model;\n this.capabilities = recording.capabilities;\n this.recordedAt = new Date(recording.recordedAt);\n this.calls = structuredClone(recording.calls);\n this.recordedNested = structuredClone(recording.nested ?? {});\n if (recording.fingerprints) {\n this.recorded = new Fingerprints(recording.fingerprints, options.fingerprints);\n }\n }\n\n /** Records every call made through it to `live`, which answers it. */\n static record(live: AgentProvider, options: RecordingProviderOptions = {}): RecordingProvider {\n return new RecordingProvider(live, undefined, options);\n }\n\n /** Answers each call with the recorded one. See the class for how calls are matched. */\n static replay(recording: Recording, options: RecordingProviderOptions = {}): RecordingProvider {\n return new RecordingProvider(undefined, recording, options);\n }\n\n /** Whether it records (true) or replays. */\n get isRecording(): boolean {\n return this.live !== undefined;\n }\n\n /**\n * Why the replay should be recorded again: the parts of the requests that\n * differed and were tolerated (`match`). Empty for a replay\n * that matched exactly, and for a recording.\n */\n get stale(): ReadonlySet<string> {\n return this.shared.stale;\n }\n\n /** How many calls replayed stale, the sub-runs' included. */\n get staleCalls(): number {\n return this.shared.staleCalls;\n }\n\n /**\n * The provider of sub-run `key` (a sub-agent's, say), recorded and replayed\n * apart from this one's calls and the other sub-runs', so sub-runs running\n * side by side can replay in any interleaving. The same key answers the same\n * provider, so a sub-run continued later goes on after its calls. Replaying\n * a key the recording does not have throws.\n */\n nested(key: string): RecordingProvider {\n if (this.parent) return this.parent.nested(key);\n let child = this.children.get(key);\n if (!child) {\n const calls = this.recordedNested[key];\n if (!this.live && !calls) {\n throw new RecordingMismatchError(`The recording has no sub-run \"${key}\".`);\n }\n child = new RecordingProvider(this.live, undefined, this.options, {\n parent: this,\n key,\n calls: calls ?? [],\n });\n this.children.set(key, child);\n }\n return child;\n }\n\n /**\n * The recording so far: every call made through this provider and its\n * sub-runs. Write it as JSON. Only for a provider made with `record`.\n */\n recording(): Recording {\n if (this.parent) return this.parent.recording();\n if (!this.live)\n throw new Error(\"Only a recording provider (`record`) has a recording to save.\");\n return {\n version: 1,\n model: this.model,\n capabilities: this.capabilities,\n recordedAt: this.recordedAt.toISOString(),\n calls: structuredClone(this.calls),\n ...(this.options.fingerprints ? { fingerprints: this.fingerprints().data } : {}),\n ...(this.children.size > 0\n ? {\n nested: Object.fromEntries(\n [...this.children].map(([key, child]) => [key, structuredClone(child.calls)]),\n ),\n }\n : {}),\n };\n }\n\n /**\n * The fingerprints of what the calls sent so far, the sub-runs' included:\n * of this recording, or of this replay (compare it with the recording's to\n * tell whether a new recording would differ). Uses the `fingerprints`\n * options for where prompts live.\n */\n fingerprints(): Fingerprints {\n const root = this.parent ?? this;\n return Fingerprints.of(root.texts, root.toolHashes, this.options.fingerprints);\n }\n\n /**\n * What changed since `recording` was made, without replaying it: the prompt\n * files and inputs its fingerprints name that differ today. Empty for a\n * recording without fingerprints. For listing the recordings to make again.\n */\n static changedSince(recording: Recording, options: FingerprintOptions = {}): string[] {\n return recording.fingerprints\n ? new Fingerprints(recording.fingerprints, options).changed()\n : [];\n }\n\n /**\n * Replaying: whether every recorded call was made, the sub-runs' too. A run\n * that took another path and stopped early made fewer.\n */\n replayedInFull(): boolean {\n const root = this.parent ?? this;\n return (\n root.calls.length === 0 &&\n Object.entries(root.recordedNested).every(\n ([key, calls]) => (root.children.get(key)?.calls ?? calls).length === 0,\n )\n );\n }\n\n /**\n * The position (`position`) the next call's prompt should show the app at,\n * given `now`, where it is. Recording, that is `now`, kept with the call.\n * Replaying, it is the recorded position, once the app has got there, so a\n * prompt rendered from the app's state is the one that was recorded,\n * however the other runs were timed.\n */\n async pin(now: number): Promise<number> {\n if (this.live) {\n this.read = now;\n return now;\n }\n const read = this.calls[0]?.read;\n if (read === undefined) return now;\n await (this.parent ?? this).reach(read, this.where());\n return read;\n }\n\n async upload(file: File): Promise<string> {\n const n = ++this.uploadCount;\n const id = this.key === undefined ? `upload_${n}` : `upload_${this.key}_${n}`;\n if (this.live) this.uploads.set(id, await this.live.upload(file));\n return id;\n }\n\n normalizeError(error: unknown) {\n return this.live ? this.live.normalizeError(error) : super.normalizeError(error);\n }\n\n async *stream(params: ProviderStreamParams): AsyncGenerator<ProviderEvent> {\n const request = this.requestOf(params);\n if (this.live) {\n yield* this.recordCall(params, request);\n return;\n }\n yield* this.replayCall(params, request);\n }\n\n // --- recording ---------------------------------------------------------------\n\n private async *recordCall(\n params: ProviderStreamParams,\n request: RecordedRequest,\n ): AsyncGenerator<ProviderEvent> {\n const root = this.parent ?? this;\n const at = root.shared.started++;\n const read = this.read;\n this.read = undefined;\n const events: ProviderEvent[] = [];\n // The live call shows the model the files it uploaded, by the provider's ids.\n const messages = params.messages.map((message) => ({\n ...message,\n content: message.content.map((part) =>\n part.type === \"file\" && part.fileId && this.uploads.has(part.fileId)\n ? { ...part, fileId: this.uploads.get(part.fileId) }\n : part,\n ),\n }));\n for await (const event of this.live!.stream({ ...params, messages })) {\n const last = events.at(-1);\n if (event.type === \"tool-call-discard\") {\n // The provider asked again: the discarded calls' deltas are void.\n const discarded = new Set(event.toolCallIds);\n const kept = events.filter(\n (e) => e.type !== \"tool-call-delta\" || !discarded.has(e.toolCallId),\n );\n events.splice(0, events.length, ...kept);\n } else if (event.type === \"retry\") {\n // How the live call went, not what it answered.\n } else if (\n last &&\n (event.type === \"text-delta\" || event.type === \"output-delta\") &&\n last.type === event.type\n ) {\n // Consecutive deltas are kept as one, which replays the same text.\n last.delta += event.delta;\n } else if (\n last?.type === \"tool-call-delta\" &&\n event.type === \"tool-call-delta\" &&\n last.toolCallId === event.toolCallId\n ) {\n last.argsDelta += event.argsDelta;\n } else {\n events.push({ ...event });\n }\n yield event;\n }\n const ended = this.options.position ? await this.options.position() : undefined;\n this.calls.push({\n request,\n events,\n at,\n ...(read !== undefined ? { read } : {}),\n ...(ended !== undefined ? { ended } : {}),\n });\n }\n\n // --- replaying ---------------------------------------------------------------\n\n private async *replayCall(\n params: ProviderStreamParams,\n request: RecordedRequest,\n ): AsyncGenerator<ProviderEvent> {\n const root = this.parent ?? this;\n const where = this.where();\n const next = this.calls[0];\n if (this.options.ordered && next?.at !== undefined) await root.turn(next.at, where);\n const call = this.calls.shift();\n if (!call) {\n throw new RecordingMismatchError(\n `${where}: call ${this.sentCalls} was not recorded (the recording has no more calls).`,\n );\n }\n // A recording made with 0.204.0 kept the request's `promptCacheKey`: it is\n // not compared (see `requestOf`).\n const { promptCacheKey: _cacheKey, ...recorded } = call.request;\n if (!root.matches(JSON.stringify(recorded), request)) {\n root.tolerate(\n where,\n { ...call, request: recorded as RecordedRequest },\n request,\n params.tools ?? [],\n );\n }\n if (call.ended !== undefined) await root.reach(call.ended, where);\n const ids = root.shared.ids;\n for (const event of call.events) {\n yield JSON.parse(\n JSON.stringify(event).replace(this.options.ids, (id) => ids.get(id) ?? id),\n ) as ProviderEvent;\n }\n }\n\n private where(): string {\n return this.key === undefined ? \"the recording\" : `sub-run \"${this.key}\"`;\n }\n\n /** How many calls were made through this provider (not its sub-runs). */\n private sentCalls = 0;\n\n /**\n * The request as it is recorded and matched: see the class. Also moves\n * `sent` on, so the next call is recorded after this one.\n */\n private requestOf(params: ProviderStreamParams): RecordedRequest {\n this.sentCalls++;\n // `promptCacheKey` is derived from the prompt and the tools (#1228): it\n // changes whenever they are reworded, and recordings made before it have\n // none. It says nothing the request doesn't already say, so it is neither\n // matched nor fingerprinted (#1231).\n const { signal: _signal, promptCacheKey: _cacheKey, messages, tools, ...rest } = params;\n const sent = messages.map(({ role, content }) => ({\n role,\n content: withoutTranscripts(content),\n }));\n const after =\n this.sent.length > 0 &&\n this.sent.length <= sent.length &&\n JSON.stringify(sent.slice(0, this.sent.length)) === JSON.stringify(this.sent)\n ? this.sent.length\n : 0;\n this.sent = sent;\n const listed = tools && tools.length > 0 ? JSON.stringify(tools) : undefined;\n const root = this.parent ?? this;\n const keep = (text: string) => {\n root.texts.add(text);\n return text;\n };\n mapStrings([rest, sent.slice(after)], keep);\n if (listed && !root.toolLists.has(listed)) {\n root.toolLists.add(listed);\n for (const tool of flatTools(tools!)) {\n mapStrings(tool, keep);\n const hashes = root.toolHashes.get(tool.name) ?? new Set<string>();\n hashes.add(Fingerprints.tool(tool));\n root.toolHashes.set(tool.name, hashes);\n }\n }\n return {\n ...(withoutTranscripts(rest) as Record<string, unknown>),\n ...(listed\n ? {\n tools: `sha256:${sha256(listed)}`,\n toolNames: flatTools(tools!)\n .map((tool) => tool.name)\n .sort(),\n }\n : {}),\n ...(after > 0 ? { after } : {}),\n messages: sent.slice(after),\n };\n }\n\n /**\n * Whether `request` is the recorded one (`recorded`, as JSON), with each\n * recorded id matched to the id at its place in the request, the same one\n * every time it shows (`ids`, shared by the runs and sub-runs).\n */\n private matches(recorded: string, request: unknown): boolean {\n const pattern = this.options.ids;\n const sent = JSON.stringify(request);\n const theirs = recorded.match(pattern) ?? [];\n const ours = sent.match(pattern) ?? [];\n if (theirs.length !== ours.length) return false;\n const ids = new Map(this.shared.ids);\n for (const [index, id] of theirs.entries()) {\n const mapped = ids.get(id) ?? ours[index]!;\n if (mapped !== ours[index]) return false;\n ids.set(id, mapped);\n }\n if (recorded.replace(pattern, (id) => ids.get(id)!) !== sent) return false;\n for (const [id, mapped] of ids) this.shared.ids.set(id, mapped);\n return true;\n }\n\n /**\n * A request that is not the recorded one. It replays, stale, when what\n * differs is what `match` allows (see `RecordingProviderOptions.match`), and\n * every tool call of the recorded answer fits today's tools if those differ.\n * Throws otherwise, showing where the two first differ.\n */\n private tolerate(\n where: string,\n call: RecordedCall,\n request: RecordedRequest,\n tools: NonNullable<ProviderStreamParams[\"tools\"]>,\n ): void {\n const pattern = this.options.ids;\n const match = this.options.match;\n const recorded = call.request;\n const differs = (theirs: unknown, ours: unknown, why: string): never => {\n // Where they first differ, ids aside (they are matched by place).\n const a = JSON.stringify(theirs).replace(pattern, \"<id>\");\n const b = JSON.stringify(ours).replace(pattern, \"<id>\");\n let at = 0;\n while (at < a.length && a[at] === b[at]) at++;\n throw new RecordingMismatchError(\n `${where}: the request differs from the recorded one${why}. Recorded: …${a.slice(Math.max(0, at - 80), at + 120)}… Sent: …${b.slice(Math.max(0, at - 80), at + 120)}…`,\n );\n };\n if (match === \"exact\") differs(recorded, request, \"\");\n\n const { tools: recordedTools, toolNames: recordedNames, ...recordedRest } = recorded;\n const { tools: sentTools, toolNames: sentNames, ...sentRest } = request;\n const reasons: string[] = [];\n\n if (!this.matches(JSON.stringify(recordedRest), sentRest)) {\n if (match === \"wording\") {\n if (!this.recorded) {\n differs(\n recordedRest,\n sentRest,\n \", and the recording has no fingerprints to tell a reworded prompt by\",\n );\n }\n try {\n this.cuts ??= this.recorded!.cutters();\n } catch (error) {\n throw new RecordingMismatchError(`${where}: ${(error as Error).message}.`);\n }\n const theirs = mapStrings(recordedRest, this.cuts.recorded);\n const ours = mapStrings(sentRest, this.cuts.sent);\n if (this.cuts.changed.length === 0 || !this.matches(JSON.stringify(theirs), ours)) {\n differs(\n theirs,\n ours,\n this.cuts.changed.length > 0 ? \", beyond the wording of the prompts changed since\" : \"\",\n );\n }\n reasons.push(...this.cuts.changed.map((path) => `${path} changed`));\n } else {\n // The conversation's shape, ids matched by place as for an exact match.\n const sameShape =\n (recorded.after ?? 0) === (request.after ?? 0) &&\n this.matches(JSON.stringify(shapeOf(recorded.messages)), shapeOf(request.messages));\n if (!sameShape) differs(recordedRest, sentRest, \" in the conversation itself\");\n const { messages: recordedMessages, ...recordedSettings } = recordedRest;\n const { messages: sentMessages, ...sentSettings } = sentRest;\n if (!this.matches(JSON.stringify(recordedMessages), sentMessages)) {\n reasons.push(\"message text changed\");\n }\n const fields = new Set([...Object.keys(recordedSettings), ...Object.keys(sentSettings)]);\n for (const field of [...fields].sort()) {\n const theirs = JSON.stringify(recordedSettings[field] ?? null);\n if (!this.matches(theirs, sentSettings[field] ?? null)) reasons.push(`${field} changed`);\n }\n }\n }\n\n if (recordedTools !== sentTools) {\n const specs = flatTools(tools);\n for (const event of call.events) {\n if (event.type !== \"tool-call\") continue;\n const spec = specs.find((tool) => tool.name === event.name);\n if (!spec) {\n throw new RecordingMismatchError(\n `${where}: the recorded answer calls ${event.name}, which is not offered any more.`,\n );\n }\n // Formats are hints here: the tool checks them itself when the call runs.\n const formats = Object.fromEntries(\n [...JSON.stringify(spec.parameters).matchAll(/\"format\":\"([^\"]+)\"/g)].map(([, f]) => [\n f!,\n true as const,\n ]),\n );\n let input: unknown;\n try {\n input = JSON.parse(event.args || \"{}\");\n } catch {\n input = undefined;\n }\n // A schema `fromJSONSchema` can't model (a free-form part, such as an\n // object value with no type) isn't checked here (#1234): the tool still\n // validates its input when the call runs, as for formats.\n let schema: ReturnType<typeof s.fromJSONSchema> | undefined;\n try {\n schema = s.fromJSONSchema(spec.parameters as never, { unknownKeys: \"error\", formats });\n } catch (error) {\n if (!(error instanceof JSONSchemaError)) throw error;\n }\n const checked = schema?.safeParse(input);\n if (checked && checked.ok === false) {\n throw new RecordingMismatchError(\n `${where}: the recorded call of ${event.name} does not fit its schema any more (${checked.errors.join(\"; \")}).`,\n );\n }\n }\n if (this.recorded) {\n const changed = specs\n .filter(\n (tool) => !this.recorded!.data.tools[tool.name]?.includes(Fingerprints.tool(tool)),\n )\n .map((tool) => tool.name)\n .sort();\n reasons.push(\n changed.length > 0 ? `tools changed: ${changed.join(\", \")}` : \"the tools offered changed\",\n );\n } else {\n const before = new Set(recordedNames ?? []);\n const now = new Set(sentNames ?? []);\n const added = [...now].filter((name) => !before.has(name));\n const removed = [...before].filter((name) => !now.has(name));\n reasons.push(\n added.length > 0 || removed.length > 0\n ? `tools offered changed (${[\n ...added.map((name) => `+${name}`),\n ...removed.map((name) => `-${name}`),\n ].join(\", \")})`\n : \"the tools offered changed\",\n );\n }\n }\n this.shared.staleCalls++;\n for (const reason of reasons) this.shared.stale.add(reason);\n }\n\n /** Waits until every recorded call that started before `at` has started (`ordered`). */\n private async turn(at: number, where: string): Promise<void> {\n const shared = this.shared;\n shared.pending ??= [...this.calls, ...Object.values(this.recordedNested).flat()]\n .map((call) => call.at)\n .filter((started): started is number => started !== undefined)\n .sort((a, b) => a - b);\n while (shared.pending[0] !== undefined && shared.pending[0] < at) {\n const moved = shared.moved.promise;\n const waited = await Promise.race([\n moved.then(() => true),\n new Promise<boolean>((resolve) => setTimeout(() => resolve(false), this.options.waitMs)),\n ]);\n if (!waited) {\n throw new RecordingMismatchError(\n `${where}: call ${at} waits for call ${shared.pending[0]}, which the replay does not make.`,\n );\n }\n }\n shared.pending = shared.pending.filter((started) => started !== at);\n shared.moved.resolve();\n shared.moved = resolvers();\n }\n\n /** Waits until the app's `position` is at `target` or past it. */\n private async reach(target: number, where: string): Promise<void> {\n const position = this.options.position;\n if (!position) return;\n let last = await position();\n let still = 0;\n while (last < target) {\n await new Promise((resolve) => setTimeout(resolve, 25));\n const now = await position();\n still = now === last ? still + 25 : 0;\n last = now;\n if (still >= this.options.waitMs) {\n throw new RecordingMismatchError(\n `${where}: a call waits for the app to reach ${target}; it stays at ${last}.`,\n );\n }\n }\n }\n}\n",
5
+ "import { createHash } from \"node:crypto\";\n\nimport {\n AgentProvider,\n type ProviderCapabilities,\n type ProviderEvent,\n type ProviderStreamParams,\n type ProviderToolSpec,\n} from \"../AgentProvider\";\nimport { JSONSchemaError, s } from \"../Schema\";\nimport { type FingerprintOptions, Fingerprints, type RecordingFingerprints } from \"./Fingerprints\";\n\n/**\n * One model call, as a recording keeps it: what was sent (normalised, see\n * `RecordingProvider`) and what the model streamed back.\n */\nexport type RecordedCall = {\n request: RecordedRequest;\n events: ProviderEvent[];\n /** When it started among all the calls of the recording, its sub-runs' too (`ordered`). */\n at?: number;\n /** The app's position (`position`) the call's prompt was pinned to (`pin`). */\n read?: number;\n /** The app's position once the call's answer had streamed in full, before its tools ran. */\n ended?: number;\n};\n\n/**\n * A request as recorded. `messages` are the messages new since the call\n * before it (`after` says how many of that call's it resent), each without\n * the parts minted per run; `tools` is a hash of the tool list, and\n * `toolNames` the names it offered.\n */\nexport type RecordedRequest = {\n messages: { role: string; content: unknown }[];\n after?: number;\n tools?: string;\n toolNames?: string[];\n [field: string]: unknown;\n};\n\n/** What a `RecordingProvider` records, and replays from. Plain JSON: write it where you like. */\nexport type Recording = {\n version: 1;\n model: string;\n capabilities: ProviderCapabilities;\n /** When the recording started (ISO). A replay can run at that time: see `pinClock`. */\n recordedAt: string;\n calls: RecordedCall[];\n /** Sub-runs' calls (`nested(key)`), each in its own order. */\n nested?: Record<string, RecordedCall[]>;\n /** What it was made with, when recorded with `fingerprints`. See `Fingerprints`. */\n fingerprints?: RecordingFingerprints;\n};\n\n/** How `replay` matches a request against the recorded one. See `RecordingProviderOptions.match`. */\nexport type RecordingMatch = \"exact\" | \"wording\" | \"shape\";\n\nexport type RecordingProviderOptions = {\n /**\n * What a replayed request may differ in from the recorded one and still\n * replay, counted as `stale` with the reason:\n *\n * - `\"wording\"` (the default): the wording of the prompt files changed since\n * the recording, and nothing else. The static text of those files is cut\n * out of both requests (see `Fingerprints.cutters`), so the messages, the\n * tool calls and results and every value filled into the prompts must\n * still be the same. Needs a recording made with `fingerprints`, and\n * `fingerprints` on the replay to find the files.\n * - `\"shape\"`: anything but the shape of the conversation (its roles, tool\n * calls with their inputs, tool results with their status): instructions,\n * settings and message text. For an app whose prompts are not files.\n * - `\"exact\"`: nothing.\n *\n * In `\"wording\"` and `\"shape\"`, the tools offered may differ too, as long as\n * every tool call the recorded answer makes is to a tool still offered and\n * fits its schema today.\n */\n match?: RecordingMatch;\n /**\n * Fingerprint what the recording is made with (the prompt files its\n * requests carried, its tools' definitions, `inputs`), and, replaying, tell\n * a reworded prompt by them. See `Fingerprints`.\n */\n fingerprints?: FingerprintOptions;\n /**\n * Ids minted per run (a record's id, say), which a replay mints anew. Each\n * recorded id matches the id at its place in the request, the same one\n * wherever it shows, and the recorded answer is given the replay's ids.\n * Default: UUIDs.\n */\n ids?: RegExp;\n /**\n * Replays the calls, the sub-runs' too, in the order they started when\n * recorded (`at`), for runs that go side by side and whose order shows.\n * Off, each run and sub-run replays in its own order, in any interleaving.\n */\n ordered?: boolean;\n /**\n * A position in the app's own state that moves as tools run (an edit log's\n * head, say). Recording, each call keeps where it was; replaying, a call's\n * answer waits until the app gets there again, so tool calls running side by\n * side write in the recorded order. See also `pin`.\n */\n position?: () => number | Promise<number>;\n /** How long a replay waits for `ordered` or `position` before it gives up. Default 60 s. */\n waitMs?: number;\n};\n\n/** A replayed request that is not the recorded one, beyond what `match` tolerates. */\nexport class RecordingMismatchError extends Error {\n constructor(message: string) {\n super(`${message} Record again.`);\n this.name = \"RecordingMismatchError\";\n }\n}\n\nconst UUIDS = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/g;\n\n/** `value` with each of its strings passed through `change`. */\nfunction mapStrings(value: unknown, change: (text: string) => string): unknown {\n if (typeof value === \"string\") return change(value);\n if (Array.isArray(value)) return value.map((item) => mapStrings(item, change));\n if (value && typeof value === \"object\") {\n return Object.fromEntries(\n Object.entries(value).map(([key, inner]) => [key, mapStrings(inner, change)]),\n );\n }\n return value;\n}\n\n/**\n * A message's content without what a run mints and the model is not sent: a\n * tool call's sub-run transcript (`nested`, recorded on its own), and the full\n * output of a tool whose model reads a projection (`modelOutput`).\n */\nfunction withoutTranscripts<T>(value: T): T {\n return JSON.parse(\n JSON.stringify(value, function (this: Record<string, unknown>, key, inner) {\n if (key === \"nested\") return undefined;\n if (key === \"output\" && this.type === \"tool-result\" && \"modelOutput\" in this) {\n return undefined;\n }\n return inner;\n }),\n );\n}\n\nfunction resolvers(): { promise: Promise<void>; resolve: () => void } {\n let resolve!: () => void;\n const promise = new Promise<void>((done) => (resolve = done));\n return { promise, resolve };\n}\n\nconst sha256 = (text: string) => createHash(\"sha256\").update(text).digest(\"hex\");\n\nconst flatTools = (tools: NonNullable<ProviderStreamParams[\"tools\"]>): ProviderToolSpec[] =>\n tools.flatMap((tool) => (\"tools\" in tool ? tool.tools : [tool]));\n\n/**\n * The shape of a conversation, which `match: \"shape\"` keeps: each message's\n * role, its tool calls with their inputs and its tool results with their\n * status, but not its text.\n */\nfunction shapeOf(messages: { role: string; content: unknown }[]): unknown {\n return messages.map(({ role, content }) => ({\n role,\n parts: (Array.isArray(content) ? content : []).flatMap((part: any): unknown[] => {\n if (part?.type === \"tool-call\") return [{ call: part.name, input: part.input ?? part.args }];\n if (part?.type === \"tool-result\") return [{ result: part.name, status: part.status }];\n if (part?.type === \"file\") return [{ file: true }];\n return [];\n }),\n }));\n}\n\ntype Shared = {\n ids: Map<string, string>;\n stale: Set<string>;\n staleCalls: number;\n started: number;\n pending?: number[];\n moved: { promise: Promise<void>; resolve: () => void };\n};\n\n/**\n * A provider that records a live provider's calls, and replays them later\n * without one: model-backed tests and evals that run in CI, offline and for\n * free, and stay the same from run to run.\n *\n * // Recording: every call goes to `live`, and is kept.\n * const recorder = RecordingProvider.record(live);\n * await runTheCase(recorder);\n * await Bun.write(file, JSON.stringify(recorder.recording()));\n *\n * // Replaying: each call is answered with what was recorded for it.\n * const replay = RecordingProvider.replay(await Bun.file(file).json());\n * await runTheCase(replay);\n * replay.stale; // why the recording should be made again, if it should\n *\n * WHAT IS MATCHED. The n-th call replays the n-th recorded call (per run and\n * per sub-run, see `nested`), and it has to be the same request:\n *\n * - Messages are compared without ids and times, which differ per run: only\n * `role` and `content` are kept, without sub-run transcripts. A call resends\n * the messages of the one before it, so only the new ones are recorded\n * (`after`), and a recording grows with the run, not with its square.\n * - Ids minted per run (`ids`, UUIDs by default) are matched by place, and the\n * recorded answer is given the replay's ids.\n * - The tool list is compared by its hash.\n *\n * A request that differs is stale rather than a mismatch only as far as\n * `match` allows. With `\"wording\"` (the default) that is the rewording of\n * prompt files changed since the recording: their static text is cut out of\n * both requests and the rest must be the same (see `Fingerprints`). The tools\n * offered may differ too, as long as each tool call the recorded answer makes\n * still exists and fits its schema today: replaying a call that doesn't\n * would test nothing. A stale call replays and is counted in `stale` with the\n * reason. Anything else throws a `RecordingMismatchError` that shows where\n * the two differ.\n *\n * UPLOADS are answered `upload_<n>`, by order, so a file need not be the same\n * bytes on another machine for its call to replay. A sub-run counts its own,\n * `upload_<key>_<n>`, so the ids stay the same however sub-runs interleave.\n * Recording, the file goes to the live provider, and the calls show the model\n * the provider's id.\n *\n * TIME. `recordedAt` is when the recording started. `pinClock(recordedAt)`\n * runs a replay at that time, so dates relative to today come out as recorded.\n */\nexport class RecordingProvider extends AgentProvider {\n readonly model: string;\n readonly capabilities: ProviderCapabilities;\n /** When the recording started. */\n readonly recordedAt: Date;\n private readonly calls: RecordedCall[];\n /** Replaying: the recorded calls of the sub-runs, by key. */\n private readonly recordedNested: Record<string, RecordedCall[]>;\n private readonly children = new Map<string, RecordingProvider>();\n private parent?: RecordingProvider;\n private readonly key?: string;\n /** The messages of the previous call, which the next call's are recorded after. */\n private sent: unknown[] = [];\n /** Recording: the live provider's file id of each upload, by the id answered here. */\n private readonly uploads: Map<string, string>;\n /** Uploads answered so far, counted per run and per sub-run. */\n private uploadCount = 0;\n /** Recording: the position the next call's prompt was pinned to. */\n private read?: number;\n private readonly shared: Shared;\n private readonly options: Required<Pick<RecordingProviderOptions, \"match\" | \"ids\" | \"waitMs\">> &\n RecordingProviderOptions;\n /** What the calls sent, for the fingerprints: every string, and each tool's definition hashes. */\n private readonly texts = new Set<string>();\n private readonly toolHashes = new Map<string, Set<string>>();\n private readonly toolLists = new Set<string>();\n /** Replaying: the recording's fingerprints, and how a differing request is cut by them. */\n private recorded?: Fingerprints;\n private cuts?: ReturnType<Fingerprints[\"cutters\"]>;\n\n private constructor(\n private readonly live: AgentProvider | undefined,\n recording: Recording | undefined,\n options: RecordingProviderOptions,\n child?: { parent: RecordingProvider; key: string; calls: RecordedCall[] },\n ) {\n super();\n this.options = {\n ...options,\n match: options.match ?? \"wording\",\n ids: new RegExp(options.ids ?? UUIDS, \"g\"),\n waitMs: options.waitMs ?? 60_000,\n };\n if (child) {\n const { parent } = child;\n this.parent = parent;\n this.key = child.key;\n this.model = parent.model;\n this.capabilities = parent.capabilities;\n this.recordedAt = parent.recordedAt;\n this.calls = child.calls;\n this.recordedNested = {};\n this.uploads = parent.uploads;\n this.shared = parent.shared;\n return;\n }\n this.shared = {\n ids: new Map(),\n stale: new Set(),\n staleCalls: 0,\n started: 0,\n moved: resolvers(),\n };\n this.uploads = new Map();\n if (live) {\n this.model = live.model;\n this.capabilities = live.capabilities;\n this.recordedAt = new Date();\n this.calls = [];\n this.recordedNested = {};\n return;\n }\n if (!recording || recording.version !== 1 || !Array.isArray(recording.calls)) {\n throw new Error(\"RecordingProvider.replay needs a recording made by RecordingProvider.\");\n }\n this.model = recording.model;\n this.capabilities = recording.capabilities;\n this.recordedAt = new Date(recording.recordedAt);\n this.calls = structuredClone(recording.calls);\n this.recordedNested = structuredClone(recording.nested ?? {});\n if (recording.fingerprints) {\n this.recorded = new Fingerprints(recording.fingerprints, options.fingerprints);\n }\n }\n\n /** Records every call made through it to `live`, which answers it. */\n static record(live: AgentProvider, options: RecordingProviderOptions = {}): RecordingProvider {\n return new RecordingProvider(live, undefined, options);\n }\n\n /** Answers each call with the recorded one. See the class for how calls are matched. */\n static replay(recording: Recording, options: RecordingProviderOptions = {}): RecordingProvider {\n return new RecordingProvider(undefined, recording, options);\n }\n\n /** Whether it records (true) or replays. */\n get isRecording(): boolean {\n return this.live !== undefined;\n }\n\n /**\n * Why the replay should be recorded again: the parts of the requests that\n * differed and were tolerated (`match`). Empty for a replay\n * that matched exactly, and for a recording.\n */\n get stale(): ReadonlySet<string> {\n return this.shared.stale;\n }\n\n /** How many calls replayed stale, the sub-runs' included. */\n get staleCalls(): number {\n return this.shared.staleCalls;\n }\n\n /**\n * The provider of sub-run `key` (a sub-agent's, say), recorded and replayed\n * apart from this one's calls and the other sub-runs', so sub-runs running\n * side by side can replay in any interleaving. The same key answers the same\n * provider, so a sub-run continued later goes on after its calls. Replaying\n * a key the recording does not have throws.\n */\n nested(key: string): RecordingProvider {\n if (this.parent) return this.parent.nested(key);\n let child = this.children.get(key);\n if (!child) {\n const calls = this.recordedNested[key];\n if (!this.live && !calls) {\n throw new RecordingMismatchError(`The recording has no sub-run \"${key}\".`);\n }\n child = new RecordingProvider(this.live, undefined, this.options, {\n parent: this,\n key,\n calls: calls ?? [],\n });\n this.children.set(key, child);\n }\n return child;\n }\n\n /**\n * The recording so far: every call made through this provider and its\n * sub-runs. Write it as JSON. Only for a provider made with `record`.\n */\n recording(): Recording {\n if (this.parent) return this.parent.recording();\n if (!this.live)\n throw new Error(\"Only a recording provider (`record`) has a recording to save.\");\n return {\n version: 1,\n model: this.model,\n capabilities: this.capabilities,\n recordedAt: this.recordedAt.toISOString(),\n calls: structuredClone(this.calls),\n ...(this.options.fingerprints ? { fingerprints: this.fingerprints().data } : {}),\n ...(this.children.size > 0\n ? {\n nested: Object.fromEntries(\n [...this.children].map(([key, child]) => [key, structuredClone(child.calls)]),\n ),\n }\n : {}),\n };\n }\n\n /**\n * The fingerprints of what the calls sent so far, the sub-runs' included:\n * of this recording, or of this replay (compare it with the recording's to\n * tell whether a new recording would differ). Uses the `fingerprints`\n * options for where prompts live.\n */\n fingerprints(): Fingerprints {\n const root = this.parent ?? this;\n return Fingerprints.of(root.texts, root.toolHashes, this.options.fingerprints);\n }\n\n /**\n * What changed since `recording` was made, without replaying it: the prompt\n * files and inputs its fingerprints name that differ today. Empty for a\n * recording without fingerprints. For listing the recordings to make again.\n */\n static changedSince(recording: Recording, options: FingerprintOptions = {}): string[] {\n return recording.fingerprints\n ? new Fingerprints(recording.fingerprints, options).changed()\n : [];\n }\n\n /**\n * Replaying: whether every recorded call was made, the sub-runs' too. A run\n * that took another path and stopped early made fewer.\n */\n replayedInFull(): boolean {\n const root = this.parent ?? this;\n return (\n root.calls.length === 0 &&\n Object.entries(root.recordedNested).every(\n ([key, calls]) => (root.children.get(key)?.calls ?? calls).length === 0,\n )\n );\n }\n\n /**\n * The position (`position`) the next call's prompt should show the app at,\n * given `now`, where it is. Recording, that is `now`, kept with the call.\n * Replaying, it is the recorded position, once the app has got there, so a\n * prompt rendered from the app's state is the one that was recorded,\n * however the other runs were timed.\n */\n async pin(now: number): Promise<number> {\n if (this.live) {\n this.read = now;\n return now;\n }\n const read = this.calls[0]?.read;\n if (read === undefined) return now;\n await (this.parent ?? this).reach(read, this.where());\n return read;\n }\n\n async upload(file: File): Promise<string> {\n const n = ++this.uploadCount;\n const id = this.key === undefined ? `upload_${n}` : `upload_${this.key}_${n}`;\n if (this.live) this.uploads.set(id, await this.live.upload(file));\n return id;\n }\n\n /** Deletes the live copy of a recorded upload; a replay has nothing to delete. */\n override async deleteFile(fileId: string): Promise<void> {\n const live = this.uploads.get(fileId);\n if (this.live && live !== undefined) {\n if (!this.live.deleteFile) {\n throw new Error(`${this.live.constructor.name} cannot delete provider files: it does not implement deleteFile().`);\n }\n await this.live.deleteFile(live);\n this.uploads.delete(fileId);\n }\n }\n\n normalizeError(error: unknown) {\n return this.live ? this.live.normalizeError(error) : super.normalizeError(error);\n }\n\n async *stream(params: ProviderStreamParams): AsyncGenerator<ProviderEvent> {\n const request = this.requestOf(params);\n if (this.live) {\n yield* this.recordCall(params, request);\n return;\n }\n yield* this.replayCall(params, request);\n }\n\n // --- recording ---------------------------------------------------------------\n\n private async *recordCall(\n params: ProviderStreamParams,\n request: RecordedRequest,\n ): AsyncGenerator<ProviderEvent> {\n const root = this.parent ?? this;\n const at = root.shared.started++;\n const read = this.read;\n this.read = undefined;\n const events: ProviderEvent[] = [];\n // The live call shows the model the files it uploaded, by the provider's ids.\n const messages = params.messages.map((message) => ({\n ...message,\n content: message.content.map((part) =>\n part.type === \"file\" && part.fileId && this.uploads.has(part.fileId)\n ? { ...part, fileId: this.uploads.get(part.fileId) }\n : part,\n ),\n }));\n for await (const event of this.live!.stream({ ...params, messages })) {\n const last = events.at(-1);\n if (event.type === \"tool-call-discard\") {\n // The provider asked again: the discarded calls' deltas are void.\n const discarded = new Set(event.toolCallIds);\n const kept = events.filter(\n (e) => e.type !== \"tool-call-delta\" || !discarded.has(e.toolCallId),\n );\n events.splice(0, events.length, ...kept);\n } else if (event.type === \"retry\") {\n // How the live call went, not what it answered.\n } else if (\n last &&\n (event.type === \"text-delta\" || event.type === \"output-delta\") &&\n last.type === event.type\n ) {\n // Consecutive deltas are kept as one, which replays the same text.\n last.delta += event.delta;\n } else if (\n last?.type === \"tool-call-delta\" &&\n event.type === \"tool-call-delta\" &&\n last.toolCallId === event.toolCallId\n ) {\n last.argsDelta += event.argsDelta;\n } else {\n events.push({ ...event });\n }\n yield event;\n }\n const ended = this.options.position ? await this.options.position() : undefined;\n this.calls.push({\n request,\n events,\n at,\n ...(read !== undefined ? { read } : {}),\n ...(ended !== undefined ? { ended } : {}),\n });\n }\n\n // --- replaying ---------------------------------------------------------------\n\n private async *replayCall(\n params: ProviderStreamParams,\n request: RecordedRequest,\n ): AsyncGenerator<ProviderEvent> {\n const root = this.parent ?? this;\n const where = this.where();\n const next = this.calls[0];\n if (this.options.ordered && next?.at !== undefined) await root.turn(next.at, where);\n const call = this.calls.shift();\n if (!call) {\n throw new RecordingMismatchError(\n `${where}: call ${this.sentCalls} was not recorded (the recording has no more calls).`,\n );\n }\n // A recording made with 0.204.0 kept the request's `promptCacheKey`: it is\n // not compared (see `requestOf`).\n const { promptCacheKey: _cacheKey, ...recorded } = call.request;\n if (!root.matches(JSON.stringify(recorded), request)) {\n root.tolerate(\n where,\n { ...call, request: recorded as RecordedRequest },\n request,\n params.tools ?? [],\n );\n }\n if (call.ended !== undefined) await root.reach(call.ended, where);\n const ids = root.shared.ids;\n for (const event of call.events) {\n yield JSON.parse(\n JSON.stringify(event).replace(this.options.ids, (id) => ids.get(id) ?? id),\n ) as ProviderEvent;\n }\n }\n\n private where(): string {\n return this.key === undefined ? \"the recording\" : `sub-run \"${this.key}\"`;\n }\n\n /** How many calls were made through this provider (not its sub-runs). */\n private sentCalls = 0;\n\n /**\n * The request as it is recorded and matched: see the class. Also moves\n * `sent` on, so the next call is recorded after this one.\n */\n private requestOf(params: ProviderStreamParams): RecordedRequest {\n this.sentCalls++;\n // `promptCacheKey` is derived from the prompt and the tools (#1228): it\n // changes whenever they are reworded, and recordings made before it have\n // none. It says nothing the request doesn't already say, so it is neither\n // matched nor fingerprinted (#1231).\n const { signal: _signal, promptCacheKey: _cacheKey, messages, tools, ...rest } = params;\n const sent = messages.map(({ role, content }) => ({\n role,\n content: withoutTranscripts(content),\n }));\n const after =\n this.sent.length > 0 &&\n this.sent.length <= sent.length &&\n JSON.stringify(sent.slice(0, this.sent.length)) === JSON.stringify(this.sent)\n ? this.sent.length\n : 0;\n this.sent = sent;\n const listed = tools && tools.length > 0 ? JSON.stringify(tools) : undefined;\n const root = this.parent ?? this;\n const keep = (text: string) => {\n root.texts.add(text);\n return text;\n };\n mapStrings([rest, sent.slice(after)], keep);\n if (listed && !root.toolLists.has(listed)) {\n root.toolLists.add(listed);\n for (const tool of flatTools(tools!)) {\n mapStrings(tool, keep);\n const hashes = root.toolHashes.get(tool.name) ?? new Set<string>();\n hashes.add(Fingerprints.tool(tool));\n root.toolHashes.set(tool.name, hashes);\n }\n }\n return {\n ...(withoutTranscripts(rest) as Record<string, unknown>),\n ...(listed\n ? {\n tools: `sha256:${sha256(listed)}`,\n toolNames: flatTools(tools!)\n .map((tool) => tool.name)\n .sort(),\n }\n : {}),\n ...(after > 0 ? { after } : {}),\n messages: sent.slice(after),\n };\n }\n\n /**\n * Whether `request` is the recorded one (`recorded`, as JSON), with each\n * recorded id matched to the id at its place in the request, the same one\n * every time it shows (`ids`, shared by the runs and sub-runs).\n */\n private matches(recorded: string, request: unknown): boolean {\n const pattern = this.options.ids;\n const sent = JSON.stringify(request);\n const theirs = recorded.match(pattern) ?? [];\n const ours = sent.match(pattern) ?? [];\n if (theirs.length !== ours.length) return false;\n const ids = new Map(this.shared.ids);\n for (const [index, id] of theirs.entries()) {\n const mapped = ids.get(id) ?? ours[index]!;\n if (mapped !== ours[index]) return false;\n ids.set(id, mapped);\n }\n if (recorded.replace(pattern, (id) => ids.get(id)!) !== sent) return false;\n for (const [id, mapped] of ids) this.shared.ids.set(id, mapped);\n return true;\n }\n\n /**\n * A request that is not the recorded one. It replays, stale, when what\n * differs is what `match` allows (see `RecordingProviderOptions.match`), and\n * every tool call of the recorded answer fits today's tools if those differ.\n * Throws otherwise, showing where the two first differ.\n */\n private tolerate(\n where: string,\n call: RecordedCall,\n request: RecordedRequest,\n tools: NonNullable<ProviderStreamParams[\"tools\"]>,\n ): void {\n const pattern = this.options.ids;\n const match = this.options.match;\n const recorded = call.request;\n const differs = (theirs: unknown, ours: unknown, why: string): never => {\n // Where they first differ, ids aside (they are matched by place).\n const a = JSON.stringify(theirs).replace(pattern, \"<id>\");\n const b = JSON.stringify(ours).replace(pattern, \"<id>\");\n let at = 0;\n while (at < a.length && a[at] === b[at]) at++;\n throw new RecordingMismatchError(\n `${where}: the request differs from the recorded one${why}. Recorded: …${a.slice(Math.max(0, at - 80), at + 120)}… Sent: …${b.slice(Math.max(0, at - 80), at + 120)}…`,\n );\n };\n if (match === \"exact\") differs(recorded, request, \"\");\n\n const { tools: recordedTools, toolNames: recordedNames, ...recordedRest } = recorded;\n const { tools: sentTools, toolNames: sentNames, ...sentRest } = request;\n const reasons: string[] = [];\n\n if (!this.matches(JSON.stringify(recordedRest), sentRest)) {\n if (match === \"wording\") {\n if (!this.recorded) {\n differs(\n recordedRest,\n sentRest,\n \", and the recording has no fingerprints to tell a reworded prompt by\",\n );\n }\n try {\n this.cuts ??= this.recorded!.cutters();\n } catch (error) {\n throw new RecordingMismatchError(`${where}: ${(error as Error).message}.`);\n }\n const theirs = mapStrings(recordedRest, this.cuts.recorded);\n const ours = mapStrings(sentRest, this.cuts.sent);\n if (this.cuts.changed.length === 0 || !this.matches(JSON.stringify(theirs), ours)) {\n differs(\n theirs,\n ours,\n this.cuts.changed.length > 0 ? \", beyond the wording of the prompts changed since\" : \"\",\n );\n }\n reasons.push(...this.cuts.changed.map((path) => `${path} changed`));\n } else {\n // The conversation's shape, ids matched by place as for an exact match.\n const sameShape =\n (recorded.after ?? 0) === (request.after ?? 0) &&\n this.matches(JSON.stringify(shapeOf(recorded.messages)), shapeOf(request.messages));\n if (!sameShape) differs(recordedRest, sentRest, \" in the conversation itself\");\n const { messages: recordedMessages, ...recordedSettings } = recordedRest;\n const { messages: sentMessages, ...sentSettings } = sentRest;\n if (!this.matches(JSON.stringify(recordedMessages), sentMessages)) {\n reasons.push(\"message text changed\");\n }\n const fields = new Set([...Object.keys(recordedSettings), ...Object.keys(sentSettings)]);\n for (const field of [...fields].sort()) {\n const theirs = JSON.stringify(recordedSettings[field] ?? null);\n if (!this.matches(theirs, sentSettings[field] ?? null)) reasons.push(`${field} changed`);\n }\n }\n }\n\n if (recordedTools !== sentTools) {\n const specs = flatTools(tools);\n for (const event of call.events) {\n if (event.type !== \"tool-call\") continue;\n const spec = specs.find((tool) => tool.name === event.name);\n if (!spec) {\n throw new RecordingMismatchError(\n `${where}: the recorded answer calls ${event.name}, which is not offered any more.`,\n );\n }\n // Formats are hints here: the tool checks them itself when the call runs.\n const formats = Object.fromEntries(\n [...JSON.stringify(spec.parameters).matchAll(/\"format\":\"([^\"]+)\"/g)].map(([, f]) => [\n f!,\n true as const,\n ]),\n );\n let input: unknown;\n try {\n input = JSON.parse(event.args || \"{}\");\n } catch {\n input = undefined;\n }\n // A schema `fromJSONSchema` can't model (a free-form part, such as an\n // object value with no type) isn't checked here (#1234): the tool still\n // validates its input when the call runs, as for formats.\n let schema: ReturnType<typeof s.fromJSONSchema> | undefined;\n try {\n schema = s.fromJSONSchema(spec.parameters as never, { unknownKeys: \"error\", formats });\n } catch (error) {\n if (!(error instanceof JSONSchemaError)) throw error;\n }\n const checked = schema?.safeParse(input);\n if (checked && checked.ok === false) {\n throw new RecordingMismatchError(\n `${where}: the recorded call of ${event.name} does not fit its schema any more (${checked.errors.join(\"; \")}).`,\n );\n }\n }\n if (this.recorded) {\n const changed = specs\n .filter(\n (tool) => !this.recorded!.data.tools[tool.name]?.includes(Fingerprints.tool(tool)),\n )\n .map((tool) => tool.name)\n .sort();\n reasons.push(\n changed.length > 0 ? `tools changed: ${changed.join(\", \")}` : \"the tools offered changed\",\n );\n } else {\n const before = new Set(recordedNames ?? []);\n const now = new Set(sentNames ?? []);\n const added = [...now].filter((name) => !before.has(name));\n const removed = [...before].filter((name) => !now.has(name));\n reasons.push(\n added.length > 0 || removed.length > 0\n ? `tools offered changed (${[\n ...added.map((name) => `+${name}`),\n ...removed.map((name) => `-${name}`),\n ].join(\", \")})`\n : \"the tools offered changed\",\n );\n }\n }\n this.shared.staleCalls++;\n for (const reason of reasons) this.shared.stale.add(reason);\n }\n\n /** Waits until every recorded call that started before `at` has started (`ordered`). */\n private async turn(at: number, where: string): Promise<void> {\n const shared = this.shared;\n shared.pending ??= [...this.calls, ...Object.values(this.recordedNested).flat()]\n .map((call) => call.at)\n .filter((started): started is number => started !== undefined)\n .sort((a, b) => a - b);\n while (shared.pending[0] !== undefined && shared.pending[0] < at) {\n const moved = shared.moved.promise;\n const waited = await Promise.race([\n moved.then(() => true),\n new Promise<boolean>((resolve) => setTimeout(() => resolve(false), this.options.waitMs)),\n ]);\n if (!waited) {\n throw new RecordingMismatchError(\n `${where}: call ${at} waits for call ${shared.pending[0]}, which the replay does not make.`,\n );\n }\n }\n shared.pending = shared.pending.filter((started) => started !== at);\n shared.moved.resolve();\n shared.moved = resolvers();\n }\n\n /** Waits until the app's `position` is at `target` or past it. */\n private async reach(target: number, where: string): Promise<void> {\n const position = this.options.position;\n if (!position) return;\n let last = await position();\n let still = 0;\n while (last < target) {\n await new Promise((resolve) => setTimeout(resolve, 25));\n const now = await position();\n still = now === last ? still + 25 : 0;\n last = now;\n if (still >= this.options.waitMs) {\n throw new RecordingMismatchError(\n `${where}: a call waits for the app to reach ${target}; it stays at ${last}.`,\n );\n }\n }\n }\n}\n",
6
6
  "import { createHash } from \"node:crypto\";\nimport { existsSync, readdirSync, readFileSync, statSync } from \"node:fs\";\nimport { join, relative, sep } from \"node:path\";\n\n/**\n * What a recording was made with, kept on it (`Recording.fingerprints`):\n *\n * - `prompts`: each prompt file whose text the requests carried, by its path\n * from `root`, as its git blob id, so the version it was recorded with can\n * be read back from git;\n * - `tools`: each tool the requests offered, by name, as the hashes of its\n * definitions (description and parameters);\n * - `inputs`: anything else the app says the recording depends on\n * (`FingerprintOptions.inputs`), such as the schemas behind generated\n * tools, hashed by name.\n */\nexport type RecordingFingerprints = {\n prompts: Record<string, string>;\n tools: Record<string, string[]>;\n inputs?: Record<string, string>;\n};\n\n/** Where a recording's prompt files are, and how to read their recorded versions back. */\nexport type FingerprintOptions = {\n /** The repository root that paths are relative to, and git runs in. Default the working directory. */\n root?: string;\n /** The folders, relative to `root`, that prompt files (`*.md`) live in. Default `[\"app/agents\"]`, gemi's. */\n dirs?: string[];\n /** The folder under a prompt folder that a bare partial name (`{{> tone}}`) resolves in. Default `prompts`, as `Prompt.render`. */\n shared?: string;\n /**\n * A prompt file's text by its git blob id, for the version a recording was\n * made with. Default `git cat-file blob <id>` in `root`. `undefined` when it\n * can't be found.\n */\n readBlob?: (blob: string) => string | undefined;\n /**\n * Other inputs the recording depends on, hashed by name, given the names of\n * the tools its requests offered: the component schemas behind generated\n * `add_` tools, say. Called when recording, and again to tell what changed.\n */\n inputs?: (tools: ReadonlySet<string>) => Record<string, string>;\n};\n\n/** What a piece of a prompt's static text is replaced with when it is cut out of a request. */\nconst CUT = \"␟\";\n/** Prompt text shorter than this is cut only next to a cut: it could be part of a value as well. */\nconst SHORTEST = 6;\nconst PARTIAL = /\\{\\{>\\s*([^}\\s]+)\\s*\\}\\}/g;\n\nconst escape = (text: string) => text.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n\n/**\n * Cuts `pieces` of prompt text out of a text, leaving a mark (and no\n * whitespace) where each was. A short piece (a full stop between a\n * placeholder and a partial) is cut only where it touches a cut.\n */\nfunction cutOut(pieces: string[]): (text: string) => string {\n const long = pieces.filter((piece) => piece.length >= SHORTEST);\n const short = pieces.filter((piece) => piece.length < SHORTEST);\n return (text) => {\n let left = text;\n for (const piece of long) if (left.includes(piece)) left = left.split(piece).join(CUT);\n for (const piece of short) {\n left = left\n .replace(new RegExp(`${escape(piece)}\\\\s*${CUT}`, \"g\"), CUT)\n .replace(new RegExp(`${CUT}\\\\s*${escape(piece)}`, \"g\"), CUT);\n }\n return left.replace(new RegExp(`\\\\s*${CUT}[\\\\s${CUT}]*`, \"g\"), CUT);\n };\n}\n\nfunction scan(dir: string, out: string[] = []): string[] {\n for (const entry of readdirSync(dir)) {\n if (entry === \"node_modules\") continue;\n const path = join(dir, entry);\n if (statSync(path).isDirectory()) scan(path, out);\n else if (entry.endsWith(\".md\")) out.push(path);\n }\n return out;\n}\n\n/**\n * A recording's fingerprints, and what they tell about it today: which of the\n * prompts, tools and inputs it was made with have changed (`changed`), and how\n * to compare a request across a prompt's rewording (`cutters`).\n *\n * A replayed call whose request differs only in the wording of the prompt\n * files changed since the recording is stale, not a mismatch: the static text\n * of those files is cut out of both sides (the recorded version, read back from\n * git, out of the recorded request; today's out of the replay's), so the\n * messages, the tool calls and results and every value filled into the\n * prompts must still be the same.\n */\nexport class Fingerprints {\n readonly root: string;\n private readonly options: FingerprintOptions;\n\n constructor(\n readonly data: RecordingFingerprints,\n options: FingerprintOptions = {},\n ) {\n this.options = options;\n this.root = options.root ?? process.cwd();\n }\n\n /** A text's git blob id (`git hash-object`). */\n static blob(text: string): string {\n return createHash(\"sha1\")\n .update(`blob ${Buffer.byteLength(text)}\\0`)\n .update(text)\n .digest(\"hex\");\n }\n\n /** A prompt's static text: the pieces between its placeholders and partials. */\n static pieces(text: string): string[] {\n return text\n .split(/\\{\\{[^}]*\\}\\}/)\n .map((piece) => piece.trim())\n .filter((piece) => piece.length > 0);\n }\n\n /** A tool definition's hash, as `tools` keeps it. */\n static tool(tool: { description?: string; parameters?: unknown }): string {\n return createHash(\"sha256\")\n .update(JSON.stringify({ description: tool.description, parameters: tool.parameters }))\n .digest(\"hex\");\n }\n\n /** The prompt files under the configured folders today, by path from `root`. */\n static prompts(options: FingerprintOptions = {}): Map<string, string> {\n const root = options.root ?? process.cwd();\n const prompts = new Map<string, string>();\n for (const dir of options.dirs ?? [\"app/agents\"]) {\n if (!existsSync(join(root, dir))) continue;\n for (const path of scan(join(root, dir)).sort()) {\n prompts.set(relative(root, path).split(sep).join(\"/\"), readFileSync(path, \"utf8\"));\n }\n }\n return prompts;\n }\n\n /**\n * The fingerprints of what requests sent: `texts`, every string they\n * carried, and `tools`, each tool's definition hashes by name. A prompt file\n * counts as sent when one of its three longest pieces of static text (of 12\n * characters or more) is in `texts`.\n */\n static of(\n texts: Iterable<string>,\n tools: ReadonlyMap<string, ReadonlySet<string>>,\n options: FingerprintOptions = {},\n ): Fingerprints {\n const sent = [...texts].join(\"\\n\\0\\n\");\n const prompts: Record<string, string> = {};\n for (const [path, text] of Fingerprints.prompts(options)) {\n const longest = Fingerprints.pieces(text)\n .filter((piece) => piece.length >= 12)\n .sort((a, b) => b.length - a.length)\n .slice(0, 3);\n if (longest.some((piece) => sent.includes(piece))) prompts[path] = Fingerprints.blob(text);\n }\n const names = [...tools.keys()].sort();\n const inputs = options.inputs?.(new Set(names));\n return new Fingerprints(\n {\n prompts,\n tools: Object.fromEntries(names.map((name) => [name, [...tools.get(name)!].sort()])),\n ...(inputs && Object.keys(inputs).length > 0 ? { inputs: sortKeys(inputs) } : {}),\n },\n options,\n );\n }\n\n /** Whether `other` says the same. */\n same(other: Fingerprints | RecordingFingerprints): boolean {\n const data = other instanceof Fingerprints ? other.data : other;\n return JSON.stringify(this.data) === JSON.stringify(data);\n }\n\n /**\n * What differs today from what the recording was made with, without running\n * anything: each prompt file changed or gone (its path) and each input\n * changed or gone (`input <name>`). Tools defined in code are compared by a\n * replay, which offers them.\n */\n changed(): string[] {\n const today = this.options.inputs?.(new Set(Object.keys(this.data.tools))) ?? {};\n return [\n ...this.changedPrompts().map(([path]) => path),\n ...Object.entries(this.data.inputs ?? {})\n .filter(([name, hash]) => today[name] !== hash)\n .map(([name]) => `input ${name}`),\n ];\n }\n\n /**\n * How each side of a differing request is cut before the two are compared:\n * the static text of every prompt file changed since the recording (and of\n * the partials each version of it includes) is cut out, the recorded\n * version's from the recorded request and today's from the replay's.\n * `changed` names those files. Throws when a changed prompt's recorded\n * version can't be read back.\n */\n cutters(): {\n changed: string[];\n recorded: (text: string) => string;\n sent: (text: string) => string;\n } {\n const today = Fingerprints.prompts(this.options);\n const changed = this.changedPrompts();\n const recorded = new Map<string, string>();\n const sent = new Map<string, string>();\n for (const [path, blob] of changed) {\n const text = this.readBlob(blob);\n if (text === undefined) {\n throw new Error(\n `${path} changed since the recording, and the version it was recorded with (${blob}) can't be read back from git`,\n );\n }\n recorded.set(path, text);\n if (today.has(path)) sent.set(path, today.get(path)!);\n }\n return {\n changed: changed.map(([path]) => path),\n recorded: cutOut(\n this.piecesWithPartials(recorded, (path) => {\n const blob = this.data.prompts[path];\n return (blob && this.readBlob(blob)) || today.get(path);\n }),\n ),\n sent: cutOut(this.piecesWithPartials(sent, (path) => today.get(path))),\n };\n }\n\n /** The prompt files that changed or are gone since the recording, with their recorded blob ids. */\n private changedPrompts(): [string, string][] {\n const today = Fingerprints.prompts(this.options);\n return Object.entries(this.data.prompts).filter(([path, blob]) => {\n const text = today.get(path);\n return text === undefined || Fingerprints.blob(text) !== blob;\n });\n }\n\n private readBlob(blob: string): string | undefined {\n if (this.options.readBlob) return this.options.readBlob(blob);\n const git = Bun.spawnSync([\"git\", \"cat-file\", \"blob\", blob], { cwd: this.root });\n return git.exitCode === 0 ? git.stdout.toString() : undefined;\n }\n\n /**\n * The static text of `texts` and of the partials each includes, longest\n * first: moving text into a partial is a change of wording too. Partials\n * resolve as `Prompt.render` resolves them.\n */\n private piecesWithPartials(\n texts: Map<string, string>,\n version: (path: string) => string | undefined,\n ): string[] {\n const dirs = this.options.dirs ?? [\"app/agents\"];\n const shared = this.options.shared ?? \"prompts\";\n const pending = [...texts];\n while (pending.length > 0) {\n const [path, text] = pending.pop()!;\n const dir = dirs.find((d) => path.startsWith(`${d}/`));\n if (dir === undefined) continue;\n for (const [, name] of text.matchAll(PARTIAL)) {\n const partial = `${dir}/${name!.includes(\"/\") ? name : `${shared}/${name}`}.md`;\n const body = texts.has(partial) ? undefined : version(partial);\n if (body === undefined) continue;\n texts.set(partial, body);\n pending.push([partial, body]);\n }\n }\n return [...texts.values()]\n .flatMap((text) => Fingerprints.pieces(text))\n .sort((a, b) => b.length - a.length);\n }\n}\n\nfunction sortKeys(record: Record<string, string>): Record<string, string> {\n return Object.fromEntries(Object.entries(record).sort(([a], [b]) => a.localeCompare(b)));\n}\n",
7
7
  "/**\n * Runs the process's clock from `at`: `Date.now()` and `new Date()` answer\n * `at` plus the time since the call, until the returned function puts the real\n * clock back. For replaying a recording (`RecordingProvider.recordedAt`), so\n * dates relative to today (\"in three days\", \"this week\") come out as they were\n * recorded. Timers are not touched: time still passes at its real rate.\n *\n * const restore = pinClock(replay.recordedAt);\n * try {\n * await runTheCase(replay);\n * } finally {\n * restore();\n * }\n *\n * Process-wide, like the clock it replaces: don't run two pinned replays side\n * by side. Inside vitest, `vi.setSystemTime` does the same job.\n */\nexport function pinClock(at: Date | string | number): () => void {\n const RealDate = globalThis.Date;\n const offset = new RealDate(at).getTime() - RealDate.now();\n if (!Number.isFinite(offset)) throw new Error(`pinClock: ${String(at)} is not a date.`);\n\n class PinnedDate extends RealDate {\n constructor(...args: unknown[]) {\n if (args.length === 0) super(RealDate.now() + offset);\n else super(...(args as [string | number | Date]));\n }\n\n static now(): number {\n return RealDate.now() + offset;\n }\n }\n globalThis.Date = PinnedDate as DateConstructor;\n return () => {\n if (globalThis.Date === (PinnedDate as DateConstructor)) globalThis.Date = RealDate;\n };\n}\n"
8
8
  ],
9
- "mappings": ";wKAAA,mBAAS,aCAT,mBAAS,eACT,qBAAS,iBAAY,kBAAa,cAAc,WAChD,eAAS,cAAM,SAAU,aA2CzB,IAAM,EAAM,SAEN,EAAW,EACX,EAAU,4BAEV,EAAS,CAAC,IAAiB,EAAK,QAAQ,sBAAuB,MAAM,EAO3E,SAAS,CAAM,CAAC,EAA4C,CAC1D,IAAM,EAAO,EAAO,OAAO,CAAC,IAAU,EAAM,QAAU,CAAQ,EACxD,EAAQ,EAAO,OAAO,CAAC,IAAU,EAAM,OAAS,CAAQ,EAC9D,MAAO,CAAC,IAAS,CACf,IAAI,EAAO,EACX,QAAW,KAAS,EAAM,GAAI,EAAK,SAAS,CAAK,EAAG,EAAO,EAAK,MAAM,CAAK,EAAE,KAAK,CAAG,EACrF,QAAW,KAAS,EAClB,EAAO,EACJ,QAAQ,IAAI,OAAO,GAAG,EAAO,CAAK,QAAQ,IAAO,GAAG,EAAG,CAAG,EAC1D,QAAQ,IAAI,OAAO,GAAG,QAAU,EAAO,CAAK,IAAK,GAAG,EAAG,CAAG,EAE/D,OAAO,EAAK,QAAQ,IAAI,OAAO,OAAO,QAAU,MAAS,GAAG,EAAG,CAAG,GAItE,SAAS,CAAI,CAAC,EAAa,EAAgB,CAAC,EAAa,CACvD,QAAW,KAAS,EAAY,CAAG,EAAG,CACpC,GAAI,IAAU,eAAgB,SAC9B,IAAM,EAAO,EAAK,EAAK,CAAK,EAC5B,GAAI,EAAS,CAAI,EAAE,YAAY,EAAG,EAAK,EAAM,CAAG,EAC3C,QAAI,EAAM,SAAS,KAAK,EAAG,EAAI,KAAK,CAAI,EAE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S,IAAI,EACzD,GAAI,CAAC,OAAO,SAAS,CAAM,EAAG,MAAU,MAAM,aAAa,OAAO,CAAE,kBAAkB,EAEtF,MAAM,UAAmB,CAAS,CAChC,WAAW,IAAI,EAAiB,CAC9B,GAAI,EAAK,SAAW,EAAG,MAAM,EAAS,IAAI,EAAI,CAAM,EAC/C,WAAM,GAAI,CAAiC,QAG3C,IAAG,EAAW,CACnB,OAAO,EAAS,IAAI,EAAI,EAE5B,CAEA,OADA,WAAW,KAAO,EACX,IAAM,CACX,GAAI,WAAW,OAAU,EAAgC,WAAW,KAAO",
10
+ "debugId": "BEC7B241B241AB0164756E2164756E21",
11
11
  "names": []
12
12
  }
package/dist/app/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // @bun
2
- import{Sa as a}from"../chunk-t0519abr.js";import"../chunk-bw1mvk6n.js";import"../chunk-0z8h6t7k.js";export{a as App};
2
+ import{Sa as a}from"../chunk-4k3r37be.js";import"../chunk-rp2f9mq1.js";import"../chunk-yedb5vvg.js";export{a as App};
3
3
 
4
4
  //# debugId=668BCB797828983E64756E2164756E21
@@ -1,4 +1,4 @@
1
- import { type AgentModel } from "./model";
1
+ import { type AgentModel, type Property, type TypeRef } from "./model";
2
2
  /**
3
3
  * The model as Kotlin, for `dev.gemijs.chat`.
4
4
  *
@@ -8,6 +8,18 @@ import { type AgentModel } from "./model";
8
8
  * iOS and an Android client reads one vocabulary in both.
9
9
  */
10
10
  export declare function renderKotlin(agent: AgentModel, packageName: string): string;
11
+ /**
12
+ * A Kotlin string literal. `JSON.stringify` is nearly one, but a `$` in it
13
+ * would start a template — and `$ref`, `$type` are ordinary JSON keys — and
14
+ * Kotlin has no `\f`.
15
+ */
16
+ export declare function kotlinString(value: string): string;
17
+ export declare function renderClass(name: string, properties: Property[], parent: string | undefined, literalDefaults?: ReadonlySet<string>, imports?: Set<string>): string[];
18
+ export declare function renderEnum(name: string, values: string[]): string[];
19
+ export declare function renderUnion(name: string, discriminant: string, variants: {
20
+ value: string | boolean;
21
+ type: TypeRef;
22
+ }[], strictTagType?: boolean): string[];
11
23
  /** Why `name` cannot be a Kotlin package, or `undefined` when it can. */
12
24
  export declare function invalidPackage(name: string): string | undefined;
13
25
  //# sourceMappingURL=kotlin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"kotlin.d.ts","sourceRoot":"","sources":["../../../bin/ai-client/kotlin.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EAMhB,MAAM,SAAS,CAAC;AAEjB;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CA4I3E;AA4ID,yEAAyE;AACzE,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAQ/D"}
1
+ {"version":3,"file":"kotlin.d.ts","sourceRoot":"","sources":["../../../bin/ai-client/kotlin.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EAEf,KAAK,QAAQ,EACb,KAAK,OAAO,EAGb,MAAM,SAAS,CAAC;AAEjB;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CA4I3E;AA+BD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAIlD;AAaD,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,QAAQ,EAAE,EACtB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,eAAe,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,EACrC,OAAO,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,GACpB,MAAM,EAAE,CA8BV;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAQnE;AAED,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE;IAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,EAAE,EACtD,aAAa,UAAQ,GACpB,MAAM,EAAE,CAyBV;AA0BD,yEAAyE;AACzE,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAQ/D"}
@@ -1,4 +1,4 @@
1
- import { type AgentModel } from "./model";
1
+ import { type AgentModel, type Property, type TypeRef } from "./model";
2
2
  /**
3
3
  * The model as Swift, for `GemiChat`.
4
4
  *
@@ -7,4 +7,13 @@ import { type AgentModel } from "./model";
7
7
  * one app can each have a `SearchInput` without a collision.
8
8
  */
9
9
  export declare function renderSwift(agent: AgentModel): string;
10
+ /** Swift escapes control characters as Unicode scalars and cannot represent a lone surrogate. */
11
+ export declare function swiftString(value: string): string;
12
+ export declare function renderStruct(name: string, properties: Property[], literalDefaults?: ReadonlyMap<string, string>): string[];
13
+ export declare function renderEnum(name: string, values: string[]): string[];
14
+ export declare function renderUnion(name: string, discriminant: string, variants: {
15
+ value: string | boolean;
16
+ type: TypeRef;
17
+ }[]): string[];
18
+ export declare function swiftLiteralCase(value: string | number | boolean): string;
10
19
  //# sourceMappingURL=swift.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"swift.d.ts","sourceRoot":"","sources":["../../../bin/ai-client/swift.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAA0D,MAAM,SAAS,CAAC;AAElG;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAkFrD"}
1
+ {"version":3,"file":"swift.d.ts","sourceRoot":"","sources":["../../../bin/ai-client/swift.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAkB,KAAK,QAAQ,EAAE,KAAK,OAAO,EAAa,MAAM,SAAS,CAAC;AAElG;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAkFrD;AAED,iGAAiG;AACjG,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMjD;AAoCD,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,QAAQ,EAAE,EACtB,eAAe,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GAC5C,MAAM,EAAE,CAgEV;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAanE;AAED,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE;IAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,EAAE,GACrD,MAAM,EAAE,CAwCV;AAaD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAMzE"}
package/dist/bin/gemi.js CHANGED
@@ -36384,7 +36384,7 @@ function renderType(type, parent) {
36384
36384
  return renderUnion(type.name, type.discriminant, type.variants);
36385
36385
  }
36386
36386
  }
36387
- function renderClass(name, properties, parent) {
36387
+ function renderClass(name, properties, parent, literalDefaults, imports) {
36388
36388
  const implemented = parent ? ` : ${parent}` : "";
36389
36389
  if (properties.length === 0) {
36390
36390
  return ["@Serializable", `public data object ${name}${implemented}`];
@@ -36394,10 +36394,15 @@ function renderClass(name, properties, parent) {
36394
36394
  properties.forEach((property, index) => {
36395
36395
  const field = names[index];
36396
36396
  const renamed = field === property.key ? "" : `@SerialName(${kotlinString(property.key)}) `;
36397
+ if (renamed)
36398
+ imports?.add("kotlinx.serialization.SerialName");
36397
36399
  const base = kotlinType(property.type);
36398
36400
  const type = property.optional && !base.endsWith("?") ? `${base}?` : base;
36399
- const fallback = property.optional ? " = null" : "";
36400
- lines.push(` ${renamed}public val ${escape(field)}: ${type}${fallback},`);
36401
+ const requiredLiteral = !property.optional && literalDefaults?.has(base);
36402
+ if (requiredLiteral)
36403
+ imports?.add("kotlinx.serialization.Required");
36404
+ const fallback = property.optional ? " = null" : requiredLiteral ? ` = ${base}` : "";
36405
+ lines.push(` ${renamed}${requiredLiteral ? "@Required " : ""}public val ${escape(field)}: ${type}${fallback},`);
36401
36406
  });
36402
36407
  lines.push(`)${implemented}`);
36403
36408
  return lines;
@@ -36411,23 +36416,25 @@ function renderEnum(name, values) {
36411
36416
  lines.push("}");
36412
36417
  return lines;
36413
36418
  }
36414
- function renderUnion(name, discriminant, variants) {
36419
+ function renderUnion(name, discriminant, variants, strictTagType = false) {
36415
36420
  const lines = [
36416
36421
  `@Serializable(with = ${name}.Serializer::class)`,
36417
36422
  `public sealed interface ${name} {`,
36418
36423
  ` public object Serializer : JsonContentPolymorphicSerializer<${name}>(${name}::class) {`,
36419
36424
  ` override fun selectDeserializer(element: JsonElement): DeserializationStrategy<${name}> =`,
36420
- ` when (val value = element.jsonObject[${kotlinString(discriminant)}]?.jsonPrimitive?.contentOrNull) {`
36425
+ ` when (val value = element.jsonObject[${kotlinString(discriminant)}]${strictTagType ? "" : "?.jsonPrimitive?.contentOrNull"}) {`
36421
36426
  ];
36422
36427
  for (const variant of variants) {
36423
- lines.push(` ${kotlinString(variant.value)} -> ${variantClass(variant)}.serializer()`);
36428
+ const literal = typeof variant.value === "boolean" ? String(variant.value) : kotlinString(variant.value);
36429
+ lines.push(` ${strictTagType ? `JsonPrimitive(${literal})` : literal} -> ${variantClass(variant)}.serializer()`);
36424
36430
  }
36425
- const unknown = kotlinString(`Unknown ${discriminant} "`).slice(0, -1);
36426
- lines.push(` else -> throw SerializationException(${unknown}$value\\"")`, " }", " }", "}");
36431
+ const unknown = kotlinString(`Unknown ${discriminant} `).slice(0, -1);
36432
+ const displayValue = strictTagType ? '${value ?: "missing"}' : "\\\"$value\\\"";
36433
+ lines.push(` else -> throw SerializationException(${unknown}${displayValue}")`, " }", " }", "}");
36427
36434
  return lines;
36428
36435
  }
36429
36436
  function variantClass(variant) {
36430
- return variant.type.kind === "named" ? variant.type.name : variant.value;
36437
+ return variant.type.kind === "named" ? variant.type.name : String(variant.value);
36431
36438
  }
36432
36439
  function uniqueNames(names, taken = new Set) {
36433
36440
  const used = new Set(taken);
@@ -36517,7 +36524,7 @@ function renderSwift(agent) {
36517
36524
  for (const tool of tools) {
36518
36525
  const typed = view.typed(tool).replace(/<.*>$/, "");
36519
36526
  const value = view.failable ? `${view.typed(tool)}(${argument}).map(${view.name}.${escape2(tool.case)}) ?? .unknown(${argument})` : `.${tool.case}(${typed}(${argument}))`;
36520
- emit(` case ${JSON.stringify(tool.name)}: ${value}`);
36527
+ emit(` case ${swiftString(tool.name)}: ${value}`);
36521
36528
  }
36522
36529
  emit(` default: .unknown(${argument})`);
36523
36530
  emit(" }");
@@ -36534,6 +36541,11 @@ function renderSwift(agent) {
36534
36541
  `)}
36535
36542
  `;
36536
36543
  }
36544
+ function swiftString(value) {
36545
+ if (/[\uD800-\uDFFF]/u.test(value))
36546
+ throw new Error("A Swift string cannot contain a lone surrogate");
36547
+ return JSON.stringify(value).replace(/\\\\|\\u([0-9a-f]{4})|\\b|\\f/g, (s, hex) => hex ? `\\u{${hex}}` : s === "\\b" ? "\\u{8}" : s === "\\f" ? "\\u{c}" : s);
36548
+ }
36537
36549
  function swiftType(type) {
36538
36550
  switch (type.kind) {
36539
36551
  case "string":
@@ -36566,7 +36578,7 @@ function renderType2(type) {
36566
36578
  return renderUnion2(type.name, type.discriminant, type.variants);
36567
36579
  }
36568
36580
  }
36569
- function renderStruct(name, properties) {
36581
+ function renderStruct(name, properties, literalDefaults) {
36570
36582
  const names = uniqueIdentifiers(properties.map((property) => property.key));
36571
36583
  const fields = properties.map((property, index) => {
36572
36584
  const base = swiftType(property.type);
@@ -36578,7 +36590,10 @@ function renderStruct(name, properties) {
36578
36590
  lines.push(` public var ${escape2(field.name)}: ${field.swiftType}`);
36579
36591
  if (fields.length > 0)
36580
36592
  lines.push("");
36581
- const parameters = fields.map((field) => `${escape2(field.name)}: ${field.swiftType}${field.swiftType.endsWith("?") ? " = nil" : ""}`);
36593
+ const parameters = fields.map((field) => {
36594
+ const fallback = field.swiftType.endsWith("?") ? "nil" : literalDefaults?.get(field.swiftType);
36595
+ return `${escape2(field.name)}: ${field.swiftType}${fallback ? ` = ${fallback}` : ""}`;
36596
+ });
36582
36597
  if (parameters.length === 0) {
36583
36598
  lines.push(" public init() {}");
36584
36599
  } else {
@@ -36600,7 +36615,7 @@ function renderStruct(name, properties) {
36600
36615
  lines.push("");
36601
36616
  lines.push(" private enum CodingKeys: String, CodingKey {");
36602
36617
  for (const field of fields) {
36603
- lines.push(field.name === field.key ? ` case ${escape2(field.name)}` : ` case ${escape2(field.name)} = ${JSON.stringify(field.key)}`);
36618
+ lines.push(field.name === field.key ? ` case ${escape2(field.name)}` : ` case ${escape2(field.name)} = ${swiftString(field.key)}`);
36604
36619
  }
36605
36620
  lines.push(" }");
36606
36621
  }
@@ -36622,30 +36637,33 @@ function renderEnum2(name, values) {
36622
36637
  const lines = [`public enum ${name}: String, Codable, Hashable, Sendable, CaseIterable {`];
36623
36638
  values.forEach((value, index) => {
36624
36639
  const identifier = names[index];
36625
- lines.push(identifier === value ? ` case ${escape2(identifier)}` : ` case ${escape2(identifier)} = ${JSON.stringify(value)}`);
36640
+ lines.push(identifier === value ? ` case ${escape2(identifier)}` : ` case ${escape2(identifier)} = ${swiftString(value)}`);
36626
36641
  });
36627
36642
  lines.push("}");
36628
36643
  return lines;
36629
36644
  }
36630
36645
  function renderUnion2(name, discriminant, variants) {
36631
- const names = caseIdentifiers(variants.map((variant) => variant.value));
36646
+ const names = caseIdentifiers(variants.map((variant) => String(variant.value)));
36632
36647
  const lines = [`public enum ${name}: Codable, Hashable, Sendable {`];
36633
36648
  variants.forEach((variant, index) => lines.push(` case ${escape2(names[index])}(${swiftType(variant.type)})`));
36634
36649
  lines.push("");
36635
36650
  lines.push(" private enum Discriminant: String, CodingKey {");
36636
- lines.push(` case key = ${JSON.stringify(discriminant)}`);
36651
+ lines.push(` case key = ${swiftString(discriminant)}`);
36637
36652
  lines.push(" }");
36638
36653
  lines.push("");
36639
36654
  lines.push(" public init(from decoder: Decoder) throws {");
36640
36655
  lines.push(" let container = try decoder.container(keyedBy: Discriminant.self)");
36641
- lines.push(" let value = try container.decode(String.self, forKey: .key)");
36656
+ const tagType = typeof variants[0]?.value === "boolean" ? "Bool" : "String";
36657
+ lines.push(` let value = try container.decode(${tagType}.self, forKey: .key)`);
36642
36658
  lines.push(" switch value {");
36643
36659
  variants.forEach((variant, index) => {
36644
- lines.push(` case ${JSON.stringify(variant.value)}: self = .${names[index]}(try ${swiftType(variant.type)}(from: decoder))`);
36660
+ lines.push(` case ${typeof variant.value === "boolean" ? variant.value : swiftString(variant.value)}: self = .${names[index]}(try ${swiftType(variant.type)}(from: decoder))`);
36645
36661
  });
36646
- lines.push(" default:");
36647
- lines.push(" throw DecodingError.dataCorruptedError(");
36648
- lines.push(` forKey: .key, in: container, debugDescription: "Unknown ${discriminant} \\"\\(value)\\"")`);
36662
+ if (tagType === "String" || variants.length < 2) {
36663
+ lines.push(" default:");
36664
+ lines.push(" throw DecodingError.dataCorruptedError(");
36665
+ lines.push(` forKey: .key, in: container, debugDescription: "Unknown ${swiftString(discriminant).slice(1, -1)} \\"\\(value)\\"")`);
36666
+ }
36649
36667
  lines.push(" }");
36650
36668
  lines.push(" }");
36651
36669
  lines.push("");
@@ -42368,5 +42386,5 @@ program.command("app:route-manifest").action(async () => {
42368
42386
  });
42369
42387
  program.parse();
42370
42388
 
42371
- //# debugId=7BA25457E9EF346864756E2164756E21
42389
+ //# debugId=DF58762A7242F09264756E2164756E21
42372
42390
  //# sourceMappingURL=gemi.js.map