@statelyai/agent 2.0.0-alpha.26 → 2.0.0-alpha.27
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 +4 -4
- package/dist/ai-sdk.d.cts +6 -6
- package/dist/ai-sdk.d.mts +6 -6
- package/dist/ai-sdk.mjs +4 -4
- package/dist/{decision-CM9CYZ6t.cjs → decision-CmM8-HHz.cjs} +10 -9
- package/dist/{decision-DzSv1NpD.mjs → decision-RQ0iv0oZ.mjs} +10 -9
- package/dist/{event-log-store-Ba2fsc4E.mjs → event-log-store-2pAFiWuc.mjs} +1 -1
- package/dist/{event-log-store-DvOcs10J.d.cts → event-log-store-2xzFmgr2.d.cts} +1 -1
- package/dist/{event-log-store-DxyVgnas.d.mts → event-log-store-BIPOz-di.d.mts} +1 -1
- package/dist/{event-log-store-DQmImLYk.cjs → event-log-store-C-COhIXP.cjs} +1 -1
- package/dist/index.cjs +13 -195
- package/dist/index.d.cts +25 -105
- package/dist/index.d.mts +25 -105
- package/dist/index.mjs +12 -189
- package/dist/log.cjs +1 -1
- package/dist/log.d.cts +1 -1
- package/dist/log.d.mts +1 -1
- package/dist/log.mjs +1 -1
- package/dist/machines.cjs +4 -7
- package/dist/machines.d.cts +5 -7
- package/dist/machines.d.mts +5 -7
- package/dist/machines.mjs +4 -7
- package/dist/openai.cjs +3 -3
- package/dist/openai.d.cts +5 -5
- package/dist/openai.d.mts +5 -5
- package/dist/openai.mjs +3 -3
- package/dist/otel.cjs +2 -2
- package/dist/otel.d.cts +3 -3
- package/dist/otel.d.mts +3 -3
- package/dist/otel.mjs +2 -2
- package/dist/{run-agent-CG343kFs.d.mts → run-agent-ByO-Bxyd.d.cts} +184 -179
- package/dist/{run-agent-BOfoJg5B.d.cts → run-agent-COXXc0RW.d.mts} +184 -179
- package/dist/{run-agent-Cb1-LS5P.cjs → run-agent-Dmf8GV2d.cjs} +539 -737
- package/dist/{run-agent-DvDQd4If.mjs → run-agent-xNTxpt82.mjs} +537 -705
- package/dist/{setup-agent-CFW-jPI8.mjs → setup-agent-BuanDXeh.mjs} +6 -28
- package/dist/{setup-agent-CPf7MxnG.cjs → setup-agent-DV4cTou-.cjs} +6 -28
- package/dist/testing.cjs +276 -27
- package/dist/testing.d.cts +17 -15
- package/dist/testing.d.mts +17 -15
- package/dist/testing.mjs +260 -12
- package/dist/{text-logic-Bl_ZRxDi.mjs → text-logic-CIqHAmBi.mjs} +10 -26
- package/dist/{text-logic-BFEOxyxv.d.cts → text-logic-D-czVPYp.d.mts} +27 -28
- package/dist/{text-logic-hZSiRUo1.d.mts → text-logic-IjfYy9DP.d.cts} +27 -28
- package/dist/{text-logic-C8xyr6Ag.cjs → text-logic-f5F5sCdc.cjs} +9 -43
- package/dist/{types-B1Qs2q3q.d.cts → types-BgNbNKnJ.d.mts} +3 -3
- package/dist/{types-tA3SdczG.d.mts → types-hR5f5YXa.d.cts} +3 -3
- package/dist/{utils-C2DPqomn.d.mts → utils-_q7F-AZu.d.mts} +2 -2
- package/dist/{utils-ceStNCOh.d.cts → utils-o4YRdHJX.d.cts} +2 -2
- package/dist/validate.cjs +0 -8
- package/dist/validate.mjs +0 -8
- package/package.json +3 -3
- package/readme.md +4 -2
- package/schemas/agent-workflow.json +0 -8
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { C as UserMessage, S as ToolResultPart, _ as StandardSchemaV1, a as AgentToolDescriptor, b as ToolCallPart, c as AllowedEvents, d as EventUnion, f as FilePart, g as NormalizedEventSchemas, h as InferOutput, i as AgentToolChoice, l as AssistantMessage, m as InferInput, n as AgentMessage, o as AgentToolExecute, p as ImagePart, r as AgentTool, s as AgentTools, t as AgentEventSchemaInputMap, u as ChosenEvent, v as SystemMessage, w as WithAgentInputSchema, x as ToolMessage, y as TextPart } from "./types-
|
|
2
|
-
import { A as AgentDecisionExhaustedError, B as createDecisionRequest, C as getAgentOutputMode, D as parseProviderOutput, E as parseOutput, F as DecisionAttempt, G as AgentRequestOptions, H as resolveDecision, I as DecisionLogic, J as EventFromSnapshot, K as AgentRequestSource, L as DecisionLogicConfig, M as AgentDecisionRequest, N as AgentExecutorDecisionRequest, O as providerOutputSchema, P as CreateDecisionRequestOptions, Q as AgentTruncatedError, R as ResolveDecisionOptions, S as createTextLogic, T as getCallUsage, U as AgentEventDescriptor, V as renderDecisionAttempts, W as AgentInvalidEventPayloadError, X as parseAgentEvent, Y as getAcceptedEvents, Z as AgentError, _ as TextLogic, a as AgentModelRef, b as TextLogicExecutor, c as AgentRequestExecutorInfo, d as AgentRequestMode, f as AgentTextRequest, g as ProviderStructuredOutput, h as BuiltinAgentActors, i as AgentModelMap, j as AgentDecisionInput, k as AgentDecisionExecutor, l as AgentRequestExecutorResult, m as AgentUsage, n as AgentExecutorTextRequest, o as AgentOutputMode, p as AgentTextResult, q as AgentSchemas, r as AgentFinishReason, s as AgentRequestExecutor, t as AgentCallUsage, u as AgentRequestExecutors, v as TextLogicConfig, w as getCallFinishReason, x as bindRequestExecutor, y as TextLogicExecuteArgs, z as createDecisionLogic } from "./text-logic-
|
|
3
|
-
import { C as
|
|
4
|
-
import { c as AgentLogEntry, d as AgentMachineVersionMismatchError, n as AgentEventLogStore, t as AgentEventLogConflictError } from "./event-log-store-
|
|
5
|
-
import { a as getMachineStructuralHash, c as getStatePath, d as toolMessage, f as userMessage, i as getJsonSchemaSync, l as isStandardSchema, n as assistantMessage, o as getMessageText, r as getJsonSchema, s as getStateMeta, u as systemMessage } from "./utils-
|
|
6
|
-
import { AnyActorLogic, AnyMachineSnapshot, AnySetupConfig, AnyStateMachine, AsyncActorLogic, ContextFrom, DoneActorEvent,
|
|
1
|
+
import { C as UserMessage, S as ToolResultPart, _ as StandardSchemaV1, a as AgentToolDescriptor, b as ToolCallPart, c as AllowedEvents, d as EventUnion, f as FilePart, g as NormalizedEventSchemas, h as InferOutput, i as AgentToolChoice, l as AssistantMessage, m as InferInput, n as AgentMessage, o as AgentToolExecute, p as ImagePart, r as AgentTool, s as AgentTools, t as AgentEventSchemaInputMap, u as ChosenEvent, v as SystemMessage, w as WithAgentInputSchema, x as ToolMessage, y as TextPart } from "./types-hR5f5YXa.cjs";
|
|
2
|
+
import { A as AgentDecisionExhaustedError, B as createDecisionRequest, C as getAgentOutputMode, D as parseProviderOutput, E as parseOutput, F as DecisionAttempt, G as AgentRequestOptions, H as resolveDecision, I as DecisionLogic, J as EventFromSnapshot, K as AgentRequestSource, L as DecisionLogicConfig, M as AgentDecisionRequest, N as AgentExecutorDecisionRequest, O as providerOutputSchema, P as CreateDecisionRequestOptions, Q as AgentTruncatedError, R as ResolveDecisionOptions, S as createTextLogic, T as getCallUsage, U as AgentEventDescriptor, V as renderDecisionAttempts, W as AgentInvalidEventPayloadError, X as parseAgentEvent, Y as getAcceptedEvents, Z as AgentError, _ as TextLogic, a as AgentModelRef, b as TextLogicExecutor, c as AgentRequestExecutorInfo, d as AgentRequestMode, f as AgentTextRequest, g as ProviderStructuredOutput, h as BuiltinAgentActors, i as AgentModelMap, j as AgentDecisionInput, k as AgentDecisionExecutor, l as AgentRequestExecutorResult, m as AgentUsage, n as AgentExecutorTextRequest, o as AgentOutputMode, p as AgentTextResult, q as AgentSchemas, r as AgentFinishReason, s as AgentRequestExecutor, t as AgentCallUsage, u as AgentRequestExecutors, v as TextLogicConfig, w as getCallFinishReason, x as bindRequestExecutor, y as TextLogicExecuteArgs, z as createDecisionLogic } from "./text-logic-IjfYy9DP.cjs";
|
|
3
|
+
import { C as serializeTraceEvent, D as AGENT_USAGE_EVENT_TYPE, E as AgentStepRequest, O as AgentUsageEvent, S as runToQuiescence, T as AgentRequest, _ as InspectedActorRef, a as AgentRunErrorCause, b as inspectTransitions, c as AgentRunResult, d as AgentRuntimeOptions, f as AgentSnapshotDivergedError, g as AgentTransitionHandler, h as AgentTraceEvent, i as AgentMaxModelCallsExceededError, l as AgentRunStart, m as AgentTimerScheduler, n as AgentEffects, o as AgentRunInit, p as AgentTimerEvent, r as AgentInputFrom, s as AgentRunMeta, t as AGENT_TRACE_SCHEMA_VERSION, u as AgentRuntime, v as JsonSerializableTraceEvent, w as traceTransitions, x as isAgentIdle, y as createAgentRuntime } from "./run-agent-ByO-Bxyd.cjs";
|
|
4
|
+
import { c as AgentLogEntry, d as AgentMachineVersionMismatchError, n as AgentEventLogStore, t as AgentEventLogConflictError } from "./event-log-store-2xzFmgr2.cjs";
|
|
5
|
+
import { a as getMachineStructuralHash, c as getStatePath, d as toolMessage, f as userMessage, i as getJsonSchemaSync, l as isStandardSchema, n as assistantMessage, o as getMessageText, r as getJsonSchema, s as getStateMeta, u as systemMessage } from "./utils-o4YRdHJX.cjs";
|
|
6
|
+
import { AnyActorLogic, AnyMachineSnapshot, AnySetupConfig, AnyStateMachine, AsyncActorLogic, ContextFrom, DoneActorEvent, EventFromLogic, EventObject, InputFrom, MachineContext, MetaObject, NonReducibleUnknown, OutputFrom, SetupReturnFromConfig, SetupStateSchema, SnapshotFrom, StateValueFrom } from "xstate";
|
|
7
7
|
|
|
8
8
|
//#region src/type-helpers.d.ts
|
|
9
9
|
type SchemaAt<T, TKey extends PropertyKey> = T extends {
|
|
@@ -199,17 +199,6 @@ interface AgentWorkflowConfig {
|
|
|
199
199
|
actors?: Record<string, AgentWorkflowActorConfig>;
|
|
200
200
|
initial: string;
|
|
201
201
|
states: Record<string, AgentWorkflowStateConfig>;
|
|
202
|
-
/**
|
|
203
|
-
* State tags that mark an INTENTIONAL wait for an external event (a human
|
|
204
|
-
* approval, an inbound webhook, …) — the declarative form of `setupAgent({
|
|
205
|
-
* isIdle })`, since a config cannot carry a function. Lowered to a
|
|
206
|
-
* `snapshot.hasTag(...)`-any-of predicate so `runAgent` settles those
|
|
207
|
-
* snapshots idle deterministically instead of using its timing heuristic.
|
|
208
|
-
* Every listed tag must appear in some state's `tags` — an unused tag is a
|
|
209
|
-
* build-time error. A `fromConfig(config, { isIdle })` option takes
|
|
210
|
-
* precedence over declarative `idleTags`.
|
|
211
|
-
*/
|
|
212
|
-
idleTags?: string[];
|
|
213
202
|
meta?: Record<string, unknown>;
|
|
214
203
|
}
|
|
215
204
|
/** A `requests` entry in {@link AgentWorkflowConfig} — the JSON equivalent of a `setupAgent({ requests })` `TextLogicConfig`. Fields beyond `input`/`output`/`tools`/`mode`/`description` are `unknown` because they accept template-expression strings (see {@link AgentWorkflowConfig}). */
|
|
@@ -313,7 +302,7 @@ interface AgentWorkflowActionConfig {
|
|
|
313
302
|
*/
|
|
314
303
|
interface FromConfigResult {
|
|
315
304
|
machine: AnyStateMachine;
|
|
316
|
-
/** Compiled `context`/`events`/`input`/`output`/`meta`/`emitted` schemas — the same pack `
|
|
305
|
+
/** Compiled `context`/`events`/`input`/`output`/`meta`/`emitted` schemas — the same pack `createAgentRuntime` executes this machine with. */
|
|
317
306
|
schemas: AgentSchemaPack<StandardSchemaV1<Record<string, unknown>>, Record<string, StandardSchemaV1>, StandardSchemaV1, StandardSchemaV1, StandardSchemaV1<MetaObject>>;
|
|
318
307
|
}
|
|
319
308
|
/** Options for `setupAgent.fromConfig(...)`. */
|
|
@@ -342,15 +331,6 @@ interface FromConfigOptions {
|
|
|
342
331
|
* implementation here is a build-time error.
|
|
343
332
|
*/
|
|
344
333
|
actions?: Record<string, (params: any) => unknown>;
|
|
345
|
-
/**
|
|
346
|
-
* Detects a snapshot that is an INTENTIONAL wait for an external event —
|
|
347
|
-
* the same machine-carried predicate `setupAgent({ isIdle })` declares
|
|
348
|
-
* for TS-authored machines, registered here because a function cannot live
|
|
349
|
-
* in the workflow config itself. Takes precedence over the config's
|
|
350
|
-
* declarative {@link AgentWorkflowConfig.idleTags}. Travels with the machine
|
|
351
|
-
* through `machine.provide(...)`.
|
|
352
|
-
*/
|
|
353
|
-
isIdle?: (snapshot: AnyMachineSnapshot) => boolean;
|
|
354
334
|
}
|
|
355
335
|
//#endregion
|
|
356
336
|
//#region src/setup-agent.d.ts
|
|
@@ -386,8 +366,7 @@ type AgentDefaultMeta<TEventSchemas extends AgentEventSchemaInputMap> = AgentInt
|
|
|
386
366
|
* A machine's full schema set — context, event payloads, machine input/
|
|
387
367
|
* output, and state/transition meta — as returned by {@link createAgentSchemas}
|
|
388
368
|
* and retained on `setupAgent(...)`'s `result.schemas` for runtime
|
|
389
|
-
* validation (e.g. by
|
|
390
|
-
* by `getAcceptedEvents` to attach event payload schemas). Unlike
|
|
369
|
+
* validation (e.g. by `getAcceptedEvents` to attach event payload schemas). Unlike
|
|
391
370
|
* `AgentSchemaConfig` (the input to `createAgentSchemas`), every field here
|
|
392
371
|
* is required — `events`/`input`/`output`/`meta` default to empty/unknown
|
|
393
372
|
* schemas when not supplied.
|
|
@@ -398,7 +377,7 @@ interface AgentSchemaPack<TContextSchema extends StandardSchemaV1<Record<string,
|
|
|
398
377
|
input: TInputSchema;
|
|
399
378
|
output: TOutputSchema;
|
|
400
379
|
meta: TMetaSchema;
|
|
401
|
-
/** Schemas for events the machine emits (`enq.emit(...)`), keyed by event type — they type `enq.emit` in the machine and the `on` handlers of {@link
|
|
380
|
+
/** Schemas for events the machine emits (`enq.emit(...)`), keyed by event type — they type `enq.emit` in the machine and the `on` handlers of {@link createAgentRuntime}. Optional: omitted means emitted events stay untyped. */
|
|
402
381
|
emitted?: TEmittedSchemas;
|
|
403
382
|
}
|
|
404
383
|
type AgentSchemaConfig<TContextSchema extends StandardSchemaV1<Record<string, unknown>>, TEventSchemas extends AgentEventSchemaInputMap, TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TEmittedSchemas extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>> = {
|
|
@@ -464,7 +443,7 @@ type AgentSetupEmittedSchema<TEmittedSchemas extends Record<string, StandardSche
|
|
|
464
443
|
* XState resolves `schemas.input` to a single type used both by
|
|
465
444
|
* `createActor`'s `input` option and by the `context: ({ input })` factory —
|
|
466
445
|
* and it never validates, so a schema default reads as a required field at the
|
|
467
|
-
* call site while being absent at runtime.
|
|
446
|
+
* call site while being absent at runtime. The runtime validates the input
|
|
468
447
|
* (filling defaults) and reads this brand back through `AgentInputFrom` to
|
|
469
448
|
* accept the schema's looser *input* side, while the factory keeps seeing the
|
|
470
449
|
* validated *output* side.
|
|
@@ -504,17 +483,6 @@ type SetupAgentBaseConfig<TContextSchema extends StandardSchemaV1<Record<string,
|
|
|
504
483
|
actions?: NonNullable<AnySetupConfig["actions"]>;
|
|
505
484
|
guards?: AgentGuardSources<TContextSchema, TEventSchemas>;
|
|
506
485
|
delays?: AgentDelaySources<TContextSchema, TEventSchemas>;
|
|
507
|
-
/**
|
|
508
|
-
* Detects a snapshot that is an INTENTIONAL wait for an external event (a
|
|
509
|
-
* human approval, an inbound webhook, …) — the machine's own declaration of
|
|
510
|
-
* what "idle" means for it, so `runAgent` settles those snapshots idle
|
|
511
|
-
* deterministically instead of using its timing heuristic. Travels with the
|
|
512
|
-
* machine through `machine.provide(...)`. Without one, `runAgent` recognizes
|
|
513
|
-
* resting event-handling states and `meta.interaction` by structure. Use a
|
|
514
|
-
* predicate only for a more specialized machine-owned wait rule. Import and
|
|
515
|
-
* call `isAgentIdle(snapshot)` inside it when expanding the default rule.
|
|
516
|
-
*/
|
|
517
|
-
isIdle?: (snapshot: AnyMachineSnapshot) => boolean;
|
|
518
486
|
};
|
|
519
487
|
type SetupAgentXStateResult<TContextSchema extends StandardSchemaV1<Record<string, unknown>>, TEventSchemas extends AgentEventSchemaInputMap, TActors extends { [K in keyof TActors]: AnyActorLogic }, TRequestSchemas extends AgentRequestSchemaMap, TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TModels extends AgentModelMap, TEmittedSchemas extends Record<string, StandardSchemaV1> = {}, TStateSchemas extends Record<string, SetupStateSchema> = Record<string, SetupStateSchema>> = SetupReturnFromConfig<AgentSetupXStateConfig<TContextSchema, TEventSchemas, TActors, TRequestSchemas, TInputSchema, TOutputSchema, TMetaSchema, TModels, TEmittedSchemas, TStateSchemas>>;
|
|
520
488
|
/**
|
|
@@ -522,13 +490,13 @@ type SetupAgentXStateResult<TContextSchema extends StandardSchemaV1<Record<strin
|
|
|
522
490
|
* (`createMachine`, `assign`, …) extended with `schemas` (the resolved
|
|
523
491
|
* {@link AgentSchemaPack}), `models`, and `requests` (the built request
|
|
524
492
|
* actors). Machines created here are registered so
|
|
525
|
-
* `
|
|
493
|
+
* `createAgentRuntime` can resolve their schemas/actors
|
|
526
494
|
* without re-passing them each call.
|
|
527
495
|
*/
|
|
528
496
|
type SetupAgentResult<TContextSchema extends StandardSchemaV1<Record<string, unknown>>, TEventSchemas extends AgentEventSchemaInputMap, TActors extends { [K in keyof TActors]: AnyActorLogic }, TRequestSchemas extends AgentRequestSchemaMap, TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TModels extends AgentModelMap, TEmittedSchemas extends Record<string, StandardSchemaV1> = {}, TStateSchemas extends Record<string, SetupStateSchema> = Record<string, SetupStateSchema>> = Omit<SetupAgentXStateResult<TContextSchema, TEventSchemas, TActors, TRequestSchemas, TInputSchema, TOutputSchema, TMetaSchema, TModels, TEmittedSchemas, TStateSchemas>, "createMachine"> & {
|
|
529
497
|
/**
|
|
530
498
|
* Creates the agent machine — XState's own `createMachine`, plus: the
|
|
531
|
-
* machine is registered so
|
|
499
|
+
* machine is registered so {@link createAgentRuntime} can resolve
|
|
532
500
|
* its schemas/actors without re-passing them, and a single final state's
|
|
533
501
|
* `output` is copied to the machine root when the root declares none.
|
|
534
502
|
*/
|
|
@@ -540,7 +508,7 @@ type SetupAgentResult<TContextSchema extends StandardSchemaV1<Record<string, unk
|
|
|
540
508
|
/**
|
|
541
509
|
* Schema-first `setup(...)` for agent machines — the standard entry point
|
|
542
510
|
* for authoring a machine (the blueprint) that this library then runs (via
|
|
543
|
-
* {@link
|
|
511
|
+
* {@link createAgentRuntime}) against host-supplied model/decision
|
|
544
512
|
* executors. Context, events, machine input, machine output, and
|
|
545
513
|
* state/transition meta are all standard schemas — no `{} as Type` casts —
|
|
546
514
|
* and are retained on `result.schemas` for runtime validation. Also
|
|
@@ -602,7 +570,10 @@ declare namespace setupAgent {
|
|
|
602
570
|
* const { machine, schemas } = setupAgent.fromConfig(workflowConfig, {
|
|
603
571
|
* compileSchema,
|
|
604
572
|
* });
|
|
605
|
-
* const result = await
|
|
573
|
+
* const result = await runToQuiescence(
|
|
574
|
+
* createAgentRuntime(machine, { executors: { generateText, decide } }),
|
|
575
|
+
* { input: { ticket } },
|
|
576
|
+
* );
|
|
606
577
|
* const event = parseAgentEvent(result.snapshot, raw, { events: schemas.events });
|
|
607
578
|
* ```
|
|
608
579
|
*/
|
|
@@ -620,57 +591,6 @@ declare namespace setupAgent {
|
|
|
620
591
|
*/
|
|
621
592
|
declare function getAgentSchemas(machine: AnyStateMachine): AgentSchemas | undefined;
|
|
622
593
|
//#endregion
|
|
623
|
-
//#region src/agent-run.d.ts
|
|
624
|
-
type AgentStreamEvent<TMachine extends AnyStateMachine = AnyStateMachine> = {
|
|
625
|
-
kind: "request";
|
|
626
|
-
phase: "start" | "end";
|
|
627
|
-
name: string;
|
|
628
|
-
id: string;
|
|
629
|
-
request: AgentStepRequest;
|
|
630
|
-
output?: unknown;
|
|
631
|
-
raw?: unknown;
|
|
632
|
-
} | {
|
|
633
|
-
kind: "request";
|
|
634
|
-
phase: "error";
|
|
635
|
-
name: string;
|
|
636
|
-
id: string;
|
|
637
|
-
request: AgentStepRequest;
|
|
638
|
-
error: unknown;
|
|
639
|
-
} | {
|
|
640
|
-
kind: "chunk";
|
|
641
|
-
name: string;
|
|
642
|
-
id: string;
|
|
643
|
-
delta: string;
|
|
644
|
-
} | {
|
|
645
|
-
kind: "transition";
|
|
646
|
-
value: StateValue;
|
|
647
|
-
event: EventFromLogic<TMachine>;
|
|
648
|
-
} | {
|
|
649
|
-
kind: "emit";
|
|
650
|
-
event: EmittedFrom<TMachine>;
|
|
651
|
-
} | {
|
|
652
|
-
kind: "done";
|
|
653
|
-
result: Extract<RunAgentResult<TMachine>, {
|
|
654
|
-
status: "done";
|
|
655
|
-
}>;
|
|
656
|
-
} | {
|
|
657
|
-
kind: "idle";
|
|
658
|
-
result: Extract<RunAgentResult<TMachine>, {
|
|
659
|
-
status: "idle";
|
|
660
|
-
}>;
|
|
661
|
-
} | {
|
|
662
|
-
kind: "error";
|
|
663
|
-
result: Extract<RunAgentResult<TMachine>, {
|
|
664
|
-
status: "error";
|
|
665
|
-
}>;
|
|
666
|
-
};
|
|
667
|
-
/**
|
|
668
|
-
* Streams one {@link runAgent} call as agent-level events. The machine remains
|
|
669
|
-
* the single artifact; this function only projects its requests, chunks,
|
|
670
|
-
* transitions, emitted events, and terminal result into an async iterable.
|
|
671
|
-
*/
|
|
672
|
-
declare function runAgentStream<TMachine extends AnyStateMachine>(machine: TMachine, options: RunAgentOptions<TMachine>): AsyncGenerator<AgentStreamEvent<TMachine>, void>;
|
|
673
|
-
//#endregion
|
|
674
594
|
//#region src/provide-executors.d.ts
|
|
675
595
|
/** Options for {@link provideExecutors}. */
|
|
676
596
|
interface ProvideExecutorsOptions<TMachine extends AnyStateMachine = AnyStateMachine> {
|
|
@@ -687,12 +607,12 @@ interface ProvideExecutorsOptions<TMachine extends AnyStateMachine = AnyStateMac
|
|
|
687
607
|
/**
|
|
688
608
|
* A single ordered stream of request-level trace events
|
|
689
609
|
* (`request.start`/`request.end`/`request.error`/`stream.chunk`) with the
|
|
690
|
-
* SAME versioned envelope {@link
|
|
610
|
+
* SAME versioned envelope {@link createAgentRuntime} emits. Because one bound machine can
|
|
691
611
|
* back many concurrent root actors, envelope state (`runId`, monotonic `seq`)
|
|
692
612
|
* is minted per ROOT actor at runtime — two concurrent actors get distinct
|
|
693
613
|
* `runId`s and independent `seq`. Pair with {@link traceTransitions} on the
|
|
694
614
|
* actor's `inspect` to fold `machine.transition` events into the same stream.
|
|
695
|
-
* Unlike `
|
|
615
|
+
* Unlike `createAgentRuntime` there are NO `run.start`/`run.end` events (no run
|
|
696
616
|
* boundary).
|
|
697
617
|
*/
|
|
698
618
|
onTrace?: (event: AgentTraceEvent<TMachine>) => void;
|
|
@@ -700,8 +620,8 @@ interface ProvideExecutorsOptions<TMachine extends AnyStateMachine = AnyStateMac
|
|
|
700
620
|
/**
|
|
701
621
|
* Binds a machine's agent actor sources to a set of host `executors` in one
|
|
702
622
|
* call, returning a `machine.provide(...)`-ed copy ready for a plain
|
|
703
|
-
* `createActor(...)` — the uncontrolled-mode counterpart to {@link
|
|
704
|
-
* No run loop, no
|
|
623
|
+
* `createActor(...)` — the uncontrolled-mode counterpart to {@link createAgentRuntime}.
|
|
624
|
+
* No run loop, no settling: the returned machine drives itself, so
|
|
705
625
|
*
|
|
706
626
|
* ```ts
|
|
707
627
|
* const actor = createActor(provideExecutors(machine, { generateText, decide }), { input });
|
|
@@ -716,10 +636,10 @@ interface ProvideExecutorsOptions<TMachine extends AnyStateMachine = AnyStateMac
|
|
|
716
636
|
* - `mode: 'stream'` text source → `executors.streamText`
|
|
717
637
|
* - decision / `agent.decide` source → `executors.decide` (snapshot-driven
|
|
718
638
|
* candidate events, guard `canTake`, and auto-delivery of the chosen event,
|
|
719
|
-
* mirroring `
|
|
639
|
+
* mirroring `createAgentRuntime` but without its model-call counting)
|
|
720
640
|
*
|
|
721
641
|
* Pass `options.onTrace` to observe request-level trace events (identical in
|
|
722
|
-
* shape to `
|
|
642
|
+
* shape to `createAgentRuntime`'s); pair it with {@link traceTransitions} on the actor's
|
|
723
643
|
* `inspect` to also capture `machine.transition` events in the same stream.
|
|
724
644
|
*
|
|
725
645
|
* A source that already carries its own executor (`.withExecutor(...)`) is left
|
|
@@ -730,7 +650,7 @@ interface ProvideExecutorsOptions<TMachine extends AnyStateMachine = AnyStateMac
|
|
|
730
650
|
* Throws at bind time if a source needs an executor kind that `executors` does
|
|
731
651
|
* not provide.
|
|
732
652
|
*
|
|
733
|
-
* Executor inheritance is RECURSIVE, exactly as in `
|
|
653
|
+
* Executor inheritance is RECURSIVE, exactly as in `createAgentRuntime`: a string-keyed
|
|
734
654
|
* invoked child machine is rebound too, so its own text/decision requests — at
|
|
735
655
|
* any depth — reach the same host executors. A direct-object invoke `src`
|
|
736
656
|
* cannot be swapped via `.provide`, so nothing under one inherits; bind those
|
|
@@ -739,4 +659,4 @@ interface ProvideExecutorsOptions<TMachine extends AnyStateMachine = AnyStateMac
|
|
|
739
659
|
*/
|
|
740
660
|
declare function provideExecutors<TMachine extends AnyStateMachine>(machine: TMachine, executors: AgentRequestExecutors, options?: ProvideExecutorsOptions<TMachine>): TMachine;
|
|
741
661
|
//#endregion
|
|
742
|
-
export { AGENT_TRACE_SCHEMA_VERSION, AGENT_USAGE_EVENT_TYPE, type AgentCallUsage, type AgentDecisionExecutor, AgentDecisionExhaustedError, type AgentDecisionInput, type AgentDecisionRequest, type AgentDefaultMeta, AgentError, type AgentEventDescriptor, AgentEventLogConflictError, type AgentEventLogStore, type AgentExecutorDecisionRequest, type AgentExecutorTextRequest, type AgentFinishReason, type AgentInputFrom, type AgentInteraction, type AgentInteractionDescriptor, type AgentInteractionEvent, type AgentInteractionEventMeta, type AgentInteractionMeta, AgentInvalidEventPayloadError, type AgentLogEntry, AgentMachineVersionMismatchError, AgentMaxModelCallsExceededError, type AgentMessage, type AgentModelRef, type AgentOutputMode, type AgentRequest, type AgentRequestExecutor, type AgentRequestExecutorInfo, type AgentRequestExecutorResult, type AgentRequestExecutors, type AgentRequestOptions, type AgentRequestSource, type AgentRunMeta, type AgentSchemaPack, type AgentSchemas, AgentSnapshotDivergedError, type
|
|
662
|
+
export { AGENT_TRACE_SCHEMA_VERSION, AGENT_USAGE_EVENT_TYPE, type AgentCallUsage, type AgentDecisionExecutor, AgentDecisionExhaustedError, type AgentDecisionInput, type AgentDecisionRequest, type AgentDefaultMeta, type AgentEffects, AgentError, type AgentEventDescriptor, AgentEventLogConflictError, type AgentEventLogStore, type AgentExecutorDecisionRequest, type AgentExecutorTextRequest, type AgentFinishReason, type AgentInputFrom, type AgentInteraction, type AgentInteractionDescriptor, type AgentInteractionEvent, type AgentInteractionEventMeta, type AgentInteractionMeta, AgentInvalidEventPayloadError, type AgentLogEntry, AgentMachineVersionMismatchError, AgentMaxModelCallsExceededError, type AgentMessage, type AgentModelRef, type AgentOutputMode, type AgentRequest, type AgentRequestExecutor, type AgentRequestExecutorInfo, type AgentRequestExecutorResult, type AgentRequestExecutors, type AgentRequestOptions, type AgentRequestSource, type AgentRunErrorCause, type AgentRunInit, type AgentRunMeta, type AgentRunResult, type AgentRunStart, type AgentRuntime, type AgentRuntimeOptions, type AgentSchemaPack, type AgentSchemas, AgentSnapshotDivergedError, type AgentStepRequest, type AgentTextRequest, type AgentTextResult, type AgentTimerEvent, type AgentTimerScheduler, type AgentTool, type AgentToolChoice, type AgentToolDescriptor, type AgentToolExecute, type AgentTools, type AgentTraceEvent, type AgentTransitionHandler, AgentTruncatedError, type AgentUsage, type AgentUsageEvent, type AgentUsageEventPayload, type AgentWorkflowActionConfig, type AgentWorkflowActorConfig, type AgentWorkflowConfig, type AgentWorkflowInvokeConfig, type AgentWorkflowRequestConfig, type AgentWorkflowStateConfig, type AgentWorkflowTransitionConfig, type AllowedEvents, type AssistantMessage, type ChosenEvent, type ContextOf, type CreateDecisionRequestOptions, type DecisionAttempt, type DecisionLogic, type DecisionLogicConfig, type DoneActorEventOf, type EventOf, type FilePart, type FromConfigOptions, type FromConfigResult, type GetInteractionOptions, type ImagePart, type InferInput, type InferOutput, type InputOf, type InspectedActorRef, type JsonSerializableTraceEvent, type MetaOf, type OutputOf, type ProvideExecutorsOptions, type ProviderStructuredOutput, type RequestNamesOf, type ResolveDecisionOptions, type SchemaCompiler, type SnapshotOf, type StandardSchemaV1, type StateValueOf, type SystemMessage, type TextLogic, type TextLogicConfig, type TextLogicExecuteArgs, type TextLogicExecutor, type TextPart, type ToolCallPart, type ToolMessage, type ToolResultPart, type UserMessage, type WithAgentEvents, type WithAgentUsageEvent, assistantMessage, bindRequestExecutor, createAgentRuntime, createAgentSchemas, createDecisionLogic, createDecisionRequest, createTextLogic, eventFromInteraction, getAcceptedEvents, getAgentOutputMode, getAgentSchemas, getCallFinishReason, getCallUsage, getInteraction, getJsonSchema, getJsonSchemaSync, getMachineStructuralHash, getMessageText, getStateMeta, getStatePath, inspectTransitions, interactionMetaSchema, isAgentIdle, isAgentMessages, isStandardSchema, messagesSchema, parseAgentEvent, parseOutput, parseProviderOutput, provideExecutors, providerOutputSchema, renderDecisionAttempts, resolveDecision, runToQuiescence, serializeTraceEvent, setupAgent, systemMessage, toolMessage, traceTransitions, userMessage };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { C as UserMessage, S as ToolResultPart, _ as StandardSchemaV1, a as AgentToolDescriptor, b as ToolCallPart, c as AllowedEvents, d as EventUnion, f as FilePart, g as NormalizedEventSchemas, h as InferOutput, i as AgentToolChoice, l as AssistantMessage, m as InferInput, n as AgentMessage, o as AgentToolExecute, p as ImagePart, r as AgentTool, s as AgentTools, t as AgentEventSchemaInputMap, u as ChosenEvent, v as SystemMessage, w as WithAgentInputSchema, x as ToolMessage, y as TextPart } from "./types-
|
|
2
|
-
import { A as AgentDecisionExhaustedError, B as createDecisionRequest, C as getAgentOutputMode, D as parseProviderOutput, E as parseOutput, F as DecisionAttempt, G as AgentRequestOptions, H as resolveDecision, I as DecisionLogic, J as EventFromSnapshot, K as AgentRequestSource, L as DecisionLogicConfig, M as AgentDecisionRequest, N as AgentExecutorDecisionRequest, O as providerOutputSchema, P as CreateDecisionRequestOptions, Q as AgentTruncatedError, R as ResolveDecisionOptions, S as createTextLogic, T as getCallUsage, U as AgentEventDescriptor, V as renderDecisionAttempts, W as AgentInvalidEventPayloadError, X as parseAgentEvent, Y as getAcceptedEvents, Z as AgentError, _ as TextLogic, a as AgentModelRef, b as TextLogicExecutor, c as AgentRequestExecutorInfo, d as AgentRequestMode, f as AgentTextRequest, g as ProviderStructuredOutput, h as BuiltinAgentActors, i as AgentModelMap, j as AgentDecisionInput, k as AgentDecisionExecutor, l as AgentRequestExecutorResult, m as AgentUsage, n as AgentExecutorTextRequest, o as AgentOutputMode, p as AgentTextResult, q as AgentSchemas, r as AgentFinishReason, s as AgentRequestExecutor, t as AgentCallUsage, u as AgentRequestExecutors, v as TextLogicConfig, w as getCallFinishReason, x as bindRequestExecutor, y as TextLogicExecuteArgs, z as createDecisionLogic } from "./text-logic-
|
|
3
|
-
import { C as
|
|
4
|
-
import { c as AgentLogEntry, d as AgentMachineVersionMismatchError, n as AgentEventLogStore, t as AgentEventLogConflictError } from "./event-log-store-
|
|
5
|
-
import { a as getMachineStructuralHash, c as getStatePath, d as toolMessage, f as userMessage, i as getJsonSchemaSync, l as isStandardSchema, n as assistantMessage, o as getMessageText, r as getJsonSchema, s as getStateMeta, u as systemMessage } from "./utils-
|
|
6
|
-
import { AnyActorLogic, AnyMachineSnapshot, AnySetupConfig, AnyStateMachine, AsyncActorLogic, ContextFrom, DoneActorEvent,
|
|
1
|
+
import { C as UserMessage, S as ToolResultPart, _ as StandardSchemaV1, a as AgentToolDescriptor, b as ToolCallPart, c as AllowedEvents, d as EventUnion, f as FilePart, g as NormalizedEventSchemas, h as InferOutput, i as AgentToolChoice, l as AssistantMessage, m as InferInput, n as AgentMessage, o as AgentToolExecute, p as ImagePart, r as AgentTool, s as AgentTools, t as AgentEventSchemaInputMap, u as ChosenEvent, v as SystemMessage, w as WithAgentInputSchema, x as ToolMessage, y as TextPart } from "./types-BgNbNKnJ.mjs";
|
|
2
|
+
import { A as AgentDecisionExhaustedError, B as createDecisionRequest, C as getAgentOutputMode, D as parseProviderOutput, E as parseOutput, F as DecisionAttempt, G as AgentRequestOptions, H as resolveDecision, I as DecisionLogic, J as EventFromSnapshot, K as AgentRequestSource, L as DecisionLogicConfig, M as AgentDecisionRequest, N as AgentExecutorDecisionRequest, O as providerOutputSchema, P as CreateDecisionRequestOptions, Q as AgentTruncatedError, R as ResolveDecisionOptions, S as createTextLogic, T as getCallUsage, U as AgentEventDescriptor, V as renderDecisionAttempts, W as AgentInvalidEventPayloadError, X as parseAgentEvent, Y as getAcceptedEvents, Z as AgentError, _ as TextLogic, a as AgentModelRef, b as TextLogicExecutor, c as AgentRequestExecutorInfo, d as AgentRequestMode, f as AgentTextRequest, g as ProviderStructuredOutput, h as BuiltinAgentActors, i as AgentModelMap, j as AgentDecisionInput, k as AgentDecisionExecutor, l as AgentRequestExecutorResult, m as AgentUsage, n as AgentExecutorTextRequest, o as AgentOutputMode, p as AgentTextResult, q as AgentSchemas, r as AgentFinishReason, s as AgentRequestExecutor, t as AgentCallUsage, u as AgentRequestExecutors, v as TextLogicConfig, w as getCallFinishReason, x as bindRequestExecutor, y as TextLogicExecuteArgs, z as createDecisionLogic } from "./text-logic-D-czVPYp.mjs";
|
|
3
|
+
import { C as serializeTraceEvent, D as AGENT_USAGE_EVENT_TYPE, E as AgentStepRequest, O as AgentUsageEvent, S as runToQuiescence, T as AgentRequest, _ as InspectedActorRef, a as AgentRunErrorCause, b as inspectTransitions, c as AgentRunResult, d as AgentRuntimeOptions, f as AgentSnapshotDivergedError, g as AgentTransitionHandler, h as AgentTraceEvent, i as AgentMaxModelCallsExceededError, l as AgentRunStart, m as AgentTimerScheduler, n as AgentEffects, o as AgentRunInit, p as AgentTimerEvent, r as AgentInputFrom, s as AgentRunMeta, t as AGENT_TRACE_SCHEMA_VERSION, u as AgentRuntime, v as JsonSerializableTraceEvent, w as traceTransitions, x as isAgentIdle, y as createAgentRuntime } from "./run-agent-COXXc0RW.mjs";
|
|
4
|
+
import { c as AgentLogEntry, d as AgentMachineVersionMismatchError, n as AgentEventLogStore, t as AgentEventLogConflictError } from "./event-log-store-BIPOz-di.mjs";
|
|
5
|
+
import { a as getMachineStructuralHash, c as getStatePath, d as toolMessage, f as userMessage, i as getJsonSchemaSync, l as isStandardSchema, n as assistantMessage, o as getMessageText, r as getJsonSchema, s as getStateMeta, u as systemMessage } from "./utils-_q7F-AZu.mjs";
|
|
6
|
+
import { AnyActorLogic, AnyMachineSnapshot, AnySetupConfig, AnyStateMachine, AsyncActorLogic, ContextFrom, DoneActorEvent, EventFromLogic, EventObject, InputFrom, MachineContext, MetaObject, NonReducibleUnknown, OutputFrom, SetupReturnFromConfig, SetupStateSchema, SnapshotFrom, StateValueFrom } from "xstate";
|
|
7
7
|
|
|
8
8
|
//#region src/type-helpers.d.ts
|
|
9
9
|
type SchemaAt<T, TKey extends PropertyKey> = T extends {
|
|
@@ -199,17 +199,6 @@ interface AgentWorkflowConfig {
|
|
|
199
199
|
actors?: Record<string, AgentWorkflowActorConfig>;
|
|
200
200
|
initial: string;
|
|
201
201
|
states: Record<string, AgentWorkflowStateConfig>;
|
|
202
|
-
/**
|
|
203
|
-
* State tags that mark an INTENTIONAL wait for an external event (a human
|
|
204
|
-
* approval, an inbound webhook, …) — the declarative form of `setupAgent({
|
|
205
|
-
* isIdle })`, since a config cannot carry a function. Lowered to a
|
|
206
|
-
* `snapshot.hasTag(...)`-any-of predicate so `runAgent` settles those
|
|
207
|
-
* snapshots idle deterministically instead of using its timing heuristic.
|
|
208
|
-
* Every listed tag must appear in some state's `tags` — an unused tag is a
|
|
209
|
-
* build-time error. A `fromConfig(config, { isIdle })` option takes
|
|
210
|
-
* precedence over declarative `idleTags`.
|
|
211
|
-
*/
|
|
212
|
-
idleTags?: string[];
|
|
213
202
|
meta?: Record<string, unknown>;
|
|
214
203
|
}
|
|
215
204
|
/** A `requests` entry in {@link AgentWorkflowConfig} — the JSON equivalent of a `setupAgent({ requests })` `TextLogicConfig`. Fields beyond `input`/`output`/`tools`/`mode`/`description` are `unknown` because they accept template-expression strings (see {@link AgentWorkflowConfig}). */
|
|
@@ -313,7 +302,7 @@ interface AgentWorkflowActionConfig {
|
|
|
313
302
|
*/
|
|
314
303
|
interface FromConfigResult {
|
|
315
304
|
machine: AnyStateMachine;
|
|
316
|
-
/** Compiled `context`/`events`/`input`/`output`/`meta`/`emitted` schemas — the same pack `
|
|
305
|
+
/** Compiled `context`/`events`/`input`/`output`/`meta`/`emitted` schemas — the same pack `createAgentRuntime` executes this machine with. */
|
|
317
306
|
schemas: AgentSchemaPack<StandardSchemaV1<Record<string, unknown>>, Record<string, StandardSchemaV1>, StandardSchemaV1, StandardSchemaV1, StandardSchemaV1<MetaObject>>;
|
|
318
307
|
}
|
|
319
308
|
/** Options for `setupAgent.fromConfig(...)`. */
|
|
@@ -342,15 +331,6 @@ interface FromConfigOptions {
|
|
|
342
331
|
* implementation here is a build-time error.
|
|
343
332
|
*/
|
|
344
333
|
actions?: Record<string, (params: any) => unknown>;
|
|
345
|
-
/**
|
|
346
|
-
* Detects a snapshot that is an INTENTIONAL wait for an external event —
|
|
347
|
-
* the same machine-carried predicate `setupAgent({ isIdle })` declares
|
|
348
|
-
* for TS-authored machines, registered here because a function cannot live
|
|
349
|
-
* in the workflow config itself. Takes precedence over the config's
|
|
350
|
-
* declarative {@link AgentWorkflowConfig.idleTags}. Travels with the machine
|
|
351
|
-
* through `machine.provide(...)`.
|
|
352
|
-
*/
|
|
353
|
-
isIdle?: (snapshot: AnyMachineSnapshot) => boolean;
|
|
354
334
|
}
|
|
355
335
|
//#endregion
|
|
356
336
|
//#region src/setup-agent.d.ts
|
|
@@ -386,8 +366,7 @@ type AgentDefaultMeta<TEventSchemas extends AgentEventSchemaInputMap> = AgentInt
|
|
|
386
366
|
* A machine's full schema set — context, event payloads, machine input/
|
|
387
367
|
* output, and state/transition meta — as returned by {@link createAgentSchemas}
|
|
388
368
|
* and retained on `setupAgent(...)`'s `result.schemas` for runtime
|
|
389
|
-
* validation (e.g. by
|
|
390
|
-
* by `getAcceptedEvents` to attach event payload schemas). Unlike
|
|
369
|
+
* validation (e.g. by `getAcceptedEvents` to attach event payload schemas). Unlike
|
|
391
370
|
* `AgentSchemaConfig` (the input to `createAgentSchemas`), every field here
|
|
392
371
|
* is required — `events`/`input`/`output`/`meta` default to empty/unknown
|
|
393
372
|
* schemas when not supplied.
|
|
@@ -398,7 +377,7 @@ interface AgentSchemaPack<TContextSchema extends StandardSchemaV1<Record<string,
|
|
|
398
377
|
input: TInputSchema;
|
|
399
378
|
output: TOutputSchema;
|
|
400
379
|
meta: TMetaSchema;
|
|
401
|
-
/** Schemas for events the machine emits (`enq.emit(...)`), keyed by event type — they type `enq.emit` in the machine and the `on` handlers of {@link
|
|
380
|
+
/** Schemas for events the machine emits (`enq.emit(...)`), keyed by event type — they type `enq.emit` in the machine and the `on` handlers of {@link createAgentRuntime}. Optional: omitted means emitted events stay untyped. */
|
|
402
381
|
emitted?: TEmittedSchemas;
|
|
403
382
|
}
|
|
404
383
|
type AgentSchemaConfig<TContextSchema extends StandardSchemaV1<Record<string, unknown>>, TEventSchemas extends AgentEventSchemaInputMap, TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TEmittedSchemas extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>> = {
|
|
@@ -464,7 +443,7 @@ type AgentSetupEmittedSchema<TEmittedSchemas extends Record<string, StandardSche
|
|
|
464
443
|
* XState resolves `schemas.input` to a single type used both by
|
|
465
444
|
* `createActor`'s `input` option and by the `context: ({ input })` factory —
|
|
466
445
|
* and it never validates, so a schema default reads as a required field at the
|
|
467
|
-
* call site while being absent at runtime.
|
|
446
|
+
* call site while being absent at runtime. The runtime validates the input
|
|
468
447
|
* (filling defaults) and reads this brand back through `AgentInputFrom` to
|
|
469
448
|
* accept the schema's looser *input* side, while the factory keeps seeing the
|
|
470
449
|
* validated *output* side.
|
|
@@ -504,17 +483,6 @@ type SetupAgentBaseConfig<TContextSchema extends StandardSchemaV1<Record<string,
|
|
|
504
483
|
actions?: NonNullable<AnySetupConfig["actions"]>;
|
|
505
484
|
guards?: AgentGuardSources<TContextSchema, TEventSchemas>;
|
|
506
485
|
delays?: AgentDelaySources<TContextSchema, TEventSchemas>;
|
|
507
|
-
/**
|
|
508
|
-
* Detects a snapshot that is an INTENTIONAL wait for an external event (a
|
|
509
|
-
* human approval, an inbound webhook, …) — the machine's own declaration of
|
|
510
|
-
* what "idle" means for it, so `runAgent` settles those snapshots idle
|
|
511
|
-
* deterministically instead of using its timing heuristic. Travels with the
|
|
512
|
-
* machine through `machine.provide(...)`. Without one, `runAgent` recognizes
|
|
513
|
-
* resting event-handling states and `meta.interaction` by structure. Use a
|
|
514
|
-
* predicate only for a more specialized machine-owned wait rule. Import and
|
|
515
|
-
* call `isAgentIdle(snapshot)` inside it when expanding the default rule.
|
|
516
|
-
*/
|
|
517
|
-
isIdle?: (snapshot: AnyMachineSnapshot) => boolean;
|
|
518
486
|
};
|
|
519
487
|
type SetupAgentXStateResult<TContextSchema extends StandardSchemaV1<Record<string, unknown>>, TEventSchemas extends AgentEventSchemaInputMap, TActors extends { [K in keyof TActors]: AnyActorLogic }, TRequestSchemas extends AgentRequestSchemaMap, TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TModels extends AgentModelMap, TEmittedSchemas extends Record<string, StandardSchemaV1> = {}, TStateSchemas extends Record<string, SetupStateSchema> = Record<string, SetupStateSchema>> = SetupReturnFromConfig<AgentSetupXStateConfig<TContextSchema, TEventSchemas, TActors, TRequestSchemas, TInputSchema, TOutputSchema, TMetaSchema, TModels, TEmittedSchemas, TStateSchemas>>;
|
|
520
488
|
/**
|
|
@@ -522,13 +490,13 @@ type SetupAgentXStateResult<TContextSchema extends StandardSchemaV1<Record<strin
|
|
|
522
490
|
* (`createMachine`, `assign`, …) extended with `schemas` (the resolved
|
|
523
491
|
* {@link AgentSchemaPack}), `models`, and `requests` (the built request
|
|
524
492
|
* actors). Machines created here are registered so
|
|
525
|
-
* `
|
|
493
|
+
* `createAgentRuntime` can resolve their schemas/actors
|
|
526
494
|
* without re-passing them each call.
|
|
527
495
|
*/
|
|
528
496
|
type SetupAgentResult<TContextSchema extends StandardSchemaV1<Record<string, unknown>>, TEventSchemas extends AgentEventSchemaInputMap, TActors extends { [K in keyof TActors]: AnyActorLogic }, TRequestSchemas extends AgentRequestSchemaMap, TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TModels extends AgentModelMap, TEmittedSchemas extends Record<string, StandardSchemaV1> = {}, TStateSchemas extends Record<string, SetupStateSchema> = Record<string, SetupStateSchema>> = Omit<SetupAgentXStateResult<TContextSchema, TEventSchemas, TActors, TRequestSchemas, TInputSchema, TOutputSchema, TMetaSchema, TModels, TEmittedSchemas, TStateSchemas>, "createMachine"> & {
|
|
529
497
|
/**
|
|
530
498
|
* Creates the agent machine — XState's own `createMachine`, plus: the
|
|
531
|
-
* machine is registered so
|
|
499
|
+
* machine is registered so {@link createAgentRuntime} can resolve
|
|
532
500
|
* its schemas/actors without re-passing them, and a single final state's
|
|
533
501
|
* `output` is copied to the machine root when the root declares none.
|
|
534
502
|
*/
|
|
@@ -540,7 +508,7 @@ type SetupAgentResult<TContextSchema extends StandardSchemaV1<Record<string, unk
|
|
|
540
508
|
/**
|
|
541
509
|
* Schema-first `setup(...)` for agent machines — the standard entry point
|
|
542
510
|
* for authoring a machine (the blueprint) that this library then runs (via
|
|
543
|
-
* {@link
|
|
511
|
+
* {@link createAgentRuntime}) against host-supplied model/decision
|
|
544
512
|
* executors. Context, events, machine input, machine output, and
|
|
545
513
|
* state/transition meta are all standard schemas — no `{} as Type` casts —
|
|
546
514
|
* and are retained on `result.schemas` for runtime validation. Also
|
|
@@ -602,7 +570,10 @@ declare namespace setupAgent {
|
|
|
602
570
|
* const { machine, schemas } = setupAgent.fromConfig(workflowConfig, {
|
|
603
571
|
* compileSchema,
|
|
604
572
|
* });
|
|
605
|
-
* const result = await
|
|
573
|
+
* const result = await runToQuiescence(
|
|
574
|
+
* createAgentRuntime(machine, { executors: { generateText, decide } }),
|
|
575
|
+
* { input: { ticket } },
|
|
576
|
+
* );
|
|
606
577
|
* const event = parseAgentEvent(result.snapshot, raw, { events: schemas.events });
|
|
607
578
|
* ```
|
|
608
579
|
*/
|
|
@@ -620,57 +591,6 @@ declare namespace setupAgent {
|
|
|
620
591
|
*/
|
|
621
592
|
declare function getAgentSchemas(machine: AnyStateMachine): AgentSchemas | undefined;
|
|
622
593
|
//#endregion
|
|
623
|
-
//#region src/agent-run.d.ts
|
|
624
|
-
type AgentStreamEvent<TMachine extends AnyStateMachine = AnyStateMachine> = {
|
|
625
|
-
kind: "request";
|
|
626
|
-
phase: "start" | "end";
|
|
627
|
-
name: string;
|
|
628
|
-
id: string;
|
|
629
|
-
request: AgentStepRequest;
|
|
630
|
-
output?: unknown;
|
|
631
|
-
raw?: unknown;
|
|
632
|
-
} | {
|
|
633
|
-
kind: "request";
|
|
634
|
-
phase: "error";
|
|
635
|
-
name: string;
|
|
636
|
-
id: string;
|
|
637
|
-
request: AgentStepRequest;
|
|
638
|
-
error: unknown;
|
|
639
|
-
} | {
|
|
640
|
-
kind: "chunk";
|
|
641
|
-
name: string;
|
|
642
|
-
id: string;
|
|
643
|
-
delta: string;
|
|
644
|
-
} | {
|
|
645
|
-
kind: "transition";
|
|
646
|
-
value: StateValue;
|
|
647
|
-
event: EventFromLogic<TMachine>;
|
|
648
|
-
} | {
|
|
649
|
-
kind: "emit";
|
|
650
|
-
event: EmittedFrom<TMachine>;
|
|
651
|
-
} | {
|
|
652
|
-
kind: "done";
|
|
653
|
-
result: Extract<RunAgentResult<TMachine>, {
|
|
654
|
-
status: "done";
|
|
655
|
-
}>;
|
|
656
|
-
} | {
|
|
657
|
-
kind: "idle";
|
|
658
|
-
result: Extract<RunAgentResult<TMachine>, {
|
|
659
|
-
status: "idle";
|
|
660
|
-
}>;
|
|
661
|
-
} | {
|
|
662
|
-
kind: "error";
|
|
663
|
-
result: Extract<RunAgentResult<TMachine>, {
|
|
664
|
-
status: "error";
|
|
665
|
-
}>;
|
|
666
|
-
};
|
|
667
|
-
/**
|
|
668
|
-
* Streams one {@link runAgent} call as agent-level events. The machine remains
|
|
669
|
-
* the single artifact; this function only projects its requests, chunks,
|
|
670
|
-
* transitions, emitted events, and terminal result into an async iterable.
|
|
671
|
-
*/
|
|
672
|
-
declare function runAgentStream<TMachine extends AnyStateMachine>(machine: TMachine, options: RunAgentOptions<TMachine>): AsyncGenerator<AgentStreamEvent<TMachine>, void>;
|
|
673
|
-
//#endregion
|
|
674
594
|
//#region src/provide-executors.d.ts
|
|
675
595
|
/** Options for {@link provideExecutors}. */
|
|
676
596
|
interface ProvideExecutorsOptions<TMachine extends AnyStateMachine = AnyStateMachine> {
|
|
@@ -687,12 +607,12 @@ interface ProvideExecutorsOptions<TMachine extends AnyStateMachine = AnyStateMac
|
|
|
687
607
|
/**
|
|
688
608
|
* A single ordered stream of request-level trace events
|
|
689
609
|
* (`request.start`/`request.end`/`request.error`/`stream.chunk`) with the
|
|
690
|
-
* SAME versioned envelope {@link
|
|
610
|
+
* SAME versioned envelope {@link createAgentRuntime} emits. Because one bound machine can
|
|
691
611
|
* back many concurrent root actors, envelope state (`runId`, monotonic `seq`)
|
|
692
612
|
* is minted per ROOT actor at runtime — two concurrent actors get distinct
|
|
693
613
|
* `runId`s and independent `seq`. Pair with {@link traceTransitions} on the
|
|
694
614
|
* actor's `inspect` to fold `machine.transition` events into the same stream.
|
|
695
|
-
* Unlike `
|
|
615
|
+
* Unlike `createAgentRuntime` there are NO `run.start`/`run.end` events (no run
|
|
696
616
|
* boundary).
|
|
697
617
|
*/
|
|
698
618
|
onTrace?: (event: AgentTraceEvent<TMachine>) => void;
|
|
@@ -700,8 +620,8 @@ interface ProvideExecutorsOptions<TMachine extends AnyStateMachine = AnyStateMac
|
|
|
700
620
|
/**
|
|
701
621
|
* Binds a machine's agent actor sources to a set of host `executors` in one
|
|
702
622
|
* call, returning a `machine.provide(...)`-ed copy ready for a plain
|
|
703
|
-
* `createActor(...)` — the uncontrolled-mode counterpart to {@link
|
|
704
|
-
* No run loop, no
|
|
623
|
+
* `createActor(...)` — the uncontrolled-mode counterpart to {@link createAgentRuntime}.
|
|
624
|
+
* No run loop, no settling: the returned machine drives itself, so
|
|
705
625
|
*
|
|
706
626
|
* ```ts
|
|
707
627
|
* const actor = createActor(provideExecutors(machine, { generateText, decide }), { input });
|
|
@@ -716,10 +636,10 @@ interface ProvideExecutorsOptions<TMachine extends AnyStateMachine = AnyStateMac
|
|
|
716
636
|
* - `mode: 'stream'` text source → `executors.streamText`
|
|
717
637
|
* - decision / `agent.decide` source → `executors.decide` (snapshot-driven
|
|
718
638
|
* candidate events, guard `canTake`, and auto-delivery of the chosen event,
|
|
719
|
-
* mirroring `
|
|
639
|
+
* mirroring `createAgentRuntime` but without its model-call counting)
|
|
720
640
|
*
|
|
721
641
|
* Pass `options.onTrace` to observe request-level trace events (identical in
|
|
722
|
-
* shape to `
|
|
642
|
+
* shape to `createAgentRuntime`'s); pair it with {@link traceTransitions} on the actor's
|
|
723
643
|
* `inspect` to also capture `machine.transition` events in the same stream.
|
|
724
644
|
*
|
|
725
645
|
* A source that already carries its own executor (`.withExecutor(...)`) is left
|
|
@@ -730,7 +650,7 @@ interface ProvideExecutorsOptions<TMachine extends AnyStateMachine = AnyStateMac
|
|
|
730
650
|
* Throws at bind time if a source needs an executor kind that `executors` does
|
|
731
651
|
* not provide.
|
|
732
652
|
*
|
|
733
|
-
* Executor inheritance is RECURSIVE, exactly as in `
|
|
653
|
+
* Executor inheritance is RECURSIVE, exactly as in `createAgentRuntime`: a string-keyed
|
|
734
654
|
* invoked child machine is rebound too, so its own text/decision requests — at
|
|
735
655
|
* any depth — reach the same host executors. A direct-object invoke `src`
|
|
736
656
|
* cannot be swapped via `.provide`, so nothing under one inherits; bind those
|
|
@@ -739,4 +659,4 @@ interface ProvideExecutorsOptions<TMachine extends AnyStateMachine = AnyStateMac
|
|
|
739
659
|
*/
|
|
740
660
|
declare function provideExecutors<TMachine extends AnyStateMachine>(machine: TMachine, executors: AgentRequestExecutors, options?: ProvideExecutorsOptions<TMachine>): TMachine;
|
|
741
661
|
//#endregion
|
|
742
|
-
export { AGENT_TRACE_SCHEMA_VERSION, AGENT_USAGE_EVENT_TYPE, type AgentCallUsage, type AgentDecisionExecutor, AgentDecisionExhaustedError, type AgentDecisionInput, type AgentDecisionRequest, type AgentDefaultMeta, AgentError, type AgentEventDescriptor, AgentEventLogConflictError, type AgentEventLogStore, type AgentExecutorDecisionRequest, type AgentExecutorTextRequest, type AgentFinishReason, type AgentInputFrom, type AgentInteraction, type AgentInteractionDescriptor, type AgentInteractionEvent, type AgentInteractionEventMeta, type AgentInteractionMeta, AgentInvalidEventPayloadError, type AgentLogEntry, AgentMachineVersionMismatchError, AgentMaxModelCallsExceededError, type AgentMessage, type AgentModelRef, type AgentOutputMode, type AgentRequest, type AgentRequestExecutor, type AgentRequestExecutorInfo, type AgentRequestExecutorResult, type AgentRequestExecutors, type AgentRequestOptions, type AgentRequestSource, type AgentRunMeta, type AgentSchemaPack, type AgentSchemas, AgentSnapshotDivergedError, type
|
|
662
|
+
export { AGENT_TRACE_SCHEMA_VERSION, AGENT_USAGE_EVENT_TYPE, type AgentCallUsage, type AgentDecisionExecutor, AgentDecisionExhaustedError, type AgentDecisionInput, type AgentDecisionRequest, type AgentDefaultMeta, type AgentEffects, AgentError, type AgentEventDescriptor, AgentEventLogConflictError, type AgentEventLogStore, type AgentExecutorDecisionRequest, type AgentExecutorTextRequest, type AgentFinishReason, type AgentInputFrom, type AgentInteraction, type AgentInteractionDescriptor, type AgentInteractionEvent, type AgentInteractionEventMeta, type AgentInteractionMeta, AgentInvalidEventPayloadError, type AgentLogEntry, AgentMachineVersionMismatchError, AgentMaxModelCallsExceededError, type AgentMessage, type AgentModelRef, type AgentOutputMode, type AgentRequest, type AgentRequestExecutor, type AgentRequestExecutorInfo, type AgentRequestExecutorResult, type AgentRequestExecutors, type AgentRequestOptions, type AgentRequestSource, type AgentRunErrorCause, type AgentRunInit, type AgentRunMeta, type AgentRunResult, type AgentRunStart, type AgentRuntime, type AgentRuntimeOptions, type AgentSchemaPack, type AgentSchemas, AgentSnapshotDivergedError, type AgentStepRequest, type AgentTextRequest, type AgentTextResult, type AgentTimerEvent, type AgentTimerScheduler, type AgentTool, type AgentToolChoice, type AgentToolDescriptor, type AgentToolExecute, type AgentTools, type AgentTraceEvent, type AgentTransitionHandler, AgentTruncatedError, type AgentUsage, type AgentUsageEvent, type AgentUsageEventPayload, type AgentWorkflowActionConfig, type AgentWorkflowActorConfig, type AgentWorkflowConfig, type AgentWorkflowInvokeConfig, type AgentWorkflowRequestConfig, type AgentWorkflowStateConfig, type AgentWorkflowTransitionConfig, type AllowedEvents, type AssistantMessage, type ChosenEvent, type ContextOf, type CreateDecisionRequestOptions, type DecisionAttempt, type DecisionLogic, type DecisionLogicConfig, type DoneActorEventOf, type EventOf, type FilePart, type FromConfigOptions, type FromConfigResult, type GetInteractionOptions, type ImagePart, type InferInput, type InferOutput, type InputOf, type InspectedActorRef, type JsonSerializableTraceEvent, type MetaOf, type OutputOf, type ProvideExecutorsOptions, type ProviderStructuredOutput, type RequestNamesOf, type ResolveDecisionOptions, type SchemaCompiler, type SnapshotOf, type StandardSchemaV1, type StateValueOf, type SystemMessage, type TextLogic, type TextLogicConfig, type TextLogicExecuteArgs, type TextLogicExecutor, type TextPart, type ToolCallPart, type ToolMessage, type ToolResultPart, type UserMessage, type WithAgentEvents, type WithAgentUsageEvent, assistantMessage, bindRequestExecutor, createAgentRuntime, createAgentSchemas, createDecisionLogic, createDecisionRequest, createTextLogic, eventFromInteraction, getAcceptedEvents, getAgentOutputMode, getAgentSchemas, getCallFinishReason, getCallUsage, getInteraction, getJsonSchema, getJsonSchemaSync, getMachineStructuralHash, getMessageText, getStateMeta, getStatePath, inspectTransitions, interactionMetaSchema, isAgentIdle, isAgentMessages, isStandardSchema, messagesSchema, parseAgentEvent, parseOutput, parseProviderOutput, provideExecutors, providerOutputSchema, renderDecisionAttempts, resolveDecision, runToQuiescence, serializeTraceEvent, setupAgent, systemMessage, toolMessage, traceTransitions, userMessage };
|