dsh-folia 4.26.0-pre.73 → 4.26.0-pre.76
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 +660 -173
- package/lib/persona-store.js +87 -6
- package/lib/pet-chat-brain.js +340 -11
- package/lib/pet-chat-tools.js +255 -1
- package/lib/routes/pet-chat.js +454 -24
- package/lib/tts/tts-worker.cjs +540 -63
- package/lib/tts/tts.js +58 -2
- package/lib/tts/voice-center.js +46 -3
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -755,6 +755,25 @@ window.__ModuleLoader__.load({
|
|
|
755
755
|
"连续对话已停止:{e}": "Continuous conversation stopped: {e}",
|
|
756
756
|
"连续对话结束:连续 {n} 轮没听到": "Continuous conversation ended: no speech for {n} rounds",
|
|
757
757
|
"没听到,再说一次({n}/{m})": "Didn't hear that — try again ({n}/{m})",
|
|
758
|
+
// v3:常驻聆听 + 暂停说话 / 暂停聆听(任务 §4)
|
|
759
|
+
"暂停说话": "Mute speech",
|
|
760
|
+
"暂停聆听": "Pause listening",
|
|
761
|
+
"继续聆听": "Resume listening",
|
|
762
|
+
"常驻聆听中": "Always listening",
|
|
763
|
+
"麦克风已暂停": "Microphone paused",
|
|
764
|
+
"🎤 麦克风已暂停": "🎤 Microphone paused",
|
|
765
|
+
"🔇 仅文字": "🔇 Subtitles only",
|
|
766
|
+
"仅文字": "Subtitles only",
|
|
767
|
+
"🔇 仅文字(继续听,不出声)": "🔇 Subtitles only (still listening, no sound)",
|
|
768
|
+
"🔊 声音已恢复": "🔊 Sound is back",
|
|
769
|
+
"⏸ 麦克风已暂停(右键「继续聆听」恢复)": "⏸ Microphone paused (right-click 'Resume listening' to restore)",
|
|
770
|
+
"还在听(没听到人声,{n} 次)": "Still listening (no voice, {n} times)",
|
|
771
|
+
"常驻聆听已暂停:{e}(右键「继续聆听」重试)": "Always-listening paused: {e} (right-click 'Resume listening' to retry)",
|
|
772
|
+
"这个 DSH 版本没有语音转写服务:常驻聆听不可用,先打字吧": "This DSH build has no speech-to-text service — always-listening is unavailable, please type instead",
|
|
773
|
+
// v3:气泡美化(展开 / 复制)
|
|
774
|
+
"展开": "Expand",
|
|
775
|
+
"复制": "Copy",
|
|
776
|
+
"复制失败:这个环境没有剪贴板权限": "Copy failed: no clipboard permission in this environment",
|
|
758
777
|
// pre.64:大脑 v2(壁纸动作的客户端执行反馈)
|
|
759
778
|
"正在换壁纸…": "Switching wallpaper…",
|
|
760
779
|
"没找到叫「{name}」的壁纸": "No wallpaper named '{name}' was found",
|
|
@@ -1425,6 +1444,8 @@ window.__ModuleLoader__.load({
|
|
|
1425
1444
|
"下载失败:{e}": "Download failed: {e}",
|
|
1426
1445
|
"下载中断,正在重试(第 {n}/{m} 次)": "Download interrupted; retrying ({n}/{m})",
|
|
1427
1446
|
"正在下载离线音色{n}": "Downloading offline voice{n}",
|
|
1447
|
+
"先填模型 Key,我才能听懂你说话(设置 → 智能大肥鱼)": "Add a model key first so I can hear you (Settings → Smart Fish).",
|
|
1448
|
+
"我会一直听着,直接说话就行;右键可「暂停聆听」": "I stay listening — just speak; right-click to pause listening.",
|
|
1428
1449
|
};
|
|
1429
1450
|
|
|
1430
1451
|
// ── 内联模块:src/i18n-copy-picker.js —— 英文词表域:壁纸选择器与快捷面板(picker-* · quick-panel · sidebar-right · theme-follow)(构建期注入;勿手改本段)──
|
|
@@ -19475,7 +19496,9 @@ window.__ModuleLoader__.load({
|
|
|
19475
19496
|
subtype: 'volc-seed-tts', voiceId: 'zh_female_shuangkuaisisi_uranus_bigtts',
|
|
19476
19497
|
});
|
|
19477
19498
|
const [volcNote, setVolcNote] = React.useState(null);
|
|
19478
|
-
const [
|
|
19499
|
+
const [volcDiag, setVolcDiag] = React.useState(null);
|
|
19500
|
+
const [perm, setPerm] = React.useState({ loading: false, advanced: false, preset: '', presets: [], groups: [], toolLog: { items: [], total: 0 }, isCharacter: false, message: '' });
|
|
19501
|
+
const [toolWl, setToolWl] = React.useState({ loading: false, domains: '', apps: '', note: null });
|
|
19479
19502
|
const [permBusy, setPermBusy] = React.useState(false);
|
|
19480
19503
|
const [permNote, setPermNote] = React.useState(null);
|
|
19481
19504
|
const [wizard, setWizard] = React.useState({ step: 1, name: '', nickname: '', tone: '温柔', relation: '' });
|
|
@@ -19718,6 +19741,8 @@ window.__ModuleLoader__.load({
|
|
|
19718
19741
|
setPerm({
|
|
19719
19742
|
loading: false,
|
|
19720
19743
|
advanced: data.advanced === true,
|
|
19744
|
+
preset: String(data.preset || ''),
|
|
19745
|
+
presets: Array.isArray(data.presets) ? data.presets : [],
|
|
19721
19746
|
groups: Array.isArray(data.groups) ? data.groups : [],
|
|
19722
19747
|
isCharacter: data.isCharacter === true,
|
|
19723
19748
|
message: String(data.message || ''),
|
|
@@ -19728,6 +19753,35 @@ window.__ModuleLoader__.load({
|
|
|
19728
19753
|
}
|
|
19729
19754
|
}, []);
|
|
19730
19755
|
|
|
19756
|
+
/** 工具白名单(任务 §6②:open_url 域名 / app_launch 应用,用户可编辑)。 */
|
|
19757
|
+
const loadToolWhitelist = React.useCallback(async () => {
|
|
19758
|
+
try {
|
|
19759
|
+
const data = unwrap(await apiJson('/pet-chat/tools/whitelist', { parse: 'always' }));
|
|
19760
|
+
setToolWl({
|
|
19761
|
+
loading: false,
|
|
19762
|
+
domains: Array.isArray(data.domains) ? data.domains.join(', ') : '',
|
|
19763
|
+
apps: Array.isArray(data.apps) ? data.apps.map((item) => item.id || item).join(', ') : '',
|
|
19764
|
+
note: null,
|
|
19765
|
+
});
|
|
19766
|
+
} catch {
|
|
19767
|
+
setToolWl((prev) => ({ ...prev, loading: false, note: { ok: false, text: '读取白名单失败' } }));
|
|
19768
|
+
}
|
|
19769
|
+
}, []);
|
|
19770
|
+
|
|
19771
|
+
const saveToolWhitelist = async () => {
|
|
19772
|
+
setPermBusy(true);
|
|
19773
|
+
try {
|
|
19774
|
+
const domains = String(toolWl.domains || '').split(/[,,\s]+/).map((item) => item.trim()).filter(Boolean);
|
|
19775
|
+
const apps = String(toolWl.apps || '').split(/[,,\s]+/).map((item) => item.trim()).filter(Boolean);
|
|
19776
|
+
const data = unwrap(await apiPostJson('/pet-chat/tools/whitelist', { domains, apps }, { parse: 'always' }));
|
|
19777
|
+
if (!data.ok) throw new Error(data.hint || 'save-failed');
|
|
19778
|
+
setToolWl((prev) => ({ ...prev, note: { ok: true, text: '白名单已保存' } }));
|
|
19779
|
+
await loadToolWhitelist();
|
|
19780
|
+
} catch (error) {
|
|
19781
|
+
setToolWl((prev) => ({ ...prev, note: { ok: false, text: String((error && error.message) || '保存失败') } }));
|
|
19782
|
+
} finally { setPermBusy(false); }
|
|
19783
|
+
};
|
|
19784
|
+
|
|
19731
19785
|
/** 下载/删除/设默认之后把包状态合并回目录(不重新拉 Edge 列表)。 */
|
|
19732
19786
|
const mergePackState = (packs) => {
|
|
19733
19787
|
setVoiceCatalog((prev) => {
|
|
@@ -19766,36 +19820,59 @@ window.__ModuleLoader__.load({
|
|
|
19766
19820
|
|
|
19767
19821
|
const previewVoice = React.useCallback(async (id) => {
|
|
19768
19822
|
if (!id) return;
|
|
19823
|
+
// 任务 §1②:播放前先告诉用户「正在用哪个引擎合成」,失败照实报,不静默换音色。
|
|
19824
|
+
const engine = String(id).split(':')[0] || 'tts';
|
|
19769
19825
|
setPreviewId(id);
|
|
19770
|
-
setVoiceNote(
|
|
19826
|
+
setVoiceNote({ ok: true, text: `正在用 ${engine} 合成…(试听不回落,失败会照实报)` });
|
|
19771
19827
|
try {
|
|
19772
19828
|
const resp = await apiFetch('/pet-chat/voice/preview', {
|
|
19773
19829
|
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
|
19774
19830
|
body: JSON.stringify({ id }), parse: false,
|
|
19775
19831
|
});
|
|
19832
|
+
// ⚠️ 二进制消费者:blob() 必须紧跟同一个 apiFetch 调用窗(verify-api-client 的 ①b)。
|
|
19833
|
+
// 先拿 blob,再读响应头(哪个引擎 / 有没有回落);失败分支再用 json() 读原因。
|
|
19834
|
+
const blob = resp && resp.ok ? await resp.response.blob() : null;
|
|
19776
19835
|
if (!resp || !resp.ok) {
|
|
19836
|
+
let code = String((resp && resp.status) || '');
|
|
19777
19837
|
let hint = '';
|
|
19838
|
+
let engineOut = engine;
|
|
19778
19839
|
try {
|
|
19779
19840
|
const doc = await resp.response.json();
|
|
19780
|
-
|
|
19841
|
+
code = doc.code || code;
|
|
19842
|
+
hint = doc.hint || '';
|
|
19843
|
+
engineOut = doc.engine || engine;
|
|
19781
19844
|
} catch { /* ignore */ }
|
|
19782
|
-
setVoiceNote({
|
|
19845
|
+
setVoiceNote({
|
|
19846
|
+
ok: false,
|
|
19847
|
+
text: `试听失败(${engineOut || engine} · ${code || 'tts-failed'}):${hint || '这个音色现在合成不了,不会偷偷换成别的音色'}`,
|
|
19848
|
+
});
|
|
19783
19849
|
setPreviewId('');
|
|
19784
19850
|
return;
|
|
19785
19851
|
}
|
|
19786
|
-
|
|
19852
|
+
let usedEngine = engine;
|
|
19853
|
+
let fallback = false;
|
|
19854
|
+
try {
|
|
19855
|
+
usedEngine = String(resp.response.headers.get('x-folia-tts-engine') || engine);
|
|
19856
|
+
fallback = String(resp.response.headers.get('x-folia-tts-fallback') || '0') === '1';
|
|
19857
|
+
} catch { /* 头读不到不影响播放 */ }
|
|
19787
19858
|
const url = URL.createObjectURL(blob);
|
|
19788
19859
|
const audio = new Audio(url);
|
|
19789
19860
|
const cleanup = () => { try { URL.revokeObjectURL(url); } catch { /* ignore */ } setPreviewId(''); };
|
|
19790
19861
|
audio.onended = cleanup;
|
|
19791
|
-
audio.onerror = () => { cleanup(); setVoiceNote({ ok: false, text: '
|
|
19862
|
+
audio.onerror = () => { cleanup(); setVoiceNote({ ok: false, text: '试听音频播放失败(文件坏了或播放器不可用)' }); };
|
|
19792
19863
|
const played = audio.play();
|
|
19864
|
+
setVoiceNote({
|
|
19865
|
+
ok: fallback !== true,
|
|
19866
|
+
text: fallback
|
|
19867
|
+
? `正在用 ${usedEngine} 播放,但宿主报告发生了回落(不该出现在试听里,请反馈)`
|
|
19868
|
+
: `正在用 ${usedEngine} 播放试听:${id}`,
|
|
19869
|
+
});
|
|
19793
19870
|
if (played && typeof played.catch === 'function') {
|
|
19794
19871
|
played.catch(() => { cleanup(); setVoiceNote({ ok: false, text: '浏览器拦截了自动播放,再点一次 ▶' }); });
|
|
19795
19872
|
}
|
|
19796
19873
|
} catch {
|
|
19797
19874
|
setPreviewId('');
|
|
19798
|
-
setVoiceNote({ ok: false, text: '
|
|
19875
|
+
setVoiceNote({ ok: false, text: '试听请求失败(宿主没响应)' });
|
|
19799
19876
|
}
|
|
19800
19877
|
}, []);
|
|
19801
19878
|
|
|
@@ -19823,7 +19900,8 @@ window.__ModuleLoader__.load({
|
|
|
19823
19900
|
if (detailTab === 'voice' && !voices.length) void loadVoices();
|
|
19824
19901
|
if (detailTab === 'voice' && !voiceCatalog) void loadVoiceCatalog();
|
|
19825
19902
|
if (detailTab === 'permissions') void loadPermissions(selected.id);
|
|
19826
|
-
|
|
19903
|
+
if (detailTab === 'permissions') void loadToolWhitelist();
|
|
19904
|
+
}, [selected, detailTab, loadMemory, loadVoices, voices.length, voiceCatalog, loadVoiceCatalog, loadPermissions, loadToolWhitelist]);
|
|
19827
19905
|
|
|
19828
19906
|
const packAction = async (kind, pack) => {
|
|
19829
19907
|
if (!pack) return;
|
|
@@ -19893,6 +19971,7 @@ window.__ModuleLoader__.load({
|
|
|
19893
19971
|
const testVolc = async () => {
|
|
19894
19972
|
setVoiceBusy('volc-test');
|
|
19895
19973
|
setVolcNote({ ok: true, text: '正在真调火山(最长 25 秒)…' });
|
|
19974
|
+
setVolcDiag(null);
|
|
19896
19975
|
try {
|
|
19897
19976
|
if (volcForm.appId.trim() || volcForm.accessToken.trim()) {
|
|
19898
19977
|
const saved = unwrap(await apiPostJson('/pet-chat/voice/providers', {
|
|
@@ -19907,11 +19986,21 @@ window.__ModuleLoader__.load({
|
|
|
19907
19986
|
if (!saved.ok) throw new Error(saved.error || 'save-failed');
|
|
19908
19987
|
}
|
|
19909
19988
|
const data = unwrap(await apiPostJson('/pet-chat/voice/providers/test', { provider: 'volcengine' }, { parse: 'always' }));
|
|
19989
|
+
// 任务 §2①:把真实诊断(状态码 / 响应片段 / URL / ResourceId / 音色 / 子类型)原样显示。
|
|
19990
|
+
setVolcDiag({
|
|
19991
|
+
status: data.status, code: data.code, bodySnippet: data.bodySnippet,
|
|
19992
|
+
url: data.url, resourceId: data.resourceId, voiceId: data.voiceId,
|
|
19993
|
+
subtype: data.subtype, hint: data.hint, maskedAppId: data.maskedAppId, maskedToken: data.maskedToken,
|
|
19994
|
+
});
|
|
19910
19995
|
if (data.ok) {
|
|
19911
|
-
|
|
19912
|
-
|
|
19996
|
+
setVolcNote({
|
|
19997
|
+
ok: true,
|
|
19998
|
+
text: `火山已接通(已验证):${data.subtype || volcForm.subtype} · ${data.resourceId || volcForm.resourceId} · ${data.voiceId || volcForm.voiceId}`,
|
|
19999
|
+
});
|
|
19913
20000
|
} else {
|
|
19914
|
-
|
|
20001
|
+
const parts = [`HTTP ${data.status || 0}`, data.code || 'failed', data.error || '测试失败'];
|
|
20002
|
+
if (data.hint) parts.push(`→ ${data.hint}`);
|
|
20003
|
+
setVolcNote({ ok: false, text: parts.join(' · ') });
|
|
19915
20004
|
}
|
|
19916
20005
|
await loadVoiceCatalog();
|
|
19917
20006
|
} catch (error) {
|
|
@@ -19919,6 +20008,22 @@ window.__ModuleLoader__.load({
|
|
|
19919
20008
|
} finally { setVoiceBusy(''); }
|
|
19920
20009
|
};
|
|
19921
20010
|
|
|
20011
|
+
/** 权限预设:标准 / 宽松 / 自定义(任务 §6①)。 */
|
|
20012
|
+
const setPermissionPreset = async (preset) => {
|
|
20013
|
+
if (!draft) return;
|
|
20014
|
+
setPermBusy(true);
|
|
20015
|
+
setPermNote(null);
|
|
20016
|
+
try {
|
|
20017
|
+
const data = unwrap(await apiPostJson('/pet-chat/personas/' + encodeURIComponent(draft.id) + '/permissions/preset', { preset }, { parse: 'always' }));
|
|
20018
|
+
if (!data.ok) throw new Error(data.hint || data.message || 'preset-failed');
|
|
20019
|
+
setPermNote({ ok: true, text: data.message || '预设已应用' });
|
|
20020
|
+
await loadPermissions(draft.id);
|
|
20021
|
+
} catch (error) {
|
|
20022
|
+
setPermNote({ ok: false, text: String((error && error.message) || '预设应用失败') });
|
|
20023
|
+
await loadPermissions(draft.id);
|
|
20024
|
+
} finally { setPermBusy(false); }
|
|
20025
|
+
};
|
|
20026
|
+
|
|
19922
20027
|
const setPermissionGroup = async (group, level) => {
|
|
19923
20028
|
if (!draft) return;
|
|
19924
20029
|
setPermBusy(true);
|
|
@@ -20406,7 +20511,11 @@ window.__ModuleLoader__.load({
|
|
|
20406
20511
|
const center = (voiceCatalog && voiceCatalog.center) || {};
|
|
20407
20512
|
const volc = center.volcengine || {};
|
|
20408
20513
|
const configured = volc.configured === true;
|
|
20409
|
-
|
|
20514
|
+
// 任务 §2④:已配置 → 已验证(最后一次真实测试通过);并把实际用的子类型/资源 ID 显示出来。
|
|
20515
|
+
const verified = volc.verified === true || volc.lastOk === true;
|
|
20516
|
+
const statusText = configured ? (verified ? '已验证' : '已配置(未验证)') : '未配置';
|
|
20517
|
+
const usedSubtype = volc.verifiedSubtype || volc.subtype || '';
|
|
20518
|
+
const usedResourceId = volc.verifiedResourceId || volc.resourceId || '';
|
|
20410
20519
|
const howTo = (voiceCatalog && voiceCatalog.howTo) || volc.howTo || [];
|
|
20411
20520
|
const howToRows = howTo.map((step) => React.createElement('div', { key: step.step, style: { ...PERSONA_STYLE.card, padding: '7px 9px' } },
|
|
20412
20521
|
React.createElement('div', { style: { fontSize: '12px', fontWeight: 600 } }, `${step.step}. ${step.title}`),
|
|
@@ -20417,15 +20526,33 @@ window.__ModuleLoader__.load({
|
|
|
20417
20526
|
}, step.link) : null));
|
|
20418
20527
|
const header = React.createElement('div', { style: { ...PERSONA_STYLE.row, justifyContent: 'space-between' } },
|
|
20419
20528
|
React.createElement('div', { style: { fontSize: '12px', fontWeight: 600 } }, '火山引擎(唯一在线供应商)',
|
|
20420
|
-
personaTag(statusText,
|
|
20529
|
+
personaTag(statusText, verified ? 'ok' : 'warn'),
|
|
20530
|
+
verified ? personaTag(`实际:${usedSubtype || '?'} · ${usedResourceId || '?'}`, 'ok') : null),
|
|
20421
20531
|
personaButton(howToOpen ? '收起「如何获取」' : '如何获取 →', () => setHowToOpen((prev) => !prev)));
|
|
20422
20532
|
const statusHint = configured
|
|
20423
20533
|
? React.createElement('div', { className: 'we-picker__hint', style: { margin: '2px 0 4px' } },
|
|
20424
|
-
`AppID ${volc.maskedAppId || '已保存'} · Token ${volc.maskedToken || '已保存'} ·
|
|
20534
|
+
`AppID ${volc.maskedAppId || '已保存'} · Token ${volc.maskedToken || '已保存'} · 子类型 ${volc.subtype || ''}`
|
|
20535
|
+
+ ` · Cluster ${volc.cluster || ''} · Resource ID ${volc.resourceId || ''}`
|
|
20536
|
+
+ (verified && volc.verifiedStatus ? ` · 上次测试 HTTP ${volc.verifiedStatus}` : ''))
|
|
20425
20537
|
: null;
|
|
20426
20538
|
const errorHint = volc.lastError
|
|
20427
20539
|
? React.createElement('div', { className: 'we-picker__hint', style: { color: '#f87171' } }, volc.lastError)
|
|
20428
20540
|
: null;
|
|
20541
|
+
// 任务 §2①:把「测试」拿到的真实诊断原样摆出来(状态码 + 响应片段 + URL + ResourceId + 音色)。
|
|
20542
|
+
const diagBlock = volcDiag
|
|
20543
|
+
? React.createElement('div', { style: { ...PERSONA_STYLE.card, padding: '7px 9px', marginTop: '4px', borderColor: 'rgba(120,190,255,.35)' } },
|
|
20544
|
+
React.createElement('div', { style: { fontSize: '11px', fontWeight: 600 } },
|
|
20545
|
+
`诊断 · HTTP ${volcDiag.status || 0} · ${volcDiag.code || ''}`),
|
|
20546
|
+
React.createElement('div', { style: { fontSize: '10px', opacity: .8, marginTop: '2px', wordBreak: 'break-all' } },
|
|
20547
|
+
`POST ${volcDiag.url || '(未发出请求)'}`),
|
|
20548
|
+
React.createElement('div', { style: { fontSize: '10px', opacity: .8, marginTop: '1px' } },
|
|
20549
|
+
`subtype=${volcDiag.subtype || '?'} · resourceId=${volcDiag.resourceId || '?'} · voiceId=${volcDiag.voiceId || '?'}`),
|
|
20550
|
+
React.createElement('div', { style: { fontSize: '10px', opacity: .8, marginTop: '1px' } },
|
|
20551
|
+
`AppID ${volcDiag.maskedAppId || '?'} · Token ${volcDiag.maskedToken || '?'}(只显示掩码)`),
|
|
20552
|
+
React.createElement('div', { style: { fontSize: '10px', opacity: .82, marginTop: '3px', whiteSpace: 'pre-wrap', wordBreak: 'break-all' } },
|
|
20553
|
+
`响应片段:${volcDiag.bodySnippet || '(空)'}`),
|
|
20554
|
+
volcDiag.hint ? React.createElement('div', { style: { fontSize: '10px', color: '#fcd34d', marginTop: '2px' } }, volcDiag.hint) : null)
|
|
20555
|
+
: null;
|
|
20429
20556
|
const credentialsGrid = React.createElement('div', { style: { display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '6px', marginTop: '4px' } },
|
|
20430
20557
|
personaField('AppID', personaInput({
|
|
20431
20558
|
value: volcForm.appId,
|
|
@@ -20479,7 +20606,7 @@ window.__ModuleLoader__.load({
|
|
|
20479
20606
|
howToRows)
|
|
20480
20607
|
: null;
|
|
20481
20608
|
return React.createElement('div', { style: { ...PERSONA_STYLE.card, padding: '10px' } },
|
|
20482
|
-
header, statusHint, errorHint, credentialsGrid, routingGrid, voiceGrid, actions, noteRow, howToBlock);
|
|
20609
|
+
header, statusHint, errorHint, credentialsGrid, routingGrid, voiceGrid, actions, noteRow, diagBlock, howToBlock);
|
|
20483
20610
|
};
|
|
20484
20611
|
|
|
20485
20612
|
const permissionRow = (group) => {
|
|
@@ -20648,9 +20775,19 @@ window.__ModuleLoader__.load({
|
|
|
20648
20775
|
React.createElement('div', { className: 'we-picker__hint', style: { marginTop: '3px' } },
|
|
20649
20776
|
'这是代码层强制:即使提示词要求它换壁纸/卸载/读文件,工具层也会拒绝。声音页仍可正常选音色与试听。'))
|
|
20650
20777
|
: React.createElement('div', null,
|
|
20651
|
-
React.createElement('div', { style: { fontSize: '12px', fontWeight: 600, marginBottom: '2px' } }, '工具组权限'
|
|
20778
|
+
React.createElement('div', { style: { fontSize: '12px', fontWeight: 600, marginBottom: '2px' } }, '工具组权限',
|
|
20779
|
+
personaTag(`预设:${((perm.presets || []).find((item) => item.current) || {}).label || '自定义'}`, '')),
|
|
20780
|
+
// 任务 §6①:一键预设(标准 / 宽松 / 自定义);改过任何一组会自动变「自定义」。
|
|
20781
|
+
React.createElement('div', { style: { ...PERSONA_STYLE.row, gap: '4px', margin: '2px 0 4px', flexWrap: 'wrap' } },
|
|
20782
|
+
(perm.presets || []).map((item) => personaButton(
|
|
20783
|
+
`${item.label}${item.current ? ' ✓' : ''}`,
|
|
20784
|
+
() => { void setPermissionPreset(item.id); },
|
|
20785
|
+
{ disabled: permBusy || item.current, style: item.current ? { borderColor: 'rgba(120,190,255,.7)', background: 'rgba(90,160,255,.16)' } : {} },
|
|
20786
|
+
))),
|
|
20652
20787
|
React.createElement('div', { className: 'we-picker__hint', style: { marginBottom: '4px' } },
|
|
20653
|
-
'允许 = 直接做;询问 = 先问一句,说「好」或在气泡点「允许」才做;禁止 = 明确拒绝。'),
|
|
20788
|
+
((perm.presets || []).find((item) => item.current) || {}).desc || '允许 = 直接做;询问 = 先问一句,说「好」或在气泡点「允许」才做;禁止 = 明确拒绝。'),
|
|
20789
|
+
React.createElement('div', { className: 'we-picker__hint', style: { marginBottom: '4px' } },
|
|
20790
|
+
'写文件(doc_write)、剪贴板、系统操作永远需要二次确认;预设不会绕过它们。'),
|
|
20654
20791
|
perm.loading ? React.createElement('div', { className: 'we-picker__hint' }, '正在读取权限…') : null,
|
|
20655
20792
|
perm.groups.map(permissionRow),
|
|
20656
20793
|
React.createElement('label', { style: { ...PERSONA_STYLE.row, gap: '6px', margin: '8px 0 2px', cursor: permBusy ? 'default' : 'pointer' } },
|
|
@@ -20660,6 +20797,25 @@ window.__ModuleLoader__.load({
|
|
|
20660
20797
|
}),
|
|
20661
20798
|
React.createElement('span', null, '高级权限',
|
|
20662
20799
|
React.createElement('span', { style: { opacity: .72 } }, '(允许系统级操作;每个动作仍会二次确认)'))),
|
|
20800
|
+
// 任务 §6②:「用户可编辑白名单」——open_url 域名 + app_launch 应用。
|
|
20801
|
+
React.createElement('div', { style: { marginTop: '10px', paddingTop: '8px', borderTop: '1px solid rgba(255,255,255,.10)' } },
|
|
20802
|
+
React.createElement('div', { style: { fontSize: '12px', fontWeight: 600 } }, '工具白名单'),
|
|
20803
|
+
React.createElement('div', { className: 'we-picker__hint', style: { margin: '2px 0 4px' } },
|
|
20804
|
+
'open_url 只开这些域名(https);app_launch 只启动这些应用。用逗号分隔,保存后立刻生效。'),
|
|
20805
|
+
personaField('允许的域名', personaInput({
|
|
20806
|
+
value: toolWl.domains, placeholder: 'bilibili.com, github.com',
|
|
20807
|
+
onChange: (v) => setToolWl((prev) => ({ ...prev, domains: v })),
|
|
20808
|
+
})),
|
|
20809
|
+
personaField('允许的应用(id)', personaInput({
|
|
20810
|
+
value: toolWl.apps, placeholder: 'notepad, calc, mspaint, explorer, browser',
|
|
20811
|
+
onChange: (v) => setToolWl((prev) => ({ ...prev, apps: v })),
|
|
20812
|
+
})),
|
|
20813
|
+
React.createElement('div', { style: { ...PERSONA_STYLE.row, marginTop: '4px' } },
|
|
20814
|
+
personaButton('保存白名单', () => { void saveToolWhitelist(); }, { primary: true, disabled: permBusy }),
|
|
20815
|
+
personaButton('重新读取', () => { void loadToolWhitelist(); })),
|
|
20816
|
+
toolWl.note
|
|
20817
|
+
? React.createElement('div', { className: 'we-picker__hint', style: { color: toolWl.note.ok ? undefined : '#f87171' } }, toolWl.note.text)
|
|
20818
|
+
: null),
|
|
20663
20819
|
permNote ? React.createElement('div', { className: 'we-picker__hint', style: { color: permNote.ok ? undefined : '#f87171' } }, permNote.text) : null,
|
|
20664
20820
|
React.createElement('div', { style: { fontSize: '12px', fontWeight: 600, marginTop: '10px' } },
|
|
20665
20821
|
'最近调用记录', personaTag(`共 ${perm.toolLog ? perm.toolLog.total : 0} 条`, '')),
|
|
@@ -20748,7 +20904,7 @@ window.__ModuleLoader__.load({
|
|
|
20748
20904
|
petName: '',
|
|
20749
20905
|
ownerName: '',
|
|
20750
20906
|
// v0.2:朗读 = voice.muted 取反;音色 = voice.name;SAPI = voice.sapiEnabled(默认 false)。
|
|
20751
|
-
voice: { name: '', muted: false, rate: 0, sapiEnabled: false, enabledEngine: 'edge', continuous: true },
|
|
20907
|
+
voice: { name: '', muted: false, rate: 0, sapiEnabled: false, enabledEngine: 'edge', continuous: true, listenPaused: false },
|
|
20752
20908
|
};
|
|
20753
20909
|
|
|
20754
20910
|
/** apiJson 的返回是 { ok, status, data },而 /pet-chat/* 的 data 里还套一层 { ok, data }。 */
|
|
@@ -20926,7 +21082,7 @@ window.__ModuleLoader__.load({
|
|
|
20926
21082
|
const [workPlugins, setWorkPlugins] = React.useState(null);
|
|
20927
21083
|
const [voices, setVoices] = React.useState(null);
|
|
20928
21084
|
const [voiceMeta, setVoiceMeta] = React.useState({});
|
|
20929
|
-
const [voiceCfg, setVoiceCfg] = React.useState({ sapiEnabled: false, enabledEngine: 'edge', continuous: true });
|
|
21085
|
+
const [voiceCfg, setVoiceCfg] = React.useState({ sapiEnabled: false, enabledEngine: 'edge', continuous: true, listenPaused: false });
|
|
20930
21086
|
const [setupBusy, setSetupBusy] = React.useState(false);
|
|
20931
21087
|
const [setupReport, setSetupReport] = React.useState(null);
|
|
20932
21088
|
// pre.62:录音组件(ffmpeg)供给状态;下载中时轮询 /voice/diagnose 显示百分比。
|
|
@@ -20984,8 +21140,9 @@ window.__ModuleLoader__.load({
|
|
|
20984
21140
|
voice.sapiEnabled = voice.sapiEnabled === true;
|
|
20985
21141
|
voice.enabledEngine = ['edge', 'piper', 'sapi'].includes(String(voice.enabledEngine || '')) ? voice.enabledEngine : 'edge';
|
|
20986
21142
|
voice.continuous = voice.continuous !== false;
|
|
21143
|
+
voice.listenPaused = voice.listenPaused === true;
|
|
20987
21144
|
setDraft({ ...CHAT_DEFAULTS, ...doc, voice, apiKey: '' });
|
|
20988
|
-
setVoiceCfg({ sapiEnabled: voice.sapiEnabled, enabledEngine: voice.enabledEngine, continuous: voice.continuous });
|
|
21145
|
+
setVoiceCfg({ sapiEnabled: voice.sapiEnabled, enabledEngine: voice.enabledEngine, continuous: voice.continuous, listenPaused: voice.listenPaused });
|
|
20989
21146
|
publishContinuous(voice.continuous !== false);
|
|
20990
21147
|
setEnabledEngine(voice.enabledEngine);
|
|
20991
21148
|
setCheckedEngine(voice.enabledEngine);
|
|
@@ -21256,6 +21413,7 @@ window.__ModuleLoader__.load({
|
|
|
21256
21413
|
sapiEnabled: voiceCfg.sapiEnabled === true,
|
|
21257
21414
|
enabledEngine,
|
|
21258
21415
|
continuous: voiceCfg.continuous !== false,
|
|
21416
|
+
listenPaused: voiceCfg.listenPaused === true,
|
|
21259
21417
|
});
|
|
21260
21418
|
if (!voice.name) {
|
|
21261
21419
|
const fallback = assistantDefaultVoice(voices);
|
|
@@ -21273,6 +21431,8 @@ window.__ModuleLoader__.load({
|
|
|
21273
21431
|
sapiEnabled: voice.sapiEnabled,
|
|
21274
21432
|
enabledEngine,
|
|
21275
21433
|
continuous: voiceCfg.continuous !== false,
|
|
21434
|
+
listenPaused: voiceCfg.listenPaused === true,
|
|
21435
|
+
muted: voice.muted === true,
|
|
21276
21436
|
}, { parse: 'always' }).catch(() => null);
|
|
21277
21437
|
if (voice.muted === true) {
|
|
21278
21438
|
try { petSpeakStop(); } catch { /* 朗读是增强:停不下来也不能影响保存 */ }
|
|
@@ -21334,7 +21494,7 @@ window.__ModuleLoader__.load({
|
|
|
21334
21494
|
const voiceKnown = usableVoices.some((v) => String(v.id) === currentVoiceName);
|
|
21335
21495
|
const edgeOk = usableVoices.some((v) => v.engine === 'edge') || Boolean(voiceMeta && voiceMeta.edge && voiceMeta.edge.ok);
|
|
21336
21496
|
const piperInstalled = Boolean(voiceMeta && voiceMeta.piper && voiceMeta.piper.installed);
|
|
21337
|
-
const
|
|
21497
|
+
const listenOn = voiceCfg.listenPaused !== true;
|
|
21338
21498
|
// 下拉只列“当前已启用的内置引擎”+ 已测试通过的在线渠道,避免选到不参与回落的音色。
|
|
21339
21499
|
const selectableVoices = usableVoices.filter((v) => v.engine === enabledEngine
|
|
21340
21500
|
|| ['openai', 'azure', 'elevenlabs'].includes(v.engine));
|
|
@@ -21426,28 +21586,28 @@ window.__ModuleLoader__.load({
|
|
|
21426
21586
|
weT('🔊 朗读回答')));
|
|
21427
21587
|
voicePage.push(React.createElement('div', {
|
|
21428
21588
|
key: 'speak-hint', className: 'we-picker__hint', style: { margin: '0 0 6px' },
|
|
21429
|
-
}, weT('
|
|
21589
|
+
}, weT('关闭后只显示字幕、不合成语音(=「暂停说话」);聆听与字幕不中断,保存后立刻生效。')));
|
|
21430
21590
|
|
|
21431
21591
|
voicePage.push(React.createElement('label', {
|
|
21432
|
-
key: '
|
|
21592
|
+
key: 'listen-toggle', style: { display: 'flex', gap: '6px', alignItems: 'center', fontSize: '12px', margin: '6px 0 2px' },
|
|
21433
21593
|
},
|
|
21434
21594
|
React.createElement('input', {
|
|
21435
|
-
type: 'checkbox', checked:
|
|
21595
|
+
type: 'checkbox', checked: listenOn, disabled: busy,
|
|
21436
21596
|
onChange: (e) => {
|
|
21437
|
-
const
|
|
21438
|
-
setVoiceCfg((prev) => ({ ...prev,
|
|
21439
|
-
publishContinuous(
|
|
21597
|
+
const listening = e.target.checked;
|
|
21598
|
+
setVoiceCfg((prev) => ({ ...prev, listenPaused: !listening }));
|
|
21599
|
+
publishContinuous(listening);
|
|
21440
21600
|
try {
|
|
21441
21601
|
if (typeof window !== 'undefined' && typeof window.dispatchEvent === 'function') {
|
|
21442
|
-
window.dispatchEvent(new CustomEvent('we-pet-continuous', { detail: { action: '
|
|
21602
|
+
window.dispatchEvent(new CustomEvent('we-pet-continuous', { detail: { action: listening ? 'resume' : 'pause' } }));
|
|
21443
21603
|
}
|
|
21444
21604
|
} catch { /* ignore */ }
|
|
21445
21605
|
},
|
|
21446
21606
|
}),
|
|
21447
|
-
weT('
|
|
21607
|
+
weT('🎤 常驻聆听')));
|
|
21448
21608
|
voicePage.push(React.createElement('div', {
|
|
21449
|
-
key: '
|
|
21450
|
-
}, weT('
|
|
21609
|
+
key: 'listen-hint', className: 'we-picker__hint', style: { margin: '0 0 6px' },
|
|
21610
|
+
}, weT('装好就在听(不用点桌宠):朗读时自动闭麦,播完 300ms 恢复;取消勾选 =「暂停聆听」(临时关麦,重启后仍记住)。')));
|
|
21451
21611
|
|
|
21452
21612
|
voicePage.push(ffmpegRow('ffmpeg-voice'));
|
|
21453
21613
|
voicePage.push(React.createElement('div', { key: 'setup', style: { display: 'flex', gap: '8px', alignItems: 'center', margin: '6px 0' } },
|
|
@@ -22181,13 +22341,15 @@ window.__ModuleLoader__.load({
|
|
|
22181
22341
|
let walkLeft = 0;
|
|
22182
22342
|
/** 单击轮换到第几号轨道。 */
|
|
22183
22343
|
let clickIdx = 0;
|
|
22184
|
-
/**
|
|
22344
|
+
/** 常驻聆听 / 暂停说话的状态(由 pet-chat 通过事件同步)。 */
|
|
22185
22345
|
let continuousEnabled = true;
|
|
22186
22346
|
let continuousPaused = false;
|
|
22347
|
+
let speakPaused = false;
|
|
22187
22348
|
const onContinuousState = (event) => {
|
|
22188
22349
|
const detail = (event && event.detail) || {};
|
|
22189
22350
|
if (typeof detail.enabled === 'boolean') continuousEnabled = detail.enabled;
|
|
22190
22351
|
if (typeof detail.paused === 'boolean') continuousPaused = detail.paused;
|
|
22352
|
+
if (typeof detail.speakPaused === 'boolean') speakPaused = detail.speakPaused;
|
|
22191
22353
|
if (menu) closeMenu();
|
|
22192
22354
|
};
|
|
22193
22355
|
|
|
@@ -22411,6 +22573,7 @@ window.__ModuleLoader__.load({
|
|
|
22411
22573
|
let menu = null;
|
|
22412
22574
|
if (typeof window !== "undefined" && window.addEventListener) {
|
|
22413
22575
|
window.addEventListener("we-pet-continuous-state", onContinuousState);
|
|
22576
|
+
window.addEventListener("we-pet-voice-state", onContinuousState);
|
|
22414
22577
|
}
|
|
22415
22578
|
function closeMenu() {
|
|
22416
22579
|
if (menu && menu.parentNode) menu.parentNode.removeChild(menu);
|
|
@@ -22454,30 +22617,29 @@ window.__ModuleLoader__.load({
|
|
|
22454
22617
|
const hr = document.createElement("div");
|
|
22455
22618
|
hr.style.cssText = "height:1px;margin:6px 0;background:rgba(255,255,255,0.14)";
|
|
22456
22619
|
menu.appendChild(hr);
|
|
22457
|
-
//
|
|
22458
|
-
const
|
|
22620
|
+
// 任务 §4:右键只留两个开关 ——「暂停说话」(静音但继续听 + 出字幕)/「暂停聆听」(临时关麦)。
|
|
22621
|
+
const sendVoice = (action, extra) => {
|
|
22459
22622
|
try {
|
|
22460
|
-
window.dispatchEvent(new CustomEvent("we-pet-continuous", { detail: { action } }));
|
|
22623
|
+
window.dispatchEvent(new CustomEvent("we-pet-continuous", { detail: { action, ...(extra || {}) } }));
|
|
22461
22624
|
} catch { /* 没装 pet-chat 时无副作用 */ }
|
|
22462
22625
|
};
|
|
22463
22626
|
menu.appendChild(buildMenuItem(
|
|
22464
|
-
(
|
|
22627
|
+
(speakPaused ? "☑ " : "☐ ") + weT("暂停说话"),
|
|
22465
22628
|
() => {
|
|
22466
|
-
|
|
22467
|
-
|
|
22629
|
+
speakPaused = !speakPaused;
|
|
22630
|
+
sendVoice("speak-pause", { paused: speakPaused });
|
|
22631
|
+
closeMenu();
|
|
22632
|
+
},
|
|
22633
|
+
));
|
|
22634
|
+
menu.appendChild(buildMenuItem(
|
|
22635
|
+
(continuousPaused ? "▶ " : "⏸ ") + (continuousPaused ? weT("继续聆听") : weT("暂停聆听")),
|
|
22636
|
+
() => {
|
|
22637
|
+
const next = !continuousPaused;
|
|
22638
|
+
continuousPaused = next;
|
|
22639
|
+
sendVoice(next ? "pause" : "resume", { paused: next });
|
|
22468
22640
|
closeMenu();
|
|
22469
22641
|
},
|
|
22470
22642
|
));
|
|
22471
|
-
if (continuousEnabled) {
|
|
22472
|
-
menu.appendChild(buildMenuItem(
|
|
22473
|
-
continuousPaused ? weT("继续听") : weT("暂停听"),
|
|
22474
|
-
() => {
|
|
22475
|
-
sendContinuous(continuousPaused ? "resume" : "pause");
|
|
22476
|
-
continuousPaused = !continuousPaused;
|
|
22477
|
-
closeMenu();
|
|
22478
|
-
},
|
|
22479
|
-
));
|
|
22480
|
-
}
|
|
22481
22643
|
const hr2 = document.createElement("div");
|
|
22482
22644
|
hr2.style.cssText = "height:1px;margin:6px 0;background:rgba(255,255,255,0.14)";
|
|
22483
22645
|
menu.appendChild(hr2);
|
|
@@ -22551,6 +22713,7 @@ window.__ModuleLoader__.load({
|
|
|
22551
22713
|
window.removeEventListener("pointermove", onPointerMove);
|
|
22552
22714
|
window.removeEventListener("pointerup", onPointerUp);
|
|
22553
22715
|
window.removeEventListener("we-pet-continuous-state", onContinuousState);
|
|
22716
|
+
window.removeEventListener("we-pet-voice-state", onContinuousState);
|
|
22554
22717
|
}
|
|
22555
22718
|
}
|
|
22556
22719
|
|
|
@@ -23863,18 +24026,19 @@ window.__ModuleLoader__.load({
|
|
|
23863
24026
|
|
|
23864
24027
|
// ── 内联模块:src/pet-bubble.js —— 头顶气泡:锚定桌宠头顶、跟随位置/缩放、逐字显示、最多 6 行、朗读结束 +3s 淡出(构建期注入;勿手改本段)──
|
|
23865
24028
|
/**
|
|
23866
|
-
* pet-bubble.js — 桌宠头顶的**双层气泡**(
|
|
24029
|
+
* pet-bubble.js — 桌宠头顶的**双层气泡**(v3 §5 美化版)。
|
|
23867
24030
|
*
|
|
23868
24031
|
* 用户口径:提示/错误不能和回答挤在同一个框里。
|
|
23869
|
-
* ① 状态条(独立、细、可点、3–5
|
|
23870
|
-
* ②
|
|
24032
|
+
* ① 状态条(独立、细、可点、3–5 秒淡出):🎤 在听 / 💭 在想 / 🔊 在说 / 🔇 仅文字 / 麦克风已暂停
|
|
24033
|
+
* ② 回答气泡(只有回答,小尾巴指向桌宠):最多 4 行,超出显示「展开」;展开后出现「复制」,
|
|
24034
|
+
* 长回答在 240px 内滚动到底部;新消息替换旧消息时先淡出再淡入(150ms)。
|
|
23871
24035
|
*
|
|
23872
24036
|
* 结构:
|
|
23873
24037
|
* .we-pet-wrap(固定定位、列布局、整体锚定在桌宠头顶)
|
|
23874
|
-
* ├─ .we-pet-status(状态条;自带 data-state 控制
|
|
23875
|
-
* └─ .we-pet-bubble(回答气泡;内部 .we-pet-bubble-text +
|
|
24038
|
+
* ├─ .we-pet-status(状态条;自带 data-state 控制 🎤/💭/🔊/🔇 动效)
|
|
24039
|
+
* └─ .we-pet-bubble(回答气泡;内部 .we-pet-bubble-text + 展开/复制/关闭)
|
|
23876
24040
|
*
|
|
23877
|
-
* 依赖全部注入(document / 定时器 /
|
|
24041
|
+
* 依赖全部注入(document / 定时器 / 锚点 / 剪贴板),Node 里能用假 DOM 跑判据;
|
|
23878
24042
|
* 浏览器侧由 pet-chat.js 用真实 window 构造。`setState` 仍同步写 bubble 的
|
|
23879
24043
|
* `data-state`(既有判据与桌宠动作读它),视觉三态则落在状态条上。
|
|
23880
24044
|
*/
|
|
@@ -23889,34 +24053,50 @@ window.__ModuleLoader__.load({
|
|
|
23889
24053
|
: (typeof clearTimeout === 'function' ? clearTimeout : () => {});
|
|
23890
24054
|
const getAnchor = typeof options.getAnchor === 'function' ? options.getAnchor : () => null;
|
|
23891
24055
|
const onStatusClick = typeof options.onStatusClick === 'function' ? options.onStatusClick : null;
|
|
23892
|
-
|
|
23893
|
-
const
|
|
23894
|
-
|
|
24056
|
+
/** 最多显示几行(超出折叠 + 「展开」)。 */
|
|
24057
|
+
const MAX_LINES = 4;
|
|
24058
|
+
/** 气泡最大宽度(任务 §5:300px)。 */
|
|
24059
|
+
const BUBBLE_MAX_WIDTH = 300;
|
|
24060
|
+
/** 展开后的最大高度(长回答内部滚动)。 */
|
|
24061
|
+
const BUBBLE_MAX_HEIGHT = 240;
|
|
24062
|
+
/** 出现/消失的动效时长(任务 §5:150ms)。 */
|
|
24063
|
+
const FADE_MS = 150;
|
|
23895
24064
|
|
|
23896
24065
|
const raf = typeof options.requestAnimationFrame === 'function' ? options.requestAnimationFrame : null;
|
|
23897
24066
|
const cancelRaf = typeof options.cancelAnimationFrame === 'function' ? options.cancelAnimationFrame : null;
|
|
23898
24067
|
let rafId = null;
|
|
23899
24068
|
const onClose = typeof options.onClose === 'function' ? options.onClose : () => {};
|
|
24069
|
+
const clipboard = options.clipboard && typeof options.clipboard.writeText === 'function' ? options.clipboard : null;
|
|
23900
24070
|
/** 独立冒烟(只 eval 本文件)时没有 weT;有就用词表,没有就回落中文原文。 */
|
|
23901
24071
|
const tr = (text) => {
|
|
23902
24072
|
try { return typeof weT === 'function' ? weT(text) : text; } catch { return text; }
|
|
23903
24073
|
};
|
|
23904
24074
|
|
|
23905
24075
|
const CSS = [
|
|
23906
|
-
'.we-pet-wrap{position:fixed;z-index:9999;display:flex;flex-direction:column;align-items:center;gap:6px;max-width:
|
|
23907
|
-
//
|
|
23908
|
-
'.we-pet-bubble{position:relative;max-width:
|
|
23909
|
-
'.we-pet-bubble[data-visible="1"]{opacity:1;}',
|
|
24076
|
+
'.we-pet-wrap{position:fixed;z-index:9999;display:flex;flex-direction:column;align-items:center;gap:6px;max-width:300px;pointer-events:none;transform-origin:50% 100%;}',
|
|
24077
|
+
// 回答气泡:深色半透明底 + 1px 描边 + 柔和阴影;圆角 16;最大宽 300;内边距 10 / 14。
|
|
24078
|
+
'.we-pet-bubble{position:relative;max-width:300px;max-height:240px;overflow:hidden;padding:10px 14px;border-radius:16px;background:rgba(18,18,22,.86);color:#f2f2f5;font-size:13px;line-height:1.5;border:1px solid rgba(255,255,255,.14);box-shadow:0 10px 30px rgba(0,0,0,.38);backdrop-filter:blur(8px);-webkit-backdrop-filter:blur(8px);white-space:pre-wrap;word-break:break-word;opacity:0;transform:translateY(4px);transition:opacity 150ms ease, transform 150ms ease;pointer-events:auto;scrollbar-width:thin;}',
|
|
24079
|
+
'.we-pet-bubble[data-visible="1"]{opacity:1;transform:translateY(0);}',
|
|
24080
|
+
// 折叠态:最多 4 行(-webkit-line-clamp),超出显示「展开」。
|
|
24081
|
+
'.we-pet-bubble[data-expanded="0"] .we-pet-bubble-text{display:-webkit-box;-webkit-line-clamp:4;-webkit-box-orient:vertical;overflow:hidden;}',
|
|
24082
|
+
// 展开态:最多 240px,内部滚动到底部。
|
|
24083
|
+
'.we-pet-bubble[data-expanded="1"]{max-height:240px;overflow-y:auto;}',
|
|
23910
24084
|
// 小尾巴指向桌宠(在气泡底部中央;不挡脸)。
|
|
23911
24085
|
'.we-pet-bubble::after{content:"";position:absolute;left:50%;bottom:-6px;width:12px;height:12px;background:inherit;border-right:1px solid rgba(255,255,255,.14);border-bottom:1px solid rgba(255,255,255,.14);transform:translateX(-50%) rotate(45deg);}',
|
|
23912
24086
|
'.we-pet-bubble::-webkit-scrollbar{width:4px;}',
|
|
23913
24087
|
'.we-pet-bubble::-webkit-scrollbar-thumb{background:rgba(255,255,255,.22);border-radius:2px;}',
|
|
23914
|
-
//
|
|
23915
|
-
'.we-pet-
|
|
24088
|
+
// 气泡底部小工具条(展开/收起 + 复制):只在需要时出现,不抢正文。
|
|
24089
|
+
'.we-pet-bubble-tools{display:flex;gap:8px;justify-content:flex-end;align-items:center;margin-top:6px;font-size:11px;opacity:.78;}',
|
|
24090
|
+
'.we-pet-bubble-tools button{background:transparent;border:0;color:inherit;font:inherit;cursor:pointer;padding:0;opacity:.9;}',
|
|
24091
|
+
'.we-pet-bubble-tools button:hover{opacity:1;text-decoration:underline;}',
|
|
24092
|
+
'.we-pet-bubble-tools button[hidden]{display:none;}',
|
|
24093
|
+
// 状态条:细、独立、可点、3–5 秒淡出;字号 12。
|
|
24094
|
+
'.we-pet-status{max-width:300px;padding:5px 10px;border-radius:999px;background:rgba(18,18,22,.78);color:#ececf2;font-size:12px;line-height:1.4;border:1px solid rgba(255,255,255,.12);box-shadow:0 4px 14px rgba(0,0,0,.24);backdrop-filter:blur(8px);-webkit-backdrop-filter:blur(8px);display:flex;align-items:center;gap:6px;opacity:0;transition:opacity 150ms ease;pointer-events:auto;cursor:pointer;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}',
|
|
23916
24095
|
'.we-pet-status[data-visible="1"]{opacity:1;}',
|
|
23917
24096
|
'.we-pet-status[data-state="listen"]::after{content:"";width:8px;height:8px;border-radius:50%;background:currentColor;opacity:.7;animation:we-pet-status-pulse 1s ease-in-out infinite;}',
|
|
23918
24097
|
'.we-pet-status[data-state="think"]::after{content:"…";margin-left:1px;opacity:.8;animation:we-pet-status-blink 1.1s steps(2,end) infinite;}',
|
|
23919
24098
|
'.we-pet-status[data-state="speak"]::after{content:"";display:block;width:28px;height:10px;opacity:.85;background:linear-gradient(currentColor,currentColor) 0 100%/3px 45% no-repeat,linear-gradient(currentColor,currentColor) 7px 100%/3px 90% no-repeat,linear-gradient(currentColor,currentColor) 14px 100%/3px 60% no-repeat,linear-gradient(currentColor,currentColor) 21px 100%/3px 100% no-repeat;transform-origin:0 100%;animation:we-pet-status-wave .8s ease-in-out infinite alternate;}',
|
|
24099
|
+
'.we-pet-status[data-state="muted"]{opacity:.92;}',
|
|
23920
24100
|
'.we-pet-status[data-state="error"]{border-color:rgba(255,120,120,.45);}',
|
|
23921
24101
|
'@keyframes we-pet-status-wave{from{transform:scaleY(.55);opacity:.55;}to{transform:scaleY(1);opacity:.95;}}',
|
|
23922
24102
|
'@keyframes we-pet-status-pulse{0%,100%{transform:scale(.8);opacity:.45;}50%{transform:scale(1.15);opacity:.9;}}',
|
|
@@ -23926,13 +24106,21 @@ window.__ModuleLoader__.load({
|
|
|
23926
24106
|
let wrap = null;
|
|
23927
24107
|
let el = null; // 回答气泡
|
|
23928
24108
|
let textEl = null;
|
|
24109
|
+
let toolsEl = null;
|
|
24110
|
+
let moreBtn = null;
|
|
24111
|
+
let copyBtn = null;
|
|
23929
24112
|
let statusEl = null;
|
|
23930
24113
|
let text = '';
|
|
23931
24114
|
let visible = false;
|
|
24115
|
+
let expanded = false;
|
|
23932
24116
|
let fadeTimer = null;
|
|
24117
|
+
let replaceTimer = null;
|
|
23933
24118
|
let statusTimer = null;
|
|
24119
|
+
let copyTimer = null;
|
|
23934
24120
|
let stylesInjected = false;
|
|
23935
24121
|
let continuous = false;
|
|
24122
|
+
let speakPaused = false;
|
|
24123
|
+
let listenPaused = false;
|
|
23936
24124
|
|
|
23937
24125
|
function startFollow() {
|
|
23938
24126
|
if (!raf || rafId != null) return;
|
|
@@ -23969,6 +24157,69 @@ window.__ModuleLoader__.load({
|
|
|
23969
24157
|
wrap.style.transform = `translate(-50%, -100%) scale(${Number(anchor.scale) || 1})`;
|
|
23970
24158
|
}
|
|
23971
24159
|
|
|
24160
|
+
/** 展开/收起:只改 data 属性,视觉由 CSS 的 line-clamp 与 max-height 决定。 */
|
|
24161
|
+
function setExpanded(next) {
|
|
24162
|
+
expanded = next === true;
|
|
24163
|
+
if (el && el.dataset) el.dataset.expanded = expanded ? '1' : '0';
|
|
24164
|
+
if (moreBtn) moreBtn.textContent = expanded ? tr('收起') : tr('展开');
|
|
24165
|
+
if (copyBtn) {
|
|
24166
|
+
if (expanded) {
|
|
24167
|
+
if (typeof copyBtn.removeAttribute === 'function') copyBtn.removeAttribute('hidden');
|
|
24168
|
+
if (copyBtn.style) copyBtn.style.display = '';
|
|
24169
|
+
} else {
|
|
24170
|
+
if (typeof copyBtn.setAttribute === 'function') copyBtn.setAttribute('hidden', 'hidden');
|
|
24171
|
+
if (copyBtn.style) copyBtn.style.display = 'none';
|
|
24172
|
+
}
|
|
24173
|
+
}
|
|
24174
|
+
if (expanded) followBottom();
|
|
24175
|
+
return expanded;
|
|
24176
|
+
}
|
|
24177
|
+
|
|
24178
|
+
/** 长回答追加时保持在底部(用户往上翻时不强拉,交给浏览器滚动条)。 */
|
|
24179
|
+
function followBottom() {
|
|
24180
|
+
try {
|
|
24181
|
+
if (!el) return;
|
|
24182
|
+
if (Number(el.scrollHeight) > Number(el.clientHeight)) el.scrollTop = el.scrollHeight;
|
|
24183
|
+
} catch { /* 假 DOM / 旧浏览器没有 scroll 属性 */ }
|
|
24184
|
+
}
|
|
24185
|
+
|
|
24186
|
+
function cancelFade() {
|
|
24187
|
+
if (fadeTimer != null) { clearTimer(fadeTimer); fadeTimer = null; }
|
|
24188
|
+
if (replaceTimer != null) { clearTimer(replaceTimer); replaceTimer = null; }
|
|
24189
|
+
}
|
|
24190
|
+
function cancelStatus() {
|
|
24191
|
+
if (statusTimer != null) { clearTimer(statusTimer); statusTimer = null; }
|
|
24192
|
+
}
|
|
24193
|
+
function statusVisible() {
|
|
24194
|
+
return Boolean(statusEl && statusEl.style && String(statusEl.style.opacity) === '1');
|
|
24195
|
+
}
|
|
24196
|
+
|
|
24197
|
+
/** 把文字真正写进气泡(show / 替换淡出后都走这里)。 */
|
|
24198
|
+
function applyText(nextText, animate) {
|
|
24199
|
+
text = String(nextText == null ? '' : nextText);
|
|
24200
|
+
if (textEl) textEl.textContent = text;
|
|
24201
|
+
if (el) {
|
|
24202
|
+
if (el.dataset) el.dataset.visible = '1';
|
|
24203
|
+
// 淡入:先让 opacity 回到 1(CSS transition 150ms + translateY 4px→0)。
|
|
24204
|
+
el.style.opacity = animate === false ? '1' : '0';
|
|
24205
|
+
if (animate !== false) {
|
|
24206
|
+
setTimer(() => { if (el) el.style.opacity = '1'; }, 10);
|
|
24207
|
+
}
|
|
24208
|
+
}
|
|
24209
|
+
visible = true;
|
|
24210
|
+
setExpanded(false);
|
|
24211
|
+
followBottom();
|
|
24212
|
+
place();
|
|
24213
|
+
startFollow();
|
|
24214
|
+
}
|
|
24215
|
+
|
|
24216
|
+
/** 假 DOM / 老环境可能没有 addEventListener:气泡是装饰层,缺了也不能抛。 */
|
|
24217
|
+
const listen = (target, type, fn) => {
|
|
24218
|
+
try {
|
|
24219
|
+
if (target && typeof target.addEventListener === 'function') target.addEventListener(type, fn);
|
|
24220
|
+
} catch { /* ignore */ }
|
|
24221
|
+
};
|
|
24222
|
+
|
|
23972
24223
|
function ensure() {
|
|
23973
24224
|
if (wrap || !doc || typeof doc.createElement !== 'function') return wrap;
|
|
23974
24225
|
ensureStyles();
|
|
@@ -23980,28 +24231,56 @@ window.__ModuleLoader__.load({
|
|
|
23980
24231
|
statusEl.dataset = statusEl.dataset || {};
|
|
23981
24232
|
statusEl.setAttribute('role', 'status');
|
|
23982
24233
|
statusEl.setAttribute('aria-live', 'polite');
|
|
23983
|
-
statusEl
|
|
24234
|
+
listen(statusEl, 'click', () => {
|
|
23984
24235
|
try { if (onStatusClick) onStatusClick(); else hideStatus(0); } catch { /* ignore */ }
|
|
23985
24236
|
});
|
|
23986
24237
|
|
|
23987
24238
|
el = doc.createElement('div');
|
|
23988
24239
|
el.className = 'we-pet-bubble';
|
|
23989
24240
|
el.dataset = el.dataset || {};
|
|
24241
|
+
el.dataset.expanded = '0';
|
|
23990
24242
|
el.style.position = 'relative';
|
|
23991
24243
|
el.style.pointerEvents = 'auto';
|
|
23992
24244
|
// 点气泡 = 收起(二选一里的“收起”;不复制,避免误触剪贴板)。拖选文字时不触发 click。
|
|
23993
|
-
el
|
|
24245
|
+
listen(el, 'click', () => { hide(0); onClose(); });
|
|
23994
24246
|
|
|
23995
24247
|
textEl = doc.createElement('div');
|
|
23996
24248
|
textEl.className = 'we-pet-bubble-text';
|
|
23997
24249
|
if (typeof el.appendChild === 'function') el.appendChild(textEl);
|
|
23998
24250
|
|
|
24251
|
+
// 底部工具条:展开/收起 + 复制(复制只在展开态出现,任务 §5)。
|
|
24252
|
+
toolsEl = doc.createElement('div');
|
|
24253
|
+
toolsEl.className = 'we-pet-bubble-tools';
|
|
24254
|
+
moreBtn = doc.createElement('button');
|
|
24255
|
+
moreBtn.type = 'button';
|
|
24256
|
+
moreBtn.className = 'pet-bubble-more';
|
|
24257
|
+
moreBtn.textContent = tr('展开');
|
|
24258
|
+
listen(moreBtn, 'click', (event) => {
|
|
24259
|
+
try { if (event && typeof event.stopPropagation === 'function') event.stopPropagation(); } catch { /* ignore */ }
|
|
24260
|
+
setExpanded(!expanded);
|
|
24261
|
+
});
|
|
24262
|
+
copyBtn = doc.createElement('button');
|
|
24263
|
+
copyBtn.type = 'button';
|
|
24264
|
+
copyBtn.className = 'pet-bubble-copy';
|
|
24265
|
+
copyBtn.textContent = tr('复制');
|
|
24266
|
+
copyBtn.setAttribute('hidden', 'hidden');
|
|
24267
|
+
if (copyBtn.style) copyBtn.style.display = 'none';
|
|
24268
|
+
listen(copyBtn, 'click', (event) => {
|
|
24269
|
+
try { if (event && typeof event.stopPropagation === 'function') event.stopPropagation(); } catch { /* ignore */ }
|
|
24270
|
+
void copyText();
|
|
24271
|
+
});
|
|
24272
|
+
if (typeof toolsEl.appendChild === 'function') {
|
|
24273
|
+
toolsEl.appendChild(moreBtn);
|
|
24274
|
+
toolsEl.appendChild(copyBtn);
|
|
24275
|
+
}
|
|
24276
|
+
if (typeof el.appendChild === 'function') el.appendChild(toolsEl);
|
|
24277
|
+
|
|
23999
24278
|
const close = doc.createElement('button');
|
|
24000
24279
|
close.className = 'pet-bubble-close';
|
|
24001
24280
|
close.setAttribute('aria-label', '关闭');
|
|
24002
24281
|
close.textContent = '×';
|
|
24003
24282
|
close.style.cssText = 'position:absolute;top:-6px;right:-6px;width:18px;height:18px;border-radius:50%;border:none;background:#333;color:#ddd;font-size:12px;line-height:1;cursor:pointer;pointer-events:auto;';
|
|
24004
|
-
close
|
|
24283
|
+
listen(close, 'click', (event) => {
|
|
24005
24284
|
// 阻止冒泡到气泡(否则同一次点击会触发两次 onClose)。
|
|
24006
24285
|
try { if (event && typeof event.stopPropagation === 'function') event.stopPropagation(); } catch { /* ignore */ }
|
|
24007
24286
|
hide(0);
|
|
@@ -24014,35 +24293,42 @@ window.__ModuleLoader__.load({
|
|
|
24014
24293
|
return wrap;
|
|
24015
24294
|
}
|
|
24016
24295
|
|
|
24017
|
-
/**
|
|
24018
|
-
function
|
|
24296
|
+
/** 复制全文(只在展开态可用;失败给状态条提示,不静默)。 */
|
|
24297
|
+
async function copyText() {
|
|
24298
|
+
if (!text) return false;
|
|
24019
24299
|
try {
|
|
24020
|
-
if (
|
|
24021
|
-
|
|
24022
|
-
|
|
24023
|
-
|
|
24024
|
-
|
|
24025
|
-
|
|
24026
|
-
|
|
24027
|
-
|
|
24028
|
-
|
|
24029
|
-
|
|
24030
|
-
|
|
24031
|
-
|
|
24032
|
-
|
|
24300
|
+
if (clipboard) {
|
|
24301
|
+
await clipboard.writeText(text);
|
|
24302
|
+
} else if (typeof navigator !== 'undefined' && navigator.clipboard && typeof navigator.clipboard.writeText === 'function') {
|
|
24303
|
+
await navigator.clipboard.writeText(text);
|
|
24304
|
+
} else {
|
|
24305
|
+
throw new Error('clipboard-unavailable');
|
|
24306
|
+
}
|
|
24307
|
+
if (copyBtn) copyBtn.textContent = tr('已复制');
|
|
24308
|
+
if (copyTimer != null) clearTimer(copyTimer);
|
|
24309
|
+
copyTimer = setTimer(() => { copyTimer = null; if (copyBtn) copyBtn.textContent = tr('复制'); }, 1500);
|
|
24310
|
+
return true;
|
|
24311
|
+
} catch {
|
|
24312
|
+
status('error', tr('复制失败:这个环境没有剪贴板权限'), { delay: 3000 });
|
|
24313
|
+
return false;
|
|
24314
|
+
}
|
|
24033
24315
|
}
|
|
24034
24316
|
|
|
24035
|
-
/**
|
|
24317
|
+
/** 显示(或替换)一段**回答**;替换旧消息时先淡出再淡入。 */
|
|
24036
24318
|
function show(nextText) {
|
|
24037
24319
|
if (!ensure()) return;
|
|
24038
24320
|
cancelFade();
|
|
24039
|
-
|
|
24040
|
-
if (
|
|
24041
|
-
|
|
24042
|
-
|
|
24043
|
-
|
|
24044
|
-
|
|
24045
|
-
|
|
24321
|
+
const next = String(nextText == null ? '' : nextText);
|
|
24322
|
+
if (visible && text && next !== text) {
|
|
24323
|
+
// 任务 §5:新消息替换旧消息时先淡出(150ms),再换文字淡入。
|
|
24324
|
+
if (el) el.style.opacity = '0';
|
|
24325
|
+
replaceTimer = setTimer(() => {
|
|
24326
|
+
replaceTimer = null;
|
|
24327
|
+
applyText(next, true);
|
|
24328
|
+
}, FADE_MS);
|
|
24329
|
+
return;
|
|
24330
|
+
}
|
|
24331
|
+
applyText(next, visible);
|
|
24046
24332
|
}
|
|
24047
24333
|
|
|
24048
24334
|
/** 逐字/逐段追加(SSE 每个 chunk 调一次)。 */
|
|
@@ -24068,6 +24354,7 @@ window.__ModuleLoader__.load({
|
|
|
24068
24354
|
el.style.opacity = '0';
|
|
24069
24355
|
if (el.dataset) el.dataset.visible = '0';
|
|
24070
24356
|
}
|
|
24357
|
+
setExpanded(false);
|
|
24071
24358
|
visible = false;
|
|
24072
24359
|
}
|
|
24073
24360
|
|
|
@@ -24087,7 +24374,7 @@ window.__ModuleLoader__.load({
|
|
|
24087
24374
|
doHide();
|
|
24088
24375
|
}
|
|
24089
24376
|
|
|
24090
|
-
/**
|
|
24377
|
+
/** 显示状态条(错误/提示/在听/在想/在说/仅文字/麦克风暂停)。 */
|
|
24091
24378
|
function status(kind, message, opts) {
|
|
24092
24379
|
if (!ensure()) return;
|
|
24093
24380
|
cancelStatus();
|
|
@@ -24122,7 +24409,7 @@ window.__ModuleLoader__.load({
|
|
|
24122
24409
|
doHide();
|
|
24123
24410
|
}
|
|
24124
24411
|
|
|
24125
|
-
/**
|
|
24412
|
+
/** 三态 + v3 两态:在听 / 在想 / 在说 / 🔇 仅文字(落在状态条上)。 */
|
|
24126
24413
|
function setState(kind) {
|
|
24127
24414
|
if (!ensure()) return;
|
|
24128
24415
|
const k = String(kind || '');
|
|
@@ -24136,13 +24423,14 @@ window.__ModuleLoader__.load({
|
|
|
24136
24423
|
return;
|
|
24137
24424
|
}
|
|
24138
24425
|
const labels = {
|
|
24139
|
-
listen: '🎤 ' + (continuous ? tr('
|
|
24426
|
+
listen: listenPaused ? '🎤 ' + tr('麦克风已暂停') : '🎤 ' + (continuous ? tr('常驻聆听中') : tr('在听')),
|
|
24140
24427
|
think: '💭 ' + tr('在想'),
|
|
24141
24428
|
speak: '🔊 ' + tr('在说'),
|
|
24429
|
+
muted: '🔇 ' + tr('仅文字'),
|
|
24142
24430
|
};
|
|
24143
24431
|
const label = labels[k];
|
|
24144
24432
|
if (!label) return;
|
|
24145
|
-
//
|
|
24433
|
+
// 错误/提示在它自己的 3–6 秒窗口内优先于三态,别被下一句“在说”立刻盖掉。
|
|
24146
24434
|
const curState = statusEl && statusEl.dataset ? String(statusEl.dataset.state || '') : '';
|
|
24147
24435
|
if (curState === 'error' || curState === 'info') return;
|
|
24148
24436
|
cancelStatus();
|
|
@@ -24158,14 +24446,25 @@ window.__ModuleLoader__.load({
|
|
|
24158
24446
|
|
|
24159
24447
|
function isVisible() { return visible; }
|
|
24160
24448
|
|
|
24161
|
-
/**
|
|
24449
|
+
/** 常驻聆听:把「在听」换成一语中的状态条。 */
|
|
24162
24450
|
function setContinuous(active) {
|
|
24163
24451
|
continuous = active === true;
|
|
24164
24452
|
if (continuous && statusEl && statusEl.dataset && String(statusEl.dataset.state || '') === 'listen') {
|
|
24165
|
-
statusEl.textContent = '🎤 ' + tr('
|
|
24453
|
+
statusEl.textContent = '🎤 ' + tr('常驻聆听中');
|
|
24166
24454
|
}
|
|
24167
24455
|
}
|
|
24168
24456
|
|
|
24457
|
+
/** 「暂停说话 / 暂停聆听」的状态同步(状态条文案立刻跟着变)。 */
|
|
24458
|
+
function setVoiceFlags(flags) {
|
|
24459
|
+
const next = flags && typeof flags === 'object' ? flags : {};
|
|
24460
|
+
if (typeof next.speakPaused === 'boolean') speakPaused = next.speakPaused;
|
|
24461
|
+
if (typeof next.listenPaused === 'boolean') listenPaused = next.listenPaused;
|
|
24462
|
+
const cur = statusEl && statusEl.dataset ? String(statusEl.dataset.state || '') : '';
|
|
24463
|
+
if (cur === 'listen') setState('listen');
|
|
24464
|
+
else if (speakPaused && cur === 'speak') setState('muted');
|
|
24465
|
+
return { speakPaused, listenPaused };
|
|
24466
|
+
}
|
|
24467
|
+
|
|
24169
24468
|
function dispose() {
|
|
24170
24469
|
cancelFade();
|
|
24171
24470
|
cancelStatus();
|
|
@@ -24174,15 +24473,21 @@ window.__ModuleLoader__.load({
|
|
|
24174
24473
|
wrap = null;
|
|
24175
24474
|
el = null;
|
|
24176
24475
|
textEl = null;
|
|
24476
|
+
toolsEl = null;
|
|
24477
|
+
moreBtn = null;
|
|
24478
|
+
copyBtn = null;
|
|
24177
24479
|
statusEl = null;
|
|
24178
24480
|
text = '';
|
|
24179
24481
|
visible = false;
|
|
24482
|
+
expanded = false;
|
|
24180
24483
|
}
|
|
24181
24484
|
|
|
24182
24485
|
return {
|
|
24183
|
-
show, append, clear, hide, setState, status, hideStatus, place, isVisible, setContinuous,
|
|
24486
|
+
show, append, clear, hide, setState, status, hideStatus, place, isVisible, setContinuous, setVoiceFlags,
|
|
24487
|
+
setExpanded, copyText, dispose,
|
|
24184
24488
|
get following() { return rafId != null; },
|
|
24185
24489
|
get text() { return text; },
|
|
24490
|
+
get expanded() { return expanded; },
|
|
24186
24491
|
get element() { return el; },
|
|
24187
24492
|
get textElement() { return textEl; },
|
|
24188
24493
|
get statusElement() { return statusEl; },
|
|
@@ -24190,6 +24495,7 @@ window.__ModuleLoader__.load({
|
|
|
24190
24495
|
MAX_LINES,
|
|
24191
24496
|
BUBBLE_MAX_WIDTH,
|
|
24192
24497
|
BUBBLE_MAX_HEIGHT,
|
|
24498
|
+
FADE_MS,
|
|
24193
24499
|
};
|
|
24194
24500
|
}
|
|
24195
24501
|
|
|
@@ -24629,6 +24935,8 @@ window.__ModuleLoader__.load({
|
|
|
24629
24935
|
*/
|
|
24630
24936
|
async function ensureAsrReady(isCancelled) {
|
|
24631
24937
|
const cancelled = typeof isCancelled === 'function' ? isCancelled : () => false;
|
|
24938
|
+
// 假 DOM / 极简环境没有 setTimeout:常驻聆听不能因此抛错(只返回"没准备好")。
|
|
24939
|
+
if (typeof setTimeout !== 'function') return false;
|
|
24632
24940
|
petBubble.setState('think');
|
|
24633
24941
|
try {
|
|
24634
24942
|
await apiPostJson('/pet-chat/asr', {}, { parse: 'always' });
|
|
@@ -24682,7 +24990,7 @@ window.__ModuleLoader__.load({
|
|
|
24682
24990
|
* 懒加载:挂载时与每次唤醒时各刷一次(设置面板改完立刻生效,不用重启)。
|
|
24683
24991
|
* 读不到就保持“不静音”,宁可多念一句,也不要让用户以为朗读坏了。
|
|
24684
24992
|
*/
|
|
24685
|
-
let petChatVoice = { name: '', muted: false, rate: 0, continuous: true };
|
|
24993
|
+
let petChatVoice = { name: '', muted: false, rate: 0, continuous: true, listenPaused: false };
|
|
24686
24994
|
/** pre.65:本轮输入方式决定长度策略(语音 1–3 句;文字可长)。 */
|
|
24687
24995
|
let petChatInputMode = 'text';
|
|
24688
24996
|
/** 当前 active persona(只用于提示/排障;宿主以 index.active 为准,避免切换后发旧 id)。 */
|
|
@@ -24692,25 +25000,39 @@ window.__ModuleLoader__.load({
|
|
|
24692
25000
|
const resp = await apiJson('/pet-chat/state', { parse: 'always' });
|
|
24693
25001
|
const doc = (resp && resp.data) || {};
|
|
24694
25002
|
if (doc.persona && doc.persona.id) petChatPersonaId = String(doc.persona.id);
|
|
25003
|
+
petChatModelReady = doc.modelReady === true;
|
|
24695
25004
|
if (doc.voice && typeof doc.voice === 'object') {
|
|
24696
25005
|
petChatVoice = {
|
|
24697
25006
|
name: String(doc.voice.name || ''),
|
|
24698
25007
|
muted: doc.voice.muted === true,
|
|
24699
25008
|
rate: Number.isFinite(Number(doc.voice.rate)) ? Number(doc.voice.rate) : 0,
|
|
24700
25009
|
continuous: doc.voice.continuous !== false,
|
|
25010
|
+
listenPaused: doc.voice.listenPaused === true,
|
|
24701
25011
|
};
|
|
24702
25012
|
}
|
|
24703
25013
|
} catch { /* 读不到就用默认(不静音) */ }
|
|
24704
|
-
|
|
24705
|
-
|
|
25014
|
+
// 「暂停说话 / 暂停聆听」都是持久开关:设置页/右键改完立刻生效。
|
|
25015
|
+
petChatSpeakPaused = petChatVoice.muted === true;
|
|
25016
|
+
petChatContinuousEnabled = true;
|
|
25017
|
+
petChatContinuousPaused = petChatVoice.listenPaused === true;
|
|
25018
|
+
petBubble.setVoiceFlags({ speakPaused: petChatSpeakPaused, listenPaused: petChatContinuousPaused });
|
|
24706
25019
|
petChatPublishContinuousState();
|
|
24707
25020
|
return petChatVoice;
|
|
24708
25021
|
}
|
|
24709
25022
|
|
|
24710
|
-
/* ──
|
|
24711
|
-
|
|
24712
|
-
|
|
24713
|
-
|
|
25023
|
+
/* ── 常驻聆听(任务 §4):装好就在听;半双工;「暂停说话 / 暂停聆听」两个开关 ── *
|
|
25024
|
+
*
|
|
25025
|
+
* 状态机:idle → listening → thinking → speaking → listening(循环)
|
|
25026
|
+
* · 挂载后自动进入 listening(受持久化的「暂停聆听」约束);
|
|
25027
|
+
* · 朗读开始时**绝不录音**(半双工,避免听到自己);播完 300ms 自动恢复听;
|
|
25028
|
+
* · 「暂停说话」只静音 TTS,继续听 + 头顶出字幕;
|
|
25029
|
+
* · 麦克风被占用/权限失败 ⇒ 退出常驻聆听并明确提示(不静默)。
|
|
25030
|
+
*/
|
|
25031
|
+
const PET_CHAT_LISTEN_RESUME_MS = 300;
|
|
25032
|
+
/** 连续 60 秒没听到人声 ⇒ 探听降频到每 2 秒一次(但仍算"在听")。 */
|
|
25033
|
+
const PET_CHAT_QUIET_AFTER_MS = 60000;
|
|
25034
|
+
const PET_CHAT_QUIET_PROBE_MS = 2000;
|
|
25035
|
+
const PET_CHAT_SILENT_PROMPT_EVERY = 3;
|
|
24714
25036
|
let petChatContinuousEnabled = true;
|
|
24715
25037
|
let petChatContinuousActive = false;
|
|
24716
25038
|
let petChatContinuousPaused = false;
|
|
@@ -24718,6 +25040,12 @@ window.__ModuleLoader__.load({
|
|
|
24718
25040
|
let petChatContinuousSilent = 0;
|
|
24719
25041
|
let petChatContinuousTimer = null;
|
|
24720
25042
|
let petChatVoiceAbort = false;
|
|
25043
|
+
/** 暂停说话(= voice.muted):不出声,但继续听、继续出字幕。 */
|
|
25044
|
+
let petChatSpeakPaused = false;
|
|
25045
|
+
let petChatLastHeardAt = Date.now();
|
|
25046
|
+
let petChatListeningNow = false;
|
|
25047
|
+
/** 模型是否就绪(enabled + 有 Key/本机模型):不满足时**不开麦**,先提示填 Key。 */
|
|
25048
|
+
let petChatModelReady = false;
|
|
24721
25049
|
|
|
24722
25050
|
function petChatContinuousClearTimer() {
|
|
24723
25051
|
if (petChatContinuousTimer != null) {
|
|
@@ -24726,7 +25054,7 @@ window.__ModuleLoader__.load({
|
|
|
24726
25054
|
}
|
|
24727
25055
|
}
|
|
24728
25056
|
|
|
24729
|
-
/**
|
|
25057
|
+
/** 把常驻聆听 / 暂停说话的状态推给右键菜单(pet-layer 监听)。 */
|
|
24730
25058
|
function petChatPublishContinuousState() {
|
|
24731
25059
|
try {
|
|
24732
25060
|
if (typeof window === 'undefined' || typeof window.dispatchEvent !== 'function') return;
|
|
@@ -24738,6 +25066,14 @@ window.__ModuleLoader__.load({
|
|
|
24738
25066
|
rounds: petChatContinuousRounds,
|
|
24739
25067
|
},
|
|
24740
25068
|
}));
|
|
25069
|
+
window.dispatchEvent(new CustomEvent('we-pet-voice-state', {
|
|
25070
|
+
detail: {
|
|
25071
|
+
speakPaused: petChatSpeakPaused === true,
|
|
25072
|
+
listenPaused: petChatContinuousPaused === true,
|
|
25073
|
+
listening: petChatListeningNow === true,
|
|
25074
|
+
speaking: (() => { try { return petTts.isSpeaking(); } catch { return false; } })(),
|
|
25075
|
+
},
|
|
25076
|
+
}));
|
|
24741
25077
|
} catch { /* 右键菜单是增强,事件失败不影响对话 */ }
|
|
24742
25078
|
}
|
|
24743
25079
|
|
|
@@ -24746,104 +25082,132 @@ window.__ModuleLoader__.load({
|
|
|
24746
25082
|
petChatContinuousClearTimer();
|
|
24747
25083
|
petChatContinuousActive = true;
|
|
24748
25084
|
petChatContinuousPaused = false;
|
|
24749
|
-
if (petChatContinuousRounds === 0) petChatContinuousSilent = 0;
|
|
24750
25085
|
petBubble.setContinuous(true);
|
|
24751
25086
|
petChatPublishContinuousState();
|
|
24752
25087
|
return true;
|
|
24753
25088
|
}
|
|
24754
25089
|
|
|
25090
|
+
/** 停止常驻聆听(暂停聆听 / 页面隐藏 / 麦克风失败时调用)。 */
|
|
24755
25091
|
function petChatContinuousStop(reason, silent) {
|
|
24756
25092
|
petChatContinuousClearTimer();
|
|
24757
25093
|
petChatContinuousActive = false;
|
|
24758
25094
|
petChatContinuousPaused = true;
|
|
24759
25095
|
petChatContinuousRounds = 0;
|
|
24760
25096
|
petChatContinuousSilent = 0;
|
|
25097
|
+
petChatListeningNow = false;
|
|
24761
25098
|
petBubble.setContinuous(false);
|
|
24762
25099
|
petChatPublishContinuousState();
|
|
24763
25100
|
if (reason && silent !== true) petBubble.status('info', reason, { delay: 3500 });
|
|
24764
25101
|
}
|
|
24765
25102
|
|
|
24766
|
-
/**
|
|
25103
|
+
/** 右键「暂停聆听」:立即停麦 + 停掉自动续听,并持久化(重启后仍暂停)。 */
|
|
24767
25104
|
function petChatContinuousPause(reason) {
|
|
24768
|
-
if (!petChatContinuousEnabled) return false;
|
|
24769
25105
|
petChatVoiceAbort = true;
|
|
24770
25106
|
try { petVoiceIn.stop(); } catch { /* ignore */ }
|
|
24771
|
-
petChatContinuousStop(reason || weT('⏸
|
|
25107
|
+
petChatContinuousStop(reason || weT('⏸ 麦克风已暂停(右键「继续聆听」恢复)'), false);
|
|
25108
|
+
petBubble.status('info', weT('🎤 麦克风已暂停'), { delay: 3000 });
|
|
25109
|
+
void petChatPersistListenPaused(true);
|
|
24772
25110
|
return true;
|
|
24773
25111
|
}
|
|
24774
25112
|
|
|
24775
|
-
/**
|
|
25113
|
+
/** 右键「继续聆听」:恢复常驻聆听,并立刻听下一轮(不用再点桌宠)。 */
|
|
24776
25114
|
function petChatContinuousResume() {
|
|
24777
|
-
if (!petChatContinuousEnabled) return false;
|
|
24778
25115
|
petChatVoiceAbort = false;
|
|
25116
|
+
petChatContinuousEnabled = true;
|
|
24779
25117
|
petChatContinuousPaused = false;
|
|
25118
|
+
// 「恢复后立刻可听」:把最近人声时间拉回现在,不再套用 60s 静默后的 2s 探听节奏。
|
|
25119
|
+
petChatLastHeardAt = Date.now();
|
|
24780
25120
|
petChatContinuousStart();
|
|
24781
|
-
|
|
25121
|
+
void petChatPersistListenPaused(false);
|
|
25122
|
+
petChatContinuousArm(120);
|
|
24782
25123
|
return true;
|
|
24783
25124
|
}
|
|
24784
25125
|
|
|
24785
|
-
/**
|
|
24786
|
-
function
|
|
24787
|
-
|
|
24788
|
-
|
|
24789
|
-
|
|
24790
|
-
|
|
24791
|
-
|
|
24792
|
-
|
|
24793
|
-
|
|
24794
|
-
|
|
24795
|
-
|
|
24796
|
-
|
|
24797
|
-
|
|
25126
|
+
/** 存「暂停聆听」到 voice.listenPaused(宿主持久化;重启后沿用)。 */
|
|
25127
|
+
async function petChatPersistListenPaused(paused) {
|
|
25128
|
+
try {
|
|
25129
|
+
await apiPostJson('/pet-chat/voice/config', { listenPaused: paused === true }, { parse: 'always' });
|
|
25130
|
+
} catch { /* 设置页下次保存会再写 */ }
|
|
25131
|
+
}
|
|
25132
|
+
|
|
25133
|
+
/** 暂停说话:静音 TTS(继续听 + 出字幕)。 */
|
|
25134
|
+
function petChatSetSpeakPaused(paused) {
|
|
25135
|
+
const next = paused === true;
|
|
25136
|
+
petChatSpeakPaused = next;
|
|
25137
|
+
petChatVoice.muted = next;
|
|
25138
|
+
if (next) petSpeakStop();
|
|
25139
|
+
petBubble.setVoiceFlags({ speakPaused: next, listenPaused: petChatContinuousPaused });
|
|
25140
|
+
petBubble.status('info', next ? weT('🔇 仅文字(继续听,不出声)') : weT('🔊 声音已恢复'), { delay: 2600 });
|
|
25141
|
+
petChatPublishContinuousState();
|
|
24798
25142
|
try {
|
|
24799
|
-
void apiPostJson('/pet-chat/voice/config', {
|
|
24800
|
-
.then(() => petChatRefreshVoice())
|
|
24801
|
-
.catch(() => { /* 设置页下次保存会再写 */ });
|
|
25143
|
+
void apiPostJson('/pet-chat/voice/config', { muted: next }, { parse: 'always' });
|
|
24802
25144
|
} catch { /* ignore */ }
|
|
24803
25145
|
return next;
|
|
24804
25146
|
}
|
|
24805
25147
|
|
|
24806
|
-
/**
|
|
25148
|
+
/** 暂停聆听:关麦(不再自动开麦),保留"暂停说话"。 */
|
|
25149
|
+
function petChatSetListenPaused(paused) {
|
|
25150
|
+
const next = paused === true;
|
|
25151
|
+
if (next) petChatContinuousPause();
|
|
25152
|
+
else petChatContinuousResume();
|
|
25153
|
+
petBubble.setVoiceFlags({ speakPaused: petChatSpeakPaused, listenPaused: next });
|
|
25154
|
+
return next;
|
|
25155
|
+
}
|
|
25156
|
+
|
|
25157
|
+
/** 右键菜单事件:toggle / pause / resume(旧协议)+ speak-pause / listen-pause(v3)。 */
|
|
24807
25158
|
function petChatOnContinuousCommand(event) {
|
|
24808
25159
|
const action = String((event && event.detail && event.detail.action) || '');
|
|
24809
|
-
if (action === 'toggle')
|
|
24810
|
-
else if (action === 'set')
|
|
24811
|
-
else if (action === 'pause')
|
|
24812
|
-
else if (action === 'resume')
|
|
25160
|
+
if (action === 'toggle') petChatSetListenPaused(!petChatContinuousPaused);
|
|
25161
|
+
else if (action === 'set') petChatSetListenPaused(event.detail.enabled !== true);
|
|
25162
|
+
else if (action === 'pause') petChatSetListenPaused(true);
|
|
25163
|
+
else if (action === 'resume') petChatSetListenPaused(false);
|
|
25164
|
+
else if (action === 'speak-pause') petChatSetSpeakPaused(!petChatSpeakPaused);
|
|
25165
|
+
else if (action === 'speak-set') petChatSetSpeakPaused(event.detail.paused === true);
|
|
24813
25166
|
}
|
|
24814
25167
|
|
|
24815
|
-
/**
|
|
25168
|
+
/** 静默累计到一定轮次才提示一次,不因为安静就退出常驻聆听。 */
|
|
25169
|
+
function petChatSilenceDelay(delayMs) {
|
|
25170
|
+
const quietFor = Date.now() - petChatLastHeardAt;
|
|
25171
|
+
if (quietFor >= PET_CHAT_QUIET_AFTER_MS) return PET_CHAT_QUIET_PROBE_MS;
|
|
25172
|
+
return Math.max(PET_CHAT_LISTEN_RESUME_MS, Number(delayMs) || PET_CHAT_LISTEN_RESUME_MS);
|
|
25173
|
+
}
|
|
25174
|
+
|
|
25175
|
+
/** 朗读结束 / 一次静默后,延迟 300ms 自动开麦(半双工:播完才听)。 */
|
|
24816
25176
|
function petChatContinuousArm(delayMs) {
|
|
24817
25177
|
if (!petChatContinuousEnabled || !petChatContinuousActive || petChatContinuousPaused) return;
|
|
24818
|
-
if (petChatContinuousRounds >= PET_CHAT_CONTINUOUS_MAX_ROUNDS) {
|
|
24819
|
-
petChatContinuousStop(weT('连续对话结束:已连续 {n} 轮', { n: PET_CHAT_CONTINUOUS_MAX_ROUNDS }));
|
|
24820
|
-
return;
|
|
24821
|
-
}
|
|
24822
25178
|
petChatContinuousClearTimer();
|
|
24823
25179
|
petChatShowContinuousListening();
|
|
25180
|
+
const waitMs = petChatSilenceDelay(delayMs);
|
|
24824
25181
|
petChatContinuousTimer = setTimeout(() => {
|
|
24825
25182
|
petChatContinuousTimer = null;
|
|
24826
25183
|
if (!petChatContinuousEnabled || !petChatContinuousActive || petChatContinuousPaused) return;
|
|
25184
|
+
// 半双工硬约束:正在朗读时**绝不开麦**(等 onIdle 再排下一拍)。
|
|
25185
|
+
try { if (petTts.isSpeaking()) return; } catch { /* 实例未就绪时照常开麦 */ }
|
|
24827
25186
|
petChatVoiceAbort = false;
|
|
25187
|
+
petChatListeningNow = true;
|
|
25188
|
+
petChatPublishContinuousState();
|
|
24828
25189
|
void petVoiceIn.start();
|
|
24829
|
-
},
|
|
25190
|
+
}, waitMs);
|
|
24830
25191
|
}
|
|
24831
25192
|
|
|
24832
|
-
/**
|
|
25193
|
+
/**
|
|
25194
|
+
* 一次语音轮次失败:静默类(没听到/太小声)继续听,设备类错误退出常驻聆听并提示。
|
|
25195
|
+
*/
|
|
24833
25196
|
function petChatContinuousVoiceError(code) {
|
|
24834
25197
|
if (!petChatContinuousActive || petChatContinuousPaused) return;
|
|
24835
25198
|
const silent = ['no-speech', 'unclear', 'too-quiet'].includes(String(code || ''));
|
|
24836
25199
|
if (!silent) {
|
|
24837
|
-
|
|
25200
|
+
// 麦克风被占用 / 权限失败:退出常驻聆听(不静默),并把提示留在状态条。
|
|
25201
|
+
petChatContinuousStop(weT('常驻聆听已暂停:{e}(右键「继续聆听」重试)', { e: code || '麦克风不可用' }));
|
|
25202
|
+
void petChatPersistListenPaused(true);
|
|
24838
25203
|
return;
|
|
24839
25204
|
}
|
|
24840
25205
|
petChatContinuousSilent += 1;
|
|
24841
|
-
|
|
24842
|
-
|
|
24843
|
-
|
|
25206
|
+
petChatContinuousRounds += 1;
|
|
25207
|
+
if (petChatContinuousSilent % PET_CHAT_SILENT_PROMPT_EVERY === 0) {
|
|
25208
|
+
petBubble.status('info', weT('还在听(没听到人声,{n} 次)', { n: petChatContinuousSilent }), { delay: 1600 });
|
|
24844
25209
|
}
|
|
24845
|
-
|
|
24846
|
-
petChatContinuousArm(500);
|
|
25210
|
+
petChatContinuousArm(PET_CHAT_LISTEN_RESUME_MS);
|
|
24847
25211
|
}
|
|
24848
25212
|
|
|
24849
25213
|
/* ── v2 大脑(前端侧):情绪语速 / 环境快照 / 动作回执 / 主动触发 ─────────── */
|
|
@@ -24964,6 +25328,20 @@ window.__ModuleLoader__.load({
|
|
|
24964
25328
|
* 失败返回 `{ok:false,error}`,由宿主统一说人话 —— 这里只负责把真实结果回执回去。
|
|
24965
25329
|
*/
|
|
24966
25330
|
async function petChatApplyAction(tool, args) {
|
|
25331
|
+
if (tool === 'wallpaper_volume') {
|
|
25332
|
+
// 任务 §6② volume_set(target=wallpaper):写壁纸音轨音量并回读 selection.videoVolume。
|
|
25333
|
+
const percent = Math.max(0, Math.min(100, Math.round(Number(args && args.percent) || 0)));
|
|
25334
|
+
try {
|
|
25335
|
+
if (typeof onVideoVolume !== 'function') return { ok: false, error: 'unsupported' };
|
|
25336
|
+
onVideoVolume(percent);
|
|
25337
|
+
} catch {
|
|
25338
|
+
return { ok: false, error: 'apply-failed' };
|
|
25339
|
+
}
|
|
25340
|
+
await new Promise((resolve) => { setTimeout(resolve, 200); });
|
|
25341
|
+
const actual = Math.round(Number(selection && selection.videoVolume || 0) * 100);
|
|
25342
|
+
if (Math.abs(actual - percent) > 2) return { ok: false, error: 'not-applied', percent: actual };
|
|
25343
|
+
return { ok: true, percent: actual, verified: true };
|
|
25344
|
+
}
|
|
24967
25345
|
if (tool === 'wallpaper_cycle') {
|
|
24968
25346
|
const enabled = !(args && args.enabled === false);
|
|
24969
25347
|
const before = Boolean(selection && selection.rotationEnabled);
|
|
@@ -25054,6 +25432,7 @@ window.__ModuleLoader__.load({
|
|
|
25054
25432
|
ok: result.ok === true,
|
|
25055
25433
|
targetId: result.targetId || '',
|
|
25056
25434
|
title: result.title || '',
|
|
25435
|
+
percent: Number.isFinite(Number(result.percent)) ? Number(result.percent) : undefined,
|
|
25057
25436
|
error: result.error || '',
|
|
25058
25437
|
}, { parse: 'always' });
|
|
25059
25438
|
} catch { /* 回执失败由宿主超时判失败,不会谎报成功 */ }
|
|
@@ -25103,6 +25482,7 @@ window.__ModuleLoader__.load({
|
|
|
25103
25482
|
const result = await petChatApplyAction(String(action.tool || ''), action.args || {});
|
|
25104
25483
|
let say = '';
|
|
25105
25484
|
if (action.tool === 'wallpaper_cycle') say = result.ok ? (result.enabled ? '轮播打开了。' : '轮播关掉了。') : '轮播没切成功。';
|
|
25485
|
+
else if (action.tool === 'wallpaper_volume') say = result.ok ? `壁纸音量调到 ${result.percent}% 了。` : '壁纸音量没调成。';
|
|
25106
25486
|
else if (result.ok) say = result.title ? `换成「${result.title}」了。` : '换好了。';
|
|
25107
25487
|
else say = result.error === 'no-match' ? '没找到那张壁纸。' : '没换成,再试一次吧。';
|
|
25108
25488
|
petBubble.show(say);
|
|
@@ -25212,8 +25592,10 @@ window.__ModuleLoader__.load({
|
|
|
25212
25592
|
onState: (kind) => { petBubble.setState(kind); },
|
|
25213
25593
|
onIdle: () => {
|
|
25214
25594
|
petBubble.hide(3000);
|
|
25215
|
-
|
|
25216
|
-
|
|
25595
|
+
petChatListeningNow = false;
|
|
25596
|
+
// 播完 300ms 自动恢复听(半双工:朗读期间绝不录音)。
|
|
25597
|
+
if (petChatContinuousActive && !petChatContinuousPaused) petChatContinuousArm(PET_CHAT_LISTEN_RESUME_MS);
|
|
25598
|
+
petChatPublishContinuousState();
|
|
25217
25599
|
},
|
|
25218
25600
|
onVoiceFallback: (actual) => {
|
|
25219
25601
|
// pre.54(B3④):宿主回落到本机默认音色时明确提示,不静默换音色。
|
|
@@ -25319,6 +25701,11 @@ window.__ModuleLoader__.load({
|
|
|
25319
25701
|
const enqueueSpeech = (piece) => {
|
|
25320
25702
|
const line = String(piece || '').trim();
|
|
25321
25703
|
if (!line) return;
|
|
25704
|
+
// 任务 §4③:「暂停说话」= 跳过 TTS 队列,只出字幕;状态条显示「🔇 仅文字」。
|
|
25705
|
+
if (petChatSpeakPaused) {
|
|
25706
|
+
petBubble.setState('muted');
|
|
25707
|
+
return;
|
|
25708
|
+
}
|
|
25322
25709
|
// v2:本轮语速由宿主 meta 给(夜间/疲惫 -1 = -10%);再叠加当前人设的 voice.rate。
|
|
25323
25710
|
if (petSpeak(line, { rate: petChatSpeechRate + (Number(petChatVoice.rate) || 0) })) queuedSpeech += 1;
|
|
25324
25711
|
};
|
|
@@ -25396,20 +25783,15 @@ window.__ModuleLoader__.load({
|
|
|
25396
25783
|
// 最后一段没有句末标点也要念(比如“我也在”)
|
|
25397
25784
|
enqueueSpeech(speakBuffer);
|
|
25398
25785
|
if (typeof onState === 'function') onState({ state: 'idle' });
|
|
25399
|
-
//
|
|
25400
|
-
|
|
25401
|
-
|
|
25402
|
-
|
|
25403
|
-
|
|
25404
|
-
|
|
25405
|
-
|
|
25406
|
-
|
|
25407
|
-
|
|
25408
|
-
petChatPublishContinuousState();
|
|
25409
|
-
if (!queuedSpeech) petChatContinuousArm();
|
|
25410
|
-
}
|
|
25411
|
-
// 没有任何一句进入朗读(静音 / 合成不可用)⇒ 沿用旧行为:整段文字 3 秒后淡出。
|
|
25412
|
-
// 有朗读时由 petTts 的 onIdle 在念完后淡出(按句字幕不会被提前清掉)。
|
|
25786
|
+
// 本轮成功:常驻聆听继续(任务 §4:装好就在听,不靠"点了才听");
|
|
25787
|
+
// 有朗读时等 onIdle 播完再开麦(半双工),没朗读(暂停说话/静音)直接 300ms 后排下一轮。
|
|
25788
|
+
if (!petChatContinuousActive && !petChatContinuousPaused) petChatContinuousStart();
|
|
25789
|
+
petChatLastHeardAt = Date.now();
|
|
25790
|
+
petChatContinuousRounds += 1;
|
|
25791
|
+
petChatContinuousSilent = 0;
|
|
25792
|
+
petChatPublishContinuousState();
|
|
25793
|
+
if (!queuedSpeech) petChatContinuousArm();
|
|
25794
|
+
// 没有任何一句进入朗读(暂停说话 / 合成不可用)⇒ 字幕照常显示,3 秒后淡出。
|
|
25413
25795
|
if (!queuedSpeech) petBubble.hide(3000);
|
|
25414
25796
|
petChatTurnEnd();
|
|
25415
25797
|
},
|
|
@@ -25501,18 +25883,23 @@ window.__ModuleLoader__.load({
|
|
|
25501
25883
|
/** 每次点桌宠递增;收起/重开时让旧的 ASR 等待自动作废。 */
|
|
25502
25884
|
let petChatWakeSeq = 0;
|
|
25503
25885
|
|
|
25504
|
-
/**
|
|
25886
|
+
/** 点桌宠:常驻聆听默认在听 —— 点它只做三件事:打断朗读 / 恢复聆听 / 收起气泡。 */
|
|
25505
25887
|
function petChatWake() {
|
|
25506
25888
|
// **任何一次唤醒都是 barge-in**:先把正在念的停掉,再决定是收起还是开麦。
|
|
25507
25889
|
petSpeakStop();
|
|
25508
25890
|
void petChatRefreshVoice();
|
|
25509
25891
|
const seq = ++petChatWakeSeq;
|
|
25510
|
-
|
|
25511
|
-
|
|
25512
|
-
|
|
25892
|
+
// 暂停聆听中点桌宠 = 恢复常驻聆听(不用再去右键菜单)。
|
|
25893
|
+
if (petChatContinuousPaused) {
|
|
25894
|
+
petChatContinuousResume();
|
|
25895
|
+
return;
|
|
25896
|
+
}
|
|
25897
|
+
if (petChatContinuousActive) {
|
|
25898
|
+
// 已经常驻聆听:点一下只收起气泡/状态条,**不关麦**(任务 §4:装好就在听)。
|
|
25513
25899
|
petBubble.hide(0);
|
|
25514
25900
|
petBubble.hideStatus(0);
|
|
25515
|
-
|
|
25901
|
+
petBubble.setContinuous(true);
|
|
25902
|
+
if (!petChatContinuousTimer && !petChatListeningNow) petChatContinuousArm(PET_CHAT_LISTEN_RESUME_MS);
|
|
25516
25903
|
return;
|
|
25517
25904
|
}
|
|
25518
25905
|
if (petBubble.isVisible()) { petBubble.hide(0); petBubble.hideStatus(0); petVoiceIn.stop(); return; }
|
|
@@ -25535,15 +25922,59 @@ window.__ModuleLoader__.load({
|
|
|
25535
25922
|
if (seq !== petChatWakeSeq) return;
|
|
25536
25923
|
petChatVoiceAbort = false;
|
|
25537
25924
|
petBubble.setState('listen');
|
|
25925
|
+
petChatListeningNow = true;
|
|
25538
25926
|
const started = await petVoiceIn.start();
|
|
25539
25927
|
if (!started) return; // 失败分支已经由 onError 提示(回落打字)
|
|
25540
25928
|
// 状态条已经由 setState('listen') 显示「🎤 在听」,这里不再往回答气泡里塞提示。
|
|
25541
25929
|
})();
|
|
25542
25930
|
}
|
|
25543
25931
|
|
|
25932
|
+
/**
|
|
25933
|
+
* 添加/恢复常驻聆听(安装后自动跑一次;右键「继续聆听」也走它)。
|
|
25934
|
+
* ASR 没就绪时先准备模型(进度显示在状态条),就绪后才开麦。
|
|
25935
|
+
*/
|
|
25936
|
+
async function petChatResidentStart(seqGuard) {
|
|
25937
|
+
// 没填模型 Key 就不开麦(隐私 + 体验):先让用户去设置里配置。
|
|
25938
|
+
if (!petChatModelReady) {
|
|
25939
|
+
petBubble.status('info', weT('先填模型 Key,我才能听懂你说话(设置 → 智能大肥鱼)'), { delay: 7000 });
|
|
25940
|
+
return false;
|
|
25941
|
+
}
|
|
25942
|
+
const seq = typeof seqGuard === 'number' ? seqGuard : ++petChatWakeSeq;
|
|
25943
|
+
if (petChatContinuousPaused || petChatContinuousEnabled !== true) {
|
|
25944
|
+
petBubble.setVoiceFlags({ speakPaused: petChatSpeakPaused, listenPaused: true });
|
|
25945
|
+
return false;
|
|
25946
|
+
}
|
|
25947
|
+
const resp = await apiJson('/pet-chat/asr', { parse: 'always' }).catch(() => null);
|
|
25948
|
+
const doc = (resp && resp.data) || {};
|
|
25949
|
+
if (doc.available === false) {
|
|
25950
|
+
petChatContinuousStop(weT('这个 DSH 版本没有语音转写服务:常驻聆听不可用,先打字吧'));
|
|
25951
|
+
petBubble.status('error', weT('这个 DSH 版本没有语音转写服务,先打字吧'), { delay: 6000 });
|
|
25952
|
+
return false;
|
|
25953
|
+
}
|
|
25954
|
+
if (!doc.ready) {
|
|
25955
|
+
const ready = await ensureAsrReady(() => seq !== petChatWakeSeq);
|
|
25956
|
+
if (!ready || seq !== petChatWakeSeq) return false;
|
|
25957
|
+
}
|
|
25958
|
+
if (seq !== petChatWakeSeq) return false;
|
|
25959
|
+
// 回到页面 / 刚恢复:不要因为之前安静了很久而等 2 秒,立刻进入听。
|
|
25960
|
+
petChatLastHeardAt = Date.now();
|
|
25961
|
+
petChatContinuousStart();
|
|
25962
|
+
petChatContinuousArm(120);
|
|
25963
|
+
// 首次进入常驻聆听的一次性告知(不弹窗,只气泡)。
|
|
25964
|
+
try {
|
|
25965
|
+
const NOTICE_KEY = 'dsh-folia:resident-notice-v1';
|
|
25966
|
+
if (window.localStorage && !window.localStorage.getItem(NOTICE_KEY)) {
|
|
25967
|
+
window.localStorage.setItem(NOTICE_KEY, '1');
|
|
25968
|
+
petBubble.status('info', weT('我会一直听着,直接说话就行;右键可「暂停聆听」'), { delay: 6500 });
|
|
25969
|
+
}
|
|
25970
|
+
} catch { /* 隐私模式/无 localStorage 时忽略 */ }
|
|
25971
|
+
return true;
|
|
25972
|
+
}
|
|
25973
|
+
|
|
25544
25974
|
/** 连续对话等待/开麦时的状态条:独立成函数,确保补丁位置在 ASR 就绪判断之后。 */
|
|
25545
25975
|
function petChatShowContinuousListening() {
|
|
25546
25976
|
petBubble.setContinuous(true);
|
|
25977
|
+
petBubble.setVoiceFlags({ speakPaused: petChatSpeakPaused, listenPaused: petChatContinuousPaused });
|
|
25547
25978
|
petBubble.setState('listen');
|
|
25548
25979
|
}
|
|
25549
25980
|
|
|
@@ -25553,6 +25984,28 @@ window.__ModuleLoader__.load({
|
|
|
25553
25984
|
* `window.__dshFoliaPet.speak(text)` / 派发 `we-pet-speak` 事件。
|
|
25554
25985
|
* EventSource 自带重连;这里不弹任何提示。
|
|
25555
25986
|
*/
|
|
25987
|
+
/**
|
|
25988
|
+
* 桌面通知(任务 §6② notify):宿主经 /events 推 `{type:'notify'}`。
|
|
25989
|
+
* 浏览器 Notification 被系统拦掉时回落气泡状态条 —— 不静默丢通知。
|
|
25990
|
+
*/
|
|
25991
|
+
function petChatShowNotify(doc) {
|
|
25992
|
+
const title = String((doc && doc.title) || '桌宠');
|
|
25993
|
+
const text = String((doc && doc.text) || '').trim();
|
|
25994
|
+
if (!text) return;
|
|
25995
|
+
try {
|
|
25996
|
+
const N = typeof Notification === 'function' ? Notification : null;
|
|
25997
|
+
if (N && N.permission === 'granted') {
|
|
25998
|
+
const note = new N(title, { body: text });
|
|
25999
|
+
setTimeout(() => { try { note.close(); } catch { /* ignore */ } }, 6000);
|
|
26000
|
+
return;
|
|
26001
|
+
}
|
|
26002
|
+
if (N && N.permission === 'default' && typeof N.requestPermission === 'function') {
|
|
26003
|
+
void N.requestPermission().catch(() => {});
|
|
26004
|
+
}
|
|
26005
|
+
} catch { /* Electron 可能没有 Notification */ }
|
|
26006
|
+
petBubble.status('info', `🔔 ${title}:${text}`, { delay: 6000 });
|
|
26007
|
+
}
|
|
26008
|
+
|
|
25556
26009
|
let petChatEventSource = null;
|
|
25557
26010
|
function petChatEventsStart() {
|
|
25558
26011
|
if (petChatEventSource || typeof EventSource !== 'function') return;
|
|
@@ -25561,7 +26014,9 @@ window.__ModuleLoader__.load({
|
|
|
25561
26014
|
source.onmessage = (event) => {
|
|
25562
26015
|
let doc;
|
|
25563
26016
|
try { doc = JSON.parse((event && event.data) || ''); } catch { doc = null; }
|
|
25564
|
-
if (!doc
|
|
26017
|
+
if (!doc) return;
|
|
26018
|
+
if (doc.type === 'notify') { petChatShowNotify(doc); return; }
|
|
26019
|
+
if (doc.type !== 'speak' || !doc.text) return;
|
|
25565
26020
|
petSpeak(String(doc.text), { voice: doc.voice, rate: doc.rate });
|
|
25566
26021
|
};
|
|
25567
26022
|
source.onerror = () => { /* EventSource 自动重连;失败不打扰用户 */ };
|
|
@@ -25604,20 +26059,44 @@ window.__ModuleLoader__.load({
|
|
|
25604
26059
|
|
|
25605
26060
|
window.addEventListener('we-pet-talk', onTalkEvent);
|
|
25606
26061
|
window.addEventListener('we-pet-speak', onSpeakEvent);
|
|
25607
|
-
//
|
|
26062
|
+
// 右键菜单:常驻聆听 / 暂停说话(v3 §4)。旧 we-pet-continuous 保留兼容。
|
|
25608
26063
|
const onContinuousEvent = (event) => { petChatOnContinuousCommand(event); };
|
|
25609
26064
|
window.addEventListener('we-pet-continuous', onContinuousEvent);
|
|
25610
|
-
|
|
26065
|
+
const onSpeakPauseEvent = (event) => {
|
|
26066
|
+
const detail = (event && event.detail) || {};
|
|
26067
|
+
petChatSetSpeakPaused(detail.paused === undefined ? !petChatSpeakPaused : detail.paused === true);
|
|
26068
|
+
};
|
|
26069
|
+
const onListenPauseEvent = (event) => {
|
|
26070
|
+
const detail = (event && event.detail) || {};
|
|
26071
|
+
petChatSetListenPaused(detail.paused === undefined ? !petChatContinuousPaused : detail.paused === true);
|
|
26072
|
+
};
|
|
26073
|
+
window.addEventListener('we-pet-speak-pause', onSpeakPauseEvent);
|
|
26074
|
+
window.addEventListener('we-pet-listen-pause', onListenPauseEvent);
|
|
26075
|
+
// 页面隐藏:暂时停麦(不持久化,回到页面自动恢复);不偷偷在后台开麦。
|
|
25611
26076
|
const onVisibility = () => {
|
|
25612
|
-
if (typeof document === 'undefined'
|
|
25613
|
-
if (
|
|
25614
|
-
|
|
26077
|
+
if (typeof document === 'undefined') return;
|
|
26078
|
+
if (document.visibilityState === 'hidden') {
|
|
26079
|
+
if (petChatContinuousActive && !petChatContinuousPaused) {
|
|
26080
|
+
petChatVoiceAbort = true;
|
|
26081
|
+
try { petVoiceIn.stop(); } catch { /* ignore */ }
|
|
26082
|
+
petChatContinuousClearTimer();
|
|
26083
|
+
petChatListeningNow = false;
|
|
26084
|
+
petBubble.setContinuous(false);
|
|
26085
|
+
petChatPublishContinuousState();
|
|
26086
|
+
}
|
|
26087
|
+
return;
|
|
25615
26088
|
}
|
|
26089
|
+
// 回到页面:如果没被「暂停聆听」,300ms 内恢复听。
|
|
26090
|
+
if (!petChatContinuousPaused && petChatContinuousEnabled) petChatResidentStart();
|
|
25616
26091
|
};
|
|
25617
26092
|
document.addEventListener('visibilitychange', onVisibility);
|
|
25618
26093
|
document.addEventListener('click', onDocumentClick, true);
|
|
25619
26094
|
document.addEventListener('keydown', onKeyDown, true);
|
|
25620
|
-
|
|
26095
|
+
// 任务 §4:安装/启动后自动进入常驻聆听(受持久化的「暂停聆听」约束)。
|
|
26096
|
+
void petChatRefreshVoice().then(() => {
|
|
26097
|
+
petChatPublishContinuousState();
|
|
26098
|
+
if (!petChatContinuousPaused) void petChatResidentStart();
|
|
26099
|
+
}).catch(() => {});
|
|
25621
26100
|
petChatEventsStart();
|
|
25622
26101
|
// v2 主动发起:壁纸变化 → 30 秒后点评;连续工作 45 分钟 → 休息提醒;挂载后试早晚问候。
|
|
25623
26102
|
// 三条都受“正在朗读 / 正在听 / 一轮回答中 / 页面隐藏”约束(见 petChatProactiveAllowed)。
|
|
@@ -25631,12 +26110,20 @@ window.__ModuleLoader__.load({
|
|
|
25631
26110
|
stop: () => petSpeakStop(),
|
|
25632
26111
|
chat: (text) => { petChatInputMode = 'text'; return petVoiceIn.postChat(String(text || '')); },
|
|
25633
26112
|
isSpeaking: () => petTts.isSpeaking(),
|
|
26113
|
+
// 任务 §4:两个开关(菜单之外的对外通道;判据也用它)
|
|
26114
|
+
setSpeakPaused: (paused) => petChatSetSpeakPaused(paused === true),
|
|
26115
|
+
setListenPaused: (paused) => petChatSetListenPaused(paused === true),
|
|
26116
|
+
isListening: () => petChatListeningNow === true,
|
|
26117
|
+
isSpeakPaused: () => petChatSpeakPaused === true,
|
|
26118
|
+
isListenPaused: () => petChatContinuousPaused === true,
|
|
25634
26119
|
};
|
|
25635
26120
|
} catch { /* 被别的插件占用就只保留事件通道 */ }
|
|
25636
26121
|
return () => {
|
|
25637
26122
|
window.removeEventListener('we-pet-talk', onTalkEvent);
|
|
25638
26123
|
window.removeEventListener('we-pet-speak', onSpeakEvent);
|
|
25639
26124
|
window.removeEventListener('we-pet-continuous', onContinuousEvent);
|
|
26125
|
+
window.removeEventListener('we-pet-speak-pause', onSpeakPauseEvent);
|
|
26126
|
+
window.removeEventListener('we-pet-listen-pause', onListenPauseEvent);
|
|
25640
26127
|
document.removeEventListener('click', onDocumentClick, true);
|
|
25641
26128
|
document.removeEventListener('keydown', onKeyDown, true);
|
|
25642
26129
|
document.removeEventListener('visibilitychange', onVisibility);
|