@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
@@ -55,6 +55,12 @@ export const ChatAnthropicNodeImpl = {
55
55
  };
56
56
  return chartNode;
57
57
  },
58
+ getRunActivityDescriptor() {
59
+ return {
60
+ category: 'model',
61
+ primaryOutputPortId: 'response',
62
+ };
63
+ },
58
64
  getInputDefinitions(data) {
59
65
  const inputs = [];
60
66
  if (data.model.startsWith('claude-3')) {
@@ -394,6 +400,7 @@ export const ChatAnthropicNodeImpl = {
394
400
  if (data.cache) {
395
401
  const cached = cache.get(cacheKey);
396
402
  if (cached) {
403
+ context.markResultAsEditorCacheHit?.();
397
404
  return cached;
398
405
  }
399
406
  }
@@ -4,5 +4,4 @@
4
4
  export { init } from '@gentrace/core/dist/providers/init.mjs';
5
5
  export { getPipelines } from '@gentrace/core/dist/providers/pipeline-methods.mjs';
6
6
  export { Pipeline } from '@gentrace/core/dist/providers/pipeline.mjs';
7
- export { runTest } from '@gentrace/core/dist/providers/run-test.mjs';
8
7
  export { StepRun } from '@gentrace/core/dist/providers/step-run.mjs';
@@ -1,3 +1,2 @@
1
- // eslint-disable-next-line import/no-cycle -- The plugin implementation uses GraphProcessor to execute local Gentrace tests.
2
1
  import { gentracePlugin } from './plugin.js';
3
2
  export default gentracePlugin;
@@ -1,12 +1,4 @@
1
- import { Pipeline, StepRun, init, runTest, getPipelines } from './gentraceSdk.js';
2
- import { globalRivetNodeRegistry } from '../../model/Nodes.js';
3
- import { cloneDeep, mapValues } from 'lodash-es';
4
- import { GptTokenizerTokenizer } from '../../integrations/GptTokenizerTokenizer.js';
5
- import { ExecutionRecorder } from '../../recording/ExecutionRecorder.js';
6
- import { inferType } from '../../utils/coerceType.js';
7
- // eslint-disable-next-line import/no-cycle -- Local Gentrace execution intentionally depends on GraphProcessor.
8
- import { GraphProcessor } from '../../model/GraphProcessor.js';
9
- import { resolveProcessSettings } from '../../api/processSettings.js';
1
+ import { Pipeline, StepRun, getPipelines, init } from './gentraceSdk.js';
10
2
  const apiKeyConfigSpec = {
11
3
  type: 'secret',
12
4
  label: 'Gentrace API Key',
@@ -15,183 +7,73 @@ const apiKeyConfigSpec = {
15
7
  helperText: 'Create at https://gentrace.ai/settings/api-keys',
16
8
  };
17
9
  function initializeGentrace(gentraceApiKey) {
18
- init({
19
- apiKey: gentraceApiKey,
20
- });
21
- }
22
- export const runGentraceTests = async (gentracePipelineSlug, settings, project, graph, nativeApi, contextValues = {}) => {
23
- const gentraceApiKey = settings.pluginSettings?.gentrace?.gentraceApiKey;
24
- if (!gentraceApiKey) {
10
+ if (!gentraceApiKey)
25
11
  throw new Error('Gentrace API key not set.');
12
+ init({ apiKey: gentraceApiKey });
13
+ }
14
+ function timestampForTrial(run, durationMs, index) {
15
+ const runStart = Date.parse(run.startedAt);
16
+ const safeStart = Number.isFinite(runStart) ? runStart + index : Date.now();
17
+ const safeDuration = Number.isFinite(durationMs) && durationMs >= 0 ? durationMs : 0;
18
+ return {
19
+ start: new Date(safeStart).toISOString(),
20
+ end: new Date(safeStart + safeDuration).toISOString(),
21
+ };
22
+ }
23
+ /**
24
+ * Exports an already completed Rivet Evaluation as one Gentrace pipeline run.
25
+ * It never fetches Gentrace test cases and never executes a Rivet graph: the
26
+ * generic Evaluations runner remains the sole execution engine.
27
+ */
28
+ export async function exportGentraceEvaluationRun(input) {
29
+ initializeGentrace(input.gentraceApiKey);
30
+ if (!input.pipelineSlug)
31
+ throw new Error('Gentrace pipeline slug is required.');
32
+ if (input.run.executionStatus !== 'completed') {
33
+ throw new Error('Only completed Rivet Evaluation runs can be exported to Gentrace.');
26
34
  }
27
- const graphId = graph.metadata?.id;
28
- if (!graphId) {
29
- throw new Error('Graph ID not set.');
30
- }
31
- initializeGentrace(gentraceApiKey);
32
- const response = await runTest(gentracePipelineSlug, async (testCase) => {
33
- const pipeline = new Pipeline({
34
- slug: gentracePipelineSlug,
35
- });
36
- const runner = pipeline.start();
37
- const rivetFormattedInputs = mapValues(testCase.inputs, inferType);
38
- const tempProject = {
39
- ...project,
40
- graphs: {
41
- ...project.graphs,
42
- [graph.metadata.id]: graph,
43
- },
44
- };
45
- const recorder = new ExecutionRecorder();
46
- const processor = new GraphProcessor(tempProject, graphId, globalRivetNodeRegistry);
47
- processor.executor = 'browser';
48
- recorder.record(processor);
49
- const runContextValues = cloneDeep(contextValues);
50
- await processor.processGraph({
51
- settings: resolveProcessSettings(settings),
52
- nativeApi,
53
- tokenizer: new GptTokenizerTokenizer(),
54
- }, rivetFormattedInputs, runContextValues);
55
- const fullRecording = recorder.getRecording();
56
- const stepRuns = convertRecordingToStepRuns(fullRecording, project, graphId);
57
- for (const stepRun of stepRuns) {
58
- await runner.addStepRunNode(stepRun);
59
- }
60
- if (stepRuns.length === 0) {
61
- throw new Error('No Rivet steps found. You need operations which are not Graph Input or Graph Output nodes.');
62
- }
63
- return ['', runner];
64
- });
65
- return response;
66
- };
67
- export const runRemoteGentraceTests = async (gentracePipelineSlug, settings, project, graph, runAndRecord) => {
68
- const gentraceApiKey = settings.pluginSettings?.gentrace?.gentraceApiKey;
69
- if (!gentraceApiKey) {
70
- throw new Error('Gentrace API key not set.');
71
- }
72
- const graphId = graph.metadata?.id;
73
- if (!graphId) {
74
- throw new Error('Graph ID not set.');
75
- }
76
- initializeGentrace(gentraceApiKey);
77
- const response = await runTest(gentracePipelineSlug, async (testCase) => {
78
- const pipeline = new Pipeline({
79
- slug: gentracePipelineSlug,
80
- });
81
- const runner = pipeline.start();
82
- const rivetFormattedInputs = mapValues(testCase.inputs, inferType);
83
- const fullRecording = await runAndRecord(rivetFormattedInputs);
84
- const stepRuns = convertRecordingToStepRuns(fullRecording, project, graphId);
85
- for (const stepRun of stepRuns) {
86
- await runner.addStepRunNode(stepRun);
87
- }
88
- if (stepRuns.length === 0) {
89
- throw new Error('No Rivet steps found. You need operations which are not Graph Input or Graph Output nodes.');
90
- }
91
- return ['', runner];
92
- });
93
- return response;
94
- };
95
- function convertRecordingToStepRuns(recording, project, graphId) {
96
- const partialProcessStartEndPairs = {};
97
- recording.events.forEach((event) => {
98
- const eventType = event?.type;
99
- if (!eventType) {
100
- return;
101
- }
102
- if (eventType === 'nodeStart' || eventType === 'nodeFinish') {
103
- const processId = event?.data?.processId;
104
- const nodeId = event?.data?.nodeId;
105
- if (!processId) {
106
- return;
107
- }
108
- let existingPair = partialProcessStartEndPairs[processId];
109
- if (!existingPair) {
110
- existingPair = {};
111
- partialProcessStartEndPairs[processId] = existingPair;
112
- }
113
- existingPair.nodeId = nodeId;
114
- if (eventType === 'nodeStart') {
115
- existingPair.start = event.ts;
116
- existingPair.inputs = event.data.inputs;
117
- }
118
- else {
119
- existingPair.end = event.ts;
120
- existingPair.outputs = event.data.outputs;
121
- }
122
- }
35
+ const pipeline = new Pipeline({ slug: input.pipelineSlug });
36
+ const runner = pipeline.start({
37
+ metadata: {
38
+ source: { type: 'string', value: 'rivet-evaluations' },
39
+ evaluationRunId: { type: 'string', value: input.run.id },
40
+ suiteName: { type: 'string', value: input.run.suiteName },
41
+ purpose: { type: 'string', value: input.run.purpose },
42
+ qualityStatus: { type: 'string', value: input.run.qualityStatus },
43
+ qualityReason: { type: 'string', value: input.run.qualityReason.message },
44
+ accountingStatus: { type: 'string', value: input.run.accountingStatus },
45
+ executionStatus: { type: 'string', value: input.run.executionStatus },
46
+ },
123
47
  });
124
- const processStartEndPairs = partialProcessStartEndPairs;
125
- const selectedGraph = project.graphs[graphId];
126
- if (!selectedGraph) {
127
- return [];
128
- }
129
- // Convert to step runs
130
- const stepRuns = [];
131
- for (const [, pair] of Object.entries(processStartEndPairs)) {
132
- const { nodeId } = pair;
133
- const relatedNode = selectedGraph.nodes.find((node) => node.id === nodeId);
134
- const nodeType = relatedNode?.type;
135
- if (!nodeType || !relatedNode.data || nodeType === 'graphInput' || nodeType === 'graphOutput') {
136
- continue;
137
- }
138
- const nodeData = relatedNode.data;
139
- if (relatedNode) {
140
- pair.modelParams = { ...nodeData, ...{ type: nodeType } };
141
- }
142
- if (nodeType === 'chat') {
143
- const modelName = nodeData.model ? nodeData.model : '';
144
- if (modelName.startsWith('gpt')) {
145
- // Convert to OpenAI Gentrace node
146
- const gentraceOpenAIInputs = { ...pair.inputs };
147
- gentraceOpenAIInputs.messages = [
148
- {
149
- content: pair.inputs.prompt.value,
150
- role: 'user',
151
- },
152
- ];
153
- const gentraceOpenAIModelParams = { ...pair.modelParams };
154
- gentraceOpenAIModelParams.model = modelName;
155
- gentraceOpenAIModelParams.frequency_penalty = pair.modelParams.frequencyPenalty || null;
156
- gentraceOpenAIModelParams.max_tokens = pair.modelParams.maxTokens || undefined;
157
- gentraceOpenAIModelParams.presence_penalty = pair.modelParams.presencePenalty || null;
158
- gentraceOpenAIModelParams.stop = pair.modelParams.stop || null;
159
- gentraceOpenAIModelParams.temperature = pair.modelParams.temperature || null;
160
- gentraceOpenAIModelParams.top_p = pair.modelParams.top_p || null;
161
- const gentraceOpenAIOutputs = { ...pair.outputs };
162
- const outputValues = Array.isArray(pair.outputs.response.value)
163
- ? pair.outputs.response.value
164
- : [pair.outputs.response.value];
165
- gentraceOpenAIOutputs.choices = outputValues.map((outputValue, index) => {
166
- return {
167
- index,
168
- message: {
169
- content: outputValue,
170
- role: 'assistant',
171
- },
172
- usage: {
173
- completion_tokens: pair.outputs.responseTokens.value,
174
- prompt_tokens: pair.outputs.requestTokens.value,
175
- total_tokens: pair.outputs.responseTokens.value + pair.outputs.requestTokens.value,
176
- },
177
- };
178
- });
179
- stepRuns.push(new StepRun('openai', 'openai_createChatCompletion', pair.end - pair.start, new Date(pair.start).toISOString(), new Date(pair.end).toISOString(), gentraceOpenAIInputs, gentraceOpenAIModelParams, gentraceOpenAIOutputs, {}, undefined));
180
- continue;
181
- }
182
- }
183
- stepRuns.push(new StepRun('rivet', nodeType ? `rivet_operation_${nodeType}` : 'rivet_operation', pair.end - pair.start, new Date(pair.start).toISOString(), new Date(pair.end).toISOString(), pair.inputs, pair.modelParams, pair.outputs, {}, undefined));
48
+ for (const [index, trial] of input.run.trials.entries()) {
49
+ const durationMs = typeof trial.totalMetrics.durationMs === 'number' ? trial.totalMetrics.durationMs : 0;
50
+ const { start, end } = timestampForTrial(input.run, durationMs, index);
51
+ await runner.addStepRunNode(new StepRun('rivet', 'rivet_evaluation_trial', durationMs, start, end, {
52
+ caseId: trial.caseId,
53
+ caseName: trial.caseName,
54
+ trialIndex: trial.trialIndex,
55
+ inputs: trial.inputs,
56
+ expected: trial.expected,
57
+ }, {
58
+ source: 'rivet-evaluations',
59
+ purpose: input.run.purpose,
60
+ }, {
61
+ executionStatus: trial.executionStatus,
62
+ qualityStatus: trial.qualityStatus,
63
+ qualityReason: trial.qualityReason,
64
+ outputs: trial.outputs,
65
+ observations: trial.observations,
66
+ metrics: trial.totalMetrics,
67
+ }, {}, trial.error));
184
68
  }
185
- return stepRuns;
69
+ return (await runner.submit({ waitForServer: true }));
186
70
  }
187
- export const getGentracePipelines = async (gentraceApiKey) => {
71
+ export async function getGentracePipelines(gentraceApiKey) {
188
72
  initializeGentrace(gentraceApiKey);
189
- return await getPipelines();
190
- };
73
+ return getPipelines();
74
+ }
191
75
  export const gentracePlugin = {
192
76
  id: 'gentrace',
193
77
  name: 'Gentrace',
194
- configSpec: {
195
- gentraceApiKey: apiKeyConfigSpec,
196
- },
78
+ configSpec: { gentraceApiKey: apiKeyConfigSpec },
197
79
  };
@@ -60,20 +60,16 @@ export const generativeAiGoogleModels = {
60
60
  },
61
61
  'gemini-1.5-pro': {
62
62
  maxTokens: 2097152,
63
- cost: {
64
- prompt: 0, // It's per-character wtf
65
- completion: 0, // It's per-character
66
- },
67
63
  displayName: 'Gemini 1.5 Pro',
64
+ // The retained legacy model stays selectable, but its old catalog did not
65
+ // carry a reliable token rate. Do not turn that absence into a false $0.
66
+ pricing: 'unpriced',
68
67
  },
69
68
  'gemini-1.5-flash': {
70
69
  maxTokens: 1048576,
71
- cost: {
72
- prompt: 0, // It's per-character wtf
73
- completion: 0, // It's per-character
74
- },
75
70
  displayName: 'Gemini 1.5 Flash',
76
- }
71
+ pricing: 'unpriced',
72
+ },
77
73
  };
78
74
  export const googleModelOptionsDeprecated = Object.entries(googleModelsDeprecated).map(([id, { displayName }]) => ({
79
75
  value: id,
@@ -395,7 +395,9 @@ export const ChatGoogleNodeImpl = {
395
395
  type: Type.OBJECT,
396
396
  properties: mapValues(parameters.properties ?? {}, (property) => ({
397
397
  // gemini doesn't support union property types, it uses openapi style not jsonschema, what a mess
398
- 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),
399
401
  description: property.description,
400
402
  })),
401
403
  required: parameters.required ?? [],
@@ -447,6 +449,7 @@ export const ChatGoogleNodeImpl = {
447
449
  if (data.cache) {
448
450
  const cached = cache.get(cacheKey);
449
451
  if (cached) {
452
+ context.markResultAsEditorCacheHit?.();
450
453
  return cached;
451
454
  }
452
455
  }
@@ -3,9 +3,8 @@ import autoevalsPlugin from './plugins/autoevals/index.js';
3
3
  import assemblyAiPlugin from './plugins/assemblyAi/index.js';
4
4
  import { huggingFacePlugin } from './plugins/huggingface/plugin.js';
5
5
  import pineconePlugin from './plugins/pinecone/index.js';
6
- // eslint-disable-next-line import/no-cycle -- Gentrace depends on GraphProcessor for local test execution.
7
6
  import gentracePlugin from './plugins/gentrace/index.js';
8
- export { getGentracePipelines, runGentraceTests, runRemoteGentraceTests } from './plugins/gentrace/plugin.js';
7
+ export { exportGentraceEvaluationRun, getGentracePipelines } from './plugins/gentrace/plugin.js';
9
8
  import { openAIPlugin } from './plugins/openai/plugin.js';
10
9
  import { googlePlugin } from './plugins/google/plugin.js';
11
10
  export { anthropicPlugin, autoevalsPlugin, assemblyAiPlugin, pineconePlugin, huggingFacePlugin, gentracePlugin, googlePlugin, };
@@ -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,21 @@ 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
+ llmProfileAttempt: ({ execution, ...event }) => ({ ...event, execution }),
82
+ toolCallFinished: ({ execution, ...event }) => ({ ...event, execution }),
74
83
  nodeOutputsCleared: ({ node, processId, execution }) => withExecution({
75
84
  nodeId: node.id,
76
85
  processId,
@@ -108,13 +117,28 @@ function toRecordedEvent(event, data) {
108
117
  ts: Date.now(),
109
118
  };
110
119
  }
120
+ const recordableData = omitReplayRecordedAt(data);
111
121
  const recordedEvent = {
112
122
  type: event,
113
- data: toRecordedEventMap[event](data),
123
+ data: toRecordedEventMap[event](recordableData),
114
124
  ts: Date.now(),
115
125
  };
116
126
  return recordedEvent;
117
127
  }
128
+ /**
129
+ * Replay provenance belongs to the current delivery, not the historical event
130
+ * itself. If a replay is recorded again, the recorder's own `ts` is the one
131
+ * authoritative timestamp to persist.
132
+ */
133
+ function omitReplayRecordedAt(data) {
134
+ if (data == null || typeof data !== 'object')
135
+ return data;
136
+ const { replayRecordedAt: _replayRecordedAt, ...recordableData } = data;
137
+ return recordableData;
138
+ }
139
+ function isRecordableProcessEvent(message) {
140
+ return message in toRecordedEventMap || isPrefix(message, 'globalSet:') || isPrefix(message, 'userEvent:');
141
+ }
118
142
  function mapValuesDeep(obj, fn) {
119
143
  if (Array.isArray(obj)) {
120
144
  return obj.map((value) => {
@@ -204,18 +228,39 @@ export class ExecutionRecorder {
204
228
  on = undefined;
205
229
  off = undefined;
206
230
  once = undefined;
207
- recordSocket(channel) {
231
+ recordSocket(channel, options = {}) {
208
232
  return new Promise((resolve) => {
209
233
  this.recordingId = nanoid();
234
+ let settled = false;
235
+ const finish = () => {
236
+ if (settled)
237
+ return;
238
+ settled = true;
239
+ channel.removeEventListener('message', listener);
240
+ options.signal?.removeEventListener('abort', finish);
241
+ resolve();
242
+ };
210
243
  const listener = (event) => {
211
- const { message, data } = JSON.parse(event.data);
212
- if (this.#includePartialOutputs === false && message === 'partialOutput') {
244
+ let payload;
245
+ try {
246
+ payload = JSON.parse(event.data);
247
+ }
248
+ catch {
249
+ // A debugger socket can carry control-plane payloads alongside graph
250
+ // events. They are not part of a replayable graph recording.
213
251
  return;
214
252
  }
215
- if (this.#includeTrace === false && message === 'trace') {
253
+ const { message, data, requestId } = payload;
254
+ if (typeof message !== 'string' || !isRecordableProcessEvent(message)) {
216
255
  return;
217
256
  }
218
- if (message === 'codeConsole') {
257
+ if (options.requestId !== undefined && requestId !== options.requestId) {
258
+ return;
259
+ }
260
+ if (this.#includePartialOutputs === false && message === 'partialOutput') {
261
+ return;
262
+ }
263
+ if (this.#includeTrace === false && message === 'trace') {
219
264
  return;
220
265
  }
221
266
  this.#events.push(toRecordedEvent(message, data));
@@ -223,11 +268,15 @@ export class ExecutionRecorder {
223
268
  emitDetached(this.#emitter, 'finish', {
224
269
  recording: this.getRecording(),
225
270
  });
226
- channel.removeEventListener('message', listener);
227
- resolve();
271
+ finish();
228
272
  }
229
273
  };
274
+ if (options.signal?.aborted) {
275
+ finish();
276
+ return;
277
+ }
230
278
  channel.addEventListener('message', listener);
279
+ options.signal?.addEventListener('abort', finish, { once: true });
231
280
  });
232
281
  }
233
282
  record(processor) {
@@ -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
  },