dsh-xiaomi-tts 2.3.0 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/README.en.md +4 -2
  2. package/README.md +79 -12
  3. package/assets/image.png +0 -0
  4. package/lib/client/conversation.d.ts +26 -0
  5. package/lib/client/conversation.d.ts.map +1 -0
  6. package/lib/client/index.d.ts +0 -51
  7. package/lib/client/index.d.ts.map +1 -1
  8. package/lib/client/live-speech-controller.d.ts +44 -0
  9. package/lib/client/live-speech-controller.d.ts.map +1 -0
  10. package/lib/client/localization.d.ts +64 -0
  11. package/lib/client/localization.d.ts.map +1 -0
  12. package/lib/client/pcm-audio-queue.d.ts +21 -0
  13. package/lib/client/pcm-audio-queue.d.ts.map +1 -0
  14. package/lib/client/playback-controller.d.ts +29 -0
  15. package/lib/client/playback-controller.d.ts.map +1 -0
  16. package/lib/client/playback-types.d.ts +17 -0
  17. package/lib/client/playback-types.d.ts.map +1 -0
  18. package/lib/client/playback.d.ts +4 -0
  19. package/lib/client/playback.d.ts.map +1 -0
  20. package/lib/client/settings-card.d.ts +11 -0
  21. package/lib/client/settings-card.d.ts.map +1 -0
  22. package/lib/client/settings-scope.d.ts +6 -0
  23. package/lib/client/settings-scope.d.ts.map +1 -0
  24. package/lib/client/styles.d.ts +2 -0
  25. package/lib/client/styles.d.ts.map +1 -0
  26. package/lib/client/voice-design-picker.d.ts +14 -0
  27. package/lib/client/voice-design-picker.d.ts.map +1 -0
  28. package/lib/client.js +595 -382
  29. package/lib/client.js.map +1 -1
  30. package/lib/index.d.ts.map +1 -1
  31. package/lib/index.js +143 -2
  32. package/lib/{shared-DQA9zfpt.js → shared-Ari92Zhu.js} +29 -8
  33. package/lib/shared.d.ts +10 -1
  34. package/lib/shared.d.ts.map +1 -1
  35. package/lib/shared.js +2 -2
  36. package/package.json +3 -1
package/lib/client.js CHANGED
@@ -37,6 +37,8 @@ const TTS_SETTINGS_NAMESPACE = "xiaomi-mimo-tts";
37
37
  const TTS_ROUTE = "/plugins/xiaomi-mimo-tts/synthesize";
38
38
  /** Same-origin route that proxies MiMo PCM16 server-sent audio chunks. */
39
39
  const TTS_STREAM_ROUTE = "/plugins/xiaomi-mimo-tts/synthesize-stream";
40
+ /** Same-origin route that removes this plugin from the DSH Web profile. */
41
+ const TTS_UNINSTALL_ROUTE = "/plugins/xiaomi-mimo-tts/uninstall";
40
42
  /** Same-origin prefix used by the Web client to load voice-design preset icons. */
41
43
  const TTS_VOICE_DESIGN_ASSET_ROUTE = "/plugins/xiaomi-mimo-tts/voice-presets";
42
44
  /** Supported built-in Xiaomi MiMo voices. */
@@ -118,10 +120,12 @@ const TTS_PUNCTUATION = {
118
120
  "?": "?",
119
121
  ";": ";",
120
122
  "、": ",",
123
+ "(": ",",
124
+ ")": ",",
121
125
  " ": " "
122
126
  };
123
127
  /** Decorative punctuation can make TTS emit non-speech artifacts, so omit it entirely. */
124
- const TTS_NON_SPEECH_PUNCTUATION = /[()()\[\]【】[]〔〕〖〗{}{}「」『』《》〈〉“”‘’"'`<>::…—–-~]/gu;
128
+ const TTS_NON_SPEECH_PUNCTUATION = /[()\[\]【】[]〔〕〖〗{}{}「」『』《》〈〉“”‘’"'`<>:…—–-~]/gu;
125
129
  const TTS_URL_PATTERN = /\b(?:https?|ftp):\/\/[^\s<>()]+|\bwww\.[^\s<>()]+|\b(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+(?:com|cn|net|org|io|ai|dev|me|co|edu|gov|xyz|tech|info|app|site|link)(?:[/:?#][^\s<>()]*)?/giu;
126
130
  const TTS_WINDOWS_PATH_PATTERN = /(?:\b[A-Za-z]:[\\/]|\\\\)(?:[A-Za-z0-9._ -]+[\\/])*(?:[A-Za-z0-9._ -]+)/gu;
127
131
  const TTS_UNIX_PATH_PATTERN = /\/(?:[A-Za-z0-9._-]+\/)*(?:[A-Za-z0-9._-]+)/gu;
@@ -139,7 +143,7 @@ function removeTtsSymbols(value) {
139
143
  return value.replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F-\u009F\u200B-\u200F\u202A-\u202E\u2060-\u2064\u2066-\u206F\uFEFF]/g, " ").replace(/(?:\p{Extended_Pictographic}|\p{Emoji_Presentation}|\p{Regional_Indicator}|\p{Emoji_Modifier}|\p{So}|\uFE0E|\uFE0F|\u200D|\u20E3)/gu, " ");
140
144
  }
141
145
  function normalizeTtsPunctuation(value) {
142
- return value.replace(TTS_NON_SPEECH_PUNCTUATION, "").replace(/[,。!?;、 ]/gu, (character) => TTS_PUNCTUATION[character] ?? character).replace(/(^|\s)[,;:!?]+(?=\s|$)/g, "$1").replace(/([,;:])\s*([.!?])/g, "$2").replace(/\s+([,.;:!?])/g, "$1");
146
+ return value.replace(TTS_NON_SPEECH_PUNCTUATION, "").replace(/[,。!?;、() ]/gu, (character) => TTS_PUNCTUATION[character] ?? character).replace(/(^|\s)[,;:!?]+(?=\s|$)/g, "$1").replace(/([,;:])\s*([.!?])/g, "$2").replace(/\s+([,.;:!?])/g, "$1");
143
147
  }
144
148
  /**
145
149
  * Prepare assistant text for speech synthesis without changing the chat transcript.
@@ -196,16 +200,18 @@ function classifyLiveSpeechTransition(current, next) {
196
200
  if (current === null || current.sessionId !== next.sessionId || current.turn !== next.turn) return "new-turn";
197
201
  return current.step === next.step ? "same-step" : "same-turn";
198
202
  }
199
- /** Serializes sentence requests and makes cancellation independent from the playback backend. */
200
203
  var AbortableSentenceQueue = class {
201
204
  pending = [];
202
205
  current = null;
203
206
  revision = 0;
204
- constructor(start) {
207
+ busy = false;
208
+ constructor(start, options = {}) {
205
209
  this.start = start;
210
+ this.options = options;
206
211
  }
207
212
  enqueue(sentence) {
208
213
  this.pending.push(sentence);
214
+ this.setBusy(true);
209
215
  this.pump();
210
216
  }
211
217
  cancel() {
@@ -213,23 +219,38 @@ var AbortableSentenceQueue = class {
213
219
  this.pending.length = 0;
214
220
  this.current?.abort();
215
221
  this.current = null;
222
+ this.setBusy(false);
216
223
  }
217
224
  async pump() {
218
225
  if (this.current !== null) return;
219
226
  const sentence = this.pending.shift();
220
- if (sentence === void 0) return;
227
+ if (sentence === void 0) {
228
+ this.setBusy(false);
229
+ return;
230
+ }
221
231
  const revision = this.revision;
222
232
  const controller = new AbortController();
223
233
  this.current = controller;
224
234
  try {
225
235
  await this.start(sentence, controller.signal);
226
236
  } catch (error) {
227
- if (!controller.signal.aborted) throw error;
237
+ if (!controller.signal.aborted && revision === this.revision) {
238
+ this.pending.length = 0;
239
+ this.revision += 1;
240
+ this.options.onError?.(error);
241
+ }
228
242
  } finally {
229
243
  if (this.current === controller) this.current = null;
230
- if (revision === this.revision) this.pump();
244
+ if (revision === this.revision) if (this.pending.length > 0) this.pump();
245
+ else this.setBusy(false);
246
+ else this.setBusy(false);
231
247
  }
232
248
  }
249
+ setBusy(busy) {
250
+ if (this.busy === busy) return;
251
+ this.busy = busy;
252
+ this.options.onBusyChange?.(busy);
253
+ }
233
254
  };
234
255
  /** Defaults shared by the Schemastery config and the Web settings form. */
235
256
  const DEFAULT_TTS_SETTINGS = {
@@ -262,228 +283,32 @@ function resolveTtsSettings(value) {
262
283
  }
263
284
 
264
285
  //#endregion
265
- //#region src/client/index.tsx
266
- /** Client services required by this plugin. */
267
- const inject = [
268
- "slots",
269
- "locale",
270
- "connection",
271
- "remote",
272
- "settingsScope"
273
- ];
274
- const NS = "xiaomi-mimo-tts";
275
- const zh = {
276
- "action.play": "朗读回复",
277
- "action.pause": "暂停朗读",
278
- "action.resume": "继续朗读",
279
- "action.loading": "正在生成语音",
280
- "action.retry": "重新生成语音",
281
- "error.noText": "这条回复没有可朗读的正文。",
282
- "error.request": "语音生成失败。",
283
- "error.play": "浏览器阻止了自动播放,请点击朗读按钮。",
284
- "settings.title": "语音朗读 (Xiaomi MiMo)",
285
- "settings.description": "在助手回复操作栏中使用 Xiaomi MiMo TTS 生成并播放语音。",
286
- "settings.enabled": "显示朗读按钮",
287
- "settings.enabledHint": "关闭后不会在助手回复操作栏显示朗读按钮,也不会自动播报。",
288
- "settings.apiKey": "API Key",
289
- "settings.apiKeyHint": "密钥保存在 DSH 设置文件中,传到浏览器前会被脱敏。",
290
- "settings.apiKeyStatus": "只有输入新值并保存时才会替换现有密钥。",
291
- "settings.apiKeyConfigured": "已配置",
292
- "settings.getApiKey": "获取 API Key",
293
- "settings.autoPlay": "开启自动播报",
294
- "settings.autoPlayHint": "开启时会同步显示朗读按钮;浏览器也可能拒绝自动播放。",
295
- "settings.model": "TTS 模型",
296
- "settings.presetModel": "预置音色模型 (mimo-v2.5-tts)",
297
- "settings.voiceDesignModel": "自定义音色模型 (mimo-v2.5-tts-voicedesign)",
298
- "settings.modelAutoPlayHintPreset": "预置音色模型支持实时流式播放。",
299
- "settings.modelAutoPlayHintVoiceDesign": "自定义音色仅支持在回复完成后自动播放。",
300
- "settings.voice": "内置音色",
301
- "settings.voiceDesignPrompt": "自定义音色描述",
302
- "settings.customVoiceOption": "自定义",
303
- "settings.customVoiceSummary": "手动编写音色描述",
304
- "settings.voiceDesignPromptHint": "按“年龄段 + 性别、声音质感、语速节奏、情绪底色”描述声音本身;不写场景或动作。",
305
- "settings.format": "音频格式",
306
- "settings.save": "保存",
307
- "settings.saving": "保存中…",
308
- "settings.saved": "已保存",
309
- "settings.unsaved": "未保存",
310
- "settings.overridden": "已覆盖",
311
- "settings.reset": "恢复默认",
312
- "settings.discard": "放弃修改",
313
- "settings.failed": "保存失败,请重试。",
314
- "settings.readOnly": "当前 DSH 设置为只读。",
315
- "settings.secretPlaceholder": "输入新的 Xiaomi MiMo API Key",
316
- "settings.expand": "展开设置",
317
- "settings.collapse": "收起设置"
318
- };
319
- const en = {
320
- "action.play": "Read aloud",
321
- "action.pause": "Pause speech",
322
- "action.resume": "Resume speech",
323
- "action.loading": "Generating speech",
324
- "action.retry": "Generate speech again",
325
- "error.noText": "This response has no readable body text.",
326
- "error.request": "Speech generation failed.",
327
- "error.play": "The browser blocked autoplay. Click Read aloud to play it.",
328
- "settings.title": "Text To Speech (Xiaomi MiMo)",
329
- "settings.description": "Generate and play Xiaomi MiMo TTS audio from assistant message actions.",
330
- "settings.enabled": "Show read-aloud button",
331
- "settings.enabledHint": "When disabled, the read-aloud button and automatic speech are both turned off.",
332
- "settings.apiKey": "API Key",
333
- "settings.apiKeyHint": "Stored in DSH settings and redacted before settings are sent to the browser.",
334
- "settings.apiKeyStatus": "An existing key changes only when you save a new value.",
335
- "settings.apiKeyConfigured": "Configured",
336
- "settings.getApiKey": "Get API Key",
337
- "settings.autoPlay": "Enable automatic read-aloud",
338
- "settings.autoPlayHint": "Enabling it also shows the read-aloud button; the browser may reject autoplay.",
339
- "settings.model": "TTS model",
340
- "settings.presetModel": "Preset voices (mimo-v2.5-tts)",
341
- "settings.voiceDesignModel": "Custom voice design (mimo-v2.5-tts-voicedesign)",
342
- "settings.modelAutoPlayHintPreset": "Preset voices support realtime streaming playback.",
343
- "settings.modelAutoPlayHintVoiceDesign": "Custom voice design supports automatic playback only after the reply is complete.",
344
- "settings.voice": "Built-in voice",
345
- "settings.voiceDesignPrompt": "Custom voice description",
346
- "settings.customVoiceOption": "Custom",
347
- "settings.customVoiceSummary": "Write a custom voice description",
348
- "settings.voiceDesignPromptHint": "Describe the voice itself with age/gender, texture, pace, and emotional baseline; avoid scenes or actions.",
349
- "settings.format": "Audio format",
350
- "settings.save": "Save",
351
- "settings.saving": "Saving…",
352
- "settings.saved": "Saved",
353
- "settings.unsaved": "Unsaved",
354
- "settings.overridden": "Overridden",
355
- "settings.reset": "Restore default",
356
- "settings.discard": "Discard changes",
357
- "settings.failed": "Save failed. Try again.",
358
- "settings.readOnly": "DSH settings are read-only.",
359
- "settings.secretPlaceholder": "Enter a new Xiaomi MiMo API key",
360
- "settings.expand": "Expand settings",
361
- "settings.collapse": "Collapse settings"
362
- };
363
- function isRecord(value) {
364
- return value !== null && typeof value === "object" && !Array.isArray(value);
365
- }
366
- function decodeSettings(value) {
367
- if (!isRecord(value)) return void 0;
368
- const decoded = {};
369
- if (typeof value.enabled === "boolean") decoded.enabled = value.enabled;
370
- if (typeof value.apiKey === "string") decoded.apiKey = value.apiKey;
371
- if (typeof value.baseURL === "string") decoded.baseURL = value.baseURL;
372
- if (TTS_MODELS.includes(value.model)) decoded.model = value.model;
373
- if (typeof value.voice === "string") decoded.voice = value.voice;
374
- if (typeof value.voiceDesignPrompt === "string") decoded.voiceDesignPrompt = value.voiceDesignPrompt;
375
- if (typeof value.voiceDesignCustomPrompt === "string") decoded.voiceDesignCustomPrompt = value.voiceDesignCustomPrompt;
376
- if (value.format === "mp3" || value.format === "wav") decoded.format = value.format;
377
- if (typeof value.autoPlay === "boolean") decoded.autoPlay = value.autoPlay;
378
- if (typeof value.maxTextLength === "number") decoded.maxTextLength = value.maxTextLength;
379
- if (typeof value.requestTimeoutMs === "number") decoded.requestTimeoutMs = value.requestTimeoutMs;
380
- return decoded;
381
- }
382
- function useSettingsSnapshot(scope) {
383
- return (0, react.useSyncExternalStore)((listener) => scope.subscribe(listener), () => scope.getSnapshot(), () => scope.getSnapshot());
384
- }
385
- function formatStartupError(error) {
386
- return error instanceof Error ? error.message : String(error);
387
- }
388
- function registerSlotContribution(ctx, name, register) {
389
- ctx.effect(() => {
390
- try {
391
- ctx.slots.inject(name, () => {
392
- try {
393
- return register();
394
- } catch (error) {
395
- ctx.logger.error(`dsh-xiaomi-tts: ${name} contribution disabled: ${formatStartupError(error)}`);
396
- return () => {};
397
- }
398
- });
399
- } catch (error) {
400
- ctx.logger.error(`dsh-xiaomi-tts: ${name} injection disabled: ${formatStartupError(error)}`);
401
- }
402
- return () => {};
403
- }, `xiaomi-mimo-tts: ${name}`);
404
- }
405
- function messageText(snapshot, messageId) {
406
- for (const node of snapshot.nodes) {
407
- if (node.kind !== "assistant" || node.messageId !== messageId) continue;
408
- return (0, __deepseek_ai_dsh_client_ui_primitives.extractMarkdownPlainText)(prepareTtsText(node.blocks.filter((block) => block.kind === "text").map((block) => block.text).join("\n\n"))).trim();
409
- }
410
- return "";
411
- }
412
- function messageTime(snapshot, messageId) {
413
- for (const node of snapshot.nodes) if (node.kind === "assistant" && node.messageId === messageId) return node.time;
414
- return null;
415
- }
416
- function latestAssistantMessageId(snapshot) {
417
- for (let index = snapshot.nodes.length - 1; index >= 0; index -= 1) {
418
- const node = snapshot.nodes[index];
419
- if (node?.kind === "assistant" && node.messageId !== void 0) return node.messageId;
420
- }
421
- return null;
422
- }
423
- function assistantText(blocks) {
424
- return blocks.filter((block) => block.kind === "text" && typeof block.text === "string").map((block) => block.text).join("\n\n");
425
- }
426
- function finalLiveMessage(snapshot, turn, step) {
427
- for (let index = snapshot.nodes.length - 1; index >= 0; index -= 1) {
428
- const node = snapshot.nodes[index];
429
- if (node?.kind === "assistant" && node.messageId !== void 0 && node.turn === turn && node.step === step) return {
430
- messageId: node.messageId,
431
- turn: node.turn,
432
- step: node.step,
433
- text: assistantText(node.blocks),
434
- interrupted: node.interrupted === true
435
- };
436
- }
437
- return null;
438
- }
439
- function messageLiveIdentity(snapshot, messageId) {
440
- for (const node of snapshot.nodes) if (node.kind === "assistant" && node.messageId === messageId) return {
441
- turn: node.turn,
442
- step: node.step
443
- };
444
- return null;
445
- }
446
- function pcmDeltaFromSse(data) {
447
- if (data === "[DONE]") return null;
448
- try {
449
- const pcm = JSON.parse(data).choices?.[0]?.delta?.audio?.data;
450
- return typeof pcm === "string" && pcm.length > 0 ? pcm : null;
451
- } catch {
452
- return null;
453
- }
454
- }
286
+ //#region src/client/pcm-audio-queue.ts
455
287
  var PcmAudioQueue = class {
456
288
  context = null;
457
289
  scheduledAt = 0;
458
290
  sources = /* @__PURE__ */ new Set();
459
291
  revision = 0;
460
292
  chain = Promise.resolve();
461
- constructor(onStateChange) {
462
- this.onStateChange = onStateChange;
293
+ busy = false;
294
+ constructor(callbacks) {
295
+ this.callbacks = callbacks;
463
296
  }
464
297
  enqueue(base64) {
465
298
  const revision = this.revision;
466
- this.chain = this.chain.then(() => this.schedule(base64, revision)).catch(() => {});
467
- return this.chain;
299
+ const run = this.chain.then(() => this.schedule(base64, revision));
300
+ this.chain = run.catch(() => {});
301
+ return run;
468
302
  }
469
303
  stop() {
470
304
  this.revision += 1;
471
305
  this.scheduledAt = 0;
472
- for (const source of this.sources) source.stop();
306
+ this.chain = Promise.resolve();
307
+ for (const source of this.sources) try {
308
+ source.stop();
309
+ } catch {}
473
310
  this.sources.clear();
474
- this.onStateChange("idle");
475
- }
476
- pause() {
477
- if (this.context?.state === "running") {
478
- this.context.suspend();
479
- this.onStateChange("paused");
480
- }
481
- }
482
- resume() {
483
- if (this.context !== null && this.context.state !== "running") {
484
- this.context.resume();
485
- this.onStateChange("playing");
486
- }
311
+ this.setBusy(false);
487
312
  }
488
313
  async dispose() {
489
314
  this.stop();
@@ -512,18 +337,47 @@ var PcmAudioQueue = class {
512
337
  source.addEventListener("ended", () => {
513
338
  if (revision !== this.revision) return;
514
339
  this.sources.delete(source);
515
- if (this.sources.size === 0) this.onStateChange("idle");
340
+ if (this.sources.size === 0) this.setBusy(false);
516
341
  }, { once: true });
517
- source.start(startAt);
518
- this.onStateChange("playing");
342
+ try {
343
+ source.start(startAt);
344
+ } catch (error) {
345
+ this.sources.delete(source);
346
+ throw error;
347
+ }
348
+ this.setBusy(true);
349
+ this.callbacks.onPlaybackStart();
350
+ }
351
+ setBusy(busy) {
352
+ if (this.busy === busy) return;
353
+ this.busy = busy;
354
+ this.callbacks.onBusyChange(busy);
519
355
  }
520
356
  getContext() {
521
357
  if (this.context === null) this.context = new AudioContext();
522
358
  return this.context;
523
359
  }
524
360
  };
361
+
362
+ //#endregion
363
+ //#region src/client/live-speech-controller.ts
364
+ function pcmDeltaFromSse(data) {
365
+ if (data === "[DONE]") return null;
366
+ try {
367
+ const pcm = JSON.parse(data).choices?.[0]?.delta?.audio?.data;
368
+ return typeof pcm === "string" && pcm.length > 0 ? pcm : null;
369
+ } catch {
370
+ return null;
371
+ }
372
+ }
525
373
  var LiveSpeechController = class {
526
- audio = new PcmAudioQueue((status) => this.setStatus(status));
374
+ audio = new PcmAudioQueue({
375
+ onBusyChange: (busy) => {
376
+ this.audioBusy = busy;
377
+ this.maybeFinishPlayback();
378
+ },
379
+ onPlaybackStart: () => this.setStatus("playing")
380
+ });
527
381
  streamGeneration = 0;
528
382
  queue = this.createQueue();
529
383
  active = null;
@@ -534,6 +388,9 @@ var LiveSpeechController = class {
534
388
  messageId = null;
535
389
  status = "idle";
536
390
  sessionId = null;
391
+ requestBusy = false;
392
+ audioBusy = false;
393
+ blockedTurn = null;
537
394
  onStateChange = null;
538
395
  setStateChangeListener(listener) {
539
396
  this.onStateChange = listener;
@@ -555,6 +412,9 @@ var LiveSpeechController = class {
555
412
  turn,
556
413
  step
557
414
  };
415
+ const turnKey = `${sessionId}:${turn}`;
416
+ if (this.blockedTurn === turnKey) return;
417
+ if (this.blockedTurn !== null && this.blockedTurn !== turnKey) this.blockedTurn = null;
558
418
  const transition = classifyLiveSpeechTransition(this.active, next);
559
419
  if (transition === "new-turn" || transition === "same-step" && !text.startsWith(this.observed)) this.reset(next);
560
420
  else if (transition === "same-turn") this.advanceSegment(next);
@@ -563,6 +423,10 @@ var LiveSpeechController = class {
563
423
  }
564
424
  finish(sessionId, final) {
565
425
  const key = `${sessionId}:${final.turn}:${final.step}`;
426
+ if (this.blockedTurn === `${sessionId}:${final.turn}`) {
427
+ this.handled.add(key);
428
+ return;
429
+ }
566
430
  if (this.sessionId !== sessionId || this.active === null || this.cursorKey(this.active) !== key) return;
567
431
  if (final.interrupted) {
568
432
  this.cancelSession(sessionId);
@@ -574,28 +438,22 @@ var LiveSpeechController = class {
574
438
  this.drain(true);
575
439
  this.handled.add(key);
576
440
  }
577
- toggle(sessionId, messageId) {
578
- if (this.sessionId !== sessionId) return false;
579
- if (this.messageId !== messageId || this.status !== "playing" && this.status !== "paused") return false;
580
- if (this.status === "playing") this.audio.pause();
581
- else this.audio.resume();
441
+ stop(sessionId) {
442
+ if (this.sessionId !== sessionId || this.active === null || this.status !== "loading" && this.status !== "playing") return false;
443
+ this.blockedTurn = `${sessionId}:${this.active.turn}`;
444
+ this.resetState();
582
445
  return true;
583
446
  }
584
447
  hasHandled(sessionId, identity) {
585
- return identity !== null && this.handled.has(`${sessionId}:${identity.turn}:${identity.step}`);
448
+ if (identity === null) return false;
449
+ return this.blockedTurn === `${sessionId}:${identity.turn}` || this.handled.has(`${sessionId}:${identity.turn}:${identity.step}`);
586
450
  }
587
451
  cancelSession(sessionId) {
588
- if (this.active?.sessionId === sessionId) this.cancel();
452
+ if (this.sessionId === sessionId) this.cancel();
589
453
  }
590
454
  cancel() {
591
- this.replaceQueue();
592
- this.audio.stop();
593
- this.active = null;
594
- this.observed = "";
595
- this.consumed = 0;
596
- this.pendingText = "";
597
- this.messageId = null;
598
- this.status = "idle";
455
+ this.blockedTurn = null;
456
+ this.resetState();
599
457
  }
600
458
  async dispose() {
601
459
  this.cancel();
@@ -605,19 +463,29 @@ var LiveSpeechController = class {
605
463
  reset(next) {
606
464
  this.replaceQueue();
607
465
  this.audio.stop();
608
- this.beginSegment(next);
609
- this.status = "idle";
466
+ this.beginSegment(next, false);
467
+ this.setStatus("idle");
610
468
  }
611
469
  advanceSegment(next) {
612
470
  this.drain(true);
613
- this.beginSegment(next);
471
+ this.beginSegment(next, true);
614
472
  }
615
- beginSegment(next) {
473
+ beginSegment(next, preserveMessageId) {
616
474
  this.active = next;
617
475
  this.observed = "";
618
476
  this.consumed = 0;
619
477
  this.pendingText = "";
478
+ if (!preserveMessageId) this.messageId = null;
479
+ }
480
+ resetState() {
481
+ this.replaceQueue();
482
+ this.audio.stop();
483
+ this.active = null;
484
+ this.observed = "";
485
+ this.consumed = 0;
486
+ this.pendingText = "";
620
487
  this.messageId = null;
488
+ this.setStatus("idle");
621
489
  }
622
490
  cursorKey(cursor) {
623
491
  return `${cursor.sessionId}:${cursor.turn}:${cursor.step}`;
@@ -638,10 +506,21 @@ var LiveSpeechController = class {
638
506
  }
639
507
  createQueue() {
640
508
  const generation = this.streamGeneration;
641
- return new AbortableSentenceQueue((sentence, signal) => this.stream(sentence, signal, generation));
509
+ return new AbortableSentenceQueue((sentence, signal) => this.stream(sentence, signal, generation), {
510
+ onBusyChange: (busy) => {
511
+ if (generation !== this.streamGeneration) return;
512
+ this.requestBusy = busy;
513
+ if (busy && this.status === "idle") this.setStatus("loading");
514
+ this.maybeFinishPlayback();
515
+ },
516
+ onError: (error) => {
517
+ if (generation === this.streamGeneration) this.handleStreamError(error);
518
+ }
519
+ });
642
520
  }
643
521
  replaceQueue() {
644
522
  this.streamGeneration += 1;
523
+ this.requestBusy = false;
645
524
  this.queue.cancel();
646
525
  this.queue = this.createQueue();
647
526
  }
@@ -650,7 +529,6 @@ var LiveSpeechController = class {
650
529
  }
651
530
  async stream(sentence, signal, generation) {
652
531
  if (!this.isCurrentStream(generation, signal)) return;
653
- this.setStatus("loading");
654
532
  try {
655
533
  const response = await fetch(TTS_STREAM_ROUTE, {
656
534
  method: "POST",
@@ -684,12 +562,20 @@ var LiveSpeechController = class {
684
562
  reader.releaseLock();
685
563
  }
686
564
  } catch (error) {
687
- if (!this.isCurrentStream(generation, signal)) return;
688
- this.setStatus("error");
689
- throw error;
565
+ if (this.isCurrentStream(generation, signal)) throw error;
690
566
  }
691
567
  }
568
+ handleStreamError(error) {
569
+ if (this.active !== null) this.blockedTurn = `${this.active.sessionId}:${this.active.turn}`;
570
+ this.setStatus("error");
571
+ this.replaceQueue();
572
+ this.audio.stop();
573
+ }
574
+ maybeFinishPlayback() {
575
+ if (!this.requestBusy && !this.audioBusy && (this.status === "loading" || this.status === "playing")) this.setStatus("idle");
576
+ }
692
577
  setStatus(status) {
578
+ if (this.status === status) return;
693
579
  this.status = status;
694
580
  this.reportStatus();
695
581
  }
@@ -697,11 +583,15 @@ var LiveSpeechController = class {
697
583
  if (this.sessionId !== null && this.messageId !== null) this.onStateChange?.(this.sessionId, this.messageId, this.status);
698
584
  }
699
585
  };
586
+
587
+ //#endregion
588
+ //#region src/client/playback-controller.ts
700
589
  var PlaybackController = class {
701
590
  autoPlayArmedAt = Date.now();
702
591
  view = {
703
592
  sessionId: null,
704
593
  messageId: null,
594
+ source: null,
705
595
  status: "idle",
706
596
  error: null
707
597
  };
@@ -727,23 +617,13 @@ var PlaybackController = class {
727
617
  this.completedSessions.clear();
728
618
  this.completedMessages.clear();
729
619
  this.activeSessionId = sessionId;
730
- this.publish({
731
- sessionId: null,
732
- messageId: null,
733
- status: "idle",
734
- error: null
735
- });
620
+ this.publish(this.emptyView());
736
621
  }
737
622
  cancelPlayback(sessionId) {
738
623
  if (this.activeSessionId !== sessionId) return;
739
624
  this.generation += 1;
740
625
  this.stopCurrent();
741
- this.publish({
742
- sessionId: null,
743
- messageId: null,
744
- status: "idle",
745
- error: null
746
- });
626
+ this.publish(this.emptyView());
747
627
  }
748
628
  deactivateSession(sessionId) {
749
629
  if (this.activeSessionId !== sessionId) return;
@@ -753,12 +633,7 @@ var PlaybackController = class {
753
633
  this.completedSessions.clear();
754
634
  this.completedMessages.clear();
755
635
  this.activeSessionId = null;
756
- this.publish({
757
- sessionId: null,
758
- messageId: null,
759
- status: "idle",
760
- error: null
761
- });
636
+ this.publish(this.emptyView());
762
637
  }
763
638
  observeSession(sessionId, running, latestMessageId) {
764
639
  if (this.activeSessionId !== sessionId) return;
@@ -783,16 +658,21 @@ var PlaybackController = class {
783
658
  }
784
659
  updateLivePlayback(sessionId, messageId, status) {
785
660
  if (this.activeSessionId !== sessionId) return;
786
- if (this.view.messageId === messageId || status !== "idle") this.publish({
661
+ if (status === "idle") {
662
+ if (this.view.source === "live" && this.view.messageId === messageId) this.publish(this.emptyView());
663
+ return;
664
+ }
665
+ if (this.view.source !== "complete") this.publish({
787
666
  sessionId,
788
667
  messageId,
668
+ source: "live",
789
669
  status,
790
670
  error: status === "error" ? "play-failed" : null
791
671
  });
792
672
  }
793
673
  async toggle(sessionId, messageId, text, automatic) {
794
674
  if (this.activeSessionId !== sessionId) return;
795
- if (this.view.sessionId === sessionId && this.view.messageId === messageId && this.current !== null) {
675
+ if (this.view.source === "complete" && this.view.sessionId === sessionId && this.view.messageId === messageId && this.current !== null) {
796
676
  const audio = this.current.audio;
797
677
  const generation$1 = this.generation;
798
678
  if (audio.paused) try {
@@ -801,6 +681,7 @@ var PlaybackController = class {
801
681
  this.publish({
802
682
  sessionId,
803
683
  messageId,
684
+ source: "complete",
804
685
  status: "playing",
805
686
  error: null
806
687
  });
@@ -809,6 +690,7 @@ var PlaybackController = class {
809
690
  this.publish({
810
691
  sessionId,
811
692
  messageId,
693
+ source: "complete",
812
694
  status: "paused",
813
695
  error: automatic ? "autoplay-blocked" : "play-failed"
814
696
  });
@@ -818,6 +700,7 @@ var PlaybackController = class {
818
700
  this.publish({
819
701
  sessionId,
820
702
  messageId,
703
+ source: "complete",
821
704
  status: "paused",
822
705
  error: null
823
706
  });
@@ -828,6 +711,7 @@ var PlaybackController = class {
828
711
  this.publish({
829
712
  sessionId,
830
713
  messageId,
714
+ source: "complete",
831
715
  status: "error",
832
716
  error: "no-text"
833
717
  });
@@ -840,6 +724,7 @@ var PlaybackController = class {
840
724
  this.publish({
841
725
  sessionId,
842
726
  messageId,
727
+ source: "complete",
843
728
  status: "loading",
844
729
  error: null
845
730
  });
@@ -863,33 +748,37 @@ var PlaybackController = class {
863
748
  if (generation !== this.generation || this.activeSessionId !== sessionId) return;
864
749
  const url = URL.createObjectURL(blob);
865
750
  const audio = new Audio(url);
866
- this.current = {
751
+ const current = {
867
752
  url,
868
- audio
753
+ audio,
754
+ onEnded: () => {
755
+ if (this.activeSessionId !== sessionId || this.current?.audio !== audio) return;
756
+ this.releaseCurrentAudio(audio);
757
+ this.publish(this.emptyView());
758
+ },
759
+ onError: () => {
760
+ if (this.activeSessionId !== sessionId || this.current?.audio !== audio) return;
761
+ this.releaseCurrentAudio(audio);
762
+ this.publish({
763
+ sessionId,
764
+ messageId,
765
+ source: "complete",
766
+ status: "error",
767
+ error: "play-failed"
768
+ });
769
+ }
869
770
  };
771
+ this.current = current;
870
772
  this.request = null;
871
- audio.addEventListener("ended", () => {
872
- if (this.activeSessionId === sessionId && this.current?.audio === audio) this.publish({
873
- sessionId,
874
- messageId,
875
- status: "idle",
876
- error: null
877
- });
878
- });
879
- audio.addEventListener("error", () => {
880
- if (this.activeSessionId === sessionId && this.current?.audio === audio) this.publish({
881
- sessionId,
882
- messageId,
883
- status: "error",
884
- error: "play-failed"
885
- });
886
- });
773
+ audio.addEventListener("ended", current.onEnded);
774
+ audio.addEventListener("error", current.onError);
887
775
  try {
888
776
  await audio.play();
889
777
  if (generation !== this.generation || this.activeSessionId !== sessionId || this.current?.audio !== audio) return;
890
778
  this.publish({
891
779
  sessionId,
892
780
  messageId,
781
+ source: "complete",
893
782
  status: "playing",
894
783
  error: null
895
784
  });
@@ -898,6 +787,7 @@ var PlaybackController = class {
898
787
  this.publish({
899
788
  sessionId,
900
789
  messageId,
790
+ source: "complete",
901
791
  status: "paused",
902
792
  error: automatic ? "autoplay-blocked" : "play-failed"
903
793
  });
@@ -908,6 +798,7 @@ var PlaybackController = class {
908
798
  this.publish({
909
799
  sessionId,
910
800
  messageId,
801
+ source: "complete",
911
802
  status: "error",
912
803
  error: error instanceof Error ? error.message : String(error)
913
804
  });
@@ -922,21 +813,108 @@ var PlaybackController = class {
922
813
  this.activeSessionId = null;
923
814
  this.listeners.clear();
924
815
  }
925
- stopCurrent() {
926
- this.request?.abort();
927
- this.request = null;
928
- if (this.current !== null) {
929
- this.current.audio.pause();
930
- this.current.audio.removeAttribute("src");
931
- URL.revokeObjectURL(this.current.url);
932
- this.current = null;
933
- }
816
+ stopCurrent() {
817
+ this.request?.abort();
818
+ this.request = null;
819
+ if (this.current !== null) this.releaseCurrentAudio(this.current.audio);
820
+ }
821
+ releaseCurrentAudio(audio) {
822
+ if (this.current?.audio !== audio) return;
823
+ const current = this.current;
824
+ this.current = null;
825
+ audio.removeEventListener("ended", current.onEnded);
826
+ audio.removeEventListener("error", current.onError);
827
+ audio.pause();
828
+ audio.removeAttribute("src");
829
+ audio.load();
830
+ URL.revokeObjectURL(current.url);
831
+ }
832
+ emptyView() {
833
+ return {
834
+ sessionId: null,
835
+ messageId: null,
836
+ source: null,
837
+ status: "idle",
838
+ error: null
839
+ };
840
+ }
841
+ publish(view) {
842
+ if (this.view.sessionId === view.sessionId && this.view.messageId === view.messageId && this.view.source === view.source && this.view.status === view.status && this.view.error === view.error) return;
843
+ this.view = view;
844
+ for (const listener of this.listeners) listener();
845
+ }
846
+ };
847
+
848
+ //#endregion
849
+ //#region src/client/settings-scope.ts
850
+ function isRecord(value) {
851
+ return value !== null && typeof value === "object" && !Array.isArray(value);
852
+ }
853
+ function decodeSettings(value) {
854
+ if (!isRecord(value)) return void 0;
855
+ const decoded = {};
856
+ if (typeof value.enabled === "boolean") decoded.enabled = value.enabled;
857
+ if (typeof value.apiKey === "string") decoded.apiKey = value.apiKey;
858
+ if (typeof value.baseURL === "string") decoded.baseURL = value.baseURL;
859
+ if (TTS_MODELS.includes(value.model)) decoded.model = value.model;
860
+ if (typeof value.voice === "string") decoded.voice = value.voice;
861
+ if (typeof value.voiceDesignPrompt === "string") decoded.voiceDesignPrompt = value.voiceDesignPrompt;
862
+ if (typeof value.voiceDesignCustomPrompt === "string") decoded.voiceDesignCustomPrompt = value.voiceDesignCustomPrompt;
863
+ if (value.format === "mp3" || value.format === "wav") decoded.format = value.format;
864
+ if (typeof value.autoPlay === "boolean") decoded.autoPlay = value.autoPlay;
865
+ if (typeof value.maxTextLength === "number") decoded.maxTextLength = value.maxTextLength;
866
+ if (typeof value.requestTimeoutMs === "number") decoded.requestTimeoutMs = value.requestTimeoutMs;
867
+ return decoded;
868
+ }
869
+ function useSettingsSnapshot(scope) {
870
+ const subscribe = (0, react.useCallback)((listener) => scope.subscribe(listener), [scope]);
871
+ const getSnapshot = (0, react.useCallback)(() => scope.getSnapshot(), [scope]);
872
+ return (0, react.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
873
+ }
874
+
875
+ //#endregion
876
+ //#region src/client/conversation.tsx
877
+ function messageText(snapshot, messageId) {
878
+ for (const node of snapshot.nodes) {
879
+ if (node.kind !== "assistant" || node.messageId !== messageId) continue;
880
+ return (0, __deepseek_ai_dsh_client_ui_primitives.extractMarkdownPlainText)(prepareTtsText(node.blocks.filter((block) => block.kind === "text").map((block) => block.text).join("\n\n"))).trim();
881
+ }
882
+ return "";
883
+ }
884
+ function messageTime(snapshot, messageId) {
885
+ for (const node of snapshot.nodes) if (node.kind === "assistant" && node.messageId === messageId) return node.time;
886
+ return null;
887
+ }
888
+ function latestAssistantMessageId(snapshot) {
889
+ for (let index = snapshot.nodes.length - 1; index >= 0; index -= 1) {
890
+ const node = snapshot.nodes[index];
891
+ if (node?.kind === "assistant" && node.messageId !== void 0) return node.messageId;
934
892
  }
935
- publish(view) {
936
- this.view = view;
937
- for (const listener of this.listeners) listener();
893
+ return null;
894
+ }
895
+ function assistantText(blocks) {
896
+ return blocks.filter((block) => block.kind === "text" && typeof block.text === "string").map((block) => block.text).join("\n\n");
897
+ }
898
+ function finalLiveMessage(snapshot, turn, step) {
899
+ for (let index = snapshot.nodes.length - 1; index >= 0; index -= 1) {
900
+ const node = snapshot.nodes[index];
901
+ if (node?.kind === "assistant" && node.messageId !== void 0 && node.turn === turn && node.step === step) return {
902
+ messageId: node.messageId,
903
+ turn: node.turn,
904
+ step: node.step,
905
+ text: assistantText(node.blocks),
906
+ interrupted: node.interrupted === true
907
+ };
938
908
  }
939
- };
909
+ return null;
910
+ }
911
+ function messageLiveIdentity(snapshot, messageId) {
912
+ for (const node of snapshot.nodes) if (node.kind === "assistant" && node.messageId === messageId) return {
913
+ turn: node.turn,
914
+ step: node.step
915
+ };
916
+ return null;
917
+ }
940
918
  /** Own the active-session boundary and feed its partial assistant output into realtime speech. */
941
919
  function SessionPlaybackObserver({ sessionId, session, playback, live, settings }) {
942
920
  const resolvedSettings = resolveTtsSettings(useSettingsSnapshot(settings).value);
@@ -1046,7 +1024,9 @@ function ReadAloudAction({ sessionId, messageId, useSession, playback, live, set
1046
1024
  if (settingsSnapshot.value?.enabled !== true || text.length === 0) return null;
1047
1025
  const mine = view.sessionId === sessionId && view.messageId === messageId;
1048
1026
  const status = mine ? view.status : "idle";
1049
- const label = status === "loading" ? t("action.loading") : status === "playing" ? t("action.pause") : status === "paused" ? t("action.resume") : status === "error" ? t("action.retry") : t("action.play");
1027
+ const source = mine ? view.source : null;
1028
+ const liveActive = source === "live" && (status === "loading" || status === "playing");
1029
+ const label = status === "loading" ? liveActive ? t("action.cancel") : t("action.loading") : status === "playing" ? liveActive ? t("action.stop") : t("action.pause") : status === "paused" ? t("action.resume") : status === "error" ? t("action.retry") : t("action.play");
1050
1030
  const error = mine ? view.error : null;
1051
1031
  const errorText = error === null ? null : error === "no-text" ? t("error.noText") : error === "autoplay-blocked" || error === "play-failed" ? t("error.play") : t("error.request");
1052
1032
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__deepseek_ai_dsh_client_ui_primitives.Tooltip, {
@@ -1056,13 +1036,16 @@ function ReadAloudAction({ sessionId, messageId, useSession, playback, live, set
1056
1036
  type: "button",
1057
1037
  className: "xmimo-tts-action",
1058
1038
  "aria-label": label,
1059
- "aria-pressed": status === "playing",
1060
- disabled: status === "loading",
1039
+ "aria-pressed": status === "playing" || liveActive,
1040
+ disabled: status === "loading" && !liveActive,
1061
1041
  onClick: () => {
1062
- if (!live.toggle(sessionId, messageId)) {
1063
- live.cancel();
1064
- playback.toggle(sessionId, messageId, text, false);
1042
+ if (mine && source === "live" && (status === "loading" || status === "playing")) {
1043
+ live.stop(sessionId);
1044
+ playback.cancelPlayback(sessionId);
1045
+ return;
1065
1046
  }
1047
+ live.cancelSession(sessionId);
1048
+ playback.toggle(sessionId, messageId, text, false);
1066
1049
  },
1067
1050
  children: status === "loading" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__deepseek_ai_dsh_client_ui_primitives.IconLoadingOutline16, { className: "xmimo-tts-spin" }) : status === "playing" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__deepseek_ai_dsh_client_ui_primitives.IconPauseOutline16, {}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__deepseek_ai_dsh_client_ui_primitives.IconPlayOutline16, {})
1068
1051
  })
@@ -1072,15 +1055,121 @@ function ReadAloudAction({ sessionId, messageId, useSession, playback, live, set
1072
1055
  children: errorText
1073
1056
  })] });
1074
1057
  }
1075
- const EDITABLE_SETTING_FIELDS = [
1076
- "enabled",
1077
- "autoPlay",
1078
- "model",
1079
- "voice",
1080
- "voiceDesignPrompt",
1081
- "voiceDesignCustomPrompt",
1082
- "format"
1083
- ];
1058
+
1059
+ //#endregion
1060
+ //#region src/client/localization.ts
1061
+ const NS = "xiaomi-mimo-tts";
1062
+ const zh = {
1063
+ "action.play": "朗读回复",
1064
+ "action.pause": "暂停朗读",
1065
+ "action.resume": "继续朗读",
1066
+ "action.loading": "正在生成语音",
1067
+ "action.cancel": "取消语音生成",
1068
+ "action.stop": "停止朗读",
1069
+ "action.retry": "重新生成语音",
1070
+ "error.noText": "这条回复没有可朗读的正文。",
1071
+ "error.request": "语音生成失败。",
1072
+ "error.play": "浏览器阻止了自动播放,请点击朗读按钮。",
1073
+ "settings.title": "语音朗读 (Xiaomi MiMo)",
1074
+ "settings.description": "在助手回复操作栏中使用 Xiaomi MiMo TTS 生成并播放语音。",
1075
+ "settings.enabled": "显示朗读按钮",
1076
+ "settings.enabledHint": "关闭后不会在助手回复操作栏显示朗读按钮,也不会自动播报。",
1077
+ "settings.apiKey": "API Key",
1078
+ "settings.apiKeyHint": "密钥保存在 DSH 设置文件中,传到浏览器前会被脱敏。",
1079
+ "settings.apiKeyStatus": "只有输入新值并保存时才会替换现有密钥。",
1080
+ "settings.apiKeyConfigured": "已配置",
1081
+ "settings.getApiKey": "获取 API Key",
1082
+ "settings.autoPlay": "开启自动播报",
1083
+ "settings.autoPlayHint": "开启时会同步显示朗读按钮;浏览器也可能拒绝自动播放。",
1084
+ "settings.model": "TTS 模型",
1085
+ "settings.presetModel": "预置音色模型 (mimo-v2.5-tts)",
1086
+ "settings.voiceDesignModel": "自定义音色模型 (mimo-v2.5-tts-voicedesign)",
1087
+ "settings.modelAutoPlayHintPreset": "预置音色模型支持实时流式播放。",
1088
+ "settings.modelAutoPlayHintVoiceDesign": "自定义音色仅支持在回复完成后自动播放。",
1089
+ "settings.voice": "内置音色",
1090
+ "settings.voiceDesignPrompt": "自定义音色描述",
1091
+ "settings.customVoiceOption": "自定义",
1092
+ "settings.customVoiceSummary": "手动编写音色描述",
1093
+ "settings.voiceDesignPromptHint": "按“年龄段 + 性别、声音质感、语速节奏、情绪底色”描述声音本身;不写场景或动作。",
1094
+ "settings.format": "音频格式",
1095
+ "settings.save": "保存",
1096
+ "settings.saving": "保存中…",
1097
+ "settings.saved": "已保存",
1098
+ "settings.unsaved": "未保存",
1099
+ "settings.overridden": "已覆盖",
1100
+ "settings.reset": "恢复默认",
1101
+ "settings.discard": "放弃修改",
1102
+ "settings.failed": "保存失败,请重试。",
1103
+ "settings.star": "点亮Star⭐",
1104
+ "settings.uninstall": "卸载此插件",
1105
+ "settings.uninstalling": "卸载中…",
1106
+ "settings.uninstallQuestion": "确认卸载?",
1107
+ "settings.uninstallConfirm": "确认",
1108
+ "settings.uninstallCancel": "取消",
1109
+ "settings.uninstalled": "已卸载,重启 DSH Web 后生效。",
1110
+ "settings.uninstallFailed": "卸载失败,请重试或使用 DSH 命令行卸载。",
1111
+ "settings.readOnly": "当前 DSH 设置为只读。",
1112
+ "settings.secretPlaceholder": "输入新的 Xiaomi MiMo API Key",
1113
+ "settings.expand": "展开设置",
1114
+ "settings.collapse": "收起设置"
1115
+ };
1116
+ const en = {
1117
+ "action.play": "Read aloud",
1118
+ "action.pause": "Pause speech",
1119
+ "action.resume": "Resume speech",
1120
+ "action.loading": "Generating speech",
1121
+ "action.cancel": "Cancel speech generation",
1122
+ "action.stop": "Stop speech",
1123
+ "action.retry": "Generate speech again",
1124
+ "error.noText": "This response has no readable body text.",
1125
+ "error.request": "Speech generation failed.",
1126
+ "error.play": "The browser blocked autoplay. Click Read aloud to play it.",
1127
+ "settings.title": "Text To Speech (Xiaomi MiMo)",
1128
+ "settings.description": "Generate and play Xiaomi MiMo TTS audio from assistant message actions.",
1129
+ "settings.enabled": "Show read-aloud button",
1130
+ "settings.enabledHint": "When disabled, the read-aloud button and automatic speech are both turned off.",
1131
+ "settings.apiKey": "API Key",
1132
+ "settings.apiKeyHint": "Stored in DSH settings and redacted before settings are sent to the browser.",
1133
+ "settings.apiKeyStatus": "An existing key changes only when you save a new value.",
1134
+ "settings.apiKeyConfigured": "Configured",
1135
+ "settings.getApiKey": "Get API Key",
1136
+ "settings.autoPlay": "Enable automatic read-aloud",
1137
+ "settings.autoPlayHint": "Enabling it also shows the read-aloud button; the browser may reject autoplay.",
1138
+ "settings.model": "TTS model",
1139
+ "settings.presetModel": "Preset voices (mimo-v2.5-tts)",
1140
+ "settings.voiceDesignModel": "Custom voice design (mimo-v2.5-tts-voicedesign)",
1141
+ "settings.modelAutoPlayHintPreset": "Preset voices support realtime streaming playback.",
1142
+ "settings.modelAutoPlayHintVoiceDesign": "Custom voice design supports automatic playback only after the reply is complete.",
1143
+ "settings.voice": "Built-in voice",
1144
+ "settings.voiceDesignPrompt": "Custom voice description",
1145
+ "settings.customVoiceOption": "Custom",
1146
+ "settings.customVoiceSummary": "Write a custom voice description",
1147
+ "settings.voiceDesignPromptHint": "Describe the voice itself with age/gender, texture, pace, and emotional baseline; avoid scenes or actions.",
1148
+ "settings.format": "Audio format",
1149
+ "settings.save": "Save",
1150
+ "settings.saving": "Saving…",
1151
+ "settings.saved": "Saved",
1152
+ "settings.unsaved": "Unsaved",
1153
+ "settings.overridden": "Overridden",
1154
+ "settings.reset": "Restore default",
1155
+ "settings.discard": "Discard changes",
1156
+ "settings.failed": "Save failed. Try again.",
1157
+ "settings.star": "Feedback or Star us ⭐",
1158
+ "settings.uninstall": "Uninstall this plugin",
1159
+ "settings.uninstalling": "Uninstalling…",
1160
+ "settings.uninstallQuestion": "Confirm uninstall?",
1161
+ "settings.uninstallConfirm": "Confirm",
1162
+ "settings.uninstallCancel": "Cancel",
1163
+ "settings.uninstalled": "Uninstalled. Restart DSH Web to apply the change.",
1164
+ "settings.uninstallFailed": "Uninstall failed. Try again or remove the plugin with the DSH CLI.",
1165
+ "settings.readOnly": "DSH settings are read-only.",
1166
+ "settings.secretPlaceholder": "Enter a new Xiaomi MiMo API key",
1167
+ "settings.expand": "Expand settings",
1168
+ "settings.collapse": "Collapse settings"
1169
+ };
1170
+
1171
+ //#endregion
1172
+ //#region src/client/voice-design-picker.tsx
1084
1173
  const CUSTOM_VOICE_DESIGN_OPTION = "__custom__";
1085
1174
  function isPresetVoiceDesignPrompt(value) {
1086
1175
  return TTS_VOICE_DESIGN_PRESETS.some((item) => item.prompt === value);
@@ -1252,6 +1341,18 @@ function VoiceDesignPresetPicker({ value, disabled, label, customLabel, customSu
1252
1341
  }) : null]
1253
1342
  });
1254
1343
  }
1344
+
1345
+ //#endregion
1346
+ //#region src/client/settings-card.tsx
1347
+ const EDITABLE_SETTING_FIELDS = [
1348
+ "enabled",
1349
+ "autoPlay",
1350
+ "model",
1351
+ "voice",
1352
+ "voiceDesignPrompt",
1353
+ "voiceDesignCustomPrompt",
1354
+ "format"
1355
+ ];
1255
1356
  function layerSettings(value) {
1256
1357
  return isRecord(value) ? value : void 0;
1257
1358
  }
@@ -1297,6 +1398,7 @@ function SettingsCard({ scope, t }) {
1297
1398
  const [format, setFormat] = (0, react.useState)(initial.format);
1298
1399
  const [changes, setChanges] = (0, react.useState)({});
1299
1400
  const [state, setState] = (0, react.useState)("idle");
1401
+ const [uninstallState, setUninstallState] = (0, react.useState)("idle");
1300
1402
  const [open, setOpen] = (0, react.useState)(false);
1301
1403
  const accepted = resolveTtsSettings(value);
1302
1404
  const base = resolveTtsSettings(layerSettings(snapshot.base));
@@ -1392,6 +1494,21 @@ function SettingsCard({ scope, t }) {
1392
1494
  setState("failed");
1393
1495
  }
1394
1496
  };
1497
+ const uninstall = async () => {
1498
+ setUninstallState("uninstalling");
1499
+ try {
1500
+ const response = await fetch(TTS_UNINSTALL_ROUTE, {
1501
+ method: "POST",
1502
+ headers: { "content-type": "application/json" },
1503
+ body: "{}"
1504
+ });
1505
+ const result = await response.json();
1506
+ if (!response.ok || result.ok !== true) throw new Error("plugin-uninstall-failed");
1507
+ setUninstallState("uninstalled");
1508
+ } catch {
1509
+ setUninstallState("failed");
1510
+ }
1511
+ };
1395
1512
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", {
1396
1513
  className: open ? "xmimo-tts-card xmimo-tts-card-open" : "xmimo-tts-card",
1397
1514
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
@@ -1470,64 +1587,84 @@ function SettingsCard({ scope, t }) {
1470
1587
  className: "xmimo-tts-switch-row xmimo-tts-wide",
1471
1588
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
1472
1589
  className: "xmimo-tts-checkbox-row",
1473
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1474
- type: "checkbox",
1475
- checked: enabled,
1476
- disabled: !snapshot.writable,
1477
- onChange: (event) => {
1478
- const next = event.target.checked;
1479
- setEnabled(next);
1480
- if (!next) {
1481
- setAutoPlay(false);
1482
- setChanges((current) => ({
1483
- ...current,
1484
- enabled: { kind: "set" },
1485
- autoPlay: { kind: "set" }
1486
- }));
1487
- } else markChange("enabled");
1488
- setState("idle");
1489
- }
1490
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SettingFieldHeading, {
1491
- label: t("settings.enabled"),
1492
- overriddenLabel: t("settings.overridden"),
1493
- resetLabel: t("settings.reset"),
1494
- overridden: false,
1495
- resettable: false,
1496
- disabled: !snapshot.writable,
1497
- onReset: () => {
1498
- resetField("enabled");
1499
- }
1500
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: t("settings.enabledHint") })] })]
1590
+ children: [
1591
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1592
+ className: "xmimo-tts-switch-copy",
1593
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SettingFieldHeading, {
1594
+ label: t("settings.enabled"),
1595
+ overriddenLabel: t("settings.overridden"),
1596
+ resetLabel: t("settings.reset"),
1597
+ overridden: false,
1598
+ resettable: false,
1599
+ disabled: !snapshot.writable,
1600
+ onReset: () => {
1601
+ resetField("enabled");
1602
+ }
1603
+ })
1604
+ }),
1605
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1606
+ type: "checkbox",
1607
+ checked: enabled,
1608
+ disabled: !snapshot.writable,
1609
+ onChange: (event) => {
1610
+ const next = event.target.checked;
1611
+ setEnabled(next);
1612
+ if (!next) {
1613
+ setAutoPlay(false);
1614
+ setChanges((current) => ({
1615
+ ...current,
1616
+ enabled: { kind: "set" },
1617
+ autoPlay: { kind: "set" }
1618
+ }));
1619
+ } else markChange("enabled");
1620
+ setState("idle");
1621
+ }
1622
+ }),
1623
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1624
+ className: "xmimo-tts-switch-control",
1625
+ "aria-hidden": "true"
1626
+ })
1627
+ ]
1501
1628
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
1502
1629
  className: "xmimo-tts-checkbox-row",
1503
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1504
- type: "checkbox",
1505
- checked: enabled && autoPlay,
1506
- disabled: !snapshot.writable,
1507
- onChange: (event) => {
1508
- const next = event.target.checked;
1509
- setAutoPlay(next);
1510
- if (next) {
1511
- setEnabled(true);
1512
- setChanges((current) => ({
1513
- ...current,
1514
- autoPlay: { kind: "set" },
1515
- enabled: { kind: "set" }
1516
- }));
1517
- } else markChange("autoPlay");
1518
- setState("idle");
1519
- }
1520
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SettingFieldHeading, {
1521
- label: t("settings.autoPlay"),
1522
- overriddenLabel: t("settings.overridden"),
1523
- resetLabel: t("settings.reset"),
1524
- overridden: false,
1525
- resettable: false,
1526
- disabled: !snapshot.writable,
1527
- onReset: () => {
1528
- resetField("autoPlay");
1529
- }
1530
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: t("settings.autoPlayHint") })] })]
1630
+ children: [
1631
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1632
+ className: "xmimo-tts-switch-copy",
1633
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SettingFieldHeading, {
1634
+ label: t("settings.autoPlay"),
1635
+ overriddenLabel: t("settings.overridden"),
1636
+ resetLabel: t("settings.reset"),
1637
+ overridden: false,
1638
+ resettable: false,
1639
+ disabled: !snapshot.writable,
1640
+ onReset: () => {
1641
+ resetField("autoPlay");
1642
+ }
1643
+ })
1644
+ }),
1645
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1646
+ type: "checkbox",
1647
+ checked: enabled && autoPlay,
1648
+ disabled: !snapshot.writable,
1649
+ onChange: (event) => {
1650
+ const next = event.target.checked;
1651
+ setAutoPlay(next);
1652
+ if (next) {
1653
+ setEnabled(true);
1654
+ setChanges((current) => ({
1655
+ ...current,
1656
+ autoPlay: { kind: "set" },
1657
+ enabled: { kind: "set" }
1658
+ }));
1659
+ } else markChange("autoPlay");
1660
+ setState("idle");
1661
+ }
1662
+ }),
1663
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1664
+ className: "xmimo-tts-switch-control",
1665
+ "aria-hidden": "true"
1666
+ })
1667
+ ]
1531
1668
  })]
1532
1669
  }),
1533
1670
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
@@ -1607,9 +1744,9 @@ function SettingsCard({ scope, t }) {
1607
1744
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: t("settings.voiceDesignPromptHint") })
1608
1745
  ]
1609
1746
  }) : null,
1610
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1611
- className: model === "mimo-v2.5-tts" ? "xmimo-tts-select-column xmimo-tts-wide" : "xmimo-tts-select-column",
1612
- children: [model === "mimo-v2.5-tts" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SettingFieldHeading, {
1747
+ model === "mimo-v2.5-tts" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1748
+ className: "xmimo-tts-select-column xmimo-tts-wide",
1749
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SettingFieldHeading, {
1613
1750
  label: t("settings.voice"),
1614
1751
  overriddenLabel: t("settings.overridden"),
1615
1752
  resetLabel: t("settings.reset"),
@@ -1630,7 +1767,7 @@ function SettingsCard({ scope, t }) {
1630
1767
  value: item,
1631
1768
  children: item
1632
1769
  }, item))
1633
- })] }) : null, /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SettingFieldHeading, {
1770
+ })] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SettingFieldHeading, {
1634
1771
  label: t("settings.format"),
1635
1772
  overriddenLabel: t("settings.overridden"),
1636
1773
  resetLabel: t("settings.reset"),
@@ -1655,12 +1792,55 @@ function SettingsCard({ scope, t }) {
1655
1792
  children: "WAV"
1656
1793
  })]
1657
1794
  })] })]
1658
- })
1795
+ }) : null
1659
1796
  ]
1660
1797
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1661
1798
  className: "xmimo-tts-card-actions",
1662
1799
  children: [
1800
+ uninstallState === "confirming" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
1801
+ className: "xmimo-tts-uninstall-confirmation",
1802
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("settings.uninstallQuestion") }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
1803
+ className: "xmimo-tts-uninstall-choice",
1804
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1805
+ type: "button",
1806
+ onClick: () => {
1807
+ uninstall();
1808
+ },
1809
+ children: t("settings.uninstallConfirm")
1810
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1811
+ type: "button",
1812
+ onClick: () => {
1813
+ setUninstallState("idle");
1814
+ },
1815
+ children: t("settings.uninstallCancel")
1816
+ })]
1817
+ })]
1818
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1819
+ type: "button",
1820
+ className: "xmimo-tts-uninstall",
1821
+ disabled: uninstallState === "uninstalling" || uninstallState === "uninstalled",
1822
+ onClick: () => {
1823
+ setUninstallState("confirming");
1824
+ },
1825
+ children: uninstallState === "uninstalling" ? t("settings.uninstalling") : t("settings.uninstall")
1826
+ }),
1827
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
1828
+ className: "xmimo-tts-star",
1829
+ href: "https://github.com/ppy-web/dsh-plugin-xiaomi-mimo-tts",
1830
+ target: "_blank",
1831
+ rel: "noopener noreferrer",
1832
+ children: t("settings.star")
1833
+ }),
1663
1834
  !snapshot.writable ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("settings.readOnly") }) : null,
1835
+ uninstallState === "uninstalled" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1836
+ role: "status",
1837
+ children: t("settings.uninstalled")
1838
+ }) : null,
1839
+ uninstallState === "failed" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1840
+ className: "xmimo-tts-failed",
1841
+ role: "status",
1842
+ children: t("settings.uninstallFailed")
1843
+ }) : null,
1664
1844
  state === "saved" && !dirty ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1665
1845
  role: "status",
1666
1846
  children: t("settings.saved")
@@ -1690,6 +1870,49 @@ function SettingsCard({ scope, t }) {
1690
1870
  }) : null]
1691
1871
  });
1692
1872
  }
1873
+
1874
+ //#endregion
1875
+ //#region src/client/styles.ts
1876
+ const CLIENT_STYLES = `
1877
+ .xmimo-tts-action{width:28px;height:28px;color:var(--dsw-alias-label-tertiary);cursor:pointer;background:transparent;border:none;border-radius:28px;justify-content:center;align-items:center;padding:6px;display:inline-flex}.xmimo-tts-action:hover{background:var(--dsw-alias-interactive-bg-hover,#f3f4f6);color:var(--dsw-alias-label-secondary,#5f6875)}.xmimo-tts-action[aria-pressed=true]{background:var(--dsw-alias-interactive-bg-hover,#f3f4f6);color:var(--dsw-alias-label-secondary,#5f6875)}.xmimo-tts-action:disabled{cursor:default;opacity:.45}.xmimo-tts-spin{animation:xmimo-spin 1s linear infinite}@keyframes xmimo-spin{to{transform:rotate(360deg)}}
1878
+ .xmimo-tts-inline-error{max-width:220px;color:var(--dsw-alias-state-error-primary,#dc2626);font-size:12px}
1879
+ .xmimo-tts-card{list-style:none;border:1px solid var(--dsw-alias-border-l2,#e5e7eb);border-radius:12px;color:var(--dsw-alias-label-primary,#1f2328);background:var(--dsw-alias-bg-layer-3,#fff);overflow:hidden;transition:border-color 160ms ease,background 160ms ease}.xmimo-tts-card:hover{border-color:var(--dsw-alias-label-dimmed,#c8ccd4)}.xmimo-tts-card-open{background:var(--dsw-alias-bg-layer-2,#f7f8fa);border-color:var(--dsw-alias-label-dimmed,#c8ccd4)}.xmimo-tts-card-header{appearance:none;display:flex;width:100%;align-items:center;justify-content:space-between;gap:12px;padding:14px 16px;border:0;border-radius:12px;color:inherit;text-align:left;background:transparent;font:inherit;cursor:pointer}.xmimo-tts-card-header:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4f6ef7);outline-offset:-2px}.xmimo-tts-card-head-text{display:flex;min-width:0;flex:1;flex-direction:column;gap:4px}.xmimo-tts-card-title{font-size:15px;font-weight:600}.xmimo-tts-card-description{color:var(--dsw-alias-label-tertiary,#8b93a1);font-size:13px;line-height:18px}.xmimo-tts-chevron{flex:none;color:var(--dsw-alias-label-tertiary,#8b93a1);transition:transform 160ms ease}.xmimo-tts-chevron-open{transform:rotate(180deg)}.xmimo-tts-pending{flex:none;border-radius:999px;padding:1px 8px;color:var(--dsw-alias-label-secondary,#5f6875);background:var(--dsw-alias-bg-module-platform,#eef0f3);font-size:11px;font-weight:500;line-height:17px}.xmimo-tts-card-body{border-top:1px solid var(--dsw-alias-border-l2,#e5e7eb);margin:0 16px;padding:0 0 16px}
1880
+ .xmimo-tts-grid{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:0;align-items:start}.xmimo-tts-grid>*{box-sizing:border-box;padding:16px 0;border-top:1px solid var(--dsw-alias-border-l2,#e5e7eb)}.xmimo-tts-grid>:first-child{border-top:0}.xmimo-tts-grid label,.xmimo-tts-api-key,.xmimo-tts-model,.xmimo-tts-voice-design-prompt,.xmimo-tts-select-column>div{display:flex;min-width:0;flex-direction:column;gap:6px;font-size:13px}.xmimo-tts-grid input,.xmimo-tts-grid select,.xmimo-tts-grid textarea{box-sizing:border-box;width:100%;border:1px solid var(--dsw-alias-border-l2,#e5e7eb);border-radius:8px;padding:8px 10px;color:var(--dsw-alias-label-primary,#1f2328);background:var(--dsw-alias-bg-layer-2,#f3f4f6);font:inherit}.xmimo-tts-grid select{color-scheme:light dark}.xmimo-tts-grid select option{color:var(--dsw-alias-label-primary,#1f2328);background:var(--dsw-alias-bg-layer-1,#fff)}.xmimo-tts-grid select:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4f6ef7);outline-offset:1px}.xmimo-tts-grid small{color:var(--dsw-alias-label-tertiary,#8b93a1);line-height:17px}.xmimo-tts-field-heading{display:flex;min-width:0;min-height:20px;flex-direction:row!important;align-items:center;justify-content:space-between;gap:8px}.xmimo-tts-field-label{display:inline-flex;min-width:0;align-items:center;gap:8px}.xmimo-tts-api-key-link{color:var(--dsw-alias-brand-primary,#4f6ef7);font-size:12px;text-decoration:none}.xmimo-tts-api-key-link:hover{text-decoration:underline}.xmimo-tts-field-badges{display:flex!important;flex:none;flex-direction:row!important;align-items:center;gap:8px}.xmimo-tts-overridden{border-radius:999px;padding:1px 7px;color:var(--dsw-alias-label-secondary,#5f6875);background:var(--dsw-alias-bg-module-platform,#eef0f3);font-size:11px;line-height:17px}.xmimo-tts-reset{padding:0;border:0;color:var(--dsw-alias-label-secondary,#5f6875);background:transparent;font:inherit;font-size:12px;cursor:pointer}.xmimo-tts-reset:hover:not(:disabled){color:var(--dsw-alias-label-primary,#1f2328)}.xmimo-tts-reset:disabled{cursor:not-allowed;opacity:.45}.xmimo-tts-api-key-hints{display:flex;min-width:0;gap:8px;align-items:center}.xmimo-tts-api-key-hints small{min-width:0;white-space:nowrap}.xmimo-tts-wide{grid-column:1/-1}.xmimo-tts-switch-row{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:0}.xmimo-tts-switch-row>*:first-child{padding-right:14px}.xmimo-tts-switch-row>*+*{padding-left:14px;border-left:1px solid var(--dsw-alias-border-l2,#e5e7eb)}.xmimo-tts-checkbox-row{position:relative;flex-direction:row!important;align-items:center!important;gap:10px!important;cursor:pointer}.xmimo-tts-switch-copy{display:flex;min-width:0;flex-direction:column;gap:4px}.xmimo-tts-checkbox-row>input{position:absolute;width:1px!important;height:1px;margin:0!important;padding:0!important;overflow:hidden;border:0!important;opacity:0;clip-path:inset(50%)}.xmimo-tts-switch-control{box-sizing:border-box;position:relative;display:inline-block!important;width:36px;height:20px;min-width:36px;flex:none;border:1px solid var(--dsw-alias-border-l2,#c8ccd4);border-radius:999px;background:var(--dsw-alias-bg-module-platform,#e5e7eb);transition:border-color 160ms ease,background 160ms ease}.xmimo-tts-switch-control:after{content:"";position:absolute;top:2px;left:2px;width:14px;height:14px;border-radius:50%;background:var(--dsw-alias-bg-layer-1,#fff);box-shadow:0 1px 3px rgba(15,23,42,.24);transition:transform 160ms ease}.xmimo-tts-checkbox-row>input:checked+.xmimo-tts-switch-control{border-color:var(--dsw-alias-brand-primary,#4f6ef7);background:var(--dsw-alias-brand-primary,#4f6ef7)}.xmimo-tts-checkbox-row>input:checked+.xmimo-tts-switch-control:after{transform:translateX(16px)}.xmimo-tts-checkbox-row>input:focus-visible+.xmimo-tts-switch-control{outline:2px solid var(--dsw-alias-brand-primary,#4f6ef7);outline-offset:2px}.xmimo-tts-checkbox-row>input:disabled+.xmimo-tts-switch-control{cursor:not-allowed;opacity:.45}.xmimo-tts-select-column{display:flex;min-width:0;flex-direction:row;gap:0}.xmimo-tts-select-column>div{flex:1}.xmimo-tts-select-column>div:first-child:not(:only-child){padding-right:16px}.xmimo-tts-select-column>div+div{padding-left:16px;border-left:1px solid var(--dsw-alias-border-l2,#e5e7eb)}
1881
+ .xmimo-tts-voice-picker{display:flex;min-width:0;flex-direction:column;gap:6px}.xmimo-tts-voice-picker-trigger,.xmimo-tts-voice-option{box-sizing:border-box;display:flex;width:100%;min-width:0;align-items:center;gap:10px;border:1px solid var(--dsw-alias-border-l2,#e5e7eb);color:var(--dsw-alias-label-primary,#1f2328);background:var(--dsw-alias-bg-layer-2,#f3f4f6);font:inherit;text-align:left;cursor:pointer}.xmimo-tts-voice-picker-trigger{min-height:54px;border-radius:10px;padding:6px 10px}.xmimo-tts-voice-picker-trigger:hover:not(:disabled){border-color:var(--dsw-alias-label-dimmed,#c8ccd4);background:var(--dsw-alias-interactive-bg-hover,#eef0f3)}.xmimo-tts-voice-picker-trigger:focus-visible,.xmimo-tts-voice-option:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4f6ef7);outline-offset:1px}.xmimo-tts-voice-picker-trigger:disabled{cursor:not-allowed;opacity:.55}.xmimo-tts-voice-avatar{box-sizing:border-box;display:block;width:40px;height:40px;flex:none;border:1px solid color-mix(in srgb,var(--dsw-alias-border-l2,#e5e7eb) 80%,transparent);border-radius:50%;object-fit:cover;background:var(--dsw-alias-bg-layer-1,#fff)}.xmimo-tts-custom-voice-avatar{display:grid;place-items:center;color:var(--dsw-alias-brand-primary,#4f6ef7);background:color-mix(in srgb,var(--dsw-alias-brand-primary,#4f6ef7) 12%,var(--dsw-alias-bg-layer-1,#fff))}.xmimo-tts-custom-voice-avatar svg{width:30px;height:30px;overflow:visible}.xmimo-tts-custom-voice-avatar circle{fill:currentColor}.xmimo-tts-custom-voice-avatar path{fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}.xmimo-tts-voice-option-copy{display:flex;min-width:0;flex:1;flex-direction:column;gap:1px}.xmimo-tts-voice-option-copy strong{overflow:hidden;font-size:13px;font-weight:600;line-height:18px;text-overflow:ellipsis;white-space:nowrap}.xmimo-tts-voice-option-copy small{overflow:hidden;font-size:12px;text-overflow:ellipsis;white-space:nowrap}.xmimo-tts-voice-picker-chevron{flex:none;color:var(--dsw-alias-label-tertiary,#8b93a1);transition:transform 160ms ease}.xmimo-tts-voice-picker-chevron-open{transform:rotate(180deg)}.xmimo-tts-voice-picker-menu{display:grid;max-height:310px;overflow:auto;overscroll-behavior:contain;border:1px solid var(--dsw-alias-border-l2,#e5e7eb);border-radius:10px;padding:5px;background:var(--dsw-alias-bg-layer-1,#fff);box-shadow:0 10px 28px rgba(15,23,42,.12)}.xmimo-tts-voice-option{min-height:50px;border:0;border-radius:7px;padding:5px 7px;background:transparent}.xmimo-tts-voice-option:hover,.xmimo-tts-voice-option:focus-visible{background:var(--dsw-alias-interactive-bg-hover,#f3f4f6)}.xmimo-tts-voice-option-selected{background:color-mix(in srgb,var(--dsw-alias-brand-primary,#4f6ef7) 10%,transparent)}
1882
+ .xmimo-tts-card-actions{display:flex;align-items:center;justify-content:flex-end;gap:10px;padding-top:12px;border-top:1px solid var(--dsw-alias-border-l2,#e5e7eb);font-size:12px;color:var(--dsw-alias-label-tertiary,#8b93a1)}.xmimo-tts-card-actions button{border:1px solid var(--dsw-alias-brand-primary,#4f6ef7);border-radius:8px;padding:5px 14px;color:var(--dsw-alias-bg-layer-1,#fff);background:var(--dsw-alias-brand-primary,#4f6ef7);cursor:pointer;font:inherit}.xmimo-tts-card-actions button:hover:not(:disabled){filter:brightness(1.08)}.xmimo-tts-card-actions button:disabled{cursor:not-allowed;color:var(--dsw-alias-label-dimmed,#9ca3af);background:var(--dsw-alias-bg-layer-2,#f3f4f6);border-color:var(--dsw-alias-border-l2,#e5e7eb);opacity:1}.xmimo-tts-card-actions .xmimo-tts-star{border-color:transparent;color:var(--dsw-alias-brand-primary,#4f6ef7);background:transparent;font-weight:500}.xmimo-tts-card-actions .xmimo-tts-star:hover{text-decoration:underline}.xmimo-tts-card-actions .xmimo-tts-uninstall{margin-right:auto;border-color:#F56C6C;color:#F56C6C;background:transparent}.xmimo-tts-card-actions .xmimo-tts-uninstall:hover:not(:disabled){background:color-mix(in srgb,#F56C6C 10%,transparent)}.xmimo-tts-card-actions .xmimo-tts-uninstall:disabled{border-color:#F56C6C;color:#F56C6C;background:transparent;opacity:.55}.xmimo-tts-uninstall-confirmation{display:flex;align-items:center;gap:8px;margin-right:auto;color:#F56C6C}.xmimo-tts-uninstall-choice{display:inline-flex;overflow:hidden;border:1px solid #F56C6C;border-radius:8px}.xmimo-tts-card-actions .xmimo-tts-uninstall-choice button{border:0;border-radius:0;padding:5px 12px;color:#F56C6C;background:transparent}.xmimo-tts-card-actions .xmimo-tts-uninstall-choice button+button{border-left:1px solid #F56C6C}.xmimo-tts-card-actions .xmimo-tts-uninstall-choice button:hover{filter:none;background:color-mix(in srgb,#F56C6C 10%,transparent)}.xmimo-tts-card-actions .xmimo-tts-discard{border-color:var(--dsw-alias-border-l2,#e5e7eb);color:var(--dsw-alias-label-secondary,#5f6875);background:transparent}.xmimo-tts-card-actions .xmimo-tts-discard:hover:not(:disabled){color:var(--dsw-alias-label-primary,#1f2328);border-color:var(--dsw-alias-label-dimmed,#c8ccd4)}.xmimo-tts-failed{color:var(--dsw-alias-state-error-primary,#dc2626)}
1883
+ @media(max-width:720px){.xmimo-tts-grid{grid-template-columns:1fr}.xmimo-tts-wide{grid-column:auto}.xmimo-tts-switch-row{grid-template-columns:1fr}.xmimo-tts-switch-row>*:first-child{padding-right:0;padding-bottom:16px}.xmimo-tts-switch-row>*+*{padding-top:16px;padding-left:0;border-top:1px solid var(--dsw-alias-border-l2,#e5e7eb);border-left:0}.xmimo-tts-select-column{grid-column:auto;flex-direction:column}.xmimo-tts-select-column>div:first-child:not(:only-child){padding-right:0;padding-bottom:16px}.xmimo-tts-select-column>div+div{padding-top:16px;padding-left:0;border-top:1px solid var(--dsw-alias-border-l2,#e5e7eb);border-left:0}.xmimo-tts-api-key-hints{flex-wrap:wrap}.xmimo-tts-api-key-hints small{white-space:normal}}
1884
+ `;
1885
+
1886
+ //#endregion
1887
+ //#region src/client/index.tsx
1888
+ /** Client services required by this plugin. */
1889
+ const inject = [
1890
+ "slots",
1891
+ "locale",
1892
+ "connection",
1893
+ "remote",
1894
+ "settingsScope"
1895
+ ];
1896
+ function formatStartupError(error) {
1897
+ return error instanceof Error ? error.message : String(error);
1898
+ }
1899
+ function registerSlotContribution(ctx, name, register) {
1900
+ ctx.effect(() => {
1901
+ try {
1902
+ ctx.slots.inject(name, () => {
1903
+ try {
1904
+ return register();
1905
+ } catch (error) {
1906
+ ctx.logger.error(`dsh-xiaomi-tts: ${name} contribution disabled: ${formatStartupError(error)}`);
1907
+ return () => {};
1908
+ }
1909
+ });
1910
+ } catch (error) {
1911
+ ctx.logger.error(`dsh-xiaomi-tts: ${name} injection disabled: ${formatStartupError(error)}`);
1912
+ }
1913
+ return () => {};
1914
+ }, `xiaomi-mimo-tts: ${name}`);
1915
+ }
1693
1916
  /** Register the Web action, settings card, locale dictionaries, and styles. */
1694
1917
  function apply(ctx) {
1695
1918
  const locale = ctx.locale;
@@ -1706,21 +1929,11 @@ function apply(ctx) {
1706
1929
  const live = new LiveSpeechController();
1707
1930
  live.setStateChangeListener((sessionId, messageId, status) => playback.updateLivePlayback(sessionId, messageId, status));
1708
1931
  ctx.effect(() => () => playback.dispose(), "xiaomi-mimo-tts: playback");
1709
- ctx.effect(() => () => {
1710
- live.dispose();
1711
- }, "xiaomi-mimo-tts: live playback");
1932
+ ctx.effect(() => () => live.dispose(), "xiaomi-mimo-tts: live playback");
1712
1933
  ctx.effect(() => {
1713
1934
  const style = document.createElement("style");
1714
1935
  style.dataset.plugin = NS;
1715
- style.textContent = `
1716
- .xmimo-tts-action{width:28px;height:28px;color:var(--dsw-alias-label-tertiary);cursor:pointer;background:transparent;border:none;border-radius:28px;justify-content:center;align-items:center;padding:6px;display:inline-flex}.xmimo-tts-action:hover{background:var(--dsw-alias-interactive-bg-hover,#f3f4f6);color:var(--dsw-alias-label-secondary,#5f6875)}.xmimo-tts-action[aria-pressed=true]{background:var(--dsw-alias-interactive-bg-hover,#f3f4f6);color:var(--dsw-alias-label-secondary,#5f6875)}.xmimo-tts-action:disabled{cursor:default;opacity:.45}.xmimo-tts-spin{animation:xmimo-spin 1s linear infinite}@keyframes xmimo-spin{to{transform:rotate(360deg)}}
1717
- .xmimo-tts-inline-error{max-width:220px;color:var(--dsw-alias-state-error-primary,#dc2626);font-size:12px}
1718
- .xmimo-tts-card{list-style:none;border:1px solid var(--dsw-alias-border-l2,#e5e7eb);border-radius:12px;color:var(--dsw-alias-label-primary,#1f2328);background:var(--dsw-alias-bg-layer-3,#fff);overflow:hidden;transition:border-color 160ms ease,background 160ms ease}.xmimo-tts-card:hover{border-color:var(--dsw-alias-label-dimmed,#c8ccd4)}.xmimo-tts-card-open{background:var(--dsw-alias-bg-layer-2,#f7f8fa);border-color:var(--dsw-alias-label-dimmed,#c8ccd4)}.xmimo-tts-card-header{appearance:none;display:flex;width:100%;align-items:center;justify-content:space-between;gap:12px;padding:14px 16px;border:0;border-radius:12px;color:inherit;text-align:left;background:transparent;font:inherit;cursor:pointer}.xmimo-tts-card-header:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4f6ef7);outline-offset:-2px}.xmimo-tts-card-head-text{display:flex;min-width:0;flex:1;flex-direction:column;gap:4px}.xmimo-tts-card-title{font-size:15px;font-weight:600}.xmimo-tts-card-description{color:var(--dsw-alias-label-tertiary,#8b93a1);font-size:13px;line-height:18px}.xmimo-tts-chevron{flex:none;color:var(--dsw-alias-label-tertiary,#8b93a1);transition:transform 160ms ease}.xmimo-tts-chevron-open{transform:rotate(180deg)}.xmimo-tts-pending{flex:none;border-radius:999px;padding:1px 8px;color:var(--dsw-alias-label-secondary,#5f6875);background:var(--dsw-alias-bg-module-platform,#eef0f3);font-size:11px;font-weight:500;line-height:17px}.xmimo-tts-card-body{border-top:1px solid var(--dsw-alias-border-l2,#e5e7eb);margin:0 16px;padding:0 0 16px}
1719
- .xmimo-tts-grid{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:16px 14px;margin-top:16px;align-items:start}.xmimo-tts-grid label,.xmimo-tts-api-key,.xmimo-tts-model,.xmimo-tts-voice-design-prompt,.xmimo-tts-select-column>div{display:flex;min-width:0;flex-direction:column;gap:6px;font-size:13px}.xmimo-tts-grid input,.xmimo-tts-grid select,.xmimo-tts-grid textarea{box-sizing:border-box;width:100%;border:1px solid var(--dsw-alias-border-l2,#e5e7eb);border-radius:8px;padding:8px 10px;color:var(--dsw-alias-label-primary,#1f2328);background:var(--dsw-alias-bg-layer-2,#f3f4f6);font:inherit}.xmimo-tts-grid select{color-scheme:light dark}.xmimo-tts-grid select option{color:var(--dsw-alias-label-primary,#1f2328);background:var(--dsw-alias-bg-layer-1,#fff)}.xmimo-tts-grid select:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4f6ef7);outline-offset:1px}.xmimo-tts-grid small{color:var(--dsw-alias-label-tertiary,#8b93a1);line-height:17px}.xmimo-tts-field-heading{display:flex;min-width:0;min-height:20px;flex-direction:row!important;align-items:center;justify-content:space-between;gap:8px}.xmimo-tts-field-label{display:inline-flex;min-width:0;align-items:center;gap:8px}.xmimo-tts-api-key-link{color:var(--dsw-alias-brand-primary,#4f6ef7);font-size:12px;text-decoration:none}.xmimo-tts-api-key-link:hover{text-decoration:underline}.xmimo-tts-field-badges{display:flex!important;flex:none;flex-direction:row!important;align-items:center;gap:8px}.xmimo-tts-overridden{border-radius:999px;padding:1px 7px;color:var(--dsw-alias-label-secondary,#5f6875);background:var(--dsw-alias-bg-module-platform,#eef0f3);font-size:11px;line-height:17px}.xmimo-tts-reset{padding:0;border:0;color:var(--dsw-alias-label-secondary,#5f6875);background:transparent;font:inherit;font-size:12px;cursor:pointer}.xmimo-tts-reset:hover:not(:disabled){color:var(--dsw-alias-label-primary,#1f2328)}.xmimo-tts-reset:disabled{cursor:not-allowed;opacity:.45}.xmimo-tts-api-key-hints{display:flex;min-width:0;gap:8px;align-items:center}.xmimo-tts-api-key-hints small{min-width:0;white-space:nowrap}.xmimo-tts-wide{grid-column:1/-1}.xmimo-tts-switch-row{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:14px}.xmimo-tts-checkbox-row{flex-direction:row!important;align-items:flex-start!important}.xmimo-tts-checkbox-row input{width:auto!important;flex:none;margin-top:3px}.xmimo-tts-checkbox-row span{display:flex;min-width:0;flex-direction:column;gap:4px}.xmimo-tts-select-column{display:flex;min-width:0;flex-direction:row;gap:16px}.xmimo-tts-select-column>div{flex:1}
1720
- .xmimo-tts-voice-picker{display:flex;min-width:0;flex-direction:column;gap:6px}.xmimo-tts-voice-picker-trigger,.xmimo-tts-voice-option{box-sizing:border-box;display:flex;width:100%;min-width:0;align-items:center;gap:10px;border:1px solid var(--dsw-alias-border-l2,#e5e7eb);color:var(--dsw-alias-label-primary,#1f2328);background:var(--dsw-alias-bg-layer-2,#f3f4f6);font:inherit;text-align:left;cursor:pointer}.xmimo-tts-voice-picker-trigger{min-height:54px;border-radius:10px;padding:6px 10px}.xmimo-tts-voice-picker-trigger:hover:not(:disabled){border-color:var(--dsw-alias-label-dimmed,#c8ccd4);background:var(--dsw-alias-interactive-bg-hover,#eef0f3)}.xmimo-tts-voice-picker-trigger:focus-visible,.xmimo-tts-voice-option:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4f6ef7);outline-offset:1px}.xmimo-tts-voice-picker-trigger:disabled{cursor:not-allowed;opacity:.55}.xmimo-tts-voice-avatar{box-sizing:border-box;display:block;width:40px;height:40px;flex:none;border:1px solid color-mix(in srgb,var(--dsw-alias-border-l2,#e5e7eb) 80%,transparent);border-radius:50%;object-fit:cover;background:var(--dsw-alias-bg-layer-1,#fff)}.xmimo-tts-custom-voice-avatar{display:grid;place-items:center;color:var(--dsw-alias-brand-primary,#4f6ef7);background:color-mix(in srgb,var(--dsw-alias-brand-primary,#4f6ef7) 12%,var(--dsw-alias-bg-layer-1,#fff))}.xmimo-tts-custom-voice-avatar svg{width:30px;height:30px;overflow:visible}.xmimo-tts-custom-voice-avatar circle{fill:currentColor}.xmimo-tts-custom-voice-avatar path{fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}.xmimo-tts-voice-option-copy{display:flex;min-width:0;flex:1;flex-direction:column;gap:1px}.xmimo-tts-voice-option-copy strong{overflow:hidden;font-size:13px;font-weight:600;line-height:18px;text-overflow:ellipsis;white-space:nowrap}.xmimo-tts-voice-option-copy small{overflow:hidden;font-size:12px;text-overflow:ellipsis;white-space:nowrap}.xmimo-tts-voice-picker-chevron{flex:none;color:var(--dsw-alias-label-tertiary,#8b93a1);transition:transform 160ms ease}.xmimo-tts-voice-picker-chevron-open{transform:rotate(180deg)}.xmimo-tts-voice-picker-menu{display:grid;max-height:310px;overflow:auto;overscroll-behavior:contain;border:1px solid var(--dsw-alias-border-l2,#e5e7eb);border-radius:10px;padding:5px;background:var(--dsw-alias-bg-layer-1,#fff);box-shadow:0 10px 28px rgba(15,23,42,.12)}.xmimo-tts-voice-option{min-height:50px;border:0;border-radius:7px;padding:5px 7px;background:transparent}.xmimo-tts-voice-option:hover,.xmimo-tts-voice-option:focus-visible{background:var(--dsw-alias-interactive-bg-hover,#f3f4f6)}.xmimo-tts-voice-option-selected{background:color-mix(in srgb,var(--dsw-alias-brand-primary,#4f6ef7) 10%,transparent)}
1721
- .xmimo-tts-card-actions{display:flex;align-items:center;justify-content:flex-end;gap:10px;margin-top:16px;padding-top:12px;border-top:1px solid var(--dsw-alias-border-l2,#e5e7eb);font-size:12px;color:var(--dsw-alias-label-tertiary,#8b93a1)}.xmimo-tts-card-actions button{border:1px solid var(--dsw-alias-brand-primary,#4f6ef7);border-radius:8px;padding:5px 14px;color:var(--dsw-alias-bg-layer-1,#fff);background:var(--dsw-alias-brand-primary,#4f6ef7);cursor:pointer;font:inherit}.xmimo-tts-card-actions button:hover:not(:disabled){filter:brightness(1.08)}.xmimo-tts-card-actions button:disabled{cursor:not-allowed;color:var(--dsw-alias-label-dimmed,#9ca3af);background:var(--dsw-alias-bg-layer-2,#f3f4f6);border-color:var(--dsw-alias-border-l2,#e5e7eb);opacity:1}.xmimo-tts-card-actions .xmimo-tts-discard{border-color:var(--dsw-alias-border-l2,#e5e7eb);color:var(--dsw-alias-label-secondary,#5f6875);background:transparent}.xmimo-tts-card-actions .xmimo-tts-discard:hover:not(:disabled){color:var(--dsw-alias-label-primary,#1f2328);border-color:var(--dsw-alias-label-dimmed,#c8ccd4)}.xmimo-tts-failed{color:var(--dsw-alias-state-error-primary,#dc2626)}
1722
- @media(max-width:720px){.xmimo-tts-grid{grid-template-columns:1fr}.xmimo-tts-wide{grid-column:auto}.xmimo-tts-switch-row{grid-template-columns:1fr}.xmimo-tts-select-column{grid-column:auto;flex-direction:column}.xmimo-tts-api-key-hints{flex-wrap:wrap}.xmimo-tts-api-key-hints small{white-space:normal}}
1723
- `;
1936
+ style.textContent = CLIENT_STYLES;
1724
1937
  document.head.appendChild(style);
1725
1938
  return () => style.remove();
1726
1939
  }, "xiaomi-mimo-tts: styles");