@statelyai/agent 2.0.0-alpha.28 → 2.0.0-alpha.30
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 +150 -27
- package/dist/ai-sdk.d.cts +59 -36
- package/dist/ai-sdk.d.mts +59 -36
- package/dist/ai-sdk.mjs +148 -24
- package/dist/{decision-RQ0iv0oZ.mjs → decision-BHkvuImD.mjs} +74 -8
- package/dist/{decision-CmM8-HHz.cjs → decision-CIb7ddIv.cjs} +113 -30
- package/dist/{text-logic-f5F5sCdc.cjs → event-log-BZRfBRd7.cjs} +814 -7
- package/dist/{text-logic-CIqHAmBi.mjs → event-log-DJCMHek_.mjs} +680 -4
- package/dist/{event-log-store-BIPOz-di.d.mts → event-log-store-CIIJohjj.d.mts} +90 -5
- package/dist/{event-log-store-2xzFmgr2.d.cts → event-log-store-CLAC9q2Y.d.cts} +90 -5
- package/dist/event-log-store-DZR4IIWe.cjs +95 -0
- package/dist/event-log-store-DsP6GCRh.mjs +84 -0
- package/dist/index.cjs +576 -58
- package/dist/index.d.cts +104 -510
- package/dist/index.d.mts +104 -510
- package/dist/index.mjs +547 -32
- package/dist/log.cjs +77 -20
- package/dist/log.d.cts +5 -5
- package/dist/log.d.mts +5 -5
- package/dist/log.mjs +58 -3
- package/dist/machines.cjs +1 -1
- package/dist/machines.d.cts +15 -15
- package/dist/machines.d.mts +15 -15
- package/dist/machines.mjs +1 -1
- package/dist/model-source-BCKg4qJ1.cjs +44 -0
- package/dist/model-source-BaHwJ1wK.mjs +39 -0
- package/dist/openai.cjs +11 -11
- package/dist/openai.d.cts +28 -26
- package/dist/openai.d.mts +28 -26
- package/dist/openai.mjs +3 -3
- package/dist/otel.cjs +5 -4
- package/dist/otel.d.cts +5 -7
- package/dist/otel.d.mts +5 -7
- package/dist/otel.mjs +5 -3
- package/dist/{run-agent-xNTxpt82.mjs → run-agent-BpHqkaZw.mjs} +181 -44
- package/dist/{run-agent-COXXc0RW.d.mts → run-agent-CAVt5R-r.d.mts} +95 -30
- package/dist/{run-agent-ByO-Bxyd.d.cts → run-agent-CTlMc3Jb.d.cts} +95 -30
- package/dist/{run-agent-Dmf8GV2d.cjs → run-agent-ctLCvNgL.cjs} +230 -88
- package/dist/{setup-agent-BuanDXeh.mjs → setup-agent-7rV_cujV.mjs} +15 -9
- package/dist/setup-agent-CGELn1qZ.d.mts +577 -0
- package/dist/setup-agent-CLPCkXsu.d.cts +577 -0
- package/dist/{setup-agent-DV4cTou-.cjs → setup-agent-DoUk7EdC.cjs} +31 -20
- package/dist/tanstack-ai.cjs +627 -0
- package/dist/tanstack-ai.d.cts +204 -0
- package/dist/tanstack-ai.d.mts +204 -0
- package/dist/tanstack-ai.mjs +618 -0
- package/dist/testing.cjs +204 -985
- package/dist/testing.d.cts +132 -347
- package/dist/testing.d.mts +132 -347
- package/dist/testing.mjs +191 -973
- package/dist/{text-logic-IjfYy9DP.d.cts → text-logic-BRYOPWvY.d.mts} +52 -12
- package/dist/{text-logic-D-czVPYp.d.mts → text-logic-DmciuVUQ.d.cts} +52 -12
- package/dist/{types-BgNbNKnJ.d.mts → types-Dp5_Ru4R.d.cts} +2 -2
- package/dist/{types-hR5f5YXa.d.cts → types-Dp5_Ru4R.d.mts} +2 -2
- package/dist/usage-BkM3z02Y.d.mts +17 -0
- package/dist/usage-Cm_ovz9V.d.cts +17 -0
- package/dist/{utils-_q7F-AZu.d.mts → utils-BnXdWih3.d.mts} +1 -2
- package/dist/{utils-o4YRdHJX.d.cts → utils-ebVpCYoF.d.cts} +1 -2
- package/dist/validate.cjs +239 -8
- package/dist/validate.d.cts +110 -3
- package/dist/validate.d.mts +110 -3
- package/dist/validate.mjs +238 -7
- package/dist/verify-COFWyprJ.mjs +1181 -0
- package/dist/verify-CVlsTZ-V.cjs +1222 -0
- package/dist/verify-Cn86rT8l.d.mts +414 -0
- package/dist/verify-Dzwd4Mvk.d.cts +414 -0
- package/package.json +44 -31
- package/readme.md +40 -28
- package/skills/add-evals/SKILL.md +129 -0
- package/skills/add-traces/SKILL.md +135 -0
- package/skills/generate-machine/SKILL.md +143 -69
- package/skills/graph-engineering/SKILL.md +33 -0
- package/skills/improve-machine/SKILL.md +241 -0
- package/skills/improve-machine/reference.md +101 -0
- package/skills/loop-to-machine/SKILL.md +183 -0
- package/skills/loop-to-machine/policy.md +158 -0
- package/dist/event-log-store-2pAFiWuc.mjs +0 -576
- package/dist/event-log-store-C-COhIXP.cjs +0 -702
- package/dist/usage-BdEjFuIi.mjs +0 -5
- package/dist/usage-efOQPdf_.cjs +0 -10
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
const
|
|
2
|
-
const require_decision = require("./decision-
|
|
3
|
-
const require_usage = require("./usage-efOQPdf_.cjs");
|
|
4
|
-
require("./validate.cjs");
|
|
1
|
+
const require_event_log = require("./event-log-BZRfBRd7.cjs");
|
|
2
|
+
const require_decision = require("./decision-CIb7ddIv.cjs");
|
|
5
3
|
let xstate = require("xstate");
|
|
6
4
|
//#region src/workflow-config.ts
|
|
7
5
|
/**
|
|
@@ -82,7 +80,7 @@ function createRequestsFromWorkflowConfig(config, compileSchema) {
|
|
|
82
80
|
}]));
|
|
83
81
|
}
|
|
84
82
|
function createActorPlaceholdersFromWorkflowConfig(config) {
|
|
85
|
-
return Object.fromEntries(Object.keys(config.actors ?? {}).map((key) => [key,
|
|
83
|
+
return Object.fromEntries(Object.keys(config.actors ?? {}).map((key) => [key, require_event_log.missingActor(key)]));
|
|
86
84
|
}
|
|
87
85
|
const AGENT_EXPRESSION_LANG = "agent-template";
|
|
88
86
|
function containsTemplateExpression(value) {
|
|
@@ -103,7 +101,7 @@ function createWorkflowConfigEvaluator(contextSchema) {
|
|
|
103
101
|
};
|
|
104
102
|
return ({ source, slot, scope }) => {
|
|
105
103
|
const value = decode(source);
|
|
106
|
-
if (slot === "context") return
|
|
104
|
+
if (slot === "context") return require_event_log.validateSchemaSync(contextSchema, evaluateWorkflowConfigValue(value, { input: scope.input }));
|
|
107
105
|
return evaluateWorkflowConfigValue(value, {
|
|
108
106
|
context: scope.context,
|
|
109
107
|
event: scope.event,
|
|
@@ -286,7 +284,8 @@ function setupAgentFromConfig(config, options) {
|
|
|
286
284
|
syntheticGuards: {},
|
|
287
285
|
transitionTargets: {}
|
|
288
286
|
};
|
|
289
|
-
const
|
|
287
|
+
const json = translateWorkflowConfig(config, translation);
|
|
288
|
+
const machine = (0, xstate.machineFromJSON)(json, {
|
|
290
289
|
guards: Object.fromEntries(Object.entries({
|
|
291
290
|
...translation.guards,
|
|
292
291
|
...translation.syntheticGuards
|
|
@@ -298,7 +297,7 @@ function setupAgentFromConfig(config, options) {
|
|
|
298
297
|
actors,
|
|
299
298
|
evaluators: { [AGENT_EXPRESSION_LANG]: createWorkflowConfigEvaluator(schemas.context) }
|
|
300
299
|
});
|
|
301
|
-
|
|
300
|
+
require_event_log.setAgentExecutionOptions(machine, {
|
|
302
301
|
schemas,
|
|
303
302
|
actors,
|
|
304
303
|
models: {}
|
|
@@ -315,7 +314,12 @@ const emptyEventSchema = { "~standard": {
|
|
|
315
314
|
vendor: "statelyai-agent",
|
|
316
315
|
validate(value) {
|
|
317
316
|
return value !== null && typeof value === "object" && Object.keys(value).length === 0 ? { value: {} } : { issues: [{ message: "Expected an empty event payload" }] };
|
|
318
|
-
}
|
|
317
|
+
},
|
|
318
|
+
jsonSchema: { input: () => ({
|
|
319
|
+
type: "object",
|
|
320
|
+
properties: {},
|
|
321
|
+
additionalProperties: false
|
|
322
|
+
}) }
|
|
319
323
|
} };
|
|
320
324
|
const USAGE_TOKEN_FIELDS = [
|
|
321
325
|
"inputTokens",
|
|
@@ -375,11 +379,11 @@ const agentUsageEventSchema = { "~standard": {
|
|
|
375
379
|
* delivers.
|
|
376
380
|
*/
|
|
377
381
|
function withAgentUsageEventSchema(events) {
|
|
378
|
-
const declared = events?.[
|
|
379
|
-
if (declared !== void 0 && declared !== agentUsageEventSchema) throw new Error(`setupAgent: event type '${
|
|
382
|
+
const declared = events?.[require_event_log.AGENT_USAGE_EVENT_TYPE];
|
|
383
|
+
if (declared !== void 0 && declared !== agentUsageEventSchema) throw new Error(`setupAgent: event type '${require_event_log.AGENT_USAGE_EVENT_TYPE}' is in the reserved '@agent.' namespace and cannot be declared in 'events' — setupAgent registers it for you with the usage payload schema. Remove it from 'events'; to receive it, declare a transition instead: on: { '${require_event_log.AGENT_USAGE_EVENT_TYPE}': … }.`);
|
|
380
384
|
return {
|
|
381
385
|
...events,
|
|
382
|
-
[
|
|
386
|
+
[require_event_log.AGENT_USAGE_EVENT_TYPE]: agentUsageEventSchema
|
|
383
387
|
};
|
|
384
388
|
}
|
|
385
389
|
function normalizeEventSchemas(events) {
|
|
@@ -452,7 +456,7 @@ function setupAgent(config) {
|
|
|
452
456
|
const schemas = normalizeAgentSchemas(config);
|
|
453
457
|
const requestActors = createRequestActors(config.requests ?? {});
|
|
454
458
|
const actors = createAgentActors(config.actors, requestActors);
|
|
455
|
-
const
|
|
459
|
+
const setupConfig = {
|
|
456
460
|
schemas: {
|
|
457
461
|
context: schemas.context,
|
|
458
462
|
events: schemas.events,
|
|
@@ -466,7 +470,8 @@ function setupAgent(config) {
|
|
|
466
470
|
actions: config.actions,
|
|
467
471
|
guards: config.guards,
|
|
468
472
|
delays: config.delays
|
|
469
|
-
}
|
|
473
|
+
};
|
|
474
|
+
const base = (0, xstate.setup)(setupConfig);
|
|
470
475
|
const createBaseMachine = base.createMachine.bind(base);
|
|
471
476
|
const models = config.models ?? {};
|
|
472
477
|
const machineOptions = {
|
|
@@ -478,7 +483,7 @@ function setupAgent(config) {
|
|
|
478
483
|
createMachine(machineConfig) {
|
|
479
484
|
assertStateSchemaKeysExist(config.states, machineConfig?.states);
|
|
480
485
|
const machine = createBaseMachine(withRootOutputFromSingleFinal(machineConfig));
|
|
481
|
-
|
|
486
|
+
require_event_log.setAgentExecutionOptions(machine, machineOptions);
|
|
482
487
|
return machine;
|
|
483
488
|
},
|
|
484
489
|
schemas,
|
|
@@ -518,12 +523,12 @@ function withRootOutputFromSingleFinal(config) {
|
|
|
518
523
|
* on the machine's root `config`, which `.provide` shares by reference.
|
|
519
524
|
*/
|
|
520
525
|
function getAgentSchemas(machine) {
|
|
521
|
-
return
|
|
526
|
+
return require_event_log.getAgentExecutionOptions(machine)?.schemas;
|
|
522
527
|
}
|
|
523
528
|
/** Builds one TextLogic actor per `setupAgent({ requests })` entry. @internal */
|
|
524
529
|
function createRequestActors(requests) {
|
|
525
530
|
return Object.fromEntries(Object.entries(requests).map(([key, request]) => {
|
|
526
|
-
return [key,
|
|
531
|
+
return [key, require_event_log.createTextLogic({
|
|
527
532
|
...request,
|
|
528
533
|
name: key,
|
|
529
534
|
mode: request.mode ?? "generate"
|
|
@@ -560,7 +565,7 @@ function assertStateSchemaKeysExist(stateSchemas, machineStates, path = []) {
|
|
|
560
565
|
if (stateSchema && typeof stateSchema === "object" && "states" in stateSchema && stateSchema.states) assertStateSchemaKeysExist(stateSchema.states, machineState.states, [...path, key]);
|
|
561
566
|
}
|
|
562
567
|
}
|
|
563
|
-
const RESERVED_AGENT_ACTOR_KEYS = [...Object.keys(
|
|
568
|
+
const RESERVED_AGENT_ACTOR_KEYS = [...Object.keys(require_event_log.builtinTextActors), require_event_log.DECIDE_ACTOR];
|
|
564
569
|
/**
|
|
565
570
|
* The whole `agent.` actor-source namespace is reserved for the library, not
|
|
566
571
|
* just the shipped builtins: a key starting with this prefix is rejected at
|
|
@@ -597,8 +602,8 @@ function assertActorKeys(actors, requests) {
|
|
|
597
602
|
function createAgentActors(actors, requestActors) {
|
|
598
603
|
assertActorKeys(actors, requestActors);
|
|
599
604
|
return {
|
|
600
|
-
...
|
|
601
|
-
[
|
|
605
|
+
...require_event_log.builtinTextActors,
|
|
606
|
+
[require_event_log.DECIDE_ACTOR]: require_decision.createDecideActor(),
|
|
602
607
|
...actors,
|
|
603
608
|
...requestActors
|
|
604
609
|
};
|
|
@@ -622,3 +627,9 @@ Object.defineProperty(exports, "setupAgent", {
|
|
|
622
627
|
return setupAgent;
|
|
623
628
|
}
|
|
624
629
|
});
|
|
630
|
+
Object.defineProperty(exports, "setupAgentFromConfig", {
|
|
631
|
+
enumerable: true,
|
|
632
|
+
get: function() {
|
|
633
|
+
return setupAgentFromConfig;
|
|
634
|
+
}
|
|
635
|
+
});
|