@statelyai/agent 2.0.0-alpha.5 → 2.0.0-alpha.7

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.
@@ -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 };
@@ -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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statelyai/agent",
3
- "version": "2.0.0-alpha.5",
3
+ "version": "2.0.0-alpha.7",
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
@@ -132,6 +132,7 @@ The example has one model decision and two final outcomes. Real machines can add
132
132
  <!-- starter examples derived from examples/*/metadata.json and examples/index.ts -->
133
133
 
134
134
  - [Twenty Questions](examples/twenty-questions) shows a model choosing legal events in a loop.
135
+ - [Go Fish](examples/go-fish) pits a model against a human while the machine enforces hidden-information game rules.
135
136
  - [Human in the loop](examples/human-in-the-loop) pauses, stores a snapshot, and resumes after review.
136
137
  - [Ticket triage](examples/triage) returns structured data from a model request.
137
138
  - [JSON agent](examples/json-agent) runs a machine defined as data.