@ny4n/durable 0.0.0-stage → 1.0.1

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 (303) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +711 -2
  3. package/dist/documents.d.ts +66 -0
  4. package/dist/documents.d.ts.map +1 -0
  5. package/dist/documents.js +98 -0
  6. package/dist/documents.js.map +1 -0
  7. package/dist/entries.d.ts +31 -0
  8. package/dist/entries.d.ts.map +1 -0
  9. package/dist/entries.js +31 -0
  10. package/dist/entries.js.map +1 -0
  11. package/dist/env/decode.d.ts +16 -0
  12. package/dist/env/decode.d.ts.map +1 -0
  13. package/dist/env/decode.js +28 -0
  14. package/dist/env/decode.js.map +1 -0
  15. package/dist/env/index.d.ts +263 -0
  16. package/dist/env/index.d.ts.map +1 -0
  17. package/dist/env/index.js +49 -0
  18. package/dist/env/index.js.map +1 -0
  19. package/dist/env/line-scan.d.ts +13 -0
  20. package/dist/env/line-scan.d.ts.map +1 -0
  21. package/dist/env/line-scan.js +147 -0
  22. package/dist/env/line-scan.js.map +1 -0
  23. package/dist/env/node-watch.d.ts +29 -0
  24. package/dist/env/node-watch.d.ts.map +1 -0
  25. package/dist/env/node-watch.js +485 -0
  26. package/dist/env/node-watch.js.map +1 -0
  27. package/dist/env/node.d.ts +56 -0
  28. package/dist/env/node.d.ts.map +1 -0
  29. package/dist/env/node.js +1166 -0
  30. package/dist/env/node.js.map +1 -0
  31. package/dist/errors.d.ts +32 -0
  32. package/dist/errors.d.ts.map +1 -0
  33. package/dist/errors.js +53 -0
  34. package/dist/errors.js.map +1 -0
  35. package/dist/harness/agent.d.ts +33 -0
  36. package/dist/harness/agent.d.ts.map +1 -0
  37. package/dist/harness/agent.js +235 -0
  38. package/dist/harness/agent.js.map +1 -0
  39. package/dist/harness/assistant.d.ts +15 -0
  40. package/dist/harness/assistant.d.ts.map +1 -0
  41. package/dist/harness/assistant.js +23 -0
  42. package/dist/harness/assistant.js.map +1 -0
  43. package/dist/harness/compaction.d.ts +56 -0
  44. package/dist/harness/compaction.d.ts.map +1 -0
  45. package/dist/harness/compaction.js +384 -0
  46. package/dist/harness/compaction.js.map +1 -0
  47. package/dist/harness/context.d.ts +63 -0
  48. package/dist/harness/context.d.ts.map +1 -0
  49. package/dist/harness/context.js +221 -0
  50. package/dist/harness/context.js.map +1 -0
  51. package/dist/harness/define.d.ts +18 -0
  52. package/dist/harness/define.d.ts.map +1 -0
  53. package/dist/harness/define.js +25 -0
  54. package/dist/harness/define.js.map +1 -0
  55. package/dist/harness/events.d.ts +180 -0
  56. package/dist/harness/events.d.ts.map +1 -0
  57. package/dist/harness/events.js +370 -0
  58. package/dist/harness/events.js.map +1 -0
  59. package/dist/harness/generation.d.ts +54 -0
  60. package/dist/harness/generation.d.ts.map +1 -0
  61. package/dist/harness/generation.js +514 -0
  62. package/dist/harness/generation.js.map +1 -0
  63. package/dist/harness/harness.d.ts +17 -0
  64. package/dist/harness/harness.d.ts.map +1 -0
  65. package/dist/harness/harness.js +332 -0
  66. package/dist/harness/harness.js.map +1 -0
  67. package/dist/harness/inbox.d.ts +59 -0
  68. package/dist/harness/inbox.d.ts.map +1 -0
  69. package/dist/harness/inbox.js +97 -0
  70. package/dist/harness/inbox.js.map +1 -0
  71. package/dist/harness/json.d.ts +10 -0
  72. package/dist/harness/json.d.ts.map +1 -0
  73. package/dist/harness/json.js +33 -0
  74. package/dist/harness/json.js.map +1 -0
  75. package/dist/harness/live.d.ts +142 -0
  76. package/dist/harness/live.d.ts.map +1 -0
  77. package/dist/harness/live.js +149 -0
  78. package/dist/harness/live.js.map +1 -0
  79. package/dist/harness/output.d.ts +69 -0
  80. package/dist/harness/output.d.ts.map +1 -0
  81. package/dist/harness/output.js +318 -0
  82. package/dist/harness/output.js.map +1 -0
  83. package/dist/harness/prompt.d.ts +27 -0
  84. package/dist/harness/prompt.d.ts.map +1 -0
  85. package/dist/harness/prompt.js +131 -0
  86. package/dist/harness/prompt.js.map +1 -0
  87. package/dist/harness/provider.d.ts +14 -0
  88. package/dist/harness/provider.d.ts.map +1 -0
  89. package/dist/harness/provider.js +30 -0
  90. package/dist/harness/provider.js.map +1 -0
  91. package/dist/harness/registry.d.ts +6 -0
  92. package/dist/harness/registry.d.ts.map +1 -0
  93. package/dist/harness/registry.js +101 -0
  94. package/dist/harness/registry.js.map +1 -0
  95. package/dist/harness/run.d.ts +17 -0
  96. package/dist/harness/run.d.ts.map +1 -0
  97. package/dist/harness/run.js +26 -0
  98. package/dist/harness/run.js.map +1 -0
  99. package/dist/harness/scheduler.d.ts +106 -0
  100. package/dist/harness/scheduler.d.ts.map +1 -0
  101. package/dist/harness/scheduler.js +1743 -0
  102. package/dist/harness/scheduler.js.map +1 -0
  103. package/dist/harness/submissions.d.ts +29 -0
  104. package/dist/harness/submissions.d.ts.map +1 -0
  105. package/dist/harness/submissions.js +175 -0
  106. package/dist/harness/submissions.js.map +1 -0
  107. package/dist/harness/task-graph.d.ts +49 -0
  108. package/dist/harness/task-graph.d.ts.map +1 -0
  109. package/dist/harness/task-graph.js +168 -0
  110. package/dist/harness/task-graph.js.map +1 -0
  111. package/dist/harness/tool.d.ts +76 -0
  112. package/dist/harness/tool.d.ts.map +1 -0
  113. package/dist/harness/tool.js +736 -0
  114. package/dist/harness/tool.js.map +1 -0
  115. package/dist/harness/types.d.ts +713 -0
  116. package/dist/harness/types.d.ts.map +1 -0
  117. package/dist/harness/types.js +2 -0
  118. package/dist/harness/types.js.map +1 -0
  119. package/dist/harness/usage.d.ts +18 -0
  120. package/dist/harness/usage.d.ts.map +1 -0
  121. package/dist/harness/usage.js +57 -0
  122. package/dist/harness/usage.js.map +1 -0
  123. package/dist/harness/util.d.ts +19 -0
  124. package/dist/harness/util.d.ts.map +1 -0
  125. package/dist/harness/util.js +58 -0
  126. package/dist/harness/util.js.map +1 -0
  127. package/dist/harness/view.d.ts +47 -0
  128. package/dist/harness/view.d.ts.map +1 -0
  129. package/dist/harness/view.js +206 -0
  130. package/dist/harness/view.js.map +1 -0
  131. package/dist/ids.d.ts +6 -0
  132. package/dist/ids.d.ts.map +1 -0
  133. package/dist/ids.js +9 -0
  134. package/dist/ids.js.map +1 -0
  135. package/dist/images/cloudflare.d.ts +4 -0
  136. package/dist/images/cloudflare.d.ts.map +1 -0
  137. package/dist/images/cloudflare.js +9 -0
  138. package/dist/images/cloudflare.js.map +1 -0
  139. package/dist/images/exif.d.ts +3 -0
  140. package/dist/images/exif.d.ts.map +1 -0
  141. package/dist/images/exif.js +71 -0
  142. package/dist/images/exif.js.map +1 -0
  143. package/dist/images/index.d.ts +18 -0
  144. package/dist/images/index.d.ts.map +1 -0
  145. package/dist/images/index.js +125 -0
  146. package/dist/images/index.js.map +1 -0
  147. package/dist/images/node-worker.d.ts +17 -0
  148. package/dist/images/node-worker.d.ts.map +1 -0
  149. package/dist/images/node-worker.js +16 -0
  150. package/dist/images/node-worker.js.map +1 -0
  151. package/dist/images/node.d.ts +21 -0
  152. package/dist/images/node.d.ts.map +1 -0
  153. package/dist/images/node.js +121 -0
  154. package/dist/images/node.js.map +1 -0
  155. package/dist/index.d.ts +24 -0
  156. package/dist/index.d.ts.map +1 -0
  157. package/dist/index.js +20 -0
  158. package/dist/index.js.map +1 -0
  159. package/dist/session/forks.d.ts +10 -0
  160. package/dist/session/forks.d.ts.map +1 -0
  161. package/dist/session/forks.js +42 -0
  162. package/dist/session/forks.js.map +1 -0
  163. package/dist/session/observation.d.ts +42 -0
  164. package/dist/session/observation.d.ts.map +1 -0
  165. package/dist/session/observation.js +281 -0
  166. package/dist/session/observation.js.map +1 -0
  167. package/dist/session/session.d.ts +133 -0
  168. package/dist/session/session.d.ts.map +1 -0
  169. package/dist/session/session.js +811 -0
  170. package/dist/session/session.js.map +1 -0
  171. package/dist/session/transaction.d.ts +119 -0
  172. package/dist/session/transaction.d.ts.map +1 -0
  173. package/dist/session/transaction.js +795 -0
  174. package/dist/session/transaction.js.map +1 -0
  175. package/dist/storage/jsonl/index.d.ts +2 -0
  176. package/dist/storage/jsonl/index.d.ts.map +1 -0
  177. package/dist/storage/jsonl/index.js +2 -0
  178. package/dist/storage/jsonl/index.js.map +1 -0
  179. package/dist/storage/jsonl/node.d.ts +6 -0
  180. package/dist/storage/jsonl/node.d.ts.map +1 -0
  181. package/dist/storage/jsonl/node.js +8 -0
  182. package/dist/storage/jsonl/node.js.map +1 -0
  183. package/dist/storage/jsonl/storage.d.ts +143 -0
  184. package/dist/storage/jsonl/storage.d.ts.map +1 -0
  185. package/dist/storage/jsonl/storage.js +682 -0
  186. package/dist/storage/jsonl/storage.js.map +1 -0
  187. package/dist/storage/memory.d.ts +62 -0
  188. package/dist/storage/memory.d.ts.map +1 -0
  189. package/dist/storage/memory.js +733 -0
  190. package/dist/storage/memory.js.map +1 -0
  191. package/dist/storage/scan.d.ts +18 -0
  192. package/dist/storage/scan.d.ts.map +1 -0
  193. package/dist/storage/scan.js +29 -0
  194. package/dist/storage/scan.js.map +1 -0
  195. package/dist/storage/sqlite/cloudflare.d.ts +46 -0
  196. package/dist/storage/sqlite/cloudflare.d.ts.map +1 -0
  197. package/dist/storage/sqlite/cloudflare.js +106 -0
  198. package/dist/storage/sqlite/cloudflare.js.map +1 -0
  199. package/dist/storage/sqlite/database.d.ts +37 -0
  200. package/dist/storage/sqlite/database.d.ts.map +1 -0
  201. package/dist/storage/sqlite/database.js +2 -0
  202. package/dist/storage/sqlite/database.js.map +1 -0
  203. package/dist/storage/sqlite/index.d.ts +4 -0
  204. package/dist/storage/sqlite/index.d.ts.map +1 -0
  205. package/dist/storage/sqlite/index.js +3 -0
  206. package/dist/storage/sqlite/index.js.map +1 -0
  207. package/dist/storage/sqlite/migrations.d.ts +11 -0
  208. package/dist/storage/sqlite/migrations.d.ts.map +1 -0
  209. package/dist/storage/sqlite/migrations.js +111 -0
  210. package/dist/storage/sqlite/migrations.js.map +1 -0
  211. package/dist/storage/sqlite/node.d.ts +41 -0
  212. package/dist/storage/sqlite/node.d.ts.map +1 -0
  213. package/dist/storage/sqlite/node.js +179 -0
  214. package/dist/storage/sqlite/node.js.map +1 -0
  215. package/dist/storage/sqlite/storage.d.ts +65 -0
  216. package/dist/storage/sqlite/storage.d.ts.map +1 -0
  217. package/dist/storage/sqlite/storage.js +670 -0
  218. package/dist/storage/sqlite/storage.js.map +1 -0
  219. package/dist/tasks.d.ts +6 -0
  220. package/dist/tasks.d.ts.map +1 -0
  221. package/dist/tasks.js +5 -0
  222. package/dist/tasks.js.map +1 -0
  223. package/dist/testing/assertions.d.ts +5 -0
  224. package/dist/testing/assertions.d.ts.map +1 -0
  225. package/dist/testing/assertions.js +25 -0
  226. package/dist/testing/assertions.js.map +1 -0
  227. package/dist/testing/env-conformance.d.ts +7 -0
  228. package/dist/testing/env-conformance.d.ts.map +1 -0
  229. package/dist/testing/env-conformance.js +431 -0
  230. package/dist/testing/env-conformance.js.map +1 -0
  231. package/dist/testing/index.d.ts +7 -0
  232. package/dist/testing/index.d.ts.map +1 -0
  233. package/dist/testing/index.js +6 -0
  234. package/dist/testing/index.js.map +1 -0
  235. package/dist/testing/runner.d.ts +12 -0
  236. package/dist/testing/runner.d.ts.map +1 -0
  237. package/dist/testing/runner.js +23 -0
  238. package/dist/testing/runner.js.map +1 -0
  239. package/dist/testing/storage-benchmark.d.ts +41 -0
  240. package/dist/testing/storage-benchmark.d.ts.map +1 -0
  241. package/dist/testing/storage-benchmark.js +350 -0
  242. package/dist/testing/storage-benchmark.js.map +1 -0
  243. package/dist/testing/storage-conformance.d.ts +4 -0
  244. package/dist/testing/storage-conformance.d.ts.map +1 -0
  245. package/dist/testing/storage-conformance.js +1213 -0
  246. package/dist/testing/storage-conformance.js.map +1 -0
  247. package/dist/testing/types.d.ts +37 -0
  248. package/dist/testing/types.d.ts.map +1 -0
  249. package/dist/testing/types.js +2 -0
  250. package/dist/testing/types.js.map +1 -0
  251. package/dist/tools/bash.d.ts +55 -0
  252. package/dist/tools/bash.d.ts.map +1 -0
  253. package/dist/tools/bash.js +138 -0
  254. package/dist/tools/bash.js.map +1 -0
  255. package/dist/tools/edit-diff.d.ts +89 -0
  256. package/dist/tools/edit-diff.d.ts.map +1 -0
  257. package/dist/tools/edit-diff.js +386 -0
  258. package/dist/tools/edit-diff.js.map +1 -0
  259. package/dist/tools/edit.d.ts +18 -0
  260. package/dist/tools/edit.d.ts.map +1 -0
  261. package/dist/tools/edit.js +117 -0
  262. package/dist/tools/edit.js.map +1 -0
  263. package/dist/tools/env.d.ts +5 -0
  264. package/dist/tools/env.d.ts.map +1 -0
  265. package/dist/tools/env.js +7 -0
  266. package/dist/tools/env.js.map +1 -0
  267. package/dist/tools/file-mutation-queue.d.ts +9 -0
  268. package/dist/tools/file-mutation-queue.d.ts.map +1 -0
  269. package/dist/tools/file-mutation-queue.js +52 -0
  270. package/dist/tools/file-mutation-queue.js.map +1 -0
  271. package/dist/tools/image-processor.d.ts +47 -0
  272. package/dist/tools/image-processor.d.ts.map +1 -0
  273. package/dist/tools/image-processor.js +30 -0
  274. package/dist/tools/image-processor.js.map +1 -0
  275. package/dist/tools/image.d.ts +20 -0
  276. package/dist/tools/image.d.ts.map +1 -0
  277. package/dist/tools/image.js +178 -0
  278. package/dist/tools/image.js.map +1 -0
  279. package/dist/tools/index.d.ts +46 -0
  280. package/dist/tools/index.d.ts.map +1 -0
  281. package/dist/tools/index.js +23 -0
  282. package/dist/tools/index.js.map +1 -0
  283. package/dist/tools/path-utils.d.ts +5 -0
  284. package/dist/tools/path-utils.d.ts.map +1 -0
  285. package/dist/tools/path-utils.js +26 -0
  286. package/dist/tools/path-utils.js.map +1 -0
  287. package/dist/tools/read.d.ts +25 -0
  288. package/dist/tools/read.d.ts.map +1 -0
  289. package/dist/tools/read.js +235 -0
  290. package/dist/tools/read.js.map +1 -0
  291. package/dist/tools/write.d.ts +10 -0
  292. package/dist/tools/write.d.ts.map +1 -0
  293. package/dist/tools/write.js +31 -0
  294. package/dist/tools/write.js.map +1 -0
  295. package/dist/truncate.d.ts +64 -0
  296. package/dist/truncate.d.ts.map +1 -0
  297. package/dist/truncate.js +154 -0
  298. package/dist/truncate.js.map +1 -0
  299. package/dist/types.d.ts +932 -0
  300. package/dist/types.d.ts.map +1 -0
  301. package/dist/types.js +3 -0
  302. package/dist/types.js.map +1 -0
  303. package/package.json +140 -5
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/harness/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,gBAAgB,EAChB,cAAc,EACd,OAAO,EACP,YAAY,EACZ,kBAAkB,EAClB,MAAM,EACN,IAAI,EACJ,QAAQ,EACR,iBAAiB,EACjB,SAAS,EACT,OAAO,EACP,KAAK,EACL,WAAW,EACX,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,uBAAuB,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACxF,OAAO,KAAK,EACX,cAAc,EACd,qBAAqB,EACrB,kBAAkB,EAClB,MAAM,EACN,gBAAgB,EAChB,cAAc,EACd,UAAU,EACV,OAAO,EACP,UAAU,EACV,WAAW,EACX,UAAU,EACV,IAAI,EACJ,OAAO,EACP,YAAY,EACZ,gBAAgB,EAChB,IAAI,EACJ,MAAM,EACN,WAAW,EACX,UAAU,EACV,SAAS,EACT,EAAE,EACF,WAAW,EACX,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAElD,0FAA0F;AAC1F,MAAM,MAAM,QAAQ,GAAG;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE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I,EAAE,YAAY,EAClB,MAAM,EAAE,mBAAmB,EAC3B,GAAG,EAAE,OAAO,EACZ,OAAO,EAAE,OAAO,GACd,UAAU,CAAC,mBAAmB,CAAC,CAAC;CACnC;AAED,6CAA6C;AAC7C,MAAM,WAAW,eAAe;IAC/B;;;;OAIG;IACH,aAAa,CACZ,UAAU,EAAE;QACX,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC;QAClC,QAAQ,CAAC,OAAO,EAAE,SAAS,WAAW,EAAE,CAAC;QACzC,QAAQ,CAAC,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAC;QACtC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;QAC5B,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;KAC/B,EACD,GAAG,EAAE,OAAO,EACZ,OAAO,EAAE,OAAO,GACd,UAAU,CAAC;QAAE,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAA;KAAE,GAAG;QAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACzE"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/harness/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n\tAssistantMessage,\n\tCacheRetention,\n\tMessage,\n\tModelRuntime,\n\tModelThinkingLevel,\n\tStatic,\n\tTool,\n\tToolCall,\n\tToolResultMessage,\n\tTransport,\n\tTSchema,\n\tUsage,\n\tUserMessage,\n} from \"@ny4n/ai/contracts\";\nimport type { AttachedReplicatedState, Context, JsonValue } from \"@ny4n/chord\";\nimport type { ExecutionEnv, ShellOutputSkip, ShellOutputWindow } from \"../env/index.ts\";\nimport type {\n\tConversationId,\n\tConversationOwnership,\n\tConversationRecord,\n\tCursor,\n\tDocumentObserver,\n\tDocumentReader,\n\tEntryDraft,\n\tEntryId,\n\tEntryQuery,\n\tEntryRecord,\n\tJsonObject,\n\tPage,\n\tSession,\n\tSubmissionId,\n\tSubmissionRecord,\n\tTask,\n\tTaskId,\n\tTaskOptions,\n\tTaskRecord,\n\tTaskState,\n\tTx,\n\tWatchHandle,\n} from \"../types.ts\";\nimport type { TaskGraph, TaskGraphWatch } from \"./task-graph.ts\";\nimport type { UsageState } from \"./usage.ts\";\nimport type { ConversationView } from \"./view.ts\";\n\n/** Provider and model ID resolved through the provider-neutral model runtime contract. */\nexport type ModelRef = {\n\treadonly provider: string;\n\treadonly modelId: string;\n};\n\nexport type UserInput = UserMessage[\"content\"];\n\n/** Host submission: user input that may start a run, or a passive entry write. */\nexport type SubmissionDraft = {\n\treadonly requestId?: string;\n} & (\n\t| {\n\t\t\treadonly type: \"input\";\n\t\t\treadonly content: UserInput;\n\t\t\treadonly whenBusy?: \"steer\" | \"followUp\" | \"reject\";\n\t\t\treadonly entry?: never;\n\t }\n\t| {\n\t\t\treadonly type: \"write\";\n\t\t\treadonly entry: EntryDraft;\n\t\t\treadonly content?: never;\n\t\t\treadonly whenBusy?: never;\n\t }\n);\n\nexport type InputSubmissionDraft = Extract<SubmissionDraft, { readonly type: \"input\" }>;\n\nexport type SettledSubmissionRecord = SubmissionRecord & {\n\treadonly status: \"done\" | \"unanswered\";\n};\n\n/** Awaitable host object for one durably admitted submission. */\nexport interface Submission {\n\treadonly id: SubmissionId;\n\tstatus(context: Context): Promise<SubmissionRecord>;\n\twait(context: Context): Promise<SettledSubmissionRecord>;\n\tabort(context: Context): Promise<\"aborted\" | \"already_placed\" | \"settled\">;\n}\n\nexport type SettledTask<R> = TaskRecord<JsonValue, JsonValue, R> & {\n\treadonly state: Extract<TaskState<JsonValue, R>, { readonly status: \"terminal\" }>;\n};\n\n/** Erased executable task definition stored in the registry. */\nexport type AnyTask = {\n\treadonly definition: {\n\t\treadonly name: string;\n\t\treadonly version: number;\n\t\treadonly initial: unknown;\n\t\treadonly phases: Readonly<Record<string, unknown>>;\n\t\treadonly abort: unknown;\n\t\treadonly migrate?: unknown;\n\t\treadonly hooks?: object;\n\t};\n};\n\n/** Options of `Conversation.abort()`. */\nexport type ConversationAbortOptions = {\n\t/**\n\t * Cross background boundaries: mark every live task reached ignoring the background flag when the abort is admitted,\n\t * withdraw the queued inputs of every conversation reached, and wait until those tasks are terminal and the\n\t * conversation is ordinarily idle. Background work created afterwards is neither marked nor awaited.\n\t */\n\treadonly background?: boolean;\n};\n\n/** Hook handler map declared by a task definition. */\nexport type HooksOf<K> = K extends Task<infer _I, infer _S, infer _R, infer H> ? H : never;\n\n/**\n * Invocation-bound conversation operations for tasks and tools. Rejects after the invocation ends; passive entries are\n * written with ordinary transaction writes instead.\n */\nexport interface ConversationHandle {\n\treadonly id: ConversationId;\n\tsubmit(submission: InputSubmissionDraft, context: Context): Promise<Submission>;\n\t/** `Conversation.abort()`: withdraw queued inputs, abort the ordinary ownership scope, and wait until it is idle. */\n\tabort(context: Context, options?: ConversationAbortOptions): Promise<void>;\n\t/** Resolve when the conversation's ordinary ownership scope has no live non-background task. */\n\twaitForIdle(context: Context): Promise<void>;\n}\n\n/** Post-tools controls requested by a tool result. */\nexport type ToolControl = {\n\treadonly addTools?: readonly string[];\n\treadonly terminate?: true;\n\treadonly handoff?: string;\n};\n\n/** Remark about a call for the model and the UI, such as truncation or a spill path; never part of the tool's data. */\nexport type ToolDiagnostic = {\n\treadonly severity: \"info\" | \"warn\" | \"error\";\n\treadonly message: string;\n\treadonly code?: string;\n};\n\n/**\n * What a tool returns, on three channels: `output` for the model, `structuredOutput` for programs that call the tool\n * (`executeTool()` callers, code mode scripts), and `details` for UIs.\n */\nexport type ToolExecutionResult<TDetails extends JsonValue = JsonValue> = {\n\t/** For the model. Omitted: the retained `output()` text. */\n\treadonly output?: ToolResultMessage[\"content\"];\n\t/**\n\t * For programs. Required unless `isError` when the tool declares `structuredOutputSchema`, and validated against it;\n\t * not allowed without one, where programs get the output itself (`NestedToolExecutionResult.structuredOutput`).\n\t */\n\treadonly structuredOutput?: JsonValue;\n\treadonly isError?: boolean;\n\t/** Omitted: the last `details()` value becomes the details. */\n\treadonly details?: TDetails;\n\t/** Added after those recorded through `api.diagnostic()`. */\n\treadonly diagnostics?: readonly ToolDiagnostic[];\n\t/** Spend of the execution itself, such as a model call; stored on the result and in `nyan.usage.tools`. */\n\treadonly usage?: Usage;\n\treadonly control?: ToolControl;\n};\n\n/**\n * Result of a nested call, as `executeTool()` returns it. Programs read `structuredOutput`; the output for the model\n * is not kept, and `control` does not apply.\n */\nexport type NestedToolExecutionResult = {\n\t/** The nested call's tool task. */\n\treadonly taskId: TaskId;\n\t/**\n\t * The value for programs. A tool with `structuredOutputSchema`: its validated `structuredOutput`, absent on an error\n\t * result that has none. A tool without: its bounded output, success or error, as a string for one text item, an\n\t * `ImageContent` for one image, `\"\"` for none, and the content list otherwise. Absent on an error result the Harness\n\t * wrote itself (unavailable, invalid, blocked, interrupted, aborted); `diagnostics` say what went wrong.\n\t */\n\treadonly structuredOutput?: JsonValue;\n\treadonly isError: boolean;\n\treadonly details?: JsonValue;\n\treadonly diagnostics: readonly ToolDiagnostic[];\n\treadonly usage?: Usage;\n\t/** Execution time of the attempt that produced the result; absent when it never executed. */\n\treadonly durationMs?: number;\n};\n\n/** Whether the tools of one round run at once or one after another in call order. */\nexport type ToolExecutionMode = \"parallel\" | \"sequential\";\n\n/** How many queued items of one mode a boundary places: the first, or all of them. */\nexport type QueueMode = \"all\" | \"one-at-a-time\";\n\n/**\n * Operations available to one tool invocation. A plain object, so a wrapper can spread it. Every operation rejects after\n * the invocation ends.\n */\nexport interface ToolExecutionApi<TDetails extends JsonValue = JsonValue> extends DocumentObserver, DocumentReader {\n\treadonly taskId: TaskId;\n\treadonly conversationId: ConversationId;\n\treadonly callId: string;\n\t/** The tool task's phase snapshot. */\n\treadonly registry: RegistrySnapshot;\n\t/** The calling conversation's agent, as the tool task's phase resolved it. */\n\tagent(context: Context): Promise<Agent>;\n\t/** `HarnessOptions.models`: the catalog, credentials, and request transforms generation uses. */\n\treadonly models: ModelRuntime;\n\t/** Built by `HarnessOptions.env` for this call; `undefined` without an environment. */\n\treadonly env: ExecutionEnv | undefined;\n\t/**\n\t * Append running output; it becomes the result's `output` when the result omits it. `skipped` counts output\n\t * omitted before the chunk, as reported by an environment given `outputWindow` (`ShellOutputInfo.skipped`).\n\t */\n\toutput(chunk: string | Uint8Array, skipped?: ShellOutputSkip): void;\n\t/**\n\t * The tail this call's output keeps and the pace of its progress commits, for `ShellExecOptions.window`; `undefined`\n\t * when the tool keeps the head of its output, which cannot accept skips. A wrapper that replaces `output` and\n\t * transforms text must also replace this with `undefined`, so skipped text cannot bypass its transform.\n\t */\n\treadonly outputWindow: ShellOutputWindow | undefined;\n\t/**\n\t * The output retained so far, as the model will see it when the result omits `output`, and whether earlier output was\n\t * dropped; for a tool that also returns that text in its `structuredOutput`.\n\t */\n\tretainedOutput(): { readonly text: string; readonly truncated: boolean };\n\t/** Record a model-visible remark about this call. */\n\tdiagnostic(diagnostic: ToolDiagnostic): void;\n\t/** Replace running details; the last value becomes the result details when the result omits `details`. */\n\tdetails(value: TDetails, context: Context): Promise<void>;\n\tcommit<T>(change: (tx: Tx) => T | Promise<T>, context: Context): Promise<T>;\n\tmemo<T extends JsonValue>(name: string, context: Context): Promise<T | undefined>;\n\tmemo<T extends JsonValue>(name: string, candidate: T, context: Context): Promise<T>;\n\t/**\n\t * Create a task in one commit. A child task of a tool that is not replay-safe defaults to `abandonOnRestart`: the\n\t * tool never resumes after a restart, so nothing awaits the child then.\n\t */\n\tcreateTask<I, S extends { phase: string }, R, H extends object>(\n\t\ttask: Task<I, S, R, H>,\n\t\tinput: I,\n\t\toptions: Omit<TaskOptions, \"conversationId\">,\n\t\tcontext: Context,\n\t): Promise<TaskId<R>>;\n\tgetTask<R>(id: TaskId<R>, context: Context): Promise<TaskRecord<JsonValue, JsonValue, R> | undefined>;\n\twaitForTask<R>(id: TaskId<R>, context: Context): Promise<SettledTask<R>>;\n\t/** Invocation-bound handle of an existing conversation, such as one this tool created in `commit()`. */\n\tconversation(id: ConversationId, context: Context): Promise<ConversationHandle | undefined>;\n\t/**\n\t * Run tool `name` as a nested call of this one and wait for its result. The nested call is its own `nyan.tool` task,\n\t * owned by this call: it resolves the tool among the conversation's tools, validates, runs the `ToolTask` hooks (which\n\t * see `call.parent`), applies output limits and the tool's replay policy, and reports progress in `nyan.live.nestedTools`.\n\t * Its result returns here instead of entering the transcript. A call that is blocked, invalid, throws, is interrupted,\n\t * or is aborted returns an `isError` result.\n\t *\n\t * The nested call's key names it within this call; its call ID is `<callId>/<key>`. By default the key is the call's\n\t * position among this invocation's nested calls, `1`, `2`, ... An explicit `key` must be non-empty, without `/`, not\n\t * `__proto__`, and not a positive integer, so it never collides with a default one. A rerun of a replay-safe tool\n\t * that makes a call with a used key, by calling in the same order or by passing the same `key`, gets that nested call\n\t * back, finished or still running, instead of starting another. A nested call a crash interrupted before its result\n\t * committed follows its own replay policy, so this is not exactly-once execution. Reusing a key with another tool or\n\t * other arguments throws. A tool that is not replay-safe never reruns: after a restart, its unfinished nested calls\n\t * are abandoned (`TaskOptions.abandonOnRestart`) before they run again.\n\t *\n\t * `progress: false` commits no running output, details, or diagnostics to the nested call's slot, only its status;\n\t * the result still carries its details and diagnostics, and a schema-less tool's output as `structuredOutput`. An\n\t * interrupted or aborted call's result is built from its slot, so it then has none of them. Either way, programs never\n\t * get the partial output of an interrupted or aborted call.\n\t *\n\t * Nested calls run as soon as they are made, whatever their `executionMode`; the caller decides what runs at once by\n\t * what it awaits. Cancelling `context` stops only the wait; the nested call runs on. When this call settles, nested\n\t * calls it left running are aborted first. A nested result's `usage` is already counted under its tool; a result\n\t * that passes it on counts it again. Rejects, instead of returning a result, once `execute()` has returned, when this\n\t * call is aborted, or when the Harness closes.\n\t */\n\texecuteTool(\n\t\tname: string,\n\t\targs: JsonObject,\n\t\tcontext: Context,\n\t\toptions?: { readonly key?: string; readonly progress?: boolean },\n\t): Promise<NestedToolExecutionResult>;\n}\n\n/**\n * Executable tool registered in a registry. Only nyan-ai `Tool` fields enter the transcript. `args` are typed by\n * `parameters`, which the Harness validates them against before `execute()`; `defineTool()` infers both generics.\n */\nexport type ToolRegistration<\n\tTParameters extends TSchema = TSchema,\n\tTDetails extends JsonValue = JsonValue,\n> = Tool<TParameters> & {\n\t/** Whether an interrupted execution may rerun on recovery. Default `unsafe`. */\n\treadonly replay?: \"safe\" | \"unsafe\";\n\t/** Default: the settings' `toolExecution`. One sequential call makes its whole round sequential. */\n\treadonly executionMode?: ToolExecutionMode;\n\t/**\n\t * Repair arguments models commonly get wrong before validation, such as a JSON string where an array belongs. Must be\n\t * pure and must not mutate `args`: it runs again when a call is retried before its intent is recorded. Its result is\n\t * still validated against `parameters`.\n\t */\n\tprepareArguments?(args: unknown): Static<TParameters>;\n\t/**\n\t * Schema of `structuredOutput`, which programs that call the tool receive. Omitted: they receive the result's bounded\n\t * output, success or error, as `NestedToolExecutionResult.structuredOutput` describes.\n\t */\n\treadonly structuredOutputSchema?: TSchema;\n\t/**\n\t * Who may call the tool: the model, other tools through `executeTool()`, or both (default). A code mode tool is\n\t * `[\"model\"]`, so scripts cannot start scripts; tools behind code mode, such as MCP tools, can be `[\"tools\"]`, so the\n\t * model is never offered them.\n\t */\n\treadonly callers?: readonly (\"model\" | \"tools\")[];\n\treadonly outputLimits?: {\n\t\treadonly maxBytes?: number;\n\t\treadonly maxLines?: number;\n\t\treadonly retain?: \"head\" | \"tail\";\n\t};\n\texecute(\n\t\targs: Static<TParameters>,\n\t\tapi: ToolExecutionApi<TDetails>,\n\t\tcontext: Context,\n\t): Promise<ToolExecutionResult<TDetails>>;\n};\n\n/** Input to system prompt section rendering for one request preparation. */\nexport type PromptInput<Tool extends ToolRegistration = ToolRegistration> = {\n\treadonly conversationId: ConversationId;\n\t/** The request's resolution; `agent.tools` are the tools offered in this request. */\n\treadonly agent: Agent<Tool>;\n\t/** Built by `HarnessOptions.env` for this preparation; `undefined` without an environment. */\n\treadonly env: ExecutionEnv | undefined;\n\t/** Sections already in effect after replaying the active transcript. */\n\treadonly shown: Readonly<Record<string, string>>;\n\t/** Committed document reads. */\n\treadonly read: DocumentReader;\n};\n\n/** One system prompt section; the agent's sections render in order before each request. */\nexport type PromptSection<Tool extends ToolRegistration = ToolRegistration> = {\n\treadonly key: string;\n\trender(input: PromptInput<Tool>, context: Context): string | undefined | Promise<string | undefined>;\n\t/** Default true: wrap the text as `<key>\\n...\\n</key>`. */\n\treadonly tag?: boolean;\n};\n\n/** Built by `hook()`; matches tasks by name. */\nexport type HookRegistration = { readonly task: string; readonly handlers: object };\n\n/** Built by `wrapTool()` and `wrapSection()`; targets a tool name or a section key. Wrappers are pure. */\nexport type Wrap<Tool extends ToolRegistration = ToolRegistration> =\n\t| { readonly tool: string; wrap(tool: Tool): Tool }\n\t| { readonly section: string; wrap(section: PromptSection<Tool>): PromptSection<Tool> };\n\n/** Named bundle of code; installed in a registry and selected by conversations by name. */\nexport interface Extension<Tool extends ToolRegistration = ToolRegistration> {\n\treadonly name: string;\n\treadonly tools?: readonly Tool[];\n\treadonly sections?: readonly PromptSection<Tool>[];\n\treadonly hooks?: readonly HookRegistration[];\n\t/** Apply where this extension is selected, in order. */\n\treadonly wraps?: readonly Wrap<Tool>[];\n\t/** Resolved by name for every task, whichever conversations select this extension. */\n\treadonly tasks?: readonly AnyTask[];\n}\n\n/** Immutable view of one published registry state. */\nexport interface RegistrySnapshot<Tool extends ToolRegistration = ToolRegistration> {\n\tinstalled(): readonly Extension<Tool>[];\n\textension(name: string): Extension<Tool> | undefined;\n\t/** Every installed tool with its extension, in install order. Names may repeat across extensions. */\n\ttools(): readonly { readonly extension: Extension<Tool>; readonly tool: Tool }[];\n\tsections(): readonly { readonly extension: Extension<Tool>; readonly section: PromptSection<Tool> }[];\n\t/** Built-in and installed task definitions. */\n\ttasks(): readonly AnyTask[];\n\ttask(name: string): AnyTask | undefined;\n}\n\n/** Read side of a registry consumed by a Harness. */\nexport interface RegistryReader<Tool extends ToolRegistration = ToolRegistration> {\n\t/** Immutable view of the whole current registry. */\n\tsnapshot(): RegistrySnapshot<Tool>;\n\t/** Called synchronously after every publication; wakes the scheduler to reconsider blocked tasks. */\n\tsubscribe(listener: () => void): () => void;\n}\n\n/** Application-owned registry of extensions. */\nexport interface Registry<Tool extends ToolRegistration = ToolRegistration> extends RegistryReader<Tool> {\n\t/** Install `extension`, or replace the installed extension with its name in place. Publishes at once. */\n\tinstall(extension: Extension<Tool>): void;\n\t/** Remove the installed extension with `extension.name`, whichever object it is. A later install appends. */\n\tuninstall(extension: Extension): void;\n}\n\n/** Stored choices of one conversation; names, not objects. Unset fields follow the host. */\nexport type AgentState = {\n\tmodel?: ModelRef;\n\tthinkingLevel?: ModelThinkingLevel;\n\t/** An array selects exactly these extensions, in order. An object edits the host default selection. */\n\textensions?: string[] | { add?: string[]; remove?: string[] };\n\t/** Filters the selected extensions' tools: the enabled tools. An array enables exactly these, in order. */\n\ttools?: string[] | { remove: string[] };\n\t/**\n\t * Filters the enabled tools the model may call (`callers` includes `model`): the tools offered to it. An array offers\n\t * exactly these, in order. Never widens: other tools can still call the ones it leaves out.\n\t */\n\tmodelTools?: string[] | { remove: string[] };\n\t/** Rendered after every extension section, as the section `instructions`. */\n\tinstructions?: string;\n\t/** Directory within the environment's file system, passed to `HarnessOptions.env`. */\n\tcwd?: string;\n};\n\n/** A change to `nyan.agent`: a given field replaces the stored one, `null` clears it, `undefined` changes nothing. */\nexport type AgentChange = {\n\treadonly model?: ModelRef | null;\n\treadonly thinkingLevel?: ModelThinkingLevel | null;\n\treadonly extensions?:\n\t\t| readonly Extension[]\n\t\t| { readonly add?: readonly Extension[]; readonly remove?: readonly Extension[] }\n\t\t| null;\n\treadonly tools?: readonly ToolRegistration[] | { readonly remove: readonly ToolRegistration[] } | null;\n\treadonly modelTools?: readonly ToolRegistration[] | { readonly remove: readonly ToolRegistration[] } | null;\n\treadonly instructions?: string | null;\n\treadonly cwd?: string | null;\n};\n\n/** A conversation's agent resolved against a registry snapshot and the settings. */\nexport type Agent<Tool extends ToolRegistration = ToolRegistration> = {\n\treadonly model?: ModelRef;\n\treadonly thinkingLevel: ModelThinkingLevel;\n\treadonly extensions: readonly Extension<Tool>[];\n\t/** The tools a request offers, in order: enabled, callable by the model, and selected by `modelTools`. */\n\treadonly tools: readonly Tool[];\n\t/** The tools nested calls (`executeTool()`) resolve among, in order: enabled and callable by tools. */\n\treadonly callable: readonly Tool[];\n\t/** Extension sections, then `instructions` when set. */\n\treadonly sections: readonly PromptSection<Tool>[];\n\treadonly instructions?: string;\n\treadonly cwd?: string;\n};\n\n/**\n * Runs inside the creating commit, after the creation hook and the `agent` change. The conversation creation is already\n * a table write, so table reads here throw `ReadAfterWrite`; document access remains available.\n */\nexport type ConversationInit = (tx: Tx, conversationId: ConversationId) => void | Promise<void>;\n\nexport type ConversationCreateOptions = {\n\treadonly ownership: ConversationOwnership;\n\t/** Applied in the creating commit after the creation hook's copy, before `init`. */\n\treadonly agent?: AgentChange;\n\treadonly init?: ConversationInit;\n};\n\n/** Curated nyan-ai request options; absent fields use nyan-ai defaults. */\nexport type ConversationStreamOptions = {\n\ttransport?: Transport;\n\ttimeoutMs?: number;\n\t/** Provider/SDK retries inside one request attempt. */\n\tmaxRetries?: number;\n\tmaxRetryDelayMs?: number;\n\theaders?: Record<string, string>;\n\tmetadata?: JsonObject;\n\tcacheRetention?: CacheRetention;\n\tdeferred?: boolean | { window?: \"15m\" | \"1h\" | \"24h\" };\n};\n\n/** Durable generation attempt retries; the JSON shape of nyan-ai `RetryPolicy`. */\nexport type ConversationRetryPolicy = {\n\tenabled: boolean;\n\tmaxRetries: number;\n\tbaseDelayMs: number;\n\tmaxAgentDelayMs?: number;\n};\n\n/** Automatic compaction thresholds (spec §8.7); manual compaction ignores `enabled`. */\nexport type CompactionPolicy = {\n\t/** Threshold and overflow compaction. */\n\tenabled: boolean;\n\t/** Room kept free for the answer: generation blocks to compact above `contextWindow - reserveTokens`. */\n\treserveTokens: number;\n\t/** Approximate size of the recent context a summary keeps verbatim. */\n\tkeepRecentTokens: number;\n\t/** Background compaction starts `backgroundTokens` below the blocking threshold; `0` disables it. */\n\tbackgroundTokens: number;\n};\n\n/**\n * How often running progress is committed. Each progress commit is a storage write; a host whose storage is remote can\n * commit less often, so live answers and tool output appear in larger steps.\n */\nexport type ProgressPolicy = {\n\t/** Minimum pause between commits of the answer being generated. */\n\tpartialIntervalMs: number;\n\t/** Minimum pause between commits of running tool output; large commits also pause in proportion to their size. */\n\toutputIntervalMs: number;\n};\n\n/** Why a compaction runs: `compact()`, a threshold in generation preparation, or a context overflow. */\nexport type CompactionReason = \"manual\" | \"threshold\" | \"overflow\";\n\n/**\n * `entryId` of a blocking compaction's summary, or the `submissionId` of a conversation-owned compaction's summary\n * write; both absent when nothing was compacted.\n */\nexport type CompactionResult = { entryId?: EntryId; submissionId?: SubmissionId };\n\n/** Harness-wide run policy. Read at every resolution and never copied; getters are fine. Synchronous: some readers run on the Session line. */\nexport type HarnessSettings = {\n\t/** Default extension selection; absent: every installed extension, in install order. */\n\treadonly extensions?: readonly Extension[];\n\treadonly stream?: ConversationStreamOptions;\n\treadonly retry?: Partial<ConversationRetryPolicy>;\n\treadonly compaction?: Partial<CompactionPolicy>;\n\treadonly progress?: Partial<ProgressPolicy>;\n\treadonly toolExecution?: ToolExecutionMode;\n\treadonly steeringMode?: QueueMode;\n\treadonly followUpMode?: QueueMode;\n\t/**\n\t * How long an idle conversation keeps its last context read in memory, so its next run reads only newer entries.\n\t * Busy conversations always keep it; `0` drops it once the conversation is idle.\n\t */\n\treadonly contextRetentionMs?: number;\n\t/**\n\t * How long a loaded document that no watch or document state observes stays in memory after its last read or write;\n\t * the next access loads it from Storage. Observed documents always stay. Default ten minutes; `0` drops one right\n\t * after use; `Infinity` keeps them. Anything else that is not a number of milliseconds means the default.\n\t */\n\treadonly documentRetentionMs?: number;\n};\n\n/** Resolved settings: every field over its built-in default, object fields merged. */\nexport type Settings = {\n\t/** Absent: every installed extension, in install order. */\n\treadonly extensions?: readonly Extension[];\n\treadonly stream: ConversationStreamOptions;\n\treadonly retry: ConversationRetryPolicy;\n\treadonly compaction: CompactionPolicy;\n\treadonly progress: ProgressPolicy;\n\treadonly toolExecution: ToolExecutionMode;\n\treadonly steeringMode: QueueMode;\n\treadonly followUpMode: QueueMode;\n\treadonly contextRetentionMs: number;\n\treadonly documentRetentionMs: number;\n};\n\n/** What `HarnessOptions.env` builds an environment for. */\nexport type EnvTarget = {\n\treadonly conversationId: ConversationId;\n\t/** The conversation's agent `cwd`. */\n\treadonly cwd?: string;\n\treadonly read: DocumentReader;\n};\n\nexport type HarnessOptions<Tool extends ToolRegistration = ToolRegistration> = {\n\t/** Provider-neutral model operations used by generation. */\n\treadonly models: ModelRuntime;\n\treadonly registry: RegistryReader<Tool>;\n\treadonly settings?: HarnessSettings;\n\t/** Builds a conversation's environment at each use. Never called on the Session line; may be async. */\n\treadonly env?: (target: EnvTarget, context: Context) => ExecutionEnv | undefined | Promise<ExecutionEnv | undefined>;\n\t/**\n\t * Runs in every commit that creates or forks a conversation, raw `tx.createConversation()` included, after the\n\t * built-in `nyan.*` documents and before the conveniences apply `agent` and run `init`. A fork already has its copies.\n\t * Table reads throw `ReadAfterWrite`, as in `init`; a throw fails the creating commit.\n\t */\n\treadonly conversationCreated?: (tx: Tx, conversation: ConversationRecord) => void | Promise<void>;\n\treadonly now?: () => number;\n\t/**\n\t * Receives failures that do not fail the calling operation, such as a throwing hook or listener, and the error that\n\t * fails the Session, once. Its own throw or rejection is dropped.\n\t */\n\treadonly onReport?: (error: unknown) => void;\n};\n\n/** Live task and what the scheduler would do with it under the current registry. */\nexport type TaskInspection = {\n\treadonly record: TaskRecord<JsonValue, JsonValue, JsonValue>;\n\treadonly state: /** An invocation is active. */\n\t\t| { readonly kind: \"running\" }\n\t\t/** The next scheduling pass reserves it; `migrates` when its definition is newer and has `migrate`. */\n\t\t| { readonly kind: \"ready\"; readonly migrates: boolean }\n\t\t/**\n\t\t * Waits for these live tasks: the live part of its `on`, or, when abort-marked, its live ordinary owned work, which\n\t\t * must end before its abort handler starts.\n\t\t */\n\t\t| { readonly kind: \"waiting\"; readonly on: readonly TaskId[] }\n\t\t/** Outcome held until its ordinary owned work drains. */\n\t\t| { readonly kind: \"completing\" }\n\t\t/** No registered definition can take it; aborting it settles it as `orphaned`. */\n\t\t| {\n\t\t\t\treadonly kind: \"blocked\";\n\t\t\t\treadonly reason: \"missing_task\" | \"task_too_old\" | \"migration_failed\";\n\t\t\t\treadonly error?: unknown;\n\t\t };\n};\n\n/** Point-in-time view of live work: unfinished tasks and submissions, read on the Session line. */\nexport type HarnessInspection = {\n\treadonly scheduling: \"paused\" | \"running\" | \"closing\";\n\treadonly tasks: readonly TaskInspection[];\n\t/** Queued and placed submissions, in ID order. */\n\treadonly submissions: readonly SubmissionRecord[];\n};\n\n/** Raw active transcript and derived model context. */\nexport type ContextView = {\n\t/** Newest applicable head marker, if any. */\n\treadonly head: EntryRecord | undefined;\n\t/** Raw active entries: the head marker followed by non-head entries from its head through the tail. */\n\treadonly entries: readonly EntryRecord[];\n\t/** Per entry of `entries`, its model messages after edits and excluded stop reasons, before tool result ordering. */\n\treadonly contributions: readonly (readonly Message[])[];\n\t/** Model context for the next provider request. */\n\treadonly messages: readonly Message[];\n};\n\n/** Stateless handle for one conversation, bound to the Harness that returned it. Compare handles by `id`. */\nexport interface Conversation {\n\treadonly id: ConversationId;\n\n\t/** Resolved with the current registry snapshot and settings. */\n\tagent(context: Context): Promise<Agent>;\n\t/** `configure()` in its own commit. */\n\tconfigure(change: AgentChange, context: Context): Promise<void>;\n\n\t/**\n\t * Durably admit user input or a passive entry write. A busy conversation, or one with queued items, queues it in\n\t * `nyan.inbox`; `whenBusy: \"reject\"` rejects with `ConversationBusy` instead and writes nothing.\n\t */\n\tsubmit(submission: SubmissionDraft, context: Context): Promise<Submission>;\n\t/**\n\t * Admit a write of a `nyan.reset` entry that starts a new context, carrying `handoff` as a user message when given.\n\t * Resolves after admission; while busy, it is placed at the next boundary.\n\t */\n\treset(handoff: string | undefined, context: Context): Promise<void>;\n\t/**\n\t * Admit a manual compaction task and return its ID. It summarizes while the conversation keeps working and places its\n\t * summary through a write submission: at once when idle, otherwise at the next boundary (spec §8.7).\n\t */\n\tcompact(instructions: string | undefined, context: Context): Promise<TaskId<CompactionResult>>;\n\n\t/** Session commit whose `tx.createTask()` defaults to this conversation. */\n\tcommit<T>(change: (tx: Tx) => T | Promise<T>, context: Context): Promise<T>;\n\t/**\n\t * Committed raw active transcript and model context. With `at`, the context as of that visible entry: the same view\n\t * `fork(at)` would start with, without creating a conversation.\n\t */\n\tcontext(context: Context, options?: { readonly at?: EntryId }): Promise<ContextView>;\n\t/** Fork-aware history of this conversation, newest first unless `query.order` is `ascending`. */\n\tentries(\n\t\tquery: Omit<EntryQuery, \"conversationId\">,\n\t\tlimit: number,\n\t\tcursor: Cursor | undefined,\n\t\tcontext: Context,\n\t): Promise<Page<EntryRecord, Cursor>>;\n\tfork(at: EntryId, options: ConversationCreateOptions, context: Context): Promise<Conversation>;\n\t/**\n\t * Withdraw queued inputs (queued writes stay), mark every live non-background task of the ordinary ownership scope,\n\t * signal them, and resolve once the scope is idle. Background subtrees survive unless `background` is set.\n\t */\n\tabort(context: Context, options?: ConversationAbortOptions): Promise<void>;\n\t/**\n\t * Resolve when the ordinary ownership scope has no live non-background task: this conversation and the conversations\n\t * owned, transitively, by its non-background tasks.\n\t */\n\twaitForIdle(context: Context): Promise<void>;\n\t/** The structural view (spec §9.3) as a disposable read-only Chord state. */\n\tviewState(context: Context): Promise<AttachedReplicatedState<ConversationView>>;\n\t/** The structural view as a serialized exact-frame watch with bounded pending frames. */\n\twatch(context: Context): Promise<ConversationWatch>;\n}\n\nexport type ConversationWatch = WatchHandle<ConversationView>;\n\n/** Durable agent harness over one Session. */\nexport interface Harness extends Session {\n\t/**\n\t * Enable task scheduling. Idempotent; throws after close. Calls that ask for progress enable it too:\n\t * `Conversation.submit()`, `Conversation.compact()`, `Conversation.abort()`, `Submission.wait()`, `waitForTask()`,\n\t * `Harness.waitForIdle()`, and `Conversation.waitForIdle()`. Read-only viewers never do.\n\t */\n\tresume(): void;\n\n\t/** Return the reserved root conversation, creating it with `agent` and `init` in one commit when absent. */\n\troot(\n\t\tcontext: Context,\n\t\toptions?: { readonly agent?: AgentChange; readonly init?: ConversationInit },\n\t): Promise<Conversation>;\n\tconversation(id: ConversationId, context: Context): Promise<Conversation | undefined>;\n\tcreateConversation(options: ConversationCreateOptions, context: Context): Promise<Conversation>;\n\n\tgetTask<R>(id: TaskId<R>, context: Context): Promise<TaskRecord<JsonValue, JsonValue, R> | undefined>;\n\t/** Live tasks and unsettled submissions. Writes nothing and runs no task code. */\n\tinspect(context: Context): Promise<HarnessInspection>;\n\t/** Reacquire a submission, for example after reopen. */\n\tsubmission(id: SubmissionId, context: Context): Promise<Submission | undefined>;\n\t/** `not_found` for an unknown submission or one of another conversation than `conversationId`. */\n\tabortSubmission(\n\t\tid: SubmissionId,\n\t\tcontext: Context,\n\t\tconversationId?: ConversationId,\n\t): Promise<\"aborted\" | \"already_placed\" | \"settled\" | \"not_found\">;\n\t/**\n\t * Commit the abort mark, signal and join an active run invocation, and schedule the abort invocation. A task whose\n\t * definition cannot take it settles as `orphaned` instead.\n\t */\n\tabortTask(id: TaskId, context: Context): Promise<\"marked\" | \"terminal\">;\n\t/** Resolve with the terminal receipt; cancelling `context` cancels only this wait. */\n\twaitForTask<R>(id: TaskId<R>, context: Context): Promise<SettledTask<R>>;\n\t/** Resolve when the ordinary ownership scope of every ownerless conversation has no live non-background task. */\n\twaitForIdle(context: Context): Promise<void>;\n\t/** Session total: every conversation's `nyan.usage` summed. */\n\tusage(context: Context): Promise<UsageState>;\n\t/** Every live task with its owner edge, status, and owned conversations (spec §9.5), as a disposable Chord state. */\n\ttaskGraph(context: Context): Promise<AttachedReplicatedState<TaskGraph>>;\n\t/** The task graph as a serialized exact-frame watch with bounded pending frames. */\n\twatchTaskGraph(context: Context): Promise<TaskGraphWatch>;\n}\n\n/** What a hook may use: committed reads and the asking task's memos, which hooks and the task share. */\nexport interface HookApi extends DocumentReader {\n\treadonly taskId: TaskId;\n\treadonly conversationId: ConversationId;\n\t/** `HarnessOptions.models`. */\n\treadonly models: ModelRuntime;\n\tmemo<T extends JsonValue>(name: string, context: Context): Promise<T | undefined>;\n\tmemo<T extends JsonValue>(name: string, candidate: T, context: Context): Promise<T>;\n}\n\nexport type HookResult<T> = T | undefined | Promise<T | undefined>;\n\n/** Hooks of the built-in generation task. */\nexport interface GenerationHooks {\n\t/** Before every request attempt, including recovery; the result is used for that request only. */\n\tbeforeRequest(\n\t\trequest: { readonly messages: readonly Message[] },\n\t\tapi: HookApi,\n\t\tcontext: Context,\n\t): HookResult<{ readonly messages: readonly Message[] }>;\n\t/** Every terminal provider message, before classification. */\n\tafterResponse(message: AssistantMessage, api: HookApi, context: Context): void | Promise<void>;\n\t/** A final answer; the first `continue` appends a user message and continues the run. */\n\tonYield(answer: AssistantMessage, api: HookApi, context: Context): HookResult<{ readonly continue: UserInput }>;\n\t/** After every tool of the round is terminal; `results` are the round's result entries in call order. */\n\tafterTools(assistant: EntryId, results: readonly EntryId[], api: HookApi, context: Context): void | Promise<void>;\n}\n\n/** A call as tool hooks see it; `parent` is set for a nested call, one a running tool made through `executeTool()`. */\nexport type ToolHookCall = ToolCall & {\n\treadonly parent?: { readonly taskId: TaskId; readonly callId: string };\n};\n\n/** Hooks of the built-in tool task, for model-issued and nested calls. */\nexport interface ToolHooks {\n\t/** Before intent; the first `block` wins, otherwise `arguments` replace the call's arguments. A throw blocks. */\n\tbeforeTool(\n\t\tcall: ToolHookCall,\n\t\tapi: HookApi,\n\t\tcontext: Context,\n\t): HookResult<{ readonly arguments?: JsonObject; readonly block?: string }>;\n\t/** After execution, before the result is committed; replaces the result. */\n\tafterTool(\n\t\tcall: ToolHookCall,\n\t\tresult: ToolExecutionResult,\n\t\tapi: HookApi,\n\t\tcontext: Context,\n\t): HookResult<ToolExecutionResult>;\n}\n\n/** Hooks of the built-in compaction task. */\nexport interface CompactionHooks {\n\t/**\n\t * After range selection, before summarizing; the first decision wins. `entries` are the active entries the summary\n\t * replaces, the head marker first, and `messages` their model context, the summarizer's source; `firstKept` is the\n\t * first entry kept verbatim.\n\t */\n\tbeforeCompact(\n\t\tcompaction: {\n\t\t\treadonly reason: CompactionReason;\n\t\t\treadonly entries: readonly EntryRecord[];\n\t\t\treadonly messages: readonly Message[];\n\t\t\treadonly firstKept: EntryId;\n\t\t\treadonly instructions?: string;\n\t\t},\n\t\tapi: HookApi,\n\t\tcontext: Context,\n\t): HookResult<{ readonly decline: true } | { readonly summary: string }>;\n}\n"]}
@@ -0,0 +1,18 @@
1
+ import type { Usage } from "@ny4n/ai/contracts";
2
+ import { type Draft, type JsonRepresentation } from "@ny4n/chord";
3
+ import type { ConversationId, Tx } from "../types.ts";
4
+ /** Ledger of one conversation's own spend: its entries, and compaction summarization attempts, which have none. */
5
+ export type UsageState = {
6
+ /** Assistant entries and summarization attempts, keyed `provider/modelId`. */
7
+ models: Record<string, JsonRepresentation<Usage>>;
8
+ /** Tool results, keyed by tool name; their usage has no model identity. */
9
+ tools: Record<string, JsonRepresentation<Usage>>;
10
+ };
11
+ export declare const UsageDoc: import("../types.ts").ConversationDocToken<UsageState>;
12
+ /** Add `usage` to one bucket of the conversation's `nyan.usage`, in the commit that records the response. */
13
+ export declare function recordUsage(tx: Tx, conversationId: ConversationId, bucket: keyof UsageState, key: string, usage: Usage): Promise<void>;
14
+ /** Add every counter of `usage` to `total`; optional counters are added once either side reports them. */
15
+ export declare function addUsage(total: Draft<Usage> | Usage, usage: Usage): void;
16
+ /** Add every bucket of `state` into `sum`. */
17
+ export declare function addUsageState(sum: UsageState, state: Readonly<UsageState>): void;
18
+ //# sourceMappingURL=usage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../../src/harness/usage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAY,KAAK,KAAK,EAAE,KAAK,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAE5E,OAAO,KAAK,EAAE,cAAc,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAEtD,mHAAmH;AACnH,MAAM,MAAM,UAAU,GAAG;IACxB,8EAA8E;IAC9E,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC;IAClD,2EAA2E;IAC3E,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC;CACjD,CAAC;AAEF,eAAO,MAAM,QAAQ,wDAQnB,CAAC;AAEH,6GAA6G;AAC7G,wBAAsB,WAAW,CAChC,EAAE,EAAE,EAAE,EACN,cAAc,EAAE,cAAc,EAC9B,MAAM,EAAE,MAAM,UAAU,EACxB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,KAAK,GACV,OAAO,CAAC,IAAI,CAAC,CAQf;AAED,0GAA0G;AAC1G,wBAAgB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,KAAK,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,CAaxE;AAED,8CAA8C;AAC9C,wBAAgB,aAAa,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG,IAAI,CAchF"}
@@ -0,0 +1,57 @@
1
+ import { copyJson } from "@ny4n/chord";
2
+ import { defineDoc } from "../documents.js";
3
+ export const UsageDoc = defineDoc({
4
+ kind: "nyan.usage",
5
+ version: 1,
6
+ scope: "conversation",
7
+ history: "latest",
8
+ fork: "initial",
9
+ initial: () => ({ models: {}, tools: {} }),
10
+ checkpointWhen: () => true,
11
+ });
12
+ /** Add `usage` to one bucket of the conversation's `nyan.usage`, in the commit that records the response. */
13
+ export async function recordUsage(tx, conversationId, bucket, key, usage) {
14
+ const totals = (await tx.doc(UsageDoc, conversationId))[bucket];
15
+ // Own keys only: a tool may be called `toString`.
16
+ const total = Object.hasOwn(totals, key) ? totals[key] : undefined;
17
+ // Providers may leave optional counters `undefined`; drafts take strict JSON.
18
+ if (total === undefined)
19
+ totals[key] = copyJson(usage, { omitUndefinedProperties: true });
20
+ else
21
+ addUsage(total, usage);
22
+ }
23
+ /** Add every counter of `usage` to `total`; optional counters are added once either side reports them. */
24
+ export function addUsage(total, usage) {
25
+ total.input += usage.input;
26
+ total.output += usage.output;
27
+ total.cacheRead += usage.cacheRead;
28
+ total.cacheWrite += usage.cacheWrite;
29
+ total.totalTokens += usage.totalTokens;
30
+ if (usage.cacheWrite1h !== undefined)
31
+ total.cacheWrite1h = (total.cacheWrite1h ?? 0) + usage.cacheWrite1h;
32
+ if (usage.reasoning !== undefined)
33
+ total.reasoning = (total.reasoning ?? 0) + usage.reasoning;
34
+ total.cost.input += usage.cost.input;
35
+ total.cost.output += usage.cost.output;
36
+ total.cost.cacheRead += usage.cost.cacheRead;
37
+ total.cost.cacheWrite += usage.cost.cacheWrite;
38
+ total.cost.total += usage.cost.total;
39
+ }
40
+ /** Add every bucket of `state` into `sum`. */
41
+ export function addUsageState(sum, state) {
42
+ for (const bucket of ["models", "tools"]) {
43
+ for (const [key, usage] of Object.entries(state[bucket])) {
44
+ const total = Object.hasOwn(sum[bucket], key) ? sum[bucket][key] : undefined;
45
+ // Define rather than assign: assigning a tool named `__proto__` would set the prototype.
46
+ if (total !== undefined)
47
+ addUsage(total, usage);
48
+ else
49
+ Object.defineProperty(sum[bucket], key, {
50
+ value: structuredClone(usage),
51
+ enumerable: true,
52
+ writable: true,
53
+ });
54
+ }
55
+ }
56
+ }
57
+ //# sourceMappingURL=usage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usage.js","sourceRoot":"","sources":["../../src/harness/usage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAuC,MAAM,aAAa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AAS,CAAC;YAC7E,yFAAyF;YACzF,IAAI,KAAK,KAAK,SAAS;gBAAE,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;;gBAE/C,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE;oBACvC,KAAK,EAAE,eAAe,CAAC,KAAK,CAAC;oBAC7B,UAAU,EAAE,IAAI;oBAChB,QAAQ,EAAE,IAAI;iBACd,CAAC,CAAC;QACL,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["import type { Usage } from \"@ny4n/ai/contracts\";\nimport { copyJson, type Draft, type JsonRepresentation } from \"@ny4n/chord\";\nimport { defineDoc } from \"../documents.ts\";\nimport type { ConversationId, Tx } from \"../types.ts\";\n\n/** Ledger of one conversation's own spend: its entries, and compaction summarization attempts, which have none. */\nexport type UsageState = {\n\t/** Assistant entries and summarization attempts, keyed `provider/modelId`. */\n\tmodels: Record<string, JsonRepresentation<Usage>>;\n\t/** Tool results, keyed by tool name; their usage has no model identity. */\n\ttools: Record<string, JsonRepresentation<Usage>>;\n};\n\nexport const UsageDoc = defineDoc<UsageState>({\n\tkind: \"nyan.usage\",\n\tversion: 1,\n\tscope: \"conversation\",\n\thistory: \"latest\",\n\tfork: \"initial\",\n\tinitial: () => ({ models: {}, tools: {} }),\n\tcheckpointWhen: () => true,\n});\n\n/** Add `usage` to one bucket of the conversation's `nyan.usage`, in the commit that records the response. */\nexport async function recordUsage(\n\ttx: Tx,\n\tconversationId: ConversationId,\n\tbucket: keyof UsageState,\n\tkey: string,\n\tusage: Usage,\n): Promise<void> {\n\tconst totals = (await tx.doc(UsageDoc, conversationId))[bucket];\n\t// Own keys only: a tool may be called `toString`.\n\tconst total = Object.hasOwn(totals, key) ? totals[key] : undefined;\n\t// Providers may leave optional counters `undefined`; drafts take strict JSON.\n\tif (total === undefined)\n\t\ttotals[key] = copyJson(usage, { omitUndefinedProperties: true }) as JsonRepresentation<Usage>;\n\telse addUsage(total, usage);\n}\n\n/** Add every counter of `usage` to `total`; optional counters are added once either side reports them. */\nexport function addUsage(total: Draft<Usage> | Usage, usage: Usage): void {\n\ttotal.input += usage.input;\n\ttotal.output += usage.output;\n\ttotal.cacheRead += usage.cacheRead;\n\ttotal.cacheWrite += usage.cacheWrite;\n\ttotal.totalTokens += usage.totalTokens;\n\tif (usage.cacheWrite1h !== undefined) total.cacheWrite1h = (total.cacheWrite1h ?? 0) + usage.cacheWrite1h;\n\tif (usage.reasoning !== undefined) total.reasoning = (total.reasoning ?? 0) + usage.reasoning;\n\ttotal.cost.input += usage.cost.input;\n\ttotal.cost.output += usage.cost.output;\n\ttotal.cost.cacheRead += usage.cost.cacheRead;\n\ttotal.cost.cacheWrite += usage.cost.cacheWrite;\n\ttotal.cost.total += usage.cost.total;\n}\n\n/** Add every bucket of `state` into `sum`. */\nexport function addUsageState(sum: UsageState, state: Readonly<UsageState>): void {\n\tfor (const bucket of [\"models\", \"tools\"] as const) {\n\t\tfor (const [key, usage] of Object.entries(state[bucket])) {\n\t\t\tconst total = Object.hasOwn(sum[bucket], key) ? sum[bucket][key] : undefined;\n\t\t\t// Define rather than assign: assigning a tool named `__proto__` would set the prototype.\n\t\t\tif (total !== undefined) addUsage(total, usage);\n\t\t\telse\n\t\t\t\tObject.defineProperty(sum[bucket], key, {\n\t\t\t\t\tvalue: structuredClone(usage),\n\t\t\t\t\tenumerable: true,\n\t\t\t\t\twritable: true,\n\t\t\t\t});\n\t\t}\n\t}\n}\n"]}
@@ -0,0 +1,19 @@
1
+ import type { Context } from "@ny4n/chord";
2
+ import type { Cursor, Page } from "../types.ts";
3
+ /** Pending waits by key. Each settles once: through `resolve`, `rejectAll`, or cancellation of its context. */
4
+ export declare class Waiters<K, T> {
5
+ #private;
6
+ add(key: K, context: Context): Promise<T>;
7
+ keys(): K[];
8
+ resolve(key: K, value: T): void;
9
+ rejectAll(error: unknown): void;
10
+ }
11
+ /** Every item of a paginated scan, in page order. */
12
+ export declare function scanAll<T>(scan: (cursor: Cursor | undefined) => Promise<Page<T, Cursor>>): Promise<T[]>;
13
+ /** What a closed Harness rejects with: `SessionFailed` with the cause when it closed because the Session failed. */
14
+ export declare function closedError(session: {
15
+ readonly failure: {
16
+ readonly error: unknown;
17
+ } | undefined;
18
+ }): Error;
19
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/harness/util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAEhD,+GAA+G;AAC/G,qBAAa,OAAO,CAAC,CAAC,EAAE,CAAC;;IAGxB,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAiBxC;IAED,IAAI,IAAI,CAAC,EAAE,CAEV;IAED,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAI9B;IAED,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAI9B;CACD;AAED,qDAAqD;AACrD,wBAAsB,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,CAS7G;AAED,oHAAoH;AACpH,wBAAgB,WAAW,CAAC,OAAO,EAAE;IAAE,QAAQ,CAAC,OAAO,EAAE;QAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;KAAE,GAAG,SAAS,CAAA;CAAE,GAAG,KAAK,CAGzG"}
@@ -0,0 +1,58 @@
1
+ import { SessionFailed } from "../errors.js";
2
+ /** Pending waits by key. Each settles once: through `resolve`, `rejectAll`, or cancellation of its context. */
3
+ export class Waiters {
4
+ #sets = new Map();
5
+ add(key, context) {
6
+ const signal = context.abortSignal;
7
+ if (signal?.aborted)
8
+ return Promise.reject(signal.reason);
9
+ const waiter = Promise.withResolvers();
10
+ const set = this.#sets.get(key) ?? new Set();
11
+ this.#sets.set(key, set.add(waiter));
12
+ if (signal !== undefined) {
13
+ const onAbort = () => {
14
+ set.delete(waiter);
15
+ if (set.size === 0 && this.#sets.get(key) === set)
16
+ this.#sets.delete(key);
17
+ waiter.reject(signal.reason);
18
+ };
19
+ signal.addEventListener("abort", onAbort, { once: true });
20
+ const detach = () => signal.removeEventListener("abort", onAbort);
21
+ waiter.promise.then(detach, detach);
22
+ }
23
+ return waiter.promise;
24
+ }
25
+ keys() {
26
+ return [...this.#sets.keys()];
27
+ }
28
+ resolve(key, value) {
29
+ const set = this.#sets.get(key);
30
+ this.#sets.delete(key);
31
+ for (const waiter of set ?? [])
32
+ waiter.resolve(value);
33
+ }
34
+ rejectAll(error) {
35
+ const sets = [...this.#sets.values()];
36
+ this.#sets.clear();
37
+ for (const set of sets)
38
+ for (const waiter of set)
39
+ waiter.reject(error);
40
+ }
41
+ }
42
+ /** Every item of a paginated scan, in page order. */
43
+ export async function scanAll(scan) {
44
+ const items = [];
45
+ let cursor;
46
+ do {
47
+ const page = await scan(cursor);
48
+ items.push(...page.items);
49
+ cursor = page.next;
50
+ } while (cursor !== undefined);
51
+ return items;
52
+ }
53
+ /** What a closed Harness rejects with: `SessionFailed` with the cause when it closed because the Session failed. */
54
+ export function closedError(session) {
55
+ const failure = session.failure;
56
+ return failure === undefined ? new Error("Harness is closed") : new SessionFailed(failure.error);
57
+ }
58
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/harness/util.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAG7C,+GAA+G;AAC/G,MAAM,OAAO,OAAO;IACV,KAAK,GAAG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OAAO,CAAC,KAAK,CAAC,CAAC;AAClG,CAAC","sourcesContent":["import type { Context } from \"@ny4n/chord\";\nimport { SessionFailed } from \"../errors.ts\";\nimport type { Cursor, Page } from \"../types.ts\";\n\n/** Pending waits by key. Each settles once: through `resolve`, `rejectAll`, or cancellation of its context. */\nexport class Waiters<K, T> {\n\treadonly #sets = new Map<K, Set<PromiseWithResolvers<T>>>();\n\n\tadd(key: K, context: Context): Promise<T> {\n\t\tconst signal = context.abortSignal;\n\t\tif (signal?.aborted) return Promise.reject(signal.reason);\n\t\tconst waiter = Promise.withResolvers<T>();\n\t\tconst set = this.#sets.get(key) ?? new Set();\n\t\tthis.#sets.set(key, set.add(waiter));\n\t\tif (signal !== undefined) {\n\t\t\tconst onAbort = (): void => {\n\t\t\t\tset.delete(waiter);\n\t\t\t\tif (set.size === 0 && this.#sets.get(key) === set) this.#sets.delete(key);\n\t\t\t\twaiter.reject(signal.reason);\n\t\t\t};\n\t\t\tsignal.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\tconst detach = (): void => signal.removeEventListener(\"abort\", onAbort);\n\t\t\twaiter.promise.then(detach, detach);\n\t\t}\n\t\treturn waiter.promise;\n\t}\n\n\tkeys(): K[] {\n\t\treturn [...this.#sets.keys()];\n\t}\n\n\tresolve(key: K, value: T): void {\n\t\tconst set = this.#sets.get(key);\n\t\tthis.#sets.delete(key);\n\t\tfor (const waiter of set ?? []) waiter.resolve(value);\n\t}\n\n\trejectAll(error: unknown): void {\n\t\tconst sets = [...this.#sets.values()];\n\t\tthis.#sets.clear();\n\t\tfor (const set of sets) for (const waiter of set) waiter.reject(error);\n\t}\n}\n\n/** Every item of a paginated scan, in page order. */\nexport async function scanAll<T>(scan: (cursor: Cursor | undefined) => Promise<Page<T, Cursor>>): Promise<T[]> {\n\tconst items: T[] = [];\n\tlet cursor: Cursor | undefined;\n\tdo {\n\t\tconst page = await scan(cursor);\n\t\titems.push(...page.items);\n\t\tcursor = page.next;\n\t} while (cursor !== undefined);\n\treturn items;\n}\n\n/** What a closed Harness rejects with: `SessionFailed` with the cause when it closed because the Session failed. */\nexport function closedError(session: { readonly failure: { readonly error: unknown } | undefined }): Error {\n\tconst failure = session.failure;\n\treturn failure === undefined ? new Error(\"Harness is closed\") : new SessionFailed(failure.error);\n}\n"]}
@@ -0,0 +1,47 @@
1
+ import { type AttachedReplicatedState, type Context } from "@ny4n/chord";
2
+ import { type Op } from "@ny4n/chord/delta";
3
+ import { type SessionImpl } from "../session/session.ts";
4
+ import type { CommitPublication, ConversationId, ConversationRecord, EntryRecord, JsonObject, Storage, WatchHandle } from "../types.ts";
5
+ /** Structural mount of one conversation's active transcript and built-in documents (spec §9.3). */
6
+ export type ConversationView = {
7
+ readonly conversation: ConversationRecord;
8
+ /** Raw active entries, as `ContextView.entries`: the head marker, then the non-head entries from its head. */
9
+ readonly entries: readonly EntryRecord[];
10
+ /** Built-in conversation documents keyed by kind; absent documents are absent. */
11
+ readonly docs: Readonly<Record<string, JsonObject>>;
12
+ };
13
+ /** Receives each next revision of a mount, and the Session's close. */
14
+ export type ViewObserver = {
15
+ advance?(value: ConversationView, ops: readonly Op[], context: Context): void;
16
+ /** Every publication, after the mount took it; `ops` are the mount's, possibly none. */
17
+ publication?(before: ConversationView, after: ConversationView, ops: readonly Op[], publication: CommitPublication, context: Context): void;
18
+ closeSession(failure: {
19
+ readonly error: unknown;
20
+ } | undefined): void;
21
+ };
22
+ /** The view mounts of a Harness, for adapters built on them. */
23
+ export declare function conversationViews(harness: object): ConversationViews;
24
+ /**
25
+ * The Harness's conversation view mounts: at most one per conversation, built on the Session line by its first
26
+ * observer and dropped with its last. Each mount advances from the Session's commit publications, which are durable.
27
+ */
28
+ export declare class ConversationViews {
29
+ #private;
30
+ constructor(session: SessionImpl, storage: Storage);
31
+ /** Report an observer's listener error through the Harness. */
32
+ report(error: unknown): void;
33
+ /** A disposable read-only Chord state of the view. */
34
+ state(id: ConversationId, context: Context): Promise<AttachedReplicatedState<ConversationView>>;
35
+ /** A serialized exact-frame watch of the view; cancelling `context` stops it. */
36
+ watch(id: ConversationId, context: Context): Promise<WatchHandle<ConversationView>>;
37
+ /**
38
+ * Register an observer created from the current revision, atomically on the Session line: it sees every later
39
+ * publication and nothing earlier. `create` may read committed Storage, still on the line. `release` drops it, and
40
+ * the mount with its last observer.
41
+ */
42
+ attach<O extends ViewObserver>(id: ConversationId, create: (value: ConversationView, release: () => void, storage: Storage) => O | Promise<O>, context: Context): Promise<{
43
+ observer: O;
44
+ detach: () => void;
45
+ }>;
46
+ }
47
+ //# sourceMappingURL=view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../../src/harness/view.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,uBAAuB,EAAE,KAAK,OAAO,EAAmC,MAAM,aAAa,CAAC;AAE1G,OAAO,EAAqC,KAAK,EAAE,EAAa,MAAM,mBAAmB,CAAC;AAE1F,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,KAAK,EACX,iBAAiB,EAEjB,cAAc,EACd,kBAAkB,EAElB,WAAW,EACX,UAAU,EACV,OAAO,EACP,WAAW,EACX,MAAM,aAAa,CAAC;AASrB,mGAAmG;AACnG,MAAM,MAAM,gBAAgB,GAAG;IAC9B,QAAQ,CAAC,YAAY,EAAE,kBAAkB,CAAC;IAC1C,8GAA8G;IAC9G,QAAQ,CAAC,OAAO,EAAE,SAAS,WAAW,EAAE,CAAC;IACzC,kFAAkF;IAClF,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;CACpD,CAAC;AAEF,uEAAuE;AACvE,MAAM,MAAM,YAAY,GAAG;IAC1B,OAAO,CAAC,CAAC,KAAK,EAAE,gBAAgB,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IAC9E,wFAA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ortSignal } from "@ny4n/chord/context";
3
+ import { applyImmutable } from "@ny4n/chord/delta";
4
+ import { CommittedStateSource, CommittedWatch } from "../session/observation.js";
5
+ import { contained } from "../session/session.js";
6
+ import { AgentDoc } from "./agent.js";
7
+ import { activeEntries, captureContextBounds } from "./context.js";
8
+ import { InboxDoc } from "./inbox.js";
9
+ import { LiveDoc } from "./live.js";
10
+ import { ProviderDoc } from "./provider.js";
11
+ import { UsageDoc } from "./usage.js";
12
+ import { closedError } from "./util.js";
13
+ const MOUNTED = [
14
+ AgentDoc,
15
+ LiveDoc,
16
+ InboxDoc,
17
+ ProviderDoc,
18
+ UsageDoc,
19
+ ];
20
+ const MOUNTED_KINDS = new Set(MOUNTED.map((token) => token.definition.kind));
21
+ const VIEWS = new WeakMap();
22
+ /** The view mounts of a Harness, for adapters built on them. */
23
+ export function conversationViews(harness) {
24
+ const views = VIEWS.get(harness);
25
+ if (views === undefined)
26
+ throw new Error("Not a Harness");
27
+ return views;
28
+ }
29
+ /**
30
+ * The Harness's conversation view mounts: at most one per conversation, built on the Session line by its first
31
+ * observer and dropped with its last. Each mount advances from the Session's commit publications, which are durable.
32
+ */
33
+ export class ConversationViews {
34
+ #session;
35
+ #storage;
36
+ #mounts = new Map();
37
+ #closed = false;
38
+ constructor(session, storage) {
39
+ this.#session = session;
40
+ this.#storage = storage;
41
+ VIEWS.set(session, this);
42
+ session.observeCommits((publication, context) => {
43
+ for (const [id, mount] of this.#mounts)
44
+ advance(id, mount, publication, context, (error) => this.report(error));
45
+ });
46
+ session.subscribeClose(() => {
47
+ this.#closed = true;
48
+ for (const mount of this.#mounts.values())
49
+ for (const observer of [...mount.observers]) {
50
+ contained(() => observer.closeSession(this.#session.failure), (error) => this.report(error));
51
+ }
52
+ this.#mounts.clear();
53
+ });
54
+ }
55
+ /** Report an observer's listener error through the Harness. */
56
+ report(error) {
57
+ this.#session.report(error);
58
+ }
59
+ /** A disposable read-only Chord state of the view. */
60
+ async state(id, context) {
61
+ const { observer, detach } = await this.attach(id, (value, release) => new CommittedStateSource(value, release), context);
62
+ try {
63
+ return replicatedState(observer, { onError: (error) => this.#session.report(error) });
64
+ }
65
+ catch (error) {
66
+ detach();
67
+ throw error;
68
+ }
69
+ }
70
+ /** A serialized exact-frame watch of the view; cancelling `context` stops it. */
71
+ async watch(id, context) {
72
+ const { observer } = await this.attach(id, (value, release) => new CommittedWatch(value, release, (error) => this.#session.report(error)), context);
73
+ const signal = context.abortSignal;
74
+ if (signal?.aborted) {
75
+ observer.cancel();
76
+ throw signal.reason;
77
+ }
78
+ if (signal !== undefined)
79
+ observer.observeCancellation(signal);
80
+ return observer;
81
+ }
82
+ /**
83
+ * Register an observer created from the current revision, atomically on the Session line: it sees every later
84
+ * publication and nothing earlier. `create` may read committed Storage, still on the line. `release` drops it, and
85
+ * the mount with its last observer.
86
+ */
87
+ attach(id, create, context) {
88
+ return this.#session.readOnLine(async () => {
89
+ const mount = this.#mounts.get(id) ?? (await this.#build(id, context));
90
+ const detach = () => {
91
+ mount.observers.delete(observer);
92
+ if (mount.observers.size === 0 && this.#mounts.get(id) === mount)
93
+ this.#mounts.delete(id);
94
+ };
95
+ const observer = await create(mount.value, detach, this.#storage);
96
+ // Close or cancellation may begin while the mount hydrates; register nothing then.
97
+ if (this.#closed)
98
+ throw closedError(this.#session);
99
+ context.abortSignal?.throwIfAborted();
100
+ this.#mounts.set(id, mount);
101
+ mount.observers.add(observer);
102
+ return { observer, detach };
103
+ });
104
+ }
105
+ async #build(id, context) {
106
+ const conversation = await this.#storage.conversation(id, context);
107
+ if (conversation === undefined)
108
+ throw new Error(`Conversation ${id} does not exist`);
109
+ const bounds = await captureContextBounds(this.#storage, id, context);
110
+ const entries = await activeEntries(this.#storage, id, bounds, context);
111
+ const docs = {};
112
+ const incarnations = new Map();
113
+ for (const token of MOUNTED) {
114
+ const loaded = await this.#session.conversationDocumentOnLine(token, id, context);
115
+ if (loaded === undefined)
116
+ continue;
117
+ docs[token.definition.kind] = loaded.value;
118
+ incarnations.set(token.definition.kind, { id: loaded.record.id, version: loaded.version });
119
+ }
120
+ return { value: { conversation, entries, docs }, docs: incarnations, observers: new Set() };
121
+ }
122
+ }
123
+ /**
124
+ * Derive the mount's operations from one publication, apply them, and hand the revision to every observer; one that
125
+ * throws is reported through `report`, and the others still get it.
126
+ */
127
+ function advance(id, mount, publication, context, report) {
128
+ const docOps = [];
129
+ const entryOps = [];
130
+ let entries = mount.value.entries;
131
+ // Entry writes are published in ID order.
132
+ for (const change of publication.changes) {
133
+ if (change.type === "entry" && change.value.conversationId === id) {
134
+ const entry = change.value;
135
+ const value = entry;
136
+ if (entry.head === undefined) {
137
+ entryOps.push(["p", ["entries"], entries.length, 0, [value]]);
138
+ entries = [...entries, entry];
139
+ continue;
140
+ }
141
+ // A head marker keeps the non-head entries from its head, which are always a suffix, and goes in front.
142
+ const target = entry.head;
143
+ let kept = entries.findIndex((candidate) => candidate.head === undefined && candidate.id >= target);
144
+ if (kept < 0)
145
+ kept = entries.length;
146
+ entryOps.push(["p", ["entries"], 0, kept, [value]]);
147
+ entries = [entry, ...entries.slice(kept)];
148
+ continue;
149
+ }
150
+ if (change.type !== "document" || change.conversationId !== id)
151
+ continue;
152
+ const kind = change.record.kind;
153
+ if (!MOUNTED_KINDS.has(kind) || change.record.key !== undefined)
154
+ continue;
155
+ const path = ["docs", kind];
156
+ const mounted = mount.docs.get(kind);
157
+ if (change.value === null) {
158
+ if (mounted?.id !== change.record.id)
159
+ continue;
160
+ mount.docs.delete(kind);
161
+ docOps.push(["d", path]);
162
+ }
163
+ else if (mounted?.id === change.record.id && mounted.version === change.version) {
164
+ for (const op of change.ops)
165
+ docOps.push(prefixed(op, path));
166
+ }
167
+ else {
168
+ mount.docs.set(kind, { id: change.record.id, version: change.version });
169
+ docOps.push(["s", path, change.value]);
170
+ }
171
+ }
172
+ const before = mount.value;
173
+ const ops = [...docOps, ...entryOps];
174
+ const frameContext = withoutAbortSignal(context);
175
+ if (ops.length > 0) {
176
+ const value = docOps.length === 0 ? mount.value : applyImmutable(mount.value, docOps);
177
+ mount.value = entries === value.entries ? value : { ...value, entries };
178
+ for (const observer of [...mount.observers]) {
179
+ contained(() => observer.advance?.(mount.value, ops, frameContext), report);
180
+ }
181
+ }
182
+ for (const observer of [...mount.observers]) {
183
+ contained(() => observer.publication?.(before, mount.value, ops, publication, frameContext), report);
184
+ }
185
+ }
186
+ /** `op` moved under `prefix`; a root replacement becomes a set of the prefix. */
187
+ function prefixed(op, prefix) {
188
+ const at = (path) => [...prefix, ...path];
189
+ switch (op[0]) {
190
+ case "r":
191
+ return ["s", prefix, op[1]];
192
+ case "p":
193
+ return ["p", at(op[1]), op[2], op[3], op[4]];
194
+ case "m":
195
+ return ["m", at(op[1]), op[2]];
196
+ case "s":
197
+ return ["s", at(op[1]), op[2]];
198
+ case "d":
199
+ return ["d", at(op[1])];
200
+ case "a":
201
+ return ["a", at(op[1]), op[2]];
202
+ case "t":
203
+ return ["t", at(op[1]), op[2]];
204
+ }
205
+ }
206
+ //# sourceMappingURL=view.js.map