@statelyai/agent 2.0.0-alpha.36 → 2.0.0-alpha.37
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 +27 -0
- package/dist/{effects-CuOUNYtZ.mjs → effects-BT_cSY0j.mjs} +95 -11
- package/dist/{effects-B23bFZEs.cjs → effects-DDseYtJk.cjs} +95 -11
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +1 -1
- package/dist/otel.d.cts +1 -1
- package/dist/otel.d.mts +1 -1
- package/dist/{run-agent-BcQ-9NRT.d.cts → run-agent-30mH2moE.d.cts} +2 -2
- package/dist/{run-agent-C86drZtN.d.mts → run-agent-DlPzBWj-.d.mts} +2 -2
- package/dist/{setup-agent-jlo4vtaZ.d.cts → setup-agent-BaNyz6Q3.d.cts} +1 -1
- package/dist/{setup-agent-BIKcbVXV.d.mts → setup-agent-C1CG_nfX.d.mts} +1 -1
- package/dist/testing.cjs +2411 -1799
- package/dist/testing.d.cts +167 -4
- package/dist/testing.d.mts +167 -4
- package/dist/testing.mjs +2412 -1801
- package/dist/{usage-HtnrUsl9.d.cts → usage-Bm5nvpow.d.cts} +5 -0
- package/dist/{usage-DoP0Oi84.d.mts → usage-BnikdOca.d.mts} +5 -0
- package/dist/validate.cjs +1 -1
- package/dist/validate.d.cts +2 -2
- package/dist/validate.d.mts +2 -2
- package/dist/validate.mjs +1 -1
- package/dist/{verify-Dpz1u5Pe.mjs → verify-ChyX6jq0.mjs} +75 -20
- package/dist/{verify-Bink-Drw.cjs → verify-CwlombbC.cjs} +75 -20
- package/dist/{verify-CciG8UP-.d.cts → verify-DJHfEfm6.d.cts} +9 -4
- package/dist/{verify-Buh8XSUr.d.mts → verify-i9Hiwc5g.d.mts} +9 -4
- package/docs/event-log.md +2 -1
- package/docs/persistence.md +71 -0
- package/docs/steps.md +2 -0
- package/docs/usage-and-budgets.md +2 -0
- package/docs/verify.md +7 -2
- package/package.json +1 -1
- package/skills/build-machine/SKILL.md +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# @statelyai/agent
|
|
2
2
|
|
|
3
|
+
## 2.0.0-alpha.37
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#225](https://github.com/statelyai/agent/pull/225) [`d6c41bc`](https://github.com/statelyai/agent/commit/d6c41bcb72420a0a2f4e0ec6c411f7b091314e75) Thanks [@davidkpiano](https://github.com/davidkpiano)! - `children: "coupled"` exploration closes two proof gaps:
|
|
8
|
+
|
|
9
|
+
- A `canReach` predicate and `dedupeBy` now see each coupled child's explored state through `snapshot.children[id].getSnapshot()`, not the state it started in. A parent's send and the child's receipt are one state, so cross-actor invariants can be targets.
|
|
10
|
+
- A coupled child's text requests deliver `@agent.usage` to the root, as a run does: each `usage` value forks a branch, and the root takes or drops the event by the usual rules. Token budgets fed by child calls can now be proved.
|
|
11
|
+
|
|
12
|
+
- [#224](https://github.com/statelyai/agent/pull/224) [`12fab4f`](https://github.com/statelyai/agent/commit/12fab4f56ac0c78c4071a9ef674c71f6a8ca124c) Thanks [@davidkpiano](https://github.com/davidkpiano)! - `checkCrashRecovery` takes `sendDuring` (host events sent while a named effect, or its `occurrence`-th start, is in flight, and redelivered after a crash when the log lost them) and `timers: "host"` (the harness hosts root `after` timers on a virtual clock; an id-less `{ type: "xstate.timer" }` in `events` fires the soonest). A `sendDuring` key the run never starts, or `events` left undelivered, now throw.
|
|
13
|
+
|
|
14
|
+
Fix: a model call (text, decision, or fill) whose invoke is stopped while it waits for the journal write no longer reaches the executor, so a cancel that lands in the same step costs no tokens.
|
|
15
|
+
|
|
16
|
+
Fix: a plain actor at the root waits for the journal like a model call does, so the event that started it is durable before its side effect runs.
|
|
17
|
+
|
|
18
|
+
`runAgent`'s `onIdle` may return a host timer firing (`{ type: "xstate.timer", id }`).
|
|
19
|
+
|
|
20
|
+
- [#223](https://github.com/statelyai/agent/pull/223) [`106e3c6`](https://github.com/statelyai/agent/commit/106e3c67a0dd1e05c7d559aeeb3a355e0f593b70) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Add `checkCrashRecovery` to `@statelyai/agent/testing`: it kills a durable run after every log append and while every effect is in flight, resumes each from the store's log, and checks the resume against an uninterrupted run (no durable effect re-runs, none skipped, same `callKey` and request, same outcome, the log replays). Pass `store` to check your own store adapter.
|
|
21
|
+
|
|
22
|
+
Fix: a child machine that finished just before a crash (its last entry journaled, its parent's `xstate.done.actor` not yet) no longer leaves the resumed parent waiting forever. The restored child's completion is now delivered to its parent, at any depth.
|
|
23
|
+
|
|
24
|
+
`@agent.usage` now carries the call's `callKey`.
|
|
25
|
+
|
|
26
|
+
Fix: a parent's `sendTo` into a journaled child machine, and the child's reply, are no longer lost when the run dies between appends. The store now receives every entry since the loop last waited in one atomic append (`expectedIndex` is the batch's first index), so an event and the child inputs it caused land together.
|
|
27
|
+
|
|
28
|
+
- [#221](https://github.com/statelyai/agent/pull/221) [`cd6148c`](https://github.com/statelyai/agent/commit/cd6148c01d45a547bed9df5b7601e8a871f9a412) Thanks [@davidkpiano](https://github.com/davidkpiano)! - `explorePaths` delivers a scripted `@agent.usage` event only when the machine accepts it, as a run does, and a usage transition that restarts the invoke no longer receives the old request's completion.
|
|
29
|
+
|
|
3
30
|
## 2.0.0-alpha.36
|
|
4
31
|
|
|
5
32
|
### Minor Changes
|
|
@@ -742,6 +742,7 @@ async function runTextRequest(runCtx, mode, request, self, signal) {
|
|
|
742
742
|
try {
|
|
743
743
|
const callKey = id !== "" ? runCtx.callKey?.(id, self) : void 0;
|
|
744
744
|
await runCtx.awaitJournal?.();
|
|
745
|
+
signal.throwIfAborted();
|
|
745
746
|
const raw = await executor(requestWithTools, {
|
|
746
747
|
onChunk: (chunk) => {
|
|
747
748
|
runCtx.emitTrace?.({
|
|
@@ -766,7 +767,8 @@ async function runTextRequest(runCtx, mode, request, self, signal) {
|
|
|
766
767
|
...id !== "" ? { id } : {},
|
|
767
768
|
...src !== "" ? { src } : {},
|
|
768
769
|
model: request.model,
|
|
769
|
-
...request.name !== void 0 ? { name: request.name } : {}
|
|
770
|
+
...request.name !== void 0 ? { name: request.name } : {},
|
|
771
|
+
...callKey !== void 0 ? { callKey } : {}
|
|
770
772
|
}, self);
|
|
771
773
|
runCtx.emitTrace?.({
|
|
772
774
|
type: "request.end",
|
|
@@ -909,6 +911,7 @@ function createCountingDecide(runCtx, self, recordLater) {
|
|
|
909
911
|
const invokeCallKey = id !== "" ? runCtx.callKey?.(id, self) : void 0;
|
|
910
912
|
const callKey = invokeCallKey === void 0 ? void 0 : `${invokeCallKey}.${attemptRequest.attempts?.length ?? 0}`;
|
|
911
913
|
await runCtx.awaitJournal?.();
|
|
914
|
+
info?.signal?.throwIfAborted();
|
|
912
915
|
const result = await runCtx.decide(runCtx.runId !== void 0 ? {
|
|
913
916
|
...attemptRequest,
|
|
914
917
|
runId: runCtx.runId
|
|
@@ -926,7 +929,8 @@ function createCountingDecide(runCtx, self, recordLater) {
|
|
|
926
929
|
kind: "decision",
|
|
927
930
|
...attemptRequest.id ? { id: attemptRequest.id } : {},
|
|
928
931
|
...src !== "" ? { src } : {},
|
|
929
|
-
model: attemptRequest.model
|
|
932
|
+
model: attemptRequest.model,
|
|
933
|
+
...callKey !== void 0 ? { callKey } : {}
|
|
930
934
|
}, self));
|
|
931
935
|
}
|
|
932
936
|
runCtx.emitTrace?.({
|
|
@@ -967,6 +971,7 @@ function createCountingFill(runCtx, self, recordLater) {
|
|
|
967
971
|
}, self);
|
|
968
972
|
try {
|
|
969
973
|
await runCtx.awaitJournal?.();
|
|
974
|
+
info?.signal?.throwIfAborted();
|
|
970
975
|
const raw = await runCtx.generateText(request, {
|
|
971
976
|
...info,
|
|
972
977
|
...runCtx.runId !== void 0 ? { runId: runCtx.runId } : {},
|
|
@@ -979,7 +984,8 @@ function createCountingFill(runCtx, self, recordLater) {
|
|
|
979
984
|
kind: "decision",
|
|
980
985
|
...id !== "" ? { id } : {},
|
|
981
986
|
...src !== "" ? { src } : {},
|
|
982
|
-
model: request.model
|
|
987
|
+
model: request.model,
|
|
988
|
+
...info?.callKey !== void 0 ? { callKey: info.callKey } : {}
|
|
983
989
|
}, self));
|
|
984
990
|
runCtx.emitTrace?.({
|
|
985
991
|
type: "request.end",
|
|
@@ -1361,14 +1367,15 @@ function journalGatedLogic(logic, pending) {
|
|
|
1361
1367
|
const gate = (result, self) => {
|
|
1362
1368
|
const [snapshot, effects] = result;
|
|
1363
1369
|
if (!Array.isArray(effects) || !effects.some((e) => e?.type === "@xstate.effect")) return result;
|
|
1370
|
+
const finishing = snapshot?.status === "done";
|
|
1364
1371
|
return [snapshot, effects.map((effect) => {
|
|
1365
1372
|
if (effect?.type !== "@xstate.effect") return effect;
|
|
1366
1373
|
const exec = effect.exec;
|
|
1367
1374
|
const gated = (...args) => {
|
|
1368
1375
|
const waiting = pending();
|
|
1369
1376
|
if (waiting === void 0) return exec(...args);
|
|
1370
|
-
waiting.then(() => {
|
|
1371
|
-
if (self.getSnapshot().status === "active") exec(...args);
|
|
1377
|
+
waiting.then((ok) => {
|
|
1378
|
+
if (ok && (finishing || self.getSnapshot().status === "active")) exec(...args);
|
|
1372
1379
|
});
|
|
1373
1380
|
};
|
|
1374
1381
|
return {
|
|
@@ -1725,15 +1732,23 @@ function createAgentRuntime(machine, options = {}) {
|
|
|
1725
1732
|
let journalChain = Promise.resolve();
|
|
1726
1733
|
let journalPending = 0;
|
|
1727
1734
|
let journalError;
|
|
1728
|
-
|
|
1729
|
-
|
|
1735
|
+
let unflushed = [];
|
|
1736
|
+
let flushWaiters = [];
|
|
1737
|
+
let resultOwed = false;
|
|
1738
|
+
const flushJournal = () => {
|
|
1739
|
+
const waiters = flushWaiters;
|
|
1740
|
+
flushWaiters = [];
|
|
1741
|
+
for (const resolve of waiters) resolve();
|
|
1742
|
+
if (store === void 0 || unflushed.length === 0) return;
|
|
1743
|
+
const entries = unflushed;
|
|
1744
|
+
unflushed = [];
|
|
1730
1745
|
journalPending++;
|
|
1731
1746
|
journalChain = journalChain.then(async () => {
|
|
1732
1747
|
if (journalError !== void 0) return;
|
|
1733
1748
|
await store.append({
|
|
1734
1749
|
threadId,
|
|
1735
|
-
expectedIndex:
|
|
1736
|
-
entries
|
|
1750
|
+
expectedIndex: entries[0].index,
|
|
1751
|
+
entries
|
|
1737
1752
|
});
|
|
1738
1753
|
}).catch((error) => {
|
|
1739
1754
|
journalError ??= error;
|
|
@@ -1745,6 +1760,29 @@ function createAgentRuntime(machine, options = {}) {
|
|
|
1745
1760
|
journalPending--;
|
|
1746
1761
|
});
|
|
1747
1762
|
};
|
|
1763
|
+
const journalEntry = (entry) => {
|
|
1764
|
+
if (store === void 0) return;
|
|
1765
|
+
unflushed.push(entry);
|
|
1766
|
+
if (finished) flushJournal();
|
|
1767
|
+
};
|
|
1768
|
+
/**
|
|
1769
|
+
* Resolves once the entries so far are handed to the store as one settled
|
|
1770
|
+
* step. Mid-step (a transition's effects still running, its children's
|
|
1771
|
+
* replies not yet delivered), a barrier waits for the loop to finish the
|
|
1772
|
+
* step, so it cannot write a child's input without the reply it sends back.
|
|
1773
|
+
* The loop flushes when it next waits; a host that is not reading
|
|
1774
|
+
* `nextEvent` gets the flush on the next task instead.
|
|
1775
|
+
*/
|
|
1776
|
+
const stepSettled = () => {
|
|
1777
|
+
if (wake !== void 0 || finished || stopReason !== void 0) {
|
|
1778
|
+
flushJournal();
|
|
1779
|
+
return Promise.resolve();
|
|
1780
|
+
}
|
|
1781
|
+
return new Promise((resolve) => {
|
|
1782
|
+
flushWaiters.push(resolve);
|
|
1783
|
+
setTimeout(flushJournal, 0);
|
|
1784
|
+
});
|
|
1785
|
+
};
|
|
1748
1786
|
/**
|
|
1749
1787
|
* Every journal write ISSUED SO FAR, including the stragglers appended after
|
|
1750
1788
|
* the run settled. Re-reads the chain tail until it stops moving, so a write
|
|
@@ -1753,6 +1791,7 @@ function createAgentRuntime(machine, options = {}) {
|
|
|
1753
1791
|
*/
|
|
1754
1792
|
const drainJournal = async () => {
|
|
1755
1793
|
if (store === void 0) return;
|
|
1794
|
+
flushJournal();
|
|
1756
1795
|
let tail = journalChain;
|
|
1757
1796
|
for (;;) {
|
|
1758
1797
|
await tail;
|
|
@@ -1763,6 +1802,7 @@ function createAgentRuntime(machine, options = {}) {
|
|
|
1763
1802
|
/** The barrier: settle the pending chain, then surface any failure. */
|
|
1764
1803
|
const awaitJournal = async () => {
|
|
1765
1804
|
if (store === void 0) return;
|
|
1805
|
+
await stepSettled();
|
|
1766
1806
|
while (journalPending > 0) await journalChain;
|
|
1767
1807
|
if (journalError !== void 0) throw journalError;
|
|
1768
1808
|
};
|
|
@@ -1840,6 +1880,7 @@ function createAgentRuntime(machine, options = {}) {
|
|
|
1840
1880
|
maxModelCalls
|
|
1841
1881
|
}
|
|
1842
1882
|
};
|
|
1883
|
+
if (source.kind === "text") resultOwed = true;
|
|
1843
1884
|
let delivered = false;
|
|
1844
1885
|
deliverUsageEvent(event, () => rootFacade(() => delivered = true, source.kind === "decision" ? void 0 : self), (dropped) => {
|
|
1845
1886
|
if (!finished) return false;
|
|
@@ -1913,7 +1954,7 @@ function createAgentRuntime(machine, options = {}) {
|
|
|
1913
1954
|
}),
|
|
1914
1955
|
runId,
|
|
1915
1956
|
schemas: getRegisteredAgentExecutionOptions(machine).schemas,
|
|
1916
|
-
pendingJournal: () => store !== void 0 && journalPending > 0 ? awaitJournal().
|
|
1957
|
+
pendingJournal: () => store !== void 0 && (journalPending > 0 || unflushed.length > 0) ? awaitJournal().then(() => stopReason === void 0, () => false) : void 0,
|
|
1917
1958
|
onChildEvent: (self, event) => {
|
|
1918
1959
|
if (finished || event.type === "xstate.stop") return;
|
|
1919
1960
|
const actorPath = actorPathOf(self);
|
|
@@ -1953,6 +1994,7 @@ function createAgentRuntime(machine, options = {}) {
|
|
|
1953
1994
|
if (rebound !== logic) wrappedSources[key] = rebound;
|
|
1954
1995
|
continue;
|
|
1955
1996
|
}
|
|
1997
|
+
if (runCtx.pendingJournal && typeof logic?.transition === "function") wrappedSources[key] = journalGatedLogic(logic, runCtx.pendingJournal);
|
|
1956
1998
|
}
|
|
1957
1999
|
const boundMachine = provided.provide({ actors: wrappedSources });
|
|
1958
2000
|
const mailbox = [];
|
|
@@ -2066,6 +2108,32 @@ function createAgentRuntime(machine, options = {}) {
|
|
|
2066
2108
|
if (typeof options.inspect === "function") options.inspect(event);
|
|
2067
2109
|
else options.inspect?.next?.(event);
|
|
2068
2110
|
});
|
|
2111
|
+
const completionOf = (child) => {
|
|
2112
|
+
const snapshot = child.getSnapshot();
|
|
2113
|
+
if (snapshot.status === "done") return {
|
|
2114
|
+
type: "xstate.done.actor",
|
|
2115
|
+
output: snapshot.output,
|
|
2116
|
+
actorId: child.id,
|
|
2117
|
+
sessionId: child.sessionId
|
|
2118
|
+
};
|
|
2119
|
+
if (snapshot.status === "error") return {
|
|
2120
|
+
type: "xstate.error.actor",
|
|
2121
|
+
error: snapshot.error,
|
|
2122
|
+
actorId: child.id,
|
|
2123
|
+
sessionId: child.sessionId
|
|
2124
|
+
};
|
|
2125
|
+
};
|
|
2126
|
+
const restoredRootCompletions = (snapshot) => Object.values(snapshot.children ?? {}).map((child) => child ? completionOf(child) : void 0).filter((event) => event !== void 0);
|
|
2127
|
+
const reportRestoredCompletions = (actor) => {
|
|
2128
|
+
const snapshot = actor.getSnapshot();
|
|
2129
|
+
if (snapshot.status !== "active") return;
|
|
2130
|
+
for (const child of Object.values(snapshot.children ?? {})) {
|
|
2131
|
+
if (!child) continue;
|
|
2132
|
+
const event = completionOf(child);
|
|
2133
|
+
if (event !== void 0 && child._restored) child.system?.sendEvent?.(child, actor, event);
|
|
2134
|
+
else reportRestoredCompletions(child);
|
|
2135
|
+
}
|
|
2136
|
+
};
|
|
2069
2137
|
let execution;
|
|
2070
2138
|
execution = createDurable(boundMachine, {
|
|
2071
2139
|
startActor: (actor) => {
|
|
@@ -2075,12 +2143,17 @@ function createAgentRuntime(machine, options = {}) {
|
|
|
2075
2143
|
error: recheck
|
|
2076
2144
|
});
|
|
2077
2145
|
actor.start();
|
|
2146
|
+
reportRestoredCompletions(actor);
|
|
2078
2147
|
},
|
|
2079
2148
|
enqueueRootEvent: (_source, event) => enqueue(event),
|
|
2080
2149
|
executeAction: (action, _metadata, runtime) => action.exec(runtime),
|
|
2081
2150
|
waitForEvent: () => {
|
|
2082
2151
|
const queued = mailbox.shift();
|
|
2083
2152
|
if (queued !== void 0) return queued;
|
|
2153
|
+
if (resultOwed) {
|
|
2154
|
+
resultOwed = false;
|
|
2155
|
+
setTimeout(flushJournal, 0);
|
|
2156
|
+
} else flushJournal();
|
|
2084
2157
|
if (stopReason !== void 0 || finished || !workInFlight()) return QUIESCENT;
|
|
2085
2158
|
return new Promise((resolve) => {
|
|
2086
2159
|
wake = resolve;
|
|
@@ -2326,6 +2399,7 @@ function createAgentRuntime(machine, options = {}) {
|
|
|
2326
2399
|
else {
|
|
2327
2400
|
try {
|
|
2328
2401
|
[snapshot, effects] = execution.restore(effectiveSnapshot);
|
|
2402
|
+
for (const event of restoredRootCompletions(snapshot)) enqueue(event);
|
|
2329
2403
|
} catch (error) {
|
|
2330
2404
|
try {
|
|
2331
2405
|
current = execution.initialTransition(resolvedInput)[0];
|
|
@@ -2411,7 +2485,16 @@ function createAgentRuntime(machine, options = {}) {
|
|
|
2411
2485
|
if (finished) throw new AgentError("runtime-finished", "createAgentRuntime: `finish` was already called.");
|
|
2412
2486
|
clearTimeout(abortTimer);
|
|
2413
2487
|
if ((pendingAbort !== void 0 || abortApplied) && current?.status === "active") abortNow();
|
|
2414
|
-
|
|
2488
|
+
const journaledUsage = /* @__PURE__ */ new Set();
|
|
2489
|
+
for (;;) {
|
|
2490
|
+
await drainJournal();
|
|
2491
|
+
const usage = mailbox.filter((event) => event.type === "@agent.usage" && !journaledUsage.has(event));
|
|
2492
|
+
if (usage.length === 0) break;
|
|
2493
|
+
for (const event of usage) {
|
|
2494
|
+
journaledUsage.add(event);
|
|
2495
|
+
appendLogEntry(event);
|
|
2496
|
+
}
|
|
2497
|
+
}
|
|
2415
2498
|
const snapshot = current;
|
|
2416
2499
|
let outcome;
|
|
2417
2500
|
if (stopReason !== void 0) outcome = {
|
|
@@ -2464,6 +2547,7 @@ function createAgentRuntime(machine, options = {}) {
|
|
|
2464
2547
|
return persistedSnapshot;
|
|
2465
2548
|
};
|
|
2466
2549
|
finished = true;
|
|
2550
|
+
flushJournal();
|
|
2467
2551
|
releaseAllDeliveries();
|
|
2468
2552
|
const journalAtSettle = journalChain;
|
|
2469
2553
|
const result = {
|
|
@@ -742,6 +742,7 @@ async function runTextRequest(runCtx, mode, request, self, signal) {
|
|
|
742
742
|
try {
|
|
743
743
|
const callKey = id !== "" ? runCtx.callKey?.(id, self) : void 0;
|
|
744
744
|
await runCtx.awaitJournal?.();
|
|
745
|
+
signal.throwIfAborted();
|
|
745
746
|
const raw = await executor(requestWithTools, {
|
|
746
747
|
onChunk: (chunk) => {
|
|
747
748
|
runCtx.emitTrace?.({
|
|
@@ -766,7 +767,8 @@ async function runTextRequest(runCtx, mode, request, self, signal) {
|
|
|
766
767
|
...id !== "" ? { id } : {},
|
|
767
768
|
...src !== "" ? { src } : {},
|
|
768
769
|
model: request.model,
|
|
769
|
-
...request.name !== void 0 ? { name: request.name } : {}
|
|
770
|
+
...request.name !== void 0 ? { name: request.name } : {},
|
|
771
|
+
...callKey !== void 0 ? { callKey } : {}
|
|
770
772
|
}, self);
|
|
771
773
|
runCtx.emitTrace?.({
|
|
772
774
|
type: "request.end",
|
|
@@ -909,6 +911,7 @@ function createCountingDecide(runCtx, self, recordLater) {
|
|
|
909
911
|
const invokeCallKey = id !== "" ? runCtx.callKey?.(id, self) : void 0;
|
|
910
912
|
const callKey = invokeCallKey === void 0 ? void 0 : `${invokeCallKey}.${attemptRequest.attempts?.length ?? 0}`;
|
|
911
913
|
await runCtx.awaitJournal?.();
|
|
914
|
+
info?.signal?.throwIfAborted();
|
|
912
915
|
const result = await runCtx.decide(runCtx.runId !== void 0 ? {
|
|
913
916
|
...attemptRequest,
|
|
914
917
|
runId: runCtx.runId
|
|
@@ -926,7 +929,8 @@ function createCountingDecide(runCtx, self, recordLater) {
|
|
|
926
929
|
kind: "decision",
|
|
927
930
|
...attemptRequest.id ? { id: attemptRequest.id } : {},
|
|
928
931
|
...src !== "" ? { src } : {},
|
|
929
|
-
model: attemptRequest.model
|
|
932
|
+
model: attemptRequest.model,
|
|
933
|
+
...callKey !== void 0 ? { callKey } : {}
|
|
930
934
|
}, self));
|
|
931
935
|
}
|
|
932
936
|
runCtx.emitTrace?.({
|
|
@@ -967,6 +971,7 @@ function createCountingFill(runCtx, self, recordLater) {
|
|
|
967
971
|
}, self);
|
|
968
972
|
try {
|
|
969
973
|
await runCtx.awaitJournal?.();
|
|
974
|
+
info?.signal?.throwIfAborted();
|
|
970
975
|
const raw = await runCtx.generateText(request, {
|
|
971
976
|
...info,
|
|
972
977
|
...runCtx.runId !== void 0 ? { runId: runCtx.runId } : {},
|
|
@@ -979,7 +984,8 @@ function createCountingFill(runCtx, self, recordLater) {
|
|
|
979
984
|
kind: "decision",
|
|
980
985
|
...id !== "" ? { id } : {},
|
|
981
986
|
...src !== "" ? { src } : {},
|
|
982
|
-
model: request.model
|
|
987
|
+
model: request.model,
|
|
988
|
+
...info?.callKey !== void 0 ? { callKey: info.callKey } : {}
|
|
983
989
|
}, self));
|
|
984
990
|
runCtx.emitTrace?.({
|
|
985
991
|
type: "request.end",
|
|
@@ -1361,14 +1367,15 @@ function journalGatedLogic(logic, pending) {
|
|
|
1361
1367
|
const gate = (result, self) => {
|
|
1362
1368
|
const [snapshot, effects] = result;
|
|
1363
1369
|
if (!Array.isArray(effects) || !effects.some((e) => e?.type === "@xstate.effect")) return result;
|
|
1370
|
+
const finishing = snapshot?.status === "done";
|
|
1364
1371
|
return [snapshot, effects.map((effect) => {
|
|
1365
1372
|
if (effect?.type !== "@xstate.effect") return effect;
|
|
1366
1373
|
const exec = effect.exec;
|
|
1367
1374
|
const gated = (...args) => {
|
|
1368
1375
|
const waiting = pending();
|
|
1369
1376
|
if (waiting === void 0) return exec(...args);
|
|
1370
|
-
waiting.then(() => {
|
|
1371
|
-
if (self.getSnapshot().status === "active") exec(...args);
|
|
1377
|
+
waiting.then((ok) => {
|
|
1378
|
+
if (ok && (finishing || self.getSnapshot().status === "active")) exec(...args);
|
|
1372
1379
|
});
|
|
1373
1380
|
};
|
|
1374
1381
|
return {
|
|
@@ -1725,15 +1732,23 @@ function createAgentRuntime(machine, options = {}) {
|
|
|
1725
1732
|
let journalChain = Promise.resolve();
|
|
1726
1733
|
let journalPending = 0;
|
|
1727
1734
|
let journalError;
|
|
1728
|
-
|
|
1729
|
-
|
|
1735
|
+
let unflushed = [];
|
|
1736
|
+
let flushWaiters = [];
|
|
1737
|
+
let resultOwed = false;
|
|
1738
|
+
const flushJournal = () => {
|
|
1739
|
+
const waiters = flushWaiters;
|
|
1740
|
+
flushWaiters = [];
|
|
1741
|
+
for (const resolve of waiters) resolve();
|
|
1742
|
+
if (store === void 0 || unflushed.length === 0) return;
|
|
1743
|
+
const entries = unflushed;
|
|
1744
|
+
unflushed = [];
|
|
1730
1745
|
journalPending++;
|
|
1731
1746
|
journalChain = journalChain.then(async () => {
|
|
1732
1747
|
if (journalError !== void 0) return;
|
|
1733
1748
|
await store.append({
|
|
1734
1749
|
threadId,
|
|
1735
|
-
expectedIndex:
|
|
1736
|
-
entries
|
|
1750
|
+
expectedIndex: entries[0].index,
|
|
1751
|
+
entries
|
|
1737
1752
|
});
|
|
1738
1753
|
}).catch((error) => {
|
|
1739
1754
|
journalError ??= error;
|
|
@@ -1745,6 +1760,29 @@ function createAgentRuntime(machine, options = {}) {
|
|
|
1745
1760
|
journalPending--;
|
|
1746
1761
|
});
|
|
1747
1762
|
};
|
|
1763
|
+
const journalEntry = (entry) => {
|
|
1764
|
+
if (store === void 0) return;
|
|
1765
|
+
unflushed.push(entry);
|
|
1766
|
+
if (finished) flushJournal();
|
|
1767
|
+
};
|
|
1768
|
+
/**
|
|
1769
|
+
* Resolves once the entries so far are handed to the store as one settled
|
|
1770
|
+
* step. Mid-step (a transition's effects still running, its children's
|
|
1771
|
+
* replies not yet delivered), a barrier waits for the loop to finish the
|
|
1772
|
+
* step, so it cannot write a child's input without the reply it sends back.
|
|
1773
|
+
* The loop flushes when it next waits; a host that is not reading
|
|
1774
|
+
* `nextEvent` gets the flush on the next task instead.
|
|
1775
|
+
*/
|
|
1776
|
+
const stepSettled = () => {
|
|
1777
|
+
if (wake !== void 0 || finished || stopReason !== void 0) {
|
|
1778
|
+
flushJournal();
|
|
1779
|
+
return Promise.resolve();
|
|
1780
|
+
}
|
|
1781
|
+
return new Promise((resolve) => {
|
|
1782
|
+
flushWaiters.push(resolve);
|
|
1783
|
+
setTimeout(flushJournal, 0);
|
|
1784
|
+
});
|
|
1785
|
+
};
|
|
1748
1786
|
/**
|
|
1749
1787
|
* Every journal write ISSUED SO FAR, including the stragglers appended after
|
|
1750
1788
|
* the run settled. Re-reads the chain tail until it stops moving, so a write
|
|
@@ -1753,6 +1791,7 @@ function createAgentRuntime(machine, options = {}) {
|
|
|
1753
1791
|
*/
|
|
1754
1792
|
const drainJournal = async () => {
|
|
1755
1793
|
if (store === void 0) return;
|
|
1794
|
+
flushJournal();
|
|
1756
1795
|
let tail = journalChain;
|
|
1757
1796
|
for (;;) {
|
|
1758
1797
|
await tail;
|
|
@@ -1763,6 +1802,7 @@ function createAgentRuntime(machine, options = {}) {
|
|
|
1763
1802
|
/** The barrier: settle the pending chain, then surface any failure. */
|
|
1764
1803
|
const awaitJournal = async () => {
|
|
1765
1804
|
if (store === void 0) return;
|
|
1805
|
+
await stepSettled();
|
|
1766
1806
|
while (journalPending > 0) await journalChain;
|
|
1767
1807
|
if (journalError !== void 0) throw journalError;
|
|
1768
1808
|
};
|
|
@@ -1840,6 +1880,7 @@ function createAgentRuntime(machine, options = {}) {
|
|
|
1840
1880
|
maxModelCalls
|
|
1841
1881
|
}
|
|
1842
1882
|
};
|
|
1883
|
+
if (source.kind === "text") resultOwed = true;
|
|
1843
1884
|
let delivered = false;
|
|
1844
1885
|
deliverUsageEvent(event, () => rootFacade(() => delivered = true, source.kind === "decision" ? void 0 : self), (dropped) => {
|
|
1845
1886
|
if (!finished) return false;
|
|
@@ -1913,7 +1954,7 @@ function createAgentRuntime(machine, options = {}) {
|
|
|
1913
1954
|
}),
|
|
1914
1955
|
runId,
|
|
1915
1956
|
schemas: require_event_log.getRegisteredAgentExecutionOptions(machine).schemas,
|
|
1916
|
-
pendingJournal: () => store !== void 0 && journalPending > 0 ? awaitJournal().
|
|
1957
|
+
pendingJournal: () => store !== void 0 && (journalPending > 0 || unflushed.length > 0) ? awaitJournal().then(() => stopReason === void 0, () => false) : void 0,
|
|
1917
1958
|
onChildEvent: (self, event) => {
|
|
1918
1959
|
if (finished || event.type === "xstate.stop") return;
|
|
1919
1960
|
const actorPath = actorPathOf(self);
|
|
@@ -1953,6 +1994,7 @@ function createAgentRuntime(machine, options = {}) {
|
|
|
1953
1994
|
if (rebound !== logic) wrappedSources[key] = rebound;
|
|
1954
1995
|
continue;
|
|
1955
1996
|
}
|
|
1997
|
+
if (runCtx.pendingJournal && typeof logic?.transition === "function") wrappedSources[key] = journalGatedLogic(logic, runCtx.pendingJournal);
|
|
1956
1998
|
}
|
|
1957
1999
|
const boundMachine = provided.provide({ actors: wrappedSources });
|
|
1958
2000
|
const mailbox = [];
|
|
@@ -2066,6 +2108,32 @@ function createAgentRuntime(machine, options = {}) {
|
|
|
2066
2108
|
if (typeof options.inspect === "function") options.inspect(event);
|
|
2067
2109
|
else options.inspect?.next?.(event);
|
|
2068
2110
|
});
|
|
2111
|
+
const completionOf = (child) => {
|
|
2112
|
+
const snapshot = child.getSnapshot();
|
|
2113
|
+
if (snapshot.status === "done") return {
|
|
2114
|
+
type: "xstate.done.actor",
|
|
2115
|
+
output: snapshot.output,
|
|
2116
|
+
actorId: child.id,
|
|
2117
|
+
sessionId: child.sessionId
|
|
2118
|
+
};
|
|
2119
|
+
if (snapshot.status === "error") return {
|
|
2120
|
+
type: "xstate.error.actor",
|
|
2121
|
+
error: snapshot.error,
|
|
2122
|
+
actorId: child.id,
|
|
2123
|
+
sessionId: child.sessionId
|
|
2124
|
+
};
|
|
2125
|
+
};
|
|
2126
|
+
const restoredRootCompletions = (snapshot) => Object.values(snapshot.children ?? {}).map((child) => child ? completionOf(child) : void 0).filter((event) => event !== void 0);
|
|
2127
|
+
const reportRestoredCompletions = (actor) => {
|
|
2128
|
+
const snapshot = actor.getSnapshot();
|
|
2129
|
+
if (snapshot.status !== "active") return;
|
|
2130
|
+
for (const child of Object.values(snapshot.children ?? {})) {
|
|
2131
|
+
if (!child) continue;
|
|
2132
|
+
const event = completionOf(child);
|
|
2133
|
+
if (event !== void 0 && child._restored) child.system?.sendEvent?.(child, actor, event);
|
|
2134
|
+
else reportRestoredCompletions(child);
|
|
2135
|
+
}
|
|
2136
|
+
};
|
|
2069
2137
|
let execution;
|
|
2070
2138
|
execution = (0, xstate_durable.createDurable)(boundMachine, {
|
|
2071
2139
|
startActor: (actor) => {
|
|
@@ -2075,12 +2143,17 @@ function createAgentRuntime(machine, options = {}) {
|
|
|
2075
2143
|
error: recheck
|
|
2076
2144
|
});
|
|
2077
2145
|
actor.start();
|
|
2146
|
+
reportRestoredCompletions(actor);
|
|
2078
2147
|
},
|
|
2079
2148
|
enqueueRootEvent: (_source, event) => enqueue(event),
|
|
2080
2149
|
executeAction: (action, _metadata, runtime) => action.exec(runtime),
|
|
2081
2150
|
waitForEvent: () => {
|
|
2082
2151
|
const queued = mailbox.shift();
|
|
2083
2152
|
if (queued !== void 0) return queued;
|
|
2153
|
+
if (resultOwed) {
|
|
2154
|
+
resultOwed = false;
|
|
2155
|
+
setTimeout(flushJournal, 0);
|
|
2156
|
+
} else flushJournal();
|
|
2084
2157
|
if (stopReason !== void 0 || finished || !workInFlight()) return QUIESCENT;
|
|
2085
2158
|
return new Promise((resolve) => {
|
|
2086
2159
|
wake = resolve;
|
|
@@ -2326,6 +2399,7 @@ function createAgentRuntime(machine, options = {}) {
|
|
|
2326
2399
|
else {
|
|
2327
2400
|
try {
|
|
2328
2401
|
[snapshot, effects] = execution.restore(effectiveSnapshot);
|
|
2402
|
+
for (const event of restoredRootCompletions(snapshot)) enqueue(event);
|
|
2329
2403
|
} catch (error) {
|
|
2330
2404
|
try {
|
|
2331
2405
|
current = execution.initialTransition(resolvedInput)[0];
|
|
@@ -2411,7 +2485,16 @@ function createAgentRuntime(machine, options = {}) {
|
|
|
2411
2485
|
if (finished) throw new require_event_log.AgentError("runtime-finished", "createAgentRuntime: `finish` was already called.");
|
|
2412
2486
|
clearTimeout(abortTimer);
|
|
2413
2487
|
if ((pendingAbort !== void 0 || abortApplied) && current?.status === "active") abortNow();
|
|
2414
|
-
|
|
2488
|
+
const journaledUsage = /* @__PURE__ */ new Set();
|
|
2489
|
+
for (;;) {
|
|
2490
|
+
await drainJournal();
|
|
2491
|
+
const usage = mailbox.filter((event) => event.type === "@agent.usage" && !journaledUsage.has(event));
|
|
2492
|
+
if (usage.length === 0) break;
|
|
2493
|
+
for (const event of usage) {
|
|
2494
|
+
journaledUsage.add(event);
|
|
2495
|
+
appendLogEntry(event);
|
|
2496
|
+
}
|
|
2497
|
+
}
|
|
2415
2498
|
const snapshot = current;
|
|
2416
2499
|
let outcome;
|
|
2417
2500
|
if (stopReason !== void 0) outcome = {
|
|
@@ -2464,6 +2547,7 @@ function createAgentRuntime(machine, options = {}) {
|
|
|
2464
2547
|
return persistedSnapshot;
|
|
2465
2548
|
};
|
|
2466
2549
|
finished = true;
|
|
2550
|
+
flushJournal();
|
|
2467
2551
|
releaseAllDeliveries();
|
|
2468
2552
|
const journalAtSettle = journalChain;
|
|
2469
2553
|
const result = {
|
package/dist/index.cjs
CHANGED
|
@@ -3,7 +3,7 @@ const require_event_log = require("./event-log-Dkc-yIYu.cjs");
|
|
|
3
3
|
const require_decision = require("./decision-CMeuNZ1g.cjs");
|
|
4
4
|
const require_act = require("./act-CrX0JwWY.cjs");
|
|
5
5
|
const require_setup_agent = require("./setup-agent-CmEToB8y.cjs");
|
|
6
|
-
const require_effects = require("./effects-
|
|
6
|
+
const require_effects = require("./effects-DDseYtJk.cjs");
|
|
7
7
|
const require_event_log_store = require("./event-log-store-Cl-YWDnq.cjs");
|
|
8
8
|
let xstate = require("xstate");
|
|
9
9
|
let acorn = require("acorn");
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { A as UserMessage, C as StandardSchemaV1, D as ToolMessage, E as ToolCallPart, O as ToolResultOutput, S as ProviderOptions, T as TextPart, _ as FilePart, a as AgentToolChoice, b as InferOutput, c as AgentToolSchema, d as AllowedEvents, f as AssistantMessage, g as EventUnion, h as EventPayload, i as AgentTool, j as WithAgentInputSchema, k as ToolResultPart, l as AgentTools, m as DataContent, n as AgentEventSchemaInputMap, o as AgentToolDescriptor, p as ChosenEvent, r as AgentMessage, s as AgentToolExecute, t as AgentEventSchemaInput, u as AllowedEventPattern, v as ImagePart, w as SystemMessage, x as NormalizedEventSchemas, y as InferInput } from "./types-DQUOOaZO.cjs";
|
|
2
2
|
import { $ as AgentRequestOptions, A as AgentActInput, B as DecisionAttempt, C as getAgentOutputMode, D as parseProviderOutput, E as parseOutput, F as AgentDecisionOption, G as createDecisionRequest, H as DecisionLogicConfig, I as AgentDecisionRejection, J as DecisionStrategy, K as renderDecisionAttempts, L as AgentDecisionRequest, M as AgentDecisionExecutor, N as AgentDecisionExhaustedError, O as providerOutputSchema, P as AgentDecisionInput, Q as AgentInvalidEventPayloadError, R as AgentExecutorDecisionRequest, S as createTextLogic, T as getCallUsage, U as ResolveDecisionOptions, V as DecisionLogic, W as createDecisionLogic, X as MAX_FINITE_PAYLOADS, Y as GROUPED_EVENT_THRESHOLD, Z as AgentEventDescriptor, _ as TextLogic, a as AgentModelRef, at as AgentError, b as TextLogicExecutor, c as AgentRequestExecutorInfo, d as AgentRequestMode, et as AgentRequestSource, f as AgentTextRequest, g as ProviderStructuredOutput, h as BuiltinAgentActors, i as AgentModelMap, it as parseAgentEvent, j as DEFAULT_ACT_MAX_STEPS, k as ACT_STATE_EXITED, l as AgentRequestExecutorResult, m as AgentUsage, n as AgentExecutorTextRequest, nt as EventFromSnapshot, o as AgentOutputMode, ot as AgentTruncatedError, p as AgentTextResult, q as resolveDecision, r as AgentFinishReason, rt as getAcceptedEvents, s as AgentRequestExecutor, t as AgentCallUsage, tt as AgentSchemas, u as AgentRequestExecutors, v as TextLogicConfig, w as getCallFinishReason, x as bindRequestExecutor, y as TextLogicExecuteArgs, z as CreateDecisionRequestOptions } from "./text-logic-CSf9bqpP.cjs";
|
|
3
|
-
import { n as AgentUsageEvent, t as AGENT_USAGE_EVENT_TYPE } from "./usage-
|
|
4
|
-
import { C as AgentInteractionEvent, D as eventFromInteraction, E as GetInteractionOptions, O as getInteraction, S as AgentInteractionDescriptor, T as AgentInteractionMeta, _ as FromConfigOptions, a as WithAgentEvents, b as AgentInteraction, c as getAgentSchemas, d as AgentWorkflowActorConfig, f as AgentWorkflowConfig, g as AgentWorkflowTransitionConfig, h as AgentWorkflowStateConfig, i as SetupAgentResult, k as interactionMetaSchema, l as setupAgent, m as AgentWorkflowRequestConfig, n as AgentSchemaPack, o as WithAgentUsageEvent, p as AgentWorkflowInvokeConfig, r as AgentUsageEventPayload, s as createAgentSchemas, t as AgentDefaultMeta, u as AgentWorkflowActionConfig, v as FromConfigResult, w as AgentInteractionEventMeta, x as AgentInteractionChoice, y as SchemaCompiler } from "./setup-agent-
|
|
5
|
-
import { A as AgentStepRequest, C as inspectTransitions, D as serializeTraceEvent, E as runToQuiescence, O as traceTransitions, S as createAgentRuntime, T as runAgent, _ as AgentTraceEvent, a as AgentMaxModelCallsExceededError, b as JsonSerializableTraceEvent, c as AgentRunMeta, d as AgentRunStart, f as AgentRuntime, g as AgentTimerScheduler, h as AgentTimerEvent, i as AgentInputFrom, k as AgentRequest, l as AgentRunOptions, m as AgentSnapshotDivergedError, n as AgentEffects, o as AgentRunErrorCause, p as AgentRuntimeOptions, r as AgentInbox, s as AgentRunInit, t as AGENT_TRACE_SCHEMA_VERSION, u as AgentRunResult, v as AgentTransitionHandler, w as isAgentIdle, x as createAgentInbox, y as InspectedActorRef } from "./run-agent-
|
|
3
|
+
import { n as AgentUsageEvent, t as AGENT_USAGE_EVENT_TYPE } from "./usage-Bm5nvpow.cjs";
|
|
4
|
+
import { C as AgentInteractionEvent, D as eventFromInteraction, E as GetInteractionOptions, O as getInteraction, S as AgentInteractionDescriptor, T as AgentInteractionMeta, _ as FromConfigOptions, a as WithAgentEvents, b as AgentInteraction, c as getAgentSchemas, d as AgentWorkflowActorConfig, f as AgentWorkflowConfig, g as AgentWorkflowTransitionConfig, h as AgentWorkflowStateConfig, i as SetupAgentResult, k as interactionMetaSchema, l as setupAgent, m as AgentWorkflowRequestConfig, n as AgentSchemaPack, o as WithAgentUsageEvent, p as AgentWorkflowInvokeConfig, r as AgentUsageEventPayload, s as createAgentSchemas, t as AgentDefaultMeta, u as AgentWorkflowActionConfig, v as FromConfigResult, w as AgentInteractionEventMeta, x as AgentInteractionChoice, y as SchemaCompiler } from "./setup-agent-BaNyz6Q3.cjs";
|
|
5
|
+
import { A as AgentStepRequest, C as inspectTransitions, D as serializeTraceEvent, E as runToQuiescence, O as traceTransitions, S as createAgentRuntime, T as runAgent, _ as AgentTraceEvent, a as AgentMaxModelCallsExceededError, b as JsonSerializableTraceEvent, c as AgentRunMeta, d as AgentRunStart, f as AgentRuntime, g as AgentTimerScheduler, h as AgentTimerEvent, i as AgentInputFrom, k as AgentRequest, l as AgentRunOptions, m as AgentSnapshotDivergedError, n as AgentEffects, o as AgentRunErrorCause, p as AgentRuntimeOptions, r as AgentInbox, s as AgentRunInit, t as AGENT_TRACE_SCHEMA_VERSION, u as AgentRunResult, v as AgentTransitionHandler, w as isAgentIdle, x as createAgentInbox, y as InspectedActorRef } from "./run-agent-30mH2moE.cjs";
|
|
6
6
|
import { c as AgentLogEntry, d as AgentMachineVersionMismatchError, h as JsonValue, n as AgentEventLogStore, t as AgentEventLogConflictError } from "./event-log-store-bc4ICGcS.cjs";
|
|
7
7
|
import { n as PresetMachine } from "./internal-C3Lqu538.cjs";
|
|
8
8
|
import { M as Recorder, a as getMachineStructuralHash, c as getStatePath, d as toolMessage, f as userMessage, i as getJsonSchemaSync, l as isStandardSchema, n as assistantMessage, o as getMessageText, r as getJsonSchema, s as getStateMeta, t as MetaOfSnapshot, u as systemMessage } from "./utils-7lSa4H-i.cjs";
|
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { A as UserMessage, C as StandardSchemaV1, D as ToolMessage, E as ToolCallPart, O as ToolResultOutput, S as ProviderOptions, T as TextPart, _ as FilePart, a as AgentToolChoice, b as InferOutput, c as AgentToolSchema, d as AllowedEvents, f as AssistantMessage, g as EventUnion, h as EventPayload, i as AgentTool, j as WithAgentInputSchema, k as ToolResultPart, l as AgentTools, m as DataContent, n as AgentEventSchemaInputMap, o as AgentToolDescriptor, p as ChosenEvent, r as AgentMessage, s as AgentToolExecute, t as AgentEventSchemaInput, u as AllowedEventPattern, v as ImagePart, w as SystemMessage, x as NormalizedEventSchemas, y as InferInput } from "./types-DQUOOaZO.mjs";
|
|
2
2
|
import { $ as AgentRequestOptions, A as AgentActInput, B as DecisionAttempt, C as getAgentOutputMode, D as parseProviderOutput, E as parseOutput, F as AgentDecisionOption, G as createDecisionRequest, H as DecisionLogicConfig, I as AgentDecisionRejection, J as DecisionStrategy, K as renderDecisionAttempts, L as AgentDecisionRequest, M as AgentDecisionExecutor, N as AgentDecisionExhaustedError, O as providerOutputSchema, P as AgentDecisionInput, Q as AgentInvalidEventPayloadError, R as AgentExecutorDecisionRequest, S as createTextLogic, T as getCallUsage, U as ResolveDecisionOptions, V as DecisionLogic, W as createDecisionLogic, X as MAX_FINITE_PAYLOADS, Y as GROUPED_EVENT_THRESHOLD, Z as AgentEventDescriptor, _ as TextLogic, a as AgentModelRef, at as AgentError, b as TextLogicExecutor, c as AgentRequestExecutorInfo, d as AgentRequestMode, et as AgentRequestSource, f as AgentTextRequest, g as ProviderStructuredOutput, h as BuiltinAgentActors, i as AgentModelMap, it as parseAgentEvent, j as DEFAULT_ACT_MAX_STEPS, k as ACT_STATE_EXITED, l as AgentRequestExecutorResult, m as AgentUsage, n as AgentExecutorTextRequest, nt as EventFromSnapshot, o as AgentOutputMode, ot as AgentTruncatedError, p as AgentTextResult, q as resolveDecision, r as AgentFinishReason, rt as getAcceptedEvents, s as AgentRequestExecutor, t as AgentCallUsage, tt as AgentSchemas, u as AgentRequestExecutors, v as TextLogicConfig, w as getCallFinishReason, x as bindRequestExecutor, y as TextLogicExecuteArgs, z as CreateDecisionRequestOptions } from "./text-logic-BqxalgMr.mjs";
|
|
3
|
-
import { n as AgentUsageEvent, t as AGENT_USAGE_EVENT_TYPE } from "./usage-
|
|
4
|
-
import { C as AgentInteractionEvent, D as eventFromInteraction, E as GetInteractionOptions, O as getInteraction, S as AgentInteractionDescriptor, T as AgentInteractionMeta, _ as FromConfigOptions, a as WithAgentEvents, b as AgentInteraction, c as getAgentSchemas, d as AgentWorkflowActorConfig, f as AgentWorkflowConfig, g as AgentWorkflowTransitionConfig, h as AgentWorkflowStateConfig, i as SetupAgentResult, k as interactionMetaSchema, l as setupAgent, m as AgentWorkflowRequestConfig, n as AgentSchemaPack, o as WithAgentUsageEvent, p as AgentWorkflowInvokeConfig, r as AgentUsageEventPayload, s as createAgentSchemas, t as AgentDefaultMeta, u as AgentWorkflowActionConfig, v as FromConfigResult, w as AgentInteractionEventMeta, x as AgentInteractionChoice, y as SchemaCompiler } from "./setup-agent-
|
|
5
|
-
import { A as AgentStepRequest, C as inspectTransitions, D as serializeTraceEvent, E as runToQuiescence, O as traceTransitions, S as createAgentRuntime, T as runAgent, _ as AgentTraceEvent, a as AgentMaxModelCallsExceededError, b as JsonSerializableTraceEvent, c as AgentRunMeta, d as AgentRunStart, f as AgentRuntime, g as AgentTimerScheduler, h as AgentTimerEvent, i as AgentInputFrom, k as AgentRequest, l as AgentRunOptions, m as AgentSnapshotDivergedError, n as AgentEffects, o as AgentRunErrorCause, p as AgentRuntimeOptions, r as AgentInbox, s as AgentRunInit, t as AGENT_TRACE_SCHEMA_VERSION, u as AgentRunResult, v as AgentTransitionHandler, w as isAgentIdle, x as createAgentInbox, y as InspectedActorRef } from "./run-agent-
|
|
3
|
+
import { n as AgentUsageEvent, t as AGENT_USAGE_EVENT_TYPE } from "./usage-BnikdOca.mjs";
|
|
4
|
+
import { C as AgentInteractionEvent, D as eventFromInteraction, E as GetInteractionOptions, O as getInteraction, S as AgentInteractionDescriptor, T as AgentInteractionMeta, _ as FromConfigOptions, a as WithAgentEvents, b as AgentInteraction, c as getAgentSchemas, d as AgentWorkflowActorConfig, f as AgentWorkflowConfig, g as AgentWorkflowTransitionConfig, h as AgentWorkflowStateConfig, i as SetupAgentResult, k as interactionMetaSchema, l as setupAgent, m as AgentWorkflowRequestConfig, n as AgentSchemaPack, o as WithAgentUsageEvent, p as AgentWorkflowInvokeConfig, r as AgentUsageEventPayload, s as createAgentSchemas, t as AgentDefaultMeta, u as AgentWorkflowActionConfig, v as FromConfigResult, w as AgentInteractionEventMeta, x as AgentInteractionChoice, y as SchemaCompiler } from "./setup-agent-C1CG_nfX.mjs";
|
|
5
|
+
import { A as AgentStepRequest, C as inspectTransitions, D as serializeTraceEvent, E as runToQuiescence, O as traceTransitions, S as createAgentRuntime, T as runAgent, _ as AgentTraceEvent, a as AgentMaxModelCallsExceededError, b as JsonSerializableTraceEvent, c as AgentRunMeta, d as AgentRunStart, f as AgentRuntime, g as AgentTimerScheduler, h as AgentTimerEvent, i as AgentInputFrom, k as AgentRequest, l as AgentRunOptions, m as AgentSnapshotDivergedError, n as AgentEffects, o as AgentRunErrorCause, p as AgentRuntimeOptions, r as AgentInbox, s as AgentRunInit, t as AGENT_TRACE_SCHEMA_VERSION, u as AgentRunResult, v as AgentTransitionHandler, w as isAgentIdle, x as createAgentInbox, y as InspectedActorRef } from "./run-agent-DlPzBWj-.mjs";
|
|
6
6
|
import { c as AgentLogEntry, d as AgentMachineVersionMismatchError, h as JsonValue, n as AgentEventLogStore, t as AgentEventLogConflictError } from "./event-log-store-BBS8so8a.mjs";
|
|
7
7
|
import { n as PresetMachine } from "./internal-DUcdhk-i.mjs";
|
|
8
8
|
import { M as Recorder, a as getMachineStructuralHash, c as getStatePath, d as toolMessage, f as userMessage, i as getJsonSchemaSync, l as isStandardSchema, n as assistantMessage, o as getMessageText, r as getJsonSchema, s as getStateMeta, t as MetaOfSnapshot, u as systemMessage } from "./utils-CBbKw2fM.mjs";
|
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { $ as getJsonSchema, B as parseOutput, F as getCallFinishReason, G as ex
|
|
|
2
2
|
import { a as createDecisionRequest, c as renderDecisionAttempts, d as GROUPED_EVENT_THRESHOLD, f as MAX_FINITE_PAYLOADS, h as getAcceptedEvents, i as createDecisionLogic, m as AgentInvalidEventPayloadError, s as isDecisionLogic, t as AgentDecisionExhaustedError, u as resolveDecision, v as parseAgentEvent } from "./decision-m5hGmHpF.mjs";
|
|
3
3
|
import { i as isActLogic, n as DEFAULT_ACT_MAX_STEPS, t as ACT_STATE_EXITED } from "./act-B9hLQls6.mjs";
|
|
4
4
|
import { n as getAgentSchemas, r as setupAgent, t as createAgentSchemas } from "./setup-agent-BDmNr6PC.mjs";
|
|
5
|
-
import { _ as runToQuiescence, a as AgentSnapshotDivergedError, b as traceTransitions, c as bindDecisionForProvide, d as createAgentRuntime, f as getConfiguredInvokeSrcs, g as runAgent, h as isStateMachineLogic, i as AgentMaxModelCallsExceededError, l as bindTextForProvide, m as isAgentIdle, n as mapEffects, o as bindActForProvide, p as inspectTransitions, r as AGENT_TRACE_SCHEMA_VERSION, s as bindChildMachineForProvide, t as isAsyncIterable, u as createAgentInbox, v as serializeTraceEvent, x as decideNext, y as toJsonValue } from "./effects-
|
|
5
|
+
import { _ as runToQuiescence, a as AgentSnapshotDivergedError, b as traceTransitions, c as bindDecisionForProvide, d as createAgentRuntime, f as getConfiguredInvokeSrcs, g as runAgent, h as isStateMachineLogic, i as AgentMaxModelCallsExceededError, l as bindTextForProvide, m as isAgentIdle, n as mapEffects, o as bindActForProvide, p as inspectTransitions, r as AGENT_TRACE_SCHEMA_VERSION, s as bindChildMachineForProvide, t as isAsyncIterable, u as createAgentInbox, v as serializeTraceEvent, x as decideNext, y as toJsonValue } from "./effects-BT_cSY0j.mjs";
|
|
6
6
|
import { t as AgentEventLogConflictError } from "./event-log-store-Brx9tOHt.mjs";
|
|
7
7
|
import { createAsyncLogic, machineToJSON } from "xstate";
|
|
8
8
|
import { parse } from "acorn";
|
package/dist/otel.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as AgentTraceEvent } from "./run-agent-
|
|
1
|
+
import { _ as AgentTraceEvent } from "./run-agent-30mH2moE.cjs";
|
|
2
2
|
import { Attributes, Tracer, TracerProvider } from "@opentelemetry/api";
|
|
3
3
|
//#region src/otel/index.d.ts
|
|
4
4
|
/** Options for {@link createOtelTraceHandler}. */
|
package/dist/otel.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as AgentTraceEvent } from "./run-agent-
|
|
1
|
+
import { _ as AgentTraceEvent } from "./run-agent-DlPzBWj-.mjs";
|
|
2
2
|
import { Attributes, Tracer, TracerProvider } from "@opentelemetry/api";
|
|
3
3
|
//#region src/otel/index.d.ts
|
|
4
4
|
/** Options for {@link createOtelTraceHandler}. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { C as StandardSchemaV1, j as WithAgentInputSchema, l as AgentTools, y as InferInput } from "./types-DQUOOaZO.cjs";
|
|
2
2
|
import { B as DecisionAttempt, L as AgentDecisionRequest, Z as AgentEventDescriptor, at as AgentError, d as AgentRequestMode, et as AgentRequestSource, f as AgentTextRequest, m as AgentUsage, r as AgentFinishReason, t as AgentCallUsage, u as AgentRequestExecutors } from "./text-logic-CSf9bqpP.cjs";
|
|
3
|
-
import { n as AgentUsageEvent } from "./usage-
|
|
3
|
+
import { n as AgentUsageEvent } from "./usage-Bm5nvpow.cjs";
|
|
4
4
|
import { c as AgentLogEntry, h as JsonValue$1, n as AgentEventLogStore } from "./event-log-store-bc4ICGcS.cjs";
|
|
5
5
|
import { AnyActorLogic, AnyActorRef, AnyMachineSnapshot, AnyStateMachine, AsyncActorLogic, EmittedFrom, EventFromLogic, EventObject, InputFrom, InspectionEvent, OutputFrom, Snapshot, SnapshotFrom, StateValue } from "xstate";
|
|
6
6
|
import { DurableExecution } from "xstate/durable";
|
|
@@ -684,7 +684,7 @@ interface AgentRunOptions<TMachine extends AnyStateMachine> extends AgentRuntime
|
|
|
684
684
|
*/
|
|
685
685
|
onIdle?: (snapshot: SnapshotFrom<TMachine>, options: {
|
|
686
686
|
signal: AbortSignal | undefined;
|
|
687
|
-
}) => Promise<EventFromLogic<TMachine
|
|
687
|
+
}) => Promise<EventFromLogic<TMachine> | AgentTimerEvent>;
|
|
688
688
|
/**
|
|
689
689
|
* A send handle for events pushed mid-run (a cancel, a user message), from
|
|
690
690
|
* {@link createAgentInbox}. Each `inbox.send` goes to the current pass's
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { C as StandardSchemaV1, j as WithAgentInputSchema, l as AgentTools, y as InferInput } from "./types-DQUOOaZO.mjs";
|
|
2
2
|
import { B as DecisionAttempt, L as AgentDecisionRequest, Z as AgentEventDescriptor, at as AgentError, d as AgentRequestMode, et as AgentRequestSource, f as AgentTextRequest, m as AgentUsage, r as AgentFinishReason, t as AgentCallUsage, u as AgentRequestExecutors } from "./text-logic-BqxalgMr.mjs";
|
|
3
|
-
import { n as AgentUsageEvent } from "./usage-
|
|
3
|
+
import { n as AgentUsageEvent } from "./usage-BnikdOca.mjs";
|
|
4
4
|
import { c as AgentLogEntry, h as JsonValue$1, n as AgentEventLogStore } from "./event-log-store-BBS8so8a.mjs";
|
|
5
5
|
import { AnyActorLogic, AnyActorRef, AnyMachineSnapshot, AnyStateMachine, AsyncActorLogic, EmittedFrom, EventFromLogic, EventObject, InputFrom, InspectionEvent, OutputFrom, Snapshot, SnapshotFrom, StateValue } from "xstate";
|
|
6
6
|
import { DurableExecution } from "xstate/durable";
|
|
@@ -684,7 +684,7 @@ interface AgentRunOptions<TMachine extends AnyStateMachine> extends AgentRuntime
|
|
|
684
684
|
*/
|
|
685
685
|
onIdle?: (snapshot: SnapshotFrom<TMachine>, options: {
|
|
686
686
|
signal: AbortSignal | undefined;
|
|
687
|
-
}) => Promise<EventFromLogic<TMachine
|
|
687
|
+
}) => Promise<EventFromLogic<TMachine> | AgentTimerEvent>;
|
|
688
688
|
/**
|
|
689
689
|
* A send handle for events pushed mid-run (a cancel, a user message), from
|
|
690
690
|
* {@link createAgentInbox}. Each `inbox.send` goes to the current pass's
|