@tanstack/ai-client 0.29.0 → 0.29.2
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/esm/chat-client.d.ts +6 -0
- package/dist/esm/chat-client.js +28 -4
- package/dist/esm/chat-client.js.map +1 -1
- package/dist/esm/connection-adapters.js +15 -0
- package/dist/esm/connection-adapters.js.map +1 -1
- package/dist/esm/devtools-noop.d.ts +3 -0
- package/dist/esm/devtools-noop.js +3 -0
- package/dist/esm/devtools-noop.js.map +1 -1
- package/dist/esm/devtools.d.ts +15 -1
- package/dist/esm/devtools.js +149 -10
- package/dist/esm/devtools.js.map +1 -1
- package/package.json +3 -3
- package/src/chat-client.ts +50 -8
- package/src/connection-adapters.ts +23 -0
- package/src/devtools-noop.ts +3 -0
- package/src/devtools.ts +280 -12
|
@@ -480,6 +480,20 @@ function normalizeConnectionAdapter(connection) {
|
|
|
480
480
|
if (waiter) waiter(chunk);
|
|
481
481
|
else activeBuffer.push(chunk);
|
|
482
482
|
}
|
|
483
|
+
async function waitUntilSubscriberIdle(abortSignal) {
|
|
484
|
+
const idle = () => activeBuffer.length === 0 && (activeWaiters.length > 0 || abortSignal?.aborted);
|
|
485
|
+
for (let i = 0; i < 16 && !abortSignal?.aborted; i++) {
|
|
486
|
+
if (idle()) return;
|
|
487
|
+
await Promise.resolve();
|
|
488
|
+
}
|
|
489
|
+
let macrotaskWaits = 0;
|
|
490
|
+
while (!abortSignal?.aborted) {
|
|
491
|
+
if (idle()) return;
|
|
492
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
493
|
+
macrotaskWaits++;
|
|
494
|
+
if (activeWaiters.length === 0 && macrotaskWaits >= 32) return;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
483
497
|
return {
|
|
484
498
|
subscribe(abortSignal) {
|
|
485
499
|
const myBuffer = activeBuffer.splice(0);
|
|
@@ -537,6 +551,7 @@ function normalizeConnectionAdapter(connection) {
|
|
|
537
551
|
} catch {}
|
|
538
552
|
throw err;
|
|
539
553
|
}
|
|
554
|
+
await waitUntilSubscriberIdle(abortSignal);
|
|
540
555
|
},
|
|
541
556
|
...typeof connection.joinRun === "function" ? { joinRun: (runId, abortSignal) => connection.joinRun(runId, abortSignal) } : {},
|
|
542
557
|
...(() => {
|