@valerypopoff/rivet2-core 2.1.9 → 2.1.10
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 +3596 -1745
- package/dist/cjs/bundle.cjs.map +4 -4
- package/dist/cjs/webAppRuntime.cjs +298 -21
- package/dist/cjs/webAppRuntime.cjs.map +4 -4
- package/dist/esm/exports.js +1 -0
- package/dist/esm/model/AgentResponseTrace.js +448 -0
- package/dist/esm/model/ConnectedToolContinuationHost.js +33 -0
- package/dist/esm/model/GraphProcessor.js +151 -74
- package/dist/esm/model/NodeImpl.js +6 -0
- package/dist/esm/model/ProcessContextBuilder.js +3 -1
- package/dist/esm/model/RecordingPlayer.js +164 -22
- package/dist/esm/model/SplitRunProcessor.js +49 -8
- package/dist/esm/model/SubprocessorBridge.js +2 -0
- package/dist/esm/model/ToolCallContinuationCoordinator.js +7 -3
- package/dist/esm/model/UiGraph.js +21 -0
- package/dist/esm/model/UiGraphActionProtocol.js +2 -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/chatV2CallObserver.js +9 -5
- package/dist/esm/model/chat-v2/chatV2EditorCache.js +42 -16
- 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 +61 -146
- package/dist/esm/model/chat-v2/chatV2ProviderProfile.js +8 -2
- 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 +55 -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 +6 -1
- package/dist/esm/model/chat-v2/chatV2Types.js +5 -9
- package/dist/esm/model/chat-v2/chatV2UsageAccounting.js +78 -0
- package/dist/esm/model/chat-v2/customProviderApi.js +42 -0
- package/dist/esm/model/chat-v2/index.js +12 -0
- package/dist/esm/model/chat-v2/llmChatV2Body.js +281 -0
- package/dist/esm/model/chat-v2/llmChatV2CacheBoundary.js +32 -0
- package/dist/esm/model/chat-v2/llmChatV2CachePolicy.js +20 -0
- package/dist/esm/model/chat-v2/llmChatV2NodeData.js +6 -50
- package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +25 -13
- package/dist/esm/model/chat-v2/llmChatV2NodeMigration.js +24 -0
- package/dist/esm/model/chat-v2/llmChatV2NodeRuntime.js +121 -193
- 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 +75 -0
- package/dist/esm/model/chat-v2/llmProfile.js +10 -65
- package/dist/esm/model/chat-v2/llmProfileBody.js +183 -0
- package/dist/esm/model/chat-v2/llmProfileFallback.js +55 -99
- package/dist/esm/model/chat-v2/llmProfileFieldRegistry.js +67 -0
- package/dist/esm/model/chat-v2/llmProfileNodeRuntime.js +3 -0
- 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 +86 -20
- 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/DelegateFunctionCallNode.js +19 -6
- package/dist/esm/model/nodes/LLMChatV2Node.js +112 -229
- package/dist/esm/model/nodes/LLMProfileNode.js +27 -8
- 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/google/google.js +5 -9
- package/dist/esm/plugins/google/nodes/ChatGoogleNode.js +4 -1
- package/dist/esm/recording/ExecutionRecorder.js +13 -5
- 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/exports.d.ts +1 -0
- package/dist/types/model/AgentResponseTrace.d.ts +110 -0
- package/dist/types/model/ConnectedToolContinuationHost.d.ts +34 -0
- package/dist/types/model/ExecutorProtocol.d.ts +25 -7
- package/dist/types/model/GraphProcessor.d.ts +27 -5
- 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 +47 -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 +2 -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/chatV2EditorCache.d.ts +1 -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 +4 -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 +19 -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/chatV2Types.d.ts +20 -10
- package/dist/types/model/chat-v2/chatV2UsageAccounting.d.ts +14 -0
- package/dist/types/model/chat-v2/customProviderApi.d.ts +23 -0
- package/dist/types/model/chat-v2/index.d.ts +12 -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 +10 -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 +18 -0
- package/dist/types/model/chat-v2/llmProfileBody.d.ts +20 -0
- package/dist/types/model/chat-v2/llmProfileFallback.d.ts +17 -49
- package/dist/types/model/chat-v2/llmProfileFieldRegistry.d.ts +189 -0
- package/dist/types/model/chat-v2/llmProfileTypes.d.ts +1 -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 +10 -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/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/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/google/google.d.ts +2 -8
- 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
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Invocation-scoped, append-only facts collected from physical provider calls.
|
|
3
|
+
* It stores physical-call accounting alongside the full developer-visible LLM
|
|
4
|
+
* attempt diagnostics selected by the node.
|
|
5
|
+
*/
|
|
6
|
+
export class LLMInvocationJournal {
|
|
7
|
+
#modelCalls = [];
|
|
8
|
+
#events = [];
|
|
9
|
+
#llmAttempts = [];
|
|
10
|
+
recordModelCall(event) {
|
|
11
|
+
// The host observer is allowed to inspect the same event after this local
|
|
12
|
+
// observer returns. Preserve an immutable-at-recording-time snapshot so a
|
|
13
|
+
// later observer cannot rewrite this invocation's accounting facts.
|
|
14
|
+
const snapshot = {
|
|
15
|
+
...event,
|
|
16
|
+
...(event.rawUsage == null ? {} : { rawUsage: { ...event.rawUsage } }),
|
|
17
|
+
...(event.normalizedUsage == null ? {} : { normalizedUsage: { ...event.normalizedUsage } }),
|
|
18
|
+
pricing: { ...event.pricing },
|
|
19
|
+
};
|
|
20
|
+
this.#modelCalls.push(snapshot);
|
|
21
|
+
this.#events.push({ type: 'model-call', event: snapshot });
|
|
22
|
+
}
|
|
23
|
+
recordToolRound(event) {
|
|
24
|
+
this.#events.push({ type: 'tool-round', ...event });
|
|
25
|
+
}
|
|
26
|
+
recordLLMAttempt(attempt) {
|
|
27
|
+
const snapshot = { ...attempt };
|
|
28
|
+
this.#llmAttempts.push(snapshot);
|
|
29
|
+
this.#events.push({ type: 'llm-attempt', attempt: snapshot });
|
|
30
|
+
}
|
|
31
|
+
recordTerminal(event) {
|
|
32
|
+
this.#events.push({ type: 'terminal', ...event });
|
|
33
|
+
}
|
|
34
|
+
get modelCalls() {
|
|
35
|
+
return this.#modelCalls;
|
|
36
|
+
}
|
|
37
|
+
get events() {
|
|
38
|
+
return this.#events;
|
|
39
|
+
}
|
|
40
|
+
get llmAttempts() {
|
|
41
|
+
return this.#llmAttempts;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { coerceTypeOptional } from '../../utils/coerceType.js';
|
|
2
|
+
import { getInputOrData } from '../../utils/inputs.js';
|
|
3
|
+
import { coercePromptToChatMessages, prependSystemPrompt } from '../chat/chatMessages.js';
|
|
4
|
+
import { getInstructionMessageRoles } from './developerMessageRoles.js';
|
|
5
|
+
import { createChatV2ResponseOutput, resolveChatV2ResponseFormatParameters, } from './chatV2ResponseFormat.js';
|
|
6
|
+
import { resolveLLMChatV2ToolChoice } from './chatV2RuntimeOptions.js';
|
|
7
|
+
import { shouldIncludeLLMChatV2ToolCalls } from './llmChatV2NodeData.js';
|
|
8
|
+
import { shouldOutputChatV2RequestBody, shouldOutputChatV2ResponseBody, } from './chatV2Types.js';
|
|
9
|
+
import { createChatV2ResponseBodyCapture } from './chatV2ResponseBodyCapture.js';
|
|
10
|
+
export function resolveLLMChatV2BaseURL(data, inputs) {
|
|
11
|
+
return data.provider === 'custom'
|
|
12
|
+
? getInputOrData(data, inputs, 'customProviderBaseURL', 'string', 'useCustomProviderBaseURLInput')?.trim() ||
|
|
13
|
+
undefined
|
|
14
|
+
: undefined;
|
|
15
|
+
}
|
|
16
|
+
export function buildLLMInvocationPlan(params) {
|
|
17
|
+
const { data, inputs, context } = params;
|
|
18
|
+
const prompt = inputs['prompt'];
|
|
19
|
+
const systemPrompt = inputs['systemPrompt'];
|
|
20
|
+
const responseBodyCapture = shouldOutputChatV2ResponseBody(data) ? createChatV2ResponseBodyCapture() : undefined;
|
|
21
|
+
return {
|
|
22
|
+
data,
|
|
23
|
+
inputs,
|
|
24
|
+
context,
|
|
25
|
+
prompt,
|
|
26
|
+
systemPrompt,
|
|
27
|
+
functions: data.useToolCalling && inputs['functions'] != null
|
|
28
|
+
? coerceTypeOptional(inputs['functions'], 'gpt-function[]')
|
|
29
|
+
: undefined,
|
|
30
|
+
responseFormatParameters: resolveChatV2ResponseFormatParameters(data, inputs),
|
|
31
|
+
toolChoice: resolveLLMChatV2ToolChoice(data),
|
|
32
|
+
requestBodies: shouldOutputChatV2RequestBody(data) ? [] : undefined,
|
|
33
|
+
responseBodies: responseBodyCapture?.bodies,
|
|
34
|
+
responseBodyCapture,
|
|
35
|
+
instructionRoles: getInstructionMessageRoles(prependSystemPrompt(coercePromptToChatMessages(prompt), systemPrompt)),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Build the provider-neutral portion of an executable round. A model is never
|
|
40
|
+
* fabricated here; candidate resolution supplies it before this reaches the
|
|
41
|
+
* request pipeline.
|
|
42
|
+
*/
|
|
43
|
+
export function buildLLMInvocationRunOptions(params) {
|
|
44
|
+
const { plan, provider, modelId } = params;
|
|
45
|
+
return {
|
|
46
|
+
provider,
|
|
47
|
+
modelId,
|
|
48
|
+
prompt: plan.prompt,
|
|
49
|
+
systemPrompt: plan.systemPrompt,
|
|
50
|
+
functions: plan.functions,
|
|
51
|
+
responseOutput: createChatV2ResponseOutput(plan.responseFormatParameters, provider, plan.data.customProviderApi),
|
|
52
|
+
responseFormat: plan.responseFormatParameters?.responseFormat,
|
|
53
|
+
outputUsage: plan.data.outputUsage,
|
|
54
|
+
outputReasoning: plan.data.outputReasoning,
|
|
55
|
+
outputRequestBody: shouldOutputChatV2RequestBody(plan.data),
|
|
56
|
+
outputResponseBody: shouldOutputChatV2ResponseBody(plan.data),
|
|
57
|
+
includeFunctionCalls: shouldIncludeLLMChatV2ToolCalls(plan.data),
|
|
58
|
+
emitPartialOutputs: plan.data.useAsGraphPartialOutput,
|
|
59
|
+
toolChoice: plan.toolChoice,
|
|
60
|
+
requestBodies: plan.requestBodies,
|
|
61
|
+
responseBodies: plan.responseBodies,
|
|
62
|
+
responseBodyCapture: plan.responseBodyCapture,
|
|
63
|
+
retryOnNon200: plan.data.retryOnNon200,
|
|
64
|
+
retryOnNon200RepeatTimes: plan.data.retryOnNon200RepeatTimes,
|
|
65
|
+
retryOnNon200CooldownMs: plan.data.retryOnNon200CooldownMs,
|
|
66
|
+
context: plan.context,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { projectLLMInvocationUsage } from './llmInvocationProjections.js';
|
|
2
|
+
import { createChatV2CapturedBodyOutputs } from './chatV2Outputs.js';
|
|
3
|
+
/**
|
|
4
|
+
* Projects invocation facts that remain useful even when the node fails.
|
|
5
|
+
* Captured HTTP bodies are emitted only through their opt-in ports, while
|
|
6
|
+
* attempts and profile summaries retain the same public shapes as a success.
|
|
7
|
+
*/
|
|
8
|
+
export function projectLLMInvocationDiagnostics({ runOptions, outputLLMAttempts, llmAttempts, profileSummary, }) {
|
|
9
|
+
const capturedBodies = createChatV2CapturedBodyOutputs(runOptions);
|
|
10
|
+
return {
|
|
11
|
+
...Object.fromEntries(Object.entries(capturedBodies).filter(([, output]) => output?.type !== 'control-flow-excluded')),
|
|
12
|
+
...projectLLMInvocationMetadata({ outputLLMAttempts, llmAttempts, profileSummary }),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function projectLLMInvocationMetadata(params) {
|
|
16
|
+
const { outputLLMAttempts, llmAttempts, profileSummary } = params;
|
|
17
|
+
const outputs = {};
|
|
18
|
+
if (outputLLMAttempts) {
|
|
19
|
+
outputs['llmAttempts'] = {
|
|
20
|
+
type: 'object[]',
|
|
21
|
+
value: [...llmAttempts],
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if (profileSummary != null) {
|
|
25
|
+
outputs['llmProfileSummary'] = {
|
|
26
|
+
type: 'string',
|
|
27
|
+
value: profileSummary,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return outputs;
|
|
31
|
+
}
|
|
32
|
+
/** Applies existing public LLM Chat output shapes from invocation facts. */
|
|
33
|
+
export function projectLLMInvocationResult(params) {
|
|
34
|
+
const { result, modelCalls, outputUsage, outputLLMAttempts, llmAttempts, profileSummary } = params;
|
|
35
|
+
if (outputUsage && modelCalls.length > 0) {
|
|
36
|
+
const physicalUsage = projectLLMInvocationUsage(modelCalls);
|
|
37
|
+
if (physicalUsage != null) {
|
|
38
|
+
result.usage = physicalUsage;
|
|
39
|
+
result.commonOutputs['usage'] = { type: 'object', value: physicalUsage };
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
Object.assign(result.commonOutputs, projectLLMInvocationMetadata({
|
|
43
|
+
outputLLMAttempts,
|
|
44
|
+
llmAttempts,
|
|
45
|
+
profileSummary,
|
|
46
|
+
}));
|
|
47
|
+
return result.commonOutputs;
|
|
48
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { getInputOrData } from '../../utils/inputs.js';
|
|
2
|
+
import { hasLLMChatV2ToolResponseFormatConflict, LLM_CHAT_V2_TOOL_RESPONSE_FORMAT_CONFLICT_COPY, } from './chatV2FeatureCompatibility.js';
|
|
3
|
+
import { buildLLMInvocationRunOptions, resolveLLMChatV2BaseURL } from './llmInvocationPlan.js';
|
|
4
|
+
import { applyLLMProfileToNodeData } from './llmProfile.js';
|
|
5
|
+
import { createResolvedChatV2Provider, resolveChatV2Credential, } from './chatV2ProviderProfile.js';
|
|
6
|
+
import { resolveLLMChatV2BuiltInTools, resolveLLMChatV2GenerationParameters, resolveLLMChatV2Headers, resolveLLMChatV2RuntimeProviderOptions, } from './chatV2RuntimeOptions.js';
|
|
7
|
+
import { createChatV2ResponseOutput, mergeCustomProviderResponseFormatOptions } from './chatV2ResponseFormat.js';
|
|
8
|
+
import { parseCustomProviderApi } from './customProviderApi.js';
|
|
9
|
+
import { parseChatV2Provider } from './providerOptions.js';
|
|
10
|
+
import { restoreOpenAICompatibleInstructionRoles } from './developerMessageRoles.js';
|
|
11
|
+
export async function resolveLLMModelCandidate(params) {
|
|
12
|
+
const { plan, profile } = params;
|
|
13
|
+
const effectiveData = profile ? applyLLMProfileToNodeData(plan.data, profile) : plan.data;
|
|
14
|
+
if (hasLLMChatV2ToolResponseFormatConflict(effectiveData)) {
|
|
15
|
+
throw new Error(LLM_CHAT_V2_TOOL_RESPONSE_FORMAT_CONFLICT_COPY.paragraphs[0]);
|
|
16
|
+
}
|
|
17
|
+
const provider = parseChatV2Provider(effectiveData.provider);
|
|
18
|
+
const customProviderApi = provider === 'custom' ? parseCustomProviderApi(effectiveData.customProviderApi) : undefined;
|
|
19
|
+
const modelId = getInputOrData(effectiveData, plan.inputs, 'model', 'string');
|
|
20
|
+
const baseURL = resolveLLMChatV2BaseURL(effectiveData, plan.inputs);
|
|
21
|
+
const headers = resolveLLMChatV2Headers(effectiveData, plan.inputs);
|
|
22
|
+
const credential = profile?.credential ??
|
|
23
|
+
resolveChatV2Credential({
|
|
24
|
+
provider,
|
|
25
|
+
context: plan.context,
|
|
26
|
+
apiKeySource: effectiveData.apiKeySource === 'input' ? 'input' : 'configured',
|
|
27
|
+
inputs: plan.inputs,
|
|
28
|
+
customProgrammaticName: effectiveData.customProviderApiKeyProgrammaticName,
|
|
29
|
+
customEnvironmentName: effectiveData.customProviderApiKeyEnvVarName,
|
|
30
|
+
});
|
|
31
|
+
const transformRequestBody = (provider === 'openai' || provider === 'custom') && plan.instructionRoles.includes('developer')
|
|
32
|
+
? (body) => restoreOpenAICompatibleInstructionRoles(body, plan.instructionRoles)
|
|
33
|
+
: undefined;
|
|
34
|
+
const resolvedProvider = await createResolvedChatV2Provider({
|
|
35
|
+
provider,
|
|
36
|
+
modelId,
|
|
37
|
+
context: plan.context,
|
|
38
|
+
baseURL,
|
|
39
|
+
headers,
|
|
40
|
+
credential,
|
|
41
|
+
onRequestBody: plan.requestBodies == null ? undefined : (body) => plan.requestBodies.push(body),
|
|
42
|
+
onResponseBody: plan.responseBodyCapture == null ? undefined : (response) => plan.responseBodyCapture.capture(response),
|
|
43
|
+
transformRequestBody,
|
|
44
|
+
customProviderApi,
|
|
45
|
+
});
|
|
46
|
+
const generationParameters = resolveLLMChatV2GenerationParameters(effectiveData, plan.inputs);
|
|
47
|
+
const providerOptions = mergeCustomProviderResponseFormatOptions(provider, resolveLLMChatV2RuntimeProviderOptions(effectiveData, plan.inputs), plan.responseFormatParameters, customProviderApi);
|
|
48
|
+
const baseRunOptions = params.roundOptions ??
|
|
49
|
+
buildLLMInvocationRunOptions({
|
|
50
|
+
plan,
|
|
51
|
+
provider,
|
|
52
|
+
modelId,
|
|
53
|
+
});
|
|
54
|
+
return {
|
|
55
|
+
effectiveData,
|
|
56
|
+
credential,
|
|
57
|
+
providerConfig: resolvedProvider.config,
|
|
58
|
+
runOptions: {
|
|
59
|
+
...baseRunOptions,
|
|
60
|
+
provider,
|
|
61
|
+
model: resolvedProvider.model,
|
|
62
|
+
modelId,
|
|
63
|
+
...(customProviderApi == null ? {} : { customProviderApi }),
|
|
64
|
+
additionalTools: resolveLLMChatV2BuiltInTools(effectiveData, plan.context, resolvedProvider.config, credential.value),
|
|
65
|
+
...generationParameters,
|
|
66
|
+
responseOutput: createChatV2ResponseOutput(plan.responseFormatParameters, provider, customProviderApi),
|
|
67
|
+
responseFormat: plan.responseFormatParameters?.responseFormat,
|
|
68
|
+
providerOptions,
|
|
69
|
+
anthropicCacheControlTtl: provider === 'anthropic' ? effectiveData.anthropicCacheControlTtl || undefined : undefined,
|
|
70
|
+
requestBodies: plan.requestBodies,
|
|
71
|
+
responseBodies: plan.responseBodies,
|
|
72
|
+
responseBodyCapture: plan.responseBodyCapture,
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { createLLMChatV2NodeData
|
|
1
|
+
import { createLLMChatV2NodeData } from './llmChatV2NodeData.js';
|
|
2
|
+
import { parseCustomProviderApi } from './customProviderApi.js';
|
|
3
|
+
import { llmProfileBooleanDataKeys, llmProfileOptionalNumberDataKeys, llmProfileRequiredNumberDataKeys, llmProfileResolvedInputToggleDataKeys, llmProfileStringDataKeys, } from './llmProfileFieldRegistry.js';
|
|
2
4
|
import { LLM_PROFILE_VALUE_VERSION, pickLLMChatV2ProfileData } from './llmProfileTypes.js';
|
|
3
5
|
export { applyLLMProfileToNodeData, createDefaultLLMProfileValue, createLLMProfileNodeData, LLM_PROFILE_VALUE_VERSION, pickLLMChatV2ProfileData, } from './llmProfileTypes.js';
|
|
4
6
|
const credentialSources = new Set([
|
|
@@ -10,65 +12,6 @@ const credentialSources = new Set([
|
|
|
10
12
|
'none',
|
|
11
13
|
]);
|
|
12
14
|
const profileProviders = new Set(['openai', 'anthropic', 'google', 'custom']);
|
|
13
|
-
const stringFields = [
|
|
14
|
-
'model',
|
|
15
|
-
'customProviderApiKeyProgrammaticName',
|
|
16
|
-
'customProviderApiKeyEnvVarName',
|
|
17
|
-
'customProviderBaseURL',
|
|
18
|
-
'extraProviderOptions',
|
|
19
|
-
'openAIReasoningEffort',
|
|
20
|
-
'openAIReasoningSummary',
|
|
21
|
-
'openAIPreviousResponseId',
|
|
22
|
-
];
|
|
23
|
-
const booleanFields = [
|
|
24
|
-
'useModelInput',
|
|
25
|
-
'useTemperatureInput',
|
|
26
|
-
'useTopPInput',
|
|
27
|
-
'useTopKInput',
|
|
28
|
-
'usePresencePenaltyInput',
|
|
29
|
-
'useFrequencyPenaltyInput',
|
|
30
|
-
'useStopSequencesInput',
|
|
31
|
-
'useSeedInput',
|
|
32
|
-
'useMaxTokensInput',
|
|
33
|
-
'useCustomProviderBaseURLInput',
|
|
34
|
-
'useHeadersInput',
|
|
35
|
-
'useExtraProviderOptionsInput',
|
|
36
|
-
'useOpenAIPreviousResponseIdInput',
|
|
37
|
-
'enableOpenAIWebSearch',
|
|
38
|
-
'enableOpenAICodeInterpreter',
|
|
39
|
-
'useAnthropicThinkingBudgetInput',
|
|
40
|
-
'useGoogleThinkingBudgetInput',
|
|
41
|
-
'googleIncludeThoughts',
|
|
42
|
-
'enableGoogleSearchGrounding',
|
|
43
|
-
'enableGoogleUrlContext',
|
|
44
|
-
];
|
|
45
|
-
const requiredNumberFields = ['temperature', 'maxTokens'];
|
|
46
|
-
const optionalNumberFields = [
|
|
47
|
-
'topP',
|
|
48
|
-
'topK',
|
|
49
|
-
'presencePenalty',
|
|
50
|
-
'frequencyPenalty',
|
|
51
|
-
'seed',
|
|
52
|
-
'anthropicThinkingBudget',
|
|
53
|
-
'googleThinkingBudget',
|
|
54
|
-
];
|
|
55
|
-
const resolvedInputToggleFields = [
|
|
56
|
-
'useModelInput',
|
|
57
|
-
'useTemperatureInput',
|
|
58
|
-
'useTopPInput',
|
|
59
|
-
'useTopKInput',
|
|
60
|
-
'usePresencePenaltyInput',
|
|
61
|
-
'useFrequencyPenaltyInput',
|
|
62
|
-
'useStopSequencesInput',
|
|
63
|
-
'useSeedInput',
|
|
64
|
-
'useMaxTokensInput',
|
|
65
|
-
'useCustomProviderBaseURLInput',
|
|
66
|
-
'useHeadersInput',
|
|
67
|
-
'useExtraProviderOptionsInput',
|
|
68
|
-
'useOpenAIPreviousResponseIdInput',
|
|
69
|
-
'useAnthropicThinkingBudgetInput',
|
|
70
|
-
'useGoogleThinkingBudgetInput',
|
|
71
|
-
];
|
|
72
15
|
export function normalizeLLMProfileValue(value) {
|
|
73
16
|
if (!isRecord(value)) {
|
|
74
17
|
throw new Error('LLM Profile input must contain an LLM profile value.');
|
|
@@ -120,22 +63,22 @@ export function normalizeLLMProfileChainInput(value) {
|
|
|
120
63
|
});
|
|
121
64
|
}
|
|
122
65
|
function normalizeConfiguration(data) {
|
|
123
|
-
for (const field of
|
|
66
|
+
for (const field of llmProfileStringDataKeys) {
|
|
124
67
|
if (typeof data[field] !== 'string') {
|
|
125
68
|
throw new Error(`LLM Profile ${field} must be a string.`);
|
|
126
69
|
}
|
|
127
70
|
}
|
|
128
|
-
for (const field of
|
|
71
|
+
for (const field of llmProfileBooleanDataKeys) {
|
|
129
72
|
if (typeof data[field] !== 'boolean') {
|
|
130
73
|
throw new Error(`LLM Profile ${field} must be a boolean.`);
|
|
131
74
|
}
|
|
132
75
|
}
|
|
133
|
-
for (const field of
|
|
76
|
+
for (const field of llmProfileRequiredNumberDataKeys) {
|
|
134
77
|
if (typeof data[field] !== 'number' || !Number.isFinite(data[field])) {
|
|
135
78
|
throw new Error(`LLM Profile ${field} must be a finite number.`);
|
|
136
79
|
}
|
|
137
80
|
}
|
|
138
|
-
for (const field of
|
|
81
|
+
for (const field of llmProfileOptionalNumberDataKeys) {
|
|
139
82
|
const fieldValue = data[field];
|
|
140
83
|
if (fieldValue != null && (typeof fieldValue !== 'number' || !Number.isFinite(fieldValue))) {
|
|
141
84
|
throw new Error(`LLM Profile ${field} must be a finite number when provided.`);
|
|
@@ -152,12 +95,14 @@ function normalizeConfiguration(data) {
|
|
|
152
95
|
throw new Error(`Unsupported LLM Profile API key source: ${String(data.apiKeySource)}.`);
|
|
153
96
|
}
|
|
154
97
|
assertEnumValue(data.openAIWebSearchContextSize, ['low', 'medium', 'high'], 'OpenAI web search context');
|
|
98
|
+
const customProviderApi = parseCustomProviderApi(data.customProviderApi);
|
|
155
99
|
assertEnumValue(data.anthropicThinkingMode, ['', 'adaptive', 'enabled', 'disabled'], 'Anthropic thinking mode');
|
|
156
100
|
assertEnumValue(data.anthropicEffort, ['', 'low', 'medium', 'high', 'max'], 'Anthropic effort');
|
|
157
101
|
assertEnumValue(data.anthropicCacheControlTtl, ['', '5m', '1h'], 'Anthropic cache TTL');
|
|
158
102
|
assertEnumValue(data.googleThinkingLevel, ['', 'minimal', 'low', 'medium', 'high'], 'Google thinking level');
|
|
159
103
|
const resolvedData = {
|
|
160
104
|
...data,
|
|
105
|
+
customProviderApi,
|
|
161
106
|
model: data.model.trim(),
|
|
162
107
|
customProviderBaseURL: data.customProviderBaseURL.trim(),
|
|
163
108
|
customProviderApiKeyProgrammaticName: data.customProviderApiKeyProgrammaticName?.trim(),
|
|
@@ -168,7 +113,7 @@ function normalizeConfiguration(data) {
|
|
|
168
113
|
// A profile is a resolved configuration value. LLM Chat intentionally does not
|
|
169
114
|
// expose the profile-owned inputs, so accepting a dynamic flag here would let
|
|
170
115
|
// stale hidden connections influence a supposedly self-contained profile.
|
|
171
|
-
for (const field of
|
|
116
|
+
for (const field of llmProfileResolvedInputToggleDataKeys) {
|
|
172
117
|
resolvedData[field] = false;
|
|
173
118
|
}
|
|
174
119
|
return pickLLMChatV2ProfileData(resolvedData);
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { getChatV2ModelInfo } from './modelRegistry.js';
|
|
2
|
+
import { anthropicCacheControlTtlOptions, anthropicEffortOptions, anthropicThinkingModeOptions, getChatV2ProviderLabel, getCustomProviderApiContract, googleThinkingLevelOptions, openAIReasoningEffortOptions, openAIWebSearchContextSizeOptions, } from './providerOptions.js';
|
|
3
|
+
function getOptionLabel(options, value) {
|
|
4
|
+
const optionValue = typeof value === 'string' ? value : '';
|
|
5
|
+
return options.find((option) => option.value === optionValue)?.label ?? (optionValue || 'Default');
|
|
6
|
+
}
|
|
7
|
+
function getOptionalNumberBodyField(label, value, usesInput) {
|
|
8
|
+
if (usesInput) {
|
|
9
|
+
return { label, value: '(Using Input)' };
|
|
10
|
+
}
|
|
11
|
+
return value === undefined ? undefined : { label, value: `${value}` };
|
|
12
|
+
}
|
|
13
|
+
function getOptionalStringBodyField(label, value, usesInput) {
|
|
14
|
+
if (usesInput) {
|
|
15
|
+
return { label, value: '(Using Input)' };
|
|
16
|
+
}
|
|
17
|
+
return typeof value === 'string' && value.trim().length > 0 ? { label, value } : undefined;
|
|
18
|
+
}
|
|
19
|
+
function getCustomProviderBodyLabel(api) {
|
|
20
|
+
try {
|
|
21
|
+
return getCustomProviderApiContract(api).label;
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
// Corrupt hand-authored project data must not prevent canvas rendering.
|
|
25
|
+
// Runtime profile validation still rejects it before a request.
|
|
26
|
+
return `Custom (${String(api)})`;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function getModelBodyLabel(data) {
|
|
30
|
+
if (data.useModelInput) {
|
|
31
|
+
return '(Using Input)';
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
return getChatV2ModelInfo(data.provider, data.model)?.displayName ?? String(data.model);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return String(data.model);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function getProviderBodyFields(data) {
|
|
41
|
+
switch (data.provider) {
|
|
42
|
+
case 'openai':
|
|
43
|
+
return [
|
|
44
|
+
getOptionalStringBodyField('Previous response ID', data.openAIPreviousResponseId, data.useOpenAIPreviousResponseIdInput),
|
|
45
|
+
...(data.openAIReasoningEffort
|
|
46
|
+
? [
|
|
47
|
+
{
|
|
48
|
+
label: 'Reasoning effort',
|
|
49
|
+
value: getOptionLabel(openAIReasoningEffortOptions, data.openAIReasoningEffort),
|
|
50
|
+
},
|
|
51
|
+
]
|
|
52
|
+
: []),
|
|
53
|
+
...(data.openAIReasoningSummary ? [{ label: 'Reasoning summary', value: data.openAIReasoningSummary }] : []),
|
|
54
|
+
...(data.enableOpenAIWebSearch
|
|
55
|
+
? [
|
|
56
|
+
{
|
|
57
|
+
label: 'Web search',
|
|
58
|
+
value: `Enabled (${getOptionLabel(openAIWebSearchContextSizeOptions, data.openAIWebSearchContextSize)})`,
|
|
59
|
+
},
|
|
60
|
+
]
|
|
61
|
+
: []),
|
|
62
|
+
...(data.enableOpenAICodeInterpreter ? [{ label: 'Code interpreter', value: 'Enabled' }] : []),
|
|
63
|
+
].filter((field) => field !== undefined);
|
|
64
|
+
case 'anthropic':
|
|
65
|
+
return [
|
|
66
|
+
...(data.anthropicThinkingMode
|
|
67
|
+
? [
|
|
68
|
+
{
|
|
69
|
+
label: 'Thinking mode',
|
|
70
|
+
value: getOptionLabel(anthropicThinkingModeOptions, data.anthropicThinkingMode),
|
|
71
|
+
},
|
|
72
|
+
]
|
|
73
|
+
: []),
|
|
74
|
+
...(data.anthropicEffort
|
|
75
|
+
? [{ label: 'Effort', value: getOptionLabel(anthropicEffortOptions, data.anthropicEffort) }]
|
|
76
|
+
: []),
|
|
77
|
+
getOptionalNumberBodyField('Thinking budget', data.anthropicThinkingBudget, data.useAnthropicThinkingBudgetInput),
|
|
78
|
+
...(data.anthropicCacheControlTtl
|
|
79
|
+
? [
|
|
80
|
+
{
|
|
81
|
+
label: 'Cache breakpoint TTL',
|
|
82
|
+
value: getOptionLabel(anthropicCacheControlTtlOptions, data.anthropicCacheControlTtl),
|
|
83
|
+
},
|
|
84
|
+
]
|
|
85
|
+
: []),
|
|
86
|
+
].filter((field) => field !== undefined);
|
|
87
|
+
case 'google':
|
|
88
|
+
return [
|
|
89
|
+
...(data.googleThinkingLevel
|
|
90
|
+
? [{ label: 'Thinking level', value: getOptionLabel(googleThinkingLevelOptions, data.googleThinkingLevel) }]
|
|
91
|
+
: []),
|
|
92
|
+
getOptionalNumberBodyField('Thinking budget', data.googleThinkingBudget, data.useGoogleThinkingBudgetInput),
|
|
93
|
+
...(data.googleIncludeThoughts ? [{ label: 'Include thoughts', value: 'Enabled' }] : []),
|
|
94
|
+
...(data.enableGoogleSearchGrounding ? [{ label: 'Google search grounding', value: 'Enabled' }] : []),
|
|
95
|
+
...(data.enableGoogleUrlContext ? [{ label: 'URL context', value: 'Enabled' }] : []),
|
|
96
|
+
].filter((field) => field !== undefined);
|
|
97
|
+
case 'custom':
|
|
98
|
+
default:
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function getHeadersBodyField(data) {
|
|
103
|
+
if (data.useHeadersInput) {
|
|
104
|
+
return { label: 'Headers', value: '(Using Input)' };
|
|
105
|
+
}
|
|
106
|
+
const headers = Array.isArray(data.headers)
|
|
107
|
+
? data.headers.filter((header) => typeof header?.key === 'string' && header.key.trim().length > 0 && typeof header.value === 'string')
|
|
108
|
+
: [];
|
|
109
|
+
return headers.length > 0
|
|
110
|
+
? { label: 'Headers', value: headers.map(({ key, value }) => `${key}: ${value}`).join(', ') }
|
|
111
|
+
: undefined;
|
|
112
|
+
}
|
|
113
|
+
function getStopSequencesBodyField(data) {
|
|
114
|
+
if (data.useStopSequencesInput) {
|
|
115
|
+
return { label: 'Stop sequences', value: '(Using Input)' };
|
|
116
|
+
}
|
|
117
|
+
const stopSequences = Array.isArray(data.stopSequences)
|
|
118
|
+
? data.stopSequences.filter((sequence) => typeof sequence === 'string' && sequence.length > 0)
|
|
119
|
+
: [];
|
|
120
|
+
return stopSequences.length > 0
|
|
121
|
+
? { label: 'Stop sequences', value: stopSequences.map((sequence) => JSON.stringify(sequence)).join(', ') }
|
|
122
|
+
: undefined;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Stable canvas presentation data for LLM Profile configuration. It deliberately
|
|
126
|
+
* contains stored configuration only: runtime API-key values are never present
|
|
127
|
+
* in the node data and therefore cannot be rendered here.
|
|
128
|
+
*/
|
|
129
|
+
export function getLLMProfileBodySections(data) {
|
|
130
|
+
const modelFields = [
|
|
131
|
+
{
|
|
132
|
+
label: 'Provider',
|
|
133
|
+
value: data.provider === 'custom'
|
|
134
|
+
? getCustomProviderBodyLabel(data.customProviderApi)
|
|
135
|
+
: getChatV2ProviderLabel(data.provider),
|
|
136
|
+
},
|
|
137
|
+
...(data.provider === 'custom'
|
|
138
|
+
? [getOptionalStringBodyField('Base URL', data.customProviderBaseURL, data.useCustomProviderBaseURLInput)]
|
|
139
|
+
: []),
|
|
140
|
+
{ label: 'Model', value: getModelBodyLabel(data) },
|
|
141
|
+
{ label: 'API key source', value: data.apiKeySource === 'input' ? 'Input port' : 'Configured key' },
|
|
142
|
+
...(data.provider === 'custom' && data.apiKeySource !== 'input'
|
|
143
|
+
? [
|
|
144
|
+
data.customProviderApiKeyProgrammaticName?.trim()
|
|
145
|
+
? { label: 'Alternative programmatic key', value: data.customProviderApiKeyProgrammaticName }
|
|
146
|
+
: undefined,
|
|
147
|
+
data.customProviderApiKeyEnvVarName?.trim()
|
|
148
|
+
? { label: 'Alternative API key env var', value: data.customProviderApiKeyEnvVarName }
|
|
149
|
+
: undefined,
|
|
150
|
+
]
|
|
151
|
+
: []),
|
|
152
|
+
];
|
|
153
|
+
const parameterFields = [
|
|
154
|
+
{ label: 'Temperature', value: data.useTemperatureInput ? '(Using Input)' : `${data.temperature}` },
|
|
155
|
+
{ label: 'Max output tokens', value: data.useMaxTokensInput ? '(Using Input)' : `${data.maxTokens}` },
|
|
156
|
+
getOptionalNumberBodyField('Top P', data.topP, data.useTopPInput),
|
|
157
|
+
getOptionalNumberBodyField('Top K', data.topK, data.useTopKInput),
|
|
158
|
+
getOptionalNumberBodyField('Presence penalty', data.presencePenalty, data.usePresencePenaltyInput),
|
|
159
|
+
getOptionalNumberBodyField('Frequency penalty', data.frequencyPenalty, data.useFrequencyPenaltyInput),
|
|
160
|
+
getStopSequencesBodyField(data),
|
|
161
|
+
getOptionalNumberBodyField('Seed', data.seed, data.useSeedInput),
|
|
162
|
+
];
|
|
163
|
+
const advancedFields = [
|
|
164
|
+
getHeadersBodyField(data),
|
|
165
|
+
...(data.useExtraProviderOptionsInput ? [{ label: 'Extra provider options', value: '(Using Input)' }] : []),
|
|
166
|
+
];
|
|
167
|
+
const extraProviderOptions = !data.useExtraProviderOptionsInput &&
|
|
168
|
+
typeof data.extraProviderOptions === 'string' &&
|
|
169
|
+
data.extraProviderOptions.trim().length > 0
|
|
170
|
+
? { label: 'Extra provider options', text: data.extraProviderOptions }
|
|
171
|
+
: undefined;
|
|
172
|
+
const sections = [
|
|
173
|
+
{ id: 'model', fields: modelFields.filter((field) => field !== undefined) },
|
|
174
|
+
{ id: 'parameters', fields: parameterFields.filter((field) => field !== undefined) },
|
|
175
|
+
{ id: 'provider', fields: getProviderBodyFields(data) },
|
|
176
|
+
{
|
|
177
|
+
id: 'advanced',
|
|
178
|
+
fields: advancedFields.filter((field) => field !== undefined),
|
|
179
|
+
snippet: extraProviderOptions,
|
|
180
|
+
},
|
|
181
|
+
];
|
|
182
|
+
return sections.filter((section) => section.fields.length > 0 || section.snippet !== undefined);
|
|
183
|
+
}
|