@sweny-ai/core 0.1.62 → 0.1.63
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/__tests__/cascade.test.d.ts +11 -0
- package/dist/__tests__/cascade.test.js +449 -0
- package/dist/executor.js +104 -25
- package/dist/schema.d.ts +724 -0
- package/dist/schema.js +51 -1
- package/dist/types.d.ts +20 -0
- package/package.json +1 -1
package/dist/schema.js
CHANGED
|
@@ -63,12 +63,26 @@ export const skillZ = z
|
|
|
63
63
|
.refine((s) => s.tools.length > 0 || s.instruction || s.mcp, {
|
|
64
64
|
message: "Skill must provide at least one of: tools, instruction, or mcp",
|
|
65
65
|
});
|
|
66
|
+
/**
|
|
67
|
+
* NodeSources: either an array of Sources (additive — inherits cascade)
|
|
68
|
+
* or an object `{ only?: boolean, sources: Source[] }` where `only: true`
|
|
69
|
+
* blocks the cascade for that field.
|
|
70
|
+
*/
|
|
71
|
+
export const nodeSourcesZ = z.union([
|
|
72
|
+
z.array(sourceZ),
|
|
73
|
+
z.object({
|
|
74
|
+
only: z.boolean().optional(),
|
|
75
|
+
sources: z.array(sourceZ),
|
|
76
|
+
}),
|
|
77
|
+
]);
|
|
66
78
|
export const nodeZ = z.object({
|
|
67
79
|
name: z.string().min(1),
|
|
68
80
|
instruction: sourceZ,
|
|
69
81
|
skills: z.array(z.string()).default([]),
|
|
70
82
|
output: jsonSchemaZ.optional(),
|
|
71
83
|
max_turns: z.number().int().min(1).optional(),
|
|
84
|
+
rules: nodeSourcesZ.optional(),
|
|
85
|
+
context: nodeSourcesZ.optional(),
|
|
72
86
|
});
|
|
73
87
|
export const edgeZ = z.object({
|
|
74
88
|
from: z.string().min(1),
|
|
@@ -84,6 +98,8 @@ export const workflowZ = z.object({
|
|
|
84
98
|
edges: z.array(edgeZ),
|
|
85
99
|
entry: z.string().min(1),
|
|
86
100
|
skills: z.record(skillDefinitionZ).default({}),
|
|
101
|
+
rules: z.array(sourceZ).optional(),
|
|
102
|
+
context: z.array(sourceZ).optional(),
|
|
87
103
|
});
|
|
88
104
|
/** Parse + validate a raw object as a Workflow. Throws on invalid input. */
|
|
89
105
|
export function parseWorkflow(raw) {
|
|
@@ -269,12 +285,38 @@ export const workflowJsonSchema = {
|
|
|
269
285
|
type: "object",
|
|
270
286
|
required: ["id", "name", "nodes", "edges", "entry"],
|
|
271
287
|
additionalProperties: false,
|
|
272
|
-
$defs: {
|
|
288
|
+
$defs: {
|
|
289
|
+
Source: sourceJsonSchema,
|
|
290
|
+
NodeSources: {
|
|
291
|
+
oneOf: [
|
|
292
|
+
{ type: "array", items: { $ref: "#/$defs/Source" } },
|
|
293
|
+
{
|
|
294
|
+
type: "object",
|
|
295
|
+
required: ["sources"],
|
|
296
|
+
additionalProperties: false,
|
|
297
|
+
properties: {
|
|
298
|
+
only: { type: "boolean" },
|
|
299
|
+
sources: { type: "array", items: { $ref: "#/$defs/Source" } },
|
|
300
|
+
},
|
|
301
|
+
},
|
|
302
|
+
],
|
|
303
|
+
},
|
|
304
|
+
},
|
|
273
305
|
properties: {
|
|
274
306
|
id: { type: "string", minLength: 1 },
|
|
275
307
|
name: { type: "string", minLength: 1 },
|
|
276
308
|
description: { type: "string" },
|
|
277
309
|
entry: { type: "string", minLength: 1, description: "ID of the entry node" },
|
|
310
|
+
rules: {
|
|
311
|
+
type: "array",
|
|
312
|
+
items: { $ref: "#/$defs/Source" },
|
|
313
|
+
description: "Directives prepended to every node's instruction.",
|
|
314
|
+
},
|
|
315
|
+
context: {
|
|
316
|
+
type: "array",
|
|
317
|
+
items: { $ref: "#/$defs/Source" },
|
|
318
|
+
description: "Background knowledge prepended to every node's instruction.",
|
|
319
|
+
},
|
|
278
320
|
nodes: {
|
|
279
321
|
type: "object",
|
|
280
322
|
additionalProperties: {
|
|
@@ -298,6 +340,14 @@ export const workflowJsonSchema = {
|
|
|
298
340
|
minimum: 1,
|
|
299
341
|
description: "Max AI model turns for this node. When absent, the executor's default applies.",
|
|
300
342
|
},
|
|
343
|
+
rules: {
|
|
344
|
+
$ref: "#/$defs/NodeSources",
|
|
345
|
+
description: "Per-node rules. Additive by default; set { only: true } to block cascade.",
|
|
346
|
+
},
|
|
347
|
+
context: {
|
|
348
|
+
$ref: "#/$defs/NodeSources",
|
|
349
|
+
description: "Per-node context. Additive by default; set { only: true } to block cascade.",
|
|
350
|
+
},
|
|
301
351
|
},
|
|
302
352
|
},
|
|
303
353
|
},
|
package/dist/types.d.ts
CHANGED
|
@@ -37,6 +37,18 @@ export interface Skill {
|
|
|
37
37
|
/** External MCP server definition wired for nodes referencing this skill. */
|
|
38
38
|
mcp?: McpServerConfig;
|
|
39
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Per-node rules or context.
|
|
42
|
+
*
|
|
43
|
+
* - Array form (additive): inherits workflow/runtime sources AND adds these.
|
|
44
|
+
* - Object form: when `only: true`, blocks the cascade for this field and
|
|
45
|
+
* uses only `sources`. When `only` is absent/false, behaves like the
|
|
46
|
+
* array form.
|
|
47
|
+
*/
|
|
48
|
+
export type NodeSources = _Source[] | {
|
|
49
|
+
only?: boolean;
|
|
50
|
+
sources: _Source[];
|
|
51
|
+
};
|
|
40
52
|
/** A node in the workflow DAG */
|
|
41
53
|
export interface Node {
|
|
42
54
|
/** Human-readable name */
|
|
@@ -49,6 +61,10 @@ export interface Node {
|
|
|
49
61
|
output?: JSONSchema;
|
|
50
62
|
/** Max AI model turns for this node. When absent, the executor's default applies. */
|
|
51
63
|
max_turns?: number;
|
|
64
|
+
/** Per-node directives. Additive by default; set `{ only: true, sources: [...] }` to block cascade. */
|
|
65
|
+
rules?: NodeSources;
|
|
66
|
+
/** Per-node background knowledge. Additive by default; set `{ only: true, sources: [...] }` to block cascade. */
|
|
67
|
+
context?: NodeSources;
|
|
52
68
|
}
|
|
53
69
|
/** An edge connecting two nodes */
|
|
54
70
|
export interface Edge {
|
|
@@ -68,6 +84,10 @@ export interface Workflow {
|
|
|
68
84
|
edges: Edge[];
|
|
69
85
|
entry: string;
|
|
70
86
|
skills?: Record<string, SkillDefinition>;
|
|
87
|
+
/** Directives prepended to every node's instruction. Cascade into per-node rules. */
|
|
88
|
+
rules?: _Source[];
|
|
89
|
+
/** Background knowledge prepended to every node's instruction. Cascade into per-node context. */
|
|
90
|
+
context?: _Source[];
|
|
71
91
|
}
|
|
72
92
|
/**
|
|
73
93
|
* Inline skill definition in a workflow's `skills` block.
|