@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
@@ -0,0 +1,175 @@
1
+ const REGEX_LITERAL_PREFIX_CHARACTERS = new Set([
2
+ '(',
3
+ '[',
4
+ '{',
5
+ ':',
6
+ ';',
7
+ ',',
8
+ '=',
9
+ '!',
10
+ '~',
11
+ '?',
12
+ '&',
13
+ '|',
14
+ '+',
15
+ '-',
16
+ '*',
17
+ '%',
18
+ '^',
19
+ '<',
20
+ '>',
21
+ ]);
22
+ export function isInterpolationSyntaxCharacterEscaped(value, index) {
23
+ let backslashCount = 0;
24
+ for (let cursor = index - 1; cursor >= 0 && value[cursor] === '\\'; cursor -= 1) {
25
+ backslashCount += 1;
26
+ }
27
+ return backslashCount % 2 === 1;
28
+ }
29
+ /**
30
+ * JSONPath filters can contain JavaScript regex literals. Treat their contents
31
+ * as opaque while looking for an interpolation terminator or processor pipe;
32
+ * otherwise a `]` or `|` inside the regex can be mistaken for JSONPath syntax.
33
+ */
34
+ export function isInterpolationRegexLiteralStart(value, index) {
35
+ if (value[index] !== '/') {
36
+ return false;
37
+ }
38
+ let previousIndex = index - 1;
39
+ while (previousIndex >= 0 && /\s/.test(value[previousIndex])) {
40
+ previousIndex -= 1;
41
+ }
42
+ return previousIndex < 0 || REGEX_LITERAL_PREFIX_CHARACTERS.has(value[previousIndex]);
43
+ }
44
+ function getEscapedTripleTokenEnd(template, start) {
45
+ for (let cursor = start + 3; cursor < template.length - 2; cursor += 1) {
46
+ if (template[cursor] === '}' && template[cursor + 1] === '}' && template[cursor + 2] === '}') {
47
+ return cursor + 3;
48
+ }
49
+ }
50
+ return undefined;
51
+ }
52
+ /** Finds a matching `}}` while allowing JSONPath filters, quotes, and braces. */
53
+ function scanInterpolationToken(template, start) {
54
+ let quote;
55
+ let regex = false;
56
+ let regexCharacterClass = false;
57
+ let bracketDepth = 0;
58
+ let parenthesisDepth = 0;
59
+ let braceDepth = 0;
60
+ for (let cursor = start + 2; cursor < template.length; cursor += 1) {
61
+ const character = template[cursor];
62
+ if (regex) {
63
+ if (character === '[' && !isInterpolationSyntaxCharacterEscaped(template, cursor)) {
64
+ regexCharacterClass = true;
65
+ }
66
+ else if (character === ']' && !isInterpolationSyntaxCharacterEscaped(template, cursor)) {
67
+ regexCharacterClass = false;
68
+ }
69
+ else if (character === '/' && !regexCharacterClass && !isInterpolationSyntaxCharacterEscaped(template, cursor)) {
70
+ regex = false;
71
+ }
72
+ continue;
73
+ }
74
+ if (quote) {
75
+ if (character === quote && !isInterpolationSyntaxCharacterEscaped(template, cursor)) {
76
+ quote = undefined;
77
+ }
78
+ continue;
79
+ }
80
+ if (character === '/' && isInterpolationRegexLiteralStart(template, cursor)) {
81
+ regex = true;
82
+ regexCharacterClass = false;
83
+ continue;
84
+ }
85
+ if (character === '"' || character === "'" || character === '`') {
86
+ quote = character;
87
+ continue;
88
+ }
89
+ // A second opener always starts recovery outside quoted or regex syntax.
90
+ // JSONPath object literals use single `{` characters; a literal `{{` is
91
+ // not valid JSONPath syntax and should not swallow a later valid token.
92
+ if (character === '{' && template[cursor + 1] === '{') {
93
+ return { kind: 'nested', start: cursor };
94
+ }
95
+ if (character === '[') {
96
+ bracketDepth += 1;
97
+ continue;
98
+ }
99
+ if (character === ']' && bracketDepth > 0) {
100
+ bracketDepth -= 1;
101
+ continue;
102
+ }
103
+ if (character === '(') {
104
+ parenthesisDepth += 1;
105
+ continue;
106
+ }
107
+ if (character === ')' && parenthesisDepth > 0) {
108
+ parenthesisDepth -= 1;
109
+ continue;
110
+ }
111
+ if (character === '{') {
112
+ braceDepth += 1;
113
+ continue;
114
+ }
115
+ if (character === '}') {
116
+ if (braceDepth > 0) {
117
+ braceDepth -= 1;
118
+ continue;
119
+ }
120
+ if (template[cursor + 1] === '}' && bracketDepth === 0 && parenthesisDepth === 0) {
121
+ return { kind: 'closed', end: cursor + 2 };
122
+ }
123
+ }
124
+ }
125
+ return { kind: 'unclosed' };
126
+ }
127
+ /**
128
+ * Scans token boundaries without parsing expressions or resolving values.
129
+ *
130
+ * This deliberately has no evaluator dependencies, so editor-only surfaces
131
+ * can share Core's malformed-token recovery rules without loading JSONPath or
132
+ * the rest of the execution runtime. The returned spans are fresh data and
133
+ * exclude escaped triple-brace tokens.
134
+ */
135
+ export function scanInterpolationTokenSpans(template) {
136
+ const spans = [];
137
+ let searchIndex = 0;
138
+ while (searchIndex < template.length) {
139
+ const start = template.indexOf('{{', searchIndex);
140
+ if (start === -1) {
141
+ break;
142
+ }
143
+ if (template[start + 2] === '{') {
144
+ const escapedEnd = getEscapedTripleTokenEnd(template, start);
145
+ if (escapedEnd !== undefined) {
146
+ searchIndex = escapedEnd;
147
+ continue;
148
+ }
149
+ }
150
+ const scanResult = scanInterpolationToken(template, start);
151
+ if (scanResult.kind === 'nested') {
152
+ searchIndex = scanResult.start;
153
+ continue;
154
+ }
155
+ if (scanResult.kind === 'unclosed') {
156
+ // A malformed outer token can leave the scanner inside an unterminated
157
+ // quote or filter. Resume at a later opener so a valid following token
158
+ // is still discovered. Properly closed outer tokens return above, so
159
+ // valid quoted `{{` content remains part of that outer token.
160
+ const nextStart = template.indexOf('{{', start + 2);
161
+ if (nextStart === -1) {
162
+ break;
163
+ }
164
+ searchIndex = nextStart;
165
+ continue;
166
+ }
167
+ spans.push({
168
+ start,
169
+ end: scanResult.end,
170
+ rawInner: template.slice(start + 2, scanResult.end - 2),
171
+ });
172
+ searchIndex = scanResult.end;
173
+ }
174
+ return spans;
175
+ }
@@ -0,0 +1,129 @@
1
+ import { JSONPath } from 'jsonpath-plus';
2
+ import { isInterpolationRegexLiteralStart, isInterpolationSyntaxCharacterEscaped } from './interpolationSyntax.js';
3
+ function getNextNonWhitespaceCharacter(value, index) {
4
+ for (let cursor = index; cursor < value.length; cursor++) {
5
+ if (!/\s/.test(value[cursor])) {
6
+ return value[cursor];
7
+ }
8
+ }
9
+ return undefined;
10
+ }
11
+ function getWhitespaceRunEnd(value, index) {
12
+ let cursor = index;
13
+ while (cursor < value.length && /\s/.test(value[cursor])) {
14
+ cursor += 1;
15
+ }
16
+ return cursor;
17
+ }
18
+ /**
19
+ * Normalizes Rivet's historically accepted convenience whitespace around
20
+ * JSONPath structural separators. Quoted values, regular expressions, filter
21
+ * expressions, and object literals keep their authored contents unchanged.
22
+ *
23
+ * All runtime JSONPath consumers must pass through this helper so stored node
24
+ * paths and interpolation suffixes accept the same path language.
25
+ */
26
+ export function normalizeJsonPathExpression(path) {
27
+ const trimmedPath = path.trim();
28
+ if (!/\s/.test(trimmedPath)) {
29
+ return trimmedPath;
30
+ }
31
+ const result = [];
32
+ let lastResultCharacter;
33
+ let quote;
34
+ let regex = false;
35
+ let regexCharacterClass = false;
36
+ const filterBrackets = [];
37
+ let filterDepth = 0;
38
+ const append = (value) => {
39
+ if (value === '') {
40
+ return;
41
+ }
42
+ result.push(value);
43
+ lastResultCharacter = value.at(-1);
44
+ };
45
+ for (let cursor = 0; cursor < trimmedPath.length; cursor++) {
46
+ const character = trimmedPath[cursor];
47
+ if (regex) {
48
+ if (character === '[' && !isInterpolationSyntaxCharacterEscaped(trimmedPath, cursor)) {
49
+ regexCharacterClass = true;
50
+ }
51
+ else if (character === ']' && !isInterpolationSyntaxCharacterEscaped(trimmedPath, cursor)) {
52
+ regexCharacterClass = false;
53
+ }
54
+ else if (character === '/' &&
55
+ !regexCharacterClass &&
56
+ !isInterpolationSyntaxCharacterEscaped(trimmedPath, cursor)) {
57
+ regex = false;
58
+ }
59
+ append(character);
60
+ continue;
61
+ }
62
+ if (quote) {
63
+ if (character === quote && !isInterpolationSyntaxCharacterEscaped(trimmedPath, cursor)) {
64
+ quote = undefined;
65
+ }
66
+ append(character);
67
+ continue;
68
+ }
69
+ if (character === '"' || character === "'" || character === '`') {
70
+ quote = character;
71
+ append(character);
72
+ continue;
73
+ }
74
+ if (character === '/' && isInterpolationRegexLiteralStart(trimmedPath, cursor)) {
75
+ regex = true;
76
+ regexCharacterClass = false;
77
+ append(character);
78
+ continue;
79
+ }
80
+ const insideFilter = filterDepth > 0;
81
+ if (/\s/.test(character)) {
82
+ const whitespaceEnd = getWhitespaceRunEnd(trimmedPath, cursor);
83
+ const previousCharacter = lastResultCharacter;
84
+ const nextCharacter = trimmedPath[whitespaceEnd];
85
+ // jsonpath-plus rejects whitespace immediately inside either bracket.
86
+ // Preserve other filter whitespace because it may separate JavaScript
87
+ // tokens or be meaningful inside filter expressions.
88
+ const shouldRemoveWhitespace = previousCharacter === '[' ||
89
+ nextCharacter === ']' ||
90
+ nextCharacter === '[' ||
91
+ (!insideFilter && (previousCharacter === '.' || previousCharacter === ']' || nextCharacter === '.'));
92
+ if (!shouldRemoveWhitespace) {
93
+ append(trimmedPath.slice(cursor, whitespaceEnd));
94
+ }
95
+ cursor = whitespaceEnd - 1;
96
+ continue;
97
+ }
98
+ if (character === '[') {
99
+ const opensFilter = getNextNonWhitespaceCharacter(trimmedPath, cursor + 1) === '?';
100
+ filterBrackets.push(opensFilter);
101
+ if (opensFilter) {
102
+ filterDepth += 1;
103
+ }
104
+ append(character);
105
+ continue;
106
+ }
107
+ if (character === ']') {
108
+ if (filterBrackets.pop()) {
109
+ filterDepth -= 1;
110
+ }
111
+ append(character);
112
+ continue;
113
+ }
114
+ append(character);
115
+ }
116
+ return result.join('').trim();
117
+ }
118
+ /**
119
+ * Evaluates a JSONPath expression with the same engine and options used by the
120
+ * object-path nodes. Callers retain ownership of their no-match and error
121
+ * policy; this helper deliberately lets JSONPath errors propagate.
122
+ */
123
+ export function evaluateJsonPath(value, path, wrap = false) {
124
+ return JSONPath({
125
+ json: value ?? null,
126
+ path: normalizeJsonPathExpression(path),
127
+ wrap,
128
+ });
129
+ }
@@ -68,7 +68,9 @@ export * from './integrations/Tokenizer.js';
68
68
  export * from './integrations/GptTokenizerTokenizer.js';
69
69
  export { JS_LIST_CALLBACK_LOCAL_NAMES, interpolateJSListCallbackBody } from './model/nodes/jsListCallbackHelpers.js';
70
70
  export { findAutoDelegateGraphCandidate } from './model/nodes/toolCallDelegation.js';
71
- export { extractInterpolationVariables, findInterpolationTokenSpans, getInterpolationTokenName, interpolate, protectEscapedInterpolationTokens, restoreEscapedInterpolationTokens, } from './utils/interpolation.js';
71
+ export { extractInterpolationVariables, extractInterpolationVariableReferences, findInterpolationTokenSpans, getInterpolationTokenReference, getInterpolationTokenName, interpolate, parseInterpolationExpression, parseInterpolationTemplate, protectEscapedInterpolationTokens, resolveCodeInterpolationExpression, resolveInterpolationExpressionRawValue, resolveInterpolationTokenRawValue, restoreEscapedInterpolationTokens, stringifyInterpolationSourceValue, } from './utils/interpolation.js';
72
+ export type { InterpolateOptions, InterpolationReferenceSource, InterpolationTokenReplacementInfo, InterpolationTokenSpan, InterpolationValueSources, InterpolationVariableReference, ParsedInterpolationExpression, ParsedInterpolationTemplate, ParsedInterpolationToken, ReplaceInterpolationTokensOptions, } from './utils/interpolation.js';
73
+ export { scanInterpolationTokenSpans } from './utils/interpolationSyntax.js';
72
74
  export { WarningsPort } from './utils/symbols.js';
73
75
  import * as openai from './utils/openai.js';
74
76
  export { openai };
@@ -11,5 +11,14 @@ export interface CodeRunnerOptions {
11
11
  includeRivet: boolean;
12
12
  includeProcess: boolean;
13
13
  includeConsole: boolean;
14
+ /**
15
+ * The collision-safe name of the narrow interpolation resolver injected for
16
+ * generated Code-family wrappers. Runners only add the resolver when this
17
+ * is present, so ordinary authored code keeps its established argument
18
+ * shape and capability cost. A runner that accepts this option must inject
19
+ * a resolver compatible with `resolveCodeInterpolationExpression`; paths
20
+ * and @graphInputs/@context references depend on that contract.
21
+ */
22
+ interpolationHelperIdentifier?: string;
14
23
  }
15
24
  export declare const ALL_CODE_RUNNER_OPTIONS: CodeRunnerOptions;
@@ -1,4 +1,5 @@
1
1
  import type { EditorDefinition } from '../../model/EditorDefinition.js';
2
+ import type { DataValue } from '../../model/DataValue.js';
2
3
  import type { Inputs } from '../../model/GraphProcessor.js';
3
4
  import type { ChartNode, NodeInputDefinition } from '../../model/NodeBase.js';
4
5
  import type { InternalProcessContext } from '../../model/ProcessContext.js';
@@ -38,4 +39,5 @@ export declare function getMCPServerEditors<T extends ChartNode<string, MCPBaseN
38
39
  export declare function getMCPBaseBody(data: MCPBaseNodeData, context: RivetUIContext): string;
39
40
  export declare function requireMCPProvider(context: InternalProcessContext): MCPProvider;
40
41
  export declare function resolveMCPServer(data: MCPBaseNodeData, inputs: Inputs, context: InternalProcessContext): Promise<MCPResolvedServer | undefined>;
41
- export declare function interpolateMCPArgumentTemplate(template: string, inputs: Inputs): string;
42
+ export declare function interpolateMCPArgumentTemplate(template: string, inputs: Inputs, graphInputValues?: Record<string, DataValue>, contextValues?: Record<string, DataValue>): string;
43
+ export declare function getMCPArgumentTemplateInputs(template: string | undefined): NodeInputDefinition[];
@@ -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';
@@ -96,6 +96,8 @@ export type BuildAgentResponseTraceOptions = {
96
96
  events: readonly AgentTraceEvent[];
97
97
  nodeId?: NodeId;
98
98
  processId?: ProcessId;
99
+ /** Recorded whole-node duration for an LLM invocation; response traces retain their output-ready duration. */
100
+ invocationDurationMs?: number;
99
101
  startedAt?: number;
100
102
  responseReadyAt?: number;
101
103
  finishedAt?: number;
@@ -71,6 +71,10 @@ export type SerializedProcessEventMap = {
71
71
  node: ChartNode;
72
72
  error: Error | string;
73
73
  processId: ProcessId;
74
+ /** Display-only outputs retained by a failed non-split invocation. */
75
+ outputs?: Outputs;
76
+ /** Display-only outputs retained by individual failed split invocations. */
77
+ splitOutputs?: Record<number, Outputs>;
74
78
  resultOrigin?: NodeResultOrigin;
75
79
  durationMs?: number;
76
80
  splitRunDurationMs?: Record<number, number>;
@@ -4,7 +4,6 @@ import type { NodeId, NodeInputDefinition, NodeOutputDefinition, PortId } from '
4
4
  import type { GraphId, NodeGraph } from './NodeGraph.js';
5
5
  import type { Project } from './Project.js';
6
6
  import type { DynamicEditorEditor } from './EditorDefinition.js';
7
- export declare const GRAPH_BOUNDARY_OUTPUT_DEMAND_OPTIMIZATION_ENABLED = false;
8
7
  export type GraphBoundaryInput = {
9
8
  dataType: DataType;
10
9
  editor?: DynamicEditorEditor;
@@ -30,4 +29,3 @@ export declare function getGraphBoundaryInputDefinitions(boundary: GraphBoundary
30
29
  export declare function getGraphBoundaryOutputDefinitions(boundary: GraphBoundary, outputPortOrder?: readonly string[]): NodeOutputDefinition[];
31
30
  export declare function buildGraphBoundaryInputData(boundary: GraphBoundary, inputs: Inputs, defaults: Record<string, DataValue> | undefined): Inputs;
32
31
  export declare function buildExcludedGraphBoundaryOutputs(boundary: GraphBoundary): Outputs;
33
- export declare function getRequestedGraphOutputNodeIds(boundary: GraphBoundary, requestedOutputPortIds: ReadonlySet<PortId>): NodeId[];
@@ -0,0 +1,8 @@
1
+ import type { ChartNode, NodeId } from './NodeBase.js';
2
+ import type { NodeGraph } from './NodeGraph.js';
3
+ export type GraphOutputSelection = {
4
+ startNodes: ChartNode[];
5
+ nodeIds: ReadonlySet<NodeId>;
6
+ };
7
+ /** Invocation-local selection over compiled topology, never a mutation of the reusable graph plan. */
8
+ export declare function createGraphOutputSelection(graph: Pick<NodeGraph, 'nodes' | 'connections'>, requestedOutputIds: readonly string[], getInputNodes: (node: ChartNode) => readonly ChartNode[]): GraphOutputSelection;
@@ -84,6 +84,14 @@ export type ProcessEvents = {
84
84
  node: ChartNode;
85
85
  error: Error | string;
86
86
  processId: ProcessId;
87
+ /** Display-only outputs retained by a failed non-split invocation. */
88
+ outputs?: Outputs;
89
+ /**
90
+ * Display-only evidence retained by split items that actually ran. It can
91
+ * contain completed sibling outputs and failed-item checkpoints, but is
92
+ * never a successful aggregate result or downstream input.
93
+ */
94
+ splitOutputs?: Record<number, Outputs>;
87
95
  resultOrigin?: NodeResultOrigin;
88
96
  durationMs?: number;
89
97
  splitRunDurationMs?: Record<number, number>;
@@ -298,10 +306,11 @@ export declare class GraphProcessor {
298
306
  /** Inputs to the main graph. You should pass all inputs required by the GraphInputNodes of the graph. */
299
307
  inputs?: Record<string, DataValue>,
300
308
  /** Contextual data available to all graphs and subgraphs. Kind of like react context, avoids drilling down data into subgraphs. Be careful when using it. */
301
- contextValues?: Record<string, DataValue>,
302
- /** Allows callers such as web apps to receive root outputs while managed async branches continue settling. */
303
- options?: {
309
+ contextValues?: Record<string, DataValue>, options?: {
310
+ /** Allows web apps to receive root outputs while managed async branches continue settling. */
304
311
  returnWhenGraphOutputsReady?: boolean;
312
+ /** Restrict this invocation to named graph outputs and their prerequisites. Cannot be combined with runToNodeIds. */
313
+ requestedGraphOutputIds?: readonly string[];
305
314
  }): Promise<GraphOutputs>;
306
315
  getRootProcessor(): GraphProcessor;
307
316
  /** Raise a user event on the processor, all subprocessors, and their children. */
@@ -301,6 +301,12 @@ export type InternalProcessContext<T extends ChartNode = ChartNode> = ProcessCon
301
301
  getGraphBoundary?: (project: Project, graphId: GraphId | undefined) => GraphBoundary | undefined;
302
302
  /** Call when the node has partial data but has not finished execution yet. */
303
303
  onPartialOutputs?: (outputs: Outputs) => void;
304
+ /**
305
+ * Preserves display-only outputs for this invocation if it subsequently
306
+ * fails. These values are reported with nodeError, never used as graph
307
+ * results, and must not change the original failure.
308
+ */
309
+ setFailureOutputs?: (outputs: Outputs) => void;
304
310
  /** Creates a subprocessor, for executing subgraphs. */
305
311
  createSubProcessor: (subGraphId: GraphId | undefined, options?: {
306
312
  signal?: AbortSignal;
@@ -310,14 +316,15 @@ export type InternalProcessContext<T extends ChartNode = ChartNode> = ProcessCon
310
316
  getGlobal: (id: string) => ScalarOrArrayDataValue | undefined;
311
317
  /** Like context, but variables that are set during the run of the graph and can be read during the graph. Shared among all graphs and subgraphs. */
312
318
  setGlobal: (id: string, value: ScalarOrArrayDataValue) => void;
313
- waitForGlobal: (id: string) => Promise<ScalarOrArrayDataValue>;
319
+ /** Waits for a global value; by default the current node's cancellation stops the wait. */
320
+ waitForGlobal: (id: string, signal?: AbortSignal) => Promise<ScalarOrArrayDataValue>;
314
321
  /** Reads through the root run's stored-value cache and optional persistence store. */
315
322
  getStoredValue: (key: string) => Promise<RivetStoredValueReadResult>;
316
323
  /** Returns only the current root run's synchronous stored-value cache state. */
317
324
  getCachedStoredValue: (key: string) => RivetStoredValueCacheResult;
318
325
  /** Writes through the root run's cache and optional persistence store. */
319
326
  setStoredValue: (key: string, value: RivetStoredValue) => Promise<RivetStoredValueSetResult>;
320
- /** Waits only for a successful Set Stored Value in this root run. */
327
+ /** Waits only for a successful Set Stored Value in this root run; defaults to the current node's abort signal. */
321
328
  waitForStoredValue: (key: string, signal?: AbortSignal) => Promise<RivetStoredValue>;
322
329
  /** Resolves a named project or host-provided knowledge store for this execution. */
323
330
  getKnowledgeStore: (connectionId: KnowledgeStoreConnectionId) => Promise<RivetKnowledgeStore>;
@@ -4,7 +4,7 @@ import type { ChartNode, PortId } from './NodeBase.js';
4
4
  import type { GraphId } from './NodeGraph.js';
5
5
  import type { Project } from './Project.js';
6
6
  import type { AttachedNodeData, ExternalFunction, Outputs } from './GraphProcessor.js';
7
- export type NodeProcessContextBase = Omit<InternalProcessContext, 'attachedData' | 'activeOutputPortIds' | 'createSubProcessor' | 'execution' | 'externalFunctions' | 'getPluginConfig' | 'node' | 'onPartialOutputs' | 'processId' | 'requestUserInput' | 'reportProgress' | 'isDirectRunTarget' | 'markResultAsEditorCacheHit' | 'setGlobal' | 'signal' | 'splitIndex' | 'toolCallContinuation' | 'toolCallTraceSource' | 'waitEvent'>;
7
+ export type NodeProcessContextBase = Omit<InternalProcessContext, 'attachedData' | 'activeOutputPortIds' | 'createSubProcessor' | 'execution' | 'externalFunctions' | 'getPluginConfig' | 'node' | 'onPartialOutputs' | 'setFailureOutputs' | 'processId' | 'requestUserInput' | 'reportProgress' | 'isDirectRunTarget' | 'markResultAsEditorCacheHit' | 'setGlobal' | 'signal' | 'splitIndex' | 'toolCallContinuation' | 'toolCallTraceSource' | 'waitEvent'>;
8
8
  export declare function buildNodeProcessContext(options: {
9
9
  activeOutputPortIds: ReadonlySet<PortId>;
10
10
  base: NodeProcessContextBase;
@@ -21,6 +21,7 @@ export declare function buildNodeProcessContext(options: {
21
21
  node: ChartNode;
22
22
  nodeAbortController: AbortController;
23
23
  onPartialOutputs: (partialOutputs: Outputs) => void;
24
+ setFailureOutputs?: InternalProcessContext['setFailureOutputs'];
24
25
  processId: ProcessId;
25
26
  requestUserInput: (inputStrings: string[], renderingType: 'text' | 'markdown') => Promise<StringArrayDataValue>;
26
27
  reportProgress: InternalProcessContext['reportProgress'];
@@ -12,7 +12,8 @@ export type SplitRunDeps = {
12
12
  accumulateCost(output: Outputs): void;
13
13
  setNodeResults(nodeId: ChartNode['id'], outputs: Outputs): void;
14
14
  markNodeVisited(nodeId: ChartNode['id']): void;
15
- nodeErrored(node: ChartNode, error: unknown, processId: ProcessId, durationMs?: number, splitRunDurationMs?: Record<number, number>, resultOrigin?: SplitRunResultOrigin): Promise<void>;
15
+ nodeErrored(node: ChartNode, error: unknown, processId: ProcessId, durationMs?: number, splitRunDurationMs?: Record<number, number>, resultOrigin?: SplitRunResultOrigin, splitOutputs?: Record<number, Outputs>): Promise<void>;
16
+ takeFailureOutputs(processId: ProcessId, index: number): Outputs | undefined;
16
17
  isAborted(): boolean;
17
18
  getAbortError(): Error;
18
19
  emit(event: 'nodeStart', data: {