@valerypopoff/rivet2-core 2.1.10 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/bundle.cjs +2101 -867
  3. package/dist/cjs/bundle.cjs.map +4 -4
  4. package/dist/cjs/webAppRuntime.cjs +37 -3
  5. package/dist/cjs/webAppRuntime.cjs.map +2 -2
  6. package/dist/esm/api/createProcessor.js +2 -0
  7. package/dist/esm/integrations/CodeRunner.js +2 -7
  8. package/dist/esm/integrations/CodeRunnerOptions.js +7 -0
  9. package/dist/esm/model/AgentResponseTrace.js +121 -11
  10. package/dist/esm/model/GraphProcessor.js +14 -0
  11. package/dist/esm/model/RecordingPlayer.js +50 -5
  12. package/dist/esm/model/SubprocessorBridge.js +1 -0
  13. package/dist/esm/model/UiGraphActionProtocol.js +1 -0
  14. package/dist/esm/model/chat-v2/aiSdkBridge.js +146 -14
  15. package/dist/esm/model/chat-v2/chatV2CallObserver.js +2 -0
  16. package/dist/esm/model/chat-v2/chatV2CredentialNames.js +93 -0
  17. package/dist/esm/model/chat-v2/chatV2EditorCache.js +6 -5
  18. package/dist/esm/model/chat-v2/chatV2Pipeline.js +41 -4
  19. package/dist/esm/model/chat-v2/chatV2ProviderProfile.js +31 -2
  20. package/dist/esm/model/chat-v2/chatV2ResponseBodyCapture.js +10 -2
  21. package/dist/esm/model/chat-v2/chatV2RuntimeOptions.js +6 -11
  22. package/dist/esm/model/chat-v2/chatV2Shared.js +1 -1
  23. package/dist/esm/model/chat-v2/chatV2Types.js +16 -0
  24. package/dist/esm/model/chat-v2/customProviderApi.js +0 -2
  25. package/dist/esm/model/chat-v2/index.js +3 -0
  26. package/dist/esm/model/chat-v2/llmChatV2Body.js +9 -1
  27. package/dist/esm/model/chat-v2/llmChatV2CachePolicy.js +5 -0
  28. package/dist/esm/model/chat-v2/llmChatV2NodeData.js +7 -0
  29. package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +95 -14
  30. package/dist/esm/model/chat-v2/llmChatV2NodeRuntime.js +32 -9
  31. package/dist/esm/model/chat-v2/llmModelCandidate.js +5 -1
  32. package/dist/esm/model/chat-v2/llmProfile.js +42 -0
  33. package/dist/esm/model/chat-v2/llmProfileBody.js +10 -0
  34. package/dist/esm/model/chat-v2/llmProfileFallback.js +390 -4
  35. package/dist/esm/model/chat-v2/llmProfileFieldRegistry.js +7 -0
  36. package/dist/esm/model/chat-v2/llmProfileHealthStore.js +326 -0
  37. package/dist/esm/model/chat-v2/llmProfileNodeRuntime.js +53 -34
  38. package/dist/esm/model/chat-v2/providerOptions.js +33 -7
  39. package/dist/esm/model/nodes/CodeNewNode.js +5 -47
  40. package/dist/esm/model/nodes/CodeNode.js +4 -46
  41. package/dist/esm/model/nodes/ExpressionNode.js +5 -8
  42. package/dist/esm/model/nodes/LLMChatV2Node.js +10 -1
  43. package/dist/esm/model/nodes/MatchNode.js +86 -41
  44. package/dist/esm/plugins/gentrace/gentraceSdk.js +0 -1
  45. package/dist/esm/plugins/gentrace/index.js +0 -1
  46. package/dist/esm/plugins/gentrace/plugin.js +61 -179
  47. package/dist/esm/plugins.js +1 -2
  48. package/dist/esm/recording/ExecutionRecorder.js +49 -8
  49. package/dist/types/api/createProcessor.d.ts +3 -0
  50. package/dist/types/integrations/CodeRunner.d.ts +10 -7
  51. package/dist/types/integrations/CodeRunnerOptions.d.ts +15 -0
  52. package/dist/types/model/AgentResponseTrace.d.ts +14 -1
  53. package/dist/types/model/EditorDefinition.d.ts +16 -0
  54. package/dist/types/model/ExecutorProtocol.d.ts +9 -6
  55. package/dist/types/model/GraphProcessor.d.ts +15 -5
  56. package/dist/types/model/NodeBase.d.ts +0 -10
  57. package/dist/types/model/Nodes.d.ts +2 -2
  58. package/dist/types/model/ProcessContext.d.ts +52 -0
  59. package/dist/types/model/UiGraphActionProtocol.d.ts +1 -0
  60. package/dist/types/model/chat-v2/chatV2CredentialNames.d.ts +30 -0
  61. package/dist/types/model/chat-v2/chatV2EditorCache.d.ts +1 -0
  62. package/dist/types/model/chat-v2/chatV2ProviderProfile.d.ts +3 -0
  63. package/dist/types/model/chat-v2/chatV2ResponseBodyCapture.d.ts +8 -2
  64. package/dist/types/model/chat-v2/chatV2RuntimeOptions.d.ts +3 -8
  65. package/dist/types/model/chat-v2/chatV2Types.d.ts +24 -0
  66. package/dist/types/model/chat-v2/customProviderApi.d.ts +0 -1
  67. package/dist/types/model/chat-v2/index.d.ts +3 -0
  68. package/dist/types/model/chat-v2/llmChatV2CachePolicy.d.ts +1 -1
  69. package/dist/types/model/chat-v2/llmChatV2NodeData.d.ts +10 -1
  70. package/dist/types/model/chat-v2/llmModelCandidate.d.ts +2 -0
  71. package/dist/types/model/chat-v2/llmProfile.d.ts +14 -0
  72. package/dist/types/model/chat-v2/llmProfileBody.d.ts +1 -1
  73. package/dist/types/model/chat-v2/llmProfileFallback.d.ts +21 -2
  74. package/dist/types/model/chat-v2/llmProfileFieldRegistry.d.ts +26 -6
  75. package/dist/types/model/chat-v2/llmProfileHealthStore.d.ts +111 -0
  76. package/dist/types/model/chat-v2/llmProfileNodeRuntime.d.ts +1 -1
  77. package/dist/types/model/chat-v2/llmProfileTypes.d.ts +3 -0
  78. package/dist/types/model/chat-v2/providerOptions.d.ts +2 -0
  79. package/dist/types/model/nodes/CodeNewNode.d.ts +0 -5
  80. package/dist/types/model/nodes/CodeNode.d.ts +0 -5
  81. package/dist/types/model/nodes/MatchNode.d.ts +6 -0
  82. package/dist/types/plugins/gentrace/gentraceSdk.d.ts +0 -1
  83. package/dist/types/plugins/gentrace/plugin.d.ts +55 -9
  84. package/dist/types/plugins.d.ts +1 -1
  85. package/dist/types/recording/ExecutionRecorder.d.ts +7 -1
  86. package/package.json +2 -2
@@ -1,4 +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 { getNonDefaultChatV2CredentialNames } from './chatV2CredentialNames.js';
2
3
  import { getChatV2ModelInfo } from './modelRegistry.js';
3
4
  import { anthropicCacheControlTtlOptions, anthropicEffortOptions, anthropicThinkingModeOptions, getChatV2ProviderLabel, getCustomProviderApiContract, googleThinkingLevelOptions, openAIReasoningEffortOptions, openAIWebSearchContextSizeOptions, } from './providerOptions.js';
4
5
  function getOptionLabel(options, value) {
@@ -171,7 +172,7 @@ function getToolBodyFields(data) {
171
172
  }
172
173
  function getBehaviorBodyFields(data) {
173
174
  return [
174
- ...(data.useAsGraphPartialOutput === false ? [{ label: 'Stream response', value: 'Disabled' }] : []),
175
+ ...(data.useAsGraphPartialOutput ? [{ label: 'Stream response', value: 'Enabled' }] : []),
175
176
  ...(data.cache ? [{ label: 'Editor cache (legacy)', value: 'Enabled' }] : []),
176
177
  ];
177
178
  }
@@ -204,12 +205,19 @@ function getAdvancedBodySection(data) {
204
205
  }
205
206
  function getInlineModelBodyFields(data) {
206
207
  const customBaseURL = getCustomProviderBaseURLBodyValue(data);
208
+ const credentialNames = getNonDefaultChatV2CredentialNames(data.provider, data.providerApiKeyNames);
207
209
  return [
208
210
  { label: 'Provider', value: getProviderBodyLabel(data) },
209
211
  getCustomProviderApiBodyField(data),
210
212
  customBaseURL ? { label: 'Base URL', value: customBaseURL } : undefined,
211
213
  { label: 'Model', value: getModelBodyValue(data) },
212
214
  ...(data.apiKeySource === 'input' ? [{ label: 'API key source', value: 'Input port' }] : []),
215
+ ...(credentialNames != null && data.apiKeySource !== 'input'
216
+ ? [
217
+ { label: 'Programmatic API key name', value: credentialNames.programmaticName },
218
+ { label: 'API key environment variable', value: credentialNames.environmentVariableName },
219
+ ]
220
+ : []),
213
221
  ...(data.provider === 'custom' && data.apiKeySource !== 'input'
214
222
  ? [
215
223
  data.customProviderApiKeyProgrammaticName?.trim()
@@ -7,6 +7,11 @@ export function getLLMChatV2EditorCacheEligibility(data) {
7
7
  if (!data.cache) {
8
8
  return { eligible: false, reason: 'disabled' };
9
9
  }
10
+ if (data.enableCircuitBreaker === true) {
11
+ // Cross-run provider health is mutable external state. Replaying a cached
12
+ // response would bypass the health gate and make recovery diagnostics lie.
13
+ return { eligible: false, reason: 'circuit-breaker' };
14
+ }
10
15
  if (data.useToolCalling) {
11
16
  return { eligible: false, reason: 'rivet-tools' };
12
17
  }
@@ -1,6 +1,7 @@
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
3
  import { llmProfileDataKeys } from './llmProfileFieldRegistry.js';
4
+ import { DEFAULT_LLM_PROFILE_CIRCUIT_FAILURE_THRESHOLD, DEFAULT_LLM_PROFILE_CIRCUIT_FAILURE_WINDOW_MS, DEFAULT_LLM_PROFILE_CIRCUIT_OPEN_DURATION_MS, DEFAULT_LLM_PROFILE_FIRST_OUTPUT_TIMEOUT_MS, DEFAULT_LLM_PROFILE_STREAM_INACTIVITY_TIMEOUT_MS, } from './llmProfileHealthStore.js';
4
5
  /** @deprecated Use llmProfileDataKeys from llmProfileFieldRegistry instead. */
5
6
  export const llmChatV2ProfileDataKeys = llmProfileDataKeys;
6
7
  export function createLLMChatV2NodeData() {
@@ -40,6 +41,12 @@ export function createLLMChatV2NodeData() {
40
41
  googleIncludeThoughts: false,
41
42
  enableGoogleSearchGrounding: false,
42
43
  enableGoogleUrlContext: false,
44
+ enableCircuitBreaker: false,
45
+ firstOutputTimeoutMs: DEFAULT_LLM_PROFILE_FIRST_OUTPUT_TIMEOUT_MS,
46
+ streamInactivityTimeoutMs: DEFAULT_LLM_PROFILE_STREAM_INACTIVITY_TIMEOUT_MS,
47
+ circuitBreakerFailureThreshold: DEFAULT_LLM_PROFILE_CIRCUIT_FAILURE_THRESHOLD,
48
+ circuitBreakerFailureWindowMs: DEFAULT_LLM_PROFILE_CIRCUIT_FAILURE_WINDOW_MS,
49
+ circuitBreakerOpenDurationMs: DEFAULT_LLM_PROFILE_CIRCUIT_OPEN_DURATION_MS,
43
50
  responseFormat: '',
44
51
  responseSchemaName: '',
45
52
  useResponseSchemaNameInput: false,
@@ -1,6 +1,8 @@
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
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
+ import { DEFAULT_LLM_PROFILE_CIRCUIT_FAILURE_THRESHOLD, DEFAULT_LLM_PROFILE_CIRCUIT_FAILURE_WINDOW_MS, DEFAULT_LLM_PROFILE_CIRCUIT_OPEN_DURATION_MS, DEFAULT_LLM_PROFILE_FIRST_OUTPUT_TIMEOUT_MS, DEFAULT_LLM_PROFILE_STREAM_INACTIVITY_TIMEOUT_MS, } from './llmProfileHealthStore.js';
5
+ import { getChatV2CredentialNamesForDisplay, isChatV2BuiltInProvider } from './chatV2CredentialNames.js';
4
6
  const hideUnlessProvider = (provider) => (data) => data.provider !== provider;
5
7
  function group(label, editors, defaultOpen) {
6
8
  return {
@@ -33,11 +35,14 @@ function getApiKeySourceHelperMessage(data) {
33
35
  }
34
36
  switch (data.provider) {
35
37
  case 'openai':
36
- return 'Configured key uses Settings > LLM > OpenAI API Key in the Rivet editor, with OPENAI_API_KEY as a desktop/Node fallback. Programmatic runs can pass openAiApiKey or set OPENAI_API_KEY.';
37
38
  case 'anthropic':
38
- return 'Configured key uses Settings > LLM > Anthropic API Key in the Rivet editor, with ANTHROPIC_API_KEY as a desktop/Node fallback. Programmatic runs can pass anthropicApiKey or set ANTHROPIC_API_KEY.';
39
- case 'google':
40
- return 'Configured key uses Settings > LLM > Google API Key in the Rivet editor, with GOOGLE_GENERATIVE_AI_API_KEY as a desktop/Node fallback. Programmatic runs can pass googleApiKey or set GOOGLE_GENERATIVE_AI_API_KEY.';
39
+ case 'google': {
40
+ const names = getChatV2CredentialNamesForDisplay(data.provider, data.providerApiKeyNames?.[data.provider]);
41
+ const hasOverride = data.providerApiKeyNames?.[data.provider] != null;
42
+ return hasOverride
43
+ ? `Configured key checks ${names.programmaticName} first, then ${names.environmentVariableName}. This explicit override does not fall back to the shared provider key.`
44
+ : `Configured key uses ${names.programmaticName} or ${names.environmentVariableName}, including the existing Settings > LLM provider key.`;
45
+ }
41
46
  case 'custom': {
42
47
  const programmaticName = data.customProviderApiKeyProgrammaticName?.trim();
43
48
  const envVarName = data.customProviderApiKeyEnvVarName?.trim() || 'CUSTOM_PROVIDER_API_KEY';
@@ -93,6 +98,12 @@ function getModelEditors(modelOptions) {
93
98
  ],
94
99
  helperMessage: getApiKeySourceHelperMessage,
95
100
  },
101
+ {
102
+ type: 'custom',
103
+ label: 'Configured API key names',
104
+ customEditorId: 'LLMChatV2CredentialNames',
105
+ hideIf: (data) => !isChatV2BuiltInProvider(data.provider) || data.apiKeySource === 'input',
106
+ },
96
107
  {
97
108
  type: 'string',
98
109
  label: 'Alternative programmatic key name',
@@ -114,6 +125,75 @@ function getModelEditors(modelOptions) {
114
125
  function getProviderEditors() {
115
126
  return [getOpenAIProviderEditors(), getAnthropicProviderEditors(), getGoogleProviderEditors()];
116
127
  }
128
+ function getCircuitBreakerEditors() {
129
+ return group('LLM profile suspension', [
130
+ {
131
+ type: 'info',
132
+ label: "It's a hosted runtime capability",
133
+ helperMessage: 'This configuration is enforced by Rivet Studio Server or another host that explicitly provides shared LLM profile reliability. It has no effect in standalone Rivet.',
134
+ },
135
+ {
136
+ type: 'toggle',
137
+ label: 'Enable automatic suspension',
138
+ dataKey: 'enableCircuitBreaker',
139
+ helperMessage: 'After provider failures or timeouts, temporarily suspend this profile in the LLM profiles fallback chain. When the suspension ends, one recovery attempt checks whether the profile can resume.',
140
+ },
141
+ {
142
+ type: 'number',
143
+ label: 'Useful output wait time, seconds',
144
+ dataKey: 'firstOutputTimeoutMs',
145
+ defaultValue: DEFAULT_LLM_PROFILE_FIRST_OUTPUT_TIMEOUT_MS,
146
+ storageMultiplier: 1_000,
147
+ min: 1_000,
148
+ step: 1_000,
149
+ helperMessage: 'Maximum wait time for a non-stream response (or the first useful streamed output). A call that reaches this deadline falls back immediately, even before this profile is suspended.',
150
+ hideIf: (data) => data.enableCircuitBreaker !== true,
151
+ },
152
+ {
153
+ type: 'number',
154
+ label: 'Stream inactivity timeout, seconds',
155
+ dataKey: 'streamInactivityTimeoutMs',
156
+ defaultValue: DEFAULT_LLM_PROFILE_STREAM_INACTIVITY_TIMEOUT_MS,
157
+ storageMultiplier: 1_000,
158
+ min: 1_000,
159
+ step: 1_000,
160
+ helperMessage: 'Maximum gap between streamed response events before falling back.',
161
+ hideIf: (data) => data.enableCircuitBreaker !== true,
162
+ },
163
+ {
164
+ type: 'number',
165
+ label: 'Failures before suspension',
166
+ dataKey: 'circuitBreakerFailureThreshold',
167
+ defaultValue: DEFAULT_LLM_PROFILE_CIRCUIT_FAILURE_THRESHOLD,
168
+ min: 1,
169
+ step: 1,
170
+ helperMessage: 'Failed or timed-out profile attempts required within the failure window before suspending this profile.',
171
+ hideIf: (data) => data.enableCircuitBreaker !== true,
172
+ },
173
+ {
174
+ type: 'number',
175
+ label: 'Failure window, seconds',
176
+ dataKey: 'circuitBreakerFailureWindowMs',
177
+ defaultValue: DEFAULT_LLM_PROFILE_CIRCUIT_FAILURE_WINDOW_MS,
178
+ storageMultiplier: 1_000,
179
+ min: 1_000,
180
+ step: 1_000,
181
+ helperMessage: 'Failed or timed-out profile attempts inside this rolling window count toward suspension.',
182
+ hideIf: (data) => data.enableCircuitBreaker !== true,
183
+ },
184
+ {
185
+ type: 'number',
186
+ label: 'Suspension duration, seconds',
187
+ dataKey: 'circuitBreakerOpenDurationMs',
188
+ defaultValue: DEFAULT_LLM_PROFILE_CIRCUIT_OPEN_DURATION_MS,
189
+ storageMultiplier: 1_000,
190
+ min: 1_000,
191
+ step: 1_000,
192
+ helperMessage: 'How long the fallback chain skips this profile before allowing one recovery attempt.',
193
+ hideIf: (data) => data.enableCircuitBreaker !== true,
194
+ },
195
+ ]);
196
+ }
117
197
  function getOpenAIProviderEditors() {
118
198
  return providerGroup('openai', 'OpenAI', [
119
199
  {
@@ -318,8 +398,8 @@ function getReasoningEditors() {
318
398
  },
319
399
  ]);
320
400
  }
321
- function getResponseFormatEditors() {
322
- return group('Response format', [
401
+ function getResponseSettingsEditors() {
402
+ return group('Response settings', [
323
403
  {
324
404
  type: 'dropdown',
325
405
  label: 'Response format',
@@ -333,6 +413,12 @@ function getResponseFormatEditors() {
333
413
  defaultValue: '',
334
414
  helperMessage: 'Uses Vercel AI SDK structured-output response formatting when supported by the provider. JSON schema adds a Response Schema input port.',
335
415
  },
416
+ {
417
+ type: 'toggle',
418
+ label: 'Stream response',
419
+ dataKey: 'useAsGraphPartialOutput',
420
+ helperMessage: 'Shows streamed response updates in the node output while running in the editor. Other nodes only receive the final response after it is complete.',
421
+ },
336
422
  {
337
423
  type: 'string',
338
424
  label: 'Schema name',
@@ -440,12 +526,6 @@ function getOutputEditors() {
440
526
  dataKey: 'outputResponseBody',
441
527
  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
528
  },
443
- {
444
- type: 'toggle',
445
- label: 'Stream response',
446
- dataKey: 'useAsGraphPartialOutput',
447
- helperMessage: 'Shows streamed response updates in the node output while running in the editor. Other nodes only receive the final response after it is complete.',
448
- },
449
529
  {
450
530
  type: 'toggle',
451
531
  label: 'Cache outputs (editor only) (legacy)',
@@ -471,7 +551,7 @@ function getProviderAdvancedEditors() {
471
551
  dataKey: 'extraProviderOptions',
472
552
  useInputToggleDataKey: 'useExtraProviderOptionsInput',
473
553
  language: 'json',
474
- helperMessage: 'Power-user Vercel providerOptions for the selected provider. Enter a JSON object; visible settings above override conflicting fields.',
554
+ helperMessage: 'Adds these exact top-level JSON fields to the provider request body. Field names are preserved, and these values override generated request fields with the same name.',
475
555
  enableFolding: true,
476
556
  },
477
557
  ]);
@@ -524,7 +604,7 @@ export async function getLLMChatV2Editors(data, context) {
524
604
  ...(data.provider === 'custom' ? [] : [getReasoningEditors()]),
525
605
  ]
526
606
  : []),
527
- getResponseFormatEditors(),
607
+ getResponseSettingsEditors(),
528
608
  getToolEditors(),
529
609
  getOutputEditors(),
530
610
  ...(!usesProfile ? [getProviderAdvancedEditors()] : []),
@@ -538,6 +618,7 @@ export async function getLLMProfileEditors(data, context) {
538
618
  ...getProviderEditors(),
539
619
  getParameterEditors(),
540
620
  ...(profileData.provider === 'custom' ? [] : [getReasoningEditors()]),
621
+ getCircuitBreakerEditors(),
541
622
  getProviderAdvancedEditors(),
542
623
  ];
543
624
  }
@@ -1,6 +1,6 @@
1
1
  import { cleanHeaders } from '../../utils/inputs.js';
2
2
  import { createLLMProfileFallbackRunner, getLLMAttemptErrorMessage } from './llmProfileFallback.js';
3
- import { applyLLMProfileToNodeData, normalizeLLMProfileChainInput } from './llmProfile.js';
3
+ import { applyLLMProfileToNodeData, normalizeLLMProfileChainInput, scopeLLMProfileHealthIdentity, } from './llmProfile.js';
4
4
  import { buildLLMInvocationPlan, buildLLMInvocationRunOptions } from './llmInvocationPlan.js';
5
5
  import { resolveLLMModelCandidate } from './llmModelCandidate.js';
6
6
  import { mergeCustomProviderResponseFormatOptions } from './chatV2ResponseFormat.js';
@@ -11,6 +11,7 @@ import { buildLLMChatV2EditorCacheKey, cloneLLMChatV2EditorCacheOutputs, resolve
11
11
  import { resolveLLMChatV2GenerationParameters, resolveLLMChatV2RuntimeProviderOptions, } from './chatV2RuntimeOptions.js';
12
12
  import {} from './llmChatV2NodeData.js';
13
13
  import { isChatV2ResponseValidationError, runChatV2Pipeline } from './chatV2Pipeline.js';
14
+ import { DEFAULT_LLM_PROFILE_FIRST_OUTPUT_TIMEOUT_MS, DEFAULT_LLM_PROFILE_STREAM_INACTIVITY_TIMEOUT_MS, resolveRivetLLMProfileCircuitBreakerPolicy, } from './llmProfileHealthStore.js';
14
15
  export { buildLLMChatV2EditorCacheKey, cloneLLMChatV2EditorCacheOutputs };
15
16
  export { resolveLLMChatV2RuntimeProviderOptions } from './chatV2RuntimeOptions.js';
16
17
  export async function resolveLLMChatV2RuntimeConfig(params) {
@@ -49,6 +50,7 @@ export async function resolveLLMChatV2RuntimeConfig(params) {
49
50
  provider: inlineRunOptions.provider,
50
51
  providerConfig: inlineCandidate.providerConfig,
51
52
  providerOptions: inlineRunOptions.providerOptions,
53
+ requestBodyOverlay: inlineCandidate.requestBodyOverlay,
52
54
  responseFormatParameters: plan.responseFormatParameters,
53
55
  systemPrompt: plan.systemPrompt,
54
56
  toolChoice: plan.toolChoice,
@@ -121,7 +123,13 @@ export async function resolveLLMChatV2RuntimeConfig(params) {
121
123
  isProfileFallbackExhausted: () => false,
122
124
  };
123
125
  }
124
- const profiles = normalizeLLMProfileChainInput(profileInput?.value);
126
+ const profiles = normalizeLLMProfileChainInput(profileInput?.value).map((profile) => profile.configuration.enableCircuitBreaker !== true
127
+ ? profile
128
+ : scopeLLMProfileHealthIdentity(profile, {
129
+ projectId: context.project.metadata.id,
130
+ profileNodeId: nodeId,
131
+ chatNodeHeaders: context.settings.chatNodeHeaders,
132
+ }));
125
133
  // Profile-owned provider-native capabilities are resolved only after the
126
134
  // input profile is normalized. One cache entry covers the complete fallback
127
135
  // chain, so every possible candidate must be replay-safe.
@@ -147,19 +155,33 @@ export async function resolveLLMChatV2RuntimeConfig(params) {
147
155
  anthropicCacheControlTtl: firstProvider === 'anthropic' ? firstProfileData.anthropicCacheControlTtl || undefined : undefined,
148
156
  });
149
157
  const fallbackRunner = createLLMProfileFallbackRunner({
150
- candidates: profiles.map((profile) => ({
151
- provider: parseChatV2Provider(profile.configuration.provider),
152
- model: profile.configuration.model,
153
- ...(profile.configuration.provider === 'custom'
154
- ? { customProviderApi: parseCustomProviderApi(profile.configuration.customProviderApi) }
155
- : {}),
156
- })),
158
+ candidates: profiles.map((profile) => {
159
+ const policy = resolveRivetLLMProfileCircuitBreakerPolicy(profile.configuration);
160
+ return {
161
+ provider: parseChatV2Provider(profile.configuration.provider),
162
+ model: profile.configuration.model,
163
+ ...(profile.configuration.provider === 'custom'
164
+ ? { customProviderApi: parseCustomProviderApi(profile.configuration.customProviderApi) }
165
+ : {}),
166
+ ...(policy == null
167
+ ? {}
168
+ : {
169
+ health: {
170
+ identity: profile.healthIdentity,
171
+ policy,
172
+ firstOutputTimeoutMs: profile.configuration.firstOutputTimeoutMs ?? DEFAULT_LLM_PROFILE_FIRST_OUTPUT_TIMEOUT_MS,
173
+ streamInactivityTimeoutMs: profile.configuration.streamInactivityTimeoutMs ?? DEFAULT_LLM_PROFILE_STREAM_INACTIVITY_TIMEOUT_MS,
174
+ },
175
+ }),
176
+ };
177
+ }),
157
178
  resolveCandidate: (profileIndex, roundOptions) => resolveLLMModelCandidate({
158
179
  plan,
159
180
  profile: profiles[profileIndex],
160
181
  roundOptions,
161
182
  }).then((candidate) => candidate.runOptions),
162
183
  onAttempt: params.onLLMAttempt,
184
+ healthStore: context.llmProfileHealthStore,
163
185
  });
164
186
  const { cacheKey, cachedOutputs } = resolveLLMChatV2EditorCache({
165
187
  apiKey: undefined,
@@ -177,6 +199,7 @@ export async function resolveLLMChatV2RuntimeConfig(params) {
177
199
  // global-header edit cannot reuse a stale profile-mode editor cache entry.
178
200
  providerConfig: { headers: cleanHeaders(context.settings?.chatNodeHeaders ?? {}) },
179
201
  providerOptions: undefined,
202
+ requestBodyOverlay: undefined,
180
203
  responseFormatParameters: plan.responseFormatParameters,
181
204
  systemPrompt: plan.systemPrompt,
182
205
  toolChoice: plan.toolChoice,
@@ -3,7 +3,7 @@ import { hasLLMChatV2ToolResponseFormatConflict, LLM_CHAT_V2_TOOL_RESPONSE_FORMA
3
3
  import { buildLLMInvocationRunOptions, resolveLLMChatV2BaseURL } from './llmInvocationPlan.js';
4
4
  import { applyLLMProfileToNodeData } from './llmProfile.js';
5
5
  import { createResolvedChatV2Provider, resolveChatV2Credential, } from './chatV2ProviderProfile.js';
6
- import { resolveLLMChatV2BuiltInTools, resolveLLMChatV2GenerationParameters, resolveLLMChatV2Headers, resolveLLMChatV2RuntimeProviderOptions, } from './chatV2RuntimeOptions.js';
6
+ import { resolveLLMChatV2BuiltInTools, resolveLLMChatV2ExtraProviderOptions, resolveLLMChatV2GenerationParameters, resolveLLMChatV2Headers, resolveLLMChatV2RuntimeProviderOptions, } from './chatV2RuntimeOptions.js';
7
7
  import { createChatV2ResponseOutput, mergeCustomProviderResponseFormatOptions } from './chatV2ResponseFormat.js';
8
8
  import { parseCustomProviderApi } from './customProviderApi.js';
9
9
  import { parseChatV2Provider } from './providerOptions.js';
@@ -19,12 +19,14 @@ export async function resolveLLMModelCandidate(params) {
19
19
  const modelId = getInputOrData(effectiveData, plan.inputs, 'model', 'string');
20
20
  const baseURL = resolveLLMChatV2BaseURL(effectiveData, plan.inputs);
21
21
  const headers = resolveLLMChatV2Headers(effectiveData, plan.inputs);
22
+ const requestBodyOverlay = resolveLLMChatV2ExtraProviderOptions(effectiveData, plan.inputs);
22
23
  const credential = profile?.credential ??
23
24
  resolveChatV2Credential({
24
25
  provider,
25
26
  context: plan.context,
26
27
  apiKeySource: effectiveData.apiKeySource === 'input' ? 'input' : 'configured',
27
28
  inputs: plan.inputs,
29
+ providerApiKeyNames: effectiveData.providerApiKeyNames,
28
30
  customProgrammaticName: effectiveData.customProviderApiKeyProgrammaticName,
29
31
  customEnvironmentName: effectiveData.customProviderApiKeyEnvVarName,
30
32
  });
@@ -41,6 +43,7 @@ export async function resolveLLMModelCandidate(params) {
41
43
  onRequestBody: plan.requestBodies == null ? undefined : (body) => plan.requestBodies.push(body),
42
44
  onResponseBody: plan.responseBodyCapture == null ? undefined : (response) => plan.responseBodyCapture.capture(response),
43
45
  transformRequestBody,
46
+ requestBodyOverlay,
44
47
  customProviderApi,
45
48
  });
46
49
  const generationParameters = resolveLLMChatV2GenerationParameters(effectiveData, plan.inputs);
@@ -55,6 +58,7 @@ export async function resolveLLMModelCandidate(params) {
55
58
  effectiveData,
56
59
  credential,
57
60
  providerConfig: resolvedProvider.config,
61
+ requestBodyOverlay,
58
62
  runOptions: {
59
63
  ...baseRunOptions,
60
64
  provider,
@@ -2,6 +2,8 @@ import { createLLMChatV2NodeData } from './llmChatV2NodeData.js';
2
2
  import { parseCustomProviderApi } from './customProviderApi.js';
3
3
  import { llmProfileBooleanDataKeys, llmProfileOptionalNumberDataKeys, llmProfileRequiredNumberDataKeys, llmProfileResolvedInputToggleDataKeys, llmProfileStringDataKeys, } from './llmProfileFieldRegistry.js';
4
4
  import { LLM_PROFILE_VALUE_VERSION, pickLLMChatV2ProfileData } from './llmProfileTypes.js';
5
+ import { createRivetLLMProfileHealthIdentity } from './llmProfileHealthStore.js';
6
+ import { normalizeChatV2CredentialNamesByProvider } from './chatV2CredentialNames.js';
5
7
  export { applyLLMProfileToNodeData, createDefaultLLMProfileValue, createLLMProfileNodeData, LLM_PROFILE_VALUE_VERSION, pickLLMChatV2ProfileData, } from './llmProfileTypes.js';
6
8
  const credentialSources = new Set([
7
9
  'input',
@@ -35,10 +37,16 @@ export function normalizeLLMProfileValue(value) {
35
37
  provider,
36
38
  model: model.trim(),
37
39
  });
40
+ const sourceIdentity = normalizeSourceIdentity(value.healthIdentity);
38
41
  return {
39
42
  version: LLM_PROFILE_VALUE_VERSION,
40
43
  configuration,
41
44
  credential,
45
+ healthIdentity: createRivetLLMProfileHealthIdentity({
46
+ configuration,
47
+ credential,
48
+ ...sourceIdentity,
49
+ }),
42
50
  };
43
51
  }
44
52
  /**
@@ -62,6 +70,30 @@ export function normalizeLLMProfileChainInput(value) {
62
70
  }
63
71
  });
64
72
  }
73
+ /**
74
+ * Programmatic or serialized llm-config values may originate outside the
75
+ * currently executing project. Always bind health to that project before
76
+ * shared storage is consulted so copied values cannot share a circuit across
77
+ * projects. Preserve an originating profile-node identity when one exists;
78
+ * otherwise the consuming Chat node owns the identity.
79
+ */
80
+ export function scopeLLMProfileHealthIdentity(profile, fallback) {
81
+ const profileNodeId = profile.healthIdentity?.profileNodeId ?? fallback.profileNodeId;
82
+ const healthIdentity = createRivetLLMProfileHealthIdentity({
83
+ configuration: profile.configuration,
84
+ credential: profile.credential,
85
+ chatNodeHeaders: fallback.chatNodeHeaders,
86
+ projectId: fallback.projectId,
87
+ profileNodeId,
88
+ });
89
+ if (profile.healthIdentity?.key === healthIdentity.key) {
90
+ return profile;
91
+ }
92
+ return {
93
+ ...profile,
94
+ healthIdentity,
95
+ };
96
+ }
65
97
  function normalizeConfiguration(data) {
66
98
  for (const field of llmProfileStringDataKeys) {
67
99
  if (typeof data[field] !== 'string') {
@@ -103,6 +135,7 @@ function normalizeConfiguration(data) {
103
135
  const resolvedData = {
104
136
  ...data,
105
137
  customProviderApi,
138
+ providerApiKeyNames: normalizeChatV2CredentialNamesByProvider(data.providerApiKeyNames),
106
139
  model: data.model.trim(),
107
140
  customProviderBaseURL: data.customProviderBaseURL.trim(),
108
141
  customProviderApiKeyProgrammaticName: data.customProviderApiKeyProgrammaticName?.trim(),
@@ -152,6 +185,15 @@ function normalizeCredential(value) {
152
185
  },
153
186
  };
154
187
  }
188
+ function normalizeSourceIdentity(value) {
189
+ if (!isRecord(value)) {
190
+ return {};
191
+ }
192
+ return {
193
+ ...(typeof value.projectId === 'string' ? { projectId: value.projectId } : {}),
194
+ ...(typeof value.profileNodeId === 'string' ? { profileNodeId: value.profileNodeId } : {}),
195
+ };
196
+ }
155
197
  function isRecord(value) {
156
198
  return typeof value === 'object' && value != null && !Array.isArray(value);
157
199
  }
@@ -1,3 +1,4 @@
1
+ import { getNonDefaultChatV2CredentialNames } from './chatV2CredentialNames.js';
1
2
  import { getChatV2ModelInfo } from './modelRegistry.js';
2
3
  import { anthropicCacheControlTtlOptions, anthropicEffortOptions, anthropicThinkingModeOptions, getChatV2ProviderLabel, getCustomProviderApiContract, googleThinkingLevelOptions, openAIReasoningEffortOptions, openAIWebSearchContextSizeOptions, } from './providerOptions.js';
3
4
  function getOptionLabel(options, value) {
@@ -127,6 +128,7 @@ function getStopSequencesBodyField(data) {
127
128
  * in the node data and therefore cannot be rendered here.
128
129
  */
129
130
  export function getLLMProfileBodySections(data) {
131
+ const credentialNames = getNonDefaultChatV2CredentialNames(data.provider, data.providerApiKeyNames);
130
132
  const modelFields = [
131
133
  {
132
134
  label: 'Provider',
@@ -139,6 +141,12 @@ export function getLLMProfileBodySections(data) {
139
141
  : []),
140
142
  { label: 'Model', value: getModelBodyLabel(data) },
141
143
  { label: 'API key source', value: data.apiKeySource === 'input' ? 'Input port' : 'Configured key' },
144
+ ...(credentialNames != null && data.apiKeySource !== 'input'
145
+ ? [
146
+ { label: 'Programmatic API key name', value: credentialNames.programmaticName },
147
+ { label: 'API key environment variable', value: credentialNames.environmentVariableName },
148
+ ]
149
+ : []),
142
150
  ...(data.provider === 'custom' && data.apiKeySource !== 'input'
143
151
  ? [
144
152
  data.customProviderApiKeyProgrammaticName?.trim()
@@ -169,10 +177,12 @@ export function getLLMProfileBodySections(data) {
169
177
  data.extraProviderOptions.trim().length > 0
170
178
  ? { label: 'Extra provider options', text: data.extraProviderOptions }
171
179
  : undefined;
180
+ const reliabilityFields = data.enableCircuitBreaker === true ? [{ label: 'Automatic suspension', value: 'Configured' }] : [];
172
181
  const sections = [
173
182
  { id: 'model', fields: modelFields.filter((field) => field !== undefined) },
174
183
  { id: 'parameters', fields: parameterFields.filter((field) => field !== undefined) },
175
184
  { id: 'provider', fields: getProviderBodyFields(data) },
185
+ { id: 'reliability', fields: reliabilityFields },
176
186
  {
177
187
  id: 'advanced',
178
188
  fields: advancedFields.filter((field) => field !== undefined),