@valerypopoff/rivet2-core 2.0.7 → 2.0.9
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.
- package/dist/cjs/bundle.cjs +1757 -789
- package/dist/cjs/bundle.cjs.map +4 -4
- package/dist/esm/api/createProcessor.js +9 -2
- package/dist/esm/api/streaming.js +1 -0
- package/dist/esm/exports.js +1 -0
- package/dist/esm/model/DebuggerTransportSentinel.js +78 -0
- package/dist/esm/model/GraphAbortReasons.js +69 -0
- package/dist/esm/model/GraphBoundaryCache.js +92 -0
- package/dist/esm/model/GraphPreprocessor.js +212 -32
- package/dist/esm/model/GraphProcessor.js +493 -172
- package/dist/esm/model/NodeExclusionPolicy.js +67 -0
- package/dist/esm/model/NodeExecutionPlanner.js +66 -22
- package/dist/esm/model/NodeImpl.js +6 -4
- package/dist/esm/model/ProcessContextBuilder.js +2 -17
- package/dist/esm/model/RecordingPlayer.js +27 -7
- package/dist/esm/model/SplitRunProcessor.js +48 -9
- package/dist/esm/model/SubprocessorBridge.js +30 -23
- package/dist/esm/model/chat-v2/chatV2Outputs.js +183 -0
- package/dist/esm/model/chat-v2/chatV2Pipeline.js +30 -212
- package/dist/esm/model/nodes/CodeNewNode.js +1 -1
- package/dist/esm/model/nodes/CodeNode.js +1 -1
- package/dist/esm/model/nodes/GetGlobalNode.js +14 -4
- package/dist/esm/model/nodes/GraphOutputNode.js +31 -2
- package/dist/esm/model/nodes/HttpCallNode.js +20 -18
- package/dist/esm/model/nodes/LoopUntilNode.js +18 -45
- package/dist/esm/model/nodes/ReferencedGraphAliasNode.js +24 -63
- package/dist/esm/model/nodes/SetGlobalNode.js +2 -1
- package/dist/esm/model/nodes/SubGraphNode.js +22 -63
- package/dist/esm/model/nodes/codeNodeErrorDiagnostics.js +2 -3
- package/dist/esm/recording/ExecutionRecorder.js +19 -6
- package/dist/esm/utils/emitDetached.js +2 -2
- package/dist/esm/utils/interpolation.js +41 -1
- package/dist/esm/utils/serialization/serialization.js +6 -5
- package/dist/esm/utils/serialization/serializationHelpers.js +2 -2
- package/dist/esm/utils/serialization/serializationInput.js +48 -0
- package/dist/esm/utils/serialization/serializationUtils.js +2 -33
- package/dist/esm/utils/serialization/serialization_v2.js +8 -8
- package/dist/types/api/createProcessor.d.ts +9 -2
- package/dist/types/api/streaming.d.ts +1 -0
- package/dist/types/exports.d.ts +1 -0
- package/dist/types/model/DebuggerTransportSentinel.d.ts +21 -0
- package/dist/types/model/EditorDefinition.d.ts +2 -0
- package/dist/types/model/ExecutorProtocol.d.ts +5 -0
- package/dist/types/model/GraphAbortReasons.d.ts +23 -0
- package/dist/types/model/GraphBoundaryCache.d.ts +27 -0
- package/dist/types/model/GraphPreprocessor.d.ts +39 -3
- package/dist/types/model/GraphProcessor.d.ts +20 -1
- package/dist/types/model/NodeExclusionPolicy.d.ts +21 -0
- package/dist/types/model/NodeExecutionPlanner.d.ts +3 -8
- package/dist/types/model/NodeImpl.d.ts +10 -5
- package/dist/types/model/Nodes.d.ts +2 -2
- package/dist/types/model/ProcessContext.d.ts +3 -0
- package/dist/types/model/ProcessContextBuilder.d.ts +4 -20
- package/dist/types/model/SplitRunProcessor.d.ts +8 -3
- package/dist/types/model/chat-v2/chatV2Outputs.d.ts +29 -0
- package/dist/types/model/nodes/LoopUntilNode.d.ts +5 -4
- package/dist/types/model/nodes/ReferencedGraphAliasNode.d.ts +5 -4
- package/dist/types/model/nodes/SubGraphNode.d.ts +6 -5
- package/dist/types/model/nodes/codeNodeErrorDiagnostics.d.ts +1 -2
- package/dist/types/recording/RecordedEvents.d.ts +4 -0
- package/dist/types/utils/emitDetached.d.ts +2 -2
- package/dist/types/utils/serialization/serializationInput.d.ts +7 -0
- package/package.json +1 -1
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
import * as yaml from 'yaml';
|
|
3
3
|
import { graphV3Deserializer, projectV3Deserializer } from './serialization_v3.js';
|
|
4
4
|
import { getError } from '../errors.js';
|
|
5
|
-
import {
|
|
5
|
+
import { yamlProblem } from './serializationUtils.js';
|
|
6
|
+
import { prepareSerializedInput } from './serializationInput.js';
|
|
6
7
|
import { datasetV4Deserializer, datasetV4Serializer, graphV4Deserializer, graphV4Serializer, projectV4Deserializer, projectV4Serializer, } from './serialization_v4.js';
|
|
7
8
|
import { graphV2Deserializer, projectV2Deserializer } from './serialization_v2.js';
|
|
8
9
|
import { graphV1Deserializer, projectV1Deserializer } from './serialization_v1.js';
|
|
@@ -11,9 +12,9 @@ export function serializeProject(project, attachedData) {
|
|
|
11
12
|
}
|
|
12
13
|
const errMessage = (err) => `${getError(err).message}\n${getError(err).stack}`;
|
|
13
14
|
export function deserializeProject(serializedProject, path = null) {
|
|
14
|
-
const version =
|
|
15
|
+
const { deserializerInput, version } = prepareSerializedInput(serializedProject);
|
|
15
16
|
try {
|
|
16
|
-
const result = deserializeProjectByVersion(
|
|
17
|
+
const result = deserializeProjectByVersion(deserializerInput, version);
|
|
17
18
|
normalizeProjectDefaultNodeTitles(result[0]);
|
|
18
19
|
if (path !== null) {
|
|
19
20
|
result[0].metadata.path = path;
|
|
@@ -32,9 +33,9 @@ export function serializeGraph(graph) {
|
|
|
32
33
|
return graphV4Serializer(graph);
|
|
33
34
|
}
|
|
34
35
|
export function deserializeGraph(serializedGraph) {
|
|
35
|
-
const version =
|
|
36
|
+
const { deserializerInput, version } = prepareSerializedInput(serializedGraph);
|
|
36
37
|
try {
|
|
37
|
-
const graph = deserializeGraphByVersion(
|
|
38
|
+
const graph = deserializeGraphByVersion(deserializerInput, version);
|
|
38
39
|
normalizeGraphDefaultNodeTitles(graph);
|
|
39
40
|
return graph;
|
|
40
41
|
}
|
|
@@ -52,10 +52,10 @@ export function wrapInYamlEnvelope(version, data) {
|
|
|
52
52
|
return yaml.stringify({ version, data: stabilized }, null, { indent: 2 });
|
|
53
53
|
}
|
|
54
54
|
export function unwrapYamlEnvelope(raw, expectedVersion, label) {
|
|
55
|
-
if (typeof raw !== 'string') {
|
|
55
|
+
if (typeof raw !== 'string' && (!raw || typeof raw !== 'object' || Array.isArray(raw))) {
|
|
56
56
|
throw new Error(`${label} deserializer requires a string`);
|
|
57
57
|
}
|
|
58
|
-
const parsed = yaml.parse(raw);
|
|
58
|
+
const parsed = (typeof raw === 'string' ? yaml.parse(raw) : raw);
|
|
59
59
|
if (parsed.version !== expectedVersion) {
|
|
60
60
|
throw new Error(`${label} deserializer requires a version ${expectedVersion} ${label.toLowerCase()}`);
|
|
61
61
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as YAML from 'yaml';
|
|
2
|
+
export function prepareSerializedInput(data) {
|
|
3
|
+
if (typeof data !== 'string') {
|
|
4
|
+
return {
|
|
5
|
+
deserializerInput: data,
|
|
6
|
+
version: 1,
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
const trimmed = data.trim();
|
|
10
|
+
if (!trimmed) {
|
|
11
|
+
return {
|
|
12
|
+
deserializerInput: data,
|
|
13
|
+
version: 1,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
if (trimmed.startsWith('{') || trimmed.startsWith('[')) {
|
|
17
|
+
try {
|
|
18
|
+
const parsed = JSON.parse(trimmed);
|
|
19
|
+
const version = getParsedSerializationVersion(parsed);
|
|
20
|
+
return {
|
|
21
|
+
deserializerInput: version === 1 ? data : parsed,
|
|
22
|
+
version,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return {
|
|
27
|
+
deserializerInput: data,
|
|
28
|
+
version: 1,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const parsed = YAML.parse(trimmed);
|
|
33
|
+
const version = getParsedSerializationVersion(parsed);
|
|
34
|
+
return {
|
|
35
|
+
deserializerInput: version === 1 ? data : parsed,
|
|
36
|
+
version,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function getParsedSerializationVersion(parsed) {
|
|
40
|
+
if (!parsed || typeof parsed !== 'object') {
|
|
41
|
+
return 1;
|
|
42
|
+
}
|
|
43
|
+
const version = parsed.version;
|
|
44
|
+
if (version === 2 || version === 3 || version === 4) {
|
|
45
|
+
return version;
|
|
46
|
+
}
|
|
47
|
+
return 1;
|
|
48
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { prepareSerializedInput } from './serializationInput.js';
|
|
2
2
|
/** Validates a deserialized project structure. Returns errors for structural problems. */
|
|
3
3
|
export function validateProject(project) {
|
|
4
4
|
const errors = [];
|
|
@@ -77,36 +77,5 @@ export function yamlProblem(err) {
|
|
|
77
77
|
throw new Error(`YAML error: ${code} ${message} at ${pos} ${linePos}`);
|
|
78
78
|
}
|
|
79
79
|
export function detectSerializationVersion(data) {
|
|
80
|
-
|
|
81
|
-
return 1;
|
|
82
|
-
}
|
|
83
|
-
const trimmed = data.trim();
|
|
84
|
-
if (!trimmed) {
|
|
85
|
-
return 1;
|
|
86
|
-
}
|
|
87
|
-
if (trimmed.startsWith('{') || trimmed.startsWith('[')) {
|
|
88
|
-
try {
|
|
89
|
-
const parsed = JSON.parse(trimmed);
|
|
90
|
-
if (typeof parsed === 'object' &&
|
|
91
|
-
parsed != null &&
|
|
92
|
-
typeof parsed.version === 'number' &&
|
|
93
|
-
parsed.version >= 2 &&
|
|
94
|
-
parsed.version <= 4) {
|
|
95
|
-
return parsed.version;
|
|
96
|
-
}
|
|
97
|
-
return 1;
|
|
98
|
-
}
|
|
99
|
-
catch {
|
|
100
|
-
return 1;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
const parsed = YAML.parse(trimmed);
|
|
104
|
-
if (parsed &&
|
|
105
|
-
typeof parsed === 'object' &&
|
|
106
|
-
typeof parsed.version === 'number' &&
|
|
107
|
-
parsed.version >= 2 &&
|
|
108
|
-
parsed.version <= 4) {
|
|
109
|
-
return parsed.version;
|
|
110
|
-
}
|
|
111
|
-
return 1;
|
|
80
|
+
return prepareSerializedInput(data).version;
|
|
112
81
|
}
|
|
@@ -2,10 +2,7 @@ import { doubleCheckProject } from './serializationUtils.js';
|
|
|
2
2
|
// @ts-ignore
|
|
3
3
|
import * as yaml from 'yaml';
|
|
4
4
|
export function projectV2Deserializer(data) {
|
|
5
|
-
|
|
6
|
-
throw new Error('Project v2 deserializer requires a string');
|
|
7
|
-
}
|
|
8
|
-
const project = yaml.parse(data);
|
|
5
|
+
const project = unwrapV2Envelope(data, 'Project v2');
|
|
9
6
|
if (project.version !== 2) {
|
|
10
7
|
throw new Error('Project v2 deserializer requires a version 2 project');
|
|
11
8
|
}
|
|
@@ -13,12 +10,15 @@ export function projectV2Deserializer(data) {
|
|
|
13
10
|
return project.data;
|
|
14
11
|
}
|
|
15
12
|
export function graphV2Deserializer(data) {
|
|
16
|
-
|
|
17
|
-
throw new Error('Graph v2 deserializer requires a string');
|
|
18
|
-
}
|
|
19
|
-
const graph = yaml.parse(data);
|
|
13
|
+
const graph = unwrapV2Envelope(data, 'Graph v2');
|
|
20
14
|
if (graph.version !== 2) {
|
|
21
15
|
throw new Error('Graph v2 deserializer requires a version 2 graph');
|
|
22
16
|
}
|
|
23
17
|
return graph.data;
|
|
24
18
|
}
|
|
19
|
+
function unwrapV2Envelope(data, label) {
|
|
20
|
+
if (typeof data !== 'string' && (!data || typeof data !== 'object' || Array.isArray(data))) {
|
|
21
|
+
throw new Error(`${label} deserializer requires a string`);
|
|
22
|
+
}
|
|
23
|
+
return (typeof data === 'string' ? yaml.parse(data) : data);
|
|
24
|
+
}
|
|
@@ -3,7 +3,7 @@ import type { AttachedData } from '../utils/serialization/serializationUtils.js'
|
|
|
3
3
|
import type { AudioProvider } from '../integrations/AudioProvider.js';
|
|
4
4
|
import type { DataValue } from '../model/DataValue.js';
|
|
5
5
|
import type { DatasetProvider } from '../integrations/DatasetProvider.js';
|
|
6
|
-
import type { ExternalFunction, GraphProcessorConcurrency, ProcessEvents } from '../model/GraphProcessor.js';
|
|
6
|
+
import type { ExternalFunction, GraphProcessorConcurrency, GraphProcessorExecutionPlanCacheMode, GraphProcessorRuntimeCache, GraphProcessorScheduler, ProcessEvents } from '../model/GraphProcessor.js';
|
|
7
7
|
import type { Project } from '../model/Project.js';
|
|
8
8
|
import type { MCPProvider } from '../integrations/mcp/MCPProvider.js';
|
|
9
9
|
import type { NativeApi } from '../native/NativeApi.js';
|
|
@@ -30,6 +30,7 @@ export type RunGraphOptions = {
|
|
|
30
30
|
[key: string]: (data: DataValue | undefined) => void;
|
|
31
31
|
};
|
|
32
32
|
abortSignal?: AbortSignal;
|
|
33
|
+
captureNodeTimings?: boolean;
|
|
33
34
|
registry?: NodeRegistration<any, any>;
|
|
34
35
|
includeTrace?: boolean;
|
|
35
36
|
concurrency?: GraphProcessorConcurrency;
|
|
@@ -42,7 +43,13 @@ export type RunGraphOptions = {
|
|
|
42
43
|
} & {
|
|
43
44
|
[P in keyof ProcessEvents as `on${PascalCase<P>}`]?: (params: ProcessEvents[P]) => void;
|
|
44
45
|
} & Settings;
|
|
45
|
-
export
|
|
46
|
+
export type CoreCreateProcessorInternalOptions = {
|
|
47
|
+
cacheLoadedProjects?: boolean;
|
|
48
|
+
executionPlanCacheMode?: GraphProcessorExecutionPlanCacheMode;
|
|
49
|
+
runtimeCache?: GraphProcessorRuntimeCache;
|
|
50
|
+
scheduler?: GraphProcessorScheduler;
|
|
51
|
+
};
|
|
52
|
+
export declare function coreCreateProcessor(project: Project, options: RunGraphOptions, internalOptions?: CoreCreateProcessorInternalOptions): {
|
|
46
53
|
processor: GraphProcessor;
|
|
47
54
|
inputs: Record<string, DataValue>;
|
|
48
55
|
contextValues: Record<string, DataValue>;
|
package/dist/types/exports.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export * from './native/BaseDir.js';
|
|
|
11
11
|
export * from './native/NativeApi.js';
|
|
12
12
|
export * from './native/BrowserNativeApi.js';
|
|
13
13
|
export * from './model/ProcessContext.js';
|
|
14
|
+
export * from './model/DebuggerTransportSentinel.js';
|
|
14
15
|
export * from './model/ProjectReferenceLoader.js';
|
|
15
16
|
export * from './model/RivetUIContext.js';
|
|
16
17
|
export * from './model/chat-v2/index.js';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
declare const DEBUGGER_TRANSPORT_SENTINEL_KEY = "__rivetDebuggerTransportSentinel";
|
|
2
|
+
declare const DEBUGGER_TRANSPORT_SENTINEL_VERSION = 1;
|
|
3
|
+
type DebuggerTransportUndefinedSentinel = {
|
|
4
|
+
[DEBUGGER_TRANSPORT_SENTINEL_KEY]: {
|
|
5
|
+
type: 'undefined';
|
|
6
|
+
version: typeof DEBUGGER_TRANSPORT_SENTINEL_VERSION;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
type DebuggerTransportEscapedSentinel = {
|
|
10
|
+
[DEBUGGER_TRANSPORT_SENTINEL_KEY]: {
|
|
11
|
+
type: 'escaped-sentinel';
|
|
12
|
+
version: typeof DEBUGGER_TRANSPORT_SENTINEL_VERSION;
|
|
13
|
+
value: unknown;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export declare function createDebuggerTransportUndefinedSentinel(): DebuggerTransportUndefinedSentinel;
|
|
17
|
+
export declare function createDebuggerTransportEscapedSentinel(value: unknown): DebuggerTransportEscapedSentinel;
|
|
18
|
+
export declare function createDebuggerTransportEscapedSentinelEnvelope(value: unknown): DebuggerTransportEscapedSentinel;
|
|
19
|
+
export declare function isDebuggerTransportSentinelEnvelope(value: unknown): boolean;
|
|
20
|
+
export declare function decodeDebuggerTransportSentinels<T>(value: T): T;
|
|
21
|
+
export {};
|
|
@@ -10,6 +10,7 @@ export type SharedEditorDefinitionProps<T extends ChartNode> = {
|
|
|
10
10
|
label: string;
|
|
11
11
|
helperMessage?: string | ((data: T['data']) => string | undefined);
|
|
12
12
|
autoFocus?: boolean;
|
|
13
|
+
includeInGraphSearch?: boolean;
|
|
13
14
|
layout?: 'inline';
|
|
14
15
|
hideIf?: (data: T['data']) => boolean;
|
|
15
16
|
disableIf?: (data: T['data']) => boolean;
|
|
@@ -25,6 +26,7 @@ export type ToggleEditorDefinition<T extends ChartNode> = SharedEditorDefinition
|
|
|
25
26
|
type: 'toggle';
|
|
26
27
|
dataKey: DataOfType<T, boolean>;
|
|
27
28
|
useInputToggleDataKey?: DataOfType<T, boolean>;
|
|
29
|
+
turnOffDataKeysWhenEnabled?: DataOfType<T, boolean>[];
|
|
28
30
|
};
|
|
29
31
|
export type DataTypeSelectorEditorDefinition<T extends ChartNode> = SharedEditorDefinitionProps<T> & {
|
|
30
32
|
type: 'dataTypeSelector';
|
|
@@ -51,11 +51,15 @@ export type SerializedProcessEventMap = {
|
|
|
51
51
|
node: ChartNode;
|
|
52
52
|
outputs: Outputs;
|
|
53
53
|
processId: ProcessId;
|
|
54
|
+
durationMs?: number;
|
|
55
|
+
splitRunDurationMs?: Record<number, number>;
|
|
54
56
|
}>;
|
|
55
57
|
nodeError: WithExecution<{
|
|
56
58
|
node: ChartNode;
|
|
57
59
|
error: Error | string;
|
|
58
60
|
processId: ProcessId;
|
|
61
|
+
durationMs?: number;
|
|
62
|
+
splitRunDurationMs?: Record<number, number>;
|
|
59
63
|
}>;
|
|
60
64
|
nodeExcluded: WithExecution<{
|
|
61
65
|
node: ChartNode;
|
|
@@ -195,6 +199,7 @@ export type OutgoingMessageMap = {
|
|
|
195
199
|
inputs?: GraphInputs;
|
|
196
200
|
projectPath?: string | null;
|
|
197
201
|
useEditorCache?: boolean;
|
|
202
|
+
captureNodeTimings?: boolean;
|
|
198
203
|
};
|
|
199
204
|
abort: undefined;
|
|
200
205
|
pause: undefined;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare const RACE_LOSER_EXCLUSION_REASON = "Race branch lost";
|
|
2
|
+
export declare const SUCCESSFUL_GRAPH_ABORT_EXCLUSION_REASON = "Graph aborted successfully";
|
|
3
|
+
declare const GRAPH_ABORT_ERROR_MARKER = "rivet:graph-abort-error";
|
|
4
|
+
declare const GRAPH_ABORT_REASON_MARKER = "rivet:graph-abort-reason";
|
|
5
|
+
export type GraphAbortReason = {
|
|
6
|
+
error?: Error | string;
|
|
7
|
+
marker: typeof GRAPH_ABORT_REASON_MARKER;
|
|
8
|
+
successful: boolean;
|
|
9
|
+
};
|
|
10
|
+
export type GraphAbortError = Error & {
|
|
11
|
+
graphAbortReason?: GraphAbortReason;
|
|
12
|
+
marker: typeof GRAPH_ABORT_ERROR_MARKER;
|
|
13
|
+
};
|
|
14
|
+
export declare function createGraphAbortReason(successful: boolean, error?: Error | string): GraphAbortReason;
|
|
15
|
+
export declare function createGraphAbortError(reason: GraphAbortReason | undefined, message?: string): GraphAbortError;
|
|
16
|
+
export declare function createGraphAbortErrorFromSignal(signal: AbortSignal | undefined, message?: string): GraphAbortError;
|
|
17
|
+
export declare function getAbortSignalReason(signal: AbortSignal | undefined): unknown;
|
|
18
|
+
export declare function getGraphAbortReasonFromSignal(signal: AbortSignal | undefined): GraphAbortReason | undefined;
|
|
19
|
+
export declare function getGraphAbortReasonFromError(error: unknown): GraphAbortReason | undefined;
|
|
20
|
+
export declare function isRaceLoserGraphAbortReason(reason: GraphAbortReason | undefined): boolean;
|
|
21
|
+
export declare function isSuccessfulNonRaceGraphAbortReason(reason: GraphAbortReason | undefined): boolean;
|
|
22
|
+
export declare function isAbortLikeError(error: Error): boolean;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { DataType, DataValue } from './DataValue.js';
|
|
2
|
+
import type { Inputs, Outputs } from './GraphProcessor.js';
|
|
3
|
+
import type { NodeInputDefinition, NodeOutputDefinition, PortId } from './NodeBase.js';
|
|
4
|
+
import type { GraphId, NodeGraph } from './NodeGraph.js';
|
|
5
|
+
import type { Project } from './Project.js';
|
|
6
|
+
import type { DynamicEditorEditor } from './EditorDefinition.js';
|
|
7
|
+
export type GraphBoundaryInput = {
|
|
8
|
+
dataType: DataType;
|
|
9
|
+
editor?: DynamicEditorEditor;
|
|
10
|
+
id: string;
|
|
11
|
+
portId: PortId;
|
|
12
|
+
};
|
|
13
|
+
export type GraphBoundaryOutput = {
|
|
14
|
+
dataType: DataType;
|
|
15
|
+
id: string;
|
|
16
|
+
portId: PortId;
|
|
17
|
+
};
|
|
18
|
+
export type GraphBoundary = {
|
|
19
|
+
inputs: readonly GraphBoundaryInput[];
|
|
20
|
+
outputs: readonly GraphBoundaryOutput[];
|
|
21
|
+
};
|
|
22
|
+
export type GraphBoundaryCache = WeakMap<NodeGraph, GraphBoundary>;
|
|
23
|
+
export declare function getGraphBoundary(project: Project, graphId: GraphId | undefined, cache?: GraphBoundaryCache): GraphBoundary | undefined;
|
|
24
|
+
export declare function getGraphBoundaryInputDefinitions(boundary: GraphBoundary): NodeInputDefinition[];
|
|
25
|
+
export declare function getGraphBoundaryOutputDefinitions(boundary: GraphBoundary): NodeOutputDefinition[];
|
|
26
|
+
export declare function buildGraphBoundaryInputData(boundary: GraphBoundary, inputs: Inputs, defaults: Record<string, DataValue> | undefined): Inputs;
|
|
27
|
+
export declare function buildExcludedGraphBoundaryOutputs(boundary: GraphBoundary): Outputs;
|
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
import type { NodeRegistration } from './NodeRegistration.js';
|
|
2
2
|
import type { NodeGraph } from './NodeGraph.js';
|
|
3
|
-
import type { NodeConnection, NodeId, ChartNode, NodeInputDefinition, NodeOutputDefinition } from './NodeBase.js';
|
|
4
|
-
import type { NodeImpl } from './NodeImpl.js';
|
|
3
|
+
import type { NodeConnection, NodeId, ChartNode, NodeInputDefinition, NodeOutputDefinition, PortId } from './NodeBase.js';
|
|
4
|
+
import type { NodeDefinitionContext, NodeImpl } from './NodeImpl.js';
|
|
5
5
|
import type { Project, ProjectId } from './Project.js';
|
|
6
6
|
export type GraphNodeDefinitions = Record<NodeId, {
|
|
7
7
|
inputs: NodeInputDefinition[];
|
|
8
8
|
outputs: NodeOutputDefinition[];
|
|
9
9
|
}>;
|
|
10
|
+
export type GraphPortConnectionMap = Record<NodeId, Partial<Record<PortId, NodeConnection>>>;
|
|
11
|
+
export type GraphPortConnectionsMap = Record<NodeId, Partial<Record<PortId, NodeConnection[]>>>;
|
|
12
|
+
export type GraphOutputNodeResult = {
|
|
13
|
+
connections: NodeConnection[];
|
|
14
|
+
connectionsToNodes: {
|
|
15
|
+
connections: NodeConnection[];
|
|
16
|
+
node: ChartNode;
|
|
17
|
+
}[];
|
|
18
|
+
nodes: ChartNode[];
|
|
19
|
+
};
|
|
10
20
|
export type GraphPreprocessorResult = {
|
|
11
21
|
connections: Record<NodeId, NodeConnection[]>;
|
|
12
22
|
definitions: GraphNodeDefinitions;
|
|
@@ -15,10 +25,36 @@ export type GraphPreprocessorResult = {
|
|
|
15
25
|
nodesNotInCycle: ChartNode[];
|
|
16
26
|
stronglyConnectedComponents: ChartNode[][];
|
|
17
27
|
};
|
|
18
|
-
export
|
|
28
|
+
export type GraphExecutionPlan = Omit<GraphPreprocessorResult, 'nodeInstances'> & {
|
|
29
|
+
cycleIndexByNode: Record<NodeId, number>;
|
|
30
|
+
graphNodes: ChartNode[];
|
|
31
|
+
nodeIds: readonly NodeId[];
|
|
32
|
+
inputConnectionByNodeAndPort: GraphPortConnectionMap;
|
|
33
|
+
inputConnectionsByNode: Record<NodeId, NodeConnection[]>;
|
|
34
|
+
inputNodesByNode: Record<NodeId, ChartNode[]>;
|
|
35
|
+
missingRequiredInputsByNode: Record<NodeId, NodeInputDefinition[]>;
|
|
36
|
+
outputConnectionsByNodeAndPort: GraphPortConnectionsMap;
|
|
37
|
+
outputNodeResultsByNode: Record<NodeId, GraphOutputNodeResult>;
|
|
38
|
+
startNodes: ChartNode[];
|
|
39
|
+
};
|
|
40
|
+
export type GraphPreprocessorExecutionPlanResult = GraphPreprocessorResult & GraphExecutionPlan;
|
|
41
|
+
export type GraphPreprocessedState = GraphPreprocessorResult | GraphPreprocessorExecutionPlanResult;
|
|
42
|
+
type GraphPreprocessorOptions = {
|
|
43
|
+
buildExecutionPlan?: boolean;
|
|
44
|
+
definitionContext?: NodeDefinitionContext;
|
|
19
45
|
graph: NodeGraph;
|
|
20
46
|
loadedProjects: Record<ProjectId, Project>;
|
|
21
47
|
project: Project;
|
|
22
48
|
registry: NodeRegistration<any, any>;
|
|
23
49
|
warnOnInvalidGraph: boolean;
|
|
50
|
+
};
|
|
51
|
+
export declare function preprocessGraphState(options: GraphPreprocessorOptions & {
|
|
52
|
+
buildExecutionPlan: true;
|
|
53
|
+
}): GraphPreprocessorExecutionPlanResult;
|
|
54
|
+
export declare function preprocessGraphState(options: GraphPreprocessorOptions & {
|
|
55
|
+
buildExecutionPlan?: false | undefined;
|
|
24
56
|
}): GraphPreprocessorResult;
|
|
57
|
+
export declare function preprocessGraphState(options: GraphPreprocessorOptions): GraphPreprocessedState;
|
|
58
|
+
export declare function isGraphExecutionPlan(preprocessedGraph: GraphPreprocessedState | GraphExecutionPlan): preprocessedGraph is GraphExecutionPlan;
|
|
59
|
+
export declare function toReusableGraphExecutionPlan(preprocessedGraph: GraphPreprocessorExecutionPlanResult): GraphExecutionPlan;
|
|
60
|
+
export {};
|
|
@@ -2,11 +2,13 @@ import { type DataValue, type StringArrayDataValue, type ScalarOrArrayDataValue
|
|
|
2
2
|
import { type ChartNode, type NodeConnection, type NodeId, type PortId } from './NodeBase.js';
|
|
3
3
|
import type { GraphId, NodeGraph } from './NodeGraph.js';
|
|
4
4
|
import Emittery from 'emittery';
|
|
5
|
-
import { type Project } from './Project.js';
|
|
5
|
+
import { type ProjectId, type Project } from './Project.js';
|
|
6
6
|
import type { GraphExecutionMetadata, InternalProcessContext, ProcessContext, ProcessId } from './ProcessContext.js';
|
|
7
7
|
import type { ExecutionRecorder } from '../recording/ExecutionRecorder.js';
|
|
8
8
|
import type { Tagged } from 'type-fest';
|
|
9
9
|
import type { NodeRegistration } from './NodeRegistration.js';
|
|
10
|
+
import { type GraphExecutionPlan } from './GraphPreprocessor.js';
|
|
11
|
+
import { type GraphBoundaryCache } from './GraphBoundaryCache.js';
|
|
10
12
|
type WithExecution<T extends object> = T & {
|
|
11
13
|
execution: GraphExecutionMetadata;
|
|
12
14
|
};
|
|
@@ -50,12 +52,16 @@ export type ProcessEvents = {
|
|
|
50
52
|
node: ChartNode;
|
|
51
53
|
outputs: Outputs;
|
|
52
54
|
processId: ProcessId;
|
|
55
|
+
durationMs?: number;
|
|
56
|
+
splitRunDurationMs?: Record<number, number>;
|
|
53
57
|
}>;
|
|
54
58
|
/** Called when a node has errored during processing. */
|
|
55
59
|
nodeError: WithExecution<{
|
|
56
60
|
node: ChartNode;
|
|
57
61
|
error: Error | string;
|
|
58
62
|
processId: ProcessId;
|
|
63
|
+
durationMs?: number;
|
|
64
|
+
splitRunDurationMs?: Record<number, number>;
|
|
59
65
|
}>;
|
|
60
66
|
/** Called when a node has been excluded from processing. */
|
|
61
67
|
nodeExcluded: WithExecution<{
|
|
@@ -140,6 +146,13 @@ export type GraphProcessorConcurrency = {
|
|
|
140
146
|
nodeConcurrency?: number;
|
|
141
147
|
splitRunConcurrency?: number;
|
|
142
148
|
};
|
|
149
|
+
export type GraphProcessorRuntimeCache = {
|
|
150
|
+
executionPlans?: WeakMap<NodeGraph, GraphExecutionPlan>;
|
|
151
|
+
graphBoundaries?: GraphBoundaryCache;
|
|
152
|
+
loadedProjects?: Record<ProjectId, Project>;
|
|
153
|
+
};
|
|
154
|
+
export type GraphProcessorExecutionPlanCacheMode = 'all' | 'subprocessors';
|
|
155
|
+
export type GraphProcessorScheduler = 'compatible' | 'fast-acyclic';
|
|
143
156
|
export declare const DEFAULT_SPLIT_RUN_CONCURRENCY = 4;
|
|
144
157
|
export type RaceId = Tagged<string, 'RaceId'>;
|
|
145
158
|
export type LoopInfo = AttachedNodeDataItem & {
|
|
@@ -175,7 +188,13 @@ export declare class GraphProcessor {
|
|
|
175
188
|
warnOnInvalidGraph: boolean;
|
|
176
189
|
get isRunning(): boolean;
|
|
177
190
|
constructor(project: Project, graphId: GraphId | undefined, registry: NodeRegistration<any, any>, includeTrace?: boolean, options?: {
|
|
191
|
+
cacheLoadedProjects?: boolean;
|
|
192
|
+
captureNodeTimings?: boolean;
|
|
178
193
|
concurrency?: GraphProcessorConcurrency;
|
|
194
|
+
executionPlanCacheMode?: GraphProcessorExecutionPlanCacheMode;
|
|
195
|
+
initialExecutionPlan?: GraphExecutionPlan;
|
|
196
|
+
runtimeCache?: GraphProcessorRuntimeCache;
|
|
197
|
+
scheduler?: GraphProcessorScheduler;
|
|
179
198
|
});
|
|
180
199
|
on: Emittery<ProcessEvents>["on"];
|
|
181
200
|
off: Emittery<ProcessEvents>["off"];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ControlFlowExcludedDataValue, type DataValue } from './DataValue.js';
|
|
2
|
+
import { type ChartNode, type NodeInputDefinition, type NodeOutputDefinition, type PortId } from './NodeBase.js';
|
|
3
|
+
type NodePortValues = Record<PortId, DataValue | undefined>;
|
|
4
|
+
export type NodeExclusionReason = 'disabled' | 'if port is false' | 'input is excluded value' | 'missing required input';
|
|
5
|
+
export type NodeExclusionDecision = {
|
|
6
|
+
action: 'continue' | 'defer';
|
|
7
|
+
} | {
|
|
8
|
+
action: 'exclude';
|
|
9
|
+
reason: NodeExclusionReason;
|
|
10
|
+
traceMessage: string;
|
|
11
|
+
};
|
|
12
|
+
export declare function getControlFlowExclusionDecision({ inputValues, node, typeOfExclusion, }: {
|
|
13
|
+
inputValues: NodePortValues;
|
|
14
|
+
node: ChartNode;
|
|
15
|
+
typeOfExclusion?: ControlFlowExcludedDataValue['value'];
|
|
16
|
+
}): NodeExclusionDecision;
|
|
17
|
+
export declare function getMissingRequiredInputExclusion(node: ChartNode, missingRequiredInputs: NodeInputDefinition[]): Extract<NodeExclusionDecision, {
|
|
18
|
+
action: 'exclude';
|
|
19
|
+
}>;
|
|
20
|
+
export declare function createExcludedNodeOutputs(node: ChartNode, outputDefinitions: NodeOutputDefinition[]): NodePortValues;
|
|
21
|
+
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ChartNode, NodeConnection, NodeId, NodeInputDefinition, NodeOutputDefinition } from './NodeBase.js';
|
|
2
2
|
import type { Inputs } from './GraphProcessor.js';
|
|
3
|
+
import type { GraphExecutionPlan, GraphOutputNodeResult } from './GraphPreprocessor.js';
|
|
3
4
|
export type ExecutionState = {
|
|
4
5
|
connections: Record<NodeId, NodeConnection[]>;
|
|
5
6
|
definitions: Record<NodeId, {
|
|
@@ -7,19 +8,13 @@ export type ExecutionState = {
|
|
|
7
8
|
outputs: NodeOutputDefinition[];
|
|
8
9
|
}>;
|
|
9
10
|
erroredNodes: Map<NodeId, Error | string>;
|
|
11
|
+
executionPlan?: GraphExecutionPlan;
|
|
10
12
|
loopControllersSeen: Set<NodeId>;
|
|
11
13
|
nodesById: Record<NodeId, ChartNode>;
|
|
12
14
|
stronglyConnectedComponents: ChartNode[][];
|
|
13
15
|
visitedNodes: Set<NodeId>;
|
|
14
16
|
};
|
|
15
|
-
export type OutputNodeResult =
|
|
16
|
-
nodes: ChartNode[];
|
|
17
|
-
connections: NodeConnection[];
|
|
18
|
-
connectionsToNodes: {
|
|
19
|
-
connections: NodeConnection[];
|
|
20
|
-
node: ChartNode;
|
|
21
|
-
}[];
|
|
22
|
-
};
|
|
17
|
+
export type OutputNodeResult = GraphOutputNodeResult;
|
|
23
18
|
export declare function getStartNodes(state: ExecutionState, graphNodes: ChartNode[], runToNodeIds?: NodeId[]): ChartNode[];
|
|
24
19
|
export declare function getInputNodesTo(state: ExecutionState, node: ChartNode): ChartNode[];
|
|
25
20
|
export declare function getOutputNodesFrom(state: ExecutionState, node: ChartNode): OutputNodeResult;
|
|
@@ -5,6 +5,11 @@ import type { InternalProcessContext } from './ProcessContext.js';
|
|
|
5
5
|
import type { EditorDefinition } from './EditorDefinition.js';
|
|
6
6
|
import type { NodeBodySpec } from './NodeBodySpec.js';
|
|
7
7
|
import type { RivetUIContext } from './RivetUIContext.js';
|
|
8
|
+
import type { GraphBoundary } from './GraphBoundaryCache.js';
|
|
9
|
+
import type { GraphId } from './NodeGraph.js';
|
|
10
|
+
export type NodeDefinitionContext = {
|
|
11
|
+
getGraphBoundary: (project: Project, graphId: GraphId | undefined) => GraphBoundary | undefined;
|
|
12
|
+
};
|
|
8
13
|
export interface PluginNodeImpl<T extends ChartNode> {
|
|
9
14
|
getInputDefinitions(data: T['data'], connections: NodeConnection[], nodes: Record<NodeId, ChartNode>, project: Project): NodeInputDefinition[];
|
|
10
15
|
getOutputDefinitions(data: T['data'], connections: NodeConnection[], nodes: Record<NodeId, ChartNode>, project: Project): NodeOutputDefinition[];
|
|
@@ -25,9 +30,9 @@ export declare abstract class NodeImpl<T extends ChartNode, Type extends T['type
|
|
|
25
30
|
y: number;
|
|
26
31
|
};
|
|
27
32
|
get data(): T['data'];
|
|
28
|
-
abstract getInputDefinitions(connections: NodeConnection[], nodes: Record<NodeId, ChartNode>, project: Project, referencedProjects: Record<ProjectId, Project
|
|
29
|
-
getInputDefinitionsIncludingBuiltIn(connections: NodeConnection[], nodes: Record<NodeId, ChartNode>, project: Project, referencedProjects: Record<ProjectId, Project
|
|
30
|
-
abstract getOutputDefinitions(connections: NodeConnection[], nodes: Record<NodeId, ChartNode>, project: Project, referencedProjects: Record<ProjectId, Project
|
|
33
|
+
abstract getInputDefinitions(connections: NodeConnection[], nodes: Record<NodeId, ChartNode>, project: Project, referencedProjects: Record<ProjectId, Project>, definitionContext?: NodeDefinitionContext): NodeInputDefinition[];
|
|
34
|
+
getInputDefinitionsIncludingBuiltIn(connections: NodeConnection[], nodes: Record<NodeId, ChartNode>, project: Project, referencedProjects: Record<ProjectId, Project>, definitionContext?: NodeDefinitionContext): NodeInputDefinition[];
|
|
35
|
+
abstract getOutputDefinitions(connections: NodeConnection[], nodes: Record<NodeId, ChartNode>, project: Project, referencedProjects: Record<ProjectId, Project>, definitionContext?: NodeDefinitionContext): NodeOutputDefinition[];
|
|
31
36
|
abstract process(inputData: Inputs, context: InternalProcessContext): Promise<Outputs>;
|
|
32
37
|
getEditors(_context: RivetUIContext): EditorDefinition<T>[] | Promise<EditorDefinition<T>[]>;
|
|
33
38
|
getBody(_context: RivetUIContext): NodeBody | Promise<NodeBody>;
|
|
@@ -36,8 +41,8 @@ export type NodeBody = string | NodeBodySpec | NodeBodySpec[] | undefined;
|
|
|
36
41
|
export declare class PluginNodeImplClass<T extends ChartNode, Type extends T['type'] = T['type']> extends NodeImpl<T, Type> {
|
|
37
42
|
readonly impl: PluginNodeImpl<T>;
|
|
38
43
|
constructor(chartNode: T, impl: PluginNodeImpl<T>);
|
|
39
|
-
getInputDefinitions(connections: NodeConnection[], nodes: Record<NodeId, ChartNode>, project: Project): NodeInputDefinition[];
|
|
40
|
-
getOutputDefinitions(connections: NodeConnection[], nodes: Record<NodeId, ChartNode>, project: Project): NodeOutputDefinition[];
|
|
44
|
+
getInputDefinitions(connections: NodeConnection[], nodes: Record<NodeId, ChartNode>, project: Project, _referencedProjects?: Record<ProjectId, Project>, _definitionContext?: NodeDefinitionContext): NodeInputDefinition[];
|
|
45
|
+
getOutputDefinitions(connections: NodeConnection[], nodes: Record<NodeId, ChartNode>, project: Project, _referencedProjects?: Record<ProjectId, Project>, _definitionContext?: NodeDefinitionContext): NodeOutputDefinition[];
|
|
41
46
|
process(inputData: Inputs, context: InternalProcessContext): Promise<Outputs>;
|
|
42
47
|
getEditors(context: RivetUIContext): EditorDefinition<T>[] | Promise<EditorDefinition<T>[]>;
|
|
43
48
|
getBody(context: RivetUIContext): NodeBody | Promise<NodeBody>;
|