@valerypopoff/rivet2-core 2.1.3 → 2.1.5

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 (114) hide show
  1. package/dist/cjs/bundle.cjs +10138 -5679
  2. package/dist/cjs/bundle.cjs.map +4 -4
  3. package/dist/cjs/webAppRuntime.cjs +1214 -0
  4. package/dist/cjs/webAppRuntime.cjs.map +7 -0
  5. package/dist/esm/api/createProcessor.js +8 -1
  6. package/dist/esm/api/streaming.js +6 -0
  7. package/dist/esm/exports.js +8 -0
  8. package/dist/esm/integrations/mcp/MCPBase.js +92 -34
  9. package/dist/esm/model/GraphBoundaryEffects.js +13 -0
  10. package/dist/esm/model/GraphProcessor.js +1138 -86
  11. package/dist/esm/model/GraphProgress.js +15 -0
  12. package/dist/esm/model/ManagedAsyncBranches.js +28 -0
  13. package/dist/esm/model/Nodes.js +12 -0
  14. package/dist/esm/model/ProcessContextBuilder.js +3 -1
  15. package/dist/esm/model/RecordingPlayer.js +19 -0
  16. package/dist/esm/model/StoredValueStore.js +226 -0
  17. package/dist/esm/model/SubprocessorBridge.js +50 -18
  18. package/dist/esm/model/ToolCallContinuation.js +1 -0
  19. package/dist/esm/model/UiGraph.js +177 -4
  20. package/dist/esm/model/UiGraphActionProtocol.js +131 -0
  21. package/dist/esm/model/UiGraphBindings.js +530 -0
  22. package/dist/esm/model/UiGraphBrowserRuntime.js +373 -0
  23. package/dist/esm/model/UiGraphNormalization.js +148 -0
  24. package/dist/esm/model/UiGraphRendererStyles.js +1108 -42
  25. package/dist/esm/model/UiGraphRuntimeModel.js +518 -2
  26. package/dist/esm/model/UiGraphSchema.js +91 -0
  27. package/dist/esm/model/UiGraphWebAppStatus.js +19 -0
  28. package/dist/esm/model/UiGraphWebAppStorage.js +1 -0
  29. package/dist/esm/model/chat/chatMessages.js +5 -9
  30. package/dist/esm/model/chat-v2/chatV2Errors.js +36 -3
  31. package/dist/esm/model/chat-v2/index.js +1 -0
  32. package/dist/esm/model/chat-v2/toolContinuation.js +6 -8
  33. package/dist/esm/model/chat-v2/toolContinuationConnection.js +68 -0
  34. package/dist/esm/model/nodes/ArrayNode.js +2 -13
  35. package/dist/esm/model/nodes/AssembleMessageNode.js +2 -13
  36. package/dist/esm/model/nodes/AssemblePromptNode.js +2 -13
  37. package/dist/esm/model/nodes/CoalesceNode.js +2 -15
  38. package/dist/esm/model/nodes/DelayNode.js +3 -14
  39. package/dist/esm/model/nodes/DelegateFunctionCallNode.js +12 -40
  40. package/dist/esm/model/nodes/DidRunNode.js +2 -13
  41. package/dist/esm/model/nodes/GetStoredValueNode.js +109 -0
  42. package/dist/esm/model/nodes/JoinNode.js +2 -13
  43. package/dist/esm/model/nodes/LLMChatV2Node.js +17 -1
  44. package/dist/esm/model/nodes/LoopControllerNode.js +3 -14
  45. package/dist/esm/model/nodes/MCPDiscoveryNode.js +19 -90
  46. package/dist/esm/model/nodes/MCPGetPromptNode.js +11 -97
  47. package/dist/esm/model/nodes/MCPToolCallNode.js +11 -97
  48. package/dist/esm/model/nodes/MatchNode.js +7 -7
  49. package/dist/esm/model/nodes/PassthroughNode.js +3 -14
  50. package/dist/esm/model/nodes/RaceInputsNode.js +2 -13
  51. package/dist/esm/model/nodes/ReportProgressNode.js +57 -0
  52. package/dist/esm/model/nodes/SetStoredValueNode.js +84 -0
  53. package/dist/esm/model/nodes/StartBackgroundBranchNode.js +59 -0
  54. package/dist/esm/model/nodes/StoredValueNodeUtils.js +47 -0
  55. package/dist/esm/model/nodes/toolCallDelegation.js +44 -1
  56. package/dist/esm/model/nodes/variadicPortIndex.js +32 -0
  57. package/dist/esm/plugins/anthropic/anthropic.js +1 -1
  58. package/dist/esm/recording/ExecutionRecorder.js +6 -0
  59. package/dist/esm/utils/coerceType.js +3 -0
  60. package/dist/esm/utils/fetchEventSource.js +16 -17
  61. package/dist/esm/utils/serialization/serialization.js +4 -0
  62. package/dist/esm/utils/serialization/serializationUtils.js +8 -27
  63. package/dist/esm/utils/serialization/serialization_v4.js +3 -3
  64. package/dist/esm/webAppRuntime.js +4 -2
  65. package/dist/types/api/createProcessor.d.ts +4 -0
  66. package/dist/types/api/streaming.d.ts +6 -0
  67. package/dist/types/exports.d.ts +8 -0
  68. package/dist/types/integrations/mcp/MCPBase.d.ts +26 -3
  69. package/dist/types/model/EditorDefinition.d.ts +2 -1
  70. package/dist/types/model/ExecutorProtocol.d.ts +19 -0
  71. package/dist/types/model/GraphBoundaryEffects.d.ts +9 -1
  72. package/dist/types/model/GraphProcessor.d.ts +26 -2
  73. package/dist/types/model/GraphProgress.d.ts +6 -0
  74. package/dist/types/model/ManagedAsyncBranches.d.ts +6 -0
  75. package/dist/types/model/Nodes.d.ts +6 -2
  76. package/dist/types/model/ProcessContext.d.ts +18 -0
  77. package/dist/types/model/ProcessContextBuilder.d.ts +3 -1
  78. package/dist/types/model/StoredValueStore.d.ts +55 -0
  79. package/dist/types/model/SubprocessorBridge.d.ts +4 -2
  80. package/dist/types/model/ToolCallContinuation.d.ts +13 -0
  81. package/dist/types/model/UiGraph.d.ts +63 -9
  82. package/dist/types/model/UiGraphActionProtocol.d.ts +71 -0
  83. package/dist/types/model/UiGraphBindings.d.ts +45 -0
  84. package/dist/types/model/UiGraphBrowserRuntime.d.ts +55 -0
  85. package/dist/types/model/UiGraphNormalization.d.ts +24 -0
  86. package/dist/types/model/UiGraphRendererStyles.d.ts +2 -2
  87. package/dist/types/model/UiGraphRuntimeModel.d.ts +97 -6
  88. package/dist/types/model/UiGraphSchema.d.ts +113 -0
  89. package/dist/types/model/UiGraphWebAppStatus.d.ts +5 -0
  90. package/dist/types/model/UiGraphWebAppStorage.d.ts +3 -0
  91. package/dist/types/model/chat-v2/index.d.ts +1 -0
  92. package/dist/types/model/chat-v2/toolContinuation.d.ts +1 -0
  93. package/dist/types/model/chat-v2/toolContinuationConnection.d.ts +28 -0
  94. package/dist/types/model/nodes/ArrayNode.d.ts +0 -1
  95. package/dist/types/model/nodes/AssembleMessageNode.d.ts +0 -1
  96. package/dist/types/model/nodes/AssemblePromptNode.d.ts +0 -1
  97. package/dist/types/model/nodes/DelayNode.d.ts +0 -1
  98. package/dist/types/model/nodes/DidRunNode.d.ts +0 -1
  99. package/dist/types/model/nodes/GetStoredValueNode.d.ts +25 -0
  100. package/dist/types/model/nodes/JoinNode.d.ts +0 -1
  101. package/dist/types/model/nodes/LoopControllerNode.d.ts +0 -1
  102. package/dist/types/model/nodes/PassthroughNode.d.ts +0 -1
  103. package/dist/types/model/nodes/RaceInputsNode.d.ts +0 -1
  104. package/dist/types/model/nodes/ReportProgressNode.d.ts +23 -0
  105. package/dist/types/model/nodes/SetStoredValueNode.d.ts +23 -0
  106. package/dist/types/model/nodes/StartBackgroundBranchNode.d.ts +14 -0
  107. package/dist/types/model/nodes/StoredValueNodeUtils.d.ts +5 -0
  108. package/dist/types/model/nodes/toolCallDelegation.d.ts +4 -0
  109. package/dist/types/model/nodes/variadicPortIndex.d.ts +4 -0
  110. package/dist/types/recording/RecordedEvents.d.ts +10 -0
  111. package/dist/types/webAppRuntime.d.ts +8 -3
  112. package/package.json +2 -2
  113. package/dist/esm/plugins/anthropic/fetchEventSource.js +0 -107
  114. package/dist/types/plugins/anthropic/fetchEventSource.d.ts +0 -11
@@ -0,0 +1,113 @@
1
+ import { z } from 'zod';
2
+ import type { GraphId } from './NodeGraph.js';
3
+ import { type UiComponentId, type UiGraph, type UiGraphComponent, type UiGraphId } from './UiGraph.js';
4
+ type LegacyUiGraphComponent = UiGraphComponent extends infer TComponent ? TComponent extends {
5
+ id: UiComponentId;
6
+ } ? Omit<TComponent, 'id'> & {
7
+ id?: UiComponentId;
8
+ } : never : never;
9
+ export declare const UI_GRAPH_COMPONENT_SCHEMA: z.ZodDiscriminatedUnion<[z.ZodObject<{
10
+ id: z.ZodOptional<z.ZodCustom<UiComponentId, UiComponentId>>;
11
+ type: z.ZodLiteral<"text">;
12
+ text: z.ZodString;
13
+ }, z.core.$strip>, z.ZodObject<{
14
+ id: z.ZodOptional<z.ZodCustom<UiComponentId, UiComponentId>>;
15
+ type: z.ZodLiteral<"markdown">;
16
+ markdown: z.ZodString;
17
+ }, z.core.$strip>, z.ZodObject<{
18
+ id: z.ZodOptional<z.ZodCustom<UiComponentId, UiComponentId>>;
19
+ type: z.ZodLiteral<"gap">;
20
+ size: z.ZodEnum<{
21
+ small: "small";
22
+ medium: "medium";
23
+ large: "large";
24
+ }>;
25
+ }, z.core.$strip>, z.ZodObject<{
26
+ id: z.ZodOptional<z.ZodCustom<UiComponentId, UiComponentId>>;
27
+ label: z.ZodString;
28
+ stateKey: z.ZodString;
29
+ placeholder: z.ZodOptional<z.ZodString>;
30
+ defaultValue: z.ZodOptional<z.ZodString>;
31
+ type: z.ZodLiteral<"input">;
32
+ }, z.core.$strip>, z.ZodObject<{
33
+ id: z.ZodOptional<z.ZodCustom<UiComponentId, UiComponentId>>;
34
+ label: z.ZodString;
35
+ stateKey: z.ZodString;
36
+ placeholder: z.ZodOptional<z.ZodString>;
37
+ defaultValue: z.ZodOptional<z.ZodString>;
38
+ type: z.ZodLiteral<"textarea">;
39
+ }, z.core.$strip>, z.ZodObject<{
40
+ id: z.ZodOptional<z.ZodCustom<UiComponentId, UiComponentId>>;
41
+ type: z.ZodLiteral<"dropdown">;
42
+ label: z.ZodString;
43
+ stateKey: z.ZodString;
44
+ items: z.ZodArray<z.ZodObject<{
45
+ label: z.ZodString;
46
+ value: z.ZodString;
47
+ }, z.core.$strip>>;
48
+ }, z.core.$strip>, z.ZodObject<{
49
+ id: z.ZodOptional<z.ZodCustom<UiComponentId, UiComponentId>>;
50
+ type: z.ZodLiteral<"button">;
51
+ label: z.ZodString;
52
+ action: z.ZodObject<{
53
+ type: z.ZodLiteral<"runGraph">;
54
+ graphId: z.ZodOptional<z.ZodCustom<GraphId, GraphId>>;
55
+ outputKey: z.ZodOptional<z.ZodString>;
56
+ outputStateKey: z.ZodOptional<z.ZodString>;
57
+ inputMappings: z.ZodOptional<z.ZodArray<z.ZodObject<{
58
+ inputKey: z.ZodString;
59
+ stateKey: z.ZodString;
60
+ }, z.core.$strip>>>;
61
+ inputs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{
62
+ key: z.ZodString;
63
+ type: z.ZodLiteral<"state">;
64
+ }, z.core.$strip>, z.ZodObject<{
65
+ type: z.ZodLiteral<"literal">;
66
+ value: z.ZodUnknown;
67
+ }, z.core.$strip>], "type">>>;
68
+ outputs: z.ZodOptional<z.ZodArray<z.ZodObject<{
69
+ outputKey: z.ZodOptional<z.ZodString>;
70
+ stateKey: z.ZodString;
71
+ }, z.core.$strip>>>;
72
+ }, z.core.$strip>;
73
+ }, z.core.$strip>, z.ZodObject<{
74
+ id: z.ZodOptional<z.ZodCustom<UiComponentId, UiComponentId>>;
75
+ type: z.ZodLiteral<"chat">;
76
+ placeholder: z.ZodOptional<z.ZodString>;
77
+ action: z.ZodObject<{
78
+ type: z.ZodLiteral<"runGraph">;
79
+ graphId: z.ZodOptional<z.ZodCustom<GraphId, GraphId>>;
80
+ userInputId: z.ZodOptional<z.ZodString>;
81
+ historyInputId: z.ZodOptional<z.ZodString>;
82
+ responseOutputId: z.ZodOptional<z.ZodString>;
83
+ inputMappings: z.ZodOptional<z.ZodArray<z.ZodObject<{
84
+ inputKey: z.ZodString;
85
+ stateKey: z.ZodString;
86
+ }, z.core.$strip>>>;
87
+ }, z.core.$strip>;
88
+ }, z.core.$strip>, z.ZodObject<{
89
+ id: z.ZodOptional<z.ZodCustom<UiComponentId, UiComponentId>>;
90
+ type: z.ZodLiteral<"output">;
91
+ label: z.ZodOptional<z.ZodString>;
92
+ stateKey: z.ZodString;
93
+ renderAs: z.ZodOptional<z.ZodEnum<{
94
+ image: "image";
95
+ text: "text";
96
+ json: "json";
97
+ markdown: "markdown";
98
+ }>>;
99
+ }, z.core.$strip>], "type">;
100
+ export declare const UI_GRAPH_ENVELOPE_SCHEMA: z.ZodObject<{
101
+ id: z.ZodCustom<UiGraphId, UiGraphId>;
102
+ name: z.ZodString;
103
+ description: z.ZodOptional<z.ZodString>;
104
+ components: z.ZodArray<z.ZodUnknown>;
105
+ }, z.core.$strip>;
106
+ type UiGraphEnvelope = Omit<UiGraph, 'components'> & {
107
+ components: unknown[];
108
+ };
109
+ type IsExactly<Left, Right> = [Left] extends [Right] ? ([Right] extends [Left] ? true : false) : false;
110
+ type Assert<Condition extends true> = Condition;
111
+ export type _UiGraphComponentSchemaTypeCheck = Assert<IsExactly<z.output<typeof UI_GRAPH_COMPONENT_SCHEMA>, LegacyUiGraphComponent>>;
112
+ export type _UiGraphEnvelopeSchemaTypeCheck = Assert<IsExactly<z.output<typeof UI_GRAPH_ENVELOPE_SCHEMA>, UiGraphEnvelope>>;
113
+ export {};
@@ -0,0 +1,5 @@
1
+ import type { ExternalFunction } from './GraphProcessor.js';
2
+ export declare const RIVET_WEB_APP_STATUS_FUNCTION_NAME = "setWebAppStatus";
3
+ /** Built-in External Call function used to report web-app status. */
4
+ export declare const rivetWebAppStatusExternalFunction: ExternalFunction;
5
+ export declare function formatRivetWebAppStatusMessage(value: unknown): string;
@@ -0,0 +1,3 @@
1
+ import type { RivetStoredValueRecord } from './StoredValueStore.js';
2
+ /** Browser-hosted snapshot/patch representation for one scoped web app. */
3
+ export type RivetWebAppStorage = RivetStoredValueRecord;
@@ -10,3 +10,4 @@ export * from './messageConverter.js';
10
10
  export * from './modelRegistry.js';
11
11
  export * from './providerOptions.js';
12
12
  export * from './toolConverter.js';
13
+ export * from './toolContinuationConnection.js';
@@ -7,6 +7,7 @@ export type ToolContinuationOptions = RunChatV2PipelineOptions & {
7
7
  maxToolRounds: number;
8
8
  functions: GptFunction[] | undefined;
9
9
  delegateToolCall: (toolCall: StreamedFunctionCall) => Promise<ToolContinuationToolResult>;
10
+ delegateToolCallRound?: (toolCalls: StreamedFunctionCall[], preToolMessage: string) => Promise<ToolContinuationToolResult[]>;
10
11
  runPipeline?: (options: RunChatV2PipelineOptions) => Promise<ChatV2PipelineResult>;
11
12
  };
12
13
  export type ToolContinuationToolResult = ChatMessageDataValue & {
@@ -0,0 +1,28 @@
1
+ import type { ChartNode, NodeConnection, NodeId, PortId } from '../NodeBase.js';
2
+ import type { NodeGraph } from '../NodeGraph.js';
3
+ export declare const LLM_CHAT_V2_TOOL_CALLS_OUTPUT_ID: PortId;
4
+ export declare const DELEGATE_TOOL_CALL_INPUT_ID: PortId;
5
+ type ContinuationGraph = Pick<NodeGraph, 'connections' | 'nodes'>;
6
+ export type ToolContinuationConnectionCandidate = {
7
+ connection: NodeConnection;
8
+ delegateNode: ChartNode<'delegateFunctionCall'>;
9
+ };
10
+ export type ToolContinuationConnectionResolution = {
11
+ kind: 'none';
12
+ } | ({
13
+ kind: 'connected';
14
+ } & ToolContinuationConnectionCandidate) | {
15
+ kind: 'ambiguous';
16
+ candidates: ToolContinuationConnectionCandidate[];
17
+ };
18
+ /**
19
+ * Resolves every special request/response relationship formed by an
20
+ * auto-continuing LLM Chat node and an effective Delegate Tool Call input.
21
+ * Callers that inspect a whole graph should reuse this single pass.
22
+ */
23
+ export declare function resolveToolContinuationConnections(graph: ContinuationGraph): ReadonlyMap<NodeId, Exclude<ToolContinuationConnectionResolution, {
24
+ kind: 'none';
25
+ }>>;
26
+ /** Resolves one LLM node while preserving the convenient `none` result. */
27
+ export declare function resolveToolContinuationConnection(graph: ContinuationGraph, llmNodeId: NodeId): ToolContinuationConnectionResolution;
28
+ export {};
@@ -8,7 +8,6 @@ export type ArrayNodeData = {
8
8
  flattenDeep?: boolean;
9
9
  };
10
10
  export declare class ArrayNodeImpl extends NodeImpl<ArrayNode> {
11
- #private;
12
11
  static create(): ArrayNode;
13
12
  getInputDefinitions(connections: NodeConnection[]): NodeInputDefinition[];
14
13
  getOutputDefinitions(): NodeOutputDefinition[];
@@ -11,7 +11,6 @@ export type AssembleMessageNodeData = {
11
11
  useToolCallIdInput?: boolean;
12
12
  };
13
13
  export declare class AssembleMessageNodeImpl extends NodeImpl<AssembleMessageNode> {
14
- #private;
15
14
  static create(): AssembleMessageNode;
16
15
  getInputDefinitions(connections: NodeConnection[]): NodeInputDefinition[];
17
16
  getOutputDefinitions(): NodeOutputDefinition[];
@@ -11,7 +11,6 @@ export type AssemblePromptNodeData = {
11
11
  useIsLastMessageCacheBreakpointInput?: boolean;
12
12
  };
13
13
  export declare class AssemblePromptNodeImpl extends NodeImpl<AssemblePromptNode> {
14
- #private;
15
14
  static create(): AssemblePromptNode;
16
15
  getInputDefinitions(connections: NodeConnection[]): NodeInputDefinition[];
17
16
  getOutputDefinitions(): NodeOutputDefinition[];
@@ -8,7 +8,6 @@ export type DelayNodeData = {
8
8
  useDelayInput?: boolean;
9
9
  };
10
10
  export declare class DelayNodeImpl extends NodeImpl<DelayNode> {
11
- #private;
12
11
  static create(): DelayNode;
13
12
  getInputDefinitions(connections: NodeConnection[]): NodeInputDefinition[];
14
13
  getOutputDefinitions(connections: NodeConnection[]): NodeOutputDefinition[];
@@ -5,7 +5,6 @@ import { type EditorDefinition } from '../EditorDefinition.js';
5
5
  export type DidRunNode = ChartNode<'didRun', DidRunNodeData>;
6
6
  export type DidRunNodeData = {};
7
7
  export declare class DidRunNodeImpl extends NodeImpl<DidRunNode> {
8
- #private;
9
8
  static create(): DidRunNode;
10
9
  getInputDefinitions(connections: NodeConnection[]): NodeInputDefinition[];
11
10
  getOutputDefinitions(): NodeOutputDefinition[];
@@ -0,0 +1,25 @@
1
+ import type { EditorDefinition } from '../EditorDefinition.js';
2
+ import type { ScalarOrArrayDataType } from '../DataValue.js';
3
+ import type { Inputs, Outputs } from '../GraphProcessor.js';
4
+ import type { ChartNode, NodeInputDefinition, NodeOutputDefinition } from '../NodeBase.js';
5
+ import { NodeImpl, type NodeUIData } from '../NodeImpl.js';
6
+ import type { InternalProcessContext } from '../ProcessContext.js';
7
+ import type { NodeBodySpec } from '../NodeBodySpec.js';
8
+ export type GetStoredValueNode = ChartNode<'getStoredValue', GetStoredValueNodeData>;
9
+ export type GetStoredValueNodeData = {
10
+ dataType: ScalarOrArrayDataType;
11
+ key: string;
12
+ onDemand: boolean;
13
+ useKeyInput: boolean;
14
+ wait: boolean;
15
+ };
16
+ export declare class GetStoredValueNodeImpl extends NodeImpl<GetStoredValueNode> {
17
+ static create(): GetStoredValueNode;
18
+ getInputDefinitions(): NodeInputDefinition[];
19
+ getOutputDefinitions(): NodeOutputDefinition[];
20
+ getEditors(): EditorDefinition<GetStoredValueNode>[];
21
+ getBody(): string | NodeBodySpec | undefined;
22
+ static getUIData(): NodeUIData;
23
+ process(inputs: Inputs, context: InternalProcessContext): Promise<Outputs>;
24
+ }
25
+ export declare const getStoredValueNode: import("../NodeDefinition.js").NodeDefinition<GetStoredValueNode>;
@@ -9,7 +9,6 @@ export type JoinNodeData = {
9
9
  useJoinStringInput?: boolean;
10
10
  };
11
11
  export declare class JoinNodeImpl extends NodeImpl<JoinNode> {
12
- #private;
13
12
  static create: () => JoinNode;
14
13
  getInputDefinitions(connections: NodeConnection[]): NodeInputDefinition[];
15
14
  getOutputDefinitions(): NodeOutputDefinition[];
@@ -9,7 +9,6 @@ export type LoopControllerNodeData = {
9
9
  atMaxIterationsAction?: 'break' | 'error';
10
10
  };
11
11
  export declare class LoopControllerNodeImpl extends NodeImpl<LoopControllerNode> {
12
- #private;
13
12
  static create(): LoopControllerNode;
14
13
  getInputDefinitions(connections: NodeConnection[], nodes: Record<NodeId, ChartNode>): NodeInputDefinition[];
15
14
  getOutputDefinitions(connections: NodeConnection[], nodes: Record<NodeId, ChartNode>): NodeOutputDefinition[];
@@ -4,7 +4,6 @@ import { type Inputs, type Outputs } from '../GraphProcessor.js';
4
4
  export type PassthroughNode = ChartNode<'passthrough', PassthroughNodeData>;
5
5
  export type PassthroughNodeData = {};
6
6
  export declare class PassthroughNodeImpl extends NodeImpl<PassthroughNode> {
7
- #private;
8
7
  static create: () => PassthroughNode;
9
8
  getInputDefinitions(connections: NodeConnection[]): NodeInputDefinition[];
10
9
  getOutputDefinitions(connections: NodeConnection[]): NodeOutputDefinition[];
@@ -5,7 +5,6 @@ import { type EditorDefinition } from '../../index.js';
5
5
  export type RaceInputsNode = ChartNode<'raceInputs', RaceInputsNodeData>;
6
6
  export type RaceInputsNodeData = {};
7
7
  export declare class RaceInputsNodeImpl extends NodeImpl<RaceInputsNode> {
8
- #private;
9
8
  static create(): RaceInputsNode;
10
9
  getInputDefinitions(connections: NodeConnection[]): NodeInputDefinition[];
11
10
  getOutputDefinitions(): NodeOutputDefinition[];
@@ -0,0 +1,23 @@
1
+ import type { DataValue } from '../DataValue.js';
2
+ import type { EditorDefinition } from '../EditorDefinition.js';
3
+ import type { Inputs } from '../GraphProcessor.js';
4
+ import type { ChartNode, NodeInputDefinition, NodeOutputDefinition } from '../NodeBase.js';
5
+ import { NodeImpl, type NodeUIData } from '../NodeImpl.js';
6
+ import type { InternalProcessContext } from '../ProcessContext.js';
7
+ export type ReportProgressNode = ChartNode<'reportProgress', ReportProgressNodeData>;
8
+ export type ReportProgressNodeData = {
9
+ message: string;
10
+ percent?: number;
11
+ useMessageInput: boolean;
12
+ usePercentInput: boolean;
13
+ };
14
+ export declare class ReportProgressNodeImpl extends NodeImpl<ReportProgressNode> {
15
+ static create(): ReportProgressNode;
16
+ getInputDefinitions(): NodeInputDefinition[];
17
+ getOutputDefinitions(): NodeOutputDefinition[];
18
+ getEditors(): EditorDefinition<ReportProgressNode>[];
19
+ getBody(): string;
20
+ static getUIData(): NodeUIData;
21
+ process(inputs: Inputs, context: InternalProcessContext): Promise<Record<string, DataValue>>;
22
+ }
23
+ export declare const reportProgressNode: import("../NodeDefinition.js").NodeDefinition<ReportProgressNode>;
@@ -0,0 +1,23 @@
1
+ import type { EditorDefinition } from '../EditorDefinition.js';
2
+ import { type ScalarOrArrayDataType } from '../DataValue.js';
3
+ import type { Inputs, Outputs } from '../GraphProcessor.js';
4
+ import type { ChartNode, NodeInputDefinition, NodeOutputDefinition } from '../NodeBase.js';
5
+ import { NodeImpl, type NodeUIData } from '../NodeImpl.js';
6
+ import type { InternalProcessContext } from '../ProcessContext.js';
7
+ import type { NodeBodySpec } from '../NodeBodySpec.js';
8
+ export type SetStoredValueNode = ChartNode<'setStoredValue', SetStoredValueNodeData>;
9
+ export type SetStoredValueNodeData = {
10
+ dataType: ScalarOrArrayDataType;
11
+ key: string;
12
+ useKeyInput: boolean;
13
+ };
14
+ export declare class SetStoredValueNodeImpl extends NodeImpl<SetStoredValueNode> {
15
+ static create(): SetStoredValueNode;
16
+ getInputDefinitions(): NodeInputDefinition[];
17
+ getOutputDefinitions(): NodeOutputDefinition[];
18
+ getEditors(): EditorDefinition<SetStoredValueNode>[];
19
+ getBody(): string | NodeBodySpec | undefined;
20
+ static getUIData(): NodeUIData;
21
+ process(inputs: Inputs, context: InternalProcessContext): Promise<Outputs>;
22
+ }
23
+ export declare const setStoredValueNode: import("../NodeDefinition.js").NodeDefinition<SetStoredValueNode>;
@@ -0,0 +1,14 @@
1
+ import type { Inputs, Outputs } from '../GraphProcessor.js';
2
+ import { type ChartNode, type NodeConnection, type NodeInputDefinition, type NodeOutputDefinition } from '../NodeBase.js';
3
+ import { NodeImpl, type NodeUIData } from '../NodeImpl.js';
4
+ export type StartBackgroundBranchNode = ChartNode<'startBackgroundBranch', StartBackgroundBranchNodeData>;
5
+ export type StartBackgroundBranchNodeData = {};
6
+ export declare class StartBackgroundBranchNodeImpl extends NodeImpl<StartBackgroundBranchNode> {
7
+ static create: () => StartBackgroundBranchNode;
8
+ getInputDefinitions(connections: NodeConnection[]): NodeInputDefinition[];
9
+ getOutputDefinitions(connections: NodeConnection[]): NodeOutputDefinition[];
10
+ static getUIData(): NodeUIData;
11
+ getBody(): string;
12
+ process(inputData: Inputs): Promise<Outputs>;
13
+ }
14
+ export declare const startBackgroundBranchNode: import("../NodeDefinition.js").NodeDefinition<StartBackgroundBranchNode>;
@@ -0,0 +1,5 @@
1
+ import { type DataValue, type ScalarOrArrayDataType } from '../DataValue.js';
2
+ import type { RivetStoredValue } from '../StoredValueStore.js';
3
+ export declare const portableStoredValueScalarTypes: ("string" | "number" | "boolean" | "object" | "date" | "time" | "datetime" | "any" | "vector")[];
4
+ export declare function storedValueToDataValue(value: RivetStoredValue, dataType: ScalarOrArrayDataType): DataValue;
5
+ export declare function missingStoredValueDataValue(dataType: ScalarOrArrayDataType): DataValue;
@@ -1,6 +1,7 @@
1
1
  import type { ParsedAssistantChatMessageFunctionCall, ChatMessage } from '../DataValue.js';
2
2
  import type { GraphId } from '../NodeGraph.js';
3
3
  import type { InternalProcessContext } from '../ProcessContext.js';
4
+ import type { Outputs } from '../GraphProcessor.js';
4
5
  export type ToolCallDelegationConfig = {
5
6
  handlers: {
6
7
  key: string | undefined;
@@ -15,6 +16,8 @@ export type ToolCallDelegationResult = {
15
16
  outputString: string;
16
17
  message: ChatMessage;
17
18
  record: DelegatedToolCallRecord;
19
+ /** Cost from this live delegation. Kept out of the replay record so replay cannot charge it again. */
20
+ cost?: number;
18
21
  };
19
22
  export type DelegatedToolCallRecord = {
20
23
  delegatedToolCall: true;
@@ -25,5 +28,6 @@ export type DelegatedToolCallRecord = {
25
28
  message: ChatMessage;
26
29
  };
27
30
  export declare function isDelegatedToolCallRecord(input: unknown): input is DelegatedToolCallRecord;
31
+ export declare function buildDelegatedToolCallOutputs(records: DelegatedToolCallRecord[], preToolMessage?: string, cost?: number): Outputs;
28
32
  export declare function normalizeFunctionCallInput(input: unknown): ParsedAssistantChatMessageFunctionCall;
29
33
  export declare function delegateToolCall(rawFunctionCall: unknown, context: InternalProcessContext, config: ToolCallDelegationConfig): Promise<ToolCallDelegationResult>;
@@ -0,0 +1,4 @@
1
+ import type { NodeConnection, NodeId } from '../NodeBase.js';
2
+ export type VariadicPortIndexPolicy = 'legacy' | 'decimal' | 'strict-positive';
3
+ export declare function getHighestVariadicPortIndex(connections: readonly NodeConnection[], inputNodeId: NodeId, prefix: string, policy: VariadicPortIndexPolicy): number;
4
+ export declare function getNextVariadicPortIndex(connections: readonly NodeConnection[], inputNodeId: NodeId, prefix: string, policy: VariadicPortIndexPolicy): number;
@@ -27,6 +27,11 @@ export type RecordedEventsMap = OverrideProperties<ProcessEvents, {
27
27
  graphId: GraphId;
28
28
  outputs: GraphOutputs;
29
29
  }>;
30
+ /** Called when root outputs are available before managed async branches finish. */
31
+ graphOutputsReady: WithOptionalExecution<{
32
+ graphId: GraphId;
33
+ outputs: GraphOutputs;
34
+ }>;
30
35
  /** Called when a graph or subgraph has been aborted. */
31
36
  graphAbort: WithOptionalExecution<{
32
37
  graphId: GraphId;
@@ -79,6 +84,11 @@ export type RecordedEventsMap = OverrideProperties<ProcessEvents, {
79
84
  index: number;
80
85
  processId: ProcessId;
81
86
  }>;
87
+ progress: WithOptionalExecution<{
88
+ nodeId: NodeId;
89
+ processId: ProcessId;
90
+ progress: ProcessEvents['progress']['progress'];
91
+ }>;
82
92
  /** Called when the outputs of a node have been cleared entirely. If processId is present, only the one process() should be cleared. */
83
93
  nodeOutputsCleared: WithOptionalExecution<{
84
94
  nodeId: NodeId;
@@ -1,4 +1,9 @@
1
- export type { UiComponentId, UiGraph, UiGraphComponent } from './model/UiGraph.js';
1
+ export type { UiComponentId, UiGraph, UiGraphActionComponent, UiGraphChatMessage, UiGraphChatPin, UiGraphComponent, } from './model/UiGraph.js';
2
+ export type { UiGraphInteractionSnapshot } from './model/UiGraphRuntimeModel.js';
3
+ export type { RivetWebAppClientMessage, RivetWebAppRunEvent, RivetWebAppServerMessage, } from './model/UiGraphActionProtocol.js';
4
+ export type { GraphProgress } from './model/GraphProgress.js';
2
5
  export type { RivetMarkdownSanitizerPolicy } from './model/MarkdownSanitizationPolicy.js';
3
- export { getUiGraphActionState } from './model/UiGraph.js';
4
- export { applyUiGraphStatePatch, getUiGraphComponentRenderModel, getUiGraphJsonOutputFilename, } from './model/UiGraphRuntimeModel.js';
6
+ export { createUiGraphChatHistoryFlushStatePatch, createUiGraphChatPinStatePatch, createUiGraphChatSubmissionStatePatch, getUiGraphActionState, getUiGraphChatDraftStateKey, getUiGraphChatMessagesStateKey, } from './model/UiGraph.js';
7
+ export { applyUiGraphStatePatch, createUiGraphActionExecutionController, createUiGraphInteractionController, getUiGraphComponentRenderModel, getUiGraphJsonOutputFilename, getUiGraphProgressiveJsonOutputChunks, } from './model/UiGraphRuntimeModel.js';
8
+ export { parseRivetWebAppClientMessage, parseRivetWebAppServerMessage, RIVET_WEB_APP_ACTION_PROTOCOL_VERSION, } from './model/UiGraphActionProtocol.js';
9
+ export { copyUiGraphText, applyUiGraphWebAppStorageActionPatch, applyUiGraphWebAppStoragePatch, clearUiGraphChatSearchMatches, downloadUiGraphJsonOutput, hasUiGraphChatPersistentStateChanged, getUiGraphChatPersistentState, getUiGraphChatStorageKey, getUiGraphWebAppStorageKey, highlightUiGraphChatSearchMatches, loadUiGraphChatPersistentState, loadUiGraphWebAppStorage, observeUiGraphOutputResizeBounds, revealUiGraphChatElement, revealUiGraphChatSearchMatch, saveUiGraphChatPersistentState, } from './model/UiGraphBrowserRuntime.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valerypopoff/rivet2-core",
3
- "version": "2.1.3",
3
+ "version": "2.1.5",
4
4
  "license": "MIT",
5
5
  "main": "dist/cjs/bundle.cjs",
6
6
  "module": "dist/esm/index.js",
@@ -27,7 +27,7 @@
27
27
  "./web-app-runtime": {
28
28
  "types": "./dist/types/webAppRuntime.d.ts",
29
29
  "import": "./dist/esm/webAppRuntime.js",
30
- "require": "./dist/cjs/bundle.cjs"
30
+ "require": "./dist/cjs/webAppRuntime.cjs"
31
31
  }
32
32
  },
33
33
  "files": [
@@ -1,107 +0,0 @@
1
- import { DEFAULT_CHAT_NODE_TIMEOUT } from '../../utils/defaults.js';
2
- // https://github.com/openai/openai-node/issues/18#issuecomment-1518715285
3
- export class EventSourceResponse extends Response {
4
- name;
5
- streams;
6
- constructor(body, init) {
7
- if (body == null) {
8
- super(null, init);
9
- this.name = 'EventSourceResponse';
10
- this.streams = null;
11
- return;
12
- }
13
- const [bodyForString, bodyForEvents] = body.tee();
14
- const streams = createEventStream(bodyForEvents);
15
- // By passing our transformed stream into the Response constructor, we prevent anyone
16
- // from accidentally accessing the raw response.body stream.
17
- super(bodyForString, init);
18
- this.name = 'EventSourceResponse';
19
- this.streams = streams;
20
- }
21
- async *events() {
22
- if (this.streams == null) {
23
- return;
24
- }
25
- const reader = this.streams.eventStream.getReader();
26
- try {
27
- while (true) {
28
- const { done, value } = await this.raceWithTimeout(reader.read(), DEFAULT_CHAT_NODE_TIMEOUT);
29
- if (done) {
30
- break;
31
- }
32
- yield value;
33
- }
34
- }
35
- finally {
36
- reader.releaseLock();
37
- }
38
- }
39
- async raceWithTimeout(promise, timeout = 5000) {
40
- // eslint-disable-next-line no-async-promise-executor,@typescript-eslint/no-misused-promises -- Error handled correctly
41
- return new Promise(async (resolve, reject) => {
42
- const timer = setTimeout(() => {
43
- reject(new Error('Timeout: API response took too long.'));
44
- }, timeout);
45
- try {
46
- const result = await promise;
47
- clearTimeout(timer);
48
- resolve(result);
49
- }
50
- catch (error) {
51
- clearTimeout(timer);
52
- reject(error);
53
- }
54
- });
55
- }
56
- }
57
- export default async function fetchEventSource(url, init) {
58
- const headers = {
59
- ...init?.headers,
60
- accept: 'text/event-stream',
61
- };
62
- const response = await fetch(url, {
63
- ...init,
64
- headers,
65
- });
66
- return new EventSourceResponse(response.body, response);
67
- }
68
- class LineSplitter {
69
- separator;
70
- buffer = '';
71
- constructor(separator = /\n+/) {
72
- this.separator = separator;
73
- }
74
- transform(chunk, controller) {
75
- this.buffer += chunk;
76
- const lines = this.buffer.split(this.separator);
77
- this.buffer = lines.pop() ?? '';
78
- for (const line of lines) {
79
- controller.enqueue(line);
80
- }
81
- }
82
- flush(controller) {
83
- if (this.buffer.length > 0) {
84
- controller.enqueue(this.buffer);
85
- this.buffer = '';
86
- }
87
- }
88
- }
89
- function createEventStream(body) {
90
- if (body == null) {
91
- return null;
92
- }
93
- const textStream = body.pipeThrough(new TextDecoderStream());
94
- const eventStream = textStream.pipeThrough(new TransformStream(new LineSplitter())).pipeThrough(new TransformStream({
95
- transform(line, controller) {
96
- if (line.startsWith('data: ')) {
97
- const data = line.slice(6).trim();
98
- controller.enqueue(data);
99
- }
100
- else if (line.startsWith('event: ')) {
101
- const event = line.slice(7).trim();
102
- controller.enqueue(`[${event}]`);
103
- }
104
- },
105
- }));
106
- return { eventStream, textStream };
107
- }
@@ -1,11 +0,0 @@
1
- export declare class EventSourceResponse extends Response {
2
- name: string;
3
- readonly streams: {
4
- eventStream: ReadableStream<string>;
5
- textStream: ReadableStream<string>;
6
- } | null;
7
- constructor(body: ReadableStream<Uint8Array> | null, init?: ResponseInit);
8
- events(): AsyncGenerator<string>;
9
- private raceWithTimeout;
10
- }
11
- export default function fetchEventSource(url: string, init?: RequestInit): Promise<EventSourceResponse>;