@statelyai/agent 2.0.0-alpha.16 → 2.0.0-alpha.17

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_decision = require("./decision-Ba8qrT8r.cjs");
2
+ const require_decision = require("./decision-DnQCQPew.cjs");
3
3
  let ai = require("ai");
4
4
  //#region src/ai-sdk/mappers.ts
5
5
  /**
package/dist/ai-sdk.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { H as isStandardSchema, _ as getAgentOutputMode, i as renderDecisionAttempts, p as buildEnvelopeSchema } from "./decision-Bt2HYYRo.mjs";
1
+ import { H as isStandardSchema, _ as getAgentOutputMode, i as renderDecisionAttempts, p as buildEnvelopeSchema } from "./decision-C11xuud2.mjs";
2
2
  import { NoObjectGeneratedError, Output, generateText, stepCountIs, streamText, tool } from "ai";
3
3
  //#region src/ai-sdk/mappers.ts
4
4
  /**
@@ -232,9 +232,10 @@ const agentExecutionOptions = /* @__PURE__ */ new WeakMap();
232
232
  * object. `config` is shared by reference across `machine.provide(...)` (unlike
233
233
  * the machine object itself), so a predicate registered here travels with the
234
234
  * machine through `.provide` — which is why it is keyed on `config`, not the
235
- * machine. Set by `setupAgent({ isSuspended })` in `createMachine`, read by
236
- * `runAgent` (below the host `options.isSuspended` override, above the timing
237
- * heuristic).
235
+ * machine. Set by `setupAgent({ isSuspended })` in `createMachine` and by
236
+ * `setupAgent.fromConfig` (its `isSuspended` option or the config's
237
+ * `suspendedTags`), read by `runAgent` (below the host `options.isSuspended`
238
+ * override, above the timing heuristic).
238
239
  */
239
240
  const machineSuspensionPredicates = /* @__PURE__ */ new WeakMap();
240
241
  /** Reads the {@link machineSuspensionPredicates} predicate carried by `machine` (via its root `config`), if any. */
@@ -232,9 +232,10 @@ const agentExecutionOptions = /* @__PURE__ */ new WeakMap();
232
232
  * object. `config` is shared by reference across `machine.provide(...)` (unlike
233
233
  * the machine object itself), so a predicate registered here travels with the
234
234
  * machine through `.provide` — which is why it is keyed on `config`, not the
235
- * machine. Set by `setupAgent({ isSuspended })` in `createMachine`, read by
236
- * `runAgent` (below the host `options.isSuspended` override, above the timing
237
- * heuristic).
235
+ * machine. Set by `setupAgent({ isSuspended })` in `createMachine` and by
236
+ * `setupAgent.fromConfig` (its `isSuspended` option or the config's
237
+ * `suspendedTags`), read by `runAgent` (below the host `options.isSuspended`
238
+ * override, above the timing heuristic).
238
239
  */
239
240
  const machineSuspensionPredicates = /* @__PURE__ */ new WeakMap();
240
241
  /** Reads the {@link machineSuspensionPredicates} predicate carried by `machine` (via its root `config`), if any. */
package/dist/index.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_errors = require("./errors-DUBBzRLP.cjs");
3
- const require_setup_agent = require("./setup-agent-BLU77gqr.cjs");
4
- const require_decision = require("./decision-Ba8qrT8r.cjs");
3
+ const require_setup_agent = require("./setup-agent-D_EyJ0Ik.cjs");
4
+ const require_decision = require("./decision-DnQCQPew.cjs");
5
5
  const require_event_log_store = require("./event-log-store-yquOV1TX.cjs");
6
6
  let xstate = require("xstate");
7
7
  //#region src/internal/state-request-pass.ts
package/dist/index.d.cts CHANGED
@@ -96,6 +96,17 @@ interface AgentWorkflowConfig {
96
96
  actors?: Record<string, AgentWorkflowActorConfig>;
97
97
  initial: string;
98
98
  states: Record<string, AgentWorkflowStateConfig>;
99
+ /**
100
+ * State tags that mark an INTENTIONAL wait for an external event (a human
101
+ * approval, an inbound webhook, …) — the declarative form of `setupAgent({
102
+ * isSuspended })`, since a config cannot carry a function. Lowered to a
103
+ * `snapshot.hasTag(...)`-any-of predicate so `runAgent` settles those
104
+ * snapshots idle deterministically instead of using its timing heuristic.
105
+ * Every listed tag must appear in some state's `tags` — an unused tag is a
106
+ * build-time error. A `fromConfig(config, { isSuspended })` option takes
107
+ * precedence; a `runAgent({ isSuspended })` host override beats both.
108
+ */
109
+ suspendedTags?: string[];
99
110
  meta?: Record<string, unknown>;
100
111
  }
101
112
  /** A `requests` entry in {@link AgentWorkflowConfig} — the JSON equivalent of a `setupAgent({ requests })` `TextLogicConfig`. Fields beyond `input`/`output`/`tools`/`mode`/`description` are `unknown` because they accept template-expression strings (see {@link AgentWorkflowConfig}). */
@@ -228,6 +239,16 @@ interface FromConfigOptions {
228
239
  * implementation here is a build-time error.
229
240
  */
230
241
  actions?: Record<string, (params: any) => unknown>;
242
+ /**
243
+ * Detects a snapshot that is an INTENTIONAL wait for an external event —
244
+ * the same machine-carried predicate `setupAgent({ isSuspended })` declares
245
+ * for TS-authored machines, registered here because a function cannot live
246
+ * in the workflow config itself. Takes precedence over the config's
247
+ * declarative {@link AgentWorkflowConfig.suspendedTags}; a
248
+ * `runAgent({ isSuspended })` host override beats both. Travels with the
249
+ * machine through `machine.provide(...)`.
250
+ */
251
+ isSuspended?: (snapshot: AnyMachineSnapshot) => boolean;
231
252
  }
232
253
  //#endregion
233
254
  //#region src/setup-agent.d.ts
package/dist/index.d.mts CHANGED
@@ -96,6 +96,17 @@ interface AgentWorkflowConfig {
96
96
  actors?: Record<string, AgentWorkflowActorConfig>;
97
97
  initial: string;
98
98
  states: Record<string, AgentWorkflowStateConfig>;
99
+ /**
100
+ * State tags that mark an INTENTIONAL wait for an external event (a human
101
+ * approval, an inbound webhook, …) — the declarative form of `setupAgent({
102
+ * isSuspended })`, since a config cannot carry a function. Lowered to a
103
+ * `snapshot.hasTag(...)`-any-of predicate so `runAgent` settles those
104
+ * snapshots idle deterministically instead of using its timing heuristic.
105
+ * Every listed tag must appear in some state's `tags` — an unused tag is a
106
+ * build-time error. A `fromConfig(config, { isSuspended })` option takes
107
+ * precedence; a `runAgent({ isSuspended })` host override beats both.
108
+ */
109
+ suspendedTags?: string[];
99
110
  meta?: Record<string, unknown>;
100
111
  }
101
112
  /** A `requests` entry in {@link AgentWorkflowConfig} — the JSON equivalent of a `setupAgent({ requests })` `TextLogicConfig`. Fields beyond `input`/`output`/`tools`/`mode`/`description` are `unknown` because they accept template-expression strings (see {@link AgentWorkflowConfig}). */
@@ -228,6 +239,16 @@ interface FromConfigOptions {
228
239
  * implementation here is a build-time error.
229
240
  */
230
241
  actions?: Record<string, (params: any) => unknown>;
242
+ /**
243
+ * Detects a snapshot that is an INTENTIONAL wait for an external event —
244
+ * the same machine-carried predicate `setupAgent({ isSuspended })` declares
245
+ * for TS-authored machines, registered here because a function cannot live
246
+ * in the workflow config itself. Takes precedence over the config's
247
+ * declarative {@link AgentWorkflowConfig.suspendedTags}; a
248
+ * `runAgent({ isSuspended })` host override beats both. Travels with the
249
+ * machine through `machine.provide(...)`.
250
+ */
251
+ isSuspended?: (snapshot: AnyMachineSnapshot) => boolean;
231
252
  }
232
253
  //#endregion
233
254
  //#region src/setup-agent.d.ts
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { t as AgentError } from "./errors-CeSXQx0v.mjs";
2
- import { _ as resolveAgentStep, a as AgentReplayDivergenceError, b as messagesSchema, c as diffEventLogs, d as replay, f as validateReplayEntries, g as initialAgentStep, h as getInvokeEffectMetadata, i as AGENT_USAGE_EVENT_TYPE, l as getAgentEffects, m as executeAgentRequest, n as setupAgent, o as AgentReplayMachineMismatchError, p as verifyReplay, r as AGENT_INIT_EVENT_TYPE, s as createReplayEntry, t as createAgentSchemas, u as initEntry, v as transitionAgentStep, y as appendMessages } from "./setup-agent-SbiiSbAU.mjs";
3
- import { A as isUnboundPlaceholder, B as getMachineStructuralHash, C as parseStructuredEnvelope, D as getMachineStaticTransitionTargets, E as executorBoundLogics, G as toolMessage, H as isStandardSchema, I as findNonSerializableContextPaths, K as userMessage, L as getAgentMessages, O as getMachineSuspensionPredicate, P as assistantMessage, R as getJsonSchema, S as parseOutput, U as persistSnapshot, V as getStateMeta, W as systemMessage, _ as getAgentOutputMode, a as resolveDecision, b as normalizeGeneratorResult, c as AGENT_USAGE_TOKEN_FIELDS, f as bindRequestExecutor, h as createTextLogic, i as renderDecisionAttempts, k as getRegisteredAgentExecutionOptions, o as getAcceptedEvents, p as buildEnvelopeSchema, q as validateSchemaSync, r as isDecisionLogic, s as parseAgentEvent, t as AgentDecisionExhaustedError, u as INTERPRET_SOURCE, v as getCallUsage, x as parseModelRef, y as isTextLogic, z as getJsonSchemaSync } from "./decision-Bt2HYYRo.mjs";
2
+ import { _ as resolveAgentStep, a as AgentReplayDivergenceError, b as messagesSchema, c as diffEventLogs, d as replay, f as validateReplayEntries, g as initialAgentStep, h as getInvokeEffectMetadata, i as AGENT_USAGE_EVENT_TYPE, l as getAgentEffects, m as executeAgentRequest, n as setupAgent, o as AgentReplayMachineMismatchError, p as verifyReplay, r as AGENT_INIT_EVENT_TYPE, s as createReplayEntry, t as createAgentSchemas, u as initEntry, v as transitionAgentStep, y as appendMessages } from "./setup-agent-CTg57Pa4.mjs";
3
+ import { A as isUnboundPlaceholder, B as getMachineStructuralHash, C as parseStructuredEnvelope, D as getMachineStaticTransitionTargets, E as executorBoundLogics, G as toolMessage, H as isStandardSchema, I as findNonSerializableContextPaths, K as userMessage, L as getAgentMessages, O as getMachineSuspensionPredicate, P as assistantMessage, R as getJsonSchema, S as parseOutput, U as persistSnapshot, V as getStateMeta, W as systemMessage, _ as getAgentOutputMode, a as resolveDecision, b as normalizeGeneratorResult, c as AGENT_USAGE_TOKEN_FIELDS, f as bindRequestExecutor, h as createTextLogic, i as renderDecisionAttempts, k as getRegisteredAgentExecutionOptions, o as getAcceptedEvents, p as buildEnvelopeSchema, q as validateSchemaSync, r as isDecisionLogic, s as parseAgentEvent, t as AgentDecisionExhaustedError, u as INTERPRET_SOURCE, v as getCallUsage, x as parseModelRef, y as isTextLogic, z as getJsonSchemaSync } from "./decision-C11xuud2.mjs";
4
4
  import { a as assertJsonSerializable, i as assertAgentLogEntry, n as AgentEventLogConflictError, o as createInMemoryEventLogStore, r as NonSerializableAgentEventError, s as assertEventLogStoreConformance, t as AGENT_EVENT_SCHEMA_VERSION } from "./event-log-store-B-1fcfkT.mjs";
5
5
  import { createActor, createAsyncLogic, getNextTransitions, isMachineSnapshot } from "xstate";
6
6
  //#region src/internal/state-request-pass.ts
package/dist/machines.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_setup_agent = require("./setup-agent-BLU77gqr.cjs");
2
+ const require_setup_agent = require("./setup-agent-D_EyJ0Ik.cjs");
3
3
  //#region src/machines/internal.ts
4
4
  /** The builtin inline text request every preset lowers a request entry to. */
5
5
  const GENERATE_TEXT_SRC = "agent.generateText";
package/dist/machines.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as setupAgent } from "./setup-agent-SbiiSbAU.mjs";
1
+ import { n as setupAgent } from "./setup-agent-CTg57Pa4.mjs";
2
2
  //#region src/machines/internal.ts
3
3
  /** The builtin inline text request every preset lowers a request entry to. */
4
4
  const GENERATE_TEXT_SRC = "agent.generateText";
@@ -1,5 +1,5 @@
1
1
  import { t as AgentError } from "./errors-CeSXQx0v.mjs";
2
- import { B as getMachineStructuralHash, F as djb2Hex, M as machineSuspensionPredicates, N as missingActor, T as agentExecutionOptions, d as USER_INPUT_ACTOR, g as executeAgentTextRequest, h as createTextLogic, j as machineStaticTransitionTargets, 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-Bt2HYYRo.mjs";
2
+ import { B as getMachineStructuralHash, F as djb2Hex, M as machineSuspensionPredicates, N as missingActor, T as agentExecutionOptions, d as USER_INPUT_ACTOR, g as executeAgentTextRequest, h as createTextLogic, j as machineStaticTransitionTargets, 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-C11xuud2.mjs";
3
3
  import { a as assertJsonSerializable, i as assertAgentLogEntry } from "./event-log-store-B-1fcfkT.mjs";
4
4
  import { createMachineFromConfig, initialTransition, setup, transition } from "xstate";
5
5
  //#region src/messages.ts
@@ -1128,6 +1128,22 @@ function translateWorkflowConfig(config, translation) {
1128
1128
  if (json.output === void 0 && finalOutputs.length === 1) json.output = finalOutputs[0];
1129
1129
  return json;
1130
1130
  }
1131
+ function collectDeclaredStateTags(states, tags = /* @__PURE__ */ new Set()) {
1132
+ for (const state of Object.values(states ?? {})) {
1133
+ for (const tag of state.tags ?? []) tags.add(tag);
1134
+ collectDeclaredStateTags(state.states, tags);
1135
+ }
1136
+ return tags;
1137
+ }
1138
+ function resolveSuspensionPredicate(config, options) {
1139
+ if (options.isSuspended) return options.isSuspended;
1140
+ const suspendedTags = config.suspendedTags ?? [];
1141
+ if (!suspendedTags.length) return;
1142
+ const declaredTags = collectDeclaredStateTags(config.states);
1143
+ const unknown = suspendedTags.filter((tag) => !declaredTags.has(tag));
1144
+ if (unknown.length) throw new Error(`setupAgent.fromConfig: 'suspendedTags' 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.`);
1145
+ return (snapshot) => suspendedTags.some((tag) => snapshot.hasTag(tag));
1146
+ }
1131
1147
  function setupAgentFromConfig(config, options) {
1132
1148
  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.");
1133
1149
  const { compileSchema } = options;
@@ -1158,6 +1174,8 @@ function setupAgentFromConfig(config, options) {
1158
1174
  models: {}
1159
1175
  });
1160
1176
  if (machine.config) machineStaticTransitionTargets.set(machine.config, translation.transitionTargets);
1177
+ const isSuspended = resolveSuspensionPredicate(config, options);
1178
+ if (isSuspended && machine.config) machineSuspensionPredicates.set(machine.config, isSuspended);
1161
1179
  return {
1162
1180
  machine,
1163
1181
  schemas
@@ -1,5 +1,5 @@
1
1
  const require_errors = require("./errors-DUBBzRLP.cjs");
2
- const require_decision = require("./decision-Ba8qrT8r.cjs");
2
+ const require_decision = require("./decision-DnQCQPew.cjs");
3
3
  const require_event_log_store = require("./event-log-store-yquOV1TX.cjs");
4
4
  let xstate = require("xstate");
5
5
  //#region src/messages.ts
@@ -1128,6 +1128,22 @@ function translateWorkflowConfig(config, translation) {
1128
1128
  if (json.output === void 0 && finalOutputs.length === 1) json.output = finalOutputs[0];
1129
1129
  return json;
1130
1130
  }
1131
+ function collectDeclaredStateTags(states, tags = /* @__PURE__ */ new Set()) {
1132
+ for (const state of Object.values(states ?? {})) {
1133
+ for (const tag of state.tags ?? []) tags.add(tag);
1134
+ collectDeclaredStateTags(state.states, tags);
1135
+ }
1136
+ return tags;
1137
+ }
1138
+ function resolveSuspensionPredicate(config, options) {
1139
+ if (options.isSuspended) return options.isSuspended;
1140
+ const suspendedTags = config.suspendedTags ?? [];
1141
+ if (!suspendedTags.length) return;
1142
+ const declaredTags = collectDeclaredStateTags(config.states);
1143
+ const unknown = suspendedTags.filter((tag) => !declaredTags.has(tag));
1144
+ if (unknown.length) throw new Error(`setupAgent.fromConfig: 'suspendedTags' 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.`);
1145
+ return (snapshot) => suspendedTags.some((tag) => snapshot.hasTag(tag));
1146
+ }
1131
1147
  function setupAgentFromConfig(config, options) {
1132
1148
  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.");
1133
1149
  const { compileSchema } = options;
@@ -1158,6 +1174,8 @@ function setupAgentFromConfig(config, options) {
1158
1174
  models: {}
1159
1175
  });
1160
1176
  if (machine.config) require_decision.machineStaticTransitionTargets.set(machine.config, translation.transitionTargets);
1177
+ const isSuspended = resolveSuspensionPredicate(config, options);
1178
+ if (isSuspended && machine.config) require_decision.machineSuspensionPredicates.set(machine.config, isSuspended);
1161
1179
  return {
1162
1180
  machine,
1163
1181
  schemas
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statelyai/agent",
3
- "version": "2.0.0-alpha.16",
3
+ "version": "2.0.0-alpha.17",
4
4
  "description": "Make invalid agent actions impossible. Agent logic as state machines: deterministic, inspectable, resumable, runs anywhere.",
5
5
  "keywords": [
6
6
  "agent",
@@ -71,6 +71,14 @@
71
71
  "$ref": "#/$defs/State"
72
72
  }
73
73
  },
74
+ "suspendedTags": {
75
+ "description": "State tags that mark an intentional wait for an external event (a human approval, an inbound webhook, ...). Lowered by setupAgent.fromConfig(...) into a snapshot.hasTag(...) suspension predicate so runAgent settles those states idle deterministically. Every listed tag must appear in some state's 'tags'.",
76
+ "type": "array",
77
+ "items": {
78
+ "type": "string",
79
+ "minLength": 1
80
+ }
81
+ },
74
82
  "meta": {
75
83
  "$ref": "#/$defs/JsonObject"
76
84
  }