Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

feat(live): keep the bot's spoken lines in the call record and show them in the call sheet

AdityaUmale4c2fd76a2d14
diff --git a/packages/phone-protocol/src/live-call-wire.ts b/packages/phone-protocol/src/live-call-wire.ts
index 29d60eae99..68c0b8a8af 100644
--- a/packages/phone-protocol/src/live-call-wire.ts
+++ b/packages/phone-protocol/src/live-call-wire.ts
@@ -29,7 +29,14 @@ export interface LiveCallState {
error?: string;
}
-/** One finished Live call, written once when a call that went live ends. Never carries speech. */
+/** A line the bot said aloud on a Live call: when it began (epoch ms) and its words. */
+export interface LiveSpokenLine {
+ at: number;
+ text: string;
+}
+
+/** One finished Live call, written once when a call that went live ends. Of what was said it carries only the bot's own
+ * spoken lines; the person's words stay in the chat as the requests the bot received. */
export interface LiveCallRecord {
callId: string;
botId: string;
@@ -43,6 +50,8 @@ export interface LiveCallRecord {
endReason: LiveEndReason;
/** only when LLM thread titles are on and the engine can generateText */
title?: string;
+ /** what the bot said aloud, in order; absent when the voice session sent no words (Fish, Gemini, ElevenLabs) */
+ spoken?: LiveSpokenLine[];
}
/** Who runs a Live call's voice session: OpenAI itself, a GPT-Live deployment on the user's own Azure OpenAI / Foundry
diff --git a/packages/phone-protocol/src/live-call.ts b/packages/phone-protocol/src/live-call.ts
index ae3024fb13..377f525be4 100644
--- a/packages/phone-protocol/src/live-call.ts
+++ b/packages/phone-protocol/src/live-call.ts
@@ -2,6 +2,8 @@
// *that* it wants help, never *what*: `session.delegation.created` carries an id
// and a timeline offset, so the request is rebuilt from the input transcript.
+import type { LiveSpokenLine } from "./live-call-wire.ts";
+
export interface TranscriptSegment {
text: string;
startMs: number;
@@ -75,6 +77,34 @@ export class LiveTranscript {
}
}
+/** A pause on the session timeline longer than this starts a new spoken line. */
+const SPOKEN_LINE_GAP_MS = 1_000;
+const MAX_SPOKEN_LINES = 2_000;
+
+/** The bot's own words on a call (`session.output_transcript.delta` text), one
+ * line per stretch of speech, for the call record. A delta without timing
+ * continues the current line. */
+export class SpokenLines {
+ private lines: Array<{ at: number; fragments: string[]; endMs: number }> = [];
+
+ add(text: string, at: number, startMs: number, endMs: number): void {
+ if (!text) return;
+ const timed = Number.isFinite(startMs) && Number.isFinite(endMs);
+ const last = this.lines.at(-1);
+ if (last && (!timed || startMs <= last.endMs + SPOKEN_LINE_GAP_MS)) {
+ last.fragments.push(text);
+ if (timed) last.endMs = Math.max(last.endMs, endMs);
+ return;
+ }
+ if (this.lines.length >= MAX_SPOKEN_LINES) return;
+ this.lines.push({ at, fragments: [text], endMs: timed ? endMs : Number.NEGATIVE_INFINITY });
+ }
+
+ list(): LiveSpokenLine[] {
+ return this.lines.map((line) => ({ at: line.at, text: joinFragments(line.fragments) })).filter((line) => line.text);
+ }
+}
+
/** Transcript deltas are fragments of words, not words: glue them as sent. */
export function joinFragments(fragments: string[]): string {
return fragments.join("").replace(/\s+/g, " ").trim();
diff --git a/packages/phone-protocol/src/wire.ts b/packages/phone-protocol/src/wire.ts
index 5109c10a01..728e17e5e0 100644
--- a/packages/phone-protocol/src/wire.ts
+++ b/packages/phone-protocol/src/wire.ts
@@ -39,7 +39,7 @@ import type { CompanionEndpointsSnapshot } from "./responses.ts";
/** What a team bot's main chat is called, beside each person's own chats. */
export const SHARED_CHAT_TITLE = "Shared chat";
-export type { LiveCallRecord, LiveCallState, LiveCallStatus, LiveClient, LiveElevenLabsSession, LiveElevenLabsTransport, LiveEndReason, LiveFishRelayCommand, LiveFishRelayEvent, LiveFishSessionToken, LiveFishTransport, LiveGeminiSession, LiveGeminiTransport, LiveKeySource, LiveProvider, LiveSettings } from "./live-call-wire.ts";
+export type { LiveCallRecord, LiveCallState, LiveCallStatus, LiveClient, LiveElevenLabsSession, LiveElevenLabsTransport, LiveEndReason, LiveFishRelayCommand, LiveFishRelayEvent, LiveFishSessionToken, LiveFishTransport, LiveGeminiSession, LiveGeminiTransport, LiveKeySource, LiveProvider, LiveSettings, LiveSpokenLine } from "./live-call-wire.ts";
export type { ForkOrigin, TaskClosedBy, TaskOpenedBy } from "./task-provenance.ts";
export type { AuthPairResponse, AuthSessionResponse, BotCreateResponse, BotsResponse, BotUpdateResponse, CompanionE2EDescriptor, CompanionEndpointsSnapshot, InstancesResponse, LoopbackSessionResponse, PairedDevice, PairedSession, PairRequest, PairResponse, RoomCreateResponse, RoomTaskCreateResponse, RoomTaskUpdateResponse, RoomUpdateResponse, SearchHit, SearchResponse, SignedInSessionResponse, TaskResponse, WireComputerControl, WireInstance, WireMessagePage, WireModelOption } from "./responses.ts";
diff --git a/server/live-call-controller.test.ts b/server/live-call-controller.test.ts
index 237326df3d..5d39a848b8 100644
--- a/server/live-call-controller.test.ts
+++ b/server/live-call-controller.test.ts
@@ -1697,6 +1697,21 @@ describe("LiveCallController record", () => {
expect(JSON.stringify(recorded(t))).not.toContain("calendar");
});
+ it("keeps what the bot said aloud, one line per stretch of speech, and still nothing the person said", async () => {
+ const t = setup({ recordCall: vi.fn() });
+ await t.start();
+ t.socket().receive({ type: "session.input_transcript.delta", delta: "what is on my calendar", start_ms: 100, end_ms: 900 });
+ t.socket().receive({ type: "session.output_transcript.delta", delta: "You have two ", start_ms: 1_000, end_ms: 1_500 });
+ t.socket().receive({ type: "session.output_transcript.delta", delta: "meetings.", start_ms: 1_500, end_ms: 2_000 });
+ t.socket().receive({ type: "session.input_transcript.delta", delta: "thanks bye", start_ms: 4_000, end_ms: 4_600 });
+ t.socket().receive({ type: "session.output_transcript.delta", delta: "Bye!", start_ms: 5_000, end_ms: 5_400 });
+ t.socket().drop();
+ const record = recorded(t)[0]!.record;
+ expect(record.spoken).toEqual([{ at: expect.any(Number), text: "You have two meetings." }, { at: expect.any(Number), text: "Bye!" }]);
+ expect(JSON.stringify(record)).not.toContain("calendar");
+ expect(JSON.stringify(record)).not.toContain("thanks");
+ });
+
it("counts wall-clock seconds when OpenAI sent none", async () => {
const t = setup({ recordCall: vi.fn() });
await t.start();
diff --git a/server/live-call-controller.ts b/server/live-call-controller.ts
index d90e41141d..e8e68a3252 100644
--- a/server/live-call-controller.ts
+++ b/server/live-call-controller.ts
@@ -4,7 +4,7 @@ import { spokenConsent } from "../shared/call-consent.ts";
import {
LIVE_COPY, liveCardKind, liveStepLabel, spokenApprovalPrompt, spokenConnectorPrompt, spokenQuestionPrompt, spokenReviewPrompt, spokenSecretPrompt, spokenSignInPrompt,
} from "../shared/live-approval.ts";
-import { botCallVoice, clampAppend, commentaryChunks, geminiLiveVoice, LiveTranscript } from "../shared/live-call.ts";
+import { botCallVoice, clampAppend, commentaryChunks, geminiLiveVoice, LiveTranscript, SpokenLines } from "../shared/live-call.ts";
import { signInWaits } from "../shared/sign-in-request.ts";
import type { LiveCallRecord, LiveCallState, LiveClient, LiveElevenLabsTransport, LiveEndReason, LiveFishTransport, LiveGeminiTransport, LiveProvider } from "../shared/wire.ts";
import { FISH_AGENT_VOICE } from "./live-fish.ts";
@@ -128,6 +128,7 @@ interface Call {
socket: LiveSocket | null;
attached: boolean;
transcript: LiveTranscript;
+ spoken: SpokenLines;
heardThroughMs: number;
lastDecision: { throughMs: number; copy: string } | null;
eventCounter: number;
@@ -295,6 +296,7 @@ export class LiveCallController {
socket: null,
attached: false,
transcript: new LiveTranscript(),
+ spoken: new SpokenLines(),
heardThroughMs: 0,
lastDecision: null,
eventCounter: 0,
@@ -435,6 +437,7 @@ export class LiveCallController {
private writeRecord(call: Call, reason: LiveEndReason): void {
if (!call.attached || !this.deps.recordCall) return;
const endedAt = this.now();
+ const spoken = call.spoken.list();
const record: LiveCallRecord = {
callId: call.state.callId,
botId: call.state.botId,
@@ -443,6 +446,7 @@ export class LiveCallController {
endedAt,
seconds: Math.max(0, Math.round(call.stats.seconds ?? (endedAt - call.state.startedAt) / 1000)),
endReason: reason,
+ ...(spoken.length ? { spoken } : {}),
};
try {
this.deps.recordCall({ threadId: call.state.threadId, botName: call.botName, record });
@@ -494,6 +498,7 @@ export class LiveCallController {
return;
case "session.output_transcript.delta":
call.transcript.addOutput(Number(event.start_ms), Number(event.end_ms));
+ call.spoken.add(String(event.delta ?? ""), this.now(), Number(event.start_ms), Number(event.end_ms));
this.touch(call);
return;
case "session.delegation.created": {
diff --git a/server/live-call-record.test.ts b/server/live-call-record.test.ts
index 3a768065fd..d244477cc2 100644
--- a/server/live-call-record.test.ts
+++ b/server/live-call-record.test.ts
@@ -2,6 +2,7 @@ import { readFileSync } from "node:fs";
import { describe, expect, it, vi } from "vitest";
import type { LiveCallRecord } from "../shared/wire.ts";
+import { redactBotAuthored } from "./message-redaction.ts";
import { recordLiveCall, spokenLineFields, titleLiveCall, type LiveCallRecordDeps, type LiveCallTitleDeps } from "./live-call-record.ts";
import { redactSecretsInText } from "./redact.ts";
import type { Message } from "./store.ts";
@@ -42,6 +43,13 @@ describe("recordLiveCall", () => {
expect(appended).toEqual([row]);
});
+ it("scrubs a secret the bot read aloud before its line is stored", () => {
+ const key = "sk-proj-" + "a1B2c3D4e5F6g7H8i9J0".repeat(3);
+ const row = redactBotAuthored({ role: "bot", kind: "call", text: "Call with Ada · 1:42", call: record({ spoken: [{ at: 2_000, text: `Your key is ${key}.` }] }) });
+ expect(row.call?.spoken).toEqual([{ at: 2_000, text: redactSecretsInText(`Your key is ${key}.`) }]);
+ expect(JSON.stringify(row)).not.toContain(key);
+ });
+
it("writes nothing when the call's chat or bot was deleted during the call", () => {
const { deps, appended } = chat(false);
expect(recordLiveCall(deps, { threadId: "t1", botName: "Ada", record: record({ endReason: "deleted" }) })).toBeNull();
diff --git a/server/live-call-record.ts b/server/live-call-record.ts
index c6336ca054..7a3b00e8d9 100644
--- a/server/live-call-record.ts
+++ b/server/live-call-record.ts
@@ -1,4 +1,4 @@
-// Never holds anything said on a call beyond the requests the bot already received.
+// Of what was said on a call, holds only the bot's own spoken lines; the person's words are the requests already in the chat.
// steer-queue.ts imports this at runtime, so it stays light: store and title machinery arrive as injected deps.
import { liveCallRowText } from "../shared/live-call.ts";
import type { LiveCallRecord } from "../shared/wire.ts";
diff --git a/server/message-redaction.ts b/server/message-redaction.ts
index 0486d8bc62..1758c8e2dc 100644
--- a/server/message-redaction.ts
+++ b/server/message-redaction.ts
@@ -37,6 +37,7 @@ export function redactBotAuthored<T extends Omit<WireMessage, "id" | "at"> & { a
};
}
if (out.call?.title) out.call = { ...out.call, title: redactSecretsInText(out.call.title) };
+ if (out.call?.spoken) out.call = { ...out.call, spoken: out.call.spoken.map((line) => ({ ...line, text: redactSecretsInText(line.text) })) };
if (out.card) {
const card = { ...out.card } as OptionCardData & { summary?: string };
card.title = redactSecretsInText(card.title);
diff --git a/shared/live-call.test.ts b/shared/live-call.test.ts
index 19eb86b836..3002efdda0 100644
--- a/shared/live-call.test.ts
+++ b/shared/live-call.test.ts
@@ -1,6 +1,31 @@
import { describe, expect, it } from "vitest";
-import { clampAppend, commentaryChunks, formatCallDuration, FULL_ANSWER_IN_CHAT, joinFragments, LiveTranscript, liveCallRowText } from "./live-call.ts";
+import { clampAppend, commentaryChunks, formatCallDuration, FULL_ANSWER_IN_CHAT, joinFragments, LiveTranscript, liveCallRowText, SpokenLines } from "./live-call.ts";
+
+describe("SpokenLines", () => {
+ it("keeps each stretch of the voice's speech as one line, stamped when it began", () => {
+ const lines = new SpokenLines();
+ lines.add("You have ", 10, 1_000, 1_400);
+ lines.add("two meet", 11, 1_400, 1_800);
+ lines.add("ings.", 12, 1_800, 2_000);
+ lines.add(" Anything else?", 13, 2_500, 3_000);
+ lines.add("Bye!", 40, 9_000, 9_400);
+ expect(lines.list()).toEqual([
+ { at: 10, text: "You have two meetings. Anything else?" },
+ { at: 40, text: "Bye!" },
+ ]);
+ });
+
+ it("adds a delta without timing to the current line, and skips empty ones", () => {
+ const lines = new SpokenLines();
+ lines.add("", 1, 0, 100);
+ lines.add("Sure", 2, Number.NaN, Number.NaN);
+ lines.add(", on it.", 3, Number.NaN, Number.NaN);
+ lines.add("Done.", 9, 5_000, 5_300);
+ lines.add(" ", 10, 20_000, 20_100);
+ expect(lines.list()).toEqual([{ at: 2, text: "Sure, on it." }, { at: 9, text: "Done." }]);
+ });
+});
describe("LiveTranscript", () => {
it("rebuilds each delegated request from the words spoken since the previous one", () => {
diff --git a/src/components/CallSheet.test.ts b/src/components/CallSheet.test.ts
index 85160d01cf..39d3e8a7b2 100644
--- a/src/components/CallSheet.test.ts
+++ b/src/components/CallSheet.test.ts
@@ -74,6 +74,21 @@ describe("CallSheet", () => {
expect(text).toContain("Nothing else said on the call is kept.");
});
+ it("shows what the bot said aloud among the rest, and says it keeps it", () => {
+ const withSpoken = msg("row", { ...record, call: { ...record.call!, spoken: [{ at: at - 1, text: "Sure, let me check." }, { at: at + 1, text: "That's all, bye!" }] } });
+ const list = [...transcript.slice(0, -1), withSpoken];
+ flushSync(() => root.render(createElement(CallRecordRow, { message: withSpoken, transcript: list, botName: "Kiwi", threadId: "t", busy: false, hasMore: false })));
+ openSheet();
+ const text = sheet()!.textContent ?? "";
+ const first = text.indexOf("Sure, let me check.");
+ const asked = text.indexOf("Hey Kiwi, what are the two issues I should pick up");
+ const answered = text.indexOf("MOCA-295 and MOCA-341.");
+ expect(first).toBeGreaterThanOrEqual(0);
+ expect(asked).toBeGreaterThan(first);
+ expect(text.indexOf("That's all, bye!")).toBeGreaterThan(answered);
+ expect(text).toContain("Your requests, and what Kiwi said, did and answered. Nothing else you said on the call is kept.");
+ });
+
it("says so when nothing was asked on the call", () => {
draw([record]);
openSheet();
diff --git a/src/components/CallSheet.tsx b/src/components/CallSheet.tsx
index 47c5fded2f..c2606efc6d 100644
--- a/src/components/CallSheet.tsx
+++ b/src/components/CallSheet.tsx
@@ -66,13 +66,13 @@ export function CallLineItem({ line, busy }: { line: CallRecordLine; busy: boole
}
type Block =
- | Extract<CallConversationEntry, { kind: "said" | "answer" }>
+ | Extract<CallConversationEntry, { kind: "said" | "answer" | "spoken" }>
| { kind: "lines"; id: string; lines: CallRecordLine[] };
function blocksOf(entries: readonly CallConversationEntry[]): Block[] {
const blocks: Block[] = [];
for (const entry of entries) {
- if (entry.kind === "said" || entry.kind === "answer") {
+ if (entry.kind === "said" || entry.kind === "answer" || entry.kind === "spoken") {
blocks.push(entry);
continue;
}
@@ -96,7 +96,8 @@ export function CallSheet({ message, transcript, botName, threadId, busy, partia
useModalDialog(dialog, onClose);
const call = message.call;
const callId = call?.callId;
- const blocks = useMemo(() => (callId === undefined ? [] : blocksOf(callConversation(transcript, callId))), [transcript, callId]);
+ const spoken = call?.spoken;
+ const blocks = useMemo(() => (callId === undefined ? [] : blocksOf(callConversation(transcript, callId, spoken))), [transcript, callId, spoken]);
if (!call) return null;
const title = call.title?.trim() || t("chat.callRecord.title", { name: botName });
const when = new Date(call.startedAt || call.endedAt).toLocaleString(intlLocale(), { dateStyle: "medium", timeStyle: "short" });
@@ -144,7 +145,7 @@ export function CallSheet({ message, transcript, botName, threadId, busy, partia
)}
</div>
<footer className="border-t border-hairline/40 px-5 py-3 text-[12px] text-ink-tertiary">
- {t("chat.callSheet.kept", { name: botName })}
+ {t(spoken?.length ? "chat.callSheet.keptSpoken" : "chat.callSheet.kept", { name: botName })}
</footer>
</div>
</div>,
@@ -169,6 +170,15 @@ function SheetBlock({ block, busy, threadId }: { block: Block; busy: boolean; th
</div>
);
}
+ if (block.kind === "spoken") {
+ return (
+ <div className="flex justify-start">
+ <div className="w-fit max-w-[85%] whitespace-pre-wrap rounded-2xl bg-card px-3.5 py-2 text-[14px] leading-relaxed text-ink">
+ {block.text}
+ </div>
+ </div>
+ );
+ }
const text = stripLeakedSystemHarnessMessages(block.message.text);
if (!text.trim()) return null;
return (
diff --git a/src/lib/call-record.test.ts b/src/lib/call-record.test.ts
index 837e07a898..2f24f1cc05 100644
--- a/src/lib/call-record.test.ts
+++ b/src/lib/call-record.test.ts
@@ -248,6 +248,23 @@ describe("callConversation", () => {
expect(entries(transcript, "c1")).toEqual(["said:m1", "answer:b1"]);
});
+ it("places the bot's spoken lines among the rows by when they began, even on a call where nothing was asked", () => {
+ const transcript = [
+ spoken("m1", "check the build", "c1"),
+ msg("b1", { text: "The build is green.", requestMessageId: "m1" }),
+ callRow("r1", "c1"),
+ ];
+ const [asked, answered] = transcript;
+ const lines = [
+ { at: asked!.at - 1, text: "Hi, what can I do?" },
+ { at: asked!.at, text: "On it." },
+ { at: answered!.at + 0.5, text: "It's green." },
+ ];
+ const kinds = callConversation(transcript, "c1", lines).map((entry) => entry.kind === "spoken" ? `spoken:${entry.text}` : `${entry.kind}:${entry.id}`);
+ expect(kinds).toEqual(["spoken:Hi, what can I do?", "spoken:On it.", "said:m1", "answer:b1", "spoken:It's green."]);
+ expect(callConversation([callRow("r2", "c2")], "c2", [{ at: 1, text: "Hello!" }])).toEqual([{ kind: "spoken", id: "spoken-0", text: "Hello!" }]);
+ });
+
it("is empty for a call where nothing was asked", () => {
expect(callConversation([callRow("r1", "c1")], "c1")).toEqual([]);
});
diff --git a/src/lib/call-record.ts b/src/lib/call-record.ts
index a4d74e8265..42111edcea 100644
--- a/src/lib/call-record.ts
+++ b/src/lib/call-record.ts
@@ -1,5 +1,6 @@
import type { Message } from "@/state/store";
import { isToolStep } from "@/lib/activity-runs";
+import type { LiveSpokenLine } from "../../shared/wire";
export type CallRecordLine =
| { kind: "step"; id: string; tool: NonNullable<Message["tool"]> }
@@ -20,13 +21,20 @@ export function callRecordLines(transcript: readonly Message[], callId: string):
export type CallConversationEntry =
| { kind: "said"; id: string; message: Message }
| { kind: "answer"; id: string; message: Message }
+ | { kind: "spoken"; id: string; text: string }
| CallRecordLine;
-export function callConversation(transcript: readonly Message[], callId: string): CallConversationEntry[] {
+/** `spoken` is the call record's lines the bot said aloud, placed among the chat's rows by when they began. */
+export function callConversation(transcript: readonly Message[], callId: string, spoken: readonly LiveSpokenLine[] = []): CallConversationEntry[] {
const requests = callRequests(transcript, callId);
- if (requests.size === 0) return [];
+ if (requests.size === 0 && spoken.length === 0) return [];
const entries: CallConversationEntry[] = [];
+ let next = 0;
+ const speakUntil = (at: number) => {
+ for (; next < spoken.length && spoken[next]!.at <= at; next++) entries.push({ kind: "spoken", id: `spoken-${next}`, text: spoken[next]!.text });
+ };
for (const message of transcript) {
+ speakUntil(message.at);
if (requests.has(message.id)) {
if (message.text?.trim()) entries.push({ kind: "said", id: message.id, message });
continue;
@@ -39,6 +47,7 @@ export function callConversation(transcript: readonly Message[], callId: string)
const line = callRecordLine(message);
if (line) entries.push(line);
}
+ speakUntil(Number.POSITIVE_INFINITY);
return entries;
}
diff --git a/src/locales/en.json b/src/locales/en.json
index 50ebdf475a..23eacb9324 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -2652,6 +2652,7 @@
"chat.callSheet.kicker": "Live call",
"chat.callSheet.empty": "Nothing was asked on this call.",
"chat.callSheet.kept": "Your requests and {name}’s answers and steps. Nothing else said on the call is kept.",
+ "chat.callSheet.keptSpoken": "Your requests, and what {name} said, did and answered. Nothing else you said on the call is kept.",
"chat.showFull": "Show full message",
"chat.showLess": "Show less",
"chat.generatedImage": "Generated image",
diff --git a/src/locales/pt-br.json b/src/locales/pt-br.json
index d617321bee..c728c310e0 100644
--- a/src/locales/pt-br.json
+++ b/src/locales/pt-br.json
@@ -2470,6 +2470,7 @@
"chat.callSheet.kicker": "Chamada ao vivo",
"chat.callSheet.empty": "Nada foi pedido nesta chamada.",
"chat.callSheet.kept": "Seus pedidos, as respostas e os passos de {name}. Nada mais do que foi dito na chamada fica salvo.",
+ "chat.callSheet.keptSpoken": "Seus pedidos e o que {name} disse, fez e respondeu. Nada mais do que você disse na chamada fica salvo.",
"chat.showFull": "Ver a mensagem inteira",
"chat.showLess": "Mostrar menos",
"chat.generatedImage": "Imagem gerada",