mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-10-16 20:02:20 +02:00
Preserve preview harness, editor, email and task improvements
Snapshot current maintainer-preview application changes and regression fixtures for integration into lab. Excludes local runtime data, evaluation outputs and source backups. Focused Python regression selection: 140 passed; full suite not certified.
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
export async function readEmailReplyResponse(response, onReply) {
|
||||
if (!response.ok) throw new Error(`AI reply service returned HTTP ${response.status}`);
|
||||
if (!response.headers.get('content-type')?.includes('text/event-stream')) return response.json();
|
||||
const reader = response.body.getReader();
|
||||
const decoder = new TextDecoder();
|
||||
let buffer = '';
|
||||
try {
|
||||
while (true) {
|
||||
const { value, done } = await reader.read();
|
||||
buffer += decoder.decode(value || new Uint8Array(), { stream: !done });
|
||||
let boundary;
|
||||
while ((boundary = buffer.indexOf('\n\n')) !== -1) {
|
||||
const frame = buffer.slice(0, boundary);
|
||||
buffer = buffer.slice(boundary + 2);
|
||||
for (const line of frame.split('\n')) {
|
||||
if (!line.startsWith('data: ')) continue;
|
||||
const event = JSON.parse(line.slice(6));
|
||||
if (event.type === 'reply' && onReply(event.text) === false) {
|
||||
throw new Error('Draft was edited or closed; AI insertion stopped');
|
||||
}
|
||||
if (event.type === 'result') return event;
|
||||
}
|
||||
}
|
||||
if (done) throw new Error('AI reply connection ended before completion');
|
||||
}
|
||||
} finally {
|
||||
await reader.cancel();
|
||||
reader.releaseLock();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user