@valerypopoff/rivet2-core 2.1.9 → 2.3.0
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 +1 -1
- package/dist/cjs/bundle.cjs +5618 -2533
- package/dist/cjs/bundle.cjs.map +4 -4
- package/dist/cjs/webAppRuntime.cjs +333 -22
- package/dist/cjs/webAppRuntime.cjs.map +4 -4
- package/dist/esm/api/createProcessor.js +2 -0
- package/dist/esm/exports.js +1 -0
- package/dist/esm/integrations/CodeRunner.js +2 -7
- package/dist/esm/integrations/CodeRunnerOptions.js +7 -0
- package/dist/esm/model/AgentResponseTrace.js +558 -0
- package/dist/esm/model/ConnectedToolContinuationHost.js +33 -0
- package/dist/esm/model/GraphProcessor.js +165 -74
- package/dist/esm/model/NodeImpl.js +6 -0
- package/dist/esm/model/ProcessContextBuilder.js +3 -1
- package/dist/esm/model/RecordingPlayer.js +212 -25
- package/dist/esm/model/SplitRunProcessor.js +49 -8
- package/dist/esm/model/SubprocessorBridge.js +3 -0
- package/dist/esm/model/ToolCallContinuationCoordinator.js +7 -3
- package/dist/esm/model/UiGraph.js +21 -0
- package/dist/esm/model/UiGraphActionProtocol.js +3 -0
- package/dist/esm/model/UiGraphBrowserRuntime.js +133 -4
- package/dist/esm/model/UiGraphRendererStyles.js +221 -0
- package/dist/esm/model/UiGraphRuntimeModel.js +9 -3
- package/dist/esm/model/UiGraphSchema.js +7 -1
- package/dist/esm/model/chat/aiSdkTools.js +3 -2
- package/dist/esm/model/chat-v2/aiSdkBridge.js +146 -14
- package/dist/esm/model/chat-v2/chatV2CallObserver.js +11 -5
- package/dist/esm/model/chat-v2/chatV2CredentialNames.js +93 -0
- package/dist/esm/model/chat-v2/chatV2EditorCache.js +47 -20
- package/dist/esm/model/chat-v2/chatV2Errors.js +7 -19
- package/dist/esm/model/chat-v2/chatV2FeatureCompatibility.js +1 -1
- package/dist/esm/model/chat-v2/chatV2Outputs.js +48 -108
- package/dist/esm/model/chat-v2/chatV2Pipeline.js +101 -149
- package/dist/esm/model/chat-v2/chatV2ProviderProfile.js +39 -4
- package/dist/esm/model/chat-v2/chatV2ProviderRegistry.js +9 -0
- package/dist/esm/model/chat-v2/chatV2RequestPlan.js +2 -3
- package/dist/esm/model/chat-v2/chatV2ResponseBodyCapture.js +63 -0
- package/dist/esm/model/chat-v2/chatV2ResponseFormat.js +8 -4
- package/dist/esm/model/chat-v2/chatV2Retry.js +4 -3
- package/dist/esm/model/chat-v2/chatV2RuntimeOptions.js +7 -7
- package/dist/esm/model/chat-v2/chatV2Shared.js +1 -1
- package/dist/esm/model/chat-v2/chatV2Types.js +20 -8
- package/dist/esm/model/chat-v2/chatV2UsageAccounting.js +78 -0
- package/dist/esm/model/chat-v2/customProviderApi.js +40 -0
- package/dist/esm/model/chat-v2/index.js +15 -0
- package/dist/esm/model/chat-v2/llmChatV2Body.js +289 -0
- package/dist/esm/model/chat-v2/llmChatV2CacheBoundary.js +32 -0
- package/dist/esm/model/chat-v2/llmChatV2CachePolicy.js +25 -0
- package/dist/esm/model/chat-v2/llmChatV2NodeData.js +13 -50
- package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +117 -24
- package/dist/esm/model/chat-v2/llmChatV2NodeMigration.js +24 -0
- package/dist/esm/model/chat-v2/llmChatV2NodeRuntime.js +150 -199
- package/dist/esm/model/chat-v2/llmInvocationCoordinator.js +60 -0
- package/dist/esm/model/chat-v2/llmInvocationDecision.js +11 -0
- package/dist/esm/model/chat-v2/llmInvocationJournal.js +43 -0
- package/dist/esm/model/chat-v2/llmInvocationPlan.js +68 -0
- package/dist/esm/model/chat-v2/llmInvocationProjections.js +5 -0
- package/dist/esm/model/chat-v2/llmInvocationResultProjector.js +48 -0
- package/dist/esm/model/chat-v2/llmModelCandidate.js +79 -0
- package/dist/esm/model/chat-v2/llmProfile.js +52 -65
- package/dist/esm/model/chat-v2/llmProfileBody.js +193 -0
- package/dist/esm/model/chat-v2/llmProfileFallback.js +442 -100
- package/dist/esm/model/chat-v2/llmProfileFieldRegistry.js +74 -0
- package/dist/esm/model/chat-v2/llmProfileHealthStore.js +326 -0
- package/dist/esm/model/chat-v2/llmProfileNodeRuntime.js +55 -33
- package/dist/esm/model/chat-v2/llmProfileTypes.js +1 -18
- package/dist/esm/model/chat-v2/llmResponseMaterializer.js +42 -0
- package/dist/esm/model/chat-v2/modelRegistry.js +54 -4
- package/dist/esm/model/chat-v2/parallelToolCalls.js +9 -2
- package/dist/esm/model/chat-v2/providerOptions.js +116 -24
- package/dist/esm/model/chat-v2/rivetToolRegistry.js +9 -0
- package/dist/esm/model/chat-v2/toolCallCodec.js +52 -0
- package/dist/esm/model/chat-v2/toolContinuation.js +72 -35
- package/dist/esm/model/chat-v2/toolHandlerResolver.js +23 -0
- package/dist/esm/model/chat-v2/toolRoundExecutor.js +12 -0
- package/dist/esm/model/nodes/ChatNode.js +6 -0
- package/dist/esm/model/nodes/ChatNodeBase.js +1 -0
- package/dist/esm/model/nodes/CodeNewNode.js +5 -47
- package/dist/esm/model/nodes/CodeNode.js +4 -46
- package/dist/esm/model/nodes/DelegateFunctionCallNode.js +19 -6
- package/dist/esm/model/nodes/ExpressionNode.js +5 -8
- package/dist/esm/model/nodes/LLMChatV2Node.js +121 -229
- package/dist/esm/model/nodes/LLMProfileNode.js +27 -8
- package/dist/esm/model/nodes/MatchNode.js +86 -41
- package/dist/esm/model/nodes/PromptNode.js +7 -0
- package/dist/esm/model/nodes/ToolNode.js +7 -0
- package/dist/esm/model/nodes/toolCallDelegation.js +177 -110
- package/dist/esm/plugins/anthropic/anthropic.js +4 -4
- package/dist/esm/plugins/anthropic/nodes/ChatAnthropicNode.js +7 -0
- package/dist/esm/plugins/gentrace/gentraceSdk.js +0 -1
- package/dist/esm/plugins/gentrace/index.js +0 -1
- package/dist/esm/plugins/gentrace/plugin.js +61 -179
- package/dist/esm/plugins/google/google.js +5 -9
- package/dist/esm/plugins/google/nodes/ChatGoogleNode.js +4 -1
- package/dist/esm/plugins.js +1 -2
- package/dist/esm/recording/ExecutionRecorder.js +62 -13
- package/dist/esm/utils/emitDetached.js +6 -3
- package/dist/esm/utils/openai.js +60 -16
- package/dist/esm/utils/serialization/serialization.js +2 -19
- package/dist/esm/webAppRuntime.js +3 -2
- package/dist/types/api/createProcessor.d.ts +3 -0
- package/dist/types/exports.d.ts +1 -0
- package/dist/types/integrations/CodeRunner.d.ts +10 -7
- package/dist/types/integrations/CodeRunnerOptions.d.ts +15 -0
- package/dist/types/model/AgentResponseTrace.d.ts +123 -0
- package/dist/types/model/ConnectedToolContinuationHost.d.ts +34 -0
- package/dist/types/model/EditorDefinition.d.ts +16 -0
- package/dist/types/model/ExecutorProtocol.d.ts +32 -11
- package/dist/types/model/GraphProcessor.d.ts +41 -9
- package/dist/types/model/NodeBase.d.ts +0 -10
- package/dist/types/model/NodeImpl.d.ts +18 -1
- package/dist/types/model/Nodes.d.ts +2 -2
- package/dist/types/model/ProcessContext.d.ts +99 -0
- package/dist/types/model/ProcessContextBuilder.d.ts +3 -1
- package/dist/types/model/RecordingPlayer.d.ts +6 -0
- package/dist/types/model/SplitRunProcessor.d.ts +10 -3
- package/dist/types/model/UiGraph.d.ts +8 -0
- package/dist/types/model/UiGraphActionProtocol.d.ts +3 -0
- package/dist/types/model/UiGraphBrowserRuntime.d.ts +11 -2
- package/dist/types/model/UiGraphRendererStyles.d.ts +1 -1
- package/dist/types/model/UiGraphRuntimeModel.d.ts +2 -0
- package/dist/types/model/UiGraphSchema.d.ts +1 -0
- package/dist/types/model/chat-v2/chatV2CallObserver.d.ts +2 -0
- package/dist/types/model/chat-v2/chatV2CredentialNames.d.ts +30 -0
- package/dist/types/model/chat-v2/chatV2EditorCache.d.ts +2 -3
- package/dist/types/model/chat-v2/chatV2Outputs.d.ts +6 -16
- package/dist/types/model/chat-v2/chatV2Pipeline.d.ts +13 -17
- package/dist/types/model/chat-v2/chatV2ProviderProfile.d.ts +7 -0
- package/dist/types/model/chat-v2/chatV2ProviderRegistry.d.ts +8 -0
- package/dist/types/model/chat-v2/chatV2RequestPlan.d.ts +2 -2
- package/dist/types/model/chat-v2/chatV2ResponseBodyCapture.d.ts +25 -0
- package/dist/types/model/chat-v2/chatV2ResponseFormat.d.ts +3 -2
- package/dist/types/model/chat-v2/chatV2Retry.d.ts +2 -0
- package/dist/types/model/chat-v2/chatV2RuntimeOptions.d.ts +3 -8
- package/dist/types/model/chat-v2/chatV2Types.d.ts +44 -10
- package/dist/types/model/chat-v2/chatV2UsageAccounting.d.ts +14 -0
- package/dist/types/model/chat-v2/customProviderApi.d.ts +22 -0
- package/dist/types/model/chat-v2/index.d.ts +15 -0
- package/dist/types/model/chat-v2/llmChatV2Body.d.ts +24 -0
- package/dist/types/model/chat-v2/llmChatV2CacheBoundary.d.ts +10 -0
- package/dist/types/model/chat-v2/llmChatV2CachePolicy.d.ts +13 -0
- package/dist/types/model/chat-v2/llmChatV2NodeData.d.ts +19 -3
- package/dist/types/model/chat-v2/llmChatV2NodeMigration.d.ts +8 -0
- package/dist/types/model/chat-v2/llmChatV2NodeRuntime.d.ts +14 -16
- package/dist/types/model/chat-v2/llmInvocationCoordinator.d.ts +16 -0
- package/dist/types/model/chat-v2/llmInvocationDecision.d.ts +21 -0
- package/dist/types/model/chat-v2/llmInvocationJournal.d.ts +38 -0
- package/dist/types/model/chat-v2/llmInvocationPlan.d.ts +41 -0
- package/dist/types/model/chat-v2/llmInvocationProjections.d.ts +3 -0
- package/dist/types/model/chat-v2/llmInvocationResultProjector.d.ts +26 -0
- package/dist/types/model/chat-v2/llmModelCandidate.d.ts +20 -0
- package/dist/types/model/chat-v2/llmProfile.d.ts +14 -0
- package/dist/types/model/chat-v2/llmProfileBody.d.ts +20 -0
- package/dist/types/model/chat-v2/llmProfileFallback.d.ts +36 -49
- package/dist/types/model/chat-v2/llmProfileFieldRegistry.d.ts +209 -0
- package/dist/types/model/chat-v2/llmProfileHealthStore.d.ts +111 -0
- package/dist/types/model/chat-v2/llmProfileNodeRuntime.d.ts +1 -1
- package/dist/types/model/chat-v2/llmProfileTypes.d.ts +4 -1
- package/dist/types/model/chat-v2/llmResponseMaterializer.d.ts +20 -0
- package/dist/types/model/chat-v2/modelRegistry.d.ts +17 -187
- package/dist/types/model/chat-v2/parallelToolCalls.d.ts +3 -1
- package/dist/types/model/chat-v2/providerOptions.d.ts +12 -0
- package/dist/types/model/chat-v2/rivetToolRegistry.d.ts +11 -0
- package/dist/types/model/chat-v2/toolCallCodec.d.ts +7 -0
- package/dist/types/model/chat-v2/toolContinuation.d.ts +3 -3
- package/dist/types/model/chat-v2/toolHandlerResolver.d.ts +25 -0
- package/dist/types/model/chat-v2/toolRoundExecutor.d.ts +18 -0
- package/dist/types/model/nodes/ChatNode.d.ts +2 -1
- package/dist/types/model/nodes/CodeNewNode.d.ts +0 -5
- package/dist/types/model/nodes/CodeNode.d.ts +0 -5
- package/dist/types/model/nodes/DelegateFunctionCallNode.d.ts +2 -1
- package/dist/types/model/nodes/LLMChatV2Node.d.ts +2 -1
- package/dist/types/model/nodes/LLMProfileNode.d.ts +2 -1
- package/dist/types/model/nodes/MatchNode.d.ts +6 -0
- package/dist/types/model/nodes/PromptNode.d.ts +4 -1
- package/dist/types/model/nodes/ToolNode.d.ts +2 -1
- package/dist/types/model/nodes/toolCallDelegation.d.ts +10 -3
- package/dist/types/plugins/anthropic/anthropic.d.ts +1 -0
- package/dist/types/plugins/gentrace/gentraceSdk.d.ts +0 -1
- package/dist/types/plugins/gentrace/plugin.d.ts +55 -9
- package/dist/types/plugins/google/google.d.ts +2 -8
- package/dist/types/plugins.d.ts +1 -1
- package/dist/types/recording/ExecutionRecorder.d.ts +7 -1
- package/dist/types/recording/RecordedEvents.d.ts +6 -0
- package/dist/types/utils/emitDetached.d.ts +3 -2
- package/dist/types/utils/openai.d.ts +49 -0
- package/dist/types/webAppRuntime.d.ts +4 -2
- package/package.json +2 -2
|
@@ -7,6 +7,8 @@ import {} from '../NodeBodySpec.js';
|
|
|
7
7
|
import { nodeDefinition } from '../NodeDefinition.js';
|
|
8
8
|
import { resolveUniqueValueDerivedPortIds } from '../../utils/orderedStringPortIds.js';
|
|
9
9
|
import { appendCodeNodeSourceUrl, buildCodeNodeSourceUrl, enrichCodeNodeErrorWithLocation, } from './codeNodeErrorDiagnostics.js';
|
|
10
|
+
import { ALL_CODE_RUNNER_OPTIONS } from '../../integrations/CodeRunnerOptions.js';
|
|
11
|
+
const CODE_RUNTIME_HELPER_MESSAGE = 'Node execution also provides "require" and "process". Browser execution provides "fetch", "console", and "Rivet".';
|
|
10
12
|
export class CodeNodeImpl extends NodeImpl {
|
|
11
13
|
static create() {
|
|
12
14
|
const chartNode = {
|
|
@@ -32,11 +34,6 @@ export class CodeNodeImpl extends NodeImpl {
|
|
|
32
34
|
`,
|
|
33
35
|
inputNames: 'input1',
|
|
34
36
|
outputNames: 'output1',
|
|
35
|
-
allowFetch: false,
|
|
36
|
-
allowRequire: false,
|
|
37
|
-
allowRivet: false,
|
|
38
|
-
allowProcess: false,
|
|
39
|
-
allowConsole: false,
|
|
40
37
|
},
|
|
41
38
|
};
|
|
42
39
|
return chartNode;
|
|
@@ -81,6 +78,7 @@ export class CodeNodeImpl extends NodeImpl {
|
|
|
81
78
|
{
|
|
82
79
|
type: 'code',
|
|
83
80
|
label: '',
|
|
81
|
+
helperMessage: CODE_RUNTIME_HELPER_MESSAGE,
|
|
84
82
|
dataKey: 'code',
|
|
85
83
|
language: 'javascript',
|
|
86
84
|
enableFolding: true,
|
|
@@ -107,40 +105,6 @@ export class CodeNodeImpl extends NodeImpl {
|
|
|
107
105
|
valueToPortId: 'sanitize-identifier',
|
|
108
106
|
},
|
|
109
107
|
},
|
|
110
|
-
{
|
|
111
|
-
type: 'group',
|
|
112
|
-
label: 'Runtime permissions',
|
|
113
|
-
defaultOpen: true,
|
|
114
|
-
editors: [
|
|
115
|
-
{
|
|
116
|
-
type: 'toggle',
|
|
117
|
-
label: 'Allow "fetch"',
|
|
118
|
-
dataKey: 'allowFetch',
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
type: 'toggle',
|
|
122
|
-
label: 'Allow "Rivet"',
|
|
123
|
-
dataKey: 'allowRivet',
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
type: 'toggle',
|
|
127
|
-
label: 'Allow "console"',
|
|
128
|
-
dataKey: 'allowConsole',
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
type: 'toggle',
|
|
132
|
-
label: 'Allow "require"',
|
|
133
|
-
dataKey: 'allowRequire',
|
|
134
|
-
helperMessage: 'Only available with the Node executor',
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
type: 'toggle',
|
|
138
|
-
label: 'Allow "process"',
|
|
139
|
-
dataKey: 'allowProcess',
|
|
140
|
-
helperMessage: 'Only available with the Node executor',
|
|
141
|
-
},
|
|
142
|
-
],
|
|
143
|
-
},
|
|
144
108
|
];
|
|
145
109
|
}
|
|
146
110
|
getBody() {
|
|
@@ -167,13 +131,7 @@ export class CodeNodeImpl extends NodeImpl {
|
|
|
167
131
|
const sourceUrl = buildCodeNodeSourceUrl(this.chartNode.id);
|
|
168
132
|
let outputs;
|
|
169
133
|
try {
|
|
170
|
-
outputs = await context.codeRunner.runCode(appendCodeNodeSourceUrl(this.data.code, sourceUrl), inputs,
|
|
171
|
-
includeFetch: this.data.allowFetch ?? false,
|
|
172
|
-
includeRequire: this.data.allowRequire ?? false,
|
|
173
|
-
includeRivet: this.data.allowRivet ?? false,
|
|
174
|
-
includeProcess: this.data.allowProcess ?? false,
|
|
175
|
-
includeConsole: this.data.allowConsole ?? false,
|
|
176
|
-
}, context.graphInputNodeValues, context.contextValues);
|
|
134
|
+
outputs = await context.codeRunner.runCode(appendCodeNodeSourceUrl(this.data.code, sourceUrl), inputs, ALL_CODE_RUNNER_OPTIONS, context.graphInputNodeValues, context.contextValues);
|
|
177
135
|
}
|
|
178
136
|
catch (error) {
|
|
179
137
|
throw await enrichCodeNodeErrorWithLocation({
|
|
@@ -39,12 +39,6 @@ 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
|
-
});
|
|
48
42
|
outputs.push({
|
|
49
43
|
id: 'tool-name',
|
|
50
44
|
dataType: ['string', 'string[]'],
|
|
@@ -57,12 +51,24 @@ export class DelegateFunctionCallNodeImpl extends NodeImpl {
|
|
|
57
51
|
title: 'Tool Arguments',
|
|
58
52
|
description: 'The resolved arguments passed to the selected tool.',
|
|
59
53
|
});
|
|
54
|
+
outputs.push({
|
|
55
|
+
id: 'assistant-message',
|
|
56
|
+
dataType: 'string',
|
|
57
|
+
title: 'Message',
|
|
58
|
+
description: 'Nonblank text the assistant emitted alongside a connected tool-call round. This output fires before the tools are invoked.',
|
|
59
|
+
});
|
|
60
60
|
outputs.push({
|
|
61
61
|
id: 'output',
|
|
62
62
|
dataType: ['string', 'string[]'],
|
|
63
63
|
title: 'Output',
|
|
64
64
|
description: 'The output of the tool call.',
|
|
65
65
|
});
|
|
66
|
+
outputs.push({
|
|
67
|
+
id: 'execution-time',
|
|
68
|
+
dataType: ['number', 'number[]'],
|
|
69
|
+
title: 'Tool Execution Time (sec)',
|
|
70
|
+
description: 'Seconds spent running the tool handler graph or external function.',
|
|
71
|
+
});
|
|
66
72
|
outputs.push({
|
|
67
73
|
id: 'message',
|
|
68
74
|
dataType: ['chat-message', 'chat-message[]', 'object', 'object[]'],
|
|
@@ -71,6 +77,13 @@ export class DelegateFunctionCallNodeImpl extends NodeImpl {
|
|
|
71
77
|
});
|
|
72
78
|
return outputs;
|
|
73
79
|
}
|
|
80
|
+
getRunActivityDescriptor() {
|
|
81
|
+
return {
|
|
82
|
+
category: 'tool',
|
|
83
|
+
primaryOutputPortId: 'output',
|
|
84
|
+
fullOutputActionLabel: 'Open tool result',
|
|
85
|
+
};
|
|
86
|
+
}
|
|
74
87
|
static getUIData() {
|
|
75
88
|
return {
|
|
76
89
|
infoBoxBody: dedent `
|
|
@@ -5,6 +5,8 @@ import {} from '../../index.js';
|
|
|
5
5
|
import { dedent } from 'ts-dedent';
|
|
6
6
|
import { nodeDefinition } from '../NodeDefinition.js';
|
|
7
7
|
import { buildJsValueInterpolatedSource, buildJsValueInputsInitializer, buildJsValuePreview, getJsValueInterpolationInputDefinitions, getJsValueInterpolationRuntimeContext, interpolateJsValuePreviewSource, sanitizeGeneratedJsValueError, } from './jsValueInterpolation.js';
|
|
8
|
+
import { ALL_CODE_RUNNER_OPTIONS } from '../../integrations/CodeRunnerOptions.js';
|
|
9
|
+
const CODE_RUNTIME_HELPER_MESSAGE = 'Node execution also provides "require" and "process". Browser execution provides "fetch", "console", and "Rivet".';
|
|
8
10
|
const DEFAULT_EXPRESSION = '{{a}} == "123" ? {{b}} : {{c}}';
|
|
9
11
|
const MAX_BODY_PREVIEW_LINES = 15;
|
|
10
12
|
const EXPRESSION_INPUTS_IDENTIFIER = '__expressionInputs';
|
|
@@ -77,7 +79,8 @@ export class ExpressionNodeImpl extends NodeImpl {
|
|
|
77
79
|
{
|
|
78
80
|
type: 'code',
|
|
79
81
|
label: 'Expression',
|
|
80
|
-
helperMessage: 'Use {{var}} to create input ports. Interpolated variables evaluate as the connected values.'
|
|
82
|
+
helperMessage: 'Use {{var}} to create input ports. Interpolated variables evaluate as the connected values. ' +
|
|
83
|
+
CODE_RUNTIME_HELPER_MESSAGE,
|
|
81
84
|
dataKey: 'expression',
|
|
82
85
|
language: 'javascript',
|
|
83
86
|
interpolationSyntax: 'js-value',
|
|
@@ -111,13 +114,7 @@ export class ExpressionNodeImpl extends NodeImpl {
|
|
|
111
114
|
const { inputNames, inputsIdentifier } = interpolationContext;
|
|
112
115
|
const source = buildExpressionWrapper(this.data.expression, interpolationContext);
|
|
113
116
|
try {
|
|
114
|
-
return await context.codeRunner.runCode(source, inputs,
|
|
115
|
-
includeFetch: false,
|
|
116
|
-
includeRequire: false,
|
|
117
|
-
includeRivet: false,
|
|
118
|
-
includeProcess: false,
|
|
119
|
-
includeConsole: false,
|
|
120
|
-
}, context.graphInputNodeValues, context.contextValues);
|
|
117
|
+
return await context.codeRunner.runCode(source, inputs, ALL_CODE_RUNNER_OPTIONS, context.graphInputNodeValues, context.contextValues);
|
|
121
118
|
}
|
|
122
119
|
catch (error) {
|
|
123
120
|
throw sanitizeExpressionError(error, inputNames, inputsIdentifier);
|
|
@@ -5,46 +5,19 @@ import { NodeImpl } from '../NodeImpl.js';
|
|
|
5
5
|
import { getCommonChatV2Inputs, getCommonChatV2Outputs } from '../chat-v2/chatV2Shared.js';
|
|
6
6
|
import { getLLMChatV2Editors } from '../chat-v2/llmChatV2NodeEditors.js';
|
|
7
7
|
import { createLLMChatV2NodeData, shouldIncludeLLMChatV2ToolCalls, } from '../chat-v2/llmChatV2NodeData.js';
|
|
8
|
+
import { getLLMChatV2BodySections } from '../chat-v2/llmChatV2Body.js';
|
|
8
9
|
import { isLLMChatV2StructuredResponseFormat } from '../chat-v2/chatV2FeatureCompatibility.js';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
10
|
+
import { LLMInvocationJournal } from '../chat-v2/llmInvocationJournal.js';
|
|
11
|
+
import { executeLLMInvocation } from '../chat-v2/llmInvocationCoordinator.js';
|
|
12
|
+
import { projectLLMInvocationDiagnostics, projectLLMInvocationResult, } from '../chat-v2/llmInvocationResultProjector.js';
|
|
13
|
+
import { isChatV2PipelineProviderFailureResult } from '../chat-v2/chatV2Pipeline.js';
|
|
14
|
+
import { shouldOutputChatV2RequestBody, shouldOutputChatV2ResponseBody } from '../chat-v2/chatV2Types.js';
|
|
15
|
+
import { buildLLMChatV2EditorCacheKey, resolveLLMChatV2RuntimeConfig, resolveLLMChatV2RuntimeProviderOptions, } from '../chat-v2/llmChatV2NodeRuntime.js';
|
|
16
|
+
import { projectLLMChatV2EditorCacheHit, writeLLMChatV2EditorCache } from '../chat-v2/llmChatV2CacheBoundary.js';
|
|
16
17
|
export { buildLLMChatV2EditorCacheKey, resolveLLMChatV2RuntimeProviderOptions };
|
|
17
18
|
function usesBaseURLInput(data) {
|
|
18
19
|
return data.provider === 'custom' && data.useCustomProviderBaseURLInput;
|
|
19
20
|
}
|
|
20
|
-
function getCustomProviderBaseURLBodyValue(data) {
|
|
21
|
-
if (data.provider !== 'custom') {
|
|
22
|
-
return undefined;
|
|
23
|
-
}
|
|
24
|
-
if (data.useCustomProviderBaseURLInput) {
|
|
25
|
-
return '(Using Input)';
|
|
26
|
-
}
|
|
27
|
-
const baseURL = data.customProviderBaseURL.trim();
|
|
28
|
-
return baseURL || undefined;
|
|
29
|
-
}
|
|
30
|
-
function getOptionLabel(options, value) {
|
|
31
|
-
return options.find((option) => option.value === (value ?? ''))?.label ?? value ?? 'Default';
|
|
32
|
-
}
|
|
33
|
-
function getProviderBodyLabel(data) {
|
|
34
|
-
return data.provider === 'custom' ? 'Custom' : getChatV2ProviderLabel(data.provider);
|
|
35
|
-
}
|
|
36
|
-
function getReasoningEffortBodyValue(data) {
|
|
37
|
-
switch (data.provider) {
|
|
38
|
-
case 'openai':
|
|
39
|
-
return getOptionLabel(openAIReasoningEffortOptions, data.openAIReasoningEffort);
|
|
40
|
-
case 'anthropic':
|
|
41
|
-
return getOptionLabel(anthropicEffortOptions, data.anthropicEffort);
|
|
42
|
-
case 'google':
|
|
43
|
-
return getOptionLabel(googleThinkingLevelOptions, data.googleThinkingLevel);
|
|
44
|
-
case 'custom':
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
21
|
function escapeMarkdownInline(value) {
|
|
49
22
|
return value
|
|
50
23
|
.replace(/\r/g, '\\r')
|
|
@@ -58,20 +31,19 @@ function escapeMarkdownInline(value) {
|
|
|
58
31
|
function getBodyLine(label, value) {
|
|
59
32
|
return `<span style="opacity: 0.55">${label}:</span> ${escapeMarkdownInline(value)}`;
|
|
60
33
|
}
|
|
61
|
-
function
|
|
62
|
-
|
|
63
|
-
return getBodyLine(label, '(Using Input)');
|
|
64
|
-
}
|
|
65
|
-
return value === undefined ? undefined : getBodyLine(label, `${value}`);
|
|
34
|
+
function escapeMarkdownPreformatted(value) {
|
|
35
|
+
return value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
66
36
|
}
|
|
67
|
-
function
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
37
|
+
function getBodySectionText(section) {
|
|
38
|
+
return [
|
|
39
|
+
...section.fields.map((field) => getBodyLine(field.label, field.value)),
|
|
40
|
+
...(section.snippet
|
|
41
|
+
? [
|
|
42
|
+
`<span style="opacity: 0.55">${section.snippet.label}:</span>`,
|
|
43
|
+
`<pre>${escapeMarkdownPreformatted(section.snippet.text)}</pre>`,
|
|
44
|
+
]
|
|
45
|
+
: []),
|
|
46
|
+
].join('\n');
|
|
75
47
|
}
|
|
76
48
|
export class LLMChatV2NodeImpl extends NodeImpl {
|
|
77
49
|
static create() {
|
|
@@ -87,6 +59,12 @@ export class LLMChatV2NodeImpl extends NodeImpl {
|
|
|
87
59
|
data: createLLMChatV2NodeData(),
|
|
88
60
|
};
|
|
89
61
|
}
|
|
62
|
+
getRunActivityDescriptor() {
|
|
63
|
+
return {
|
|
64
|
+
category: 'model',
|
|
65
|
+
primaryOutputPortId: 'response',
|
|
66
|
+
};
|
|
67
|
+
}
|
|
90
68
|
getInputDefinitions() {
|
|
91
69
|
const usesProfile = this.data.configurationMode === 'profile';
|
|
92
70
|
const commonInputData = usesProfile
|
|
@@ -211,58 +189,42 @@ export class LLMChatV2NodeImpl extends NodeImpl {
|
|
|
211
189
|
});
|
|
212
190
|
const responseOutput = outputs.find((output) => output.id === 'response');
|
|
213
191
|
if (responseOutput != null && isLLMChatV2StructuredResponseFormat(this.data.responseFormat)) {
|
|
214
|
-
responseOutput.dataType =
|
|
215
|
-
'
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
192
|
+
responseOutput.dataType =
|
|
193
|
+
this.data.responseFormat === 'json_schema'
|
|
194
|
+
? 'object'
|
|
195
|
+
: [
|
|
196
|
+
'object',
|
|
197
|
+
'object[]',
|
|
198
|
+
'any',
|
|
199
|
+
'any[]',
|
|
200
|
+
'string',
|
|
201
|
+
'string[]',
|
|
202
|
+
'number',
|
|
203
|
+
'number[]',
|
|
204
|
+
'boolean',
|
|
205
|
+
'boolean[]',
|
|
206
|
+
];
|
|
226
207
|
}
|
|
227
|
-
if (this.data
|
|
228
|
-
const profileArrayRequestDetails = this.data.configurationMode === 'profile'
|
|
229
|
-
? ['number', 'number[]', 'any']
|
|
230
|
-
: this.data.retryOnNon200
|
|
231
|
-
? 'number[]'
|
|
232
|
-
: 'number';
|
|
208
|
+
if (shouldOutputChatV2RequestBody(this.data)) {
|
|
233
209
|
outputs.push({
|
|
234
|
-
id: '
|
|
235
|
-
title: '
|
|
236
|
-
dataType:
|
|
237
|
-
...(this.data.configurationMode === 'profile'
|
|
238
|
-
? {
|
|
239
|
-
description: 'A scalar profile keeps the normal status shape. An LLM Profile array groups values by profile: one request is a number, retries are a number array.',
|
|
240
|
-
}
|
|
241
|
-
: {}),
|
|
210
|
+
id: 'requestBody',
|
|
211
|
+
title: 'LLM request body',
|
|
212
|
+
dataType: ['object', 'object[]', 'string', 'string[]', 'any', 'any[]'],
|
|
242
213
|
});
|
|
243
214
|
}
|
|
244
|
-
if (
|
|
245
|
-
const profileArrayRequestErrors = this.data.configurationMode === 'profile'
|
|
246
|
-
? ['string', 'string[]', 'any']
|
|
247
|
-
: this.data.retryOnNon200
|
|
248
|
-
? 'string[]'
|
|
249
|
-
: 'string';
|
|
215
|
+
if (shouldOutputChatV2ResponseBody(this.data)) {
|
|
250
216
|
outputs.push({
|
|
251
|
-
id: '
|
|
252
|
-
title: '
|
|
253
|
-
dataType:
|
|
254
|
-
...(this.data.configurationMode === 'profile'
|
|
255
|
-
? {
|
|
256
|
-
description: 'A scalar profile keeps the normal error shape. An LLM Profile array keeps profile positions when errors occur: one error is a string and retries are an array.',
|
|
257
|
-
}
|
|
258
|
-
: {}),
|
|
217
|
+
id: 'responseBody',
|
|
218
|
+
title: 'LLM response body',
|
|
219
|
+
dataType: ['object', 'object[]', 'string', 'string[]', 'any', 'any[]'],
|
|
259
220
|
});
|
|
260
221
|
}
|
|
261
|
-
if (
|
|
222
|
+
if (this.data.outputLLMAttempts) {
|
|
262
223
|
outputs.push({
|
|
263
|
-
id: '
|
|
264
|
-
title: 'LLM
|
|
265
|
-
dataType:
|
|
224
|
+
id: 'llmAttempts',
|
|
225
|
+
title: 'LLM Attempts',
|
|
226
|
+
dataType: 'object[]',
|
|
227
|
+
description: 'Chronological provider configuration, request, and response-validation attempts for this LLM Chat run.',
|
|
266
228
|
});
|
|
267
229
|
}
|
|
268
230
|
if (this.data.configurationMode === 'profile') {
|
|
@@ -271,11 +233,6 @@ export class LLMChatV2NodeImpl extends NodeImpl {
|
|
|
271
233
|
title: 'LLM Profile Summary',
|
|
272
234
|
dataType: 'string',
|
|
273
235
|
description: 'Human-readable profile fallback outcome for this LLM Chat run.',
|
|
274
|
-
}, {
|
|
275
|
-
id: 'llmProfileAttempts',
|
|
276
|
-
title: 'LLM Profile Attempts',
|
|
277
|
-
dataType: 'object[]',
|
|
278
|
-
description: 'Chronological provider/profile attempts for this LLM Chat run.',
|
|
279
236
|
});
|
|
280
237
|
}
|
|
281
238
|
return outputs;
|
|
@@ -297,156 +254,91 @@ export class LLMChatV2NodeImpl extends NodeImpl {
|
|
|
297
254
|
return getLLMChatV2Editors(this.data, context);
|
|
298
255
|
}
|
|
299
256
|
getBody() {
|
|
300
|
-
if (this.data.configurationMode === 'profile') {
|
|
301
|
-
return {
|
|
302
|
-
type: 'markdown',
|
|
303
|
-
disableLinks: true,
|
|
304
|
-
text: [
|
|
305
|
-
getBodyLine('Configuration', 'From LLM Profiles input'),
|
|
306
|
-
...(this.data.useToolCalling ? [getBodyLine('Tools', 'Enabled')] : []),
|
|
307
|
-
...(this.data.responseFormat ? [getBodyLine('Response format', this.data.responseFormat)] : []),
|
|
308
|
-
].join('\n'),
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
const modelInfo = getChatV2ModelInfo(this.data.provider, this.data.model);
|
|
312
|
-
const providerLabel = getProviderBodyLabel(this.data);
|
|
313
|
-
const baseURLValue = getCustomProviderBaseURLBodyValue(this.data);
|
|
314
|
-
const modelLine = modelInfo?.displayName ?? this.data.model;
|
|
315
|
-
const providerDetails = [
|
|
316
|
-
getBodyLine('Provider', providerLabel),
|
|
317
|
-
...(baseURLValue ? [getBodyLine('Base URL', baseURLValue)] : []),
|
|
318
|
-
getBodyLine('Model', modelLine),
|
|
319
|
-
];
|
|
320
|
-
const reasoningEffortValue = getReasoningEffortBodyValue(this.data);
|
|
321
257
|
return {
|
|
322
258
|
type: 'markdown',
|
|
323
259
|
disableLinks: true,
|
|
324
|
-
text:
|
|
325
|
-
...providerDetails,
|
|
326
|
-
...(reasoningEffortValue ? [getBodyLine('Reasoning effort', reasoningEffortValue)] : []),
|
|
327
|
-
getBodyLine('Temperature', this.data.useTemperatureInput ? '(Using Input)' : `${this.data.temperature}`),
|
|
328
|
-
getBodyLine('Max output tokens', this.data.useMaxTokensInput ? '(Using Input)' : `${this.data.maxTokens}`),
|
|
329
|
-
getOptionalNumberBodyLine('Top P', this.data.topP, this.data.useTopPInput),
|
|
330
|
-
getOptionalNumberBodyLine('Top K', this.data.topK, this.data.useTopKInput),
|
|
331
|
-
getOptionalNumberBodyLine('Presence penalty', this.data.presencePenalty, this.data.usePresencePenaltyInput),
|
|
332
|
-
getOptionalNumberBodyLine('Frequency penalty', this.data.frequencyPenalty, this.data.useFrequencyPenaltyInput),
|
|
333
|
-
getStopSequencesBodyLine(this.data),
|
|
334
|
-
getOptionalNumberBodyLine('Seed', this.data.seed, this.data.useSeedInput),
|
|
335
|
-
]
|
|
336
|
-
.filter((line) => line !== undefined)
|
|
337
|
-
.join('\n'),
|
|
260
|
+
text: getLLMChatV2BodySections(this.data).map(getBodySectionText).join('\n\n'),
|
|
338
261
|
};
|
|
339
262
|
}
|
|
340
263
|
async process(inputs, context) {
|
|
264
|
+
const invocationJournal = new LLMInvocationJournal();
|
|
265
|
+
let profileAttemptSequence = 0;
|
|
266
|
+
// Retries, fallback profiles, and tool continuation produce several
|
|
267
|
+
// physical provider calls underneath one node invocation. Always observe
|
|
268
|
+
// them locally so every later output projection shares one truthful
|
|
269
|
+
// boundary; whether Usage is exposed remains an output-setting decision.
|
|
270
|
+
const usageTrackingContext = {
|
|
271
|
+
...context,
|
|
272
|
+
onChatV2CallFinished: (event) => {
|
|
273
|
+
try {
|
|
274
|
+
invocationJournal.recordModelCall(event);
|
|
275
|
+
}
|
|
276
|
+
catch {
|
|
277
|
+
// Accounting is observational and must never affect a provider call.
|
|
278
|
+
}
|
|
279
|
+
return context.onChatV2CallFinished?.(event);
|
|
280
|
+
},
|
|
281
|
+
};
|
|
341
282
|
const runtime = await resolveLLMChatV2RuntimeConfig({
|
|
342
283
|
data: this.data,
|
|
343
284
|
nodeId: this.chartNode.id,
|
|
344
285
|
inputs,
|
|
345
|
-
context,
|
|
286
|
+
context: usageTrackingContext,
|
|
287
|
+
onLLMAttempt: (attempt) => {
|
|
288
|
+
invocationJournal.recordLLMAttempt(attempt);
|
|
289
|
+
context.onLLMProfileAttempt?.({
|
|
290
|
+
...attempt,
|
|
291
|
+
eventId: `${context.processId}:llm-profile-attempt:${profileAttemptSequence++}`,
|
|
292
|
+
nodeId: context.node.id,
|
|
293
|
+
processId: context.processId,
|
|
294
|
+
});
|
|
295
|
+
},
|
|
346
296
|
});
|
|
347
297
|
const toolCallContinuation = context.toolCallContinuation;
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
cachedStatus.value = compactLLMProfileRequestStatuses(cachedStatus.value);
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
if (runtime.profileChainUsesArray && shouldOutputChatV2RequestError(this.data)) {
|
|
356
|
-
const cachedError = runtime.cachedOutputs['requestError'];
|
|
357
|
-
if (cachedError?.type === 'any' && Array.isArray(cachedError.value)) {
|
|
358
|
-
cachedError.value = compactLLMProfileRequestErrors(cachedError.value);
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
// Cached provider output belongs to an earlier invocation, whereas this
|
|
362
|
-
// port is an observability record for physical profile attempts made by
|
|
363
|
-
// the current one. A cache hit made no such attempt.
|
|
364
|
-
if (runtime.profileAttempts != null) {
|
|
365
|
-
runtime.cachedOutputs['llmProfileAttempts'] = {
|
|
366
|
-
type: 'object[]',
|
|
367
|
-
value: [],
|
|
368
|
-
};
|
|
369
|
-
runtime.cachedOutputs['llmProfileSummary'] = {
|
|
370
|
-
type: 'string',
|
|
371
|
-
value: 'Editor cache hit — no LLM Profile calls were made for this run.',
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
return runtime.cachedOutputs;
|
|
298
|
+
const cacheHit = projectLLMChatV2EditorCacheHit(runtime);
|
|
299
|
+
if (cacheHit != null) {
|
|
300
|
+
context.markResultAsEditorCacheHit?.();
|
|
301
|
+
return cacheHit;
|
|
375
302
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
:
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
unknownHandler: undefined,
|
|
396
|
-
autoDelegate: true,
|
|
397
|
-
fallBackToExternalCall: true,
|
|
398
|
-
passthroughErrors: true,
|
|
399
|
-
});
|
|
400
|
-
return {
|
|
401
|
-
type: 'chat-message',
|
|
402
|
-
value: delegated.message,
|
|
403
|
-
delegatedToolCall: delegated.record,
|
|
404
|
-
};
|
|
405
|
-
},
|
|
406
|
-
runPipeline: runtime.runPipeline,
|
|
407
|
-
})
|
|
408
|
-
: await runtime.runPipeline(runtime.runOptions);
|
|
409
|
-
if (runtime.profileAttempts != null) {
|
|
410
|
-
result.commonOutputs['llmProfileAttempts'] = {
|
|
411
|
-
type: 'object[]',
|
|
412
|
-
value: runtime.profileAttempts,
|
|
413
|
-
};
|
|
414
|
-
result.commonOutputs['llmProfileSummary'] = {
|
|
415
|
-
type: 'string',
|
|
416
|
-
value: runtime.getProfileSummary(),
|
|
417
|
-
};
|
|
418
|
-
if (runtime.profileChainUsesArray && runtime.profileChainLength != null) {
|
|
419
|
-
const diagnostics = buildLLMProfileRequestDiagnostics(runtime.profileChainLength, runtime.profileAttempts);
|
|
420
|
-
// Rivet has scalar and one-dimensional array Data Values, but no
|
|
421
|
-
// nested-array Data Type. Keep profile/retry grouping as portable JSON
|
|
422
|
-
// inside Any values. One request or error stays scalar when doing so
|
|
423
|
-
// preserves useful diagnostic information.
|
|
424
|
-
if (this.data.outputRequestStatus) {
|
|
425
|
-
result.commonOutputs['requestStatus'] = {
|
|
426
|
-
type: 'any',
|
|
427
|
-
value: diagnostics.statuses,
|
|
428
|
-
};
|
|
429
|
-
}
|
|
430
|
-
if (shouldOutputChatV2RequestError(this.data)) {
|
|
431
|
-
result.commonOutputs['requestError'] = {
|
|
432
|
-
type: 'any',
|
|
433
|
-
value: diagnostics.errors,
|
|
434
|
-
};
|
|
303
|
+
let result;
|
|
304
|
+
try {
|
|
305
|
+
result = await executeLLMInvocation({
|
|
306
|
+
context,
|
|
307
|
+
journal: invocationJournal,
|
|
308
|
+
runtime,
|
|
309
|
+
toolCallContinuation,
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
catch (error) {
|
|
313
|
+
try {
|
|
314
|
+
const diagnostics = projectLLMInvocationDiagnostics({
|
|
315
|
+
runOptions: runtime.runOptions,
|
|
316
|
+
outputLLMAttempts: this.data.outputLLMAttempts,
|
|
317
|
+
llmAttempts: invocationJournal.llmAttempts,
|
|
318
|
+
profileSummary: runtime.getProfileSummary?.(),
|
|
319
|
+
});
|
|
320
|
+
if (Object.keys(diagnostics).length > 0) {
|
|
321
|
+
context.onPartialOutputs?.(diagnostics);
|
|
435
322
|
}
|
|
436
323
|
}
|
|
324
|
+
catch {
|
|
325
|
+
// Developer diagnostics are observational and must never replace the
|
|
326
|
+
// provider/configuration error which caused this node to fail.
|
|
327
|
+
}
|
|
328
|
+
throw error;
|
|
437
329
|
}
|
|
438
|
-
|
|
330
|
+
projectLLMInvocationResult({
|
|
331
|
+
result,
|
|
332
|
+
modelCalls: invocationJournal.modelCalls,
|
|
333
|
+
outputUsage: this.data.outputUsage,
|
|
334
|
+
outputLLMAttempts: this.data.outputLLMAttempts,
|
|
335
|
+
llmAttempts: invocationJournal.llmAttempts,
|
|
336
|
+
profileSummary: runtime.getProfileSummary?.(),
|
|
337
|
+
});
|
|
338
|
+
if (toolCallContinuation && !isChatV2PipelineProviderFailureResult(result) && result.functionCalls.length > 0) {
|
|
439
339
|
toolCallContinuation.release();
|
|
440
340
|
}
|
|
441
|
-
|
|
442
|
-
const cacheOutputs = cloneLLMChatV2EditorCacheOutputs(result.commonOutputs);
|
|
443
|
-
// Attempt history is specific to this execution. Rebuild it as an empty
|
|
444
|
-
// observability value on a later cache hit instead of presenting stale
|
|
445
|
-
// provider calls as if they happened again.
|
|
446
|
-
delete cacheOutputs['llmProfileAttempts'];
|
|
447
|
-
delete cacheOutputs['llmProfileSummary'];
|
|
448
|
-
runtime.editorCache.set(runtime.cacheKey, cacheOutputs);
|
|
449
|
-
}
|
|
341
|
+
writeLLMChatV2EditorCache({ runtime, result });
|
|
450
342
|
return result.commonOutputs;
|
|
451
343
|
}
|
|
452
344
|
}
|
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
import { nanoid } from 'nanoid/non-secure';
|
|
2
|
-
import { dedent } from 'ts-dedent';
|
|
3
2
|
import { nodeDefinition } from '../NodeDefinition.js';
|
|
4
3
|
import { NodeImpl } from '../NodeImpl.js';
|
|
5
4
|
import { getLLMProfileEditors } from '../chat-v2/llmChatV2NodeEditors.js';
|
|
5
|
+
import { getLLMProfileBodySections } from '../chat-v2/llmProfileBody.js';
|
|
6
6
|
import { resolveLLMProfileNodeValue } from '../chat-v2/llmProfileNodeRuntime.js';
|
|
7
7
|
import { createLLMProfileNodeData } from '../chat-v2/llmProfileTypes.js';
|
|
8
|
-
|
|
8
|
+
function escapeMarkdownInline(value) {
|
|
9
|
+
return String(value)
|
|
10
|
+
.replace(/\r/g, '\\r')
|
|
11
|
+
.replace(/\n/g, '\\n')
|
|
12
|
+
.replace(/&/g, '&')
|
|
13
|
+
.replace(/</g, '<')
|
|
14
|
+
.replace(/>/g, '>')
|
|
15
|
+
.replace(/"/g, '"')
|
|
16
|
+
.replace(/([\\`*_[\]{}()#+\-.!|])/g, '\\$1');
|
|
17
|
+
}
|
|
18
|
+
function getBodyLine(label, value) {
|
|
19
|
+
return `<span style="opacity: 0.55">${label}:</span> ${escapeMarkdownInline(value)}`;
|
|
20
|
+
}
|
|
9
21
|
export class LLMProfileNodeImpl extends NodeImpl {
|
|
10
22
|
static create() {
|
|
11
23
|
return {
|
|
@@ -101,12 +113,19 @@ export class LLMProfileNodeImpl extends NodeImpl {
|
|
|
101
113
|
return await getLLMProfileEditors(this.data, context);
|
|
102
114
|
}
|
|
103
115
|
getBody() {
|
|
104
|
-
return
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
116
|
+
return {
|
|
117
|
+
type: 'markdown',
|
|
118
|
+
disableLinks: true,
|
|
119
|
+
text: getLLMProfileBodySections(this.data)
|
|
120
|
+
.map((section) => {
|
|
121
|
+
const fields = section.fields.map((field) => getBodyLine(field.label, field.value));
|
|
122
|
+
const snippet = section.snippet
|
|
123
|
+
? `${getBodyLine(section.snippet.label, '')}\n${escapeMarkdownInline(section.snippet.text)}`
|
|
124
|
+
: undefined;
|
|
125
|
+
return [...fields, ...(snippet ? [snippet] : [])].join('\n');
|
|
126
|
+
})
|
|
127
|
+
.join('\n\n'),
|
|
128
|
+
};
|
|
110
129
|
}
|
|
111
130
|
static getUIData() {
|
|
112
131
|
return {
|