tavern-harness 0.1.31 → 0.1.32

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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,48 @@
3
3
  > 本文件由 `scripts/changelog.mjs` 从 `changelog/v*.md` 生成,请勿手动编辑。
4
4
  > 版本对比链接见文末;源文件位于仓库 `changelog/` 目录。
5
5
 
6
+ ## [0.1.32] - 2026-11-18
7
+
8
+ ### 中文
9
+
10
+ #### 新增
11
+
12
+ - 语音服务供应商:设置页新增「🔊 语音服务供应商」分区,支持 DeepSeek(海星 · 女声、暗潮 · 男声)与百炼 Token Plan(龙安灵心、龙安陆风)。填写 API Key 即可保存,保存前还能在表单里试听音色;可以添加多个供应商,并随时启用、停用、编辑或删除
13
+ - 朗读助手消息:在助手消息的「更多」菜单中选择「朗读消息」,就会用默认音色朗读这条回复
14
+ - 自动朗读:对话标题栏新增朗读开关,开启后每条助手回复生成完毕会自动朗读,关闭后恢复静音
15
+ - 默认音色:在「语音服务供应商」下方选择默认的供应商与音色,手动朗读和自动朗读都会使用它;没有配置时会提示先选择
16
+
17
+ #### 改进
18
+
19
+ - 设置页的供应商列表改为按添加时间倒序排列,新添加的供应商显示在最上方;「添加供应商」按钮移到分区标题右侧,列表为空时也始终可见
20
+ - 文本供应商与语音供应商的卡片分别显示「文本」「语音」标签,并统一了两类标签的配色,一眼就能区分服务类型
21
+ - 文本与语音供应商的 API Key 输入框都增加了显示 / 隐藏按钮,方便核对已填写的密钥
22
+ - 语音合成请求由本地持久化服务代理转发,API Key 只保存在本地数据库,不会直接出现在发往第三方的浏览器请求里
23
+
24
+ #### 内部
25
+
26
+ - 新增 `voice-server.mjs`,对百炼返回的音频地址做 HTTPS 与域名校验;补充语音、持久化与供应商相关的测试
27
+
28
+ ### English
29
+
30
+ #### Added
31
+
32
+ - **Voice service providers**: Settings now has a **🔊 Voice Service Providers** section supporting DeepSeek (Stella · female, Tide · male) and Bailian Token Plan (Longan Lingxin, Longan Lufeng). Enter an API key to save a provider, and preview each voice right in the form before saving. You can add several providers and enable, disable, edit, or delete them at any time
33
+ - **Read message aloud**: choose **Read message aloud** from an assistant message's More menu to hear that reply in the default voice
34
+ - **Automatic reading**: the conversation header has a new reading toggle. When it is on, every completed assistant reply is read aloud automatically; turn it off to go silent
35
+ - **Default voice**: pick the default provider and voice below the voice providers section; both manual and automatic reading use it. If nothing is configured, the app prompts you to choose one first
36
+
37
+ #### Changed
38
+
39
+ - The provider list in Settings is now sorted newest first, so freshly added providers appear at the top; the **Add provider** button moved next to the section heading and is always visible, even when the list is empty
40
+ - Text and voice provider cards now carry **Text** and **Voice** tags with a unified color scheme, making the service type obvious at a glance
41
+ - API key fields for both text and voice providers gained a show/hide button so you can check what you entered
42
+ - Voice synthesis requests are proxied through the local persistence service, so the API key stays in the local database and never appears in browser requests to third parties
43
+
44
+ #### Internal
45
+
46
+ - Added `voice-server.mjs` to validate Bailian audio URLs against HTTPS and an allowlisted domain pattern, plus tests for voice, persistence, and provider behavior
47
+
6
48
  ## [0.1.31] - 2026-11-05
7
49
 
8
50
  ### 中文
@@ -914,6 +956,7 @@
914
956
  - Vite + React + Zustand + Dexie stack with browser-side local persistence
915
957
 
916
958
  <!-- 链接定义 -->
959
+ [0.1.32]: https://github.com/Rannichan/Tavern-Harness/compare/v0.1.31...v0.1.32
917
960
  [0.1.31]: https://github.com/Rannichan/Tavern-Harness/compare/v0.1.30...v0.1.31
918
961
  [0.1.30]: https://github.com/Rannichan/Tavern-Harness/compare/v0.1.29...v0.1.30
919
962
  [0.1.29]: https://github.com/Rannichan/Tavern-Harness/compare/v0.1.28...v0.1.29
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tavern-harness",
3
- "version": "0.1.31",
3
+ "version": "0.1.32",
4
4
  "description": "Tavern Harness — 酒馆模式下的本地 AI Agent 助手(MyAgent-Android 的 Web 复刻)",
5
5
  "private": false,
6
6
  "type": "module",
@@ -9,6 +9,7 @@ import { mkdirSync } from 'node:fs';
9
9
  import { homedir } from 'node:os';
10
10
  import { dirname, join, resolve } from 'node:path';
11
11
  import { DatabaseSync } from 'node:sqlite';
12
+ import { normalizeBailianAudioUrl } from './voice-server.mjs';
12
13
 
13
14
  const PORT = Number(process.argv[2] || process.env.PERSISTENCE_PORT || 17892);
14
15
  // 记录读写(图片/附件)走大上限;锁和健康检查的请求体很小,单独收紧。
@@ -194,7 +195,7 @@ const listRecordsByJsonField = database.prepare(`
194
195
  const listStartupRecords = database.prepare(`
195
196
  SELECT collection, record_key, value_json, updated_at
196
197
  FROM app_records
197
- WHERE collection IN ('settings', 'providers', 'npcs', 'sessions', 'worldBooks', 'tools', 'achievementUnlocks')
198
+ WHERE collection IN ('settings', 'providers', 'voiceProviders', 'npcs', 'sessions', 'worldBooks', 'tools', 'achievementUnlocks')
198
199
  ORDER BY collection, record_key
199
200
  `);
200
201
  const deleteRecord = database.prepare('DELETE FROM app_records WHERE collection = ? AND record_key = ?');
@@ -288,6 +289,7 @@ const server = createServer(async (req, res) => {
288
289
  const collections = {
289
290
  settings: [],
290
291
  providers: [],
292
+ voiceProviders: [],
291
293
  npcs: [],
292
294
  sessions: [],
293
295
  worldBooks: [],
@@ -304,6 +306,87 @@ const server = createServer(async (req, res) => {
304
306
  json(res, 200, { ok: true, lock: lockState(clientId), collections });
305
307
  return;
306
308
  }
309
+ if (pathname === '/voice/synthesize' || pathname === '/voice/preview') {
310
+ const voiceId = typeof body.voiceId === 'string' ? body.voiceId : '';
311
+ const text = typeof body.text === 'string' ? body.text.trim() : '';
312
+ let kind;
313
+ let apiKey;
314
+ if (pathname === '/voice/preview') {
315
+ kind = body.kind;
316
+ apiKey = typeof body.apiKey === 'string' ? body.apiKey.trim() : '';
317
+ } else {
318
+ const providerId = Number(body.providerId);
319
+ if (!Number.isInteger(providerId) || providerId <= 0) {
320
+ json(res, 400, { ok: false, message: 'Invalid voice synthesis request' });
321
+ return;
322
+ }
323
+ const record = getRecord.get('voiceProviders', String(providerId));
324
+ if (!record) {
325
+ json(res, 404, { ok: false, message: 'Voice provider not found' });
326
+ return;
327
+ }
328
+ const provider = JSON.parse(record.value_json);
329
+ if (!provider.isEnabled) {
330
+ json(res, 400, { ok: false, message: 'Voice provider or voice is unavailable' });
331
+ return;
332
+ }
333
+ kind = provider.kind;
334
+ apiKey = typeof provider.apiKey === 'string' ? provider.apiKey.trim() : '';
335
+ }
336
+ const allowedVoices = kind === 'deepseek'
337
+ ? new Set(['stella', 'tide'])
338
+ : kind === 'bailian'
339
+ ? new Set(['longanlingxin', 'longanlufeng'])
340
+ : null;
341
+ if (!allowedVoices || !apiKey || !allowedVoices.has(voiceId) || !text || text.length > 10_000) {
342
+ json(res, 400, { ok: false, message: 'Voice provider or voice is unavailable' });
343
+ return;
344
+ }
345
+ const endpoint = kind === 'deepseek'
346
+ ? 'https://api.deepseek.com/v1/tools/tts'
347
+ : 'https://token-plan.cn-beijing.maas.aliyuncs.com/api/v1/services/audio/tts/SpeechSynthesizer';
348
+ const requestBody = kind === 'deepseek'
349
+ ? { text, voice_id: voiceId, format: 'wav', filter_markdown: true }
350
+ : { model: 'qwen-audio-3.0-tts-plus', input: { text, voice: voiceId, format: 'mp3', sample_rate: 22050 } };
351
+ const upstream = await fetch(endpoint, {
352
+ method: 'POST',
353
+ headers: { Authorization: `Bearer ${apiKey}`, 'Content-Type': 'application/json' },
354
+ body: JSON.stringify(requestBody),
355
+ signal: AbortSignal.timeout(120_000),
356
+ });
357
+ if (!upstream.ok) {
358
+ const payload = await upstream.json().catch(() => null);
359
+ upstream.body?.cancel();
360
+ const upstreamMessage = payload?.message ?? payload?.error?.message ?? payload?.code;
361
+ json(res, upstream.status, { ok: false, message: upstreamMessage ? `Voice service error: ${upstreamMessage}` : `Voice service returned HTTP ${upstream.status}` });
362
+ return;
363
+ }
364
+ let audioResponse = upstream;
365
+ if (kind === 'bailian') {
366
+ const payload = await upstream.json();
367
+ const rawAudioUrl = payload?.output?.audio?.url;
368
+ const audioUrl = normalizeBailianAudioUrl(rawAudioUrl);
369
+ if (!audioUrl) {
370
+ const upstreamMessage = payload?.message ?? payload?.error?.message ?? payload?.code;
371
+ json(res, 502, { ok: false, message: upstreamMessage ? `Bailian synthesis failed: ${upstreamMessage}` : 'Bailian did not return a valid audio URL' });
372
+ return;
373
+ }
374
+ audioResponse = await fetch(audioUrl, { signal: AbortSignal.timeout(120_000) });
375
+ if (!audioResponse.ok) {
376
+ audioResponse.body?.cancel();
377
+ json(res, 502, { ok: false, message: `Unable to download generated audio (HTTP ${audioResponse.status})` });
378
+ return;
379
+ }
380
+ }
381
+ const audio = Buffer.from(await audioResponse.arrayBuffer());
382
+ res.writeHead(200, {
383
+ 'Content-Type': audioResponse.headers.get('content-type') || (kind === 'deepseek' ? 'audio/wav' : 'audio/mpeg'),
384
+ 'Content-Length': String(audio.length),
385
+ 'Cache-Control': 'no-store',
386
+ });
387
+ res.end(audio);
388
+ return;
389
+ }
307
390
  if (!pathname.startsWith('/records/')) {
308
391
  json(res, 404, { ok: false, message: `Unknown persistence endpoint: ${pathname}` });
309
392
  return;
package/src/App.tsx CHANGED
@@ -321,6 +321,7 @@ function SessionHeader({
321
321
  const deleteSession = useStore((s) => s.deleteSession);
322
322
  const resetSessionConversation = useStore((s) => s.resetSessionConversation);
323
323
  const themeMode = useStore((s) => s.settings?.themeMode ?? 'system');
324
+ const autoVoiceEnabled = useStore((s) => s.settings?.autoVoiceEnabled ?? false);
324
325
  const setSettings = useStore((s) => s.setSettings);
325
326
  const t = useT();
326
327
  const [showEdit, setShowEdit] = useState(false);
@@ -402,6 +403,16 @@ function SessionHeader({
402
403
  >
403
404
  <Icon name="more" size={18} />
404
405
  </button>
406
+ <button
407
+ className={`btn-ghost icon-tooltip chat-voice-toggle${autoVoiceEnabled ? ' active' : ''}`}
408
+ type="button"
409
+ title={t(autoVoiceEnabled ? 'header.disableAutoVoice' : 'header.enableAutoVoice')}
410
+ aria-label={t(autoVoiceEnabled ? 'header.disableAutoVoice' : 'header.enableAutoVoice')}
411
+ aria-pressed={autoVoiceEnabled}
412
+ onClick={() => void setSettings({ autoVoiceEnabled: !autoVoiceEnabled })}
413
+ >
414
+ <Icon name={autoVoiceEnabled ? 'speaker' : 'speaker-off'} size={17} />
415
+ </button>
405
416
  <button
406
417
  className="btn-ghost icon-tooltip chat-theme-toggle"
407
418
  type="button"
@@ -1321,6 +1321,7 @@ export function MessageMenu() {
1321
1321
  const t = useT();
1322
1322
  const regenerateMessage = useStore((s) => s.regenerateMessage);
1323
1323
  const forkSession = useStore((s) => s.forkSession);
1324
+ const speakMessage = useStore((s) => s.speakMessage);
1324
1325
  const addToast = useStore((s) => s.addToast);
1325
1326
  const messages = useStore((s) => s.messages);
1326
1327
  const npcs = useStore((s) => s.npcs);
@@ -1415,6 +1416,13 @@ export function MessageMenu() {
1415
1416
  });
1416
1417
  },
1417
1418
  });
1419
+ if (msg.role === 'assistant') {
1420
+ actions.push({
1421
+ label: t('chat.readMsg'),
1422
+ icon: 'speaker',
1423
+ onClick: () => { void speakMessage(msg.content); },
1424
+ });
1425
+ }
1418
1426
  }
1419
1427
  if (msg.role === 'user' || msg.role === 'assistant') {
1420
1428
  actions.push({
@@ -2,7 +2,8 @@ import { memo, useRef, useState, type PointerEvent as ReactPointerEvent } from '
2
2
  import { useStore } from '../store/store';
3
3
  import { db, DEFAULT_GENERATION_SETTINGS } from '../db/database';
4
4
  import { type ThemeMode } from '../theme/theme';
5
- import { type ApiProvider, type AppLanguage, type ReasoningEffort, enabledModelIds, modelAliases } from '../types/models';
5
+ import { type ApiProvider, type AppLanguage, type ReasoningEffort, type VoiceProvider, type VoiceProviderKind, type VoiceId, enabledModelIds, modelAliases } from '../types/models';
6
+ import { VOICE_PROVIDER_OPTIONS, previewVoice } from '../core/voice';
6
7
  import { Icon, Modal } from './shared';
7
8
  import { DeleteConfirmDialog } from './DeleteConfirmDialog';
8
9
  import { isNetworkLikeError, toProxyUrl } from '../core/proxy';
@@ -21,6 +22,8 @@ export const SettingsView = memo(function SettingsView() {
21
22
  const resetTavern = useStore((s) => s.resetTavern);
22
23
  const providers = useStore((s) => s.providers);
23
24
  const refreshProviders = useStore((s) => s.refreshProviders);
25
+ const voiceProviders = useStore((s) => s.voiceProviders);
26
+ const refreshVoiceProviders = useStore((s) => s.refreshVoiceProviders);
24
27
  const [showResetConfirm, setShowResetConfirm] = useState(false);
25
28
  const [resetting, setResetting] = useState(false);
26
29
  const [showVersionHistory, setShowVersionHistory] = useState(false);
@@ -113,6 +116,7 @@ export const SettingsView = memo(function SettingsView() {
113
116
 
114
117
  {/* 模型服务 Provider(置顶) */}
115
118
  <ProviderManager providers={providers} onChanged={refreshProviders} />
119
+ <VoiceProviderManager providers={voiceProviders} onChanged={refreshVoiceProviders} />
116
120
 
117
121
  <div className="set-section">
118
122
  <h3>{t('settings.toolExecution')}</h3>
@@ -429,11 +433,164 @@ async function fetchModelsSmart(baseUrl: string, apiKey: string): Promise<Models
429
433
  throw lastErr ?? new Error('unknown-error');
430
434
  }
431
435
 
436
+ function ApiKeyField({ value, onChange, required = false }: { value: string; onChange: (value: string) => void; required?: boolean }) {
437
+ const t = useT();
438
+ const [visible, setVisible] = useState(false);
439
+
440
+ return (
441
+ <div className="field">
442
+ <label>{t('settings.apiKey')}</label>
443
+ <div className="password-input-wrap">
444
+ <input
445
+ className="input mono"
446
+ type={visible ? 'text' : 'password'}
447
+ required={required}
448
+ value={value}
449
+ onChange={(event) => onChange(event.target.value)}
450
+ placeholder={t('settings.apiKeyPh')}
451
+ />
452
+ <button
453
+ type="button"
454
+ className="password-visibility-btn"
455
+ onClick={() => setVisible((current) => !current)}
456
+ aria-label={t(visible ? 'settings.hideApiKey' : 'settings.showApiKey')}
457
+ title={t(visible ? 'settings.hideApiKey' : 'settings.showApiKey')}
458
+ >
459
+ <Icon name={visible ? 'eye-off' : 'eye'} size={16} />
460
+ </button>
461
+ </div>
462
+ </div>
463
+ );
464
+ }
465
+
466
+ function VoiceProviderManager({ providers, onChanged }: { providers: VoiceProvider[]; onChanged: () => void }) {
467
+ const settings = useStore((s) => s.settings)!;
468
+ const setSettings = useStore((s) => s.setSettings);
469
+ const addToast = useStore((s) => s.addToast);
470
+ const t = useT();
471
+ const [editing, setEditing] = useState<VoiceProvider | null>(null);
472
+ const [pendingDelete, setPendingDelete] = useState<VoiceProvider | null>(null);
473
+
474
+ const providerName = (kind: VoiceProviderKind) => t(`settings.voiceProviderKind.${kind}`);
475
+ const voiceLabel = (voiceId: VoiceId) => t(`settings.voiceLabel.${voiceId}`);
476
+
477
+ const saveProvider = async (provider: VoiceProvider) => {
478
+ if (provider.id != null) await db.voiceProviders.update(provider.id, provider);
479
+ else await db.voiceProviders.add(provider);
480
+ setEditing(null);
481
+ await onChanged();
482
+ addToast(t(provider.id != null ? 'toast.voiceProviderUpdated' : 'toast.voiceProviderAdded'));
483
+ };
484
+
485
+ return (
486
+ <div className="set-section">
487
+ <div className="settings-section-head">
488
+ <h3>{t('settings.voiceProviderTitle')}</h3>
489
+ <button className="btn btn-sm settings-gen-reset" onClick={() => setEditing({ kind: 'deepseek', apiKey: '', isEnabled: true, createdAt: Date.now() })}>
490
+ <Icon name="plus" size={13} /> {t('settings.addProvider')}
491
+ </button>
492
+ </div>
493
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
494
+ {providers.length === 0 && <div className="typo-body-sm text-muted">{t('settings.noVoiceProvider')}</div>}
495
+ {[...providers].sort((a, b) => b.createdAt - a.createdAt).map((provider) => {
496
+ const options = VOICE_PROVIDER_OPTIONS[provider.kind];
497
+ return (
498
+ <div key={provider.id} className={`provider-card ${provider.isEnabled ? '' : 'disabled'}`}>
499
+ <div className="p-head">
500
+ <label className="switch" title={provider.isEnabled ? t('settings.disable') : t('settings.enable')}>
501
+ <input type="checkbox" checked={provider.isEnabled} onChange={async () => { await db.voiceProviders.update(provider.id!, { isEnabled: !provider.isEnabled }); await onChanged(); }} />
502
+ <span className="switch-slider" />
503
+ </label>
504
+ <span className="p-name">{providerName(provider.kind)}</span>
505
+ <span className="p-status voice">{t('settings.voiceServiceTag')}</span>
506
+ <div style={{ marginLeft: 'auto', display: 'flex', gap: 6 }}>
507
+ <button className="btn btn-sm" onClick={() => setEditing(provider)}>{t('common.edit')}</button>
508
+ <button className="btn btn-sm btn-danger" onClick={() => setPendingDelete(provider)}><Icon name="trash" size={12} /></button>
509
+ </div>
510
+ </div>
511
+ <div className="provider-inline-detail"><b>{t('settings.voices')}:</b> {options.voices.map((voice) => voiceLabel(voice.id)).join(', ')}</div>
512
+ </div>
513
+ );
514
+ })}
515
+ </div>
516
+ <div className="voice-default-card">
517
+ <div>
518
+ <div className="s-label">{t('settings.defaultVoice')}</div>
519
+ <div className="s-desc">{t('settings.defaultVoiceDesc')}</div>
520
+ </div>
521
+ <select
522
+ className="select voice-default-select"
523
+ value={settings.activeVoiceProviderId != null && settings.activeVoiceId ? `${settings.activeVoiceProviderId}:${settings.activeVoiceId}` : ''}
524
+ onChange={(event) => {
525
+ const [providerId, voiceId] = event.target.value.split(':');
526
+ void setSettings(event.target.value
527
+ ? { activeVoiceProviderId: Number(providerId), activeVoiceId: voiceId as VoiceId }
528
+ : { activeVoiceProviderId: null, activeVoiceId: null });
529
+ }}
530
+ >
531
+ <option value="">{t('settings.noDefaultVoice')}</option>
532
+ {providers.filter((provider) => provider.isEnabled).flatMap((provider) => VOICE_PROVIDER_OPTIONS[provider.kind].voices.map((voice) => (
533
+ <option key={`${provider.id}:${voice.id}`} value={`${provider.id}:${voice.id}`}>
534
+ {providerName(provider.kind)} · {voiceLabel(voice.id)}
535
+ </option>
536
+ )))}
537
+ </select>
538
+ </div>
539
+ {editing && <Modal onClose={() => setEditing(null)}>
540
+ <div className="modal-head">
541
+ <span className="typo-dialog-title">{editing.id != null ? t('settings.editVoiceProvider') : t('settings.addVoiceProvider')}</span>
542
+ <button className="icon-btn" onClick={() => setEditing(null)}><Icon name="x" /></button>
543
+ </div>
544
+ <VoiceProviderForm initial={editing} onSave={saveProvider} />
545
+ </Modal>}
546
+ {pendingDelete && <DeleteConfirmDialog title={t('settings.deleteVoiceProvider')} itemName={providerName(pendingDelete.kind)} onCancel={() => setPendingDelete(null)} onConfirm={async () => {
547
+ await db.voiceProviders.delete(pendingDelete.id!);
548
+ if (settings.activeVoiceProviderId === pendingDelete.id) await setSettings({ activeVoiceProviderId: null, activeVoiceId: null });
549
+ setPendingDelete(null);
550
+ await onChanged();
551
+ }} />}
552
+ </div>
553
+ );
554
+ }
555
+
556
+ function VoiceProviderForm({ initial, onSave }: { initial: VoiceProvider; onSave: (provider: VoiceProvider) => void }) {
557
+ const addToast = useStore((s) => s.addToast);
558
+ const t = useT();
559
+ const [kind, setKind] = useState<VoiceProviderKind>(initial.kind);
560
+ const [apiKey, setApiKey] = useState(initial.apiKey);
561
+ const [previewingVoiceId, setPreviewingVoiceId] = useState<VoiceId | null>(null);
562
+ const voices = VOICE_PROVIDER_OPTIONS[kind].voices;
563
+
564
+ const preview = async (voiceId: VoiceId) => {
565
+ setPreviewingVoiceId(voiceId);
566
+ try {
567
+ await previewVoice(kind, apiKey, voiceId, t('settings.voicePreviewText'));
568
+ addToast(t('toast.voicePreviewPlaying'));
569
+ } catch (error) {
570
+ addToast(t('toast.voiceFailed', { msg: error instanceof Error ? error.message : String(error) }), 'error');
571
+ } finally {
572
+ setPreviewingVoiceId(null);
573
+ }
574
+ };
575
+
576
+ return <>
577
+ <div className="modal-body" style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
578
+ <div className="field"><label>{t('settings.voiceProvider')}</label><select className="select" value={kind} disabled={initial.id != null} onChange={(event) => setKind(event.target.value as VoiceProviderKind)}><option value="deepseek">{t('settings.voiceProviderKind.deepseek')}</option><option value="bailian">{t('settings.voiceProviderKind.bailian')}</option></select></div>
579
+ <ApiKeyField value={apiKey} onChange={setApiKey} required />
580
+ <div className="field"><label>{t('settings.voices')}</label><div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>{voices.map((voice) => <div key={voice.id} className="provider-voice-option"><span><b>{voice.id}</b><br /><span className="text-muted">{t(`settings.voiceLabel.${voice.id}`)}</span></span><button type="button" className="icon-btn provider-voice-preview" disabled={!apiKey.trim() || previewingVoiceId != null} title={t('settings.previewVoice')} aria-label={`${t('settings.previewVoice')}: ${t(`settings.voiceLabel.${voice.id}`)}`} onClick={() => void preview(voice.id)}>{previewingVoiceId === voice.id ? <span className="spinner" /> : <Icon name="speaker" size={17} />}</button></div>)}</div></div>
581
+ </div>
582
+ <div className="modal-foot">
583
+ <button className="btn btn-primary" disabled={!apiKey.trim()} onClick={() => onSave({ ...initial, kind, apiKey: apiKey.trim(), isEnabled: true })}>{t('common.save')}</button>
584
+ </div>
585
+ </>;
586
+ }
587
+
432
588
  function ProviderManager({ providers, onChanged }: { providers: ApiProvider[]; onChanged: () => void }) {
433
589
  const addToast = useStore((s) => s.addToast);
434
590
  const t = useT();
435
591
  const [editing, setEditing] = useState<ApiProvider | null>(null);
436
592
  const [pendingDelete, setPendingDelete] = useState<ApiProvider | null>(null);
593
+ const orderedProviders = [...providers].sort((a, b) => b.createdAt - a.createdAt);
437
594
 
438
595
  const toggleEnabled = async (p: ApiProvider) => {
439
596
  await db.providers.update(p.id!, { isEnabled: !p.isEnabled });
@@ -449,10 +606,18 @@ function ProviderManager({ providers, onChanged }: { providers: ApiProvider[]; o
449
606
 
450
607
  return (
451
608
  <div className="set-section">
452
- <h3>{t('settings.providerTitle')}</h3>
609
+ <div className="settings-section-head">
610
+ <h3>{t('settings.providerTitle')}</h3>
611
+ <button
612
+ className="btn btn-sm settings-gen-reset"
613
+ onClick={() => setEditing({ name: '', baseUrl: '', apiKey: '', isEnabled: true, cachedModelsCsv: '', modelAliasesJson: '{}', createdAt: Date.now() })}
614
+ >
615
+ <Icon name="plus" size={13} /> {t('settings.addProvider')}
616
+ </button>
617
+ </div>
453
618
  <div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
454
619
  {providers.length === 0 && <div className="typo-body-sm text-muted">{t('settings.noProvider')}</div>}
455
- {providers.map((p) => {
620
+ {orderedProviders.map((p) => {
456
621
  const aliases = modelAliases(p);
457
622
  const enabledModels = enabledModelIds(p);
458
623
  const visibleModels = p.cachedModelsCsv.split(',').map((model) => model.trim()).filter((model) => enabledModels.has(model));
@@ -466,7 +631,7 @@ function ProviderManager({ providers, onChanged }: { providers: ApiProvider[]; o
466
631
  <span className="switch-slider" />
467
632
  </label>
468
633
  <span className="p-name">{p.name}</span>
469
- <span className={`p-status ${p.isEnabled ? 'on' : 'off'}`}>{p.isEnabled ? t('settings.enable') : t('settings.disable')}</span>
634
+ <span className="p-status text">{t('settings.textServiceTag')}</span>
470
635
  <div style={{ marginLeft: 'auto', display: 'flex', gap: 6 }}>
471
636
  <button className="btn btn-sm" onClick={() => setEditing(p)}>{t('common.edit')}</button>
472
637
  <button className="btn btn-sm btn-danger" onClick={() => setPendingDelete(p)}><Icon name="trash" size={12} /></button>
@@ -483,9 +648,6 @@ function ProviderManager({ providers, onChanged }: { providers: ApiProvider[]; o
483
648
  </div>
484
649
  );
485
650
  })}
486
- <button className="btn" style={{ alignSelf: 'flex-start' }} onClick={() => setEditing({ name: '', baseUrl: '', apiKey: '', isEnabled: true, cachedModelsCsv: '', modelAliasesJson: '{}', createdAt: Date.now() })}>
487
- <Icon name="plus" size={13} /> {t('settings.addProvider')}
488
- </button>
489
651
  </div>
490
652
 
491
653
  {editing && (
@@ -565,10 +727,7 @@ function ProviderForm({ initial, onSave }: { initial: ApiProvider; onSave: (p: A
565
727
  <label>{t('settings.baseUrl')}</label>
566
728
  <input className="input mono" value={baseUrl} onChange={(e) => setBaseUrl(e.target.value)} placeholder={t('settings.baseUrlPh')} />
567
729
  </div>
568
- <div className="field">
569
- <label>{t('settings.apiKey')}</label>
570
- <input className="input mono" type="password" value={apiKey} onChange={(e) => setApiKey(e.target.value)} placeholder={t('settings.apiKeyPh')} />
571
- </div>
730
+ <ApiKeyField value={apiKey} onChange={setApiKey} />
572
731
  {models.length > 0 && (
573
732
  <div className="field">
574
733
  <label>{t('settings.models')}</label>
@@ -418,10 +418,14 @@ const ICONS: Record<string, React.ReactNode> = {
418
418
  'pip-exit': <><rect x="3" y="5" width="18" height="14" rx="2" /><path d="m14 14 5-5M15 9h4v4" /></>,
419
419
  'text-wrap': <><path d="M4 6h13a4 4 0 0 1 0 8H9" /><path d="m12 11-3 3 3 3M4 18h3" /></>,
420
420
  eye: <><path d="M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7-10-7-10-7z" /><circle cx="12" cy="12" r="3" /></>,
421
+ 'eye-off': <><path d="m3 3 18 18" /><path d="M10.6 5.2A11.8 11.8 0 0 1 12 5c6.5 0 10 7 10 7a17.7 17.7 0 0 1-2.1 3.1M6.6 6.6C3.7 8.4 2 12 2 12s3.5 7 10 7a10.7 10.7 0 0 0 4.1-.8" /><path d="M9.9 9.9a3 3 0 0 0 4.2 4.2" /></>,
422
+ speaker: <><path d="M11 5 6 9H2v6h4l5 4V5z" /><path d="M15.5 8.5a5 5 0 0 1 0 7M18.5 5.5a9 9 0 0 1 0 13" /></>,
423
+ 'speaker-off': <><path d="M11 5 6 9H2v6h4l5 4V5z" /><path d="m16 9 5 5M21 9l-5 5" /></>,
421
424
  sun: <><circle cx="12" cy="12" r="4" /><path d="M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M4.93 19.07l1.41-1.41M17.66 6.34l1.41-1.41" /></>,
422
425
  moon: <path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z" />,
423
426
  folder: <><path d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z" /></>,
424
427
  copy: <><rect x="8" y="8" width="13" height="13" rx="2" /><path d="M5 16V6a2 2 0 0 1 2-2h10" /></>,
428
+ play: <><path d="M6 4l14 8-14 8z" /></>,
425
429
  };
426
430
 
427
431
  export function Icon({ name, size = 15 }: { name: string; size?: number }) {
package/src/core/i18n.ts CHANGED
@@ -95,6 +95,8 @@ const MESSAGES: Record<LangKey, Record<string, string>> = {
95
95
  'header.deleteConfirm': '确定删除对话「{title}」?该操作不可恢复。',
96
96
  'header.switchToLightTip': '切换到浅色模式',
97
97
  'header.switchToDarkTip': '切换到深色模式',
98
+ 'header.enableAutoVoice': '开启自动朗读',
99
+ 'header.disableAutoVoice': '关闭自动朗读',
98
100
  'header.workspaceHint': '本对话的专属工作目录。文件工具限制在该目录内;本地命令以此为起始目录,但不具备 OS 隔离。点击可浏览目录文件(只读)。',
99
101
  'header.workspaceRootHint': '酒馆老板的单人对话固定使用公共工作目录。文件工具限制在该目录内;本地命令不具备 OS 隔离。点击可浏览文件(只读)。',
100
102
  'header.fileManagerTitle': '工作区文件',
@@ -129,6 +131,7 @@ const MESSAGES: Record<LangKey, Record<string, string>> = {
129
131
  'chat.thinking': '思考',
130
132
  'chat.editMsg': '编辑消息',
131
133
  'chat.copyMsg': '复制消息',
134
+ 'chat.readMsg': '朗读消息',
132
135
  'chat.addAttachment': '添加附件',
133
136
  'chat.saveHint': '⌘/Ctrl+Enter 保存 · Esc 取消',
134
137
  'chat.saveRegenerate': '保存并发送',
@@ -152,7 +155,7 @@ const MESSAGES: Record<LangKey, Record<string, string>> = {
152
155
  'chat.nsfwPendingMarker': '演出指导将在下一条消息中注入',
153
156
  'chat.cmdPass': '跳过本轮发言(群聊中,不修改对话历史)',
154
157
  'chat.cmdNsfw': '强制注入一轮演出指导(强控模型行为)',
155
- 'chat.modelEmpty': '暂无可用模型列表。请先在「设置 → 模型服务 Provider」添加并测试连接。',
158
+ 'chat.modelEmpty': '暂无可用模型列表。请先在「设置 → 模型服务供应商」添加并测试连接。',
156
159
  'chat.noActions': '该消息无可用操作',
157
160
  'chat.regenerate': '重新生成回复',
158
161
  'chat.viewRaw': '查看原始日志',
@@ -255,8 +258,33 @@ const MESSAGES: Record<LangKey, Record<string, string>> = {
255
258
  'builtinNpc.prompt': '神秘的酒馆老板,可以响应客人的任何需求',
256
259
  'builtinNpc.greeting': '你来啦!快坐下~',
257
260
  'builtinWorldbook.name': '酒馆经营手册(精华版)',
258
- 'settings.providerTitle': '🔌 模型服务 Provider',
259
- 'settings.noProvider': '还没有配置 Provider,点击下方按钮添加',
261
+ 'settings.providerTitle': '🔌 模型服务供应商',
262
+ 'settings.voiceProviderTitle': '🔊 语音服务供应商',
263
+ 'settings.noVoiceProvider': '尚未添加语音供应商',
264
+ 'settings.voiceProvider': '供应商',
265
+ 'settings.addVoiceProvider': '添加语音供应商',
266
+ 'settings.editVoiceProvider': '编辑语音供应商',
267
+ 'settings.deleteVoiceProvider': '删除语音供应商',
268
+ 'settings.voiceProviderKind.deepseek': 'DeepSeek',
269
+ 'settings.voiceProviderKind.bailian': '百炼 Token Plan',
270
+ 'settings.voices': '可用音色',
271
+ 'settings.narrationVoice': '音色',
272
+ 'settings.defaultVoice': '默认音色',
273
+ 'settings.defaultVoiceDesc': '用于自动朗读',
274
+ 'settings.noDefaultVoice': '未选择默认音色',
275
+ 'settings.voiceLabel.stella': '海星 · 女声',
276
+ 'settings.voiceLabel.tide': '暗潮 · 男声',
277
+ 'settings.voiceLabel.longanlingxin': '龙安灵心',
278
+ 'settings.voiceLabel.longanlufeng': '龙安陆风',
279
+ 'settings.activeVoice': '当前旁白',
280
+ 'settings.inactiveVoice': '未选中',
281
+ 'settings.voiceServiceTag': '语音',
282
+ 'settings.textServiceTag': '文本',
283
+ 'settings.showApiKey': '显示 API Key',
284
+ 'settings.hideApiKey': '隐藏 API Key',
285
+ 'settings.previewVoice': '试听',
286
+ 'settings.voicePreviewText': '你好,欢迎来到酒馆。',
287
+ 'settings.noProvider': '还没有配置供应商,点击下方按钮添加',
260
288
  'settings.enable': '启用',
261
289
  'settings.disable': '停用',
262
290
  'settings.testing': '测试中',
@@ -265,9 +293,9 @@ const MESSAGES: Record<LangKey, Record<string, string>> = {
265
293
  'settings.emptyModels': '空',
266
294
  'settings.modelAlias': '展示别名',
267
295
  'settings.modelAliasPh': '留空则显示原模型名',
268
- 'settings.addProvider': '添加 Provider',
269
- 'settings.editProvider': '编辑 Provider',
270
- 'settings.deleteProvider': '删除 Provider',
296
+ 'settings.addProvider': '添加供应商',
297
+ 'settings.editProvider': '编辑供应商',
298
+ 'settings.deleteProvider': '删除供应商',
271
299
  'settings.providerName': '名称',
272
300
  'settings.providerNamePh': '如:DeepSeek 官方',
273
301
  'settings.baseUrl': 'Base URL',
@@ -466,7 +494,7 @@ const MESSAGES: Record<LangKey, Record<string, string>> = {
466
494
  'toast.passOnlyGroup': '/pass 仅在群聊中有效',
467
495
  'toast.nsfwDisabled': '请先在设置中开启 NSFW 模式',
468
496
  'toast.mentionRequired': '仅 @ 模式下,请先 @ 一位角色再发送消息',
469
- 'toast.noEndpoint': '请在「模型服务 Provider」中添加并启用一个端点,并选择模型',
497
+ 'toast.noEndpoint': '请在「模型服务供应商」中添加并启用一个端点,并选择模型',
470
498
  'toast.genFailed': '生成失败: {msg}',
471
499
  'toast.emptyModelResponse': '模型未返回内容。请确认所选模型可用后重试。',
472
500
  'chat.interrupted': '生成已中断,已保留部分内容。',
@@ -501,9 +529,14 @@ const MESSAGES: Record<LangKey, Record<string, string>> = {
501
529
  'toast.providerViaProxy': '(经本地代理转发)',
502
530
  'toast.providerFail': '❌ 连接失败: {msg}{hint}',
503
531
  'toast.providerFailCors': '。疑似 CORS 跨域被拦截(目标服务未开放 CORS 头,已自动尝试内置代理失败)',
504
- 'toast.providerDeleted': '已删除 Provider',
505
- 'toast.providerUpdated': '已更新 Provider',
506
- 'toast.providerAdded': '已添加 Provider',
532
+ 'toast.providerDeleted': '已删除供应商',
533
+ 'toast.providerUpdated': '已更新供应商',
534
+ 'toast.providerAdded': '已添加供应商',
535
+ 'toast.voiceProviderAdded': '已添加语音供应商',
536
+ 'toast.voiceProviderUpdated': '已更新语音供应商',
537
+ 'toast.voicePreviewPlaying': '正在播放试听',
538
+ 'toast.voiceNotConfigured': '请先在设置中选择旁白音色',
539
+ 'toast.voiceFailed': '语音播放失败:{msg}',
507
540
  'toast.providerDuplicateModel': '模型「{model}」存在同名模型,请设置别名后再保存。',
508
541
  'toast.statsReset': '统计已重置',
509
542
  'toast.canceled': 'CANCELLED: 用户取消了 {name}',
@@ -636,6 +669,8 @@ const MESSAGES: Record<LangKey, Record<string, string>> = {
636
669
  'header.deleteConfirm': '確定刪除對話「{title}」?此操作無法復原。',
637
670
  'header.switchToLightTip': '切換到淺色模式',
638
671
  'header.switchToDarkTip': '切換到深色模式',
672
+ 'header.enableAutoVoice': '開啟自動朗讀',
673
+ 'header.disableAutoVoice': '關閉自動朗讀',
639
674
  'header.workspaceHint': '本對話的專屬工作目錄。檔案工具限制在該目錄內;本地指令以此為起始目錄,但不具備 OS 隔離。點擊可瀏覽目錄檔案(唯讀)。',
640
675
  'header.workspaceRootHint': '酒館老闆的單人對話固定使用公共工作目錄。檔案工具限制在該目錄內;本地指令不具備 OS 隔離。點擊可瀏覽檔案(唯讀)。',
641
676
  'header.fileManagerTitle': '工作區檔案',
@@ -669,6 +704,7 @@ const MESSAGES: Record<LangKey, Record<string, string>> = {
669
704
  'chat.thinking': '思考',
670
705
  'chat.editMsg': '編輯訊息',
671
706
  'chat.copyMsg': '複製訊息',
707
+ 'chat.readMsg': '朗讀訊息',
672
708
  'chat.addAttachment': '新增附件',
673
709
  'chat.saveHint': '⌘/Ctrl+Enter 儲存 · Esc 取消',
674
710
  'chat.saveRegenerate': '儲存並傳送',
@@ -692,7 +728,7 @@ const MESSAGES: Record<LangKey, Record<string, string>> = {
692
728
  'chat.nsfwPendingMarker': '演出指導將在下一則訊息中注入',
693
729
  'chat.cmdPass': '跳過本輪發言(群聊中,不修改對話歷史)',
694
730
  'chat.cmdNsfw': '強制注入一輪演出指導(強控模型行為)',
695
- 'chat.modelEmpty': '暫無可用模型清單。請先在「設定 → 模型服務 Provider」新增並測試連線。',
731
+ 'chat.modelEmpty': '暫無可用模型清單。請先在「設定 → 模型服務供應商」新增並測試連線。',
696
732
  'chat.noActions': '此訊息沒有可用的操作',
697
733
  'chat.regenerate': '重新產生回覆',
698
734
  'chat.viewRaw': '檢視原始日誌',
@@ -793,8 +829,33 @@ const MESSAGES: Record<LangKey, Record<string, string>> = {
793
829
  'builtinNpc.prompt': '神秘的酒館老闆,可以回應客人的任何需求',
794
830
  'builtinNpc.greeting': '你來啦!快坐下~',
795
831
  'builtinWorldbook.name': '酒館經營手冊(精華版)',
796
- 'settings.providerTitle': '🔌 模型服務 Provider',
797
- 'settings.noProvider': '還沒有設定 Provider,點擊下方按鈕新增',
832
+ 'settings.providerTitle': '🔌 模型服務供應商',
833
+ 'settings.voiceProviderTitle': '🔊 語音服務供應商',
834
+ 'settings.noVoiceProvider': '尚未新增語音供應商',
835
+ 'settings.voiceProvider': '供應商',
836
+ 'settings.addVoiceProvider': '新增語音供應商',
837
+ 'settings.editVoiceProvider': '編輯語音供應商',
838
+ 'settings.deleteVoiceProvider': '刪除語音供應商',
839
+ 'settings.voiceProviderKind.deepseek': 'DeepSeek',
840
+ 'settings.voiceProviderKind.bailian': '百煉 Token Plan',
841
+ 'settings.voices': '可用音色',
842
+ 'settings.narrationVoice': '音色',
843
+ 'settings.defaultVoice': '預設音色',
844
+ 'settings.defaultVoiceDesc': '用於自動朗讀',
845
+ 'settings.noDefaultVoice': '未選擇預設音色',
846
+ 'settings.voiceLabel.stella': '海星 · 女聲',
847
+ 'settings.voiceLabel.tide': '暗潮 · 男聲',
848
+ 'settings.voiceLabel.longanlingxin': '龍安靈心',
849
+ 'settings.voiceLabel.longanlufeng': '龍安陸風',
850
+ 'settings.activeVoice': '目前旁白',
851
+ 'settings.inactiveVoice': '未選取',
852
+ 'settings.voiceServiceTag': '語音',
853
+ 'settings.textServiceTag': '文字',
854
+ 'settings.showApiKey': '顯示 API Key',
855
+ 'settings.hideApiKey': '隱藏 API Key',
856
+ 'settings.previewVoice': '試聽',
857
+ 'settings.voicePreviewText': '你好,歡迎來到酒館。',
858
+ 'settings.noProvider': '還沒有設定供應商,點擊下方按鈕新增',
798
859
  'settings.enable': '啟用',
799
860
  'settings.disable': '停用',
800
861
  'settings.testing': '測試中',
@@ -803,9 +864,9 @@ const MESSAGES: Record<LangKey, Record<string, string>> = {
803
864
  'settings.emptyModels': '空',
804
865
  'settings.modelAlias': '顯示別名',
805
866
  'settings.modelAliasPh': '留空則顯示原模型名稱',
806
- 'settings.addProvider': '新增 Provider',
807
- 'settings.editProvider': '編輯 Provider',
808
- 'settings.deleteProvider': '刪除 Provider',
867
+ 'settings.addProvider': '新增供應商',
868
+ 'settings.editProvider': '編輯供應商',
869
+ 'settings.deleteProvider': '刪除供應商',
809
870
  'settings.providerName': '名稱',
810
871
  'settings.providerNamePh': '如:DeepSeek 官方',
811
872
  'settings.baseUrl': 'Base URL',
@@ -997,7 +1058,7 @@ const MESSAGES: Record<LangKey, Record<string, string>> = {
997
1058
  'toast.passOnlyGroup': '/pass 僅在群聊中有效',
998
1059
  'toast.nsfwDisabled': '請先在設定中開啟 NSFW 模式',
999
1060
  'toast.mentionRequired': '僅 @ 模式下,請先 @ 一位角色再傳送訊息',
1000
- 'toast.noEndpoint': '請在「模型服務 Provider」中新增並啟用一個端點,並選擇模型',
1061
+ 'toast.noEndpoint': '請在「模型服務供應商」中新增並啟用一個端點,並選擇模型',
1001
1062
  'toast.genFailed': '產生失敗: {msg}',
1002
1063
  'toast.emptyModelResponse': '模型未回傳內容。請確認所選模型可用後重試。',
1003
1064
  'chat.interrupted': '產生已中斷,已保留部分內容。',
@@ -1032,9 +1093,14 @@ const MESSAGES: Record<LangKey, Record<string, string>> = {
1032
1093
  'toast.providerViaProxy': '(經本地代理轉發)',
1033
1094
  'toast.providerFail': '❌ 連線失敗: {msg}{hint}',
1034
1095
  'toast.providerFailCors': '。疑似 CORS 跨域被封鎖(目標服務未開放 CORS 頭,已自動嘗試內建代理失敗)',
1035
- 'toast.providerDeleted': '已刪除 Provider',
1036
- 'toast.providerUpdated': '已更新 Provider',
1037
- 'toast.providerAdded': '已新增 Provider',
1096
+ 'toast.providerDeleted': '已刪除供應商',
1097
+ 'toast.providerUpdated': '已更新供應商',
1098
+ 'toast.providerAdded': '已新增供應商',
1099
+ 'toast.voiceProviderAdded': '已新增語音供應商',
1100
+ 'toast.voiceProviderUpdated': '已更新語音供應商',
1101
+ 'toast.voicePreviewPlaying': '正在播放試聽',
1102
+ 'toast.voiceNotConfigured': '請先在設定中選擇旁白音色',
1103
+ 'toast.voiceFailed': '語音播放失敗:{msg}',
1038
1104
  'toast.providerDuplicateModel': '模型「{model}」存在同名模型,請設定別名後再儲存。',
1039
1105
  'toast.statsReset': '統計已重置',
1040
1106
  'toast.canceled': 'CANCELLED: 使用者取消了 {name}',
@@ -1165,6 +1231,8 @@ const MESSAGES: Record<LangKey, Record<string, string>> = {
1165
1231
  'header.deleteConfirm': 'Delete conversation "{title}"? This cannot be undone.',
1166
1232
  'header.switchToLightTip': 'Switch to light mode',
1167
1233
  'header.switchToDarkTip': 'Switch to dark mode',
1234
+ 'header.enableAutoVoice': 'Enable automatic reading',
1235
+ 'header.disableAutoVoice': 'Disable automatic reading',
1168
1236
  'header.workspaceHint': 'This conversation\'s private workspace. File tools are restricted to it; local commands start here but are not OS-isolated. Click to browse its files (read-only).',
1169
1237
  'header.workspaceRootHint': 'A one-on-one conversation with the Tavern Keeper always uses the public workspace. File tools are restricted to it; local commands are not OS-isolated. Click to browse files (read-only).',
1170
1238
  'header.fileManagerTitle': 'Workspace files',
@@ -1198,6 +1266,7 @@ const MESSAGES: Record<LangKey, Record<string, string>> = {
1198
1266
  'chat.thinking': 'Thinking',
1199
1267
  'chat.editMsg': 'Edit message',
1200
1268
  'chat.copyMsg': 'Copy message',
1269
+ 'chat.readMsg': 'Read message aloud',
1201
1270
  'chat.addAttachment': 'Add attachment',
1202
1271
  'chat.saveHint': '⌘/Ctrl+Enter to save · Esc to cancel',
1203
1272
  'chat.saveRegenerate': 'Save & send',
@@ -1323,6 +1392,31 @@ const MESSAGES: Record<LangKey, Record<string, string>> = {
1323
1392
  'builtinNpc.greeting': 'Welcome! Have a seat~',
1324
1393
  'builtinWorldbook.name': 'Tavern Management Handbook (Essentials)',
1325
1394
  'settings.providerTitle': '🔌 Model Providers',
1395
+ 'settings.voiceProviderTitle': '🔊 Voice Service Providers',
1396
+ 'settings.noVoiceProvider': 'No voice provider added',
1397
+ 'settings.voiceProvider': 'Provider',
1398
+ 'settings.addVoiceProvider': 'Add voice provider',
1399
+ 'settings.editVoiceProvider': 'Edit voice provider',
1400
+ 'settings.deleteVoiceProvider': 'Delete voice provider',
1401
+ 'settings.voiceProviderKind.deepseek': 'DeepSeek',
1402
+ 'settings.voiceProviderKind.bailian': 'Bailian Token Plan',
1403
+ 'settings.voices': 'Available voices',
1404
+ 'settings.narrationVoice': 'Voice',
1405
+ 'settings.defaultVoice': 'Default voice',
1406
+ 'settings.defaultVoiceDesc': 'Used for automatic reading',
1407
+ 'settings.noDefaultVoice': 'No default voice selected',
1408
+ 'settings.voiceLabel.stella': 'Stella · Female',
1409
+ 'settings.voiceLabel.tide': 'Tide · Male',
1410
+ 'settings.voiceLabel.longanlingxin': 'Longan Lingxin',
1411
+ 'settings.voiceLabel.longanlufeng': 'Longan Lufeng',
1412
+ 'settings.activeVoice': 'Active narration',
1413
+ 'settings.inactiveVoice': 'Not selected',
1414
+ 'settings.voiceServiceTag': 'Voice',
1415
+ 'settings.textServiceTag': 'Text',
1416
+ 'settings.showApiKey': 'Show API key',
1417
+ 'settings.hideApiKey': 'Hide API key',
1418
+ 'settings.previewVoice': 'Preview',
1419
+ 'settings.voicePreviewText': 'Hello, welcome to the tavern.',
1326
1420
  'settings.noProvider': 'No providers configured yet — add one below',
1327
1421
  'settings.enable': 'Enabled',
1328
1422
  'settings.disable': 'Disabled',
@@ -1564,6 +1658,11 @@ const MESSAGES: Record<LangKey, Record<string, string>> = {
1564
1658
  'toast.providerDeleted': 'Provider deleted',
1565
1659
  'toast.providerUpdated': 'Provider updated',
1566
1660
  'toast.providerAdded': 'Provider added',
1661
+ 'toast.voiceProviderAdded': 'Voice provider added',
1662
+ 'toast.voiceProviderUpdated': 'Voice provider updated',
1663
+ 'toast.voicePreviewPlaying': 'Playing voice preview',
1664
+ 'toast.voiceNotConfigured': 'Select a narration voice in Settings first',
1665
+ 'toast.voiceFailed': 'Voice playback failed: {msg}',
1567
1666
  'toast.providerDuplicateModel': 'A model named "{model}" already exists. Set an alias before saving.',
1568
1667
  'toast.statsReset': 'Stats reset',
1569
1668
  'toast.canceled': 'CANCELLED: user canceled {name}',
@@ -0,0 +1,77 @@
1
+ import type { VoiceProvider, VoiceProviderKind, VoiceId } from '../types/models';
2
+
3
+ export const VOICE_PROVIDER_OPTIONS: Record<VoiceProviderKind, {
4
+ name: string;
5
+ voices: ReadonlyArray<{ id: VoiceId; label: string }>;
6
+ }> = {
7
+ deepseek: {
8
+ name: 'Deepseek',
9
+ voices: [
10
+ { id: 'stella', label: '海星 · 女声' },
11
+ { id: 'tide', label: '暗潮 · 男声' },
12
+ ],
13
+ },
14
+ bailian: {
15
+ name: '百炼 Token Plan',
16
+ voices: [
17
+ { id: 'longanlingxin', label: '龙安灵心' },
18
+ { id: 'longanlufeng', label: '龙安陆风' },
19
+ ],
20
+ },
21
+ };
22
+
23
+ export function isVoiceAllowed(kind: VoiceProviderKind, voiceId: string): voiceId is VoiceId {
24
+ return VOICE_PROVIDER_OPTIONS[kind].voices.some((voice) => voice.id === voiceId);
25
+ }
26
+
27
+ export function activeVoiceProvider(
28
+ providers: VoiceProvider[],
29
+ providerId: number | null | undefined,
30
+ voiceId: string | null | undefined,
31
+ ): VoiceProvider | null {
32
+ const provider = providers.find((item) => item.id === providerId && item.isEnabled);
33
+ return provider && voiceId && isVoiceAllowed(provider.kind, voiceId) ? provider : null;
34
+ }
35
+
36
+ let currentAudio: HTMLAudioElement | null = null;
37
+ let currentObjectUrl: string | null = null;
38
+
39
+ async function playVoiceRequest(path: string, body: Record<string, unknown>): Promise<void> {
40
+ currentAudio?.pause();
41
+ if (currentObjectUrl) URL.revokeObjectURL(currentObjectUrl);
42
+
43
+ const response = await fetch(path, {
44
+ method: 'POST',
45
+ headers: { 'Content-Type': 'application/json' },
46
+ body: JSON.stringify(body),
47
+ });
48
+ if (!response.ok) {
49
+ const payload = await response.json().catch(() => null) as { message?: string } | null;
50
+ throw new Error(payload?.message || `语音合成失败(HTTP ${response.status})`);
51
+ }
52
+ const blob = await response.blob();
53
+ if (!blob.size) throw new Error('语音服务返回了空音频');
54
+ currentObjectUrl = URL.createObjectURL(blob);
55
+ currentAudio = new Audio(currentObjectUrl);
56
+ currentAudio.addEventListener('ended', () => {
57
+ if (currentObjectUrl) URL.revokeObjectURL(currentObjectUrl);
58
+ currentObjectUrl = null;
59
+ currentAudio = null;
60
+ }, { once: true });
61
+ await currentAudio.play();
62
+ }
63
+
64
+ export async function speakText(providerId: number, voiceId: VoiceId, text: string): Promise<void> {
65
+ const content = text.trim();
66
+ if (!content) throw new Error('没有可朗读的文本');
67
+ await playVoiceRequest('/api-v3/voice/synthesize', { providerId, voiceId, text: content });
68
+ }
69
+
70
+ export async function previewVoice(kind: VoiceProviderKind, apiKey: string, voiceId: VoiceId, text: string): Promise<void> {
71
+ const content = text.trim();
72
+ const key = apiKey.trim();
73
+ if (!content) throw new Error('没有可朗读的文本');
74
+ if (!key) throw new Error('API Key 不能为空');
75
+ if (!isVoiceAllowed(kind, voiceId)) throw new Error('该 Provider 不支持所选音色');
76
+ await playVoiceRequest('/api-v3/voice/preview', { kind, apiKey: key, voiceId, text: content });
77
+ }
@@ -2,6 +2,7 @@ import Dexie, { type Table } from 'dexie';
2
2
  import type {
3
3
  ApiProvider,
4
4
  AppSettings,
5
+ VoiceProvider,
5
6
  AchievementUnlock,
6
7
  CareerNpcStat,
7
8
  CareerStatsTotal,
@@ -245,7 +246,7 @@ export class TavernDB extends Dexie {
245
246
  }
246
247
 
247
248
  const COLLECTIONS = [
248
- 'settings', 'providers', 'npcs', 'sessions', 'participants', 'messages',
249
+ 'settings', 'providers', 'voiceProviders', 'npcs', 'sessions', 'participants', 'messages',
249
250
  'contextCompressions', 'tools', 'worldBooks', 'careerStats', 'careerNpcStats', 'achievementUnlocks',
250
251
  ] as const;
251
252
 
@@ -352,6 +353,7 @@ type StartupSnapshot = {
352
353
  collections: {
353
354
  settings: Array<{ value: AppSettings }>;
354
355
  providers: Array<{ value: ApiProvider }>;
356
+ voiceProviders: Array<{ value: VoiceProvider }>;
355
357
  npcs: Array<{ value: NpcCharacter }>;
356
358
  sessions: Array<{ value: ChatSession }>;
357
359
  worldBooks: Array<{ value: WorldBook }>;
@@ -371,9 +373,10 @@ export async function loadStartupSnapshot(): Promise<StartupSnapshot> {
371
373
  if (!(error instanceof Error) || !error.message.includes('Unknown persistence endpoint: /startup/snapshot')) throw error;
372
374
  await initDatabase();
373
375
  const readOnly = await isWriteLocked();
374
- const [settings, providers, npcs, sessions, worldBooks, tools, achievementUnlocks] = await Promise.all([
376
+ const [settings, providers, voiceProviders, npcs, sessions, worldBooks, tools, achievementUnlocks] = await Promise.all([
375
377
  db.settings.toArray(),
376
378
  db.providers.toArray(),
379
+ db.voiceProviders.toArray(),
377
380
  db.npcs.toArray(),
378
381
  db.sessions.toArray(),
379
382
  db.worldBooks.toArray(),
@@ -385,6 +388,7 @@ export async function loadStartupSnapshot(): Promise<StartupSnapshot> {
385
388
  collections: {
386
389
  settings: settings.map((value) => ({ value })),
387
390
  providers: providers.map((value) => ({ value })),
391
+ voiceProviders: voiceProviders.map((value) => ({ value })),
388
392
  npcs: npcs.map((value) => ({ value })),
389
393
  sessions: sessions.map((value) => ({ value })),
390
394
  worldBooks: worldBooks.map((value) => ({ value })),
@@ -522,7 +526,7 @@ class RemoteTable<T extends object> {
522
526
  async add(value: T): Promise<number> {
523
527
  await requireWriteLock();
524
528
  const record = { ...value } as T & { id?: number };
525
- if (['providers', 'npcs', 'sessions', 'messages', 'contextCompressions', 'tools', 'worldBooks', 'achievementUnlocks'].includes(this.collection) && record.id == null) {
529
+ if (['providers', 'voiceProviders', 'npcs', 'sessions', 'messages', 'contextCompressions', 'tools', 'worldBooks', 'achievementUnlocks'].includes(this.collection) && record.id == null) {
526
530
  const result = await persistenceRequest<{ id: number }>('/records/allocate-id', { collection: this.collection });
527
531
  record.id = result.id;
528
532
  }
@@ -568,6 +572,7 @@ class RemoteTable<T extends object> {
568
572
  class RemoteTavernDB {
569
573
  settings = new RemoteTable<AppSettings>('settings');
570
574
  providers = new RemoteTable<ApiProvider>('providers');
575
+ voiceProviders = new RemoteTable<VoiceProvider>('voiceProviders');
571
576
  npcs = new RemoteTable<NpcCharacter>('npcs');
572
577
  sessions = new RemoteTable<ChatSession>('sessions');
573
578
  participants = new RemoteTable<ChatParticipant>('participants');
@@ -593,7 +598,7 @@ class RemoteTavernDB {
593
598
  return (args.at(-1) as () => Promise<T>)();
594
599
  }
595
600
  async delete(): Promise<void> {
596
- for (const table of [this.settings, this.providers, this.npcs, this.sessions, this.participants, this.messages, this.contextCompressions, this.tools, this.worldBooks, this.careerStats, this.careerNpcStats, this.achievementUnlocks]) await table.clear();
601
+ for (const table of [this.settings, this.providers, this.voiceProviders, this.npcs, this.sessions, this.participants, this.messages, this.contextCompressions, this.tools, this.worldBooks, this.careerStats, this.careerNpcStats, this.achievementUnlocks]) await table.clear();
597
602
  }
598
603
  close(): void {
599
604
  if (lockHeartbeat != null && typeof window !== 'undefined') {
@@ -685,6 +690,9 @@ export const DEFAULT_SETTINGS: AppSettings = {
685
690
  yoloMode: false,
686
691
  nsfwMode: false,
687
692
  pureMode: false,
693
+ autoVoiceEnabled: false,
694
+ activeVoiceProviderId: null,
695
+ activeVoiceId: null,
688
696
  statsResetTime: null,
689
697
  };
690
698
 
@@ -1,7 +1,67 @@
1
1
  {
2
- "latest": "0.1.31",
2
+ "latest": "0.1.32",
3
3
  "repo": "https://github.com/Rannichan/Tavern-Harness",
4
4
  "entries": [
5
+ {
6
+ "version": "0.1.32",
7
+ "date": "2026-11-18",
8
+ "breaking": false,
9
+ "compare": "v0.1.31...v0.1.32",
10
+ "groups": {
11
+ "zh-CN": [
12
+ {
13
+ "kind": "added",
14
+ "items": [
15
+ "语音服务供应商:设置页新增「🔊 语音服务供应商」分区,支持 DeepSeek(海星 · 女声、暗潮 · 男声)与百炼 Token Plan(龙安灵心、龙安陆风)。填写 API Key 即可保存,保存前还能在表单里试听音色;可以添加多个供应商,并随时启用、停用、编辑或删除",
16
+ "朗读助手消息:在助手消息的「更多」菜单中选择「朗读消息」,就会用默认音色朗读这条回复",
17
+ "自动朗读:对话标题栏新增朗读开关,开启后每条助手回复生成完毕会自动朗读,关闭后恢复静音",
18
+ "默认音色:在「语音服务供应商」下方选择默认的供应商与音色,手动朗读和自动朗读都会使用它;没有配置时会提示先选择"
19
+ ]
20
+ },
21
+ {
22
+ "kind": "changed",
23
+ "items": [
24
+ "设置页的供应商列表改为按添加时间倒序排列,新添加的供应商显示在最上方;「添加供应商」按钮移到分区标题右侧,列表为空时也始终可见",
25
+ "文本供应商与语音供应商的卡片分别显示「文本」「语音」标签,并统一了两类标签的配色,一眼就能区分服务类型",
26
+ "文本与语音供应商的 API Key 输入框都增加了显示 / 隐藏按钮,方便核对已填写的密钥",
27
+ "语音合成请求由本地持久化服务代理转发,API Key 只保存在本地数据库,不会直接出现在发往第三方的浏览器请求里"
28
+ ]
29
+ },
30
+ {
31
+ "kind": "internal",
32
+ "items": [
33
+ "新增 `voice-server.mjs`,对百炼返回的音频地址做 HTTPS 与域名校验;补充语音、持久化与供应商相关的测试"
34
+ ]
35
+ }
36
+ ],
37
+ "en": [
38
+ {
39
+ "kind": "added",
40
+ "items": [
41
+ "**Voice service providers**: Settings now has a **🔊 Voice Service Providers** section supporting DeepSeek (Stella · female, Tide · male) and Bailian Token Plan (Longan Lingxin, Longan Lufeng). Enter an API key to save a provider, and preview each voice right in the form before saving. You can add several providers and enable, disable, edit, or delete them at any time",
42
+ "**Read message aloud**: choose **Read message aloud** from an assistant message's More menu to hear that reply in the default voice",
43
+ "**Automatic reading**: the conversation header has a new reading toggle. When it is on, every completed assistant reply is read aloud automatically; turn it off to go silent",
44
+ "**Default voice**: pick the default provider and voice below the voice providers section; both manual and automatic reading use it. If nothing is configured, the app prompts you to choose one first"
45
+ ]
46
+ },
47
+ {
48
+ "kind": "changed",
49
+ "items": [
50
+ "The provider list in Settings is now sorted newest first, so freshly added providers appear at the top; the **Add provider** button moved next to the section heading and is always visible, even when the list is empty",
51
+ "Text and voice provider cards now carry **Text** and **Voice** tags with a unified color scheme, making the service type obvious at a glance",
52
+ "API key fields for both text and voice providers gained a show/hide button so you can check what you entered",
53
+ "Voice synthesis requests are proxied through the local persistence service, so the API key stays in the local database and never appears in browser requests to third parties"
54
+ ]
55
+ },
56
+ {
57
+ "kind": "internal",
58
+ "items": [
59
+ "Added `voice-server.mjs` to validate Bailian audio URLs against HTTPS and an allowlisted domain pattern, plus tests for voice, persistence, and provider behavior"
60
+ ]
61
+ }
62
+ ]
63
+ }
64
+ },
5
65
  {
6
66
  "version": "0.1.31",
7
67
  "date": "2026-11-05",
@@ -4,6 +4,7 @@ import {
4
4
  type ApiProvider,
5
5
  type AppSettings,
6
6
  type ProviderModelOption,
7
+ type VoiceProvider,
7
8
  enabledModelIds,
8
9
  modelAliases,
9
10
  ChatMessage,
@@ -63,6 +64,7 @@ import { estimateTokensFromChars, accumulateStats, preloadCareerStats, sessionPr
63
64
  import { seedOpeningGreeting } from '../core/openingGreeting';
64
65
  import { ACHIEVEMENTS, type AchievementDef } from '../core/achievements';
65
66
  import { npcFingerprint, sameRows, toolFingerprint, worldBookFingerprint } from '../core/rowFingerprint';
67
+ import { activeVoiceProvider, speakText } from '../core/voice';
66
68
 
67
69
  // ============================================================
68
70
  // Store(对应 MainViewModel)
@@ -108,6 +110,7 @@ interface AppState {
108
110
  readOnly: boolean;
109
111
  settings: AppSettings | null;
110
112
  providers: ApiProvider[];
113
+ voiceProviders: VoiceProvider[];
111
114
  npcs: NpcCharacter[];
112
115
  sessions: ChatSession[];
113
116
  worldBooks: WorldBook[];
@@ -187,6 +190,8 @@ interface AppState {
187
190
  refreshWorldBooks: () => Promise<void>;
188
191
  refreshTools: () => Promise<void>;
189
192
  refreshProviders: () => Promise<void>;
193
+ refreshVoiceProviders: () => Promise<void>;
194
+ speakMessage: (text: string) => Promise<void>;
190
195
  refreshAchievements: () => Promise<void>;
191
196
  loadMessages: (sessionId: number) => Promise<void>;
192
197
  /** 重新加载当前活动会话的参与者(语言切换后刷新内置角色显示名) */
@@ -228,6 +233,7 @@ async function initializeDeferredData(readOnly: boolean): Promise<void> {
228
233
  }
229
234
  await Promise.all([
230
235
  useStore.getState().refreshProviders(),
236
+ useStore.getState().refreshVoiceProviders(),
231
237
  useStore.getState().refreshAchievements(),
232
238
  preloadCareerStats(),
233
239
  ]);
@@ -311,6 +317,7 @@ export const useStore = create<AppState>((set, get) => ({
311
317
  readOnly: false,
312
318
  settings: null,
313
319
  providers: [],
320
+ voiceProviders: [],
314
321
  npcs: [],
315
322
  sessions: [],
316
323
  worldBooks: [],
@@ -354,6 +361,7 @@ export const useStore = create<AppState>((set, get) => ({
354
361
  const settings = { ...serverSettings, ...browserPreferences };
355
362
  setLanguage(settings.language);
356
363
  const providers = snapshot.collections.providers.map((record) => record.value);
364
+ const voiceProviders = (snapshot.collections.voiceProviders ?? []).map((record) => record.value);
357
365
  const npcs = sortNpcs(snapshot.collections.npcs.map((record) => record.value));
358
366
  const sessions = sortSessionsPinnedFirst(snapshot.collections.sessions.map((record) => record.value));
359
367
  const worldBooks = sortWorldBooks(snapshot.collections.worldBooks.map((record) => record.value));
@@ -370,6 +378,7 @@ export const useStore = create<AppState>((set, get) => ({
370
378
  readOnly,
371
379
  settings,
372
380
  providers,
381
+ voiceProviders,
373
382
  modelsList: aggregateEnabledProviderModels(providers),
374
383
  npcs,
375
384
  sessions,
@@ -539,6 +548,26 @@ export const useStore = create<AppState>((set, get) => ({
539
548
  set({ careerTotalTokens: stats.inputTokens + stats.outputTokens });
540
549
  },
541
550
 
551
+ refreshVoiceProviders: async () => {
552
+ set({ voiceProviders: await db.voiceProviders.toArray() });
553
+ },
554
+
555
+ speakMessage: async (text) => {
556
+ const state = get();
557
+ const settings = state.settings;
558
+ if (!settings) return;
559
+ const provider = activeVoiceProvider(state.voiceProviders, settings.activeVoiceProviderId, settings.activeVoiceId);
560
+ if (!provider || !settings.activeVoiceId) {
561
+ state.addToast(translate('toast.voiceNotConfigured'), 'error');
562
+ return;
563
+ }
564
+ try {
565
+ await speakText(provider.id!, settings.activeVoiceId, text);
566
+ } catch (error) {
567
+ state.addToast(translate('toast.voiceFailed', { msg: error instanceof Error ? error.message : String(error) }), 'error');
568
+ }
569
+ },
570
+
542
571
  refreshProviders: async () => {
543
572
  const providers = await db.providers.toArray();
544
573
  set({ providers });
@@ -2304,6 +2333,9 @@ async function performAssistantTurn(
2304
2333
  rawResponseBody: rawLines.join('\n'),
2305
2334
  });
2306
2335
  await useStore.getState().loadMessages(sessionId);
2336
+ if (normalizedContent && useStore.getState().settings?.autoVoiceEnabled === true) {
2337
+ void useStore.getState().speakMessage(normalizedContent);
2338
+ }
2307
2339
 
2308
2340
  // 生涯统计:1 个回复回合 = 1 轮对话(ReAct 多层只计一次);
2309
2341
  // 群聊中 NPC 发言会把该轮计入对应角色的 careerNpcStats(最活跃角色统计)
@@ -1970,7 +1970,7 @@ hr.sep {
1970
1970
  gap: 0;
1971
1971
  }
1972
1972
 
1973
- .chat-actions .icon-tooltip:not(.chat-actions-more, .chat-actions-export, .chat-theme-toggle) {
1973
+ .chat-actions .icon-tooltip:not(.chat-actions-more, .chat-actions-export, .chat-voice-toggle, .chat-theme-toggle) {
1974
1974
  display: none;
1975
1975
  }
1976
1976
 
@@ -1983,10 +1983,14 @@ hr.sep {
1983
1983
  order: 2;
1984
1984
  }
1985
1985
 
1986
- .chat-actions .chat-theme-toggle {
1986
+ .chat-actions .chat-voice-toggle {
1987
1987
  order: 3;
1988
1988
  }
1989
1989
 
1990
+ .chat-actions .chat-theme-toggle {
1991
+ order: 4;
1992
+ }
1993
+
1990
1994
  .chat-actions .icon-tooltip {
1991
1995
  width: 34px;
1992
1996
  height: 34px;
@@ -912,13 +912,10 @@
912
912
  padding: 2px 8px;
913
913
  border-radius: 999px;
914
914
  }
915
- .p-status.on {
916
- color: var(--text-success);
917
- background: var(--success-soft);
918
- }
919
- .p-status.off {
920
- color: var(--text-muted);
921
- background: var(--surface-2);
915
+ .p-status.voice,
916
+ .p-status.text {
917
+ color: var(--text-accent);
918
+ background: var(--primary-soft);
922
919
  }
923
920
 
924
921
  .provider-card.disabled {
@@ -927,6 +924,89 @@
927
924
  .provider-card.disabled .p-name {
928
925
  color: var(--text-muted);
929
926
  }
927
+ .provider-voice-option {
928
+ display: flex;
929
+ align-items: center;
930
+ justify-content: space-between;
931
+ gap: 10px;
932
+ padding: 10px 12px;
933
+ border: 1px solid var(--border);
934
+ border-radius: 10px;
935
+ background: var(--surface);
936
+ transition: border-color 0.2s ease, background 0.2s ease;
937
+ }
938
+ .provider-voice-option:hover {
939
+ border-color: color-mix(in srgb, var(--primary) 35%, var(--border));
940
+ }
941
+ .provider-voice-preview {
942
+ flex: 0 0 auto;
943
+ }
944
+ .voice-default-card {
945
+ margin-top: 12px;
946
+ padding: 12px 14px;
947
+ display: flex;
948
+ align-items: center;
949
+ justify-content: space-between;
950
+ gap: 16px;
951
+ border: 1px solid var(--border);
952
+ border-radius: 12px;
953
+ background: var(--surface);
954
+ }
955
+ .voice-default-card .s-label {
956
+ font-size: var(--font-size-body-sm);
957
+ font-weight: var(--font-weight-semibold);
958
+ color: var(--text-secondary);
959
+ }
960
+ .voice-default-card .s-desc {
961
+ margin-top: 3px;
962
+ font-size: var(--font-size-sm);
963
+ color: var(--text-muted);
964
+ }
965
+ .voice-default-select {
966
+ width: 280px;
967
+ max-width: 48vw;
968
+ }
969
+ @media (max-width: 640px) {
970
+ .voice-default-card {
971
+ align-items: stretch;
972
+ flex-direction: column;
973
+ }
974
+ .voice-default-select {
975
+ width: 100%;
976
+ max-width: none;
977
+ min-width: 0;
978
+ }
979
+ }
980
+ .password-input-wrap {
981
+ position: relative;
982
+ }
983
+ .password-input-wrap .input {
984
+ width: 100%;
985
+ padding-right: 42px;
986
+ }
987
+ .password-visibility-btn {
988
+ position: absolute;
989
+ top: 50%;
990
+ right: 6px;
991
+ width: 30px;
992
+ height: 30px;
993
+ display: grid;
994
+ place-items: center;
995
+ transform: translateY(-50%);
996
+ border: 0;
997
+ border-radius: 7px;
998
+ color: var(--text-muted);
999
+ background: transparent;
1000
+ cursor: pointer;
1001
+ }
1002
+ .password-visibility-btn:hover {
1003
+ color: var(--text-accent);
1004
+ background: var(--primary-soft);
1005
+ }
1006
+ .password-visibility-btn:focus-visible {
1007
+ outline: 2px solid var(--primary);
1008
+ outline-offset: 1px;
1009
+ }
930
1010
 
931
1011
  /* ---------- 开关 Switch ---------- */
932
1012
  .switch {
@@ -59,9 +59,26 @@ export interface AppSettings {
59
59
  nsfwMode: boolean;
60
60
  /** 隐藏对话中的思考与工具调用,仅保留消息正文;默认关闭。 */
61
61
  pureMode: boolean;
62
+ /** 新生成的助手回复自动朗读;默认关闭。 */
63
+ autoVoiceEnabled: boolean;
64
+ /** 当前启用的语音 Provider。 */
65
+ activeVoiceProviderId: number | null;
66
+ /** 当前旁白音色。 */
67
+ activeVoiceId: VoiceId | null;
62
68
  statsResetTime: number | null;
63
69
  }
64
70
 
71
+ export type VoiceProviderKind = 'deepseek' | 'bailian';
72
+ export type VoiceId = 'stella' | 'tide' | 'longanlingxin' | 'longanlufeng';
73
+
74
+ export interface VoiceProvider {
75
+ id?: number;
76
+ kind: VoiceProviderKind;
77
+ apiKey: string;
78
+ isEnabled: boolean;
79
+ createdAt: number;
80
+ }
81
+
65
82
  export interface ApiProvider {
66
83
  id?: number;
67
84
  name: string;