@valerypopoff/rivet2-core 2.1.4 → 2.1.6

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 (107) hide show
  1. package/dist/cjs/bundle.cjs +6651 -1022
  2. package/dist/cjs/bundle.cjs.map +4 -4
  3. package/dist/cjs/webAppRuntime.cjs +733 -19
  4. package/dist/cjs/webAppRuntime.cjs.map +3 -3
  5. package/dist/esm/api/createProcessor.js +6 -1
  6. package/dist/esm/exports.js +7 -0
  7. package/dist/esm/integrations/KnowledgeStore.js +1 -0
  8. package/dist/esm/integrations/KnowledgeStoreProvider.js +292 -0
  9. package/dist/esm/integrations/KnowledgeStoreValidation.js +428 -0
  10. package/dist/esm/integrations/ManagedKnowledgeStore.js +539 -0
  11. package/dist/esm/model/DataValue.js +22 -2
  12. package/dist/esm/model/GraphBoundaryEffects.js +13 -0
  13. package/dist/esm/model/GraphProcessor.js +1141 -82
  14. package/dist/esm/model/ManagedAsyncBranches.js +28 -0
  15. package/dist/esm/model/Nodes.js +27 -0
  16. package/dist/esm/model/ProcessContextBuilder.js +2 -1
  17. package/dist/esm/model/RecordingPlayer.js +9 -0
  18. package/dist/esm/model/StoredValueStore.js +226 -0
  19. package/dist/esm/model/SubprocessorBridge.js +50 -19
  20. package/dist/esm/model/ToolCallContinuation.js +1 -0
  21. package/dist/esm/model/UiGraph.js +52 -2
  22. package/dist/esm/model/UiGraphActionProtocol.js +10 -1
  23. package/dist/esm/model/UiGraphBrowserRuntime.js +444 -0
  24. package/dist/esm/model/UiGraphNormalization.js +35 -185
  25. package/dist/esm/model/UiGraphRendererStyles.js +878 -78
  26. package/dist/esm/model/UiGraphRuntimeModel.js +255 -15
  27. package/dist/esm/model/UiGraphSchema.js +91 -0
  28. package/dist/esm/model/UiGraphWebAppStorage.js +1 -0
  29. package/dist/esm/model/chat/chatMessages.js +5 -9
  30. package/dist/esm/model/chat/openAIChatRequest.js +8 -2
  31. package/dist/esm/model/chat-v2/chatV2Errors.js +36 -3
  32. package/dist/esm/model/chat-v2/chatV2RuntimeOptions.js +8 -8
  33. package/dist/esm/model/chat-v2/index.js +1 -0
  34. package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +3 -1
  35. package/dist/esm/model/chat-v2/parallelToolCalls.js +38 -0
  36. package/dist/esm/model/chat-v2/toolContinuation.js +45 -8
  37. package/dist/esm/model/chat-v2/toolContinuationConnection.js +68 -0
  38. package/dist/esm/model/nodes/BuildKnowledgeContextNode.js +157 -0
  39. package/dist/esm/model/nodes/DelegateFunctionCallNode.js +12 -40
  40. package/dist/esm/model/nodes/GetKnowledgeSourceStatusNode.js +79 -0
  41. package/dist/esm/model/nodes/GetStoredValueNode.js +109 -0
  42. package/dist/esm/model/nodes/KnowledgeDocumentNode.js +88 -0
  43. package/dist/esm/model/nodes/KnowledgeSourceNode.js +94 -0
  44. package/dist/esm/model/nodes/LLMChatV2Node.js +17 -1
  45. package/dist/esm/model/nodes/MatchNode.js +7 -7
  46. package/dist/esm/model/nodes/SearchKnowledgeNode.js +127 -0
  47. package/dist/esm/model/nodes/SetStoredValueNode.js +84 -0
  48. package/dist/esm/model/nodes/StartBackgroundBranchNode.js +59 -0
  49. package/dist/esm/model/nodes/StoredValueNodeUtils.js +57 -0
  50. package/dist/esm/model/nodes/SyncKnowledgeSourceNode.js +149 -0
  51. package/dist/esm/model/nodes/ToolNode.js +14 -0
  52. package/dist/esm/model/nodes/toolCallDelegation.js +44 -1
  53. package/dist/esm/plugins/pinecone/PineconeKnowledgeStore.js +553 -0
  54. package/dist/esm/plugins/pinecone/plugin.js +32 -0
  55. package/dist/esm/recording/ExecutionRecorder.js +1 -0
  56. package/dist/esm/utils/coerceType.js +27 -2
  57. package/dist/esm/utils/getPluginConfig.js +12 -6
  58. package/dist/esm/utils/serialization/serialization.js +4 -1
  59. package/dist/esm/utils/serialization/serializationUtils.js +59 -1
  60. package/dist/esm/webAppRuntime.js +3 -3
  61. package/dist/types/api/createProcessor.d.ts +6 -0
  62. package/dist/types/exports.d.ts +7 -0
  63. package/dist/types/integrations/KnowledgeStore.d.ts +131 -0
  64. package/dist/types/integrations/KnowledgeStoreProvider.d.ts +46 -0
  65. package/dist/types/integrations/KnowledgeStoreValidation.d.ts +16 -0
  66. package/dist/types/integrations/ManagedKnowledgeStore.d.ts +57 -0
  67. package/dist/types/model/DataValue.d.ts +10 -3
  68. package/dist/types/model/EditorDefinition.d.ts +9 -2
  69. package/dist/types/model/ExecutorProtocol.d.ts +12 -0
  70. package/dist/types/model/GraphBoundaryEffects.d.ts +9 -1
  71. package/dist/types/model/GraphProcessor.d.ts +21 -2
  72. package/dist/types/model/ManagedAsyncBranches.d.ts +6 -0
  73. package/dist/types/model/Nodes.d.ts +11 -2
  74. package/dist/types/model/ProcessContext.d.ts +18 -0
  75. package/dist/types/model/ProcessContextBuilder.d.ts +2 -1
  76. package/dist/types/model/Project.d.ts +11 -0
  77. package/dist/types/model/StoredValueStore.d.ts +55 -0
  78. package/dist/types/model/SubprocessorBridge.d.ts +4 -2
  79. package/dist/types/model/ToolCallContinuation.d.ts +13 -0
  80. package/dist/types/model/UiGraph.d.ts +24 -1
  81. package/dist/types/model/UiGraphActionProtocol.d.ts +2 -0
  82. package/dist/types/model/UiGraphBrowserRuntime.d.ts +75 -0
  83. package/dist/types/model/UiGraphRendererStyles.d.ts +2 -2
  84. package/dist/types/model/UiGraphRuntimeModel.d.ts +22 -3
  85. package/dist/types/model/UiGraphSchema.d.ts +113 -0
  86. package/dist/types/model/UiGraphWebAppStorage.d.ts +3 -0
  87. package/dist/types/model/chat-v2/index.d.ts +1 -0
  88. package/dist/types/model/chat-v2/parallelToolCalls.d.ts +9 -0
  89. package/dist/types/model/chat-v2/toolContinuation.d.ts +1 -0
  90. package/dist/types/model/chat-v2/toolContinuationConnection.d.ts +28 -0
  91. package/dist/types/model/nodes/BuildKnowledgeContextNode.d.ts +23 -0
  92. package/dist/types/model/nodes/GetKnowledgeSourceStatusNode.d.ts +19 -0
  93. package/dist/types/model/nodes/GetStoredValueNode.d.ts +25 -0
  94. package/dist/types/model/nodes/KnowledgeDocumentNode.d.ts +26 -0
  95. package/dist/types/model/nodes/KnowledgeSourceNode.d.ts +25 -0
  96. package/dist/types/model/nodes/SearchKnowledgeNode.d.ts +25 -0
  97. package/dist/types/model/nodes/SetStoredValueNode.d.ts +23 -0
  98. package/dist/types/model/nodes/StartBackgroundBranchNode.d.ts +14 -0
  99. package/dist/types/model/nodes/StoredValueNodeUtils.d.ts +5 -0
  100. package/dist/types/model/nodes/SyncKnowledgeSourceNode.d.ts +27 -0
  101. package/dist/types/model/nodes/ToolNode.d.ts +2 -0
  102. package/dist/types/model/nodes/toolCallDelegation.d.ts +4 -0
  103. package/dist/types/plugins/pinecone/PineconeKnowledgeStore.d.ts +11 -0
  104. package/dist/types/recording/RecordedEvents.d.ts +5 -0
  105. package/dist/types/utils/serialization/serializationUtils.d.ts +4 -0
  106. package/dist/types/webAppRuntime.d.ts +5 -4
  107. package/package.json +1 -1
@@ -1,4 +1,5 @@
1
- import { UI_GRAPH_GAP_SIZES, UI_GRAPH_OUTPUT_RENDER_MODES, normalizeUiGraphComponentIds, } from './UiGraph.js';
1
+ import { normalizeUiGraphComponentIds } from './UiGraph.js';
2
+ import { UI_GRAPH_COMPONENT_SCHEMA, UI_GRAPH_ENVELOPE_SCHEMA } from './UiGraphSchema.js';
2
3
  export class UiGraphNormalizationError extends Error {
3
4
  issues;
4
5
  constructor(issues) {
@@ -51,23 +52,16 @@ export function normalizeProjectUiGraphs(project) {
51
52
  return uiGraphs === project.uiGraphs ? project : { ...project, uiGraphs };
52
53
  }
53
54
  function parseUiGraph(value, options) {
54
- const issues = [];
55
- const graphLabel = getUiGraphLabel(value, options.expectedId);
56
- const graphPath = `UI graph "${graphLabel}"`;
55
+ const graphPath = `UI graph "${getUiGraphLabel(value, options.expectedId)}"`;
57
56
  if (!isRecord(value)) {
58
57
  return { issues: [{ message: 'must be an object', path: graphPath }] };
59
58
  }
60
- requireNonEmptyString(value, 'id', graphPath, issues);
61
- requireString(value, 'name', graphPath, issues);
62
- optionalString(value, 'description', graphPath, issues);
59
+ const envelopeResult = UI_GRAPH_ENVELOPE_SCHEMA.safeParse(value);
60
+ const issues = envelopeResult.success ? [] : mapSchemaIssues(envelopeResult.error.issues, graphPath);
63
61
  if (options.expectedId !== undefined && typeof value.id === 'string' && value.id !== options.expectedId) {
64
- issues.push({
65
- message: `must match its project key "${options.expectedId}"`,
66
- path: `${graphPath}.id`,
67
- });
62
+ issues.push({ message: `must match its project key "${options.expectedId}"`, path: `${graphPath}.id` });
68
63
  }
69
64
  if (!Array.isArray(value.components)) {
70
- issues.push({ message: 'must be an array', path: `${graphPath}.components` });
71
65
  return { issues };
72
66
  }
73
67
  validateComponents(value.components, graphPath, options, issues);
@@ -89,10 +83,12 @@ function validateComponents(components, graphPath, options, issues) {
89
83
  issues.push({ message: 'must be an object', path: componentPath });
90
84
  continue;
91
85
  }
92
- validateComponent(component, componentPath, issues);
86
+ const result = UI_GRAPH_COMPONENT_SCHEMA.safeParse(component);
87
+ if (!result.success) {
88
+ issues.push(...mapComponentSchemaIssues(result.error.issues, componentPath, component.type));
89
+ }
93
90
  const rawComponentId = component.id;
94
91
  if (rawComponentId !== undefined && typeof rawComponentId !== 'string') {
95
- issues.push({ message: 'must be a string', path: `${componentPath}.id` });
96
92
  continue;
97
93
  }
98
94
  const componentId = rawComponentId ?? '';
@@ -103,186 +99,43 @@ function validateComponents(components, graphPath, options, issues) {
103
99
  continue;
104
100
  }
105
101
  if (usedIds.has(componentId)) {
106
- if (repairComponentIds) {
107
- continue;
102
+ if (!repairComponentIds) {
103
+ issues.push({ message: `duplicates component id "${componentId}"`, path: `${componentPath}.id` });
108
104
  }
109
- issues.push({
110
- message: `duplicates component id "${componentId}"`,
111
- path: `${componentPath}.id`,
112
- });
113
105
  continue;
114
106
  }
115
107
  usedIds.add(componentId);
116
108
  }
117
109
  }
118
- function validateComponent(component, path, issues) {
119
- const componentType = component.type;
120
- if (typeof componentType !== 'string' || !hasOwn(UI_GRAPH_COMPONENT_VALIDATORS, componentType)) {
121
- issues.push({
122
- message: typeof componentType === 'string'
110
+ function mapComponentSchemaIssues(schemaIssues, path, componentType) {
111
+ return schemaIssues.map((issue) => ({
112
+ message: issue.path.length === 1 && issue.path[0] === 'type'
113
+ ? typeof componentType === 'string'
123
114
  ? `has unsupported type "${componentType}"`
124
- : 'must have a supported string type',
125
- path: `${path}.type`,
126
- });
127
- return;
128
- }
129
- UI_GRAPH_COMPONENT_VALIDATORS[componentType](component, path, issues);
130
- }
131
- const UI_GRAPH_COMPONENT_VALIDATORS = {
132
- text(component, path, issues) {
133
- requireString(component, 'text', path, issues);
134
- },
135
- markdown(component, path, issues) {
136
- requireString(component, 'markdown', path, issues);
137
- },
138
- gap(component, path, issues) {
139
- requireEnum(component, 'size', UI_GRAPH_GAP_SIZES, path, issues);
140
- },
141
- input: validateInputComponent,
142
- textarea: validateInputComponent,
143
- button(component, path, issues) {
144
- requireString(component, 'label', path, issues);
145
- validateAction(component.action, `${path}.action`, issues);
146
- },
147
- chat(component, path, issues) {
148
- optionalString(component, 'placeholder', path, issues);
149
- validateChatAction(component.action, `${path}.action`, issues);
150
- },
151
- output(component, path, issues) {
152
- optionalString(component, 'label', path, issues);
153
- requireString(component, 'stateKey', path, issues);
154
- optionalEnum(component, 'renderAs', UI_GRAPH_OUTPUT_RENDER_MODES, path, issues);
155
- },
156
- };
157
- function validateInputComponent(component, path, issues) {
158
- requireString(component, 'label', path, issues);
159
- requireString(component, 'stateKey', path, issues);
160
- optionalString(component, 'placeholder', path, issues);
161
- optionalString(component, 'defaultValue', path, issues);
162
- }
163
- function validateAction(value, path, issues) {
164
- if (!isRecord(value)) {
165
- issues.push({ message: 'must be an object', path });
166
- return;
167
- }
168
- const actionType = value.type;
169
- if (typeof actionType !== 'string' || !hasOwn(UI_GRAPH_ACTION_VALIDATORS, actionType)) {
170
- issues.push({ message: 'must be "runGraph"', path: `${path}.type` });
171
- return;
172
- }
173
- UI_GRAPH_ACTION_VALIDATORS[actionType](value, path, issues);
174
- }
175
- function validateChatAction(value, path, issues) {
176
- if (!isRecord(value)) {
177
- issues.push({ message: 'must be an object', path });
178
- return;
179
- }
180
- if (value.type !== 'runGraph') {
181
- issues.push({ message: 'must be "runGraph"', path: `${path}.type` });
182
- }
183
- optionalString(value, 'graphId', path, issues);
184
- optionalString(value, 'userInputId', path, issues);
185
- optionalString(value, 'historyInputId', path, issues);
186
- optionalString(value, 'responseOutputId', path, issues);
187
- validateInputMappings(value.inputMappings, `${path}.inputMappings`, issues);
188
- }
189
- const UI_GRAPH_ACTION_VALIDATORS = {
190
- runGraph(value, path, issues) {
191
- optionalString(value, 'graphId', path, issues);
192
- optionalString(value, 'outputKey', path, issues);
193
- optionalString(value, 'outputStateKey', path, issues);
194
- validateInputMappings(value.inputMappings, `${path}.inputMappings`, issues);
195
- validateLegacyInputs(value.inputs, `${path}.inputs`, issues);
196
- validateOutputMappings(value.outputs, `${path}.outputs`, issues);
197
- },
198
- };
199
- function validateInputMappings(value, path, issues) {
200
- if (value === undefined) {
201
- return;
202
- }
203
- if (!Array.isArray(value)) {
204
- issues.push({ message: 'must be an array', path });
205
- return;
206
- }
207
- for (const [index, binding] of value.entries()) {
208
- const bindingPath = `${path} at index ${index}`;
209
- if (!isRecord(binding)) {
210
- issues.push({ message: 'must be an object', path: bindingPath });
211
- continue;
115
+ : 'must have a supported string type'
116
+ : issue.message,
117
+ path: formatSchemaPath(path, issue.path),
118
+ }));
119
+ }
120
+ function mapSchemaIssues(schemaIssues, path) {
121
+ return schemaIssues.map((issue) => ({ message: issue.message, path: formatSchemaPath(path, issue.path) }));
122
+ }
123
+ function formatSchemaPath(basePath, schemaPath) {
124
+ let path = basePath;
125
+ for (let index = 0; index < schemaPath.length; index += 1) {
126
+ const segment = schemaPath[index];
127
+ const previous = schemaPath[index - 1];
128
+ if (typeof segment === 'number') {
129
+ path += previous === 'items' ? `[${segment}]` : ` at index ${segment}`;
212
130
  }
213
- requireString(binding, 'inputKey', bindingPath, issues);
214
- requireString(binding, 'stateKey', bindingPath, issues);
215
- }
216
- }
217
- function validateLegacyInputs(value, path, issues) {
218
- if (value === undefined) {
219
- return;
220
- }
221
- if (!isRecord(value)) {
222
- issues.push({ message: 'must be an object', path });
223
- return;
224
- }
225
- for (const [inputId, binding] of Object.entries(value)) {
226
- const bindingPath = `${path}[${JSON.stringify(inputId)}]`;
227
- if (!isRecord(binding)) {
228
- issues.push({ message: 'must be an object', path: bindingPath });
229
- continue;
230
- }
231
- if (binding.type === 'state') {
232
- requireString(binding, 'key', bindingPath, issues);
233
- }
234
- else if (binding.type === 'literal') {
235
- if (!Object.prototype.hasOwnProperty.call(binding, 'value')) {
236
- issues.push({ message: 'is required', path: `${bindingPath}.value` });
237
- }
131
+ else if (typeof previous === 'string' && previous === 'inputs') {
132
+ path += `[${JSON.stringify(segment)}]`;
238
133
  }
239
134
  else {
240
- issues.push({ message: 'must be "state" or "literal"', path: `${bindingPath}.type` });
135
+ path += `.${String(segment)}`;
241
136
  }
242
137
  }
243
- }
244
- function validateOutputMappings(value, path, issues) {
245
- if (value === undefined) {
246
- return;
247
- }
248
- if (!Array.isArray(value)) {
249
- issues.push({ message: 'must be an array', path });
250
- return;
251
- }
252
- for (const [index, binding] of value.entries()) {
253
- const bindingPath = `${path} at index ${index}`;
254
- if (!isRecord(binding)) {
255
- issues.push({ message: 'must be an object', path: bindingPath });
256
- continue;
257
- }
258
- optionalString(binding, 'outputKey', bindingPath, issues);
259
- requireString(binding, 'stateKey', bindingPath, issues);
260
- }
261
- }
262
- function requireString(value, key, path, issues) {
263
- if (typeof value[key] !== 'string') {
264
- issues.push({ message: 'must be a string', path: `${path}.${key}` });
265
- }
266
- }
267
- function requireNonEmptyString(value, key, path, issues) {
268
- if (typeof value[key] !== 'string' || !value[key].trim()) {
269
- issues.push({ message: 'must be a non-empty string', path: `${path}.${key}` });
270
- }
271
- }
272
- function optionalString(value, key, path, issues) {
273
- if (value[key] !== undefined && typeof value[key] !== 'string') {
274
- issues.push({ message: 'must be a string when provided', path: `${path}.${key}` });
275
- }
276
- }
277
- function requireEnum(value, key, allowed, path, issues) {
278
- if (typeof value[key] !== 'string' || !allowed.includes(value[key])) {
279
- issues.push({ message: `must be one of: ${allowed.join(', ')}`, path: `${path}.${key}` });
280
- }
281
- }
282
- function optionalEnum(value, key, allowed, path, issues) {
283
- if (value[key] !== undefined && (typeof value[key] !== 'string' || !allowed.includes(value[key]))) {
284
- issues.push({ message: `must be one of: ${allowed.join(', ')}`, path: `${path}.${key}` });
285
- }
138
+ return path;
286
139
  }
287
140
  function getUiGraphLabel(value, expectedId) {
288
141
  if (expectedId !== undefined) {
@@ -293,6 +146,3 @@ function getUiGraphLabel(value, expectedId) {
293
146
  function isRecord(value) {
294
147
  return value != null && typeof value === 'object' && !Array.isArray(value);
295
148
  }
296
- function hasOwn(value, key) {
297
- return Object.prototype.hasOwnProperty.call(value, key);
298
- }