@yielded/agent 0.1.0-beta.173 → 0.1.0-beta.175

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 (266) hide show
  1. package/dist/{Admin-BX9ns28E.d.mts → Admin-Qa3I1oA5.d.mts} +61 -21
  2. package/dist/{Agent-9aBoIi74.d.mts → Agent-B39jRnFv.d.mts} +2 -2
  3. package/dist/{Agent-0WvBWWbM.mjs → Agent-BiRbr73L.mjs} +7 -6
  4. package/dist/Agent-BiRbr73L.mjs.map +1 -0
  5. package/dist/{AgentRuntime-BfP14534.d.mts → AgentRuntime-CHDyRbSf.d.mts} +12 -12
  6. package/dist/{AgentRuntime-CQ-qcETl.mjs → AgentRuntime-DaDKMasp.mjs} +290 -273
  7. package/dist/AgentRuntime-DaDKMasp.mjs.map +1 -0
  8. package/dist/{Digest-DCuPlhNk.mjs → Digest-C3EODOee.mjs} +42 -15
  9. package/dist/Digest-C3EODOee.mjs.map +1 -0
  10. package/dist/{DurableAgentRuntime-BAmSkWYr.mjs → DurableAgentRuntime-CPlw5_7e.mjs} +1557 -1458
  11. package/dist/DurableAgentRuntime-CPlw5_7e.mjs.map +1 -0
  12. package/dist/{EventSource-BwliwQz9.d.mts → EventSource-BTu68yDW.d.mts} +2 -2
  13. package/dist/InMemory.d.mts +2 -2
  14. package/dist/{MessageDelivery-B943ebI_.d.mts → MessageDelivery-DjAZJ4Fd.d.mts} +42 -42
  15. package/dist/{Messaging-C_6OOg_s.d.mts → Messaging-SVu6rWV8.d.mts} +12 -6
  16. package/dist/{MessagingHost-B8oKM7AC.d.mts → MessagingHost-C6SOAcoG.d.mts} +2 -2
  17. package/dist/{MessagingHost-CRUK4JBi.mjs → MessagingHost-CZCyrnvJ.mjs} +27 -26
  18. package/dist/MessagingHost-CZCyrnvJ.mjs.map +1 -0
  19. package/dist/{Output-Dsx6k52t.d.mts → Output-CRamN1Fy.d.mts} +2 -2
  20. package/dist/{PreparedInputAdmission-CxSJSiTl.d.mts → PreparedInputAdmission-wgY4JMZY.d.mts} +3 -3
  21. package/dist/{Records-BiuJDWNe.mjs → Records-DzL4Kbtw.mjs} +2 -2
  22. package/dist/{Records-BiuJDWNe.mjs.map → Records-DzL4Kbtw.mjs.map} +1 -1
  23. package/dist/{RunContinuation-FHM7XPjq.d.mts → RunContinuation-3jB5pULC.d.mts} +13 -7
  24. package/dist/{RunContinuation-DHYNAQFi.mjs → RunContinuation-BiyKJK32.mjs} +173 -82
  25. package/dist/RunContinuation-BiyKJK32.mjs.map +1 -0
  26. package/dist/{RunJournal-kfKVxJj7.mjs → RunJournal-CPMKcfd0.mjs} +106 -73
  27. package/dist/RunJournal-CPMKcfd0.mjs.map +1 -0
  28. package/dist/{RunOptions-D8zxFIrZ.d.mts → RunOptions-Be77lKVZ.d.mts} +2 -2
  29. package/dist/{RunStorage-uqPxps09.mjs → RunStorage-CzutHJBE.mjs} +10 -6
  30. package/dist/RunStorage-CzutHJBE.mjs.map +1 -0
  31. package/dist/{Scheduling-CVyfXlBR.mjs → Scheduling-07_dsGED.mjs} +12 -12
  32. package/dist/Scheduling-07_dsGED.mjs.map +1 -0
  33. package/dist/{Subagent-vpffemql.mjs → Subagent-CexndZSp.mjs} +53 -40
  34. package/dist/Subagent-CexndZSp.mjs.map +1 -0
  35. package/dist/{Subagent-E6tvd7-k.d.mts → Subagent-xhN_aD1r.d.mts} +20 -9
  36. package/dist/{SubagentHost-B6w2m-SI.d.mts → SubagentHost-D1xBgn9g.d.mts} +2 -2
  37. package/dist/{Subscription-DONig54Q.d.mts → Subscription-DmIHlOJK.d.mts} +2 -2
  38. package/dist/{SubscriptionInput-mJIRxWJM.d.mts → SubscriptionInput-DgcQhvbe.d.mts} +2 -2
  39. package/dist/{Thread-dk-QiNml.d.mts → Thread-DzdJAY4J.d.mts} +4 -3
  40. package/dist/{ThreadHistory-ByxS8HU1.d.mts → ThreadHistory-KPPBJLJb.d.mts} +12 -2
  41. package/dist/{ThreadImport-DckUMEqJ.mjs → ThreadImport-CjlG57vH.mjs} +9 -9
  42. package/dist/ThreadImport-CjlG57vH.mjs.map +1 -0
  43. package/dist/{ThreadImport-DpHxjBrA.d.mts → ThreadImport-DP-vOk2F.d.mts} +5 -5
  44. package/dist/{ThreadStore-CEekRa80.mjs → ThreadStore-EuUilthA.mjs} +162 -85
  45. package/dist/ThreadStore-EuUilthA.mjs.map +1 -0
  46. package/dist/{ThreadTransfer-B4gTQLIl.mjs → ThreadTransfer-DB_zsrtJ.mjs} +4 -4
  47. package/dist/{ThreadTransfer-B4gTQLIl.mjs.map → ThreadTransfer-DB_zsrtJ.mjs.map} +1 -1
  48. package/dist/{WorkerAdmission-DFVbbVh2.mjs → WorkerAdmission-eBeXt_mu.mjs} +5 -5
  49. package/dist/{WorkerAdmission-DFVbbVh2.mjs.map → WorkerAdmission-eBeXt_mu.mjs.map} +1 -1
  50. package/dist/{agent-registration-ByMZ_cK5.mjs → agent-registration-a6QYaG3h.mjs} +70 -57
  51. package/dist/agent-registration-a6QYaG3h.mjs.map +1 -0
  52. package/dist/capabilities/Approval.mjs +2 -2
  53. package/dist/capabilities/Approval.mjs.map +1 -1
  54. package/dist/capabilities/BrowserUse.d.mts +102 -1867
  55. package/dist/capabilities/BrowserUse.mjs +74 -798
  56. package/dist/capabilities/BrowserUse.mjs.map +1 -1
  57. package/dist/capabilities/Budget.mjs +3 -1
  58. package/dist/capabilities/Budget.mjs.map +1 -1
  59. package/dist/capabilities/CodeMode.d.mts +1 -1
  60. package/dist/capabilities/CodeMode.mjs +16 -9
  61. package/dist/capabilities/CodeMode.mjs.map +1 -1
  62. package/dist/capabilities/Commands.d.mts +1 -1
  63. package/dist/capabilities/McpClient.mjs +1 -1
  64. package/dist/capabilities/McpClient.mjs.map +1 -1
  65. package/dist/capabilities/Messaging.d.mts +1 -1
  66. package/dist/capabilities/Messaging.mjs +5 -5
  67. package/dist/capabilities/Messaging.mjs.map +1 -1
  68. package/dist/capabilities/ModelContext.d.mts +1 -1
  69. package/dist/capabilities/ModelContext.mjs +7 -5
  70. package/dist/capabilities/ModelContext.mjs.map +1 -1
  71. package/dist/capabilities/Redaction.mjs +49 -19
  72. package/dist/capabilities/Redaction.mjs.map +1 -1
  73. package/dist/capabilities/RunHooks.d.mts +2 -2
  74. package/dist/capabilities/RunHooks.mjs +1 -1
  75. package/dist/capabilities/RunHooks.mjs.map +1 -1
  76. package/dist/capabilities/Subagent.d.mts +1 -1
  77. package/dist/capabilities/Subagent.mjs +1 -1
  78. package/dist/capabilities/SubagentReservations.mjs +3 -1
  79. package/dist/capabilities/SubagentReservations.mjs.map +1 -1
  80. package/dist/capabilities/WebCapture.mjs.map +1 -1
  81. package/dist/capabilities/WebSearch.mjs +7 -7
  82. package/dist/capabilities/WebSearch.mjs.map +1 -1
  83. package/dist/core/Agent.d.mts +1 -1
  84. package/dist/core/Agent.mjs +1 -1
  85. package/dist/core/AgentUpdates.mjs +8 -8
  86. package/dist/core/AgentUpdates.mjs.map +1 -1
  87. package/dist/core/Thread.d.mts +2 -2
  88. package/dist/core/Thread.mjs +6 -4
  89. package/dist/core/Thread.mjs.map +1 -1
  90. package/dist/core/Usage.mjs +2 -2
  91. package/dist/core/Usage.mjs.map +1 -1
  92. package/dist/durable/ActivityStore.mjs +1 -1
  93. package/dist/durable/Admin.d.mts +1 -1
  94. package/dist/durable/Admin.mjs +1 -1
  95. package/dist/durable/AgentRegistration.d.mts +1 -1
  96. package/dist/durable/AgentRegistration.mjs +1 -1
  97. package/dist/durable/Certification.d.mts +1 -1
  98. package/dist/durable/CommittedActivity.d.mts +1 -1
  99. package/dist/durable/CommittedActivity.mjs +3 -3
  100. package/dist/durable/Digest.mjs +1 -1
  101. package/dist/durable/DurableAgentRuntime.d.mts +1 -1
  102. package/dist/durable/DurableAgentRuntime.mjs +2 -2
  103. package/dist/durable/EventSource.d.mts +1 -1
  104. package/dist/durable/EventSource.mjs +7 -7
  105. package/dist/durable/EventSource.mjs.map +1 -1
  106. package/dist/durable/GitHubWorkflowSource.d.mts +3 -3
  107. package/dist/durable/LifecyclePublication.d.mts +1 -1
  108. package/dist/durable/LifecyclePublication.mjs +2 -2
  109. package/dist/durable/MessageDelivery.d.mts +1 -1
  110. package/dist/durable/MessageDelivery.mjs +2 -2
  111. package/dist/durable/MessageDeliveryStoreConformance.d.mts +40 -40
  112. package/dist/durable/MessageDeliveryStoreConformance.mjs +2 -2
  113. package/dist/durable/PersistentHistory.d.mts +2 -2
  114. package/dist/durable/PersistentHistory.mjs +4 -4
  115. package/dist/durable/PreparedInputAdmission.d.mts +1 -1
  116. package/dist/durable/RecordFormat.mjs +3 -3
  117. package/dist/durable/RecordFormat.mjs.map +1 -1
  118. package/dist/durable/Records.mjs +1 -1
  119. package/dist/durable/Recovery.d.mts +1 -1
  120. package/dist/durable/Recovery.mjs +1 -1
  121. package/dist/durable/RunContinuation.d.mts +2 -2
  122. package/dist/durable/RunContinuation.mjs +3 -3
  123. package/dist/durable/RunJournal.d.mts +2 -2
  124. package/dist/durable/RunJournal.mjs +2 -2
  125. package/dist/durable/RunStorage.d.mts +1 -1
  126. package/dist/durable/RunStorage.mjs +1 -1
  127. package/dist/durable/Schedule.mjs +1 -1
  128. package/dist/durable/ScheduleStoreConformance.mjs +1 -1
  129. package/dist/durable/ScheduleTransition.mjs +1 -1
  130. package/dist/durable/Scheduling.d.mts +1 -1
  131. package/dist/durable/Scheduling.mjs +1 -1
  132. package/dist/durable/SettlementPublisher.d.mts +1 -1
  133. package/dist/durable/SettlementPublisher.mjs +3 -3
  134. package/dist/durable/SqlMemoryStore.mjs +5 -3
  135. package/dist/durable/SqlMemoryStore.mjs.map +1 -1
  136. package/dist/durable/SubmissionLedger.d.mts +1 -1
  137. package/dist/durable/SubmissionLedger.mjs +11 -3
  138. package/dist/durable/SubmissionLedger.mjs.map +1 -1
  139. package/dist/durable/SubmissionLedgerConformance.d.mts +1 -1
  140. package/dist/durable/SubmissionLedgerConformance.mjs +6 -6
  141. package/dist/durable/SubmissionStatus.d.mts +1 -1
  142. package/dist/durable/Subscription.d.mts +1 -1
  143. package/dist/durable/Subscription.mjs +2 -2
  144. package/dist/durable/SubscriptionInput.d.mts +1 -1
  145. package/dist/durable/SubscriptionInput.mjs +4 -4
  146. package/dist/durable/SubscriptionInput.mjs.map +1 -1
  147. package/dist/durable/SubscriptionStoreConformance.d.mts +1 -1
  148. package/dist/durable/SubscriptionStoreConformance.mjs +3 -3
  149. package/dist/durable/SubscriptionStoreConformance.mjs.map +1 -1
  150. package/dist/durable/SubscriptionTools.d.mts +2 -2
  151. package/dist/durable/SubscriptionTransition.d.mts +1 -1
  152. package/dist/durable/SubscriptionTransition.mjs +1 -1
  153. package/dist/durable/Subscriptions.d.mts +5 -5
  154. package/dist/durable/Subscriptions.mjs +3 -3
  155. package/dist/durable/Subscriptions.mjs.map +1 -1
  156. package/dist/durable/ThreadArchiveRange.d.mts +1 -1
  157. package/dist/durable/ThreadArchiveRange.mjs +1 -1
  158. package/dist/durable/ThreadContextHistory.d.mts +1 -1
  159. package/dist/durable/ThreadContextHistory.mjs +2 -2
  160. package/dist/durable/ThreadContextHistoryProjection.mjs +1 -1
  161. package/dist/durable/ThreadImport.d.mts +1 -1
  162. package/dist/durable/ThreadImport.mjs +1 -1
  163. package/dist/durable/ThreadInvariants.d.mts +3 -3
  164. package/dist/durable/ThreadInvariants.mjs +5 -5
  165. package/dist/durable/ThreadInvariants.mjs.map +1 -1
  166. package/dist/durable/ThreadProjection.mjs +1 -1
  167. package/dist/durable/ThreadProjectionMaintenance.d.mts +1 -1
  168. package/dist/durable/ThreadReader.d.mts +1 -1
  169. package/dist/durable/ThreadReader.mjs +1 -1
  170. package/dist/durable/ThreadStore.d.mts +1 -1
  171. package/dist/durable/ThreadStore.mjs +2 -2
  172. package/dist/durable/ThreadStoreConformance.d.mts +1 -1
  173. package/dist/durable/ThreadStoreConformance.mjs +4 -4
  174. package/dist/durable/ThreadTransfer.d.mts +1 -1
  175. package/dist/durable/ThreadTransfer.mjs +1 -1
  176. package/dist/durable/ThreadWork.d.mts +2 -2
  177. package/dist/durable/ThreadWork.mjs +12 -6
  178. package/dist/durable/ThreadWork.mjs.map +1 -1
  179. package/dist/durable/ToolReconciler.mjs +1 -1
  180. package/dist/durable/WakeScheduler.mjs +23 -39
  181. package/dist/durable/WakeScheduler.mjs.map +1 -1
  182. package/dist/durable/WorkerAdmission.d.mts +1 -1
  183. package/dist/durable/WorkerAdmission.mjs +1 -1
  184. package/dist/durable/WorkerHost.d.mts +2 -2
  185. package/dist/engine/AgentRuntime.d.mts +1 -1
  186. package/dist/engine/AgentRuntime.mjs +1 -1
  187. package/dist/engine/MessagingHost.d.mts +1 -1
  188. package/dist/engine/MessagingHost.mjs +1 -1
  189. package/dist/engine/Output.d.mts +1 -1
  190. package/dist/engine/Output.mjs +1 -1
  191. package/dist/engine/RunOptions.d.mts +1 -1
  192. package/dist/engine/SubagentHost.d.mts +1 -1
  193. package/dist/engine/ThreadHistory.d.mts +1 -1
  194. package/dist/engine/ThreadHistory.mjs +3 -2
  195. package/dist/engine/ThreadHistory.mjs.map +1 -1
  196. package/dist/index.d.mts +21 -21
  197. package/dist/index.mjs +16 -16
  198. package/dist/{output-contract-CMIhu4Cw.mjs → output-contract-DCnLYCdp.mjs} +12 -15
  199. package/dist/{output-contract-CMIhu4Cw.mjs.map → output-contract-DCnLYCdp.mjs.map} +1 -1
  200. package/dist/{run-context-reader-OcsZr4bk.d.mts → run-context-reader-DVhJZ1Qe.d.mts} +2 -2
  201. package/package.json +1 -1
  202. package/src/capabilities/Approval.ts +58 -60
  203. package/src/capabilities/BrowserUse.ts +89 -944
  204. package/src/capabilities/Budget.ts +8 -1
  205. package/src/capabilities/CodeMode.ts +57 -33
  206. package/src/capabilities/McpClient.ts +2 -2
  207. package/src/capabilities/Messaging.ts +51 -55
  208. package/src/capabilities/ModelContext.ts +5 -2
  209. package/src/capabilities/Redaction.ts +64 -34
  210. package/src/capabilities/RunHooks.ts +52 -55
  211. package/src/capabilities/Subagent.ts +33 -33
  212. package/src/capabilities/SubagentReservations.ts +9 -1
  213. package/src/capabilities/WebCapture.ts +6 -0
  214. package/src/capabilities/WebSearch.ts +10 -7
  215. package/src/capabilities/internal/subagent-background.ts +202 -158
  216. package/src/core/Agent.ts +11 -6
  217. package/src/core/AgentUpdates.ts +8 -8
  218. package/src/core/Thread.ts +142 -146
  219. package/src/core/Usage.ts +7 -8
  220. package/src/core/internal/agent-updates.ts +1 -0
  221. package/src/durable/DurableAgentRuntime.ts +1024 -829
  222. package/src/durable/EventSource.ts +15 -9
  223. package/src/durable/RecordFormat.ts +5 -3
  224. package/src/durable/RunContinuation.ts +316 -113
  225. package/src/durable/RunJournal.ts +106 -114
  226. package/src/durable/RunStorage.ts +129 -124
  227. package/src/durable/Scheduling.ts +639 -651
  228. package/src/durable/SqlMemoryStore.ts +8 -6
  229. package/src/durable/SubmissionLedger.ts +11 -0
  230. package/src/durable/SubscriptionInput.ts +5 -3
  231. package/src/durable/SubscriptionStoreConformance.ts +23 -23
  232. package/src/durable/Subscriptions.ts +18 -19
  233. package/src/durable/ThreadImport.ts +18 -19
  234. package/src/durable/ThreadInvariants.ts +2 -1
  235. package/src/durable/ThreadStore.ts +217 -111
  236. package/src/durable/ThreadWork.ts +11 -2
  237. package/src/durable/WakeScheduler.ts +34 -66
  238. package/src/durable/internal/StorageOwner.ts +10 -4
  239. package/src/durable/internal/agent-registration.ts +96 -89
  240. package/src/durable/internal/canonical-json.ts +61 -20
  241. package/src/durable/internal/prompt-history-cache.ts +13 -4
  242. package/src/durable/internal/record-encoding.ts +120 -64
  243. package/src/durable/internal/schedule-time.ts +6 -6
  244. package/src/durable/internal/usage-totals.ts +35 -0
  245. package/src/durable/internal/worker-host.ts +69 -74
  246. package/src/engine/MessagingHost.ts +4 -2
  247. package/src/engine/ThreadHistory.ts +47 -48
  248. package/src/engine/internal/agent-runtime.ts +1298 -1217
  249. package/src/engine/internal/output-contract.ts +15 -15
  250. package/src/engine/internal/primitive-delta.ts +2 -3
  251. package/src/engine/internal/provisional-text.ts +12 -10
  252. package/src/engine/internal/tool-exposure.ts +22 -18
  253. package/src/engine/internal/tool-telemetry.ts +15 -12
  254. package/dist/Agent-0WvBWWbM.mjs.map +0 -1
  255. package/dist/AgentRuntime-CQ-qcETl.mjs.map +0 -1
  256. package/dist/Digest-DCuPlhNk.mjs.map +0 -1
  257. package/dist/DurableAgentRuntime-BAmSkWYr.mjs.map +0 -1
  258. package/dist/MessagingHost-CRUK4JBi.mjs.map +0 -1
  259. package/dist/RunContinuation-DHYNAQFi.mjs.map +0 -1
  260. package/dist/RunJournal-kfKVxJj7.mjs.map +0 -1
  261. package/dist/RunStorage-uqPxps09.mjs.map +0 -1
  262. package/dist/Scheduling-CVyfXlBR.mjs.map +0 -1
  263. package/dist/Subagent-vpffemql.mjs.map +0 -1
  264. package/dist/ThreadImport-DckUMEqJ.mjs.map +0 -1
  265. package/dist/ThreadStore-CEekRa80.mjs.map +0 -1
  266. package/dist/agent-registration-ByMZ_cK5.mjs.map +0 -1
package/src/core/Agent.ts CHANGED
@@ -570,9 +570,11 @@ export function make(
570
570
 
571
571
  for (const declaration of options.completionFromTools ?? []) {
572
572
  if (declaration.tool === options.completion?.tool || completionNames.has(declaration.tool)) {
573
+ // oxlint-disable-next-line effect/no-untyped-throw, effect/no-native-error -- Agent.make synchronously rejects duplicate completion declarations before constructing the Definition.
573
574
  throw new Error(`Tool ${declaration.tool} has more than one completion declaration`);
574
575
  }
575
576
  if (!Object.hasOwn(options.toolkit.tools, declaration.tool)) {
577
+ // oxlint-disable-next-line effect/no-untyped-throw, effect/no-native-error -- Agent.make synchronously rejects completion declarations for absent Tools.
576
578
  throw new Error(`Unknown completion Tool ${declaration.tool}`);
577
579
  }
578
580
  completionNames.add(declaration.tool);
@@ -622,11 +624,14 @@ export function make(
622
624
  }
623
625
 
624
626
  /** Bind a native model or thread resolver without acquiring or hiding its requirements. */
625
- export const withModel = <DefinitionValue extends AnyDefinition, ModelValue>(
627
+ export function withModel<DefinitionValue extends AnyDefinition, ModelValue>(
626
628
  definition: DefinitionValue,
627
629
  model: NativeModel<ModelValue>,
628
- ): Binding<DefinitionValue, ModelValue> =>
629
- Object.freeze({
630
- definition,
631
- model,
632
- });
630
+ ): Binding<DefinitionValue, ModelValue>;
631
+
632
+ export function withModel<DefinitionValue extends AnyDefinition, ModelValue>(
633
+ definition: DefinitionValue,
634
+ model: ModelValue,
635
+ ) {
636
+ return Object.freeze({ definition, model });
637
+ }
@@ -59,20 +59,20 @@ export const emit = Effect.fnUntraced(function* <S extends Schema.Top>(
59
59
  ): Effect.fn.Return<Update, UpdateError, Emitter | S["EncodingServices"]> {
60
60
  const target = "definition" in agent ? agent.definition : agent;
61
61
 
62
- if (target.updates === undefined) return yield* new UpdateError({ reason: "unavailable" });
62
+ if (target.updates === undefined) return yield* UpdateError.make({ reason: "unavailable" });
63
63
 
64
64
  const updateId = yield* Schema.decodeEffect(IdempotencyKey)(options.idempotencyKey).pipe(
65
- Effect.mapError(() => new UpdateError({ reason: "validation" })),
65
+ Effect.mapError(() => UpdateError.make({ reason: "validation" })),
66
66
  );
67
67
 
68
68
  const encoded = yield* Schema.encodeEffect(target.updates)(value).pipe(
69
69
  Effect.flatMap(Schema.decodeUnknownEffect(Schema.Json)),
70
- Effect.mapError(() => new UpdateError({ reason: "validation" })),
70
+ Effect.mapError(() => UpdateError.make({ reason: "validation" })),
71
71
  );
72
72
 
73
73
  const emitter = yield* Effect.serviceOption(Emitter);
74
74
 
75
- if (Option.isNone(emitter)) return yield* new UpdateError({ reason: "unavailable" });
75
+ if (Option.isNone(emitter)) return yield* UpdateError.make({ reason: "unavailable" });
76
76
 
77
77
  return yield* emitter.value.emit({ target, updateId, value: encoded });
78
78
  });
@@ -84,16 +84,16 @@ export const decode = Effect.fnUntraced(function* <S extends Schema.Top>(
84
84
  ): Effect.fn.Return<S["Type"], UpdateError, S["DecodingServices"]> {
85
85
  const definition = "definition" in agent ? agent.definition : agent;
86
86
 
87
- if (definition.updates === undefined) return yield* new UpdateError({ reason: "unavailable" });
87
+ if (definition.updates === undefined) return yield* UpdateError.make({ reason: "unavailable" });
88
88
 
89
89
  const decoded = yield* Schema.decodeEffect(Update)(update).pipe(
90
- Effect.mapError(() => new UpdateError({ reason: "validation" })),
90
+ Effect.mapError(() => UpdateError.make({ reason: "validation" })),
91
91
  );
92
92
 
93
- if (decoded.agentId !== definition.id) return yield* new UpdateError({ reason: "identity" });
93
+ if (decoded.agentId !== definition.id) return yield* UpdateError.make({ reason: "identity" });
94
94
 
95
95
  return yield* Schema.decodeEffect(definition.updates)(decoded.value).pipe(
96
- Effect.mapError(() => new UpdateError({ reason: "validation" })),
96
+ Effect.mapError(() => UpdateError.make({ reason: "validation" })),
97
97
  );
98
98
  });
99
99
 
@@ -287,164 +287,160 @@ const appendEncoded = Effect.fnUntraced(function* (
287
287
  });
288
288
 
289
289
  /** In-memory storage shared for the consumer's Scope; it does not survive process loss. */
290
- export const layerMemory = Layer.effect(
291
- Store,
292
- Effect.gen(function* () {
293
- const state = yield* SynchronizedRef.make<State>({ threads: new Map(), contentBytes: 0 });
294
- const root: Owner = { closed: false };
295
-
296
- const release = (owner: Owner) =>
297
- SynchronizedRef.update(state, (current) => {
298
- owner.closed = true;
299
- const threads = new Map(current.threads);
300
- let contentBytes = current.contentBytes;
301
-
302
- for (const [id, entry] of threads) {
303
- if (belongsTo(entry.owner, owner)) {
304
- threads.delete(id);
305
- contentBytes -= entry.snapshot.contentBytes;
306
- }
290
+ export const makeMemoryStore = Effect.gen(function* () {
291
+ const state = yield* SynchronizedRef.make<State>({ threads: new Map(), contentBytes: 0 });
292
+ const root: Owner = { closed: false };
293
+
294
+ const release = (owner: Owner) =>
295
+ SynchronizedRef.update(state, (current) => {
296
+ owner.closed = true;
297
+ const threads = new Map(current.threads);
298
+ let contentBytes = current.contentBytes;
299
+
300
+ for (const [id, entry] of threads) {
301
+ if (belongsTo(entry.owner, owner)) {
302
+ threads.delete(id);
303
+ contentBytes -= entry.snapshot.contentBytes;
307
304
  }
305
+ }
308
306
 
309
- return { threads, contentBytes };
310
- });
307
+ return { threads, contentBytes };
308
+ });
311
309
 
312
- yield* Effect.addFinalizer(() => release(root));
313
-
314
- const view = (owner: Owner): StoreService => ({
315
- scoped: Effect.acquireRelease(
316
- Effect.sync((): Owner => ({ closed: false, parent: owner })),
317
- release,
318
- ).pipe(Effect.map(view)),
319
- create: (threadId) =>
320
- SynchronizedRef.modifyEffect(
321
- state,
322
- Effect.fnUntraced(function* (threads) {
323
- const existing = yield* access(threads, owner, threadId);
324
-
325
- if (existing !== undefined) return [existing, threads] as const;
326
- if (threads.threads.size >= MAX_THREADS) {
327
- return yield* ThreadLimitExceeded.make({
328
- threadId,
329
- limit: "threads",
330
- limitValue: MAX_THREADS,
331
- observedValue: threads.threads.size + 1,
332
- });
333
- }
310
+ yield* Effect.addFinalizer(() => release(root));
311
+
312
+ const view = (owner: Owner): StoreService => ({
313
+ scoped: Effect.acquireRelease(
314
+ Effect.sync((): Owner => ({ closed: false, parent: owner })),
315
+ release,
316
+ ).pipe(Effect.map(view)),
317
+ create: (threadId) =>
318
+ SynchronizedRef.modifyEffect(
319
+ state,
320
+ Effect.fnUntraced(function* (threads) {
321
+ const existing = yield* access(threads, owner, threadId);
322
+
323
+ if (existing !== undefined) return [existing, threads] as const;
324
+ if (threads.threads.size >= MAX_THREADS) {
325
+ return yield* ThreadLimitExceeded.make({
326
+ threadId,
327
+ limit: "threads",
328
+ limitValue: MAX_THREADS,
329
+ observedValue: threads.threads.size + 1,
330
+ });
331
+ }
334
332
 
335
- const created = Thread.make({
336
- version: 1,
333
+ const created = Thread.make({
334
+ version: 1,
335
+ threadId,
336
+ nextSequence: 0,
337
+ contentBytes: 0,
338
+ messages: [],
339
+ });
340
+
341
+ return [created, put(threads, owner, created)] as const;
342
+ }),
343
+ ),
344
+ append: Effect.fnUntraced(function* (threadId, message) {
345
+ const encoded = yield* encodeMessage(threadId, message.message);
346
+ const timestamp = DateTime.toUtc(DateTime.makeUnsafe(yield* Clock.currentTimeMillis));
347
+
348
+ return yield* SynchronizedRef.modifyEffect(
349
+ state,
350
+ Effect.fnUntraced(function* (threads) {
351
+ const current = yield* findSnapshot(threads, owner, threadId);
352
+
353
+ return yield* appendEncoded(threads, owner, current, message, encoded, timestamp);
354
+ }),
355
+ );
356
+ }),
357
+ recordHistory: Effect.fnUntraced(function* (threadId, historyRunId, history) {
358
+ const incoming = yield* Effect.forEach(history.content, (message) =>
359
+ encodeMessage(threadId, message).pipe(Effect.map((encoded) => ({ message, encoded }))),
360
+ );
361
+
362
+ // Publish the complete suffix only after verification and every bounded append succeed.
363
+ return yield* SynchronizedRef.modifyEffect(
364
+ state,
365
+ Effect.fnUntraced(function* (threads) {
366
+ const current = yield* findSnapshot(threads, owner, threadId);
367
+
368
+ const currentEncoded = yield* Effect.forEach(current.messages, (entry) =>
369
+ encodeMessage(threadId, entry.message),
370
+ );
371
+
372
+ if (
373
+ incoming.length < currentEncoded.length ||
374
+ currentEncoded.some((encoded, index) => encoded !== incoming[index]?.encoded)
375
+ ) {
376
+ return yield* ThreadHistoryDiverged.make({
337
377
  threadId,
338
- nextSequence: 0,
339
- contentBytes: 0,
340
- messages: [],
378
+ message: "Engine history is not an append-only extension of official history",
341
379
  });
380
+ }
381
+ const timestamp = DateTime.toUtc(DateTime.makeUnsafe(yield* Clock.currentTimeMillis));
342
382
 
343
- return [created, put(threads, owner, created)] as const;
344
- }),
345
- ),
346
- append: Effect.fnUntraced(function* (threadId, message) {
347
- const encoded = yield* encodeMessage(threadId, message.message);
348
- const timestamp = DateTime.toUtc(DateTime.makeUnsafe(yield* Clock.currentTimeMillis));
349
-
350
- return yield* SynchronizedRef.modifyEffect(
351
- state,
352
- Effect.fnUntraced(function* (threads) {
353
- const current = yield* findSnapshot(threads, owner, threadId);
354
-
355
- return yield* appendEncoded(threads, owner, current, message, encoded, timestamp);
356
- }),
357
- );
358
- }),
359
- recordHistory: Effect.fnUntraced(function* (threadId, historyRunId, history) {
360
- const incoming = yield* Effect.forEach(history.content, (message) =>
361
- encodeMessage(threadId, message).pipe(Effect.map((encoded) => ({ message, encoded }))),
362
- );
363
-
364
- // Publish the complete suffix only after verification and every bounded append succeed.
365
- return yield* SynchronizedRef.modifyEffect(
366
- state,
367
- Effect.fnUntraced(function* (threads) {
368
- const current = yield* findSnapshot(threads, owner, threadId);
369
-
370
- const currentEncoded = yield* Effect.forEach(current.messages, (entry) =>
371
- encodeMessage(threadId, entry.message),
372
- );
383
+ if (incoming.length === currentEncoded.length) return [current, threads] as const;
384
+
385
+ const messages = [...current.messages];
386
+ let contentBytes = current.contentBytes;
387
+ let storeBytes = threads.contentBytes;
388
+ let nextSequence = current.nextSequence;
389
+
390
+ for (const entry of incoming.slice(currentEncoded.length)) {
391
+ const append = ThreadAppend.make({ runId: historyRunId, message: entry.message });
373
392
 
374
- if (
375
- incoming.length < currentEncoded.length ||
376
- currentEncoded.some((encoded, index) => encoded !== incoming[index]?.encoded)
377
- ) {
378
- return yield* ThreadHistoryDiverged.make({
393
+ const messageBytes = yield* messageSize(threadId, entry.encoded);
394
+
395
+ contentBytes += messageBytes;
396
+ storeBytes += messageBytes;
397
+ if (storeBytes > MAX_STORE_CONTENT_BYTES) {
398
+ return yield* ThreadLimitExceeded.make({
379
399
  threadId,
380
- message: "Engine history is not an append-only extension of official history",
400
+ limit: "store-content-bytes",
401
+ limitValue: MAX_STORE_CONTENT_BYTES,
402
+ observedValue: storeBytes,
381
403
  });
382
404
  }
383
- const timestamp = DateTime.toUtc(DateTime.makeUnsafe(yield* Clock.currentTimeMillis));
384
-
385
- if (incoming.length === currentEncoded.length) return [current, threads] as const;
386
-
387
- const messages = [...current.messages];
388
- let contentBytes = current.contentBytes;
389
- let storeBytes = threads.contentBytes;
390
- let nextSequence = current.nextSequence;
391
-
392
- for (const entry of incoming.slice(currentEncoded.length)) {
393
- const append = ThreadAppend.make({ runId: historyRunId, message: entry.message });
394
-
395
- const messageBytes = yield* messageSize(threadId, entry.encoded);
396
-
397
- contentBytes += messageBytes;
398
- storeBytes += messageBytes;
399
- if (storeBytes > MAX_STORE_CONTENT_BYTES) {
400
- return yield* ThreadLimitExceeded.make({
401
- threadId,
402
- limit: "store-content-bytes",
403
- limitValue: MAX_STORE_CONTENT_BYTES,
404
- observedValue: storeBytes,
405
- });
406
- }
407
- messages.push(
408
- ThreadMessage.make({
409
- threadId,
410
- sequence: nextSequence,
411
- ...(append.runId === undefined ? {} : { runId: append.runId }),
412
- message: append.message,
413
- encodedBytes: messageBytes,
414
- timestamp,
415
- }),
416
- );
417
- nextSequence += 1;
418
- }
419
-
420
- const snapshot = Thread.make({
421
- version: current.version,
422
- threadId,
423
- nextSequence,
424
- contentBytes,
425
- messages,
426
- });
405
+ messages.push(
406
+ ThreadMessage.make({
407
+ threadId,
408
+ sequence: nextSequence,
409
+ ...(append.runId === undefined ? {} : { runId: append.runId }),
410
+ message: append.message,
411
+ encodedBytes: messageBytes,
412
+ timestamp,
413
+ }),
414
+ );
415
+ nextSequence += 1;
416
+ }
427
417
 
428
- return [snapshot, put(threads, owner, snapshot)] as const;
429
- }),
430
- );
431
- }),
432
- snapshot: (threadId) =>
433
- SynchronizedRef.get(state).pipe(
434
- Effect.flatMap((all) => findSnapshot(all, owner, threadId)),
435
- ),
436
- export: (threadId) =>
437
- Effect.gen(function* () {
438
- const snapshot = yield* findSnapshot(yield* SynchronizedRef.get(state), owner, threadId);
439
-
440
- return ThreadExport.make({
441
- format: "effect-agent/ephemeral-thread@1",
442
- exportedAt: DateTime.toUtc(DateTime.makeUnsafe(yield* Clock.currentTimeMillis)),
443
- snapshot,
418
+ const snapshot = Thread.make({
419
+ version: current.version,
420
+ threadId,
421
+ nextSequence,
422
+ contentBytes,
423
+ messages,
444
424
  });
425
+
426
+ return [snapshot, put(threads, owner, snapshot)] as const;
445
427
  }),
446
- });
428
+ );
429
+ }),
430
+ snapshot: (threadId) =>
431
+ SynchronizedRef.get(state).pipe(Effect.flatMap((all) => findSnapshot(all, owner, threadId))),
432
+ export: Effect.fnUntraced(function* (threadId) {
433
+ const snapshot = yield* findSnapshot(yield* SynchronizedRef.get(state), owner, threadId);
434
+
435
+ return ThreadExport.make({
436
+ format: "effect-agent/ephemeral-thread@1",
437
+ exportedAt: DateTime.toUtc(DateTime.makeUnsafe(yield* Clock.currentTimeMillis)),
438
+ snapshot,
439
+ });
440
+ }),
441
+ });
442
+
443
+ return view(root);
444
+ });
447
445
 
448
- return view(root);
449
- }),
450
- );
446
+ export const layerMemory = Layer.effect(Store, makeMemoryStore);
package/src/core/Usage.ts CHANGED
@@ -293,8 +293,8 @@ export const sumRunTotals = Effect.fnUntraced(function* (
293
293
 
294
294
  for (const contribution of contributions) {
295
295
  const value = yield* Schema.decodeEffect(RunTotals)(contribution).pipe(
296
- Effect.mapError(
297
- () => new UsageAggregationError({ field: "totals", message: "Invalid Run totals" }),
296
+ Effect.mapError(() =>
297
+ UsageAggregationError.make({ field: "totals", message: "Invalid Run totals" }),
298
298
  ),
299
299
  );
300
300
 
@@ -376,12 +376,11 @@ export const summarizeModelUsage = Effect.fnUntraced(function* (
376
376
  seed === undefined
377
377
  ? undefined
378
378
  : yield* Schema.decodeEffect(RunUsageSummary)(seed).pipe(
379
- Effect.mapError(
380
- () =>
381
- new UsageAggregationError({
382
- field: "seed",
383
- message: "Canonical usage seed does not satisfy the RunUsageSummary Schema",
384
- }),
379
+ Effect.mapError(() =>
380
+ UsageAggregationError.make({
381
+ field: "seed",
382
+ message: "Canonical usage seed does not satisfy the RunUsageSummary Schema",
383
+ }),
385
384
  ),
386
385
  );
387
386
 
@@ -29,6 +29,7 @@ export const withUpdateTool = (
29
29
  ): Toolkit.Any => {
30
30
  if (schema === undefined) return toolkit;
31
31
  if (Object.hasOwn(toolkit.tools, "emit_update"))
32
+ // oxlint-disable-next-line effect/no-untyped-throw, effect/no-native-error -- Agent.make synchronously rejects a toolkit that occupies the reserved update Tool name.
32
33
  throw new TypeError("emit_update is reserved for Agent updates");
33
34
 
34
35
  return Toolkit.make(...Object.values(toolkit.tools), updateTool(schema));