@dudko.dev/agent-web 0.0.41 → 0.0.43
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 +102 -5
- package/dist/agent-web.js +140 -140
- package/dist/agent-web.js.map +1 -1
- package/dist/{chunk-4FBTBE74.js → chunk-2MLHZ6LQ.js} +2 -2
- package/dist/{chunk-L7Y3QRAM.js → chunk-DAREMCXF.js} +2 -2
- package/dist/{chunk-YUA2BHRM.js → chunk-ZSZSSJS4.js} +402 -13
- package/dist/chunk-ZSZSSJS4.js.map +1 -0
- package/dist/{elicitation-BA1knkdA.d.cts → elicitation-DS-84_bF.d.cts} +123 -9
- package/dist/{elicitation-BA1knkdA.d.ts → elicitation-DS-84_bF.d.ts} +123 -9
- package/dist/index.cjs +346 -43
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +78 -202
- package/dist/index.d.ts +78 -202
- package/dist/index.js +264 -43
- package/dist/index.js.map +1 -1
- package/dist/mcp.cjs +352 -9
- package/dist/mcp.cjs.map +1 -1
- package/dist/mcp.d.cts +12 -6
- package/dist/mcp.d.ts +12 -6
- package/dist/mcp.js +8 -3
- package/dist/mcp.js.map +1 -1
- package/dist/pipeline-engine.cjs +1130 -0
- package/dist/pipeline-engine.cjs.map +1 -0
- package/dist/pipeline-engine.d.cts +226 -0
- package/dist/pipeline-engine.d.ts +226 -0
- package/dist/pipeline-engine.js +1094 -0
- package/dist/pipeline-engine.js.map +1 -0
- package/dist/{sandbox-ZDQIIZS7.js → sandbox-3VRX47UY.js} +3 -3
- package/package.json +13 -3
- package/dist/chunk-YUA2BHRM.js.map +0 -1
- /package/dist/{chunk-4FBTBE74.js.map → chunk-2MLHZ6LQ.js.map} +0 -0
- /package/dist/{chunk-L7Y3QRAM.js.map → chunk-DAREMCXF.js.map} +0 -0
- /package/dist/{sandbox-ZDQIIZS7.js.map → sandbox-3VRX47UY.js.map} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/pipeline/engine.ts"],"sourcesContent":["// The pipeline engine: the JSON definition, its validation, the edge conditions and the scheduler.\n// Pure - no agent, no I/O, no imports: a node is run by the `runNode` it is handed.\n//\n// DETERMINISTIC, BY CONTRACT. No clock (`Date`, `performance`), no randomness (`Math.random`,\n// `crypto`), no timers, no I/O, no imports, and no global the language itself does not define:\n// `DOMException` and `AbortController` are used only where the runtime has them (`abortError`,\n// `createStopper`). What a run does - the calls to `runNode`, the events, the trace, the result -\n// depends only on the definition, the input and the runner's answers in the order they arrive\n// (and on when `signal` aborts, which is an input too). So a host can use `runPipelineGraph` as a\n// deterministic scheduler and replay a run from a log of those answers, in a sandbox that has\n// nothing but the language. `tests/pipeline-determinism.test.ts` (both packages) holds the file to\n// it: a scan of its source, and a run inside a `node:vm` context with only the language's globals.\n//\n// A DELIBERATE COPY. `packages/agent/src/pipeline-engine.ts` and\n// `packages/agent-web/src/pipeline/engine.ts` are the same file, byte for byte: change both, with\n// tests (`tests/pipeline-agent.test.ts` in the Node package fails when they differ). Only the adapter\n// that runs a node with a package's own `createAgent` is different (`pipeline.ts` /\n// `pipeline/index.ts`).\n\n// ── The definition (plain JSON) ──────────────────────────────────────────────\n\nexport interface PipelineDefinition {\n version: 1\n name?: string\n // The id of the node that receives the request.\n entry: string\n nodes: PipelineNode[]\n edges: PipelineEdge[]\n limits?: {\n // Visits of one node (default 3).\n maxNodeVisits?: number\n // Node runs of the whole pipeline (default 25).\n maxRuns?: number\n }\n}\n\nexport interface PipelineNode {\n id: string\n name?: string\n // This node's role, added to its agent's system prompt.\n instructions?: string\n // Keys the host resolves. Never a model object, never a secret.\n model?: string\n skills?: string[]\n tools?: string[]\n mcpServers?: string[]\n // The node picks one of these after it answers.\n routes?: PipelineRoute[]\n // How a node activated by several edges waits for them (default 'all').\n join?: 'all' | 'any'\n // Passed to the host's resolver untouched.\n settings?: Record<string, unknown>\n // For editors; the runner ignores it.\n position?: { x: number; y: number }\n}\n\nexport interface PipelineRoute {\n label: string\n description?: string\n}\n\nexport type PipelineCondition =\n | { kind: 'always' }\n | { kind: 'contains'; text: string; caseSensitive?: boolean }\n | { kind: 'matches'; pattern: string; flags?: string }\n | { kind: 'route'; label: string }\n | { kind: 'otherwise' }\n\nexport interface PipelineEdge {\n // Unique. An edge without one is given `e<its position in edges>` (see normalizePipeline).\n id?: string\n from: string\n to: string\n // Absent = always.\n when?: PipelineCondition\n}\n\n// ── Bounds ───────────────────────────────────────────────────────────────────\n\nexport const PIPELINE_LIMITS = {\n // Defaults of `limits`.\n maxNodeVisits: 3,\n maxRuns: 25,\n // The largest values `limits` accepts (the smallest is 1).\n maxNodeVisitsCeiling: 100,\n maxRunsCeiling: 1000,\n // The size of a definition.\n maxNodes: 200,\n maxEdges: 1000,\n maxRoutes: 20,\n // `matches`: the longest pattern, and the largest compiled program (what `a{50}` grows into).\n maxPatternLength: 500,\n maxPatternProgram: 1000,\n // `contains` and `matches` look at this many leading characters of an output.\n conditionInputChars: 50_000,\n} as const\n\n// ── What a run hands out ─────────────────────────────────────────────────────\n\nexport interface PipelineUsage {\n inputTokens: number\n outputTokens: number\n totalTokens: number\n reasoningTokens?: number\n cachedInputTokens?: number\n cacheWriteTokens?: number\n}\n\nexport interface PipelineNodeSource {\n nodeId: string\n name?: string\n text: string\n}\n\nexport interface PipelineNodeInput {\n // The original input of the run.\n request: string\n // The outputs that activated this visit (empty for the entry node's first visit).\n from: PipelineNodeSource[]\n // 1 for the first visit of this node.\n visit: number\n}\n\nexport interface PipelineNodeOutput {\n text: string\n usage?: PipelineUsage\n // One of the node's `routes` labels; anything else counts as no route.\n route?: string\n}\n\nexport interface PipelineNodeContext<E = never> {\n // Aborted when the run is aborted, or when another node of the wave failed. Where the runtime\n // has no AbortController, a stand-in with `aborted`, `reason`, `onabort`, `throwIfAborted()` and\n // `addEventListener` / `removeEventListener` for 'abort'.\n signal: AbortSignal\n pipeline: PipelineDefinition\n // Forward one of the node's own events; the runner adds `nodeId` and `visit`.\n emit: (event: E) => void\n}\n\nexport type PipelineNodeRunner<E = never> = (\n node: PipelineNode,\n input: PipelineNodeInput,\n ctx: PipelineNodeContext<E>,\n) => Promise<PipelineNodeOutput>\n\nexport type PipelineStop = 'maxRuns' | 'maxNodeVisits' | 'aborted'\n\nexport type PipelineEvent =\n | { type: 'pipeline.started'; pipeline?: string }\n | { type: 'pipeline.node.started'; nodeId: string; visit: number; from: string[] }\n | {\n type: 'pipeline.node.finished'\n nodeId: string\n visit: number\n text: string\n route?: string\n usage?: PipelineUsage\n }\n | { type: 'pipeline.node.failed'; nodeId: string; visit: number; error: string }\n // An activation a cap refused: the node does not start.\n | {\n type: 'pipeline.node.skipped'\n nodeId: string\n from: string[]\n reason: 'maxRuns' | 'maxNodeVisits'\n }\n // `visit` is the visit of the SOURCE node whose output decided the edge.\n | {\n type: 'pipeline.edge'\n from: string\n to: string\n edgeId: string\n visit: number\n fired: boolean\n }\n | { type: 'pipeline.finished'; stoppedBy?: PipelineStop; runs: number }\n\n// A node's own event, as the runner forwards it.\nexport type PipelineNodeEvent<E> = E & { nodeId: string; visit: number }\n\nexport type PipelineTraceEntry =\n | {\n type: 'node'\n nodeId: string\n visit: number\n wave: number\n from: string[]\n text: string\n route?: string\n usage?: PipelineUsage\n }\n | { type: 'edge'; from: string; to: string; edgeId: string; visit: number; fired: boolean }\n // An activation a cap refused: the node did not run.\n | { type: 'dropped'; nodeId: string; from: string[]; reason: 'maxRuns' | 'maxNodeVisits' }\n\nexport interface PipelineResult {\n // The output of the last terminal node to finish; several of the same wave are joined under\n // their names.\n text: string\n outputs: Record<string, { visit: number; text: string; route?: string }[]>\n // Node runs, edge decisions and dropped activations, in order.\n trace: PipelineTraceEntry[]\n usage: PipelineUsage\n stoppedBy?: PipelineStop\n // Node runs started.\n runs: number\n}\n\nexport interface PipelineIssue {\n code: string\n message: string\n nodeId?: string\n edgeId?: string\n // Position in `edges`.\n edgeIndex?: number\n}\n\nexport interface PipelineValidation {\n ok: boolean\n errors: PipelineIssue[]\n warnings: PipelineIssue[]\n}\n\nexport class PipelineValidationError extends Error {\n errors: PipelineIssue[]\n constructor(errors: PipelineIssue[]) {\n super(`Invalid pipeline: ${errors.map((e) => e.message).join('; ')}`)\n this.name = 'PipelineValidationError'\n this.errors = errors\n }\n}\n\nexport class PipelineNodeError extends Error {\n nodeId: string\n visit: number\n constructor(nodeId: string, visit: number, cause: unknown) {\n const reason = cause instanceof Error ? cause.message : String(cause)\n super(`Pipeline node \"${nodeId}\" failed (visit ${visit}): ${reason}`, { cause })\n this.name = 'PipelineNodeError'\n this.nodeId = nodeId\n this.visit = visit\n }\n}\n\n// ── `matches`: a matcher that cannot backtrack ───────────────────────────────\n//\n// A definition may come from someone else, and a backtracking regex engine (the browser's, Node's)\n// has no timeout: `(a+)+$` on thirty characters is enough to hang a tab. So a pattern is NOT run by\n// RegExp. It is compiled to a small program and simulated over the input one character at a time,\n// keeping the SET of positions the program can be in (a Pike VM): the work is bounded by\n// (input length) x (program size), whatever the pattern. The price is a subset of the syntax: no\n// backreferences and no lookaround (they are what needs backtracking), no \\p{...}.\n\ntype Assertion = 'start' | 'end' | 'word' | 'not-word'\n\ntype Ast =\n | { t: 'char'; c: number }\n | { t: 'any' }\n // Flat pairs: lo, hi, lo, hi ...\n | { t: 'set'; r: number[]; neg: boolean }\n | { t: 'assert'; k: Assertion }\n | { t: 'cat'; items: Ast[] }\n | { t: 'alt'; items: Ast[] }\n | { t: 'rep'; item: Ast; min: number; max: number }\n\ntype Inst =\n | { op: 'char'; c: number }\n | { op: 'any' }\n | { op: 'set'; r: number[]; neg: boolean }\n | { op: 'assert'; k: Assertion }\n | { op: 'split'; x: number; y: number }\n | { op: 'jmp'; x: number }\n | { op: 'match' }\n\nconst cp = (s: string): number => s.codePointAt(0) as number\n\nconst DIGIT = [0x30, 0x39]\nconst WORD = [0x30, 0x39, 0x41, 0x5a, 0x5f, 0x5f, 0x61, 0x7a]\nconst SPACE = [\n 0x09, 0x0d, 0x20, 0x20, 0xa0, 0xa0, 0x1680, 0x1680, 0x2000, 0x200a, 0x2028, 0x2029, 0x202f,\n 0x202f, 0x205f, 0x205f, 0x3000, 0x3000, 0xfeff, 0xfeff,\n]\nconst MAX_CODE_POINT = 0x10ffff\nconst MAX_REPEAT = 1000\n\nconst inRanges = (r: number[], c: number): boolean => {\n for (let i = 0; i < r.length; i += 2) {\n if (c >= r[i] && c <= r[i + 1]) return true\n }\n return false\n}\n\n// The ranges NOT covered by `r`.\nconst complement = (r: number[]): number[] => {\n const pairs: [number, number][] = []\n for (let i = 0; i < r.length; i += 2) pairs.push([r[i], r[i + 1]])\n pairs.sort((a, b) => a[0] - b[0])\n const out: number[] = []\n let next = 0\n for (const [lo, hi] of pairs) {\n if (lo > next) out.push(next, lo - 1)\n next = Math.max(next, hi + 1)\n }\n if (next <= MAX_CODE_POINT) out.push(next, MAX_CODE_POINT)\n return out\n}\n\nconst isLineEnd = (c: number): boolean => c === 0x0a || c === 0x0d || c === 0x2028 || c === 0x2029\nconst isWordChar = (c: number | undefined): boolean => c !== undefined && inRanges(WORD, c)\nconst isHex = (c: number | undefined): boolean =>\n c !== undefined && /^[0-9a-fA-F]$/.test(String.fromCodePoint(c))\nconst isDigit = (c: number | undefined): boolean => c !== undefined && c >= 0x30 && c <= 0x39\n\nconst parsePattern = (pattern: string): Ast => {\n const src = Array.from(pattern, cp)\n let i = 0\n const peek = (offset = 0): number | undefined => src[i + offset]\n const is = (ch: string, offset = 0): boolean => src[i + offset] === cp(ch)\n const fail = (message: string): never => {\n throw new Error(`${message} (at ${i})`)\n }\n\n const hex = (digits: number): number => {\n let value = 0\n for (let n = 0; n < digits; n++) {\n if (!isHex(peek())) fail('a bad hexadecimal escape')\n value = value * 16 + parseInt(String.fromCodePoint(src[i++]), 16)\n }\n return value\n }\n\n // After the backslash. A class shorthand comes back as ranges, anything else as one character.\n const escape = (inClass: boolean): { c: number } | { r: number[] } | { k: Assertion } => {\n const c = peek()\n if (c === undefined) return fail('a pattern cannot end with a backslash')\n i++\n const ch = String.fromCodePoint(c)\n switch (ch) {\n case 'd':\n return { r: DIGIT }\n case 'D':\n return { r: complement(DIGIT) }\n case 'w':\n return { r: WORD }\n case 'W':\n return { r: complement(WORD) }\n case 's':\n return { r: SPACE }\n case 'S':\n return { r: complement(SPACE) }\n case 'b':\n return inClass ? { c: 0x08 } : { k: 'word' }\n case 'B':\n return inClass ? fail('\\\\B is not allowed in a class') : { k: 'not-word' }\n case 'n':\n return { c: 0x0a }\n case 'r':\n return { c: 0x0d }\n case 't':\n return { c: 0x09 }\n case 'f':\n return { c: 0x0c }\n case 'v':\n return { c: 0x0b }\n case '0':\n return isDigit(peek()) ? fail('octal escapes are not supported') : { c: 0 }\n case 'x':\n return { c: hex(2) }\n case 'u': {\n if (!is('{')) return { c: hex(4) }\n i++\n let value = 0\n let digits = 0\n while (isHex(peek())) {\n value = value * 16 + parseInt(String.fromCodePoint(src[i++]), 16)\n digits++\n if (value > MAX_CODE_POINT) fail('a code point out of range')\n }\n if (!digits || !is('}')) fail('a bad \\\\u{...} escape')\n i++\n return { c: value }\n }\n case 'k':\n return fail('backreferences are not supported')\n case 'p':\n case 'P':\n return fail('\\\\p{...} is not supported')\n case 'c':\n return fail('\\\\c control escapes are not supported')\n default:\n if (isDigit(c)) return fail('backreferences are not supported')\n if (/^[a-zA-Z]$/.test(ch)) return fail(`unknown escape \\\\${ch}`)\n return { c }\n }\n }\n\n const klass = (): Ast => {\n const neg = is('^')\n if (neg) i++\n const r: number[] = []\n for (;;) {\n const c = peek()\n if (c === undefined) return fail('an unterminated class')\n if (is(']')) {\n i++\n break\n }\n i++\n let lo: number\n if (c === cp('\\\\')) {\n const e = escape(true)\n if ('r' in e) {\n r.push(...e.r)\n continue\n }\n lo = (e as { c: number }).c\n } else {\n lo = c\n }\n if (is('-') && peek(1) !== undefined && !is(']', 1)) {\n i++\n let hi = src[i++]\n if (hi === cp('\\\\')) {\n const e = escape(true)\n if (!('c' in e)) return fail('a bad range in a class')\n hi = e.c\n }\n if (hi < lo) fail('a range out of order in a class')\n r.push(lo, hi)\n } else {\n r.push(lo, lo)\n }\n }\n return { t: 'set', r, neg }\n }\n\n // `{n}`, `{n,}`, `{n,m}` at the cursor, or undefined when the brace is not a quantifier.\n const braces = (): { min: number; max: number } | undefined => {\n let j = i + 1\n const number = (): number | undefined => {\n const start = j\n while (isDigit(src[j])) j++\n return j > start ? Number(String.fromCodePoint(...src.slice(start, j))) : undefined\n }\n const min = number()\n if (min === undefined) return undefined\n let max: number | undefined = min\n if (src[j] === cp(',')) {\n j++\n max = number() ?? Infinity\n }\n if (src[j] !== cp('}')) return undefined\n i = j + 1\n if (max < min) fail('a quantifier out of order')\n if (min > MAX_REPEAT || (max !== Infinity && max > MAX_REPEAT)) {\n fail(`a repeat count above ${MAX_REPEAT}`)\n }\n return { min, max }\n }\n\n const atom = (): Ast => {\n const c = src[i++]\n switch (String.fromCodePoint(c)) {\n case '(': {\n if (is('?')) {\n if (is(':', 1)) {\n i += 2\n } else if (is('<', 1) && !is('=', 2) && !is('!', 2)) {\n // A named group: the name is dropped, nothing is captured.\n while (peek() !== undefined && !is('>')) i++\n if (peek() === undefined) fail('an unterminated group name')\n i++\n } else {\n fail('lookaround is not supported')\n }\n }\n const inner = alternation()\n if (!is(')')) fail('an unterminated group')\n i++\n return inner\n }\n case '[':\n return klass()\n case '.':\n return { t: 'any' }\n case '^':\n return { t: 'assert', k: 'start' }\n case '$':\n return { t: 'assert', k: 'end' }\n case '\\\\': {\n const e = escape(false)\n if ('k' in e) return { t: 'assert', k: e.k }\n return 'r' in e ? { t: 'set', r: e.r, neg: false } : { t: 'char', c: e.c }\n }\n case '*':\n case '+':\n case '?':\n return fail('nothing to repeat')\n case '{':\n i--\n if (braces()) fail('nothing to repeat')\n i++\n return { t: 'char', c }\n default:\n return { t: 'char', c }\n }\n }\n\n const repetition = (): Ast => {\n let item = atom()\n for (;;) {\n let q: { min: number; max: number } | undefined\n if (is('*')) q = { min: 0, max: Infinity }\n else if (is('+')) q = { min: 1, max: Infinity }\n else if (is('?')) q = { min: 0, max: 1 }\n if (q) i++\n else if (is('{')) q = braces()\n if (!q) return item\n if (item.t === 'assert') fail('nothing to repeat')\n // Lazy (`*?`): the same answer for a yes/no test.\n if (is('?')) i++\n item = { t: 'rep', item, min: q.min, max: q.max }\n }\n }\n\n const sequence = (): Ast => {\n const items: Ast[] = []\n while (peek() !== undefined && !is('|') && !is(')')) items.push(repetition())\n return items.length === 1 ? items[0] : { t: 'cat', items }\n }\n\n function alternation(): Ast {\n const items = [sequence()]\n while (is('|')) {\n i++\n items.push(sequence())\n }\n return items.length === 1 ? items[0] : { t: 'alt', items }\n }\n\n const ast = alternation()\n if (i < src.length) fail('an unmatched )')\n return ast\n}\n\nconst compileAst = (ast: Ast): Inst[] => {\n const prog: Inst[] = []\n const push = (inst: Inst): number => {\n if (prog.length >= PIPELINE_LIMITS.maxPatternProgram) {\n throw new Error(\n `the pattern is too complex (more than ${PIPELINE_LIMITS.maxPatternProgram} steps once its repeats are unrolled)`,\n )\n }\n prog.push(inst)\n return prog.length - 1\n }\n const emit = (node: Ast): void => {\n switch (node.t) {\n case 'char':\n push({ op: 'char', c: node.c })\n return\n case 'any':\n push({ op: 'any' })\n return\n case 'set':\n push({ op: 'set', r: node.r, neg: node.neg })\n return\n case 'assert':\n push({ op: 'assert', k: node.k })\n return\n case 'cat':\n for (const item of node.items) emit(item)\n return\n case 'alt': {\n const exits: Extract<Inst, { op: 'jmp' }>[] = []\n node.items.forEach((item, index) => {\n if (index === node.items.length - 1) {\n emit(item)\n return\n }\n const split: Inst = { op: 'split', x: 0, y: 0 }\n split.x = push(split) + 1\n emit(item)\n const exit: Extract<Inst, { op: 'jmp' }> = { op: 'jmp', x: 0 }\n push(exit)\n exits.push(exit)\n split.y = prog.length\n })\n for (const exit of exits) exit.x = prog.length\n return\n }\n case 'rep': {\n for (let n = 0; n < node.min; n++) emit(node.item)\n if (node.max === Infinity) {\n const split: Inst = { op: 'split', x: 0, y: 0 }\n const at = push(split)\n split.x = at + 1\n emit(node.item)\n push({ op: 'jmp', x: at })\n split.y = prog.length\n return\n }\n const skips: Extract<Inst, { op: 'split' }>[] = []\n for (let n = node.min; n < node.max; n++) {\n const split: Extract<Inst, { op: 'split' }> = { op: 'split', x: 0, y: 0 }\n split.x = push(split) + 1\n skips.push(split)\n emit(node.item)\n }\n for (const split of skips) split.y = prog.length\n return\n }\n }\n }\n emit(ast)\n push({ op: 'match' })\n return prog\n}\n\nconst ALLOWED_FLAGS = 'imsu'\n\n// A compiled `matches` condition: does the pattern occur anywhere in the text?\ntype Matcher = (text: string) => boolean\n\n// Throws an Error that says what is wrong with the pattern or the flags.\nconst compileMatcher = (pattern: string, flags = ''): Matcher => {\n if (typeof pattern !== 'string' || pattern.length === 0) {\n throw new Error('the pattern is empty')\n }\n if (pattern.length > PIPELINE_LIMITS.maxPatternLength) {\n throw new Error(`the pattern is longer than ${PIPELINE_LIMITS.maxPatternLength} characters`)\n }\n if (typeof flags !== 'string') throw new Error('flags must be a string')\n for (const flag of flags) {\n if (!ALLOWED_FLAGS.includes(flag)) {\n throw new Error(`flag \"${flag}\" is not allowed (allowed: ${ALLOWED_FLAGS})`)\n }\n }\n if (new Set(flags).size !== flags.length) throw new Error('a flag is repeated')\n // The subset must also be a regular expression as JavaScript reads it. Compiling is linear;\n // the RegExp is never executed.\n try {\n new RegExp(pattern, flags)\n } catch (err) {\n throw new Error(err instanceof Error ? err.message : String(err))\n }\n const prog = compileAst(parsePattern(pattern))\n const ignoreCase = flags.includes('i')\n const multiline = flags.includes('m')\n const dotAll = flags.includes('s')\n // A case mapping that is not one character for one character (ß → SS) is no mapping.\n const single = (c: number, mapped: string): number =>\n mapped.length === String.fromCodePoint(cp(mapped)).length ? cp(mapped) : c\n const lower = (c: number): number => single(c, String.fromCodePoint(c).toLowerCase())\n const upper = (c: number): number => single(c, String.fromCodePoint(c).toUpperCase())\n\n return (text: string): boolean => {\n const input = Array.from(text.slice(0, PIPELINE_LIMITS.conditionInputChars), cp)\n const n = input.length\n // mark[pc] === generation: this program position is already on the list for this character.\n const mark = new Int32Array(prog.length)\n let generation = 0\n let matched = false\n const stack: number[] = []\n\n const holds = (k: Assertion, pos: number): boolean => {\n switch (k) {\n case 'start':\n return pos === 0 || (multiline && isLineEnd(input[pos - 1]))\n case 'end':\n return pos === n || (multiline && isLineEnd(input[pos]))\n case 'word':\n return isWordChar(input[pos - 1]) !== isWordChar(input[pos])\n case 'not-word':\n return isWordChar(input[pos - 1]) === isWordChar(input[pos])\n }\n }\n\n // Follow the jumps from `start` and list every position that waits for a character.\n const add = (list: number[], start: number, pos: number): void => {\n stack.push(start)\n while (stack.length) {\n const pc = stack.pop() as number\n if (mark[pc] === generation) continue\n mark[pc] = generation\n const inst = prog[pc]\n switch (inst.op) {\n case 'jmp':\n stack.push(inst.x)\n break\n case 'split':\n stack.push(inst.y, inst.x)\n break\n case 'assert':\n if (holds(inst.k, pos)) stack.push(pc + 1)\n break\n case 'match':\n matched = true\n break\n default:\n list.push(pc)\n }\n }\n }\n\n let current: number[] = []\n let next: number[] = []\n generation++\n add(current, 0, 0)\n for (let pos = 0; pos < n && !matched; pos++) {\n const c = input[pos]\n const lo = ignoreCase ? lower(c) : c\n const up = ignoreCase ? upper(c) : c\n generation++\n for (const pc of current) {\n const inst = prog[pc]\n let ok = false\n if (inst.op === 'char') {\n ok =\n inst.c === c || (ignoreCase && (inst.c === lo || inst.c === up || lower(inst.c) === lo))\n } else if (inst.op === 'any') {\n ok = dotAll || !isLineEnd(c)\n } else if (inst.op === 'set') {\n const inside =\n inRanges(inst.r, c) || (ignoreCase && (inRanges(inst.r, lo) || inRanges(inst.r, up)))\n ok = inside !== inst.neg\n }\n if (ok) add(next, pc + 1, pos + 1)\n }\n // A match may start at any character.\n add(next, 0, pos + 1)\n current = next\n next = []\n }\n return matched\n }\n}\n\n// ── Conditions ───────────────────────────────────────────────────────────────\n\nconst CONDITION_KINDS = ['always', 'contains', 'matches', 'route', 'otherwise']\n\n// Does a condition hold for a node's output? `otherwise` is not decided here: it depends on the\n// node's other edges, and answers false. Throws on an invalid pattern - validate first.\nexport const testPipelineCondition = (\n when: PipelineCondition | undefined,\n output: { text: string; route?: string },\n matcher?: (text: string) => boolean,\n): boolean => {\n if (!when || when.kind === 'always') return true\n switch (when.kind) {\n case 'contains': {\n const text = output.text.slice(0, PIPELINE_LIMITS.conditionInputChars)\n return when.caseSensitive\n ? text.includes(when.text)\n : text.toLowerCase().includes(when.text.toLowerCase())\n }\n case 'matches':\n return (matcher ?? compileMatcher(when.pattern, when.flags))(output.text)\n case 'route':\n return output.route !== undefined && output.route === when.label\n default:\n return false\n }\n}\n\n// ── Validation ───────────────────────────────────────────────────────────────\n\nconst isRecord = (v: unknown): v is Record<string, unknown> =>\n typeof v === 'object' && v !== null && !Array.isArray(v)\nconst isId = (v: unknown): v is string => typeof v === 'string' && v.trim().length > 0\n\n// The id of an edge: its own, or `e<position>` when it has none.\nconst edgeIdOf = (edge: unknown, index: number): string =>\n isRecord(edge) && isId(edge.id) ? edge.id : `e${index}`\n\nconst edgeRef = (edge: unknown, index: number): { edgeId: string; edgeIndex: number } => ({\n edgeId: edgeIdOf(edge, index),\n edgeIndex: index,\n})\n\n// A copy of a definition in which every edge has an id (`e0`, `e1`, ... for the ones that had\n// none), so an event or an editor can always name an edge. Editing the original afterwards\n// changes nothing in the copy.\nexport const normalizePipeline = (definition: PipelineDefinition): PipelineDefinition => {\n const def = JSON.parse(JSON.stringify(definition)) as PipelineDefinition\n if (isRecord(def) && Array.isArray(def.edges)) {\n def.edges.forEach((edge, index) => {\n if (isRecord(edge)) edge.id = edgeIdOf(edge, index)\n })\n }\n return def\n}\n\nconst inRange = (v: unknown, max: number): boolean =>\n typeof v === 'number' && Number.isInteger(v) && v >= 1 && v <= max\n\n// Check a definition. Pure: nothing is run, and a pattern is compiled but never executed.\nexport const validatePipeline = (definition: PipelineDefinition): PipelineValidation => {\n const errors: PipelineIssue[] = []\n const warnings: PipelineIssue[] = []\n const error = (code: string, message: string, at: Partial<PipelineIssue> = {}): void => {\n errors.push({ code, message, ...at })\n }\n const done = (): PipelineValidation => ({ ok: errors.length === 0, errors, warnings })\n\n const def = definition as unknown\n if (!isRecord(def)) {\n error('definition', 'a pipeline definition must be an object')\n return done()\n }\n if (def.version !== 1) {\n error('version', `unsupported pipeline version ${JSON.stringify(def.version)} (expected 1)`)\n }\n const nodes = Array.isArray(def.nodes) ? (def.nodes as unknown[]) : undefined\n const edges = Array.isArray(def.edges) ? (def.edges as unknown[]) : undefined\n if (!nodes || nodes.length === 0) error('nodes', 'a pipeline needs at least one node')\n if (!edges) error('edges', '`edges` must be an array')\n if (nodes && nodes.length > PIPELINE_LIMITS.maxNodes) {\n error('nodes', `more than ${PIPELINE_LIMITS.maxNodes} nodes`)\n }\n if (edges && edges.length > PIPELINE_LIMITS.maxEdges) {\n error('edges', `more than ${PIPELINE_LIMITS.maxEdges} edges`)\n }\n\n const ids = new Set<string>()\n const routesOf = new Map<string, string[]>()\n for (const [index, node] of (nodes ?? []).entries()) {\n if (!isRecord(node) || !isId(node.id)) {\n error('node.id', `node #${index + 1} has no id`)\n continue\n }\n const nodeId = node.id\n if (ids.has(nodeId)) {\n error('node.duplicate', `duplicate node id \"${nodeId}\"`, { nodeId })\n continue\n }\n ids.add(nodeId)\n if (node.join !== undefined && node.join !== 'all' && node.join !== 'any') {\n error('node.join', `node \"${nodeId}\": join must be \"all\" or \"any\"`, { nodeId })\n }\n const labels: string[] = []\n if (node.routes !== undefined) {\n if (!Array.isArray(node.routes) || node.routes.length > PIPELINE_LIMITS.maxRoutes) {\n error(\n 'node.routes',\n `node \"${nodeId}\": routes must be a list of at most ${PIPELINE_LIMITS.maxRoutes}`,\n { nodeId },\n )\n } else {\n for (const route of node.routes as unknown[]) {\n if (!isRecord(route) || !isId(route.label)) {\n error('node.routes', `node \"${nodeId}\": a route has no label`, { nodeId })\n } else if (labels.includes(route.label)) {\n error('node.routes', `node \"${nodeId}\": duplicate route \"${route.label}\"`, { nodeId })\n } else {\n labels.push(route.label)\n }\n }\n }\n }\n routesOf.set(nodeId, labels)\n }\n\n if (!isId(def.entry)) {\n error('entry', 'the pipeline has no entry node')\n } else if (!ids.has(def.entry)) {\n error('entry', `the entry node \"${def.entry}\" does not exist`)\n }\n\n const out = new Map<string, string[]>()\n const edgeIds = new Set<string>()\n const otherwise = new Set<string>()\n const routed = new Set<string>()\n for (const [index, edge] of (edges ?? []).entries()) {\n const at = edgeRef(edge, index)\n const label = `edge \"${at.edgeId}\"`\n if (!isRecord(edge)) {\n error('edge', `${label} is not an object`, at)\n continue\n }\n // Given ids and the ones handed out (`e<position>`) share one namespace.\n if (edge.id !== undefined && !isId(edge.id)) error('edge.id', `${label} has an empty id`, at)\n if (edgeIds.has(at.edgeId)) error('edge.duplicate', `duplicate edge id \"${at.edgeId}\"`, at)\n edgeIds.add(at.edgeId)\n const from = edge.from\n const to = edge.to\n const fromOk = isId(from) && ids.has(from)\n const toOk = isId(to) && ids.has(to)\n if (!fromOk)\n error('edge.from', `${label} starts at an unknown node ${JSON.stringify(from)}`, at)\n if (!toOk) error('edge.to', `${label} leads to an unknown node ${JSON.stringify(to)}`, at)\n if (fromOk && toOk) out.set(from, [...(out.get(from) ?? []), to])\n\n const when = edge.when\n if (when === undefined) continue\n if (!isRecord(when) || !CONDITION_KINDS.includes(when.kind as string)) {\n error('edge.when', `${label} has an unknown condition`, at)\n continue\n }\n switch (when.kind) {\n case 'contains':\n if (typeof when.text !== 'string' || when.text.length === 0) {\n error('edge.when', `${label}: \"contains\" needs a text`, at)\n }\n break\n case 'matches':\n try {\n compileMatcher(when.pattern as string, (when.flags ?? '') as string)\n } catch (err) {\n error('edge.pattern', `${label}: ${(err as Error).message}`, at)\n }\n break\n case 'route':\n if (fromOk) routed.add(from)\n if (!isId(when.label)) {\n error('edge.route', `${label}: \"route\" needs a label`, at)\n } else if (fromOk && !(routesOf.get(from) ?? []).includes(when.label)) {\n error(\n 'edge.route',\n `${label}: node \"${from}\" has no route \"${when.label}\"`,\n fromOk ? { ...at, nodeId: from } : at,\n )\n }\n break\n case 'otherwise':\n if (fromOk) {\n if (otherwise.has(from)) {\n error('edge.otherwise', `node \"${from}\" has more than one \"otherwise\" edge`, {\n ...at,\n nodeId: from,\n })\n }\n otherwise.add(from)\n }\n break\n }\n }\n\n if (def.limits !== undefined) {\n if (!isRecord(def.limits)) {\n error('limits', '`limits` must be an object')\n } else {\n const { maxNodeVisits, maxRuns } = def.limits\n if (\n maxNodeVisits !== undefined &&\n !inRange(maxNodeVisits, PIPELINE_LIMITS.maxNodeVisitsCeiling)\n ) {\n error(\n 'limits',\n `limits.maxNodeVisits must be a whole number from 1 to ${PIPELINE_LIMITS.maxNodeVisitsCeiling}`,\n )\n }\n if (maxRuns !== undefined && !inRange(maxRuns, PIPELINE_LIMITS.maxRunsCeiling)) {\n error(\n 'limits',\n `limits.maxRuns must be a whole number from 1 to ${PIPELINE_LIMITS.maxRunsCeiling}`,\n )\n }\n }\n }\n\n // Warnings describe a graph that is at least well-formed.\n if (errors.length > 0 || !isId(def.entry)) return done()\n\n const reached = new Set<string>([def.entry])\n const queue = [def.entry]\n while (queue.length) {\n for (const to of out.get(queue.pop() as string) ?? []) {\n if (!reached.has(to)) {\n reached.add(to)\n queue.push(to)\n }\n }\n }\n for (const nodeId of ids) {\n if (!reached.has(nodeId)) {\n warnings.push({\n code: 'unreachable',\n message: `node \"${nodeId}\" cannot be reached from the entry node`,\n nodeId,\n })\n }\n if ((routesOf.get(nodeId) ?? []).length > 0 && !routed.has(nodeId)) {\n warnings.push({\n code: 'routes.unused',\n message: `node \"${nodeId}\" has routes but no edge with a \"route\" condition`,\n nodeId,\n })\n }\n }\n\n // A cycle is allowed (the caps bound it); say so once, naming one.\n const state = new Map<string, 'open' | 'closed'>()\n const path: string[] = []\n const findCycle = (nodeId: string): string[] | undefined => {\n state.set(nodeId, 'open')\n path.push(nodeId)\n for (const to of out.get(nodeId) ?? []) {\n if (state.get(to) === 'open') return [...path.slice(path.indexOf(to)), to]\n if (!state.has(to)) {\n const found = findCycle(to)\n if (found) return found\n }\n }\n path.pop()\n state.set(nodeId, 'closed')\n return undefined\n }\n const cycle = findCycle(def.entry)\n if (cycle) {\n warnings.push({\n code: 'cycle',\n message: `the pipeline has a loop (${cycle.join(' → ')}); limits.maxNodeVisits and limits.maxRuns bound it`,\n nodeId: cycle[0],\n })\n }\n return done()\n}\n\n// ── What a node is told, and how it picks a route ────────────────────────────\n\nconst titleOf = (source: { nodeId: string; name?: string }): string => source.name || source.nodeId\n\n// The node's input as the plain text its agent reads: the request, then each predecessor's output\n// under its name.\nexport const renderPipelineNodeInput = (input: PipelineNodeInput): string => {\n if (input.from.length === 0 && input.visit <= 1) return input.request\n const parts = [`Request:\\n${input.request}`]\n for (const source of input.from) {\n parts.push(`Output of \"${titleOf(source)}\":\\n${source.text}`)\n }\n if (input.visit > 1) parts.push(`(This is visit ${input.visit} of this step.)`)\n return parts.join('\\n\\n')\n}\n\nexport const PIPELINE_ROUTER_SYSTEM =\n 'You are the Router of one step in a pipeline of agents. The step has answered. Pick the ONE ' +\n 'route label that fits its answer, from the list you are given. Answer with a label exactly as ' +\n 'it is written in the list, and nothing else.'\n\n// Enough of a long answer to judge it by: verdicts tend to sit at the end.\nconst ROUTER_HEAD_CHARS = 2000\nconst ROUTER_TAIL_CHARS = 6000\n\n// The prompt of the small call that picks a route.\nexport const renderPipelineRoutePrompt = (node: PipelineNode, text: string): string => {\n const routes = (node.routes ?? [])\n .map((r) => `- ${r.label}${r.description ? `: ${r.description}` : ''}`)\n .join('\\n')\n const answer =\n text.length > ROUTER_HEAD_CHARS + ROUTER_TAIL_CHARS\n ? `${text.slice(0, ROUTER_HEAD_CHARS)}\\n[...]\\n${text.slice(-ROUTER_TAIL_CHARS)}`\n : text\n return [\n `Step: ${titleOf({ nodeId: node.id, name: node.name })}`,\n node.instructions ? `Its role:\\n${node.instructions}` : '',\n `Routes:\\n${routes}`,\n `The step's answer:\\n${answer}`,\n 'Which route? Answer with one label from the list.',\n ]\n .filter(Boolean)\n .join('\\n\\n')\n}\n\n// The label a router's answer names, or undefined: an answer that is not one of the node's labels\n// is no route. Takes the structured `{ route }`, a bare label, or JSON text carrying one.\nexport const matchPipelineRoute = (node: PipelineNode, answer: unknown): string | undefined => {\n const labels = (node.routes ?? []).map((r) => r.label)\n let value: unknown = answer\n if (typeof value === 'string') {\n const text = value.trim()\n if (text.startsWith('{')) {\n try {\n value = JSON.parse(text)\n } catch {\n value = text\n }\n } else {\n value = text\n }\n }\n if (isRecord(value)) value = value.route\n if (typeof value !== 'string') return undefined\n const wanted = value\n .trim()\n .replace(/^[\"'`]+|[\"'`.]+$/g, '')\n .toLowerCase()\n return labels.find((label) => label.toLowerCase() === wanted)\n}\n\n// ── The scheduler ────────────────────────────────────────────────────────────\n\ninterface PlannedEdge {\n edge: PipelineEdge\n matcher?: Matcher\n}\n\n// A validated definition, ready to run. It holds maps and functions, not JSON: prepare it where it\n// runs (preparePipeline is pure, so preparing the same definition twice gives the same plan).\nexport interface PipelinePlan {\n // The normalised copy (every edge has an id).\n definition: PipelineDefinition\n nodes: Map<string, PipelineNode>\n outgoing: Map<string, PlannedEdge[]>\n // The definition's limits, or the defaults.\n maxNodeVisits: number\n maxRuns: number\n // Can `from` reach `to` along the edges (conditions aside)?\n reaches: (from: string, to: string) => boolean\n}\n\n// Validate and compile a definition. Throws PipelineValidationError. The definition is copied\n// (normalizePipeline): editing the original afterwards does not change the plan.\nexport const preparePipeline = (definition: PipelineDefinition): PipelinePlan => {\n const { errors } = validatePipeline(definition)\n if (errors.length > 0) throw new PipelineValidationError(errors)\n const def = normalizePipeline(definition)\n const nodes = new Map(def.nodes.map((n) => [n.id, n]))\n const outgoing = new Map<string, PlannedEdge[]>(def.nodes.map((n) => [n.id, []]))\n for (const edge of def.edges) {\n const planned: PlannedEdge = { edge }\n if (edge.when?.kind === 'matches') {\n planned.matcher = compileMatcher(edge.when.pattern, edge.when.flags)\n }\n outgoing.get(edge.from)?.push(planned)\n }\n const closure = new Map<string, Set<string>>()\n const descendants = (from: string): Set<string> => {\n let seen = closure.get(from)\n if (!seen) {\n seen = new Set<string>()\n const queue = [from]\n while (queue.length) {\n for (const { edge } of outgoing.get(queue.pop() as string) ?? []) {\n if (!seen.has(edge.to)) {\n seen.add(edge.to)\n queue.push(edge.to)\n }\n }\n }\n closure.set(from, seen)\n }\n return seen\n }\n return {\n definition: def,\n nodes,\n outgoing,\n maxNodeVisits: def.limits?.maxNodeVisits ?? PIPELINE_LIMITS.maxNodeVisits,\n maxRuns: def.limits?.maxRuns ?? PIPELINE_LIMITS.maxRuns,\n reaches: (from, to) => descendants(from).has(to),\n }\n}\n\n// What `from` reaches in ONE pass of every loop: along the edges, but never along a loop's way\n// back - an edge whose target every path from the entry to its source passes through (the target\n// dominates the source: it is the loop's head). A cycle with more than one way in has no head, so\n// no such edge, and stays a cycle. It depends on the graph, not on the order of `edges`.\nconst passReach = (plan: PipelinePlan): ((from: string, to: string) => boolean) => {\n const entry = plan.definition.entry\n // The nodes the entry reaches, and each one's predecessors among them.\n const order = [entry]\n const preds = new Map<string, string[]>([[entry, []]])\n for (let i = 0; i < order.length; i++) {\n for (const { edge } of plan.outgoing.get(order[i]) ?? []) {\n if (!preds.has(edge.to)) {\n preds.set(edge.to, [])\n order.push(edge.to)\n }\n ;(preds.get(edge.to) as string[]).push(order[i])\n }\n }\n // The dominators: the entry's are itself; a node's are itself and what all its predecessors'\n // have in common. Iterated until nothing changes (the sets only shrink).\n const dom = new Map<string, Set<string>>()\n for (const nodeId of order) dom.set(nodeId, new Set(nodeId === entry ? [entry] : order))\n for (let changed = true; changed;) {\n changed = false\n for (const nodeId of order) {\n if (nodeId === entry) continue\n const [first, ...rest] = (preds.get(nodeId) as string[]).map((p) => dom.get(p) as Set<string>)\n const next = new Set([nodeId])\n for (const d of first) if (rest.every((set) => set.has(d))) next.add(d)\n if (next.size < (dom.get(nodeId) as Set<string>).size) {\n dom.set(nodeId, next)\n changed = true\n }\n }\n }\n const closure = new Map<string, Set<string>>()\n return (from, to) => {\n let seen = closure.get(from)\n if (!seen) {\n const found = new Set<string>()\n const queue = [from]\n while (queue.length) {\n const at = queue.pop() as string\n for (const { edge } of plan.outgoing.get(at) ?? []) {\n // A loop's way back: the next pass, not this one.\n if (dom.get(at)?.has(edge.to) || found.has(edge.to)) continue\n found.add(edge.to)\n queue.push(edge.to)\n }\n }\n closure.set(from, (seen = found))\n }\n return seen.has(to)\n }\n}\n\n// What an aborted run does: 'reject' with an AbortError, or 'resolve' with what it has and\n// `stoppedBy: 'aborted'`. Each package's createPipeline follows its own agent.\nexport type PipelineAbortBehaviour = 'reject' | 'resolve'\n\nexport interface PipelineGraphRunOptions<E = never> {\n // The request: every node's `input.request`.\n input: string\n // Read through `aborted` and `addEventListener` / `removeEventListener('abort')` only.\n signal?: AbortSignal\n // The pipeline.* events, and the nodes' own (`ctx.emit`) with `nodeId` and `visit` added. A\n // handler that throws does not break the run.\n onEvent?: (event: PipelineEvent | PipelineNodeEvent<E>) => void\n // Default 'reject'.\n onAbort?: PipelineAbortBehaviour\n}\n\n// One finished visit, and how many of the activations it fired are still alive.\ninterface VisitRecord {\n nodeId: string\n name?: string\n text: string\n wave: number\n live: number\n}\n\ninterface Activation {\n source: PipelineNodeSource\n record: VisitRecord\n}\n\n// The error an aborted run rejects with: a DOMException named AbortError, as the platform's own\n// APIs throw. A runtime without DOMException gets an Error with the same name and message.\nconst abortError = (): Error => {\n if (typeof DOMException === 'function') return new DOMException('Aborted', 'AbortError')\n const error = new Error('Aborted')\n error.name = 'AbortError'\n return error\n}\n\n// How a run stops the visits still in flight (their `ctx.signal`).\ninterface Stopper {\n signal: AbortSignal\n abort: () => void\n}\n\ntype AbortListener =\n ((event: { type: 'abort' }) => void) | { handleEvent: (event: { type: 'abort' }) => void }\n\n// An AbortController where the runtime has one. Without it, a stand-in with the part of\n// AbortSignal a runner reads: `aborted`, `reason`, `onabort`, `throwIfAborted()` and\n// `addEventListener` / `removeEventListener` for 'abort' (a listener added twice runs once; the\n// signal aborts once, so `once` changes nothing). A listener that throws does not stop the others,\n// nor the run.\nconst createStopper = (): Stopper => {\n if (typeof AbortController === 'function') {\n const controller = new AbortController()\n return { signal: controller.signal, abort: () => controller.abort() }\n }\n const listeners: AbortListener[] = []\n const signal = {\n aborted: false,\n reason: undefined as unknown,\n onabort: null as ((event: { type: 'abort' }) => void) | null,\n addEventListener(type: string, listener: AbortListener | null): void {\n if (type === 'abort' && listener && !listeners.includes(listener)) listeners.push(listener)\n },\n removeEventListener(type: string, listener: AbortListener | null): void {\n const index = listener ? listeners.indexOf(listener) : -1\n if (type === 'abort' && index >= 0) listeners.splice(index, 1)\n },\n throwIfAborted(): void {\n if (signal.aborted) throw signal.reason\n },\n }\n const abort = (): void => {\n if (signal.aborted) return\n signal.aborted = true\n signal.reason = abortError()\n const event = { type: 'abort' as const, target: signal }\n const call = (fn: (event: { type: 'abort' }) => void, thisArg: unknown): void => {\n try {\n fn.call(thisArg, event)\n } catch {\n // As a DOM listener's error: reported nowhere here, and the others still run.\n }\n }\n for (const listener of listeners.splice(0)) {\n if (typeof listener === 'function') call(listener, signal)\n else call(listener.handleEvent, listener)\n }\n if (typeof signal.onabort === 'function') call(signal.onabort, signal)\n }\n return { signal: signal as unknown as AbortSignal, abort }\n}\n\nconst addUsage = (into: PipelineUsage, usage: PipelineUsage | undefined): void => {\n if (!usage) return\n const sum = into as unknown as Record<string, number>\n for (const [key, value] of Object.entries(usage)) {\n if (typeof value === 'number' && Number.isFinite(value)) sum[key] = (sum[key] ?? 0) + value\n }\n}\n\n// Run a prepared pipeline once, with `runNode` running every node: the scheduler createPipeline\n// uses, public so a host can run a graph with a runner of its own (a queue job, a remote worker,\n// a child workflow). The scheduling rules (waves, the join rule, the caps) are in the package's\n// docs; the runner's side of the contract:\n// - `runNode(node, input, ctx)` is called once per visit, never for an activation a cap refused.\n// It resolves with `{ text, usage?, route? }`: `text` is what the edges test (anything but a\n// string counts as ''), `usage` is added to the result's, and `route` is one of `node.routes`'\n// labels exactly as written - anything else is no route (`matchPipelineRoute` turns a model's\n// answer into a label).\n// - The visits of a wave are started in the order their nodes were first activated, before any is\n// awaited; the next wave starts once all of them have settled. A visit's output is applied\n// (events, trace, edges) when it settles, so the order the answers arrive in is part of the\n// input: the same answers in the same order give the same run.\n// - A runner that rejects fails the run: the other visits' `ctx.signal` is aborted, nothing they\n// do afterwards counts, and the run rejects with a PipelineNodeError, whatever `onAbort` says.\n// - `options.signal` aborting does the same to the visits in flight and settles the run at once,\n// without waiting for them: it rejects with an AbortError (`onAbort: 'reject'`, the default) or\n// resolves with what it has and `stoppedBy: 'aborted'` ('resolve').\n// - `ctx.emit(event)` forwards one of the node's own events, with `nodeId` and `visit`, until the\n// run is over.\nexport const runPipelineGraph = async <E = never>(\n plan: PipelinePlan,\n runNode: PipelineNodeRunner<E>,\n options: PipelineGraphRunOptions<E>,\n): Promise<PipelineResult> => {\n const { definition } = plan\n const onAbort = options.onAbort ?? 'reject'\n const stopper = createStopper()\n // Set once the run is over for the nodes still in flight: their events and results are ignored.\n let halted: 'aborted' | 'failed' | undefined\n let halt: (err: Error) => void = () => {}\n const haltPromise = new Promise<never>((_, reject) => {\n halt = reject\n })\n haltPromise.catch(() => {})\n\n const emit = (event: PipelineEvent | PipelineNodeEvent<E>): void => {\n try {\n options.onEvent?.(event)\n } catch {\n // A handler that throws must not break the run.\n }\n }\n\n const visits = new Map<string, number>()\n const usage: PipelineUsage = { inputTokens: 0, outputTokens: 0, totalTokens: 0 }\n const outputs: PipelineResult['outputs'] = {}\n const trace: PipelineTraceEntry[] = []\n const terminals: VisitRecord[] = []\n const capped = new Set<'maxRuns' | 'maxNodeVisits'>()\n let runs = 0\n let wave = 0\n // Activated nodes that have not started, in the order they were first activated.\n const pending = new Map<string, Activation[]>([[definition.entry, []]])\n\n const result = (stoppedBy?: PipelineStop): PipelineResult => {\n const lastWave = Math.max(-1, ...terminals.map((t) => t.wave))\n const last = terminals.filter((t) => t.wave === lastWave)\n const text =\n last.length === 1\n ? last[0].text\n : last.map((t) => `## ${titleOf(t)}\\n\\n${t.text}`).join('\\n\\n')\n return { text, outputs, trace, usage, ...(stoppedBy ? { stoppedBy } : {}), runs }\n }\n\n const onOuterAbort = (): void => {\n if (halted) return\n halted = 'aborted'\n stopper.abort()\n halt(abortError())\n }\n\n const visit = async (nodeId: string, activations: Activation[]): Promise<void> => {\n const node = plan.nodes.get(nodeId) as PipelineNode\n const number = (visits.get(nodeId) ?? 0) + 1\n visits.set(nodeId, number)\n runs++\n const from = activations.map((a) => a.source.nodeId)\n emit({ type: 'pipeline.node.started', nodeId, visit: number, from })\n\n let output: PipelineNodeOutput\n try {\n output = await runNode(\n node,\n { request: options.input, from: activations.map((a) => ({ ...a.source })), visit: number },\n {\n signal: stopper.signal,\n pipeline: definition,\n emit: (event) => {\n if (!halted) emit({ ...event, nodeId, visit: number })\n },\n },\n )\n } catch (err) {\n // Already over (an abort, or another node failed first): this is the fallout, not a cause.\n if (halted) return\n halted = 'failed'\n const failure = new PipelineNodeError(nodeId, number, err)\n emit({\n type: 'pipeline.node.failed',\n nodeId,\n visit: number,\n error: err instanceof Error ? err.message : String(err),\n })\n stopper.abort()\n halt(failure)\n return\n }\n if (halted) return\n\n const text = typeof output?.text === 'string' ? output.text : ''\n const route = (node.routes ?? []).some((r) => r.label === output?.route)\n ? output.route\n : undefined\n addUsage(usage, output?.usage)\n const optional = {\n ...(route !== undefined ? { route } : {}),\n ...(output?.usage ? { usage: output.usage } : {}),\n }\n ;(outputs[nodeId] ??= []).push({\n visit: number,\n text,\n ...(route !== undefined ? { route } : {}),\n })\n trace.push({ type: 'node', nodeId, visit: number, wave, from, text, ...optional })\n emit({ type: 'pipeline.node.finished', nodeId, visit: number, text, ...optional })\n\n // Every edge whose condition holds fires; `otherwise` only when none of the others did.\n const edges = plan.outgoing.get(nodeId) ?? []\n const fired = edges.map(({ edge, matcher }) =>\n testPipelineCondition(edge.when, { text, route }, matcher),\n )\n const anyFired = fired.some(Boolean)\n const record: VisitRecord = { nodeId, name: node.name, text, wave, live: 0 }\n const targets = new Set<string>()\n edges.forEach(({ edge }, index) => {\n const fires = edge.when?.kind === 'otherwise' ? !anyFired : fired[index]\n const decision = {\n from: nodeId,\n to: edge.to,\n edgeId: edge.id as string,\n visit: number,\n fired: fires,\n }\n trace.push({ type: 'edge', ...decision })\n emit({ type: 'pipeline.edge', ...decision })\n // Two edges to the same node carry the output once.\n if (!fires || targets.has(edge.to)) return\n targets.add(edge.to)\n const waiting = pending.get(edge.to) ?? []\n waiting.push({ source: { nodeId, ...(node.name ? { name: node.name } : {}), text }, record })\n pending.set(edge.to, waiting)\n })\n record.live = targets.size\n // Terminal: it ran and activated nothing.\n if (record.live === 0) terminals.push(record)\n }\n\n // A cap refused the activation: the visits that fired it may have become terminal.\n const drop = (nodeId: string, activations: Activation[], reason: 'maxRuns' | 'maxNodeVisits') => {\n capped.add(reason)\n const from = activations.map((a) => a.source.nodeId)\n trace.push({ type: 'dropped', nodeId, from, reason })\n emit({ type: 'pipeline.node.skipped', nodeId, from, reason })\n for (const { record } of activations) {\n record.live--\n if (record.live === 0) terminals.push(record)\n }\n }\n\n // join 'all': wait while another pending node can still reach this one through the graph (a\n // path to a node never needs to pass through it, so plain reachability is the whole test).\n const deferred = (nodeId: string, all: string[], reaches = plan.reaches): boolean =>\n (plan.nodes.get(nodeId)?.join ?? 'all') === 'all' &&\n all.some((other) => other !== nodeId && reaches(other, nodeId))\n // Made the first time every waiting node waits for another (passReach).\n let inPass: ((from: string, to: string) => boolean) | undefined\n\n emit({ type: 'pipeline.started', ...(definition.name ? { pipeline: definition.name } : {}) })\n options.signal?.addEventListener('abort', onOuterAbort, { once: true })\n try {\n if (options.signal?.aborted) onOuterAbort()\n while (pending.size > 0 && !halted) {\n const waiting = [...pending.keys()]\n let ready = waiting.filter((nodeId) => !deferred(nodeId, waiting))\n // Everybody waits for somebody: they reach each other through a loop. A wait that goes back\n // through a loop's head is for the loop's next pass, so only the waits within this pass\n // count: the nodes nothing reaches within it start, and a join inside the loop goes on\n // waiting for its slower branch.\n if (ready.length === 0) {\n const reaches = (inPass ??= passReach(plan))\n ready = waiting.filter((nodeId) => !deferred(nodeId, waiting, reaches))\n }\n // Still everybody (a cycle with more than one way in has no head): nobody would ever\n // start, so all of them do.\n if (ready.length === 0) ready = waiting\n const starting: Promise<void>[] = []\n for (const nodeId of ready) {\n const activations = pending.get(nodeId) as Activation[]\n pending.delete(nodeId)\n if ((visits.get(nodeId) ?? 0) >= plan.maxNodeVisits) {\n drop(nodeId, activations, 'maxNodeVisits')\n } else if (runs >= plan.maxRuns) {\n drop(nodeId, activations, 'maxRuns')\n } else {\n starting.push(visit(nodeId, activations))\n }\n }\n if (starting.length === 0) continue\n await Promise.race([Promise.all(starting), haltPromise])\n wave++\n }\n if (halted) await haltPromise\n } catch (err) {\n if (halted !== 'aborted') throw err\n emit({ type: 'pipeline.finished', stoppedBy: 'aborted', runs })\n if (onAbort === 'reject') throw err\n return result('aborted')\n } finally {\n options.signal?.removeEventListener('abort', onOuterAbort)\n }\n const stoppedBy = capped.has('maxRuns')\n ? 'maxRuns'\n : capped.has('maxNodeVisits')\n ? 'maxNodeVisits'\n : undefined\n emit({ type: 'pipeline.finished', ...(stoppedBy ? { stoppedBy } : {}), runs })\n return result(stoppedBy)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA+EO,IAAM,kBAAkB;AAAA;AAAA,EAE7B,eAAe;AAAA,EACf,SAAS;AAAA;AAAA,EAET,sBAAsB;AAAA,EACtB,gBAAgB;AAAA;AAAA,EAEhB,UAAU;AAAA,EACV,UAAU;AAAA,EACV,WAAW;AAAA;AAAA,EAEX,kBAAkB;AAAA,EAClB,mBAAmB;AAAA;AAAA,EAEnB,qBAAqB;AACvB;A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,EACzB,UAAE;AACA,YAAQ,QAAQ,oBAAoB,SAAS,YAAY;AAAA,EAC3D;AACA,QAAM,YAAY,OAAO,IAAI,SAAS,IAClC,YACA,OAAO,IAAI,eAAe,IACxB,kBACA;AACN,OAAK,EAAE,MAAM,qBAAqB,GAAI,YAAY,EAAE,UAAU,IAAI,CAAC,GAAI,KAAK,CAAC;AAC7E,SAAO,OAAO,SAAS;AACzB;","names":["stoppedBy"]}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
interface PipelineDefinition {
|
|
2
|
+
version: 1;
|
|
3
|
+
name?: string;
|
|
4
|
+
entry: string;
|
|
5
|
+
nodes: PipelineNode[];
|
|
6
|
+
edges: PipelineEdge[];
|
|
7
|
+
limits?: {
|
|
8
|
+
maxNodeVisits?: number;
|
|
9
|
+
maxRuns?: number;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
interface PipelineNode {
|
|
13
|
+
id: string;
|
|
14
|
+
name?: string;
|
|
15
|
+
instructions?: string;
|
|
16
|
+
model?: string;
|
|
17
|
+
skills?: string[];
|
|
18
|
+
tools?: string[];
|
|
19
|
+
mcpServers?: string[];
|
|
20
|
+
routes?: PipelineRoute[];
|
|
21
|
+
join?: 'all' | 'any';
|
|
22
|
+
settings?: Record<string, unknown>;
|
|
23
|
+
position?: {
|
|
24
|
+
x: number;
|
|
25
|
+
y: number;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
interface PipelineRoute {
|
|
29
|
+
label: string;
|
|
30
|
+
description?: string;
|
|
31
|
+
}
|
|
32
|
+
type PipelineCondition = {
|
|
33
|
+
kind: 'always';
|
|
34
|
+
} | {
|
|
35
|
+
kind: 'contains';
|
|
36
|
+
text: string;
|
|
37
|
+
caseSensitive?: boolean;
|
|
38
|
+
} | {
|
|
39
|
+
kind: 'matches';
|
|
40
|
+
pattern: string;
|
|
41
|
+
flags?: string;
|
|
42
|
+
} | {
|
|
43
|
+
kind: 'route';
|
|
44
|
+
label: string;
|
|
45
|
+
} | {
|
|
46
|
+
kind: 'otherwise';
|
|
47
|
+
};
|
|
48
|
+
interface PipelineEdge {
|
|
49
|
+
id?: string;
|
|
50
|
+
from: string;
|
|
51
|
+
to: string;
|
|
52
|
+
when?: PipelineCondition;
|
|
53
|
+
}
|
|
54
|
+
declare const PIPELINE_LIMITS: {
|
|
55
|
+
readonly maxNodeVisits: 3;
|
|
56
|
+
readonly maxRuns: 25;
|
|
57
|
+
readonly maxNodeVisitsCeiling: 100;
|
|
58
|
+
readonly maxRunsCeiling: 1000;
|
|
59
|
+
readonly maxNodes: 200;
|
|
60
|
+
readonly maxEdges: 1000;
|
|
61
|
+
readonly maxRoutes: 20;
|
|
62
|
+
readonly maxPatternLength: 500;
|
|
63
|
+
readonly maxPatternProgram: 1000;
|
|
64
|
+
readonly conditionInputChars: 50000;
|
|
65
|
+
};
|
|
66
|
+
interface PipelineUsage {
|
|
67
|
+
inputTokens: number;
|
|
68
|
+
outputTokens: number;
|
|
69
|
+
totalTokens: number;
|
|
70
|
+
reasoningTokens?: number;
|
|
71
|
+
cachedInputTokens?: number;
|
|
72
|
+
cacheWriteTokens?: number;
|
|
73
|
+
}
|
|
74
|
+
interface PipelineNodeSource {
|
|
75
|
+
nodeId: string;
|
|
76
|
+
name?: string;
|
|
77
|
+
text: string;
|
|
78
|
+
}
|
|
79
|
+
interface PipelineNodeInput {
|
|
80
|
+
request: string;
|
|
81
|
+
from: PipelineNodeSource[];
|
|
82
|
+
visit: number;
|
|
83
|
+
}
|
|
84
|
+
interface PipelineNodeOutput {
|
|
85
|
+
text: string;
|
|
86
|
+
usage?: PipelineUsage;
|
|
87
|
+
route?: string;
|
|
88
|
+
}
|
|
89
|
+
interface PipelineNodeContext<E = never> {
|
|
90
|
+
signal: AbortSignal;
|
|
91
|
+
pipeline: PipelineDefinition;
|
|
92
|
+
emit: (event: E) => void;
|
|
93
|
+
}
|
|
94
|
+
type PipelineNodeRunner<E = never> = (node: PipelineNode, input: PipelineNodeInput, ctx: PipelineNodeContext<E>) => Promise<PipelineNodeOutput>;
|
|
95
|
+
type PipelineStop = 'maxRuns' | 'maxNodeVisits' | 'aborted';
|
|
96
|
+
type PipelineEvent = {
|
|
97
|
+
type: 'pipeline.started';
|
|
98
|
+
pipeline?: string;
|
|
99
|
+
} | {
|
|
100
|
+
type: 'pipeline.node.started';
|
|
101
|
+
nodeId: string;
|
|
102
|
+
visit: number;
|
|
103
|
+
from: string[];
|
|
104
|
+
} | {
|
|
105
|
+
type: 'pipeline.node.finished';
|
|
106
|
+
nodeId: string;
|
|
107
|
+
visit: number;
|
|
108
|
+
text: string;
|
|
109
|
+
route?: string;
|
|
110
|
+
usage?: PipelineUsage;
|
|
111
|
+
} | {
|
|
112
|
+
type: 'pipeline.node.failed';
|
|
113
|
+
nodeId: string;
|
|
114
|
+
visit: number;
|
|
115
|
+
error: string;
|
|
116
|
+
} | {
|
|
117
|
+
type: 'pipeline.node.skipped';
|
|
118
|
+
nodeId: string;
|
|
119
|
+
from: string[];
|
|
120
|
+
reason: 'maxRuns' | 'maxNodeVisits';
|
|
121
|
+
} | {
|
|
122
|
+
type: 'pipeline.edge';
|
|
123
|
+
from: string;
|
|
124
|
+
to: string;
|
|
125
|
+
edgeId: string;
|
|
126
|
+
visit: number;
|
|
127
|
+
fired: boolean;
|
|
128
|
+
} | {
|
|
129
|
+
type: 'pipeline.finished';
|
|
130
|
+
stoppedBy?: PipelineStop;
|
|
131
|
+
runs: number;
|
|
132
|
+
};
|
|
133
|
+
type PipelineNodeEvent<E> = E & {
|
|
134
|
+
nodeId: string;
|
|
135
|
+
visit: number;
|
|
136
|
+
};
|
|
137
|
+
type PipelineTraceEntry = {
|
|
138
|
+
type: 'node';
|
|
139
|
+
nodeId: string;
|
|
140
|
+
visit: number;
|
|
141
|
+
wave: number;
|
|
142
|
+
from: string[];
|
|
143
|
+
text: string;
|
|
144
|
+
route?: string;
|
|
145
|
+
usage?: PipelineUsage;
|
|
146
|
+
} | {
|
|
147
|
+
type: 'edge';
|
|
148
|
+
from: string;
|
|
149
|
+
to: string;
|
|
150
|
+
edgeId: string;
|
|
151
|
+
visit: number;
|
|
152
|
+
fired: boolean;
|
|
153
|
+
} | {
|
|
154
|
+
type: 'dropped';
|
|
155
|
+
nodeId: string;
|
|
156
|
+
from: string[];
|
|
157
|
+
reason: 'maxRuns' | 'maxNodeVisits';
|
|
158
|
+
};
|
|
159
|
+
interface PipelineResult {
|
|
160
|
+
text: string;
|
|
161
|
+
outputs: Record<string, {
|
|
162
|
+
visit: number;
|
|
163
|
+
text: string;
|
|
164
|
+
route?: string;
|
|
165
|
+
}[]>;
|
|
166
|
+
trace: PipelineTraceEntry[];
|
|
167
|
+
usage: PipelineUsage;
|
|
168
|
+
stoppedBy?: PipelineStop;
|
|
169
|
+
runs: number;
|
|
170
|
+
}
|
|
171
|
+
interface PipelineIssue {
|
|
172
|
+
code: string;
|
|
173
|
+
message: string;
|
|
174
|
+
nodeId?: string;
|
|
175
|
+
edgeId?: string;
|
|
176
|
+
edgeIndex?: number;
|
|
177
|
+
}
|
|
178
|
+
interface PipelineValidation {
|
|
179
|
+
ok: boolean;
|
|
180
|
+
errors: PipelineIssue[];
|
|
181
|
+
warnings: PipelineIssue[];
|
|
182
|
+
}
|
|
183
|
+
declare class PipelineValidationError extends Error {
|
|
184
|
+
errors: PipelineIssue[];
|
|
185
|
+
constructor(errors: PipelineIssue[]);
|
|
186
|
+
}
|
|
187
|
+
declare class PipelineNodeError extends Error {
|
|
188
|
+
nodeId: string;
|
|
189
|
+
visit: number;
|
|
190
|
+
constructor(nodeId: string, visit: number, cause: unknown);
|
|
191
|
+
}
|
|
192
|
+
type Matcher = (text: string) => boolean;
|
|
193
|
+
declare const testPipelineCondition: (when: PipelineCondition | undefined, output: {
|
|
194
|
+
text: string;
|
|
195
|
+
route?: string;
|
|
196
|
+
}, matcher?: (text: string) => boolean) => boolean;
|
|
197
|
+
declare const normalizePipeline: (definition: PipelineDefinition) => PipelineDefinition;
|
|
198
|
+
declare const validatePipeline: (definition: PipelineDefinition) => PipelineValidation;
|
|
199
|
+
declare const renderPipelineNodeInput: (input: PipelineNodeInput) => string;
|
|
200
|
+
declare const PIPELINE_ROUTER_SYSTEM: string;
|
|
201
|
+
declare const renderPipelineRoutePrompt: (node: PipelineNode, text: string) => string;
|
|
202
|
+
declare const matchPipelineRoute: (node: PipelineNode, answer: unknown) => string | undefined;
|
|
203
|
+
interface PlannedEdge {
|
|
204
|
+
edge: PipelineEdge;
|
|
205
|
+
matcher?: Matcher;
|
|
206
|
+
}
|
|
207
|
+
interface PipelinePlan {
|
|
208
|
+
definition: PipelineDefinition;
|
|
209
|
+
nodes: Map<string, PipelineNode>;
|
|
210
|
+
outgoing: Map<string, PlannedEdge[]>;
|
|
211
|
+
maxNodeVisits: number;
|
|
212
|
+
maxRuns: number;
|
|
213
|
+
reaches: (from: string, to: string) => boolean;
|
|
214
|
+
}
|
|
215
|
+
declare const preparePipeline: (definition: PipelineDefinition) => PipelinePlan;
|
|
216
|
+
type PipelineAbortBehaviour = 'reject' | 'resolve';
|
|
217
|
+
interface PipelineGraphRunOptions<E = never> {
|
|
218
|
+
input: string;
|
|
219
|
+
signal?: AbortSignal;
|
|
220
|
+
onEvent?: (event: PipelineEvent | PipelineNodeEvent<E>) => void;
|
|
221
|
+
onAbort?: PipelineAbortBehaviour;
|
|
222
|
+
}
|
|
223
|
+
declare const runPipelineGraph: <E = never>(plan: PipelinePlan, runNode: PipelineNodeRunner<E>, options: PipelineGraphRunOptions<E>) => Promise<PipelineResult>;
|
|
224
|
+
|
|
225
|
+
export { PIPELINE_LIMITS, PIPELINE_ROUTER_SYSTEM, PipelineNodeError, PipelineValidationError, matchPipelineRoute, normalizePipeline, preparePipeline, renderPipelineNodeInput, renderPipelineRoutePrompt, runPipelineGraph, testPipelineCondition, validatePipeline };
|
|
226
|
+
export type { PipelineAbortBehaviour, PipelineCondition, PipelineDefinition, PipelineEdge, PipelineEvent, PipelineGraphRunOptions, PipelineIssue, PipelineNode, PipelineNodeContext, PipelineNodeEvent, PipelineNodeInput, PipelineNodeOutput, PipelineNodeRunner, PipelineNodeSource, PipelinePlan, PipelineResult, PipelineRoute, PipelineStop, PipelineTraceEntry, PipelineUsage, PipelineValidation };
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
interface PipelineDefinition {
|
|
2
|
+
version: 1;
|
|
3
|
+
name?: string;
|
|
4
|
+
entry: string;
|
|
5
|
+
nodes: PipelineNode[];
|
|
6
|
+
edges: PipelineEdge[];
|
|
7
|
+
limits?: {
|
|
8
|
+
maxNodeVisits?: number;
|
|
9
|
+
maxRuns?: number;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
interface PipelineNode {
|
|
13
|
+
id: string;
|
|
14
|
+
name?: string;
|
|
15
|
+
instructions?: string;
|
|
16
|
+
model?: string;
|
|
17
|
+
skills?: string[];
|
|
18
|
+
tools?: string[];
|
|
19
|
+
mcpServers?: string[];
|
|
20
|
+
routes?: PipelineRoute[];
|
|
21
|
+
join?: 'all' | 'any';
|
|
22
|
+
settings?: Record<string, unknown>;
|
|
23
|
+
position?: {
|
|
24
|
+
x: number;
|
|
25
|
+
y: number;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
interface PipelineRoute {
|
|
29
|
+
label: string;
|
|
30
|
+
description?: string;
|
|
31
|
+
}
|
|
32
|
+
type PipelineCondition = {
|
|
33
|
+
kind: 'always';
|
|
34
|
+
} | {
|
|
35
|
+
kind: 'contains';
|
|
36
|
+
text: string;
|
|
37
|
+
caseSensitive?: boolean;
|
|
38
|
+
} | {
|
|
39
|
+
kind: 'matches';
|
|
40
|
+
pattern: string;
|
|
41
|
+
flags?: string;
|
|
42
|
+
} | {
|
|
43
|
+
kind: 'route';
|
|
44
|
+
label: string;
|
|
45
|
+
} | {
|
|
46
|
+
kind: 'otherwise';
|
|
47
|
+
};
|
|
48
|
+
interface PipelineEdge {
|
|
49
|
+
id?: string;
|
|
50
|
+
from: string;
|
|
51
|
+
to: string;
|
|
52
|
+
when?: PipelineCondition;
|
|
53
|
+
}
|
|
54
|
+
declare const PIPELINE_LIMITS: {
|
|
55
|
+
readonly maxNodeVisits: 3;
|
|
56
|
+
readonly maxRuns: 25;
|
|
57
|
+
readonly maxNodeVisitsCeiling: 100;
|
|
58
|
+
readonly maxRunsCeiling: 1000;
|
|
59
|
+
readonly maxNodes: 200;
|
|
60
|
+
readonly maxEdges: 1000;
|
|
61
|
+
readonly maxRoutes: 20;
|
|
62
|
+
readonly maxPatternLength: 500;
|
|
63
|
+
readonly maxPatternProgram: 1000;
|
|
64
|
+
readonly conditionInputChars: 50000;
|
|
65
|
+
};
|
|
66
|
+
interface PipelineUsage {
|
|
67
|
+
inputTokens: number;
|
|
68
|
+
outputTokens: number;
|
|
69
|
+
totalTokens: number;
|
|
70
|
+
reasoningTokens?: number;
|
|
71
|
+
cachedInputTokens?: number;
|
|
72
|
+
cacheWriteTokens?: number;
|
|
73
|
+
}
|
|
74
|
+
interface PipelineNodeSource {
|
|
75
|
+
nodeId: string;
|
|
76
|
+
name?: string;
|
|
77
|
+
text: string;
|
|
78
|
+
}
|
|
79
|
+
interface PipelineNodeInput {
|
|
80
|
+
request: string;
|
|
81
|
+
from: PipelineNodeSource[];
|
|
82
|
+
visit: number;
|
|
83
|
+
}
|
|
84
|
+
interface PipelineNodeOutput {
|
|
85
|
+
text: string;
|
|
86
|
+
usage?: PipelineUsage;
|
|
87
|
+
route?: string;
|
|
88
|
+
}
|
|
89
|
+
interface PipelineNodeContext<E = never> {
|
|
90
|
+
signal: AbortSignal;
|
|
91
|
+
pipeline: PipelineDefinition;
|
|
92
|
+
emit: (event: E) => void;
|
|
93
|
+
}
|
|
94
|
+
type PipelineNodeRunner<E = never> = (node: PipelineNode, input: PipelineNodeInput, ctx: PipelineNodeContext<E>) => Promise<PipelineNodeOutput>;
|
|
95
|
+
type PipelineStop = 'maxRuns' | 'maxNodeVisits' | 'aborted';
|
|
96
|
+
type PipelineEvent = {
|
|
97
|
+
type: 'pipeline.started';
|
|
98
|
+
pipeline?: string;
|
|
99
|
+
} | {
|
|
100
|
+
type: 'pipeline.node.started';
|
|
101
|
+
nodeId: string;
|
|
102
|
+
visit: number;
|
|
103
|
+
from: string[];
|
|
104
|
+
} | {
|
|
105
|
+
type: 'pipeline.node.finished';
|
|
106
|
+
nodeId: string;
|
|
107
|
+
visit: number;
|
|
108
|
+
text: string;
|
|
109
|
+
route?: string;
|
|
110
|
+
usage?: PipelineUsage;
|
|
111
|
+
} | {
|
|
112
|
+
type: 'pipeline.node.failed';
|
|
113
|
+
nodeId: string;
|
|
114
|
+
visit: number;
|
|
115
|
+
error: string;
|
|
116
|
+
} | {
|
|
117
|
+
type: 'pipeline.node.skipped';
|
|
118
|
+
nodeId: string;
|
|
119
|
+
from: string[];
|
|
120
|
+
reason: 'maxRuns' | 'maxNodeVisits';
|
|
121
|
+
} | {
|
|
122
|
+
type: 'pipeline.edge';
|
|
123
|
+
from: string;
|
|
124
|
+
to: string;
|
|
125
|
+
edgeId: string;
|
|
126
|
+
visit: number;
|
|
127
|
+
fired: boolean;
|
|
128
|
+
} | {
|
|
129
|
+
type: 'pipeline.finished';
|
|
130
|
+
stoppedBy?: PipelineStop;
|
|
131
|
+
runs: number;
|
|
132
|
+
};
|
|
133
|
+
type PipelineNodeEvent<E> = E & {
|
|
134
|
+
nodeId: string;
|
|
135
|
+
visit: number;
|
|
136
|
+
};
|
|
137
|
+
type PipelineTraceEntry = {
|
|
138
|
+
type: 'node';
|
|
139
|
+
nodeId: string;
|
|
140
|
+
visit: number;
|
|
141
|
+
wave: number;
|
|
142
|
+
from: string[];
|
|
143
|
+
text: string;
|
|
144
|
+
route?: string;
|
|
145
|
+
usage?: PipelineUsage;
|
|
146
|
+
} | {
|
|
147
|
+
type: 'edge';
|
|
148
|
+
from: string;
|
|
149
|
+
to: string;
|
|
150
|
+
edgeId: string;
|
|
151
|
+
visit: number;
|
|
152
|
+
fired: boolean;
|
|
153
|
+
} | {
|
|
154
|
+
type: 'dropped';
|
|
155
|
+
nodeId: string;
|
|
156
|
+
from: string[];
|
|
157
|
+
reason: 'maxRuns' | 'maxNodeVisits';
|
|
158
|
+
};
|
|
159
|
+
interface PipelineResult {
|
|
160
|
+
text: string;
|
|
161
|
+
outputs: Record<string, {
|
|
162
|
+
visit: number;
|
|
163
|
+
text: string;
|
|
164
|
+
route?: string;
|
|
165
|
+
}[]>;
|
|
166
|
+
trace: PipelineTraceEntry[];
|
|
167
|
+
usage: PipelineUsage;
|
|
168
|
+
stoppedBy?: PipelineStop;
|
|
169
|
+
runs: number;
|
|
170
|
+
}
|
|
171
|
+
interface PipelineIssue {
|
|
172
|
+
code: string;
|
|
173
|
+
message: string;
|
|
174
|
+
nodeId?: string;
|
|
175
|
+
edgeId?: string;
|
|
176
|
+
edgeIndex?: number;
|
|
177
|
+
}
|
|
178
|
+
interface PipelineValidation {
|
|
179
|
+
ok: boolean;
|
|
180
|
+
errors: PipelineIssue[];
|
|
181
|
+
warnings: PipelineIssue[];
|
|
182
|
+
}
|
|
183
|
+
declare class PipelineValidationError extends Error {
|
|
184
|
+
errors: PipelineIssue[];
|
|
185
|
+
constructor(errors: PipelineIssue[]);
|
|
186
|
+
}
|
|
187
|
+
declare class PipelineNodeError extends Error {
|
|
188
|
+
nodeId: string;
|
|
189
|
+
visit: number;
|
|
190
|
+
constructor(nodeId: string, visit: number, cause: unknown);
|
|
191
|
+
}
|
|
192
|
+
type Matcher = (text: string) => boolean;
|
|
193
|
+
declare const testPipelineCondition: (when: PipelineCondition | undefined, output: {
|
|
194
|
+
text: string;
|
|
195
|
+
route?: string;
|
|
196
|
+
}, matcher?: (text: string) => boolean) => boolean;
|
|
197
|
+
declare const normalizePipeline: (definition: PipelineDefinition) => PipelineDefinition;
|
|
198
|
+
declare const validatePipeline: (definition: PipelineDefinition) => PipelineValidation;
|
|
199
|
+
declare const renderPipelineNodeInput: (input: PipelineNodeInput) => string;
|
|
200
|
+
declare const PIPELINE_ROUTER_SYSTEM: string;
|
|
201
|
+
declare const renderPipelineRoutePrompt: (node: PipelineNode, text: string) => string;
|
|
202
|
+
declare const matchPipelineRoute: (node: PipelineNode, answer: unknown) => string | undefined;
|
|
203
|
+
interface PlannedEdge {
|
|
204
|
+
edge: PipelineEdge;
|
|
205
|
+
matcher?: Matcher;
|
|
206
|
+
}
|
|
207
|
+
interface PipelinePlan {
|
|
208
|
+
definition: PipelineDefinition;
|
|
209
|
+
nodes: Map<string, PipelineNode>;
|
|
210
|
+
outgoing: Map<string, PlannedEdge[]>;
|
|
211
|
+
maxNodeVisits: number;
|
|
212
|
+
maxRuns: number;
|
|
213
|
+
reaches: (from: string, to: string) => boolean;
|
|
214
|
+
}
|
|
215
|
+
declare const preparePipeline: (definition: PipelineDefinition) => PipelinePlan;
|
|
216
|
+
type PipelineAbortBehaviour = 'reject' | 'resolve';
|
|
217
|
+
interface PipelineGraphRunOptions<E = never> {
|
|
218
|
+
input: string;
|
|
219
|
+
signal?: AbortSignal;
|
|
220
|
+
onEvent?: (event: PipelineEvent | PipelineNodeEvent<E>) => void;
|
|
221
|
+
onAbort?: PipelineAbortBehaviour;
|
|
222
|
+
}
|
|
223
|
+
declare const runPipelineGraph: <E = never>(plan: PipelinePlan, runNode: PipelineNodeRunner<E>, options: PipelineGraphRunOptions<E>) => Promise<PipelineResult>;
|
|
224
|
+
|
|
225
|
+
export { PIPELINE_LIMITS, PIPELINE_ROUTER_SYSTEM, PipelineNodeError, PipelineValidationError, matchPipelineRoute, normalizePipeline, preparePipeline, renderPipelineNodeInput, renderPipelineRoutePrompt, runPipelineGraph, testPipelineCondition, validatePipeline };
|
|
226
|
+
export type { PipelineAbortBehaviour, PipelineCondition, PipelineDefinition, PipelineEdge, PipelineEvent, PipelineGraphRunOptions, PipelineIssue, PipelineNode, PipelineNodeContext, PipelineNodeEvent, PipelineNodeInput, PipelineNodeOutput, PipelineNodeRunner, PipelineNodeSource, PipelinePlan, PipelineResult, PipelineRoute, PipelineStop, PipelineTraceEntry, PipelineUsage, PipelineValidation };
|