@valerypopoff/rivet2-core 2.1.8 → 2.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (168) hide show
  1. package/dist/cjs/bundle.cjs +4457 -1809
  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 +152 -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 +68 -18
  13. package/dist/esm/model/SubprocessorBridge.js +2 -0
  14. package/dist/esm/model/ToolCallContinuationCoordinator.js +13 -4
  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/aiSdkMessages.js +8 -0
  22. package/dist/esm/model/chat/aiSdkTools.js +3 -2
  23. package/dist/esm/model/chat-v2/chatV2CallObserver.js +11 -5
  24. package/dist/esm/model/chat-v2/chatV2EditorCache.js +58 -10
  25. package/dist/esm/model/chat-v2/chatV2Errors.js +7 -19
  26. package/dist/esm/model/chat-v2/chatV2FeatureCompatibility.js +1 -1
  27. package/dist/esm/model/chat-v2/chatV2Outputs.js +56 -106
  28. package/dist/esm/model/chat-v2/chatV2Pipeline.js +142 -149
  29. package/dist/esm/model/chat-v2/chatV2ProviderProfile.js +9 -2
  30. package/dist/esm/model/chat-v2/chatV2ProviderRegistry.js +9 -0
  31. package/dist/esm/model/chat-v2/chatV2RequestPlan.js +5 -5
  32. package/dist/esm/model/chat-v2/chatV2ResponseBodyCapture.js +55 -0
  33. package/dist/esm/model/chat-v2/chatV2ResponseFormat.js +8 -4
  34. package/dist/esm/model/chat-v2/chatV2Retry.js +4 -3
  35. package/dist/esm/model/chat-v2/chatV2RuntimeOptions.js +6 -1
  36. package/dist/esm/model/chat-v2/chatV2Shared.js +1 -6
  37. package/dist/esm/model/chat-v2/chatV2Types.js +7 -1
  38. package/dist/esm/model/chat-v2/chatV2UsageAccounting.js +78 -0
  39. package/dist/esm/model/chat-v2/customProviderApi.js +42 -0
  40. package/dist/esm/model/chat-v2/developerMessageRoles.js +45 -0
  41. package/dist/esm/model/chat-v2/index.js +12 -0
  42. package/dist/esm/model/chat-v2/llmChatV2Body.js +281 -0
  43. package/dist/esm/model/chat-v2/llmChatV2CacheBoundary.js +32 -0
  44. package/dist/esm/model/chat-v2/llmChatV2CachePolicy.js +20 -0
  45. package/dist/esm/model/chat-v2/llmChatV2NodeData.js +8 -54
  46. package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +41 -20
  47. package/dist/esm/model/chat-v2/llmChatV2NodeMigration.js +24 -0
  48. package/dist/esm/model/chat-v2/llmChatV2NodeRuntime.js +178 -94
  49. package/dist/esm/model/chat-v2/llmInvocationCoordinator.js +60 -0
  50. package/dist/esm/model/chat-v2/llmInvocationDecision.js +11 -0
  51. package/dist/esm/model/chat-v2/llmInvocationJournal.js +43 -0
  52. package/dist/esm/model/chat-v2/llmInvocationPlan.js +68 -0
  53. package/dist/esm/model/chat-v2/llmInvocationProjections.js +5 -0
  54. package/dist/esm/model/chat-v2/llmInvocationResultProjector.js +48 -0
  55. package/dist/esm/model/chat-v2/llmModelCandidate.js +75 -0
  56. package/dist/esm/model/chat-v2/llmProfile.js +31 -65
  57. package/dist/esm/model/chat-v2/llmProfileBody.js +183 -0
  58. package/dist/esm/model/chat-v2/llmProfileFallback.js +244 -0
  59. package/dist/esm/model/chat-v2/llmProfileFieldRegistry.js +67 -0
  60. package/dist/esm/model/chat-v2/llmProfileNodeRuntime.js +3 -0
  61. package/dist/esm/model/chat-v2/llmProfileTypes.js +1 -18
  62. package/dist/esm/model/chat-v2/llmResponseMaterializer.js +42 -0
  63. package/dist/esm/model/chat-v2/messageConverter.js +14 -0
  64. package/dist/esm/model/chat-v2/modelRegistry.js +54 -4
  65. package/dist/esm/model/chat-v2/parallelToolCalls.js +9 -2
  66. package/dist/esm/model/chat-v2/providerOptions.js +120 -21
  67. package/dist/esm/model/chat-v2/rivetToolRegistry.js +9 -0
  68. package/dist/esm/model/chat-v2/toolCallCodec.js +52 -0
  69. package/dist/esm/model/chat-v2/toolContinuation.js +72 -39
  70. package/dist/esm/model/chat-v2/toolHandlerResolver.js +23 -0
  71. package/dist/esm/model/chat-v2/toolRoundExecutor.js +12 -0
  72. package/dist/esm/model/nodes/AssembleMessageNode.js +6 -0
  73. package/dist/esm/model/nodes/ChatNode.js +6 -0
  74. package/dist/esm/model/nodes/ChatNodeBase.js +1 -0
  75. package/dist/esm/model/nodes/DelegateFunctionCallNode.js +26 -1
  76. package/dist/esm/model/nodes/LLMChatV2Node.js +131 -144
  77. package/dist/esm/model/nodes/LLMProfileNode.js +27 -8
  78. package/dist/esm/model/nodes/PromptNode.js +16 -2
  79. package/dist/esm/model/nodes/ToolNode.js +7 -0
  80. package/dist/esm/model/nodes/toolCallDelegation.js +193 -110
  81. package/dist/esm/plugins/anthropic/anthropic.js +4 -4
  82. package/dist/esm/plugins/anthropic/nodes/ChatAnthropicNode.js +29 -28
  83. package/dist/esm/plugins/google/google.js +25 -18
  84. package/dist/esm/plugins/google/nodes/ChatGoogleNode.js +21 -7
  85. package/dist/esm/recording/ExecutionRecorder.js +13 -5
  86. package/dist/esm/utils/chatMessageToOpenAIChatCompletionMessage.js +4 -0
  87. package/dist/esm/utils/emitDetached.js +6 -3
  88. package/dist/esm/utils/openai.js +60 -16
  89. package/dist/esm/utils/serialization/serialization.js +2 -0
  90. package/dist/esm/webAppRuntime.js +3 -2
  91. package/dist/types/exports.d.ts +1 -0
  92. package/dist/types/model/AgentResponseTrace.d.ts +110 -0
  93. package/dist/types/model/ConnectedToolContinuationHost.d.ts +34 -0
  94. package/dist/types/model/DataValue.d.ts +7 -1
  95. package/dist/types/model/ExecutorProtocol.d.ts +25 -7
  96. package/dist/types/model/GraphProcessor.d.ts +27 -5
  97. package/dist/types/model/NodeBase.d.ts +6 -0
  98. package/dist/types/model/NodeImpl.d.ts +18 -1
  99. package/dist/types/model/Nodes.d.ts +2 -2
  100. package/dist/types/model/ProcessContext.d.ts +51 -0
  101. package/dist/types/model/ProcessContextBuilder.d.ts +3 -1
  102. package/dist/types/model/RecordingPlayer.d.ts +6 -0
  103. package/dist/types/model/SplitRunProcessor.d.ts +11 -3
  104. package/dist/types/model/UiGraph.d.ts +8 -0
  105. package/dist/types/model/UiGraphActionProtocol.d.ts +2 -0
  106. package/dist/types/model/UiGraphBrowserRuntime.d.ts +11 -2
  107. package/dist/types/model/UiGraphRendererStyles.d.ts +1 -1
  108. package/dist/types/model/UiGraphRuntimeModel.d.ts +2 -0
  109. package/dist/types/model/UiGraphSchema.d.ts +1 -0
  110. package/dist/types/model/chat-v2/chatV2CallObserver.d.ts +2 -0
  111. package/dist/types/model/chat-v2/chatV2EditorCache.d.ts +3 -1
  112. package/dist/types/model/chat-v2/chatV2Outputs.d.ts +7 -17
  113. package/dist/types/model/chat-v2/chatV2Pipeline.d.ts +29 -0
  114. package/dist/types/model/chat-v2/chatV2ProviderProfile.d.ts +5 -0
  115. package/dist/types/model/chat-v2/chatV2ProviderRegistry.d.ts +8 -0
  116. package/dist/types/model/chat-v2/chatV2RequestPlan.d.ts +2 -2
  117. package/dist/types/model/chat-v2/chatV2ResponseBodyCapture.d.ts +19 -0
  118. package/dist/types/model/chat-v2/chatV2ResponseFormat.d.ts +3 -2
  119. package/dist/types/model/chat-v2/chatV2Retry.d.ts +2 -0
  120. package/dist/types/model/chat-v2/chatV2Shared.d.ts +0 -1
  121. package/dist/types/model/chat-v2/chatV2Types.d.ts +35 -1
  122. package/dist/types/model/chat-v2/chatV2UsageAccounting.d.ts +14 -0
  123. package/dist/types/model/chat-v2/customProviderApi.d.ts +23 -0
  124. package/dist/types/model/chat-v2/developerMessageRoles.d.ts +10 -0
  125. package/dist/types/model/chat-v2/index.d.ts +12 -0
  126. package/dist/types/model/chat-v2/llmChatV2Body.d.ts +24 -0
  127. package/dist/types/model/chat-v2/llmChatV2CacheBoundary.d.ts +10 -0
  128. package/dist/types/model/chat-v2/llmChatV2CachePolicy.d.ts +13 -0
  129. package/dist/types/model/chat-v2/llmChatV2NodeData.d.ts +13 -3
  130. package/dist/types/model/chat-v2/llmChatV2NodeMigration.d.ts +8 -0
  131. package/dist/types/model/chat-v2/llmChatV2NodeRuntime.d.ts +18 -4
  132. package/dist/types/model/chat-v2/llmInvocationCoordinator.d.ts +16 -0
  133. package/dist/types/model/chat-v2/llmInvocationDecision.d.ts +21 -0
  134. package/dist/types/model/chat-v2/llmInvocationJournal.d.ts +38 -0
  135. package/dist/types/model/chat-v2/llmInvocationPlan.d.ts +41 -0
  136. package/dist/types/model/chat-v2/llmInvocationProjections.d.ts +3 -0
  137. package/dist/types/model/chat-v2/llmInvocationResultProjector.d.ts +26 -0
  138. package/dist/types/model/chat-v2/llmModelCandidate.d.ts +18 -0
  139. package/dist/types/model/chat-v2/llmProfile.d.ts +7 -0
  140. package/dist/types/model/chat-v2/llmProfileBody.d.ts +20 -0
  141. package/dist/types/model/chat-v2/llmProfileFallback.d.ts +47 -0
  142. package/dist/types/model/chat-v2/llmProfileFieldRegistry.d.ts +189 -0
  143. package/dist/types/model/chat-v2/llmProfileTypes.d.ts +1 -1
  144. package/dist/types/model/chat-v2/llmResponseMaterializer.d.ts +20 -0
  145. package/dist/types/model/chat-v2/modelRegistry.d.ts +17 -187
  146. package/dist/types/model/chat-v2/parallelToolCalls.d.ts +3 -1
  147. package/dist/types/model/chat-v2/providerOptions.d.ts +11 -0
  148. package/dist/types/model/chat-v2/rivetToolRegistry.d.ts +11 -0
  149. package/dist/types/model/chat-v2/toolCallCodec.d.ts +7 -0
  150. package/dist/types/model/chat-v2/toolContinuation.d.ts +3 -3
  151. package/dist/types/model/chat-v2/toolHandlerResolver.d.ts +25 -0
  152. package/dist/types/model/chat-v2/toolRoundExecutor.d.ts +18 -0
  153. package/dist/types/model/nodes/AssembleMessageNode.d.ts +2 -1
  154. package/dist/types/model/nodes/ChatNode.d.ts +2 -1
  155. package/dist/types/model/nodes/DelegateFunctionCallNode.d.ts +2 -1
  156. package/dist/types/model/nodes/LLMChatV2Node.d.ts +2 -1
  157. package/dist/types/model/nodes/LLMProfileNode.d.ts +2 -1
  158. package/dist/types/model/nodes/PromptNode.d.ts +6 -3
  159. package/dist/types/model/nodes/ToolNode.d.ts +2 -1
  160. package/dist/types/model/nodes/toolCallDelegation.d.ts +10 -3
  161. package/dist/types/plugins/anthropic/anthropic.d.ts +1 -0
  162. package/dist/types/plugins/google/google.d.ts +14 -9
  163. package/dist/types/plugins/google/nodes/ChatGoogleNode.d.ts +2 -1
  164. package/dist/types/recording/RecordedEvents.d.ts +6 -0
  165. package/dist/types/utils/emitDetached.d.ts +3 -2
  166. package/dist/types/utils/openai.d.ts +49 -0
  167. package/dist/types/webAppRuntime.d.ts +4 -2
  168. package/package.json +2 -2
@@ -273,14 +273,13 @@ export const ChatGoogleNodeImpl = {
273
273
  },
274
274
  async process(data, inputs, context) {
275
275
  const output = {};
276
- const systemPrompt = coerceTypeOptional(inputs['systemPrompt'], 'string');
277
276
  const rawModel = getInputOrData(data, inputs, 'model');
278
277
  const model = rawModel;
279
278
  const temperature = getInputOrData(data, inputs, 'temperature', 'number');
280
279
  const topP = getInputOrData(data, inputs, 'top_p', 'number');
281
280
  const useTopP = getInputOrData(data, inputs, 'useTopP', 'boolean');
282
281
  const thinkingBudget = getInputOrData(data, inputs, 'thinkingBudget', 'number');
283
- const { messages } = getChatGoogleNodeMessages(inputs);
282
+ const { messages, systemPrompt } = getChatGoogleNodeMessages(inputs);
284
283
  let prompt = await Promise.all(messages.map(async (message) => {
285
284
  if (message.type === 'user' || message.type === 'assistant') {
286
285
  const parts = await Promise.all([message.message].flat().map(async (part) => {
@@ -343,7 +342,7 @@ export const ChatGoogleNodeImpl = {
343
342
  ],
344
343
  };
345
344
  }
346
- throw new Error(`Google Vertex AI does not support message type ${message.type}`);
345
+ throw new Error('Google Vertex AI received an unsupported message type.');
347
346
  }));
348
347
  // Collapse sequential function responses into a single function response with mutliple parts
349
348
  prompt = prompt.reduce((acc, message) => {
@@ -368,7 +367,10 @@ export const ChatGoogleNodeImpl = {
368
367
  endpoint: undefined,
369
368
  };
370
369
  // TODO Better token counting for Google models.
371
- const tokenCount = await context.tokenizer.getTokenCountForMessages(messages, undefined, tokenizerInfo);
370
+ const tokenMessages = systemPrompt
371
+ ? [{ type: 'system', message: systemPrompt }, ...messages]
372
+ : messages;
373
+ const tokenCount = await context.tokenizer.getTokenCountForMessages(tokenMessages, undefined, tokenizerInfo);
372
374
  if (generativeAiGoogleModels[model]) {
373
375
  maxTokens = clampMaxTokensToModelLimit(output, model, tokenCount, maxTokens, generativeAiGoogleModels[model].maxTokens);
374
376
  }
@@ -393,7 +395,9 @@ export const ChatGoogleNodeImpl = {
393
395
  type: Type.OBJECT,
394
396
  properties: mapValues(parameters.properties ?? {}, (property) => ({
395
397
  // gemini doesn't support union property types, it uses openapi style not jsonschema, what a mess
396
- type: toGoogleSchemaType(Array.isArray(property.type) ? property.type.find((type) => type !== 'null') : property.type),
398
+ type: toGoogleSchemaType(Array.isArray(property.type)
399
+ ? property.type.find((type) => type !== 'null')
400
+ : property.type),
397
401
  description: property.description,
398
402
  })),
399
403
  required: parameters.required ?? [],
@@ -445,6 +449,7 @@ export const ChatGoogleNodeImpl = {
445
449
  if (data.cache) {
446
450
  const cached = cache.get(cacheKey);
447
451
  if (cached) {
452
+ context.markResultAsEditorCacheHit?.();
448
453
  return cached;
449
454
  }
450
455
  }
@@ -478,6 +483,7 @@ export const ChatGoogleNodeImpl = {
478
483
  temperature: useTopP ? undefined : temperature,
479
484
  top_p: useTopP ? topP : undefined,
480
485
  top_k: undefined,
486
+ systemPrompt,
481
487
  project: project,
482
488
  location: location,
483
489
  applicationCredentials: applicationCredentials,
@@ -579,6 +585,14 @@ export const ChatGoogleNodeImpl = {
579
585
  };
580
586
  export const chatGoogleNode = pluginNodeDefinition(ChatGoogleNodeImpl, 'Chat (Google, Legacy)');
581
587
  export function getChatGoogleNodeMessages(inputs) {
582
- const prompt = inputs['prompt'];
583
- return { messages: coercePromptToChatMessages(prompt, { requirePrompt: true }) };
588
+ const promptMessages = coercePromptToChatMessages(inputs['prompt'], { requirePrompt: true });
589
+ const instructionMessages = promptMessages.filter((message) => message.type === 'system' || message.type === 'developer');
590
+ const systemPromptParts = [
591
+ coerceTypeOptional(inputs['systemPrompt'], 'string'),
592
+ ...instructionMessages.map((message) => coerceTypeOptional({ type: 'chat-message', value: message }, 'string')),
593
+ ].filter((part) => !!part);
594
+ return {
595
+ messages: promptMessages.filter((message) => message.type !== 'system' && message.type !== 'developer'),
596
+ systemPrompt: systemPromptParts.length > 0 ? systemPromptParts.join('\n\n') : undefined,
597
+ };
584
598
  }
@@ -24,20 +24,24 @@ const toRecordedEventMap = {
24
24
  graphId: graph.metadata.id,
25
25
  error: typeof error === 'string' ? error : error.stack,
26
26
  }, execution),
27
- nodeStart: ({ node, inputs, processId, execution }) => withExecution({
27
+ nodeStart: ({ node, inputs, inputConnections, processId, resultOrigin, execution }) => withExecution({
28
28
  nodeId: node.id,
29
29
  inputs,
30
+ ...(inputConnections == null ? {} : { inputConnections }),
30
31
  processId,
32
+ ...(resultOrigin === undefined ? {} : { resultOrigin }),
31
33
  }, execution),
32
- nodeFinish: ({ node, outputs, processId, durationMs, splitRunDurationMs, execution }) => withExecution(withDuration({
34
+ nodeFinish: ({ node, outputs, processId, resultOrigin, durationMs, splitRunDurationMs, execution }) => withExecution(withDuration({
33
35
  nodeId: node.id,
34
36
  outputs,
35
37
  processId,
38
+ ...(resultOrigin === undefined ? {} : { resultOrigin }),
36
39
  }, durationMs, splitRunDurationMs), execution),
37
- nodeError: ({ node, error, processId, durationMs, splitRunDurationMs, execution }) => withExecution(withDuration({
40
+ nodeError: ({ node, error, processId, resultOrigin, durationMs, splitRunDurationMs, execution }) => withExecution(withDuration({
38
41
  nodeId: node.id,
39
42
  error: typeof error === 'string' ? error : error.stack,
40
43
  processId,
44
+ ...(resultOrigin === undefined ? {} : { resultOrigin }),
41
45
  }, durationMs, splitRunDurationMs), execution),
42
46
  abort: ({ successful, error }) => ({ successful, error: typeof error === 'string' ? error : error?.stack }),
43
47
  graphAbort: ({ successful, error, graph, execution }) => withExecution({
@@ -45,12 +49,13 @@ const toRecordedEventMap = {
45
49
  error: typeof error === 'string' ? error : error?.stack,
46
50
  graphId: graph.metadata.id,
47
51
  }, execution),
48
- nodeExcluded: ({ node, processId, inputs, outputs, reason, execution }) => withExecution({
52
+ nodeExcluded: ({ node, processId, inputs, outputs, reason, resultOrigin, execution }) => withExecution({
49
53
  nodeId: node.id,
50
54
  processId,
51
55
  inputs,
52
56
  outputs,
53
57
  reason,
58
+ ...(resultOrigin === undefined ? {} : { resultOrigin }),
54
59
  }, execution),
55
60
  userInput: ({ node, inputs, callback, processId, inputStrings, renderingType, execution }) => withExecution({
56
61
  nodeId: node.id,
@@ -60,17 +65,20 @@ const toRecordedEventMap = {
60
65
  inputStrings,
61
66
  renderingType,
62
67
  }, execution),
63
- partialOutput: ({ node, outputs, index, processId, execution }) => withExecution({
68
+ partialOutput: ({ node, outputs, index, processId, resultOrigin, execution }) => withExecution({
64
69
  nodeId: node.id,
65
70
  outputs,
66
71
  index,
67
72
  processId,
73
+ ...(resultOrigin === undefined ? {} : { resultOrigin }),
68
74
  }, execution),
69
75
  progress: ({ node, processId, progress, execution }) => withExecution({
70
76
  nodeId: node.id,
71
77
  processId,
72
78
  progress,
73
79
  }, execution),
80
+ llmCallFinished: ({ execution, ...event }) => ({ ...event, execution }),
81
+ toolCallFinished: ({ execution, ...event }) => ({ ...event, execution }),
74
82
  nodeOutputsCleared: ({ node, processId, execution }) => withExecution({
75
83
  nodeId: node.id,
76
84
  processId,
@@ -28,6 +28,10 @@ export async function chatMessageToOpenAIChatCompletionMessage(message, options)
28
28
  };
29
29
  }
30
30
  })
31
+ .with({ type: 'developer' }, (m) => ({
32
+ role: 'developer',
33
+ content: onlyStringContent(m),
34
+ }))
31
35
  .with({ type: 'user' }, async (m) => {
32
36
  const parts = Array.isArray(m.message) ? m.message : [m.message];
33
37
  if (parts.length === 1 && typeof parts[0] === 'string') {
@@ -4,9 +4,12 @@
4
4
  * Use this instead of inline `// eslint-disable-next-line @typescript-eslint/no-floating-promises`
5
5
  * to make the "detached async" intent explicit and auditable.
6
6
  *
7
- * The returned promise is intentionally discarded. Call this only for events
8
- * where listener completion does not affect processor ordering.
7
+ * The returned promise is intentionally detached and listener failures are
8
+ * contained. Call this only for observer events where listener completion or
9
+ * failure must not affect processor ordering.
9
10
  */
10
11
  export function emitDetached(emitter, event, data) {
11
- void emitter.emit(event, data);
12
+ void emitter.emit(event, data).catch(() => {
13
+ // Detached observers must not alter or terminate graph execution.
14
+ });
12
15
  }
@@ -6,11 +6,55 @@ export const defaultOpenaiSupported = {
6
6
  parallelFunctionCalls: true,
7
7
  };
8
8
  export const openaiModels = {
9
+ 'gpt-5.6': {
10
+ maxTokens: 1_050_000,
11
+ cost: {
12
+ prompt: 0.005,
13
+ completion: 0.03,
14
+ },
15
+ displayName: 'GPT-5.6',
16
+ supported: {
17
+ parallelFunctionCalls: true,
18
+ },
19
+ },
20
+ 'gpt-5.6-sol': {
21
+ maxTokens: 1_050_000,
22
+ cost: {
23
+ prompt: 0.005,
24
+ completion: 0.03,
25
+ },
26
+ displayName: 'GPT-5.6 Sol',
27
+ supported: {
28
+ parallelFunctionCalls: true,
29
+ },
30
+ },
31
+ 'gpt-5.6-terra': {
32
+ maxTokens: 1_050_000,
33
+ cost: {
34
+ prompt: 0.002,
35
+ completion: 0.012,
36
+ },
37
+ displayName: 'GPT-5.6 Terra',
38
+ supported: {
39
+ parallelFunctionCalls: true,
40
+ },
41
+ },
42
+ 'gpt-5.6-luna': {
43
+ maxTokens: 1_050_000,
44
+ cost: {
45
+ prompt: 0.0002,
46
+ completion: 0.0012,
47
+ },
48
+ displayName: 'GPT-5.6 Luna',
49
+ supported: {
50
+ parallelFunctionCalls: true,
51
+ },
52
+ },
9
53
  'gpt-5': {
10
54
  maxTokens: 400000,
11
55
  cost: {
12
- prompt: 1.25e-6,
13
- completion: 10e-6,
56
+ prompt: 1.25e-3,
57
+ completion: 0.01,
14
58
  },
15
59
  displayName: 'GPT-5',
16
60
  supported: {
@@ -20,8 +64,8 @@ export const openaiModels = {
20
64
  'gpt-5-mini': {
21
65
  maxTokens: 400000,
22
66
  cost: {
23
- prompt: 0.25 - 6,
24
- completion: 2e-6,
67
+ prompt: 0.25e-3,
68
+ completion: 0.002,
25
69
  },
26
70
  displayName: 'GPT-5 mini',
27
71
  supported: {
@@ -31,8 +75,8 @@ export const openaiModels = {
31
75
  'gpt-5-nano': {
32
76
  maxTokens: 400000,
33
77
  cost: {
34
- prompt: 0.05e-6,
35
- completion: 0.4e-6,
78
+ prompt: 0.05e-3,
79
+ completion: 0.0004,
36
80
  },
37
81
  displayName: 'GPT-5 nano',
38
82
  supported: {
@@ -42,8 +86,8 @@ export const openaiModels = {
42
86
  'gpt-4o': {
43
87
  maxTokens: 128000,
44
88
  cost: {
45
- prompt: 0.005,
46
- completion: 0.015,
89
+ prompt: 0.0025,
90
+ completion: 0.01,
47
91
  },
48
92
  displayName: 'GPT-4o',
49
93
  },
@@ -51,7 +95,7 @@ export const openaiModels = {
51
95
  maxTokens: 128000,
52
96
  cost: {
53
97
  prompt: 0.00015,
54
- completion: 0.00075,
98
+ completion: 0.0006,
55
99
  },
56
100
  displayName: 'GPT-4o mini',
57
101
  },
@@ -59,7 +103,7 @@ export const openaiModels = {
59
103
  maxTokens: 128000,
60
104
  cost: {
61
105
  prompt: 0.015,
62
- completion: 0.6,
106
+ completion: 0.06,
63
107
  },
64
108
  displayName: 'o1',
65
109
  supported: {
@@ -101,24 +145,24 @@ export const openaiModels = {
101
145
  'gpt-4.1': {
102
146
  maxTokens: 1_047_576,
103
147
  cost: {
104
- prompt: 2e-6,
105
- completion: 8e-6,
148
+ prompt: 0.002,
149
+ completion: 0.008,
106
150
  },
107
151
  displayName: 'GPT-4.1',
108
152
  },
109
153
  o3: {
110
154
  maxTokens: 200_000,
111
155
  cost: {
112
- prompt: 10e-6,
113
- completion: 40e-6,
156
+ prompt: 0.01,
157
+ completion: 0.04,
114
158
  },
115
159
  displayName: 'o3',
116
160
  },
117
161
  'o4-mini': {
118
162
  maxTokens: 200_000,
119
163
  cost: {
120
- prompt: 1.1e-6,
121
- completion: 4.4e-6,
164
+ prompt: 0.0011,
165
+ completion: 0.0044,
122
166
  },
123
167
  displayName: 'o4-mini',
124
168
  },
@@ -8,6 +8,7 @@ import { UiGraphNormalizationError } from '../../model/UiGraphNormalization.js';
8
8
  import { datasetV4Deserializer, datasetV4Serializer, graphV4Deserializer, graphV4Serializer, projectV4Deserializer, projectV4Serializer, } from './serialization_v4.js';
9
9
  import { graphV2Deserializer, projectV2Deserializer } from './serialization_v2.js';
10
10
  import { graphV1Deserializer, projectV1Deserializer } from './serialization_v1.js';
11
+ import { normalizeSerializedLLMChatV2Node } from '../../model/chat-v2/llmChatV2NodeMigration.js';
11
12
  export function serializeProject(project, attachedData) {
12
13
  return projectV4Serializer(project, attachedData);
13
14
  }
@@ -82,6 +83,7 @@ function normalizeDeserializedNode(node) {
82
83
  const { renderAsDataBus: _legacyFlag, ...data } = node.data;
83
84
  node.data = data;
84
85
  }
86
+ normalizeSerializedLLMChatV2Node(node);
85
87
  }
86
88
  function deserializeProjectByVersion(serializedProject, version) {
87
89
  switch (version) {
@@ -1,4 +1,5 @@
1
- export { createUiGraphChatHistoryFlushStatePatch, createUiGraphChatPinStatePatch, createUiGraphChatSubmissionStatePatch, getUiGraphActionState, getUiGraphChatDraftStateKey, getUiGraphChatMessagesStateKey, } from './model/UiGraph.js';
1
+ export { isAgentResponseTrace } from './model/AgentResponseTrace.js';
2
+ export { createUiGraphChatHistoryFlushStatePatch, createUiGraphChatMessageRemovalStatePatch, createUiGraphChatPinStatePatch, createUiGraphChatSubmissionStatePatch, getUiGraphActionState, getUiGraphChatDraftStateKey, getUiGraphChatMessagesStateKey, } from './model/UiGraph.js';
2
3
  export { applyUiGraphStatePatch, createUiGraphActionExecutionController, createUiGraphInteractionController, getUiGraphComponentRenderModel, getUiGraphJsonOutputFilename, getUiGraphProgressiveJsonOutputChunks, } from './model/UiGraphRuntimeModel.js';
3
4
  export { parseRivetWebAppClientMessage, parseRivetWebAppServerMessage, RIVET_WEB_APP_ACTION_PROTOCOL_VERSION, } from './model/UiGraphActionProtocol.js';
4
- export { copyUiGraphText, applyUiGraphWebAppStorageActionPatch, applyUiGraphWebAppStoragePatch, clearUiGraphChatSearchMatches, downloadUiGraphJsonOutput, enhanceUiGraphChatJsonCodeBlocks, hasUiGraphChatPersistentStateChanged, getUiGraphChatPersistentState, getUiGraphChatMessagePresentations, getUiGraphChatStorageKey, getUiGraphWebAppStorageKey, highlightUiGraphChatSearchMatches, loadUiGraphChatPersistentState, loadUiGraphWebAppStorage, observeUiGraphOutputResizeBounds, revealUiGraphChatElement, revealUiGraphChatSearchMatch, saveUiGraphChatPersistentState, } from './model/UiGraphBrowserRuntime.js';
5
+ export { copyUiGraphText, applyUiGraphWebAppStorageActionPatch, applyUiGraphWebAppStoragePatch, clearUiGraphChatSearchMatches, downloadUiGraphJsonOutput, enhanceUiGraphChatJsonCodeBlocks, hasUiGraphChatPersistentStateChanged, getUiGraphChatPersistentState, getUiGraphChatMessagePresentations, getUiGraphChatStorageKey, getUiGraphWebAppStorageKey, highlightUiGraphChatSearchMatches, loadUiGraphChatPersistentState, loadUiGraphWebAppStorage, observeUiGraphOutputResizeBounds, revealUiGraphChatElement, revealUiGraphChatSearchMatch, saveUiGraphChatPersistentState, saveUiGraphResponseTrace, loadUiGraphResponseTrace, pruneUiGraphResponseTraces, } from './model/UiGraphBrowserRuntime.js';
@@ -26,6 +26,7 @@ export * from './native/BaseDir.js';
26
26
  export * from './native/NativeApi.js';
27
27
  export * from './native/BrowserNativeApi.js';
28
28
  export * from './model/ProcessContext.js';
29
+ export * from './model/AgentResponseTrace.js';
29
30
  export * from './model/DebuggerTransportSentinel.js';
30
31
  export * from './model/ProjectReferenceLoader.js';
31
32
  export * from './model/RivetUIContext.js';
@@ -0,0 +1,110 @@
1
+ import type { ChatV2CallTraceEvent, GraphExecutionMetadata, GraphRunId, ProcessId, RootRunId, ToolCallFinishedEvent } from './ProcessContext.js';
2
+ import type { GraphId } from './NodeGraph.js';
3
+ import type { NodeId } from './NodeBase.js';
4
+ import type { GraphProcessor } from './GraphProcessor.js';
5
+ export declare const AGENT_RESPONSE_TRACE_SCHEMA_VERSION: 1;
6
+ export declare const AGENT_RESPONSE_TRACE_MAX_MODEL_CALLS = 250;
7
+ export declare const AGENT_RESPONSE_TRACE_MAX_TOOL_CALLS = 500;
8
+ export type AgentModelCallTrace = {
9
+ callId: string;
10
+ nodeId: NodeId;
11
+ processId: ProcessId;
12
+ provider: string;
13
+ model: string;
14
+ customProviderApi?: ChatV2CallTraceEvent['customProviderApi'];
15
+ outcome: ChatV2CallTraceEvent['outcome'];
16
+ attemptIndex: number;
17
+ profileIndex?: number;
18
+ roundIndex?: number;
19
+ startedAt?: number;
20
+ durationMs?: number;
21
+ finishReason?: string;
22
+ usage?: ChatV2CallTraceEvent['normalizedUsage'];
23
+ pricing: ChatV2CallTraceEvent['pricing'];
24
+ };
25
+ export type AgentToolCallTrace = {
26
+ toolCallId?: string;
27
+ toolName: string;
28
+ sourceNodeId: NodeId;
29
+ sourceProcessId: ProcessId;
30
+ /** Pointer to the pre-existing Delegate Tool Call output, never copied result text. */
31
+ resultOwner?: ToolCallFinishedEvent['resultOwner'];
32
+ handlerKind: ToolCallFinishedEvent['handlerKind'];
33
+ handlerGraphId?: GraphId;
34
+ handlerName?: string;
35
+ outcome: ToolCallFinishedEvent['outcome'];
36
+ startedAt?: number;
37
+ durationMs?: number;
38
+ };
39
+ export type AgentResponseTrace = {
40
+ schemaVersion: typeof AGENT_RESPONSE_TRACE_SCHEMA_VERSION;
41
+ traceId: RootRunId;
42
+ scope: 'response' | 'llm-invocation';
43
+ rootRunId: RootRunId;
44
+ graphRunId: GraphRunId;
45
+ graphId: GraphId;
46
+ nodeId?: NodeId;
47
+ processId?: ProcessId;
48
+ startedAt?: number;
49
+ responseReadyAt?: number;
50
+ finishedAt?: number;
51
+ durationMs?: number;
52
+ status: 'running' | 'response-ready' | 'completed' | 'error' | 'aborted' | 'unavailable';
53
+ backgroundWorkPending?: boolean;
54
+ summary: {
55
+ modelCallCount: number;
56
+ toolCallCount: number;
57
+ retryCount: number;
58
+ fallbackCount: number;
59
+ promptTokens?: number;
60
+ completionTokens?: number;
61
+ totalTokens?: number;
62
+ cachedTokens?: number;
63
+ reasoningTokens?: number;
64
+ knownCostUsd: number;
65
+ costStatus: 'known' | 'partial' | 'unknown';
66
+ };
67
+ modelCalls: AgentModelCallTrace[];
68
+ toolCalls: AgentToolCallTrace[];
69
+ omittedModelCallCount: number;
70
+ omittedToolCallCount: number;
71
+ };
72
+ export type AgentTraceEvent = ({
73
+ type: 'llm-call-finished';
74
+ execution: GraphExecutionMetadata;
75
+ } & ChatV2CallTraceEvent) | ({
76
+ type: 'tool-call-finished';
77
+ execution: GraphExecutionMetadata;
78
+ } & ToolCallFinishedEvent);
79
+ export type BuildAgentResponseTraceOptions = {
80
+ scope: AgentResponseTrace['scope'];
81
+ execution: GraphExecutionMetadata;
82
+ events: readonly AgentTraceEvent[];
83
+ nodeId?: NodeId;
84
+ processId?: ProcessId;
85
+ startedAt?: number;
86
+ responseReadyAt?: number;
87
+ finishedAt?: number;
88
+ status: AgentResponseTrace['status'];
89
+ backgroundWorkPending?: boolean;
90
+ };
91
+ export declare function buildAgentResponseTrace(options: BuildAgentResponseTraceOptions): AgentResponseTrace;
92
+ export declare function getAgentTraceEventIdentity(event: AgentTraceEvent): string | undefined;
93
+ /**
94
+ * Redelivery is allowed to omit newly added optional observability fields. Keep
95
+ * an exact Delegate result pointer once it was observed instead of making a
96
+ * later legacy-shaped copy erase result navigation.
97
+ */
98
+ export declare function mergeAgentTraceEvent(existing: AgentTraceEvent, incoming: AgentTraceEvent): AgentTraceEvent;
99
+ export declare function isAgentResponseTrace(value: unknown): value is AgentResponseTrace;
100
+ /**
101
+ * Collects privacy-bounded response metadata for one root processor run.
102
+ * Listener failures are isolated by GraphProcessor; callers should dispose the
103
+ * collector after the processor and any asynchronous branches settle.
104
+ */
105
+ export declare class AgentResponseTraceCollector {
106
+ #private;
107
+ constructor(processor: GraphProcessor);
108
+ build(): AgentResponseTrace | undefined;
109
+ dispose(): void;
110
+ }
@@ -0,0 +1,34 @@
1
+ import type { Outputs } from './GraphProcessor.js';
2
+ import type { NodeId } from './NodeBase.js';
3
+ import type { ProcessId } from './ProcessContext.js';
4
+ import type { ToolCallContinuation } from './ToolCallContinuation.js';
5
+ import type { DelegateFunctionCallNode } from './nodes/DelegateFunctionCallNode.js';
6
+ /**
7
+ * Owns connected Delegate invocation lifetime. GraphProcessor supplies narrow
8
+ * scheduling callbacks, while this host owns only continuation-local state.
9
+ */
10
+ export type ConnectedToolContinuationInvocation = {
11
+ delegateNode: DelegateFunctionCallNode;
12
+ latestOutputs: Map<NodeId, Outputs>;
13
+ llmNodeId: NodeId;
14
+ llmProcessId: ProcessId;
15
+ released: boolean;
16
+ };
17
+ export declare class ConnectedToolContinuationHost {
18
+ #private;
19
+ begin(params: {
20
+ key: string;
21
+ delegateNode: DelegateFunctionCallNode;
22
+ llmNodeId: NodeId;
23
+ llmProcessId: ProcessId;
24
+ run: (invocation: ConnectedToolContinuationInvocation, toolCalls: Parameters<ToolCallContinuation['run']>[0], assistantMessage: string) => ReturnType<ToolCallContinuation['run']>;
25
+ }): ToolCallContinuation;
26
+ finalize(params: {
27
+ key: string;
28
+ nodeOutputs: Outputs;
29
+ replay: (invocation: ConnectedToolContinuationInvocation, nodeOutputs: Outputs) => void;
30
+ commit: (invocation: ConnectedToolContinuationInvocation) => void;
31
+ }): void;
32
+ discard(key: string): void;
33
+ reset(): void;
34
+ }
@@ -15,6 +15,12 @@ export type SystemChatMessage = {
15
15
  /** If true, this message marks a breakpoint when used with prompt caching (as of right now, Anthropic-only). */
16
16
  isCacheBreakpoint?: boolean;
17
17
  };
18
+ export type DeveloperChatMessage = {
19
+ type: 'developer';
20
+ message: ChatMessageMessagePart | ChatMessageMessagePart[];
21
+ /** If true, this message marks a breakpoint when used with prompt caching (as of right now, Anthropic-only). */
22
+ isCacheBreakpoint?: boolean;
23
+ };
18
24
  export type UserChatMessage = {
19
25
  type: 'user';
20
26
  message: ChatMessageMessagePart | ChatMessageMessagePart[];
@@ -48,7 +54,7 @@ export type FunctionResponseChatMessage = {
48
54
  /** If true, this message marks a breakpoint when used with prompt caching (as of right now, Anthropic-only). */
49
55
  isCacheBreakpoint?: boolean;
50
56
  };
51
- export type ChatMessage = SystemChatMessage | UserChatMessage | AssistantChatMessage | FunctionResponseChatMessage;
57
+ export type ChatMessage = SystemChatMessage | DeveloperChatMessage | UserChatMessage | AssistantChatMessage | FunctionResponseChatMessage;
52
58
  export type ChatMessageMessagePart = string | {
53
59
  type: 'image';
54
60
  mediaType: SupportedImageMediaTypes;
@@ -1,11 +1,11 @@
1
1
  import type { DataValue, ScalarOrArrayDataValue, StringArrayDataValue } from './DataValue.js';
2
2
  import type { Dataset, DatasetId, DatasetMetadata, DatasetRow } from './Dataset.js';
3
- import type { ChartNode, NodeId, PortId } from './NodeBase.js';
3
+ import type { ChartNode, NodeConnection, NodeId, PortId } from './NodeBase.js';
4
4
  import type { GraphId, NodeGraph } from './NodeGraph.js';
5
- import type { GraphExecutionMetadata, ProcessId } from './ProcessContext.js';
5
+ import type { ChatV2CallTraceEvent, GraphExecutionMetadata, ProcessId, ToolCallFinishedEvent } from './ProcessContext.js';
6
6
  import type { Project, ProjectId } from './Project.js';
7
7
  import type { Settings } from './Settings.js';
8
- import type { FrozenNodeOutputsByGraph } from './GraphProcessor.js';
8
+ import type { FrozenNodeOutputsByGraph, NodeResultOrigin } from './GraphProcessor.js';
9
9
  import type { GraphProgress } from './GraphProgress.js';
10
10
  import type { RivetWebAppStorage } from './UiGraphWebAppStorage.js';
11
11
  export type GraphInputs = Record<string, DataValue>;
@@ -55,12 +55,15 @@ export type SerializedProcessEventMap = {
55
55
  nodeStart: WithExecution<{
56
56
  node: ChartNode;
57
57
  inputs: Inputs;
58
+ inputConnections?: NodeConnection[];
58
59
  processId: ProcessId;
60
+ resultOrigin?: NodeResultOrigin;
59
61
  }>;
60
62
  nodeFinish: WithExecution<{
61
63
  node: ChartNode;
62
64
  outputs: Outputs;
63
65
  processId: ProcessId;
66
+ resultOrigin?: NodeResultOrigin;
64
67
  durationMs?: number;
65
68
  splitRunDurationMs?: Record<number, number>;
66
69
  }>;
@@ -68,6 +71,7 @@ export type SerializedProcessEventMap = {
68
71
  node: ChartNode;
69
72
  error: Error | string;
70
73
  processId: ProcessId;
74
+ resultOrigin?: NodeResultOrigin;
71
75
  durationMs?: number;
72
76
  splitRunDurationMs?: Record<number, number>;
73
77
  }>;
@@ -77,6 +81,7 @@ export type SerializedProcessEventMap = {
77
81
  inputs: Inputs;
78
82
  outputs: Outputs;
79
83
  reason: string;
84
+ resultOrigin?: NodeResultOrigin;
80
85
  }>;
81
86
  userInput: WithExecution<{
82
87
  node: ChartNode;
@@ -84,18 +89,23 @@ export type SerializedProcessEventMap = {
84
89
  inputs: Inputs;
85
90
  processId: ProcessId;
86
91
  renderingType: 'text' | 'markdown';
92
+ /** See ProcessEvents.userInput.isReplay. */
93
+ isReplay?: true;
87
94
  }>;
88
95
  partialOutput: WithExecution<{
89
96
  node: ChartNode;
90
97
  outputs: Outputs;
91
98
  index: number;
92
99
  processId: ProcessId;
100
+ resultOrigin?: NodeResultOrigin;
93
101
  }>;
94
102
  progress: WithExecution<{
95
103
  node: ChartNode;
96
104
  processId: ProcessId;
97
105
  progress: GraphProgress;
98
106
  }>;
107
+ llmCallFinished: WithExecution<ChatV2CallTraceEvent>;
108
+ toolCallFinished: WithExecution<ToolCallFinishedEvent>;
99
109
  nodeOutputsCleared: WithExecution<{
100
110
  node: ChartNode;
101
111
  processId?: ProcessId;
@@ -112,8 +122,14 @@ export type SerializedProcessEventMap = {
112
122
  };
113
123
  finish: void;
114
124
  trace: string;
115
- pause: void;
116
- resume: void;
125
+ /** Present only when RecordingPlayer re-emits a historical lifecycle transition. */
126
+ pause: {
127
+ isReplay?: true;
128
+ } | undefined;
129
+ /** Present only when RecordingPlayer re-emits a historical lifecycle transition. */
130
+ resume: {
131
+ isReplay?: true;
132
+ } | undefined;
117
133
  globalSet: WithExecution<{
118
134
  id: string;
119
135
  value: ScalarOrArrayDataValue;
@@ -144,12 +160,14 @@ export type ProcessEventMessageMap = {
144
160
  graphOutputsReady: SerializedProcessEventMap['graphOutputsReady'];
145
161
  partialOutput: SerializedProcessEventMap['partialOutput'];
146
162
  progress: SerializedProcessEventMap['progress'];
163
+ llmCallFinished: SerializedProcessEventMap['llmCallFinished'];
164
+ toolCallFinished: SerializedProcessEventMap['toolCallFinished'];
147
165
  nodeOutputsCleared: SerializedProcessEventMap['nodeOutputsCleared'];
148
166
  error: SerializedProcessEventMap['error'];
149
167
  graphError: SerializedProcessEventMap['graphError'];
150
168
  trace: string;
151
- pause: void;
152
- resume: void;
169
+ pause: SerializedProcessEventMap['pause'];
170
+ resume: SerializedProcessEventMap['resume'];
153
171
  };
154
172
  export type GraphUploadAllowedMessage = {
155
173
  message: 'graph-upload-allowed';