@statelyai/agent 2.0.0-alpha.24 → 2.0.0-alpha.26
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 +30 -34
- package/dist/ai-sdk.d.cts +27 -31
- package/dist/ai-sdk.d.mts +27 -31
- package/dist/ai-sdk.mjs +27 -31
- package/dist/decision-CM9CYZ6t.cjs +519 -0
- package/dist/decision-DzSv1NpD.mjs +453 -0
- package/dist/event-log-store-Ba2fsc4E.mjs +576 -0
- package/dist/event-log-store-DQmImLYk.cjs +702 -0
- package/dist/event-log-store-DvOcs10J.d.cts +338 -0
- package/dist/event-log-store-DxyVgnas.d.mts +338 -0
- package/dist/index.cjs +429 -4272
- package/dist/index.d.cts +104 -1005
- package/dist/index.d.mts +104 -1005
- package/dist/index.mjs +389 -4202
- package/dist/log.cjs +392 -0
- package/dist/log.d.cts +32 -0
- package/dist/log.d.mts +32 -0
- package/dist/log.mjs +371 -0
- package/dist/machines.cjs +27 -16
- package/dist/machines.d.cts +1 -1
- package/dist/machines.d.mts +1 -1
- package/dist/machines.mjs +27 -16
- package/dist/openai.cjs +16 -15
- package/dist/openai.d.cts +9 -9
- package/dist/openai.d.mts +9 -9
- package/dist/openai.mjs +10 -9
- package/dist/otel.d.cts +1 -1
- package/dist/otel.d.mts +1 -1
- package/dist/{run-agent-Ck7Sa3Tb.d.mts → run-agent-BOfoJg5B.d.cts} +86 -387
- package/dist/{run-agent-DWqA8KiI.d.cts → run-agent-CG343kFs.d.mts} +86 -387
- package/dist/run-agent-Cb1-LS5P.cjs +1783 -0
- package/dist/run-agent-DvDQd4If.mjs +1669 -0
- package/dist/{setup-agent-CeO2fARv.mjs → setup-agent-CFW-jPI8.mjs} +9 -20
- package/dist/{setup-agent-Dl2VELLi.cjs → setup-agent-CPf7MxnG.cjs} +20 -37
- package/dist/testing.cjs +1088 -0
- package/dist/testing.d.cts +617 -0
- package/dist/testing.d.mts +617 -0
- package/dist/testing.mjs +1079 -0
- package/dist/{text-logic-DJBK3LbG.d.mts → text-logic-BFEOxyxv.d.cts} +71 -147
- package/dist/text-logic-Bl_ZRxDi.mjs +833 -0
- package/dist/text-logic-C8xyr6Ag.cjs +1091 -0
- package/dist/{text-logic-C7bSnH_B.d.cts → text-logic-hZSiRUo1.d.mts} +71 -147
- package/dist/{types-CjHk5OdH.d.cts → types-B1Qs2q3q.d.cts} +2 -1
- package/dist/{types-DWA6X9R-.d.mts → types-tA3SdczG.d.mts} +2 -1
- package/dist/usage-BdEjFuIi.mjs +5 -0
- package/dist/usage-efOQPdf_.cjs +10 -0
- package/dist/utils-C2DPqomn.d.mts +109 -0
- package/dist/utils-ceStNCOh.d.cts +109 -0
- package/package.json +26 -5
- package/readme.md +5 -3
- package/skills/generate-machine/SKILL.md +4 -6
- package/dist/decision-BBZ2jMO1.mjs +0 -1490
- package/dist/decision-Cv6SfNWl.cjs +0 -1856
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { E as setAgentExecutionOptions, T as missingActor, V as validateSchemaSync, b as getAgentExecutionOptions, n as DECIDE_ACTOR, o as builtinTextActors, s as createTextLogic, w as machineIdlePredicates } from "./text-logic-Bl_ZRxDi.mjs";
|
|
2
|
+
import { n as createDecideActor } from "./decision-DzSv1NpD.mjs";
|
|
3
|
+
import { t as AGENT_USAGE_EVENT_TYPE } from "./usage-BdEjFuIi.mjs";
|
|
2
4
|
import { createMachineFromConfig, setup } from "xstate";
|
|
3
|
-
//#region src/usage.ts
|
|
4
|
-
/** Reserved event delivered after a model call reports token usage. */
|
|
5
|
-
const AGENT_USAGE_EVENT_TYPE = "@agent.usage";
|
|
6
|
-
//#endregion
|
|
7
5
|
//#region src/workflow-config.ts
|
|
8
6
|
/**
|
|
9
7
|
* The machines-as-data lowering: `setupAgent(...).fromConfig(config, options)`.
|
|
@@ -396,12 +394,9 @@ const agentUsageEventSchema = { "~standard": {
|
|
|
396
394
|
function withAgentUsageEventSchema(events) {
|
|
397
395
|
const declared = events?.[AGENT_USAGE_EVENT_TYPE];
|
|
398
396
|
if (declared !== void 0 && declared !== agentUsageEventSchema) throw new Error(`setupAgent: event type '${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: { '${AGENT_USAGE_EVENT_TYPE}': … }.`);
|
|
399
|
-
const declaredMessages = events?.[AGENT_MESSAGES_EVENT_TYPE];
|
|
400
|
-
if (declaredMessages !== void 0 && declaredMessages !== agentMessagesEventSchema) throw new Error(`setupAgent: event type '${AGENT_MESSAGES_EVENT_TYPE}' is reserved and cannot be declared in 'events' — setupAgent registers it for you. Add a transition instead: on: { '${AGENT_MESSAGES_EVENT_TYPE}': appendMessages() }.`);
|
|
401
397
|
return {
|
|
402
398
|
...events,
|
|
403
|
-
[AGENT_USAGE_EVENT_TYPE]: agentUsageEventSchema
|
|
404
|
-
[AGENT_MESSAGES_EVENT_TYPE]: agentMessagesEventSchema
|
|
399
|
+
[AGENT_USAGE_EVENT_TYPE]: agentUsageEventSchema
|
|
405
400
|
};
|
|
406
401
|
}
|
|
407
402
|
function normalizeEventSchemas(events) {
|
|
@@ -432,11 +427,11 @@ function createAgentSchemas(schemas) {
|
|
|
432
427
|
* executors. Context, events, machine input, machine output, and
|
|
433
428
|
* state/transition meta are all standard schemas — no `{} as Type` casts —
|
|
434
429
|
* and are retained on `result.schemas` for runtime validation. Also
|
|
435
|
-
* registers the `agent.generateText`/`agent.streamText
|
|
430
|
+
* registers the `agent.generateText`/`agent.streamText`/
|
|
436
431
|
* `agent.decide` builtin actors and lowers `requests`/`actors` into the
|
|
437
432
|
* machine's actor sources. The result is the xstate `setup(...)` object with
|
|
438
433
|
* a wrapped `result.createMachine(...)` plus `result.schemas`/`models`/
|
|
439
|
-
* `requests
|
|
434
|
+
* `requests` attached. Also has a
|
|
440
435
|
* `setupAgent.fromConfig(...)` namespace member for building a machine from
|
|
441
436
|
* a serializable {@link AgentWorkflowConfig} instead of this TS API.
|
|
442
437
|
*
|
|
@@ -509,8 +504,7 @@ function setupAgent(config) {
|
|
|
509
504
|
},
|
|
510
505
|
schemas,
|
|
511
506
|
models,
|
|
512
|
-
requests: requestActors
|
|
513
|
-
appendMessages
|
|
507
|
+
requests: requestActors
|
|
514
508
|
});
|
|
515
509
|
}
|
|
516
510
|
function collectFinalStateOutputs(states, outputs = []) {
|
|
@@ -587,11 +581,7 @@ function assertStateSchemaKeysExist(stateSchemas, machineStates, path = []) {
|
|
|
587
581
|
if (stateSchema && typeof stateSchema === "object" && "states" in stateSchema && stateSchema.states) assertStateSchemaKeysExist(stateSchema.states, machineState.states, [...path, key]);
|
|
588
582
|
}
|
|
589
583
|
}
|
|
590
|
-
const RESERVED_AGENT_ACTOR_KEYS = [
|
|
591
|
-
...Object.keys(builtinTextActors),
|
|
592
|
-
USER_INPUT_ACTOR,
|
|
593
|
-
DECIDE_ACTOR
|
|
594
|
-
];
|
|
584
|
+
const RESERVED_AGENT_ACTOR_KEYS = [...Object.keys(builtinTextActors), DECIDE_ACTOR];
|
|
595
585
|
/**
|
|
596
586
|
* The whole `agent.` actor-source namespace is reserved for the library, not
|
|
597
587
|
* just the shipped builtins: a key starting with this prefix is rejected at
|
|
@@ -629,11 +619,10 @@ function createAgentActors(actors, requestActors) {
|
|
|
629
619
|
assertActorKeys(actors, requestActors);
|
|
630
620
|
return {
|
|
631
621
|
...builtinTextActors,
|
|
632
|
-
[USER_INPUT_ACTOR]: userInputActor,
|
|
633
622
|
[DECIDE_ACTOR]: createDecideActor(),
|
|
634
623
|
...actors,
|
|
635
624
|
...requestActors
|
|
636
625
|
};
|
|
637
626
|
}
|
|
638
627
|
//#endregion
|
|
639
|
-
export {
|
|
628
|
+
export { getAgentSchemas as n, setupAgent as r, createAgentSchemas as t };
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_text_logic = require("./text-logic-C8xyr6Ag.cjs");
|
|
2
|
+
const require_decision = require("./decision-CM9CYZ6t.cjs");
|
|
3
|
+
const require_usage = require("./usage-efOQPdf_.cjs");
|
|
2
4
|
require("./validate.cjs");
|
|
3
5
|
let xstate = require("xstate");
|
|
4
|
-
//#region src/usage.ts
|
|
5
|
-
/** Reserved event delivered after a model call reports token usage. */
|
|
6
|
-
const AGENT_USAGE_EVENT_TYPE = "@agent.usage";
|
|
7
|
-
//#endregion
|
|
8
6
|
//#region src/workflow-config.ts
|
|
9
7
|
/**
|
|
10
8
|
* The machines-as-data lowering: `setupAgent(...).fromConfig(config, options)`.
|
|
@@ -84,7 +82,7 @@ function createRequestsFromWorkflowConfig(config, compileSchema) {
|
|
|
84
82
|
}]));
|
|
85
83
|
}
|
|
86
84
|
function createActorPlaceholdersFromWorkflowConfig(config) {
|
|
87
|
-
return Object.fromEntries(Object.keys(config.actors ?? {}).map((key) => [key,
|
|
85
|
+
return Object.fromEntries(Object.keys(config.actors ?? {}).map((key) => [key, require_text_logic.missingActor(key)]));
|
|
88
86
|
}
|
|
89
87
|
const AGENT_EXPRESSION_LANG = "agent-template";
|
|
90
88
|
function containsTemplateExpression(value) {
|
|
@@ -105,7 +103,7 @@ function createWorkflowConfigEvaluator(contextSchema) {
|
|
|
105
103
|
};
|
|
106
104
|
return ({ source, slot, scope }) => {
|
|
107
105
|
const value = decode(source);
|
|
108
|
-
if (slot === "context") return
|
|
106
|
+
if (slot === "context") return require_text_logic.validateSchemaSync(contextSchema, evaluateWorkflowConfigValue(value, { input: scope.input }));
|
|
109
107
|
return evaluateWorkflowConfigValue(value, {
|
|
110
108
|
context: scope.context,
|
|
111
109
|
event: scope.event,
|
|
@@ -316,13 +314,13 @@ function setupAgentFromConfig(config, options) {
|
|
|
316
314
|
actors: Object.fromEntries(Object.keys(actors).map((key) => [key, key])),
|
|
317
315
|
evaluators: { [AGENT_EXPRESSION_LANG]: createWorkflowConfigEvaluator(schemas.context) }
|
|
318
316
|
}).provide({ actors });
|
|
319
|
-
|
|
317
|
+
require_text_logic.setAgentExecutionOptions(machine, {
|
|
320
318
|
schemas,
|
|
321
319
|
actors,
|
|
322
320
|
models: {}
|
|
323
321
|
});
|
|
324
322
|
const isIdle = resolveIdlePredicate(config, options);
|
|
325
|
-
if (isIdle && machine.config)
|
|
323
|
+
if (isIdle && machine.config) require_text_logic.machineIdlePredicates.set(machine.config, isIdle);
|
|
326
324
|
return {
|
|
327
325
|
machine,
|
|
328
326
|
schemas
|
|
@@ -395,14 +393,11 @@ const agentUsageEventSchema = { "~standard": {
|
|
|
395
393
|
* delivers.
|
|
396
394
|
*/
|
|
397
395
|
function withAgentUsageEventSchema(events) {
|
|
398
|
-
const declared = events?.[AGENT_USAGE_EVENT_TYPE];
|
|
399
|
-
if (declared !== void 0 && declared !== agentUsageEventSchema) throw new Error(`setupAgent: event type '${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: { '${AGENT_USAGE_EVENT_TYPE}': … }.`);
|
|
400
|
-
const declaredMessages = events?.[require_decision.AGENT_MESSAGES_EVENT_TYPE];
|
|
401
|
-
if (declaredMessages !== void 0 && declaredMessages !== require_decision.agentMessagesEventSchema) throw new Error(`setupAgent: event type '${require_decision.AGENT_MESSAGES_EVENT_TYPE}' is reserved and cannot be declared in 'events' — setupAgent registers it for you. Add a transition instead: on: { '${require_decision.AGENT_MESSAGES_EVENT_TYPE}': appendMessages() }.`);
|
|
396
|
+
const declared = events?.[require_usage.AGENT_USAGE_EVENT_TYPE];
|
|
397
|
+
if (declared !== void 0 && declared !== agentUsageEventSchema) throw new Error(`setupAgent: event type '${require_usage.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_usage.AGENT_USAGE_EVENT_TYPE}': … }.`);
|
|
402
398
|
return {
|
|
403
399
|
...events,
|
|
404
|
-
[AGENT_USAGE_EVENT_TYPE]: agentUsageEventSchema
|
|
405
|
-
[require_decision.AGENT_MESSAGES_EVENT_TYPE]: require_decision.agentMessagesEventSchema
|
|
400
|
+
[require_usage.AGENT_USAGE_EVENT_TYPE]: agentUsageEventSchema
|
|
406
401
|
};
|
|
407
402
|
}
|
|
408
403
|
function normalizeEventSchemas(events) {
|
|
@@ -433,11 +428,11 @@ function createAgentSchemas(schemas) {
|
|
|
433
428
|
* executors. Context, events, machine input, machine output, and
|
|
434
429
|
* state/transition meta are all standard schemas — no `{} as Type` casts —
|
|
435
430
|
* and are retained on `result.schemas` for runtime validation. Also
|
|
436
|
-
* registers the `agent.generateText`/`agent.streamText
|
|
431
|
+
* registers the `agent.generateText`/`agent.streamText`/
|
|
437
432
|
* `agent.decide` builtin actors and lowers `requests`/`actors` into the
|
|
438
433
|
* machine's actor sources. The result is the xstate `setup(...)` object with
|
|
439
434
|
* a wrapped `result.createMachine(...)` plus `result.schemas`/`models`/
|
|
440
|
-
* `requests
|
|
435
|
+
* `requests` attached. Also has a
|
|
441
436
|
* `setupAgent.fromConfig(...)` namespace member for building a machine from
|
|
442
437
|
* a serializable {@link AgentWorkflowConfig} instead of this TS API.
|
|
443
438
|
*
|
|
@@ -501,17 +496,16 @@ function setupAgent(config) {
|
|
|
501
496
|
createMachine(machineConfig) {
|
|
502
497
|
assertStateSchemaKeysExist(config.states, machineConfig?.states);
|
|
503
498
|
const machine = createBaseMachine(withRootOutputFromSingleFinal(machineConfig));
|
|
504
|
-
|
|
499
|
+
require_text_logic.setAgentExecutionOptions(machine, machineOptions);
|
|
505
500
|
if (config.isIdle) {
|
|
506
501
|
const rootConfig = machine.config;
|
|
507
|
-
if (rootConfig)
|
|
502
|
+
if (rootConfig) require_text_logic.machineIdlePredicates.set(rootConfig, config.isIdle);
|
|
508
503
|
}
|
|
509
504
|
return machine;
|
|
510
505
|
},
|
|
511
506
|
schemas,
|
|
512
507
|
models,
|
|
513
|
-
requests: requestActors
|
|
514
|
-
appendMessages: require_decision.appendMessages
|
|
508
|
+
requests: requestActors
|
|
515
509
|
});
|
|
516
510
|
}
|
|
517
511
|
function collectFinalStateOutputs(states, outputs = []) {
|
|
@@ -546,12 +540,12 @@ function withRootOutputFromSingleFinal(config) {
|
|
|
546
540
|
* on the machine's root `config`, which `.provide` shares by reference.
|
|
547
541
|
*/
|
|
548
542
|
function getAgentSchemas(machine) {
|
|
549
|
-
return
|
|
543
|
+
return require_text_logic.getAgentExecutionOptions(machine)?.schemas;
|
|
550
544
|
}
|
|
551
545
|
/** Builds one TextLogic actor per `setupAgent({ requests })` entry. @internal */
|
|
552
546
|
function createRequestActors(requests) {
|
|
553
547
|
return Object.fromEntries(Object.entries(requests).map(([key, request]) => {
|
|
554
|
-
return [key,
|
|
548
|
+
return [key, require_text_logic.createTextLogic({
|
|
555
549
|
...request,
|
|
556
550
|
name: key,
|
|
557
551
|
mode: request.mode ?? "generate"
|
|
@@ -588,11 +582,7 @@ function assertStateSchemaKeysExist(stateSchemas, machineStates, path = []) {
|
|
|
588
582
|
if (stateSchema && typeof stateSchema === "object" && "states" in stateSchema && stateSchema.states) assertStateSchemaKeysExist(stateSchema.states, machineState.states, [...path, key]);
|
|
589
583
|
}
|
|
590
584
|
}
|
|
591
|
-
const RESERVED_AGENT_ACTOR_KEYS = [
|
|
592
|
-
...Object.keys(require_decision.builtinTextActors),
|
|
593
|
-
require_decision.USER_INPUT_ACTOR,
|
|
594
|
-
require_decision.DECIDE_ACTOR
|
|
595
|
-
];
|
|
585
|
+
const RESERVED_AGENT_ACTOR_KEYS = [...Object.keys(require_text_logic.builtinTextActors), require_text_logic.DECIDE_ACTOR];
|
|
596
586
|
/**
|
|
597
587
|
* The whole `agent.` actor-source namespace is reserved for the library, not
|
|
598
588
|
* just the shipped builtins: a key starting with this prefix is rejected at
|
|
@@ -629,20 +619,13 @@ function assertActorKeys(actors, requests) {
|
|
|
629
619
|
function createAgentActors(actors, requestActors) {
|
|
630
620
|
assertActorKeys(actors, requestActors);
|
|
631
621
|
return {
|
|
632
|
-
...
|
|
633
|
-
[
|
|
634
|
-
[require_decision.DECIDE_ACTOR]: require_decision.createDecideActor(),
|
|
622
|
+
...require_text_logic.builtinTextActors,
|
|
623
|
+
[require_text_logic.DECIDE_ACTOR]: require_decision.createDecideActor(),
|
|
635
624
|
...actors,
|
|
636
625
|
...requestActors
|
|
637
626
|
};
|
|
638
627
|
}
|
|
639
628
|
//#endregion
|
|
640
|
-
Object.defineProperty(exports, "AGENT_USAGE_EVENT_TYPE", {
|
|
641
|
-
enumerable: true,
|
|
642
|
-
get: function() {
|
|
643
|
-
return AGENT_USAGE_EVENT_TYPE;
|
|
644
|
-
}
|
|
645
|
-
});
|
|
646
629
|
Object.defineProperty(exports, "createAgentSchemas", {
|
|
647
630
|
enumerable: true,
|
|
648
631
|
get: function() {
|