@cognipipe/core
v0.4.1
Published
Core workflow execution engine for CogniPipe
Maintainers
Readme
@cognipipe/core
The workflow engine behind CogniPipe: parse a workflow file, validate it, and execute its steps through registered nodes.
Requires Node.js >= 22.14. Ships ESM and CommonJS builds.
Install
npm install @cognipipe/core @cognipipe/node-http
# or: pnpm add @cognipipe/core @cognipipe/node-httpQuick start
import { WorkflowParser, WorkflowValidator, NodeRegistry, WorkflowExecutor } from '@cognipipe/core';
import { HttpNode } from '@cognipipe/node-http';
const registry = new NodeRegistry();
registry.register('@cognipipe/node-http', HttpNode);
const raw = await new WorkflowParser().parseFile('./workflow.yaml'); // .yaml, .yml or .json
const config = new WorkflowValidator().validate(raw); // throws CogniPipeError if invalid
const { context, stepErrors } = await new WorkflowExecutor(registry).run(config);
console.log(context.get('steps')); // { [stepName]: { output, completedAt, durationMs, retryCount } }# workflow.yaml
name: fetch-and-report
version: '1.0.0'
steps:
- name: fetch-data
uses: '@cognipipe/node-http'
config:
url: 'https://catfact.ninja/fact'
- name: report
uses: '@cognipipe/node-http'
dependsOn: ['fetch-data'] # required to read fetch-data's output
config:
url: 'https://example.com/hook'
method: POST
body: '{{ steps.fetch-data.output.body }}'How execution works
- Every step's
usesmust be registered before anything runs; a typo never leaves earlier steps half-applied. - Cycles in
dependsOnare rejected up front (CIRCULAR_DEPENDENCY). - Steps run as a DAG: a step with no unmet
dependsOnstarts immediately, concurrently with other ready steps. A step that reads another step's output with{{ steps.<name>.output.<path> }}must list that step independsOn. continueOnError: truerecords the failure instepErrorsand keeps going. Other failures throwSTEP_EXECUTION_FAILED.retry: { attempts, delayMs, backoff }retries a step'sexecute()(linearorexponentialbackoff).{{ ... }}expressions in a step'sconfigare resolved before the node runs. Objects and arrays are inserted as JSON.
API
| Export | Purpose |
| --------------------------------------------------------------- | ---------------------------------------------------- |
| WorkflowParser | parseFile, parseYAML, parseJSON → unknown |
| WorkflowValidator | validate(raw) → typed WorkflowConfig |
| NodeRegistry | register, get, has, instantiate, listTypes |
| WorkflowExecutor | run(config, initial?) → { context, stepErrors } |
| ExecutionContext | Immutable key/value store with interpolate() |
| resolveTemplate, resolveDotPath | Interpolation utilities |
| detectCycles | Cycle detection for dependsOn graphs |
| WorkflowConfigSchema, StepConfigSchema, RetryConfigSchema | Zod schemas |
| CogniPipeError, isCogniPipeError, COGNIPIPE_ERROR_CODES | Error handling |
Errors
Every error is a CogniPipeError with a machine-readable code and optional context:
import { isCogniPipeError } from '@cognipipe/core';
try {
await executor.run(config);
} catch (err) {
if (isCogniPipeError(err)) console.error(`[${err.code}] ${err.message}`, err.context);
else throw err;
}Codes: WORKFLOW_VALIDATION_ERROR, WORKFLOW_PARSE_ERROR, STEP_NOT_FOUND, NODE_NOT_REGISTERED, STEP_EXECUTION_FAILED, CIRCULAR_DEPENDENCY, INTERPOLATION_ERROR, CONTEXT_KEY_NOT_FOUND, NODE_INSTANTIATION_FAILED, NODE_CONFIG_INVALID.
Related packages
@cognipipe/types · @cognipipe/sdk · cognipipe (CLI)
License
MIT © Aakif Kohari
