diff --git a/apps/server/src/speech/CloudSpeech.test.ts b/apps/server/src/speech/CloudSpeech.test.ts
index 1a1054f8d251..a5f27502dec7 100644
--- a/apps/server/src/speech/CloudSpeech.test.ts
+++ b/apps/server/src/speech/CloudSpeech.test.ts
@@ -1,3 +1,4 @@
+// @effect-diagnostics processEnvInEffect:off - checks that the host key leaves the live environment.
import { it } from "@effect/vitest";
import {
DEFAULT_SPEECH_TRANSCRIPTION_OPTIONS,
@@ -5,6 +6,7 @@ import {
type SpeechTranscriptionOptions,
} from "@t3tools/contracts";
import * as SecretResolver from "@t3tools/secret-provider-core/server/SecretResolver";
+import * as ConfigProvider from "effect/ConfigProvider";
import * as Effect from "effect/Effect";
import * as Fiber from "effect/Fiber";
import * as Layer from "effect/Layer";
@@ -302,3 +304,53 @@ it.effect(
expect(yield* Effect.flip(transcribe(1600))).toMatchObject({ reason: "missing-key" });
}),
);
+
+it.effect(
+ "a host-injected AssemblyAI key works without settings and never outranks a saved key",
+ () =>
+ Effect.gen(function* () {
+ const upstream = vi.fn(async () => Response.json({ text: "hello" }));
+ process.env.ASSEMBLYAI_API_KEY = "host-fixture";
+ const service = yield* CloudSpeech.CloudSpeech.pipe(
+ Effect.provide(
+ CloudSpeech.layer.pipe(
+ Layer.provide(FetchHttpClient.layer),
+ Layer.provide(ServerSettings.ServerSettingsService.layerTest()),
+ Layer.provide(Layer.mock(SecretResolver.SecretResolver)({})),
+ Layer.provide(
+ ConfigProvider.layer(
+ ConfigProvider.fromEnv({ env: { ASSEMBLYAI_API_KEY: " host-fixture\n" } }),
+ ),
+ ),
+ ),
+ ),
+ );
+ // Agent subprocesses must not inherit the key.
+ expect(process.env.ASSEMBLYAI_API_KEY).toBeUndefined();
+ const authorization = () =>
+ new Headers(upstream.mock.calls.at(-1)![1]?.headers).get("authorization");
+ const transcribe = () =>
+ service
+ .transcribe("assemblyai", new Uint8Array(new Float32Array(1600).buffer), {
+ ...DEFAULT_SPEECH_TRANSCRIPTION_OPTIONS,
+ })
+ .pipe(Effect.provideService(FetchHttpClient.Fetch, upstream));
+ expect(yield* service.configured).toEqual({
+ openai: false,
+ xai: false,
+ openrouter: false,
+ assemblyai: true,
+ hostManaged: ["assemblyai"],
+ });
+ expect(yield* transcribe()).toBe("hello");
+ expect(authorization()).toBe("host-fixture");
+ yield* service.setKey("assemblyai", Redacted.make("saved-fixture"));
+ expect((yield* service.configured).hostManaged).toBeUndefined();
+ yield* transcribe();
+ expect(authorization()).toBe("saved-fixture");
+ yield* service.setKey("assemblyai", null);
+ expect((yield* service.configured).hostManaged).toEqual(["assemblyai"]);
+ yield* transcribe();
+ expect(authorization()).toBe("host-fixture");
+ }),
+);
diff --git a/apps/server/src/speech/CloudSpeech.ts b/apps/server/src/speech/CloudSpeech.ts
index b846bff387df..5c6e56890e8f 100644
--- a/apps/server/src/speech/CloudSpeech.ts
+++ b/apps/server/src/speech/CloudSpeech.ts
@@ -14,10 +14,12 @@ import {
} from "@t3tools/contracts";
import * as SecretResolver from "@t3tools/secret-provider-core/server/SecretResolver";
import { cloudSpeechLanguages, effectiveSpeechLanguage } from "@t3tools/shared/speech";
+import * as Config from "effect/Config";
import * as Context from "effect/Context";
import * as Effect from "effect/Effect";
import * as Exit from "effect/Exit";
import * as Layer from "effect/Layer";
+import * as Option from "effect/Option";
import * as Redacted from "effect/Redacted";
import * as Schema from "effect/Schema";
import { FetchHttpClient, HttpClient, HttpClientRequest, HttpClientResponse } from "effect/http";
@@ -35,6 +37,11 @@ const endpoints = {
};
const OPENROUTER_CATALOG_URL =
"https://openrouter.ai/api/v1/models?output_modalities=transcription&zdr=true";
+/**
+ * Keys a host injects at launch (for example `infisical run -- t3`), so nobody types or sees them.
+ * A key saved in settings still wins.
+ */
+const HOST_KEY_VARIABLES = { assemblyai: "ASSEMBLYAI_API_KEY" } as const;
const isApiKey = Schema.is(CloudSpeechApiKey);
const isModelId = Schema.is(CloudSpeechModelId);
const sameCredential = Schema.toEquivalence(SettingsSecretValue);
@@ -140,15 +147,34 @@ export const layer = Layer.effect(
const settings = yield* ServerSettings.ServerSettingsService;
const resolver = yield* SecretResolver.SecretResolver;
const http = yield* HttpClient.HttpClient;
- const credentials = settings.getSettings.pipe(
+ const hostAssemblyAi = Option.filter(
+ Option.map(yield* Config.Redacted(HOST_KEY_VARIABLES.assemblyai).pipe(Config.option), (key) =>
+ Redacted.value(key).trim(),
+ ),
+ isApiKey,
+ );
+ // Agent subprocesses inherit this environment; only this service should hold the key.
+ // @effect-diagnostics-next-line processEnvInEffect:off
+ delete process.env[HOST_KEY_VARIABLES.assemblyai];
+ const savedCredentials = settings.getSettings.pipe(
Effect.map((value) => value.cloudSpeechCredentials),
);
- const configured = credentials.pipe(
+ const credentials = savedCredentials.pipe(
+ Effect.map((saved) =>
+ !saved.assemblyai && Option.isSome(hostAssemblyAi)
+ ? { ...saved, assemblyai: hostAssemblyAi.value }
+ : saved,
+ ),
+ );
+ const configured = savedCredentials.pipe(
Effect.map(({ openai, xai, openrouter, assemblyai }) => ({
openai: Boolean(openai),
xai: Boolean(xai),
openrouter: Boolean(openrouter),
- assemblyai: Boolean(assemblyai),
+ assemblyai: Boolean(assemblyai) || Option.isSome(hostAssemblyAi),
+ ...(!assemblyai && Option.isSome(hostAssemblyAi)
+ ? { hostManaged: ["assemblyai" as const] }
+ : {}),
})),
);
const execute = (request: HttpClientRequest.HttpClientRequest) =>
diff --git a/apps/web/src/components/settings/CloudVoiceConfiguration.browser.test.tsx b/apps/web/src/components/settings/CloudVoiceConfiguration.browser.test.tsx
index b5eddbcc10df..aeb09849ebc2 100644
--- a/apps/web/src/components/settings/CloudVoiceConfiguration.browser.test.tsx
+++ b/apps/web/src/components/settings/CloudVoiceConfiguration.browser.test.tsx
@@ -22,7 +22,7 @@ vi.mock("../../state/environments", async (importOriginal) => ({
{
environmentId: "voice-host",
label: "Laptop",
- connection: { phase: "available" },
+ connection: { phase: "connected" },
serverConfig: {
secretReferences: true,
settings: {
@@ -46,6 +46,7 @@ const grantKey = "t3code:voice-audio-grant:v1";
async function withVoicePanel(
route: (url: URL, request: RequestInfo | URL, init?: RequestInit) => Promise | null,
body: (screen: Awaited>) => Promise,
+ { connected = true, path = "/" }: { connected?: boolean; path?: string } = {},
) {
const target = new PrimaryConnectionTarget({
environmentId: id,
@@ -53,12 +54,13 @@ async function withVoicePanel(
httpBaseUrl: window.location.origin,
wsBaseUrl: "ws://localhost",
});
- const prepared = Option.some({
+ const connection = Option.some({
...target,
target,
socketUrl: target.wsBaseUrl,
httpAuthorization: null,
});
+ const prepared = connected ? connection : Option.none();
using cleanup = new DisposableStack();
cleanup.defer(() => chooseAudioDestination(null));
const fetch = globalThis.fetch;
@@ -76,6 +78,7 @@ async function withVoicePanel(
{}}>
,
+ { router: path },
);
await body(screen);
},
@@ -99,13 +102,13 @@ it("cancelling a provider's setup keeps the current destination and writes nothi
},
async (screen) => {
const destination = screen.getByRole("combobox", { name: "Transcribe with" });
- await expect.element(destination).toHaveTextContent("Laptop");
+ await expect.element(destination).toHaveTextContent("Local model");
await destination.click();
- await page.getByRole("option", { name: "OpenAI via Laptop" }).click();
+ await page.getByRole("option", { name: "OpenAI" }).click();
const dialog = page.getByRole("dialog");
await dialog.getByRole("button", { name: "Cancel" }).click();
await expect.element(dialog).not.toBeInTheDocument();
- await expect.element(destination).toHaveTextContent("Laptop");
+ await expect.element(destination).toHaveTextContent("Local model");
expect(writes).toEqual([]);
},
);
@@ -132,7 +135,7 @@ it("enables the chosen provider only after a successful setup", async () => {
async (screen) => {
const destination = screen.getByRole("combobox", { name: "Transcribe with" });
await destination.click();
- await page.getByRole("option", { name: "OpenAI via Laptop" }).click();
+ await page.getByRole("option", { name: "OpenAI" }).click();
const dialog = page.getByRole("dialog");
await dialog.getByRole("combobox", { name: "OpenAI API key source" }).click();
await page.getByRole("option", { name: "Work vault" }).click();
@@ -144,7 +147,7 @@ it("enables the chosen provider only after a successful setup", async () => {
await dialog.getByLabelText("OpenAI API key reference").click();
await userEvent.keyboard("{Enter}");
await expect.element(dialog).not.toBeInTheDocument();
- await expect.element(destination).toHaveTextContent("OpenAI via Laptop");
+ await expect.element(destination).toHaveTextContent("OpenAI");
expect(writes).toEqual([{ key: { provider: "work", reference: "op://Work/Voice/key" } }]);
},
);
@@ -186,12 +189,12 @@ it("uses a provider's saved key without writing it, and turns dictation off", as
async (screen) => {
const destination = screen.getByRole("combobox", { name: "Transcribe with" });
await destination.click();
- await page.getByRole("option", { name: "Grok Voice Transcribe via Laptop" }).click();
+ await page.getByRole("option", { name: "Grok Voice Transcribe" }).click();
await page
.getByRole("dialog")
.getByRole("button", { name: "Use Grok Voice Transcribe" })
.click();
- await expect.element(destination).toHaveTextContent("Grok Voice Transcribe via Laptop");
+ await expect.element(destination).toHaveTextContent("Grok Voice Transcribe");
await destination.click();
await page.getByRole("option", { name: "Off", exact: true }).click();
await expect.element(destination).toHaveTextContent("Off");
@@ -230,7 +233,7 @@ it("OpenRouter needs an exact model, and changing it writes no credential", asyn
async (screen) => {
const destination = screen.getByRole("combobox", { name: "Transcribe with" });
await destination.click();
- await page.getByRole("option", { name: "OpenRouter via Laptop" }).click();
+ await page.getByRole("option", { name: "OpenRouter" }).click();
const dialog = page.getByRole("dialog");
const save = dialog.getByRole("button", { name: "Save and enable" });
await expect.element(save).toBeDisabled();
@@ -246,7 +249,7 @@ it("OpenRouter needs an exact model, and changing it writes no credential", asyn
await key.fill("");
await save.click();
await expect.element(dialog).not.toBeInTheDocument();
- await expect.element(destination).toHaveTextContent("OpenRouter via Laptop");
+ await expect.element(destination).toHaveTextContent("OpenRouter");
expect(grantModel()).toBe("other/listen-2");
expect(writes).toEqual([]);
await screen.getByRole("button", { name: "Manage OpenRouter" }).click();
@@ -256,9 +259,89 @@ it("OpenRouter needs an exact model, and changing it writes no credential", asyn
await page.getByRole("option", { name: /Acme: Transcribe 1/ }).click();
await dialog.getByRole("button", { name: "Save" }).click();
await expect.element(dialog).not.toBeInTheDocument();
- await expect.element(destination).toHaveTextContent("OpenRouter via Laptop");
+ await expect.element(destination).toHaveTextContent("OpenRouter");
expect(grantModel()).toBe("acme/transcribe-1");
expect(writes).toEqual([]);
},
);
});
+
+/** Every step either offers a real next action or names nothing the user can't find. */
+function expectNoDeadEnd(dialog: ReturnType) {
+ const element = dialog.element();
+ const buttons = [...element.querySelectorAll("button")].map((button) =>
+ button.textContent.trim(),
+ );
+ const forward = buttons.filter((label) => label && !["Cancel", "Close"].includes(label));
+ expect(forward.length).toBeGreaterThan(0);
+ for (const [, name] of element.textContent.matchAll(
+ /\b(?:press|click|tap|hit|open)\s+([A-Z][\w ]*?)(?=[ .,]|$)/g,
+ ))
+ expect(buttons.some((label) => label.includes(name!))).toBe(true);
+ if (/\bcontinue\b/i.test(element.textContent)) expect(buttons).toContain("Continue");
+}
+
+it("a backend on a disconnected environment points to a real control, never a missing Continue", async () => {
+ chooseAudioDestination(null);
+ await withVoicePanel(
+ () => null,
+ async (screen) => {
+ await screen.getByRole("combobox", { name: "Transcribe with" }).click();
+ await page.getByRole("option", { name: /AssemblyAI/ }).click();
+ const dialog = page.getByRole("dialog");
+ await expect
+ .element(dialog.getByText("Laptop isn’t connected.", { exact: false }))
+ .toBeVisible();
+ expectNoDeadEnd(dialog);
+ await dialog.getByRole("button", { name: "Open Environments" }).click();
+ await expect.element(dialog).not.toBeInTheDocument();
+ expect(screen.router?.state.location.pathname).toBe("/settings/connections");
+ },
+ { connected: false },
+ );
+});
+
+it("AssemblyAI with a host-provided key enables in one step, with nothing to type or remove", async () => {
+ // Never chosen, unlike an explicit Off.
+ window.localStorage.removeItem(grantKey);
+ const writes: unknown[] = [];
+ await withVoicePanel(
+ (url) => {
+ if (url.pathname === "/api/voice/cloud/keys")
+ return Promise.resolve(
+ Response.json({
+ openai: false,
+ xai: false,
+ assemblyai: true,
+ hostManaged: ["assemblyai"],
+ }),
+ );
+ if (url.pathname.endsWith("/key")) writes.push(url.pathname);
+ return null;
+ },
+ async (screen) => {
+ // The composer's mic sends first-time users here; the recommended backend is offered at once.
+ const dialog = page.getByRole("dialog");
+ await expect.element(dialog.getByText("Use AssemblyAI for dictation?")).toBeVisible();
+ await expect
+ .element(
+ dialog.getByText("was started with, so there’s nothing to enter", { exact: false }),
+ )
+ .toBeVisible();
+ expect(dialog.element().querySelector("input")).toBeNull();
+ expectNoDeadEnd(dialog);
+ await dialog.getByRole("button", { name: "Use AssemblyAI" }).click();
+ await expect.element(dialog).not.toBeInTheDocument();
+ const destination = screen.getByRole("combobox", { name: "Transcribe with" });
+ await expect.element(destination).toHaveTextContent("AssemblyAI");
+ await screen.getByRole("button", { name: "Manage key" }).click();
+ await expect.element(dialog).toBeVisible();
+ expect(dialog.element().querySelector("input")).toBeNull();
+ await expect
+ .element(dialog.getByRole("button", { name: "Remove key…" }))
+ .not.toBeInTheDocument();
+ expect(writes).toEqual([]);
+ },
+ { path: "/settings/voice#voice-transcription-destination" },
+ );
+});
diff --git a/apps/web/src/components/settings/CloudVoiceConfiguration.tsx b/apps/web/src/components/settings/CloudVoiceConfiguration.tsx
index b3579f5def75..4db3d9e0d270 100644
--- a/apps/web/src/components/settings/CloudVoiceConfiguration.tsx
+++ b/apps/web/src/components/settings/CloudVoiceConfiguration.tsx
@@ -29,6 +29,7 @@ import * as Option from "effect/Option";
import * as Schema from "effect/Schema";
import type { HttpClient } from "effect/http";
import { Atom, AsyncResult } from "effect/reactivity";
+import { useNavigate } from "@tanstack/react-router";
import { useId, useState } from "react";
import { isSecretsFeatureEnabled } from "../../env";
import {
@@ -164,6 +165,7 @@ export function CloudVoiceConfiguration({
const company = CLOUD_SPEECH_PROVIDER_NAMES[provider];
const routed = provider === "openrouter";
const formId = useId();
+ const navigate = useNavigate();
const prepared = Option.getOrNull(usePreparedConnection(id));
const canUse = useEnvironmentScope(id, AuthOrchestrationOperateScope);
const canManage = useEnvironmentScope(id, AuthSettingsWriteScope);
@@ -183,6 +185,9 @@ export function CloudVoiceConfiguration({
const [error, setError] = useState("");
const [model, setModel] = useState(currentModel ?? "");
const saved = AsyncResult.isSuccess(presence) ? presence.value?.[provider] : undefined;
+ // The host's launch environment supplies this key, so there is nothing to type or remove.
+ const hostManaged =
+ AsyncResult.isSuccess(presence) && presence.value?.hostManaged?.includes(provider) === true;
const existing = environment.serverConfig?.settings?.cloudSpeechCredentials?.[provider];
const sources =
isSecretsFeatureEnabled && environment.serverConfig?.secretReferences
@@ -210,7 +215,8 @@ export function CloudVoiceConfiguration({
);
const connected = canUse && prepared !== null;
// Fixed providers edit the key only when nothing is saved or the device already uses them.
- const editingKey = canManage && saved !== undefined && (routed || active || !saved);
+ const editingKey =
+ canManage && saved !== undefined && !hostManaged && (routed || active || !saved);
const listedModels = AsyncResult.isSuccess(models) ? (models.value?.models ?? null) : null;
const modelChosen = isModelId(model) && (listedModels?.some((m) => m.id === model) ?? false);
const keyReady = draft.trim() ? credential !== undefined : Boolean(saved);
@@ -309,6 +315,50 @@ export function CloudVoiceConfiguration({
>
);
+ const primaryAction = !connected ? (
+
+ ) : remove ? (
+
+ ) : routed ? (
+ saved !== undefined && (saved || canManage) ? (
+
+ ) : null
+ ) : editingKey ? (
+
+ ) : saved && !active ? (
+
+ ) : null;
+
return (
)}
- {connected && canManage && saved && (active || routed) && !remove && (
+ {connected && canManage && saved && !hostManaged && (active || routed) && !remove && (