@statelyai/agent 2.0.0-alpha.13 → 2.0.0-alpha.14
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 +31 -155
- package/dist/index.d.cts +8 -12
- package/dist/index.d.mts +8 -12
- package/dist/index.mjs +33 -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-2MnlQTkB.d.mts} +60 -107
- package/dist/{run-agent-DnvtcnTZ.d.cts → run-agent-BlqKwHIF.d.cts} +60 -107
- 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-C5kbjaDz.d.mts} +5 -93
- package/dist/{text-logic-BDxwQNsD.d.cts → text-logic-Jkilp1Ie.d.cts} +5 -93
- package/dist/{types-QbEfCVny.d.cts → types-9Bqg5rZB.d.mts} +2 -2
- package/dist/{types-_FXoFBGO.d.mts → types-rMe7x6NR.d.cts} +2 -2
- 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
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { C as UserMessage, S as ToolResultPart, _ as StandardSchemaV1, a as AgentToolChoice, b as ToolCallPart, c as AgentTools, d as ChosenEvent, f as EventUnion, g as NormalizedEventSchemas, h as InferOutput, i as AgentTool, l as AllowedEvents, m as ImagePart, n as AgentMessage, o as AgentToolDescriptor, p as FilePart, r as AgentSnapshotStore, s as AgentToolExecute, t as AgentEventSchemaInputMap, u as AssistantMessage, v as SystemMessage, x as ToolMessage, y as TextPart } from "./types-
|
|
1
|
+
import { C as UserMessage, S as ToolResultPart, _ as StandardSchemaV1, a as AgentToolChoice, b as ToolCallPart, c as AgentTools, d as ChosenEvent, f as EventUnion, g as NormalizedEventSchemas, h as InferOutput, i as AgentTool, l as AllowedEvents, m as ImagePart, n as AgentMessage, o as AgentToolDescriptor, p as FilePart, r as AgentSnapshotStore, s as AgentToolExecute, t as AgentEventSchemaInputMap, u as AssistantMessage, v as SystemMessage, x as ToolMessage, y as TextPart } from "./types-rMe7x6NR.cjs";
|
|
2
2
|
import { t as AgentError } from "./errors-BQRk9eiZ.cjs";
|
|
3
|
-
import { A as AgentDecisionExhaustedError, B as
|
|
4
|
-
import {
|
|
5
|
-
import { a as
|
|
3
|
+
import { A as AgentDecisionExhaustedError, B as AgentRequestOptions, C as buildEnvelopeSchema, D as parseOutput, E as parseModelRef, F as ResolveDecisionOptions, H as getAcceptedEvents, I as renderDecisionAttempts, L as resolveDecision, M as AgentDecisionRequest, N as DecisionAttempt, O as parseStructuredEnvelope, P as DecisionLogicConfig, R as AgentEventDescriptor, S as bindRequestExecutor, T as getAgentOutputMode, U as parseAgentEvent, V as AgentRequestSource, _ as StructuredOutputEnvelope, a as AgentOutputMode, b as TextLogicExecuteArgs, c as AgentRequestExecutorResult, d as AgentTextRequest, f as AgentUsage, g as BuiltinAgentActors, h as AiSdkShapedTextResult, i as AgentModelRef, j as AgentDecisionInput, k as AgentDecisionExecutor, l as AgentRequestExecutors, m as AiSdkShapedStreamResult, n as AgentExecutorTextRequest, o as AgentRequestExecutor, p as AgentUserInput, r as AgentModelMap, s as AgentRequestExecutorInfo, t as AgentCallUsage, u as AgentRequestMode, v as TextLogic, w as createTextLogic, x as TextLogicExecutor, y as TextLogicConfig, z as AgentEventToolNameResolver } from "./text-logic-Jkilp1Ie.cjs";
|
|
4
|
+
import { a as AgentLogVerification, c as assertAgentLogEntry, d as createInMemoryEventLogStore, i as AgentLogEntry, l as assertEventLogStoreConformance, n as AgentEventLogConflictError, o as JsonValue, r as AgentEventLogStore, s as NonSerializableAgentEventError, t as AGENT_EVENT_SCHEMA_VERSION, u as assertJsonSerializable } from "./event-log-store-CVd2eyRy.cjs";
|
|
5
|
+
import { A as AgentEffectDiff, B as createReplayEntry, C as AgentStateRequest, D as AGENT_INIT_EVENT_TYPE, E as executeAgentRequest, F as AgentUsageEvent, G as replay, H as getAgentEffects, I as CreateReplayEntryOptions, K as verifyReplay, L as GetAgentEffectsOptions, M as AgentLogPatchOperation, N as AgentReplayDivergenceError, O as AGENT_USAGE_EVENT_TYPE, P as AgentReplayMachineMismatchError, R as ReplayOptions, S as traceTransitions, T as AgentStepRequest, U as getCallUsage, V as diffEventLogs, W as initEntry, _ as createAgentActor, a as AgentMessageInfo, b as runAgent, c as AgentTraceEvent, d as InspectedActorRef, f as JsonSerializableTraceEvent, g as RunAgentResult, h as RunAgentOptions, i as AgentIllegalResumeEventError, j as AgentEventLogDiff, k as AgentEffect, l as AgentUserInputExecutor, m as RunAgentErrorCause, n as AgentActorSession, o as AgentRunMeta, p as PendingUserInput, r as AgentIdleError, s as AgentSnapshotVersionMismatchError, t as AGENT_TRACE_SCHEMA_VERSION, u as GenerateResult, v as generateResult, w as AgentRequest, x as serializeTraceEvent, y as inspectTransitions, z as ReplayResult } from "./run-agent-BlqKwHIF.cjs";
|
|
6
6
|
import { AnyActorLogic, AnyMachineSnapshot, AnySetupConfig, AnyStateMachine, AsyncActorLogic, EventFromLogic, EventObject, InputFrom, MachineContext, MetaObject, NonReducibleUnknown, SetupReturnFromConfig, SetupStateSchema, SnapshotFrom, StateValue } from "xstate";
|
|
7
7
|
|
|
8
8
|
//#region src/messages.d.ts
|
|
@@ -420,7 +420,7 @@ type SetupAgentResult<TContextSchema extends StandardSchemaV1<Record<string, unk
|
|
|
420
420
|
* state/transition meta are all standard schemas — no `{} as Type` casts —
|
|
421
421
|
* and are retained on `result.schemas` for runtime validation. Also
|
|
422
422
|
* registers the `agent.generateText`/`agent.streamText`/`agent.userInput`/
|
|
423
|
-
* `agent.decide
|
|
423
|
+
* `agent.decide` builtin actors and lowers `requests`/`actors` into the
|
|
424
424
|
* machine's actor sources. The result is the xstate `setup(...)` object with
|
|
425
425
|
* a wrapped `result.createMachine(...)` plus `result.schemas`/`models`/
|
|
426
426
|
* `requests`/`appendMessages` attached. Also has a
|
|
@@ -593,7 +593,6 @@ interface ProvideExecutorsOptions<TMachine extends AnyStateMachine = AnyStateMac
|
|
|
593
593
|
* - decision / `agent.decide` source → `executors.decide` (snapshot-driven
|
|
594
594
|
* candidate events, guard `canTake`, and auto-delivery of the chosen event,
|
|
595
595
|
* mirroring `runAgent` but without its model-call counting)
|
|
596
|
-
* - `agent.plan` source → `executors.decide` (iterated, same semantics)
|
|
597
596
|
*
|
|
598
597
|
* Pass `options.onTrace` to observe request-level trace events (identical in
|
|
599
598
|
* shape to `runAgent`'s); pair it with {@link traceTransitions} on the actor's
|
|
@@ -782,10 +781,7 @@ interface AgentPathReport {
|
|
|
782
781
|
* depth, model-free, and reports which states are reached and how each path
|
|
783
782
|
* terminates. At each decision request it forks one branch per candidate event
|
|
784
783
|
* (guard-rejected candidates are counted in `prunedByGuard`, not explored); at
|
|
785
|
-
* an idle wait it forks per externally-accepted event.
|
|
786
|
-
* forks the same way — one branch per candidate, including the reserved
|
|
787
|
-
* `agent.plan.done` move — advancing each branch through the real plan protocol
|
|
788
|
-
* (`resolveAgentRequests`), so a plan can consume several depth units. Text/`userInput` invokes
|
|
784
|
+
* an idle wait it forks per externally-accepted event. Text/`userInput` invokes
|
|
789
785
|
* are resolved from `textOutputs` (a by-src canned-output map) — a missing src
|
|
790
786
|
* halts that branch with a `needs-output` terminal rather than throwing.
|
|
791
787
|
*
|
|
@@ -938,7 +934,7 @@ type ScriptedDecisionEntry = ScriptedDecisionValue | ((request: AgentDecisionReq
|
|
|
938
934
|
type ScriptedTextEntry = ((request: AgentTextRequest, info?: AgentRequestExecutorInfo) => unknown) | string | number | boolean | null | object;
|
|
939
935
|
/** The script {@link createScriptedExecutors} plays back. */
|
|
940
936
|
interface ScriptedExecutorsScript {
|
|
941
|
-
/** Answers for `decide`
|
|
937
|
+
/** Answers for `decide` requests, consumed in order. */
|
|
942
938
|
decisions?: ScriptedDecisionEntry[];
|
|
943
939
|
/** Answers for text requests, consumed in order. `generateText` and `streamText` share this one queue. */
|
|
944
940
|
text?: ScriptedTextEntry[];
|
|
@@ -1202,4 +1198,4 @@ declare function getJsonSchema(schema?: StandardSchemaV1): Promise<Record<string
|
|
|
1202
1198
|
*/
|
|
1203
1199
|
declare function getJsonSchemaSync(schema?: StandardSchemaV1): Record<string, unknown> | undefined;
|
|
1204
1200
|
//#endregion
|
|
1205
|
-
export { AGENT_EVENT_SCHEMA_VERSION, AGENT_INIT_EVENT_TYPE, AGENT_TRACE_SCHEMA_VERSION, AGENT_USAGE_EVENT_TYPE, type AgentActorSession, type AgentCallUsage, type AgentDecisionExecutor, AgentDecisionExhaustedError, type AgentDecisionInput, type AgentDecisionRequest, type AgentEffect, type AgentEffectDiff, AgentError, type AgentEventDescriptor, AgentEventLogConflictError, type AgentEventLogDiff, type AgentEventLogStore, type AgentEventToolNameResolver, type AgentExecutorTextRequest, AgentIdleError, AgentIllegalResumeEventError, type AgentLintDiagnostic, AgentLintError, type AgentLintSeverity, type AgentLogEntry, type AgentLogPatchOperation, type AgentLogVerification, type AgentMessage, type AgentMessageInfo, type AgentModelRef, type AgentOutputMode, type AgentPathReport, type AgentPathTerminal,
|
|
1201
|
+
export { AGENT_EVENT_SCHEMA_VERSION, AGENT_INIT_EVENT_TYPE, AGENT_TRACE_SCHEMA_VERSION, AGENT_USAGE_EVENT_TYPE, type AgentActorSession, type AgentCallUsage, type AgentDecisionExecutor, AgentDecisionExhaustedError, type AgentDecisionInput, type AgentDecisionRequest, type AgentEffect, type AgentEffectDiff, AgentError, type AgentEventDescriptor, AgentEventLogConflictError, type AgentEventLogDiff, type AgentEventLogStore, type AgentEventToolNameResolver, type AgentExecutorTextRequest, AgentIdleError, AgentIllegalResumeEventError, type AgentLintDiagnostic, AgentLintError, type AgentLintSeverity, type AgentLogEntry, type AgentLogPatchOperation, type AgentLogVerification, type AgentMessage, type AgentMessageInfo, type AgentModelRef, type AgentOutputMode, type AgentPathReport, type AgentPathTerminal, AgentReplayDivergenceError, AgentReplayMachineMismatchError, type AgentRequest, type AgentRequestExecutor, type AgentRequestExecutorInfo, type AgentRequestExecutorResult, type AgentRequestExecutors, type AgentRequestOptions, type AgentRequestSource, type AgentRun, type AgentRunMeta, type AgentSchemaPack, type AgentSnapshotStore, AgentSnapshotVersionMismatchError, type AgentStateRequest, type AgentStepRequest, type AgentTextRequest, type AgentTool, type AgentToolChoice, type AgentToolDescriptor, type AgentToolExecute, type AgentTools, type AgentTraceEvent, type AgentUsage, type AgentUsageEvent, type AgentUsageEventPayload, type AgentUserInput, type AgentUserInputExecutor, type AgentWorkflowActionConfig, type AgentWorkflowActorConfig, type AgentWorkflowConfig, type AgentWorkflowInvokeConfig, type AgentWorkflowRequestConfig, type AgentWorkflowStateConfig, type AgentWorkflowTransitionConfig, type AiSdkShapedStreamResult, type AiSdkShapedTextResult, type AllowedEvents, type AssertAgentMachineOptions, type AssistantMessage, type CanReachResult, type ChosenEvent, type CreateReplayEntryOptions, type DecisionAttempt, type DecisionLogicConfig, type ExplorePathsOptions, type FilePart, type FromConfigOptions, type FromConfigResult, type GenerateResult, type GetAgentEffectsOptions, type ImagePart, type InferOutput, type InspectedActorRef, type JsonSerializableTraceEvent, type JsonValue, type LintAgentMachineOptions, type MatchTrajectoryOptions, NonSerializableAgentEventError, type PendingUserInput, type ProvideExecutorsOptions, type ReplayOptions, type ReplayResult, type ResolveDecisionOptions, type RunAgentErrorCause, type RunAgentOptions, type RunAgentResult, type RunSeamOptions, type RunSeamResult, type SchemaCompiler, type ScriptedDecisionEntry, type ScriptedDecisionValue, type ScriptedExecutorsScript, type ScriptedTextEntry, type SeamRef, type SeamSlice, type SeamTurn, type SimulateAgentOptions, type SimulateAgentResult, type SimulationScript, type SimulationTrailEntry, type StandardSchemaV1, type StructuredOutputEnvelope, type SystemMessage, type TextLogic, type TextLogicConfig, type TextLogicExecuteArgs, type TextLogicExecutor, type TextPart, type ToolCallPart, type ToolMessage, type ToolResultPart, type TrajectoryEvent, type TrajectoryItem, type TrajectoryMatch, type TrajectoryMiss, type UserMessage, type WithAgentUsageEvent, appendMessages, assertAgentLogEntry, assertAgentMachine, assertEventLogStoreConformance, assertJsonSerializable, assistantMessage, bindRequestExecutor, buildEnvelopeSchema, canReach, createAgentActor, createAgentRun, createAgentSchemas, createInMemoryEventLogStore, createReplayEntry, createScriptedExecutors, createTextLogic, diffEventLogs, executeAgentRequest, explorePaths, generateResult, getAcceptedEvents, getAgentEffects, getAgentMessages, getAgentOutputMode, getCallUsage, getJsonSchema, getJsonSchemaSync, getMachineStructuralHash, getStateMeta, initEntry, inspectTransitions, isStandardSchema, lintAgentMachine, matchesTrajectory, messagesSchema, parseAgentEvent, parseModelRef, parseOutput, parseStructuredEnvelope, persistSnapshot, provideExecutors, renderDecisionAttempts, replay, resolveDecision, runAgent, runSeam, serializeTraceEvent, setupAgent, simulateAgent, systemMessage, toolMessage, traceTransitions, userMessage, verifyReplay };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { C as UserMessage, S as ToolResultPart, _ as StandardSchemaV1, a as AgentToolChoice, b as ToolCallPart, c as AgentTools, d as ChosenEvent, f as EventUnion, g as NormalizedEventSchemas, h as InferOutput, i as AgentTool, l as AllowedEvents, m as ImagePart, n as AgentMessage, o as AgentToolDescriptor, p as FilePart, r as AgentSnapshotStore, s as AgentToolExecute, t as AgentEventSchemaInputMap, u as AssistantMessage, v as SystemMessage, x as ToolMessage, y as TextPart } from "./types-
|
|
1
|
+
import { C as UserMessage, S as ToolResultPart, _ as StandardSchemaV1, a as AgentToolChoice, b as ToolCallPart, c as AgentTools, d as ChosenEvent, f as EventUnion, g as NormalizedEventSchemas, h as InferOutput, i as AgentTool, l as AllowedEvents, m as ImagePart, n as AgentMessage, o as AgentToolDescriptor, p as FilePart, r as AgentSnapshotStore, s as AgentToolExecute, t as AgentEventSchemaInputMap, u as AssistantMessage, v as SystemMessage, x as ToolMessage, y as TextPart } from "./types-9Bqg5rZB.mjs";
|
|
2
2
|
import { t as AgentError } from "./errors-C9rxnWbX.mjs";
|
|
3
|
-
import { A as AgentDecisionExhaustedError, B as
|
|
4
|
-
import {
|
|
5
|
-
import { a as
|
|
3
|
+
import { A as AgentDecisionExhaustedError, B as AgentRequestOptions, C as buildEnvelopeSchema, D as parseOutput, E as parseModelRef, F as ResolveDecisionOptions, H as getAcceptedEvents, I as renderDecisionAttempts, L as resolveDecision, M as AgentDecisionRequest, N as DecisionAttempt, O as parseStructuredEnvelope, P as DecisionLogicConfig, R as AgentEventDescriptor, S as bindRequestExecutor, T as getAgentOutputMode, U as parseAgentEvent, V as AgentRequestSource, _ as StructuredOutputEnvelope, a as AgentOutputMode, b as TextLogicExecuteArgs, c as AgentRequestExecutorResult, d as AgentTextRequest, f as AgentUsage, g as BuiltinAgentActors, h as AiSdkShapedTextResult, i as AgentModelRef, j as AgentDecisionInput, k as AgentDecisionExecutor, l as AgentRequestExecutors, m as AiSdkShapedStreamResult, n as AgentExecutorTextRequest, o as AgentRequestExecutor, p as AgentUserInput, r as AgentModelMap, s as AgentRequestExecutorInfo, t as AgentCallUsage, u as AgentRequestMode, v as TextLogic, w as createTextLogic, x as TextLogicExecutor, y as TextLogicConfig, z as AgentEventToolNameResolver } from "./text-logic-C5kbjaDz.mjs";
|
|
4
|
+
import { a as AgentLogVerification, c as assertAgentLogEntry, d as createInMemoryEventLogStore, i as AgentLogEntry, l as assertEventLogStoreConformance, n as AgentEventLogConflictError, o as JsonValue, r as AgentEventLogStore, s as NonSerializableAgentEventError, t as AGENT_EVENT_SCHEMA_VERSION, u as assertJsonSerializable } from "./event-log-store-BkUNtyOF.mjs";
|
|
5
|
+
import { A as AgentEffectDiff, B as createReplayEntry, C as AgentStateRequest, D as AGENT_INIT_EVENT_TYPE, E as executeAgentRequest, F as AgentUsageEvent, G as replay, H as getAgentEffects, I as CreateReplayEntryOptions, K as verifyReplay, L as GetAgentEffectsOptions, M as AgentLogPatchOperation, N as AgentReplayDivergenceError, O as AGENT_USAGE_EVENT_TYPE, P as AgentReplayMachineMismatchError, R as ReplayOptions, S as traceTransitions, T as AgentStepRequest, U as getCallUsage, V as diffEventLogs, W as initEntry, _ as createAgentActor, a as AgentMessageInfo, b as runAgent, c as AgentTraceEvent, d as InspectedActorRef, f as JsonSerializableTraceEvent, g as RunAgentResult, h as RunAgentOptions, i as AgentIllegalResumeEventError, j as AgentEventLogDiff, k as AgentEffect, l as AgentUserInputExecutor, m as RunAgentErrorCause, n as AgentActorSession, o as AgentRunMeta, p as PendingUserInput, r as AgentIdleError, s as AgentSnapshotVersionMismatchError, t as AGENT_TRACE_SCHEMA_VERSION, u as GenerateResult, v as generateResult, w as AgentRequest, x as serializeTraceEvent, y as inspectTransitions, z as ReplayResult } from "./run-agent-2MnlQTkB.mjs";
|
|
6
6
|
import { AnyActorLogic, AnyMachineSnapshot, AnySetupConfig, AnyStateMachine, AsyncActorLogic, EventFromLogic, EventObject, InputFrom, MachineContext, MetaObject, NonReducibleUnknown, SetupReturnFromConfig, SetupStateSchema, SnapshotFrom, StateValue } from "xstate";
|
|
7
7
|
|
|
8
8
|
//#region src/messages.d.ts
|
|
@@ -420,7 +420,7 @@ type SetupAgentResult<TContextSchema extends StandardSchemaV1<Record<string, unk
|
|
|
420
420
|
* state/transition meta are all standard schemas — no `{} as Type` casts —
|
|
421
421
|
* and are retained on `result.schemas` for runtime validation. Also
|
|
422
422
|
* registers the `agent.generateText`/`agent.streamText`/`agent.userInput`/
|
|
423
|
-
* `agent.decide
|
|
423
|
+
* `agent.decide` builtin actors and lowers `requests`/`actors` into the
|
|
424
424
|
* machine's actor sources. The result is the xstate `setup(...)` object with
|
|
425
425
|
* a wrapped `result.createMachine(...)` plus `result.schemas`/`models`/
|
|
426
426
|
* `requests`/`appendMessages` attached. Also has a
|
|
@@ -593,7 +593,6 @@ interface ProvideExecutorsOptions<TMachine extends AnyStateMachine = AnyStateMac
|
|
|
593
593
|
* - decision / `agent.decide` source → `executors.decide` (snapshot-driven
|
|
594
594
|
* candidate events, guard `canTake`, and auto-delivery of the chosen event,
|
|
595
595
|
* mirroring `runAgent` but without its model-call counting)
|
|
596
|
-
* - `agent.plan` source → `executors.decide` (iterated, same semantics)
|
|
597
596
|
*
|
|
598
597
|
* Pass `options.onTrace` to observe request-level trace events (identical in
|
|
599
598
|
* shape to `runAgent`'s); pair it with {@link traceTransitions} on the actor's
|
|
@@ -782,10 +781,7 @@ interface AgentPathReport {
|
|
|
782
781
|
* depth, model-free, and reports which states are reached and how each path
|
|
783
782
|
* terminates. At each decision request it forks one branch per candidate event
|
|
784
783
|
* (guard-rejected candidates are counted in `prunedByGuard`, not explored); at
|
|
785
|
-
* an idle wait it forks per externally-accepted event.
|
|
786
|
-
* forks the same way — one branch per candidate, including the reserved
|
|
787
|
-
* `agent.plan.done` move — advancing each branch through the real plan protocol
|
|
788
|
-
* (`resolveAgentRequests`), so a plan can consume several depth units. Text/`userInput` invokes
|
|
784
|
+
* an idle wait it forks per externally-accepted event. Text/`userInput` invokes
|
|
789
785
|
* are resolved from `textOutputs` (a by-src canned-output map) — a missing src
|
|
790
786
|
* halts that branch with a `needs-output` terminal rather than throwing.
|
|
791
787
|
*
|
|
@@ -938,7 +934,7 @@ type ScriptedDecisionEntry = ScriptedDecisionValue | ((request: AgentDecisionReq
|
|
|
938
934
|
type ScriptedTextEntry = ((request: AgentTextRequest, info?: AgentRequestExecutorInfo) => unknown) | string | number | boolean | null | object;
|
|
939
935
|
/** The script {@link createScriptedExecutors} plays back. */
|
|
940
936
|
interface ScriptedExecutorsScript {
|
|
941
|
-
/** Answers for `decide`
|
|
937
|
+
/** Answers for `decide` requests, consumed in order. */
|
|
942
938
|
decisions?: ScriptedDecisionEntry[];
|
|
943
939
|
/** Answers for text requests, consumed in order. `generateText` and `streamText` share this one queue. */
|
|
944
940
|
text?: ScriptedTextEntry[];
|
|
@@ -1202,4 +1198,4 @@ declare function getJsonSchema(schema?: StandardSchemaV1): Promise<Record<string
|
|
|
1202
1198
|
*/
|
|
1203
1199
|
declare function getJsonSchemaSync(schema?: StandardSchemaV1): Record<string, unknown> | undefined;
|
|
1204
1200
|
//#endregion
|
|
1205
|
-
export { AGENT_EVENT_SCHEMA_VERSION, AGENT_INIT_EVENT_TYPE, AGENT_TRACE_SCHEMA_VERSION, AGENT_USAGE_EVENT_TYPE, type AgentActorSession, type AgentCallUsage, type AgentDecisionExecutor, AgentDecisionExhaustedError, type AgentDecisionInput, type AgentDecisionRequest, type AgentEffect, type AgentEffectDiff, AgentError, type AgentEventDescriptor, AgentEventLogConflictError, type AgentEventLogDiff, type AgentEventLogStore, type AgentEventToolNameResolver, type AgentExecutorTextRequest, AgentIdleError, AgentIllegalResumeEventError, type AgentLintDiagnostic, AgentLintError, type AgentLintSeverity, type AgentLogEntry, type AgentLogPatchOperation, type AgentLogVerification, type AgentMessage, type AgentMessageInfo, type AgentModelRef, type AgentOutputMode, type AgentPathReport, type AgentPathTerminal,
|
|
1201
|
+
export { AGENT_EVENT_SCHEMA_VERSION, AGENT_INIT_EVENT_TYPE, AGENT_TRACE_SCHEMA_VERSION, AGENT_USAGE_EVENT_TYPE, type AgentActorSession, type AgentCallUsage, type AgentDecisionExecutor, AgentDecisionExhaustedError, type AgentDecisionInput, type AgentDecisionRequest, type AgentEffect, type AgentEffectDiff, AgentError, type AgentEventDescriptor, AgentEventLogConflictError, type AgentEventLogDiff, type AgentEventLogStore, type AgentEventToolNameResolver, type AgentExecutorTextRequest, AgentIdleError, AgentIllegalResumeEventError, type AgentLintDiagnostic, AgentLintError, type AgentLintSeverity, type AgentLogEntry, type AgentLogPatchOperation, type AgentLogVerification, type AgentMessage, type AgentMessageInfo, type AgentModelRef, type AgentOutputMode, type AgentPathReport, type AgentPathTerminal, AgentReplayDivergenceError, AgentReplayMachineMismatchError, type AgentRequest, type AgentRequestExecutor, type AgentRequestExecutorInfo, type AgentRequestExecutorResult, type AgentRequestExecutors, type AgentRequestOptions, type AgentRequestSource, type AgentRun, type AgentRunMeta, type AgentSchemaPack, type AgentSnapshotStore, AgentSnapshotVersionMismatchError, type AgentStateRequest, type AgentStepRequest, type AgentTextRequest, type AgentTool, type AgentToolChoice, type AgentToolDescriptor, type AgentToolExecute, type AgentTools, type AgentTraceEvent, type AgentUsage, type AgentUsageEvent, type AgentUsageEventPayload, type AgentUserInput, type AgentUserInputExecutor, type AgentWorkflowActionConfig, type AgentWorkflowActorConfig, type AgentWorkflowConfig, type AgentWorkflowInvokeConfig, type AgentWorkflowRequestConfig, type AgentWorkflowStateConfig, type AgentWorkflowTransitionConfig, type AiSdkShapedStreamResult, type AiSdkShapedTextResult, type AllowedEvents, type AssertAgentMachineOptions, type AssistantMessage, type CanReachResult, type ChosenEvent, type CreateReplayEntryOptions, type DecisionAttempt, type DecisionLogicConfig, type ExplorePathsOptions, type FilePart, type FromConfigOptions, type FromConfigResult, type GenerateResult, type GetAgentEffectsOptions, type ImagePart, type InferOutput, type InspectedActorRef, type JsonSerializableTraceEvent, type JsonValue, type LintAgentMachineOptions, type MatchTrajectoryOptions, NonSerializableAgentEventError, type PendingUserInput, type ProvideExecutorsOptions, type ReplayOptions, type ReplayResult, type ResolveDecisionOptions, type RunAgentErrorCause, type RunAgentOptions, type RunAgentResult, type RunSeamOptions, type RunSeamResult, type SchemaCompiler, type ScriptedDecisionEntry, type ScriptedDecisionValue, type ScriptedExecutorsScript, type ScriptedTextEntry, type SeamRef, type SeamSlice, type SeamTurn, type SimulateAgentOptions, type SimulateAgentResult, type SimulationScript, type SimulationTrailEntry, type StandardSchemaV1, type StructuredOutputEnvelope, type SystemMessage, type TextLogic, type TextLogicConfig, type TextLogicExecuteArgs, type TextLogicExecutor, type TextPart, type ToolCallPart, type ToolMessage, type ToolResultPart, type TrajectoryEvent, type TrajectoryItem, type TrajectoryMatch, type TrajectoryMiss, type UserMessage, type WithAgentUsageEvent, appendMessages, assertAgentLogEntry, assertAgentMachine, assertEventLogStoreConformance, assertJsonSerializable, assistantMessage, bindRequestExecutor, buildEnvelopeSchema, canReach, createAgentActor, createAgentRun, createAgentSchemas, createInMemoryEventLogStore, createReplayEntry, createScriptedExecutors, createTextLogic, diffEventLogs, executeAgentRequest, explorePaths, generateResult, getAcceptedEvents, getAgentEffects, getAgentMessages, getAgentOutputMode, getCallUsage, getJsonSchema, getJsonSchemaSync, getMachineStructuralHash, getStateMeta, initEntry, inspectTransitions, isStandardSchema, lintAgentMachine, matchesTrajectory, messagesSchema, parseAgentEvent, parseModelRef, parseOutput, parseStructuredEnvelope, persistSnapshot, provideExecutors, renderDecisionAttempts, replay, resolveDecision, runAgent, runSeam, serializeTraceEvent, setupAgent, simulateAgent, systemMessage, toolMessage, traceTransitions, userMessage, verifyReplay };
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as AgentError } from "./errors-CeSXQx0v.mjs";
|
|
2
|
-
import { _ as
|
|
3
|
-
import { A as
|
|
2
|
+
import { _ as resolveAgentStep, a as AgentReplayDivergenceError, b as messagesSchema, c as diffEventLogs, d as initEntry, f as replay, g as initialAgentStep, h as getInvokeEffectMetadata, i as AGENT_USAGE_EVENT_TYPE, l as getAgentEffects, m as executeAgentRequest, n as setupAgent, o as AgentReplayMachineMismatchError, p as verifyReplay, r as AGENT_INIT_EVENT_TYPE, s as createReplayEntry, t as createAgentSchemas, u as getCallUsage, v as transitionAgentStep, y as appendMessages } from "./setup-agent-DeHRW-qX.mjs";
|
|
3
|
+
import { A as isUnboundPlaceholder, B as getStateMeta, C as parseStructuredEnvelope, D as getMachineStaticTransitionTargets, E as executorBoundLogics, F as findNonSerializableContextPaths, G as userMessage, H as persistSnapshot, I as getAgentMessages, L as getJsonSchema, O as getMachineSuspensionPredicate, P as assistantMessage, R as getJsonSchemaSync, S as parseOutput, U as systemMessage, V as isStandardSchema, W as toolMessage, _ as extractCallUsage, a as resolveDecision, b as normalizeGeneratorResult, c as AGENT_USAGE_TOKEN_FIELDS, f as bindRequestExecutor, h as createTextLogic, i as renderDecisionAttempts, k as getRegisteredAgentExecutionOptions, o as getAcceptedEvents, p as buildEnvelopeSchema, r as isDecisionLogic, s as parseAgentEvent, t as AgentDecisionExhaustedError, u as INTERPRET_SOURCE, v as getAgentOutputMode, x as parseModelRef, y as isTextLogic, z as getMachineStructuralHash } from "./decision-D9Zi7Xi5.mjs";
|
|
4
4
|
import { a as assertEventLogStoreConformance, i as assertAgentLogEntry, n as AgentEventLogConflictError, o as assertJsonSerializable, r as NonSerializableAgentEventError, s as createInMemoryEventLogStore, t as AGENT_EVENT_SCHEMA_VERSION } from "./event-log-store-D7pWtIhb.mjs";
|
|
5
|
-
import { createActor, createAsyncLogic, getNextTransitions } from "xstate";
|
|
5
|
+
import { createActor, createAsyncLogic, getNextTransitions, isMachineSnapshot } from "xstate";
|
|
6
6
|
//#region src/internal/state-request-pass.ts
|
|
7
7
|
async function runTextPhase(stateRequest, baseMessages, deps) {
|
|
8
8
|
const { model, system } = stateRequest;
|
|
@@ -364,7 +364,7 @@ function assertMachineBindable(machine, effectiveSources, options, ctx) {
|
|
|
364
364
|
assertChildMachineBindable(src, src, stateName, options, ctx);
|
|
365
365
|
continue;
|
|
366
366
|
}
|
|
367
|
-
if ((isTextLogic(src) || isDecisionLogic(src)
|
|
367
|
+
if ((isTextLogic(src) || isDecisionLogic(src)) && !executorBoundLogics.has(src)) throw new Error(`runAgent: ${where} '${stateName}' invokes a direct-object actor logic (kind: '${src.kind}'). Direct-object invoke srcs cannot be rebound by runAgent — either call '.withExecutor(...)' on the logic before invoking it, or register it as a string-keyed actor source instead (machine.provide({ actors: { name: logic } })) and invoke it by name.`);
|
|
368
368
|
continue;
|
|
369
369
|
}
|
|
370
370
|
const logic = effectiveSources[src];
|
|
@@ -380,11 +380,6 @@ function assertMachineBindable(machine, effectiveSources, options, ctx) {
|
|
|
380
380
|
if (!options.hasDecide) throw new Error(`runAgent: ${where} '${stateName}' invokes decision source '${src}' but no 'decide' executor was provided to runAgent(...).`);
|
|
381
381
|
continue;
|
|
382
382
|
}
|
|
383
|
-
if (isPlanLogic(logic)) {
|
|
384
|
-
if (!ctx.rebindable) throw unrebindableChildRequestError(ctx.childPath, stateName, src, "plan");
|
|
385
|
-
if (!options.hasDecide) throw new Error(`runAgent: ${where} '${stateName}' invokes plan source '${src}' but no 'decide' executor was provided to runAgent(...).`);
|
|
386
|
-
continue;
|
|
387
|
-
}
|
|
388
383
|
if (isTextLogic(logic)) {
|
|
389
384
|
if (executorBoundLogics.has(logic)) continue;
|
|
390
385
|
if (!ctx.rebindable) throw unrebindableChildRequestError(ctx.childPath, stateName, src, logic.mode === "stream" ? "streaming text" : "text");
|
|
@@ -442,11 +437,11 @@ function selfIdAndSrc(self) {
|
|
|
442
437
|
};
|
|
443
438
|
}
|
|
444
439
|
/**
|
|
445
|
-
* The machine actor that INVOKED a decision
|
|
440
|
+
* The machine actor that INVOKED a decision request — the actor whose
|
|
446
441
|
* live snapshot supplies the candidate events and drives `canTake`/`send`.
|
|
447
442
|
* For a top-level request this is the root actor (identity-equal to
|
|
448
443
|
* `runCtx.actorHolder.actorRef`); for a request inside an invoked child
|
|
449
|
-
* machine it is that child's actor, so a child decision
|
|
444
|
+
* machine it is that child's actor, so a child decision reads and drives
|
|
450
445
|
* the CHILD's snapshot — not the root's. Read off `self._parent`, with the
|
|
451
446
|
* root actor as a fallback.
|
|
452
447
|
*/
|
|
@@ -541,7 +536,7 @@ function wrapTextLogicForRunAgent(logic, runCtx) {
|
|
|
541
536
|
}
|
|
542
537
|
});
|
|
543
538
|
}
|
|
544
|
-
function createCountingDecide(runCtx, self
|
|
539
|
+
function createCountingDecide(runCtx, self) {
|
|
545
540
|
return async (attemptRequest) => {
|
|
546
541
|
runCtx.consumeModelCall();
|
|
547
542
|
runCtx.onTrace?.({
|
|
@@ -557,7 +552,7 @@ function createCountingDecide(runCtx, self, kind = "decision") {
|
|
|
557
552
|
if (usage) {
|
|
558
553
|
const { src } = selfIdAndSrc(self);
|
|
559
554
|
runCtx.recordUsage?.(usage, {
|
|
560
|
-
kind,
|
|
555
|
+
kind: "decision",
|
|
561
556
|
...attemptRequest.id ? { id: attemptRequest.id } : {},
|
|
562
557
|
...src !== "" ? { src } : {},
|
|
563
558
|
model: attemptRequest.model
|
|
@@ -594,8 +589,8 @@ function createCountingDecide(runCtx, self, kind = "decision") {
|
|
|
594
589
|
* logic here that calls `resolveDecision` itself, reusing `logic.request(...)`
|
|
595
590
|
* to build the request the same way the original logic would have.
|
|
596
591
|
*
|
|
597
|
-
* On success it SENDS the chosen event to the invoking actor (auto-delivery
|
|
598
|
-
*
|
|
592
|
+
* On success it SENDS the chosen event to the invoking actor (auto-delivery)
|
|
593
|
+
* and then completes with that event
|
|
599
594
|
* as its output — so callers never wire an `onDone` to deliver it. See the
|
|
600
595
|
* send-then-complete note inside `run` for how exit-cancels-invoke interacts
|
|
601
596
|
* with `onDone`.
|
|
@@ -632,85 +627,6 @@ function createRunAgentDecisionLogic(logic, runCtx) {
|
|
|
632
627
|
});
|
|
633
628
|
}
|
|
634
629
|
/**
|
|
635
|
-
* Builds the plan actor logic runAgent installs in place of the `agent.plan`
|
|
636
|
-
* builtin: iterated {@link resolveDecision}. Each step re-reads the live
|
|
637
|
-
* snapshot (so the candidate set reflects everything applied so far), asks
|
|
638
|
-
* the `decide` executor for one legal event with the same validation/retry
|
|
639
|
-
* loop a decision gets, and sends it to the machine. The loop ends on a
|
|
640
|
-
* `stopOn` event, at `maxSteps`, when no legal candidate remains, or when an
|
|
641
|
-
* applied event exits the invoking state (xstate cancels this invoke — the
|
|
642
|
-
* machine simply moves on and the pending output is discarded).
|
|
643
|
-
*
|
|
644
|
-
* The invoke's `input` is resolved once, so the prompt cannot re-render
|
|
645
|
-
* context between steps; instead the applied trail is appended to the prompt
|
|
646
|
-
* each step so the model can see plan progress.
|
|
647
|
-
*/
|
|
648
|
-
function createRunAgentPlanLogic(logic, runCtx) {
|
|
649
|
-
const planLogic = createAsyncLogic({ run: async ({ input, signal, self }) => {
|
|
650
|
-
if (!runCtx.decide) throw new Error("runAgent: no 'decide' executor provided.");
|
|
651
|
-
const { id } = selfIdAndSrc(self);
|
|
652
|
-
const stopOn = new Set(input.stopOn ?? []);
|
|
653
|
-
const countingDecide = createCountingDecide(runCtx, self, "plan");
|
|
654
|
-
const base = logic.request(input);
|
|
655
|
-
let ledger = initialPlanLedger(logic, input);
|
|
656
|
-
const end = (stopped) => {
|
|
657
|
-
ledger = advancePlanLedger(logic, ledger, {
|
|
658
|
-
type: "plan.ended",
|
|
659
|
-
stopped
|
|
660
|
-
});
|
|
661
|
-
return ledger.output;
|
|
662
|
-
};
|
|
663
|
-
await Promise.resolve();
|
|
664
|
-
const invokingActor = invokingActorOf(self, runCtx);
|
|
665
|
-
while (ledger.context.stepsRemaining > 0) {
|
|
666
|
-
const actorRef = invokingActor;
|
|
667
|
-
if (!actorRef || signal.aborted) break;
|
|
668
|
-
const machineEvents = getAcceptedEvents(actorRef.getSnapshot(), {
|
|
669
|
-
schemas: runCtx.schemas,
|
|
670
|
-
eventTypes: logic.allowedEventTypes(input)
|
|
671
|
-
});
|
|
672
|
-
if (machineEvents.length === 0) return end("no-legal-events");
|
|
673
|
-
const doneDescriptor = {
|
|
674
|
-
type: PLAN_DONE_EVENT_TYPE,
|
|
675
|
-
toolName: sanitizeEventToolName(PLAN_DONE_EVENT_TYPE)
|
|
676
|
-
};
|
|
677
|
-
const events = machineEvents.some((event) => event.type === "agent.plan.done") ? machineEvents : [...machineEvents, doneDescriptor];
|
|
678
|
-
const applied = ledger.context.applied;
|
|
679
|
-
const trail = applied.length === 0 ? "" : `\n\nEvents already applied in this plan, in order:\n${applied.map((step) => JSON.stringify(step)).join("\n")}\nContinue from here; do not repeat applied events.`;
|
|
680
|
-
const doneHint = `\n\nWhen the request is fully handled (or no action is needed), choose '${PLAN_DONE_EVENT_TYPE}'.`;
|
|
681
|
-
const chosen = await resolveDecision({
|
|
682
|
-
...base,
|
|
683
|
-
id: `${id}[${applied.length}]`,
|
|
684
|
-
events,
|
|
685
|
-
prompt: `${base.prompt ?? ""}${trail}${doneHint}`,
|
|
686
|
-
attempts: []
|
|
687
|
-
}, countingDecide, {
|
|
688
|
-
maxRetries: input.maxRetries ?? logic.maxRetries,
|
|
689
|
-
signal,
|
|
690
|
-
canTake: (event) => {
|
|
691
|
-
if (event.type === "agent.plan.done" || stopOn.has(event.type)) return true;
|
|
692
|
-
return invokingActor ? invokingActor.getSnapshot().can(event) : true;
|
|
693
|
-
}
|
|
694
|
-
});
|
|
695
|
-
if (chosen.type === "agent.plan.done") return end("done");
|
|
696
|
-
actorRef.send(chosen);
|
|
697
|
-
ledger = advancePlanLedger(logic, ledger, {
|
|
698
|
-
type: "plan.applied",
|
|
699
|
-
event: chosen
|
|
700
|
-
});
|
|
701
|
-
await Promise.resolve();
|
|
702
|
-
if (stopOn.has(chosen.type)) return end("stop-event");
|
|
703
|
-
}
|
|
704
|
-
return end("max-steps");
|
|
705
|
-
} });
|
|
706
|
-
return Object.assign(planLogic, {
|
|
707
|
-
kind: "statelyai.planLogic",
|
|
708
|
-
maxRetries: logic.maxRetries,
|
|
709
|
-
request: logic.request,
|
|
710
|
-
allowedEventTypes: logic.allowedEventTypes
|
|
711
|
-
});
|
|
712
|
-
}
|
|
713
|
-
/**
|
|
714
630
|
* The set of string-keyed actor `src`s the machine's own config invokes
|
|
715
631
|
* (top-level, recursing into child STATES but not into invoked child
|
|
716
632
|
* machines). {@link provideExecutors} uses it to require an executor only for a
|
|
@@ -850,17 +766,9 @@ function bindDecisionForProvide(machine, logic, executors, options) {
|
|
|
850
766
|
return createRunAgentDecisionLogic(logic, provideBindContext(machine, executors, options));
|
|
851
767
|
}
|
|
852
768
|
/**
|
|
853
|
-
* Host-binds one `agent.plan` source for {@link provideExecutors}: runAgent's
|
|
854
|
-
* plan wrapper (iterated snapshot-driven decisions, auto-delivery) with the same
|
|
855
|
-
* request-level tracing runAgent emits, minus run-scoped counting. @internal
|
|
856
|
-
*/
|
|
857
|
-
function bindPlanForProvide(machine, logic, executors, options) {
|
|
858
|
-
return createRunAgentPlanLogic(logic, provideBindContext(machine, executors, options));
|
|
859
|
-
}
|
|
860
|
-
/**
|
|
861
769
|
* Recursively rebinds an invoked child machine's own agent sources with the
|
|
862
770
|
* SAME host-backed wrappers runAgent applies to the top-level machine, so a
|
|
863
|
-
* child's text/stream/decision
|
|
771
|
+
* child's text/stream/decision requests inherit runAgent's executors and
|
|
864
772
|
* participate in maxModelCalls counting, onTrace/onChunk/onResult exactly like
|
|
865
773
|
* parent requests. Returns the child machine to invoke: a `.provide`-rebound
|
|
866
774
|
* copy when any inner source needed wrapping, else the original untouched.
|
|
@@ -881,10 +789,6 @@ function rebindChildMachine(childMachine, runCtx, visited) {
|
|
|
881
789
|
if (!executorBoundLogics.has(logic)) wrapped[key] = createRunAgentDecisionLogic(logic, runCtx);
|
|
882
790
|
continue;
|
|
883
791
|
}
|
|
884
|
-
if (isPlanLogic(logic)) {
|
|
885
|
-
wrapped[key] = createRunAgentPlanLogic(logic, runCtx);
|
|
886
|
-
continue;
|
|
887
|
-
}
|
|
888
792
|
if (isTextLogic(logic)) {
|
|
889
793
|
if (!executorBoundLogics.has(logic)) wrapped[key] = wrapTextLogicForRunAgent(logic, runCtx);
|
|
890
794
|
continue;
|
|
@@ -1084,10 +988,6 @@ function createAgentSession(machine, options, lifecycle) {
|
|
|
1084
988
|
wrappedSources[key] = createRunAgentDecisionLogic(logic, runCtx);
|
|
1085
989
|
continue;
|
|
1086
990
|
}
|
|
1087
|
-
if (isPlanLogic(logic)) {
|
|
1088
|
-
wrappedSources[key] = createRunAgentPlanLogic(logic, runCtx);
|
|
1089
|
-
continue;
|
|
1090
|
-
}
|
|
1091
991
|
if (isTextLogic(logic)) {
|
|
1092
992
|
if (!executorBoundLogics.has(logic)) wrappedSources[key] = wrapTextLogicForRunAgent(logic, runCtx);
|
|
1093
993
|
continue;
|
|
@@ -1224,10 +1124,8 @@ function createAgentSession(machine, options, lifecycle) {
|
|
|
1224
1124
|
settle({
|
|
1225
1125
|
status: "idle",
|
|
1226
1126
|
snapshot: current,
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
persistedSnapshot: actor.getPersistedSnapshot()
|
|
1230
|
-
} : {}
|
|
1127
|
+
persistedSnapshot: actor.getPersistedSnapshot(),
|
|
1128
|
+
...pendingUserInputs.length > 0 ? { pendingUserInputs } : {}
|
|
1231
1129
|
});
|
|
1232
1130
|
};
|
|
1233
1131
|
let interpreting = false;
|
|
@@ -1358,7 +1256,13 @@ function createAgentSession(machine, options, lifecycle) {
|
|
|
1358
1256
|
return;
|
|
1359
1257
|
}
|
|
1360
1258
|
if (!deliveringResumeEvent && isSuspended(snapshot) && isIdleSnapshot(snapshot, { ignoreUserInputChildren: userInputIsPlaceholder })) {
|
|
1361
|
-
|
|
1259
|
+
queueMicrotask(() => {
|
|
1260
|
+
if (settled) return;
|
|
1261
|
+
const current = actor.getSnapshot();
|
|
1262
|
+
if (isSuspended(current) && isIdleSnapshot(current, { ignoreUserInputChildren: userInputIsPlaceholder })) {
|
|
1263
|
+
if (!maybeInterpret(current)) settleIdle(current);
|
|
1264
|
+
} else scheduleIdleCheck();
|
|
1265
|
+
});
|
|
1362
1266
|
return;
|
|
1363
1267
|
}
|
|
1364
1268
|
scheduleIdleCheck();
|
|
@@ -1498,7 +1402,10 @@ function isIdleSnapshot(snapshot, { ignoreUserInputChildren }) {
|
|
|
1498
1402
|
if (Object.values(snapshot.children ?? {}).some((child) => {
|
|
1499
1403
|
const ref = child;
|
|
1500
1404
|
if (ignoreUserInputChildren && ref?.src === "agent.userInput") return false;
|
|
1501
|
-
|
|
1405
|
+
const childSnapshot = ref?.getSnapshot?.();
|
|
1406
|
+
if (childSnapshot?.status !== "active") return false;
|
|
1407
|
+
if (isMachineSnapshot(childSnapshot)) return !isIdleSnapshot(childSnapshot, { ignoreUserInputChildren });
|
|
1408
|
+
return true;
|
|
1502
1409
|
})) return false;
|
|
1503
1410
|
return !getNextTransitions(snapshot).some((transitionDef) => transitionDef.eventType === "" || transitionDef.eventType.startsWith("xstate.after"));
|
|
1504
1411
|
}
|
|
@@ -1637,7 +1544,6 @@ function createAgentRun(machine, options) {
|
|
|
1637
1544
|
* - decision / `agent.decide` source → `executors.decide` (snapshot-driven
|
|
1638
1545
|
* candidate events, guard `canTake`, and auto-delivery of the chosen event,
|
|
1639
1546
|
* mirroring `runAgent` but without its model-call counting)
|
|
1640
|
-
* - `agent.plan` source → `executors.decide` (iterated, same semantics)
|
|
1641
1547
|
*
|
|
1642
1548
|
* Pass `options.onTrace` to observe request-level trace events (identical in
|
|
1643
1549
|
* shape to `runAgent`'s); pair it with {@link traceTransitions} on the actor's
|
|
@@ -1675,14 +1581,6 @@ function provideExecutors(machine, executors, options = {}) {
|
|
|
1675
1581
|
wrappedSources[key] = bindDecisionForProvide(provided, logic, executors, bindOptions);
|
|
1676
1582
|
continue;
|
|
1677
1583
|
}
|
|
1678
|
-
if (isPlanLogic(logic)) {
|
|
1679
|
-
if (!executors.decide) {
|
|
1680
|
-
if (invokedSrcs.has(key)) throw missingExecutorError(key, "plan", "decide");
|
|
1681
|
-
continue;
|
|
1682
|
-
}
|
|
1683
|
-
wrappedSources[key] = bindPlanForProvide(provided, logic, executors, bindOptions);
|
|
1684
|
-
continue;
|
|
1685
|
-
}
|
|
1686
1584
|
if (isTextLogic(logic)) {
|
|
1687
1585
|
if (executorBoundLogics.has(logic)) continue;
|
|
1688
1586
|
if (!(logic.mode === "stream" ? executors.streamText : executors.generateText)) {
|
|
@@ -1701,7 +1599,6 @@ function missingExecutorError(src, kind, executor) {
|
|
|
1701
1599
|
//#endregion
|
|
1702
1600
|
//#region src/verify.ts
|
|
1703
1601
|
const DECIDE_SRC = "agent.decide";
|
|
1704
|
-
const PLAN_SRC = "agent.plan";
|
|
1705
1602
|
function normalizeInvokes(invoke) {
|
|
1706
1603
|
if (invoke === void 0 || invoke === null) return [];
|
|
1707
1604
|
return Array.isArray(invoke) ? invoke : [invoke];
|
|
@@ -1838,17 +1735,12 @@ function hasNonEmptyOn(config) {
|
|
|
1838
1735
|
function decisionKindOf(src, actors) {
|
|
1839
1736
|
if (typeof src === "string") {
|
|
1840
1737
|
if (src === DECIDE_SRC) return "decision";
|
|
1841
|
-
|
|
1842
|
-
const logic = actors[src];
|
|
1843
|
-
if (isDecisionLogic(logic)) return "decision";
|
|
1844
|
-
if (isPlanLogic(logic)) return "plan";
|
|
1845
|
-
return;
|
|
1738
|
+
return isDecisionLogic(actors[src]) ? "decision" : void 0;
|
|
1846
1739
|
}
|
|
1847
|
-
|
|
1848
|
-
if (isPlanLogic(src)) return "plan";
|
|
1740
|
+
return isDecisionLogic(src) ? "decision" : void 0;
|
|
1849
1741
|
}
|
|
1850
1742
|
function isAgentLogicNeedingBinding(src) {
|
|
1851
|
-
return (isTextLogic(src) || isDecisionLogic(src)
|
|
1743
|
+
return (isTextLogic(src) || isDecisionLogic(src)) && !executorBoundLogics.has(src);
|
|
1852
1744
|
}
|
|
1853
1745
|
function schemaExposesJson(schema) {
|
|
1854
1746
|
if (!schema) return false;
|
|
@@ -2129,17 +2021,6 @@ async function simulateAgent(machine, options) {
|
|
|
2129
2021
|
});
|
|
2130
2022
|
continue;
|
|
2131
2023
|
}
|
|
2132
|
-
if (request.kind === "plan") {
|
|
2133
|
-
const taken = takeFromQueue(script.decisions, request.src);
|
|
2134
|
-
if (!taken.found) throw scriptDryError("decision", request.src, request.id, request);
|
|
2135
|
-
const event = taken.value;
|
|
2136
|
-
step = await resolveAgentRequests(machine, step, { decide: async () => ({ event }) });
|
|
2137
|
-
trail.push({
|
|
2138
|
-
state: step.snapshot.value,
|
|
2139
|
-
appliedEvent: taken.value
|
|
2140
|
-
});
|
|
2141
|
-
continue;
|
|
2142
|
-
}
|
|
2143
2024
|
const taken = takeFromQueue(script.text, request.src);
|
|
2144
2025
|
if (!taken.found) throw scriptDryError("text", request.src, request.id);
|
|
2145
2026
|
step = resolveAgentStep(machine, step, request, taken.value);
|
|
@@ -2223,7 +2104,7 @@ async function explore(machine, options, stopWhen) {
|
|
|
2223
2104
|
recordState(current.snapshot);
|
|
2224
2105
|
continue;
|
|
2225
2106
|
}
|
|
2226
|
-
if (request &&
|
|
2107
|
+
if (request && request.kind === "decision") return { step: current };
|
|
2227
2108
|
const [invoke] = pendingInvokes(current);
|
|
2228
2109
|
if (invoke) {
|
|
2229
2110
|
if (!(invoke.src in textOutputs)) return {
|
|
@@ -2270,8 +2151,7 @@ async function explore(machine, options, stopWhen) {
|
|
|
2270
2151
|
return;
|
|
2271
2152
|
}
|
|
2272
2153
|
const request = settled.requests[0];
|
|
2273
|
-
const
|
|
2274
|
-
const branchEvents = request?.kind === "decision" || request?.kind === "plan" ? request.events.map((descriptor) => ({ type: descriptor.type })) : getAcceptedEvents(settled.snapshot).map((descriptor) => ({ type: descriptor.type }));
|
|
2154
|
+
const branchEvents = request?.kind === "decision" ? request.events.map((descriptor) => ({ type: descriptor.type })) : getAcceptedEvents(settled.snapshot).map((descriptor) => ({ type: descriptor.type }));
|
|
2275
2155
|
if (branchEvents.length === 0) {
|
|
2276
2156
|
pathsExplored++;
|
|
2277
2157
|
terminals.push({
|
|
@@ -2296,11 +2176,11 @@ async function explore(machine, options, stopWhen) {
|
|
|
2296
2176
|
if (pathsExplored >= maxPaths) hitPathCap = true;
|
|
2297
2177
|
return;
|
|
2298
2178
|
}
|
|
2299
|
-
if (!
|
|
2179
|
+
if (!settled.snapshot.can(event)) {
|
|
2300
2180
|
prunedByGuard++;
|
|
2301
2181
|
continue;
|
|
2302
2182
|
}
|
|
2303
|
-
const next =
|
|
2183
|
+
const next = transitionAgentStep(machine, settled, event);
|
|
2304
2184
|
recordState(next.snapshot);
|
|
2305
2185
|
await visit(next, [...path, event], depth + 1);
|
|
2306
2186
|
}
|
|
@@ -2323,10 +2203,7 @@ async function explore(machine, options, stopWhen) {
|
|
|
2323
2203
|
* depth, model-free, and reports which states are reached and how each path
|
|
2324
2204
|
* terminates. At each decision request it forks one branch per candidate event
|
|
2325
2205
|
* (guard-rejected candidates are counted in `prunedByGuard`, not explored); at
|
|
2326
|
-
* an idle wait it forks per externally-accepted event.
|
|
2327
|
-
* forks the same way — one branch per candidate, including the reserved
|
|
2328
|
-
* `agent.plan.done` move — advancing each branch through the real plan protocol
|
|
2329
|
-
* (`resolveAgentRequests`), so a plan can consume several depth units. Text/`userInput` invokes
|
|
2206
|
+
* an idle wait it forks per externally-accepted event. Text/`userInput` invokes
|
|
2330
2207
|
* are resolved from `textOutputs` (a by-src canned-output map) — a missing src
|
|
2331
2208
|
* halts that branch with a `needs-output` terminal rather than throwing.
|
|
2332
2209
|
*
|
|
@@ -2796,4 +2673,4 @@ async function runSeam(machine, options) {
|
|
|
2796
2673
|
};
|
|
2797
2674
|
}
|
|
2798
2675
|
//#endregion
|
|
2799
|
-
export { AGENT_EVENT_SCHEMA_VERSION, AGENT_INIT_EVENT_TYPE, AGENT_TRACE_SCHEMA_VERSION, AGENT_USAGE_EVENT_TYPE, AgentDecisionExhaustedError, AgentError, AgentEventLogConflictError, AgentIdleError, AgentIllegalResumeEventError, AgentLintError, AgentReplayDivergenceError, AgentReplayMachineMismatchError, AgentSnapshotVersionMismatchError, NonSerializableAgentEventError,
|
|
2676
|
+
export { AGENT_EVENT_SCHEMA_VERSION, AGENT_INIT_EVENT_TYPE, AGENT_TRACE_SCHEMA_VERSION, AGENT_USAGE_EVENT_TYPE, AgentDecisionExhaustedError, AgentError, AgentEventLogConflictError, AgentIdleError, AgentIllegalResumeEventError, AgentLintError, AgentReplayDivergenceError, AgentReplayMachineMismatchError, AgentSnapshotVersionMismatchError, NonSerializableAgentEventError, appendMessages, assertAgentLogEntry, assertAgentMachine, assertEventLogStoreConformance, assertJsonSerializable, assistantMessage, bindRequestExecutor, buildEnvelopeSchema, canReach, createAgentActor, createAgentRun, createAgentSchemas, createInMemoryEventLogStore, createReplayEntry, createScriptedExecutors, createTextLogic, diffEventLogs, executeAgentRequest, explorePaths, generateResult, getAcceptedEvents, getAgentEffects, getAgentMessages, getAgentOutputMode, getCallUsage, getJsonSchema, getJsonSchemaSync, getMachineStructuralHash, getStateMeta, initEntry, inspectTransitions, isStandardSchema, lintAgentMachine, matchesTrajectory, messagesSchema, parseAgentEvent, parseModelRef, parseOutput, parseStructuredEnvelope, persistSnapshot, provideExecutors, renderDecisionAttempts, replay, resolveDecision, runAgent, runSeam, serializeTraceEvent, setupAgent, simulateAgent, systemMessage, toolMessage, traceTransitions, userMessage, verifyReplay };
|
package/dist/machines.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_setup_agent = require("./setup-agent-
|
|
2
|
+
const require_setup_agent = require("./setup-agent-CpK0ZRWV.cjs");
|
|
3
3
|
//#region src/machines/internal.ts
|
|
4
4
|
/** The builtin inline text request every preset lowers a request entry to. */
|
|
5
5
|
const GENERATE_TEXT_SRC = "agent.generateText";
|
package/dist/machines.d.cts
CHANGED
package/dist/machines.d.mts
CHANGED
package/dist/machines.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as setupAgent } from "./setup-agent-
|
|
1
|
+
import { n as setupAgent } from "./setup-agent-DeHRW-qX.mjs";
|
|
2
2
|
//#region src/machines/internal.ts
|
|
3
3
|
/** The builtin inline text request every preset lowers a request entry to. */
|
|
4
4
|
const GENERATE_TEXT_SRC = "agent.generateText";
|
package/dist/otel.cjs
CHANGED
|
@@ -33,23 +33,15 @@ function usageAttributes(usage) {
|
|
|
33
33
|
}
|
|
34
34
|
return attributes;
|
|
35
35
|
}
|
|
36
|
-
/** The model ref a request targets: text
|
|
36
|
+
/** The model ref a request targets: text carries it on `input`, a decision inline. */
|
|
37
37
|
function requestModel(request) {
|
|
38
38
|
const model = request.kind === "decision" ? request.model : request.input?.model;
|
|
39
39
|
return typeof model === "string" ? model : void 0;
|
|
40
40
|
}
|
|
41
|
-
/** The `src` a text
|
|
41
|
+
/** The `src` a text invoke was declared with; a decision has none. */
|
|
42
42
|
function requestSrc(request) {
|
|
43
43
|
return "src" in request && typeof request.src === "string" ? request.src : void 0;
|
|
44
44
|
}
|
|
45
|
-
/**
|
|
46
|
-
* `gen_ai.operation.name` for a request. A plan request drives the machine
|
|
47
|
-
* through a sequence of events, which semconv names `plan`; text and decision
|
|
48
|
-
* requests are both single chat completions.
|
|
49
|
-
*/
|
|
50
|
-
function operationName(request) {
|
|
51
|
-
return request.kind === "plan" ? "plan" : "chat";
|
|
52
|
-
}
|
|
53
45
|
/** Best-effort JSON, never throws — content capture must not break a run. */
|
|
54
46
|
function toJson(value) {
|
|
55
47
|
try {
|
|
@@ -162,10 +154,9 @@ function createOtelTraceHandler(options) {
|
|
|
162
154
|
const request = event.request;
|
|
163
155
|
endRequest(request.id, () => {});
|
|
164
156
|
const model = requestModel(request);
|
|
165
|
-
const operation = operationName(request);
|
|
166
157
|
const attributes = {
|
|
167
158
|
...baseAttributes,
|
|
168
|
-
"gen_ai.operation.name":
|
|
159
|
+
"gen_ai.operation.name": "chat",
|
|
169
160
|
"agent.run_id": event.runId,
|
|
170
161
|
"agent.request_id": request.id,
|
|
171
162
|
"agent.request_kind": request.kind
|
|
@@ -182,9 +173,8 @@ function createOtelTraceHandler(options) {
|
|
|
182
173
|
const json = toJson(input.messages ?? input.prompt);
|
|
183
174
|
if (json !== void 0) attributes["gen_ai.input.messages"] = json;
|
|
184
175
|
}
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
kind: operation === "plan" ? _opentelemetry_api.SpanKind.INTERNAL : _opentelemetry_api.SpanKind.CLIENT,
|
|
176
|
+
const span = tracer.startSpan(`chat ${model ?? request.kind}`, {
|
|
177
|
+
kind: _opentelemetry_api.SpanKind.CLIENT,
|
|
188
178
|
attributes
|
|
189
179
|
}, runFor(event).context);
|
|
190
180
|
requests.set(request.id, {
|
package/dist/otel.d.cts
CHANGED