@statelyai/agent 2.0.0-alpha.5 → 2.0.0-alpha.6
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.mjs +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/{decision-pC-bY2DE.cjs → decision-CX3YdwrO.cjs} +8 -0
- package/dist/{decision-FTmbqSEe.mjs → decision-D1654JdD.mjs} +3 -1
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +2 -2
- package/dist/openai-compat.cjs +1 -1
- package/dist/openai-compat.mjs +1 -1
- package/dist/{src-CjpHDU8F.mjs → src-CEa947Dm.mjs} +13 -9
- package/dist/{src-DcRsWPfV.cjs → src-wBfi-kTA.cjs} +13 -9
- package/package.json +1 -1
package/dist/ai-sdk.cjs
CHANGED
package/dist/ai-sdk.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { G as isStandardSchema, T as getAgentOutputMode, l as renderDecisionAttempts, x as buildEnvelopeSchema } from "./decision-D1654JdD.mjs";
|
|
2
2
|
import { Output, generateText, stepCountIs, streamText, tool } from "ai";
|
|
3
3
|
//#region src/ai-sdk/index.ts
|
|
4
4
|
/**
|
package/dist/cli.cjs
CHANGED
package/dist/cli.mjs
CHANGED
|
@@ -264,6 +264,8 @@ const GENERATE_TEXT_ACTOR = "agent.generateText";
|
|
|
264
264
|
const STREAM_TEXT_ACTOR = "agent.streamText";
|
|
265
265
|
const DECIDE_ACTOR = "agent.decide";
|
|
266
266
|
const PLAN_ACTOR = "agent.plan";
|
|
267
|
+
/** Synthetic `src` stamped on trace requests produced by `getRequests` state interpretation — NOT a registered actor source (nothing is invoked; the pass makes the call directly). */
|
|
268
|
+
const INTERPRET_SOURCE = "agent.interpret";
|
|
267
269
|
const agentTextInputSchema = { "~standard": {
|
|
268
270
|
version: 1,
|
|
269
271
|
vendor: "statelyai-agent",
|
|
@@ -953,6 +955,12 @@ Object.defineProperty(exports, "EVENT_TOOL_PREFIX", {
|
|
|
953
955
|
return EVENT_TOOL_PREFIX;
|
|
954
956
|
}
|
|
955
957
|
});
|
|
958
|
+
Object.defineProperty(exports, "INTERPRET_SOURCE", {
|
|
959
|
+
enumerable: true,
|
|
960
|
+
get: function() {
|
|
961
|
+
return INTERPRET_SOURCE;
|
|
962
|
+
}
|
|
963
|
+
});
|
|
956
964
|
Object.defineProperty(exports, "PLAN_ACTOR", {
|
|
957
965
|
enumerable: true,
|
|
958
966
|
get: function() {
|
|
@@ -264,6 +264,8 @@ const GENERATE_TEXT_ACTOR = "agent.generateText";
|
|
|
264
264
|
const STREAM_TEXT_ACTOR = "agent.streamText";
|
|
265
265
|
const DECIDE_ACTOR = "agent.decide";
|
|
266
266
|
const PLAN_ACTOR = "agent.plan";
|
|
267
|
+
/** Synthetic `src` stamped on trace requests produced by `getRequests` state interpretation — NOT a registered actor source (nothing is invoked; the pass makes the call directly). */
|
|
268
|
+
const INTERPRET_SOURCE = "agent.interpret";
|
|
267
269
|
const agentTextInputSchema = { "~standard": {
|
|
268
270
|
version: 1,
|
|
269
271
|
vendor: "statelyai-agent",
|
|
@@ -935,4 +937,4 @@ async function resolveDecision(request, executor, options = {}) {
|
|
|
935
937
|
throw new DecisionExhaustedError(attempts);
|
|
936
938
|
}
|
|
937
939
|
//#endregion
|
|
938
|
-
export {
|
|
940
|
+
export { userInputActor as A, getAgentMessages as B, createTextLogic as C, isTextLogic as D, isStructuredOutputSchema as E, isUnboundPlaceholder as F, isStandardSchema as G, getJsonSchemaSync as H, machineSuspensionPredicates as I, toolMessage as J, persistSnapshot as K, missingActor as L, executorBoundLogics as M, getMachineSuspensionPredicate as N, normalizeGeneratorResult as O, getRegisteredAgentExecutionOptions as P, assistantMessage as R, builtinTextActors as S, getAgentOutputMode as T, getMachineStructuralHash as U, getJsonSchema as V, getStateMeta as W, validateSchemaSync as X, userMessage as Y, INTERPRET_SOURCE as _, createPlanActor as a, bindRequestExecutor as b, isPlanLogic as c, EVENT_TOOL_PREFIX as d, getAcceptedEvents as f, DECIDE_ACTOR as g, sanitizeEventToolName as h, createDecideActor as i, agentExecutionOptions as j, parseOutput as k, renderDecisionAttempts as l, parseAgentEvent as m, PLAN_DONE_EVENT_TYPE as n, initialPlanLedger as o, matchesEventPattern as p, systemMessage as q, advancePlanLedger as r, isDecisionLogic as s, DecisionExhaustedError as t, resolveDecision as u, PLAN_ACTOR as v, executeAgentTextRequest as w, buildEnvelopeSchema as x, USER_INPUT_ACTOR as y, findNonSerializableContextPaths as z };
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_src = require("./src-
|
|
3
|
-
const require_decision = require("./decision-
|
|
2
|
+
const require_src = require("./src-wBfi-kTA.cjs");
|
|
3
|
+
const require_decision = require("./decision-CX3YdwrO.cjs");
|
|
4
4
|
exports.AgentIdleError = require_src.AgentIdleError;
|
|
5
5
|
exports.DecisionExhaustedError = require_decision.DecisionExhaustedError;
|
|
6
6
|
exports.EVENT_TOOL_PREFIX = require_decision.EVENT_TOOL_PREFIX;
|
package/dist/index.d.cts
CHANGED
|
@@ -842,7 +842,7 @@ interface RunAgentOptions<TMachine extends AnyStateMachine> {
|
|
|
842
842
|
* that sends no event settles idle. Every model call counts against
|
|
843
843
|
* `maxModelCalls`.
|
|
844
844
|
*/
|
|
845
|
-
getRequests?: (snapshot: SnapshotFrom<TMachine>,
|
|
845
|
+
getRequests?: (snapshot: SnapshotFrom<TMachine>, agentContext: {
|
|
846
846
|
messages: readonly AgentMessage[];
|
|
847
847
|
}) => AgentStateRequest | readonly AgentStateRequest[] | undefined;
|
|
848
848
|
/**
|
package/dist/index.d.mts
CHANGED
|
@@ -842,7 +842,7 @@ interface RunAgentOptions<TMachine extends AnyStateMachine> {
|
|
|
842
842
|
* that sends no event settles idle. Every model call counts against
|
|
843
843
|
* `maxModelCalls`.
|
|
844
844
|
*/
|
|
845
|
-
getRequests?: (snapshot: SnapshotFrom<TMachine>,
|
|
845
|
+
getRequests?: (snapshot: SnapshotFrom<TMachine>, agentContext: {
|
|
846
846
|
messages: readonly AgentMessage[];
|
|
847
847
|
}) => AgentStateRequest | readonly AgentStateRequest[] | undefined;
|
|
848
848
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { _ as createAgentSchemas, a as AgentIdleError, b as messagesSchema, c as inspectTransitions, d as executeAgentRequest, f as getAgentRequests, g as transitionAgentStep, h as resolveAgentStep, i as simulateAgent, l as runAgent, m as resolveAgentRequests, n as explorePaths, o as IllegalResumeEventError, p as initialAgentStep, r as lintAgentMachine, s as SnapshotVersionMismatchError, t as canReach, u as runAgentToCompletion, v as setupAgent, y as appendMessages } from "./src-
|
|
2
|
-
import { B as
|
|
1
|
+
import { _ as createAgentSchemas, a as AgentIdleError, b as messagesSchema, c as inspectTransitions, d as executeAgentRequest, f as getAgentRequests, g as transitionAgentStep, h as resolveAgentStep, i as simulateAgent, l as runAgent, m as resolveAgentRequests, n as explorePaths, o as IllegalResumeEventError, p as initialAgentStep, r as lintAgentMachine, s as SnapshotVersionMismatchError, t as canReach, u as runAgentToCompletion, v as setupAgent, y as appendMessages } from "./src-CEa947Dm.mjs";
|
|
2
|
+
import { B as getAgentMessages, C as createTextLogic, E as isStructuredOutputSchema, G as isStandardSchema, H as getJsonSchemaSync, J as toolMessage, K as persistSnapshot, R as assistantMessage, T as getAgentOutputMode, U as getMachineStructuralHash, V as getJsonSchema, W as getStateMeta, X as validateSchemaSync, Y as userMessage, b as bindRequestExecutor, d as EVENT_TOOL_PREFIX, f as getAcceptedEvents, k as parseOutput, l as renderDecisionAttempts, m as parseAgentEvent, n as PLAN_DONE_EVENT_TYPE, p as matchesEventPattern, q as systemMessage, t as DecisionExhaustedError, u as resolveDecision, x as buildEnvelopeSchema } from "./decision-D1654JdD.mjs";
|
|
3
3
|
export { AgentIdleError, DecisionExhaustedError, EVENT_TOOL_PREFIX, IllegalResumeEventError, PLAN_DONE_EVENT_TYPE, SnapshotVersionMismatchError, appendMessages, assistantMessage, bindRequestExecutor, buildEnvelopeSchema, canReach, createAgentSchemas, createTextLogic, executeAgentRequest, explorePaths, getAcceptedEvents, getAgentMessages, getAgentOutputMode, getAgentRequests, getJsonSchema, getJsonSchemaSync, getMachineStructuralHash, getStateMeta, initialAgentStep, inspectTransitions, isStandardSchema, isStructuredOutputSchema, lintAgentMachine, matchesEventPattern, messagesSchema, parseAgentEvent, parseOutput, persistSnapshot, renderDecisionAttempts, resolveAgentRequests, resolveAgentStep, resolveDecision, runAgent, runAgentToCompletion, setupAgent, simulateAgent, systemMessage, toolMessage, transitionAgentStep, userMessage, validateSchemaSync };
|
package/dist/openai-compat.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_decision = require("./decision-
|
|
2
|
+
const require_decision = require("./decision-CX3YdwrO.cjs");
|
|
3
3
|
//#region src/openai-compat/index.ts
|
|
4
4
|
/**
|
|
5
5
|
* OpenAI-compatible Chat Completions adapter — a COMPLETE `{ generateText,
|
package/dist/openai-compat.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { G as isStandardSchema, H as getJsonSchemaSync, T as getAgentOutputMode, V as getJsonSchema, l as renderDecisionAttempts, x as buildEnvelopeSchema } from "./decision-D1654JdD.mjs";
|
|
2
2
|
//#region src/openai-compat/index.ts
|
|
3
3
|
/**
|
|
4
4
|
* OpenAI-compatible Chat Completions adapter — a COMPLETE `{ generateText,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as userInputActor, B as getAgentMessages, C as createTextLogic, D as isTextLogic, F as isUnboundPlaceholder, H as getJsonSchemaSync, I as machineSuspensionPredicates, L as missingActor, M as executorBoundLogics, N as getMachineSuspensionPredicate, O as normalizeGeneratorResult, P as getRegisteredAgentExecutionOptions, R as assistantMessage, S as builtinTextActors, U as getMachineStructuralHash, X as validateSchemaSync, Y as userMessage, _ as INTERPRET_SOURCE, a as createPlanActor, c as isPlanLogic, f as getAcceptedEvents, g as DECIDE_ACTOR, h as sanitizeEventToolName, i as createDecideActor, j as agentExecutionOptions, n as PLAN_DONE_EVENT_TYPE, o as initialPlanLedger, r as advancePlanLedger, s as isDecisionLogic, t as DecisionExhaustedError, u as resolveDecision, v as PLAN_ACTOR, w as executeAgentTextRequest, y as USER_INPUT_ACTOR, z as findNonSerializableContextPaths } from "./decision-D1654JdD.mjs";
|
|
2
2
|
import { createActor, createAsyncLogic, getNextTransitions, initialTransition, setup, transition } from "xstate";
|
|
3
3
|
//#region src/messages.ts
|
|
4
4
|
function addMessages(resolve) {
|
|
@@ -840,7 +840,7 @@ async function runTextPhase(stateRequest, baseMessages, deps) {
|
|
|
840
840
|
const agentRequest = {
|
|
841
841
|
kind: "text",
|
|
842
842
|
id,
|
|
843
|
-
src:
|
|
843
|
+
src: INTERPRET_SOURCE,
|
|
844
844
|
mode: "generate",
|
|
845
845
|
input: request,
|
|
846
846
|
tools: {},
|
|
@@ -855,6 +855,8 @@ async function runTextPhase(stateRequest, baseMessages, deps) {
|
|
|
855
855
|
try {
|
|
856
856
|
const raw = await deps.generateText(request, { signal: deps.signal });
|
|
857
857
|
output = await normalizeGeneratorResult(raw, id, { request });
|
|
858
|
+
const rawReasoning = raw?.reasoning;
|
|
859
|
+
const reasoning = typeof rawReasoning === "string" ? rawReasoning : void 0;
|
|
858
860
|
deps.onResult?.(agentRequest, {
|
|
859
861
|
output,
|
|
860
862
|
raw
|
|
@@ -863,7 +865,8 @@ async function runTextPhase(stateRequest, baseMessages, deps) {
|
|
|
863
865
|
type: "request.end",
|
|
864
866
|
request: agentRequest,
|
|
865
867
|
output,
|
|
866
|
-
raw
|
|
868
|
+
raw,
|
|
869
|
+
...reasoning !== void 0 ? { reasoning } : {}
|
|
867
870
|
});
|
|
868
871
|
} catch (error) {
|
|
869
872
|
deps.onTrace?.({
|
|
@@ -916,8 +919,8 @@ async function runAdvancePhase(plan, deps) {
|
|
|
916
919
|
signal: deps.signal,
|
|
917
920
|
canTake: (event) => deps.getSnapshot().can(event)
|
|
918
921
|
});
|
|
919
|
-
deps.appendToLog(assistantMessage(`[chose: ${chosen.type}]`));
|
|
920
922
|
if (deps.isSettled()) return false;
|
|
923
|
+
deps.appendToLog(assistantMessage(`[chose: ${chosen.type}]`));
|
|
921
924
|
deps.send(chosen);
|
|
922
925
|
return true;
|
|
923
926
|
}
|
|
@@ -1571,10 +1574,10 @@ async function runAgent(machine, options) {
|
|
|
1571
1574
|
}
|
|
1572
1575
|
}
|
|
1573
1576
|
}
|
|
1574
|
-
const priorMessages = effectiveSnapshot
|
|
1577
|
+
const priorMessages = getAgentMessages(effectiveSnapshot);
|
|
1575
1578
|
const messages = typeof options.messages === "function" ? [...options.messages([...priorMessages])] : [...priorMessages, ...options.messages ?? []];
|
|
1576
1579
|
const stampMessages = (snapshot) => {
|
|
1577
|
-
if (!options.getRequests && !options.messages) return;
|
|
1580
|
+
if (!options.getRequests && !options.messages && messages.length === 0) return;
|
|
1578
1581
|
if (snapshot && typeof snapshot === "object") snapshot.messages = [...messages];
|
|
1579
1582
|
};
|
|
1580
1583
|
if (effectiveSnapshot !== void 0 && options.event !== void 0 && (options.onIllegalResumeEvent ?? "throw") === "throw") {
|
|
@@ -1631,10 +1634,11 @@ async function runAgent(machine, options) {
|
|
|
1631
1634
|
messages.push(...items);
|
|
1632
1635
|
if (options.onMessage) for (const item of items) options.onMessage(item);
|
|
1633
1636
|
};
|
|
1637
|
+
const runErrorCause = (error) => budgetExceeded ? "max-model-calls" : wrapsDecisionExhausted(error) ? "decision-exhausted" : "machine";
|
|
1634
1638
|
const settleInterpretError = (error) => {
|
|
1635
1639
|
settle({
|
|
1636
1640
|
status: "error",
|
|
1637
|
-
cause:
|
|
1641
|
+
cause: runErrorCause(error),
|
|
1638
1642
|
error,
|
|
1639
1643
|
snapshot: actor.getSnapshot()
|
|
1640
1644
|
});
|
|
@@ -1664,7 +1668,7 @@ async function runAgent(machine, options) {
|
|
|
1664
1668
|
settleInterpretError(error);
|
|
1665
1669
|
return true;
|
|
1666
1670
|
}
|
|
1667
|
-
const requests = (Array.isArray(requested) ? requested : requested ? [requested] : []).filter(Boolean);
|
|
1671
|
+
const requests = (Array.isArray(requested) ? requested : requested ? [requested] : []).filter((stateRequest) => Boolean(stateRequest));
|
|
1668
1672
|
if (requests.length === 0) return false;
|
|
1669
1673
|
interpreting = true;
|
|
1670
1674
|
runStateRequestPass(requests, passDeps).then(({ sentAny }) => {
|
|
@@ -1712,7 +1716,7 @@ async function runAgent(machine, options) {
|
|
|
1712
1716
|
if (snapshot.status === "error") {
|
|
1713
1717
|
settle({
|
|
1714
1718
|
status: "error",
|
|
1715
|
-
cause:
|
|
1719
|
+
cause: runErrorCause(snapshot.error),
|
|
1716
1720
|
error: snapshot.error,
|
|
1717
1721
|
snapshot
|
|
1718
1722
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_decision = require("./decision-
|
|
1
|
+
const require_decision = require("./decision-CX3YdwrO.cjs");
|
|
2
2
|
let xstate = require("xstate");
|
|
3
3
|
//#region src/messages.ts
|
|
4
4
|
function addMessages(resolve) {
|
|
@@ -840,7 +840,7 @@ async function runTextPhase(stateRequest, baseMessages, deps) {
|
|
|
840
840
|
const agentRequest = {
|
|
841
841
|
kind: "text",
|
|
842
842
|
id,
|
|
843
|
-
src:
|
|
843
|
+
src: require_decision.INTERPRET_SOURCE,
|
|
844
844
|
mode: "generate",
|
|
845
845
|
input: request,
|
|
846
846
|
tools: {},
|
|
@@ -855,6 +855,8 @@ async function runTextPhase(stateRequest, baseMessages, deps) {
|
|
|
855
855
|
try {
|
|
856
856
|
const raw = await deps.generateText(request, { signal: deps.signal });
|
|
857
857
|
output = await require_decision.normalizeGeneratorResult(raw, id, { request });
|
|
858
|
+
const rawReasoning = raw?.reasoning;
|
|
859
|
+
const reasoning = typeof rawReasoning === "string" ? rawReasoning : void 0;
|
|
858
860
|
deps.onResult?.(agentRequest, {
|
|
859
861
|
output,
|
|
860
862
|
raw
|
|
@@ -863,7 +865,8 @@ async function runTextPhase(stateRequest, baseMessages, deps) {
|
|
|
863
865
|
type: "request.end",
|
|
864
866
|
request: agentRequest,
|
|
865
867
|
output,
|
|
866
|
-
raw
|
|
868
|
+
raw,
|
|
869
|
+
...reasoning !== void 0 ? { reasoning } : {}
|
|
867
870
|
});
|
|
868
871
|
} catch (error) {
|
|
869
872
|
deps.onTrace?.({
|
|
@@ -916,8 +919,8 @@ async function runAdvancePhase(plan, deps) {
|
|
|
916
919
|
signal: deps.signal,
|
|
917
920
|
canTake: (event) => deps.getSnapshot().can(event)
|
|
918
921
|
});
|
|
919
|
-
deps.appendToLog(require_decision.assistantMessage(`[chose: ${chosen.type}]`));
|
|
920
922
|
if (deps.isSettled()) return false;
|
|
923
|
+
deps.appendToLog(require_decision.assistantMessage(`[chose: ${chosen.type}]`));
|
|
921
924
|
deps.send(chosen);
|
|
922
925
|
return true;
|
|
923
926
|
}
|
|
@@ -1571,10 +1574,10 @@ async function runAgent(machine, options) {
|
|
|
1571
1574
|
}
|
|
1572
1575
|
}
|
|
1573
1576
|
}
|
|
1574
|
-
const priorMessages = effectiveSnapshot
|
|
1577
|
+
const priorMessages = require_decision.getAgentMessages(effectiveSnapshot);
|
|
1575
1578
|
const messages = typeof options.messages === "function" ? [...options.messages([...priorMessages])] : [...priorMessages, ...options.messages ?? []];
|
|
1576
1579
|
const stampMessages = (snapshot) => {
|
|
1577
|
-
if (!options.getRequests && !options.messages) return;
|
|
1580
|
+
if (!options.getRequests && !options.messages && messages.length === 0) return;
|
|
1578
1581
|
if (snapshot && typeof snapshot === "object") snapshot.messages = [...messages];
|
|
1579
1582
|
};
|
|
1580
1583
|
if (effectiveSnapshot !== void 0 && options.event !== void 0 && (options.onIllegalResumeEvent ?? "throw") === "throw") {
|
|
@@ -1631,10 +1634,11 @@ async function runAgent(machine, options) {
|
|
|
1631
1634
|
messages.push(...items);
|
|
1632
1635
|
if (options.onMessage) for (const item of items) options.onMessage(item);
|
|
1633
1636
|
};
|
|
1637
|
+
const runErrorCause = (error) => budgetExceeded ? "max-model-calls" : wrapsDecisionExhausted(error) ? "decision-exhausted" : "machine";
|
|
1634
1638
|
const settleInterpretError = (error) => {
|
|
1635
1639
|
settle({
|
|
1636
1640
|
status: "error",
|
|
1637
|
-
cause:
|
|
1641
|
+
cause: runErrorCause(error),
|
|
1638
1642
|
error,
|
|
1639
1643
|
snapshot: actor.getSnapshot()
|
|
1640
1644
|
});
|
|
@@ -1664,7 +1668,7 @@ async function runAgent(machine, options) {
|
|
|
1664
1668
|
settleInterpretError(error);
|
|
1665
1669
|
return true;
|
|
1666
1670
|
}
|
|
1667
|
-
const requests = (Array.isArray(requested) ? requested : requested ? [requested] : []).filter(Boolean);
|
|
1671
|
+
const requests = (Array.isArray(requested) ? requested : requested ? [requested] : []).filter((stateRequest) => Boolean(stateRequest));
|
|
1668
1672
|
if (requests.length === 0) return false;
|
|
1669
1673
|
interpreting = true;
|
|
1670
1674
|
runStateRequestPass(requests, passDeps).then(({ sentAny }) => {
|
|
@@ -1712,7 +1716,7 @@ async function runAgent(machine, options) {
|
|
|
1712
1716
|
if (snapshot.status === "error") {
|
|
1713
1717
|
settle({
|
|
1714
1718
|
status: "error",
|
|
1715
|
-
cause:
|
|
1719
|
+
cause: runErrorCause(snapshot.error),
|
|
1716
1720
|
error: snapshot.error,
|
|
1717
1721
|
snapshot
|
|
1718
1722
|
});
|