@diffra-ai/durable 0.0.0-stage → 0.2.2

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 (411) hide show
  1. package/CHANGELOG.md +440 -0
  2. package/README.md +1153 -2
  3. package/dist/codemode/codemode.d.ts +174 -0
  4. package/dist/codemode/codemode.d.ts.map +1 -0
  5. package/dist/codemode/codemode.js +884 -0
  6. package/dist/codemode/codemode.js.map +1 -0
  7. package/dist/codemode/describe.d.ts +38 -0
  8. package/dist/codemode/describe.d.ts.map +1 -0
  9. package/dist/codemode/describe.js +127 -0
  10. package/dist/codemode/describe.js.map +1 -0
  11. package/dist/codemode/index.d.ts +3 -0
  12. package/dist/codemode/index.d.ts.map +1 -0
  13. package/dist/codemode/index.js +3 -0
  14. package/dist/codemode/index.js.map +1 -0
  15. package/dist/codemode/models.d.ts +29 -0
  16. package/dist/codemode/models.d.ts.map +1 -0
  17. package/dist/codemode/models.js +242 -0
  18. package/dist/codemode/models.js.map +1 -0
  19. package/dist/codemode/output.d.ts +43 -0
  20. package/dist/codemode/output.d.ts.map +1 -0
  21. package/dist/codemode/output.js +168 -0
  22. package/dist/codemode/output.js.map +1 -0
  23. package/dist/documents.d.ts +66 -0
  24. package/dist/documents.d.ts.map +1 -0
  25. package/dist/documents.js +98 -0
  26. package/dist/documents.js.map +1 -0
  27. package/dist/entries.d.ts +31 -0
  28. package/dist/entries.d.ts.map +1 -0
  29. package/dist/entries.js +31 -0
  30. package/dist/entries.js.map +1 -0
  31. package/dist/env/decode.d.ts +16 -0
  32. package/dist/env/decode.d.ts.map +1 -0
  33. package/dist/env/decode.js +28 -0
  34. package/dist/env/decode.js.map +1 -0
  35. package/dist/env/index.d.ts +308 -0
  36. package/dist/env/index.d.ts.map +1 -0
  37. package/dist/env/index.js +49 -0
  38. package/dist/env/index.js.map +1 -0
  39. package/dist/env/line-scan.d.ts +13 -0
  40. package/dist/env/line-scan.d.ts.map +1 -0
  41. package/dist/env/line-scan.js +147 -0
  42. package/dist/env/line-scan.js.map +1 -0
  43. package/dist/env/node-watch.d.ts +29 -0
  44. package/dist/env/node-watch.d.ts.map +1 -0
  45. package/dist/env/node-watch.js +487 -0
  46. package/dist/env/node-watch.js.map +1 -0
  47. package/dist/env/node.d.ts +56 -0
  48. package/dist/env/node.d.ts.map +1 -0
  49. package/dist/env/node.js +1185 -0
  50. package/dist/env/node.js.map +1 -0
  51. package/dist/errors.d.ts +48 -0
  52. package/dist/errors.d.ts.map +1 -0
  53. package/dist/errors.js +76 -0
  54. package/dist/errors.js.map +1 -0
  55. package/dist/harness/agent.d.ts +46 -0
  56. package/dist/harness/agent.d.ts.map +1 -0
  57. package/dist/harness/agent.js +334 -0
  58. package/dist/harness/agent.js.map +1 -0
  59. package/dist/harness/compaction.d.ts +68 -0
  60. package/dist/harness/compaction.d.ts.map +1 -0
  61. package/dist/harness/compaction.js +431 -0
  62. package/dist/harness/compaction.js.map +1 -0
  63. package/dist/harness/context.d.ts +84 -0
  64. package/dist/harness/context.d.ts.map +1 -0
  65. package/dist/harness/context.js +301 -0
  66. package/dist/harness/context.js.map +1 -0
  67. package/dist/harness/define.d.ts +25 -0
  68. package/dist/harness/define.d.ts.map +1 -0
  69. package/dist/harness/define.js +32 -0
  70. package/dist/harness/define.js.map +1 -0
  71. package/dist/harness/generation.d.ts +117 -0
  72. package/dist/harness/generation.d.ts.map +1 -0
  73. package/dist/harness/generation.js +1098 -0
  74. package/dist/harness/generation.js.map +1 -0
  75. package/dist/harness/harness.d.ts +22 -0
  76. package/dist/harness/harness.d.ts.map +1 -0
  77. package/dist/harness/harness.js +438 -0
  78. package/dist/harness/harness.js.map +1 -0
  79. package/dist/harness/inbox.d.ts +84 -0
  80. package/dist/harness/inbox.d.ts.map +1 -0
  81. package/dist/harness/inbox.js +135 -0
  82. package/dist/harness/inbox.js.map +1 -0
  83. package/dist/harness/json.d.ts +26 -0
  84. package/dist/harness/json.d.ts.map +1 -0
  85. package/dist/harness/json.js +51 -0
  86. package/dist/harness/json.js.map +1 -0
  87. package/dist/harness/live.d.ts +285 -0
  88. package/dist/harness/live.d.ts.map +1 -0
  89. package/dist/harness/live.js +257 -0
  90. package/dist/harness/live.js.map +1 -0
  91. package/dist/harness/parks.d.ts +23 -0
  92. package/dist/harness/parks.d.ts.map +1 -0
  93. package/dist/harness/parks.js +52 -0
  94. package/dist/harness/parks.js.map +1 -0
  95. package/dist/harness/partial-changes.d.ts +54 -0
  96. package/dist/harness/partial-changes.d.ts.map +1 -0
  97. package/dist/harness/partial-changes.js +163 -0
  98. package/dist/harness/partial-changes.js.map +1 -0
  99. package/dist/harness/prompt.d.ts +27 -0
  100. package/dist/harness/prompt.d.ts.map +1 -0
  101. package/dist/harness/prompt.js +131 -0
  102. package/dist/harness/prompt.js.map +1 -0
  103. package/dist/harness/provider.d.ts +16 -0
  104. package/dist/harness/provider.d.ts.map +1 -0
  105. package/dist/harness/provider.js +33 -0
  106. package/dist/harness/provider.js.map +1 -0
  107. package/dist/harness/registry-reader.d.ts +11 -0
  108. package/dist/harness/registry-reader.d.ts.map +1 -0
  109. package/dist/harness/registry-reader.js +25 -0
  110. package/dist/harness/registry-reader.js.map +1 -0
  111. package/dist/harness/registry.d.ts +6 -0
  112. package/dist/harness/registry.d.ts.map +1 -0
  113. package/dist/harness/registry.js +101 -0
  114. package/dist/harness/registry.js.map +1 -0
  115. package/dist/harness/scheduler.d.ts +195 -0
  116. package/dist/harness/scheduler.d.ts.map +1 -0
  117. package/dist/harness/scheduler.js +3073 -0
  118. package/dist/harness/scheduler.js.map +1 -0
  119. package/dist/harness/submissions.d.ts +44 -0
  120. package/dist/harness/submissions.d.ts.map +1 -0
  121. package/dist/harness/submissions.js +265 -0
  122. package/dist/harness/submissions.js.map +1 -0
  123. package/dist/harness/task-graph.d.ts +75 -0
  124. package/dist/harness/task-graph.d.ts.map +1 -0
  125. package/dist/harness/task-graph.js +224 -0
  126. package/dist/harness/task-graph.js.map +1 -0
  127. package/dist/harness/telemetry.d.ts +307 -0
  128. package/dist/harness/telemetry.d.ts.map +1 -0
  129. package/dist/harness/telemetry.js +140 -0
  130. package/dist/harness/telemetry.js.map +1 -0
  131. package/dist/harness/tool.d.ts +106 -0
  132. package/dist/harness/tool.d.ts.map +1 -0
  133. package/dist/harness/tool.js +1182 -0
  134. package/dist/harness/tool.js.map +1 -0
  135. package/dist/harness/transcript.d.ts +72 -0
  136. package/dist/harness/transcript.d.ts.map +1 -0
  137. package/dist/harness/transcript.js +264 -0
  138. package/dist/harness/transcript.js.map +1 -0
  139. package/dist/harness/types.d.ts +1146 -0
  140. package/dist/harness/types.d.ts.map +1 -0
  141. package/dist/harness/types.js +2 -0
  142. package/dist/harness/types.js.map +1 -0
  143. package/dist/harness/usage.d.ts +19 -0
  144. package/dist/harness/usage.d.ts.map +1 -0
  145. package/dist/harness/usage.js +57 -0
  146. package/dist/harness/usage.js.map +1 -0
  147. package/dist/harness/util.d.ts +25 -0
  148. package/dist/harness/util.d.ts.map +1 -0
  149. package/dist/harness/util.js +76 -0
  150. package/dist/harness/util.js.map +1 -0
  151. package/dist/harness/view.d.ts +69 -0
  152. package/dist/harness/view.d.ts.map +1 -0
  153. package/dist/harness/view.js +265 -0
  154. package/dist/harness/view.js.map +1 -0
  155. package/dist/ids.d.ts +6 -0
  156. package/dist/ids.d.ts.map +1 -0
  157. package/dist/ids.js +9 -0
  158. package/dist/ids.js.map +1 -0
  159. package/dist/images/cloudflare.d.ts +4 -0
  160. package/dist/images/cloudflare.d.ts.map +1 -0
  161. package/dist/images/cloudflare.js +9 -0
  162. package/dist/images/cloudflare.js.map +1 -0
  163. package/dist/images/exif.d.ts +3 -0
  164. package/dist/images/exif.d.ts.map +1 -0
  165. package/dist/images/exif.js +71 -0
  166. package/dist/images/exif.js.map +1 -0
  167. package/dist/images/fit.d.ts +41 -0
  168. package/dist/images/fit.d.ts.map +1 -0
  169. package/dist/images/fit.js +108 -0
  170. package/dist/images/fit.js.map +1 -0
  171. package/dist/images/index.d.ts +18 -0
  172. package/dist/images/index.d.ts.map +1 -0
  173. package/dist/images/index.js +125 -0
  174. package/dist/images/index.js.map +1 -0
  175. package/dist/images/node-worker.d.ts +19 -0
  176. package/dist/images/node-worker.d.ts.map +1 -0
  177. package/dist/images/node-worker.js +17 -0
  178. package/dist/images/node-worker.js.map +1 -0
  179. package/dist/images/node.d.ts +21 -0
  180. package/dist/images/node.d.ts.map +1 -0
  181. package/dist/images/node.js +121 -0
  182. package/dist/images/node.js.map +1 -0
  183. package/dist/index.d.ts +29 -0
  184. package/dist/index.d.ts.map +1 -0
  185. package/dist/index.js +23 -0
  186. package/dist/index.js.map +1 -0
  187. package/dist/search.d.ts +29 -0
  188. package/dist/search.d.ts.map +1 -0
  189. package/dist/search.js +148 -0
  190. package/dist/search.js.map +1 -0
  191. package/dist/session/cached-storage.d.ts +72 -0
  192. package/dist/session/cached-storage.d.ts.map +1 -0
  193. package/dist/session/cached-storage.js +269 -0
  194. package/dist/session/cached-storage.js.map +1 -0
  195. package/dist/session/conversation-tails.d.ts +33 -0
  196. package/dist/session/conversation-tails.d.ts.map +1 -0
  197. package/dist/session/conversation-tails.js +101 -0
  198. package/dist/session/conversation-tails.js.map +1 -0
  199. package/dist/session/forks.d.ts +10 -0
  200. package/dist/session/forks.d.ts.map +1 -0
  201. package/dist/session/forks.js +42 -0
  202. package/dist/session/forks.js.map +1 -0
  203. package/dist/session/keys.d.ts +69 -0
  204. package/dist/session/keys.d.ts.map +1 -0
  205. package/dist/session/keys.js +161 -0
  206. package/dist/session/keys.js.map +1 -0
  207. package/dist/session/session.d.ts +287 -0
  208. package/dist/session/session.d.ts.map +1 -0
  209. package/dist/session/session.js +1701 -0
  210. package/dist/session/session.js.map +1 -0
  211. package/dist/session/transaction.d.ts +205 -0
  212. package/dist/session/transaction.d.ts.map +1 -0
  213. package/dist/session/transaction.js +1059 -0
  214. package/dist/session/transaction.js.map +1 -0
  215. package/dist/session/writer.d.ts +74 -0
  216. package/dist/session/writer.d.ts.map +1 -0
  217. package/dist/session/writer.js +294 -0
  218. package/dist/session/writer.js.map +1 -0
  219. package/dist/signals.d.ts +180 -0
  220. package/dist/signals.d.ts.map +1 -0
  221. package/dist/signals.js +236 -0
  222. package/dist/signals.js.map +1 -0
  223. package/dist/storage/indexeddb.d.ts +69 -0
  224. package/dist/storage/indexeddb.d.ts.map +1 -0
  225. package/dist/storage/indexeddb.js +883 -0
  226. package/dist/storage/indexeddb.js.map +1 -0
  227. package/dist/storage/jsonl/index.d.ts +2 -0
  228. package/dist/storage/jsonl/index.d.ts.map +1 -0
  229. package/dist/storage/jsonl/index.js +2 -0
  230. package/dist/storage/jsonl/index.js.map +1 -0
  231. package/dist/storage/jsonl/node.d.ts +6 -0
  232. package/dist/storage/jsonl/node.d.ts.map +1 -0
  233. package/dist/storage/jsonl/node.js +8 -0
  234. package/dist/storage/jsonl/node.js.map +1 -0
  235. package/dist/storage/jsonl/storage.d.ts +206 -0
  236. package/dist/storage/jsonl/storage.d.ts.map +1 -0
  237. package/dist/storage/jsonl/storage.js +799 -0
  238. package/dist/storage/jsonl/storage.js.map +1 -0
  239. package/dist/storage/memory.d.ts +68 -0
  240. package/dist/storage/memory.d.ts.map +1 -0
  241. package/dist/storage/memory.js +761 -0
  242. package/dist/storage/memory.js.map +1 -0
  243. package/dist/storage/scan.d.ts +18 -0
  244. package/dist/storage/scan.d.ts.map +1 -0
  245. package/dist/storage/scan.js +29 -0
  246. package/dist/storage/scan.js.map +1 -0
  247. package/dist/storage/sqlite/cloudflare.d.ts +9 -0
  248. package/dist/storage/sqlite/cloudflare.d.ts.map +1 -0
  249. package/dist/storage/sqlite/cloudflare.js +11 -0
  250. package/dist/storage/sqlite/cloudflare.js.map +1 -0
  251. package/dist/storage/sqlite/commit.d.ts +52 -0
  252. package/dist/storage/sqlite/commit.d.ts.map +1 -0
  253. package/dist/storage/sqlite/commit.js +371 -0
  254. package/dist/storage/sqlite/commit.js.map +1 -0
  255. package/dist/storage/sqlite/database.d.ts +2 -0
  256. package/dist/storage/sqlite/database.d.ts.map +1 -0
  257. package/dist/storage/sqlite/database.js +2 -0
  258. package/dist/storage/sqlite/database.js.map +1 -0
  259. package/dist/storage/sqlite/index.d.ts +4 -0
  260. package/dist/storage/sqlite/index.d.ts.map +1 -0
  261. package/dist/storage/sqlite/index.js +3 -0
  262. package/dist/storage/sqlite/index.js.map +1 -0
  263. package/dist/storage/sqlite/migrations.d.ts +12 -0
  264. package/dist/storage/sqlite/migrations.d.ts.map +1 -0
  265. package/dist/storage/sqlite/migrations.js +121 -0
  266. package/dist/storage/sqlite/migrations.js.map +1 -0
  267. package/dist/storage/sqlite/node.d.ts +8 -0
  268. package/dist/storage/sqlite/node.d.ts.map +1 -0
  269. package/dist/storage/sqlite/node.js +12 -0
  270. package/dist/storage/sqlite/node.js.map +1 -0
  271. package/dist/storage/sqlite/rows.d.ts +33 -0
  272. package/dist/storage/sqlite/rows.d.ts.map +1 -0
  273. package/dist/storage/sqlite/rows.js +53 -0
  274. package/dist/storage/sqlite/rows.js.map +1 -0
  275. package/dist/storage/sqlite/schema.d.ts +45 -0
  276. package/dist/storage/sqlite/schema.d.ts.map +1 -0
  277. package/dist/storage/sqlite/schema.js +50 -0
  278. package/dist/storage/sqlite/schema.js.map +1 -0
  279. package/dist/storage/sqlite/statements.d.ts +13 -0
  280. package/dist/storage/sqlite/statements.d.ts.map +1 -0
  281. package/dist/storage/sqlite/statements.js +88 -0
  282. package/dist/storage/sqlite/statements.js.map +1 -0
  283. package/dist/storage/sqlite/storage.d.ts +86 -0
  284. package/dist/storage/sqlite/storage.d.ts.map +1 -0
  285. package/dist/storage/sqlite/storage.js +534 -0
  286. package/dist/storage/sqlite/storage.js.map +1 -0
  287. package/dist/storage/store/commit.d.ts +33 -0
  288. package/dist/storage/store/commit.d.ts.map +1 -0
  289. package/dist/storage/store/commit.js +286 -0
  290. package/dist/storage/store/commit.js.map +1 -0
  291. package/dist/storage/store/documents.d.ts +43 -0
  292. package/dist/storage/store/documents.d.ts.map +1 -0
  293. package/dist/storage/store/documents.js +102 -0
  294. package/dist/storage/store/documents.js.map +1 -0
  295. package/dist/storage/store/index.d.ts +2 -0
  296. package/dist/storage/store/index.d.ts.map +1 -0
  297. package/dist/storage/store/index.js +2 -0
  298. package/dist/storage/store/index.js.map +1 -0
  299. package/dist/storage/store/queries.d.ts +49 -0
  300. package/dist/storage/store/queries.d.ts.map +1 -0
  301. package/dist/storage/store/queries.js +93 -0
  302. package/dist/storage/store/queries.js.map +1 -0
  303. package/dist/storage/store/storage.d.ts +60 -0
  304. package/dist/storage/store/storage.d.ts.map +1 -0
  305. package/dist/storage/store/storage.js +438 -0
  306. package/dist/storage/store/storage.js.map +1 -0
  307. package/dist/storage/store/tables.d.ts +54 -0
  308. package/dist/storage/store/tables.d.ts.map +1 -0
  309. package/dist/storage/store/tables.js +108 -0
  310. package/dist/storage/store/tables.js.map +1 -0
  311. package/dist/tasks.d.ts +6 -0
  312. package/dist/tasks.d.ts.map +1 -0
  313. package/dist/tasks.js +5 -0
  314. package/dist/tasks.js.map +1 -0
  315. package/dist/testing/assertions.d.ts +5 -0
  316. package/dist/testing/assertions.d.ts.map +1 -0
  317. package/dist/testing/assertions.js +25 -0
  318. package/dist/testing/assertions.js.map +1 -0
  319. package/dist/testing/commit-writes.d.ts +5 -0
  320. package/dist/testing/commit-writes.d.ts.map +1 -0
  321. package/dist/testing/commit-writes.js +12 -0
  322. package/dist/testing/commit-writes.js.map +1 -0
  323. package/dist/testing/env-conformance.d.ts +7 -0
  324. package/dist/testing/env-conformance.d.ts.map +1 -0
  325. package/dist/testing/env-conformance.js +531 -0
  326. package/dist/testing/env-conformance.js.map +1 -0
  327. package/dist/testing/index.d.ts +8 -0
  328. package/dist/testing/index.d.ts.map +1 -0
  329. package/dist/testing/index.js +7 -0
  330. package/dist/testing/index.js.map +1 -0
  331. package/dist/testing/runner.d.ts +12 -0
  332. package/dist/testing/runner.d.ts.map +1 -0
  333. package/dist/testing/runner.js +23 -0
  334. package/dist/testing/runner.js.map +1 -0
  335. package/dist/testing/storage-benchmark.d.ts +41 -0
  336. package/dist/testing/storage-benchmark.d.ts.map +1 -0
  337. package/dist/testing/storage-benchmark.js +351 -0
  338. package/dist/testing/storage-benchmark.js.map +1 -0
  339. package/dist/testing/storage-conformance.d.ts +4 -0
  340. package/dist/testing/storage-conformance.d.ts.map +1 -0
  341. package/dist/testing/storage-conformance.js +1554 -0
  342. package/dist/testing/storage-conformance.js.map +1 -0
  343. package/dist/testing/types.d.ts +39 -0
  344. package/dist/testing/types.d.ts.map +1 -0
  345. package/dist/testing/types.js +2 -0
  346. package/dist/testing/types.js.map +1 -0
  347. package/dist/timers.d.ts +21 -0
  348. package/dist/timers.d.ts.map +1 -0
  349. package/dist/timers.js +72 -0
  350. package/dist/timers.js.map +1 -0
  351. package/dist/tool-search/index.d.ts +2 -0
  352. package/dist/tool-search/index.d.ts.map +1 -0
  353. package/dist/tool-search/index.js +2 -0
  354. package/dist/tool-search/index.js.map +1 -0
  355. package/dist/tool-search/tool-search.d.ts +17 -0
  356. package/dist/tool-search/tool-search.d.ts.map +1 -0
  357. package/dist/tool-search/tool-search.js +96 -0
  358. package/dist/tool-search/tool-search.js.map +1 -0
  359. package/dist/tools/bash.d.ts +55 -0
  360. package/dist/tools/bash.d.ts.map +1 -0
  361. package/dist/tools/bash.js +139 -0
  362. package/dist/tools/bash.js.map +1 -0
  363. package/dist/tools/edit-diff.d.ts +89 -0
  364. package/dist/tools/edit-diff.d.ts.map +1 -0
  365. package/dist/tools/edit-diff.js +386 -0
  366. package/dist/tools/edit-diff.js.map +1 -0
  367. package/dist/tools/edit.d.ts +18 -0
  368. package/dist/tools/edit.d.ts.map +1 -0
  369. package/dist/tools/edit.js +117 -0
  370. package/dist/tools/edit.js.map +1 -0
  371. package/dist/tools/env.d.ts +5 -0
  372. package/dist/tools/env.d.ts.map +1 -0
  373. package/dist/tools/env.js +7 -0
  374. package/dist/tools/env.js.map +1 -0
  375. package/dist/tools/file-mutation-queue.d.ts +9 -0
  376. package/dist/tools/file-mutation-queue.d.ts.map +1 -0
  377. package/dist/tools/file-mutation-queue.js +52 -0
  378. package/dist/tools/file-mutation-queue.js.map +1 -0
  379. package/dist/tools/image-processor.d.ts +57 -0
  380. package/dist/tools/image-processor.d.ts.map +1 -0
  381. package/dist/tools/image-processor.js +49 -0
  382. package/dist/tools/image-processor.js.map +1 -0
  383. package/dist/tools/image.d.ts +20 -0
  384. package/dist/tools/image.d.ts.map +1 -0
  385. package/dist/tools/image.js +178 -0
  386. package/dist/tools/image.js.map +1 -0
  387. package/dist/tools/index.d.ts +46 -0
  388. package/dist/tools/index.d.ts.map +1 -0
  389. package/dist/tools/index.js +23 -0
  390. package/dist/tools/index.js.map +1 -0
  391. package/dist/tools/path-utils.d.ts +5 -0
  392. package/dist/tools/path-utils.d.ts.map +1 -0
  393. package/dist/tools/path-utils.js +26 -0
  394. package/dist/tools/path-utils.js.map +1 -0
  395. package/dist/tools/read.d.ts +30 -0
  396. package/dist/tools/read.d.ts.map +1 -0
  397. package/dist/tools/read.js +239 -0
  398. package/dist/tools/read.js.map +1 -0
  399. package/dist/tools/write.d.ts +10 -0
  400. package/dist/tools/write.d.ts.map +1 -0
  401. package/dist/tools/write.js +31 -0
  402. package/dist/tools/write.js.map +1 -0
  403. package/dist/truncate.d.ts +65 -0
  404. package/dist/truncate.d.ts.map +1 -0
  405. package/dist/truncate.js +124 -0
  406. package/dist/truncate.js.map +1 -0
  407. package/dist/types.d.ts +1244 -0
  408. package/dist/types.d.ts.map +1 -0
  409. package/dist/types.js +3 -0
  410. package/dist/types.js.map +1 -0
  411. package/package.json +179 -5
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool.js","sourceRoot":"","sources":["../../src/harness/tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAgB,eAAe,EAAE,kBAAkB,EAAE,MAAM,0BAA0B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QAAE,OAAO,KAAK,CAAC;IAC7F,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1C,OAAO,CACN,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAE,CAAC,CAAC,CAC7G,CAAC;IACH,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC5B,OAAO,CACN,IAAI,CAAC,MAAM,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,GAAG,CAAE,EAAE,CAAC,CAAC,GAAG,CAAE,CAAC,CAAC,CAClH,CAAC;AACH,CAAC","sourcesContent":["import type { ImageContent, TextContent, ToolCall, ToolResultMessage } from \"@diffra-ai/ai\";\nimport { validateToolArguments } from \"@diffra-ai/ai/utils/validation\";\nimport { awaitWithContext, type Context, withAbortSignal, withoutAbortSignal } from \"@diffra-ai/chord/context\";\nimport { type Draft, overlap, ownedSlice } from \"@diffra-ai/chord/delta\";\nimport { copyJson, type JsonRepresentation, type JsonValue } from \"@diffra-ai/chord/json\";\nimport {\n\tboundOutput,\n\tOutputBuffer,\n\ttype OutputLimits,\n\tPROGRESS_BYTES_PER_SECOND,\n\tProgress,\n\ttype ProgressClock,\n} from \"@diffra-ai/chord/output\";\nimport { compile, type Validator } from \"@diffra-ai/schema\";\nimport { formats } from \"@diffra-ai/schema/formats\";\nimport { defineDocFamily } from \"../documents.ts\";\nimport { AssistantEntry, ToolResultEntry } from \"../entries.ts\";\nimport type { ExecutionEnv } from \"../env/index.ts\";\nimport { errorMessage } from \"../errors.ts\";\nimport { defineTask } from \"../tasks.ts\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, utf8ByteLength } from \"../truncate.ts\";\nimport type {\n\tConversationId,\n\tEntryId,\n\tJsonObject,\n\tTask,\n\tTaskId,\n\tTaskOptions,\n\tTaskOutcome,\n\tTaskRecord,\n\tTaskRuntime,\n\tTx,\n\tTypedEntry,\n\tWakeReason,\n} from \"../types.ts\";\nimport { toolExtension } from \"./agent.ts\";\nimport { assignJson } from \"./json.ts\";\nimport {\n\tclearOutput,\n\tclearProgress,\n\tcutOffCount,\n\tcutOffTooOften,\n\tfindSlot,\n\tfinishSlot,\n\tLiveDoc,\n\ttype NestedToolSlot,\n\ttype NestedToolSummary,\n\tPROGRESS_COMMIT,\n\tremoveNestedSlots,\n\tsalvageable,\n\ttype ToolSlot,\n\ttoolSlot,\n} from \"./live.ts\";\nimport { BASE_PARKS, isPark, type ParkCarrier, parkError } from \"./parks.ts\";\nimport { closeSignal } from \"./scheduler.ts\";\nimport type {\n\tGateSleep,\n\tNestedToolCall,\n\tNestedToolExecutionResult,\n\tToolControl,\n\tToolDiagnostic,\n\tToolExecutionApi,\n\tToolExecutionResult,\n\tToolHookCall,\n\tToolHooks,\n\tToolPark,\n\tToolRegistration,\n} from \"./types.ts\";\nimport { recordUsage } from \"./usage.ts\";\nimport { optionalExtension } from \"./util.ts\";\n\n/**\n * A model-issued call, read from its assistant entry, or a nested call a running tool made through `executeTool()`,\n * whose call the input carries because no entry holds it.\n */\nexport type ToolTaskInput =\n\t| {\n\t\t\tkind: \"model\";\n\t\t\tassistant: EntryId;\n\t\t\tcallId: string;\n\t\t\t/** A call to a tool its request did not offer: settles `tool_unavailable` without resolving the name. */\n\t\t\tunoffered?: true;\n\t }\n\t| {\n\t\t\tkind: \"nested\";\n\t\t\tparent: TaskId;\n\t\t\tparentCallId: string;\n\t\t\tkey: string;\n\t\t\tcall: ToolCall;\n\t\t\t/** `false`: commit no running output, details, or diagnostics to the slot; the result still gets them. */\n\t\t\tprogress?: false;\n\t };\n\nexport type ToolTaskCheckpoint =\n\t| { phase: \"call\" }\n\t/**\n\t * Durable intent: the final arguments and the replay policy recorded before execution, and for a run after a park,\n\t * why it woke and what it parked with. `execute()` runs in the phase that commits it; this phase is reached only by\n\t * recovery.\n\t */\n\t| { phase: \"execute\"; arguments: JsonObject; replay: \"safe\" | \"unsafe\"; wake?: WakeReason; checkpoint?: JsonValue }\n\t/** The call is parked: the `sleeping` or `waiting` state holds this checkpoint (spec suspendable §4.2). */\n\t| { phase: \"parked\"; arguments: JsonObject; replay: \"safe\" | \"unsafe\"; checkpoint?: JsonValue };\n\n/**\n * A model-issued call's result is its transcript entry; a nested call's result is in its caller's\n * `NestedCallDoc`, so the receipt stays small and the result retires with the caller. A version 1 task that was\n * already holding its outcome as `completing` when the Harness upgraded finishes with a version 1 result,\n * `{ entryId, control? }` without `kind`; treat a result without `kind` as a model-issued call's.\n */\nexport type ToolTaskResult = { kind: \"model\"; entryId: EntryId; control?: ToolControl } | { kind: \"nested\" };\n\n/**\n * Memo of a tool task that made a nested call, in any attempt, committed before the first admission of each attempt:\n * only then can `diffra.live` hold slots below it, which settling removes. A crash between the two only costs a scan.\n */\nconst MADE_NESTED_CALLS = \"diffra.tool.madeNestedCalls\";\n\n/**\n * One key of a running tool: a nested call, its task and once it ended its result, or a task created under the key\n * (`createTask()` with `key`). A member without `kind`, written before keyed tasks, is a nested call's.\n */\nexport type NestedCallState = {\n\tkind?: \"nested\" | \"task\";\n\t/** Absent only inside the commit that creates the member; a creation that fails leaves no member. */\n\ttaskId?: TaskId;\n\t/** Exactly what `executeTool()` returns; absent while running, and for a call the scheduler faulted or orphaned. */\n\tresult?: JsonRepresentation<NestedToolExecutionResult>;\n};\n\n/**\n * The nested calls of a tool call, a task-scoped family of the calling task keyed by the nested call's key: so a rerun\n * finds the calls it already made, and the caller reads each result. Created with the nested task; the nested call's\n * terminal commit adds its result. One document per call, so no commit rewrites the others. Retires with the caller.\n */\nexport const NestedCallDoc = defineDocFamily<NestedCallState, null>({\n\tkind: \"diffra.tool.nested-call\",\n\tversion: 1,\n\tscope: \"task\",\n\tfamily: true,\n\tinitial: () => ({}),\n\t// The document retires with its task.\n\tcheckpointWhen: () => false,\n});\n\ntype Runtime = TaskRuntime<ToolTaskInput, ToolTaskCheckpoint, ToolTaskResult, ToolHooks>;\ntype Content = (TextContent | ImageContent)[];\n\n/**\n * Built-in tool task: resolves the called tool among its phase agent's tools, validates, runs `beforeTool`, records intent,\n * executes, runs `afterTool`, and settles the result, all in one `call` handler so nothing separates resolution from\n * settlement. A call that parks runs again in `parked`, which resolves the tool, records intent, and executes in one\n * handler too. `execute` is reached only by recovery and applies the replay rule. A model-issued call settles by\n * appending its result entry; a nested call by writing its result to its caller's `NestedCallDoc`.\n */\nexport const ToolTask = defineTask<ToolTaskInput, ToolTaskCheckpoint, ToolTaskResult, ToolHooks>({\n\tname: \"diffra.tool\",\n\tversion: 4,\n\tinitial: () => ({ phase: \"call\" }),\n\t// Version 1 had only model-issued calls, without `kind`; version 3 added `unoffered`, absent in version 2 inputs;\n\t// version 4 added `parked` and the optional fields of `execute`, absent in older checkpoints.\n\tmigrate: (input, checkpoint, fromVersion) => ({\n\t\tinput:\n\t\t\tfromVersion === 1\n\t\t\t\t? { kind: \"model\", ...(input as { assistant: EntryId; callId: string }) }\n\t\t\t\t: (input as ToolTaskInput),\n\t\tcheckpoint: checkpoint as ToolTaskCheckpoint,\n\t}),\n\tphases: {\n\t\tcall: async (task, runtime, context) => {\n\t\t\tconst call = await readCall(runtime, task.input, context);\n\t\t\tif (cutOffTooOften(task, runtime)) return endCutOff(runtime, task, call, context);\n\t\t\tconst tool = isUnoffered(task.input) ? undefined : await resolveTool(runtime, task.input, call.name, context);\n\t\t\tif (tool === undefined) {\n\t\t\t\tconst error = harnessError(\"tool_unavailable\", `Tool ${call.name} is not available`);\n\t\t\t\treturn reject(runtime, task.input, call, undefined, error, context);\n\t\t\t}\n\t\t\tconst prepared = prepare(tool, call.arguments as JsonObject);\n\t\t\tconst checked = prepared.kind === \"invalid\" ? prepared : validate(tool, call, prepared.args);\n\t\t\tif (checked.kind === \"invalid\")\n\t\t\t\treturn reject(runtime, task.input, call, tool, invalid(checked.error), context);\n\t\t\tlet args = checked.args;\n\t\t\tlet block: string | undefined;\n\t\t\tlet sleep: GateSleep | undefined;\n\t\t\tawait runtime.hooks.each(\"beforeTool\", async (hook) => {\n\t\t\t\tif (block !== undefined || sleep !== undefined) return;\n\t\t\t\ttry {\n\t\t\t\t\tconst decision = await hook({ ...call, arguments: args }, runtime, context);\n\t\t\t\t\tif (decision?.block !== undefined) block = decision.block;\n\t\t\t\t\telse if (decision?.sleep !== undefined) sleep = decision.sleep;\n\t\t\t\t\telse if (decision?.arguments !== undefined) args = decision.arguments;\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (runtime.signal.aborted) throw error;\n\t\t\t\t\tblock = errorMessage(error);\n\t\t\t\t}\n\t\t\t});\n\t\t\tif (block !== undefined) {\n\t\t\t\tconst blocked = harnessError(\"blocked\", `Tool call blocked: ${block}`);\n\t\t\t\treturn reject(runtime, task.input, call, tool, blocked, context);\n\t\t\t}\n\t\t\tif (sleep !== undefined) return parkAtGate(runtime, task.input, call, tool, sleep, context);\n\t\t\tconst validated = validate(tool, call, args);\n\t\t\tif (validated.kind === \"invalid\")\n\t\t\t\treturn reject(runtime, task.input, call, tool, invalid(validated.error), context);\n\t\t\t// Strict JSON: repair may set optional properties to undefined, which the slot and checkpoint cannot hold.\n\t\t\tconst final = copyJson(validated.args, { omitUndefinedProperties: true }) as JsonObject;\n\t\t\tawait commitIntent(runtime, { phase: \"execute\", arguments: final, replay: tool.replay ?? \"unsafe\" }, context);\n\t\t\tawait run(runtime, task.input, call, tool, final, {}, context);\n\t\t},\n\t\t/**\n\t\t * Woken from a park: resolve the tool again, record intent with the wake, and run `execute()` again. A tool that\n\t\t * no longer resolves cannot run or clean up; the call ends `failed`, so what it owns is aborted.\n\t\t */\n\t\tparked: async (task, runtime, context) => {\n\t\t\tconst { arguments: args, checkpoint } = task.state.checkpoint;\n\t\t\tconst wake = task.state.wake;\n\t\t\tconst call = await readCall(runtime, task.input, context);\n\t\t\tif (cutOffTooOften(task, runtime)) return endCutOff(runtime, task, call, context);\n\t\t\tconst tool = await resolveTool(runtime, task.input, call.name, context);\n\t\t\tif (tool === undefined) {\n\t\t\t\tconst message = `Tool ${call.name} is not available`;\n\t\t\t\truntime.report(new Error(`${message}: its parked call ${call.id} cannot run again`));\n\t\t\t\tconst ending = { status: \"failed\", message } as const;\n\t\t\t\treturn settleFromSlot(runtime, task.input, call, { tool }, ending, \"tool_unavailable\", message, context);\n\t\t\t}\n\t\t\tconst intent = {\n\t\t\t\tphase: \"execute\",\n\t\t\t\targuments: args,\n\t\t\t\treplay: tool.replay ?? \"unsafe\",\n\t\t\t\t...(wake === undefined ? {} : { wake }),\n\t\t\t\t...(checkpoint === undefined ? {} : { checkpoint }),\n\t\t\t} as const;\n\t\t\tawait commitIntent(runtime, intent, context);\n\t\t\tawait run(runtime, task.input, call, tool, args, { wake, checkpoint }, context);\n\t\t},\n\t\t/** Recovery after intent: rerun only when the stored and the current policy both say `safe`. */\n\t\texecute: async (task, runtime, context) => {\n\t\t\tconst { arguments: args, replay, wake, checkpoint } = task.state.checkpoint;\n\t\t\tconst call = await readCall(runtime, task.input, context);\n\t\t\t// Also before an interruption result: its `afterTool` hooks may be what cut the task off.\n\t\t\tif (cutOffTooOften(task, runtime)) return endCutOff(runtime, task, call, context);\n\t\t\tconst tool = await resolveTool(runtime, task.input, call.name, context);\n\t\t\tif (replay === \"safe\" && tool?.replay === \"safe\") {\n\t\t\t\t// The rerun reports from scratch: clear what the interrupted attempt published, and show the slot running with\n\t\t\t\t// the arguments it runs with again, as the deferred commit that showed them may have been lost with the crash.\n\t\t\t\t// A woken run keeps the details and diagnostics earlier runs left, as a park does.\n\t\t\t\tawait runtime.commit(async (tx) => {\n\t\t\t\t\tconst found = findSlot(await tx.doc(LiveDoc, runtime.conversationId), runtime.taskId);\n\t\t\t\t\tif (found !== undefined) {\n\t\t\t\t\t\tif (wake === undefined) clearProgress(found.slot);\n\t\t\t\t\t\telse clearOutput(found.slot);\n\t\t\t\t\t\tfound.slot.status = \"running\";\n\t\t\t\t\t\tif (found.kind === \"nested\") found.slot.arguments = args;\n\t\t\t\t\t}\n\t\t\t\t\treturn undefined;\n\t\t\t\t}, context);\n\t\t\t\treturn run(runtime, task.input, call, tool, args, { wake, checkpoint }, context);\n\t\t\t}\n\t\t\t// A woken run may have restarted external work that nothing will collect now.\n\t\t\tif (wake !== undefined && tool !== undefined)\n\t\t\t\tawait cancel(runtime, task.input, call, tool, args, checkpoint, context);\n\t\t\tconst message = `Tool ${call.name} was interrupted and may have partially run`;\n\t\t\t// `failed` records cancellation intent, so the call's owned conversations, left unsupervised, are aborted.\n\t\t\tconst ending = { status: \"failed\", message } as const;\n\t\t\t// Not cut off too often (checked above), so the hooks run.\n\t\t\tawait settleFromSlot(runtime, task.input, call, { tool }, ending, \"interrupted\", message, context);\n\t\t},\n\t},\n\tabort: async (task, runtime, context) => {\n\t\tconst call = await readCall(runtime, task.input, context);\n\t\tconst checkpoint = task.state.checkpoint;\n\t\t// Abandoned after a restart (`TaskOptions.abandonOnRestart`): say whether the call may have run. An unoffered call\n\t\t// could not run in any case, and its result says so.\n\t\tconst [code, message] = isUnoffered(task.input)\n\t\t\t? [\"tool_unavailable\", `Tool ${call.name} is not available`]\n\t\t\t: task.abortReason !== \"restart\"\n\t\t\t\t? [\"aborted\", `Tool ${call.name} was aborted`]\n\t\t\t\t: checkpoint.phase === \"execute\"\n\t\t\t\t\t? [\"interrupted\", `Tool ${call.name} was interrupted by a restart and may have partially run`]\n\t\t\t\t\t: checkpoint.phase === \"parked\"\n\t\t\t\t\t\t? [\"abandoned\", `Tool ${call.name} was parked: its caller ended with a restart`]\n\t\t\t\t\t\t: [\"abandoned\", `Tool ${call.name} was not started: its caller ended with a restart`];\n\t\tconst tool = await toolForLimits(runtime, task.input, call.name, context);\n\t\t// External work may be live while no code of the tool runs: parked, or woken and cut off before it parked again.\n\t\t// The scheduler ends an abort handler cut off `restartLimit` times itself, so `cancel` cannot keep it from ending.\n\t\tif (checkpoint.phase === \"parked\" || (checkpoint.phase === \"execute\" && checkpoint.wake !== undefined)) {\n\t\t\tif (tool !== undefined) {\n\t\t\t\tawait cancel(runtime, task.input, call, tool, checkpoint.arguments, checkpoint.checkpoint, context);\n\t\t\t} else {\n\t\t\t\truntime.report(\n\t\t\t\t\tnew Error(`Tool ${call.name} is not available: its parked call ${call.id} was not cancelled`),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\t// The scheduler faults the task without a result when its last abort attempt is cut off. That attempt skips the\n\t\t// hooks, which may be what cuts it off.\n\t\tconst hooks = (task.restarts ?? 0) < runtime.settings.restartLimit - 1 ? { tool } : undefined;\n\t\tawait settleFromSlot(runtime, task.input, call, hooks, { status: \"aborted\" }, code, message, context);\n\t},\n});\n\n/**\n * Park the call at its gates, before it runs (spec suspendable §5.1): the task sleeps at `call`, its slot `sleeping`,\n * and every wake runs the whole phase again. A sleep the commit refuses (no `until` or signals, a used key, a bad\n * deadline) ends the call `invalid_park`, through `afterTool`.\n */\nasync function parkAtGate(\n\truntime: Runtime,\n\tinput: ToolTaskInput,\n\tcall: ToolHookCall,\n\ttool: ToolRegistration,\n\t{ until, signals }: GateSleep,\n\tcontext: Context,\n): Promise<void> {\n\ttry {\n\t\tawait runtime.commit(async (tx) => {\n\t\t\tconst slot = toolSlot(await tx.doc(LiveDoc, runtime.conversationId), runtime.taskId);\n\t\t\tif (slot !== undefined) slot.status = \"sleeping\";\n\t\t\treturn {\n\t\t\t\tstatus: \"sleeping\",\n\t\t\t\tcheckpoint: { phase: \"call\" },\n\t\t\t\t...(until === undefined ? {} : { until }),\n\t\t\t\t...(signals === undefined ? {} : { signals }),\n\t\t\t};\n\t\t}, context);\n\t} catch (error) {\n\t\t// A close seals the Session before it signals the run.\n\t\tif (runtime.signal.aborted || closeSignal(runtime).aborted) throw error;\n\t\tconst invalid = harnessError(\n\t\t\t\"invalid_park\",\n\t\t\t`Tool call ${call.id} cannot wait at its gates: ${errorMessage(error)}`,\n\t\t);\n\t\tawait reject(runtime, input, call, tool, invalid, context);\n\t}\n}\n\n/**\n * Whether a sleeping task is a tool call parked at its gates, before its intent (spec suspendable §5.2): the registry,\n * and every open, wake it, so the gates installed then decide.\n */\nexport function gatedCall(record: TaskRecord<JsonValue, JsonValue, JsonValue>): boolean {\n\treturn (\n\t\trecord.kind === ToolTask.definition.name &&\n\t\trecord.state.status === \"sleeping\" &&\n\t\t(record.state.checkpoint as ToolTaskCheckpoint).phase === \"call\"\n\t);\n}\n\n/**\n * Whether a task's `abandonOnRestart` children survive a restart (spec suspendable §2.5): it is a tool call that was\n * not cut off while running, parked or not started yet, whatever its status.\n */\nexport function keepsChildren(record: TaskRecord<JsonValue, JsonValue, JsonValue>): boolean {\n\tif (record.kind !== ToolTask.definition.name) return false;\n\t// A tool task's checkpoint; absent once it holds or has its outcome.\n\tconst phase = (record.state.checkpoint as ToolTaskCheckpoint | undefined)?.phase;\n\treturn phase === \"call\" || phase === \"parked\";\n}\n\n/**\n * Record intent: the slot shows the call `running` (and a nested call the arguments it runs with), stored like progress\n * (`PROGRESS_COMMIT`), so parallel calls of one round share no immediate write to `diffra.live`; then the `execute`\n * checkpoint, durable before the tool runs.\n */\nasync function commitIntent(\n\truntime: Runtime,\n\tintent: Extract<ToolTaskCheckpoint, { phase: \"execute\" }>,\n\tcontext: Context,\n): Promise<void> {\n\tawait runtime.commit(\n\t\tasync (tx) => {\n\t\t\tconst found = findSlot(await tx.doc(LiveDoc, runtime.conversationId), runtime.taskId);\n\t\t\tif (found !== undefined) found.slot.status = \"running\";\n\t\t\t// Assigned whole: an equal value records no change, and a rerun corrects what an earlier attempt showed.\n\t\t\tif (found?.kind === \"nested\") found.slot.arguments = intent.arguments;\n\t\t\treturn undefined;\n\t\t},\n\t\tcontext,\n\t\tPROGRESS_COMMIT,\n\t);\n\tawait runtime.commit(() => ({ status: \"running\", checkpoint: intent }), context);\n}\n\n/**\n * End a call cut off `settings.restartLimit` times in a row (spec §5.4) with an error result, built from the slot like\n * an interrupted call's, instead of running it again. `failed`, like an interruption, so its owned work is aborted.\n */\nasync function endCutOff(\n\truntime: Runtime,\n\ttask: { readonly restarts?: number; readonly input: ToolTaskInput },\n\tcall: ToolHookCall,\n\tcontext: Context,\n): Promise<void> {\n\tconst message = `Tool ${call.name} was interrupted ${cutOffCount(task)}; it is not run again`;\n\tconst ending = { status: \"failed\", message, reason: \"restart_limit\" } as const;\n\t// Past the limit the hooks may be what keeps cutting the task off (`salvageable`).\n\tconst hooks = salvageable(task, runtime)\n\t\t? { tool: await toolForLimits(runtime, task.input, call.name, context) }\n\t\t: undefined;\n\tawait settleFromSlot(runtime, task.input, call, hooks, ending, \"restart_limit\", message, context);\n}\n\n/**\n * Settle a result the Harness decided in the `call` phase, without running the tool: the tool did not resolve, the\n * arguments are invalid, or `beforeTool` blocked the call. `afterTool` applies as to an executed call's result.\n */\nasync function reject(\n\truntime: Runtime,\n\tinput: ToolTaskInput,\n\tcall: ToolHookCall,\n\ttool: ToolRegistration | undefined,\n\tresult: ToolExecutionResult,\n\tcontext: Context,\n): Promise<void> {\n\tconst settled = await afterHarnessResult(runtime, input, call, tool, result, undefined, context);\n\tawait settle(runtime, input, call, COMPLETED, settled, context);\n}\n\n/**\n * Settle an error result built from the call's slot (`fromSlot`): an interruption, the restart limit, or an abort.\n * The tool is not running, so the slot read before the commit is still current when it commits. With `hooks`, the\n * result passes `afterTool` and is bounded with the limits of `hooks.tool` (the defaults when it is `undefined`);\n * without, it is settled as built, when the hooks may be what cuts the task off.\n */\nasync function settleFromSlot(\n\truntime: Runtime,\n\tinput: ToolTaskInput,\n\tcall: ToolHookCall,\n\thooks: { readonly tool: ToolRegistration | undefined } | undefined,\n\tending: Ending,\n\tcode: string,\n\tmessage: string,\n\tcontext: Context,\n): Promise<void> {\n\tconst live = await runtime.snapshot(LiveDoc, runtime.conversationId, context);\n\tconst { result, truncation } = fromSlot(\n\t\tlive === undefined ? undefined : toolSlot(live, runtime.taskId),\n\t\tcode,\n\t\tmessage,\n\t);\n\tconst settled =\n\t\thooks !== undefined\n\t\t\t? await afterHarnessResult(runtime, input, call, hooks.tool, result, truncation, context)\n\t\t\t: truncation === undefined\n\t\t\t\t? result\n\t\t\t\t: { ...result, diagnostics: [...(result.diagnostics ?? []), truncation] };\n\tawait settle(runtime, input, call, ending, settled, context);\n}\n\n/**\n * The tool whose output limits bound a hooks' result: the called tool, or none when it, or the agent, fails to resolve,\n * and for an unoffered call, which never resolves its name.\n */\nasync function toolForLimits(\n\truntime: Runtime,\n\tinput: ToolTaskInput,\n\tname: string,\n\tcontext: Context,\n): Promise<ToolRegistration | undefined> {\n\tif (isUnoffered(input)) return undefined;\n\treturn resolveTool(runtime, input, name, context).catch(() => undefined);\n}\n\n/** A model-issued call to a tool its request did not offer (spec §8.3). */\nfunction isUnoffered(input: ToolTaskInput): boolean {\n\treturn input.kind === \"model\" && input.unoffered === true;\n}\n\n/** The called tool: among the tools the model is offered for a model-issued call, else among those tools may call. */\nasync function resolveTool(\n\truntime: Runtime,\n\tinput: ToolTaskInput,\n\tname: string,\n\tcontext: Context,\n): Promise<ToolRegistration | undefined> {\n\tconst agent = await runtime.agent(context);\n\treturn (input.kind === \"model\" ? agent.tools : agent.callable).find((tool) => tool.name === name);\n}\n\n/** The tool's output limits, the defaults filled in; all defaults when the tool did not resolve. */\nfunction outputLimits(tool: ToolRegistration | undefined): OutputLimits {\n\treturn {\n\t\tmaxBytes: tool?.outputLimits?.maxBytes ?? DEFAULT_MAX_BYTES,\n\t\tmaxLines: tool?.outputLimits?.maxLines ?? DEFAULT_MAX_LINES,\n\t\tretain: tool?.outputLimits?.retain ?? \"head\",\n\t};\n}\n\n/** The call: from the input for a nested call, which hooks see with its parent, else from the assistant entry. */\nasync function readCall(runtime: Runtime, input: ToolTaskInput, context: Context): Promise<ToolHookCall> {\n\tif (input.kind === \"nested\") {\n\t\tcontext.telemetry.setAttributes({\n\t\t\t\"tool.name\": input.call.name,\n\t\t\t\"tool.call_id\": input.call.id,\n\t\t});\n\t\treturn { ...input.call, parent: { taskId: input.parent, callId: input.parentCallId } };\n\t}\n\tconst entry = await runtime.entry(AssistantEntry, input.assistant, context);\n\tconst message = entry?.model?.[0];\n\tconst call =\n\t\tmessage?.role === \"assistant\"\n\t\t\t? message.content.find(\n\t\t\t\t\t(content): content is ToolCall => content.type === \"toolCall\" && content.id === input.callId,\n\t\t\t\t)\n\t\t\t: undefined;\n\tif (call === undefined) throw new Error(`Entry ${input.assistant} has no tool call ${input.callId}`);\n\tcontext.telemetry.setAttributes({\n\t\t\"tool.name\": call.name,\n\t\t\"tool.call_id\": call.id,\n\t});\n\treturn call;\n}\n\n/** Arguments, or why they are invalid. */\ntype Checked =\n\t| { readonly kind: \"valid\"; readonly args: JsonObject }\n\t| { readonly kind: \"invalid\"; readonly error: string };\n\n/** The call's arguments as repaired by the tool; a throwing repair makes them invalid. */\nfunction prepare(tool: ToolRegistration, args: JsonObject): Checked {\n\tif (tool.prepareArguments === undefined) return { kind: \"valid\", args };\n\ttry {\n\t\treturn { kind: \"valid\", args: tool.prepareArguments(args) as JsonObject };\n\t} catch (error) {\n\t\treturn { kind: \"invalid\", error: errorMessage(error) };\n\t}\n}\n\n/** Arguments validated and coerced against the implementation's schema. */\nfunction validate(tool: ToolRegistration, call: ToolCall, args: JsonObject): Checked {\n\ttry {\n\t\treturn { kind: \"valid\", args: validateToolArguments(tool, { ...call, arguments: args }) as JsonObject };\n\t} catch (error) {\n\t\treturn { kind: \"invalid\", error: errorMessage(error) };\n\t}\n}\n\nfunction invalid(message: string): ToolExecutionResult {\n\treturn harnessError(\"invalid_arguments\", message);\n}\n\n/** What a running tool reported through its api: output, the last details, and diagnostics. */\ntype Reported = {\n\treadonly output: OutputBuffer;\n\treadonly limits: OutputLimits;\n\treadonly diagnostics: ToolDiagnostic[];\n\tdetails: JsonValue | undefined;\n};\n\n/** What a run of `execute()` starts from after a park: why it woke, and what the call last parked with. */\ntype Resumed = { readonly wake?: WakeReason; readonly checkpoint?: JsonValue };\n\n/** Execute with the resolved implementation, then settle its result or park the call. */\nasync function run(\n\truntime: Runtime,\n\tinput: ToolTaskInput,\n\tcall: ToolHookCall,\n\ttool: ToolRegistration,\n\targs: JsonObject,\n\tresumed: Resumed,\n\tcontext: Context,\n): Promise<void> {\n\tconst attempt = await startAttempt(runtime, input, call, tool, resumed, context);\n\tlet returned: ToolExecutionResult | ToolPark;\n\tlet ending = COMPLETED;\n\t// Execution time of this attempt, for a record without `startedAt` (`settle()`).\n\tlet measured: number | undefined;\n\ttry {\n\t\tattempt.env = await runtime.env(context);\n\t\tconst startedAt = performance.now();\n\t\ttry {\n\t\t\treturned = await tool.execute(args, attempt.api, context);\n\t\t} finally {\n\t\t\tmeasured = Math.round(performance.now() - startedAt);\n\t\t}\n\t} catch (error) {\n\t\tif (runtime.signal.aborted) {\n\t\t\tattempt.ended = true;\n\t\t\tfor (const waiter of await attempt.progress.stop()) waiter.reject(error);\n\t\t\tthrow error;\n\t\t}\n\t\treturned = { isError: true, diagnostics: [toolDiagnostic(\"tool_error\", errorMessage(error))] };\n\t\t// A throw, from `execute()` or from building the environment, ends the task `failed`, which cancels what the call\n\t\t// owned; it no longer supervises it. The error text is already in the result.\n\t\tending = { status: \"failed\", message: `Tool ${call.name} threw` };\n\t}\n\t// Details still waiting for a progress commit settle with the next commit, the park's or the result's.\n\tconst pending = await attempt.end();\n\ttry {\n\t\tif (isPark(returned)) {\n\t\t\tconst invalid = await park(runtime, input, call, tool, args, returned, attempt, context);\n\t\t\tif (invalid === undefined) {\n\t\t\t\tfor (const waiter of pending) waiter.resolve();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\treturned = harnessError(\"invalid_park\", `Tool ${call.name} returned an invalid park: ${invalid}`);\n\t\t\tending = { status: \"failed\", message: `Tool ${call.name} returned an invalid park` };\n\t\t}\n\t\tconst settled = await finalResult(runtime, input, call, tool, returned, attempt.reported, context);\n\t\tawait settle(runtime, input, call, ending, settled, context, measured);\n\t} catch (error) {\n\t\tfor (const waiter of pending) waiter.reject(error);\n\t\tthrow error;\n\t}\n\tfor (const waiter of pending) waiter.resolve();\n}\n\n/** One run of a tool's code (`execute()` or `cancel`): its api, what it reported, and its progress commits. */\ntype Attempt = {\n\treadonly api: ToolExecutionApi & ParkCarrier;\n\treadonly reported: Reported;\n\treadonly progress: Progress;\n\t/** Built for this run with `HarnessOptions.env`, so a rerun after recovery gets the conversation's at that time. */\n\tenv: ExecutionEnv | undefined;\n\t/** Set once the code returned: the api then throws, and no nested call is admitted. */\n\tended: boolean;\n\t/** End the attempt: let admitted nested calls commit, end the output, and stop progress; returns its waiters. */\n\tend(): Promise<PromiseWithResolvers<void>[]>;\n};\n\n/**\n * Start a run of the tool's code. A woken run adds to the details and diagnostics earlier runs left in the slot (spec\n * suspendable §4.2), so it starts from them; a nested call without progress keeps none there.\n */\nasync function startAttempt(\n\truntime: Runtime,\n\tinput: ToolTaskInput,\n\tcall: ToolHookCall,\n\ttool: ToolRegistration,\n\tresumed: Resumed,\n\tcontext: Context,\n): Promise<Attempt> {\n\tconst limits = outputLimits(tool);\n\tconst streams = input.kind === \"model\" || input.progress !== false;\n\tconst live =\n\t\tresumed.wake !== undefined && streams\n\t\t\t? await runtime.snapshot(LiveDoc, runtime.conversationId, context)\n\t\t\t: undefined;\n\tconst kept = live === undefined ? undefined : toolSlot(live, runtime.taskId);\n\tconst reported: Reported = {\n\t\toutput: new OutputBuffer(limits),\n\t\tlimits,\n\t\tdiagnostics: [...(kept?.diagnostics ?? [])],\n\t\tdetails: kept?.details,\n\t};\n\tconst progress = publishProgress(runtime, reported, streams, context);\n\t/** Nested call admissions this attempt started; its end waits for them, so settlement sees every nested call. */\n\tconst admissions: Promise<unknown>[] = [];\n\t// A caller that can rerun reattaches to its nested calls and child tasks after a restart; any other caller never\n\t// resumes, so they are abandoned (`TaskOptions.abandonOnRestart`).\n\tconst resumes = tool.replay === \"safe\";\n\t/** Default keys: the order of this attempt's calls, so a rerun that calls in the same order reattaches. */\n\tlet sequence = 0;\n\t/** This attempt's commit of the `MADE_NESTED_CALLS` memo. */\n\tlet madeNestedMemo: Promise<unknown> | undefined;\n\tconst assertLive = (): void => {\n\t\tif (attempt.ended) throw new Error(`Tool call ${call.id} has settled`);\n\t};\n\t/** The next position, for a nested call made without a key; after a wake a position may mean another call. */\n\tconst defaultKey = (): string => {\n\t\tif (resumed.wake !== undefined) throw new Error(`Tool call ${call.id} needs explicit keys after a wake`);\n\t\treturn String(++sequence);\n\t};\n\tconst api: ToolExecutionApi & ParkCarrier = {\n\t\t[BASE_PARKS]: new Set(),\n\t\ttaskId: runtime.taskId,\n\t\tconversationId: runtime.conversationId,\n\t\tcallId: call.id,\n\t\twake: resumed.wake,\n\t\tcheckpoint: resumed.checkpoint,\n\t\tregistry: runtime.registry,\n\t\tagent: runtime.agent,\n\t\tget models() {\n\t\t\treturn runtime.models;\n\t\t},\n\t\tget env() {\n\t\t\treturn attempt.env;\n\t\t},\n\t\tnow: () => runtime.now(),\n\t\toutput: (chunk, skipped) => {\n\t\t\tassertLive();\n\t\t\tif (reported.output.push(chunk, skipped)) progress.mark();\n\t\t},\n\t\toutputWindow:\n\t\t\tlimits.retain === \"tail\"\n\t\t\t\t? {\n\t\t\t\t\t\tmaxBytes: limits.maxBytes,\n\t\t\t\t\t\tmaxLines: limits.maxLines,\n\t\t\t\t\t\tminIntervalMs: runtime.settings.progress.outputIntervalMs,\n\t\t\t\t\t\tbytesPerSecond: PROGRESS_BYTES_PER_SECOND,\n\t\t\t\t\t}\n\t\t\t\t: undefined,\n\t\tretainedOutput: () => {\n\t\t\tassertLive();\n\t\t\tconst retained = reported.output.snapshot();\n\t\t\treturn { text: retained.text, truncated: retained.droppedBytes > 0 };\n\t\t},\n\t\tdiagnostic: (diagnostic) => {\n\t\t\tassertLive();\n\t\t\treported.diagnostics.push(copyJson(diagnostic, { omitUndefinedProperties: true }) as ToolDiagnostic);\n\t\t\tprogress.mark();\n\t\t},\n\t\tdetails: async (value, detailsContext) => {\n\t\t\tassertLive();\n\t\t\tdetailsContext.abortSignal?.throwIfAborted();\n\t\t\treported.details = copyJson(value, { omitUndefinedProperties: true });\n\t\t\tconst committed = progress.markAndWait();\n\t\t\t// Cancelling the wait leaves the update in place; the commit's own outcome stays observed.\n\t\t\tcommitted.catch(() => {});\n\t\t\treturn awaitWithContext(committed, detailsContext);\n\t\t},\n\t\tcommit: async (change, commitContext, options) => {\n\t\t\tlet result: Awaited<ReturnType<typeof change>> | undefined;\n\t\t\tawait runtime.commit(\n\t\t\t\tasync (tx) => {\n\t\t\t\t\tresult = await change(tx);\n\t\t\t\t\treturn undefined;\n\t\t\t\t},\n\t\t\t\tcommitContext,\n\t\t\t\toptions,\n\t\t\t);\n\t\t\treturn result as Awaited<ReturnType<typeof change>>;\n\t\t},\n\t\tmemo: runtime.memo,\n\t\treadSignal: runtime.readSignal,\n\t\tcreateTask: async <I, S extends { phase: string }, R, H extends object>(\n\t\t\ttask: Task<I, S, R, H>,\n\t\t\ttaskInput: I,\n\t\t\t{ key, ...options }: Omit<TaskOptions, \"conversationId\"> & { readonly key?: string },\n\t\t\ttaskContext: Context,\n\t\t): Promise<TaskId<R>> => {\n\t\t\tif (key !== undefined) checkKey(key);\n\t\t\telse if (resumed.wake !== undefined) throw new Error(`Tool call ${call.id} needs explicit keys after a wake`);\n\t\t\tconst child = options.ownership.kind === \"task\" && !resumes ? { abandonOnRestart: true, ...options } : options;\n\t\t\tlet id: TaskId<R> | undefined;\n\t\t\tawait runtime.commit(async (tx) => {\n\t\t\t\tif (key === undefined) {\n\t\t\t\t\tid = await tx.createTask(task, taskInput, child);\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\t\t\t\t// Opened, or created empty for a key not used yet.\n\t\t\t\tconst member = await tx.doc(NestedCallDoc, runtime.taskId, key, null);\n\t\t\t\tif (member.taskId !== undefined) {\n\t\t\t\t\tconst existing = member.kind === \"task\" ? await tx.task(member.taskId) : undefined;\n\t\t\t\t\tconst same =\n\t\t\t\t\t\texisting?.kind === task.definition.name &&\n\t\t\t\t\t\tjsonEqual(existing.input, copyJson(taskInput, { omitUndefinedProperties: true }));\n\t\t\t\t\tif (!same)\n\t\t\t\t\t\tthrow new Error(`Key ${key} of tool call ${call.id} was already used for another call or task`);\n\t\t\t\t\tid = member.taskId as TaskId<R>;\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\t\t\t\tid = await tx.createTask(task, taskInput, child);\n\t\t\t\tmember.kind = \"task\";\n\t\t\t\tmember.taskId = id;\n\t\t\t\treturn undefined;\n\t\t\t}, taskContext);\n\t\t\treturn id!;\n\t\t},\n\t\tgetTask: runtime.getTask,\n\t\twaitForTask: runtime.waitForTask,\n\t\tconversation: runtime.conversation,\n\t\tsnapshot: runtime.snapshot,\n\t\tsnapshotAsOf: runtime.snapshotAsOf,\n\t\twatchDoc: runtime.watchDoc,\n\t\texecuteTool: (async (\n\t\t\tname: string,\n\t\t\ttoolArgs: JsonObject,\n\t\t\tcallContext: Context,\n\t\t\toptions: { readonly key?: string; readonly progress?: boolean; readonly wait?: boolean } = {},\n\t\t) => {\n\t\t\tassertLive();\n\t\t\tconst key = options.key ?? defaultKey();\n\t\t\tif (options.key !== undefined) checkKey(options.key);\n\t\t\t// The memo first, once per attempt; a failed one is tried again by the next call.\n\t\t\tmadeNestedMemo ??= runtime.memo(MADE_NESTED_CALLS, true, callContext).catch((error: unknown) => {\n\t\t\t\tmadeNestedMemo = undefined;\n\t\t\t\tthrow error;\n\t\t\t});\n\t\t\t// Registered now, so the attempt's end waits for it.\n\t\t\tconst admission = madeNestedMemo.then(() =>\n\t\t\t\tstartNestedCall(\n\t\t\t\t\truntime,\n\t\t\t\t\tcall.id,\n\t\t\t\t\tname,\n\t\t\t\t\ttoolArgs,\n\t\t\t\t\t{ key, progress: options.progress, abandonOnRestart: !resumes },\n\t\t\t\t\tcallContext,\n\t\t\t\t),\n\t\t\t);\n\t\t\tadmissions.push(admission);\n\t\t\tconst id = await admission;\n\t\t\tconst nested: NestedToolCall = {\n\t\t\t\ttaskId: id,\n\t\t\t\tresult: async (resultContext) => {\n\t\t\t\t\tconst settled = await runtime.waitForTask(id, resultContext);\n\t\t\t\t\tconst stored = (await runtime.snapshot(NestedCallDoc, runtime.taskId, key, resultContext))?.result;\n\t\t\t\t\t// A copy the tool may change; a nested call the scheduler faulted or orphaned stored none.\n\t\t\t\t\treturn stored === undefined\n\t\t\t\t\t\t? fallbackResult(id, name, settled.state.outcome)\n\t\t\t\t\t\t: (copyJson(stored as unknown as JsonValue) as unknown as NestedToolExecutionResult);\n\t\t\t\t},\n\t\t\t};\n\t\t\treturn options.wait === false ? nested : nested.result(callContext);\n\t\t}) as ToolExecutionApi[\"executeTool\"],\n\t};\n\tconst attempt: Attempt = {\n\t\tapi,\n\t\treported,\n\t\tprogress,\n\t\tenv: undefined,\n\t\tended: false,\n\t\tend: async () => {\n\t\t\tattempt.ended = true;\n\t\t\t// No admission starts after `ended`; let those underway commit, so settlement aborts and lists their calls.\n\t\t\tawait Promise.allSettled(admissions);\n\t\t\treported.output.end();\n\t\t\treturn progress.stop();\n\t\t},\n\t};\n\treturn attempt;\n}\n\n/**\n * Park the call (spec suspendable §4.2). One commit persists the details and diagnostics the attempt reported, shows the\n * slot `sleeping` or `waiting` without output, and stores the `parked` checkpoint with the park's sleep or wait; the\n * call's live nested calls keep running. Returns why the park is invalid instead, when it is. When the commit is refused\n * because the call was abort-marked meanwhile, `cancel` cleans up what the run started before the error ends the run.\n */\nasync function park(\n\truntime: Runtime,\n\tinput: ToolTaskInput,\n\tcall: ToolHookCall,\n\ttool: ToolRegistration,\n\targs: JsonObject,\n\treturned: ToolPark,\n\tattempt: Attempt,\n\tcontext: Context,\n): Promise<string | undefined> {\n\tconst { api, reported } = attempt;\n\tconst shape = parkError(tool, returned, api);\n\tif (shape !== undefined) return shape;\n\tif (returned.kind === \"wait\") {\n\t\tfor (const id of returned.on) {\n\t\t\tif ((await runtime.getTask(id, context))?.owner !== runtime.taskId)\n\t\t\t\treturn `task ${id} is not owned by the call`;\n\t\t}\n\t}\n\tconst { checkpoint } = returned;\n\tconst parked = {\n\t\tphase: \"parked\",\n\t\targuments: args,\n\t\treplay: tool.replay ?? \"unsafe\",\n\t\t...(checkpoint === undefined ? {} : { checkpoint }),\n\t} as const;\n\tconst streams = input.kind === \"model\" || input.progress !== false;\n\ttry {\n\t\tawait runtime.commit(async (tx) => {\n\t\t\tconst slot = toolSlot(await tx.doc(LiveDoc, runtime.conversationId), runtime.taskId);\n\t\t\tif (slot !== undefined) {\n\t\t\t\tif (streams && reported.details !== undefined) assignJson(slot, \"details\", reported.details);\n\t\t\t\tif (streams && reported.diagnostics.length > 0) assignJson(slot, \"diagnostics\", reported.diagnostics);\n\t\t\t\tclearOutput(slot);\n\t\t\t\tslot.status = returned.kind === \"sleep\" ? \"sleeping\" : \"waiting\";\n\t\t\t}\n\t\t\tif (returned.kind === \"sleep\") {\n\t\t\t\tconst { until, signals } = returned;\n\t\t\t\treturn {\n\t\t\t\t\tstatus: \"sleeping\",\n\t\t\t\t\tcheckpoint: parked,\n\t\t\t\t\t...(until === undefined ? {} : { until }),\n\t\t\t\t\t...(signals === undefined ? {} : { signals }),\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn { status: \"waiting\", checkpoint: parked, on: returned.on, policy: returned.policy };\n\t\t}, context);\n\t} catch (error) {\n\t\t// The sleep or wait broke a rule the commit checks: a deadline, a used key, a missing task, a wait cycle. A close\n\t\t// seals the Session before it signals the run.\n\t\tif (!runtime.signal.aborted && !closeSignal(runtime).aborted) return errorMessage(error);\n\t\t// Abort-marked meanwhile, unlike a close, which leaves the run to recovery: the park is not stored, so clean up\n\t\t// with its checkpoint now, in a context only the Harness's close cancels.\n\t\tconst cleanup = withAbortSignal(closeSignal(runtime), withoutAbortSignal(context));\n\t\tif ((await runtime.getTask(runtime.taskId, cleanup))?.abortRequested === true) {\n\t\t\tawait cancel(runtime, input, call, tool, args, checkpoint, cleanup);\n\t\t}\n\t\tthrow error;\n\t}\n\treturn undefined;\n}\n\n/**\n * Run the tool's `cancel`, if it has one, to clean up the external work of a call that parked (spec suspendable §4.2):\n * `api.checkpoint` is the last park's, `api.wake` undefined, and the api starts no nested calls or tasks. A throw is\n * reported; the call ends either way.\n */\nasync function cancel(\n\truntime: Runtime,\n\tinput: ToolTaskInput,\n\tcall: ToolHookCall,\n\ttool: ToolRegistration,\n\targs: JsonObject,\n\tcheckpoint: JsonValue | undefined,\n\tcontext: Context,\n): Promise<void> {\n\tif (tool.cancel === undefined) return;\n\tconst attempt = await startAttempt(\n\t\truntime,\n\t\tinput,\n\t\tcall,\n\t\ttool,\n\t\tcheckpoint === undefined ? {} : { checkpoint },\n\t\tcontext,\n\t);\n\tconst refused = (): never => {\n\t\tthrow new Error(`Tool ${call.name} cannot start nested calls or tasks in cancel`);\n\t};\n\ttry {\n\t\tattempt.env = await runtime.env(context);\n\t\t// Spread once the environment is built: the copy reads the getters once.\n\t\tawait tool.cancel(args, { ...attempt.api, executeTool: refused, createTask: refused }, context);\n\t} catch (error) {\n\t\t// Only the Harness's close cancels a cleanup.\n\t\tif (context.abortSignal?.aborted === true) throw error;\n\t\tawait reportToolError(runtime, tool, error, context);\n\t}\n\tfor (const waiter of await attempt.end()) waiter.resolve();\n}\n\n/**\n * The Harness clock and timers for progress pacing. After the invocation ends nothing more commits, and the clock\n * answers with the last time it read.\n */\nfunction progressClock(runtime: Runtime): ProgressClock {\n\tlet last = 0;\n\treturn {\n\t\tnow: () => {\n\t\t\ttry {\n\t\t\t\tlast = runtime.now();\n\t\t\t} catch {\n\t\t\t\t// The invocation ended.\n\t\t\t}\n\t\t\treturn last;\n\t\t},\n\t\tsetTimer: (callback, delayMs) => runtime.setTimer(callback, delayMs),\n\t};\n}\n\n/**\n * Throttled commits of what the tool reported into its slot, in `diffra.live.tools` or `diffra.live.nestedTools`, each writing\n * only what changed since the last one, deferred (`PROGRESS_COMMIT`); none when `enabled` is false.\n */\nfunction publishProgress(runtime: Runtime, reported: Reported, enabled: boolean, context: Context): Progress {\n\t// The slot holds what the attempt started from (`startAttempt()`).\n\tlet written = { text: \"\", details: reported.details, diagnostics: reported.diagnostics.length };\n\treturn new Progress(\n\t\tasync () => {\n\t\t\tif (!enabled) return 0;\n\t\t\t// Capture everything synchronously: the tool keeps reporting while the commit is in flight.\n\t\t\tconst snapshot = reported.output.snapshot();\n\t\t\tconst current = { text: snapshot.text, details: reported.details, diagnostics: reported.diagnostics.length };\n\t\t\tconst added = reported.diagnostics.slice(written.diagnostics, current.diagnostics);\n\t\t\tconst detailsChanged = current.details !== written.details;\n\t\t\t// What the commit writes, as Chord diffs the string: an append, a trim plus an append of what follows the shared\n\t\t\t// part, or the whole window when its bounded overlap search finds nothing.\n\t\t\tlet bytes = 0;\n\t\t\tif (snapshot.text !== written.text) {\n\t\t\t\tconst shared = snapshot.text.startsWith(written.text)\n\t\t\t\t\t? written.text.length\n\t\t\t\t\t: overlap(written.text, snapshot.text, 65_536);\n\t\t\t\tbytes += utf8ByteLength(snapshot.text.slice(shared));\n\t\t\t}\n\t\t\tif (detailsChanged) bytes += utf8ByteLength(JSON.stringify(current.details ?? null));\n\t\t\tif (added.length > 0) bytes += utf8ByteLength(JSON.stringify(added));\n\t\t\tawait runtime.commit(\n\t\t\t\tasync (tx) => {\n\t\t\t\t\tconst slot = toolSlot(await tx.doc(LiveDoc, runtime.conversationId), runtime.taskId);\n\t\t\t\t\tif (slot === undefined) return undefined;\n\t\t\t\t\t// REMINDER: assign `output` as one string field. Chord then diffs it into an append, or a trim plus an\n\t\t\t\t\t// append for a sliding tail; replacing the slot object would record the whole window on every commit.\n\t\t\t\t\tif ((slot.output ?? \"\") !== snapshot.text) slot.output = snapshot.text;\n\t\t\t\t\tif (snapshot.droppedBytes > 0) slot.droppedBytes = snapshot.droppedBytes;\n\t\t\t\t\tif (snapshot.droppedLines > 0) slot.droppedLines = snapshot.droppedLines;\n\t\t\t\t\t// Diff details leaf by leaf and append new diagnostics, so each commit writes only what changed.\n\t\t\t\t\tif (detailsChanged && current.details !== undefined) {\n\t\t\t\t\t\tassignJson(slot, \"details\", current.details);\n\t\t\t\t\t}\n\t\t\t\t\tif (added.length > 0) {\n\t\t\t\t\t\tif (slot.diagnostics === undefined) slot.diagnostics = [];\n\t\t\t\t\t\tfor (const diagnostic of added) slot.diagnostics.push(diagnostic);\n\t\t\t\t\t}\n\t\t\t\t\treturn undefined;\n\t\t\t\t},\n\t\t\t\tcontext,\n\t\t\t\tPROGRESS_COMMIT,\n\t\t\t);\n\t\t\twritten = current;\n\t\t\treturn bytes;\n\t\t},\n\t\t(error) => {\n\t\t\t// Rejections after an abort mark or close are expected; the committed state stays consistent.\n\t\t\tif (!runtime.signal.aborted) runtime.report(error);\n\t\t},\n\t\truntime.settings.progress.outputIntervalMs,\n\t\tprogressClock(runtime),\n\t);\n}\n\n/**\n * The settled result: the tool's result with the retained output and last details as fallbacks, its diagnostics after\n * those reported through the api, `afterTool` applied, explicit text bounded, and `structuredOutput` checked against the\n * tool's schema, with the Harness's diagnostics last. A nested call whose `structuredOutput` breaks the contract gets an\n * error result without it; a model-issued call only loses it, and the break is reported to the host.\n */\nasync function finalResult(\n\truntime: Runtime,\n\tinput: ToolTaskInput,\n\tcall: ToolHookCall,\n\ttool: ToolRegistration,\n\tresult: ToolExecutionResult,\n\treported: Reported,\n\tcontext: Context,\n): Promise<ToolExecutionResult> {\n\tconst harness: ToolDiagnostic[] = [];\n\tconst retained = result.output === undefined ? reported.output.snapshot() : undefined;\n\tconst output: Content =\n\t\tretained === undefined ? result.output! : retained.text === \"\" ? [] : [{ type: \"text\", text: retained.text }];\n\tlet final: ToolExecutionResult = {\n\t\t...result,\n\t\toutput,\n\t\tdetails: result.details === undefined ? reported.details : result.details,\n\t\tdiagnostics: [...reported.diagnostics, ...(result.diagnostics ?? [])],\n\t};\n\tawait runtime.hooks.each(\"afterTool\", async (hook) => {\n\t\tfinal = (await hook(call, final, runtime, context)) ?? final;\n\t});\n\t// The retained output's truncation applies only while afterTool kept that output.\n\tif (retained !== undefined && retained.droppedBytes > 0 && final.output === output) {\n\t\tharness.push(truncated(retained, reported.limits.retain));\n\t}\n\tconst bounded = boundContent(final.output ?? [], reported.limits);\n\tif (bounded.droppedBytes > 0) harness.push(truncated(bounded, reported.limits.retain));\n\tconst broken = structuredOutputError(tool, final);\n\tif (broken !== undefined) {\n\t\tconst { structuredOutput: _dropped, ...rest } = final;\n\t\tif (input.kind === \"nested\") {\n\t\t\tfinal = { ...rest, isError: true };\n\t\t\tharness.push(toolDiagnostic(\"invalid_structured_output\", broken));\n\t\t} else {\n\t\t\t// The model never sees structured output, so its call stands; the host learns of the broken tool.\n\t\t\tfinal = rest;\n\t\t\tawait reportToolError(runtime, tool, new Error(broken), context);\n\t\t}\n\t}\n\t// Programs get the tool's own value: without a schema, its output. The model reads only `output`, so model-issued\n\t// calls skip both.\n\tif (input.kind === \"nested\" && tool.structuredOutputSchema === undefined) {\n\t\tfinal = { ...final, structuredOutput: outputValue(bounded.content) as JsonValue };\n\t}\n\t// A schema tool's error result without structured output has its text only in the output, which programs never\n\t// get: it becomes an error diagnostic, as a thrown error's message does, unless one says what went wrong already.\n\tif (\n\t\tinput.kind === \"nested\" &&\n\t\ttool.structuredOutputSchema !== undefined &&\n\t\tfinal.isError === true &&\n\t\tfinal.structuredOutput === undefined &&\n\t\t![...(final.diagnostics ?? []), ...harness].some((diagnostic) => diagnostic.severity === \"error\")\n\t) {\n\t\tconst text = bounded.content.flatMap((item) => (item.type === \"text\" ? [item.text] : [])).join(\"\\n\");\n\t\tif (text !== \"\") harness.push(toolDiagnostic(\"tool_error\", text));\n\t}\n\treturn { ...final, output: bounded.content, diagnostics: [...(final.diagnostics ?? []), ...harness] };\n}\n\n/** Report a failure of the tool's code as an `extension_error`, naming its extension when the agent resolves. */\nasync function reportToolError(\n\truntime: Runtime,\n\ttool: ToolRegistration,\n\terror: unknown,\n\tcontext: Context,\n): Promise<void> {\n\tconst extension = await runtime.agent(context).then(\n\t\t(agent) => toolExtension(agent, tool.name),\n\t\t() => undefined,\n\t);\n\truntime.report(error, { kind: \"extension\", ...optionalExtension(extension) });\n}\n\n/**\n * A result the Harness wrote itself, without executing the tool, after the `afterTool` chain, normalized like an\n * executed call's: the output bounded with the tool's limits (the defaults when it did not resolve), a truncation\n * diagnostic when that dropped something, and the hooks' `structuredOutput` dropped, since the tool never produced\n * one. A nested call that the hooks turned into a success gets the bounded output as its value, as a schema-less\n * tool's success does, unless the tool declares a schema. `usage` is kept and recorded; `control` applies only when\n * the task completes. `truncation` describes what the result's own output lost before (a slot's retained output); it\n * is kept only while the hooks keep that output.\n */\nasync function afterHarnessResult(\n\truntime: Runtime,\n\tinput: ToolTaskInput,\n\tcall: ToolHookCall,\n\ttool: ToolRegistration | undefined,\n\tresult: ToolExecutionResult,\n\ttruncation: ToolDiagnostic | undefined,\n\tcontext: Context,\n): Promise<ToolExecutionResult> {\n\tlet final = result;\n\tawait runtime.hooks.each(\"afterTool\", async (hook) => {\n\t\tfinal = (await hook(call, final, runtime, context)) ?? final;\n\t});\n\tconst harness: ToolDiagnostic[] = [];\n\tif (truncation !== undefined && final.output === result.output) harness.push(truncation);\n\tconst limits = outputLimits(tool);\n\tconst bounded = boundContent(final.output ?? [], limits);\n\tif (bounded.droppedBytes > 0) harness.push(truncated(bounded, limits.retain));\n\tconst { structuredOutput: _dropped, ...rest } = final;\n\tconst value =\n\t\tinput.kind === \"nested\" && final.isError !== true && tool?.structuredOutputSchema === undefined\n\t\t\t? { structuredOutput: outputValue(bounded.content) as JsonValue }\n\t\t\t: {};\n\treturn { ...rest, ...value, output: bounded.content, diagnostics: [...(rest.diagnostics ?? []), ...harness] };\n}\n\nconst structuredValidators = new WeakMap<object, Validator>();\n\n/** Why a result's `structuredOutput` breaks the tool's contract, or `undefined` when it keeps it. */\nfunction structuredOutputError(tool: ToolRegistration, result: ToolExecutionResult): string | undefined {\n\tconst schema = tool.structuredOutputSchema;\n\tconst value = result.structuredOutput;\n\tif (schema === undefined) {\n\t\treturn value === undefined\n\t\t\t? undefined\n\t\t\t: `Tool ${tool.name} returned structuredOutput but declares no structuredOutputSchema`;\n\t}\n\tif (value === undefined) {\n\t\treturn result.isError === true ? undefined : `Tool ${tool.name} returned no structuredOutput`;\n\t}\n\tlet validator = structuredValidators.get(schema);\n\tif (validator === undefined) {\n\t\tvalidator = compile(schema, { formats, unresolvedRefs: \"reject\" });\n\t\tstructuredValidators.set(schema, validator);\n\t}\n\tif (validator.check(value)) return undefined;\n\tconst [first] = validator.errors(value);\n\tconst path =\n\t\tfirst?.path\n\t\t\t.slice(1)\n\t\t\t.split(\"/\")\n\t\t\t.map((segment) => segment.replace(/~1/g, \"/\").replace(/~0/g, \"~\"))\n\t\t\t.join(\".\") || \"root\";\n\treturn `Tool ${tool.name} returned structuredOutput that does not match its schema: ${path}: ${first?.message ?? \"invalid\"}`;\n}\n\n/**\n * Commit the tool's terminal state and mark its slot done. A model-issued call appends its result entry and ends with\n * the entry ID; a nested call writes its result to the caller's `NestedCallDoc`, records its usage, and ends with a\n * small receipt. Nested calls this call left running are aborted first, so they report into their slots before the\n * slots below the call leave `diffra.live`. `control` applies only when the task completes.\n */\nasync function settle(\n\truntime: Runtime,\n\tinput: ToolTaskInput,\n\tcall: ToolHookCall,\n\tending: Ending,\n\tresult: ToolExecutionResult,\n\tcontext: Context,\n\tmeasured?: number,\n): Promise<void> {\n\t// A crash in between leaves the call in `execute`: a safe rerun reattaches to the calls, an interruption ends here.\n\t// Every live nested call the task owns, also those an earlier attempt made and this one never called again.\n\tconst nestedIds = (await runtime.ownedTasks(context))\n\t\t.filter((record) => record.kind === ToolTask.definition.name && (record.input as ToolTaskInput).kind === \"nested\")\n\t\t.map((record) => record.id);\n\t// Read before the settling commit: no admission starts after `ended`, and those underway were awaited.\n\tconst madeNested = (await runtime.memo(MADE_NESTED_CALLS, context)) === true;\n\t// Mark them all before waiting for any: one may run until a sibling is cancelled.\n\tawait Promise.all(nestedIds.map((id) => runtime.abortOwned(id, context)));\n\tawait runtime.commit(async (tx, current) => {\n\t\tconst conversationId = runtime.conversationId;\n\t\t// The call's whole span, parks, reruns, and downtime included (spec suspendable §4.2); a record from before\n\t\t// lifecycle times keeps the last attempt's execution time.\n\t\tconst durationMs = current.startedAt === undefined ? measured : runtime.now() - current.startedAt;\n\t\tconst live = await tx.doc(LiveDoc, conversationId);\n\t\tconst found = findSlot(live, runtime.taskId);\n\t\tlet settled: ToolTaskResult;\n\t\tif (input.kind === \"nested\") {\n\t\t\tconst nested = nestedResult(runtime.taskId, result, durationMs);\n\t\t\tif (nested.usage !== undefined) await recordUsage(tx, conversationId, \"tools\", call.name, nested.usage);\n\t\t\t// The caller is never terminal before its owned nested calls, so its document is open; another task in it is a\n\t\t\t// bug, not a race.\n\t\t\tconst state = await tx.doc(NestedCallDoc, input.parent, input.key, null);\n\t\t\tif (state.taskId !== runtime.taskId) throw new Error(`Nested call ${call.id} is not in its caller's index`);\n\t\t\tstate.result = nested as unknown as Draft<JsonRepresentation<NestedToolExecutionResult>>;\n\t\t\tif (found?.kind === \"nested\") {\n\t\t\t\tfinishSlot(found.slot);\n\t\t\t\tfound.slot.summary = summaryOf(nested, result.output ?? []);\n\t\t\t}\n\t\t\tsettled = { kind: \"nested\" };\n\t\t} else {\n\t\t\tconst timing = { timestamp: runtime.now(), durationMs };\n\t\t\tconst entry = await appendToolResult(tx, conversationId, call, result, timing);\n\t\t\tif (found?.kind === \"model\") {\n\t\t\t\tfinishSlot(found.slot);\n\t\t\t\tfound.slot.entry = entry.id;\n\t\t\t}\n\t\t\t// Tools build control objects freely; drop keys set to undefined so the task result is strict JSON.\n\t\t\tconst control =\n\t\t\t\tresult.control === undefined || ending.status !== \"completed\"\n\t\t\t\t\t? {}\n\t\t\t\t\t: { control: copyJson(result.control as JsonValue, { omitUndefinedProperties: true }) as ToolControl };\n\t\t\tsettled = { kind: \"model\", entryId: entry.id, ...control };\n\t\t}\n\t\t// A call that made no nested calls, in any attempt, has no slots below it; skipping the scan keeps many leaves\n\t\t// linear. Committed before the read: no nested call is admitted after `ended`.\n\t\tif (madeNested) removeNestedSlots(live, runtime.taskId);\n\t\tif (ending.status === \"aborted\") return { status: \"terminal\", outcome: { status: \"aborted\", result: settled } };\n\t\tif (ending.status === \"failed\") {\n\t\t\tconst error = {\n\t\t\t\tmessage: ending.message,\n\t\t\t\t...(ending.reason === undefined ? {} : { detail: { reason: ending.reason } }),\n\t\t\t};\n\t\t\treturn { status: \"terminal\", outcome: { status: \"failed\", error, result: settled } };\n\t\t}\n\t\treturn { status: \"terminal\", outcome: { status: \"completed\", result: settled } };\n\t}, context);\n}\n\n/**\n * A nested call's result, as stored and returned: strict JSON, without `output`, which only the model reads, and\n * without `control`, which only model-issued calls apply.\n */\nfunction nestedResult(\n\ttaskId: TaskId,\n\tresult: ToolExecutionResult,\n\tdurationMs: number | undefined,\n): NestedToolExecutionResult {\n\tconst nested = {\n\t\ttaskId,\n\t\tstructuredOutput: result.structuredOutput,\n\t\tisError: result.isError ?? false,\n\t\tdetails: result.details,\n\t\tdiagnostics: result.diagnostics ?? [],\n\t\tusage: result.usage,\n\t\tdurationMs,\n\t};\n\treturn copyJson(nested as unknown as JsonValue, {\n\t\tomitUndefinedProperties: true,\n\t}) as unknown as NestedToolExecutionResult;\n}\n\n/**\n * Create nested call `key` of the call `parentCallId` in one commit: its tool task, owned by the calling task, its slot,\n * and its `NestedCallDoc`. A key already made returns that call's task when it names the same tool and arguments.\n */\nasync function startNestedCall(\n\truntime: Runtime,\n\tparentCallId: string,\n\tname: string,\n\targs: JsonObject,\n\toptions: { readonly key: string; readonly progress: boolean | undefined; readonly abandonOnRestart: boolean },\n\tcontext: Context,\n): Promise<TaskId<ToolTaskResult>> {\n\tconst key = options.key;\n\tconst call: ToolCall = {\n\t\ttype: \"toolCall\",\n\t\tid: `${parentCallId}/${key}`,\n\t\tname,\n\t\targuments: copyJson(args, { omitUndefinedProperties: true }) as JsonObject,\n\t};\n\tlet id: TaskId<ToolTaskResult> | undefined;\n\tlet replayed = false;\n\tawait runtime.commit(async (tx) => {\n\t\t// Opened, or created empty for a key not made yet.\n\t\tconst state = await tx.doc(NestedCallDoc, runtime.taskId, key, null);\n\t\tconst existing = state.taskId;\n\t\tif (existing !== undefined) {\n\t\t\tconst input =\n\t\t\t\tstate.kind === \"task\" ? undefined : ((await tx.task(existing))?.input as ToolTaskInput | undefined);\n\t\t\tconst same =\n\t\t\t\tinput?.kind === \"nested\" &&\n\t\t\t\tinput.call.name === name &&\n\t\t\t\tjsonEqual(input.call.arguments as JsonValue, call.arguments as JsonValue);\n\t\t\tif (!same) throw new Error(`Nested call ${call.id} was already made with another tool or other arguments`);\n\t\t\tid = existing as TaskId<ToolTaskResult>;\n\t\t\treplayed = state.result !== undefined;\n\t\t\treturn undefined;\n\t\t}\n\t\tconst input: ToolTaskInput = {\n\t\t\tkind: \"nested\",\n\t\t\tparent: runtime.taskId,\n\t\t\tparentCallId,\n\t\t\tkey,\n\t\t\tcall,\n\t\t\t...(options.progress === false ? { progress: false } : {}),\n\t\t};\n\t\tconst created = await tx.createTask(ToolTask, input, {\n\t\t\townership: { kind: \"task\", taskId: runtime.taskId },\n\t\t\tabandonOnRestart: options.abandonOnRestart,\n\t\t});\n\t\tstate.kind = \"nested\";\n\t\tstate.taskId = created;\n\t\tconst live = await tx.doc(LiveDoc, runtime.conversationId);\n\t\tlive.nestedTools ??= [];\n\t\tconst slot: NestedToolSlot = {\n\t\t\tcallId: call.id,\n\t\t\tparentCallId,\n\t\t\tparentTaskId: runtime.taskId,\n\t\t\tname,\n\t\t\ttaskId: created,\n\t\t\targuments: call.arguments as JsonObject,\n\t\t\tstatus: \"pending\",\n\t\t};\n\t\tlive.nestedTools.push(slot as Draft<NestedToolSlot>);\n\t\tid = created;\n\t\treturn undefined;\n\t}, context);\n\tif (replayed) {\n\t\tcontext.telemetry.addEvent(\"diffra.durable.replay\", { \"tool.name\": name });\n\t}\n\treturn id!;\n}\n\n/**\n * What programs get of a tool's output when it declares no schema: one text item as its string, one image as itself,\n * nothing as `\"\"`, and anything else as the content list.\n */\nfunction outputValue(output: Content): string | ImageContent | Content {\n\tif (output.length === 0) return \"\";\n\tif (output.length > 1) return output;\n\tconst [only] = output;\n\treturn only!.type === \"text\" ? only!.text : only!;\n}\n\n/** What the caller gets for a nested call without a stored result: one the scheduler faulted or orphaned. */\nfunction fallbackResult(taskId: TaskId, name: string, outcome: TaskOutcome<ToolTaskResult>): NestedToolExecutionResult {\n\tconst message =\n\t\toutcome.status === \"faulted\"\n\t\t\t? `Tool ${name} failed: ${outcome.error.message}`\n\t\t\t: outcome.status === \"orphaned\"\n\t\t\t\t? `Tool ${name} could not resume: ${outcome.reason}`\n\t\t\t\t: `Tool ${name} ended without a result`;\n\tconst error = harnessError(outcome.status, message);\n\treturn { taskId, isError: true, diagnostics: error.diagnostics ?? [] };\n}\n\n/**\n * How a tool task ends; the result entry is appended either way. `failed` (execution threw or was interrupted)\n * records cancellation intent for the conversations the call owns; a result with `isError` still completes.\n */\ntype Ending =\n\t| { readonly status: \"completed\" | \"aborted\" }\n\t| { readonly status: \"failed\"; readonly message: string; readonly reason?: string };\n\nconst COMPLETED: Ending = { status: \"completed\" };\n\n/**\n * An error result from the slot's durable partial output, details, and diagnostics, ending with `code`; and the\n * truncation diagnostic of that output, when its bounds dropped some, which the caller adds after `afterTool`.\n */\nfunction fromSlot(\n\tslot: Readonly<ToolSlot | NestedToolSlot> | undefined,\n\tcode: string,\n\tmessage: string,\n): { readonly result: ToolExecutionResult; readonly truncation?: ToolDiagnostic } {\n\tconst droppedBytes = slot?.droppedBytes ?? 0;\n\tconst result: ToolExecutionResult = {\n\t\toutput: slot?.output === undefined || slot.output === \"\" ? [] : [{ type: \"text\", text: slot.output }],\n\t\tisError: true,\n\t\t...(slot?.details === undefined ? {} : { details: slot.details }),\n\t\tdiagnostics: [...(slot?.diagnostics ?? []), toolDiagnostic(code, message)],\n\t};\n\tif (droppedBytes === 0) return { result };\n\treturn { result, truncation: truncated({ droppedBytes, droppedLines: slot?.droppedLines ?? 0 }) };\n}\n\n/** An error result the Harness writes itself: no content and one `error` diagnostic with `code`. */\nexport function harnessError(code: string, message: string): ToolExecutionResult {\n\treturn { output: [], isError: true, diagnostics: [toolDiagnostic(code, message)] };\n}\n\nfunction toolDiagnostic(code: string, message: string): ToolDiagnostic {\n\treturn { severity: \"error\", code, message };\n}\n\n/** The Harness's truncation diagnostic; `retain` is unknown when rebuilt from a slot after recovery. */\nfunction truncated(\n\tdropped: { readonly droppedLines: number; readonly droppedBytes: number },\n\tretain?: \"head\" | \"tail\",\n): ToolDiagnostic {\n\tconst kept = retain === undefined ? \"\" : ` to its ${retain === \"head\" ? \"beginning\" : \"end\"}`;\n\treturn {\n\t\tseverity: \"warn\",\n\t\tcode: \"truncated\",\n\t\tmessage: `Output truncated${kept}: ${dropped.droppedLines} lines, ${dropped.droppedBytes} bytes dropped`,\n\t};\n}\n\n/** Error text a nested call's summary keeps. */\nconst MAX_SUMMARY_ERROR_CHARS = 500;\n\n/**\n * How a nested call ended, for its slot: error text, from its diagnostics or else its `output`, bounded. The bound is a\n * copy, so the slot never keeps a large output alive through a slice of it.\n */\nfunction summaryOf(result: NestedToolExecutionResult, output: Content): NestedToolSummary {\n\tconst error = result.isError ? ownedSlice(errorTextOf(result, output), 0, MAX_SUMMARY_ERROR_CHARS) : \"\";\n\treturn {\n\t\tisError: result.isError,\n\t\t...(result.durationMs === undefined ? {} : { durationMs: result.durationMs }),\n\t\t...(result.usage === undefined ? {} : { usage: result.usage }),\n\t\t...(error === \"\" ? {} : { error }),\n\t};\n}\n\n/** The error messages of a nested result, else the text items of its output, joined with newlines. */\nfunction errorTextOf(result: NestedToolExecutionResult, output: Content): string {\n\tconst errors = result.diagnostics.filter((diagnostic) => diagnostic.severity === \"error\");\n\tif (errors.length > 0) return errors.map((diagnostic) => diagnostic.message).join(\"\\n\");\n\treturn output.flatMap((item) => (item.type === \"text\" ? [item.text] : [])).join(\"\\n\");\n}\n\n/**\n * Append a `diffra.tool-result` entry. The content ends with the rendered diagnostics, so the stored message is exactly\n * what the model sees; `data` keeps the structured list. A result's usage is added to `diffra.usage` in the same commit.\n */\nexport async function appendToolResult(\n\ttx: Tx,\n\tconversationId: ConversationId,\n\tcall: ToolCall,\n\tresult: ToolExecutionResult,\n\tmeta: { readonly timestamp: number; readonly durationMs?: number },\n): Promise<TypedEntry<{ diagnostics: ToolDiagnostic[] }>> {\n\tconst { timestamp, durationMs } = meta;\n\tconst diagnostics = [...(result.diagnostics ?? [])];\n\tconst content: Content = [...(result.output ?? [])];\n\tif (diagnostics.length > 0) content.push({ type: \"text\", text: renderDiagnostics(diagnostics) });\n\tconst message = {\n\t\trole: \"toolResult\",\n\t\ttoolCallId: call.id,\n\t\ttoolName: call.name,\n\t\tcontent,\n\t\t...(result.details === undefined ? {} : { details: result.details }),\n\t\t...(result.usage === undefined ? {} : { usage: result.usage }),\n\t\tisError: result.isError ?? false,\n\t\t...(durationMs === undefined ? {} : { durationMs }),\n\t\ttimestamp,\n\t} as ToolResultMessage;\n\tif (result.usage !== undefined) await recordUsage(tx, conversationId, \"tools\", call.name, result.usage);\n\treturn tx.appendEntry(ToolResultEntry, conversationId, { model: [message], data: { diagnostics } });\n}\n\nfunction renderDiagnostics(diagnostics: readonly ToolDiagnostic[]): string {\n\treturn `<harness>\\n${diagnostics.map((diagnostic) => `[${diagnostic.severity}] ${diagnostic.message}`).join(\"\\n\")}\\n</harness>`;\n}\n\n/**\n * Bound the text of result content. When the joined text exceeds the limits, the text items are replaced by one bounded\n * item at the position of the first (head) or last (tail) text item; other content is kept.\n */\nfunction boundContent(\n\tcontent: Content,\n\tlimits: OutputLimits,\n): { content: Content; droppedBytes: number; droppedLines: number } {\n\tconst texts = content.filter((item): item is TextContent => item.type === \"text\");\n\tconst bounded = boundOutput(texts.map((item) => item.text).join(\"\"), limits);\n\tif (bounded.droppedBytes === 0) return { content, droppedBytes: 0, droppedLines: 0 };\n\tconst keep = limits.retain === \"head\" ? texts[0] : texts.at(-1);\n\tconst result: Content = [];\n\tfor (const item of content) {\n\t\tif (item.type !== \"text\") result.push(item);\n\t\telse if (item === keep) result.push({ ...item, text: bounded.text });\n\t}\n\treturn { content: result, droppedBytes: bounded.droppedBytes, droppedLines: bounded.droppedLines };\n}\n\n/**\n * Explicit nested call keys are path segments of the call ID, so IDs of different nested calls never collide, and are\n * never plain positive integers, which default keys use. `__proto__` stays reserved, as it was when keys indexed a JSON object.\n */\nfunction checkKey(key: string): void {\n\tif (key === \"\" || key.includes(\"/\") || key === \"__proto__\" || /^[1-9][0-9]*$/.test(key)) {\n\t\tthrow new Error(\n\t\t\t`Nested call key ${JSON.stringify(key)} must be non-empty, without \"/\", not \"__proto__\", and not a positive integer`,\n\t\t);\n\t}\n}\n\n/** Structural JSON equality; object key order does not matter. */\nfunction jsonEqual(a: JsonValue, b: JsonValue): boolean {\n\tif (a === b) return true;\n\tif (typeof a !== \"object\" || typeof b !== \"object\" || a === null || b === null) return false;\n\tif (Array.isArray(a) || Array.isArray(b)) {\n\t\treturn (\n\t\t\tArray.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((item, i) => jsonEqual(item, b[i]!))\n\t\t);\n\t}\n\tconst keys = Object.keys(a);\n\treturn (\n\t\tkeys.length === Object.keys(b).length && keys.every((key) => Object.hasOwn(b, key) && jsonEqual(a[key]!, b[key]!))\n\t);\n}\n"]}
@@ -0,0 +1,72 @@
1
+ import type { Context } from "@diffra-ai/chord/context";
2
+ import type { Cursor, EntryId, EntryQuery, EntryRecord, Page } from "../types.ts";
3
+ import type { ConversationView, ConversationWindow } from "./view.ts";
4
+ /** One row of a client's transcript. */
5
+ export type TranscriptItem = {
6
+ readonly kind: "entry";
7
+ readonly entry: EntryRecord;
8
+ }
9
+ /** Entries strictly between `after` and `upTo` are missing: render "load more" and call `fillGap()`. */
10
+ | {
11
+ readonly kind: "gap";
12
+ readonly after: EntryId;
13
+ readonly upTo: EntryId;
14
+ }
15
+ /** The transcript continues above: render "load earlier" and call `loadEarlier()`. Always the first item. */
16
+ | {
17
+ readonly kind: "earlier";
18
+ };
19
+ /** The conversation view as a renderer sees it: `items`, the client's whole transcript, instead of the window. */
20
+ export type TranscriptView = Omit<ConversationView, "entries" | "before"> & {
21
+ readonly items: readonly TranscriptItem[];
22
+ };
23
+ /** Pages a conversation's entries, as `Conversation.entries()` does without a cursor. */
24
+ export type EntryLoader = (query: Omit<EntryQuery, "conversationId">, limit: number, context: Context) => Promise<Page<EntryRecord, Cursor>>;
25
+ export type ConversationTranscriptOptions = {
26
+ /** Entries `loadEarlier()` and `fillGap()` load per call; default 50. */
27
+ readonly pageSize?: number;
28
+ };
29
+ type Gap = Extract<TranscriptItem, {
30
+ kind: "gap";
31
+ }>;
32
+ /**
33
+ * What a client has of one conversation: every entry it got from a view or fetched, and the gaps between (spec §9.3).
34
+ * A layer over any `ConversationView`, wherever it comes from: call `merge()` with every value of the view; it returns
35
+ * the view with the client's whole transcript as `items` instead of the window. Entries never change once committed,
36
+ * so the transcript only grows; a window that dropped its oldest entries keeps them here.
37
+ *
38
+ * A window whose `before` lies past the newest entry the client has does not continue it, after a stall, an overflow,
39
+ * or a reconnect: the entries in between become a gap. Nothing counts entries or computes ranges from entry IDs, which
40
+ * have holes; only exclusive bounds are turned into the inclusive bounds of `EntryQuery`. After a drop, a new watch
41
+ * with `resume` as its window continues the transcript.
42
+ *
43
+ * A merge costs O(items) and never re-sorts or re-fetches; a merge, `loadEarlier()`, or `fillGap()` that adds nothing
44
+ * returns the previous `items` array. Concurrent calls of `loadEarlier()`, or of `fillGap()` for the same gap, share one
45
+ * load, so a placeholder that stays visible does not fetch twice.
46
+ */
47
+ export declare class ConversationTranscript {
48
+ #private;
49
+ constructor(load: EntryLoader, options?: ConversationTranscriptOptions);
50
+ /**
51
+ * The ID the transcript reaches: its newest entry, or the `before` of a later window that was empty. Undefined before
52
+ * the first merge and for an empty transcript.
53
+ */
54
+ get newest(): EntryId | undefined;
55
+ /**
56
+ * The window that resumes this transcript after a drop: `{ from }` right after `newest`, so a new watch returns only
57
+ * what was missed when it fits its window, otherwise its newest entries and a gap; `{}` for an empty transcript;
58
+ * undefined before the first merge. `conversation.watch(context, transcript.resume)`.
59
+ */
60
+ get resume(): ConversationWindow | undefined;
61
+ /** Take one value of the view: its window's entries join the transcript. */
62
+ merge(view: ConversationView): TranscriptView;
63
+ /** Load the page before the oldest entry held. Without anything earlier, returns the current view. */
64
+ loadEarlier(context: Context): Promise<TranscriptView>;
65
+ /**
66
+ * Load the next page of `gap`, a gap item of `items`, shrinking it from its start, or removing it once nothing is
67
+ * missing. A gap that has shrunk since loads the gap it became; one that is no longer there returns the current view.
68
+ */
69
+ fillGap(gap: Gap, context: Context): Promise<TranscriptView>;
70
+ }
71
+ export {};
72
+ //# sourceMappingURL=transcript.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transcript.d.ts","sourceRoot":"","sources":["../../src/harness/transcript.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAExD,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAClF,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAEtE,wCAAwC;AACxC,MAAM,MAAM,cAAc,GACvB;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAA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CAAC,CAuBrD;IAED;;;OAGG;IACH,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,cAAc,CAAC,CAgC3D;CAkGD"}
@@ -0,0 +1,264 @@
1
+ import { idFromNumber } from "../ids.js";
2
+ const EARLIER = Object.freeze({ kind: "earlier" });
3
+ /**
4
+ * What a client has of one conversation: every entry it got from a view or fetched, and the gaps between (spec §9.3).
5
+ * A layer over any `ConversationView`, wherever it comes from: call `merge()` with every value of the view; it returns
6
+ * the view with the client's whole transcript as `items` instead of the window. Entries never change once committed,
7
+ * so the transcript only grows; a window that dropped its oldest entries keeps them here.
8
+ *
9
+ * A window whose `before` lies past the newest entry the client has does not continue it, after a stall, an overflow,
10
+ * or a reconnect: the entries in between become a gap. Nothing counts entries or computes ranges from entry IDs, which
11
+ * have holes; only exclusive bounds are turned into the inclusive bounds of `EntryQuery`. After a drop, a new watch
12
+ * with `resume` as its window continues the transcript.
13
+ *
14
+ * A merge costs O(items) and never re-sorts or re-fetches; a merge, `loadEarlier()`, or `fillGap()` that adds nothing
15
+ * returns the previous `items` array. Concurrent calls of `loadEarlier()`, or of `fillGap()` for the same gap, share one
16
+ * load, so a placeholder that stays visible does not fetch twice.
17
+ */
18
+ export class ConversationTranscript {
19
+ #load;
20
+ #pageSize;
21
+ /** Every entry held, in ID order, as items. */
22
+ #entries = [];
23
+ #ids = new Set();
24
+ /** Gaps in ID order; each is an immutable item, replaced when it shrinks. */
25
+ #gaps = [];
26
+ /** Whether anything was merged yet. */
27
+ #started = false;
28
+ /** Exclusive lower bound of the known range: entries at or below it are not loaded; `-Infinity` at the start. */
29
+ #low = Number.NEGATIVE_INFINITY;
30
+ /** Inclusive upper bound of the known range: the newest entry, or a later empty window's `before`. */
31
+ #tail = Number.NEGATIVE_INFINITY;
32
+ #items = [];
33
+ #last;
34
+ #view;
35
+ #earlier;
36
+ #filling = new Map();
37
+ constructor(load, options) {
38
+ const pageSize = options?.pageSize ?? 50;
39
+ if (!Number.isSafeInteger(pageSize) || pageSize < 1) {
40
+ throw new RangeError(`Page size must be an integer >= 1, got ${pageSize}`);
41
+ }
42
+ this.#load = load;
43
+ this.#pageSize = pageSize;
44
+ }
45
+ /**
46
+ * The ID the transcript reaches: its newest entry, or the `before` of a later window that was empty. Undefined before
47
+ * the first merge and for an empty transcript.
48
+ */
49
+ get newest() {
50
+ return this.#tail === Number.NEGATIVE_INFINITY ? undefined : idFromNumber(this.#tail);
51
+ }
52
+ /**
53
+ * The window that resumes this transcript after a drop: `{ from }` right after `newest`, so a new watch returns only
54
+ * what was missed when it fits its window, otherwise its newest entries and a gap; `{}` for an empty transcript;
55
+ * undefined before the first merge. `conversation.watch(context, transcript.resume)`.
56
+ */
57
+ get resume() {
58
+ if (!this.#started)
59
+ return undefined;
60
+ const newest = this.newest;
61
+ return newest === undefined ? {} : { from: idFromNumber(newest + 1) };
62
+ }
63
+ /** Take one value of the view: its window's entries join the transcript. */
64
+ merge(view) {
65
+ this.#last = view;
66
+ const { entries, before } = view;
67
+ const hi = entries.at(-1)?.id ?? before ?? Number.NEGATIVE_INFINITY;
68
+ this.#cover(before ?? Number.NEGATIVE_INFINITY, hi, entries);
69
+ return this.#result();
70
+ }
71
+ /** Load the page before the oldest entry held. Without anything earlier, returns the current view. */
72
+ loadEarlier(context) {
73
+ const last = this.#last;
74
+ if (last === undefined)
75
+ return Promise.reject(new Error("ConversationTranscript: merge a view first"));
76
+ if (this.#low === Number.NEGATIVE_INFINITY)
77
+ return Promise.resolve(this.#result());
78
+ if (this.#earlier !== undefined)
79
+ return this.#earlier;
80
+ const low = this.#low;
81
+ // The loader runs in a later microtask, so even its synchronous throw settles a promise that is already shared.
82
+ const loading = Promise.resolve().then(async () => {
83
+ const query = { maxEntryId: idFromNumber(low), order: "descending" };
84
+ const page = await this.#load(query, this.#pageSize, context);
85
+ const items = [...page.items].reverse();
86
+ const oldest = items[0];
87
+ // No next page, or an empty one: the transcript starts here.
88
+ if (page.next === undefined || oldest === undefined)
89
+ this.#cover(Number.NEGATIVE_INFINITY, low, items);
90
+ else
91
+ this.#cover(oldest.id - 1, low, items);
92
+ return this.#result();
93
+ });
94
+ this.#earlier = loading;
95
+ const settled = () => {
96
+ if (this.#earlier === loading)
97
+ this.#earlier = undefined;
98
+ };
99
+ loading.then(settled, settled);
100
+ return loading;
101
+ }
102
+ /**
103
+ * Load the next page of `gap`, a gap item of `items`, shrinking it from its start, or removing it once nothing is
104
+ * missing. A gap that has shrunk since loads the gap it became; one that is no longer there returns the current view.
105
+ */
106
+ fillGap(gap, context) {
107
+ const current = this.#gaps.find((each) => each.after === gap.after && each.upTo === gap.upTo) ??
108
+ this.#gaps.find((each) => each.after < gap.upTo && gap.after < each.upTo);
109
+ if (current === undefined) {
110
+ const last = this.#last;
111
+ if (last === undefined)
112
+ return Promise.reject(new Error("ConversationTranscript: merge a view first"));
113
+ return Promise.resolve(this.#result());
114
+ }
115
+ // Keyed by the gap the call resolved to, so a stale descriptor and the current one share the load.
116
+ const key = `${current.after}:${current.upTo}`;
117
+ const running = this.#filling.get(key);
118
+ if (running !== undefined)
119
+ return running;
120
+ const filling = Promise.resolve().then(async () => {
121
+ const query = {
122
+ minEntryId: idFromNumber(current.after + 1),
123
+ maxEntryId: idFromNumber(current.upTo - 1),
124
+ order: "ascending",
125
+ };
126
+ const page = await this.#load(query, this.#pageSize, context);
127
+ const newest = page.items.at(-1);
128
+ // No next page, or an empty one: nothing else is missing.
129
+ if (page.next === undefined || newest === undefined)
130
+ this.#cover(current.after, current.upTo - 1, page.items);
131
+ else
132
+ this.#cover(current.after, newest.id, page.items);
133
+ return this.#result();
134
+ });
135
+ this.#filling.set(key, filling);
136
+ const settled = () => {
137
+ if (this.#filling.get(key) === filling)
138
+ this.#filling.delete(key);
139
+ };
140
+ filling.then(settled, settled);
141
+ return filling;
142
+ }
143
+ /**
144
+ * Record that every entry with an ID in (`lo`, `hi`] is known, `added` being those entries in ID order: hold the new
145
+ * ones, shrink the gaps they fill, extend the known range, and open a gap where the range does not continue it.
146
+ */
147
+ #cover(lo, hi, added) {
148
+ const fresh = added.filter((entry) => !this.#ids.has(entry.id));
149
+ for (const entry of fresh)
150
+ this.#ids.add(entry.id);
151
+ const held = this.#entries;
152
+ // New entries past every held one: the items grow at their end.
153
+ const appended = fresh.length === 0 || held.length === 0 || fresh[0].id > held.at(-1).entry.id;
154
+ const items = fresh.map((entry) => ({ kind: "entry", entry }));
155
+ if (items.length > 0)
156
+ this.#entries = appended ? held.concat(items) : mergeById(held, items);
157
+ let rebuild = false;
158
+ if (!this.#started || (held.length === 0 && this.#gaps.length === 0 && lo >= this.#tail)) {
159
+ // The first range, or one after an empty transcript: it is all the client knows.
160
+ rebuild = !this.#started || lo !== this.#low;
161
+ this.#started = true;
162
+ this.#low = lo;
163
+ this.#tail = Math.max(this.#tail, hi);
164
+ }
165
+ else if (lo > this.#tail) {
166
+ // Past the newest known ID: what lies between is missing.
167
+ const upTo = added[0]?.id ?? lo + 1;
168
+ this.#gaps = [...this.#gaps, gapOf(this.#tail, upTo)];
169
+ this.#tail = hi;
170
+ rebuild = true;
171
+ }
172
+ else if (hi !== Number.NEGATIVE_INFINITY && hi < this.#low) {
173
+ // Below the oldest known ID: what lies between is missing.
174
+ const upTo = held.find((item) => item.entry.id > hi)?.entry.id ?? this.#low + 1;
175
+ this.#gaps = [gapOf(hi, upTo), ...this.#gaps];
176
+ this.#low = lo;
177
+ rebuild = true;
178
+ }
179
+ else {
180
+ const gaps = this.#subtract(lo, hi);
181
+ if (gaps !== this.#gaps) {
182
+ this.#gaps = gaps;
183
+ rebuild = true;
184
+ }
185
+ if (lo < this.#low) {
186
+ this.#low = lo;
187
+ rebuild = true;
188
+ }
189
+ if (hi > this.#tail)
190
+ this.#tail = hi;
191
+ }
192
+ if (rebuild || !appended)
193
+ this.#items = this.#build();
194
+ else if (items.length > 0)
195
+ this.#items = this.#items.concat(items);
196
+ }
197
+ /** The gaps without (`lo`, `hi`]; the same array when none changes, as when the range is empty. */
198
+ #subtract(lo, hi) {
199
+ if (hi <= lo)
200
+ return this.#gaps;
201
+ let changed = false;
202
+ const gaps = [];
203
+ for (const gap of this.#gaps) {
204
+ // Missing: IDs in (after, upTo); known now: IDs in (lo, hi].
205
+ if (hi <= gap.after || lo + 1 >= gap.upTo) {
206
+ gaps.push(gap);
207
+ continue;
208
+ }
209
+ changed = true;
210
+ if (lo > gap.after) {
211
+ const firstKnown = this.#entries.find((item) => item.entry.id > lo)?.entry.id ?? lo + 1;
212
+ gaps.push(gapOf(gap.after, Math.min(gap.upTo, firstKnown)));
213
+ }
214
+ if (hi + 1 < gap.upTo)
215
+ gaps.push(gapOf(hi, gap.upTo));
216
+ }
217
+ return changed ? gaps : this.#gaps;
218
+ }
219
+ /** Items in ID order: "earlier" until the start is known, then entries with each gap before the entry after it. */
220
+ #build() {
221
+ const items = this.#low === Number.NEGATIVE_INFINITY ? [] : [EARLIER];
222
+ const gaps = this.#gaps;
223
+ let next = 0;
224
+ for (const item of this.#entries) {
225
+ while (next < gaps.length && gaps[next].after < item.entry.id)
226
+ items.push(gaps[next++]);
227
+ items.push(item);
228
+ }
229
+ while (next < gaps.length)
230
+ items.push(gaps[next++]);
231
+ return items;
232
+ }
233
+ /** The view with the current items; the previous one when nothing changed. */
234
+ #result() {
235
+ const last = this.#last;
236
+ const previous = this.#view;
237
+ if (previous !== undefined &&
238
+ previous.items === this.#items &&
239
+ previous.docs === last.docs &&
240
+ previous.conversation === last.conversation) {
241
+ return previous;
242
+ }
243
+ this.#view = { conversation: last.conversation, docs: last.docs, items: this.#items };
244
+ return this.#view;
245
+ }
246
+ }
247
+ function gapOf(after, upTo) {
248
+ return Object.freeze({ kind: "gap", after: idFromNumber(after), upTo: idFromNumber(upTo) });
249
+ }
250
+ /** Two ID-ordered item lists merged in one pass. */
251
+ function mergeById(left, right) {
252
+ const merged = [];
253
+ let i = 0;
254
+ let j = 0;
255
+ while (i < left.length && j < right.length) {
256
+ merged.push(left[i].entry.id < right[j].entry.id ? left[i++] : right[j++]);
257
+ }
258
+ while (i < left.length)
259
+ merged.push(left[i++]);
260
+ while (j < right.length)
261
+ merged.push(right[j++]);
262
+ return merged;
263
+ }
264
+ //# sourceMappingURL=transcript.js.map