@valerypopoff/rivet2-core 2.5.0 → 2.6.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 +370 -84
- package/dist/cjs/bundle.cjs.map +3 -3
- package/dist/cjs/webAppRuntime.cjs.map +2 -2
- package/dist/esm/model/AgentResponseTrace.js +8 -3
- package/dist/esm/model/GraphProcessor.js +41 -6
- package/dist/esm/model/ProcessContextBuilder.js +2 -1
- package/dist/esm/model/RecordingPlayer.js +37 -10
- package/dist/esm/model/SplitRunProcessor.js +37 -16
- package/dist/esm/model/UiGraphRendererStyles.js +20 -0
- package/dist/esm/model/chat/aiSdkStreaming.js +3 -2
- package/dist/esm/model/chat-v2/aiSdkBridge.js +63 -5
- package/dist/esm/model/chat-v2/chatV2Pipeline.js +66 -3
- package/dist/esm/model/chat-v2/llmInvocationResultProjector.js +20 -7
- package/dist/esm/model/chat-v2/llmProfileFallback.js +12 -4
- package/dist/esm/model/nodes/LLMChatV2Node.js +30 -4
- package/dist/esm/recording/ExecutionRecorder.js +55 -23
- package/dist/types/model/AgentResponseTrace.d.ts +2 -0
- package/dist/types/model/ExecutorProtocol.d.ts +4 -0
- package/dist/types/model/GraphProcessor.d.ts +8 -0
- package/dist/types/model/ProcessContext.d.ts +6 -0
- package/dist/types/model/ProcessContextBuilder.d.ts +2 -1
- package/dist/types/model/SplitRunProcessor.d.ts +2 -1
- package/dist/types/model/UiGraphRendererStyles.d.ts +1 -1
- package/dist/types/model/chat/aiSdkStreaming.d.ts +1 -1
- package/dist/types/model/chat-v2/chatV2RequestPlan.d.ts +1 -1
- package/dist/types/model/chat-v2/chatV2Types.d.ts +29 -0
- package/dist/types/model/chat-v2/llmInvocationResultProjector.d.ts +5 -1
- package/dist/types/recording/ExecutionRecorder.d.ts +6 -1
- package/dist/types/recording/RecordedEvents.d.ts +2 -0
- package/package.json +1 -1
package/dist/cjs/bundle.cjs
CHANGED
|
@@ -6860,7 +6860,7 @@ function withReplayRecordedAt(data, replayRecordedAt) {
|
|
|
6860
6860
|
}
|
|
6861
6861
|
return { ...data, replayRecordedAt };
|
|
6862
6862
|
}
|
|
6863
|
-
var
|
|
6863
|
+
var REPLAY_TIMED_EVENTS = /* @__PURE__ */ new Set([
|
|
6864
6864
|
"start",
|
|
6865
6865
|
"graphStart",
|
|
6866
6866
|
"graphOutputsReady",
|
|
@@ -6874,7 +6874,13 @@ var REPLAY_TIMED_LIFECYCLE_EVENTS = /* @__PURE__ */ new Set([
|
|
|
6874
6874
|
"nodeFinish",
|
|
6875
6875
|
"nodeError",
|
|
6876
6876
|
"nodeExcluded",
|
|
6877
|
-
"nodeOutputsCleared"
|
|
6877
|
+
"nodeOutputsCleared",
|
|
6878
|
+
// These records retain their own physical call timestamps, but the replay
|
|
6879
|
+
// timestamp lets observers keep them on the same historical recording
|
|
6880
|
+
// timeline without borrowing a provider timestamp as a node lifecycle time.
|
|
6881
|
+
"llmCallFinished",
|
|
6882
|
+
"llmProfileAttempt",
|
|
6883
|
+
"toolCallFinished"
|
|
6878
6884
|
]);
|
|
6879
6885
|
async function replayExecutionRecording(options2) {
|
|
6880
6886
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
@@ -6914,7 +6920,7 @@ async function replayExecutionRecording(options2) {
|
|
|
6914
6920
|
};
|
|
6915
6921
|
const emitReplayExecutionEvent = (event, data) => {
|
|
6916
6922
|
hasEmittedRunActivityExecution = true;
|
|
6917
|
-
const payload =
|
|
6923
|
+
const payload = REPLAY_TIMED_EVENTS.has(event) ? withReplayRecordedAt(data, currentReplayRecordedAt) : data;
|
|
6918
6924
|
emitDetached(emitter, event, payload);
|
|
6919
6925
|
};
|
|
6920
6926
|
const emitReplayTerminalEvent = (event, data) => {
|
|
@@ -7030,11 +7036,14 @@ async function replayExecutionRecording(options2) {
|
|
|
7030
7036
|
};
|
|
7031
7037
|
const getNodeRunKey = (execution, nodeId, processId) => `${execution.rootRunId}:${execution.graphRunId}:${nodeId}:${processId}`;
|
|
7032
7038
|
const getRecordedDuration = (recordedDuration, execution, nodeId, processId, terminalTs) => {
|
|
7033
|
-
if (recordedDuration
|
|
7039
|
+
if (isValidRecordedDuration(recordedDuration)) {
|
|
7034
7040
|
return recordedDuration;
|
|
7035
7041
|
}
|
|
7036
7042
|
const startedAt = nodeStartTimestamps.get(getNodeRunKey(execution, nodeId, processId));
|
|
7037
|
-
|
|
7043
|
+
if (!isValidRecordedTimestamp(startedAt) || !isValidRecordedTimestamp(terminalTs) || terminalTs < startedAt) {
|
|
7044
|
+
return void 0;
|
|
7045
|
+
}
|
|
7046
|
+
return terminalTs - startedAt;
|
|
7038
7047
|
};
|
|
7039
7048
|
for (const event of recorder.events) {
|
|
7040
7049
|
if (isAborted()) {
|
|
@@ -7071,7 +7080,7 @@ async function replayExecutionRecording(options2) {
|
|
|
7071
7080
|
}
|
|
7072
7081
|
case "done": {
|
|
7073
7082
|
emitFallbackRootTerminal("completed", { outputs: event.data.results });
|
|
7074
|
-
|
|
7083
|
+
await emitter.emit("done", withReplayRecordedAt(event.data, currentReplayRecordedAt));
|
|
7075
7084
|
graphOutputs = event.data.results;
|
|
7076
7085
|
setGraphOutputs(graphOutputs);
|
|
7077
7086
|
break;
|
|
@@ -7198,6 +7207,8 @@ async function replayExecutionRecording(options2) {
|
|
|
7198
7207
|
node,
|
|
7199
7208
|
error: data.error,
|
|
7200
7209
|
processId: data.processId,
|
|
7210
|
+
...data.outputs === void 0 ? {} : { outputs: data.outputs },
|
|
7211
|
+
...data.splitOutputs === void 0 ? {} : { splitOutputs: data.splitOutputs },
|
|
7201
7212
|
...data.resultOrigin === void 0 ? {} : { resultOrigin: data.resultOrigin },
|
|
7202
7213
|
execution
|
|
7203
7214
|
},
|
|
@@ -7314,7 +7325,6 @@ async function replayExecutionRecording(options2) {
|
|
|
7314
7325
|
break;
|
|
7315
7326
|
}
|
|
7316
7327
|
case "finish": {
|
|
7317
|
-
emitDetached(emitter, "finish", void 0);
|
|
7318
7328
|
break;
|
|
7319
7329
|
}
|
|
7320
7330
|
default: {
|
|
@@ -7343,9 +7353,16 @@ async function replayExecutionRecording(options2) {
|
|
|
7343
7353
|
emitReplayTerminalEvent("error", { error: replayError });
|
|
7344
7354
|
} finally {
|
|
7345
7355
|
setRunning(false);
|
|
7356
|
+
emitDetached(emitter, "finish", void 0);
|
|
7346
7357
|
}
|
|
7347
7358
|
return graphOutputs;
|
|
7348
7359
|
}
|
|
7360
|
+
function isValidRecordedTimestamp(value) {
|
|
7361
|
+
return value != null && Number.isFinite(value) && value >= 0;
|
|
7362
|
+
}
|
|
7363
|
+
function isValidRecordedDuration(value) {
|
|
7364
|
+
return value != null && Number.isFinite(value) && value >= 0;
|
|
7365
|
+
}
|
|
7349
7366
|
|
|
7350
7367
|
// src/model/loopControllerBreak.ts
|
|
7351
7368
|
var LOOP_NOT_BROKEN_SENTINEL = "loop-not-broken";
|
|
@@ -7368,6 +7385,7 @@ function buildNodeProcessContext(options2) {
|
|
|
7368
7385
|
node,
|
|
7369
7386
|
nodeAbortController,
|
|
7370
7387
|
onPartialOutputs,
|
|
7388
|
+
setFailureOutputs,
|
|
7371
7389
|
processId,
|
|
7372
7390
|
requestUserInput,
|
|
7373
7391
|
reportProgress,
|
|
@@ -7389,6 +7407,7 @@ function buildNodeProcessContext(options2) {
|
|
|
7389
7407
|
waitForStoredValue: (key, signal = nodeAbortController.signal) => base.waitForStoredValue(key, signal),
|
|
7390
7408
|
externalFunctions: { ...externalFunctions },
|
|
7391
7409
|
onPartialOutputs,
|
|
7410
|
+
setFailureOutputs,
|
|
7392
7411
|
signal: nodeAbortController.signal,
|
|
7393
7412
|
processId,
|
|
7394
7413
|
splitIndex,
|
|
@@ -7504,15 +7523,13 @@ async function processSplitRunNode(node, processId, deps) {
|
|
|
7504
7523
|
resultOrigin: "executed"
|
|
7505
7524
|
});
|
|
7506
7525
|
const timingStart = (_a = deps.startNodeTiming) == null ? void 0 : _a.call(deps);
|
|
7507
|
-
|
|
7508
|
-
let results = [];
|
|
7526
|
+
const results = [];
|
|
7509
7527
|
try {
|
|
7510
7528
|
if (node.isSplitSequential) {
|
|
7511
|
-
|
|
7529
|
+
await runSequential(node, inputValues, inputDefinitionsById, splittingAmount, processId, deps, results);
|
|
7512
7530
|
} else {
|
|
7513
|
-
results
|
|
7531
|
+
results.push(...await runParallel(node, inputValues, inputDefinitionsById, splittingAmount, processId, deps));
|
|
7514
7532
|
}
|
|
7515
|
-
splitRunDurationMs = getSplitRunDurationMs(results);
|
|
7516
7533
|
const errors = results.filter((r) => r.type === "error").map((r) => r.error);
|
|
7517
7534
|
if (errors.length === 1) {
|
|
7518
7535
|
throw errors[0];
|
|
@@ -7522,7 +7539,7 @@ async function processSplitRunNode(node, processId, deps) {
|
|
|
7522
7539
|
}
|
|
7523
7540
|
throw new AggregateError(errors);
|
|
7524
7541
|
}
|
|
7525
|
-
const aggregateResults = aggregateOutputs(results);
|
|
7542
|
+
const aggregateResults = aggregateOutputs(results.filter(isSplitOutputResult));
|
|
7526
7543
|
deps.setNodeResults(node.id, aggregateResults);
|
|
7527
7544
|
deps.markNodeVisited(node.id);
|
|
7528
7545
|
await deps.emit(
|
|
@@ -7535,7 +7552,7 @@ async function processSplitRunNode(node, processId, deps) {
|
|
|
7535
7552
|
resultOrigin: getSplitRunResultOrigin(results)
|
|
7536
7553
|
},
|
|
7537
7554
|
(_b = deps.finishNodeTiming) == null ? void 0 : _b.call(deps, timingStart),
|
|
7538
|
-
|
|
7555
|
+
getSplitRunDurationMs(results)
|
|
7539
7556
|
)
|
|
7540
7557
|
);
|
|
7541
7558
|
} catch (error) {
|
|
@@ -7544,14 +7561,14 @@ async function processSplitRunNode(node, processId, deps) {
|
|
|
7544
7561
|
error,
|
|
7545
7562
|
processId,
|
|
7546
7563
|
(_c = deps.finishNodeTiming) == null ? void 0 : _c.call(deps, timingStart),
|
|
7547
|
-
|
|
7548
|
-
getSplitRunResultOrigin(results)
|
|
7564
|
+
getSplitRunDurationMs(results),
|
|
7565
|
+
getSplitRunResultOrigin(results),
|
|
7566
|
+
getSplitTerminalOutputs(results)
|
|
7549
7567
|
);
|
|
7550
7568
|
}
|
|
7551
7569
|
}
|
|
7552
|
-
async function runSequential(node, inputValues, inputDefinitionsById, splittingAmount, processId, deps) {
|
|
7570
|
+
async function runSequential(node, inputValues, inputDefinitionsById, splittingAmount, processId, deps, results) {
|
|
7553
7571
|
var _a, _b, _c;
|
|
7554
|
-
const results = [];
|
|
7555
7572
|
for (let i = 0; i < splittingAmount; i++) {
|
|
7556
7573
|
if (deps.isAborted()) {
|
|
7557
7574
|
throw deps.getAbortError();
|
|
@@ -7579,17 +7596,18 @@ async function runSequential(node, inputValues, inputDefinitionsById, splittingA
|
|
|
7579
7596
|
}
|
|
7580
7597
|
);
|
|
7581
7598
|
deps.accumulateCost(output);
|
|
7582
|
-
results.push({ type: "output", output, resultOrigin, durationMs: (_b = deps.finishNodeTiming) == null ? void 0 : _b.call(deps, splitTimingStart) });
|
|
7599
|
+
results.push({ type: "output", index: i, output, resultOrigin, durationMs: (_b = deps.finishNodeTiming) == null ? void 0 : _b.call(deps, splitTimingStart) });
|
|
7583
7600
|
} catch (error) {
|
|
7584
7601
|
results.push({
|
|
7585
7602
|
type: "error",
|
|
7586
7603
|
error: getError(error),
|
|
7604
|
+
index: i,
|
|
7587
7605
|
resultOrigin,
|
|
7588
|
-
durationMs: (_c = deps.finishNodeTiming) == null ? void 0 : _c.call(deps, splitTimingStart)
|
|
7606
|
+
durationMs: (_c = deps.finishNodeTiming) == null ? void 0 : _c.call(deps, splitTimingStart),
|
|
7607
|
+
failureOutputs: deps.takeFailureOutputs(processId, i)
|
|
7589
7608
|
});
|
|
7590
7609
|
}
|
|
7591
7610
|
}
|
|
7592
|
-
return results;
|
|
7593
7611
|
}
|
|
7594
7612
|
async function runParallel(node, inputValues, inputDefinitionsById, splittingAmount, processId, deps) {
|
|
7595
7613
|
const queue = new pQueueCompat_default({ concurrency: getParallelSplitRunConcurrency(node, deps.splitRunConcurrency) });
|
|
@@ -7597,12 +7615,13 @@ async function runParallel(node, inputValues, inputDefinitionsById, splittingAmo
|
|
|
7597
7615
|
(0, import_lodash_es3.range)(0, splittingAmount).map(async (i) => {
|
|
7598
7616
|
const result = await queue.add(async () => {
|
|
7599
7617
|
var _a, _b, _c;
|
|
7600
|
-
const splitTimingStart = (_a = deps.startNodeTiming) == null ? void 0 : _a.call(deps);
|
|
7601
7618
|
let resultOrigin = "executed";
|
|
7619
|
+
let splitTimingStart;
|
|
7602
7620
|
try {
|
|
7603
7621
|
if (deps.isAborted()) {
|
|
7604
7622
|
throw deps.getAbortError();
|
|
7605
7623
|
}
|
|
7624
|
+
splitTimingStart = (_a = deps.startNodeTiming) == null ? void 0 : _a.call(deps);
|
|
7606
7625
|
const inputs = splitInputsAtIndex(inputValues, inputDefinitionsById, i);
|
|
7607
7626
|
const output = await deps.processNodeWithInputData(
|
|
7608
7627
|
node,
|
|
@@ -7625,6 +7644,7 @@ async function runParallel(node, inputValues, inputDefinitionsById, splittingAmo
|
|
|
7625
7644
|
deps.accumulateCost(output);
|
|
7626
7645
|
return {
|
|
7627
7646
|
type: "output",
|
|
7647
|
+
index: i,
|
|
7628
7648
|
output,
|
|
7629
7649
|
resultOrigin,
|
|
7630
7650
|
durationMs: (_b = deps.finishNodeTiming) == null ? void 0 : _b.call(deps, splitTimingStart)
|
|
@@ -7633,8 +7653,10 @@ async function runParallel(node, inputValues, inputDefinitionsById, splittingAmo
|
|
|
7633
7653
|
return {
|
|
7634
7654
|
type: "error",
|
|
7635
7655
|
error: getError(error),
|
|
7656
|
+
index: i,
|
|
7636
7657
|
resultOrigin,
|
|
7637
|
-
durationMs: (_c = deps.finishNodeTiming) == null ? void 0 : _c.call(deps, splitTimingStart)
|
|
7658
|
+
durationMs: splitTimingStart === void 0 ? void 0 : (_c = deps.finishNodeTiming) == null ? void 0 : _c.call(deps, splitTimingStart),
|
|
7659
|
+
failureOutputs: deps.takeFailureOutputs(processId, i)
|
|
7638
7660
|
};
|
|
7639
7661
|
}
|
|
7640
7662
|
});
|
|
@@ -7648,6 +7670,14 @@ async function runParallel(node, inputValues, inputDefinitionsById, splittingAmo
|
|
|
7648
7670
|
function getSplitRunResultOrigin(results) {
|
|
7649
7671
|
return results.length > 0 && results.every((result) => result.resultOrigin === "editor-cache") ? "editor-cache" : "executed";
|
|
7650
7672
|
}
|
|
7673
|
+
function getSplitTerminalOutputs(results) {
|
|
7674
|
+
const outputs = Object.fromEntries(
|
|
7675
|
+
results.flatMap(
|
|
7676
|
+
(result) => result.type === "output" ? [[result.index, result.output]] : result.failureOutputs !== void 0 ? [[result.index, result.failureOutputs]] : []
|
|
7677
|
+
)
|
|
7678
|
+
);
|
|
7679
|
+
return Object.keys(outputs).length === 0 ? void 0 : outputs;
|
|
7680
|
+
}
|
|
7651
7681
|
function getParallelSplitRunConcurrency(node, defaultConcurrency) {
|
|
7652
7682
|
const value = node.splitRunConcurrency;
|
|
7653
7683
|
return typeof value === "number" && Number.isFinite(value) && value >= 2 ? Math.floor(value) : defaultConcurrency;
|
|
@@ -7672,11 +7702,14 @@ function aggregateOutputs(results) {
|
|
|
7672
7702
|
return acc;
|
|
7673
7703
|
}, {});
|
|
7674
7704
|
}
|
|
7705
|
+
function isSplitOutputResult(result) {
|
|
7706
|
+
return result.type === "output";
|
|
7707
|
+
}
|
|
7675
7708
|
function getSplitRunDurationMs(results) {
|
|
7676
7709
|
const durations = {};
|
|
7677
|
-
for (const
|
|
7710
|
+
for (const result of results) {
|
|
7678
7711
|
if (result.durationMs !== void 0) {
|
|
7679
|
-
durations[index] = result.durationMs;
|
|
7712
|
+
durations[result.index] = result.durationMs;
|
|
7680
7713
|
}
|
|
7681
7714
|
}
|
|
7682
7715
|
return Object.keys(durations).length > 0 ? durations : void 0;
|
|
@@ -10205,6 +10238,7 @@ var GraphProcessor = class _GraphProcessor {
|
|
|
10205
10238
|
// Per-process state
|
|
10206
10239
|
#erroredNodes = void 0;
|
|
10207
10240
|
// Values are strings in recordings
|
|
10241
|
+
#failureOutputsByProcessId = void 0;
|
|
10208
10242
|
#remainingNodes = void 0;
|
|
10209
10243
|
#visitedNodes = void 0;
|
|
10210
10244
|
#currentlyProcessing = void 0;
|
|
@@ -10645,6 +10679,7 @@ var GraphProcessor = class _GraphProcessor {
|
|
|
10645
10679
|
this.#visitedNodes = new Set(this.#preloadedNodeResults.keys());
|
|
10646
10680
|
this.#hasPreloadedData = this.#preloadedNodeResults.size > 0;
|
|
10647
10681
|
this.#erroredNodes = /* @__PURE__ */ new Map();
|
|
10682
|
+
this.#failureOutputsByProcessId = /* @__PURE__ */ new Map();
|
|
10648
10683
|
this.#currentlyProcessing = /* @__PURE__ */ new Set();
|
|
10649
10684
|
this.#remainingNodes = new Set(((_a = this.#seededExecutionPlanForNextRun()) == null ? void 0 : _a.nodeIds) ?? []);
|
|
10650
10685
|
this.#pendingUserInputs = {};
|
|
@@ -11139,7 +11174,6 @@ ${errors.map(({ node }) => `- ${node.title} (${node.id})`).join("\n")}`;
|
|
|
11139
11174
|
}
|
|
11140
11175
|
async #finalizeGraphRun() {
|
|
11141
11176
|
const outputValues = this.#graphOutputs;
|
|
11142
|
-
this.#lifecycle.complete();
|
|
11143
11177
|
if (this.#suppressGraphLifecycleEvents) {
|
|
11144
11178
|
return outputValues;
|
|
11145
11179
|
}
|
|
@@ -11147,7 +11181,6 @@ ${errors.map(({ node }) => `- ${node.title} (${node.id})`).join("\n")}`;
|
|
|
11147
11181
|
await this.#emitter.emit("graphFinish", this.#withExecution({ graph: this.#graph, outputs: outputValues }));
|
|
11148
11182
|
if (!this.#isSubProcessor) {
|
|
11149
11183
|
await this.#emitter.emit("done", { results: outputValues });
|
|
11150
|
-
await this.#emitFinishIfNeeded();
|
|
11151
11184
|
}
|
|
11152
11185
|
return outputValues;
|
|
11153
11186
|
}
|
|
@@ -11709,7 +11742,8 @@ ${errors.map(({ node }) => `- ${node.title} (${node.id})`).join("\n")}`;
|
|
|
11709
11742
|
accumulateCost: (output) => this.#accumulateCost(output),
|
|
11710
11743
|
setNodeResults: (nodeId, outputs) => this.#nodeResults.set(nodeId, outputs),
|
|
11711
11744
|
markNodeVisited: (nodeId) => this.#visitedNodes.add(nodeId),
|
|
11712
|
-
nodeErrored: (n, err, pid, durationMs, splitRunDurationMs, resultOrigin) => this.#nodeErrored(n, err, pid, durationMs, splitRunDurationMs, resultOrigin),
|
|
11745
|
+
nodeErrored: (n, err, pid, durationMs, splitRunDurationMs, resultOrigin, splitOutputs) => this.#nodeErrored(n, err, pid, durationMs, splitRunDurationMs, resultOrigin, void 0, splitOutputs),
|
|
11746
|
+
takeFailureOutputs: (pid, index) => this.#takeFailureOutputs(pid, index),
|
|
11713
11747
|
isAborted: () => this.#lifecycle.isAborted,
|
|
11714
11748
|
getAbortError: () => createGraphAbortErrorFromSignal(this.#abortController.signal),
|
|
11715
11749
|
emit: (event, data) => {
|
|
@@ -11822,11 +11856,20 @@ ${errors.map(({ node }) => `- ${node.title} (${node.id})`).join("\n")}`;
|
|
|
11822
11856
|
)
|
|
11823
11857
|
);
|
|
11824
11858
|
} catch (error) {
|
|
11825
|
-
await this.#nodeErrored(
|
|
11859
|
+
await this.#nodeErrored(
|
|
11860
|
+
node,
|
|
11861
|
+
error,
|
|
11862
|
+
processId,
|
|
11863
|
+
this.#finishNodeTiming(timingStart),
|
|
11864
|
+
void 0,
|
|
11865
|
+
resultOrigin,
|
|
11866
|
+
this.#takeFailureOutputs(processId, 0)
|
|
11867
|
+
);
|
|
11826
11868
|
}
|
|
11827
11869
|
}
|
|
11828
|
-
async #nodeErrored(node, e, processId, durationMs, splitRunDurationMs, resultOrigin = "executed") {
|
|
11870
|
+
async #nodeErrored(node, e, processId, durationMs, splitRunDurationMs, resultOrigin = "executed", outputs, splitOutputs) {
|
|
11829
11871
|
const error = getError(e);
|
|
11872
|
+
const retainedOutputs = splitOutputs === void 0 ? outputs ?? this.#takeFailureOutputs(processId, 0) : outputs;
|
|
11830
11873
|
const exclusionReason = this.#getErrorExclusionReason(node, error, processId);
|
|
11831
11874
|
if (exclusionReason) {
|
|
11832
11875
|
await this.#emitNodeExcluded(node, processId, this.#getInputValuesForNode(node), exclusionReason, resultOrigin);
|
|
@@ -11837,7 +11880,18 @@ ${errors.map(({ node }) => `- ${node.title} (${node.id})`).join("\n")}`;
|
|
|
11837
11880
|
await this.#emitter.emit(
|
|
11838
11881
|
"nodeError",
|
|
11839
11882
|
this.#withExecution(
|
|
11840
|
-
withOptionalDuration3(
|
|
11883
|
+
withOptionalDuration3(
|
|
11884
|
+
{
|
|
11885
|
+
node,
|
|
11886
|
+
error,
|
|
11887
|
+
processId,
|
|
11888
|
+
resultOrigin,
|
|
11889
|
+
...retainedOutputs === void 0 ? {} : { outputs: retainedOutputs },
|
|
11890
|
+
...splitOutputs === void 0 ? {} : { splitOutputs }
|
|
11891
|
+
},
|
|
11892
|
+
durationMs,
|
|
11893
|
+
splitRunDurationMs
|
|
11894
|
+
)
|
|
11841
11895
|
)
|
|
11842
11896
|
);
|
|
11843
11897
|
this.#emitTraceEvent(`Node ${node.title} (${node.id}-${processId}) errored: ${error.stack}`);
|
|
@@ -11849,6 +11903,26 @@ ${errors.map(({ node }) => `- ${node.title} (${node.id})`).join("\n")}`;
|
|
|
11849
11903
|
this.#withExecution({ node, outputs, index, processId, resultOrigin: "executed" })
|
|
11850
11904
|
);
|
|
11851
11905
|
}
|
|
11906
|
+
#setFailureOutputs(processId, index, outputs) {
|
|
11907
|
+
let outputsByIndex = this.#failureOutputsByProcessId.get(processId);
|
|
11908
|
+
if (!outputsByIndex) {
|
|
11909
|
+
outputsByIndex = /* @__PURE__ */ new Map();
|
|
11910
|
+
this.#failureOutputsByProcessId.set(processId, outputsByIndex);
|
|
11911
|
+
}
|
|
11912
|
+
outputsByIndex.set(index, outputs);
|
|
11913
|
+
}
|
|
11914
|
+
#takeFailureOutputs(processId, index) {
|
|
11915
|
+
const outputsByIndex = this.#failureOutputsByProcessId.get(processId);
|
|
11916
|
+
const outputs = outputsByIndex == null ? void 0 : outputsByIndex.get(index);
|
|
11917
|
+
outputsByIndex == null ? void 0 : outputsByIndex.delete(index);
|
|
11918
|
+
if ((outputsByIndex == null ? void 0 : outputsByIndex.size) === 0) {
|
|
11919
|
+
this.#failureOutputsByProcessId.delete(processId);
|
|
11920
|
+
}
|
|
11921
|
+
return outputs;
|
|
11922
|
+
}
|
|
11923
|
+
#discardFailureOutputs(processId, index) {
|
|
11924
|
+
this.#takeFailureOutputs(processId, index);
|
|
11925
|
+
}
|
|
11852
11926
|
#getErrorExclusionReason(node, error, processId) {
|
|
11853
11927
|
var _a;
|
|
11854
11928
|
if ((_a = this.#getAttachedDataTo(node).races) == null ? void 0 : _a.completed) {
|
|
@@ -11991,6 +12065,7 @@ ${errors.map(({ node }) => `- ${node.title} (${node.id})`).join("\n")}`;
|
|
|
11991
12065
|
if (nodeAbortController.signal.aborted) {
|
|
11992
12066
|
if (isSuccessfulNonRaceGraphAbortReason(abortReason)) {
|
|
11993
12067
|
this.#successfulAbortTerminalProcessIds.add(processId);
|
|
12068
|
+
this.#discardFailureOutputs(processId, index);
|
|
11994
12069
|
return results;
|
|
11995
12070
|
} else {
|
|
11996
12071
|
throw createGraphAbortError(abortReason, "Aborted");
|
|
@@ -11998,6 +12073,7 @@ ${errors.map(({ node }) => `- ${node.title} (${node.id})`).join("\n")}`;
|
|
|
11998
12073
|
}
|
|
11999
12074
|
this.#finalizeToolCallContinuation(processId, index, results);
|
|
12000
12075
|
continuationFinalized = true;
|
|
12076
|
+
this.#discardFailureOutputs(processId, index);
|
|
12001
12077
|
return results;
|
|
12002
12078
|
} finally {
|
|
12003
12079
|
if (!continuationFinalized) {
|
|
@@ -12034,6 +12110,7 @@ ${errors.map(({ node }) => `- ${node.title} (${node.id})`).join("\n")}`;
|
|
|
12034
12110
|
partialOutput == null ? void 0 : partialOutput(node, partialOutputs, index);
|
|
12035
12111
|
this.#emitGraphPartialOutputIfNeeded(node, partialOutputs);
|
|
12036
12112
|
},
|
|
12113
|
+
setFailureOutputs: (outputs) => this.#setFailureOutputs(processId, index, outputs),
|
|
12037
12114
|
processId,
|
|
12038
12115
|
requestUserInput: async (inputStrings, renderingType) => this.#requestUserInput(node, inputStrings, inputValues, renderingType, processId, nodeAbortController.signal),
|
|
12039
12116
|
reportProgress: (progress) => {
|
|
@@ -14107,6 +14184,7 @@ function buildAgentResponseTrace(options2) {
|
|
|
14107
14184
|
).map(toToolCallTrace);
|
|
14108
14185
|
const summary = summarizeAgentCalls(allModelCalls, allProfileAttempts, allToolCalls);
|
|
14109
14186
|
const terminalAt = options2.responseReadyAt ?? options2.finishedAt;
|
|
14187
|
+
const durationMs = options2.scope === "llm-invocation" && isNonNegativeFiniteNumber(options2.invocationDurationMs) ? options2.invocationDurationMs : isNonNegativeFiniteNumber(options2.startedAt) && isNonNegativeFiniteNumber(terminalAt) && terminalAt >= options2.startedAt ? terminalAt - options2.startedAt : void 0;
|
|
14110
14188
|
return {
|
|
14111
14189
|
schemaVersion: AGENT_RESPONSE_TRACE_SCHEMA_VERSION,
|
|
14112
14190
|
traceId: options2.execution.rootRunId,
|
|
@@ -14119,7 +14197,7 @@ function buildAgentResponseTrace(options2) {
|
|
|
14119
14197
|
...options2.startedAt == null ? {} : { startedAt: options2.startedAt },
|
|
14120
14198
|
...options2.responseReadyAt == null ? {} : { responseReadyAt: options2.responseReadyAt },
|
|
14121
14199
|
...options2.finishedAt == null ? {} : { finishedAt: options2.finishedAt },
|
|
14122
|
-
...
|
|
14200
|
+
...durationMs === void 0 ? {} : { durationMs },
|
|
14123
14201
|
status: options2.status,
|
|
14124
14202
|
...options2.backgroundWorkPending == null ? {} : { backgroundWorkPending: options2.backgroundWorkPending },
|
|
14125
14203
|
summary,
|
|
@@ -15288,6 +15366,7 @@ var RIVET_WEB_APP_RENDERER_CSS = `
|
|
|
15288
15366
|
|
|
15289
15367
|
.rivet-web-app-chat-pins-button,
|
|
15290
15368
|
.rivet-web-app-chat-search-button,
|
|
15369
|
+
.rivet-web-app-chat-new-button,
|
|
15291
15370
|
.rivet-web-app-chat-menu-button,
|
|
15292
15371
|
.rivet-web-app-chat-search-close-button,
|
|
15293
15372
|
.rivet-web-app-chat-search-navigation-button {
|
|
@@ -15313,6 +15392,18 @@ var RIVET_WEB_APP_RENDERER_CSS = `
|
|
|
15313
15392
|
border-radius: 10px;
|
|
15314
15393
|
}
|
|
15315
15394
|
|
|
15395
|
+
.rivet-web-app-chat-new-button {
|
|
15396
|
+
min-height: 30px;
|
|
15397
|
+
padding: 0 9px;
|
|
15398
|
+
border: 1px solid var(--rivet-web-app-control-border);
|
|
15399
|
+
border-radius: 7px;
|
|
15400
|
+
background: var(--rivet-web-app-control-background);
|
|
15401
|
+
color: var(--rivet-web-app-foreground);
|
|
15402
|
+
font-size: 0.875em;
|
|
15403
|
+
line-height: 1;
|
|
15404
|
+
white-space: nowrap;
|
|
15405
|
+
}
|
|
15406
|
+
|
|
15316
15407
|
.rivet-web-app-chat-pins-button {
|
|
15317
15408
|
display: inline-flex;
|
|
15318
15409
|
align-items: center;
|
|
@@ -15358,6 +15449,13 @@ var RIVET_WEB_APP_RENDERER_CSS = `
|
|
|
15358
15449
|
outline: none;
|
|
15359
15450
|
}
|
|
15360
15451
|
|
|
15452
|
+
.rivet-web-app-chat-new-button:hover,
|
|
15453
|
+
.rivet-web-app-chat-new-button:focus-visible {
|
|
15454
|
+
background: var(--rivet-web-app-control-hover-background);
|
|
15455
|
+
color: var(--rivet-web-app-foreground);
|
|
15456
|
+
outline: none;
|
|
15457
|
+
}
|
|
15458
|
+
|
|
15361
15459
|
.rivet-web-app-chat-menu {
|
|
15362
15460
|
position: absolute;
|
|
15363
15461
|
top: calc(100% + 4px);
|
|
@@ -21067,11 +21165,12 @@ async function consumeAiSdkStream(fullStream, onPartialOutputs, options2 = {}) {
|
|
|
21067
21165
|
case "text-delta": {
|
|
21068
21166
|
textBlocks.set(part.id, `${textBlocks.get(part.id) ?? ""}${part.text}`);
|
|
21069
21167
|
responseText = buildResponseText(textBlocks, !!options2.dedupeDuplicateTextBlocks);
|
|
21070
|
-
onPartialOutputs(responseText, functionCalls);
|
|
21168
|
+
onPartialOutputs(responseText, functionCalls, reasoning);
|
|
21071
21169
|
break;
|
|
21072
21170
|
}
|
|
21073
21171
|
case "reasoning-delta": {
|
|
21074
21172
|
reasoning += part.text;
|
|
21173
|
+
onPartialOutputs(responseText, functionCalls, reasoning);
|
|
21075
21174
|
break;
|
|
21076
21175
|
}
|
|
21077
21176
|
case "tool-call": {
|
|
@@ -21082,7 +21181,7 @@ async function consumeAiSdkStream(fullStream, onPartialOutputs, options2 = {}) {
|
|
|
21082
21181
|
arguments: JSON.stringify(part.input),
|
|
21083
21182
|
lastParsedArguments: part.input
|
|
21084
21183
|
});
|
|
21085
|
-
onPartialOutputs(responseText, functionCalls);
|
|
21184
|
+
onPartialOutputs(responseText, functionCalls, reasoning);
|
|
21086
21185
|
break;
|
|
21087
21186
|
}
|
|
21088
21187
|
case "finish": {
|
|
@@ -21362,8 +21461,23 @@ async function resolveGenerateReasoning(result) {
|
|
|
21362
21461
|
}
|
|
21363
21462
|
return ((_a = await resolveOptionalValue(result.reasoning)) == null ? void 0 : _a.map((part) => part.text).join("")) ?? "";
|
|
21364
21463
|
}
|
|
21464
|
+
async function resolveGenerateUsage(result) {
|
|
21465
|
+
return await resolveOptionalValue(result.totalUsage) ?? await resolveOptionalValue(result.usage);
|
|
21466
|
+
}
|
|
21467
|
+
function notifyResponseReceived(options2, response) {
|
|
21468
|
+
var _a;
|
|
21469
|
+
try {
|
|
21470
|
+
(_a = options2.onResponseReceived) == null ? void 0 : _a.call(options2, response);
|
|
21471
|
+
} catch {
|
|
21472
|
+
}
|
|
21473
|
+
}
|
|
21365
21474
|
async function executeStream(options2, executor) {
|
|
21475
|
+
var _a;
|
|
21366
21476
|
const args = buildTextArgs(options2);
|
|
21477
|
+
try {
|
|
21478
|
+
(_a = options2.onRequestStarted) == null ? void 0 : _a.call(options2);
|
|
21479
|
+
} catch {
|
|
21480
|
+
}
|
|
21367
21481
|
const firstOutputStartedAt = Date.now();
|
|
21368
21482
|
const handlePromise = Promise.resolve(executor(args));
|
|
21369
21483
|
const handleTimeout = options2.firstOutputTimeoutMs == null ? void 0 : timeoutPromise(options2.firstOutputTimeoutMs, "first-output", options2.onTimeout);
|
|
@@ -21381,11 +21495,12 @@ async function executeStream(options2, executor) {
|
|
|
21381
21495
|
const isStructuredOutput = isChatV2StructuredResponseFormat(options2.responseFormat);
|
|
21382
21496
|
const streamed = await consumeAiSdkStream(
|
|
21383
21497
|
streamWithDeadlines(handle.fullStream, options2, firstOutputStartedAt),
|
|
21384
|
-
(text, functionCalls) => {
|
|
21385
|
-
var
|
|
21386
|
-
(
|
|
21498
|
+
(text, functionCalls, reasoning) => {
|
|
21499
|
+
var _a2;
|
|
21500
|
+
(_a2 = options2.onPartialOutput) == null ? void 0 : _a2.call(options2, {
|
|
21387
21501
|
text: isStructuredOutput ? collapseRepeatedStructuredJsonText(text) : text,
|
|
21388
|
-
functionCalls
|
|
21502
|
+
functionCalls,
|
|
21503
|
+
reasoning
|
|
21389
21504
|
});
|
|
21390
21505
|
},
|
|
21391
21506
|
{
|
|
@@ -21393,10 +21508,26 @@ async function executeStream(options2, executor) {
|
|
|
21393
21508
|
}
|
|
21394
21509
|
);
|
|
21395
21510
|
const responseText = isStructuredOutput ? collapseRepeatedStructuredJsonText(streamed.responseText) : streamed.responseText;
|
|
21511
|
+
const usagePromise = streamed.usage != null ? Promise.resolve(streamed.usage) : resolveOptionalValue(handle.usage);
|
|
21512
|
+
let evidence = {
|
|
21513
|
+
text: responseText,
|
|
21514
|
+
functionCalls: streamed.functionCalls,
|
|
21515
|
+
reasoning: streamed.reasoning,
|
|
21516
|
+
usage: streamed.usage
|
|
21517
|
+
};
|
|
21518
|
+
const notifyCurrentResponseEvidence = () => notifyResponseReceived(options2, evidence);
|
|
21519
|
+
notifyCurrentResponseEvidence();
|
|
21520
|
+
void usagePromise.then(
|
|
21521
|
+
(usage2) => {
|
|
21522
|
+
evidence = { ...evidence, usage: usage2 };
|
|
21523
|
+
notifyCurrentResponseEvidence();
|
|
21524
|
+
},
|
|
21525
|
+
() => void 0
|
|
21526
|
+
);
|
|
21396
21527
|
const [structuredOutput, usage, finishReason, providerMetadata, requestStatus] = await waitForPostResponseFinalization(
|
|
21397
21528
|
Promise.all([
|
|
21398
21529
|
options2.responseOutput != null ? resolveOptionalStructuredOutput(handle.output) : void 0,
|
|
21399
|
-
|
|
21530
|
+
usagePromise,
|
|
21400
21531
|
resolveOptionalValue(handle.finishReason),
|
|
21401
21532
|
resolveOptionalValue(handle.providerMetadata),
|
|
21402
21533
|
resolveOptionalValue(handle.requestStatus)
|
|
@@ -21418,8 +21549,13 @@ async function streamChatV2(options2) {
|
|
|
21418
21549
|
return executeStream(options2, options2.executeStream ?? defaultStreamExecutor);
|
|
21419
21550
|
}
|
|
21420
21551
|
async function generateChatV2(options2) {
|
|
21552
|
+
var _a;
|
|
21421
21553
|
const args = buildTextArgs(options2);
|
|
21422
21554
|
const stepToolCalls = attachGenerateStepToolCallCollector(args);
|
|
21555
|
+
try {
|
|
21556
|
+
(_a = options2.onRequestStarted) == null ? void 0 : _a.call(options2);
|
|
21557
|
+
} catch {
|
|
21558
|
+
}
|
|
21423
21559
|
let result;
|
|
21424
21560
|
try {
|
|
21425
21561
|
result = await waitForGeneratedResponse(
|
|
@@ -21435,13 +21571,35 @@ async function generateChatV2(options2) {
|
|
|
21435
21571
|
}
|
|
21436
21572
|
const isStructuredOutput = isChatV2StructuredResponseFormat(options2.responseFormat);
|
|
21437
21573
|
const responseText = isStructuredOutput ? collapseRepeatedStructuredJsonText(result.text) : result.text;
|
|
21574
|
+
const functionCalls = toStreamedFunctionCalls(
|
|
21575
|
+
result.toolCalls != null && result.toolCalls.length > 0 ? result.toolCalls : stepToolCalls
|
|
21576
|
+
);
|
|
21577
|
+
const reasoningPromise = resolveGenerateReasoning(result);
|
|
21578
|
+
const usagePromise = resolveGenerateUsage(result);
|
|
21579
|
+
let evidence = { text: responseText, functionCalls, reasoning: "" };
|
|
21580
|
+
const notifyCurrentResponseEvidence = () => notifyResponseReceived(options2, evidence);
|
|
21581
|
+
notifyCurrentResponseEvidence();
|
|
21582
|
+
void reasoningPromise.then(
|
|
21583
|
+
(reasoning2) => {
|
|
21584
|
+
evidence = { ...evidence, reasoning: reasoning2 };
|
|
21585
|
+
notifyCurrentResponseEvidence();
|
|
21586
|
+
},
|
|
21587
|
+
() => void 0
|
|
21588
|
+
);
|
|
21589
|
+
void usagePromise.then(
|
|
21590
|
+
(usage2) => {
|
|
21591
|
+
evidence = { ...evidence, usage: usage2 };
|
|
21592
|
+
notifyCurrentResponseEvidence();
|
|
21593
|
+
},
|
|
21594
|
+
() => void 0
|
|
21595
|
+
);
|
|
21438
21596
|
const [finishReason, structuredOutput, usage, reasoning, providerMetadata, requestStatus] = await waitForPostResponseFinalization(
|
|
21439
21597
|
(async () => {
|
|
21440
21598
|
const finishReason2 = await resolveOptionalValue(result.finishReason);
|
|
21441
21599
|
const [structuredOutput2, usage2, reasoning2, providerMetadata2, requestStatus2] = await Promise.all([
|
|
21442
21600
|
resolveGenerateStructuredOutput(result, options2.responseOutput, finishReason2),
|
|
21443
|
-
|
|
21444
|
-
|
|
21601
|
+
usagePromise,
|
|
21602
|
+
reasoningPromise,
|
|
21445
21603
|
resolveOptionalValue(result.providerMetadata),
|
|
21446
21604
|
resolveOptionalValue(result.requestStatus)
|
|
21447
21605
|
]);
|
|
@@ -21452,9 +21610,7 @@ async function generateChatV2(options2) {
|
|
|
21452
21610
|
return {
|
|
21453
21611
|
responseText,
|
|
21454
21612
|
structuredOutput,
|
|
21455
|
-
functionCalls
|
|
21456
|
-
result.toolCalls != null && result.toolCalls.length > 0 ? result.toolCalls : stepToolCalls
|
|
21457
|
-
),
|
|
21613
|
+
functionCalls,
|
|
21458
21614
|
usage,
|
|
21459
21615
|
reasoning,
|
|
21460
21616
|
finishReason,
|
|
@@ -22396,6 +22552,28 @@ async function runChatV2WithRetry(options2, chatOptions, retryPlan, signal, tran
|
|
|
22396
22552
|
const callId = createObservedChatV2CallId(options2);
|
|
22397
22553
|
const callStartedAt = Date.now();
|
|
22398
22554
|
let callWasObserved = false;
|
|
22555
|
+
let acceptsResponseEvidence = true;
|
|
22556
|
+
const retireResponseEvidence = () => {
|
|
22557
|
+
acceptsResponseEvidence = false;
|
|
22558
|
+
};
|
|
22559
|
+
let latestResponseEvidence;
|
|
22560
|
+
const reportResponseEvidence = (response) => {
|
|
22561
|
+
var _a2;
|
|
22562
|
+
if (!acceptsResponseEvidence) {
|
|
22563
|
+
return;
|
|
22564
|
+
}
|
|
22565
|
+
latestResponseEvidence = response;
|
|
22566
|
+
try {
|
|
22567
|
+
(_a2 = chatOptions.onResponseReceived) == null ? void 0 : _a2.call(chatOptions, response);
|
|
22568
|
+
} catch {
|
|
22569
|
+
}
|
|
22570
|
+
};
|
|
22571
|
+
const publishAndRetireResponseEvidence = () => {
|
|
22572
|
+
if (latestResponseEvidence != null) {
|
|
22573
|
+
reportResponseEvidence(latestResponseEvidence);
|
|
22574
|
+
}
|
|
22575
|
+
retireResponseEvidence();
|
|
22576
|
+
};
|
|
22399
22577
|
const attemptController = new AbortController();
|
|
22400
22578
|
const abortAttemptFromCaller = () => attemptController.abort(signal.reason);
|
|
22401
22579
|
if (signal.aborted) {
|
|
@@ -22410,10 +22588,12 @@ async function runChatV2WithRetry(options2, chatOptions, retryPlan, signal, tran
|
|
|
22410
22588
|
firstOutputTimeoutMs: options2.firstOutputTimeoutMs,
|
|
22411
22589
|
streamInactivityTimeoutMs: options2.streamInactivityTimeoutMs,
|
|
22412
22590
|
onStreamActivity: options2.onStreamActivity,
|
|
22413
|
-
onTimeout: (error) => attemptController.abort(error)
|
|
22591
|
+
onTimeout: (error) => attemptController.abort(error),
|
|
22592
|
+
onResponseReceived: reportResponseEvidence
|
|
22414
22593
|
};
|
|
22415
22594
|
const result = transportMode === "generate" ? await generateChatV2(attemptChatOptions) : await streamChatV2(attemptChatOptions);
|
|
22416
22595
|
await ((_a = options2.responseBodyCapture) == null ? void 0 : _a.flush());
|
|
22596
|
+
publishAndRetireResponseEvidence();
|
|
22417
22597
|
const statusCode = result.requestStatus ?? 200;
|
|
22418
22598
|
notifyChatV2CallFinished(options2, {
|
|
22419
22599
|
callId,
|
|
@@ -22444,6 +22624,7 @@ async function runChatV2WithRetry(options2, chatOptions, retryPlan, signal, tran
|
|
|
22444
22624
|
await ((_b = options2.responseBodyCapture) == null ? void 0 : _b.flush({
|
|
22445
22625
|
waitForPending: !signal.aborted && !isChatV2ProviderTimeoutError(error)
|
|
22446
22626
|
}));
|
|
22627
|
+
publishAndRetireResponseEvidence();
|
|
22447
22628
|
if (!callWasObserved) {
|
|
22448
22629
|
notifyChatV2CallFinished(options2, {
|
|
22449
22630
|
callId,
|
|
@@ -22473,6 +22654,7 @@ async function runChatV2WithRetry(options2, chatOptions, retryPlan, signal, tran
|
|
|
22473
22654
|
await prepareProviderRetry();
|
|
22474
22655
|
await waitForLLMChatV2RetryCooldown(retryPlan.cooldownMs, signal);
|
|
22475
22656
|
} finally {
|
|
22657
|
+
retireResponseEvidence();
|
|
22476
22658
|
signal.removeEventListener("abort", abortAttemptFromCaller);
|
|
22477
22659
|
}
|
|
22478
22660
|
}
|
|
@@ -22494,6 +22676,35 @@ async function runChatV2PipelineExecution(options2) {
|
|
|
22494
22676
|
tools
|
|
22495
22677
|
});
|
|
22496
22678
|
const shouldStreamResponse = plan.transportMode === "stream";
|
|
22679
|
+
const emitFailureCheckpoint = (partial) => {
|
|
22680
|
+
if (options2.onFailureCheckpoint == null) {
|
|
22681
|
+
return;
|
|
22682
|
+
}
|
|
22683
|
+
try {
|
|
22684
|
+
options2.onFailureCheckpoint(
|
|
22685
|
+
createChatV2CommonOutputs({
|
|
22686
|
+
requestMessages,
|
|
22687
|
+
response: partial.text,
|
|
22688
|
+
structuredOutput: void 0,
|
|
22689
|
+
functionCalls: partial.functionCalls,
|
|
22690
|
+
usage: normalizeChatV2Usage(partial.usage, options2),
|
|
22691
|
+
reasoning: partial.reasoning,
|
|
22692
|
+
requestBodies: options2.requestBodies,
|
|
22693
|
+
responseBodies: options2.responseBodies,
|
|
22694
|
+
outputUsage: plan.output.outputUsage,
|
|
22695
|
+
outputReasoning: plan.output.outputReasoning,
|
|
22696
|
+
outputRequestBody: plan.output.outputRequestBody,
|
|
22697
|
+
outputResponseBody: plan.output.outputResponseBody,
|
|
22698
|
+
includeFunctionCalls: plan.output.includeFunctionCalls,
|
|
22699
|
+
functionCallMode: plan.output.functionCallMode,
|
|
22700
|
+
// An incomplete structured reply is still useful diagnostic text,
|
|
22701
|
+
// not a schema-valid graph result.
|
|
22702
|
+
responseFormat: void 0
|
|
22703
|
+
})
|
|
22704
|
+
);
|
|
22705
|
+
} catch {
|
|
22706
|
+
}
|
|
22707
|
+
};
|
|
22497
22708
|
let chatResponse;
|
|
22498
22709
|
try {
|
|
22499
22710
|
chatResponse = await runChatV2WithRetry(
|
|
@@ -22503,8 +22714,11 @@ async function runChatV2PipelineExecution(options2) {
|
|
|
22503
22714
|
abortSignal: options2.context.signal,
|
|
22504
22715
|
executeStream: options2.executeStream,
|
|
22505
22716
|
executeGenerate: options2.executeGenerate,
|
|
22506
|
-
|
|
22717
|
+
onRequestStarted: () => emitFailureCheckpoint({ text: "", functionCalls: [], reasoning: "" }),
|
|
22718
|
+
onResponseReceived: emitFailureCheckpoint,
|
|
22719
|
+
onPartialOutput: !shouldStreamResponse ? void 0 : ({ text, functionCalls, reasoning }) => {
|
|
22507
22720
|
var _a, _b;
|
|
22721
|
+
emitFailureCheckpoint({ text, functionCalls, reasoning });
|
|
22508
22722
|
(_b = (_a = options2.context).onPartialOutputs) == null ? void 0 : _b.call(
|
|
22509
22723
|
_a,
|
|
22510
22724
|
createChatV2CommonOutputs({
|
|
@@ -22513,11 +22727,11 @@ async function runChatV2PipelineExecution(options2) {
|
|
|
22513
22727
|
structuredOutput: void 0,
|
|
22514
22728
|
functionCalls,
|
|
22515
22729
|
usage: void 0,
|
|
22516
|
-
reasoning
|
|
22730
|
+
reasoning,
|
|
22517
22731
|
requestBodies: void 0,
|
|
22518
22732
|
responseBodies: void 0,
|
|
22519
22733
|
outputUsage: false,
|
|
22520
|
-
outputReasoning:
|
|
22734
|
+
outputReasoning: plan.output.outputReasoning,
|
|
22521
22735
|
outputRequestBody: false,
|
|
22522
22736
|
outputResponseBody: false,
|
|
22523
22737
|
includeFunctionCalls: plan.output.includeFunctionCalls,
|
|
@@ -22927,6 +23141,8 @@ function projectLLMInvocationUsage(events) {
|
|
|
22927
23141
|
function projectLLMInvocationDiagnostics({
|
|
22928
23142
|
runOptions,
|
|
22929
23143
|
outputLLMAttempts,
|
|
23144
|
+
modelCalls,
|
|
23145
|
+
outputUsage,
|
|
22930
23146
|
llmAttempts,
|
|
22931
23147
|
profileSummary
|
|
22932
23148
|
}) {
|
|
@@ -22935,9 +23151,13 @@ function projectLLMInvocationDiagnostics({
|
|
|
22935
23151
|
...Object.fromEntries(
|
|
22936
23152
|
Object.entries(capturedBodies).filter(([, output]) => (output == null ? void 0 : output.type) !== "control-flow-excluded")
|
|
22937
23153
|
),
|
|
23154
|
+
...projectLLMInvocationUsageOutput({ modelCalls, outputUsage }),
|
|
22938
23155
|
...projectLLMInvocationMetadata({ outputLLMAttempts, llmAttempts, profileSummary })
|
|
22939
23156
|
};
|
|
22940
23157
|
}
|
|
23158
|
+
function mergeLLMInvocationFailureOutputs(partialOutputs, diagnostics) {
|
|
23159
|
+
return { ...partialOutputs, ...diagnostics };
|
|
23160
|
+
}
|
|
22941
23161
|
function projectLLMInvocationMetadata(params) {
|
|
22942
23162
|
const { outputLLMAttempts, llmAttempts, profileSummary } = params;
|
|
22943
23163
|
const outputs = {};
|
|
@@ -22957,12 +23177,10 @@ function projectLLMInvocationMetadata(params) {
|
|
|
22957
23177
|
}
|
|
22958
23178
|
function projectLLMInvocationResult(params) {
|
|
22959
23179
|
const { result, modelCalls, outputUsage, outputLLMAttempts, llmAttempts, profileSummary } = params;
|
|
22960
|
-
|
|
22961
|
-
|
|
22962
|
-
|
|
22963
|
-
|
|
22964
|
-
result.commonOutputs["usage"] = { type: "object", value: physicalUsage };
|
|
22965
|
-
}
|
|
23180
|
+
const usage = getLLMInvocationUsage({ modelCalls, outputUsage });
|
|
23181
|
+
if (usage != null) {
|
|
23182
|
+
result.usage = usage;
|
|
23183
|
+
result.commonOutputs["usage"] = { type: "object", value: usage };
|
|
22966
23184
|
}
|
|
22967
23185
|
Object.assign(
|
|
22968
23186
|
result.commonOutputs,
|
|
@@ -22974,6 +23192,22 @@ function projectLLMInvocationResult(params) {
|
|
|
22974
23192
|
);
|
|
22975
23193
|
return result.commonOutputs;
|
|
22976
23194
|
}
|
|
23195
|
+
function projectLLMInvocationUsageOutput({
|
|
23196
|
+
modelCalls,
|
|
23197
|
+
outputUsage
|
|
23198
|
+
}) {
|
|
23199
|
+
const usage = getLLMInvocationUsage({ modelCalls, outputUsage });
|
|
23200
|
+
return usage == null ? {} : { ["usage"]: { type: "object", value: usage } };
|
|
23201
|
+
}
|
|
23202
|
+
function getLLMInvocationUsage({
|
|
23203
|
+
modelCalls,
|
|
23204
|
+
outputUsage
|
|
23205
|
+
}) {
|
|
23206
|
+
if (!outputUsage || modelCalls.length === 0) {
|
|
23207
|
+
return void 0;
|
|
23208
|
+
}
|
|
23209
|
+
return projectLLMInvocationUsage(modelCalls) ?? void 0;
|
|
23210
|
+
}
|
|
22977
23211
|
|
|
22978
23212
|
// src/model/chat-v2/llmProfileFallback.ts
|
|
22979
23213
|
var DEFAULT_LLM_PROFILE_HEALTH_OPERATION_TIMEOUT_MS = 2e3;
|
|
@@ -23390,7 +23624,9 @@ function createLLMProfileFallbackRunner(params) {
|
|
|
23390
23624
|
healthDisposition: "deny",
|
|
23391
23625
|
...begin.retryAt == null ? {} : { retryAt: begin.retryAt }
|
|
23392
23626
|
});
|
|
23393
|
-
|
|
23627
|
+
if (profileIndex + 1 < params.candidates.length) {
|
|
23628
|
+
clearPartialResponse(roundOptions);
|
|
23629
|
+
}
|
|
23394
23630
|
continue;
|
|
23395
23631
|
}
|
|
23396
23632
|
const permitId = begin.permitId;
|
|
@@ -23462,7 +23698,9 @@ function createLLMProfileFallbackRunner(params) {
|
|
|
23462
23698
|
outcome: "failure",
|
|
23463
23699
|
error: getLLMAttemptErrorMessage(error)
|
|
23464
23700
|
});
|
|
23465
|
-
|
|
23701
|
+
if (profileIndex + 1 < params.candidates.length) {
|
|
23702
|
+
clearPartialResponse(roundOptions);
|
|
23703
|
+
}
|
|
23466
23704
|
await (healthPermit == null ? void 0 : healthPermit.finish("ignored"));
|
|
23467
23705
|
continue;
|
|
23468
23706
|
}
|
|
@@ -23527,7 +23765,9 @@ function createLLMProfileFallbackRunner(params) {
|
|
|
23527
23765
|
outcome: "failure",
|
|
23528
23766
|
error: getLLMAttemptErrorMessage(error)
|
|
23529
23767
|
});
|
|
23530
|
-
|
|
23768
|
+
if (profileIndex + 1 < params.candidates.length) {
|
|
23769
|
+
clearPartialResponse(roundOptions);
|
|
23770
|
+
}
|
|
23531
23771
|
await (healthPermit == null ? void 0 : healthPermit.finish("ignored"));
|
|
23532
23772
|
continue;
|
|
23533
23773
|
}
|
|
@@ -23541,7 +23781,9 @@ function createLLMProfileFallbackRunner(params) {
|
|
|
23541
23781
|
await (healthPermit == null ? void 0 : healthPermit.finish(
|
|
23542
23782
|
isUnhealthyLLMProfileProviderFailure(execution.failure.normalizedError) ? "unhealthy" : "ignored"
|
|
23543
23783
|
));
|
|
23544
|
-
|
|
23784
|
+
if (profileIndex + 1 < params.candidates.length) {
|
|
23785
|
+
clearPartialResponse(roundOptions);
|
|
23786
|
+
}
|
|
23545
23787
|
}
|
|
23546
23788
|
exhausted = true;
|
|
23547
23789
|
if (params.candidates.length === 1 && lastError !== void 0) {
|
|
@@ -24679,6 +24921,7 @@ var LLMChatV2NodeImpl = class extends NodeImpl {
|
|
|
24679
24921
|
var _a, _b, _c, _d, _e;
|
|
24680
24922
|
const invocationJournal = new LLMInvocationJournal();
|
|
24681
24923
|
let profileAttemptSequence = 0;
|
|
24924
|
+
let latestFailureEvidence;
|
|
24682
24925
|
const usageTrackingContext = {
|
|
24683
24926
|
...context,
|
|
24684
24927
|
onChatV2CallFinished: (event) => {
|
|
@@ -24717,7 +24960,15 @@ var LLMChatV2NodeImpl = class extends NodeImpl {
|
|
|
24717
24960
|
invocation = await executeLLMInvocation({
|
|
24718
24961
|
context,
|
|
24719
24962
|
journal: invocationJournal,
|
|
24720
|
-
runtime
|
|
24963
|
+
runtime: {
|
|
24964
|
+
...runtime,
|
|
24965
|
+
runOptions: {
|
|
24966
|
+
...runtime.runOptions,
|
|
24967
|
+
onFailureCheckpoint: (outputs) => {
|
|
24968
|
+
latestFailureEvidence = cloneLLMChatV2Outputs(outputs);
|
|
24969
|
+
}
|
|
24970
|
+
}
|
|
24971
|
+
},
|
|
24721
24972
|
toolCallContinuation
|
|
24722
24973
|
});
|
|
24723
24974
|
} catch (error) {
|
|
@@ -24725,11 +24976,18 @@ var LLMChatV2NodeImpl = class extends NodeImpl {
|
|
|
24725
24976
|
const diagnostics = projectLLMInvocationDiagnostics({
|
|
24726
24977
|
runOptions: runtime.runOptions,
|
|
24727
24978
|
outputLLMAttempts: this.data.outputLLMAttempts,
|
|
24979
|
+
modelCalls: invocationJournal.modelCalls,
|
|
24980
|
+
outputUsage: this.data.outputUsage,
|
|
24728
24981
|
llmAttempts: invocationJournal.llmAttempts,
|
|
24729
24982
|
profileSummary: (_b = runtime.getProfileSummary) == null ? void 0 : _b.call(runtime)
|
|
24730
24983
|
});
|
|
24731
|
-
|
|
24732
|
-
|
|
24984
|
+
const failureOutputs = mergeLLMInvocationFailureOutputs(latestFailureEvidence, diagnostics);
|
|
24985
|
+
if (Object.keys(failureOutputs).length > 0) {
|
|
24986
|
+
if (context.setFailureOutputs) {
|
|
24987
|
+
context.setFailureOutputs(failureOutputs);
|
|
24988
|
+
} else {
|
|
24989
|
+
(_c = context.onPartialOutputs) == null ? void 0 : _c.call(context, failureOutputs);
|
|
24990
|
+
}
|
|
24733
24991
|
}
|
|
24734
24992
|
} catch {
|
|
24735
24993
|
}
|
|
@@ -38936,12 +39194,14 @@ var toRecordedEventMap = {
|
|
|
38936
39194
|
),
|
|
38937
39195
|
execution
|
|
38938
39196
|
),
|
|
38939
|
-
nodeError: ({ node, error, processId, resultOrigin, durationMs, splitRunDurationMs, execution }) => withExecution(
|
|
39197
|
+
nodeError: ({ node, error, processId, outputs, splitOutputs, resultOrigin, durationMs, splitRunDurationMs, execution }) => withExecution(
|
|
38940
39198
|
withDuration(
|
|
38941
39199
|
{
|
|
38942
39200
|
nodeId: node.id,
|
|
38943
39201
|
error: typeof error === "string" ? error : error.stack,
|
|
38944
39202
|
processId,
|
|
39203
|
+
...outputs === void 0 ? {} : { outputs },
|
|
39204
|
+
...splitOutputs === void 0 ? {} : { splitOutputs },
|
|
38945
39205
|
...resultOrigin === void 0 ? {} : { resultOrigin }
|
|
38946
39206
|
},
|
|
38947
39207
|
durationMs,
|
|
@@ -38949,7 +39209,14 @@ var toRecordedEventMap = {
|
|
|
38949
39209
|
),
|
|
38950
39210
|
execution
|
|
38951
39211
|
),
|
|
38952
|
-
|
|
39212
|
+
// Older debugger servers sent a null abort payload. Preserve that evidence
|
|
39213
|
+
// instead of letting a malformed legacy transport message abort the whole
|
|
39214
|
+
// recording. An unknown payload is deliberately treated as unsuccessful;
|
|
39215
|
+
// it must never be mistaken for a completed graph run during replay.
|
|
39216
|
+
abort: (data) => {
|
|
39217
|
+
const { successful, error } = data ?? {};
|
|
39218
|
+
return { successful: successful === true, error: typeof error === "string" ? error : error == null ? void 0 : error.stack };
|
|
39219
|
+
},
|
|
38953
39220
|
graphAbort: ({ successful, error, graph, execution }) => withExecution(
|
|
38954
39221
|
{
|
|
38955
39222
|
successful,
|
|
@@ -39062,6 +39329,7 @@ function omitReplayRecordedAt(data) {
|
|
|
39062
39329
|
function isRecordableProcessEvent(message) {
|
|
39063
39330
|
return message in toRecordedEventMap || isPrefix(message, "globalSet:") || isPrefix(message, "userEvent:");
|
|
39064
39331
|
}
|
|
39332
|
+
var CLOSED_WEBSOCKET_READY_STATE = 3;
|
|
39065
39333
|
function mapValuesDeep(obj, fn) {
|
|
39066
39334
|
if (Array.isArray(obj)) {
|
|
39067
39335
|
return obj.map((value) => {
|
|
@@ -39157,14 +39425,22 @@ var ExecutionRecorder = class _ExecutionRecorder {
|
|
|
39157
39425
|
var _a, _b;
|
|
39158
39426
|
this.recordingId = (0, import_non_secure100.nanoid)();
|
|
39159
39427
|
let settled = false;
|
|
39160
|
-
const finish = () => {
|
|
39428
|
+
const finish = (emitFinishedRecording) => {
|
|
39161
39429
|
var _a2;
|
|
39162
39430
|
if (settled) return;
|
|
39163
39431
|
settled = true;
|
|
39164
39432
|
channel.removeEventListener("message", listener);
|
|
39165
|
-
|
|
39433
|
+
channel.removeEventListener("close", onClose);
|
|
39434
|
+
(_a2 = options2.signal) == null ? void 0 : _a2.removeEventListener("abort", onOwnerDisposed);
|
|
39435
|
+
if (emitFinishedRecording) {
|
|
39436
|
+
emitDetached(this.#emitter, "finish", {
|
|
39437
|
+
recording: this.getRecording()
|
|
39438
|
+
});
|
|
39439
|
+
}
|
|
39166
39440
|
resolve();
|
|
39167
39441
|
};
|
|
39442
|
+
const onClose = () => finish(false);
|
|
39443
|
+
const onOwnerDisposed = () => finish(false);
|
|
39168
39444
|
const listener = (event) => {
|
|
39169
39445
|
let payload;
|
|
39170
39446
|
try {
|
|
@@ -39186,24 +39462,38 @@ var ExecutionRecorder = class _ExecutionRecorder {
|
|
|
39186
39462
|
return;
|
|
39187
39463
|
}
|
|
39188
39464
|
this.#events.push(toRecordedEvent(message, data));
|
|
39189
|
-
if (
|
|
39190
|
-
|
|
39191
|
-
recording: this.getRecording()
|
|
39192
|
-
});
|
|
39193
|
-
finish();
|
|
39465
|
+
if (isSocketRecordingTerminalEvent(message)) {
|
|
39466
|
+
finish(true);
|
|
39194
39467
|
}
|
|
39195
39468
|
};
|
|
39196
39469
|
if ((_a = options2.signal) == null ? void 0 : _a.aborted) {
|
|
39197
|
-
|
|
39470
|
+
onOwnerDisposed();
|
|
39198
39471
|
return;
|
|
39199
39472
|
}
|
|
39200
39473
|
channel.addEventListener("message", listener);
|
|
39201
|
-
|
|
39474
|
+
channel.addEventListener("close", onClose, { once: true });
|
|
39475
|
+
(_b = options2.signal) == null ? void 0 : _b.addEventListener("abort", onOwnerDisposed, { once: true });
|
|
39476
|
+
if (channel.readyState === CLOSED_WEBSOCKET_READY_STATE) {
|
|
39477
|
+
onClose();
|
|
39478
|
+
}
|
|
39202
39479
|
});
|
|
39203
39480
|
}
|
|
39204
39481
|
record(processor) {
|
|
39205
39482
|
this.recordingId = (0, import_non_secure100.nanoid)();
|
|
39206
|
-
|
|
39483
|
+
let settled = false;
|
|
39484
|
+
const finish = () => {
|
|
39485
|
+
if (settled) return;
|
|
39486
|
+
settled = true;
|
|
39487
|
+
unsubscribeAny();
|
|
39488
|
+
unsubscribeFinish();
|
|
39489
|
+
emitDetached(this.#emitter, "finish", {
|
|
39490
|
+
recording: this.getRecording()
|
|
39491
|
+
});
|
|
39492
|
+
};
|
|
39493
|
+
const unsubscribeAny = processor.onAny((event, data) => {
|
|
39494
|
+
if (settled || event === "finish") {
|
|
39495
|
+
return;
|
|
39496
|
+
}
|
|
39207
39497
|
if (this.#includePartialOutputs === false && event === "partialOutput") {
|
|
39208
39498
|
return;
|
|
39209
39499
|
}
|
|
@@ -39211,18 +39501,17 @@ var ExecutionRecorder = class _ExecutionRecorder {
|
|
|
39211
39501
|
return;
|
|
39212
39502
|
}
|
|
39213
39503
|
this.#events.push(toRecordedEvent(event, data));
|
|
39214
|
-
if (isRecordingTerminalEvent(event, data)) {
|
|
39215
|
-
emitDetached(this.#emitter, "finish", {
|
|
39216
|
-
recording: this.getRecording()
|
|
39217
|
-
});
|
|
39218
|
-
}
|
|
39219
39504
|
});
|
|
39505
|
+
const unsubscribeFinish = processor.on("finish", finish);
|
|
39220
39506
|
}
|
|
39221
39507
|
getRecording() {
|
|
39222
39508
|
var _a, _b;
|
|
39223
39509
|
return {
|
|
39224
39510
|
recordingId: this.recordingId,
|
|
39225
|
-
|
|
39511
|
+
// Callers persist and replay recordings asynchronously. Returning the
|
|
39512
|
+
// live backing array would let a later event mutate an already-finished
|
|
39513
|
+
// recording snapshot.
|
|
39514
|
+
events: [...this.#events],
|
|
39226
39515
|
startTs: ((_a = this.#events[0]) == null ? void 0 : _a.ts) ?? 0,
|
|
39227
39516
|
finishTs: ((_b = this.#events[this.#events.length - 1]) == null ? void 0 : _b.ts) ?? 0
|
|
39228
39517
|
};
|
|
@@ -39256,11 +39545,8 @@ var ExecutionRecorder = class _ExecutionRecorder {
|
|
|
39256
39545
|
return (0, import_json_stream_es.stringifyJsonStream)(serializeToObject(this.getRecording()));
|
|
39257
39546
|
}
|
|
39258
39547
|
};
|
|
39259
|
-
function
|
|
39260
|
-
|
|
39261
|
-
return true;
|
|
39262
|
-
}
|
|
39263
|
-
return event === "abort" && data.successful !== true;
|
|
39548
|
+
function isSocketRecordingTerminalEvent(event) {
|
|
39549
|
+
return event === "done" || event === "error";
|
|
39264
39550
|
}
|
|
39265
39551
|
|
|
39266
39552
|
// src/plugins/anthropic/nodes/ChatAnthropicNode.ts
|