dsh-folia 1.1.0 → 1.2.0
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/assets/system/sound/ding.wav +0 -0
- package/assets/system/sound/ok.wav +0 -0
- package/assets/system/sound/tap.wav +0 -0
- package/assets/system/sound/warn.wav +0 -0
- package/lib/client.js +667 -12
- package/lib/desktop-context.js +254 -0
- package/lib/memory-db.js +835 -0
- package/lib/persona-memory.js +280 -33
- package/lib/pet-chat-brain.js +54 -4
- package/lib/pet-chat-mind.js +259 -0
- package/lib/routes/personas.js +112 -1
- package/lib/routes/pet-chat.js +452 -14
- package/lib/settings-schema.js +45 -0
- package/lib/tts/tts.js +104 -1
- package/lib/tts/voice-pack.js +196 -0
- package/package.json +5 -1
package/lib/client.js
CHANGED
|
@@ -781,6 +781,63 @@ window.__ModuleLoader__.load({
|
|
|
781
781
|
"展开": "Expand",
|
|
782
782
|
"复制": "Copy",
|
|
783
783
|
"复制失败:这个环境没有剪贴板权限": "Copy failed: no clipboard permission in this environment",
|
|
784
|
+
// v1.2:故事模式按钮 / 观察模式 / 宿主错误提示
|
|
785
|
+
"继续": "Continue",
|
|
786
|
+
"重讲": "Tell again",
|
|
787
|
+
"缩短": "Shorten",
|
|
788
|
+
"观察中": "Observing",
|
|
789
|
+
"这次没答上来": "No answer this time",
|
|
790
|
+
"讲故事": "Storytelling",
|
|
791
|
+
"树洞": "Tree hole",
|
|
792
|
+
"只观察": "Observe only",
|
|
793
|
+
// v1.2:对话与隐私 / 记忆 / 用户音色包
|
|
794
|
+
"对话与隐私": "Conversation & privacy",
|
|
795
|
+
"聊天=日常短答;讲故事=不按句数截断;树洞=先接情绪;只观察=不回答、只记不说。": "Chat = short replies; Storytelling = no sentence cut-off; Tree hole = feelings first; Observe only = no reply, just notes.",
|
|
796
|
+
"3 句": "3 sentences",
|
|
797
|
+
"8 句": "8 sentences",
|
|
798
|
+
"主动搭话(默认关)": "Proactive talk (off by default)",
|
|
799
|
+
"搭话间隔": "Proactive interval",
|
|
800
|
+
"15 分钟": "15 minutes",
|
|
801
|
+
"30 分钟": "30 minutes",
|
|
802
|
+
"60 分钟": "60 minutes",
|
|
803
|
+
"关着的时候它只在你主动说话时回应;打开后每小时最多主动 2 次。": "While off, it only responds when you speak first. When on, it initiates at most twice per hour.",
|
|
804
|
+
"勿扰时段": "Do-not-disturb window",
|
|
805
|
+
"屏幕感知(默认关)": "Screen awareness (off by default)",
|
|
806
|
+
"只读前台应用名与窗口标题(可选再加屏幕 OCR);读不到别的 App 内部数据,绝不上传截图或 OCR 原文。": "Reads only the foreground app name and window title (optionally plus screen OCR). It cannot read other apps' internal data, and never uploads screenshots or OCR text.",
|
|
807
|
+
"前台应用": "Foreground app",
|
|
808
|
+
"前台 + OCR": "Foreground + OCR",
|
|
809
|
+
"开启后它会知道你当前在用哪个应用、窗口标题是什么(前台+OCR 还会定时读取屏幕文字)。所有记录只存在本机记忆里,可随时查看、删除。": "Once enabled it knows which app and window title you are using (plus periodic screen text with OCR). All records stay in local memory and can be viewed or deleted at any time.",
|
|
810
|
+
"确认开启": "Confirm and enable",
|
|
811
|
+
"当前:关(不读前台窗口,也不截屏)": "Now: off (no foreground reads, no screenshots)",
|
|
812
|
+
"当前:已开启(可随时关)": "Now: enabled (can be turned off anytime)",
|
|
813
|
+
"查看观察记录": "View observations",
|
|
814
|
+
"清空观察记录": "Clear observations",
|
|
815
|
+
"观察记录已清空": "Observations cleared",
|
|
816
|
+
"还没有观察记录": "No observations yet",
|
|
817
|
+
"查看记忆": "View memory",
|
|
818
|
+
"导出记忆": "Export memory",
|
|
819
|
+
"最近 {n} 条事件": "Last {n} events",
|
|
820
|
+
"按日期回滚": "Roll back by date",
|
|
821
|
+
"回滚": "Roll back",
|
|
822
|
+
"先填日期(YYYY-MM-DD)": "Fill in a date first (YYYY-MM-DD)",
|
|
823
|
+
"已回滚 {n} 条": "Rolled back {n} entries",
|
|
824
|
+
"导出失败": "Export failed",
|
|
825
|
+
"树洞求助热线": "Tree-hole helpline",
|
|
826
|
+
"用户音色包(角色语音只走导入)": "User voice packs (character voices are import-only)",
|
|
827
|
+
"本插件不携带角色/声优素材。导入前请确认你有权使用这段参考音频,并填写许可证与作者/来源。": "This plugin ships no character or voice-actor assets. Make sure you have the rights to the reference audio, and fill in the license and author/source.",
|
|
828
|
+
"未填许可证": "No license",
|
|
829
|
+
"音色包名字": "Voice pack name",
|
|
830
|
+
"许可证(如:本人录制,仅自用)": "License (e.g. self-recorded, personal use only)",
|
|
831
|
+
"作者 / 来源": "Author / source",
|
|
832
|
+
"参考音频对应的文字(可选)": "Text spoken in the reference audio (optional)",
|
|
833
|
+
"参考音频只存本机用户目录,不进 npm 包、不上传。": "The reference audio is stored only in your local user directory; it is never packaged or uploaded.",
|
|
834
|
+
"内置系统音效(4 个,MIT,本项目合成;不含角色语音)": "Built-in system sounds (4, MIT, synthesized in this project; no character voices)",
|
|
835
|
+
"在线音色暂不可用(429 限流):先用本地音色,稍后再试。": "Online voices are temporarily unavailable (HTTP 429). Local voices still work — try again later.",
|
|
836
|
+
"先填名字、许可证、作者/来源——没有授权的音色不要导入": "Fill in name, license and author/source first — do not import voices you have no rights to.",
|
|
837
|
+
"读不到这个音频文件": "Could not read this audio file",
|
|
838
|
+
"已导入:{n}": "Imported: {n}",
|
|
839
|
+
"导入失败": "Import failed",
|
|
840
|
+
"填 Key、起名字、选音色;对话模式、主动搭话、屏幕感知都在「对话与隐私」里,默认全关。": "Enter the key, name and voice; conversation mode, proactive talk and screen awareness live under Conversation & privacy, all off by default.",
|
|
784
841
|
// pre.64:大脑 v2(壁纸动作的客户端执行反馈)
|
|
785
842
|
"正在换壁纸…": "Switching wallpaper…",
|
|
786
843
|
"没找到叫「{name}」的壁纸": "No wallpaper named '{name}' was found",
|
|
@@ -8614,6 +8671,16 @@ window.__ModuleLoader__.load({
|
|
|
8614
8671
|
voice: { name: '', muted: false },
|
|
8615
8672
|
// 唤醒:点一下默认开;叫名字默认关(S6 才实现,先在设置里留位)
|
|
8616
8673
|
wake: { click: true, name: false, keyword: '' },
|
|
8674
|
+
// v1.2:会话模式(聊天 / 讲故事 / 树洞 / 只观察)。默认聊天。
|
|
8675
|
+
conversationMode: 'chat',
|
|
8676
|
+
// v1.2:语音回答长度(0 = 不限;默认 8 句 —— 旧版写死 3 句,讲故事被截断的根因)。
|
|
8677
|
+
voiceLength: 8,
|
|
8678
|
+
// v1.2:主动思维(默认关;15/30/60 分钟才开)。勿扰时段跨零点也支持。
|
|
8679
|
+
proactive: { enabled: false, intervalMin: 15, quietFrom: '23:00', quietTo: '08:00' },
|
|
8680
|
+
// v1.2:屏幕感知(默认关;app = 只读前台应用/标题,ocr = 再加屏幕 OCR,需二次确认)。
|
|
8681
|
+
screen: { mode: 'off', confirmed: false },
|
|
8682
|
+
// v1.2:树洞安全提示里的求助热线(配置化;不写死成某一家的号码)。
|
|
8683
|
+
treehole: { hotline: '12356' },
|
|
8617
8684
|
// 对话记忆默认开启且**不暴露开关**(追加决定 1):能力常开,用户只能在右键里查看/清空
|
|
8618
8685
|
},
|
|
8619
8686
|
};
|
|
@@ -9330,6 +9397,19 @@ window.__ModuleLoader__.load({
|
|
|
9330
9397
|
const PET_CHAT_API_KEY_MAX = 400;
|
|
9331
9398
|
const PET_CHAT_MODEL_MAX = 120;
|
|
9332
9399
|
const PET_CHAT_PERSONA_MAX = 200;
|
|
9400
|
+
/** v1.2:会话模式 / 语音长度 / 主动搭话 / 屏幕感知(全部**默认关闭**高风险项)。 */
|
|
9401
|
+
const PET_CHAT_CONVERSATION_MODES = Object.freeze(['chat', 'story', 'treehole', 'observe']);
|
|
9402
|
+
/** 语音回答长度:0 = 不限;默认 8 句(v1.2 从 3 句改上来的)。 */
|
|
9403
|
+
const PET_CHAT_VOICE_LENGTHS = Object.freeze([0, 3, 8]);
|
|
9404
|
+
/** 主动搭话间隔(分钟):0 = 关。默认关。 */
|
|
9405
|
+
const PET_CHAT_PROACTIVE_INTERVALS = Object.freeze([0, 15, 30, 60]);
|
|
9406
|
+
/** 屏幕感知:off / app(前台应用)/ ocr(前台 + 屏幕 OCR)。默认 off。 */
|
|
9407
|
+
const PET_CHAT_SCREEN_MODES = Object.freeze(['off', 'app', 'ocr']);
|
|
9408
|
+
const PET_CHAT_HHMM = /^([01]\d|2[0-3]):[0-5]\d$/;
|
|
9409
|
+
const petChatClock = (v, fallback) => {
|
|
9410
|
+
const text = typeof v === 'string' ? v.trim().slice(0, 5) : '';
|
|
9411
|
+
return PET_CHAT_HHMM.test(text) ? text : fallback;
|
|
9412
|
+
};
|
|
9333
9413
|
|
|
9334
9414
|
const petChatStr = (v, max) => (typeof v === 'string' ? v.slice(0, max) : '');
|
|
9335
9415
|
const petChatFloat = (v, lo, hi, fallback) => {
|
|
@@ -9372,6 +9452,9 @@ window.__ModuleLoader__.load({
|
|
|
9372
9452
|
const src = raw && typeof raw === 'object' && !Array.isArray(raw) ? raw : {};
|
|
9373
9453
|
const persona = src.persona && typeof src.persona === 'object' && !Array.isArray(src.persona) ? src.persona : {};
|
|
9374
9454
|
const wake = src.wake && typeof src.wake === 'object' && !Array.isArray(src.wake) ? src.wake : {};
|
|
9455
|
+
const proactive = src.proactive && typeof src.proactive === 'object' && !Array.isArray(src.proactive) ? src.proactive : {};
|
|
9456
|
+
const screen = src.screen && typeof src.screen === 'object' && !Array.isArray(src.screen) ? src.screen : {};
|
|
9457
|
+
const treehole = src.treehole && typeof src.treehole === 'object' && !Array.isArray(src.treehole) ? src.treehole : {};
|
|
9375
9458
|
const baseUrl = petChatStr(src.baseUrl, PET_CHAT_BASE_URL_MAX).trim();
|
|
9376
9459
|
return {
|
|
9377
9460
|
enabled: src.enabled === true,
|
|
@@ -9389,6 +9472,25 @@ window.__ModuleLoader__.load({
|
|
|
9389
9472
|
name: wake.name === true,
|
|
9390
9473
|
keyword: petChatStr(wake.keyword, 40).trim(),
|
|
9391
9474
|
},
|
|
9475
|
+
// v1.2:认不出的模式 / 长度 / 间隔一律回落默认(不猜近似值)
|
|
9476
|
+
conversationMode: PET_CHAT_CONVERSATION_MODES.includes(src.conversationMode) ? src.conversationMode : def.conversationMode,
|
|
9477
|
+
voiceLength: PET_CHAT_VOICE_LENGTHS.includes(Number(src.voiceLength)) ? Number(src.voiceLength) : def.voiceLength,
|
|
9478
|
+
proactive: {
|
|
9479
|
+
enabled: proactive.enabled === true,
|
|
9480
|
+
intervalMin: PET_CHAT_PROACTIVE_INTERVALS.includes(Number(proactive.intervalMin))
|
|
9481
|
+
? Number(proactive.intervalMin) : def.proactive.intervalMin,
|
|
9482
|
+
quietFrom: petChatClock(proactive.quietFrom, def.proactive.quietFrom),
|
|
9483
|
+
quietTo: petChatClock(proactive.quietTo, def.proactive.quietTo),
|
|
9484
|
+
},
|
|
9485
|
+
screen: {
|
|
9486
|
+
mode: PET_CHAT_SCREEN_MODES.includes(screen.mode) ? screen.mode : def.screen.mode,
|
|
9487
|
+
// 二次确认是**一次性**授权:只有旧值为 confirm 过且 mode 仍非 off 才算数;
|
|
9488
|
+
// 单独把 confirmed 置 true 但没有 mode 也不生效(读的时候按 mode 判定,见路由)。
|
|
9489
|
+
confirmed: screen.confirmed === true,
|
|
9490
|
+
},
|
|
9491
|
+
treehole: {
|
|
9492
|
+
hotline: petChatStr(treehole.hotline, 40).trim() || def.treehole.hotline,
|
|
9493
|
+
},
|
|
9392
9494
|
// 记忆常开:设置里没有这个开关(追加决定 1),旧档里的 false 也不再尊重
|
|
9393
9495
|
memoryEnabled: true,
|
|
9394
9496
|
};
|
|
@@ -20838,6 +20940,8 @@ window.__ModuleLoader__.load({
|
|
|
20838
20940
|
const currentItem = builtin.items.concat(edge.items, providers.items).find((item) => item.id === currentId);
|
|
20839
20941
|
const edgeByLang = {};
|
|
20840
20942
|
for (const item of edge.items) {
|
|
20943
|
+
// 用户口径:声音里不可用的不要出现(429/不可用从主列表隐藏,只留一条提示)
|
|
20944
|
+
if (item.status === 'rate-limited' || item.status === 'unavailable') continue;
|
|
20841
20945
|
const key = item.langGroup || '其他';
|
|
20842
20946
|
if (!edgeByLang[key]) edgeByLang[key] = [];
|
|
20843
20947
|
edgeByLang[key].push(item);
|
|
@@ -20896,7 +21000,7 @@ window.__ModuleLoader__.load({
|
|
|
20896
21000
|
'免费在线 · Edge', personaTag('可能限流', 'warn')),
|
|
20897
21001
|
voiceCatalog && voiceCatalog.edgeRateLimited
|
|
20898
21002
|
? React.createElement('div', { className: 'we-picker__hint', style: { color: '#fcd34d' } },
|
|
20899
|
-
`在线音色被限流(429
|
|
21003
|
+
`在线音色被限流(429):不可用项已隐藏;可先用内置音色,稍后自动恢复。`)
|
|
20900
21004
|
: null,
|
|
20901
21005
|
Object.keys(edgeByLang).length
|
|
20902
21006
|
? Object.keys(edgeByLang).map((lang) => React.createElement('div', { key: 'pick-edge-' + lang },
|
|
@@ -21112,6 +21216,12 @@ window.__ModuleLoader__.load({
|
|
|
21112
21216
|
ownerName: '',
|
|
21113
21217
|
// v0.2:朗读 = voice.muted 取反;音色 = voice.name;SAPI = voice.sapiEnabled(默认 false)。
|
|
21114
21218
|
voice: { name: '', muted: false, rate: 0, sapiEnabled: false, enabledEngine: 'edge', continuous: true, listenPaused: false },
|
|
21219
|
+
// v1.2:会话模式 / 语音长度 / 主动思维 / 屏幕感知 / 树洞热线(默认全关高风险项)
|
|
21220
|
+
conversationMode: 'chat',
|
|
21221
|
+
voiceLength: 8,
|
|
21222
|
+
proactive: { enabled: false, intervalMin: 15, quietFrom: '23:00', quietTo: '08:00' },
|
|
21223
|
+
screen: { mode: 'off', confirmed: false },
|
|
21224
|
+
treehole: { hotline: '12356' },
|
|
21115
21225
|
};
|
|
21116
21226
|
|
|
21117
21227
|
/** apiJson 的返回是 { ok, status, data },而 /pet-chat/* 的 data 里还套一层 { ok, data }。 */
|
|
@@ -21288,6 +21398,8 @@ window.__ModuleLoader__.load({
|
|
|
21288
21398
|
const [tab, setTab] = React.useState('assistant');
|
|
21289
21399
|
const [workPlugins, setWorkPlugins] = React.useState(null);
|
|
21290
21400
|
const [voices, setVoices] = React.useState(null);
|
|
21401
|
+
/** v1.2:Edge 429 等“在线音色暂时不可用”的提示(列表里不再堆灰项)。 */
|
|
21402
|
+
const [voiceNotice, setVoiceNotice] = React.useState('');
|
|
21291
21403
|
const [voiceMeta, setVoiceMeta] = React.useState({});
|
|
21292
21404
|
const [voiceCfg, setVoiceCfg] = React.useState({ sapiEnabled: false, enabledEngine: 'edge', continuous: true, listenPaused: false });
|
|
21293
21405
|
const [setupBusy, setSetupBusy] = React.useState(false);
|
|
@@ -21299,6 +21411,16 @@ window.__ModuleLoader__.load({
|
|
|
21299
21411
|
const [enableBusy, setEnableBusy] = React.useState('');
|
|
21300
21412
|
const [enableNote, setEnableNote] = React.useState(null);
|
|
21301
21413
|
const [detailOpen, setDetailOpen] = React.useState({});
|
|
21414
|
+
// v1.2:屏幕感知二次确认 / 观察记录 / 记忆回滚 / 用户音色包
|
|
21415
|
+
const [screenArmed, setScreenArmed] = React.useState('');
|
|
21416
|
+
const [observeList, setObserveList] = React.useState(null);
|
|
21417
|
+
const [memoryInfo, setMemoryInfo] = React.useState(null);
|
|
21418
|
+
const [memoryNote, setMemoryNote] = React.useState(null);
|
|
21419
|
+
const [rollbackDate, setRollbackDate] = React.useState('');
|
|
21420
|
+
const [userPacks, setUserPacks] = React.useState([]);
|
|
21421
|
+
const [systemSounds, setSystemSounds] = React.useState([]);
|
|
21422
|
+
const [packForm, setPackForm] = React.useState({ name: '', license: '', author: '', refText: '', engine: 'gpt-sovits' });
|
|
21423
|
+
const [packNote, setPackNote] = React.useState(null);
|
|
21302
21424
|
const [providers, setProviders] = React.useState(null);
|
|
21303
21425
|
const [providerBusy, setProviderBusy] = React.useState(false);
|
|
21304
21426
|
const [providerNote, setProviderNote] = React.useState(null);
|
|
@@ -21365,6 +21487,9 @@ window.__ModuleLoader__.load({
|
|
|
21365
21487
|
const doc = unwrapPetChat(resp);
|
|
21366
21488
|
const items = (doc && Array.isArray(doc.voices) ? doc.voices : []).filter((v) => v && v.usable === true);
|
|
21367
21489
|
setVoices(items);
|
|
21490
|
+
setVoiceNotice(doc && doc.rateLimited === true
|
|
21491
|
+
? weT('在线音色暂不可用(429 限流):先用本地音色,稍后再试。')
|
|
21492
|
+
: '');
|
|
21368
21493
|
setVoiceMeta((doc && doc.meta) || {});
|
|
21369
21494
|
const engine = ['edge', 'piper', 'sapi'].includes(String(doc && doc.enabledEngine || '')) ? doc.enabledEngine : 'edge';
|
|
21370
21495
|
setEnabledEngine(engine);
|
|
@@ -21385,8 +21510,106 @@ window.__ModuleLoader__.load({
|
|
|
21385
21510
|
}
|
|
21386
21511
|
}, []);
|
|
21387
21512
|
|
|
21388
|
-
|
|
21389
|
-
|
|
21513
|
+
/* ── v1.2:观察记录 / 记忆 / 用户音色包(设置页直接查看与清理)─────────── */
|
|
21514
|
+
|
|
21515
|
+
const loadObserveRecords = React.useCallback(async () => {
|
|
21516
|
+
const resp = await apiJson('/pet-chat/observe/records?limit=20', { parse: 'always' }).catch(() => null);
|
|
21517
|
+
const doc = unwrapPetChat(resp);
|
|
21518
|
+
setObserveList(Array.isArray(doc.items) ? doc.items : []);
|
|
21519
|
+
}, []);
|
|
21520
|
+
|
|
21521
|
+
const clearObserveRecords = async () => {
|
|
21522
|
+
await apiFetch('/pet-chat/observe/records', { method: 'DELETE' }).catch(() => null);
|
|
21523
|
+
setObserveList([]);
|
|
21524
|
+
setMemoryNote({ ok: true, text: weT('观察记录已清空') });
|
|
21525
|
+
};
|
|
21526
|
+
|
|
21527
|
+
const loadMemoryInfo = React.useCallback(async () => {
|
|
21528
|
+
const resp = await apiJson('/pet-chat/memory', { parse: 'always' }).catch(() => null);
|
|
21529
|
+
const doc = unwrapPetChat(resp);
|
|
21530
|
+
setMemoryInfo(doc && doc.memory ? { personaId: doc.personaId, events: doc.memory.events || [], line: doc.line || '' } : null);
|
|
21531
|
+
}, []);
|
|
21532
|
+
|
|
21533
|
+
const memoryRollback = async () => {
|
|
21534
|
+
if (!memoryInfo || !memoryInfo.personaId || !/^\d{4}-\d{2}-\d{2}$/.test(rollbackDate)) {
|
|
21535
|
+
setMemoryNote({ ok: false, text: weT('先填日期(YYYY-MM-DD)') });
|
|
21536
|
+
return;
|
|
21537
|
+
}
|
|
21538
|
+
const resp = await apiFetch(`/pet-chat/personas/${encodeURIComponent(memoryInfo.personaId)}/memory/by-date?date=${encodeURIComponent(rollbackDate)}`, {
|
|
21539
|
+
method: 'DELETE',
|
|
21540
|
+
}).catch(() => null);
|
|
21541
|
+
const doc = (resp && resp.data) || {};
|
|
21542
|
+
setMemoryNote({ ok: doc.ok === true, text: doc.ok === true ? weT('已回滚 {n} 条', { n: doc.deleted || 0 }) : weT('回滚失败') });
|
|
21543
|
+
await loadMemoryInfo();
|
|
21544
|
+
};
|
|
21545
|
+
|
|
21546
|
+
const memoryExport = async () => {
|
|
21547
|
+
if (!memoryInfo || !memoryInfo.personaId) return;
|
|
21548
|
+
const resp = await apiFetch(`/pet-chat/personas/${encodeURIComponent(memoryInfo.personaId)}/memory/export`, { parse: false }).catch(() => null);
|
|
21549
|
+
try {
|
|
21550
|
+
const blob = await resp.response.blob();
|
|
21551
|
+
const url = URL.createObjectURL(blob);
|
|
21552
|
+
const a = document.createElement('a');
|
|
21553
|
+
a.href = url;
|
|
21554
|
+
a.download = memoryInfo.personaId + '-memory.json';
|
|
21555
|
+
a.click();
|
|
21556
|
+
setTimeout(() => URL.revokeObjectURL(url), 3000);
|
|
21557
|
+
} catch { setMemoryNote({ ok: false, text: weT('导出失败') }); }
|
|
21558
|
+
};
|
|
21559
|
+
|
|
21560
|
+
const loadUserPacks = React.useCallback(async () => {
|
|
21561
|
+
const resp = await apiJson('/pet-chat/voice/user-packs', { parse: 'always' }).catch(() => null);
|
|
21562
|
+
const doc = unwrapPetChat(resp);
|
|
21563
|
+
setUserPacks(Array.isArray(doc.userPacks) ? doc.userPacks : []);
|
|
21564
|
+
}, []);
|
|
21565
|
+
React.useEffect(() => {
|
|
21566
|
+
if (tab === 'voice') void loadUserPacks();
|
|
21567
|
+
}, [tab, loadUserPacks]);
|
|
21568
|
+
React.useEffect(() => {
|
|
21569
|
+
if (tab !== 'voice') return;
|
|
21570
|
+
void apiJson('/pet-chat/system-sounds', { parse: 'always' }).then((resp) => {
|
|
21571
|
+
const doc = unwrapPetChat(resp);
|
|
21572
|
+
setSystemSounds(Array.isArray(doc.sounds) ? doc.sounds : []);
|
|
21573
|
+
}).catch(() => {});
|
|
21574
|
+
}, [tab]);
|
|
21575
|
+
|
|
21576
|
+
const adminVoicePacks = async () => {
|
|
21577
|
+
const resp = await apiJson('/pet-chat/voice/user-packs', { parse: 'always' }).catch(() => null);
|
|
21578
|
+
const doc = unwrapPetChat(resp);
|
|
21579
|
+
setUserPacks(Array.isArray(doc.userPacks) ? doc.userPacks : []);
|
|
21580
|
+
return doc;
|
|
21581
|
+
};
|
|
21582
|
+
|
|
21583
|
+
const importUserPack = async (file) => {
|
|
21584
|
+
if (!file) return;
|
|
21585
|
+
if (!packForm.name || !packForm.license || !packForm.author) {
|
|
21586
|
+
setPackNote({ ok: false, text: weT('先填名字、许可证、作者/来源——没有授权的音色不要导入') });
|
|
21587
|
+
return;
|
|
21588
|
+
}
|
|
21589
|
+
const base64 = await new Promise((resolve) => {
|
|
21590
|
+
const reader = new FileReader();
|
|
21591
|
+
reader.onload = () => resolve(String(reader.result || ''));
|
|
21592
|
+
reader.onerror = () => resolve('');
|
|
21593
|
+
reader.readAsDataURL(file);
|
|
21594
|
+
});
|
|
21595
|
+
if (!base64) { setPackNote({ ok: false, text: weT('读不到这个音频文件') }); return; }
|
|
21596
|
+
const resp = await apiPostJson('/pet-chat/voice/user-packs/import', { ...packForm, audioBase64: base64 }, { parse: 'always' }).catch(() => null);
|
|
21597
|
+
const doc = unwrapPetChat(resp);
|
|
21598
|
+
if (doc && doc.ok) {
|
|
21599
|
+
setPackNote({ ok: true, text: weT('已导入:{n}', { n: doc.pack && doc.pack.name ? doc.pack.name : packForm.name }) });
|
|
21600
|
+
setPackForm({ name: '', license: '', author: '', refText: '', engine: 'gpt-sovits' });
|
|
21601
|
+
await adminVoicePacks();
|
|
21602
|
+
} else {
|
|
21603
|
+
setPackNote({ ok: false, text: (doc && doc.hint) || weT('导入失败') });
|
|
21604
|
+
}
|
|
21605
|
+
};
|
|
21606
|
+
|
|
21607
|
+
const removeUserPack = async (id) => {
|
|
21608
|
+
await apiPostJson('/pet-chat/voice/user-packs/remove', { id }, { parse: 'always' }).catch(() => null);
|
|
21609
|
+
await adminVoicePacks();
|
|
21610
|
+
};
|
|
21611
|
+
|
|
21612
|
+
const loadFfmpeg = React.useCallback(async () => { const resp = await apiJson('/pet-chat/voice/diagnose?light=1', { parse: 'always' }).catch(() => null);
|
|
21390
21613
|
const doc = unwrapPetChat(resp);
|
|
21391
21614
|
const st = doc && doc.steps && doc.steps.ffmpeg;
|
|
21392
21615
|
if (st && st.phase) setFfmpeg(st);
|
|
@@ -21730,10 +21953,11 @@ window.__ModuleLoader__.load({
|
|
|
21730
21953
|
: null);
|
|
21731
21954
|
child.push(React.createElement('div', { key: 'title', style: { fontWeight: 600, margin: '14px 0 4px', fontSize: '13px' } }, weT('智能大肥鱼')));
|
|
21732
21955
|
child.push(React.createElement('div', { key: 'hint', className: 'we-picker__hint', style: { margin: '0 0 6px' } },
|
|
21733
|
-
weT('填 Key
|
|
21956
|
+
weT('填 Key、起名字、选音色;对话模式、主动搭话、屏幕感知都在「对话与隐私」里,默认全关。')));
|
|
21734
21957
|
|
|
21735
21958
|
const tabs = [
|
|
21736
21959
|
['assistant', weT('助手')],
|
|
21960
|
+
['behavior', weT('对话与隐私')],
|
|
21737
21961
|
['voice', weT('朗读与音色')],
|
|
21738
21962
|
['work', weT('工作能力')],
|
|
21739
21963
|
];
|
|
@@ -21777,6 +22001,128 @@ window.__ModuleLoader__.load({
|
|
|
21777
22001
|
child.push(React.createElement(MicTestBlock, { key: 'mic-test' }));
|
|
21778
22002
|
}
|
|
21779
22003
|
|
|
22004
|
+
if (tab === 'behavior') {
|
|
22005
|
+
const mode = ['chat', 'story', 'treehole', 'observe'].includes(String(draft.conversationMode))
|
|
22006
|
+
? draft.conversationMode : 'chat';
|
|
22007
|
+
const pro = Object.assign({}, CHAT_DEFAULTS.proactive, draft.proactive || {});
|
|
22008
|
+
const screen = Object.assign({}, CHAT_DEFAULTS.screen, draft.screen || {});
|
|
22009
|
+
const behaviorPage = [];
|
|
22010
|
+
const selectOf = (key, value, options, onChange, disabled) => React.createElement('select', {
|
|
22011
|
+
key, value, disabled: busy || disabled === true,
|
|
22012
|
+
onChange: (e) => onChange(e.target.value),
|
|
22013
|
+
style: { minWidth: '128px' },
|
|
22014
|
+
}, options.map(([val, label]) => React.createElement('option', { key: val, value: val }, label)));
|
|
22015
|
+
const toggle = (key, checked, onChange, label) => React.createElement('label', {
|
|
22016
|
+
key, style: { display: 'flex', gap: '6px', alignItems: 'center', fontSize: '12px', margin: '4px 0' },
|
|
22017
|
+
}, React.createElement('input', {
|
|
22018
|
+
type: 'checkbox', checked, disabled: busy, onChange: (e) => onChange(e.target.checked),
|
|
22019
|
+
}), weT(label));
|
|
22020
|
+
|
|
22021
|
+
behaviorPage.push(row('conversation-mode', '对话模式', selectOf('mode', mode, [
|
|
22022
|
+
['chat', weT('聊天')], ['story', weT('讲故事')], ['treehole', weT('树洞')], ['observe', weT('只观察')],
|
|
22023
|
+
], (value) => update({ conversationMode: value }))));
|
|
22024
|
+
behaviorPage.push(React.createElement('div', { key: 'mode-hint', className: 'we-picker__hint', style: { margin: '0 0 6px' } },
|
|
22025
|
+
weT('聊天=日常短答;讲故事=不按句数截断;树洞=先接情绪;只观察=不回答、只记不说。')));
|
|
22026
|
+
|
|
22027
|
+
behaviorPage.push(row('voice-length', '语音回答长度', selectOf('vlen', String(draft.voiceLength), [
|
|
22028
|
+
['3', weT('3 句')], ['8', weT('8 句')], ['0', weT('不限')],
|
|
22029
|
+
], (value) => update({ voiceLength: Number(value) }))));
|
|
22030
|
+
|
|
22031
|
+
behaviorPage.push(toggle('pro-enabled', pro.enabled === true, (checked) => update({
|
|
22032
|
+
proactive: Object.assign({}, pro, { enabled: checked, intervalMin: checked && !pro.intervalMin ? 15 : pro.intervalMin }),
|
|
22033
|
+
}), '主动搭话(默认关)'));
|
|
22034
|
+
behaviorPage.push(row('pro-interval', '搭话间隔', selectOf('pint', String(pro.intervalMin || 15), [
|
|
22035
|
+
['15', weT('15 分钟')], ['30', weT('30 分钟')], ['60', weT('60 分钟')],
|
|
22036
|
+
], (value) => update({ proactive: Object.assign({}, pro, { intervalMin: Number(value) }) }), pro.enabled !== true)));
|
|
22037
|
+
if (pro.enabled !== true) {
|
|
22038
|
+
behaviorPage.push(React.createElement('div', { key: 'pro-off', className: 'we-picker__hint', style: { margin: '0 0 6px' } },
|
|
22039
|
+
weT('关着的时候它只在你主动说话时回应;打开后每小时最多主动 2 次。')));
|
|
22040
|
+
}
|
|
22041
|
+
behaviorPage.push(row('quiet-from', '勿扰时段', React.createElement('div', { key: 'q', style: { display: 'flex', gap: '4px', alignItems: 'center' } },
|
|
22042
|
+
React.createElement('input', {
|
|
22043
|
+
type: 'time', value: pro.quietFrom, disabled: busy,
|
|
22044
|
+
onChange: (e) => update({ proactive: Object.assign({}, pro, { quietFrom: e.target.value }) }),
|
|
22045
|
+
}),
|
|
22046
|
+
React.createElement('span', null, '–'),
|
|
22047
|
+
React.createElement('input', {
|
|
22048
|
+
type: 'time', value: pro.quietTo, disabled: busy,
|
|
22049
|
+
onChange: (e) => update({ proactive: Object.assign({}, pro, { quietTo: e.target.value }) }),
|
|
22050
|
+
}))));
|
|
22051
|
+
|
|
22052
|
+
behaviorPage.push(React.createElement('div', { key: 'privacy-head', style: { marginTop: '12px', fontSize: '12px', fontWeight: 600 } },
|
|
22053
|
+
weT('屏幕感知(默认关)')));
|
|
22054
|
+
behaviorPage.push(React.createElement('div', { key: 'privacy-hint', className: 'we-picker__hint', style: { margin: '2px 0 6px' } },
|
|
22055
|
+
weT('只读前台应用名与窗口标题(可选再加屏幕 OCR);读不到别的 App 内部数据,绝不上传截图或 OCR 原文。')));
|
|
22056
|
+
behaviorPage.push(row('screen-mode', '屏幕感知', selectOf('screen', screen.mode, [
|
|
22057
|
+
['off', weT('关')], ['app', weT('前台应用')], ['ocr', weT('前台 + OCR')],
|
|
22058
|
+
], (value) => {
|
|
22059
|
+
if (value === 'off') {
|
|
22060
|
+
setScreenArmed('');
|
|
22061
|
+
update({ screen: { mode: 'off', confirmed: false } });
|
|
22062
|
+
} else {
|
|
22063
|
+
// 第一下只“上膛”,看说明再确认(不直接开)。
|
|
22064
|
+
setScreenArmed(value);
|
|
22065
|
+
}
|
|
22066
|
+
})));
|
|
22067
|
+
if (screenArmed) {
|
|
22068
|
+
behaviorPage.push(React.createElement('div', {
|
|
22069
|
+
key: 'screen-confirm', style: {
|
|
22070
|
+
border: '1px solid rgba(251,191,36,.45)', background: 'rgba(251,191,36,.08)',
|
|
22071
|
+
borderRadius: '8px', padding: '6px 8px', margin: '2px 0 6px', fontSize: '11px',
|
|
22072
|
+
},
|
|
22073
|
+
},
|
|
22074
|
+
React.createElement('div', { style: { marginBottom: '4px' } },
|
|
22075
|
+
weT('开启后它会知道你当前在用哪个应用、窗口标题是什么(前台+OCR 还会定时读取屏幕文字)。所有记录只存在本机记忆里,可随时查看、删除。')),
|
|
22076
|
+
React.createElement('div', { key: 'btn-row', style: { display: 'flex', gap: '6px' } },
|
|
22077
|
+
React.createElement('button', {
|
|
22078
|
+
type: 'button', className: 'we-picker__btn', disabled: busy,
|
|
22079
|
+
onClick: () => { update({ screen: { mode: screenArmed, confirmed: true } }); setScreenArmed(''); },
|
|
22080
|
+
}, weT('确认开启')),
|
|
22081
|
+
React.createElement('button', {
|
|
22082
|
+
type: 'button', className: 'we-picker__btn', disabled: busy,
|
|
22083
|
+
onClick: () => setScreenArmed(''),
|
|
22084
|
+
}, weT('取消')))));
|
|
22085
|
+
}
|
|
22086
|
+
behaviorPage.push(React.createElement('div', { key: 'status-line', className: 'we-picker__hint', style: { margin: '0 0 4px' } },
|
|
22087
|
+
screen.mode === 'off' ? weT('当前:关(不读前台窗口,也不截屏)') : weT('当前:已开启(可随时关)')));
|
|
22088
|
+
behaviorPage.push(React.createElement('div', { key: 'observe-row', style: { display: 'flex', gap: '6px', flexWrap: 'wrap', margin: '4px 0' } },
|
|
22089
|
+
React.createElement('button', { type: 'button', className: 'we-picker__btn', onClick: () => { void loadObserveRecords(); } }, weT('查看观察记录')),
|
|
22090
|
+
React.createElement('button', { type: 'button', className: 'we-picker__btn', onClick: () => { void clearObserveRecords(); } }, weT('清空观察记录'))));
|
|
22091
|
+
if (observeList !== null) {
|
|
22092
|
+
behaviorPage.push(React.createElement('div', { key: 'observe-list', className: 'we-picker__hint', style: { margin: '0 0 6px' } },
|
|
22093
|
+
observeList.length
|
|
22094
|
+
? observeList.slice(0, 8).map((item) => React.createElement('div', { key: item.id }, '· ' + String(item.text || '').slice(0, 80)))
|
|
22095
|
+
: weT('还没有观察记录')));
|
|
22096
|
+
}
|
|
22097
|
+
|
|
22098
|
+
behaviorPage.push(React.createElement('div', { key: 'memory-head', style: { marginTop: '12px', fontSize: '12px', fontWeight: 600 } },
|
|
22099
|
+
weT('记忆')));
|
|
22100
|
+
behaviorPage.push(React.createElement('div', { key: 'memory-row', style: { display: 'flex', gap: '6px', flexWrap: 'wrap', margin: '4px 0' } },
|
|
22101
|
+
React.createElement('button', { type: 'button', className: 'we-picker__btn', onClick: () => { void loadMemoryInfo(); } }, weT('查看记忆')),
|
|
22102
|
+
React.createElement('button', { type: 'button', className: 'we-picker__btn', onClick: () => { void memoryExport(); } }, weT('导出记忆'))));
|
|
22103
|
+
if (memoryInfo) {
|
|
22104
|
+
behaviorPage.push(React.createElement('div', { key: 'memory-info', className: 'we-picker__hint', style: { margin: '0 0 6px' } },
|
|
22105
|
+
weT('最近 {n} 条事件', { n: (memoryInfo.events || []).length })));
|
|
22106
|
+
}
|
|
22107
|
+
behaviorPage.push(row('memory-rollback', '按日期回滚', React.createElement('div', { key: 'r', style: { display: 'flex', gap: '4px' } },
|
|
22108
|
+
React.createElement('input', {
|
|
22109
|
+
type: 'date', value: rollbackDate, disabled: busy,
|
|
22110
|
+
onChange: (e) => setRollbackDate(e.target.value),
|
|
22111
|
+
}),
|
|
22112
|
+
React.createElement('button', { type: 'button', className: 'we-picker__btn', disabled: busy, onClick: () => { void memoryRollback(); } }, weT('回滚')))));
|
|
22113
|
+
if (memoryNote) {
|
|
22114
|
+
behaviorPage.push(React.createElement('div', {
|
|
22115
|
+
key: 'memory-note', className: 'we-picker__hint',
|
|
22116
|
+
style: { margin: '0 0 6px', color: memoryNote.ok ? '#4ade80' : '#f87171' },
|
|
22117
|
+
}, memoryNote.text));
|
|
22118
|
+
}
|
|
22119
|
+
behaviorPage.push(row('hotline', '树洞求助热线', React.createElement('input', {
|
|
22120
|
+
type: 'text', value: (draft.treehole && draft.treehole.hotline) || '12356', disabled: busy,
|
|
22121
|
+
onChange: (e) => update({ treehole: { hotline: e.target.value } }),
|
|
22122
|
+
})));
|
|
22123
|
+
child.push(React.createElement('div', { key: 'behavior-page' }, behaviorPage));
|
|
22124
|
+
}
|
|
22125
|
+
|
|
21780
22126
|
if (tab === 'voice') {
|
|
21781
22127
|
const voicePage = [];
|
|
21782
22128
|
voicePage.push(React.createElement('div', {
|
|
@@ -21841,6 +22187,12 @@ window.__ModuleLoader__.load({
|
|
|
21841
22187
|
voicePage.push(React.createElement('div', {
|
|
21842
22188
|
key: 'local-head', style: { marginTop: '10px', fontSize: '12px', fontWeight: 600 },
|
|
21843
22189
|
}, weT('音色(只列本机真实可用)')));
|
|
22190
|
+
if (voiceNotice) {
|
|
22191
|
+
voicePage.push(React.createElement('div', {
|
|
22192
|
+
key: 'voice-notice', className: 'we-picker__hint',
|
|
22193
|
+
style: { margin: '2px 0', color: '#fbbf24' },
|
|
22194
|
+
}, voiceNotice));
|
|
22195
|
+
}
|
|
21844
22196
|
if (selectableVoices.length) {
|
|
21845
22197
|
const groups = [];
|
|
21846
22198
|
for (const engine of ['edge', 'piper', 'sapi', 'openai', 'azure', 'elevenlabs']) {
|
|
@@ -22074,6 +22426,57 @@ window.__ModuleLoader__.load({
|
|
|
22074
22426
|
...detailProps,
|
|
22075
22427
|
}));
|
|
22076
22428
|
}
|
|
22429
|
+
// v1.2:角色音色只走「用户下载/导入」;内置只有 4 个系统音效。
|
|
22430
|
+
voicePage.push(React.createElement('div', {
|
|
22431
|
+
key: 'pack-head', style: { marginTop: '14px', fontSize: '12px', fontWeight: 600 },
|
|
22432
|
+
}, weT('用户音色包(角色语音只走导入)')));
|
|
22433
|
+
voicePage.push(React.createElement('div', {
|
|
22434
|
+
key: 'pack-policy', className: 'we-picker__hint', style: { margin: '2px 0 6px' },
|
|
22435
|
+
}, weT('本插件不携带角色/声优素材。导入前请确认你有权使用这段参考音频,并填写许可证与作者/来源。')));
|
|
22436
|
+
if (userPacks.length) {
|
|
22437
|
+
voicePage.push(React.createElement('div', { key: 'pack-list', style: { display: 'flex', flexDirection: 'column', gap: '3px', margin: '0 0 6px' } },
|
|
22438
|
+
userPacks.map((pack) => React.createElement('div', { key: pack.id, style: { display: 'flex', gap: '6px', alignItems: 'center', fontSize: '11px' } },
|
|
22439
|
+
React.createElement('span', { style: { flex: 1 } }, `${pack.name} · ${pack.engine} · ${pack.license || weT('未填许可证')}`),
|
|
22440
|
+
React.createElement('button', {
|
|
22441
|
+
type: 'button', className: 'we-picker__btn', onClick: () => { void removeUserPack(pack.id); },
|
|
22442
|
+
}, weT('删除'))))));
|
|
22443
|
+
}
|
|
22444
|
+
const packInput = (key, placeholder, value, onChange, type) => React.createElement('input', {
|
|
22445
|
+
key, type: type || 'text', value, placeholder, disabled: busy,
|
|
22446
|
+
onChange: (e) => onChange(e.target.value),
|
|
22447
|
+
style: { fontSize: '11px', padding: '2px 6px', minWidth: '0' },
|
|
22448
|
+
});
|
|
22449
|
+
voicePage.push(React.createElement('div', {
|
|
22450
|
+
key: 'pack-form', style: { display: 'flex', flexDirection: 'column', gap: '4px', margin: '0 0 6px' },
|
|
22451
|
+
},
|
|
22452
|
+
packInput('pname', weT('音色包名字'), packForm.name, (v) => setPackForm((prev) => ({ ...prev, name: v }))),
|
|
22453
|
+
packInput('plicense', weT('许可证(如:本人录制,仅自用)'), packForm.license, (v) => setPackForm((prev) => ({ ...prev, license: v }))),
|
|
22454
|
+
packInput('pauthor', weT('作者 / 来源'), packForm.author, (v) => setPackForm((prev) => ({ ...prev, author: v }))),
|
|
22455
|
+
packInput('pref', weT('参考音频对应的文字(可选)'), packForm.refText, (v) => setPackForm((prev) => ({ ...prev, refText: v }))),
|
|
22456
|
+
React.createElement('div', { key: 'import-row', style: { display: 'flex', gap: '6px', alignItems: 'center', flexWrap: 'wrap' } },
|
|
22457
|
+
React.createElement('input', {
|
|
22458
|
+
key: 'file', type: 'file', accept: 'audio/*',
|
|
22459
|
+
onChange: (e) => { const file = e.target.files && e.target.files[0]; void importUserPack(file); },
|
|
22460
|
+
}),
|
|
22461
|
+
React.createElement('span', { className: 'we-picker__hint', style: { margin: 0 } },
|
|
22462
|
+
weT('参考音频只存本机用户目录,不进 npm 包、不上传。')))));
|
|
22463
|
+
if (packNote && packNote.text) {
|
|
22464
|
+
voicePage.push(React.createElement('div', {
|
|
22465
|
+
key: 'pack-note', className: 'we-picker__hint',
|
|
22466
|
+
style: { margin: '0 0 6px', color: packNote.ok ? '#4ade80' : '#f87171' },
|
|
22467
|
+
}, packNote.text));
|
|
22468
|
+
}
|
|
22469
|
+
voicePage.push(React.createElement('div', { key: 'sound-head', className: 'we-picker__hint', style: { margin: '2px 0' } },
|
|
22470
|
+
weT('内置系统音效(4 个,MIT,本项目合成;不含角色语音)')));
|
|
22471
|
+
if (systemSounds.length) {
|
|
22472
|
+
voicePage.push(React.createElement('div', { key: 'sound-list', style: { display: 'flex', flexDirection: 'column', gap: '3px', margin: '0 0 6px' } },
|
|
22473
|
+
systemSounds.map((sound) => React.createElement('div', { key: sound.id, style: { display: 'flex', gap: '6px', alignItems: 'center', fontSize: '11px' } },
|
|
22474
|
+
React.createElement('span', null, `${sound.name} · ${sound.license || ''}`),
|
|
22475
|
+
React.createElement('audio', {
|
|
22476
|
+
controls: true, preload: 'none', style: { height: '22px' },
|
|
22477
|
+
src: apiUrl('/pet-chat/system-sounds/' + encodeURIComponent(sound.id) + '.wav'),
|
|
22478
|
+
})))));
|
|
22479
|
+
}
|
|
22077
22480
|
child.push(React.createElement('div', { key: 'voice-page' }, voicePage));
|
|
22078
22481
|
}
|
|
22079
22482
|
|
|
@@ -23317,6 +23720,19 @@ window.__ModuleLoader__.load({
|
|
|
23317
23720
|
try { window.dispatchEvent(new CustomEvent("we-pet-talk")); } catch { /* ignore */ }
|
|
23318
23721
|
closeMenu();
|
|
23319
23722
|
}));
|
|
23723
|
+
// v1.2 会话模式:聊天 / 讲故事 / 树洞 / 只观察(右键直接切换,由 pet-chat 监听)
|
|
23724
|
+
let chatMode = "chat";
|
|
23725
|
+
try { chatMode = (window.__dshFoliaPet && window.__dshFoliaPet.getMode && window.__dshFoliaPet.getMode()) || "chat"; } catch { /* ignore */ }
|
|
23726
|
+
const modeHead = document.createElement("div");
|
|
23727
|
+
modeHead.textContent = weT("模式");
|
|
23728
|
+
modeHead.style.cssText = "padding:4px 10px 4px;opacity:0.55;font-size:11px";
|
|
23729
|
+
menu.appendChild(modeHead);
|
|
23730
|
+
[["chat", weT("聊天")], ["story", weT("讲故事")], ["treehole", weT("树洞")], ["observe", weT("只观察")]].forEach(([mode, label]) => {
|
|
23731
|
+
menu.appendChild(buildMenuItem((chatMode === mode ? "☑ " : "☐ ") + label, () => {
|
|
23732
|
+
try { window.dispatchEvent(new CustomEvent("we-pet-mode", { detail: { mode } })); } catch { /* ignore */ }
|
|
23733
|
+
closeMenu();
|
|
23734
|
+
}));
|
|
23735
|
+
});
|
|
23320
23736
|
menu.appendChild(buildMenuItem(weT("再大一点"), () => { applyScale(scale + 0.2); closeMenu(); }));
|
|
23321
23737
|
menu.appendChild(buildMenuItem(weT("再小一点"), () => { applyScale(Math.max(0.5, scale - 0.2)); closeMenu(); }));
|
|
23322
23738
|
menu.appendChild(buildMenuItem(weT("回右下角"), () => {
|
|
@@ -25217,6 +25633,11 @@ window.__ModuleLoader__.load({
|
|
|
25217
25633
|
const PET_TTS_MAX_PIECES = 8;
|
|
25218
25634
|
/** 与宿主 `TTS_MAX_CHARS` 对齐的总上限。 */
|
|
25219
25635
|
const PET_TTS_MAX_CHARS = 240;
|
|
25636
|
+
/**
|
|
25637
|
+
* 句间静音(200–350ms,任务书 §11③):不靠标点让引擎停顿(那会被念成“逗号/句号”),
|
|
25638
|
+
* 而是由播放队列在两句之间插一段静音 —— 有停顿,但合成文本里已经没有标点。
|
|
25639
|
+
*/
|
|
25640
|
+
const PET_TTS_GAP_MS = 260;
|
|
25220
25641
|
|
|
25221
25642
|
/**
|
|
25222
25643
|
* 纯函数:把一段文字切成“适合一句一合成”的片段。
|
|
@@ -25439,6 +25860,11 @@ window.__ModuleLoader__.load({
|
|
|
25439
25860
|
onError(error);
|
|
25440
25861
|
break;
|
|
25441
25862
|
}
|
|
25863
|
+
// 句间 260ms 静音(任务书 §11③):合成文本已去标点,停顿只能由队列给。
|
|
25864
|
+
if (queue.length && queue[0].gen === gen) {
|
|
25865
|
+
await new Promise((resolve) => { setTimeout(resolve, PET_TTS_GAP_MS); });
|
|
25866
|
+
if (item.gen !== generation) break;
|
|
25867
|
+
}
|
|
25442
25868
|
}
|
|
25443
25869
|
} finally {
|
|
25444
25870
|
busy = false;
|
|
@@ -25484,13 +25910,23 @@ window.__ModuleLoader__.load({
|
|
|
25484
25910
|
if (disposed) return false;
|
|
25485
25911
|
const cfg = getVoice() || {};
|
|
25486
25912
|
if (cfg.muted === true) { onState('idle'); return false; }
|
|
25487
|
-
|
|
25913
|
+
let pieces = petTtsSplit(text);
|
|
25488
25914
|
if (!pieces.length) return false;
|
|
25489
25915
|
if (!AudioCtor) {
|
|
25490
25916
|
onError({ code: 'tts-no-audio', hint: '这个环境不能播放声音' });
|
|
25491
25917
|
return false;
|
|
25492
25918
|
}
|
|
25493
25919
|
const speechOpts = speech || {};
|
|
25920
|
+
/**
|
|
25921
|
+
* v1.2 故事模式:`group: 2|3` 把相邻 2–3 句合成**一段**再请求宿主
|
|
25922
|
+
* (每 1–3 句一段,减少碎片;默认 group=1 时行为与旧版完全一致)。
|
|
25923
|
+
*/
|
|
25924
|
+
const group = Math.min(3, Math.max(1, Math.round(Number(speechOpts.group) || 1)));
|
|
25925
|
+
if (group > 1 && pieces.length > 1) {
|
|
25926
|
+
const merged = [];
|
|
25927
|
+
for (let i = 0; i < pieces.length; i += group) merged.push(pieces.slice(i, i + group).join(''));
|
|
25928
|
+
pieces = merged;
|
|
25929
|
+
}
|
|
25494
25930
|
const voice = String(speechOpts.voice || cfg.name || '');
|
|
25495
25931
|
const rawRate = speechOpts.rate !== undefined ? speechOpts.rate : cfg.rate;
|
|
25496
25932
|
const rate = Number.isFinite(Number(rawRate)) ? Number(rawRate) : 0;
|
|
@@ -25688,6 +26124,17 @@ window.__ModuleLoader__.load({
|
|
|
25688
26124
|
let petChatVoice = { name: '', muted: false, rate: 0, continuous: true, listenPaused: false };
|
|
25689
26125
|
/** pre.65:本轮输入方式决定长度策略(语音 1–3 句;文字可长)。 */
|
|
25690
26126
|
let petChatInputMode = 'text';
|
|
26127
|
+
/**
|
|
26128
|
+
* v1.2 会话模式:chat(默认)/ story(讲故事)/ treehole(树洞)/ observe(只观察)。
|
|
26129
|
+
* 模式随每次 /pet-chat/chat 上报(宿主旧版本会安全忽略未知字段)。
|
|
26130
|
+
*/
|
|
26131
|
+
let petChatConversationMode = 'chat';
|
|
26132
|
+
/** v1.2 语音回答长度(0 = 不限;默认 8 句 —— 旧版宿主写死 3 句)。 */
|
|
26133
|
+
let petChatVoiceLength = 8;
|
|
26134
|
+
/** 故事模式:上一轮全文(「重讲 / 缩短」直接用它,不再问模型)。 */
|
|
26135
|
+
let petChatLastReply = '';
|
|
26136
|
+
/** 「继续」:下一轮不清空气泡,接在原文后面。 */
|
|
26137
|
+
let petChatKeepBubble = false;
|
|
25691
26138
|
/** 当前 active persona(只用于提示/排障;宿主以 index.active 为准,避免切换后发旧 id)。 */
|
|
25692
26139
|
let petChatPersonaId = '';
|
|
25693
26140
|
async function petChatRefreshVoice() {
|
|
@@ -25705,6 +26152,10 @@ window.__ModuleLoader__.load({
|
|
|
25705
26152
|
listenPaused: doc.voice.listenPaused === true,
|
|
25706
26153
|
};
|
|
25707
26154
|
}
|
|
26155
|
+
// v1.2:会话模式 / 语音长度由宿主设置下发(默认 chat / 8)。
|
|
26156
|
+
if (typeof doc.conversationMode === 'string') petChatConversationMode = petChatNormalizeMode(doc.conversationMode);
|
|
26157
|
+
if (Number.isFinite(Number(doc.voiceLength))) petChatVoiceLength = Math.max(0, Math.round(Number(doc.voiceLength)));
|
|
26158
|
+
petChatProactiveEnabled = Boolean(doc.proactive && doc.proactive.enabled === true);
|
|
25708
26159
|
} catch { /* 读不到就用默认(不静音) */ }
|
|
25709
26160
|
// 「暂停说话 / 暂停聆听」都是持久开关:设置页/右键改完立刻生效。
|
|
25710
26161
|
petChatSpeakPaused = petChatVoice.muted === true;
|
|
@@ -25712,9 +26163,29 @@ window.__ModuleLoader__.load({
|
|
|
25712
26163
|
petChatContinuousPaused = petChatVoice.listenPaused === true;
|
|
25713
26164
|
petBubble.setVoiceFlags({ speakPaused: petChatSpeakPaused, listenPaused: petChatContinuousPaused });
|
|
25714
26165
|
petChatPublishContinuousState();
|
|
26166
|
+
petChatApplyModeUi();
|
|
26167
|
+
if (petChatProactiveEnabled) petChatMindStart();
|
|
25715
26168
|
return petChatVoice;
|
|
25716
26169
|
}
|
|
25717
26170
|
|
|
26171
|
+
/** v1.2:模式值归一(未知值一律回落 chat,不猜近似值)。 */
|
|
26172
|
+
function petChatNormalizeMode(value) {
|
|
26173
|
+
const mode = String(value || '');
|
|
26174
|
+
return ['chat', 'story', 'treehole', 'observe'].includes(mode) ? mode : 'chat';
|
|
26175
|
+
}
|
|
26176
|
+
|
|
26177
|
+
/** v1.2:模式的可视提示 —— 只观察时状态条常驻「👁 观察中」,退出即收起。 */
|
|
26178
|
+
function petChatApplyModeUi() {
|
|
26179
|
+
try {
|
|
26180
|
+
if (petChatConversationMode === 'observe') {
|
|
26181
|
+
petBubble.status('info', '👁 ' + weT('观察中'), { delay: 0 });
|
|
26182
|
+
} else {
|
|
26183
|
+
petBubble.hideStatus(0);
|
|
26184
|
+
}
|
|
26185
|
+
} catch { /* 状态条是增强 */ }
|
|
26186
|
+
petChatPublishContinuousState();
|
|
26187
|
+
}
|
|
26188
|
+
|
|
25718
26189
|
/* ── 常驻聆听(任务 §4):装好就在听;半双工;「暂停说话 / 暂停聆听」两个开关 ── *
|
|
25719
26190
|
*
|
|
25720
26191
|
* 状态机:idle → listening → thinking → speaking → listening(循环)
|
|
@@ -25759,6 +26230,8 @@ window.__ModuleLoader__.load({
|
|
|
25759
26230
|
active: petChatContinuousActive === true,
|
|
25760
26231
|
paused: petChatContinuousPaused === true,
|
|
25761
26232
|
rounds: petChatContinuousRounds,
|
|
26233
|
+
mode: petChatConversationMode,
|
|
26234
|
+
voiceLength: petChatVoiceLength,
|
|
25762
26235
|
},
|
|
25763
26236
|
}));
|
|
25764
26237
|
window.dispatchEvent(new CustomEvent('we-pet-voice-state', {
|
|
@@ -26304,7 +26777,10 @@ window.__ModuleLoader__.load({
|
|
|
26304
26777
|
},
|
|
26305
26778
|
onState: (kind) => { petBubble.setState(kind); },
|
|
26306
26779
|
onIdle: () => {
|
|
26307
|
-
|
|
26780
|
+
// v1.2:故事/树洞读完不马上收起(否则 800 字故事刚读完就消失,没法回看)。
|
|
26781
|
+
if (petChatConversationMode === 'story') { /* 保留气泡,由用户点关闭或「缩短」 */ }
|
|
26782
|
+
else if (petChatConversationMode === 'treehole') petBubble.hide(10000);
|
|
26783
|
+
else petBubble.hide(3000);
|
|
26308
26784
|
petChatListeningNow = false;
|
|
26309
26785
|
// 播完 150ms 自动恢复听(半双工:朗读期间绝不录音)。
|
|
26310
26786
|
if (petChatContinuousActive && !petChatContinuousPaused) petChatContinuousArm(PET_CHAT_LISTEN_RESUME_MS);
|
|
@@ -26472,6 +26948,16 @@ window.__ModuleLoader__.load({
|
|
|
26472
26948
|
return;
|
|
26473
26949
|
}
|
|
26474
26950
|
petChatTurnBegin();
|
|
26951
|
+
/**
|
|
26952
|
+
* v1.2 只观察模式:**不回答、不弹气泡**(没对它说话时只记不说)。
|
|
26953
|
+
* 宿主也会兜底拒绝,但客户端这一层先挡住,避免每次唤醒都白发一个请求。
|
|
26954
|
+
*/
|
|
26955
|
+
if (petChatConversationMode === 'observe') {
|
|
26956
|
+
petBubble.status('info', '👁 ' + weT('观察中'), { delay: 0 });
|
|
26957
|
+
if (typeof onState === 'function') onState({ state: 'idle' });
|
|
26958
|
+
petChatTurnEnd();
|
|
26959
|
+
return;
|
|
26960
|
+
}
|
|
26475
26961
|
const turnStartAt = Date.now();
|
|
26476
26962
|
let firstTokenAt = 0;
|
|
26477
26963
|
let firstAudioAt = 0;
|
|
@@ -26485,7 +26971,13 @@ window.__ModuleLoader__.load({
|
|
|
26485
26971
|
// “想”态:模型还在回,先不给“说”的波形
|
|
26486
26972
|
petBubble.setState('think');
|
|
26487
26973
|
// 新一轮回答从空气泡开始(否则会追加到上一轮回答的尾部)。
|
|
26488
|
-
|
|
26974
|
+
// v1.2「继续」:不清空,用两个换行接在原文后面(故事分章阅读)。
|
|
26975
|
+
if (petChatKeepBubble) {
|
|
26976
|
+
petBubble.append('\n\n');
|
|
26977
|
+
petChatKeepBubble = false;
|
|
26978
|
+
} else {
|
|
26979
|
+
petBubble.clear();
|
|
26980
|
+
}
|
|
26489
26981
|
// v2 环境感知:壁纸名 / 正在播放由前端补(宿主不认识 selection 与媒体桥实例)。
|
|
26490
26982
|
const context = await petChatEnvSnapshot();
|
|
26491
26983
|
// ⚠️ apiFetch 的返回值里**已经带上了原始 Response**(字段 `response`)。
|
|
@@ -26503,6 +26995,8 @@ window.__ModuleLoader__.load({
|
|
|
26503
26995
|
context,
|
|
26504
26996
|
// pre.65:显式输入方式让宿主做“语音 1–3 句 / 文字可长”的长度策略。
|
|
26505
26997
|
inputMode: petChatInputMode === 'voice' ? 'voice' : 'text',
|
|
26998
|
+
// v1.2:会话模式随每次请求上报(旧宿主安全忽略未知字段)。
|
|
26999
|
+
conversationMode: petChatConversationMode,
|
|
26506
27000
|
}),
|
|
26507
27001
|
// ⚠️ 必须 parse:'none'。默认路径会 await response.json(),
|
|
26508
27002
|
// 那会把 SSE 流**整个消费掉**(等到生成结束、再解析失败),
|
|
@@ -26534,16 +27028,30 @@ window.__ModuleLoader__.load({
|
|
|
26534
27028
|
*/
|
|
26535
27029
|
let speakBuffer = '';
|
|
26536
27030
|
let queuedSpeech = 0;
|
|
26537
|
-
|
|
26538
|
-
|
|
27031
|
+
/** v1.2:故事模式每 2 句合成一段(1–3 句/段的队列播放),减少碎片化。 */
|
|
27032
|
+
let speechBatch = '';
|
|
27033
|
+
/** 本轮回答全文(故事模式的「重讲 / 缩短」用)。 */
|
|
27034
|
+
let turnReply = '';
|
|
27035
|
+
const enqueueSpeech = (piece, flush) => {
|
|
27036
|
+
let line = String(piece || '').trim();
|
|
26539
27037
|
if (!line) return;
|
|
26540
27038
|
// 任务 §4③:「暂停说话」= 跳过 TTS 队列,只出字幕;状态条显示「🔇 仅文字」。
|
|
26541
27039
|
if (petChatSpeakPaused) {
|
|
26542
27040
|
petBubble.setState('muted');
|
|
26543
27041
|
return;
|
|
26544
27042
|
}
|
|
27043
|
+
if (petChatConversationMode === 'story') {
|
|
27044
|
+
// 2 句一批;flush 时把尾句也送出去。每段仍受宿主 240 字上限约束(2 句通常 < 100 字)。
|
|
27045
|
+
speechBatch += line;
|
|
27046
|
+
if (!flush && speechBatch.length < 60) return;
|
|
27047
|
+
line = speechBatch;
|
|
27048
|
+
speechBatch = '';
|
|
27049
|
+
}
|
|
26545
27050
|
// v2:本轮语速由宿主 meta 给(夜间/疲惫 -1 = -10%);再叠加当前人设的 voice.rate。
|
|
26546
|
-
if (petSpeak(line, {
|
|
27051
|
+
if (petSpeak(line, {
|
|
27052
|
+
rate: petChatSpeechRate + (Number(petChatVoice.rate) || 0),
|
|
27053
|
+
...(petChatConversationMode === 'story' ? { group: 2 } : {}),
|
|
27054
|
+
})) {
|
|
26547
27055
|
queuedSpeech += 1;
|
|
26548
27056
|
if (!firstAudioAt) firstAudioAt = Date.now(); // 首段音频交给播放器的时刻
|
|
26549
27057
|
}
|
|
@@ -26606,6 +27114,16 @@ window.__ModuleLoader__.load({
|
|
|
26606
27114
|
if (Number.isFinite(Number(payload.rate))) petChatSpeechRate = Number(payload.rate);
|
|
26607
27115
|
continue;
|
|
26608
27116
|
}
|
|
27117
|
+
/**
|
|
27118
|
+
* v1.2:宿主失败事件(rate-limited / no-model / timeout / bad-request…)以前**完全静默**,
|
|
27119
|
+
* 气泡停在「在想」。这里补一条可见提示,并把这一轮收尾。
|
|
27120
|
+
*/
|
|
27121
|
+
if (eventName === 'error') {
|
|
27122
|
+
const hint = String(payload.hint || payload.code || weT('这次没答上来'));
|
|
27123
|
+
petBubble.status('error', hint, { delay: 5000 });
|
|
27124
|
+
replyDone = true;
|
|
27125
|
+
continue;
|
|
27126
|
+
}
|
|
26609
27127
|
// 防兜底:模型偶尔仍会输出 {"reply":"…","emotion":"…"} 信封,
|
|
26610
27128
|
// 这里只把 reply 的正文喂给气泡(不显示大括号/字段名/emotion)。
|
|
26611
27129
|
if (typeof payload.t === 'string') {
|
|
@@ -26628,6 +27146,7 @@ window.__ModuleLoader__.load({
|
|
|
26628
27146
|
// 气泡始终显示**完整回答**(逐段追加,长文在 160px 内滚动);
|
|
26629
27147
|
// 朗读只负责切句与“说”状态,不再改写气泡内容。
|
|
26630
27148
|
petBubble.append(piece);
|
|
27149
|
+
turnReply += piece;
|
|
26631
27150
|
speakBuffer += piece;
|
|
26632
27151
|
const split = petTtsSentences(speakBuffer);
|
|
26633
27152
|
for (const sentence of split.sentences) enqueueSpeech(sentence);
|
|
@@ -26638,7 +27157,10 @@ window.__ModuleLoader__.load({
|
|
|
26638
27157
|
}
|
|
26639
27158
|
}
|
|
26640
27159
|
// 最后一段没有句末标点也要念(比如“我也在”)
|
|
26641
|
-
enqueueSpeech(speakBuffer);
|
|
27160
|
+
enqueueSpeech(speakBuffer, true);
|
|
27161
|
+
// v1.2:故事模式记住全文(「重讲 / 缩短」不再问模型),并给出操作按钮。
|
|
27162
|
+
petChatLastReply = String(turnReply || '').trim();
|
|
27163
|
+
if (petChatConversationMode === 'story' && petChatLastReply) petChatStoryBarShow();
|
|
26642
27164
|
if (typeof onState === 'function') onState({ state: 'idle' });
|
|
26643
27165
|
// 本轮成功:常驻聆听继续(任务 §4:装好就在听,不靠"点了才听");
|
|
26644
27166
|
// 有朗读时等 onIdle 播完再开麦(半双工),没朗读(暂停说话/静音)直接 150ms 后排下一轮。
|
|
@@ -26650,7 +27172,12 @@ window.__ModuleLoader__.load({
|
|
|
26650
27172
|
if (!queuedSpeech && !singStarted) petChatContinuousArm();
|
|
26651
27173
|
// 没有任何一句进入朗读(暂停说话 / 合成不可用)⇒ 字幕照常显示,3 秒后淡出。
|
|
26652
27174
|
// 唱歌时气泡归歌词用:不提前收,播完由 petChatSingPlay 收。
|
|
26653
|
-
|
|
27175
|
+
// v1.2:故事保留气泡(用户要能回看/点「缩短」);树洞多留一会儿。
|
|
27176
|
+
if (!queuedSpeech && !singStarted) {
|
|
27177
|
+
if (petChatConversationMode === 'story') { /* 不自动收 */ }
|
|
27178
|
+
else if (petChatConversationMode === 'treehole') petBubble.hide(10000);
|
|
27179
|
+
else petBubble.hide(3000);
|
|
27180
|
+
}
|
|
26654
27181
|
petChatReportLatency(turnStartAt, firstTokenAt, firstAudioAt);
|
|
26655
27182
|
petChatTurnEnd();
|
|
26656
27183
|
},
|
|
@@ -26740,6 +27267,122 @@ window.__ModuleLoader__.load({
|
|
|
26740
27267
|
if (!petSpeak(line)) petBubble.hide(3000);
|
|
26741
27268
|
}
|
|
26742
27269
|
|
|
27270
|
+
/* ── v1.2 故事模式:继续 / 重讲 / 缩短 ─────────────────────────────────── */
|
|
27271
|
+
|
|
27272
|
+
let petChatStoryBar = null;
|
|
27273
|
+
|
|
27274
|
+
function petChatStoryBarHide() {
|
|
27275
|
+
try { if (petChatStoryBar && petChatStoryBar.parentNode) petChatStoryBar.parentNode.removeChild(petChatStoryBar); } catch { /* ignore */ }
|
|
27276
|
+
petChatStoryBar = null;
|
|
27277
|
+
}
|
|
27278
|
+
|
|
27279
|
+
/** 把一段长文按句切成 ≤max 字的小段(重讲/朗读用;宿主单次上限 240 字)。 */
|
|
27280
|
+
function petChatStoryChunks(text, max) {
|
|
27281
|
+
const limit = Math.max(60, Number(max) || 180);
|
|
27282
|
+
const chunks = [];
|
|
27283
|
+
let buffer = '';
|
|
27284
|
+
for (const ch of String(text || '')) {
|
|
27285
|
+
buffer += ch;
|
|
27286
|
+
if (/[。!?!?;;\n]/.test(ch) && buffer.length >= limit * 0.5) {
|
|
27287
|
+
chunks.push(buffer.trim());
|
|
27288
|
+
buffer = '';
|
|
27289
|
+
} else if (buffer.length >= limit) {
|
|
27290
|
+
chunks.push(buffer.trim());
|
|
27291
|
+
buffer = '';
|
|
27292
|
+
}
|
|
27293
|
+
}
|
|
27294
|
+
if (buffer.trim()) chunks.push(buffer.trim());
|
|
27295
|
+
return chunks.filter(Boolean);
|
|
27296
|
+
}
|
|
27297
|
+
|
|
27298
|
+
function petChatStoryBarShow() {
|
|
27299
|
+
petChatStoryBarHide();
|
|
27300
|
+
if (typeof document === 'undefined' || !document.body || typeof document.createElement !== 'function') return;
|
|
27301
|
+
const bar = document.createElement('div');
|
|
27302
|
+
bar.id = 'we-pet-story-actions';
|
|
27303
|
+
bar.style.cssText = 'position:fixed;right:22px;bottom:104px;z-index:10000;display:flex;gap:6px;'
|
|
27304
|
+
+ 'background:rgba(20,22,28,.92);border:1px solid rgba(255,255,255,.16);border-radius:10px;padding:6px;'
|
|
27305
|
+
+ 'box-shadow:0 6px 20px rgba(0,0,0,.35);';
|
|
27306
|
+
const make = (label, onClick) => {
|
|
27307
|
+
const button = document.createElement('button');
|
|
27308
|
+
button.type = 'button';
|
|
27309
|
+
button.textContent = label;
|
|
27310
|
+
button.style.cssText = 'font-size:12px;padding:4px 9px;border-radius:7px;border:1px solid rgba(255,255,255,.18);'
|
|
27311
|
+
+ 'background:rgba(255,255,255,.08);color:#eee;cursor:pointer;';
|
|
27312
|
+
button.addEventListener('click', (event) => {
|
|
27313
|
+
try { event.stopPropagation(); } catch { /* ignore */ }
|
|
27314
|
+
onClick();
|
|
27315
|
+
});
|
|
27316
|
+
return button;
|
|
27317
|
+
};
|
|
27318
|
+
bar.appendChild(make(weT('继续'), () => {
|
|
27319
|
+
petChatStoryBarHide();
|
|
27320
|
+
petChatInputMode = 'text';
|
|
27321
|
+
petChatKeepBubble = true;
|
|
27322
|
+
petBubble.setState('think');
|
|
27323
|
+
void petVoiceIn.postChat('继续讲下去,接着刚才的情节,不要重复已经讲过的内容。');
|
|
27324
|
+
}));
|
|
27325
|
+
bar.appendChild(make(weT('重讲'), () => {
|
|
27326
|
+
petChatStoryBarHide();
|
|
27327
|
+
petSpeakStop();
|
|
27328
|
+
const text = petChatLastReply;
|
|
27329
|
+
if (!text) return;
|
|
27330
|
+
petBubble.show(text);
|
|
27331
|
+
try { petBubble.setExpanded(true); } catch { /* ignore */ }
|
|
27332
|
+
for (const chunk of petChatStoryChunks(text)) petSpeak(chunk, { group: 2 });
|
|
27333
|
+
}));
|
|
27334
|
+
bar.appendChild(make(weT('缩短'), () => {
|
|
27335
|
+
petChatStoryBarHide();
|
|
27336
|
+
petSpeakStop();
|
|
27337
|
+
const text = petChatLastReply;
|
|
27338
|
+
if (!text) return;
|
|
27339
|
+
const sentences = (text.match(/[^。!?!?]+[。!?!?]?/g) || []).slice(0, 3).join('').trim() || text.slice(0, 160);
|
|
27340
|
+
petChatLastReply = sentences;
|
|
27341
|
+
petBubble.show(sentences);
|
|
27342
|
+
petSpeak(sentences);
|
|
27343
|
+
}));
|
|
27344
|
+
bar.appendChild(make(weT('收起'), () => {
|
|
27345
|
+
petChatStoryBarHide();
|
|
27346
|
+
petBubble.hide(0);
|
|
27347
|
+
}));
|
|
27348
|
+
document.body.appendChild(bar);
|
|
27349
|
+
petChatStoryBar = bar;
|
|
27350
|
+
}
|
|
27351
|
+
|
|
27352
|
+
/** v1.2:切换会话模式(右键菜单 / 设置都会走到这里)。 */
|
|
27353
|
+
function petChatSetMode(mode) {
|
|
27354
|
+
petChatConversationMode = petChatNormalizeMode(mode);
|
|
27355
|
+
if (petChatConversationMode !== 'story') petChatStoryBarHide();
|
|
27356
|
+
petChatApplyModeUi();
|
|
27357
|
+
petChatPublishContinuousState();
|
|
27358
|
+
}
|
|
27359
|
+
|
|
27360
|
+
/* ── v1.2 主动思维:客户端每 5 分钟问一次宿主“现在想不想说点什么” ─────── */
|
|
27361
|
+
|
|
27362
|
+
let petChatProactiveEnabled = false;
|
|
27363
|
+
let petChatMindTimer = null;
|
|
27364
|
+
|
|
27365
|
+
async function petChatMindPoll() {
|
|
27366
|
+
if (!petChatProactiveEnabled || petChatConversationMode === 'observe') return;
|
|
27367
|
+
if (!petChatProactiveAllowed()) return;
|
|
27368
|
+
try {
|
|
27369
|
+
const resp = await apiPostJson('/pet-chat/mind/tick', {
|
|
27370
|
+
speaking: (() => { try { return petTts.isSpeaking(); } catch { return false; } })(),
|
|
27371
|
+
listening: petChatListeningNow === true,
|
|
27372
|
+
turnBusy: petChatTurnBusy === true,
|
|
27373
|
+
activeMinutes: petChatWorkStart ? Math.round((Date.now() - petChatWorkStart) / 60000) : 0,
|
|
27374
|
+
}, { parse: 'always' });
|
|
27375
|
+
const doc = (resp && resp.data) || {};
|
|
27376
|
+
if (doc.ok && doc.line) petChatSay(String(doc.line));
|
|
27377
|
+
} catch { /* 主动是增强,失败静默 */ }
|
|
27378
|
+
}
|
|
27379
|
+
|
|
27380
|
+
function petChatMindStart() {
|
|
27381
|
+
if (petChatMindTimer != null || typeof setInterval !== 'function') return;
|
|
27382
|
+
petChatMindTimer = setInterval(() => { void petChatMindPoll(); }, 5 * 60 * 1000);
|
|
27383
|
+
if (typeof petChatMindTimer.unref === 'function') petChatMindTimer.unref();
|
|
27384
|
+
}
|
|
27385
|
+
|
|
26743
27386
|
/** 每次点桌宠递增;收起/重开时让旧的 ASR 等待自动作废。 */
|
|
26744
27387
|
let petChatWakeSeq = 0;
|
|
26745
27388
|
|
|
@@ -26933,6 +27576,12 @@ window.__ModuleLoader__.load({
|
|
|
26933
27576
|
};
|
|
26934
27577
|
window.addEventListener('we-pet-speak-pause', onSpeakPauseEvent);
|
|
26935
27578
|
window.addEventListener('we-pet-listen-pause', onListenPauseEvent);
|
|
27579
|
+
// v1.2:右键菜单/设置页切换会话模式(聊天 / 讲故事 / 树洞 / 只观察)。
|
|
27580
|
+
const onModeEvent = (event) => {
|
|
27581
|
+
const detail = (event && event.detail) || {};
|
|
27582
|
+
petChatSetMode(detail.mode);
|
|
27583
|
+
};
|
|
27584
|
+
window.addEventListener('we-pet-mode', onModeEvent);
|
|
26936
27585
|
// 页面隐藏:暂时停麦(不持久化,回到页面自动恢复);不偷偷在后台开麦。
|
|
26937
27586
|
const onVisibility = () => {
|
|
26938
27587
|
if (typeof document === 'undefined') return;
|
|
@@ -26978,6 +27627,9 @@ window.__ModuleLoader__.load({
|
|
|
26978
27627
|
isListening: () => petChatListeningNow === true,
|
|
26979
27628
|
isSpeakPaused: () => petChatSpeakPaused === true,
|
|
26980
27629
|
isListenPaused: () => petChatContinuousPaused === true,
|
|
27630
|
+
// v1.2:会话模式(右键/设置页切换;判据也用它)
|
|
27631
|
+
getMode: () => petChatConversationMode,
|
|
27632
|
+
setMode: (mode) => petChatSetMode(mode),
|
|
26981
27633
|
};
|
|
26982
27634
|
} catch { /* 被别的插件占用就只保留事件通道 */ }
|
|
26983
27635
|
return () => {
|
|
@@ -26986,6 +27638,7 @@ window.__ModuleLoader__.load({
|
|
|
26986
27638
|
window.removeEventListener('we-pet-continuous', onContinuousEvent);
|
|
26987
27639
|
window.removeEventListener('we-pet-speak-pause', onSpeakPauseEvent);
|
|
26988
27640
|
window.removeEventListener('we-pet-listen-pause', onListenPauseEvent);
|
|
27641
|
+
window.removeEventListener('we-pet-mode', onModeEvent);
|
|
26989
27642
|
document.removeEventListener('click', onDocumentClick, true);
|
|
26990
27643
|
document.removeEventListener('keydown', onKeyDown, true);
|
|
26991
27644
|
document.removeEventListener('visibilitychange', onVisibility);
|
|
@@ -26995,6 +27648,8 @@ window.__ModuleLoader__.load({
|
|
|
26995
27648
|
// v5 §6:深度思考的 3s 提示定时器也要随卸载清掉(否则会在 dispose 后改气泡)。
|
|
26996
27649
|
if (petChatDeepTimer != null) { clearTimeout(petChatDeepTimer); petChatDeepTimer = null; }
|
|
26997
27650
|
if (petSingTimer != null) { clearInterval(petSingTimer); petSingTimer = null; }
|
|
27651
|
+
if (petChatMindTimer != null) { clearInterval(petChatMindTimer); petChatMindTimer = null; }
|
|
27652
|
+
petChatStoryBarHide();
|
|
26998
27653
|
petChatWallpaperTimer = null;
|
|
26999
27654
|
petChatWorkTimer = null;
|
|
27000
27655
|
petChatGreetingTimer = null;
|