@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.
Files changed (155) hide show
  1. package/dist/cjs/bundle.cjs +3596 -1745
  2. package/dist/cjs/bundle.cjs.map +4 -4
  3. package/dist/cjs/webAppRuntime.cjs +298 -21
  4. package/dist/cjs/webAppRuntime.cjs.map +4 -4
  5. package/dist/esm/exports.js +1 -0
  6. package/dist/esm/model/AgentResponseTrace.js +448 -0
  7. package/dist/esm/model/ConnectedToolContinuationHost.js +33 -0
  8. package/dist/esm/model/GraphProcessor.js +151 -74
  9. package/dist/esm/model/NodeImpl.js +6 -0
  10. package/dist/esm/model/ProcessContextBuilder.js +3 -1
  11. package/dist/esm/model/RecordingPlayer.js +164 -22
  12. package/dist/esm/model/SplitRunProcessor.js +49 -8
  13. package/dist/esm/model/SubprocessorBridge.js +2 -0
  14. package/dist/esm/model/ToolCallContinuationCoordinator.js +7 -3
  15. package/dist/esm/model/UiGraph.js +21 -0
  16. package/dist/esm/model/UiGraphActionProtocol.js +2 -0
  17. package/dist/esm/model/UiGraphBrowserRuntime.js +133 -4
  18. package/dist/esm/model/UiGraphRendererStyles.js +221 -0
  19. package/dist/esm/model/UiGraphRuntimeModel.js +9 -3
  20. package/dist/esm/model/UiGraphSchema.js +7 -1
  21. package/dist/esm/model/chat/aiSdkTools.js +3 -2
  22. package/dist/esm/model/chat-v2/chatV2CallObserver.js +9 -5
  23. package/dist/esm/model/chat-v2/chatV2EditorCache.js +42 -16
  24. package/dist/esm/model/chat-v2/chatV2Errors.js +7 -19
  25. package/dist/esm/model/chat-v2/chatV2FeatureCompatibility.js +1 -1
  26. package/dist/esm/model/chat-v2/chatV2Outputs.js +48 -108
  27. package/dist/esm/model/chat-v2/chatV2Pipeline.js +61 -146
  28. package/dist/esm/model/chat-v2/chatV2ProviderProfile.js +8 -2
  29. package/dist/esm/model/chat-v2/chatV2ProviderRegistry.js +9 -0
  30. package/dist/esm/model/chat-v2/chatV2RequestPlan.js +2 -3
  31. package/dist/esm/model/chat-v2/chatV2ResponseBodyCapture.js +55 -0
  32. package/dist/esm/model/chat-v2/chatV2ResponseFormat.js +8 -4
  33. package/dist/esm/model/chat-v2/chatV2Retry.js +4 -3
  34. package/dist/esm/model/chat-v2/chatV2RuntimeOptions.js +6 -1
  35. package/dist/esm/model/chat-v2/chatV2Types.js +5 -9
  36. package/dist/esm/model/chat-v2/chatV2UsageAccounting.js +78 -0
  37. package/dist/esm/model/chat-v2/customProviderApi.js +42 -0
  38. package/dist/esm/model/chat-v2/index.js +12 -0
  39. package/dist/esm/model/chat-v2/llmChatV2Body.js +281 -0
  40. package/dist/esm/model/chat-v2/llmChatV2CacheBoundary.js +32 -0
  41. package/dist/esm/model/chat-v2/llmChatV2CachePolicy.js +20 -0
  42. package/dist/esm/model/chat-v2/llmChatV2NodeData.js +6 -50
  43. package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +25 -13
  44. package/dist/esm/model/chat-v2/llmChatV2NodeMigration.js +24 -0
  45. package/dist/esm/model/chat-v2/llmChatV2NodeRuntime.js +121 -193
  46. package/dist/esm/model/chat-v2/llmInvocationCoordinator.js +60 -0
  47. package/dist/esm/model/chat-v2/llmInvocationDecision.js +11 -0
  48. package/dist/esm/model/chat-v2/llmInvocationJournal.js +43 -0
  49. package/dist/esm/model/chat-v2/llmInvocationPlan.js +68 -0
  50. package/dist/esm/model/chat-v2/llmInvocationProjections.js +5 -0
  51. package/dist/esm/model/chat-v2/llmInvocationResultProjector.js +48 -0
  52. package/dist/esm/model/chat-v2/llmModelCandidate.js +75 -0
  53. package/dist/esm/model/chat-v2/llmProfile.js +10 -65
  54. package/dist/esm/model/chat-v2/llmProfileBody.js +183 -0
  55. package/dist/esm/model/chat-v2/llmProfileFallback.js +55 -99
  56. package/dist/esm/model/chat-v2/llmProfileFieldRegistry.js +67 -0
  57. package/dist/esm/model/chat-v2/llmProfileNodeRuntime.js +3 -0
  58. package/dist/esm/model/chat-v2/llmProfileTypes.js +1 -18
  59. package/dist/esm/model/chat-v2/llmResponseMaterializer.js +42 -0
  60. package/dist/esm/model/chat-v2/modelRegistry.js +54 -4
  61. package/dist/esm/model/chat-v2/parallelToolCalls.js +9 -2
  62. package/dist/esm/model/chat-v2/providerOptions.js +86 -20
  63. package/dist/esm/model/chat-v2/rivetToolRegistry.js +9 -0
  64. package/dist/esm/model/chat-v2/toolCallCodec.js +52 -0
  65. package/dist/esm/model/chat-v2/toolContinuation.js +72 -35
  66. package/dist/esm/model/chat-v2/toolHandlerResolver.js +23 -0
  67. package/dist/esm/model/chat-v2/toolRoundExecutor.js +12 -0
  68. package/dist/esm/model/nodes/ChatNode.js +6 -0
  69. package/dist/esm/model/nodes/ChatNodeBase.js +1 -0
  70. package/dist/esm/model/nodes/DelegateFunctionCallNode.js +19 -6
  71. package/dist/esm/model/nodes/LLMChatV2Node.js +112 -229
  72. package/dist/esm/model/nodes/LLMProfileNode.js +27 -8
  73. package/dist/esm/model/nodes/PromptNode.js +7 -0
  74. package/dist/esm/model/nodes/ToolNode.js +7 -0
  75. package/dist/esm/model/nodes/toolCallDelegation.js +177 -110
  76. package/dist/esm/plugins/anthropic/anthropic.js +4 -4
  77. package/dist/esm/plugins/anthropic/nodes/ChatAnthropicNode.js +7 -0
  78. package/dist/esm/plugins/google/google.js +5 -9
  79. package/dist/esm/plugins/google/nodes/ChatGoogleNode.js +4 -1
  80. package/dist/esm/recording/ExecutionRecorder.js +13 -5
  81. package/dist/esm/utils/emitDetached.js +6 -3
  82. package/dist/esm/utils/openai.js +60 -16
  83. package/dist/esm/utils/serialization/serialization.js +2 -19
  84. package/dist/esm/webAppRuntime.js +3 -2
  85. package/dist/types/exports.d.ts +1 -0
  86. package/dist/types/model/AgentResponseTrace.d.ts +110 -0
  87. package/dist/types/model/ConnectedToolContinuationHost.d.ts +34 -0
  88. package/dist/types/model/ExecutorProtocol.d.ts +25 -7
  89. package/dist/types/model/GraphProcessor.d.ts +27 -5
  90. package/dist/types/model/NodeImpl.d.ts +18 -1
  91. package/dist/types/model/Nodes.d.ts +2 -2
  92. package/dist/types/model/ProcessContext.d.ts +47 -0
  93. package/dist/types/model/ProcessContextBuilder.d.ts +3 -1
  94. package/dist/types/model/RecordingPlayer.d.ts +6 -0
  95. package/dist/types/model/SplitRunProcessor.d.ts +10 -3
  96. package/dist/types/model/UiGraph.d.ts +8 -0
  97. package/dist/types/model/UiGraphActionProtocol.d.ts +2 -0
  98. package/dist/types/model/UiGraphBrowserRuntime.d.ts +11 -2
  99. package/dist/types/model/UiGraphRendererStyles.d.ts +1 -1
  100. package/dist/types/model/UiGraphRuntimeModel.d.ts +2 -0
  101. package/dist/types/model/UiGraphSchema.d.ts +1 -0
  102. package/dist/types/model/chat-v2/chatV2CallObserver.d.ts +2 -0
  103. package/dist/types/model/chat-v2/chatV2EditorCache.d.ts +1 -3
  104. package/dist/types/model/chat-v2/chatV2Outputs.d.ts +6 -16
  105. package/dist/types/model/chat-v2/chatV2Pipeline.d.ts +13 -17
  106. package/dist/types/model/chat-v2/chatV2ProviderProfile.d.ts +4 -0
  107. package/dist/types/model/chat-v2/chatV2ProviderRegistry.d.ts +8 -0
  108. package/dist/types/model/chat-v2/chatV2RequestPlan.d.ts +2 -2
  109. package/dist/types/model/chat-v2/chatV2ResponseBodyCapture.d.ts +19 -0
  110. package/dist/types/model/chat-v2/chatV2ResponseFormat.d.ts +3 -2
  111. package/dist/types/model/chat-v2/chatV2Retry.d.ts +2 -0
  112. package/dist/types/model/chat-v2/chatV2Types.d.ts +20 -10
  113. package/dist/types/model/chat-v2/chatV2UsageAccounting.d.ts +14 -0
  114. package/dist/types/model/chat-v2/customProviderApi.d.ts +23 -0
  115. package/dist/types/model/chat-v2/index.d.ts +12 -0
  116. package/dist/types/model/chat-v2/llmChatV2Body.d.ts +24 -0
  117. package/dist/types/model/chat-v2/llmChatV2CacheBoundary.d.ts +10 -0
  118. package/dist/types/model/chat-v2/llmChatV2CachePolicy.d.ts +13 -0
  119. package/dist/types/model/chat-v2/llmChatV2NodeData.d.ts +10 -3
  120. package/dist/types/model/chat-v2/llmChatV2NodeMigration.d.ts +8 -0
  121. package/dist/types/model/chat-v2/llmChatV2NodeRuntime.d.ts +14 -16
  122. package/dist/types/model/chat-v2/llmInvocationCoordinator.d.ts +16 -0
  123. package/dist/types/model/chat-v2/llmInvocationDecision.d.ts +21 -0
  124. package/dist/types/model/chat-v2/llmInvocationJournal.d.ts +38 -0
  125. package/dist/types/model/chat-v2/llmInvocationPlan.d.ts +41 -0
  126. package/dist/types/model/chat-v2/llmInvocationProjections.d.ts +3 -0
  127. package/dist/types/model/chat-v2/llmInvocationResultProjector.d.ts +26 -0
  128. package/dist/types/model/chat-v2/llmModelCandidate.d.ts +18 -0
  129. package/dist/types/model/chat-v2/llmProfileBody.d.ts +20 -0
  130. package/dist/types/model/chat-v2/llmProfileFallback.d.ts +17 -49
  131. package/dist/types/model/chat-v2/llmProfileFieldRegistry.d.ts +189 -0
  132. package/dist/types/model/chat-v2/llmProfileTypes.d.ts +1 -1
  133. package/dist/types/model/chat-v2/llmResponseMaterializer.d.ts +20 -0
  134. package/dist/types/model/chat-v2/modelRegistry.d.ts +17 -187
  135. package/dist/types/model/chat-v2/parallelToolCalls.d.ts +3 -1
  136. package/dist/types/model/chat-v2/providerOptions.d.ts +10 -0
  137. package/dist/types/model/chat-v2/rivetToolRegistry.d.ts +11 -0
  138. package/dist/types/model/chat-v2/toolCallCodec.d.ts +7 -0
  139. package/dist/types/model/chat-v2/toolContinuation.d.ts +3 -3
  140. package/dist/types/model/chat-v2/toolHandlerResolver.d.ts +25 -0
  141. package/dist/types/model/chat-v2/toolRoundExecutor.d.ts +18 -0
  142. package/dist/types/model/nodes/ChatNode.d.ts +2 -1
  143. package/dist/types/model/nodes/DelegateFunctionCallNode.d.ts +2 -1
  144. package/dist/types/model/nodes/LLMChatV2Node.d.ts +2 -1
  145. package/dist/types/model/nodes/LLMProfileNode.d.ts +2 -1
  146. package/dist/types/model/nodes/PromptNode.d.ts +4 -1
  147. package/dist/types/model/nodes/ToolNode.d.ts +2 -1
  148. package/dist/types/model/nodes/toolCallDelegation.d.ts +10 -3
  149. package/dist/types/plugins/anthropic/anthropic.d.ts +1 -0
  150. package/dist/types/plugins/google/google.d.ts +2 -8
  151. package/dist/types/recording/RecordedEvents.d.ts +6 -0
  152. package/dist/types/utils/emitDetached.d.ts +3 -2
  153. package/dist/types/utils/openai.d.ts +49 -0
  154. package/dist/types/webAppRuntime.d.ts +4 -2
  155. package/package.json +2 -2
@@ -1,53 +1,8 @@
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
+ import { llmProfileDataKeys } from './llmProfileFieldRegistry.js';
4
+ /** @deprecated Use llmProfileDataKeys from llmProfileFieldRegistry instead. */
5
+ export const llmChatV2ProfileDataKeys = llmProfileDataKeys;
51
6
  export function createLLMChatV2NodeData() {
52
7
  return {
53
8
  ...createChatV2CommonNodeData({
@@ -60,6 +15,7 @@ export function createLLMChatV2NodeData() {
60
15
  customProviderApiKeyEnvVarName: 'CUSTOM_PROVIDER_API_KEY',
61
16
  customProviderBaseURL: '',
62
17
  useCustomProviderBaseURLInput: false,
18
+ customProviderApi: 'completions',
63
19
  baseURL: '',
64
20
  useBaseURLInput: false,
65
21
  headers: [],
@@ -97,9 +53,9 @@ export function createLLMChatV2NodeData() {
97
53
  retryOnNon200: false,
98
54
  retryOnNon200RepeatTimes: DEFAULT_LLM_CHAT_V2_RETRY_ON_NON_200_REPEAT_TIMES,
99
55
  retryOnNon200CooldownMs: DEFAULT_LLM_CHAT_V2_RETRY_ON_NON_200_COOLDOWN_MS,
100
- outputRequestStatus: false,
101
- outputRequestError: false,
56
+ outputLLMAttempts: false,
102
57
  outputRequestBody: false,
58
+ outputResponseBody: false,
103
59
  };
104
60
  }
105
61
  export function shouldIncludeLLMChatV2ToolCalls(data) {
@@ -1,5 +1,5 @@
1
1
  import { DEFAULT_LLM_CHAT_V2_RETRY_ON_NON_200_COOLDOWN_MS, DEFAULT_LLM_CHAT_V2_RETRY_ON_NON_200_REPEAT_TIMES, } from './chatV2Retry.js';
2
- import { anthropicCacheControlTtlOptions, anthropicEffortOptions, anthropicThinkingModeOptions, chatV2ProviderOptions, getChatV2ModelOptions, googleThinkingLevelOptions, openAIReasoningEffortOptions, openAIWebSearchContextSizeOptions, } from './providerOptions.js';
2
+ import { anthropicCacheControlTtlOptions, anthropicEffortOptions, anthropicThinkingModeOptions, chatV2ProviderOptions, customProviderApiOptions, getChatV2ModelOptions, googleThinkingLevelOptions, openAIReasoningEffortOptions, openAIWebSearchContextSizeOptions, } from './providerOptions.js';
3
3
  import { LLM_CHAT_V2_PARALLEL_TOOL_CALLS_HELPER_MESSAGE, supportsLLMChatV2ParallelToolCalls, } from './parallelToolCalls.js';
4
4
  const hideUnlessProvider = (provider) => (data) => data.provider !== provider;
5
5
  function group(label, editors, defaultOpen) {
@@ -61,7 +61,16 @@ function getModelEditors(modelOptions) {
61
61
  dataKey: 'customProviderBaseURL',
62
62
  useInputToggleDataKey: 'useCustomProviderBaseURLInput',
63
63
  placeholder: 'https://api.cerebras.ai/v1',
64
- helperMessage: 'OpenAI-compatible provider base URL. Full /chat/completions URLs are accepted and normalized.',
64
+ helperMessage: 'OpenAI-compatible provider base URL. Full /chat/completions or /responses URLs are accepted and normalized.',
65
+ hideIf: hideUnlessProvider('custom'),
66
+ },
67
+ {
68
+ type: 'segmented',
69
+ label: 'API',
70
+ ariaLabel: 'Custom provider API',
71
+ dataKey: 'customProviderApi',
72
+ defaultValue: 'completions',
73
+ options: [...customProviderApiOptions],
65
74
  hideIf: hideUnlessProvider('custom'),
66
75
  },
67
76
  {
@@ -375,7 +384,9 @@ function getToolEditors() {
375
384
  type: 'toggle',
376
385
  label: 'Allow parallel toolcalls',
377
386
  dataKey: 'parallelToolCalls',
378
- helperMessage: LLM_CHAT_V2_PARALLEL_TOOL_CALLS_HELPER_MESSAGE,
387
+ helperMessage: (data) => data.configurationMode === 'profile'
388
+ ? `${LLM_CHAT_V2_PARALLEL_TOOL_CALLS_HELPER_MESSAGE} In From profile mode, it applies only to candidates whose providers support parallel tool calls; unsupported candidates ignore it.`
389
+ : LLM_CHAT_V2_PARALLEL_TOOL_CALLS_HELPER_MESSAGE,
379
390
  hideIf: (data) => !data.useToolCalling ||
380
391
  (data.configurationMode !== 'profile' && !supportsLLMChatV2ParallelToolCalls(data.provider)),
381
392
  },
@@ -388,8 +399,9 @@ function getToolEditors() {
388
399
  },
389
400
  {
390
401
  type: 'number',
391
- label: 'Max tool rounds',
402
+ label: 'Maximum tool rounds',
392
403
  dataKey: 'maxToolRounds',
404
+ helperMessage: 'Each round may contain multiple parallel tool calls if not disallowed.',
393
405
  min: 1,
394
406
  step: 1,
395
407
  hideIf: (data) => !data.useToolCalling || !data.autoContinueToolCalls,
@@ -412,9 +424,9 @@ function getOutputEditors() {
412
424
  },
413
425
  {
414
426
  type: 'toggle',
415
- label: 'Output response status',
416
- dataKey: 'outputRequestStatus',
417
- helperMessage: 'Adds a Response Status output. Retry mode returns statuses for each physical request. An LLM Profile array groups values by profile, while a profile with one request stays a number.',
427
+ label: 'Output LLM attempts',
428
+ dataKey: 'outputLLMAttempts',
429
+ helperMessage: 'Adds one chronological record for every profile configuration, provider request, and response-validation attempt. Records include provider, model, retry status, and provider error details when available.',
418
430
  },
419
431
  {
420
432
  type: 'toggle',
@@ -422,6 +434,12 @@ function getOutputEditors() {
422
434
  dataKey: 'outputRequestBody',
423
435
  helperMessage: 'Adds an LLM request body output. It can contain prompts and non-secret provider options; it never includes authorization headers or API keys.',
424
436
  },
437
+ {
438
+ type: 'toggle',
439
+ label: 'Output response body',
440
+ dataKey: 'outputResponseBody',
441
+ helperMessage: 'Adds the complete LLM response body captured at the provider HTTP boundary. JSON responses are parsed for inspection; other responses remain text. Rivet does not redact or truncate captured content.',
442
+ },
425
443
  {
426
444
  type: 'toggle',
427
445
  label: 'Stream response',
@@ -488,12 +506,6 @@ function getErrorBehaviorEditors() {
488
506
  helperMessage: 'Milliseconds to wait between repeats',
489
507
  hideIf: (data) => !data.retryOnNon200,
490
508
  },
491
- {
492
- type: 'toggle',
493
- label: 'Output response error',
494
- dataKey: 'outputRequestError',
495
- helperMessage: 'Adds a Response Error output. Provider request failures become excluded outputs instead of node errors. Retry mode returns errors for each physical request; an LLM Profile array groups errors by profile.',
496
- },
497
509
  ]);
498
510
  }
499
511
  export async function getLLMChatV2Editors(data, context) {
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Serialized LLM Chat migrations live beside the node contract, rather than
3
+ * making generic project serialization understand LLM-specific settings.
4
+ * This is deliberately idempotent because deserialization can normalize a
5
+ * graph more than once while it is imported or embedded in a prefab.
6
+ */
7
+ export function normalizeSerializedLLMChatV2Node(node) {
8
+ if (node.type !== 'llmChatV2' || node.data == null || typeof node.data !== 'object') {
9
+ return;
10
+ }
11
+ const data = node.data;
12
+ const hadLegacyRequestDiagnostics = data.outputRequestStatus === true || data.outputRequestError === true;
13
+ if (hadLegacyRequestDiagnostics && !Object.hasOwn(data, 'outputLLMAttempts')) {
14
+ data.outputLLMAttempts = true;
15
+ }
16
+ // The original request-details switch also enabled request-body capture.
17
+ // Preserve that still-supported diagnostic independently from the retired
18
+ // status/error ports.
19
+ if (data.outputRequestStatus === true && !Object.hasOwn(data, 'outputRequestBody')) {
20
+ data.outputRequestBody = true;
21
+ }
22
+ delete data.outputRequestStatus;
23
+ delete data.outputRequestError;
24
+ }
@@ -1,273 +1,201 @@
1
- import { coerceTypeOptional } from '../../utils/coerceType.js';
2
- import { cleanHeaders, getInputOrData } from '../../utils/inputs.js';
3
- import { coercePromptToChatMessages, prependSystemPrompt } from '../chat/chatMessages.js';
4
- import { getInstructionMessageRoles, restoreOpenAICompatibleInstructionRoles } from './developerMessageRoles.js';
5
- import { createChatV2ResponseOutput, mergeCustomProviderResponseFormatOptions, resolveChatV2ResponseFormatParameters, } from './chatV2ResponseFormat.js';
6
- import { hasLLMChatV2ToolResponseFormatConflict, LLM_CHAT_V2_TOOL_RESPONSE_FORMAT_CONFLICT_COPY, } from './chatV2FeatureCompatibility.js';
7
- import { createLLMProfileFallbackRunner } from './llmProfileFallback.js';
1
+ import { cleanHeaders } from '../../utils/inputs.js';
2
+ import { createLLMProfileFallbackRunner, getLLMAttemptErrorMessage } from './llmProfileFallback.js';
8
3
  import { applyLLMProfileToNodeData, normalizeLLMProfileChainInput } from './llmProfile.js';
9
- import { parseChatV2Provider, resolveChatV2ProviderConfig } from './providerOptions.js';
10
- import { createResolvedChatV2Provider, resolveChatV2Credential } from './chatV2ProviderProfile.js';
11
- import { shouldOutputChatV2RequestBody, shouldOutputChatV2RequestError, } from './chatV2Types.js';
4
+ import { buildLLMInvocationPlan, buildLLMInvocationRunOptions } from './llmInvocationPlan.js';
5
+ import { resolveLLMModelCandidate } from './llmModelCandidate.js';
6
+ import { mergeCustomProviderResponseFormatOptions } from './chatV2ResponseFormat.js';
7
+ import { getLLMChatV2EditorCacheEligibility } from './llmChatV2CachePolicy.js';
8
+ import { parseChatV2Provider } from './providerOptions.js';
9
+ import { parseCustomProviderApi } from './customProviderApi.js';
12
10
  import { buildLLMChatV2EditorCacheKey, cloneLLMChatV2EditorCacheOutputs, resolveLLMChatV2EditorCache, } from './chatV2EditorCache.js';
13
- import { resolveLLMChatV2BuiltInTools, resolveLLMChatV2GenerationParameters, resolveLLMChatV2Headers, resolveLLMChatV2RuntimeProviderOptions, resolveLLMChatV2ToolChoice, } from './chatV2RuntimeOptions.js';
14
- import { shouldIncludeLLMChatV2ToolCalls, } from './llmChatV2NodeData.js';
15
- import { runChatV2Pipeline } from './chatV2Pipeline.js';
11
+ import { resolveLLMChatV2GenerationParameters, resolveLLMChatV2RuntimeProviderOptions, } from './chatV2RuntimeOptions.js';
12
+ import {} from './llmChatV2NodeData.js';
13
+ import { isChatV2ResponseValidationError, runChatV2Pipeline } from './chatV2Pipeline.js';
16
14
  export { buildLLMChatV2EditorCacheKey, cloneLLMChatV2EditorCacheOutputs };
17
15
  export { resolveLLMChatV2RuntimeProviderOptions } from './chatV2RuntimeOptions.js';
18
- function resolveLLMChatV2BaseURL(data, inputs) {
19
- return data.provider === 'custom'
20
- ? getInputOrData(data, inputs, 'customProviderBaseURL', 'string', 'useCustomProviderBaseURLInput')?.trim() ||
21
- undefined
22
- : undefined;
23
- }
24
- function createSharedRunOptions(params) {
25
- const { shared, provider, modelId } = params;
26
- return {
27
- provider,
28
- // From profile mode replaces this before a provider request. Keeping the
29
- // field populated preserves the established Tool Continuation contract.
30
- model: undefined,
31
- modelId,
32
- prompt: shared.prompt,
33
- systemPrompt: shared.systemPrompt,
34
- functions: shared.functions,
35
- responseOutput: createChatV2ResponseOutput(shared.responseFormatParameters, provider),
36
- responseFormat: shared.responseFormatParameters?.responseFormat,
37
- outputUsage: shared.data.outputUsage,
38
- outputReasoning: shared.data.outputReasoning,
39
- outputRequestStatus: shared.data.outputRequestStatus,
40
- outputRequestError: shouldOutputChatV2RequestError(shared.data),
41
- outputRequestBody: shouldOutputChatV2RequestBody(shared.data),
42
- includeFunctionCalls: shouldIncludeLLMChatV2ToolCalls(shared.data),
43
- emitPartialOutputs: shared.data.useAsGraphPartialOutput,
44
- toolChoice: shared.toolChoice,
45
- requestBodies: shared.requestBodies,
46
- retryOnNon200: shared.data.retryOnNon200,
47
- retryOnNon200RepeatTimes: shared.data.retryOnNon200RepeatTimes,
48
- retryOnNon200CooldownMs: shared.data.retryOnNon200CooldownMs,
49
- context: shared.context,
50
- };
51
- }
52
- function createRuntimeProviderProfile(params) {
53
- const provider = parseChatV2Provider(params.data.provider);
54
- return {
55
- provider,
56
- modelId: getInputOrData(params.data, params.inputs, 'model', 'string'),
57
- baseURL: resolveLLMChatV2BaseURL(params.data, params.inputs),
58
- hasCustomHeaders: Object.keys(resolveLLMChatV2Headers(params.data, params.inputs) ?? {}).length > 0,
59
- credential: params.credential.reference,
60
- capabilities: {
61
- builtInTools: provider === 'openai' || provider === 'google',
62
- structuredOutput: true,
63
- },
64
- };
65
- }
66
- async function resolveCandidateRunOptions(params) {
67
- const { shared, profile, roundOptions } = params;
68
- const effectiveData = profile ? applyLLMProfileToNodeData(shared.data, profile) : shared.data;
69
- if (hasLLMChatV2ToolResponseFormatConflict(effectiveData)) {
70
- throw new Error(LLM_CHAT_V2_TOOL_RESPONSE_FORMAT_CONFLICT_COPY.paragraphs[0]);
71
- }
72
- const provider = parseChatV2Provider(effectiveData.provider);
73
- const modelId = getInputOrData(effectiveData, shared.inputs, 'model', 'string');
74
- const baseURL = resolveLLMChatV2BaseURL(effectiveData, shared.inputs);
75
- const headers = resolveLLMChatV2Headers(effectiveData, shared.inputs);
76
- const credential = profile?.credential ??
77
- resolveChatV2Credential({
78
- provider,
79
- context: shared.context,
80
- apiKeySource: effectiveData.apiKeySource === 'input' ? 'input' : 'configured',
81
- inputs: shared.inputs,
82
- customProgrammaticName: effectiveData.customProviderApiKeyProgrammaticName,
83
- customEnvironmentName: effectiveData.customProviderApiKeyEnvVarName,
84
- });
85
- const transformRequestBody = (provider === 'openai' || provider === 'custom') && shared.instructionRoles.includes('developer')
86
- ? (body) => restoreOpenAICompatibleInstructionRoles(body, shared.instructionRoles)
87
- : undefined;
88
- const resolvedProvider = await createResolvedChatV2Provider({
89
- provider,
90
- modelId,
91
- context: shared.context,
92
- baseURL,
93
- headers,
94
- credential,
95
- onRequestBody: shared.requestBodies == null ? undefined : (body) => shared.requestBodies.push(body),
96
- transformRequestBody,
97
- });
98
- const generationParameters = resolveLLMChatV2GenerationParameters(effectiveData, shared.inputs);
99
- const providerOptions = mergeCustomProviderResponseFormatOptions(provider, resolveLLMChatV2RuntimeProviderOptions(effectiveData, shared.inputs), shared.responseFormatParameters);
100
- return {
101
- ...roundOptions,
102
- provider,
103
- model: resolvedProvider.model,
104
- modelId,
105
- additionalTools: resolveLLMChatV2BuiltInTools(effectiveData, shared.context, resolvedProvider.config, credential.value),
106
- ...generationParameters,
107
- responseOutput: createChatV2ResponseOutput(shared.responseFormatParameters, provider),
108
- responseFormat: shared.responseFormatParameters?.responseFormat,
109
- providerOptions,
110
- anthropicCacheControlTtl: provider === 'anthropic' ? effectiveData.anthropicCacheControlTtl || undefined : undefined,
111
- requestBodies: shared.requestBodies,
112
- };
113
- }
114
- function createSharedRuntimeValues(params) {
115
- const { data, inputs, context } = params;
116
- const prompt = inputs['prompt'];
117
- const systemPrompt = inputs['systemPrompt'];
118
- return {
119
- data,
120
- inputs,
121
- context,
122
- prompt,
123
- systemPrompt,
124
- functions: data.useToolCalling && inputs['functions'] != null
125
- ? coerceTypeOptional(inputs['functions'], 'gpt-function[]')
126
- : undefined,
127
- responseFormatParameters: resolveChatV2ResponseFormatParameters(data, inputs),
128
- toolChoice: resolveLLMChatV2ToolChoice(data),
129
- requestBodies: shouldOutputChatV2RequestBody(data) ? [] : undefined,
130
- instructionRoles: getInstructionMessageRoles(prependSystemPrompt(coercePromptToChatMessages(prompt), systemPrompt)),
131
- };
132
- }
133
16
  export async function resolveLLMChatV2RuntimeConfig(params) {
134
17
  const { data, nodeId, inputs, context } = params;
135
18
  const profileInput = inputs['llmProfile'];
136
19
  if (data.configurationMode === 'profile' && profileInput == null) {
137
20
  throw new Error('LLM Profile input is required when Configuration is From profile.');
138
21
  }
139
- const shared = createSharedRuntimeValues({ data, inputs, context });
140
- const editorCache = data.cache ? context.editorExecutionCache : undefined;
22
+ const plan = buildLLMInvocationPlan({ data, inputs, context });
141
23
  if (data.configurationMode !== 'profile') {
142
- const inlineRunOptions = await resolveCandidateRunOptions({
143
- shared,
24
+ // The editor cache cannot faithfully replay tool handlers, connected
25
+ // Delegate runs, provider-native tools, or their side effects. A legacy
26
+ // cache-enabled node therefore remains cacheable only for ordinary model
27
+ // calls without tool use.
28
+ const editorCache = getEligibleEditorCache(data, context);
29
+ const inlineCandidate = await resolveLLMModelCandidate({
30
+ plan,
144
31
  profile: undefined,
145
- roundOptions: createSharedRunOptions({
146
- shared,
32
+ roundOptions: buildLLMInvocationRunOptions({
33
+ plan,
147
34
  provider: parseChatV2Provider(data.provider),
148
35
  modelId: data.model,
149
36
  }),
150
37
  });
38
+ const inlineRunOptions = inlineCandidate.runOptions;
151
39
  const generationParameters = resolveLLMChatV2GenerationParameters(data, inputs);
152
- const inlineCredential = resolveChatV2Credential({
153
- provider: inlineRunOptions.provider,
154
- context,
155
- apiKeySource: data.apiKeySource === 'input' ? 'input' : 'configured',
156
- inputs,
157
- customProgrammaticName: data.customProviderApiKeyProgrammaticName,
158
- customEnvironmentName: data.customProviderApiKeyEnvVarName,
159
- });
160
- const inlineProviderConfig = await resolveChatV2ProviderConfig(inlineRunOptions.provider, inlineRunOptions.modelId, context, {
161
- baseURL: resolveLLMChatV2BaseURL(data, inputs),
162
- headers: resolveLLMChatV2Headers(data, inputs),
163
- });
164
40
  const { cacheKey, cachedOutputs } = resolveLLMChatV2EditorCache({
165
- apiKey: inlineCredential.value,
41
+ apiKey: inlineCandidate.credential.value,
166
42
  data,
167
43
  editorCache,
168
- functions: shared.functions,
44
+ functions: plan.functions,
169
45
  generationParameters,
170
46
  modelId: inlineRunOptions.modelId,
171
47
  nodeId,
172
- prompt: shared.prompt,
48
+ prompt: plan.prompt,
173
49
  provider: inlineRunOptions.provider,
174
- providerConfig: inlineProviderConfig,
50
+ providerConfig: inlineCandidate.providerConfig,
175
51
  providerOptions: inlineRunOptions.providerOptions,
176
- responseFormatParameters: shared.responseFormatParameters,
177
- systemPrompt: shared.systemPrompt,
178
- toolChoice: shared.toolChoice,
52
+ responseFormatParameters: plan.responseFormatParameters,
53
+ systemPrompt: plan.systemPrompt,
54
+ toolChoice: plan.toolChoice,
179
55
  });
180
56
  return {
181
57
  runOptions: inlineRunOptions,
182
- providerProfile: createRuntimeProviderProfile({
183
- data,
184
- inputs,
185
- credential: inlineCredential,
186
- }),
187
- runPipeline: runChatV2Pipeline,
188
- functions: shared.functions,
58
+ runPipeline: async (roundOptions) => {
59
+ try {
60
+ return await runChatV2Pipeline({
61
+ ...roundOptions,
62
+ model: inlineRunOptions.model,
63
+ onProviderAttempt: (attempt) => {
64
+ try {
65
+ roundOptions.onProviderAttempt?.(attempt);
66
+ }
67
+ catch {
68
+ // A caller-owned observer must not affect the physical request.
69
+ }
70
+ try {
71
+ params.onLLMAttempt?.({
72
+ roundIndex: roundOptions.roundIndex ?? 0,
73
+ provider: inlineRunOptions.provider,
74
+ model: inlineRunOptions.modelId,
75
+ ...(inlineRunOptions.customProviderApi == null
76
+ ? {}
77
+ : { customProviderApi: inlineRunOptions.customProviderApi }),
78
+ stage: 'request',
79
+ outcome: attempt.outcome === 'success' ? 'success' : attempt.outcome === 'aborted' ? 'aborted' : 'failure',
80
+ attemptIndex: attempt.attemptIndex,
81
+ ...(attempt.status == null ? {} : { status: attempt.status }),
82
+ ...(attempt.error == null ? {} : { error: getLLMAttemptErrorMessage(attempt.error) }),
83
+ });
84
+ }
85
+ catch {
86
+ // Diagnostics must never affect a model invocation.
87
+ }
88
+ },
89
+ });
90
+ }
91
+ catch (error) {
92
+ if (isChatV2ResponseValidationError(error)) {
93
+ try {
94
+ params.onLLMAttempt?.({
95
+ roundIndex: roundOptions.roundIndex ?? 0,
96
+ provider: inlineRunOptions.provider,
97
+ model: inlineRunOptions.modelId,
98
+ ...(inlineRunOptions.customProviderApi == null
99
+ ? {}
100
+ : { customProviderApi: inlineRunOptions.customProviderApi }),
101
+ stage: 'response-validation',
102
+ outcome: 'failure',
103
+ error: getLLMAttemptErrorMessage(error),
104
+ });
105
+ }
106
+ catch {
107
+ // Diagnostics must never affect a model invocation.
108
+ }
109
+ }
110
+ throw error;
111
+ }
112
+ },
113
+ functions: plan.functions,
189
114
  cacheKey,
190
115
  cachedOutputs,
191
116
  editorCache,
192
117
  shouldAutoContinueToolCalls: !!data.autoContinueToolCalls && data.useToolCalling,
193
118
  maxToolRounds: data.maxToolRounds ?? 3,
194
- profileAttempts: undefined,
195
- profileChainUsesArray: false,
196
- profileChainLength: undefined,
119
+ outputLLMAttempts: data.outputLLMAttempts === true,
197
120
  getProfileSummary: undefined,
198
121
  isProfileFallbackExhausted: () => false,
199
122
  };
200
123
  }
201
124
  const profiles = normalizeLLMProfileChainInput(profileInput?.value);
125
+ // Profile-owned provider-native capabilities are resolved only after the
126
+ // input profile is normalized. One cache entry covers the complete fallback
127
+ // chain, so every possible candidate must be replay-safe.
128
+ const editorCache = profiles.every((profile) => getLLMChatV2EditorCacheEligibility({ ...data, ...profile.configuration }).eligible)
129
+ ? context.editorExecutionCache
130
+ : undefined;
202
131
  const firstProfile = profiles[0];
203
132
  const firstProvider = parseChatV2Provider(firstProfile.configuration.provider);
204
- const profileRunOptions = createSharedRunOptions({
205
- shared,
206
- provider: firstProvider,
207
- modelId: firstProfile.configuration.model,
208
- });
133
+ // The fallback runner resolves a real model before every physical request.
134
+ // This is deliberately a provider-neutral round template, never a fake
135
+ // executable model state.
136
+ const profileRunOptions = {
137
+ ...buildLLMInvocationRunOptions({
138
+ plan,
139
+ provider: firstProvider,
140
+ modelId: firstProfile.configuration.model,
141
+ }),
142
+ };
209
143
  const firstProfileData = applyLLMProfileToNodeData(data, firstProfile);
210
144
  Object.assign(profileRunOptions, {
211
145
  ...resolveLLMChatV2GenerationParameters(firstProfileData, inputs),
212
- providerOptions: mergeCustomProviderResponseFormatOptions(firstProvider, resolveLLMChatV2RuntimeProviderOptions(firstProfileData, inputs), shared.responseFormatParameters),
146
+ providerOptions: mergeCustomProviderResponseFormatOptions(firstProvider, resolveLLMChatV2RuntimeProviderOptions(firstProfileData, inputs), plan.responseFormatParameters, firstProfileData.customProviderApi),
213
147
  anthropicCacheControlTtl: firstProvider === 'anthropic' ? firstProfileData.anthropicCacheControlTtl || undefined : undefined,
214
148
  });
215
149
  const fallbackRunner = createLLMProfileFallbackRunner({
216
150
  candidates: profiles.map((profile) => ({
217
151
  provider: parseChatV2Provider(profile.configuration.provider),
218
152
  model: profile.configuration.model,
219
- credential: profile.credential.value,
220
- redactionValues: [
221
- ...profile.configuration.headers.map((header) => header.value),
222
- ...Object.values(cleanHeaders(context.settings?.chatNodeHeaders ?? {})),
223
- ],
153
+ ...(profile.configuration.provider === 'custom'
154
+ ? { customProviderApi: parseCustomProviderApi(profile.configuration.customProviderApi) }
155
+ : {}),
224
156
  })),
225
- resolveCandidate: (profileIndex, roundOptions) => resolveCandidateRunOptions({
226
- shared,
157
+ resolveCandidate: (profileIndex, roundOptions) => resolveLLMModelCandidate({
158
+ plan,
227
159
  profile: profiles[profileIndex],
228
160
  roundOptions,
229
- }),
161
+ }).then((candidate) => candidate.runOptions),
162
+ onAttempt: params.onLLMAttempt,
230
163
  });
231
164
  const { cacheKey, cachedOutputs } = resolveLLMChatV2EditorCache({
232
165
  apiKey: undefined,
233
166
  data: firstProfileData,
234
167
  editorCache,
235
- functions: shared.functions,
168
+ functions: plan.functions,
236
169
  generationParameters: undefined,
237
170
  modelId: firstProfile.configuration.model,
238
171
  nodeId,
239
- prompt: shared.prompt,
172
+ prompt: plan.prompt,
240
173
  provider: firstProvider,
241
174
  // Profile headers are part of the individual profile fingerprints, but
242
175
  // provider resolution also merges project-wide Chat headers. Include those
243
- // values through the existing redacted provider-config fingerprint so a
176
+ // values through the normalized provider-config fingerprint so a
244
177
  // global-header edit cannot reuse a stale profile-mode editor cache entry.
245
178
  providerConfig: { headers: cleanHeaders(context.settings?.chatNodeHeaders ?? {}) },
246
179
  providerOptions: undefined,
247
- responseFormatParameters: shared.responseFormatParameters,
248
- systemPrompt: shared.systemPrompt,
249
- toolChoice: shared.toolChoice,
180
+ responseFormatParameters: plan.responseFormatParameters,
181
+ systemPrompt: plan.systemPrompt,
182
+ toolChoice: plan.toolChoice,
250
183
  profileChain: profiles,
251
- profileChainUsesArray: Array.isArray(profileInput?.value),
252
184
  });
253
185
  return {
254
186
  runOptions: profileRunOptions,
255
- providerProfile: createRuntimeProviderProfile({
256
- data: firstProfileData,
257
- inputs,
258
- credential: firstProfile.credential,
259
- }),
260
187
  runPipeline: fallbackRunner.run,
261
- functions: shared.functions,
188
+ functions: plan.functions,
262
189
  cacheKey,
263
190
  cachedOutputs,
264
191
  editorCache,
265
192
  shouldAutoContinueToolCalls: !!data.autoContinueToolCalls && data.useToolCalling,
266
193
  maxToolRounds: data.maxToolRounds ?? 3,
267
- profileAttempts: fallbackRunner.attempts,
268
- profileChainUsesArray: Array.isArray(profileInput?.value),
269
- profileChainLength: profiles.length,
194
+ outputLLMAttempts: data.outputLLMAttempts === true,
270
195
  getProfileSummary: fallbackRunner.summary,
271
196
  isProfileFallbackExhausted: fallbackRunner.wasExhausted,
272
197
  };
273
198
  }
199
+ function getEligibleEditorCache(data, context) {
200
+ return getLLMChatV2EditorCacheEligibility(data).eligible ? context.editorExecutionCache : undefined;
201
+ }
@@ -0,0 +1,60 @@
1
+ import { delegateToolCall } from '../nodes/toolCallDelegation.js';
2
+ import { runChatV2PipelineWithToolContinuation } from './toolContinuation.js';
3
+ import { isChatV2PipelineProviderFailureResult } from './chatV2Pipeline.js';
4
+ /**
5
+ * Owns the LLM-level recovery and continuation decision boundary. The node
6
+ * boundary provides a resolved runtime and GraphProcessor supplies only the
7
+ * connected Delegate host; no graph scheduling policy lives here.
8
+ */
9
+ export async function executeLLMInvocation(params) {
10
+ const { context, journal, runtime, toolCallContinuation } = params;
11
+ try {
12
+ const result = runtime.shouldAutoContinueToolCalls
13
+ ? await runChatV2PipelineWithToolContinuation({
14
+ ...runtime.runOptions,
15
+ autoContinue: true,
16
+ maxToolRounds: runtime.maxToolRounds,
17
+ functions: runtime.functions,
18
+ delegateToolCallRound: toolCallContinuation
19
+ ? async (toolCalls, preToolMessage) => {
20
+ const results = await toolCallContinuation.run(toolCalls, preToolMessage);
21
+ journal.recordToolRound({ kind: 'connected', count: results.length });
22
+ return results.map((entry) => ({
23
+ type: 'chat-message',
24
+ value: entry.message,
25
+ delegatedToolCall: entry.record,
26
+ }));
27
+ }
28
+ : undefined,
29
+ delegateToolCall: async (toolCall) => {
30
+ const delegated = await delegateToolCall(toolCall, context, {
31
+ handlers: [],
32
+ unknownHandler: undefined,
33
+ autoDelegate: true,
34
+ fallBackToExternalCall: true,
35
+ passthroughErrors: true,
36
+ });
37
+ journal.recordToolRound({ kind: 'internal', count: 1 });
38
+ return {
39
+ type: 'chat-message',
40
+ value: delegated.message,
41
+ delegatedToolCall: delegated.record,
42
+ };
43
+ },
44
+ runPipeline: runtime.runPipeline,
45
+ })
46
+ : await runtime.runPipeline(runtime.runOptions);
47
+ journal.recordTerminal({
48
+ kind: isChatV2PipelineProviderFailureResult(result)
49
+ ? 'failed'
50
+ : result.functionCalls.length > 0
51
+ ? 'released-unresolved-calls'
52
+ : 'final-model-answer',
53
+ });
54
+ return result;
55
+ }
56
+ catch (error) {
57
+ journal.recordTerminal({ kind: context.signal.aborted ? 'cancelled' : 'failed' });
58
+ throw error;
59
+ }
60
+ }
@@ -0,0 +1,11 @@
1
+ /** Pure terminal/continuation policy, intentionally independent of scheduling. */
2
+ export function decideLLMInvocationRound(params) {
3
+ if (params.calls.length === 0)
4
+ return { kind: 'final-model-answer' };
5
+ if (!params.autoContinue || !params.calls.every((call) => params.knownToolNames.has(call.name))) {
6
+ return { kind: 'release-unresolved-calls' };
7
+ }
8
+ if (params.completedRounds >= params.maxToolRounds)
9
+ return { kind: 'max-rounds-reached' };
10
+ return params.isDirectReturn ? { kind: 'direct-tool-response' } : { kind: 'delegate-tools' };
11
+ }