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

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-C0cUKvNt.cjs → decision-Ba8qrT8r.cjs} +42 -28
  6. package/dist/{decision-D9Zi7Xi5.mjs → decision-Bt2HYYRo.mjs} +31 -23
  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 +109 -104
  13. package/dist/index.d.mts +109 -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-CpK0ZRWV.cjs → setup-agent-BLU77gqr.cjs} +141 -172
  24. package/dist/{setup-agent-DeHRW-qX.mjs → setup-agent-SbiiSbAU.mjs} +136 -167
  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 +1 -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
@@ -623,7 +623,7 @@ interface ProvideExecutorsOptions<TMachine extends AnyStateMachine = AnyStateMac
623
623
  * Throws at bind time if a source needs an executor kind that `executors` does
624
624
  * not provide.
625
625
  *
626
- * v1 does NOT descend into invoked child state machines: a string-keyed child
626
+ * `provideExecutors` does not descend into invoked child state machines: a string-keyed child
627
627
  * machine source is left untouched, so a child with its own agent invokes needs
628
628
  * its own `provideExecutors(...)` (or `runAgent`, which does rebind children).
629
629
  */
@@ -877,7 +877,10 @@ interface TrajectoryMatch {
877
877
  matchedCount: number;
878
878
  /** `expected.length`, so a scorer can compute its own ratio. */
879
879
  expectedCount: number;
880
- /** Partial credit, 0..1. `1` for an empty expectation. */
880
+ /**
881
+ * Partial credit, 0..1. `1` for an empty expectation. Denominator is
882
+ * `max(expectedCount, actual.length)` in `exact` mode, `expectedCount` otherwise.
883
+ */
881
884
  score: number;
882
885
  /** Absent when `matched`. */
883
886
  firstMiss?: TrajectoryMiss;
@@ -927,7 +930,6 @@ type ScriptedDecisionValue = ChosenEvent | {
927
930
  event: ChosenEvent;
928
931
  reason?: string;
929
932
  usage?: AgentCallUsage;
930
- [key: string]: unknown;
931
933
  };
932
934
  /**
933
935
  * One entry in the `decisions` queue: a scripted answer, or a function of the
@@ -987,6 +989,101 @@ interface ScriptedExecutorsScript {
987
989
  */
988
990
  declare function createScriptedExecutors(script?: ScriptedExecutorsScript): Required<AgentRequestExecutors>;
989
991
  //#endregion
992
+ //#region src/utils.d.ts
993
+ /**
994
+ * Deep-clones a snapshot to a plain-JSON value via a `JSON` round-trip, the
995
+ * shape you persist and later feed back to `runAgent({ snapshot })`. Asserts
996
+ * JSON-serializability: functions, `undefined`, and other non-JSON values are
997
+ * dropped or throw exactly as `JSON.stringify`/`JSON.parse` would. Returns a
998
+ * plain-JSON deep clone, not a live snapshot.
999
+ */
1000
+ declare function persistSnapshot<TSnapshot>(snapshot: TSnapshot): TSnapshot;
1001
+ /**
1002
+ * A stable, dependency-free structural fingerprint of a machine — a short hex
1003
+ * `djb2` hash over its **structural** config only: state ids/nesting, transition
1004
+ * event types and targets, invoke `src`s, `initial`, and any other serializable
1005
+ * config fields. Function values (context/output builders, prompts, inline
1006
+ * guards/actions) are excluded entirely, so two machines that differ only in
1007
+ * their prompts or executors hash identically; adding/removing/retargeting a
1008
+ * state or transition changes the hash.
1009
+ *
1010
+ * Used by {@link runAgent} to stamp settled snapshots with a `version` and to
1011
+ * detect a structurally-edited machine on resume. It is a change detector, not
1012
+ * a cryptographic digest — collisions are possible but unlikely for real
1013
+ * configs. Pass an explicit `machineVersion` to `runAgent` to override it.
1014
+ */
1015
+ declare function getMachineStructuralHash(machine: AnyStateMachine): string;
1016
+ /** Builds a {@link UserMessage} from a string or multimodal content parts. */
1017
+ declare function userMessage(content: string | Array<TextPart | ImagePart | FilePart>): UserMessage;
1018
+ /** Builds an {@link AssistantMessage} from a string or content parts (text, files, tool calls/results). */
1019
+ declare function assistantMessage(content: string | Array<TextPart | FilePart | ToolCallPart | ToolResultPart>): AssistantMessage;
1020
+ /** Builds a {@link SystemMessage}. */
1021
+ declare function systemMessage(content: string): SystemMessage;
1022
+ /** Builds a {@link ToolMessage} from one or more tool-result parts. */
1023
+ declare function toolMessage(content: Array<ToolResultPart>): ToolMessage;
1024
+ type MetaOfSnapshot<TSnapshot extends {
1025
+ getMeta(): Record<string, unknown>;
1026
+ }> = NonNullable<ReturnType<TSnapshot["getMeta"]>[keyof ReturnType<TSnapshot["getMeta"]>]>;
1027
+ /**
1028
+ * Returns the merged `meta` of a snapshot's active state(s) — the typed
1029
+ * replacement for the `Object.values(snapshot.getMeta())[0]` dance.
1030
+ *
1031
+ * `snapshot.getMeta()` is keyed by state id; a leaf machine has one active
1032
+ * state, but parallel/nested machines can have several. This shallow-merges
1033
+ * every active state's meta into one object (later/deeper entries win) and
1034
+ * returns `{}` when no active state declares meta.
1035
+ *
1036
+ * The return type is recovered from the snapshot's own `getMeta()` type, so a
1037
+ * schema-typed machine (`setupAgent({ meta })`) yields the meta schema's
1038
+ * output type. Pass an explicit `TMeta` to override when the snapshot is
1039
+ * untyped (e.g. `AnyMachineSnapshot`).
1040
+ *
1041
+ * @example HITL: read the current state's interaction protocol off an idle
1042
+ * snapshot to render for a human.
1043
+ * ```ts
1044
+ * const { interaction } = getStateMeta(result.snapshot);
1045
+ * ```
1046
+ */
1047
+ declare function getStateMeta<TSnapshot extends {
1048
+ getMeta(): Record<string, unknown>;
1049
+ } = AnyMachineSnapshot, TMeta = MetaOfSnapshot<TSnapshot>>(snapshot: TSnapshot): Partial<TMeta>;
1050
+ /**
1051
+ * Reads the run-owned message log off a snapshot settled by a `runAgent` call
1052
+ * that used `getRequests` (or `options.messages`) — the typed replacement for
1053
+ * the `(snapshot as { messages?: AgentMessage[] }).messages` cast. runAgent
1054
+ * stamps the log as a plain enumerable `messages` property (like `agentMeta`),
1055
+ * so it survives a JSON persist/resume round-trip; this accessor works on the
1056
+ * live settled snapshot and on a JSON-parsed persisted one alike. Returns `[]`
1057
+ * when no log was stamped (e.g. a default invoke-driven run).
1058
+ *
1059
+ * The write path is `runAgent(..., { messages })`: an explicit seed that
1060
+ * overrides the resume snapshot's stamped log (fold in a user reply on
1061
+ * resume, or start a run with prior history).
1062
+ */
1063
+ declare function getAgentMessages(snapshot: unknown): AgentMessage[];
1064
+ /**
1065
+ * Structural guard for a {@link StandardSchemaV1}: `true` when `value` carries
1066
+ * the `~standard` marker. Used to tell an already-schema'd tool `inputSchema`
1067
+ * (a Zod/Valibot/… schema) apart from an SDK-specific schema wrapper that core
1068
+ * can't read directly — see the `ai-sdk` tool pass-through.
1069
+ */
1070
+ declare function isStandardSchema(value: unknown): value is StandardSchemaV1;
1071
+ /**
1072
+ * Pulls the JSON Schema off a {@link StandardSchemaV1} via its optional
1073
+ * `~standard.jsonSchema.input()` extension (implemented by e.g. Zod v4's
1074
+ * `z.toJSONSchema`), awaiting it when the producer is async. Returns
1075
+ * `undefined` when the schema doesn't expose the extension. Use this to build
1076
+ * a provider request's `response_format`/tool `parameters` from a schema.
1077
+ */
1078
+ declare function getJsonSchema(schema?: StandardSchemaV1): Promise<Record<string, unknown> | undefined>;
1079
+ /**
1080
+ * Synchronous variant of {@link getJsonSchema}, for call sites that can't
1081
+ * await (building tool/event descriptors inline). An async JSON Schema
1082
+ * producer is treated as absent (returns `undefined`) — in practice Zod's
1083
+ * `z.toJSONSchema` resolves synchronously.
1084
+ */
1085
+ declare function getJsonSchemaSync(schema?: StandardSchemaV1): Record<string, unknown> | undefined;
1086
+ //#endregion
990
1087
  //#region src/seam.d.ts
991
1088
  /**
992
1089
  * Which model call is under test: the Nth call addressed either by request
@@ -1014,8 +1111,11 @@ interface SeamTurn<TMachine extends AnyStateMachine> {
1014
1111
  snapshot: SnapshotFrom<TMachine>;
1015
1112
  /** Its state value, for a `switch` on flat machines. */
1016
1113
  state: StateValue;
1017
- /** The merged `meta` of the active state(s) — e.g. a declared `interaction`. */
1018
- meta: Record<string, unknown>;
1114
+ /**
1115
+ * The merged `meta` of the active state(s), e.g. a declared `interaction`.
1116
+ * Typed from the machine's own meta schema (`setupAgent({ meta })`).
1117
+ */
1118
+ meta: Partial<MetaOfSnapshot<SnapshotFrom<TMachine>>>;
1019
1119
  /** 0-based index of this pause within the run. */
1020
1120
  turn: number;
1021
1121
  /** The `idle` result that produced the pause. */
@@ -1120,99 +1220,4 @@ interface RunSeamResult<TMachine extends AnyStateMachine> {
1120
1220
  */
1121
1221
  declare function runSeam<TMachine extends AnyStateMachine>(machine: TMachine, options: RunSeamOptions<TMachine>): Promise<RunSeamResult<TMachine>>;
1122
1222
  //#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
1223
  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
@@ -623,7 +623,7 @@ interface ProvideExecutorsOptions<TMachine extends AnyStateMachine = AnyStateMac
623
623
  * Throws at bind time if a source needs an executor kind that `executors` does
624
624
  * not provide.
625
625
  *
626
- * v1 does NOT descend into invoked child state machines: a string-keyed child
626
+ * `provideExecutors` does not descend into invoked child state machines: a string-keyed child
627
627
  * machine source is left untouched, so a child with its own agent invokes needs
628
628
  * its own `provideExecutors(...)` (or `runAgent`, which does rebind children).
629
629
  */
@@ -877,7 +877,10 @@ interface TrajectoryMatch {
877
877
  matchedCount: number;
878
878
  /** `expected.length`, so a scorer can compute its own ratio. */
879
879
  expectedCount: number;
880
- /** Partial credit, 0..1. `1` for an empty expectation. */
880
+ /**
881
+ * Partial credit, 0..1. `1` for an empty expectation. Denominator is
882
+ * `max(expectedCount, actual.length)` in `exact` mode, `expectedCount` otherwise.
883
+ */
881
884
  score: number;
882
885
  /** Absent when `matched`. */
883
886
  firstMiss?: TrajectoryMiss;
@@ -927,7 +930,6 @@ type ScriptedDecisionValue = ChosenEvent | {
927
930
  event: ChosenEvent;
928
931
  reason?: string;
929
932
  usage?: AgentCallUsage;
930
- [key: string]: unknown;
931
933
  };
932
934
  /**
933
935
  * One entry in the `decisions` queue: a scripted answer, or a function of the
@@ -987,6 +989,101 @@ interface ScriptedExecutorsScript {
987
989
  */
988
990
  declare function createScriptedExecutors(script?: ScriptedExecutorsScript): Required<AgentRequestExecutors>;
989
991
  //#endregion
992
+ //#region src/utils.d.ts
993
+ /**
994
+ * Deep-clones a snapshot to a plain-JSON value via a `JSON` round-trip, the
995
+ * shape you persist and later feed back to `runAgent({ snapshot })`. Asserts
996
+ * JSON-serializability: functions, `undefined`, and other non-JSON values are
997
+ * dropped or throw exactly as `JSON.stringify`/`JSON.parse` would. Returns a
998
+ * plain-JSON deep clone, not a live snapshot.
999
+ */
1000
+ declare function persistSnapshot<TSnapshot>(snapshot: TSnapshot): TSnapshot;
1001
+ /**
1002
+ * A stable, dependency-free structural fingerprint of a machine — a short hex
1003
+ * `djb2` hash over its **structural** config only: state ids/nesting, transition
1004
+ * event types and targets, invoke `src`s, `initial`, and any other serializable
1005
+ * config fields. Function values (context/output builders, prompts, inline
1006
+ * guards/actions) are excluded entirely, so two machines that differ only in
1007
+ * their prompts or executors hash identically; adding/removing/retargeting a
1008
+ * state or transition changes the hash.
1009
+ *
1010
+ * Used by {@link runAgent} to stamp settled snapshots with a `version` and to
1011
+ * detect a structurally-edited machine on resume. It is a change detector, not
1012
+ * a cryptographic digest — collisions are possible but unlikely for real
1013
+ * configs. Pass an explicit `machineVersion` to `runAgent` to override it.
1014
+ */
1015
+ declare function getMachineStructuralHash(machine: AnyStateMachine): string;
1016
+ /** Builds a {@link UserMessage} from a string or multimodal content parts. */
1017
+ declare function userMessage(content: string | Array<TextPart | ImagePart | FilePart>): UserMessage;
1018
+ /** Builds an {@link AssistantMessage} from a string or content parts (text, files, tool calls/results). */
1019
+ declare function assistantMessage(content: string | Array<TextPart | FilePart | ToolCallPart | ToolResultPart>): AssistantMessage;
1020
+ /** Builds a {@link SystemMessage}. */
1021
+ declare function systemMessage(content: string): SystemMessage;
1022
+ /** Builds a {@link ToolMessage} from one or more tool-result parts. */
1023
+ declare function toolMessage(content: Array<ToolResultPart>): ToolMessage;
1024
+ type MetaOfSnapshot<TSnapshot extends {
1025
+ getMeta(): Record<string, unknown>;
1026
+ }> = NonNullable<ReturnType<TSnapshot["getMeta"]>[keyof ReturnType<TSnapshot["getMeta"]>]>;
1027
+ /**
1028
+ * Returns the merged `meta` of a snapshot's active state(s) — the typed
1029
+ * replacement for the `Object.values(snapshot.getMeta())[0]` dance.
1030
+ *
1031
+ * `snapshot.getMeta()` is keyed by state id; a leaf machine has one active
1032
+ * state, but parallel/nested machines can have several. This shallow-merges
1033
+ * every active state's meta into one object (later/deeper entries win) and
1034
+ * returns `{}` when no active state declares meta.
1035
+ *
1036
+ * The return type is recovered from the snapshot's own `getMeta()` type, so a
1037
+ * schema-typed machine (`setupAgent({ meta })`) yields the meta schema's
1038
+ * output type. Pass an explicit `TMeta` to override when the snapshot is
1039
+ * untyped (e.g. `AnyMachineSnapshot`).
1040
+ *
1041
+ * @example HITL: read the current state's interaction protocol off an idle
1042
+ * snapshot to render for a human.
1043
+ * ```ts
1044
+ * const { interaction } = getStateMeta(result.snapshot);
1045
+ * ```
1046
+ */
1047
+ declare function getStateMeta<TSnapshot extends {
1048
+ getMeta(): Record<string, unknown>;
1049
+ } = AnyMachineSnapshot, TMeta = MetaOfSnapshot<TSnapshot>>(snapshot: TSnapshot): Partial<TMeta>;
1050
+ /**
1051
+ * Reads the run-owned message log off a snapshot settled by a `runAgent` call
1052
+ * that used `getRequests` (or `options.messages`) — the typed replacement for
1053
+ * the `(snapshot as { messages?: AgentMessage[] }).messages` cast. runAgent
1054
+ * stamps the log as a plain enumerable `messages` property (like `agentMeta`),
1055
+ * so it survives a JSON persist/resume round-trip; this accessor works on the
1056
+ * live settled snapshot and on a JSON-parsed persisted one alike. Returns `[]`
1057
+ * when no log was stamped (e.g. a default invoke-driven run).
1058
+ *
1059
+ * The write path is `runAgent(..., { messages })`: an explicit seed that
1060
+ * overrides the resume snapshot's stamped log (fold in a user reply on
1061
+ * resume, or start a run with prior history).
1062
+ */
1063
+ declare function getAgentMessages(snapshot: unknown): AgentMessage[];
1064
+ /**
1065
+ * Structural guard for a {@link StandardSchemaV1}: `true` when `value` carries
1066
+ * the `~standard` marker. Used to tell an already-schema'd tool `inputSchema`
1067
+ * (a Zod/Valibot/… schema) apart from an SDK-specific schema wrapper that core
1068
+ * can't read directly — see the `ai-sdk` tool pass-through.
1069
+ */
1070
+ declare function isStandardSchema(value: unknown): value is StandardSchemaV1;
1071
+ /**
1072
+ * Pulls the JSON Schema off a {@link StandardSchemaV1} via its optional
1073
+ * `~standard.jsonSchema.input()` extension (implemented by e.g. Zod v4's
1074
+ * `z.toJSONSchema`), awaiting it when the producer is async. Returns
1075
+ * `undefined` when the schema doesn't expose the extension. Use this to build
1076
+ * a provider request's `response_format`/tool `parameters` from a schema.
1077
+ */
1078
+ declare function getJsonSchema(schema?: StandardSchemaV1): Promise<Record<string, unknown> | undefined>;
1079
+ /**
1080
+ * Synchronous variant of {@link getJsonSchema}, for call sites that can't
1081
+ * await (building tool/event descriptors inline). An async JSON Schema
1082
+ * producer is treated as absent (returns `undefined`) — in practice Zod's
1083
+ * `z.toJSONSchema` resolves synchronously.
1084
+ */
1085
+ declare function getJsonSchemaSync(schema?: StandardSchemaV1): Record<string, unknown> | undefined;
1086
+ //#endregion
990
1087
  //#region src/seam.d.ts
991
1088
  /**
992
1089
  * Which model call is under test: the Nth call addressed either by request
@@ -1014,8 +1111,11 @@ interface SeamTurn<TMachine extends AnyStateMachine> {
1014
1111
  snapshot: SnapshotFrom<TMachine>;
1015
1112
  /** Its state value, for a `switch` on flat machines. */
1016
1113
  state: StateValue;
1017
- /** The merged `meta` of the active state(s) — e.g. a declared `interaction`. */
1018
- meta: Record<string, unknown>;
1114
+ /**
1115
+ * The merged `meta` of the active state(s), e.g. a declared `interaction`.
1116
+ * Typed from the machine's own meta schema (`setupAgent({ meta })`).
1117
+ */
1118
+ meta: Partial<MetaOfSnapshot<SnapshotFrom<TMachine>>>;
1019
1119
  /** 0-based index of this pause within the run. */
1020
1120
  turn: number;
1021
1121
  /** The `idle` result that produced the pause. */
@@ -1120,99 +1220,4 @@ interface RunSeamResult<TMachine extends AnyStateMachine> {
1120
1220
  */
1121
1221
  declare function runSeam<TMachine extends AnyStateMachine>(machine: TMachine, options: RunSeamOptions<TMachine>): Promise<RunSeamResult<TMachine>>;
1122
1222
  //#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
1223
  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 };