@agentsmarket/pipeline-runtime 0.1.0
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/README.md +94 -0
- package/bin/webhook.mjs +11 -0
- package/dist/adapters/minimax.d.ts +31 -0
- package/dist/adapters/minimax.js +69 -0
- package/dist/adapters/openrouter.d.ts +29 -0
- package/dist/adapters/openrouter.js +71 -0
- package/dist/checkpoints.d.ts +142 -0
- package/dist/checkpoints.js +192 -0
- package/dist/composition.d.ts +90 -0
- package/dist/composition.js +108 -0
- package/dist/content-hash.d.ts +7 -0
- package/dist/content-hash.js +17 -0
- package/dist/fallback.d.ts +31 -0
- package/dist/fallback.js +76 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.js +61 -0
- package/dist/model-resolver.d.ts +136 -0
- package/dist/model-resolver.js +36 -0
- package/dist/parallel.d.ts +26 -0
- package/dist/parallel.js +83 -0
- package/dist/pricing.d.ts +57 -0
- package/dist/pricing.js +135 -0
- package/dist/provider-registry.d.ts +190 -0
- package/dist/provider-registry.js +333 -0
- package/dist/resolve-vars.d.ts +91 -0
- package/dist/resolve-vars.js +203 -0
- package/dist/retry.d.ts +40 -0
- package/dist/retry.js +61 -0
- package/dist/runtime-constraints.d.ts +39 -0
- package/dist/runtime-constraints.js +60 -0
- package/dist/stage-output-refs.d.ts +79 -0
- package/dist/stage-output-refs.js +107 -0
- package/dist/stages.d.ts +247 -0
- package/dist/stages.js +633 -0
- package/dist/streaming-events.d.ts +118 -0
- package/dist/streaming-events.js +132 -0
- package/dist/types.d.ts +138 -0
- package/dist/types.js +54 -0
- package/dist/webhook.d.ts +30 -0
- package/dist/webhook.js +160 -0
- package/dist/when.d.ts +55 -0
- package/dist/when.js +165 -0
- package/package.json +42 -0
package/dist/when.js
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* R10.2 — `when` DSL per ADR Q5.
|
|
3
|
+
*
|
|
4
|
+
* Pure-comparison DSL. No JS expressions, no I/O. Reuses existing
|
|
5
|
+
* `expandPipelineText` for `{{ stages.x.outputs.y }}` template resolution.
|
|
6
|
+
*
|
|
7
|
+
* YAML shape (either form):
|
|
8
|
+
*
|
|
9
|
+
* when: "stages.x.outputs.category == 'bug'" # single comparison
|
|
10
|
+
* when:
|
|
11
|
+
* all: # all-must-be-true
|
|
12
|
+
* - "stages.x.outputs.category == 'bug'"
|
|
13
|
+
* - "stages.x.outputs.confidence > 0.7"
|
|
14
|
+
* when:
|
|
15
|
+
* any: # at-least-one
|
|
16
|
+
* - "stages.x.outputs.severity == 'P0'"
|
|
17
|
+
* - "stages.x.outputs.severity == 'P1'"
|
|
18
|
+
*
|
|
19
|
+
* Supported operators: ==, !=, <, >, <=, >=, in, not in. Anything else
|
|
20
|
+
* rejected at validator time.
|
|
21
|
+
*
|
|
22
|
+
* DAG semantics: when-missed stages are SKIPPED at execution time. They
|
|
23
|
+
* produce null outputs. The DAG topology itself is static — branch
|
|
24
|
+
* decisions happen at execution time, not compile time.
|
|
25
|
+
*/
|
|
26
|
+
export class WhenParseError extends Error {
|
|
27
|
+
expression;
|
|
28
|
+
reason;
|
|
29
|
+
constructor(expression, reason) {
|
|
30
|
+
super(`Invalid when expression: '${expression}' — ${reason}`);
|
|
31
|
+
this.name = 'WHEN_PARSE_ERROR';
|
|
32
|
+
this.expression = expression;
|
|
33
|
+
this.reason = reason;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const WHEN_OP_PATTERN = /^(.*?)\s*(==|!=|>=|<=|>|<|\bnot\s+in\b|\bin\b)\s*(.*)$/;
|
|
37
|
+
export function parseComparison(expr) {
|
|
38
|
+
const trimmed = expr.trim();
|
|
39
|
+
const m = WHEN_OP_PATTERN.exec(trimmed);
|
|
40
|
+
if (!m)
|
|
41
|
+
return null;
|
|
42
|
+
return {
|
|
43
|
+
lhs: m[1].trim(),
|
|
44
|
+
op: m[2].replace(/\s+/g, ' '),
|
|
45
|
+
rhs: m[3].trim(),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export function parseWhenLiteral(s) {
|
|
49
|
+
const trimmed = s.trim();
|
|
50
|
+
if (trimmed === 'true')
|
|
51
|
+
return true;
|
|
52
|
+
if (trimmed === 'false')
|
|
53
|
+
return false;
|
|
54
|
+
if (trimmed === 'null')
|
|
55
|
+
return null;
|
|
56
|
+
if (/^-?\d+(\.\d+)?$/.test(trimmed))
|
|
57
|
+
return Number(trimmed);
|
|
58
|
+
const m = /^(['"])(.*)\1$/.exec(trimmed);
|
|
59
|
+
if (m)
|
|
60
|
+
return m[2];
|
|
61
|
+
return trimmed;
|
|
62
|
+
}
|
|
63
|
+
export function evaluateComparison(parsed, resolve) {
|
|
64
|
+
if (parsed.op === 'in' || parsed.op === 'not in') {
|
|
65
|
+
return evaluateMembership(parsed, resolve);
|
|
66
|
+
}
|
|
67
|
+
const lhsVal = parseWhenLiteral(resolve(parsed.lhs));
|
|
68
|
+
const rhsVal = parseWhenLiteral(resolve(parsed.rhs));
|
|
69
|
+
switch (parsed.op) {
|
|
70
|
+
case '==':
|
|
71
|
+
return lhsVal === rhsVal;
|
|
72
|
+
case '!=':
|
|
73
|
+
return lhsVal !== rhsVal;
|
|
74
|
+
case '<':
|
|
75
|
+
return Number(lhsVal) < Number(rhsVal);
|
|
76
|
+
case '>':
|
|
77
|
+
return Number(lhsVal) > Number(rhsVal);
|
|
78
|
+
case '<=':
|
|
79
|
+
return Number(lhsVal) <= Number(rhsVal);
|
|
80
|
+
case '>=':
|
|
81
|
+
return Number(lhsVal) >= Number(rhsVal);
|
|
82
|
+
default:
|
|
83
|
+
throw new WhenParseError(`${parsed.lhs} ${parsed.op} ${parsed.rhs}`, `unsupported operator '${parsed.op}'`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function evaluateMembership(parsed, resolve) {
|
|
87
|
+
const lhsVal = parseWhenLiteral(resolve(parsed.lhs));
|
|
88
|
+
const rhsResolved = resolve(parsed.rhs);
|
|
89
|
+
let arr;
|
|
90
|
+
try {
|
|
91
|
+
const candidate = JSON.parse(rhsResolved);
|
|
92
|
+
if (!Array.isArray(candidate)) {
|
|
93
|
+
throw new WhenParseError(`${parsed.lhs} ${parsed.op} ${parsed.rhs}`, `rhs must be a JSON array literal like ["a","b"], got ${typeof candidate}`);
|
|
94
|
+
}
|
|
95
|
+
arr = candidate;
|
|
96
|
+
}
|
|
97
|
+
catch (e) {
|
|
98
|
+
if (e instanceof WhenParseError)
|
|
99
|
+
throw e;
|
|
100
|
+
throw new WhenParseError(`${parsed.lhs} ${parsed.op} ${parsed.rhs}`, `rhs must be a JSON array literal like ["a","b"] (JSON parse failed: ${e.message})`);
|
|
101
|
+
}
|
|
102
|
+
const contains = arr.includes(lhsVal);
|
|
103
|
+
return parsed.op === 'in' ? contains : !contains;
|
|
104
|
+
}
|
|
105
|
+
export function evaluateWhen(condition, resolve) {
|
|
106
|
+
if (typeof condition === 'string') {
|
|
107
|
+
const parsed = parseComparison(condition);
|
|
108
|
+
if (!parsed) {
|
|
109
|
+
throw new WhenParseError(condition, "must have form 'lhs OP rhs' where OP is ==, !=, <, >, <=, >=, in, 'not in'");
|
|
110
|
+
}
|
|
111
|
+
return evaluateComparison(parsed, resolve);
|
|
112
|
+
}
|
|
113
|
+
if ('all' in condition) {
|
|
114
|
+
return condition.all.every((c) => evaluateWhen(c, resolve));
|
|
115
|
+
}
|
|
116
|
+
if ('any' in condition) {
|
|
117
|
+
return condition.any.some((c) => evaluateWhen(c, resolve));
|
|
118
|
+
}
|
|
119
|
+
throw new WhenParseError(JSON.stringify(condition), 'unknown condition shape (expected string, or object with all/any array)');
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Check whether an evaluated when condition was a "true" result, suitable
|
|
123
|
+
* for executor-stage-skip decision.
|
|
124
|
+
*/
|
|
125
|
+
export function shouldSkipStage(condition, resolve) {
|
|
126
|
+
return !evaluateWhen(condition, resolve);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Validate shape only. Returns first error string or null. Does NOT
|
|
130
|
+
* execute evaluation — just structural soundness.
|
|
131
|
+
*/
|
|
132
|
+
export function validateWhenShape(condition) {
|
|
133
|
+
if (typeof condition === 'string') {
|
|
134
|
+
const parsed = parseComparison(condition);
|
|
135
|
+
if (!parsed) {
|
|
136
|
+
return `when string must have form 'lhs OP rhs' (lhs references stages.X.outputs.Y or inputs.X; OP is ==, !=, <, >, <=, >=, in, "not in")`;
|
|
137
|
+
}
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
if (typeof condition !== 'object' || condition === null || Array.isArray(condition)) {
|
|
141
|
+
return 'when must be a string or object with all/any array';
|
|
142
|
+
}
|
|
143
|
+
const w = condition;
|
|
144
|
+
if (Array.isArray(w.all)) {
|
|
145
|
+
for (const c of w.all) {
|
|
146
|
+
if (typeof c !== 'string')
|
|
147
|
+
return 'when.all entries must be strings';
|
|
148
|
+
const err = validateWhenShape(c);
|
|
149
|
+
if (err)
|
|
150
|
+
return err;
|
|
151
|
+
}
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
if (Array.isArray(w.any)) {
|
|
155
|
+
for (const c of w.any) {
|
|
156
|
+
if (typeof c !== 'string')
|
|
157
|
+
return 'when.any entries must be strings';
|
|
158
|
+
const err = validateWhenShape(c);
|
|
159
|
+
if (err)
|
|
160
|
+
return err;
|
|
161
|
+
}
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
return 'when object must have all or any array';
|
|
165
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agentsmarket/pipeline-runtime",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Runtime for executing PIPELINE.md workflows (multi-skill orchestration). Provider-agnostic (MiniMax, Claude, OpenAI).",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"README.md"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"test": "vitest run",
|
|
15
|
+
"test:coverage": "vitest run --coverage",
|
|
16
|
+
"dev": "tsx src/index.ts",
|
|
17
|
+
"lint": "tsc --noEmit"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@anthropic-ai/sdk": "^0.125.0",
|
|
21
|
+
"@hono/node-server": "^1.13.0",
|
|
22
|
+
"@scure/bip39": "^2.4.0",
|
|
23
|
+
"ethers": "^6.17.0",
|
|
24
|
+
"hono": "^4.6.0",
|
|
25
|
+
"js-yaml": "^4.1.0",
|
|
26
|
+
"openai": "^7.15.0",
|
|
27
|
+
"zod": "^3.25"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/js-yaml": "^4.0.9",
|
|
31
|
+
"@types/node": "^22.0.0",
|
|
32
|
+
"@vitest/coverage-v8": "^4.1.11",
|
|
33
|
+
"typescript": "^5.6.0",
|
|
34
|
+
"vitest": "^4.1.11"
|
|
35
|
+
},
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=20"
|
|
38
|
+
},
|
|
39
|
+
"bin": {
|
|
40
|
+
"pipeline-webhook": "./bin/webhook.mjs"
|
|
41
|
+
}
|
|
42
|
+
}
|