@bastani/atomic 0.10.1 → 0.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (295) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/dist/builtin/intercom/CHANGELOG.md +12 -0
  3. package/dist/builtin/intercom/broker/watchdog.ts +4 -0
  4. package/dist/builtin/intercom/package.json +1 -1
  5. package/dist/builtin/mcp/package.json +1 -1
  6. package/dist/builtin/subagents/CHANGELOG.md +32 -0
  7. package/dist/builtin/subagents/README.md +2 -0
  8. package/dist/builtin/subagents/package.json +1 -1
  9. package/dist/builtin/subagents/skills/subagent/SKILL.md +3 -3
  10. package/dist/builtin/subagents/src/extension/index.bundle.mjs +269 -144
  11. package/dist/builtin/web-access/CHANGELOG.md +14 -0
  12. package/dist/builtin/web-access/index.bundle.mjs +9 -5
  13. package/dist/builtin/web-access/package.json +1 -1
  14. package/dist/cli/list-models.d.ts.map +1 -1
  15. package/dist/cli/list-models.js +1 -14
  16. package/dist/cli/list-models.js.map +1 -1
  17. package/dist/core/agent-session-export.d.ts.map +1 -1
  18. package/dist/core/agent-session-export.js +13 -9
  19. package/dist/core/agent-session-export.js.map +1 -1
  20. package/dist/core/agent-session-message-queue.d.ts.map +1 -1
  21. package/dist/core/agent-session-message-queue.js +6 -3
  22. package/dist/core/agent-session-message-queue.js.map +1 -1
  23. package/dist/core/agent-session-methods.d.ts +3 -0
  24. package/dist/core/agent-session-methods.d.ts.map +1 -1
  25. package/dist/core/agent-session-methods.js.map +1 -1
  26. package/dist/core/agent-session-nested-tools.d.ts.map +1 -1
  27. package/dist/core/agent-session-nested-tools.js +2 -1
  28. package/dist/core/agent-session-nested-tools.js.map +1 -1
  29. package/dist/core/agent-session-prompt.d.ts.map +1 -1
  30. package/dist/core/agent-session-prompt.js +12 -0
  31. package/dist/core/agent-session-prompt.js.map +1 -1
  32. package/dist/core/agent-session-state.d.ts +6 -0
  33. package/dist/core/agent-session-state.d.ts.map +1 -1
  34. package/dist/core/agent-session-state.js +71 -4
  35. package/dist/core/agent-session-state.js.map +1 -1
  36. package/dist/core/agent-session-tool-hooks.d.ts.map +1 -1
  37. package/dist/core/agent-session-tool-hooks.js +9 -1
  38. package/dist/core/agent-session-tool-hooks.js.map +1 -1
  39. package/dist/core/agent-session-types.d.ts +2 -0
  40. package/dist/core/agent-session-types.d.ts.map +1 -1
  41. package/dist/core/agent-session-types.js.map +1 -1
  42. package/dist/core/agent-session.d.ts +3 -0
  43. package/dist/core/agent-session.d.ts.map +1 -1
  44. package/dist/core/agent-session.js +7 -0
  45. package/dist/core/agent-session.js.map +1 -1
  46. package/dist/core/cache-stats.d.ts +15 -0
  47. package/dist/core/cache-stats.d.ts.map +1 -1
  48. package/dist/core/cache-stats.js +40 -2
  49. package/dist/core/cache-stats.js.map +1 -1
  50. package/dist/core/diagnostic-writer.d.ts.map +1 -1
  51. package/dist/core/diagnostic-writer.js +2 -1
  52. package/dist/core/diagnostic-writer.js.map +1 -1
  53. package/dist/core/export-html/template.js +14 -4
  54. package/dist/core/extensions/context-types.d.ts +6 -0
  55. package/dist/core/extensions/context-types.d.ts.map +1 -1
  56. package/dist/core/extensions/context-types.js.map +1 -1
  57. package/dist/core/extensions/loader-api.d.ts.map +1 -1
  58. package/dist/core/extensions/loader-api.js +5 -2
  59. package/dist/core/extensions/loader-api.js.map +1 -1
  60. package/dist/core/queued-message-delivery.d.ts +100 -7
  61. package/dist/core/queued-message-delivery.d.ts.map +1 -1
  62. package/dist/core/queued-message-delivery.js +194 -4
  63. package/dist/core/queued-message-delivery.js.map +1 -1
  64. package/dist/core/resume-cache-checkpoint.d.ts +32 -0
  65. package/dist/core/resume-cache-checkpoint.d.ts.map +1 -0
  66. package/dist/core/resume-cache-checkpoint.js +67 -0
  67. package/dist/core/resume-cache-checkpoint.js.map +1 -0
  68. package/dist/core/sdk-types.d.ts +37 -0
  69. package/dist/core/sdk-types.d.ts.map +1 -1
  70. package/dist/core/sdk-types.js.map +1 -1
  71. package/dist/core/sdk.d.ts.map +1 -1
  72. package/dist/core/sdk.js +57 -28
  73. package/dist/core/sdk.js.map +1 -1
  74. package/dist/core/session-manager-core.d.ts.map +1 -1
  75. package/dist/core/session-manager-core.js +12 -3
  76. package/dist/core/session-manager-core.js.map +1 -1
  77. package/dist/core/session-manager-entries.d.ts +13 -0
  78. package/dist/core/session-manager-entries.d.ts.map +1 -1
  79. package/dist/core/session-manager-entries.js +38 -6
  80. package/dist/core/session-manager-entries.js.map +1 -1
  81. package/dist/core/settings-lock-directory.d.ts.map +1 -1
  82. package/dist/core/settings-lock-directory.js +2 -1
  83. package/dist/core/settings-lock-directory.js.map +1 -1
  84. package/dist/core/storage/node-sqlite-file-gate.d.ts +173 -0
  85. package/dist/core/storage/node-sqlite-file-gate.d.ts.map +1 -0
  86. package/dist/core/storage/node-sqlite-file-gate.js +1033 -0
  87. package/dist/core/storage/node-sqlite-file-gate.js.map +1 -0
  88. package/dist/core/storage/node-sqlite-thread.d.ts +33 -6
  89. package/dist/core/storage/node-sqlite-thread.d.ts.map +1 -1
  90. package/dist/core/storage/node-sqlite-thread.js +72 -2
  91. package/dist/core/storage/node-sqlite-thread.js.map +1 -1
  92. package/dist/core/storage/node-sqlite.d.ts.map +1 -1
  93. package/dist/core/storage/node-sqlite.js +216 -15
  94. package/dist/core/storage/node-sqlite.js.map +1 -1
  95. package/dist/core/storage/session/entry-structure.d.ts.map +1 -1
  96. package/dist/core/storage/session/entry-structure.js +39 -2
  97. package/dist/core/storage/session/entry-structure.js.map +1 -1
  98. package/dist/core/storage/session/session-resume.d.ts.map +1 -1
  99. package/dist/core/storage/session/session-resume.js +1 -0
  100. package/dist/core/storage/session/session-resume.js.map +1 -1
  101. package/dist/core/storage/session/session-search-index.d.ts.map +1 -1
  102. package/dist/core/storage/session/session-search-index.js +56 -9
  103. package/dist/core/storage/session/session-search-index.js.map +1 -1
  104. package/dist/core/storage/statement-sequence.d.ts +36 -0
  105. package/dist/core/storage/statement-sequence.d.ts.map +1 -0
  106. package/dist/core/storage/statement-sequence.js +22 -0
  107. package/dist/core/storage/statement-sequence.js.map +1 -0
  108. package/dist/core/system-prompt.d.ts.map +1 -1
  109. package/dist/core/system-prompt.js +13 -4
  110. package/dist/core/system-prompt.js.map +1 -1
  111. package/dist/core/tasks/heartbeat-notice.d.ts.map +1 -1
  112. package/dist/core/tasks/heartbeat-notice.js +2 -1
  113. package/dist/core/tasks/heartbeat-notice.js.map +1 -1
  114. package/dist/core/tool-loadout.d.ts +4 -2
  115. package/dist/core/tool-loadout.d.ts.map +1 -1
  116. package/dist/core/tool-loadout.js +27 -5
  117. package/dist/core/tool-loadout.js.map +1 -1
  118. package/dist/core/tools/history-regex-worker.d.ts.map +1 -1
  119. package/dist/core/tools/history-regex-worker.js +2 -1
  120. package/dist/core/tools/history-regex-worker.js.map +1 -1
  121. package/dist/core/tools/powershell.d.ts +22 -22
  122. package/dist/core/tools/sqlite-selector-connection.d.ts.map +1 -1
  123. package/dist/core/tools/sqlite-selector-connection.js +7 -0
  124. package/dist/core/tools/sqlite-selector-connection.js.map +1 -1
  125. package/dist/core/transformed-system-prompt.d.ts +92 -0
  126. package/dist/core/transformed-system-prompt.d.ts.map +1 -0
  127. package/dist/core/transformed-system-prompt.js +240 -0
  128. package/dist/core/transformed-system-prompt.js.map +1 -0
  129. package/dist/extensions/codemode/execute.js +1 -1
  130. package/dist/extensions/codemode/execute.js.map +1 -1
  131. package/dist/extensions/codemode/tool.d.ts.map +1 -1
  132. package/dist/extensions/codemode/tool.js +16 -3
  133. package/dist/extensions/codemode/tool.js.map +1 -1
  134. package/dist/extensions/llama/ui.d.ts.map +1 -1
  135. package/dist/extensions/llama/ui.js +13 -8
  136. package/dist/extensions/llama/ui.js.map +1 -1
  137. package/dist/extensions/mcp/config.d.ts +2 -0
  138. package/dist/extensions/mcp/config.d.ts.map +1 -1
  139. package/dist/extensions/mcp/config.js +5 -0
  140. package/dist/extensions/mcp/config.js.map +1 -1
  141. package/dist/extensions/mcp/index.d.ts +4 -0
  142. package/dist/extensions/mcp/index.d.ts.map +1 -1
  143. package/dist/extensions/mcp/index.js +289 -64
  144. package/dist/extensions/mcp/index.js.map +1 -1
  145. package/dist/extensions/mcp/runtime.d.ts +1 -1
  146. package/dist/extensions/mcp/runtime.d.ts.map +1 -1
  147. package/dist/extensions/mcp/runtime.js +2 -2
  148. package/dist/extensions/mcp/runtime.js.map +1 -1
  149. package/dist/extensions/mcp/tool-records.d.ts +58 -0
  150. package/dist/extensions/mcp/tool-records.d.ts.map +1 -0
  151. package/dist/extensions/mcp/tool-records.js +129 -0
  152. package/dist/extensions/mcp/tool-records.js.map +1 -0
  153. package/dist/index.d.ts +1 -0
  154. package/dist/index.d.ts.map +1 -1
  155. package/dist/index.js +1 -0
  156. package/dist/index.js.map +1 -1
  157. package/dist/modes/interactive/components/agent-panel.d.ts +2 -4
  158. package/dist/modes/interactive/components/agent-panel.d.ts.map +1 -1
  159. package/dist/modes/interactive/components/agent-panel.js +65 -80
  160. package/dist/modes/interactive/components/agent-panel.js.map +1 -1
  161. package/dist/modes/interactive/components/compaction-boundary-message.d.ts.map +1 -1
  162. package/dist/modes/interactive/components/compaction-boundary-message.js +3 -3
  163. package/dist/modes/interactive/components/compaction-boundary-message.js.map +1 -1
  164. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  165. package/dist/modes/interactive/components/footer.js +35 -28
  166. package/dist/modes/interactive/components/footer.js.map +1 -1
  167. package/dist/modes/interactive/components/notice-line.d.ts +16 -0
  168. package/dist/modes/interactive/components/notice-line.d.ts.map +1 -1
  169. package/dist/modes/interactive/components/notice-line.js +7 -0
  170. package/dist/modes/interactive/components/notice-line.js.map +1 -1
  171. package/dist/modes/interactive/components/prompt-slot.d.ts +1 -0
  172. package/dist/modes/interactive/components/prompt-slot.d.ts.map +1 -1
  173. package/dist/modes/interactive/components/prompt-slot.js +8 -4
  174. package/dist/modes/interactive/components/prompt-slot.js.map +1 -1
  175. package/dist/modes/interactive/components/task-board.d.ts +0 -1
  176. package/dist/modes/interactive/components/task-board.d.ts.map +1 -1
  177. package/dist/modes/interactive/components/task-board.js +6 -14
  178. package/dist/modes/interactive/components/task-board.js.map +1 -1
  179. package/dist/modes/interactive/components/task-row.d.ts.map +1 -1
  180. package/dist/modes/interactive/components/task-row.js +7 -6
  181. package/dist/modes/interactive/components/task-row.js.map +1 -1
  182. package/dist/modes/interactive/components/token-segment.d.ts +2 -1
  183. package/dist/modes/interactive/components/token-segment.d.ts.map +1 -1
  184. package/dist/modes/interactive/components/token-segment.js +2 -4
  185. package/dist/modes/interactive/components/token-segment.js.map +1 -1
  186. package/dist/modes/interactive/components/tree-selector-content.d.ts.map +1 -1
  187. package/dist/modes/interactive/components/tree-selector-content.js +2 -2
  188. package/dist/modes/interactive/components/tree-selector-content.js.map +1 -1
  189. package/dist/modes/interactive/components/working-run-meter.d.ts +0 -1
  190. package/dist/modes/interactive/components/working-run-meter.d.ts.map +1 -1
  191. package/dist/modes/interactive/components/working-run-meter.js +0 -9
  192. package/dist/modes/interactive/components/working-run-meter.js.map +1 -1
  193. package/dist/modes/interactive/extension-command-hold.d.ts +25 -0
  194. package/dist/modes/interactive/extension-command-hold.d.ts.map +1 -0
  195. package/dist/modes/interactive/extension-command-hold.js +45 -0
  196. package/dist/modes/interactive/extension-command-hold.js.map +1 -0
  197. package/dist/modes/interactive/interactive-agent-events.js +2 -1
  198. package/dist/modes/interactive/interactive-agent-events.js.map +1 -1
  199. package/dist/modes/interactive/interactive-extension-context.js +18 -10
  200. package/dist/modes/interactive/interactive-extension-context.js.map +1 -1
  201. package/dist/modes/interactive/interactive-extension-custom-ui.js +3 -0
  202. package/dist/modes/interactive/interactive-extension-custom-ui.js.map +1 -1
  203. package/dist/modes/interactive/interactive-input-handling.d.ts.map +1 -1
  204. package/dist/modes/interactive/interactive-input-handling.js +54 -13
  205. package/dist/modes/interactive/interactive-input-handling.js.map +1 -1
  206. package/dist/modes/interactive/interactive-model-routing.d.ts +6 -0
  207. package/dist/modes/interactive/interactive-model-routing.d.ts.map +1 -1
  208. package/dist/modes/interactive/interactive-model-routing.js +15 -9
  209. package/dist/modes/interactive/interactive-model-routing.js.map +1 -1
  210. package/dist/modes/interactive/interactive-prompt-turn.js +4 -0
  211. package/dist/modes/interactive/interactive-prompt-turn.js.map +1 -1
  212. package/dist/modes/interactive/interactive-queueing.d.ts +7 -0
  213. package/dist/modes/interactive/interactive-queueing.d.ts.map +1 -1
  214. package/dist/modes/interactive/interactive-queueing.js +47 -1
  215. package/dist/modes/interactive/interactive-queueing.js.map +1 -1
  216. package/dist/modes/interactive/interactive-session-routing.js +6 -0
  217. package/dist/modes/interactive/interactive-session-routing.js.map +1 -1
  218. package/dist/modes/interactive/interactive-slash-commands.js +165 -65
  219. package/dist/modes/interactive/interactive-slash-commands.js.map +1 -1
  220. package/dist/modes/interactive/screen-hold.d.ts +3 -0
  221. package/dist/modes/interactive/screen-hold.d.ts.map +1 -1
  222. package/dist/modes/interactive/screen-hold.js +9 -1
  223. package/dist/modes/interactive/screen-hold.js.map +1 -1
  224. package/dist/modes/interactive-engine/engine-health.d.ts +11 -3
  225. package/dist/modes/interactive-engine/engine-health.d.ts.map +1 -1
  226. package/dist/modes/interactive-engine/engine-health.js +5 -4
  227. package/dist/modes/interactive-engine/engine-health.js.map +1 -1
  228. package/dist/modes/interactive-engine/engine-quit-intent.d.ts +7 -0
  229. package/dist/modes/interactive-engine/engine-quit-intent.d.ts.map +1 -1
  230. package/dist/modes/interactive-engine/engine-quit-intent.js +19 -0
  231. package/dist/modes/interactive-engine/engine-quit-intent.js.map +1 -1
  232. package/dist/modes/interactive-engine/isolated-runtime.d.ts +18 -0
  233. package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
  234. package/dist/modes/interactive-engine/isolated-runtime.js +56 -4
  235. package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
  236. package/dist/modes/interactive-engine/protocol.d.ts +7 -0
  237. package/dist/modes/interactive-engine/protocol.d.ts.map +1 -1
  238. package/dist/modes/interactive-engine/protocol.js +1 -0
  239. package/dist/modes/interactive-engine/protocol.js.map +1 -1
  240. package/dist/modes/rpc/agent-panel-bridge.d.ts.map +1 -1
  241. package/dist/modes/rpc/agent-panel-bridge.js +0 -13
  242. package/dist/modes/rpc/agent-panel-bridge.js.map +1 -1
  243. package/dist/modes/rpc/rpc-client-process.d.ts +14 -1
  244. package/dist/modes/rpc/rpc-client-process.d.ts.map +1 -1
  245. package/dist/modes/rpc/rpc-client-process.js +74 -10
  246. package/dist/modes/rpc/rpc-client-process.js.map +1 -1
  247. package/dist/modes/rpc/rpc-client.d.ts +27 -1
  248. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  249. package/dist/modes/rpc/rpc-client.js +81 -5
  250. package/dist/modes/rpc/rpc-client.js.map +1 -1
  251. package/dist/modes/rpc/rpc-event-buffer.d.ts +2 -0
  252. package/dist/modes/rpc/rpc-event-buffer.d.ts.map +1 -1
  253. package/dist/modes/rpc/rpc-event-buffer.js +9 -0
  254. package/dist/modes/rpc/rpc-event-buffer.js.map +1 -1
  255. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  256. package/dist/modes/rpc/rpc-mode.js +16 -3
  257. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  258. package/dist/modes/rpc/rpc-session-binding.d.ts +7 -1
  259. package/dist/modes/rpc/rpc-session-binding.d.ts.map +1 -1
  260. package/dist/modes/rpc/rpc-session-binding.js +10 -2
  261. package/dist/modes/rpc/rpc-session-binding.js.map +1 -1
  262. package/dist/utils/image-resize.d.ts.map +1 -1
  263. package/dist/utils/image-resize.js +2 -1
  264. package/dist/utils/image-resize.js.map +1 -1
  265. package/dist/utils/interactive-engine-bootstrap.d.ts +2 -0
  266. package/dist/utils/interactive-engine-bootstrap.d.ts.map +1 -1
  267. package/dist/utils/interactive-engine-bootstrap.js +1 -0
  268. package/dist/utils/interactive-engine-bootstrap.js.map +1 -1
  269. package/dist/utils/interactive-engine-env.d.ts +2 -0
  270. package/dist/utils/interactive-engine-env.d.ts.map +1 -1
  271. package/dist/utils/interactive-engine-env.js +1 -0
  272. package/dist/utils/interactive-engine-env.js.map +1 -1
  273. package/dist/utils/shell.d.ts.map +1 -1
  274. package/dist/utils/shell.js +2 -0
  275. package/dist/utils/shell.js.map +1 -1
  276. package/dist/utils/token-count.d.ts +8 -0
  277. package/dist/utils/token-count.d.ts.map +1 -0
  278. package/dist/utils/token-count.js +25 -0
  279. package/dist/utils/token-count.js.map +1 -0
  280. package/dist/utils/worker-threads.d.ts +18 -0
  281. package/dist/utils/worker-threads.d.ts.map +1 -0
  282. package/dist/utils/worker-threads.js +28 -0
  283. package/dist/utils/worker-threads.js.map +1 -0
  284. package/docs/background-tasks.md +13 -12
  285. package/docs/compaction.md +2 -2
  286. package/docs/development.md +1 -1
  287. package/docs/extensions/api-reference.md +5 -3
  288. package/docs/extensions/events.md +2 -0
  289. package/docs/mcp-servers.md +1 -1
  290. package/docs/settings.md +2 -0
  291. package/docs/storage.md +3 -1
  292. package/docs/subagents.md +6 -2
  293. package/docs/usage.md +1 -1
  294. package/npm-shrinkwrap.json +49 -49
  295. package/package.json +6 -6
@@ -1,12 +1,13 @@
1
1
  /**
2
2
  * A queued message from the moment its turn takes it out of the session's queue until its own `message_start`
3
3
  * reaches the session's listeners. Between the two, the session runs the extensions' `message_start` hooks, and the
4
- * `queue_update` it sent when the turn took the message already lists the queue without it. A chat in this process
5
- * keeps showing such a message as queued until its own row is in the transcript, so the message is never off screen.
4
+ * `queue_update` it sent when the turn took the message already lists the queue without it. A chat keeps showing such
5
+ * a message as queued until its own row is in the transcript, so the message is never off screen.
6
6
  *
7
- * Nothing here changes a public event or its order, and nothing crosses a process boundary. Only deliveries still
8
- * under way are reachable: an event a listener keeps reaches the session's deliveries in flight, never the text of
9
- * one that ended, and each `queue_update` records a number, not a copy.
7
+ * Nothing here changes a public event or its order. Only deliveries still under way are reachable: an event a listener
8
+ * keeps reaches the session's deliveries in flight, never the text of one that ended, and each `queue_update` records a
9
+ * number, not a copy. An isolated engine tells its host about them with {@link QueuedDeliveryRelay}: each message's
10
+ * text crosses once, when a `queue_update` first names it, and its end crosses as a count.
10
11
  */
11
12
  export interface QueuedMessageDelivery {
12
13
  readonly lane: "steer" | "followUp";
@@ -14,10 +15,19 @@ export interface QueuedMessageDelivery {
14
15
  /** Its place in the order the session's turns took messages. */
15
16
  readonly order: number;
16
17
  }
17
- /** One session's deliveries under way, in the order its turns took them; dropped once none is left. */
18
+ /** Messages per lane, each lane in the order the turns took them. */
19
+ export interface QueuedMessageLanes {
20
+ readonly steering: readonly string[];
21
+ readonly followUp: readonly string[];
22
+ }
23
+ /** The lanes with no message: what every chat draws while nothing is being delivered. */
24
+ export declare const NO_QUEUED_MESSAGES: QueuedMessageLanes;
25
+ /** One session's deliveries under way, by their order, in the order its turns took them; dropped once none is left. */
18
26
  interface SessionDeliveries {
19
27
  taken: number;
20
- readonly underWay: Set<QueuedMessageDelivery>;
28
+ readonly underWay: Map<number, QueuedMessageDelivery>;
29
+ /** The texts under way per lane, kept until the next delivery begins or ends, so an unchanged one is the same. */
30
+ lanes?: QueuedMessageLanes;
21
31
  }
22
32
  /** The deliveries a `queue_update` lists: those of `session` the turns had taken when it was sent, while under way. */
23
33
  export interface QueueUpdateDeliveries {
@@ -37,5 +47,88 @@ export declare function noteQueueUpdateDeliveries(session: object, event: object
37
47
  export declare function queueUpdateDeliveries(event: object): QueueUpdateDeliveries | undefined;
38
48
  /** The texts of `lane` that `listed` still has under way, in the order the turns took them. */
39
49
  export declare function queuedTextsUnderWay(listed: QueueUpdateDeliveries | undefined, lane: QueuedMessageDelivery["lane"]): string[];
50
+ /**
51
+ * Every message `session` is delivering now, per lane. The session's queue lists none of them, so a chat that reads
52
+ * the queue and this at the same moment shows each queued message once. The same object until a delivery begins or
53
+ * ends; {@link NO_QUEUED_MESSAGES} when none is under way.
54
+ */
55
+ export declare function queuedMessagesUnderWay(session: object): QueuedMessageLanes;
56
+ /** A message a turn took, as an engine names it to its host. */
57
+ export interface QueuedDeliveryEntry {
58
+ readonly lane: QueuedMessageDelivery["lane"];
59
+ readonly text: string;
60
+ }
61
+ /**
62
+ * What changed in the deliveries an engine told its host about: the `ended` oldest of them are no longer under way,
63
+ * then the turns took `taken`, in order.
64
+ */
65
+ export interface QueuedDeliveryChange {
66
+ readonly ended?: number;
67
+ readonly taken?: readonly QueuedDeliveryEntry[];
68
+ }
69
+ /**
70
+ * The engine's side of the deliveries its host draws for the main chat. With each event it sends, {@link note} answers
71
+ * what the host has to learn: the messages a `queue_update` names that the host was not told about, and how many of the
72
+ * ones it was told about are no longer under way. Deliveries end in the order the turns took them (the session handles
73
+ * their events one at a time), so the ended ones are always the oldest; one that ended out of order is counted once
74
+ * those before it have. Each event costs constant time, apart from the messages it names.
75
+ */
76
+ export declare class QueuedDeliveryRelay {
77
+ /**
78
+ * The deliveries the host was told about and not told ended, oldest first, from `head` on. A slot before `head` is
79
+ * cleared as it is passed, so no message ended is kept.
80
+ */
81
+ private told;
82
+ private head;
83
+ /** The record of the session's deliveries the host was last told about, and the last order it was told. */
84
+ private toldRecord;
85
+ private toldThrough;
86
+ private readonly retired;
87
+ /** The change to send with `event`, which `session` sends now; undefined when there is none to send with it. */
88
+ note(session: object, event: {
89
+ readonly type: string;
90
+ }): QueuedDeliveryChange | undefined;
91
+ /** The deliveries `event`, a `queue_update`, lists that the host was not told about, oldest first. */
92
+ private newlyListed;
93
+ /**
94
+ * `session` is being replaced, and the host forgets every delivery it was told about. Its events from now on carry no
95
+ * change: the host shows the replacement.
96
+ */
97
+ retire(session: object): void;
98
+ }
99
+ /** The end a line brought, kept until its event reaches the chat; it holds a count, never a message. */
100
+ export interface QueuedDeliveryEnd {
101
+ readonly ended: number;
102
+ /** The view's reset count when the line was read: an end read before a reset never applies. */
103
+ readonly resets: number;
104
+ }
105
+ /**
106
+ * A host's view of what its engine's main session is delivering: the messages the engine said its turns took, oldest
107
+ * first, each until the event that ends it reaches the chat. A line's taken messages join when the host reads it, with
108
+ * the cached queue that no longer lists them; its ended count waits for its event, which may be held back from the chat
109
+ * (a compaction's end holds later events until the session view caught up), so a message leaves in the step its own
110
+ * row is drawn. Losing the engine or its retiring the session forgets everything at once.
111
+ */
112
+ export declare class QueuedDeliveryView {
113
+ private entries;
114
+ private lanes;
115
+ private resets;
116
+ /** The messages being delivered, per lane; the same object until they change. */
117
+ get texts(): QueuedMessageLanes;
118
+ /** A line brought `change`: what it took joins now; its end, returned, applies when its event reaches the chat. */
119
+ receive(change: QueuedDeliveryChange): QueuedDeliveryEnd | undefined;
120
+ /** The event that carried `end` reaches the chat now: the oldest messages it ended leave. */
121
+ end(end: QueuedDeliveryEnd): void;
122
+ /** Forget every message; an end read before now never applies. Answers whether any was listed. */
123
+ reset(): boolean;
124
+ private set;
125
+ }
126
+ /** `record`, an event line an engine writes, with `change` when there is one. */
127
+ export declare function withQueuedDeliveryChange(record: object, change: QueuedDeliveryChange | undefined): object;
128
+ /**
129
+ * Take the change in deliveries off `event`, an event line the host read from its engine, before anything else sees
130
+ * the event: its listeners get it as the engine's session sent it, and keeping it keeps no message text.
131
+ */
132
+ export declare function takeQueuedDeliveryChange(event: object): QueuedDeliveryChange | undefined;
40
133
  export {};
41
134
  //# sourceMappingURL=queued-message-delivery.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"queued-message-delivery.d.ts","sourceRoot":"","sources":["../../src/core/queued-message-delivery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,WAAW,qBAAqB;IACrC,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,UAAU,CAAC;IACpC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,gEAAgE;IAChE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACvB;AAED,uGAAuG;AACvG,UAAU,iBAAiB;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,qBAAqB,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AiF;AACjF,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,oBAAoB,GAAG,SAAS,GAAG,MAAM,CAEzG;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,GAAG,oBAAoB,GAAG,SAAS,CAMxF"}
@@ -1,14 +1,23 @@
1
+ /** The lanes with no message: what every chat draws while nothing is being delivered. */
2
+ export const NO_QUEUED_MESSAGES = Object.freeze({
3
+ steering: Object.freeze([]),
4
+ followUp: Object.freeze([]),
5
+ });
1
6
  const sessions = new WeakMap();
2
7
  const listedWith = new WeakMap();
8
+ /** Every delivery under way, whichever session it belongs to. */
9
+ const underWay = new WeakSet();
3
10
  /** The turn took `text` out of `session`'s `lane` queue; its `message_start` has not reached the listeners yet. */
4
11
  export function beginQueuedMessageDelivery(session, lane, text) {
5
12
  let deliveries = sessions.get(session);
6
13
  if (deliveries === undefined) {
7
- deliveries = { taken: 0, underWay: new Set() };
14
+ deliveries = { taken: 0, underWay: new Map() };
8
15
  sessions.set(session, deliveries);
9
16
  }
10
17
  const delivery = { lane, text, order: ++deliveries.taken };
11
- deliveries.underWay.add(delivery);
18
+ deliveries.underWay.set(delivery.order, delivery);
19
+ deliveries.lanes = undefined;
20
+ underWay.add(delivery);
12
21
  return delivery;
13
22
  }
14
23
  /**
@@ -19,8 +28,11 @@ export function endQueuedMessageDelivery(session, delivery) {
19
28
  if (delivery === undefined)
20
29
  return;
21
30
  const deliveries = sessions.get(session);
22
- if (deliveries === undefined || !deliveries.underWay.delete(delivery))
31
+ if (deliveries?.underWay.get(delivery.order) !== delivery)
23
32
  return;
33
+ deliveries.underWay.delete(delivery.order);
34
+ deliveries.lanes = undefined;
35
+ underWay.delete(delivery);
24
36
  // A later delivery starts a new record, which an event sent before it never reaches.
25
37
  if (deliveries.underWay.size === 0)
26
38
  sessions.delete(session);
@@ -40,9 +52,187 @@ export function queuedTextsUnderWay(listed, lane) {
40
52
  if (listed === undefined)
41
53
  return [];
42
54
  const texts = [];
43
- for (const delivery of listed.session.underWay)
55
+ for (const delivery of listed.session.underWay.values())
44
56
  if (delivery.lane === lane && delivery.order <= listed.through)
45
57
  texts.push(delivery.text);
46
58
  return texts;
47
59
  }
60
+ /**
61
+ * Every message `session` is delivering now, per lane. The session's queue lists none of them, so a chat that reads
62
+ * the queue and this at the same moment shows each queued message once. The same object until a delivery begins or
63
+ * ends; {@link NO_QUEUED_MESSAGES} when none is under way.
64
+ */
65
+ export function queuedMessagesUnderWay(session) {
66
+ const deliveries = sessions.get(session);
67
+ if (deliveries === undefined)
68
+ return NO_QUEUED_MESSAGES;
69
+ deliveries.lanes ??= lanesOf(deliveries.underWay.values());
70
+ return deliveries.lanes;
71
+ }
72
+ /**
73
+ * The engine's side of the deliveries its host draws for the main chat. With each event it sends, {@link note} answers
74
+ * what the host has to learn: the messages a `queue_update` names that the host was not told about, and how many of the
75
+ * ones it was told about are no longer under way. Deliveries end in the order the turns took them (the session handles
76
+ * their events one at a time), so the ended ones are always the oldest; one that ended out of order is counted once
77
+ * those before it have. Each event costs constant time, apart from the messages it names.
78
+ */
79
+ export class QueuedDeliveryRelay {
80
+ /**
81
+ * The deliveries the host was told about and not told ended, oldest first, from `head` on. A slot before `head` is
82
+ * cleared as it is passed, so no message ended is kept.
83
+ */
84
+ told = [];
85
+ head = 0;
86
+ /** The record of the session's deliveries the host was last told about, and the last order it was told. */
87
+ toldRecord;
88
+ toldThrough = 0;
89
+ retired = new WeakSet();
90
+ /** The change to send with `event`, which `session` sends now; undefined when there is none to send with it. */
91
+ note(session, event) {
92
+ // Before it is written, a newer update of the same tool call can replace a tool update, and a change with it.
93
+ if (event.type === "tool_execution_update" || this.retired.has(session))
94
+ return undefined;
95
+ const start = this.head;
96
+ for (let next = this.told[this.head]; next !== undefined && !underWay.has(next); next = this.told[this.head]) {
97
+ this.told[this.head] = undefined;
98
+ this.head++;
99
+ }
100
+ const ended = this.head - start;
101
+ const taken = event.type === "queue_update" ? this.newlyListed(event) : [];
102
+ // Drop the told ones that ended once they are most of the list: each delivery is moved at most once.
103
+ if (this.head > 0 && this.head * 2 >= this.told.length) {
104
+ this.told = this.told.slice(this.head);
105
+ this.head = 0;
106
+ }
107
+ for (const delivery of taken)
108
+ this.told.push(delivery);
109
+ if (ended === 0 && taken.length === 0)
110
+ return undefined;
111
+ return {
112
+ ...(ended > 0 ? { ended } : {}),
113
+ ...(taken.length > 0 ? { taken: taken.map(({ lane, text }) => ({ lane, text })) } : {}),
114
+ };
115
+ }
116
+ /** The deliveries `event`, a `queue_update`, lists that the host was not told about, oldest first. */
117
+ newlyListed(event) {
118
+ const listed = listedWith.get(event);
119
+ if (listed === undefined)
120
+ return [];
121
+ if (listed.session !== this.toldRecord) {
122
+ this.toldRecord = listed.session;
123
+ this.toldThrough = 0;
124
+ }
125
+ const taken = [];
126
+ for (let order = this.toldThrough + 1; order <= listed.through; order++) {
127
+ const delivery = listed.session.underWay.get(order);
128
+ if (delivery !== undefined)
129
+ taken.push(delivery);
130
+ }
131
+ this.toldThrough = Math.max(this.toldThrough, listed.through);
132
+ return taken;
133
+ }
134
+ /**
135
+ * `session` is being replaced, and the host forgets every delivery it was told about. Its events from now on carry no
136
+ * change: the host shows the replacement.
137
+ */
138
+ retire(session) {
139
+ this.retired.add(session);
140
+ this.told = [];
141
+ this.head = 0;
142
+ this.toldRecord = undefined;
143
+ this.toldThrough = 0;
144
+ }
145
+ }
146
+ /**
147
+ * A host's view of what its engine's main session is delivering: the messages the engine said its turns took, oldest
148
+ * first, each until the event that ends it reaches the chat. A line's taken messages join when the host reads it, with
149
+ * the cached queue that no longer lists them; its ended count waits for its event, which may be held back from the chat
150
+ * (a compaction's end holds later events until the session view caught up), so a message leaves in the step its own
151
+ * row is drawn. Losing the engine or its retiring the session forgets everything at once.
152
+ */
153
+ export class QueuedDeliveryView {
154
+ entries = [];
155
+ lanes = NO_QUEUED_MESSAGES;
156
+ resets = 0;
157
+ /** The messages being delivered, per lane; the same object until they change. */
158
+ get texts() {
159
+ return this.lanes;
160
+ }
161
+ /** A line brought `change`: what it took joins now; its end, returned, applies when its event reaches the chat. */
162
+ receive(change) {
163
+ if (change.taken !== undefined && change.taken.length > 0)
164
+ this.set([...this.entries, ...change.taken]);
165
+ return change.ended === undefined || change.ended === 0
166
+ ? undefined
167
+ : { ended: change.ended, resets: this.resets };
168
+ }
169
+ /** The event that carried `end` reaches the chat now: the oldest messages it ended leave. */
170
+ end(end) {
171
+ if (end.resets === this.resets)
172
+ this.set(this.entries.slice(end.ended));
173
+ }
174
+ /** Forget every message; an end read before now never applies. Answers whether any was listed. */
175
+ reset() {
176
+ this.resets++;
177
+ if (this.entries.length === 0)
178
+ return false;
179
+ this.set([]);
180
+ return true;
181
+ }
182
+ set(entries) {
183
+ this.entries = entries;
184
+ this.lanes = lanesOf(entries);
185
+ }
186
+ }
187
+ function lanesOf(deliveries) {
188
+ const steering = [];
189
+ const followUp = [];
190
+ for (const delivery of deliveries)
191
+ (delivery.lane === "steer" ? steering : followUp).push(delivery.text);
192
+ return steering.length === 0 && followUp.length === 0 ? NO_QUEUED_MESSAGES : { steering, followUp };
193
+ }
194
+ /**
195
+ * The field of an engine's event line that carries a change in deliveries. An engine writes it only for a host that
196
+ * asked for it when it started the engine, so a host of an earlier version never receives it.
197
+ */
198
+ const CHANGE_FIELD = "atomicQueuedDeliveries";
199
+ /** `record`, an event line an engine writes, with `change` when there is one. */
200
+ export function withQueuedDeliveryChange(record, change) {
201
+ return change === undefined ? record : { ...record, [CHANGE_FIELD]: change };
202
+ }
203
+ /**
204
+ * Take the change in deliveries off `event`, an event line the host read from its engine, before anything else sees
205
+ * the event: its listeners get it as the engine's session sent it, and keeping it keeps no message text.
206
+ */
207
+ export function takeQueuedDeliveryChange(event) {
208
+ if (!(CHANGE_FIELD in event))
209
+ return undefined;
210
+ const data = event;
211
+ const change = parseQueuedDeliveryChange(data[CHANGE_FIELD]);
212
+ delete data[CHANGE_FIELD];
213
+ return change;
214
+ }
215
+ /** `value` as a change in deliveries, as an engine writes one; undefined for anything else. */
216
+ function parseQueuedDeliveryChange(value) {
217
+ if (typeof value !== "object" || value === null || Array.isArray(value))
218
+ return undefined;
219
+ const { ended, taken } = value;
220
+ if (ended !== undefined && !(typeof ended === "number" && Number.isSafeInteger(ended) && ended >= 0))
221
+ return undefined;
222
+ if (taken !== undefined && !Array.isArray(taken))
223
+ return undefined;
224
+ const entries = [];
225
+ for (const entry of taken ?? []) {
226
+ if (typeof entry !== "object" || entry === null)
227
+ return undefined;
228
+ const { lane, text } = entry;
229
+ if ((lane !== "steer" && lane !== "followUp") || typeof text !== "string")
230
+ return undefined;
231
+ entries.push({ lane, text });
232
+ }
233
+ return {
234
+ ...(typeof ended === "number" && ended > 0 ? { ended } : {}),
235
+ ...(entries.length > 0 ? { taken: entries } : {}),
236
+ };
237
+ }
48
238
  //# sourceMappingURL=queued-message-delivery.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"queued-message-delivery.js","sourceRoot":"","sources":["../../src/core/queued-message-delivery.ts"],"names":[],"mappings":"AA6BA,MAAM,QAAQ,GAAG,IAAI,OAAO,EAA6B,CAAC;AAC1D,MAAM,UAAU,GAAG,IAAI,OAAO,EAAiC,CAAC;AAEhE,mHAAmH;AACnH,MAAM,UAAU,0BAA0B,CACzC,OAAe,EACf,IAAmC,EACnC,IAAY;IAEZ,IAAI,UAAU,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACvC,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QAC9B,UAAU,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,IAAI,GAAG,EAAE,EAAE,CAAC;QAC/C,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IACnC,CAAC;IACD,MAAM,QAAQ,GAA0B,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,UAAU,CAAC,KAAK,EAAE,CAAC;IAClF,UAAU,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AAE,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC3F,OAAO,KAAK,CAAC;AACd,CAAC","sourcesContent":["/**\n * A queued message from the moment its turn takes it out of the session's queue until its own `message_start`\n * reaches the session's listeners. Between the two, the session runs the extensions' `message_start` hooks, and the\n * `queue_update` it sent when the turn took the message already lists the queue without it. A chat in this process\n * keeps showing such a message as queued until its own row is in the transcript, so the message is never off screen.\n *\n * Nothing here changes a public event or its order, and nothing crosses a process boundary. Only deliveries still\n * under way are reachable: an event a listener keeps reaches the session's deliveries in flight, never the text of\n * one that ended, and each `queue_update` records a number, not a copy.\n */\nexport interface QueuedMessageDelivery {\n\treadonly lane: \"steer\" | \"followUp\";\n\treadonly text: string;\n\t/** Its place in the order the session's turns took messages. */\n\treadonly order: number;\n}\n\n/** One session's deliveries under way, in the order its turns took them; dropped once none is left. */\ninterface SessionDeliveries {\n\ttaken: number;\n\treadonly underWay: Set<QueuedMessageDelivery>;\n}\n\n/** The deliveries a `queue_update` lists: those of `session` the turns had taken when it was sent, while under way. */\nexport interface QueueUpdateDeliveries {\n\treadonly session: SessionDeliveries;\n\treadonly through: number;\n}\n\nconst sessions = new WeakMap<object, SessionDeliveries>();\nconst listedWith = new WeakMap<object, QueueUpdateDeliveries>();\n\n/** The turn took `text` out of `session`'s `lane` queue; its `message_start` has not reached the listeners yet. */\nexport function beginQueuedMessageDelivery(\n\tsession: object,\n\tlane: QueuedMessageDelivery[\"lane\"],\n\ttext: string,\n): QueuedMessageDelivery {\n\tlet deliveries = sessions.get(session);\n\tif (deliveries === undefined) {\n\t\tdeliveries = { taken: 0, underWay: new Set() };\n\t\tsessions.set(session, deliveries);\n\t}\n\tconst delivery: QueuedMessageDelivery = { lane, text, order: ++deliveries.taken };\n\tdeliveries.underWay.add(delivery);\n\treturn delivery;\n}\n\n/**\n * The message's `message_start` is reaching the listeners now, or never will (a hook failed, or the session already\n * shows the input): it is no longer under way.\n */\nexport function endQueuedMessageDelivery(session: object, delivery: QueuedMessageDelivery | undefined): void {\n\tif (delivery === undefined) return;\n\tconst deliveries = sessions.get(session);\n\tif (deliveries === undefined || !deliveries.underWay.delete(delivery)) return;\n\t// A later delivery starts a new record, which an event sent before it never reaches.\n\tif (deliveries.underWay.size === 0) sessions.delete(session);\n}\n\n/** Record with `event`, a `queue_update` `session` is about to send, which deliveries are under way now. */\nexport function noteQueueUpdateDeliveries(session: object, event: object): void {\n\tconst deliveries = sessions.get(session);\n\tif (deliveries !== undefined) listedWith.set(event, { session: deliveries, through: deliveries.taken });\n}\n\n/** The deliveries `event`, a `queue_update`, lists; undefined when none was under way as it was sent. */\nexport function queueUpdateDeliveries(event: object): QueueUpdateDeliveries | undefined {\n\treturn listedWith.get(event);\n}\n\n/** The texts of `lane` that `listed` still has under way, in the order the turns took them. */\nexport function queuedTextsUnderWay(\n\tlisted: QueueUpdateDeliveries | undefined,\n\tlane: QueuedMessageDelivery[\"lane\"],\n): string[] {\n\tif (listed === undefined) return [];\n\tconst texts: string[] = [];\n\tfor (const delivery of listed.session.underWay)\n\t\tif (delivery.lane === lane && delivery.order <= listed.through) texts.push(delivery.text);\n\treturn texts;\n}\n"]}
1
+ {"version":3,"file":"queued-message-delivery.js","sourceRoot":"","sources":["../../src/core/queued-message-delivery.ts"],"names":[],"mappings":"AAwBA,yFAAyF;AACzF,MAAM,CAAC,MAAM,kBAAkB,GAAuB,MAAM,CAAC,MAAM,CAAC;IACnE,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;IAC3B,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;CAC3B,CAAC,CAAC;AAgBH,MAAM,QAAQ,GAAG,IAAI,OAAO,EAA6B,CAAC;AAC1D,MAAM,UAAU,GAAG,IAAI,OAAO,EAAiC,CAAC;AAChE,iEAAiE;AACjE,MAAM,QAAQ,GAAG,IAAI,OAAO,EAAyB,CAAC;AAEtD,mHAAmH;AACnH,MAAM,UAAU,0BAA0B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AC;IACD,OAAO;QACN,GAAG,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5D,GAAG,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACjD,CAAC;AACH,CAAC","sourcesContent":["/**\n * A queued message from the moment its turn takes it out of the session's queue until its own `message_start`\n * reaches the session's listeners. Between the two, the session runs the extensions' `message_start` hooks, and the\n * `queue_update` it sent when the turn took the message already lists the queue without it. A chat keeps showing such\n * a message as queued until its own row is in the transcript, so the message is never off screen.\n *\n * Nothing here changes a public event or its order. Only deliveries still under way are reachable: an event a listener\n * keeps reaches the session's deliveries in flight, never the text of one that ended, and each `queue_update` records a\n * number, not a copy. An isolated engine tells its host about them with {@link QueuedDeliveryRelay}: each message's\n * text crosses once, when a `queue_update` first names it, and its end crosses as a count.\n */\nexport interface QueuedMessageDelivery {\n\treadonly lane: \"steer\" | \"followUp\";\n\treadonly text: string;\n\t/** Its place in the order the session's turns took messages. */\n\treadonly order: number;\n}\n\n/** Messages per lane, each lane in the order the turns took them. */\nexport interface QueuedMessageLanes {\n\treadonly steering: readonly string[];\n\treadonly followUp: readonly string[];\n}\n\n/** The lanes with no message: what every chat draws while nothing is being delivered. */\nexport const NO_QUEUED_MESSAGES: QueuedMessageLanes = Object.freeze({\n\tsteering: Object.freeze([]),\n\tfollowUp: Object.freeze([]),\n});\n\n/** One session's deliveries under way, by their order, in the order its turns took them; dropped once none is left. */\ninterface SessionDeliveries {\n\ttaken: number;\n\treadonly underWay: Map<number, QueuedMessageDelivery>;\n\t/** The texts under way per lane, kept until the next delivery begins or ends, so an unchanged one is the same. */\n\tlanes?: QueuedMessageLanes;\n}\n\n/** The deliveries a `queue_update` lists: those of `session` the turns had taken when it was sent, while under way. */\nexport interface QueueUpdateDeliveries {\n\treadonly session: SessionDeliveries;\n\treadonly through: number;\n}\n\nconst sessions = new WeakMap<object, SessionDeliveries>();\nconst listedWith = new WeakMap<object, QueueUpdateDeliveries>();\n/** Every delivery under way, whichever session it belongs to. */\nconst underWay = new WeakSet<QueuedMessageDelivery>();\n\n/** The turn took `text` out of `session`'s `lane` queue; its `message_start` has not reached the listeners yet. */\nexport function beginQueuedMessageDelivery(\n\tsession: object,\n\tlane: QueuedMessageDelivery[\"lane\"],\n\ttext: string,\n): QueuedMessageDelivery {\n\tlet deliveries = sessions.get(session);\n\tif (deliveries === undefined) {\n\t\tdeliveries = { taken: 0, underWay: new Map() };\n\t\tsessions.set(session, deliveries);\n\t}\n\tconst delivery: QueuedMessageDelivery = { lane, text, order: ++deliveries.taken };\n\tdeliveries.underWay.set(delivery.order, delivery);\n\tdeliveries.lanes = undefined;\n\tunderWay.add(delivery);\n\treturn delivery;\n}\n\n/**\n * The message's `message_start` is reaching the listeners now, or never will (a hook failed, or the session already\n * shows the input): it is no longer under way.\n */\nexport function endQueuedMessageDelivery(session: object, delivery: QueuedMessageDelivery | undefined): void {\n\tif (delivery === undefined) return;\n\tconst deliveries = sessions.get(session);\n\tif (deliveries?.underWay.get(delivery.order) !== delivery) return;\n\tdeliveries.underWay.delete(delivery.order);\n\tdeliveries.lanes = undefined;\n\tunderWay.delete(delivery);\n\t// A later delivery starts a new record, which an event sent before it never reaches.\n\tif (deliveries.underWay.size === 0) sessions.delete(session);\n}\n\n/** Record with `event`, a `queue_update` `session` is about to send, which deliveries are under way now. */\nexport function noteQueueUpdateDeliveries(session: object, event: object): void {\n\tconst deliveries = sessions.get(session);\n\tif (deliveries !== undefined) listedWith.set(event, { session: deliveries, through: deliveries.taken });\n}\n\n/** The deliveries `event`, a `queue_update`, lists; undefined when none was under way as it was sent. */\nexport function queueUpdateDeliveries(event: object): QueueUpdateDeliveries | undefined {\n\treturn listedWith.get(event);\n}\n\n/** The texts of `lane` that `listed` still has under way, in the order the turns took them. */\nexport function queuedTextsUnderWay(\n\tlisted: QueueUpdateDeliveries | undefined,\n\tlane: QueuedMessageDelivery[\"lane\"],\n): string[] {\n\tif (listed === undefined) return [];\n\tconst texts: string[] = [];\n\tfor (const delivery of listed.session.underWay.values())\n\t\tif (delivery.lane === lane && delivery.order <= listed.through) texts.push(delivery.text);\n\treturn texts;\n}\n\n/**\n * Every message `session` is delivering now, per lane. The session's queue lists none of them, so a chat that reads\n * the queue and this at the same moment shows each queued message once. The same object until a delivery begins or\n * ends; {@link NO_QUEUED_MESSAGES} when none is under way.\n */\nexport function queuedMessagesUnderWay(session: object): QueuedMessageLanes {\n\tconst deliveries = sessions.get(session);\n\tif (deliveries === undefined) return NO_QUEUED_MESSAGES;\n\tdeliveries.lanes ??= lanesOf(deliveries.underWay.values());\n\treturn deliveries.lanes;\n}\n\n/** A message a turn took, as an engine names it to its host. */\nexport interface QueuedDeliveryEntry {\n\treadonly lane: QueuedMessageDelivery[\"lane\"];\n\treadonly text: string;\n}\n\n/**\n * What changed in the deliveries an engine told its host about: the `ended` oldest of them are no longer under way,\n * then the turns took `taken`, in order.\n */\nexport interface QueuedDeliveryChange {\n\treadonly ended?: number;\n\treadonly taken?: readonly QueuedDeliveryEntry[];\n}\n\n/**\n * The engine's side of the deliveries its host draws for the main chat. With each event it sends, {@link note} answers\n * what the host has to learn: the messages a `queue_update` names that the host was not told about, and how many of the\n * ones it was told about are no longer under way. Deliveries end in the order the turns took them (the session handles\n * their events one at a time), so the ended ones are always the oldest; one that ended out of order is counted once\n * those before it have. Each event costs constant time, apart from the messages it names.\n */\nexport class QueuedDeliveryRelay {\n\t/**\n\t * The deliveries the host was told about and not told ended, oldest first, from `head` on. A slot before `head` is\n\t * cleared as it is passed, so no message ended is kept.\n\t */\n\tprivate told: (QueuedMessageDelivery | undefined)[] = [];\n\tprivate head = 0;\n\t/** The record of the session's deliveries the host was last told about, and the last order it was told. */\n\tprivate toldRecord: SessionDeliveries | undefined;\n\tprivate toldThrough = 0;\n\tprivate readonly retired = new WeakSet<object>();\n\n\t/** The change to send with `event`, which `session` sends now; undefined when there is none to send with it. */\n\tnote(session: object, event: { readonly type: string }): QueuedDeliveryChange | undefined {\n\t\t// Before it is written, a newer update of the same tool call can replace a tool update, and a change with it.\n\t\tif (event.type === \"tool_execution_update\" || this.retired.has(session)) return undefined;\n\t\tconst start = this.head;\n\t\tfor (let next = this.told[this.head]; next !== undefined && !underWay.has(next); next = this.told[this.head]) {\n\t\t\tthis.told[this.head] = undefined;\n\t\t\tthis.head++;\n\t\t}\n\t\tconst ended = this.head - start;\n\t\tconst taken = event.type === \"queue_update\" ? this.newlyListed(event) : [];\n\t\t// Drop the told ones that ended once they are most of the list: each delivery is moved at most once.\n\t\tif (this.head > 0 && this.head * 2 >= this.told.length) {\n\t\t\tthis.told = this.told.slice(this.head);\n\t\t\tthis.head = 0;\n\t\t}\n\t\tfor (const delivery of taken) this.told.push(delivery);\n\t\tif (ended === 0 && taken.length === 0) return undefined;\n\t\treturn {\n\t\t\t...(ended > 0 ? { ended } : {}),\n\t\t\t...(taken.length > 0 ? { taken: taken.map(({ lane, text }) => ({ lane, text })) } : {}),\n\t\t};\n\t}\n\n\t/** The deliveries `event`, a `queue_update`, lists that the host was not told about, oldest first. */\n\tprivate newlyListed(event: object): QueuedMessageDelivery[] {\n\t\tconst listed = listedWith.get(event);\n\t\tif (listed === undefined) return [];\n\t\tif (listed.session !== this.toldRecord) {\n\t\t\tthis.toldRecord = listed.session;\n\t\t\tthis.toldThrough = 0;\n\t\t}\n\t\tconst taken: QueuedMessageDelivery[] = [];\n\t\tfor (let order = this.toldThrough + 1; order <= listed.through; order++) {\n\t\t\tconst delivery = listed.session.underWay.get(order);\n\t\t\tif (delivery !== undefined) taken.push(delivery);\n\t\t}\n\t\tthis.toldThrough = Math.max(this.toldThrough, listed.through);\n\t\treturn taken;\n\t}\n\n\t/**\n\t * `session` is being replaced, and the host forgets every delivery it was told about. Its events from now on carry no\n\t * change: the host shows the replacement.\n\t */\n\tretire(session: object): void {\n\t\tthis.retired.add(session);\n\t\tthis.told = [];\n\t\tthis.head = 0;\n\t\tthis.toldRecord = undefined;\n\t\tthis.toldThrough = 0;\n\t}\n}\n\n/** The end a line brought, kept until its event reaches the chat; it holds a count, never a message. */\nexport interface QueuedDeliveryEnd {\n\treadonly ended: number;\n\t/** The view's reset count when the line was read: an end read before a reset never applies. */\n\treadonly resets: number;\n}\n\n/**\n * A host's view of what its engine's main session is delivering: the messages the engine said its turns took, oldest\n * first, each until the event that ends it reaches the chat. A line's taken messages join when the host reads it, with\n * the cached queue that no longer lists them; its ended count waits for its event, which may be held back from the chat\n * (a compaction's end holds later events until the session view caught up), so a message leaves in the step its own\n * row is drawn. Losing the engine or its retiring the session forgets everything at once.\n */\nexport class QueuedDeliveryView {\n\tprivate entries: readonly QueuedDeliveryEntry[] = [];\n\tprivate lanes: QueuedMessageLanes = NO_QUEUED_MESSAGES;\n\tprivate resets = 0;\n\n\t/** The messages being delivered, per lane; the same object until they change. */\n\tget texts(): QueuedMessageLanes {\n\t\treturn this.lanes;\n\t}\n\n\t/** A line brought `change`: what it took joins now; its end, returned, applies when its event reaches the chat. */\n\treceive(change: QueuedDeliveryChange): QueuedDeliveryEnd | undefined {\n\t\tif (change.taken !== undefined && change.taken.length > 0) this.set([...this.entries, ...change.taken]);\n\t\treturn change.ended === undefined || change.ended === 0\n\t\t\t? undefined\n\t\t\t: { ended: change.ended, resets: this.resets };\n\t}\n\n\t/** The event that carried `end` reaches the chat now: the oldest messages it ended leave. */\n\tend(end: QueuedDeliveryEnd): void {\n\t\tif (end.resets === this.resets) this.set(this.entries.slice(end.ended));\n\t}\n\n\t/** Forget every message; an end read before now never applies. Answers whether any was listed. */\n\treset(): boolean {\n\t\tthis.resets++;\n\t\tif (this.entries.length === 0) return false;\n\t\tthis.set([]);\n\t\treturn true;\n\t}\n\n\tprivate set(entries: readonly QueuedDeliveryEntry[]): void {\n\t\tthis.entries = entries;\n\t\tthis.lanes = lanesOf(entries);\n\t}\n}\n\nfunction lanesOf(deliveries: Iterable<QueuedDeliveryEntry>): QueuedMessageLanes {\n\tconst steering: string[] = [];\n\tconst followUp: string[] = [];\n\tfor (const delivery of deliveries) (delivery.lane === \"steer\" ? steering : followUp).push(delivery.text);\n\treturn steering.length === 0 && followUp.length === 0 ? NO_QUEUED_MESSAGES : { steering, followUp };\n}\n\n/**\n * The field of an engine's event line that carries a change in deliveries. An engine writes it only for a host that\n * asked for it when it started the engine, so a host of an earlier version never receives it.\n */\nconst CHANGE_FIELD = \"atomicQueuedDeliveries\";\n\n/** `record`, an event line an engine writes, with `change` when there is one. */\nexport function withQueuedDeliveryChange(record: object, change: QueuedDeliveryChange | undefined): object {\n\treturn change === undefined ? record : { ...record, [CHANGE_FIELD]: change };\n}\n\n/**\n * Take the change in deliveries off `event`, an event line the host read from its engine, before anything else sees\n * the event: its listeners get it as the engine's session sent it, and keeping it keeps no message text.\n */\nexport function takeQueuedDeliveryChange(event: object): QueuedDeliveryChange | undefined {\n\tif (!(CHANGE_FIELD in event)) return undefined;\n\tconst data = event as { [CHANGE_FIELD]?: unknown };\n\tconst change = parseQueuedDeliveryChange(data[CHANGE_FIELD]);\n\tdelete data[CHANGE_FIELD];\n\treturn change;\n}\n\n/** `value` as a change in deliveries, as an engine writes one; undefined for anything else. */\nfunction parseQueuedDeliveryChange(value: unknown): QueuedDeliveryChange | undefined {\n\tif (typeof value !== \"object\" || value === null || Array.isArray(value)) return undefined;\n\tconst { ended, taken } = value as { ended?: unknown; taken?: unknown };\n\tif (ended !== undefined && !(typeof ended === \"number\" && Number.isSafeInteger(ended) && ended >= 0))\n\t\treturn undefined;\n\tif (taken !== undefined && !Array.isArray(taken)) return undefined;\n\tconst entries: QueuedDeliveryEntry[] = [];\n\tfor (const entry of (taken as unknown[] | undefined) ?? []) {\n\t\tif (typeof entry !== \"object\" || entry === null) return undefined;\n\t\tconst { lane, text } = entry as { lane?: unknown; text?: unknown };\n\t\tif ((lane !== \"steer\" && lane !== \"followUp\") || typeof text !== \"string\") return undefined;\n\t\tentries.push({ lane, text });\n\t}\n\treturn {\n\t\t...(typeof ended === \"number\" && ended > 0 ? { ended } : {}),\n\t\t...(entries.length > 0 ? { taken: entries } : {}),\n\t};\n}\n"]}
@@ -0,0 +1,32 @@
1
+ import type { AgentMessage, ThinkingLevel } from "@bastani/atomic-agent-core";
2
+ import type { Message, ThinkingBudgets } from "@bastani/atomic-ai";
3
+ /**
4
+ * The message a resumed session's history ends with, as its last request before the exit sent it or as that request's
5
+ * reply. A resume appends blueprint context before the session starts; that was never sent, so it is not part of it.
6
+ * A system message is skipped too: requests may rebuild system messages as new objects, so it could not be found in
7
+ * them, and the breakpoint goes on the input before it anyway.
8
+ */
9
+ export declare function restoredCacheCheckpoint(messages: readonly AgentMessage[]): AgentMessage | undefined;
10
+ export interface CacheCheckpointResult {
11
+ converted: Message[];
12
+ /** False once the checkpoint is answered or gone: later requests extend a prefix their own previous request cached. */
13
+ keep: boolean;
14
+ }
15
+ /**
16
+ * Ask for a prompt-cache breakpoint at `checkpoint` in the provider messages `converted` from `messages`, so the first
17
+ * request after a resume finds the prefix the last request before the exit cached, however much the resume appended
18
+ * after it. `rows` holds the provider message each input message became, by position. Kept until a reply after the
19
+ * checkpoint is answered. The marked message is a copy; the transcript is not changed.
20
+ */
21
+ export declare function withCacheCheckpoint(messages: readonly AgentMessage[], rows: readonly (Message | undefined)[], converted: Message[], checkpoint: AgentMessage): CacheCheckpointResult;
22
+ /**
23
+ * The thinking budgets a resumed session continues with. While it resumes on the model and thinking level of its last
24
+ * recorded reply, that reply's budget stays, as it would in a session that kept running: a changed settings file or a
25
+ * newer default budget would change the cached request. An explicit model or level change at resume, and a history
26
+ * with no recorded budget, use `configured`.
27
+ */
28
+ export declare function restoredThinkingBudgets(messages: readonly AgentMessage[], model: {
29
+ provider: string;
30
+ id: string;
31
+ } | undefined, thinkingLevel: ThinkingLevel | undefined, configured: ThinkingBudgets | undefined): ThinkingBudgets | undefined;
32
+ //# sourceMappingURL=resume-cache-checkpoint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resume-cache-checkpoint.d.ts","sourceRoot":"","sources":["../../src/core/resume-cache-checkpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC9E,OAAO,KAAK,EAAoB,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGrF;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,SAAS,YAAY,EAAE,GAAG,YAAY,GAAG,SAAS,CAQnG;AASD,MAAM,WAAW,qBAAqB;IACrC,SAAS,EAAE,OAAO,EAAE,CAAC;IACrB,uHAAuH;IACvH,IAAI,EAAE,OAAO,CAAC;CACd;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAClC,QAAQ,EAAE,SAAS,YAAY,EAAE,EACjC,IAAI,EAAE,SAAS,CAAC,OAAO,GAAG,SAAS,CAAC,EAAE,EACtC,SAAS,EAAE,OAAO,EAAE,EACpB,UAAU,EAAE,YAAY,GACtB,qBAAqB,CAavB;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACtC,QAAQ,EAAE,SAAS,YAAY,EAAE,EACjC,KAAK,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,EACnD,aAAa,EAAE,aAAa,GAAG,SAAS,EACxC,UAAU,EAAE,eAAe,GAAG,SAAS,GACrC,eAAe,GAAG,SAAS,CAY7B"}
@@ -0,0 +1,67 @@
1
+ import { BLUEPRINT_CONTEXT_TYPE } from "./resume/blueprint/context.js";
2
+ /**
3
+ * The message a resumed session's history ends with, as its last request before the exit sent it or as that request's
4
+ * reply. A resume appends blueprint context before the session starts; that was never sent, so it is not part of it.
5
+ * A system message is skipped too: requests may rebuild system messages as new objects, so it could not be found in
6
+ * them, and the breakpoint goes on the input before it anyway.
7
+ */
8
+ export function restoredCacheCheckpoint(messages) {
9
+ for (let index = messages.length - 1; index >= 0; index--) {
10
+ const message = messages[index];
11
+ if (message.role === "system")
12
+ continue;
13
+ if (message.role === "custom" && message.customType === BLUEPRINT_CONTEXT_TYPE)
14
+ continue;
15
+ return message;
16
+ }
17
+ return undefined;
18
+ }
19
+ function isAnsweredReply(message) {
20
+ return (message.role === "assistant" &&
21
+ (message.stopReason === "stop" || message.stopReason === "toolUse" || message.stopReason === "length"));
22
+ }
23
+ /**
24
+ * Ask for a prompt-cache breakpoint at `checkpoint` in the provider messages `converted` from `messages`, so the first
25
+ * request after a resume finds the prefix the last request before the exit cached, however much the resume appended
26
+ * after it. `rows` holds the provider message each input message became, by position. Kept until a reply after the
27
+ * checkpoint is answered. The marked message is a copy; the transcript is not changed.
28
+ */
29
+ export function withCacheCheckpoint(messages, rows, converted, checkpoint) {
30
+ const index = messages.indexOf(checkpoint);
31
+ if (index === -1 || messages.slice(index + 1).some(isAnsweredReply))
32
+ return { converted, keep: false };
33
+ for (let source = index; source >= 0; source--) {
34
+ const row = rows[source];
35
+ if (row === undefined || row.role === "system")
36
+ continue;
37
+ const at = converted.indexOf(row);
38
+ if (at === -1)
39
+ continue;
40
+ const marked = converted.slice();
41
+ marked[at] = { ...row, cacheBreakpoint: true };
42
+ return { converted: marked, keep: true };
43
+ }
44
+ return { converted, keep: true };
45
+ }
46
+ /**
47
+ * The thinking budgets a resumed session continues with. While it resumes on the model and thinking level of its last
48
+ * recorded reply, that reply's budget stays, as it would in a session that kept running: a changed settings file or a
49
+ * newer default budget would change the cached request. An explicit model or level change at resume, and a history
50
+ * with no recorded budget, use `configured`.
51
+ */
52
+ export function restoredThinkingBudgets(messages, model, thinkingLevel, configured) {
53
+ if (!model || thinkingLevel === undefined || thinkingLevel === "off")
54
+ return configured;
55
+ for (let index = messages.length - 1; index >= 0; index--) {
56
+ const message = messages[index];
57
+ if (message.role !== "assistant" || message.requestedThinkingBudget === undefined)
58
+ continue;
59
+ const recordedLevel = message.thinkingLevel;
60
+ if (message.provider !== model.provider || message.model !== model.id || recordedLevel !== thinkingLevel)
61
+ return configured;
62
+ const level = thinkingLevel === "xhigh" || thinkingLevel === "max" ? "high" : thinkingLevel;
63
+ return { ...configured, [level]: message.requestedThinkingBudget };
64
+ }
65
+ return configured;
66
+ }
67
+ //# sourceMappingURL=resume-cache-checkpoint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resume-cache-checkpoint.js","sourceRoot":"","sources":["../../src/core/resume-cache-checkpoint.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAEvE;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CAAC,QAAiC;IACxE,KAAK,IAAI,KAAK,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;QAC3D,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAE,CAAC;QACjC,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ;YAAE,SAAS;QACxC,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ,IAAI,OAAO,CAAC,UAAU,KAAK,sBAAsB;YAAE,SAAS;QACzF,OAAO,OAAO,CAAC;IAChB,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC;AAED,SAAS,eAAe,CAAC,OAAqB;IAC7C,OAAO,CACN,OAAO,CAAC,IAAI,KAAK,WAAW;QAC5B,CAAC,OAAO,CAAC,UAAU,KAAK,MAAM,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS,IAAI,OAAO,CAAC,UAAU,KAAK,QAAQ,CAAC,CACtG,CAAC;AACH,CAAC;AAQD;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAClC,QAAiC,EACjC,IAAsC,EACtC,SAAoB,EACpB,UAAwB;IAExB,MAAM,KAAK,GAAG,QAAQ,CAAC,OA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CAAC,IAAI,KAAK,WAAW,IAAI,OAAO,CAAC,uBAAuB,KAAK,SAAS;YAAE,SAAS;QAC5F,MAAM,aAAa,GAAI,OAAyD,CAAC,aAAa,CAAC;QAC/F,IAAI,OAAO,CAAC,QAAQ,KAAK,KAAK,CAAC,QAAQ,IAAI,OAAO,CAAC,KAAK,KAAK,KAAK,CAAC,EAAE,IAAI,aAAa,KAAK,aAAa;YACvG,OAAO,UAAU,CAAC;QACnB,MAAM,KAAK,GAAG,aAAa,KAAK,OAAO,IAAI,aAAa,KAAK,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,aAAa,CAAC;QAC5F,OAAO,EAAE,GAAG,UAAU,EAAE,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,uBAAuB,EAAE,CAAC;IACpE,CAAC;IACD,OAAO,UAAU,CAAC;AACnB,CAAC","sourcesContent":["import type { AgentMessage, ThinkingLevel } from \"@bastani/atomic-agent-core\";\nimport type { AssistantMessage, Message, ThinkingBudgets } from \"@bastani/atomic-ai\";\nimport { BLUEPRINT_CONTEXT_TYPE } from \"./resume/blueprint/context.ts\";\n\n/**\n * The message a resumed session's history ends with, as its last request before the exit sent it or as that request's\n * reply. A resume appends blueprint context before the session starts; that was never sent, so it is not part of it.\n * A system message is skipped too: requests may rebuild system messages as new objects, so it could not be found in\n * them, and the breakpoint goes on the input before it anyway.\n */\nexport function restoredCacheCheckpoint(messages: readonly AgentMessage[]): AgentMessage | undefined {\n\tfor (let index = messages.length - 1; index >= 0; index--) {\n\t\tconst message = messages[index]!;\n\t\tif (message.role === \"system\") continue;\n\t\tif (message.role === \"custom\" && message.customType === BLUEPRINT_CONTEXT_TYPE) continue;\n\t\treturn message;\n\t}\n\treturn undefined;\n}\n\nfunction isAnsweredReply(message: AgentMessage): boolean {\n\treturn (\n\t\tmessage.role === \"assistant\" &&\n\t\t(message.stopReason === \"stop\" || message.stopReason === \"toolUse\" || message.stopReason === \"length\")\n\t);\n}\n\nexport interface CacheCheckpointResult {\n\tconverted: Message[];\n\t/** False once the checkpoint is answered or gone: later requests extend a prefix their own previous request cached. */\n\tkeep: boolean;\n}\n\n/**\n * Ask for a prompt-cache breakpoint at `checkpoint` in the provider messages `converted` from `messages`, so the first\n * request after a resume finds the prefix the last request before the exit cached, however much the resume appended\n * after it. `rows` holds the provider message each input message became, by position. Kept until a reply after the\n * checkpoint is answered. The marked message is a copy; the transcript is not changed.\n */\nexport function withCacheCheckpoint(\n\tmessages: readonly AgentMessage[],\n\trows: readonly (Message | undefined)[],\n\tconverted: Message[],\n\tcheckpoint: AgentMessage,\n): CacheCheckpointResult {\n\tconst index = messages.indexOf(checkpoint);\n\tif (index === -1 || messages.slice(index + 1).some(isAnsweredReply)) return { converted, keep: false };\n\tfor (let source = index; source >= 0; source--) {\n\t\tconst row = rows[source];\n\t\tif (row === undefined || row.role === \"system\") continue;\n\t\tconst at = converted.indexOf(row);\n\t\tif (at === -1) continue;\n\t\tconst marked = converted.slice();\n\t\tmarked[at] = { ...row, cacheBreakpoint: true };\n\t\treturn { converted: marked, keep: true };\n\t}\n\treturn { converted, keep: true };\n}\n\n/**\n * The thinking budgets a resumed session continues with. While it resumes on the model and thinking level of its last\n * recorded reply, that reply's budget stays, as it would in a session that kept running: a changed settings file or a\n * newer default budget would change the cached request. An explicit model or level change at resume, and a history\n * with no recorded budget, use `configured`.\n */\nexport function restoredThinkingBudgets(\n\tmessages: readonly AgentMessage[],\n\tmodel: { provider: string; id: string } | undefined,\n\tthinkingLevel: ThinkingLevel | undefined,\n\tconfigured: ThinkingBudgets | undefined,\n): ThinkingBudgets | undefined {\n\tif (!model || thinkingLevel === undefined || thinkingLevel === \"off\") return configured;\n\tfor (let index = messages.length - 1; index >= 0; index--) {\n\t\tconst message = messages[index]!;\n\t\tif (message.role !== \"assistant\" || message.requestedThinkingBudget === undefined) continue;\n\t\tconst recordedLevel = (message as AssistantMessage & { thinkingLevel?: string }).thinkingLevel;\n\t\tif (message.provider !== model.provider || message.model !== model.id || recordedLevel !== thinkingLevel)\n\t\t\treturn configured;\n\t\tconst level = thinkingLevel === \"xhigh\" || thinkingLevel === \"max\" ? \"high\" : thinkingLevel;\n\t\treturn { ...configured, [level]: message.requestedThinkingBudget };\n\t}\n\treturn configured;\n}\n"]}
@@ -151,6 +151,13 @@ export interface CreateAgentSessionOptions {
151
151
  * child makes.
152
152
  */
153
153
  parentUsageSink?: (usage: import("@bastani/atomic-ai/compat").Usage) => void;
154
+ /**
155
+ * Internal: in options from `getChildSessionOptions()`, the tools the parent's requests declare but hide (codemode
156
+ * reaches them), so a fork of its conversation sends that conversation as the parent did.
157
+ */
158
+ parentHiddenTools?: readonly string[];
159
+ /** Internal: in options from `getChildSessionOptions()`, the tools the parent's requests declare. */
160
+ parentToolNames?: readonly string[];
154
161
  /**
155
162
  * Internal: called with `true` when this session starts waiting for its resource-admission permit and `false` when
156
163
  * the wait ends, so an in-process subagent's start budget can tell that wait from the rest of its setup.
@@ -165,9 +172,39 @@ export interface CreateAgentSessionOptions {
165
172
  releaseWhenIdle?: ReleaseWhenIdleOptions;
166
173
  /** Transform the fully constructed base system prompt at session construction. */
167
174
  systemPromptTransform?: (prompt: string) => string;
175
+ /**
176
+ * Internal: `systemPromptTransform` applied section by section. With it the session keeps sending the transformed
177
+ * prompt it first sent, also after it is reopened, and tells the model later changes as section updates.
178
+ */
179
+ systemPromptSections?: SystemPromptSectionsTransform;
168
180
  /** Filter inherited session messages before they enter the new AgentSession. */
169
181
  initialContextTransform?: (messages: AgentMessage[]) => AgentMessage[];
170
182
  }
183
+ /** `systemPromptTransform` applied to each section of the structured prompt; see `CreateAgentSessionOptions`. */
184
+ export interface SystemPromptSectionsTransform {
185
+ /**
186
+ * What the transform lets the prompt hold, such as which inherited instructions it keeps. A prompt the session sent
187
+ * under another key, or that another session sent, is not sent again: the session sends its current prompt instead.
188
+ */
189
+ readonly key: string;
190
+ /** Each section as the transformed prompt holds it, keyed and ordered as in that prompt; one it drops is absent. */
191
+ readonly transform: (sections: Record<string, string>) => Record<string, string>;
192
+ /**
193
+ * The session continues another session's conversation (a forked subagent). Its first request sends that
194
+ * conversation exactly as the other session last sent it, so it is read from that session's prompt cache, then a
195
+ * note and the session's own sections after it. Its requests use `sessionId` as their prompt-cache key.
196
+ */
197
+ readonly fork?: {
198
+ readonly sessionId: string;
199
+ /** The tools the other session's requests declared but hid; see `parentHiddenTools`. */
200
+ readonly hiddenTools?: readonly string[];
201
+ /** The note that opens what the fork adds: the tools it may call, and those it reaches through codemode. */
202
+ readonly note: (tools: {
203
+ readonly tools: readonly string[];
204
+ readonly throughCodemode: readonly string[];
205
+ }) => string;
206
+ };
207
+ }
171
208
  export interface ResourceAdmissionRequest {
172
209
  readonly delegated?: boolean;
173
210
  }
@@ -1 +1 @@
1
- {"version":3,"file":"sdk-types.d.ts","sourceRoot":"","sources":["../../src/core/sdk-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC9E,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACzE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,EACX,oBAAoB,EACpB,iBAAiB,EACjB,mBAAmB,EACnB,cAAc,EACd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,eAAe,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