Skip to content

an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions

feat(realtime): wire Oscar's rt-9 cost engine into the core (spawn estimate + session meter)

Chaitanya Giri57fafe133ad5
diff --git a/src/main/realtimeActions.ts b/src/main/realtimeActions.ts
index 97346e8a..dc6c6e9a 100644
--- a/src/main/realtimeActions.ts
+++ b/src/main/realtimeActions.ts
@@ -37,6 +37,7 @@
import { ipcMain } from 'electron';
import type { HiveMessage, HiveTask, Registry } from './hive';
import type { ScheduledMission } from './config';
+import { spawnCostSpoken } from './realtimeCost';
export const VOICE_ACTOR = 'michael-voice';
@@ -428,8 +429,8 @@ function proposeDestructive(deps: RealtimeActionDeps, verb: string, a: Record<st
return {
ok: true,
needsConfirm: true,
- // STUB estimate — rt-9 replaces "roughly a few dollars an hour" with a real figure.
- spoken: `You want to hire a new ${provider} agent${role ? ` as ${role}` : ''}, named ${name}. Estimated cost is pending real numbers from the cost guard — roughly a few dollars an hour while it runs. To hire, say "confirm" or "spawn". Say "cancel" to stop.`
+ // Real spawn cost estimate from Oscar's rt-9 cost engine (replaces the rt-5 stub).
+ spoken: `You want to hire a new ${provider} agent${role ? ` as ${role}` : ''}, named ${name}. That will cost ${spawnCostSpoken(provider, str(a.model) || undefined)}. To hire, say "confirm" or "spawn". Say "cancel" to stop.`
};
}
diff --git a/src/renderer/src/realtime/session.ts b/src/renderer/src/realtime/session.ts
index 8d00d1a3..6d7ee90d 100644
--- a/src/renderer/src/realtime/session.ts
+++ b/src/renderer/src/realtime/session.ts
@@ -27,6 +27,7 @@ import { useSyncExternalStore } from 'react';
import { RealtimeAgent, RealtimeSession, OpenAIRealtimeWebRTC } from '@openai/agents-realtime';
import { realtimeReadTools, realtimeSessionSummary } from './tools';
import { realtimeActionTools } from './actions';
+import { resetRealtimeCost, recordRealtimeUsage, endRealtimeCost } from './costStore';
/**
* Voice-loop state machine:
@@ -148,6 +149,20 @@ function wire(s: RealtimeSession): void {
const msg = e instanceof Error ? e.message : typeof e === 'string' ? e : 'realtime session error';
setState({ error: msg });
});
+
+ // rt-9 cost meter: each completed response reports token usage on the raw transport
+ // `response.done` event. Hand it straight to Oscar's cost store (its normalizer
+ // tolerates camel/snake-case + missing fields). Best-effort — never break the loop.
+ s.on('transport_event', (event) => {
+ try {
+ const ev = event as { type?: string; response?: { usage?: unknown } };
+ if (ev.type === 'response.done' && ev.response?.usage) {
+ recordRealtimeUsage(ev.response.usage as Parameters<typeof recordRealtimeUsage>[0], Date.now());
+ }
+ } catch {
+ /* metering is best-effort */
+ }
+ });
}
/** Stop the mic + release the audio sink. Safe to call repeatedly. */
@@ -290,6 +305,7 @@ export async function connect(): Promise<void> {
await s.connect({ apiKey: mint.token, model: mint.sessionConfig.model });
session = s;
+ resetRealtimeCost(Date.now()); // rt-9: start the live session cost meter
setState({
status: 'listening',
muted: false,
@@ -322,6 +338,7 @@ export function disconnect(): void {
}
session = null;
teardownMedia();
+ endRealtimeCost(); // rt-9: freeze the session cost meter
// Close the main-process mic gate so the realtime flag doesn't keep the mic permission
// open after we've stopped (fire-and-forget — tracks are already stopped above).
void setMicGate(false);