@valerypopoff/rivet2-core 2.1.8 → 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 +4457 -1809
- 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 +152 -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 +68 -18
- package/dist/esm/model/SubprocessorBridge.js +2 -0
- package/dist/esm/model/ToolCallContinuationCoordinator.js +13 -4
- 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/aiSdkMessages.js +8 -0
- package/dist/esm/model/chat/aiSdkTools.js +3 -2
- package/dist/esm/model/chat-v2/chatV2CallObserver.js +11 -5
- package/dist/esm/model/chat-v2/chatV2EditorCache.js +58 -10
- 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 +56 -106
- package/dist/esm/model/chat-v2/chatV2Pipeline.js +142 -149
- package/dist/esm/model/chat-v2/chatV2ProviderProfile.js +9 -2
- package/dist/esm/model/chat-v2/chatV2ProviderRegistry.js +9 -0
- package/dist/esm/model/chat-v2/chatV2RequestPlan.js +5 -5
- 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/chatV2Shared.js +1 -6
- package/dist/esm/model/chat-v2/chatV2Types.js +7 -1
- 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/developerMessageRoles.js +45 -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 +8 -54
- package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +41 -20
- package/dist/esm/model/chat-v2/llmChatV2NodeMigration.js +24 -0
- package/dist/esm/model/chat-v2/llmChatV2NodeRuntime.js +178 -94
- 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 +31 -65
- package/dist/esm/model/chat-v2/llmProfileBody.js +183 -0
- package/dist/esm/model/chat-v2/llmProfileFallback.js +244 -0
- 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/messageConverter.js +14 -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 +120 -21
- 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 -39
- 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/AssembleMessageNode.js +6 -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 +26 -1
- package/dist/esm/model/nodes/LLMChatV2Node.js +131 -144
- package/dist/esm/model/nodes/LLMProfileNode.js +27 -8
- package/dist/esm/model/nodes/PromptNode.js +16 -2
- package/dist/esm/model/nodes/ToolNode.js +7 -0
- package/dist/esm/model/nodes/toolCallDelegation.js +193 -110
- package/dist/esm/plugins/anthropic/anthropic.js +4 -4
- package/dist/esm/plugins/anthropic/nodes/ChatAnthropicNode.js +29 -28
- package/dist/esm/plugins/google/google.js +25 -18
- package/dist/esm/plugins/google/nodes/ChatGoogleNode.js +21 -7
- package/dist/esm/recording/ExecutionRecorder.js +13 -5
- package/dist/esm/utils/chatMessageToOpenAIChatCompletionMessage.js +4 -0
- package/dist/esm/utils/emitDetached.js +6 -3
- package/dist/esm/utils/openai.js +60 -16
- package/dist/esm/utils/serialization/serialization.js +2 -0
- 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/DataValue.d.ts +7 -1
- package/dist/types/model/ExecutorProtocol.d.ts +25 -7
- package/dist/types/model/GraphProcessor.d.ts +27 -5
- package/dist/types/model/NodeBase.d.ts +6 -0
- 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 +51 -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 +11 -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 +3 -1
- package/dist/types/model/chat-v2/chatV2Outputs.d.ts +7 -17
- package/dist/types/model/chat-v2/chatV2Pipeline.d.ts +29 -0
- package/dist/types/model/chat-v2/chatV2ProviderProfile.d.ts +5 -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/chatV2Shared.d.ts +0 -1
- package/dist/types/model/chat-v2/chatV2Types.d.ts +35 -1
- 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/developerMessageRoles.d.ts +10 -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 +13 -3
- package/dist/types/model/chat-v2/llmChatV2NodeMigration.d.ts +8 -0
- package/dist/types/model/chat-v2/llmChatV2NodeRuntime.d.ts +18 -4
- 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/llmProfile.d.ts +7 -0
- package/dist/types/model/chat-v2/llmProfileBody.d.ts +20 -0
- package/dist/types/model/chat-v2/llmProfileFallback.d.ts +47 -0
- 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 +11 -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/AssembleMessageNode.d.ts +2 -1
- 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 +6 -3
- 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 +14 -9
- package/dist/types/plugins/google/nodes/ChatGoogleNode.d.ts +2 -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
|
@@ -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.');
|
|
@@ -98,23 +41,44 @@ export function normalizeLLMProfileValue(value) {
|
|
|
98
41
|
credential,
|
|
99
42
|
};
|
|
100
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Normalizes the single LLM Profile or ordered fallback chain accepted by
|
|
46
|
+
* LLM Chat's From profile input. We validate every member here rather than
|
|
47
|
+
* trusting a same-type `llm-config[]` wrapper: arrays can otherwise carry
|
|
48
|
+
* malformed values without re-entering scalar coercion.
|
|
49
|
+
*/
|
|
50
|
+
export function normalizeLLMProfileChainInput(value) {
|
|
51
|
+
const rawProfiles = Array.isArray(value) ? value : [value];
|
|
52
|
+
if (rawProfiles.length === 0) {
|
|
53
|
+
throw new Error('LLM Profiles input must contain at least one LLM Profile.');
|
|
54
|
+
}
|
|
55
|
+
return rawProfiles.map((profile, index) => {
|
|
56
|
+
try {
|
|
57
|
+
return normalizeLLMProfileValue(profile);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
61
|
+
throw new Error(`LLM Profiles input item ${index} is invalid: ${message}`);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
101
65
|
function normalizeConfiguration(data) {
|
|
102
|
-
for (const field of
|
|
66
|
+
for (const field of llmProfileStringDataKeys) {
|
|
103
67
|
if (typeof data[field] !== 'string') {
|
|
104
68
|
throw new Error(`LLM Profile ${field} must be a string.`);
|
|
105
69
|
}
|
|
106
70
|
}
|
|
107
|
-
for (const field of
|
|
71
|
+
for (const field of llmProfileBooleanDataKeys) {
|
|
108
72
|
if (typeof data[field] !== 'boolean') {
|
|
109
73
|
throw new Error(`LLM Profile ${field} must be a boolean.`);
|
|
110
74
|
}
|
|
111
75
|
}
|
|
112
|
-
for (const field of
|
|
76
|
+
for (const field of llmProfileRequiredNumberDataKeys) {
|
|
113
77
|
if (typeof data[field] !== 'number' || !Number.isFinite(data[field])) {
|
|
114
78
|
throw new Error(`LLM Profile ${field} must be a finite number.`);
|
|
115
79
|
}
|
|
116
80
|
}
|
|
117
|
-
for (const field of
|
|
81
|
+
for (const field of llmProfileOptionalNumberDataKeys) {
|
|
118
82
|
const fieldValue = data[field];
|
|
119
83
|
if (fieldValue != null && (typeof fieldValue !== 'number' || !Number.isFinite(fieldValue))) {
|
|
120
84
|
throw new Error(`LLM Profile ${field} must be a finite number when provided.`);
|
|
@@ -131,12 +95,14 @@ function normalizeConfiguration(data) {
|
|
|
131
95
|
throw new Error(`Unsupported LLM Profile API key source: ${String(data.apiKeySource)}.`);
|
|
132
96
|
}
|
|
133
97
|
assertEnumValue(data.openAIWebSearchContextSize, ['low', 'medium', 'high'], 'OpenAI web search context');
|
|
98
|
+
const customProviderApi = parseCustomProviderApi(data.customProviderApi);
|
|
134
99
|
assertEnumValue(data.anthropicThinkingMode, ['', 'adaptive', 'enabled', 'disabled'], 'Anthropic thinking mode');
|
|
135
100
|
assertEnumValue(data.anthropicEffort, ['', 'low', 'medium', 'high', 'max'], 'Anthropic effort');
|
|
136
101
|
assertEnumValue(data.anthropicCacheControlTtl, ['', '5m', '1h'], 'Anthropic cache TTL');
|
|
137
102
|
assertEnumValue(data.googleThinkingLevel, ['', 'minimal', 'low', 'medium', 'high'], 'Google thinking level');
|
|
138
103
|
const resolvedData = {
|
|
139
104
|
...data,
|
|
105
|
+
customProviderApi,
|
|
140
106
|
model: data.model.trim(),
|
|
141
107
|
customProviderBaseURL: data.customProviderBaseURL.trim(),
|
|
142
108
|
customProviderApiKeyProgrammaticName: data.customProviderApiKeyProgrammaticName?.trim(),
|
|
@@ -147,7 +113,7 @@ function normalizeConfiguration(data) {
|
|
|
147
113
|
// A profile is a resolved configuration value. LLM Chat intentionally does not
|
|
148
114
|
// expose the profile-owned inputs, so accepting a dynamic flag here would let
|
|
149
115
|
// stale hidden connections influence a supposedly self-contained profile.
|
|
150
|
-
for (const field of
|
|
116
|
+
for (const field of llmProfileResolvedInputToggleDataKeys) {
|
|
151
117
|
resolvedData[field] = false;
|
|
152
118
|
}
|
|
153
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
|
+
}
|