@alpic80/rivet-core 1.19.1-aidon.2 → 1.24.0-aidon.1
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/README.md +4 -0
- package/dist/cjs/bundle.cjs +4187 -1020
- package/dist/cjs/bundle.cjs.map +4 -4
- package/dist/esm/api/createProcessor.js +8 -17
- package/dist/esm/api/looseDataValue.js +16 -0
- package/dist/esm/exports.js +2 -0
- package/dist/esm/integrations/CodeRunner.js +36 -0
- package/dist/esm/integrations/GptTokenizerTokenizer.js +7 -4
- package/dist/esm/integrations/openai/OpenAIEmbeddingGenerator.js +1 -1
- package/dist/esm/model/DataValue.js +14 -2
- package/dist/esm/model/GraphProcessor.js +275 -104
- package/dist/esm/model/NodeBase.js +11 -1
- package/dist/esm/model/NodeImpl.js +8 -0
- package/dist/esm/model/Nodes.js +31 -4
- package/dist/esm/model/ProjectReferenceLoader.js +1 -0
- package/dist/esm/model/nodes/AssembleMessageNode.js +12 -2
- package/dist/esm/model/nodes/AssemblePromptNode.js +22 -0
- package/dist/esm/model/nodes/CallGraphNode.js +3 -4
- package/dist/esm/model/nodes/ChatLoopNode.js +150 -0
- package/dist/esm/model/nodes/ChatNode.js +7 -934
- package/dist/esm/model/nodes/ChatNodeBase.js +1275 -0
- package/dist/esm/model/nodes/ChunkNode.js +2 -2
- package/dist/esm/model/nodes/CodeNode.js +40 -4
- package/dist/esm/model/nodes/CronNode.js +248 -0
- package/dist/esm/model/nodes/DelegateFunctionCallNode.js +37 -12
- package/dist/esm/model/nodes/DestructureNode.js +1 -1
- package/dist/esm/model/nodes/DocumentNode.js +183 -0
- package/dist/esm/model/nodes/ExtractJsonNode.js +4 -4
- package/dist/esm/model/nodes/ExtractRegexNode.js +10 -11
- package/dist/esm/model/nodes/GetEmbeddingNode.js +1 -1
- package/dist/esm/model/nodes/HttpCallNode.js +3 -1
- package/dist/esm/model/nodes/IfNode.js +5 -0
- package/dist/esm/model/nodes/ImageToMDNode.js +116 -0
- package/dist/esm/model/nodes/LoopUntilNode.js +214 -0
- package/dist/esm/model/nodes/PromptNode.js +29 -6
- package/dist/esm/model/nodes/ReadAllFilesNode.js +210 -0
- package/dist/esm/model/nodes/ReadDirectoryNode.js +31 -25
- package/dist/esm/model/nodes/ReferencedGraphAliasNode.js +199 -0
- package/dist/esm/model/nodes/TextNode.js +9 -4
- package/dist/esm/model/nodes/ToMarkdownTableNode.js +119 -0
- package/dist/esm/model/nodes/ToTreeNode.js +133 -0
- package/dist/esm/model/nodes/{GptFunctionNode.js → ToolNode.js} +10 -10
- package/dist/esm/model/nodes/UserInputNode.js +10 -12
- package/dist/esm/plugins/aidon/nodes/ChatAidonNode.js +3 -3
- package/dist/esm/plugins/anthropic/anthropic.js +29 -10
- package/dist/esm/plugins/anthropic/fetchEventSource.js +3 -2
- package/dist/esm/plugins/anthropic/nodes/ChatAnthropicNode.js +267 -147
- package/dist/esm/plugins/anthropic/plugin.js +9 -1
- package/dist/esm/plugins/gentrace/plugin.js +6 -6
- package/dist/esm/plugins/google/google.js +113 -5
- package/dist/esm/plugins/google/nodes/ChatGoogleNode.js +211 -54
- package/dist/esm/plugins/google/plugin.js +13 -6
- package/dist/esm/plugins/openai/nodes/RunThreadNode.js +2 -2
- package/dist/esm/recording/ExecutionRecorder.js +5 -1
- package/dist/esm/utils/chatMessageToOpenAIChatCompletionMessage.js +15 -2
- package/dist/esm/utils/coerceType.js +1 -1
- package/dist/esm/utils/fetchEventSource.js +1 -1
- package/dist/esm/utils/interpolation.js +108 -3
- package/dist/esm/utils/openai.js +106 -50
- package/dist/esm/utils/paths.js +80 -0
- package/dist/esm/utils/serialization/serialization_v4.js +5 -0
- package/dist/types/api/createProcessor.d.ts +11 -5
- package/dist/types/api/looseDataValue.d.ts +4 -0
- package/dist/types/api/streaming.d.ts +1 -1
- package/dist/types/exports.d.ts +2 -0
- package/dist/types/integrations/CodeRunner.d.ts +18 -0
- package/dist/types/model/DataValue.d.ts +29 -6
- package/dist/types/model/EditorDefinition.d.ts +6 -1
- package/dist/types/model/GraphProcessor.d.ts +14 -7
- package/dist/types/model/NodeBase.d.ts +4 -0
- package/dist/types/model/NodeImpl.d.ts +5 -4
- package/dist/types/model/Nodes.d.ts +13 -4
- package/dist/types/model/ProcessContext.d.ts +16 -1
- package/dist/types/model/Project.d.ts +19 -7
- package/dist/types/model/ProjectReferenceLoader.d.ts +5 -0
- package/dist/types/model/RivetPlugin.d.ts +6 -0
- package/dist/types/model/RivetUIContext.d.ts +5 -1
- package/dist/types/model/Settings.d.ts +1 -0
- package/dist/types/model/nodes/AssemblePromptNode.d.ts +4 -1
- package/dist/types/model/nodes/ChatLoopNode.d.ts +21 -0
- package/dist/types/model/nodes/ChatNode.d.ts +2 -62
- package/dist/types/model/nodes/ChatNodeBase.d.ts +85 -0
- package/dist/types/model/nodes/CodeNode.d.ts +8 -2
- package/dist/types/model/nodes/CronNode.d.ts +34 -0
- package/dist/types/model/nodes/DelegateFunctionCallNode.d.ts +1 -0
- package/dist/types/model/nodes/DocumentNode.d.ts +28 -0
- package/dist/types/model/nodes/ImageToMDNode.d.ts +20 -0
- package/dist/types/model/nodes/LoopUntilNode.d.ts +32 -0
- package/dist/types/model/nodes/PromptNode.d.ts +2 -0
- package/dist/types/model/nodes/ReadAllFilesNode.d.ts +30 -0
- package/dist/types/model/nodes/ReadDirectoryNode.d.ts +1 -1
- package/dist/types/model/nodes/ReferencedGraphAliasNode.d.ts +31 -0
- package/dist/types/model/nodes/ToMarkdownTableNode.d.ts +19 -0
- package/dist/types/model/nodes/ToTreeNode.d.ts +21 -0
- package/dist/types/model/nodes/UserInputNode.d.ts +2 -3
- package/dist/types/plugins/anthropic/anthropic.d.ts +94 -13
- package/dist/types/plugins/anthropic/nodes/ChatAnthropicNode.d.ts +7 -2
- package/dist/types/plugins/google/google.d.ts +93 -18
- package/dist/types/plugins/google/nodes/ChatGoogleNode.d.ts +3 -2
- package/dist/types/recording/RecordedEvents.d.ts +2 -0
- package/dist/types/utils/base64.d.ts +1 -1
- package/dist/types/utils/chatMessageToOpenAIChatCompletionMessage.d.ts +3 -1
- package/dist/types/utils/interpolation.d.ts +3 -0
- package/dist/types/utils/openai.d.ts +127 -21
- package/dist/types/utils/paths.d.ts +8 -0
- package/package.json +15 -11
- /package/dist/types/model/nodes/{GptFunctionNode.d.ts → ToolNode.d.ts} +0 -0
|
@@ -1,24 +1,9 @@
|
|
|
1
1
|
import {} from '../index.js';
|
|
2
|
-
import { mapValues } from '../utils/typeSafety.js';
|
|
3
2
|
import { getProcessorEvents, getProcessorSSEStream, getSingleNodeStream } from './streaming.js';
|
|
4
3
|
import { GraphProcessor } from '../model/GraphProcessor.js';
|
|
5
4
|
import { deserializeProject } from '../utils/serialization/serialization.js';
|
|
6
5
|
import { DEFAULT_CHAT_NODE_TIMEOUT } from '../utils/defaults.js';
|
|
7
|
-
|
|
8
|
-
return mapValues(values, (val) => looseDataValueToDataValue(val));
|
|
9
|
-
}
|
|
10
|
-
export function looseDataValueToDataValue(value) {
|
|
11
|
-
if (typeof value === 'string') {
|
|
12
|
-
return { type: 'string', value };
|
|
13
|
-
}
|
|
14
|
-
if (typeof value === 'number') {
|
|
15
|
-
return { type: 'number', value };
|
|
16
|
-
}
|
|
17
|
-
if (typeof value === 'boolean') {
|
|
18
|
-
return { type: 'boolean', value };
|
|
19
|
-
}
|
|
20
|
-
return value;
|
|
21
|
-
}
|
|
6
|
+
import { looseDataValuesToDataValues } from './looseDataValue.js';
|
|
22
7
|
export function coreCreateProcessor(project, options) {
|
|
23
8
|
const { graph, inputs = {}, context = {} } = options;
|
|
24
9
|
const graphId = graph
|
|
@@ -29,7 +14,8 @@ export function coreCreateProcessor(project, options) {
|
|
|
29
14
|
if (!graphId) {
|
|
30
15
|
throw new Error(`Graph not found, and no main graph specified.`);
|
|
31
16
|
}
|
|
32
|
-
|
|
17
|
+
// TODO: Consolidate options into one object
|
|
18
|
+
const processor = new GraphProcessor(project, graphId, options.registry, options.includeTrace);
|
|
33
19
|
if (options.onStart) {
|
|
34
20
|
processor.on('start', options.onStart);
|
|
35
21
|
}
|
|
@@ -86,6 +72,7 @@ export function coreCreateProcessor(project, options) {
|
|
|
86
72
|
}
|
|
87
73
|
}
|
|
88
74
|
options.abortSignal?.addEventListener('abort', () => {
|
|
75
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
89
76
|
processor.abort();
|
|
90
77
|
});
|
|
91
78
|
const resolvedInputs = looseDataValuesToDataValues(inputs);
|
|
@@ -102,6 +89,9 @@ export function coreCreateProcessor(project, options) {
|
|
|
102
89
|
nativeApi: options.nativeApi,
|
|
103
90
|
datasetProvider: options.datasetProvider,
|
|
104
91
|
audioProvider: options.audioProvider,
|
|
92
|
+
codeRunner: options.codeRunner,
|
|
93
|
+
projectPath: options.projectPath,
|
|
94
|
+
projectReferenceLoader: options.projectReferenceLoader,
|
|
105
95
|
settings: {
|
|
106
96
|
openAiKey: options.openAiKey ?? '',
|
|
107
97
|
openAiOrganization: options.openAiOrganization ?? '',
|
|
@@ -111,6 +101,7 @@ export function coreCreateProcessor(project, options) {
|
|
|
111
101
|
recordingPlaybackLatency: 1000,
|
|
112
102
|
chatNodeHeaders: options.chatNodeHeaders ?? {},
|
|
113
103
|
chatNodeTimeout: options.chatNodeTimeout ?? DEFAULT_CHAT_NODE_TIMEOUT,
|
|
104
|
+
throttleChatNode: options.throttleChatNode ?? 100,
|
|
114
105
|
},
|
|
115
106
|
getChatNodeEndpoint: options.getChatNodeEndpoint,
|
|
116
107
|
}, resolvedInputs, resolvedContextValues);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { mapValues } from 'lodash-es';
|
|
2
|
+
export function looseDataValuesToDataValues(values) {
|
|
3
|
+
return mapValues(values, (val) => looseDataValueToDataValue(val));
|
|
4
|
+
}
|
|
5
|
+
export function looseDataValueToDataValue(value) {
|
|
6
|
+
if (typeof value === 'string') {
|
|
7
|
+
return { type: 'string', value };
|
|
8
|
+
}
|
|
9
|
+
if (typeof value === 'number') {
|
|
10
|
+
return { type: 'number', value };
|
|
11
|
+
}
|
|
12
|
+
if (typeof value === 'boolean') {
|
|
13
|
+
return { type: 'boolean', value };
|
|
14
|
+
}
|
|
15
|
+
return value;
|
|
16
|
+
}
|
package/dist/esm/exports.js
CHANGED
|
@@ -28,5 +28,7 @@ export * from './model/Dataset.js';
|
|
|
28
28
|
export * from './api/streaming.js';
|
|
29
29
|
export * from './api/createProcessor.js';
|
|
30
30
|
export * from './integrations/AudioProvider.js';
|
|
31
|
+
export * from './api/looseDataValue.js';
|
|
32
|
+
export * from './integrations/CodeRunner.js';
|
|
31
33
|
import * as openai from './utils/openai.js';
|
|
32
34
|
export { openai };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// eslint-disable-next-line import/no-cycle -- There has to be a cycle if we're to import the entirety of Rivet here.
|
|
2
|
+
import * as Rivet from '../exports.js';
|
|
3
|
+
export class IsomorphicCodeRunner {
|
|
4
|
+
async runCode(code, inputs, options) {
|
|
5
|
+
const argNames = ['inputs'];
|
|
6
|
+
const args = [inputs];
|
|
7
|
+
if (options.includeRequire) {
|
|
8
|
+
throw new Error('require() requires the Node executor.');
|
|
9
|
+
}
|
|
10
|
+
if (options.includeProcess) {
|
|
11
|
+
throw new Error('process requires the Node executor.');
|
|
12
|
+
}
|
|
13
|
+
if (options.includeConsole) {
|
|
14
|
+
argNames.push('console');
|
|
15
|
+
args.push(console);
|
|
16
|
+
}
|
|
17
|
+
if (options.includeFetch) {
|
|
18
|
+
argNames.push('fetch');
|
|
19
|
+
args.push(fetch);
|
|
20
|
+
}
|
|
21
|
+
if (options.includeRivet) {
|
|
22
|
+
argNames.push('Rivet');
|
|
23
|
+
args.push(Rivet);
|
|
24
|
+
}
|
|
25
|
+
argNames.push(code);
|
|
26
|
+
const AsyncFunction = async function () { }.constructor;
|
|
27
|
+
const codeFunction = new AsyncFunction(...argNames);
|
|
28
|
+
const outputs = await codeFunction(...args);
|
|
29
|
+
return outputs;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export class NotAllowedCodeRunner {
|
|
33
|
+
async runCode(_code, _inputs, _options) {
|
|
34
|
+
throw new Error('Dynamic code execution is disabled.');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -13,10 +13,12 @@ export class GptTokenizerTokenizer {
|
|
|
13
13
|
}
|
|
14
14
|
async getTokenCountForMessages(messages, functions, _info) {
|
|
15
15
|
try {
|
|
16
|
-
const openaiMessages = await Promise.all(messages.map((message) => chatMessageToOpenAIChatCompletionMessage(message)));
|
|
17
|
-
const validMessages = openaiMessages
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
const openaiMessages = await Promise.all(messages.map((message) => chatMessageToOpenAIChatCompletionMessage(message, { isReasoningModel: false })));
|
|
17
|
+
const validMessages = openaiMessages.map((message) => {
|
|
18
|
+
// Tools not supported to calculate token count so we convert them to user messages
|
|
19
|
+
if (message.role === 'tool') {
|
|
20
|
+
return { role: 'user', content: message.content };
|
|
21
|
+
}
|
|
20
22
|
if (Array.isArray(message.content)) {
|
|
21
23
|
const textContent = message.content
|
|
22
24
|
.filter((c) => c.type === 'text')
|
|
@@ -32,6 +34,7 @@ export class GptTokenizerTokenizer {
|
|
|
32
34
|
return encodedChat.length + encodedFunctions.length;
|
|
33
35
|
}
|
|
34
36
|
catch (err) {
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
35
38
|
this.emitter.emit('error', getError(err));
|
|
36
39
|
return 0;
|
|
37
40
|
}
|
|
@@ -15,7 +15,7 @@ export class OpenAIEmbeddingGenerator {
|
|
|
15
15
|
const response = await api.embeddings.create({
|
|
16
16
|
input: text,
|
|
17
17
|
model: options?.model ?? 'text-embedding-ada-002',
|
|
18
|
-
dimensions: options?.dimensions
|
|
18
|
+
dimensions: options?.dimensions,
|
|
19
19
|
});
|
|
20
20
|
const embeddings = response.data;
|
|
21
21
|
return embeddings[0].embedding;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { exhaustiveTuple } from '../utils/genericUtilFunctions.js';
|
|
2
|
-
export const dataTypes = exhaustiveTuple()('any', 'any[]', 'boolean', 'boolean[]', 'string', 'string[]', 'number', 'number[]', 'date', 'date[]', 'time', 'time[]', 'datetime', 'datetime[]', 'chat-message', 'chat-message[]', 'control-flow-excluded', 'control-flow-excluded[]', 'object', 'object[]', 'fn<string>', 'fn<number>', 'fn<boolean>', 'fn<date>', 'fn<time>', 'fn<datetime>', 'fn<any>', 'fn<object>', 'fn<chat-message>', 'fn<control-flow-excluded>', 'fn<string[]>', 'fn<number[]>', 'fn<boolean[]>', 'fn<date[]>', 'fn<time[]>', 'fn<datetime[]>', 'fn<any[]>', 'fn<object[]>', 'fn<chat-message[]>', 'fn<control-flow-excluded[]>', 'gpt-function', 'gpt-function[]', 'fn<gpt-function[]>', 'fn<gpt-function>', 'vector', 'vector[]', 'fn<vector>', 'fn<vector[]>', 'image', 'image[]', 'fn<image>', 'fn<image[]>', 'binary', 'binary[]', 'fn<binary>', 'fn<binary[]>', 'audio', 'audio[]', 'fn<audio>', 'fn<audio[]>', 'graph-reference', 'graph-reference[]', 'fn<graph-reference>', 'fn<graph-reference[]>');
|
|
3
|
-
export const scalarTypes = exhaustiveTuple()('any', 'boolean', 'string', 'number', 'date', 'time', 'datetime', 'chat-message', 'control-flow-excluded', 'object', 'gpt-function', 'vector', 'image', 'binary', 'audio', 'graph-reference');
|
|
2
|
+
export const dataTypes = exhaustiveTuple()('any', 'any[]', 'boolean', 'boolean[]', 'string', 'string[]', 'number', 'number[]', 'date', 'date[]', 'time', 'time[]', 'datetime', 'datetime[]', 'chat-message', 'chat-message[]', 'control-flow-excluded', 'control-flow-excluded[]', 'object', 'object[]', 'fn<string>', 'fn<number>', 'fn<boolean>', 'fn<date>', 'fn<time>', 'fn<datetime>', 'fn<any>', 'fn<object>', 'fn<chat-message>', 'fn<control-flow-excluded>', 'fn<string[]>', 'fn<number[]>', 'fn<boolean[]>', 'fn<date[]>', 'fn<time[]>', 'fn<datetime[]>', 'fn<any[]>', 'fn<object[]>', 'fn<chat-message[]>', 'fn<control-flow-excluded[]>', 'gpt-function', 'gpt-function[]', 'fn<gpt-function[]>', 'fn<gpt-function>', 'vector', 'vector[]', 'fn<vector>', 'fn<vector[]>', 'image', 'image[]', 'fn<image>', 'fn<image[]>', 'binary', 'binary[]', 'fn<binary>', 'fn<binary[]>', 'audio', 'audio[]', 'fn<audio>', 'fn<audio[]>', 'graph-reference', 'graph-reference[]', 'fn<graph-reference>', 'fn<graph-reference[]>', 'document', 'document[]', 'fn<document>', 'fn<document[]>');
|
|
3
|
+
export const scalarTypes = exhaustiveTuple()('any', 'boolean', 'string', 'number', 'date', 'time', 'datetime', 'chat-message', 'control-flow-excluded', 'object', 'gpt-function', 'vector', 'image', 'binary', 'audio', 'graph-reference', 'document');
|
|
4
4
|
export const dataTypeDisplayNames = {
|
|
5
5
|
any: 'Any',
|
|
6
6
|
'any[]': 'Any Array',
|
|
@@ -66,6 +66,10 @@ export const dataTypeDisplayNames = {
|
|
|
66
66
|
'graph-reference[]': 'Graph Reference Array',
|
|
67
67
|
'fn<graph-reference>': 'Function<Graph Reference>',
|
|
68
68
|
'fn<graph-reference[]>': 'Function<Graph Reference Array>',
|
|
69
|
+
document: 'Document',
|
|
70
|
+
'document[]': 'Document Array',
|
|
71
|
+
'fn<document>': 'Function<Document>',
|
|
72
|
+
'fn<document[]>': 'Function<Document Array>',
|
|
69
73
|
};
|
|
70
74
|
export function isScalarDataValue(value) {
|
|
71
75
|
if (!value) {
|
|
@@ -143,6 +147,7 @@ export const scalarDefaults = {
|
|
|
143
147
|
'chat-message': {
|
|
144
148
|
type: 'user',
|
|
145
149
|
message: '',
|
|
150
|
+
isCacheBreakpoint: undefined,
|
|
146
151
|
},
|
|
147
152
|
'control-flow-excluded': undefined,
|
|
148
153
|
date: new Date().toISOString(),
|
|
@@ -164,6 +169,13 @@ export const scalarDefaults = {
|
|
|
164
169
|
binary: new Uint8Array(),
|
|
165
170
|
audio: { data: new Uint8Array() },
|
|
166
171
|
'graph-reference': { graphId: '', graphName: '' },
|
|
172
|
+
document: {
|
|
173
|
+
mediaType: 'text/plain',
|
|
174
|
+
data: new Uint8Array(),
|
|
175
|
+
title: undefined,
|
|
176
|
+
context: undefined,
|
|
177
|
+
enableCitations: false,
|
|
178
|
+
},
|
|
167
179
|
};
|
|
168
180
|
export function getDefaultValue(type) {
|
|
169
181
|
if (isArrayDataType(type)) {
|