@foresthubai/workflow-core 0.3.0 → 0.4.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.
Files changed (77) hide show
  1. package/LICENSE +202 -202
  2. package/NOTICE +14 -14
  3. package/README.md +63 -63
  4. package/dist/api/workflow.d.ts +2 -2
  5. package/dist/api/workflow.d.ts.map +1 -1
  6. package/package.json +1 -1
  7. package/src/api/index.ts +11 -11
  8. package/src/api/workflow.ts +607 -607
  9. package/src/channel/Channel.ts +11 -11
  10. package/src/channel/ChannelDefinition.ts +76 -76
  11. package/src/channel/index.ts +6 -6
  12. package/src/channel/serialization.ts +68 -68
  13. package/src/deploy/index.ts +1 -1
  14. package/src/deploy/requirements.test.ts +61 -61
  15. package/src/deploy/requirements.ts +41 -41
  16. package/src/diagnostics/__fixtures__/diagnosticFixtures.ts +158 -158
  17. package/src/diagnostics/diagnostics.test.ts +878 -878
  18. package/src/diagnostics/diagnostics.ts +936 -936
  19. package/src/diagnostics/index.ts +11 -11
  20. package/src/edge/Edge.ts +23 -23
  21. package/src/edge/EdgeDefinition.ts +45 -45
  22. package/src/edge/EdgeType.ts +19 -19
  23. package/src/edge/index.ts +8 -8
  24. package/src/edge/serialization.ts +83 -83
  25. package/src/expression/index.ts +4 -4
  26. package/src/expression/parser.ts +362 -362
  27. package/src/expression/types.ts +30 -30
  28. package/src/function/FunctionDeclaration.ts +54 -54
  29. package/src/function/index.ts +3 -3
  30. package/src/function/serialization.ts +40 -40
  31. package/src/globals.d.ts +9 -9
  32. package/src/id/index.ts +8 -8
  33. package/src/index.ts +22 -22
  34. package/src/memory/Memory.ts +15 -15
  35. package/src/memory/MemoryDefinition.ts +16 -16
  36. package/src/memory/MemoryFileDefinition.ts +37 -37
  37. package/src/memory/MemoryRegistry.ts +35 -35
  38. package/src/memory/VectorDatabaseDefinition.ts +21 -21
  39. package/src/memory/index.ts +8 -8
  40. package/src/memory/serialization.ts +47 -47
  41. package/src/migration/index.ts +4 -4
  42. package/src/migration/migrate.test.ts +44 -44
  43. package/src/migration/migrate.ts +58 -58
  44. package/src/migration/migrations.ts +24 -24
  45. package/src/migration/version.ts +9 -9
  46. package/src/model/LLMModelDefinition.ts +12 -12
  47. package/src/model/Model.ts +39 -39
  48. package/src/model/ModelDefinition.ts +15 -15
  49. package/src/model/ModelRegistry.ts +33 -33
  50. package/src/model/index.ts +7 -7
  51. package/src/model/serialization.ts +30 -30
  52. package/src/node/AgentNode.ts +82 -82
  53. package/src/node/DataNode.ts +41 -41
  54. package/src/node/FunctionNode.ts +76 -76
  55. package/src/node/InputNode.ts +185 -185
  56. package/src/node/LogicNode.ts +33 -33
  57. package/src/node/MqttNode.ts +127 -127
  58. package/src/node/Node.ts +61 -61
  59. package/src/node/NodeDefinition.ts +37 -37
  60. package/src/node/NodeRegistry.ts +85 -85
  61. package/src/node/OutputNode.ts +87 -87
  62. package/src/node/ToolNode.ts +32 -32
  63. package/src/node/TriggerNode.ts +272 -272
  64. package/src/node/constants.ts +16 -16
  65. package/src/node/index.ts +26 -26
  66. package/src/node/methods.ts +278 -278
  67. package/src/node/serialization.ts +544 -544
  68. package/src/parameter/OutputParameter.ts +68 -68
  69. package/src/parameter/Parameter.ts +243 -243
  70. package/src/parameter/index.ts +33 -33
  71. package/src/variable/Variable.ts +10 -10
  72. package/src/variable/index.ts +16 -16
  73. package/src/variable/operations.ts +106 -106
  74. package/src/workflow/Workflow.ts +41 -41
  75. package/src/workflow/index.ts +3 -3
  76. package/src/workflow/serialization.test.ts +240 -240
  77. package/src/workflow/serialization.ts +242 -242
@@ -1,158 +1,158 @@
1
- import type { Edge } from "../../edge";
2
- import type { NodeDefinition, NodeData } from "../../node";
3
- import type { DataType, Expression, Reference } from "../../api";
4
- import type { Channel } from "../../channel";
5
- import type { Memory } from "../../memory";
6
- import { NodeCategory } from "../../node";
7
- import type { Variable, DeclaredVariable, NodeOutputVariable } from "../../variable";
8
- import type { Diagnostic, DiagnosticCategory } from "../diagnostics";
9
-
10
- // ============================================================================
11
- // Variable builders
12
- // ============================================================================
13
-
14
- export function makeDeclaredVar(overrides: Partial<DeclaredVariable> = {}): Variable {
15
- return {
16
- kind: "declared",
17
- uid: "v1",
18
- name: "count",
19
- dataType: "int" as DataType,
20
- ...overrides,
21
- };
22
- }
23
-
24
- export function makeNodeOutputVar(overrides: Partial<NodeOutputVariable> = {}): Variable {
25
- return {
26
- kind: "node",
27
- nodeId: "n1",
28
- outputId: "output",
29
- name: "result",
30
- dataType: "int" as DataType,
31
- ...overrides,
32
- };
33
- }
34
-
35
- /** Build an `availableVariables` map from a list of `AvailableVariable` entries. */
36
- export function makeAvailableVars(vars: Variable[]): Record<string, Variable> {
37
- const map: Record<string, Variable> = {};
38
- for (const v of vars) {
39
- const key = v.kind === "declared" ? `declared:${v.uid}` : v.kind === "fnarg" ? `fnarg:${v.uid}` : `${v.nodeId}:${v.outputId}`;
40
- map[key] = v;
41
- }
42
- return map;
43
- }
44
-
45
- // ============================================================================
46
- // Expression / Reference builders
47
- // ============================================================================
48
-
49
- export function makeExpression(expression: string, dataType: DataType = "int", references: Reference[] = []): Expression {
50
- return { expression, references, dataType };
51
- }
52
-
53
- export function makeDeclaredRef(uid: string): Reference {
54
- return { srcId: "declared", varId: uid };
55
- }
56
-
57
- // ============================================================================
58
- // Edge builder
59
- // ============================================================================
60
-
61
- export function makeEdge(
62
- id: string,
63
- source: string,
64
- sourceHandle: string,
65
- target: string,
66
- targetHandle: string,
67
- overrides: Partial<Edge> = {},
68
- ): Edge {
69
- return {
70
- id,
71
- source,
72
- sourceHandle,
73
- target,
74
- targetHandle,
75
- type: "control",
76
- ...overrides,
77
- };
78
- }
79
-
80
- // ============================================================================
81
- // Channel builders
82
- // ============================================================================
83
-
84
- export function makeChannel(overrides: Partial<Channel> = {}): Channel {
85
- return {
86
- id: "ch1",
87
- label: "GPIO 4",
88
- type: "GPIOIN",
89
- arguments: {},
90
- ...overrides,
91
- };
92
- }
93
-
94
- export function makeChannels(channels: Channel[]): Record<string, Channel> {
95
- const map: Record<string, Channel> = {};
96
- for (const v of channels) map[v.id] = v;
97
- return map;
98
- }
99
-
100
- // ============================================================================
101
- // Memory builders
102
- // ============================================================================
103
-
104
- export function makeMemory(overrides: Partial<Memory> = {}): Memory {
105
- return {
106
- id: "mem1",
107
- label: "memory1",
108
- type: "MemoryFile",
109
- arguments: {},
110
- ...overrides,
111
- };
112
- }
113
-
114
- export function makeMemories(memories: Memory[]): Record<string, Memory> {
115
- const map: Record<string, Memory> = {};
116
- for (const m of memories) map[m.id] = m;
117
- return map;
118
- }
119
-
120
- // ============================================================================
121
- // Node instance builder — untyped escape hatch
122
- // ============================================================================
123
-
124
- /**
125
- * Build a minimal NodeData. Tests assert against the shape `computeNodeDiagnostics`
126
- * sees (arguments record + type discriminator), not against the strict per-type shapes,
127
- * so we widen to `NodeData` via unknown at the boundary.
128
- */
129
- export function makeNode(type: string, args: Record<string, unknown>, overrides: Record<string, unknown> = {}): NodeData {
130
- return { id: "n1", type, arguments: args, ...overrides } as unknown as NodeData;
131
- }
132
-
133
- // ============================================================================
134
- // Synthetic NodeDefinition builder
135
- // ============================================================================
136
-
137
- export function makeNodeDef(overrides: Partial<NodeDefinition> = {}): NodeDefinition {
138
- return {
139
- type: "Synthetic" as NodeDefinition["type"],
140
- label: "Synthetic Node",
141
- category: NodeCategory.Input,
142
- description: "Synthetic node used only in tests",
143
- parameters: [],
144
- ...overrides,
145
- };
146
- }
147
-
148
- // ============================================================================
149
- // Diagnostic assertion helpers
150
- // ============================================================================
151
-
152
- export function diagsOfCategory(diags: Diagnostic[], category: DiagnosticCategory): Diagnostic[] {
153
- return diags.filter((d) => d.category === category);
154
- }
155
-
156
- export function hasDiag(diags: Diagnostic[], predicate: (d: Diagnostic) => boolean): boolean {
157
- return diags.some(predicate);
158
- }
1
+ import type { Edge } from "../../edge";
2
+ import type { NodeDefinition, NodeData } from "../../node";
3
+ import type { DataType, Expression, Reference } from "../../api";
4
+ import type { Channel } from "../../channel";
5
+ import type { Memory } from "../../memory";
6
+ import { NodeCategory } from "../../node";
7
+ import type { Variable, DeclaredVariable, NodeOutputVariable } from "../../variable";
8
+ import type { Diagnostic, DiagnosticCategory } from "../diagnostics";
9
+
10
+ // ============================================================================
11
+ // Variable builders
12
+ // ============================================================================
13
+
14
+ export function makeDeclaredVar(overrides: Partial<DeclaredVariable> = {}): Variable {
15
+ return {
16
+ kind: "declared",
17
+ uid: "v1",
18
+ name: "count",
19
+ dataType: "int" as DataType,
20
+ ...overrides,
21
+ };
22
+ }
23
+
24
+ export function makeNodeOutputVar(overrides: Partial<NodeOutputVariable> = {}): Variable {
25
+ return {
26
+ kind: "node",
27
+ nodeId: "n1",
28
+ outputId: "output",
29
+ name: "result",
30
+ dataType: "int" as DataType,
31
+ ...overrides,
32
+ };
33
+ }
34
+
35
+ /** Build an `availableVariables` map from a list of `AvailableVariable` entries. */
36
+ export function makeAvailableVars(vars: Variable[]): Record<string, Variable> {
37
+ const map: Record<string, Variable> = {};
38
+ for (const v of vars) {
39
+ const key = v.kind === "declared" ? `declared:${v.uid}` : v.kind === "fnarg" ? `fnarg:${v.uid}` : `${v.nodeId}:${v.outputId}`;
40
+ map[key] = v;
41
+ }
42
+ return map;
43
+ }
44
+
45
+ // ============================================================================
46
+ // Expression / Reference builders
47
+ // ============================================================================
48
+
49
+ export function makeExpression(expression: string, dataType: DataType = "int", references: Reference[] = []): Expression {
50
+ return { expression, references, dataType };
51
+ }
52
+
53
+ export function makeDeclaredRef(uid: string): Reference {
54
+ return { srcId: "declared", varId: uid };
55
+ }
56
+
57
+ // ============================================================================
58
+ // Edge builder
59
+ // ============================================================================
60
+
61
+ export function makeEdge(
62
+ id: string,
63
+ source: string,
64
+ sourceHandle: string,
65
+ target: string,
66
+ targetHandle: string,
67
+ overrides: Partial<Edge> = {},
68
+ ): Edge {
69
+ return {
70
+ id,
71
+ source,
72
+ sourceHandle,
73
+ target,
74
+ targetHandle,
75
+ type: "control",
76
+ ...overrides,
77
+ };
78
+ }
79
+
80
+ // ============================================================================
81
+ // Channel builders
82
+ // ============================================================================
83
+
84
+ export function makeChannel(overrides: Partial<Channel> = {}): Channel {
85
+ return {
86
+ id: "ch1",
87
+ label: "GPIO 4",
88
+ type: "GPIOIN",
89
+ arguments: {},
90
+ ...overrides,
91
+ };
92
+ }
93
+
94
+ export function makeChannels(channels: Channel[]): Record<string, Channel> {
95
+ const map: Record<string, Channel> = {};
96
+ for (const v of channels) map[v.id] = v;
97
+ return map;
98
+ }
99
+
100
+ // ============================================================================
101
+ // Memory builders
102
+ // ============================================================================
103
+
104
+ export function makeMemory(overrides: Partial<Memory> = {}): Memory {
105
+ return {
106
+ id: "mem1",
107
+ label: "memory1",
108
+ type: "MemoryFile",
109
+ arguments: {},
110
+ ...overrides,
111
+ };
112
+ }
113
+
114
+ export function makeMemories(memories: Memory[]): Record<string, Memory> {
115
+ const map: Record<string, Memory> = {};
116
+ for (const m of memories) map[m.id] = m;
117
+ return map;
118
+ }
119
+
120
+ // ============================================================================
121
+ // Node instance builder — untyped escape hatch
122
+ // ============================================================================
123
+
124
+ /**
125
+ * Build a minimal NodeData. Tests assert against the shape `computeNodeDiagnostics`
126
+ * sees (arguments record + type discriminator), not against the strict per-type shapes,
127
+ * so we widen to `NodeData` via unknown at the boundary.
128
+ */
129
+ export function makeNode(type: string, args: Record<string, unknown>, overrides: Record<string, unknown> = {}): NodeData {
130
+ return { id: "n1", type, arguments: args, ...overrides } as unknown as NodeData;
131
+ }
132
+
133
+ // ============================================================================
134
+ // Synthetic NodeDefinition builder
135
+ // ============================================================================
136
+
137
+ export function makeNodeDef(overrides: Partial<NodeDefinition> = {}): NodeDefinition {
138
+ return {
139
+ type: "Synthetic" as NodeDefinition["type"],
140
+ label: "Synthetic Node",
141
+ category: NodeCategory.Input,
142
+ description: "Synthetic node used only in tests",
143
+ parameters: [],
144
+ ...overrides,
145
+ };
146
+ }
147
+
148
+ // ============================================================================
149
+ // Diagnostic assertion helpers
150
+ // ============================================================================
151
+
152
+ export function diagsOfCategory(diags: Diagnostic[], category: DiagnosticCategory): Diagnostic[] {
153
+ return diags.filter((d) => d.category === category);
154
+ }
155
+
156
+ export function hasDiag(diags: Diagnostic[], predicate: (d: Diagnostic) => boolean): boolean {
157
+ return diags.some(predicate);
158
+ }