Skip to content

Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.

feat(desktop): run LiveKit without voice keys and take voice keys in the app

shoudi zhenge624562ea97a
diff --git a/.env.example b/.env.example
index 07ca8ff2..6c00aa89 100644
--- a/.env.example
+++ b/.env.example
@@ -104,8 +104,9 @@ TEAMHUB_COMPOSIO_ENVIRONMENT_KEY=default
TEAMHUB_ARTIFACT_STORAGE_ROOT=.local/teamhub/artifacts
# --- Voice ------------------------------------------------------------------
-# Personal key. The root docker-compose.yml runs LiveKit; `pnpm dev` runs
-# livekit-server from PATH on the LIVEKIT_* below while a voice key is set
+# Voice keys are normally saved in the app; a key set here overrides it. The
+# root docker-compose.yml runs LiveKit; `pnpm dev` runs livekit-server from
+# PATH on the LIVEKIT_* below, with or without a voice key
# (scripts/dev-livekit.ts). node-services supervises
# the separate ASR, recorder and Live workers. Soniox enables recording,
# dictation and archive recovery; empty keeps them off. Recordings go to
@@ -115,6 +116,8 @@ SONIOX_API_KEY=
# Enables Grok Live on its own; it does not need Soniox. With it set the Voice
# Mode button is Live; with only Soniox it dictates.
XAI_API_KEY=
+# on|off: off tells TeamHub this deployment cannot run voice (no LiveKit).
+TEAMHUB_VOICE_MEDIA=on
# Gateways that accept base64 PCM events require json; the direct provider
# uses binary microphone frames. The key must match the configured endpoint.
VOICE_RUNTIME_XAI_LIVE_WEBSOCKET_URL=wss://api.x.ai/v1/realtime
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 6fbe3c16..bf7d223f 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -26,17 +26,17 @@ pnpm dev
`pnpm dev` starts no containers. It migrates the PostgreSQL that
`TEAMHUB_DATABASE_URL` names, then runs Web, TeamHub and the node-services
-process on your machine with hot reload, plus a LiveKit server while a voice
-key is set. Set `TEAMHUB_DATABASE_URL` in `.env`
+process on your machine with hot reload, plus a LiveKit server. Set `TEAMHUB_DATABASE_URL` in `.env`
to your database; the default matches the `postgres` service of the root
`docker-compose.yml`. `.env.example` holds every other value `pnpm dev` needs;
only optional personal keys (Composio, Soniox) are left empty. Check the
services with `pnpm dev:check`, and open <http://localhost:3000>.
-Voice: set `SONIOX_API_KEY` (recording and dictation) or `XAI_API_KEY` (Grok
-Live) in `.env`. `pnpm dev` then runs `livekit-server` from `PATH` on the ports
-and keys `LIVEKIT_URL`, `LIVEKIT_API_KEY` and `LIVEKIT_API_SECRET` name, and
-node-services starts the voice workers. Install it with `brew install livekit`
+Voice: `pnpm dev` runs `livekit-server` from `PATH` on the ports and keys
+`LIVEKIT_URL`, `LIVEKIT_API_KEY` and `LIVEKIT_API_SECRET` name, with or without
+a voice key. Save a Soniox (recording and dictation) or xAI (Grok Live) key in
+the app, or set `SONIOX_API_KEY` or `XAI_API_KEY` in `.env` to override it;
+node-services then starts the voice workers. Install it with `brew install livekit`
on macOS or `curl -sSL https://get.livekit.io | bash` on Linux; recording also
needs `ffmpeg` and `ffprobe`. Point `LIVEKIT_URL` at another host to use a
LiveKit server you run elsewhere instead.
diff --git a/apps/desktop/AGENTS.md b/apps/desktop/AGENTS.md
index 351b88dd..ca87b60d 100644
--- a/apps/desktop/AGENTS.md
+++ b/apps/desktop/AGENTS.md
@@ -130,13 +130,16 @@ Gateway and runs Agents. The daemon exits with the app.
says what is missing (offline computer, no writable folder, or no signed-in
runtime with each runtime's reported state) and logs
`local_server.another_me_missing`. Customize → API keys takes the
- Composio, Soniox and xAI keys (`provider-keys.ts`); Install saves the edits
+ Composio key only (`provider-keys.ts`); voice keys are saved in the app,
+ and a `SONIOX_API_KEY` or `XAI_API_KEY` written into `user.env` by hand
+ still reaches the services and overrides the app's. Install saves the edits
before the installer starts (`installer.js --instance desktop --user-keys`,
the keys on stdin) into the owner-only `instances/desktop/user.env` of the
install location, and the page only learns which keys are saved. Both
engines pass them to the services whenever they are configured (an edit
runs a new job even after a finished one); Native also starts its bundled
- LiveKit when a voice key is set (see Release). There is no settings page
+ LiveKit whenever this computer has voice tools, with or without a voice
+ key (see Release). There is no settings page
after setup yet: keys change on the next Install or Try Again.
- `src/main/diagnostics.ts`: Diagnostics, "Show Logs" (opens
`<userData>/logs`) and "Save Diagnostics" (a redacted
@@ -361,15 +364,17 @@ Linux with `node scripts/prepare-native-voice-tools.mjs --target <target>
`voiceTools`. The build is reproducible except for the Go toolchain download,
and it checks the versions, the ffmpeg components the voice workers use,
static linking and the Mach-O signatures. Licenses ship in `licenses/` of the
-archive. When a voice key is saved, Native extracts the archive into
+archive. On every install and start, whether or not a voice key is saved,
+Native extracts the archive into
`tools/native/components`, puts its `bin` first on the services' `PATH`
(TeamHub and the voice workers run `ffmpeg`/`ffprobe` from it) and runs
`livekit-server` as the `livekit` Native service: loopback only, HTTP and
WebSocket on one free port and media on one free UDP port, both kept with
the generated API key and secret in the owner-only `livekit.env` of the
instance, logs in `native/logs/livekit.log`. ICE over TCP stays off because
-LiveKit binds it on every interface. Without the tools for the computer
-Native keeps voice off. The macOS tools are ad-hoc signed by their linker and
+LiveKit binds it on every interface. Without the tools for the computer, or
+when they fail to prepare, Native logs it, keeps voice off, gives TeamHub
+`TEAMHUB_VOICE_MEDIA=off` and finishes the install. The macOS tools are ad-hoc signed by their linker and
live in the archive, outside the app's signature, like PostgreSQL.
A build with a source package for `win32-x64`, `linux-x64` or `darwin-arm64`
diff --git a/apps/desktop/src/main/diagnostics.ts b/apps/desktop/src/main/diagnostics.ts
index ea03b247..aa7af771 100644
--- a/apps/desktop/src/main/diagnostics.ts
+++ b/apps/desktop/src/main/diagnostics.ts
@@ -10,7 +10,7 @@ import { ZipFile } from "yazl";
import type { LocalServerModule } from "./local-server.js";
import { LOCAL_INSTANCE } from "./local-server.js";
import type { Module, ModuleContext } from "./modules.js";
-import { savedProviderKeys } from "./provider-keys.js";
+import { savedSecretValues } from "./provider-keys.js";
// A file put into the bundle: where it is read from and its name inside.
export interface DiagnosticsFile {
@@ -187,10 +187,8 @@ export const collectDiagnostics = async (
const zip = new ZipFile();
const added = new Set<string>();
const homes = [...new Set(options.homes.map((home) => path.resolve(home)))];
- // The saved provider keys themselves, wherever a service printed them.
- const keys = homes.flatMap((home) =>
- Object.values(savedProviderKeys(home, LOCAL_INSTANCE)),
- );
+ // The saved keys themselves, wherever a service printed them.
+ const keys = homes.flatMap((home) => savedSecretValues(home, LOCAL_INSTANCE));
const addText = (entry: string, text: string) => {
if (added.has(entry)) return;
added.add(entry);
diff --git a/apps/desktop/src/main/local-server.test.ts b/apps/desktop/src/main/local-server.test.ts
index b3b44cad..b0fbcb03 100644
--- a/apps/desktop/src/main/local-server.test.ts
+++ b/apps/desktop/src/main/local-server.test.ts
@@ -58,7 +58,7 @@ if (args.includes("--user-keys")) {
const changes = JSON.parse(fs.readFileSync(0, "utf8"));
fs.writeFileSync(path.join(home, "keys-args.json"), JSON.stringify(args));
if (Object.values(changes).includes("bad")) {
- process.stdout.write(JSON.stringify({ error: "XAI_API_KEY is not a valid key" }) + "\n");
+ process.stdout.write(JSON.stringify({ error: "COMPOSIO_API_KEY is not a valid key" }) + "\n");
process.exit(1);
}
const directory = path.join(home, "instances", "desktop");
@@ -1544,16 +1544,12 @@ describe("LocalServerModule", () => {
};
const f = fixture(withCheckout, {}, checkout, installerApi([finishedJob]));
await f.host.start();
- expect(f.module.status().keys).toEqual({
- composio: false,
- soniox: false,
- xai: false,
- });
+ expect(f.module.status().keys).toEqual({ composio: false });
const info = vi.spyOn(silentLog, "info");
const warn = vi.spyOn(silentLog, "warn");
await f.module.begin({
runtime: "claude",
- keys: { composio: "composio-1", soniox: "soniox-1", xai: "xai-1" },
+ keys: { composio: "composio-1" },
});
// The keys go over stdin, never in the arguments.
const keysArgs = readFileSync(path.join(f.home, "keys-args.json"), "utf8");
@@ -1569,29 +1565,22 @@ describe("LocalServerModule", () => {
path.join(f.home, "instances", LOCAL_INSTANCE, "user.env"),
"utf8",
),
- ).toBe(
- "COMPOSIO_API_KEY=composio-1\nSONIOX_API_KEY=soniox-1\nXAI_API_KEY=xai-1\n",
- );
- expect(f.module.status().keys).toEqual({
- composio: true,
- soniox: true,
- xai: true,
- });
+ ).toBe("COMPOSIO_API_KEY=composio-1\n");
+ expect(f.module.status().keys).toEqual({ composio: true });
// The finished installation does not carry them, so a new one runs.
expect(f.api.created).toHaveLength(1);
expect(f.module.status().phase).toBe("ready");
expect(info).toHaveBeenCalledWith("local_server.keys_saved", {
- saved: ["COMPOSIO_API_KEY", "SONIOX_API_KEY", "XAI_API_KEY"],
+ saved: ["COMPOSIO_API_KEY"],
});
const logged = JSON.stringify([info.mock.calls, warn.mock.calls]);
expect(logged).not.toContain("composio-1");
- expect(logged).not.toContain("soniox-1");
- expect(logged).not.toContain("xai-1");
info.mockRestore();
warn.mockRestore();
await f.host.stop("quit");
- // Removing one key keeps the other; without changes the finished
+ // Removing the Composio key keeps the voice keys a person put in
+ // user.env by hand; without changes the finished
// installation is followed as before.
const again = fixture(
withCheckout,
@@ -1603,7 +1592,7 @@ describe("LocalServerModule", () => {
});
writeFileSync(
path.join(home, "instances", LOCAL_INSTANCE, "user.env"),
- "SONIOX_API_KEY=soniox-1\nXAI_API_KEY=xai-1\n",
+ "COMPOSIO_API_KEY=composio-1\nSONIOX_API_KEY=soniox-1\n",
);
},
installerApi([finishedJob]),
@@ -1611,13 +1600,15 @@ describe("LocalServerModule", () => {
await again.host.start();
await again.module.begin({
runtime: "claude",
- keys: { xai: "" },
- });
- expect(again.module.status().keys).toEqual({
- composio: false,
- soniox: true,
- xai: false,
+ keys: { composio: "" },
});
+ expect(again.module.status().keys).toEqual({ composio: false });
+ expect(
+ readFileSync(
+ path.join(again.home, "instances", LOCAL_INSTANCE, "user.env"),
+ "utf8",
+ ),
+ ).toBe("SONIOX_API_KEY=soniox-1\n");
await again.host.stop("quit");
const plain = fixture(
withCheckout,
@@ -1638,10 +1629,10 @@ describe("LocalServerModule", () => {
await expect(
f.module.begin({
runtime: "claude",
- keys: { xai: "bad" },
+ keys: { composio: "bad" },
}),
).rejects.toThrow(
- "Keys could not be saved: XAI_API_KEY is not a valid key",
+ "Keys could not be saved: COMPOSIO_API_KEY is not a valid key",
);
expect(existsSync(path.join(f.home, "installer", "args.json"))).toBe(false);
expect(f.module.status().phase).toBe("failed");
diff --git a/apps/desktop/src/main/local-server.ts b/apps/desktop/src/main/local-server.ts
index a0e7762b..a7ac5bdb 100644
--- a/apps/desktop/src/main/local-server.ts
+++ b/apps/desktop/src/main/local-server.ts
@@ -233,8 +233,6 @@ export interface LocalServerStatus {
// keys themselves.
readonly keys: {
readonly composio: boolean;
- readonly soniox: boolean;
- readonly xai: boolean;
};
readonly origin?: string;
// While the "signin" step waits for the person.
@@ -424,8 +422,6 @@ export class LocalServerModule implements Module {
},
keys: {
composio: !!keys.composio,
- soniox: !!keys.soniox,
- xai: !!keys.xai,
},
...(this.#origin ? { origin: this.#origin } : {}),
...(this.#signIn ? { signIn: this.#signIn } : {}),
diff --git a/apps/desktop/src/main/provider-keys.ts b/apps/desktop/src/main/provider-keys.ts
index 751ca850..56d75f5a 100644
--- a/apps/desktop/src/main/provider-keys.ts
+++ b/apps/desktop/src/main/provider-keys.ts
@@ -4,11 +4,9 @@ import { parseEnv } from "node:util";
// The personal provider keys the setup page takes, by the names the services
// read. The installer keeps them in the instance's user.env, which a person
-// can also edit by hand.
+// can also edit by hand; voice keys are saved in the app instead.
export const PROVIDER_KEYS = {
composio: "COMPOSIO_API_KEY",
- soniox: "SONIOX_API_KEY",
- xai: "XAI_API_KEY",
} as const;
export type KeyProvider = keyof typeof PROVIDER_KEYS;
@@ -19,23 +17,42 @@ export type ProviderKeyChanges = Partial<Record<KeyProvider, string>>;
export const userEnvironmentFile = (home: string, instance: string): string =>
path.join(home, "instances", instance, "user.env");
-// The keys saved in `home`, by provider; unreadable counts as none.
-export function savedProviderKeys(
+// Voice keys a person may still write into user.env by hand; the page does
+// not take them, but diagnostics must redact them.
+const HAND_EDITED_KEYS = ["SONIOX_API_KEY", "XAI_API_KEY"];
+
+// user.env in `home`; unreadable counts as empty.
+function readUserEnvironment(
home: string,
instance: string,
-): Partial<Record<KeyProvider, string>> {
- let saved: Record<string, string | undefined>;
+): Record<string, string | undefined> {
try {
- saved = parseEnv(readFileSync(userEnvironmentFile(home, instance), "utf8"));
+ return parseEnv(readFileSync(userEnvironmentFile(home, instance), "utf8"));
} catch {
return {};
}
+}
+
+// The keys saved in `home`, by provider.
+export function savedProviderKeys(
+ home: string,
+ instance: string,
+): Partial<Record<KeyProvider, string>> {
+ const saved = readUserEnvironment(home, instance);
const keys: Partial<Record<KeyProvider, string>> = {};
for (const [provider, name] of Object.entries(PROVIDER_KEYS))
if (saved[name]?.trim()) keys[provider as KeyProvider] = saved[name].trim();
return keys;
}
+// Every key value user.env in `home` holds, for redaction.
+export function savedSecretValues(home: string, instance: string): string[] {
+ const saved = readUserEnvironment(home, instance);
+ return [...Object.values(PROVIDER_KEYS), ...HAND_EDITED_KEYS]
+ .map((name) => saved[name]?.trim())
+ .filter((value): value is string => !!value);
+}
+
// The installer's own input for the same edits.
export const installerKeyChanges = (
changes: ProviderKeyChanges,
diff --git a/apps/desktop/src/main/setup-command.test.ts b/apps/desktop/src/main/setup-command.test.ts
index a53acf56..1857d2a2 100644
--- a/apps/desktop/src/main/setup-command.test.ts
+++ b/apps/desktop/src/main/setup-command.test.ts
@@ -57,25 +57,36 @@ describe("parseSetupCommand", () => {
expect(
parseSetupCommand({
op: "local.start",
- keys: { composio: " key-0 ", soniox: " key-1 ", xai: "" },
+ keys: { composio: " key-0 " },
}),
- ).toEqual({
- op: "local.start",
- keys: { composio: "key-0", soniox: "key-1", xai: "" },
- });
+ ).toEqual({ op: "local.start", keys: { composio: "key-0" } });
+ expect(
+ parseSetupCommand({ op: "local.start", keys: { composio: "" } }),
+ ).toEqual({ op: "local.start", keys: { composio: "" } });
+ // Voice keys are saved in the app, not on the setup page.
+ for (const provider of ["soniox", "xai"])
+ expect(() =>
+ parseSetupCommand({ op: "local.start", keys: { [provider]: "x" } }),
+ ).toThrow();
expect(() =>
parseSetupCommand({ op: "local.start", keys: { livekit: "x" } }),
).toThrow();
expect(() =>
- parseSetupCommand({ op: "local.start", keys: { xai: "a b" } }),
+ parseSetupCommand({ op: "local.start", keys: { composio: "a b" } }),
).toThrow();
expect(() =>
- parseSetupCommand({ op: "local.start", keys: { xai: "x".repeat(513) } }),
+ parseSetupCommand({
+ op: "local.start",
+ keys: { composio: "x".repeat(513) },
+ }),
).toThrow();
// A rejected key is not repeated in the error.
let message = "";
try {
- parseSetupCommand({ op: "local.start", keys: { xai: "secret value" } });
+ parseSetupCommand({
+ op: "local.start",
+ keys: { composio: "secret value" },
+ });
} catch (error) {
message = String(error);
}
diff --git a/apps/desktop/src/main/setup-command.ts b/apps/desktop/src/main/setup-command.ts
index 98951fdb..2df7bb9f 100644
--- a/apps/desktop/src/main/setup-command.ts
+++ b/apps/desktop/src/main/setup-command.ts
@@ -22,8 +22,6 @@ const setupCommand = z.discriminatedUnion("op", [
keys: z
.object({
composio: providerKey.optional(),
- soniox: providerKey.optional(),
- xai: providerKey.optional(),
})
.strict()
.optional(),
diff --git a/apps/desktop/src/shared/setup.ts b/apps/desktop/src/shared/setup.ts
index 66f167c5..d003477d 100644
--- a/apps/desktop/src/shared/setup.ts
+++ b/apps/desktop/src/shared/setup.ts
@@ -37,8 +37,6 @@ export interface SetupLocalServer {
// Which provider keys are saved there; the page never sees them.
readonly keys: {
readonly composio: boolean;
- readonly soniox: boolean;
- readonly xai: boolean;
};
// While the "signin" step shows: the AI runtime's own sign-in.
readonly signIn?: SetupRuntimeSignIn;
@@ -113,8 +111,6 @@ export type SetupLocalRuntime =
// removes it and an absent provider keeps it.
export interface SetupProviderKeys {
readonly composio?: string;
- readonly soniox?: string;
- readonly xai?: string;
}
export interface SetupState {
diff --git a/apps/desktop/src/shell/setup-page.test.ts b/apps/desktop/src/shell/setup-page.test.ts
index db41a473..7d33498d 100644
--- a/apps/desktop/src/shell/setup-page.test.ts
+++ b/apps/desktop/src/shell/setup-page.test.ts
@@ -40,7 +40,7 @@ const state = (
attempt: 1,
localModels: { state: "unavailable" },
location: { path: "~/.simplexai", custom: false },
- keys: { composio: false, soniox: false, xai: false },
+ keys: { composio: false },
...(account ? { account } : {}),
},
});
diff --git a/apps/desktop/src/shell/setup.html b/apps/desktop/src/shell/setup.html
index 0cafeff6..8fc632f7 100644
--- a/apps/desktop/src/shell/setup.html
+++ b/apps/desktop/src/shell/setup.html
@@ -1358,8 +1358,8 @@
<div class="text">
<strong>API keys</strong
><span class="sub"
- >Optional. Composio connects apps; Soniox and xAI enable
- voice input. Keys stay on this computer.</span
+ >Optional. Composio connects apps; turn on voice inside the
+ app. Keys stay on this computer.</span
>
</div>
<div class="keys">
@@ -1378,36 +1378,6 @@
<button type="button" class="change" data-remove="composio">
Remove
</button>
- <label for="key-soniox">Soniox</label>
- <input
- id="key-soniox"
- type="password"
- data-key="soniox"
- autocomplete="off"
- spellcheck="false"
- aria-label="Soniox API key"
- />
- <button type="button" class="change" data-reveal="soniox">
- Show
- </button>
- <button type="button" class="change" data-remove="soniox">
- Remove
- </button>
- <label for="key-xai">xAI</label>
- <input
- id="key-xai"
- type="password"
- data-key="xai"
- autocomplete="off"
- spellcheck="false"
- aria-label="xAI API key"
- />
- <button type="button" class="change" data-reveal="xai">
- Show
- </button>
- <button type="button" class="change" data-remove="xai">
- Remove
- </button>
</div>
<p class="keys-note" id="keys-note"></p>
</div>
diff --git a/packages/local-installation/AGENTS.md b/packages/local-installation/AGENTS.md
index 47b97d2c..f4678edb 100644
--- a/packages/local-installation/AGENTS.md
+++ b/packages/local-installation/AGENTS.md
@@ -17,11 +17,14 @@ Each instance directory holds `user.env` (0600), the only file a person edits:
`compose.env` / `native.env` over a developer checkout's `.env` and under the
installer's own values; other names are ignored with a warning, and the file
is created from a template once and never rewritten. The desktop source
-package's `.env` is not read. In a release, a voice key turns on the Compose
-`voice` profile, which runs LiveKit (pinned by digest, pulled only then) with
-the key pair and media ports in the instance's `livekit.env`; the gateway
-forwards `/rtc` to it. `compose up` recreates what a changed `user.env`
-touches; a native process restarts when its generated environment changes.
+package's `.env` is not read. Voice keys are normally saved in the app
+(TeamHub); a key in `user.env` overrides it. Whenever the distribution has
+voice tools for this computer, Native prepares them and runs LiveKit with
+the key pair and ports in the instance's `livekit.env`, with or without a
+voice key; without them, or when they fail to prepare, TeamHub gets
+`TEAMHUB_VOICE_MEDIA=off` and the install continues. The services' `voice`
+setting tracks only the tools, so a key change never restarts them through
+it. A native process restarts when its generated environment changes.
Every update or recreate path stops node-services on its own, right before
TeamHub restarts (natively: for a changed configuration) and while TeamHub is
still up, so its graceful shutdown requeues in-flight Agent Runs.
diff --git a/packages/local-installation/src/native-source-flow.test.ts b/packages/local-installation/src/native-source-flow.test.ts
index 1612721a..39e6f027 100644
--- a/packages/local-installation/src/native-source-flow.test.ts
+++ b/packages/local-installation/src/native-source-flow.test.ts
@@ -988,61 +988,112 @@ test("bundled services that do not verify fall back to installing packages", asy
);
expect(existsSync(directory)).toBe(false);
});
-for (const bundled of [true, false])
- test(`saved voice keys ${bundled ? "start LiveKit and put ffmpeg on PATH" : "stay off without voice tools"}`, async () => {
- const f = await fixture();
- vi.mocked(prepareRuntime).mockResolvedValue({
- code: 0,
- state: "ready",
- message: "ready",
- });
- await updateUserKeys(path.join(f.home, "instances", "native-voice"), {
- SONIOX_API_KEY: "soniox-1",
- });
- const bin = path.join(f.home, "voice", "bin");
+async function installVoice(
+ tools: "bundled" | "absent" | "failed",
+ keys: Record<string, string> = {},
+ f?: Awaited<ReturnType<typeof fixture>>,
+) {
+ f ??= await fixture();
+ vi.mocked(prepareRuntime).mockResolvedValue({
+ code: 0,
+ state: "ready",
+ message: "ready",
+ });
+ if (Object.keys(keys).length)
+ await updateUserKeys(path.join(f.home, "instances", "native-voice"), keys);
+ const bin = path.join(f.home, "voice", "bin");
+ if (tools === "failed")
+ vi.mocked(prepareNativeVoiceTools).mockRejectedValue(
+ new Error("voice tools download failed"),
+ );
+ else
vi.mocked(prepareNativeVoiceTools).mockResolvedValue(
- bundled ? { bin, livekit: path.join(bin, "livekit-server") } : undefined,
+ tools === "bundled"
+ ? { bin, livekit: path.join(bin, "livekit-server") }
+ : undefined,
);
- const settings = {
- httpPort: 30000,
- rtcPort: 30001,
- apiKey: "APIabcdef123456",
- apiSecret: "s".repeat(64),
- };
- vi.mocked(readLiveKitSettings).mockResolvedValue(settings);
- const events: string[] = [];
- await installNativeSource({
- home: f.home,
- repo: f.repo,
- name: "native-voice",
- setupChoice: "pi",
- externalComputer: true,
- signal: new AbortController().signal,
- onEvent: (event) => events.push(event.message),
- });
- const services = vi
- .mocked(startNativeProcess)
- .mock.calls.map(([options]) => options)
- .filter((options) => options.name !== "postgres");
- const env = services.find(
- (options) => options.name === "node-services",
- )!.env;
- // A key or tools change restarts the services that read them.
+ const settings = {
+ httpPort: 30000,
+ rtcPort: 30001,
+ apiKey: "APIabcdef123456",
+ apiSecret: "s".repeat(64),
+ };
+ vi.mocked(readLiveKitSettings).mockResolvedValue(settings);
+ const events: string[] = [];
+ await installNativeSource({
+ home: f.home,
+ repo: f.repo,
+ name: "native-voice",
+ setupChoice: "pi",
+ externalComputer: true,
+ signal: new AbortController().signal,
+ onEvent: (event) => events.push(event.message),
+ });
+ const services = vi
+ .mocked(startNativeProcess)
+ .mock.calls.map(([options]) => options)
+ .filter((options) => options.name !== "postgres");
+ const env = (name: string) =>
+ services.find((options) => options.name === name)!.env;
+ return { f, bin, settings, events: events.join(""), services, env };
+}
+
+for (const keys of [{}, { SONIOX_API_KEY: "soniox-1" }] as Record<
+ string,
+ string
+>[])
+ test(`voice tools start LiveKit and put ffmpeg on PATH ${Object.keys(keys).length ? "with" : "without"} a voice key`, async () => {
+ const { bin, settings, events, services, env } = await installVoice(
+ "bundled",
+ keys,
+ );
+ expect(prepareNativeVoiceTools).toHaveBeenCalled();
for (const options of services)
- expect(JSON.parse(options.settings!).voice).toBe(bundled ? bin : "off");
- if (bundled) {
- expect(startNativeLiveKit).toHaveBeenCalledWith(
- expect.objectContaining({
- executable: path.join(bin, "livekit-server"),
- settings,
- }),
- );
- expect(env.SONIOX_API_KEY).toBe("soniox-1");
- expect(env.PATH!.split(path.delimiter)[0]).toBe(bin);
- } else {
- expect(startNativeLiveKit).not.toHaveBeenCalled();
- expect(env.SONIOX_API_KEY).toBe("");
- expect(events.join("")).toContain("Voice stays off");
+ expect(JSON.parse(options.settings!).voice).toBe(bin);
+ expect(startNativeLiveKit).toHaveBeenCalledWith(
+ expect.objectContaining({
+ executable: path.join(bin, "livekit-server"),
+ settings,
+ }),
+ );
+ for (const name of ["teamhub", "node-services"]) {
+ expect(env(name).PATH!.split(path.delimiter)[0]).toBe(bin);
+ expect(env(name).TEAMHUB_VOICE_MEDIA).toBeUndefined();
+ expect(env(name).LIVEKIT_API_KEY).toBeTruthy();
}
- expect(events.join("")).not.toContain("soniox-1");
+ // A key in user.env passes through unchanged.
+ expect(env("node-services").SONIOX_API_KEY).toBe(
+ "SONIOX_API_KEY" in keys ? "soniox-1" : undefined,
+ );
+ expect(events).not.toContain("soniox-1");
});
+
+for (const tools of ["absent", "failed"] as const)
+ test(`voice stays off and the install continues when voice tools are ${tools}`, async () => {
+ const { events, services, env } = await installVoice(tools, {
+ SONIOX_API_KEY: "soniox-1",
+ });
+ for (const options of services)
+ expect(JSON.parse(options.settings!).voice).toBe("off");
+ expect(startNativeLiveKit).not.toHaveBeenCalled();
+ expect(env("teamhub").TEAMHUB_VOICE_MEDIA).toBe("off");
+ expect(env("node-services").SONIOX_API_KEY).toBe("soniox-1");
+ expect(events).toContain("Voice stays off");
+ if (tools === "failed")
+ expect(events).toContain("voice tools download failed");
+ expect(events).not.toContain("soniox-1");
+ });
+
+test("a changed voice key leaves the voice setting alone", async () => {
+ const first = await installVoice("bundled", { XAI_API_KEY: "xai-1" });
+ vi.mocked(startNativeProcess).mockClear();
+ const second = await installVoice(
+ "bundled",
+ { XAI_API_KEY: "xai-2" },
+ first.f,
+ );
+ const voice = (run: typeof first) =>
+ run.services.map((options) => JSON.parse(options.settings!).voice);
+ expect(voice(second)).toEqual(voice(first));
+ expect(second.env("node-services").XAI_API_KEY).toBe("xai-2");
+});
diff --git a/packages/local-installation/src/native-source.test.ts b/packages/local-installation/src/native-source.test.ts
index f9f44a6b..0282c39b 100644
--- a/packages/local-installation/src/native-source.test.ts
+++ b/packages/local-installation/src/native-source.test.ts
@@ -110,7 +110,6 @@ test("keys saved from the setup page and LiveKit reach the Native services", asy
const keys = { SONIOX_API_KEY: "soniox-1", XAI_API_KEY: "xai-1" };
const root = (name: string) => path.join(f.home, "instances", name);
await updateUserKeys(root("native-keys"), keys);
- // Native turns voice off at start when it has no voice tools.
const native = await prepareNativeConfiguration(f.repo, {
home: f.home,
name: "native-keys",
diff --git a/packages/local-installation/src/native-source.ts b/packages/local-installation/src/native-source.ts
index 4b2858b8..1917f0cc 100644
--- a/packages/local-installation/src/native-source.ts
+++ b/packages/local-installation/src/native-source.ts
@@ -563,17 +563,22 @@ async function runNativeSource(
}),
);
// Voice needs LiveKit and ffmpeg; the desktop ships them for each
- // computer. Without them (or without keys) voice stays off.
- const voiceKeys = Boolean(
- configured.env.SONIOX_API_KEY?.trim() ||
- configured.env.XAI_API_KEY?.trim(),
- );
- const voice = voiceKeys
- ? await timed("Preparing the voice tools", () =>
- prepareNativeVoiceTools({ home, signal, onEvent: emit }),
- )
- : undefined;
- if (voiceKeys && !voice)
+ // computer. They run whether or not a voice key is set, so a key
+ // saved later in the app works without a reinstall. A computer
+ // without them, or a failed preparation, keeps voice off and the
+ // install going; TeamHub then reports voice as unavailable.
+ const voice = await timed("Preparing the voice tools", () =>
+ prepareNativeVoiceTools({ home, signal, onEvent: emit }),
+ ).catch((error: unknown) => {
+ if (signal.aborted) throw error;
+ emit({
+ kind: "log",
+ stage,
+ message: `The voice tools could not be prepared: ${error instanceof Error ? error.message : String(error)}\n`,
+ });
+ return undefined;
+ });
+ if (!voice)
emit({
kind: "log",
stage,
@@ -591,9 +596,7 @@ async function runNativeSource(
.filter(Boolean)
.join(path.delimiter),
}
- : voiceKeys
- ? { SONIOX_API_KEY: "", XAI_API_KEY: "" }
- : {}),
+ : { TEAMHUB_VOICE_MEDIA: "off" }),
};
// Only TeamHub gets the identity key (serviceOptions); no other
// service may prove itself as this instance's server.
@@ -603,7 +606,9 @@ async function runNativeSource(
// change restarts them.
const shared = {
env: configured.env,
- voice: voice ? voice.bin : voiceKeys ? "off" : undefined,
+ // Tool availability only: a voice key saved in the app or user.env
+ // changes env, not this.
+ voice: voice ? voice.bin : "off",
};
const settings = JSON.stringify(shared);
// TeamHub also restarts for a new identity key; the digest keeps the
diff --git a/packages/local-installation/src/source-checkout.ts b/packages/local-installation/src/source-checkout.ts
index 25bdf54b..3e401932 100644
--- a/packages/local-installation/src/source-checkout.ts
+++ b/packages/local-installation/src/source-checkout.ts
@@ -192,8 +192,6 @@ export async function prepareSourceConfiguration(
const ports = instance.source.ports;
const generated = {
...supplied,
- // Native without its voice tools turns the voice keys off when it
- // starts the services (native-source.ts).
...user,
LOCAL_ENV_FILE: envFile,
COMPUTER_RELEASE_TARGETS: `${process.platform}-${process.arch}`,
diff --git a/packages/local-installation/src/user-environment.test.ts b/packages/local-installation/src/user-environment.test.ts
index 367f9c15..d1da5769 100644
--- a/packages/local-installation/src/user-environment.test.ts
+++ b/packages/local-installation/src/user-environment.test.ts
@@ -10,7 +10,6 @@ import {
userEnvironmentFile,
updateUserKeys,
userEnvironmentPending,
- voiceEnabled,
} from "./user-environment.js";
const root = () => mkdtemp(path.join(tmpdir(), "linger-user-env-"));
@@ -62,13 +61,6 @@ describe("readUserEnvironment", () => {
await expect(readUserEnvironment(directory)).rejects.toThrow(/chmod 600/);
},
);
-
- it("turns voice on for either voice key", () => {
- expect(voiceEnabled({})).toBe(false);
- expect(voiceEnabled({ COMPOSIO_API_KEY: "c", TZ: "UTC" })).toBe(false);
- expect(voiceEnabled({ SONIOX_API_KEY: "s" })).toBe(true);
- expect(voiceEnabled({ XAI_API_KEY: "x" })).toBe(true);
- });
});
describe("userEnvironmentPending", () => {
diff --git a/packages/local-installation/src/user-environment.ts b/packages/local-installation/src/user-environment.ts
index f0ec3b59..36db7d43 100644
--- a/packages/local-installation/src/user-environment.ts
+++ b/packages/local-installation/src/user-environment.ts
@@ -25,6 +25,8 @@ const TEMPLATE = `# Your own keys for this Linger instance. Linger reads only th
# Connected apps such as Gmail, GitHub and Slack (Composio).
COMPOSIO_API_KEY=
+# Voice keys are normally saved in the Linger app; a key here overrides the
+# app's.
# Recording, dictation and meeting transcripts (Soniox).
SONIOX_API_KEY=
# Grok Live voice mode (xAI); it does not need Soniox.
@@ -98,10 +100,6 @@ export async function readUserEnvironment(
return values;
}
-export function voiceEnabled(values: UserEnvironment): boolean {
- return Boolean(values.SONIOX_API_KEY || values.XAI_API_KEY);
-}
-
/**
* Whether user.env holds other keys than the generated configuration the
* services last started with, so they need a restart to take them.
diff --git a/scripts/dev-livekit.test.ts b/scripts/dev-livekit.test.ts
index 98ed1d0f..8e344534 100644
--- a/scripts/dev-livekit.test.ts
+++ b/scripts/dev-livekit.test.ts
@@ -9,19 +9,12 @@ const liveKit = {
};
describe("planDevLiveKit", () => {
- it("leaves LiveKit off without a voice key", () => {
- expect(planDevLiveKit({ ...liveKit, SONIOX_API_KEY: " " }).action).toBe(
- "skip",
- );
- });
-
- it("runs LiveKit on the LIVEKIT_URL port with the .env key pair", () => {
- const plan = planDevLiveKit({ ...liveKit, XAI_API_KEY: "xai-test" });
+ it("runs LiveKit on the LIVEKIT_URL port without a voice key", () => {
+ const plan = planDevLiveKit({ ...liveKit });
expect(plan).toMatchObject({
action: "run",
httpPort: 17880,
keys: "devkey: devsecret-livekit-voice-local-only-32-bytes",
- ffmpegNeeded: false,
});
if (plan.action !== "run") throw new Error("expected a run plan");
expect(JSON.parse(plan.config)).toMatchObject({
@@ -32,17 +25,11 @@ describe("planDevLiveKit", () => {
expect(plan.config).not.toContain("devsecret");
});
- it("asks for ffmpeg only when Soniox records", () => {
- const plan = planDevLiveKit({ ...liveKit, SONIOX_API_KEY: "soniox" });
- expect(plan).toMatchObject({ action: "run", ffmpegNeeded: true });
- });
-
it("uses a LiveKit server on another host instead of starting one", () => {
expect(
planDevLiveKit({
...liveKit,
LIVEKIT_URL: "wss://livekit.example.com",
- SONIOX_API_KEY: "soniox",
}).action,
).toBe("skip");
});
@@ -50,7 +37,6 @@ describe("planDevLiveKit", () => {
it("names the missing LiveKit settings", () => {
expect(() =>
planDevLiveKit({
- SONIOX_API_KEY: "soniox",
LIVEKIT_URL: liveKit.LIVEKIT_URL,
}),
).toThrow(/LIVEKIT_API_KEY/);
diff --git a/scripts/dev-livekit.ts b/scripts/dev-livekit.ts
index 2383a8e7..bacdae6d 100644
--- a/scripts/dev-livekit.ts
+++ b/scripts/dev-livekit.ts
@@ -3,9 +3,10 @@ import path from "node:path";
import { fileURLToPath } from "node:url";
// `pnpm dev` runs the LiveKit server voice needs, as docker-compose.yml does,
-// with the same ports and keys from .env. It runs only while a voice key is
-// set and LIVEKIT_URL names this computer; otherwise the services use the
-// LiveKit that LIVEKIT_URL names, or voice stays off.
+// with the same ports and keys from .env, whether or not a voice key is set,
+// so a key saved later in the app works without a restart. It runs while
+// LIVEKIT_URL names this computer; otherwise the services use the LiveKit
+// that LIVEKIT_URL names.
// The media ports of the livekit service in docker-compose.yml.
const RTC_UDP_PORT = 7882;
@@ -18,18 +19,9 @@ export type LiveKitDevPlan =
httpPort: number;
keys: string;
config: string;
- ffmpegNeeded: boolean;
};
export function planDevLiveKit(environment: NodeJS.ProcessEnv): LiveKitDevPlan {
- const soniox = Boolean(environment.SONIOX_API_KEY?.trim());
- const xai = Boolean(environment.XAI_API_KEY?.trim());
- if (!soniox && !xai)
- return {
- action: "skip",
- reason:
- "Voice is off: set SONIOX_API_KEY or XAI_API_KEY in .env to run LiveKit with pnpm dev.",
- };
const url = environment.LIVEKIT_URL?.trim();
const key = environment.LIVEKIT_API_KEY?.trim();
const secret = environment.LIVEKIT_API_SECRET?.trim();
@@ -65,7 +57,6 @@ export function planDevLiveKit(environment: NodeJS.ProcessEnv): LiveKitDevPlan {
},
logging: { level: "info" },
}),
- ffmpegNeeded: soniox,
};
}
@@ -102,7 +93,7 @@ export async function runDevLiveKit(
console.log(plan.reason);
return 0;
}
- if (plan.ffmpegNeeded && !(onPath("ffmpeg") && onPath("ffprobe")))
+ if (!(onPath("ffmpeg") && onPath("ffprobe")))
console.warn(
"Recording needs ffmpeg and ffprobe on PATH; install them to save recordings.",
);
diff --git a/scripts/installs/README.md b/scripts/installs/README.md
index cad4b195..44d2b5a6 100644
--- a/scripts/installs/README.md
+++ b/scripts/installs/README.md
@@ -16,12 +16,15 @@ must stay private to you (`chmod 600`); otherwise the app stops and says how
to fix it. Docker Compose and `pnpm dev` read these keys from the root `.env`
instead.
-| Name | Turns on |
-| ------------------ | ------------------------------------------------------- |
-| `COMPOSIO_API_KEY` | Connected apps such as Gmail, GitHub and Slack |
-| `SONIOX_API_KEY` | Recording, dictation and meeting transcripts |
-| `XAI_API_KEY` | Grok Live voice mode, without Soniox |
-| `TZ` | The services' time zone, for example `America/New_York` |
+| Name | Turns on |
+| ------------------ | ------------------------------------------------------------ |
+| `COMPOSIO_API_KEY` | Connected apps such as Gmail, GitHub and Slack |
+| `SONIOX_API_KEY` | Recording, dictation and meeting transcripts (overrides app) |
+| `XAI_API_KEY` | Grok Live voice mode, without Soniox (overrides app) |
+| `TZ` | The services' time zone, for example `America/New_York` |
+
+Voice keys are normally saved in the app itself; a voice key written here
+still works and takes precedence over the one saved in the app.
```sh
XAI_API_KEY=xai-...
@@ -29,7 +32,8 @@ SONIOX_API_KEY=...
```
Quit and reopen the Linger app after editing it: services whose configuration
-changed restart, and LiveKit runs only while a voice key is set. Other names,
+changed restart. LiveKit runs whenever the app has voice tools for this
+computer, with or without a voice key. Other names,
such as `LINGER_SECRET_SEED` or ports, are ignored with a warning, because the
installer manages them. Keys never appear in installer logs or the app's
diagnostics.