AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.
HTML ai-agentcloudflarecloudflare-d1cloudflare-r2cloudflare-workersdockerelectronevernoteevernote-alternativeknowledge-basemcpnote-takingobsidian-alternativeoffline-firstpersonal-knowledge-basepwaself-hostedsqlitetiptapweb-clipper
Add direct speech service connection test
tianma-if1080b39791a8
diff --git a/apps/api/src/ai-routes.test.mjs b/apps/api/src/ai-routes.test.mjsindex 09ba0699..d73c0ddf 100644--- a/apps/api/src/ai-routes.test.mjs+++ b/apps/api/src/ai-routes.test.mjs@@ -120,7 +120,14 @@ describe("AI route contracts", () => {databaseEnvironment,);expect(saved.status).toBe(201);- expect(JSON.stringify(await saved.json())).not.toContain("secret");+ const settings = await saved.json();+ expect(JSON.stringify(settings)).not.toContain("secret");++ const credentialPath = `/api/v1/ai/transcription-providers/${settings.providers[0].id}/direct-credential`;+ const credential = await app.request(credentialPath, { method: "POST" }, databaseEnvironment);+ expect(credential.status).toBe(200);+ expect(credential.headers.get("Cache-Control")).toBe("no-store");+ expect(await credential.json()).toEqual({ apiKey: "secret" });const transcript = await app.request("/api/v1/memos/missing/resources/missing/transcription-target",@@ -136,6 +143,11 @@ describe("AI route contracts", () => {databaseEnvironment,);expect(denied.status).toBe(403);+ const deniedCredential = await scopedApp.request(credentialPath, { method: "POST" }, databaseEnvironment);+ expect(deniedCredential.status).toBe(403);+ const otherWorkspaceApp = createApp({ currentAuth: { ...auth, workspaceId: "ws_other" } });+ const otherWorkspaceCredential = await otherWorkspaceApp.request(credentialPath, { method: "POST" }, databaseEnvironment);+ expect(otherWorkspaceCredential.status).toBe(404);});test("accepts the shared semantic action catalog with required parameters", () => {diff --git a/apps/api/src/ai-routes.ts b/apps/api/src/ai-routes.tsindex 23c4678d..aeab8d26 100644--- a/apps/api/src/ai-routes.ts+++ b/apps/api/src/ai-routes.ts@@ -272,6 +272,27 @@ export const registerAiRoutes = (app: Hono<AppEnv>, dependencies: AiRouteDepende}});+ app.post("/api/v1/ai/transcription-providers/:providerId/direct-credential", async (context) => {+ const denied = requireUser(context);+ if (denied) return denied;+ if (dependencies.isDemoMode(context.env)) {+ return forbidden(context, "Speech transcription is unavailable in demo mode.");+ }+ try {+ const provider = await getAiTranscriptionProvider(+ context.env.storage.db,+ getWorkspaceId(context),+ context.req.param("providerId"),+ );+ if (!provider) return notFound(context, "Speech service not found.");+ const apiKey = await decryptAiCredential(provider.api_key_encrypted, context.env);+ context.header("Cache-Control", "no-store");+ return context.json({ apiKey });+ } catch (error) {+ return withAiError(context, error, "ai_transcription_failed");+ }+ });+app.post("/api/v1/ai/transcription-providers",zValidator("json", AiTranscriptionProviderCreateSchema, invalidTranscriptionSettings),diff --git a/apps/web/src/components/settings/SpeechProviderCard.tsx b/apps/web/src/components/settings/SpeechProviderCard.tsxindex c4be09b2..3bca6b7e 100644--- a/apps/web/src/components/settings/SpeechProviderCard.tsx+++ b/apps/web/src/components/settings/SpeechProviderCard.tsx@@ -1,7 +1,7 @@-import { useEffect, useState, type FormEvent, type ReactNode } from "react";+import { useEffect, useRef, useState, type FormEvent, type ReactNode } from "react";import { useMutation } from "@tanstack/react-query";import type { AiTranscriptionProvider, AiTranscriptionSettings, AiTranscriptionStandard } from "@edgeever/shared";-import { Loader2, MoreHorizontal, Pencil, Plus, Trash2 } from "lucide-react";+import { CheckCircle2, Loader2, MoreHorizontal, Pencil, Plus, Trash2 } from "lucide-react";import { useTranslation } from "react-i18next";import { aiErrorMessage, trimAiText } from "@/components/settings/ai-provider-options";import { Button } from "@/components/ui/button";@@ -42,8 +42,10 @@ export const SpeechProviderCard = ({const [baseUrl, setBaseUrl] = useState(saved.baseUrl);const [apiKey, setApiKey] = useState("");const [modelId, setModelId] = useState("");+ const [testModelConfigId, setTestModelConfigId] = useState(saved.models[0]?.id ?? "");const [showConnection, setShowConnection] = useState(false);const [showAddModel, setShowAddModel] = useState(false);+ const testAbortRef = useRef<AbortController | null>(null);useEffect(() => {setProvider(saved.provider);@@ -51,6 +53,11 @@ export const SpeechProviderCard = ({setBaseUrl(saved.baseUrl);}, [saved.baseUrl, saved.displayName, saved.provider]);+ useEffect(() => {+ setTestModelConfigId((current) => saved.models.some((model) => model.id === current)+ ? current : saved.models[0]?.id ?? "");+ }, [saved.models]);+const saveMutation = useMutation({mutationFn: () => api.updateAiTranscriptionProvider(saved.id, {provider,@@ -65,6 +72,22 @@ export const SpeechProviderCard = ({onChanged(settings);},});+ const testMutation = useMutation({+ mutationFn: async () => {+ const selectedModel = saved.models.find((model) => model.id === testModelConfigId);+ if (!selectedModel) throw new Error(t("speechTranscription.testModelRequired"));+ const controller = new AbortController();+ testAbortRef.current = controller;+ try {+ const key = apiKey.trim()+ || (await api.getAiTranscriptionDirectCredential(saved.id, controller.signal)).apiKey;+ const { testSpeechService } = await import("@/lib/transcribe-note-resource");+ return await testSpeechService({ baseUrl, modelId: selectedModel.modelId, apiKey: key }, controller.signal);+ } finally {+ if (testAbortRef.current === controller) testAbortRef.current = null;+ }+ },+ });const toggleMutation = useMutation({mutationFn: (isEnabled: boolean) => api.updateAiTranscriptionProvider(saved.id, {provider: saved.provider,@@ -93,16 +116,28 @@ export const SpeechProviderCard = ({const cardBusy = toggleMutation.isPending || deleteMutation.isPending || deleteModelMutation.isPending;const cardError = toggleMutation.error ?? deleteMutation.error ?? addModelMutation.error ?? deleteModelMutation.error;+ const connectionBusy = saveMutation.isPending || testMutation.isPending;+ const updateConnection = (change: { provider?: AiTranscriptionStandard; displayName?: string; baseUrl?: string; apiKey?: string }) => {+ if (change.provider !== undefined) setProvider(change.provider);+ if (change.displayName !== undefined) setDisplayName(change.displayName);+ if (change.baseUrl !== undefined) setBaseUrl(change.baseUrl);+ if (change.apiKey !== undefined) setApiKey(change.apiKey);+ testMutation.reset();+ };const resetConnectionForm = () => {setProvider(saved.provider);setDisplayName(saved.displayName);setBaseUrl(saved.baseUrl);setApiKey("");saveMutation.reset();+ testMutation.reset();};const handleConnectionChange = (open: boolean) => {setShowConnection(open);- if (!open) resetConnectionForm();+ if (!open) {+ testAbortRef.current?.abort();+ resetConnectionForm();+ }};const handleAddModelChange = (open: boolean) => {setShowAddModel(open);@@ -237,16 +272,16 @@ export const SpeechProviderCard = ({) : null}<Dialog open={showConnection} onOpenChange={handleConnectionChange}><DialogContent className="max-h-[calc(100vh-2rem)] overflow-y-auto sm:max-w-lg">- <form className="grid gap-4" onSubmit={(event: FormEvent) => { event.preventDefault(); if (readOnly) return; saveMutation.mutate(); }}>+ <form className="grid gap-4" onSubmit={(event: FormEvent) => { event.preventDefault(); if (readOnly || connectionBusy) return; saveMutation.mutate(); }}><DialogHeader><DialogTitle className="text-xs font-normal">{t("speechTranscription.editConnection")}</DialogTitle></DialogHeader><div className="grid gap-4 sm:grid-cols-2"><Field label={t("speechTranscription.displayName")}>- <Input className="h-9 text-xs" value={displayName} onChange={(event) => setDisplayName(event.target.value)} required maxLength={80} disabled={readOnly} />+ <Input className="h-9 text-xs" value={displayName} onChange={(event) => updateConnection({ displayName: event.target.value })} required maxLength={80} disabled={readOnly || connectionBusy} /></Field><Field label={t("speechTranscription.standard")}>- <Select value={provider} onValueChange={(value) => setProvider(value as AiTranscriptionStandard)} disabled={readOnly}>+ <Select value={provider} onValueChange={(value) => updateConnection({ provider: value as AiTranscriptionStandard })} disabled={readOnly || connectionBusy}><SelectTrigger className="h-9 bg-card text-xs font-normal"><SelectValue /></SelectTrigger><SelectContent><SelectItem value="openai-compatible">{t("speechTranscription.standards.openai-compatible")}</SelectItem>@@ -255,20 +290,41 @@ export const SpeechProviderCard = ({</Field></div><Field label={t("speechTranscription.baseUrl")} hint={t("speechTranscription.baseUrlHint")}>- <Input className="h-9 text-xs" value={baseUrl} onChange={(event) => setBaseUrl(event.target.value)} required inputMode="url" autoComplete="off" spellCheck={false} maxLength={500} disabled={readOnly} />+ <Input className="h-9 text-xs" value={baseUrl} onChange={(event) => updateConnection({ baseUrl: event.target.value })} required inputMode="url" autoComplete="off" spellCheck={false} maxLength={500} disabled={readOnly || connectionBusy} /></Field><Field label={t("speechTranscription.apiToken")} hint={saved.hasApiKey ? t("speechTranscription.apiTokenSavedHint") : t("speechTranscription.apiTokenHint")}><InputclassName="h-9 text-xs"type="password"value={apiKey}- onChange={(event) => setApiKey(event.target.value)}+ onChange={(event) => updateConnection({ apiKey: event.target.value })}placeholder={saved.hasApiKey ? t("speechTranscription.apiTokenStoredPlaceholder") : ""}autoComplete="new-password"maxLength={4096}- disabled={readOnly}+ disabled={readOnly || connectionBusy}/></Field>+ {saved.models.length ? (+ <Field label={t("speechTranscription.testModel")}>+ <Select value={testModelConfigId} onValueChange={(value) => { setTestModelConfigId(value); testMutation.reset(); }} disabled={connectionBusy}>+ <SelectTrigger className="h-9 bg-card text-xs font-normal"><SelectValue /></SelectTrigger>+ <SelectContent>+ {saved.models.map((model) => <SelectItem key={model.id} value={model.id}>{model.displayName}</SelectItem>)}+ </SelectContent>+ </Select>+ </Field>+ ) : <p className="text-xs text-slate-500">{t("speechTranscription.testModelRequired")}</p>}+ <p className="text-xs leading-5 text-slate-500">{t("speechTranscription.testHint")}</p>+ {testMutation.isSuccess ? (+ <p className="flex items-start gap-1.5 text-xs font-medium text-emerald-700" role="status">+ <CheckCircle2 className="h-4 w-4 shrink-0" />{t("speechTranscription.testSucceeded", { transcript: testMutation.data.slice(0, 160) })}+ </p>+ ) : null}+ {testMutation.isError ? (+ <p className="text-xs font-medium text-rose-600" role="alert">+ {aiErrorMessage(testMutation.error, t("speechTranscription.testFailed"), t("aiModel.encryptionKeyMissing"), t("speechTranscription.savedCredentialsUnavailable"))}+ </p>+ ) : null}{saveMutation.isError ? (<p className="text-xs font-medium text-rose-600" role="alert">{aiErrorMessage(saveMutation.error, t("speechTranscription.failed"), t("aiModel.encryptionKeyMissing"), t("speechTranscription.savedCredentialsUnavailable"))}@@ -276,7 +332,10 @@ export const SpeechProviderCard = ({) : null}<DialogFooter className="gap-2 sm:space-x-0"><Button type="button" variant="outline" className="text-xs font-normal" onClick={() => handleConnectionChange(false)}>{t("common.cancel")}</Button>- <Button type="submit" variant="solid" className="text-xs font-normal" disabled={readOnly || saveMutation.isPending}>+ <Button type="button" variant="outline" className="text-xs font-normal" disabled={readOnly || !baseUrl.trim() || !testModelConfigId || (!saved.hasApiKey && !apiKey.trim()) || connectionBusy} onClick={() => testMutation.mutate()}>+ {testMutation.isPending ? <Loader2 className="h-4 w-4 animate-spin" /> : null}{t("speechTranscription.test")}+ </Button>+ <Button type="submit" variant="solid" className="text-xs font-normal" disabled={readOnly || connectionBusy}>{saveMutation.isPending ? <Loader2 className="h-4 w-4 animate-spin" /> : null}{t("common.save")}</Button></DialogFooter>diff --git a/apps/web/src/components/settings/SpeechTranscriptionCard.tsx b/apps/web/src/components/settings/SpeechTranscriptionCard.tsxindex 448f9dbb..c159d6ce 100644--- a/apps/web/src/components/settings/SpeechTranscriptionCard.tsx+++ b/apps/web/src/components/settings/SpeechTranscriptionCard.tsx@@ -1,7 +1,7 @@-import { useState, type FormEvent, type ReactNode } from "react";+import { useRef, useState, type FormEvent, type ReactNode } from "react";import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";import { type AiTranscriptionSettings, type AiTranscriptionStandard } from "@edgeever/shared";-import { AudioLines, Loader2, Plus, TriangleAlert } from "lucide-react";+import { AudioLines, CheckCircle2, Loader2, Plus, TriangleAlert } from "lucide-react";import { useTranslation } from "react-i18next";import { aiErrorMessage } from "@/components/settings/ai-provider-options";import { SpeechProviderCard } from "@/components/settings/SpeechProviderCard";@@ -42,6 +42,7 @@ export const SpeechTranscriptionCard = ({ demoMode }: { demoMode: boolean }) =>});const [showAdd, setShowAdd] = useState(false);const [draft, setDraft] = useState(emptyDraft);+ const testAbortRef = useRef<AbortController | null>(null);const settings = settingsQuery.data;const providers = settings?.providers ?? [];@@ -71,6 +72,22 @@ export const SpeechTranscriptionCard = ({ demoMode }: { demoMode: boolean }) =>setDraft(emptyDraft);},});+ const testMutation = useMutation({+ mutationFn: async () => {+ const controller = new AbortController();+ testAbortRef.current = controller;+ try {+ const { testSpeechService } = await import("@/lib/transcribe-note-resource");+ return await testSpeechService({+ baseUrl: draft.baseUrl,+ modelId: draft.initialModelId,+ apiKey: draft.apiKey.trim(),+ }, controller.signal);+ } finally {+ if (testAbortRef.current === controller) testAbortRef.current = null;+ }+ },+ });const defaultMutation = useMutation({mutationFn: api.updateDefaultAiTranscriptionModel,onSuccess: applySettings,@@ -83,10 +100,16 @@ export const SpeechTranscriptionCard = ({ demoMode }: { demoMode: boolean }) =>const handleAddDialogChange = (open: boolean) => {setShowAdd(open);if (!open) {+ testAbortRef.current?.abort();setDraft(emptyDraft);createMutation.reset();+ testMutation.reset();}};+ const updateDraft = (change: Partial<typeof emptyDraft>) => {+ setDraft((current) => ({ ...current, ...change }));+ testMutation.reset();+ };return (<Card className="w-full min-w-0 overflow-hidden shadow-none">@@ -185,7 +208,7 @@ export const SpeechTranscriptionCard = ({ demoMode }: { demoMode: boolean }) =>className="grid gap-4"onSubmit={(event: FormEvent) => {event.preventDefault();- if (!canAdd || createMutation.isPending) return;+ if (!canAdd || createMutation.isPending || testMutation.isPending) return;createMutation.mutate();}}>@@ -194,22 +217,34 @@ export const SpeechTranscriptionCard = ({ demoMode }: { demoMode: boolean }) =></DialogHeader><div className="grid gap-4 sm:grid-cols-2"><Field label={t("speechTranscription.displayName")}>- <Input className="h-9 text-xs" value={draft.displayName} onChange={(event) => setDraft({ ...draft, displayName: event.target.value })} required maxLength={80} />+ <Input className="h-9 text-xs" value={draft.displayName} onChange={(event) => updateDraft({ displayName: event.target.value })} required maxLength={80} disabled={testMutation.isPending || createMutation.isPending} /></Field><SpeechStandardFieldvalue={draft.provider}- onChange={(provider) => setDraft({ ...draft, provider })}+ onChange={(provider) => updateDraft({ provider })}+ disabled={testMutation.isPending || createMutation.isPending}/></div><Field label={t("speechTranscription.baseUrl")} hint={t("speechTranscription.baseUrlHint")}>- <Input className="h-9 text-xs" value={draft.baseUrl} onChange={(event) => setDraft({ ...draft, baseUrl: event.target.value })} placeholder={t("speechTranscription.baseUrlPlaceholder")} required inputMode="url" autoComplete="off" spellCheck={false} maxLength={500} />+ <Input className="h-9 text-xs" value={draft.baseUrl} onChange={(event) => updateDraft({ baseUrl: event.target.value })} placeholder={t("speechTranscription.baseUrlPlaceholder")} required inputMode="url" autoComplete="off" spellCheck={false} maxLength={500} disabled={testMutation.isPending || createMutation.isPending} /></Field><Field label={t("speechTranscription.modelId")}>- <Input className="h-9 text-xs" value={draft.initialModelId} onChange={(event) => setDraft({ ...draft, initialModelId: event.target.value })} placeholder={t("speechTranscription.modelIdPlaceholder")} required autoComplete="off" spellCheck={false} maxLength={200} />+ <Input className="h-9 text-xs" value={draft.initialModelId} onChange={(event) => updateDraft({ initialModelId: event.target.value })} placeholder={t("speechTranscription.modelIdPlaceholder")} required autoComplete="off" spellCheck={false} maxLength={200} disabled={testMutation.isPending || createMutation.isPending} /></Field><Field label={t("speechTranscription.apiToken")} hint={t("speechTranscription.apiTokenHint")}>- <Input className="h-9 text-xs" type="password" value={draft.apiKey} onChange={(event) => setDraft({ ...draft, apiKey: event.target.value })} required autoComplete="new-password" maxLength={4096} />+ <Input className="h-9 text-xs" type="password" value={draft.apiKey} onChange={(event) => updateDraft({ apiKey: event.target.value })} required autoComplete="new-password" maxLength={4096} disabled={testMutation.isPending || createMutation.isPending} /></Field>+ <p className="text-xs leading-5 text-slate-500">{t("speechTranscription.testHint")}</p>+ {testMutation.isSuccess ? (+ <p className="flex items-start gap-1.5 text-xs font-medium text-emerald-700" role="status">+ <CheckCircle2 className="h-4 w-4 shrink-0" />{t("speechTranscription.testSucceeded", { transcript: testMutation.data.slice(0, 160) })}+ </p>+ ) : null}+ {testMutation.isError ? (+ <p className="text-xs font-medium text-rose-600" role="alert">+ {aiErrorMessage(testMutation.error, t("speechTranscription.testFailed"), t("aiModel.encryptionKeyMissing"), t("speechTranscription.savedCredentialsUnavailable"))}+ </p>+ ) : null}{createMutation.isError ? (<p className="text-xs font-medium text-rose-600" role="alert">{aiErrorMessage(createMutation.error, t("speechTranscription.failed"), t("aiModel.encryptionKeyMissing"), t("speechTranscription.savedCredentialsUnavailable"))}@@ -217,7 +252,10 @@ export const SpeechTranscriptionCard = ({ demoMode }: { demoMode: boolean }) =>) : null}<DialogFooter className="gap-2 sm:space-x-0"><Button type="button" variant="outline" className="text-xs font-normal" onClick={() => handleAddDialogChange(false)}>{t("common.cancel")}</Button>- <Button type="submit" variant="solid" className="text-xs font-normal" disabled={!canAdd || createMutation.isPending}>+ <Button type="button" variant="outline" className="text-xs font-normal" disabled={!canAdd || !draft.baseUrl.trim() || !draft.initialModelId.trim() || !draft.apiKey.trim() || createMutation.isPending || testMutation.isPending} onClick={() => testMutation.mutate()}>+ {testMutation.isPending ? <Loader2 className="h-4 w-4 animate-spin" /> : null}{t("speechTranscription.test")}+ </Button>+ <Button type="submit" variant="solid" className="text-xs font-normal" disabled={!canAdd || createMutation.isPending || testMutation.isPending}>{createMutation.isPending ? <Loader2 className="h-4 w-4 animate-spin" /> : null}{t("speechTranscription.addProvider")}</Button></DialogFooter>diff --git a/apps/web/src/lib/fixtures/speech-service-check.mp3 b/apps/web/src/lib/fixtures/speech-service-check.mp3new file mode 100644index 00000000..29b00f16Binary files /dev/null and b/apps/web/src/lib/fixtures/speech-service-check.mp3 differdiff --git a/apps/web/src/lib/transcribe-note-resource.test.mjs b/apps/web/src/lib/transcribe-note-resource.test.mjsindex 3f7d4934..fc61acf9 100644--- a/apps/web/src/lib/transcribe-note-resource.test.mjs+++ b/apps/web/src/lib/transcribe-note-resource.test.mjs@@ -2,7 +2,7 @@ import { describe, expect, test } from "bun:test";import { readFile } from "node:fs/promises";import { fileURLToPath } from "node:url";import { ALL_FORMATS, BufferSource, Input } from "mediabunny";-import { extractAudioParts, transcribePreparedAudioParts } from "./transcribe-note-resource.ts";+import { extractAudioParts, testSpeechService, transcribePreparedAudioParts } from "./transcribe-note-resource.ts";const fixturePath = fileURLToPath(new URL("./fixtures/transcription-video.mp4", import.meta.url));@@ -51,6 +51,39 @@ describe("client-side note media preparation", () => {input.dispose();});+ test("bundles a real spoken MP3 for provider connection checks", async () => {+ const bytes = await readFile(fileURLToPath(new URL("./fixtures/speech-service-check.mp3", import.meta.url)));+ expect(bytes.byteLength).toBeGreaterThan(1_000);+ const input = new Input({ formats: ALL_FORMATS, source: new BufferSource(bytes) });+ expect(await input.canRead()).toBe(true);+ expect(await input.getPrimaryAudioTrack()).not.toBeNull();+ input.dispose();+ });++ test("connection check sends its sample from the client without saving settings", async () => {+ const bytes = await readFile(fileURLToPath(new URL("./fixtures/speech-service-check.mp3", import.meta.url)));+ const requests = [];+ const transcript = await testSpeechService(+ { baseUrl: "https://speech.example/v1/", modelId: "whisper-1", apiKey: "test-token" },+ undefined,+ {+ sampleFetch: async (url) => {+ requests.push({ kind: "sample", url: String(url) });+ return new Response(bytes, { status: 200 });+ },+ providerFetch: async (url, init) => {+ requests.push({ kind: "provider", url: String(url), init });+ return Response.json({ text: "Hello, this is a speech recognition test." });+ },+ },+ );+ expect(transcript).toContain("speech recognition test");+ expect(requests.map((request) => request.kind)).toEqual(["sample", "provider"]);+ expect(requests[1].url).toBe("https://speech.example/v1/audio/transcriptions");+ expect(requests[1].init.body.get("file")).toBeInstanceOf(File);+ expect(requests[1].init.body.get("model")).toBe("whisper-1");+ });+test("sends each prepared segment directly to the configured speech endpoint", async () => {const requests = [];const completed = [];diff --git a/apps/web/src/lib/transcribe-note-resource.ts b/apps/web/src/lib/transcribe-note-resource.tsindex 99c4ff88..ff214729 100644--- a/apps/web/src/lib/transcribe-note-resource.ts+++ b/apps/web/src/lib/transcribe-note-resource.ts@@ -175,6 +175,7 @@ export async function transcribePreparedAudioParts(providerFetch: typeof fetch,signal?: AbortSignal,onProgress?: (completedSegments: number) => void,+ requestTimeoutMs = 180_000,): Promise<string> {const transcripts: string[] = [];for await (const file of parts) {@@ -190,8 +191,8 @@ export async function transcribePreparedAudioParts(body: form,redirect: "error",signal: signal- ? AbortSignal.any([signal, AbortSignal.timeout(180_000)])- : AbortSignal.timeout(180_000),+ ? AbortSignal.any([signal, AbortSignal.timeout(requestTimeoutMs)])+ : AbortSignal.timeout(requestTimeoutMs),});} catch {if (signal?.aborted) signal.throwIfAborted();@@ -208,3 +209,29 @@ export async function transcribePreparedAudioParts(}return transcripts.join("\n\n");}++export async function testSpeechService(+ target: { baseUrl: string; modelId: string; apiKey: string },+ signal?: AbortSignal,+ transport: { sampleFetch?: typeof fetch; providerFetch?: typeof fetch } = {},+): Promise<string> {+ const sampleResponse = await (transport.sampleFetch ?? fetch)(+ new URL("./fixtures/speech-service-check.mp3", import.meta.url),+ { signal },+ );+ if (!sampleResponse.ok) throw new Error("The built-in speech test audio is unavailable.");+ const sample = new File(+ [await sampleResponse.arrayBuffer()],+ "speech-service-check.mp3",+ { type: "audio/mpeg" },+ );+ async function* parts() { yield sample; }+ return transcribePreparedAudioParts(+ { ...target, baseUrl: target.baseUrl.trim().replace(/\/+$/, ""), modelId: target.modelId.trim() },+ parts(),+ transport.providerFetch ?? directProviderFetch,+ signal,+ undefined,+ 30_000,+ );+}diff --git a/docs/video-clip-spec.md b/docs/video-clip-spec.mdindex 68a05855..a54e8827 100644--- a/docs/video-clip-spec.md+++ b/docs/video-clip-spec.md@@ -8,6 +8,8 @@ Supported pages are ordinary YouTube videos and Shorts, and ordinary Bilibili viUsers can explicitly transcribe an audio or MP4/WebM video attachment already uploaded to a note. A workspace configures an OpenAI-compatible speech provider and default model. The API accepts only a note ID and an attachment ID belonging to that note; it does not accept a media URL. The instance validates attachment ownership and gives the signed-in client the current speech model URL, name, and credential; the credential is encrypted at rest on the instance. The web/desktop client reads the attachment in ranges through the existing resource API, extracts its audio track locally, and splits it by size or duration. The client sends each audio segment of at most 24 MB directly to the configured `/audio/transcriptions` service. The instance serves the original attachment bytes but does not extract or convert audio or relay provider requests. Browser calls require the provider to support cross-origin requests and put the credential in the current browser session; the desktop main process calls the provider locally. The result is shown for copying or insertion into the current note. Plugins can use the same client-side capability through `context.ai.transcribeResource(noteId, resourceId)` but do not receive provider credentials. Attachments remain subject to the normal upload limit; unreadable formats or audio tracks return an error.+When adding a service, users can test the unsaved URL, model ID, and token. When editing, they can select an existing model and test with either the stored token or a replacement. The current client sends a short bundled speech sample directly to the model service and shows its returned transcript. Testing does not save the form and may incur a small provider charge. Browser CORS limitations are the same as for normal transcription.+## Withdrawn external media retrieval design: technical notesThe following records an unreleased external media retrieval design for possible future evaluation of authorized use. **It does not describe current product behavior or a planned feature.** The withdrawn scope includes external audio retrieval, browser session reuse, automatic yt-dlp installation and updates, external video transcription jobs, and desktop polling. Note attachment transcription above is a separate implementation.diff --git a/docs/video-clip-spec.zh-CN.md b/docs/video-clip-spec.zh-CN.mdindex 41fb07b9..1270edde 100644--- a/docs/video-clip-spec.zh-CN.md+++ b/docs/video-clip-spec.zh-CN.md@@ -8,6 +8,8 @@用户可以在已上传到笔记的音频或 MP4/WebM 视频附件上主动选择「转录」。工作区配置 OpenAI 兼容语音模型和默认模型;API 仅接受笔记 ID 与归属该笔记的附件 ID,不接受媒体 URL。实例校验附件归属,并把当前语音模型地址、名称及凭据交给已登录客户端;凭据在实例上加密保存。Web/桌面客户端经原有资源接口分段读取附件,在本机提取音轨并按大小或时长切段,由客户端把每段不超过 24 MB 的音频直接发送到用户配置的 `/audio/transcriptions` 服务。实例只提供原有附件字节,不提取或转换音轨,也不转发模型请求。Web 浏览器中的直连要求模型服务支持跨域请求,并会使模型凭据进入当前浏览器会话;桌面端由本机主进程直接请求模型服务。识别文本先展示给用户,可复制或插入当前笔记。插件可通过 `context.ai.transcribeResource(noteId, resourceId)` 调用同一客户端能力,但不会拿到模型凭据。附件仍受普通上传上限约束;无法读取的媒体格式或音轨会明确报错。+添加服务时可用尚未保存的地址、模型 ID 和 Token 测试连接;编辑服务时可选择已添加的模型,并沿用已保存的 Token 或输入新 Token 测试。测试从当前客户端直连模型服务,发送一段内置短语音并显示返回的文本;测试不保存表单,可能产生少量模型费用。浏览器跨域限制与真实转录相同。+## 已撤回的外部媒体抓取方案:技术备忘以下记录未上线的外部媒体抓取设计,供以后评估授权场景时参考,**不是当前产品行为或待实现需求**。撤回范围包括外部音轨抓取、浏览器登录状态复用、yt-dlp 自动安装与更新、外部视频识别任务和桌面轮询。上面的笔记附件语音识别是独立实现。diff --git a/packages/client/src/index.ts b/packages/client/src/index.tsindex a0dc2383..ba3dd838 100644--- a/packages/client/src/index.ts+++ b/packages/client/src/index.ts@@ -958,6 +958,12 @@ export const createEdgeEverClient = (options: EdgeEverClientOptions = {}) => {{ method: "POST", signal },),+ getAiTranscriptionDirectCredential: (providerId: string, signal?: AbortSignal) =>+ request<{ apiKey: string }>(+ `/api/v1/ai/transcription-providers/${encodeURIComponent(providerId)}/direct-credential`,+ { method: "POST", signal },+ ),+createAiProvider: (payload: AiProviderCreatePayload) =>request<AiSettings>("/api/v1/ai/providers", {method: "POST",diff --git a/packages/shared/src/i18n/en-US.ts b/packages/shared/src/i18n/en-US.tsindex cee4a01e..02d86fee 100644--- a/packages/shared/src/i18n/en-US.ts+++ b/packages/shared/src/i18n/en-US.ts@@ -1201,6 +1201,12 @@ export const enUS = {serviceActions: "Service actions",addModel: "Add a model",editConnection: "Edit connection",+ test: "Test connection",+ testModel: "Model to test",+ testModelRequired: "Add a speech model to this service before testing the connection.",+ testHint: "A short built-in audio sample is sent directly from this client to the model service. This may incur a small provider charge. Testing does not save the form.",+ testSucceeded: "Connection works. Transcript: “{{transcript}}”",+ testFailed: "Speech service test failed.",removeModel: "Remove model",noModels: "No models yet",deleteProviderConfirm: "Delete the speech service “{{name}}”? Its saved token is deleted too.",diff --git a/packages/shared/src/i18n/ja.ts b/packages/shared/src/i18n/ja.tsindex df829983..26655a19 100644--- a/packages/shared/src/i18n/ja.ts+++ b/packages/shared/src/i18n/ja.ts@@ -1201,6 +1201,12 @@ export const ja = {serviceActions: "サービスの操作",addModel: "モデルを追加",editConnection: "接続を編集",+ test: "接続をテスト",+ testModel: "テストするモデル",+ testModelRequired: "接続をテストする前に、このサービスに音声モデルを追加してください。",+ testHint: "短い内蔵音声をこのクライアントからモデルサービスへ直接送信します。少額の利用料金が発生する場合があります。テストでは設定を保存しません。",+ testSucceeded: "接続できました。文字起こし結果:「{{transcript}}」",+ testFailed: "音声サービスのテストに失敗しました。",removeModel: "モデルを削除",noModels: "モデルはまだありません",deleteProviderConfirm: "音声サービス「{{name}}」を削除しますか?保存したトークンも削除されます。",diff --git a/packages/shared/src/i18n/pl.ts b/packages/shared/src/i18n/pl.tsindex 3e711150..c03ad9dd 100644--- a/packages/shared/src/i18n/pl.ts+++ b/packages/shared/src/i18n/pl.ts@@ -1201,6 +1201,12 @@ export const pl = {serviceActions: "Działania usługi",addModel: "Dodaj model",editConnection: "Edytuj połączenie",+ test: "Przetestuj połączenie",+ testModel: "Model do testu",+ testModelRequired: "Przed testem połączenia dodaj model rozpoznawania mowy do tej usługi.",+ testHint: "Krótka wbudowana próbka audio jest wysyłana bezpośrednio z tego klienta do usługi modelu. Może to spowodować niewielki koszt. Test nie zapisuje formularza.",+ testSucceeded: "Połączenie działa. Transkrypcja: „{{transcript}}”",+ testFailed: "Test usługi rozpoznawania mowy nie powiódł się.",removeModel: "Usuń model",noModels: "Nie ma jeszcze modeli",deleteProviderConfirm: "Usunąć usługę mowy „{{name}}”? Zapisany token też zostanie usunięty.",diff --git a/packages/shared/src/i18n/zh-CN.ts b/packages/shared/src/i18n/zh-CN.tsindex 5ad94b5f..1a77bd59 100644--- a/packages/shared/src/i18n/zh-CN.ts+++ b/packages/shared/src/i18n/zh-CN.ts@@ -1201,6 +1201,12 @@ export const zhCN = {serviceActions: "服务操作",addModel: "添加模型",editConnection: "编辑连接",+ test: "测试连接",+ testModel: "测试模型",+ testModelRequired: "请先为该服务添加一个语音模型,再测试连接。",+ testHint: "将从当前客户端直接发送一段内置短音频给模型服务;可能产生少量模型费用。测试不会保存表单。",+ testSucceeded: "连接可用,识别结果:“{{transcript}}”",+ testFailed: "语音服务测试失败。",removeModel: "移除模型",noModels: "还没有模型",deleteProviderConfirm: "删除语音服务「{{name}}」?保存的 Token 会一起删除。",