@parcha/agentrun-dsl 0.1.0-beta.1
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/LICENSE +202 -0
- package/NOTICE +2 -0
- package/README.md +67 -0
- package/dist/authoring.d.ts +72 -0
- package/dist/authoring.js +138 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +135 -0
- package/dist/code-exec.d.ts +4 -0
- package/dist/code-exec.js +45 -0
- package/dist/demo.d.ts +54 -0
- package/dist/demo.js +80 -0
- package/dist/dry-run.d.ts +19 -0
- package/dist/dry-run.js +191 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +8 -0
- package/dist/inspection.d.ts +35 -0
- package/dist/inspection.js +107 -0
- package/dist/predicates.d.ts +34 -0
- package/dist/predicates.js +43 -0
- package/dist/schema-references.d.ts +3 -0
- package/dist/schema-references.js +66 -0
- package/dist/system-one.d.ts +78 -0
- package/dist/system-one.js +193 -0
- package/dist/workflow-shape.d.ts +1 -0
- package/dist/workflow-shape.js +181 -0
- package/dist/workflow.d.ts +541 -0
- package/dist/workflow.js +2294 -0
- package/dist/zod-json-contract.d.ts +1 -0
- package/dist/zod-json-contract.js +106 -0
- package/package.json +52 -0
- package/schema/workflow.schema.json +1850 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function assertZodJsonContract(schema: unknown, inputRoot?: boolean): void;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/** Zod documents _zod.def as the traversal interface for schema tools:
|
|
2
|
+
* https://zod.dev/packages/core. Keep this dependency-free and fail closed on new
|
|
3
|
+
* constructs: the JSON interpreter cannot execute a schema library's parser hooks. */
|
|
4
|
+
const TYPES = new Set([
|
|
5
|
+
"string", "number", "boolean", "null", "literal", "enum", "object", "array",
|
|
6
|
+
"tuple", "record", "union", "intersection", "optional", "nullable", "nonoptional",
|
|
7
|
+
"any", "unknown", "never",
|
|
8
|
+
]);
|
|
9
|
+
const CHECKS = new Set([
|
|
10
|
+
"less_than", "greater_than", "multiple_of", "number_format", "min_length",
|
|
11
|
+
"max_length", "length_equals", "string_format",
|
|
12
|
+
]);
|
|
13
|
+
const SCHEMA_KEYWORDS = new Set([
|
|
14
|
+
"$ref", "$schema", "$id", "$anchor", "$dynamicRef", "$dynamicAnchor", "$defs", "definitions",
|
|
15
|
+
"type", "enum", "const", "properties", "patternProperties", "additionalProperties", "required",
|
|
16
|
+
"propertyNames", "dependentRequired", "dependentSchemas", "dependencies", "unevaluatedProperties",
|
|
17
|
+
"items", "prefixItems", "additionalItems", "contains", "minContains", "maxContains", "unevaluatedItems",
|
|
18
|
+
"allOf", "anyOf", "oneOf", "not", "if", "then", "else", "minimum", "maximum", "exclusiveMinimum",
|
|
19
|
+
"exclusiveMaximum", "multipleOf", "minLength", "maxLength", "pattern", "format", "minItems", "maxItems",
|
|
20
|
+
"uniqueItems", "minProperties", "maxProperties", "contentEncoding", "contentMediaType", "contentSchema",
|
|
21
|
+
]);
|
|
22
|
+
function record(value) {
|
|
23
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
24
|
+
}
|
|
25
|
+
export function assertZodJsonContract(schema, inputRoot = false) {
|
|
26
|
+
const seen = new Set();
|
|
27
|
+
const fail = (path, reason) => {
|
|
28
|
+
throw new Error(`${path}: ${reason}; use JSON-representable Zod schemas and put parsing or custom checks in an explicit workflow step`);
|
|
29
|
+
};
|
|
30
|
+
const check = (value, path) => {
|
|
31
|
+
if (!record(value) || !record(value._zod) || !record(value._zod.def))
|
|
32
|
+
fail(path, "unsupported Zod check representation");
|
|
33
|
+
const def = value._zod.def;
|
|
34
|
+
if (!CHECKS.has(String(def.check)))
|
|
35
|
+
fail(path, `Zod check ${String(def.check)} is not supported`);
|
|
36
|
+
if (def.check === "string_format" && !(def.pattern instanceof RegExp) && def.format !== "url") {
|
|
37
|
+
fail(path, `Zod format ${String(def.format)} has no JSON-runtime validation rule`);
|
|
38
|
+
}
|
|
39
|
+
if (def.pattern instanceof RegExp && def.pattern.flags)
|
|
40
|
+
fail(path, "regular-expression flags do not survive JSON Schema conversion");
|
|
41
|
+
if (def.normalize || def.hostname || def.protocol)
|
|
42
|
+
fail(path, "URL normalization and custom URL constraints do not survive JSON Schema conversion");
|
|
43
|
+
};
|
|
44
|
+
const visit = (value, path) => {
|
|
45
|
+
if (!record(value) || !record(value._zod) || !record(value._zod.def))
|
|
46
|
+
fail(path, "unsupported Zod schema representation");
|
|
47
|
+
const node = value;
|
|
48
|
+
if (seen.has(node))
|
|
49
|
+
return;
|
|
50
|
+
seen.add(node);
|
|
51
|
+
const def = node._zod.def;
|
|
52
|
+
if (!TYPES.has(String(def.type)))
|
|
53
|
+
fail(path, `Zod ${String(def.type)} is not supported`);
|
|
54
|
+
if (def.coerce)
|
|
55
|
+
fail(path, "Zod coercion is not supported");
|
|
56
|
+
if (typeof node.meta === "function") {
|
|
57
|
+
const metadata = node.meta();
|
|
58
|
+
for (const key of Object.keys(metadata ?? {}))
|
|
59
|
+
if (SCHEMA_KEYWORDS.has(key))
|
|
60
|
+
fail(path, `metadata cannot override JSON Schema keyword ${key}`);
|
|
61
|
+
}
|
|
62
|
+
if (def.check !== undefined)
|
|
63
|
+
check(node, path);
|
|
64
|
+
if (def.checks !== undefined) {
|
|
65
|
+
if (!Array.isArray(def.checks))
|
|
66
|
+
fail(path, "unsupported Zod checks representation");
|
|
67
|
+
def.checks.forEach((entry, index) => check(entry, `${path}.checks[${index}]`));
|
|
68
|
+
}
|
|
69
|
+
if (def.type === "object") {
|
|
70
|
+
if (!record(def.shape))
|
|
71
|
+
fail(path, "unsupported Zod object shape");
|
|
72
|
+
for (const [key, child] of Object.entries(def.shape))
|
|
73
|
+
visit(child, `${path}.${key}`);
|
|
74
|
+
if (def.catchall !== undefined)
|
|
75
|
+
visit(def.catchall, `${path}.*`);
|
|
76
|
+
}
|
|
77
|
+
for (const field of ["element", "innerType", "keyType", "valueType", "left", "right", "rest"]) {
|
|
78
|
+
if (def[field] !== undefined && def[field] !== null)
|
|
79
|
+
visit(def[field], `${path}.${field}`);
|
|
80
|
+
}
|
|
81
|
+
for (const field of ["options", "items"]) {
|
|
82
|
+
if (def[field] === undefined)
|
|
83
|
+
continue;
|
|
84
|
+
if (!Array.isArray(def[field]))
|
|
85
|
+
fail(path, `unsupported Zod ${field} representation`);
|
|
86
|
+
def[field].forEach((child, index) => visit(child, `${path}.${field}[${index}]`));
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
visit(schema, "schema");
|
|
90
|
+
if (inputRoot) {
|
|
91
|
+
const objectInput = (value) => {
|
|
92
|
+
const def = value._zod.def;
|
|
93
|
+
if (def.type === "object" || def.type === "record")
|
|
94
|
+
return true;
|
|
95
|
+
if (def.type === "union")
|
|
96
|
+
return def.options.every(objectInput);
|
|
97
|
+
if (def.type === "intersection")
|
|
98
|
+
return objectInput(def.left) || objectInput(def.right);
|
|
99
|
+
if (def.type === "nonoptional")
|
|
100
|
+
return objectInput(def.innerType);
|
|
101
|
+
return false;
|
|
102
|
+
};
|
|
103
|
+
if (!objectInput(schema))
|
|
104
|
+
fail("schema", "workflow input must be an object schema, or a union/intersection constrained to objects");
|
|
105
|
+
}
|
|
106
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@parcha/agentrun-dsl",
|
|
3
|
+
"version": "0.1.0-beta.1",
|
|
4
|
+
"description": "Composable, typed workflows for agents",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"bin": {
|
|
8
|
+
"agentrun": "./dist/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./demo": {
|
|
16
|
+
"types": "./dist/demo.d.ts",
|
|
17
|
+
"import": "./dist/demo.js"
|
|
18
|
+
},
|
|
19
|
+
"./schema": "./schema/workflow.schema.json"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"README.md",
|
|
24
|
+
"LICENSE",
|
|
25
|
+
"NOTICE",
|
|
26
|
+
"schema"
|
|
27
|
+
],
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=22.19.0"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsc -p tsconfig.json",
|
|
33
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
34
|
+
"test": "node --test test/*.test.mjs"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"typebox": "1.3.7"
|
|
38
|
+
},
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "git+https://github.com/Parcha-ai/agentrun.git",
|
|
42
|
+
"directory": "packages/dsl"
|
|
43
|
+
},
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/Parcha-ai/agentrun/issues"
|
|
46
|
+
},
|
|
47
|
+
"homepage": "https://agentrun.ai",
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public",
|
|
50
|
+
"tag": "beta"
|
|
51
|
+
}
|
|
52
|
+
}
|