@valerypopoff/rivet2-core 2.15.0 → 2.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/bundle.cjs +7906 -3980
- package/dist/cjs/bundle.cjs.map +4 -4
- package/dist/cjs/interpolationRuntime.cjs +62 -7
- package/dist/cjs/interpolationRuntime.cjs.map +3 -3
- package/dist/cjs/interpolationSyntax.cjs +9 -5
- package/dist/cjs/interpolationSyntax.cjs.map +2 -2
- package/dist/cjs/serialization.cjs +1880 -0
- package/dist/cjs/serialization.cjs.map +7 -0
- package/dist/cjs/webAppRuntime.cjs +168 -6
- package/dist/cjs/webAppRuntime.cjs.map +3 -3
- package/dist/esm/api/createProcessor.js +5 -2
- package/dist/esm/api/processSettings.js +1 -0
- package/dist/esm/exports.js +4 -0
- package/dist/esm/model/AgentResponseTrace.js +99 -34
- package/dist/esm/model/AgentResponseTracePresentation.js +130 -0
- package/dist/esm/model/DataValue.js +11 -2
- package/dist/esm/model/GlobalVariables.js +2 -1
- package/dist/esm/model/GraphBoundaryCache.js +2 -1
- package/dist/esm/model/GraphBoundaryEffects.js +38 -1
- package/dist/esm/model/GraphExecutionState.js +81 -0
- package/dist/esm/model/GraphProcessor.js +825 -884
- package/dist/esm/model/GraphSchedulerBoundaryState.js +64 -0
- package/dist/esm/model/Nodes.js +15 -0
- package/dist/esm/model/ProjectBundle.js +248 -0
- package/dist/esm/model/ProjectBundleRuntime.js +54 -0
- package/dist/esm/model/SchedulerBoundaryPlanner.js +233 -0
- package/dist/esm/model/SplitRunProcessor.js +28 -7
- package/dist/esm/model/StreamingWatchTopology.js +118 -8
- package/dist/esm/model/SubgraphProjectTarget.js +7 -0
- package/dist/esm/model/SubprocessorBridge.js +125 -87
- package/dist/esm/model/ToolCallContinuationCoordinator.js +1 -1
- package/dist/esm/model/chat-v2/aiSdkBridge.js +22 -17
- package/dist/esm/model/chat-v2/chatV2CallObserver.js +2 -4
- package/dist/esm/model/chat-v2/chatV2CredentialNames.js +5 -1
- package/dist/esm/model/chat-v2/chatV2Outputs.js +2 -2
- package/dist/esm/model/chat-v2/chatV2Pipeline.js +24 -9
- package/dist/esm/model/chat-v2/chatV2ProviderProfile.js +3 -2
- package/dist/esm/model/chat-v2/chatV2ProviderRegistry.js +46 -6
- package/dist/esm/model/chat-v2/chatV2RuntimeOptions.js +26 -1
- package/dist/esm/model/chat-v2/chatV2Shared.js +2 -1
- package/dist/esm/model/chat-v2/chatV2UsageAccounting.js +10 -0
- package/dist/esm/model/chat-v2/llmChatV2Body.js +13 -10
- package/dist/esm/model/chat-v2/llmChatV2CacheBoundary.js +5 -2
- package/dist/esm/model/chat-v2/llmChatV2NodeData.js +3 -0
- package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +33 -9
- package/dist/esm/model/chat-v2/llmChatV2NodeMigration.js +22 -2
- package/dist/esm/model/chat-v2/llmInvocationCoordinator.js +10 -2
- package/dist/esm/model/chat-v2/llmInvocationResultProjector.js +17 -0
- package/dist/esm/model/chat-v2/llmModelCandidate.js +2 -1
- package/dist/esm/model/chat-v2/llmProfile.js +5 -1
- package/dist/esm/model/chat-v2/llmProfileBody.js +11 -2
- package/dist/esm/model/chat-v2/llmProfileFallback.js +7 -4
- package/dist/esm/model/chat-v2/llmProfileFieldRegistry.js +2 -1
- package/dist/esm/model/chat-v2/llmProfileHealthStore.js +16 -3
- package/dist/esm/model/chat-v2/llmProfileNodeRuntime.js +1 -1
- package/dist/esm/model/chat-v2/messageConverter.js +18 -16
- package/dist/esm/model/chat-v2/modelRegistry.js +14 -4
- package/dist/esm/model/chat-v2/openRouterModel.js +73 -0
- package/dist/esm/model/chat-v2/parallelToolCalls.js +2 -0
- package/dist/esm/model/chat-v2/providerOptions.js +30 -25
- package/dist/esm/model/chat-v2/temperature.js +9 -0
- package/dist/esm/model/classifier/credentials.js +42 -6
- package/dist/esm/model/classifier/images.js +176 -0
- package/dist/esm/model/classifier/json.js +57 -0
- package/dist/esm/model/classifier/limits.js +300 -0
- package/dist/esm/model/classifier/openai.js +118 -0
- package/dist/esm/model/classifier/perplexity.js +63 -0
- package/dist/esm/model/classifier/preparation.js +74 -0
- package/dist/esm/model/classifier/profile.js +151 -0
- package/dist/esm/model/classifier/profileExecution.js +294 -0
- package/dist/esm/model/classifier/providers.js +454 -192
- package/dist/esm/model/classifier/questionHelpers.js +29 -45
- package/dist/esm/model/classifier/questions.js +53 -0
- package/dist/esm/model/classifier/response.js +75 -0
- package/dist/esm/model/classifier/state.js +207 -0
- package/dist/esm/model/classifier/types.js +11 -1
- package/dist/esm/model/nodeRunFailure.js +54 -0
- package/dist/esm/model/nodes/CallGraphNode.js +6 -0
- package/dist/esm/model/nodes/CatchStreamingChunksNode.js +42 -0
- package/dist/esm/model/nodes/ClassifierEvaluateNode.js +385 -154
- package/dist/esm/model/nodes/ClassifierProfileNode.js +133 -0
- package/dist/esm/model/nodes/ClassifierQuestionNode.js +59 -15
- package/dist/esm/model/nodes/DelegateFunctionCallNode.js +1 -1
- package/dist/esm/model/nodes/GetGlobalNode.js +2 -2
- package/dist/esm/model/nodes/HttpCallNode.js +44 -75
- package/dist/esm/model/nodes/ImageNode.js +44 -3
- package/dist/esm/model/nodes/LLMChatV2Node.js +26 -4
- package/dist/esm/model/nodes/ObjectNode.js +29 -18
- package/dist/esm/model/nodes/PromptNode.js +2 -1
- package/dist/esm/model/nodes/ReferencedGraphAliasNode.js +4 -1
- package/dist/esm/model/nodes/SetGlobalNode.js +5 -3
- package/dist/esm/model/nodes/StopWatchingStreamingOutputNode.js +8 -8
- package/dist/esm/model/nodes/StreamValueNode.js +38 -0
- package/dist/esm/model/nodes/SubGraphNode.js +199 -35
- package/dist/esm/model/nodes/ToBase64Node.js +106 -0
- package/dist/esm/model/nodes/WatchStreamingOutputNode.js +7 -7
- package/dist/esm/model/nodes/toolCallDelegation.js +5 -1
- package/dist/esm/model/profileSuspensionHints.js +8 -0
- package/dist/esm/recording/ExecutionRecorder.js +26 -0
- package/dist/esm/serialization.js +2 -0
- package/dist/esm/utils/base64.js +18 -15
- package/dist/esm/utils/coerceType.js +11 -1
- package/dist/esm/utils/errors.js +41 -0
- package/dist/esm/utils/interpolation.js +44 -22
- package/dist/esm/utils/interpolationSyntax.js +15 -6
- package/dist/esm/utils/serialization/serialization.js +3 -2
- package/dist/esm/utils/serialization/serializationUtils.js +6 -0
- package/dist/esm/utils/serialization/serialization_v4.js +15 -3
- package/dist/esm/webAppRuntime.js +1 -0
- package/dist/types/api/createProcessor.d.ts +7 -1
- package/dist/types/exports.d.ts +4 -0
- package/dist/types/model/AgentResponseTrace.d.ts +15 -4
- package/dist/types/model/AgentResponseTracePresentation.d.ts +15 -0
- package/dist/types/model/CycleDetector.d.ts +1 -2
- package/dist/types/model/DataValue.d.ts +12 -8
- package/dist/types/model/ExecutorProtocol.d.ts +9 -0
- package/dist/types/model/GraphBoundaryCache.d.ts +2 -0
- package/dist/types/model/GraphBoundaryEffects.d.ts +10 -1
- package/dist/types/model/GraphExecutionState.d.ts +68 -0
- package/dist/types/model/GraphProcessor.d.ts +2 -0
- package/dist/types/model/GraphSchedulerBoundaryState.d.ts +96 -0
- package/dist/types/model/Nodes.d.ts +11 -4
- package/dist/types/model/ProcessContext.d.ts +24 -3
- package/dist/types/model/ProjectBundle.d.ts +59 -0
- package/dist/types/model/ProjectBundleRuntime.d.ts +24 -0
- package/dist/types/model/ProjectReferenceLoader.d.ts +3 -0
- package/dist/types/model/RivetUIContext.d.ts +1 -1
- package/dist/types/model/SchedulerBoundaryPlanner.d.ts +42 -0
- package/dist/types/model/Settings.d.ts +1 -0
- package/dist/types/model/StreamingWatchTopology.d.ts +11 -1
- package/dist/types/model/SubgraphProjectTarget.d.ts +38 -0
- package/dist/types/model/SubprocessorBridge.d.ts +2 -0
- package/dist/types/model/chat-v2/chatV2CredentialNames.d.ts +4 -0
- package/dist/types/model/chat-v2/chatV2Outputs.d.ts +1 -1
- package/dist/types/model/chat-v2/chatV2ProviderRegistry.d.ts +79 -1
- package/dist/types/model/chat-v2/chatV2ProviderTypes.d.ts +1 -1
- package/dist/types/model/chat-v2/chatV2Shared.d.ts +1 -1
- package/dist/types/model/chat-v2/chatV2UsageAccounting.d.ts +2 -0
- package/dist/types/model/chat-v2/llmChatV2NodeData.d.ts +4 -1
- package/dist/types/model/chat-v2/llmChatV2NodeMigration.d.ts +3 -1
- package/dist/types/model/chat-v2/llmInvocationCoordinator.d.ts +2 -0
- package/dist/types/model/chat-v2/llmInvocationResultProjector.d.ts +2 -0
- package/dist/types/model/chat-v2/llmProfileFallback.d.ts +51 -3
- package/dist/types/model/chat-v2/llmProfileFieldRegistry.d.ts +10 -7
- package/dist/types/model/chat-v2/llmProfileHealthStore.d.ts +6 -2
- package/dist/types/model/chat-v2/modelRegistry.d.ts +5 -4
- package/dist/types/model/chat-v2/openRouterModel.d.ts +2 -0
- package/dist/types/model/chat-v2/providerOptions.d.ts +2 -13
- package/dist/types/model/chat-v2/temperature.d.ts +2 -0
- package/dist/types/model/classifier/credentials.d.ts +7 -1
- package/dist/types/model/classifier/images.d.ts +18 -0
- package/dist/types/model/classifier/json.d.ts +19 -0
- package/dist/types/model/classifier/limits.d.ts +45 -0
- package/dist/types/model/classifier/openai.d.ts +5 -0
- package/dist/types/model/classifier/perplexity.d.ts +7 -0
- package/dist/types/model/classifier/preparation.d.ts +16 -0
- package/dist/types/model/classifier/profile.d.ts +46 -0
- package/dist/types/model/classifier/profileExecution.d.ts +32 -0
- package/dist/types/model/classifier/providers.d.ts +98 -9
- package/dist/types/model/classifier/questionHelpers.d.ts +6 -4
- package/dist/types/model/classifier/questions.d.ts +4 -0
- package/dist/types/model/classifier/response.d.ts +4 -0
- package/dist/types/model/classifier/state.d.ts +37 -0
- package/dist/types/model/classifier/types.d.ts +11 -0
- package/dist/types/model/nodeRunFailure.d.ts +13 -0
- package/dist/types/model/nodes/CatchStreamingChunksNode.d.ts +20 -0
- package/dist/types/model/nodes/ClassifierEvaluateNode.d.ts +17 -12
- package/dist/types/model/nodes/ClassifierProfileNode.d.ts +20 -0
- package/dist/types/model/nodes/GetGlobalNode.d.ts +7 -0
- package/dist/types/model/nodes/ImageNode.d.ts +4 -0
- package/dist/types/model/nodes/LLMChatV2Node.d.ts +1 -0
- package/dist/types/model/nodes/ObjectNode.d.ts +2 -1
- package/dist/types/model/nodes/StreamValueNode.d.ts +14 -0
- package/dist/types/model/nodes/SubGraphNode.d.ts +21 -2
- package/dist/types/model/nodes/ToBase64Node.d.ts +12 -0
- package/dist/types/model/nodes/toolCallDelegation.d.ts +3 -1
- package/dist/types/model/profileSuspensionHints.d.ts +8 -0
- package/dist/types/recording/ExecutionRecorder.d.ts +8 -2
- package/dist/types/serialization.d.ts +2 -0
- package/dist/types/utils/base64.d.ts +1 -1
- package/dist/types/utils/errors.d.ts +4 -0
- package/dist/types/utils/interpolation.d.ts +13 -2
- package/dist/types/utils/interpolationSyntax.d.ts +1 -1
- package/dist/types/utils/serialization/serialization.d.ts +3 -1
- package/dist/types/utils/serialization/serializationUtils.d.ts +1 -0
- package/dist/types/webAppRuntime.d.ts +1 -0
- package/package.json +7 -1
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { nanoid } from 'nanoid/non-secure';
|
|
2
|
+
import { NodeImpl } from '../NodeImpl.js';
|
|
3
|
+
import { nodeDefinition } from '../NodeDefinition.js';
|
|
4
|
+
import { uint8ArrayToBase64 } from '../../utils/base64.js';
|
|
5
|
+
async function getBytesToEncode(input) {
|
|
6
|
+
if (!input) {
|
|
7
|
+
throw new Error('No data to encode as base64');
|
|
8
|
+
}
|
|
9
|
+
if (input.type.startsWith('fn<') || input.type === 'control-flow-excluded') {
|
|
10
|
+
throw new Error(`Cannot encode ${input.type} as base64`);
|
|
11
|
+
}
|
|
12
|
+
const value = input.value;
|
|
13
|
+
if (input.type === 'binary') {
|
|
14
|
+
if (!(value instanceof Uint8Array))
|
|
15
|
+
throw new Error('Binary input must contain bytes');
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
if (input.type === 'image' || input.type === 'audio' || input.type === 'document') {
|
|
19
|
+
const bytes = value && typeof value === 'object' && 'data' in value ? value.data : undefined;
|
|
20
|
+
if (!(bytes instanceof Uint8Array))
|
|
21
|
+
throw new Error(`${input.type} input must contain bytes`);
|
|
22
|
+
return bytes;
|
|
23
|
+
}
|
|
24
|
+
if (value instanceof Uint8Array) {
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
if (value instanceof ArrayBuffer) {
|
|
28
|
+
return new Uint8Array(value);
|
|
29
|
+
}
|
|
30
|
+
if (ArrayBuffer.isView(value)) {
|
|
31
|
+
return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
32
|
+
}
|
|
33
|
+
if (typeof Blob !== 'undefined' && value instanceof Blob) {
|
|
34
|
+
return new Uint8Array(await value.arrayBuffer());
|
|
35
|
+
}
|
|
36
|
+
if (typeof value === 'string') {
|
|
37
|
+
return new TextEncoder().encode(value);
|
|
38
|
+
}
|
|
39
|
+
let json;
|
|
40
|
+
try {
|
|
41
|
+
json = JSON.stringify(value, (_key, item) => {
|
|
42
|
+
if (typeof item === 'number' && !Number.isFinite(item)) {
|
|
43
|
+
throw new Error('Non-finite numbers cannot be encoded as JSON');
|
|
44
|
+
}
|
|
45
|
+
if (item && typeof item === 'object' && !Array.isArray(item)) {
|
|
46
|
+
const prototype = Object.getPrototypeOf(item);
|
|
47
|
+
if (prototype !== null && Object.getPrototypeOf(prototype) !== null) {
|
|
48
|
+
throw new Error('Non-JSON objects must be converted before base64 encoding');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return item;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
const detail = error instanceof Error ? `: ${error.message}` : '';
|
|
56
|
+
throw new Error(`Cannot serialize input as JSON for base64 encoding${detail}`, { cause: error });
|
|
57
|
+
}
|
|
58
|
+
if (json === undefined) {
|
|
59
|
+
throw new Error(`Cannot encode ${input.type} as base64`);
|
|
60
|
+
}
|
|
61
|
+
return new TextEncoder().encode(json);
|
|
62
|
+
}
|
|
63
|
+
export class ToBase64NodeImpl extends NodeImpl {
|
|
64
|
+
static create() {
|
|
65
|
+
return {
|
|
66
|
+
id: nanoid(),
|
|
67
|
+
type: 'toBase64',
|
|
68
|
+
title: 'To Base64',
|
|
69
|
+
visualData: { x: 0, y: 0, width: 175 },
|
|
70
|
+
data: {},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
getInputDefinitions() {
|
|
74
|
+
return [
|
|
75
|
+
{
|
|
76
|
+
id: 'data',
|
|
77
|
+
title: 'Data',
|
|
78
|
+
dataType: 'any',
|
|
79
|
+
required: true,
|
|
80
|
+
coerced: false,
|
|
81
|
+
splitRunBehavior: 'preserve-array',
|
|
82
|
+
},
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
getOutputDefinitions() {
|
|
86
|
+
return [{ id: 'base64', title: 'Base64', dataType: 'string' }];
|
|
87
|
+
}
|
|
88
|
+
static getUIData() {
|
|
89
|
+
return {
|
|
90
|
+
contextMenuTitle: 'To Base64',
|
|
91
|
+
group: ['Text', 'Data'],
|
|
92
|
+
infoBoxTitle: 'To Base64 Node',
|
|
93
|
+
infoBoxBody: 'Encodes bytes directly, text as UTF-8, and other JSON-serializable values as UTF-8 JSON. Outputs raw base64.',
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
async process(inputs) {
|
|
97
|
+
const bytes = await getBytesToEncode(inputs['data']);
|
|
98
|
+
return {
|
|
99
|
+
['base64']: {
|
|
100
|
+
type: 'string',
|
|
101
|
+
value: await uint8ArrayToBase64(bytes),
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
export const toBase64Node = nodeDefinition(ToBase64NodeImpl, 'To Base64');
|
|
@@ -15,7 +15,7 @@ export class WatchStreamingOutputNodeImpl extends NodeImpl {
|
|
|
15
15
|
queueOverflowBehavior: streamingOutputWatchDefaults.queueOverflowBehavior,
|
|
16
16
|
},
|
|
17
17
|
id: nanoid(),
|
|
18
|
-
title: 'Watch
|
|
18
|
+
title: 'Watch streaming',
|
|
19
19
|
type: 'watchStreamingOutput',
|
|
20
20
|
visualData: { x: 0, y: 0, width: 230 },
|
|
21
21
|
};
|
|
@@ -38,12 +38,12 @@ export class WatchStreamingOutputNodeImpl extends NodeImpl {
|
|
|
38
38
|
}
|
|
39
39
|
static getUIData() {
|
|
40
40
|
return {
|
|
41
|
-
contextMenuTitle: 'Watch
|
|
42
|
-
group: ['
|
|
43
|
-
infoBoxTitle: 'Watch
|
|
41
|
+
contextMenuTitle: 'Watch streaming',
|
|
42
|
+
group: ['Streaming'],
|
|
43
|
+
infoBoxTitle: 'Watch streaming node',
|
|
44
44
|
infoBoxBody: dedent `
|
|
45
|
-
Runs its downstream branch for streaming output snapshots. Without Stop
|
|
46
|
-
|
|
45
|
+
Runs its downstream branch for streaming output snapshots. Without Stop watching
|
|
46
|
+
streaming, every snapshot runs the branch and the watch finishes with its
|
|
47
47
|
producer. Add one Stop node only when a chosen value must continue through the
|
|
48
48
|
ordinary graph. Non-watched connections still wait for their upstream node's final result.
|
|
49
49
|
`,
|
|
@@ -123,4 +123,4 @@ export class WatchStreamingOutputNodeImpl extends NodeImpl {
|
|
|
123
123
|
};
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
|
-
export const watchStreamingOutputNode = nodeDefinition(WatchStreamingOutputNodeImpl, 'Watch
|
|
126
|
+
export const watchStreamingOutputNode = nodeDefinition(WatchStreamingOutputNodeImpl, 'Watch streaming');
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { omit } from 'lodash-es';
|
|
2
|
+
import { readGraphCostBreakdown } from '../GraphBoundaryEffects.js';
|
|
2
3
|
import { coerceTypeOptional } from '../../utils/coerceType.js';
|
|
3
4
|
import { getError } from '../../utils/errors.js';
|
|
4
5
|
import { createDelegatedToolCallRecord, createToolResultMessage, normalizeToolCall, stringifyToolResult, } from '../chat-v2/toolCallCodec.js';
|
|
@@ -36,7 +37,7 @@ export function isDelegatedToolCallRecord(input) {
|
|
|
36
37
|
typeof maybeMessage.name === 'string' &&
|
|
37
38
|
(maybeMessage.toolName == null || typeof maybeMessage.toolName === 'string'));
|
|
38
39
|
}
|
|
39
|
-
export function buildDelegatedToolCallOutputs(records, preToolMessage, cost) {
|
|
40
|
+
export function buildDelegatedToolCallOutputs(records, preToolMessage, cost, costBreakdown) {
|
|
40
41
|
const preToolMessageOutput = preToolMessage == null
|
|
41
42
|
? {
|
|
42
43
|
type: 'control-flow-excluded',
|
|
@@ -107,6 +108,8 @@ export function buildDelegatedToolCallOutputs(records, preToolMessage, cost) {
|
|
|
107
108
|
};
|
|
108
109
|
if (cost != null) {
|
|
109
110
|
outputs['cost'] = { type: 'number', value: cost };
|
|
111
|
+
if (costBreakdown)
|
|
112
|
+
outputs['costBreakdown'] = { type: 'object', value: { ...costBreakdown } };
|
|
110
113
|
}
|
|
111
114
|
return outputs;
|
|
112
115
|
}
|
|
@@ -275,6 +278,7 @@ async function delegateResolvedToolCall(functionCall, context, config, trace) {
|
|
|
275
278
|
message: createToolResultMessage(functionCall, outputString),
|
|
276
279
|
record: createDelegatedToolCallRecord(functionCall, outputString, executionTimeMs),
|
|
277
280
|
cost,
|
|
281
|
+
costBreakdown: readGraphCostBreakdown(outputs),
|
|
278
282
|
};
|
|
279
283
|
}
|
|
280
284
|
function notifyToolCallFinished(context, event) {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Shared inspector wording for LLM and Classifier profile suspension. */
|
|
2
|
+
export const profileSuspensionHints = {
|
|
3
|
+
host: 'Requires Studio Server or a host with shared profile health. Not available in standalone Rivet.',
|
|
4
|
+
enable: 'Suspend this profile after provider failures or timeouts. After suspension, allow one recovery attempt.',
|
|
5
|
+
threshold: 'Failures or timeouts within the failure window needed to suspend this profile.',
|
|
6
|
+
window: 'Rolling period for counting failures and timeouts.',
|
|
7
|
+
duration: 'Time to suspend this profile before one recovery attempt.',
|
|
8
|
+
};
|
|
@@ -295,6 +295,9 @@ export class ExecutionRecorder {
|
|
|
295
295
|
if (this.#includeTrace === false && message === 'trace') {
|
|
296
296
|
return;
|
|
297
297
|
}
|
|
298
|
+
if (getEventProjectScope(data) !== undefined) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
298
301
|
this.#events.push(toRecordedEvent(message, data));
|
|
299
302
|
if (isSocketRecordingTerminalEvent(message)) {
|
|
300
303
|
finish(true);
|
|
@@ -314,6 +317,7 @@ export class ExecutionRecorder {
|
|
|
314
317
|
}
|
|
315
318
|
record(processor) {
|
|
316
319
|
this.recordingId = nanoid();
|
|
320
|
+
const recordingProjectScope = processor.recordingProjectScope;
|
|
317
321
|
let settled = false;
|
|
318
322
|
const finish = () => {
|
|
319
323
|
if (settled)
|
|
@@ -335,9 +339,25 @@ export class ExecutionRecorder {
|
|
|
335
339
|
if (this.#includeTrace === false && event === 'trace') {
|
|
336
340
|
return;
|
|
337
341
|
}
|
|
342
|
+
const eventScope = getEventProjectScope(data);
|
|
343
|
+
if (eventScope !== undefined && eventScope !== recordingProjectScope) {
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
338
346
|
this.#events.push(toRecordedEvent(event, data));
|
|
339
347
|
});
|
|
340
348
|
const unsubscribeFinish = processor.on('finish', finish);
|
|
349
|
+
// Child processors have graph terminals but no root-level done/finish.
|
|
350
|
+
// Their owner calls this after processGraph settles to make a standalone,
|
|
351
|
+
// replayable recording without changing the live event stream.
|
|
352
|
+
return (terminal) => {
|
|
353
|
+
if (settled)
|
|
354
|
+
return;
|
|
355
|
+
if (terminal?.type === 'done')
|
|
356
|
+
this.#events.push(toRecordedEvent('done', { results: terminal.results }));
|
|
357
|
+
if (terminal?.type === 'error')
|
|
358
|
+
this.#events.push(toRecordedEvent('error', { error: terminal.error }));
|
|
359
|
+
finish();
|
|
360
|
+
};
|
|
341
361
|
}
|
|
342
362
|
getRecording() {
|
|
343
363
|
return {
|
|
@@ -382,3 +402,9 @@ export class ExecutionRecorder {
|
|
|
382
402
|
function isSocketRecordingTerminalEvent(event) {
|
|
383
403
|
return event === 'done' || event === 'error';
|
|
384
404
|
}
|
|
405
|
+
function getEventProjectScope(data) {
|
|
406
|
+
if (!data || typeof data !== 'object' || !('execution' in data))
|
|
407
|
+
return undefined;
|
|
408
|
+
const execution = data.execution;
|
|
409
|
+
return execution?.projectScope;
|
|
410
|
+
}
|
package/dist/esm/utils/base64.js
CHANGED
|
@@ -1,31 +1,34 @@
|
|
|
1
|
+
function encodeWithBtoa(bytes) {
|
|
2
|
+
const chunks = [];
|
|
3
|
+
// Every non-final chunk must contain a multiple of three bytes so its padding
|
|
4
|
+
// cannot interrupt the combined base64 stream.
|
|
5
|
+
for (let offset = 0; offset < bytes.length; offset += 0x6000) {
|
|
6
|
+
chunks.push(btoa(String.fromCharCode(...bytes.subarray(offset, offset + 0x6000))));
|
|
7
|
+
}
|
|
8
|
+
return chunks.join('');
|
|
9
|
+
}
|
|
1
10
|
export async function uint8ArrayToBase64(uint8Array) {
|
|
2
|
-
if (typeof
|
|
3
|
-
// Node executor
|
|
11
|
+
if (typeof Buffer !== 'undefined') {
|
|
4
12
|
return Buffer.from(uint8Array).toString('base64');
|
|
5
13
|
}
|
|
6
|
-
|
|
7
|
-
// Browser executor
|
|
14
|
+
if (typeof FileReader !== 'undefined') {
|
|
8
15
|
const blob = new Blob([uint8Array], { type: 'application/octet-stream' });
|
|
9
|
-
const dataUrl = await new Promise((resolve) => {
|
|
16
|
+
const dataUrl = await new Promise((resolve, reject) => {
|
|
10
17
|
const reader = new FileReader();
|
|
11
18
|
reader.onload = () => resolve(reader.result);
|
|
19
|
+
reader.onerror = () => reject(reader.error ?? new Error('Failed to encode bytes as base64'));
|
|
12
20
|
reader.readAsDataURL(blob);
|
|
13
21
|
});
|
|
14
|
-
return dataUrl.
|
|
22
|
+
return dataUrl.slice(dataUrl.indexOf(',') + 1);
|
|
15
23
|
}
|
|
24
|
+
// Browser workers have btoa but neither window nor FileReader.
|
|
25
|
+
return encodeWithBtoa(uint8Array);
|
|
16
26
|
}
|
|
17
27
|
export function uint8ArrayToBase64Sync(uint8Array) {
|
|
18
|
-
if (typeof
|
|
19
|
-
// Node executor
|
|
28
|
+
if (typeof Buffer !== 'undefined') {
|
|
20
29
|
return Buffer.from(uint8Array).toString('base64');
|
|
21
30
|
}
|
|
22
|
-
|
|
23
|
-
// Browser executor
|
|
24
|
-
const binary = Array.from(uint8Array)
|
|
25
|
-
.map((byte) => String.fromCharCode(byte))
|
|
26
|
-
.join('');
|
|
27
|
-
return btoa(binary);
|
|
28
|
-
}
|
|
31
|
+
return encodeWithBtoa(uint8Array);
|
|
29
32
|
}
|
|
30
33
|
export function base64ToUint8Array(base64) {
|
|
31
34
|
const binaryString = atob(base64);
|
|
@@ -6,7 +6,8 @@ function isValidatedObjectValueType(type) {
|
|
|
6
6
|
return (type === 'knowledge-source' ||
|
|
7
7
|
type === 'knowledge-document' ||
|
|
8
8
|
type === 'knowledge-evidence' ||
|
|
9
|
-
type === 'llm-config'
|
|
9
|
+
type === 'llm-config' ||
|
|
10
|
+
type === 'classifier-config');
|
|
10
11
|
}
|
|
11
12
|
function canAttemptGeneralCoercion(from, to) {
|
|
12
13
|
return !isValidatedObjectValueType(from) || to === 'object' || to === 'string';
|
|
@@ -53,6 +54,8 @@ const scalarCoercionRules = {
|
|
|
53
54
|
'knowledge-document': sameTypeOrObjectScalarRule('knowledge-document', (value) => coerceValidatedObjectValue(value, normalizeKnowledgeDocument)),
|
|
54
55
|
'knowledge-evidence': sameTypeOrObjectScalarRule('knowledge-evidence', (value) => coerceValidatedObjectValue(value, normalizeKnowledgeEvidence)),
|
|
55
56
|
'llm-config': sameTypeOrObjectScalarRule('llm-config', (value) => coerceValidatedObjectValue(value, normalizeLLMProfileValue)),
|
|
57
|
+
// Provider-specific validation belongs to Evaluate's bounded snapshot boundary.
|
|
58
|
+
'classifier-config': sameTypeOrObjectScalarRule('classifier-config', (value) => value?.value != null && typeof value.value === 'object' && !Array.isArray(value.value) ? value.value : undefined),
|
|
56
59
|
document: generalScalarRule('document'),
|
|
57
60
|
};
|
|
58
61
|
export function coerceTypeOptional(wrapped, type) {
|
|
@@ -60,6 +63,13 @@ export function coerceTypeOptional(wrapped, type) {
|
|
|
60
63
|
return expectTypeOptional(wrapped, type);
|
|
61
64
|
}
|
|
62
65
|
const value = wrapped ? unwrapDataValue(wrapped) : undefined;
|
|
66
|
+
// These profiles share a versioned object envelope but configure different
|
|
67
|
+
// APIs. Do not reinterpret a typed chat profile as a classifier (or vice versa),
|
|
68
|
+
// including after unwrapping a deferred value. Object/any imports remain valid.
|
|
69
|
+
if ((type === 'classifier-config' && value?.type === 'llm-config') ||
|
|
70
|
+
(type === 'llm-config' && value?.type === 'classifier-config')) {
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
63
73
|
// Coerce 'true' to [true] for example
|
|
64
74
|
if (isArrayDataType(type) && !isArrayDataValue(value)) {
|
|
65
75
|
const coerced = coerceTypeOptional(value, getScalarTypeOf(type));
|
package/dist/esm/utils/errors.js
CHANGED
|
@@ -5,3 +5,44 @@ export function getError(error) {
|
|
|
5
5
|
: new Error(error != null ? error.toString() : 'Unknown error');
|
|
6
6
|
return errorInstance;
|
|
7
7
|
}
|
|
8
|
+
/** Full failure text for graph error outputs, including nested causes. */
|
|
9
|
+
export function formatCaughtRunError(error, seen = new Set()) {
|
|
10
|
+
try {
|
|
11
|
+
if (error && typeof error === 'object') {
|
|
12
|
+
if (seen.has(error))
|
|
13
|
+
return '[Circular error reference]';
|
|
14
|
+
seen.add(error);
|
|
15
|
+
}
|
|
16
|
+
const errorLike = error != null && typeof error === 'object' ? error : undefined;
|
|
17
|
+
// Error identity is realm-local; iframe/provider errors still have the
|
|
18
|
+
// standard name/message/stack shape, usually with non-enumerable fields.
|
|
19
|
+
if (errorLike &&
|
|
20
|
+
(error instanceof Error || (typeof errorLike.name === 'string' && typeof errorLike.message === 'string'))) {
|
|
21
|
+
const text = (typeof errorLike.stack === 'string' && errorLike.stack.trim()) ||
|
|
22
|
+
`${errorLike.name}: ${errorLike.message}`.trim();
|
|
23
|
+
return errorLike.cause == null ? text : `${text}\n\nCaused by: ${formatCaughtRunError(errorLike.cause, seen)}`;
|
|
24
|
+
}
|
|
25
|
+
return typeof error === 'object' && error != null ? JSON.stringify(error, null, 2) ?? String(error) : String(error);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
// Arbitrary thrown values can have no prototype, cycles or throwing getters.
|
|
29
|
+
// Formatting their error output must never become a second graph failure.
|
|
30
|
+
try {
|
|
31
|
+
return String(error);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return '[Unprintable thrown value]';
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** Caller cancellation wins over provider failure, including cross-realm errors. */
|
|
39
|
+
export function isAbortError(error, signal) {
|
|
40
|
+
if (signal.aborted)
|
|
41
|
+
return true;
|
|
42
|
+
try {
|
|
43
|
+
return error != null && typeof error === 'object' && error.name === 'AbortError';
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -327,8 +327,9 @@ export function parseInterpolationToken(rawInner) {
|
|
|
327
327
|
function freezeReference(reference) {
|
|
328
328
|
return reference ? Object.freeze({ ...reference }) : undefined;
|
|
329
329
|
}
|
|
330
|
-
function parseInterpolationTemplateUncached(template) {
|
|
331
|
-
const tokens = scanInterpolationTokenSpans(template).map((span) => {
|
|
330
|
+
function parseInterpolationTemplateUncached(template, check, tokenLimit = Infinity) {
|
|
331
|
+
const tokens = scanInterpolationTokenSpans(template, check, tokenLimit).map((span) => {
|
|
332
|
+
check?.();
|
|
332
333
|
const parsedToken = parseInterpolationToken(span.rawInner);
|
|
333
334
|
return Object.freeze({
|
|
334
335
|
...parsedToken,
|
|
@@ -373,12 +374,15 @@ function cacheInterpolationTemplate(template, parsed) {
|
|
|
373
374
|
cachedInterpolationTemplateStorageChars += storageChars;
|
|
374
375
|
}
|
|
375
376
|
/** Returns an immutable, cached syntax representation. It never evaluates values. */
|
|
376
|
-
export function parseInterpolationTemplate(template) {
|
|
377
|
+
export function parseInterpolationTemplate(template, check, tokenLimit = Infinity) {
|
|
378
|
+
check?.();
|
|
377
379
|
const cached = interpolationTemplateCache.get(template);
|
|
378
380
|
if (cached) {
|
|
381
|
+
if (cached.parsed.tokens.length > tokenLimit)
|
|
382
|
+
throw new Error('Interpolation template has too many tokens.');
|
|
379
383
|
return cached.parsed;
|
|
380
384
|
}
|
|
381
|
-
const parsed = parseInterpolationTemplateUncached(template);
|
|
385
|
+
const parsed = parseInterpolationTemplateUncached(template, check, tokenLimit);
|
|
382
386
|
if (template.includes('{{')) {
|
|
383
387
|
cacheInterpolationTemplate(template, parsed);
|
|
384
388
|
}
|
|
@@ -403,28 +407,33 @@ export function getInterpolationTokenReference(rawInner) {
|
|
|
403
407
|
return parseInterpolationToken(rawInner).reference;
|
|
404
408
|
}
|
|
405
409
|
export function replaceInterpolationTokens(template, getReplacement, options = {}) {
|
|
406
|
-
const parsedTemplate = parseInterpolationTemplate(template);
|
|
410
|
+
const parsedTemplate = parseInterpolationTemplate(template, options.guard?.check, options.guard?.tokenLimit);
|
|
407
411
|
if (parsedTemplate.tokens.length === 0) {
|
|
408
412
|
const restoredTemplate = restoreEscapedInterpolationTokens(template);
|
|
409
413
|
return options.trim ? restoredTemplate.trim() : restoredTemplate;
|
|
410
414
|
}
|
|
411
415
|
let result = '';
|
|
412
416
|
let cursor = 0;
|
|
417
|
+
const append = (fragment) => {
|
|
418
|
+
options.guard?.output(fragment, result.length);
|
|
419
|
+
result += fragment;
|
|
420
|
+
};
|
|
413
421
|
for (const token of parsedTemplate.tokens) {
|
|
414
422
|
// Restore escaped delimiters only from authored template text. A
|
|
415
423
|
// replacement may deliberately contain `{{{...}}}` or `\\{\\{...\\}\\}` and
|
|
416
424
|
// must be returned unchanged rather than interpreted as template syntax.
|
|
417
|
-
|
|
418
|
-
|
|
425
|
+
options.guard?.check();
|
|
426
|
+
append(restoreEscapedInterpolationTokens(template.slice(cursor, token.span.start)));
|
|
427
|
+
append(getReplacement({
|
|
419
428
|
rawInner: token.rawInner,
|
|
420
429
|
span: { ...token.span },
|
|
421
430
|
tokenName: token.tokenName,
|
|
422
431
|
processingChain: token.processingChain,
|
|
423
432
|
reference: token.reference ? { ...token.reference } : undefined,
|
|
424
|
-
});
|
|
433
|
+
}));
|
|
425
434
|
cursor = token.span.end;
|
|
426
435
|
}
|
|
427
|
-
|
|
436
|
+
append(restoreEscapedInterpolationTokens(template.slice(cursor)));
|
|
428
437
|
return options.trim ? result.trim() : result;
|
|
429
438
|
}
|
|
430
439
|
/**
|
|
@@ -458,14 +467,17 @@ export function extractInterpolationVariableReferences(template) {
|
|
|
458
467
|
* are intentionally snapshotted at node execution: interpolation neither
|
|
459
468
|
* waits for a writer nor creates an execution dependency.
|
|
460
469
|
*/
|
|
461
|
-
export function getInterpolationGlobalValues(template, getGlobal) {
|
|
470
|
+
export function getInterpolationGlobalValues(template, getGlobal, check, tokenLimit = Infinity) {
|
|
462
471
|
const values = Object.create(null);
|
|
463
472
|
if (!getGlobal || !template.includes('{{')) {
|
|
464
473
|
return values;
|
|
465
474
|
}
|
|
466
|
-
for (const token of parseInterpolationTemplate(template).tokens) {
|
|
475
|
+
for (const token of parseInterpolationTemplate(template, check, tokenLimit).tokens) {
|
|
476
|
+
check?.();
|
|
467
477
|
const reference = token.reference;
|
|
468
|
-
if (!reference ||
|
|
478
|
+
if (!reference ||
|
|
479
|
+
reference.source !== 'globals' ||
|
|
480
|
+
Object.prototype.hasOwnProperty.call(values, reference.baseName)) {
|
|
469
481
|
continue;
|
|
470
482
|
}
|
|
471
483
|
const value = getGlobal(reference.baseName);
|
|
@@ -511,18 +523,22 @@ export function resolveInterpolationExpressionRawValue(expression, sources) {
|
|
|
511
523
|
return undefined;
|
|
512
524
|
}
|
|
513
525
|
const shouldUnwrapDataValue = reference.source !== 'variable' || sources.unwrapVariableDataValues !== false;
|
|
514
|
-
const
|
|
515
|
-
|
|
516
|
-
|
|
526
|
+
const property = sources.guard ? Object.getOwnPropertyDescriptor(source, reference.baseName) : undefined;
|
|
527
|
+
if (sources.guard && (!property || !('value' in property)))
|
|
528
|
+
throw new Error('Interpolation sources must use own data properties, not accessors.');
|
|
529
|
+
const sourceValue = sources.guard ? sources.guard.prepareValue(property.value) : source[reference.baseName];
|
|
530
|
+
const baseValue = shouldUnwrapDataValue ? unwrapPotentialDataValue(sourceValue) : sourceValue;
|
|
517
531
|
if (reference.jsonPath === undefined) {
|
|
518
532
|
return baseValue;
|
|
519
533
|
}
|
|
534
|
+
let selected;
|
|
520
535
|
try {
|
|
521
|
-
|
|
536
|
+
selected = evaluateJsonPath(baseValue, reference.jsonPath, false);
|
|
522
537
|
}
|
|
523
538
|
catch {
|
|
524
539
|
return undefined;
|
|
525
540
|
}
|
|
541
|
+
return sources.guard ? sources.guard.prepareValue(selected) : selected;
|
|
526
542
|
}
|
|
527
543
|
export function resolveInterpolationTokenRawValue(rawInner, sources) {
|
|
528
544
|
const reference = parseInterpolationToken(rawInner).reference;
|
|
@@ -559,19 +575,23 @@ function parseProcessing(instruction) {
|
|
|
559
575
|
param: parts[1] ? Number.parseInt(parts[1], 10) : undefined,
|
|
560
576
|
};
|
|
561
577
|
}
|
|
562
|
-
function applyProcessing(value, processingChain) {
|
|
578
|
+
function applyProcessing(value, processingChain, guard) {
|
|
579
|
+
guard?.processing(processingChain, 'chain', undefined);
|
|
563
580
|
const instructions = processingChain
|
|
564
581
|
.split('|')
|
|
565
582
|
.map((instruction) => instruction.trim())
|
|
566
583
|
.filter((instruction) => instruction !== '');
|
|
567
584
|
return instructions.reduce((result, instruction) => {
|
|
568
585
|
const { func, param } = parseProcessing(instruction);
|
|
586
|
+
guard?.processing(result, func, param);
|
|
569
587
|
const processingFunc = processingFunctions[func];
|
|
570
588
|
if (!processingFunc) {
|
|
571
589
|
console.warn(`Unknown processing function: ${func}`);
|
|
572
590
|
return result;
|
|
573
591
|
}
|
|
574
|
-
|
|
592
|
+
const processed = processingFunc(result, param);
|
|
593
|
+
guard?.output(processed, 0);
|
|
594
|
+
return processed;
|
|
575
595
|
}, value);
|
|
576
596
|
}
|
|
577
597
|
/**
|
|
@@ -590,6 +610,7 @@ export function interpolate(template, variables, graphInputValues, contextValues
|
|
|
590
610
|
contextValues,
|
|
591
611
|
globalValues: options.globalValues,
|
|
592
612
|
unwrapVariableDataValues: options.unwrapVariableDataValues,
|
|
613
|
+
guard: options.guard,
|
|
593
614
|
});
|
|
594
615
|
if (resolvedValue === undefined) {
|
|
595
616
|
console.warn(`Interpolation variable or path "${token.tokenName}" not found or resolved to undefined.`);
|
|
@@ -597,13 +618,14 @@ export function interpolate(template, variables, graphInputValues, contextValues
|
|
|
597
618
|
}
|
|
598
619
|
const isBareOrdinaryVariable = token.reference.source === 'variable' && token.reference.jsonPath === undefined;
|
|
599
620
|
const stringValue = isBareOrdinaryVariable
|
|
600
|
-
? stringifyInterpolationSourceValue(variables[token.reference.baseName], {
|
|
621
|
+
? stringifyInterpolationSourceValue(options.guard ? resolvedValue : variables[token.reference.baseName], {
|
|
601
622
|
coerceDataValueToString: options.coerceBareVariableDataValues,
|
|
602
|
-
unwrapDataValue: options.unwrapVariableDataValues !== false,
|
|
623
|
+
unwrapDataValue: !options.guard && options.unwrapVariableDataValues !== false,
|
|
603
624
|
})
|
|
604
625
|
: stringifyInterpolationValue(resolvedValue);
|
|
605
|
-
|
|
606
|
-
|
|
626
|
+
options.guard?.output(stringValue, 0);
|
|
627
|
+
return token.processingChain ? applyProcessing(stringValue, token.processingChain, options.guard) : stringValue;
|
|
628
|
+
}, { guard: options.guard });
|
|
607
629
|
}
|
|
608
630
|
/** Runtime helper injected into JavaScript runners without exposing the whole Rivet API. */
|
|
609
631
|
export function resolveCodeInterpolationExpression(inputs, expression, graphInputValues, contextValues, globalValues) {
|
|
@@ -41,8 +41,10 @@ export function isInterpolationRegexLiteralStart(value, index) {
|
|
|
41
41
|
}
|
|
42
42
|
return previousIndex < 0 || REGEX_LITERAL_PREFIX_CHARACTERS.has(value[previousIndex]);
|
|
43
43
|
}
|
|
44
|
-
function getEscapedTripleTokenEnd(template, start) {
|
|
44
|
+
function getEscapedTripleTokenEnd(template, start, check) {
|
|
45
45
|
for (let cursor = start + 3; cursor < template.length - 2; cursor += 1) {
|
|
46
|
+
if ((cursor & 4095) === 0)
|
|
47
|
+
check?.();
|
|
46
48
|
if (template[cursor] === '}' && template[cursor + 1] === '}' && template[cursor + 2] === '}') {
|
|
47
49
|
return cursor + 3;
|
|
48
50
|
}
|
|
@@ -50,7 +52,7 @@ function getEscapedTripleTokenEnd(template, start) {
|
|
|
50
52
|
return undefined;
|
|
51
53
|
}
|
|
52
54
|
/** Finds a matching `}}` while allowing JSONPath filters, quotes, and braces. */
|
|
53
|
-
function scanInterpolationToken(template, start) {
|
|
55
|
+
function scanInterpolationToken(template, start, check) {
|
|
54
56
|
let quote;
|
|
55
57
|
let regex = false;
|
|
56
58
|
let regexCharacterClass = false;
|
|
@@ -58,6 +60,8 @@ function scanInterpolationToken(template, start) {
|
|
|
58
60
|
let parenthesisDepth = 0;
|
|
59
61
|
let braceDepth = 0;
|
|
60
62
|
for (let cursor = start + 2; cursor < template.length; cursor += 1) {
|
|
63
|
+
if ((cursor & 4095) === 0)
|
|
64
|
+
check?.();
|
|
61
65
|
const character = template[cursor];
|
|
62
66
|
if (regex) {
|
|
63
67
|
if (character === '[' && !isInterpolationSyntaxCharacterEscaped(template, cursor)) {
|
|
@@ -66,7 +70,9 @@ function scanInterpolationToken(template, start) {
|
|
|
66
70
|
else if (character === ']' && !isInterpolationSyntaxCharacterEscaped(template, cursor)) {
|
|
67
71
|
regexCharacterClass = false;
|
|
68
72
|
}
|
|
69
|
-
else if (character === '/' &&
|
|
73
|
+
else if (character === '/' &&
|
|
74
|
+
!regexCharacterClass &&
|
|
75
|
+
!isInterpolationSyntaxCharacterEscaped(template, cursor)) {
|
|
70
76
|
regex = false;
|
|
71
77
|
}
|
|
72
78
|
continue;
|
|
@@ -132,22 +138,23 @@ function scanInterpolationToken(template, start) {
|
|
|
132
138
|
* the rest of the execution runtime. The returned spans are fresh data and
|
|
133
139
|
* exclude escaped triple-brace tokens.
|
|
134
140
|
*/
|
|
135
|
-
export function scanInterpolationTokenSpans(template) {
|
|
141
|
+
export function scanInterpolationTokenSpans(template, check, tokenLimit = Infinity) {
|
|
136
142
|
const spans = [];
|
|
137
143
|
let searchIndex = 0;
|
|
138
144
|
while (searchIndex < template.length) {
|
|
145
|
+
check?.();
|
|
139
146
|
const start = template.indexOf('{{', searchIndex);
|
|
140
147
|
if (start === -1) {
|
|
141
148
|
break;
|
|
142
149
|
}
|
|
143
150
|
if (template[start + 2] === '{') {
|
|
144
|
-
const escapedEnd = getEscapedTripleTokenEnd(template, start);
|
|
151
|
+
const escapedEnd = getEscapedTripleTokenEnd(template, start, check);
|
|
145
152
|
if (escapedEnd !== undefined) {
|
|
146
153
|
searchIndex = escapedEnd;
|
|
147
154
|
continue;
|
|
148
155
|
}
|
|
149
156
|
}
|
|
150
|
-
const scanResult = scanInterpolationToken(template, start);
|
|
157
|
+
const scanResult = scanInterpolationToken(template, start, check);
|
|
151
158
|
if (scanResult.kind === 'nested') {
|
|
152
159
|
searchIndex = scanResult.start;
|
|
153
160
|
continue;
|
|
@@ -164,6 +171,8 @@ export function scanInterpolationTokenSpans(template) {
|
|
|
164
171
|
searchIndex = nextStart;
|
|
165
172
|
continue;
|
|
166
173
|
}
|
|
174
|
+
if (spans.length >= tokenLimit)
|
|
175
|
+
throw new Error('Interpolation template has too many tokens.');
|
|
167
176
|
spans.push({
|
|
168
177
|
start,
|
|
169
178
|
end: scanResult.end,
|
|
@@ -14,7 +14,7 @@ export function serializeProject(project, attachedData) {
|
|
|
14
14
|
return projectV4Serializer(project, attachedData);
|
|
15
15
|
}
|
|
16
16
|
const errMessage = (err) => `${getError(err).message}\n${getError(err).stack}`;
|
|
17
|
-
export function deserializeProject(serializedProject, path = null) {
|
|
17
|
+
export function deserializeProject(serializedProject, path = null, options = {}) {
|
|
18
18
|
const { deserializerInput, version } = prepareSerializedInput(serializedProject);
|
|
19
19
|
try {
|
|
20
20
|
const result = deserializeProjectByVersion(deserializerInput, version);
|
|
@@ -28,7 +28,8 @@ export function deserializeProject(serializedProject, path = null) {
|
|
|
28
28
|
if (err instanceof yaml.YAMLError) {
|
|
29
29
|
yamlProblem(err);
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
if (options.logErrors !== false)
|
|
32
|
+
console.warn(`Failed to deserialize project v${version}: ${errMessage(err)}`);
|
|
32
33
|
if (err instanceof UiGraphNormalizationError) {
|
|
33
34
|
throw new Error(`Could not deserialize project: ${err.message}`, { cause: err });
|
|
34
35
|
}
|
|
@@ -18,6 +18,9 @@ export function validateProject(project) {
|
|
|
18
18
|
return { valid: false, errors: ['Project is not an object'], warnings };
|
|
19
19
|
}
|
|
20
20
|
const p = project;
|
|
21
|
+
if (!isValidProjectStaticData(p.data)) {
|
|
22
|
+
errors.push('Project data must be a record of static-data strings');
|
|
23
|
+
}
|
|
21
24
|
// Metadata checks
|
|
22
25
|
if (!p.metadata || typeof p.metadata !== 'object') {
|
|
23
26
|
errors.push('Missing project metadata');
|
|
@@ -136,6 +139,9 @@ function isPlainRecord(value) {
|
|
|
136
139
|
const prototype = Object.getPrototypeOf(value);
|
|
137
140
|
return prototype === Object.prototype || prototype === null;
|
|
138
141
|
}
|
|
142
|
+
export function isValidProjectStaticData(value) {
|
|
143
|
+
return (value === undefined || (isPlainRecord(value) && Object.values(value).every((entry) => typeof entry === 'string')));
|
|
144
|
+
}
|
|
139
145
|
function validateUiGraphs(uiGraphs, errors) {
|
|
140
146
|
try {
|
|
141
147
|
normalizeUiGraphRecord(uiGraphs, { repairComponentIds: false });
|