Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Live calls on Fish Audio speak the app's language
AdityaUmale032fb4cdd582
diff --git a/server/index.ts b/server/index.tsindex ba50e85191..05857526fa 100644--- a/server/index.ts+++ b/server/index.ts@@ -12449,7 +12449,7 @@ function liveCallTitle(botId: string, threadId: string, excerpt: string): Promisconst gate = threadTitleGate(bot);return gate.ok ? generateThreadTitle(gate.instance, excerpt, "call") : null;}-const liveWiring = liveSessionWiring({ bot: liveBotFor, history: liveHistoryFor, cloudHome: Boolean(CLOUD_HOME), othersOnLoopback: adminActivityRecording, saveAgent: (agent) => { saveConfig({ live: agent }); Object.assign(cfg, loadConfig()); } });+const liveWiring = liveSessionWiring({ bot: liveBotFor, history: liveHistoryFor, cloudHome: Boolean(CLOUD_HOME), othersOnLoopback: adminActivityRecording, saveAgent: (agent) => { saveConfig({ live: agent }); Object.assign(cfg, loadConfig()); }, language: appLanguage, fishAgentLanguage: () => cfg.live?.fishAgentLanguage });const liveCalls = new LiveCallController({store,send: async ({ auth, botId, threadId, text, callId }) => {diff --git a/server/live-config.ts b/server/live-config.tsindex 9d5c64cde4..f570dc716c 100644--- a/server/live-config.ts+++ b/server/live-config.ts@@ -4,7 +4,7 @@ import { z } from "zod";export const LIVE_KEY_NEEDS_ENDPOINT = "Save the Azure endpoint first: a Live key works only with the endpoint it was saved for.";const NOWHERE = "nowhere";-/** Live calls: `key` is a key for Live calls only; with `provider` "openai" (the default) a call without one uses `openai.key`, with "azure" it is the Azure resource's key and is required, with "fish", "gemini" or "elevenlabs" it is not used: Fish Audio calls use the Fish Audio key (`tts.fishKey`), Gemini calls the Gemini key (`tts.geminiKey`) and ElevenLabs calls the ElevenLabs key (`tts.key`). `keyFor` says where `key` may go (`liveKeyTarget`): the server sets it when the key is saved and never takes it from a request; absent, the key is from before Azure was offered, so OpenAI's. `azureEndpoint` is the resource URL and `azureDeployment` the gpt-live-1 deployment name. `fishAgentId` is the Fish Audio agent a "fish" call starts, which the harness sets up on the account of the key whose `fishKeyPrint` is `fishAgentFor`; without `fishAgentFor` (an operator's OMB_FISH_LIVE_AGENT_ID) it is used with any key. `elevenlabsAgentId` and `elevenlabsAgentFor` are the same for an "elevenlabs" call's ElevenLabs agent. `voice` is a GPT-Live voice, `geminiVoice` a Gemini Live voice. */+/** Live calls: `key` is a key for Live calls only; with `provider` "openai" (the default) a call without one uses `openai.key`, with "azure" it is the Azure resource's key and is required, with "fish", "gemini" or "elevenlabs" it is not used: Fish Audio calls use the Fish Audio key (`tts.fishKey`), Gemini calls the Gemini key (`tts.geminiKey`) and ElevenLabs calls the ElevenLabs key (`tts.key`). `keyFor` says where `key` may go (`liveKeyTarget`): the server sets it when the key is saved and never takes it from a request; absent, the key is from before Azure was offered, so OpenAI's. `azureEndpoint` is the resource URL and `azureDeployment` the gpt-live-1 deployment name. `fishAgentId` is the Fish Audio agent a "fish" call starts, which the harness sets up on the account of the key whose `fishKeyPrint` is `fishAgentFor`; without `fishAgentFor` (an operator's OMB_FISH_LIVE_AGENT_ID) it is used with any key, and `fishAgentLanguage` is the language the harness last set it to speak (absent: English, as agents were first set up). `elevenlabsAgentId` and `elevenlabsAgentFor` are the same for an "elevenlabs" call's ElevenLabs agent. `voice` is a GPT-Live voice, `geminiVoice` a Gemini Live voice. */export const liveConfigSchema = z.object({key: z.string().optional(),keyFor: z.string().max(300).optional(),@@ -13,6 +13,7 @@ export const liveConfigSchema = z.object({azureDeployment: z.string().trim().max(64).optional(),fishAgentId: z.string().trim().max(128).optional(),fishAgentFor: z.string().max(64).optional(),+ fishAgentLanguage: z.string().max(8).optional(),elevenlabsAgentId: z.string().trim().max(128).optional(),elevenlabsAgentFor: z.string().max(64).optional(),voice: z.string().trim().max(40).regex(/^[a-z]*$/, "a Live voice is a lowercase built-in voice name").optional(),@@ -29,6 +30,7 @@ export interface LiveConfig {azureDeployment?: string;fishAgentId?: string;fishAgentFor?: string;+ fishAgentLanguage?: string;elevenlabsAgentId?: string;elevenlabsAgentFor?: string;voice?: string;@@ -84,6 +86,7 @@ export function liveConfigWithEnv(live: LiveConfig | undefined, env: NodeJS.Procif (env.OMB_FISH_LIVE_AGENT_ID?.trim()) {next.fishAgentId = env.OMB_FISH_LIVE_AGENT_ID.trim();delete next.fishAgentFor;+ delete next.fishAgentLanguage;}// Set together in the environment, the key and the Azure endpoint are the operator's own pairing. A `keyFor` from the// file stands: saves mirror settings into the environment, so they must not be able to pair a forgotten key.diff --git a/server/live-fish.test.ts b/server/live-fish.test.tsindex 6adaaedb35..141224c205 100644--- a/server/live-fish.test.ts+++ b/server/live-fish.test.ts@@ -2,7 +2,7 @@ import { describe, expect, it, vi } from "vitest";import { LiveSessionError } from "./live-call.ts";import {createFishLiveSession, endFishLiveSession, fishErrorMessage, fishInstructions, fishKeyPrint, fishLiveBaseUrl, fishLiveEndpoint, FishRelays,- FISH_UPDATE_PREFIX, setUpFishAgent, usableFishAgent,+ FISH_UPDATE_PREFIX, fishSpeakingLanguage, setFishAgentLanguage, setUpFishAgent, usableFishAgent,} from "./live-fish.ts";const ENDPOINT = fishLiveEndpoint("agent_123", {});@@ -50,12 +50,12 @@ describe("the Fish agent for Live calls", () => {const route = `${init!.method} ${String(url).replace(ENDPOINT.apiBase, "")}`;return new Response(JSON.stringify(answers[route] ?? {}), { status: route in answers ? 200 : 404 });});- await expect(setUpFishAgent(" fish-key ", { ...ENDPOINT, model: "" }, "MausBot", fetchImpl)).resolves.toBe("agent_new");+ await expect(setUpFishAgent(" fish-key ", { ...ENDPOINT, model: "" }, "MausBot", "vi", fetchImpl)).resolves.toBe("agent_new");const calls = fetchImpl.mock.calls.map(([url, init]) => ({ route: `${init!.method} ${String(url).replace(ENDPOINT.apiBase, "")}`, body: JSON.parse(String(init!.body)), init: init! }));expect(calls.map((call) => call.route)).toEqual(Object.keys(answers));expect(calls[0]!.body).toMatchObject({ name: "delegate", tool_type: "client", expects_response: true });expect(calls[1]!.body.name).toBe("MausBot Live calls");- expect(calls[1]!.body.config).toEqual({ voice: { engine: "live3", speaking_language: "en" }, tools: { enabled: true, tool_ids: ["tool_1"] } });+ expect(calls[1]!.body.config).toEqual({ voice: { engine: "live3", speaking_language: "vi" }, tools: { enabled: true, tool_ids: ["tool_1"] } });expect(calls[2]!.body).toEqual({ overrides_allowed: ["system_prompt"] });for (const call of calls) {expect((call.init.headers as Record<string, string>).authorization).toBe("Bearer fish-key");@@ -63,11 +63,29 @@ describe("the Fish agent for Live calls", () => {}});+ it("speaks the app's language when Fish Audio speaks it, else English", () => {+ expect(fishSpeakingLanguage("vi")).toBe("vi");+ expect(fishSpeakingLanguage(" pt-br ")).toBe("pt");+ expect(fishSpeakingLanguage("zh_TW")).toBe("zh");+ expect(fishSpeakingLanguage("en-US")).toBe("en");+ expect(fishSpeakingLanguage("xx")).toBe("en");+ expect(fishSpeakingLanguage("")).toBe("en");+ expect(fishSpeakingLanguage(undefined)).toBe("en");+ });++ it("moves a saved agent to another language through its draft config, then publishes it", async () => {+ const fetchImpl = fakeFetch(200, {});+ await setFishAgentLanguage("fish-key", ENDPOINT, "agent_123", "vi", fetchImpl);+ const calls = fetchImpl.mock.calls.map(([url, init]) => [`${init!.method} ${String(url).replace(ENDPOINT.apiBase, "")}`, JSON.parse(String(init!.body))]);+ expect(calls).toEqual([["PATCH /agents/agent_123/config", { voice: { speaking_language: "vi" } }], ["POST /agents/agent_123/publish", {}]]);+ await expect(setFishAgentLanguage("fish-key", ENDPOINT, "agent_123", "vi", fakeFetch(404, {}))).rejects.toMatchObject({ status: 502 });+ });+it("stops at Fish's first refusal with the user's next step, never Fish's body", async () => {const fetchImpl = fakeFetch(401, { message: "raw fish-key detail" });- await expect(setUpFishAgent("fish-key", ENDPOINT, "MausBot", fetchImpl)).rejects.toMatchObject({ status: 502, message: fishErrorMessage(401) });+ await expect(setUpFishAgent("fish-key", ENDPOINT, "MausBot", "en", fetchImpl)).rejects.toMatchObject({ status: 502, message: fishErrorMessage(401) });expect(fetchImpl).toHaveBeenCalledTimes(1);- await expect(setUpFishAgent("fish-key", ENDPOINT, "MausBot", fakeFetch(201, {}))).rejects.toMatchObject({ status: 502 });+ await expect(setUpFishAgent("fish-key", ENDPOINT, "MausBot", "en", fakeFetch(201, {}))).rejects.toMatchObject({ status: 502 });});});diff --git a/server/live-fish.ts b/server/live-fish.tsindex 69efa40bda..dbb9d04524 100644--- a/server/live-fish.ts+++ b/server/live-fish.ts@@ -46,9 +46,23 @@ export function usableFishAgent(live: LiveConfig | undefined, key: string): strireturn live?.fishAgentFor === undefined || (key.trim() !== "" && live.fishAgentFor === fishKeyPrint(key)) ? id : null;}-/** Fish API v1: a Live 3 agent in English named for `product`, with the client tool `delegate` and a system prompt each- * session may override (`createFishLiveSession` sends one), published so sessions can start. Returns its id. */-export async function setUpFishAgent(key: string, endpoint: LiveEndpoint, product: string, fetchImpl: typeof fetch = fetch): Promise<string> {+/** The `voice.speaking_language` codes Fish Audio agents take. */+const FISH_SPEAKING_LANGUAGES = new Set([+ "en", "ja", "zh", "ko", "es", "fr", "de", "pt", "it", "nl", "ar", "hi", "id", "tr", "ru", "bg", "sr", "hr", "cs", "sk", "pl", "uk", "ro",+ "hu", "el", "sv", "da", "no", "fi", "et", "lv", "lt", "ca", "he", "fa", "ur", "kk", "ka", "hy", "bn", "ta", "te", "kn", "mr", "gu", "pa",+ "ne", "th", "vi", "ms", "tl", "af",+]);++/** The language a Fish agent speaks and listens for with the app in `language` (a locale such as "vi" or "pt-br"):+ * its base code when Fish Audio speaks it, else English. */+export function fishSpeakingLanguage(language: string | undefined): string {+ const base = language?.trim().toLowerCase().split(/[-_]/)[0] ?? "";+ return FISH_SPEAKING_LANGUAGES.has(base) ? base : "en";+}++/** Fish API v1: a Live 3 agent speaking `language` named for `product`, with the client tool `delegate` and a system prompt+ * each session may override (`createFishLiveSession` sends one), published so sessions can start. Returns its id. */+export async function setUpFishAgent(key: string, endpoint: LiveEndpoint, product: string, language: string, fetchImpl: typeof fetch = fetch): Promise<string> {const call = (method: string, path: string, body: unknown) => fishSetupRequest(fetchImpl, key, method, `${endpoint.apiBase}${path}`, body);const tool = await call("POST", "/tools", {name: FISH_DELEGATE_TOOL,@@ -62,7 +76,7 @@ export async function setUpFishAgent(key: string, endpoint: LiveEndpoint, producif (!toolId) throw new LiveSessionError(FISH_UNEXPECTED, 502);const agent = await call("POST", "/agents", {name: `${product} Live calls`.slice(0, 120),- config: { voice: { engine: "live3", speaking_language: "en" }, tools: { enabled: true, tool_ids: [toolId] } },+ config: { voice: { engine: "live3", speaking_language: language }, tools: { enabled: true, tool_ids: [toolId] } },});const agentId = typeof agent.agent_id === "string" && AGENT_ID.test(agent.agent_id) ? agent.agent_id : "";if (!agentId) throw new LiveSessionError(FISH_UNEXPECTED, 502);@@ -71,6 +85,13 @@ export async function setUpFishAgent(key: string, endpoint: LiveEndpoint, producreturn agentId;}+/** Fish API v1: the agent speaks and listens for `language` from its next session on (a draft config change, published). */+export async function setFishAgentLanguage(key: string, endpoint: LiveEndpoint, agentId: string, language: string, fetchImpl: typeof fetch = fetch): Promise<void> {+ const agent = `${endpoint.apiBase}/agents/${encodeURIComponent(agentId)}`;+ await fishSetupRequest(fetchImpl, key, "PATCH", `${agent}/config`, { voice: { speaking_language: language } });+ await fishSetupRequest(fetchImpl, key, "POST", `${agent}/publish`, {});+}+const FISH_UNEXPECTED = "Fish Audio returned an unexpected answer. Try the call again.";async function fishSetupRequest(fetchImpl: typeof fetch, key: string, method: string, url: string, body: unknown): Promise<Record<string, unknown>> {diff --git a/server/live-session-wiring.test.ts b/server/live-session-wiring.test.tsindex 66cce75657..ccd1468c07 100644--- a/server/live-session-wiring.test.ts+++ b/server/live-session-wiring.test.ts@@ -5,21 +5,25 @@ import { liveSessionWiring } from "./live-session-wiring.ts";const TOKEN = { transport: "livekit", session_id: "sess_1", expires_at: "x", max_duration_seconds: 900, livekit_url: "wss://lk.fish.audio", token: "jwt" };-function fakeFish({ goneAgents = [] as string[] } = {}) {+function fakeFish({ goneAgents = [] as string[], refuseConfig = false } = {}) {return vi.fn(async (url: string | URL | Request, init?: RequestInit) => {const route = `${init!.method} ${String(url).replace("https://api.fish.audio/v1/agent", "")}`;if (route === "POST /sessions") {const agent = JSON.parse(String(init!.body)).agent_id as string;return goneAgents.includes(agent) ? new Response("{}", { status: 404 }) : new Response(JSON.stringify(TOKEN), { status: 201 });}+ if (refuseConfig && route.endsWith("/config")) return new Response("{}", { status: 500 });const answers: Record<string, unknown> = { "POST /tools": { tool_id: "tool_1" }, "POST /agents": { agent_id: "agent_new" } };return new Response(JSON.stringify(answers[route] ?? {}), { status: 200 });});}-function wiring(fetchImpl: typeof fetch, env: NodeJS.ProcessEnv = {}) {+function wiring(fetchImpl: typeof fetch, env: NodeJS.ProcessEnv = {}, speech: { language?: string; fishAgentLanguage?: string } = {}) {const saveAgent = vi.fn();- const wired = liveSessionWiring({ bot: () => ({ name: "Rigel" }), history: () => [], cloudHome: false, othersOnLoopback: () => false, saveAgent, productName: () => "Acme", env, fetchImpl });+ const wired = liveSessionWiring({+ bot: () => ({ name: "Rigel" }), history: () => [], cloudHome: false, othersOnLoopback: () => false, saveAgent, productName: () => "Acme", env, fetchImpl,+ language: () => speech.language, fishAgentLanguage: () => speech.fishAgentLanguage,+ });return { ...wired, saveAgent };}@@ -32,7 +36,7 @@ describe("a Fish Audio call's session", () => {const w = wiring(fetchImpl);const answer = await w.calls.createSession({ ...start, endpoint: fishLiveEndpoint("", {}) });expect(routes(fetchImpl)).toEqual(["POST /tools", "POST /agents", "PATCH /agents/agent_new", "POST /agents/agent_new/publish", "POST /sessions"]);- expect(w.saveAgent).toHaveBeenCalledWith({ fishAgentId: "agent_new", fishAgentFor: fishKeyPrint("fish-key") });+ expect(w.saveAgent).toHaveBeenCalledWith({ fishAgentId: "agent_new", fishAgentFor: fishKeyPrint("fish-key"), fishAgentLanguage: "en" });const created = fetchImpl.mock.calls.find(([url, init]) => init!.method === "POST" && String(url).endsWith("/agents"))!;expect(JSON.parse(String(created[1]!.body)).name).toBe("Acme Live calls");expect(answer).toMatchObject({ sessionId: "sess_1", fish: { type: "fish", session: TOKEN } });@@ -57,6 +61,45 @@ describe("a Fish Audio call's session", () => {expect(w.saveAgent).toHaveBeenCalledTimes(1);});+ it("sets up a new agent in the app's language", async () => {+ const fetchImpl = fakeFish();+ const w = wiring(fetchImpl, {}, { language: "vi" });+ await w.calls.createSession({ ...start, endpoint: fishLiveEndpoint("", {}) });+ const created = fetchImpl.mock.calls.find(([url, init]) => init!.method === "POST" && String(url).endsWith("/agents"))!;+ expect(JSON.parse(String(created[1]!.body)).config.voice.speaking_language).toBe("vi");+ expect(w.saveAgent).toHaveBeenCalledWith({ fishAgentId: "agent_new", fishAgentFor: fishKeyPrint("fish-key"), fishAgentLanguage: "vi" });+ });++ it("moves the saved agent to the app's language before the call, once", async () => {+ const fetchImpl = fakeFish();+ const w = wiring(fetchImpl, {}, { language: "vi" });+ await w.calls.createSession({ ...start, endpoint: fishLiveEndpoint("agent_saved", {}) });+ expect(routes(fetchImpl)).toEqual(["PATCH /agents/agent_saved/config", "POST /agents/agent_saved/publish", "POST /sessions"]);+ expect(JSON.parse(String(fetchImpl.mock.calls[0]![1]!.body))).toEqual({ voice: { speaking_language: "vi" } });+ expect(w.saveAgent).toHaveBeenCalledWith({ fishAgentId: "agent_saved", fishAgentFor: fishKeyPrint("fish-key"), fishAgentLanguage: "vi" });++ const again = fakeFish();+ const moved = wiring(again, {}, { language: "vi", fishAgentLanguage: "vi" });+ await moved.calls.createSession({ ...start, endpoint: fishLiveEndpoint("agent_saved", {}) });+ expect(routes(again)).toEqual(["POST /sessions"]);+ expect(moved.saveAgent).not.toHaveBeenCalled();+ });++ it("still starts the call when Fish won't change the agent's language", async () => {+ const fetchImpl = fakeFish({ refuseConfig: true });+ const w = wiring(fetchImpl, {}, { language: "vi" });+ await expect(w.calls.createSession({ ...start, endpoint: fishLiveEndpoint("agent_saved", {}) })).resolves.toMatchObject({ sessionId: "sess_1" });+ expect(routes(fetchImpl)).toEqual(["PATCH /agents/agent_saved/config", "POST /sessions"]);+ expect(w.saveAgent).not.toHaveBeenCalled();+ });++ it("never changes the language of an agent the operator chose", async () => {+ const fetchImpl = fakeFish();+ const w = wiring(fetchImpl, { OMB_FISH_LIVE_AGENT_ID: "agent_op" }, { language: "vi" });+ await w.calls.createSession({ ...start, endpoint: fishLiveEndpoint("agent_op", {}) });+ expect(routes(fetchImpl)).toEqual(["POST /sessions"]);+ });+it("never replaces an agent the operator chose", async () => {const fetchImpl = fakeFish({ goneAgents: ["agent_op"] });const w = wiring(fetchImpl, { OMB_FISH_LIVE_AGENT_ID: "agent_op" });diff --git a/server/live-session-wiring.ts b/server/live-session-wiring.tsindex 7b91d6dd3f..e1d184f6eb 100644--- a/server/live-session-wiring.ts+++ b/server/live-session-wiring.ts@@ -4,7 +4,7 @@ import { openLiveSocket, relayedProvider } from "./live-call-controller.ts";import { createLiveSession, liveAttachUrl, type LiveBot, type LiveEndpoint, type LiveHistoryMessage } from "./live-call.ts";import { elevenLabsLiveCallRefusal, fishLiveCallRefusal, geminiLiveCallRefusal } from "./live-access.ts";import type { LiveConfig } from "./live-config.ts";-import { createFishLiveSession, endFishLiveSession, fishKeyPrint, FishRelays, setUpFishAgent } from "./live-fish.ts";+import { createFishLiveSession, endFishLiveSession, fishKeyPrint, FishRelays, fishSpeakingLanguage, setFishAgentLanguage, setUpFishAgent } from "./live-fish.ts";import { createElevenLabsLiveSession, setUpElevenLabsAgent } from "./live-elevenlabs.ts";import { createGeminiLiveSession } from "./live-gemini.ts";import type { LiveRouteDeps } from "./routes/live.ts";@@ -15,7 +15,11 @@ export interface LiveSessionWiringInput {cloudHome: boolean;othersOnLoopback(): boolean;/** Saves the Fish Audio or ElevenLabs agent the harness set up, with the account it belongs to. */- saveAgent(agent: Required<Pick<LiveConfig, "fishAgentId" | "fishAgentFor">> | Required<Pick<LiveConfig, "elevenlabsAgentId" | "elevenlabsAgentFor">>): void;+ saveAgent(agent: Required<Pick<LiveConfig, "fishAgentId" | "fishAgentFor" | "fishAgentLanguage">> | Required<Pick<LiveConfig, "elevenlabsAgentId" | "elevenlabsAgentFor">>): void;+ /** The app's language, which a Fish Audio agent speaks; English when unset. */+ language?(): string | undefined;+ /** The language the saved Fish Audio agent was last set to speak (`LiveConfig.fishAgentLanguage`). */+ fishAgentLanguage?(): string | undefined;/** The name a person reads, which names the agent on their account; the brand's own by default. */productName?(): string;env?: NodeJS.ProcessEnv;@@ -33,22 +37,37 @@ export function liveSessionWiring(input: LiveSessionWiringInput): {const env = input.env ?? process.env;const fetchImpl = input.fetchImpl ?? fetch;- const setUpAgent = async (key: string, endpoint: LiveEndpoint): Promise<LiveEndpoint> => {- const fishAgentId = await setUpFishAgent(key, endpoint, (input.productName ?? productName)(), fetchImpl);- input.saveAgent({ fishAgentId, fishAgentFor: fishKeyPrint(key) });+ const operatorAgent = () => Boolean(env.OMB_FISH_LIVE_AGENT_ID?.trim());++ const setUpAgent = async (key: string, endpoint: LiveEndpoint, language: string): Promise<LiveEndpoint> => {+ const fishAgentId = await setUpFishAgent(key, endpoint, (input.productName ?? productName)(), language, fetchImpl);+ input.saveAgent({ fishAgentId, fishAgentFor: fishKeyPrint(key), fishAgentLanguage: language });return { ...endpoint, model: fishAgentId };};+ // Moves the saved agent the harness set up to the app's language; if Fish refuses, the call goes ahead in the old one.+ const speakLanguage = async (key: string, endpoint: LiveEndpoint, language: string): Promise<void> => {+ if (operatorAgent() || (input.fishAgentLanguage?.() ?? "en") === language) return;+ try {+ await setFishAgentLanguage(key, endpoint, endpoint.model, language, fetchImpl);+ } catch {+ return;+ }+ input.saveAgent({ fishAgentId: endpoint.model, fishAgentFor: fishKeyPrint(key), fishAgentLanguage: language });+ };+const startFish = async (key: string, endpoint: LiveEndpoint, botId: string, threadId: string) => {const session = { key, bot: input.bot(botId), history: input.history(threadId), cloudHome: input.cloudHome, fetchImpl };- let agent = endpoint.model ? endpoint : await setUpAgent(key, endpoint);+ const language = fishSpeakingLanguage(input.language?.());+ if (endpoint.model) await speakLanguage(key, endpoint, language);+ let agent = endpoint.model ? endpoint : await setUpAgent(key, endpoint, language);try {return { agent, token: await createFishLiveSession({ ...session, endpoint: agent }) };} catch (error) {// An agent removed on Fish Audio is set up again, unless the operator chose it.- const gone = (error as { fishStatus?: number }).fishStatus === 404 && endpoint.model !== "" && !env.OMB_FISH_LIVE_AGENT_ID?.trim();+ const gone = (error as { fishStatus?: number }).fishStatus === 404 && endpoint.model !== "" && !operatorAgent();if (!gone) throw error;- agent = await setUpAgent(key, endpoint);+ agent = await setUpAgent(key, endpoint, language);return { agent, token: await createFishLiveSession({ ...session, endpoint: agent }) };}};