agentenkit 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (216) hide show
  1. package/README.md +34 -14
  2. package/dist/adapters/inline.d.ts +19 -5
  3. package/dist/adapters/inline.d.ts.map +1 -1
  4. package/dist/adapters/inline.js +87 -14
  5. package/dist/adapters/inline.js.map +1 -1
  6. package/dist/adapters/memory.d.ts +65 -3
  7. package/dist/adapters/memory.d.ts.map +1 -1
  8. package/dist/adapters/memory.js +267 -3
  9. package/dist/adapters/memory.js.map +1 -1
  10. package/dist/adapters/prisma.d.ts +125 -18
  11. package/dist/adapters/prisma.d.ts.map +1 -1
  12. package/dist/adapters/prisma.js +308 -67
  13. package/dist/adapters/prisma.js.map +1 -1
  14. package/dist/adapters/qstash.d.ts +15 -2
  15. package/dist/adapters/qstash.d.ts.map +1 -1
  16. package/dist/adapters/qstash.js +31 -14
  17. package/dist/adapters/qstash.js.map +1 -1
  18. package/dist/adapters/redis.d.ts +40 -4
  19. package/dist/adapters/redis.d.ts.map +1 -1
  20. package/dist/adapters/redis.js +265 -20
  21. package/dist/adapters/redis.js.map +1 -1
  22. package/dist/adapters/sqlite.d.ts +52 -2
  23. package/dist/adapters/sqlite.d.ts.map +1 -1
  24. package/dist/adapters/sqlite.js +342 -35
  25. package/dist/adapters/sqlite.js.map +1 -1
  26. package/dist/adapters/stream-scripts.d.ts +49 -0
  27. package/dist/adapters/stream-scripts.d.ts.map +1 -0
  28. package/dist/adapters/stream-scripts.js +150 -0
  29. package/dist/adapters/stream-scripts.js.map +1 -0
  30. package/dist/adapters/upstash.d.ts +20 -0
  31. package/dist/adapters/upstash.d.ts.map +1 -1
  32. package/dist/adapters/upstash.js +29 -0
  33. package/dist/adapters/upstash.js.map +1 -1
  34. package/dist/admin/memory.d.ts +11 -1
  35. package/dist/admin/memory.d.ts.map +1 -1
  36. package/dist/admin/memory.js +83 -14
  37. package/dist/admin/memory.js.map +1 -1
  38. package/dist/admin/migrations/postgres/0002-run-settled-at.d.ts +5 -0
  39. package/dist/admin/migrations/postgres/0002-run-settled-at.d.ts.map +1 -0
  40. package/dist/admin/migrations/postgres/0002-run-settled-at.js +11 -0
  41. package/dist/admin/migrations/postgres/0002-run-settled-at.js.map +1 -0
  42. package/dist/admin/migrations/postgres/0003-run-enqueued-at.d.ts +5 -0
  43. package/dist/admin/migrations/postgres/0003-run-enqueued-at.d.ts.map +1 -0
  44. package/dist/admin/migrations/postgres/0003-run-enqueued-at.js +15 -0
  45. package/dist/admin/migrations/postgres/0003-run-enqueued-at.js.map +1 -0
  46. package/dist/admin/migrations/postgres/0004-run-settle-claim.d.ts +5 -0
  47. package/dist/admin/migrations/postgres/0004-run-settle-claim.d.ts.map +1 -0
  48. package/dist/admin/migrations/postgres/0004-run-settle-claim.js +15 -0
  49. package/dist/admin/migrations/postgres/0004-run-settle-claim.js.map +1 -0
  50. package/dist/admin/migrations/postgres/0005-bigint-counters.d.ts +5 -0
  51. package/dist/admin/migrations/postgres/0005-bigint-counters.d.ts.map +1 -0
  52. package/dist/admin/migrations/postgres/0005-bigint-counters.js +12 -0
  53. package/dist/admin/migrations/postgres/0005-bigint-counters.js.map +1 -0
  54. package/dist/admin/migrations/postgres/index.d.ts.map +1 -1
  55. package/dist/admin/migrations/postgres/index.js +16 -1
  56. package/dist/admin/migrations/postgres/index.js.map +1 -1
  57. package/dist/admin/migrations/runner.d.ts +21 -1
  58. package/dist/admin/migrations/runner.d.ts.map +1 -1
  59. package/dist/admin/migrations/runner.js +41 -4
  60. package/dist/admin/migrations/runner.js.map +1 -1
  61. package/dist/admin/migrations/sqlite/0002-run-settled-at.d.ts +5 -0
  62. package/dist/admin/migrations/sqlite/0002-run-settled-at.d.ts.map +1 -0
  63. package/dist/admin/migrations/sqlite/0002-run-settled-at.js +11 -0
  64. package/dist/admin/migrations/sqlite/0002-run-settled-at.js.map +1 -0
  65. package/dist/admin/migrations/sqlite/0003-run-enqueued-at.d.ts +5 -0
  66. package/dist/admin/migrations/sqlite/0003-run-enqueued-at.d.ts.map +1 -0
  67. package/dist/admin/migrations/sqlite/0003-run-enqueued-at.js +15 -0
  68. package/dist/admin/migrations/sqlite/0003-run-enqueued-at.js.map +1 -0
  69. package/dist/admin/migrations/sqlite/0004-run-settle-claim.d.ts +5 -0
  70. package/dist/admin/migrations/sqlite/0004-run-settle-claim.d.ts.map +1 -0
  71. package/dist/admin/migrations/sqlite/0004-run-settle-claim.js +15 -0
  72. package/dist/admin/migrations/sqlite/0004-run-settle-claim.js.map +1 -0
  73. package/dist/admin/migrations/sqlite/index.d.ts +2 -2
  74. package/dist/admin/migrations/sqlite/index.d.ts.map +1 -1
  75. package/dist/admin/migrations/sqlite/index.js +17 -3
  76. package/dist/admin/migrations/sqlite/index.js.map +1 -1
  77. package/dist/admin/postgres.d.ts +14 -4
  78. package/dist/admin/postgres.d.ts.map +1 -1
  79. package/dist/admin/postgres.js +131 -36
  80. package/dist/admin/postgres.js.map +1 -1
  81. package/dist/admin/shared.d.ts +19 -0
  82. package/dist/admin/shared.d.ts.map +1 -0
  83. package/dist/admin/shared.js +28 -0
  84. package/dist/admin/shared.js.map +1 -0
  85. package/dist/admin/sqlite.d.ts +9 -1
  86. package/dist/admin/sqlite.d.ts.map +1 -1
  87. package/dist/admin/sqlite.js +112 -29
  88. package/dist/admin/sqlite.js.map +1 -1
  89. package/dist/core/admin.d.ts +28 -6
  90. package/dist/core/admin.d.ts.map +1 -1
  91. package/dist/core/admin.js +92 -23
  92. package/dist/core/admin.js.map +1 -1
  93. package/dist/core/agent.d.ts +7 -4
  94. package/dist/core/agent.d.ts.map +1 -1
  95. package/dist/core/agent.js +15 -11
  96. package/dist/core/agent.js.map +1 -1
  97. package/dist/core/agui.d.ts +17 -0
  98. package/dist/core/agui.d.ts.map +1 -0
  99. package/dist/core/agui.js +69 -0
  100. package/dist/core/agui.js.map +1 -0
  101. package/dist/core/context.d.ts +13 -1
  102. package/dist/core/context.d.ts.map +1 -1
  103. package/dist/core/context.js +70 -19
  104. package/dist/core/context.js.map +1 -1
  105. package/dist/core/deleteThread.d.ts.map +1 -1
  106. package/dist/core/deleteThread.js +33 -4
  107. package/dist/core/deleteThread.js.map +1 -1
  108. package/dist/core/engine.d.ts +41 -11
  109. package/dist/core/engine.d.ts.map +1 -1
  110. package/dist/core/engine.js +855 -352
  111. package/dist/core/engine.js.map +1 -1
  112. package/dist/core/follow.d.ts +63 -1
  113. package/dist/core/follow.d.ts.map +1 -1
  114. package/dist/core/follow.js +293 -16
  115. package/dist/core/follow.js.map +1 -1
  116. package/dist/core/hitl.d.ts +43 -0
  117. package/dist/core/hitl.d.ts.map +1 -1
  118. package/dist/core/hitl.js +163 -35
  119. package/dist/core/hitl.js.map +1 -1
  120. package/dist/core/keys.d.ts +22 -4
  121. package/dist/core/keys.d.ts.map +1 -1
  122. package/dist/core/keys.js +23 -5
  123. package/dist/core/keys.js.map +1 -1
  124. package/dist/core/lease.d.ts +46 -0
  125. package/dist/core/lease.d.ts.map +1 -0
  126. package/dist/core/lease.js +142 -0
  127. package/dist/core/lease.js.map +1 -0
  128. package/dist/core/loop.d.ts +27 -7
  129. package/dist/core/loop.d.ts.map +1 -1
  130. package/dist/core/loop.js +140 -55
  131. package/dist/core/loop.js.map +1 -1
  132. package/dist/core/messages.d.ts +21 -2
  133. package/dist/core/messages.d.ts.map +1 -1
  134. package/dist/core/messages.js +61 -2
  135. package/dist/core/messages.js.map +1 -1
  136. package/dist/core/prune.d.ts +24 -0
  137. package/dist/core/prune.d.ts.map +1 -0
  138. package/dist/core/prune.js +43 -0
  139. package/dist/core/prune.js.map +1 -0
  140. package/dist/core/publish.d.ts +38 -10
  141. package/dist/core/publish.d.ts.map +1 -1
  142. package/dist/core/publish.js +126 -12
  143. package/dist/core/publish.js.map +1 -1
  144. package/dist/core/reclaim.d.ts +8 -1
  145. package/dist/core/reclaim.d.ts.map +1 -1
  146. package/dist/core/reclaim.js +149 -18
  147. package/dist/core/reclaim.js.map +1 -1
  148. package/dist/core/run.d.ts +7 -3
  149. package/dist/core/run.d.ts.map +1 -1
  150. package/dist/core/run.js +95 -35
  151. package/dist/core/run.js.map +1 -1
  152. package/dist/core/segment.d.ts +62 -0
  153. package/dist/core/segment.d.ts.map +1 -0
  154. package/dist/core/segment.js +318 -0
  155. package/dist/core/segment.js.map +1 -0
  156. package/dist/core/settle.d.ts +57 -0
  157. package/dist/core/settle.d.ts.map +1 -0
  158. package/dist/core/settle.js +181 -0
  159. package/dist/core/settle.js.map +1 -0
  160. package/dist/core/snapshot.d.ts +36 -0
  161. package/dist/core/snapshot.d.ts.map +1 -0
  162. package/dist/core/snapshot.js +87 -0
  163. package/dist/core/snapshot.js.map +1 -0
  164. package/dist/core/stop.d.ts +16 -1
  165. package/dist/core/stop.d.ts.map +1 -1
  166. package/dist/core/stop.js +69 -15
  167. package/dist/core/stop.js.map +1 -1
  168. package/dist/core/stream-events.d.ts +184 -0
  169. package/dist/core/stream-events.d.ts.map +1 -0
  170. package/dist/core/stream-events.js +26 -0
  171. package/dist/core/stream-events.js.map +1 -0
  172. package/dist/core/stream.d.ts +29 -0
  173. package/dist/core/stream.d.ts.map +1 -1
  174. package/dist/core/stream.js +79 -0
  175. package/dist/core/stream.js.map +1 -1
  176. package/dist/core/subagent.d.ts +36 -5
  177. package/dist/core/subagent.d.ts.map +1 -1
  178. package/dist/core/subagent.js +117 -22
  179. package/dist/core/subagent.js.map +1 -1
  180. package/dist/core/types.d.ts +195 -12
  181. package/dist/core/types.d.ts.map +1 -1
  182. package/dist/core/types.js +26 -1
  183. package/dist/core/types.js.map +1 -1
  184. package/dist/core/usage.d.ts +53 -5
  185. package/dist/core/usage.d.ts.map +1 -1
  186. package/dist/core/usage.js +170 -47
  187. package/dist/core/usage.js.map +1 -1
  188. package/dist/index.d.ts +16 -11
  189. package/dist/index.d.ts.map +1 -1
  190. package/dist/index.js +12 -7
  191. package/dist/index.js.map +1 -1
  192. package/dist/ports/admin.d.ts +59 -0
  193. package/dist/ports/admin.d.ts.map +1 -1
  194. package/dist/ports/kv.d.ts +17 -0
  195. package/dist/ports/kv.d.ts.map +1 -1
  196. package/dist/ports/queue.d.ts +87 -7
  197. package/dist/ports/queue.d.ts.map +1 -1
  198. package/dist/ports/queue.js +36 -1
  199. package/dist/ports/queue.js.map +1 -1
  200. package/dist/ports/runtime.d.ts +171 -20
  201. package/dist/ports/runtime.d.ts.map +1 -1
  202. package/dist/ports/storage.d.ts +26 -5
  203. package/dist/ports/storage.d.ts.map +1 -1
  204. package/dist/ports/streams.d.ts +60 -0
  205. package/dist/ports/streams.d.ts.map +1 -0
  206. package/dist/ports/streams.js +20 -0
  207. package/dist/ports/streams.js.map +1 -0
  208. package/dist/pricing.d.ts +5 -0
  209. package/dist/pricing.d.ts.map +1 -1
  210. package/dist/pricing.js +35 -10
  211. package/dist/pricing.js.map +1 -1
  212. package/dist/runtime.d.ts +6 -0
  213. package/dist/runtime.d.ts.map +1 -1
  214. package/dist/runtime.js +144 -46
  215. package/dist/runtime.js.map +1 -1
  216. package/package.json +1 -1
@@ -29,6 +29,23 @@ export declare function promptMessage(m: {
29
29
  role: string;
30
30
  content: unknown;
31
31
  };
32
+ /** Reads a stored message as a compaction summary: whether it is one, and the
33
+ * last message it covers (null on one written before the mark). */
34
+ export declare function summaryOf(m: {
35
+ content: unknown;
36
+ }): {
37
+ coversUpTo: string | null;
38
+ } | null;
39
+ /** The part of a stored history that goes to the model (§2.6): the latest
40
+ * compaction summary, then only the messages after the last one it covers.
41
+ * Everything before is in the summary already, and sending it again would
42
+ * undo the compaction. A summary written before the cover mark existed covers
43
+ * nothing known, so every summary is left out and the whole history goes; the
44
+ * next compaction writes a proper one. */
45
+ export declare function promptHistory<T extends {
46
+ id: string;
47
+ content: unknown;
48
+ }>(history: T[]): T[];
32
49
  /** `promptMessage` over a whole history. */
33
50
  export declare const promptMessages: (messages: Array<{
34
51
  role: string;
@@ -42,7 +59,9 @@ export declare const DANGLING_CALL_RESULT: {
42
59
  reason: string;
43
60
  };
44
61
  /** Close every assistant tool call that has no tool result before the next
45
- * turn. Idempotent. */
46
- export declare function repairDanglingToolCalls<T extends MessageLike>(messages: T[]): T[];
62
+ * turn, and drop every tool result whose call is not in the history before
63
+ * it (an orphan: its call was cut away, or the result was written first).
64
+ * Strict providers reject both. Idempotent. */
65
+ export declare function repairDanglingToolCalls<T extends MessageLike>(input: T[]): T[];
47
66
  export {};
48
67
  //# sourceMappingURL=messages.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/core/messages.ts"],"names":[],"mappings":"AAAA;;;;;;;iDAOiD;AASjD,UAAU,WAAW;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAID;;;;;;;;;;iDAUiD;AACjD,wBAAgB,aAAa,CAAC,CAAC,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CASvG;AAED,4CAA4C;AAC5C,eAAO,MAAM,cAAc,GAAI,UAAU,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC;UAZJ,MAAM;aAAW,OAAO;GAazE,CAAC;AAE9B,eAAO,MAAM,oBAAoB;;;CAGhC,CAAC;AAEF;wBACwB;AACxB,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,WAAW,EAAE,QAAQ,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAgCjF"}
1
+ {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/core/messages.ts"],"names":[],"mappings":"AAAA;;;;;;;iDAOiD;AASjD,UAAU,WAAW;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAID;;;;;;;;;;iDAUiD;AACjD,wBAAgB,aAAa,CAAC,CAAC,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CASvG;AAID;oEACoE;AACpE,wBAAgB,SAAS,CAAC,CAAC,EAAE;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAAG,IAAI,CAIvF;AAED;;;;;2CAK2C;AAC3C,wBAAgB,aAAa,CAAC,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,EAAE,OAAO,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAc3F;AAED,4CAA4C;AAC5C,eAAO,MAAM,cAAc,GAAI,UAAU,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC;UA5CJ,MAAM;aAAW,OAAO;GA6CzE,CAAC;AAE9B,eAAO,MAAM,oBAAoB;;;CAGhC,CAAC;AAEF;;;gDAGgD;AAChD,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,WAAW,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAiC9E"}
@@ -28,6 +28,37 @@ export function promptMessage(m) {
28
28
  }
29
29
  return { role: m.role, content: c };
30
30
  }
31
+ const CONTEXT_SUMMARY = 'CONTEXT_SUMMARY';
32
+ /** Reads a stored message as a compaction summary: whether it is one, and the
33
+ * last message it covers (null on one written before the mark). */
34
+ export function summaryOf(m) {
35
+ const c = m.content;
36
+ if (!c || typeof c !== 'object' || Array.isArray(c) || c.type !== CONTEXT_SUMMARY)
37
+ return null;
38
+ return { coversUpTo: typeof c.coversUpTo === 'string' ? c.coversUpTo : null };
39
+ }
40
+ /** The part of a stored history that goes to the model (§2.6): the latest
41
+ * compaction summary, then only the messages after the last one it covers.
42
+ * Everything before is in the summary already, and sending it again would
43
+ * undo the compaction. A summary written before the cover mark existed covers
44
+ * nothing known, so every summary is left out and the whole history goes; the
45
+ * next compaction writes a proper one. */
46
+ export function promptHistory(history) {
47
+ let latest = -1;
48
+ let covers = null;
49
+ history.forEach((m, i) => {
50
+ const s = summaryOf(m);
51
+ if (s) {
52
+ latest = i;
53
+ covers = s.coversUpTo;
54
+ }
55
+ });
56
+ if (latest < 0)
57
+ return history;
58
+ const coveredAt = covers === null ? -1 : history.findIndex((m) => m.id === covers);
59
+ const rest = history.slice(coveredAt + 1).filter((m) => !summaryOf(m));
60
+ return coveredAt >= 0 ? [history[latest], ...rest] : rest;
61
+ }
31
62
  /** `promptMessage` over a whole history. */
32
63
  export const promptMessages = (messages) => messages.map(promptMessage);
33
64
  export const DANGLING_CALL_RESULT = {
@@ -35,8 +66,11 @@ export const DANGLING_CALL_RESULT = {
35
66
  reason: 'no result was recorded for this call',
36
67
  };
37
68
  /** Close every assistant tool call that has no tool result before the next
38
- * turn. Idempotent. */
39
- export function repairDanglingToolCalls(messages) {
69
+ * turn, and drop every tool result whose call is not in the history before
70
+ * it (an orphan: its call was cut away, or the result was written first).
71
+ * Strict providers reject both. Idempotent. */
72
+ export function repairDanglingToolCalls(input) {
73
+ const messages = dropOrphanResults(input);
40
74
  const out = [];
41
75
  for (let i = 0; i < messages.length; i += 1) {
42
76
  const m = messages[i];
@@ -71,4 +105,29 @@ export function repairDanglingToolCalls(messages) {
71
105
  }
72
106
  return out;
73
107
  }
108
+ /** Tool results whose call has not appeared yet are dropped; a tool message
109
+ * left with no parts goes with them. */
110
+ function dropOrphanResults(messages) {
111
+ const called = new Set();
112
+ const out = [];
113
+ for (const m of messages) {
114
+ if (m.role === 'assistant') {
115
+ for (const p of parts(m.content)) {
116
+ if (p.type === 'tool-call' && p.toolCallId)
117
+ called.add(p.toolCallId);
118
+ }
119
+ }
120
+ if (m.role !== 'tool' || !Array.isArray(m.content)) {
121
+ out.push(m);
122
+ continue;
123
+ }
124
+ const all = parts(m.content);
125
+ const kept = all.filter((p) => p.type !== 'tool-result' || !p.toolCallId || called.has(p.toolCallId));
126
+ if (kept.length === all.length)
127
+ out.push(m);
128
+ else if (kept.length > 0)
129
+ out.push({ ...m, content: kept });
130
+ }
131
+ return out;
132
+ }
74
133
  //# sourceMappingURL=messages.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/core/messages.ts"],"names":[],"mappings":"AAAA;;;;;;;iDAOiD;AAejD,MAAM,KAAK,GAAG,CAAC,OAAgB,EAAc,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAE,OAAsB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAExG;;;;;;;;;;iDAUiD;AACjD,MAAM,UAAU,aAAa,CAAC,CAAqC;IACjE,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC;IACpB,IAAI,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;QACpD,MAAM,QAAQ,GAAG,CAAuC,CAAC;QACzD,IAAI,OAAO,QAAQ,CAAC,IAAI,KAAK,QAAQ,IAAI,OAAO,QAAQ,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC3E,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;QAClD,CAAC;IACH,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;AACtC,CAAC;AAED,4CAA4C;AAC5C,MAAM,CAAC,MAAM,cA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I,EAAO,CAAC,CAAC;IACnE,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,24 @@
1
+ import type { RuntimePorts } from '../ports/runtime.js';
2
+ /** The types older releases kept in the event log that now live only on a
3
+ * run stream or the bus. Nothing reads them from the table any more, so
4
+ * they can go. An app's own types are never among them: there is no
5
+ * telling whether the app wanted one kept. */
6
+ export declare const STREAM_ONLY_TYPES: readonly string[];
7
+ export interface PruneOptions {
8
+ /** Count what would go, and delete nothing. */
9
+ dryRun?: boolean;
10
+ /** Rows per batch; each batch is its own short delete. Default 10,000. */
11
+ batchSize?: number;
12
+ }
13
+ export interface PruneReport {
14
+ /** Rows deleted (or, on a dry run, found) per type. */
15
+ byType: Record<string, number>;
16
+ total: number;
17
+ batches: number;
18
+ }
19
+ /** Delete the stream-only rows older releases left in the event log (see
20
+ * STREAM_ONLY_TYPES), a batch at a time, so a large table never holds one
21
+ * long lock. Safe to stop and run again: each batch stands on its own.
22
+ * Needs a storage whose events port can prune; one that cannot throws. */
23
+ export declare function pruneEvents(deps: RuntimePorts, opts?: PruneOptions): Promise<PruneReport>;
24
+ //# sourceMappingURL=prune.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prune.d.ts","sourceRoot":"","sources":["../../src/core/prune.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD;;;+CAG+C;AAC/C,eAAO,MAAM,iBAAiB,EAAE,SAAS,MAAM,EAY9C,CAAC;AAEF,MAAM,WAAW,YAAY;IAC3B,+CAA+C;IAC/C,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,0EAA0E;IAC1E,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,WAAW;IAC1B,uDAAuD;IACvD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;2EAG2E;AAC3E,wBAAsB,WAAW,CAAC,IAAI,EAAE,YAAY,EAAE,IAAI,GAAE,YAAiB,GAAG,OAAO,CAAC,WAAW,CAAC,CAkBnG"}
@@ -0,0 +1,43 @@
1
+ /** The types older releases kept in the event log that now live only on a
2
+ * run stream or the bus. Nothing reads them from the table any more, so
3
+ * they can go. An app's own types are never among them: there is no
4
+ * telling whether the app wanted one kept. */
5
+ export const STREAM_ONLY_TYPES = [
6
+ 'CHUNK',
7
+ 'SUBAGENT_CHUNK',
8
+ 'STEP_COMMITTED',
9
+ 'STEP_FINISHED',
10
+ 'TEXT_RESULT',
11
+ 'SUBAGENT_STARTED',
12
+ 'SUBAGENT_COMPLETED',
13
+ 'SUBAGENT_FAILED',
14
+ 'MESSAGE_APPENDED',
15
+ 'STATE_CHANGE',
16
+ 'HEARTBEAT',
17
+ ];
18
+ /** Delete the stream-only rows older releases left in the event log (see
19
+ * STREAM_ONLY_TYPES), a batch at a time, so a large table never holds one
20
+ * long lock. Safe to stop and run again: each batch stands on its own.
21
+ * Needs a storage whose events port can prune; one that cannot throws. */
22
+ export async function pruneEvents(deps, opts = {}) {
23
+ const prune = deps.storage.events.prune;
24
+ if (!prune)
25
+ throw new Error('pruneEvents: this storage cannot prune its events');
26
+ const limit = opts.batchSize ?? 10_000;
27
+ const report = { byType: {}, total: 0, batches: 0 };
28
+ for (;;) {
29
+ const counts = await prune([...STREAM_ONLY_TYPES], { limit, dryRun: opts.dryRun });
30
+ report.batches++;
31
+ let n = 0;
32
+ for (const [type, count] of Object.entries(counts)) {
33
+ report.byType[type] = (report.byType[type] ?? 0) + count;
34
+ n += count;
35
+ }
36
+ report.total += n;
37
+ // A dry run counts everything in one pass; a batch smaller than the
38
+ // limit was the last one.
39
+ if (opts.dryRun || n < limit)
40
+ return report;
41
+ }
42
+ }
43
+ //# sourceMappingURL=prune.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prune.js","sourceRoot":"","s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AAI,CAAC,MAAM,IAAI,CAAC,GAAG,KAAK;YAAE,OAAO,MAAM,CAAC;IAC9C,CAAC;AACH,CAAC"}
@@ -1,23 +1,34 @@
1
1
  import type { RuntimePorts } from '../ports/runtime.js';
2
- import type { ExecutionState } from './types.js';
2
+ import type { ExecutionState, ThreadTransition } from './types.js';
3
3
  import type { AgentEvent } from './types.js';
4
- /** Persist to the replayable event log, then fan out live to all subscribers
5
- * (§2.2). Seq comes from Kv.incr — monotonic per thread (§3.4). */
6
- export declare function publish(deps: RuntimePorts, threadId: string, type: string, payload: unknown): Promise<AgentEvent>;
7
- /** Publish a bus-only notice (never persisted) — e.g. HITL death notices (§2.5). */
4
+ /** The platform's types that go in the thread record: what must outlive a
5
+ * run (see Storage.events). Every other platform type is live only: a
6
+ * notice on the bus, and an event on the run stream when one is open. */
7
+ export declare const RECORD_EVENT_TYPES: ReadonlySet<string>;
8
+ /** Publish a platform event (§2.2). A record type is stored first (the
9
+ * store mints its seq) and then sent; any other type is sent as a notice.
10
+ * Either way it reaches the run stream this process has open on the
11
+ * thread. */
12
+ export declare function publish(deps: RuntimePorts, threadId: string, type: string, payload: unknown, runId?: string): Promise<AgentEvent>;
13
+ /** Publish a live-only event (never stored). While this process has a
14
+ * segment open on the thread, stream content and an app's own events go to
15
+ * the run stream alone; everything else goes on the bus, and to the stream
16
+ * when the stream has a shape for it (a step's end). */
8
17
  export declare function publishNotice(deps: RuntimePorts, threadId: string, type: string, payload: unknown): Promise<AgentEvent>;
9
18
  /** Event types the platform itself emits. An app cannot publish these: a
10
19
  * client's reducer trusts them to mean what the engine meant. */
11
20
  export declare const RESERVED_EVENT_TYPES: ReadonlySet<string>;
12
21
  export interface PublishEventOptions {
13
- /** `true` (the default) writes the event to the thread's log, so it is
14
- * replayed to a client that reconnects. `false` sends it over the bus only:
15
- * a progress tick, a typing indicator — anything nobody needs to see twice. */
22
+ /** `true` also keeps the event in the thread record, so a tab that opens
23
+ * the thread next week still sees it. Otherwise (the default) it is live
24
+ * only: it goes out on the bus and, during a run, on the run's stream,
25
+ * which a tab that reconnects within the grace window replays. */
16
26
  durable?: boolean;
17
27
  }
18
28
  /** Publish an event of your own on a thread, through the same pipeline the
19
- * platform's events take: the durable log and the live bus (§2.2). A client
20
- * sees it in `onEvent`, exactly like a built-in one. */
29
+ * platform's events take (§2.2): the live bus, the run stream during a run
30
+ * (as CUSTOM), and the thread record when it is durable. A client sees it
31
+ * in `onEvent`, exactly like a built-in one. */
21
32
  export declare function publishEvent(deps: RuntimePorts, threadId: string, type: string, payload: unknown, options?: PublishEventOptions): Promise<AgentEvent>;
22
33
  /** What a tool calls to publish: `publishEvent(type, payload, options?)`,
23
34
  * already bound to the thread the tool is acting on. */
@@ -26,6 +37,23 @@ export type ToolPublishEvent = (type: string, payload: unknown, options?: Publis
26
37
  * the thread it runs on — main agent, nested run, or a segment resumed after
27
38
  * an approval alike. */
28
39
  export declare function withPublishEvent(deps: RuntimePorts, threadId: string, tools: Record<string, any>): Record<string, any>;
40
+ /** A non-terminal STATE_CHANGE: the state, the run it belongs to, and when
41
+ * that run started, read off its record. Every STATE_CHANGE names its run,
42
+ * so a client keeps one timer per run and never refetches history to find
43
+ * its start. */
44
+ export declare function runStatePayload(deps: RuntimePorts, state: ExecutionState, runId?: string): Promise<Record<string, unknown>>;
45
+ /** The states a run is still going in: the ones a stop or a failure can end. */
46
+ export declare const ACTIVE_STATES: ExecutionState[];
47
+ /** The one way a run moves its thread's state (§3.4). A compare-and-set on
48
+ * the durable row, on the state AND the run that owns the thread, and only
49
+ * the caller that wins it writes the hot cache and the admin view. So a stop
50
+ * is never overwritten by a finish, and a stopped or replaced run can never
51
+ * move the thread again: its change simply loses. Returns whether this
52
+ * caller made the change. Publishing the STATE_CHANGE is left to the caller,
53
+ * whose payload differs per change. */
54
+ export declare function transition(deps: RuntimePorts, threadId: string, change: ThreadTransition & {
55
+ model?: string;
56
+ }): Promise<boolean>;
29
57
  /** Move a thread to a new state on BOTH the caller's storage and the
30
58
  * platform's own operational view (§2.9).
31
59
  *
@@ -1 +1 @@
1
- {"version":3,"file":"publish.d.ts","sourceRoot":"","sources":["../../src/core/publish.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C;oEACoE;AACpE,wBAAsB,OAAO,CAC3B,IAAI,EAAE,YAAY,EAClB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,UAAU,CAAC,CAMrB;AAED,oFAAoF;AACpF,wBAAsB,aAAa,CACjC,IAAI,EAAE,YAAY,EAClB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,UAAU,CAAC,CAIrB;AAED;kEACkE;AAClE,eAAO,MAAM,oBAAoB,EAAE,WAAW,CAAC,MAAM,CAoBnD,CAAC;AAEH,MAAM,WAAW,mBAAmB;IAClC;;oFAEgF;IAChF,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;yDAEyD;AACzD,wBAAsB,YAAY,CAChC,IAAI,EAAE,YAAY,EAClB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,UAAU,CAAC,CAUrB;AAED;yDACyD;AACzD,MAAM,MAAM,gBAAgB,GAAG,CAC7B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,mBAAmB,KAC1B,OAAO,CAAC,UAAU,CAAC,CAAC;AAEzB;;yBAEyB;AACzB,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,YAAY,EAClB,QAAQ,EAAE,MAAM,EAChB,K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B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,UAAU,CAAC,CAUrB;AAED;yDACyD;AACzD,MAAM,MAAM,gBAAgB,GAAG,CAC7B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,mBAAmB,KAC1B,OAAO,CAAC,UAAU,CAAC,CAAC;AAEzB;;yBAEyB;AACzB,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,YAAY,EAClB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACzB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAerB;AAED;;;iBAGiB;AACjB,wBAAsB,eAAe,CACnC,IAAI,EAAE,YAAY,EAClB,KAAK,EAAE,cAAc,EACrB,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAWlC;AAED,gFAAgF;AAChF,eAAO,MAAM,aAAa,EAAE,cAAc,EAA+C,CAAC;AAE1F;;;;;;wCAMwC;AACxC,wBAAsB,UAAU,CAC9B,IAAI,EAAE,YAAY,EAClB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,gBAAgB,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GAC5C,OAAO,CAAC,OAAO,CAAC,CAMlB;AAED;;;;;;;mBAOmB;AACnB,wBAAsB,cAAc,CAClC,IAAI,EAAE,YAAY,EAClB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,cAAc,EACrB,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAGf"}
@@ -1,16 +1,85 @@
1
- /** Persist to the replayable event log, then fan out live to all subscribers
2
- * (§2.2). Seq comes from Kv.incr — monotonic per thread (§3.4). */
3
- export async function publish(deps, threadId, type, payload) {
4
- const seq = await deps.kv.incr(`agent:seq:${threadId}`);
5
- const event = { threadId, seq, type, payload, createdAt: new Date() };
6
- await deps.storage.events.append(threadId, event);
1
+ import { THREAD_KEY_TTL_SECONDS } from './keys.js';
2
+ import { activeSegment } from './segment.js';
3
+ /** The platform's types that go in the thread record: what must outlive a
4
+ * run (see Storage.events). Every other platform type is live only: a
5
+ * notice on the bus, and an event on the run stream when one is open. */
6
+ export const RECORD_EVENT_TYPES = new Set([
7
+ 'INPUT_REQUIRED',
8
+ 'INPUT_EXPIRED',
9
+ 'HITL_RESPONSE',
10
+ 'RUN_REFUSED',
11
+ 'TOKEN_BUDGET_EXHAUSTED',
12
+ 'COST_BUDGET_EXHAUSTED',
13
+ 'CONTEXT_COMPACTED',
14
+ 'MESSAGES_DROPPED',
15
+ 'RUN_STARTED',
16
+ 'RUN_ENDED',
17
+ ]);
18
+ /** The run an entry belongs to: the one given, else the one its payload
19
+ * names. */
20
+ function runOf(payload, runId) {
21
+ if (runId)
22
+ return runId;
23
+ const p = payload;
24
+ if (typeof p?.runId === 'string')
25
+ return p.runId;
26
+ if (typeof p?.resume?.runId === 'string')
27
+ return p.resume.runId;
28
+ return null;
29
+ }
30
+ /** Publish a platform event (§2.2). A record type is stored first (the
31
+ * store mints its seq) and then sent; any other type is sent as a notice.
32
+ * Either way it reaches the run stream this process has open on the
33
+ * thread. */
34
+ export async function publish(deps, threadId, type, payload, runId) {
35
+ if (!RECORD_EVENT_TYPES.has(type))
36
+ return publishNotice(deps, threadId, type, payload);
37
+ return record(deps, threadId, type, payload, runOf(payload, runId));
38
+ }
39
+ /** Store an entry in the thread record, then send it. */
40
+ async function record(deps, threadId, type, payload, runId) {
41
+ const event = await deps.storage.events.append(threadId, { type, payload, runId });
7
42
  await deps.bus.publish(threadId, event);
43
+ // A platform entry the stream shows too (a park). An app's durable event
44
+ // is delivered as this entry alone, so a tab never sees it twice.
45
+ if (RESERVED_EVENT_TYPES.has(type))
46
+ await toSegment(deps, threadId, type, payload);
8
47
  return event;
9
48
  }
10
- /** Publish a bus-only notice (never persisted) — e.g. HITL death notices (§2.5). */
49
+ /** What a run stream carries in place of the bus while a segment is open:
50
+ * a tab reads these from the stream, so the bus sending them too would
51
+ * show them twice. */
52
+ const STREAM_CONTENT = new Set([
53
+ 'CHUNK',
54
+ 'SUBAGENT_CHUNK',
55
+ 'TEXT_RESULT',
56
+ 'STEP_COMMITTED',
57
+ 'SUBAGENT_STARTED',
58
+ 'SUBAGENT_COMPLETED',
59
+ 'SUBAGENT_FAILED',
60
+ ]);
61
+ /** Hands an event to the run stream this process has open on the thread,
62
+ * if any; the segment keeps what belongs in a stream (see SegmentStream). */
63
+ async function toSegment(deps, threadId, type, payload) {
64
+ const seg = activeSegment(deps, threadId);
65
+ if (seg)
66
+ await seg.forward(type, payload, RESERVED_EVENT_TYPES.has(type));
67
+ }
68
+ /** Publish a live-only event (never stored). While this process has a
69
+ * segment open on the thread, stream content and an app's own events go to
70
+ * the run stream alone; everything else goes on the bus, and to the stream
71
+ * when the stream has a shape for it (a step's end). */
11
72
  export async function publishNotice(deps, threadId, type, payload) {
12
73
  const event = { threadId, seq: 0, type, payload, createdAt: new Date() };
74
+ const seg = activeSegment(deps, threadId);
75
+ const custom = !RESERVED_EVENT_TYPES.has(type);
76
+ if (seg && (custom || STREAM_CONTENT.has(type))) {
77
+ await seg.forward(type, payload, !custom);
78
+ return event;
79
+ }
13
80
  await deps.bus.publish(threadId, event);
81
+ if (seg)
82
+ await seg.forward(type, payload, true);
14
83
  return event;
15
84
  }
16
85
  /** Event types the platform itself emits. An app cannot publish these: a
@@ -35,10 +104,16 @@ export const RESERVED_EVENT_TYPES = new Set([
35
104
  'HEARTBEAT',
36
105
  'RUN_REFUSED',
37
106
  'TOKEN_BUDGET_EXHAUSTED',
107
+ 'COST_BUDGET_EXHAUSTED',
108
+ 'RUN_STARTED',
109
+ 'RUN_ENDED',
110
+ 'RECORD_CHANGED',
111
+ 'SNAPSHOT',
38
112
  ]);
39
113
  /** Publish an event of your own on a thread, through the same pipeline the
40
- * platform's events take: the durable log and the live bus (§2.2). A client
41
- * sees it in `onEvent`, exactly like a built-in one. */
114
+ * platform's events take (§2.2): the live bus, the run stream during a run
115
+ * (as CUSTOM), and the thread record when it is durable. A client sees it
116
+ * in `onEvent`, exactly like a built-in one. */
42
117
  export async function publishEvent(deps, threadId, type, payload, options = {}) {
43
118
  if (!type || typeof type !== 'string') {
44
119
  throw new Error('publishEvent: an event type is required');
@@ -46,9 +121,9 @@ export async function publishEvent(deps, threadId, type, payload, options = {})
46
121
  if (RESERVED_EVENT_TYPES.has(type)) {
47
122
  throw new Error(`publishEvent: ${type} is a platform event type — pick your own`);
48
123
  }
49
- return options.durable === false
50
- ? publishNotice(deps, threadId, type, payload)
51
- : publish(deps, threadId, type, payload);
124
+ return options.durable
125
+ ? record(deps, threadId, type, payload, runOf(payload))
126
+ : publishNotice(deps, threadId, type, payload);
52
127
  }
53
128
  /** Give every tool `publishEvent` alongside the SDK's own options, bound to
54
129
  * the thread it runs on — main agent, nested run, or a segment resumed after
@@ -67,6 +142,42 @@ export function withPublishEvent(deps, threadId, tools) {
67
142
  }
68
143
  return out;
69
144
  }
145
+ /** A non-terminal STATE_CHANGE: the state, the run it belongs to, and when
146
+ * that run started, read off its record. Every STATE_CHANGE names its run,
147
+ * so a client keeps one timer per run and never refetches history to find
148
+ * its start. */
149
+ export async function runStatePayload(deps, state, runId) {
150
+ const p = { state };
151
+ if (!runId)
152
+ return p;
153
+ p.runId = runId;
154
+ try {
155
+ const rec = await deps.admin.runs.get(runId);
156
+ if (rec)
157
+ p.startedAt = rec.startedAt;
158
+ }
159
+ catch {
160
+ // The timer is a nicety; a missing record never fails a transition.
161
+ }
162
+ return p;
163
+ }
164
+ /** The states a run is still going in: the ones a stop or a failure can end. */
165
+ export const ACTIVE_STATES = ['QUEUED', 'RUNNING', 'WAITING_FOR_INPUT'];
166
+ /** The one way a run moves its thread's state (§3.4). A compare-and-set on
167
+ * the durable row, on the state AND the run that owns the thread, and only
168
+ * the caller that wins it writes the hot cache and the admin view. So a stop
169
+ * is never overwritten by a finish, and a stopped or replaced run can never
170
+ * move the thread again: its change simply loses. Returns whether this
171
+ * caller made the change. Publishing the STATE_CHANGE is left to the caller,
172
+ * whose payload differs per change. */
173
+ export async function transition(deps, threadId, change) {
174
+ const { model, ...t } = change;
175
+ if (!(await deps.storage.threads.transition(threadId, t)))
176
+ return false;
177
+ await deps.kv.set(`agent:state:${threadId}`, t.to, { exSeconds: THREAD_KEY_TTL_SECONDS });
178
+ await upsertAdminThread(deps, threadId, t.to, model);
179
+ return true;
180
+ }
70
181
  /** Move a thread to a new state on BOTH the caller's storage and the
71
182
  * platform's own operational view (§2.9).
72
183
  *
@@ -77,6 +188,9 @@ export function withPublishEvent(deps, threadId, tools) {
77
188
  * skip a read. */
78
189
  export async function setThreadState(deps, threadId, state, model) {
79
190
  await deps.storage.threads.setState(threadId, state);
191
+ await upsertAdminThread(deps, threadId, state, model);
192
+ }
193
+ async function upsertAdminThread(deps, threadId, state, model) {
80
194
  try {
81
195
  const resolved = model ?? (await deps.storage.threads.get(threadId))?.model ?? 'unknown';
82
196
  await deps.admin.threads.upsert({ id: threadId, state, model: resolved });
@@ -1 +1 @@
1
- {"version":3,"file":"publish.js","sourceRoot":"","sources":["../../src/core/publish.ts"],"names":[],"mappings":"AAIA;oEACoE;AACpE,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,IAAkB,EAClB,QAAgB,EAChB,IAAY,EACZ,OAAgB;IAEhB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,aAAa,QAAQ,EAAE,CAAC,CAAC;IACxD,MAAM,KAAK,GAAe,EAAE,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,EAAE,CAAC;IAClF,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC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B,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,IAAkB,EAClB,QAAgB,EAChB,KAAqB,EACrB,KAAc;IAEd,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IACrD,MAAM,iBAAiB,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;AACxD,CAAC;AAED,KAAK,UAAU,iBAAiB,CAC9B,IAAkB,EAClB,QAAgB,EAChB,KAAqB,EACrB,KAAc;IAEd,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,KAAK,IAAI,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,KAAK,IAAI,SAAS,CAAC;QACzF,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC5E,CAAC;IAAC,MAAM,CAAC;QACP,wEAAwE;IAC1E,CAAC;AACH,CAAC"}
@@ -8,6 +8,13 @@ export declare function reclaimGraceAfterMs(deps: RuntimePorts): number;
8
8
  * delay. Callers are first-touch checks in run() and respond(), plus any
9
9
  * listener that wants the denial to land live in front of a user.
10
10
  *
11
+ * It also covers a run the queue lost: a thread QUEUED or RUNNING whose run
12
+ * lock nobody holds and whose job the queue no longer has. A worker that died
13
+ * leaves exactly that behind once its lock lapses, and so does a job dropped
14
+ * as dead. The run is re-dispatched and resumes from its last persisted
15
+ * step, unless its record already ended, in which case the thread is moved
16
+ * to match the record.
17
+ *
11
18
  * It no longer heals inline. It re-dispatches the run and lets the engine
12
19
  * resolve the park, so there is exactly ONE definition of what an expired
13
20
  * approval becomes — and so a thread holding several open approvals (§2.7)
@@ -15,6 +22,6 @@ export declare function reclaimGraceAfterMs(deps: RuntimePorts): number;
15
22
  * same run twice is safe: the run lock and the engine's readiness check make
16
23
  * the duplicate a no-op (§2.8).
17
24
  *
18
- * Returns true iff a re-dispatch was enqueued. */
25
+ * Returns true iff a re-dispatch was enqueued or the thread was healed. */
19
26
  export declare function reclaimIfOrphaned(deps: RuntimePorts, threadId: string): Promise<boolean>;
20
27
  //# sourceMappingURL=reclaim.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"reclaim.d.ts","sourceRoot":"","sources":["../../src/core/reclaim.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAOxD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,CAE9D;AAED;;;;;;;;;;;;;;;mDAemD;AACnD,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAoC9F"}
1
+ {"version":3,"file":"reclaim.d.ts","sourceRoot":"","sources":["../../src/core/reclaim.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAaxD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,CAE9D;AAED;;;;;;;;;;;;;;;;;;;;;;4EAsB4E;AAC5E,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAoD9F"}