Skip to content

Commit c387f2f

Browse files
fix(server): advertise speech only on supported hosts
1 parent 508e798 commit c387f2f

4 files changed

Lines changed: 46 additions & 9 deletions

File tree

‎apps/server/src/environment/ServerEnvironment.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import * as Schema from "effect/Schema";
1111

1212
import { DEFAULT_SIGNAL_EXPORT } from "@t3tools/shared/observability";
1313
import * as OtelEnvironment from "@t3tools/shared/otelEnvironment";
14+
import { HostProcessArchitecture, HostProcessPlatform } from "@t3tools/shared/hostProcess";
1415

1516
import * as ServerSecretStore from "../auth/ServerSecretStore.ts";
1617
import {
@@ -79,6 +80,34 @@ const makeServerConfig = Effect.fn(function* (baseDir: string) {
7980
});
8081

8182
it.layer(NodeServices.layer)("ServerEnvironmentLive", (it) => {
83+
it.effect.each([
84+
{ platform: "darwin", architecture: "arm64", supported: true },
85+
{ platform: "darwin", architecture: "x64", supported: true },
86+
{ platform: "win32", architecture: "x64", supported: true },
87+
{ platform: "linux", architecture: "x64", supported: true },
88+
{ platform: "linux", architecture: "arm64", supported: true },
89+
{ platform: "win32", architecture: "arm64", supported: false },
90+
{ platform: "linux", architecture: "arm", supported: false },
91+
{ platform: "freebsd", architecture: "x64", supported: false },
92+
] as const)("advertises voice transcription on $platform-$architecture: $supported", (host) =>
93+
Effect.gen(function* () {
94+
const fileSystem = yield* FileSystem.FileSystem;
95+
const baseDir = yield* fileSystem.makeTempDirectoryScoped({
96+
prefix: "t3-server-environment-speech-test-",
97+
});
98+
const descriptor = yield* Effect.gen(function* () {
99+
const serverEnvironment = yield* ServerEnvironment.ServerEnvironment;
100+
return yield* serverEnvironment.getDescriptor;
101+
}).pipe(
102+
Effect.provide(makeServerEnvironmentLayer(baseDir)),
103+
Effect.provideService(HostProcessPlatform, host.platform),
104+
Effect.provideService(HostProcessArchitecture, host.architecture),
105+
);
106+
107+
expect(descriptor.capabilities.voiceTranscription).toBe(host.supported);
108+
}),
109+
);
110+
82111
it.effect.each([
83112
{ name: "missing", content: undefined },
84113
{ name: "empty", content: "" },

‎apps/server/src/environment/ServerEnvironment.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { resolveServerSelfUpdateCapability } from "../cloud/selfUpdate.ts";
2020
import { resolveServiceLauncherMode } from "../cloud/serviceLauncherClient.ts";
2121
import * as ServerConfig from "../config.ts";
2222
import * as ProcessRunner from "../processRunner.ts";
23+
import { isSpeechPlatformSupported } from "../speech/platform.ts";
2324
import { resolveServerEnvironmentLabel } from "./ServerEnvironmentLabel.ts";
2425
import { detectServerEnvironmentMachineKind } from "./ServerEnvironmentMachine.ts";
2526

@@ -246,7 +247,7 @@ export const make = Effect.gen(function* () {
246247
serverResolvedCommandContext: true,
247248
environmentIcon: true,
248249
projectCloneTracking: true,
249-
voiceTranscription: true,
250+
voiceTranscription: isSpeechPlatformSupported(hostPlatform, hostArchitecture),
250251
...(serverSelfUpdate === null ? {} : { serverSelfUpdate }),
251252
// V2 restart recovery uses the environment-owned opt-in. The old
252253
// per-update request flag is not wired into the V2 update RPC path.

‎apps/server/src/speech/SpeechService.ts‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
transcriptionCustomWords,
3838
} from "./customWords.ts";
3939
import { removeSpeechFillerWords } from "./fillerWords.ts";
40+
import { isSpeechPlatformSupported } from "./platform.ts";
4041

4142
const SAMPLE_RATE = 16_000;
4243
const MAX_SPEECH_DURATION_SECONDS = 5 * 60;
@@ -180,13 +181,6 @@ export class SpeechService extends Context.Service<
180181
}
181182
>()("t3/speech/SpeechService") {}
182183

183-
function supported(platform: string, architecture: string): string | null {
184-
const tuple = `${platform}-${architecture}`;
185-
return new Set(["darwin-arm64", "darwin-x64", "win32-x64", "linux-x64", "linux-arm64"]).has(tuple)
186-
? null
187-
: `voice transcription is not available on ${tuple}`;
188-
}
189-
190184
/** @public Service construction is part of the canonical Effect module API. */
191185
export const make = Effect.gen(function* () {
192186
const platform = yield* HostProcessPlatform;
@@ -196,7 +190,9 @@ export const make = Effect.gen(function* () {
196190
const path = yield* Path.Path;
197191
const clock = yield* Clock.Clock;
198192
const now = () => Number(clock.monotonicTimeNanosUnsafe()) / 1_000_000;
199-
const unsupportedReason = supported(platform, architecture);
193+
const unsupportedReason = isSpeechPlatformSupported(platform, architecture)
194+
? null
195+
: `voice transcription is not available on ${platform}-${architecture}`;
200196
const modelDirectory = path.join(config.stateDir, "speech", "models");
201197
let model: LoadedModel | undefined;
202198
let loadedModelId: string | undefined;

‎apps/server/src/speech/platform.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const SUPPORTED_PLATFORMS = new Set([
2+
"darwin-arm64",
3+
"darwin-x64",
4+
"win32-x64",
5+
"linux-x64",
6+
"linux-arm64",
7+
]);
8+
9+
export function isSpeechPlatformSupported(platform: string, architecture: string): boolean {
10+
return SUPPORTED_PLATFORMS.has(`${platform}-${architecture}`);
11+
}

0 commit comments

Comments
 (0)