@statelyai/agent 2.0.0-alpha.6 → 2.0.0-alpha.8

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.
@@ -1,4 +1,4 @@
1
- import { b as StandardSchemaV1, c as AgentTools, f as ChosenEvent, i as AgentToolChoice, t as AgentMessage, u as AllowedEvents, v as InferOutput } from "./types-BHjeDdch.cjs";
1
+ import { C as StandardSchemaV1, b as InferOutput, f as AllowedEvents, m as ChosenEvent, o as AgentToolChoice, r as AgentMessage, u as AgentTools } from "./types-qm00QF91.mjs";
2
2
  import { AnyMachineSnapshot, AsyncActorLogic, EventObject, LogicActorLogic, MachineSnapshot } from "xstate";
3
3
 
4
4
  //#region src/events.d.ts
@@ -383,6 +383,21 @@ type AgentModelMap = Record<string, unknown>;
383
383
  * adapter's models map / `resolveModel`) resolves them to a real model.
384
384
  */
385
385
  type AgentModelRef<TModels extends AgentModelMap = {}> = [keyof TModels] extends [never] ? string : (keyof TModels & string) | (string & {});
386
+ /**
387
+ * Splits a portable `"provider/model-id"` model ref (the convention JSON
388
+ * workflows and registry-less hosts use, e.g. `"openai/gpt-5.4-mini"`) into
389
+ * its parts. A ref with no `/` has no provider — `modelId` is the whole ref.
390
+ * The standard building block for a host's `resolveModel`:
391
+ *
392
+ * @example
393
+ * ```ts
394
+ * const resolveModel = (ref: string) => openai(parseModelRef(ref).modelId);
395
+ * ```
396
+ */
397
+ declare function parseModelRef(modelRef: string): {
398
+ provider: string | undefined;
399
+ modelId: string;
400
+ };
386
401
  /**
387
402
  * Portable, provider-agnostic input a text request passes to a host
388
403
  * executor (`generateText`/`streamText` on {@link AgentRequestExecutors}).
@@ -437,17 +452,22 @@ interface AgentTextRequest<TMetadata = Record<string, unknown>> {
437
452
  */
438
453
  metadata?: TMetadata;
439
454
  }
440
- /** Inline input for the `agent.userInput` builtin actor — a human-input request (CLI prompt, form, chat reply, …). See {@link RunAgentOptions.userInput}. */
455
+ /**
456
+ * Inline input for the `agent.userInput` builtin actor — a human-input request
457
+ * (CLI prompt, chat reply, …) that resolves to the `string` the human typed.
458
+ * See {@link RunAgentOptions.userInput}. For structured input, parse/classify
459
+ * the string in a follow-up state, or register a custom actor source; host
460
+ * rendering hints (a form spec, say) belong in `metadata`.
461
+ */
441
462
  interface AgentUserInput<TMetadata = Record<string, unknown>> {
442
463
  prompt?: string;
443
- schema?: StandardSchemaV1;
444
464
  metadata?: TMetadata;
445
465
  }
446
466
  /** The five `agent.*` builtin actor logics every setupAgent-built machine registers. @internal */
447
467
  type BuiltinAgentActors<TEvent extends string = string, TModel extends string = string> = {
448
468
  [GENERATE_TEXT_ACTOR]: AsyncActorLogic<unknown, AgentTextRequest>;
449
469
  [STREAM_TEXT_ACTOR]: AsyncActorLogic<unknown, AgentTextRequest>;
450
- [USER_INPUT_ACTOR]: AsyncActorLogic<unknown, AgentUserInput>;
470
+ [USER_INPUT_ACTOR]: AsyncActorLogic<string, AgentUserInput>;
451
471
  [DECIDE_ACTOR]: AsyncActorLogic<ChosenEvent, AgentDecisionInput<TEvent, Record<string, unknown>, TModel>>;
452
472
  [PLAN_ACTOR]: PlanLogic<StandardSchemaV1<AgentPlanInput<TEvent, Record<string, unknown>, TModel>>>;
453
473
  };
@@ -564,7 +584,7 @@ declare function createTextLogic<TInputSchema extends StandardSchemaV1, TOutputS
564
584
  * });
565
585
  * ```
566
586
  */
567
- declare function bindRequestExecutor<TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetadata>(logic: TextLogic<TInputSchema, TOutputSchema, TMetadata>, executor: AgentRequestExecutor): TextLogic<TInputSchema, TOutputSchema, TMetadata>;
587
+ declare function bindRequestExecutor<TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetadata>(logic: TextLogic<TInputSchema, TOutputSchema, TMetadata>, executor: AgentRequestExecutor, info?: Pick<AgentRequestExecutorInfo, "onChunk">): TextLogic<TInputSchema, TOutputSchema, TMetadata>;
568
588
  /**
569
589
  * The envelope an {@link AgentRequestExecutor} must return: `{ output }` where
570
590
  * `output` is the request's value (a text string or a structured object).
@@ -678,5 +698,13 @@ interface StructuredOutputEnvelope {
678
698
  declare function buildEnvelopeSchema(inner: StandardSchemaV1, options?: {
679
699
  reasoning?: boolean;
680
700
  }): StandardSchemaV1<StructuredOutputEnvelope>;
701
+ /**
702
+ * Validates a raw provider value against the structured-output envelope for
703
+ * `request` and returns the unwrapped `{ result, reasoning? }` — the checked
704
+ * replacement for `raw as StructuredOutputEnvelope` in hand-written hosts.
705
+ * Pair with {@link buildEnvelopeSchema} (which produced the schema the
706
+ * provider was asked to satisfy).
707
+ */
708
+ declare function parseStructuredEnvelope(request: Pick<AgentTextRequest, "outputSchema" | "reasoning">, value: unknown): StructuredOutputEnvelope;
681
709
  //#endregion
682
- export { AgentPlanInput as A, AgentEventDescriptor as B, createTextLogic as C, AgentDecisionExecutor as D, parseOutput as E, DecisionLogicConfig as F, getAcceptedEvents as G, AgentRequestOptions as H, PLAN_DONE_EVENT_TYPE as I, matchesEventPattern as K, ResolveDecisionOptions as L, DecisionAttempt as M, DecisionExhaustedError as N, AgentDecisionInput as O, DecisionLogic as P, renderDecisionAttempts as R, buildEnvelopeSchema as S, isStructuredOutputSchema as T, AgentRequestSource as U, AgentEventToolNameResolver as V, EVENT_TOOL_PREFIX as W, TextLogicExecuteArgs as _, AgentRequestExecutorInfo as a, TextLogicOutput as b, AgentRequestMode as c, AiSdkShapedStreamResult as d, AiSdkShapedTextResult as f, TextLogicConfig as g, TextLogic as h, AgentRequestExecutor as i, AgentPlanOutput as j, AgentDecisionRequest as k, AgentTextRequest as l, StructuredOutputEnvelope as m, AgentModelRef as n, AgentRequestExecutorResult as o, BuiltinAgentActors as p, parseAgentEvent as q, AgentOutputMode as r, AgentRequestExecutors as s, AgentModelMap as t, AgentUserInput as u, TextLogicExecutor as v, getAgentOutputMode as w, bindRequestExecutor as x, TextLogicInput as y, resolveDecision as z };
710
+ export { AgentDecisionInput as A, renderDecisionAttempts as B, createTextLogic as C, parseOutput as D, parseModelRef as E, DecisionExhaustedError as F, AgentRequestSource as G, AgentEventDescriptor as H, DecisionLogic as I, matchesEventPattern as J, EVENT_TOOL_PREFIX as K, DecisionLogicConfig as L, AgentPlanInput as M, AgentPlanOutput as N, parseStructuredEnvelope as O, DecisionAttempt as P, PLAN_DONE_EVENT_TYPE as R, buildEnvelopeSchema as S, isStructuredOutputSchema as T, AgentEventToolNameResolver as U, resolveDecision as V, AgentRequestOptions as W, parseAgentEvent as Y, TextLogicExecuteArgs as _, AgentRequestExecutorInfo as a, TextLogicOutput as b, AgentRequestMode as c, AiSdkShapedStreamResult as d, AiSdkShapedTextResult as f, TextLogicConfig as g, TextLogic as h, AgentRequestExecutor as i, AgentDecisionRequest as j, AgentDecisionExecutor as k, AgentTextRequest as l, StructuredOutputEnvelope as m, AgentModelRef as n, AgentRequestExecutorResult as o, BuiltinAgentActors as p, getAcceptedEvents as q, AgentOutputMode as r, AgentRequestExecutors as s, AgentModelMap as t, AgentUserInput as u, TextLogicExecutor as v, getAgentOutputMode as w, bindRequestExecutor as x, TextLogicInput as y, ResolveDecisionOptions as z };
@@ -1,4 +1,4 @@
1
- import { b as StandardSchemaV1, c as AgentTools, f as ChosenEvent, i as AgentToolChoice, t as AgentMessage, u as AllowedEvents, v as InferOutput } from "./types-Cq1YlAQ6.mjs";
1
+ import { C as StandardSchemaV1, b as InferOutput, f as AllowedEvents, m as ChosenEvent, o as AgentToolChoice, r as AgentMessage, u as AgentTools } from "./types-C9QiMjre.cjs";
2
2
  import { AnyMachineSnapshot, AsyncActorLogic, EventObject, LogicActorLogic, MachineSnapshot } from "xstate";
3
3
 
4
4
  //#region src/events.d.ts
@@ -383,6 +383,21 @@ type AgentModelMap = Record<string, unknown>;
383
383
  * adapter's models map / `resolveModel`) resolves them to a real model.
384
384
  */
385
385
  type AgentModelRef<TModels extends AgentModelMap = {}> = [keyof TModels] extends [never] ? string : (keyof TModels & string) | (string & {});
386
+ /**
387
+ * Splits a portable `"provider/model-id"` model ref (the convention JSON
388
+ * workflows and registry-less hosts use, e.g. `"openai/gpt-5.4-mini"`) into
389
+ * its parts. A ref with no `/` has no provider — `modelId` is the whole ref.
390
+ * The standard building block for a host's `resolveModel`:
391
+ *
392
+ * @example
393
+ * ```ts
394
+ * const resolveModel = (ref: string) => openai(parseModelRef(ref).modelId);
395
+ * ```
396
+ */
397
+ declare function parseModelRef(modelRef: string): {
398
+ provider: string | undefined;
399
+ modelId: string;
400
+ };
386
401
  /**
387
402
  * Portable, provider-agnostic input a text request passes to a host
388
403
  * executor (`generateText`/`streamText` on {@link AgentRequestExecutors}).
@@ -437,17 +452,22 @@ interface AgentTextRequest<TMetadata = Record<string, unknown>> {
437
452
  */
438
453
  metadata?: TMetadata;
439
454
  }
440
- /** Inline input for the `agent.userInput` builtin actor — a human-input request (CLI prompt, form, chat reply, …). See {@link RunAgentOptions.userInput}. */
455
+ /**
456
+ * Inline input for the `agent.userInput` builtin actor — a human-input request
457
+ * (CLI prompt, chat reply, …) that resolves to the `string` the human typed.
458
+ * See {@link RunAgentOptions.userInput}. For structured input, parse/classify
459
+ * the string in a follow-up state, or register a custom actor source; host
460
+ * rendering hints (a form spec, say) belong in `metadata`.
461
+ */
441
462
  interface AgentUserInput<TMetadata = Record<string, unknown>> {
442
463
  prompt?: string;
443
- schema?: StandardSchemaV1;
444
464
  metadata?: TMetadata;
445
465
  }
446
466
  /** The five `agent.*` builtin actor logics every setupAgent-built machine registers. @internal */
447
467
  type BuiltinAgentActors<TEvent extends string = string, TModel extends string = string> = {
448
468
  [GENERATE_TEXT_ACTOR]: AsyncActorLogic<unknown, AgentTextRequest>;
449
469
  [STREAM_TEXT_ACTOR]: AsyncActorLogic<unknown, AgentTextRequest>;
450
- [USER_INPUT_ACTOR]: AsyncActorLogic<unknown, AgentUserInput>;
470
+ [USER_INPUT_ACTOR]: AsyncActorLogic<string, AgentUserInput>;
451
471
  [DECIDE_ACTOR]: AsyncActorLogic<ChosenEvent, AgentDecisionInput<TEvent, Record<string, unknown>, TModel>>;
452
472
  [PLAN_ACTOR]: PlanLogic<StandardSchemaV1<AgentPlanInput<TEvent, Record<string, unknown>, TModel>>>;
453
473
  };
@@ -564,7 +584,7 @@ declare function createTextLogic<TInputSchema extends StandardSchemaV1, TOutputS
564
584
  * });
565
585
  * ```
566
586
  */
567
- declare function bindRequestExecutor<TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetadata>(logic: TextLogic<TInputSchema, TOutputSchema, TMetadata>, executor: AgentRequestExecutor): TextLogic<TInputSchema, TOutputSchema, TMetadata>;
587
+ declare function bindRequestExecutor<TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetadata>(logic: TextLogic<TInputSchema, TOutputSchema, TMetadata>, executor: AgentRequestExecutor, info?: Pick<AgentRequestExecutorInfo, "onChunk">): TextLogic<TInputSchema, TOutputSchema, TMetadata>;
568
588
  /**
569
589
  * The envelope an {@link AgentRequestExecutor} must return: `{ output }` where
570
590
  * `output` is the request's value (a text string or a structured object).
@@ -678,5 +698,13 @@ interface StructuredOutputEnvelope {
678
698
  declare function buildEnvelopeSchema(inner: StandardSchemaV1, options?: {
679
699
  reasoning?: boolean;
680
700
  }): StandardSchemaV1<StructuredOutputEnvelope>;
701
+ /**
702
+ * Validates a raw provider value against the structured-output envelope for
703
+ * `request` and returns the unwrapped `{ result, reasoning? }` — the checked
704
+ * replacement for `raw as StructuredOutputEnvelope` in hand-written hosts.
705
+ * Pair with {@link buildEnvelopeSchema} (which produced the schema the
706
+ * provider was asked to satisfy).
707
+ */
708
+ declare function parseStructuredEnvelope(request: Pick<AgentTextRequest, "outputSchema" | "reasoning">, value: unknown): StructuredOutputEnvelope;
681
709
  //#endregion
682
- export { AgentPlanInput as A, AgentEventDescriptor as B, createTextLogic as C, AgentDecisionExecutor as D, parseOutput as E, DecisionLogicConfig as F, getAcceptedEvents as G, AgentRequestOptions as H, PLAN_DONE_EVENT_TYPE as I, matchesEventPattern as K, ResolveDecisionOptions as L, DecisionAttempt as M, DecisionExhaustedError as N, AgentDecisionInput as O, DecisionLogic as P, renderDecisionAttempts as R, buildEnvelopeSchema as S, isStructuredOutputSchema as T, AgentRequestSource as U, AgentEventToolNameResolver as V, EVENT_TOOL_PREFIX as W, TextLogicExecuteArgs as _, AgentRequestExecutorInfo as a, TextLogicOutput as b, AgentRequestMode as c, AiSdkShapedStreamResult as d, AiSdkShapedTextResult as f, TextLogicConfig as g, TextLogic as h, AgentRequestExecutor as i, AgentPlanOutput as j, AgentDecisionRequest as k, AgentTextRequest as l, StructuredOutputEnvelope as m, AgentModelRef as n, AgentRequestExecutorResult as o, BuiltinAgentActors as p, parseAgentEvent as q, AgentOutputMode as r, AgentRequestExecutors as s, AgentModelMap as t, AgentUserInput as u, TextLogicExecutor as v, getAgentOutputMode as w, bindRequestExecutor as x, TextLogicInput as y, resolveDecision as z };
710
+ export { AgentDecisionInput as A, renderDecisionAttempts as B, createTextLogic as C, parseOutput as D, parseModelRef as E, DecisionExhaustedError as F, AgentRequestSource as G, AgentEventDescriptor as H, DecisionLogic as I, matchesEventPattern as J, EVENT_TOOL_PREFIX as K, DecisionLogicConfig as L, AgentPlanInput as M, AgentPlanOutput as N, parseStructuredEnvelope as O, DecisionAttempt as P, PLAN_DONE_EVENT_TYPE as R, buildEnvelopeSchema as S, isStructuredOutputSchema as T, AgentEventToolNameResolver as U, resolveDecision as V, AgentRequestOptions as W, parseAgentEvent as Y, TextLogicExecuteArgs as _, AgentRequestExecutorInfo as a, TextLogicOutput as b, AgentRequestMode as c, AiSdkShapedStreamResult as d, AiSdkShapedTextResult as f, TextLogicConfig as g, TextLogic as h, AgentRequestExecutor as i, AgentDecisionRequest as j, AgentDecisionExecutor as k, AgentTextRequest as l, StructuredOutputEnvelope as m, AgentModelRef as n, AgentRequestExecutorResult as o, BuiltinAgentActors as p, getAcceptedEvents as q, AgentOutputMode as r, AgentRequestExecutors as s, AgentModelMap as t, AgentUserInput as u, TextLogicExecutor as v, getAgentOutputMode as w, bindRequestExecutor as x, TextLogicInput as y, ResolveDecisionOptions as z };
@@ -38,15 +38,26 @@ interface StandardSchemaV1<Input = unknown, Output = Input> {
38
38
  type InferOutput<T> = T extends StandardSchemaV1<any, infer O> ? O : never;
39
39
  /** An event schema's output, widened to `unknown` when it validates an empty object (no payload fields). */
40
40
  type EventPayload<T> = T extends Record<string, never> ? unknown : T;
41
+ /**
42
+ * One entry in an event schema map: a Standard Schema for the event's
43
+ * payload, or the `{}` shorthand for a payload-less event
44
+ * (`events: { CONFIRM: {} }` ≡ `events: { CONFIRM: z.object({}) }`).
45
+ */
46
+ type AgentEventSchemaInput = StandardSchemaV1 | Record<string, never>;
47
+ /** An event schema map as authored: payload schemas and/or `{}` payload-less shorthands, keyed by event type. */
48
+ type AgentEventSchemaInputMap = Record<string, AgentEventSchemaInput>;
49
+ /** Resolves an authored event schema map's `{}` shorthands to real (empty-payload) schemas — the type-level counterpart of the runtime normalization in `createAgentSchemas`. */
50
+ type NormalizedEventSchemas<T extends AgentEventSchemaInputMap> = { [K in keyof T]: T[K] extends StandardSchemaV1 ? T[K] : StandardSchemaV1<{}> };
41
51
  /**
42
52
  * The discriminated event union derived from a machine's event schema map
43
53
  * (e.g. `{ ASK: z.object({ question: z.string() }) }` → `{ type: 'ASK';
44
- * question: string }`). Used internally by {@link createAgentSchemas} and
45
- * `setupAgent` to type a machine's `TEvent`.
54
+ * question: string }`; a `{}` shorthand entry yields its bare `{ type: K }`).
55
+ * Used internally by {@link createAgentSchemas} and `setupAgent` to type a
56
+ * machine's `TEvent`.
46
57
  */
47
- type EventUnion<T extends Record<string, StandardSchemaV1>> = { [K in keyof T & string]: {
58
+ type EventUnion<T extends AgentEventSchemaInputMap> = { [K in keyof T & string]: {
48
59
  type: K;
49
- } & EventPayload<InferOutput<T[K]>> }[keyof T & string];
60
+ } & (T[K] extends StandardSchemaV1 ? EventPayload<InferOutput<T[K]>> : unknown) }[keyof T & string];
50
61
  /** Raw binary or string content for an {@link ImagePart}/{@link FilePart}. */
51
62
  type DataContent = string | Uint8Array | ArrayBuffer;
52
63
  /** Provider-specific passthrough options, keyed by provider name (e.g. `{ anthropic: { cacheControl: ... } }`). */
@@ -205,4 +216,4 @@ type AllowedEvents<TEvent extends string = string, TInput = unknown> = AllowedEv
205
216
  input: TInput;
206
217
  }) => AllowedEventPattern<TEvent> | readonly AllowedEventPattern<TEvent>[]);
207
218
  //#endregion
208
- export { ToolCallPart as C, UserMessage as D, ToolResultPart as E, TextPart as S, ToolResultOutput as T, ImagePart as _, AgentToolDescriptor as a, StandardSchemaV1 as b, AgentTools as c, AssistantMessage as d, ChosenEvent as f, FilePart as g, EventUnion as h, AgentToolChoice as i, AllowedEventPattern as l, EventPayload as m, AgentSnapshotStore as n, AgentToolExecute as o, DataContent as p, AgentTool as r, AgentToolSchema as s, AgentMessage as t, AllowedEvents as u, InferOutput as v, ToolMessage as w, SystemMessage as x, ProviderOptions as y };
219
+ export { UserMessage as A, StandardSchemaV1 as C, ToolMessage as D, ToolCallPart as E, ToolResultOutput as O, ProviderOptions as S, TextPart as T, EventUnion as _, AgentTool as a, InferOutput as b, AgentToolExecute as c, AllowedEventPattern as d, AllowedEvents as f, EventPayload as g, DataContent as h, AgentSnapshotStore as i, ToolResultPart as k, AgentToolSchema as l, ChosenEvent as m, AgentEventSchemaInputMap as n, AgentToolChoice as o, AssistantMessage as p, AgentMessage as r, AgentToolDescriptor as s, AgentEventSchemaInput as t, AgentTools as u, FilePart as v, SystemMessage as w, NormalizedEventSchemas as x, ImagePart as y };
@@ -38,15 +38,26 @@ interface StandardSchemaV1<Input = unknown, Output = Input> {
38
38
  type InferOutput<T> = T extends StandardSchemaV1<any, infer O> ? O : never;
39
39
  /** An event schema's output, widened to `unknown` when it validates an empty object (no payload fields). */
40
40
  type EventPayload<T> = T extends Record<string, never> ? unknown : T;
41
+ /**
42
+ * One entry in an event schema map: a Standard Schema for the event's
43
+ * payload, or the `{}` shorthand for a payload-less event
44
+ * (`events: { CONFIRM: {} }` ≡ `events: { CONFIRM: z.object({}) }`).
45
+ */
46
+ type AgentEventSchemaInput = StandardSchemaV1 | Record<string, never>;
47
+ /** An event schema map as authored: payload schemas and/or `{}` payload-less shorthands, keyed by event type. */
48
+ type AgentEventSchemaInputMap = Record<string, AgentEventSchemaInput>;
49
+ /** Resolves an authored event schema map's `{}` shorthands to real (empty-payload) schemas — the type-level counterpart of the runtime normalization in `createAgentSchemas`. */
50
+ type NormalizedEventSchemas<T extends AgentEventSchemaInputMap> = { [K in keyof T]: T[K] extends StandardSchemaV1 ? T[K] : StandardSchemaV1<{}> };
41
51
  /**
42
52
  * The discriminated event union derived from a machine's event schema map
43
53
  * (e.g. `{ ASK: z.object({ question: z.string() }) }` → `{ type: 'ASK';
44
- * question: string }`). Used internally by {@link createAgentSchemas} and
45
- * `setupAgent` to type a machine's `TEvent`.
54
+ * question: string }`; a `{}` shorthand entry yields its bare `{ type: K }`).
55
+ * Used internally by {@link createAgentSchemas} and `setupAgent` to type a
56
+ * machine's `TEvent`.
46
57
  */
47
- type EventUnion<T extends Record<string, StandardSchemaV1>> = { [K in keyof T & string]: {
58
+ type EventUnion<T extends AgentEventSchemaInputMap> = { [K in keyof T & string]: {
48
59
  type: K;
49
- } & EventPayload<InferOutput<T[K]>> }[keyof T & string];
60
+ } & (T[K] extends StandardSchemaV1 ? EventPayload<InferOutput<T[K]>> : unknown) }[keyof T & string];
50
61
  /** Raw binary or string content for an {@link ImagePart}/{@link FilePart}. */
51
62
  type DataContent = string | Uint8Array | ArrayBuffer;
52
63
  /** Provider-specific passthrough options, keyed by provider name (e.g. `{ anthropic: { cacheControl: ... } }`). */
@@ -205,4 +216,4 @@ type AllowedEvents<TEvent extends string = string, TInput = unknown> = AllowedEv
205
216
  input: TInput;
206
217
  }) => AllowedEventPattern<TEvent> | readonly AllowedEventPattern<TEvent>[]);
207
218
  //#endregion
208
- export { ToolCallPart as C, UserMessage as D, ToolResultPart as E, TextPart as S, ToolResultOutput as T, ImagePart as _, AgentToolDescriptor as a, StandardSchemaV1 as b, AgentTools as c, AssistantMessage as d, ChosenEvent as f, FilePart as g, EventUnion as h, AgentToolChoice as i, AllowedEventPattern as l, EventPayload as m, AgentSnapshotStore as n, AgentToolExecute as o, DataContent as p, AgentTool as r, AgentToolSchema as s, AgentMessage as t, AllowedEvents as u, InferOutput as v, ToolMessage as w, SystemMessage as x, ProviderOptions as y };
219
+ export { UserMessage as A, StandardSchemaV1 as C, ToolMessage as D, ToolCallPart as E, ToolResultOutput as O, ProviderOptions as S, TextPart as T, EventUnion as _, AgentTool as a, InferOutput as b, AgentToolExecute as c, AllowedEventPattern as d, AllowedEvents as f, EventPayload as g, DataContent as h, AgentSnapshotStore as i, ToolResultPart as k, AgentToolSchema as l, ChosenEvent as m, AgentEventSchemaInputMap as n, AgentToolChoice as o, AssistantMessage as p, AgentMessage as r, AgentToolDescriptor as s, AgentEventSchemaInput as t, AgentTools as u, FilePart as v, SystemMessage as w, NormalizedEventSchemas as x, ImagePart as y };
@@ -1,4 +1,4 @@
1
- import { C as ToolCallPart, D as UserMessage, E as ToolResultPart, S as TextPart, _ as ImagePart, b as StandardSchemaV1, d as AssistantMessage, g as FilePart, t as AgentMessage, w as ToolMessage, x as SystemMessage } from "./types-Cq1YlAQ6.mjs";
1
+ import { A as UserMessage, C as StandardSchemaV1, D as ToolMessage, E as ToolCallPart, T as TextPart, k as ToolResultPart, p as AssistantMessage, r as AgentMessage, v as FilePart, w as SystemMessage, y as ImagePart } from "./types-C9QiMjre.cjs";
2
2
  import { AnyMachineSnapshot, AnyStateMachine } from "xstate";
3
3
 
4
4
  //#region src/utils.d.ts
@@ -1,4 +1,4 @@
1
- import { C as ToolCallPart, D as UserMessage, E as ToolResultPart, S as TextPart, _ as ImagePart, b as StandardSchemaV1, d as AssistantMessage, g as FilePart, t as AgentMessage, w as ToolMessage, x as SystemMessage } from "./types-BHjeDdch.cjs";
1
+ import { A as UserMessage, C as StandardSchemaV1, D as ToolMessage, E as ToolCallPart, T as TextPart, k as ToolResultPart, p as AssistantMessage, r as AgentMessage, v as FilePart, w as SystemMessage, y as ImagePart } from "./types-qm00QF91.mjs";
2
2
  import { AnyMachineSnapshot, AnyStateMachine } from "xstate";
3
3
 
4
4
  //#region src/utils.d.ts
package/dist/zod.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { t as AgentMessage } from "./types-BHjeDdch.cjs";
1
+ import { r as AgentMessage } from "./types-C9QiMjre.cjs";
2
2
  import { z } from "zod";
3
3
 
4
4
  //#region src/zod/index.d.ts
package/dist/zod.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { t as AgentMessage } from "./types-Cq1YlAQ6.mjs";
1
+ import { r as AgentMessage } from "./types-qm00QF91.mjs";
2
2
  import { z } from "zod";
3
3
 
4
4
  //#region src/zod/index.d.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statelyai/agent",
3
- "version": "2.0.0-alpha.6",
3
+ "version": "2.0.0-alpha.8",
4
4
  "description": "State-machine authoring layer for AI agents",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -96,7 +96,7 @@
96
96
  "tsx": "^4.21.0",
97
97
  "typescript": "^5.6.2",
98
98
  "vitest": "^2.1.2",
99
- "xstate": "6.0.0-alpha.17",
99
+ "xstate": "6.0.0-alpha.21",
100
100
  "zod": "^4.3.6"
101
101
  },
102
102
  "publishConfig": {
package/readme.md CHANGED
@@ -24,18 +24,18 @@ Node 22.18 or newer is required.
24
24
 
25
25
  ## Quick start
26
26
 
27
- <!-- refund decision example using setupAgent, agent.decide, a machine guard, and runAgent -->
27
+ <!-- refund decision example using setupAgent, agent.decide, a machine guard, and the AI SDK runAgent host -->
28
28
 
29
29
  This agent reviews refund requests. The model may propose an automatic refund, but the state machine owns the $100 limit.
30
30
 
31
31
  ```ts
32
- import { openai } from '@ai-sdk/openai';
33
- import { createAiSdkExecutors, defineModels } from '@statelyai/agent/ai-sdk';
34
- import { runAgent, setupAgent } from '@statelyai/agent';
35
- import { z } from 'zod';
32
+ import { openai } from "@ai-sdk/openai";
33
+ import { defineModels, runAgent } from "@statelyai/agent/ai-sdk";
34
+ import { setupAgent } from "@statelyai/agent";
35
+ import { z } from "zod";
36
36
 
37
37
  const models = defineModels({
38
- fast: openai('gpt-5.4-mini'),
38
+ fast: openai("gpt-5.4-mini"),
39
39
  });
40
40
 
41
41
  const agent = setupAgent({
@@ -49,54 +49,52 @@ const agent = setupAgent({
49
49
  amount: z.number(),
50
50
  }),
51
51
  output: z.object({
52
- outcome: z.enum(['refunded', 'review']),
52
+ outcome: z.enum(["refunded", "review"]),
53
53
  }),
54
54
  events: {
55
- AUTO_REFUND: z.object({}),
55
+ AUTO_REFUND: {},
56
56
  REVIEW: z.object({ reason: z.string() }),
57
57
  },
58
58
  });
59
59
 
60
60
  const refundMachine = agent.createMachine({
61
61
  context: ({ input }) => input,
62
- initial: 'deciding',
62
+ initial: "deciding",
63
63
  states: {
64
64
  deciding: {
65
65
  invoke: {
66
- src: 'agent.decide',
66
+ src: "agent.decide",
67
67
  input: ({ context }) => ({
68
- model: 'fast',
69
- system: 'Choose AUTO_REFUND for eligible requests. Otherwise choose REVIEW.',
68
+ model: "fast",
69
+ system: "Choose AUTO_REFUND for eligible requests. Otherwise choose REVIEW.",
70
70
  prompt: `${context.request}\nAmount: $${context.amount}`,
71
- allowedEvents: ['AUTO_REFUND', 'REVIEW'],
71
+ allowedEvents: ["AUTO_REFUND", "REVIEW"],
72
72
  }),
73
73
  },
74
74
  on: {
75
- AUTO_REFUND: ({ context }) =>
76
- context.amount <= 100 ? { target: 'refunded' } : undefined,
77
- REVIEW: { target: 'review' },
75
+ AUTO_REFUND: ({ context }) => (context.amount <= 100 ? { target: "refunded" } : undefined),
76
+ REVIEW: { target: "review" },
78
77
  },
79
78
  },
80
79
  refunded: {
81
- type: 'final',
82
- output: () => ({ outcome: 'refunded' }),
80
+ type: "final",
81
+ output: () => ({ outcome: "refunded" }),
83
82
  },
84
83
  review: {
85
- type: 'final',
86
- output: () => ({ outcome: 'review' }),
84
+ type: "final",
85
+ output: () => ({ outcome: "review" }),
87
86
  },
88
87
  },
89
88
  });
90
89
 
91
90
  const result = await runAgent(refundMachine, {
92
91
  input: {
93
- request: 'I was charged twice for the same order.',
92
+ request: "I was charged twice for the same order.",
94
93
  amount: 75,
95
94
  },
96
- executors: createAiSdkExecutors({ models }),
97
95
  });
98
96
 
99
- if (result.status === 'done') {
97
+ if (result.status === "done") {
100
98
  console.log(result.output);
101
99
  }
102
100
  ```
@@ -132,6 +130,7 @@ The example has one model decision and two final outcomes. Real machines can add
132
130
  <!-- starter examples derived from examples/*/metadata.json and examples/index.ts -->
133
131
 
134
132
  - [Twenty Questions](examples/twenty-questions) shows a model choosing legal events in a loop.
133
+ - [Go Fish](examples/go-fish) pits a model against a human while the machine enforces hidden-information game rules.
135
134
  - [Human in the loop](examples/human-in-the-loop) pauses, stores a snapshot, and resumes after review.
136
135
  - [Ticket triage](examples/triage) returns structured data from a model request.
137
136
  - [JSON agent](examples/json-agent) runs a machine defined as data.