@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.
- package/CHANGELOG.md +59 -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 +142 -97
- package/dist/index.d.cts +97 -141
- package/dist/index.d.mts +97 -141
- package/dist/index.mjs +123 -74
- 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/machine-input-0YTPcnCm.mjs +27 -0
- package/dist/machine-input-DU3owLUr.cjs +32 -0
- 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/{run-agent-DlPzBWj-.d.mts → run-agent-BO9RSb7i.d.cts} +33 -40
- package/dist/{run-agent-30mH2moE.d.cts → run-agent-BxkeuAYR.d.mts} +33 -40
- package/dist/{effects-DDseYtJk.cjs → run-agent-COdR9FpM.cjs} +175 -228
- package/dist/{effects-BT_cSY0j.mjs → run-agent-D3gW9wfd.mjs} +176 -211
- 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-CIu4mqIZ.d.mts} +56 -6
- package/dist/{verify-i9Hiwc5g.d.mts → verify-CTHlmBbh.d.cts} +56 -6
- package/dist/{verify-ChyX6jq0.mjs → verify-Cacz6XSk.mjs} +170 -46
- package/dist/{verify-CwlombbC.cjs → verify-D8UDqU4l.cjs} +170 -46
- 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 +5 -4
- package/docs/environment-and-policy.md +1 -1
- package/docs/evals.md +57 -43
- package/docs/event-log.md +13 -15
- package/docs/from-a-loop.md +3 -3
- package/docs/generate-machines.md +4 -4
- package/docs/hosts.md +25 -30
- 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 +7 -12
- 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 +10 -20
- package/docs/quickstart.md +3 -3
- package/docs/statechart-policy-examples.md +1 -1
- package/docs/steps.md +5 -6
- package/docs/strangler-fig.md +105 -33
- 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 +54 -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,151 @@
|
|
|
1
|
-
import { C as
|
|
2
|
-
import { _ as isEventPattern, a as createDecisionRequest, g as getHumanEventTypes, h as getAcceptedEvents, l as resolveAllowedEventTypes, n as acceptedDecisionOptions, s as isDecisionLogic, t as AgentDecisionExhaustedError, u as resolveDecision } from "./decision-
|
|
3
|
-
import { i as isActLogic, t as ACT_STATE_EXITED } from "./act-
|
|
4
|
-
import { t as AgentEventLogConflictError } from "./event-log-store-
|
|
1
|
+
import { C as AGENT_USAGE_EVENT_TYPE, F as getCallModelCalls, I as getCallUsage, K as getRegisteredAgentExecutionOptions, L as isTextLogic, P as getCallFinishReason, R as normalizeGeneratorResult, S as validateReplayEntries, T as ACT_ACTOR, U as responseMessagesOf, W as executorBoundLogics, Z as findNonSerializableContextPaths, _ as getSnapshotStateHash, c as agentCallSite, ct as validateSchemaSync, d as canonicalEventJson, dt as isPlainObject, f as createReplayEntry, ft as isRecord, g as getLogExecutionId, i as AgentMachineVersionMismatchError, it as resolveMachineVersion, lt as canonicalJson, p as foldLog, pt as AgentError, q as isUnboundPlaceholder, s as agentCallOccurrence, u as assertJsonSerializable, v as getUsageFromEvents, w as restoreMachineSnapshot, x as replay, y as initEntry } from "./event-log-CEq_bVXQ.mjs";
|
|
2
|
+
import { _ as isEventPattern, a as createDecisionRequest, g as getHumanEventTypes, h as getAcceptedEvents, l as resolveAllowedEventTypes, n as acceptedDecisionOptions, s as isDecisionLogic, t as AgentDecisionExhaustedError, u as resolveDecision } from "./decision-B41YBx5U.mjs";
|
|
3
|
+
import { i as isActLogic, t as ACT_STATE_EXITED } from "./act-Bsz-hUfD.mjs";
|
|
4
|
+
import { t as AgentEventLogConflictError } from "./event-log-store-DLAfNM34.mjs";
|
|
5
|
+
import { t as resolveMachineInput } from "./machine-input-0YTPcnCm.mjs";
|
|
5
6
|
import { createAsyncLogic, deliverEvent, getNextTransitions, isMachineSnapshot, stopActor, transition } from "xstate";
|
|
6
7
|
import { createDurable } from "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 (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 = isRecord(persisted) ? persisted["children"] : void 0;
|
|
25
|
+
if (!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(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 (!isRecord(snapshot) || !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 (!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" && 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 = 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" && 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) => 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 (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 = isRecord(persisted) ? persisted["children"] : void 0;
|
|
202
|
-
if (!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(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 (!isRecord(snapshot) || !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 (!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" && 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 = 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" && 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) => 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 = getRegisteredAgentExecutionOptions(machine).schemas?.input;
|
|
1297
|
-
if (!isStandardSchema(schema)) return input;
|
|
1298
|
-
try {
|
|
1299
|
-
return validateSchemaSync(schema, input);
|
|
1300
|
-
} catch (error) {
|
|
1301
|
-
throw new 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 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 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({
|
|
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
|
|
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
|
|
2077
|
+
if (abortWith === void 0) {
|
|
2090
2078
|
abortNow();
|
|
2091
2079
|
return;
|
|
2092
2080
|
}
|
|
2093
|
-
|
|
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) {
|
|
2092
|
+
abortNow();
|
|
2093
|
+
return;
|
|
2094
|
+
}
|
|
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 = 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 (canonicalJson(threadInit.input) !== canonicalJson(resolvedInput)) throw new 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,26 +2636,4 @@ function isAgentIdle(snapshot) {
|
|
|
2649
2636
|
}) || getAcceptedEvents(snapshot).length > 0;
|
|
2650
2637
|
}
|
|
2651
2638
|
//#endregion
|
|
2652
|
-
|
|
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
|
-
export { runToQuiescence as _, AgentSnapshotDivergedError as a, traceTransitions as b, bindDecisionForProvide as c, createAgentRuntime as d, getConfiguredInvokeSrcs as f, runAgent as g, isStateMachineLogic as h, AgentMaxModelCallsExceededError as i, bindTextForProvide as l, isAgentIdle as m, mapEffects as n, bindActForProvide as o, inspectTransitions as p, AGENT_TRACE_SCHEMA_VERSION as r, bindChildMachineForProvide as s, isAsyncIterable as t, createAgentInbox as u, serializeTraceEvent as v, decideNext as x, toJsonValue as y };
|
|
2639
|
+
export { traceTransitions as _, bindChildMachineForProvide as a, createAgentInbox as c, isAgentIdle as d, isStateMachineLogic as f, toJsonValue as g, serializeTraceEvent as h, bindActForProvide as i, createAgentRuntime as l, runToQuiescence as m, AgentMaxModelCallsExceededError as n, bindDecisionForProvide as o, runAgent as p, AgentSnapshotDivergedError as r, bindTextForProvide as s, AGENT_TRACE_SCHEMA_VERSION as t, getConfiguredInvokeSrcs as u, decideNext as v };
|
|
@@ -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}
|