Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/web/src/speech/browserVoiceInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import type { PreparedConnection } from "@t3tools/client-runtime/connection";
import type { SpeechTranscriptionOptions, SpeechStreamText } from "@t3tools/contracts";

import { runtime } from "../lib/runtime";
import { speechRuntime as runtime } from "./runtime";
import { createBrowserPcmCapture } from "./browserPcmCapture";

export function createBrowserVoiceInputPlatform(input: {
Expand Down
25 changes: 25 additions & 0 deletions apps/web/src/speech/runtime.browser.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { RelayConnectionTarget, type PreparedConnection } from "@t3tools/client-runtime/connection";
import { getEnvironmentSpeechStatus } from "@t3tools/client-runtime/voice-input";
import { EnvironmentId } from "@t3tools/contracts";
import { expect, it } from "vite-plus/test";

import { speechRuntime } from "./runtime";

it("authorizes relay speech requests through the connection session", async () => {
const target = new RelayConnectionTarget({
environmentId: EnvironmentId.make("speech-relay-test"),
label: "Speech destination",
});
const prepared: PreparedConnection = {
target,
environmentId: target.environmentId,
label: target.label,
httpBaseUrl: "https://speech.example.test",
socketUrl: "wss://speech.example.test/ws",
httpAuthorization: { _tag: "Dpop", accessToken: "expired", expiresAtEpochMs: 0 },
};
// No account is signed in: renewal must reach the authorizer rather than fail on a missing service.
await expect(speechRuntime.runPromise(getEnvironmentSpeechStatus(prepared))).rejects.toThrow(
"Could not authorize the environment request.",
);
});
17 changes: 17 additions & 0 deletions apps/web/src/speech/runtime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as Effect from "effect/Effect";
import type { HttpClient } from "effect/http";
import { AtomRegistry } from "effect/reactivity";

import { connectionAtomRuntime } from "../connection/runtime";
import { appAtomRegistry } from "../rpc/atomRegistry";

export const speechRuntime = {
runPromise: <A, E>(
effect: Effect.Effect<A, E, HttpClient.HttpClient>,
options?: { signal?: AbortSignal },
) =>
Effect.runPromise(
AtomRegistry.getResult(appAtomRegistry, connectionAtomRuntime.atom(effect)),
options,
),
};
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ vi.mock("../hooks/useSettings", () => ({
),
}),
}));
vi.mock("../lib/runtime", () => ({ runtime: { runPromise: Effect.runPromise } }));
vi.mock("./runtime", () => ({ speechRuntime: { runPromise: Effect.runPromise } }));
vi.mock("../components/ui/toast", () => ({ toastManager: { add: vi.fn() } }));
vi.mock("@t3tools/client-runtime/voice-input", async (importOriginal) => ({
...(await importOriginal<typeof import("@t3tools/client-runtime/voice-input")>()),
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/speech/useEnvironmentSpeechInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
useClientSettingsHydrated,
useEnvironmentSettings,
} from "../hooks/useSettings";
import { runtime } from "../lib/runtime";
import { speechRuntime as runtime } from "./runtime";
import { useEnvironment } from "../state/environments";
import { useEnvironmentScope, usePreparedConnection } from "../state/session";
import { createBrowserVoiceInputPlatform } from "./browserVoiceInput";
Expand Down
Loading