dsh-folia 4.26.0-pre.76 → 4.26.0-pre.78
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 +268 -15
- package/lib/index.js +9 -0
- package/lib/persona-store.js +15 -0
- package/lib/persona-tool-log.js +3 -0
- package/lib/pet-chat-brain.js +487 -1
- package/lib/pet-chat-tools.js +274 -1
- package/lib/route-registry.js +2 -0
- package/lib/routes/pet-chat.js +513 -20
- package/lib/tts/sing-synth.js +541 -0
- package/lib/tts/singing.js +386 -0
- package/lib/tts/tts-worker.cjs +21 -6
- package/lib/tts/tts.js +2 -0
- package/lib/voice/record.js +3 -2
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -744,6 +744,13 @@ window.__ModuleLoader__.load({
|
|
|
744
744
|
"在听": "Listening",
|
|
745
745
|
"在想": "Thinking",
|
|
746
746
|
"在说": "Speaking",
|
|
747
|
+
// v5:唱歌(按谱清唱)
|
|
748
|
+
"在唱": "Singing",
|
|
749
|
+
"深度思考中…": "Thinking deeply…",
|
|
750
|
+
"唱完啦(清唱,无伴奏)": "Song finished (a cappella, no backing track)",
|
|
751
|
+
"这首歌的音频放不出来(文件坏了或播放器不可用)": "This song's audio cannot play (corrupt file or unavailable player)",
|
|
752
|
+
"浏览器拦了自动播放:再点一次「唱首歌」": "The browser blocked autoplay — click 'sing a song' again",
|
|
753
|
+
"唱歌音频没放起来": "The song audio did not start",
|
|
747
754
|
// pre.63:连续对话(右键菜单 + 设置页同一 voice.continuous)
|
|
748
755
|
"连续对话": "Continuous conversation",
|
|
749
756
|
"暂停听": "Pause listening",
|
|
@@ -19768,6 +19775,33 @@ window.__ModuleLoader__.load({
|
|
|
19768
19775
|
}
|
|
19769
19776
|
}, []);
|
|
19770
19777
|
|
|
19778
|
+
/** v5 §4:已安装插件/技能能力(只列不调用,逐项启用)。 */
|
|
19779
|
+
const [caps, setCaps] = React.useState({ loading: false, skills: [], plugins: [], note: null });
|
|
19780
|
+
const loadCapabilities = React.useCallback(async () => {
|
|
19781
|
+
setCaps((prev) => ({ ...prev, loading: true }));
|
|
19782
|
+
try {
|
|
19783
|
+
const data = unwrap(await apiJson('/pet-chat/capabilities', { parse: 'always' }));
|
|
19784
|
+
setCaps({
|
|
19785
|
+
loading: false,
|
|
19786
|
+
skills: Array.isArray(data.skills) ? data.skills : [],
|
|
19787
|
+
plugins: Array.isArray(data.plugins) ? data.plugins : [],
|
|
19788
|
+
note: String(data.note || ''),
|
|
19789
|
+
});
|
|
19790
|
+
} catch {
|
|
19791
|
+
setCaps((prev) => ({ ...prev, loading: false, note: '读取已安装能力失败' }));
|
|
19792
|
+
}
|
|
19793
|
+
}, []);
|
|
19794
|
+
const toggleCapability = async (id, enabled) => {
|
|
19795
|
+
setPermBusy(true);
|
|
19796
|
+
try {
|
|
19797
|
+
const data = unwrap(await apiPostJson('/pet-chat/capabilities', { id, enabled }, { parse: 'always' }));
|
|
19798
|
+
if (!data.ok) throw new Error(data.hint || 'toggle-failed');
|
|
19799
|
+
await loadCapabilities();
|
|
19800
|
+
} catch (error) {
|
|
19801
|
+
setCaps((prev) => ({ ...prev, note: String((error && error.message) || '操作失败') }));
|
|
19802
|
+
} finally { setPermBusy(false); }
|
|
19803
|
+
};
|
|
19804
|
+
|
|
19771
19805
|
const saveToolWhitelist = async () => {
|
|
19772
19806
|
setPermBusy(true);
|
|
19773
19807
|
try {
|
|
@@ -19901,7 +19935,8 @@ window.__ModuleLoader__.load({
|
|
|
19901
19935
|
if (detailTab === 'voice' && !voiceCatalog) void loadVoiceCatalog();
|
|
19902
19936
|
if (detailTab === 'permissions') void loadPermissions(selected.id);
|
|
19903
19937
|
if (detailTab === 'permissions') void loadToolWhitelist();
|
|
19904
|
-
|
|
19938
|
+
if (detailTab === 'permissions') void loadCapabilities();
|
|
19939
|
+
}, [selected, detailTab, loadMemory, loadVoices, voices.length, voiceCatalog, loadVoiceCatalog, loadPermissions, loadToolWhitelist, loadCapabilities]);
|
|
19905
19940
|
|
|
19906
19941
|
const packAction = async (kind, pack) => {
|
|
19907
19942
|
if (!pack) return;
|
|
@@ -20816,6 +20851,32 @@ window.__ModuleLoader__.load({
|
|
|
20816
20851
|
toolWl.note
|
|
20817
20852
|
? React.createElement('div', { className: 'we-picker__hint', style: { color: toolWl.note.ok ? undefined : '#f87171' } }, toolWl.note.text)
|
|
20818
20853
|
: null),
|
|
20854
|
+
// v5 §4:已安装插件与技能(只列不调用 → 逐项启用)。
|
|
20855
|
+
React.createElement('div', { style: { marginTop: '10px', paddingTop: '8px', borderTop: '1px solid rgba(255,255,255,.10)' } },
|
|
20856
|
+
React.createElement('div', { style: { fontSize: '12px', fontWeight: 600 } }, '已安装插件与技能',
|
|
20857
|
+
personaTag(`${(caps.skills || []).length} 个技能 / ${(caps.plugins || []).length} 个插件`, '')),
|
|
20858
|
+
React.createElement('div', { className: 'we-picker__hint', style: { margin: '2px 0 4px' } },
|
|
20859
|
+
caps.note || '只列出已安装的能力;调用默认询问,且每个能力要单独启用;调用会写审计。'),
|
|
20860
|
+
caps.loading ? React.createElement('div', { className: 'we-picker__hint' }, '正在扫描已安装能力…') : null,
|
|
20861
|
+
(caps.skills || []).length === 0
|
|
20862
|
+
? React.createElement('div', { className: 'we-picker__hint' }, '没有发现技能目录(~/.dsh/skills、项目 .dsh/skills、随包 office-skills 都没有 SKILL.md)。')
|
|
20863
|
+
: (caps.skills || []).map((skill) => React.createElement('div', { key: skill.id, style: { ...PERSONA_STYLE.row, justifyContent: 'space-between', gap: '6px', padding: '2px 0' } },
|
|
20864
|
+
React.createElement('div', { style: { minWidth: 0 } },
|
|
20865
|
+
React.createElement('div', { style: { fontSize: '12px', fontWeight: 600 } }, skill.label || skill.name,
|
|
20866
|
+
personaTag(skill.source === 'ctx.skills' ? '宿主服务' : '技能文件', '')),
|
|
20867
|
+
React.createElement('div', { className: 'we-picker__hint', style: { margin: 0, whiteSpace: 'normal' } }, skill.description || '')),
|
|
20868
|
+
React.createElement('label', { style: { display: 'flex', gap: '4px', alignItems: 'center', fontSize: '11px', flexShrink: 0 } },
|
|
20869
|
+
React.createElement('input', {
|
|
20870
|
+
type: 'checkbox', checked: skill.enabled === true, disabled: permBusy,
|
|
20871
|
+
onChange: (e) => { void toggleCapability(skill.id, e.target.checked); },
|
|
20872
|
+
}),
|
|
20873
|
+
'允许调用'))),
|
|
20874
|
+
(caps.plugins || []).length
|
|
20875
|
+
? React.createElement('div', { style: { marginTop: '6px' } },
|
|
20876
|
+
React.createElement('div', { className: 'we-picker__hint', style: { margin: '2px 0' } }, '已安装插件(无通用调用面,只读列出):'),
|
|
20877
|
+
(caps.plugins || []).slice(0, 12).map((plugin) => React.createElement('div', { key: plugin.id, style: { fontSize: '11px', opacity: .8 } },
|
|
20878
|
+
`· ${plugin.name}${plugin.version ? ' v' + plugin.version : ''} — ${plugin.description || plugin.label || ''}`.slice(0, 120))))
|
|
20879
|
+
: null),
|
|
20819
20880
|
permNote ? React.createElement('div', { className: 'we-picker__hint', style: { color: permNote.ok ? undefined : '#f87171' } }, permNote.text) : null,
|
|
20820
20881
|
React.createElement('div', { style: { fontSize: '12px', fontWeight: 600, marginTop: '10px' } },
|
|
20821
20882
|
'最近调用记录', personaTag(`共 ${perm.toolLog ? perm.toolLog.total : 0} 条`, '')),
|
|
@@ -22103,7 +22164,7 @@ window.__ModuleLoader__.load({
|
|
|
22103
22164
|
|
|
22104
22165
|
React.useEffect(() => {
|
|
22105
22166
|
void (async () => {
|
|
22106
|
-
const resp = await apiJson("/pet-chat/capabilities", { parse: "always" }).catch(() => null);
|
|
22167
|
+
const resp = await apiJson("/pet-chat/capabilities/catalog", { parse: "always" }).catch(() => null);
|
|
22107
22168
|
const doc = (resp && resp.data) || null;
|
|
22108
22169
|
if (doc && Array.isArray(doc.items)) setState((prev) => ({ ...prev, items: doc.items, error: null }));
|
|
22109
22170
|
else setState((prev) => ({ ...prev, error: weT("读取失败,重开设置页再试") }));
|
|
@@ -24096,6 +24157,7 @@ window.__ModuleLoader__.load({
|
|
|
24096
24157
|
'.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;}',
|
|
24097
24158
|
'.we-pet-status[data-state="think"]::after{content:"…";margin-left:1px;opacity:.8;animation:we-pet-status-blink 1.1s steps(2,end) infinite;}',
|
|
24098
24159
|
'.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;}',
|
|
24160
|
+
'.we-pet-status[data-state="sing"]::after{content:"";display:block;width:34px;height:11px;opacity:.9;background:linear-gradient(currentColor,currentColor) 0 100%/3px 40% no-repeat,linear-gradient(currentColor,currentColor) 6px 100%/3px 85% no-repeat,linear-gradient(currentColor,currentColor) 12px 100%/3px 55% no-repeat,linear-gradient(currentColor,currentColor) 18px 100%/3px 100% no-repeat,linear-gradient(currentColor,currentColor) 24px 100%/3px 60% no-repeat,linear-gradient(currentColor,currentColor) 30px 100%/3px 30% no-repeat;transform-origin:0 100%;animation:we-pet-status-wave .55s ease-in-out infinite alternate;}',
|
|
24099
24161
|
'.we-pet-status[data-state="muted"]{opacity:.92;}',
|
|
24100
24162
|
'.we-pet-status[data-state="error"]{border-color:rgba(255,120,120,.45);}',
|
|
24101
24163
|
'@keyframes we-pet-status-wave{from{transform:scaleY(.55);opacity:.55;}to{transform:scaleY(1);opacity:.95;}}',
|
|
@@ -24331,6 +24393,29 @@ window.__ModuleLoader__.load({
|
|
|
24331
24393
|
applyText(next, visible);
|
|
24332
24394
|
}
|
|
24333
24395
|
|
|
24396
|
+
/**
|
|
24397
|
+
* 清唱歌词:逐行显示 + 当前行高亮('▶')。**不做淡入淡出**(每 120ms 更新,
|
|
24398
|
+
* 用 show() 会每次触发替换动画)。`meta.title` 只在第一次带上。
|
|
24399
|
+
*/
|
|
24400
|
+
function showLyrics(lines, activeIndex, meta) {
|
|
24401
|
+
if (!ensure()) return;
|
|
24402
|
+
cancelFade();
|
|
24403
|
+
const list = Array.isArray(lines) ? lines.filter((line) => line && line.text) : [];
|
|
24404
|
+
const active = Math.max(0, Math.min(Math.max(0, list.length - 1), Math.round(Number(activeIndex) || 0)));
|
|
24405
|
+
const head = meta && meta.title ? '🎵 ' + String(meta.title) + '\n' : '';
|
|
24406
|
+
const body = head + list.map((line, i) => (i === active ? '▶ ' : ' ') + String(line.text)).join('\n');
|
|
24407
|
+
text = body;
|
|
24408
|
+
if (textEl) textEl.textContent = body;
|
|
24409
|
+
if (el) {
|
|
24410
|
+
if (el.dataset) el.dataset.visible = '1';
|
|
24411
|
+
el.style.opacity = '1';
|
|
24412
|
+
}
|
|
24413
|
+
visible = true;
|
|
24414
|
+
if (!expanded) followBottom();
|
|
24415
|
+
place();
|
|
24416
|
+
startFollow();
|
|
24417
|
+
}
|
|
24418
|
+
|
|
24334
24419
|
/** 逐字/逐段追加(SSE 每个 chunk 调一次)。 */
|
|
24335
24420
|
function append(chunk) {
|
|
24336
24421
|
if (!ensure()) return;
|
|
@@ -24426,6 +24511,7 @@ window.__ModuleLoader__.load({
|
|
|
24426
24511
|
listen: listenPaused ? '🎤 ' + tr('麦克风已暂停') : '🎤 ' + (continuous ? tr('常驻聆听中') : tr('在听')),
|
|
24427
24512
|
think: '💭 ' + tr('在想'),
|
|
24428
24513
|
speak: '🔊 ' + tr('在说'),
|
|
24514
|
+
sing: '🎵 ' + tr('在唱'),
|
|
24429
24515
|
muted: '🔇 ' + tr('仅文字'),
|
|
24430
24516
|
};
|
|
24431
24517
|
const label = labels[k];
|
|
@@ -24484,6 +24570,7 @@ window.__ModuleLoader__.load({
|
|
|
24484
24570
|
|
|
24485
24571
|
return {
|
|
24486
24572
|
show, append, clear, hide, setState, status, hideStatus, place, isVisible, setContinuous, setVoiceFlags,
|
|
24573
|
+
showLyrics,
|
|
24487
24574
|
setExpanded, copyText, dispose,
|
|
24488
24575
|
get following() { return rafId != null; },
|
|
24489
24576
|
get text() { return text; },
|
|
@@ -25024,11 +25111,11 @@ window.__ModuleLoader__.load({
|
|
|
25024
25111
|
*
|
|
25025
25112
|
* 状态机:idle → listening → thinking → speaking → listening(循环)
|
|
25026
25113
|
* · 挂载后自动进入 listening(受持久化的「暂停聆听」约束);
|
|
25027
|
-
* · 朗读开始时**绝不录音**(半双工,避免听到自己);播完
|
|
25114
|
+
* · 朗读开始时**绝不录音**(半双工,避免听到自己);播完 150ms 自动恢复听;
|
|
25028
25115
|
* · 「暂停说话」只静音 TTS,继续听 + 头顶出字幕;
|
|
25029
25116
|
* · 麦克风被占用/权限失败 ⇒ 退出常驻聆听并明确提示(不静默)。
|
|
25030
25117
|
*/
|
|
25031
|
-
const PET_CHAT_LISTEN_RESUME_MS =
|
|
25118
|
+
const PET_CHAT_LISTEN_RESUME_MS = 150;
|
|
25032
25119
|
/** 连续 60 秒没听到人声 ⇒ 探听降频到每 2 秒一次(但仍算"在听")。 */
|
|
25033
25120
|
const PET_CHAT_QUIET_AFTER_MS = 60000;
|
|
25034
25121
|
const PET_CHAT_QUIET_PROBE_MS = 2000;
|
|
@@ -25172,7 +25259,7 @@ window.__ModuleLoader__.load({
|
|
|
25172
25259
|
return Math.max(PET_CHAT_LISTEN_RESUME_MS, Number(delayMs) || PET_CHAT_LISTEN_RESUME_MS);
|
|
25173
25260
|
}
|
|
25174
25261
|
|
|
25175
|
-
/** 朗读结束 / 一次静默后,延迟
|
|
25262
|
+
/** 朗读结束 / 一次静默后,延迟 150ms 自动开麦(半双工:播完才听)。 */
|
|
25176
25263
|
function petChatContinuousArm(delayMs) {
|
|
25177
25264
|
if (!petChatContinuousEnabled || !petChatContinuousActive || petChatContinuousPaused) return;
|
|
25178
25265
|
petChatContinuousClearTimer();
|
|
@@ -25581,7 +25668,20 @@ window.__ModuleLoader__.load({
|
|
|
25581
25668
|
// (真机/冒烟统一症状:Cannot access 'apiPostJson' before initialization)。
|
|
25582
25669
|
apiFetch: (path, opts) => apiFetch(path, opts),
|
|
25583
25670
|
apiPostJson: (path, payload, opts) => apiPostJson(path, payload, opts),
|
|
25584
|
-
|
|
25671
|
+
// v5 §2:包一层 Audio,只为记录"首段音频真正开始播"的时刻(不改播放行为)。
|
|
25672
|
+
Audio: typeof Audio === 'function'
|
|
25673
|
+
? function PetChatAudio(url) {
|
|
25674
|
+
const audio = new Audio(url);
|
|
25675
|
+
try {
|
|
25676
|
+
const originalPlay = audio.play;
|
|
25677
|
+
audio.play = function patchedPlay(...args) {
|
|
25678
|
+
if (!petChatPlayStartAt) petChatPlayStartAt = Date.now();
|
|
25679
|
+
return originalPlay.apply(audio, args);
|
|
25680
|
+
};
|
|
25681
|
+
} catch { /* 播放器不可改写时只是少一段诊断 */ }
|
|
25682
|
+
return audio;
|
|
25683
|
+
}
|
|
25684
|
+
: null,
|
|
25585
25685
|
URL: typeof URL === 'function' ? URL : null,
|
|
25586
25686
|
getVoice: () => petChatVoice,
|
|
25587
25687
|
// 回答气泡只由 SSE 增量维护(完整回答、长文可滚);逐句朗读只切“说”态,
|
|
@@ -25593,7 +25693,7 @@ window.__ModuleLoader__.load({
|
|
|
25593
25693
|
onIdle: () => {
|
|
25594
25694
|
petBubble.hide(3000);
|
|
25595
25695
|
petChatListeningNow = false;
|
|
25596
|
-
// 播完
|
|
25696
|
+
// 播完 150ms 自动恢复听(半双工:朗读期间绝不录音)。
|
|
25597
25697
|
if (petChatContinuousActive && !petChatContinuousPaused) petChatContinuousArm(PET_CHAT_LISTEN_RESUME_MS);
|
|
25598
25698
|
petChatPublishContinuousState();
|
|
25599
25699
|
},
|
|
@@ -25615,14 +25715,123 @@ window.__ModuleLoader__.load({
|
|
|
25615
25715
|
/** 立刻停:清队列 + 停当前音频 + 通知宿主作废在途合成(barge-in 用)。 */
|
|
25616
25716
|
function petSpeakStop() { return petTts.stop(); }
|
|
25617
25717
|
|
|
25718
|
+
/* ── v5 §1:清唱播放 + 逐行歌词高亮 ─────────────────────────────────────── */
|
|
25719
|
+
|
|
25720
|
+
let petSingAudio = null;
|
|
25721
|
+
let petSingTimer = null;
|
|
25722
|
+
let petSingLines = [];
|
|
25723
|
+
let petSingIndex = -1;
|
|
25724
|
+
|
|
25725
|
+
/** 停掉正在唱的歌(barge-in / 新歌替换 / 卸载)。 */
|
|
25726
|
+
function petSingStop() {
|
|
25727
|
+
if (petSingTimer != null) { clearInterval(petSingTimer); petSingTimer = null; }
|
|
25728
|
+
if (petSingAudio) {
|
|
25729
|
+
try { petSingAudio.pause(); } catch { /* ignore */ }
|
|
25730
|
+
try { petSingAudio.src = ''; } catch { /* ignore */ }
|
|
25731
|
+
petSingAudio = null;
|
|
25732
|
+
}
|
|
25733
|
+
petSingLines = [];
|
|
25734
|
+
petSingIndex = -1;
|
|
25735
|
+
}
|
|
25736
|
+
|
|
25737
|
+
/**
|
|
25738
|
+
* 播放一首清唱:`sing = { audioUrl, lines:[{text,startMs,durMs}], title, disclaimer }`。
|
|
25739
|
+
* 歌词行按 `startMs` 高亮;播完 2 秒收起气泡,并按常驻聆听的节奏恢复听。
|
|
25740
|
+
*/
|
|
25741
|
+
function petChatSingPlay(sing) {
|
|
25742
|
+
if (!sing || !sing.audioUrl) return false;
|
|
25743
|
+
if (typeof Audio !== 'function') return false;
|
|
25744
|
+
petSingStop();
|
|
25745
|
+
petSpeakStop(); // 唱歌前先停朗读,避免两路音频叠在一起
|
|
25746
|
+
petChatConfirmHide();
|
|
25747
|
+
const lines = Array.isArray(sing.lines) ? sing.lines : [];
|
|
25748
|
+
petSingLines = lines;
|
|
25749
|
+
petSingIndex = -1;
|
|
25750
|
+
petBubble.setVoiceFlags({ speakPaused: petChatSpeakPaused, listenPaused: petChatContinuousPaused });
|
|
25751
|
+
petBubble.setState('sing');
|
|
25752
|
+
petBubble.showLyrics(lines, 0, { title: sing.title, disclaimer: sing.disclaimer });
|
|
25753
|
+
try {
|
|
25754
|
+
const audio = new Audio(apiUrl(String(sing.audioUrl)));
|
|
25755
|
+
petSingAudio = audio;
|
|
25756
|
+
const tick = () => {
|
|
25757
|
+
const nowMs = Number(audio.currentTime || 0) * 1000;
|
|
25758
|
+
let active = 0;
|
|
25759
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
25760
|
+
if (lines[i].startMs <= nowMs + 40) active = i;
|
|
25761
|
+
else break;
|
|
25762
|
+
}
|
|
25763
|
+
if (active !== petSingIndex) {
|
|
25764
|
+
petSingIndex = active;
|
|
25765
|
+
petBubble.showLyrics(lines, active);
|
|
25766
|
+
}
|
|
25767
|
+
};
|
|
25768
|
+
petSingTimer = setInterval(tick, 120);
|
|
25769
|
+
audio.addEventListener('ended', () => {
|
|
25770
|
+
petSingStop();
|
|
25771
|
+
petBubble.status('info', weT('唱完啦(清唱,无伴奏)'), { delay: 2600 });
|
|
25772
|
+
petBubble.hide(2000);
|
|
25773
|
+
petChatSingResumeListening();
|
|
25774
|
+
});
|
|
25775
|
+
audio.addEventListener('error', () => {
|
|
25776
|
+
petSingStop();
|
|
25777
|
+
petBubble.status('error', weT('这首歌的音频放不出来(文件坏了或播放器不可用)'), { delay: 5000 });
|
|
25778
|
+
petChatSingResumeListening();
|
|
25779
|
+
});
|
|
25780
|
+
const played = audio.play();
|
|
25781
|
+
if (played && typeof played.catch === 'function') {
|
|
25782
|
+
played.catch(() => {
|
|
25783
|
+
petSingStop();
|
|
25784
|
+
petBubble.status('info', weT('浏览器拦了自动播放:再点一次「唱首歌」'), { delay: 4000 });
|
|
25785
|
+
});
|
|
25786
|
+
}
|
|
25787
|
+
return true;
|
|
25788
|
+
} catch {
|
|
25789
|
+
petBubble.status('error', weT('唱歌音频没放起来'), { delay: 4000 });
|
|
25790
|
+
return false;
|
|
25791
|
+
}
|
|
25792
|
+
}
|
|
25793
|
+
|
|
25794
|
+
/** 唱完回到常驻聆听(150ms,任务 §2:轮间不重开设备,只重启录音循环)。 */
|
|
25795
|
+
function petChatSingResumeListening() {
|
|
25796
|
+
if (petChatContinuousEnabled && !petChatContinuousPaused) petChatContinuousArm(150);
|
|
25797
|
+
}
|
|
25798
|
+
|
|
25799
|
+
/* ── v5 §2:延迟 6 段采样(说完/录音完/ASR/首 token/首段音频/出声)────────── */
|
|
25800
|
+
|
|
25801
|
+
let petChatVoiceTiming = null;
|
|
25802
|
+
let petChatPlayStartAt = 0;
|
|
25803
|
+
let petChatDeepTimer = null;
|
|
25804
|
+
|
|
25805
|
+
/** 一次语音轮次结束后把 6 段耗时上报宿主(失败静默,不影响对话)。 */
|
|
25806
|
+
function petChatReportLatency(turnStartAt, firstTokenAt, firstAudioAt) {
|
|
25807
|
+
const timing = petChatVoiceTiming;
|
|
25808
|
+
petChatVoiceTiming = null;
|
|
25809
|
+
if (!timing || petChatInputMode !== 'voice' || !firstTokenAt) return;
|
|
25810
|
+
const vadTail = 550; // 与 lib/voice/record.js 的 streamSilenceMs 同口径
|
|
25811
|
+
const asr = Math.max(0, Number(timing.inferenceMs) || 0);
|
|
25812
|
+
const firstToken = Math.max(0, firstTokenAt - turnStartAt);
|
|
25813
|
+
const firstAudio = firstAudioAt ? Math.max(0, firstAudioAt - firstTokenAt) : 0;
|
|
25814
|
+
const playStart = petChatPlayStartAt ? Math.max(0, petChatPlayStartAt - (firstAudioAt || firstTokenAt)) : 0;
|
|
25815
|
+
const total = vadTail + asr + firstToken + firstAudio + playStart;
|
|
25816
|
+
try {
|
|
25817
|
+
void apiPostJson('/pet-chat/latency', {
|
|
25818
|
+
inputMode: 'voice',
|
|
25819
|
+
engine: petChatVoice && petChatVoice.name ? String(petChatVoice.name).split(':')[0] : '',
|
|
25820
|
+
segments: { recordTail: vadTail, asr, firstToken, firstAudio, playStart, total },
|
|
25821
|
+
total,
|
|
25822
|
+
}, { parse: 'always' }).catch(() => {});
|
|
25823
|
+
} catch { /* 诊断失败不影响对话 */ }
|
|
25824
|
+
}
|
|
25825
|
+
|
|
25618
25826
|
/** 语音输入(v0.1):前端不碰麦克风 —— 宿主用 ffmpeg 录,这里只发请求、收文本。 */
|
|
25619
25827
|
const petVoiceIn = petVoiceInputCreate({
|
|
25620
25828
|
// barge-in:**一开录就先停朗读**(判据 verify-voice-tts 断言这个顺序)
|
|
25621
|
-
onBeforeRecord: () => { petChatInputMode = 'voice'; petSpeakStop(); },
|
|
25829
|
+
onBeforeRecord: () => { petChatInputMode = 'voice'; petSpeakStop(); petSingStop(); },
|
|
25622
25830
|
postRecord: async () => {
|
|
25623
25831
|
// pre.62:ffmpeg 不在包里,首次点麦可能在下载。宿主回 ffmpeg-preparing+percent;
|
|
25624
25832
|
// 这里在状态条显示进度并自动重试 /record(下载在宿主后台继续),不显示“没听到声音”。
|
|
25625
25833
|
for (let attempt = 0; attempt < 180; attempt += 1) {
|
|
25834
|
+
const attemptStart = Date.now();
|
|
25626
25835
|
const res = await apiPostJson('/pet-chat/record', { language: 'zh' }, { parse: 'always' });
|
|
25627
25836
|
const doc = (res && res.data) || {};
|
|
25628
25837
|
if (doc.code === 'ffmpeg-preparing') {
|
|
@@ -25631,6 +25840,14 @@ window.__ModuleLoader__.load({
|
|
|
25631
25840
|
await new Promise((resolve) => { setTimeout(resolve, 1000); });
|
|
25632
25841
|
continue;
|
|
25633
25842
|
}
|
|
25843
|
+
if (doc.ok === true) {
|
|
25844
|
+
// 6 段诊断:宿主在同一个 /record 里做了录音 + 转写;inferenceSeconds 是 ASR 那一段。
|
|
25845
|
+
petChatVoiceTiming = {
|
|
25846
|
+
recordStartedAt: attemptStart,
|
|
25847
|
+
recordDoneAt: Date.now(),
|
|
25848
|
+
inferenceMs: Math.max(0, Number(doc.inferenceSeconds) || 0) * 1000,
|
|
25849
|
+
};
|
|
25850
|
+
}
|
|
25634
25851
|
petBubble.hideStatus(0);
|
|
25635
25852
|
return doc;
|
|
25636
25853
|
}
|
|
@@ -25642,6 +25859,10 @@ window.__ModuleLoader__.load({
|
|
|
25642
25859
|
return;
|
|
25643
25860
|
}
|
|
25644
25861
|
petChatTurnBegin();
|
|
25862
|
+
const turnStartAt = Date.now();
|
|
25863
|
+
let firstTokenAt = 0;
|
|
25864
|
+
let firstAudioAt = 0;
|
|
25865
|
+
petChatPlayStartAt = 0;
|
|
25645
25866
|
petChatSpeechRate = 0;
|
|
25646
25867
|
petChatMood = 'neutral';
|
|
25647
25868
|
const workNow = Date.now();
|
|
@@ -25690,6 +25911,8 @@ window.__ModuleLoader__.load({
|
|
|
25690
25911
|
}
|
|
25691
25912
|
let rawReply = '';
|
|
25692
25913
|
let replyStarted = false;
|
|
25914
|
+
/** v5:这一轮是不是以"唱歌"结尾(有 sing 事件时别按"无朗读"提前收气泡/开麦)。 */
|
|
25915
|
+
let singStarted = false;
|
|
25693
25916
|
let replyDone = false;
|
|
25694
25917
|
/**
|
|
25695
25918
|
* 朗读的流式切句(P1):
|
|
@@ -25707,7 +25930,10 @@ window.__ModuleLoader__.load({
|
|
|
25707
25930
|
return;
|
|
25708
25931
|
}
|
|
25709
25932
|
// v2:本轮语速由宿主 meta 给(夜间/疲惫 -1 = -10%);再叠加当前人设的 voice.rate。
|
|
25710
|
-
if (petSpeak(line, { rate: petChatSpeechRate + (Number(petChatVoice.rate) || 0) }))
|
|
25933
|
+
if (petSpeak(line, { rate: petChatSpeechRate + (Number(petChatVoice.rate) || 0) })) {
|
|
25934
|
+
queuedSpeech += 1;
|
|
25935
|
+
if (!firstAudioAt) firstAudioAt = Date.now(); // 首段音频交给播放器的时刻
|
|
25936
|
+
}
|
|
25711
25937
|
};
|
|
25712
25938
|
const reader = stream.body.getReader();
|
|
25713
25939
|
const decoder = new TextDecoder();
|
|
@@ -25734,6 +25960,17 @@ window.__ModuleLoader__.load({
|
|
|
25734
25960
|
if (eventName === 'meta') {
|
|
25735
25961
|
petChatMood = String(payload.mood || 'neutral');
|
|
25736
25962
|
petChatSpeechRate = Number.isFinite(Number(payload.rate)) ? Number(payload.rate) : 0;
|
|
25963
|
+
// v5 §5:深度档 >3s 显示「深度思考中…」(quick/standard 秒回,不闪这一下)。
|
|
25964
|
+
if (payload.tier === 'deep') {
|
|
25965
|
+
if (petChatDeepTimer != null) clearTimeout(petChatDeepTimer);
|
|
25966
|
+
petChatDeepTimer = setTimeout(() => {
|
|
25967
|
+
petChatDeepTimer = null;
|
|
25968
|
+
petBubble.status('info', weT('深度思考中…'), { delay: 0 });
|
|
25969
|
+
}, 3000);
|
|
25970
|
+
} else if (petChatDeepTimer != null) {
|
|
25971
|
+
clearTimeout(petChatDeepTimer);
|
|
25972
|
+
petChatDeepTimer = null;
|
|
25973
|
+
}
|
|
25737
25974
|
continue;
|
|
25738
25975
|
}
|
|
25739
25976
|
if (eventName === 'confirm') {
|
|
@@ -25746,6 +25983,12 @@ window.__ModuleLoader__.load({
|
|
|
25746
25983
|
void petChatHandleAction(payload);
|
|
25747
25984
|
continue;
|
|
25748
25985
|
}
|
|
25986
|
+
if (eventName === 'sing') {
|
|
25987
|
+
// v5 §1:唱歌事件带 audioUrl + 逐行时间戳;客户端单独放音频并逐行高亮。
|
|
25988
|
+
singStarted = true;
|
|
25989
|
+
petChatSingPlay(payload);
|
|
25990
|
+
continue;
|
|
25991
|
+
}
|
|
25749
25992
|
if (eventName === 'done') {
|
|
25750
25993
|
if (Number.isFinite(Number(payload.rate))) petChatSpeechRate = Number(payload.rate);
|
|
25751
25994
|
continue;
|
|
@@ -25753,6 +25996,7 @@ window.__ModuleLoader__.load({
|
|
|
25753
25996
|
// 防兜底:模型偶尔仍会输出 {"reply":"…","emotion":"…"} 信封,
|
|
25754
25997
|
// 这里只把 reply 的正文喂给气泡(不显示大括号/字段名/emotion)。
|
|
25755
25998
|
if (typeof payload.t === 'string') {
|
|
25999
|
+
if (!firstTokenAt) firstTokenAt = Date.now(); // 首 token 到达(诊断第 4 段)
|
|
25756
26000
|
rawReply += payload.t;
|
|
25757
26001
|
let piece = payload.t;
|
|
25758
26002
|
if (!replyStarted) {
|
|
@@ -25784,15 +26028,17 @@ window.__ModuleLoader__.load({
|
|
|
25784
26028
|
enqueueSpeech(speakBuffer);
|
|
25785
26029
|
if (typeof onState === 'function') onState({ state: 'idle' });
|
|
25786
26030
|
// 本轮成功:常驻聆听继续(任务 §4:装好就在听,不靠"点了才听");
|
|
25787
|
-
// 有朗读时等 onIdle 播完再开麦(半双工),没朗读(暂停说话/静音)直接
|
|
26031
|
+
// 有朗读时等 onIdle 播完再开麦(半双工),没朗读(暂停说话/静音)直接 150ms 后排下一轮。
|
|
25788
26032
|
if (!petChatContinuousActive && !petChatContinuousPaused) petChatContinuousStart();
|
|
25789
26033
|
petChatLastHeardAt = Date.now();
|
|
25790
26034
|
petChatContinuousRounds += 1;
|
|
25791
26035
|
petChatContinuousSilent = 0;
|
|
25792
26036
|
petChatPublishContinuousState();
|
|
25793
|
-
if (!queuedSpeech) petChatContinuousArm();
|
|
26037
|
+
if (!queuedSpeech && !singStarted) petChatContinuousArm();
|
|
25794
26038
|
// 没有任何一句进入朗读(暂停说话 / 合成不可用)⇒ 字幕照常显示,3 秒后淡出。
|
|
25795
|
-
|
|
26039
|
+
// 唱歌时气泡归歌词用:不提前收,播完由 petChatSingPlay 收。
|
|
26040
|
+
if (!queuedSpeech && !singStarted) petBubble.hide(3000);
|
|
26041
|
+
petChatReportLatency(turnStartAt, firstTokenAt, firstAudioAt);
|
|
25796
26042
|
petChatTurnEnd();
|
|
25797
26043
|
},
|
|
25798
26044
|
// P4:用户自己的话**不进**气泡(那是回声);只显示 assistant 的 SSE delta
|
|
@@ -25853,6 +26099,7 @@ window.__ModuleLoader__.load({
|
|
|
25853
26099
|
box.remove();
|
|
25854
26100
|
// 新的一轮 = 先掐掉上一轮还在念的(与录音入口同一条 barge-in 纪律)
|
|
25855
26101
|
petSpeakStop();
|
|
26102
|
+
petSingStop();
|
|
25856
26103
|
petChatVoiceAbort = false;
|
|
25857
26104
|
petChatInputMode = 'text';
|
|
25858
26105
|
// 打字说的文本**不上气泡**(P4 同理:气泡只显示助手的回答)。
|
|
@@ -25885,8 +26132,9 @@ window.__ModuleLoader__.load({
|
|
|
25885
26132
|
|
|
25886
26133
|
/** 点桌宠:常驻聆听默认在听 —— 点它只做三件事:打断朗读 / 恢复聆听 / 收起气泡。 */
|
|
25887
26134
|
function petChatWake() {
|
|
25888
|
-
// **任何一次唤醒都是 barge-in
|
|
26135
|
+
// **任何一次唤醒都是 barge-in**:先把正在念的/正在唱的停掉,再决定是收起还是开麦。
|
|
25889
26136
|
petSpeakStop();
|
|
26137
|
+
petSingStop();
|
|
25890
26138
|
void petChatRefreshVoice();
|
|
25891
26139
|
const seq = ++petChatWakeSeq;
|
|
25892
26140
|
// 暂停聆听中点桌宠 = 恢复常驻聆听(不用再去右键菜单)。
|
|
@@ -26086,7 +26334,7 @@ window.__ModuleLoader__.load({
|
|
|
26086
26334
|
}
|
|
26087
26335
|
return;
|
|
26088
26336
|
}
|
|
26089
|
-
// 回到页面:如果没被「暂停聆听」,
|
|
26337
|
+
// 回到页面:如果没被「暂停聆听」,150ms 内恢复听。
|
|
26090
26338
|
if (!petChatContinuousPaused && petChatContinuousEnabled) petChatResidentStart();
|
|
26091
26339
|
};
|
|
26092
26340
|
document.addEventListener('visibilitychange', onVisibility);
|
|
@@ -26107,7 +26355,8 @@ window.__ModuleLoader__.load({
|
|
|
26107
26355
|
try {
|
|
26108
26356
|
window.__dshFoliaPet = {
|
|
26109
26357
|
speak: (text, speech) => petSpeak(text, speech || {}),
|
|
26110
|
-
stop: () => petSpeakStop(),
|
|
26358
|
+
stop: () => { petSingStop(); return petSpeakStop(); },
|
|
26359
|
+
sing: (sing) => petChatSingPlay(sing),
|
|
26111
26360
|
chat: (text) => { petChatInputMode = 'text'; return petVoiceIn.postChat(String(text || '')); },
|
|
26112
26361
|
isSpeaking: () => petTts.isSpeaking(),
|
|
26113
26362
|
// 任务 §4:两个开关(菜单之外的对外通道;判据也用它)
|
|
@@ -26130,11 +26379,15 @@ window.__ModuleLoader__.load({
|
|
|
26130
26379
|
if (petChatWallpaperTimer != null) clearInterval(petChatWallpaperTimer);
|
|
26131
26380
|
if (petChatWorkTimer != null) clearInterval(petChatWorkTimer);
|
|
26132
26381
|
if (petChatGreetingTimer != null) clearTimeout(petChatGreetingTimer);
|
|
26382
|
+
// v5 §6:深度思考的 3s 提示定时器也要随卸载清掉(否则会在 dispose 后改气泡)。
|
|
26383
|
+
if (petChatDeepTimer != null) { clearTimeout(petChatDeepTimer); petChatDeepTimer = null; }
|
|
26384
|
+
if (petSingTimer != null) { clearInterval(petSingTimer); petSingTimer = null; }
|
|
26133
26385
|
petChatWallpaperTimer = null;
|
|
26134
26386
|
petChatWorkTimer = null;
|
|
26135
26387
|
petChatGreetingTimer = null;
|
|
26136
26388
|
petChatEventsStop();
|
|
26137
26389
|
petSpeakStop();
|
|
26390
|
+
petSingStop();
|
|
26138
26391
|
petChatConfirmHide();
|
|
26139
26392
|
try { if (window.__dshFoliaPet) delete window.__dshFoliaPet; } catch { /* ignore */ }
|
|
26140
26393
|
petBubble.dispose();
|
package/lib/index.js
CHANGED
|
@@ -313,6 +313,15 @@ export function apply(ctx) {
|
|
|
313
313
|
// 会抛 "cannot get property … without inject",让整个插件加载失败(POSTMORTEM-LOAD-CRASH)。
|
|
314
314
|
// 静态扫描判据:test/verify-ctx-access.mjs;加载冒烟:test/verify-entry-load.mjs。
|
|
315
315
|
speechToText: typeof ctx.get === 'function' ? ctx.get('speechToText') : undefined,
|
|
316
|
+
// v5 §4:把宿主已有的 skills/tools 服务**按需**交给桌宠路由(只读用;拿不到就退到
|
|
317
|
+
// 文件面技能目录,插件照常加载)。用 try 包住:旧宿主的 ctx.get 可能没有这两个服务。
|
|
318
|
+
services: (() => {
|
|
319
|
+
if (typeof ctx.get !== 'function') return null;
|
|
320
|
+
const safe = (name) => { try { return ctx.get(name); } catch { return null; } };
|
|
321
|
+
const skills = safe('skills');
|
|
322
|
+
const tools = safe('tools');
|
|
323
|
+
return skills || tools ? { skills, tools } : null;
|
|
324
|
+
})(),
|
|
316
325
|
// pre.62:语音链的 ffmpeg 供给(首次使用懒下载;/record 先看进度,不等 70MB)。
|
|
317
326
|
ffmpegEnsure: hostKernel.transcodeKit.ensureFfmpeg,
|
|
318
327
|
ffmpegStatus: hostKernel.transcodeKit.ffmpegStatus,
|
package/lib/persona-store.js
CHANGED
|
@@ -87,6 +87,16 @@ export const PERMISSION_GROUPS = Object.freeze([
|
|
|
87
87
|
desc: '开关朗读、改音色与语速。',
|
|
88
88
|
tools: ['tts_toggle'],
|
|
89
89
|
},
|
|
90
|
+
{
|
|
91
|
+
id: 'perform', label: '唱歌与表演', risk: 'low', riskLabel: '低风险', default: 'allow',
|
|
92
|
+
desc: '按谱清唱(合成音、无伴奏)、讲笑话/故事。只出声,不改系统。',
|
|
93
|
+
tools: ['perform_sing', 'perform_teach'],
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
id: 'tasks', label: '多步任务', risk: 'medium', riskLabel: '中风险', default: 'ask',
|
|
97
|
+
desc: '把一件事拆成 2–6 步并逐步执行;每一步仍按它自己的工具组权限判定,高危仍二次确认。',
|
|
98
|
+
tools: ['task_plan', 'task_run'],
|
|
99
|
+
},
|
|
90
100
|
{
|
|
91
101
|
id: 'reminder', label: '提醒与日程', risk: 'low', riskLabel: '低风险', default: 'allow',
|
|
92
102
|
desc: '创建/查看/清除本机提醒。',
|
|
@@ -117,6 +127,11 @@ export const PERMISSION_GROUPS = Object.freeze([
|
|
|
117
127
|
desc: '读/写系统剪贴板;内容可能包含隐私,默认每次询问。',
|
|
118
128
|
tools: ['clipboard_get', 'clipboard_set'],
|
|
119
129
|
},
|
|
130
|
+
{
|
|
131
|
+
id: 'plugins', label: '已安装插件与技能', risk: 'medium', riskLabel: '中风险', default: 'ask',
|
|
132
|
+
desc: '列出并调用已安装插件/技能;每个能力单独开关,默认只列不调用,调用会写审计。',
|
|
133
|
+
tools: ['capability_list', 'capability_call'],
|
|
134
|
+
},
|
|
120
135
|
{
|
|
121
136
|
id: 'system', label: '系统操作', risk: 'high', riskLabel: '高风险', default: 'ask', advancedOnly: true,
|
|
122
137
|
desc: '卸载皮肤、清空记忆等不可撤销操作;即使允许也要二次确认。',
|
package/lib/persona-tool-log.js
CHANGED
|
@@ -43,6 +43,9 @@ export function appendToolLog(personaId, entry = {}) {
|
|
|
43
43
|
verified: entry.verified === true,
|
|
44
44
|
source: clip(entry.source, 40) || 'chat',
|
|
45
45
|
error: clip(entry.error, 300),
|
|
46
|
+
// v5 §3:多步任务的可追溯字段(普通调用为空/0;旧日志读出来仍是 undefined,判据按"有没有"看)。
|
|
47
|
+
planId: entry.planId ? clip(entry.planId, 60) : '',
|
|
48
|
+
step: Number.isFinite(Number(entry.step)) ? Math.max(0, Math.round(Number(entry.step))) : 0,
|
|
46
49
|
};
|
|
47
50
|
try {
|
|
48
51
|
const file = toolLogPath(personaId);
|