@statelyai/agent 2.0.0-alpha.13 → 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.cjs +1 -1
- package/dist/ai-sdk.d.cts +2 -2
- package/dist/ai-sdk.d.mts +2 -2
- package/dist/ai-sdk.mjs +1 -1
- package/dist/{decision-dWGhBh0P.cjs → decision-C0cUKvNt.cjs} +0 -105
- package/dist/{decision-BezSD_YC.mjs → decision-D9Zi7Xi5.mjs} +2 -65
- package/dist/index.cjs +52 -155
- package/dist/index.d.cts +26 -13
- package/dist/index.d.mts +26 -13
- package/dist/index.mjs +54 -156
- package/dist/machines.cjs +1 -1
- package/dist/machines.d.cts +1 -1
- package/dist/machines.d.mts +1 -1
- package/dist/machines.mjs +1 -1
- package/dist/otel.cjs +5 -15
- package/dist/otel.d.cts +1 -1
- package/dist/otel.d.mts +1 -1
- package/dist/otel.mjs +5 -15
- package/dist/{run-agent-C3mFDGTf.d.mts → run-agent-BWzo4FLv.d.mts} +83 -109
- package/dist/{run-agent-DnvtcnTZ.d.cts → run-agent-B_n4Qxye.d.cts} +83 -109
- package/dist/{setup-agent-DP95MFrI.cjs → setup-agent-CpK0ZRWV.cjs} +10 -210
- package/dist/{setup-agent-DAZZSjDS.mjs → setup-agent-DeHRW-qX.mjs} +11 -205
- package/dist/sqlite.d.cts +2 -2
- package/dist/sqlite.d.mts +2 -2
- package/dist/{text-logic-TkKPw8Aq.d.mts → text-logic-C7anC7qX.d.mts} +8 -94
- package/dist/{text-logic-BDxwQNsD.d.cts → text-logic-DZW7XWy9.d.cts} +8 -94
- package/dist/{types-QbEfCVny.d.cts → types-CTBhMnFu.d.mts} +30 -3
- package/dist/{types-_FXoFBGO.d.mts → types-DFD28AWe.d.cts} +30 -3
- package/package.json +1 -1
- /package/dist/{event-log-store-CriMgX1D.d.mts → event-log-store-BkUNtyOF.d.mts} +0 -0
- /package/dist/{event-log-store-Ruq18mGp.d.cts → event-log-store-CVd2eyRy.d.cts} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
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
|
-
import { AnyMachineSnapshot, AsyncActorLogic, EventObject,
|
|
3
|
+
import { AnyMachineSnapshot, AsyncActorLogic, EventObject, MachineSnapshot } from "xstate";
|
|
4
4
|
|
|
5
5
|
//#region src/events.d.ts
|
|
6
6
|
/** The invoke `src` of an {@link AgentRequest}/{@link AgentDecisionRequest} — a plain string, widened so literal `src` values still narrow in editor hints. */
|
|
@@ -16,9 +16,11 @@ interface AgentEventDescriptor {
|
|
|
16
16
|
toolName: string;
|
|
17
17
|
inputSchema?: StandardSchemaV1;
|
|
18
18
|
}
|
|
19
|
-
/** Registered
|
|
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 {
|
|
@@ -97,92 +99,6 @@ interface AgentDecisionInput<TEvent extends string = string, TMetadata = Record<
|
|
|
97
99
|
stopSequences?: string[];
|
|
98
100
|
metadata?: TMetadata;
|
|
99
101
|
}
|
|
100
|
-
/**
|
|
101
|
-
* Inline input for the `agent.plan` builtin actor — a multi-event decision.
|
|
102
|
-
* Where `agent.decide` picks exactly one currently-legal event, `agent.plan`
|
|
103
|
-
* applies an ordered sequence of them: each step re-reads the live snapshot,
|
|
104
|
-
* asks the `decide` executor for one legal event (same validation and
|
|
105
|
-
* `rejected-by-guard` retry loop as a decision), sends it to the machine,
|
|
106
|
-
* and repeats until a `stopOn` event is chosen, `maxSteps` is reached, no
|
|
107
|
-
* legal candidate remains, or an applied event exits the invoking state
|
|
108
|
-
* (which cancels the invoke — the machine simply moves on).
|
|
109
|
-
*
|
|
110
|
-
* Requires a snapshot-aware host: {@link runAgent}, or the step path (where an
|
|
111
|
-
* `agent.plan` invoke re-surfaces as a `kind: 'plan'` request that
|
|
112
|
-
* `resolveAgentRequests` drives one step per call).
|
|
113
|
-
*/
|
|
114
|
-
interface AgentPlanInput<TEvent extends string = string, TMetadata = Record<string, unknown>, TModel extends string = string> extends AgentDecisionInput<TEvent, TMetadata, TModel> {
|
|
115
|
-
/** Maximum events applied in one plan. Default 8. */
|
|
116
|
-
maxSteps?: number;
|
|
117
|
-
/**
|
|
118
|
-
* Machine events that end the plan once chosen: the event is still
|
|
119
|
-
* validated and sent, then the loop stops. Usually unnecessary — every
|
|
120
|
-
* plan step already offers the built-in {@link PLAN_DONE_EVENT_TYPE}
|
|
121
|
-
* "done" option, which ends the plan without touching the machine.
|
|
122
|
-
* Declare `stopOn` only for "send this real event AND stop" semantics.
|
|
123
|
-
*/
|
|
124
|
-
stopOn?: readonly TEvent[];
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Reserved event type the `agent.plan` builtin adds to every step's
|
|
128
|
-
* candidates as the explicit "no further action needed" move. Choosing it
|
|
129
|
-
* ends the plan (`stopped: 'done'`); it is never sent to the machine, so
|
|
130
|
-
* machines need no no-op sentinel event of their own.
|
|
131
|
-
*/
|
|
132
|
-
declare const PLAN_DONE_EVENT_TYPE: "agent.plan.done";
|
|
133
|
-
/** What an `agent.plan` invoke resolves with (its `onDone` output). */
|
|
134
|
-
interface AgentPlanOutput {
|
|
135
|
-
/** The events applied, in order (possibly empty). */
|
|
136
|
-
steps: ChosenEvent[];
|
|
137
|
-
/** Why the loop ended. */
|
|
138
|
-
stopped: "done" | "stop-event" | "max-steps" | "no-legal-events";
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* The in-progress state of a plan, held in the `agent.plan` invoke child's own
|
|
142
|
-
* `createLogic` snapshot `context`. Because a `createLogic` snapshot serializes
|
|
143
|
-
* (and restores) by identity, this lands at
|
|
144
|
-
* `children.<planId>.snapshot.context` in a machine's persisted snapshot for
|
|
145
|
-
* free — so a step-path host that persists after every event resumes a plan
|
|
146
|
-
* mid-flight without a bespoke carrier.
|
|
147
|
-
*/
|
|
148
|
-
interface PlanLedgerContext {
|
|
149
|
-
/** The events applied so far in this plan, in order (the trail). */
|
|
150
|
-
applied: ChosenEvent[];
|
|
151
|
-
/** How many more events the plan may apply (`maxSteps - applied.length`). */
|
|
152
|
-
stepsRemaining: number;
|
|
153
|
-
/** Set once the plan terminates; `null` while in flight. */
|
|
154
|
-
stopped: AgentPlanOutput["stopped"] | null;
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* The two ledger events that drive a {@link PlanLedgerContext} forward:
|
|
158
|
-
* `plan.applied` appends one event to the trail and decrements the budget;
|
|
159
|
-
* `plan.ended` records the stop reason and completes the ledger (its snapshot
|
|
160
|
-
* goes `done` with the {@link AgentPlanOutput}).
|
|
161
|
-
*/
|
|
162
|
-
type PlanLedgerEvent = {
|
|
163
|
-
type: "plan.applied";
|
|
164
|
-
event: ChosenEvent;
|
|
165
|
-
} | {
|
|
166
|
-
type: "plan.ended";
|
|
167
|
-
stopped: AgentPlanOutput["stopped"];
|
|
168
|
-
};
|
|
169
|
-
/**
|
|
170
|
-
* Actor logic for the `agent.plan` builtin: a stateful, transition-based
|
|
171
|
-
* ledger. Its snapshot `context` ({@link PlanLedgerContext}) IS the plan's
|
|
172
|
-
* in-progress state — the applied trail plus remaining budget — advanced one
|
|
173
|
-
* {@link PlanLedgerEvent} at a time. On the step path the invoke child runs this
|
|
174
|
-
* logic directly (so its context persists at `children.<id>.snapshot.context`);
|
|
175
|
-
* runAgent swaps in an async implementation that drives the SAME ledger via the
|
|
176
|
-
* shared {@link initialPlanLedger}/{@link advancePlanLedger} drivers.
|
|
177
|
-
*/
|
|
178
|
-
interface PlanLogic<TInputSchema extends StandardSchemaV1 = StandardSchemaV1<AgentPlanInput>> extends LogicActorLogic<PlanLedgerContext, AgentPlanOutput, PlanLedgerEvent, InferOutput<TInputSchema>> {
|
|
179
|
-
readonly kind: "statelyai.planLogic";
|
|
180
|
-
readonly maxRetries: number;
|
|
181
|
-
/** Builds the per-step base {@link AgentDecisionRequest} (id/events filled in per step). */
|
|
182
|
-
request(input: InferOutput<TInputSchema>): AgentDecisionRequest;
|
|
183
|
-
/** @internal Resolves declared `allowedEvents` (undefined = all currently legal). */
|
|
184
|
-
allowedEventTypes(input: InferOutput<TInputSchema>): readonly string[] | undefined;
|
|
185
|
-
}
|
|
186
102
|
/**
|
|
187
103
|
* Config for {@link createDecisionLogic}: how to build an
|
|
188
104
|
* {@link AgentDecisionRequest} from typed input. Each field mirrors
|
|
@@ -366,7 +282,6 @@ declare const USER_INPUT_ACTOR: "agent.userInput";
|
|
|
366
282
|
declare const GENERATE_TEXT_ACTOR: "agent.generateText";
|
|
367
283
|
declare const STREAM_TEXT_ACTOR: "agent.streamText";
|
|
368
284
|
declare const DECIDE_ACTOR: "agent.decide";
|
|
369
|
-
declare const PLAN_ACTOR: "agent.plan";
|
|
370
285
|
/** Whether a text request should be resolved with `generateText` (one-shot) or `streamText` (chunked, via `onChunk`). */
|
|
371
286
|
type AgentRequestMode = "generate" | "stream";
|
|
372
287
|
/** A `setupAgent({ models })` model registry, mapping short model refs to provider-specific model values. */
|
|
@@ -485,13 +400,12 @@ interface AgentUserInput<TMetadata = Record<string, unknown>> {
|
|
|
485
400
|
prompt?: string;
|
|
486
401
|
metadata?: TMetadata;
|
|
487
402
|
}
|
|
488
|
-
/** The
|
|
403
|
+
/** The four `agent.*` builtin actor logics every setupAgent-built machine registers. @internal */
|
|
489
404
|
type BuiltinAgentActors<TEvent extends string = string, TModel extends string = string> = {
|
|
490
405
|
[GENERATE_TEXT_ACTOR]: AsyncActorLogic<unknown, AgentTextRequest>;
|
|
491
406
|
[STREAM_TEXT_ACTOR]: AsyncActorLogic<unknown, AgentTextRequest>;
|
|
492
407
|
[USER_INPUT_ACTOR]: AsyncActorLogic<string, AgentUserInput>;
|
|
493
408
|
[DECIDE_ACTOR]: AsyncActorLogic<ChosenEvent, AgentDecisionInput<TEvent, Record<string, unknown>, TModel>>;
|
|
494
|
-
[PLAN_ACTOR]: PlanLogic<StandardSchemaV1<AgentPlanInput<TEvent, Record<string, unknown>, TModel>>>;
|
|
495
409
|
};
|
|
496
410
|
/**
|
|
497
411
|
* Validates a raw model/executor output against `schema`, returning the
|
|
@@ -733,7 +647,7 @@ type AgentRequestExecutor<TResult extends AgentRequestExecutorResult = AgentRequ
|
|
|
733
647
|
* with — passed to `runAgent`, `executeAgentRequest`, and
|
|
734
648
|
* `TextLogic.execute`. Every slot is optional: `generateText` is needed only
|
|
735
649
|
* if the machine has a `mode: 'generate'` text request, `streamText` only for
|
|
736
|
-
* a `mode: 'stream'` request, and `decide` only for a decision
|
|
650
|
+
* a `mode: 'stream'` request, and `decide` only for a decision — omitting
|
|
737
651
|
* a slot the machine actually needs is a clear bind-time error (see `runAgent`
|
|
738
652
|
* and `provideExecutors`). Adapter result sets (`AiSdkExecutors`,
|
|
739
653
|
* `OpenAiCompatExecutors`) re-require all three.
|
|
@@ -790,4 +704,4 @@ declare function buildEnvelopeSchema(inner: StandardSchemaV1, options?: {
|
|
|
790
704
|
*/
|
|
791
705
|
declare function parseStructuredEnvelope(request: Pick<AgentTextRequest, "outputSchema" | "reasoning">, value: unknown): StructuredOutputEnvelope;
|
|
792
706
|
//#endregion
|
|
793
|
-
export { AgentDecisionExhaustedError as A,
|
|
707
|
+
export { AgentDecisionExhaustedError as A, AgentRequestOptions as B, buildEnvelopeSchema as C, parseOutput as D, parseModelRef as E, ResolveDecisionOptions as F, getAcceptedEvents as H, renderDecisionAttempts as I, resolveDecision as L, AgentDecisionRequest as M, DecisionAttempt as N, parseStructuredEnvelope as O, DecisionLogicConfig as P, AgentEventDescriptor as R, bindRequestExecutor as S, getAgentOutputMode as T, parseAgentEvent as U, AgentRequestSource as V, StructuredOutputEnvelope as _, AgentOutputMode as a, TextLogicExecuteArgs as b, AgentRequestExecutorResult as c, AgentTextRequest as d, AgentUsage as f, BuiltinAgentActors as g, AiSdkShapedTextResult as h, AgentModelRef as i, AgentDecisionInput as j, AgentDecisionExecutor as k, AgentRequestExecutors as l, AiSdkShapedStreamResult as m, AgentExecutorTextRequest as n, AgentRequestExecutor as o, AgentUserInput as p, AgentModelMap as r, AgentRequestExecutorInfo as s, AgentCallUsage as t, AgentRequestMode as u, TextLogic as v, createTextLogic as w, TextLogicExecutor as x, TextLogicConfig as y, AgentEventToolNameResolver as z };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
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
|
-
import { AnyMachineSnapshot, AsyncActorLogic, EventObject,
|
|
3
|
+
import { AnyMachineSnapshot, AsyncActorLogic, EventObject, MachineSnapshot } from "xstate";
|
|
4
4
|
|
|
5
5
|
//#region src/events.d.ts
|
|
6
6
|
/** The invoke `src` of an {@link AgentRequest}/{@link AgentDecisionRequest} — a plain string, widened so literal `src` values still narrow in editor hints. */
|
|
@@ -16,9 +16,11 @@ interface AgentEventDescriptor {
|
|
|
16
16
|
toolName: string;
|
|
17
17
|
inputSchema?: StandardSchemaV1;
|
|
18
18
|
}
|
|
19
|
-
/** Registered
|
|
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 {
|
|
@@ -97,92 +99,6 @@ interface AgentDecisionInput<TEvent extends string = string, TMetadata = Record<
|
|
|
97
99
|
stopSequences?: string[];
|
|
98
100
|
metadata?: TMetadata;
|
|
99
101
|
}
|
|
100
|
-
/**
|
|
101
|
-
* Inline input for the `agent.plan` builtin actor — a multi-event decision.
|
|
102
|
-
* Where `agent.decide` picks exactly one currently-legal event, `agent.plan`
|
|
103
|
-
* applies an ordered sequence of them: each step re-reads the live snapshot,
|
|
104
|
-
* asks the `decide` executor for one legal event (same validation and
|
|
105
|
-
* `rejected-by-guard` retry loop as a decision), sends it to the machine,
|
|
106
|
-
* and repeats until a `stopOn` event is chosen, `maxSteps` is reached, no
|
|
107
|
-
* legal candidate remains, or an applied event exits the invoking state
|
|
108
|
-
* (which cancels the invoke — the machine simply moves on).
|
|
109
|
-
*
|
|
110
|
-
* Requires a snapshot-aware host: {@link runAgent}, or the step path (where an
|
|
111
|
-
* `agent.plan` invoke re-surfaces as a `kind: 'plan'` request that
|
|
112
|
-
* `resolveAgentRequests` drives one step per call).
|
|
113
|
-
*/
|
|
114
|
-
interface AgentPlanInput<TEvent extends string = string, TMetadata = Record<string, unknown>, TModel extends string = string> extends AgentDecisionInput<TEvent, TMetadata, TModel> {
|
|
115
|
-
/** Maximum events applied in one plan. Default 8. */
|
|
116
|
-
maxSteps?: number;
|
|
117
|
-
/**
|
|
118
|
-
* Machine events that end the plan once chosen: the event is still
|
|
119
|
-
* validated and sent, then the loop stops. Usually unnecessary — every
|
|
120
|
-
* plan step already offers the built-in {@link PLAN_DONE_EVENT_TYPE}
|
|
121
|
-
* "done" option, which ends the plan without touching the machine.
|
|
122
|
-
* Declare `stopOn` only for "send this real event AND stop" semantics.
|
|
123
|
-
*/
|
|
124
|
-
stopOn?: readonly TEvent[];
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Reserved event type the `agent.plan` builtin adds to every step's
|
|
128
|
-
* candidates as the explicit "no further action needed" move. Choosing it
|
|
129
|
-
* ends the plan (`stopped: 'done'`); it is never sent to the machine, so
|
|
130
|
-
* machines need no no-op sentinel event of their own.
|
|
131
|
-
*/
|
|
132
|
-
declare const PLAN_DONE_EVENT_TYPE: "agent.plan.done";
|
|
133
|
-
/** What an `agent.plan` invoke resolves with (its `onDone` output). */
|
|
134
|
-
interface AgentPlanOutput {
|
|
135
|
-
/** The events applied, in order (possibly empty). */
|
|
136
|
-
steps: ChosenEvent[];
|
|
137
|
-
/** Why the loop ended. */
|
|
138
|
-
stopped: "done" | "stop-event" | "max-steps" | "no-legal-events";
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* The in-progress state of a plan, held in the `agent.plan` invoke child's own
|
|
142
|
-
* `createLogic` snapshot `context`. Because a `createLogic` snapshot serializes
|
|
143
|
-
* (and restores) by identity, this lands at
|
|
144
|
-
* `children.<planId>.snapshot.context` in a machine's persisted snapshot for
|
|
145
|
-
* free — so a step-path host that persists after every event resumes a plan
|
|
146
|
-
* mid-flight without a bespoke carrier.
|
|
147
|
-
*/
|
|
148
|
-
interface PlanLedgerContext {
|
|
149
|
-
/** The events applied so far in this plan, in order (the trail). */
|
|
150
|
-
applied: ChosenEvent[];
|
|
151
|
-
/** How many more events the plan may apply (`maxSteps - applied.length`). */
|
|
152
|
-
stepsRemaining: number;
|
|
153
|
-
/** Set once the plan terminates; `null` while in flight. */
|
|
154
|
-
stopped: AgentPlanOutput["stopped"] | null;
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* The two ledger events that drive a {@link PlanLedgerContext} forward:
|
|
158
|
-
* `plan.applied` appends one event to the trail and decrements the budget;
|
|
159
|
-
* `plan.ended` records the stop reason and completes the ledger (its snapshot
|
|
160
|
-
* goes `done` with the {@link AgentPlanOutput}).
|
|
161
|
-
*/
|
|
162
|
-
type PlanLedgerEvent = {
|
|
163
|
-
type: "plan.applied";
|
|
164
|
-
event: ChosenEvent;
|
|
165
|
-
} | {
|
|
166
|
-
type: "plan.ended";
|
|
167
|
-
stopped: AgentPlanOutput["stopped"];
|
|
168
|
-
};
|
|
169
|
-
/**
|
|
170
|
-
* Actor logic for the `agent.plan` builtin: a stateful, transition-based
|
|
171
|
-
* ledger. Its snapshot `context` ({@link PlanLedgerContext}) IS the plan's
|
|
172
|
-
* in-progress state — the applied trail plus remaining budget — advanced one
|
|
173
|
-
* {@link PlanLedgerEvent} at a time. On the step path the invoke child runs this
|
|
174
|
-
* logic directly (so its context persists at `children.<id>.snapshot.context`);
|
|
175
|
-
* runAgent swaps in an async implementation that drives the SAME ledger via the
|
|
176
|
-
* shared {@link initialPlanLedger}/{@link advancePlanLedger} drivers.
|
|
177
|
-
*/
|
|
178
|
-
interface PlanLogic<TInputSchema extends StandardSchemaV1 = StandardSchemaV1<AgentPlanInput>> extends LogicActorLogic<PlanLedgerContext, AgentPlanOutput, PlanLedgerEvent, InferOutput<TInputSchema>> {
|
|
179
|
-
readonly kind: "statelyai.planLogic";
|
|
180
|
-
readonly maxRetries: number;
|
|
181
|
-
/** Builds the per-step base {@link AgentDecisionRequest} (id/events filled in per step). */
|
|
182
|
-
request(input: InferOutput<TInputSchema>): AgentDecisionRequest;
|
|
183
|
-
/** @internal Resolves declared `allowedEvents` (undefined = all currently legal). */
|
|
184
|
-
allowedEventTypes(input: InferOutput<TInputSchema>): readonly string[] | undefined;
|
|
185
|
-
}
|
|
186
102
|
/**
|
|
187
103
|
* Config for {@link createDecisionLogic}: how to build an
|
|
188
104
|
* {@link AgentDecisionRequest} from typed input. Each field mirrors
|
|
@@ -366,7 +282,6 @@ declare const USER_INPUT_ACTOR: "agent.userInput";
|
|
|
366
282
|
declare const GENERATE_TEXT_ACTOR: "agent.generateText";
|
|
367
283
|
declare const STREAM_TEXT_ACTOR: "agent.streamText";
|
|
368
284
|
declare const DECIDE_ACTOR: "agent.decide";
|
|
369
|
-
declare const PLAN_ACTOR: "agent.plan";
|
|
370
285
|
/** Whether a text request should be resolved with `generateText` (one-shot) or `streamText` (chunked, via `onChunk`). */
|
|
371
286
|
type AgentRequestMode = "generate" | "stream";
|
|
372
287
|
/** A `setupAgent({ models })` model registry, mapping short model refs to provider-specific model values. */
|
|
@@ -485,13 +400,12 @@ interface AgentUserInput<TMetadata = Record<string, unknown>> {
|
|
|
485
400
|
prompt?: string;
|
|
486
401
|
metadata?: TMetadata;
|
|
487
402
|
}
|
|
488
|
-
/** The
|
|
403
|
+
/** The four `agent.*` builtin actor logics every setupAgent-built machine registers. @internal */
|
|
489
404
|
type BuiltinAgentActors<TEvent extends string = string, TModel extends string = string> = {
|
|
490
405
|
[GENERATE_TEXT_ACTOR]: AsyncActorLogic<unknown, AgentTextRequest>;
|
|
491
406
|
[STREAM_TEXT_ACTOR]: AsyncActorLogic<unknown, AgentTextRequest>;
|
|
492
407
|
[USER_INPUT_ACTOR]: AsyncActorLogic<string, AgentUserInput>;
|
|
493
408
|
[DECIDE_ACTOR]: AsyncActorLogic<ChosenEvent, AgentDecisionInput<TEvent, Record<string, unknown>, TModel>>;
|
|
494
|
-
[PLAN_ACTOR]: PlanLogic<StandardSchemaV1<AgentPlanInput<TEvent, Record<string, unknown>, TModel>>>;
|
|
495
409
|
};
|
|
496
410
|
/**
|
|
497
411
|
* Validates a raw model/executor output against `schema`, returning the
|
|
@@ -733,7 +647,7 @@ type AgentRequestExecutor<TResult extends AgentRequestExecutorResult = AgentRequ
|
|
|
733
647
|
* with — passed to `runAgent`, `executeAgentRequest`, and
|
|
734
648
|
* `TextLogic.execute`. Every slot is optional: `generateText` is needed only
|
|
735
649
|
* if the machine has a `mode: 'generate'` text request, `streamText` only for
|
|
736
|
-
* a `mode: 'stream'` request, and `decide` only for a decision
|
|
650
|
+
* a `mode: 'stream'` request, and `decide` only for a decision — omitting
|
|
737
651
|
* a slot the machine actually needs is a clear bind-time error (see `runAgent`
|
|
738
652
|
* and `provideExecutors`). Adapter result sets (`AiSdkExecutors`,
|
|
739
653
|
* `OpenAiCompatExecutors`) re-require all three.
|
|
@@ -790,4 +704,4 @@ declare function buildEnvelopeSchema(inner: StandardSchemaV1, options?: {
|
|
|
790
704
|
*/
|
|
791
705
|
declare function parseStructuredEnvelope(request: Pick<AgentTextRequest, "outputSchema" | "reasoning">, value: unknown): StructuredOutputEnvelope;
|
|
792
706
|
//#endregion
|
|
793
|
-
export { AgentDecisionExhaustedError as A,
|
|
707
|
+
export { AgentDecisionExhaustedError as A, AgentRequestOptions as B, buildEnvelopeSchema as C, parseOutput as D, parseModelRef as E, ResolveDecisionOptions as F, getAcceptedEvents as H, renderDecisionAttempts as I, resolveDecision as L, AgentDecisionRequest as M, DecisionAttempt as N, parseStructuredEnvelope as O, DecisionLogicConfig as P, AgentEventDescriptor as R, bindRequestExecutor as S, getAgentOutputMode as T, parseAgentEvent as U, AgentRequestSource as V, StructuredOutputEnvelope as _, AgentOutputMode as a, TextLogicExecuteArgs as b, AgentRequestExecutorResult as c, AgentTextRequest as d, AgentUsage as f, BuiltinAgentActors as g, AiSdkShapedTextResult as h, AgentModelRef as i, AgentDecisionInput as j, AgentDecisionExecutor as k, AgentRequestExecutors as l, AiSdkShapedStreamResult as m, AgentExecutorTextRequest as n, AgentRequestExecutor as o, AgentUserInput as p, AgentModelMap as r, AgentRequestExecutorInfo as s, AgentCallUsage as t, AgentRequestMode as u, TextLogic as v, createTextLogic as w, TextLogicExecutor as x, TextLogicConfig as y, AgentEventToolNameResolver as z };
|
|
@@ -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
|
/**
|
|
@@ -201,8 +228,8 @@ type EventWildcardsOf<TEvent extends string> = TEvent extends `${infer Head}.${i
|
|
|
201
228
|
/** One `allowedEvents` entry: an exact declared event type, `'*'` (every event), or a `'prefix.*'` wildcard derived from the declared dotted event types. */
|
|
202
229
|
type AllowedEventPattern<TEvent extends string = string> = TEvent | "*" | EventWildcardsOf<TEvent>;
|
|
203
230
|
/**
|
|
204
|
-
* Candidate event types for a decision
|
|
205
|
-
*
|
|
231
|
+
* Candidate event types for a decision (declared on the `agent.decide`
|
|
232
|
+
* builtin's `allowedEvents` input). A single
|
|
206
233
|
* entry or an array; entries are exact event types or wildcard patterns
|
|
207
234
|
* (`'*'` for every event, `'todo.*'` for a dotted namespace). The effective
|
|
208
235
|
* candidate set offered to the model is this declaration **intersected with
|
|
@@ -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 {
|
|
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
|
/**
|
|
@@ -201,8 +228,8 @@ type EventWildcardsOf<TEvent extends string> = TEvent extends `${infer Head}.${i
|
|
|
201
228
|
/** One `allowedEvents` entry: an exact declared event type, `'*'` (every event), or a `'prefix.*'` wildcard derived from the declared dotted event types. */
|
|
202
229
|
type AllowedEventPattern<TEvent extends string = string> = TEvent | "*" | EventWildcardsOf<TEvent>;
|
|
203
230
|
/**
|
|
204
|
-
* Candidate event types for a decision
|
|
205
|
-
*
|
|
231
|
+
* Candidate event types for a decision (declared on the `agent.decide`
|
|
232
|
+
* builtin's `allowedEvents` input). A single
|
|
206
233
|
* entry or an array; entries are exact event types or wildcard patterns
|
|
207
234
|
* (`'*'` for every event, `'todo.*'` for a dotted namespace). The effective
|
|
208
235
|
* candidate set offered to the model is this declaration **intersected with
|
|
@@ -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 {
|
|
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.
|
|
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",
|
|
File without changes
|
|
File without changes
|