graph-mode 0.1.1 → 0.1.3

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.
Files changed (2) hide show
  1. package/README.md +30 -9
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -23,27 +23,47 @@ enum Nodes {
23
23
  PROCESS = 'PROCESS',
24
24
  }
25
25
 
26
+ type InputSchema = {
27
+ input: string,
28
+ }
29
+
30
+ type OutputSchema = {
31
+ output: string,
32
+ }
33
+
26
34
  // Create nodes with exec and routing functions
27
- const startNode = new GraphNode({
35
+ const startNode = new GraphNode<InputSchema, OutputSchema, Nodes>({
28
36
  nodeType: Nodes.START,
29
37
  description: 'Initial node that prepares data',
30
- exec: (input: { data: string }) => ({ ...input, started: true }),
31
- routing: () => Nodes.PROCESS, // Route to PROCESS node
38
+ maxAttempts: 3,
39
+ exec: (input: InputSchema ) => {
40
+ //some logic
41
+ const output = { output: "hello" };
42
+ return output;
43
+ },
44
+ routing: () => {
45
+ if(output) return Nodes.PROCESS // Route to PROCESS node
46
+ return null; //end graph run if no output
32
47
  });
33
48
 
34
- const processNode = new GraphNode({
49
+ const processNode = new GraphNode<OutputSchema, OutputSchema, Nodes>({
35
50
  nodeType: Nodes.PROCESS,
36
51
  description: 'Process the data',
37
- exec: (input) => ({ ...input, processed: true }),
52
+ maxAttempts: 3,
53
+ exec: (input: OutputSchema) => {
54
+ //some logic
55
+ const output = {output: input.output + " world";
56
+ return output;
57
+ },
38
58
  routing: () => null, // End of graph (return null to stop)
39
59
  });
40
60
 
41
61
  // Create and run the graph
42
- const runner = new GraphRunner({
62
+ const runner = new GraphRunner<Nodes>({
43
63
  graphName: 'my-workflow',
44
64
  nodes: [startNode, processNode],
45
65
  startNode: Nodes.START,
46
- input: { data: 'hello' },
66
+ input: { input: 'hello world' },
47
67
  });
48
68
 
49
69
  const result = await runner.run();
@@ -54,9 +74,9 @@ console.log(result); // { data: 'hello', started: true, processed: true }
54
74
 
55
75
  - **Type-safe**: Full TypeScript support with generics for input/output types
56
76
  - **Async support**: Node exec functions can be sync or async
77
+ - **Advanced flexibility**: Run anything in a node execution, including another graph runs for parallel executions
57
78
  - **Automatic retry**: Built-in retry with exponential backoff
58
79
  - **Pluggable logging**: Optional execution logging with customizable backends
59
- - **Universal**: Works with Node.js, Bun, and Deno
60
80
 
61
81
  ## Logging
62
82
 
@@ -67,7 +87,7 @@ By default, graph-mode doesn't log executions. You can enable logging by providi
67
87
  ```typescript
68
88
  import { GraphRunner, ConsoleLogger } from 'graph-mode';
69
89
 
70
- const runner = new GraphRunner({
90
+ const runner = new GraphRunner<NodeEnums>({
71
91
  graphName: 'my-workflow',
72
92
  nodes: [...],
73
93
  startNode: 'START',
@@ -131,6 +151,7 @@ class MyCustomLogger implements Logger {
131
151
  new GraphNode<InputType, OutputType, NodeEnum>({
132
152
  nodeType: string, // Unique identifier for this node
133
153
  description: string, // Human-readable description
154
+ maxAttempts: number, // Max retries per node execution
134
155
  exec: (input) => output, // Execution function (sync or async)
135
156
  routing: (output) => next, // Return next node ID or null to end
136
157
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graph-mode",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "A graph-based workflow execution framework for TypeScript",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -40,7 +40,7 @@
40
40
  "license": "MIT",
41
41
  "repository": {
42
42
  "type": "git",
43
- "url": "https://github.com/jackmuva/graph-mode"
43
+ "url": "git+https://github.com/jackmuva/graph-mode.git"
44
44
  },
45
45
  "engines": {
46
46
  "node": ">=18"