@statelyai/agent 2.0.0-alpha.37 → 2.0.0-alpha.39
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.
- package/CHANGELOG.md +51 -0
- package/dist/{act-CrX0JwWY.cjs → act-B0CVbmo4.cjs} +1 -1
- package/dist/{act-B9hLQls6.mjs → act-Bsz-hUfD.mjs} +1 -1
- package/dist/ai-sdk.cjs +4 -4
- package/dist/ai-sdk.d.cts +2 -3
- package/dist/ai-sdk.d.mts +2 -3
- package/dist/ai-sdk.mjs +4 -4
- package/dist/{decision-m5hGmHpF.mjs → decision-B41YBx5U.mjs} +1 -1
- package/dist/{decision-CMeuNZ1g.cjs → decision-D8bcIGXQ.cjs} +1 -1
- package/dist/{decision-object-DBcLWVvv.d.cts → decision-object-BB8XV5Ec.d.cts} +1 -1
- package/dist/{decision-object-B5zGSPFp.d.mts → decision-object-CH_sE694.d.mts} +1 -1
- package/dist/effects-B9IvUPVh.mjs +23 -0
- package/dist/effects-DrWcUGgc.cjs +34 -0
- package/dist/evals.cjs +810 -0
- package/dist/evals.d.cts +595 -0
- package/dist/evals.d.mts +595 -0
- package/dist/evals.mjs +801 -0
- package/dist/{event-log-DkVlk3Rh.mjs → event-log-CEq_bVXQ.mjs} +8 -4
- package/dist/{event-log-Dkc-yIYu.cjs → event-log-dSOnXHuG.cjs} +7 -15
- package/dist/{event-log-store-Brx9tOHt.mjs → event-log-store-DLAfNM34.mjs} +1 -1
- package/dist/{event-log-store-BBS8so8a.d.mts → event-log-store-DYun526m.d.mts} +15 -14
- package/dist/{event-log-store-Cl-YWDnq.cjs → event-log-store-Dey9ufA4.cjs} +1 -1
- package/dist/{event-log-store-bc4ICGcS.d.cts → event-log-store-aFXK6yZX.d.cts} +15 -14
- package/dist/index.cjs +136 -98
- package/dist/index.d.cts +73 -134
- package/dist/index.d.mts +73 -134
- package/dist/index.mjs +117 -75
- package/dist/internal-BzlpzSux.d.cts +14 -0
- package/dist/internal-BzlpzSux.d.mts +14 -0
- package/dist/log.cjs +2 -3
- package/dist/log.d.cts +2 -2
- package/dist/log.d.mts +2 -2
- package/dist/log.mjs +3 -3
- package/dist/machines.cjs +1 -719
- package/dist/machines.d.cts +2 -424
- package/dist/machines.d.mts +2 -424
- package/dist/machines.mjs +2 -709
- package/dist/{model-source-kjGwqAV8.mjs → model-source-BrsLDvHL.mjs} +1 -1
- package/dist/{model-source-B4WQ8Idp.cjs → model-source-YpxjmWuX.cjs} +1 -1
- package/dist/openai.cjs +3 -3
- package/dist/openai.d.cts +2 -3
- package/dist/openai.d.mts +2 -3
- package/dist/openai.mjs +3 -3
- package/dist/otel.d.cts +1 -1
- package/dist/otel.d.mts +1 -1
- package/dist/policy.cjs +77 -0
- package/dist/policy.d.cts +143 -0
- package/dist/policy.d.mts +143 -0
- package/dist/policy.mjs +75 -0
- package/dist/{effects-BT_cSY0j.mjs → run-agent-BE7DOWD6.mjs} +150 -184
- package/dist/{run-agent-DlPzBWj-.d.mts → run-agent-DHlq87G7.d.mts} +18 -34
- package/dist/{effects-DDseYtJk.cjs → run-agent-De3xVFGw.cjs} +149 -201
- package/dist/{run-agent-30mH2moE.d.cts → run-agent-Dq0oSFRm.d.cts} +18 -34
- package/dist/{setup-agent-BDmNr6PC.mjs → setup-agent-CLm6QVGy.mjs} +3 -3
- package/dist/{setup-agent-BaNyz6Q3.d.cts → setup-agent-Cv8Hk3mX.d.cts} +12 -11
- package/dist/{setup-agent-C1CG_nfX.d.mts → setup-agent-DgFAhaPJ.d.mts} +12 -11
- package/dist/{setup-agent-CmEToB8y.cjs → setup-agent-Dv5VpuHe.cjs} +3 -3
- package/dist/tanstack-ai.cjs +4 -4
- package/dist/tanstack-ai.d.cts +2 -3
- package/dist/tanstack-ai.d.mts +2 -3
- package/dist/tanstack-ai.mjs +4 -4
- package/dist/testing.cjs +122 -996
- package/dist/testing.d.cts +36 -695
- package/dist/testing.d.mts +36 -695
- package/dist/testing.mjs +112 -977
- package/dist/{text-logic-BqxalgMr.d.mts → text-logic-x17uLBwA.d.cts} +238 -2
- package/dist/{text-logic-CSf9bqpP.d.cts → text-logic-x17uLBwA.d.mts} +238 -2
- package/dist/trajectory-BFjXaooB.d.cts +96 -0
- package/dist/trajectory-BFjXaooB.d.mts +96 -0
- package/dist/trajectory-BUXj_1Ue.mjs +152 -0
- package/dist/trajectory-CoZSv4wF.cjs +157 -0
- package/dist/{usage-Bm5nvpow.d.cts → usage-B4B-TQSV.d.mts} +1 -1
- package/dist/{usage-BnikdOca.d.mts → usage-DvGcoK6x.d.cts} +1 -1
- package/dist/{utils-7lSa4H-i.d.cts → utils-B8k-YPYI.d.mts} +23 -17
- package/dist/{utils-CBbKw2fM.d.mts → utils-DAclF-kw.d.cts} +23 -17
- package/dist/validate.cjs +4 -4
- package/dist/validate.d.cts +2 -2
- package/dist/validate.d.mts +2 -2
- package/dist/validate.mjs +4 -4
- package/dist/{verify-DJHfEfm6.d.cts → verify-BM0sGmsf.d.cts} +42 -6
- package/dist/{verify-ChyX6jq0.mjs → verify-CWlg3j7B.mjs} +153 -45
- package/dist/{verify-CwlombbC.cjs → verify-Dek6gHCS.cjs} +153 -45
- package/dist/{verify-i9Hiwc5g.d.mts → verify-H3Pr2gNw.d.mts} +42 -6
- package/dist/{with-model-calls-B_WLmOSl.cjs → with-model-calls-D50Ca6qW.cjs} +2 -2
- package/dist/{with-model-calls-BkOwdroS.mjs → with-model-calls-uY-KKliA.mjs} +2 -2
- package/docs/advanced.md +5 -5
- package/docs/choosing-a-run-mode.md +7 -7
- package/docs/debugging.md +6 -8
- package/docs/decisions.md +6 -5
- package/docs/environment-and-policy.md +1 -1
- package/docs/evals.md +57 -43
- package/docs/event-log.md +14 -16
- package/docs/from-a-loop.md +3 -3
- package/docs/generate-machines.md +4 -4
- package/docs/hosts.md +22 -29
- package/docs/human-in-the-loop.md +5 -8
- package/docs/index.md +4 -4
- package/docs/judgments.md +5 -7
- package/docs/langgraph-comparison.md +6 -6
- package/docs/machines-as-data.md +12 -17
- package/docs/machines-presets.md +17 -120
- package/docs/machines.md +13 -13
- package/docs/models-and-providers.md +19 -25
- package/docs/multi-agent.md +1 -1
- package/docs/observability.md +6 -8
- package/docs/persistence.md +15 -25
- package/docs/quickstart.md +4 -4
- package/docs/statechart-policy-examples.md +1 -1
- package/docs/steps.md +5 -6
- package/docs/strangler-fig.md +72 -7
- package/docs/text-requests.md +10 -12
- package/docs/thinking-in-state-machines.md +8 -8
- package/docs/tools.md +10 -12
- package/docs/upgrading.md +1 -1
- package/docs/usage-and-budgets.md +51 -56
- package/docs/validate-and-repair.md +9 -14
- package/docs/verify.md +53 -7
- package/docs/xstate-4-and-5-apps.md +19 -28
- package/llms.txt +1 -1
- package/package.json +31 -6
- package/readme.md +32 -24
- package/dist/internal-C3Lqu538.d.cts +0 -43
- package/dist/internal-DUcdhk-i.d.mts +0 -43
- package/dist/types-DQUOOaZO.d.cts +0 -238
- package/dist/types-DQUOOaZO.d.mts +0 -238
- package/skills/add-evals/SKILL.md +0 -152
- package/skills/add-traces/SKILL.md +0 -152
- package/skills/build-machine/SKILL.md +0 -84
- package/skills/generate-machine/SKILL.md +0 -335
- package/skills/graph-engineering/SKILL.md +0 -43
- package/skills/improve-machine/SKILL.md +0 -261
- package/skills/improve-machine/reference.md +0 -101
- package/skills/loop-to-machine/SKILL.md +0 -205
- package/skills/loop-to-machine/policy.md +0 -154
- package/skills/loop-to-machine/reference.md +0 -260
|
@@ -1,9 +1,150 @@
|
|
|
1
|
-
const require_event_log = require("./event-log-
|
|
2
|
-
const require_decision = require("./decision-
|
|
3
|
-
const require_act = require("./act-
|
|
4
|
-
const require_event_log_store = require("./event-log-store-
|
|
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
5
|
let xstate = require("xstate");
|
|
6
6
|
let xstate_durable = require("xstate/durable");
|
|
7
|
+
//#region src/internal/stable-inspection.ts
|
|
8
|
+
const stableInspections = /* @__PURE__ */ new WeakSet();
|
|
9
|
+
/** Whether `inspect` already came from {@link stableInspection}. */
|
|
10
|
+
function isStableInspection(inspect) {
|
|
11
|
+
return typeof inspect === "function" && stableInspections.has(inspect);
|
|
12
|
+
}
|
|
13
|
+
function actorPath(ref) {
|
|
14
|
+
const ids = [];
|
|
15
|
+
let current = ref;
|
|
16
|
+
while (require_event_log.isRecord(current)) {
|
|
17
|
+
ids.unshift(current["id"]);
|
|
18
|
+
current = current["_parent"];
|
|
19
|
+
}
|
|
20
|
+
return JSON.stringify(ids);
|
|
21
|
+
}
|
|
22
|
+
function persistedChildPaths(persisted, prefix = [], paths = /* @__PURE__ */ new Set()) {
|
|
23
|
+
const children = require_event_log.isRecord(persisted) ? persisted["children"] : void 0;
|
|
24
|
+
if (!require_event_log.isRecord(children)) return paths;
|
|
25
|
+
for (const [id, child] of Object.entries(children)) {
|
|
26
|
+
const path = [...prefix, id];
|
|
27
|
+
paths.add(JSON.stringify(path));
|
|
28
|
+
persistedChildPaths(require_event_log.isRecord(child) ? child["snapshot"] : void 0, path, paths);
|
|
29
|
+
}
|
|
30
|
+
return paths;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Makes a durable run's inspection stream look like one live actor system to
|
|
34
|
+
* an inspector. The durable runtime re-creates an actor object for each step
|
|
35
|
+
* under the same `sessionId` and announces it again, so an inspector that
|
|
36
|
+
* tracks actors by object (`@statelyai/sdk`) sees a duplicate and drops the
|
|
37
|
+
* rest of the run. Each `sessionId` gets one stable handle that reads from the
|
|
38
|
+
* newest actor object, and is announced once. Across runtimes (`runAgent`'s
|
|
39
|
+
* `onIdle` passes), {@link StableInspection.endPass} carries live actors over.
|
|
40
|
+
*/
|
|
41
|
+
function stableInspection(inspect) {
|
|
42
|
+
const handles = /* @__PURE__ */ new Map();
|
|
43
|
+
const announced = /* @__PURE__ */ new Set();
|
|
44
|
+
const snapshots = /* @__PURE__ */ new WeakMap();
|
|
45
|
+
const aliases = /* @__PURE__ */ new Map();
|
|
46
|
+
const live = /* @__PURE__ */ new Map();
|
|
47
|
+
const stopped = /* @__PURE__ */ new Map();
|
|
48
|
+
let carried = /* @__PURE__ */ new Map();
|
|
49
|
+
const stableSnapshot = (snapshot) => {
|
|
50
|
+
if (!require_event_log.isRecord(snapshot) || !require_event_log.isRecord(snapshot["children"])) return snapshot;
|
|
51
|
+
const cached = snapshots.get(snapshot);
|
|
52
|
+
if (cached) return cached;
|
|
53
|
+
const copy = Object.create(Object.getPrototypeOf(snapshot), Object.getOwnPropertyDescriptors(snapshot));
|
|
54
|
+
copy["children"] = Object.fromEntries(Object.entries(snapshot["children"]).map(([id, child]) => [id, stable(child)]));
|
|
55
|
+
snapshots.set(snapshot, copy);
|
|
56
|
+
return copy;
|
|
57
|
+
};
|
|
58
|
+
const stable = (ref, adopt = false) => {
|
|
59
|
+
if (!require_event_log.isRecord(ref) || typeof ref["sessionId"] !== "string") return ref;
|
|
60
|
+
const sessionId = aliases.get(ref["sessionId"]) ?? ref["sessionId"];
|
|
61
|
+
const known = handles.get(sessionId);
|
|
62
|
+
if (known) {
|
|
63
|
+
if (adopt) known.latest = ref;
|
|
64
|
+
return known.handle;
|
|
65
|
+
}
|
|
66
|
+
const entry = {
|
|
67
|
+
latest: ref,
|
|
68
|
+
handle: ref
|
|
69
|
+
};
|
|
70
|
+
entry.handle = new Proxy(ref, {
|
|
71
|
+
get(_target, key) {
|
|
72
|
+
const value = Reflect.get(entry.latest, key, entry.latest);
|
|
73
|
+
if (key === "_parent") return stable(value);
|
|
74
|
+
if (key === "ref") return entry.handle;
|
|
75
|
+
if (key === "sessionId") return sessionId;
|
|
76
|
+
if (key === "getSnapshot") return () => stableSnapshot(entry.latest.getSnapshot());
|
|
77
|
+
if (key === "_snapshot") return stableSnapshot(value);
|
|
78
|
+
if (key === "options" && require_event_log.isRecord(value) && value["parent"] !== void 0) return {
|
|
79
|
+
...value,
|
|
80
|
+
parent: stable(value["parent"])
|
|
81
|
+
};
|
|
82
|
+
return typeof value === "function" ? value.bind(entry.latest) : value;
|
|
83
|
+
},
|
|
84
|
+
has: (_target, key) => key in entry.latest
|
|
85
|
+
});
|
|
86
|
+
handles.set(sessionId, entry);
|
|
87
|
+
return entry.handle;
|
|
88
|
+
};
|
|
89
|
+
const stableInspect = ((event) => {
|
|
90
|
+
const raw = event;
|
|
91
|
+
const actorRef = raw["actorRef"];
|
|
92
|
+
const rawSessionId = require_event_log.isRecord(actorRef) ? actorRef["sessionId"] : void 0;
|
|
93
|
+
if (raw["type"] === "@xstate.actor" && typeof rawSessionId === "string") {
|
|
94
|
+
const path = actorPath(actorRef);
|
|
95
|
+
const previous = carried.get(path);
|
|
96
|
+
if (previous !== void 0 && previous !== rawSessionId) {
|
|
97
|
+
carried.delete(path);
|
|
98
|
+
aliases.set(rawSessionId, previous);
|
|
99
|
+
}
|
|
100
|
+
const sessionId = aliases.get(rawSessionId) ?? rawSessionId;
|
|
101
|
+
live.set(sessionId, path);
|
|
102
|
+
if (announced.has(sessionId)) {
|
|
103
|
+
stable(actorRef, true);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
announced.add(sessionId);
|
|
107
|
+
}
|
|
108
|
+
if (typeof rawSessionId === "string" && require_event_log.isRecord(raw["snapshot"])) {
|
|
109
|
+
const status = raw["snapshot"]["status"];
|
|
110
|
+
if (status !== void 0 && status !== "active") {
|
|
111
|
+
const sessionId = aliases.get(rawSessionId) ?? rawSessionId;
|
|
112
|
+
const path = live.get(sessionId);
|
|
113
|
+
live.delete(sessionId);
|
|
114
|
+
if (status === "stopped" && path !== void 0) stopped.set(sessionId, path);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const next = {
|
|
118
|
+
...raw,
|
|
119
|
+
actorRef: stable(actorRef, true)
|
|
120
|
+
};
|
|
121
|
+
if (raw["snapshot"] !== void 0) next["snapshot"] = stableSnapshot(raw["snapshot"]);
|
|
122
|
+
if (Array.isArray(raw["sent"])) next["sent"] = raw["sent"].map((sent) => require_event_log.isRecord(sent) && sent["targetRef"] !== void 0 ? {
|
|
123
|
+
...sent,
|
|
124
|
+
targetRef: stable(sent["targetRef"])
|
|
125
|
+
} : sent);
|
|
126
|
+
for (const key of [
|
|
127
|
+
"parentRef",
|
|
128
|
+
"sourceRef",
|
|
129
|
+
"targetRef"
|
|
130
|
+
]) if (raw[key] !== void 0) next[key] = stable(raw[key]);
|
|
131
|
+
inspect(next);
|
|
132
|
+
});
|
|
133
|
+
stableInspect.endPass = (persisted) => {
|
|
134
|
+
const kept = persistedChildPaths(persisted);
|
|
135
|
+
const root = [...live.values(), ...stopped.values()].find((path) => JSON.parse(path).length === 1);
|
|
136
|
+
const rootId = root === void 0 ? void 0 : JSON.parse(root)[0];
|
|
137
|
+
const carriedStopped = [...stopped].filter(([, path]) => {
|
|
138
|
+
const [id, ...rest] = JSON.parse(path);
|
|
139
|
+
return id === rootId && kept.has(JSON.stringify(rest));
|
|
140
|
+
});
|
|
141
|
+
stopped.clear();
|
|
142
|
+
carried = new Map([...live, ...carriedStopped].map(([sessionId, path]) => [path, sessionId]));
|
|
143
|
+
};
|
|
144
|
+
stableInspections.add(stableInspect);
|
|
145
|
+
return stableInspect;
|
|
146
|
+
}
|
|
147
|
+
//#endregion
|
|
7
148
|
//#region src/decide-next.ts
|
|
8
149
|
/**
|
|
9
150
|
* Asks a model to choose the next event for ANY XState snapshot, including a
|
|
@@ -182,147 +323,6 @@ function short(value, max = 60) {
|
|
|
182
323
|
return text.length > max ? `${text.slice(0, max - 1)}…` : text;
|
|
183
324
|
}
|
|
184
325
|
//#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
326
|
//#region src/run-agent.ts
|
|
327
327
|
/**
|
|
328
328
|
* Thrown by {@link AgentRuntime.start} when a resume is given BOTH an `events` log and a
|
|
@@ -1909,7 +1909,10 @@ function createAgentRuntime(machine, options = {}) {
|
|
|
1909
1909
|
warnedNonSerializable = true;
|
|
1910
1910
|
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
1911
|
};
|
|
1912
|
-
const provided = machine.provide({
|
|
1912
|
+
const provided = machine.provide({
|
|
1913
|
+
actors: options.actors,
|
|
1914
|
+
...options.actions && { actions: options.actions }
|
|
1915
|
+
});
|
|
1913
1916
|
logMachine = provided;
|
|
1914
1917
|
const effectiveSources = provided.sources.actors;
|
|
1915
1918
|
const executors = { ...options.executors };
|
|
@@ -2576,21 +2579,6 @@ function createAgentRuntime(machine, options = {}) {
|
|
|
2576
2579
|
return runtime;
|
|
2577
2580
|
}
|
|
2578
2581
|
/**
|
|
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
2582
|
* An xstate `inspect` handler that emits `machine.transition` trace events onto
|
|
2595
2583
|
* `onTrace`, sharing the SAME versioned envelope and per-root-actor `seq`
|
|
2596
2584
|
* registry as {@link provideExecutors}' `onTrace`. Pair the two on one actor to
|
|
@@ -2649,28 +2637,6 @@ function isAgentIdle(snapshot) {
|
|
|
2649
2637
|
}) || require_decision.getAcceptedEvents(snapshot).length > 0;
|
|
2650
2638
|
}
|
|
2651
2639
|
//#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
2640
|
Object.defineProperty(exports, "AGENT_TRACE_SCHEMA_VERSION", {
|
|
2675
2641
|
enumerable: true,
|
|
2676
2642
|
get: function() {
|
|
@@ -2737,36 +2703,18 @@ Object.defineProperty(exports, "getConfiguredInvokeSrcs", {
|
|
|
2737
2703
|
return getConfiguredInvokeSrcs;
|
|
2738
2704
|
}
|
|
2739
2705
|
});
|
|
2740
|
-
Object.defineProperty(exports, "inspectTransitions", {
|
|
2741
|
-
enumerable: true,
|
|
2742
|
-
get: function() {
|
|
2743
|
-
return inspectTransitions;
|
|
2744
|
-
}
|
|
2745
|
-
});
|
|
2746
2706
|
Object.defineProperty(exports, "isAgentIdle", {
|
|
2747
2707
|
enumerable: true,
|
|
2748
2708
|
get: function() {
|
|
2749
2709
|
return isAgentIdle;
|
|
2750
2710
|
}
|
|
2751
2711
|
});
|
|
2752
|
-
Object.defineProperty(exports, "isAsyncIterable", {
|
|
2753
|
-
enumerable: true,
|
|
2754
|
-
get: function() {
|
|
2755
|
-
return isAsyncIterable;
|
|
2756
|
-
}
|
|
2757
|
-
});
|
|
2758
2712
|
Object.defineProperty(exports, "isStateMachineLogic", {
|
|
2759
2713
|
enumerable: true,
|
|
2760
2714
|
get: function() {
|
|
2761
2715
|
return isStateMachineLogic;
|
|
2762
2716
|
}
|
|
2763
2717
|
});
|
|
2764
|
-
Object.defineProperty(exports, "mapEffects", {
|
|
2765
|
-
enumerable: true,
|
|
2766
|
-
get: function() {
|
|
2767
|
-
return mapEffects;
|
|
2768
|
-
}
|
|
2769
|
-
});
|
|
2770
2718
|
Object.defineProperty(exports, "runAgent", {
|
|
2771
2719
|
enumerable: true,
|
|
2772
2720
|
get: function() {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { n as
|
|
4
|
-
import {
|
|
5
|
-
import { AnyActorLogic, AnyActorRef, AnyMachineSnapshot, AnyStateMachine, AsyncActorLogic, EmittedFrom, EventFromLogic, EventObject, InputFrom, InspectionEvent, OutputFrom, Snapshot, SnapshotFrom, StateValue } from "xstate";
|
|
1
|
+
import { B as DecisionAttempt, L as AgentDecisionRequest, Lt as WithAgentInputSchema, Tt as InferInput, Z as AgentEventDescriptor, at as AgentError, d as AgentRequestMode, et as AgentRequestSource, f as AgentTextRequest, ht as AgentTools, kt as StandardSchemaV1, m as AgentUsage, r as AgentFinishReason, t as AgentCallUsage, u as AgentRequestExecutors } from "./text-logic-x17uLBwA.cjs";
|
|
2
|
+
import { n as AgentUsageEvent } from "./usage-DvGcoK6x.cjs";
|
|
3
|
+
import { c as AgentLogEntry, h as JsonValue$1, n as AgentEventLogStore } from "./event-log-store-aFXK6yZX.cjs";
|
|
4
|
+
import { AnyActorLogic, AnyMachineSnapshot, AnyStateMachine, AsyncActorLogic, EmittedFrom, EventFromLogic, EventObject, InputFrom, InspectionEvent, OutputFrom, Snapshot, SnapshotFrom, StateValue } from "xstate";
|
|
6
5
|
import { DurableExecution } from "xstate/durable";
|
|
7
6
|
//#region src/steps.d.ts
|
|
8
7
|
/**
|
|
@@ -208,6 +207,8 @@ declare const TRACE_ENVELOPE_KEYS: readonly ["schemaVersion", "runId", "seq", "t
|
|
|
208
207
|
declare function serializeTraceEvent(event: AgentTraceEvent, options?: {
|
|
209
208
|
includeRaw?: boolean;
|
|
210
209
|
}): JsonSerializableTraceEvent;
|
|
210
|
+
/** The action implementations `machine.provide` accepts for `TMachine`. */
|
|
211
|
+
type ProvidedActions<TMachine extends AnyStateMachine> = NonNullable<Parameters<TMachine["provide"]>[0]["actions"]>;
|
|
211
212
|
/**
|
|
212
213
|
* Options for {@link createAgentRuntime}: what the runtime binds and observes.
|
|
213
214
|
* The run's `input`/`snapshot`/`events` go to {@link AgentRuntime.start} (or
|
|
@@ -272,6 +273,13 @@ interface AgentRuntimeOptions<TMachine extends AnyStateMachine> {
|
|
|
272
273
|
metadata?: Record<string, JsonValue$1>;
|
|
273
274
|
/** Actor source implementations, merged onto the machine before binding — sugar for `machine.provide({ actors })` ahead of the run. */
|
|
274
275
|
actors?: Record<string, AnyActorLogic>;
|
|
276
|
+
/**
|
|
277
|
+
* Action implementations for this run, merged onto the machine before
|
|
278
|
+
* binding: sugar for `machine.provide({ actions })`. Each key must be an
|
|
279
|
+
* action declared in `setupAgent`, with the same params. Build them per run
|
|
280
|
+
* to close over live objects (a store, a session) that cannot go in context.
|
|
281
|
+
*/
|
|
282
|
+
actions?: ProvidedActions<TMachine>;
|
|
275
283
|
/**
|
|
276
284
|
* Sugar over {@link onTrace}'s `stream.chunk` events: fires for each streamed
|
|
277
285
|
* chunk of a `mode: 'stream'` text request, alongside the {@link AgentRequest}
|
|
@@ -655,13 +663,6 @@ interface AgentRunInit<TMachine extends AnyStateMachine> extends AgentRunStart<T
|
|
|
655
663
|
*/
|
|
656
664
|
attempts?: DecisionAttempt[];
|
|
657
665
|
}
|
|
658
|
-
/**
|
|
659
|
-
* The blocking host: opens the run, delivers `event` if given, then applies
|
|
660
|
-
* every event that arrives until the run is quiescent, and returns the
|
|
661
|
-
* outcome. A request handler or durable engine writes the same loop with its
|
|
662
|
-
* own stop policy; this one is for scripts and tests.
|
|
663
|
-
*/
|
|
664
|
-
declare function runToQuiescence<TMachine extends AnyStateMachine>(runtime: AgentRuntime<TMachine>, init?: AgentRunInit<TMachine>): Promise<AgentRunResult<TMachine>>;
|
|
665
666
|
/** Everything {@link runAgent} takes: the runtime's options plus how to open the run. */
|
|
666
667
|
interface AgentRunOptions<TMachine extends AnyStateMachine> extends AgentRuntimeOptions<TMachine>, AgentRunInit<TMachine> {
|
|
667
668
|
/**
|
|
@@ -691,7 +692,10 @@ interface AgentRunOptions<TMachine extends AnyStateMachine> extends AgentRuntime
|
|
|
691
692
|
* {@link AgentRuntime.send}; one sent before the run starts is delivered
|
|
692
693
|
* after the opening `event`. An inbox event that arrives while the run is
|
|
693
694
|
* idle resumes it, ahead of a pending `onIdle` answer (that answer is then
|
|
694
|
-
* dropped).
|
|
695
|
+
* dropped). Without `onIdle`, the run returns at the first idle state
|
|
696
|
+
* (an event that lands while that pass is finishing still resumes it), and
|
|
697
|
+
* a `send` after `runAgent` returns gets `false`: a pause that waits for a
|
|
698
|
+
* resume needs `onIdle` as well. One inbox serves one `runAgent` call.
|
|
695
699
|
*/
|
|
696
700
|
inbox?: AgentInbox<EventFromLogic<TMachine>>;
|
|
697
701
|
}
|
|
@@ -779,26 +783,6 @@ declare function runAgent<TMachine extends AnyStateMachine>(machine: TMachine, o
|
|
|
779
783
|
* `createOpenAiExecutors` from '@statelyai/agent/openai' supply all three.
|
|
780
784
|
*/
|
|
781
785
|
declare function createAgentRuntime<TMachine extends AnyStateMachine>(machine: TMachine, options?: AgentRuntimeOptions<TMachine>): AgentRuntime<TMachine>;
|
|
782
|
-
/**
|
|
783
|
-
* The actor handed to an {@link inspectTransitions} handler: an
|
|
784
|
-
* {@link AnyActorRef} widened with the runtime `id`/`src` used to attribute a
|
|
785
|
-
* transition to the root machine or a specific invoked child (xstate's static
|
|
786
|
-
* `ActorRef` type omits them, but they are always present at runtime).
|
|
787
|
-
*/
|
|
788
|
-
type InspectedActorRef = AnyActorRef & {
|
|
789
|
-
id: string;
|
|
790
|
-
src?: string | AnyActorLogic;
|
|
791
|
-
};
|
|
792
|
-
/**
|
|
793
|
-
* Wraps a `(snapshot, actorRef) => void` handler into a function usable as
|
|
794
|
-
* {@link AgentRuntimeOptions.inspect}: it filters the raw inspection stream to
|
|
795
|
-
* `@xstate.transition` events and hands the handler the typed
|
|
796
|
-
* {@link AnyMachineSnapshot} and the {@link InspectedActorRef} that
|
|
797
|
-
* transitioned. Attribute a child actor via `actorRef.id`/`actorRef.src`. Saves
|
|
798
|
-
* the manual `event.type === '@xstate.transition'` filtering and the snapshot/
|
|
799
|
-
* actorRef casts.
|
|
800
|
-
*/
|
|
801
|
-
declare function inspectTransitions(handler: (snapshot: AnyMachineSnapshot, actorRef: InspectedActorRef) => void): (inspectionEvent: InspectionEvent) => void;
|
|
802
786
|
/**
|
|
803
787
|
* An xstate `inspect` handler that emits `machine.transition` trace events onto
|
|
804
788
|
* `onTrace`, sharing the SAME versioned envelope and per-root-actor `seq`
|
|
@@ -835,4 +819,4 @@ declare function traceTransitions<TMachine extends AnyStateMachine = AnyStateMac
|
|
|
835
819
|
*/
|
|
836
820
|
declare function isAgentIdle(snapshot: AnyMachineSnapshot): boolean;
|
|
837
821
|
//#endregion
|
|
838
|
-
export {
|
|
822
|
+
export { runAgent as C, AgentStepRequest as D, AgentRequest as E, isAgentIdle as S, traceTransitions as T, AgentTraceEvent as _, AgentMaxModelCallsExceededError as a, createAgentInbox as b, AgentRunMeta as c, AgentRunStart as d, AgentRuntime as f, AgentTimerScheduler as g, AgentTimerEvent as h, AgentInputFrom as i, AgentRunOptions as l, AgentSnapshotDivergedError as m, AgentEffects as n, AgentRunErrorCause as o, AgentRuntimeOptions as p, AgentInbox as r, AgentRunInit as s, AGENT_TRACE_SCHEMA_VERSION as t, AgentRunResult as u, AgentTransitionHandler as v, serializeTraceEvent as w, createAgentRuntime as x, JsonSerializableTraceEvent as y };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { r as createDecideActor } from "./decision-
|
|
3
|
-
import { r as createActActor } from "./act-
|
|
1
|
+
import { C as AGENT_USAGE_EVENT_TYPE, D as DECIDE_ACTOR, G as getAgentExecutionOptions, J as missingActor, M as createTextLogic, T as ACT_ACTOR, Y as setAgentExecutionOptions, ct as validateSchemaSync, dt as isPlainObject, j as builtinTextActors, pt as AgentError } from "./event-log-CEq_bVXQ.mjs";
|
|
2
|
+
import { r as createDecideActor } from "./decision-B41YBx5U.mjs";
|
|
3
|
+
import { r as createActActor } from "./act-Bsz-hUfD.mjs";
|
|
4
4
|
import { machineFromJSON, setup } from "xstate";
|
|
5
5
|
//#region src/workflow-config.ts
|
|
6
6
|
/**
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { n as AgentUsageEvent, t as AGENT_USAGE_EVENT_TYPE } from "./usage-Bm5nvpow.cjs";
|
|
1
|
+
import { Dt as NormalizedEventSchemas, Et as InferOutput, Lt as WithAgentInputSchema, St as EventUnion, Tt as InferInput, _ as TextLogic, a as AgentModelRef, ct as AgentEventSchemaInputMap, d as AgentRequestMode, dt as AgentToolChoice, h as BuiltinAgentActors, ht as AgentTools, i as AgentModelMap, kt as StandardSchemaV1, nt as EventFromSnapshot, tt as AgentSchemas, v as TextLogicConfig } from "./text-logic-x17uLBwA.cjs";
|
|
2
|
+
import { n as AgentUsageEvent, t as AGENT_USAGE_EVENT_TYPE } from "./usage-DvGcoK6x.cjs";
|
|
4
3
|
import { AnyActorLogic, AnyMachineSnapshot, AnySetupConfig, AnyStateMachine, AsyncActorLogic, EventObject, MachineContext, MetaObject, NonReducibleUnknown, SetupReturnFromConfig, SetupStateSchema } from "xstate";
|
|
5
4
|
//#region src/interaction.d.ts
|
|
6
5
|
interface AgentInteractionEvent<TType extends string = string> {
|
|
@@ -441,7 +440,9 @@ type AgentSetupEmittedSchema<TEmittedSchemas extends Record<string, StandardSche
|
|
|
441
440
|
* and intersecting a brand into that collapses members to `never`.
|
|
442
441
|
*/
|
|
443
442
|
type BrandedInputSchema<TInputSchema extends StandardSchemaV1> = InferOutput<TInputSchema> extends Record<string, unknown> ? StandardSchemaV1<InferInput<TInputSchema>, InferOutput<TInputSchema> & WithAgentInputSchema<TInputSchema>> : TInputSchema;
|
|
444
|
-
|
|
443
|
+
/** Action sources for `setupAgent({ actions })`. */
|
|
444
|
+
type AgentActionSources = NonNullable<AnySetupConfig["actions"]>;
|
|
445
|
+
type AgentSetupXStateConfig<TContextSchema extends StandardSchemaV1<Record<string, unknown>>, TEventSchemas extends AgentEventSchemaInputMap, TActors extends { [K in keyof TActors]: AnyActorLogic; }, TRequestSchemas extends AgentRequestSchemaMap, TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TModels extends AgentModelMap, TEmittedSchemas extends Record<string, StandardSchemaV1> = {}, TStateSchemas extends Record<string, SetupStateSchema> = Record<string, SetupStateSchema>, TActions extends AgentActionSources = AgentActionSources> = {
|
|
445
446
|
schemas: {
|
|
446
447
|
context: TContextSchema;
|
|
447
448
|
input: BrandedInputSchema<TInputSchema>;
|
|
@@ -450,11 +451,11 @@ type AgentSetupXStateConfig<TContextSchema extends StandardSchemaV1<Record<strin
|
|
|
450
451
|
} & AgentSetupEventsSchema<TEventSchemas> & AgentSetupEmittedSchema<TEmittedSchemas>;
|
|
451
452
|
states?: TStateSchemas;
|
|
452
453
|
actors: SetupActors<AgentSetupActors<AgentAllActors<TActors, TRequestSchemas>, Exclude<keyof TEventSchemas & string, typeof AGENT_USAGE_EVENT_TYPE>, AgentModelRef<TModels>>>;
|
|
453
|
-
actions?:
|
|
454
|
+
actions?: TActions;
|
|
454
455
|
guards?: NonNullable<AnySetupConfig["guards"]>;
|
|
455
456
|
delays?: NonNullable<AnySetupConfig["delays"]>;
|
|
456
457
|
};
|
|
457
|
-
type SetupAgentBaseConfig<TContextSchema extends StandardSchemaV1<Record<string, unknown>>, TEventSchemas extends AgentEventSchemaInputMap, TActors extends { [K in keyof TActors]: AnyActorLogic; }, TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TRequestSchemas extends AgentRequestSchemaMap, TModels extends AgentModelMap, TEmittedSchemas extends Record<string, StandardSchemaV1> = {}, TStateSchemas extends Record<string, SetupStateSchema> = Record<string, SetupStateSchema
|
|
458
|
+
type SetupAgentBaseConfig<TContextSchema extends StandardSchemaV1<Record<string, unknown>>, TEventSchemas extends AgentEventSchemaInputMap, TActors extends { [K in keyof TActors]: AnyActorLogic; }, TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TRequestSchemas extends AgentRequestSchemaMap, TModels extends AgentModelMap, TEmittedSchemas extends Record<string, StandardSchemaV1> = {}, TStateSchemas extends Record<string, SetupStateSchema> = Record<string, SetupStateSchema>, TActions extends AgentActionSources = AgentActionSources> = ({
|
|
458
459
|
schemas: AgentSchemaPack<TContextSchema, TEventSchemas, TInputSchema, TOutputSchema, TMetaSchema, TEmittedSchemas>;
|
|
459
460
|
} | AgentSchemaConfig<TContextSchema, TEventSchemas, TInputSchema, TOutputSchema, TMetaSchema, TEmittedSchemas>) & {
|
|
460
461
|
models?: TModels;
|
|
@@ -468,11 +469,11 @@ type SetupAgentBaseConfig<TContextSchema extends StandardSchemaV1<Record<string,
|
|
|
468
469
|
*/
|
|
469
470
|
states?: TStateSchemas;
|
|
470
471
|
requests?: AgentRequestInput<TRequestSchemas, AgentModelRef<TModels>>;
|
|
471
|
-
actions?:
|
|
472
|
+
actions?: TActions;
|
|
472
473
|
guards?: AgentGuardSources<TContextSchema, TEventSchemas>;
|
|
473
474
|
delays?: AgentDelaySources<TContextSchema, TEventSchemas>;
|
|
474
475
|
};
|
|
475
|
-
type SetupAgentXStateResult<TContextSchema extends StandardSchemaV1<Record<string, unknown>>, TEventSchemas extends AgentEventSchemaInputMap, TActors extends { [K in keyof TActors]: AnyActorLogic; }, TRequestSchemas extends AgentRequestSchemaMap, TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TModels extends AgentModelMap, TEmittedSchemas extends Record<string, StandardSchemaV1> = {}, TStateSchemas extends Record<string, SetupStateSchema> = Record<string, SetupStateSchema
|
|
476
|
+
type SetupAgentXStateResult<TContextSchema extends StandardSchemaV1<Record<string, unknown>>, TEventSchemas extends AgentEventSchemaInputMap, TActors extends { [K in keyof TActors]: AnyActorLogic; }, TRequestSchemas extends AgentRequestSchemaMap, TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TModels extends AgentModelMap, TEmittedSchemas extends Record<string, StandardSchemaV1> = {}, TStateSchemas extends Record<string, SetupStateSchema> = Record<string, SetupStateSchema>, TActions extends AgentActionSources = AgentActionSources> = SetupReturnFromConfig<AgentSetupXStateConfig<TContextSchema, TEventSchemas, TActors, TRequestSchemas, TInputSchema, TOutputSchema, TMetaSchema, TModels, TEmittedSchemas, TStateSchemas, TActions>>;
|
|
476
477
|
/**
|
|
477
478
|
* The object returned by {@link setupAgent}: an xstate `setup(...)` result
|
|
478
479
|
* (`createMachine`, `assign`, …) extended with `schemas` (the resolved
|
|
@@ -481,14 +482,14 @@ type SetupAgentXStateResult<TContextSchema extends StandardSchemaV1<Record<strin
|
|
|
481
482
|
* `createAgentRuntime` can resolve their schemas/actors
|
|
482
483
|
* without re-passing them each call.
|
|
483
484
|
*/
|
|
484
|
-
type SetupAgentResult<TContextSchema extends StandardSchemaV1<Record<string, unknown>>, TEventSchemas extends AgentEventSchemaInputMap, TActors extends { [K in keyof TActors]: AnyActorLogic; }, TRequestSchemas extends AgentRequestSchemaMap, TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TModels extends AgentModelMap, TEmittedSchemas extends Record<string, StandardSchemaV1> = {}, TStateSchemas extends Record<string, SetupStateSchema> = Record<string, SetupStateSchema
|
|
485
|
+
type SetupAgentResult<TContextSchema extends StandardSchemaV1<Record<string, unknown>>, TEventSchemas extends AgentEventSchemaInputMap, TActors extends { [K in keyof TActors]: AnyActorLogic; }, TRequestSchemas extends AgentRequestSchemaMap, TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TModels extends AgentModelMap, TEmittedSchemas extends Record<string, StandardSchemaV1> = {}, TStateSchemas extends Record<string, SetupStateSchema> = Record<string, SetupStateSchema>, TActions extends AgentActionSources = AgentActionSources> = Omit<SetupAgentXStateResult<TContextSchema, TEventSchemas, TActors, TRequestSchemas, TInputSchema, TOutputSchema, TMetaSchema, TModels, TEmittedSchemas, TStateSchemas, TActions>, "createMachine"> & {
|
|
485
486
|
/**
|
|
486
487
|
* Creates the agent machine — XState's own `createMachine`, plus: the
|
|
487
488
|
* machine is registered so {@link createAgentRuntime} can resolve
|
|
488
489
|
* its schemas/actors without re-passing them, and a single final state's
|
|
489
490
|
* `output` is copied to the machine root when the root declares none.
|
|
490
491
|
*/
|
|
491
|
-
createMachine: SetupAgentXStateResult<TContextSchema, TEventSchemas, TActors, TRequestSchemas, TInputSchema, TOutputSchema, TMetaSchema, TModels, TEmittedSchemas, TStateSchemas>["createMachine"];
|
|
492
|
+
createMachine: SetupAgentXStateResult<TContextSchema, TEventSchemas, TActors, TRequestSchemas, TInputSchema, TOutputSchema, TMetaSchema, TModels, TEmittedSchemas, TStateSchemas, TActions>["createMachine"];
|
|
492
493
|
/** The retained schema pack ({@link AgentSchemaPack}) for host-side validation and tooling. Its `events` include the reserved `'@agent.usage'` entry setupAgent registers by default. */
|
|
493
494
|
schemas: AgentSchemaPack<TContextSchema, WithAgentUsageEvent<TEventSchemas>, TInputSchema, TOutputSchema, TMetaSchema, TEmittedSchemas>;
|
|
494
495
|
/** The `models` registry passed to `setupAgent(...)`, if any (used to type-narrow `AgentModelRef`). */
|
|
@@ -541,7 +542,7 @@ type SetupAgentResult<TContextSchema extends StandardSchemaV1<Record<string, unk
|
|
|
541
542
|
* });
|
|
542
543
|
* ```
|
|
543
544
|
*/
|
|
544
|
-
declare function setupAgent<TContextSchema extends StandardSchemaV1<Record<string, unknown>>, TEventSchemas extends AgentEventSchemaInputMap, TActors extends { [K in keyof TActors]: AnyActorLogic; }, TRequestSchemas extends AgentRequestSchemaMap = {}, TInputSchema extends StandardSchemaV1 = StandardSchemaV1<NonReducibleUnknown>, TOutputSchema extends StandardSchemaV1 = StandardSchemaV1<NonReducibleUnknown>, TMetaSchema extends StandardSchemaV1 = StandardSchemaV1<AgentDefaultMeta<TEventSchemas>>, TModels extends AgentModelMap = {}, TEmittedSchemas extends Record<string, StandardSchemaV1> = {}, const TStateSchemas extends Record<string, SetupStateSchema> = Record<string, SetupStateSchema
|
|
545
|
+
declare function setupAgent<TContextSchema extends StandardSchemaV1<Record<string, unknown>>, TEventSchemas extends AgentEventSchemaInputMap, TActors extends { [K in keyof TActors]: AnyActorLogic; }, TRequestSchemas extends AgentRequestSchemaMap = {}, TInputSchema extends StandardSchemaV1 = StandardSchemaV1<NonReducibleUnknown>, TOutputSchema extends StandardSchemaV1 = StandardSchemaV1<NonReducibleUnknown>, TMetaSchema extends StandardSchemaV1 = StandardSchemaV1<AgentDefaultMeta<TEventSchemas>>, TModels extends AgentModelMap = {}, TEmittedSchemas extends Record<string, StandardSchemaV1> = {}, const TStateSchemas extends Record<string, SetupStateSchema> = Record<string, SetupStateSchema>, TActions extends AgentActionSources = AgentActionSources>(config: SetupAgentBaseConfig<TContextSchema, TEventSchemas, TActors, TInputSchema, TOutputSchema, TMetaSchema, TRequestSchemas, TModels, TEmittedSchemas, TStateSchemas, TActions>): SetupAgentResult<TContextSchema, TEventSchemas, TActors, TRequestSchemas, TInputSchema, TOutputSchema, TMetaSchema, TModels, TEmittedSchemas, TStateSchemas, TActions>;
|
|
545
546
|
declare namespace setupAgent {
|
|
546
547
|
/**
|
|
547
548
|
* Builds a state machine from a serializable {@link AgentWorkflowConfig}
|