@statelyai/agent 2.0.0-alpha.18 → 2.0.0-alpha.19
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 +4 -2
- package/dist/ai-sdk.d.cts +1 -1
- package/dist/ai-sdk.d.mts +1 -1
- package/dist/ai-sdk.mjs +3 -2
- package/dist/{decision-C11xuud2.mjs → decision-DsIkEuHz.mjs} +48 -28
- package/dist/{decision-DnQCQPew.cjs → decision-t26zsnSR.cjs} +64 -43
- package/dist/{event-log-store-CQJq8_v4.d.cts → event-log-store-Bz7HDBkE.d.cts} +11 -12
- package/dist/{event-log-store-B-1fcfkT.mjs → event-log-store-DmIDosD6.mjs} +22 -14
- package/dist/{event-log-store-yquOV1TX.cjs → event-log-store-a_TKy1gk.cjs} +22 -14
- package/dist/{event-log-store-BrC9Q1xW.d.mts → event-log-store-hrA1vqtN.d.mts} +11 -12
- package/dist/index.cjs +265 -109
- package/dist/index.d.cts +136 -80
- package/dist/index.d.mts +136 -80
- package/dist/index.mjs +262 -107
- package/dist/machines.cjs +13 -17
- package/dist/machines.d.cts +14 -17
- package/dist/machines.d.mts +14 -17
- package/dist/machines.mjs +13 -17
- package/dist/otel.cjs +1 -0
- package/dist/otel.d.cts +1 -1
- package/dist/otel.d.mts +1 -1
- package/dist/{run-agent-r9OD4z8F.d.cts → run-agent--4bbms-D.d.cts} +121 -48
- package/dist/{run-agent-DQIDikfd.d.mts → run-agent-CwmzAZwj.d.mts} +121 -48
- package/dist/{setup-agent-C3ETi_HZ.cjs → setup-agent-BFA4VKpN.cjs} +31 -33
- package/dist/{setup-agent-BrE2zFDy.mjs → setup-agent-CPFPN06s.mjs} +31 -28
- package/dist/sqlite.cjs +3 -9
- package/dist/sqlite.d.cts +1 -1
- package/dist/sqlite.d.mts +1 -1
- package/dist/sqlite.mjs +3 -9
- package/dist/{text-logic-VcWqO-Cl.d.cts → text-logic-Cavva1W6.d.cts} +24 -8
- package/dist/{text-logic-RvnlD-An.d.mts → text-logic-Er5KkTX6.d.mts} +24 -8
- package/dist/validate.cjs +436 -0
- package/dist/validate.d.cts +31 -0
- package/dist/validate.d.mts +31 -0
- package/dist/validate.mjs +411 -0
- package/package.json +15 -1
- package/schemas/agent-workflow.json +2 -2
- package/skills/generate-machine/SKILL.md +12 -14
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
//#endregion
|
|
24
|
+
let ajv_dist_2020_js = require("ajv/dist/2020.js");
|
|
25
|
+
ajv_dist_2020_js = __toESM(ajv_dist_2020_js);
|
|
26
|
+
//#region schemas/agent-workflow.json
|
|
27
|
+
var agent_workflow_default = {
|
|
28
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
29
|
+
$id: "https://stately.ai/schemas/agent-workflow.json",
|
|
30
|
+
title: "Stately Agent Workflow Definition",
|
|
31
|
+
description: "Static, declarative agent workflow definition that can be lowered to a setupAgent(...) XState machine.",
|
|
32
|
+
type: "object",
|
|
33
|
+
required: ["initial", "states"],
|
|
34
|
+
properties: {
|
|
35
|
+
"$schema": {
|
|
36
|
+
"description": "JSON Schema reference an editor attaches to the config file. Ignored by the lowering.",
|
|
37
|
+
"type": "string"
|
|
38
|
+
},
|
|
39
|
+
"key": {
|
|
40
|
+
"description": "Stable workflow key used by tools, storage, and visual editors.",
|
|
41
|
+
"type": "string",
|
|
42
|
+
"minLength": 1
|
|
43
|
+
},
|
|
44
|
+
"id": {
|
|
45
|
+
"description": "Optional XState machine id.",
|
|
46
|
+
"type": "string",
|
|
47
|
+
"minLength": 1
|
|
48
|
+
},
|
|
49
|
+
"version": {
|
|
50
|
+
"description": "Definition version chosen by the author.",
|
|
51
|
+
"type": "string"
|
|
52
|
+
},
|
|
53
|
+
"description": { "type": "string" },
|
|
54
|
+
"schemas": { "$ref": "#/$defs/AgentSchemas" },
|
|
55
|
+
"context": {
|
|
56
|
+
"description": "Initial XState context. Values may be JSON literals or whole-string {{ }} expressions evaluated with machine input.",
|
|
57
|
+
"$ref": "#/$defs/ExpressionObject"
|
|
58
|
+
},
|
|
59
|
+
"requests": {
|
|
60
|
+
"description": "Named model requests that become typed invoke sources.",
|
|
61
|
+
"type": "object",
|
|
62
|
+
"propertyNames": { "$ref": "#/$defs/Identifier" },
|
|
63
|
+
"additionalProperties": { "$ref": "#/$defs/Request" },
|
|
64
|
+
"default": {}
|
|
65
|
+
},
|
|
66
|
+
"actors": {
|
|
67
|
+
"description": "Placeholder actor sources declared by key. JSON wires no execution; provide the logic via machine.provide({ actors }) after setupAgent.fromConfig(...).",
|
|
68
|
+
"type": "object",
|
|
69
|
+
"propertyNames": { "$ref": "#/$defs/Identifier" },
|
|
70
|
+
"additionalProperties": { "$ref": "#/$defs/Actor" },
|
|
71
|
+
"default": {}
|
|
72
|
+
},
|
|
73
|
+
"initial": {
|
|
74
|
+
"description": "Initial child state key.",
|
|
75
|
+
"type": "string"
|
|
76
|
+
},
|
|
77
|
+
"states": {
|
|
78
|
+
"description": "Root state nodes.",
|
|
79
|
+
"type": "object",
|
|
80
|
+
"minProperties": 1,
|
|
81
|
+
"propertyNames": { "$ref": "#/$defs/Identifier" },
|
|
82
|
+
"additionalProperties": { "$ref": "#/$defs/State" }
|
|
83
|
+
},
|
|
84
|
+
"idleTags": {
|
|
85
|
+
"description": "State tags that mark an intentional wait for an external event (a human approval, an inbound webhook, ...). Lowered by setupAgent.fromConfig(...) into a snapshot.hasTag(...) idle predicate so runAgent settles those states idle deterministically. Every listed tag must appear in some state's 'tags'.",
|
|
86
|
+
"type": "array",
|
|
87
|
+
"items": {
|
|
88
|
+
"type": "string",
|
|
89
|
+
"minLength": 1
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
"meta": { "$ref": "#/$defs/JsonObject" }
|
|
93
|
+
},
|
|
94
|
+
additionalProperties: false,
|
|
95
|
+
$defs: {
|
|
96
|
+
"Identifier": {
|
|
97
|
+
"type": "string",
|
|
98
|
+
"minLength": 1,
|
|
99
|
+
"pattern": "^[A-Za-z_$][A-Za-z0-9_$.-]*$"
|
|
100
|
+
},
|
|
101
|
+
"ExpressionString": {
|
|
102
|
+
"description": "Whole-string expression delimited by {{ }}.",
|
|
103
|
+
"type": "string",
|
|
104
|
+
"pattern": "^\\{\\{[\\s\\S]*\\}\\}$"
|
|
105
|
+
},
|
|
106
|
+
"TemplateString": {
|
|
107
|
+
"description": "String that may contain {{ }} template expressions. Escape literal delimiters according to the selected expression/template evaluator.",
|
|
108
|
+
"type": "string"
|
|
109
|
+
},
|
|
110
|
+
"JsonValue": { "anyOf": [
|
|
111
|
+
{ "type": "null" },
|
|
112
|
+
{ "type": "boolean" },
|
|
113
|
+
{ "type": "number" },
|
|
114
|
+
{ "type": "string" },
|
|
115
|
+
{
|
|
116
|
+
"type": "array",
|
|
117
|
+
"items": { "$ref": "#/$defs/JsonValue" }
|
|
118
|
+
},
|
|
119
|
+
{ "$ref": "#/$defs/JsonObject" }
|
|
120
|
+
] },
|
|
121
|
+
"JsonObject": {
|
|
122
|
+
"type": "object",
|
|
123
|
+
"propertyNames": { "type": "string" },
|
|
124
|
+
"additionalProperties": { "$ref": "#/$defs/JsonValue" }
|
|
125
|
+
},
|
|
126
|
+
"ExpressionValue": {
|
|
127
|
+
"description": "JSON value or whole-string {{ }} expression. Use this for typed values, not prompt templating.",
|
|
128
|
+
"anyOf": [
|
|
129
|
+
{ "$ref": "#/$defs/ExpressionString" },
|
|
130
|
+
{ "type": "null" },
|
|
131
|
+
{ "type": "boolean" },
|
|
132
|
+
{ "type": "number" },
|
|
133
|
+
{ "type": "string" },
|
|
134
|
+
{
|
|
135
|
+
"type": "array",
|
|
136
|
+
"items": { "$ref": "#/$defs/ExpressionValue" }
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
"type": "object",
|
|
140
|
+
"propertyNames": { "type": "string" },
|
|
141
|
+
"additionalProperties": { "$ref": "#/$defs/ExpressionValue" }
|
|
142
|
+
}
|
|
143
|
+
]
|
|
144
|
+
},
|
|
145
|
+
"ExpressionObject": {
|
|
146
|
+
"type": "object",
|
|
147
|
+
"propertyNames": { "type": "string" },
|
|
148
|
+
"additionalProperties": { "$ref": "#/$defs/ExpressionValue" }
|
|
149
|
+
},
|
|
150
|
+
"JsonSchema": {
|
|
151
|
+
"description": "JSON Schema object.",
|
|
152
|
+
"type": "object",
|
|
153
|
+
"propertyNames": { "type": "string" },
|
|
154
|
+
"additionalProperties": true
|
|
155
|
+
},
|
|
156
|
+
"AgentSchemas": {
|
|
157
|
+
"type": "object",
|
|
158
|
+
"properties": {
|
|
159
|
+
"input": { "$ref": "#/$defs/JsonSchema" },
|
|
160
|
+
"context": { "$ref": "#/$defs/JsonSchema" },
|
|
161
|
+
"events": {
|
|
162
|
+
"type": "object",
|
|
163
|
+
"propertyNames": { "$ref": "#/$defs/Identifier" },
|
|
164
|
+
"additionalProperties": { "$ref": "#/$defs/JsonSchema" }
|
|
165
|
+
},
|
|
166
|
+
"emitted": {
|
|
167
|
+
"type": "object",
|
|
168
|
+
"description": "Schemas for events emitted outward by emit actions, keyed by emitted event type.",
|
|
169
|
+
"propertyNames": { "$ref": "#/$defs/Identifier" },
|
|
170
|
+
"additionalProperties": { "$ref": "#/$defs/JsonSchema" }
|
|
171
|
+
},
|
|
172
|
+
"output": { "$ref": "#/$defs/JsonSchema" },
|
|
173
|
+
"meta": { "$ref": "#/$defs/JsonSchema" }
|
|
174
|
+
},
|
|
175
|
+
"additionalProperties": false
|
|
176
|
+
},
|
|
177
|
+
"Request": {
|
|
178
|
+
"type": "object",
|
|
179
|
+
"required": [
|
|
180
|
+
"model",
|
|
181
|
+
"input",
|
|
182
|
+
"output"
|
|
183
|
+
],
|
|
184
|
+
"properties": {
|
|
185
|
+
"mode": {
|
|
186
|
+
"type": "string",
|
|
187
|
+
"enum": ["generate", "stream"],
|
|
188
|
+
"default": "generate"
|
|
189
|
+
},
|
|
190
|
+
"description": { "type": "string" },
|
|
191
|
+
"model": { "$ref": "#/$defs/TemplateString" },
|
|
192
|
+
"system": { "$ref": "#/$defs/TemplateString" },
|
|
193
|
+
"prompt": { "$ref": "#/$defs/TemplateString" },
|
|
194
|
+
"messages": { "anyOf": [{ "$ref": "#/$defs/ExpressionString" }, {
|
|
195
|
+
"type": "array",
|
|
196
|
+
"items": { "$ref": "#/$defs/Message" }
|
|
197
|
+
}] },
|
|
198
|
+
"input": { "$ref": "#/$defs/JsonSchema" },
|
|
199
|
+
"output": { "$ref": "#/$defs/JsonSchema" },
|
|
200
|
+
"tools": {
|
|
201
|
+
"type": "object",
|
|
202
|
+
"propertyNames": { "$ref": "#/$defs/Identifier" },
|
|
203
|
+
"additionalProperties": { "$ref": "#/$defs/Tool" }
|
|
204
|
+
},
|
|
205
|
+
"toolChoice": {
|
|
206
|
+
"description": "Passed to the provider as-is; unlike other request fields it is NOT template-evaluated, so {{ }} expressions are not allowed here.",
|
|
207
|
+
"anyOf": [{
|
|
208
|
+
"type": "string",
|
|
209
|
+
"enum": [
|
|
210
|
+
"auto",
|
|
211
|
+
"none",
|
|
212
|
+
"required"
|
|
213
|
+
]
|
|
214
|
+
}, {
|
|
215
|
+
"type": "object",
|
|
216
|
+
"required": ["type", "name"],
|
|
217
|
+
"properties": {
|
|
218
|
+
"type": { "const": "tool" },
|
|
219
|
+
"name": { "$ref": "#/$defs/Identifier" }
|
|
220
|
+
},
|
|
221
|
+
"additionalProperties": false
|
|
222
|
+
}]
|
|
223
|
+
},
|
|
224
|
+
"reasoning": {
|
|
225
|
+
"description": "Opt into the structured-output envelope's `reasoning` field.",
|
|
226
|
+
"type": "boolean"
|
|
227
|
+
},
|
|
228
|
+
"temperature": { "$ref": "#/$defs/ExpressionValue" },
|
|
229
|
+
"maxOutputTokens": { "$ref": "#/$defs/ExpressionValue" },
|
|
230
|
+
"topP": { "$ref": "#/$defs/ExpressionValue" },
|
|
231
|
+
"topK": { "$ref": "#/$defs/ExpressionValue" },
|
|
232
|
+
"seed": { "$ref": "#/$defs/ExpressionValue" },
|
|
233
|
+
"stopSequences": { "anyOf": [{ "$ref": "#/$defs/ExpressionString" }, {
|
|
234
|
+
"type": "array",
|
|
235
|
+
"items": { "type": "string" }
|
|
236
|
+
}] },
|
|
237
|
+
"metadata": { "$ref": "#/$defs/ExpressionValue" }
|
|
238
|
+
},
|
|
239
|
+
"additionalProperties": false
|
|
240
|
+
},
|
|
241
|
+
"Message": {
|
|
242
|
+
"type": "object",
|
|
243
|
+
"required": ["role", "content"],
|
|
244
|
+
"properties": {
|
|
245
|
+
"role": { "$ref": "#/$defs/TemplateString" },
|
|
246
|
+
"content": { "$ref": "#/$defs/TemplateString" }
|
|
247
|
+
},
|
|
248
|
+
"additionalProperties": { "$ref": "#/$defs/ExpressionValue" }
|
|
249
|
+
},
|
|
250
|
+
"Actor": {
|
|
251
|
+
"description": "A placeholder actor source: schemas describe it for authors/editors; the implementation is provided by the host.",
|
|
252
|
+
"type": "object",
|
|
253
|
+
"properties": {
|
|
254
|
+
"description": { "type": "string" },
|
|
255
|
+
"input": { "$ref": "#/$defs/JsonSchema" },
|
|
256
|
+
"output": { "$ref": "#/$defs/JsonSchema" }
|
|
257
|
+
},
|
|
258
|
+
"additionalProperties": false
|
|
259
|
+
},
|
|
260
|
+
"Tool": {
|
|
261
|
+
"type": "object",
|
|
262
|
+
"properties": {
|
|
263
|
+
"description": { "type": "string" },
|
|
264
|
+
"inputSchema": { "$ref": "#/$defs/JsonSchema" },
|
|
265
|
+
"outputSchema": { "$ref": "#/$defs/JsonSchema" }
|
|
266
|
+
},
|
|
267
|
+
"additionalProperties": { "$ref": "#/$defs/JsonValue" }
|
|
268
|
+
},
|
|
269
|
+
"State": {
|
|
270
|
+
"type": "object",
|
|
271
|
+
"properties": {
|
|
272
|
+
"description": { "type": "string" },
|
|
273
|
+
"type": {
|
|
274
|
+
"type": "string",
|
|
275
|
+
"enum": [
|
|
276
|
+
"parallel",
|
|
277
|
+
"history",
|
|
278
|
+
"final",
|
|
279
|
+
"choice"
|
|
280
|
+
]
|
|
281
|
+
},
|
|
282
|
+
"initial": { "type": "string" },
|
|
283
|
+
"states": {
|
|
284
|
+
"type": "object",
|
|
285
|
+
"propertyNames": { "$ref": "#/$defs/Identifier" },
|
|
286
|
+
"additionalProperties": { "$ref": "#/$defs/State" }
|
|
287
|
+
},
|
|
288
|
+
"invoke": { "anyOf": [{ "$ref": "#/$defs/Invoke" }, {
|
|
289
|
+
"type": "array",
|
|
290
|
+
"items": { "$ref": "#/$defs/Invoke" }
|
|
291
|
+
}] },
|
|
292
|
+
"choice": {
|
|
293
|
+
"description": "Choice-state routing, equivalent to XState's type: 'choice' + choice transition function.",
|
|
294
|
+
"$ref": "#/$defs/TransitionOrArray"
|
|
295
|
+
},
|
|
296
|
+
"on": {
|
|
297
|
+
"type": "object",
|
|
298
|
+
"propertyNames": { "type": "string" },
|
|
299
|
+
"additionalProperties": { "$ref": "#/$defs/TransitionOrArray" }
|
|
300
|
+
},
|
|
301
|
+
"always": { "$ref": "#/$defs/TransitionOrArray" },
|
|
302
|
+
"onDone": { "$ref": "#/$defs/TransitionOrArray" },
|
|
303
|
+
"after": {
|
|
304
|
+
"type": "object",
|
|
305
|
+
"propertyNames": { "type": "string" },
|
|
306
|
+
"additionalProperties": { "$ref": "#/$defs/TransitionOrArray" }
|
|
307
|
+
},
|
|
308
|
+
"entry": { "$ref": "#/$defs/ActionOrArray" },
|
|
309
|
+
"exit": { "$ref": "#/$defs/ActionOrArray" },
|
|
310
|
+
"tags": {
|
|
311
|
+
"type": "array",
|
|
312
|
+
"items": { "type": "string" }
|
|
313
|
+
},
|
|
314
|
+
"output": { "$ref": "#/$defs/ExpressionValue" },
|
|
315
|
+
"meta": {
|
|
316
|
+
"description": "Static state metadata, passed through verbatim. Not template-evaluated.",
|
|
317
|
+
"$ref": "#/$defs/JsonObject"
|
|
318
|
+
}
|
|
319
|
+
},
|
|
320
|
+
"additionalProperties": false
|
|
321
|
+
},
|
|
322
|
+
"Invoke": {
|
|
323
|
+
"type": "object",
|
|
324
|
+
"required": ["src"],
|
|
325
|
+
"properties": {
|
|
326
|
+
"id": { "type": "string" },
|
|
327
|
+
"src": {
|
|
328
|
+
"description": "Actor source name. 'agent.decide' invokes are special: decision delivery is automatic (the chosen event is sent as soon as the model decides) and 'onDone' must be omitted — see the 'onDone' description.",
|
|
329
|
+
"$ref": "#/$defs/Identifier"
|
|
330
|
+
},
|
|
331
|
+
"input": { "$ref": "#/$defs/ExpressionValue" },
|
|
332
|
+
"onDone": {
|
|
333
|
+
"description": "Not valid on an 'agent.decide' invoke — the built-in lowering rejects it at setupAgent.fromConfig(...) time. A decision has no output value of its own (its output IS the chosen event), so delivery is automatic and not configurable from JSON. 'onError' (retries exhausted) still applies to 'agent.decide' invokes.",
|
|
334
|
+
"$ref": "#/$defs/TransitionOrArray"
|
|
335
|
+
},
|
|
336
|
+
"onError": { "$ref": "#/$defs/TransitionOrArray" }
|
|
337
|
+
},
|
|
338
|
+
"additionalProperties": false
|
|
339
|
+
},
|
|
340
|
+
"TransitionOrArray": { "anyOf": [{ "$ref": "#/$defs/Transition" }, {
|
|
341
|
+
"type": "array",
|
|
342
|
+
"items": { "$ref": "#/$defs/Transition" }
|
|
343
|
+
}] },
|
|
344
|
+
"Transition": {
|
|
345
|
+
"type": "object",
|
|
346
|
+
"properties": {
|
|
347
|
+
"target": { "anyOf": [{ "type": "string" }, {
|
|
348
|
+
"type": "array",
|
|
349
|
+
"items": { "type": "string" }
|
|
350
|
+
}] },
|
|
351
|
+
"guard": {
|
|
352
|
+
"description": "Either a whole-string {{ }} expression evaluated as truthy/falsy, or a named guard reference resolved against the `guards` passed to setupAgent.fromConfig(config, { guards }). Object guards ({ type, params }) are rejected by the lowering.",
|
|
353
|
+
"anyOf": [{ "$ref": "#/$defs/ExpressionString" }, { "$ref": "#/$defs/Identifier" }]
|
|
354
|
+
},
|
|
355
|
+
"assign": {
|
|
356
|
+
"description": "Context assignments applied when this transition is taken.",
|
|
357
|
+
"$ref": "#/$defs/ExpressionObject"
|
|
358
|
+
},
|
|
359
|
+
"actions": { "$ref": "#/$defs/ActionOrArray" },
|
|
360
|
+
"description": { "type": "string" },
|
|
361
|
+
"reenter": { "type": "boolean" },
|
|
362
|
+
"meta": {
|
|
363
|
+
"description": "Static transition metadata, passed through verbatim. Not template-evaluated.",
|
|
364
|
+
"$ref": "#/$defs/JsonObject"
|
|
365
|
+
}
|
|
366
|
+
},
|
|
367
|
+
"additionalProperties": false
|
|
368
|
+
},
|
|
369
|
+
"ActionOrArray": { "anyOf": [{ "$ref": "#/$defs/Action" }, {
|
|
370
|
+
"type": "array",
|
|
371
|
+
"items": { "$ref": "#/$defs/Action" }
|
|
372
|
+
}] },
|
|
373
|
+
"Action": {
|
|
374
|
+
"type": "object",
|
|
375
|
+
"properties": {
|
|
376
|
+
"type": { "type": "string" },
|
|
377
|
+
"params": { "$ref": "#/$defs/ExpressionValue" },
|
|
378
|
+
"assign": { "$ref": "#/$defs/ExpressionObject" },
|
|
379
|
+
"emit": {
|
|
380
|
+
"description": "Event emitted outward through runAgent's on handlers.",
|
|
381
|
+
"$ref": "#/$defs/ExpressionValue"
|
|
382
|
+
}
|
|
383
|
+
},
|
|
384
|
+
"anyOf": [
|
|
385
|
+
{ "required": ["type"] },
|
|
386
|
+
{ "required": ["assign"] },
|
|
387
|
+
{ "required": ["emit"] }
|
|
388
|
+
],
|
|
389
|
+
"additionalProperties": { "$ref": "#/$defs/ExpressionValue" }
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
//#endregion
|
|
394
|
+
//#region src/validate/index.ts
|
|
395
|
+
/**
|
|
396
|
+
* Schema validation for agent workflow configs.
|
|
397
|
+
*
|
|
398
|
+
* Lives behind the `@statelyai/agent/validate` subpath so the core package
|
|
399
|
+
* stays dependency-free. This module imports `ajv`, which is declared as an
|
|
400
|
+
* optional peer dependency.
|
|
401
|
+
*/
|
|
402
|
+
let compiledWorkflowValidator;
|
|
403
|
+
function getWorkflowValidator() {
|
|
404
|
+
if (!compiledWorkflowValidator) compiledWorkflowValidator = new ajv_dist_2020_js.default({
|
|
405
|
+
strict: false,
|
|
406
|
+
allowUnionTypes: true,
|
|
407
|
+
allErrors: true
|
|
408
|
+
}).compile(agent_workflow_default);
|
|
409
|
+
return compiledWorkflowValidator;
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Validates a value against the shipped `schemas/agent-workflow.json` before
|
|
413
|
+
* you hand it to `setupAgent(...).fromConfig(...)`. Returns diagnostics rather
|
|
414
|
+
* than throwing; `valid: true` means the config is structurally sound (it does
|
|
415
|
+
* not check that named guards/actions/actors are implemented, which
|
|
416
|
+
* `fromConfig` does). The compiled validator is cached across calls.
|
|
417
|
+
*/
|
|
418
|
+
function validateAgentConfig(config) {
|
|
419
|
+
const validate = getWorkflowValidator();
|
|
420
|
+
if (validate(config)) return {
|
|
421
|
+
valid: true,
|
|
422
|
+
errors: []
|
|
423
|
+
};
|
|
424
|
+
return {
|
|
425
|
+
valid: false,
|
|
426
|
+
errors: (validate.errors ?? []).map((error) => ({
|
|
427
|
+
severity: "error",
|
|
428
|
+
path: error.instancePath || "/",
|
|
429
|
+
message: error.message ?? "is invalid",
|
|
430
|
+
keyword: error.keyword
|
|
431
|
+
}))
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
//#endregion
|
|
435
|
+
exports.__toESM = __toESM;
|
|
436
|
+
exports.validateAgentConfig = validateAgentConfig;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//#region src/validate/index.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* One schema-validation finding from {@link validateAgentConfig}. `path` is a
|
|
4
|
+
* JSON Pointer into the config (`/states/idle/invoke`, `/` for the root) and
|
|
5
|
+
* `message` explains what the schema rejected. Mirrors the shape of
|
|
6
|
+
* `AgentLintDiagnostic` so config validation and machine linting report the
|
|
7
|
+
* same way.
|
|
8
|
+
*/
|
|
9
|
+
interface AgentConfigDiagnostic {
|
|
10
|
+
severity: "error";
|
|
11
|
+
/** JSON Pointer into the config (`/` for the root). */
|
|
12
|
+
path: string;
|
|
13
|
+
message: string;
|
|
14
|
+
/** The schema keyword that failed (`required`, `type`, `enum`, ...). */
|
|
15
|
+
keyword: string;
|
|
16
|
+
}
|
|
17
|
+
/** Result of {@link validateAgentConfig}. */
|
|
18
|
+
interface AgentConfigValidationResult {
|
|
19
|
+
valid: boolean;
|
|
20
|
+
errors: AgentConfigDiagnostic[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Validates a value against the shipped `schemas/agent-workflow.json` before
|
|
24
|
+
* you hand it to `setupAgent(...).fromConfig(...)`. Returns diagnostics rather
|
|
25
|
+
* than throwing; `valid: true` means the config is structurally sound (it does
|
|
26
|
+
* not check that named guards/actions/actors are implemented, which
|
|
27
|
+
* `fromConfig` does). The compiled validator is cached across calls.
|
|
28
|
+
*/
|
|
29
|
+
declare function validateAgentConfig(config: unknown): AgentConfigValidationResult;
|
|
30
|
+
//#endregion
|
|
31
|
+
export { AgentConfigDiagnostic, AgentConfigValidationResult, validateAgentConfig };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//#region src/validate/index.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* One schema-validation finding from {@link validateAgentConfig}. `path` is a
|
|
4
|
+
* JSON Pointer into the config (`/states/idle/invoke`, `/` for the root) and
|
|
5
|
+
* `message` explains what the schema rejected. Mirrors the shape of
|
|
6
|
+
* `AgentLintDiagnostic` so config validation and machine linting report the
|
|
7
|
+
* same way.
|
|
8
|
+
*/
|
|
9
|
+
interface AgentConfigDiagnostic {
|
|
10
|
+
severity: "error";
|
|
11
|
+
/** JSON Pointer into the config (`/` for the root). */
|
|
12
|
+
path: string;
|
|
13
|
+
message: string;
|
|
14
|
+
/** The schema keyword that failed (`required`, `type`, `enum`, ...). */
|
|
15
|
+
keyword: string;
|
|
16
|
+
}
|
|
17
|
+
/** Result of {@link validateAgentConfig}. */
|
|
18
|
+
interface AgentConfigValidationResult {
|
|
19
|
+
valid: boolean;
|
|
20
|
+
errors: AgentConfigDiagnostic[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Validates a value against the shipped `schemas/agent-workflow.json` before
|
|
24
|
+
* you hand it to `setupAgent(...).fromConfig(...)`. Returns diagnostics rather
|
|
25
|
+
* than throwing; `valid: true` means the config is structurally sound (it does
|
|
26
|
+
* not check that named guards/actions/actors are implemented, which
|
|
27
|
+
* `fromConfig` does). The compiled validator is cached across calls.
|
|
28
|
+
*/
|
|
29
|
+
declare function validateAgentConfig(config: unknown): AgentConfigValidationResult;
|
|
30
|
+
//#endregion
|
|
31
|
+
export { AgentConfigDiagnostic, AgentConfigValidationResult, validateAgentConfig };
|