@valerypopoff/rivet2-core 2.0.7 → 2.0.8
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/dist/cjs/bundle.cjs +703 -329
- package/dist/cjs/bundle.cjs.map +4 -4
- package/dist/esm/api/createProcessor.js +8 -2
- package/dist/esm/model/GraphPreprocessor.js +129 -7
- package/dist/esm/model/GraphProcessor.js +204 -82
- package/dist/esm/model/NodeExclusionPolicy.js +67 -0
- package/dist/esm/model/NodeExecutionPlanner.js +66 -22
- package/dist/esm/model/chat-v2/chatV2Outputs.js +183 -0
- package/dist/esm/model/chat-v2/chatV2Pipeline.js +30 -212
- package/dist/esm/model/nodes/CodeNewNode.js +1 -1
- package/dist/esm/model/nodes/CodeNode.js +1 -1
- package/dist/esm/model/nodes/HttpCallNode.js +20 -18
- package/dist/esm/model/nodes/codeNodeErrorDiagnostics.js +2 -3
- package/dist/types/api/createProcessor.d.ts +8 -2
- package/dist/types/model/GraphPreprocessor.d.ts +36 -2
- package/dist/types/model/GraphProcessor.d.ts +12 -1
- package/dist/types/model/NodeExclusionPolicy.d.ts +21 -0
- package/dist/types/model/NodeExecutionPlanner.d.ts +3 -8
- package/dist/types/model/chat-v2/chatV2Outputs.d.ts +29 -0
- package/dist/types/model/nodes/codeNodeErrorDiagnostics.d.ts +1 -2
- package/package.json +1 -1
package/dist/cjs/bundle.cjs
CHANGED
|
@@ -2262,7 +2262,7 @@ function findStronglyConnectedComponents(nodes, getAdjacentNodes) {
|
|
|
2262
2262
|
// src/model/GraphPreprocessor.ts
|
|
2263
2263
|
function preprocessGraphState(options2) {
|
|
2264
2264
|
var _a, _b;
|
|
2265
|
-
const { graph, loadedProjects, project, registry, warnOnInvalidGraph } = options2;
|
|
2265
|
+
const { buildExecutionPlan, graph, loadedProjects, project, registry, warnOnInvalidGraph } = options2;
|
|
2266
2266
|
const nodeInstances = {};
|
|
2267
2267
|
const nodesById = {};
|
|
2268
2268
|
const connections = {};
|
|
@@ -2302,14 +2302,49 @@ function preprocessGraphState(options2) {
|
|
|
2302
2302
|
const nodeConnections = connections[node.id] ?? [];
|
|
2303
2303
|
return nodeConnections.filter((connection) => connection.outputNodeId === node.id).map((connection) => nodesById[connection.inputNodeId]).filter(Boolean);
|
|
2304
2304
|
});
|
|
2305
|
-
|
|
2305
|
+
const nodesNotInCycle = stronglyConnectedComponents.filter((component) => component.length === 1).flat();
|
|
2306
|
+
const result = {
|
|
2306
2307
|
connections,
|
|
2307
2308
|
definitions,
|
|
2308
2309
|
nodeInstances,
|
|
2309
2310
|
nodesById,
|
|
2310
|
-
nodesNotInCycle
|
|
2311
|
+
nodesNotInCycle,
|
|
2311
2312
|
stronglyConnectedComponents
|
|
2312
2313
|
};
|
|
2314
|
+
if (!buildExecutionPlan) {
|
|
2315
|
+
return result;
|
|
2316
|
+
}
|
|
2317
|
+
return {
|
|
2318
|
+
...result,
|
|
2319
|
+
...buildGraphExecutionPlan({
|
|
2320
|
+
connections,
|
|
2321
|
+
definitions,
|
|
2322
|
+
graphNodes: graph.nodes,
|
|
2323
|
+
nodesById,
|
|
2324
|
+
stronglyConnectedComponents
|
|
2325
|
+
})
|
|
2326
|
+
};
|
|
2327
|
+
}
|
|
2328
|
+
function isGraphExecutionPlan(preprocessedGraph) {
|
|
2329
|
+
return "inputConnectionByNodeAndPort" in preprocessedGraph;
|
|
2330
|
+
}
|
|
2331
|
+
function toReusableGraphExecutionPlan(preprocessedGraph) {
|
|
2332
|
+
return {
|
|
2333
|
+
connections: preprocessedGraph.connections,
|
|
2334
|
+
cycleIndexByNode: preprocessedGraph.cycleIndexByNode,
|
|
2335
|
+
definitions: preprocessedGraph.definitions,
|
|
2336
|
+
graphNodes: preprocessedGraph.graphNodes,
|
|
2337
|
+
inputConnectionByNodeAndPort: preprocessedGraph.inputConnectionByNodeAndPort,
|
|
2338
|
+
inputConnectionsByNode: preprocessedGraph.inputConnectionsByNode,
|
|
2339
|
+
inputNodesByNode: preprocessedGraph.inputNodesByNode,
|
|
2340
|
+
missingRequiredInputsByNode: preprocessedGraph.missingRequiredInputsByNode,
|
|
2341
|
+
nodesById: preprocessedGraph.nodesById,
|
|
2342
|
+
nodesNotInCycle: preprocessedGraph.nodesNotInCycle,
|
|
2343
|
+
outputConnectionsByNodeAndPort: preprocessedGraph.outputConnectionsByNodeAndPort,
|
|
2344
|
+
outputNodeResultsByNode: preprocessedGraph.outputNodeResultsByNode,
|
|
2345
|
+
startNodes: preprocessedGraph.startNodes,
|
|
2346
|
+
stronglyConnectedComponents: preprocessedGraph.stronglyConnectedComponents
|
|
2347
|
+
};
|
|
2313
2348
|
}
|
|
2314
2349
|
function loadInputOutputDefinitions(options2) {
|
|
2315
2350
|
const { connections, loadedProjects, nodeInstances, nodesById, project, warnOnInvalidGraph } = options2;
|
|
@@ -2358,17 +2393,114 @@ function loadInputOutputDefinitions(options2) {
|
|
|
2358
2393
|
}
|
|
2359
2394
|
return false;
|
|
2360
2395
|
});
|
|
2361
|
-
|
|
2396
|
+
if (invalidConnections.length > 0) {
|
|
2362
2397
|
for (const invalidConnection of invalidConnections) {
|
|
2363
|
-
|
|
2364
|
-
if (
|
|
2365
|
-
|
|
2398
|
+
removeConnectionFromNode(connections, invalidConnection, invalidConnection.inputNodeId);
|
|
2399
|
+
if (invalidConnection.outputNodeId !== invalidConnection.inputNodeId) {
|
|
2400
|
+
removeConnectionFromNode(connections, invalidConnection, invalidConnection.outputNodeId);
|
|
2366
2401
|
}
|
|
2367
2402
|
}
|
|
2368
2403
|
}
|
|
2369
2404
|
}
|
|
2370
2405
|
return definitions;
|
|
2371
2406
|
}
|
|
2407
|
+
function removeConnectionFromNode(connections, connection, nodeId) {
|
|
2408
|
+
const nodeConnections = connections[nodeId];
|
|
2409
|
+
if (!nodeConnections) {
|
|
2410
|
+
return;
|
|
2411
|
+
}
|
|
2412
|
+
const invalidConnectionIndex = nodeConnections.indexOf(connection);
|
|
2413
|
+
if (invalidConnectionIndex !== -1) {
|
|
2414
|
+
nodeConnections.splice(invalidConnectionIndex, 1);
|
|
2415
|
+
}
|
|
2416
|
+
}
|
|
2417
|
+
function buildGraphExecutionPlan(options2) {
|
|
2418
|
+
var _a, _b;
|
|
2419
|
+
const { connections, definitions, graphNodes, nodesById, stronglyConnectedComponents } = options2;
|
|
2420
|
+
const cycleIndexByNode = {};
|
|
2421
|
+
const inputConnectionByNodeAndPort = {};
|
|
2422
|
+
const inputConnectionsByNode = {};
|
|
2423
|
+
const inputNodesByNode = {};
|
|
2424
|
+
const missingRequiredInputsByNode = {};
|
|
2425
|
+
const outputConnectionsByNodeAndPort = {};
|
|
2426
|
+
const outputNodeResultsByNode = {};
|
|
2427
|
+
stronglyConnectedComponents.forEach((component, index) => {
|
|
2428
|
+
for (const node of component) {
|
|
2429
|
+
cycleIndexByNode[node.id] = index;
|
|
2430
|
+
}
|
|
2431
|
+
});
|
|
2432
|
+
for (const node of graphNodes) {
|
|
2433
|
+
const nodeConnections = connections[node.id] ?? [];
|
|
2434
|
+
const inputDefinitions = ((_a = definitions[node.id]) == null ? void 0 : _a.inputs) ?? [];
|
|
2435
|
+
const outputDefinitions = ((_b = definitions[node.id]) == null ? void 0 : _b.outputs) ?? [];
|
|
2436
|
+
const validInputIds = new Set(inputDefinitions.map((definition) => definition.id));
|
|
2437
|
+
const validOutputIds = new Set(outputDefinitions.map((definition) => definition.id));
|
|
2438
|
+
const inputConnections = nodeConnections.filter(
|
|
2439
|
+
(connection) => connection.inputNodeId === node.id && validInputIds.has(connection.inputId)
|
|
2440
|
+
);
|
|
2441
|
+
const outputConnections = nodeConnections.filter(
|
|
2442
|
+
(connection) => connection.outputNodeId === node.id && validOutputIds.has(connection.outputId)
|
|
2443
|
+
);
|
|
2444
|
+
inputConnectionsByNode[node.id] = inputConnections;
|
|
2445
|
+
outputConnectionsByNodeAndPort[node.id] = {};
|
|
2446
|
+
inputConnectionByNodeAndPort[node.id] = {};
|
|
2447
|
+
for (const connection of inputConnections) {
|
|
2448
|
+
inputConnectionByNodeAndPort[node.id][connection.inputId] ??= connection;
|
|
2449
|
+
}
|
|
2450
|
+
for (const connection of outputConnections) {
|
|
2451
|
+
outputConnectionsByNodeAndPort[node.id][connection.outputId] ??= [];
|
|
2452
|
+
outputConnectionsByNodeAndPort[node.id][connection.outputId].push(connection);
|
|
2453
|
+
}
|
|
2454
|
+
inputNodesByNode[node.id] = inputConnections.map((connection) => nodesById[connection.outputNodeId]).filter((inputNode) => inputNode != null);
|
|
2455
|
+
missingRequiredInputsByNode[node.id] = inputDefinitions.filter(
|
|
2456
|
+
(input) => {
|
|
2457
|
+
var _a2;
|
|
2458
|
+
return input.required && ((_a2 = inputConnectionByNodeAndPort[node.id]) == null ? void 0 : _a2[input.id]) == null;
|
|
2459
|
+
}
|
|
2460
|
+
);
|
|
2461
|
+
const outputNodes = [];
|
|
2462
|
+
const seenOutputNodeIds = /* @__PURE__ */ new Set();
|
|
2463
|
+
const outputConnectionsByNode = /* @__PURE__ */ new Map();
|
|
2464
|
+
for (const connection of outputConnections) {
|
|
2465
|
+
const outputNode = nodesById[connection.inputNodeId];
|
|
2466
|
+
if (!outputNode) {
|
|
2467
|
+
continue;
|
|
2468
|
+
}
|
|
2469
|
+
if (!seenOutputNodeIds.has(outputNode.id)) {
|
|
2470
|
+
outputNodes.push(outputNode);
|
|
2471
|
+
seenOutputNodeIds.add(outputNode.id);
|
|
2472
|
+
}
|
|
2473
|
+
const nodeConnections2 = outputConnectionsByNode.get(outputNode.id);
|
|
2474
|
+
if (nodeConnections2) {
|
|
2475
|
+
nodeConnections2.push(connection);
|
|
2476
|
+
} else {
|
|
2477
|
+
outputConnectionsByNode.set(outputNode.id, [connection]);
|
|
2478
|
+
}
|
|
2479
|
+
}
|
|
2480
|
+
outputNodeResultsByNode[node.id] = {
|
|
2481
|
+
connections: outputConnections,
|
|
2482
|
+
connectionsToNodes: outputNodes.map((outputNode) => ({
|
|
2483
|
+
connections: outputConnectionsByNode.get(outputNode.id) ?? [],
|
|
2484
|
+
node: outputNode
|
|
2485
|
+
})),
|
|
2486
|
+
nodes: outputNodes
|
|
2487
|
+
};
|
|
2488
|
+
}
|
|
2489
|
+
return {
|
|
2490
|
+
cycleIndexByNode,
|
|
2491
|
+
graphNodes,
|
|
2492
|
+
inputConnectionByNodeAndPort,
|
|
2493
|
+
inputConnectionsByNode,
|
|
2494
|
+
inputNodesByNode,
|
|
2495
|
+
missingRequiredInputsByNode,
|
|
2496
|
+
outputConnectionsByNodeAndPort,
|
|
2497
|
+
outputNodeResultsByNode,
|
|
2498
|
+
startNodes: graphNodes.filter((node) => {
|
|
2499
|
+
var _a2;
|
|
2500
|
+
return ((_a2 = outputNodeResultsByNode[node.id]) == null ? void 0 : _a2.nodes.length) === 0;
|
|
2501
|
+
})
|
|
2502
|
+
};
|
|
2503
|
+
}
|
|
2372
2504
|
|
|
2373
2505
|
// src/model/RecordingPlayer.ts
|
|
2374
2506
|
var import_non_secure3 = require("nanoid/non-secure");
|
|
@@ -2828,41 +2960,75 @@ function aggregateOutputs(results) {
|
|
|
2828
2960
|
}
|
|
2829
2961
|
|
|
2830
2962
|
// src/model/NodeExecutionPlanner.ts
|
|
2831
|
-
var import_lodash_es4 = require("lodash");
|
|
2832
2963
|
function getStartNodes(state, graphNodes, runToNodeIds) {
|
|
2833
|
-
|
|
2964
|
+
var _a;
|
|
2965
|
+
if (runToNodeIds) {
|
|
2966
|
+
return graphNodes.filter((node) => runToNodeIds.includes(node.id));
|
|
2967
|
+
}
|
|
2968
|
+
return ((_a = state.executionPlan) == null ? void 0 : _a.startNodes) ?? graphNodes.filter((node) => getOutputNodesFrom(state, node).nodes.length === 0);
|
|
2834
2969
|
}
|
|
2835
2970
|
function getInputNodesTo(state, node) {
|
|
2836
|
-
var _a;
|
|
2971
|
+
var _a, _b;
|
|
2972
|
+
const plannedInputNodes = (_a = state.executionPlan) == null ? void 0 : _a.inputNodesByNode[node.id];
|
|
2973
|
+
if (plannedInputNodes) {
|
|
2974
|
+
return plannedInputNodes;
|
|
2975
|
+
}
|
|
2837
2976
|
const connections = state.connections[node.id];
|
|
2838
2977
|
if (!connections) {
|
|
2839
2978
|
return [];
|
|
2840
2979
|
}
|
|
2841
|
-
const
|
|
2842
|
-
const
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2980
|
+
const inputDefinitions = ((_b = state.definitions[node.id]) == null ? void 0 : _b.inputs) ?? [];
|
|
2981
|
+
const validInputIds = new Set(inputDefinitions.map((definition) => definition.id));
|
|
2982
|
+
const inputNodes = [];
|
|
2983
|
+
for (const connection of connections) {
|
|
2984
|
+
if (connection.inputNodeId !== node.id || !validInputIds.has(connection.inputId)) {
|
|
2985
|
+
continue;
|
|
2986
|
+
}
|
|
2987
|
+
const inputNode = state.nodesById[connection.outputNodeId];
|
|
2988
|
+
if (inputNode) {
|
|
2989
|
+
inputNodes.push(inputNode);
|
|
2990
|
+
}
|
|
2991
|
+
}
|
|
2992
|
+
return inputNodes;
|
|
2847
2993
|
}
|
|
2848
2994
|
function getOutputNodesFrom(state, node) {
|
|
2849
|
-
var _a;
|
|
2995
|
+
var _a, _b;
|
|
2996
|
+
const plannedOutputNodes = (_a = state.executionPlan) == null ? void 0 : _a.outputNodeResultsByNode[node.id];
|
|
2997
|
+
if (plannedOutputNodes) {
|
|
2998
|
+
return plannedOutputNodes;
|
|
2999
|
+
}
|
|
2850
3000
|
const connections = state.connections[node.id];
|
|
2851
3001
|
if (!connections) {
|
|
2852
3002
|
return { nodes: [], connections: [], connectionsToNodes: [] };
|
|
2853
3003
|
}
|
|
2854
|
-
const
|
|
2855
|
-
const
|
|
2856
|
-
const outputConnections =
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
const
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
3004
|
+
const outputDefinitions = ((_b = state.definitions[node.id]) == null ? void 0 : _b.outputs) ?? [];
|
|
3005
|
+
const validOutputIds = new Set(outputDefinitions.map((definition) => definition.id));
|
|
3006
|
+
const outputConnections = [];
|
|
3007
|
+
const outputConnectionsByNode = /* @__PURE__ */ new Map();
|
|
3008
|
+
const outputNodes = [];
|
|
3009
|
+
const seenOutputNodeIds = /* @__PURE__ */ new Set();
|
|
3010
|
+
for (const connection of connections) {
|
|
3011
|
+
if (connection.outputNodeId !== node.id || !validOutputIds.has(connection.outputId)) {
|
|
3012
|
+
continue;
|
|
3013
|
+
}
|
|
3014
|
+
outputConnections.push(connection);
|
|
3015
|
+
const outputNode = state.nodesById[connection.inputNodeId];
|
|
3016
|
+
if (!outputNode) {
|
|
3017
|
+
continue;
|
|
3018
|
+
}
|
|
3019
|
+
if (!seenOutputNodeIds.has(outputNode.id)) {
|
|
3020
|
+
outputNodes.push(outputNode);
|
|
3021
|
+
seenOutputNodeIds.add(outputNode.id);
|
|
3022
|
+
}
|
|
3023
|
+
const nodeConnections = outputConnectionsByNode.get(outputNode.id);
|
|
3024
|
+
if (nodeConnections) {
|
|
3025
|
+
nodeConnections.push(connection);
|
|
3026
|
+
} else {
|
|
3027
|
+
outputConnectionsByNode.set(outputNode.id, [connection]);
|
|
3028
|
+
}
|
|
3029
|
+
}
|
|
2864
3030
|
const connectionsToNodes = outputNodes.map((outputNode) => ({
|
|
2865
|
-
connections:
|
|
3031
|
+
connections: outputConnectionsByNode.get(outputNode.id) ?? [],
|
|
2866
3032
|
node: outputNode
|
|
2867
3033
|
}));
|
|
2868
3034
|
return { nodes: outputNodes, connections: outputConnections, connectionsToNodes };
|
|
@@ -2877,10 +3043,20 @@ function hasErroredInputNode(state, node, inputNodes, onTrace) {
|
|
|
2877
3043
|
return false;
|
|
2878
3044
|
}
|
|
2879
3045
|
function getMissingRequiredInputs(state, node) {
|
|
3046
|
+
var _a;
|
|
3047
|
+
const plannedMissingInputs = (_a = state.executionPlan) == null ? void 0 : _a.missingRequiredInputsByNode[node.id];
|
|
3048
|
+
if (plannedMissingInputs) {
|
|
3049
|
+
return plannedMissingInputs;
|
|
3050
|
+
}
|
|
2880
3051
|
const connections = state.connections[node.id] ?? [];
|
|
3052
|
+
const connectedInputIds = /* @__PURE__ */ new Set();
|
|
3053
|
+
for (const connection of connections) {
|
|
3054
|
+
if (connection.inputNodeId === node.id) {
|
|
3055
|
+
connectedInputIds.add(connection.inputId);
|
|
3056
|
+
}
|
|
3057
|
+
}
|
|
2881
3058
|
return state.definitions[node.id].inputs.filter((input) => {
|
|
2882
|
-
|
|
2883
|
-
return input.required && !connectionToInput;
|
|
3059
|
+
return input.required && !connectedInputIds.has(input.id);
|
|
2884
3060
|
});
|
|
2885
3061
|
}
|
|
2886
3062
|
function getWaitingForInputNode(state, node, inputNodes, inputValues) {
|
|
@@ -2901,6 +3077,11 @@ function getWaitingForInputNode(state, node, inputNodes, inputValues) {
|
|
|
2901
3077
|
return waitingForInputNode;
|
|
2902
3078
|
}
|
|
2903
3079
|
function nodesAreInSameCycle(state, a, b) {
|
|
3080
|
+
var _a;
|
|
3081
|
+
const plannedCycleIndexByNode = (_a = state.executionPlan) == null ? void 0 : _a.cycleIndexByNode;
|
|
3082
|
+
if (plannedCycleIndexByNode) {
|
|
3083
|
+
return plannedCycleIndexByNode[a] != null && plannedCycleIndexByNode[a] === plannedCycleIndexByNode[b];
|
|
3084
|
+
}
|
|
2904
3085
|
return state.stronglyConnectedComponents.find(
|
|
2905
3086
|
(cycle) => cycle.find((node) => node.id === a) && cycle.find((node) => node.id === b)
|
|
2906
3087
|
);
|
|
@@ -3007,6 +3188,77 @@ function wireSubprocessorLifecycle(processor, options2) {
|
|
|
3007
3188
|
unsubscribers.push(subscribeOwnGraphRunLifecycle(processor, cleanup));
|
|
3008
3189
|
}
|
|
3009
3190
|
|
|
3191
|
+
// src/model/NodeExclusionPolicy.ts
|
|
3192
|
+
var nodesAllowedToConsumeExcludedValue = /* @__PURE__ */ new Set([
|
|
3193
|
+
"if",
|
|
3194
|
+
"ifElse",
|
|
3195
|
+
"coalesce",
|
|
3196
|
+
"graphOutput",
|
|
3197
|
+
"raceInputs",
|
|
3198
|
+
"loopController"
|
|
3199
|
+
]);
|
|
3200
|
+
function isControlFlowExcluded2(value) {
|
|
3201
|
+
return value != null && getScalarTypeOf(value.type) === "control-flow-excluded";
|
|
3202
|
+
}
|
|
3203
|
+
function getControlFlowExclusionDecision({
|
|
3204
|
+
inputValues,
|
|
3205
|
+
node,
|
|
3206
|
+
typeOfExclusion
|
|
3207
|
+
}) {
|
|
3208
|
+
var _a;
|
|
3209
|
+
if (node.disabled) {
|
|
3210
|
+
return {
|
|
3211
|
+
action: "exclude",
|
|
3212
|
+
reason: "disabled",
|
|
3213
|
+
traceMessage: `Excluding node ${node.title} because it's disabled`
|
|
3214
|
+
};
|
|
3215
|
+
}
|
|
3216
|
+
if (node.isConditional && typeOfExclusion === void 0) {
|
|
3217
|
+
const ifValue = coerceTypeOptional(inputValues[IF_PORT.id], "boolean");
|
|
3218
|
+
if (ifValue === false) {
|
|
3219
|
+
return {
|
|
3220
|
+
action: "exclude",
|
|
3221
|
+
reason: "if port is false",
|
|
3222
|
+
traceMessage: `Excluding node ${node.title} because if port is false`
|
|
3223
|
+
};
|
|
3224
|
+
}
|
|
3225
|
+
}
|
|
3226
|
+
const controlFlowExcludedValues = entries(inputValues).filter(
|
|
3227
|
+
([, value]) => isControlFlowExcluded2(value) && (typeOfExclusion === void 0 || value.value === typeOfExclusion)
|
|
3228
|
+
);
|
|
3229
|
+
const isWaitingForLoop = controlFlowExcludedValues.some(([, value]) => (value == null ? void 0 : value.value) === LOOP_NOT_BROKEN_SENTINEL);
|
|
3230
|
+
const allowedToConsumeExcludedValue = nodesAllowedToConsumeExcludedValue.has(node.type) && !isWaitingForLoop;
|
|
3231
|
+
if (controlFlowExcludedValues.length === 0 || allowedToConsumeExcludedValue) {
|
|
3232
|
+
return { action: "continue" };
|
|
3233
|
+
}
|
|
3234
|
+
if (isWaitingForLoop) {
|
|
3235
|
+
return { action: "defer" };
|
|
3236
|
+
}
|
|
3237
|
+
return {
|
|
3238
|
+
action: "exclude",
|
|
3239
|
+
reason: "input is excluded value",
|
|
3240
|
+
traceMessage: `Excluding node ${node.title} because of control flow. Input is has excluded value: ${(_a = controlFlowExcludedValues[0]) == null ? void 0 : _a[0]}`
|
|
3241
|
+
};
|
|
3242
|
+
}
|
|
3243
|
+
function getMissingRequiredInputExclusion(node, missingRequiredInputs) {
|
|
3244
|
+
const missingInputNames = missingRequiredInputs.map((input) => input.title || input.id).join(", ");
|
|
3245
|
+
return {
|
|
3246
|
+
action: "exclude",
|
|
3247
|
+
reason: "missing required input",
|
|
3248
|
+
traceMessage: `Excluding node ${node.title} because required inputs are not connected: ${missingInputNames}`
|
|
3249
|
+
};
|
|
3250
|
+
}
|
|
3251
|
+
function createExcludedNodeOutputs(node, outputDefinitions) {
|
|
3252
|
+
const outputs = {};
|
|
3253
|
+
for (const output of outputDefinitions) {
|
|
3254
|
+
outputs[output.id] = { type: "control-flow-excluded", value: void 0 };
|
|
3255
|
+
}
|
|
3256
|
+
if (node.type === "loopController") {
|
|
3257
|
+
outputs["break"] = { type: "control-flow-excluded", value: LOOP_NOT_BROKEN_SENTINEL };
|
|
3258
|
+
}
|
|
3259
|
+
return outputs;
|
|
3260
|
+
}
|
|
3261
|
+
|
|
3010
3262
|
// src/integrations/CodeRunner.ts
|
|
3011
3263
|
var IsomorphicCodeRunner = class {
|
|
3012
3264
|
async runCode(code, inputs, options2, graphInputs, contextValues) {
|
|
@@ -3055,6 +3307,13 @@ var NotAllowedCodeRunner = class {
|
|
|
3055
3307
|
// src/model/GraphProcessor.ts
|
|
3056
3308
|
var DEFAULT_NODE_CONCURRENCY = 8;
|
|
3057
3309
|
var DEFAULT_SPLIT_RUN_CONCURRENCY = 4;
|
|
3310
|
+
var FAST_ACYCLIC_UNSUPPORTED_NODE_TYPES = /* @__PURE__ */ new Set([
|
|
3311
|
+
"loopController",
|
|
3312
|
+
"loopUntil",
|
|
3313
|
+
"raceInputs",
|
|
3314
|
+
"userInput",
|
|
3315
|
+
"waitForEvent"
|
|
3316
|
+
]);
|
|
3058
3317
|
function normalizeConcurrencyValue(value, fallback) {
|
|
3059
3318
|
return typeof value === "number" && Number.isFinite(value) && value >= 1 ? Math.floor(value) : fallback;
|
|
3060
3319
|
}
|
|
@@ -3080,6 +3339,10 @@ var GraphProcessor = class _GraphProcessor {
|
|
|
3080
3339
|
#parent;
|
|
3081
3340
|
#registry;
|
|
3082
3341
|
#concurrency;
|
|
3342
|
+
#executionPlanCacheMode;
|
|
3343
|
+
#runtimeCache;
|
|
3344
|
+
#cacheLoadedProjects;
|
|
3345
|
+
#scheduler;
|
|
3083
3346
|
id = (0, import_non_secure4.nanoid)();
|
|
3084
3347
|
#includeTrace = true;
|
|
3085
3348
|
executor;
|
|
@@ -3123,7 +3386,7 @@ var GraphProcessor = class _GraphProcessor {
|
|
|
3123
3386
|
#loadedProjects = void 0;
|
|
3124
3387
|
#definitions = void 0;
|
|
3125
3388
|
#scc = void 0;
|
|
3126
|
-
|
|
3389
|
+
#graphExecutionPlan;
|
|
3127
3390
|
#nodesNotInCycle = void 0;
|
|
3128
3391
|
#nodeAbortControllers = /* @__PURE__ */ new Map();
|
|
3129
3392
|
#graphInputNodeValues = {};
|
|
@@ -3147,6 +3410,10 @@ var GraphProcessor = class _GraphProcessor {
|
|
|
3147
3410
|
this.#nodesById = {};
|
|
3148
3411
|
this.#registry = registry;
|
|
3149
3412
|
this.#concurrency = resolveGraphProcessorConcurrency(options2 == null ? void 0 : options2.concurrency);
|
|
3413
|
+
this.#executionPlanCacheMode = (options2 == null ? void 0 : options2.executionPlanCacheMode) ?? "all";
|
|
3414
|
+
this.#runtimeCache = options2 == null ? void 0 : options2.runtimeCache;
|
|
3415
|
+
this.#cacheLoadedProjects = (options2 == null ? void 0 : options2.cacheLoadedProjects) ?? false;
|
|
3416
|
+
this.#scheduler = (options2 == null ? void 0 : options2.scheduler) ?? "compatible";
|
|
3150
3417
|
this.#emitter.bindMethods(this, ["on", "off", "once", "onAny", "offAny"]);
|
|
3151
3418
|
this.setExternalFunction("echo", async (value) => ({ type: "any", value }));
|
|
3152
3419
|
this.#emitter.on("globalSet", ({ id, value }) => {
|
|
@@ -3154,19 +3421,53 @@ var GraphProcessor = class _GraphProcessor {
|
|
|
3154
3421
|
});
|
|
3155
3422
|
}
|
|
3156
3423
|
#preprocessGraph() {
|
|
3424
|
+
var _a;
|
|
3425
|
+
const runtimeCache = this.#canUseRuntimeExecutionPlanCache() ? this.#runtimeCache : void 0;
|
|
3426
|
+
const shouldUseRuntimeCache = runtimeCache != null;
|
|
3427
|
+
const cachedPlan = (_a = runtimeCache == null ? void 0 : runtimeCache.executionPlans) == null ? void 0 : _a.get(this.#graph);
|
|
3428
|
+
if (cachedPlan) {
|
|
3429
|
+
this.#applyPreprocessedGraph(cachedPlan, { recreateNodeInstances: true });
|
|
3430
|
+
return;
|
|
3431
|
+
}
|
|
3157
3432
|
const preprocessedGraph = preprocessGraphState({
|
|
3158
3433
|
graph: this.#graph,
|
|
3159
3434
|
loadedProjects: this.#loadedProjects,
|
|
3160
3435
|
project: this.#project,
|
|
3161
3436
|
registry: this.#registry,
|
|
3162
|
-
warnOnInvalidGraph: this.warnOnInvalidGraph
|
|
3437
|
+
warnOnInvalidGraph: this.warnOnInvalidGraph,
|
|
3438
|
+
buildExecutionPlan: shouldUseRuntimeCache
|
|
3163
3439
|
});
|
|
3164
|
-
|
|
3440
|
+
if (shouldUseRuntimeCache && isGraphExecutionPlan(preprocessedGraph)) {
|
|
3441
|
+
runtimeCache.executionPlans ??= /* @__PURE__ */ new WeakMap();
|
|
3442
|
+
runtimeCache.executionPlans.set(this.#graph, toReusableGraphExecutionPlan(preprocessedGraph));
|
|
3443
|
+
}
|
|
3444
|
+
this.#applyPreprocessedGraph(preprocessedGraph);
|
|
3445
|
+
}
|
|
3446
|
+
#canUseRuntimeExecutionPlanCache() {
|
|
3447
|
+
var _a;
|
|
3448
|
+
if (this.warnOnInvalidGraph || this.#runtimeCache == null) {
|
|
3449
|
+
return false;
|
|
3450
|
+
}
|
|
3451
|
+
if (this.#executionPlanCacheMode === "subprocessors" && !this.#isSubProcessor) {
|
|
3452
|
+
return false;
|
|
3453
|
+
}
|
|
3454
|
+
if (!this.#cacheLoadedProjects && (((_a = this.#project.references) == null ? void 0 : _a.length) ?? 0) > 0) {
|
|
3455
|
+
return false;
|
|
3456
|
+
}
|
|
3457
|
+
return true;
|
|
3458
|
+
}
|
|
3459
|
+
#applyPreprocessedGraph(preprocessedGraph, options2 = {}) {
|
|
3460
|
+
const nodeInstances = options2.recreateNodeInstances || !("nodeInstances" in preprocessedGraph) ? this.#createNodeInstances(isGraphExecutionPlan(preprocessedGraph) ? preprocessedGraph.graphNodes : this.#graph.nodes) : preprocessedGraph.nodeInstances;
|
|
3461
|
+
Object.assign(this.#nodeInstances, nodeInstances);
|
|
3165
3462
|
Object.assign(this.#nodesById, preprocessedGraph.nodesById);
|
|
3166
3463
|
Object.assign(this.#connections, preprocessedGraph.connections);
|
|
3167
3464
|
this.#definitions = preprocessedGraph.definitions;
|
|
3168
3465
|
this.#scc = preprocessedGraph.stronglyConnectedComponents;
|
|
3169
3466
|
this.#nodesNotInCycle = preprocessedGraph.nodesNotInCycle;
|
|
3467
|
+
this.#graphExecutionPlan = isGraphExecutionPlan(preprocessedGraph) ? preprocessedGraph : void 0;
|
|
3468
|
+
}
|
|
3469
|
+
#createNodeInstances(nodes) {
|
|
3470
|
+
return Object.fromEntries(nodes.map((node) => [node.id, this.#registry.createDynamicImpl(node)]));
|
|
3170
3471
|
}
|
|
3171
3472
|
#emitTraceEvent(eventData) {
|
|
3172
3473
|
if (this.#includeTrace) {
|
|
@@ -3322,6 +3623,7 @@ var GraphProcessor = class _GraphProcessor {
|
|
|
3322
3623
|
this.#preprocessGraph();
|
|
3323
3624
|
}
|
|
3324
3625
|
#collectDependencyNodesDeep(nodeId, dependencyNodes) {
|
|
3626
|
+
var _a;
|
|
3325
3627
|
if (dependencyNodes.has(nodeId)) {
|
|
3326
3628
|
return;
|
|
3327
3629
|
}
|
|
@@ -3330,7 +3632,7 @@ var GraphProcessor = class _GraphProcessor {
|
|
|
3330
3632
|
return;
|
|
3331
3633
|
}
|
|
3332
3634
|
dependencyNodes.add(nodeId);
|
|
3333
|
-
const connections = this.#connections[nodeId] ?? [];
|
|
3635
|
+
const connections = ((_a = this.#graphExecutionPlan) == null ? void 0 : _a.inputConnectionsByNode[nodeId]) ?? this.#connections[nodeId] ?? [];
|
|
3334
3636
|
for (const connection of connections) {
|
|
3335
3637
|
if (connection.inputNodeId === nodeId) {
|
|
3336
3638
|
this.#collectDependencyNodesDeep(connection.outputNodeId, dependencyNodes);
|
|
@@ -3367,6 +3669,7 @@ var GraphProcessor = class _GraphProcessor {
|
|
|
3367
3669
|
return this.#graphOutputs;
|
|
3368
3670
|
}
|
|
3369
3671
|
#initProcessState() {
|
|
3672
|
+
var _a;
|
|
3370
3673
|
this.#running = true;
|
|
3371
3674
|
this.#finishEmitted = false;
|
|
3372
3675
|
if (!this.#hasPreloadedData) {
|
|
@@ -3394,7 +3697,7 @@ var GraphProcessor = class _GraphProcessor {
|
|
|
3394
3697
|
this.#abortError = void 0;
|
|
3395
3698
|
this.#abortSuccessfully = false;
|
|
3396
3699
|
this.#nodeAbortControllers = /* @__PURE__ */ new Map();
|
|
3397
|
-
this.#loadedProjects = {};
|
|
3700
|
+
this.#loadedProjects = this.#cacheLoadedProjects && ((_a = this.#runtimeCache) == null ? void 0 : _a.loadedProjects) ? { ...this.#runtimeCache.loadedProjects } : {};
|
|
3398
3701
|
this.#graphInputNodeValues = {};
|
|
3399
3702
|
}
|
|
3400
3703
|
/** Main function for running a graph. Runs a graph and returns the outputs from the output nodes of the graph. */
|
|
@@ -3409,9 +3712,13 @@ var GraphProcessor = class _GraphProcessor {
|
|
|
3409
3712
|
await this.#emitGraphStart();
|
|
3410
3713
|
await this.#emitPreloadedNodeResults();
|
|
3411
3714
|
await this.#waitUntilUnpaused();
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3715
|
+
if (this.#canUseFastAcyclicScheduler()) {
|
|
3716
|
+
await this.#processFastAcyclicGraph();
|
|
3717
|
+
} else {
|
|
3718
|
+
await this.#queueStartNodes(getStartNodes(this.#executionState, this.#graph.nodes, this.runToNodeIds));
|
|
3719
|
+
await this.#processingQueue.onIdle();
|
|
3720
|
+
this.#markUnqueuedNodesIgnored();
|
|
3721
|
+
}
|
|
3415
3722
|
await this.#throwIfGraphErrored();
|
|
3416
3723
|
return await this.#finalizeGraphRun();
|
|
3417
3724
|
} finally {
|
|
@@ -3498,6 +3805,87 @@ var GraphProcessor = class _GraphProcessor {
|
|
|
3498
3805
|
});
|
|
3499
3806
|
}
|
|
3500
3807
|
}
|
|
3808
|
+
#canUseFastAcyclicScheduler() {
|
|
3809
|
+
if (this.#scheduler !== "fast-acyclic") {
|
|
3810
|
+
return false;
|
|
3811
|
+
}
|
|
3812
|
+
if (this.#hasPreloadedData || this.runToNodeIds || this.slowMode || this.#includeTrace) {
|
|
3813
|
+
return false;
|
|
3814
|
+
}
|
|
3815
|
+
if (this.#nodesNotInCycle.length !== this.#graph.nodes.length) {
|
|
3816
|
+
return false;
|
|
3817
|
+
}
|
|
3818
|
+
if (this.#graph.connections.some((connection) => connection.inputNodeId === connection.outputNodeId)) {
|
|
3819
|
+
return false;
|
|
3820
|
+
}
|
|
3821
|
+
return this.#graph.nodes.every((node) => {
|
|
3822
|
+
if (node.isSplitRun) {
|
|
3823
|
+
return false;
|
|
3824
|
+
}
|
|
3825
|
+
return !FAST_ACYCLIC_UNSUPPORTED_NODE_TYPES.has(node.type);
|
|
3826
|
+
});
|
|
3827
|
+
}
|
|
3828
|
+
async #processFastAcyclicGraph() {
|
|
3829
|
+
const remainingInputsByNode = /* @__PURE__ */ new Map();
|
|
3830
|
+
const readyNodes = [];
|
|
3831
|
+
const queuedNodeIds = /* @__PURE__ */ new Set();
|
|
3832
|
+
for (const node of this.#graph.nodes) {
|
|
3833
|
+
const inputNodeIds = /* @__PURE__ */ new Set();
|
|
3834
|
+
for (const inputNode of getInputNodesTo(this.#executionState, node)) {
|
|
3835
|
+
inputNodeIds.add(inputNode.id);
|
|
3836
|
+
}
|
|
3837
|
+
const inputCount = inputNodeIds.size;
|
|
3838
|
+
remainingInputsByNode.set(node.id, inputCount);
|
|
3839
|
+
if (inputCount === 0) {
|
|
3840
|
+
readyNodes.push(node);
|
|
3841
|
+
queuedNodeIds.add(node.id);
|
|
3842
|
+
}
|
|
3843
|
+
}
|
|
3844
|
+
await new Promise((resolve, reject) => {
|
|
3845
|
+
let activeCount = 0;
|
|
3846
|
+
let settled = false;
|
|
3847
|
+
const queueReadyOutputs = (outputNodes) => {
|
|
3848
|
+
for (const outputNode of outputNodes) {
|
|
3849
|
+
const remainingInputs = (remainingInputsByNode.get(outputNode.id) ?? 0) - 1;
|
|
3850
|
+
remainingInputsByNode.set(outputNode.id, remainingInputs);
|
|
3851
|
+
if (remainingInputs <= 0 && !queuedNodeIds.has(outputNode.id)) {
|
|
3852
|
+
readyNodes.push(outputNode);
|
|
3853
|
+
queuedNodeIds.add(outputNode.id);
|
|
3854
|
+
}
|
|
3855
|
+
}
|
|
3856
|
+
};
|
|
3857
|
+
const settle = () => {
|
|
3858
|
+
if (settled) {
|
|
3859
|
+
return;
|
|
3860
|
+
}
|
|
3861
|
+
if (activeCount === 0 && readyNodes.length === 0) {
|
|
3862
|
+
settled = true;
|
|
3863
|
+
resolve();
|
|
3864
|
+
}
|
|
3865
|
+
};
|
|
3866
|
+
const pump = () => {
|
|
3867
|
+
if (settled) {
|
|
3868
|
+
return;
|
|
3869
|
+
}
|
|
3870
|
+
while (activeCount < this.#concurrency.nodeConcurrency && readyNodes.length > 0) {
|
|
3871
|
+
const node = readyNodes.shift();
|
|
3872
|
+
activeCount += 1;
|
|
3873
|
+
void this.#processNodeIfAllInputsAvailable(node, { queueOutputNodes: false }).then(queueReadyOutputs).then(() => {
|
|
3874
|
+
activeCount -= 1;
|
|
3875
|
+
pump();
|
|
3876
|
+
settle();
|
|
3877
|
+
}).catch((error) => {
|
|
3878
|
+
if (!settled) {
|
|
3879
|
+
settled = true;
|
|
3880
|
+
reject(error);
|
|
3881
|
+
}
|
|
3882
|
+
});
|
|
3883
|
+
}
|
|
3884
|
+
settle();
|
|
3885
|
+
};
|
|
3886
|
+
pump();
|
|
3887
|
+
});
|
|
3888
|
+
}
|
|
3501
3889
|
#markUnqueuedNodesIgnored() {
|
|
3502
3890
|
if (!this.runToNodeIds) {
|
|
3503
3891
|
return;
|
|
@@ -3558,8 +3946,12 @@ ${erroredNodes.map(([nodeId]) => `- ${this.#nodesById[nodeId].title} (${nodeId})
|
|
|
3558
3946
|
return outputValues;
|
|
3559
3947
|
}
|
|
3560
3948
|
async #loadProjectReferences() {
|
|
3561
|
-
var _a;
|
|
3949
|
+
var _a, _b;
|
|
3562
3950
|
if ((((_a = this.#project.references) == null ? void 0 : _a.length) ?? 0) > 0) {
|
|
3951
|
+
if (this.#cacheLoadedProjects && ((_b = this.#runtimeCache) == null ? void 0 : _b.loadedProjects)) {
|
|
3952
|
+
this.#loadedProjects = { ...this.#runtimeCache.loadedProjects };
|
|
3953
|
+
return;
|
|
3954
|
+
}
|
|
3563
3955
|
if (!this.#context.projectReferenceLoader) {
|
|
3564
3956
|
throw new Error(
|
|
3565
3957
|
"Project references are set, but no projectReferenceLoader is set in the context. Since this project uses project references, you must provide a projectReferenceLoader in the context."
|
|
@@ -3580,6 +3972,9 @@ ${erroredNodes.map(([nodeId]) => `- ${this.#nodesById[nodeId].title} (${nodeId})
|
|
|
3580
3972
|
for (const reference of this.#project.references) {
|
|
3581
3973
|
await loadProject(reference);
|
|
3582
3974
|
}
|
|
3975
|
+
if (this.#cacheLoadedProjects && this.#runtimeCache) {
|
|
3976
|
+
this.#runtimeCache.loadedProjects = { ...this.#loadedProjects };
|
|
3977
|
+
}
|
|
3583
3978
|
}
|
|
3584
3979
|
}
|
|
3585
3980
|
/** Returns true if any input node has errored. Optionally emits a trace event. */
|
|
@@ -3602,10 +3997,6 @@ ${erroredNodes.map(([nodeId]) => `- ${this.#nodesById[nodeId].title} (${nodeId})
|
|
|
3602
3997
|
this.#totalCost += coerceTypeOptional(output["cost"], "number") ?? 0;
|
|
3603
3998
|
}
|
|
3604
3999
|
}
|
|
3605
|
-
/** Checks if a data value represents a control-flow-excluded signal. */
|
|
3606
|
-
#isControlFlowExcluded(value) {
|
|
3607
|
-
return value != null && getScalarTypeOf(value.type) === "control-flow-excluded";
|
|
3608
|
-
}
|
|
3609
4000
|
async #fetchNodeDataAndProcessNode(node) {
|
|
3610
4001
|
var _a;
|
|
3611
4002
|
if (this.#currentlyProcessing.has(node.id) || this.#queuedNodes.has(node.id)) {
|
|
@@ -3646,37 +4037,47 @@ ${erroredNodes.map(([nodeId]) => `- ${this.#nodesById[nodeId].title} (${nodeId})
|
|
|
3646
4037
|
await this.#processNodeIfAllInputsAvailable(node);
|
|
3647
4038
|
}
|
|
3648
4039
|
/** If all inputs are present, all conditions met, processes the node. */
|
|
3649
|
-
async #processNodeIfAllInputsAvailable(node) {
|
|
4040
|
+
async #processNodeIfAllInputsAvailable(node, options2 = {}) {
|
|
4041
|
+
const { queueOutputNodes = true } = options2;
|
|
3650
4042
|
const builtInNode = node;
|
|
3651
4043
|
const inputNodes = getInputNodesTo(this.#executionState, node);
|
|
3652
4044
|
if (this.#shouldSkipNodeProcessing(node, inputNodes)) {
|
|
3653
|
-
return;
|
|
4045
|
+
return [];
|
|
3654
4046
|
}
|
|
3655
4047
|
const attachedData = this.#getAttachedDataTo(node);
|
|
3656
4048
|
if (this.#shouldSkipCompletedRaceNode(node, attachedData)) {
|
|
3657
|
-
return;
|
|
4049
|
+
return [];
|
|
3658
4050
|
}
|
|
3659
4051
|
const inputValues = this.#getInputValuesForNode(node);
|
|
3660
|
-
|
|
4052
|
+
const loopExclusion = this.#excludedDueToControlFlow(
|
|
4053
|
+
node,
|
|
4054
|
+
inputValues,
|
|
4055
|
+
(0, import_non_secure4.nanoid)(),
|
|
4056
|
+
LOOP_NOT_BROKEN_SENTINEL,
|
|
4057
|
+
{ queueOutputNodes }
|
|
4058
|
+
);
|
|
4059
|
+
if (loopExclusion) {
|
|
3661
4060
|
this.#emitTraceEvent(`Node ${node.title} is excluded due to control flow`);
|
|
3662
|
-
return;
|
|
4061
|
+
return loopExclusion === true ? [] : loopExclusion;
|
|
3663
4062
|
}
|
|
3664
4063
|
const waitingForInputNode = getWaitingForInputNode(this.#executionState, node, inputNodes, inputValues);
|
|
3665
4064
|
if (waitingForInputNode) {
|
|
3666
4065
|
this.#emitTraceEvent(`Node ${node.title} is waiting for input node ${waitingForInputNode}`);
|
|
3667
|
-
return;
|
|
4066
|
+
return [];
|
|
3668
4067
|
}
|
|
3669
|
-
|
|
4068
|
+
const exclusion = this.#excludedDueToControlFlow(node, inputValues, (0, import_non_secure4.nanoid)(), void 0, {
|
|
4069
|
+
queueOutputNodes
|
|
4070
|
+
});
|
|
4071
|
+
if (exclusion) {
|
|
3670
4072
|
this.#emitTraceEvent(`Node ${node.title} is excluded due to control flow`);
|
|
3671
|
-
return;
|
|
4073
|
+
return exclusion === true ? [] : exclusion;
|
|
3672
4074
|
}
|
|
3673
4075
|
const missingRequiredInputs = this.#getMissingRequiredInputs(node);
|
|
3674
4076
|
if (missingRequiredInputs.length > 0) {
|
|
3675
|
-
this.#excludeNodeWithMissingRequiredInputs(node, inputValues, missingRequiredInputs);
|
|
3676
|
-
return;
|
|
4077
|
+
return this.#excludeNodeWithMissingRequiredInputs(node, inputValues, missingRequiredInputs, { queueOutputNodes });
|
|
3677
4078
|
}
|
|
3678
4079
|
if (this.#beginNodeProcessing(node, attachedData) === false) {
|
|
3679
|
-
return;
|
|
4080
|
+
return [];
|
|
3680
4081
|
}
|
|
3681
4082
|
const processId = await this.#processNode(node);
|
|
3682
4083
|
if (this.slowMode) {
|
|
@@ -3690,10 +4091,13 @@ ${erroredNodes.map(([nodeId]) => `- ${this.#nodesById[nodeId].title} (${nodeId})
|
|
|
3690
4091
|
this.#handleLoopControllerPostProcess(node, attachedData);
|
|
3691
4092
|
this.#handleCompletedRace(node);
|
|
3692
4093
|
if (!this.#assignChildLoopInfo(node, builtInNode, attachedData, processId)) {
|
|
3693
|
-
return;
|
|
4094
|
+
return [];
|
|
3694
4095
|
}
|
|
3695
4096
|
this.#propagateAttachedDataToOutputNodes(node, attachedData, outputNodes.connectionsToNodes);
|
|
3696
|
-
|
|
4097
|
+
if (queueOutputNodes) {
|
|
4098
|
+
this.#queueOutputNodes(node, outputNodes.nodes);
|
|
4099
|
+
}
|
|
4100
|
+
return outputNodes.nodes;
|
|
3697
4101
|
}
|
|
3698
4102
|
#shouldSkipNodeProcessing(node, inputNodes) {
|
|
3699
4103
|
if (this.#ignoreNodes.has(node.id)) {
|
|
@@ -3724,11 +4128,11 @@ ${erroredNodes.map(([nodeId]) => `- ${this.#nodesById[nodeId].title} (${nodeId})
|
|
|
3724
4128
|
}
|
|
3725
4129
|
return false;
|
|
3726
4130
|
}
|
|
3727
|
-
#excludeNodeWithMissingRequiredInputs(node, inputValues, missingRequiredInputs) {
|
|
3728
|
-
const
|
|
4131
|
+
#excludeNodeWithMissingRequiredInputs(node, inputValues, missingRequiredInputs, options2 = {}) {
|
|
4132
|
+
const exclusion = getMissingRequiredInputExclusion(node, missingRequiredInputs);
|
|
3729
4133
|
const processId = (0, import_non_secure4.nanoid)();
|
|
3730
|
-
this.#emitTraceEvent(
|
|
3731
|
-
this.#excludeNode(node, processId, inputValues,
|
|
4134
|
+
this.#emitTraceEvent(exclusion.traceMessage);
|
|
4135
|
+
return this.#excludeNode(node, processId, inputValues, exclusion.reason, options2);
|
|
3732
4136
|
}
|
|
3733
4137
|
#beginNodeProcessing(node, attachedData) {
|
|
3734
4138
|
if (this.#shouldSkipCompletedRaceNode(node, attachedData)) {
|
|
@@ -3879,7 +4283,7 @@ ${erroredNodes.map(([nodeId]) => `- ${this.#nodesById[nodeId].title} (${nodeId})
|
|
|
3879
4283
|
async #processSplitRunNode(node, processId) {
|
|
3880
4284
|
return processSplitRunNode(node, processId, {
|
|
3881
4285
|
getInputValues: (n) => this.#getInputValuesForNode(n),
|
|
3882
|
-
isExcludedDueToControlFlow: (n, inputs, pid) => this.#excludedDueToControlFlow(n, inputs, pid),
|
|
4286
|
+
isExcludedDueToControlFlow: (n, inputs, pid) => this.#excludedDueToControlFlow(n, inputs, pid) !== false,
|
|
3883
4287
|
processNodeWithInputData: (n, inputs, idx, pid, partial) => this.#processNodeWithInputData(n, inputs, idx, pid, partial),
|
|
3884
4288
|
splitRunConcurrency: this.#concurrency.splitRunConcurrency,
|
|
3885
4289
|
accumulateCost: (output) => this.#accumulateCost(output),
|
|
@@ -4058,7 +4462,11 @@ ${erroredNodes.map(([nodeId]) => `- ${this.#nodesById[nodeId].title} (${nodeId})
|
|
|
4058
4462
|
}
|
|
4059
4463
|
#createSubProcessor(node, index, processId, subGraphId, { signal, project } = {}) {
|
|
4060
4464
|
const processor = new _GraphProcessor(project ?? this.#project, subGraphId, this.#registry, this.#includeTrace, {
|
|
4061
|
-
|
|
4465
|
+
cacheLoadedProjects: this.#cacheLoadedProjects,
|
|
4466
|
+
concurrency: this.#concurrency,
|
|
4467
|
+
executionPlanCacheMode: this.#executionPlanCacheMode,
|
|
4468
|
+
runtimeCache: this.#runtimeCache,
|
|
4469
|
+
scheduler: this.#scheduler
|
|
4062
4470
|
});
|
|
4063
4471
|
processor.executor = this.executor;
|
|
4064
4472
|
processor.#isSubProcessor = true;
|
|
@@ -4130,53 +4538,19 @@ ${erroredNodes.map(([nodeId]) => `- ${this.#nodesById[nodeId].title} (${nodeId})
|
|
|
4130
4538
|
);
|
|
4131
4539
|
});
|
|
4132
4540
|
}
|
|
4133
|
-
#excludedDueToControlFlow(node, inputValues, processId, typeOfExclusion =
|
|
4134
|
-
|
|
4135
|
-
if (
|
|
4136
|
-
|
|
4137
|
-
this.#excludeNode(node, processId, inputValues, "disabled");
|
|
4138
|
-
return true;
|
|
4139
|
-
}
|
|
4140
|
-
if (node.isConditional && typeOfExclusion === void 0) {
|
|
4141
|
-
const ifValue = coerceTypeOptional(inputValues[IF_PORT.id], "boolean");
|
|
4142
|
-
if (ifValue === false) {
|
|
4143
|
-
this.#emitTraceEvent(`Excluding node ${node.title} because if port is false`);
|
|
4144
|
-
this.#excludeNode(node, processId, inputValues, "if port is false");
|
|
4145
|
-
return true;
|
|
4146
|
-
}
|
|
4541
|
+
#excludedDueToControlFlow(node, inputValues, processId, typeOfExclusion, options2 = {}) {
|
|
4542
|
+
const exclusion = getControlFlowExclusionDecision({ node, inputValues, typeOfExclusion });
|
|
4543
|
+
if (exclusion.action === "continue") {
|
|
4544
|
+
return false;
|
|
4147
4545
|
}
|
|
4148
|
-
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
);
|
|
4152
|
-
const inputIsExcludedValue = inputsWithValues.length > 0 && controlFlowExcludedValues.length > 0;
|
|
4153
|
-
const isWaitingForLoop = controlFlowExcludedValues.some((value) => {
|
|
4154
|
-
var _a2;
|
|
4155
|
-
return ((_a2 = value == null ? void 0 : value[1]) == null ? void 0 : _a2.value) === LOOP_NOT_BROKEN_SENTINEL;
|
|
4156
|
-
});
|
|
4157
|
-
const nodesAllowedToConsumeExcludedValue = [
|
|
4158
|
-
"if",
|
|
4159
|
-
"ifElse",
|
|
4160
|
-
"coalesce",
|
|
4161
|
-
"graphOutput",
|
|
4162
|
-
"raceInputs",
|
|
4163
|
-
"loopController"
|
|
4164
|
-
];
|
|
4165
|
-
const allowedToConsumedExcludedValue = nodesAllowedToConsumeExcludedValue.includes(node.type) && !isWaitingForLoop;
|
|
4166
|
-
if (inputIsExcludedValue && !allowedToConsumedExcludedValue) {
|
|
4167
|
-
if (!isWaitingForLoop) {
|
|
4168
|
-
if (inputIsExcludedValue) {
|
|
4169
|
-
this.#emitTraceEvent(
|
|
4170
|
-
`Excluding node ${node.title} because of control flow. Input is has excluded value: ${(_a = controlFlowExcludedValues[0]) == null ? void 0 : _a[0]}`
|
|
4171
|
-
);
|
|
4172
|
-
}
|
|
4173
|
-
this.#excludeNode(node, processId, inputValues, "input is excluded value");
|
|
4174
|
-
}
|
|
4175
|
-
return true;
|
|
4546
|
+
if (exclusion.action === "exclude") {
|
|
4547
|
+
this.#emitTraceEvent(exclusion.traceMessage);
|
|
4548
|
+
return this.#excludeNode(node, processId, inputValues, exclusion.reason, options2);
|
|
4176
4549
|
}
|
|
4177
|
-
return
|
|
4550
|
+
return true;
|
|
4178
4551
|
}
|
|
4179
|
-
#excludeNode(node, processId, inputValues, reason) {
|
|
4552
|
+
#excludeNode(node, processId, inputValues, reason, options2 = {}) {
|
|
4553
|
+
const { queueOutputNodes = true } = options2;
|
|
4180
4554
|
const attachedData = this.#getAttachedDataTo(node);
|
|
4181
4555
|
this.#registerNodeInActiveLoop(node, attachedData);
|
|
4182
4556
|
this.#visitedNodes.add(node.id);
|
|
@@ -4185,16 +4559,13 @@ ${erroredNodes.map(([nodeId]) => `- ${this.#nodesById[nodeId].title} (${nodeId})
|
|
|
4185
4559
|
this.#remainingNodes.delete(node.id);
|
|
4186
4560
|
const outputNodes = getOutputNodesFrom(this.#executionState, node);
|
|
4187
4561
|
this.#propagateAttachedDataToOutputNodes(node, attachedData, outputNodes.connectionsToNodes);
|
|
4188
|
-
|
|
4562
|
+
if (queueOutputNodes) {
|
|
4563
|
+
this.#queueOutputNodes(node, outputNodes.nodes);
|
|
4564
|
+
}
|
|
4565
|
+
return outputNodes.nodes;
|
|
4189
4566
|
}
|
|
4190
4567
|
#markAsExcluded(node, processId, inputValues, reason) {
|
|
4191
|
-
const outputs =
|
|
4192
|
-
for (const output of this.#definitions[node.id].outputs) {
|
|
4193
|
-
outputs[output.id] = { type: "control-flow-excluded", value: void 0 };
|
|
4194
|
-
}
|
|
4195
|
-
if (node.type === "loopController") {
|
|
4196
|
-
outputs["break"] = { type: "control-flow-excluded", value: LOOP_NOT_BROKEN_SENTINEL };
|
|
4197
|
-
}
|
|
4568
|
+
const outputs = createExcludedNodeOutputs(node, this.#definitions[node.id].outputs);
|
|
4198
4569
|
this.#nodeResults.set(node.id, outputs);
|
|
4199
4570
|
emitDetached(
|
|
4200
4571
|
this.#emitter,
|
|
@@ -4212,10 +4583,8 @@ ${erroredNodes.map(([nodeId]) => `- ${this.#nodesById[nodeId].title} (${nodeId})
|
|
|
4212
4583
|
const connections = this.#connections[node.id];
|
|
4213
4584
|
return this.#definitions[node.id].inputs.reduce(
|
|
4214
4585
|
(values2, input) => {
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
}
|
|
4218
|
-
const connection = connections.find((conn) => conn.inputId === input.id && conn.inputNodeId === node.id);
|
|
4586
|
+
var _a, _b;
|
|
4587
|
+
const connection = ((_b = (_a = this.#graphExecutionPlan) == null ? void 0 : _a.inputConnectionByNodeAndPort[node.id]) == null ? void 0 : _b[input.id]) ?? (connections == null ? void 0 : connections.find((conn) => conn.inputId === input.id && conn.inputNodeId === node.id));
|
|
4219
4588
|
if (connection) {
|
|
4220
4589
|
const outputNode = this.#nodeInstances[connection.outputNodeId].chartNode;
|
|
4221
4590
|
const outputNodeOutputs = this.#nodeResults.get(outputNode.id);
|
|
@@ -4232,6 +4601,7 @@ ${erroredNodes.map(([nodeId]) => `- ${this.#nodesById[nodeId].title} (${nodeId})
|
|
|
4232
4601
|
connections: this.#connections,
|
|
4233
4602
|
definitions: this.#definitions,
|
|
4234
4603
|
erroredNodes: this.#erroredNodes,
|
|
4604
|
+
executionPlan: this.#graphExecutionPlan,
|
|
4235
4605
|
loopControllersSeen: this.#loopControllersSeen,
|
|
4236
4606
|
nodesById: this.#nodesById,
|
|
4237
4607
|
stronglyConnectedComponents: this.#scc,
|
|
@@ -4457,7 +4827,7 @@ var NodeRegistration = class {
|
|
|
4457
4827
|
|
|
4458
4828
|
// src/model/nodes/UserInputNode.ts
|
|
4459
4829
|
var import_non_secure5 = require("nanoid/non-secure");
|
|
4460
|
-
var
|
|
4830
|
+
var import_lodash_es4 = require("lodash");
|
|
4461
4831
|
var import_ts_dedent2 = require("ts-dedent");
|
|
4462
4832
|
var UserInputNodeImpl = class extends NodeImpl {
|
|
4463
4833
|
static create() {
|
|
@@ -4554,7 +4924,7 @@ var UserInputNodeImpl = class extends NodeImpl {
|
|
|
4554
4924
|
},
|
|
4555
4925
|
["questionsAndAnswers"]: {
|
|
4556
4926
|
type: "string[]",
|
|
4557
|
-
value: (0,
|
|
4927
|
+
value: (0, import_lodash_es4.zip)(questions, response.value).map(([q, a]) => `${q}
|
|
4558
4928
|
${a}`)
|
|
4559
4929
|
}
|
|
4560
4930
|
};
|
|
@@ -4567,7 +4937,7 @@ var import_non_secure6 = require("nanoid/non-secure");
|
|
|
4567
4937
|
var import_ts_dedent3 = require("ts-dedent");
|
|
4568
4938
|
|
|
4569
4939
|
// src/utils/interpolation.ts
|
|
4570
|
-
var
|
|
4940
|
+
var import_lodash_es5 = require("lodash");
|
|
4571
4941
|
var ESCAPED_TOKEN_REGEX = /\{\{\{([^}]+?)\}\}\}/g;
|
|
4572
4942
|
var ESCAPED_ESCAPED_TOKEN_REGEX = /\\\{\\\{([^}]+?)\\\}\\\}/g;
|
|
4573
4943
|
var processingFunctions = {
|
|
@@ -4657,7 +5027,7 @@ function resolveExpressionRawValue(source, expression, sourceType) {
|
|
|
4657
5027
|
let finalValue;
|
|
4658
5028
|
if (path) {
|
|
4659
5029
|
try {
|
|
4660
|
-
finalValue = (0,
|
|
5030
|
+
finalValue = (0, import_lodash_es5.get)(baseValue, path);
|
|
4661
5031
|
finalValue = unwrapPotentialDataValue(finalValue);
|
|
4662
5032
|
} catch (error) {
|
|
4663
5033
|
console.warn(`Error accessing path "${path}" in ${sourceType} value for key "${key}":`, error);
|
|
@@ -4999,7 +5369,7 @@ __export(openai_exports, {
|
|
|
4999
5369
|
openaiModels: () => openaiModels,
|
|
5000
5370
|
streamChatCompletions: () => streamChatCompletions
|
|
5001
5371
|
});
|
|
5002
|
-
var
|
|
5372
|
+
var import_lodash_es6 = require("lodash");
|
|
5003
5373
|
|
|
5004
5374
|
// src/utils/fetchEventSource.ts
|
|
5005
5375
|
var EventSourceResponse = class extends Response {
|
|
@@ -5244,7 +5614,7 @@ var openaiModels = {
|
|
|
5244
5614
|
displayName: "Local Model"
|
|
5245
5615
|
}
|
|
5246
5616
|
};
|
|
5247
|
-
var openAiModelOptions = (0,
|
|
5617
|
+
var openAiModelOptions = (0, import_lodash_es6.orderBy)(
|
|
5248
5618
|
Object.entries(openaiModels).map(([id, { displayName }]) => ({
|
|
5249
5619
|
value: id,
|
|
5250
5620
|
label: displayName
|
|
@@ -9677,21 +10047,9 @@ function normalizeChatV2ProviderError(error, context) {
|
|
|
9677
10047
|
return normalized;
|
|
9678
10048
|
}
|
|
9679
10049
|
|
|
9680
|
-
// src/model/chat-v2/
|
|
9681
|
-
var
|
|
9682
|
-
var
|
|
9683
|
-
var StreamChatV2RetryFailure = class extends Error {
|
|
9684
|
-
constructor(error, requestStatuses, requestErrors) {
|
|
9685
|
-
super("Chat v2 retry attempts failed");
|
|
9686
|
-
this.error = error;
|
|
9687
|
-
this.requestStatuses = requestStatuses;
|
|
9688
|
-
this.requestErrors = requestErrors;
|
|
9689
|
-
this.name = "StreamChatV2RetryFailure";
|
|
9690
|
-
}
|
|
9691
|
-
};
|
|
9692
|
-
function isStreamChatV2RetryFailure(error) {
|
|
9693
|
-
return error instanceof StreamChatV2RetryFailure;
|
|
9694
|
-
}
|
|
10050
|
+
// src/model/chat-v2/chatV2Outputs.ts
|
|
10051
|
+
var CHAT_V2_REQUEST_STATUS_PORT_ID = "requestStatus";
|
|
10052
|
+
var CHAT_V2_REQUEST_ERROR_PORT_ID = "requestError";
|
|
9695
10053
|
function toFunctionCallOutputValue(functionCall) {
|
|
9696
10054
|
let argumentsValue = functionCall.lastParsedArguments;
|
|
9697
10055
|
if (argumentsValue == null) {
|
|
@@ -9707,7 +10065,13 @@ function toFunctionCallOutputValue(functionCall) {
|
|
|
9707
10065
|
id: functionCall.id
|
|
9708
10066
|
};
|
|
9709
10067
|
}
|
|
9710
|
-
function
|
|
10068
|
+
function createControlFlowExcludedOutput() {
|
|
10069
|
+
return {
|
|
10070
|
+
type: "control-flow-excluded",
|
|
10071
|
+
value: void 0
|
|
10072
|
+
};
|
|
10073
|
+
}
|
|
10074
|
+
function normalizeChatV2Usage(usage, options2) {
|
|
9711
10075
|
var _a, _b, _c;
|
|
9712
10076
|
if (usage == null) {
|
|
9713
10077
|
return void 0;
|
|
@@ -9733,19 +10097,57 @@ function tryParseStructuredResponseText(response) {
|
|
|
9733
10097
|
return void 0;
|
|
9734
10098
|
}
|
|
9735
10099
|
}
|
|
9736
|
-
function
|
|
10100
|
+
function createChatV2ResponseOutput2(response, structuredOutput, responseFormat) {
|
|
9737
10101
|
if (!isChatV2StructuredResponseFormat(responseFormat)) {
|
|
9738
10102
|
return { type: "string", value: response };
|
|
9739
10103
|
}
|
|
9740
10104
|
const parsedOutput = structuredOutput !== void 0 ? structuredOutput : tryParseStructuredResponseText(response);
|
|
9741
10105
|
return parsedOutput !== void 0 ? inferType(parsedOutput) : { type: "string", value: response };
|
|
9742
10106
|
}
|
|
9743
|
-
function
|
|
10107
|
+
function createChatV2ReasoningOutput(reasoning) {
|
|
10108
|
+
if (Array.isArray(reasoning)) {
|
|
10109
|
+
const nonEmptyReasoning = reasoning.filter((part) => typeof part === "string" && part.trim().length > 0);
|
|
10110
|
+
return nonEmptyReasoning.length > 0 ? {
|
|
10111
|
+
type: "string[]",
|
|
10112
|
+
value: nonEmptyReasoning
|
|
10113
|
+
} : createControlFlowExcludedOutput();
|
|
10114
|
+
}
|
|
10115
|
+
const reasoningText = typeof reasoning === "string" ? reasoning : "";
|
|
10116
|
+
return reasoningText.trim().length > 0 ? {
|
|
10117
|
+
type: "string",
|
|
10118
|
+
value: reasoningText
|
|
10119
|
+
} : createControlFlowExcludedOutput();
|
|
10120
|
+
}
|
|
10121
|
+
function createChatV2RetryAttemptOutput(type, values2) {
|
|
10122
|
+
return values2.length > 0 ? {
|
|
10123
|
+
type,
|
|
10124
|
+
value: values2
|
|
10125
|
+
} : createControlFlowExcludedOutput();
|
|
10126
|
+
}
|
|
10127
|
+
function createChatV2CommonOutputs({
|
|
10128
|
+
requestMessages,
|
|
10129
|
+
response,
|
|
10130
|
+
structuredOutput,
|
|
10131
|
+
functionCalls,
|
|
10132
|
+
usage,
|
|
10133
|
+
reasoning,
|
|
10134
|
+
requestStatus,
|
|
10135
|
+
responseError,
|
|
10136
|
+
requestStatuses,
|
|
10137
|
+
requestErrors,
|
|
10138
|
+
outputUsage,
|
|
10139
|
+
outputReasoning,
|
|
10140
|
+
outputRequestStatus,
|
|
10141
|
+
includeFunctionCalls,
|
|
10142
|
+
functionCallMode,
|
|
10143
|
+
retryOnNon200,
|
|
10144
|
+
responseFormat
|
|
10145
|
+
}) {
|
|
9744
10146
|
const outputs = {
|
|
9745
|
-
["response"]:
|
|
10147
|
+
["response"]: createChatV2ResponseOutput2(response, structuredOutput, responseFormat),
|
|
9746
10148
|
["in-messages"]: { type: "chat-message[]", value: requestMessages },
|
|
9747
10149
|
["all-messages"]: createAssistantMessagesOutput(requestMessages, response, functionCalls, {
|
|
9748
|
-
functionCallMode
|
|
10150
|
+
functionCallMode
|
|
9749
10151
|
}),
|
|
9750
10152
|
["responseTokens"]: { type: "number", value: (usage == null ? void 0 : usage.completionTokens) ?? 0 }
|
|
9751
10153
|
};
|
|
@@ -9754,13 +10156,10 @@ function buildCommonOutputs(requestMessages, response, structuredOutput, functio
|
|
|
9754
10156
|
type: "object[]",
|
|
9755
10157
|
value: functionCalls.map(toFunctionCallOutputValue)
|
|
9756
10158
|
};
|
|
9757
|
-
} else if (
|
|
9758
|
-
outputs["function-calls"] =
|
|
9759
|
-
type: "control-flow-excluded",
|
|
9760
|
-
value: void 0
|
|
9761
|
-
};
|
|
10159
|
+
} else if (includeFunctionCalls) {
|
|
10160
|
+
outputs["function-calls"] = createControlFlowExcludedOutput();
|
|
9762
10161
|
}
|
|
9763
|
-
if (
|
|
10162
|
+
if (outputUsage) {
|
|
9764
10163
|
outputs["usage"] = {
|
|
9765
10164
|
type: "object",
|
|
9766
10165
|
value: usage ?? {
|
|
@@ -9773,76 +10172,53 @@ function buildCommonOutputs(requestMessages, response, structuredOutput, functio
|
|
|
9773
10172
|
}
|
|
9774
10173
|
};
|
|
9775
10174
|
}
|
|
9776
|
-
if (
|
|
9777
|
-
outputs["reasoning"] =
|
|
10175
|
+
if (outputReasoning) {
|
|
10176
|
+
outputs["reasoning"] = createChatV2ReasoningOutput(reasoning);
|
|
9778
10177
|
}
|
|
9779
|
-
if (
|
|
9780
|
-
if (
|
|
9781
|
-
outputs[
|
|
10178
|
+
if (outputRequestStatus) {
|
|
10179
|
+
if (retryOnNon200) {
|
|
10180
|
+
outputs[CHAT_V2_REQUEST_STATUS_PORT_ID] = createChatV2RetryAttemptOutput(
|
|
9782
10181
|
"number[]",
|
|
9783
10182
|
requestStatuses.length > 0 ? requestStatuses : [requestStatus ?? 200]
|
|
9784
10183
|
);
|
|
9785
|
-
outputs[
|
|
10184
|
+
outputs[CHAT_V2_REQUEST_ERROR_PORT_ID] = createChatV2RetryAttemptOutput("string[]", requestErrors);
|
|
9786
10185
|
} else {
|
|
9787
|
-
outputs[
|
|
10186
|
+
outputs[CHAT_V2_REQUEST_STATUS_PORT_ID] = {
|
|
9788
10187
|
type: "number",
|
|
9789
10188
|
value: requestStatus ?? 200
|
|
9790
10189
|
};
|
|
9791
|
-
outputs[
|
|
10190
|
+
outputs[CHAT_V2_REQUEST_ERROR_PORT_ID] = responseError != null ? {
|
|
9792
10191
|
type: "string",
|
|
9793
10192
|
value: responseError
|
|
9794
|
-
} :
|
|
9795
|
-
type: "control-flow-excluded",
|
|
9796
|
-
value: void 0
|
|
9797
|
-
};
|
|
10193
|
+
} : createControlFlowExcludedOutput();
|
|
9798
10194
|
}
|
|
9799
10195
|
}
|
|
9800
10196
|
return outputs;
|
|
9801
10197
|
}
|
|
9802
|
-
function
|
|
9803
|
-
|
|
9804
|
-
|
|
9805
|
-
|
|
9806
|
-
|
|
9807
|
-
|
|
9808
|
-
|
|
9809
|
-
|
|
9810
|
-
|
|
9811
|
-
|
|
9812
|
-
|
|
9813
|
-
const
|
|
9814
|
-
|
|
9815
|
-
type: "string",
|
|
9816
|
-
value: reasoningText
|
|
9817
|
-
} : {
|
|
9818
|
-
type: "control-flow-excluded",
|
|
9819
|
-
value: void 0
|
|
9820
|
-
};
|
|
9821
|
-
}
|
|
9822
|
-
function getProviderFailureMessage(error) {
|
|
9823
|
-
if (error instanceof Error) {
|
|
9824
|
-
return error.message;
|
|
9825
|
-
}
|
|
9826
|
-
return String(error);
|
|
9827
|
-
}
|
|
9828
|
-
function buildProviderFailureOutputs(requestMessages, responseStatus, responseError, requestStatuses, requestErrors, options2) {
|
|
9829
|
-
const outputs = {};
|
|
9830
|
-
Object.assign(outputs, {
|
|
9831
|
-
[REQUEST_ERROR_PORT_ID]: options2.retryOnNon200 ? buildRetryAttemptOutput("string[]", requestErrors) : {
|
|
10198
|
+
function createChatV2ProviderFailureOutputs({
|
|
10199
|
+
requestMessages,
|
|
10200
|
+
responseStatus,
|
|
10201
|
+
responseError,
|
|
10202
|
+
requestStatuses,
|
|
10203
|
+
requestErrors,
|
|
10204
|
+
outputUsage,
|
|
10205
|
+
outputReasoning,
|
|
10206
|
+
includeFunctionCalls,
|
|
10207
|
+
retryOnNon200
|
|
10208
|
+
}) {
|
|
10209
|
+
const outputs = {
|
|
10210
|
+
[CHAT_V2_REQUEST_ERROR_PORT_ID]: retryOnNon200 ? createChatV2RetryAttemptOutput("string[]", requestErrors) : {
|
|
9832
10211
|
type: "string",
|
|
9833
10212
|
value: responseError
|
|
9834
10213
|
},
|
|
9835
|
-
[
|
|
10214
|
+
[CHAT_V2_REQUEST_STATUS_PORT_ID]: retryOnNon200 ? createChatV2RetryAttemptOutput("number[]", requestStatuses) : responseStatus == null ? {
|
|
9836
10215
|
type: "control-flow-excluded",
|
|
9837
10216
|
value: void 0
|
|
9838
10217
|
} : {
|
|
9839
10218
|
type: "number",
|
|
9840
10219
|
value: responseStatus
|
|
9841
10220
|
},
|
|
9842
|
-
["response"]:
|
|
9843
|
-
type: "control-flow-excluded",
|
|
9844
|
-
value: void 0
|
|
9845
|
-
},
|
|
10221
|
+
["response"]: createControlFlowExcludedOutput(),
|
|
9846
10222
|
["in-messages"]: {
|
|
9847
10223
|
type: "chat-message[]",
|
|
9848
10224
|
value: requestMessages
|
|
@@ -9851,39 +10227,38 @@ function buildProviderFailureOutputs(requestMessages, responseStatus, responseEr
|
|
|
9851
10227
|
type: "chat-message[]",
|
|
9852
10228
|
value: requestMessages
|
|
9853
10229
|
},
|
|
9854
|
-
["responseTokens"]:
|
|
9855
|
-
|
|
9856
|
-
|
|
9857
|
-
|
|
9858
|
-
});
|
|
9859
|
-
if (options2.includeFunctionCalls) {
|
|
9860
|
-
outputs["function-calls"] = {
|
|
9861
|
-
type: "control-flow-excluded",
|
|
9862
|
-
value: void 0
|
|
9863
|
-
};
|
|
10230
|
+
["responseTokens"]: createControlFlowExcludedOutput()
|
|
10231
|
+
};
|
|
10232
|
+
if (includeFunctionCalls) {
|
|
10233
|
+
outputs["function-calls"] = createControlFlowExcludedOutput();
|
|
9864
10234
|
}
|
|
9865
|
-
if (
|
|
9866
|
-
outputs["usage"] =
|
|
9867
|
-
type: "control-flow-excluded",
|
|
9868
|
-
value: void 0
|
|
9869
|
-
};
|
|
10235
|
+
if (outputUsage) {
|
|
10236
|
+
outputs["usage"] = createControlFlowExcludedOutput();
|
|
9870
10237
|
}
|
|
9871
|
-
if (
|
|
9872
|
-
outputs["reasoning"] =
|
|
9873
|
-
type: "control-flow-excluded",
|
|
9874
|
-
value: void 0
|
|
9875
|
-
};
|
|
10238
|
+
if (outputReasoning) {
|
|
10239
|
+
outputs["reasoning"] = createControlFlowExcludedOutput();
|
|
9876
10240
|
}
|
|
9877
10241
|
return outputs;
|
|
9878
10242
|
}
|
|
9879
|
-
|
|
9880
|
-
|
|
9881
|
-
|
|
9882
|
-
|
|
9883
|
-
|
|
9884
|
-
|
|
9885
|
-
|
|
9886
|
-
|
|
10243
|
+
|
|
10244
|
+
// src/model/chat-v2/chatV2Pipeline.ts
|
|
10245
|
+
var StreamChatV2RetryFailure = class extends Error {
|
|
10246
|
+
constructor(error, requestStatuses, requestErrors) {
|
|
10247
|
+
super("Chat v2 retry attempts failed");
|
|
10248
|
+
this.error = error;
|
|
10249
|
+
this.requestStatuses = requestStatuses;
|
|
10250
|
+
this.requestErrors = requestErrors;
|
|
10251
|
+
this.name = "StreamChatV2RetryFailure";
|
|
10252
|
+
}
|
|
10253
|
+
};
|
|
10254
|
+
function isStreamChatV2RetryFailure(error) {
|
|
10255
|
+
return error instanceof StreamChatV2RetryFailure;
|
|
10256
|
+
}
|
|
10257
|
+
function getProviderFailureMessage(error) {
|
|
10258
|
+
if (error instanceof Error) {
|
|
10259
|
+
return error.message;
|
|
10260
|
+
}
|
|
10261
|
+
return String(error);
|
|
9887
10262
|
}
|
|
9888
10263
|
function buildNon200StatusError(statusCode) {
|
|
9889
10264
|
const error = new Error(`Provider request returned non-200 status: ${statusCode}`);
|
|
@@ -9948,19 +10323,17 @@ function buildProviderFailureResult(requestMessages, options2, normalizedError,
|
|
|
9948
10323
|
const responseError = getProviderFailureMessage(normalizedError);
|
|
9949
10324
|
const retryRequestStatuses = options2.retryOnNon200 ? requestStatuses.length > 0 ? requestStatuses : statusCode == null ? [] : [statusCode] : [];
|
|
9950
10325
|
const retryRequestErrors = options2.retryOnNon200 ? requestErrors.length > 0 ? requestErrors : [responseError] : [];
|
|
9951
|
-
const commonOutputs =
|
|
10326
|
+
const commonOutputs = createChatV2ProviderFailureOutputs({
|
|
9952
10327
|
requestMessages,
|
|
9953
|
-
statusCode,
|
|
10328
|
+
responseStatus: statusCode,
|
|
9954
10329
|
responseError,
|
|
9955
|
-
retryRequestStatuses,
|
|
9956
|
-
retryRequestErrors,
|
|
9957
|
-
|
|
9958
|
-
|
|
9959
|
-
|
|
9960
|
-
|
|
9961
|
-
|
|
9962
|
-
}
|
|
9963
|
-
);
|
|
10330
|
+
requestStatuses: retryRequestStatuses,
|
|
10331
|
+
requestErrors: retryRequestErrors,
|
|
10332
|
+
outputUsage: options2.outputUsage,
|
|
10333
|
+
outputReasoning: options2.outputReasoning,
|
|
10334
|
+
includeFunctionCalls: options2.includeFunctionCalls,
|
|
10335
|
+
retryOnNon200: options2.retryOnNon200
|
|
10336
|
+
});
|
|
9964
10337
|
const allMessagesOutput = commonOutputs["all-messages"];
|
|
9965
10338
|
if ((allMessagesOutput == null ? void 0 : allMessagesOutput.type) !== "chat-message[]") {
|
|
9966
10339
|
throw new Error("Chat v2 provider failure expected all-messages output to be chat-message[].");
|
|
@@ -10013,27 +10386,25 @@ async function runChatV2Pipeline(options2) {
|
|
|
10013
10386
|
var _a, _b;
|
|
10014
10387
|
(_b = (_a = options2.context).onPartialOutputs) == null ? void 0 : _b.call(
|
|
10015
10388
|
_a,
|
|
10016
|
-
|
|
10389
|
+
createChatV2CommonOutputs({
|
|
10017
10390
|
requestMessages,
|
|
10018
|
-
text,
|
|
10019
|
-
void 0,
|
|
10391
|
+
response: text,
|
|
10392
|
+
structuredOutput: void 0,
|
|
10020
10393
|
functionCalls,
|
|
10021
|
-
void 0,
|
|
10022
|
-
"",
|
|
10023
|
-
void 0,
|
|
10024
|
-
void 0,
|
|
10025
|
-
[],
|
|
10026
|
-
[],
|
|
10027
|
-
|
|
10028
|
-
|
|
10029
|
-
|
|
10030
|
-
|
|
10031
|
-
|
|
10032
|
-
|
|
10033
|
-
|
|
10034
|
-
|
|
10035
|
-
}
|
|
10036
|
-
)
|
|
10394
|
+
usage: void 0,
|
|
10395
|
+
reasoning: "",
|
|
10396
|
+
requestStatus: void 0,
|
|
10397
|
+
responseError: void 0,
|
|
10398
|
+
requestStatuses: [],
|
|
10399
|
+
requestErrors: [],
|
|
10400
|
+
outputUsage: false,
|
|
10401
|
+
outputReasoning: false,
|
|
10402
|
+
outputRequestStatus: false,
|
|
10403
|
+
includeFunctionCalls: options2.includeFunctionCalls,
|
|
10404
|
+
functionCallMode: options2.functionCallMode,
|
|
10405
|
+
retryOnNon200: false,
|
|
10406
|
+
responseFormat: void 0
|
|
10407
|
+
})
|
|
10037
10408
|
);
|
|
10038
10409
|
}
|
|
10039
10410
|
},
|
|
@@ -10063,31 +10434,29 @@ async function runChatV2Pipeline(options2) {
|
|
|
10063
10434
|
if ("commonOutputs" in streamed) {
|
|
10064
10435
|
return streamed;
|
|
10065
10436
|
}
|
|
10066
|
-
const usage =
|
|
10437
|
+
const usage = normalizeChatV2Usage(streamed.result.usage, options2);
|
|
10067
10438
|
const requestStatuses = streamed.requestStatuses;
|
|
10068
10439
|
const requestErrors = normalizeProviderFailureMessages(streamed.requestErrors, options2);
|
|
10069
10440
|
const responseError = streamed.responseError ? normalizeProviderFailureMessage(streamed.responseError, options2) : void 0;
|
|
10070
|
-
const commonOutputs =
|
|
10441
|
+
const commonOutputs = createChatV2CommonOutputs({
|
|
10071
10442
|
requestMessages,
|
|
10072
|
-
streamed.result.responseText,
|
|
10073
|
-
streamed.result.structuredOutput,
|
|
10074
|
-
streamed.result.functionCalls,
|
|
10443
|
+
response: streamed.result.responseText,
|
|
10444
|
+
structuredOutput: streamed.result.structuredOutput,
|
|
10445
|
+
functionCalls: streamed.result.functionCalls,
|
|
10075
10446
|
usage,
|
|
10076
|
-
streamed.result.reasoning,
|
|
10077
|
-
streamed.result.requestStatus,
|
|
10447
|
+
reasoning: streamed.result.reasoning,
|
|
10448
|
+
requestStatus: streamed.result.requestStatus,
|
|
10078
10449
|
responseError,
|
|
10079
10450
|
requestStatuses,
|
|
10080
10451
|
requestErrors,
|
|
10081
|
-
|
|
10082
|
-
|
|
10083
|
-
|
|
10084
|
-
|
|
10085
|
-
|
|
10086
|
-
|
|
10087
|
-
|
|
10088
|
-
|
|
10089
|
-
}
|
|
10090
|
-
);
|
|
10452
|
+
outputUsage: options2.outputUsage,
|
|
10453
|
+
outputReasoning: options2.outputReasoning,
|
|
10454
|
+
outputRequestStatus: options2.outputRequestStatus,
|
|
10455
|
+
includeFunctionCalls: options2.includeFunctionCalls,
|
|
10456
|
+
functionCallMode: options2.functionCallMode,
|
|
10457
|
+
retryOnNon200: options2.retryOnNon200,
|
|
10458
|
+
responseFormat: options2.responseFormat
|
|
10459
|
+
});
|
|
10091
10460
|
const allMessagesOutput = commonOutputs["all-messages"];
|
|
10092
10461
|
if ((allMessagesOutput == null ? void 0 : allMessagesOutput.type) !== "chat-message[]") {
|
|
10093
10462
|
throw new Error("Chat v2 pipeline expected all-messages output to be chat-message[].");
|
|
@@ -10220,7 +10589,7 @@ async function runChatV2PipelineWithToolContinuation(options2) {
|
|
|
10220
10589
|
}
|
|
10221
10590
|
|
|
10222
10591
|
// src/model/nodes/toolCallDelegation.ts
|
|
10223
|
-
var
|
|
10592
|
+
var import_lodash_es7 = require("lodash");
|
|
10224
10593
|
function isDelegatedToolCallRecord(input) {
|
|
10225
10594
|
const maybeRecord = input;
|
|
10226
10595
|
const maybeMessage = maybeRecord == null ? void 0 : maybeRecord.message;
|
|
@@ -10308,7 +10677,7 @@ async function delegateToolCall(rawFunctionCall, context, config) {
|
|
|
10308
10677
|
const externalFunction = context.externalFunctions[functionCall.name];
|
|
10309
10678
|
if (externalFunction) {
|
|
10310
10679
|
try {
|
|
10311
|
-
const externalContext = (0,
|
|
10680
|
+
const externalContext = (0, import_lodash_es7.omit)(context, ["setGlobal"]);
|
|
10312
10681
|
const result = await externalFunction(externalContext, functionCall.arguments ?? {});
|
|
10313
10682
|
const outputString2 = stringifyToolOutput(result);
|
|
10314
10683
|
return {
|
|
@@ -11061,9 +11430,8 @@ function escapeRegExp(value) {
|
|
|
11061
11430
|
function sanitizeSourceUrlPart(value) {
|
|
11062
11431
|
return String(value).replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
11063
11432
|
}
|
|
11064
|
-
function buildCodeNodeSourceUrl(nodeId
|
|
11065
|
-
|
|
11066
|
-
return `rivet-code-node-${sanitizeSourceUrlPart(nodeId)}${processPart}.js`;
|
|
11433
|
+
function buildCodeNodeSourceUrl(nodeId) {
|
|
11434
|
+
return `rivet-code-node-${sanitizeSourceUrlPart(nodeId)}.js`;
|
|
11067
11435
|
}
|
|
11068
11436
|
function appendCodeNodeSourceUrl(code, sourceUrl) {
|
|
11069
11437
|
return `${code}
|
|
@@ -11320,7 +11688,7 @@ var CodeNodeImpl = class extends NodeImpl {
|
|
|
11320
11688
|
};
|
|
11321
11689
|
}
|
|
11322
11690
|
async process(inputs, context) {
|
|
11323
|
-
const sourceUrl = buildCodeNodeSourceUrl(this.chartNode.id
|
|
11691
|
+
const sourceUrl = buildCodeNodeSourceUrl(this.chartNode.id);
|
|
11324
11692
|
let outputs;
|
|
11325
11693
|
try {
|
|
11326
11694
|
outputs = await context.codeRunner.runCode(
|
|
@@ -11770,7 +12138,7 @@ var CodeNewNodeImpl = class extends NodeImpl {
|
|
|
11770
12138
|
};
|
|
11771
12139
|
}
|
|
11772
12140
|
async process(inputs, context) {
|
|
11773
|
-
const sourceUrl = buildCodeNodeSourceUrl(this.chartNode.id
|
|
12141
|
+
const sourceUrl = buildCodeNodeSourceUrl(this.chartNode.id);
|
|
11774
12142
|
const interpolationContext = getJsValueInterpolationRuntimeContext(this.data.code, CODE_NEW_INPUTS_IDENTIFIER);
|
|
11775
12143
|
const { inputNames, inputsIdentifier } = interpolationContext;
|
|
11776
12144
|
const { source, userCodeLineOffset } = buildCodeNewWrapper(this.data.code, interpolationContext);
|
|
@@ -13253,7 +13621,7 @@ var subGraphNode = nodeDefinition(SubGraphNodeImpl, "Subgraph");
|
|
|
13253
13621
|
|
|
13254
13622
|
// src/model/nodes/ArrayNode.ts
|
|
13255
13623
|
var import_non_secure23 = require("nanoid/non-secure");
|
|
13256
|
-
var
|
|
13624
|
+
var import_lodash_es8 = require("lodash");
|
|
13257
13625
|
var import_ts_dedent21 = require("ts-dedent");
|
|
13258
13626
|
var ArrayNodeImpl = class extends NodeImpl {
|
|
13259
13627
|
static create() {
|
|
@@ -13359,7 +13727,7 @@ var ArrayNodeImpl = class extends NodeImpl {
|
|
|
13359
13727
|
if (Array.isArray(input == null ? void 0 : input.value)) {
|
|
13360
13728
|
for (const value of (input == null ? void 0 : input.value) ?? []) {
|
|
13361
13729
|
if (this.data.flattenDeep) {
|
|
13362
|
-
outputArray.push(...Array.isArray(value) ? (0,
|
|
13730
|
+
outputArray.push(...Array.isArray(value) ? (0, import_lodash_es8.flattenDeep)(value) : [value]);
|
|
13363
13731
|
} else {
|
|
13364
13732
|
outputArray.push(value);
|
|
13365
13733
|
}
|
|
@@ -13516,7 +13884,7 @@ function createMatchedOutput(value) {
|
|
|
13516
13884
|
|
|
13517
13885
|
// src/model/nodes/AssemblePromptNode.ts
|
|
13518
13886
|
var import_non_secure25 = require("nanoid/non-secure");
|
|
13519
|
-
var
|
|
13887
|
+
var import_lodash_es9 = require("lodash");
|
|
13520
13888
|
var import_ts_dedent23 = require("ts-dedent");
|
|
13521
13889
|
var AssemblePromptNodeImpl = class extends NodeImpl {
|
|
13522
13890
|
static create() {
|
|
@@ -13623,7 +13991,7 @@ var AssemblePromptNodeImpl = class extends NodeImpl {
|
|
|
13623
13991
|
const output = {};
|
|
13624
13992
|
const isLastMessageCacheBreakpoint = getInputOrData(this.data, inputs, "isLastMessageCacheBreakpoint", "boolean");
|
|
13625
13993
|
const outMessages = [];
|
|
13626
|
-
const inputMessages = (0,
|
|
13994
|
+
const inputMessages = (0, import_lodash_es9.orderBy)(
|
|
13627
13995
|
Object.entries(inputs).filter(([key]) => key.startsWith("message")),
|
|
13628
13996
|
([key]) => key,
|
|
13629
13997
|
"asc"
|
|
@@ -14177,7 +14545,7 @@ var trimChatMessagesNode = nodeDefinition(TrimChatMessagesNodeImpl, "Trim Chat M
|
|
|
14177
14545
|
|
|
14178
14546
|
// src/model/nodes/ExternalCallNode.ts
|
|
14179
14547
|
var import_non_secure29 = require("nanoid/non-secure");
|
|
14180
|
-
var
|
|
14548
|
+
var import_lodash_es10 = require("lodash");
|
|
14181
14549
|
var import_ts_dedent27 = require("ts-dedent");
|
|
14182
14550
|
var ExternalCallNodeImpl = class extends NodeImpl {
|
|
14183
14551
|
static create() {
|
|
@@ -14272,7 +14640,7 @@ var ExternalCallNodeImpl = class extends NodeImpl {
|
|
|
14272
14640
|
}
|
|
14273
14641
|
}
|
|
14274
14642
|
const fn = context.externalFunctions[functionName];
|
|
14275
|
-
const externalContext = (0,
|
|
14643
|
+
const externalContext = (0, import_lodash_es10.omit)(context, ["setGlobal"]);
|
|
14276
14644
|
if (!fn) {
|
|
14277
14645
|
if (this.data.useErrorOutput) {
|
|
14278
14646
|
return {
|
|
@@ -16461,7 +16829,7 @@ var joinNode = nodeDefinition(JoinNodeImpl, "Coalesce");
|
|
|
16461
16829
|
|
|
16462
16830
|
// src/model/nodes/FilterNode.ts
|
|
16463
16831
|
var import_non_secure50 = require("nanoid/non-secure");
|
|
16464
|
-
var
|
|
16832
|
+
var import_lodash_es11 = require("lodash");
|
|
16465
16833
|
var import_ts_dedent48 = require("ts-dedent");
|
|
16466
16834
|
var FilterNodeImpl = class extends NodeImpl {
|
|
16467
16835
|
static create() {
|
|
@@ -16517,7 +16885,7 @@ var FilterNodeImpl = class extends NodeImpl {
|
|
|
16517
16885
|
var _a;
|
|
16518
16886
|
const array = coerceType(inputs["array"], "any[]");
|
|
16519
16887
|
const include = coerceType(inputs["include"], "boolean[]");
|
|
16520
|
-
const zipped = (0,
|
|
16888
|
+
const zipped = (0, import_lodash_es11.zip)(array, include);
|
|
16521
16889
|
const filtered = zipped.filter(([_, include2]) => include2).map(([value, _]) => value);
|
|
16522
16890
|
return {
|
|
16523
16891
|
["filtered"]: {
|
|
@@ -17120,7 +17488,7 @@ var booleanNode = nodeDefinition(BooleanNodeImpl, "Boolean");
|
|
|
17120
17488
|
|
|
17121
17489
|
// src/model/nodes/CompareNode.ts
|
|
17122
17490
|
var import_non_secure55 = require("nanoid/non-secure");
|
|
17123
|
-
var
|
|
17491
|
+
var import_lodash_es12 = require("lodash");
|
|
17124
17492
|
var import_ts_pattern5 = require("ts-pattern");
|
|
17125
17493
|
var import_ts_dedent54 = require("ts-dedent");
|
|
17126
17494
|
var CompareNodeImpl = class extends NodeImpl {
|
|
@@ -17233,7 +17601,7 @@ var CompareNodeImpl = class extends NodeImpl {
|
|
|
17233
17601
|
return {
|
|
17234
17602
|
["output"]: {
|
|
17235
17603
|
type: "boolean",
|
|
17236
|
-
value: (0, import_ts_pattern5.match)(comparisonFunction).with("==", () => (0,
|
|
17604
|
+
value: (0, import_ts_pattern5.match)(comparisonFunction).with("==", () => (0, import_lodash_es12.isEqual)(value1, value2)).with("!=", () => !(0, import_lodash_es12.isEqual)(value1, value2)).with("<", () => compareValues(value1, value2)["<"]).with(">", () => compareValues(value1, value2)[">"]).with("<=", () => compareValues(value1, value2)["<="]).with(">=", () => compareValues(value1, value2)[">="]).with("and", () => !!(value1 && value2)).with("or", () => !!(value1 || value2)).with("xor", () => !!(value1 ? !value2 : value2)).with("nand", () => !(value1 && value2)).with("nor", () => !(value1 || value2)).with("xnor", () => !(value1 ? !value2 : value2)).exhaustive()
|
|
17237
17605
|
}
|
|
17238
17606
|
};
|
|
17239
17607
|
}
|
|
@@ -17553,7 +17921,7 @@ var randomNumberNode = nodeDefinition(RandomNumberNodeImpl, "Random number");
|
|
|
17553
17921
|
|
|
17554
17922
|
// src/model/nodes/ShuffleNode.ts
|
|
17555
17923
|
var import_non_secure59 = require("nanoid/non-secure");
|
|
17556
|
-
var
|
|
17924
|
+
var import_lodash_es13 = require("lodash");
|
|
17557
17925
|
var import_ts_dedent58 = require("ts-dedent");
|
|
17558
17926
|
var ShuffleNodeImpl = class extends NodeImpl {
|
|
17559
17927
|
static create() {
|
|
@@ -17602,7 +17970,7 @@ var ShuffleNodeImpl = class extends NodeImpl {
|
|
|
17602
17970
|
var _a;
|
|
17603
17971
|
const input = inputs["array"];
|
|
17604
17972
|
const items = input ? isArrayDataValue(input) ? input.value : [input.value] : [];
|
|
17605
|
-
const shuffled = (0,
|
|
17973
|
+
const shuffled = (0, import_lodash_es13.shuffle)(items);
|
|
17606
17974
|
return {
|
|
17607
17975
|
["shuffled"]: {
|
|
17608
17976
|
type: ((_a = inputs["array"]) == null ? void 0 : _a.type) ?? "any[]",
|
|
@@ -17950,7 +18318,7 @@ function recordHttpCallThrownAttempt(attempts, error, signal) {
|
|
|
17950
18318
|
attempts.requestFailedValues.push(true);
|
|
17951
18319
|
attempts.requestErrorMessages.push(formatCaughtRequestFailureError(error));
|
|
17952
18320
|
}
|
|
17953
|
-
function
|
|
18321
|
+
function buildRetryAttemptOutput(type, values2) {
|
|
17954
18322
|
return values2.length > 0 ? {
|
|
17955
18323
|
type,
|
|
17956
18324
|
value: values2
|
|
@@ -18025,7 +18393,7 @@ async function waitForRetryCooldown(cooldownMs, signal) {
|
|
|
18025
18393
|
}
|
|
18026
18394
|
function buildRequestFailedOutputs(params) {
|
|
18027
18395
|
const sharedOutputs = {
|
|
18028
|
-
[STATUS_CODE_OUTPUT_ID]: params.retryOnNon200 ?
|
|
18396
|
+
[STATUS_CODE_OUTPUT_ID]: params.retryOnNon200 ? buildRetryAttemptOutput("number[]", params.attempts.statusCodeValues) : {
|
|
18029
18397
|
type: "control-flow-excluded",
|
|
18030
18398
|
value: void 0
|
|
18031
18399
|
},
|
|
@@ -18058,11 +18426,11 @@ function buildRequestFailedOutputs(params) {
|
|
|
18058
18426
|
function buildCaughtRequestFailedResult(params) {
|
|
18059
18427
|
const attempts = params.retryOnNon200 ? withCaughtFailureAttemptFallback(params.attempts, params.error) : params.attempts;
|
|
18060
18428
|
const outputs = {
|
|
18061
|
-
[REQUEST_ERROR_OUTPUT_ID]: params.retryOnNon200 ?
|
|
18429
|
+
[REQUEST_ERROR_OUTPUT_ID]: params.retryOnNon200 ? buildRetryAttemptOutput("string[]", attempts.requestErrorMessages) : {
|
|
18062
18430
|
type: "string",
|
|
18063
18431
|
value: formatCaughtRequestFailureError(params.error)
|
|
18064
18432
|
},
|
|
18065
|
-
[REQUEST_FAILED_OUTPUT_ID]: params.retryOnNon200 ?
|
|
18433
|
+
[REQUEST_FAILED_OUTPUT_ID]: params.retryOnNon200 ? buildRetryAttemptOutput("boolean[]", attempts.requestFailedValues) : {
|
|
18066
18434
|
type: "boolean",
|
|
18067
18435
|
value: true
|
|
18068
18436
|
},
|
|
@@ -18307,7 +18675,7 @@ var HttpCallNodeImpl = class extends NodeImpl {
|
|
|
18307
18675
|
}
|
|
18308
18676
|
async process(inputs, context) {
|
|
18309
18677
|
var _a;
|
|
18310
|
-
const requestAttempts = createHttpCallRequestAttempts();
|
|
18678
|
+
const requestAttempts = this.data.retryOnNon200 ? createHttpCallRequestAttempts() : void 0;
|
|
18311
18679
|
try {
|
|
18312
18680
|
const method = getInputOrData(this.data, inputs, "method", "string");
|
|
18313
18681
|
const url = getInputOrData(this.data, inputs, "url", "string");
|
|
@@ -18365,7 +18733,7 @@ var HttpCallNodeImpl = class extends NodeImpl {
|
|
|
18365
18733
|
throw err;
|
|
18366
18734
|
}
|
|
18367
18735
|
};
|
|
18368
|
-
const performTrackedRequest = async () => {
|
|
18736
|
+
const performTrackedRequest = requestAttempts ? async () => {
|
|
18369
18737
|
try {
|
|
18370
18738
|
const response2 = await performRequest();
|
|
18371
18739
|
recordHttpCallResponseAttempt(requestAttempts, response2);
|
|
@@ -18374,9 +18742,9 @@ var HttpCallNodeImpl = class extends NodeImpl {
|
|
|
18374
18742
|
recordHttpCallThrownAttempt(requestAttempts, error, context.signal);
|
|
18375
18743
|
throw error;
|
|
18376
18744
|
}
|
|
18377
|
-
};
|
|
18745
|
+
} : performRequest;
|
|
18378
18746
|
let response = await performTrackedRequest();
|
|
18379
|
-
if (
|
|
18747
|
+
if (requestAttempts) {
|
|
18380
18748
|
const repeatTimes = normalizeHttpRetryCount(this.data.retryOnNon200RepeatTimes);
|
|
18381
18749
|
const cooldownMs = normalizeHttpRetryCooldownMs(this.data.retryOnNon200CooldownMs);
|
|
18382
18750
|
for (let attempt = 0; response.status !== 200 && attempt < repeatTimes; attempt++) {
|
|
@@ -18388,7 +18756,7 @@ var HttpCallNodeImpl = class extends NodeImpl {
|
|
|
18388
18756
|
throw buildNon2xxStatusCodeError(response.status);
|
|
18389
18757
|
}
|
|
18390
18758
|
const output = {
|
|
18391
|
-
[STATUS_CODE_OUTPUT_ID]:
|
|
18759
|
+
[STATUS_CODE_OUTPUT_ID]: requestAttempts ? buildRetryAttemptOutput("number[]", requestAttempts.statusCodeValues) : {
|
|
18392
18760
|
type: "number",
|
|
18393
18761
|
value: response.status
|
|
18394
18762
|
},
|
|
@@ -18422,12 +18790,12 @@ var HttpCallNodeImpl = class extends NodeImpl {
|
|
|
18422
18790
|
};
|
|
18423
18791
|
}
|
|
18424
18792
|
}
|
|
18425
|
-
if (this.data.catchRequestFailed ||
|
|
18426
|
-
output[REQUEST_FAILED_OUTPUT_ID] =
|
|
18793
|
+
if (this.data.catchRequestFailed || requestAttempts) {
|
|
18794
|
+
output[REQUEST_FAILED_OUTPUT_ID] = requestAttempts ? buildRetryAttemptOutput("boolean[]", requestAttempts.requestFailedValues) : {
|
|
18427
18795
|
type: "boolean",
|
|
18428
18796
|
value: false
|
|
18429
18797
|
};
|
|
18430
|
-
output[REQUEST_ERROR_OUTPUT_ID] =
|
|
18798
|
+
output[REQUEST_ERROR_OUTPUT_ID] = requestAttempts ? buildRetryAttemptOutput("string[]", requestAttempts.requestErrorMessages) : {
|
|
18431
18799
|
type: "control-flow-excluded",
|
|
18432
18800
|
value: void 0
|
|
18433
18801
|
};
|
|
@@ -18438,8 +18806,8 @@ var HttpCallNodeImpl = class extends NodeImpl {
|
|
|
18438
18806
|
return buildCaughtRequestFailedResult({
|
|
18439
18807
|
isBinaryOutput: Boolean(this.data.isBinaryOutput),
|
|
18440
18808
|
error,
|
|
18441
|
-
retryOnNon200:
|
|
18442
|
-
attempts: requestAttempts
|
|
18809
|
+
retryOnNon200: requestAttempts != null,
|
|
18810
|
+
attempts: requestAttempts ?? createHttpCallRequestAttempts()
|
|
18443
18811
|
});
|
|
18444
18812
|
}
|
|
18445
18813
|
throw error;
|
|
@@ -19356,7 +19724,7 @@ var extractMarkdownCodeBlocksNode = nodeDefinition(
|
|
|
19356
19724
|
|
|
19357
19725
|
// src/model/nodes/AssembleMessageNode.ts
|
|
19358
19726
|
var import_non_secure68 = require("nanoid/non-secure");
|
|
19359
|
-
var
|
|
19727
|
+
var import_lodash_es14 = require("lodash");
|
|
19360
19728
|
var import_ts_pattern7 = require("ts-pattern");
|
|
19361
19729
|
var messageTypeToTitle = {
|
|
19362
19730
|
assistant: "Assistant",
|
|
@@ -19513,7 +19881,7 @@ var AssembleMessageNodeImpl = class extends NodeImpl {
|
|
|
19513
19881
|
).otherwise(() => {
|
|
19514
19882
|
throw new Error(`Invalid type: ${type}`);
|
|
19515
19883
|
});
|
|
19516
|
-
const inputParts = (0,
|
|
19884
|
+
const inputParts = (0, import_lodash_es14.orderBy)(
|
|
19517
19885
|
Object.entries(inputs).filter(([key]) => key.startsWith("part")),
|
|
19518
19886
|
([key]) => key,
|
|
19519
19887
|
"asc"
|
|
@@ -20047,9 +20415,9 @@ var import_non_secure73 = require("nanoid/non-secure");
|
|
|
20047
20415
|
var import_ts_dedent67 = require("ts-dedent");
|
|
20048
20416
|
|
|
20049
20417
|
// src/api/looseDataValue.ts
|
|
20050
|
-
var
|
|
20418
|
+
var import_lodash_es15 = require("lodash");
|
|
20051
20419
|
function looseDataValuesToDataValues(values2) {
|
|
20052
|
-
return (0,
|
|
20420
|
+
return (0, import_lodash_es15.mapValues)(values2, (val) => looseDataValueToDataValue(val));
|
|
20053
20421
|
}
|
|
20054
20422
|
function looseDataValueToDataValue(value) {
|
|
20055
20423
|
if (typeof value === "string") {
|
|
@@ -21289,7 +21657,7 @@ var cronNode = nodeDefinition(CronNodeImpl, "Cron");
|
|
|
21289
21657
|
// src/model/nodes/ToTreeNode.ts
|
|
21290
21658
|
var import_non_secure79 = require("nanoid/non-secure");
|
|
21291
21659
|
var import_ts_dedent73 = require("ts-dedent");
|
|
21292
|
-
var
|
|
21660
|
+
var import_lodash_es16 = require("lodash");
|
|
21293
21661
|
var ToTreeNodeImpl = class extends NodeImpl {
|
|
21294
21662
|
static create() {
|
|
21295
21663
|
const chartNode = {
|
|
@@ -21375,7 +21743,7 @@ var ToTreeNodeImpl = class extends NodeImpl {
|
|
|
21375
21743
|
if (!Array.isArray(objects) || objects.length === 0)
|
|
21376
21744
|
return "";
|
|
21377
21745
|
let result = "";
|
|
21378
|
-
const sortedObjects = this.data.useSortAlphabetically ? (0,
|
|
21746
|
+
const sortedObjects = this.data.useSortAlphabetically ? (0, import_lodash_es16.sortBy)(objects, (obj) => String((0, import_lodash_es16.get)(obj, "path", ""))) : objects;
|
|
21379
21747
|
sortedObjects.forEach((obj, index) => {
|
|
21380
21748
|
const isLastItem = index === sortedObjects.length - 1;
|
|
21381
21749
|
const prefix = level === 0 ? "" : isLast ? "\u2514\u2500\u2500 " : "\u251C\u2500\u2500 ";
|
|
@@ -21384,14 +21752,14 @@ var ToTreeNodeImpl = class extends NodeImpl {
|
|
|
21384
21752
|
const interpolationVars = matches.reduce(
|
|
21385
21753
|
(acc, match10) => {
|
|
21386
21754
|
const key = match10;
|
|
21387
|
-
acc[key] = String((0,
|
|
21755
|
+
acc[key] = String((0, import_lodash_es16.get)(obj, key, ""));
|
|
21388
21756
|
return acc;
|
|
21389
21757
|
},
|
|
21390
21758
|
{}
|
|
21391
21759
|
);
|
|
21392
21760
|
const formattedNode = interpolate(this.data.format, interpolationVars);
|
|
21393
21761
|
result += indent + prefix + formattedNode + "\n";
|
|
21394
|
-
const children = (0,
|
|
21762
|
+
const children = (0, import_lodash_es16.get)(obj, this.data.childrenProperty);
|
|
21395
21763
|
if (Array.isArray(children) && children.length > 0) {
|
|
21396
21764
|
const newPath = parentPath ? `${parentPath}/${formattedNode}` : formattedNode;
|
|
21397
21765
|
result += this.buildTree(children, newPath, level + 1, isLastItem);
|
|
@@ -22675,7 +23043,7 @@ registerIntegration("embeddingGenerator", "openai", (context) => new OpenAIEmbed
|
|
|
22675
23043
|
// src/recording/ExecutionRecorder.ts
|
|
22676
23044
|
var import_non_secure84 = require("nanoid/non-secure");
|
|
22677
23045
|
var import_emittery2 = __toESM(require("emittery-0-13"), 1);
|
|
22678
|
-
var
|
|
23046
|
+
var import_lodash_es17 = require("lodash");
|
|
22679
23047
|
var import_json_stream_es = require("json-stream-es");
|
|
22680
23048
|
|
|
22681
23049
|
// src/vendor/fnv1a.js
|
|
@@ -22836,16 +23204,16 @@ function toRecordedEvent(event, data) {
|
|
|
22836
23204
|
function mapValuesDeep(obj, fn) {
|
|
22837
23205
|
if (Array.isArray(obj)) {
|
|
22838
23206
|
return obj.map((value) => {
|
|
22839
|
-
if ((0,
|
|
23207
|
+
if ((0, import_lodash_es17.isPlainObject)(value) || Array.isArray(value)) {
|
|
22840
23208
|
return mapValuesDeep(value, fn);
|
|
22841
23209
|
}
|
|
22842
23210
|
return fn(value);
|
|
22843
23211
|
});
|
|
22844
23212
|
}
|
|
22845
|
-
if ((0,
|
|
23213
|
+
if ((0, import_lodash_es17.isPlainObject)(obj)) {
|
|
22846
23214
|
return Object.fromEntries(
|
|
22847
23215
|
Object.entries(obj).map(([key, value]) => {
|
|
22848
|
-
if ((0,
|
|
23216
|
+
if ((0, import_lodash_es17.isPlainObject)(value) || Array.isArray(value)) {
|
|
22849
23217
|
return [key, mapValuesDeep(value, fn)];
|
|
22850
23218
|
}
|
|
22851
23219
|
return [key, fn(value)];
|
|
@@ -25181,7 +25549,7 @@ var pinecone_default = pineconePlugin;
|
|
|
25181
25549
|
|
|
25182
25550
|
// src/plugins/gentrace/plugin.ts
|
|
25183
25551
|
var import_core = require("@gentrace/core");
|
|
25184
|
-
var
|
|
25552
|
+
var import_lodash_es18 = require("lodash");
|
|
25185
25553
|
|
|
25186
25554
|
// src/integrations/GptTokenizerTokenizer.ts
|
|
25187
25555
|
var import_emittery3 = __toESM(require("emittery-0-13"), 1);
|
|
@@ -25279,7 +25647,7 @@ var runGentraceTests = async (gentracePipelineSlug, settings, project, graph, na
|
|
|
25279
25647
|
slug: gentracePipelineSlug
|
|
25280
25648
|
});
|
|
25281
25649
|
const runner = pipeline.start();
|
|
25282
|
-
const rivetFormattedInputs = (0,
|
|
25650
|
+
const rivetFormattedInputs = (0, import_lodash_es18.mapValues)(testCase.inputs, inferType);
|
|
25283
25651
|
const tempProject = {
|
|
25284
25652
|
...project,
|
|
25285
25653
|
graphs: {
|
|
@@ -25291,7 +25659,7 @@ var runGentraceTests = async (gentracePipelineSlug, settings, project, graph, na
|
|
|
25291
25659
|
const processor = new GraphProcessor(tempProject, graphId, globalRivetNodeRegistry);
|
|
25292
25660
|
processor.executor = "browser";
|
|
25293
25661
|
recorder.record(processor);
|
|
25294
|
-
const runContextValues = (0,
|
|
25662
|
+
const runContextValues = (0, import_lodash_es18.cloneDeep)(contextValues);
|
|
25295
25663
|
await processor.processGraph(
|
|
25296
25664
|
{
|
|
25297
25665
|
settings,
|
|
@@ -25329,7 +25697,7 @@ var runRemoteGentraceTests = async (gentracePipelineSlug, settings, project, gra
|
|
|
25329
25697
|
slug: gentracePipelineSlug
|
|
25330
25698
|
});
|
|
25331
25699
|
const runner = pipeline.start();
|
|
25332
|
-
const rivetFormattedInputs = (0,
|
|
25700
|
+
const rivetFormattedInputs = (0, import_lodash_es18.mapValues)(testCase.inputs, inferType);
|
|
25333
25701
|
const fullRecording = await runAndRecord(rivetFormattedInputs);
|
|
25334
25702
|
const stepRuns = convertRecordingToStepRuns(fullRecording, project, graphId);
|
|
25335
25703
|
for (const stepRun of stepRuns) {
|
|
@@ -28009,7 +28377,7 @@ ${additional.join("\n")}`;
|
|
|
28009
28377
|
var runThreadNode = pluginNodeDefinition(RunThreadNodeImpl, "Run Thread");
|
|
28010
28378
|
|
|
28011
28379
|
// src/plugins/openai/nodes/ThreadMessageNode.ts
|
|
28012
|
-
var
|
|
28380
|
+
var import_lodash_es19 = require("lodash");
|
|
28013
28381
|
var ThreadMessageNodeImpl = {
|
|
28014
28382
|
create() {
|
|
28015
28383
|
return {
|
|
@@ -28132,7 +28500,7 @@ var ThreadMessageNodeImpl = {
|
|
|
28132
28500
|
if (data.useMetadataInput && inputData["metadata"]) {
|
|
28133
28501
|
metadata = coerceTypeOptional(inputData["metadata"], "object");
|
|
28134
28502
|
}
|
|
28135
|
-
const inputMap = (0,
|
|
28503
|
+
const inputMap = (0, import_lodash_es19.mapValues)(inputData, (input) => coerceType(input, "string"));
|
|
28136
28504
|
const interpolated = interpolate(text, inputMap);
|
|
28137
28505
|
return {
|
|
28138
28506
|
["message"]: {
|
|
@@ -28185,7 +28553,7 @@ var import_ts_dedent85 = require("ts-dedent");
|
|
|
28185
28553
|
var import_p_retry3 = __toESM(require("p-retry-4"), 1);
|
|
28186
28554
|
var import_ts_pattern9 = require("ts-pattern");
|
|
28187
28555
|
var import_genai2 = require("@google/genai");
|
|
28188
|
-
var
|
|
28556
|
+
var import_lodash_es20 = require("lodash");
|
|
28189
28557
|
function toGoogleSchemaType(type) {
|
|
28190
28558
|
switch (type) {
|
|
28191
28559
|
case "string":
|
|
@@ -28557,7 +28925,7 @@ var ChatGoogleNodeImpl = {
|
|
|
28557
28925
|
description: tool.description,
|
|
28558
28926
|
parameters: Object.keys(parameters.properties ?? {}).length === 0 ? void 0 : {
|
|
28559
28927
|
type: import_genai2.Type.OBJECT,
|
|
28560
|
-
properties: (0,
|
|
28928
|
+
properties: (0, import_lodash_es20.mapValues)(parameters.properties ?? {}, (property) => ({
|
|
28561
28929
|
// gemini doesn't support union property types, it uses openapi style not jsonschema, what a mess
|
|
28562
28930
|
type: toGoogleSchemaType(
|
|
28563
28931
|
Array.isArray(property.type) ? property.type.find((type) => type !== "null") : property.type
|
|
@@ -28840,7 +29208,7 @@ async function assembleRegistry(specs, loadPlugin) {
|
|
|
28840
29208
|
}
|
|
28841
29209
|
|
|
28842
29210
|
// src/integrations/DatasetProvider.ts
|
|
28843
|
-
var
|
|
29211
|
+
var import_lodash_es21 = require("lodash");
|
|
28844
29212
|
var InMemoryDatasetProvider = class {
|
|
28845
29213
|
#datasets;
|
|
28846
29214
|
constructor(datasets) {
|
|
@@ -28920,7 +29288,7 @@ var InMemoryDatasetProvider = class {
|
|
|
28920
29288
|
return sorted.slice(0, k).map((r) => ({ ...r.row, distance: r.similarity }));
|
|
28921
29289
|
}
|
|
28922
29290
|
async exportDatasetsForProject(_projectId) {
|
|
28923
|
-
return (0,
|
|
29291
|
+
return (0, import_lodash_es21.cloneDeep)(this.#datasets);
|
|
28924
29292
|
}
|
|
28925
29293
|
};
|
|
28926
29294
|
var dotProductSimilarity = (a, b) => {
|
|
@@ -29043,7 +29411,7 @@ function resolveProcessSettings(settings = {}, fallbacks = {}) {
|
|
|
29043
29411
|
}
|
|
29044
29412
|
|
|
29045
29413
|
// src/api/createProcessor.ts
|
|
29046
|
-
function coreCreateProcessor(project, options2) {
|
|
29414
|
+
function coreCreateProcessor(project, options2, internalOptions = {}) {
|
|
29047
29415
|
var _a, _b, _c;
|
|
29048
29416
|
const { graph, inputs = {}, context = {} } = options2;
|
|
29049
29417
|
const graphId = graph ? graph in project.graphs ? graph : (_b = (_a = Object.values(project.graphs).find((g) => {
|
|
@@ -29058,7 +29426,13 @@ function coreCreateProcessor(project, options2) {
|
|
|
29058
29426
|
graphId,
|
|
29059
29427
|
options2.registry ?? globalRivetNodeRegistry,
|
|
29060
29428
|
options2.includeTrace,
|
|
29061
|
-
{
|
|
29429
|
+
{
|
|
29430
|
+
cacheLoadedProjects: internalOptions.cacheLoadedProjects,
|
|
29431
|
+
concurrency: options2.concurrency,
|
|
29432
|
+
executionPlanCacheMode: internalOptions.executionPlanCacheMode,
|
|
29433
|
+
runtimeCache: internalOptions.runtimeCache,
|
|
29434
|
+
scheduler: internalOptions.scheduler
|
|
29435
|
+
}
|
|
29062
29436
|
);
|
|
29063
29437
|
if (options2.onStart) {
|
|
29064
29438
|
processor.on("start", options2.onStart);
|