@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
@@ -0,0 +1,88 @@
1
+ import { nanoid } from 'nanoid/non-secure';
2
+ import { dedent } from 'ts-dedent';
3
+ import { nodeDefinition } from '../NodeDefinition.js';
4
+ import { NodeImpl } from '../NodeImpl.js';
5
+ import { coerceType } from '../../utils/coerceType.js';
6
+ import { normalizeKnowledgeDocument, normalizeKnowledgeMetadata } from '../../integrations/KnowledgeStoreValidation.js';
7
+ export class KnowledgeDocumentNodeImpl extends NodeImpl {
8
+ static create() {
9
+ return {
10
+ id: nanoid(),
11
+ type: 'knowledgeDocument',
12
+ title: 'Knowledge Document',
13
+ visualData: { x: 0, y: 0, width: 250 },
14
+ data: {
15
+ text: '',
16
+ useTextInput: true,
17
+ documentId: '',
18
+ useDocumentIdInput: false,
19
+ title: '',
20
+ useTitleInput: false,
21
+ metadata: {},
22
+ useMetadataInput: false,
23
+ },
24
+ };
25
+ }
26
+ getInputDefinitions() {
27
+ const inputs = [];
28
+ if (this.data.useTextInput)
29
+ inputs.push({ id: 'text', title: 'Text', dataType: 'string', required: true });
30
+ if (this.data.useDocumentIdInput)
31
+ inputs.push({ id: 'document-id', title: 'Document ID', dataType: 'string' });
32
+ if (this.data.useTitleInput)
33
+ inputs.push({ id: 'title', title: 'Title', dataType: 'string' });
34
+ if (this.data.useMetadataInput)
35
+ inputs.push({ id: 'metadata', title: 'Metadata', dataType: 'object' });
36
+ return inputs;
37
+ }
38
+ getOutputDefinitions() {
39
+ return [{ id: 'document', title: 'Document', dataType: 'knowledge-document' }];
40
+ }
41
+ getEditors() {
42
+ return [
43
+ {
44
+ type: 'code',
45
+ language: 'text',
46
+ dataKey: 'text',
47
+ useInputToggleDataKey: 'useTextInput',
48
+ label: 'Text',
49
+ height: 160,
50
+ },
51
+ { type: 'string', dataKey: 'documentId', useInputToggleDataKey: 'useDocumentIdInput', label: 'Document ID' },
52
+ { type: 'string', dataKey: 'title', useInputToggleDataKey: 'useTitleInput', label: 'Title' },
53
+ {
54
+ type: 'jsonObject',
55
+ dataKey: 'metadata',
56
+ useInputToggleDataKey: 'useMetadataInput',
57
+ label: 'Metadata',
58
+ helperMessage: 'Enter a flat JSON object, or leave {} when the document has no metadata.',
59
+ },
60
+ ];
61
+ }
62
+ getBody() {
63
+ return dedent `
64
+ ${this.data.useTextInput ? 'Text from input' : `${this.data.text.length} characters`}
65
+ ${this.data.useDocumentIdInput ? 'ID from input' : this.data.documentId ? `ID: ${this.data.documentId}` : 'ID generated from content'}
66
+ `;
67
+ }
68
+ static getUIData() {
69
+ return {
70
+ contextMenuTitle: 'Knowledge Document',
71
+ infoBoxTitle: 'Knowledge Document Node',
72
+ infoBoxBody: 'Creates a typed text document with a stable ID, title, and portable searchable metadata.',
73
+ group: 'Knowledge',
74
+ };
75
+ }
76
+ async process(inputs, _context) {
77
+ const text = this.data.useTextInput ? coerceType(inputs['text'], 'string') : this.data.text;
78
+ const id = (this.data.useDocumentIdInput ? coerceType(inputs['document-id'], 'string') : this.data.documentId).trim();
79
+ const title = (this.data.useTitleInput ? coerceType(inputs['title'], 'string') : this.data.title).trim();
80
+ const metadataRaw = this.data.useMetadataInput
81
+ ? coerceType(inputs['metadata'], 'object')
82
+ : this.data.metadata;
83
+ const metadata = normalizeKnowledgeMetadata(metadataRaw);
84
+ const document = normalizeKnowledgeDocument({ text, ...(id ? { id } : {}), ...(title ? { title } : {}), metadata });
85
+ return { ['document']: { type: 'knowledge-document', value: document } };
86
+ }
87
+ }
88
+ export const knowledgeDocumentNode = nodeDefinition(KnowledgeDocumentNodeImpl, 'Knowledge Document');
@@ -0,0 +1,94 @@
1
+ import { nanoid } from 'nanoid/non-secure';
2
+ import { dedent } from 'ts-dedent';
3
+ import { nodeDefinition } from '../NodeDefinition.js';
4
+ import { NodeImpl } from '../NodeImpl.js';
5
+ import { coerceType } from '../../utils/coerceType.js';
6
+ import { normalizeKnowledgeConnectionId, normalizeKnowledgeSourceId, normalizeKnowledgeSourceReference, } from '../../integrations/KnowledgeStoreValidation.js';
7
+ export class KnowledgeSourceNodeImpl extends NodeImpl {
8
+ static create() {
9
+ return {
10
+ id: nanoid(),
11
+ type: 'knowledgeSource',
12
+ title: 'Knowledge Source',
13
+ visualData: { x: 0, y: 0, width: 250 },
14
+ data: {
15
+ connectionId: '',
16
+ useConnectionIdInput: false,
17
+ sourceId: '',
18
+ useSourceIdInput: true,
19
+ version: '',
20
+ useVersionInput: false,
21
+ },
22
+ };
23
+ }
24
+ getInputDefinitions() {
25
+ const inputs = [];
26
+ if (this.data.useConnectionIdInput) {
27
+ inputs.push({ id: 'connection-id', title: 'Connection ID', dataType: 'string', required: true });
28
+ }
29
+ if (this.data.useSourceIdInput) {
30
+ inputs.push({ id: 'source-id', title: 'Source ID', dataType: 'string', required: true });
31
+ }
32
+ if (this.data.useVersionInput) {
33
+ inputs.push({ id: 'version', title: 'Exact Version', dataType: 'string', required: false });
34
+ }
35
+ return inputs;
36
+ }
37
+ getOutputDefinitions() {
38
+ return [{ id: 'source', title: 'Source', dataType: 'knowledge-source' }];
39
+ }
40
+ getEditors() {
41
+ return [
42
+ {
43
+ type: 'custom',
44
+ customEditorId: 'KnowledgeStoreSelector',
45
+ dataKey: 'connectionId',
46
+ useInputToggleDataKey: 'useConnectionIdInput',
47
+ label: 'Knowledge Store',
48
+ includeInGraphSearch: true,
49
+ },
50
+ {
51
+ type: 'string',
52
+ dataKey: 'sourceId',
53
+ useInputToggleDataKey: 'useSourceIdInput',
54
+ label: 'Source ID',
55
+ includeInGraphSearch: true,
56
+ },
57
+ {
58
+ type: 'string',
59
+ dataKey: 'version',
60
+ useInputToggleDataKey: 'useVersionInput',
61
+ label: 'Exact Version',
62
+ helperMessage: 'Leave blank to resolve the active committed version when the source is used.',
63
+ },
64
+ ];
65
+ }
66
+ getBody(context) {
67
+ const connection = context.project.metadata.knowledgeStores?.[this.data.connectionId];
68
+ return dedent `
69
+ Store: ${this.data.useConnectionIdInput ? '(from input)' : (connection?.displayName ?? this.data.connectionId) || '(not selected)'}
70
+ Source: ${this.data.useSourceIdInput ? '(from input)' : this.data.sourceId || '(not set)'}
71
+ ${this.data.useVersionInput || this.data.version ? 'Exact version configured' : 'Uses active version'}
72
+ `;
73
+ }
74
+ static getUIData() {
75
+ return {
76
+ contextMenuTitle: 'Knowledge Source',
77
+ infoBoxTitle: 'Knowledge Source Node',
78
+ infoBoxBody: 'Creates a portable reference to one logical source in a named project knowledge store.',
79
+ group: 'Knowledge',
80
+ };
81
+ }
82
+ async process(inputs, _context) {
83
+ const connectionId = normalizeKnowledgeConnectionId(this.data.useConnectionIdInput ? coerceType(inputs['connection-id'], 'string') : this.data.connectionId);
84
+ const sourceId = normalizeKnowledgeSourceId(this.data.useSourceIdInput ? coerceType(inputs['source-id'], 'string') : this.data.sourceId);
85
+ const version = (this.data.useVersionInput ? coerceType(inputs['version'], 'string') : this.data.version).trim();
86
+ return {
87
+ ['source']: {
88
+ type: 'knowledge-source',
89
+ value: normalizeKnowledgeSourceReference({ connectionId, sourceId, ...(version ? { version } : {}) }),
90
+ },
91
+ };
92
+ }
93
+ }
94
+ export const knowledgeSourceNode = nodeDefinition(KnowledgeSourceNodeImpl, 'Knowledge Source');
@@ -255,7 +255,9 @@ export class LLMChatV2NodeImpl extends NodeImpl {
255
255
  getOptionalNumberBodyLine('Frequency penalty', this.data.frequencyPenalty, this.data.useFrequencyPenaltyInput),
256
256
  getStopSequencesBodyLine(this.data),
257
257
  getOptionalNumberBodyLine('Seed', this.data.seed, this.data.useSeedInput),
258
- ].filter((line) => line !== undefined).join('\n'),
258
+ ]
259
+ .filter((line) => line !== undefined)
260
+ .join('\n'),
259
261
  };
260
262
  }
261
263
  async process(inputs, context) {
@@ -265,6 +267,7 @@ export class LLMChatV2NodeImpl extends NodeImpl {
265
267
  inputs,
266
268
  context,
267
269
  });
270
+ const toolCallContinuation = context.toolCallContinuation;
268
271
  if (runtime.cachedOutputs != null) {
269
272
  return runtime.cachedOutputs;
270
273
  }
@@ -274,6 +277,16 @@ export class LLMChatV2NodeImpl extends NodeImpl {
274
277
  autoContinue: true,
275
278
  maxToolRounds: runtime.maxToolRounds,
276
279
  functions: runtime.functions,
280
+ delegateToolCallRound: toolCallContinuation
281
+ ? async (toolCalls, preToolMessage) => {
282
+ const results = await toolCallContinuation.run(toolCalls, preToolMessage);
283
+ return results.map((result) => ({
284
+ type: 'chat-message',
285
+ value: result.message,
286
+ delegatedToolCall: result.record,
287
+ }));
288
+ }
289
+ : undefined,
277
290
  delegateToolCall: async (toolCall) => {
278
291
  const delegated = await delegateToolCall(toolCall, context, {
279
292
  handlers: [],
@@ -290,6 +303,9 @@ export class LLMChatV2NodeImpl extends NodeImpl {
290
303
  },
291
304
  })
292
305
  : await runChatV2Pipeline(runtime.runOptions);
306
+ if (toolCallContinuation && result.functionCalls.length > 0) {
307
+ toolCallContinuation.release();
308
+ }
293
309
  if (runtime.cacheKey != null && runtime.editorCache != null) {
294
310
  runtime.editorCache.set(runtime.cacheKey, cloneLLMChatV2EditorCacheOutputs(result.commonOutputs));
295
311
  }
@@ -11,7 +11,7 @@ export class MatchNodeImpl extends NodeImpl {
11
11
  static create() {
12
12
  const chartNode = {
13
13
  type: 'match',
14
- title: 'Match',
14
+ title: 'Regex Match',
15
15
  id: nanoid(),
16
16
  visualData: {
17
17
  x: 0,
@@ -106,13 +106,14 @@ export class MatchNodeImpl extends NodeImpl {
106
106
  infoBoxBody: dedent `
107
107
  Any number of regular expressions can be configured, each corresponding to an output of the node. The output port of the first matching regex will be ran, and all other output ports will not be ran.
108
108
  `,
109
- infoBoxTitle: 'Match Node',
110
- contextMenuTitle: 'Match',
109
+ infoBoxTitle: 'Regex Match Node',
110
+ contextMenuTitle: 'Regex Match',
111
111
  group: ['Logic'],
112
112
  };
113
113
  }
114
114
  async process(inputs) {
115
- const inputString = coerceType(inputs['input'], 'string');
115
+ const inputValue = inputs['input'];
116
+ const inputString = inputValue?.value == null ? undefined : coerceType(inputValue, 'string');
116
117
  const value = inputs['value'];
117
118
  const portIds = resolveStoredOrderedPortIds(this.data.cases.length, this.data.casePortIds, {
118
119
  kind: 'prefix',
@@ -125,8 +126,7 @@ export class MatchNodeImpl extends NodeImpl {
125
126
  let matched = false;
126
127
  const output = {};
127
128
  for (let i = 0; i < cases.length; i++) {
128
- const regExp = new RegExp(cases[i]);
129
- const match = regExp.test(inputString);
129
+ const match = inputString !== undefined && new RegExp(cases[i]).test(inputString);
130
130
  const canMatch = !this.data.exclusive || !matched;
131
131
  if (match && canMatch) {
132
132
  matched = true;
@@ -157,4 +157,4 @@ export class MatchNodeImpl extends NodeImpl {
157
157
  return output;
158
158
  }
159
159
  }
160
- export const matchNode = nodeDefinition(MatchNodeImpl, 'Match');
160
+ export const matchNode = nodeDefinition(MatchNodeImpl, 'Regex Match');
@@ -0,0 +1,127 @@
1
+ import { nanoid } from 'nanoid/non-secure';
2
+ import { dedent } from 'ts-dedent';
3
+ import { nodeDefinition } from '../NodeDefinition.js';
4
+ import { NodeImpl } from '../NodeImpl.js';
5
+ import { coerceType } from '../../utils/coerceType.js';
6
+ import { normalizeKnowledgeFilter, normalizeKnowledgeQueries, normalizeSearchKnowledgeSourceResult, normalizeKnowledgeSourceReference, } from '../../integrations/KnowledgeStoreValidation.js';
7
+ export class SearchKnowledgeNodeImpl extends NodeImpl {
8
+ static create() {
9
+ return {
10
+ id: nanoid(),
11
+ type: 'searchKnowledge',
12
+ title: 'Search Knowledge',
13
+ visualData: { x: 0, y: 0, width: 270 },
14
+ data: {
15
+ filter: {},
16
+ useFilterInput: false,
17
+ topK: 10,
18
+ maxConcurrency: 3,
19
+ finalResultCount: 10,
20
+ rerankMode: 'off',
21
+ rerankTopN: 7,
22
+ },
23
+ };
24
+ }
25
+ getInputDefinitions() {
26
+ const inputs = [
27
+ { id: 'source', title: 'Source', dataType: 'knowledge-source', required: true },
28
+ { id: 'query', title: 'Query', dataType: ['string', 'string[]'], required: true },
29
+ ];
30
+ if (this.data.useFilterInput)
31
+ inputs.push({ id: 'filter', title: 'Metadata Filter', dataType: 'object' });
32
+ return inputs;
33
+ }
34
+ getOutputDefinitions() {
35
+ return [
36
+ { id: 'evidence', title: 'Evidence', dataType: 'knowledge-evidence[]' },
37
+ { id: 'source', title: 'Resolved Source', dataType: 'knowledge-source' },
38
+ { id: 'source-found', title: 'Source Found', dataType: 'boolean' },
39
+ { id: 'query-results', title: 'Query Results', dataType: 'object[]' },
40
+ { id: 'message', title: 'Status Message', dataType: 'string' },
41
+ ];
42
+ }
43
+ getEditors() {
44
+ return [
45
+ {
46
+ type: 'jsonObject',
47
+ dataKey: 'filter',
48
+ useInputToggleDataKey: 'useFilterInput',
49
+ label: 'Metadata Filter',
50
+ helperMessage: 'Enter a JSON filter expression, or leave {} to search without a metadata filter.',
51
+ },
52
+ { type: 'number', dataKey: 'topK', label: 'Results Per Query', min: 1, max: 100 },
53
+ { type: 'number', dataKey: 'maxConcurrency', label: 'Query Concurrency', min: 1, max: 32 },
54
+ { type: 'number', dataKey: 'finalResultCount', label: 'Final Result Count', min: 1, max: 500 },
55
+ {
56
+ type: 'dropdown',
57
+ dataKey: 'rerankMode',
58
+ label: 'Provider Reranking',
59
+ options: [
60
+ { value: 'off', label: 'Off' },
61
+ { value: 'connection-default', label: 'Connection Default' },
62
+ { value: 'required', label: 'Required' },
63
+ ],
64
+ },
65
+ {
66
+ type: 'number',
67
+ dataKey: 'rerankTopN',
68
+ label: 'Rerank Result Count',
69
+ min: 1,
70
+ max: 100,
71
+ hideIf: (data) => data.rerankMode === 'off',
72
+ },
73
+ ];
74
+ }
75
+ getBody() {
76
+ return dedent `
77
+ ${this.data.topK} per query -> ${this.data.finalResultCount} final
78
+ Reranking: ${this.data.rerankMode}
79
+ `;
80
+ }
81
+ static getUIData() {
82
+ return {
83
+ contextMenuTitle: 'Search Knowledge',
84
+ infoBoxTitle: 'Search Knowledge Node',
85
+ infoBoxBody: 'Searches the active durable source version and returns normalized, deduplicated evidence.',
86
+ group: 'Knowledge',
87
+ };
88
+ }
89
+ async process(inputs, context) {
90
+ const source = normalizeKnowledgeSourceReference(coerceType(inputs['source'], 'knowledge-source'));
91
+ const queryInput = inputs['query'];
92
+ const queries = normalizeKnowledgeQueries(queryInput?.type === 'string[]'
93
+ ? queryInput.value
94
+ : queryInput?.type === 'any' && Array.isArray(queryInput.value)
95
+ ? queryInput.value
96
+ : [coerceType(queryInput, 'string')]);
97
+ const rawFilter = this.data.useFilterInput ? coerceType(inputs['filter'], 'object') : this.data.filter;
98
+ const filter = Object.keys(rawFilter).length ? normalizeKnowledgeFilter(rawFilter) : undefined;
99
+ const rerank = this.data.rerankMode === 'off'
100
+ ? undefined
101
+ : { mode: this.data.rerankMode, topN: this.data.rerankTopN };
102
+ const store = await context.getKnowledgeStore(source.connectionId);
103
+ const result = normalizeSearchKnowledgeSourceResult(await store.search({
104
+ source,
105
+ queries,
106
+ topK: this.data.topK,
107
+ maxConcurrency: this.data.maxConcurrency,
108
+ finalResultCount: this.data.finalResultCount,
109
+ filter,
110
+ rerank,
111
+ }, { signal: context.signal, reportProgress: context.reportProgress }), source, queries);
112
+ return {
113
+ ['evidence']: { type: 'knowledge-evidence[]', value: result.evidence },
114
+ ['source']: { type: 'knowledge-source', value: result.source },
115
+ ['source-found']: { type: 'boolean', value: result.sourceFound },
116
+ ['query-results']: {
117
+ type: 'object[]',
118
+ value: result.queryResults.map((queryResult) => ({
119
+ query: queryResult.query,
120
+ evidence: queryResult.evidence,
121
+ })),
122
+ },
123
+ ['message']: { type: 'string', value: result.message },
124
+ };
125
+ }
126
+ }
127
+ export const searchKnowledgeNode = nodeDefinition(SearchKnowledgeNodeImpl, 'Search Knowledge');
@@ -0,0 +1,84 @@
1
+ import { nanoid } from 'nanoid/non-secure';
2
+ import { dedent } from 'ts-dedent';
3
+ import { unwrapDataValue } from '../DataValue.js';
4
+ import { nodeDefinition } from '../NodeDefinition.js';
5
+ import { NodeImpl } from '../NodeImpl.js';
6
+ import { cloneRivetStoredValue } from '../StoredValueStore.js';
7
+ import { coerceType } from '../../utils/coerceType.js';
8
+ import { missingStoredValueDataValue, portableStoredValueScalarTypes, storedValueToDataValue, } from './StoredValueNodeUtils.js';
9
+ export class SetStoredValueNodeImpl extends NodeImpl {
10
+ static create() {
11
+ return {
12
+ type: 'setStoredValue',
13
+ title: 'Set Stored Value',
14
+ id: nanoid(),
15
+ visualData: { x: 0, y: 0, width: 220 },
16
+ data: { dataType: 'string', key: 'key', useKeyInput: false },
17
+ };
18
+ }
19
+ getInputDefinitions() {
20
+ const inputs = [];
21
+ if (this.data.useKeyInput) {
22
+ inputs.push({ id: 'key', title: 'Key', dataType: 'string' });
23
+ }
24
+ inputs.push({ id: 'value', title: 'Value', dataType: this.data.dataType });
25
+ return inputs;
26
+ }
27
+ getOutputDefinitions() {
28
+ return [
29
+ { id: 'saved-value', title: 'Saved Value', dataType: this.data.dataType },
30
+ { id: 'previous-value', title: 'Previous Value', dataType: this.data.dataType },
31
+ { id: 'had-previous-value', title: 'Had Previous Value', dataType: 'boolean' },
32
+ { id: 'key', title: 'Key', dataType: 'string' },
33
+ ];
34
+ }
35
+ getEditors() {
36
+ return [
37
+ {
38
+ type: 'string',
39
+ dataKey: 'key',
40
+ useInputToggleDataKey: 'useKeyInput',
41
+ label: 'Key',
42
+ includeInGraphSearch: true,
43
+ },
44
+ {
45
+ type: 'dataTypeSelector',
46
+ dataKey: 'dataType',
47
+ label: 'Data Type',
48
+ allowedDataTypes: portableStoredValueScalarTypes,
49
+ },
50
+ ];
51
+ }
52
+ getBody() {
53
+ return dedent `
54
+ ${this.data.useKeyInput ? '(Key from input)' : this.data.key}
55
+ Type: ${this.data.dataType}
56
+ `;
57
+ }
58
+ static getUIData() {
59
+ return {
60
+ infoBoxBody: 'Stores a portable JSON value in the current root run and, when the host supplies persistence, across later runs.',
61
+ infoBoxTitle: 'Set Stored Value Node',
62
+ contextMenuTitle: 'Set Stored Value',
63
+ group: ['Advanced'],
64
+ };
65
+ }
66
+ async process(inputs, context) {
67
+ const inputValue = inputs['value'];
68
+ if (!inputValue)
69
+ throw new Error('Missing stored value');
70
+ const key = this.data.useKeyInput ? coerceType(inputs['key'], 'string') : this.data.key;
71
+ const coercedValue = this.data.dataType === 'any' ? unwrapDataValue(inputValue).value : coerceType(inputValue, this.data.dataType);
72
+ const storedValue = cloneRivetStoredValue(coercedValue, 'Stored Value node input');
73
+ const result = await context.setStoredValue(key, storedValue);
74
+ return {
75
+ ['saved-value']: storedValueToDataValue(result.savedValue, this.data.dataType),
76
+ ['previous-value']: result.hadPreviousValue
77
+ ? storedValueToDataValue(result.previousValue, this.data.dataType)
78
+ : missingStoredValueDataValue(this.data.dataType),
79
+ ['had-previous-value']: { type: 'boolean', value: result.hadPreviousValue },
80
+ ['key']: { type: 'string', value: key },
81
+ };
82
+ }
83
+ }
84
+ export const setStoredValueNode = nodeDefinition(SetStoredValueNodeImpl, 'Set Stored Value');
@@ -0,0 +1,59 @@
1
+ import { nanoid } from 'nanoid/non-secure';
2
+ import { dedent } from 'ts-dedent';
3
+ import {} from '../NodeBase.js';
4
+ import { nodeDefinition } from '../NodeDefinition.js';
5
+ import { NodeImpl } from '../NodeImpl.js';
6
+ import { getNextVariadicPortIndex } from './variadicPortIndex.js';
7
+ export class StartBackgroundBranchNodeImpl extends NodeImpl {
8
+ static create = () => ({
9
+ type: 'startBackgroundBranch',
10
+ title: 'Start Async Branch',
11
+ id: nanoid(),
12
+ data: {},
13
+ visualData: {
14
+ x: 0,
15
+ y: 0,
16
+ width: 200,
17
+ },
18
+ });
19
+ getInputDefinitions(connections) {
20
+ const inputCount = getNextVariadicPortIndex(connections, this.chartNode.id, 'input', 'decimal');
21
+ return Array.from({ length: inputCount }, (_, index) => ({
22
+ dataType: 'any',
23
+ id: `input${index + 1}`,
24
+ title: `Async Input ${index + 1}`,
25
+ }));
26
+ }
27
+ getOutputDefinitions(connections) {
28
+ const inputCount = getNextVariadicPortIndex(connections, this.chartNode.id, 'input', 'decimal');
29
+ return Array.from({ length: Math.max(0, inputCount - 1) }, (_, index) => ({
30
+ dataType: 'any',
31
+ id: `output${index + 1}`,
32
+ title: `Async Output ${index + 1}`,
33
+ }));
34
+ }
35
+ static getUIData() {
36
+ return {
37
+ infoBoxBody: dedent `
38
+ Starts its downstream branch asynchronously. The foreground graph continues immediately, while the root run waits for the async branch before it ends.
39
+ `,
40
+ infoBoxTitle: 'Start Async Branch Node',
41
+ contextMenuTitle: 'Start Async Branch',
42
+ group: ['Logic'],
43
+ };
44
+ }
45
+ getBody() {
46
+ return 'Starts downstream asynchronously; the root run still waits';
47
+ }
48
+ async process(inputData) {
49
+ const outputs = {};
50
+ for (const [inputId, value] of Object.entries(inputData)) {
51
+ const match = /^input([1-9]\d*)$/.exec(inputId);
52
+ if (match && value != null) {
53
+ outputs[`output${match[1]}`] = value;
54
+ }
55
+ }
56
+ return outputs;
57
+ }
58
+ }
59
+ export const startBackgroundBranchNode = nodeDefinition(StartBackgroundBranchNodeImpl, 'Start Async Branch');
@@ -0,0 +1,57 @@
1
+ import { getDefaultValue, getScalarTypeOf, isArrayDataType, } from '../DataValue.js';
2
+ import { isKnowledgeDocument, isKnowledgeEvidence, isKnowledgeSourceReference, } from '../../integrations/KnowledgeStoreValidation.js';
3
+ export const portableStoredValueScalarTypes = [
4
+ 'any',
5
+ 'boolean',
6
+ 'string',
7
+ 'number',
8
+ 'date',
9
+ 'time',
10
+ 'datetime',
11
+ 'object',
12
+ 'vector',
13
+ 'knowledge-source',
14
+ 'knowledge-document',
15
+ 'knowledge-evidence',
16
+ ];
17
+ export function storedValueToDataValue(value, dataType) {
18
+ const outputValue = isStoredValueCompatibleWithDataType(value, dataType) ? value : getDefaultValue(dataType);
19
+ return { type: dataType, value: outputValue };
20
+ }
21
+ export function missingStoredValueDataValue(dataType) {
22
+ return { type: dataType, value: getDefaultValue(dataType) };
23
+ }
24
+ function isStoredValueCompatibleWithDataType(value, dataType) {
25
+ if (isArrayDataType(dataType)) {
26
+ return (Array.isArray(value) &&
27
+ value.every((item) => isStoredValueCompatibleWithScalarType(item, getScalarTypeOf(dataType))));
28
+ }
29
+ return isStoredValueCompatibleWithScalarType(value, dataType);
30
+ }
31
+ function isStoredValueCompatibleWithScalarType(value, dataType) {
32
+ switch (dataType) {
33
+ case 'any':
34
+ return true;
35
+ case 'boolean':
36
+ return typeof value === 'boolean';
37
+ case 'string':
38
+ case 'date':
39
+ case 'time':
40
+ case 'datetime':
41
+ return typeof value === 'string';
42
+ case 'number':
43
+ return typeof value === 'number' && Number.isFinite(value);
44
+ case 'object':
45
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
46
+ case 'vector':
47
+ return Array.isArray(value) && value.every((item) => typeof item === 'number' && Number.isFinite(item));
48
+ case 'knowledge-source':
49
+ return isKnowledgeSourceReference(value);
50
+ case 'knowledge-document':
51
+ return isKnowledgeDocument(value);
52
+ case 'knowledge-evidence':
53
+ return isKnowledgeEvidence(value);
54
+ default:
55
+ return false;
56
+ }
57
+ }