@statelyai/agent 2.0.0-alpha.18 → 2.0.0-alpha.19
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/dist/ai-sdk.cjs +4 -2
- package/dist/ai-sdk.d.cts +1 -1
- package/dist/ai-sdk.d.mts +1 -1
- package/dist/ai-sdk.mjs +3 -2
- package/dist/{decision-C11xuud2.mjs → decision-DsIkEuHz.mjs} +48 -28
- package/dist/{decision-DnQCQPew.cjs → decision-t26zsnSR.cjs} +64 -43
- package/dist/{event-log-store-CQJq8_v4.d.cts → event-log-store-Bz7HDBkE.d.cts} +11 -12
- package/dist/{event-log-store-B-1fcfkT.mjs → event-log-store-DmIDosD6.mjs} +22 -14
- package/dist/{event-log-store-yquOV1TX.cjs → event-log-store-a_TKy1gk.cjs} +22 -14
- package/dist/{event-log-store-BrC9Q1xW.d.mts → event-log-store-hrA1vqtN.d.mts} +11 -12
- package/dist/index.cjs +265 -109
- package/dist/index.d.cts +136 -80
- package/dist/index.d.mts +136 -80
- package/dist/index.mjs +262 -107
- package/dist/machines.cjs +13 -17
- package/dist/machines.d.cts +14 -17
- package/dist/machines.d.mts +14 -17
- package/dist/machines.mjs +13 -17
- package/dist/otel.cjs +1 -0
- package/dist/otel.d.cts +1 -1
- package/dist/otel.d.mts +1 -1
- package/dist/{run-agent-r9OD4z8F.d.cts → run-agent--4bbms-D.d.cts} +121 -48
- package/dist/{run-agent-DQIDikfd.d.mts → run-agent-CwmzAZwj.d.mts} +121 -48
- package/dist/{setup-agent-C3ETi_HZ.cjs → setup-agent-BFA4VKpN.cjs} +31 -33
- package/dist/{setup-agent-BrE2zFDy.mjs → setup-agent-CPFPN06s.mjs} +31 -28
- package/dist/sqlite.cjs +3 -9
- package/dist/sqlite.d.cts +1 -1
- package/dist/sqlite.d.mts +1 -1
- package/dist/sqlite.mjs +3 -9
- package/dist/{text-logic-VcWqO-Cl.d.cts → text-logic-Cavva1W6.d.cts} +24 -8
- package/dist/{text-logic-RvnlD-An.d.mts → text-logic-Er5KkTX6.d.mts} +24 -8
- package/dist/validate.cjs +436 -0
- package/dist/validate.d.cts +31 -0
- package/dist/validate.d.mts +31 -0
- package/dist/validate.mjs +411 -0
- package/package.json +15 -1
- package/schemas/agent-workflow.json +2 -2
- package/skills/generate-machine/SKILL.md +12 -14
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const require_errors = require("./errors-DUBBzRLP.cjs");
|
|
2
|
-
const require_decision = require("./decision-
|
|
3
|
-
const require_event_log_store = require("./event-log-store-
|
|
2
|
+
const require_decision = require("./decision-t26zsnSR.cjs");
|
|
3
|
+
const require_event_log_store = require("./event-log-store-a_TKy1gk.cjs");
|
|
4
|
+
require("./validate.cjs");
|
|
4
5
|
let xstate = require("xstate");
|
|
5
6
|
//#region src/messages.ts
|
|
6
7
|
function addMessages(resolve) {
|
|
@@ -221,7 +222,7 @@ function resolveAgentStep(machine, step, request, output, options) {
|
|
|
221
222
|
return createAgentStep(machine, snapshot, actions, require_decision.getRegisteredAgentExecutionOptions(machine, options));
|
|
222
223
|
}
|
|
223
224
|
async function executeAgentRequest(requestOrEffect, executors) {
|
|
224
|
-
if (requestOrEffect.kind === "decision") throw new Error("executeAgentRequest(...) is text-only. Resolve a 'decision' request with resolveDecision(request, executors
|
|
225
|
+
if (requestOrEffect.kind === "decision") throw new Error("executeAgentRequest(...) is text-only. Resolve a 'decision' request with resolveDecision(request, executors, ...) instead.");
|
|
225
226
|
const request = "requestId" in requestOrEffect ? {
|
|
226
227
|
kind: "text",
|
|
227
228
|
id: requestOrEffect.requestId,
|
|
@@ -335,7 +336,7 @@ const AGENT_USAGE_EVENT_TYPE = "@agent.usage";
|
|
|
335
336
|
function createReplayEntry(machine, entries, event, options = {}) {
|
|
336
337
|
const index = entries.length;
|
|
337
338
|
const machineId = machine.config.id ?? machine.id ?? "(machine)";
|
|
338
|
-
const machineVersion = options.machineVersion ?? require_decision.
|
|
339
|
+
const machineVersion = options.machineVersion ?? require_decision.resolveMachineVersion(machine);
|
|
339
340
|
const entry = {
|
|
340
341
|
schemaVersion: 1,
|
|
341
342
|
id: options.id ?? `evt_${String(index).padStart(8, "0")}`,
|
|
@@ -631,7 +632,7 @@ function validateReplayEntries(entries, expected, label) {
|
|
|
631
632
|
function replay(machine, entries, options = {}) {
|
|
632
633
|
validateReplayEntries(entries, {
|
|
633
634
|
machineId: machine.config.id ?? machine.id ?? "(machine)",
|
|
634
|
-
machineVersion: options.machineVersion ?? require_decision.
|
|
635
|
+
machineVersion: options.machineVersion ?? require_decision.resolveMachineVersion(machine)
|
|
635
636
|
}, "Replay entries");
|
|
636
637
|
const events = toEvents(entries);
|
|
637
638
|
const initOffset = events[0]?.type === "@agent.init" ? 1 : 0;
|
|
@@ -661,13 +662,6 @@ function replay(machine, entries, options = {}) {
|
|
|
661
662
|
effects
|
|
662
663
|
};
|
|
663
664
|
}
|
|
664
|
-
/** Requires and checks every entry's recorded state/effect hashes. */
|
|
665
|
-
function verifyReplay(machine, entries, options = {}) {
|
|
666
|
-
return replay(machine, entries, {
|
|
667
|
-
...options,
|
|
668
|
-
verify: "strict"
|
|
669
|
-
});
|
|
670
|
-
}
|
|
671
665
|
/** Structural event-tail, logical-state, and owed-effect comparison. */
|
|
672
666
|
function diffEventLogs(machine, parentEntries, forkEntries, options = {}) {
|
|
673
667
|
let commonLength = 0;
|
|
@@ -1135,14 +1129,14 @@ function collectDeclaredStateTags(states, tags = /* @__PURE__ */ new Set()) {
|
|
|
1135
1129
|
}
|
|
1136
1130
|
return tags;
|
|
1137
1131
|
}
|
|
1138
|
-
function
|
|
1139
|
-
if (options.
|
|
1140
|
-
const
|
|
1141
|
-
if (!
|
|
1132
|
+
function resolveIdlePredicate(config, options) {
|
|
1133
|
+
if (options.isIdle) return options.isIdle;
|
|
1134
|
+
const idleTags = config.idleTags ?? [];
|
|
1135
|
+
if (!idleTags.length) return;
|
|
1142
1136
|
const declaredTags = collectDeclaredStateTags(config.states);
|
|
1143
|
-
const unknown =
|
|
1144
|
-
if (unknown.length) throw new Error(`setupAgent.fromConfig: '
|
|
1145
|
-
return (snapshot) =>
|
|
1137
|
+
const unknown = idleTags.filter((tag) => !declaredTags.has(tag));
|
|
1138
|
+
if (unknown.length) throw new Error(`setupAgent.fromConfig: 'idleTags' lists ${unknown.map((tag) => `'${tag}'`).join(", ")}, which no state declares in its 'tags'. Tag the waiting state(s) — e.g. "tags": ["${unknown[0]}"] — or remove the entry.`);
|
|
1139
|
+
return (snapshot) => idleTags.some((tag) => snapshot.hasTag(tag));
|
|
1146
1140
|
}
|
|
1147
1141
|
function setupAgentFromConfig(config, options) {
|
|
1148
1142
|
if (!options || typeof options.compileSchema !== "function") throw new Error("setupAgent.fromConfig(...) requires a 'compileSchema' option: { compileSchema: (jsonSchema, name) => StandardSchemaV1 }. Bring your own JSON Schema engine (Ajv, @cfworker/json-schema, a compiled-Zod-from-JSON-Schema pipeline, ...). Core intentionally ships no JSON Schema engine.");
|
|
@@ -1174,8 +1168,8 @@ function setupAgentFromConfig(config, options) {
|
|
|
1174
1168
|
models: {}
|
|
1175
1169
|
});
|
|
1176
1170
|
if (machine.config) require_decision.machineStaticTransitionTargets.set(machine.config, translation.transitionTargets);
|
|
1177
|
-
const
|
|
1178
|
-
if (
|
|
1171
|
+
const isIdle = resolveIdlePredicate(config, options);
|
|
1172
|
+
if (isIdle && machine.config) require_decision.machineIdlePredicates.set(machine.config, isIdle);
|
|
1179
1173
|
return {
|
|
1180
1174
|
machine,
|
|
1181
1175
|
schemas
|
|
@@ -1389,9 +1383,9 @@ function setupAgent(config) {
|
|
|
1389
1383
|
assertStateSchemaKeysExist(config.states, machineConfig?.states);
|
|
1390
1384
|
const machine = createBaseMachine(withRootOutputFromSingleFinal(machineConfig));
|
|
1391
1385
|
require_decision.agentExecutionOptions.set(machine, machineOptions);
|
|
1392
|
-
if (config.
|
|
1386
|
+
if (config.isIdle) {
|
|
1393
1387
|
const rootConfig = machine.config;
|
|
1394
|
-
if (rootConfig) require_decision.
|
|
1388
|
+
if (rootConfig) require_decision.machineIdlePredicates.set(rootConfig, config.isIdle);
|
|
1395
1389
|
}
|
|
1396
1390
|
return machine;
|
|
1397
1391
|
},
|
|
@@ -1482,13 +1476,22 @@ const RESERVED_AGENT_ACTOR_KEYS = [
|
|
|
1482
1476
|
require_decision.DECIDE_ACTOR
|
|
1483
1477
|
];
|
|
1484
1478
|
/**
|
|
1479
|
+
* The whole `agent.` actor-source namespace is reserved for the library, not
|
|
1480
|
+
* just the shipped builtins: a key starting with this prefix is rejected at
|
|
1481
|
+
* setup time so a future builtin can never collide with (or be shadowed by) a
|
|
1482
|
+
* user source. Name your own sources without it.
|
|
1483
|
+
*/
|
|
1484
|
+
const RESERVED_AGENT_KEY_PREFIX = "agent.";
|
|
1485
|
+
/**
|
|
1485
1486
|
* Runtime guards over the user-supplied `actors`/`requests` keys, in one walk
|
|
1486
1487
|
* of both groups:
|
|
1487
1488
|
*
|
|
1488
|
-
* 1. A key in the reserved `agent
|
|
1489
|
-
*
|
|
1490
|
-
* key overwrite the builtin
|
|
1491
|
-
*
|
|
1489
|
+
* 1. A key in the reserved `agent.` namespace is rejected — every key with
|
|
1490
|
+
* that prefix, not only today's builtins. Without this, the builtins-first
|
|
1491
|
+
* spread in {@link createAgentActors} lets such a key overwrite the builtin
|
|
1492
|
+
* (`agent.decide`, …) silently, and a builtin added later would start
|
|
1493
|
+
* colliding with user code. Deliberate override of a builtin is still
|
|
1494
|
+
* possible after the machine is created, via
|
|
1492
1495
|
* `machine.provide({ actors: { 'agent.decide': ... } })`.
|
|
1493
1496
|
* 2. A key appearing in BOTH groups is almost certainly a mistake (whichever
|
|
1494
1497
|
* spread applies last would silently win) — fail fast with a clear message
|
|
@@ -1499,6 +1502,7 @@ function assertActorKeys(actors, requests) {
|
|
|
1499
1502
|
const groups = [["actors", actors], ["requests", requests]];
|
|
1500
1503
|
for (const [groupName, group] of groups) for (const key of Object.keys(group ?? {})) {
|
|
1501
1504
|
if (RESERVED_AGENT_ACTOR_KEYS.some((reserved) => reserved === key)) throw new Error(`setupAgent: '${groupName}' key '${key}' is a reserved builtin agent actor and cannot be redefined here (it would silently clobber the builtin). Reserved keys: ${RESERVED_AGENT_ACTOR_KEYS.join(", ")}. To deliberately override a builtin, do it on the created machine instead: machine.provide({ actors: { '${key}': ... } }).`);
|
|
1505
|
+
if (key.startsWith(RESERVED_AGENT_KEY_PREFIX)) throw new Error(`setupAgent: '${groupName}' key '${key}' uses the reserved '${RESERVED_AGENT_KEY_PREFIX}' namespace, which belongs to the library (${RESERVED_AGENT_ACTOR_KEYS.join(", ")}, and anything added later). Rename it without the '${RESERVED_AGENT_KEY_PREFIX}' prefix.`);
|
|
1502
1506
|
const existingGroup = seenIn.get(key);
|
|
1503
1507
|
if (existingGroup) throw new Error(`setupAgent: key '${key}' is defined in both '${existingGroup}' and '${groupName}'. Each actor source key must be unique across 'actors' and 'requests'.`);
|
|
1504
1508
|
seenIn.set(key, groupName);
|
|
@@ -1635,9 +1639,3 @@ Object.defineProperty(exports, "validateReplayEntries", {
|
|
|
1635
1639
|
return validateReplayEntries;
|
|
1636
1640
|
}
|
|
1637
1641
|
});
|
|
1638
|
-
Object.defineProperty(exports, "verifyReplay", {
|
|
1639
|
-
enumerable: true,
|
|
1640
|
-
get: function() {
|
|
1641
|
-
return verifyReplay;
|
|
1642
|
-
}
|
|
1643
|
-
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as AgentError } from "./errors-CeSXQx0v.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { a as assertJsonSerializable, i as assertAgentLogEntry } from "./event-log-store-
|
|
2
|
+
import { F as djb2Hex, M as machineStaticTransitionTargets, N as missingActor, T as agentExecutionOptions, U as resolveMachineVersion, d as USER_INPUT_ACTOR, g as executeAgentTextRequest, h as createTextLogic, j as machineIdlePredicates, k as getRegisteredAgentExecutionOptions, l as DECIDE_ACTOR, m as builtinTextActors, n as createDecideActor, o as getAcceptedEvents, q as validateSchemaSync, r as isDecisionLogic, w as userInputActor, y as isTextLogic } from "./decision-DsIkEuHz.mjs";
|
|
3
|
+
import { a as assertJsonSerializable, i as assertAgentLogEntry } from "./event-log-store-DmIDosD6.mjs";
|
|
4
4
|
import { createMachineFromConfig, initialTransition, setup, transition } from "xstate";
|
|
5
5
|
//#region src/messages.ts
|
|
6
6
|
function addMessages(resolve) {
|
|
@@ -221,7 +221,7 @@ function resolveAgentStep(machine, step, request, output, options) {
|
|
|
221
221
|
return createAgentStep(machine, snapshot, actions, getRegisteredAgentExecutionOptions(machine, options));
|
|
222
222
|
}
|
|
223
223
|
async function executeAgentRequest(requestOrEffect, executors) {
|
|
224
|
-
if (requestOrEffect.kind === "decision") throw new Error("executeAgentRequest(...) is text-only. Resolve a 'decision' request with resolveDecision(request, executors
|
|
224
|
+
if (requestOrEffect.kind === "decision") throw new Error("executeAgentRequest(...) is text-only. Resolve a 'decision' request with resolveDecision(request, executors, ...) instead.");
|
|
225
225
|
const request = "requestId" in requestOrEffect ? {
|
|
226
226
|
kind: "text",
|
|
227
227
|
id: requestOrEffect.requestId,
|
|
@@ -335,7 +335,7 @@ const AGENT_USAGE_EVENT_TYPE = "@agent.usage";
|
|
|
335
335
|
function createReplayEntry(machine, entries, event, options = {}) {
|
|
336
336
|
const index = entries.length;
|
|
337
337
|
const machineId = machine.config.id ?? machine.id ?? "(machine)";
|
|
338
|
-
const machineVersion = options.machineVersion ??
|
|
338
|
+
const machineVersion = options.machineVersion ?? resolveMachineVersion(machine);
|
|
339
339
|
const entry = {
|
|
340
340
|
schemaVersion: 1,
|
|
341
341
|
id: options.id ?? `evt_${String(index).padStart(8, "0")}`,
|
|
@@ -631,7 +631,7 @@ function validateReplayEntries(entries, expected, label) {
|
|
|
631
631
|
function replay(machine, entries, options = {}) {
|
|
632
632
|
validateReplayEntries(entries, {
|
|
633
633
|
machineId: machine.config.id ?? machine.id ?? "(machine)",
|
|
634
|
-
machineVersion: options.machineVersion ??
|
|
634
|
+
machineVersion: options.machineVersion ?? resolveMachineVersion(machine)
|
|
635
635
|
}, "Replay entries");
|
|
636
636
|
const events = toEvents(entries);
|
|
637
637
|
const initOffset = events[0]?.type === "@agent.init" ? 1 : 0;
|
|
@@ -661,13 +661,6 @@ function replay(machine, entries, options = {}) {
|
|
|
661
661
|
effects
|
|
662
662
|
};
|
|
663
663
|
}
|
|
664
|
-
/** Requires and checks every entry's recorded state/effect hashes. */
|
|
665
|
-
function verifyReplay(machine, entries, options = {}) {
|
|
666
|
-
return replay(machine, entries, {
|
|
667
|
-
...options,
|
|
668
|
-
verify: "strict"
|
|
669
|
-
});
|
|
670
|
-
}
|
|
671
664
|
/** Structural event-tail, logical-state, and owed-effect comparison. */
|
|
672
665
|
function diffEventLogs(machine, parentEntries, forkEntries, options = {}) {
|
|
673
666
|
let commonLength = 0;
|
|
@@ -1135,14 +1128,14 @@ function collectDeclaredStateTags(states, tags = /* @__PURE__ */ new Set()) {
|
|
|
1135
1128
|
}
|
|
1136
1129
|
return tags;
|
|
1137
1130
|
}
|
|
1138
|
-
function
|
|
1139
|
-
if (options.
|
|
1140
|
-
const
|
|
1141
|
-
if (!
|
|
1131
|
+
function resolveIdlePredicate(config, options) {
|
|
1132
|
+
if (options.isIdle) return options.isIdle;
|
|
1133
|
+
const idleTags = config.idleTags ?? [];
|
|
1134
|
+
if (!idleTags.length) return;
|
|
1142
1135
|
const declaredTags = collectDeclaredStateTags(config.states);
|
|
1143
|
-
const unknown =
|
|
1144
|
-
if (unknown.length) throw new Error(`setupAgent.fromConfig: '
|
|
1145
|
-
return (snapshot) =>
|
|
1136
|
+
const unknown = idleTags.filter((tag) => !declaredTags.has(tag));
|
|
1137
|
+
if (unknown.length) throw new Error(`setupAgent.fromConfig: 'idleTags' lists ${unknown.map((tag) => `'${tag}'`).join(", ")}, which no state declares in its 'tags'. Tag the waiting state(s) — e.g. "tags": ["${unknown[0]}"] — or remove the entry.`);
|
|
1138
|
+
return (snapshot) => idleTags.some((tag) => snapshot.hasTag(tag));
|
|
1146
1139
|
}
|
|
1147
1140
|
function setupAgentFromConfig(config, options) {
|
|
1148
1141
|
if (!options || typeof options.compileSchema !== "function") throw new Error("setupAgent.fromConfig(...) requires a 'compileSchema' option: { compileSchema: (jsonSchema, name) => StandardSchemaV1 }. Bring your own JSON Schema engine (Ajv, @cfworker/json-schema, a compiled-Zod-from-JSON-Schema pipeline, ...). Core intentionally ships no JSON Schema engine.");
|
|
@@ -1174,8 +1167,8 @@ function setupAgentFromConfig(config, options) {
|
|
|
1174
1167
|
models: {}
|
|
1175
1168
|
});
|
|
1176
1169
|
if (machine.config) machineStaticTransitionTargets.set(machine.config, translation.transitionTargets);
|
|
1177
|
-
const
|
|
1178
|
-
if (
|
|
1170
|
+
const isIdle = resolveIdlePredicate(config, options);
|
|
1171
|
+
if (isIdle && machine.config) machineIdlePredicates.set(machine.config, isIdle);
|
|
1179
1172
|
return {
|
|
1180
1173
|
machine,
|
|
1181
1174
|
schemas
|
|
@@ -1389,9 +1382,9 @@ function setupAgent(config) {
|
|
|
1389
1382
|
assertStateSchemaKeysExist(config.states, machineConfig?.states);
|
|
1390
1383
|
const machine = createBaseMachine(withRootOutputFromSingleFinal(machineConfig));
|
|
1391
1384
|
agentExecutionOptions.set(machine, machineOptions);
|
|
1392
|
-
if (config.
|
|
1385
|
+
if (config.isIdle) {
|
|
1393
1386
|
const rootConfig = machine.config;
|
|
1394
|
-
if (rootConfig)
|
|
1387
|
+
if (rootConfig) machineIdlePredicates.set(rootConfig, config.isIdle);
|
|
1395
1388
|
}
|
|
1396
1389
|
return machine;
|
|
1397
1390
|
},
|
|
@@ -1482,13 +1475,22 @@ const RESERVED_AGENT_ACTOR_KEYS = [
|
|
|
1482
1475
|
DECIDE_ACTOR
|
|
1483
1476
|
];
|
|
1484
1477
|
/**
|
|
1478
|
+
* The whole `agent.` actor-source namespace is reserved for the library, not
|
|
1479
|
+
* just the shipped builtins: a key starting with this prefix is rejected at
|
|
1480
|
+
* setup time so a future builtin can never collide with (or be shadowed by) a
|
|
1481
|
+
* user source. Name your own sources without it.
|
|
1482
|
+
*/
|
|
1483
|
+
const RESERVED_AGENT_KEY_PREFIX = "agent.";
|
|
1484
|
+
/**
|
|
1485
1485
|
* Runtime guards over the user-supplied `actors`/`requests` keys, in one walk
|
|
1486
1486
|
* of both groups:
|
|
1487
1487
|
*
|
|
1488
|
-
* 1. A key in the reserved `agent
|
|
1489
|
-
*
|
|
1490
|
-
* key overwrite the builtin
|
|
1491
|
-
*
|
|
1488
|
+
* 1. A key in the reserved `agent.` namespace is rejected — every key with
|
|
1489
|
+
* that prefix, not only today's builtins. Without this, the builtins-first
|
|
1490
|
+
* spread in {@link createAgentActors} lets such a key overwrite the builtin
|
|
1491
|
+
* (`agent.decide`, …) silently, and a builtin added later would start
|
|
1492
|
+
* colliding with user code. Deliberate override of a builtin is still
|
|
1493
|
+
* possible after the machine is created, via
|
|
1492
1494
|
* `machine.provide({ actors: { 'agent.decide': ... } })`.
|
|
1493
1495
|
* 2. A key appearing in BOTH groups is almost certainly a mistake (whichever
|
|
1494
1496
|
* spread applies last would silently win) — fail fast with a clear message
|
|
@@ -1499,6 +1501,7 @@ function assertActorKeys(actors, requests) {
|
|
|
1499
1501
|
const groups = [["actors", actors], ["requests", requests]];
|
|
1500
1502
|
for (const [groupName, group] of groups) for (const key of Object.keys(group ?? {})) {
|
|
1501
1503
|
if (RESERVED_AGENT_ACTOR_KEYS.some((reserved) => reserved === key)) throw new Error(`setupAgent: '${groupName}' key '${key}' is a reserved builtin agent actor and cannot be redefined here (it would silently clobber the builtin). Reserved keys: ${RESERVED_AGENT_ACTOR_KEYS.join(", ")}. To deliberately override a builtin, do it on the created machine instead: machine.provide({ actors: { '${key}': ... } }).`);
|
|
1504
|
+
if (key.startsWith(RESERVED_AGENT_KEY_PREFIX)) throw new Error(`setupAgent: '${groupName}' key '${key}' uses the reserved '${RESERVED_AGENT_KEY_PREFIX}' namespace, which belongs to the library (${RESERVED_AGENT_ACTOR_KEYS.join(", ")}, and anything added later). Rename it without the '${RESERVED_AGENT_KEY_PREFIX}' prefix.`);
|
|
1502
1505
|
const existingGroup = seenIn.get(key);
|
|
1503
1506
|
if (existingGroup) throw new Error(`setupAgent: key '${key}' is defined in both '${existingGroup}' and '${groupName}'. Each actor source key must be unique across 'actors' and 'requests'.`);
|
|
1504
1507
|
seenIn.set(key, groupName);
|
|
@@ -1515,4 +1518,4 @@ function createAgentActors(actors, requestActors) {
|
|
|
1515
1518
|
};
|
|
1516
1519
|
}
|
|
1517
1520
|
//#endregion
|
|
1518
|
-
export {
|
|
1521
|
+
export { resolveAgentStep as _, AGENT_USAGE_EVENT_TYPE as a, messagesSchema as b, createReplayEntry as c, initEntry as d, replay as f, initialAgentStep as g, getInvokeEffectMetadata as h, AGENT_INIT_EVENT_TYPE as i, diffEventLogs as l, executeAgentRequest as m, getAgentSchemas as n, AgentReplayDivergenceError as o, validateReplayEntries as p, setupAgent as r, AgentReplayMachineMismatchError as s, createAgentSchemas as t, getAgentEffects as u, transitionAgentStep as v, appendMessages as y };
|
package/dist/sqlite.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_event_log_store = require("./event-log-store-
|
|
2
|
+
const require_event_log_store = require("./event-log-store-a_TKy1gk.cjs");
|
|
3
3
|
//#region src/sqlite/index.ts
|
|
4
4
|
function openDatabase(path) {
|
|
5
5
|
const sqlite = process.getBuiltinModule?.("node:sqlite");
|
|
@@ -80,18 +80,12 @@ function createSqliteEventLogStore(options) {
|
|
|
80
80
|
async length(threadId) {
|
|
81
81
|
return lengthOf(threadId);
|
|
82
82
|
},
|
|
83
|
-
async fork({ threadId, newThreadId, upToIndex
|
|
84
|
-
if (upToIndex !== void 0 && atEventId !== void 0) throw new Error("AgentEventLogStore.fork: pass either upToIndex or atEventId, not both.");
|
|
83
|
+
async fork({ threadId, newThreadId, upToIndex }) {
|
|
85
84
|
transact(() => {
|
|
86
85
|
if (lengthOf(newThreadId) > 0) throw new Error(`AgentEventLogStore.fork: newThreadId "${newThreadId}" already has entries.`);
|
|
87
86
|
const sourceLength = lengthOf(threadId);
|
|
88
87
|
if (sourceLength === 0) throw new Error(`AgentEventLogStore.fork: unknown source thread "${threadId}".`);
|
|
89
|
-
|
|
90
|
-
if (atEventId !== void 0) {
|
|
91
|
-
const row = db.prepare(`SELECT idx FROM ${table} WHERE thread_id = ? AND entry_id = ?`).get(threadId, atEventId);
|
|
92
|
-
if (!row) throw new Error(`AgentEventLogStore.fork: thread "${threadId}" has no event id "${atEventId}".`);
|
|
93
|
-
upTo = Number(row.idx) + 1;
|
|
94
|
-
}
|
|
88
|
+
const upTo = upToIndex ?? sourceLength;
|
|
95
89
|
if (upTo < 0 || upTo > sourceLength) throw new Error(`AgentEventLogStore.fork: thread "${threadId}" (length ${sourceLength}) has no index ${upTo} to fork up to.`);
|
|
96
90
|
db.prepare(`INSERT INTO ${table} (thread_id, idx, entry_id, entry)
|
|
97
91
|
SELECT ?, idx, entry_id, entry FROM ${table} WHERE thread_id = ? AND idx < ?`).run(newThreadId, threadId, upTo);
|
package/dist/sqlite.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { r as AgentSnapshotStore } from "./types-pJ5Hn8fv.cjs";
|
|
2
|
-
import { r as AgentEventLogStore } from "./event-log-store-
|
|
2
|
+
import { r as AgentEventLogStore } from "./event-log-store-Bz7HDBkE.cjs";
|
|
3
3
|
|
|
4
4
|
//#region src/sqlite/index.d.ts
|
|
5
5
|
/** A prepared statement, structurally compatible with `node:sqlite`'s `StatementSync`. */
|
package/dist/sqlite.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { r as AgentSnapshotStore } from "./types-DYpK3QF4.mjs";
|
|
2
|
-
import { r as AgentEventLogStore } from "./event-log-store-
|
|
2
|
+
import { r as AgentEventLogStore } from "./event-log-store-hrA1vqtN.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/sqlite/index.d.ts
|
|
5
5
|
/** A prepared statement, structurally compatible with `node:sqlite`'s `StatementSync`. */
|
package/dist/sqlite.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as assertAgentLogEntry, n as AgentEventLogConflictError } from "./event-log-store-
|
|
1
|
+
import { i as assertAgentLogEntry, n as AgentEventLogConflictError } from "./event-log-store-DmIDosD6.mjs";
|
|
2
2
|
//#region src/sqlite/index.ts
|
|
3
3
|
function openDatabase(path) {
|
|
4
4
|
const sqlite = process.getBuiltinModule?.("node:sqlite");
|
|
@@ -79,18 +79,12 @@ function createSqliteEventLogStore(options) {
|
|
|
79
79
|
async length(threadId) {
|
|
80
80
|
return lengthOf(threadId);
|
|
81
81
|
},
|
|
82
|
-
async fork({ threadId, newThreadId, upToIndex
|
|
83
|
-
if (upToIndex !== void 0 && atEventId !== void 0) throw new Error("AgentEventLogStore.fork: pass either upToIndex or atEventId, not both.");
|
|
82
|
+
async fork({ threadId, newThreadId, upToIndex }) {
|
|
84
83
|
transact(() => {
|
|
85
84
|
if (lengthOf(newThreadId) > 0) throw new Error(`AgentEventLogStore.fork: newThreadId "${newThreadId}" already has entries.`);
|
|
86
85
|
const sourceLength = lengthOf(threadId);
|
|
87
86
|
if (sourceLength === 0) throw new Error(`AgentEventLogStore.fork: unknown source thread "${threadId}".`);
|
|
88
|
-
|
|
89
|
-
if (atEventId !== void 0) {
|
|
90
|
-
const row = db.prepare(`SELECT idx FROM ${table} WHERE thread_id = ? AND entry_id = ?`).get(threadId, atEventId);
|
|
91
|
-
if (!row) throw new Error(`AgentEventLogStore.fork: thread "${threadId}" has no event id "${atEventId}".`);
|
|
92
|
-
upTo = Number(row.idx) + 1;
|
|
93
|
-
}
|
|
87
|
+
const upTo = upToIndex ?? sourceLength;
|
|
94
88
|
if (upTo < 0 || upTo > sourceLength) throw new Error(`AgentEventLogStore.fork: thread "${threadId}" (length ${sourceLength}) has no index ${upTo} to fork up to.`);
|
|
95
89
|
db.prepare(`INSERT INTO ${table} (thread_id, idx, entry_id, entry)
|
|
96
90
|
SELECT ?, idx, entry_id, entry FROM ${table} WHERE thread_id = ? AND idx < ?`).run(newThreadId, threadId, upTo);
|
|
@@ -214,14 +214,17 @@ declare function renderDecisionAttempts(request: Pick<AgentDecisionRequest, "eve
|
|
|
214
214
|
* `generateText`/`streamText` — how the model is coerced into choosing
|
|
215
215
|
* (tool-per-event + forced tool choice, structured output, …) is entirely
|
|
216
216
|
* adapter business; core only validates and retries the returned choice (see
|
|
217
|
-
* {@link resolveDecision}).
|
|
217
|
+
* {@link resolveDecision}). It takes the same `(request, info)` pair as
|
|
218
|
+
* `generateText`/`streamText` — `info` carries the host seams (`signal`,
|
|
219
|
+
* `runId`, `requestId`); `onChunk` is never set for a decision.
|
|
220
|
+
* The optional `reason` is carried through to
|
|
218
221
|
* `onResult`/event-sourcing but never affects validation. Like text
|
|
219
222
|
* executors' `{ output, ...extras }` envelope, any extra keys (finish reason,
|
|
220
223
|
* …) flow untouched to `onResult`'s `raw`; `usage` is the one core reads —
|
|
221
224
|
* report this attempt's tokens there and `runAgent` folds them into the run's
|
|
222
225
|
* aggregated {@link AgentUsage}.
|
|
223
226
|
*/
|
|
224
|
-
type AgentDecisionExecutor = (request: AgentDecisionRequest) => PromiseLike<{
|
|
227
|
+
type AgentDecisionExecutor = (request: AgentDecisionRequest, info?: AgentRequestExecutorInfo) => PromiseLike<{
|
|
225
228
|
event: ChosenEvent;
|
|
226
229
|
reason?: string; /** This attempt's token usage, aggregated into the run result's {@link AgentUsage}. */
|
|
227
230
|
usage?: AgentCallUsage;
|
|
@@ -252,7 +255,7 @@ interface ResolveDecisionOptions<TEvent extends ChosenEvent = ChosenEvent> {
|
|
|
252
255
|
}
|
|
253
256
|
/**
|
|
254
257
|
* Validation + retry core for decisions. No provider mechanics — the
|
|
255
|
-
* `
|
|
258
|
+
* `executors.decide` is responsible for making the model choose an event; this
|
|
256
259
|
* function only validates the choice and retries on failure, up to
|
|
257
260
|
* `options.maxRetries` (default 2, i.e. up to 3 attempts total).
|
|
258
261
|
*
|
|
@@ -270,12 +273,12 @@ interface ResolveDecisionOptions<TEvent extends ChosenEvent = ChosenEvent> {
|
|
|
270
273
|
*
|
|
271
274
|
* @example
|
|
272
275
|
* ```ts
|
|
273
|
-
* const event = await resolveDecision(request,
|
|
276
|
+
* const event = await resolveDecision(request, executors, {
|
|
274
277
|
* canTake: (e) => snapshot.can(e),
|
|
275
278
|
* });
|
|
276
279
|
* ```
|
|
277
280
|
*/
|
|
278
|
-
declare function resolveDecision<TEvent extends ChosenEvent = ChosenEvent>(request: AgentDecisionRequest,
|
|
281
|
+
declare function resolveDecision<TEvent extends ChosenEvent = ChosenEvent>(request: AgentDecisionRequest, executors: Pick<Partial<AgentRequestExecutors>, "decide">, options?: ResolveDecisionOptions<TEvent>): Promise<TEvent>;
|
|
279
282
|
//#endregion
|
|
280
283
|
//#region src/text-logic.d.ts
|
|
281
284
|
declare const USER_INPUT_ACTOR: "agent.userInput";
|
|
@@ -352,12 +355,23 @@ interface AgentTextRequest<TMetadata = Record<string, unknown>> {
|
|
|
352
355
|
topK?: number;
|
|
353
356
|
seed?: number;
|
|
354
357
|
stopSequences?: string[];
|
|
358
|
+
/**
|
|
359
|
+
* Bounds the HOST-side tool-call loop for this one request: the maximum
|
|
360
|
+
* number of model steps the executor may run before it must return. Omitted
|
|
361
|
+
* means single-step (one model call, tool results not fed back). Named and
|
|
362
|
+
* typed to match the AI SDK — the shipped adapter lowers it to
|
|
363
|
+
* `stopWhen: stepCountIs(maxSteps)`.
|
|
364
|
+
*
|
|
365
|
+
* This is a REQUEST budget, distinct from the machine-level `maxTurns` a
|
|
366
|
+
* preset uses for its own turn budget, and from `runAgent`'s run-wide
|
|
367
|
+
* `maxModelCalls`.
|
|
368
|
+
*/
|
|
369
|
+
maxSteps?: number;
|
|
355
370
|
/**
|
|
356
371
|
* Host-owned per-call options. Use this for provider/runtime details such
|
|
357
372
|
* as Cloudflare bindings, tracing IDs, SDK provider options, or transport
|
|
358
|
-
* hints. The machine carries it; the host decides what it means
|
|
359
|
-
*
|
|
360
|
-
* bound its multi-step tool-call loop for that request.
|
|
373
|
+
* hints. The machine carries it; the host decides what it means. Not the
|
|
374
|
+
* place for `maxSteps` any more — that is a typed field above.
|
|
361
375
|
*/
|
|
362
376
|
metadata?: TMetadata;
|
|
363
377
|
}
|
|
@@ -473,6 +487,8 @@ interface TextLogicConfig<TInputSchema extends StandardSchemaV1 = StandardSchema
|
|
|
473
487
|
topK?: ResolveTextLogicValue<number | undefined, InferOutput<TInputSchema>>;
|
|
474
488
|
seed?: ResolveTextLogicValue<number | undefined, InferOutput<TInputSchema>>;
|
|
475
489
|
stopSequences?: ResolveTextLogicValue<string[] | undefined, InferOutput<TInputSchema>>;
|
|
490
|
+
/** Bounds this request's host-side tool loop (see {@link AgentTextRequest.maxSteps}). */
|
|
491
|
+
maxSteps?: ResolveTextLogicValue<number | undefined, InferOutput<TInputSchema>>;
|
|
476
492
|
metadata?: ResolveTextLogicValue<TMetadata | undefined, InferOutput<TInputSchema>>;
|
|
477
493
|
}
|
|
478
494
|
/** Arguments passed to a {@link TextLogicExecutor}: the typed input, the lowered {@link AgentTextRequest}, and the actor's own `signal`/`system`/`self`/`emit`. */
|
|
@@ -214,14 +214,17 @@ declare function renderDecisionAttempts(request: Pick<AgentDecisionRequest, "eve
|
|
|
214
214
|
* `generateText`/`streamText` — how the model is coerced into choosing
|
|
215
215
|
* (tool-per-event + forced tool choice, structured output, …) is entirely
|
|
216
216
|
* adapter business; core only validates and retries the returned choice (see
|
|
217
|
-
* {@link resolveDecision}).
|
|
217
|
+
* {@link resolveDecision}). It takes the same `(request, info)` pair as
|
|
218
|
+
* `generateText`/`streamText` — `info` carries the host seams (`signal`,
|
|
219
|
+
* `runId`, `requestId`); `onChunk` is never set for a decision.
|
|
220
|
+
* The optional `reason` is carried through to
|
|
218
221
|
* `onResult`/event-sourcing but never affects validation. Like text
|
|
219
222
|
* executors' `{ output, ...extras }` envelope, any extra keys (finish reason,
|
|
220
223
|
* …) flow untouched to `onResult`'s `raw`; `usage` is the one core reads —
|
|
221
224
|
* report this attempt's tokens there and `runAgent` folds them into the run's
|
|
222
225
|
* aggregated {@link AgentUsage}.
|
|
223
226
|
*/
|
|
224
|
-
type AgentDecisionExecutor = (request: AgentDecisionRequest) => PromiseLike<{
|
|
227
|
+
type AgentDecisionExecutor = (request: AgentDecisionRequest, info?: AgentRequestExecutorInfo) => PromiseLike<{
|
|
225
228
|
event: ChosenEvent;
|
|
226
229
|
reason?: string; /** This attempt's token usage, aggregated into the run result's {@link AgentUsage}. */
|
|
227
230
|
usage?: AgentCallUsage;
|
|
@@ -252,7 +255,7 @@ interface ResolveDecisionOptions<TEvent extends ChosenEvent = ChosenEvent> {
|
|
|
252
255
|
}
|
|
253
256
|
/**
|
|
254
257
|
* Validation + retry core for decisions. No provider mechanics — the
|
|
255
|
-
* `
|
|
258
|
+
* `executors.decide` is responsible for making the model choose an event; this
|
|
256
259
|
* function only validates the choice and retries on failure, up to
|
|
257
260
|
* `options.maxRetries` (default 2, i.e. up to 3 attempts total).
|
|
258
261
|
*
|
|
@@ -270,12 +273,12 @@ interface ResolveDecisionOptions<TEvent extends ChosenEvent = ChosenEvent> {
|
|
|
270
273
|
*
|
|
271
274
|
* @example
|
|
272
275
|
* ```ts
|
|
273
|
-
* const event = await resolveDecision(request,
|
|
276
|
+
* const event = await resolveDecision(request, executors, {
|
|
274
277
|
* canTake: (e) => snapshot.can(e),
|
|
275
278
|
* });
|
|
276
279
|
* ```
|
|
277
280
|
*/
|
|
278
|
-
declare function resolveDecision<TEvent extends ChosenEvent = ChosenEvent>(request: AgentDecisionRequest,
|
|
281
|
+
declare function resolveDecision<TEvent extends ChosenEvent = ChosenEvent>(request: AgentDecisionRequest, executors: Pick<Partial<AgentRequestExecutors>, "decide">, options?: ResolveDecisionOptions<TEvent>): Promise<TEvent>;
|
|
279
282
|
//#endregion
|
|
280
283
|
//#region src/text-logic.d.ts
|
|
281
284
|
declare const USER_INPUT_ACTOR: "agent.userInput";
|
|
@@ -352,12 +355,23 @@ interface AgentTextRequest<TMetadata = Record<string, unknown>> {
|
|
|
352
355
|
topK?: number;
|
|
353
356
|
seed?: number;
|
|
354
357
|
stopSequences?: string[];
|
|
358
|
+
/**
|
|
359
|
+
* Bounds the HOST-side tool-call loop for this one request: the maximum
|
|
360
|
+
* number of model steps the executor may run before it must return. Omitted
|
|
361
|
+
* means single-step (one model call, tool results not fed back). Named and
|
|
362
|
+
* typed to match the AI SDK — the shipped adapter lowers it to
|
|
363
|
+
* `stopWhen: stepCountIs(maxSteps)`.
|
|
364
|
+
*
|
|
365
|
+
* This is a REQUEST budget, distinct from the machine-level `maxTurns` a
|
|
366
|
+
* preset uses for its own turn budget, and from `runAgent`'s run-wide
|
|
367
|
+
* `maxModelCalls`.
|
|
368
|
+
*/
|
|
369
|
+
maxSteps?: number;
|
|
355
370
|
/**
|
|
356
371
|
* Host-owned per-call options. Use this for provider/runtime details such
|
|
357
372
|
* as Cloudflare bindings, tracing IDs, SDK provider options, or transport
|
|
358
|
-
* hints. The machine carries it; the host decides what it means
|
|
359
|
-
*
|
|
360
|
-
* bound its multi-step tool-call loop for that request.
|
|
373
|
+
* hints. The machine carries it; the host decides what it means. Not the
|
|
374
|
+
* place for `maxSteps` any more — that is a typed field above.
|
|
361
375
|
*/
|
|
362
376
|
metadata?: TMetadata;
|
|
363
377
|
}
|
|
@@ -473,6 +487,8 @@ interface TextLogicConfig<TInputSchema extends StandardSchemaV1 = StandardSchema
|
|
|
473
487
|
topK?: ResolveTextLogicValue<number | undefined, InferOutput<TInputSchema>>;
|
|
474
488
|
seed?: ResolveTextLogicValue<number | undefined, InferOutput<TInputSchema>>;
|
|
475
489
|
stopSequences?: ResolveTextLogicValue<string[] | undefined, InferOutput<TInputSchema>>;
|
|
490
|
+
/** Bounds this request's host-side tool loop (see {@link AgentTextRequest.maxSteps}). */
|
|
491
|
+
maxSteps?: ResolveTextLogicValue<number | undefined, InferOutput<TInputSchema>>;
|
|
476
492
|
metadata?: ResolveTextLogicValue<TMetadata | undefined, InferOutput<TInputSchema>>;
|
|
477
493
|
}
|
|
478
494
|
/** Arguments passed to a {@link TextLogicExecutor}: the typed input, the lowered {@link AgentTextRequest}, and the actor's own `signal`/`system`/`self`/`emit`. */
|