@statelyai/agent 2.0.0-alpha.15 → 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.
Files changed (35) hide show
  1. package/dist/ai-sdk.cjs +1 -1
  2. package/dist/ai-sdk.d.cts +2 -2
  3. package/dist/ai-sdk.d.mts +2 -2
  4. package/dist/ai-sdk.mjs +1 -1
  5. package/dist/{decision-D9Zi7Xi5.mjs → decision-C11xuud2.mjs} +35 -26
  6. package/dist/{decision-C0cUKvNt.cjs → decision-DnQCQPew.cjs} +46 -31
  7. package/dist/{event-log-store-D7pWtIhb.mjs → event-log-store-B-1fcfkT.mjs} +149 -141
  8. package/dist/{event-log-store-BkUNtyOF.d.mts → event-log-store-BrC9Q1xW.d.mts} +14 -12
  9. package/dist/{event-log-store-CVd2eyRy.d.cts → event-log-store-CQJq8_v4.d.cts} +14 -12
  10. package/dist/{event-log-store-CNT_7F0V.cjs → event-log-store-yquOV1TX.cjs} +148 -140
  11. package/dist/index.cjs +498 -520
  12. package/dist/index.d.cts +130 -104
  13. package/dist/index.d.mts +130 -104
  14. package/dist/index.mjs +497 -519
  15. package/dist/machines.cjs +1 -1
  16. package/dist/machines.d.cts +1 -1
  17. package/dist/machines.d.mts +1 -1
  18. package/dist/machines.mjs +1 -1
  19. package/dist/otel.d.cts +1 -1
  20. package/dist/otel.d.mts +1 -1
  21. package/dist/{run-agent-B_n4Qxye.d.cts → run-agent-BxjGaVpL.d.cts} +49 -109
  22. package/dist/{run-agent-BWzo4FLv.d.mts → run-agent-COHoCgQd.d.mts} +49 -109
  23. package/dist/{setup-agent-DeHRW-qX.mjs → setup-agent-CTg57Pa4.mjs} +154 -167
  24. package/dist/{setup-agent-CpK0ZRWV.cjs → setup-agent-D_EyJ0Ik.cjs} +159 -172
  25. package/dist/sqlite.cjs +1 -1
  26. package/dist/sqlite.d.cts +2 -2
  27. package/dist/sqlite.d.mts +2 -2
  28. package/dist/sqlite.mjs +1 -1
  29. package/dist/{text-logic-DZW7XWy9.d.cts → text-logic-BFX5q7fM.d.cts} +23 -2
  30. package/dist/{text-logic-C7anC7qX.d.mts → text-logic-DQW8_DWW.d.mts} +23 -2
  31. package/dist/{types-DFD28AWe.d.cts → types-DYpK3QF4.d.mts} +7 -6
  32. package/dist/{types-CTBhMnFu.d.mts → types-pJ5Hn8fv.d.cts} +7 -6
  33. package/package.json +28 -28
  34. package/readme.md +6 -19
  35. package/schemas/agent-workflow.json +9 -4
package/dist/index.d.cts CHANGED
@@ -1,8 +1,8 @@
1
- import { C as ToolResultPart, S as ToolMessage, T as WithAgentInputSchema, _ as NormalizedEventSchemas, a as AgentToolChoice, b as TextPart, c as AgentTools, d as ChosenEvent, f as EventUnion, g as InferOutput, h as InferInput, i as AgentTool, l as AllowedEvents, m as ImagePart, n as AgentMessage, o as AgentToolDescriptor, p as FilePart, r as AgentSnapshotStore, s as AgentToolExecute, t as AgentEventSchemaInputMap, u as AssistantMessage, v as StandardSchemaV1, w as UserMessage, x as ToolCallPart, y as SystemMessage } from "./types-DFD28AWe.cjs";
1
+ import { C as ToolResultPart, S as ToolMessage, T as WithAgentInputSchema, _ as NormalizedEventSchemas, a as AgentToolChoice, b as TextPart, c as AgentTools, d as ChosenEvent, f as EventUnion, g as InferOutput, h as InferInput, i as AgentTool, l as AllowedEvents, m as ImagePart, n as AgentMessage, o as AgentToolDescriptor, p as FilePart, r as AgentSnapshotStore, s as AgentToolExecute, t as AgentEventSchemaInputMap, u as AssistantMessage, v as StandardSchemaV1, w as UserMessage, x as ToolCallPart, y as SystemMessage } from "./types-pJ5Hn8fv.cjs";
2
2
  import { t as AgentError } from "./errors-BQRk9eiZ.cjs";
3
- import { A as AgentDecisionExhaustedError, B as AgentRequestOptions, C as buildEnvelopeSchema, D as parseOutput, E as parseModelRef, F as ResolveDecisionOptions, H as getAcceptedEvents, I as renderDecisionAttempts, L as resolveDecision, M as AgentDecisionRequest, N as DecisionAttempt, O as parseStructuredEnvelope, P as DecisionLogicConfig, R as AgentEventDescriptor, S as bindRequestExecutor, T as getAgentOutputMode, U as parseAgentEvent, V as AgentRequestSource, _ as StructuredOutputEnvelope, a as AgentOutputMode, b as TextLogicExecuteArgs, c as AgentRequestExecutorResult, d as AgentTextRequest, f as AgentUsage, g as BuiltinAgentActors, h as AiSdkShapedTextResult, i as AgentModelRef, j as AgentDecisionInput, k as AgentDecisionExecutor, l as AgentRequestExecutors, m as AiSdkShapedStreamResult, n as AgentExecutorTextRequest, o as AgentRequestExecutor, p as AgentUserInput, r as AgentModelMap, s as AgentRequestExecutorInfo, t as AgentCallUsage, u as AgentRequestMode, v as TextLogic, w as createTextLogic, x as TextLogicExecutor, y as TextLogicConfig, z as AgentEventToolNameResolver } from "./text-logic-DZW7XWy9.cjs";
4
- import { a as AgentLogVerification, c as assertAgentLogEntry, d as createInMemoryEventLogStore, i as AgentLogEntry, l as assertEventLogStoreConformance, n as AgentEventLogConflictError, o as JsonValue, r as AgentEventLogStore, s as NonSerializableAgentEventError, t as AGENT_EVENT_SCHEMA_VERSION, u as assertJsonSerializable } from "./event-log-store-CVd2eyRy.cjs";
5
- import { A as AgentEffect, B as ReplayResult, C as traceTransitions, D as executeAgentRequest, E as AgentStepRequest, F as AgentReplayMachineMismatchError, G as initEntry, H as diffEventLogs, I as AgentUsageEvent, K as replay, L as CreateReplayEntryOptions, M as AgentEventLogDiff, N as AgentLogPatchOperation, O as AGENT_INIT_EVENT_TYPE, P as AgentReplayDivergenceError, R as GetAgentEffectsOptions, S as serializeTraceEvent, T as AgentRequest, U as getAgentEffects, V as createReplayEntry, W as getCallUsage, _ as RunAgentResult, a as AgentInputFrom, b as inspectTransitions, c as AgentSnapshotVersionMismatchError, d as GenerateResult, f as InspectedActorRef, g as RunAgentOptions, h as RunAgentErrorCause, i as AgentIllegalResumeEventError, j as AgentEffectDiff, k as AGENT_USAGE_EVENT_TYPE, l as AgentTraceEvent, m as PendingUserInput, n as AgentActorSession, o as AgentMessageInfo, p as JsonSerializableTraceEvent, q as verifyReplay, r as AgentIdleError, s as AgentRunMeta, t as AGENT_TRACE_SCHEMA_VERSION, u as AgentUserInputExecutor, v as createAgentActor, w as AgentStateRequest, x as runAgent, y as generateResult, z as ReplayOptions } from "./run-agent-B_n4Qxye.cjs";
3
+ import { A as AgentDecisionExecutor, B as AgentEventToolNameResolver, C as buildEnvelopeSchema, D as parseModelRef, E as getCallUsage, F as DecisionLogicConfig, H as AgentRequestSource, I as ResolveDecisionOptions, L as renderDecisionAttempts, M as AgentDecisionInput, N as AgentDecisionRequest, O as parseOutput, P as DecisionAttempt, R as resolveDecision, S as bindRequestExecutor, T as getAgentOutputMode, U as getAcceptedEvents, V as AgentRequestOptions, W as parseAgentEvent, _ as StructuredOutputEnvelope, a as AgentOutputMode, b as TextLogicExecuteArgs, c as AgentRequestExecutorResult, d as AgentTextRequest, f as AgentUsage, g as BuiltinAgentActors, h as AiSdkShapedTextResult, i as AgentModelRef, j as AgentDecisionExhaustedError, k as parseStructuredEnvelope, l as AgentRequestExecutors, m as AiSdkShapedStreamResult, n as AgentExecutorTextRequest, o as AgentRequestExecutor, p as AgentUserInput, r as AgentModelMap, s as AgentRequestExecutorInfo, t as AgentCallUsage, u as AgentRequestMode, v as TextLogic, w as createTextLogic, x as TextLogicExecutor, y as TextLogicConfig, z as AgentEventDescriptor } from "./text-logic-BFX5q7fM.cjs";
4
+ import { a as AgentLogVerification, c as assertAgentLogEntry, d as assertEventLogStoreConformance, i as AgentLogEntry, l as assertJsonSerializable, n as AgentEventLogConflictError, o as JsonValue, r as AgentEventLogStore, s as NonSerializableAgentEventError, t as AGENT_EVENT_SCHEMA_VERSION, u as createInMemoryEventLogStore } from "./event-log-store-CQJq8_v4.cjs";
5
+ import { A as AgentEffect, B as ReplayResult, C as traceTransitions, D as executeAgentRequest, E as AgentStepRequest, F as AgentReplayMachineMismatchError, G as replay, H as diffEventLogs, I as AgentUsageEvent, K as verifyReplay, L as CreateReplayEntryOptions, M as AgentEventLogDiff, N as AgentLogPatchOperation, O as AGENT_INIT_EVENT_TYPE, P as AgentReplayDivergenceError, R as GetAgentEffectsOptions, S as serializeTraceEvent, T as AgentRequest, U as getAgentEffects, V as createReplayEntry, W as initEntry, _ as RunAgentResult, a as AgentInputFrom, b as inspectTransitions, c as AgentSnapshotVersionMismatchError, d as GenerateResult, f as InspectedActorRef, g as RunAgentOptions, h as RunAgentErrorCause, i as AgentIllegalResumeEventError, j as AgentEffectDiff, k as AGENT_USAGE_EVENT_TYPE, l as AgentTraceEvent, m as PendingUserInput, n as AgentActorSession, o as AgentMessageInfo, p as JsonSerializableTraceEvent, r as AgentIdleError, s as AgentRunMeta, t as AGENT_TRACE_SCHEMA_VERSION, u as AgentUserInputExecutor, v as createAgentActor, w as AgentStateRequest, x as runAgent, y as generateResult, z as ReplayOptions } from "./run-agent-BxjGaVpL.cjs";
6
6
  import { AnyActorLogic, AnyMachineSnapshot, AnySetupConfig, AnyStateMachine, AsyncActorLogic, EventFromLogic, EventObject, InputFrom, MachineContext, MetaObject, NonReducibleUnknown, SetupReturnFromConfig, SetupStateSchema, SnapshotFrom, StateValue } from "xstate";
7
7
 
8
8
  //#region src/messages.d.ts
@@ -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
@@ -623,7 +644,7 @@ interface ProvideExecutorsOptions<TMachine extends AnyStateMachine = AnyStateMac
623
644
  * Throws at bind time if a source needs an executor kind that `executors` does
624
645
  * not provide.
625
646
  *
626
- * v1 does NOT descend into invoked child state machines: a string-keyed child
647
+ * `provideExecutors` does not descend into invoked child state machines: a string-keyed child
627
648
  * machine source is left untouched, so a child with its own agent invokes needs
628
649
  * its own `provideExecutors(...)` (or `runAgent`, which does rebind children).
629
650
  */
@@ -877,7 +898,10 @@ interface TrajectoryMatch {
877
898
  matchedCount: number;
878
899
  /** `expected.length`, so a scorer can compute its own ratio. */
879
900
  expectedCount: number;
880
- /** Partial credit, 0..1. `1` for an empty expectation. */
901
+ /**
902
+ * Partial credit, 0..1. `1` for an empty expectation. Denominator is
903
+ * `max(expectedCount, actual.length)` in `exact` mode, `expectedCount` otherwise.
904
+ */
881
905
  score: number;
882
906
  /** Absent when `matched`. */
883
907
  firstMiss?: TrajectoryMiss;
@@ -927,7 +951,6 @@ type ScriptedDecisionValue = ChosenEvent | {
927
951
  event: ChosenEvent;
928
952
  reason?: string;
929
953
  usage?: AgentCallUsage;
930
- [key: string]: unknown;
931
954
  };
932
955
  /**
933
956
  * One entry in the `decisions` queue: a scripted answer, or a function of the
@@ -987,6 +1010,101 @@ interface ScriptedExecutorsScript {
987
1010
  */
988
1011
  declare function createScriptedExecutors(script?: ScriptedExecutorsScript): Required<AgentRequestExecutors>;
989
1012
  //#endregion
1013
+ //#region src/utils.d.ts
1014
+ /**
1015
+ * Deep-clones a snapshot to a plain-JSON value via a `JSON` round-trip, the
1016
+ * shape you persist and later feed back to `runAgent({ snapshot })`. Asserts
1017
+ * JSON-serializability: functions, `undefined`, and other non-JSON values are
1018
+ * dropped or throw exactly as `JSON.stringify`/`JSON.parse` would. Returns a
1019
+ * plain-JSON deep clone, not a live snapshot.
1020
+ */
1021
+ declare function persistSnapshot<TSnapshot>(snapshot: TSnapshot): TSnapshot;
1022
+ /**
1023
+ * A stable, dependency-free structural fingerprint of a machine — a short hex
1024
+ * `djb2` hash over its **structural** config only: state ids/nesting, transition
1025
+ * event types and targets, invoke `src`s, `initial`, and any other serializable
1026
+ * config fields. Function values (context/output builders, prompts, inline
1027
+ * guards/actions) are excluded entirely, so two machines that differ only in
1028
+ * their prompts or executors hash identically; adding/removing/retargeting a
1029
+ * state or transition changes the hash.
1030
+ *
1031
+ * Used by {@link runAgent} to stamp settled snapshots with a `version` and to
1032
+ * detect a structurally-edited machine on resume. It is a change detector, not
1033
+ * a cryptographic digest — collisions are possible but unlikely for real
1034
+ * configs. Pass an explicit `machineVersion` to `runAgent` to override it.
1035
+ */
1036
+ declare function getMachineStructuralHash(machine: AnyStateMachine): string;
1037
+ /** Builds a {@link UserMessage} from a string or multimodal content parts. */
1038
+ declare function userMessage(content: string | Array<TextPart | ImagePart | FilePart>): UserMessage;
1039
+ /** Builds an {@link AssistantMessage} from a string or content parts (text, files, tool calls/results). */
1040
+ declare function assistantMessage(content: string | Array<TextPart | FilePart | ToolCallPart | ToolResultPart>): AssistantMessage;
1041
+ /** Builds a {@link SystemMessage}. */
1042
+ declare function systemMessage(content: string): SystemMessage;
1043
+ /** Builds a {@link ToolMessage} from one or more tool-result parts. */
1044
+ declare function toolMessage(content: Array<ToolResultPart>): ToolMessage;
1045
+ type MetaOfSnapshot<TSnapshot extends {
1046
+ getMeta(): Record<string, unknown>;
1047
+ }> = NonNullable<ReturnType<TSnapshot["getMeta"]>[keyof ReturnType<TSnapshot["getMeta"]>]>;
1048
+ /**
1049
+ * Returns the merged `meta` of a snapshot's active state(s) — the typed
1050
+ * replacement for the `Object.values(snapshot.getMeta())[0]` dance.
1051
+ *
1052
+ * `snapshot.getMeta()` is keyed by state id; a leaf machine has one active
1053
+ * state, but parallel/nested machines can have several. This shallow-merges
1054
+ * every active state's meta into one object (later/deeper entries win) and
1055
+ * returns `{}` when no active state declares meta.
1056
+ *
1057
+ * The return type is recovered from the snapshot's own `getMeta()` type, so a
1058
+ * schema-typed machine (`setupAgent({ meta })`) yields the meta schema's
1059
+ * output type. Pass an explicit `TMeta` to override when the snapshot is
1060
+ * untyped (e.g. `AnyMachineSnapshot`).
1061
+ *
1062
+ * @example HITL: read the current state's interaction protocol off an idle
1063
+ * snapshot to render for a human.
1064
+ * ```ts
1065
+ * const { interaction } = getStateMeta(result.snapshot);
1066
+ * ```
1067
+ */
1068
+ declare function getStateMeta<TSnapshot extends {
1069
+ getMeta(): Record<string, unknown>;
1070
+ } = AnyMachineSnapshot, TMeta = MetaOfSnapshot<TSnapshot>>(snapshot: TSnapshot): Partial<TMeta>;
1071
+ /**
1072
+ * Reads the run-owned message log off a snapshot settled by a `runAgent` call
1073
+ * that used `getRequests` (or `options.messages`) — the typed replacement for
1074
+ * the `(snapshot as { messages?: AgentMessage[] }).messages` cast. runAgent
1075
+ * stamps the log as a plain enumerable `messages` property (like `agentMeta`),
1076
+ * so it survives a JSON persist/resume round-trip; this accessor works on the
1077
+ * live settled snapshot and on a JSON-parsed persisted one alike. Returns `[]`
1078
+ * when no log was stamped (e.g. a default invoke-driven run).
1079
+ *
1080
+ * The write path is `runAgent(..., { messages })`: an explicit seed that
1081
+ * overrides the resume snapshot's stamped log (fold in a user reply on
1082
+ * resume, or start a run with prior history).
1083
+ */
1084
+ declare function getAgentMessages(snapshot: unknown): AgentMessage[];
1085
+ /**
1086
+ * Structural guard for a {@link StandardSchemaV1}: `true` when `value` carries
1087
+ * the `~standard` marker. Used to tell an already-schema'd tool `inputSchema`
1088
+ * (a Zod/Valibot/… schema) apart from an SDK-specific schema wrapper that core
1089
+ * can't read directly — see the `ai-sdk` tool pass-through.
1090
+ */
1091
+ declare function isStandardSchema(value: unknown): value is StandardSchemaV1;
1092
+ /**
1093
+ * Pulls the JSON Schema off a {@link StandardSchemaV1} via its optional
1094
+ * `~standard.jsonSchema.input()` extension (implemented by e.g. Zod v4's
1095
+ * `z.toJSONSchema`), awaiting it when the producer is async. Returns
1096
+ * `undefined` when the schema doesn't expose the extension. Use this to build
1097
+ * a provider request's `response_format`/tool `parameters` from a schema.
1098
+ */
1099
+ declare function getJsonSchema(schema?: StandardSchemaV1): Promise<Record<string, unknown> | undefined>;
1100
+ /**
1101
+ * Synchronous variant of {@link getJsonSchema}, for call sites that can't
1102
+ * await (building tool/event descriptors inline). An async JSON Schema
1103
+ * producer is treated as absent (returns `undefined`) — in practice Zod's
1104
+ * `z.toJSONSchema` resolves synchronously.
1105
+ */
1106
+ declare function getJsonSchemaSync(schema?: StandardSchemaV1): Record<string, unknown> | undefined;
1107
+ //#endregion
990
1108
  //#region src/seam.d.ts
991
1109
  /**
992
1110
  * Which model call is under test: the Nth call addressed either by request
@@ -1014,8 +1132,11 @@ interface SeamTurn<TMachine extends AnyStateMachine> {
1014
1132
  snapshot: SnapshotFrom<TMachine>;
1015
1133
  /** Its state value, for a `switch` on flat machines. */
1016
1134
  state: StateValue;
1017
- /** The merged `meta` of the active state(s) — e.g. a declared `interaction`. */
1018
- meta: Record<string, unknown>;
1135
+ /**
1136
+ * The merged `meta` of the active state(s), e.g. a declared `interaction`.
1137
+ * Typed from the machine's own meta schema (`setupAgent({ meta })`).
1138
+ */
1139
+ meta: Partial<MetaOfSnapshot<SnapshotFrom<TMachine>>>;
1019
1140
  /** 0-based index of this pause within the run. */
1020
1141
  turn: number;
1021
1142
  /** The `idle` result that produced the pause. */
@@ -1120,99 +1241,4 @@ interface RunSeamResult<TMachine extends AnyStateMachine> {
1120
1241
  */
1121
1242
  declare function runSeam<TMachine extends AnyStateMachine>(machine: TMachine, options: RunSeamOptions<TMachine>): Promise<RunSeamResult<TMachine>>;
1122
1243
  //#endregion
1123
- //#region src/utils.d.ts
1124
- /**
1125
- * Deep-clones a snapshot to a plain-JSON value via a `JSON` round-trip, the
1126
- * shape you persist and later feed back to `runAgent({ snapshot })`. Asserts
1127
- * JSON-serializability: functions, `undefined`, and other non-JSON values are
1128
- * dropped or throw exactly as `JSON.stringify`/`JSON.parse` would. Returns a
1129
- * plain-JSON deep clone, not a live snapshot.
1130
- */
1131
- declare function persistSnapshot<TSnapshot>(snapshot: TSnapshot): TSnapshot;
1132
- /**
1133
- * A stable, dependency-free structural fingerprint of a machine — a short hex
1134
- * `djb2` hash over its **structural** config only: state ids/nesting, transition
1135
- * event types and targets, invoke `src`s, `initial`, and any other serializable
1136
- * config fields. Function values (context/output builders, prompts, inline
1137
- * guards/actions) are excluded entirely, so two machines that differ only in
1138
- * their prompts or executors hash identically; adding/removing/retargeting a
1139
- * state or transition changes the hash.
1140
- *
1141
- * Used by {@link runAgent} to stamp settled snapshots with a `version` and to
1142
- * detect a structurally-edited machine on resume. It is a change detector, not
1143
- * a cryptographic digest — collisions are possible but unlikely for real
1144
- * configs. Pass an explicit `machineVersion` to `runAgent` to override it.
1145
- */
1146
- declare function getMachineStructuralHash(machine: AnyStateMachine): string;
1147
- /** Builds a {@link UserMessage} from a string or multimodal content parts. */
1148
- declare function userMessage(content: string | Array<TextPart | ImagePart | FilePart>): UserMessage;
1149
- /** Builds an {@link AssistantMessage} from a string or content parts (text, files, tool calls/results). */
1150
- declare function assistantMessage(content: string | Array<TextPart | FilePart | ToolCallPart | ToolResultPart>): AssistantMessage;
1151
- /** Builds a {@link SystemMessage}. */
1152
- declare function systemMessage(content: string): SystemMessage;
1153
- /** Builds a {@link ToolMessage} from one or more tool-result parts. */
1154
- declare function toolMessage(content: Array<ToolResultPart>): ToolMessage;
1155
- type MetaOfSnapshot<TSnapshot extends {
1156
- getMeta(): Record<string, unknown>;
1157
- }> = NonNullable<ReturnType<TSnapshot["getMeta"]>[keyof ReturnType<TSnapshot["getMeta"]>]>;
1158
- /**
1159
- * Returns the merged `meta` of a snapshot's active state(s) — the typed
1160
- * replacement for the `Object.values(snapshot.getMeta())[0]` dance.
1161
- *
1162
- * `snapshot.getMeta()` is keyed by state id; a leaf machine has one active
1163
- * state, but parallel/nested machines can have several. This shallow-merges
1164
- * every active state's meta into one object (later/deeper entries win) and
1165
- * returns `{}` when no active state declares meta.
1166
- *
1167
- * The return type is recovered from the snapshot's own `getMeta()` type, so a
1168
- * schema-typed machine (`setupAgent({ meta })`) yields the meta schema's
1169
- * output type. Pass an explicit `TMeta` to override when the snapshot is
1170
- * untyped (e.g. `AnyMachineSnapshot`).
1171
- *
1172
- * @example HITL: read the current state's interaction protocol off an idle
1173
- * snapshot to render for a human.
1174
- * ```ts
1175
- * const { interaction } = getStateMeta(result.snapshot);
1176
- * ```
1177
- */
1178
- declare function getStateMeta<TSnapshot extends {
1179
- getMeta(): Record<string, unknown>;
1180
- } = AnyMachineSnapshot, TMeta = MetaOfSnapshot<TSnapshot>>(snapshot: TSnapshot): Partial<TMeta>;
1181
- /**
1182
- * Reads the run-owned message log off a snapshot settled by a `runAgent` call
1183
- * that used `getRequests` (or `options.messages`) — the typed replacement for
1184
- * the `(snapshot as { messages?: AgentMessage[] }).messages` cast. runAgent
1185
- * stamps the log as a plain enumerable `messages` property (like `agentMeta`),
1186
- * so it survives a JSON persist/resume round-trip; this accessor works on the
1187
- * live settled snapshot and on a JSON-parsed persisted one alike. Returns `[]`
1188
- * when no log was stamped (e.g. a default invoke-driven run).
1189
- *
1190
- * The write path is `runAgent(..., { messages })`: an explicit seed that
1191
- * overrides the resume snapshot's stamped log (fold in a user reply on
1192
- * resume, or start a run with prior history).
1193
- */
1194
- declare function getAgentMessages(snapshot: unknown): AgentMessage[];
1195
- /**
1196
- * Structural guard for a {@link StandardSchemaV1}: `true` when `value` carries
1197
- * the `~standard` marker. Used to tell an already-schema'd tool `inputSchema`
1198
- * (a Zod/Valibot/… schema) apart from an SDK-specific schema wrapper that core
1199
- * can't read directly — see the `ai-sdk` tool pass-through.
1200
- */
1201
- declare function isStandardSchema(value: unknown): value is StandardSchemaV1;
1202
- /**
1203
- * Pulls the JSON Schema off a {@link StandardSchemaV1} via its optional
1204
- * `~standard.jsonSchema.input()` extension (implemented by e.g. Zod v4's
1205
- * `z.toJSONSchema`), awaiting it when the producer is async. Returns
1206
- * `undefined` when the schema doesn't expose the extension. Use this to build
1207
- * a provider request's `response_format`/tool `parameters` from a schema.
1208
- */
1209
- declare function getJsonSchema(schema?: StandardSchemaV1): Promise<Record<string, unknown> | undefined>;
1210
- /**
1211
- * Synchronous variant of {@link getJsonSchema}, for call sites that can't
1212
- * await (building tool/event descriptors inline). An async JSON Schema
1213
- * producer is treated as absent (returns `undefined`) — in practice Zod's
1214
- * `z.toJSONSchema` resolves synchronously.
1215
- */
1216
- declare function getJsonSchemaSync(schema?: StandardSchemaV1): Record<string, unknown> | undefined;
1217
- //#endregion
1218
1244
  export { AGENT_EVENT_SCHEMA_VERSION, AGENT_INIT_EVENT_TYPE, AGENT_TRACE_SCHEMA_VERSION, AGENT_USAGE_EVENT_TYPE, type AgentActorSession, type AgentCallUsage, type AgentDecisionExecutor, AgentDecisionExhaustedError, type AgentDecisionInput, type AgentDecisionRequest, type AgentEffect, type AgentEffectDiff, AgentError, type AgentEventDescriptor, AgentEventLogConflictError, type AgentEventLogDiff, type AgentEventLogStore, type AgentEventToolNameResolver, type AgentExecutorTextRequest, AgentIdleError, AgentIllegalResumeEventError, type AgentInputFrom, type AgentLintDiagnostic, AgentLintError, type AgentLintSeverity, type AgentLogEntry, type AgentLogPatchOperation, type AgentLogVerification, type AgentMessage, type AgentMessageInfo, type AgentModelRef, type AgentOutputMode, type AgentPathReport, type AgentPathTerminal, AgentReplayDivergenceError, AgentReplayMachineMismatchError, type AgentRequest, type AgentRequestExecutor, type AgentRequestExecutorInfo, type AgentRequestExecutorResult, type AgentRequestExecutors, type AgentRequestOptions, type AgentRequestSource, type AgentRun, type AgentRunMeta, type AgentSchemaPack, type AgentSnapshotStore, AgentSnapshotVersionMismatchError, type AgentStateRequest, type AgentStepRequest, type AgentTextRequest, type AgentTool, type AgentToolChoice, type AgentToolDescriptor, type AgentToolExecute, type AgentTools, type AgentTraceEvent, type AgentUsage, type AgentUsageEvent, type AgentUsageEventPayload, type AgentUserInput, type AgentUserInputExecutor, type AgentWorkflowActionConfig, type AgentWorkflowActorConfig, type AgentWorkflowConfig, type AgentWorkflowInvokeConfig, type AgentWorkflowRequestConfig, type AgentWorkflowStateConfig, type AgentWorkflowTransitionConfig, type AiSdkShapedStreamResult, type AiSdkShapedTextResult, type AllowedEvents, type AssertAgentMachineOptions, type AssistantMessage, type CanReachResult, type ChosenEvent, type CreateReplayEntryOptions, type DecisionAttempt, type DecisionLogicConfig, type ExplorePathsOptions, type FilePart, type FromConfigOptions, type FromConfigResult, type GenerateResult, type GetAgentEffectsOptions, type ImagePart, type InferInput, type InferOutput, type InspectedActorRef, type JsonSerializableTraceEvent, type JsonValue, type LintAgentMachineOptions, type MatchTrajectoryOptions, NonSerializableAgentEventError, type PendingUserInput, type ProvideExecutorsOptions, type ReplayOptions, type ReplayResult, type ResolveDecisionOptions, type RunAgentErrorCause, type RunAgentOptions, type RunAgentResult, type RunSeamOptions, type RunSeamResult, type SchemaCompiler, type ScriptedDecisionEntry, type ScriptedDecisionValue, type ScriptedExecutorsScript, type ScriptedTextEntry, type SeamRef, type SeamSlice, type SeamTurn, type SimulateAgentOptions, type SimulateAgentResult, type SimulationScript, type SimulationTrailEntry, type StandardSchemaV1, type StructuredOutputEnvelope, type SystemMessage, type TextLogic, type TextLogicConfig, type TextLogicExecuteArgs, type TextLogicExecutor, type TextPart, type ToolCallPart, type ToolMessage, type ToolResultPart, type TrajectoryEvent, type TrajectoryItem, type TrajectoryMatch, type TrajectoryMiss, type UserMessage, type WithAgentUsageEvent, appendMessages, assertAgentLogEntry, assertAgentMachine, assertEventLogStoreConformance, assertJsonSerializable, assistantMessage, bindRequestExecutor, buildEnvelopeSchema, canReach, createAgentActor, createAgentRun, createAgentSchemas, createInMemoryEventLogStore, createReplayEntry, createScriptedExecutors, createTextLogic, diffEventLogs, executeAgentRequest, explorePaths, generateResult, getAcceptedEvents, getAgentEffects, getAgentMessages, getAgentOutputMode, getCallUsage, getJsonSchema, getJsonSchemaSync, getMachineStructuralHash, getStateMeta, initEntry, inspectTransitions, isStandardSchema, lintAgentMachine, matchesTrajectory, messagesSchema, parseAgentEvent, parseModelRef, parseOutput, parseStructuredEnvelope, persistSnapshot, provideExecutors, renderDecisionAttempts, replay, resolveDecision, runAgent, runSeam, serializeTraceEvent, setupAgent, simulateAgent, systemMessage, toolMessage, traceTransitions, userMessage, verifyReplay };
package/dist/index.d.mts CHANGED
@@ -1,8 +1,8 @@
1
- import { C as ToolResultPart, S as ToolMessage, T as WithAgentInputSchema, _ as NormalizedEventSchemas, a as AgentToolChoice, b as TextPart, c as AgentTools, d as ChosenEvent, f as EventUnion, g as InferOutput, h as InferInput, i as AgentTool, l as AllowedEvents, m as ImagePart, n as AgentMessage, o as AgentToolDescriptor, p as FilePart, r as AgentSnapshotStore, s as AgentToolExecute, t as AgentEventSchemaInputMap, u as AssistantMessage, v as StandardSchemaV1, w as UserMessage, x as ToolCallPart, y as SystemMessage } from "./types-CTBhMnFu.mjs";
1
+ import { C as ToolResultPart, S as ToolMessage, T as WithAgentInputSchema, _ as NormalizedEventSchemas, a as AgentToolChoice, b as TextPart, c as AgentTools, d as ChosenEvent, f as EventUnion, g as InferOutput, h as InferInput, i as AgentTool, l as AllowedEvents, m as ImagePart, n as AgentMessage, o as AgentToolDescriptor, p as FilePart, r as AgentSnapshotStore, s as AgentToolExecute, t as AgentEventSchemaInputMap, u as AssistantMessage, v as StandardSchemaV1, w as UserMessage, x as ToolCallPart, y as SystemMessage } from "./types-DYpK3QF4.mjs";
2
2
  import { t as AgentError } from "./errors-C9rxnWbX.mjs";
3
- import { A as AgentDecisionExhaustedError, B as AgentRequestOptions, C as buildEnvelopeSchema, D as parseOutput, E as parseModelRef, F as ResolveDecisionOptions, H as getAcceptedEvents, I as renderDecisionAttempts, L as resolveDecision, M as AgentDecisionRequest, N as DecisionAttempt, O as parseStructuredEnvelope, P as DecisionLogicConfig, R as AgentEventDescriptor, S as bindRequestExecutor, T as getAgentOutputMode, U as parseAgentEvent, V as AgentRequestSource, _ as StructuredOutputEnvelope, a as AgentOutputMode, b as TextLogicExecuteArgs, c as AgentRequestExecutorResult, d as AgentTextRequest, f as AgentUsage, g as BuiltinAgentActors, h as AiSdkShapedTextResult, i as AgentModelRef, j as AgentDecisionInput, k as AgentDecisionExecutor, l as AgentRequestExecutors, m as AiSdkShapedStreamResult, n as AgentExecutorTextRequest, o as AgentRequestExecutor, p as AgentUserInput, r as AgentModelMap, s as AgentRequestExecutorInfo, t as AgentCallUsage, u as AgentRequestMode, v as TextLogic, w as createTextLogic, x as TextLogicExecutor, y as TextLogicConfig, z as AgentEventToolNameResolver } from "./text-logic-C7anC7qX.mjs";
4
- import { a as AgentLogVerification, c as assertAgentLogEntry, d as createInMemoryEventLogStore, i as AgentLogEntry, l as assertEventLogStoreConformance, n as AgentEventLogConflictError, o as JsonValue, r as AgentEventLogStore, s as NonSerializableAgentEventError, t as AGENT_EVENT_SCHEMA_VERSION, u as assertJsonSerializable } from "./event-log-store-BkUNtyOF.mjs";
5
- import { A as AgentEffect, B as ReplayResult, C as traceTransitions, D as executeAgentRequest, E as AgentStepRequest, F as AgentReplayMachineMismatchError, G as initEntry, H as diffEventLogs, I as AgentUsageEvent, K as replay, L as CreateReplayEntryOptions, M as AgentEventLogDiff, N as AgentLogPatchOperation, O as AGENT_INIT_EVENT_TYPE, P as AgentReplayDivergenceError, R as GetAgentEffectsOptions, S as serializeTraceEvent, T as AgentRequest, U as getAgentEffects, V as createReplayEntry, W as getCallUsage, _ as RunAgentResult, a as AgentInputFrom, b as inspectTransitions, c as AgentSnapshotVersionMismatchError, d as GenerateResult, f as InspectedActorRef, g as RunAgentOptions, h as RunAgentErrorCause, i as AgentIllegalResumeEventError, j as AgentEffectDiff, k as AGENT_USAGE_EVENT_TYPE, l as AgentTraceEvent, m as PendingUserInput, n as AgentActorSession, o as AgentMessageInfo, p as JsonSerializableTraceEvent, q as verifyReplay, r as AgentIdleError, s as AgentRunMeta, t as AGENT_TRACE_SCHEMA_VERSION, u as AgentUserInputExecutor, v as createAgentActor, w as AgentStateRequest, x as runAgent, y as generateResult, z as ReplayOptions } from "./run-agent-BWzo4FLv.mjs";
3
+ import { A as AgentDecisionExecutor, B as AgentEventToolNameResolver, C as buildEnvelopeSchema, D as parseModelRef, E as getCallUsage, F as DecisionLogicConfig, H as AgentRequestSource, I as ResolveDecisionOptions, L as renderDecisionAttempts, M as AgentDecisionInput, N as AgentDecisionRequest, O as parseOutput, P as DecisionAttempt, R as resolveDecision, S as bindRequestExecutor, T as getAgentOutputMode, U as getAcceptedEvents, V as AgentRequestOptions, W as parseAgentEvent, _ as StructuredOutputEnvelope, a as AgentOutputMode, b as TextLogicExecuteArgs, c as AgentRequestExecutorResult, d as AgentTextRequest, f as AgentUsage, g as BuiltinAgentActors, h as AiSdkShapedTextResult, i as AgentModelRef, j as AgentDecisionExhaustedError, k as parseStructuredEnvelope, l as AgentRequestExecutors, m as AiSdkShapedStreamResult, n as AgentExecutorTextRequest, o as AgentRequestExecutor, p as AgentUserInput, r as AgentModelMap, s as AgentRequestExecutorInfo, t as AgentCallUsage, u as AgentRequestMode, v as TextLogic, w as createTextLogic, x as TextLogicExecutor, y as TextLogicConfig, z as AgentEventDescriptor } from "./text-logic-DQW8_DWW.mjs";
4
+ import { a as AgentLogVerification, c as assertAgentLogEntry, d as assertEventLogStoreConformance, i as AgentLogEntry, l as assertJsonSerializable, n as AgentEventLogConflictError, o as JsonValue, r as AgentEventLogStore, s as NonSerializableAgentEventError, t as AGENT_EVENT_SCHEMA_VERSION, u as createInMemoryEventLogStore } from "./event-log-store-BrC9Q1xW.mjs";
5
+ import { A as AgentEffect, B as ReplayResult, C as traceTransitions, D as executeAgentRequest, E as AgentStepRequest, F as AgentReplayMachineMismatchError, G as replay, H as diffEventLogs, I as AgentUsageEvent, K as verifyReplay, L as CreateReplayEntryOptions, M as AgentEventLogDiff, N as AgentLogPatchOperation, O as AGENT_INIT_EVENT_TYPE, P as AgentReplayDivergenceError, R as GetAgentEffectsOptions, S as serializeTraceEvent, T as AgentRequest, U as getAgentEffects, V as createReplayEntry, W as initEntry, _ as RunAgentResult, a as AgentInputFrom, b as inspectTransitions, c as AgentSnapshotVersionMismatchError, d as GenerateResult, f as InspectedActorRef, g as RunAgentOptions, h as RunAgentErrorCause, i as AgentIllegalResumeEventError, j as AgentEffectDiff, k as AGENT_USAGE_EVENT_TYPE, l as AgentTraceEvent, m as PendingUserInput, n as AgentActorSession, o as AgentMessageInfo, p as JsonSerializableTraceEvent, r as AgentIdleError, s as AgentRunMeta, t as AGENT_TRACE_SCHEMA_VERSION, u as AgentUserInputExecutor, v as createAgentActor, w as AgentStateRequest, x as runAgent, y as generateResult, z as ReplayOptions } from "./run-agent-COHoCgQd.mjs";
6
6
  import { AnyActorLogic, AnyMachineSnapshot, AnySetupConfig, AnyStateMachine, AsyncActorLogic, EventFromLogic, EventObject, InputFrom, MachineContext, MetaObject, NonReducibleUnknown, SetupReturnFromConfig, SetupStateSchema, SnapshotFrom, StateValue } from "xstate";
7
7
 
8
8
  //#region src/messages.d.ts
@@ -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
@@ -623,7 +644,7 @@ interface ProvideExecutorsOptions<TMachine extends AnyStateMachine = AnyStateMac
623
644
  * Throws at bind time if a source needs an executor kind that `executors` does
624
645
  * not provide.
625
646
  *
626
- * v1 does NOT descend into invoked child state machines: a string-keyed child
647
+ * `provideExecutors` does not descend into invoked child state machines: a string-keyed child
627
648
  * machine source is left untouched, so a child with its own agent invokes needs
628
649
  * its own `provideExecutors(...)` (or `runAgent`, which does rebind children).
629
650
  */
@@ -877,7 +898,10 @@ interface TrajectoryMatch {
877
898
  matchedCount: number;
878
899
  /** `expected.length`, so a scorer can compute its own ratio. */
879
900
  expectedCount: number;
880
- /** Partial credit, 0..1. `1` for an empty expectation. */
901
+ /**
902
+ * Partial credit, 0..1. `1` for an empty expectation. Denominator is
903
+ * `max(expectedCount, actual.length)` in `exact` mode, `expectedCount` otherwise.
904
+ */
881
905
  score: number;
882
906
  /** Absent when `matched`. */
883
907
  firstMiss?: TrajectoryMiss;
@@ -927,7 +951,6 @@ type ScriptedDecisionValue = ChosenEvent | {
927
951
  event: ChosenEvent;
928
952
  reason?: string;
929
953
  usage?: AgentCallUsage;
930
- [key: string]: unknown;
931
954
  };
932
955
  /**
933
956
  * One entry in the `decisions` queue: a scripted answer, or a function of the
@@ -987,6 +1010,101 @@ interface ScriptedExecutorsScript {
987
1010
  */
988
1011
  declare function createScriptedExecutors(script?: ScriptedExecutorsScript): Required<AgentRequestExecutors>;
989
1012
  //#endregion
1013
+ //#region src/utils.d.ts
1014
+ /**
1015
+ * Deep-clones a snapshot to a plain-JSON value via a `JSON` round-trip, the
1016
+ * shape you persist and later feed back to `runAgent({ snapshot })`. Asserts
1017
+ * JSON-serializability: functions, `undefined`, and other non-JSON values are
1018
+ * dropped or throw exactly as `JSON.stringify`/`JSON.parse` would. Returns a
1019
+ * plain-JSON deep clone, not a live snapshot.
1020
+ */
1021
+ declare function persistSnapshot<TSnapshot>(snapshot: TSnapshot): TSnapshot;
1022
+ /**
1023
+ * A stable, dependency-free structural fingerprint of a machine — a short hex
1024
+ * `djb2` hash over its **structural** config only: state ids/nesting, transition
1025
+ * event types and targets, invoke `src`s, `initial`, and any other serializable
1026
+ * config fields. Function values (context/output builders, prompts, inline
1027
+ * guards/actions) are excluded entirely, so two machines that differ only in
1028
+ * their prompts or executors hash identically; adding/removing/retargeting a
1029
+ * state or transition changes the hash.
1030
+ *
1031
+ * Used by {@link runAgent} to stamp settled snapshots with a `version` and to
1032
+ * detect a structurally-edited machine on resume. It is a change detector, not
1033
+ * a cryptographic digest — collisions are possible but unlikely for real
1034
+ * configs. Pass an explicit `machineVersion` to `runAgent` to override it.
1035
+ */
1036
+ declare function getMachineStructuralHash(machine: AnyStateMachine): string;
1037
+ /** Builds a {@link UserMessage} from a string or multimodal content parts. */
1038
+ declare function userMessage(content: string | Array<TextPart | ImagePart | FilePart>): UserMessage;
1039
+ /** Builds an {@link AssistantMessage} from a string or content parts (text, files, tool calls/results). */
1040
+ declare function assistantMessage(content: string | Array<TextPart | FilePart | ToolCallPart | ToolResultPart>): AssistantMessage;
1041
+ /** Builds a {@link SystemMessage}. */
1042
+ declare function systemMessage(content: string): SystemMessage;
1043
+ /** Builds a {@link ToolMessage} from one or more tool-result parts. */
1044
+ declare function toolMessage(content: Array<ToolResultPart>): ToolMessage;
1045
+ type MetaOfSnapshot<TSnapshot extends {
1046
+ getMeta(): Record<string, unknown>;
1047
+ }> = NonNullable<ReturnType<TSnapshot["getMeta"]>[keyof ReturnType<TSnapshot["getMeta"]>]>;
1048
+ /**
1049
+ * Returns the merged `meta` of a snapshot's active state(s) — the typed
1050
+ * replacement for the `Object.values(snapshot.getMeta())[0]` dance.
1051
+ *
1052
+ * `snapshot.getMeta()` is keyed by state id; a leaf machine has one active
1053
+ * state, but parallel/nested machines can have several. This shallow-merges
1054
+ * every active state's meta into one object (later/deeper entries win) and
1055
+ * returns `{}` when no active state declares meta.
1056
+ *
1057
+ * The return type is recovered from the snapshot's own `getMeta()` type, so a
1058
+ * schema-typed machine (`setupAgent({ meta })`) yields the meta schema's
1059
+ * output type. Pass an explicit `TMeta` to override when the snapshot is
1060
+ * untyped (e.g. `AnyMachineSnapshot`).
1061
+ *
1062
+ * @example HITL: read the current state's interaction protocol off an idle
1063
+ * snapshot to render for a human.
1064
+ * ```ts
1065
+ * const { interaction } = getStateMeta(result.snapshot);
1066
+ * ```
1067
+ */
1068
+ declare function getStateMeta<TSnapshot extends {
1069
+ getMeta(): Record<string, unknown>;
1070
+ } = AnyMachineSnapshot, TMeta = MetaOfSnapshot<TSnapshot>>(snapshot: TSnapshot): Partial<TMeta>;
1071
+ /**
1072
+ * Reads the run-owned message log off a snapshot settled by a `runAgent` call
1073
+ * that used `getRequests` (or `options.messages`) — the typed replacement for
1074
+ * the `(snapshot as { messages?: AgentMessage[] }).messages` cast. runAgent
1075
+ * stamps the log as a plain enumerable `messages` property (like `agentMeta`),
1076
+ * so it survives a JSON persist/resume round-trip; this accessor works on the
1077
+ * live settled snapshot and on a JSON-parsed persisted one alike. Returns `[]`
1078
+ * when no log was stamped (e.g. a default invoke-driven run).
1079
+ *
1080
+ * The write path is `runAgent(..., { messages })`: an explicit seed that
1081
+ * overrides the resume snapshot's stamped log (fold in a user reply on
1082
+ * resume, or start a run with prior history).
1083
+ */
1084
+ declare function getAgentMessages(snapshot: unknown): AgentMessage[];
1085
+ /**
1086
+ * Structural guard for a {@link StandardSchemaV1}: `true` when `value` carries
1087
+ * the `~standard` marker. Used to tell an already-schema'd tool `inputSchema`
1088
+ * (a Zod/Valibot/… schema) apart from an SDK-specific schema wrapper that core
1089
+ * can't read directly — see the `ai-sdk` tool pass-through.
1090
+ */
1091
+ declare function isStandardSchema(value: unknown): value is StandardSchemaV1;
1092
+ /**
1093
+ * Pulls the JSON Schema off a {@link StandardSchemaV1} via its optional
1094
+ * `~standard.jsonSchema.input()` extension (implemented by e.g. Zod v4's
1095
+ * `z.toJSONSchema`), awaiting it when the producer is async. Returns
1096
+ * `undefined` when the schema doesn't expose the extension. Use this to build
1097
+ * a provider request's `response_format`/tool `parameters` from a schema.
1098
+ */
1099
+ declare function getJsonSchema(schema?: StandardSchemaV1): Promise<Record<string, unknown> | undefined>;
1100
+ /**
1101
+ * Synchronous variant of {@link getJsonSchema}, for call sites that can't
1102
+ * await (building tool/event descriptors inline). An async JSON Schema
1103
+ * producer is treated as absent (returns `undefined`) — in practice Zod's
1104
+ * `z.toJSONSchema` resolves synchronously.
1105
+ */
1106
+ declare function getJsonSchemaSync(schema?: StandardSchemaV1): Record<string, unknown> | undefined;
1107
+ //#endregion
990
1108
  //#region src/seam.d.ts
991
1109
  /**
992
1110
  * Which model call is under test: the Nth call addressed either by request
@@ -1014,8 +1132,11 @@ interface SeamTurn<TMachine extends AnyStateMachine> {
1014
1132
  snapshot: SnapshotFrom<TMachine>;
1015
1133
  /** Its state value, for a `switch` on flat machines. */
1016
1134
  state: StateValue;
1017
- /** The merged `meta` of the active state(s) — e.g. a declared `interaction`. */
1018
- meta: Record<string, unknown>;
1135
+ /**
1136
+ * The merged `meta` of the active state(s), e.g. a declared `interaction`.
1137
+ * Typed from the machine's own meta schema (`setupAgent({ meta })`).
1138
+ */
1139
+ meta: Partial<MetaOfSnapshot<SnapshotFrom<TMachine>>>;
1019
1140
  /** 0-based index of this pause within the run. */
1020
1141
  turn: number;
1021
1142
  /** The `idle` result that produced the pause. */
@@ -1120,99 +1241,4 @@ interface RunSeamResult<TMachine extends AnyStateMachine> {
1120
1241
  */
1121
1242
  declare function runSeam<TMachine extends AnyStateMachine>(machine: TMachine, options: RunSeamOptions<TMachine>): Promise<RunSeamResult<TMachine>>;
1122
1243
  //#endregion
1123
- //#region src/utils.d.ts
1124
- /**
1125
- * Deep-clones a snapshot to a plain-JSON value via a `JSON` round-trip, the
1126
- * shape you persist and later feed back to `runAgent({ snapshot })`. Asserts
1127
- * JSON-serializability: functions, `undefined`, and other non-JSON values are
1128
- * dropped or throw exactly as `JSON.stringify`/`JSON.parse` would. Returns a
1129
- * plain-JSON deep clone, not a live snapshot.
1130
- */
1131
- declare function persistSnapshot<TSnapshot>(snapshot: TSnapshot): TSnapshot;
1132
- /**
1133
- * A stable, dependency-free structural fingerprint of a machine — a short hex
1134
- * `djb2` hash over its **structural** config only: state ids/nesting, transition
1135
- * event types and targets, invoke `src`s, `initial`, and any other serializable
1136
- * config fields. Function values (context/output builders, prompts, inline
1137
- * guards/actions) are excluded entirely, so two machines that differ only in
1138
- * their prompts or executors hash identically; adding/removing/retargeting a
1139
- * state or transition changes the hash.
1140
- *
1141
- * Used by {@link runAgent} to stamp settled snapshots with a `version` and to
1142
- * detect a structurally-edited machine on resume. It is a change detector, not
1143
- * a cryptographic digest — collisions are possible but unlikely for real
1144
- * configs. Pass an explicit `machineVersion` to `runAgent` to override it.
1145
- */
1146
- declare function getMachineStructuralHash(machine: AnyStateMachine): string;
1147
- /** Builds a {@link UserMessage} from a string or multimodal content parts. */
1148
- declare function userMessage(content: string | Array<TextPart | ImagePart | FilePart>): UserMessage;
1149
- /** Builds an {@link AssistantMessage} from a string or content parts (text, files, tool calls/results). */
1150
- declare function assistantMessage(content: string | Array<TextPart | FilePart | ToolCallPart | ToolResultPart>): AssistantMessage;
1151
- /** Builds a {@link SystemMessage}. */
1152
- declare function systemMessage(content: string): SystemMessage;
1153
- /** Builds a {@link ToolMessage} from one or more tool-result parts. */
1154
- declare function toolMessage(content: Array<ToolResultPart>): ToolMessage;
1155
- type MetaOfSnapshot<TSnapshot extends {
1156
- getMeta(): Record<string, unknown>;
1157
- }> = NonNullable<ReturnType<TSnapshot["getMeta"]>[keyof ReturnType<TSnapshot["getMeta"]>]>;
1158
- /**
1159
- * Returns the merged `meta` of a snapshot's active state(s) — the typed
1160
- * replacement for the `Object.values(snapshot.getMeta())[0]` dance.
1161
- *
1162
- * `snapshot.getMeta()` is keyed by state id; a leaf machine has one active
1163
- * state, but parallel/nested machines can have several. This shallow-merges
1164
- * every active state's meta into one object (later/deeper entries win) and
1165
- * returns `{}` when no active state declares meta.
1166
- *
1167
- * The return type is recovered from the snapshot's own `getMeta()` type, so a
1168
- * schema-typed machine (`setupAgent({ meta })`) yields the meta schema's
1169
- * output type. Pass an explicit `TMeta` to override when the snapshot is
1170
- * untyped (e.g. `AnyMachineSnapshot`).
1171
- *
1172
- * @example HITL: read the current state's interaction protocol off an idle
1173
- * snapshot to render for a human.
1174
- * ```ts
1175
- * const { interaction } = getStateMeta(result.snapshot);
1176
- * ```
1177
- */
1178
- declare function getStateMeta<TSnapshot extends {
1179
- getMeta(): Record<string, unknown>;
1180
- } = AnyMachineSnapshot, TMeta = MetaOfSnapshot<TSnapshot>>(snapshot: TSnapshot): Partial<TMeta>;
1181
- /**
1182
- * Reads the run-owned message log off a snapshot settled by a `runAgent` call
1183
- * that used `getRequests` (or `options.messages`) — the typed replacement for
1184
- * the `(snapshot as { messages?: AgentMessage[] }).messages` cast. runAgent
1185
- * stamps the log as a plain enumerable `messages` property (like `agentMeta`),
1186
- * so it survives a JSON persist/resume round-trip; this accessor works on the
1187
- * live settled snapshot and on a JSON-parsed persisted one alike. Returns `[]`
1188
- * when no log was stamped (e.g. a default invoke-driven run).
1189
- *
1190
- * The write path is `runAgent(..., { messages })`: an explicit seed that
1191
- * overrides the resume snapshot's stamped log (fold in a user reply on
1192
- * resume, or start a run with prior history).
1193
- */
1194
- declare function getAgentMessages(snapshot: unknown): AgentMessage[];
1195
- /**
1196
- * Structural guard for a {@link StandardSchemaV1}: `true` when `value` carries
1197
- * the `~standard` marker. Used to tell an already-schema'd tool `inputSchema`
1198
- * (a Zod/Valibot/… schema) apart from an SDK-specific schema wrapper that core
1199
- * can't read directly — see the `ai-sdk` tool pass-through.
1200
- */
1201
- declare function isStandardSchema(value: unknown): value is StandardSchemaV1;
1202
- /**
1203
- * Pulls the JSON Schema off a {@link StandardSchemaV1} via its optional
1204
- * `~standard.jsonSchema.input()` extension (implemented by e.g. Zod v4's
1205
- * `z.toJSONSchema`), awaiting it when the producer is async. Returns
1206
- * `undefined` when the schema doesn't expose the extension. Use this to build
1207
- * a provider request's `response_format`/tool `parameters` from a schema.
1208
- */
1209
- declare function getJsonSchema(schema?: StandardSchemaV1): Promise<Record<string, unknown> | undefined>;
1210
- /**
1211
- * Synchronous variant of {@link getJsonSchema}, for call sites that can't
1212
- * await (building tool/event descriptors inline). An async JSON Schema
1213
- * producer is treated as absent (returns `undefined`) — in practice Zod's
1214
- * `z.toJSONSchema` resolves synchronously.
1215
- */
1216
- declare function getJsonSchemaSync(schema?: StandardSchemaV1): Record<string, unknown> | undefined;
1217
- //#endregion
1218
1244
  export { AGENT_EVENT_SCHEMA_VERSION, AGENT_INIT_EVENT_TYPE, AGENT_TRACE_SCHEMA_VERSION, AGENT_USAGE_EVENT_TYPE, type AgentActorSession, type AgentCallUsage, type AgentDecisionExecutor, AgentDecisionExhaustedError, type AgentDecisionInput, type AgentDecisionRequest, type AgentEffect, type AgentEffectDiff, AgentError, type AgentEventDescriptor, AgentEventLogConflictError, type AgentEventLogDiff, type AgentEventLogStore, type AgentEventToolNameResolver, type AgentExecutorTextRequest, AgentIdleError, AgentIllegalResumeEventError, type AgentInputFrom, type AgentLintDiagnostic, AgentLintError, type AgentLintSeverity, type AgentLogEntry, type AgentLogPatchOperation, type AgentLogVerification, type AgentMessage, type AgentMessageInfo, type AgentModelRef, type AgentOutputMode, type AgentPathReport, type AgentPathTerminal, AgentReplayDivergenceError, AgentReplayMachineMismatchError, type AgentRequest, type AgentRequestExecutor, type AgentRequestExecutorInfo, type AgentRequestExecutorResult, type AgentRequestExecutors, type AgentRequestOptions, type AgentRequestSource, type AgentRun, type AgentRunMeta, type AgentSchemaPack, type AgentSnapshotStore, AgentSnapshotVersionMismatchError, type AgentStateRequest, type AgentStepRequest, type AgentTextRequest, type AgentTool, type AgentToolChoice, type AgentToolDescriptor, type AgentToolExecute, type AgentTools, type AgentTraceEvent, type AgentUsage, type AgentUsageEvent, type AgentUsageEventPayload, type AgentUserInput, type AgentUserInputExecutor, type AgentWorkflowActionConfig, type AgentWorkflowActorConfig, type AgentWorkflowConfig, type AgentWorkflowInvokeConfig, type AgentWorkflowRequestConfig, type AgentWorkflowStateConfig, type AgentWorkflowTransitionConfig, type AiSdkShapedStreamResult, type AiSdkShapedTextResult, type AllowedEvents, type AssertAgentMachineOptions, type AssistantMessage, type CanReachResult, type ChosenEvent, type CreateReplayEntryOptions, type DecisionAttempt, type DecisionLogicConfig, type ExplorePathsOptions, type FilePart, type FromConfigOptions, type FromConfigResult, type GenerateResult, type GetAgentEffectsOptions, type ImagePart, type InferInput, type InferOutput, type InspectedActorRef, type JsonSerializableTraceEvent, type JsonValue, type LintAgentMachineOptions, type MatchTrajectoryOptions, NonSerializableAgentEventError, type PendingUserInput, type ProvideExecutorsOptions, type ReplayOptions, type ReplayResult, type ResolveDecisionOptions, type RunAgentErrorCause, type RunAgentOptions, type RunAgentResult, type RunSeamOptions, type RunSeamResult, type SchemaCompiler, type ScriptedDecisionEntry, type ScriptedDecisionValue, type ScriptedExecutorsScript, type ScriptedTextEntry, type SeamRef, type SeamSlice, type SeamTurn, type SimulateAgentOptions, type SimulateAgentResult, type SimulationScript, type SimulationTrailEntry, type StandardSchemaV1, type StructuredOutputEnvelope, type SystemMessage, type TextLogic, type TextLogicConfig, type TextLogicExecuteArgs, type TextLogicExecutor, type TextPart, type ToolCallPart, type ToolMessage, type ToolResultPart, type TrajectoryEvent, type TrajectoryItem, type TrajectoryMatch, type TrajectoryMiss, type UserMessage, type WithAgentUsageEvent, appendMessages, assertAgentLogEntry, assertAgentMachine, assertEventLogStoreConformance, assertJsonSerializable, assistantMessage, bindRequestExecutor, buildEnvelopeSchema, canReach, createAgentActor, createAgentRun, createAgentSchemas, createInMemoryEventLogStore, createReplayEntry, createScriptedExecutors, createTextLogic, diffEventLogs, executeAgentRequest, explorePaths, generateResult, getAcceptedEvents, getAgentEffects, getAgentMessages, getAgentOutputMode, getCallUsage, getJsonSchema, getJsonSchemaSync, getMachineStructuralHash, getStateMeta, initEntry, inspectTransitions, isStandardSchema, lintAgentMachine, matchesTrajectory, messagesSchema, parseAgentEvent, parseModelRef, parseOutput, parseStructuredEnvelope, persistSnapshot, provideExecutors, renderDecisionAttempts, replay, resolveDecision, runAgent, runSeam, serializeTraceEvent, setupAgent, simulateAgent, systemMessage, toolMessage, traceTransitions, userMessage, verifyReplay };