@valerypopoff/rivet2-core 2.1.9 → 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 (188) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/bundle.cjs +5618 -2533
  3. package/dist/cjs/bundle.cjs.map +4 -4
  4. package/dist/cjs/webAppRuntime.cjs +333 -22
  5. package/dist/cjs/webAppRuntime.cjs.map +4 -4
  6. package/dist/esm/api/createProcessor.js +2 -0
  7. package/dist/esm/exports.js +1 -0
  8. package/dist/esm/integrations/CodeRunner.js +2 -7
  9. package/dist/esm/integrations/CodeRunnerOptions.js +7 -0
  10. package/dist/esm/model/AgentResponseTrace.js +558 -0
  11. package/dist/esm/model/ConnectedToolContinuationHost.js +33 -0
  12. package/dist/esm/model/GraphProcessor.js +165 -74
  13. package/dist/esm/model/NodeImpl.js +6 -0
  14. package/dist/esm/model/ProcessContextBuilder.js +3 -1
  15. package/dist/esm/model/RecordingPlayer.js +212 -25
  16. package/dist/esm/model/SplitRunProcessor.js +49 -8
  17. package/dist/esm/model/SubprocessorBridge.js +3 -0
  18. package/dist/esm/model/ToolCallContinuationCoordinator.js +7 -3
  19. package/dist/esm/model/UiGraph.js +21 -0
  20. package/dist/esm/model/UiGraphActionProtocol.js +3 -0
  21. package/dist/esm/model/UiGraphBrowserRuntime.js +133 -4
  22. package/dist/esm/model/UiGraphRendererStyles.js +221 -0
  23. package/dist/esm/model/UiGraphRuntimeModel.js +9 -3
  24. package/dist/esm/model/UiGraphSchema.js +7 -1
  25. package/dist/esm/model/chat/aiSdkTools.js +3 -2
  26. package/dist/esm/model/chat-v2/aiSdkBridge.js +146 -14
  27. package/dist/esm/model/chat-v2/chatV2CallObserver.js +11 -5
  28. package/dist/esm/model/chat-v2/chatV2CredentialNames.js +93 -0
  29. package/dist/esm/model/chat-v2/chatV2EditorCache.js +47 -20
  30. package/dist/esm/model/chat-v2/chatV2Errors.js +7 -19
  31. package/dist/esm/model/chat-v2/chatV2FeatureCompatibility.js +1 -1
  32. package/dist/esm/model/chat-v2/chatV2Outputs.js +48 -108
  33. package/dist/esm/model/chat-v2/chatV2Pipeline.js +101 -149
  34. package/dist/esm/model/chat-v2/chatV2ProviderProfile.js +39 -4
  35. package/dist/esm/model/chat-v2/chatV2ProviderRegistry.js +9 -0
  36. package/dist/esm/model/chat-v2/chatV2RequestPlan.js +2 -3
  37. package/dist/esm/model/chat-v2/chatV2ResponseBodyCapture.js +63 -0
  38. package/dist/esm/model/chat-v2/chatV2ResponseFormat.js +8 -4
  39. package/dist/esm/model/chat-v2/chatV2Retry.js +4 -3
  40. package/dist/esm/model/chat-v2/chatV2RuntimeOptions.js +7 -7
  41. package/dist/esm/model/chat-v2/chatV2Shared.js +1 -1
  42. package/dist/esm/model/chat-v2/chatV2Types.js +20 -8
  43. package/dist/esm/model/chat-v2/chatV2UsageAccounting.js +78 -0
  44. package/dist/esm/model/chat-v2/customProviderApi.js +40 -0
  45. package/dist/esm/model/chat-v2/index.js +15 -0
  46. package/dist/esm/model/chat-v2/llmChatV2Body.js +289 -0
  47. package/dist/esm/model/chat-v2/llmChatV2CacheBoundary.js +32 -0
  48. package/dist/esm/model/chat-v2/llmChatV2CachePolicy.js +25 -0
  49. package/dist/esm/model/chat-v2/llmChatV2NodeData.js +13 -50
  50. package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +117 -24
  51. package/dist/esm/model/chat-v2/llmChatV2NodeMigration.js +24 -0
  52. package/dist/esm/model/chat-v2/llmChatV2NodeRuntime.js +150 -199
  53. package/dist/esm/model/chat-v2/llmInvocationCoordinator.js +60 -0
  54. package/dist/esm/model/chat-v2/llmInvocationDecision.js +11 -0
  55. package/dist/esm/model/chat-v2/llmInvocationJournal.js +43 -0
  56. package/dist/esm/model/chat-v2/llmInvocationPlan.js +68 -0
  57. package/dist/esm/model/chat-v2/llmInvocationProjections.js +5 -0
  58. package/dist/esm/model/chat-v2/llmInvocationResultProjector.js +48 -0
  59. package/dist/esm/model/chat-v2/llmModelCandidate.js +79 -0
  60. package/dist/esm/model/chat-v2/llmProfile.js +52 -65
  61. package/dist/esm/model/chat-v2/llmProfileBody.js +193 -0
  62. package/dist/esm/model/chat-v2/llmProfileFallback.js +442 -100
  63. package/dist/esm/model/chat-v2/llmProfileFieldRegistry.js +74 -0
  64. package/dist/esm/model/chat-v2/llmProfileHealthStore.js +326 -0
  65. package/dist/esm/model/chat-v2/llmProfileNodeRuntime.js +55 -33
  66. package/dist/esm/model/chat-v2/llmProfileTypes.js +1 -18
  67. package/dist/esm/model/chat-v2/llmResponseMaterializer.js +42 -0
  68. package/dist/esm/model/chat-v2/modelRegistry.js +54 -4
  69. package/dist/esm/model/chat-v2/parallelToolCalls.js +9 -2
  70. package/dist/esm/model/chat-v2/providerOptions.js +116 -24
  71. package/dist/esm/model/chat-v2/rivetToolRegistry.js +9 -0
  72. package/dist/esm/model/chat-v2/toolCallCodec.js +52 -0
  73. package/dist/esm/model/chat-v2/toolContinuation.js +72 -35
  74. package/dist/esm/model/chat-v2/toolHandlerResolver.js +23 -0
  75. package/dist/esm/model/chat-v2/toolRoundExecutor.js +12 -0
  76. package/dist/esm/model/nodes/ChatNode.js +6 -0
  77. package/dist/esm/model/nodes/ChatNodeBase.js +1 -0
  78. package/dist/esm/model/nodes/CodeNewNode.js +5 -47
  79. package/dist/esm/model/nodes/CodeNode.js +4 -46
  80. package/dist/esm/model/nodes/DelegateFunctionCallNode.js +19 -6
  81. package/dist/esm/model/nodes/ExpressionNode.js +5 -8
  82. package/dist/esm/model/nodes/LLMChatV2Node.js +121 -229
  83. package/dist/esm/model/nodes/LLMProfileNode.js +27 -8
  84. package/dist/esm/model/nodes/MatchNode.js +86 -41
  85. package/dist/esm/model/nodes/PromptNode.js +7 -0
  86. package/dist/esm/model/nodes/ToolNode.js +7 -0
  87. package/dist/esm/model/nodes/toolCallDelegation.js +177 -110
  88. package/dist/esm/plugins/anthropic/anthropic.js +4 -4
  89. package/dist/esm/plugins/anthropic/nodes/ChatAnthropicNode.js +7 -0
  90. package/dist/esm/plugins/gentrace/gentraceSdk.js +0 -1
  91. package/dist/esm/plugins/gentrace/index.js +0 -1
  92. package/dist/esm/plugins/gentrace/plugin.js +61 -179
  93. package/dist/esm/plugins/google/google.js +5 -9
  94. package/dist/esm/plugins/google/nodes/ChatGoogleNode.js +4 -1
  95. package/dist/esm/plugins.js +1 -2
  96. package/dist/esm/recording/ExecutionRecorder.js +62 -13
  97. package/dist/esm/utils/emitDetached.js +6 -3
  98. package/dist/esm/utils/openai.js +60 -16
  99. package/dist/esm/utils/serialization/serialization.js +2 -19
  100. package/dist/esm/webAppRuntime.js +3 -2
  101. package/dist/types/api/createProcessor.d.ts +3 -0
  102. package/dist/types/exports.d.ts +1 -0
  103. package/dist/types/integrations/CodeRunner.d.ts +10 -7
  104. package/dist/types/integrations/CodeRunnerOptions.d.ts +15 -0
  105. package/dist/types/model/AgentResponseTrace.d.ts +123 -0
  106. package/dist/types/model/ConnectedToolContinuationHost.d.ts +34 -0
  107. package/dist/types/model/EditorDefinition.d.ts +16 -0
  108. package/dist/types/model/ExecutorProtocol.d.ts +32 -11
  109. package/dist/types/model/GraphProcessor.d.ts +41 -9
  110. package/dist/types/model/NodeBase.d.ts +0 -10
  111. package/dist/types/model/NodeImpl.d.ts +18 -1
  112. package/dist/types/model/Nodes.d.ts +2 -2
  113. package/dist/types/model/ProcessContext.d.ts +99 -0
  114. package/dist/types/model/ProcessContextBuilder.d.ts +3 -1
  115. package/dist/types/model/RecordingPlayer.d.ts +6 -0
  116. package/dist/types/model/SplitRunProcessor.d.ts +10 -3
  117. package/dist/types/model/UiGraph.d.ts +8 -0
  118. package/dist/types/model/UiGraphActionProtocol.d.ts +3 -0
  119. package/dist/types/model/UiGraphBrowserRuntime.d.ts +11 -2
  120. package/dist/types/model/UiGraphRendererStyles.d.ts +1 -1
  121. package/dist/types/model/UiGraphRuntimeModel.d.ts +2 -0
  122. package/dist/types/model/UiGraphSchema.d.ts +1 -0
  123. package/dist/types/model/chat-v2/chatV2CallObserver.d.ts +2 -0
  124. package/dist/types/model/chat-v2/chatV2CredentialNames.d.ts +30 -0
  125. package/dist/types/model/chat-v2/chatV2EditorCache.d.ts +2 -3
  126. package/dist/types/model/chat-v2/chatV2Outputs.d.ts +6 -16
  127. package/dist/types/model/chat-v2/chatV2Pipeline.d.ts +13 -17
  128. package/dist/types/model/chat-v2/chatV2ProviderProfile.d.ts +7 -0
  129. package/dist/types/model/chat-v2/chatV2ProviderRegistry.d.ts +8 -0
  130. package/dist/types/model/chat-v2/chatV2RequestPlan.d.ts +2 -2
  131. package/dist/types/model/chat-v2/chatV2ResponseBodyCapture.d.ts +25 -0
  132. package/dist/types/model/chat-v2/chatV2ResponseFormat.d.ts +3 -2
  133. package/dist/types/model/chat-v2/chatV2Retry.d.ts +2 -0
  134. package/dist/types/model/chat-v2/chatV2RuntimeOptions.d.ts +3 -8
  135. package/dist/types/model/chat-v2/chatV2Types.d.ts +44 -10
  136. package/dist/types/model/chat-v2/chatV2UsageAccounting.d.ts +14 -0
  137. package/dist/types/model/chat-v2/customProviderApi.d.ts +22 -0
  138. package/dist/types/model/chat-v2/index.d.ts +15 -0
  139. package/dist/types/model/chat-v2/llmChatV2Body.d.ts +24 -0
  140. package/dist/types/model/chat-v2/llmChatV2CacheBoundary.d.ts +10 -0
  141. package/dist/types/model/chat-v2/llmChatV2CachePolicy.d.ts +13 -0
  142. package/dist/types/model/chat-v2/llmChatV2NodeData.d.ts +19 -3
  143. package/dist/types/model/chat-v2/llmChatV2NodeMigration.d.ts +8 -0
  144. package/dist/types/model/chat-v2/llmChatV2NodeRuntime.d.ts +14 -16
  145. package/dist/types/model/chat-v2/llmInvocationCoordinator.d.ts +16 -0
  146. package/dist/types/model/chat-v2/llmInvocationDecision.d.ts +21 -0
  147. package/dist/types/model/chat-v2/llmInvocationJournal.d.ts +38 -0
  148. package/dist/types/model/chat-v2/llmInvocationPlan.d.ts +41 -0
  149. package/dist/types/model/chat-v2/llmInvocationProjections.d.ts +3 -0
  150. package/dist/types/model/chat-v2/llmInvocationResultProjector.d.ts +26 -0
  151. package/dist/types/model/chat-v2/llmModelCandidate.d.ts +20 -0
  152. package/dist/types/model/chat-v2/llmProfile.d.ts +14 -0
  153. package/dist/types/model/chat-v2/llmProfileBody.d.ts +20 -0
  154. package/dist/types/model/chat-v2/llmProfileFallback.d.ts +36 -49
  155. package/dist/types/model/chat-v2/llmProfileFieldRegistry.d.ts +209 -0
  156. package/dist/types/model/chat-v2/llmProfileHealthStore.d.ts +111 -0
  157. package/dist/types/model/chat-v2/llmProfileNodeRuntime.d.ts +1 -1
  158. package/dist/types/model/chat-v2/llmProfileTypes.d.ts +4 -1
  159. package/dist/types/model/chat-v2/llmResponseMaterializer.d.ts +20 -0
  160. package/dist/types/model/chat-v2/modelRegistry.d.ts +17 -187
  161. package/dist/types/model/chat-v2/parallelToolCalls.d.ts +3 -1
  162. package/dist/types/model/chat-v2/providerOptions.d.ts +12 -0
  163. package/dist/types/model/chat-v2/rivetToolRegistry.d.ts +11 -0
  164. package/dist/types/model/chat-v2/toolCallCodec.d.ts +7 -0
  165. package/dist/types/model/chat-v2/toolContinuation.d.ts +3 -3
  166. package/dist/types/model/chat-v2/toolHandlerResolver.d.ts +25 -0
  167. package/dist/types/model/chat-v2/toolRoundExecutor.d.ts +18 -0
  168. package/dist/types/model/nodes/ChatNode.d.ts +2 -1
  169. package/dist/types/model/nodes/CodeNewNode.d.ts +0 -5
  170. package/dist/types/model/nodes/CodeNode.d.ts +0 -5
  171. package/dist/types/model/nodes/DelegateFunctionCallNode.d.ts +2 -1
  172. package/dist/types/model/nodes/LLMChatV2Node.d.ts +2 -1
  173. package/dist/types/model/nodes/LLMProfileNode.d.ts +2 -1
  174. package/dist/types/model/nodes/MatchNode.d.ts +6 -0
  175. package/dist/types/model/nodes/PromptNode.d.ts +4 -1
  176. package/dist/types/model/nodes/ToolNode.d.ts +2 -1
  177. package/dist/types/model/nodes/toolCallDelegation.d.ts +10 -3
  178. package/dist/types/plugins/anthropic/anthropic.d.ts +1 -0
  179. package/dist/types/plugins/gentrace/gentraceSdk.d.ts +0 -1
  180. package/dist/types/plugins/gentrace/plugin.d.ts +55 -9
  181. package/dist/types/plugins/google/google.d.ts +2 -8
  182. package/dist/types/plugins.d.ts +1 -1
  183. package/dist/types/recording/ExecutionRecorder.d.ts +7 -1
  184. package/dist/types/recording/RecordedEvents.d.ts +6 -0
  185. package/dist/types/utils/emitDetached.d.ts +3 -2
  186. package/dist/types/utils/openai.d.ts +49 -0
  187. package/dist/types/webAppRuntime.d.ts +4 -2
  188. package/package.json +2 -2
@@ -0,0 +1,48 @@
1
+ import { projectLLMInvocationUsage } from './llmInvocationProjections.js';
2
+ import { createChatV2CapturedBodyOutputs } from './chatV2Outputs.js';
3
+ /**
4
+ * Projects invocation facts that remain useful even when the node fails.
5
+ * Captured HTTP bodies are emitted only through their opt-in ports, while
6
+ * attempts and profile summaries retain the same public shapes as a success.
7
+ */
8
+ export function projectLLMInvocationDiagnostics({ runOptions, outputLLMAttempts, llmAttempts, profileSummary, }) {
9
+ const capturedBodies = createChatV2CapturedBodyOutputs(runOptions);
10
+ return {
11
+ ...Object.fromEntries(Object.entries(capturedBodies).filter(([, output]) => output?.type !== 'control-flow-excluded')),
12
+ ...projectLLMInvocationMetadata({ outputLLMAttempts, llmAttempts, profileSummary }),
13
+ };
14
+ }
15
+ function projectLLMInvocationMetadata(params) {
16
+ const { outputLLMAttempts, llmAttempts, profileSummary } = params;
17
+ const outputs = {};
18
+ if (outputLLMAttempts) {
19
+ outputs['llmAttempts'] = {
20
+ type: 'object[]',
21
+ value: [...llmAttempts],
22
+ };
23
+ }
24
+ if (profileSummary != null) {
25
+ outputs['llmProfileSummary'] = {
26
+ type: 'string',
27
+ value: profileSummary,
28
+ };
29
+ }
30
+ return outputs;
31
+ }
32
+ /** Applies existing public LLM Chat output shapes from invocation facts. */
33
+ export function projectLLMInvocationResult(params) {
34
+ const { result, modelCalls, outputUsage, outputLLMAttempts, llmAttempts, profileSummary } = params;
35
+ if (outputUsage && modelCalls.length > 0) {
36
+ const physicalUsage = projectLLMInvocationUsage(modelCalls);
37
+ if (physicalUsage != null) {
38
+ result.usage = physicalUsage;
39
+ result.commonOutputs['usage'] = { type: 'object', value: physicalUsage };
40
+ }
41
+ }
42
+ Object.assign(result.commonOutputs, projectLLMInvocationMetadata({
43
+ outputLLMAttempts,
44
+ llmAttempts,
45
+ profileSummary,
46
+ }));
47
+ return result.commonOutputs;
48
+ }
@@ -0,0 +1,79 @@
1
+ import { getInputOrData } from '../../utils/inputs.js';
2
+ import { hasLLMChatV2ToolResponseFormatConflict, LLM_CHAT_V2_TOOL_RESPONSE_FORMAT_CONFLICT_COPY, } from './chatV2FeatureCompatibility.js';
3
+ import { buildLLMInvocationRunOptions, resolveLLMChatV2BaseURL } from './llmInvocationPlan.js';
4
+ import { applyLLMProfileToNodeData } from './llmProfile.js';
5
+ import { createResolvedChatV2Provider, resolveChatV2Credential, } from './chatV2ProviderProfile.js';
6
+ import { resolveLLMChatV2BuiltInTools, resolveLLMChatV2ExtraProviderOptions, resolveLLMChatV2GenerationParameters, resolveLLMChatV2Headers, resolveLLMChatV2RuntimeProviderOptions, } from './chatV2RuntimeOptions.js';
7
+ import { createChatV2ResponseOutput, mergeCustomProviderResponseFormatOptions } from './chatV2ResponseFormat.js';
8
+ import { parseCustomProviderApi } from './customProviderApi.js';
9
+ import { parseChatV2Provider } from './providerOptions.js';
10
+ import { restoreOpenAICompatibleInstructionRoles } from './developerMessageRoles.js';
11
+ export async function resolveLLMModelCandidate(params) {
12
+ const { plan, profile } = params;
13
+ const effectiveData = profile ? applyLLMProfileToNodeData(plan.data, profile) : plan.data;
14
+ if (hasLLMChatV2ToolResponseFormatConflict(effectiveData)) {
15
+ throw new Error(LLM_CHAT_V2_TOOL_RESPONSE_FORMAT_CONFLICT_COPY.paragraphs[0]);
16
+ }
17
+ const provider = parseChatV2Provider(effectiveData.provider);
18
+ const customProviderApi = provider === 'custom' ? parseCustomProviderApi(effectiveData.customProviderApi) : undefined;
19
+ const modelId = getInputOrData(effectiveData, plan.inputs, 'model', 'string');
20
+ const baseURL = resolveLLMChatV2BaseURL(effectiveData, plan.inputs);
21
+ const headers = resolveLLMChatV2Headers(effectiveData, plan.inputs);
22
+ const requestBodyOverlay = resolveLLMChatV2ExtraProviderOptions(effectiveData, plan.inputs);
23
+ const credential = profile?.credential ??
24
+ resolveChatV2Credential({
25
+ provider,
26
+ context: plan.context,
27
+ apiKeySource: effectiveData.apiKeySource === 'input' ? 'input' : 'configured',
28
+ inputs: plan.inputs,
29
+ providerApiKeyNames: effectiveData.providerApiKeyNames,
30
+ customProgrammaticName: effectiveData.customProviderApiKeyProgrammaticName,
31
+ customEnvironmentName: effectiveData.customProviderApiKeyEnvVarName,
32
+ });
33
+ const transformRequestBody = (provider === 'openai' || provider === 'custom') && plan.instructionRoles.includes('developer')
34
+ ? (body) => restoreOpenAICompatibleInstructionRoles(body, plan.instructionRoles)
35
+ : undefined;
36
+ const resolvedProvider = await createResolvedChatV2Provider({
37
+ provider,
38
+ modelId,
39
+ context: plan.context,
40
+ baseURL,
41
+ headers,
42
+ credential,
43
+ onRequestBody: plan.requestBodies == null ? undefined : (body) => plan.requestBodies.push(body),
44
+ onResponseBody: plan.responseBodyCapture == null ? undefined : (response) => plan.responseBodyCapture.capture(response),
45
+ transformRequestBody,
46
+ requestBodyOverlay,
47
+ customProviderApi,
48
+ });
49
+ const generationParameters = resolveLLMChatV2GenerationParameters(effectiveData, plan.inputs);
50
+ const providerOptions = mergeCustomProviderResponseFormatOptions(provider, resolveLLMChatV2RuntimeProviderOptions(effectiveData, plan.inputs), plan.responseFormatParameters, customProviderApi);
51
+ const baseRunOptions = params.roundOptions ??
52
+ buildLLMInvocationRunOptions({
53
+ plan,
54
+ provider,
55
+ modelId,
56
+ });
57
+ return {
58
+ effectiveData,
59
+ credential,
60
+ providerConfig: resolvedProvider.config,
61
+ requestBodyOverlay,
62
+ runOptions: {
63
+ ...baseRunOptions,
64
+ provider,
65
+ model: resolvedProvider.model,
66
+ modelId,
67
+ ...(customProviderApi == null ? {} : { customProviderApi }),
68
+ additionalTools: resolveLLMChatV2BuiltInTools(effectiveData, plan.context, resolvedProvider.config, credential.value),
69
+ ...generationParameters,
70
+ responseOutput: createChatV2ResponseOutput(plan.responseFormatParameters, provider, customProviderApi),
71
+ responseFormat: plan.responseFormatParameters?.responseFormat,
72
+ providerOptions,
73
+ anthropicCacheControlTtl: provider === 'anthropic' ? effectiveData.anthropicCacheControlTtl || undefined : undefined,
74
+ requestBodies: plan.requestBodies,
75
+ responseBodies: plan.responseBodies,
76
+ responseBodyCapture: plan.responseBodyCapture,
77
+ },
78
+ };
79
+ }
@@ -1,5 +1,9 @@
1
- import { createLLMChatV2NodeData, } from './llmChatV2NodeData.js';
1
+ import { createLLMChatV2NodeData } from './llmChatV2NodeData.js';
2
+ import { parseCustomProviderApi } from './customProviderApi.js';
3
+ import { llmProfileBooleanDataKeys, llmProfileOptionalNumberDataKeys, llmProfileRequiredNumberDataKeys, llmProfileResolvedInputToggleDataKeys, llmProfileStringDataKeys, } from './llmProfileFieldRegistry.js';
2
4
  import { LLM_PROFILE_VALUE_VERSION, pickLLMChatV2ProfileData } from './llmProfileTypes.js';
5
+ import { createRivetLLMProfileHealthIdentity } from './llmProfileHealthStore.js';
6
+ import { normalizeChatV2CredentialNamesByProvider } from './chatV2CredentialNames.js';
3
7
  export { applyLLMProfileToNodeData, createDefaultLLMProfileValue, createLLMProfileNodeData, LLM_PROFILE_VALUE_VERSION, pickLLMChatV2ProfileData, } from './llmProfileTypes.js';
4
8
  const credentialSources = new Set([
5
9
  'input',
@@ -10,65 +14,6 @@ const credentialSources = new Set([
10
14
  'none',
11
15
  ]);
12
16
  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
17
  export function normalizeLLMProfileValue(value) {
73
18
  if (!isRecord(value)) {
74
19
  throw new Error('LLM Profile input must contain an LLM profile value.');
@@ -92,10 +37,16 @@ export function normalizeLLMProfileValue(value) {
92
37
  provider,
93
38
  model: model.trim(),
94
39
  });
40
+ const sourceIdentity = normalizeSourceIdentity(value.healthIdentity);
95
41
  return {
96
42
  version: LLM_PROFILE_VALUE_VERSION,
97
43
  configuration,
98
44
  credential,
45
+ healthIdentity: createRivetLLMProfileHealthIdentity({
46
+ configuration,
47
+ credential,
48
+ ...sourceIdentity,
49
+ }),
99
50
  };
100
51
  }
101
52
  /**
@@ -119,23 +70,47 @@ export function normalizeLLMProfileChainInput(value) {
119
70
  }
120
71
  });
121
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
+ }
122
97
  function normalizeConfiguration(data) {
123
- for (const field of stringFields) {
98
+ for (const field of llmProfileStringDataKeys) {
124
99
  if (typeof data[field] !== 'string') {
125
100
  throw new Error(`LLM Profile ${field} must be a string.`);
126
101
  }
127
102
  }
128
- for (const field of booleanFields) {
103
+ for (const field of llmProfileBooleanDataKeys) {
129
104
  if (typeof data[field] !== 'boolean') {
130
105
  throw new Error(`LLM Profile ${field} must be a boolean.`);
131
106
  }
132
107
  }
133
- for (const field of requiredNumberFields) {
108
+ for (const field of llmProfileRequiredNumberDataKeys) {
134
109
  if (typeof data[field] !== 'number' || !Number.isFinite(data[field])) {
135
110
  throw new Error(`LLM Profile ${field} must be a finite number.`);
136
111
  }
137
112
  }
138
- for (const field of optionalNumberFields) {
113
+ for (const field of llmProfileOptionalNumberDataKeys) {
139
114
  const fieldValue = data[field];
140
115
  if (fieldValue != null && (typeof fieldValue !== 'number' || !Number.isFinite(fieldValue))) {
141
116
  throw new Error(`LLM Profile ${field} must be a finite number when provided.`);
@@ -152,12 +127,15 @@ function normalizeConfiguration(data) {
152
127
  throw new Error(`Unsupported LLM Profile API key source: ${String(data.apiKeySource)}.`);
153
128
  }
154
129
  assertEnumValue(data.openAIWebSearchContextSize, ['low', 'medium', 'high'], 'OpenAI web search context');
130
+ const customProviderApi = parseCustomProviderApi(data.customProviderApi);
155
131
  assertEnumValue(data.anthropicThinkingMode, ['', 'adaptive', 'enabled', 'disabled'], 'Anthropic thinking mode');
156
132
  assertEnumValue(data.anthropicEffort, ['', 'low', 'medium', 'high', 'max'], 'Anthropic effort');
157
133
  assertEnumValue(data.anthropicCacheControlTtl, ['', '5m', '1h'], 'Anthropic cache TTL');
158
134
  assertEnumValue(data.googleThinkingLevel, ['', 'minimal', 'low', 'medium', 'high'], 'Google thinking level');
159
135
  const resolvedData = {
160
136
  ...data,
137
+ customProviderApi,
138
+ providerApiKeyNames: normalizeChatV2CredentialNamesByProvider(data.providerApiKeyNames),
161
139
  model: data.model.trim(),
162
140
  customProviderBaseURL: data.customProviderBaseURL.trim(),
163
141
  customProviderApiKeyProgrammaticName: data.customProviderApiKeyProgrammaticName?.trim(),
@@ -168,7 +146,7 @@ function normalizeConfiguration(data) {
168
146
  // A profile is a resolved configuration value. LLM Chat intentionally does not
169
147
  // expose the profile-owned inputs, so accepting a dynamic flag here would let
170
148
  // stale hidden connections influence a supposedly self-contained profile.
171
- for (const field of resolvedInputToggleFields) {
149
+ for (const field of llmProfileResolvedInputToggleDataKeys) {
172
150
  resolvedData[field] = false;
173
151
  }
174
152
  return pickLLMChatV2ProfileData(resolvedData);
@@ -207,6 +185,15 @@ function normalizeCredential(value) {
207
185
  },
208
186
  };
209
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
+ }
210
197
  function isRecord(value) {
211
198
  return typeof value === 'object' && value != null && !Array.isArray(value);
212
199
  }
@@ -0,0 +1,193 @@
1
+ import { getNonDefaultChatV2CredentialNames } from './chatV2CredentialNames.js';
2
+ import { getChatV2ModelInfo } from './modelRegistry.js';
3
+ import { anthropicCacheControlTtlOptions, anthropicEffortOptions, anthropicThinkingModeOptions, getChatV2ProviderLabel, getCustomProviderApiContract, googleThinkingLevelOptions, openAIReasoningEffortOptions, openAIWebSearchContextSizeOptions, } from './providerOptions.js';
4
+ function getOptionLabel(options, value) {
5
+ const optionValue = typeof value === 'string' ? value : '';
6
+ return options.find((option) => option.value === optionValue)?.label ?? (optionValue || 'Default');
7
+ }
8
+ function getOptionalNumberBodyField(label, value, usesInput) {
9
+ if (usesInput) {
10
+ return { label, value: '(Using Input)' };
11
+ }
12
+ return value === undefined ? undefined : { label, value: `${value}` };
13
+ }
14
+ function getOptionalStringBodyField(label, value, usesInput) {
15
+ if (usesInput) {
16
+ return { label, value: '(Using Input)' };
17
+ }
18
+ return typeof value === 'string' && value.trim().length > 0 ? { label, value } : undefined;
19
+ }
20
+ function getCustomProviderBodyLabel(api) {
21
+ try {
22
+ return getCustomProviderApiContract(api).label;
23
+ }
24
+ catch {
25
+ // Corrupt hand-authored project data must not prevent canvas rendering.
26
+ // Runtime profile validation still rejects it before a request.
27
+ return `Custom (${String(api)})`;
28
+ }
29
+ }
30
+ function getModelBodyLabel(data) {
31
+ if (data.useModelInput) {
32
+ return '(Using Input)';
33
+ }
34
+ try {
35
+ return getChatV2ModelInfo(data.provider, data.model)?.displayName ?? String(data.model);
36
+ }
37
+ catch {
38
+ return String(data.model);
39
+ }
40
+ }
41
+ function getProviderBodyFields(data) {
42
+ switch (data.provider) {
43
+ case 'openai':
44
+ return [
45
+ getOptionalStringBodyField('Previous response ID', data.openAIPreviousResponseId, data.useOpenAIPreviousResponseIdInput),
46
+ ...(data.openAIReasoningEffort
47
+ ? [
48
+ {
49
+ label: 'Reasoning effort',
50
+ value: getOptionLabel(openAIReasoningEffortOptions, data.openAIReasoningEffort),
51
+ },
52
+ ]
53
+ : []),
54
+ ...(data.openAIReasoningSummary ? [{ label: 'Reasoning summary', value: data.openAIReasoningSummary }] : []),
55
+ ...(data.enableOpenAIWebSearch
56
+ ? [
57
+ {
58
+ label: 'Web search',
59
+ value: `Enabled (${getOptionLabel(openAIWebSearchContextSizeOptions, data.openAIWebSearchContextSize)})`,
60
+ },
61
+ ]
62
+ : []),
63
+ ...(data.enableOpenAICodeInterpreter ? [{ label: 'Code interpreter', value: 'Enabled' }] : []),
64
+ ].filter((field) => field !== undefined);
65
+ case 'anthropic':
66
+ return [
67
+ ...(data.anthropicThinkingMode
68
+ ? [
69
+ {
70
+ label: 'Thinking mode',
71
+ value: getOptionLabel(anthropicThinkingModeOptions, data.anthropicThinkingMode),
72
+ },
73
+ ]
74
+ : []),
75
+ ...(data.anthropicEffort
76
+ ? [{ label: 'Effort', value: getOptionLabel(anthropicEffortOptions, data.anthropicEffort) }]
77
+ : []),
78
+ getOptionalNumberBodyField('Thinking budget', data.anthropicThinkingBudget, data.useAnthropicThinkingBudgetInput),
79
+ ...(data.anthropicCacheControlTtl
80
+ ? [
81
+ {
82
+ label: 'Cache breakpoint TTL',
83
+ value: getOptionLabel(anthropicCacheControlTtlOptions, data.anthropicCacheControlTtl),
84
+ },
85
+ ]
86
+ : []),
87
+ ].filter((field) => field !== undefined);
88
+ case 'google':
89
+ return [
90
+ ...(data.googleThinkingLevel
91
+ ? [{ label: 'Thinking level', value: getOptionLabel(googleThinkingLevelOptions, data.googleThinkingLevel) }]
92
+ : []),
93
+ getOptionalNumberBodyField('Thinking budget', data.googleThinkingBudget, data.useGoogleThinkingBudgetInput),
94
+ ...(data.googleIncludeThoughts ? [{ label: 'Include thoughts', value: 'Enabled' }] : []),
95
+ ...(data.enableGoogleSearchGrounding ? [{ label: 'Google search grounding', value: 'Enabled' }] : []),
96
+ ...(data.enableGoogleUrlContext ? [{ label: 'URL context', value: 'Enabled' }] : []),
97
+ ].filter((field) => field !== undefined);
98
+ case 'custom':
99
+ default:
100
+ return [];
101
+ }
102
+ }
103
+ function getHeadersBodyField(data) {
104
+ if (data.useHeadersInput) {
105
+ return { label: 'Headers', value: '(Using Input)' };
106
+ }
107
+ const headers = Array.isArray(data.headers)
108
+ ? data.headers.filter((header) => typeof header?.key === 'string' && header.key.trim().length > 0 && typeof header.value === 'string')
109
+ : [];
110
+ return headers.length > 0
111
+ ? { label: 'Headers', value: headers.map(({ key, value }) => `${key}: ${value}`).join(', ') }
112
+ : undefined;
113
+ }
114
+ function getStopSequencesBodyField(data) {
115
+ if (data.useStopSequencesInput) {
116
+ return { label: 'Stop sequences', value: '(Using Input)' };
117
+ }
118
+ const stopSequences = Array.isArray(data.stopSequences)
119
+ ? data.stopSequences.filter((sequence) => typeof sequence === 'string' && sequence.length > 0)
120
+ : [];
121
+ return stopSequences.length > 0
122
+ ? { label: 'Stop sequences', value: stopSequences.map((sequence) => JSON.stringify(sequence)).join(', ') }
123
+ : undefined;
124
+ }
125
+ /**
126
+ * Stable canvas presentation data for LLM Profile configuration. It deliberately
127
+ * contains stored configuration only: runtime API-key values are never present
128
+ * in the node data and therefore cannot be rendered here.
129
+ */
130
+ export function getLLMProfileBodySections(data) {
131
+ const credentialNames = getNonDefaultChatV2CredentialNames(data.provider, data.providerApiKeyNames);
132
+ const modelFields = [
133
+ {
134
+ label: 'Provider',
135
+ value: data.provider === 'custom'
136
+ ? getCustomProviderBodyLabel(data.customProviderApi)
137
+ : getChatV2ProviderLabel(data.provider),
138
+ },
139
+ ...(data.provider === 'custom'
140
+ ? [getOptionalStringBodyField('Base URL', data.customProviderBaseURL, data.useCustomProviderBaseURLInput)]
141
+ : []),
142
+ { label: 'Model', value: getModelBodyLabel(data) },
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
+ : []),
150
+ ...(data.provider === 'custom' && data.apiKeySource !== 'input'
151
+ ? [
152
+ data.customProviderApiKeyProgrammaticName?.trim()
153
+ ? { label: 'Alternative programmatic key', value: data.customProviderApiKeyProgrammaticName }
154
+ : undefined,
155
+ data.customProviderApiKeyEnvVarName?.trim()
156
+ ? { label: 'Alternative API key env var', value: data.customProviderApiKeyEnvVarName }
157
+ : undefined,
158
+ ]
159
+ : []),
160
+ ];
161
+ const parameterFields = [
162
+ { label: 'Temperature', value: data.useTemperatureInput ? '(Using Input)' : `${data.temperature}` },
163
+ { label: 'Max output tokens', value: data.useMaxTokensInput ? '(Using Input)' : `${data.maxTokens}` },
164
+ getOptionalNumberBodyField('Top P', data.topP, data.useTopPInput),
165
+ getOptionalNumberBodyField('Top K', data.topK, data.useTopKInput),
166
+ getOptionalNumberBodyField('Presence penalty', data.presencePenalty, data.usePresencePenaltyInput),
167
+ getOptionalNumberBodyField('Frequency penalty', data.frequencyPenalty, data.useFrequencyPenaltyInput),
168
+ getStopSequencesBodyField(data),
169
+ getOptionalNumberBodyField('Seed', data.seed, data.useSeedInput),
170
+ ];
171
+ const advancedFields = [
172
+ getHeadersBodyField(data),
173
+ ...(data.useExtraProviderOptionsInput ? [{ label: 'Extra provider options', value: '(Using Input)' }] : []),
174
+ ];
175
+ const extraProviderOptions = !data.useExtraProviderOptionsInput &&
176
+ typeof data.extraProviderOptions === 'string' &&
177
+ data.extraProviderOptions.trim().length > 0
178
+ ? { label: 'Extra provider options', text: data.extraProviderOptions }
179
+ : undefined;
180
+ const reliabilityFields = data.enableCircuitBreaker === true ? [{ label: 'Automatic suspension', value: 'Configured' }] : [];
181
+ const sections = [
182
+ { id: 'model', fields: modelFields.filter((field) => field !== undefined) },
183
+ { id: 'parameters', fields: parameterFields.filter((field) => field !== undefined) },
184
+ { id: 'provider', fields: getProviderBodyFields(data) },
185
+ { id: 'reliability', fields: reliabilityFields },
186
+ {
187
+ id: 'advanced',
188
+ fields: advancedFields.filter((field) => field !== undefined),
189
+ snippet: extraProviderOptions,
190
+ },
191
+ ];
192
+ return sections.filter((section) => section.fields.length > 0 || section.snippet !== undefined);
193
+ }