Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(live): keep credential shapes whole until the record is redacted and mask held codes said across a pause
AdityaUmaleed44eff02417
diff --git a/packages/phone-protocol/src/live-call.ts b/packages/phone-protocol/src/live-call.tsindex 02d0dea101..a0048a4f21 100644--- a/packages/phone-protocol/src/live-call.ts+++ b/packages/phone-protocol/src/live-call.ts@@ -81,14 +81,17 @@ export class LiveTranscript {const SPOKEN_LINE_GAP_MS = 1_000;const MAX_SPOKEN_LINES = 2_000;+type SpokenLineState = { at: number; text: string; endMs: number };+/** 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; text: string; endMs: number }> = [];+ private lines: SpokenLineState[] = [];private readonly scrub: (text: string) => string;- /** `scrub` masks each line as it grows, while anything it masks is still known to it. */+ /** `scrub` masks known values (held one-time codes) in each line as it grows, while they are still known to it.+ * It must only replace exact values: a mask it leaves stays, so a value it forgets later stays masked. */constructor(scrub: (text: string) => string = (text) => text) {this.scrub = scrub;}@@ -100,10 +103,25 @@ export class SpokenLines {if (last && (!timed || startMs <= last.endMs + SPOKEN_LINE_GAP_MS)) {last.text = this.scrub(last.text + text);if (timed) last.endMs = Math.max(last.endMs, endMs);- return;+ } else {+ if (this.lines.length >= MAX_SPOKEN_LINES) return;+ this.lines.push({ at, text: this.scrub(text), endMs: timed ? endMs : Number.NEGATIVE_INFINITY });+ }+ this.joinAcrossPause();+ }++ /** A value said across a pause is split over two lines, neither of which holds all of it: when the scrub+ * masks something in the two joined, they become one line. */+ private joinAcrossPause(): void {+ while (this.lines.length >= 2) {+ const [previous, last] = this.lines.slice(-2) as [SpokenLineState, SpokenLineState];+ const joined = previous.text + last.text;+ const scrubbed = this.scrub(joined);+ if (scrubbed === joined) return;+ previous.text = scrubbed;+ previous.endMs = Math.max(previous.endMs, last.endMs);+ this.lines.pop();}- if (this.lines.length >= MAX_SPOKEN_LINES) return;- this.lines.push({ at, text: this.scrub(text), endMs: timed ? endMs : Number.NEGATIVE_INFINITY });}list(): LiveSpokenLine[] {diff --git a/server/live-call-controller.test.ts b/server/live-call-controller.test.tsindex 441dda5724..e42d311f25 100644--- a/server/live-call-controller.test.ts+++ b/server/live-call-controller.test.ts@@ -9,7 +9,7 @@ import { LIVE_CUSTOM_REFUSAL } from "./live-access.ts";import { LIVE_NEEDS_AZURE, LIVE_NEEDS_KEY, LiveSessionError, type LiveEndpoint } from "./live-call.ts";import { FishRelays, FISH_AGENT_VOICE } from "./live-fish.ts";import type { LiveElevenLabsSession, LiveFishSessionToken, LiveGeminiSession } from "../shared/wire.ts";-import { addHeldSecretScrubber, HELD_SECRET_MASK } from "./redact.ts";+import { addHeldSecretScrubber, HELD_SECRET_MASK, redactSecretsInText } from "./redact.ts";import type { RequestAuth } from "./request-auth.ts";import type { Message, StoreChange } from "./store.ts";@@ -1730,6 +1730,34 @@ describe("LiveCallController record", () => {expect(JSON.stringify(record)).not.toContain("24LM");});+ it("masks a held code said across a pause, which splits it over two lines", async () => {+ const code = "Q7XK-24LM";+ const forget = addHeldSecretScrubber((text) => text.replaceAll(code, HELD_SECRET_MASK));+ const t = setup({ recordCall: vi.fn() });+ try {+ await t.start();+ t.socket().receive({ type: "session.output_transcript.delta", delta: "Your code is Q7XK", start_ms: 1_000, end_ms: 1_500 });+ t.socket().receive({ type: "session.output_transcript.delta", delta: "-24", start_ms: 3_000, end_ms: 3_200 });+ t.socket().receive({ type: "session.output_transcript.delta", delta: "LM.", start_ms: 3_200, end_ms: 3_500 });+ } finally {+ forget();+ }+ t.socket().drop();+ const record = recorded(t)[0]!.record;+ expect(record.spoken).toEqual([{ at: expect.any(Number), text: `Your code is ${HELD_SECRET_MASK}.` }]);+ expect(JSON.stringify(record)).not.toContain("Q7XK");+ });++ it("leaves a credential shape whole until the record is redacted, so a key split across deltas is masked in full", async () => {+ const t = setup({ recordCall: vi.fn() });+ await t.start();+ t.socket().receive({ type: "session.output_transcript.delta", delta: "Set service_key=Q7XK", start_ms: 1_000, end_ms: 1_500 });+ t.socket().receive({ type: "session.output_transcript.delta", delta: "-24LM now.", start_ms: 1_500, end_ms: 2_000 });+ t.socket().drop();+ const spoken = recorded(t)[0]!.record.spoken!.map((line) => redactSecretsInText(line.text));+ expect(spoken).toEqual(["Set service_key=«redacted 9 chars» now."]);+ });+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.tsindex 78990554f3..709753b21f 100644--- a/server/live-call-controller.ts+++ b/server/live-call-controller.ts@@ -10,7 +10,7 @@ import type { LiveCallRecord, LiveCallState, LiveClient, LiveElevenLabsTransportimport { FISH_AGENT_VOICE } from "./live-fish.ts";import { LIVE_NEEDS_KEY, liveAuthHeaders, liveCallSummaryLine, liveProviderName, LiveSessionError, liveVoice, spokenHangUp, type LiveEndpoint } from "./live-call.ts";import { LIVE_CUSTOM_REFUSAL } from "./live-access.ts";-import { redactSecretsInText } from "./redact.ts";+import { scrubHeldSecrets } from "./redact.ts";import type { RequestAuth } from "./request-auth.ts";import type { Message, StoreChange } from "./store.ts";@@ -297,7 +297,7 @@ export class LiveCallController {socket: null,attached: false,transcript: new LiveTranscript(),- spoken: new SpokenLines(redactSecretsInText),+ spoken: new SpokenLines(scrubHeldSecrets),heardThroughMs: 0,lastDecision: null,eventCounter: 0,