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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/ai-sdk.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { d as ChosenEvent } from "./types-rMe7x6NR.cjs";
2
- import { k as AgentDecisionExecutor, l as AgentRequestExecutors, o as AgentRequestExecutor } from "./text-logic-Jkilp1Ie.cjs";
1
+ import { d as ChosenEvent } from "./types-DFD28AWe.cjs";
2
+ import { k as AgentDecisionExecutor, l as AgentRequestExecutors, o as AgentRequestExecutor } from "./text-logic-DZW7XWy9.cjs";
3
3
  import { FinishReason, LanguageModel, LanguageModelUsage, ToolSet, TypedToolCall, TypedToolResult } from "ai";
4
4
 
5
5
  //#region src/ai-sdk/index.d.ts
package/dist/ai-sdk.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { d as ChosenEvent } from "./types-9Bqg5rZB.mjs";
2
- import { k as AgentDecisionExecutor, l as AgentRequestExecutors, o as AgentRequestExecutor } from "./text-logic-C5kbjaDz.mjs";
1
+ import { d as ChosenEvent } from "./types-CTBhMnFu.mjs";
2
+ import { k as AgentDecisionExecutor, l as AgentRequestExecutors, o as AgentRequestExecutor } from "./text-logic-C7anC7qX.mjs";
3
3
  import { FinishReason, LanguageModel, LanguageModelUsage, ToolSet, TypedToolCall, TypedToolResult } from "ai";
4
4
 
5
5
  //#region src/ai-sdk/index.d.ts
package/dist/index.cjs CHANGED
@@ -767,6 +767,26 @@ function bindDecisionForProvide(machine, logic, executors, options) {
767
767
  return createRunAgentDecisionLogic(logic, provideBindContext(machine, executors, options));
768
768
  }
769
769
  /**
770
+ * Validates `input` against the machine's registered input schema, returning
771
+ * the schema's output — so defaults are filled and transforms applied before
772
+ * the value reaches `createActor` or the replayable event log.
773
+ *
774
+ * Standard Schema only (no validation library is referenced), so this works for
775
+ * whatever the machine was declared with. Omitted input stays omitted rather
776
+ * than being validated as `{}`: "started with no input" keeps meaning what it
777
+ * has always meant, instead of newly failing schemas with required fields.
778
+ */
779
+ function resolveMachineInput(machine, input) {
780
+ if (input === void 0) return input;
781
+ const schema = require_decision.getRegisteredAgentExecutionOptions(machine).schemas?.input;
782
+ if (!require_decision.isStandardSchema(schema)) return input;
783
+ try {
784
+ return require_decision.validateSchemaSync(schema, input);
785
+ } catch (error) {
786
+ throw new require_errors.AgentError("invalid-machine-input", `runAgent: machine input failed validation against the declared input schema: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
787
+ }
788
+ }
789
+ /**
770
790
  * Recursively rebinds an invoked child machine's own agent sources with the
771
791
  * SAME host-backed wrappers runAgent applies to the top-level machine, so a
772
792
  * child's text/stream/decision requests inherit runAgent's executors and
@@ -876,6 +896,7 @@ function createAgentSession(machine, options, lifecycle) {
876
896
  let warnedHeuristicIdle = false;
877
897
  const runId = `run_${nextRunAgentTraceId++}`;
878
898
  let traceSeq = 0;
899
+ const resolvedInput = resolveMachineInput(machine, options.input);
879
900
  const machineId = machine.config.id ?? machine.id ?? "(machine)";
880
901
  const machineVersion = options.machineVersion ?? machine.version ?? require_decision.getMachineStructuralHash(machine);
881
902
  const agentMeta = {
@@ -1070,7 +1091,7 @@ function createAgentSession(machine, options, lifecycle) {
1070
1091
  return entry;
1071
1092
  };
1072
1093
  if (replayEvents.length === 0 && effectiveSnapshot === void 0) {
1073
- const entry = require_setup_agent.initEntry(machine, options.input, { machineVersion });
1094
+ const entry = require_setup_agent.initEntry(machine, resolvedInput, { machineVersion });
1074
1095
  replayEventIds.add(entry.id);
1075
1096
  replayEvents.push(entry);
1076
1097
  options.onEvent?.(entry);
@@ -1208,7 +1229,7 @@ function createAgentSession(machine, options, lifecycle) {
1208
1229
  }, 0);
1209
1230
  };
1210
1231
  actor = (0, xstate.createActor)(boundMachine, {
1211
- input: options.input,
1232
+ input: resolvedInput,
1212
1233
  snapshot: effectiveSnapshot,
1213
1234
  inspect: (event) => {
1214
1235
  if (typeof options.inspect === "function") options.inspect(event);
@@ -1305,7 +1326,7 @@ function createAgentSession(machine, options, lifecycle) {
1305
1326
  }
1306
1327
  onTrace({
1307
1328
  type: "run.start",
1308
- ...options.input !== void 0 ? { input: options.input } : {},
1329
+ ...resolvedInput !== void 0 ? { input: resolvedInput } : {},
1309
1330
  ...effectiveSnapshot !== void 0 ? { snapshot: effectiveSnapshot } : {},
1310
1331
  ...options.event !== void 0 ? { event: options.event } : {}
1311
1332
  });
package/dist/index.d.cts CHANGED
@@ -1,8 +1,8 @@
1
- import { C as UserMessage, S as ToolResultPart, _ as StandardSchemaV1, a as AgentToolChoice, b as ToolCallPart, c as AgentTools, d as ChosenEvent, f as EventUnion, g as NormalizedEventSchemas, h as InferOutput, 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 SystemMessage, x as ToolMessage, y as TextPart } from "./types-rMe7x6NR.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-DFD28AWe.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-Jkilp1Ie.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
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 AgentEffectDiff, B as createReplayEntry, C as AgentStateRequest, D as AGENT_INIT_EVENT_TYPE, E as executeAgentRequest, F as AgentUsageEvent, G as replay, H as getAgentEffects, I as CreateReplayEntryOptions, K as verifyReplay, L as GetAgentEffectsOptions, M as AgentLogPatchOperation, N as AgentReplayDivergenceError, O as AGENT_USAGE_EVENT_TYPE, P as AgentReplayMachineMismatchError, R as ReplayOptions, S as traceTransitions, T as AgentStepRequest, U as getCallUsage, V as diffEventLogs, W as initEntry, _ as createAgentActor, a as AgentMessageInfo, b as runAgent, c as AgentTraceEvent, d as InspectedActorRef, f as JsonSerializableTraceEvent, g as RunAgentResult, h as RunAgentOptions, i as AgentIllegalResumeEventError, j as AgentEventLogDiff, k as AgentEffect, l as AgentUserInputExecutor, m as RunAgentErrorCause, n as AgentActorSession, o as AgentRunMeta, p as PendingUserInput, r as AgentIdleError, s as AgentSnapshotVersionMismatchError, t as AGENT_TRACE_SCHEMA_VERSION, u as GenerateResult, v as generateResult, w as AgentRequest, x as serializeTraceEvent, y as inspectTransitions, z as ReplayResult } from "./run-agent-BlqKwHIF.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";
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
@@ -309,10 +309,27 @@ type AgentSetupEventsSchema<TEventSchemas extends AgentEventSchemaInputMap> = {
309
309
  type AgentSetupEmittedSchema<TEmittedSchemas extends Record<string, StandardSchemaV1>> = [keyof TEmittedSchemas] extends [never] ? {} : {
310
310
  emitted: TEmittedSchemas;
311
311
  };
312
+ /**
313
+ * The input schema as handed to xstate's `setup(...)`, with the machine's input
314
+ * type branded by the schema it came from.
315
+ *
316
+ * XState resolves `schemas.input` to a single type used both by
317
+ * `createActor`'s `input` option and by the `context: ({ input })` factory —
318
+ * and it never validates, so a schema default reads as a required field at the
319
+ * call site while being absent at runtime. `runAgent` validates the input
320
+ * (filling defaults) and reads this brand back through `AgentInputFrom` to
321
+ * accept the schema's looser *input* side, while the factory keeps seeing the
322
+ * validated *output* side.
323
+ *
324
+ * Only object-shaped input is branded: with no declared input schema the
325
+ * resolved type is xstate's `NonReducibleUnknown` (a union including `null`),
326
+ * and intersecting a brand into that collapses members to `never`.
327
+ */
328
+ type BrandedInputSchema<TInputSchema extends StandardSchemaV1> = InferOutput<TInputSchema> extends Record<string, unknown> ? StandardSchemaV1<InferInput<TInputSchema>, InferOutput<TInputSchema> & WithAgentInputSchema<TInputSchema>> : TInputSchema;
312
329
  type AgentSetupXStateConfig<TContextSchema extends StandardSchemaV1<Record<string, unknown>>, TEventSchemas extends AgentEventSchemaInputMap, TActors extends { [K in keyof TActors]: AnyActorLogic }, TRequestSchemas extends AgentRequestSchemaMap, TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TModels extends AgentModelMap, TEmittedSchemas extends Record<string, StandardSchemaV1> = {}, TStateSchemas extends Record<string, SetupStateSchema> = Record<string, SetupStateSchema>> = {
313
330
  schemas: {
314
331
  context: TContextSchema;
315
- input: TInputSchema;
332
+ input: BrandedInputSchema<TInputSchema>;
316
333
  output: TOutputSchema;
317
334
  meta: TMetaSchema;
318
335
  } & AgentSetupEventsSchema<TEventSchemas> & AgentSetupEmittedSchema<TEmittedSchemas>;
@@ -1198,4 +1215,4 @@ declare function getJsonSchema(schema?: StandardSchemaV1): Promise<Record<string
1198
1215
  */
1199
1216
  declare function getJsonSchemaSync(schema?: StandardSchemaV1): Record<string, unknown> | undefined;
1200
1217
  //#endregion
1201
- 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 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 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 };
1218
+ 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 UserMessage, S as ToolResultPart, _ as StandardSchemaV1, a as AgentToolChoice, b as ToolCallPart, c as AgentTools, d as ChosenEvent, f as EventUnion, g as NormalizedEventSchemas, h as InferOutput, 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 SystemMessage, x as ToolMessage, y as TextPart } from "./types-9Bqg5rZB.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-CTBhMnFu.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-C5kbjaDz.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
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 AgentEffectDiff, B as createReplayEntry, C as AgentStateRequest, D as AGENT_INIT_EVENT_TYPE, E as executeAgentRequest, F as AgentUsageEvent, G as replay, H as getAgentEffects, I as CreateReplayEntryOptions, K as verifyReplay, L as GetAgentEffectsOptions, M as AgentLogPatchOperation, N as AgentReplayDivergenceError, O as AGENT_USAGE_EVENT_TYPE, P as AgentReplayMachineMismatchError, R as ReplayOptions, S as traceTransitions, T as AgentStepRequest, U as getCallUsage, V as diffEventLogs, W as initEntry, _ as createAgentActor, a as AgentMessageInfo, b as runAgent, c as AgentTraceEvent, d as InspectedActorRef, f as JsonSerializableTraceEvent, g as RunAgentResult, h as RunAgentOptions, i as AgentIllegalResumeEventError, j as AgentEventLogDiff, k as AgentEffect, l as AgentUserInputExecutor, m as RunAgentErrorCause, n as AgentActorSession, o as AgentRunMeta, p as PendingUserInput, r as AgentIdleError, s as AgentSnapshotVersionMismatchError, t as AGENT_TRACE_SCHEMA_VERSION, u as GenerateResult, v as generateResult, w as AgentRequest, x as serializeTraceEvent, y as inspectTransitions, z as ReplayResult } from "./run-agent-2MnlQTkB.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";
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
@@ -309,10 +309,27 @@ type AgentSetupEventsSchema<TEventSchemas extends AgentEventSchemaInputMap> = {
309
309
  type AgentSetupEmittedSchema<TEmittedSchemas extends Record<string, StandardSchemaV1>> = [keyof TEmittedSchemas] extends [never] ? {} : {
310
310
  emitted: TEmittedSchemas;
311
311
  };
312
+ /**
313
+ * The input schema as handed to xstate's `setup(...)`, with the machine's input
314
+ * type branded by the schema it came from.
315
+ *
316
+ * XState resolves `schemas.input` to a single type used both by
317
+ * `createActor`'s `input` option and by the `context: ({ input })` factory —
318
+ * and it never validates, so a schema default reads as a required field at the
319
+ * call site while being absent at runtime. `runAgent` validates the input
320
+ * (filling defaults) and reads this brand back through `AgentInputFrom` to
321
+ * accept the schema's looser *input* side, while the factory keeps seeing the
322
+ * validated *output* side.
323
+ *
324
+ * Only object-shaped input is branded: with no declared input schema the
325
+ * resolved type is xstate's `NonReducibleUnknown` (a union including `null`),
326
+ * and intersecting a brand into that collapses members to `never`.
327
+ */
328
+ type BrandedInputSchema<TInputSchema extends StandardSchemaV1> = InferOutput<TInputSchema> extends Record<string, unknown> ? StandardSchemaV1<InferInput<TInputSchema>, InferOutput<TInputSchema> & WithAgentInputSchema<TInputSchema>> : TInputSchema;
312
329
  type AgentSetupXStateConfig<TContextSchema extends StandardSchemaV1<Record<string, unknown>>, TEventSchemas extends AgentEventSchemaInputMap, TActors extends { [K in keyof TActors]: AnyActorLogic }, TRequestSchemas extends AgentRequestSchemaMap, TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TModels extends AgentModelMap, TEmittedSchemas extends Record<string, StandardSchemaV1> = {}, TStateSchemas extends Record<string, SetupStateSchema> = Record<string, SetupStateSchema>> = {
313
330
  schemas: {
314
331
  context: TContextSchema;
315
- input: TInputSchema;
332
+ input: BrandedInputSchema<TInputSchema>;
316
333
  output: TOutputSchema;
317
334
  meta: TMetaSchema;
318
335
  } & AgentSetupEventsSchema<TEventSchemas> & AgentSetupEmittedSchema<TEmittedSchemas>;
@@ -1198,4 +1215,4 @@ declare function getJsonSchema(schema?: StandardSchemaV1): Promise<Record<string
1198
1215
  */
1199
1216
  declare function getJsonSchemaSync(schema?: StandardSchemaV1): Record<string, unknown> | undefined;
1200
1217
  //#endregion
1201
- 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 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 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 };
1218
+ 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.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { t as AgentError } from "./errors-CeSXQx0v.mjs";
2
2
  import { _ as resolveAgentStep, a as AgentReplayDivergenceError, b as messagesSchema, c as diffEventLogs, d as initEntry, f as replay, g as initialAgentStep, h as getInvokeEffectMetadata, i as AGENT_USAGE_EVENT_TYPE, l as getAgentEffects, m as executeAgentRequest, n as setupAgent, o as AgentReplayMachineMismatchError, p as verifyReplay, r as AGENT_INIT_EVENT_TYPE, s as createReplayEntry, t as createAgentSchemas, u as getCallUsage, v as transitionAgentStep, y as appendMessages } from "./setup-agent-DeHRW-qX.mjs";
3
- import { A as isUnboundPlaceholder, B as getStateMeta, C as parseStructuredEnvelope, D as getMachineStaticTransitionTargets, E as executorBoundLogics, F as findNonSerializableContextPaths, G as userMessage, H as persistSnapshot, I as getAgentMessages, L as getJsonSchema, O as getMachineSuspensionPredicate, P as assistantMessage, R as getJsonSchemaSync, S as parseOutput, U as systemMessage, V as isStandardSchema, W as toolMessage, _ as extractCallUsage, a as resolveDecision, b as normalizeGeneratorResult, c as AGENT_USAGE_TOKEN_FIELDS, f as bindRequestExecutor, h as createTextLogic, i as renderDecisionAttempts, k as getRegisteredAgentExecutionOptions, o as getAcceptedEvents, p as buildEnvelopeSchema, r as isDecisionLogic, s as parseAgentEvent, t as AgentDecisionExhaustedError, u as INTERPRET_SOURCE, v as getAgentOutputMode, x as parseModelRef, y as isTextLogic, z as getMachineStructuralHash } from "./decision-D9Zi7Xi5.mjs";
3
+ import { A as isUnboundPlaceholder, B as getStateMeta, C as parseStructuredEnvelope, D as getMachineStaticTransitionTargets, E as executorBoundLogics, F as findNonSerializableContextPaths, G as userMessage, H as persistSnapshot, I as getAgentMessages, K as validateSchemaSync, L as getJsonSchema, O as getMachineSuspensionPredicate, P as assistantMessage, R as getJsonSchemaSync, S as parseOutput, U as systemMessage, V as isStandardSchema, W as toolMessage, _ as extractCallUsage, a as resolveDecision, b as normalizeGeneratorResult, c as AGENT_USAGE_TOKEN_FIELDS, f as bindRequestExecutor, h as createTextLogic, i as renderDecisionAttempts, k as getRegisteredAgentExecutionOptions, o as getAcceptedEvents, p as buildEnvelopeSchema, r as isDecisionLogic, s as parseAgentEvent, t as AgentDecisionExhaustedError, u as INTERPRET_SOURCE, v as getAgentOutputMode, x as parseModelRef, y as isTextLogic, z as getMachineStructuralHash } from "./decision-D9Zi7Xi5.mjs";
4
4
  import { a as assertEventLogStoreConformance, i as assertAgentLogEntry, n as AgentEventLogConflictError, o as assertJsonSerializable, r as NonSerializableAgentEventError, s as createInMemoryEventLogStore, t as AGENT_EVENT_SCHEMA_VERSION } from "./event-log-store-D7pWtIhb.mjs";
5
5
  import { createActor, createAsyncLogic, getNextTransitions, isMachineSnapshot } from "xstate";
6
6
  //#region src/internal/state-request-pass.ts
@@ -766,6 +766,26 @@ function bindDecisionForProvide(machine, logic, executors, options) {
766
766
  return createRunAgentDecisionLogic(logic, provideBindContext(machine, executors, options));
767
767
  }
768
768
  /**
769
+ * Validates `input` against the machine's registered input schema, returning
770
+ * the schema's output — so defaults are filled and transforms applied before
771
+ * the value reaches `createActor` or the replayable event log.
772
+ *
773
+ * Standard Schema only (no validation library is referenced), so this works for
774
+ * whatever the machine was declared with. Omitted input stays omitted rather
775
+ * than being validated as `{}`: "started with no input" keeps meaning what it
776
+ * has always meant, instead of newly failing schemas with required fields.
777
+ */
778
+ function resolveMachineInput(machine, input) {
779
+ if (input === void 0) return input;
780
+ const schema = getRegisteredAgentExecutionOptions(machine).schemas?.input;
781
+ if (!isStandardSchema(schema)) return input;
782
+ try {
783
+ return validateSchemaSync(schema, input);
784
+ } catch (error) {
785
+ throw new AgentError("invalid-machine-input", `runAgent: machine input failed validation against the declared input schema: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
786
+ }
787
+ }
788
+ /**
769
789
  * Recursively rebinds an invoked child machine's own agent sources with the
770
790
  * SAME host-backed wrappers runAgent applies to the top-level machine, so a
771
791
  * child's text/stream/decision requests inherit runAgent's executors and
@@ -875,6 +895,7 @@ function createAgentSession(machine, options, lifecycle) {
875
895
  let warnedHeuristicIdle = false;
876
896
  const runId = `run_${nextRunAgentTraceId++}`;
877
897
  let traceSeq = 0;
898
+ const resolvedInput = resolveMachineInput(machine, options.input);
878
899
  const machineId = machine.config.id ?? machine.id ?? "(machine)";
879
900
  const machineVersion = options.machineVersion ?? machine.version ?? getMachineStructuralHash(machine);
880
901
  const agentMeta = {
@@ -1069,7 +1090,7 @@ function createAgentSession(machine, options, lifecycle) {
1069
1090
  return entry;
1070
1091
  };
1071
1092
  if (replayEvents.length === 0 && effectiveSnapshot === void 0) {
1072
- const entry = initEntry(machine, options.input, { machineVersion });
1093
+ const entry = initEntry(machine, resolvedInput, { machineVersion });
1073
1094
  replayEventIds.add(entry.id);
1074
1095
  replayEvents.push(entry);
1075
1096
  options.onEvent?.(entry);
@@ -1207,7 +1228,7 @@ function createAgentSession(machine, options, lifecycle) {
1207
1228
  }, 0);
1208
1229
  };
1209
1230
  actor = createActor(boundMachine, {
1210
- input: options.input,
1231
+ input: resolvedInput,
1211
1232
  snapshot: effectiveSnapshot,
1212
1233
  inspect: (event) => {
1213
1234
  if (typeof options.inspect === "function") options.inspect(event);
@@ -1304,7 +1325,7 @@ function createAgentSession(machine, options, lifecycle) {
1304
1325
  }
1305
1326
  onTrace({
1306
1327
  type: "run.start",
1307
- ...options.input !== void 0 ? { input: options.input } : {},
1328
+ ...resolvedInput !== void 0 ? { input: resolvedInput } : {},
1308
1329
  ...effectiveSnapshot !== void 0 ? { snapshot: effectiveSnapshot } : {},
1309
1330
  ...options.event !== void 0 ? { event: options.event } : {}
1310
1331
  });
@@ -1,4 +1,4 @@
1
- import { _ as StandardSchemaV1, c as AgentTools } from "./types-rMe7x6NR.cjs";
1
+ import { c as AgentTools, v as StandardSchemaV1 } from "./types-DFD28AWe.cjs";
2
2
  import { AnyStateMachine } from "xstate";
3
3
 
4
4
  //#region src/machines/tool-loop.d.ts
@@ -1,4 +1,4 @@
1
- import { _ as StandardSchemaV1, c as AgentTools } from "./types-9Bqg5rZB.mjs";
1
+ import { c as AgentTools, v as StandardSchemaV1 } from "./types-CTBhMnFu.mjs";
2
2
  import { AnyStateMachine } from "xstate";
3
3
 
4
4
  //#region src/machines/tool-loop.d.ts
package/dist/otel.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { c as AgentTraceEvent } from "./run-agent-BlqKwHIF.cjs";
1
+ import { l as AgentTraceEvent } from "./run-agent-B_n4Qxye.cjs";
2
2
  import { Attributes, Tracer, TracerProvider } from "@opentelemetry/api";
3
3
 
4
4
  //#region src/otel/index.d.ts
package/dist/otel.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { c as AgentTraceEvent } from "./run-agent-2MnlQTkB.mjs";
1
+ import { l as AgentTraceEvent } from "./run-agent-BWzo4FLv.mjs";
2
2
  import { Attributes, Tracer, TracerProvider } from "@opentelemetry/api";
3
3
 
4
4
  //#region src/otel/index.d.ts
@@ -1,6 +1,6 @@
1
- import { c as AgentTools, d as ChosenEvent, n as AgentMessage } from "./types-9Bqg5rZB.mjs";
1
+ import { T as WithAgentInputSchema, c as AgentTools, d as ChosenEvent, h as InferInput, n as AgentMessage, v as StandardSchemaV1 } from "./types-CTBhMnFu.mjs";
2
2
  import { t as AgentError } from "./errors-C9rxnWbX.mjs";
3
- import { B as AgentRequestOptions, M as AgentDecisionRequest, R as AgentEventDescriptor, V as AgentRequestSource, d as AgentTextRequest, f as AgentUsage, l as AgentRequestExecutors, p as AgentUserInput, t as AgentCallUsage, u as AgentRequestMode } from "./text-logic-C5kbjaDz.mjs";
3
+ import { B as AgentRequestOptions, M as AgentDecisionRequest, R as AgentEventDescriptor, V as AgentRequestSource, d as AgentTextRequest, f as AgentUsage, l as AgentRequestExecutors, p as AgentUserInput, t as AgentCallUsage, u as AgentRequestMode } from "./text-logic-C7anC7qX.mjs";
4
4
  import { i as AgentLogEntry, o as JsonValue } from "./event-log-store-BkUNtyOF.mjs";
5
5
  import { AnyActorLogic, AnyActorRef, AnyMachineSnapshot, AnyStateMachine, AsyncActorLogic, EmittedFrom, EventFromLogic, EventObject, ExecutableActionObject, InputFrom, InspectionEvent, OutputFrom, Snapshot, SnapshotFrom, createActor } from "xstate";
6
6
 
@@ -624,8 +624,15 @@ interface RunAgentOptions<TMachine extends AnyStateMachine> {
624
624
  * kind, so e.g. a stream-only machine may pass `{ streamText }` alone.
625
625
  */
626
626
  executors?: Partial<AgentRequestExecutors>;
627
- /** Machine input, passed straight to `createActor(machine, { input })`. Omit when resuming via `snapshot`. */
628
- input?: InputFrom<TMachine>;
627
+ /**
628
+ * Machine input. Validated against the machine's declared input schema —
629
+ * defaults filled, transforms applied — before it reaches
630
+ * `createActor(machine, { input })` and the replayable event log; invalid
631
+ * input throws an {@link AgentError} with code `invalid-machine-input`.
632
+ * Typed as {@link AgentInputFrom}, so fields the schema defaults are optional
633
+ * here. Omit when resuming via `snapshot`.
634
+ */
635
+ input?: AgentInputFrom<TMachine>;
629
636
  /** A previously-settled run's `result.snapshot`, to resume from instead of starting fresh. Pair with `event` to deliver the event that unblocks the resumed idle state. */
630
637
  snapshot?: Snapshot<unknown>;
631
638
  /** An event to send immediately after starting/resuming the actor (e.g. the human's answer to an idle-state prompt). */
@@ -901,6 +908,20 @@ type RunAgentResult<TMachine extends AnyStateMachine> = RunAgentOutcome<TMachine
901
908
  * - `'stopped'` — the actor was stopped externally (`status === 'stopped'`).
902
909
  */
903
910
  type RunAgentErrorCause = "aborted" | "max-model-calls" | "decision-exhausted" | "machine" | "stopped";
911
+ /**
912
+ * The machine input a run accepts, which is the schema's *pre*-validation side.
913
+ *
914
+ * XState's `schemas` are types only — it never validates, and it resolves
915
+ * `schemas.input` to one type shared by `createActor`'s `input` option and the
916
+ * `context: ({ input })` factory. A schema field declared with a default
917
+ * therefore reads as required at the call site even though the caller is meant
918
+ * to omit it. `setupAgent` brands the machine's input type with its own schema
919
+ * ({@link WithAgentInputSchema}), so this recovers the looser caller-facing
920
+ * side while the factory keeps seeing the validated one. Machines with no
921
+ * declared input schema — and machines reached through `.provide(...)`, which
922
+ * drops the brand — fall back to xstate's `InputFrom`.
923
+ */
924
+ type AgentInputFrom<TMachine extends AnyStateMachine> = InputFrom<TMachine> extends WithAgentInputSchema<infer TInputSchema> ? [TInputSchema] extends [StandardSchemaV1] ? InferInput<TInputSchema> : InputFrom<TMachine> : InputFrom<TMachine>;
904
925
  /**
905
926
  * Runs an agent machine to completion or idle: a `createActor` host that
906
927
  * binds `options`' host executors onto the machine's `agent.*`/`TextLogic`/
@@ -1061,4 +1082,4 @@ declare function inspectTransitions(handler: (snapshot: AnyMachineSnapshot, acto
1061
1082
  */
1062
1083
  declare function traceTransitions<TMachine extends AnyStateMachine = AnyStateMachine>(onTrace: (event: AgentTraceEvent<TMachine>) => void): (inspectionEvent: InspectionEvent) => void;
1063
1084
  //#endregion
1064
- export { AgentEffectDiff as A, createReplayEntry as B, AgentStateRequest as C, AGENT_INIT_EVENT_TYPE as D, executeAgentRequest as E, AgentUsageEvent as F, replay as G, getAgentEffects as H, CreateReplayEntryOptions as I, verifyReplay as K, GetAgentEffectsOptions as L, AgentLogPatchOperation as M, AgentReplayDivergenceError as N, AGENT_USAGE_EVENT_TYPE as O, AgentReplayMachineMismatchError as P, ReplayOptions as R, traceTransitions as S, AgentStepRequest as T, getCallUsage as U, diffEventLogs as V, initEntry as W, createAgentActor as _, AgentMessageInfo as a, runAgent as b, AgentTraceEvent as c, InspectedActorRef as d, JsonSerializableTraceEvent as f, RunAgentResult as g, RunAgentOptions as h, AgentIllegalResumeEventError as i, AgentEventLogDiff as j, AgentEffect as k, AgentUserInputExecutor as l, RunAgentErrorCause as m, AgentActorSession as n, AgentRunMeta as o, PendingUserInput as p, AgentIdleError as r, AgentSnapshotVersionMismatchError as s, AGENT_TRACE_SCHEMA_VERSION as t, GenerateResult as u, generateResult as v, AgentRequest as w, serializeTraceEvent as x, inspectTransitions as y, ReplayResult as z };
1085
+ export { AgentEffect as A, ReplayResult as B, traceTransitions as C, executeAgentRequest as D, AgentStepRequest as E, AgentReplayMachineMismatchError as F, initEntry as G, diffEventLogs as H, AgentUsageEvent as I, replay as K, CreateReplayEntryOptions as L, AgentEventLogDiff as M, AgentLogPatchOperation as N, AGENT_INIT_EVENT_TYPE as O, AgentReplayDivergenceError as P, GetAgentEffectsOptions as R, serializeTraceEvent as S, AgentRequest as T, getAgentEffects as U, createReplayEntry as V, getCallUsage as W, RunAgentResult as _, AgentInputFrom as a, inspectTransitions as b, AgentSnapshotVersionMismatchError as c, GenerateResult as d, InspectedActorRef as f, RunAgentOptions as g, RunAgentErrorCause as h, AgentIllegalResumeEventError as i, AgentEffectDiff as j, AGENT_USAGE_EVENT_TYPE as k, AgentTraceEvent as l, PendingUserInput as m, AgentActorSession as n, AgentMessageInfo as o, JsonSerializableTraceEvent as p, verifyReplay as q, AgentIdleError as r, AgentRunMeta as s, AGENT_TRACE_SCHEMA_VERSION as t, AgentUserInputExecutor as u, createAgentActor as v, AgentStateRequest as w, runAgent as x, generateResult as y, ReplayOptions as z };
@@ -1,6 +1,6 @@
1
- import { c as AgentTools, d as ChosenEvent, n as AgentMessage } from "./types-rMe7x6NR.cjs";
1
+ import { T as WithAgentInputSchema, c as AgentTools, d as ChosenEvent, h as InferInput, n as AgentMessage, v as StandardSchemaV1 } from "./types-DFD28AWe.cjs";
2
2
  import { t as AgentError } from "./errors-BQRk9eiZ.cjs";
3
- import { B as AgentRequestOptions, M as AgentDecisionRequest, R as AgentEventDescriptor, V as AgentRequestSource, d as AgentTextRequest, f as AgentUsage, l as AgentRequestExecutors, p as AgentUserInput, t as AgentCallUsage, u as AgentRequestMode } from "./text-logic-Jkilp1Ie.cjs";
3
+ import { B as AgentRequestOptions, M as AgentDecisionRequest, R as AgentEventDescriptor, V as AgentRequestSource, d as AgentTextRequest, f as AgentUsage, l as AgentRequestExecutors, p as AgentUserInput, t as AgentCallUsage, u as AgentRequestMode } from "./text-logic-DZW7XWy9.cjs";
4
4
  import { i as AgentLogEntry, o as JsonValue } from "./event-log-store-CVd2eyRy.cjs";
5
5
  import { AnyActorLogic, AnyActorRef, AnyMachineSnapshot, AnyStateMachine, AsyncActorLogic, EmittedFrom, EventFromLogic, EventObject, ExecutableActionObject, InputFrom, InspectionEvent, OutputFrom, Snapshot, SnapshotFrom, createActor } from "xstate";
6
6
 
@@ -624,8 +624,15 @@ interface RunAgentOptions<TMachine extends AnyStateMachine> {
624
624
  * kind, so e.g. a stream-only machine may pass `{ streamText }` alone.
625
625
  */
626
626
  executors?: Partial<AgentRequestExecutors>;
627
- /** Machine input, passed straight to `createActor(machine, { input })`. Omit when resuming via `snapshot`. */
628
- input?: InputFrom<TMachine>;
627
+ /**
628
+ * Machine input. Validated against the machine's declared input schema —
629
+ * defaults filled, transforms applied — before it reaches
630
+ * `createActor(machine, { input })` and the replayable event log; invalid
631
+ * input throws an {@link AgentError} with code `invalid-machine-input`.
632
+ * Typed as {@link AgentInputFrom}, so fields the schema defaults are optional
633
+ * here. Omit when resuming via `snapshot`.
634
+ */
635
+ input?: AgentInputFrom<TMachine>;
629
636
  /** A previously-settled run's `result.snapshot`, to resume from instead of starting fresh. Pair with `event` to deliver the event that unblocks the resumed idle state. */
630
637
  snapshot?: Snapshot<unknown>;
631
638
  /** An event to send immediately after starting/resuming the actor (e.g. the human's answer to an idle-state prompt). */
@@ -901,6 +908,20 @@ type RunAgentResult<TMachine extends AnyStateMachine> = RunAgentOutcome<TMachine
901
908
  * - `'stopped'` — the actor was stopped externally (`status === 'stopped'`).
902
909
  */
903
910
  type RunAgentErrorCause = "aborted" | "max-model-calls" | "decision-exhausted" | "machine" | "stopped";
911
+ /**
912
+ * The machine input a run accepts, which is the schema's *pre*-validation side.
913
+ *
914
+ * XState's `schemas` are types only — it never validates, and it resolves
915
+ * `schemas.input` to one type shared by `createActor`'s `input` option and the
916
+ * `context: ({ input })` factory. A schema field declared with a default
917
+ * therefore reads as required at the call site even though the caller is meant
918
+ * to omit it. `setupAgent` brands the machine's input type with its own schema
919
+ * ({@link WithAgentInputSchema}), so this recovers the looser caller-facing
920
+ * side while the factory keeps seeing the validated one. Machines with no
921
+ * declared input schema — and machines reached through `.provide(...)`, which
922
+ * drops the brand — fall back to xstate's `InputFrom`.
923
+ */
924
+ type AgentInputFrom<TMachine extends AnyStateMachine> = InputFrom<TMachine> extends WithAgentInputSchema<infer TInputSchema> ? [TInputSchema] extends [StandardSchemaV1] ? InferInput<TInputSchema> : InputFrom<TMachine> : InputFrom<TMachine>;
904
925
  /**
905
926
  * Runs an agent machine to completion or idle: a `createActor` host that
906
927
  * binds `options`' host executors onto the machine's `agent.*`/`TextLogic`/
@@ -1061,4 +1082,4 @@ declare function inspectTransitions(handler: (snapshot: AnyMachineSnapshot, acto
1061
1082
  */
1062
1083
  declare function traceTransitions<TMachine extends AnyStateMachine = AnyStateMachine>(onTrace: (event: AgentTraceEvent<TMachine>) => void): (inspectionEvent: InspectionEvent) => void;
1063
1084
  //#endregion
1064
- export { AgentEffectDiff as A, createReplayEntry as B, AgentStateRequest as C, AGENT_INIT_EVENT_TYPE as D, executeAgentRequest as E, AgentUsageEvent as F, replay as G, getAgentEffects as H, CreateReplayEntryOptions as I, verifyReplay as K, GetAgentEffectsOptions as L, AgentLogPatchOperation as M, AgentReplayDivergenceError as N, AGENT_USAGE_EVENT_TYPE as O, AgentReplayMachineMismatchError as P, ReplayOptions as R, traceTransitions as S, AgentStepRequest as T, getCallUsage as U, diffEventLogs as V, initEntry as W, createAgentActor as _, AgentMessageInfo as a, runAgent as b, AgentTraceEvent as c, InspectedActorRef as d, JsonSerializableTraceEvent as f, RunAgentResult as g, RunAgentOptions as h, AgentIllegalResumeEventError as i, AgentEventLogDiff as j, AgentEffect as k, AgentUserInputExecutor as l, RunAgentErrorCause as m, AgentActorSession as n, AgentRunMeta as o, PendingUserInput as p, AgentIdleError as r, AgentSnapshotVersionMismatchError as s, AGENT_TRACE_SCHEMA_VERSION as t, GenerateResult as u, generateResult as v, AgentRequest as w, serializeTraceEvent as x, inspectTransitions as y, ReplayResult as z };
1085
+ export { AgentEffect as A, ReplayResult as B, traceTransitions as C, executeAgentRequest as D, AgentStepRequest as E, AgentReplayMachineMismatchError as F, initEntry as G, diffEventLogs as H, AgentUsageEvent as I, replay as K, CreateReplayEntryOptions as L, AgentEventLogDiff as M, AgentLogPatchOperation as N, AGENT_INIT_EVENT_TYPE as O, AgentReplayDivergenceError as P, GetAgentEffectsOptions as R, serializeTraceEvent as S, AgentRequest as T, getAgentEffects as U, createReplayEntry as V, getCallUsage as W, RunAgentResult as _, AgentInputFrom as a, inspectTransitions as b, AgentSnapshotVersionMismatchError as c, GenerateResult as d, InspectedActorRef as f, RunAgentOptions as g, RunAgentErrorCause as h, AgentIllegalResumeEventError as i, AgentEffectDiff as j, AGENT_USAGE_EVENT_TYPE as k, AgentTraceEvent as l, PendingUserInput as m, AgentActorSession as n, AgentMessageInfo as o, JsonSerializableTraceEvent as p, verifyReplay as q, AgentIdleError as r, AgentRunMeta as s, AGENT_TRACE_SCHEMA_VERSION as t, AgentUserInputExecutor as u, createAgentActor as v, AgentStateRequest as w, runAgent as x, generateResult as y, ReplayOptions as z };
package/dist/sqlite.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { r as AgentSnapshotStore } from "./types-rMe7x6NR.cjs";
1
+ import { r as AgentSnapshotStore } from "./types-DFD28AWe.cjs";
2
2
  import { r as AgentEventLogStore } from "./event-log-store-CVd2eyRy.cjs";
3
3
 
4
4
  //#region src/sqlite/index.d.ts
package/dist/sqlite.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { r as AgentSnapshotStore } from "./types-9Bqg5rZB.mjs";
1
+ import { r as AgentSnapshotStore } from "./types-CTBhMnFu.mjs";
2
2
  import { r as AgentEventLogStore } from "./event-log-store-BkUNtyOF.mjs";
3
3
 
4
4
  //#region src/sqlite/index.d.ts
@@ -1,4 +1,4 @@
1
- import { _ as StandardSchemaV1, a as AgentToolChoice, c as AgentTools, d as ChosenEvent, h as InferOutput, l as AllowedEvents, n as AgentMessage } from "./types-9Bqg5rZB.mjs";
1
+ import { a as AgentToolChoice, c as AgentTools, d as ChosenEvent, g as InferOutput, l as AllowedEvents, n as AgentMessage, v as StandardSchemaV1 } from "./types-CTBhMnFu.mjs";
2
2
  import { t as AgentError } from "./errors-C9rxnWbX.mjs";
3
3
  import { AnyMachineSnapshot, AsyncActorLogic, EventObject, MachineSnapshot } from "xstate";
4
4
 
@@ -16,9 +16,11 @@ interface AgentEventDescriptor {
16
16
  toolName: string;
17
17
  inputSchema?: StandardSchemaV1;
18
18
  }
19
- /** Registered event payload schemas, as attached to a machine by `setupAgent`/`createAgentSchemas`. */
19
+ /** Registered schemas, as attached to a machine by `setupAgent`/`createAgentSchemas`. */
20
20
  interface AgentSchemas {
21
21
  events?: Record<string, StandardSchemaV1>;
22
+ /** Machine input schema; `runAgent` validates `options.input` against it. */
23
+ input?: StandardSchemaV1;
22
24
  }
23
25
  /** Shared options threaded through step discovery ({@link getAgentRequests}/{@link getAcceptedEvents}) — snapshot for event legality, event schemas for payload validation/tool schemas, and registered actor source logics. */
24
26
  interface AgentRequestOptions {
@@ -1,4 +1,4 @@
1
- import { _ as StandardSchemaV1, a as AgentToolChoice, c as AgentTools, d as ChosenEvent, h as InferOutput, l as AllowedEvents, n as AgentMessage } from "./types-rMe7x6NR.cjs";
1
+ import { a as AgentToolChoice, c as AgentTools, d as ChosenEvent, g as InferOutput, l as AllowedEvents, n as AgentMessage, v as StandardSchemaV1 } from "./types-DFD28AWe.cjs";
2
2
  import { t as AgentError } from "./errors-BQRk9eiZ.cjs";
3
3
  import { AnyMachineSnapshot, AsyncActorLogic, EventObject, MachineSnapshot } from "xstate";
4
4
 
@@ -16,9 +16,11 @@ interface AgentEventDescriptor {
16
16
  toolName: string;
17
17
  inputSchema?: StandardSchemaV1;
18
18
  }
19
- /** Registered event payload schemas, as attached to a machine by `setupAgent`/`createAgentSchemas`. */
19
+ /** Registered schemas, as attached to a machine by `setupAgent`/`createAgentSchemas`. */
20
20
  interface AgentSchemas {
21
21
  events?: Record<string, StandardSchemaV1>;
22
+ /** Machine input schema; `runAgent` validates `options.input` against it. */
23
+ input?: StandardSchemaV1;
22
24
  }
23
25
  /** Shared options threaded through step discovery ({@link getAgentRequests}/{@link getAcceptedEvents}) — snapshot for event legality, event schemas for payload validation/tool schemas, and registered actor source logics. */
24
26
  interface AgentRequestOptions {
@@ -36,6 +36,33 @@ interface StandardSchemaV1<Input = unknown, Output = Input> {
36
36
  }
37
37
  /** The validated output type of a {@link StandardSchemaV1}. */
38
38
  type InferOutput<T> = T extends StandardSchemaV1<any, infer O> ? O : never;
39
+ /**
40
+ * The *pre*-validation input type of a {@link StandardSchemaV1}: what a caller
41
+ * passes in, before defaults are filled and transforms applied. Standard Schema
42
+ * carries both sides (`~standard.types.input` / `.output`), so a schema
43
+ * declaring a defaulted field makes that field optional here and required in
44
+ * {@link InferOutput} — which is exactly the split between what `runAgent`
45
+ * accepts as machine `input` and what the `context` factory then sees.
46
+ */
47
+ type InferInput<T> = T extends StandardSchemaV1<infer I, any> ? I : never;
48
+ /**
49
+ * Phantom brand carrying a machine's declared input schema on the machine type.
50
+ *
51
+ * XState resolves `schemas.input` to a single type and uses it for both
52
+ * `createActor`'s `input` option and the `context: ({ input })` factory, so the
53
+ * caller-facing and factory-facing sides cannot differ there. `setupAgent`'s
54
+ * `createMachine` brands the machine's input type with the schema itself, which
55
+ * lets `AgentInputFrom` recover the looser input side for `runAgent` while the
56
+ * `context` factory keeps the strict validated side.
57
+ *
58
+ * The key is a `~`-prefixed phantom property (the same convention Standard
59
+ * Schema uses for `~standard`) rather than a `unique symbol`: a symbol would
60
+ * have to be exported as a runtime value for declaration emit to name it in
61
+ * every machine type it touches.
62
+ */
63
+ type WithAgentInputSchema<TInputSchema> = {
64
+ readonly "~agent.inputSchema"?: TInputSchema;
65
+ };
39
66
  /** An event schema's output, widened to `unknown` when it validates an empty object (no payload fields). */
40
67
  type EventPayload<T> = T extends Record<string, never> ? unknown : T;
41
68
  /**
@@ -216,4 +243,4 @@ type AllowedEvents<TEvent extends string = string, TInput = unknown> = AllowedEv
216
243
  input: TInput;
217
244
  }) => AllowedEventPattern<TEvent> | readonly AllowedEventPattern<TEvent>[]);
218
245
  //#endregion
219
- export { UserMessage as C, ToolResultPart as S, StandardSchemaV1 as _, AgentToolChoice as a, ToolCallPart as b, AgentTools as c, ChosenEvent as d, EventUnion as f, NormalizedEventSchemas as g, InferOutput as h, AgentTool as i, AllowedEvents as l, ImagePart as m, AgentMessage as n, AgentToolDescriptor as o, FilePart as p, AgentSnapshotStore as r, AgentToolExecute as s, AgentEventSchemaInputMap as t, AssistantMessage as u, SystemMessage as v, ToolMessage as x, TextPart as y };
246
+ export { ToolResultPart as C, ToolMessage as S, WithAgentInputSchema as T, NormalizedEventSchemas as _, AgentToolChoice as a, TextPart as b, AgentTools as c, ChosenEvent as d, EventUnion as f, InferOutput as g, InferInput as h, AgentTool as i, AllowedEvents as l, ImagePart as m, AgentMessage as n, AgentToolDescriptor as o, FilePart as p, AgentSnapshotStore as r, AgentToolExecute as s, AgentEventSchemaInputMap as t, AssistantMessage as u, StandardSchemaV1 as v, UserMessage as w, ToolCallPart as x, SystemMessage as y };
@@ -36,6 +36,33 @@ interface StandardSchemaV1<Input = unknown, Output = Input> {
36
36
  }
37
37
  /** The validated output type of a {@link StandardSchemaV1}. */
38
38
  type InferOutput<T> = T extends StandardSchemaV1<any, infer O> ? O : never;
39
+ /**
40
+ * The *pre*-validation input type of a {@link StandardSchemaV1}: what a caller
41
+ * passes in, before defaults are filled and transforms applied. Standard Schema
42
+ * carries both sides (`~standard.types.input` / `.output`), so a schema
43
+ * declaring a defaulted field makes that field optional here and required in
44
+ * {@link InferOutput} — which is exactly the split between what `runAgent`
45
+ * accepts as machine `input` and what the `context` factory then sees.
46
+ */
47
+ type InferInput<T> = T extends StandardSchemaV1<infer I, any> ? I : never;
48
+ /**
49
+ * Phantom brand carrying a machine's declared input schema on the machine type.
50
+ *
51
+ * XState resolves `schemas.input` to a single type and uses it for both
52
+ * `createActor`'s `input` option and the `context: ({ input })` factory, so the
53
+ * caller-facing and factory-facing sides cannot differ there. `setupAgent`'s
54
+ * `createMachine` brands the machine's input type with the schema itself, which
55
+ * lets `AgentInputFrom` recover the looser input side for `runAgent` while the
56
+ * `context` factory keeps the strict validated side.
57
+ *
58
+ * The key is a `~`-prefixed phantom property (the same convention Standard
59
+ * Schema uses for `~standard`) rather than a `unique symbol`: a symbol would
60
+ * have to be exported as a runtime value for declaration emit to name it in
61
+ * every machine type it touches.
62
+ */
63
+ type WithAgentInputSchema<TInputSchema> = {
64
+ readonly "~agent.inputSchema"?: TInputSchema;
65
+ };
39
66
  /** An event schema's output, widened to `unknown` when it validates an empty object (no payload fields). */
40
67
  type EventPayload<T> = T extends Record<string, never> ? unknown : T;
41
68
  /**
@@ -216,4 +243,4 @@ type AllowedEvents<TEvent extends string = string, TInput = unknown> = AllowedEv
216
243
  input: TInput;
217
244
  }) => AllowedEventPattern<TEvent> | readonly AllowedEventPattern<TEvent>[]);
218
245
  //#endregion
219
- export { UserMessage as C, ToolResultPart as S, StandardSchemaV1 as _, AgentToolChoice as a, ToolCallPart as b, AgentTools as c, ChosenEvent as d, EventUnion as f, NormalizedEventSchemas as g, InferOutput as h, AgentTool as i, AllowedEvents as l, ImagePart as m, AgentMessage as n, AgentToolDescriptor as o, FilePart as p, AgentSnapshotStore as r, AgentToolExecute as s, AgentEventSchemaInputMap as t, AssistantMessage as u, SystemMessage as v, ToolMessage as x, TextPart as y };
246
+ export { ToolResultPart as C, ToolMessage as S, WithAgentInputSchema as T, NormalizedEventSchemas as _, AgentToolChoice as a, TextPart as b, AgentTools as c, ChosenEvent as d, EventUnion as f, InferOutput as g, InferInput as h, AgentTool as i, AllowedEvents as l, ImagePart as m, AgentMessage as n, AgentToolDescriptor as o, FilePart as p, AgentSnapshotStore as r, AgentToolExecute as s, AgentEventSchemaInputMap as t, AssistantMessage as u, StandardSchemaV1 as v, UserMessage as w, ToolCallPart as x, SystemMessage as y };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statelyai/agent",
3
- "version": "2.0.0-alpha.14",
3
+ "version": "2.0.0-alpha.15",
4
4
  "description": "Make invalid agent actions impossible. Agent logic as state machines: deterministic, inspectable, resumable, runs anywhere.",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",