mirror of
https://github.com/R0m1k3/EveFlow.git
synced 2026-10-15 03:07:06 +02:00
Electron main - utility-process channel: sherpa output copied into V8 buffers (Electron rejects external buffers), audio exchanged as base64; worker restart on timeout, identity-safe exit handling, deterministic native unload by restart - webhook: loopback by default without secret, UTF-8-safe body assembly, clean restart, port validation - files IPC: realpath-based root check, openPath allow-list (reveal-only outside document folders), Windows reserved names; store: debounced async atomic writes with backup of corrupt files; logger: streaming writes with rotation; log message size cap - HTTP stream proxy: socket released on idle timeout / renderer destroyed, id validation - model manager: inactivity timeout, retrying rm/rename (Windows locks), engine stopped before replacing a model; WAV decoder handles float/24-bit; IPC payload validation - window: opaque rounded window on Windows, navigation lock-down, visibility events; Ctrl+Alt+Escape instead of the Task Manager shortcut; single-instance guard; EVEFLOW_USER_DATA Voice pipeline - abort semantics (SendHandle.aborted), abort before the stream opens, session id prefixes per transport - hands-free re-arm after replies without speech, start/stop race, no chime on auto re-arm, no silence shipped to STT (400 ms pre-roll), no transcription of empty manual stops - TTS: bounded prefetch, cancellable segments, non-interrupting notices, volume applied at play time - SSE CRLF split, usage in chat completions, finish_reason length, phonetic regex hoisted HUD - core renderer: no canvas shadows, cached colours, reusable spectrum buffer, theme read on change, 30 fps idle, stops when the window is hidden; ping flashes on send / tool / speech - deltas coalesced per animation frame; stable auto-scroll; narrow selectors everywhere - bundled fonts (offline), reduce-motion fix, error toasts, ops drawer below 1180 px, interim transcript and first-token latency in the core caption, Ctrl+K, dialog semantics, switch/aria roles, compact widget cleanup, Whisper small recommended for French - docs/ROADMAP.md: audit results, e2e results and the plan towards a real JARVIS Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017Wn5VX9HNbJ7N54hR24u9Y
76 lines
2.2 KiB
TypeScript
76 lines
2.2 KiB
TypeScript
export interface SseMessage {
|
|
event: string;
|
|
data: string;
|
|
id?: string;
|
|
}
|
|
|
|
/**
|
|
* Incremental Server-Sent Events parser (spec-compliant subset: event/data/id/comments,
|
|
* multi-line data joined with "\n", CRLF tolerant). Feed arbitrary text chunks.
|
|
*/
|
|
export class SseParser {
|
|
private buffer = '';
|
|
private event = '';
|
|
private data: string[] = [];
|
|
private id: string | undefined;
|
|
|
|
constructor(private readonly onMessage: (message: SseMessage) => void) {}
|
|
|
|
feed(chunk: string): void {
|
|
this.buffer += chunk;
|
|
let index: number;
|
|
while ((index = this.buffer.search(/\r\n|\n|\r/)) !== -1) {
|
|
// A trailing "\r" may be the first half of a "\r\n" split across chunks: wait for more data.
|
|
if (this.buffer[index] === '\r' && index === this.buffer.length - 1) break;
|
|
const line = this.buffer.slice(0, index);
|
|
const sepLength = this.buffer.startsWith('\r\n', index) ? 2 : 1;
|
|
this.buffer = this.buffer.slice(index + sepLength);
|
|
this.processLine(line);
|
|
}
|
|
}
|
|
|
|
/** Flush any pending message (call when the stream ends). */
|
|
end(): void {
|
|
if (this.buffer.length) {
|
|
const rest = this.buffer;
|
|
this.buffer = '';
|
|
this.processLine(rest);
|
|
}
|
|
this.dispatch();
|
|
}
|
|
|
|
private processLine(line: string): void {
|
|
if (line === '') {
|
|
this.dispatch();
|
|
return;
|
|
}
|
|
if (line.startsWith(':')) return;
|
|
const colon = line.indexOf(':');
|
|
const field = colon === -1 ? line : line.slice(0, colon);
|
|
let value = colon === -1 ? '' : line.slice(colon + 1);
|
|
if (value.startsWith(' ')) value = value.slice(1);
|
|
switch (field) {
|
|
case 'event': this.event = value; break;
|
|
case 'data': this.data.push(value); break;
|
|
case 'id': this.id = value; break;
|
|
default: break;
|
|
}
|
|
}
|
|
|
|
private dispatch(): void {
|
|
if (this.data.length === 0 && !this.event) return;
|
|
const message: SseMessage = { event: this.event || 'message', data: this.data.join('\n'), id: this.id };
|
|
this.event = '';
|
|
this.data = [];
|
|
this.onMessage(message);
|
|
}
|
|
}
|
|
|
|
export function tryParseJson<T = unknown>(text: string): T | null {
|
|
try {
|
|
return JSON.parse(text) as T;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|