Build Scene (/build-scene): three.js + mannequin-js blockout viewport ported from open-media, with per-session compositions (origin='scene' keeps rails separate), agent shot_* tools as the only toolset for that surface, viewport toolbar, keyframe motion + camera timeline with 60s video export, and captures usable as project reference images. Scene to Clips: clips table (1 scene : N renderable shots), coverage agent breaks scenes into shots with full dialogue/action allocation, script generation stays faithful to the screenplay (verbatim dialogue, content- derived durations, chunked + durable inserts), video pipeline re-scoped to clips (enqueue, continue-from, export, drafts), Script/Video UI clip-first (#N.M labels, per-scene Break Into Shots scoped to one scene). Agent loop: lean ReAct discipline with fail-streak escalation and budget nudge; policy treats explicit user commands as permission; Build Scene tool scope enforced mechanically; document + video attachments feed the VLM.
90 lines
2.2 KiB
TypeScript
90 lines
2.2 KiB
TypeScript
export type CalliopeEvent = {
|
|
type: string;
|
|
data: Record<string, unknown>;
|
|
ts: string;
|
|
};
|
|
|
|
/**
|
|
* SSE connection lifecycle:
|
|
* - `connecting` — first attach attempt in flight
|
|
* - `open` — stream established (EventSource.onopen fired)
|
|
* - `reconnecting` — stream dropped; the 3s re-attach loop is running
|
|
*/
|
|
export type EventConnectionState = 'connecting' | 'open' | 'reconnecting';
|
|
|
|
type Listener = (event: CalliopeEvent) => void;
|
|
type StateListener = (state: EventConnectionState) => void;
|
|
|
|
export function connectEvents(
|
|
onEvent: Listener,
|
|
onState?: StateListener,
|
|
): (signal?: AbortSignal) => void {
|
|
let es: EventSource | null = null;
|
|
let closed = false;
|
|
let firstAttach = true;
|
|
let everOpened = false;
|
|
let reconnectTimer: ReturnType<typeof setTimeout> | null = null;
|
|
|
|
const attach = () => {
|
|
if (closed) return;
|
|
onState?.(firstAttach ? 'connecting' : 'reconnecting');
|
|
firstAttach = false;
|
|
es = new EventSource('/api/events');
|
|
es.onopen = () => {
|
|
onState?.('open');
|
|
// Reconnected after a drop: everything missed while the stream was
|
|
// down is gone forever (no replay), so ask the page to refetch.
|
|
// Listeners gate on `everOpened` so the very first open is a no-op.
|
|
if (everOpened) {
|
|
onEvent({ type: 'events.resync', data: {}, ts: new Date().toISOString() });
|
|
}
|
|
everOpened = true;
|
|
};
|
|
const handler = (e: MessageEvent) => {
|
|
try {
|
|
const parsed = JSON.parse(e.data) as CalliopeEvent;
|
|
onEvent(parsed);
|
|
} catch {
|
|
/* ignore */
|
|
}
|
|
};
|
|
// Listen to named events + default message
|
|
[
|
|
'agent.thinking',
|
|
'agent.session.updated',
|
|
'agent.message',
|
|
'agent.token',
|
|
'agent.tool',
|
|
'agent.plan',
|
|
'agent.task',
|
|
'job.created',
|
|
'job.started',
|
|
'job.progress',
|
|
'job.completed',
|
|
'job.failed',
|
|
'job.deleted',
|
|
'asset.ready',
|
|
'story.ready',
|
|
'canvas.updated',
|
|
'shot.updated',
|
|
'shot.capture.saved',
|
|
].forEach((name) => es!.addEventListener(name, handler as EventListener));
|
|
es.onmessage = handler;
|
|
es.onerror = () => {
|
|
onState?.('reconnecting');
|
|
es?.close();
|
|
if (!closed) {
|
|
reconnectTimer = setTimeout(attach, 3000);
|
|
}
|
|
};
|
|
};
|
|
|
|
attach();
|
|
|
|
return () => {
|
|
closed = true;
|
|
if (reconnectTimer) clearTimeout(reconnectTimer);
|
|
es?.close();
|
|
};
|
|
}
|