@valerypopoff/rivet2-core 2.4.0 → 2.6.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 (82) hide show
  1. package/dist/cjs/bundle.cjs +1800 -753
  2. package/dist/cjs/bundle.cjs.map +4 -4
  3. package/dist/cjs/interpolationRuntime.cjs +1578 -0
  4. package/dist/cjs/interpolationRuntime.cjs.map +7 -0
  5. package/dist/cjs/interpolationSyntax.cjs +186 -0
  6. package/dist/cjs/interpolationSyntax.cjs.map +7 -0
  7. package/dist/cjs/webAppRuntime.cjs.map +2 -2
  8. package/dist/esm/exports.js +2 -1
  9. package/dist/esm/integrations/CodeRunner.js +5 -0
  10. package/dist/esm/integrations/mcp/MCPBase.js +16 -6
  11. package/dist/esm/interpolationRuntime.js +5 -0
  12. package/dist/esm/model/AgentResponseTrace.js +8 -3
  13. package/dist/esm/model/GraphBoundaryCache.js +0 -6
  14. package/dist/esm/model/GraphBoundaryEffects.js +5 -1
  15. package/dist/esm/model/GraphOutputSelection.js +34 -0
  16. package/dist/esm/model/GraphProcessor.js +177 -50
  17. package/dist/esm/model/ProcessContextBuilder.js +4 -1
  18. package/dist/esm/model/RecordingPlayer.js +46 -14
  19. package/dist/esm/model/SplitRunProcessor.js +37 -16
  20. package/dist/esm/model/StoredValueStore.js +4 -3
  21. package/dist/esm/model/UiGraphRendererStyles.js +20 -0
  22. package/dist/esm/model/chat/aiSdkStreaming.js +3 -2
  23. package/dist/esm/model/chat-v2/aiSdkBridge.js +63 -5
  24. package/dist/esm/model/chat-v2/chatV2Pipeline.js +66 -3
  25. package/dist/esm/model/chat-v2/llmInvocationResultProjector.js +20 -7
  26. package/dist/esm/model/chat-v2/llmProfileFallback.js +12 -4
  27. package/dist/esm/model/nodes/CodeNewNode.js +16 -16
  28. package/dist/esm/model/nodes/DestructureNode.js +2 -2
  29. package/dist/esm/model/nodes/ExpressionNode.js +16 -16
  30. package/dist/esm/model/nodes/ExtractObjectPathNode.js +2 -2
  31. package/dist/esm/model/nodes/ExtractYamlNode.js +5 -5
  32. package/dist/esm/model/nodes/JSFilterNode.js +3 -1
  33. package/dist/esm/model/nodes/JSMapNode.js +3 -1
  34. package/dist/esm/model/nodes/LLMChatV2Node.js +30 -4
  35. package/dist/esm/model/nodes/MCPGetPromptNode.js +6 -2
  36. package/dist/esm/model/nodes/MCPToolCallNode.js +6 -2
  37. package/dist/esm/model/nodes/ObjectNode.js +19 -20
  38. package/dist/esm/model/nodes/PromptNode.js +10 -11
  39. package/dist/esm/model/nodes/ReferencedGraphAliasNode.js +2 -40
  40. package/dist/esm/model/nodes/SubGraphNode.js +40 -26
  41. package/dist/esm/model/nodes/TextNode.js +11 -32
  42. package/dist/esm/model/nodes/ToTreeNode.js +6 -13
  43. package/dist/esm/model/nodes/ToolNode.js +33 -16
  44. package/dist/esm/model/nodes/jsListCallbackHelpers.js +19 -15
  45. package/dist/esm/model/nodes/jsValueInterpolation.js +83 -30
  46. package/dist/esm/model/nodes/nodeBodyPreview.js +23 -0
  47. package/dist/esm/plugins/openai/nodes/ThreadMessageNode.js +14 -11
  48. package/dist/esm/recording/ExecutionRecorder.js +55 -23
  49. package/dist/esm/utils/index.js +2 -0
  50. package/dist/esm/utils/interpolation.js +478 -221
  51. package/dist/esm/utils/interpolationSyntax.js +175 -0
  52. package/dist/esm/utils/jsonPath.js +129 -0
  53. package/dist/types/exports.d.ts +3 -1
  54. package/dist/types/integrations/CodeRunnerOptions.d.ts +9 -0
  55. package/dist/types/integrations/mcp/MCPBase.d.ts +3 -1
  56. package/dist/types/interpolationRuntime.d.ts +5 -0
  57. package/dist/types/model/AgentResponseTrace.d.ts +2 -0
  58. package/dist/types/model/ExecutorProtocol.d.ts +4 -0
  59. package/dist/types/model/GraphBoundaryCache.d.ts +0 -2
  60. package/dist/types/model/GraphOutputSelection.d.ts +8 -0
  61. package/dist/types/model/GraphProcessor.d.ts +12 -3
  62. package/dist/types/model/ProcessContext.d.ts +9 -2
  63. package/dist/types/model/ProcessContextBuilder.d.ts +2 -1
  64. package/dist/types/model/SplitRunProcessor.d.ts +2 -1
  65. package/dist/types/model/UiGraphRendererStyles.d.ts +1 -1
  66. package/dist/types/model/chat/aiSdkStreaming.d.ts +1 -1
  67. package/dist/types/model/chat-v2/chatV2RequestPlan.d.ts +1 -1
  68. package/dist/types/model/chat-v2/chatV2Types.d.ts +29 -0
  69. package/dist/types/model/chat-v2/llmInvocationResultProjector.d.ts +5 -1
  70. package/dist/types/model/nodes/ObjectNode.d.ts +1 -1
  71. package/dist/types/model/nodes/SubGraphNode.d.ts +2 -0
  72. package/dist/types/model/nodes/ToTreeNode.d.ts +5 -2
  73. package/dist/types/model/nodes/ToolNode.d.ts +13 -1
  74. package/dist/types/model/nodes/jsValueInterpolation.d.ts +16 -8
  75. package/dist/types/model/nodes/nodeBodyPreview.d.ts +7 -0
  76. package/dist/types/recording/ExecutionRecorder.d.ts +6 -1
  77. package/dist/types/recording/RecordedEvents.d.ts +2 -0
  78. package/dist/types/utils/index.d.ts +2 -0
  79. package/dist/types/utils/interpolation.d.ts +93 -8
  80. package/dist/types/utils/interpolationSyntax.d.ts +21 -0
  81. package/dist/types/utils/jsonPath.d.ts +15 -0
  82. package/package.json +11 -1
@@ -66,7 +66,8 @@ export * from './integrations/Tokenizer.js';
66
66
  export * from './integrations/GptTokenizerTokenizer.js';
67
67
  export { JS_LIST_CALLBACK_LOCAL_NAMES, interpolateJSListCallbackBody } from './model/nodes/jsListCallbackHelpers.js';
68
68
  export { findAutoDelegateGraphCandidate } from './model/nodes/toolCallDelegation.js';
69
- export { extractInterpolationVariables, findInterpolationTokenSpans, getInterpolationTokenName, interpolate, protectEscapedInterpolationTokens, restoreEscapedInterpolationTokens, } from './utils/interpolation.js';
69
+ export { extractInterpolationVariables, extractInterpolationVariableReferences, findInterpolationTokenSpans, getInterpolationTokenReference, getInterpolationTokenName, interpolate, parseInterpolationExpression, parseInterpolationTemplate, protectEscapedInterpolationTokens, resolveCodeInterpolationExpression, resolveInterpolationExpressionRawValue, resolveInterpolationTokenRawValue, restoreEscapedInterpolationTokens, stringifyInterpolationSourceValue, } from './utils/interpolation.js';
70
+ export { scanInterpolationTokenSpans } from './utils/interpolationSyntax.js';
70
71
  export { WarningsPort } from './utils/symbols.js';
71
72
  import * as openai from './utils/openai.js';
72
73
  export { openai };
@@ -1,3 +1,4 @@
1
+ import { resolveCodeInterpolationExpression } from '../utils/interpolation.js';
1
2
  // eslint-disable-next-line import/no-cycle -- Authored code receives the complete public Rivet namespace at execution time.
2
3
  import * as Rivet from '../exports.js';
3
4
  export { ALL_CODE_RUNNER_OPTIONS } from './CodeRunnerOptions.js';
@@ -25,6 +26,10 @@ export class IsomorphicCodeRunner {
25
26
  argNames.push('context');
26
27
  args.push(contextValues);
27
28
  }
29
+ if (options.interpolationHelperIdentifier) {
30
+ argNames.push(options.interpolationHelperIdentifier);
31
+ args.push(resolveCodeInterpolationExpression);
32
+ }
28
33
  argNames.push(code);
29
34
  const AsyncFunction = async function () { }.constructor;
30
35
  const codeFunction = new AsyncFunction(...argNames);
@@ -1,6 +1,6 @@
1
- import { coerceTypeOptional } from '../../utils/coerceType.js';
1
+ import { createInterpolationInputDefinition } from '../../model/interpolationInputDefinition.js';
2
2
  import { getInputOrData } from '../../utils/inputs.js';
3
- import { interpolate } from '../../utils/interpolation.js';
3
+ import { extractInterpolationVariables, interpolate } from '../../utils/interpolation.js';
4
4
  import { keys } from '../../utils/typeSafety.js';
5
5
  import { MCPError, MCPErrorType } from './MCPProvider.js';
6
6
  import { getServerHelperMessage, getServerOptions, loadMCPConfiguration } from './MCPUtils.js';
@@ -134,12 +134,22 @@ export async function resolveMCPServer(data, inputs, context) {
134
134
  }
135
135
  return undefined;
136
136
  }
137
- export function interpolateMCPArgumentTemplate(template, inputs) {
137
+ export function interpolateMCPArgumentTemplate(template, inputs, graphInputValues, contextValues) {
138
138
  const values = {};
139
139
  for (const key of keys(inputs)) {
140
- if (key.startsWith('input')) {
141
- values[key.slice('input-'.length)] = coerceTypeOptional(inputs[key], 'string') ?? '';
140
+ if (key.startsWith('input-')) {
141
+ values[key.slice('input-'.length)] = inputs[key];
142
142
  }
143
143
  }
144
- return interpolate(template, values);
144
+ return interpolate(template, values, graphInputValues, contextValues, {
145
+ coerceBareVariableDataValues: true,
146
+ });
147
+ }
148
+ export function getMCPArgumentTemplateInputs(template) {
149
+ return extractInterpolationVariables(template ?? '').map((interpolationName) => createInterpolationInputDefinition({
150
+ id: `input-${interpolationName}`,
151
+ interpolationName,
152
+ dataType: 'any',
153
+ required: false,
154
+ }));
145
155
  }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Narrow runtime entrypoint for JavaScript executors. Build tooling can bundle
3
+ * this module into isolated workers without exposing the complete Core API.
4
+ */
5
+ export { resolveCodeInterpolationExpression } from './utils/interpolation.js';
@@ -29,6 +29,13 @@ export function buildAgentResponseTrace(options) {
29
29
  .map(toToolCallTrace);
30
30
  const summary = summarizeAgentCalls(allModelCalls, allProfileAttempts, allToolCalls);
31
31
  const terminalAt = options.responseReadyAt ?? options.finishedAt;
32
+ const durationMs = options.scope === 'llm-invocation' && isNonNegativeFiniteNumber(options.invocationDurationMs)
33
+ ? options.invocationDurationMs
34
+ : isNonNegativeFiniteNumber(options.startedAt) &&
35
+ isNonNegativeFiniteNumber(terminalAt) &&
36
+ terminalAt >= options.startedAt
37
+ ? terminalAt - options.startedAt
38
+ : undefined;
32
39
  return {
33
40
  schemaVersion: AGENT_RESPONSE_TRACE_SCHEMA_VERSION,
34
41
  traceId: options.execution.rootRunId,
@@ -41,9 +48,7 @@ export function buildAgentResponseTrace(options) {
41
48
  ...(options.startedAt == null ? {} : { startedAt: options.startedAt }),
42
49
  ...(options.responseReadyAt == null ? {} : { responseReadyAt: options.responseReadyAt }),
43
50
  ...(options.finishedAt == null ? {} : { finishedAt: options.finishedAt }),
44
- ...(options.startedAt == null || terminalAt == null
45
- ? {}
46
- : { durationMs: Math.max(0, terminalAt - options.startedAt) }),
51
+ ...(durationMs === undefined ? {} : { durationMs }),
47
52
  status: options.status,
48
53
  ...(options.backgroundWorkPending == null ? {} : { backgroundWorkPending: options.backgroundWorkPending }),
49
54
  summary,
@@ -1,4 +1,3 @@
1
- export const GRAPH_BOUNDARY_OUTPUT_DEMAND_OPTIMIZATION_ENABLED = false;
2
1
  export function getGraphBoundary(project, graphId, cache) {
3
2
  if (!graphId) {
4
3
  return undefined;
@@ -82,11 +81,6 @@ export function buildExcludedGraphBoundaryOutputs(boundary) {
82
81
  }
83
82
  return outputs;
84
83
  }
85
- export function getRequestedGraphOutputNodeIds(boundary, requestedOutputPortIds) {
86
- return boundary.outputs
87
- .filter((output) => requestedOutputPortIds.has(output.portId))
88
- .map((output) => output.nodeId);
89
- }
90
84
  function deriveGraphBoundary(graph) {
91
85
  const inputsById = new Map();
92
86
  const outputsById = new Map();
@@ -11,7 +11,11 @@ export function applyFrozenGraphBoundaryEffects(graphOutputs, node, outputValues
11
11
  if (node.type === 'graphOutput') {
12
12
  const outputId = node.data?.id;
13
13
  const valueOutput = outputValues['valueOutput'];
14
- if (outputId && valueOutput) {
14
+ // Duplicate Graph Outputs share the ordinary first-non-excluded winner,
15
+ // whether a producer is computed or replayed from frozen outputs.
16
+ if (outputId &&
17
+ valueOutput &&
18
+ (graphOutputs[outputId] == null || graphOutputs[outputId]?.type === 'control-flow-excluded')) {
15
19
  graphOutputs[outputId] = valueOutput;
16
20
  }
17
21
  return undefined;
@@ -0,0 +1,34 @@
1
+ import { resolveToolContinuationConnections } from './chat-v2/toolContinuationConnection.js';
2
+ /** Invocation-local selection over compiled topology, never a mutation of the reusable graph plan. */
3
+ export function createGraphOutputSelection(graph, requestedOutputIds, getInputNodes) {
4
+ const requestedIds = new Set(requestedOutputIds);
5
+ const missingIds = new Set(requestedIds);
6
+ const startNodes = graph.nodes.filter((node) => {
7
+ if (node.type !== 'graphOutput')
8
+ return false;
9
+ const outputId = node.data.id;
10
+ missingIds.delete(outputId);
11
+ return requestedIds.has(outputId);
12
+ });
13
+ if (missingIds.size > 0) {
14
+ throw new Error(`Unknown requested graph output IDs: ${[...missingIds].map((id) => JSON.stringify(id)).join(', ')}`);
15
+ }
16
+ const continuations = resolveToolContinuationConnections(graph);
17
+ const nodeIds = new Set();
18
+ const pendingNodes = [...startNodes];
19
+ for (let index = 0; index < pendingNodes.length; index++) {
20
+ const node = pendingNodes[index];
21
+ if (nodeIds.has(node.id))
22
+ continue;
23
+ nodeIds.add(node.id);
24
+ // Include every scheduler prerequisite, even if only the first provider supplies an input value.
25
+ pendingNodes.push(...getInputNodes(node));
26
+ const continuation = continuations.get(node.id);
27
+ if (continuation?.kind === 'connected') {
28
+ // A connected Delegate is part of the LLM computation despite the forward-facing wire.
29
+ pendingNodes.push(continuation.delegateNode);
30
+ }
31
+ // Ambiguous continuations retain their existing node-execution error; never choose a winner here.
32
+ }
33
+ return { startNodes, nodeIds };
34
+ }