flowcraft 1.0.0 → 2.0.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 +37 -134
- package/dist/analysis.d.ts +43 -0
- package/dist/analysis.js +3 -0
- package/dist/chunk-55J6XMHW.js +3 -0
- package/dist/{chunk-7XUN3OQT.js.map → chunk-55J6XMHW.js.map} +1 -1
- package/dist/chunk-6DNEDIIT.js +123 -0
- package/dist/chunk-6DNEDIIT.js.map +1 -0
- package/dist/chunk-734J4PTM.js +100 -0
- package/dist/chunk-734J4PTM.js.map +1 -0
- package/dist/chunk-DSZSR7UE.js +40 -0
- package/dist/chunk-DSZSR7UE.js.map +1 -0
- package/dist/chunk-GTZC6PQI.js +22 -0
- package/dist/chunk-GTZC6PQI.js.map +1 -0
- package/dist/chunk-HMR2GEGE.js +3 -0
- package/dist/{chunk-F2RSES6P.js.map → chunk-HMR2GEGE.js.map} +1 -1
- package/dist/chunk-J3RNCPED.js +27 -0
- package/dist/chunk-J3RNCPED.js.map +1 -0
- package/dist/chunk-M23P46ZL.js +105 -0
- package/dist/chunk-M23P46ZL.js.map +1 -0
- package/dist/chunk-MICPMOTW.js +49 -0
- package/dist/chunk-MICPMOTW.js.map +1 -0
- package/dist/chunk-NPAJNLXQ.js +106 -0
- package/dist/chunk-NPAJNLXQ.js.map +1 -0
- package/dist/chunk-RAZXOMZC.js +64 -0
- package/dist/chunk-RAZXOMZC.js.map +1 -0
- package/dist/chunk-REH55ZXV.js +13 -0
- package/dist/chunk-REH55ZXV.js.map +1 -0
- package/dist/chunk-RW4FH7IL.js +135 -0
- package/dist/chunk-RW4FH7IL.js.map +1 -0
- package/dist/chunk-RYTIQZIB.js +303 -0
- package/dist/chunk-RYTIQZIB.js.map +1 -0
- package/dist/chunk-UYPIWXZG.js +62 -0
- package/dist/chunk-UYPIWXZG.js.map +1 -0
- package/dist/chunk-VFC342WL.js +29 -0
- package/dist/chunk-VFC342WL.js.map +1 -0
- package/dist/chunk-WXT3YEWU.js +28 -0
- package/dist/chunk-WXT3YEWU.js.map +1 -0
- package/dist/context.d.ts +23 -105
- package/dist/context.js +1 -1
- package/dist/errors.d.ts +15 -31
- package/dist/errors.js +1 -1
- package/dist/evaluator.d.ts +22 -0
- package/dist/evaluator.js +3 -0
- package/dist/evaluator.js.map +1 -0
- package/dist/flow.d.ts +54 -0
- package/dist/flow.js +4 -0
- package/dist/flow.js.map +1 -0
- package/dist/index.d.ts +14 -16
- package/dist/index.js +17 -25
- package/dist/linter.d.ts +24 -0
- package/dist/linter.js +4 -0
- package/dist/linter.js.map +1 -0
- package/dist/logger.d.ts +11 -36
- package/dist/logger.js +1 -1
- package/dist/node.d.ts +1 -0
- package/dist/node.js +3 -0
- package/dist/node.js.map +1 -0
- package/dist/runtime/adapter.d.ts +78 -0
- package/dist/runtime/adapter.js +15 -0
- package/dist/runtime/adapter.js.map +1 -0
- package/dist/runtime/executors.d.ts +26 -0
- package/dist/runtime/executors.js +4 -0
- package/dist/runtime/executors.js.map +1 -0
- package/dist/runtime/index.d.ts +7 -0
- package/dist/runtime/index.js +16 -0
- package/dist/runtime/runtime.d.ts +33 -0
- package/dist/runtime/runtime.js +14 -0
- package/dist/runtime/runtime.js.map +1 -0
- package/dist/runtime/state.d.ts +21 -0
- package/dist/runtime/state.js +4 -0
- package/dist/runtime/state.js.map +1 -0
- package/dist/runtime/traverser.d.ts +24 -0
- package/dist/runtime/traverser.js +5 -0
- package/dist/runtime/traverser.js.map +1 -0
- package/dist/runtime/types.d.ts +15 -0
- package/dist/runtime/types.js +3 -0
- package/dist/sanitizer.d.ts +10 -0
- package/dist/sanitizer.js +3 -0
- package/dist/{utils/sanitize.js.map → sanitizer.js.map} +1 -1
- package/dist/serializer.d.ts +15 -0
- package/dist/serializer.js +3 -0
- package/dist/serializer.js.map +1 -0
- package/dist/types-CZN_FcB6.d.ts +201 -0
- package/dist/types.d.ts +1 -3
- package/dist/types.js +1 -1
- package/package.json +9 -20
- package/LICENSE +0 -21
- package/dist/builder/graph/graph.d.ts +0 -57
- package/dist/builder/graph/graph.js +0 -21
- package/dist/builder/graph/graph.js.map +0 -1
- package/dist/builder/graph/index.d.ts +0 -8
- package/dist/builder/graph/index.js +0 -23
- package/dist/builder/graph/internal-nodes.d.ts +0 -59
- package/dist/builder/graph/internal-nodes.js +0 -20
- package/dist/builder/graph/internal-nodes.js.map +0 -1
- package/dist/builder/graph/runner.d.ts +0 -51
- package/dist/builder/graph/runner.js +0 -21
- package/dist/builder/graph/runner.js.map +0 -1
- package/dist/builder/graph/types.d.ts +0 -3
- package/dist/builder/graph/types.js +0 -3
- package/dist/builder/index.d.ts +0 -8
- package/dist/builder/index.js +0 -24
- package/dist/builder/index.js.map +0 -1
- package/dist/builder/patterns.d.ts +0 -136
- package/dist/builder/patterns.js +0 -19
- package/dist/builder/patterns.js.map +0 -1
- package/dist/chunk-3YMBNZ77.js +0 -441
- package/dist/chunk-3YMBNZ77.js.map +0 -1
- package/dist/chunk-64DNBF5W.js +0 -36
- package/dist/chunk-64DNBF5W.js.map +0 -1
- package/dist/chunk-6QCXIRLA.js +0 -18
- package/dist/chunk-6QCXIRLA.js.map +0 -1
- package/dist/chunk-7XUN3OQT.js +0 -3
- package/dist/chunk-AOHBHYF6.js +0 -7
- package/dist/chunk-AOHBHYF6.js.map +0 -1
- package/dist/chunk-BRFMFLR6.js +0 -85
- package/dist/chunk-BRFMFLR6.js.map +0 -1
- package/dist/chunk-ELEHMJPM.js +0 -13
- package/dist/chunk-ELEHMJPM.js.map +0 -1
- package/dist/chunk-F2RSES6P.js +0 -3
- package/dist/chunk-F6C6J7HK.js +0 -3
- package/dist/chunk-F6C6J7HK.js.map +0 -1
- package/dist/chunk-GMKJ34T2.js +0 -3
- package/dist/chunk-GMKJ34T2.js.map +0 -1
- package/dist/chunk-HEO3XL4Z.js +0 -328
- package/dist/chunk-HEO3XL4Z.js.map +0 -1
- package/dist/chunk-IIKTTIW5.js +0 -56
- package/dist/chunk-IIKTTIW5.js.map +0 -1
- package/dist/chunk-KOBEU2EM.js +0 -3
- package/dist/chunk-KOBEU2EM.js.map +0 -1
- package/dist/chunk-L5PK5VL2.js +0 -178
- package/dist/chunk-L5PK5VL2.js.map +0 -1
- package/dist/chunk-P3RPDZHO.js +0 -36
- package/dist/chunk-P3RPDZHO.js.map +0 -1
- package/dist/chunk-PNWOW52F.js +0 -19
- package/dist/chunk-PNWOW52F.js.map +0 -1
- package/dist/chunk-R27FIYR5.js +0 -62
- package/dist/chunk-R27FIYR5.js.map +0 -1
- package/dist/chunk-S4WFNGQG.js +0 -17
- package/dist/chunk-S4WFNGQG.js.map +0 -1
- package/dist/chunk-TS3M7MWA.js +0 -3
- package/dist/chunk-TS3M7MWA.js.map +0 -1
- package/dist/chunk-UY4PNPBX.js +0 -156
- package/dist/chunk-UY4PNPBX.js.map +0 -1
- package/dist/chunk-VMH2LRM6.js +0 -114
- package/dist/chunk-VMH2LRM6.js.map +0 -1
- package/dist/chunk-VZDHIOCH.js +0 -76
- package/dist/chunk-VZDHIOCH.js.map +0 -1
- package/dist/chunk-WGVHM7DU.js +0 -66
- package/dist/chunk-WGVHM7DU.js.map +0 -1
- package/dist/chunk-WR5PDOPP.js +0 -91
- package/dist/chunk-WR5PDOPP.js.map +0 -1
- package/dist/chunk-YR433ZDA.js +0 -20
- package/dist/chunk-YR433ZDA.js.map +0 -1
- package/dist/executors/in-memory.d.ts +0 -39
- package/dist/executors/in-memory.js +0 -6
- package/dist/executors/in-memory.js.map +0 -1
- package/dist/executors/types.d.ts +0 -3
- package/dist/executors/types.js +0 -3
- package/dist/executors/types.js.map +0 -1
- package/dist/functions.d.ts +0 -88
- package/dist/functions.js +0 -21
- package/dist/functions.js.map +0 -1
- package/dist/types-U76Ukj96.d.ts +0 -609
- package/dist/utils/analysis.d.ts +0 -75
- package/dist/utils/analysis.js +0 -3
- package/dist/utils/index.d.ts +0 -8
- package/dist/utils/index.js +0 -10
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/mermaid.d.ts +0 -46
- package/dist/utils/mermaid.js +0 -4
- package/dist/utils/mermaid.js.map +0 -1
- package/dist/utils/middleware.d.ts +0 -11
- package/dist/utils/middleware.js +0 -3
- package/dist/utils/middleware.js.map +0 -1
- package/dist/utils/sanitize.d.ts +0 -19
- package/dist/utils/sanitize.js +0 -3
- package/dist/utils/sleep.d.ts +0 -9
- package/dist/utils/sleep.js +0 -4
- package/dist/utils/sleep.js.map +0 -1
- package/dist/workflow/AbstractNode.d.ts +0 -3
- package/dist/workflow/AbstractNode.js +0 -4
- package/dist/workflow/AbstractNode.js.map +0 -1
- package/dist/workflow/Flow.d.ts +0 -3
- package/dist/workflow/Flow.js +0 -16
- package/dist/workflow/Flow.js.map +0 -1
- package/dist/workflow/Node.d.ts +0 -3
- package/dist/workflow/Node.js +0 -15
- package/dist/workflow/Node.js.map +0 -1
- package/dist/workflow/index.d.ts +0 -4
- package/dist/workflow/index.js +0 -18
- package/dist/workflow/index.js.map +0 -1
- package/dist/workflow/node-patterns.d.ts +0 -55
- package/dist/workflow/node-patterns.js +0 -16
- package/dist/workflow/node-patterns.js.map +0 -1
- package/dist/workflow/registry.d.ts +0 -17
- package/dist/workflow/registry.js +0 -3
- package/dist/workflow/registry.js.map +0 -1
- /package/dist/{utils/analysis.js.map → analysis.js.map} +0 -0
- /package/dist/{builder/graph → runtime}/index.js.map +0 -0
- /package/dist/{builder/graph → runtime}/types.js.map +0 -0
package/dist/chunk-BRFMFLR6.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { applyMiddleware } from './chunk-PNWOW52F.js';
|
|
2
|
-
import { AbortError } from './chunk-64DNBF5W.js';
|
|
3
|
-
import { NullLogger } from './chunk-IIKTTIW5.js';
|
|
4
|
-
|
|
5
|
-
// src/executors/in-memory.ts
|
|
6
|
-
var InMemoryExecutor = class {
|
|
7
|
-
/**
|
|
8
|
-
* A stateless, reusable method that orchestrates the traversal of a graph.
|
|
9
|
-
* It is called by `run()` for top-level flows and by `Flow.exec()` for sub-flows.
|
|
10
|
-
* @param startNode The node where the graph traversal begins.
|
|
11
|
-
* @param flowMiddleware The middleware array from the containing flow.
|
|
12
|
-
* @param context The shared workflow context.
|
|
13
|
-
* @param options The internal, normalized run options.
|
|
14
|
-
* @returns The final action from the last executed node in the graph.
|
|
15
|
-
* @internal
|
|
16
|
-
*/
|
|
17
|
-
async _orch(startNode, flowMiddleware, context, options) {
|
|
18
|
-
let currentNode = startNode;
|
|
19
|
-
let nextNode;
|
|
20
|
-
let action;
|
|
21
|
-
const { logger, signal } = options;
|
|
22
|
-
const visitedInParallel = /* @__PURE__ */ new Set();
|
|
23
|
-
while (currentNode) {
|
|
24
|
-
if (signal?.aborted)
|
|
25
|
-
throw new AbortError();
|
|
26
|
-
if (visitedInParallel.has(currentNode)) {
|
|
27
|
-
currentNode = this.getNextNode(currentNode, void 0);
|
|
28
|
-
continue;
|
|
29
|
-
}
|
|
30
|
-
const nodeArgs = {
|
|
31
|
-
ctx: context,
|
|
32
|
-
params: { ...options.params, ...currentNode.params },
|
|
33
|
-
signal,
|
|
34
|
-
logger,
|
|
35
|
-
prepRes: void 0,
|
|
36
|
-
execRes: void 0,
|
|
37
|
-
name: currentNode.constructor.name,
|
|
38
|
-
executor: options.executor,
|
|
39
|
-
node: currentNode,
|
|
40
|
-
visitedInParallel
|
|
41
|
-
};
|
|
42
|
-
const chain = applyMiddleware(flowMiddleware, currentNode);
|
|
43
|
-
action = await chain(nodeArgs);
|
|
44
|
-
nextNode = this.getNextNode(currentNode, action);
|
|
45
|
-
if (!nextNode)
|
|
46
|
-
return action;
|
|
47
|
-
currentNode = nextNode;
|
|
48
|
-
}
|
|
49
|
-
return void 0;
|
|
50
|
-
}
|
|
51
|
-
async run(flow, context, options) {
|
|
52
|
-
const logger = options?.logger ?? new NullLogger();
|
|
53
|
-
const combinedParams = { ...flow.params, ...options?.params };
|
|
54
|
-
const internalOptions = {
|
|
55
|
-
logger,
|
|
56
|
-
signal: options?.signal ?? options?.controller?.signal,
|
|
57
|
-
params: combinedParams,
|
|
58
|
-
executor: this
|
|
59
|
-
};
|
|
60
|
-
if (!flow.startNode) {
|
|
61
|
-
logger.debug(`Executor is running a logic-bearing flow: ${flow.constructor.name}`);
|
|
62
|
-
const chain = applyMiddleware(flow.middleware, flow);
|
|
63
|
-
return await chain({
|
|
64
|
-
...internalOptions,
|
|
65
|
-
ctx: context,
|
|
66
|
-
prepRes: void 0,
|
|
67
|
-
execRes: void 0,
|
|
68
|
-
name: flow.constructor.name
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
return this._orch(flow.startNode, flow.middleware, context, internalOptions);
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Determines the next node to execute based on the action returned by the current node.
|
|
75
|
-
* @internal
|
|
76
|
-
*/
|
|
77
|
-
getNextNode(curr, action) {
|
|
78
|
-
const nextNodes = curr.successors.get(action);
|
|
79
|
-
return nextNodes?.[0];
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
export { InMemoryExecutor };
|
|
84
|
-
//# sourceMappingURL=chunk-BRFMFLR6.js.map
|
|
85
|
-
//# sourceMappingURL=chunk-BRFMFLR6.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/executors/in-memory.ts"],"names":[],"mappings":";;;;;AAaO,IAAM,mBAAN,MAA4C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWlD,MAAa,KAAA,CACZ,SAAA,EACA,cAAA,EACA,SACA,OAAA,EACa;AACb,IAAA,IAAI,WAAA,GAAwC,SAAA;AAC5C,IAAA,IAAI,QAAA;AACJ,IAAA,IAAI,MAAA;AAEJ,IAAA,MAAM,EAAE,MAAA,EAAQ,MAAA,EAAO,GAAI,OAAA;AAC3B,IAAA,MAAM,iBAAA,uBAAwB,GAAA,EAAkB;AAEhD,IAAA,OAAO,WAAA,EAAa;AACnB,MAA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AU,OAAA,EAAS,UAAA,EAAY,MAAA;AAAA,MAChD,MAAA,EAAQ,cAAA;AAAA,MACR,QAAA,EAAU;AAAA,KACX;AAEA,IAAA,IAAI,CAAC,KAAK,SAAA,EAAW;AACpB,MAAA,MAAA,CAAO,KAAA,CAAM,CAAA,0CAAA,EAA6C,IAAA,CAAK,WAAA,CAAY,IAAI,CAAA,CAAE,CAAA;AACjF,MAAA,MAAM,KAAA,GAAQ,eAAA,CAAgB,IAAA,CAAK,UAAA,EAAY,IAAI,CAAA;AACnD,MAAA,OAAO,MAAM,KAAA,CAAM;AAAA,QAClB,GAAG,eAAA;AAAA,QACH,GAAA,EAAK,OAAA;AAAA,QACL,OAAA,EAAS,MAAA;AAAA,QACT,OAAA,EAAS,MAAA;AAAA,QACT,IAAA,EAAM,KAAK,WAAA,CAAY;AAAA,OACvB,CAAA;AAAA,IACF;AAEA,IAAA,OAAO,KAAK,KAAA,CAAS,IAAA,CAAK,WAAW,IAAA,CAAK,UAAA,EAAY,SAAS,eAAe,CAAA;AAAA,EAC/E;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,WAAA,CAAY,MAAoB,MAAA,EAAuC;AAC7E,IAAA,MAAM,SAAA,GAAY,IAAA,CAAK,UAAA,CAAW,GAAA,CAAI,MAAM,CAAA;AAG5C,IAAA,OAAO,YAAY,CAAC,CAAA;AAAA,EACrB;AACD","file":"chunk-BRFMFLR6.js","sourcesContent":["import type { Context } from '../context'\nimport type { Middleware, NodeArgs, RunOptions } from '../types'\nimport type { AbstractNode, Flow } from '../workflow/index'\nimport type { IExecutor, InternalRunOptions } from './types'\nimport { AbortError } from '../errors'\nimport { NullLogger } from '../logger'\nimport { applyMiddleware } from '../utils/middleware'\n\n/**\n * The default executor that runs a workflow within a single, in-memory process.\n * This class contains the core logic for traversing a workflow graph, applying middleware,\n * and handling node execution.\n */\nexport class InMemoryExecutor implements IExecutor {\n\t/**\n\t * A stateless, reusable method that orchestrates the traversal of a graph.\n\t * It is called by `run()` for top-level flows and by `Flow.exec()` for sub-flows.\n\t * @param startNode The node where the graph traversal begins.\n\t * @param flowMiddleware The middleware array from the containing flow.\n\t * @param context The shared workflow context.\n\t * @param options The internal, normalized run options.\n\t * @returns The final action from the last executed node in the graph.\n\t * @internal\n\t */\n\tpublic async _orch<T = any>(\n\t\tstartNode: AbstractNode,\n\t\tflowMiddleware: Middleware[],\n\t\tcontext: Context,\n\t\toptions: InternalRunOptions,\n\t): Promise<T> {\n\t\tlet currentNode: AbstractNode | undefined = startNode\n\t\tlet nextNode: AbstractNode | undefined\n\t\tlet action: any\n\n\t\tconst { logger, signal } = options\n\t\tconst visitedInParallel = new Set<AbstractNode>()\n\n\t\twhile (currentNode) {\n\t\t\tif (signal?.aborted)\n\t\t\t\tthrow new AbortError()\n\n\t\t\tif (visitedInParallel.has(currentNode)) {\n\t\t\t\tcurrentNode = this.getNextNode(currentNode, undefined)\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tconst nodeArgs: NodeArgs = {\n\t\t\t\tctx: context,\n\t\t\t\tparams: { ...options.params, ...currentNode.params },\n\t\t\t\tsignal,\n\t\t\t\tlogger,\n\t\t\t\tprepRes: undefined,\n\t\t\t\texecRes: undefined,\n\t\t\t\tname: currentNode.constructor.name,\n\t\t\t\texecutor: options.executor,\n\t\t\t\tnode: currentNode,\n\t\t\t\tvisitedInParallel,\n\t\t\t}\n\n\t\t\tconst chain = applyMiddleware(flowMiddleware, currentNode)\n\t\t\taction = await chain(nodeArgs)\n\t\t\tnextNode = this.getNextNode(currentNode, action)\n\n\t\t\tif (!nextNode)\n\t\t\t\treturn action as T\n\n\t\t\tcurrentNode = nextNode\n\t\t}\n\n\t\treturn undefined as T\n\t}\n\n\t/**\n\t * Executes a given flow with a specific context and options.\n\t * This is the main entry point for the in-memory execution engine.\n\t * @param flow The Flow instance to execute.\n\t * @param context The shared context for the workflow.\n\t * @param options Runtime options, including a logger, abort controller, or initial params.\n\t * @returns A promise that resolves with the final action of the workflow.\n\t */\n\tpublic run<T>(flow: Flow<any, T>, context: Context, options?: RunOptions): Promise<T>\n\tpublic run(flow: Flow, context: Context, options?: RunOptions): Promise<any>\n\tpublic async run<T>(flow: Flow<any, T>, context: Context, options?: RunOptions): Promise<T> {\n\t\tconst logger = options?.logger ?? new NullLogger()\n\t\tconst combinedParams = { ...flow.params, ...options?.params }\n\n\t\tconst internalOptions: InternalRunOptions = {\n\t\t\tlogger,\n\t\t\tsignal: options?.signal ?? options?.controller?.signal,\n\t\t\tparams: combinedParams,\n\t\t\texecutor: this,\n\t\t}\n\n\t\tif (!flow.startNode) {\n\t\t\tlogger.debug(`Executor is running a logic-bearing flow: ${flow.constructor.name}`)\n\t\t\tconst chain = applyMiddleware(flow.middleware, flow)\n\t\t\treturn await chain({\n\t\t\t\t...internalOptions,\n\t\t\t\tctx: context,\n\t\t\t\tprepRes: undefined,\n\t\t\t\texecRes: undefined,\n\t\t\t\tname: flow.constructor.name,\n\t\t\t})\n\t\t}\n\n\t\treturn this._orch<T>(flow.startNode, flow.middleware, context, internalOptions)\n\t}\n\n\t/**\n\t * Determines the next node to execute based on the action returned by the current node.\n\t * @internal\n\t */\n\tpublic getNextNode(curr: AbstractNode, action: any): AbstractNode | undefined {\n\t\tconst nextNodes = curr.successors.get(action)\n\t\t// For the in-memory executor, we take the first successor for a given action.\n\t\t// Parallelism is handled by specific container nodes like ParallelFlow.\n\t\treturn nextNodes?.[0]\n\t}\n}\n"]}
|
package/dist/chunk-ELEHMJPM.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Node } from './chunk-HEO3XL4Z.js';
|
|
2
|
-
|
|
3
|
-
// src/workflow/node-patterns.ts
|
|
4
|
-
var ExecNode = class extends Node {
|
|
5
|
-
};
|
|
6
|
-
var PreNode = class extends Node {
|
|
7
|
-
};
|
|
8
|
-
var PostNode = class extends Node {
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export { ExecNode, PostNode, PreNode };
|
|
12
|
-
//# sourceMappingURL=chunk-ELEHMJPM.js.map
|
|
13
|
-
//# sourceMappingURL=chunk-ELEHMJPM.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/workflow/node-patterns.ts"],"names":[],"mappings":";;;AAYO,IAAe,QAAA,GAAf,cAIG,IAAA,CAA4C;AAQtD;AASO,IAAe,OAAA,GAAf,cAGG,IAAA,CAAyC;AAOnD;AAUO,IAAe,QAAA,GAAf,cAIG,IAAA,CAA6C;AAQvD","file":"chunk-ELEHMJPM.js","sourcesContent":["import type { Context } from '../context'\nimport type { NodeArgs, Params } from '../types'\nimport { Node } from './Node'\n\n/**\n * A simplified base class for nodes that only need to perform a core action.\n * This pattern is ideal for nodes that receive their inputs via `params` and\n * produce an output, without needing `prep` or complex `post` branching logic.\n *\n * @template ExecRes The type of data returned by the `exec` phase.\n * @template TParams The type for the node's static parameters.\n */\nexport abstract class ExecNode<\n\tExecRes = any,\n\tTParams extends Params = Params,\n\tTContext extends Context = Context,\n> extends Node<void, ExecRes, any, TParams, TContext> {\n\t/**\n\t * (Lifecycle) Performs the core, isolated logic of the node.\n\t * This is the only phase that is retried on failure. It should not access the `Context` directly.\n\t * @param args The arguments for the node, including `prepRes`.\n\t * @returns The result of the execution.\n\t */\n\tabstract override exec(args: NodeArgs<void, void, TParams, TContext>): Promise<ExecRes>\n}\n\n/**\n * A simplified base class for nodes that only perform a side effect, such as\n * modifying the `Context` or logging. These nodes do not produce an `exec` result.\n * Their logic is typically placed in the `prep` phase.\n *\n * @template TParams The type for the node's static parameters.\n */\nexport abstract class PreNode<\n\tTParams extends Params = Params,\n\tTContext extends Context = Context,\n> extends Node<void, void, any, TParams, TContext> {\n\t/**\n\t * (Lifecycle) Prepares data or performs a side effect. Runs once before `exec`.\n\t * This is the ideal place to read from or write to the `Context`.\n\t * @param args The arguments for the node, including `ctx` and `params`.\n\t */\n\tabstract override prep(args: NodeArgs<void, void, TParams, TContext>): Promise<void>\n}\n\n/**\n * A simplified base class for nodes that make a branching decision.\n * This pattern is ideal for routing the workflow based on data in the `Context`.\n * The branching logic is placed in the `post` phase, which returns a custom action string.\n *\n * @template PostRes The type of the \"action\" string returned by the `post` phase.\n * @template TParams The type for the node's static parameters.\n */\nexport abstract class PostNode<\n\tPostRes = any,\n\tTParams extends Params = Params,\n\tTContext extends Context = Context,\n> extends Node<void, void, PostRes, TParams, TContext> {\n\t/**\n\t * (Lifecycle) Processes results and determines the next step. Runs once after `exec`.\n\t * This is the ideal place to write data to the `Context` and return an action.\n\t * @param args The arguments for the node, including `execRes`.\n\t * @returns An \"action\" string to determine which successor to execute next.\n\t */\n\tabstract override post(args: NodeArgs<void, void, TParams, TContext>): Promise<PostRes>\n}\n"]}
|
package/dist/chunk-F2RSES6P.js
DELETED
package/dist/chunk-F6C6J7HK.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-F6C6J7HK.js"}
|
package/dist/chunk-GMKJ34T2.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-GMKJ34T2.js"}
|
package/dist/chunk-HEO3XL4Z.js
DELETED
|
@@ -1,328 +0,0 @@
|
|
|
1
|
-
import { sleep } from './chunk-6QCXIRLA.js';
|
|
2
|
-
import { InMemoryExecutor } from './chunk-BRFMFLR6.js';
|
|
3
|
-
import { AbstractNode } from './chunk-VZDHIOCH.js';
|
|
4
|
-
import { getFlowConstructor } from './chunk-S4WFNGQG.js';
|
|
5
|
-
import { AbortError, WorkflowError, FatalWorkflowError } from './chunk-64DNBF5W.js';
|
|
6
|
-
import { NullLogger } from './chunk-IIKTTIW5.js';
|
|
7
|
-
import { DEFAULT_ACTION, FILTER_FAILED } from './chunk-AOHBHYF6.js';
|
|
8
|
-
|
|
9
|
-
// src/workflow/Node.ts
|
|
10
|
-
var Node = class _Node extends AbstractNode {
|
|
11
|
-
/** The total number of times the `exec` phase will be attempted. */
|
|
12
|
-
maxRetries;
|
|
13
|
-
/** The time in milliseconds to wait between failed `exec` attempts. */
|
|
14
|
-
wait;
|
|
15
|
-
/**
|
|
16
|
-
* @param options Configuration options for the node's behavior.
|
|
17
|
-
* @param options.maxRetries Total number of `exec` attempts. Defaults to `1`.
|
|
18
|
-
* @param options.wait Milliseconds to wait between failed `exec` attempts. Defaults to `0`.
|
|
19
|
-
*/
|
|
20
|
-
constructor(options = {}) {
|
|
21
|
-
super();
|
|
22
|
-
this.maxRetries = options.maxRetries ?? 1;
|
|
23
|
-
this.wait = options.wait ?? 0;
|
|
24
|
-
}
|
|
25
|
-
_wrapError(e, phase) {
|
|
26
|
-
if (e instanceof AbortError || e instanceof WorkflowError)
|
|
27
|
-
return e;
|
|
28
|
-
return new WorkflowError(`Failed in ${phase} phase for node ${this.constructor.name}`, this.constructor.name, phase, e);
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* (Lifecycle) Prepares data for execution. Runs once before `exec`.
|
|
32
|
-
* This is the ideal place to read data from the `Context`.
|
|
33
|
-
* @param args The arguments for the node, including `ctx` and `params`.
|
|
34
|
-
* @returns The data required by the `exec` phase.
|
|
35
|
-
*/
|
|
36
|
-
async prep(args) {
|
|
37
|
-
return void 0;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* (Lifecycle) Performs the core, isolated logic of the node.
|
|
41
|
-
* This is the only phase that is retried on failure. It should not access the `Context` directly.
|
|
42
|
-
* @param args The arguments for the node, including `prepRes`.
|
|
43
|
-
* @returns The result of the execution.
|
|
44
|
-
*/
|
|
45
|
-
async exec(args) {
|
|
46
|
-
return void 0;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* (Lifecycle) Processes results and determines the next step. Runs once after `exec` succeeds.
|
|
50
|
-
* This is the ideal place to write data to the `Context`.
|
|
51
|
-
* @param args The arguments for the node, including `execRes`.
|
|
52
|
-
* @returns An "action" string to determine which successor to execute next. Defaults to `DEFAULT_ACTION`.
|
|
53
|
-
*/
|
|
54
|
-
async post(args) {
|
|
55
|
-
return DEFAULT_ACTION;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* (Lifecycle) A fallback that runs if all `exec` retries fail.
|
|
59
|
-
* If not implemented, the final error will be re-thrown, halting the workflow.
|
|
60
|
-
* @param args The arguments for the node, including the final `error` that caused the failure.
|
|
61
|
-
* @returns A fallback result of type `ExecRes`, allowing the workflow to recover and continue.
|
|
62
|
-
*/
|
|
63
|
-
async execFallback(args) {
|
|
64
|
-
if (args.error)
|
|
65
|
-
throw args.error;
|
|
66
|
-
throw new Error(`Node ${this.constructor.name} failed and has no fallback implementation.`);
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* The internal retry-aware execution logic for the `exec` phase.
|
|
70
|
-
* @internal
|
|
71
|
-
*/
|
|
72
|
-
async _exec(args) {
|
|
73
|
-
let lastError;
|
|
74
|
-
for (let curRetry = 0; curRetry < this.maxRetries; curRetry++) {
|
|
75
|
-
if (args.signal?.aborted)
|
|
76
|
-
throw new AbortError();
|
|
77
|
-
try {
|
|
78
|
-
return await this.exec(args);
|
|
79
|
-
} catch (e) {
|
|
80
|
-
const error = e;
|
|
81
|
-
lastError = error;
|
|
82
|
-
if (error instanceof FatalWorkflowError)
|
|
83
|
-
throw error;
|
|
84
|
-
if (error instanceof AbortError || error.name === "AbortError")
|
|
85
|
-
throw error;
|
|
86
|
-
if (curRetry < this.maxRetries - 1) {
|
|
87
|
-
args.logger.warn(`Attempt ${curRetry + 1}/${this.maxRetries} failed for ${this.constructor.name}. Retrying...`, { error });
|
|
88
|
-
if (this.wait > 0)
|
|
89
|
-
await sleep(this.wait, args.signal);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
args.logger.error(`All retries failed for ${this.constructor.name}. Executing fallback.`, { error: lastError });
|
|
94
|
-
if (args.signal?.aborted)
|
|
95
|
-
throw new AbortError();
|
|
96
|
-
return await this.execFallback({ ...args, error: lastError });
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* The internal method that executes the node's full lifecycle.
|
|
100
|
-
* @internal
|
|
101
|
-
*/
|
|
102
|
-
async _run({ ctx, params, signal, logger, executor, visitedInParallel }) {
|
|
103
|
-
if (signal?.aborted)
|
|
104
|
-
throw new AbortError();
|
|
105
|
-
let prepRes;
|
|
106
|
-
try {
|
|
107
|
-
prepRes = await this.prep({ ctx, params, signal, logger, prepRes: void 0, execRes: void 0, executor, visitedInParallel });
|
|
108
|
-
} catch (e) {
|
|
109
|
-
throw this._wrapError(e, "prep");
|
|
110
|
-
}
|
|
111
|
-
if (signal?.aborted)
|
|
112
|
-
throw new AbortError();
|
|
113
|
-
let execRes;
|
|
114
|
-
try {
|
|
115
|
-
execRes = await this._exec({ ctx, params, signal, logger, prepRes, execRes: void 0, executor, visitedInParallel });
|
|
116
|
-
} catch (e) {
|
|
117
|
-
throw this._wrapError(e, "exec");
|
|
118
|
-
}
|
|
119
|
-
if (signal?.aborted)
|
|
120
|
-
throw new AbortError();
|
|
121
|
-
try {
|
|
122
|
-
const action = await this.post({ ctx, params, signal, logger, prepRes, execRes, executor, visitedInParallel });
|
|
123
|
-
return action === void 0 ? DEFAULT_ACTION : action;
|
|
124
|
-
} catch (e) {
|
|
125
|
-
throw this._wrapError(e, "post");
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Runs the node as a standalone unit, independent of a larger flow.
|
|
130
|
-
* This is useful for testing individual nodes in isolation.
|
|
131
|
-
*
|
|
132
|
-
* @param ctx The shared workflow context.
|
|
133
|
-
* @param options Runtime options like a logger or abort controller.
|
|
134
|
-
* @returns The result of the node's `post` method (its action).
|
|
135
|
-
*/
|
|
136
|
-
async run(ctx, options) {
|
|
137
|
-
const Flow = getFlowConstructor();
|
|
138
|
-
const logger = options?.logger ?? new NullLogger();
|
|
139
|
-
if (this.successors.size > 0 && !(this instanceof Flow))
|
|
140
|
-
logger.warn("Node.run() called directly on a node with successors. The flow will not continue. Use a Flow to execute a sequence.");
|
|
141
|
-
const executor = options?.executor ?? new InMemoryExecutor();
|
|
142
|
-
return executor.run(new Flow(this), ctx, { ...options, params: this.params });
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Creates a new node that transforms the result of this node's `exec` phase.
|
|
146
|
-
*
|
|
147
|
-
* @remarks
|
|
148
|
-
* This method returns a **new** `Node` instance and does not modify the original.
|
|
149
|
-
* The new node inherits the original's `prep` method. The original `post` method
|
|
150
|
-
* is discarded as it is incompatible with the new result type.
|
|
151
|
-
*
|
|
152
|
-
* @example
|
|
153
|
-
* const fetchUserNode = new FetchUserNode() // returns { id: 1, name: 'Alice' }
|
|
154
|
-
* const getUserNameNode = fetchUserNode.map(user => user.name) // returns 'Alice'
|
|
155
|
-
*
|
|
156
|
-
* @param fn A sync or async function to transform the execution result from `ExecRes` to `NewRes`.
|
|
157
|
-
* @returns A new `Node` instance with the transformed output type.
|
|
158
|
-
*/
|
|
159
|
-
map(fn) {
|
|
160
|
-
const originalNode = this;
|
|
161
|
-
const maxRetries = this.maxRetries;
|
|
162
|
-
const wait = this.wait;
|
|
163
|
-
return new class extends _Node {
|
|
164
|
-
constructor() {
|
|
165
|
-
super({ maxRetries, wait });
|
|
166
|
-
}
|
|
167
|
-
async prep(args) {
|
|
168
|
-
return originalNode.prep(args);
|
|
169
|
-
}
|
|
170
|
-
async exec(args) {
|
|
171
|
-
const originalResult = await originalNode.exec(args);
|
|
172
|
-
return fn(originalResult);
|
|
173
|
-
}
|
|
174
|
-
async post(_args) {
|
|
175
|
-
return DEFAULT_ACTION;
|
|
176
|
-
}
|
|
177
|
-
}();
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Creates a new node that stores the result of this node's `exec` phase in the `Context`.
|
|
181
|
-
* This is a common terminal operation for a data processing chain.
|
|
182
|
-
*
|
|
183
|
-
* @remarks
|
|
184
|
-
* This method returns a **new** `Node` instance and does not modify the original.
|
|
185
|
-
*
|
|
186
|
-
* @example
|
|
187
|
-
* const USER_NAME = contextKey<string>('user_name')
|
|
188
|
-
* const workflow = new FetchUserNode()
|
|
189
|
-
* .map(user => user.name)
|
|
190
|
-
* .toContext(USER_NAME)
|
|
191
|
-
*
|
|
192
|
-
* @param key The type-safe `ContextKey` to use for storing the result.
|
|
193
|
-
* @returns A new `Node` instance that performs the context update in its `post` phase.
|
|
194
|
-
*/
|
|
195
|
-
toContext(key) {
|
|
196
|
-
const originalNode = this;
|
|
197
|
-
const maxRetries = this.maxRetries;
|
|
198
|
-
const wait = this.wait;
|
|
199
|
-
return new class extends _Node {
|
|
200
|
-
constructor() {
|
|
201
|
-
super({ maxRetries, wait });
|
|
202
|
-
}
|
|
203
|
-
async prep(args) {
|
|
204
|
-
return originalNode.prep(args);
|
|
205
|
-
}
|
|
206
|
-
async exec(args) {
|
|
207
|
-
return originalNode.exec(args);
|
|
208
|
-
}
|
|
209
|
-
async post(args) {
|
|
210
|
-
args.ctx.set(key, args.execRes);
|
|
211
|
-
return DEFAULT_ACTION;
|
|
212
|
-
}
|
|
213
|
-
}();
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Creates a new node that acts as a conditional gate based on the `exec` result.
|
|
217
|
-
* If the predicate returns `true`, the node returns `DEFAULT_ACTION`.
|
|
218
|
-
* If it returns `false`, the node returns `FILTER_FAILED`, enabling branching.
|
|
219
|
-
*
|
|
220
|
-
* @remarks
|
|
221
|
-
* This method returns a **new** `Node` instance and does not modify the original.
|
|
222
|
-
*
|
|
223
|
-
* @example
|
|
224
|
-
* const checkAdminNode = new FetchUserNode().filter(user => user.isAdmin)
|
|
225
|
-
*
|
|
226
|
-
* checkAdminNode.next(adminOnlyNode, DEFAULT_ACTION)
|
|
227
|
-
* checkAdminNode.next(accessDeniedNode, FILTER_FAILED)
|
|
228
|
-
*
|
|
229
|
-
* @param predicate A sync or async function that returns `true` or `false`.
|
|
230
|
-
* @returns A new `Node` instance that implements the filter logic.
|
|
231
|
-
*/
|
|
232
|
-
filter(predicate) {
|
|
233
|
-
const originalNode = this;
|
|
234
|
-
return new class extends _Node {
|
|
235
|
-
didPass = false;
|
|
236
|
-
async prep(args) {
|
|
237
|
-
return originalNode.prep(args);
|
|
238
|
-
}
|
|
239
|
-
async exec(args) {
|
|
240
|
-
const result = await originalNode.exec(args);
|
|
241
|
-
this.didPass = await predicate(result);
|
|
242
|
-
if (!this.didPass)
|
|
243
|
-
args.logger.debug(`[Filter] Predicate failed for node ${this.constructor.name}.`);
|
|
244
|
-
return result;
|
|
245
|
-
}
|
|
246
|
-
async post(_args) {
|
|
247
|
-
return this.didPass ? DEFAULT_ACTION : FILTER_FAILED;
|
|
248
|
-
}
|
|
249
|
-
}();
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* Creates a new node that performs a side effect with the `exec` result,
|
|
253
|
-
* but passes the original result through unmodified. Ideal for logging or debugging.
|
|
254
|
-
*
|
|
255
|
-
* @remarks
|
|
256
|
-
* This method returns a **new** `Node` instance and does not modify the original.
|
|
257
|
-
*
|
|
258
|
-
* @example
|
|
259
|
-
* const workflow = new FetchUserNode()
|
|
260
|
-
* .tap(user => console.log('Fetched User:', user))
|
|
261
|
-
* .map(user => user.id)
|
|
262
|
-
*
|
|
263
|
-
* @param fn A function to call with the execution result for its side effect.
|
|
264
|
-
* @returns A new `Node` instance that wraps the original.
|
|
265
|
-
*/
|
|
266
|
-
tap(fn) {
|
|
267
|
-
const originalNode = this;
|
|
268
|
-
const maxRetries = this.maxRetries;
|
|
269
|
-
const wait = this.wait;
|
|
270
|
-
return new class extends _Node {
|
|
271
|
-
constructor() {
|
|
272
|
-
super({ maxRetries, wait });
|
|
273
|
-
}
|
|
274
|
-
async prep(args) {
|
|
275
|
-
return originalNode.prep(args);
|
|
276
|
-
}
|
|
277
|
-
async exec(args) {
|
|
278
|
-
const originalResult = await originalNode.exec(args);
|
|
279
|
-
await fn(originalResult);
|
|
280
|
-
return originalResult;
|
|
281
|
-
}
|
|
282
|
-
async post(args) {
|
|
283
|
-
return originalNode.post(args);
|
|
284
|
-
}
|
|
285
|
-
}();
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* Creates a new node that applies a context mutation using a lens before executing.
|
|
289
|
-
* This allows for declaratively setting or updating context as part of a fluent chain.
|
|
290
|
-
*
|
|
291
|
-
* @remarks
|
|
292
|
-
* This method returns a **new** `Node` instance and does not modify the original.
|
|
293
|
-
*
|
|
294
|
-
* @example
|
|
295
|
-
* const VALUE = contextKey<number>('value')
|
|
296
|
-
* const valueLens = lens(VALUE)
|
|
297
|
-
*
|
|
298
|
-
* const nodeWithLens = new SomeNode().withLens(valueLens, 42) // Sets VALUE to 42 before SomeNode runs
|
|
299
|
-
*
|
|
300
|
-
* @param lens The `ContextLens` to use for the operation.
|
|
301
|
-
* @param value The value to set in the context via the lens.
|
|
302
|
-
* @returns A new `Node` instance that applies the context change.
|
|
303
|
-
*/
|
|
304
|
-
withLens(lens, value) {
|
|
305
|
-
const originalNode = this;
|
|
306
|
-
const maxRetries = this.maxRetries;
|
|
307
|
-
const wait = this.wait;
|
|
308
|
-
return new class extends _Node {
|
|
309
|
-
constructor() {
|
|
310
|
-
super({ maxRetries, wait });
|
|
311
|
-
}
|
|
312
|
-
async prep(args) {
|
|
313
|
-
await lens.set(value)(args.ctx);
|
|
314
|
-
return originalNode.prep(args);
|
|
315
|
-
}
|
|
316
|
-
async exec(args) {
|
|
317
|
-
return originalNode.exec(args);
|
|
318
|
-
}
|
|
319
|
-
async post(args) {
|
|
320
|
-
return originalNode.post(args);
|
|
321
|
-
}
|
|
322
|
-
}();
|
|
323
|
-
}
|
|
324
|
-
};
|
|
325
|
-
|
|
326
|
-
export { Node };
|
|
327
|
-
//# sourceMappingURL=chunk-HEO3XL4Z.js.map
|
|
328
|
-
//# sourceMappingURL=chunk-HEO3XL4Z.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/workflow/Node.ts"],"names":[],"m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L4Z.js","sourcesContent":["/* eslint-disable unused-imports/no-unused-vars, ts/no-this-alias */\n\nimport type { Context, ContextKey, ContextLens } from '../context'\nimport type { NodeArgs, NodeOptions, NodeRunContext, Params, RunOptions } from '../types'\nimport { AbortError, FatalWorkflowError, WorkflowError } from '../errors'\nimport { InMemoryExecutor } from '../executors/in-memory'\nimport { NullLogger } from '../logger'\nimport { DEFAULT_ACTION, FILTER_FAILED } from '../types'\nimport { sleep } from '../utils/index'\nimport { AbstractNode } from './AbstractNode'\nimport { getFlowConstructor } from './registry'\n\n/**\n * The fundamental building block of a workflow, representing a single unit of work.\n * It features a three-phase lifecycle, retry logic, and a fluent API for creating\n * data processing pipelines.\n *\n * @template PrepRes The type of data returned by the `prep` phase.\n * @template ExecRes The type of data returned by the `exec` phase.\n * @template PostRes The type of the action returned by the `post` phase.\n * @template TParams The type for the node's static parameters.\n */\nexport class Node<\n\tPrepRes = any,\n\tExecRes = any,\n\tPostRes = any,\n\tTParams extends Params = Params,\n\tTContext extends Context = Context,\n> extends AbstractNode<PostRes, TParams, TContext> {\n\t/** The total number of times the `exec` phase will be attempted. */\n\tpublic maxRetries: number\n\t/** The time in milliseconds to wait between failed `exec` attempts. */\n\tpublic wait: number\n\n\t/**\n\t * @param options Configuration options for the node's behavior.\n\t * @param options.maxRetries Total number of `exec` attempts. Defaults to `1`.\n\t * @param options.wait Milliseconds to wait between failed `exec` attempts. Defaults to `0`.\n\t */\n\tconstructor(options: NodeOptions = {}) {\n\t\tsuper()\n\t\tthis.maxRetries = options.maxRetries ?? 1\n\t\tthis.wait = options.wait ?? 0\n\t}\n\n\tprotected _wrapError(e: any, phase: 'prep' | 'exec' | 'post'): Error {\n\t\tif (e instanceof AbortError || e instanceof WorkflowError)\n\t\t\treturn e\n\n\t\treturn new WorkflowError(`Failed in ${phase} phase for node ${this.constructor.name}`, this.constructor.name, phase, e as Error)\n\t}\n\n\t/**\n\t * (Lifecycle) Prepares data for execution. Runs once before `exec`.\n\t * This is the ideal place to read data from the `Context`.\n\t * @param args The arguments for the node, including `ctx` and `params`.\n\t * @returns The data required by the `exec` phase.\n\t */\n\tasync prep(args: NodeArgs<void, void, TParams, TContext>): Promise<PrepRes> { return undefined as unknown as PrepRes }\n\n\t/**\n\t * (Lifecycle) Performs the core, isolated logic of the node.\n\t * This is the only phase that is retried on failure. It should not access the `Context` directly.\n\t * @param args The arguments for the node, including `prepRes`.\n\t * @returns The result of the execution.\n\t */\n\tasync exec(args: NodeArgs<PrepRes, void, TParams, TContext>): Promise<ExecRes> { return undefined as unknown as ExecRes }\n\n\t/**\n\t * (Lifecycle) Processes results and determines the next step. Runs once after `exec` succeeds.\n\t * This is the ideal place to write data to the `Context`.\n\t * @param args The arguments for the node, including `execRes`.\n\t * @returns An \"action\" string to determine which successor to execute next. Defaults to `DEFAULT_ACTION`.\n\t */\n\tasync post(args: NodeArgs<PrepRes, ExecRes, TParams, TContext>): Promise<PostRes> { return DEFAULT_ACTION as any }\n\n\t/**\n\t * (Lifecycle) A fallback that runs if all `exec` retries fail.\n\t * If not implemented, the final error will be re-thrown, halting the workflow.\n\t * @param args The arguments for the node, including the final `error` that caused the failure.\n\t * @returns A fallback result of type `ExecRes`, allowing the workflow to recover and continue.\n\t */\n\tasync execFallback(args: NodeArgs<PrepRes, void, TParams, TContext>): Promise<ExecRes> {\n\t\tif (args.error)\n\t\t\tthrow args.error\n\n\t\tthrow new Error(`Node ${this.constructor.name} failed and has no fallback implementation.`)\n\t}\n\n\t/**\n\t * The internal retry-aware execution logic for the `exec` phase.\n\t * @internal\n\t */\n\tasync _exec(args: NodeArgs<PrepRes, void, TParams, TContext>): Promise<ExecRes> {\n\t\tlet lastError: Error | undefined\n\t\tfor (let curRetry = 0; curRetry < this.maxRetries; curRetry++) {\n\t\t\tif (args.signal?.aborted)\n\t\t\t\tthrow new AbortError()\n\t\t\ttry {\n\t\t\t\treturn await this.exec(args)\n\t\t\t}\n\t\t\tcatch (e) {\n\t\t\t\tconst error = e as Error\n\t\t\t\tlastError = error\n\n\t\t\t\tif (error instanceof FatalWorkflowError)\n\t\t\t\t\tthrow error\n\n\t\t\t\tif (error instanceof AbortError || error.name === 'AbortError')\n\t\t\t\t\tthrow error\n\n\t\t\t\tif (curRetry < this.maxRetries - 1) {\n\t\t\t\t\targs.logger.warn(`Attempt ${curRetry + 1}/${this.maxRetries} failed for ${this.constructor.name}. Retrying...`, { error })\n\t\t\t\t\tif (this.wait > 0)\n\t\t\t\t\t\tawait sleep(this.wait, args.signal)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\targs.logger.error(`All retries failed for ${this.constructor.name}. Executing fallback.`, { error: lastError })\n\t\tif (args.signal?.aborted)\n\t\t\tthrow new AbortError()\n\t\treturn await this.execFallback({ ...args, error: lastError })\n\t}\n\n\t/**\n\t * The internal method that executes the node's full lifecycle.\n\t * @internal\n\t */\n\tasync _run({ ctx, params, signal, logger, executor, visitedInParallel }: NodeRunContext<TContext>): Promise<PostRes> {\n\t\tif (signal?.aborted)\n\t\t\tthrow new AbortError()\n\t\tlet prepRes: PrepRes\n\t\ttry {\n\t\t\tprepRes = await this.prep({ ctx: ctx as TContext, params: params as TParams, signal, logger, prepRes: undefined, execRes: undefined, executor, visitedInParallel })\n\t\t}\n\t\tcatch (e) {\n\t\t\tthrow this._wrapError(e, 'prep')\n\t\t}\n\n\t\tif (signal?.aborted)\n\t\t\tthrow new AbortError()\n\t\tlet execRes: ExecRes\n\t\ttry {\n\t\t\texecRes = await this._exec({ ctx: ctx as TContext, params: params as TParams, signal, logger, prepRes, execRes: undefined, executor, visitedInParallel })\n\t\t}\n\t\tcatch (e) {\n\t\t\tthrow this._wrapError(e, 'exec')\n\t\t}\n\n\t\tif (signal?.aborted)\n\t\t\tthrow new AbortError()\n\t\ttry {\n\t\t\tconst action = await this.post({ ctx: ctx as TContext, params: params as TParams, signal, logger, prepRes, execRes, executor, visitedInParallel })\n\t\t\treturn action === undefined ? DEFAULT_ACTION as any : action\n\t\t}\n\t\tcatch (e) {\n\t\t\tthrow this._wrapError(e, 'post')\n\t\t}\n\t}\n\n\t/**\n\t * Runs the node as a standalone unit, independent of a larger flow.\n\t * This is useful for testing individual nodes in isolation.\n\t *\n\t * @param ctx The shared workflow context.\n\t * @param options Runtime options like a logger or abort controller.\n\t * @returns The result of the node's `post` method (its action).\n\t */\n\tasync run(ctx: TContext, options?: RunOptions): Promise<PostRes> {\n\t\tconst Flow = getFlowConstructor()\n\t\tconst logger = options?.logger ?? new NullLogger()\n\t\tif (this.successors.size > 0 && !(this instanceof Flow))\n\t\t\tlogger.warn('Node.run() called directly on a node with successors. The flow will not continue. Use a Flow to execute a sequence.')\n\t\tconst executor = options?.executor ?? new InMemoryExecutor()\n\t\t// Wrap the node in a Flow and pass its params via the options.\n\t\treturn executor.run(new Flow(this), ctx, { ...options, params: this.params })\n\t}\n\n\t/**\n\t * Creates a new node that transforms the result of this node's `exec` phase.\n\t *\n\t * @remarks\n\t * This method returns a **new** `Node` instance and does not modify the original.\n\t * The new node inherits the original's `prep` method. The original `post` method\n\t * is discarded as it is incompatible with the new result type.\n\t *\n\t * @example\n\t * const fetchUserNode = new FetchUserNode() // returns { id: 1, name: 'Alice' }\n\t * const getUserNameNode = fetchUserNode.map(user => user.name) // returns 'Alice'\n\t *\n\t * @param fn A sync or async function to transform the execution result from `ExecRes` to `NewRes`.\n\t * @returns A new `Node` instance with the transformed output type.\n\t */\n\tmap<NewRes>(fn: (result: ExecRes) => NewRes | Promise<NewRes>): Node<PrepRes, NewRes, any, TParams, TContext> {\n\t\tconst originalNode = this\n\t\tconst maxRetries = this.maxRetries\n\t\tconst wait = this.wait\n\n\t\treturn new class extends Node<PrepRes, NewRes, any, TParams, TContext> {\n\t\t\tconstructor() { super({ maxRetries, wait }) }\n\t\t\tasync prep(args: NodeArgs<void, void, TParams, TContext>): Promise<PrepRes> { return originalNode.prep(args) }\n\t\t\tasync exec(args: NodeArgs<PrepRes, void, TParams, TContext>): Promise<NewRes> {\n\t\t\t\tconst originalResult = await originalNode.exec(args)\n\t\t\t\treturn fn(originalResult)\n\t\t\t}\n\n\t\t\tasync post(_args: NodeArgs<PrepRes, NewRes, TParams, TContext>): Promise<any> {\n\t\t\t\treturn DEFAULT_ACTION\n\t\t\t}\n\t\t}()\n\t}\n\n\t/**\n\t * Creates a new node that stores the result of this node's `exec` phase in the `Context`.\n\t * This is a common terminal operation for a data processing chain.\n\t *\n\t * @remarks\n\t * This method returns a **new** `Node` instance and does not modify the original.\n\t *\n\t * @example\n\t * const USER_NAME = contextKey<string>('user_name')\n\t * const workflow = new FetchUserNode()\n\t * .map(user => user.name)\n\t * .toContext(USER_NAME)\n\t *\n\t * @param key The type-safe `ContextKey` to use for storing the result.\n\t * @returns A new `Node` instance that performs the context update in its `post` phase.\n\t */\n\ttoContext(key: ContextKey<ExecRes>): Node<PrepRes, ExecRes, any, TParams, TContext> {\n\t\tconst originalNode = this\n\t\tconst maxRetries = this.maxRetries\n\t\tconst wait = this.wait\n\n\t\treturn new class extends Node<PrepRes, ExecRes, any, TParams, TContext> {\n\t\t\tconstructor() { super({ maxRetries, wait }) }\n\t\t\tasync prep(args: NodeArgs<void, void, TParams, TContext>): Promise<PrepRes> { return originalNode.prep(args) }\n\t\t\tasync exec(args: NodeArgs<PrepRes, void, TParams, TContext>): Promise<ExecRes> { return originalNode.exec(args) }\n\t\t\tasync post(args: NodeArgs<PrepRes, ExecRes, TParams, TContext>): Promise<any> {\n\t\t\t\targs.ctx.set(key, args.execRes)\n\t\t\t\treturn DEFAULT_ACTION\n\t\t\t}\n\t\t}()\n\t}\n\n\t/**\n\t * Creates a new node that acts as a conditional gate based on the `exec` result.\n\t * If the predicate returns `true`, the node returns `DEFAULT_ACTION`.\n\t * If it returns `false`, the node returns `FILTER_FAILED`, enabling branching.\n\t *\n\t * @remarks\n\t * This method returns a **new** `Node` instance and does not modify the original.\n\t *\n\t * @example\n\t * const checkAdminNode = new FetchUserNode().filter(user => user.isAdmin)\n\t *\n\t * checkAdminNode.next(adminOnlyNode, DEFAULT_ACTION)\n\t * checkAdminNode.next(accessDeniedNode, FILTER_FAILED)\n\t *\n\t * @param predicate A sync or async function that returns `true` or `false`.\n\t * @returns A new `Node` instance that implements the filter logic.\n\t */\n\tfilter(predicate: (result: ExecRes) => boolean | Promise<boolean>): Node<PrepRes, ExecRes, any, TParams, TContext> {\n\t\tconst originalNode = this\n\n\t\treturn new class extends Node<PrepRes, ExecRes, any, TParams, TContext> {\n\t\t\tprivate didPass = false\n\n\t\t\tasync prep(args: NodeArgs<void, void, TParams, TContext>) { return originalNode.prep(args) }\n\t\t\tasync exec(args: NodeArgs<PrepRes, void, TParams, TContext>): Promise<ExecRes> {\n\t\t\t\tconst result = await originalNode.exec(args)\n\t\t\t\tthis.didPass = await predicate(result)\n\t\t\t\tif (!this.didPass)\n\t\t\t\t\targs.logger.debug(`[Filter] Predicate failed for node ${this.constructor.name}.`)\n\n\t\t\t\treturn result\n\t\t\t}\n\n\t\t\tasync post(_args: NodeArgs<PrepRes, ExecRes, TParams, TContext>): Promise<any> {\n\t\t\t\treturn this.didPass ? DEFAULT_ACTION : FILTER_FAILED\n\t\t\t}\n\t\t}()\n\t}\n\n\t/**\n\t * Creates a new node that performs a side effect with the `exec` result,\n\t * but passes the original result through unmodified. Ideal for logging or debugging.\n\t *\n\t * @remarks\n\t * This method returns a **new** `Node` instance and does not modify the original.\n\t *\n\t * @example\n\t * const workflow = new FetchUserNode()\n\t * .tap(user => console.log('Fetched User:', user))\n\t * .map(user => user.id)\n\t *\n\t * @param fn A function to call with the execution result for its side effect.\n\t * @returns A new `Node` instance that wraps the original.\n\t */\n\ttap(fn: (result: ExecRes) => void | Promise<void>): Node<PrepRes, ExecRes, PostRes, TParams, TContext> {\n\t\tconst originalNode = this\n\t\tconst maxRetries = this.maxRetries\n\t\tconst wait = this.wait\n\n\t\treturn new class extends Node<PrepRes, ExecRes, PostRes, TParams, TContext> {\n\t\t\tconstructor() { super({ maxRetries, wait }) }\n\t\t\tasync prep(args: NodeArgs<void, void, TParams, TContext>): Promise<PrepRes> {\n\t\t\t\treturn originalNode.prep(args)\n\t\t\t}\n\n\t\t\tasync exec(args: NodeArgs<PrepRes, void, TParams, TContext>): Promise<ExecRes> {\n\t\t\t\tconst originalResult = await originalNode.exec(args)\n\t\t\t\tawait fn(originalResult)\n\t\t\t\treturn originalResult\n\t\t\t}\n\n\t\t\tasync post(args: NodeArgs<PrepRes, ExecRes, TParams, TContext>): Promise<PostRes> {\n\t\t\t\treturn originalNode.post(args)\n\t\t\t}\n\t\t}()\n\t}\n\n\t/**\n\t * Creates a new node that applies a context mutation using a lens before executing.\n\t * This allows for declaratively setting or updating context as part of a fluent chain.\n\t *\n\t * @remarks\n\t * This method returns a **new** `Node` instance and does not modify the original.\n\t *\n\t * @example\n\t * const VALUE = contextKey<number>('value')\n\t * const valueLens = lens(VALUE)\n\t *\n\t * const nodeWithLens = new SomeNode().withLens(valueLens, 42) // Sets VALUE to 42 before SomeNode runs\n\t *\n\t * @param lens The `ContextLens` to use for the operation.\n\t * @param value The value to set in the context via the lens.\n\t * @returns A new `Node` instance that applies the context change.\n\t */\n\twithLens<T>(lens: ContextLens<T>, value: T): Node<PrepRes, ExecRes, PostRes, TParams, TContext> {\n\t\tconst originalNode = this\n\t\tconst maxRetries = this.maxRetries\n\t\tconst wait = this.wait\n\n\t\treturn new class extends Node<PrepRes, ExecRes, PostRes, TParams, TContext> {\n\t\t\tconstructor() { super({ maxRetries, wait }) }\n\t\t\tasync prep(args: NodeArgs<void, void, TParams, TContext>): Promise<PrepRes> {\n\t\t\t\t// Apply the lens transformation before executing the original node's logic.\n\t\t\t\tawait lens.set(value)(args.ctx)\n\t\t\t\treturn originalNode.prep(args)\n\t\t\t}\n\n\t\t\tasync exec(args: NodeArgs<PrepRes, void, TParams, TContext>): Promise<ExecRes> {\n\t\t\t\treturn originalNode.exec(args)\n\t\t\t}\n\n\t\t\tasync post(args: NodeArgs<PrepRes, ExecRes, TParams, TContext>): Promise<PostRes> {\n\t\t\t\treturn originalNode.post(args)\n\t\t\t}\n\t\t}()\n\t}\n}\n"]}
|
package/dist/chunk-IIKTTIW5.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
// src/logger.ts
|
|
2
|
-
var NullLogger = class {
|
|
3
|
-
debug() {
|
|
4
|
-
}
|
|
5
|
-
info() {
|
|
6
|
-
}
|
|
7
|
-
warn() {
|
|
8
|
-
}
|
|
9
|
-
error() {
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
var levelPriorities = {
|
|
13
|
-
debug: 1,
|
|
14
|
-
info: 2,
|
|
15
|
-
warn: 3,
|
|
16
|
-
error: 4
|
|
17
|
-
};
|
|
18
|
-
var ConsoleLogger = class {
|
|
19
|
-
minLevel;
|
|
20
|
-
/**
|
|
21
|
-
* @param options Configuration for the logger.
|
|
22
|
-
* @param options.level The minimum level of messages to log. Defaults to 'info'.
|
|
23
|
-
*/
|
|
24
|
-
constructor(options = {}) {
|
|
25
|
-
this.minLevel = options.level ?? "info";
|
|
26
|
-
}
|
|
27
|
-
log(level, message, context) {
|
|
28
|
-
if (levelPriorities[level] < levelPriorities[this.minLevel]) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
const fullMessage = `[${level.toUpperCase()}] ${message}`;
|
|
32
|
-
if (context && Object.keys(context).length > 0) {
|
|
33
|
-
const logMethod = console[level] || console.log;
|
|
34
|
-
logMethod(fullMessage, context);
|
|
35
|
-
} else {
|
|
36
|
-
const logMethod = console[level] || console.log;
|
|
37
|
-
logMethod(fullMessage);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
debug(message, context) {
|
|
41
|
-
this.log("debug", message, context);
|
|
42
|
-
}
|
|
43
|
-
info(message, context) {
|
|
44
|
-
this.log("info", message, context);
|
|
45
|
-
}
|
|
46
|
-
warn(message, context) {
|
|
47
|
-
this.log("warn", message, context);
|
|
48
|
-
}
|
|
49
|
-
error(message, context) {
|
|
50
|
-
this.log("error", message, context);
|
|
51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AAAA,IAC/B,CAAA,MACK;AACJ,MAAA,MAAM,SAAA,GAAY,OAAA,CAAQ,KAAK,CAAA,IAAK,OAAA,CAAQ,GAAA;AAC5C,MAAA,SAAA,CAAU,WAAW,CAAA;AAAA,IACtB;AAAA,EACD;AAAA,EAEA,KAAA,CAAM,SAAiB,OAAA,EAAkB;AAAE,IAAA,IAAA,CAAK,GAAA,CAAI,OAAA,EAAS,OAAA,EAAS,OAAO,CAAA;AAAA,EAAE;AAAA,EAC/E,IAAA,CAAK,SAAiB,OAAA,EAAkB;AAAE,IAAA,IAAA,CAAK,GAAA,CAAI,MAAA,EAAQ,OAAA,EAAS,OAAO,CAAA;AAAA,EAAE;AAAA,EAC7E,IAAA,CAAK,SAAiB,OAAA,EAAkB;AAAE,IAAA,IAAA,CAAK,GAAA,CAAI,MAAA,EAAQ,OAAA,EAAS,OAAO,CAAA;AAAA,EAAE;AAAA,EAC7E,KAAA,CAAM,SAAiB,OAAA,EAAkB;AAAE,IAAA,IAAA,CAAK,GAAA,CAAI,OAAA,EAAS,OAAA,EAAS,OAAO,CAAA;AAAA,EAAE;AAChF","file":"chunk-IIKTTIW5.js","sourcesContent":["/**\n * Defines the interface for a logger that can be used by the workflow engine.\n * This allows for plugging in any logging library (e.g., Pino, Winston).\n */\nexport interface Logger {\n\tdebug: (message: string, context?: object) => void\n\tinfo: (message: string, context?: object) => void\n\twarn: (message: string, context?: object) => void\n\terror: (message: string, context?: object) => void\n}\n\n/**\n * A logger implementation that performs no action (a \"no-op\" logger).\n * This is the default logger used by the framework if none is provided,\n * making Flowcraft silent out-of-the-box.\n */\nexport class NullLogger implements Logger {\n\tdebug() { /* no-op */ }\n\tinfo() { /* no-op */ }\n\twarn() { /* no-op */ }\n\terror() { /* no-op */ }\n}\n\ntype LogLevel = 'debug' | 'info' | 'warn' | 'error'\n\nconst levelPriorities: Record<LogLevel, number> = {\n\tdebug: 1,\n\tinfo: 2,\n\twarn: 3,\n\terror: 4,\n}\n\n/**\n * A default logger implementation that writes messages to the `console`.\n * It supports a minimum log level to control verbosity.\n */\nexport class ConsoleLogger implements Logger {\n\tprivate minLevel: LogLevel\n\n\t/**\n\t * @param options Configuration for the logger.\n\t * @param options.level The minimum level of messages to log. Defaults to 'info'.\n\t */\n\tconstructor(options: { level?: LogLevel } = {}) {\n\t\tthis.minLevel = options.level ?? 'info'\n\t}\n\n\tprivate log(level: LogLevel, message: string, context?: object) {\n\t\tif (levelPriorities[level] < levelPriorities[this.minLevel]) {\n\t\t\treturn\n\t\t}\n\n\t\tconst fullMessage = `[${level.toUpperCase()}] ${message}`\n\t\tif (context && Object.keys(context).length > 0) {\n\t\t\tconst logMethod = console[level] || console.log\n\t\t\tlogMethod(fullMessage, context)\n\t\t}\n\t\telse {\n\t\t\tconst logMethod = console[level] || console.log\n\t\t\tlogMethod(fullMessage)\n\t\t}\n\t}\n\n\tdebug(message: string, context?: object) { this.log('debug', message, context) }\n\tinfo(message: string, context?: object) { this.log('info', message, context) }\n\twarn(message: string, context?: object) { this.log('warn', message, context) }\n\terror(message: string, context?: object) { this.log('error', message, context) }\n}\n"]}
|
package/dist/chunk-KOBEU2EM.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-KOBEU2EM.js"}
|