@valerypopoff/rivet2-core 2.0.7 → 2.0.8

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.
@@ -433,7 +433,7 @@ export class HttpCallNodeImpl extends NodeImpl {
433
433
  };
434
434
  }
435
435
  async process(inputs, context) {
436
- const requestAttempts = createHttpCallRequestAttempts();
436
+ const requestAttempts = this.data.retryOnNon200 ? createHttpCallRequestAttempts() : undefined;
437
437
  try {
438
438
  const method = getInputOrData(this.data, inputs, 'method', 'string');
439
439
  const url = getInputOrData(this.data, inputs, 'url', 'string');
@@ -498,19 +498,21 @@ export class HttpCallNodeImpl extends NodeImpl {
498
498
  throw err;
499
499
  }
500
500
  };
501
- const performTrackedRequest = async () => {
502
- try {
503
- const response = await performRequest();
504
- recordHttpCallResponseAttempt(requestAttempts, response);
505
- return response;
506
- }
507
- catch (error) {
508
- recordHttpCallThrownAttempt(requestAttempts, error, context.signal);
509
- throw error;
501
+ const performTrackedRequest = requestAttempts
502
+ ? async () => {
503
+ try {
504
+ const response = await performRequest();
505
+ recordHttpCallResponseAttempt(requestAttempts, response);
506
+ return response;
507
+ }
508
+ catch (error) {
509
+ recordHttpCallThrownAttempt(requestAttempts, error, context.signal);
510
+ throw error;
511
+ }
510
512
  }
511
- };
513
+ : performRequest;
512
514
  let response = await performTrackedRequest();
513
- if (this.data.retryOnNon200) {
515
+ if (requestAttempts) {
514
516
  const repeatTimes = normalizeHttpRetryCount(this.data.retryOnNon200RepeatTimes);
515
517
  const cooldownMs = normalizeHttpRetryCooldownMs(this.data.retryOnNon200CooldownMs);
516
518
  for (let attempt = 0; response.status !== 200 && attempt < repeatTimes; attempt++) {
@@ -522,7 +524,7 @@ export class HttpCallNodeImpl extends NodeImpl {
522
524
  throw buildNon2xxStatusCodeError(response.status);
523
525
  }
524
526
  const output = {
525
- [STATUS_CODE_OUTPUT_ID]: this.data.retryOnNon200
527
+ [STATUS_CODE_OUTPUT_ID]: requestAttempts
526
528
  ? buildRetryAttemptOutput('number[]', requestAttempts.statusCodeValues)
527
529
  : {
528
530
  type: 'number',
@@ -560,14 +562,14 @@ export class HttpCallNodeImpl extends NodeImpl {
560
562
  };
561
563
  }
562
564
  }
563
- if (this.data.catchRequestFailed || this.data.retryOnNon200) {
564
- output[REQUEST_FAILED_OUTPUT_ID] = this.data.retryOnNon200
565
+ if (this.data.catchRequestFailed || requestAttempts) {
566
+ output[REQUEST_FAILED_OUTPUT_ID] = requestAttempts
565
567
  ? buildRetryAttemptOutput('boolean[]', requestAttempts.requestFailedValues)
566
568
  : {
567
569
  type: 'boolean',
568
570
  value: false,
569
571
  };
570
- output[REQUEST_ERROR_OUTPUT_ID] = this.data.retryOnNon200
572
+ output[REQUEST_ERROR_OUTPUT_ID] = requestAttempts
571
573
  ? buildRetryAttemptOutput('string[]', requestAttempts.requestErrorMessages)
572
574
  : {
573
575
  type: 'control-flow-excluded',
@@ -581,8 +583,8 @@ export class HttpCallNodeImpl extends NodeImpl {
581
583
  return buildCaughtRequestFailedResult({
582
584
  isBinaryOutput: Boolean(this.data.isBinaryOutput),
583
585
  error,
584
- retryOnNon200: Boolean(this.data.retryOnNon200),
585
- attempts: requestAttempts,
586
+ retryOnNon200: requestAttempts != null,
587
+ attempts: requestAttempts ?? createHttpCallRequestAttempts(),
586
588
  });
587
589
  }
588
590
  throw error;
@@ -7,9 +7,8 @@ function escapeRegExp(value) {
7
7
  function sanitizeSourceUrlPart(value) {
8
8
  return String(value).replace(/[^a-zA-Z0-9_-]/g, '_');
9
9
  }
10
- export function buildCodeNodeSourceUrl(nodeId, processId) {
11
- const processPart = processId ? `-${sanitizeSourceUrlPart(processId)}` : '';
12
- return `rivet-code-node-${sanitizeSourceUrlPart(nodeId)}${processPart}.js`;
10
+ export function buildCodeNodeSourceUrl(nodeId) {
11
+ return `rivet-code-node-${sanitizeSourceUrlPart(nodeId)}.js`;
13
12
  }
14
13
  export function appendCodeNodeSourceUrl(code, sourceUrl) {
15
14
  return `${code}\n//# sourceURL=${sourceUrl}`;
@@ -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';
@@ -42,7 +42,13 @@ export type RunGraphOptions = {
42
42
  } & {
43
43
  [P in keyof ProcessEvents as `on${PascalCase<P>}`]?: (params: ProcessEvents[P]) => void;
44
44
  } & Settings;
45
- export declare function coreCreateProcessor(project: Project, options: RunGraphOptions): {
45
+ export type CoreCreateProcessorInternalOptions = {
46
+ cacheLoadedProjects?: boolean;
47
+ executionPlanCacheMode?: GraphProcessorExecutionPlanCacheMode;
48
+ runtimeCache?: GraphProcessorRuntimeCache;
49
+ scheduler?: GraphProcessorScheduler;
50
+ };
51
+ export declare function coreCreateProcessor(project: Project, options: RunGraphOptions, internalOptions?: CoreCreateProcessorInternalOptions): {
46
52
  processor: GraphProcessor;
47
53
  inputs: Record<string, DataValue>;
48
54
  contextValues: Record<string, DataValue>;
@@ -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';
3
+ import type { NodeConnection, NodeId, ChartNode, NodeInputDefinition, NodeOutputDefinition, PortId } from './NodeBase.js';
4
4
  import type { 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,34 @@ export type GraphPreprocessorResult = {
15
25
  nodesNotInCycle: ChartNode[];
16
26
  stronglyConnectedComponents: ChartNode[][];
17
27
  };
18
- export declare function preprocessGraphState(options: {
28
+ export type GraphExecutionPlan = Omit<GraphPreprocessorResult, 'nodeInstances'> & {
29
+ cycleIndexByNode: Record<NodeId, number>;
30
+ graphNodes: ChartNode[];
31
+ inputConnectionByNodeAndPort: GraphPortConnectionMap;
32
+ inputConnectionsByNode: Record<NodeId, NodeConnection[]>;
33
+ inputNodesByNode: Record<NodeId, ChartNode[]>;
34
+ missingRequiredInputsByNode: Record<NodeId, NodeInputDefinition[]>;
35
+ outputConnectionsByNodeAndPort: GraphPortConnectionsMap;
36
+ outputNodeResultsByNode: Record<NodeId, GraphOutputNodeResult>;
37
+ startNodes: ChartNode[];
38
+ };
39
+ export type GraphPreprocessorExecutionPlanResult = GraphPreprocessorResult & GraphExecutionPlan;
40
+ export type GraphPreprocessedState = GraphPreprocessorResult | GraphPreprocessorExecutionPlanResult;
41
+ type GraphPreprocessorOptions = {
42
+ buildExecutionPlan?: boolean;
19
43
  graph: NodeGraph;
20
44
  loadedProjects: Record<ProjectId, Project>;
21
45
  project: Project;
22
46
  registry: NodeRegistration<any, any>;
23
47
  warnOnInvalidGraph: boolean;
48
+ };
49
+ export declare function preprocessGraphState(options: GraphPreprocessorOptions & {
50
+ buildExecutionPlan: true;
51
+ }): GraphPreprocessorExecutionPlanResult;
52
+ export declare function preprocessGraphState(options: GraphPreprocessorOptions & {
53
+ buildExecutionPlan?: false | undefined;
24
54
  }): GraphPreprocessorResult;
55
+ export declare function preprocessGraphState(options: GraphPreprocessorOptions): GraphPreprocessedState;
56
+ export declare function isGraphExecutionPlan(preprocessedGraph: GraphPreprocessedState | GraphExecutionPlan): preprocessedGraph is GraphExecutionPlan;
57
+ export declare function toReusableGraphExecutionPlan(preprocessedGraph: GraphPreprocessorExecutionPlanResult): GraphExecutionPlan;
58
+ export {};
@@ -2,11 +2,12 @@ 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';
10
11
  type WithExecution<T extends object> = T & {
11
12
  execution: GraphExecutionMetadata;
12
13
  };
@@ -140,6 +141,12 @@ export type GraphProcessorConcurrency = {
140
141
  nodeConcurrency?: number;
141
142
  splitRunConcurrency?: number;
142
143
  };
144
+ export type GraphProcessorRuntimeCache = {
145
+ executionPlans?: WeakMap<NodeGraph, GraphExecutionPlan>;
146
+ loadedProjects?: Record<ProjectId, Project>;
147
+ };
148
+ export type GraphProcessorExecutionPlanCacheMode = 'all' | 'subprocessors';
149
+ export type GraphProcessorScheduler = 'compatible' | 'fast-acyclic';
143
150
  export declare const DEFAULT_SPLIT_RUN_CONCURRENCY = 4;
144
151
  export type RaceId = Tagged<string, 'RaceId'>;
145
152
  export type LoopInfo = AttachedNodeDataItem & {
@@ -175,7 +182,11 @@ export declare class GraphProcessor {
175
182
  warnOnInvalidGraph: boolean;
176
183
  get isRunning(): boolean;
177
184
  constructor(project: Project, graphId: GraphId | undefined, registry: NodeRegistration<any, any>, includeTrace?: boolean, options?: {
185
+ cacheLoadedProjects?: boolean;
178
186
  concurrency?: GraphProcessorConcurrency;
187
+ executionPlanCacheMode?: GraphProcessorExecutionPlanCacheMode;
188
+ runtimeCache?: GraphProcessorRuntimeCache;
189
+ scheduler?: GraphProcessorScheduler;
179
190
  });
180
191
  on: Emittery<ProcessEvents>["on"];
181
192
  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;
@@ -0,0 +1,29 @@
1
+ import type { LanguageModelUsage } from 'ai';
2
+ import type { ChatMessage } from '../DataValue.js';
3
+ import type { Outputs } from '../GraphProcessor.js';
4
+ import { type StreamedFunctionCall } from '../chat/streamChatResponse.js';
5
+ import type { ChatV2NormalizedUsage, ChatV2ReasoningOutput, RunChatV2PipelineOptions } from './chatV2Types.js';
6
+ type ChatV2CommonOutputOptions = Pick<RunChatV2PipelineOptions, 'outputUsage' | 'outputReasoning' | 'outputRequestStatus' | 'includeFunctionCalls' | 'functionCallMode' | 'retryOnNon200' | 'responseFormat'>;
7
+ type CreateChatV2CommonOutputsOptions = ChatV2CommonOutputOptions & {
8
+ requestMessages: ChatMessage[];
9
+ response: string;
10
+ structuredOutput: unknown | undefined;
11
+ functionCalls: StreamedFunctionCall[];
12
+ usage: ChatV2NormalizedUsage | undefined;
13
+ reasoning: ChatV2ReasoningOutput | undefined;
14
+ requestStatus: number | undefined;
15
+ responseError: string | undefined;
16
+ requestStatuses: number[];
17
+ requestErrors: string[];
18
+ };
19
+ type CreateChatV2ProviderFailureOutputsOptions = Pick<RunChatV2PipelineOptions, 'outputUsage' | 'outputReasoning' | 'includeFunctionCalls' | 'retryOnNon200'> & {
20
+ requestMessages: ChatMessage[];
21
+ responseStatus: number | undefined;
22
+ responseError: string;
23
+ requestStatuses: number[];
24
+ requestErrors: string[];
25
+ };
26
+ export declare function normalizeChatV2Usage(usage: LanguageModelUsage | undefined, options: Pick<RunChatV2PipelineOptions, 'provider' | 'modelId'>): ChatV2NormalizedUsage | undefined;
27
+ export declare function createChatV2CommonOutputs({ requestMessages, response, structuredOutput, functionCalls, usage, reasoning, requestStatus, responseError, requestStatuses, requestErrors, outputUsage, outputReasoning, outputRequestStatus, includeFunctionCalls, functionCallMode, retryOnNon200, responseFormat, }: CreateChatV2CommonOutputsOptions): Outputs;
28
+ export declare function createChatV2ProviderFailureOutputs({ requestMessages, responseStatus, responseError, requestStatuses, requestErrors, outputUsage, outputReasoning, includeFunctionCalls, retryOnNon200, }: CreateChatV2ProviderFailureOutputsOptions): Outputs;
29
+ export {};
@@ -1,6 +1,5 @@
1
1
  import type { NodeId } from '../NodeBase.js';
2
- import type { ProcessId } from '../ProcessContext.js';
3
- export declare function buildCodeNodeSourceUrl(nodeId: NodeId, processId?: ProcessId): string;
2
+ export declare function buildCodeNodeSourceUrl(nodeId: NodeId): string;
4
3
  export declare function appendCodeNodeSourceUrl(code: string, sourceUrl: string): string;
5
4
  export declare function enrichCodeNodeErrorWithLocation(params: {
6
5
  code: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valerypopoff/rivet2-core",
3
- "version": "2.0.7",
3
+ "version": "2.0.8",
4
4
  "license": "MIT",
5
5
  "main": "dist/cjs/bundle.cjs",
6
6
  "module": "dist/esm/index.js",