@valerypopoff/rivet2-core 2.1.3 → 2.1.5
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 +10138 -5679
- package/dist/cjs/bundle.cjs.map +4 -4
- package/dist/cjs/webAppRuntime.cjs +1214 -0
- package/dist/cjs/webAppRuntime.cjs.map +7 -0
- package/dist/esm/api/createProcessor.js +8 -1
- package/dist/esm/api/streaming.js +6 -0
- package/dist/esm/exports.js +8 -0
- package/dist/esm/integrations/mcp/MCPBase.js +92 -34
- package/dist/esm/model/GraphBoundaryEffects.js +13 -0
- package/dist/esm/model/GraphProcessor.js +1138 -86
- package/dist/esm/model/GraphProgress.js +15 -0
- package/dist/esm/model/ManagedAsyncBranches.js +28 -0
- package/dist/esm/model/Nodes.js +12 -0
- package/dist/esm/model/ProcessContextBuilder.js +3 -1
- package/dist/esm/model/RecordingPlayer.js +19 -0
- package/dist/esm/model/StoredValueStore.js +226 -0
- package/dist/esm/model/SubprocessorBridge.js +50 -18
- package/dist/esm/model/ToolCallContinuation.js +1 -0
- package/dist/esm/model/UiGraph.js +177 -4
- package/dist/esm/model/UiGraphActionProtocol.js +131 -0
- package/dist/esm/model/UiGraphBindings.js +530 -0
- package/dist/esm/model/UiGraphBrowserRuntime.js +373 -0
- package/dist/esm/model/UiGraphNormalization.js +148 -0
- package/dist/esm/model/UiGraphRendererStyles.js +1108 -42
- package/dist/esm/model/UiGraphRuntimeModel.js +518 -2
- package/dist/esm/model/UiGraphSchema.js +91 -0
- package/dist/esm/model/UiGraphWebAppStatus.js +19 -0
- package/dist/esm/model/UiGraphWebAppStorage.js +1 -0
- package/dist/esm/model/chat/chatMessages.js +5 -9
- package/dist/esm/model/chat-v2/chatV2Errors.js +36 -3
- package/dist/esm/model/chat-v2/index.js +1 -0
- package/dist/esm/model/chat-v2/toolContinuation.js +6 -8
- package/dist/esm/model/chat-v2/toolContinuationConnection.js +68 -0
- package/dist/esm/model/nodes/ArrayNode.js +2 -13
- package/dist/esm/model/nodes/AssembleMessageNode.js +2 -13
- package/dist/esm/model/nodes/AssemblePromptNode.js +2 -13
- package/dist/esm/model/nodes/CoalesceNode.js +2 -15
- package/dist/esm/model/nodes/DelayNode.js +3 -14
- package/dist/esm/model/nodes/DelegateFunctionCallNode.js +12 -40
- package/dist/esm/model/nodes/DidRunNode.js +2 -13
- package/dist/esm/model/nodes/GetStoredValueNode.js +109 -0
- package/dist/esm/model/nodes/JoinNode.js +2 -13
- package/dist/esm/model/nodes/LLMChatV2Node.js +17 -1
- package/dist/esm/model/nodes/LoopControllerNode.js +3 -14
- package/dist/esm/model/nodes/MCPDiscoveryNode.js +19 -90
- package/dist/esm/model/nodes/MCPGetPromptNode.js +11 -97
- package/dist/esm/model/nodes/MCPToolCallNode.js +11 -97
- package/dist/esm/model/nodes/MatchNode.js +7 -7
- package/dist/esm/model/nodes/PassthroughNode.js +3 -14
- package/dist/esm/model/nodes/RaceInputsNode.js +2 -13
- package/dist/esm/model/nodes/ReportProgressNode.js +57 -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 +47 -0
- package/dist/esm/model/nodes/toolCallDelegation.js +44 -1
- package/dist/esm/model/nodes/variadicPortIndex.js +32 -0
- package/dist/esm/plugins/anthropic/anthropic.js +1 -1
- package/dist/esm/recording/ExecutionRecorder.js +6 -0
- package/dist/esm/utils/coerceType.js +3 -0
- package/dist/esm/utils/fetchEventSource.js +16 -17
- package/dist/esm/utils/serialization/serialization.js +4 -0
- package/dist/esm/utils/serialization/serializationUtils.js +8 -27
- package/dist/esm/utils/serialization/serialization_v4.js +3 -3
- package/dist/esm/webAppRuntime.js +4 -2
- package/dist/types/api/createProcessor.d.ts +4 -0
- package/dist/types/api/streaming.d.ts +6 -0
- package/dist/types/exports.d.ts +8 -0
- package/dist/types/integrations/mcp/MCPBase.d.ts +26 -3
- package/dist/types/model/EditorDefinition.d.ts +2 -1
- package/dist/types/model/ExecutorProtocol.d.ts +19 -0
- package/dist/types/model/GraphBoundaryEffects.d.ts +9 -1
- package/dist/types/model/GraphProcessor.d.ts +26 -2
- package/dist/types/model/GraphProgress.d.ts +6 -0
- package/dist/types/model/ManagedAsyncBranches.d.ts +6 -0
- package/dist/types/model/Nodes.d.ts +6 -2
- package/dist/types/model/ProcessContext.d.ts +18 -0
- package/dist/types/model/ProcessContextBuilder.d.ts +3 -1
- 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 +63 -9
- package/dist/types/model/UiGraphActionProtocol.d.ts +71 -0
- package/dist/types/model/UiGraphBindings.d.ts +45 -0
- package/dist/types/model/UiGraphBrowserRuntime.d.ts +55 -0
- package/dist/types/model/UiGraphNormalization.d.ts +24 -0
- package/dist/types/model/UiGraphRendererStyles.d.ts +2 -2
- package/dist/types/model/UiGraphRuntimeModel.d.ts +97 -6
- package/dist/types/model/UiGraphSchema.d.ts +113 -0
- package/dist/types/model/UiGraphWebAppStatus.d.ts +5 -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/toolContinuation.d.ts +1 -0
- package/dist/types/model/chat-v2/toolContinuationConnection.d.ts +28 -0
- package/dist/types/model/nodes/ArrayNode.d.ts +0 -1
- package/dist/types/model/nodes/AssembleMessageNode.d.ts +0 -1
- package/dist/types/model/nodes/AssemblePromptNode.d.ts +0 -1
- package/dist/types/model/nodes/DelayNode.d.ts +0 -1
- package/dist/types/model/nodes/DidRunNode.d.ts +0 -1
- package/dist/types/model/nodes/GetStoredValueNode.d.ts +25 -0
- package/dist/types/model/nodes/JoinNode.d.ts +0 -1
- package/dist/types/model/nodes/LoopControllerNode.d.ts +0 -1
- package/dist/types/model/nodes/PassthroughNode.d.ts +0 -1
- package/dist/types/model/nodes/RaceInputsNode.d.ts +0 -1
- package/dist/types/model/nodes/ReportProgressNode.d.ts +23 -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/toolCallDelegation.d.ts +4 -0
- package/dist/types/model/nodes/variadicPortIndex.d.ts +4 -0
- package/dist/types/recording/RecordedEvents.d.ts +10 -0
- package/dist/types/webAppRuntime.d.ts +8 -3
- package/package.json +2 -2
- package/dist/esm/plugins/anthropic/fetchEventSource.js +0 -107
- package/dist/types/plugins/anthropic/fetchEventSource.d.ts +0 -11
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { coerceType, coerceTypeOptional } from '../../utils/coerceType.js';
|
|
2
|
-
import { getScalarTypeOf, isArrayDataValue } from '../DataValue.js';
|
|
2
|
+
import { getScalarTypeOf, isArrayDataValue, } from '../DataValue.js';
|
|
3
3
|
export function coercePromptToChatMessages(prompt, options = {}) {
|
|
4
4
|
if (!prompt) {
|
|
5
5
|
if (options.requirePrompt) {
|
|
@@ -32,16 +32,12 @@ export function coercePromptToChatMessages(prompt, options = {}) {
|
|
|
32
32
|
return [coercedMessage];
|
|
33
33
|
}
|
|
34
34
|
const coercedString = coerceTypeOptional(value, 'string');
|
|
35
|
-
return coercedString != null ? [{ type: 'user', message:
|
|
35
|
+
return coercedString != null ? [{ type: 'user', message: coercedString }] : [];
|
|
36
36
|
}
|
|
37
37
|
export function prependSystemPrompt(messages, systemPrompt) {
|
|
38
|
-
|
|
38
|
+
const systemMessage = coerceTypeOptional(systemPrompt, 'string');
|
|
39
|
+
if (!systemMessage) {
|
|
39
40
|
return messages;
|
|
40
41
|
}
|
|
41
|
-
|
|
42
|
-
const nextMessages = [...messages];
|
|
43
|
-
if (nextMessages.length > 0 && nextMessages[0].type === 'system') {
|
|
44
|
-
nextMessages.splice(0, 1);
|
|
45
|
-
}
|
|
46
|
-
return [{ type: 'system', message: systemMessage }, ...nextMessages];
|
|
42
|
+
return [{ type: 'system', message: systemMessage }, ...messages];
|
|
47
43
|
}
|
|
@@ -58,6 +58,39 @@ function parseResponseBodyMessage(responseBody) {
|
|
|
58
58
|
return compact(responseBody);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
+
function getProviderMessage(error, seen = new Set()) {
|
|
62
|
+
if (!isRecord(error) || seen.has(error)) {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
seen.add(error);
|
|
66
|
+
const responseBodyMessage = typeof error.responseBody === 'string' ? parseResponseBodyMessage(error.responseBody) : undefined;
|
|
67
|
+
if (responseBodyMessage) {
|
|
68
|
+
return responseBodyMessage;
|
|
69
|
+
}
|
|
70
|
+
const response = error.response;
|
|
71
|
+
if (isRecord(response)) {
|
|
72
|
+
const nestedResponseBody = typeof response.responseBody === 'string'
|
|
73
|
+
? response.responseBody
|
|
74
|
+
: typeof response.body === 'string'
|
|
75
|
+
? response.body
|
|
76
|
+
: undefined;
|
|
77
|
+
const nestedResponseMessage = parseResponseBodyMessage(nestedResponseBody) ??
|
|
78
|
+
findProviderMessage(response.data) ??
|
|
79
|
+
findProviderMessage(response);
|
|
80
|
+
if (nestedResponseMessage) {
|
|
81
|
+
return nestedResponseMessage;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const dataMessage = findProviderMessage(error.data);
|
|
85
|
+
if (dataMessage) {
|
|
86
|
+
return dataMessage;
|
|
87
|
+
}
|
|
88
|
+
const causeMessage = getProviderMessage(error.cause, seen);
|
|
89
|
+
if (causeMessage) {
|
|
90
|
+
return causeMessage;
|
|
91
|
+
}
|
|
92
|
+
return findProviderMessage(error);
|
|
93
|
+
}
|
|
61
94
|
function formatEndpoint(url) {
|
|
62
95
|
try {
|
|
63
96
|
const parsed = new URL(url);
|
|
@@ -180,7 +213,7 @@ function formatProviderFetchError(error, context) {
|
|
|
180
213
|
function formatApiCallError(error, context) {
|
|
181
214
|
const statusCode = getChatV2ProviderErrorStatusCode(error);
|
|
182
215
|
const statusLabel = statusCode == null ? 'request failed' : `${statusCode} ${STATUS_TEXT[statusCode] ?? 'HTTP error'}`;
|
|
183
|
-
const providerMessage =
|
|
216
|
+
const providerMessage = getProviderMessage(error);
|
|
184
217
|
const lines = [
|
|
185
218
|
`LLM provider request failed (${statusLabel}).`,
|
|
186
219
|
`Provider: ${getChatV2ProviderLabel(context.provider)}`,
|
|
@@ -189,10 +222,10 @@ function formatApiCallError(error, context) {
|
|
|
189
222
|
if (error.url) {
|
|
190
223
|
lines.push(`Endpoint: ${formatEndpoint(error.url)}`);
|
|
191
224
|
}
|
|
192
|
-
|
|
193
|
-
if (providerMessage && providerMessage !== compact(error.message)) {
|
|
225
|
+
if (providerMessage) {
|
|
194
226
|
lines.push(`Provider message: ${providerMessage}`);
|
|
195
227
|
}
|
|
228
|
+
lines.push(getApiCallRecommendation(statusCode, context));
|
|
196
229
|
return lines.join('\n');
|
|
197
230
|
}
|
|
198
231
|
function formatKnownSdkError(error, context) {
|
|
@@ -18,9 +18,7 @@ function addUsage(accumulated, usage) {
|
|
|
18
18
|
totalTokens: accumulated.totalTokens + usage.totalTokens,
|
|
19
19
|
cachedTokens: accumulated.cachedTokens + usage.cachedTokens,
|
|
20
20
|
reasoningTokens: accumulated.reasoningTokens + usage.reasoningTokens,
|
|
21
|
-
totalCost: accumulated.totalCost == null || usage.totalCost == null
|
|
22
|
-
? undefined
|
|
23
|
-
: accumulated.totalCost + usage.totalCost,
|
|
21
|
+
totalCost: accumulated.totalCost == null || usage.totalCost == null ? undefined : accumulated.totalCost + usage.totalCost,
|
|
24
22
|
};
|
|
25
23
|
}
|
|
26
24
|
function applyAccumulatedUsage(result, usage, outputUsage) {
|
|
@@ -64,7 +62,7 @@ function applyAccumulatedReasoning(result, reasoningRounds, outputReasoning) {
|
|
|
64
62
|
}
|
|
65
63
|
}
|
|
66
64
|
export async function runChatV2PipelineWithToolContinuation(options) {
|
|
67
|
-
const { autoContinue, maxToolRounds, functions, delegateToolCall, runPipeline = runChatV2Pipeline, ...pipelineOptions } = options;
|
|
65
|
+
const { autoContinue, maxToolRounds, functions, delegateToolCall, delegateToolCallRound, runPipeline = runChatV2Pipeline, ...pipelineOptions } = options;
|
|
68
66
|
const toolNames = getToolNames(functions);
|
|
69
67
|
const maxRounds = Math.max(1, Math.floor(Number.isFinite(maxToolRounds) ? maxToolRounds : 1));
|
|
70
68
|
let currentPrompt = pipelineOptions.prompt;
|
|
@@ -83,9 +81,7 @@ export async function runChatV2PipelineWithToolContinuation(options) {
|
|
|
83
81
|
if (autoContinue) {
|
|
84
82
|
appendReasoningRound(reasoningRounds, result.reasoning);
|
|
85
83
|
}
|
|
86
|
-
if (!autoContinue ||
|
|
87
|
-
completedRounds >= maxRounds ||
|
|
88
|
-
!canAutoContinue(result.functionCalls, toolNames)) {
|
|
84
|
+
if (!autoContinue || completedRounds >= maxRounds || !canAutoContinue(result.functionCalls, toolNames)) {
|
|
89
85
|
if (result.functionCalls.length === 0 && delegatedToolCalls.length > 0 && pipelineOptions.includeFunctionCalls) {
|
|
90
86
|
result.commonOutputs['function-calls'] = {
|
|
91
87
|
type: 'object[]',
|
|
@@ -98,7 +94,9 @@ export async function runChatV2PipelineWithToolContinuation(options) {
|
|
|
98
94
|
}
|
|
99
95
|
return result;
|
|
100
96
|
}
|
|
101
|
-
const toolResultMessages =
|
|
97
|
+
const toolResultMessages = delegateToolCallRound
|
|
98
|
+
? await delegateToolCallRound(result.functionCalls, result.response)
|
|
99
|
+
: await Promise.all(result.functionCalls.map(delegateToolCall));
|
|
102
100
|
delegatedToolCalls.push(...toolResultMessages
|
|
103
101
|
.map((message) => message.delegatedToolCall)
|
|
104
102
|
.filter((record) => record != null));
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export const LLM_CHAT_V2_TOOL_CALLS_OUTPUT_ID = 'function-calls';
|
|
2
|
+
export const DELEGATE_TOOL_CALL_INPUT_ID = 'function-call';
|
|
3
|
+
/**
|
|
4
|
+
* Resolves every special request/response relationship formed by an
|
|
5
|
+
* auto-continuing LLM Chat node and an effective Delegate Tool Call input.
|
|
6
|
+
* Callers that inspect a whole graph should reuse this single pass.
|
|
7
|
+
*/
|
|
8
|
+
export function resolveToolContinuationConnections(graph) {
|
|
9
|
+
const nodesById = new Map(graph.nodes.map((node) => [node.id, node]));
|
|
10
|
+
const firstConnectionByInput = new Map();
|
|
11
|
+
for (const connection of graph.connections) {
|
|
12
|
+
if (!nodesById.has(connection.outputNodeId) || !nodesById.has(connection.inputNodeId)) {
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
const inputKey = `${connection.inputNodeId}\u0000${connection.inputId}`;
|
|
16
|
+
if (!firstConnectionByInput.has(inputKey)) {
|
|
17
|
+
firstConnectionByInput.set(inputKey, connection);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const candidatesByLLMNodeId = new Map();
|
|
21
|
+
for (const connection of graph.connections) {
|
|
22
|
+
if (connection.outputId !== LLM_CHAT_V2_TOOL_CALLS_OUTPUT_ID ||
|
|
23
|
+
connection.inputId !== DELEGATE_TOOL_CALL_INPUT_ID) {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
const llmNode = nodesById.get(connection.outputNodeId);
|
|
27
|
+
const delegateNode = nodesById.get(connection.inputNodeId);
|
|
28
|
+
if (!isEligibleLLMChatV2Node(llmNode) || !isEligibleDelegateToolCallNode(delegateNode)) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const inputKey = `${connection.inputNodeId}\u0000${connection.inputId}`;
|
|
32
|
+
if (firstConnectionByInput.get(inputKey) !== connection) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const candidates = candidatesByLLMNodeId.get(llmNode.id);
|
|
36
|
+
const candidate = { connection, delegateNode };
|
|
37
|
+
if (candidates) {
|
|
38
|
+
candidates.push(candidate);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
candidatesByLLMNodeId.set(llmNode.id, [candidate]);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const resolutions = new Map();
|
|
45
|
+
for (const [llmNodeId, candidates] of candidatesByLLMNodeId) {
|
|
46
|
+
if (candidates.length === 1) {
|
|
47
|
+
resolutions.set(llmNodeId, { kind: 'connected', ...candidates[0] });
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
resolutions.set(llmNodeId, { kind: 'ambiguous', candidates });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return resolutions;
|
|
54
|
+
}
|
|
55
|
+
/** Resolves one LLM node while preserving the convenient `none` result. */
|
|
56
|
+
export function resolveToolContinuationConnection(graph, llmNodeId) {
|
|
57
|
+
return resolveToolContinuationConnections(graph).get(llmNodeId) ?? { kind: 'none' };
|
|
58
|
+
}
|
|
59
|
+
function isEligibleLLMChatV2Node(node) {
|
|
60
|
+
if (!node || node.disabled || node.isSplitRun || node.type !== 'llmChatV2') {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
const data = node.data;
|
|
64
|
+
return data.useToolCalling === true && data.autoContinueToolCalls === true;
|
|
65
|
+
}
|
|
66
|
+
function isEligibleDelegateToolCallNode(node) {
|
|
67
|
+
return node?.type === 'delegateFunctionCall' && !node.disabled;
|
|
68
|
+
}
|
|
@@ -7,6 +7,7 @@ import { flattenDeep } from 'lodash-es';
|
|
|
7
7
|
import { dedent } from 'ts-dedent';
|
|
8
8
|
import {} from '../EditorDefinition.js';
|
|
9
9
|
import { nodeDefinition } from '../NodeDefinition.js';
|
|
10
|
+
import { getNextVariadicPortIndex } from './variadicPortIndex.js';
|
|
10
11
|
export class ArrayNodeImpl extends NodeImpl {
|
|
11
12
|
static create() {
|
|
12
13
|
const chartNode = {
|
|
@@ -27,7 +28,7 @@ export class ArrayNodeImpl extends NodeImpl {
|
|
|
27
28
|
}
|
|
28
29
|
getInputDefinitions(connections) {
|
|
29
30
|
const inputs = [];
|
|
30
|
-
const inputCount =
|
|
31
|
+
const inputCount = getNextVariadicPortIndex(connections, this.chartNode.id, 'input', 'legacy');
|
|
31
32
|
for (let i = 1; i <= inputCount; i++) {
|
|
32
33
|
inputs.push({
|
|
33
34
|
dataType: 'any',
|
|
@@ -70,18 +71,6 @@ export class ArrayNodeImpl extends NodeImpl {
|
|
|
70
71
|
},
|
|
71
72
|
];
|
|
72
73
|
}
|
|
73
|
-
#getInputPortCount(connections) {
|
|
74
|
-
const inputNodeId = this.chartNode.id;
|
|
75
|
-
const inputConnections = connections.filter((connection) => connection.inputNodeId === inputNodeId && connection.inputId.startsWith('input'));
|
|
76
|
-
let maxInputNumber = 0;
|
|
77
|
-
for (const connection of inputConnections) {
|
|
78
|
-
const inputNumber = parseInt(connection.inputId.replace('input', ''));
|
|
79
|
-
if (inputNumber > maxInputNumber) {
|
|
80
|
-
maxInputNumber = inputNumber;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return maxInputNumber + 1;
|
|
84
|
-
}
|
|
85
74
|
static getUIData() {
|
|
86
75
|
return {
|
|
87
76
|
infoBoxBody: dedent `
|
|
@@ -7,6 +7,7 @@ import { orderBy } from 'lodash-es';
|
|
|
7
7
|
import { coerceTypeOptional, dedent, getInputOrData } from '../../utils/index.js';
|
|
8
8
|
import { nodeDefinition } from '../NodeDefinition.js';
|
|
9
9
|
import { match } from 'ts-pattern';
|
|
10
|
+
import { getNextVariadicPortIndex } from './variadicPortIndex.js';
|
|
10
11
|
const messageTypeToTitle = {
|
|
11
12
|
assistant: 'Assistant',
|
|
12
13
|
function: 'Function Tool Call',
|
|
@@ -35,7 +36,7 @@ export class AssembleMessageNodeImpl extends NodeImpl {
|
|
|
35
36
|
}
|
|
36
37
|
getInputDefinitions(connections) {
|
|
37
38
|
const inputs = [];
|
|
38
|
-
const messageCount =
|
|
39
|
+
const messageCount = getNextVariadicPortIndex(connections, this.chartNode.id, 'part', 'legacy');
|
|
39
40
|
if (this.data.useTypeInput) {
|
|
40
41
|
inputs.push({
|
|
41
42
|
dataType: 'string',
|
|
@@ -96,18 +97,6 @@ export class AssembleMessageNodeImpl extends NodeImpl {
|
|
|
96
97
|
},
|
|
97
98
|
];
|
|
98
99
|
}
|
|
99
|
-
#getInputPortCount(connections) {
|
|
100
|
-
const inputNodeId = this.chartNode.id;
|
|
101
|
-
const messageConnections = connections.filter((connection) => connection.inputNodeId === inputNodeId && connection.inputId.startsWith('part'));
|
|
102
|
-
let maxMessageNumber = 0;
|
|
103
|
-
for (const connection of messageConnections) {
|
|
104
|
-
const messageNumber = parseInt(connection.inputId.replace('part', ''));
|
|
105
|
-
if (messageNumber > maxMessageNumber) {
|
|
106
|
-
maxMessageNumber = messageNumber;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return maxMessageNumber + 1;
|
|
110
|
-
}
|
|
111
100
|
static getUIData() {
|
|
112
101
|
return {
|
|
113
102
|
infoBoxBody: dedent `
|
|
@@ -8,6 +8,7 @@ import { orderBy } from 'lodash-es';
|
|
|
8
8
|
import { dedent } from 'ts-dedent';
|
|
9
9
|
import { nodeDefinition } from '../NodeDefinition.js';
|
|
10
10
|
import { getInputOrData } from '../../utils/inputs.js';
|
|
11
|
+
import { getNextVariadicPortIndex } from './variadicPortIndex.js';
|
|
11
12
|
export class AssemblePromptNodeImpl extends NodeImpl {
|
|
12
13
|
static create() {
|
|
13
14
|
const chartNode = {
|
|
@@ -25,7 +26,7 @@ export class AssemblePromptNodeImpl extends NodeImpl {
|
|
|
25
26
|
}
|
|
26
27
|
getInputDefinitions(connections) {
|
|
27
28
|
const inputs = [];
|
|
28
|
-
const messageCount =
|
|
29
|
+
const messageCount = getNextVariadicPortIndex(connections, this.chartNode.id, 'message', 'legacy');
|
|
29
30
|
if (this.data.useIsLastMessageCacheBreakpointInput) {
|
|
30
31
|
inputs.push({
|
|
31
32
|
dataType: 'boolean',
|
|
@@ -63,18 +64,6 @@ export class AssemblePromptNodeImpl extends NodeImpl {
|
|
|
63
64
|
}
|
|
64
65
|
return outputs;
|
|
65
66
|
}
|
|
66
|
-
#getMessagePortCount(connections) {
|
|
67
|
-
const inputNodeId = this.chartNode.id;
|
|
68
|
-
const messageConnections = connections.filter((connection) => connection.inputNodeId === inputNodeId && connection.inputId.startsWith('message'));
|
|
69
|
-
let maxMessageNumber = 0;
|
|
70
|
-
for (const connection of messageConnections) {
|
|
71
|
-
const messageNumber = parseInt(connection.inputId.replace('message', ''));
|
|
72
|
-
if (messageNumber > maxMessageNumber) {
|
|
73
|
-
maxMessageNumber = messageNumber;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return maxMessageNumber + 1;
|
|
77
|
-
}
|
|
78
67
|
static getUIData() {
|
|
79
68
|
return {
|
|
80
69
|
infoBoxBody: dedent `
|
|
@@ -6,6 +6,7 @@ import {} from '../GraphProcessor.js';
|
|
|
6
6
|
import { dedent } from 'ts-dedent';
|
|
7
7
|
import { nodeDefinition } from '../NodeDefinition.js';
|
|
8
8
|
import {} from '../EditorDefinition.js';
|
|
9
|
+
import { getNextVariadicPortIndex } from './variadicPortIndex.js';
|
|
9
10
|
const INPUT_PORT_ID_PATTERN = /^input(\d+)$/;
|
|
10
11
|
const IGNORE_NULL_LABEL = "Ignore 'null'";
|
|
11
12
|
const IGNORE_UNDEFINED_LABEL = "Ignore 'undefined'";
|
|
@@ -29,7 +30,7 @@ export class CoalesceNodeImpl extends NodeImpl {
|
|
|
29
30
|
};
|
|
30
31
|
getInputDefinitions(connections) {
|
|
31
32
|
const inputs = [];
|
|
32
|
-
const inputCount =
|
|
33
|
+
const inputCount = getNextVariadicPortIndex(connections, this.chartNode.id, 'input', 'strict-positive');
|
|
33
34
|
inputs.push({
|
|
34
35
|
dataType: 'boolean',
|
|
35
36
|
id: 'conditional',
|
|
@@ -89,20 +90,6 @@ export class CoalesceNodeImpl extends NodeImpl {
|
|
|
89
90
|
group: ['Logic'],
|
|
90
91
|
};
|
|
91
92
|
}
|
|
92
|
-
#getInputPortCount(connections) {
|
|
93
|
-
const inputNodeId = this.chartNode.id;
|
|
94
|
-
let maxInputNumber = 0;
|
|
95
|
-
for (const connection of connections) {
|
|
96
|
-
if (connection.inputNodeId !== inputNodeId) {
|
|
97
|
-
continue;
|
|
98
|
-
}
|
|
99
|
-
const inputNumber = this.#getInputPortNumber(connection.inputId);
|
|
100
|
-
if (inputNumber && inputNumber > maxInputNumber) {
|
|
101
|
-
maxInputNumber = inputNumber;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return maxInputNumber + 1;
|
|
105
|
-
}
|
|
106
93
|
async process(inputData) {
|
|
107
94
|
const conditional = inputData['conditional'];
|
|
108
95
|
// This lets the coalesce actually be control-flow-excluded itself, because otherwise
|
|
@@ -6,6 +6,7 @@ import {} from '../GraphProcessor.js';
|
|
|
6
6
|
import {} from '../../index.js';
|
|
7
7
|
import { dedent } from 'ts-dedent';
|
|
8
8
|
import { getInputOrData } from '../../utils/inputs.js';
|
|
9
|
+
import { getNextVariadicPortIndex } from './variadicPortIndex.js';
|
|
9
10
|
export class DelayNodeImpl extends NodeImpl {
|
|
10
11
|
static create() {
|
|
11
12
|
const chartNode = {
|
|
@@ -25,7 +26,7 @@ export class DelayNodeImpl extends NodeImpl {
|
|
|
25
26
|
}
|
|
26
27
|
getInputDefinitions(connections) {
|
|
27
28
|
const inputs = [];
|
|
28
|
-
const inputCount =
|
|
29
|
+
const inputCount = getNextVariadicPortIndex(connections, this.chartNode.id, 'input', 'decimal');
|
|
29
30
|
if (this.data.useDelayInput) {
|
|
30
31
|
inputs.push({
|
|
31
32
|
dataType: 'number',
|
|
@@ -44,7 +45,7 @@ export class DelayNodeImpl extends NodeImpl {
|
|
|
44
45
|
}
|
|
45
46
|
getOutputDefinitions(connections) {
|
|
46
47
|
const outputs = [];
|
|
47
|
-
const inputCount =
|
|
48
|
+
const inputCount = getNextVariadicPortIndex(connections, this.chartNode.id, 'input', 'decimal');
|
|
48
49
|
for (let i = 1; i <= inputCount - 1; i++) {
|
|
49
50
|
outputs.push({
|
|
50
51
|
dataType: 'any',
|
|
@@ -64,18 +65,6 @@ export class DelayNodeImpl extends NodeImpl {
|
|
|
64
65
|
group: ['Logic'],
|
|
65
66
|
};
|
|
66
67
|
}
|
|
67
|
-
#getInputPortCount(connections) {
|
|
68
|
-
const inputNodeId = this.chartNode.id;
|
|
69
|
-
const inputConnections = connections.filter((connection) => connection.inputNodeId === inputNodeId && connection.inputId.startsWith('input'));
|
|
70
|
-
let maxInputNumber = 0;
|
|
71
|
-
for (const connection of inputConnections) {
|
|
72
|
-
const messageNumber = parseInt(connection.inputId.replace('input', ''), 10);
|
|
73
|
-
if (messageNumber > maxInputNumber) {
|
|
74
|
-
maxInputNumber = messageNumber;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return maxInputNumber + 1;
|
|
78
|
-
}
|
|
79
68
|
getEditors() {
|
|
80
69
|
return [
|
|
81
70
|
{
|
|
@@ -3,7 +3,7 @@ import { NodeImpl } from '../NodeImpl.js';
|
|
|
3
3
|
import { dedent } from 'ts-dedent';
|
|
4
4
|
import { nodeDefinition } from '../NodeDefinition.js';
|
|
5
5
|
import { coerceType } from '../../utils/coerceType.js';
|
|
6
|
-
import { delegateToolCall, isDelegatedToolCallRecord } from './toolCallDelegation.js';
|
|
6
|
+
import { buildDelegatedToolCallOutputs, delegateToolCall, isDelegatedToolCallRecord, } from './toolCallDelegation.js';
|
|
7
7
|
export class DelegateFunctionCallNodeImpl extends NodeImpl {
|
|
8
8
|
static create() {
|
|
9
9
|
const chartNode = {
|
|
@@ -29,7 +29,7 @@ export class DelegateFunctionCallNodeImpl extends NodeImpl {
|
|
|
29
29
|
const inputs = [];
|
|
30
30
|
inputs.push({
|
|
31
31
|
id: 'function-call',
|
|
32
|
-
dataType: 'object',
|
|
32
|
+
dataType: ['object', 'object[]'],
|
|
33
33
|
title: 'Tool Call',
|
|
34
34
|
coerced: true,
|
|
35
35
|
required: true,
|
|
@@ -39,6 +39,12 @@ export class DelegateFunctionCallNodeImpl extends NodeImpl {
|
|
|
39
39
|
}
|
|
40
40
|
getOutputDefinitions() {
|
|
41
41
|
const outputs = [];
|
|
42
|
+
outputs.push({
|
|
43
|
+
id: 'assistant-message',
|
|
44
|
+
dataType: 'string',
|
|
45
|
+
title: 'Message (fires before tool call invocation)',
|
|
46
|
+
description: 'Nonblank text the assistant emitted alongside a connected tool-call round. This output fires before the tools are invoked.',
|
|
47
|
+
});
|
|
42
48
|
outputs.push({
|
|
43
49
|
id: 'output',
|
|
44
50
|
dataType: ['string', 'string[]'],
|
|
@@ -48,8 +54,8 @@ export class DelegateFunctionCallNodeImpl extends NodeImpl {
|
|
|
48
54
|
outputs.push({
|
|
49
55
|
id: 'message',
|
|
50
56
|
dataType: ['chat-message', 'chat-message[]', 'object', 'object[]'],
|
|
51
|
-
title: 'Message
|
|
52
|
-
description: 'Maps the
|
|
57
|
+
title: 'Tool Result Message',
|
|
58
|
+
description: 'Maps the tool result into a chat message for a later LLM request.',
|
|
53
59
|
});
|
|
54
60
|
return outputs;
|
|
55
61
|
}
|
|
@@ -69,7 +75,7 @@ export class DelegateFunctionCallNodeImpl extends NodeImpl {
|
|
|
69
75
|
type: 'toggle',
|
|
70
76
|
label: 'Auto Delegate',
|
|
71
77
|
dataKey: 'autoDelegate',
|
|
72
|
-
helperMessage: '
|
|
78
|
+
helperMessage: 'Prefers a subgraph whose name exactly matches the tool, then falls back to the first name containing it.',
|
|
73
79
|
},
|
|
74
80
|
{
|
|
75
81
|
type: 'toggle',
|
|
@@ -129,16 +135,7 @@ export class DelegateFunctionCallNodeImpl extends NodeImpl {
|
|
|
129
135
|
return buildDelegatedToolCallOutputs(delegatedRecords);
|
|
130
136
|
}
|
|
131
137
|
const result = await delegateToolCall(functionCallInput, context, this.data);
|
|
132
|
-
return
|
|
133
|
-
['output']: {
|
|
134
|
-
type: 'string',
|
|
135
|
-
value: result.outputString,
|
|
136
|
-
},
|
|
137
|
-
['message']: {
|
|
138
|
-
type: 'chat-message',
|
|
139
|
-
value: result.message,
|
|
140
|
-
},
|
|
141
|
-
};
|
|
138
|
+
return buildDelegatedToolCallOutputs([result.record], undefined, result.cost);
|
|
142
139
|
}
|
|
143
140
|
}
|
|
144
141
|
function getDelegatedToolCallRecords(input) {
|
|
@@ -147,29 +144,4 @@ function getDelegatedToolCallRecords(input) {
|
|
|
147
144
|
}
|
|
148
145
|
return isDelegatedToolCallRecord(input) ? [input] : [];
|
|
149
146
|
}
|
|
150
|
-
function buildDelegatedToolCallOutputs(records) {
|
|
151
|
-
if (records.length === 1) {
|
|
152
|
-
const [record] = records;
|
|
153
|
-
return {
|
|
154
|
-
['output']: {
|
|
155
|
-
type: 'string',
|
|
156
|
-
value: record.output,
|
|
157
|
-
},
|
|
158
|
-
['message']: {
|
|
159
|
-
type: 'chat-message',
|
|
160
|
-
value: record.message,
|
|
161
|
-
},
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
return {
|
|
165
|
-
['output']: {
|
|
166
|
-
type: 'string[]',
|
|
167
|
-
value: records.map((record) => record.output),
|
|
168
|
-
},
|
|
169
|
-
['message']: {
|
|
170
|
-
type: 'chat-message[]',
|
|
171
|
-
value: records.map((record) => record.message),
|
|
172
|
-
},
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
147
|
export const delegateFunctionCallNode = nodeDefinition(DelegateFunctionCallNodeImpl, 'Delegate Tool Call');
|
|
@@ -4,6 +4,7 @@ import { NodeImpl } from '../NodeImpl.js';
|
|
|
4
4
|
import { nodeDefinition } from '../NodeDefinition.js';
|
|
5
5
|
import {} from '../GraphProcessor.js';
|
|
6
6
|
import {} from '../EditorDefinition.js';
|
|
7
|
+
import { getNextVariadicPortIndex } from './variadicPortIndex.js';
|
|
7
8
|
const DID_RUN_EXPLANATION = 'Outputs true when all connected inputs have run. Falsy or empty values still count as having run, so this is useful for adapting "did this branch run at all?" into a boolean If port.';
|
|
8
9
|
export class DidRunNodeImpl extends NodeImpl {
|
|
9
10
|
static create() {
|
|
@@ -20,7 +21,7 @@ export class DidRunNodeImpl extends NodeImpl {
|
|
|
20
21
|
};
|
|
21
22
|
}
|
|
22
23
|
getInputDefinitions(connections) {
|
|
23
|
-
const inputCount =
|
|
24
|
+
const inputCount = getNextVariadicPortIndex(connections, this.chartNode.id, 'input', 'decimal');
|
|
24
25
|
const inputs = [];
|
|
25
26
|
for (let i = 1; i <= inputCount; i++) {
|
|
26
27
|
inputs.push({
|
|
@@ -57,18 +58,6 @@ export class DidRunNodeImpl extends NodeImpl {
|
|
|
57
58
|
},
|
|
58
59
|
];
|
|
59
60
|
}
|
|
60
|
-
#getInputPortCount(connections) {
|
|
61
|
-
const inputNodeId = this.chartNode.id;
|
|
62
|
-
const inputConnections = connections.filter((connection) => connection.inputNodeId === inputNodeId && connection.inputId.startsWith('input'));
|
|
63
|
-
let maxInputNumber = 0;
|
|
64
|
-
for (const connection of inputConnections) {
|
|
65
|
-
const inputNumber = parseInt(connection.inputId.replace('input', ''), 10);
|
|
66
|
-
if (inputNumber > maxInputNumber) {
|
|
67
|
-
maxInputNumber = inputNumber;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return maxInputNumber + 1;
|
|
71
|
-
}
|
|
72
61
|
async process(inputData) {
|
|
73
62
|
const hasDynamicInput = Object.keys(inputData).some((key) => key.startsWith('input'));
|
|
74
63
|
if (!hasDynamicInput) {
|
|
@@ -0,0 +1,109 @@
|
|
|
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 { missingStoredValueDataValue, portableStoredValueScalarTypes, storedValueToDataValue, } from './StoredValueNodeUtils.js';
|
|
7
|
+
export class GetStoredValueNodeImpl extends NodeImpl {
|
|
8
|
+
static create() {
|
|
9
|
+
return {
|
|
10
|
+
type: 'getStoredValue',
|
|
11
|
+
title: 'Get Stored Value',
|
|
12
|
+
id: nanoid(),
|
|
13
|
+
visualData: { x: 0, y: 0, width: 220 },
|
|
14
|
+
data: { dataType: 'string', key: 'key', onDemand: false, useKeyInput: false, wait: false },
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
getInputDefinitions() {
|
|
18
|
+
return this.data.useKeyInput ? [{ id: 'key', title: 'Key', dataType: 'string' }] : [];
|
|
19
|
+
}
|
|
20
|
+
getOutputDefinitions() {
|
|
21
|
+
return [
|
|
22
|
+
{
|
|
23
|
+
id: 'value',
|
|
24
|
+
title: 'Value',
|
|
25
|
+
dataType: this.data.onDemand ? `fn<${this.data.dataType}>` : this.data.dataType,
|
|
26
|
+
},
|
|
27
|
+
{ id: 'found', title: 'Found', dataType: 'boolean' },
|
|
28
|
+
{ id: 'key', title: 'Key', dataType: 'string' },
|
|
29
|
+
];
|
|
30
|
+
}
|
|
31
|
+
getEditors() {
|
|
32
|
+
return [
|
|
33
|
+
{
|
|
34
|
+
type: 'custom',
|
|
35
|
+
label: 'Search Stored Values',
|
|
36
|
+
customEditorId: 'GetStoredValueSelector',
|
|
37
|
+
autoFocus: true,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
type: 'string',
|
|
41
|
+
dataKey: 'key',
|
|
42
|
+
useInputToggleDataKey: 'useKeyInput',
|
|
43
|
+
label: 'Key',
|
|
44
|
+
includeInGraphSearch: true,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
type: 'dataTypeSelector',
|
|
48
|
+
dataKey: 'dataType',
|
|
49
|
+
label: 'Data Type',
|
|
50
|
+
allowedDataTypes: portableStoredValueScalarTypes,
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
type: 'toggle',
|
|
54
|
+
dataKey: 'onDemand',
|
|
55
|
+
label: 'On Demand',
|
|
56
|
+
turnOffDataKeysWhenEnabled: ['wait'],
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
type: 'toggle',
|
|
60
|
+
dataKey: 'wait',
|
|
61
|
+
label: 'Wait',
|
|
62
|
+
turnOffDataKeysWhenEnabled: ['onDemand'],
|
|
63
|
+
},
|
|
64
|
+
];
|
|
65
|
+
}
|
|
66
|
+
getBody() {
|
|
67
|
+
return dedent `
|
|
68
|
+
${this.data.useKeyInput ? '(Key from input)' : this.data.key}
|
|
69
|
+
Type: ${this.data.dataType}
|
|
70
|
+
${this.data.wait ? 'Waits for an in-run Set' : ''}
|
|
71
|
+
`;
|
|
72
|
+
}
|
|
73
|
+
static getUIData() {
|
|
74
|
+
return {
|
|
75
|
+
infoBoxBody: 'Loads a portable JSON value from the root-run cache or the host persistence store. Missing keys return the selected type default.',
|
|
76
|
+
infoBoxTitle: 'Get Stored Value Node',
|
|
77
|
+
contextMenuTitle: 'Get Stored Value',
|
|
78
|
+
group: ['Advanced'],
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
async process(inputs, context) {
|
|
82
|
+
if (this.data.onDemand && this.data.wait)
|
|
83
|
+
throw new Error('Cannot use On Demand and Wait together');
|
|
84
|
+
const key = this.data.useKeyInput ? coerceType(inputs['key'], 'string') : this.data.key;
|
|
85
|
+
let result = await context.getStoredValue(key);
|
|
86
|
+
if (!result.found && this.data.wait) {
|
|
87
|
+
result = { found: true, value: await context.waitForStoredValue(key, context.signal) };
|
|
88
|
+
}
|
|
89
|
+
const value = this.data.onDemand
|
|
90
|
+
? {
|
|
91
|
+
type: `fn<${this.data.dataType}>`,
|
|
92
|
+
value: () => {
|
|
93
|
+
const cached = context.getCachedStoredValue(key);
|
|
94
|
+
return cached.found
|
|
95
|
+
? storedValueToDataValue(cached.value, this.data.dataType).value
|
|
96
|
+
: missingStoredValueDataValue(this.data.dataType).value;
|
|
97
|
+
},
|
|
98
|
+
}
|
|
99
|
+
: result.found
|
|
100
|
+
? storedValueToDataValue(result.value, this.data.dataType)
|
|
101
|
+
: missingStoredValueDataValue(this.data.dataType);
|
|
102
|
+
return {
|
|
103
|
+
['value']: value,
|
|
104
|
+
['found']: { type: 'boolean', value: result.found },
|
|
105
|
+
['key']: { type: 'string', value: key },
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
export const getStoredValueNode = nodeDefinition(GetStoredValueNodeImpl, 'Get Stored Value');
|