@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.
- package/dist/cjs/bundle.cjs +6651 -1022
- package/dist/cjs/bundle.cjs.map +4 -4
- package/dist/cjs/webAppRuntime.cjs +733 -19
- package/dist/cjs/webAppRuntime.cjs.map +3 -3
- package/dist/esm/api/createProcessor.js +6 -1
- package/dist/esm/exports.js +7 -0
- package/dist/esm/integrations/KnowledgeStore.js +1 -0
- package/dist/esm/integrations/KnowledgeStoreProvider.js +292 -0
- package/dist/esm/integrations/KnowledgeStoreValidation.js +428 -0
- package/dist/esm/integrations/ManagedKnowledgeStore.js +539 -0
- package/dist/esm/model/DataValue.js +22 -2
- package/dist/esm/model/GraphBoundaryEffects.js +13 -0
- package/dist/esm/model/GraphProcessor.js +1141 -82
- package/dist/esm/model/ManagedAsyncBranches.js +28 -0
- package/dist/esm/model/Nodes.js +27 -0
- package/dist/esm/model/ProcessContextBuilder.js +2 -1
- package/dist/esm/model/RecordingPlayer.js +9 -0
- package/dist/esm/model/StoredValueStore.js +226 -0
- package/dist/esm/model/SubprocessorBridge.js +50 -19
- package/dist/esm/model/ToolCallContinuation.js +1 -0
- package/dist/esm/model/UiGraph.js +52 -2
- package/dist/esm/model/UiGraphActionProtocol.js +10 -1
- package/dist/esm/model/UiGraphBrowserRuntime.js +444 -0
- package/dist/esm/model/UiGraphNormalization.js +35 -185
- package/dist/esm/model/UiGraphRendererStyles.js +878 -78
- package/dist/esm/model/UiGraphRuntimeModel.js +255 -15
- package/dist/esm/model/UiGraphSchema.js +91 -0
- package/dist/esm/model/UiGraphWebAppStorage.js +1 -0
- package/dist/esm/model/chat/chatMessages.js +5 -9
- package/dist/esm/model/chat/openAIChatRequest.js +8 -2
- package/dist/esm/model/chat-v2/chatV2Errors.js +36 -3
- package/dist/esm/model/chat-v2/chatV2RuntimeOptions.js +8 -8
- package/dist/esm/model/chat-v2/index.js +1 -0
- package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +3 -1
- package/dist/esm/model/chat-v2/parallelToolCalls.js +38 -0
- package/dist/esm/model/chat-v2/toolContinuation.js +45 -8
- package/dist/esm/model/chat-v2/toolContinuationConnection.js +68 -0
- package/dist/esm/model/nodes/BuildKnowledgeContextNode.js +157 -0
- package/dist/esm/model/nodes/DelegateFunctionCallNode.js +12 -40
- package/dist/esm/model/nodes/GetKnowledgeSourceStatusNode.js +79 -0
- package/dist/esm/model/nodes/GetStoredValueNode.js +109 -0
- package/dist/esm/model/nodes/KnowledgeDocumentNode.js +88 -0
- package/dist/esm/model/nodes/KnowledgeSourceNode.js +94 -0
- package/dist/esm/model/nodes/LLMChatV2Node.js +17 -1
- package/dist/esm/model/nodes/MatchNode.js +7 -7
- package/dist/esm/model/nodes/SearchKnowledgeNode.js +127 -0
- package/dist/esm/model/nodes/SetStoredValueNode.js +84 -0
- package/dist/esm/model/nodes/StartBackgroundBranchNode.js +59 -0
- package/dist/esm/model/nodes/StoredValueNodeUtils.js +57 -0
- package/dist/esm/model/nodes/SyncKnowledgeSourceNode.js +149 -0
- package/dist/esm/model/nodes/ToolNode.js +14 -0
- package/dist/esm/model/nodes/toolCallDelegation.js +44 -1
- package/dist/esm/plugins/pinecone/PineconeKnowledgeStore.js +553 -0
- package/dist/esm/plugins/pinecone/plugin.js +32 -0
- package/dist/esm/recording/ExecutionRecorder.js +1 -0
- package/dist/esm/utils/coerceType.js +27 -2
- package/dist/esm/utils/getPluginConfig.js +12 -6
- package/dist/esm/utils/serialization/serialization.js +4 -1
- package/dist/esm/utils/serialization/serializationUtils.js +59 -1
- package/dist/esm/webAppRuntime.js +3 -3
- package/dist/types/api/createProcessor.d.ts +6 -0
- package/dist/types/exports.d.ts +7 -0
- package/dist/types/integrations/KnowledgeStore.d.ts +131 -0
- package/dist/types/integrations/KnowledgeStoreProvider.d.ts +46 -0
- package/dist/types/integrations/KnowledgeStoreValidation.d.ts +16 -0
- package/dist/types/integrations/ManagedKnowledgeStore.d.ts +57 -0
- package/dist/types/model/DataValue.d.ts +10 -3
- package/dist/types/model/EditorDefinition.d.ts +9 -2
- package/dist/types/model/ExecutorProtocol.d.ts +12 -0
- package/dist/types/model/GraphBoundaryEffects.d.ts +9 -1
- package/dist/types/model/GraphProcessor.d.ts +21 -2
- package/dist/types/model/ManagedAsyncBranches.d.ts +6 -0
- package/dist/types/model/Nodes.d.ts +11 -2
- package/dist/types/model/ProcessContext.d.ts +18 -0
- package/dist/types/model/ProcessContextBuilder.d.ts +2 -1
- package/dist/types/model/Project.d.ts +11 -0
- package/dist/types/model/StoredValueStore.d.ts +55 -0
- package/dist/types/model/SubprocessorBridge.d.ts +4 -2
- package/dist/types/model/ToolCallContinuation.d.ts +13 -0
- package/dist/types/model/UiGraph.d.ts +24 -1
- package/dist/types/model/UiGraphActionProtocol.d.ts +2 -0
- package/dist/types/model/UiGraphBrowserRuntime.d.ts +75 -0
- package/dist/types/model/UiGraphRendererStyles.d.ts +2 -2
- package/dist/types/model/UiGraphRuntimeModel.d.ts +22 -3
- package/dist/types/model/UiGraphSchema.d.ts +113 -0
- package/dist/types/model/UiGraphWebAppStorage.d.ts +3 -0
- package/dist/types/model/chat-v2/index.d.ts +1 -0
- package/dist/types/model/chat-v2/parallelToolCalls.d.ts +9 -0
- package/dist/types/model/chat-v2/toolContinuation.d.ts +1 -0
- package/dist/types/model/chat-v2/toolContinuationConnection.d.ts +28 -0
- package/dist/types/model/nodes/BuildKnowledgeContextNode.d.ts +23 -0
- package/dist/types/model/nodes/GetKnowledgeSourceStatusNode.d.ts +19 -0
- package/dist/types/model/nodes/GetStoredValueNode.d.ts +25 -0
- package/dist/types/model/nodes/KnowledgeDocumentNode.d.ts +26 -0
- package/dist/types/model/nodes/KnowledgeSourceNode.d.ts +25 -0
- package/dist/types/model/nodes/SearchKnowledgeNode.d.ts +25 -0
- package/dist/types/model/nodes/SetStoredValueNode.d.ts +23 -0
- package/dist/types/model/nodes/StartBackgroundBranchNode.d.ts +14 -0
- package/dist/types/model/nodes/StoredValueNodeUtils.d.ts +5 -0
- package/dist/types/model/nodes/SyncKnowledgeSourceNode.d.ts +27 -0
- package/dist/types/model/nodes/ToolNode.d.ts +2 -0
- package/dist/types/model/nodes/toolCallDelegation.d.ts +4 -0
- package/dist/types/plugins/pinecone/PineconeKnowledgeStore.d.ts +11 -0
- package/dist/types/recording/RecordedEvents.d.ts +5 -0
- package/dist/types/utils/serialization/serializationUtils.d.ts +4 -0
- package/dist/types/webAppRuntime.d.ts +5 -4
- package/package.json +1 -1
|
@@ -0,0 +1,149 @@
|
|
|
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, normalizeKnowledgeSourceReference, normalizeSyncKnowledgeSourceResult, } from '../../integrations/KnowledgeStoreValidation.js';
|
|
7
|
+
export class SyncKnowledgeSourceNodeImpl extends NodeImpl {
|
|
8
|
+
static create() {
|
|
9
|
+
return {
|
|
10
|
+
id: nanoid(),
|
|
11
|
+
type: 'syncKnowledgeSource',
|
|
12
|
+
title: 'Sync Knowledge Source',
|
|
13
|
+
visualData: { x: 0, y: 0, width: 290 },
|
|
14
|
+
data: {
|
|
15
|
+
metadata: {},
|
|
16
|
+
useMetadataInput: false,
|
|
17
|
+
forceRefresh: false,
|
|
18
|
+
useForceRefreshInput: false,
|
|
19
|
+
chunkUnit: 'characters',
|
|
20
|
+
targetSize: 2600,
|
|
21
|
+
overlap: 260,
|
|
22
|
+
minimumBoundarySize: 1400,
|
|
23
|
+
includeTitle: true,
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
getInputDefinitions() {
|
|
28
|
+
const inputs = [
|
|
29
|
+
{ id: 'source', title: 'Source', dataType: 'knowledge-source', required: true },
|
|
30
|
+
{
|
|
31
|
+
id: 'documents',
|
|
32
|
+
title: 'Documents',
|
|
33
|
+
dataType: ['string', 'string[]', 'knowledge-document', 'knowledge-document[]'],
|
|
34
|
+
required: true,
|
|
35
|
+
},
|
|
36
|
+
];
|
|
37
|
+
if (this.data.useMetadataInput)
|
|
38
|
+
inputs.push({ id: 'metadata', title: 'Source Metadata', dataType: 'object' });
|
|
39
|
+
if (this.data.useForceRefreshInput)
|
|
40
|
+
inputs.push({ id: 'force-refresh', title: 'Force Refresh', dataType: 'boolean' });
|
|
41
|
+
return inputs;
|
|
42
|
+
}
|
|
43
|
+
getOutputDefinitions() {
|
|
44
|
+
return [
|
|
45
|
+
{ id: 'source', title: 'Resolved Source', dataType: 'knowledge-source' },
|
|
46
|
+
{ id: 'result', title: 'Result', dataType: 'string' },
|
|
47
|
+
{ id: 'document-count', title: 'Document Count', dataType: 'number' },
|
|
48
|
+
{ id: 'chunk-count', title: 'Chunk Count', dataType: 'number' },
|
|
49
|
+
{ id: 'previous-version', title: 'Previous Version', dataType: 'string' },
|
|
50
|
+
{ id: 'warnings', title: 'Warnings', dataType: 'string[]' },
|
|
51
|
+
];
|
|
52
|
+
}
|
|
53
|
+
getEditors() {
|
|
54
|
+
return [
|
|
55
|
+
{
|
|
56
|
+
type: 'jsonObject',
|
|
57
|
+
dataKey: 'metadata',
|
|
58
|
+
useInputToggleDataKey: 'useMetadataInput',
|
|
59
|
+
label: 'Source Metadata',
|
|
60
|
+
helperMessage: 'Enter a flat JSON object, or leave {} when the source has no metadata.',
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
type: 'toggle',
|
|
64
|
+
dataKey: 'forceRefresh',
|
|
65
|
+
useInputToggleDataKey: 'useForceRefreshInput',
|
|
66
|
+
label: 'Force Refresh',
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
type: 'dropdown',
|
|
70
|
+
dataKey: 'chunkUnit',
|
|
71
|
+
label: 'Chunk Size Unit',
|
|
72
|
+
options: [
|
|
73
|
+
{ value: 'characters', label: 'Characters' },
|
|
74
|
+
{ value: 'tokens', label: 'Tokens' },
|
|
75
|
+
],
|
|
76
|
+
},
|
|
77
|
+
{ type: 'number', dataKey: 'targetSize', label: 'Target Chunk Size', min: 100, max: 100000 },
|
|
78
|
+
{ type: 'number', dataKey: 'overlap', label: 'Chunk Overlap', min: 0, max: 99999 },
|
|
79
|
+
{ type: 'number', dataKey: 'minimumBoundarySize', label: 'Minimum Boundary Size', min: 1, max: 100000 },
|
|
80
|
+
{ type: 'toggle', dataKey: 'includeTitle', label: 'Include Title In Indexed Text' },
|
|
81
|
+
];
|
|
82
|
+
}
|
|
83
|
+
getBody() {
|
|
84
|
+
return dedent `
|
|
85
|
+
${this.data.targetSize} ${this.data.chunkUnit}
|
|
86
|
+
${this.data.overlap} overlap
|
|
87
|
+
${this.data.includeTitle ? 'Includes titles' : 'Content only'}
|
|
88
|
+
`;
|
|
89
|
+
}
|
|
90
|
+
static getUIData() {
|
|
91
|
+
return {
|
|
92
|
+
contextMenuTitle: 'Sync Knowledge Source',
|
|
93
|
+
infoBoxTitle: 'Sync Knowledge Source Node',
|
|
94
|
+
infoBoxBody: 'Idempotently chunks and activates a complete immutable version of a knowledge source.',
|
|
95
|
+
group: 'Knowledge',
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
async process(inputs, context) {
|
|
99
|
+
const source = normalizeKnowledgeSourceReference(coerceType(inputs['source'], 'knowledge-source'));
|
|
100
|
+
const documents = normalizeDocumentsInput(inputs['documents']);
|
|
101
|
+
const metadataRaw = this.data.useMetadataInput
|
|
102
|
+
? coerceType(inputs['metadata'], 'object')
|
|
103
|
+
: this.data.metadata;
|
|
104
|
+
const metadata = normalizeKnowledgeMetadata(metadataRaw, 'Source metadata');
|
|
105
|
+
const forceRefresh = this.data.useForceRefreshInput
|
|
106
|
+
? coerceType(inputs['force-refresh'], 'boolean')
|
|
107
|
+
: this.data.forceRefresh;
|
|
108
|
+
const store = await context.getKnowledgeStore(source.connectionId);
|
|
109
|
+
const result = normalizeSyncKnowledgeSourceResult(await store.syncSource({
|
|
110
|
+
source,
|
|
111
|
+
documents,
|
|
112
|
+
metadata,
|
|
113
|
+
forceRefresh,
|
|
114
|
+
chunking: {
|
|
115
|
+
unit: this.data.chunkUnit,
|
|
116
|
+
targetSize: this.data.targetSize,
|
|
117
|
+
overlap: this.data.overlap,
|
|
118
|
+
minimumBoundarySize: this.data.minimumBoundarySize,
|
|
119
|
+
includeTitle: this.data.includeTitle,
|
|
120
|
+
},
|
|
121
|
+
}, {
|
|
122
|
+
signal: context.signal,
|
|
123
|
+
reportProgress: context.reportProgress,
|
|
124
|
+
getTokenCount: (text) => context.tokenizer.getTokenCountForString(text, { node: context.node }),
|
|
125
|
+
}), source);
|
|
126
|
+
return {
|
|
127
|
+
['source']: { type: 'knowledge-source', value: result.source },
|
|
128
|
+
['result']: { type: 'string', value: result.result },
|
|
129
|
+
['document-count']: { type: 'number', value: result.documentCount },
|
|
130
|
+
['chunk-count']: { type: 'number', value: result.chunkCount },
|
|
131
|
+
['previous-version']: { type: 'string', value: result.previousVersion ?? '' },
|
|
132
|
+
['warnings']: { type: 'string[]', value: result.warnings },
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function normalizeDocumentsInput(value) {
|
|
137
|
+
if (!value)
|
|
138
|
+
throw new Error('Sync Knowledge Source is missing its Documents input.');
|
|
139
|
+
if (value.type === 'string')
|
|
140
|
+
return [normalizeKnowledgeDocument(value.value, 0)];
|
|
141
|
+
if (value.type === 'string[]')
|
|
142
|
+
return value.value.map((document, index) => normalizeKnowledgeDocument(document, index));
|
|
143
|
+
if (value.type === 'knowledge-document')
|
|
144
|
+
return [normalizeKnowledgeDocument(value.value, 0)];
|
|
145
|
+
if (value.type === 'knowledge-document[]')
|
|
146
|
+
return value.value.map((document, index) => normalizeKnowledgeDocument(document, index));
|
|
147
|
+
throw new Error(`Sync Knowledge Source cannot use ${value.type} as Documents.`);
|
|
148
|
+
}
|
|
149
|
+
export const syncKnowledgeSourceNode = nodeDefinition(SyncKnowledgeSourceNodeImpl, 'Sync Knowledge Source');
|
|
@@ -24,6 +24,7 @@ export class GptFunctionNodeImpl extends NodeImpl {
|
|
|
24
24
|
data: {
|
|
25
25
|
name: 'newTool',
|
|
26
26
|
description: 'No description provided',
|
|
27
|
+
resultHandling: 'continue',
|
|
27
28
|
schema: dedent `
|
|
28
29
|
{
|
|
29
30
|
"type": "object",
|
|
@@ -105,6 +106,17 @@ export class GptFunctionNodeImpl extends NodeImpl {
|
|
|
105
106
|
theme: 'prompt-interpolation',
|
|
106
107
|
height: 100,
|
|
107
108
|
},
|
|
109
|
+
{
|
|
110
|
+
type: 'dropdown',
|
|
111
|
+
label: 'Result handling',
|
|
112
|
+
dataKey: 'resultHandling',
|
|
113
|
+
defaultValue: 'continue',
|
|
114
|
+
options: [
|
|
115
|
+
{ label: 'Continue with LLM', value: 'continue' },
|
|
116
|
+
{ label: 'Return directly', value: 'return-direct' },
|
|
117
|
+
],
|
|
118
|
+
helperMessage: 'Return directly uses the handler output as the final LLM Chat response when it is the only tool call in an auto-continued round.',
|
|
119
|
+
},
|
|
108
120
|
{
|
|
109
121
|
type: 'code',
|
|
110
122
|
label: 'Schema',
|
|
@@ -141,6 +153,7 @@ export class GptFunctionNodeImpl extends NodeImpl {
|
|
|
141
153
|
async process(inputs) {
|
|
142
154
|
const name = getInputOrData(this.data, inputs, 'name');
|
|
143
155
|
const description = getInputOrData(this.data, inputs, 'description');
|
|
156
|
+
const resultHandling = this.data.resultHandling === 'return-direct' ? 'return-direct' : 'continue';
|
|
144
157
|
let schema;
|
|
145
158
|
if (this.data.useSchemaInput) {
|
|
146
159
|
schema = coerceType(inputs['schema'], 'object');
|
|
@@ -165,6 +178,7 @@ export class GptFunctionNodeImpl extends NodeImpl {
|
|
|
165
178
|
description,
|
|
166
179
|
parameters: schema,
|
|
167
180
|
strict: this.data.strict ?? false,
|
|
181
|
+
resultHandling,
|
|
168
182
|
},
|
|
169
183
|
},
|
|
170
184
|
};
|
|
@@ -19,6 +19,44 @@ export function isDelegatedToolCallRecord(input) {
|
|
|
19
19
|
typeof maybeMessage.name === 'string' &&
|
|
20
20
|
(maybeMessage.toolName == null || typeof maybeMessage.toolName === 'string'));
|
|
21
21
|
}
|
|
22
|
+
export function buildDelegatedToolCallOutputs(records, preToolMessage, cost) {
|
|
23
|
+
const preToolMessageOutput = preToolMessage == null
|
|
24
|
+
? {
|
|
25
|
+
type: 'control-flow-excluded',
|
|
26
|
+
value: undefined,
|
|
27
|
+
}
|
|
28
|
+
: {
|
|
29
|
+
type: 'string',
|
|
30
|
+
value: preToolMessage,
|
|
31
|
+
};
|
|
32
|
+
const outputs = records.length === 1
|
|
33
|
+
? {
|
|
34
|
+
['output']: {
|
|
35
|
+
type: 'string',
|
|
36
|
+
value: records[0].output,
|
|
37
|
+
},
|
|
38
|
+
['message']: {
|
|
39
|
+
type: 'chat-message',
|
|
40
|
+
value: records[0].message,
|
|
41
|
+
},
|
|
42
|
+
['assistant-message']: preToolMessageOutput,
|
|
43
|
+
}
|
|
44
|
+
: {
|
|
45
|
+
['output']: {
|
|
46
|
+
type: 'string[]',
|
|
47
|
+
value: records.map((record) => record.output),
|
|
48
|
+
},
|
|
49
|
+
['message']: {
|
|
50
|
+
type: 'chat-message[]',
|
|
51
|
+
value: records.map((record) => record.message),
|
|
52
|
+
},
|
|
53
|
+
['assistant-message']: preToolMessageOutput,
|
|
54
|
+
};
|
|
55
|
+
if (cost != null) {
|
|
56
|
+
outputs['cost'] = { type: 'number', value: cost };
|
|
57
|
+
}
|
|
58
|
+
return outputs;
|
|
59
|
+
}
|
|
22
60
|
export function normalizeFunctionCallInput(input) {
|
|
23
61
|
if (Array.isArray(input)) {
|
|
24
62
|
if (input.length !== 1) {
|
|
@@ -84,7 +122,9 @@ export async function delegateToolCall(rawFunctionCall, context, config) {
|
|
|
84
122
|
const functionCall = normalizeFunctionCallInput(rawFunctionCall);
|
|
85
123
|
let handler;
|
|
86
124
|
if (config.autoDelegate) {
|
|
87
|
-
const
|
|
125
|
+
const graphs = Object.values(context.project.graphs);
|
|
126
|
+
const matchingGraph = graphs.find((graph) => graph.metadata?.name === functionCall.name) ??
|
|
127
|
+
graphs.find((graph) => graph.metadata?.name?.includes(functionCall.name));
|
|
88
128
|
if (matchingGraph) {
|
|
89
129
|
handler = { key: undefined, value: matchingGraph.metadata.id };
|
|
90
130
|
}
|
|
@@ -104,6 +144,7 @@ export async function delegateToolCall(rawFunctionCall, context, config) {
|
|
|
104
144
|
outputString,
|
|
105
145
|
message: buildToolResultMessage(functionCall, outputString),
|
|
106
146
|
record: buildDelegatedToolCallRecord(functionCall, outputString),
|
|
147
|
+
cost: result.cost,
|
|
107
148
|
};
|
|
108
149
|
}
|
|
109
150
|
catch (error) {
|
|
@@ -151,9 +192,11 @@ export async function delegateToolCall(rawFunctionCall, context, config) {
|
|
|
151
192
|
const subprocessor = context.createSubProcessor(handler.value, { signal: context.signal });
|
|
152
193
|
const outputs = await subprocessor.processGraph(context, subgraphInputs, context.contextValues);
|
|
153
194
|
const outputString = coerceTypeOptional(outputs['output'], 'string') ?? '';
|
|
195
|
+
const cost = coerceTypeOptional(outputs['cost'], 'number');
|
|
154
196
|
return {
|
|
155
197
|
outputString,
|
|
156
198
|
message: buildToolResultMessage(functionCall, outputString),
|
|
157
199
|
record: buildDelegatedToolCallRecord(functionCall, outputString),
|
|
200
|
+
cost,
|
|
158
201
|
};
|
|
159
202
|
}
|