@valerypopoff/rivet2-core 2.1.10 → 2.4.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/README.md +1 -1
- package/dist/cjs/bundle.cjs +2604 -949
- package/dist/cjs/bundle.cjs.map +4 -4
- package/dist/cjs/webAppRuntime.cjs +1549 -99
- package/dist/cjs/webAppRuntime.cjs.map +4 -4
- package/dist/esm/api/createProcessor.js +4 -0
- package/dist/esm/exports.js +2 -0
- package/dist/esm/integrations/CodeRunner.js +2 -7
- package/dist/esm/integrations/CodeRunnerOptions.js +7 -0
- package/dist/esm/model/AgentResponseTrace.js +137 -11
- package/dist/esm/model/GraphProcessor.js +28 -0
- package/dist/esm/model/NodeExclusionPolicy.js +9 -1
- package/dist/esm/model/ProcessContextBuilder.js +2 -1
- package/dist/esm/model/RecordingPlayer.js +58 -5
- package/dist/esm/model/SubprocessorBridge.js +2 -0
- package/dist/esm/model/UiGraphActionProtocol.js +47 -4
- package/dist/esm/model/UiGraphBrowserRuntime.js +15 -1
- package/dist/esm/model/UiGraphIndexedDbPersistence.js +523 -0
- package/dist/esm/model/UiGraphRendererStyles.js +14 -0
- package/dist/esm/model/WebAppBrowserStorage.js +653 -0
- package/dist/esm/model/WebAppBrowserStorageRpc.js +200 -0
- package/dist/esm/model/chat-v2/aiSdkBridge.js +146 -14
- package/dist/esm/model/chat-v2/chatV2CallObserver.js +3 -0
- package/dist/esm/model/chat-v2/chatV2CredentialNames.js +93 -0
- package/dist/esm/model/chat-v2/chatV2EditorCache.js +8 -38
- package/dist/esm/model/chat-v2/chatV2Pipeline.js +41 -4
- package/dist/esm/model/chat-v2/chatV2ProviderProfile.js +31 -2
- package/dist/esm/model/chat-v2/chatV2ResponseBodyCapture.js +10 -2
- package/dist/esm/model/chat-v2/chatV2RuntimeOptions.js +6 -11
- package/dist/esm/model/chat-v2/chatV2Shared.js +1 -1
- package/dist/esm/model/chat-v2/chatV2Types.js +16 -0
- package/dist/esm/model/chat-v2/customProviderApi.js +0 -2
- package/dist/esm/model/chat-v2/index.js +3 -0
- package/dist/esm/model/chat-v2/llmChatV2Body.js +9 -1
- package/dist/esm/model/chat-v2/llmChatV2CachePolicy.js +5 -0
- package/dist/esm/model/chat-v2/llmChatV2NodeData.js +7 -0
- package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +95 -14
- package/dist/esm/model/chat-v2/llmChatV2NodeRuntime.js +33 -9
- package/dist/esm/model/chat-v2/llmChatV2OutputClone.js +42 -0
- package/dist/esm/model/chat-v2/llmInvocationCoordinator.js +31 -2
- package/dist/esm/model/chat-v2/llmModelCandidate.js +5 -1
- package/dist/esm/model/chat-v2/llmProfile.js +58 -0
- package/dist/esm/model/chat-v2/llmProfileBody.js +10 -0
- package/dist/esm/model/chat-v2/llmProfileFallback.js +406 -8
- package/dist/esm/model/chat-v2/llmProfileFieldRegistry.js +7 -0
- package/dist/esm/model/chat-v2/llmProfileHealthStore.js +328 -0
- package/dist/esm/model/chat-v2/llmProfileNodeRuntime.js +57 -34
- package/dist/esm/model/chat-v2/providerOptions.js +33 -7
- package/dist/esm/model/chat-v2/toolContinuation.js +27 -1
- package/dist/esm/model/nodes/CodeNewNode.js +5 -47
- package/dist/esm/model/nodes/CodeNode.js +4 -46
- package/dist/esm/model/nodes/ExpressionNode.js +5 -8
- package/dist/esm/model/nodes/LLMChatV2Node.js +31 -3
- package/dist/esm/model/nodes/MatchNode.js +86 -41
- package/dist/esm/plugins/gentrace/gentraceSdk.js +0 -1
- package/dist/esm/plugins/gentrace/index.js +0 -1
- package/dist/esm/plugins/gentrace/plugin.js +61 -179
- package/dist/esm/plugins.js +1 -2
- package/dist/esm/recording/ExecutionRecorder.js +50 -8
- package/dist/esm/webAppRuntime.js +5 -2
- package/dist/types/api/createProcessor.d.ts +5 -0
- package/dist/types/exports.d.ts +2 -0
- package/dist/types/integrations/CodeRunner.d.ts +10 -7
- package/dist/types/integrations/CodeRunnerOptions.d.ts +15 -0
- package/dist/types/model/AgentResponseTrace.d.ts +15 -1
- package/dist/types/model/EditorDefinition.d.ts +16 -0
- package/dist/types/model/ExecutorProtocol.d.ts +17 -6
- package/dist/types/model/GraphProcessor.d.ts +17 -5
- package/dist/types/model/NodeBase.d.ts +0 -10
- package/dist/types/model/NodeExclusionPolicy.d.ts +6 -0
- package/dist/types/model/Nodes.d.ts +2 -2
- package/dist/types/model/ProcessContext.d.ts +85 -0
- package/dist/types/model/ProcessContextBuilder.d.ts +2 -1
- package/dist/types/model/UiGraphActionProtocol.d.ts +9 -3
- package/dist/types/model/UiGraphBrowserRuntime.d.ts +6 -0
- package/dist/types/model/UiGraphIndexedDbPersistence.d.ts +50 -0
- package/dist/types/model/UiGraphRendererStyles.d.ts +1 -1
- package/dist/types/model/WebAppBrowserStorage.d.ts +90 -0
- package/dist/types/model/WebAppBrowserStorageRpc.d.ts +85 -0
- package/dist/types/model/chat-v2/chatV2CredentialNames.d.ts +30 -0
- package/dist/types/model/chat-v2/chatV2EditorCache.d.ts +1 -0
- package/dist/types/model/chat-v2/chatV2ProviderProfile.d.ts +3 -0
- package/dist/types/model/chat-v2/chatV2ResponseBodyCapture.d.ts +8 -2
- package/dist/types/model/chat-v2/chatV2RuntimeOptions.d.ts +3 -8
- package/dist/types/model/chat-v2/chatV2Types.d.ts +27 -1
- package/dist/types/model/chat-v2/customProviderApi.d.ts +0 -1
- package/dist/types/model/chat-v2/index.d.ts +3 -0
- package/dist/types/model/chat-v2/llmChatV2CachePolicy.d.ts +1 -1
- package/dist/types/model/chat-v2/llmChatV2NodeData.d.ts +10 -1
- package/dist/types/model/chat-v2/llmChatV2OutputClone.d.ts +3 -0
- package/dist/types/model/chat-v2/llmInvocationCoordinator.d.ts +5 -1
- package/dist/types/model/chat-v2/llmModelCandidate.d.ts +2 -0
- package/dist/types/model/chat-v2/llmProfile.d.ts +14 -0
- package/dist/types/model/chat-v2/llmProfileBody.d.ts +1 -1
- package/dist/types/model/chat-v2/llmProfileFallback.d.ts +25 -2
- package/dist/types/model/chat-v2/llmProfileFieldRegistry.d.ts +26 -6
- package/dist/types/model/chat-v2/llmProfileHealthStore.d.ts +121 -0
- package/dist/types/model/chat-v2/llmProfileNodeRuntime.d.ts +1 -1
- package/dist/types/model/chat-v2/llmProfileTypes.d.ts +9 -0
- package/dist/types/model/chat-v2/providerOptions.d.ts +2 -0
- package/dist/types/model/chat-v2/toolContinuation.d.ts +14 -0
- package/dist/types/model/nodes/CodeNewNode.d.ts +0 -5
- package/dist/types/model/nodes/CodeNode.d.ts +0 -5
- package/dist/types/model/nodes/MatchNode.d.ts +6 -0
- package/dist/types/plugins/gentrace/gentraceSdk.d.ts +0 -1
- package/dist/types/plugins/gentrace/plugin.d.ts +55 -9
- package/dist/types/plugins.d.ts +1 -1
- package/dist/types/recording/ExecutionRecorder.d.ts +7 -1
- package/dist/types/recording/RecordedEvents.d.ts +11 -0
- package/dist/types/webAppRuntime.d.ts +8 -2
- package/package.json +2 -2
|
@@ -138,6 +138,10 @@ export function coreCreateProcessor(project, options, internalOptions = {}) {
|
|
|
138
138
|
settings: resolveProcessSettings(options),
|
|
139
139
|
getChatNodeEndpoint: options.getChatNodeEndpoint,
|
|
140
140
|
onChatV2CallFinished: options.onChatV2CallFinished,
|
|
141
|
+
onLLMChatOutputSnapshot: options.onLLMChatOutputSnapshot,
|
|
142
|
+
llmProfileHealthStore: options.llmProfileHealthStore,
|
|
143
|
+
llmProfileHealthExecutionCorrelationId: options.llmProfileHealthExecutionCorrelationId,
|
|
144
|
+
evaluation: options.evaluation,
|
|
141
145
|
}, resolvedInputs, resolvedContextValues, { returnWhenGraphOutputsReady: options.returnWhenGraphOutputsReady });
|
|
142
146
|
if (abortSignal?.aborted) {
|
|
143
147
|
void processor.abort();
|
package/dist/esm/exports.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './utils/index.js';
|
|
2
2
|
// eslint-disable-next-line import/no-cycle -- GraphProcessor depends on CodeRunner, which exposes the top-level Rivet export surface.
|
|
3
3
|
export * from './model/GraphProcessor.js';
|
|
4
|
+
export { canConsumeControlFlowExcludedInput } from './model/NodeExclusionPolicy.js';
|
|
4
5
|
export * from './model/DataValue.js';
|
|
5
6
|
export * from './model/NodeBase.js';
|
|
6
7
|
export * from './model/NodeGraph.js';
|
|
@@ -15,6 +16,7 @@ export * from './model/UiGraphWebAppStorage.js';
|
|
|
15
16
|
export * from './model/StoredValueStore.js';
|
|
16
17
|
export * from './model/ToolCallContinuation.js';
|
|
17
18
|
export * from './model/UiGraphActionProtocol.js';
|
|
19
|
+
export * from './model/WebAppBrowserStorageRpc.js';
|
|
18
20
|
export * from './model/GraphProgress.js';
|
|
19
21
|
export * from './model/UiGraphRendererStyles.js';
|
|
20
22
|
export * from './model/MarkdownSanitizationPolicy.js';
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
// eslint-disable-next-line import/no-cycle --
|
|
1
|
+
// eslint-disable-next-line import/no-cycle -- Authored code receives the complete public Rivet namespace at execution time.
|
|
2
2
|
import * as Rivet from '../exports.js';
|
|
3
|
+
export { ALL_CODE_RUNNER_OPTIONS } from './CodeRunnerOptions.js';
|
|
3
4
|
export class IsomorphicCodeRunner {
|
|
4
5
|
async runCode(code, inputs, options, graphInputs, contextValues) {
|
|
5
6
|
const argNames = ['inputs'];
|
|
6
7
|
const args = [inputs];
|
|
7
|
-
if (options.includeRequire) {
|
|
8
|
-
throw new Error('require() requires the Node executor.');
|
|
9
|
-
}
|
|
10
|
-
if (options.includeProcess) {
|
|
11
|
-
throw new Error('process requires the Node executor.');
|
|
12
|
-
}
|
|
13
8
|
if (options.includeConsole) {
|
|
14
9
|
argNames.push('console');
|
|
15
10
|
args.push(console);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export const AGENT_RESPONSE_TRACE_SCHEMA_VERSION = 1;
|
|
2
2
|
export const AGENT_RESPONSE_TRACE_MAX_MODEL_CALLS = 250;
|
|
3
|
+
export const AGENT_RESPONSE_TRACE_MAX_PROFILE_ATTEMPTS = 1_000;
|
|
3
4
|
export const AGENT_RESPONSE_TRACE_MAX_TOOL_CALLS = 500;
|
|
4
5
|
export function buildAgentResponseTrace(options) {
|
|
5
6
|
const matchingEvents = deduplicateAgentTraceEvents(options.events.filter((event) => {
|
|
@@ -12,15 +13,21 @@ export function buildAgentResponseTrace(options) {
|
|
|
12
13
|
if (event.type === 'llm-call-finished') {
|
|
13
14
|
return event.nodeId === options.nodeId && event.processId === options.processId;
|
|
14
15
|
}
|
|
16
|
+
if (event.type === 'llm-profile-attempt') {
|
|
17
|
+
return event.nodeId === options.nodeId && event.processId === options.processId;
|
|
18
|
+
}
|
|
15
19
|
return event.sourceNodeId === options.nodeId && event.sourceProcessId === options.processId;
|
|
16
20
|
}));
|
|
17
21
|
const allModelCalls = matchingEvents
|
|
18
22
|
.filter((event) => event.type === 'llm-call-finished')
|
|
19
23
|
.map(toModelCallTrace);
|
|
24
|
+
const allProfileAttempts = matchingEvents
|
|
25
|
+
.filter((event) => event.type === 'llm-profile-attempt')
|
|
26
|
+
.map(toProfileAttemptTrace);
|
|
20
27
|
const allToolCalls = matchingEvents
|
|
21
28
|
.filter((event) => event.type === 'tool-call-finished')
|
|
22
29
|
.map(toToolCallTrace);
|
|
23
|
-
const summary = summarizeAgentCalls(allModelCalls, allToolCalls);
|
|
30
|
+
const summary = summarizeAgentCalls(allModelCalls, allProfileAttempts, allToolCalls);
|
|
24
31
|
const terminalAt = options.responseReadyAt ?? options.finishedAt;
|
|
25
32
|
return {
|
|
26
33
|
schemaVersion: AGENT_RESPONSE_TRACE_SCHEMA_VERSION,
|
|
@@ -41,8 +48,10 @@ export function buildAgentResponseTrace(options) {
|
|
|
41
48
|
...(options.backgroundWorkPending == null ? {} : { backgroundWorkPending: options.backgroundWorkPending }),
|
|
42
49
|
summary,
|
|
43
50
|
modelCalls: allModelCalls.slice(0, AGENT_RESPONSE_TRACE_MAX_MODEL_CALLS),
|
|
51
|
+
profileAttempts: allProfileAttempts.slice(0, AGENT_RESPONSE_TRACE_MAX_PROFILE_ATTEMPTS),
|
|
44
52
|
toolCalls: allToolCalls.slice(0, AGENT_RESPONSE_TRACE_MAX_TOOL_CALLS),
|
|
45
53
|
omittedModelCallCount: Math.max(0, allModelCalls.length - AGENT_RESPONSE_TRACE_MAX_MODEL_CALLS),
|
|
54
|
+
omittedProfileAttemptCount: Math.max(0, allProfileAttempts.length - AGENT_RESPONSE_TRACE_MAX_PROFILE_ATTEMPTS),
|
|
46
55
|
omittedToolCallCount: Math.max(0, allToolCalls.length - AGENT_RESPONSE_TRACE_MAX_TOOL_CALLS),
|
|
47
56
|
};
|
|
48
57
|
}
|
|
@@ -78,6 +87,9 @@ export function getAgentTraceEventIdentity(event) {
|
|
|
78
87
|
if (event.type === 'llm-call-finished') {
|
|
79
88
|
return `model\u0000${event.execution.rootRunId}\u0000${event.execution.graphRunId}\u0000${event.nodeId}\u0000${event.processId}\u0000${event.callId}`;
|
|
80
89
|
}
|
|
90
|
+
if (event.type === 'llm-profile-attempt') {
|
|
91
|
+
return `profile-attempt\u0000${event.execution.rootRunId}\u0000${event.execution.graphRunId}\u0000${event.nodeId}\u0000${event.processId}\u0000${event.eventId}`;
|
|
92
|
+
}
|
|
81
93
|
return event.toolCallId == null
|
|
82
94
|
? undefined
|
|
83
95
|
: `tool\u0000${event.execution.rootRunId}\u0000${event.execution.graphRunId}\u0000${event.sourceNodeId}\u0000${event.sourceProcessId}\u0000${event.toolCallId}`;
|
|
@@ -88,6 +100,28 @@ export function getAgentTraceEventIdentity(event) {
|
|
|
88
100
|
* later legacy-shaped copy erase result navigation.
|
|
89
101
|
*/
|
|
90
102
|
export function mergeAgentTraceEvent(existing, incoming) {
|
|
103
|
+
if (existing.type === 'llm-call-finished' && incoming.type === 'llm-call-finished') {
|
|
104
|
+
return {
|
|
105
|
+
...incoming,
|
|
106
|
+
...(incoming.profileName == null && existing.profileName != null
|
|
107
|
+
? { profileName: existing.profileName }
|
|
108
|
+
: {}),
|
|
109
|
+
...(incoming.profileHealthKey == null && existing.profileHealthKey != null
|
|
110
|
+
? { profileHealthKey: existing.profileHealthKey }
|
|
111
|
+
: {}),
|
|
112
|
+
...(incoming.profileHealthState == null && existing.profileHealthState != null
|
|
113
|
+
? { profileHealthState: existing.profileHealthState }
|
|
114
|
+
: {}),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
if (existing.type === 'llm-profile-attempt' && incoming.type === 'llm-profile-attempt') {
|
|
118
|
+
return {
|
|
119
|
+
...incoming,
|
|
120
|
+
...(incoming.profileName == null && existing.profileName != null
|
|
121
|
+
? { profileName: existing.profileName }
|
|
122
|
+
: {}),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
91
125
|
if (existing.type === 'tool-call-finished' &&
|
|
92
126
|
incoming.type === 'tool-call-finished' &&
|
|
93
127
|
existing.resultOwner != null &&
|
|
@@ -108,6 +142,9 @@ function toModelCallTrace(event) {
|
|
|
108
142
|
outcome: event.outcome,
|
|
109
143
|
attemptIndex: event.attemptIndex,
|
|
110
144
|
...(event.profileIndex == null ? {} : { profileIndex: event.profileIndex }),
|
|
145
|
+
...(event.profileName == null ? {} : { profileName: event.profileName }),
|
|
146
|
+
...(event.profileHealthKey == null ? {} : { profileHealthKey: event.profileHealthKey }),
|
|
147
|
+
...(event.profileHealthState == null ? {} : { profileHealthState: event.profileHealthState }),
|
|
111
148
|
...(event.roundIndex == null ? {} : { roundIndex: event.roundIndex }),
|
|
112
149
|
...(event.startedAt == null ? {} : { startedAt: event.startedAt }),
|
|
113
150
|
...(event.durationMs == null ? {} : { durationMs: event.durationMs }),
|
|
@@ -131,7 +168,11 @@ function toToolCallTrace(event) {
|
|
|
131
168
|
...(event.durationMs == null ? {} : { durationMs: event.durationMs }),
|
|
132
169
|
};
|
|
133
170
|
}
|
|
134
|
-
function
|
|
171
|
+
function toProfileAttemptTrace(event) {
|
|
172
|
+
const { type: _type, execution: _execution, ...trace } = event;
|
|
173
|
+
return trace;
|
|
174
|
+
}
|
|
175
|
+
function summarizeAgentCalls(modelCalls, profileAttempts, toolCalls) {
|
|
135
176
|
const usageKeys = ['promptTokens', 'completionTokens', 'totalTokens', 'cachedTokens', 'reasoningTokens'];
|
|
136
177
|
const usage = Object.fromEntries(usageKeys.flatMap((key) => {
|
|
137
178
|
const values = modelCalls.map((call) => call.usage?.[key]).filter((value) => value != null);
|
|
@@ -141,7 +182,7 @@ function summarizeAgentCalls(modelCalls, toolCalls) {
|
|
|
141
182
|
.map((call) => call.pricing.costUsd)
|
|
142
183
|
.filter((value) => value != null && Number.isFinite(value));
|
|
143
184
|
const unknownCostCount = modelCalls.filter((call) => call.pricing.status === 'unknown' || !Number.isFinite(call.pricing.costUsd)).length;
|
|
144
|
-
const profileTransitions = countProfileFallbacks(modelCalls);
|
|
185
|
+
const profileTransitions = countProfileFallbacks(modelCalls, profileAttempts);
|
|
145
186
|
return {
|
|
146
187
|
modelCallCount: modelCalls.length,
|
|
147
188
|
toolCallCount: toolCalls.length,
|
|
@@ -162,18 +203,24 @@ function summarizeAgentCalls(modelCalls, toolCalls) {
|
|
|
162
203
|
* profile across continuation rounds. Using that invariant also accounts for
|
|
163
204
|
* configuration-failed profiles that never produced a physical-call event.
|
|
164
205
|
*/
|
|
165
|
-
function countProfileFallbacks(modelCalls) {
|
|
206
|
+
function countProfileFallbacks(modelCalls, profileAttempts) {
|
|
166
207
|
const highestProfileByInvocation = new Map();
|
|
167
208
|
let count = 0;
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
209
|
+
const candidates = [
|
|
210
|
+
...modelCalls.flatMap((call) => call.profileIndex == null
|
|
211
|
+
? []
|
|
212
|
+
: [{ nodeId: call.nodeId, processId: call.processId, profileIndex: call.profileIndex }]),
|
|
213
|
+
...profileAttempts.flatMap((attempt) => attempt.profileIndex == null
|
|
214
|
+
? []
|
|
215
|
+
: [{ nodeId: attempt.nodeId, processId: attempt.processId, profileIndex: attempt.profileIndex }]),
|
|
216
|
+
];
|
|
217
|
+
for (const candidate of candidates) {
|
|
218
|
+
const key = `${candidate.nodeId}\u0000${candidate.processId}`;
|
|
172
219
|
const highestProfile = highestProfileByInvocation.get(key) ?? 0;
|
|
173
|
-
if (
|
|
220
|
+
if (candidate.profileIndex <= highestProfile)
|
|
174
221
|
continue;
|
|
175
|
-
count +=
|
|
176
|
-
highestProfileByInvocation.set(key,
|
|
222
|
+
count += candidate.profileIndex - highestProfile;
|
|
223
|
+
highestProfileByInvocation.set(key, candidate.profileIndex);
|
|
177
224
|
}
|
|
178
225
|
return count;
|
|
179
226
|
}
|
|
@@ -197,8 +244,10 @@ export function isAgentResponseTrace(value) {
|
|
|
197
244
|
'backgroundWorkPending',
|
|
198
245
|
'summary',
|
|
199
246
|
'modelCalls',
|
|
247
|
+
'profileAttempts',
|
|
200
248
|
'toolCalls',
|
|
201
249
|
'omittedModelCallCount',
|
|
250
|
+
'omittedProfileAttemptCount',
|
|
202
251
|
'omittedToolCallCount',
|
|
203
252
|
]))
|
|
204
253
|
return false;
|
|
@@ -210,8 +259,13 @@ export function isAgentResponseTrace(value) {
|
|
|
210
259
|
return false;
|
|
211
260
|
if (!isRecord(value.summary) || !Array.isArray(value.modelCalls) || !Array.isArray(value.toolCalls))
|
|
212
261
|
return false;
|
|
262
|
+
if (value.profileAttempts !== undefined && !Array.isArray(value.profileAttempts))
|
|
263
|
+
return false;
|
|
213
264
|
if (value.modelCalls.length > AGENT_RESPONSE_TRACE_MAX_MODEL_CALLS)
|
|
214
265
|
return false;
|
|
266
|
+
if (Array.isArray(value.profileAttempts) &&
|
|
267
|
+
value.profileAttempts.length > AGENT_RESPONSE_TRACE_MAX_PROFILE_ATTEMPTS)
|
|
268
|
+
return false;
|
|
215
269
|
if (value.toolCalls.length > AGENT_RESPONSE_TRACE_MAX_TOOL_CALLS)
|
|
216
270
|
return false;
|
|
217
271
|
return (isOptionalString(value.nodeId) &&
|
|
@@ -223,9 +277,11 @@ export function isAgentResponseTrace(value) {
|
|
|
223
277
|
isOptionalBoolean(value.backgroundWorkPending) &&
|
|
224
278
|
['running', 'response-ready', 'completed', 'error', 'aborted', 'unavailable'].includes(String(value.status)) &&
|
|
225
279
|
isNonNegativeInteger(value.omittedModelCallCount) &&
|
|
280
|
+
(value.omittedProfileAttemptCount === undefined || isNonNegativeInteger(value.omittedProfileAttemptCount)) &&
|
|
226
281
|
isNonNegativeInteger(value.omittedToolCallCount) &&
|
|
227
282
|
isAgentTraceSummary(value.summary) &&
|
|
228
283
|
value.modelCalls.every(isAgentModelCallTrace) &&
|
|
284
|
+
(value.profileAttempts === undefined || value.profileAttempts.every(isAgentLLMProfileAttemptTrace)) &&
|
|
229
285
|
value.toolCalls.every(isAgentToolCallTrace));
|
|
230
286
|
}
|
|
231
287
|
/**
|
|
@@ -248,6 +304,9 @@ export class AgentResponseTraceCollector {
|
|
|
248
304
|
}), processor.on('llmCallFinished', (event) => {
|
|
249
305
|
this.#execution ??= event.execution;
|
|
250
306
|
this.#events.push({ type: 'llm-call-finished', ...event });
|
|
307
|
+
}), processor.on('llmProfileAttempt', (event) => {
|
|
308
|
+
this.#execution ??= event.execution;
|
|
309
|
+
this.#events.push({ type: 'llm-profile-attempt', ...event });
|
|
251
310
|
}), processor.on('toolCallFinished', (event) => {
|
|
252
311
|
this.#execution ??= event.execution;
|
|
253
312
|
this.#events.push({ type: 'tool-call-finished', ...event });
|
|
@@ -313,6 +372,9 @@ function isAgentModelCallTrace(value) {
|
|
|
313
372
|
'outcome',
|
|
314
373
|
'attemptIndex',
|
|
315
374
|
'profileIndex',
|
|
375
|
+
'profileName',
|
|
376
|
+
'profileHealthKey',
|
|
377
|
+
'profileHealthState',
|
|
316
378
|
'roundIndex',
|
|
317
379
|
'startedAt',
|
|
318
380
|
'durationMs',
|
|
@@ -331,6 +393,12 @@ function isAgentModelCallTrace(value) {
|
|
|
331
393
|
(value.outcome === 'success' || value.outcome === 'provider-failure' || value.outcome === 'aborted') &&
|
|
332
394
|
isNonNegativeInteger(value.attemptIndex) &&
|
|
333
395
|
isOptionalNonNegativeInteger(value.profileIndex) &&
|
|
396
|
+
isOptionalString(value.profileName) &&
|
|
397
|
+
isOptionalString(value.profileHealthKey) &&
|
|
398
|
+
(value.profileHealthState === undefined ||
|
|
399
|
+
value.profileHealthState === 'closed' ||
|
|
400
|
+
value.profileHealthState === 'open' ||
|
|
401
|
+
value.profileHealthState === 'half-open') &&
|
|
334
402
|
isOptionalNonNegativeInteger(value.roundIndex) &&
|
|
335
403
|
isOptionalNonNegativeFiniteNumber(value.startedAt) &&
|
|
336
404
|
isOptionalNonNegativeFiniteNumber(value.durationMs) &&
|
|
@@ -338,6 +406,64 @@ function isAgentModelCallTrace(value) {
|
|
|
338
406
|
(value.usage === undefined || isAgentTraceUsage(value.usage)) &&
|
|
339
407
|
isAgentTracePricing(value.pricing));
|
|
340
408
|
}
|
|
409
|
+
function isAgentLLMProfileAttemptTrace(value) {
|
|
410
|
+
return (isRecord(value) &&
|
|
411
|
+
hasOnlyKeys(value, [
|
|
412
|
+
'eventId',
|
|
413
|
+
'roundIndex',
|
|
414
|
+
'profileIndex',
|
|
415
|
+
'profileName',
|
|
416
|
+
'nodeId',
|
|
417
|
+
'processId',
|
|
418
|
+
'provider',
|
|
419
|
+
'model',
|
|
420
|
+
'customProviderApi',
|
|
421
|
+
'stage',
|
|
422
|
+
'outcome',
|
|
423
|
+
'attemptIndex',
|
|
424
|
+
'status',
|
|
425
|
+
'error',
|
|
426
|
+
'profileHealthKey',
|
|
427
|
+
'healthState',
|
|
428
|
+
'healthDisposition',
|
|
429
|
+
'healthOutcome',
|
|
430
|
+
'retryAt',
|
|
431
|
+
'timeoutKind',
|
|
432
|
+
]) &&
|
|
433
|
+
typeof value.eventId === 'string' &&
|
|
434
|
+
isNonNegativeInteger(value.roundIndex) &&
|
|
435
|
+
isOptionalNonNegativeInteger(value.profileIndex) &&
|
|
436
|
+
isOptionalString(value.profileName) &&
|
|
437
|
+
typeof value.nodeId === 'string' &&
|
|
438
|
+
typeof value.processId === 'string' &&
|
|
439
|
+
typeof value.provider === 'string' &&
|
|
440
|
+
typeof value.model === 'string' &&
|
|
441
|
+
(value.customProviderApi === undefined ||
|
|
442
|
+
value.customProviderApi === 'completions' ||
|
|
443
|
+
value.customProviderApi === 'responses') &&
|
|
444
|
+
['configuration', 'request', 'response-validation', 'health-gate', 'health-update'].includes(String(value.stage)) &&
|
|
445
|
+
['success', 'failure', 'aborted', 'skipped'].includes(String(value.outcome)) &&
|
|
446
|
+
isOptionalNonNegativeInteger(value.attemptIndex) &&
|
|
447
|
+
isOptionalNonNegativeFiniteNumber(value.status) &&
|
|
448
|
+
isOptionalString(value.error) &&
|
|
449
|
+
isOptionalString(value.profileHealthKey) &&
|
|
450
|
+
(value.healthState === undefined ||
|
|
451
|
+
value.healthState === 'closed' ||
|
|
452
|
+
value.healthState === 'open' ||
|
|
453
|
+
value.healthState === 'half-open') &&
|
|
454
|
+
(value.healthDisposition === undefined ||
|
|
455
|
+
value.healthDisposition === 'allow' ||
|
|
456
|
+
value.healthDisposition === 'deny' ||
|
|
457
|
+
value.healthDisposition === 'fail-open') &&
|
|
458
|
+
(value.healthOutcome === undefined ||
|
|
459
|
+
value.healthOutcome === 'healthy' ||
|
|
460
|
+
value.healthOutcome === 'unhealthy' ||
|
|
461
|
+
value.healthOutcome === 'ignored') &&
|
|
462
|
+
isOptionalNonNegativeFiniteNumber(value.retryAt) &&
|
|
463
|
+
(value.timeoutKind === undefined ||
|
|
464
|
+
value.timeoutKind === 'first-output' ||
|
|
465
|
+
value.timeoutKind === 'stream-inactivity'));
|
|
466
|
+
}
|
|
341
467
|
function isAgentToolCallTrace(value) {
|
|
342
468
|
const hasKnownOutcome = isRecord(value) &&
|
|
343
469
|
(value.outcome === 'success' ||
|
|
@@ -410,6 +410,7 @@ export class GraphProcessor {
|
|
|
410
410
|
splitIndex: this.#executor.index,
|
|
411
411
|
}
|
|
412
412
|
: undefined,
|
|
413
|
+
...(this.#context?.evaluation === undefined ? {} : { evaluation: this.#context.evaluation }),
|
|
413
414
|
};
|
|
414
415
|
}
|
|
415
416
|
#withExecution(data, execution = this.#buildExecutionMetadata()) {
|
|
@@ -824,6 +825,8 @@ export class GraphProcessor {
|
|
|
824
825
|
// observer from the root run so nested LLM calls are not emitted once by
|
|
825
826
|
// every ancestor before their own event is bridged to the root emitter.
|
|
826
827
|
const hostChatV2Observer = this.getRootProcessor().#context.onChatV2CallFinished;
|
|
828
|
+
const hostLLMChatOutputSnapshotObserver = this.getRootProcessor().#context.onLLMChatOutputSnapshot;
|
|
829
|
+
const hostLLMProfileAttemptObserver = this.getRootProcessor().#context.onLLMProfileAttempt;
|
|
827
830
|
this.#nodeProcessContextBase = {
|
|
828
831
|
...this.#context,
|
|
829
832
|
abortGraph: (error) => {
|
|
@@ -858,6 +861,30 @@ export class GraphProcessor {
|
|
|
858
861
|
const { rawUsage: _rawUsage, ...traceEvent } = event;
|
|
859
862
|
emitDetached(this.#emitter, 'llmCallFinished', this.#withExecution(traceEvent));
|
|
860
863
|
},
|
|
864
|
+
onLLMChatOutputSnapshot: (event) => {
|
|
865
|
+
try {
|
|
866
|
+
const observerResult = hostLLMChatOutputSnapshotObserver?.(event);
|
|
867
|
+
if (observerResult != null && typeof observerResult.then === 'function') {
|
|
868
|
+
void Promise.resolve(observerResult).catch(() => undefined);
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
catch {
|
|
872
|
+
// Snapshot observers are display-only and must never affect execution.
|
|
873
|
+
}
|
|
874
|
+
emitDetached(this.#emitter, 'llmChatOutputSnapshot', this.#withExecution(event));
|
|
875
|
+
},
|
|
876
|
+
onLLMProfileAttempt: (event) => {
|
|
877
|
+
try {
|
|
878
|
+
const observerResult = hostLLMProfileAttemptObserver?.(event);
|
|
879
|
+
if (observerResult != null && typeof observerResult.then === 'function') {
|
|
880
|
+
void Promise.resolve(observerResult).catch(() => undefined);
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
catch {
|
|
884
|
+
// Host observers must never change graph execution.
|
|
885
|
+
}
|
|
886
|
+
emitDetached(this.#emitter, 'llmProfileAttempt', this.#withExecution(event));
|
|
887
|
+
},
|
|
861
888
|
onToolCallFinished: (event) => {
|
|
862
889
|
emitDetached(this.#emitter, 'toolCallFinished', this.#withExecution(event));
|
|
863
890
|
},
|
|
@@ -1905,6 +1932,7 @@ export class GraphProcessor {
|
|
|
1905
1932
|
emitDetached(this.#emitter, 'progress', this.#withExecution({ node, processId, progress: normalized }));
|
|
1906
1933
|
}
|
|
1907
1934
|
},
|
|
1935
|
+
splitIndex: node.isSplitRun ? index : 0,
|
|
1908
1936
|
setGlobal: (id, value) => {
|
|
1909
1937
|
this.#globals.set(id, value);
|
|
1910
1938
|
emitDetached(this.#emitter, 'globalSet', this.#withExecution({ id, value, processId }));
|
|
@@ -11,6 +11,14 @@ const nodesAllowedToConsumeExcludedValue = new Set([
|
|
|
11
11
|
'raceInputs',
|
|
12
12
|
'loopController',
|
|
13
13
|
]);
|
|
14
|
+
/**
|
|
15
|
+
* Whether a node intentionally handles an input that was excluded by control
|
|
16
|
+
* flow. Most nodes are excluded themselves in that situation; these nodes
|
|
17
|
+
* implement their own fallback, branching, or aggregation behavior instead.
|
|
18
|
+
*/
|
|
19
|
+
export function canConsumeControlFlowExcludedInput(node) {
|
|
20
|
+
return nodesAllowedToConsumeExcludedValue.has(node.type);
|
|
21
|
+
}
|
|
14
22
|
function isControlFlowExcluded(value) {
|
|
15
23
|
return value != null && getScalarTypeOf(value.type) === 'control-flow-excluded';
|
|
16
24
|
}
|
|
@@ -34,7 +42,7 @@ export function getControlFlowExclusionDecision({ inputValues, node, typeOfExclu
|
|
|
34
42
|
}
|
|
35
43
|
const controlFlowExcludedValues = entries(inputValues).filter(([, value]) => isControlFlowExcluded(value) && (typeOfExclusion === undefined || value.value === typeOfExclusion));
|
|
36
44
|
const isWaitingForLoop = controlFlowExcludedValues.some(([, value]) => value?.value === LOOP_NOT_BROKEN_SENTINEL);
|
|
37
|
-
const allowedToConsumeExcludedValue =
|
|
45
|
+
const allowedToConsumeExcludedValue = canConsumeControlFlowExcludedInput(node) && !isWaitingForLoop;
|
|
38
46
|
if (controlFlowExcludedValues.length === 0 || allowedToConsumeExcludedValue) {
|
|
39
47
|
return { action: 'continue' };
|
|
40
48
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export function buildNodeProcessContext(options) {
|
|
2
|
-
const { attachedData, activeOutputPortIds, base, createSubProcessor, execution, externalFunctions, getPluginConfig, isDirectRunTarget, markResultAsEditorCacheHit, node, nodeAbortController, onPartialOutputs, processId, requestUserInput, reportProgress, setGlobal, toolCallContinuation, toolCallTraceSource, waitEvent, } = options;
|
|
2
|
+
const { attachedData, activeOutputPortIds, base, createSubProcessor, execution, externalFunctions, getPluginConfig, isDirectRunTarget, markResultAsEditorCacheHit, node, nodeAbortController, onPartialOutputs, processId, requestUserInput, reportProgress, setGlobal, splitIndex, toolCallContinuation, toolCallTraceSource, waitEvent, } = options;
|
|
3
3
|
return {
|
|
4
4
|
...base,
|
|
5
5
|
node,
|
|
@@ -12,6 +12,7 @@ export function buildNodeProcessContext(options) {
|
|
|
12
12
|
onPartialOutputs,
|
|
13
13
|
signal: nodeAbortController.signal,
|
|
14
14
|
processId,
|
|
15
|
+
splitIndex,
|
|
15
16
|
setGlobal,
|
|
16
17
|
createSubProcessor: createSubProcessor,
|
|
17
18
|
getPluginConfig,
|
|
@@ -8,6 +8,31 @@ function withOptionalDuration(payload, durationMs, splitRunDurationMs) {
|
|
|
8
8
|
...(splitRunDurationMs === undefined ? {} : { splitRunDurationMs }),
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
|
+
function withReplayRecordedAt(data, replayRecordedAt) {
|
|
12
|
+
if (typeof replayRecordedAt !== 'number' ||
|
|
13
|
+
!Number.isFinite(replayRecordedAt) ||
|
|
14
|
+
data == null ||
|
|
15
|
+
typeof data !== 'object') {
|
|
16
|
+
return data;
|
|
17
|
+
}
|
|
18
|
+
return { ...data, replayRecordedAt };
|
|
19
|
+
}
|
|
20
|
+
const REPLAY_TIMED_LIFECYCLE_EVENTS = new Set([
|
|
21
|
+
'start',
|
|
22
|
+
'graphStart',
|
|
23
|
+
'graphOutputsReady',
|
|
24
|
+
'graphFinish',
|
|
25
|
+
'graphError',
|
|
26
|
+
'graphAbort',
|
|
27
|
+
'nodeStart',
|
|
28
|
+
'userInput',
|
|
29
|
+
'progress',
|
|
30
|
+
'partialOutput',
|
|
31
|
+
'nodeFinish',
|
|
32
|
+
'nodeError',
|
|
33
|
+
'nodeExcluded',
|
|
34
|
+
'nodeOutputsCleared',
|
|
35
|
+
]);
|
|
11
36
|
export async function replayExecutionRecording(options) {
|
|
12
37
|
const { emitter, erroredNodes, graphOutputs, fallbackGraphId, initialReplayExecution, project, recorder, recordingPlaybackChatLatency, setContextValues, setGraphInputs, setGraphOutputs, setRunning, visitedNodes, waitUntilUnpaused, nodeResults, isAborted, } = options;
|
|
13
38
|
const nodesByIdAllGraphs = {};
|
|
@@ -20,6 +45,7 @@ export async function replayExecutionRecording(options) {
|
|
|
20
45
|
}
|
|
21
46
|
let hasEmittedRunActivityExecution = false;
|
|
22
47
|
let getFallbackExecution;
|
|
48
|
+
let currentReplayRecordedAt;
|
|
23
49
|
const getReplayFallbackGraph = () => {
|
|
24
50
|
const replayTargetGraph = fallbackGraphId == null ? undefined : project.graphs[fallbackGraphId];
|
|
25
51
|
const projectMainGraph = project.metadata.mainGraphId == null ? undefined : project.graphs[project.metadata.mainGraphId];
|
|
@@ -31,7 +57,13 @@ export async function replayExecutionRecording(options) {
|
|
|
31
57
|
// playback error remains attached to that root instead of synthesizing a
|
|
32
58
|
// second one.
|
|
33
59
|
hasEmittedRunActivityExecution = true;
|
|
34
|
-
|
|
60
|
+
const payload = REPLAY_TIMED_LIFECYCLE_EVENTS.has(event)
|
|
61
|
+
? withReplayRecordedAt(data, currentReplayRecordedAt)
|
|
62
|
+
: data;
|
|
63
|
+
emitDetached(emitter, event, payload);
|
|
64
|
+
};
|
|
65
|
+
const emitReplayTerminalEvent = (event, data) => {
|
|
66
|
+
emitDetached(emitter, event, withReplayRecordedAt(data, currentReplayRecordedAt));
|
|
35
67
|
};
|
|
36
68
|
const emitFallbackRootTerminal = (status, data) => {
|
|
37
69
|
// Older recordings and preflight-error recordings can contain only the
|
|
@@ -168,6 +200,7 @@ export async function replayExecutionRecording(options) {
|
|
|
168
200
|
break;
|
|
169
201
|
}
|
|
170
202
|
await waitUntilUnpaused();
|
|
203
|
+
currentReplayRecordedAt = event.ts;
|
|
171
204
|
switch (event.type) {
|
|
172
205
|
case 'start': {
|
|
173
206
|
const { data } = event;
|
|
@@ -184,7 +217,7 @@ export async function replayExecutionRecording(options) {
|
|
|
184
217
|
}
|
|
185
218
|
case 'abort': {
|
|
186
219
|
emitFallbackRootTerminal('aborted', event.data);
|
|
187
|
-
|
|
220
|
+
emitReplayTerminalEvent('abort', event.data);
|
|
188
221
|
break;
|
|
189
222
|
}
|
|
190
223
|
case 'pause': {
|
|
@@ -200,14 +233,14 @@ export async function replayExecutionRecording(options) {
|
|
|
200
233
|
}
|
|
201
234
|
case 'done': {
|
|
202
235
|
emitFallbackRootTerminal('completed', { outputs: event.data.results });
|
|
203
|
-
|
|
236
|
+
emitReplayTerminalEvent('done', event.data);
|
|
204
237
|
setGraphOutputs(event.data.results);
|
|
205
238
|
setRunning(false);
|
|
206
239
|
break;
|
|
207
240
|
}
|
|
208
241
|
case 'error': {
|
|
209
242
|
emitFallbackRootTerminal('error', event.data);
|
|
210
|
-
|
|
243
|
+
emitReplayTerminalEvent('error', event.data);
|
|
211
244
|
break;
|
|
212
245
|
}
|
|
213
246
|
case 'globalSet': {
|
|
@@ -381,6 +414,22 @@ export async function replayExecutionRecording(options) {
|
|
|
381
414
|
});
|
|
382
415
|
break;
|
|
383
416
|
}
|
|
417
|
+
case 'llmChatOutputSnapshot': {
|
|
418
|
+
const { data } = event;
|
|
419
|
+
emitReplayExecutionEvent('llmChatOutputSnapshot', {
|
|
420
|
+
...data,
|
|
421
|
+
execution: getExecution(data.execution?.graphId ?? getGraphIdForNode(data.nodeId), data.execution),
|
|
422
|
+
});
|
|
423
|
+
break;
|
|
424
|
+
}
|
|
425
|
+
case 'llmProfileAttempt': {
|
|
426
|
+
const { data } = event;
|
|
427
|
+
emitReplayExecutionEvent('llmProfileAttempt', {
|
|
428
|
+
...data,
|
|
429
|
+
execution: getExecution(data.execution?.graphId ?? getGraphIdForNode(data.nodeId), data.execution),
|
|
430
|
+
});
|
|
431
|
+
break;
|
|
432
|
+
}
|
|
384
433
|
case 'toolCallFinished': {
|
|
385
434
|
const { data } = event;
|
|
386
435
|
emitReplayExecutionEvent('toolCallFinished', {
|
|
@@ -434,7 +483,11 @@ export async function replayExecutionRecording(options) {
|
|
|
434
483
|
// normal root-level `error` event is intentionally unscoped, so Run
|
|
435
484
|
// Activity has no active root to attach it to in that case.
|
|
436
485
|
emitFallbackRootTerminal('error', { error: replayError });
|
|
437
|
-
|
|
486
|
+
// This is a fresh playback failure, not a historical event from the last
|
|
487
|
+
// successful dispatch. Do not accidentally attribute it to that event's
|
|
488
|
+
// recording timestamp.
|
|
489
|
+
currentReplayRecordedAt = undefined;
|
|
490
|
+
emitReplayTerminalEvent('error', { error: replayError });
|
|
438
491
|
}
|
|
439
492
|
finally {
|
|
440
493
|
setRunning(false);
|
|
@@ -30,6 +30,8 @@ export function wireSubprocessorEvents(processor, parentEmitter, parentState) {
|
|
|
30
30
|
processor.on('partialOutput', (event) => parentEmitter.emit('partialOutput', event)),
|
|
31
31
|
processor.on('progress', (event) => parentEmitter.emit('progress', event)),
|
|
32
32
|
processor.on('llmCallFinished', (event) => parentEmitter.emit('llmCallFinished', event)),
|
|
33
|
+
processor.on('llmChatOutputSnapshot', (event) => parentEmitter.emit('llmChatOutputSnapshot', event)),
|
|
34
|
+
processor.on('llmProfileAttempt', (event) => parentEmitter.emit('llmProfileAttempt', event)),
|
|
33
35
|
processor.on('toolCallFinished', (event) => parentEmitter.emit('toolCallFinished', event)),
|
|
34
36
|
processor.on('nodeExcluded', (event) => parentEmitter.emit('nodeExcluded', event)),
|
|
35
37
|
processor.on('nodeStart', (event) => parentEmitter.emit('nodeStart', event)),
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
import { normalizeGraphProgress } from './GraphProgress.js';
|
|
2
2
|
import { isAgentResponseTrace } from './AgentResponseTrace.js';
|
|
3
|
+
import { RIVET_WEB_APP_BROWSER_STORAGE_DEFAULT_TRANSFER_TIMEOUT_MS, parseRivetWebAppBrowserStorageClientMessage, parseRivetWebAppBrowserStorageServerMessage, } from './WebAppBrowserStorageRpc.js';
|
|
3
4
|
export const RIVET_WEB_APP_ACTION_PROTOCOL_VERSION = 1;
|
|
4
5
|
export function parseRivetWebAppClientMessage(value) {
|
|
5
6
|
if (!isRecord(value) || typeof value.type !== 'string')
|
|
6
7
|
return undefined;
|
|
8
|
+
const storageMessage = parseRivetWebAppBrowserStorageClientMessage(value);
|
|
9
|
+
if (storageMessage)
|
|
10
|
+
return storageMessage;
|
|
7
11
|
switch (value.type) {
|
|
8
12
|
case 'client.hello':
|
|
9
13
|
return value.protocolVersion === RIVET_WEB_APP_ACTION_PROTOCOL_VERSION
|
|
10
|
-
? {
|
|
14
|
+
? {
|
|
15
|
+
type: value.type,
|
|
16
|
+
protocolVersion: value.protocolVersion,
|
|
17
|
+
...(isStringArray(value.capabilities) ? { capabilities: value.capabilities } : {}),
|
|
18
|
+
}
|
|
11
19
|
: undefined;
|
|
12
20
|
case 'action.start':
|
|
13
21
|
return isNonEmptyString(value.requestId) &&
|
|
@@ -22,6 +30,7 @@ export function parseRivetWebAppClientMessage(value) {
|
|
|
22
30
|
state: value.state,
|
|
23
31
|
...(isRecord(value.storage) ? { storage: value.storage } : {}),
|
|
24
32
|
...(typeof value.revisionKey === 'string' ? { revisionKey: value.revisionKey } : {}),
|
|
33
|
+
...(value.storageRpcVersion === 2 ? { storageRpcVersion: 2 } : {}),
|
|
25
34
|
}
|
|
26
35
|
: undefined;
|
|
27
36
|
case 'action.cancel':
|
|
@@ -40,10 +49,21 @@ export function parseRivetWebAppClientMessage(value) {
|
|
|
40
49
|
export function parseRivetWebAppServerMessage(value) {
|
|
41
50
|
if (!isRecord(value) || typeof value.type !== 'string')
|
|
42
51
|
return undefined;
|
|
52
|
+
const storageMessage = parseRivetWebAppBrowserStorageServerMessage(value);
|
|
53
|
+
if (storageMessage)
|
|
54
|
+
return storageMessage;
|
|
43
55
|
if (value.type === 'server.ready') {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
56
|
+
if (value.protocolVersion !== RIVET_WEB_APP_ACTION_PROTOCOL_VERSION)
|
|
57
|
+
return undefined;
|
|
58
|
+
const browserStorageRpcLimits = parseBrowserStorageRpcLimits(value.browserStorageRpcLimits);
|
|
59
|
+
if (value.browserStorageRpcLimits != null && !browserStorageRpcLimits)
|
|
60
|
+
return undefined;
|
|
61
|
+
return {
|
|
62
|
+
type: value.type,
|
|
63
|
+
protocolVersion: value.protocolVersion,
|
|
64
|
+
...(isStringArray(value.capabilities) ? { capabilities: value.capabilities } : {}),
|
|
65
|
+
...(browserStorageRpcLimits ? { browserStorageRpcLimits } : {}),
|
|
66
|
+
};
|
|
47
67
|
}
|
|
48
68
|
if (value.type === 'server.draining')
|
|
49
69
|
return { type: value.type };
|
|
@@ -104,6 +124,7 @@ export function parseRivetWebAppServerMessage(value) {
|
|
|
104
124
|
...base,
|
|
105
125
|
error: value.error,
|
|
106
126
|
...(typeof value.code === 'string' ? { code: value.code } : {}),
|
|
127
|
+
...(isAgentResponseTrace(value.responseTrace) ? { responseTrace: value.responseTrace } : {}),
|
|
107
128
|
}
|
|
108
129
|
: undefined;
|
|
109
130
|
case 'action.interrupted':
|
|
@@ -128,6 +149,28 @@ function hasRunEventBase(value) {
|
|
|
128
149
|
function isRecord(value) {
|
|
129
150
|
return typeof value === 'object' && value != null && !Array.isArray(value);
|
|
130
151
|
}
|
|
152
|
+
function parseBrowserStorageRpcLimits(value) {
|
|
153
|
+
if (!isRecord(value))
|
|
154
|
+
return undefined;
|
|
155
|
+
if (!isPositiveSafeInteger(value.maxActionBytes) ||
|
|
156
|
+
!isPositiveSafeInteger(value.maxValueBytes) ||
|
|
157
|
+
value.maxValueBytes > value.maxActionBytes) {
|
|
158
|
+
return undefined;
|
|
159
|
+
}
|
|
160
|
+
if (value.transferTimeoutMs != null && !isPositiveSafeInteger(value.transferTimeoutMs))
|
|
161
|
+
return undefined;
|
|
162
|
+
return {
|
|
163
|
+
maxActionBytes: value.maxActionBytes,
|
|
164
|
+
maxValueBytes: value.maxValueBytes,
|
|
165
|
+
transferTimeoutMs: value.transferTimeoutMs ?? RIVET_WEB_APP_BROWSER_STORAGE_DEFAULT_TRANSFER_TIMEOUT_MS,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
function isPositiveSafeInteger(value) {
|
|
169
|
+
return typeof value === 'number' && Number.isSafeInteger(value) && value > 0;
|
|
170
|
+
}
|
|
131
171
|
function isNonEmptyString(value) {
|
|
132
172
|
return typeof value === 'string' && value.length > 0;
|
|
133
173
|
}
|
|
174
|
+
function isStringArray(value) {
|
|
175
|
+
return (Array.isArray(value) && value.length <= 16 && value.every((item) => typeof item === 'string' && item.length <= 100));
|
|
176
|
+
}
|