@anuma/sdk 10.2.3 → 10.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/expo/index.cjs +60 -10
- package/dist/expo/index.mjs +60 -10
- package/dist/react/index.cjs +60 -10
- package/dist/react/index.mjs +60 -10
- package/dist/server/index.cjs +60 -10
- package/dist/server/index.mjs +60 -10
- package/package.json +1 -1
package/dist/expo/index.cjs
CHANGED
|
@@ -9609,6 +9609,9 @@ var StreamSmoother = class {
|
|
|
9609
9609
|
this.rampDuration = config.rampDuration ?? 4e3;
|
|
9610
9610
|
}
|
|
9611
9611
|
}
|
|
9612
|
+
get hasPendingOutput() {
|
|
9613
|
+
return this.buffer.length > 0;
|
|
9614
|
+
}
|
|
9612
9615
|
/**
|
|
9613
9616
|
* Add text to the buffer. If smoothing is disabled, passes through immediately.
|
|
9614
9617
|
*/
|
|
@@ -10277,6 +10280,34 @@ async function runToolLoop(options) {
|
|
|
10277
10280
|
toolsChecksum: acc.toolsChecksum
|
|
10278
10281
|
};
|
|
10279
10282
|
};
|
|
10283
|
+
const drainSmoothers = async (acc, smoothers) => {
|
|
10284
|
+
let playbackAborted = false;
|
|
10285
|
+
const stopPlayback = () => {
|
|
10286
|
+
for (const smoother of smoothers) {
|
|
10287
|
+
if (isDetach()) smoother.flush();
|
|
10288
|
+
else smoother.destroy();
|
|
10289
|
+
}
|
|
10290
|
+
};
|
|
10291
|
+
const onAbort = () => {
|
|
10292
|
+
playbackAborted = !isDetach() && smoothers.some((smoother) => smoother.hasPendingOutput);
|
|
10293
|
+
stopPlayback();
|
|
10294
|
+
};
|
|
10295
|
+
combinedSignal?.addEventListener("abort", onAbort, { once: true });
|
|
10296
|
+
try {
|
|
10297
|
+
if (combinedSignal?.aborted) stopPlayback();
|
|
10298
|
+
await Promise.all(smoothers.map((smoother) => smoother.drain()));
|
|
10299
|
+
if (!playbackAborted) return;
|
|
10300
|
+
await fireAfterModelCall(buildModelCallEndPayload(acc, { error: "aborted" }));
|
|
10301
|
+
await fireRunError({ error: "Request aborted", stage: "model" });
|
|
10302
|
+
return {
|
|
10303
|
+
data: buildResponseFinal(acc),
|
|
10304
|
+
error: "Request aborted",
|
|
10305
|
+
toolsChecksum: acc.toolsChecksum
|
|
10306
|
+
};
|
|
10307
|
+
} finally {
|
|
10308
|
+
combinedSignal?.removeEventListener("abort", onAbort);
|
|
10309
|
+
}
|
|
10310
|
+
};
|
|
10280
10311
|
for (let attempt = 0; attempt < STREAM_RETRY_MAX_ATTEMPTS; attempt++) {
|
|
10281
10312
|
sseError = null;
|
|
10282
10313
|
if (combinedSignal?.aborted) {
|
|
@@ -10414,7 +10445,8 @@ async function runToolLoop(options) {
|
|
|
10414
10445
|
contentSmoother.flush();
|
|
10415
10446
|
thinkingSmoother.flush();
|
|
10416
10447
|
} else {
|
|
10417
|
-
await
|
|
10448
|
+
const interrupted = await drainSmoothers(accumulator, [contentSmoother, thinkingSmoother]);
|
|
10449
|
+
if (interrupted) return interrupted;
|
|
10418
10450
|
}
|
|
10419
10451
|
flushDeAnon();
|
|
10420
10452
|
await fireAfterModelCall(buildModelCallEndPayload(accumulator));
|
|
@@ -10933,7 +10965,11 @@ Executing tool: ${toolInfo}
|
|
|
10933
10965
|
contContentSmoother.flush();
|
|
10934
10966
|
contThinkingSmoother.flush();
|
|
10935
10967
|
} else {
|
|
10936
|
-
await
|
|
10968
|
+
const interrupted = await drainSmoothers(currentAccumulator, [
|
|
10969
|
+
contContentSmoother,
|
|
10970
|
+
contThinkingSmoother
|
|
10971
|
+
]);
|
|
10972
|
+
if (interrupted) return interrupted;
|
|
10937
10973
|
}
|
|
10938
10974
|
flushDeAnon();
|
|
10939
10975
|
await fireAfterModelCall(buildModelCallEndPayload(currentAccumulator));
|
|
@@ -11064,6 +11100,8 @@ async function resumeStream(options) {
|
|
|
11064
11100
|
let watchdog;
|
|
11065
11101
|
let idleFired = false;
|
|
11066
11102
|
let callerAborted = false;
|
|
11103
|
+
let playbackAborted = false;
|
|
11104
|
+
let draining = false;
|
|
11067
11105
|
let settled = false;
|
|
11068
11106
|
const idleEnabled = idleTimeoutMs > 0 && idleTimeoutMs !== Infinity && typeof setTimeout === "function";
|
|
11069
11107
|
const armWatchdog = () => {
|
|
@@ -11083,6 +11121,9 @@ async function resumeStream(options) {
|
|
|
11083
11121
|
const abortMessage = () => callerAborted ? "Resume aborted" : idleFired ? "Resume timed out" : "Resume aborted";
|
|
11084
11122
|
const onCallerAbort = () => {
|
|
11085
11123
|
callerAborted = true;
|
|
11124
|
+
playbackAborted = draining && (contentSmoother.hasPendingOutput || thinkingSmoother.hasPendingOutput);
|
|
11125
|
+
contentSmoother.destroy();
|
|
11126
|
+
thinkingSmoother.destroy();
|
|
11086
11127
|
disarmWatchdog();
|
|
11087
11128
|
idleController.abort();
|
|
11088
11129
|
};
|
|
@@ -11166,15 +11207,24 @@ async function resumeStream(options) {
|
|
|
11166
11207
|
statusCode
|
|
11167
11208
|
};
|
|
11168
11209
|
}
|
|
11169
|
-
|
|
11170
|
-
|
|
11171
|
-
|
|
11210
|
+
settled = true;
|
|
11211
|
+
disarmWatchdog();
|
|
11212
|
+
try {
|
|
11213
|
+
if (idleFired) return buildInterrupted(abortMessage());
|
|
11214
|
+
if (accumulator.toolCalls.size > 0) {
|
|
11215
|
+
return buildInterrupted("Stream ended with a pending tool request");
|
|
11216
|
+
}
|
|
11217
|
+
draining = true;
|
|
11218
|
+
await Promise.all([contentSmoother.drain(), thinkingSmoother.drain()]);
|
|
11219
|
+
if (playbackAborted) return buildInterrupted(abortMessage());
|
|
11220
|
+
const response = strategy.buildFinalResponse(accumulator);
|
|
11221
|
+
const deliveredOutput = emittedOutput || (accumulator.toolCallEvents?.length ?? 0) > 0;
|
|
11222
|
+
if (onFinish && deliveredOutput) onFinish(response);
|
|
11223
|
+
return { data: response, error: null, interrupted: false, empty: !deliveredOutput };
|
|
11224
|
+
} finally {
|
|
11225
|
+
draining = false;
|
|
11226
|
+
cleanup();
|
|
11172
11227
|
}
|
|
11173
|
-
await Promise.all([contentSmoother.drain(), thinkingSmoother.drain()]);
|
|
11174
|
-
const response = strategy.buildFinalResponse(accumulator);
|
|
11175
|
-
const deliveredOutput = emittedOutput || (accumulator.toolCallEvents?.length ?? 0) > 0;
|
|
11176
|
-
if (onFinish && deliveredOutput) onFinish(response);
|
|
11177
|
-
return { data: response, error: null, interrupted: false, empty: !deliveredOutput };
|
|
11178
11228
|
}
|
|
11179
11229
|
|
|
11180
11230
|
// src/lib/chat/stockPriceCentroids.ts
|
package/dist/expo/index.mjs
CHANGED
|
@@ -7948,6 +7948,9 @@ var StreamSmoother = class {
|
|
|
7948
7948
|
this.rampDuration = config.rampDuration ?? 4e3;
|
|
7949
7949
|
}
|
|
7950
7950
|
}
|
|
7951
|
+
get hasPendingOutput() {
|
|
7952
|
+
return this.buffer.length > 0;
|
|
7953
|
+
}
|
|
7951
7954
|
/**
|
|
7952
7955
|
* Add text to the buffer. If smoothing is disabled, passes through immediately.
|
|
7953
7956
|
*/
|
|
@@ -8616,6 +8619,34 @@ async function runToolLoop(options) {
|
|
|
8616
8619
|
toolsChecksum: acc.toolsChecksum
|
|
8617
8620
|
};
|
|
8618
8621
|
};
|
|
8622
|
+
const drainSmoothers = async (acc, smoothers) => {
|
|
8623
|
+
let playbackAborted = false;
|
|
8624
|
+
const stopPlayback = () => {
|
|
8625
|
+
for (const smoother of smoothers) {
|
|
8626
|
+
if (isDetach()) smoother.flush();
|
|
8627
|
+
else smoother.destroy();
|
|
8628
|
+
}
|
|
8629
|
+
};
|
|
8630
|
+
const onAbort = () => {
|
|
8631
|
+
playbackAborted = !isDetach() && smoothers.some((smoother) => smoother.hasPendingOutput);
|
|
8632
|
+
stopPlayback();
|
|
8633
|
+
};
|
|
8634
|
+
combinedSignal?.addEventListener("abort", onAbort, { once: true });
|
|
8635
|
+
try {
|
|
8636
|
+
if (combinedSignal?.aborted) stopPlayback();
|
|
8637
|
+
await Promise.all(smoothers.map((smoother) => smoother.drain()));
|
|
8638
|
+
if (!playbackAborted) return;
|
|
8639
|
+
await fireAfterModelCall(buildModelCallEndPayload(acc, { error: "aborted" }));
|
|
8640
|
+
await fireRunError({ error: "Request aborted", stage: "model" });
|
|
8641
|
+
return {
|
|
8642
|
+
data: buildResponseFinal(acc),
|
|
8643
|
+
error: "Request aborted",
|
|
8644
|
+
toolsChecksum: acc.toolsChecksum
|
|
8645
|
+
};
|
|
8646
|
+
} finally {
|
|
8647
|
+
combinedSignal?.removeEventListener("abort", onAbort);
|
|
8648
|
+
}
|
|
8649
|
+
};
|
|
8619
8650
|
for (let attempt = 0; attempt < STREAM_RETRY_MAX_ATTEMPTS; attempt++) {
|
|
8620
8651
|
sseError = null;
|
|
8621
8652
|
if (combinedSignal?.aborted) {
|
|
@@ -8753,7 +8784,8 @@ async function runToolLoop(options) {
|
|
|
8753
8784
|
contentSmoother.flush();
|
|
8754
8785
|
thinkingSmoother.flush();
|
|
8755
8786
|
} else {
|
|
8756
|
-
await
|
|
8787
|
+
const interrupted = await drainSmoothers(accumulator, [contentSmoother, thinkingSmoother]);
|
|
8788
|
+
if (interrupted) return interrupted;
|
|
8757
8789
|
}
|
|
8758
8790
|
flushDeAnon();
|
|
8759
8791
|
await fireAfterModelCall(buildModelCallEndPayload(accumulator));
|
|
@@ -9272,7 +9304,11 @@ Executing tool: ${toolInfo}
|
|
|
9272
9304
|
contContentSmoother.flush();
|
|
9273
9305
|
contThinkingSmoother.flush();
|
|
9274
9306
|
} else {
|
|
9275
|
-
await
|
|
9307
|
+
const interrupted = await drainSmoothers(currentAccumulator, [
|
|
9308
|
+
contContentSmoother,
|
|
9309
|
+
contThinkingSmoother
|
|
9310
|
+
]);
|
|
9311
|
+
if (interrupted) return interrupted;
|
|
9276
9312
|
}
|
|
9277
9313
|
flushDeAnon();
|
|
9278
9314
|
await fireAfterModelCall(buildModelCallEndPayload(currentAccumulator));
|
|
@@ -9403,6 +9439,8 @@ async function resumeStream(options) {
|
|
|
9403
9439
|
let watchdog;
|
|
9404
9440
|
let idleFired = false;
|
|
9405
9441
|
let callerAborted = false;
|
|
9442
|
+
let playbackAborted = false;
|
|
9443
|
+
let draining = false;
|
|
9406
9444
|
let settled = false;
|
|
9407
9445
|
const idleEnabled = idleTimeoutMs > 0 && idleTimeoutMs !== Infinity && typeof setTimeout === "function";
|
|
9408
9446
|
const armWatchdog = () => {
|
|
@@ -9422,6 +9460,9 @@ async function resumeStream(options) {
|
|
|
9422
9460
|
const abortMessage = () => callerAborted ? "Resume aborted" : idleFired ? "Resume timed out" : "Resume aborted";
|
|
9423
9461
|
const onCallerAbort = () => {
|
|
9424
9462
|
callerAborted = true;
|
|
9463
|
+
playbackAborted = draining && (contentSmoother.hasPendingOutput || thinkingSmoother.hasPendingOutput);
|
|
9464
|
+
contentSmoother.destroy();
|
|
9465
|
+
thinkingSmoother.destroy();
|
|
9425
9466
|
disarmWatchdog();
|
|
9426
9467
|
idleController.abort();
|
|
9427
9468
|
};
|
|
@@ -9505,15 +9546,24 @@ async function resumeStream(options) {
|
|
|
9505
9546
|
statusCode
|
|
9506
9547
|
};
|
|
9507
9548
|
}
|
|
9508
|
-
|
|
9509
|
-
|
|
9510
|
-
|
|
9549
|
+
settled = true;
|
|
9550
|
+
disarmWatchdog();
|
|
9551
|
+
try {
|
|
9552
|
+
if (idleFired) return buildInterrupted(abortMessage());
|
|
9553
|
+
if (accumulator.toolCalls.size > 0) {
|
|
9554
|
+
return buildInterrupted("Stream ended with a pending tool request");
|
|
9555
|
+
}
|
|
9556
|
+
draining = true;
|
|
9557
|
+
await Promise.all([contentSmoother.drain(), thinkingSmoother.drain()]);
|
|
9558
|
+
if (playbackAborted) return buildInterrupted(abortMessage());
|
|
9559
|
+
const response = strategy.buildFinalResponse(accumulator);
|
|
9560
|
+
const deliveredOutput = emittedOutput || (accumulator.toolCallEvents?.length ?? 0) > 0;
|
|
9561
|
+
if (onFinish && deliveredOutput) onFinish(response);
|
|
9562
|
+
return { data: response, error: null, interrupted: false, empty: !deliveredOutput };
|
|
9563
|
+
} finally {
|
|
9564
|
+
draining = false;
|
|
9565
|
+
cleanup();
|
|
9511
9566
|
}
|
|
9512
|
-
await Promise.all([contentSmoother.drain(), thinkingSmoother.drain()]);
|
|
9513
|
-
const response = strategy.buildFinalResponse(accumulator);
|
|
9514
|
-
const deliveredOutput = emittedOutput || (accumulator.toolCallEvents?.length ?? 0) > 0;
|
|
9515
|
-
if (onFinish && deliveredOutput) onFinish(response);
|
|
9516
|
-
return { data: response, error: null, interrupted: false, empty: !deliveredOutput };
|
|
9517
9567
|
}
|
|
9518
9568
|
|
|
9519
9569
|
// src/lib/chat/stockPriceCentroids.ts
|
package/dist/react/index.cjs
CHANGED
|
@@ -10521,6 +10521,9 @@ var StreamSmoother = class {
|
|
|
10521
10521
|
this.rampDuration = config.rampDuration ?? 4e3;
|
|
10522
10522
|
}
|
|
10523
10523
|
}
|
|
10524
|
+
get hasPendingOutput() {
|
|
10525
|
+
return this.buffer.length > 0;
|
|
10526
|
+
}
|
|
10524
10527
|
/**
|
|
10525
10528
|
* Add text to the buffer. If smoothing is disabled, passes through immediately.
|
|
10526
10529
|
*/
|
|
@@ -11189,6 +11192,34 @@ async function runToolLoop(options) {
|
|
|
11189
11192
|
toolsChecksum: acc.toolsChecksum
|
|
11190
11193
|
};
|
|
11191
11194
|
};
|
|
11195
|
+
const drainSmoothers = async (acc, smoothers) => {
|
|
11196
|
+
let playbackAborted = false;
|
|
11197
|
+
const stopPlayback = () => {
|
|
11198
|
+
for (const smoother of smoothers) {
|
|
11199
|
+
if (isDetach()) smoother.flush();
|
|
11200
|
+
else smoother.destroy();
|
|
11201
|
+
}
|
|
11202
|
+
};
|
|
11203
|
+
const onAbort = () => {
|
|
11204
|
+
playbackAborted = !isDetach() && smoothers.some((smoother) => smoother.hasPendingOutput);
|
|
11205
|
+
stopPlayback();
|
|
11206
|
+
};
|
|
11207
|
+
combinedSignal?.addEventListener("abort", onAbort, { once: true });
|
|
11208
|
+
try {
|
|
11209
|
+
if (combinedSignal?.aborted) stopPlayback();
|
|
11210
|
+
await Promise.all(smoothers.map((smoother) => smoother.drain()));
|
|
11211
|
+
if (!playbackAborted) return;
|
|
11212
|
+
await fireAfterModelCall(buildModelCallEndPayload(acc, { error: "aborted" }));
|
|
11213
|
+
await fireRunError({ error: "Request aborted", stage: "model" });
|
|
11214
|
+
return {
|
|
11215
|
+
data: buildResponseFinal(acc),
|
|
11216
|
+
error: "Request aborted",
|
|
11217
|
+
toolsChecksum: acc.toolsChecksum
|
|
11218
|
+
};
|
|
11219
|
+
} finally {
|
|
11220
|
+
combinedSignal?.removeEventListener("abort", onAbort);
|
|
11221
|
+
}
|
|
11222
|
+
};
|
|
11192
11223
|
for (let attempt = 0; attempt < STREAM_RETRY_MAX_ATTEMPTS; attempt++) {
|
|
11193
11224
|
sseError = null;
|
|
11194
11225
|
if (combinedSignal?.aborted) {
|
|
@@ -11326,7 +11357,8 @@ async function runToolLoop(options) {
|
|
|
11326
11357
|
contentSmoother.flush();
|
|
11327
11358
|
thinkingSmoother.flush();
|
|
11328
11359
|
} else {
|
|
11329
|
-
await
|
|
11360
|
+
const interrupted = await drainSmoothers(accumulator, [contentSmoother, thinkingSmoother]);
|
|
11361
|
+
if (interrupted) return interrupted;
|
|
11330
11362
|
}
|
|
11331
11363
|
flushDeAnon();
|
|
11332
11364
|
await fireAfterModelCall(buildModelCallEndPayload(accumulator));
|
|
@@ -11845,7 +11877,11 @@ Executing tool: ${toolInfo}
|
|
|
11845
11877
|
contContentSmoother.flush();
|
|
11846
11878
|
contThinkingSmoother.flush();
|
|
11847
11879
|
} else {
|
|
11848
|
-
await
|
|
11880
|
+
const interrupted = await drainSmoothers(currentAccumulator, [
|
|
11881
|
+
contContentSmoother,
|
|
11882
|
+
contThinkingSmoother
|
|
11883
|
+
]);
|
|
11884
|
+
if (interrupted) return interrupted;
|
|
11849
11885
|
}
|
|
11850
11886
|
flushDeAnon();
|
|
11851
11887
|
await fireAfterModelCall(buildModelCallEndPayload(currentAccumulator));
|
|
@@ -11976,6 +12012,8 @@ async function resumeStream(options) {
|
|
|
11976
12012
|
let watchdog;
|
|
11977
12013
|
let idleFired = false;
|
|
11978
12014
|
let callerAborted = false;
|
|
12015
|
+
let playbackAborted = false;
|
|
12016
|
+
let draining = false;
|
|
11979
12017
|
let settled = false;
|
|
11980
12018
|
const idleEnabled = idleTimeoutMs > 0 && idleTimeoutMs !== Infinity && typeof setTimeout === "function";
|
|
11981
12019
|
const armWatchdog = () => {
|
|
@@ -11995,6 +12033,9 @@ async function resumeStream(options) {
|
|
|
11995
12033
|
const abortMessage = () => callerAborted ? "Resume aborted" : idleFired ? "Resume timed out" : "Resume aborted";
|
|
11996
12034
|
const onCallerAbort = () => {
|
|
11997
12035
|
callerAborted = true;
|
|
12036
|
+
playbackAborted = draining && (contentSmoother.hasPendingOutput || thinkingSmoother.hasPendingOutput);
|
|
12037
|
+
contentSmoother.destroy();
|
|
12038
|
+
thinkingSmoother.destroy();
|
|
11998
12039
|
disarmWatchdog();
|
|
11999
12040
|
idleController.abort();
|
|
12000
12041
|
};
|
|
@@ -12078,15 +12119,24 @@ async function resumeStream(options) {
|
|
|
12078
12119
|
statusCode
|
|
12079
12120
|
};
|
|
12080
12121
|
}
|
|
12081
|
-
|
|
12082
|
-
|
|
12083
|
-
|
|
12122
|
+
settled = true;
|
|
12123
|
+
disarmWatchdog();
|
|
12124
|
+
try {
|
|
12125
|
+
if (idleFired) return buildInterrupted(abortMessage());
|
|
12126
|
+
if (accumulator.toolCalls.size > 0) {
|
|
12127
|
+
return buildInterrupted("Stream ended with a pending tool request");
|
|
12128
|
+
}
|
|
12129
|
+
draining = true;
|
|
12130
|
+
await Promise.all([contentSmoother.drain(), thinkingSmoother.drain()]);
|
|
12131
|
+
if (playbackAborted) return buildInterrupted(abortMessage());
|
|
12132
|
+
const response = strategy.buildFinalResponse(accumulator);
|
|
12133
|
+
const deliveredOutput = emittedOutput || (accumulator.toolCallEvents?.length ?? 0) > 0;
|
|
12134
|
+
if (onFinish && deliveredOutput) onFinish(response);
|
|
12135
|
+
return { data: response, error: null, interrupted: false, empty: !deliveredOutput };
|
|
12136
|
+
} finally {
|
|
12137
|
+
draining = false;
|
|
12138
|
+
cleanup();
|
|
12084
12139
|
}
|
|
12085
|
-
await Promise.all([contentSmoother.drain(), thinkingSmoother.drain()]);
|
|
12086
|
-
const response = strategy.buildFinalResponse(accumulator);
|
|
12087
|
-
const deliveredOutput = emittedOutput || (accumulator.toolCallEvents?.length ?? 0) > 0;
|
|
12088
|
-
if (onFinish && deliveredOutput) onFinish(response);
|
|
12089
|
-
return { data: response, error: null, interrupted: false, empty: !deliveredOutput };
|
|
12090
12140
|
}
|
|
12091
12141
|
|
|
12092
12142
|
// src/lib/chat/stockPriceCentroids.ts
|
package/dist/react/index.mjs
CHANGED
|
@@ -8658,6 +8658,9 @@ var StreamSmoother = class {
|
|
|
8658
8658
|
this.rampDuration = config.rampDuration ?? 4e3;
|
|
8659
8659
|
}
|
|
8660
8660
|
}
|
|
8661
|
+
get hasPendingOutput() {
|
|
8662
|
+
return this.buffer.length > 0;
|
|
8663
|
+
}
|
|
8661
8664
|
/**
|
|
8662
8665
|
* Add text to the buffer. If smoothing is disabled, passes through immediately.
|
|
8663
8666
|
*/
|
|
@@ -9326,6 +9329,34 @@ async function runToolLoop(options) {
|
|
|
9326
9329
|
toolsChecksum: acc.toolsChecksum
|
|
9327
9330
|
};
|
|
9328
9331
|
};
|
|
9332
|
+
const drainSmoothers = async (acc, smoothers) => {
|
|
9333
|
+
let playbackAborted = false;
|
|
9334
|
+
const stopPlayback = () => {
|
|
9335
|
+
for (const smoother of smoothers) {
|
|
9336
|
+
if (isDetach()) smoother.flush();
|
|
9337
|
+
else smoother.destroy();
|
|
9338
|
+
}
|
|
9339
|
+
};
|
|
9340
|
+
const onAbort = () => {
|
|
9341
|
+
playbackAborted = !isDetach() && smoothers.some((smoother) => smoother.hasPendingOutput);
|
|
9342
|
+
stopPlayback();
|
|
9343
|
+
};
|
|
9344
|
+
combinedSignal?.addEventListener("abort", onAbort, { once: true });
|
|
9345
|
+
try {
|
|
9346
|
+
if (combinedSignal?.aborted) stopPlayback();
|
|
9347
|
+
await Promise.all(smoothers.map((smoother) => smoother.drain()));
|
|
9348
|
+
if (!playbackAborted) return;
|
|
9349
|
+
await fireAfterModelCall(buildModelCallEndPayload(acc, { error: "aborted" }));
|
|
9350
|
+
await fireRunError({ error: "Request aborted", stage: "model" });
|
|
9351
|
+
return {
|
|
9352
|
+
data: buildResponseFinal(acc),
|
|
9353
|
+
error: "Request aborted",
|
|
9354
|
+
toolsChecksum: acc.toolsChecksum
|
|
9355
|
+
};
|
|
9356
|
+
} finally {
|
|
9357
|
+
combinedSignal?.removeEventListener("abort", onAbort);
|
|
9358
|
+
}
|
|
9359
|
+
};
|
|
9329
9360
|
for (let attempt = 0; attempt < STREAM_RETRY_MAX_ATTEMPTS; attempt++) {
|
|
9330
9361
|
sseError = null;
|
|
9331
9362
|
if (combinedSignal?.aborted) {
|
|
@@ -9463,7 +9494,8 @@ async function runToolLoop(options) {
|
|
|
9463
9494
|
contentSmoother.flush();
|
|
9464
9495
|
thinkingSmoother.flush();
|
|
9465
9496
|
} else {
|
|
9466
|
-
await
|
|
9497
|
+
const interrupted = await drainSmoothers(accumulator, [contentSmoother, thinkingSmoother]);
|
|
9498
|
+
if (interrupted) return interrupted;
|
|
9467
9499
|
}
|
|
9468
9500
|
flushDeAnon();
|
|
9469
9501
|
await fireAfterModelCall(buildModelCallEndPayload(accumulator));
|
|
@@ -9982,7 +10014,11 @@ Executing tool: ${toolInfo}
|
|
|
9982
10014
|
contContentSmoother.flush();
|
|
9983
10015
|
contThinkingSmoother.flush();
|
|
9984
10016
|
} else {
|
|
9985
|
-
await
|
|
10017
|
+
const interrupted = await drainSmoothers(currentAccumulator, [
|
|
10018
|
+
contContentSmoother,
|
|
10019
|
+
contThinkingSmoother
|
|
10020
|
+
]);
|
|
10021
|
+
if (interrupted) return interrupted;
|
|
9986
10022
|
}
|
|
9987
10023
|
flushDeAnon();
|
|
9988
10024
|
await fireAfterModelCall(buildModelCallEndPayload(currentAccumulator));
|
|
@@ -10113,6 +10149,8 @@ async function resumeStream(options) {
|
|
|
10113
10149
|
let watchdog;
|
|
10114
10150
|
let idleFired = false;
|
|
10115
10151
|
let callerAborted = false;
|
|
10152
|
+
let playbackAborted = false;
|
|
10153
|
+
let draining = false;
|
|
10116
10154
|
let settled = false;
|
|
10117
10155
|
const idleEnabled = idleTimeoutMs > 0 && idleTimeoutMs !== Infinity && typeof setTimeout === "function";
|
|
10118
10156
|
const armWatchdog = () => {
|
|
@@ -10132,6 +10170,9 @@ async function resumeStream(options) {
|
|
|
10132
10170
|
const abortMessage = () => callerAborted ? "Resume aborted" : idleFired ? "Resume timed out" : "Resume aborted";
|
|
10133
10171
|
const onCallerAbort = () => {
|
|
10134
10172
|
callerAborted = true;
|
|
10173
|
+
playbackAborted = draining && (contentSmoother.hasPendingOutput || thinkingSmoother.hasPendingOutput);
|
|
10174
|
+
contentSmoother.destroy();
|
|
10175
|
+
thinkingSmoother.destroy();
|
|
10135
10176
|
disarmWatchdog();
|
|
10136
10177
|
idleController.abort();
|
|
10137
10178
|
};
|
|
@@ -10215,15 +10256,24 @@ async function resumeStream(options) {
|
|
|
10215
10256
|
statusCode
|
|
10216
10257
|
};
|
|
10217
10258
|
}
|
|
10218
|
-
|
|
10219
|
-
|
|
10220
|
-
|
|
10259
|
+
settled = true;
|
|
10260
|
+
disarmWatchdog();
|
|
10261
|
+
try {
|
|
10262
|
+
if (idleFired) return buildInterrupted(abortMessage());
|
|
10263
|
+
if (accumulator.toolCalls.size > 0) {
|
|
10264
|
+
return buildInterrupted("Stream ended with a pending tool request");
|
|
10265
|
+
}
|
|
10266
|
+
draining = true;
|
|
10267
|
+
await Promise.all([contentSmoother.drain(), thinkingSmoother.drain()]);
|
|
10268
|
+
if (playbackAborted) return buildInterrupted(abortMessage());
|
|
10269
|
+
const response = strategy.buildFinalResponse(accumulator);
|
|
10270
|
+
const deliveredOutput = emittedOutput || (accumulator.toolCallEvents?.length ?? 0) > 0;
|
|
10271
|
+
if (onFinish && deliveredOutput) onFinish(response);
|
|
10272
|
+
return { data: response, error: null, interrupted: false, empty: !deliveredOutput };
|
|
10273
|
+
} finally {
|
|
10274
|
+
draining = false;
|
|
10275
|
+
cleanup();
|
|
10221
10276
|
}
|
|
10222
|
-
await Promise.all([contentSmoother.drain(), thinkingSmoother.drain()]);
|
|
10223
|
-
const response = strategy.buildFinalResponse(accumulator);
|
|
10224
|
-
const deliveredOutput = emittedOutput || (accumulator.toolCallEvents?.length ?? 0) > 0;
|
|
10225
|
-
if (onFinish && deliveredOutput) onFinish(response);
|
|
10226
|
-
return { data: response, error: null, interrupted: false, empty: !deliveredOutput };
|
|
10227
10277
|
}
|
|
10228
10278
|
|
|
10229
10279
|
// src/lib/chat/stockPriceCentroids.ts
|
package/dist/server/index.cjs
CHANGED
|
@@ -23874,6 +23874,9 @@ var StreamSmoother = class {
|
|
|
23874
23874
|
this.rampDuration = config.rampDuration ?? 4e3;
|
|
23875
23875
|
}
|
|
23876
23876
|
}
|
|
23877
|
+
get hasPendingOutput() {
|
|
23878
|
+
return this.buffer.length > 0;
|
|
23879
|
+
}
|
|
23877
23880
|
/**
|
|
23878
23881
|
* Add text to the buffer. If smoothing is disabled, passes through immediately.
|
|
23879
23882
|
*/
|
|
@@ -24542,6 +24545,34 @@ async function runToolLoop(options) {
|
|
|
24542
24545
|
toolsChecksum: acc.toolsChecksum
|
|
24543
24546
|
};
|
|
24544
24547
|
};
|
|
24548
|
+
const drainSmoothers = async (acc, smoothers) => {
|
|
24549
|
+
let playbackAborted = false;
|
|
24550
|
+
const stopPlayback = () => {
|
|
24551
|
+
for (const smoother of smoothers) {
|
|
24552
|
+
if (isDetach()) smoother.flush();
|
|
24553
|
+
else smoother.destroy();
|
|
24554
|
+
}
|
|
24555
|
+
};
|
|
24556
|
+
const onAbort = () => {
|
|
24557
|
+
playbackAborted = !isDetach() && smoothers.some((smoother) => smoother.hasPendingOutput);
|
|
24558
|
+
stopPlayback();
|
|
24559
|
+
};
|
|
24560
|
+
combinedSignal?.addEventListener("abort", onAbort, { once: true });
|
|
24561
|
+
try {
|
|
24562
|
+
if (combinedSignal?.aborted) stopPlayback();
|
|
24563
|
+
await Promise.all(smoothers.map((smoother) => smoother.drain()));
|
|
24564
|
+
if (!playbackAborted) return;
|
|
24565
|
+
await fireAfterModelCall(buildModelCallEndPayload(acc, { error: "aborted" }));
|
|
24566
|
+
await fireRunError({ error: "Request aborted", stage: "model" });
|
|
24567
|
+
return {
|
|
24568
|
+
data: buildResponseFinal(acc),
|
|
24569
|
+
error: "Request aborted",
|
|
24570
|
+
toolsChecksum: acc.toolsChecksum
|
|
24571
|
+
};
|
|
24572
|
+
} finally {
|
|
24573
|
+
combinedSignal?.removeEventListener("abort", onAbort);
|
|
24574
|
+
}
|
|
24575
|
+
};
|
|
24545
24576
|
for (let attempt = 0; attempt < STREAM_RETRY_MAX_ATTEMPTS; attempt++) {
|
|
24546
24577
|
sseError = null;
|
|
24547
24578
|
if (combinedSignal?.aborted) {
|
|
@@ -24679,7 +24710,8 @@ async function runToolLoop(options) {
|
|
|
24679
24710
|
contentSmoother.flush();
|
|
24680
24711
|
thinkingSmoother.flush();
|
|
24681
24712
|
} else {
|
|
24682
|
-
await
|
|
24713
|
+
const interrupted = await drainSmoothers(accumulator, [contentSmoother, thinkingSmoother]);
|
|
24714
|
+
if (interrupted) return interrupted;
|
|
24683
24715
|
}
|
|
24684
24716
|
flushDeAnon();
|
|
24685
24717
|
await fireAfterModelCall(buildModelCallEndPayload(accumulator));
|
|
@@ -25198,7 +25230,11 @@ Executing tool: ${toolInfo}
|
|
|
25198
25230
|
contContentSmoother.flush();
|
|
25199
25231
|
contThinkingSmoother.flush();
|
|
25200
25232
|
} else {
|
|
25201
|
-
await
|
|
25233
|
+
const interrupted = await drainSmoothers(currentAccumulator, [
|
|
25234
|
+
contContentSmoother,
|
|
25235
|
+
contThinkingSmoother
|
|
25236
|
+
]);
|
|
25237
|
+
if (interrupted) return interrupted;
|
|
25202
25238
|
}
|
|
25203
25239
|
flushDeAnon();
|
|
25204
25240
|
await fireAfterModelCall(buildModelCallEndPayload(currentAccumulator));
|
|
@@ -25329,6 +25365,8 @@ async function resumeStream(options) {
|
|
|
25329
25365
|
let watchdog;
|
|
25330
25366
|
let idleFired = false;
|
|
25331
25367
|
let callerAborted = false;
|
|
25368
|
+
let playbackAborted = false;
|
|
25369
|
+
let draining = false;
|
|
25332
25370
|
let settled = false;
|
|
25333
25371
|
const idleEnabled = idleTimeoutMs > 0 && idleTimeoutMs !== Infinity && typeof setTimeout === "function";
|
|
25334
25372
|
const armWatchdog = () => {
|
|
@@ -25348,6 +25386,9 @@ async function resumeStream(options) {
|
|
|
25348
25386
|
const abortMessage = () => callerAborted ? "Resume aborted" : idleFired ? "Resume timed out" : "Resume aborted";
|
|
25349
25387
|
const onCallerAbort = () => {
|
|
25350
25388
|
callerAborted = true;
|
|
25389
|
+
playbackAborted = draining && (contentSmoother.hasPendingOutput || thinkingSmoother.hasPendingOutput);
|
|
25390
|
+
contentSmoother.destroy();
|
|
25391
|
+
thinkingSmoother.destroy();
|
|
25351
25392
|
disarmWatchdog();
|
|
25352
25393
|
idleController.abort();
|
|
25353
25394
|
};
|
|
@@ -25431,15 +25472,24 @@ async function resumeStream(options) {
|
|
|
25431
25472
|
statusCode
|
|
25432
25473
|
};
|
|
25433
25474
|
}
|
|
25434
|
-
|
|
25435
|
-
|
|
25436
|
-
|
|
25475
|
+
settled = true;
|
|
25476
|
+
disarmWatchdog();
|
|
25477
|
+
try {
|
|
25478
|
+
if (idleFired) return buildInterrupted(abortMessage());
|
|
25479
|
+
if (accumulator.toolCalls.size > 0) {
|
|
25480
|
+
return buildInterrupted("Stream ended with a pending tool request");
|
|
25481
|
+
}
|
|
25482
|
+
draining = true;
|
|
25483
|
+
await Promise.all([contentSmoother.drain(), thinkingSmoother.drain()]);
|
|
25484
|
+
if (playbackAborted) return buildInterrupted(abortMessage());
|
|
25485
|
+
const response = strategy.buildFinalResponse(accumulator);
|
|
25486
|
+
const deliveredOutput = emittedOutput || (accumulator.toolCallEvents?.length ?? 0) > 0;
|
|
25487
|
+
if (onFinish && deliveredOutput) onFinish(response);
|
|
25488
|
+
return { data: response, error: null, interrupted: false, empty: !deliveredOutput };
|
|
25489
|
+
} finally {
|
|
25490
|
+
draining = false;
|
|
25491
|
+
cleanup();
|
|
25437
25492
|
}
|
|
25438
|
-
await Promise.all([contentSmoother.drain(), thinkingSmoother.drain()]);
|
|
25439
|
-
const response = strategy.buildFinalResponse(accumulator);
|
|
25440
|
-
const deliveredOutput = emittedOutput || (accumulator.toolCallEvents?.length ?? 0) > 0;
|
|
25441
|
-
if (onFinish && deliveredOutput) onFinish(response);
|
|
25442
|
-
return { data: response, error: null, interrupted: false, empty: !deliveredOutput };
|
|
25443
25493
|
}
|
|
25444
25494
|
|
|
25445
25495
|
// src/lib/chat/stockPriceCentroids.ts
|
package/dist/server/index.mjs
CHANGED
|
@@ -22143,6 +22143,9 @@ var StreamSmoother = class {
|
|
|
22143
22143
|
this.rampDuration = config.rampDuration ?? 4e3;
|
|
22144
22144
|
}
|
|
22145
22145
|
}
|
|
22146
|
+
get hasPendingOutput() {
|
|
22147
|
+
return this.buffer.length > 0;
|
|
22148
|
+
}
|
|
22146
22149
|
/**
|
|
22147
22150
|
* Add text to the buffer. If smoothing is disabled, passes through immediately.
|
|
22148
22151
|
*/
|
|
@@ -22811,6 +22814,34 @@ async function runToolLoop(options) {
|
|
|
22811
22814
|
toolsChecksum: acc.toolsChecksum
|
|
22812
22815
|
};
|
|
22813
22816
|
};
|
|
22817
|
+
const drainSmoothers = async (acc, smoothers) => {
|
|
22818
|
+
let playbackAborted = false;
|
|
22819
|
+
const stopPlayback = () => {
|
|
22820
|
+
for (const smoother of smoothers) {
|
|
22821
|
+
if (isDetach()) smoother.flush();
|
|
22822
|
+
else smoother.destroy();
|
|
22823
|
+
}
|
|
22824
|
+
};
|
|
22825
|
+
const onAbort = () => {
|
|
22826
|
+
playbackAborted = !isDetach() && smoothers.some((smoother) => smoother.hasPendingOutput);
|
|
22827
|
+
stopPlayback();
|
|
22828
|
+
};
|
|
22829
|
+
combinedSignal?.addEventListener("abort", onAbort, { once: true });
|
|
22830
|
+
try {
|
|
22831
|
+
if (combinedSignal?.aborted) stopPlayback();
|
|
22832
|
+
await Promise.all(smoothers.map((smoother) => smoother.drain()));
|
|
22833
|
+
if (!playbackAborted) return;
|
|
22834
|
+
await fireAfterModelCall(buildModelCallEndPayload(acc, { error: "aborted" }));
|
|
22835
|
+
await fireRunError({ error: "Request aborted", stage: "model" });
|
|
22836
|
+
return {
|
|
22837
|
+
data: buildResponseFinal(acc),
|
|
22838
|
+
error: "Request aborted",
|
|
22839
|
+
toolsChecksum: acc.toolsChecksum
|
|
22840
|
+
};
|
|
22841
|
+
} finally {
|
|
22842
|
+
combinedSignal?.removeEventListener("abort", onAbort);
|
|
22843
|
+
}
|
|
22844
|
+
};
|
|
22814
22845
|
for (let attempt = 0; attempt < STREAM_RETRY_MAX_ATTEMPTS; attempt++) {
|
|
22815
22846
|
sseError = null;
|
|
22816
22847
|
if (combinedSignal?.aborted) {
|
|
@@ -22948,7 +22979,8 @@ async function runToolLoop(options) {
|
|
|
22948
22979
|
contentSmoother.flush();
|
|
22949
22980
|
thinkingSmoother.flush();
|
|
22950
22981
|
} else {
|
|
22951
|
-
await
|
|
22982
|
+
const interrupted = await drainSmoothers(accumulator, [contentSmoother, thinkingSmoother]);
|
|
22983
|
+
if (interrupted) return interrupted;
|
|
22952
22984
|
}
|
|
22953
22985
|
flushDeAnon();
|
|
22954
22986
|
await fireAfterModelCall(buildModelCallEndPayload(accumulator));
|
|
@@ -23467,7 +23499,11 @@ Executing tool: ${toolInfo}
|
|
|
23467
23499
|
contContentSmoother.flush();
|
|
23468
23500
|
contThinkingSmoother.flush();
|
|
23469
23501
|
} else {
|
|
23470
|
-
await
|
|
23502
|
+
const interrupted = await drainSmoothers(currentAccumulator, [
|
|
23503
|
+
contContentSmoother,
|
|
23504
|
+
contThinkingSmoother
|
|
23505
|
+
]);
|
|
23506
|
+
if (interrupted) return interrupted;
|
|
23471
23507
|
}
|
|
23472
23508
|
flushDeAnon();
|
|
23473
23509
|
await fireAfterModelCall(buildModelCallEndPayload(currentAccumulator));
|
|
@@ -23598,6 +23634,8 @@ async function resumeStream(options) {
|
|
|
23598
23634
|
let watchdog;
|
|
23599
23635
|
let idleFired = false;
|
|
23600
23636
|
let callerAborted = false;
|
|
23637
|
+
let playbackAborted = false;
|
|
23638
|
+
let draining = false;
|
|
23601
23639
|
let settled = false;
|
|
23602
23640
|
const idleEnabled = idleTimeoutMs > 0 && idleTimeoutMs !== Infinity && typeof setTimeout === "function";
|
|
23603
23641
|
const armWatchdog = () => {
|
|
@@ -23617,6 +23655,9 @@ async function resumeStream(options) {
|
|
|
23617
23655
|
const abortMessage = () => callerAborted ? "Resume aborted" : idleFired ? "Resume timed out" : "Resume aborted";
|
|
23618
23656
|
const onCallerAbort = () => {
|
|
23619
23657
|
callerAborted = true;
|
|
23658
|
+
playbackAborted = draining && (contentSmoother.hasPendingOutput || thinkingSmoother.hasPendingOutput);
|
|
23659
|
+
contentSmoother.destroy();
|
|
23660
|
+
thinkingSmoother.destroy();
|
|
23620
23661
|
disarmWatchdog();
|
|
23621
23662
|
idleController.abort();
|
|
23622
23663
|
};
|
|
@@ -23700,15 +23741,24 @@ async function resumeStream(options) {
|
|
|
23700
23741
|
statusCode
|
|
23701
23742
|
};
|
|
23702
23743
|
}
|
|
23703
|
-
|
|
23704
|
-
|
|
23705
|
-
|
|
23744
|
+
settled = true;
|
|
23745
|
+
disarmWatchdog();
|
|
23746
|
+
try {
|
|
23747
|
+
if (idleFired) return buildInterrupted(abortMessage());
|
|
23748
|
+
if (accumulator.toolCalls.size > 0) {
|
|
23749
|
+
return buildInterrupted("Stream ended with a pending tool request");
|
|
23750
|
+
}
|
|
23751
|
+
draining = true;
|
|
23752
|
+
await Promise.all([contentSmoother.drain(), thinkingSmoother.drain()]);
|
|
23753
|
+
if (playbackAborted) return buildInterrupted(abortMessage());
|
|
23754
|
+
const response = strategy.buildFinalResponse(accumulator);
|
|
23755
|
+
const deliveredOutput = emittedOutput || (accumulator.toolCallEvents?.length ?? 0) > 0;
|
|
23756
|
+
if (onFinish && deliveredOutput) onFinish(response);
|
|
23757
|
+
return { data: response, error: null, interrupted: false, empty: !deliveredOutput };
|
|
23758
|
+
} finally {
|
|
23759
|
+
draining = false;
|
|
23760
|
+
cleanup();
|
|
23706
23761
|
}
|
|
23707
|
-
await Promise.all([contentSmoother.drain(), thinkingSmoother.drain()]);
|
|
23708
|
-
const response = strategy.buildFinalResponse(accumulator);
|
|
23709
|
-
const deliveredOutput = emittedOutput || (accumulator.toolCallEvents?.length ?? 0) > 0;
|
|
23710
|
-
if (onFinish && deliveredOutput) onFinish(response);
|
|
23711
|
-
return { data: response, error: null, interrupted: false, empty: !deliveredOutput };
|
|
23712
23762
|
}
|
|
23713
23763
|
|
|
23714
23764
|
// src/lib/chat/stockPriceCentroids.ts
|