@valerypopoff/rivet2-core 2.0.11 → 2.1.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/dist/cjs/bundle.cjs +1657 -158
- package/dist/cjs/bundle.cjs.map +4 -4
- package/dist/esm/exports.js +4 -0
- package/dist/esm/model/GraphBoundaryCache.js +36 -4
- package/dist/esm/model/GraphBoundaryEffects.js +32 -0
- package/dist/esm/model/GraphPreprocessor.js +6 -4
- package/dist/esm/model/GraphProcessor.js +129 -17
- package/dist/esm/model/NodeGraph.js +1 -1
- package/dist/esm/model/NodePrefabResolver.js +57 -0
- package/dist/esm/model/Nodes.js +4 -1
- package/dist/esm/model/ProcessContextBuilder.js +3 -1
- package/dist/esm/model/UiGraph.js +113 -0
- package/dist/esm/model/UiGraphRendererStyles.js +241 -0
- package/dist/esm/model/chat/openAIChatRuntime.js +0 -1
- package/dist/esm/model/chat-v2/aiSdkBridge.js +100 -2
- package/dist/esm/model/chat-v2/chatV2FeatureCompatibility.js +1 -1
- package/dist/esm/model/chat-v2/chatV2Outputs.js +11 -2
- package/dist/esm/model/chat-v2/chatV2Pipeline.js +38 -31
- package/dist/esm/model/chat-v2/chatV2ResponseFormat.js +4 -1
- package/dist/esm/model/chat-v2/chatV2Shared.js +2 -2
- package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +5 -5
- package/dist/esm/model/chat-v2/llmChatV2NodeRuntime.js +8 -2
- package/dist/esm/model/chat-v2/providerOptions.js +65 -2
- package/dist/esm/model/nodes/CoalesceNode.js +1 -1
- package/dist/esm/model/nodes/CompareNode.js +15 -14
- package/dist/esm/model/nodes/GraphOutputNode.js +1 -0
- package/dist/esm/model/nodes/LLMChatV2Node.js +66 -17
- package/dist/esm/model/nodes/NodePrefabInstanceNode.js +39 -0
- package/dist/esm/model/nodes/PromptNode.js +2 -1
- package/dist/esm/model/nodes/ReferencedGraphAliasNode.js +49 -7
- package/dist/esm/model/nodes/SubGraphNode.js +42 -5
- package/dist/esm/utils/index.js +2 -0
- package/dist/esm/utils/jsonValueToDataValue.js +48 -0
- package/dist/esm/utils/projectComparison/connections.js +57 -0
- package/dist/esm/utils/projectComparison/graphs.js +60 -0
- package/dist/esm/utils/projectComparison/nodes.js +53 -0
- package/dist/esm/utils/projectComparison/summaries.js +60 -0
- package/dist/esm/utils/projectComparison/values.js +40 -0
- package/dist/esm/utils/projectComparison.js +73 -0
- package/dist/esm/utils/serialization/serializationHelpers.js +24 -3
- package/dist/esm/utils/serialization/serialization_v4.js +30 -0
- package/dist/types/exports.d.ts +5 -0
- package/dist/types/model/EditorDefinition.d.ts +1 -0
- package/dist/types/model/ExecutorProtocol.d.ts +13 -3
- package/dist/types/model/GraphBoundaryCache.d.ts +9 -3
- package/dist/types/model/GraphBoundaryEffects.d.ts +9 -0
- package/dist/types/model/GraphProcessor.d.ts +15 -0
- package/dist/types/model/NodeBase.d.ts +5 -0
- package/dist/types/model/NodeBodySpec.d.ts +1 -0
- package/dist/types/model/NodePrefabResolver.d.ts +13 -0
- package/dist/types/model/Nodes.d.ts +5 -4
- package/dist/types/model/ProcessContext.d.ts +5 -1
- package/dist/types/model/ProcessContextBuilder.d.ts +4 -2
- package/dist/types/model/Project.d.ts +9 -0
- package/dist/types/model/UiGraph.d.ts +84 -0
- package/dist/types/model/UiGraphRendererStyles.d.ts +2 -0
- package/dist/types/model/chat-v2/aiSdkBridge.d.ts +1 -0
- package/dist/types/model/chat-v2/chatV2FeatureCompatibility.d.ts +1 -1
- package/dist/types/model/chat-v2/chatV2Outputs.d.ts +4 -2
- package/dist/types/model/chat-v2/chatV2ResponseFormat.d.ts +1 -1
- package/dist/types/model/chat-v2/chatV2Types.d.ts +24 -1
- package/dist/types/model/chat-v2/providerOptions.d.ts +1 -0
- package/dist/types/model/nodes/CompareNode.d.ts +4 -0
- package/dist/types/model/nodes/LLMChatV2Node.d.ts +2 -1
- package/dist/types/model/nodes/NodePrefabInstanceNode.d.ts +13 -0
- package/dist/types/model/nodes/SubGraphNode.d.ts +2 -0
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/jsonValueToDataValue.d.ts +2 -0
- package/dist/types/utils/projectComparison/connections.d.ts +5 -0
- package/dist/types/utils/projectComparison/graphs.d.ts +3 -0
- package/dist/types/utils/projectComparison/nodes.d.ts +5 -0
- package/dist/types/utils/projectComparison/summaries.d.ts +4 -0
- package/dist/types/utils/projectComparison/values.d.ts +5 -0
- package/dist/types/utils/projectComparison.d.ts +77 -0
- package/package.json +1 -1
|
@@ -295,7 +295,7 @@ function getResponseFormatEditors() {
|
|
|
295
295
|
options: [
|
|
296
296
|
{ value: '', label: 'Default' },
|
|
297
297
|
{ value: 'text', label: 'Text' },
|
|
298
|
-
{ value: 'json', label: 'JSON' },
|
|
298
|
+
{ value: 'json', label: 'JSON object' },
|
|
299
299
|
{ value: 'json_schema', label: 'JSON schema' },
|
|
300
300
|
],
|
|
301
301
|
defaultValue: '',
|
|
@@ -307,7 +307,7 @@ function getResponseFormatEditors() {
|
|
|
307
307
|
dataKey: 'responseSchemaName',
|
|
308
308
|
useInputToggleDataKey: 'useResponseSchemaNameInput',
|
|
309
309
|
placeholder: 'response_schema',
|
|
310
|
-
helperMessage: 'Optional name passed to the provider for JSON or JSON schema responses.',
|
|
310
|
+
helperMessage: 'Optional name passed to the provider for JSON object or JSON schema responses.',
|
|
311
311
|
hideIf: (data) => data.responseFormat !== 'json' && data.responseFormat !== 'json_schema',
|
|
312
312
|
},
|
|
313
313
|
{
|
|
@@ -315,7 +315,7 @@ function getResponseFormatEditors() {
|
|
|
315
315
|
label: 'Schema description',
|
|
316
316
|
dataKey: 'responseSchemaDescription',
|
|
317
317
|
useInputToggleDataKey: 'useResponseSchemaDescriptionInput',
|
|
318
|
-
helperMessage: 'Optional description passed to the provider for JSON or JSON schema responses.',
|
|
318
|
+
helperMessage: 'Optional description passed to the provider for JSON object or JSON schema responses.',
|
|
319
319
|
hideIf: (data) => data.responseFormat !== 'json' && data.responseFormat !== 'json_schema',
|
|
320
320
|
},
|
|
321
321
|
]);
|
|
@@ -454,9 +454,9 @@ function getTechnicalDetailsEditors() {
|
|
|
454
454
|
},
|
|
455
455
|
{
|
|
456
456
|
type: 'toggle',
|
|
457
|
-
label: 'Output request
|
|
457
|
+
label: 'Output request details',
|
|
458
458
|
dataKey: 'outputRequestStatus',
|
|
459
|
-
helperMessage: 'Adds Response Status
|
|
459
|
+
helperMessage: 'Adds Response Status, Response Error, and LLM request body outputs. Retry mode changes status/error to per-attempt arrays, and LLM request body becomes an array when multiple provider calls are made.',
|
|
460
460
|
},
|
|
461
461
|
]);
|
|
462
462
|
}
|
|
@@ -24,11 +24,16 @@ export async function resolveLLMChatV2RuntimeConfig(params) {
|
|
|
24
24
|
const baseURL = resolveLLMChatV2BaseURL(data, inputs);
|
|
25
25
|
const nodeHeaders = resolveLLMChatV2Headers(data, inputs);
|
|
26
26
|
const apiKey = resolveLLMChatV2ApiKey(data, inputs, context);
|
|
27
|
+
const requestBodies = data.outputRequestStatus ? [] : undefined;
|
|
27
28
|
const providerConfig = await resolveChatV2ProviderConfig(provider, modelId, context, {
|
|
28
29
|
baseURL,
|
|
29
30
|
headers: nodeHeaders,
|
|
30
31
|
});
|
|
31
|
-
const model = createChatV2Model(provider, modelId, context, {
|
|
32
|
+
const model = createChatV2Model(provider, modelId, context, {
|
|
33
|
+
...providerConfig,
|
|
34
|
+
apiKey,
|
|
35
|
+
onRequestBody: requestBodies == null ? undefined : (body) => requestBodies.push(body),
|
|
36
|
+
});
|
|
32
37
|
const prompt = inputs['prompt'];
|
|
33
38
|
const systemPrompt = inputs['systemPrompt'];
|
|
34
39
|
const functions = data.useToolCalling && inputs['functions'] != null
|
|
@@ -47,7 +52,7 @@ export async function resolveLLMChatV2RuntimeConfig(params) {
|
|
|
47
52
|
functions,
|
|
48
53
|
additionalTools: resolveLLMChatV2BuiltInTools(data, context, providerConfig, apiKey),
|
|
49
54
|
...generationParameters,
|
|
50
|
-
responseOutput: createChatV2ResponseOutput(responseFormatParameters),
|
|
55
|
+
responseOutput: createChatV2ResponseOutput(responseFormatParameters, provider),
|
|
51
56
|
responseFormat: responseFormatParameters?.responseFormat,
|
|
52
57
|
outputUsage: data.outputUsage,
|
|
53
58
|
outputReasoning: data.outputReasoning,
|
|
@@ -57,6 +62,7 @@ export async function resolveLLMChatV2RuntimeConfig(params) {
|
|
|
57
62
|
providerOptions,
|
|
58
63
|
toolChoice,
|
|
59
64
|
anthropicCacheControlTtl: provider === 'anthropic' ? data.anthropicCacheControlTtl || undefined : undefined,
|
|
65
|
+
requestBodies,
|
|
60
66
|
retryOnNon200: data.retryOnNon200,
|
|
61
67
|
retryOnNon200RepeatTimes: data.retryOnNon200RepeatTimes,
|
|
62
68
|
retryOnNon200CooldownMs: data.retryOnNon200CooldownMs,
|
|
@@ -111,6 +111,61 @@ function openAIBaseURLToEndpoint(baseURL) {
|
|
|
111
111
|
return `${normalizedBaseURL}/chat/completions`;
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
|
+
function parseBodyText(text) {
|
|
115
|
+
try {
|
|
116
|
+
return JSON.parse(text);
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
return text;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function parseFetchBody(body) {
|
|
123
|
+
if (body == null) {
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
if (typeof body === 'string') {
|
|
127
|
+
return parseBodyText(body);
|
|
128
|
+
}
|
|
129
|
+
if (body instanceof URLSearchParams) {
|
|
130
|
+
return Object.fromEntries(body.entries());
|
|
131
|
+
}
|
|
132
|
+
if (body instanceof ArrayBuffer) {
|
|
133
|
+
return parseBodyText(new TextDecoder().decode(body));
|
|
134
|
+
}
|
|
135
|
+
if (ArrayBuffer.isView(body)) {
|
|
136
|
+
return parseBodyText(new TextDecoder().decode(body));
|
|
137
|
+
}
|
|
138
|
+
return undefined;
|
|
139
|
+
}
|
|
140
|
+
function cloneCapturedRequestBody(body) {
|
|
141
|
+
if (typeof structuredClone === 'function') {
|
|
142
|
+
try {
|
|
143
|
+
return structuredClone(body);
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
// Fall through to JSON cloning below.
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
try {
|
|
150
|
+
return JSON.parse(JSON.stringify(body));
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
return body;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function createRequestBodyCapturingFetch(onRequestBody) {
|
|
157
|
+
return async (input, init) => {
|
|
158
|
+
const body = parseFetchBody(init?.body);
|
|
159
|
+
if (body !== undefined) {
|
|
160
|
+
onRequestBody(cloneCapturedRequestBody(body));
|
|
161
|
+
}
|
|
162
|
+
const nativeFetch = globalThis.fetch;
|
|
163
|
+
return nativeFetch(input, init);
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function maybeCreateRequestBodyCapturingFetch(options) {
|
|
167
|
+
return options.onRequestBody == null ? undefined : createRequestBodyCapturingFetch(options.onRequestBody);
|
|
168
|
+
}
|
|
114
169
|
export async function resolveChatV2ProviderConfig(provider, modelId, context, options = {}) {
|
|
115
170
|
const headers = cleanHeaders({
|
|
116
171
|
...context.settings.chatNodeHeaders,
|
|
@@ -166,6 +221,7 @@ export function createChatV2Model(provider, modelId, context, options = {}) {
|
|
|
166
221
|
organization: context.settings.openAiOrganization || undefined,
|
|
167
222
|
baseURL: options.baseURL || undefined,
|
|
168
223
|
headers: options.headers,
|
|
224
|
+
fetch: maybeCreateRequestBodyCapturingFetch(options),
|
|
169
225
|
});
|
|
170
226
|
return providerInstance.responses(modelId);
|
|
171
227
|
}
|
|
@@ -174,6 +230,7 @@ export function createChatV2Model(provider, modelId, context, options = {}) {
|
|
|
174
230
|
apiKey: options.apiKey || context.getPluginConfig('anthropicApiKey') || undefined,
|
|
175
231
|
baseURL: options.baseURL || context.getPluginConfig('anthropicApiEndpoint') || undefined,
|
|
176
232
|
headers: options.headers,
|
|
233
|
+
fetch: maybeCreateRequestBodyCapturingFetch(options),
|
|
177
234
|
});
|
|
178
235
|
return providerInstance.messages(modelId);
|
|
179
236
|
}
|
|
@@ -182,6 +239,7 @@ export function createChatV2Model(provider, modelId, context, options = {}) {
|
|
|
182
239
|
apiKey: options.apiKey || context.getPluginConfig('googleApiKey') || undefined,
|
|
183
240
|
baseURL: options.baseURL || undefined,
|
|
184
241
|
headers: options.headers,
|
|
242
|
+
fetch: maybeCreateRequestBodyCapturingFetch(options),
|
|
185
243
|
});
|
|
186
244
|
return providerInstance.chat(modelId);
|
|
187
245
|
}
|
|
@@ -194,9 +252,14 @@ export function createChatV2Model(provider, modelId, context, options = {}) {
|
|
|
194
252
|
apiKey: options.apiKey,
|
|
195
253
|
baseURL: options.baseURL,
|
|
196
254
|
headers: options.headers,
|
|
197
|
-
includeUsage:
|
|
255
|
+
includeUsage: false,
|
|
256
|
+
fetch: maybeCreateRequestBodyCapturingFetch(options),
|
|
198
257
|
});
|
|
199
|
-
|
|
258
|
+
const model = providerInstance.chatModel(modelId);
|
|
259
|
+
// The installed OpenAI-compatible provider reads this from the model instance,
|
|
260
|
+
// but its factory options do not forward the flag.
|
|
261
|
+
model.supportsStructuredOutputs = true;
|
|
262
|
+
return model;
|
|
200
263
|
}
|
|
201
264
|
}
|
|
202
265
|
}
|
|
@@ -8,6 +8,20 @@ import { match } from 'ts-pattern';
|
|
|
8
8
|
import { dedent } from 'ts-dedent';
|
|
9
9
|
import { nodeDefinition } from '../NodeDefinition.js';
|
|
10
10
|
import { coerceType, coerceTypeOptional } from '../../utils/coerceType.js';
|
|
11
|
+
export const compareNodeComparisonFunctionOptions = [
|
|
12
|
+
{ label: '==', value: '==' },
|
|
13
|
+
{ label: '!=', value: '!=' },
|
|
14
|
+
{ label: '<', value: '<' },
|
|
15
|
+
{ label: '<=', value: '<=' },
|
|
16
|
+
{ label: '>', value: '>' },
|
|
17
|
+
{ label: '>=', value: '>=' },
|
|
18
|
+
{ label: 'and', value: 'and' },
|
|
19
|
+
{ label: 'or', value: 'or' },
|
|
20
|
+
{ label: 'xor', value: 'xor' },
|
|
21
|
+
{ label: 'nand', value: 'nand' },
|
|
22
|
+
{ label: 'nor', value: 'nor' },
|
|
23
|
+
{ label: 'xnor', value: 'xnor' },
|
|
24
|
+
];
|
|
11
25
|
export class CompareNodeImpl extends NodeImpl {
|
|
12
26
|
static create() {
|
|
13
27
|
const chartNode = {
|
|
@@ -62,20 +76,7 @@ export class CompareNodeImpl extends NodeImpl {
|
|
|
62
76
|
type: 'dropdown',
|
|
63
77
|
label: 'Comparison Function',
|
|
64
78
|
dataKey: 'comparisonFunction',
|
|
65
|
-
options:
|
|
66
|
-
{ label: '==', value: '==' },
|
|
67
|
-
{ label: '!=', value: '!=' },
|
|
68
|
-
{ label: '<', value: '<' },
|
|
69
|
-
{ label: '<=', value: '<=' },
|
|
70
|
-
{ label: '>', value: '>' },
|
|
71
|
-
{ label: '>=', value: '>=' },
|
|
72
|
-
{ label: 'and', value: 'and' },
|
|
73
|
-
{ label: 'or', value: 'or' },
|
|
74
|
-
{ label: 'xor', value: 'xor' },
|
|
75
|
-
{ label: 'nand', value: 'nand' },
|
|
76
|
-
{ label: 'nor', value: 'nor' },
|
|
77
|
-
{ label: 'xnor', value: 'xnor' },
|
|
78
|
-
],
|
|
79
|
+
options: compareNodeComparisonFunctionOptions,
|
|
79
80
|
useInputToggleDataKey: 'useComparisonFunctionInput',
|
|
80
81
|
},
|
|
81
82
|
];
|
|
@@ -16,31 +16,62 @@ export { buildLLMChatV2EditorCacheKey, resolveLLMChatV2RuntimeProviderOptions };
|
|
|
16
16
|
function usesBaseURLInput(data) {
|
|
17
17
|
return data.provider === 'custom' ? data.useCustomProviderBaseURLInput : data.useBaseURLInput;
|
|
18
18
|
}
|
|
19
|
-
function
|
|
19
|
+
function getCustomProviderBaseURLBodyValue(data) {
|
|
20
20
|
if (data.provider !== 'custom') {
|
|
21
21
|
return undefined;
|
|
22
22
|
}
|
|
23
23
|
if (data.useCustomProviderBaseURLInput) {
|
|
24
|
-
return '
|
|
24
|
+
return '(Using Input)';
|
|
25
25
|
}
|
|
26
26
|
const baseURL = data.customProviderBaseURL.trim();
|
|
27
|
-
return baseURL
|
|
27
|
+
return baseURL || undefined;
|
|
28
28
|
}
|
|
29
29
|
function getOptionLabel(options, value) {
|
|
30
30
|
return options.find((option) => option.value === (value ?? ''))?.label ?? value ?? 'Default';
|
|
31
31
|
}
|
|
32
|
-
function
|
|
32
|
+
function getProviderBodyLabel(data) {
|
|
33
|
+
return data.provider === 'custom' ? 'Custom' : getChatV2ProviderLabel(data.provider);
|
|
34
|
+
}
|
|
35
|
+
function getReasoningEffortBodyValue(data) {
|
|
33
36
|
switch (data.provider) {
|
|
34
37
|
case 'openai':
|
|
35
|
-
return
|
|
38
|
+
return getOptionLabel(openAIReasoningEffortOptions, data.openAIReasoningEffort);
|
|
36
39
|
case 'anthropic':
|
|
37
|
-
return
|
|
40
|
+
return getOptionLabel(anthropicEffortOptions, data.anthropicEffort);
|
|
38
41
|
case 'google':
|
|
39
|
-
return
|
|
42
|
+
return getOptionLabel(googleThinkingLevelOptions, data.googleThinkingLevel);
|
|
40
43
|
case 'custom':
|
|
41
44
|
return undefined;
|
|
42
45
|
}
|
|
43
46
|
}
|
|
47
|
+
function escapeMarkdownInline(value) {
|
|
48
|
+
return value
|
|
49
|
+
.replace(/\r/g, '\\r')
|
|
50
|
+
.replace(/\n/g, '\\n')
|
|
51
|
+
.replace(/&/g, '&')
|
|
52
|
+
.replace(/</g, '<')
|
|
53
|
+
.replace(/>/g, '>')
|
|
54
|
+
.replace(/"/g, '"')
|
|
55
|
+
.replace(/([\\`*_[\]{}()#+\-.!|])/g, '\\$1');
|
|
56
|
+
}
|
|
57
|
+
function getBodyLine(label, value) {
|
|
58
|
+
return `<span style="opacity: 0.55">${label}:</span> ${escapeMarkdownInline(value)}`;
|
|
59
|
+
}
|
|
60
|
+
function getOptionalNumberBodyLine(label, value, usesInput) {
|
|
61
|
+
if (usesInput) {
|
|
62
|
+
return getBodyLine(label, '(Using Input)');
|
|
63
|
+
}
|
|
64
|
+
return value === undefined ? undefined : getBodyLine(label, `${value}`);
|
|
65
|
+
}
|
|
66
|
+
function getStopSequencesBodyLine(data) {
|
|
67
|
+
if (data.useStopSequencesInput) {
|
|
68
|
+
return getBodyLine('Stop sequences', '(Using Input)');
|
|
69
|
+
}
|
|
70
|
+
const stopSequences = (data.stopSequences ?? []).filter((sequence) => sequence.length > 0);
|
|
71
|
+
return stopSequences.length === 0
|
|
72
|
+
? undefined
|
|
73
|
+
: getBodyLine('Stop sequences', stopSequences.map((sequence) => JSON.stringify(sequence)).join(', '));
|
|
74
|
+
}
|
|
44
75
|
export class LLMChatV2NodeImpl extends NodeImpl {
|
|
45
76
|
static create() {
|
|
46
77
|
return {
|
|
@@ -175,6 +206,10 @@ export class LLMChatV2NodeImpl extends NodeImpl {
|
|
|
175
206
|
id: 'requestError',
|
|
176
207
|
title: 'Response Error',
|
|
177
208
|
dataType: this.data.retryOnNon200 ? 'string[]' : 'string',
|
|
209
|
+
}, {
|
|
210
|
+
id: 'requestBody',
|
|
211
|
+
title: 'LLM request body',
|
|
212
|
+
dataType: ['object', 'object[]', 'string', 'string[]', 'any', 'any[]'],
|
|
178
213
|
});
|
|
179
214
|
}
|
|
180
215
|
return outputs;
|
|
@@ -197,17 +232,31 @@ export class LLMChatV2NodeImpl extends NodeImpl {
|
|
|
197
232
|
}
|
|
198
233
|
getBody() {
|
|
199
234
|
const modelInfo = getChatV2ModelInfo(this.data.provider, this.data.model);
|
|
200
|
-
const providerLabel =
|
|
201
|
-
const
|
|
235
|
+
const providerLabel = getProviderBodyLabel(this.data);
|
|
236
|
+
const baseURLValue = getCustomProviderBaseURLBodyValue(this.data);
|
|
202
237
|
const modelLine = modelInfo?.displayName ?? this.data.model;
|
|
203
|
-
const providerDetails =
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
238
|
+
const providerDetails = [
|
|
239
|
+
getBodyLine('Provider', providerLabel),
|
|
240
|
+
...(baseURLValue ? [getBodyLine('Base URL', baseURLValue)] : []),
|
|
241
|
+
getBodyLine('Model', modelLine),
|
|
242
|
+
];
|
|
243
|
+
const reasoningEffortValue = getReasoningEffortBodyValue(this.data);
|
|
244
|
+
return {
|
|
245
|
+
type: 'markdown',
|
|
246
|
+
disableLinks: true,
|
|
247
|
+
text: [
|
|
248
|
+
...providerDetails,
|
|
249
|
+
...(reasoningEffortValue ? [getBodyLine('Reasoning effort', reasoningEffortValue)] : []),
|
|
250
|
+
getBodyLine('Temperature', this.data.useTemperatureInput ? '(Using Input)' : `${this.data.temperature}`),
|
|
251
|
+
getBodyLine('Max output tokens', this.data.useMaxTokensInput ? '(Using Input)' : `${this.data.maxTokens}`),
|
|
252
|
+
getOptionalNumberBodyLine('Top P', this.data.topP, this.data.useTopPInput),
|
|
253
|
+
getOptionalNumberBodyLine('Top K', this.data.topK, this.data.useTopKInput),
|
|
254
|
+
getOptionalNumberBodyLine('Presence penalty', this.data.presencePenalty, this.data.usePresencePenaltyInput),
|
|
255
|
+
getOptionalNumberBodyLine('Frequency penalty', this.data.frequencyPenalty, this.data.useFrequencyPenaltyInput),
|
|
256
|
+
getStopSequencesBodyLine(this.data),
|
|
257
|
+
getOptionalNumberBodyLine('Seed', this.data.seed, this.data.useSeedInput),
|
|
258
|
+
].filter((line) => line !== undefined).join('\n'),
|
|
259
|
+
};
|
|
211
260
|
}
|
|
212
261
|
async process(inputs, context) {
|
|
213
262
|
const runtime = await resolveLLMChatV2RuntimeConfig({
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { nanoid } from 'nanoid/non-secure';
|
|
2
|
+
import {} from '../GraphProcessor.js';
|
|
3
|
+
import {} from '../NodeBase.js';
|
|
4
|
+
import { nodeDefinition } from '../NodeDefinition.js';
|
|
5
|
+
import { NodeImpl } from '../NodeImpl.js';
|
|
6
|
+
import { NODE_PREFAB_INSTANCE_TYPE, } from '../NodePrefabResolver.js';
|
|
7
|
+
export class NodePrefabInstanceNodeImpl extends NodeImpl {
|
|
8
|
+
static create() {
|
|
9
|
+
return {
|
|
10
|
+
type: NODE_PREFAB_INSTANCE_TYPE,
|
|
11
|
+
title: 'Linked node',
|
|
12
|
+
id: nanoid(),
|
|
13
|
+
visualData: {
|
|
14
|
+
x: 0,
|
|
15
|
+
y: 0,
|
|
16
|
+
width: 240,
|
|
17
|
+
},
|
|
18
|
+
data: {},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
getInputDefinitions() {
|
|
22
|
+
return [];
|
|
23
|
+
}
|
|
24
|
+
getOutputDefinitions() {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
async process(_inputData) {
|
|
28
|
+
throw new Error('Library node is missing. Open the Node library and reconnect this linked node.');
|
|
29
|
+
}
|
|
30
|
+
static getUIData() {
|
|
31
|
+
return {
|
|
32
|
+
contextMenuTitle: 'Linked node',
|
|
33
|
+
infoBoxTitle: 'Linked node',
|
|
34
|
+
infoBoxBody: 'Runs a node from the project Node library.',
|
|
35
|
+
group: 'Advanced',
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export const nodePrefabInstanceNode = nodeDefinition(NodePrefabInstanceNodeImpl, 'Linked node');
|
|
@@ -178,7 +178,8 @@ export class PromptNodeImpl extends NodeImpl {
|
|
|
178
178
|
acc[key] = coerceTypeOptional(inputs[key], 'string') ?? '';
|
|
179
179
|
return acc;
|
|
180
180
|
}, {});
|
|
181
|
-
|
|
181
|
+
let outputValue = interpolate(this.chartNode.data.promptText, inputMap, context.graphInputNodeValues, context.contextValues);
|
|
182
|
+
outputValue = outputValue.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
182
183
|
const type = getInputOrData(this.data, inputs, 'type', 'string');
|
|
183
184
|
const isCacheBreakpoint = getInputOrData(this.data, inputs, 'isCacheBreakpoint', 'boolean');
|
|
184
185
|
if (['assistant', 'system', 'user', 'function'].includes(type) === false) {
|
|
@@ -9,7 +9,7 @@ import {} from '../DataValue.js';
|
|
|
9
9
|
import {} from '../ProcessContext.js';
|
|
10
10
|
import { dedent } from 'ts-dedent';
|
|
11
11
|
import { getError } from '../../utils/errors.js';
|
|
12
|
-
import { buildExcludedGraphBoundaryOutputs, buildGraphBoundaryInputData, getGraphBoundary, getGraphBoundaryInputDefinitions, getGraphBoundaryOutputDefinitions, } from '../GraphBoundaryCache.js';
|
|
12
|
+
import { buildExcludedGraphBoundaryOutputs, buildGraphBoundaryInputData, GRAPH_BOUNDARY_OUTPUT_DEMAND_OPTIMIZATION_ENABLED, getGraphBoundary, getGraphBoundaryInputDefinitions, getGraphBoundaryOutputDefinitions, getRequestedGraphOutputNodeIds, } from '../GraphBoundaryCache.js';
|
|
13
13
|
export class ReferencedGraphAliasNodeImpl extends NodeImpl {
|
|
14
14
|
static create() {
|
|
15
15
|
const chartNode = {
|
|
@@ -117,14 +117,32 @@ export class ReferencedGraphAliasNodeImpl extends NodeImpl {
|
|
|
117
117
|
const boundary = context.getGraphBoundary?.(referencedProject, this.data.graphId) ??
|
|
118
118
|
getGraphBoundary(referencedProject, this.data.graphId);
|
|
119
119
|
const inputData = buildGraphBoundaryInputData(boundary, inputs, this.data.inputData);
|
|
120
|
+
const shouldRunWholeGraph = !GRAPH_BOUNDARY_OUTPUT_DEMAND_OPTIMIZATION_ENABLED ||
|
|
121
|
+
context.isDirectRunTarget ||
|
|
122
|
+
(this.data.useErrorOutput === true && context.activeOutputPortIds.has('error'));
|
|
123
|
+
const requestedGraphOutputNodeIds = shouldRunWholeGraph
|
|
124
|
+
? []
|
|
125
|
+
: getRequestedGraphOutputNodeIds(boundary, context.activeOutputPortIds);
|
|
126
|
+
if (!shouldRunWholeGraph && requestedGraphOutputNodeIds.length === 0) {
|
|
127
|
+
return buildSkippedReferencedGraphOutputs(boundary, this.data.useErrorOutput, this.data.outputCostDuration);
|
|
128
|
+
}
|
|
120
129
|
// Create a subprocessor using the referenced project's graph
|
|
121
130
|
const subGraphProcessor = context.createSubProcessor(this.data.graphId, {
|
|
122
131
|
signal: context.signal,
|
|
123
132
|
project: referencedProject,
|
|
124
133
|
});
|
|
134
|
+
if (!shouldRunWholeGraph) {
|
|
135
|
+
subGraphProcessor.runToNodeIds = requestedGraphOutputNodeIds;
|
|
136
|
+
}
|
|
125
137
|
try {
|
|
126
138
|
const startTime = Date.now();
|
|
127
|
-
const
|
|
139
|
+
const graphOutputs = await subGraphProcessor.processGraph(context, inputData, context.contextValues);
|
|
140
|
+
const outputs = shouldRunWholeGraph
|
|
141
|
+
? graphOutputs
|
|
142
|
+
: {
|
|
143
|
+
...buildExcludedGraphBoundaryOutputs(boundary),
|
|
144
|
+
...graphOutputs,
|
|
145
|
+
};
|
|
128
146
|
const duration = Date.now() - startTime;
|
|
129
147
|
if (this.data.useErrorOutput) {
|
|
130
148
|
outputs['error'] = {
|
|
@@ -138,11 +156,7 @@ export class ReferencedGraphAliasNodeImpl extends NodeImpl {
|
|
|
138
156
|
value: duration,
|
|
139
157
|
};
|
|
140
158
|
}
|
|
141
|
-
|
|
142
|
-
delete outputs['cost'];
|
|
143
|
-
delete outputs['duration'];
|
|
144
|
-
}
|
|
145
|
-
return outputs;
|
|
159
|
+
return applyMetricOutputSetting(outputs, this.data.outputCostDuration);
|
|
146
160
|
}
|
|
147
161
|
catch (err) {
|
|
148
162
|
if (!this.data.useErrorOutput) {
|
|
@@ -158,3 +172,31 @@ export class ReferencedGraphAliasNodeImpl extends NodeImpl {
|
|
|
158
172
|
}
|
|
159
173
|
}
|
|
160
174
|
export const referencedGraphAliasNode = nodeDefinition(ReferencedGraphAliasNodeImpl, 'Referenced Graph Alias');
|
|
175
|
+
function buildSkippedReferencedGraphOutputs(boundary, useErrorOutput, outputCostDuration) {
|
|
176
|
+
const outputs = buildExcludedGraphBoundaryOutputs(boundary);
|
|
177
|
+
if (useErrorOutput) {
|
|
178
|
+
outputs['error'] = {
|
|
179
|
+
type: 'control-flow-excluded',
|
|
180
|
+
value: undefined,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
if (outputCostDuration) {
|
|
184
|
+
outputs['cost'] = {
|
|
185
|
+
type: 'number',
|
|
186
|
+
value: 0,
|
|
187
|
+
};
|
|
188
|
+
outputs['duration'] = {
|
|
189
|
+
type: 'number',
|
|
190
|
+
value: 0,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
return applyMetricOutputSetting(outputs, outputCostDuration);
|
|
194
|
+
}
|
|
195
|
+
function applyMetricOutputSetting(outputs, outputCostDuration) {
|
|
196
|
+
if (outputCostDuration) {
|
|
197
|
+
return outputs;
|
|
198
|
+
}
|
|
199
|
+
delete outputs['cost'];
|
|
200
|
+
delete outputs['duration'];
|
|
201
|
+
return outputs;
|
|
202
|
+
}
|
|
@@ -10,7 +10,7 @@ import {} from '../ProcessContext.js';
|
|
|
10
10
|
import {} from '../../index.js';
|
|
11
11
|
import { dedent } from 'ts-dedent';
|
|
12
12
|
import { getError } from '../../utils/errors.js';
|
|
13
|
-
import { buildExcludedGraphBoundaryOutputs, buildGraphBoundaryInputData, getGraphBoundary, getGraphBoundaryInputDefinitions, getGraphBoundaryOutputDefinitions, } from '../GraphBoundaryCache.js';
|
|
13
|
+
import { applyGraphBoundaryPortOrder, buildExcludedGraphBoundaryOutputs, buildGraphBoundaryInputData, GRAPH_BOUNDARY_OUTPUT_DEMAND_OPTIMIZATION_ENABLED, getGraphBoundary, getGraphBoundaryInputDefinitions, getGraphBoundaryOutputDefinitions, getRequestedGraphOutputNodeIds, } from '../GraphBoundaryCache.js';
|
|
14
14
|
export class SubGraphNodeImpl extends NodeImpl {
|
|
15
15
|
static create() {
|
|
16
16
|
const chartNode = {
|
|
@@ -32,11 +32,11 @@ export class SubGraphNodeImpl extends NodeImpl {
|
|
|
32
32
|
}
|
|
33
33
|
getInputDefinitions(_connections, _nodes, project, _referencedProjects, definitionContext) {
|
|
34
34
|
const boundary = this.getBoundary(project, definitionContext);
|
|
35
|
-
return boundary ? getGraphBoundaryInputDefinitions(boundary) : [];
|
|
35
|
+
return boundary ? getGraphBoundaryInputDefinitions(boundary, this.data.inputPortOrder) : [];
|
|
36
36
|
}
|
|
37
37
|
getGraphOutputs(project, definitionContext) {
|
|
38
38
|
const boundary = this.getBoundary(project, definitionContext);
|
|
39
|
-
return boundary ? getGraphBoundaryOutputDefinitions(boundary) : [];
|
|
39
|
+
return boundary ? getGraphBoundaryOutputDefinitions(boundary, this.data.outputPortOrder) : [];
|
|
40
40
|
}
|
|
41
41
|
getOutputDefinitions(_connections, _nodes, project, _referencedProjects, definitionContext) {
|
|
42
42
|
const outputs = [];
|
|
@@ -69,7 +69,7 @@ export class SubGraphNodeImpl extends NodeImpl {
|
|
|
69
69
|
if (this.data.graphId) {
|
|
70
70
|
const boundary = getGraphBoundary(context.project, this.data.graphId);
|
|
71
71
|
if (boundary) {
|
|
72
|
-
for (const input of boundary.inputs) {
|
|
72
|
+
for (const input of applyGraphBoundaryPortOrder(boundary.inputs, this.data.inputPortOrder)) {
|
|
73
73
|
definitions.push({
|
|
74
74
|
type: 'dynamic',
|
|
75
75
|
dataKey: 'inputData',
|
|
@@ -104,10 +104,29 @@ export class SubGraphNodeImpl extends NodeImpl {
|
|
|
104
104
|
}
|
|
105
105
|
const boundary = context.getGraphBoundary?.(project, this.data.graphId) ?? getGraphBoundary(project, this.data.graphId);
|
|
106
106
|
const inputData = buildGraphBoundaryInputData(boundary, inputs, this.data.inputData);
|
|
107
|
+
const shouldRunWholeGraph = !GRAPH_BOUNDARY_OUTPUT_DEMAND_OPTIMIZATION_ENABLED ||
|
|
108
|
+
context.isDirectRunTarget ||
|
|
109
|
+
this.data.useAsGraphPartialOutput === true ||
|
|
110
|
+
(this.data.useErrorOutput === true && context.activeOutputPortIds.has('error'));
|
|
111
|
+
const requestedGraphOutputNodeIds = shouldRunWholeGraph
|
|
112
|
+
? []
|
|
113
|
+
: getRequestedGraphOutputNodeIds(boundary, context.activeOutputPortIds);
|
|
114
|
+
if (!shouldRunWholeGraph && requestedGraphOutputNodeIds.length === 0) {
|
|
115
|
+
return buildSkippedSubgraphOutputs(boundary, this.data.useErrorOutput);
|
|
116
|
+
}
|
|
107
117
|
const subGraphProcessor = context.createSubProcessor(this.data.graphId, { signal: context.signal });
|
|
118
|
+
if (!shouldRunWholeGraph) {
|
|
119
|
+
subGraphProcessor.runToNodeIds = requestedGraphOutputNodeIds;
|
|
120
|
+
}
|
|
108
121
|
try {
|
|
109
122
|
const startTime = Date.now();
|
|
110
|
-
const
|
|
123
|
+
const graphOutputs = await subGraphProcessor.processGraph(context, inputData, context.contextValues);
|
|
124
|
+
const outputs = shouldRunWholeGraph
|
|
125
|
+
? graphOutputs
|
|
126
|
+
: {
|
|
127
|
+
...buildExcludedGraphBoundaryOutputs(boundary),
|
|
128
|
+
...graphOutputs,
|
|
129
|
+
};
|
|
111
130
|
const duration = Date.now() - startTime;
|
|
112
131
|
if (this.data.useErrorOutput) {
|
|
113
132
|
outputs['error'] = {
|
|
@@ -137,3 +156,21 @@ export class SubGraphNodeImpl extends NodeImpl {
|
|
|
137
156
|
}
|
|
138
157
|
}
|
|
139
158
|
export const subGraphNode = nodeDefinition(SubGraphNodeImpl, 'Subgraph');
|
|
159
|
+
function buildSkippedSubgraphOutputs(boundary, useErrorOutput) {
|
|
160
|
+
const outputs = buildExcludedGraphBoundaryOutputs(boundary);
|
|
161
|
+
if (useErrorOutput) {
|
|
162
|
+
outputs['error'] = {
|
|
163
|
+
type: 'control-flow-excluded',
|
|
164
|
+
value: undefined,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
outputs['cost'] = {
|
|
168
|
+
type: 'number',
|
|
169
|
+
value: 0,
|
|
170
|
+
};
|
|
171
|
+
outputs['duration'] = {
|
|
172
|
+
type: 'number',
|
|
173
|
+
value: 0,
|
|
174
|
+
};
|
|
175
|
+
return outputs;
|
|
176
|
+
}
|
package/dist/esm/utils/index.js
CHANGED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export function jsonValueToDataValue(value) {
|
|
2
|
+
if (isDataValue(value)) {
|
|
3
|
+
return value;
|
|
4
|
+
}
|
|
5
|
+
if (typeof value === 'string') {
|
|
6
|
+
return { type: 'string', value };
|
|
7
|
+
}
|
|
8
|
+
if (typeof value === 'number') {
|
|
9
|
+
return { type: 'number', value };
|
|
10
|
+
}
|
|
11
|
+
if (typeof value === 'boolean') {
|
|
12
|
+
return { type: 'boolean', value };
|
|
13
|
+
}
|
|
14
|
+
if (Array.isArray(value)) {
|
|
15
|
+
return jsonArrayToDataValue(value);
|
|
16
|
+
}
|
|
17
|
+
if (isRecord(value)) {
|
|
18
|
+
return { type: 'object', value };
|
|
19
|
+
}
|
|
20
|
+
return { type: 'any', value };
|
|
21
|
+
}
|
|
22
|
+
function jsonArrayToDataValue(value) {
|
|
23
|
+
if (value.length === 0) {
|
|
24
|
+
return { type: 'any[]', value: [] };
|
|
25
|
+
}
|
|
26
|
+
if (value.every((item) => typeof item === 'string')) {
|
|
27
|
+
return { type: 'string[]', value };
|
|
28
|
+
}
|
|
29
|
+
if (value.every((item) => typeof item === 'number')) {
|
|
30
|
+
return { type: 'number[]', value };
|
|
31
|
+
}
|
|
32
|
+
if (value.every((item) => typeof item === 'boolean')) {
|
|
33
|
+
return { type: 'boolean[]', value };
|
|
34
|
+
}
|
|
35
|
+
if (value.every(isRecord)) {
|
|
36
|
+
return { type: 'object[]', value };
|
|
37
|
+
}
|
|
38
|
+
return { type: 'any[]', value };
|
|
39
|
+
}
|
|
40
|
+
function isDataValue(value) {
|
|
41
|
+
return (value != null &&
|
|
42
|
+
typeof value === 'object' &&
|
|
43
|
+
typeof value.type === 'string' &&
|
|
44
|
+
'value' in value);
|
|
45
|
+
}
|
|
46
|
+
function isRecord(value) {
|
|
47
|
+
return value != null && typeof value === 'object' && !Array.isArray(value);
|
|
48
|
+
}
|