@fbp/evaluator 1.0.0 → 1.1.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/definitions/core.js +10 -10
- package/definitions/math.js +3 -3
- package/definitions/net.js +2 -2
- package/definitions/ui.js +13 -13
- package/esm/definitions/core.js +10 -10
- package/esm/definitions/math.js +3 -3
- package/esm/definitions/net.js +2 -2
- package/esm/definitions/ui.js +13 -13
- package/esm/evaluate.js +38 -18
- package/evaluate.js +38 -18
- package/package.json +3 -3
package/definitions/core.js
CHANGED
|
@@ -18,9 +18,9 @@ exports.coreDefinitions = exports.stringConcatDef = exports.stringTemplateDef =
|
|
|
18
18
|
* - value: any (the extracted value)
|
|
19
19
|
*/
|
|
20
20
|
exports.jsonSelectDef = {
|
|
21
|
-
context: '
|
|
21
|
+
context: 'js',
|
|
22
|
+
name: 'select',
|
|
22
23
|
category: 'json',
|
|
23
|
-
type: 'core/json/select',
|
|
24
24
|
icon: 'circle',
|
|
25
25
|
inputs: [
|
|
26
26
|
{ name: 'obj', type: 'json' }
|
|
@@ -72,9 +72,9 @@ exports.jsonSelectDef = {
|
|
|
72
72
|
* - value: json (the constructed object)
|
|
73
73
|
*/
|
|
74
74
|
exports.jsonObjectDef = {
|
|
75
|
-
context: '
|
|
75
|
+
context: 'js',
|
|
76
|
+
name: 'object',
|
|
76
77
|
category: 'json',
|
|
77
|
-
type: 'core/json/object',
|
|
78
78
|
icon: 'braces',
|
|
79
79
|
inputs: [], // Dynamic inputs - any input name is valid
|
|
80
80
|
outputs: [
|
|
@@ -100,9 +100,9 @@ exports.jsonObjectDef = {
|
|
|
100
100
|
* - error: json (the error if failed)
|
|
101
101
|
*/
|
|
102
102
|
exports.flowGuardDef = {
|
|
103
|
-
context: '
|
|
103
|
+
context: 'js',
|
|
104
|
+
name: 'guard',
|
|
104
105
|
category: 'flow',
|
|
105
|
-
type: 'core/flow/guard',
|
|
106
106
|
icon: 'zap',
|
|
107
107
|
inputs: [
|
|
108
108
|
{ name: 'ok', type: 'boolean' },
|
|
@@ -146,9 +146,9 @@ exports.flowGuardDef = {
|
|
|
146
146
|
* - value: string (the resulting string)
|
|
147
147
|
*/
|
|
148
148
|
exports.stringTemplateDef = {
|
|
149
|
-
context: '
|
|
149
|
+
context: 'js',
|
|
150
|
+
name: 'template',
|
|
150
151
|
category: 'string',
|
|
151
|
-
type: 'core/string/template',
|
|
152
152
|
icon: 'quote',
|
|
153
153
|
inputs: [], // Dynamic inputs based on template placeholders
|
|
154
154
|
outputs: [
|
|
@@ -188,9 +188,9 @@ exports.stringTemplateDef = {
|
|
|
188
188
|
* - value: string (the resulting string)
|
|
189
189
|
*/
|
|
190
190
|
exports.stringConcatDef = {
|
|
191
|
-
context: '
|
|
191
|
+
context: 'js',
|
|
192
|
+
name: 'concat',
|
|
192
193
|
category: 'string',
|
|
193
|
-
type: 'core/string/concat',
|
|
194
194
|
icon: 'link',
|
|
195
195
|
inputs: [
|
|
196
196
|
{ name: 'value', type: 'string' }
|
package/definitions/math.js
CHANGED
|
@@ -6,8 +6,8 @@ exports.mathDefinitions = exports.multiplyDef = exports.addDef = exports.constNu
|
|
|
6
6
|
*/
|
|
7
7
|
exports.constNumberDef = {
|
|
8
8
|
context: 'js',
|
|
9
|
+
name: 'number',
|
|
9
10
|
category: 'const',
|
|
10
|
-
type: 'js/const/number',
|
|
11
11
|
icon: 'hash',
|
|
12
12
|
outputs: [{ name: 'value', type: 'number' }],
|
|
13
13
|
props: [{ name: 'value', type: 'number', default: 0 }],
|
|
@@ -18,8 +18,8 @@ exports.constNumberDef = {
|
|
|
18
18
|
};
|
|
19
19
|
exports.addDef = {
|
|
20
20
|
context: 'js',
|
|
21
|
+
name: 'add',
|
|
21
22
|
category: 'math',
|
|
22
|
-
type: 'js/math/add',
|
|
23
23
|
icon: 'plus',
|
|
24
24
|
inputs: [
|
|
25
25
|
{ name: 'a', type: 'number' },
|
|
@@ -33,8 +33,8 @@ exports.addDef = {
|
|
|
33
33
|
};
|
|
34
34
|
exports.multiplyDef = {
|
|
35
35
|
context: 'js',
|
|
36
|
+
name: 'multiply',
|
|
36
37
|
category: 'math',
|
|
37
|
-
type: 'js/math/multiply',
|
|
38
38
|
icon: 'x',
|
|
39
39
|
inputs: [
|
|
40
40
|
{ name: 'a', type: 'number' },
|
package/definitions/net.js
CHANGED
|
@@ -24,9 +24,9 @@ exports.netDefinitions = exports.graphqlRequestDef = void 0;
|
|
|
24
24
|
* - ok: boolean (true if request succeeded without errors)
|
|
25
25
|
*/
|
|
26
26
|
exports.graphqlRequestDef = {
|
|
27
|
-
context: '
|
|
27
|
+
context: 'js',
|
|
28
|
+
name: 'request',
|
|
28
29
|
category: 'graphql',
|
|
29
|
-
type: 'net/graphql/request',
|
|
30
30
|
icon: 'graphql',
|
|
31
31
|
inputs: [
|
|
32
32
|
{ name: 'variables', type: 'json' },
|
package/definitions/ui.js
CHANGED
|
@@ -25,8 +25,8 @@ function coerceValue(value, valueType) {
|
|
|
25
25
|
// Boundary node definitions for graph inputs/outputs
|
|
26
26
|
exports.graphInputDef = {
|
|
27
27
|
context: 'core',
|
|
28
|
+
name: 'graphInput',
|
|
28
29
|
category: 'graph',
|
|
29
|
-
type: 'core/graph/input',
|
|
30
30
|
icon: 'arrow-right',
|
|
31
31
|
inputs: [],
|
|
32
32
|
outputs: [{ name: 'value', type: 'any' }],
|
|
@@ -39,8 +39,8 @@ exports.graphInputDef = {
|
|
|
39
39
|
};
|
|
40
40
|
exports.graphOutputDef = {
|
|
41
41
|
context: 'core',
|
|
42
|
+
name: 'graphOutput',
|
|
42
43
|
category: 'graph',
|
|
43
|
-
type: 'core/graph/output',
|
|
44
44
|
icon: 'arrow-left',
|
|
45
45
|
inputs: [{ name: 'value', type: 'any' }],
|
|
46
46
|
outputs: [],
|
|
@@ -52,8 +52,8 @@ exports.graphOutputDef = {
|
|
|
52
52
|
};
|
|
53
53
|
exports.graphPropDef = {
|
|
54
54
|
context: 'core',
|
|
55
|
+
name: 'graphProp',
|
|
55
56
|
category: 'graph',
|
|
56
|
-
type: 'core/graph/prop',
|
|
57
57
|
icon: 'settings',
|
|
58
58
|
inputs: [],
|
|
59
59
|
outputs: [{ name: 'value', type: 'any' }],
|
|
@@ -65,9 +65,9 @@ exports.graphPropDef = {
|
|
|
65
65
|
impl: (_inputs, props) => ({ value: coerceValue(props?.value ?? props?.default, props?.valueType ?? 'any') })
|
|
66
66
|
};
|
|
67
67
|
exports.pageDef = {
|
|
68
|
-
context: '
|
|
68
|
+
context: 'js',
|
|
69
|
+
name: 'Page',
|
|
69
70
|
category: 'layout',
|
|
70
|
-
type: 'ui/layout/Page',
|
|
71
71
|
icon: 'file',
|
|
72
72
|
inputs: [
|
|
73
73
|
{ name: 'children', type: 'Element[]', multi: true }
|
|
@@ -88,9 +88,9 @@ exports.pageDef = {
|
|
|
88
88
|
})
|
|
89
89
|
};
|
|
90
90
|
exports.formDef = {
|
|
91
|
-
context: '
|
|
91
|
+
context: 'js',
|
|
92
|
+
name: 'Form',
|
|
92
93
|
category: 'form',
|
|
93
|
-
type: 'ui/form/Form',
|
|
94
94
|
icon: 'file-text',
|
|
95
95
|
inputs: [
|
|
96
96
|
{ name: 'children', type: 'Element[]', multi: true }
|
|
@@ -111,9 +111,9 @@ exports.formDef = {
|
|
|
111
111
|
})
|
|
112
112
|
};
|
|
113
113
|
exports.inputDef = {
|
|
114
|
-
context: '
|
|
114
|
+
context: 'js',
|
|
115
|
+
name: 'Input',
|
|
115
116
|
category: 'form',
|
|
116
|
-
type: 'ui/form/Input',
|
|
117
117
|
icon: 'text-cursor',
|
|
118
118
|
inputs: [],
|
|
119
119
|
outputs: [{ name: 'element', type: 'Element' }],
|
|
@@ -137,9 +137,9 @@ exports.inputDef = {
|
|
|
137
137
|
})
|
|
138
138
|
};
|
|
139
139
|
exports.buttonDef = {
|
|
140
|
-
context: '
|
|
140
|
+
context: 'js',
|
|
141
|
+
name: 'Button',
|
|
141
142
|
category: 'form',
|
|
142
|
-
type: 'ui/form/Button',
|
|
143
143
|
icon: 'square',
|
|
144
144
|
inputs: [],
|
|
145
145
|
outputs: [{ name: 'element', type: 'Element' }],
|
|
@@ -161,9 +161,9 @@ exports.buttonDef = {
|
|
|
161
161
|
})
|
|
162
162
|
};
|
|
163
163
|
exports.textDef = {
|
|
164
|
-
context: '
|
|
164
|
+
context: 'js',
|
|
165
|
+
name: 'Text',
|
|
165
166
|
category: 'content',
|
|
166
|
-
type: 'ui/content/Text',
|
|
167
167
|
icon: 'type',
|
|
168
168
|
inputs: [],
|
|
169
169
|
outputs: [{ name: 'element', type: 'Element' }],
|
package/esm/definitions/core.js
CHANGED
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
* - value: any (the extracted value)
|
|
16
16
|
*/
|
|
17
17
|
export const jsonSelectDef = {
|
|
18
|
-
context: '
|
|
18
|
+
context: 'js',
|
|
19
|
+
name: 'select',
|
|
19
20
|
category: 'json',
|
|
20
|
-
type: 'core/json/select',
|
|
21
21
|
icon: 'circle',
|
|
22
22
|
inputs: [
|
|
23
23
|
{ name: 'obj', type: 'json' }
|
|
@@ -69,9 +69,9 @@ export const jsonSelectDef = {
|
|
|
69
69
|
* - value: json (the constructed object)
|
|
70
70
|
*/
|
|
71
71
|
export const jsonObjectDef = {
|
|
72
|
-
context: '
|
|
72
|
+
context: 'js',
|
|
73
|
+
name: 'object',
|
|
73
74
|
category: 'json',
|
|
74
|
-
type: 'core/json/object',
|
|
75
75
|
icon: 'braces',
|
|
76
76
|
inputs: [], // Dynamic inputs - any input name is valid
|
|
77
77
|
outputs: [
|
|
@@ -97,9 +97,9 @@ export const jsonObjectDef = {
|
|
|
97
97
|
* - error: json (the error if failed)
|
|
98
98
|
*/
|
|
99
99
|
export const flowGuardDef = {
|
|
100
|
-
context: '
|
|
100
|
+
context: 'js',
|
|
101
|
+
name: 'guard',
|
|
101
102
|
category: 'flow',
|
|
102
|
-
type: 'core/flow/guard',
|
|
103
103
|
icon: 'zap',
|
|
104
104
|
inputs: [
|
|
105
105
|
{ name: 'ok', type: 'boolean' },
|
|
@@ -143,9 +143,9 @@ export const flowGuardDef = {
|
|
|
143
143
|
* - value: string (the resulting string)
|
|
144
144
|
*/
|
|
145
145
|
export const stringTemplateDef = {
|
|
146
|
-
context: '
|
|
146
|
+
context: 'js',
|
|
147
|
+
name: 'template',
|
|
147
148
|
category: 'string',
|
|
148
|
-
type: 'core/string/template',
|
|
149
149
|
icon: 'quote',
|
|
150
150
|
inputs: [], // Dynamic inputs based on template placeholders
|
|
151
151
|
outputs: [
|
|
@@ -185,9 +185,9 @@ export const stringTemplateDef = {
|
|
|
185
185
|
* - value: string (the resulting string)
|
|
186
186
|
*/
|
|
187
187
|
export const stringConcatDef = {
|
|
188
|
-
context: '
|
|
188
|
+
context: 'js',
|
|
189
|
+
name: 'concat',
|
|
189
190
|
category: 'string',
|
|
190
|
-
type: 'core/string/concat',
|
|
191
191
|
icon: 'link',
|
|
192
192
|
inputs: [
|
|
193
193
|
{ name: 'value', type: 'string' }
|
package/esm/definitions/math.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const constNumberDef = {
|
|
5
5
|
context: 'js',
|
|
6
|
+
name: 'number',
|
|
6
7
|
category: 'const',
|
|
7
|
-
type: 'js/const/number',
|
|
8
8
|
icon: 'hash',
|
|
9
9
|
outputs: [{ name: 'value', type: 'number' }],
|
|
10
10
|
props: [{ name: 'value', type: 'number', default: 0 }],
|
|
@@ -15,8 +15,8 @@ export const constNumberDef = {
|
|
|
15
15
|
};
|
|
16
16
|
export const addDef = {
|
|
17
17
|
context: 'js',
|
|
18
|
+
name: 'add',
|
|
18
19
|
category: 'math',
|
|
19
|
-
type: 'js/math/add',
|
|
20
20
|
icon: 'plus',
|
|
21
21
|
inputs: [
|
|
22
22
|
{ name: 'a', type: 'number' },
|
|
@@ -30,8 +30,8 @@ export const addDef = {
|
|
|
30
30
|
};
|
|
31
31
|
export const multiplyDef = {
|
|
32
32
|
context: 'js',
|
|
33
|
+
name: 'multiply',
|
|
33
34
|
category: 'math',
|
|
34
|
-
type: 'js/math/multiply',
|
|
35
35
|
icon: 'x',
|
|
36
36
|
inputs: [
|
|
37
37
|
{ name: 'a', type: 'number' },
|
package/esm/definitions/net.js
CHANGED
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
* - ok: boolean (true if request succeeded without errors)
|
|
22
22
|
*/
|
|
23
23
|
export const graphqlRequestDef = {
|
|
24
|
-
context: '
|
|
24
|
+
context: 'js',
|
|
25
|
+
name: 'request',
|
|
25
26
|
category: 'graphql',
|
|
26
|
-
type: 'net/graphql/request',
|
|
27
27
|
icon: 'graphql',
|
|
28
28
|
inputs: [
|
|
29
29
|
{ name: 'variables', type: 'json' },
|
package/esm/definitions/ui.js
CHANGED
|
@@ -22,8 +22,8 @@ function coerceValue(value, valueType) {
|
|
|
22
22
|
// Boundary node definitions for graph inputs/outputs
|
|
23
23
|
export const graphInputDef = {
|
|
24
24
|
context: 'core',
|
|
25
|
+
name: 'graphInput',
|
|
25
26
|
category: 'graph',
|
|
26
|
-
type: 'core/graph/input',
|
|
27
27
|
icon: 'arrow-right',
|
|
28
28
|
inputs: [],
|
|
29
29
|
outputs: [{ name: 'value', type: 'any' }],
|
|
@@ -36,8 +36,8 @@ export const graphInputDef = {
|
|
|
36
36
|
};
|
|
37
37
|
export const graphOutputDef = {
|
|
38
38
|
context: 'core',
|
|
39
|
+
name: 'graphOutput',
|
|
39
40
|
category: 'graph',
|
|
40
|
-
type: 'core/graph/output',
|
|
41
41
|
icon: 'arrow-left',
|
|
42
42
|
inputs: [{ name: 'value', type: 'any' }],
|
|
43
43
|
outputs: [],
|
|
@@ -49,8 +49,8 @@ export const graphOutputDef = {
|
|
|
49
49
|
};
|
|
50
50
|
export const graphPropDef = {
|
|
51
51
|
context: 'core',
|
|
52
|
+
name: 'graphProp',
|
|
52
53
|
category: 'graph',
|
|
53
|
-
type: 'core/graph/prop',
|
|
54
54
|
icon: 'settings',
|
|
55
55
|
inputs: [],
|
|
56
56
|
outputs: [{ name: 'value', type: 'any' }],
|
|
@@ -62,9 +62,9 @@ export const graphPropDef = {
|
|
|
62
62
|
impl: (_inputs, props) => ({ value: coerceValue(props?.value ?? props?.default, props?.valueType ?? 'any') })
|
|
63
63
|
};
|
|
64
64
|
export const pageDef = {
|
|
65
|
-
context: '
|
|
65
|
+
context: 'js',
|
|
66
|
+
name: 'Page',
|
|
66
67
|
category: 'layout',
|
|
67
|
-
type: 'ui/layout/Page',
|
|
68
68
|
icon: 'file',
|
|
69
69
|
inputs: [
|
|
70
70
|
{ name: 'children', type: 'Element[]', multi: true }
|
|
@@ -85,9 +85,9 @@ export const pageDef = {
|
|
|
85
85
|
})
|
|
86
86
|
};
|
|
87
87
|
export const formDef = {
|
|
88
|
-
context: '
|
|
88
|
+
context: 'js',
|
|
89
|
+
name: 'Form',
|
|
89
90
|
category: 'form',
|
|
90
|
-
type: 'ui/form/Form',
|
|
91
91
|
icon: 'file-text',
|
|
92
92
|
inputs: [
|
|
93
93
|
{ name: 'children', type: 'Element[]', multi: true }
|
|
@@ -108,9 +108,9 @@ export const formDef = {
|
|
|
108
108
|
})
|
|
109
109
|
};
|
|
110
110
|
export const inputDef = {
|
|
111
|
-
context: '
|
|
111
|
+
context: 'js',
|
|
112
|
+
name: 'Input',
|
|
112
113
|
category: 'form',
|
|
113
|
-
type: 'ui/form/Input',
|
|
114
114
|
icon: 'text-cursor',
|
|
115
115
|
inputs: [],
|
|
116
116
|
outputs: [{ name: 'element', type: 'Element' }],
|
|
@@ -134,9 +134,9 @@ export const inputDef = {
|
|
|
134
134
|
})
|
|
135
135
|
};
|
|
136
136
|
export const buttonDef = {
|
|
137
|
-
context: '
|
|
137
|
+
context: 'js',
|
|
138
|
+
name: 'Button',
|
|
138
139
|
category: 'form',
|
|
139
|
-
type: 'ui/form/Button',
|
|
140
140
|
icon: 'square',
|
|
141
141
|
inputs: [],
|
|
142
142
|
outputs: [{ name: 'element', type: 'Element' }],
|
|
@@ -158,9 +158,9 @@ export const buttonDef = {
|
|
|
158
158
|
})
|
|
159
159
|
};
|
|
160
160
|
export const textDef = {
|
|
161
|
-
context: '
|
|
161
|
+
context: 'js',
|
|
162
|
+
name: 'Text',
|
|
162
163
|
category: 'content',
|
|
163
|
-
type: 'ui/content/Text',
|
|
164
164
|
icon: 'type',
|
|
165
165
|
inputs: [],
|
|
166
166
|
outputs: [{ name: 'element', type: 'Element' }],
|
package/esm/evaluate.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build a definition map key from context and name.
|
|
3
|
+
*/
|
|
4
|
+
function defKey(context, name) {
|
|
5
|
+
return `${context}:${name}`;
|
|
6
|
+
}
|
|
1
7
|
/**
|
|
2
8
|
* Evaluate a graph starting from the specified output node/port.
|
|
3
9
|
* Uses lazy evaluation - only evaluates nodes that are needed for the output.
|
|
@@ -16,8 +22,10 @@ export async function evaluate(graph, options) {
|
|
|
16
22
|
}
|
|
17
23
|
const defMap = new Map();
|
|
18
24
|
for (const def of definitions) {
|
|
19
|
-
defMap.set(def.
|
|
25
|
+
defMap.set(defKey(def.context, def.name), def);
|
|
20
26
|
}
|
|
27
|
+
// Graph-level context used as default for node lookups
|
|
28
|
+
const graphContext = graph.context || '';
|
|
21
29
|
// Build edge lookup: destination node -> destination port -> edges (in array order)
|
|
22
30
|
const edgesByDst = new Map();
|
|
23
31
|
for (const edge of graph.edges) {
|
|
@@ -47,8 +55,8 @@ export async function evaluate(graph, options) {
|
|
|
47
55
|
if (!node) {
|
|
48
56
|
throw new Error(`Node not found: ${nodeName}`);
|
|
49
57
|
}
|
|
50
|
-
// Handle
|
|
51
|
-
//
|
|
58
|
+
// Handle system nodes (graphInput, graphOutput, graphProp)
|
|
59
|
+
// System nodes are identified by their type name — reserved, no definition lookup needed
|
|
52
60
|
if (node.type === 'graphInput') {
|
|
53
61
|
// Get the port name from the portName property
|
|
54
62
|
const portNameProp = node.props?.find(p => p.name === 'portName');
|
|
@@ -86,8 +94,8 @@ export async function evaluate(graph, options) {
|
|
|
86
94
|
cache.set(nodeName, result);
|
|
87
95
|
return result;
|
|
88
96
|
}
|
|
89
|
-
// Handle subnet nodes (
|
|
90
|
-
if (node.
|
|
97
|
+
// Handle subnet nodes (type: 'subnet' with inline nodes/edges)
|
|
98
|
+
if (node.type === 'subnet' && node.nodes && node.edges) {
|
|
91
99
|
// Collect inputs for the subnet by evaluating upstream nodes
|
|
92
100
|
const subnetInputs = {};
|
|
93
101
|
const subnetPortEdges = edgesByDst.get(nodeName);
|
|
@@ -118,6 +126,7 @@ export async function evaluate(graph, options) {
|
|
|
118
126
|
// Recursively evaluate the subnet's internal graph
|
|
119
127
|
const subnetResult = await evaluate({
|
|
120
128
|
name: `${nodeName}_subnet`,
|
|
129
|
+
context: graphContext || undefined,
|
|
121
130
|
nodes: node.nodes,
|
|
122
131
|
edges: node.edges
|
|
123
132
|
}, {
|
|
@@ -132,13 +141,11 @@ export async function evaluate(graph, options) {
|
|
|
132
141
|
cache.set(nodeName, subnetOutputs);
|
|
133
142
|
return subnetOutputs;
|
|
134
143
|
}
|
|
135
|
-
// Get the definition for this node
|
|
136
|
-
const
|
|
144
|
+
// Get the definition for this node — resolve context from node override or graph default
|
|
145
|
+
const nodeContext = node.context || graphContext;
|
|
146
|
+
const definition = defMap.get(defKey(nodeContext, node.type));
|
|
137
147
|
if (!definition) {
|
|
138
|
-
throw new Error(`No definition found for node
|
|
139
|
-
}
|
|
140
|
-
if (!definition.impl) {
|
|
141
|
-
throw new Error(`No implementation found for node type: ${node.type}`);
|
|
148
|
+
throw new Error(`No definition found for node: ${nodeContext}:${node.type}`);
|
|
142
149
|
}
|
|
143
150
|
// Collect inputs by evaluating upstream nodes
|
|
144
151
|
const nodeInputs = {};
|
|
@@ -147,7 +154,6 @@ export async function evaluate(graph, options) {
|
|
|
147
154
|
for (const inputPort of definition.inputs) {
|
|
148
155
|
const edges = portEdges?.get(inputPort.name) ?? [];
|
|
149
156
|
if (inputPort.multi) {
|
|
150
|
-
// Multi-input port: collect all values in edge array order
|
|
151
157
|
const values = await Promise.all(edges.map(async (edge) => {
|
|
152
158
|
const upstreamOutputs = await evaluateNode(edge.src.node);
|
|
153
159
|
return upstreamOutputs[edge.src.port];
|
|
@@ -155,7 +161,6 @@ export async function evaluate(graph, options) {
|
|
|
155
161
|
nodeInputs[inputPort.name] = values;
|
|
156
162
|
}
|
|
157
163
|
else {
|
|
158
|
-
// Single input: take first edge if exists
|
|
159
164
|
if (edges.length > 0) {
|
|
160
165
|
const edge = edges[0];
|
|
161
166
|
const upstreamOutputs = await evaluateNode(edge.src.node);
|
|
@@ -164,24 +169,39 @@ export async function evaluate(graph, options) {
|
|
|
164
169
|
}
|
|
165
170
|
}
|
|
166
171
|
}
|
|
167
|
-
// Get props from node instance
|
|
172
|
+
// Get props from node instance (override definition defaults)
|
|
168
173
|
const nodeProps = {};
|
|
169
174
|
if (definition.props) {
|
|
170
175
|
for (const propDef of definition.props) {
|
|
171
|
-
// First check node instance props
|
|
172
176
|
const instanceProp = node.props?.find(p => p.name === propDef.name);
|
|
173
177
|
if (instanceProp !== undefined && instanceProp.value !== undefined) {
|
|
174
178
|
nodeProps[propDef.name] = instanceProp.value;
|
|
175
179
|
}
|
|
176
180
|
else if (propDef.default !== undefined) {
|
|
177
|
-
// Fall back to definition default
|
|
178
181
|
nodeProps[propDef.name] = propDef.default;
|
|
179
182
|
}
|
|
180
183
|
}
|
|
181
184
|
}
|
|
182
|
-
//
|
|
185
|
+
// Digital asset: definition has an internal graph — evaluate it recursively
|
|
186
|
+
if (definition.graph) {
|
|
187
|
+
const assetGraph = definition.graph;
|
|
188
|
+
// Find all output boundary nodes in the asset's graph
|
|
189
|
+
const assetOutputs = {};
|
|
190
|
+
const outputBoundaryNodes = assetGraph.nodes.filter(n => n.type === 'graphOutput');
|
|
191
|
+
for (const outputBoundaryNode of outputBoundaryNodes) {
|
|
192
|
+
const portNameProp = outputBoundaryNode.props?.find(p => p.name === 'portName');
|
|
193
|
+
const portName = portNameProp?.value || outputBoundaryNode.name;
|
|
194
|
+
const result = await evaluate({ name: `${nodeName}_asset`, context: assetGraph.context, nodes: assetGraph.nodes, edges: assetGraph.edges }, { definitions, outputNode: outputBoundaryNode.name, outputPort: 'value', inputs: nodeInputs, props: nodeProps });
|
|
195
|
+
assetOutputs[portName] = result;
|
|
196
|
+
}
|
|
197
|
+
cache.set(nodeName, assetOutputs);
|
|
198
|
+
return assetOutputs;
|
|
199
|
+
}
|
|
200
|
+
// Leaf node: call the implementation function
|
|
201
|
+
if (!definition.impl) {
|
|
202
|
+
throw new Error(`No implementation found for node: ${nodeContext}:${node.type}`);
|
|
203
|
+
}
|
|
183
204
|
const outputs = await definition.impl(nodeInputs, nodeProps);
|
|
184
|
-
// Cache and return
|
|
185
205
|
cache.set(nodeName, outputs);
|
|
186
206
|
return outputs;
|
|
187
207
|
}
|
package/evaluate.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.evaluate = evaluate;
|
|
4
|
+
/**
|
|
5
|
+
* Build a definition map key from context and name.
|
|
6
|
+
*/
|
|
7
|
+
function defKey(context, name) {
|
|
8
|
+
return `${context}:${name}`;
|
|
9
|
+
}
|
|
4
10
|
/**
|
|
5
11
|
* Evaluate a graph starting from the specified output node/port.
|
|
6
12
|
* Uses lazy evaluation - only evaluates nodes that are needed for the output.
|
|
@@ -19,8 +25,10 @@ async function evaluate(graph, options) {
|
|
|
19
25
|
}
|
|
20
26
|
const defMap = new Map();
|
|
21
27
|
for (const def of definitions) {
|
|
22
|
-
defMap.set(def.
|
|
28
|
+
defMap.set(defKey(def.context, def.name), def);
|
|
23
29
|
}
|
|
30
|
+
// Graph-level context used as default for node lookups
|
|
31
|
+
const graphContext = graph.context || '';
|
|
24
32
|
// Build edge lookup: destination node -> destination port -> edges (in array order)
|
|
25
33
|
const edgesByDst = new Map();
|
|
26
34
|
for (const edge of graph.edges) {
|
|
@@ -50,8 +58,8 @@ async function evaluate(graph, options) {
|
|
|
50
58
|
if (!node) {
|
|
51
59
|
throw new Error(`Node not found: ${nodeName}`);
|
|
52
60
|
}
|
|
53
|
-
// Handle
|
|
54
|
-
//
|
|
61
|
+
// Handle system nodes (graphInput, graphOutput, graphProp)
|
|
62
|
+
// System nodes are identified by their type name — reserved, no definition lookup needed
|
|
55
63
|
if (node.type === 'graphInput') {
|
|
56
64
|
// Get the port name from the portName property
|
|
57
65
|
const portNameProp = node.props?.find(p => p.name === 'portName');
|
|
@@ -89,8 +97,8 @@ async function evaluate(graph, options) {
|
|
|
89
97
|
cache.set(nodeName, result);
|
|
90
98
|
return result;
|
|
91
99
|
}
|
|
92
|
-
// Handle subnet nodes (
|
|
93
|
-
if (node.
|
|
100
|
+
// Handle subnet nodes (type: 'subnet' with inline nodes/edges)
|
|
101
|
+
if (node.type === 'subnet' && node.nodes && node.edges) {
|
|
94
102
|
// Collect inputs for the subnet by evaluating upstream nodes
|
|
95
103
|
const subnetInputs = {};
|
|
96
104
|
const subnetPortEdges = edgesByDst.get(nodeName);
|
|
@@ -121,6 +129,7 @@ async function evaluate(graph, options) {
|
|
|
121
129
|
// Recursively evaluate the subnet's internal graph
|
|
122
130
|
const subnetResult = await evaluate({
|
|
123
131
|
name: `${nodeName}_subnet`,
|
|
132
|
+
context: graphContext || undefined,
|
|
124
133
|
nodes: node.nodes,
|
|
125
134
|
edges: node.edges
|
|
126
135
|
}, {
|
|
@@ -135,13 +144,11 @@ async function evaluate(graph, options) {
|
|
|
135
144
|
cache.set(nodeName, subnetOutputs);
|
|
136
145
|
return subnetOutputs;
|
|
137
146
|
}
|
|
138
|
-
// Get the definition for this node
|
|
139
|
-
const
|
|
147
|
+
// Get the definition for this node — resolve context from node override or graph default
|
|
148
|
+
const nodeContext = node.context || graphContext;
|
|
149
|
+
const definition = defMap.get(defKey(nodeContext, node.type));
|
|
140
150
|
if (!definition) {
|
|
141
|
-
throw new Error(`No definition found for node
|
|
142
|
-
}
|
|
143
|
-
if (!definition.impl) {
|
|
144
|
-
throw new Error(`No implementation found for node type: ${node.type}`);
|
|
151
|
+
throw new Error(`No definition found for node: ${nodeContext}:${node.type}`);
|
|
145
152
|
}
|
|
146
153
|
// Collect inputs by evaluating upstream nodes
|
|
147
154
|
const nodeInputs = {};
|
|
@@ -150,7 +157,6 @@ async function evaluate(graph, options) {
|
|
|
150
157
|
for (const inputPort of definition.inputs) {
|
|
151
158
|
const edges = portEdges?.get(inputPort.name) ?? [];
|
|
152
159
|
if (inputPort.multi) {
|
|
153
|
-
// Multi-input port: collect all values in edge array order
|
|
154
160
|
const values = await Promise.all(edges.map(async (edge) => {
|
|
155
161
|
const upstreamOutputs = await evaluateNode(edge.src.node);
|
|
156
162
|
return upstreamOutputs[edge.src.port];
|
|
@@ -158,7 +164,6 @@ async function evaluate(graph, options) {
|
|
|
158
164
|
nodeInputs[inputPort.name] = values;
|
|
159
165
|
}
|
|
160
166
|
else {
|
|
161
|
-
// Single input: take first edge if exists
|
|
162
167
|
if (edges.length > 0) {
|
|
163
168
|
const edge = edges[0];
|
|
164
169
|
const upstreamOutputs = await evaluateNode(edge.src.node);
|
|
@@ -167,24 +172,39 @@ async function evaluate(graph, options) {
|
|
|
167
172
|
}
|
|
168
173
|
}
|
|
169
174
|
}
|
|
170
|
-
// Get props from node instance
|
|
175
|
+
// Get props from node instance (override definition defaults)
|
|
171
176
|
const nodeProps = {};
|
|
172
177
|
if (definition.props) {
|
|
173
178
|
for (const propDef of definition.props) {
|
|
174
|
-
// First check node instance props
|
|
175
179
|
const instanceProp = node.props?.find(p => p.name === propDef.name);
|
|
176
180
|
if (instanceProp !== undefined && instanceProp.value !== undefined) {
|
|
177
181
|
nodeProps[propDef.name] = instanceProp.value;
|
|
178
182
|
}
|
|
179
183
|
else if (propDef.default !== undefined) {
|
|
180
|
-
// Fall back to definition default
|
|
181
184
|
nodeProps[propDef.name] = propDef.default;
|
|
182
185
|
}
|
|
183
186
|
}
|
|
184
187
|
}
|
|
185
|
-
//
|
|
188
|
+
// Digital asset: definition has an internal graph — evaluate it recursively
|
|
189
|
+
if (definition.graph) {
|
|
190
|
+
const assetGraph = definition.graph;
|
|
191
|
+
// Find all output boundary nodes in the asset's graph
|
|
192
|
+
const assetOutputs = {};
|
|
193
|
+
const outputBoundaryNodes = assetGraph.nodes.filter(n => n.type === 'graphOutput');
|
|
194
|
+
for (const outputBoundaryNode of outputBoundaryNodes) {
|
|
195
|
+
const portNameProp = outputBoundaryNode.props?.find(p => p.name === 'portName');
|
|
196
|
+
const portName = portNameProp?.value || outputBoundaryNode.name;
|
|
197
|
+
const result = await evaluate({ name: `${nodeName}_asset`, context: assetGraph.context, nodes: assetGraph.nodes, edges: assetGraph.edges }, { definitions, outputNode: outputBoundaryNode.name, outputPort: 'value', inputs: nodeInputs, props: nodeProps });
|
|
198
|
+
assetOutputs[portName] = result;
|
|
199
|
+
}
|
|
200
|
+
cache.set(nodeName, assetOutputs);
|
|
201
|
+
return assetOutputs;
|
|
202
|
+
}
|
|
203
|
+
// Leaf node: call the implementation function
|
|
204
|
+
if (!definition.impl) {
|
|
205
|
+
throw new Error(`No implementation found for node: ${nodeContext}:${node.type}`);
|
|
206
|
+
}
|
|
186
207
|
const outputs = await definition.impl(nodeInputs, nodeProps);
|
|
187
|
-
// Cache and return
|
|
188
208
|
cache.set(nodeName, outputs);
|
|
189
209
|
return outputs;
|
|
190
210
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fbp/evaluator",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
5
5
|
"description": "Lazy graph evaluator for Flow-Based Programming",
|
|
6
6
|
"main": "index.js",
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
"lazy-evaluation"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@fbp/types": "1.
|
|
38
|
+
"@fbp/types": "1.1.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"makage": "0.1.9"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "6f0ef58d9a54f35a2a5849e84234a67fa8d8a9b5"
|
|
44
44
|
}
|