@valerypopoff/rivet2-core 2.1.2 → 2.1.4
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 +3373 -1208
- package/dist/cjs/bundle.cjs.map +4 -4
- package/dist/cjs/webAppRuntime.cjs +625 -0
- package/dist/cjs/webAppRuntime.cjs.map +7 -0
- package/dist/esm/api/createProcessor.js +3 -0
- package/dist/esm/api/processSettings.js +5 -0
- package/dist/esm/api/streaming.js +6 -0
- package/dist/esm/exports.js +7 -0
- package/dist/esm/integrations/mcp/MCPBase.js +92 -34
- package/dist/esm/model/GraphProcessor.js +35 -49
- package/dist/esm/model/GraphProgress.js +15 -0
- package/dist/esm/model/GraphRunLifecycle.js +67 -0
- package/dist/esm/model/MarkdownSanitizationPolicy.js +38 -0
- package/dist/esm/model/Nodes.js +3 -0
- package/dist/esm/model/ProcessContextBuilder.js +2 -1
- package/dist/esm/model/RecordingPlayer.js +10 -0
- package/dist/esm/model/SubprocessorBridge.js +1 -0
- package/dist/esm/model/UiGraph.js +181 -1
- package/dist/esm/model/UiGraphActionProtocol.js +122 -0
- package/dist/esm/model/UiGraphBindings.js +530 -0
- package/dist/esm/model/UiGraphBrowserRuntime.js +40 -0
- package/dist/esm/model/UiGraphNormalization.js +298 -0
- package/dist/esm/model/UiGraphRendererStyles.js +456 -6
- package/dist/esm/model/UiGraphRuntimeModel.js +371 -0
- package/dist/esm/model/UiGraphWebAppStatus.js +19 -0
- package/dist/esm/model/chat-v2/aiSdkBridge.js +1 -1
- package/dist/esm/model/chat-v2/chatV2EditorCache.js +2 -2
- package/dist/esm/model/chat-v2/chatV2Pipeline.js +35 -48
- package/dist/esm/model/chat-v2/chatV2ProviderProfile.js +98 -0
- package/dist/esm/model/chat-v2/chatV2RequestPlan.js +64 -0
- package/dist/esm/model/chat-v2/chatV2RuntimeOptions.js +11 -39
- package/dist/esm/model/chat-v2/index.js +2 -0
- package/dist/esm/model/chat-v2/llmChatV2NodeData.js +1 -0
- package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +31 -11
- package/dist/esm/model/chat-v2/llmChatV2NodeRuntime.js +21 -9
- package/dist/esm/model/chat-v2/providerOptions.js +9 -35
- package/dist/esm/model/nodes/ArrayNode.js +2 -13
- package/dist/esm/model/nodes/AssembleMessageNode.js +2 -13
- package/dist/esm/model/nodes/AssemblePromptNode.js +2 -13
- package/dist/esm/model/nodes/CoalesceNode.js +2 -15
- package/dist/esm/model/nodes/DelayNode.js +3 -14
- package/dist/esm/model/nodes/DidRunNode.js +2 -13
- package/dist/esm/model/nodes/JoinNode.js +2 -13
- package/dist/esm/model/nodes/LLMChatV2Node.js +3 -3
- package/dist/esm/model/nodes/LoopControllerNode.js +3 -14
- package/dist/esm/model/nodes/MCPDiscoveryNode.js +19 -90
- package/dist/esm/model/nodes/MCPGetPromptNode.js +11 -97
- package/dist/esm/model/nodes/MCPToolCallNode.js +11 -97
- package/dist/esm/model/nodes/PassthroughNode.js +3 -14
- package/dist/esm/model/nodes/RaceInputsNode.js +2 -13
- package/dist/esm/model/nodes/ReportProgressNode.js +57 -0
- package/dist/esm/model/nodes/variadicPortIndex.js +32 -0
- package/dist/esm/plugins/anthropic/anthropic.js +1 -1
- package/dist/esm/plugins/autoevals/AutoEvalsNode.js +3 -1
- package/dist/esm/plugins/gentrace/gentraceSdk.js +8 -0
- package/dist/esm/plugins/gentrace/plugin.js +5 -4
- package/dist/esm/plugins/google/google.js +9 -7
- package/dist/esm/recording/ExecutionRecorder.js +5 -0
- package/dist/esm/utils/fetchEventSource.js +16 -17
- package/dist/esm/utils/pQueueCompat.js +1 -1
- package/dist/esm/utils/serialization/serialization.js +4 -0
- package/dist/esm/utils/serialization/serializationUtils.js +16 -0
- package/dist/esm/utils/serialization/serialization_v4.js +5 -4
- package/dist/esm/webAppRuntime.js +4 -0
- package/dist/types/api/createProcessor.d.ts +1 -1
- package/dist/types/api/processSettings.d.ts +3 -4
- package/dist/types/api/streaming.d.ts +6 -0
- package/dist/types/exports.d.ts +7 -0
- package/dist/types/integrations/mcp/MCPBase.d.ts +26 -3
- package/dist/types/model/ExecutorProtocol.d.ts +7 -0
- package/dist/types/model/GraphProcessor.d.ts +7 -0
- package/dist/types/model/GraphProgress.d.ts +6 -0
- package/dist/types/model/GraphRunLifecycle.d.ts +22 -0
- package/dist/types/model/MarkdownSanitizationPolicy.d.ts +9 -0
- package/dist/types/model/Nodes.d.ts +3 -2
- package/dist/types/model/ProcessContext.d.ts +5 -2
- package/dist/types/model/ProcessContextBuilder.d.ts +2 -1
- package/dist/types/model/Settings.d.ts +1 -0
- package/dist/types/model/UiGraph.d.ts +50 -5
- package/dist/types/model/UiGraphActionProtocol.d.ts +69 -0
- package/dist/types/model/UiGraphBindings.d.ts +45 -0
- package/dist/types/model/UiGraphBrowserRuntime.d.ts +4 -0
- package/dist/types/model/UiGraphNormalization.d.ts +24 -0
- package/dist/types/model/UiGraphRendererStyles.d.ts +1 -1
- package/dist/types/model/UiGraphRuntimeModel.d.ts +124 -0
- package/dist/types/model/UiGraphWebAppStatus.d.ts +5 -0
- package/dist/types/model/chat-v2/chatV2ProviderProfile.d.ts +46 -0
- package/dist/types/model/chat-v2/chatV2RequestPlan.d.ts +42 -0
- package/dist/types/model/chat-v2/chatV2Types.d.ts +1 -0
- package/dist/types/model/chat-v2/index.d.ts +2 -0
- package/dist/types/model/chat-v2/llmChatV2NodeData.d.ts +1 -0
- package/dist/types/model/chat-v2/llmChatV2NodeRuntime.d.ts +2 -0
- package/dist/types/model/chat-v2/providerOptions.d.ts +2 -2
- package/dist/types/model/nodes/ArrayNode.d.ts +0 -1
- package/dist/types/model/nodes/AssembleMessageNode.d.ts +0 -1
- package/dist/types/model/nodes/AssemblePromptNode.d.ts +0 -1
- package/dist/types/model/nodes/DelayNode.d.ts +0 -1
- package/dist/types/model/nodes/DidRunNode.d.ts +0 -1
- package/dist/types/model/nodes/JoinNode.d.ts +0 -1
- package/dist/types/model/nodes/LoopControllerNode.d.ts +0 -1
- package/dist/types/model/nodes/PassthroughNode.d.ts +0 -1
- package/dist/types/model/nodes/RaceInputsNode.d.ts +0 -1
- package/dist/types/model/nodes/ReportProgressNode.d.ts +23 -0
- package/dist/types/model/nodes/variadicPortIndex.d.ts +4 -0
- package/dist/types/plugins/gentrace/gentraceSdk.d.ts +5 -0
- package/dist/types/plugins/gentrace/plugin.d.ts +1 -1
- package/dist/types/recording/RecordedEvents.d.ts +5 -0
- package/dist/types/utils/pQueueCompat.d.ts +1 -1
- package/dist/types/webAppRuntime.d.ts +9 -0
- package/package.json +15 -9
- package/dist/esm/plugins/anthropic/fetchEventSource.js +0 -107
- package/dist/types/plugins/anthropic/fetchEventSource.d.ts +0 -11
|
@@ -4,6 +4,7 @@ import {} from '../NodeBase.js';
|
|
|
4
4
|
import { nanoid } from 'nanoid/non-secure';
|
|
5
5
|
import {} from '../GraphProcessor.js';
|
|
6
6
|
import { dedent } from 'ts-dedent';
|
|
7
|
+
import { getNextVariadicPortIndex } from './variadicPortIndex.js';
|
|
7
8
|
export class PassthroughNodeImpl extends NodeImpl {
|
|
8
9
|
static create = () => {
|
|
9
10
|
const chartNode = {
|
|
@@ -21,7 +22,7 @@ export class PassthroughNodeImpl extends NodeImpl {
|
|
|
21
22
|
};
|
|
22
23
|
getInputDefinitions(connections) {
|
|
23
24
|
const inputs = [];
|
|
24
|
-
const inputCount =
|
|
25
|
+
const inputCount = getNextVariadicPortIndex(connections, this.chartNode.id, 'input', 'decimal');
|
|
25
26
|
for (let i = 1; i <= inputCount; i++) {
|
|
26
27
|
inputs.push({
|
|
27
28
|
dataType: 'any',
|
|
@@ -33,7 +34,7 @@ export class PassthroughNodeImpl extends NodeImpl {
|
|
|
33
34
|
}
|
|
34
35
|
getOutputDefinitions(connections) {
|
|
35
36
|
const outputs = [];
|
|
36
|
-
const inputCount =
|
|
37
|
+
const inputCount = getNextVariadicPortIndex(connections, this.chartNode.id, 'input', 'decimal');
|
|
37
38
|
for (let i = 1; i <= inputCount - 1; i++) {
|
|
38
39
|
outputs.push({
|
|
39
40
|
dataType: 'any',
|
|
@@ -53,18 +54,6 @@ export class PassthroughNodeImpl extends NodeImpl {
|
|
|
53
54
|
group: ['Logic'],
|
|
54
55
|
};
|
|
55
56
|
}
|
|
56
|
-
#getInputPortCount(connections) {
|
|
57
|
-
const inputNodeId = this.chartNode.id;
|
|
58
|
-
const inputConnections = connections.filter((connection) => connection.inputNodeId === inputNodeId && connection.inputId.startsWith('input'));
|
|
59
|
-
let maxInputNumber = 0;
|
|
60
|
-
for (const connection of inputConnections) {
|
|
61
|
-
const messageNumber = parseInt(connection.inputId.replace('input', ''), 10);
|
|
62
|
-
if (messageNumber > maxInputNumber) {
|
|
63
|
-
maxInputNumber = messageNumber;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return maxInputNumber + 1;
|
|
67
|
-
}
|
|
68
57
|
async process(inputData) {
|
|
69
58
|
const inputCount = Object.keys(inputData).filter((key) => key.startsWith('input')).length;
|
|
70
59
|
const outputs = {};
|
|
@@ -5,6 +5,7 @@ import { nodeDefinition } from '../NodeDefinition.js';
|
|
|
5
5
|
import {} from '../GraphProcessor.js';
|
|
6
6
|
import { dedent } from 'ts-dedent';
|
|
7
7
|
import {} from '../../index.js';
|
|
8
|
+
import { getNextVariadicPortIndex } from './variadicPortIndex.js';
|
|
8
9
|
export class RaceInputsNodeImpl extends NodeImpl {
|
|
9
10
|
static create() {
|
|
10
11
|
const chartNode = {
|
|
@@ -20,21 +21,9 @@ export class RaceInputsNodeImpl extends NodeImpl {
|
|
|
20
21
|
};
|
|
21
22
|
return chartNode;
|
|
22
23
|
}
|
|
23
|
-
#getInputPortCount(connections) {
|
|
24
|
-
const inputNodeId = this.chartNode.id;
|
|
25
|
-
const inputConnections = connections.filter((connection) => connection.inputNodeId === inputNodeId && connection.inputId.startsWith('input'));
|
|
26
|
-
let maxInputNumber = 0;
|
|
27
|
-
for (const connection of inputConnections) {
|
|
28
|
-
const messageNumber = parseInt(connection.inputId.replace('input', ''), 10);
|
|
29
|
-
if (messageNumber > maxInputNumber) {
|
|
30
|
-
maxInputNumber = messageNumber;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return maxInputNumber + 1;
|
|
34
|
-
}
|
|
35
24
|
getInputDefinitions(connections) {
|
|
36
25
|
const inputs = [];
|
|
37
|
-
const inputCount =
|
|
26
|
+
const inputCount = getNextVariadicPortIndex(connections, this.chartNode.id, 'input', 'decimal');
|
|
38
27
|
for (let i = 1; i <= inputCount; i++) {
|
|
39
28
|
inputs.push({
|
|
40
29
|
dataType: 'any',
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { nanoid } from 'nanoid/non-secure';
|
|
2
|
+
import { coerceTypeOptional } from '../../utils/coerceType.js';
|
|
3
|
+
import { nodeDefinition } from '../NodeDefinition.js';
|
|
4
|
+
import { NodeImpl } from '../NodeImpl.js';
|
|
5
|
+
export class ReportProgressNodeImpl extends NodeImpl {
|
|
6
|
+
static create() {
|
|
7
|
+
return {
|
|
8
|
+
id: nanoid(),
|
|
9
|
+
type: 'reportProgress',
|
|
10
|
+
title: 'Report Progress',
|
|
11
|
+
visualData: { x: 0, y: 0, width: 200 },
|
|
12
|
+
data: { message: '', useMessageInput: true, usePercentInput: true },
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
getInputDefinitions() {
|
|
16
|
+
return [
|
|
17
|
+
{ dataType: 'any', id: 'value', required: true, title: 'Value' },
|
|
18
|
+
...(this.data.useMessageInput
|
|
19
|
+
? [{ dataType: 'string', id: 'message', title: 'Message' }]
|
|
20
|
+
: []),
|
|
21
|
+
...(this.data.usePercentInput
|
|
22
|
+
? [{ dataType: 'number', id: 'percent', title: 'Percent' }]
|
|
23
|
+
: []),
|
|
24
|
+
];
|
|
25
|
+
}
|
|
26
|
+
getOutputDefinitions() {
|
|
27
|
+
return [{ dataType: 'any', id: 'value', title: 'Value' }];
|
|
28
|
+
}
|
|
29
|
+
getEditors() {
|
|
30
|
+
return [
|
|
31
|
+
{ type: 'string', label: 'Message', dataKey: 'message', useInputToggleDataKey: 'useMessageInput' },
|
|
32
|
+
{ type: 'number', label: 'Percent', dataKey: 'percent', useInputToggleDataKey: 'usePercentInput' },
|
|
33
|
+
];
|
|
34
|
+
}
|
|
35
|
+
getBody() {
|
|
36
|
+
return this.data.message || 'Reports progress to the host';
|
|
37
|
+
}
|
|
38
|
+
static getUIData() {
|
|
39
|
+
return {
|
|
40
|
+
contextMenuTitle: 'Report Progress',
|
|
41
|
+
group: ['Advanced'],
|
|
42
|
+
infoBoxTitle: 'Report Progress',
|
|
43
|
+
infoBoxBody: 'Reports a public status message and/or percentage to progress-aware hosts such as Rivet web apps.',
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
async process(inputs, context) {
|
|
47
|
+
const message = this.data.useMessageInput
|
|
48
|
+
? coerceTypeOptional(inputs['message'], 'string')
|
|
49
|
+
: this.data.message;
|
|
50
|
+
const percent = this.data.usePercentInput
|
|
51
|
+
? coerceTypeOptional(inputs['percent'], 'number')
|
|
52
|
+
: this.data.percent;
|
|
53
|
+
context.reportProgress({ message, percent });
|
|
54
|
+
return { value: inputs['value'] };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export const reportProgressNode = nodeDefinition(ReportProgressNodeImpl, 'Report Progress');
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export function getHighestVariadicPortIndex(connections, inputNodeId, prefix, policy) {
|
|
2
|
+
let highestIndex = 0;
|
|
3
|
+
for (const connection of connections) {
|
|
4
|
+
if (connection.inputNodeId !== inputNodeId || !connection.inputId.startsWith(prefix)) {
|
|
5
|
+
continue;
|
|
6
|
+
}
|
|
7
|
+
const index = parseVariadicPortIndex(connection.inputId, prefix, policy);
|
|
8
|
+
if (index != null && index > highestIndex) {
|
|
9
|
+
highestIndex = index;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return highestIndex;
|
|
13
|
+
}
|
|
14
|
+
export function getNextVariadicPortIndex(connections, inputNodeId, prefix, policy) {
|
|
15
|
+
return getHighestVariadicPortIndex(connections, inputNodeId, prefix, policy) + 1;
|
|
16
|
+
}
|
|
17
|
+
function parseVariadicPortIndex(portId, prefix, policy) {
|
|
18
|
+
if (policy === 'legacy') {
|
|
19
|
+
const index = parseInt(portId.replace(prefix, ''));
|
|
20
|
+
return Number.isNaN(index) ? undefined : index;
|
|
21
|
+
}
|
|
22
|
+
if (policy === 'decimal') {
|
|
23
|
+
const index = parseInt(portId.replace(prefix, ''), 10);
|
|
24
|
+
return Number.isNaN(index) ? undefined : index;
|
|
25
|
+
}
|
|
26
|
+
const indexText = portId.slice(prefix.length);
|
|
27
|
+
if (!/^\d+$/.test(indexText)) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
const index = Number(indexText);
|
|
31
|
+
return Number.isSafeInteger(index) && index > 0 ? index : undefined;
|
|
32
|
+
}
|
|
@@ -207,7 +207,9 @@ export const AutoEvalsNodeImpl = {
|
|
|
207
207
|
return {
|
|
208
208
|
['score']: {
|
|
209
209
|
type: 'number',
|
|
210
|
-
|
|
210
|
+
// Newer AutoEvals versions represent unavailable scores as null, while
|
|
211
|
+
// this node's declared port remains numeric.
|
|
212
|
+
value: result.score ?? 0,
|
|
211
213
|
},
|
|
212
214
|
['rationale']: {
|
|
213
215
|
type: 'string',
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Gentrace's package root also exports its Node-only job runner. Keep the
|
|
2
|
+
// browser-compatible APIs behind this adapter so app bundles do not pull in
|
|
3
|
+
// async_hooks and ws through exports that Rivet never uses.
|
|
4
|
+
export { init } from '@gentrace/core/dist/providers/init.mjs';
|
|
5
|
+
export { getPipelines } from '@gentrace/core/dist/providers/pipeline-methods.mjs';
|
|
6
|
+
export { Pipeline } from '@gentrace/core/dist/providers/pipeline.mjs';
|
|
7
|
+
export { runTest } from '@gentrace/core/dist/providers/run-test.mjs';
|
|
8
|
+
export { StepRun } from '@gentrace/core/dist/providers/step-run.mjs';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Pipeline, StepRun, init, runTest, getPipelines } from '
|
|
1
|
+
import { Pipeline, StepRun, init, runTest, getPipelines } from './gentraceSdk.js';
|
|
2
2
|
import { globalRivetNodeRegistry } from '../../model/Nodes.js';
|
|
3
3
|
import { cloneDeep, mapValues } from 'lodash-es';
|
|
4
4
|
import { GptTokenizerTokenizer } from '../../integrations/GptTokenizerTokenizer.js';
|
|
@@ -6,6 +6,7 @@ import { ExecutionRecorder } from '../../recording/ExecutionRecorder.js';
|
|
|
6
6
|
import { inferType } from '../../utils/coerceType.js';
|
|
7
7
|
// eslint-disable-next-line import/no-cycle -- Local Gentrace execution intentionally depends on GraphProcessor.
|
|
8
8
|
import { GraphProcessor } from '../../model/GraphProcessor.js';
|
|
9
|
+
import { resolveProcessSettings } from '../../api/processSettings.js';
|
|
9
10
|
const apiKeyConfigSpec = {
|
|
10
11
|
type: 'secret',
|
|
11
12
|
label: 'Gentrace API Key',
|
|
@@ -47,7 +48,7 @@ export const runGentraceTests = async (gentracePipelineSlug, settings, project,
|
|
|
47
48
|
recorder.record(processor);
|
|
48
49
|
const runContextValues = cloneDeep(contextValues);
|
|
49
50
|
await processor.processGraph({
|
|
50
|
-
settings,
|
|
51
|
+
settings: resolveProcessSettings(settings),
|
|
51
52
|
nativeApi,
|
|
52
53
|
tokenizer: new GptTokenizerTokenizer(),
|
|
53
54
|
}, rivetFormattedInputs, runContextValues);
|
|
@@ -175,11 +176,11 @@ function convertRecordingToStepRuns(recording, project, graphId) {
|
|
|
175
176
|
},
|
|
176
177
|
};
|
|
177
178
|
});
|
|
178
|
-
stepRuns.push(new StepRun('openai', 'openai_createChatCompletion', pair.end - pair.start, new Date(pair.start).toISOString(), new Date(pair.end).toISOString(), gentraceOpenAIInputs, gentraceOpenAIModelParams, gentraceOpenAIOutputs, {}));
|
|
179
|
+
stepRuns.push(new StepRun('openai', 'openai_createChatCompletion', pair.end - pair.start, new Date(pair.start).toISOString(), new Date(pair.end).toISOString(), gentraceOpenAIInputs, gentraceOpenAIModelParams, gentraceOpenAIOutputs, {}, undefined));
|
|
179
180
|
continue;
|
|
180
181
|
}
|
|
181
182
|
}
|
|
182
|
-
stepRuns.push(new StepRun('rivet', nodeType ? `rivet_operation_${nodeType}` : 'rivet_operation', pair.end - pair.start, new Date(pair.start).toISOString(), new Date(pair.end).toISOString(), pair.inputs, pair.modelParams, pair.outputs, {}));
|
|
183
|
+
stepRuns.push(new StepRun('rivet', nodeType ? `rivet_operation_${nodeType}` : 'rivet_operation', pair.end - pair.start, new Date(pair.start).toISOString(), new Date(pair.end).toISOString(), pair.inputs, pair.modelParams, pair.outputs, {}, undefined));
|
|
183
184
|
}
|
|
184
185
|
return stepRuns;
|
|
185
186
|
}
|
|
@@ -135,11 +135,11 @@ export async function* streamChatCompletions({ project, location, applicationCre
|
|
|
135
135
|
const vertexAi = new VertexAI({ project, location });
|
|
136
136
|
const generativeModel = vertexAi.preview.getGenerativeModel({
|
|
137
137
|
model,
|
|
138
|
-
|
|
139
|
-
max_output_tokens,
|
|
138
|
+
generationConfig: {
|
|
139
|
+
maxOutputTokens: max_output_tokens,
|
|
140
140
|
temperature,
|
|
141
|
-
top_p,
|
|
142
|
-
top_k,
|
|
141
|
+
topP: top_p,
|
|
142
|
+
topK: top_k,
|
|
143
143
|
},
|
|
144
144
|
});
|
|
145
145
|
const response = await generativeModel.generateContentStream({
|
|
@@ -148,10 +148,12 @@ export async function* streamChatCompletions({ project, location, applicationCre
|
|
|
148
148
|
let hadChunks = false;
|
|
149
149
|
for await (const chunk of response.stream) {
|
|
150
150
|
hadChunks = true;
|
|
151
|
-
|
|
151
|
+
const candidate = chunk.candidates?.[0];
|
|
152
|
+
const completion = candidate?.content.parts[0]?.text;
|
|
153
|
+
if (!signal?.aborted && completion) {
|
|
152
154
|
yield {
|
|
153
|
-
completion
|
|
154
|
-
finish_reason:
|
|
155
|
+
completion,
|
|
156
|
+
finish_reason: candidate.finishReason,
|
|
155
157
|
model,
|
|
156
158
|
};
|
|
157
159
|
}
|
|
@@ -65,6 +65,11 @@ const toRecordedEventMap = {
|
|
|
65
65
|
index,
|
|
66
66
|
processId,
|
|
67
67
|
}, execution),
|
|
68
|
+
progress: ({ node, processId, progress, execution }) => withExecution({
|
|
69
|
+
nodeId: node.id,
|
|
70
|
+
processId,
|
|
71
|
+
progress,
|
|
72
|
+
}, execution),
|
|
68
73
|
nodeOutputsCleared: ({ node, processId, execution }) => withExecution({
|
|
69
74
|
nodeId: node.id,
|
|
70
75
|
processId,
|
|
@@ -47,28 +47,27 @@ export class EventSourceResponse extends Response {
|
|
|
47
47
|
}
|
|
48
48
|
async raceWithTimeout(promise, timeout) {
|
|
49
49
|
const raceTimeout = timeout ?? DEFAULT_CHAT_NODE_TIMEOUT;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
50
|
+
let timer;
|
|
51
|
+
try {
|
|
52
|
+
return await Promise.race([
|
|
53
|
+
promise,
|
|
54
|
+
new Promise((_resolve, reject) => {
|
|
55
|
+
timer = setTimeout(() => {
|
|
56
|
+
reject(new Error('Timeout: API response took too long.'));
|
|
57
|
+
}, raceTimeout);
|
|
58
|
+
}),
|
|
59
|
+
]);
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
if (timer != null) {
|
|
61
63
|
clearTimeout(timer);
|
|
62
|
-
reject(error);
|
|
63
64
|
}
|
|
64
|
-
}
|
|
65
|
+
}
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
export default async function fetchEventSource(url, init, timeout) {
|
|
68
|
-
const headers =
|
|
69
|
-
|
|
70
|
-
accept: 'text/event-stream',
|
|
71
|
-
};
|
|
69
|
+
const headers = new Headers(init?.headers);
|
|
70
|
+
headers.set('accept', 'text/event-stream');
|
|
72
71
|
const response = await fetch(url, {
|
|
73
72
|
...init,
|
|
74
73
|
headers,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import PQueueImport from 'p-queue';
|
|
2
2
|
/**
|
|
3
|
-
* p-queue v7+ is ESM-only. The CJS bundle (built by bundle.esbuild.
|
|
3
|
+
* p-queue v7+ is ESM-only. The CJS bundle (built by bundle.esbuild.cjs) aliases
|
|
4
4
|
* `p-queue` to `p-queue-6` (a CJS-compatible older version). That version wraps
|
|
5
5
|
* the default export so that `import PQueue from 'p-queue'` resolves to
|
|
6
6
|
* `{ default: PQueue }` instead of the class directly. This module normalizes
|
|
@@ -4,6 +4,7 @@ import { graphV3Deserializer, projectV3Deserializer } from './serialization_v3.j
|
|
|
4
4
|
import { getError } from '../errors.js';
|
|
5
5
|
import { yamlProblem } from './serializationUtils.js';
|
|
6
6
|
import { prepareSerializedInput } from './serializationInput.js';
|
|
7
|
+
import { UiGraphNormalizationError } from '../../model/UiGraphNormalization.js';
|
|
7
8
|
import { datasetV4Deserializer, datasetV4Serializer, graphV4Deserializer, graphV4Serializer, projectV4Deserializer, projectV4Serializer, } from './serialization_v4.js';
|
|
8
9
|
import { graphV2Deserializer, projectV2Deserializer } from './serialization_v2.js';
|
|
9
10
|
import { graphV1Deserializer, projectV1Deserializer } from './serialization_v1.js';
|
|
@@ -26,6 +27,9 @@ export function deserializeProject(serializedProject, path = null) {
|
|
|
26
27
|
yamlProblem(err);
|
|
27
28
|
}
|
|
28
29
|
console.warn(`Failed to deserialize project v${version}: ${errMessage(err)}`);
|
|
30
|
+
if (err instanceof UiGraphNormalizationError) {
|
|
31
|
+
throw new Error(`Could not deserialize project: ${err.message}`, { cause: err });
|
|
32
|
+
}
|
|
29
33
|
throw new Error('Could not deserialize project');
|
|
30
34
|
}
|
|
31
35
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { formatUiGraphNormalizationIssue, normalizeUiGraphRecord, UiGraphNormalizationError, } from '../../model/UiGraphNormalization.js';
|
|
1
2
|
import { prepareSerializedInput } from './serializationInput.js';
|
|
2
3
|
/** Validates a deserialized project structure. Returns errors for structural problems. */
|
|
3
4
|
export function validateProject(project) {
|
|
@@ -63,8 +64,23 @@ export function validateProject(project) {
|
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
66
|
}
|
|
67
|
+
if (p.uiGraphs != null) {
|
|
68
|
+
validateUiGraphs(p.uiGraphs, errors);
|
|
69
|
+
}
|
|
66
70
|
return { valid: errors.length === 0, errors, warnings };
|
|
67
71
|
}
|
|
72
|
+
function validateUiGraphs(uiGraphs, errors) {
|
|
73
|
+
try {
|
|
74
|
+
normalizeUiGraphRecord(uiGraphs, { repairComponentIds: false });
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
if (error instanceof UiGraphNormalizationError) {
|
|
78
|
+
errors.push(...error.issues.map(formatUiGraphNormalizationIssue));
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
68
84
|
/** Quick structural check - throws on invalid project. */
|
|
69
85
|
export function doubleCheckProject(project) {
|
|
70
86
|
const result = validateProject(project);
|
|
@@ -2,6 +2,7 @@ import { mapValues } from 'lodash-es';
|
|
|
2
2
|
import { doubleCheckProject } from './serializationUtils.js';
|
|
3
3
|
import { entries } from '../typeSafety.js';
|
|
4
4
|
import {} from '../../model/Project.js';
|
|
5
|
+
import { normalizeUiGraphRecord } from '../../model/UiGraphNormalization.js';
|
|
5
6
|
import { serializeConnection, deserializeConnection, parseVisualData, packVisualDataV4, wrapInYamlEnvelope, unwrapYamlEnvelope, } from './serializationHelpers.js';
|
|
6
7
|
export function projectV4Deserializer(data) {
|
|
7
8
|
const serializedProject = unwrapYamlEnvelope(data, 4, 'Project v4');
|
|
@@ -31,11 +32,12 @@ function toSerializedProject(project, attachedData) {
|
|
|
31
32
|
id: prefab.id,
|
|
32
33
|
sourceNode: toSerializedIsolatedNode(prefab.sourceNode),
|
|
33
34
|
}));
|
|
35
|
+
const uiGraphs = normalizeUiGraphRecord(project.uiGraphs === undefined ? {} : project.uiGraphs);
|
|
34
36
|
return {
|
|
35
37
|
metadata: project.metadata,
|
|
36
38
|
graphs: mapValues(project.graphs, (graph) => toSerializedGraph(graph)),
|
|
37
39
|
nodePrefabs: Object.keys(nodePrefabs).length > 0 ? nodePrefabs : undefined,
|
|
38
|
-
uiGraphs:
|
|
40
|
+
uiGraphs: Object.keys(uiGraphs).length > 0 ? uiGraphs : undefined,
|
|
39
41
|
attachedData,
|
|
40
42
|
plugins: project.plugins ?? [],
|
|
41
43
|
references: project.references ?? [],
|
|
@@ -46,14 +48,13 @@ function fromSerializedProject(serializedProject) {
|
|
|
46
48
|
id: prefab.id,
|
|
47
49
|
sourceNode: fromSerializedIsolatedNode(prefab.sourceNode),
|
|
48
50
|
}));
|
|
51
|
+
const uiGraphs = normalizeUiGraphRecord(serializedProject.uiGraphs === undefined ? {} : serializedProject.uiGraphs);
|
|
49
52
|
return [
|
|
50
53
|
{
|
|
51
54
|
metadata: serializedProject.metadata,
|
|
52
55
|
graphs: mapValues(serializedProject.graphs, (graph) => fromSerializedGraph(graph)),
|
|
53
56
|
nodePrefabs: Object.keys(nodePrefabs).length > 0 ? nodePrefabs : undefined,
|
|
54
|
-
uiGraphs:
|
|
55
|
-
? serializedProject.uiGraphs
|
|
56
|
-
: undefined,
|
|
57
|
+
uiGraphs: Object.keys(uiGraphs).length > 0 ? uiGraphs : undefined,
|
|
57
58
|
plugins: serializedProject.plugins ?? [],
|
|
58
59
|
references: serializedProject.references ?? [],
|
|
59
60
|
},
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { createUiGraphChatSubmissionStatePatch, getUiGraphActionState, getUiGraphChatDraftStateKey, } from './model/UiGraph.js';
|
|
2
|
+
export { applyUiGraphStatePatch, createUiGraphActionExecutionController, createUiGraphInteractionController, getUiGraphComponentRenderModel, getUiGraphJsonOutputFilename, } from './model/UiGraphRuntimeModel.js';
|
|
3
|
+
export { parseRivetWebAppClientMessage, parseRivetWebAppServerMessage, RIVET_WEB_APP_ACTION_PROTOCOL_VERSION, } from './model/UiGraphActionProtocol.js';
|
|
4
|
+
export { copyUiGraphText, downloadUiGraphJsonOutput } from './model/UiGraphBrowserRuntime.js';
|
|
@@ -42,7 +42,7 @@ export type RunGraphOptions = {
|
|
|
42
42
|
editorExecutionCache?: ProcessContext['editorExecutionCache'];
|
|
43
43
|
} & {
|
|
44
44
|
[P in keyof ProcessEvents as `on${PascalCase<P>}`]?: (params: ProcessEvents[P]) => void;
|
|
45
|
-
} & Settings
|
|
45
|
+
} & Settings & Record<string, unknown>;
|
|
46
46
|
export type CoreCreateProcessorInternalOptions = {
|
|
47
47
|
cacheLoadedProjects?: boolean;
|
|
48
48
|
executionPlanCacheMode?: GraphProcessorExecutionPlanCacheMode;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Settings } from '../model/Settings.js';
|
|
2
|
-
|
|
3
|
-
export declare function resolveProcessSettings(settings?: Settings, fallbacks?: Partial<
|
|
4
|
-
export {};
|
|
1
|
+
import type { RuntimeSettings, Settings } from '../model/Settings.js';
|
|
2
|
+
export declare function resolveProcessSettings(settings?: Settings, fallbacks?: Partial<RuntimeSettings>): RuntimeSettings;
|
|
3
|
+
export declare function resolveProcessSettings<T extends Record<string, unknown>>(settings?: Settings & T, fallbacks?: Partial<RuntimeSettings>): RuntimeSettings & T;
|
|
@@ -10,6 +10,8 @@ export type RivetEventStreamFilterSpec = {
|
|
|
10
10
|
nodeStart?: string[] | true;
|
|
11
11
|
/** Stream node finish events for the specified nodeIDs or node titles. */
|
|
12
12
|
nodeFinish?: string[] | true;
|
|
13
|
+
/** Stream application-level progress reports emitted by graph nodes. */
|
|
14
|
+
progress?: boolean;
|
|
13
15
|
};
|
|
14
16
|
/** Map of all possible event names to their data for streaming events. */
|
|
15
17
|
export type RivetEventStreamEvent = {
|
|
@@ -30,6 +32,10 @@ export type RivetEventStreamEvent = {
|
|
|
30
32
|
outputs: Outputs;
|
|
31
33
|
durationMs?: number;
|
|
32
34
|
};
|
|
35
|
+
progress: {
|
|
36
|
+
message?: string;
|
|
37
|
+
percent?: number;
|
|
38
|
+
};
|
|
33
39
|
done: {
|
|
34
40
|
graphOutput: GraphOutputs;
|
|
35
41
|
};
|
package/dist/types/exports.d.ts
CHANGED
|
@@ -7,7 +7,14 @@ export * from './model/NodePrefabResolver.js';
|
|
|
7
7
|
export { getGraphBoundary } from './model/GraphBoundaryCache.js';
|
|
8
8
|
export type { GraphBoundary } from './model/GraphBoundaryCache.js';
|
|
9
9
|
export * from './model/UiGraph.js';
|
|
10
|
+
export * from './model/UiGraphNormalization.js';
|
|
11
|
+
export * from './model/UiGraphBindings.js';
|
|
12
|
+
export * from './model/UiGraphRuntimeModel.js';
|
|
13
|
+
export * from './model/UiGraphWebAppStatus.js';
|
|
14
|
+
export * from './model/UiGraphActionProtocol.js';
|
|
15
|
+
export * from './model/GraphProgress.js';
|
|
10
16
|
export * from './model/UiGraphRendererStyles.js';
|
|
17
|
+
export * from './model/MarkdownSanitizationPolicy.js';
|
|
11
18
|
export * from './model/NodeImpl.js';
|
|
12
19
|
export * from './model/NodeDefinition.js';
|
|
13
20
|
export * from './model/Nodes.js';
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { EditorDefinition } from '../../model/EditorDefinition.js';
|
|
2
|
+
import type { Inputs } from '../../model/GraphProcessor.js';
|
|
2
3
|
import type { ChartNode, NodeInputDefinition } from '../../model/NodeBase.js';
|
|
4
|
+
import type { InternalProcessContext } from '../../model/ProcessContext.js';
|
|
3
5
|
import type { RivetUIContext } from '../../model/RivetUIContext.js';
|
|
4
|
-
import type
|
|
6
|
+
import { type MCP, type MCPProvider } from './MCPProvider.js';
|
|
5
7
|
export interface MCPBaseNodeData {
|
|
6
8
|
name: string;
|
|
7
9
|
version: string;
|
|
@@ -13,6 +15,27 @@ export interface MCPBaseNodeData {
|
|
|
13
15
|
useServerUrlInput?: boolean;
|
|
14
16
|
useServerIdInput?: boolean;
|
|
15
17
|
}
|
|
16
|
-
export type
|
|
18
|
+
export type MCPResolvedServer = {
|
|
19
|
+
transportType: 'http';
|
|
20
|
+
clientConfig: {
|
|
21
|
+
name: string;
|
|
22
|
+
version: string;
|
|
23
|
+
};
|
|
24
|
+
serverUrl: string;
|
|
25
|
+
} | {
|
|
26
|
+
transportType: 'stdio';
|
|
27
|
+
clientConfig: {
|
|
28
|
+
name: string;
|
|
29
|
+
version: string;
|
|
30
|
+
};
|
|
31
|
+
serverConfig: MCP.ServerConfigWithId;
|
|
32
|
+
};
|
|
17
33
|
export declare const getMCPBaseInputs: (data: MCPBaseNodeData) => NodeInputDefinition[];
|
|
18
|
-
export declare
|
|
34
|
+
export declare function getMCPClientEditors<T extends ChartNode<string, MCPBaseNodeData>>(): EditorDefinition<T>[];
|
|
35
|
+
export declare function getMCPServerEditors<T extends ChartNode<string, MCPBaseNodeData>>(context: RivetUIContext, data: T['data'], options?: {
|
|
36
|
+
httpServerUrlHelperMessage?: string;
|
|
37
|
+
}): Promise<EditorDefinition<T>[]>;
|
|
38
|
+
export declare function getMCPBaseBody(data: MCPBaseNodeData, context: RivetUIContext): string;
|
|
39
|
+
export declare function requireMCPProvider(context: InternalProcessContext): MCPProvider;
|
|
40
|
+
export declare function resolveMCPServer(data: MCPBaseNodeData, inputs: Inputs, context: InternalProcessContext): Promise<MCPResolvedServer | undefined>;
|
|
41
|
+
export declare function interpolateMCPArgumentTemplate(template: string, inputs: Inputs): string;
|
|
@@ -6,6 +6,7 @@ import type { GraphExecutionMetadata, ProcessId } from './ProcessContext.js';
|
|
|
6
6
|
import type { Project, ProjectId } from './Project.js';
|
|
7
7
|
import type { Settings } from './Settings.js';
|
|
8
8
|
import type { FrozenNodeOutputsByGraph } from './GraphProcessor.js';
|
|
9
|
+
import type { GraphProgress } from './GraphProgress.js';
|
|
9
10
|
export type GraphInputs = Record<string, DataValue>;
|
|
10
11
|
export type GraphOutputs = Record<string, DataValue>;
|
|
11
12
|
export type Inputs = Record<PortId, DataValue | undefined>;
|
|
@@ -82,6 +83,11 @@ export type SerializedProcessEventMap = {
|
|
|
82
83
|
index: number;
|
|
83
84
|
processId: ProcessId;
|
|
84
85
|
}>;
|
|
86
|
+
progress: WithExecution<{
|
|
87
|
+
node: ChartNode;
|
|
88
|
+
processId: ProcessId;
|
|
89
|
+
progress: GraphProgress;
|
|
90
|
+
}>;
|
|
85
91
|
nodeOutputsCleared: WithExecution<{
|
|
86
92
|
node: ChartNode;
|
|
87
93
|
processId?: ProcessId;
|
|
@@ -127,6 +133,7 @@ export type ProcessEventMessageMap = {
|
|
|
127
133
|
graphStart: SerializedProcessEventMap['graphStart'];
|
|
128
134
|
graphFinish: SerializedProcessEventMap['graphFinish'];
|
|
129
135
|
partialOutput: SerializedProcessEventMap['partialOutput'];
|
|
136
|
+
progress: SerializedProcessEventMap['progress'];
|
|
130
137
|
nodeOutputsCleared: SerializedProcessEventMap['nodeOutputsCleared'];
|
|
131
138
|
error: SerializedProcessEventMap['error'];
|
|
132
139
|
graphError: SerializedProcessEventMap['graphError'];
|
|
@@ -9,6 +9,7 @@ import type { Tagged } from 'type-fest';
|
|
|
9
9
|
import type { NodeRegistration } from './NodeRegistration.js';
|
|
10
10
|
import { type GraphExecutionPlan } from './GraphPreprocessor.js';
|
|
11
11
|
import { type GraphBoundaryCache } from './GraphBoundaryCache.js';
|
|
12
|
+
import { type GraphProgress } from './GraphProgress.js';
|
|
12
13
|
type WithExecution<T extends object> = T & {
|
|
13
14
|
execution: GraphExecutionMetadata;
|
|
14
15
|
};
|
|
@@ -88,6 +89,12 @@ export type ProcessEvents = {
|
|
|
88
89
|
index: number;
|
|
89
90
|
processId: ProcessId;
|
|
90
91
|
}>;
|
|
92
|
+
/** Called when a node reports host-facing progress. */
|
|
93
|
+
progress: WithExecution<{
|
|
94
|
+
node: ChartNode;
|
|
95
|
+
processId: ProcessId;
|
|
96
|
+
progress: GraphProgress;
|
|
97
|
+
}>;
|
|
91
98
|
/** Called when the outputs of a node have been cleared entirely. If processId is present, only the one process() should be cleared. */
|
|
92
99
|
nodeOutputsCleared: WithExecution<{
|
|
93
100
|
node: ChartNode;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type GraphProgress = Readonly<{
|
|
2
|
+
message?: string;
|
|
3
|
+
percent?: number;
|
|
4
|
+
}>;
|
|
5
|
+
/** Normalizes public graph progress before it crosses executor or web-app transports. */
|
|
6
|
+
export declare function normalizeGraphProgress(progress: GraphProgress): GraphProgress | undefined;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type GraphRunLifecyclePhase = 'idle' | 'running' | 'aborting' | 'finished';
|
|
2
|
+
export type GraphRunAbortDecision = {
|
|
3
|
+
successful: boolean;
|
|
4
|
+
error?: Error | string | undefined;
|
|
5
|
+
};
|
|
6
|
+
/** Owns run-level state only. Scheduling and event emission remain in GraphProcessor. */
|
|
7
|
+
export declare class GraphRunLifecycle {
|
|
8
|
+
#private;
|
|
9
|
+
get phase(): GraphRunLifecyclePhase;
|
|
10
|
+
get isRunning(): boolean;
|
|
11
|
+
get isPaused(): boolean;
|
|
12
|
+
get isAborted(): boolean;
|
|
13
|
+
get abortSuccessful(): boolean;
|
|
14
|
+
get abortError(): Error | string | undefined;
|
|
15
|
+
begin(): void;
|
|
16
|
+
complete(): void;
|
|
17
|
+
requestAbort(successful: boolean, error?: Error | string): GraphRunAbortDecision | undefined;
|
|
18
|
+
pause(): boolean;
|
|
19
|
+
resume(): boolean;
|
|
20
|
+
claimRootFinish(isSubProcessor: boolean): boolean;
|
|
21
|
+
getAbortError(): Error;
|
|
22
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const RIVET_MARKDOWN_ALLOWED_TAGS: readonly ["a", "blockquote", "br", "code", "del", "em", "h1", "h2", "h3", "h4", "h5", "h6", "hr", "li", "ol", "p", "pre", "strong", "sub", "sup", "table", "tbody", "td", "th", "thead", "tr", "ul"];
|
|
2
|
+
export declare const RIVET_MARKDOWN_ALLOWED_ATTRIBUTES: readonly ["class", "href", "title"];
|
|
3
|
+
export declare const RIVET_MARKDOWN_ALLOWED_URI_REGEXP_SOURCE = "^(?:https?:|mailto:|#|\\?(?:[^/]|$)|/(?!/)|\\.{1,2}/|[a-z0-9._~-]+(?:[/?#]|$))";
|
|
4
|
+
export type RivetMarkdownSanitizerPolicy = {
|
|
5
|
+
allowedAttributes: readonly string[];
|
|
6
|
+
allowedTags: readonly string[];
|
|
7
|
+
allowedUriRegExpSource: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const RIVET_MARKDOWN_SANITIZER_POLICY: RivetMarkdownSanitizerPolicy;
|