@statelyai/agent 2.0.0-alpha.13 → 2.0.0-alpha.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/ai-sdk.cjs +1 -1
  2. package/dist/ai-sdk.d.cts +2 -2
  3. package/dist/ai-sdk.d.mts +2 -2
  4. package/dist/ai-sdk.mjs +1 -1
  5. package/dist/{decision-dWGhBh0P.cjs → decision-C0cUKvNt.cjs} +0 -105
  6. package/dist/{decision-BezSD_YC.mjs → decision-D9Zi7Xi5.mjs} +2 -65
  7. package/dist/index.cjs +52 -155
  8. package/dist/index.d.cts +26 -13
  9. package/dist/index.d.mts +26 -13
  10. package/dist/index.mjs +54 -156
  11. package/dist/machines.cjs +1 -1
  12. package/dist/machines.d.cts +1 -1
  13. package/dist/machines.d.mts +1 -1
  14. package/dist/machines.mjs +1 -1
  15. package/dist/otel.cjs +5 -15
  16. package/dist/otel.d.cts +1 -1
  17. package/dist/otel.d.mts +1 -1
  18. package/dist/otel.mjs +5 -15
  19. package/dist/{run-agent-C3mFDGTf.d.mts → run-agent-BWzo4FLv.d.mts} +83 -109
  20. package/dist/{run-agent-DnvtcnTZ.d.cts → run-agent-B_n4Qxye.d.cts} +83 -109
  21. package/dist/{setup-agent-DP95MFrI.cjs → setup-agent-CpK0ZRWV.cjs} +10 -210
  22. package/dist/{setup-agent-DAZZSjDS.mjs → setup-agent-DeHRW-qX.mjs} +11 -205
  23. package/dist/sqlite.d.cts +2 -2
  24. package/dist/sqlite.d.mts +2 -2
  25. package/dist/{text-logic-TkKPw8Aq.d.mts → text-logic-C7anC7qX.d.mts} +8 -94
  26. package/dist/{text-logic-BDxwQNsD.d.cts → text-logic-DZW7XWy9.d.cts} +8 -94
  27. package/dist/{types-QbEfCVny.d.cts → types-CTBhMnFu.d.mts} +30 -3
  28. package/dist/{types-_FXoFBGO.d.mts → types-DFD28AWe.d.cts} +30 -3
  29. package/package.json +1 -1
  30. /package/dist/{event-log-store-CriMgX1D.d.mts → event-log-store-BkUNtyOF.d.mts} +0 -0
  31. /package/dist/{event-log-store-Ruq18mGp.d.cts → event-log-store-CVd2eyRy.d.cts} +0 -0
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  import { t as AgentError } from "./errors-CeSXQx0v.mjs";
2
- import { _ as resolveAgentRequests, a as AgentReplayDivergenceError, b as appendMessages, 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 resolveAgentStep, x as messagesSchema, y as transitionAgentStep } from "./setup-agent-DAZZSjDS.mjs";
3
- import { A as parseStructuredEnvelope, D as normalizeGeneratorResult, E as isTextLogic, F as getMachineSuspensionPredicate, G as getJsonSchemaSync, H as findNonSerializableContextPaths, I as getRegisteredAgentExecutionOptions, J as isStandardSchema, K as getMachineStructuralHash, L as isUnboundPlaceholder, N as executorBoundLogics, O as parseModelRef, P as getMachineStaticTransitionTargets, Q as userMessage, S as createTextLogic, T as getAgentOutputMode, U as getAgentMessages, V as assistantMessage, W as getJsonSchema, X as systemMessage, Y as persistSnapshot, Z as toolMessage, b as buildEnvelopeSchema, c as isPlanLogic, d as getAcceptedEvents, f as parseAgentEvent, g as INTERPRET_SOURCE, k as parseOutput, l as renderDecisionAttempts, m as AGENT_USAGE_TOKEN_FIELDS, n as PLAN_DONE_EVENT_TYPE, o as initialPlanLedger, p as sanitizeEventToolName, q as getStateMeta, r as advancePlanLedger, s as isDecisionLogic, t as AgentDecisionExhaustedError, u as resolveDecision, w as extractCallUsage, y as bindRequestExecutor } from "./decision-BezSD_YC.mjs";
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, K as validateSchemaSync, 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) || isPlanLogic(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.`);
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/plan request — the actor whose
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/plan reads and drives
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, kind = "decision") {
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
- * mirroring {@link createRunAgentPlanLogic}) and then completes with that event
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,29 @@ 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
769
+ * Validates `input` against the machine's registered input schema, returning
770
+ * the schema's output so defaults are filled and transforms applied before
771
+ * the value reaches `createActor` or the replayable event log.
772
+ *
773
+ * Standard Schema only (no validation library is referenced), so this works for
774
+ * whatever the machine was declared with. Omitted input stays omitted rather
775
+ * than being validated as `{}`: "started with no input" keeps meaning what it
776
+ * has always meant, instead of newly failing schemas with required fields.
856
777
  */
857
- function bindPlanForProvide(machine, logic, executors, options) {
858
- return createRunAgentPlanLogic(logic, provideBindContext(machine, executors, options));
778
+ function resolveMachineInput(machine, input) {
779
+ if (input === void 0) return input;
780
+ const schema = getRegisteredAgentExecutionOptions(machine).schemas?.input;
781
+ if (!isStandardSchema(schema)) return input;
782
+ try {
783
+ return validateSchemaSync(schema, input);
784
+ } catch (error) {
785
+ throw new AgentError("invalid-machine-input", `runAgent: machine input failed validation against the declared input schema: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
786
+ }
859
787
  }
860
788
  /**
861
789
  * Recursively rebinds an invoked child machine's own agent sources with the
862
790
  * SAME host-backed wrappers runAgent applies to the top-level machine, so a
863
- * child's text/stream/decision/plan requests inherit runAgent's executors and
791
+ * child's text/stream/decision requests inherit runAgent's executors and
864
792
  * participate in maxModelCalls counting, onTrace/onChunk/onResult exactly like
865
793
  * parent requests. Returns the child machine to invoke: a `.provide`-rebound
866
794
  * copy when any inner source needed wrapping, else the original untouched.
@@ -881,10 +809,6 @@ function rebindChildMachine(childMachine, runCtx, visited) {
881
809
  if (!executorBoundLogics.has(logic)) wrapped[key] = createRunAgentDecisionLogic(logic, runCtx);
882
810
  continue;
883
811
  }
884
- if (isPlanLogic(logic)) {
885
- wrapped[key] = createRunAgentPlanLogic(logic, runCtx);
886
- continue;
887
- }
888
812
  if (isTextLogic(logic)) {
889
813
  if (!executorBoundLogics.has(logic)) wrapped[key] = wrapTextLogicForRunAgent(logic, runCtx);
890
814
  continue;
@@ -971,6 +895,7 @@ function createAgentSession(machine, options, lifecycle) {
971
895
  let warnedHeuristicIdle = false;
972
896
  const runId = `run_${nextRunAgentTraceId++}`;
973
897
  let traceSeq = 0;
898
+ const resolvedInput = resolveMachineInput(machine, options.input);
974
899
  const machineId = machine.config.id ?? machine.id ?? "(machine)";
975
900
  const machineVersion = options.machineVersion ?? machine.version ?? getMachineStructuralHash(machine);
976
901
  const agentMeta = {
@@ -1084,10 +1009,6 @@ function createAgentSession(machine, options, lifecycle) {
1084
1009
  wrappedSources[key] = createRunAgentDecisionLogic(logic, runCtx);
1085
1010
  continue;
1086
1011
  }
1087
- if (isPlanLogic(logic)) {
1088
- wrappedSources[key] = createRunAgentPlanLogic(logic, runCtx);
1089
- continue;
1090
- }
1091
1012
  if (isTextLogic(logic)) {
1092
1013
  if (!executorBoundLogics.has(logic)) wrappedSources[key] = wrapTextLogicForRunAgent(logic, runCtx);
1093
1014
  continue;
@@ -1169,7 +1090,7 @@ function createAgentSession(machine, options, lifecycle) {
1169
1090
  return entry;
1170
1091
  };
1171
1092
  if (replayEvents.length === 0 && effectiveSnapshot === void 0) {
1172
- const entry = initEntry(machine, options.input, { machineVersion });
1093
+ const entry = initEntry(machine, resolvedInput, { machineVersion });
1173
1094
  replayEventIds.add(entry.id);
1174
1095
  replayEvents.push(entry);
1175
1096
  options.onEvent?.(entry);
@@ -1224,10 +1145,8 @@ function createAgentSession(machine, options, lifecycle) {
1224
1145
  settle({
1225
1146
  status: "idle",
1226
1147
  snapshot: current,
1227
- ...pendingUserInputs.length > 0 ? {
1228
- pendingUserInputs,
1229
- persistedSnapshot: actor.getPersistedSnapshot()
1230
- } : {}
1148
+ persistedSnapshot: actor.getPersistedSnapshot(),
1149
+ ...pendingUserInputs.length > 0 ? { pendingUserInputs } : {}
1231
1150
  });
1232
1151
  };
1233
1152
  let interpreting = false;
@@ -1309,7 +1228,7 @@ function createAgentSession(machine, options, lifecycle) {
1309
1228
  }, 0);
1310
1229
  };
1311
1230
  actor = createActor(boundMachine, {
1312
- input: options.input,
1231
+ input: resolvedInput,
1313
1232
  snapshot: effectiveSnapshot,
1314
1233
  inspect: (event) => {
1315
1234
  if (typeof options.inspect === "function") options.inspect(event);
@@ -1358,7 +1277,13 @@ function createAgentSession(machine, options, lifecycle) {
1358
1277
  return;
1359
1278
  }
1360
1279
  if (!deliveringResumeEvent && isSuspended(snapshot) && isIdleSnapshot(snapshot, { ignoreUserInputChildren: userInputIsPlaceholder })) {
1361
- if (!maybeInterpret(snapshot)) settleIdle(snapshot);
1280
+ queueMicrotask(() => {
1281
+ if (settled) return;
1282
+ const current = actor.getSnapshot();
1283
+ if (isSuspended(current) && isIdleSnapshot(current, { ignoreUserInputChildren: userInputIsPlaceholder })) {
1284
+ if (!maybeInterpret(current)) settleIdle(current);
1285
+ } else scheduleIdleCheck();
1286
+ });
1362
1287
  return;
1363
1288
  }
1364
1289
  scheduleIdleCheck();
@@ -1400,7 +1325,7 @@ function createAgentSession(machine, options, lifecycle) {
1400
1325
  }
1401
1326
  onTrace({
1402
1327
  type: "run.start",
1403
- ...options.input !== void 0 ? { input: options.input } : {},
1328
+ ...resolvedInput !== void 0 ? { input: resolvedInput } : {},
1404
1329
  ...effectiveSnapshot !== void 0 ? { snapshot: effectiveSnapshot } : {},
1405
1330
  ...options.event !== void 0 ? { event: options.event } : {}
1406
1331
  });
@@ -1498,7 +1423,10 @@ function isIdleSnapshot(snapshot, { ignoreUserInputChildren }) {
1498
1423
  if (Object.values(snapshot.children ?? {}).some((child) => {
1499
1424
  const ref = child;
1500
1425
  if (ignoreUserInputChildren && ref?.src === "agent.userInput") return false;
1501
- return ref?.getSnapshot?.()?.status === "active";
1426
+ const childSnapshot = ref?.getSnapshot?.();
1427
+ if (childSnapshot?.status !== "active") return false;
1428
+ if (isMachineSnapshot(childSnapshot)) return !isIdleSnapshot(childSnapshot, { ignoreUserInputChildren });
1429
+ return true;
1502
1430
  })) return false;
1503
1431
  return !getNextTransitions(snapshot).some((transitionDef) => transitionDef.eventType === "" || transitionDef.eventType.startsWith("xstate.after"));
1504
1432
  }
@@ -1637,7 +1565,6 @@ function createAgentRun(machine, options) {
1637
1565
  * - decision / `agent.decide` source → `executors.decide` (snapshot-driven
1638
1566
  * candidate events, guard `canTake`, and auto-delivery of the chosen event,
1639
1567
  * mirroring `runAgent` but without its model-call counting)
1640
- * - `agent.plan` source → `executors.decide` (iterated, same semantics)
1641
1568
  *
1642
1569
  * Pass `options.onTrace` to observe request-level trace events (identical in
1643
1570
  * shape to `runAgent`'s); pair it with {@link traceTransitions} on the actor's
@@ -1675,14 +1602,6 @@ function provideExecutors(machine, executors, options = {}) {
1675
1602
  wrappedSources[key] = bindDecisionForProvide(provided, logic, executors, bindOptions);
1676
1603
  continue;
1677
1604
  }
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
1605
  if (isTextLogic(logic)) {
1687
1606
  if (executorBoundLogics.has(logic)) continue;
1688
1607
  if (!(logic.mode === "stream" ? executors.streamText : executors.generateText)) {
@@ -1701,7 +1620,6 @@ function missingExecutorError(src, kind, executor) {
1701
1620
  //#endregion
1702
1621
  //#region src/verify.ts
1703
1622
  const DECIDE_SRC = "agent.decide";
1704
- const PLAN_SRC = "agent.plan";
1705
1623
  function normalizeInvokes(invoke) {
1706
1624
  if (invoke === void 0 || invoke === null) return [];
1707
1625
  return Array.isArray(invoke) ? invoke : [invoke];
@@ -1838,17 +1756,12 @@ function hasNonEmptyOn(config) {
1838
1756
  function decisionKindOf(src, actors) {
1839
1757
  if (typeof src === "string") {
1840
1758
  if (src === DECIDE_SRC) return "decision";
1841
- if (src === PLAN_SRC) return "plan";
1842
- const logic = actors[src];
1843
- if (isDecisionLogic(logic)) return "decision";
1844
- if (isPlanLogic(logic)) return "plan";
1845
- return;
1759
+ return isDecisionLogic(actors[src]) ? "decision" : void 0;
1846
1760
  }
1847
- if (isDecisionLogic(src)) return "decision";
1848
- if (isPlanLogic(src)) return "plan";
1761
+ return isDecisionLogic(src) ? "decision" : void 0;
1849
1762
  }
1850
1763
  function isAgentLogicNeedingBinding(src) {
1851
- return (isTextLogic(src) || isDecisionLogic(src) || isPlanLogic(src)) && !executorBoundLogics.has(src);
1764
+ return (isTextLogic(src) || isDecisionLogic(src)) && !executorBoundLogics.has(src);
1852
1765
  }
1853
1766
  function schemaExposesJson(schema) {
1854
1767
  if (!schema) return false;
@@ -2129,17 +2042,6 @@ async function simulateAgent(machine, options) {
2129
2042
  });
2130
2043
  continue;
2131
2044
  }
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
2045
  const taken = takeFromQueue(script.text, request.src);
2144
2046
  if (!taken.found) throw scriptDryError("text", request.src, request.id);
2145
2047
  step = resolveAgentStep(machine, step, request, taken.value);
@@ -2223,7 +2125,7 @@ async function explore(machine, options, stopWhen) {
2223
2125
  recordState(current.snapshot);
2224
2126
  continue;
2225
2127
  }
2226
- if (request && (request.kind === "decision" || request.kind === "plan")) return { step: current };
2128
+ if (request && request.kind === "decision") return { step: current };
2227
2129
  const [invoke] = pendingInvokes(current);
2228
2130
  if (invoke) {
2229
2131
  if (!(invoke.src in textOutputs)) return {
@@ -2270,8 +2172,7 @@ async function explore(machine, options, stopWhen) {
2270
2172
  return;
2271
2173
  }
2272
2174
  const request = settled.requests[0];
2273
- const isPlan = request?.kind === "plan";
2274
- const branchEvents = request?.kind === "decision" || request?.kind === "plan" ? request.events.map((descriptor) => ({ type: descriptor.type })) : getAcceptedEvents(settled.snapshot).map((descriptor) => ({ type: descriptor.type }));
2175
+ const branchEvents = request?.kind === "decision" ? request.events.map((descriptor) => ({ type: descriptor.type })) : getAcceptedEvents(settled.snapshot).map((descriptor) => ({ type: descriptor.type }));
2275
2176
  if (branchEvents.length === 0) {
2276
2177
  pathsExplored++;
2277
2178
  terminals.push({
@@ -2296,11 +2197,11 @@ async function explore(machine, options, stopWhen) {
2296
2197
  if (pathsExplored >= maxPaths) hitPathCap = true;
2297
2198
  return;
2298
2199
  }
2299
- if (!(isPlan && event.type === "agent.plan.done") && !settled.snapshot.can(event)) {
2200
+ if (!settled.snapshot.can(event)) {
2300
2201
  prunedByGuard++;
2301
2202
  continue;
2302
2203
  }
2303
- const next = isPlan ? await resolveAgentRequests(machine, settled, { decide: async () => ({ event }) }) : transitionAgentStep(machine, settled, event);
2204
+ const next = transitionAgentStep(machine, settled, event);
2304
2205
  recordState(next.snapshot);
2305
2206
  await visit(next, [...path, event], depth + 1);
2306
2207
  }
@@ -2323,10 +2224,7 @@ async function explore(machine, options, stopWhen) {
2323
2224
  * depth, model-free, and reports which states are reached and how each path
2324
2225
  * terminates. At each decision request it forks one branch per candidate event
2325
2226
  * (guard-rejected candidates are counted in `prunedByGuard`, not explored); at
2326
- * an idle wait it forks per externally-accepted event. A `agent.plan` request
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
2227
+ * an idle wait it forks per externally-accepted event. Text/`userInput` invokes
2330
2228
  * are resolved from `textOutputs` (a by-src canned-output map) — a missing src
2331
2229
  * halts that branch with a `needs-output` terminal rather than throwing.
2332
2230
  *
@@ -2796,4 +2694,4 @@ async function runSeam(machine, options) {
2796
2694
  };
2797
2695
  }
2798
2696
  //#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, PLAN_DONE_EVENT_TYPE, 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 };
2697
+ 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-DP95MFrI.cjs");
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";
@@ -1,4 +1,4 @@
1
- import { _ as StandardSchemaV1, c as AgentTools } from "./types-QbEfCVny.cjs";
1
+ import { c as AgentTools, v as StandardSchemaV1 } from "./types-DFD28AWe.cjs";
2
2
  import { AnyStateMachine } from "xstate";
3
3
 
4
4
  //#region src/machines/tool-loop.d.ts
@@ -1,4 +1,4 @@
1
- import { _ as StandardSchemaV1, c as AgentTools } from "./types-_FXoFBGO.mjs";
1
+ import { c as AgentTools, v as StandardSchemaV1 } from "./types-CTBhMnFu.mjs";
2
2
  import { AnyStateMachine } from "xstate";
3
3
 
4
4
  //#region src/machines/tool-loop.d.ts
package/dist/machines.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as setupAgent } from "./setup-agent-DAZZSjDS.mjs";
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/plan carry it on `input`, a decision inline. */
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/plan invoke was declared with; a decision has none. */
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": operation,
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 name = operation === "plan" ? `plan ${options.agentName ?? event.machineId}` : `chat ${model ?? request.kind}`;
186
- const span = tracer.startSpan(name, {
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
@@ -1,4 +1,4 @@
1
- import { c as AgentTraceEvent } from "./run-agent-DnvtcnTZ.cjs";
1
+ import { l as AgentTraceEvent } from "./run-agent-B_n4Qxye.cjs";
2
2
  import { Attributes, Tracer, TracerProvider } from "@opentelemetry/api";
3
3
 
4
4
  //#region src/otel/index.d.ts
package/dist/otel.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { c as AgentTraceEvent } from "./run-agent-C3mFDGTf.mjs";
1
+ import { l as AgentTraceEvent } from "./run-agent-BWzo4FLv.mjs";
2
2
  import { Attributes, Tracer, TracerProvider } from "@opentelemetry/api";
3
3
 
4
4
  //#region src/otel/index.d.ts
package/dist/otel.mjs CHANGED
@@ -32,23 +32,15 @@ function usageAttributes(usage) {
32
32
  }
33
33
  return attributes;
34
34
  }
35
- /** The model ref a request targets: text/plan carry it on `input`, a decision inline. */
35
+ /** The model ref a request targets: text carries it on `input`, a decision inline. */
36
36
  function requestModel(request) {
37
37
  const model = request.kind === "decision" ? request.model : request.input?.model;
38
38
  return typeof model === "string" ? model : void 0;
39
39
  }
40
- /** The `src` a text/plan invoke was declared with; a decision has none. */
40
+ /** The `src` a text invoke was declared with; a decision has none. */
41
41
  function requestSrc(request) {
42
42
  return "src" in request && typeof request.src === "string" ? request.src : void 0;
43
43
  }
44
- /**
45
- * `gen_ai.operation.name` for a request. A plan request drives the machine
46
- * through a sequence of events, which semconv names `plan`; text and decision
47
- * requests are both single chat completions.
48
- */
49
- function operationName(request) {
50
- return request.kind === "plan" ? "plan" : "chat";
51
- }
52
44
  /** Best-effort JSON, never throws — content capture must not break a run. */
53
45
  function toJson(value) {
54
46
  try {
@@ -161,10 +153,9 @@ function createOtelTraceHandler(options) {
161
153
  const request = event.request;
162
154
  endRequest(request.id, () => {});
163
155
  const model = requestModel(request);
164
- const operation = operationName(request);
165
156
  const attributes = {
166
157
  ...baseAttributes,
167
- "gen_ai.operation.name": operation,
158
+ "gen_ai.operation.name": "chat",
168
159
  "agent.run_id": event.runId,
169
160
  "agent.request_id": request.id,
170
161
  "agent.request_kind": request.kind
@@ -181,9 +172,8 @@ function createOtelTraceHandler(options) {
181
172
  const json = toJson(input.messages ?? input.prompt);
182
173
  if (json !== void 0) attributes["gen_ai.input.messages"] = json;
183
174
  }
184
- const name = operation === "plan" ? `plan ${options.agentName ?? event.machineId}` : `chat ${model ?? request.kind}`;
185
- const span = tracer.startSpan(name, {
186
- kind: operation === "plan" ? SpanKind.INTERNAL : SpanKind.CLIENT,
175
+ const span = tracer.startSpan(`chat ${model ?? request.kind}`, {
176
+ kind: SpanKind.CLIENT,
187
177
  attributes
188
178
  }, runFor(event).context);
189
179
  requests.set(request.id, {