Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

fix(ui-gallery): 组件演示里也能用麦克风了,语音设置打开是填好的样子

lmlihengeae43e451a5d
diff --git a/changelog/unreleased/2026-11-07-gallery-mock-asr.md b/changelog/unreleased/2026-11-07-gallery-mock-asr.md
new file mode 100644
index 00000000..e277b671
--- /dev/null
+++ b/changelog/unreleased/2026-11-07-gallery-mock-asr.md
@@ -0,0 +1,29 @@
+# The component gallery speaks too: the four speech endpoints are no longer missing from its mock
+
+- **Date:** 2026-11-07
+- **Type:** fix
+- **Scope:** `ui-gallery`
+- **Breaking:** no
+
+[中文](2026-11-07-gallery-mock-asr.zh.md)
+
+Every page of the component gallery runs against one in-memory demo world, and that world's mock has to
+answer every endpoint the Web App calls — a test walks the wrappers in
+`packages/web/src/api/endpoints.ts` one by one and names any it cannot route. Speech input arrived in the
+Web App with 0.6.5, so `getAsrConfig`, `putAsrConfig`, `testAsrConfig` and `asrTranscribe` came with it,
+while the mock kept answering them with `gallery_unmocked`: the microphone and "test connection" did
+nothing in the demo, and the package's suite went red on it.
+
+All four endpoints are answered now. The read is masked the way the server's is — `hasKey`, never the key;
+a save writes the address and the model into the demo world and records the key as stored when one is
+given; the connectivity check answers from the fields the form would save (an omitted one falling back to
+what is stored) and names the endpoint it used; a transcription says plainly that it is the demo's
+stand-in text. The demo world therefore carries one configured speech model, so the settings page opens
+on a filled form.
+
+## Detail
+
+- `packages/ui-gallery/src/app/mock/routes.ts`: the four routes, right after `/api/admin/settings` (the
+ order `endpoints.ts` keeps); `asrEndpoint()` derives the endpoint by the server's `asrWebSocketUrl` rule.
+- `packages/ui-gallery/src/app/mock/fixtures.ts`: one `DemoFixtures.asrConfig` row (the default gateway,
+ its one model, `hasKey: true`), typed by the server's `AsrConfig` DTO so a DTO change fails here first.
diff --git a/changelog/unreleased/2026-11-07-gallery-mock-asr.zh.md b/changelog/unreleased/2026-11-07-gallery-mock-asr.zh.md
new file mode 100644
index 00000000..a376a76d
--- /dev/null
+++ b/changelog/unreleased/2026-11-07-gallery-mock-asr.zh.md
@@ -0,0 +1,25 @@
+# 组件演示里也有语音输入了,四个接口不再漏在 mock 外面
+
+- **日期:** 2026-11-07
+- **类型:** fix
+- **范围:** `ui-gallery`
+- **破坏性:** 否
+
+[English](2026-11-07-gallery-mock-asr.md)
+
+组件演示(gallery)里的每一个页面都对着同一份内存里的演示数据跑,那套 mock 要回答 Web App 会调的
+每一个接口——有一条用例逐个调用 `packages/web/src/api/endpoints.ts` 里的封装,缺一条就报出来。语音
+输入随 0.6.5 进了 Web App,`getAsrConfig` / `putAsrConfig` / `testAsrConfig` / `asrTranscribe`
+四个封装也在其中,而 mock 当时没有它们的路由:那一页在演示里点麦克风、点「测试连通性」都只会得到
+`gallery_unmocked`,整包用例也因此红了。
+
+现在四个接口都答:读取按服务端的样子**只报 `hasKey`**、不回密钥;保存把地址、模型写进演示数据,
+密钥只要非空就记成「已存」;连通性检查按表单里那几个字段(缺省回落已存的)答 `ok` 与这次用的端点;
+转写照实说这是演示的替身文字。演示数据里因此多一行已配好的语音模型,设置页打开就是填好的样子。
+
+## 明细
+
+- `packages/ui-gallery/src/app/mock/routes.ts`:四个路由,紧跟在 `/api/admin/settings` 之后
+ (`endpoints.ts` 里也是这个顺序);`asrEndpoint()` 照服务端 `asrWebSocketUrl` 的规则推出端点。
+- `packages/ui-gallery/src/app/mock/fixtures.ts`:`DemoFixtures.asrConfig` 一行(默认网关地址、
+ 它那一个模型、`hasKey: true`),行按服务端 DTO(`AsrConfig`)标注,DTO 变了这里会先红。
diff --git a/packages/ui-gallery/src/app/mock/fixtures.ts b/packages/ui-gallery/src/app/mock/fixtures.ts
index 863cc959..71134f1a 100644
--- a/packages/ui-gallery/src/app/mock/fixtures.ts
+++ b/packages/ui-gallery/src/app/mock/fixtures.ts
@@ -10,6 +10,7 @@ import type {
AgentApiSettings,
AgentConfigResponse,
AgentSummary,
+ AsrConfig,
BenchmarkCaseSummary,
BenchmarkSummary,
CaseMaterial,
@@ -121,6 +122,11 @@ export interface DemoFixtures {
me: Omit<MeResponse, "user">;
prefs: UiPrefs;
serverSettings: ServerSettings;
+ /**
+ * The speech model the composer's microphone transcribes with, as the settings page reads it:
+ * masked, so a key is reported as stored rather than written down. A save mutates the row.
+ */
+ asrConfig: AsrConfig;
/** The storage ledger the Settings page renders; read-only, and what the page measures again. */
storageReport: StorageReport;
/**
@@ -1549,6 +1555,13 @@ export function buildFixtures(lang: Lang, now: number): DemoFixtures {
companyMode: false,
agentApiEnabled: true,
},
+ // A configured speech model, so the settings page opens on a filled form: the default
+ // gateway's address, its one model, and a key that is reported as stored rather than shown.
+ asrConfig: {
+ baseUrl: "https://tokendance.space",
+ model: "qwen-audio-3.1-asr-flash-streaming",
+ hasKey: true,
+ },
// A ledger with one of everything the page has a branch for: a class that is never a
// candidate, three that are, a duplicate-looking environment pair, and one path the scan
// could not read (the page shows its gaps rather than rounding them away).
diff --git a/packages/ui-gallery/src/app/mock/routes.ts b/packages/ui-gallery/src/app/mock/routes.ts
index 21ac75c5..3a132d80 100644
--- a/packages/ui-gallery/src/app/mock/routes.ts
+++ b/packages/ui-gallery/src/app/mock/routes.ts
@@ -29,6 +29,9 @@ import type {
AgentVaultConfigDto,
AllProjectSchedulesResponse,
ApprovalMode,
+ AsrConfigResponse,
+ AsrTestResponse,
+ AsrTranscribeResponse,
AuthResponse,
BenchmarkCasesResponse,
BuiltinBrowserHistoryResponse,
@@ -165,6 +168,23 @@ const record = (body: unknown): Record<string, unknown> =>
const str = (value: unknown, fallback = ""): string =>
typeof value === "string" ? value : fallback;
+/**
+ * Where the provider's WebSocket sits for a configured site — the server's own rule, minus its
+ * refusals: Alibaba's sites serve the models one path shorter, the reseller's gateway is the
+ * default shape. The gallery only needs a plausible string to render next to the check.
+ */
+function asrEndpoint(baseUrl: string): string {
+ let url: URL;
+ try {
+ url = new URL(baseUrl);
+ } catch {
+ return "wss://tokendance.space/gateway/alibaba/api-ws/v1/inference";
+ }
+ const bailian = url.hostname === "aliyuncs.com" || url.hostname.endsWith(".aliyuncs.com");
+ const scheme = url.protocol === "http:" ? "ws:" : "wss:";
+ return `${scheme}//${url.host}${bailian ? "/api-ws/v1/inference" : "/gateway/alibaba/api-ws/v1/inference"}`;
+}
+
/** Function declarations rather than arrows: only those narrow control flow as `never` calls. */
function readOnly(what: string): never {
return fail(409, READ_ONLY, `The gallery's demo cannot ${what}; it has no server behind it.`);
@@ -343,6 +363,36 @@ router
.get("/api/admin/settings", ({ store }): ServerSettingsResponse => ({
settings: store.f.serverSettings,
}))
+ // Speech input: the masked read, the save, the settings page's connectivity check and the
+ // composer's transcription. The key stays write-only here as it is on the server — a save
+ // records that one is stored, never what it is. There is no provider behind the gallery, so
+ // the check answers from what the form would save rather than from a real call.
+ .get("/api/asr/config", ({ store }): AsrConfigResponse => ({ config: store.f.asrConfig }))
+ .put("/api/asr/config", ({ store, body }): AsrConfigResponse => {
+ const update = record(body);
+ const baseUrl = str(update.baseUrl).trim();
+ const model = str(update.model).trim();
+ if (baseUrl !== "") store.f.asrConfig.baseUrl = baseUrl;
+ if (model !== "") store.f.asrConfig.model = model;
+ if (str(update.apiKey).trim() !== "") store.f.asrConfig.hasKey = true;
+ return { config: store.f.asrConfig };
+ })
+ .post("/api/asr/test", ({ store, body }): AsrTestResponse => {
+ const request = record(body);
+ const named = str(request.baseUrl).trim();
+ const baseUrl = named !== "" ? named : store.f.asrConfig.baseUrl;
+ const ok = str(request.apiKey).trim() !== "" || store.f.asrConfig.hasKey;
+ return {
+ ok,
+ message: ok ? "" : "Could not reach the speech service.",
+ endpoint: asrEndpoint(baseUrl),
+ };
+ })
+ .post("/api/asr/transcribe", (): AsrTranscribeResponse => ({
+ // Every signed-in user may talk into the admin's key. The gallery has no such key, so it
+ // answers with the one thing a demo can honestly say instead of a transcript.
+ text: "The gallery has no speech provider behind it, so this is the recording's stand-in text.",
+ }))
// The storage ledger's page, and the human-reviewed cleanup that reads it. The mode gates every
// write here exactly as it does on the server, so the gallery can be walked through both pages:
// off (the ledger alone, which is the default an untouched install has) and on (a bill to review,