@diffra-ai/durable 0.0.0-stage → 0.2.3

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 +442 -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":"fit.js","sourceRoot":"","sources":["../../src/images/fit.ts"],"names":[],"mappings":"AAAA,uGAAuG;AACvG,sHAAsH;AACtH,2GAA2G;AAC3G,kFAAkF;AAIlF,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE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,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IAC7F,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC,CAAC;IAC7E,IAAI,MAAM,CAAC,IAAI,KAAK,WAAW;QAAE,OAAO,SAAS,CAAC;IAClD,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC;IAC5E,MAAM,IAAI,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,EAAW,CAAC;IAC3F,OAAO,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,WAAW,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,WAAW,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC;AAClG,CAAC","sourcesContent":["// `@diffra-ai/durable/images/fit`: images entering a conversation, fitted to its model's limits by any\n// `ImageProcessor` before they are stored, so the transcript (and the provider's prompt cache) never changes later: a\n// host's input before it is submitted (`fitImage`, `fitImages`), and the results of the model's tool calls\n// (`createFitImagesExtension`). Photon is not loaded from here; pass a processor.\n\nimport type { ImageContent, TextContent } from \"@diffra-ai/ai\";\nimport type { Context } from \"@diffra-ai/chord/context\";\nimport { errorMessage } from \"../errors.ts\";\nimport { AgentDoc } from \"../harness/agent.ts\";\nimport { defineExtension, hook } from \"../harness/define.ts\";\nimport { ToolTask } from \"../harness/tool.ts\";\nimport type { Extension, HookApi, ToolExecutionResult, ToolHookCall } from \"../harness/types.ts\";\nimport { detectSupportedImageMimeType } from \"../tools/image.ts\";\nimport {\n\tfromBase64,\n\ttype ImageLimits,\n\ttype ImageProcessor,\n\timageLimits,\n\ttype PreparedImage,\n\tpreparedNotes,\n} from \"../tools/image-processor.ts\";\n\n/** One image fitted by `fitImage`, with notes for the model saying what changed; or why it was left out. */\nexport type FittedImage =\n\t| { readonly kind: \"fitted\"; readonly image: ImageContent; readonly notes: readonly string[] }\n\t| { readonly kind: \"omitted\"; readonly note: string };\n\n/** What `fitImages` did: nothing, or the content with its images fitted and notes for the model. */\nexport type FittedImages =\n\t| { readonly kind: \"unchanged\" }\n\t| { readonly kind: \"fitted\"; readonly content: (TextContent | ImageContent)[]; readonly notes: readonly string[] };\n\n/**\n * The image in `bytes`, declared as `mimeType`, prepared by `processor` to fit `limits`. Every image is decoded, as the\n * coding agent's are: one the provider would reject (damaged, or too large) never reaches the transcript, where it would\n * fail every later request. Its type is read from its bytes, since providers reject a declared type that differs. An\n * image the processor cannot prepare, or fails on, is left out with a note.\n */\nexport async function fitImage(\n\tbytes: Uint8Array,\n\tmimeType: string,\n\tlimits: ImageLimits,\n\tprocessor: ImageProcessor,\n): Promise<FittedImage> {\n\tlet prepared: PreparedImage | undefined;\n\ttry {\n\t\tprepared = await processor.prepare(bytes, detectSupportedImageMimeType(bytes) ?? mimeType, limits);\n\t} catch (error) {\n\t\t// The image is known to need preparing: keeping it would commit what the provider rejects. The note carries the\n\t\t// failure into the transcript.\n\t\treturn omitted(mimeType, `: ${errorMessage(error)}`);\n\t}\n\tif (prepared === undefined) return omitted(mimeType, \"\");\n\tconst image: ImageContent = { type: \"image\", data: prepared.data, mimeType: prepared.mimeType };\n\treturn { kind: \"fitted\", image, notes: preparedNotes(prepared) };\n}\n\nfunction omitted(mimeType: string, reason: string): FittedImage {\n\treturn {\n\t\tkind: \"omitted\",\n\t\tnote: `An image (${mimeType}) cannot be prepared for the model and was left out${reason}.`,\n\t};\n}\n\n/**\n * `content` with each image fitted by `fitImage` (malformed base64 is left out as an image that cannot be prepared);\n * text stays where it is. `unchanged` when every image came back as it was.\n */\nexport async function fitImages(\n\tcontent: readonly (TextContent | ImageContent)[],\n\tlimits: ImageLimits,\n\tprocessor: ImageProcessor,\n): Promise<FittedImages> {\n\tconst fitted: (TextContent | ImageContent)[] = [];\n\tconst notes: string[] = [];\n\tlet changed = false;\n\tfor (const item of content) {\n\t\tif (item.type !== \"image\") {\n\t\t\tfitted.push(item);\n\t\t\tcontinue;\n\t\t}\n\t\tconst result = await fitBase64(item, limits, processor);\n\t\tif (result.kind === \"omitted\") {\n\t\t\tchanged = true;\n\t\t\tnotes.push(result.note);\n\t\t} else if (result.image.data === item.data && result.image.mimeType === item.mimeType) {\n\t\t\tfitted.push(item);\n\t\t} else {\n\t\t\tchanged = true;\n\t\t\tfitted.push(result.image);\n\t\t\tnotes.push(...result.notes);\n\t\t}\n\t}\n\treturn changed ? { kind: \"fitted\", content: fitted, notes } : { kind: \"unchanged\" };\n}\n\nasync function fitBase64(image: ImageContent, limits: ImageLimits, processor: ImageProcessor): Promise<FittedImage> {\n\tlet bytes: Uint8Array;\n\ttry {\n\t\tbytes = fromBase64(image.data);\n\t} catch (error) {\n\t\t// Wire input: a tool's base64 may be malformed.\n\t\treturn omitted(image.mimeType, `: ${errorMessage(error)}`);\n\t}\n\treturn fitImage(bytes, image.mimeType, limits, processor);\n}\n\n/**\n * The `fit-images` extension: an `afterTool` hook that fits the images of every result the model gets to the\n * conversation model's current limits (`fitImages`) before it is committed, whichever tool made them (an MCP tool, code\n * mode's `image()`), and says what changed in an `info` diagnostic (code `image`). Hooks of extensions installed before\n * it see the images unfitted. Nested calls' results are left as they are: the program that made the call gets them, not\n * the model.\n */\nexport function createFitImagesExtension(processor: ImageProcessor): Extension {\n\treturn defineExtension({\n\t\tname: \"fit-images\",\n\t\thooks: [\n\t\t\thook(ToolTask, {\n\t\t\t\tafterTool: (call, result, api, context) => fitResult(call, result, processor, api, context),\n\t\t\t}),\n\t\t],\n\t});\n}\n\nasync function fitResult(\n\tcall: ToolHookCall,\n\tresult: ToolExecutionResult,\n\tprocessor: ImageProcessor,\n\tapi: HookApi,\n\tcontext: Context,\n): Promise<ToolExecutionResult | undefined> {\n\tif (call.parent !== undefined || !result.output?.some((item) => item.type === \"image\")) return undefined;\n\tconst ref = (await api.snapshot(AgentDoc, api.conversationId, context))?.model;\n\tconst model = ref === undefined ? undefined : api.models.getModel(ref.provider, ref.modelId);\n\tconst fitted = await fitImages(result.output, imageLimits(model), processor);\n\tif (fitted.kind === \"unchanged\") return undefined;\n\tif (fitted.notes.length === 0) return { ...result, output: fitted.content };\n\tconst note = { severity: \"info\", code: \"image\", message: fitted.notes.join(\" \") } as const;\n\treturn { ...result, output: fitted.content, diagnostics: [...(result.diagnostics ?? []), note] };\n}\n"]}
@@ -0,0 +1,18 @@
1
+ import { type SyncInitInput } from "@silvia-odwyer/photon/photon_rs.js";
2
+ import type { ImageProcessor } from "../tools/image-processor.ts";
3
+ /**
4
+ * An `ImageProcessor` on Photon (Rust compiled to WebAssembly), for `createCodingTools({ images })`. `wasm` is
5
+ * Photon's `photon_rs_bg.wasm` as bytes or as a compiled module: `@diffra-ai/durable/images/node` reads it from
6
+ * the installed package, `@diffra-ai/durable/images/cloudflare` imports it as a Workers module. Elsewhere, such
7
+ * as a browser, fetch the file and pass its bytes. Photon loads once per process; later calls reuse the first `wasm`.
8
+ *
9
+ * An image already upright, in a format providers take inline, and within the limits is returned as it is, once it
10
+ * decodes. Otherwise it is turned upright by its EXIF orientation, scaled to the
11
+ * maximum width and height, and encoded as PNG or JPEG at falling qualities (JPEG first for JPEG sources), then at
12
+ * smaller dimensions, 3/4 at a time, until the base64 fits. Formats providers do not take inline (BMP) become PNG.
13
+ *
14
+ * The work runs on the calling thread: about a second and a half for a 12-megapixel photo. Decoding takes the image's
15
+ * RGBA size in WebAssembly memory, which does not shrink again; leave the processor out on memory-constrained hosts.
16
+ */
17
+ export declare function createPhotonImages(wasm: SyncInitInput): ImageProcessor;
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/images/index.ts"],"names":[],"mappings":"AACA,OAAO,EAON,KAAK,aAAa,EAClB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,EAAe,cAAc,EAAiB,MAAM,6BAA6B,CAAC;AAO9F;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,aAAa,GAAG,cAAc,CAGtE"}
@@ -0,0 +1,125 @@
1
+ // The package declares only `module`, which bundlers use but Node does not: import the file itself.
2
+ import { fliph, flipv, initSync, PhotonImage, resize, SamplingFilter, } from "@silvia-odwyer/photon/photon_rs.js";
3
+ import { base64Length, INLINE_IMAGE_TYPES, toBase64 } from "../tools/image-processor.js";
4
+ import { exifOrientation } from "./exif.js";
5
+ /** JPEG qualities tried in order. */
6
+ const JPEG_QUALITIES = [80, 70, 55, 40];
7
+ /**
8
+ * An `ImageProcessor` on Photon (Rust compiled to WebAssembly), for `createCodingTools({ images })`. `wasm` is
9
+ * Photon's `photon_rs_bg.wasm` as bytes or as a compiled module: `@diffra-ai/durable/images/node` reads it from
10
+ * the installed package, `@diffra-ai/durable/images/cloudflare` imports it as a Workers module. Elsewhere, such
11
+ * as a browser, fetch the file and pass its bytes. Photon loads once per process; later calls reuse the first `wasm`.
12
+ *
13
+ * An image already upright, in a format providers take inline, and within the limits is returned as it is, once it
14
+ * decodes. Otherwise it is turned upright by its EXIF orientation, scaled to the
15
+ * maximum width and height, and encoded as PNG or JPEG at falling qualities (JPEG first for JPEG sources), then at
16
+ * smaller dimensions, 3/4 at a time, until the base64 fits. Formats providers do not take inline (BMP) become PNG.
17
+ *
18
+ * The work runs on the calling thread: about a second and a half for a 12-megapixel photo. Decoding takes the image's
19
+ * RGBA size in WebAssembly memory, which does not shrink again; leave the processor out on memory-constrained hosts.
20
+ */
21
+ export function createPhotonImages(wasm) {
22
+ initSync({ module: wasm });
23
+ return { prepare: async (bytes, mimeType, limits) => prepare(bytes, mimeType, limits) };
24
+ }
25
+ function prepare(bytes, mimeType, limits) {
26
+ const orientation = exifOrientation(bytes);
27
+ const inline = INLINE_IMAGE_TYPES.has(mimeType);
28
+ let image;
29
+ try {
30
+ // Decoded even when it is returned as it is: a damaged file is an error, not an image the provider rejects.
31
+ image = PhotonImage.new_from_byteslice(bytes);
32
+ if (inline &&
33
+ orientation === 1 &&
34
+ image.get_width() <= limits.maxWidth &&
35
+ image.get_height() <= limits.maxHeight &&
36
+ base64Length(bytes.byteLength) <= limits.maxBytes) {
37
+ return { data: toBase64(bytes), mimeType };
38
+ }
39
+ if (orientation >= 5) {
40
+ const upright = transposed(image, orientation);
41
+ // Freed first, so the upright copy reuses its WebAssembly memory.
42
+ image.free();
43
+ image = undefined;
44
+ image = new PhotonImage(upright.pixels, upright.width, upright.height);
45
+ }
46
+ else if (orientation !== 1) {
47
+ if (orientation !== 4)
48
+ fliph(image);
49
+ if (orientation !== 2)
50
+ flipv(image);
51
+ }
52
+ const width = image.get_width();
53
+ const height = image.get_height();
54
+ const scale = Math.min(1, limits.maxWidth / width, limits.maxHeight / height);
55
+ let target = { width: Math.max(1, Math.round(width * scale)), height: Math.max(1, Math.round(height * scale)) };
56
+ for (;;) {
57
+ const encoded = encodeWithin(image, target, limits.maxBytes, mimeType === "image/jpeg");
58
+ if (encoded !== undefined) {
59
+ const resized = target.width === width && target.height === height
60
+ ? {}
61
+ : { resized: { from: { width, height }, to: target } };
62
+ const converted = encoded.mimeType === mimeType ? {} : { convertedFrom: mimeType };
63
+ return { ...encoded, ...converted, ...resized };
64
+ }
65
+ if (target.width === 1 && target.height === 1)
66
+ return undefined;
67
+ target = {
68
+ width: Math.max(1, Math.floor(target.width * 0.75)),
69
+ height: Math.max(1, Math.floor(target.height * 0.75)),
70
+ };
71
+ }
72
+ }
73
+ catch {
74
+ // Photon throws for bytes it cannot decode.
75
+ return undefined;
76
+ }
77
+ finally {
78
+ image?.free();
79
+ }
80
+ }
81
+ /**
82
+ * `image` at `size` in the first encoding whose base64 fits `maxBytes`: PNG, then JPEG at falling qualities, or the
83
+ * JPEG qualities first when `jpegFirst`; `undefined` if none fits.
84
+ */
85
+ function encodeWithin(image, size, maxBytes, jpegFirst) {
86
+ const same = size.width === image.get_width() && size.height === image.get_height();
87
+ const scaled = same ? image : resize(image, size.width, size.height, SamplingFilter.Lanczos3);
88
+ try {
89
+ const png = { mimeType: "image/png", encode: () => scaled.get_bytes() };
90
+ const jpegs = JPEG_QUALITIES.map((quality) => ({
91
+ mimeType: "image/jpeg",
92
+ encode: () => scaled.get_bytes_jpeg(quality),
93
+ }));
94
+ for (const candidate of jpegFirst ? [...jpegs, png] : [png, ...jpegs]) {
95
+ const bytes = candidate.encode();
96
+ if (base64Length(bytes.byteLength) <= maxBytes)
97
+ return { data: toBase64(bytes), mimeType: candidate.mimeType };
98
+ }
99
+ return undefined;
100
+ }
101
+ finally {
102
+ if (!same)
103
+ scaled.free();
104
+ }
105
+ }
106
+ /**
107
+ * The RGBA pixels of `image` turned upright for EXIF `orientation` 5 to 8, the orientations that swap width and
108
+ * height. Photon's own `rotate` drops pixels at right angles, so the pixels are moved here.
109
+ */
110
+ function transposed(image, orientation) {
111
+ const width = image.get_width();
112
+ const height = image.get_height();
113
+ const source = image.get_raw_pixels();
114
+ const pixels = new Uint8Array(source.length);
115
+ for (let y = 0; y < height; y++) {
116
+ for (let x = 0; x < width; x++) {
117
+ // Where (x, y) lands in the upright image, which is `height` wide.
118
+ const outX = orientation === 5 || orientation === 8 ? y : height - 1 - y;
119
+ const outY = orientation === 5 || orientation === 6 ? x : width - 1 - x;
120
+ pixels.set(source.subarray((y * width + x) * 4, (y * width + x) * 4 + 4), (outY * height + outX) * 4);
121
+ }
122
+ }
123
+ return { pixels, width: height, height: width };
124
+ }
125
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/images/index.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,OAAO,EACN,KAAK,EACL,KAAK,EACL,Q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AAC,MAAM,CAAC,CAAC;IAC7C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACjC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;YAChC,mEAAmE;YACnE,MAAM,IAAI,GAAG,WAAW,KAAK,CAAC,IAAI,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC;YACzE,MAAM,IAAI,GAAG,WAAW,KAAK,CAAC,IAAI,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC;YACxE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,IAAI,GAAG,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QACvG,CAAC;IACF,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;AACjD,CAAC","sourcesContent":["// The package declares only `module`, which bundlers use but Node does not: import the file itself.\nimport {\n\tfliph,\n\tflipv,\n\tinitSync,\n\tPhotonImage,\n\tresize,\n\tSamplingFilter,\n\ttype SyncInitInput,\n} from \"@silvia-odwyer/photon/photon_rs.js\";\nimport type { ImageLimits, ImageProcessor, PreparedImage } from \"../tools/image-processor.ts\";\nimport { base64Length, INLINE_IMAGE_TYPES, toBase64 } from \"../tools/image-processor.ts\";\nimport { exifOrientation } from \"./exif.ts\";\n\n/** JPEG qualities tried in order. */\nconst JPEG_QUALITIES = [80, 70, 55, 40];\n\n/**\n * An `ImageProcessor` on Photon (Rust compiled to WebAssembly), for `createCodingTools({ images })`. `wasm` is\n * Photon's `photon_rs_bg.wasm` as bytes or as a compiled module: `@diffra-ai/durable/images/node` reads it from\n * the installed package, `@diffra-ai/durable/images/cloudflare` imports it as a Workers module. Elsewhere, such\n * as a browser, fetch the file and pass its bytes. Photon loads once per process; later calls reuse the first `wasm`.\n *\n * An image already upright, in a format providers take inline, and within the limits is returned as it is, once it\n * decodes. Otherwise it is turned upright by its EXIF orientation, scaled to the\n * maximum width and height, and encoded as PNG or JPEG at falling qualities (JPEG first for JPEG sources), then at\n * smaller dimensions, 3/4 at a time, until the base64 fits. Formats providers do not take inline (BMP) become PNG.\n *\n * The work runs on the calling thread: about a second and a half for a 12-megapixel photo. Decoding takes the image's\n * RGBA size in WebAssembly memory, which does not shrink again; leave the processor out on memory-constrained hosts.\n */\nexport function createPhotonImages(wasm: SyncInitInput): ImageProcessor {\n\tinitSync({ module: wasm });\n\treturn { prepare: async (bytes, mimeType, limits) => prepare(bytes, mimeType, limits) };\n}\n\nfunction prepare(bytes: Uint8Array, mimeType: string, limits: ImageLimits): PreparedImage | undefined {\n\tconst orientation = exifOrientation(bytes);\n\tconst inline = INLINE_IMAGE_TYPES.has(mimeType);\n\tlet image: PhotonImage | undefined;\n\ttry {\n\t\t// Decoded even when it is returned as it is: a damaged file is an error, not an image the provider rejects.\n\t\timage = PhotonImage.new_from_byteslice(bytes);\n\t\tif (\n\t\t\tinline &&\n\t\t\torientation === 1 &&\n\t\t\timage.get_width() <= limits.maxWidth &&\n\t\t\timage.get_height() <= limits.maxHeight &&\n\t\t\tbase64Length(bytes.byteLength) <= limits.maxBytes\n\t\t) {\n\t\t\treturn { data: toBase64(bytes), mimeType };\n\t\t}\n\t\tif (orientation >= 5) {\n\t\t\tconst upright = transposed(image, orientation);\n\t\t\t// Freed first, so the upright copy reuses its WebAssembly memory.\n\t\t\timage.free();\n\t\t\timage = undefined;\n\t\t\timage = new PhotonImage(upright.pixels, upright.width, upright.height);\n\t\t} else if (orientation !== 1) {\n\t\t\tif (orientation !== 4) fliph(image);\n\t\t\tif (orientation !== 2) flipv(image);\n\t\t}\n\t\tconst width = image.get_width();\n\t\tconst height = image.get_height();\n\t\tconst scale = Math.min(1, limits.maxWidth / width, limits.maxHeight / height);\n\t\tlet target = { width: Math.max(1, Math.round(width * scale)), height: Math.max(1, Math.round(height * scale)) };\n\t\tfor (;;) {\n\t\t\tconst encoded = encodeWithin(image, target, limits.maxBytes, mimeType === \"image/jpeg\");\n\t\t\tif (encoded !== undefined) {\n\t\t\t\tconst resized =\n\t\t\t\t\ttarget.width === width && target.height === height\n\t\t\t\t\t\t? {}\n\t\t\t\t\t\t: { resized: { from: { width, height }, to: target } };\n\t\t\t\tconst converted = encoded.mimeType === mimeType ? {} : { convertedFrom: mimeType };\n\t\t\t\treturn { ...encoded, ...converted, ...resized };\n\t\t\t}\n\t\t\tif (target.width === 1 && target.height === 1) return undefined;\n\t\t\ttarget = {\n\t\t\t\twidth: Math.max(1, Math.floor(target.width * 0.75)),\n\t\t\t\theight: Math.max(1, Math.floor(target.height * 0.75)),\n\t\t\t};\n\t\t}\n\t} catch {\n\t\t// Photon throws for bytes it cannot decode.\n\t\treturn undefined;\n\t} finally {\n\t\timage?.free();\n\t}\n}\n\n/**\n * `image` at `size` in the first encoding whose base64 fits `maxBytes`: PNG, then JPEG at falling qualities, or the\n * JPEG qualities first when `jpegFirst`; `undefined` if none fits.\n */\nfunction encodeWithin(\n\timage: PhotonImage,\n\tsize: { readonly width: number; readonly height: number },\n\tmaxBytes: number,\n\tjpegFirst: boolean,\n): { readonly data: string; readonly mimeType: string } | undefined {\n\tconst same = size.width === image.get_width() && size.height === image.get_height();\n\tconst scaled = same ? image : resize(image, size.width, size.height, SamplingFilter.Lanczos3);\n\ttry {\n\t\tconst png = { mimeType: \"image/png\", encode: () => scaled.get_bytes() };\n\t\tconst jpegs = JPEG_QUALITIES.map((quality) => ({\n\t\t\tmimeType: \"image/jpeg\",\n\t\t\tencode: () => scaled.get_bytes_jpeg(quality),\n\t\t}));\n\t\tfor (const candidate of jpegFirst ? [...jpegs, png] : [png, ...jpegs]) {\n\t\t\tconst bytes = candidate.encode();\n\t\t\tif (base64Length(bytes.byteLength) <= maxBytes) return { data: toBase64(bytes), mimeType: candidate.mimeType };\n\t\t}\n\t\treturn undefined;\n\t} finally {\n\t\tif (!same) scaled.free();\n\t}\n}\n\n/**\n * The RGBA pixels of `image` turned upright for EXIF `orientation` 5 to 8, the orientations that swap width and\n * height. Photon's own `rotate` drops pixels at right angles, so the pixels are moved here.\n */\nfunction transposed(\n\timage: PhotonImage,\n\torientation: number,\n): { readonly pixels: Uint8Array; readonly width: number; readonly height: number } {\n\tconst width = image.get_width();\n\tconst height = image.get_height();\n\tconst source = image.get_raw_pixels();\n\tconst pixels = new Uint8Array(source.length);\n\tfor (let y = 0; y < height; y++) {\n\t\tfor (let x = 0; x < width; x++) {\n\t\t\t// Where (x, y) lands in the upright image, which is `height` wide.\n\t\t\tconst outX = orientation === 5 || orientation === 8 ? y : height - 1 - y;\n\t\t\tconst outY = orientation === 5 || orientation === 6 ? x : width - 1 - x;\n\t\t\tpixels.set(source.subarray((y * width + x) * 4, (y * width + x) * 4 + 4), (outY * height + outX) * 4);\n\t\t}\n\t}\n\treturn { pixels, width: height, height: width };\n}\n"]}
@@ -0,0 +1,19 @@
1
+ import type { ImageLimits, PreparedImage } from "../tools/image-processor.ts";
2
+ /** One request: the image to prepare, and its ID for the reply. */
3
+ export type PrepareRequest = {
4
+ readonly id: number;
5
+ readonly bytes: Uint8Array;
6
+ readonly mimeType: string;
7
+ readonly limits: ImageLimits;
8
+ };
9
+ /** The reply to a request: its result, or why it failed. */
10
+ export type PrepareReply = {
11
+ readonly kind: "prepared";
12
+ readonly id: number;
13
+ readonly result: PreparedImage | undefined;
14
+ } | {
15
+ readonly kind: "failed";
16
+ readonly id: number;
17
+ readonly error: string;
18
+ };
19
+ //# sourceMappingURL=node-worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-worker.d.ts","sourceRoot":"","sources":["../../src/images/node-worker.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAG9E,mEAAmE;AACnE,MAAM,MAAM,cAAc,GAAG;IAC5B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;CAC7B,CAAC;AAEF,4DAA4D;AAC5D,MAAM,MAAM,YAAY,GACrB;IAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,aAAa,GAAG,SAAS,CAAA;CAAE,GAC9F;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC"}
@@ -0,0 +1,17 @@
1
+ // The worker thread of `createNodePhotonImages()`: Photon prepares images here, off the caller's event loop.
2
+ import { readFileSync } from "node:fs";
3
+ import { createRequire } from "node:module";
4
+ import { parentPort } from "node:worker_threads";
5
+ import { createPhotonImages } from "./index.js";
6
+ const port = parentPort;
7
+ if (port === null)
8
+ throw new Error("The Photon image worker needs a parent thread");
9
+ const images = createPhotonImages(readFileSync(createRequire(import.meta.url).resolve("@silvia-odwyer/photon/photon_rs_bg.wasm")));
10
+ port.on("message", (request) => {
11
+ void images.prepare(request.bytes, request.mimeType, request.limits).then((result) => port.postMessage({ kind: "prepared", id: request.id, result }), (error) => port.postMessage({
12
+ kind: "failed",
13
+ id: request.id,
14
+ error: error instanceof Error ? error.message : String(error),
15
+ }));
16
+ });
17
+ //# sourceMappingURL=node-worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-worker.js","sourceRoot":"","sources":["../../src/images/node-worker.ts"],"names":[],"mappings":"AAAA,6GAA6G;AAC7G,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAehD,MAAM,IAAI,GAAG,UAAU,CAAC;AACxB,IAAI,IAAI,KAAK,IAAI;IAAE,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;AACpF,MAAM,MAAM,GAAG,kBAAkB,CAChC,YAAY,CAAC,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,yCAAyC,CAAC,CAAC,CAC/F,CAAC;AACF,IAAI,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,OAAuB,EAAE,EAAE;IAC9C,KAAK,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,CACxE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE,EAAE,MAAM,EAAyB,CAAC,EACjG,CAAC,KAAc,EAAE,EAAE,CAClB,IAAI,CAAC,WAAW,CAAC;QAChB,IAAI,EAAE,QAAQ;QACd,EAAE,EAAE,OAAO,CAAC,EAAE;QACd,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;KACtC,CAAC,CAC1B,CAAC;AACH,CAAC,CAAC,CAAC","sourcesContent":["// The worker thread of `createNodePhotonImages()`: Photon prepares images here, off the caller's event loop.\nimport { readFileSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { parentPort } from \"node:worker_threads\";\nimport type { ImageLimits, PreparedImage } from \"../tools/image-processor.ts\";\nimport { createPhotonImages } from \"./index.ts\";\n\n/** One request: the image to prepare, and its ID for the reply. */\nexport type PrepareRequest = {\n\treadonly id: number;\n\treadonly bytes: Uint8Array;\n\treadonly mimeType: string;\n\treadonly limits: ImageLimits;\n};\n\n/** The reply to a request: its result, or why it failed. */\nexport type PrepareReply =\n\t| { readonly kind: \"prepared\"; readonly id: number; readonly result: PreparedImage | undefined }\n\t| { readonly kind: \"failed\"; readonly id: number; readonly error: string };\n\nconst port = parentPort;\nif (port === null) throw new Error(\"The Photon image worker needs a parent thread\");\nconst images = createPhotonImages(\n\treadFileSync(createRequire(import.meta.url).resolve(\"@silvia-odwyer/photon/photon_rs_bg.wasm\")),\n);\nport.on(\"message\", (request: PrepareRequest) => {\n\tvoid images.prepare(request.bytes, request.mimeType, request.limits).then(\n\t\t(result) => port.postMessage({ kind: \"prepared\", id: request.id, result } satisfies PrepareReply),\n\t\t(error: unknown) =>\n\t\t\tport.postMessage({\n\t\t\t\tkind: \"failed\",\n\t\t\t\tid: request.id,\n\t\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\t} satisfies PrepareReply),\n\t);\n});\n"]}
@@ -0,0 +1,21 @@
1
+ import type { ImageProcessor } from "../tools/image-processor.ts";
2
+ export type NodePhotonImagesOptions = {
3
+ /**
4
+ * Prepare images in a worker thread, so a large photo does not block the event loop for the second or two Photon
5
+ * takes. Default `true`; `false` prepares them on the calling thread.
6
+ */
7
+ readonly worker?: boolean;
8
+ /**
9
+ * How long the worker stays after its last image before it exits, freeing Photon's WebAssembly memory, which never
10
+ * shrinks while it lives. The next image starts a new one. Default 30 s.
11
+ */
12
+ readonly idleMs?: number;
13
+ };
14
+ /**
15
+ * `createPhotonImages()` for Node and Bun, with Photon's WebAssembly read from the installed `@silvia-odwyer/photon`,
16
+ * by default in a worker thread that keeps the process alive only while it prepares an image. A worker that cannot
17
+ * start falls back to the calling thread. A single-file binary cannot resolve the package: read its own copy of
18
+ * `photon_rs_bg.wasm` and call `createPhotonImages()`.
19
+ */
20
+ export declare function createNodePhotonImages(options?: NodePhotonImagesOptions): Promise<ImageProcessor>;
21
+ //# sourceMappingURL=node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/images/node.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAe,cAAc,EAAiB,MAAM,6BAA6B,CAAC;AAI9F,MAAM,MAAM,uBAAuB,GAAG;IACrC;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAAC,OAAO,GAAE,uBAA4B,GAAG,OAAO,CAAC,cAAc,CAAC,CAqB3G"}
@@ -0,0 +1,121 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { createRequire } from "node:module";
3
+ import { Worker } from "node:worker_threads";
4
+ import { createPhotonImages } from "./index.js";
5
+ /**
6
+ * `createPhotonImages()` for Node and Bun, with Photon's WebAssembly read from the installed `@silvia-odwyer/photon`,
7
+ * by default in a worker thread that keeps the process alive only while it prepares an image. A worker that cannot
8
+ * start falls back to the calling thread. A single-file binary cannot resolve the package: read its own copy of
9
+ * `photon_rs_bg.wasm` and call `createPhotonImages()`.
10
+ */
11
+ export async function createNodePhotonImages(options = {}) {
12
+ if (options.worker === false)
13
+ return inProcess();
14
+ const idleMs = options.idleMs ?? 30_000;
15
+ let thread;
16
+ let fallback;
17
+ return {
18
+ async prepare(bytes, mimeType, limits) {
19
+ if (fallback !== undefined)
20
+ return (await fallback).prepare(bytes, mimeType, limits);
21
+ try {
22
+ thread ??= new PhotonThread(idleMs, () => {
23
+ thread = undefined;
24
+ });
25
+ return await thread.prepare(bytes, mimeType, limits);
26
+ }
27
+ catch (error) {
28
+ if (!(error instanceof WorkerUnavailable))
29
+ throw error;
30
+ // No worker on this platform or build: prepare here from now on.
31
+ fallback = inProcess();
32
+ return (await fallback).prepare(bytes, mimeType, limits);
33
+ }
34
+ },
35
+ };
36
+ }
37
+ async function inProcess() {
38
+ const path = createRequire(import.meta.url).resolve("@silvia-odwyer/photon/photon_rs_bg.wasm");
39
+ return createPhotonImages(await readFile(path));
40
+ }
41
+ /** The worker could not start, as opposed to failing on one image. */
42
+ class WorkerUnavailable extends Error {
43
+ }
44
+ /** One worker thread and the requests it has not answered; it exits after `idleMs` without requests. */
45
+ class PhotonThread {
46
+ #worker;
47
+ #pending = new Map();
48
+ #idleMs;
49
+ #onExit;
50
+ #nextId = 0;
51
+ #idle;
52
+ /** Whether the worker answered once: a failure before that means it is unavailable. */
53
+ #started = false;
54
+ constructor(idleMs, onExit) {
55
+ this.#idleMs = idleMs;
56
+ this.#onExit = onExit;
57
+ // Run from source under a TypeScript runtime, as in tests; built, the worker sits next to this file as JS.
58
+ const file = import.meta.url.endsWith(".ts") ? "./node-worker.ts" : "./node-worker.js";
59
+ try {
60
+ this.#worker = new Worker(new URL(file, import.meta.url));
61
+ }
62
+ catch (error) {
63
+ throw new WorkerUnavailable("The Photon image worker cannot start", { cause: error });
64
+ }
65
+ this.#worker.unref();
66
+ this.#worker.on("message", (reply) => {
67
+ this.#started = true;
68
+ const request = this.#pending.get(reply.id);
69
+ if (request === undefined)
70
+ return;
71
+ this.#pending.delete(reply.id);
72
+ if (reply.kind === "failed")
73
+ request.reject(new Error(reply.error));
74
+ else
75
+ request.resolve(reply.result);
76
+ this.#settled();
77
+ });
78
+ const fail = (error) => {
79
+ const failure = this.#started
80
+ ? error
81
+ : new WorkerUnavailable("The Photon image worker cannot start", { cause: error });
82
+ for (const request of this.#pending.values())
83
+ request.reject(failure);
84
+ this.#pending.clear();
85
+ this.#exit();
86
+ };
87
+ this.#worker.on("error", fail);
88
+ this.#worker.on("exit", (code) => fail(new Error(`The Photon image worker exited with code ${code}`)));
89
+ }
90
+ prepare(bytes, mimeType, limits) {
91
+ const id = this.#nextId++;
92
+ const request = Promise.withResolvers();
93
+ this.#pending.set(id, request);
94
+ if (this.#idle !== undefined)
95
+ clearTimeout(this.#idle);
96
+ this.#idle = undefined;
97
+ // A pending image keeps the process alive, as one prepared on the calling thread would.
98
+ this.#worker.ref();
99
+ // A copy, transferred: the caller keeps its bytes.
100
+ const copy = bytes.slice();
101
+ this.#worker.postMessage({ id, bytes: copy, mimeType, limits }, [copy.buffer]);
102
+ return request.promise;
103
+ }
104
+ #settled() {
105
+ if (this.#pending.size > 0)
106
+ return;
107
+ this.#worker.unref();
108
+ this.#idle = setTimeout(() => {
109
+ this.#exit();
110
+ void this.#worker.terminate();
111
+ }, this.#idleMs);
112
+ this.#idle.unref();
113
+ }
114
+ #exit() {
115
+ if (this.#idle !== undefined)
116
+ clearTimeout(this.#idle);
117
+ this.#idle = undefined;
118
+ this.#onExit();
119
+ }
120
+ }
121
+ //# sourceMappingURL=node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.js","sourceRoot":"","sources":["../../src/images/node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAgBhD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,OAAO,GAA4B,EAAE;IACjF,IAAI,OAAO,CAAC,MAAM,KAAK,KAAK;QAAE,OAAO,SAAS,EAAE,CAAC;IACjD,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,MAAM,C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,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAA2B,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;QACxG,OAAO,OAAO,CAAC,OAAO,CAAC;IACxB,CAAC;IAED,QAAQ;QACP,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,GAAG,CAAC;YAAE,OAAO;QACnC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YAC5B,IAAI,CAAC,KAAK,EAAE,CAAC;YACb,KAAK,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;QAC/B,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACjB,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC;IAED,KAAK;QACJ,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS;YAAE,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACvD,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;QACvB,IAAI,CAAC,OAAO,EAAE,CAAC;IAChB,CAAC;CACD","sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport { createRequire } from \"node:module\";\nimport { Worker } from \"node:worker_threads\";\nimport type { ImageLimits, ImageProcessor, PreparedImage } from \"../tools/image-processor.ts\";\nimport { createPhotonImages } from \"./index.ts\";\nimport type { PrepareReply, PrepareRequest } from \"./node-worker.ts\";\n\nexport type NodePhotonImagesOptions = {\n\t/**\n\t * Prepare images in a worker thread, so a large photo does not block the event loop for the second or two Photon\n\t * takes. Default `true`; `false` prepares them on the calling thread.\n\t */\n\treadonly worker?: boolean;\n\t/**\n\t * How long the worker stays after its last image before it exits, freeing Photon's WebAssembly memory, which never\n\t * shrinks while it lives. The next image starts a new one. Default 30 s.\n\t */\n\treadonly idleMs?: number;\n};\n\n/**\n * `createPhotonImages()` for Node and Bun, with Photon's WebAssembly read from the installed `@silvia-odwyer/photon`,\n * by default in a worker thread that keeps the process alive only while it prepares an image. A worker that cannot\n * start falls back to the calling thread. A single-file binary cannot resolve the package: read its own copy of\n * `photon_rs_bg.wasm` and call `createPhotonImages()`.\n */\nexport async function createNodePhotonImages(options: NodePhotonImagesOptions = {}): Promise<ImageProcessor> {\n\tif (options.worker === false) return inProcess();\n\tconst idleMs = options.idleMs ?? 30_000;\n\tlet thread: PhotonThread | undefined;\n\tlet fallback: Promise<ImageProcessor> | undefined;\n\treturn {\n\t\tasync prepare(bytes, mimeType, limits) {\n\t\t\tif (fallback !== undefined) return (await fallback).prepare(bytes, mimeType, limits);\n\t\t\ttry {\n\t\t\t\tthread ??= new PhotonThread(idleMs, () => {\n\t\t\t\t\tthread = undefined;\n\t\t\t\t});\n\t\t\t\treturn await thread.prepare(bytes, mimeType, limits);\n\t\t\t} catch (error) {\n\t\t\t\tif (!(error instanceof WorkerUnavailable)) throw error;\n\t\t\t\t// No worker on this platform or build: prepare here from now on.\n\t\t\t\tfallback = inProcess();\n\t\t\t\treturn (await fallback).prepare(bytes, mimeType, limits);\n\t\t\t}\n\t\t},\n\t};\n}\n\nasync function inProcess(): Promise<ImageProcessor> {\n\tconst path = createRequire(import.meta.url).resolve(\"@silvia-odwyer/photon/photon_rs_bg.wasm\");\n\treturn createPhotonImages(await readFile(path));\n}\n\n/** The worker could not start, as opposed to failing on one image. */\nclass WorkerUnavailable extends Error {}\n\n/** One worker thread and the requests it has not answered; it exits after `idleMs` without requests. */\nclass PhotonThread {\n\treadonly #worker: Worker;\n\treadonly #pending = new Map<number, PromiseWithResolvers<PreparedImage | undefined>>();\n\treadonly #idleMs: number;\n\treadonly #onExit: () => void;\n\t#nextId = 0;\n\t#idle: ReturnType<typeof setTimeout> | undefined;\n\t/** Whether the worker answered once: a failure before that means it is unavailable. */\n\t#started = false;\n\n\tconstructor(idleMs: number, onExit: () => void) {\n\t\tthis.#idleMs = idleMs;\n\t\tthis.#onExit = onExit;\n\t\t// Run from source under a TypeScript runtime, as in tests; built, the worker sits next to this file as JS.\n\t\tconst file = import.meta.url.endsWith(\".ts\") ? \"./node-worker.ts\" : \"./node-worker.js\";\n\t\ttry {\n\t\t\tthis.#worker = new Worker(new URL(file, import.meta.url));\n\t\t} catch (error) {\n\t\t\tthrow new WorkerUnavailable(\"The Photon image worker cannot start\", { cause: error });\n\t\t}\n\t\tthis.#worker.unref();\n\t\tthis.#worker.on(\"message\", (reply: PrepareReply) => {\n\t\t\tthis.#started = true;\n\t\t\tconst request = this.#pending.get(reply.id);\n\t\t\tif (request === undefined) return;\n\t\t\tthis.#pending.delete(reply.id);\n\t\t\tif (reply.kind === \"failed\") request.reject(new Error(reply.error));\n\t\t\telse request.resolve(reply.result);\n\t\t\tthis.#settled();\n\t\t});\n\t\tconst fail = (error: unknown): void => {\n\t\t\tconst failure = this.#started\n\t\t\t\t? error\n\t\t\t\t: new WorkerUnavailable(\"The Photon image worker cannot start\", { cause: error });\n\t\t\tfor (const request of this.#pending.values()) request.reject(failure);\n\t\t\tthis.#pending.clear();\n\t\t\tthis.#exit();\n\t\t};\n\t\tthis.#worker.on(\"error\", fail);\n\t\tthis.#worker.on(\"exit\", (code) => fail(new Error(`The Photon image worker exited with code ${code}`)));\n\t}\n\n\tprepare(bytes: Uint8Array, mimeType: string, limits: ImageLimits): Promise<PreparedImage | undefined> {\n\t\tconst id = this.#nextId++;\n\t\tconst request = Promise.withResolvers<PreparedImage | undefined>();\n\t\tthis.#pending.set(id, request);\n\t\tif (this.#idle !== undefined) clearTimeout(this.#idle);\n\t\tthis.#idle = undefined;\n\t\t// A pending image keeps the process alive, as one prepared on the calling thread would.\n\t\tthis.#worker.ref();\n\t\t// A copy, transferred: the caller keeps its bytes.\n\t\tconst copy = bytes.slice();\n\t\tthis.#worker.postMessage({ id, bytes: copy, mimeType, limits } satisfies PrepareRequest, [copy.buffer]);\n\t\treturn request.promise;\n\t}\n\n\t#settled(): void {\n\t\tif (this.#pending.size > 0) return;\n\t\tthis.#worker.unref();\n\t\tthis.#idle = setTimeout(() => {\n\t\t\tthis.#exit();\n\t\t\tvoid this.#worker.terminate();\n\t\t}, this.#idleMs);\n\t\tthis.#idle.unref();\n\t}\n\n\t#exit(): void {\n\t\tif (this.#idle !== undefined) clearTimeout(this.#idle);\n\t\tthis.#idle = undefined;\n\t\tthis.#onExit();\n\t}\n}\n"]}
@@ -0,0 +1,29 @@
1
+ export type { NativeWatchCall, WatchCall, WatchEnd, WatchHandle } from "@diffra-ai/chord/watch";
2
+ export { defineDoc, defineDocFamily } from "./documents.ts";
3
+ export { AssistantEntry, CompactionEntry, defineEntry, ResetEntry, SystemEntry, ToolResultEntry, UserEntry, } from "./entries.ts";
4
+ export { ConversationBusy, ConversationIdle, ReadAfterWrite, ReadOnlySession, SessionFailed, StorageRequestError, } from "./errors.ts";
5
+ export { AgentDoc, configure, DEFAULT_COMPACTION_POLICY, DEFAULT_PROGRESS_POLICY, DEFAULT_RESTART_LIMIT, DEFAULT_RETRY_POLICY, } from "./harness/agent.ts";
6
+ export { type CompactionCheckpoint, type CompactionInput, CompactionTask, type SummaryRequest, } from "./harness/compaction.ts";
7
+ export { defineExtension, defineTool, hook, hookTask, section, wrapSection, wrapTool } from "./harness/define.ts";
8
+ export { type GenerationCheckpoint, type GenerationInput, type GenerationResult, GenerationTask, } from "./harness/generation.ts";
9
+ export { DEFAULT_HARNESS_IDENTITY, Harness } from "./harness/harness.ts";
10
+ export { InboxDoc, type InboxItem, type InboxState } from "./harness/inbox.ts";
11
+ export { type CompactionFailure, type CompactionStatus, LiveDoc, type LiveRun, type LiveState, type NestedToolSlot, type NestedToolSummary, type RunFailure, type RunFailureReason, type ToolSlot, } from "./harness/live.ts";
12
+ export { ProviderDoc, type ProviderState } from "./harness/provider.ts";
13
+ export { createRegistry } from "./harness/registry.ts";
14
+ export { registryReader } from "./harness/registry-reader.ts";
15
+ export type { BlockedReason } from "./harness/scheduler.ts";
16
+ export type { TaskGraph, TaskGraphNode, TaskGraphState, TaskGraphWatch } from "./harness/task-graph.ts";
17
+ export { DURABLE_TELEMETRY_SCHEMA } from "./harness/telemetry.ts";
18
+ export { NestedCallDoc, type NestedCallState, ToolTask, type ToolTaskCheckpoint, type ToolTaskInput, type ToolTaskResult, } from "./harness/tool.ts";
19
+ export { ConversationTranscript, type ConversationTranscriptOptions, type EntryLoader, type TranscriptItem, type TranscriptView, } from "./harness/transcript.ts";
20
+ export type { AfterFailedRun, AfterToolsDecision, Agent, AgentChange, AgentState, AnyTask, CompactionHooks, CompactionPolicy, CompactionReason, CompactionResult, CompactionSettings, ContextView, Conversation, ConversationAbortOptions, ConversationCreateOptions, ConversationHandle, ConversationInit, ConversationRetryPolicy, ConversationStreamOptions, ConversationWatch, EnvTarget, Extension, GenerationHooks, HarnessInspection, HarnessOptions, HarnessSettings, HookApi, HookRegistration, HookResult, HooksOf, HookTask, InputEntry, InputSubmissionDraft, ModelRef, NestedToolCall, NestedToolExecutionResult, ProgressPolicy, PromptInput, PromptSection, QueueMode, Registry, RegistryReader, RegistrySnapshot, RunSummary, Settings, SettledSubmissionRecord, SettledTask, Submission, SubmissionDraft, TaskInspection, ToolControl, ToolDiagnostic, ToolExecutionApi, ToolExecutionMode, ToolExecutionResult, ToolHookCall, ToolHooks, ToolNamespace, ToolPark, ToolRegistration, UserInput, Wake, Wrap, YieldDecision, } from "./harness/types.ts";
21
+ export { UsageDoc, type UsageState } from "./harness/usage.ts";
22
+ export type { ConversationView, ConversationWindow } from "./harness/view.ts";
23
+ export { createSession } from "./session/session.ts";
24
+ export { defineSignal, type SignalDefinition, type SignalKey, type SignalResult, type SignalState, type SignalToken, SubmissionSettled, } from "./signals.ts";
25
+ export { MemoryStorage } from "./storage/memory.ts";
26
+ export { defineTask } from "./tasks.ts";
27
+ export type { CheckpointInfo, CommitChange, CommitObservation, CommitObserver, CommitOptions, CommitPersistence, CommitPublication, CommitResult, CommonDocDefinition, ContextEdit, ConversationDocFamilyToken, ConversationDocToken, ConversationId, ConversationOwnership, ConversationQuery, ConversationRecord, Cursor, DocDefinition, DocFamilyDefinition, DocFamilyToken, DocToken, DocumentAddress, DocumentCommitChange, DocumentContent, DocumentCopySource, DocumentCreate, DocumentId, DocumentObserver, DocumentPoint, DocumentQuery, DocumentReader, DocumentRecord, DocumentSemantics, DocumentWatch, Entry, EntryDraft, EntryId, EntryQuery, EntryRecord, HookRunner, HostCallback, Id, JoinPolicy, JsonObject, LatestConversationSemantics, NextTaskState, Observation, Observer, Page, PhaseHandler, Report, ReportFrom, ReportInfo, ReportTask, RewindableConversationDocFamilyToken, RewindableConversationDocToken, RewindableConversationSemantics, RunningTask, ScanOrder, Seq, Session, SessionDocFamilyToken, SessionDocToken, SessionEnd, SetTimer, Storage, StorageWrite, StoredDocument, SubmissionCreate, SubmissionId, SubmissionNotify, SubmissionQuery, SubmissionRecord, SubmissionSettlement, TableCommitChange, Task, TaskDefinition, TaskDocFamilyToken, TaskDocToken, TaskId, TaskOptions, TaskOutcome, TaskOutcomeError, TaskOwnership, TaskQuery, TaskRecord, TaskRuntime, TaskState, Tx, TypedEntry, TypedEntryDraft, WakeReason, } from "./types.ts";
28
+ export { ROOT_CONVERSATION_ID } from "./types.ts";
29
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,eAAe,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAChG,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EACN,cAAc,EACd,eAAe,EACf,WAAW,EACX,UAAU,EACV,WAAW,EACX,eAAe,EACf,SAAS,GACT,MAAM,cAAc,CAAC;AACtB,OAAO,EACN,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,aAAa,EACb,mBAAmB,GACnB,MAAM,aAAa,CAA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ACZ,MAAM,EACN,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,aAAa,EACb,SAAS,EACT,UAAU,EACV,WAAW,EACX,SAAS,EACT,EAAE,EACF,UAAU,EACV,eAAe,EACf,UAAU,GACV,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,23 @@
1
+ export { defineDoc, defineDocFamily } from "./documents.js";
2
+ export { AssistantEntry, CompactionEntry, defineEntry, ResetEntry, SystemEntry, ToolResultEntry, UserEntry, } from "./entries.js";
3
+ export { ConversationBusy, ConversationIdle, ReadAfterWrite, ReadOnlySession, SessionFailed, StorageRequestError, } from "./errors.js";
4
+ export { AgentDoc, configure, DEFAULT_COMPACTION_POLICY, DEFAULT_PROGRESS_POLICY, DEFAULT_RESTART_LIMIT, DEFAULT_RETRY_POLICY, } from "./harness/agent.js";
5
+ export { CompactionTask, } from "./harness/compaction.js";
6
+ export { defineExtension, defineTool, hook, hookTask, section, wrapSection, wrapTool } from "./harness/define.js";
7
+ export { GenerationTask, } from "./harness/generation.js";
8
+ export { DEFAULT_HARNESS_IDENTITY, Harness } from "./harness/harness.js";
9
+ export { InboxDoc } from "./harness/inbox.js";
10
+ export { LiveDoc, } from "./harness/live.js";
11
+ export { ProviderDoc } from "./harness/provider.js";
12
+ export { createRegistry } from "./harness/registry.js";
13
+ export { registryReader } from "./harness/registry-reader.js";
14
+ export { DURABLE_TELEMETRY_SCHEMA } from "./harness/telemetry.js";
15
+ export { NestedCallDoc, ToolTask, } from "./harness/tool.js";
16
+ export { ConversationTranscript, } from "./harness/transcript.js";
17
+ export { UsageDoc } from "./harness/usage.js";
18
+ export { createSession } from "./session/session.js";
19
+ export { defineSignal, SubmissionSettled, } from "./signals.js";
20
+ export { MemoryStorage } from "./storage/memory.js";
21
+ export { defineTask } from "./tasks.js";
22
+ export { ROOT_CONVERSATION_ID } from "./types.js";
23
+ //# sourceMappingURL=index.js.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AAmB,MAAM,oBAAoB,CAAC;AAE/D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EACN,YAAY,EAMZ,iBAAiB,GACjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AA+FxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC","sourcesContent":["export type { NativeWatchCall, WatchCall, WatchEnd, WatchHandle } from \"@diffra-ai/chord/watch\";\nexport { defineDoc, defineDocFamily } from \"./documents.ts\";\nexport {\n\tAssistantEntry,\n\tCompactionEntry,\n\tdefineEntry,\n\tResetEntry,\n\tSystemEntry,\n\tToolResultEntry,\n\tUserEntry,\n} from \"./entries.ts\";\nexport {\n\tConversationBusy,\n\tConversationIdle,\n\tReadAfterWrite,\n\tReadOnlySession,\n\tSessionFailed,\n\tStorageRequestError,\n} from \"./errors.ts\";\nexport {\n\tAgentDoc,\n\tconfigure,\n\tDEFAULT_COMPACTION_POLICY,\n\tDEFAULT_PROGRESS_POLICY,\n\tDEFAULT_RESTART_LIMIT,\n\tDEFAULT_RETRY_POLICY,\n} from \"./harness/agent.ts\";\nexport {\n\ttype CompactionCheckpoint,\n\ttype CompactionInput,\n\tCompactionTask,\n\ttype SummaryRequest,\n} from \"./harness/compaction.ts\";\nexport { defineExtension, defineTool, hook, hookTask, section, wrapSection, wrapTool } from \"./harness/define.ts\";\nexport {\n\ttype GenerationCheckpoint,\n\ttype GenerationInput,\n\ttype GenerationResult,\n\tGenerationTask,\n} from \"./harness/generation.ts\";\nexport { DEFAULT_HARNESS_IDENTITY, Harness } from \"./harness/harness.ts\";\nexport { InboxDoc, type InboxItem, type InboxState } from \"./harness/inbox.ts\";\nexport {\n\ttype CompactionFailure,\n\ttype CompactionStatus,\n\tLiveDoc,\n\ttype LiveRun,\n\ttype LiveState,\n\ttype NestedToolSlot,\n\ttype NestedToolSummary,\n\ttype RunFailure,\n\ttype RunFailureReason,\n\ttype ToolSlot,\n} from \"./harness/live.ts\";\nexport { ProviderDoc, type ProviderState } from \"./harness/provider.ts\";\nexport { createRegistry } from \"./harness/registry.ts\";\nexport { registryReader } from \"./harness/registry-reader.ts\";\nexport type { BlockedReason } from \"./harness/scheduler.ts\";\nexport type { TaskGraph, TaskGraphNode, TaskGraphState, TaskGraphWatch } from \"./harness/task-graph.ts\";\nexport { DURABLE_TELEMETRY_SCHEMA } from \"./harness/telemetry.ts\";\nexport {\n\tNestedCallDoc,\n\ttype NestedCallState,\n\tToolTask,\n\ttype ToolTaskCheckpoint,\n\ttype ToolTaskInput,\n\ttype ToolTaskResult,\n} from \"./harness/tool.ts\";\nexport {\n\tConversationTranscript,\n\ttype ConversationTranscriptOptions,\n\ttype EntryLoader,\n\ttype TranscriptItem,\n\ttype TranscriptView,\n} from \"./harness/transcript.ts\";\nexport type {\n\tAfterFailedRun,\n\tAfterToolsDecision,\n\tAgent,\n\tAgentChange,\n\tAgentState,\n\tAnyTask,\n\tCompactionHooks,\n\tCompactionPolicy,\n\tCompactionReason,\n\tCompactionResult,\n\tCompactionSettings,\n\tContextView,\n\tConversation,\n\tConversationAbortOptions,\n\tConversationCreateOptions,\n\tConversationHandle,\n\tConversationInit,\n\tConversationRetryPolicy,\n\tConversationStreamOptions,\n\tConversationWatch,\n\tEnvTarget,\n\tExtension,\n\tGenerationHooks,\n\tHarnessInspection,\n\tHarnessOptions,\n\tHarnessSettings,\n\tHookApi,\n\tHookRegistration,\n\tHookResult,\n\tHooksOf,\n\tHookTask,\n\tInputEntry,\n\tInputSubmissionDraft,\n\tModelRef,\n\tNestedToolCall,\n\tNestedToolExecutionResult,\n\tProgressPolicy,\n\tPromptInput,\n\tPromptSection,\n\tQueueMode,\n\tRegistry,\n\tRegistryReader,\n\tRegistrySnapshot,\n\tRunSummary,\n\tSettings,\n\tSettledSubmissionRecord,\n\tSettledTask,\n\tSubmission,\n\tSubmissionDraft,\n\tTaskInspection,\n\tToolControl,\n\tToolDiagnostic,\n\tToolExecutionApi,\n\tToolExecutionMode,\n\tToolExecutionResult,\n\tToolHookCall,\n\tToolHooks,\n\tToolNamespace,\n\tToolPark,\n\tToolRegistration,\n\tUserInput,\n\tWake,\n\tWrap,\n\tYieldDecision,\n} from \"./harness/types.ts\";\nexport { UsageDoc, type UsageState } from \"./harness/usage.ts\";\nexport type { ConversationView, ConversationWindow } from \"./harness/view.ts\";\nexport { createSession } from \"./session/session.ts\";\nexport {\n\tdefineSignal,\n\ttype SignalDefinition,\n\ttype SignalKey,\n\ttype SignalResult,\n\ttype SignalState,\n\ttype SignalToken,\n\tSubmissionSettled,\n} from \"./signals.ts\";\nexport { MemoryStorage } from \"./storage/memory.ts\";\nexport { defineTask } from \"./tasks.ts\";\nexport type {\n\tCheckpointInfo,\n\tCommitChange,\n\tCommitObservation,\n\tCommitObserver,\n\tCommitOptions,\n\tCommitPersistence,\n\tCommitPublication,\n\tCommitResult,\n\tCommonDocDefinition,\n\tContextEdit,\n\tConversationDocFamilyToken,\n\tConversationDocToken,\n\tConversationId,\n\tConversationOwnership,\n\tConversationQuery,\n\tConversationRecord,\n\tCursor,\n\tDocDefinition,\n\tDocFamilyDefinition,\n\tDocFamilyToken,\n\tDocToken,\n\tDocumentAddress,\n\tDocumentCommitChange,\n\tDocumentContent,\n\tDocumentCopySource,\n\tDocumentCreate,\n\tDocumentId,\n\tDocumentObserver,\n\tDocumentPoint,\n\tDocumentQuery,\n\tDocumentReader,\n\tDocumentRecord,\n\tDocumentSemantics,\n\tDocumentWatch,\n\tEntry,\n\tEntryDraft,\n\tEntryId,\n\tEntryQuery,\n\tEntryRecord,\n\tHookRunner,\n\tHostCallback,\n\tId,\n\tJoinPolicy,\n\tJsonObject,\n\tLatestConversationSemantics,\n\tNextTaskState,\n\tObservation,\n\tObserver,\n\tPage,\n\tPhaseHandler,\n\tReport,\n\tReportFrom,\n\tReportInfo,\n\tReportTask,\n\tRewindableConversationDocFamilyToken,\n\tRewindableConversationDocToken,\n\tRewindableConversationSemantics,\n\tRunningTask,\n\tScanOrder,\n\tSeq,\n\tSession,\n\tSessionDocFamilyToken,\n\tSessionDocToken,\n\tSessionEnd,\n\tSetTimer,\n\tStorage,\n\tStorageWrite,\n\tStoredDocument,\n\tSubmissionCreate,\n\tSubmissionId,\n\tSubmissionNotify,\n\tSubmissionQuery,\n\tSubmissionRecord,\n\tSubmissionSettlement,\n\tTableCommitChange,\n\tTask,\n\tTaskDefinition,\n\tTaskDocFamilyToken,\n\tTaskDocToken,\n\tTaskId,\n\tTaskOptions,\n\tTaskOutcome,\n\tTaskOutcomeError,\n\tTaskOwnership,\n\tTaskQuery,\n\tTaskRecord,\n\tTaskRuntime,\n\tTaskState,\n\tTx,\n\tTypedEntry,\n\tTypedEntryDraft,\n\tWakeReason,\n} from \"./types.ts\";\nexport { ROOT_CONVERSATION_ID } from \"./types.ts\";\n"]}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * BM25 tool search for code mode's `searchTools()` and the `tool_search` tool, a copy of the coding agent's tool search
3
+ * ranking: durable keeps its own copy of what it needs from the coding agent.
4
+ */
5
+ /** A tool as the ranker sees it: its name, its text, and the text of its namespace. */
6
+ export type SearchDocument = {
7
+ readonly name: string;
8
+ /** Description and parameter names and descriptions; not the name, which the ranker reads from `name`. */
9
+ readonly text: string;
10
+ /** Name, description, and instructions of the tool's namespace. */
11
+ readonly namespaceText?: string;
12
+ };
13
+ /**
14
+ * Okapi BM25 (k1 1.2, b 0.75) over `text`, with the name and the namespace as separate fields: the names of the best
15
+ * matches, best first; ties keep document order.
16
+ * - A tool that matches more of the query's terms, in any field, ranks above one that matches fewer, whatever their
17
+ * scores: for `screenshot window`, a tool whose description has both words beats `window` whose name has one.
18
+ * - A query term in the name scores more than any number of mentions in the text.
19
+ * - A tool whose whole local name (after the last `__`) is in the query gets a bonus worth one more match of every
20
+ * query term, so among tools matching as many terms, `peekaboo app` finds `mcp__peekaboo__app` over tools that
21
+ * only mention the words.
22
+ * - A query that is exactly a tool's name, or its name after a `__`, ranks that tool first, before coverage.
23
+ *
24
+ * Only `text` is length-normalized, so a long name or long namespace instructions do not lower a tool's score.
25
+ */
26
+ export declare function rankDocuments(query: string, documents: readonly SearchDocument[], limit: number): string[];
27
+ /** Unicode word segmentation with identifier boundaries and English stop words/singular forms. */
28
+ export declare function tokenize(text: string): string[];
29
+ //# sourceMappingURL=search.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,uFAAuF;AACvF,MAAM,MAAM,cAAc,GAAG;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,0GAA0G;IAC1G,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,mEAAmE;IACnE,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;CAChC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,cAAc,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CA0C1G;AAsED,kGAAkG;AAClG,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAe/C"}