feat(ui): show actual model route and inspect live stream evidence
This commit is contained in:
@@ -14,7 +14,8 @@ export function mobileSession(store, runtime, session, redact = String) {
|
||||
progress: { total: tools.length, completed: tools.filter(value => value.state === 'completed').length,
|
||||
unknown: tools.filter(value => value.requiresVerification).map(value => pick(value, ['id', 'tool', 'state', 'runId'])) },
|
||||
events: session.events.slice(-60).map(value => ({ ...pick(value, ['id', 'kind', 'phase', 'taskId', 'runId', 'createdAt', 'exitCode', 'durationMs']),
|
||||
label: String(value.label ?? value.tool ?? '').slice(0, 240), output: String(value.output ?? '').slice(-4000) })),
|
||||
label: String(value.label ?? value.tool ?? '').slice(0, 240), output: String(value.output ?? '').slice(-4000),
|
||||
...(value.stream ? { stream: { ...pick(value.stream, ['status', 'protocol', 'sequence', 'bytes', 'textCharacters', 'toolFragments']), textPreview: String(value.stream.textPreview ?? '').slice(0, 4000) } } : {}) })),
|
||||
messages: session.messages.filter(value => ['assistant', 'system'].includes(value.role)).slice(-8).map(value => ({ ...pick(value, ['id', 'role', 'createdAt']), content: String(value.content).slice(0, 12000) })),
|
||||
approvals: session.approvals.filter(value => value.status === 'pending' && value.taskId === session.taskId && value.runId === session.runId).map(value => ({
|
||||
...pick(value, ['id', 'taskId', 'runId', 'projectId', 'command', 'reason', 'shell', 'createdAt']),
|
||||
|
||||
@@ -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' } });
|
||||
|
||||
Reference in New Issue
Block a user