feat(ui): show actual model route and inspect live stream evidence

This commit is contained in:
Agent Workbench Dev
2026-10-31 22:42:47 +08:00
parent eeb11d6a76
commit 31ed219477
22 changed files with 276 additions and 38 deletions
+11 -2
View File
@@ -8,10 +8,17 @@ export async function readModelStream(response, config, signal, onProgress) {
const reader = response.body.getReader(), decoder = new TextDecoder('utf-8', { fatal: true }), hash = createHash('sha256');
const chunks = [];
let buffer = '', data = [], bytes = 0, frames = 0, sequence = -1, text = '', done = false, terminal = null, usage = null, finish = null;
let lastProgress = 0, responseId = null, validated = false;
let lastProgress = 0, responseId = null, validated = false, progressTimer = null, progressFailure = null;
const calls = new Map(), responseCalls = new Map();
const progress = force => {
if (!force && Date.now() - lastProgress < 100) return;
if (!force && Date.now() - lastProgress < 100) {
progressTimer ??= setTimeout(() => {
progressTimer = null;
try { progress(true); } catch (cause) { progressFailure = cause; void reader.cancel().catch(() => {}); }
}, 100 - (Date.now() - lastProgress));
return;
}
if (progressTimer) { clearTimeout(progressTimer); progressTimer = null; }
lastProgress = Date.now();
onProgress?.({ phase: 'running', streaming: true, protocol: config.protocol ?? 'chat-completions', streamSequence: frames,
streamBytes: bytes, textPreview: text.slice(0, 8000), textCharacters: text.length, toolFragments: Math.max(calls.size, responseCalls.size) });
@@ -85,6 +92,7 @@ export async function readModelStream(response, config, signal, onProgress) {
while (true) {
signal?.throwIfAborted();
const chunk = await reader.read();
if (progressFailure) throw progressFailure;
signal?.throwIfAborted();
if (chunk.done) break;
bytes += chunk.value.length; hash.update(chunk.value);
@@ -121,6 +129,7 @@ export async function readModelStream(response, config, signal, onProgress) {
validated = true; progress(true);
return { value, evidence: { bytes, frames, sha256: hash.copy().digest('hex'), terminal: true, protocol: config.protocol ?? 'chat-completions' } };
} finally {
if (progressTimer) clearTimeout(progressTimer);
try { await reader.cancel(); } catch {} reader.releaseLock();
onProgress?.({ streamCapture: Buffer.concat(chunks), stream: { bytes, capturedBytes: chunks.reduce((sum, item) => sum + item.length, 0), frames,
sha256: hash.digest('hex'), terminal: validated, terminalSeen: !!terminal || done, protocol: config.protocol ?? 'chat-completions' } });