@tangle-network/agent-app 1.0.23 → 1.0.25
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/assistant/index.js +1 -1
- package/dist/{chunk-GN5JME4V.js → chunk-3VEXCVZB.js} +38 -14
- package/dist/chunk-3VEXCVZB.js.map +1 -0
- package/dist/settings-react/index.js +14 -4
- package/dist/settings-react/index.js.map +1 -1
- package/dist/settings-react/settings-layout.d.ts +2 -5
- package/dist/settings-react/settings-save-bar.d.ts +8 -12
- package/dist/stories/settings/save-group-demo.d.ts +2 -4
- package/dist/web-react/chat-stream.d.ts +27 -9
- package/dist/web-react/index.js +3 -1
- package/package.json +1 -1
- package/dist/chunk-GN5JME4V.js.map +0 -1
package/dist/assistant/index.js
CHANGED
|
@@ -154,6 +154,7 @@ function dispatchChatStreamLine(line, cb) {
|
|
|
154
154
|
} catch {
|
|
155
155
|
return { receivedContent };
|
|
156
156
|
}
|
|
157
|
+
const seq = typeof parsed.seq === "number" && Number.isInteger(parsed.seq) && parsed.seq > 0 ? parsed.seq : void 0;
|
|
157
158
|
if (parsed.kind === "tool_result") {
|
|
158
159
|
cb.onToolResult?.({
|
|
159
160
|
toolCallId: parsed.toolCallId,
|
|
@@ -161,7 +162,7 @@ function dispatchChatStreamLine(line, cb) {
|
|
|
161
162
|
label: parsed.label,
|
|
162
163
|
outcome: parsed.outcome ?? parsed.result
|
|
163
164
|
});
|
|
164
|
-
return { receivedContent: true };
|
|
165
|
+
return seq === void 0 ? { receivedContent: true } : { receivedContent: true, seq };
|
|
165
166
|
}
|
|
166
167
|
const evt = parsed.kind === "event" ? parsed.event : parsed;
|
|
167
168
|
if (!evt || typeof evt !== "object") return { receivedContent };
|
|
@@ -286,14 +287,15 @@ The agent hit an error and this turn stopped: ${message}`);
|
|
|
286
287
|
break;
|
|
287
288
|
}
|
|
288
289
|
}
|
|
289
|
-
return { turnId, receivedContent };
|
|
290
|
+
return seq === void 0 ? { turnId, receivedContent } : { turnId, receivedContent, seq };
|
|
290
291
|
}
|
|
291
|
-
async function consumeChatStream(body, cb) {
|
|
292
|
+
async function consumeChatStream(body, cb, seen) {
|
|
292
293
|
const reader = body.getReader();
|
|
293
294
|
const decoder = new TextDecoder();
|
|
294
295
|
let buffer = "";
|
|
295
296
|
let turnId = null;
|
|
296
297
|
let receivedContent = false;
|
|
298
|
+
let lastSeq = 0;
|
|
297
299
|
const owned = !trackedCallbacks.has(cb) && cb.onReasoningState ? trackChatReasoning(cb) : null;
|
|
298
300
|
const callbacks = owned ?? cb;
|
|
299
301
|
const handle = (line) => {
|
|
@@ -303,6 +305,10 @@ async function consumeChatStream(body, cb) {
|
|
|
303
305
|
cb.onTurnId?.(r.turnId);
|
|
304
306
|
}
|
|
305
307
|
if (r.receivedContent) receivedContent = true;
|
|
308
|
+
if (r.seq !== void 0 && r.seq > lastSeq) {
|
|
309
|
+
lastSeq = r.seq;
|
|
310
|
+
if (seen) seen.lastSeq = lastSeq;
|
|
311
|
+
}
|
|
306
312
|
};
|
|
307
313
|
try {
|
|
308
314
|
for (; ; ) {
|
|
@@ -319,7 +325,10 @@ async function consumeChatStream(body, cb) {
|
|
|
319
325
|
} finally {
|
|
320
326
|
owned?.end();
|
|
321
327
|
}
|
|
322
|
-
return { turnId, receivedContent };
|
|
328
|
+
return { turnId, receivedContent, lastSeq };
|
|
329
|
+
}
|
|
330
|
+
function defaultReconnectDelayMs(attempt, rand = Math.random) {
|
|
331
|
+
return Math.min(8e3, 500 * 2 ** attempt * (0.5 + rand()));
|
|
323
332
|
}
|
|
324
333
|
async function streamChatTurn(opts) {
|
|
325
334
|
const res = await settleTurnResponse(await opts.start(), (phase) => opts.callbacks.onPhase?.(phase));
|
|
@@ -337,16 +346,30 @@ async function streamChatTurn(opts) {
|
|
|
337
346
|
};
|
|
338
347
|
const tracked = opts.callbacks.onReasoningState ? trackChatReasoning(withTurnId) : null;
|
|
339
348
|
const cb = tracked ?? withTurnId;
|
|
349
|
+
const maxReconnects = opts.maxReconnects ?? 5;
|
|
350
|
+
const delayMs = opts.reconnectDelayMs ?? defaultReconnectDelayMs;
|
|
351
|
+
const seen = { lastSeq: 0 };
|
|
352
|
+
let attempt = 0;
|
|
353
|
+
let body = res.body;
|
|
354
|
+
let lastErr = null;
|
|
340
355
|
try {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
356
|
+
for (; ; ) {
|
|
357
|
+
try {
|
|
358
|
+
if (!body) throw lastErr instanceof Error ? lastErr : new Error("The turn stream was lost.");
|
|
359
|
+
const r = await consumeChatStream(body, cb, seen);
|
|
360
|
+
return r.turnId ? r : { ...r, turnId };
|
|
361
|
+
} catch (transportErr) {
|
|
362
|
+
lastErr = transportErr;
|
|
363
|
+
if (!turnId || !opts.resume || attempt >= maxReconnects) throw transportErr;
|
|
364
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs(attempt)));
|
|
365
|
+
attempt++;
|
|
366
|
+
if (seen.lastSeq === 0) {
|
|
367
|
+
opts.onResetForResume?.();
|
|
368
|
+
tracked?.replay();
|
|
369
|
+
}
|
|
370
|
+
const resumed = await opts.resume(turnId, seen.lastSeq).catch(() => null);
|
|
371
|
+
body = resumed && resumed.ok && resumed.body ? resumed.body : null;
|
|
372
|
+
}
|
|
350
373
|
}
|
|
351
374
|
} finally {
|
|
352
375
|
tracked?.end();
|
|
@@ -8592,6 +8615,7 @@ export {
|
|
|
8592
8615
|
chatReasoningFromParts,
|
|
8593
8616
|
dispatchChatStreamLine,
|
|
8594
8617
|
consumeChatStream,
|
|
8618
|
+
defaultReconnectDelayMs,
|
|
8595
8619
|
streamChatTurn,
|
|
8596
8620
|
TurnProgress,
|
|
8597
8621
|
useChatScroll,
|
|
@@ -8741,4 +8765,4 @@ export {
|
|
|
8741
8765
|
AgentProfileChoices,
|
|
8742
8766
|
ComposerProfilePill
|
|
8743
8767
|
};
|
|
8744
|
-
//# sourceMappingURL=chunk-
|
|
8768
|
+
//# sourceMappingURL=chunk-3VEXCVZB.js.map
|