@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.
- package/dist/ai-sdk.cjs +100 -7
- package/dist/ai-sdk.d.cts +43 -5
- package/dist/ai-sdk.d.mts +43 -5
- package/dist/ai-sdk.mjs +99 -9
- package/dist/cli.cjs +3 -2
- package/dist/cli.mjs +2 -1
- package/dist/{decision-D1654JdD.mjs → decision-CQdrKc8k.mjs} +42 -4
- package/dist/{decision-CX3YdwrO.cjs → decision-b-lkcs4L.cjs} +59 -3
- package/dist/index.cjs +15 -12
- package/dist/index.d.cts +6 -1039
- package/dist/index.d.mts +6 -1039
- package/dist/index.mjs +4 -3
- package/dist/openai-compat.cjs +1 -1
- package/dist/openai-compat.d.cts +3 -3
- package/dist/openai-compat.d.mts +3 -3
- package/dist/openai-compat.mjs +1 -1
- package/dist/{src-CEa947Dm.mjs → run-agent-7OaHM7SB.mjs} +61 -979
- package/dist/{src-wBfi-kTA.cjs → run-agent-BQ3vV7UI.cjs} +59 -1037
- package/dist/run-agent-BzW4emV_.d.cts +1078 -0
- package/dist/run-agent-XYjmBxHi.d.mts +1078 -0
- package/dist/src-CFtSqm-c.cjs +1043 -0
- package/dist/src-d-jhiOgP.mjs +984 -0
- package/dist/{text-logic-1ZQkO3zr.d.cts → text-logic-C7WJpCIc.d.mts} +34 -6
- package/dist/{text-logic-2EMJIS-n.d.mts → text-logic-CZjyACzQ.d.cts} +34 -6
- package/dist/{types-BHjeDdch.d.cts → types-C9QiMjre.d.cts} +16 -5
- package/dist/{types-Cq1YlAQ6.d.mts → types-qm00QF91.d.mts} +16 -5
- package/dist/{utils-CWUCa3pF.d.mts → utils-Dri7aeEG.d.cts} +1 -1
- package/dist/{utils-lK1wnL2i.d.cts → utils-Y6GDRGGE.d.mts} +1 -1
- package/dist/zod.d.cts +1 -1
- package/dist/zod.d.mts +1 -1
- package/package.json +2 -2
- package/readme.md +22 -23
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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
|
-
/**
|
|
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<
|
|
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 {
|
|
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 {
|
|
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
|
-
/**
|
|
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<
|
|
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 {
|
|
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 }`
|
|
45
|
-
* `setupAgent` to type a
|
|
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
|
|
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 {
|
|
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 }`
|
|
45
|
-
* `setupAgent` to type a
|
|
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
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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
package/dist/zod.d.mts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statelyai/agent",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
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.
|
|
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
|
|
33
|
-
import {
|
|
34
|
-
import {
|
|
35
|
-
import { z } from
|
|
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(
|
|
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([
|
|
52
|
+
outcome: z.enum(["refunded", "review"]),
|
|
53
53
|
}),
|
|
54
54
|
events: {
|
|
55
|
-
AUTO_REFUND:
|
|
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:
|
|
62
|
+
initial: "deciding",
|
|
63
63
|
states: {
|
|
64
64
|
deciding: {
|
|
65
65
|
invoke: {
|
|
66
|
-
src:
|
|
66
|
+
src: "agent.decide",
|
|
67
67
|
input: ({ context }) => ({
|
|
68
|
-
model:
|
|
69
|
-
system:
|
|
68
|
+
model: "fast",
|
|
69
|
+
system: "Choose AUTO_REFUND for eligible requests. Otherwise choose REVIEW.",
|
|
70
70
|
prompt: `${context.request}\nAmount: $${context.amount}`,
|
|
71
|
-
allowedEvents: [
|
|
71
|
+
allowedEvents: ["AUTO_REFUND", "REVIEW"],
|
|
72
72
|
}),
|
|
73
73
|
},
|
|
74
74
|
on: {
|
|
75
|
-
AUTO_REFUND: ({ context }) =>
|
|
76
|
-
|
|
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:
|
|
82
|
-
output: () => ({ outcome:
|
|
80
|
+
type: "final",
|
|
81
|
+
output: () => ({ outcome: "refunded" }),
|
|
83
82
|
},
|
|
84
83
|
review: {
|
|
85
|
-
type:
|
|
86
|
-
output: () => ({ outcome:
|
|
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:
|
|
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 ===
|
|
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.
|