dsh-folia 4.26.0-pre.68 → 4.26.0-pre.69

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/lib/client.js CHANGED
@@ -837,6 +837,18 @@ window.__ModuleLoader__.load({
837
837
  "短": "Short",
838
838
  "长": "Long",
839
839
  "语音模式由宿主按 1–3 句截断;这里保存的是该人设的音色与语速。": "Voice mode is capped at 1–3 sentences by the host; this page stores the persona voice and rate.",
840
+ // v2:声音页确认流(桌宠气泡按钮)。
841
+ "轮播打开了": "Rotation enabled",
842
+ "轮播关掉了": "Rotation disabled",
843
+ "要执行这个操作吗?": "Run this action?",
844
+ "确认没发出去,再试一次": "Confirmation didn't send — try again",
845
+ "允许": "Allow",
846
+ "不允许": "Don't allow",
847
+ "以后都允许": "Always allow",
848
+ "以后都别问": "Never ask again",
849
+ "音色库与全局音色中心已移到人物详情里的「声音」页:内置音色包、Edge 分组、火山引擎配置都在那里;这里保留朗读开关与一键启用。": "The voice library and global voice center now live under Personas → Voice (built-in packs, Edge groups, Volcengine config); this page keeps the read-aloud switch and one-click setup.",
850
+ "已安装": "Installed",
851
+ "未安装": "Not installed",
840
852
  "玩法模式": "Play mode",
841
853
  "唤醒口令": "Wake phrase",
842
854
  "例如:我回来了": "e.g. I'm back",
@@ -952,7 +964,6 @@ window.__ModuleLoader__.load({
952
964
  "让界面和对话更有趣": "Make the UI and chat more fun",
953
965
  "工作能力": "Work",
954
966
  "娱乐": "Fun",
955
- "未安装": "Not installed",
956
967
  "详情": "Details",
957
968
  "收起": "Collapse",
958
969
  "复制安装命令": "Copy install command",
@@ -1022,7 +1033,6 @@ window.__ModuleLoader__.load({
1022
1033
  "还没有安装任何皮肤 —— 从下面的站点清单里挑一个。": "No skins installed yet — pick one from the site list below.",
1023
1034
  "站点上还没有皮肤。": "No skins on the site yet.",
1024
1035
  "含动效钩子": "animated hooks",
1025
- "已安装": "Installed",
1026
1036
  "已安装过:{name}": "Already installed: {name}",
1027
1037
  "已安装:{name} —— 到「设置 → 皮肤中心」点它即可启用": "Installed: {name} — pick it in Settings → Skin centre to enable",
1028
1038
  "卸载中…": "Uninstalling…",
@@ -19362,6 +19372,7 @@ window.__ModuleLoader__.load({
19362
19372
  type: props.type || 'text', value: props.value == null ? '' : String(props.value),
19363
19373
  placeholder: props.placeholder || '', onChange: (e) => props.onChange(e.target.value),
19364
19374
  disabled: props.disabled === true,
19375
+ list: props.list,
19365
19376
  style: { ...PERSONA_STYLE.input, ...(props.style || {}) },
19366
19377
  });
19367
19378
  }
@@ -19484,6 +19495,21 @@ window.__ModuleLoader__.load({
19484
19495
  const [note, setNote] = React.useState(null);
19485
19496
  const [memory, setMemory] = React.useState({ loading: false, items: [], growth: [], total: 0, q: '' });
19486
19497
  const [voices, setVoices] = React.useState([]);
19498
+ const [voiceCatalog, setVoiceCatalog] = React.useState(null);
19499
+ const [voiceBusy, setVoiceBusy] = React.useState('');
19500
+ const [previewId, setPreviewId] = React.useState('');
19501
+ const [pendingPreview, setPendingPreview] = React.useState('');
19502
+ const [voiceNote, setVoiceNote] = React.useState(null);
19503
+ const [volcOpen, setVolcOpen] = React.useState(false);
19504
+ const [howToOpen, setHowToOpen] = React.useState(false);
19505
+ const [volcForm, setVolcForm] = React.useState({
19506
+ appId: '', accessToken: '', cluster: 'volcano_tts', resourceId: 'seed-tts-2.0',
19507
+ subtype: 'volc-seed-tts', voiceId: 'zh_female_shuangkuaisisi_uranus_bigtts',
19508
+ });
19509
+ const [volcNote, setVolcNote] = React.useState(null);
19510
+ const [perm, setPerm] = React.useState({ loading: false, advanced: false, groups: [], toolLog: { items: [], total: 0 }, isCharacter: false, message: '' });
19511
+ const [permBusy, setPermBusy] = React.useState(false);
19512
+ const [permNote, setPermNote] = React.useState(null);
19487
19513
  const [wizard, setWizard] = React.useState({ step: 1, name: '', nickname: '', tone: '温柔', relation: '' });
19488
19514
  const [doc, setDoc] = React.useState(null);
19489
19515
  const [library, setLibrary] = React.useState({ loading: false, cards: [], categories: [], q: '', category: 'all' });
@@ -19695,14 +19721,281 @@ window.__ModuleLoader__.load({
19695
19721
  } catch { setVoices([]); }
19696
19722
  }, []);
19697
19723
 
19724
+ /** v2:声音页的统一目录(内置包 / Edge / 火山)。 */
19725
+ const loadVoiceCatalog = React.useCallback(async () => {
19726
+ try {
19727
+ const data = unwrap(await apiJson('/pet-chat/voice/catalog', { parse: 'always' }));
19728
+ setVoiceCatalog(data);
19729
+ const volc = (data.center && data.center.volcengine) || {};
19730
+ setVolcForm((prev) => ({
19731
+ ...prev,
19732
+ cluster: volc.cluster || prev.cluster,
19733
+ resourceId: volc.resourceId || prev.resourceId,
19734
+ subtype: volc.subtype || prev.subtype,
19735
+ voiceId: volc.voiceId || prev.voiceId,
19736
+ appId: '',
19737
+ accessToken: '',
19738
+ }));
19739
+ } catch {
19740
+ setVoiceCatalog({ groups: [], packs: [], center: null, howTo: [] });
19741
+ }
19742
+ }, []);
19743
+
19744
+ const loadPermissions = React.useCallback(async (id) => {
19745
+ setPerm((prev) => ({ ...prev, loading: true }));
19746
+ try {
19747
+ const data = unwrap(await apiJson('/pet-chat/personas/' + encodeURIComponent(id) + '/permissions', { parse: 'always' }));
19748
+ let log = { items: [], total: 0 };
19749
+ try { log = unwrap(await apiJson('/pet-chat/personas/' + encodeURIComponent(id) + '/tool-log?limit=10', { parse: 'always' })); } catch { /* ignore */ }
19750
+ setPerm({
19751
+ loading: false,
19752
+ advanced: data.advanced === true,
19753
+ groups: Array.isArray(data.groups) ? data.groups : [],
19754
+ isCharacter: data.isCharacter === true,
19755
+ message: String(data.message || ''),
19756
+ toolLog: { items: Array.isArray(log.items) ? log.items : [], total: Number(log.total) || 0 },
19757
+ });
19758
+ } catch {
19759
+ setPerm((prev) => ({ ...prev, loading: false }));
19760
+ }
19761
+ }, []);
19762
+
19763
+ /** 下载/删除/设默认之后把包状态合并回目录(不重新拉 Edge 列表)。 */
19764
+ const mergePackState = (packs) => {
19765
+ setVoiceCatalog((prev) => {
19766
+ if (!prev) return prev;
19767
+ const byId = new Map((packs || []).map((pack) => [pack.id, pack]));
19768
+ const groups = (prev.groups || []).map((group) => {
19769
+ if (group.key !== 'builtin') return group;
19770
+ return {
19771
+ ...group,
19772
+ items: (group.items || []).map((item) => {
19773
+ const pack = byId.get(item.packId);
19774
+ if (!pack) return item;
19775
+ return {
19776
+ ...item,
19777
+ installed: pack.installed,
19778
+ status: pack.status,
19779
+ reason: pack.reason,
19780
+ progress: pack.progress,
19781
+ sizeMB: pack.sizeMB,
19782
+ sizeBytes: pack.sizeBytes,
19783
+ };
19784
+ }),
19785
+ };
19786
+ });
19787
+ return { ...prev, groups, packs: packs || prev.packs };
19788
+ });
19789
+ };
19790
+
19791
+ const refreshPacks = React.useCallback(async () => {
19792
+ try {
19793
+ const data = unwrap(await apiJson('/pet-chat/voice/packs', { parse: 'always' }));
19794
+ if (Array.isArray(data.packs)) mergePackState(data.packs);
19795
+ return data;
19796
+ } catch { return null; }
19797
+ }, []);
19798
+
19799
+ const previewVoice = React.useCallback(async (id) => {
19800
+ if (!id) return;
19801
+ setPreviewId(id);
19802
+ setVoiceNote(null);
19803
+ try {
19804
+ const resp = await apiFetch('/pet-chat/voice/preview', {
19805
+ method: 'POST', headers: { 'Content-Type': 'application/json' },
19806
+ body: JSON.stringify({ id }), parse: false,
19807
+ });
19808
+ if (!resp || !resp.ok) {
19809
+ let hint = '';
19810
+ try {
19811
+ const doc = await resp.response.json();
19812
+ hint = doc && (doc.hint || doc.code);
19813
+ } catch { /* ignore */ }
19814
+ setVoiceNote({ ok: false, text: hint || '试听失败(音色未就绪或网络不可用)' });
19815
+ setPreviewId('');
19816
+ return;
19817
+ }
19818
+ const blob = await resp.response.blob();
19819
+ const url = URL.createObjectURL(blob);
19820
+ const audio = new Audio(url);
19821
+ const cleanup = () => { try { URL.revokeObjectURL(url); } catch { /* ignore */ } setPreviewId(''); };
19822
+ audio.onended = cleanup;
19823
+ audio.onerror = () => { cleanup(); setVoiceNote({ ok: false, text: '试听音频播放失败' }); };
19824
+ const played = audio.play();
19825
+ if (played && typeof played.catch === 'function') {
19826
+ played.catch(() => { cleanup(); setVoiceNote({ ok: false, text: '浏览器拦截了自动播放,再点一次 ▶' }); });
19827
+ }
19828
+ } catch {
19829
+ setPreviewId('');
19830
+ setVoiceNote({ ok: false, text: '试听请求失败' });
19831
+ }
19832
+ }, []);
19833
+
19834
+ // 下载中:每 1.5s 合并一次进度;安装完成且有待试听 → 自动播放。
19835
+ React.useEffect(() => {
19836
+ if (!voiceCatalog || detailTab !== 'voice') return undefined;
19837
+ const downloading = (voiceCatalog.packs || []).some((pack) => pack.status === 'downloading');
19838
+ if (!downloading) return undefined;
19839
+ const timer = setInterval(() => {
19840
+ void refreshPacks().then((data) => {
19841
+ if (!data || !pendingPreview) return;
19842
+ const ready = (data.packs || []).find((pack) => pack.installed && pack.voiceId === pendingPreview);
19843
+ if (ready) {
19844
+ setPendingPreview('');
19845
+ void previewVoice(pendingPreview);
19846
+ }
19847
+ });
19848
+ }, 1500);
19849
+ return () => clearInterval(timer);
19850
+ }, [voiceCatalog, detailTab, pendingPreview, refreshPacks, previewVoice]);
19851
+
19698
19852
  React.useEffect(() => {
19699
19853
  if (!selected) return;
19700
19854
  if (detailTab === 'memory') void loadMemory(selected.id, '');
19701
19855
  if (detailTab === 'voice' && !voices.length) void loadVoices();
19702
- }, [selected, detailTab, loadMemory, loadVoices, voices.length]);
19856
+ if (detailTab === 'voice' && !voiceCatalog) void loadVoiceCatalog();
19857
+ if (detailTab === 'permissions') void loadPermissions(selected.id);
19858
+ }, [selected, detailTab, loadMemory, loadVoices, voices.length, voiceCatalog, loadVoiceCatalog, loadPermissions]);
19859
+
19860
+ const packAction = async (kind, pack) => {
19861
+ if (!pack) return;
19862
+ setVoiceBusy(kind + ':' + pack.id);
19863
+ setVoiceNote(null);
19864
+ try {
19865
+ if (kind === 'install') {
19866
+ const data = unwrap(await apiPostJson('/pet-chat/voice/packs/install', { id: pack.id }, { parse: 'always' }));
19867
+ if (!data.ok) throw new Error(data.hint || 'install-failed');
19868
+ setPendingPreview(pack.voiceId || '');
19869
+ setVoiceNote({ ok: true, text: `开始下载「${pack.name}」;完成后会自动试听。` });
19870
+ await refreshPacks();
19871
+ } else if (kind === 'remove') {
19872
+ const data = unwrap(await apiPostJson('/pet-chat/voice/packs/remove', { id: pack.id }, { parse: 'always' }));
19873
+ if (!data.ok) throw new Error(data.hint || 'remove-failed');
19874
+ setVoiceNote({ ok: true, text: `已删除「${pack.name}」(共享运行时与其它包不受影响)。` });
19875
+ await loadVoiceCatalog();
19876
+ } else if (kind === 'default') {
19877
+ const data = unwrap(await apiPostJson('/pet-chat/voice/packs/default', { id: pack.id }, { parse: 'always' }));
19878
+ if (!data.ok) throw new Error(data.hint || 'default-failed');
19879
+ setVoiceNote({ ok: true, text: `全局默认已设为「${pack.name}」。` });
19880
+ await loadVoiceCatalog();
19881
+ }
19882
+ } catch (error) {
19883
+ setVoiceNote({ ok: false, text: String((error && error.message) || '操作失败') });
19884
+ } finally {
19885
+ setVoiceBusy('');
19886
+ }
19887
+ };
19888
+
19889
+ const setGlobalDefaultVoice = async (id, label) => {
19890
+ setVoiceBusy('default:' + id);
19891
+ setVoiceNote(null);
19892
+ try {
19893
+ const data = unwrap(await apiPostJson('/pet-chat/voice/preferred', { voiceId: id }, { parse: 'always' }));
19894
+ if (!data.ok) throw new Error(data.hint || 'default-failed');
19895
+ setVoiceNote({ ok: true, text: `全局默认已设为「${label || id}」。` });
19896
+ await loadVoiceCatalog();
19897
+ } catch (error) {
19898
+ setVoiceNote({ ok: false, text: String((error && error.message) || '设置失败') });
19899
+ } finally {
19900
+ setVoiceBusy('');
19901
+ }
19902
+ };
19903
+
19904
+ const saveVolc = async () => {
19905
+ setVoiceBusy('volc-save');
19906
+ setVolcNote(null);
19907
+ try {
19908
+ const data = unwrap(await apiPostJson('/pet-chat/voice/providers', {
19909
+ provider: 'volcengine',
19910
+ appId: volcForm.appId,
19911
+ accessToken: volcForm.accessToken,
19912
+ cluster: volcForm.cluster,
19913
+ resourceId: volcForm.resourceId,
19914
+ subtype: volcForm.subtype,
19915
+ voiceId: volcForm.voiceId,
19916
+ }, { parse: 'always' }));
19917
+ if (!data.ok) throw new Error(data.error || 'save-failed');
19918
+ setVolcNote({ ok: true, text: '火山配置已保存(AppID/Token 只写不读)。' });
19919
+ await loadVoiceCatalog();
19920
+ } catch (error) {
19921
+ setVolcNote({ ok: false, text: String((error && error.message) || '保存失败') });
19922
+ } finally { setVoiceBusy(''); }
19923
+ };
19924
+
19925
+ const testVolc = async () => {
19926
+ setVoiceBusy('volc-test');
19927
+ setVolcNote({ ok: true, text: '正在真调火山(最长 25 秒)…' });
19928
+ try {
19929
+ if (volcForm.appId.trim() || volcForm.accessToken.trim()) {
19930
+ const saved = unwrap(await apiPostJson('/pet-chat/voice/providers', {
19931
+ provider: 'volcengine',
19932
+ appId: volcForm.appId,
19933
+ accessToken: volcForm.accessToken,
19934
+ cluster: volcForm.cluster,
19935
+ resourceId: volcForm.resourceId,
19936
+ subtype: volcForm.subtype,
19937
+ voiceId: volcForm.voiceId,
19938
+ }, { parse: 'always' }));
19939
+ if (!saved.ok) throw new Error(saved.error || 'save-failed');
19940
+ }
19941
+ const data = unwrap(await apiPostJson('/pet-chat/voice/providers/test', { provider: 'volcengine' }, { parse: 'always' }));
19942
+ if (data.ok) {
19943
+ const fallback = data.fallback ? '(在线失败,已回落内置音色)' : '';
19944
+ setVolcNote({ ok: true, text: `火山已接通:${data.actualVoice || volcForm.voiceId}${fallback}` });
19945
+ } else {
19946
+ setVolcNote({ ok: false, text: String(data.error || '测试失败') });
19947
+ }
19948
+ await loadVoiceCatalog();
19949
+ } catch (error) {
19950
+ setVolcNote({ ok: false, text: String((error && error.message) || '测试失败') });
19951
+ } finally { setVoiceBusy(''); }
19952
+ };
19953
+
19954
+ const setPermissionGroup = async (group, level) => {
19955
+ if (!draft) return;
19956
+ setPermBusy(true);
19957
+ setPermNote(null);
19958
+ try {
19959
+ const data = unwrap(await apiPostJson('/pet-chat/personas/' + encodeURIComponent(draft.id) + '/permissions', { group, level }, { parse: 'always' }));
19960
+ if (!data.ok) throw new Error(data.hint || data.message || 'save-failed');
19961
+ setPermNote({ ok: true, text: '权限已保存' });
19962
+ await loadPermissions(draft.id);
19963
+ } catch (error) {
19964
+ setPermNote({ ok: false, text: String((error && error.message) || '保存失败') });
19965
+ await loadPermissions(draft.id);
19966
+ } finally { setPermBusy(false); }
19967
+ };
19968
+
19969
+ const setAdvancedPermission = async (advanced) => {
19970
+ if (!draft) return;
19971
+ setPermBusy(true);
19972
+ setPermNote(null);
19973
+ try {
19974
+ const data = unwrap(await apiPostJson('/pet-chat/personas/' + encodeURIComponent(draft.id) + '/permissions', { advanced }, { parse: 'always' }));
19975
+ if (!data.ok) throw new Error(data.hint || 'save-failed');
19976
+ setPermNote({ ok: true, text: advanced ? '高级权限已打开(系统操作仍需逐次确认)' : '高级权限已关闭(系统操作不可用)' });
19977
+ await loadPermissions(draft.id);
19978
+ } catch (error) {
19979
+ setPermNote({ ok: false, text: String((error && error.message) || '保存失败') });
19980
+ } finally { setPermBusy(false); }
19981
+ };
19982
+
19983
+ const clearToolLog = async () => {
19984
+ if (!draft) return;
19985
+ setPermBusy(true);
19986
+ try {
19987
+ await apiFetch('/pet-chat/personas/' + encodeURIComponent(draft.id) + '/tool-log', { method: 'DELETE', parse: 'always' });
19988
+ await loadPermissions(draft.id);
19989
+ setPermNote({ ok: true, text: '调用记录已清空' });
19990
+ } catch {
19991
+ setPermNote({ ok: false, text: '清空失败' });
19992
+ } finally { setPermBusy(false); }
19993
+ };
19703
19994
 
19704
19995
  const patchDraft = (fn) => setDraft((prev) => { const next = clone(prev); fn(next); return next; });
19705
19996
 
19997
+
19998
+
19706
19999
  const saveKey = async (mode) => {
19707
20000
  if (!draft) return;
19708
20001
  setBusy(true);
@@ -20018,32 +20311,394 @@ window.__ModuleLoader__.load({
20018
20311
  personaInput({ type: 'number', value: p.growth.bond.trust, onChange: (v) => patchDraft((d) => { d.growth.bond.trust = Number(v); }), style: { width: '90px' } }))),
20019
20312
  React.createElement('div', { className: 'we-picker__hint' }, '剧情状态会进入特殊人设的 system prompt;世界书在「人设卡」页。'));
20020
20313
 
20021
- const voicePage = React.createElement('div', null,
20022
- personaField('音色', personaSelect({
20023
- value: p.express.voice.name || '',
20024
- onChange: (v) => patchDraft((d) => { d.express.voice.name = v; }),
20025
- options: [
20026
- { value: '', label: '自动 / 继承全局' },
20027
- ...voices.map((voice) => ({
20028
- value: String(voice.id || voice.name || ''),
20029
- label: `${voice.label || voice.id || ''}(${voice.engine || ''}${voice.usable === false ? ' · 暂不可用' : ''})`,
20030
- })),
20031
- ],
20032
- })),
20033
- personaField('语速(-10…10)', personaInput({ type: 'number', value: p.express.voice.rate, onChange: (v) => patchDraft((d) => { d.express.voice.rate = Number(v); }) })),
20034
- personaField('长度策略', personaSelect({
20035
- value: p.express.lengthPolicy, onChange: (v) => patchDraft((d) => { d.express.lengthPolicy = v; }),
20036
- options: [{ value: 'adaptive', label: '自适应' }, { value: 'short', label: '短' }, { value: 'long', label: '长' }],
20037
- })),
20038
- React.createElement('div', { className: 'we-picker__hint' }, '语音模式由宿主按 1–3 句截断;这里保存该人设的音色与语速。'),
20039
- React.createElement('div', { className: 'we-picker__hint', style: { opacity: .78 } },
20040
- voices.some((v) => v && v.usable === false && String(v.reason || '').includes('429'))
20041
- ? 'Edge 在线音色当前被限流(429),已保留但标为“暂不可用”;可先用内置 Piper 离线音色,稍后自动恢复。'
20042
- : '带“暂不可用”的音色仍可保存,宿主合成时会自动回落到可用音色。'));
20314
+ const personaTag = (text, kind) => React.createElement('span', {
20315
+ style: {
20316
+ ...PERSONA_STYLE.badge,
20317
+ ...(kind === 'ok' ? PERSONA_STYLE.badgeOk : kind === 'warn' ? PERSONA_STYLE.badgeWarn : {}),
20318
+ ...(kind === 'risk-high' ? { borderColor: 'rgba(248,113,113,.5)', color: '#fca5a5' } : {}),
20319
+ ...(kind === 'risk-medium' ? { borderColor: 'rgba(251,191,36,.45)', color: '#fcd34d' } : {}),
20320
+ ...(kind === 'risk-low' ? { borderColor: 'rgba(74,222,128,.4)', color: '#86efac' } : {}),
20321
+ },
20322
+ }, text);
20323
+
20324
+ const voiceStatusText = (item) => {
20325
+ if (!item) return '';
20326
+ if (item.installed && item.runtimeReady === false) return '缺高清运行时';
20327
+ const percent = item.progress && item.progress.percent;
20328
+ if (item.status === 'downloading') return `下载中${percent == null ? '' : ' ' + percent + '%'}`;
20329
+ if (item.status === 'downloadable') return '未下载';
20330
+ if (item.status === 'rate-limited') return '暂不可用(429 限流)';
20331
+ if (item.status === 'needs-key') return '需配置';
20332
+ if (item.status === 'needs-test') return '需测试';
20333
+ if (item.status === 'error') return '安装失败';
20334
+ if (item.status === 'unavailable') return '暂不可用';
20335
+ return '可用';
20336
+ };
20337
+
20338
+ const voiceStatusKind = (item) => {
20339
+ if (!item) return '';
20340
+ if (item.status === 'ready') return 'ok';
20341
+ if (item.status === 'downloading' || item.status === 'needs-test') return 'warn';
20342
+ return 'warn';
20343
+ };
20344
+
20345
+ /** 音色卡片:分组 + 状态徽标 + ▶ 试听 + 选中。 */
20346
+ const voiceCard = (item, opts = {}) => {
20347
+ const selected = opts.selected === true;
20348
+ const isPreviewing = previewId === item.id;
20349
+ const needsKey = item.status === 'needs-key';
20350
+ const runtimeMissing = item.installed === true && item.runtimeReady === false;
20351
+ const downloadable = item.status === 'downloadable';
20352
+ const meta = [
20353
+ item.lang,
20354
+ item.gender === 'Female' ? '女声' : item.gender === 'Male' ? '男声' : '',
20355
+ item.hd ? '高清' : item.quality,
20356
+ item.sizeMB ? `${item.sizeMB}MB` : '',
20357
+ ].filter(Boolean).join(' · ');
20358
+ return React.createElement('div', {
20359
+ key: item.id,
20360
+ style: {
20361
+ ...PERSONA_STYLE.card,
20362
+ padding: '8px 10px',
20363
+ cursor: opts.onPick ? 'pointer' : 'default',
20364
+ ...(selected ? PERSONA_STYLE.cardActive : {}),
20365
+ ...(item.status === 'rate-limited' || item.status === 'unavailable' ? { opacity: .78 } : {}),
20366
+ },
20367
+ onClick: opts.onPick ? () => opts.onPick(item) : undefined,
20368
+ },
20369
+ React.createElement('div', { style: { ...PERSONA_STYLE.row, justifyContent: 'space-between', gap: '6px' } },
20370
+ React.createElement('div', { style: { minWidth: 0 } },
20371
+ React.createElement('div', { style: { fontSize: '12px', fontWeight: 600, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } },
20372
+ item.label,
20373
+ selected ? personaTag('已选', 'ok') : null),
20374
+ React.createElement('div', { style: { fontSize: '10px', opacity: .7, marginTop: '1px' } }, meta || item.engine)),
20375
+ React.createElement('div', { style: { ...PERSONA_STYLE.row, gap: '4px', justifyContent: 'flex-end' } },
20376
+ personaTag(voiceStatusText(item), voiceStatusKind(item)),
20377
+ React.createElement('div', { onClick: (e) => { e.stopPropagation(); } },
20378
+ personaButton(isPreviewing ? '…' : (runtimeMissing ? '缺高清运行时' : (downloadable ? '▶ 下载并试听' : '▶ 试听')), () => {
20379
+ if (needsKey || runtimeMissing || isPreviewing) return;
20380
+ if (downloadable && item.packId) {
20381
+ void packAction('install', { id: item.packId, name: item.label, voiceId: item.id });
20382
+ } else {
20383
+ void previewVoice(item.id);
20384
+ }
20385
+ }, { disabled: needsKey || runtimeMissing || isPreviewing || item.status === 'downloading' })),
20386
+ opts.onDefault ? React.createElement('div', { onClick: (e) => { e.stopPropagation(); } },
20387
+ personaButton('设为默认', () => opts.onDefault(item), { disabled: item.status !== 'ready' })) : null)));
20388
+ };
20389
+
20390
+ const packRow = (pack) => {
20391
+ const progress = pack.progress || {};
20392
+ const pct = progress.percent;
20393
+ const installed = pack.installed === true;
20394
+ const runtimeMissing = installed && pack.runtimeReady === false;
20395
+ return React.createElement('div', { key: pack.id, style: { ...PERSONA_STYLE.card, padding: '8px 10px' } },
20396
+ React.createElement('div', { style: { ...PERSONA_STYLE.row, justifyContent: 'space-between', alignItems: 'flex-start' } },
20397
+ React.createElement('div', { style: { minWidth: 0 } },
20398
+ React.createElement('div', { style: { fontSize: '12px', fontWeight: 600 } },
20399
+ pack.name,
20400
+ personaTag(pack.quality || '', pack.hd ? 'ok' : ''),
20401
+ pack.recommended ? personaTag('推荐', 'ok') : null),
20402
+ React.createElement('div', { style: { fontSize: '10px', opacity: .7, marginTop: '2px' } },
20403
+ `${pack.lang} · ${pack.sizeMB}MB · ${pack.license} · ${pack.source}`),
20404
+ React.createElement('div', { className: 'we-picker__hint', style: { margin: '2px 0 0', fontSize: '10px' } }, pack.desc)),
20405
+ React.createElement('div', { style: { ...PERSONA_STYLE.row, gap: '4px', justifyContent: 'flex-end' } },
20406
+ personaTag(installed ? '已安装' : (pack.status === 'downloading' ? `下载中${pct == null ? '' : ' ' + pct + '%'}` : (pack.status === 'error' ? '失败' : '未安装')),
20407
+ installed ? 'ok' : 'warn'))),
20408
+ pack.status === 'downloading' ? React.createElement('div', {
20409
+ style: { height: '4px', borderRadius: '2px', background: 'rgba(255,255,255,.12)', marginTop: '6px', overflow: 'hidden' },
20410
+ }, React.createElement('div', {
20411
+ style: { width: `${pct == null ? 15 : pct}%`, height: '100%', background: 'rgba(120,190,255,.8)', transition: 'width 300ms' },
20412
+ })) : null,
20413
+ pack.status === 'error' && pack.reason
20414
+ ? React.createElement('div', { className: 'we-picker__hint', style: { color: '#f87171', margin: '3px 0 0' } }, pack.reason)
20415
+ : null,
20416
+ runtimeMissing
20417
+ ? React.createElement('div', { className: 'we-picker__hint', style: { color: '#fcd34d', margin: '3px 0 0' } },
20418
+ '模型已下载,但缺少 sherpa-onnx 高清运行时:试听会回落到内置音色(不假装出声)。')
20419
+ : null,
20420
+ React.createElement('div', { style: { ...PERSONA_STYLE.row, marginTop: '6px' } },
20421
+ installed ? personaButton(runtimeMissing ? '▶ 试听(回落)' : '▶ 试听', () => { void previewVoice(pack.voiceId); }, { disabled: previewId === pack.voiceId || runtimeMissing }) : null,
20422
+ !installed && pack.status !== 'downloading'
20423
+ ? personaButton(pack.status === 'error' ? '重试下载' : '下载', () => { void packAction('install', pack); }, { primary: true, disabled: voiceBusy === 'install:' + pack.id })
20424
+ : null,
20425
+ installed ? personaButton('设为全局默认', () => { void packAction('default', pack); }, { disabled: voiceBusy === 'default:' + pack.id }) : null,
20426
+ installed ? personaButton('删除', () => { void packAction('remove', pack); }, { danger: true, disabled: voiceBusy === 'remove:' + pack.id }) : null));
20427
+ };
20428
+
20429
+ const edgeGroupBox = (label, items) => {
20430
+ if (!items.length) return null;
20431
+ return React.createElement('div', { key: 'edge-' + label, style: { marginBottom: '6px' } },
20432
+ React.createElement('div', { style: { fontSize: '11px', opacity: .78, margin: '6px 0 2px' } }, `${label}(${items.length})`),
20433
+ React.createElement('div', { style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fill,minmax(240px,1fr))', gap: '6px' } },
20434
+ items.map((item) => voiceCard(item, { onDefault: (it) => { void setGlobalDefaultVoice(it.id, it.label); } }))));
20435
+ };
20436
+
20437
+ const volcPanel = () => {
20438
+ const center = (voiceCatalog && voiceCatalog.center) || {};
20439
+ const volc = center.volcengine || {};
20440
+ const configured = volc.configured === true;
20441
+ const statusText = configured ? (volc.lastOk ? '已测试通过' : '已配置(未测试)') : '未配置';
20442
+ const howTo = (voiceCatalog && voiceCatalog.howTo) || volc.howTo || [];
20443
+ const howToRows = howTo.map((step) => React.createElement('div', { key: step.step, style: { ...PERSONA_STYLE.card, padding: '7px 9px' } },
20444
+ React.createElement('div', { style: { fontSize: '12px', fontWeight: 600 } }, `${step.step}. ${step.title}`),
20445
+ React.createElement('div', { style: { fontSize: '11px', opacity: .82, marginTop: '2px', lineHeight: 1.5 } }, step.body),
20446
+ step.link ? React.createElement('a', {
20447
+ href: step.link, target: '_blank', rel: 'noreferrer',
20448
+ style: { fontSize: '10px', color: '#93c5fd' },
20449
+ }, step.link) : null));
20450
+ const header = React.createElement('div', { style: { ...PERSONA_STYLE.row, justifyContent: 'space-between' } },
20451
+ React.createElement('div', { style: { fontSize: '12px', fontWeight: 600 } }, '火山引擎(唯一在线供应商)',
20452
+ personaTag(statusText, configured ? (volc.lastOk ? 'ok' : 'warn') : 'warn')),
20453
+ personaButton(howToOpen ? '收起「如何获取」' : '如何获取 →', () => setHowToOpen((prev) => !prev)));
20454
+ const statusHint = configured
20455
+ ? React.createElement('div', { className: 'we-picker__hint', style: { margin: '2px 0 4px' } },
20456
+ `AppID ${volc.maskedAppId || '已保存'} · Token ${volc.maskedToken || '已保存'} · ${volc.cluster || ''} · ${volc.resourceId || ''}`)
20457
+ : null;
20458
+ const errorHint = volc.lastError
20459
+ ? React.createElement('div', { className: 'we-picker__hint', style: { color: '#f87171' } }, volc.lastError)
20460
+ : null;
20461
+ const credentialsGrid = React.createElement('div', { style: { display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '6px', marginTop: '4px' } },
20462
+ personaField('AppID', personaInput({
20463
+ value: volcForm.appId,
20464
+ placeholder: configured ? '留空不修改' : '火山控制台 → 应用管理',
20465
+ onChange: (v) => setVolcForm((prev) => ({ ...prev, appId: v })),
20466
+ })),
20467
+ personaField('Access Token', personaInput({
20468
+ type: 'password', value: volcForm.accessToken,
20469
+ placeholder: configured ? '留空不修改' : '应用详情 → Access Token',
20470
+ onChange: (v) => setVolcForm((prev) => ({ ...prev, accessToken: v })),
20471
+ })));
20472
+ const routingGrid = React.createElement('div', { style: { display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '6px' } },
20473
+ personaField('Cluster(传统 TTS)', personaInput({
20474
+ value: volcForm.cluster, placeholder: 'volcano_tts',
20475
+ onChange: (v) => setVolcForm((prev) => ({ ...prev, cluster: v })),
20476
+ })),
20477
+ personaField('Resource ID(Seed-TTS)', personaInput({
20478
+ value: volcForm.resourceId, placeholder: 'seed-tts-2.0',
20479
+ onChange: (v) => setVolcForm((prev) => ({ ...prev, resourceId: v })),
20480
+ })));
20481
+ const voiceGrid = React.createElement('div', { style: { display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '6px' } },
20482
+ personaField('适配器子类型', personaSelect({
20483
+ value: volcForm.subtype,
20484
+ onChange: (v) => setVolcForm((prev) => ({ ...prev, subtype: v })),
20485
+ options: [{ value: 'volc-seed-tts', label: 'volc-seed-tts(大模型)' }, { value: 'volc-tts', label: 'volc-tts(传统)' }],
20486
+ })),
20487
+ personaField('音色 ID', React.createElement('div', null,
20488
+ personaInput({
20489
+ value: volcForm.voiceId, placeholder: 'zh_female_..._uranus_bigtts',
20490
+ list: 'we-volc-voices',
20491
+ onChange: (v) => setVolcForm((prev) => ({ ...prev, voiceId: v })),
20492
+ }),
20493
+ React.createElement('datalist', { id: 'we-volc-voices' },
20494
+ (volc.voices || []).map((voice) => React.createElement('option', { key: voice.id, value: voice.id }, voice.label))))));
20495
+ const actions = React.createElement('div', { style: { ...PERSONA_STYLE.row, marginTop: '4px' } },
20496
+ personaButton('保存', () => { void saveVolc(); }, { primary: true, disabled: voiceBusy === 'volc-save' }),
20497
+ personaButton('测试', () => { void testVolc(); }, { disabled: voiceBusy === 'volc-test' }),
20498
+ personaButton('清除 Key', async () => {
20499
+ try {
20500
+ await apiPostJson('/pet-chat/voice/providers', { provider: 'volcengine', clearCredentials: true }, { parse: 'always' });
20501
+ setVolcNote({ ok: true, text: '已清除火山的 AppID / Token' });
20502
+ await loadVoiceCatalog();
20503
+ } catch { setVolcNote({ ok: false, text: '清除失败' }); }
20504
+ }, { danger: true }));
20505
+ const noteRow = volcNote
20506
+ ? React.createElement('div', { className: 'we-picker__hint', style: { color: volcNote.ok ? undefined : '#f87171', marginTop: '4px' } }, volcNote.text)
20507
+ : null;
20508
+ const howToBlock = howToOpen
20509
+ ? React.createElement('div', { style: { marginTop: '8px' } },
20510
+ React.createElement('div', { style: { fontSize: '12px', fontWeight: 600, marginBottom: '2px' } }, '如何获取(六步)'),
20511
+ howToRows)
20512
+ : null;
20513
+ return React.createElement('div', { style: { ...PERSONA_STYLE.card, padding: '10px' } },
20514
+ header, statusHint, errorHint, credentialsGrid, routingGrid, voiceGrid, actions, noteRow, howToBlock);
20515
+ };
20516
+
20517
+ const permissionRow = (group) => {
20518
+ const current = group.permission || 'deny';
20519
+ const locked = group.available === false || permBusy;
20520
+ return React.createElement('div', { key: group.id, style: { ...PERSONA_STYLE.card, padding: '8px 10px', opacity: group.available === false ? .62 : 1 } },
20521
+ React.createElement('div', { style: { ...PERSONA_STYLE.row, justifyContent: 'space-between', alignItems: 'flex-start' } },
20522
+ React.createElement('div', null,
20523
+ React.createElement('div', { style: { fontSize: '12px', fontWeight: 600 } },
20524
+ group.label,
20525
+ personaTag(group.riskLabel, group.risk === 'high' ? 'risk-high' : group.risk === 'medium' ? 'risk-medium' : 'risk-low'),
20526
+ group.advancedOnly ? personaTag('需高级权限', 'warn') : null),
20527
+ React.createElement('div', { className: 'we-picker__hint', style: { margin: '1px 0 0', fontSize: '10px' } }, group.desc)),
20528
+ React.createElement('div', { style: { ...PERSONA_STYLE.row, gap: '3px' } },
20529
+ [['allow', '允许'], ['ask', '询问'], ['deny', '禁止']].map(([value, label]) => personaButton(label, () => { void setPermissionGroup(group.id, value); }, {
20530
+ disabled: locked || current === value,
20531
+ style: current === value ? { borderColor: 'rgba(120,190,255,.7)', background: 'rgba(90,160,255,.16)' } : {},
20532
+ })))),
20533
+ group.available === false ? React.createElement('div', { className: 'we-picker__hint', style: { margin: '3px 0 0', fontSize: '10px' } },
20534
+ group.advancedOnly ? '打开下面的「高级权限」后才可用;打开后每个动作仍会二次确认。' : '当前不可用。') : null);
20535
+ };
20536
+
20537
+ const permissionLog = () => {
20538
+ const items = (perm.toolLog && perm.toolLog.items) || [];
20539
+ if (!items.length) return React.createElement('div', { className: 'we-picker__hint' }, '还没有调用记录。');
20540
+ return items.map((item) => React.createElement('div', { key: String(item.ts) + item.tool, style: { ...PERSONA_STYLE.card, padding: '6px 9px' } },
20541
+ React.createElement('div', { style: { ...PERSONA_STYLE.row, justifyContent: 'space-between' } },
20542
+ React.createElement('div', { style: { fontSize: '11px' } },
20543
+ `${new Date(item.ts).toLocaleString()} · ${item.tool}`,
20544
+ personaTag(item.permission || 'allow', item.permission === 'deny' ? 'risk-high' : item.permission === 'ask' ? 'risk-medium' : 'risk-low'),
20545
+ item.confirmed ? personaTag('已确认', 'ok') : null),
20546
+ React.createElement('div', { style: { fontSize: '10px', opacity: .72 } },
20547
+ `${item.result || ''}${item.verified ? ' · 已回读' : ''}`)),
20548
+ item.error ? React.createElement('div', { style: { fontSize: '10px', opacity: .7, marginTop: '1px' } }, item.error) : null));
20549
+ };
20550
+
20551
+ const voicePage = (() => {
20552
+ const voiceData = (p.express && p.express.voice) || {};
20553
+ const mode = voiceData.mode === 'fixed' ? 'fixed' : 'inherit';
20554
+ const center = (voiceCatalog && voiceCatalog.center) || {};
20555
+ const groups = (voiceCatalog && voiceCatalog.groups) || [];
20556
+ const builtin = groups.find((group) => group.key === 'builtin') || { items: [] };
20557
+ const edge = groups.find((group) => group.key === 'edge') || { items: [] };
20558
+ const providers = groups.find((group) => group.key === 'providers') || { items: [] };
20559
+ const packs = (voiceCatalog && voiceCatalog.packs) || [];
20560
+ const preferredLabel = (voiceCatalog && voiceCatalog.preferredLabel) || (center.preferred ? center.preferred : '');
20561
+ const currentId = mode === 'fixed' ? String(voiceData.id || voiceData.name || '') : '';
20562
+ const currentItem = builtin.items.concat(edge.items, providers.items).find((item) => item.id === currentId);
20563
+ const edgeByLang = {};
20564
+ for (const item of edge.items) {
20565
+ const key = item.langGroup || '其他';
20566
+ if (!edgeByLang[key]) edgeByLang[key] = [];
20567
+ edgeByLang[key].push(item);
20568
+ }
20569
+ const setFixed = (item) => {
20570
+ patchDraft((d) => {
20571
+ d.express.voice = {
20572
+ engine: item.engine || 'edge',
20573
+ id: item.id,
20574
+ name: String(item.id || '').replace(/^[a-z0-9-]+:/i, ''),
20575
+ rate: Number(d.express.voice && d.express.voice.rate) || 0,
20576
+ mode: 'fixed',
20577
+ };
20578
+ });
20579
+ setVoiceNote(null);
20580
+ };
20581
+ const setInherit = () => {
20582
+ patchDraft((d) => {
20583
+ d.express.voice = {
20584
+ ...(d.express.voice || {}),
20585
+ engine: 'inherit', id: '', name: '', mode: 'inherit',
20586
+ rate: Number(d.express.voice && d.express.voice.rate) || 0,
20587
+ };
20588
+ });
20589
+ };
20590
+ return React.createElement('div', null,
20591
+ React.createElement('div', { style: { fontSize: '12px', fontWeight: 600, marginBottom: '2px' } }, '音色'),
20592
+ React.createElement('label', { style: { ...PERSONA_STYLE.row, gap: '6px', padding: '4px 0', cursor: 'pointer' } },
20593
+ React.createElement('input', {
20594
+ type: 'radio', name: 'we-persona-voice-mode', checked: mode === 'inherit',
20595
+ onChange: setInherit,
20596
+ }),
20597
+ React.createElement('span', null, '继承全局',
20598
+ React.createElement('span', { style: { opacity: .72 } }, `(当前:${preferredLabel || '未设置'})`))),
20599
+ React.createElement('label', { style: { ...PERSONA_STYLE.row, gap: '6px', padding: '4px 0', cursor: 'pointer' } },
20600
+ React.createElement('input', {
20601
+ type: 'radio', name: 'we-persona-voice-mode', checked: mode === 'fixed',
20602
+ onChange: () => {
20603
+ if (mode === 'fixed') return;
20604
+ const fallback = currentItem
20605
+ || builtin.items.find((item) => item.status === 'ready')
20606
+ || edge.items.find((item) => item.status === 'ready')
20607
+ || edge.items[0];
20608
+ if (fallback) setFixed(fallback);
20609
+ },
20610
+ }),
20611
+ React.createElement('span', null, '指定音色',
20612
+ mode === 'fixed' && currentItem
20613
+ ? React.createElement('span', { style: { opacity: .72 } }, `(当前:${currentItem.label})`)
20614
+ : null)),
20615
+ mode === 'fixed' ? React.createElement('div', { style: { marginTop: '4px' } },
20616
+ React.createElement('div', { style: { fontSize: '11px', fontWeight: 600, margin: '4px 0 2px' } }, '内置音色包'),
20617
+ React.createElement('div', { style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fill,minmax(250px,1fr))', gap: '6px' } },
20618
+ builtin.items.map((item) => voiceCard(item, { selected: item.id === currentId, onPick: setFixed }))),
20619
+ React.createElement('div', { style: { fontSize: '11px', fontWeight: 600, margin: '8px 0 2px' } },
20620
+ '免费在线 · Edge', personaTag('可能限流', 'warn')),
20621
+ voiceCatalog && voiceCatalog.edgeRateLimited
20622
+ ? React.createElement('div', { className: 'we-picker__hint', style: { color: '#fcd34d' } },
20623
+ `在线音色被限流(429):已保留 ${voiceCatalog.rateLimitedCount || 0} 个并标注“暂不可用”,合成时会自动回落到内置音色。`)
20624
+ : null,
20625
+ Object.keys(edgeByLang).length
20626
+ ? Object.keys(edgeByLang).map((lang) => React.createElement('div', { key: 'pick-edge-' + lang },
20627
+ React.createElement('div', { style: { fontSize: '10px', opacity: .72, margin: '4px 0 2px' } }, lang),
20628
+ React.createElement('div', { style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fill,minmax(240px,1fr))', gap: '6px' } },
20629
+ edgeByLang[lang].map((item) => voiceCard(item, { selected: item.id === currentId, onPick: setFixed })))))
20630
+ : React.createElement('div', { className: 'we-picker__hint' }, '本机暂时拿不到 Edge 音色列表(可能被限流或断网);内置音色仍可用。'),
20631
+ React.createElement('div', { style: { fontSize: '11px', fontWeight: 600, margin: '8px 0 2px' } }, '我的在线音色 · 火山引擎'),
20632
+ providers.items.length
20633
+ ? React.createElement('div', { style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fill,minmax(240px,1fr))', gap: '6px' } },
20634
+ providers.items.map((item) => voiceCard(item, { selected: item.id === currentId, onPick: setFixed })))
20635
+ : React.createElement('div', { className: 'we-picker__hint' }, '还没有配置火山:在下方「全局音色中心 → 火山引擎」填 AppID / Access Token。')) : null,
20636
+ personaField('语速(-10…10)', personaInput({
20637
+ type: 'number', value: p.express.voice.rate,
20638
+ onChange: (v) => patchDraft((d) => { d.express.voice.rate = Number(v); }),
20639
+ })),
20640
+ personaField('长度策略', personaSelect({
20641
+ value: p.express.lengthPolicy, onChange: (v) => patchDraft((d) => { d.express.lengthPolicy = v; }),
20642
+ options: [{ value: 'adaptive', label: '自适应' }, { value: 'short', label: '短' }, { value: 'long', label: '长' }],
20643
+ })),
20644
+ React.createElement('div', { className: 'we-picker__hint' },
20645
+ mode === 'fixed'
20646
+ ? '指定音色只影响这个人设;保存后下一句生效。音色不可用时会自动回落到“继承全局”的启用音色。'
20647
+ : '继承全局:下面「全局音色中心」的默认音色对所有“继承全局”的人设同时生效。'),
20648
+ React.createElement('div', { style: { ...PERSONA_STYLE.row, margin: '4px 0' } },
20649
+ personaButton('▶ 试听当前音色', () => {
20650
+ const id = mode === 'fixed' ? currentId : (voiceCatalog && voiceCatalog.preferred);
20651
+ if (id) void previewVoice(id);
20652
+ }, { disabled: !(mode === 'fixed' ? currentId : (voiceCatalog && voiceCatalog.preferred)) || Boolean(previewId) })),
20653
+ voiceNote ? React.createElement('div', { className: 'we-picker__hint', style: { color: voiceNote.ok ? undefined : '#f87171' } }, voiceNote.text) : null,
20654
+
20655
+ React.createElement('div', { style: { marginTop: '14px', paddingTop: '10px', borderTop: '1px solid rgba(255,255,255,.10)' } },
20656
+ React.createElement('div', { style: { fontSize: '13px', fontWeight: 600 } }, '全局音色中心',
20657
+ personaTag('只对“继承全局”生效', 'warn')),
20658
+ React.createElement('div', { className: 'we-picker__hint', style: { margin: '2px 0 6px' } },
20659
+ `当前全局默认:${preferredLabel || '未设置'}。下载/删除只影响本机;设为默认会让所有“继承全局”的人设跟随。`),
20660
+ React.createElement('div', { style: { fontSize: '11px', fontWeight: 600, margin: '4px 0' } }, '内置音色包'),
20661
+ packs.map(packRow),
20662
+ React.createElement('div', { style: { fontSize: '11px', fontWeight: 600, margin: '8px 0 2px' } }, '免费在线 · Edge 分组'),
20663
+ Object.keys(edgeByLang).length
20664
+ ? Object.keys(edgeByLang).map((lang) => edgeGroupBox(lang, edgeByLang[lang]))
20665
+ : React.createElement('div', { className: 'we-picker__hint' }, '暂时没有可用的 Edge 音色列表。'),
20666
+ React.createElement('div', { style: { fontSize: '11px', fontWeight: 600, margin: '8px 0 2px' } }, '我的在线音色'),
20667
+ volcPanel(),
20668
+ React.createElement('div', { style: { ...PERSONA_STYLE.row, marginTop: '6px' } },
20669
+ personaButton('刷新音色目录', () => { void loadVoiceCatalog(); }),
20670
+ personaButton('试听全局默认', () => {
20671
+ const id = voiceCatalog && voiceCatalog.preferred;
20672
+ if (id) void previewVoice(id);
20673
+ }, { disabled: !(voiceCatalog && voiceCatalog.preferred) || Boolean(previewId) }))));
20674
+ })();
20043
20675
 
20044
20676
  const permissionsPage = React.createElement('div', null,
20045
- React.createElement('div', { style: { fontSize: '12px' } }, '助手人设可以使用系统工具(换壁纸、提醒、桌宠设置等)。'),
20046
- React.createElement('div', { className: 'we-picker__hint', style: { marginTop: '4px' } }, '特殊人设没有这一页,也不能使用任何系统工具。'));
20677
+ perm.isCharacter
20678
+ ? React.createElement('div', { style: { ...PERSONA_STYLE.card, borderColor: 'rgba(251,191,36,.45)' } },
20679
+ React.createElement('div', { style: { fontSize: '13px', fontWeight: 600 } }, '特殊人设不能使用系统工具'),
20680
+ React.createElement('div', { className: 'we-picker__hint', style: { marginTop: '3px' } },
20681
+ '这是代码层强制:即使提示词要求它换壁纸/卸载/读文件,工具层也会拒绝。声音页仍可正常选音色与试听。'))
20682
+ : React.createElement('div', null,
20683
+ React.createElement('div', { style: { fontSize: '12px', fontWeight: 600, marginBottom: '2px' } }, '工具组权限'),
20684
+ React.createElement('div', { className: 'we-picker__hint', style: { marginBottom: '4px' } },
20685
+ '允许 = 直接做;询问 = 先问一句,说「好」或在气泡点「允许」才做;禁止 = 明确拒绝。'),
20686
+ perm.loading ? React.createElement('div', { className: 'we-picker__hint' }, '正在读取权限…') : null,
20687
+ perm.groups.map(permissionRow),
20688
+ React.createElement('label', { style: { ...PERSONA_STYLE.row, gap: '6px', margin: '8px 0 2px', cursor: permBusy ? 'default' : 'pointer' } },
20689
+ React.createElement('input', {
20690
+ type: 'checkbox', checked: perm.advanced === true, disabled: permBusy,
20691
+ onChange: (e) => { void setAdvancedPermission(e.target.checked); },
20692
+ }),
20693
+ React.createElement('span', null, '高级权限',
20694
+ React.createElement('span', { style: { opacity: .72 } }, '(允许系统级操作;每个动作仍会二次确认)'))),
20695
+ permNote ? React.createElement('div', { className: 'we-picker__hint', style: { color: permNote.ok ? undefined : '#f87171' } }, permNote.text) : null,
20696
+ React.createElement('div', { style: { fontSize: '12px', fontWeight: 600, marginTop: '10px' } },
20697
+ '最近调用记录', personaTag(`共 ${perm.toolLog ? perm.toolLog.total : 0} 条`, '')),
20698
+ React.createElement('div', { style: { ...PERSONA_STYLE.row, gap: '4px', margin: '3px 0 4px' } },
20699
+ personaButton('刷新', () => { if (draft) void loadPermissions(draft.id); }),
20700
+ personaButton('清空记录', () => { void clearToolLog(); }, { danger: true, disabled: permBusy })),
20701
+ permissionLog()));
20047
20702
 
20048
20703
  const memoryPage = React.createElement('div', null,
20049
20704
  React.createElement('div', { style: { ...PERSONA_STYLE.row, marginBottom: '6px' } },
@@ -20093,7 +20748,7 @@ window.__ModuleLoader__.load({
20093
20748
  style: currentTab === tab.id ? { borderColor: 'rgba(120,190,255,.7)' } : {},
20094
20749
  }))),
20095
20750
  React.createElement('div', { style: { marginTop: '8px' } }, pages[currentTab] || basicPage),
20096
- saveRow,
20751
+ currentTab === 'permissions' ? null : saveRow,
20097
20752
  note ? React.createElement('div', { className: 'we-picker__hint', style: { color: note.ok ? undefined : '#f87171', marginTop: '5px' } }, note.text) : null);
20098
20753
  }
20099
20754
 
@@ -20789,6 +21444,9 @@ window.__ModuleLoader__.load({
20789
21444
 
20790
21445
  if (tab === 'voice') {
20791
21446
  const voicePage = [];
21447
+ voicePage.push(React.createElement('div', {
21448
+ key: 'voice-center-moved', className: 'we-picker__hint', style: { margin: '0 0 6px', opacity: .85 },
21449
+ }, weT('音色库与全局音色中心已移到人物详情里的「声音」页:内置音色包、Edge 分组、火山引擎配置都在那里;这里保留朗读开关与一键启用。')));
20792
21450
  voicePage.push(React.createElement('label', {
20793
21451
  key: 'speak-toggle',
20794
21452
  style: { display: 'flex', gap: '6px', alignItems: 'center', fontSize: '12px', margin: '6px 0 2px' },
@@ -24334,6 +24992,24 @@ window.__ModuleLoader__.load({
24334
24992
  * 失败返回 `{ok:false,error}`,由宿主统一说人话 —— 这里只负责把真实结果回执回去。
24335
24993
  */
24336
24994
  async function petChatApplyAction(tool, args) {
24995
+ if (tool === 'wallpaper_cycle') {
24996
+ const enabled = !(args && args.enabled === false);
24997
+ const before = Boolean(selection && selection.rotationEnabled);
24998
+ try {
24999
+ onToggleRotation();
25000
+ } catch {
25001
+ return { ok: false, error: 'apply-failed' };
25002
+ }
25003
+ await new Promise((resolve) => { setTimeout(resolve, 200); });
25004
+ const now = Boolean(selection && selection.rotationEnabled);
25005
+ if (now !== enabled) {
25006
+ // 状态没切到目标值(例如轮播候选为空被自动关掉)⇒ 如实回执,不谎报成功。
25007
+ if (before !== enabled) { try { onToggleRotation(); } catch { /* ignore */ } }
25008
+ return { ok: false, error: 'not-applied', enabled: now };
25009
+ }
25010
+ petBubble.status('info', enabled ? weT('轮播打开了') : weT('轮播关掉了'), { delay: 1800 });
25011
+ return { ok: true, enabled: now, rotationEnabled: now };
25012
+ }
24337
25013
  if (tool !== 'wallpaper_switch') return { ok: false, error: 'unsupported' };
24338
25014
  const input = args || {};
24339
25015
  let list;
@@ -24392,8 +25068,7 @@ window.__ModuleLoader__.load({
24392
25068
  }
24393
25069
 
24394
25070
  /** SSE action → 执行 → POST 回执。宿主据此**回读设置**再决定说不说成功。 */
24395
- async function petChatHandleAction(payload) {
24396
- const id = String((payload && payload.id) || '');
25071
+ async function petChatHandleAction(payload) { const id = String((payload && payload.id) || '');
24397
25072
  if (!id) return;
24398
25073
  let result;
24399
25074
  try {
@@ -24412,6 +25087,87 @@ window.__ModuleLoader__.load({
24412
25087
  } catch { /* 回执失败由宿主超时判失败,不会谎报成功 */ }
24413
25088
  }
24414
25089
 
25090
+ /* ── v2 权限确认:气泡按钮(与语音说「好」等价)─────────────────────────── */
25091
+
25092
+ let petChatConfirmNode = null;
25093
+
25094
+ function petChatConfirmHide() {
25095
+ if (!petChatConfirmNode) return;
25096
+ try { petChatConfirmNode.remove(); } catch { /* ignore */ }
25097
+ petChatConfirmNode = null;
25098
+ }
25099
+
25100
+ /**
25101
+ * 宿主发来 confirm 事件 → 在桌宠旁显示一行确认条:
25102
+ * [允许] [不允许] [以后都允许] [以后都别问]
25103
+ * 点击走 POST /pet-chat/tool-confirm;宿主执行完用 /speak 广播结果(本端会朗读)。
25104
+ */
25105
+ function petChatConfirmShow(payload) {
25106
+ if (typeof document === 'undefined' || !payload || !payload.id) return;
25107
+ petChatConfirmHide();
25108
+ const box = document.createElement('div');
25109
+ box.id = 'we-pet-tool-confirm';
25110
+ box.dataset.tool = String(payload.tool || '');
25111
+ Object.assign(box.style, {
25112
+ position: 'fixed', left: '50%', bottom: '96px', transform: 'translateX(-50%)',
25113
+ zIndex: '2147483000', maxWidth: 'min(560px, calc(100vw - 32px))',
25114
+ padding: '10px 12px', borderRadius: '12px', background: 'rgba(22,24,30,.94)',
25115
+ border: '1px solid rgba(255,255,255,.18)', boxShadow: '0 10px 30px rgba(0,0,0,.35)',
25116
+ color: '#eef1f6', font: '12px/1.5 system-ui, "Segoe UI", sans-serif',
25117
+ display: 'flex', flexDirection: 'column', gap: '8px',
25118
+ });
25119
+ const question = document.createElement('div');
25120
+ question.textContent = String(payload.question || weT('要执行这个操作吗?'));
25121
+ box.appendChild(question);
25122
+ const row = document.createElement('div');
25123
+ Object.assign(row.style, { display: 'flex', gap: '6px', flexWrap: 'wrap', justifyContent: 'flex-end' });
25124
+ const finish = async (decision) => {
25125
+ petChatConfirmHide();
25126
+ try {
25127
+ const resp = await apiPostJson('/pet-chat/tool-confirm', { id: payload.id, decision }, { parse: 'always' });
25128
+ const data = (resp && resp.data) || {};
25129
+ if (data.clientAction) {
25130
+ const action = data.clientAction;
25131
+ const result = await petChatApplyAction(String(action.tool || ''), action.args || {});
25132
+ let say = '';
25133
+ if (action.tool === 'wallpaper_cycle') say = result.ok ? (result.enabled ? '轮播打开了。' : '轮播关掉了。') : '轮播没切成功。';
25134
+ else if (result.ok) say = result.title ? `换成「${result.title}」了。` : '换好了。';
25135
+ else say = result.error === 'no-match' ? '没找到那张壁纸。' : '没换成,再试一次吧。';
25136
+ petBubble.show(say);
25137
+ petSpeak(say);
25138
+ return;
25139
+ }
25140
+ if (data.say && decision === 'deny') petBubble.show(String(data.say));
25141
+ if (data.say && data.ok === false) petBubble.status('error', String(data.say), { delay: 4000 });
25142
+ } catch {
25143
+ petBubble.status('error', weT('确认没发出去,再试一次'), { delay: 4000 });
25144
+ }
25145
+ };
25146
+ const button = (label, decision, primary) => {
25147
+ const el = document.createElement('button');
25148
+ el.type = 'button';
25149
+ el.textContent = label;
25150
+ Object.assign(el.style, {
25151
+ border: '1px solid ' + (primary ? 'rgba(120,190,255,.65)' : 'rgba(255,255,255,.2)'),
25152
+ borderRadius: '8px', padding: '5px 12px', cursor: 'pointer',
25153
+ background: primary ? 'rgba(90,160,255,.22)' : 'rgba(255,255,255,.05)',
25154
+ color: 'inherit', font: 'inherit',
25155
+ });
25156
+ el.addEventListener('click', (event) => {
25157
+ try { event.preventDefault(); event.stopPropagation(); } catch { /* ignore */ }
25158
+ void finish(decision);
25159
+ });
25160
+ return el;
25161
+ };
25162
+ row.appendChild(button(weT('允许'), 'allow', true));
25163
+ row.appendChild(button(weT('不允许'), 'deny', false));
25164
+ row.appendChild(button(weT('以后都允许'), 'always', false));
25165
+ row.appendChild(button(weT('以后都别问'), 'never', false));
25166
+ box.appendChild(row);
25167
+ document.body.appendChild(box);
25168
+ petChatConfirmNode = box;
25169
+ }
25170
+
24415
25171
  /** 每 4 秒看一次壁纸是否变化;变化满 30 秒且不忙时点评一句。 */
24416
25172
  function petChatWatchWallpaper() {
24417
25173
  if (typeof setInterval !== 'function') return null;
@@ -24621,6 +25377,11 @@ window.__ModuleLoader__.load({
24621
25377
  petChatSpeechRate = Number.isFinite(Number(payload.rate)) ? Number(payload.rate) : 0;
24622
25378
  continue;
24623
25379
  }
25380
+ if (eventName === 'confirm') {
25381
+ // v2:权限为 ask 时宿主先发 confirm;语音说「好」或点气泡按钮后才执行。
25382
+ petChatConfirmShow(payload);
25383
+ continue;
25384
+ }
24624
25385
  if (eventName === 'action') {
24625
25386
  // 不 await:继续读流,宿主在收到 /tool-result 后才发后续 delta/done。
24626
25387
  void petChatHandleAction(payload);
@@ -24915,6 +25676,7 @@ window.__ModuleLoader__.load({
24915
25676
  petChatGreetingTimer = null;
24916
25677
  petChatEventsStop();
24917
25678
  petSpeakStop();
25679
+ petChatConfirmHide();
24918
25680
  try { if (window.__dshFoliaPet) delete window.__dshFoliaPet; } catch { /* ignore */ }
24919
25681
  petBubble.dispose();
24920
25682
  };