@valerypopoff/rivet2-core 2.0.10 → 2.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.
Files changed (68) hide show
  1. package/dist/cjs/bundle.cjs +1762 -274
  2. package/dist/cjs/bundle.cjs.map +4 -4
  3. package/dist/esm/api/createProcessor.js +1 -0
  4. package/dist/esm/exports.js +4 -0
  5. package/dist/esm/model/GraphBoundaryCache.js +36 -4
  6. package/dist/esm/model/GraphBoundaryEffects.js +32 -0
  7. package/dist/esm/model/GraphPreprocessor.js +6 -4
  8. package/dist/esm/model/GraphProcessor.js +344 -118
  9. package/dist/esm/model/NodeGraph.js +1 -1
  10. package/dist/esm/model/NodePrefabResolver.js +57 -0
  11. package/dist/esm/model/Nodes.js +4 -1
  12. package/dist/esm/model/ProcessContextBuilder.js +3 -1
  13. package/dist/esm/model/UiGraph.js +113 -0
  14. package/dist/esm/model/UiGraphRendererStyles.js +208 -0
  15. package/dist/esm/model/chat/openAIChatRuntime.js +0 -1
  16. package/dist/esm/model/chat-v2/aiSdkBridge.js +100 -2
  17. package/dist/esm/model/chat-v2/chatV2Pipeline.js +35 -31
  18. package/dist/esm/model/chat-v2/chatV2Shared.js +1 -1
  19. package/dist/esm/model/chat-v2/providerOptions.js +5 -1
  20. package/dist/esm/model/nodes/CoalesceNode.js +1 -1
  21. package/dist/esm/model/nodes/CompareNode.js +15 -14
  22. package/dist/esm/model/nodes/GraphOutputNode.js +1 -0
  23. package/dist/esm/model/nodes/LLMChatV2Node.js +62 -17
  24. package/dist/esm/model/nodes/NodePrefabInstanceNode.js +39 -0
  25. package/dist/esm/model/nodes/PromptNode.js +2 -1
  26. package/dist/esm/model/nodes/ReferencedGraphAliasNode.js +49 -7
  27. package/dist/esm/model/nodes/SubGraphNode.js +42 -5
  28. package/dist/esm/utils/index.js +2 -0
  29. package/dist/esm/utils/jsonValueToDataValue.js +48 -0
  30. package/dist/esm/utils/projectComparison/connections.js +57 -0
  31. package/dist/esm/utils/projectComparison/graphs.js +60 -0
  32. package/dist/esm/utils/projectComparison/nodes.js +53 -0
  33. package/dist/esm/utils/projectComparison/summaries.js +60 -0
  34. package/dist/esm/utils/projectComparison/values.js +40 -0
  35. package/dist/esm/utils/projectComparison.js +73 -0
  36. package/dist/esm/utils/serialization/serializationHelpers.js +24 -3
  37. package/dist/esm/utils/serialization/serialization_v4.js +30 -0
  38. package/dist/types/api/createProcessor.d.ts +2 -1
  39. package/dist/types/exports.d.ts +5 -0
  40. package/dist/types/model/EditorDefinition.d.ts +1 -0
  41. package/dist/types/model/ExecutorProtocol.d.ts +13 -3
  42. package/dist/types/model/GraphBoundaryCache.d.ts +9 -3
  43. package/dist/types/model/GraphBoundaryEffects.d.ts +9 -0
  44. package/dist/types/model/GraphProcessor.d.ts +20 -0
  45. package/dist/types/model/NodeBase.d.ts +5 -0
  46. package/dist/types/model/NodeBodySpec.d.ts +1 -0
  47. package/dist/types/model/NodePrefabResolver.d.ts +13 -0
  48. package/dist/types/model/Nodes.d.ts +5 -4
  49. package/dist/types/model/ProcessContext.d.ts +5 -1
  50. package/dist/types/model/ProcessContextBuilder.d.ts +4 -2
  51. package/dist/types/model/Project.d.ts +9 -0
  52. package/dist/types/model/UiGraph.d.ts +84 -0
  53. package/dist/types/model/UiGraphRendererStyles.d.ts +2 -0
  54. package/dist/types/model/chat-v2/aiSdkBridge.d.ts +1 -0
  55. package/dist/types/model/chat-v2/chatV2Types.d.ts +23 -1
  56. package/dist/types/model/nodes/CompareNode.d.ts +4 -0
  57. package/dist/types/model/nodes/LLMChatV2Node.d.ts +2 -1
  58. package/dist/types/model/nodes/NodePrefabInstanceNode.d.ts +13 -0
  59. package/dist/types/model/nodes/SubGraphNode.d.ts +2 -0
  60. package/dist/types/utils/index.d.ts +2 -0
  61. package/dist/types/utils/jsonValueToDataValue.d.ts +2 -0
  62. package/dist/types/utils/projectComparison/connections.d.ts +5 -0
  63. package/dist/types/utils/projectComparison/graphs.d.ts +3 -0
  64. package/dist/types/utils/projectComparison/nodes.d.ts +5 -0
  65. package/dist/types/utils/projectComparison/summaries.d.ts +4 -0
  66. package/dist/types/utils/projectComparison/values.d.ts +5 -0
  67. package/dist/types/utils/projectComparison.d.ts +77 -0
  68. package/package.json +1 -1
@@ -23,6 +23,7 @@ export function coreCreateProcessor(project, options, internalOptions = {}) {
23
23
  concurrency: options.concurrency,
24
24
  executionPlanCacheMode: internalOptions.executionPlanCacheMode,
25
25
  runtimeCache: internalOptions.runtimeCache,
26
+ runtimeProfiler: internalOptions.runtimeProfiler,
26
27
  scheduler: internalOptions.scheduler,
27
28
  });
28
29
  if (options.onStart) {
@@ -4,6 +4,10 @@ export * from './model/GraphProcessor.js';
4
4
  export * from './model/DataValue.js';
5
5
  export * from './model/NodeBase.js';
6
6
  export * from './model/NodeGraph.js';
7
+ export * from './model/NodePrefabResolver.js';
8
+ export { getGraphBoundary } from './model/GraphBoundaryCache.js';
9
+ export * from './model/UiGraph.js';
10
+ export * from './model/UiGraphRendererStyles.js';
7
11
  export * from './model/NodeImpl.js';
8
12
  export * from './model/NodeDefinition.js';
9
13
  export * from './model/Nodes.js';
@@ -1,3 +1,4 @@
1
+ export const GRAPH_BOUNDARY_OUTPUT_DEMAND_OPTIMIZATION_ENABLED = false;
1
2
  export function getGraphBoundary(project, graphId, cache) {
2
3
  if (!graphId) {
3
4
  return undefined;
@@ -17,15 +18,40 @@ export function getGraphBoundary(project, graphId, cache) {
17
18
  cache.set(graph, boundary);
18
19
  return boundary;
19
20
  }
20
- export function getGraphBoundaryInputDefinitions(boundary) {
21
- return boundary.inputs.map((input) => ({
21
+ export function applyGraphBoundaryPortOrder(boundaryItems, portOrder) {
22
+ if (!portOrder?.length) {
23
+ return [...boundaryItems];
24
+ }
25
+ const itemsById = new Map(boundaryItems.map((item) => [item.id, item]));
26
+ const usedIds = new Set();
27
+ const orderedItems = [];
28
+ for (const id of portOrder) {
29
+ if (usedIds.has(id)) {
30
+ continue;
31
+ }
32
+ const item = itemsById.get(id);
33
+ if (!item) {
34
+ continue;
35
+ }
36
+ orderedItems.push(item);
37
+ usedIds.add(id);
38
+ }
39
+ for (const item of boundaryItems) {
40
+ if (!usedIds.has(item.id)) {
41
+ orderedItems.push(item);
42
+ }
43
+ }
44
+ return orderedItems;
45
+ }
46
+ export function getGraphBoundaryInputDefinitions(boundary, inputPortOrder) {
47
+ return applyGraphBoundaryPortOrder(boundary.inputs, inputPortOrder).map((input) => ({
22
48
  id: input.portId,
23
49
  title: input.id,
24
50
  dataType: input.dataType,
25
51
  }));
26
52
  }
27
- export function getGraphBoundaryOutputDefinitions(boundary) {
28
- return boundary.outputs.map((output) => ({
53
+ export function getGraphBoundaryOutputDefinitions(boundary, outputPortOrder) {
54
+ return applyGraphBoundaryPortOrder(boundary.outputs, outputPortOrder).map((output) => ({
29
55
  id: output.portId,
30
56
  title: output.id,
31
57
  dataType: output.dataType,
@@ -56,6 +82,11 @@ export function buildExcludedGraphBoundaryOutputs(boundary) {
56
82
  }
57
83
  return outputs;
58
84
  }
85
+ export function getRequestedGraphOutputNodeIds(boundary, requestedOutputPortIds) {
86
+ return boundary.outputs
87
+ .filter((output) => requestedOutputPortIds.has(output.portId))
88
+ .map((output) => output.nodeId);
89
+ }
59
90
  function deriveGraphBoundary(graph) {
60
91
  const inputsById = new Map();
61
92
  const outputsById = new Map();
@@ -74,6 +105,7 @@ function deriveGraphBoundary(graph) {
74
105
  outputsById.set(outputNode.data.id, {
75
106
  dataType: outputNode.data.dataType,
76
107
  id: outputNode.data.id,
108
+ nodeId: outputNode.id,
77
109
  portId: outputNode.data.id,
78
110
  });
79
111
  }
@@ -0,0 +1,32 @@
1
+ export function ensureGraphCostOutput(graphOutputs, totalCost) {
2
+ const costPort = 'cost';
3
+ if (graphOutputs[costPort] == null) {
4
+ graphOutputs[costPort] = {
5
+ type: 'number',
6
+ value: totalCost,
7
+ };
8
+ }
9
+ }
10
+ export function applyFrozenGraphBoundaryEffects(graphOutputs, node, outputValues) {
11
+ if (node.type === 'graphOutput') {
12
+ const outputId = node.data?.id;
13
+ const valueOutput = outputValues['valueOutput'];
14
+ if (outputId && valueOutput) {
15
+ graphOutputs[outputId] = valueOutput;
16
+ }
17
+ return undefined;
18
+ }
19
+ if (node.type !== 'setGlobal') {
20
+ return undefined;
21
+ }
22
+ const savedValue = outputValues['saved-value'];
23
+ const variableId = outputValues['variable_id_out'];
24
+ const variableIdValue = variableId?.type === 'string' ? variableId.value : undefined;
25
+ if (!variableIdValue || !savedValue) {
26
+ return undefined;
27
+ }
28
+ return {
29
+ variableId: variableIdValue,
30
+ value: savedValue,
31
+ };
32
+ }
@@ -1,12 +1,14 @@
1
1
  import { values } from '../utils/typeSafety.js';
2
2
  import { findStronglyConnectedComponents } from './CycleDetector.js';
3
+ import { resolveNodePrefabInstances } from './NodePrefabResolver.js';
3
4
  export function preprocessGraphState(options) {
4
5
  const { buildExecutionPlan, definitionContext, graph, loadedProjects, project, registry, warnOnInvalidGraph } = options;
5
- const effectiveDefinitionContext = definitionContext && graph.nodes.some(usesGraphBoundaryDefinitionContext) ? definitionContext : undefined;
6
+ const graphNodes = resolveNodePrefabInstances(project, graph.nodes);
7
+ const effectiveDefinitionContext = definitionContext && graphNodes.some(usesGraphBoundaryDefinitionContext) ? definitionContext : undefined;
6
8
  const nodeInstances = {};
7
9
  const nodesById = {};
8
10
  const connections = {};
9
- for (const node of graph.nodes) {
11
+ for (const node of graphNodes) {
10
12
  nodeInstances[node.id] = registry.createDynamicImpl(node);
11
13
  nodesById[node.id] = node;
12
14
  }
@@ -36,7 +38,7 @@ export function preprocessGraphState(options) {
36
38
  definitionContext: effectiveDefinitionContext,
37
39
  warnOnInvalidGraph,
38
40
  });
39
- const stronglyConnectedComponents = findStronglyConnectedComponents(graph.nodes, (node) => {
41
+ const stronglyConnectedComponents = findStronglyConnectedComponents(graphNodes, (node) => {
40
42
  const nodeConnections = connections[node.id] ?? [];
41
43
  return nodeConnections
42
44
  .filter((connection) => connection.outputNodeId === node.id)
@@ -60,7 +62,7 @@ export function preprocessGraphState(options) {
60
62
  ...buildGraphExecutionPlan({
61
63
  connections,
62
64
  definitions,
63
- graphNodes: graph.nodes,
65
+ graphNodes,
64
66
  nodesById,
65
67
  stronglyConnectedComponents,
66
68
  }),