@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.
- package/dist/ai-sdk.cjs +67 -5
- package/dist/ai-sdk.d.cts +11 -2
- package/dist/ai-sdk.d.mts +11 -2
- package/dist/ai-sdk.mjs +68 -7
- package/dist/cli.cjs +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/{decision-pC-bY2DE.cjs → decision-BnATHy0W.cjs} +58 -3
- package/dist/{decision-FTmbqSEe.mjs → decision-mPR_YQd8.mjs} +41 -4
- package/dist/index.cjs +4 -2
- package/dist/index.d.cts +47 -14
- package/dist/index.d.mts +47 -14
- package/dist/index.mjs +3 -3
- package/dist/openai-compat.cjs +1 -1
- package/dist/openai-compat.d.cts +1 -1
- package/dist/openai-compat.d.mts +1 -1
- package/dist/openai-compat.mjs +1 -1
- package/dist/{src-CjpHDU8F.mjs → src-BpQdxsKc.mjs} +69 -19
- package/dist/{src-DcRsWPfV.cjs → src-MysDmqwT.cjs} +69 -19
- package/dist/{text-logic-2EMJIS-n.d.mts → text-logic-2wFNEznm.d.mts} +33 -5
- package/dist/{text-logic-1ZQkO3zr.d.cts → text-logic-4Q2F9kyr.d.cts} +33 -5
- package/package.json +2 -2
- package/readme.md +1 -0
|
@@ -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 };
|
|
@@ -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 };
|
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.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.
|
|
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.
|