Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Live calls: a new endpoint starts a new key form
Bugfixer 22e18a2728dea
diff --git a/src/components/LiveCallSettings.tsx b/src/components/LiveCallSettings.tsxindex 13a0be15aa..c43c798677 100644--- a/src/components/LiveCallSettings.tsx+++ b/src/components/LiveCallSettings.tsx@@ -2,7 +2,7 @@ import { useCallback, useId, useState } from "react";import { GEMINI_LIVE_VOICE_OPTIONS, geminiLiveVoice, LIVE_VOICE_OPTIONS } from "../../shared/live-call";import { t } from "@/lib/i18n";-import { liveDisclosure, liveKeyCopy } from "@/lib/call-mode";+import { liveDisclosure, liveKeyCopy, liveKeyFormKey } from "@/lib/call-mode";import { api, useStore, type ConfigStatus } from "@/state/store";import type { LiveSettings } from "../../shared/wire";import { LiveKeySetup } from "./LiveKeySetup";@@ -136,8 +136,8 @@ export function LiveCallSettings({ onClose }: { onClose: () => void }) {{live.keySource !== "live" && !azure && !custom && !fish && !gemini && !elevenlabs && (<div className="-mt-2 text-[12px] text-ink-tertiary">{t(live.keySource === "openai" ? "call.live.keyFromApiKeys" : "call.live.needsKey")} <KeysLink id="openai" purpose="liveCalls" /></div>)}- {/* Keyed by provider: a key typed for one provider is never saved for another. */}- {changingKey && <LiveKeySetup key={state.config?.live?.provider ?? "openai"} compact locked={providerSaving} onSaving={setKeySaving} onSaved={() => setChangingKey(false)} />}+ {/* Keyed by provider and endpoint: a key typed for one is never saved for another. */}+ {changingKey && <LiveKeySetup key={liveKeyFormKey(state.config?.live)} compact locked={providerSaving} onSaving={setKeySaving} onSaved={() => setChangingKey(false)} />}<div className="text-[12px] text-ink-tertiary">{liveDisclosure({ cloudHome: state.config?.cloudHome === true, azure, custom, fish, gemini, elevenlabs })} {t(copy.cost)}</div>{error && <div className="text-[12px] text-danger">{error}</div>}</div>diff --git a/src/components/LiveKeyNeeded.test.ts b/src/components/LiveKeyNeeded.test.tsindex bfa9e7abca..26a81805ce 100644--- a/src/components/LiveKeyNeeded.test.ts+++ b/src/components/LiveKeyNeeded.test.ts@@ -60,3 +60,14 @@ it("with Azure chosen and no endpoint yet, asks for the endpoint first: a key isexpect(html).toContain('placeholder="https://my-resource.openai.azure.com"');expect(html).not.toContain('aria-label="Azure OpenAI key for Live calls"');});++it("starts a new key form when the endpoint changes, so a key typed for one address is never saved for another", () => {+ const formKey = (customEndpoint: string) => {+ f.live = { configured: false, provider: "custom", customEndpoint, voice: "", readTypedReplies: true, idleMinutes: 5 };+ return nodes(LiveKeyNeeded()).find((node) => typeof node.type === "function" && node.type.name === "ProviderAndKey")?.props as { formKey?: string } | undefined;+ };+ const first = formKey("https://a.example.com/v1")?.formKey;+ expect(first).toBeTruthy();+ expect(formKey("https://b.example.com/v1")?.formKey).not.toBe(first);+ expect(formKey("https://a.example.com/v1")?.formKey).toBe(first);+});diff --git a/src/components/LiveKeyNeeded.tsx b/src/components/LiveKeyNeeded.tsxindex bbf59b6c3c..1888af6124 100644--- a/src/components/LiveKeyNeeded.tsx+++ b/src/components/LiveKeyNeeded.tsx@@ -1,7 +1,7 @@import { useEffect, useId, useState } from "react";import { KeyRound } from "lucide-react";-import { liveDisclosure, liveKeyCopy } from "@/lib/call-mode";+import { liveDisclosure, liveKeyCopy, liveKeyFormKey } from "@/lib/call-mode";import { dismissLiveNotice } from "@/lib/live-call-media";import { t } from "@/lib/i18n";import { useStore } from "@/state/store";@@ -27,19 +27,19 @@ export function LiveKeyNeeded() {<KeyRound size={16} className="mt-0.5 shrink-0 text-ink-secondary" aria-hidden="true" /><h2 id={titleId} className="text-[14px] font-medium leading-[1.4] text-ink">{t(copy.needs)}</h2></div>- <ProviderAndKey provider={live?.provider ?? "openai"} keyForm={keyForm} />+ <ProviderAndKey formKey={liveKeyFormKey(live)} keyForm={keyForm} />{(azure || custom || fish || gemini || elevenlabs) && <DismissWhenReady ready={live?.configured === true} />}{!azure && !custom && !fish && !gemini && !elevenlabs && <button type="button" className="ui-button ui-button-primary self-start" onClick={() => { dismissLiveNotice(); dispatch(openKeySettings("openai", "liveCalls")); }}>{t("call.live.openApiKeys")}</button>}<p className="text-[12px] leading-[1.45] text-ink-tertiary">{!keyForm && `${liveDisclosure({ cloudHome: state.config?.cloudHome === true, azure, custom, fish, gemini, elevenlabs })} `}{t(copy.cost)}</p></section>;}-function ProviderAndKey({ provider, keyForm }: { provider: string; keyForm: boolean }) {+function ProviderAndKey({ formKey, keyForm }: { formKey: string; keyForm: boolean }) {const [keySaving, setKeySaving] = useState(false);const [providerSaving, setProviderSaving] = useState(false);return <><LiveProviderSettings locked={keySaving} onSaving={setProviderSaving} />- {keyForm && <LiveKeySetup key={provider} compact locked={providerSaving} onSaving={setKeySaving} onSaved={() => {}} />}+ {keyForm && <LiveKeySetup key={formKey} compact locked={providerSaving} onSaving={setKeySaving} onSaved={() => {}} />}</>;}diff --git a/src/lib/call-mode.test.ts b/src/lib/call-mode.test.tsindex a8b4bab568..5f275f4393 100644--- a/src/lib/call-mode.test.ts+++ b/src/lib/call-mode.test.ts@@ -1,6 +1,6 @@import { afterEach, describe, expect, it, vi } from "vitest";-import { CALL_MODE_KEY, CALL_MODES, callModeHint, effectiveCallMode, liveDisclosure, parseCallMode } from "./call-mode";+import { CALL_MODE_KEY, CALL_MODES, callModeHint, effectiveCallMode, liveDisclosure, liveKeyFormKey, parseCallMode } from "./call-mode";import { t } from "./i18n";import { localeChoices, locales } from "@/locales";@@ -61,4 +61,11 @@ describe("call mode", () => {blocked.setCallMode("live");expect(blocked.callMode()).toBe("live");});+ it("ties a Live key form to the provider and, for Azure or a custom endpoint, to its address", () => {+ expect(liveKeyFormKey(undefined)).toBe("openai");+ expect(liveKeyFormKey({ provider: "fish" })).toBe("fish");+ expect(liveKeyFormKey({ provider: "custom", customEndpoint: "https://a.example.com/v1" })).toBe("custom|https://a.example.com/v1");+ expect(liveKeyFormKey({ provider: "azure", azureEndpoint: "https://r.openai.azure.com", customEndpoint: "https://a.example.com/v1" })).toBe("azure|https://r.openai.azure.com");+ expect(liveKeyFormKey({ provider: "custom" })).toBe("custom");+ });});diff --git a/src/lib/call-mode.ts b/src/lib/call-mode.tsindex 773ec29fc4..b03edbcc6a 100644--- a/src/lib/call-mode.ts+++ b/src/lib/call-mode.ts@@ -1,6 +1,6 @@import { useSyncExternalStore } from "react";import type { LocaleKey } from "@/locales";-import type { LiveProvider } from "../../shared/wire";+import type { LiveProvider, LiveSettings } from "../../shared/wire";import { desktopCapabilitiesNow } from "./desktop";import { t } from "./i18n";@@ -41,6 +41,13 @@ export function liveKeyCopy(provider: LiveProvider | undefined) {return { title: "call.live.keyTitle", explain: "call.live.keyExplain", field: "call.live.keyField", key: "call.live.key", missing: "call.live.needsKey", needs: "call.live.needsKey", cost: "call.live.cost" } as const;}+/** The identity of a Live key form: its provider and, for Azure or a custom endpoint, the address the key is bound to. A new address starts a new form, so a key typed for one address is never saved for another. */+export function liveKeyFormKey(live: Partial<Pick<LiveSettings, "provider" | "azureEndpoint" | "customEndpoint">> | undefined): string {+ const provider = live?.provider ?? "openai";+ const endpoint = provider === "custom" ? live?.customEndpoint : provider === "azure" ? live?.azureEndpoint : undefined;+ return endpoint ? `${provider}|${endpoint}` : provider;+}+export function callModeHint(mode: CallMode, where: { cloudHome?: boolean } = {}): string {if (mode === "live") return `${t("call.mode.liveHint")} ${liveDisclosure(where)}`;return t(desktopCapabilitiesNow().dictation.engine === "fish-audio" ? "call.mode.turnsHintFish" : "call.mode.turnsHint");