@valerypopoff/rivet2-core 2.1.6 → 2.1.8

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.
Files changed (79) hide show
  1. package/dist/cjs/bundle.cjs +3436 -1831
  2. package/dist/cjs/bundle.cjs.map +4 -4
  3. package/dist/esm/api/createProcessor.js +45 -4
  4. package/dist/esm/exports.js +2 -0
  5. package/dist/esm/integrations/KnowledgeStoreFieldPolicy.js +216 -0
  6. package/dist/esm/integrations/KnowledgeStoreProvider.js +14 -90
  7. package/dist/esm/integrations/ManagedKnowledgeStore.js +0 -8
  8. package/dist/esm/model/DataBusPorts.js +26 -0
  9. package/dist/esm/model/DataBusTopology.js +207 -0
  10. package/dist/esm/model/DataValue.js +22 -7
  11. package/dist/esm/model/GraphPreprocessor.js +9 -3
  12. package/dist/esm/model/GraphProcessor.js +163 -366
  13. package/dist/esm/model/NodeIO.js +1 -0
  14. package/dist/esm/model/NodePrefabResolver.js +16 -0
  15. package/dist/esm/model/Nodes.js +7 -0
  16. package/dist/esm/model/ToolCallContinuationBranchPlanner.js +165 -0
  17. package/dist/esm/model/ToolCallContinuationCoordinator.js +201 -0
  18. package/dist/esm/model/chat-v2/chatV2CallObserver.js +140 -0
  19. package/dist/esm/model/chat-v2/chatV2Errors.js +23 -6
  20. package/dist/esm/model/chat-v2/chatV2Pipeline.js +47 -14
  21. package/dist/esm/model/chat-v2/chatV2ProviderTypes.js +1 -0
  22. package/dist/esm/model/chat-v2/chatV2RuntimeOptions.js +2 -2
  23. package/dist/esm/model/chat-v2/index.js +1 -0
  24. package/dist/esm/model/chat-v2/llmChatV2NodeData.js +52 -0
  25. package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +38 -13
  26. package/dist/esm/model/chat-v2/llmChatV2NodeRuntime.js +42 -34
  27. package/dist/esm/model/chat-v2/llmProfile.js +191 -0
  28. package/dist/esm/model/chat-v2/llmProfileNodeRuntime.js +73 -0
  29. package/dist/esm/model/chat-v2/llmProfileTypes.js +45 -0
  30. package/dist/esm/model/nodes/DataBusNode.js +81 -0
  31. package/dist/esm/model/nodes/GetGlobalNode.js +7 -11
  32. package/dist/esm/model/nodes/GetKnowledgeSourceStatusNode.js +1 -1
  33. package/dist/esm/model/nodes/LLMChatV2Node.js +44 -10
  34. package/dist/esm/model/nodes/LLMProfileNode.js +132 -0
  35. package/dist/esm/model/nodes/PassthroughNode.js +26 -8
  36. package/dist/esm/model/nodes/SearchKnowledgeNode.js +1 -1
  37. package/dist/esm/model/nodes/SetGlobalNode.js +6 -6
  38. package/dist/esm/model/nodes/SyncKnowledgeSourceNode.js +0 -1
  39. package/dist/esm/model/nodes/toolCallDelegation.js +13 -2
  40. package/dist/esm/plugins/pinecone/PineconeKnowledgeStore.js +0 -4
  41. package/dist/esm/plugins/pinecone/plugin.js +1 -1
  42. package/dist/esm/utils/coerceType.js +84 -41
  43. package/dist/esm/utils/expectType.js +45 -8
  44. package/dist/esm/utils/fetchEventSource.js +18 -0
  45. package/dist/esm/utils/serialization/serialization.js +18 -7
  46. package/dist/esm/vendor/fnv1a.js +6 -3
  47. package/dist/types/api/createProcessor.d.ts +2 -0
  48. package/dist/types/exports.d.ts +2 -0
  49. package/dist/types/integrations/KnowledgeStore.d.ts +0 -2
  50. package/dist/types/integrations/KnowledgeStoreFieldPolicy.d.ts +38 -0
  51. package/dist/types/integrations/KnowledgeStoreProvider.d.ts +6 -3
  52. package/dist/types/model/DataBusPorts.d.ts +6 -0
  53. package/dist/types/model/DataBusTopology.d.ts +16 -0
  54. package/dist/types/model/DataValue.d.ts +15 -5
  55. package/dist/types/model/GraphPreprocessor.d.ts +2 -1
  56. package/dist/types/model/GraphProcessor.d.ts +4 -3
  57. package/dist/types/model/NodeIO.d.ts +5 -0
  58. package/dist/types/model/NodePrefabResolver.d.ts +9 -0
  59. package/dist/types/model/Nodes.d.ts +5 -2
  60. package/dist/types/model/ProcessContext.d.ts +60 -0
  61. package/dist/types/model/ToolCallContinuationBranchPlanner.d.ts +43 -0
  62. package/dist/types/model/ToolCallContinuationCoordinator.d.ts +70 -0
  63. package/dist/types/model/chat-v2/chatV2CallObserver.d.ts +10 -0
  64. package/dist/types/model/chat-v2/chatV2ProviderTypes.d.ts +1 -0
  65. package/dist/types/model/chat-v2/chatV2RuntimeOptions.d.ts +8 -0
  66. package/dist/types/model/chat-v2/chatV2Types.d.ts +3 -3
  67. package/dist/types/model/chat-v2/index.d.ts +1 -0
  68. package/dist/types/model/chat-v2/llmChatV2NodeData.d.ts +6 -0
  69. package/dist/types/model/chat-v2/llmChatV2NodeEditors.d.ts +5 -1
  70. package/dist/types/model/chat-v2/llmProfile.d.ts +3 -0
  71. package/dist/types/model/chat-v2/llmProfileNodeRuntime.d.ts +9 -0
  72. package/dist/types/model/chat-v2/llmProfileTypes.d.ts +18 -0
  73. package/dist/types/model/nodes/DataBusNode.d.ts +19 -0
  74. package/dist/types/model/nodes/LLMProfileNode.d.ts +20 -0
  75. package/dist/types/model/nodes/PassthroughNode.d.ts +3 -2
  76. package/dist/types/model/nodes/SetGlobalNode.d.ts +2 -2
  77. package/dist/types/model/nodes/toolCallDelegation.d.ts +9 -0
  78. package/dist/types/vendor/fnv1a.d.ts +5 -5
  79. package/package.json +1 -1
@@ -1,10 +1,11 @@
1
1
  import { coercePromptToChatMessages, prependSystemPrompt } from '../chat/chatMessages.js';
2
2
  import { generateChatV2, streamChatV2 } from './aiSdkBridge.js';
3
+ import { createObservedChatV2CallId, notifyChatV2CallFinished } from './chatV2CallObserver.js';
3
4
  import { chatMessagesToModelMessages } from './messageConverter.js';
4
5
  import { chatV2ToolsToAiSdk } from './toolConverter.js';
5
6
  import { buildChatV2RequestPlan } from './chatV2RequestPlan.js';
6
7
  import { getChatV2ProviderErrorStatusCode, isChatV2ProviderApiCallError, isChatV2ProviderFetchError, normalizeChatV2ProviderError, } from './chatV2Errors.js';
7
- import { waitForLLMChatV2RetryCooldown, } from './chatV2Retry.js';
8
+ import { waitForLLMChatV2RetryCooldown } from './chatV2Retry.js';
8
9
  import { createChatV2CommonOutputs, createChatV2ProviderFailureOutputs, normalizeChatV2Usage, } from './chatV2Outputs.js';
9
10
  class ChatV2RetryFailure extends Error {
10
11
  error;
@@ -22,10 +23,20 @@ function isChatV2RetryFailure(error) {
22
23
  return error instanceof ChatV2RetryFailure;
23
24
  }
24
25
  function getProviderFailureMessage(error) {
25
- if (error instanceof Error) {
26
- return error.message;
26
+ try {
27
+ if (error instanceof Error && typeof error.message === 'string') {
28
+ return error.message;
29
+ }
30
+ }
31
+ catch {
32
+ return 'Provider request failed with unreadable error metadata.';
33
+ }
34
+ try {
35
+ return String(error);
36
+ }
37
+ catch {
38
+ return 'Provider request failed with unreadable error metadata.';
27
39
  }
28
- return String(error);
29
40
  }
30
41
  function buildNon200StatusError(statusCode) {
31
42
  const error = new Error(`Provider request returned non-200 status: ${statusCode}`);
@@ -34,21 +45,38 @@ function buildNon200StatusError(statusCode) {
34
45
  return error;
35
46
  }
36
47
  function normalizeProviderFailureMessage(error, options) {
37
- return getProviderFailureMessage(normalizeChatV2ProviderError(error, {
38
- provider: options.provider,
39
- modelId: options.modelId,
40
- }));
48
+ return getProviderFailureMessage(normalizeProviderFailure(error, options));
49
+ }
50
+ function normalizeProviderFailure(error, options) {
51
+ try {
52
+ return normalizeChatV2ProviderError(error, {
53
+ provider: options.provider,
54
+ modelId: options.modelId,
55
+ });
56
+ }
57
+ catch {
58
+ return error;
59
+ }
41
60
  }
42
61
  function normalizeProviderFailureMessages(errors, options) {
43
62
  return errors.map((error) => normalizeProviderFailureMessage(error, options));
44
63
  }
45
- async function runChatV2WithRetry(chatOptions, retryPlan, signal, transportMode) {
64
+ async function runChatV2WithRetry(options, chatOptions, retryPlan, signal, transportMode) {
46
65
  const requestStatuses = [];
47
66
  const requestErrors = [];
48
67
  for (let attempt = 0;; attempt++) {
68
+ const callId = createObservedChatV2CallId(options);
69
+ let callWasObserved = false;
49
70
  try {
50
71
  const result = transportMode === 'generate' ? await generateChatV2(chatOptions) : await streamChatV2(chatOptions);
51
72
  const statusCode = result.requestStatus ?? 200;
73
+ notifyChatV2CallFinished(options, {
74
+ callId,
75
+ attemptIndex: attempt,
76
+ outcome: statusCode === 200 ? 'success' : 'provider-failure',
77
+ result,
78
+ });
79
+ callWasObserved = true;
52
80
  if (retryPlan.enabled) {
53
81
  requestStatuses.push(statusCode);
54
82
  }
@@ -63,6 +91,14 @@ async function runChatV2WithRetry(chatOptions, retryPlan, signal, transportMode)
63
91
  await waitForLLMChatV2RetryCooldown(retryPlan.cooldownMs, signal);
64
92
  }
65
93
  catch (error) {
94
+ if (!callWasObserved) {
95
+ notifyChatV2CallFinished(options, {
96
+ callId,
97
+ attemptIndex: attempt,
98
+ outcome: signal.aborted ? 'aborted' : 'provider-failure',
99
+ error,
100
+ });
101
+ }
66
102
  const statusCode = getChatV2ProviderErrorStatusCode(error);
67
103
  if (!retryPlan.enabled || statusCode == null || statusCode === 200) {
68
104
  throw error;
@@ -141,7 +177,7 @@ export async function runChatV2Pipeline(options) {
141
177
  tools,
142
178
  });
143
179
  const shouldStreamResponse = plan.transportMode === 'stream';
144
- const chatResponse = await runChatV2WithRetry({
180
+ const chatResponse = await runChatV2WithRetry(options, {
145
181
  ...plan.request,
146
182
  abortSignal: options.context.signal,
147
183
  executeStream: options.executeStream,
@@ -173,10 +209,7 @@ export async function runChatV2Pipeline(options) {
173
209
  }, plan.retry, options.context.signal, plan.transportMode).catch((caughtError) => {
174
210
  const retryFailure = isChatV2RetryFailure(caughtError) ? caughtError : undefined;
175
211
  const rawError = retryFailure?.error ?? caughtError;
176
- const normalizedError = normalizeChatV2ProviderError(rawError, {
177
- provider: options.provider,
178
- modelId: options.modelId,
179
- });
212
+ const normalizedError = normalizeProviderFailure(rawError, options);
180
213
  const requestStatuses = retryFailure?.requestStatuses ?? [];
181
214
  const requestErrors = normalizeProviderFailureMessages(retryFailure?.requestErrors ?? [], options);
182
215
  const failureResult = buildProviderFailureResult(requestMessages, options, plan, normalizedError, rawError, requestStatuses, requestErrors);
@@ -0,0 +1 @@
1
+ export {};
@@ -48,7 +48,7 @@ function normalizeExtraProviderOptions(value) {
48
48
  }
49
49
  return value;
50
50
  }
51
- function resolveExtraProviderOptions(data, inputs) {
51
+ export function resolveLLMChatV2ExtraProviderOptions(data, inputs) {
52
52
  if (!data.useExtraProviderOptionsInput) {
53
53
  return parseExtraProviderOptionsText(data.extraProviderOptions ?? '');
54
54
  }
@@ -56,7 +56,7 @@ function resolveExtraProviderOptions(data, inputs) {
56
56
  }
57
57
  function resolveProviderOptions(data, inputs) {
58
58
  const providerOptions = {};
59
- const extraProviderOptions = resolveExtraProviderOptions(data, inputs);
59
+ const extraProviderOptions = resolveLLMChatV2ExtraProviderOptions(data, inputs);
60
60
  if (extraProviderOptions) {
61
61
  providerOptions[data.provider] = extraProviderOptions;
62
62
  }
@@ -6,6 +6,7 @@ export * from './chatV2RequestPlan.js';
6
6
  export * from './chatV2ResponseFormat.js';
7
7
  export * from './chatV2Shared.js';
8
8
  export * from './chatV2Types.js';
9
+ export * from './llmProfileTypes.js';
9
10
  export * from './messageConverter.js';
10
11
  export * from './modelRegistry.js';
11
12
  export * from './providerOptions.js';
@@ -1,10 +1,59 @@
1
1
  import { createChatV2CommonNodeData } from './chatV2Shared.js';
2
2
  import { DEFAULT_LLM_CHAT_V2_RETRY_ON_NON_200_COOLDOWN_MS, DEFAULT_LLM_CHAT_V2_RETRY_ON_NON_200_REPEAT_TIMES, } from './chatV2Retry.js';
3
+ export const llmChatV2ProfileDataKeys = [
4
+ 'model',
5
+ 'useModelInput',
6
+ 'temperature',
7
+ 'useTemperatureInput',
8
+ 'topP',
9
+ 'useTopPInput',
10
+ 'topK',
11
+ 'useTopKInput',
12
+ 'presencePenalty',
13
+ 'usePresencePenaltyInput',
14
+ 'frequencyPenalty',
15
+ 'useFrequencyPenaltyInput',
16
+ 'stopSequences',
17
+ 'useStopSequencesInput',
18
+ 'seed',
19
+ 'useSeedInput',
20
+ 'maxTokens',
21
+ 'useMaxTokensInput',
22
+ 'provider',
23
+ 'apiKeySource',
24
+ 'customProviderApiKeyProgrammaticName',
25
+ 'customProviderApiKeyEnvVarName',
26
+ 'customProviderBaseURL',
27
+ 'useCustomProviderBaseURLInput',
28
+ 'headers',
29
+ 'useHeadersInput',
30
+ 'extraProviderOptions',
31
+ 'useExtraProviderOptionsInput',
32
+ 'openAIReasoningEffort',
33
+ 'openAIReasoningSummary',
34
+ 'openAIPreviousResponseId',
35
+ 'useOpenAIPreviousResponseIdInput',
36
+ 'enableOpenAIWebSearch',
37
+ 'openAIWebSearchContextSize',
38
+ 'enableOpenAICodeInterpreter',
39
+ 'anthropicThinkingMode',
40
+ 'anthropicThinkingBudget',
41
+ 'useAnthropicThinkingBudgetInput',
42
+ 'anthropicEffort',
43
+ 'anthropicCacheControlTtl',
44
+ 'googleThinkingBudget',
45
+ 'useGoogleThinkingBudgetInput',
46
+ 'googleThinkingLevel',
47
+ 'googleIncludeThoughts',
48
+ 'enableGoogleSearchGrounding',
49
+ 'enableGoogleUrlContext',
50
+ ];
3
51
  export function createLLMChatV2NodeData() {
4
52
  return {
5
53
  ...createChatV2CommonNodeData({
6
54
  model: 'gpt-5',
7
55
  }),
56
+ configurationMode: 'inline',
8
57
  provider: 'openai',
9
58
  apiKeySource: 'environment',
10
59
  customProviderApiKeyProgrammaticName: '',
@@ -55,3 +104,6 @@ export function hasLLMChatV2BuiltInToolsEnabled(data) {
55
104
  return ((data.provider === 'openai' && (data.enableOpenAIWebSearch || data.enableOpenAICodeInterpreter)) ||
56
105
  (data.provider === 'google' && (data.enableGoogleSearchGrounding || data.enableGoogleUrlContext)));
57
106
  }
107
+ export function shouldIncludeLLMChatV2ToolCalls(data) {
108
+ return data.configurationMode === 'profile' || data.useToolCalling || hasLLMChatV2BuiltInToolsEnabled(data);
109
+ }
@@ -103,7 +103,11 @@ function getModelEditors(modelOptions) {
103
103
  ], true);
104
104
  }
105
105
  function getProviderEditors() {
106
- return [getOpenAIProviderEditors(), getAnthropicProviderEditors(), getGoogleProviderEditors()];
106
+ return [
107
+ getOpenAIProviderEditors(),
108
+ getAnthropicProviderEditors(),
109
+ getGoogleProviderEditors(),
110
+ ];
107
111
  }
108
112
  function getOpenAIProviderEditors() {
109
113
  return providerGroup('openai', 'OpenAI', [
@@ -246,12 +250,6 @@ function getReasoningEditors() {
246
250
  helperMessage: 'OpenAI-compatible Vercel provider option for reasoning models. Some models only support a subset of effort levels.',
247
251
  hideIf: hideUnlessProvider('openai'),
248
252
  },
249
- {
250
- type: 'toggle',
251
- label: 'Output reasoning',
252
- dataKey: 'outputReasoning',
253
- helperMessage: 'Adds a Reasoning output when the provider/model exposes reasoning or thinking text through the Vercel AI SDK. Some providers only expose token counts or summaries.',
254
- },
255
253
  {
256
254
  type: 'string',
257
255
  label: 'Reasoning summary',
@@ -382,7 +380,8 @@ function getToolEditors() {
382
380
  label: 'Allow parallel toolcalls',
383
381
  dataKey: 'parallelToolCalls',
384
382
  helperMessage: LLM_CHAT_V2_PARALLEL_TOOL_CALLS_HELPER_MESSAGE,
385
- hideIf: (data) => !data.useToolCalling || !supportsLLMChatV2ParallelToolCalls(data.provider),
383
+ hideIf: (data) => !data.useToolCalling ||
384
+ (data.configurationMode !== 'profile' && !supportsLLMChatV2ParallelToolCalls(data.provider)),
386
385
  },
387
386
  {
388
387
  type: 'toggle',
@@ -403,6 +402,12 @@ function getToolEditors() {
403
402
  }
404
403
  function getOutputEditors() {
405
404
  return group('Outputs', [
405
+ {
406
+ type: 'toggle',
407
+ label: 'Output reasoning',
408
+ dataKey: 'outputReasoning',
409
+ helperMessage: 'Adds a Reasoning output when the provider/model exposes reasoning or thinking text through the Vercel AI SDK. Some providers only expose token counts or summaries.',
410
+ },
406
411
  {
407
412
  type: 'toggle',
408
413
  label: 'Output usage details',
@@ -483,15 +488,35 @@ function getTechnicalDetailsEditors() {
483
488
  ]);
484
489
  }
485
490
  export async function getLLMChatV2Editors(data, context) {
491
+ const usesProfile = data.configurationMode === 'profile';
486
492
  return [
487
- getModelEditors(await getResolvedModelOptions(data, context)),
488
- ...getProviderEditors(),
489
- getParameterEditors(),
490
- getReasoningEditors(),
493
+ {
494
+ type: 'custom',
495
+ label: 'Configuration',
496
+ customEditorId: 'LLMChatV2Configuration',
497
+ },
498
+ ...(!usesProfile
499
+ ? [
500
+ getModelEditors(await getResolvedModelOptions(data, context)),
501
+ ...getProviderEditors(),
502
+ getParameterEditors(),
503
+ ...(data.provider === 'custom' ? [] : [getReasoningEditors()]),
504
+ ]
505
+ : []),
491
506
  getResponseFormatEditors(),
492
507
  getToolEditors(),
493
508
  getOutputEditors(),
494
- getProviderAdvancedEditors(),
509
+ ...(!usesProfile ? [getProviderAdvancedEditors()] : []),
495
510
  getTechnicalDetailsEditors(),
496
511
  ];
497
512
  }
513
+ export async function getLLMProfileEditors(data, context) {
514
+ const profileData = data;
515
+ return [
516
+ getModelEditors(await getResolvedModelOptions(profileData, context)),
517
+ ...getProviderEditors(),
518
+ getParameterEditors(),
519
+ ...(profileData.provider === 'custom' ? [] : [getReasoningEditors()]),
520
+ getProviderAdvancedEditors(),
521
+ ];
522
+ }
@@ -4,9 +4,10 @@ import { createChatV2ResponseOutput, mergeCustomProviderResponseFormatOptions, r
4
4
  import { hasLLMChatV2ToolResponseFormatConflict, LLM_CHAT_V2_TOOL_RESPONSE_FORMAT_CONFLICT_COPY, } from './chatV2FeatureCompatibility.js';
5
5
  import { parseChatV2Provider } from './providerOptions.js';
6
6
  import { createResolvedChatV2Provider, resolveChatV2Credential } from './chatV2ProviderProfile.js';
7
+ import { applyLLMProfileToNodeData, normalizeLLMProfileValue } from './llmProfile.js';
7
8
  import { buildLLMChatV2EditorCacheKey, cloneLLMChatV2EditorCacheOutputs, resolveLLMChatV2EditorCache, } from './chatV2EditorCache.js';
8
9
  import { resolveLLMChatV2BuiltInTools, resolveLLMChatV2GenerationParameters, resolveLLMChatV2Headers, resolveLLMChatV2RuntimeProviderOptions, resolveLLMChatV2ToolChoice, } from './chatV2RuntimeOptions.js';
9
- import { hasLLMChatV2BuiltInToolsEnabled, } from './llmChatV2NodeData.js';
10
+ import { shouldIncludeLLMChatV2ToolCalls, } from './llmChatV2NodeData.js';
10
11
  export { buildLLMChatV2EditorCacheKey, cloneLLMChatV2EditorCacheOutputs };
11
12
  export { resolveLLMChatV2RuntimeProviderOptions } from './chatV2RuntimeOptions.js';
12
13
  function resolveLLMChatV2BaseURL(data, inputs) {
@@ -17,23 +18,30 @@ function resolveLLMChatV2BaseURL(data, inputs) {
17
18
  }
18
19
  export async function resolveLLMChatV2RuntimeConfig(params) {
19
20
  const { data, nodeId, inputs, context } = params;
20
- if (hasLLMChatV2ToolResponseFormatConflict(data)) {
21
+ const profileInput = inputs['llmProfile'];
22
+ if (data.configurationMode === 'profile' && profileInput == null) {
23
+ throw new Error('LLM Profile input is required when Configuration is From profile.');
24
+ }
25
+ const profile = data.configurationMode === 'profile' ? normalizeLLMProfileValue(profileInput?.value) : undefined;
26
+ const effectiveData = profile ? applyLLMProfileToNodeData(data, profile) : data;
27
+ if (hasLLMChatV2ToolResponseFormatConflict(effectiveData)) {
21
28
  throw new Error(LLM_CHAT_V2_TOOL_RESPONSE_FORMAT_CONFLICT_COPY.paragraphs[0]);
22
29
  }
23
- const provider = parseChatV2Provider(data.provider);
24
- const modelId = getInputOrData(data, inputs, 'model', 'string');
25
- const baseURL = resolveLLMChatV2BaseURL(data, inputs);
26
- const nodeHeaders = resolveLLMChatV2Headers(data, inputs);
27
- const credential = resolveChatV2Credential({
28
- provider,
29
- context,
30
- apiKeySource: data.apiKeySource === 'input' ? 'input' : 'configured',
31
- inputs,
32
- customProgrammaticName: data.customProviderApiKeyProgrammaticName,
33
- customEnvironmentName: data.customProviderApiKeyEnvVarName,
34
- });
30
+ const provider = parseChatV2Provider(effectiveData.provider);
31
+ const modelId = getInputOrData(effectiveData, inputs, 'model', 'string');
32
+ const baseURL = resolveLLMChatV2BaseURL(effectiveData, inputs);
33
+ const nodeHeaders = resolveLLMChatV2Headers(effectiveData, inputs);
34
+ const credential = profile?.credential ??
35
+ resolveChatV2Credential({
36
+ provider,
37
+ context,
38
+ apiKeySource: effectiveData.apiKeySource === 'input' ? 'input' : 'configured',
39
+ inputs,
40
+ customProgrammaticName: effectiveData.customProviderApiKeyProgrammaticName,
41
+ customEnvironmentName: effectiveData.customProviderApiKeyEnvVarName,
42
+ });
35
43
  const apiKey = credential.value;
36
- const requestBodies = data.outputRequestStatus ? [] : undefined;
44
+ const requestBodies = effectiveData.outputRequestStatus ? [] : undefined;
37
45
  const resolvedProvider = await createResolvedChatV2Provider({
38
46
  provider,
39
47
  modelId,
@@ -47,13 +55,13 @@ export async function resolveLLMChatV2RuntimeConfig(params) {
47
55
  const model = resolvedProvider.model;
48
56
  const prompt = inputs['prompt'];
49
57
  const systemPrompt = inputs['systemPrompt'];
50
- const functions = data.useToolCalling && inputs['functions'] != null
58
+ const functions = effectiveData.useToolCalling && inputs['functions'] != null
51
59
  ? coerceTypeOptional(inputs['functions'], 'gpt-function[]')
52
60
  : undefined;
53
- const toolChoice = resolveLLMChatV2ToolChoice(data);
54
- const responseFormatParameters = resolveChatV2ResponseFormatParameters(data, inputs);
55
- const providerOptions = mergeCustomProviderResponseFormatOptions(provider, resolveLLMChatV2RuntimeProviderOptions(data, inputs), responseFormatParameters);
56
- const generationParameters = resolveLLMChatV2GenerationParameters(data, inputs);
61
+ const toolChoice = resolveLLMChatV2ToolChoice(effectiveData);
62
+ const responseFormatParameters = resolveChatV2ResponseFormatParameters(effectiveData, inputs);
63
+ const providerOptions = mergeCustomProviderResponseFormatOptions(provider, resolveLLMChatV2RuntimeProviderOptions(effectiveData, inputs), responseFormatParameters);
64
+ const generationParameters = resolveLLMChatV2GenerationParameters(effectiveData, inputs);
57
65
  const runOptions = {
58
66
  provider,
59
67
  model,
@@ -61,28 +69,28 @@ export async function resolveLLMChatV2RuntimeConfig(params) {
61
69
  prompt,
62
70
  systemPrompt,
63
71
  functions,
64
- additionalTools: resolveLLMChatV2BuiltInTools(data, context, providerConfig, apiKey),
72
+ additionalTools: resolveLLMChatV2BuiltInTools(effectiveData, context, providerConfig, apiKey),
65
73
  ...generationParameters,
66
74
  responseOutput: createChatV2ResponseOutput(responseFormatParameters, provider),
67
75
  responseFormat: responseFormatParameters?.responseFormat,
68
- outputUsage: data.outputUsage,
69
- outputReasoning: data.outputReasoning,
70
- outputRequestStatus: data.outputRequestStatus,
71
- includeFunctionCalls: data.useToolCalling || hasLLMChatV2BuiltInToolsEnabled(data),
72
- emitPartialOutputs: data.useAsGraphPartialOutput,
76
+ outputUsage: effectiveData.outputUsage,
77
+ outputReasoning: effectiveData.outputReasoning,
78
+ outputRequestStatus: effectiveData.outputRequestStatus,
79
+ includeFunctionCalls: shouldIncludeLLMChatV2ToolCalls(effectiveData),
80
+ emitPartialOutputs: effectiveData.useAsGraphPartialOutput,
73
81
  providerOptions,
74
82
  toolChoice,
75
- anthropicCacheControlTtl: provider === 'anthropic' ? data.anthropicCacheControlTtl || undefined : undefined,
83
+ anthropicCacheControlTtl: provider === 'anthropic' ? effectiveData.anthropicCacheControlTtl || undefined : undefined,
76
84
  requestBodies,
77
- retryOnNon200: data.retryOnNon200,
78
- retryOnNon200RepeatTimes: data.retryOnNon200RepeatTimes,
79
- retryOnNon200CooldownMs: data.retryOnNon200CooldownMs,
85
+ retryOnNon200: effectiveData.retryOnNon200,
86
+ retryOnNon200RepeatTimes: effectiveData.retryOnNon200RepeatTimes,
87
+ retryOnNon200CooldownMs: effectiveData.retryOnNon200CooldownMs,
80
88
  context,
81
89
  };
82
- const editorCache = data.cache ? context.editorExecutionCache : undefined;
90
+ const editorCache = effectiveData.cache ? context.editorExecutionCache : undefined;
83
91
  const { cacheKey, cachedOutputs } = resolveLLMChatV2EditorCache({
84
92
  apiKey,
85
- data,
93
+ data: effectiveData,
86
94
  editorCache,
87
95
  functions,
88
96
  generationParameters,
@@ -103,7 +111,7 @@ export async function resolveLLMChatV2RuntimeConfig(params) {
103
111
  cacheKey,
104
112
  cachedOutputs,
105
113
  editorCache,
106
- shouldAutoContinueToolCalls: !!data.autoContinueToolCalls && data.useToolCalling,
107
- maxToolRounds: data.maxToolRounds ?? 3,
114
+ shouldAutoContinueToolCalls: !!effectiveData.autoContinueToolCalls && effectiveData.useToolCalling,
115
+ maxToolRounds: effectiveData.maxToolRounds ?? 3,
108
116
  };
109
117
  }
@@ -0,0 +1,191 @@
1
+ import { createLLMChatV2NodeData, } from './llmChatV2NodeData.js';
2
+ import { LLM_PROFILE_VALUE_VERSION, pickLLMChatV2ProfileData } from './llmProfileTypes.js';
3
+ export { applyLLMProfileToNodeData, createDefaultLLMProfileValue, createLLMProfileNodeData, LLM_PROFILE_VALUE_VERSION, pickLLMChatV2ProfileData, } from './llmProfileTypes.js';
4
+ const credentialSources = new Set([
5
+ 'input',
6
+ 'settings',
7
+ 'plugin',
8
+ 'programmatic',
9
+ 'environment',
10
+ 'none',
11
+ ]);
12
+ 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
+ export function normalizeLLMProfileValue(value) {
73
+ if (!isRecord(value)) {
74
+ throw new Error('LLM Profile input must contain an LLM profile value.');
75
+ }
76
+ if (value.version !== LLM_PROFILE_VALUE_VERSION) {
77
+ throw new Error(`Unsupported LLM Profile version: ${String(value.version)}.`);
78
+ }
79
+ if (!isRecord(value.configuration)) {
80
+ throw new Error('LLM Profile configuration is missing.');
81
+ }
82
+ const defaults = createLLMChatV2NodeData();
83
+ const provider = normalizeProvider(value.configuration.provider ?? defaults.provider);
84
+ const model = value.configuration.model;
85
+ if (typeof model !== 'string' || !model.trim()) {
86
+ throw new Error('LLM Profile model must be a non-empty string.');
87
+ }
88
+ const credential = normalizeCredential(value.credential);
89
+ const configuration = normalizeConfiguration({
90
+ ...defaults,
91
+ ...value.configuration,
92
+ provider,
93
+ model: model.trim(),
94
+ });
95
+ return {
96
+ version: LLM_PROFILE_VALUE_VERSION,
97
+ configuration,
98
+ credential,
99
+ };
100
+ }
101
+ function normalizeConfiguration(data) {
102
+ for (const field of stringFields) {
103
+ if (typeof data[field] !== 'string') {
104
+ throw new Error(`LLM Profile ${field} must be a string.`);
105
+ }
106
+ }
107
+ for (const field of booleanFields) {
108
+ if (typeof data[field] !== 'boolean') {
109
+ throw new Error(`LLM Profile ${field} must be a boolean.`);
110
+ }
111
+ }
112
+ for (const field of requiredNumberFields) {
113
+ if (typeof data[field] !== 'number' || !Number.isFinite(data[field])) {
114
+ throw new Error(`LLM Profile ${field} must be a finite number.`);
115
+ }
116
+ }
117
+ for (const field of optionalNumberFields) {
118
+ const fieldValue = data[field];
119
+ if (fieldValue != null && (typeof fieldValue !== 'number' || !Number.isFinite(fieldValue))) {
120
+ throw new Error(`LLM Profile ${field} must be a finite number when provided.`);
121
+ }
122
+ }
123
+ if (!Array.isArray(data.stopSequences) || data.stopSequences.some((sequence) => typeof sequence !== 'string')) {
124
+ throw new Error('LLM Profile stopSequences must be an array of strings.');
125
+ }
126
+ if (!Array.isArray(data.headers) ||
127
+ data.headers.some((header) => !isRecord(header) || typeof header.key !== 'string' || typeof header.value !== 'string')) {
128
+ throw new Error('LLM Profile headers must contain string key/value pairs.');
129
+ }
130
+ if (data.apiKeySource !== 'environment' && data.apiKeySource !== 'input') {
131
+ throw new Error(`Unsupported LLM Profile API key source: ${String(data.apiKeySource)}.`);
132
+ }
133
+ assertEnumValue(data.openAIWebSearchContextSize, ['low', 'medium', 'high'], 'OpenAI web search context');
134
+ assertEnumValue(data.anthropicThinkingMode, ['', 'adaptive', 'enabled', 'disabled'], 'Anthropic thinking mode');
135
+ assertEnumValue(data.anthropicEffort, ['', 'low', 'medium', 'high', 'max'], 'Anthropic effort');
136
+ assertEnumValue(data.anthropicCacheControlTtl, ['', '5m', '1h'], 'Anthropic cache TTL');
137
+ assertEnumValue(data.googleThinkingLevel, ['', 'minimal', 'low', 'medium', 'high'], 'Google thinking level');
138
+ const resolvedData = {
139
+ ...data,
140
+ model: data.model.trim(),
141
+ customProviderBaseURL: data.customProviderBaseURL.trim(),
142
+ customProviderApiKeyProgrammaticName: data.customProviderApiKeyProgrammaticName?.trim(),
143
+ customProviderApiKeyEnvVarName: data.customProviderApiKeyEnvVarName?.trim(),
144
+ stopSequences: [...data.stopSequences],
145
+ headers: data.headers.map(({ key, value }) => ({ key, value })),
146
+ };
147
+ // A profile is a resolved configuration value. LLM Chat intentionally does not
148
+ // expose the profile-owned inputs, so accepting a dynamic flag here would let
149
+ // stale hidden connections influence a supposedly self-contained profile.
150
+ for (const field of resolvedInputToggleFields) {
151
+ resolvedData[field] = false;
152
+ }
153
+ return pickLLMChatV2ProfileData(resolvedData);
154
+ }
155
+ function assertEnumValue(value, allowed, label) {
156
+ if (typeof value !== 'string' || !allowed.includes(value)) {
157
+ throw new Error(`Unsupported LLM Profile ${label}: ${String(value)}.`);
158
+ }
159
+ }
160
+ function normalizeProvider(value) {
161
+ if (typeof value !== 'string' || !profileProviders.has(value)) {
162
+ throw new Error(`Unsupported LLM Profile provider: ${String(value)}.`);
163
+ }
164
+ return value;
165
+ }
166
+ function normalizeCredential(value) {
167
+ if (!isRecord(value) ||
168
+ !isRecord(value.reference) ||
169
+ typeof value.reference.source !== 'string' ||
170
+ !credentialSources.has(value.reference.source)) {
171
+ throw new Error('LLM Profile credential metadata is invalid.');
172
+ }
173
+ const credentialValue = value.value;
174
+ if (credentialValue != null && typeof credentialValue !== 'string') {
175
+ throw new Error('LLM Profile API key must be a string when provided.');
176
+ }
177
+ const name = value.reference.name;
178
+ if (name != null && typeof name !== 'string') {
179
+ throw new Error('LLM Profile credential name must be a string when provided.');
180
+ }
181
+ return {
182
+ ...(credentialValue == null ? {} : { value: credentialValue }),
183
+ reference: {
184
+ source: value.reference.source,
185
+ ...(name == null ? {} : { name }),
186
+ },
187
+ };
188
+ }
189
+ function isRecord(value) {
190
+ return typeof value === 'object' && value != null && !Array.isArray(value);
191
+ }