@statelyai/agent 2.0.0-alpha.38 → 2.0.0-alpha.40

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 (137) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/dist/{act-CrX0JwWY.cjs → act-B0CVbmo4.cjs} +1 -1
  3. package/dist/{act-B9hLQls6.mjs → act-Bsz-hUfD.mjs} +1 -1
  4. package/dist/ai-sdk.cjs +4 -4
  5. package/dist/ai-sdk.d.cts +2 -3
  6. package/dist/ai-sdk.d.mts +2 -3
  7. package/dist/ai-sdk.mjs +4 -4
  8. package/dist/{decision-m5hGmHpF.mjs → decision-B41YBx5U.mjs} +1 -1
  9. package/dist/{decision-CMeuNZ1g.cjs → decision-D8bcIGXQ.cjs} +1 -1
  10. package/dist/{decision-object-DBcLWVvv.d.cts → decision-object-BB8XV5Ec.d.cts} +1 -1
  11. package/dist/{decision-object-B5zGSPFp.d.mts → decision-object-CH_sE694.d.mts} +1 -1
  12. package/dist/effects-B9IvUPVh.mjs +23 -0
  13. package/dist/effects-DrWcUGgc.cjs +34 -0
  14. package/dist/evals.cjs +810 -0
  15. package/dist/evals.d.cts +595 -0
  16. package/dist/evals.d.mts +595 -0
  17. package/dist/evals.mjs +801 -0
  18. package/dist/{event-log-DkVlk3Rh.mjs → event-log-CEq_bVXQ.mjs} +8 -4
  19. package/dist/{event-log-Dkc-yIYu.cjs → event-log-dSOnXHuG.cjs} +7 -15
  20. package/dist/{event-log-store-Brx9tOHt.mjs → event-log-store-DLAfNM34.mjs} +1 -1
  21. package/dist/{event-log-store-BBS8so8a.d.mts → event-log-store-DYun526m.d.mts} +15 -14
  22. package/dist/{event-log-store-Cl-YWDnq.cjs → event-log-store-Dey9ufA4.cjs} +1 -1
  23. package/dist/{event-log-store-bc4ICGcS.d.cts → event-log-store-aFXK6yZX.d.cts} +15 -14
  24. package/dist/index.cjs +142 -97
  25. package/dist/index.d.cts +97 -141
  26. package/dist/index.d.mts +97 -141
  27. package/dist/index.mjs +123 -74
  28. package/dist/internal-BzlpzSux.d.cts +14 -0
  29. package/dist/internal-BzlpzSux.d.mts +14 -0
  30. package/dist/log.cjs +2 -3
  31. package/dist/log.d.cts +2 -2
  32. package/dist/log.d.mts +2 -2
  33. package/dist/log.mjs +3 -3
  34. package/dist/machine-input-0YTPcnCm.mjs +27 -0
  35. package/dist/machine-input-DU3owLUr.cjs +32 -0
  36. package/dist/machines.cjs +1 -719
  37. package/dist/machines.d.cts +2 -424
  38. package/dist/machines.d.mts +2 -424
  39. package/dist/machines.mjs +2 -709
  40. package/dist/{model-source-kjGwqAV8.mjs → model-source-BrsLDvHL.mjs} +1 -1
  41. package/dist/{model-source-B4WQ8Idp.cjs → model-source-YpxjmWuX.cjs} +1 -1
  42. package/dist/openai.cjs +3 -3
  43. package/dist/openai.d.cts +2 -3
  44. package/dist/openai.d.mts +2 -3
  45. package/dist/openai.mjs +3 -3
  46. package/dist/otel.d.cts +1 -1
  47. package/dist/otel.d.mts +1 -1
  48. package/dist/policy.cjs +77 -0
  49. package/dist/policy.d.cts +143 -0
  50. package/dist/policy.d.mts +143 -0
  51. package/dist/policy.mjs +75 -0
  52. package/dist/{run-agent-DlPzBWj-.d.mts → run-agent-BO9RSb7i.d.cts} +33 -40
  53. package/dist/{run-agent-30mH2moE.d.cts → run-agent-BxkeuAYR.d.mts} +33 -40
  54. package/dist/{effects-DDseYtJk.cjs → run-agent-COdR9FpM.cjs} +175 -228
  55. package/dist/{effects-BT_cSY0j.mjs → run-agent-D3gW9wfd.mjs} +176 -211
  56. package/dist/{setup-agent-BDmNr6PC.mjs → setup-agent-CLm6QVGy.mjs} +3 -3
  57. package/dist/{setup-agent-BaNyz6Q3.d.cts → setup-agent-Cv8Hk3mX.d.cts} +12 -11
  58. package/dist/{setup-agent-C1CG_nfX.d.mts → setup-agent-DgFAhaPJ.d.mts} +12 -11
  59. package/dist/{setup-agent-CmEToB8y.cjs → setup-agent-Dv5VpuHe.cjs} +3 -3
  60. package/dist/tanstack-ai.cjs +4 -4
  61. package/dist/tanstack-ai.d.cts +2 -3
  62. package/dist/tanstack-ai.d.mts +2 -3
  63. package/dist/tanstack-ai.mjs +4 -4
  64. package/dist/testing.cjs +122 -996
  65. package/dist/testing.d.cts +36 -695
  66. package/dist/testing.d.mts +36 -695
  67. package/dist/testing.mjs +112 -977
  68. package/dist/{text-logic-BqxalgMr.d.mts → text-logic-x17uLBwA.d.cts} +238 -2
  69. package/dist/{text-logic-CSf9bqpP.d.cts → text-logic-x17uLBwA.d.mts} +238 -2
  70. package/dist/trajectory-BFjXaooB.d.cts +96 -0
  71. package/dist/trajectory-BFjXaooB.d.mts +96 -0
  72. package/dist/trajectory-BUXj_1Ue.mjs +152 -0
  73. package/dist/trajectory-CoZSv4wF.cjs +157 -0
  74. package/dist/{usage-Bm5nvpow.d.cts → usage-B4B-TQSV.d.mts} +1 -1
  75. package/dist/{usage-BnikdOca.d.mts → usage-DvGcoK6x.d.cts} +1 -1
  76. package/dist/{utils-7lSa4H-i.d.cts → utils-B8k-YPYI.d.mts} +23 -17
  77. package/dist/{utils-CBbKw2fM.d.mts → utils-DAclF-kw.d.cts} +23 -17
  78. package/dist/validate.cjs +4 -4
  79. package/dist/validate.d.cts +2 -2
  80. package/dist/validate.d.mts +2 -2
  81. package/dist/validate.mjs +4 -4
  82. package/dist/{verify-DJHfEfm6.d.cts → verify-CIu4mqIZ.d.mts} +56 -6
  83. package/dist/{verify-i9Hiwc5g.d.mts → verify-CTHlmBbh.d.cts} +56 -6
  84. package/dist/{verify-ChyX6jq0.mjs → verify-Cacz6XSk.mjs} +170 -46
  85. package/dist/{verify-CwlombbC.cjs → verify-D8UDqU4l.cjs} +170 -46
  86. package/dist/{with-model-calls-B_WLmOSl.cjs → with-model-calls-D50Ca6qW.cjs} +2 -2
  87. package/dist/{with-model-calls-BkOwdroS.mjs → with-model-calls-uY-KKliA.mjs} +2 -2
  88. package/docs/advanced.md +5 -5
  89. package/docs/choosing-a-run-mode.md +7 -7
  90. package/docs/debugging.md +6 -8
  91. package/docs/decisions.md +5 -4
  92. package/docs/environment-and-policy.md +1 -1
  93. package/docs/evals.md +57 -43
  94. package/docs/event-log.md +13 -15
  95. package/docs/from-a-loop.md +3 -3
  96. package/docs/generate-machines.md +4 -4
  97. package/docs/hosts.md +25 -30
  98. package/docs/human-in-the-loop.md +5 -8
  99. package/docs/index.md +4 -4
  100. package/docs/judgments.md +5 -7
  101. package/docs/langgraph-comparison.md +6 -6
  102. package/docs/machines-as-data.md +7 -12
  103. package/docs/machines-presets.md +17 -120
  104. package/docs/machines.md +13 -13
  105. package/docs/models-and-providers.md +19 -25
  106. package/docs/multi-agent.md +1 -1
  107. package/docs/observability.md +6 -8
  108. package/docs/persistence.md +10 -20
  109. package/docs/quickstart.md +3 -3
  110. package/docs/statechart-policy-examples.md +1 -1
  111. package/docs/steps.md +5 -6
  112. package/docs/strangler-fig.md +105 -33
  113. package/docs/text-requests.md +10 -12
  114. package/docs/thinking-in-state-machines.md +8 -8
  115. package/docs/tools.md +10 -12
  116. package/docs/upgrading.md +1 -1
  117. package/docs/usage-and-budgets.md +51 -56
  118. package/docs/validate-and-repair.md +9 -14
  119. package/docs/verify.md +54 -7
  120. package/docs/xstate-4-and-5-apps.md +19 -28
  121. package/llms.txt +1 -1
  122. package/package.json +31 -6
  123. package/readme.md +32 -24
  124. package/dist/internal-C3Lqu538.d.cts +0 -43
  125. package/dist/internal-DUcdhk-i.d.mts +0 -43
  126. package/dist/types-DQUOOaZO.d.cts +0 -238
  127. package/dist/types-DQUOOaZO.d.mts +0 -238
  128. package/skills/add-evals/SKILL.md +0 -152
  129. package/skills/add-traces/SKILL.md +0 -152
  130. package/skills/build-machine/SKILL.md +0 -84
  131. package/skills/generate-machine/SKILL.md +0 -335
  132. package/skills/graph-engineering/SKILL.md +0 -43
  133. package/skills/improve-machine/SKILL.md +0 -261
  134. package/skills/improve-machine/reference.md +0 -101
  135. package/skills/loop-to-machine/SKILL.md +0 -205
  136. package/skills/loop-to-machine/policy.md +0 -154
  137. package/skills/loop-to-machine/reference.md +0 -260
@@ -1,9 +1,151 @@
1
- const require_event_log = require("./event-log-Dkc-yIYu.cjs");
2
- const require_decision = require("./decision-CMeuNZ1g.cjs");
3
- const require_act = require("./act-CrX0JwWY.cjs");
4
- const require_event_log_store = require("./event-log-store-Cl-YWDnq.cjs");
1
+ const require_event_log = require("./event-log-dSOnXHuG.cjs");
2
+ const require_decision = require("./decision-D8bcIGXQ.cjs");
3
+ const require_act = require("./act-B0CVbmo4.cjs");
4
+ const require_event_log_store = require("./event-log-store-Dey9ufA4.cjs");
5
+ const require_machine_input = require("./machine-input-DU3owLUr.cjs");
5
6
  let xstate = require("xstate");
6
7
  let xstate_durable = require("xstate/durable");
8
+ //#region src/internal/stable-inspection.ts
9
+ const stableInspections = /* @__PURE__ */ new WeakSet();
10
+ /** Whether `inspect` already came from {@link stableInspection}. */
11
+ function isStableInspection(inspect) {
12
+ return typeof inspect === "function" && stableInspections.has(inspect);
13
+ }
14
+ function actorPath(ref) {
15
+ const ids = [];
16
+ let current = ref;
17
+ while (require_event_log.isRecord(current)) {
18
+ ids.unshift(current["id"]);
19
+ current = current["_parent"];
20
+ }
21
+ return JSON.stringify(ids);
22
+ }
23
+ function persistedChildPaths(persisted, prefix = [], paths = /* @__PURE__ */ new Set()) {
24
+ const children = require_event_log.isRecord(persisted) ? persisted["children"] : void 0;
25
+ if (!require_event_log.isRecord(children)) return paths;
26
+ for (const [id, child] of Object.entries(children)) {
27
+ const path = [...prefix, id];
28
+ paths.add(JSON.stringify(path));
29
+ persistedChildPaths(require_event_log.isRecord(child) ? child["snapshot"] : void 0, path, paths);
30
+ }
31
+ return paths;
32
+ }
33
+ /**
34
+ * Makes a durable run's inspection stream look like one live actor system to
35
+ * an inspector. The durable runtime re-creates an actor object for each step
36
+ * under the same `sessionId` and announces it again, so an inspector that
37
+ * tracks actors by object (`@statelyai/sdk`) sees a duplicate and drops the
38
+ * rest of the run. Each `sessionId` gets one stable handle that reads from the
39
+ * newest actor object, and is announced once. Across runtimes (`runAgent`'s
40
+ * `onIdle` passes), {@link StableInspection.endPass} carries live actors over.
41
+ */
42
+ function stableInspection(inspect) {
43
+ const handles = /* @__PURE__ */ new Map();
44
+ const announced = /* @__PURE__ */ new Set();
45
+ const snapshots = /* @__PURE__ */ new WeakMap();
46
+ const aliases = /* @__PURE__ */ new Map();
47
+ const live = /* @__PURE__ */ new Map();
48
+ const stopped = /* @__PURE__ */ new Map();
49
+ let carried = /* @__PURE__ */ new Map();
50
+ const stableSnapshot = (snapshot) => {
51
+ if (!require_event_log.isRecord(snapshot) || !require_event_log.isRecord(snapshot["children"])) return snapshot;
52
+ const cached = snapshots.get(snapshot);
53
+ if (cached) return cached;
54
+ const copy = Object.create(Object.getPrototypeOf(snapshot), Object.getOwnPropertyDescriptors(snapshot));
55
+ copy["children"] = Object.fromEntries(Object.entries(snapshot["children"]).map(([id, child]) => [id, stable(child)]));
56
+ snapshots.set(snapshot, copy);
57
+ return copy;
58
+ };
59
+ const stable = (ref, adopt = false) => {
60
+ if (!require_event_log.isRecord(ref) || typeof ref["sessionId"] !== "string") return ref;
61
+ const sessionId = aliases.get(ref["sessionId"]) ?? ref["sessionId"];
62
+ const known = handles.get(sessionId);
63
+ if (known) {
64
+ if (adopt) known.latest = ref;
65
+ return known.handle;
66
+ }
67
+ const entry = {
68
+ latest: ref,
69
+ handle: ref
70
+ };
71
+ entry.handle = new Proxy(ref, {
72
+ get(_target, key) {
73
+ const value = Reflect.get(entry.latest, key, entry.latest);
74
+ if (key === "_parent") return stable(value);
75
+ if (key === "ref") return entry.handle;
76
+ if (key === "sessionId") return sessionId;
77
+ if (key === "getSnapshot") return () => stableSnapshot(entry.latest.getSnapshot());
78
+ if (key === "_snapshot") return stableSnapshot(value);
79
+ if (key === "options" && require_event_log.isRecord(value) && value["parent"] !== void 0) return {
80
+ ...value,
81
+ parent: stable(value["parent"])
82
+ };
83
+ return typeof value === "function" ? value.bind(entry.latest) : value;
84
+ },
85
+ has: (_target, key) => key in entry.latest
86
+ });
87
+ handles.set(sessionId, entry);
88
+ return entry.handle;
89
+ };
90
+ const stableInspect = ((event) => {
91
+ const raw = event;
92
+ const actorRef = raw["actorRef"];
93
+ const rawSessionId = require_event_log.isRecord(actorRef) ? actorRef["sessionId"] : void 0;
94
+ if (raw["type"] === "@xstate.actor" && typeof rawSessionId === "string") {
95
+ const path = actorPath(actorRef);
96
+ const previous = carried.get(path);
97
+ if (previous !== void 0 && previous !== rawSessionId) {
98
+ carried.delete(path);
99
+ aliases.set(rawSessionId, previous);
100
+ }
101
+ const sessionId = aliases.get(rawSessionId) ?? rawSessionId;
102
+ live.set(sessionId, path);
103
+ if (announced.has(sessionId)) {
104
+ stable(actorRef, true);
105
+ return;
106
+ }
107
+ announced.add(sessionId);
108
+ }
109
+ if (typeof rawSessionId === "string" && require_event_log.isRecord(raw["snapshot"])) {
110
+ const status = raw["snapshot"]["status"];
111
+ if (status !== void 0 && status !== "active") {
112
+ const sessionId = aliases.get(rawSessionId) ?? rawSessionId;
113
+ const path = live.get(sessionId);
114
+ live.delete(sessionId);
115
+ if (status === "stopped" && path !== void 0) stopped.set(sessionId, path);
116
+ }
117
+ }
118
+ const next = {
119
+ ...raw,
120
+ actorRef: stable(actorRef, true)
121
+ };
122
+ if (raw["snapshot"] !== void 0) next["snapshot"] = stableSnapshot(raw["snapshot"]);
123
+ if (Array.isArray(raw["sent"])) next["sent"] = raw["sent"].map((sent) => require_event_log.isRecord(sent) && sent["targetRef"] !== void 0 ? {
124
+ ...sent,
125
+ targetRef: stable(sent["targetRef"])
126
+ } : sent);
127
+ for (const key of [
128
+ "parentRef",
129
+ "sourceRef",
130
+ "targetRef"
131
+ ]) if (raw[key] !== void 0) next[key] = stable(raw[key]);
132
+ inspect(next);
133
+ });
134
+ stableInspect.endPass = (persisted) => {
135
+ const kept = persistedChildPaths(persisted);
136
+ const root = [...live.values(), ...stopped.values()].find((path) => JSON.parse(path).length === 1);
137
+ const rootId = root === void 0 ? void 0 : JSON.parse(root)[0];
138
+ const carriedStopped = [...stopped].filter(([, path]) => {
139
+ const [id, ...rest] = JSON.parse(path);
140
+ return id === rootId && kept.has(JSON.stringify(rest));
141
+ });
142
+ stopped.clear();
143
+ carried = new Map([...live, ...carriedStopped].map(([sessionId, path]) => [path, sessionId]));
144
+ };
145
+ stableInspections.add(stableInspect);
146
+ return stableInspect;
147
+ }
148
+ //#endregion
7
149
  //#region src/decide-next.ts
8
150
  /**
9
151
  * Asks a model to choose the next event for ANY XState snapshot, including a
@@ -182,147 +324,6 @@ function short(value, max = 60) {
182
324
  return text.length > max ? `${text.slice(0, max - 1)}…` : text;
183
325
  }
184
326
  //#endregion
185
- //#region src/internal/stable-inspection.ts
186
- const stableInspections = /* @__PURE__ */ new WeakSet();
187
- /** Whether `inspect` already came from {@link stableInspection}. */
188
- function isStableInspection(inspect) {
189
- return typeof inspect === "function" && stableInspections.has(inspect);
190
- }
191
- function actorPath(ref) {
192
- const ids = [];
193
- let current = ref;
194
- while (require_event_log.isRecord(current)) {
195
- ids.unshift(current["id"]);
196
- current = current["_parent"];
197
- }
198
- return JSON.stringify(ids);
199
- }
200
- function persistedChildPaths(persisted, prefix = [], paths = /* @__PURE__ */ new Set()) {
201
- const children = require_event_log.isRecord(persisted) ? persisted["children"] : void 0;
202
- if (!require_event_log.isRecord(children)) return paths;
203
- for (const [id, child] of Object.entries(children)) {
204
- const path = [...prefix, id];
205
- paths.add(JSON.stringify(path));
206
- persistedChildPaths(require_event_log.isRecord(child) ? child["snapshot"] : void 0, path, paths);
207
- }
208
- return paths;
209
- }
210
- /**
211
- * Makes a durable run's inspection stream look like one live actor system to
212
- * an inspector. The durable runtime re-creates an actor object for each step
213
- * under the same `sessionId` and announces it again, so an inspector that
214
- * tracks actors by object (`@statelyai/sdk`) sees a duplicate and drops the
215
- * rest of the run. Each `sessionId` gets one stable handle that reads from the
216
- * newest actor object, and is announced once. Across runtimes (`runAgent`'s
217
- * `onIdle` passes), {@link StableInspection.endPass} carries live actors over.
218
- */
219
- function stableInspection(inspect) {
220
- const handles = /* @__PURE__ */ new Map();
221
- const announced = /* @__PURE__ */ new Set();
222
- const snapshots = /* @__PURE__ */ new WeakMap();
223
- const aliases = /* @__PURE__ */ new Map();
224
- const live = /* @__PURE__ */ new Map();
225
- const stopped = /* @__PURE__ */ new Map();
226
- let carried = /* @__PURE__ */ new Map();
227
- const stableSnapshot = (snapshot) => {
228
- if (!require_event_log.isRecord(snapshot) || !require_event_log.isRecord(snapshot["children"])) return snapshot;
229
- const cached = snapshots.get(snapshot);
230
- if (cached) return cached;
231
- const copy = Object.create(Object.getPrototypeOf(snapshot), Object.getOwnPropertyDescriptors(snapshot));
232
- copy["children"] = Object.fromEntries(Object.entries(snapshot["children"]).map(([id, child]) => [id, stable(child)]));
233
- snapshots.set(snapshot, copy);
234
- return copy;
235
- };
236
- const stable = (ref, adopt = false) => {
237
- if (!require_event_log.isRecord(ref) || typeof ref["sessionId"] !== "string") return ref;
238
- const sessionId = aliases.get(ref["sessionId"]) ?? ref["sessionId"];
239
- const known = handles.get(sessionId);
240
- if (known) {
241
- if (adopt) known.latest = ref;
242
- return known.handle;
243
- }
244
- const entry = {
245
- latest: ref,
246
- handle: ref
247
- };
248
- entry.handle = new Proxy(ref, {
249
- get(_target, key) {
250
- const value = Reflect.get(entry.latest, key, entry.latest);
251
- if (key === "_parent") return stable(value);
252
- if (key === "ref") return entry.handle;
253
- if (key === "sessionId") return sessionId;
254
- if (key === "getSnapshot") return () => stableSnapshot(entry.latest.getSnapshot());
255
- if (key === "_snapshot") return stableSnapshot(value);
256
- if (key === "options" && require_event_log.isRecord(value) && value["parent"] !== void 0) return {
257
- ...value,
258
- parent: stable(value["parent"])
259
- };
260
- return typeof value === "function" ? value.bind(entry.latest) : value;
261
- },
262
- has: (_target, key) => key in entry.latest
263
- });
264
- handles.set(sessionId, entry);
265
- return entry.handle;
266
- };
267
- const stableInspect = ((event) => {
268
- const raw = event;
269
- const actorRef = raw["actorRef"];
270
- const rawSessionId = require_event_log.isRecord(actorRef) ? actorRef["sessionId"] : void 0;
271
- if (raw["type"] === "@xstate.actor" && typeof rawSessionId === "string") {
272
- const path = actorPath(actorRef);
273
- const previous = carried.get(path);
274
- if (previous !== void 0 && previous !== rawSessionId) {
275
- carried.delete(path);
276
- aliases.set(rawSessionId, previous);
277
- }
278
- const sessionId = aliases.get(rawSessionId) ?? rawSessionId;
279
- live.set(sessionId, path);
280
- if (announced.has(sessionId)) {
281
- stable(actorRef, true);
282
- return;
283
- }
284
- announced.add(sessionId);
285
- }
286
- if (typeof rawSessionId === "string" && require_event_log.isRecord(raw["snapshot"])) {
287
- const status = raw["snapshot"]["status"];
288
- if (status !== void 0 && status !== "active") {
289
- const sessionId = aliases.get(rawSessionId) ?? rawSessionId;
290
- const path = live.get(sessionId);
291
- live.delete(sessionId);
292
- if (status === "stopped" && path !== void 0) stopped.set(sessionId, path);
293
- }
294
- }
295
- const next = {
296
- ...raw,
297
- actorRef: stable(actorRef, true)
298
- };
299
- if (raw["snapshot"] !== void 0) next["snapshot"] = stableSnapshot(raw["snapshot"]);
300
- if (Array.isArray(raw["sent"])) next["sent"] = raw["sent"].map((sent) => require_event_log.isRecord(sent) && sent["targetRef"] !== void 0 ? {
301
- ...sent,
302
- targetRef: stable(sent["targetRef"])
303
- } : sent);
304
- for (const key of [
305
- "parentRef",
306
- "sourceRef",
307
- "targetRef"
308
- ]) if (raw[key] !== void 0) next[key] = stable(raw[key]);
309
- inspect(next);
310
- });
311
- stableInspect.endPass = (persisted) => {
312
- const kept = persistedChildPaths(persisted);
313
- const root = [...live.values(), ...stopped.values()].find((path) => JSON.parse(path).length === 1);
314
- const rootId = root === void 0 ? void 0 : JSON.parse(root)[0];
315
- const carriedStopped = [...stopped].filter(([, path]) => {
316
- const [id, ...rest] = JSON.parse(path);
317
- return id === rootId && kept.has(JSON.stringify(rest));
318
- });
319
- stopped.clear();
320
- carried = new Map([...live, ...carriedStopped].map(([sessionId, path]) => [path, sessionId]));
321
- };
322
- stableInspections.add(stableInspect);
323
- return stableInspect;
324
- }
325
- //#endregion
326
327
  //#region src/run-agent.ts
327
328
  /**
328
329
  * Thrown by {@link AgentRuntime.start} when a resume is given BOTH an `events` log and a
@@ -1282,26 +1283,6 @@ function bindChildMachineForProvide(childMachine, executors, options, visited) {
1282
1283
  return rebindChildMachine(childMachine, ctxFor(childMachine), visited, ctxFor);
1283
1284
  }
1284
1285
  /**
1285
- * Validates `input` against the machine's registered input schema, returning
1286
- * the schema's output — so defaults are filled and transforms applied before
1287
- * the value reaches `createActor` or the replayable event log.
1288
- *
1289
- * Standard Schema only (no validation library is referenced), so this works for
1290
- * whatever the machine was declared with. Omitted input stays omitted rather
1291
- * than being validated as `{}`: "started with no input" keeps meaning what it
1292
- * has always meant, instead of newly failing schemas with required fields.
1293
- */
1294
- function resolveMachineInput(machine, input) {
1295
- if (input === void 0) return input;
1296
- const schema = require_event_log.getRegisteredAgentExecutionOptions(machine).schemas?.input;
1297
- if (!require_event_log.isStandardSchema(schema)) return input;
1298
- try {
1299
- return require_event_log.validateSchemaSync(schema, input);
1300
- } catch (error) {
1301
- throw new require_event_log.AgentError("invalid-machine-input", `createAgentRuntime: machine input failed validation against the declared input schema: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
1302
- }
1303
- }
1304
- /**
1305
1286
  * Recursively rebinds an invoked child machine's own agent sources with the
1306
1287
  * SAME host-backed wrappers the runtime applies to the top-level machine, so a
1307
1288
  * child's text/stream/decision requests inherit the runtime's executors and
@@ -1569,7 +1550,9 @@ async function waitForIdleAnswer(snapshot, onIdle, inbox, signal, aborted) {
1569
1550
  * ```
1570
1551
  */
1571
1552
  async function runAgent(machine, options = {}) {
1572
- const { onIdle, inbox, ...rest } = options;
1553
+ const { onIdle: idle, inbox, ...rest } = options;
1554
+ if (idle === "inbox" && inbox === void 0) throw new require_event_log.AgentError("inbox-required", "runAgent: `onIdle: \"inbox\"` needs an `inbox`.");
1555
+ const onIdle = idle === "inbox" ? () => new Promise(() => {}) : idle;
1573
1556
  const inboxState = inbox === void 0 ? void 0 : inboxStates.get(inbox);
1574
1557
  if (inbox !== void 0) {
1575
1558
  if (inboxState === void 0 || inboxState.claimed) throw new require_event_log.AgentError("inbox-in-use", "runAgent: `inbox` must come from createAgentInbox() and serves one runAgent call.");
@@ -1909,7 +1892,10 @@ function createAgentRuntime(machine, options = {}) {
1909
1892
  warnedNonSerializable = true;
1910
1893
  console.warn(`createAgentRuntime: context holds value(s) that will not survive snapshot persist/resume (JSON round-trip): ${offending.join(", ")}. Persist only JSON-serializable context, or convert these before the run settles.`);
1911
1894
  };
1912
- const provided = machine.provide({ actors: options.actors });
1895
+ const provided = machine.provide({
1896
+ actors: options.actors,
1897
+ ...options.actions && { actions: options.actions }
1898
+ });
1913
1899
  logMachine = provided;
1914
1900
  const effectiveSources = provided.sources.actors;
1915
1901
  const executors = { ...options.executors };
@@ -1998,6 +1984,7 @@ function createAgentRuntime(machine, options = {}) {
1998
1984
  }
1999
1985
  const boundMachine = provided.provide({ actors: wrappedSources });
2000
1986
  const mailbox = [];
1987
+ const hostQueue = [];
2001
1988
  let wake;
2002
1989
  const fromMailbox = /* @__PURE__ */ new WeakSet();
2003
1990
  let stopReason;
@@ -2011,7 +1998,8 @@ function createAgentRuntime(machine, options = {}) {
2011
1998
  if (waiting) {
2012
1999
  wake = void 0;
2013
2000
  waiting(event);
2014
- } else mailbox.push(event);
2001
+ } else if (fromHost) hostQueue.push(event);
2002
+ else mailbox.push(event);
2015
2003
  };
2016
2004
  const inProcessTimers = options.timers === void 0 || options.timers === "in-process";
2017
2005
  const timerHandles = /* @__PURE__ */ new Map();
@@ -2086,11 +2074,25 @@ function createAgentRuntime(machine, options = {}) {
2086
2074
  let abortTimer;
2087
2075
  const onAbort = () => {
2088
2076
  const abortWith = options.abortWith;
2089
- if (abortWith === void 0 || runtime.send(abortWith.event) === false) {
2077
+ if (abortWith === void 0) {
2078
+ abortNow();
2079
+ return;
2080
+ }
2081
+ let event;
2082
+ try {
2083
+ event = typeof abortWith.event === "function" ? abortWith.event(options.signal?.reason) : abortWith.event;
2084
+ } catch (error) {
2085
+ stopRun({
2086
+ cause: "aborted",
2087
+ error
2088
+ });
2089
+ return;
2090
+ }
2091
+ if (runtime.send(event) === false) {
2090
2092
  abortNow();
2091
2093
  return;
2092
2094
  }
2093
- pendingAbort = abortWith.event;
2095
+ pendingAbort = event;
2094
2096
  if (abortWith.timeout !== void 0) abortTimer = setTimeout(() => {
2095
2097
  if (current?.status === "active") abortNow();
2096
2098
  }, abortWith.timeout);
@@ -2148,7 +2150,7 @@ function createAgentRuntime(machine, options = {}) {
2148
2150
  enqueueRootEvent: (_source, event) => enqueue(event),
2149
2151
  executeAction: (action, _metadata, runtime) => action.exec(runtime),
2150
2152
  waitForEvent: () => {
2151
- const queued = mailbox.shift();
2153
+ const queued = hostQueue.shift() ?? mailbox.shift();
2152
2154
  if (queued !== void 0) return queued;
2153
2155
  if (resultOwed) {
2154
2156
  resultOwed = false;
@@ -2221,7 +2223,7 @@ function createAgentRuntime(machine, options = {}) {
2221
2223
  resumedFromStore = true;
2222
2224
  }
2223
2225
  }
2224
- const resolvedInput = resolveMachineInput(machine, init.input);
2226
+ const resolvedInput = require_machine_input.resolveMachineInput(machine, init.input, "createAgentRuntime");
2225
2227
  const threadInit = resumeEvents?.[0]?.event;
2226
2228
  if (resumedFromStore && init.input !== void 0 && threadInit !== void 0 && Object.hasOwn(threadInit, "input")) {
2227
2229
  if (require_event_log.canonicalJson(threadInit.input) !== require_event_log.canonicalJson(resolvedInput)) throw new require_event_log.AgentError("thread-input-mismatch", `createAgentRuntime: thread '${threadId}' was started with different input. A thread that already has entries is resumed, not restarted; give a new run a new threadId.`);
@@ -2468,7 +2470,7 @@ function createAgentRuntime(machine, options = {}) {
2468
2470
  async nextEvent() {
2469
2471
  for (;;) {
2470
2472
  if (finished || stopReason !== void 0 || current?.status !== "active") return;
2471
- const event = await execution.waitForEvent();
2473
+ const event = hostQueue.shift() ?? await execution.waitForEvent();
2472
2474
  if (event === QUIESCENT || stopReason !== void 0) return;
2473
2475
  if (isStaleChildEvent(event)) continue;
2474
2476
  return event;
@@ -2576,21 +2578,6 @@ function createAgentRuntime(machine, options = {}) {
2576
2578
  return runtime;
2577
2579
  }
2578
2580
  /**
2579
- * Wraps a `(snapshot, actorRef) => void` handler into a function usable as
2580
- * {@link AgentRuntimeOptions.inspect}: it filters the raw inspection stream to
2581
- * `@xstate.transition` events and hands the handler the typed
2582
- * {@link AnyMachineSnapshot} and the {@link InspectedActorRef} that
2583
- * transitioned. Attribute a child actor via `actorRef.id`/`actorRef.src`. Saves
2584
- * the manual `event.type === '@xstate.transition'` filtering and the snapshot/
2585
- * actorRef casts.
2586
- */
2587
- function inspectTransitions(handler) {
2588
- return (inspectionEvent) => {
2589
- if (inspectionEvent.type !== "@xstate.transition") return;
2590
- handler(inspectionEvent.snapshot, inspectionEvent.actorRef);
2591
- };
2592
- }
2593
- /**
2594
2581
  * An xstate `inspect` handler that emits `machine.transition` trace events onto
2595
2582
  * `onTrace`, sharing the SAME versioned envelope and per-root-actor `seq`
2596
2583
  * registry as {@link provideExecutors}' `onTrace`. Pair the two on one actor to
@@ -2649,28 +2636,6 @@ function isAgentIdle(snapshot) {
2649
2636
  }) || require_decision.getAcceptedEvents(snapshot).length > 0;
2650
2637
  }
2651
2638
  //#endregion
2652
- //#region src/internal/effects.ts
2653
- /**
2654
- * A plain copy of an effects object with every callable effect passed
2655
- * through `wrap`: own and inherited methods alike (a class instance's
2656
- * prototype methods), each bound to the original object so `this` still
2657
- * works. Other own properties are copied as they are.
2658
- */
2659
- function mapEffects(effects, wrap) {
2660
- const source = effects;
2661
- const out = {};
2662
- for (let level = effects; level !== null && level !== Object.prototype; level = Object.getPrototypeOf(level)) for (const name of Object.getOwnPropertyNames(level)) {
2663
- if (name === "constructor" || name in out) continue;
2664
- const value = source[name];
2665
- out[name] = typeof value === "function" ? wrap(name, value.bind(effects)) : value;
2666
- }
2667
- return out;
2668
- }
2669
- /** A stream, as recorders and wrapped effects see one: anything `for await` reads. */
2670
- function isAsyncIterable(value) {
2671
- return value !== null && (typeof value === "object" || typeof value === "function") && typeof value[Symbol.asyncIterator] === "function";
2672
- }
2673
- //#endregion
2674
2639
  Object.defineProperty(exports, "AGENT_TRACE_SCHEMA_VERSION", {
2675
2640
  enumerable: true,
2676
2641
  get: function() {
@@ -2737,36 +2702,18 @@ Object.defineProperty(exports, "getConfiguredInvokeSrcs", {
2737
2702
  return getConfiguredInvokeSrcs;
2738
2703
  }
2739
2704
  });
2740
- Object.defineProperty(exports, "inspectTransitions", {
2741
- enumerable: true,
2742
- get: function() {
2743
- return inspectTransitions;
2744
- }
2745
- });
2746
2705
  Object.defineProperty(exports, "isAgentIdle", {
2747
2706
  enumerable: true,
2748
2707
  get: function() {
2749
2708
  return isAgentIdle;
2750
2709
  }
2751
2710
  });
2752
- Object.defineProperty(exports, "isAsyncIterable", {
2753
- enumerable: true,
2754
- get: function() {
2755
- return isAsyncIterable;
2756
- }
2757
- });
2758
2711
  Object.defineProperty(exports, "isStateMachineLogic", {
2759
2712
  enumerable: true,
2760
2713
  get: function() {
2761
2714
  return isStateMachineLogic;
2762
2715
  }
2763
2716
  });
2764
- Object.defineProperty(exports, "mapEffects", {
2765
- enumerable: true,
2766
- get: function() {
2767
- return mapEffects;
2768
- }
2769
- });
2770
2717
  Object.defineProperty(exports, "runAgent", {
2771
2718
  enumerable: true,
2772
2719
  get: function() {