dsh-folia 1.1.0 → 1.3.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 +679 -15
- 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 +99 -2
- package/lib/pet-chat-mind.js +259 -0
- package/lib/pet-chat-proactive.js +2 -2
- package/lib/routes/personas.js +112 -1
- package/lib/routes/pet-chat.js +472 -18
- 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,67 @@ 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
|
+
"继续讲": "Continue the story",
|
|
787
|
+
"重讲": "Tell again",
|
|
788
|
+
"缩短": "Shorten",
|
|
789
|
+
"观察中": "Observing",
|
|
790
|
+
"这次没答上来": "No answer this time",
|
|
791
|
+
"讲故事": "Storytelling",
|
|
792
|
+
"树洞": "Tree hole",
|
|
793
|
+
"只观察": "Observe only",
|
|
794
|
+
// v1.2:对话与隐私 / 记忆 / 用户音色包
|
|
795
|
+
"对话与隐私": "Conversation & privacy",
|
|
796
|
+
"聊天=日常短答;讲故事=不按句数截断;树洞=先接情绪;只观察=不回答、只记不说。": "Chat = short replies; Storytelling = no sentence cut-off; Tree hole = feelings first; Observe only = no reply, just notes.",
|
|
797
|
+
"3 句": "3 sentences",
|
|
798
|
+
"8 句": "8 sentences",
|
|
799
|
+
"主动搭话(默认关)": "Proactive talk (off by default)",
|
|
800
|
+
"搭话间隔": "Proactive interval",
|
|
801
|
+
"15 分钟": "15 minutes",
|
|
802
|
+
"30 分钟": "30 minutes",
|
|
803
|
+
"60 分钟": "60 minutes",
|
|
804
|
+
"关着的时候它只在你主动说话时回应;打开后每小时最多主动 2 次。": "While off, it only responds when you speak first. When on, it initiates at most twice per hour.",
|
|
805
|
+
"勿扰时段": "Do-not-disturb window",
|
|
806
|
+
"屏幕感知(默认关)": "Screen awareness (off by default)",
|
|
807
|
+
"只读前台应用名与窗口标题(可选再加屏幕 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.",
|
|
808
|
+
"前台应用": "Foreground app",
|
|
809
|
+
"前台 + OCR": "Foreground + OCR",
|
|
810
|
+
"开启后它会知道你当前在用哪个应用、窗口标题是什么(前台+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.",
|
|
811
|
+
"确认开启": "Confirm and enable",
|
|
812
|
+
"当前:关(不读前台窗口,也不截屏)": "Now: off (no foreground reads, no screenshots)",
|
|
813
|
+
"当前:已开启(可随时关)": "Now: enabled (can be turned off anytime)",
|
|
814
|
+
"查看观察记录": "View observations",
|
|
815
|
+
"清空观察记录": "Clear observations",
|
|
816
|
+
"观察记录已清空": "Observations cleared",
|
|
817
|
+
"还没有观察记录": "No observations yet",
|
|
818
|
+
"查看记忆": "View memory",
|
|
819
|
+
"导出记忆": "Export memory",
|
|
820
|
+
"最近 {n} 条事件": "Last {n} events",
|
|
821
|
+
"按日期回滚": "Roll back by date",
|
|
822
|
+
"回滚": "Roll back",
|
|
823
|
+
"先填日期(YYYY-MM-DD)": "Fill in a date first (YYYY-MM-DD)",
|
|
824
|
+
"已回滚 {n} 条": "Rolled back {n} entries",
|
|
825
|
+
"导出失败": "Export failed",
|
|
826
|
+
"树洞求助热线": "Tree-hole helpline",
|
|
827
|
+
"用户音色包(角色语音只走导入)": "User voice packs (character voices are import-only)",
|
|
828
|
+
"本插件不携带角色/声优素材。导入前请确认你有权使用这段参考音频,并填写许可证与作者/来源。": "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.",
|
|
829
|
+
"未填许可证": "No license",
|
|
830
|
+
"音色包名字": "Voice pack name",
|
|
831
|
+
"许可证(如:本人录制,仅自用)": "License (e.g. self-recorded, personal use only)",
|
|
832
|
+
"作者 / 来源": "Author / source",
|
|
833
|
+
"参考音频对应的文字(可选)": "Text spoken in the reference audio (optional)",
|
|
834
|
+
"参考音频只存本机用户目录,不进 npm 包、不上传。": "The reference audio is stored only in your local user directory; it is never packaged or uploaded.",
|
|
835
|
+
"内置系统音效(4 个,MIT,本项目合成;不含角色语音)": "Built-in system sounds (4, MIT, synthesized in this project; no character voices)",
|
|
836
|
+
"在线音色暂不可用(429 限流):先用本地音色,稍后再试。": "Online voices are temporarily unavailable (HTTP 429). Local voices still work — try again later.",
|
|
837
|
+
"先填名字、许可证、作者/来源——没有授权的音色不要导入": "Fill in name, license and author/source first — do not import voices you have no rights to.",
|
|
838
|
+
"读不到这个音频文件": "Could not read this audio file",
|
|
839
|
+
"已导入:{n}": "Imported: {n}",
|
|
840
|
+
"导入失败": "Import failed",
|
|
841
|
+
"填 Key、起名字、选音色;语音长度、主动搭话、屏幕感知都在「对话与隐私」里,默认全关。": "Enter the key, name and voice; answer length, proactive talk and screen awareness live under Conversation & privacy, all off by default.",
|
|
842
|
+
"⚙ 对话与隐私 / 朗读 / 工作能力": "⚙ Conversation & privacy / Speech / Capabilities",
|
|
843
|
+
"收起设置": "Collapse settings",
|
|
844
|
+
"不用先选模式:说「讲个故事」就直接讲,说「今天好累」就先共情;下一轮自动回到聊天。": "No mode to pick: say 'tell me a story' and it starts; say 'I'm exhausted today' and it listens first. The next turn returns to chat automatically.",
|
|
784
845
|
// pre.64:大脑 v2(壁纸动作的客户端执行反馈)
|
|
785
846
|
"正在换壁纸…": "Switching wallpaper…",
|
|
786
847
|
"没找到叫「{name}」的壁纸": "No wallpaper named '{name}' was found",
|
|
@@ -8614,6 +8675,16 @@ window.__ModuleLoader__.load({
|
|
|
8614
8675
|
voice: { name: '', muted: false },
|
|
8615
8676
|
// 唤醒:点一下默认开;叫名字默认关(S6 才实现,先在设置里留位)
|
|
8616
8677
|
wake: { click: true, name: false, keyword: '' },
|
|
8678
|
+
// v1.3:不再有“会话模式”。旧字段保留兼容(读档时强制 auto,运行时按每轮文本判定)。
|
|
8679
|
+
conversationMode: 'auto',
|
|
8680
|
+
// v1.2:语音回答长度(0 = 不限;默认 8 句 —— 旧版写死 3 句,讲故事被截断的根因)。
|
|
8681
|
+
voiceLength: 8,
|
|
8682
|
+
// v1.2:主动思维(默认关;15/30/60 分钟才开)。勿扰时段跨零点也支持。
|
|
8683
|
+
proactive: { enabled: false, intervalMin: 15, quietFrom: '23:00', quietTo: '08:00' },
|
|
8684
|
+
// v1.2:屏幕感知(默认关;app = 只读前台应用/标题,ocr = 再加屏幕 OCR,需二次确认)。
|
|
8685
|
+
screen: { mode: 'off', confirmed: false },
|
|
8686
|
+
// v1.2:树洞安全提示里的求助热线(配置化;不写死成某一家的号码)。
|
|
8687
|
+
treehole: { hotline: '12356' },
|
|
8617
8688
|
// 对话记忆默认开启且**不暴露开关**(追加决定 1):能力常开,用户只能在右键里查看/清空
|
|
8618
8689
|
},
|
|
8619
8690
|
};
|
|
@@ -9330,6 +9401,19 @@ window.__ModuleLoader__.load({
|
|
|
9330
9401
|
const PET_CHAT_API_KEY_MAX = 400;
|
|
9331
9402
|
const PET_CHAT_MODEL_MAX = 120;
|
|
9332
9403
|
const PET_CHAT_PERSONA_MAX = 200;
|
|
9404
|
+
/** v1.3:会话策略改为**每轮意图判定**;conversationMode 只保留旧字段兼容,运行时忽略。 */
|
|
9405
|
+
const PET_CHAT_CONVERSATION_MODES = Object.freeze(['auto', 'chat', 'story', 'treehole', 'observe']);
|
|
9406
|
+
/** 语音回答长度:0 = 不限;默认 8 句(v1.2 从 3 句改上来的)。 */
|
|
9407
|
+
const PET_CHAT_VOICE_LENGTHS = Object.freeze([0, 3, 8]);
|
|
9408
|
+
/** 主动搭话间隔(分钟):0 = 关。默认关。 */
|
|
9409
|
+
const PET_CHAT_PROACTIVE_INTERVALS = Object.freeze([0, 15, 30, 60]);
|
|
9410
|
+
/** 屏幕感知:off / app(前台应用)/ ocr(前台 + 屏幕 OCR)。默认 off。 */
|
|
9411
|
+
const PET_CHAT_SCREEN_MODES = Object.freeze(['off', 'app', 'ocr']);
|
|
9412
|
+
const PET_CHAT_HHMM = /^([01]\d|2[0-3]):[0-5]\d$/;
|
|
9413
|
+
const petChatClock = (v, fallback) => {
|
|
9414
|
+
const text = typeof v === 'string' ? v.trim().slice(0, 5) : '';
|
|
9415
|
+
return PET_CHAT_HHMM.test(text) ? text : fallback;
|
|
9416
|
+
};
|
|
9333
9417
|
|
|
9334
9418
|
const petChatStr = (v, max) => (typeof v === 'string' ? v.slice(0, max) : '');
|
|
9335
9419
|
const petChatFloat = (v, lo, hi, fallback) => {
|
|
@@ -9372,6 +9456,9 @@ window.__ModuleLoader__.load({
|
|
|
9372
9456
|
const src = raw && typeof raw === 'object' && !Array.isArray(raw) ? raw : {};
|
|
9373
9457
|
const persona = src.persona && typeof src.persona === 'object' && !Array.isArray(src.persona) ? src.persona : {};
|
|
9374
9458
|
const wake = src.wake && typeof src.wake === 'object' && !Array.isArray(src.wake) ? src.wake : {};
|
|
9459
|
+
const proactive = src.proactive && typeof src.proactive === 'object' && !Array.isArray(src.proactive) ? src.proactive : {};
|
|
9460
|
+
const screen = src.screen && typeof src.screen === 'object' && !Array.isArray(src.screen) ? src.screen : {};
|
|
9461
|
+
const treehole = src.treehole && typeof src.treehole === 'object' && !Array.isArray(src.treehole) ? src.treehole : {};
|
|
9375
9462
|
const baseUrl = petChatStr(src.baseUrl, PET_CHAT_BASE_URL_MAX).trim();
|
|
9376
9463
|
return {
|
|
9377
9464
|
enabled: src.enabled === true,
|
|
@@ -9389,6 +9476,25 @@ window.__ModuleLoader__.load({
|
|
|
9389
9476
|
name: wake.name === true,
|
|
9390
9477
|
keyword: petChatStr(wake.keyword, 40).trim(),
|
|
9391
9478
|
},
|
|
9479
|
+
// v1.3:conversationMode 只保留字段兼容;**一律回落 auto**(旧档里的 story/treehole 不再生效)。
|
|
9480
|
+
conversationMode: 'auto',
|
|
9481
|
+
voiceLength: PET_CHAT_VOICE_LENGTHS.includes(Number(src.voiceLength)) ? Number(src.voiceLength) : def.voiceLength,
|
|
9482
|
+
proactive: {
|
|
9483
|
+
enabled: proactive.enabled === true,
|
|
9484
|
+
intervalMin: PET_CHAT_PROACTIVE_INTERVALS.includes(Number(proactive.intervalMin))
|
|
9485
|
+
? Number(proactive.intervalMin) : def.proactive.intervalMin,
|
|
9486
|
+
quietFrom: petChatClock(proactive.quietFrom, def.proactive.quietFrom),
|
|
9487
|
+
quietTo: petChatClock(proactive.quietTo, def.proactive.quietTo),
|
|
9488
|
+
},
|
|
9489
|
+
screen: {
|
|
9490
|
+
mode: PET_CHAT_SCREEN_MODES.includes(screen.mode) ? screen.mode : def.screen.mode,
|
|
9491
|
+
// 二次确认是**一次性**授权:只有旧值为 confirm 过且 mode 仍非 off 才算数;
|
|
9492
|
+
// 单独把 confirmed 置 true 但没有 mode 也不生效(读的时候按 mode 判定,见路由)。
|
|
9493
|
+
confirmed: screen.confirmed === true,
|
|
9494
|
+
},
|
|
9495
|
+
treehole: {
|
|
9496
|
+
hotline: petChatStr(treehole.hotline, 40).trim() || def.treehole.hotline,
|
|
9497
|
+
},
|
|
9392
9498
|
// 记忆常开:设置里没有这个开关(追加决定 1),旧档里的 false 也不再尊重
|
|
9393
9499
|
memoryEnabled: true,
|
|
9394
9500
|
};
|
|
@@ -20838,6 +20944,8 @@ window.__ModuleLoader__.load({
|
|
|
20838
20944
|
const currentItem = builtin.items.concat(edge.items, providers.items).find((item) => item.id === currentId);
|
|
20839
20945
|
const edgeByLang = {};
|
|
20840
20946
|
for (const item of edge.items) {
|
|
20947
|
+
// 用户口径:声音里不可用的不要出现(429/不可用从主列表隐藏,只留一条提示)
|
|
20948
|
+
if (item.status === 'rate-limited' || item.status === 'unavailable') continue;
|
|
20841
20949
|
const key = item.langGroup || '其他';
|
|
20842
20950
|
if (!edgeByLang[key]) edgeByLang[key] = [];
|
|
20843
20951
|
edgeByLang[key].push(item);
|
|
@@ -20896,7 +21004,7 @@ window.__ModuleLoader__.load({
|
|
|
20896
21004
|
'免费在线 · Edge', personaTag('可能限流', 'warn')),
|
|
20897
21005
|
voiceCatalog && voiceCatalog.edgeRateLimited
|
|
20898
21006
|
? React.createElement('div', { className: 'we-picker__hint', style: { color: '#fcd34d' } },
|
|
20899
|
-
`在线音色被限流(429
|
|
21007
|
+
`在线音色被限流(429):不可用项已隐藏;可先用内置音色,稍后自动恢复。`)
|
|
20900
21008
|
: null,
|
|
20901
21009
|
Object.keys(edgeByLang).length
|
|
20902
21010
|
? Object.keys(edgeByLang).map((lang) => React.createElement('div', { key: 'pick-edge-' + lang },
|
|
@@ -21112,6 +21220,12 @@ window.__ModuleLoader__.load({
|
|
|
21112
21220
|
ownerName: '',
|
|
21113
21221
|
// v0.2:朗读 = voice.muted 取反;音色 = voice.name;SAPI = voice.sapiEnabled(默认 false)。
|
|
21114
21222
|
voice: { name: '', muted: false, rate: 0, sapiEnabled: false, enabledEngine: 'edge', continuous: true, listenPaused: false },
|
|
21223
|
+
// v1.2:会话模式 / 语音长度 / 主动思维 / 屏幕感知 / 树洞热线(默认全关高风险项)
|
|
21224
|
+
conversationMode: 'chat',
|
|
21225
|
+
voiceLength: 8,
|
|
21226
|
+
proactive: { enabled: false, intervalMin: 15, quietFrom: '23:00', quietTo: '08:00' },
|
|
21227
|
+
screen: { mode: 'off', confirmed: false },
|
|
21228
|
+
treehole: { hotline: '12356' },
|
|
21115
21229
|
};
|
|
21116
21230
|
|
|
21117
21231
|
/** apiJson 的返回是 { ok, status, data },而 /pet-chat/* 的 data 里还套一层 { ok, data }。 */
|
|
@@ -21279,15 +21393,21 @@ window.__ModuleLoader__.load({
|
|
|
21279
21393
|
}, rows);
|
|
21280
21394
|
}
|
|
21281
21395
|
|
|
21282
|
-
/**
|
|
21396
|
+
/** 设置页:四分页 + 音色库 + 一键启用。 */
|
|
21283
21397
|
function PetChatSettings() {
|
|
21398
|
+
// v1.3:入口按钮可以指定初始页签;**函数签名保持无参**(构建 marker 依赖它)。
|
|
21399
|
+
const initialProps = arguments[0] && typeof arguments[0] === 'object' ? arguments[0] : {};
|
|
21400
|
+
const initialTab = ['assistant', 'behavior', 'voice', 'work'].includes(String(initialProps.initialTab || ''))
|
|
21401
|
+
? String(initialProps.initialTab) : 'assistant';
|
|
21284
21402
|
const [draft, setDraft] = React.useState(CHAT_DEFAULTS);
|
|
21285
21403
|
const [status, setStatus] = React.useState({ ok: null, text: '' });
|
|
21286
21404
|
const [note, setNote] = React.useState(null);
|
|
21287
21405
|
const [busy, setBusy] = React.useState(false);
|
|
21288
|
-
const [tab, setTab] = React.useState(
|
|
21406
|
+
const [tab, setTab] = React.useState(initialTab);
|
|
21289
21407
|
const [workPlugins, setWorkPlugins] = React.useState(null);
|
|
21290
21408
|
const [voices, setVoices] = React.useState(null);
|
|
21409
|
+
/** v1.2:Edge 429 等“在线音色暂时不可用”的提示(列表里不再堆灰项)。 */
|
|
21410
|
+
const [voiceNotice, setVoiceNotice] = React.useState('');
|
|
21291
21411
|
const [voiceMeta, setVoiceMeta] = React.useState({});
|
|
21292
21412
|
const [voiceCfg, setVoiceCfg] = React.useState({ sapiEnabled: false, enabledEngine: 'edge', continuous: true, listenPaused: false });
|
|
21293
21413
|
const [setupBusy, setSetupBusy] = React.useState(false);
|
|
@@ -21299,6 +21419,16 @@ window.__ModuleLoader__.load({
|
|
|
21299
21419
|
const [enableBusy, setEnableBusy] = React.useState('');
|
|
21300
21420
|
const [enableNote, setEnableNote] = React.useState(null);
|
|
21301
21421
|
const [detailOpen, setDetailOpen] = React.useState({});
|
|
21422
|
+
// v1.2:屏幕感知二次确认 / 观察记录 / 记忆回滚 / 用户音色包
|
|
21423
|
+
const [screenArmed, setScreenArmed] = React.useState('');
|
|
21424
|
+
const [observeList, setObserveList] = React.useState(null);
|
|
21425
|
+
const [memoryInfo, setMemoryInfo] = React.useState(null);
|
|
21426
|
+
const [memoryNote, setMemoryNote] = React.useState(null);
|
|
21427
|
+
const [rollbackDate, setRollbackDate] = React.useState('');
|
|
21428
|
+
const [userPacks, setUserPacks] = React.useState([]);
|
|
21429
|
+
const [systemSounds, setSystemSounds] = React.useState([]);
|
|
21430
|
+
const [packForm, setPackForm] = React.useState({ name: '', license: '', author: '', refText: '', engine: 'gpt-sovits' });
|
|
21431
|
+
const [packNote, setPackNote] = React.useState(null);
|
|
21302
21432
|
const [providers, setProviders] = React.useState(null);
|
|
21303
21433
|
const [providerBusy, setProviderBusy] = React.useState(false);
|
|
21304
21434
|
const [providerNote, setProviderNote] = React.useState(null);
|
|
@@ -21365,6 +21495,9 @@ window.__ModuleLoader__.load({
|
|
|
21365
21495
|
const doc = unwrapPetChat(resp);
|
|
21366
21496
|
const items = (doc && Array.isArray(doc.voices) ? doc.voices : []).filter((v) => v && v.usable === true);
|
|
21367
21497
|
setVoices(items);
|
|
21498
|
+
setVoiceNotice(doc && doc.rateLimited === true
|
|
21499
|
+
? weT('在线音色暂不可用(429 限流):先用本地音色,稍后再试。')
|
|
21500
|
+
: '');
|
|
21368
21501
|
setVoiceMeta((doc && doc.meta) || {});
|
|
21369
21502
|
const engine = ['edge', 'piper', 'sapi'].includes(String(doc && doc.enabledEngine || '')) ? doc.enabledEngine : 'edge';
|
|
21370
21503
|
setEnabledEngine(engine);
|
|
@@ -21385,8 +21518,106 @@ window.__ModuleLoader__.load({
|
|
|
21385
21518
|
}
|
|
21386
21519
|
}, []);
|
|
21387
21520
|
|
|
21388
|
-
|
|
21389
|
-
|
|
21521
|
+
/* ── v1.2:观察记录 / 记忆 / 用户音色包(设置页直接查看与清理)─────────── */
|
|
21522
|
+
|
|
21523
|
+
const loadObserveRecords = React.useCallback(async () => {
|
|
21524
|
+
const resp = await apiJson('/pet-chat/observe/records?limit=20', { parse: 'always' }).catch(() => null);
|
|
21525
|
+
const doc = unwrapPetChat(resp);
|
|
21526
|
+
setObserveList(Array.isArray(doc.items) ? doc.items : []);
|
|
21527
|
+
}, []);
|
|
21528
|
+
|
|
21529
|
+
const clearObserveRecords = async () => {
|
|
21530
|
+
await apiFetch('/pet-chat/observe/records', { method: 'DELETE' }).catch(() => null);
|
|
21531
|
+
setObserveList([]);
|
|
21532
|
+
setMemoryNote({ ok: true, text: weT('观察记录已清空') });
|
|
21533
|
+
};
|
|
21534
|
+
|
|
21535
|
+
const loadMemoryInfo = React.useCallback(async () => {
|
|
21536
|
+
const resp = await apiJson('/pet-chat/memory', { parse: 'always' }).catch(() => null);
|
|
21537
|
+
const doc = unwrapPetChat(resp);
|
|
21538
|
+
setMemoryInfo(doc && doc.memory ? { personaId: doc.personaId, events: doc.memory.events || [], line: doc.line || '' } : null);
|
|
21539
|
+
}, []);
|
|
21540
|
+
|
|
21541
|
+
const memoryRollback = async () => {
|
|
21542
|
+
if (!memoryInfo || !memoryInfo.personaId || !/^\d{4}-\d{2}-\d{2}$/.test(rollbackDate)) {
|
|
21543
|
+
setMemoryNote({ ok: false, text: weT('先填日期(YYYY-MM-DD)') });
|
|
21544
|
+
return;
|
|
21545
|
+
}
|
|
21546
|
+
const resp = await apiFetch(`/pet-chat/personas/${encodeURIComponent(memoryInfo.personaId)}/memory/by-date?date=${encodeURIComponent(rollbackDate)}`, {
|
|
21547
|
+
method: 'DELETE',
|
|
21548
|
+
}).catch(() => null);
|
|
21549
|
+
const doc = (resp && resp.data) || {};
|
|
21550
|
+
setMemoryNote({ ok: doc.ok === true, text: doc.ok === true ? weT('已回滚 {n} 条', { n: doc.deleted || 0 }) : weT('回滚失败') });
|
|
21551
|
+
await loadMemoryInfo();
|
|
21552
|
+
};
|
|
21553
|
+
|
|
21554
|
+
const memoryExport = async () => {
|
|
21555
|
+
if (!memoryInfo || !memoryInfo.personaId) return;
|
|
21556
|
+
const resp = await apiFetch(`/pet-chat/personas/${encodeURIComponent(memoryInfo.personaId)}/memory/export`, { parse: false }).catch(() => null);
|
|
21557
|
+
try {
|
|
21558
|
+
const blob = await resp.response.blob();
|
|
21559
|
+
const url = URL.createObjectURL(blob);
|
|
21560
|
+
const a = document.createElement('a');
|
|
21561
|
+
a.href = url;
|
|
21562
|
+
a.download = memoryInfo.personaId + '-memory.json';
|
|
21563
|
+
a.click();
|
|
21564
|
+
setTimeout(() => URL.revokeObjectURL(url), 3000);
|
|
21565
|
+
} catch { setMemoryNote({ ok: false, text: weT('导出失败') }); }
|
|
21566
|
+
};
|
|
21567
|
+
|
|
21568
|
+
const loadUserPacks = React.useCallback(async () => {
|
|
21569
|
+
const resp = await apiJson('/pet-chat/voice/user-packs', { parse: 'always' }).catch(() => null);
|
|
21570
|
+
const doc = unwrapPetChat(resp);
|
|
21571
|
+
setUserPacks(Array.isArray(doc.userPacks) ? doc.userPacks : []);
|
|
21572
|
+
}, []);
|
|
21573
|
+
React.useEffect(() => {
|
|
21574
|
+
if (tab === 'voice') void loadUserPacks();
|
|
21575
|
+
}, [tab, loadUserPacks]);
|
|
21576
|
+
React.useEffect(() => {
|
|
21577
|
+
if (tab !== 'voice') return;
|
|
21578
|
+
void apiJson('/pet-chat/system-sounds', { parse: 'always' }).then((resp) => {
|
|
21579
|
+
const doc = unwrapPetChat(resp);
|
|
21580
|
+
setSystemSounds(Array.isArray(doc.sounds) ? doc.sounds : []);
|
|
21581
|
+
}).catch(() => {});
|
|
21582
|
+
}, [tab]);
|
|
21583
|
+
|
|
21584
|
+
const adminVoicePacks = async () => {
|
|
21585
|
+
const resp = await apiJson('/pet-chat/voice/user-packs', { parse: 'always' }).catch(() => null);
|
|
21586
|
+
const doc = unwrapPetChat(resp);
|
|
21587
|
+
setUserPacks(Array.isArray(doc.userPacks) ? doc.userPacks : []);
|
|
21588
|
+
return doc;
|
|
21589
|
+
};
|
|
21590
|
+
|
|
21591
|
+
const importUserPack = async (file) => {
|
|
21592
|
+
if (!file) return;
|
|
21593
|
+
if (!packForm.name || !packForm.license || !packForm.author) {
|
|
21594
|
+
setPackNote({ ok: false, text: weT('先填名字、许可证、作者/来源——没有授权的音色不要导入') });
|
|
21595
|
+
return;
|
|
21596
|
+
}
|
|
21597
|
+
const base64 = await new Promise((resolve) => {
|
|
21598
|
+
const reader = new FileReader();
|
|
21599
|
+
reader.onload = () => resolve(String(reader.result || ''));
|
|
21600
|
+
reader.onerror = () => resolve('');
|
|
21601
|
+
reader.readAsDataURL(file);
|
|
21602
|
+
});
|
|
21603
|
+
if (!base64) { setPackNote({ ok: false, text: weT('读不到这个音频文件') }); return; }
|
|
21604
|
+
const resp = await apiPostJson('/pet-chat/voice/user-packs/import', { ...packForm, audioBase64: base64 }, { parse: 'always' }).catch(() => null);
|
|
21605
|
+
const doc = unwrapPetChat(resp);
|
|
21606
|
+
if (doc && doc.ok) {
|
|
21607
|
+
setPackNote({ ok: true, text: weT('已导入:{n}', { n: doc.pack && doc.pack.name ? doc.pack.name : packForm.name }) });
|
|
21608
|
+
setPackForm({ name: '', license: '', author: '', refText: '', engine: 'gpt-sovits' });
|
|
21609
|
+
await adminVoicePacks();
|
|
21610
|
+
} else {
|
|
21611
|
+
setPackNote({ ok: false, text: (doc && doc.hint) || weT('导入失败') });
|
|
21612
|
+
}
|
|
21613
|
+
};
|
|
21614
|
+
|
|
21615
|
+
const removeUserPack = async (id) => {
|
|
21616
|
+
await apiPostJson('/pet-chat/voice/user-packs/remove', { id }, { parse: 'always' }).catch(() => null);
|
|
21617
|
+
await adminVoicePacks();
|
|
21618
|
+
};
|
|
21619
|
+
|
|
21620
|
+
const loadFfmpeg = React.useCallback(async () => { const resp = await apiJson('/pet-chat/voice/diagnose?light=1', { parse: 'always' }).catch(() => null);
|
|
21390
21621
|
const doc = unwrapPetChat(resp);
|
|
21391
21622
|
const st = doc && doc.steps && doc.steps.ffmpeg;
|
|
21392
21623
|
if (st && st.phase) setFfmpeg(st);
|
|
@@ -21730,10 +21961,11 @@ window.__ModuleLoader__.load({
|
|
|
21730
21961
|
: null);
|
|
21731
21962
|
child.push(React.createElement('div', { key: 'title', style: { fontWeight: 600, margin: '14px 0 4px', fontSize: '13px' } }, weT('智能大肥鱼')));
|
|
21732
21963
|
child.push(React.createElement('div', { key: 'hint', className: 'we-picker__hint', style: { margin: '0 0 6px' } },
|
|
21733
|
-
weT('填 Key
|
|
21964
|
+
weT('填 Key、起名字、选音色;语音长度、主动搭话、屏幕感知都在「对话与隐私」里,默认全关。')));
|
|
21734
21965
|
|
|
21735
21966
|
const tabs = [
|
|
21736
21967
|
['assistant', weT('助手')],
|
|
21968
|
+
['behavior', weT('对话与隐私')],
|
|
21737
21969
|
['voice', weT('朗读与音色')],
|
|
21738
21970
|
['work', weT('工作能力')],
|
|
21739
21971
|
];
|
|
@@ -21777,6 +22009,124 @@ window.__ModuleLoader__.load({
|
|
|
21777
22009
|
child.push(React.createElement(MicTestBlock, { key: 'mic-test' }));
|
|
21778
22010
|
}
|
|
21779
22011
|
|
|
22012
|
+
if (tab === 'behavior') {
|
|
22013
|
+
const pro = Object.assign({}, CHAT_DEFAULTS.proactive, draft.proactive || {});
|
|
22014
|
+
const screen = Object.assign({}, CHAT_DEFAULTS.screen, draft.screen || {});
|
|
22015
|
+
const behaviorPage = [];
|
|
22016
|
+
const selectOf = (key, value, options, onChange, disabled) => React.createElement('select', {
|
|
22017
|
+
key, value, disabled: busy || disabled === true,
|
|
22018
|
+
onChange: (e) => onChange(e.target.value),
|
|
22019
|
+
style: { minWidth: '128px' },
|
|
22020
|
+
}, options.map(([val, label]) => React.createElement('option', { key: val, value: val }, label)));
|
|
22021
|
+
const toggle = (key, checked, onChange, label) => React.createElement('label', {
|
|
22022
|
+
key, style: { display: 'flex', gap: '6px', alignItems: 'center', fontSize: '12px', margin: '4px 0' },
|
|
22023
|
+
}, React.createElement('input', {
|
|
22024
|
+
type: 'checkbox', checked, disabled: busy, onChange: (e) => onChange(e.target.checked),
|
|
22025
|
+
}), weT(label));
|
|
22026
|
+
|
|
22027
|
+
// v1.3:不再有「对话模式」下拉 —— 讲故事/共情由每一句话自动判定。
|
|
22028
|
+
behaviorPage.push(React.createElement('div', { key: 'intent-hint', className: 'we-picker__hint', style: { margin: '0 0 6px' } },
|
|
22029
|
+
weT('不用先选模式:说「讲个故事」就直接讲,说「今天好累」就先共情;下一轮自动回到聊天。')));
|
|
22030
|
+
|
|
22031
|
+
behaviorPage.push(row('voice-length', '语音回答长度', selectOf('vlen', String(draft.voiceLength), [
|
|
22032
|
+
['3', weT('3 句')], ['8', weT('8 句')], ['0', weT('不限')],
|
|
22033
|
+
], (value) => update({ voiceLength: Number(value) }))));
|
|
22034
|
+
|
|
22035
|
+
behaviorPage.push(toggle('pro-enabled', pro.enabled === true, (checked) => update({
|
|
22036
|
+
proactive: Object.assign({}, pro, { enabled: checked, intervalMin: checked && !pro.intervalMin ? 15 : pro.intervalMin }),
|
|
22037
|
+
}), '主动搭话(默认关)'));
|
|
22038
|
+
behaviorPage.push(row('pro-interval', '搭话间隔', selectOf('pint', String(pro.intervalMin || 15), [
|
|
22039
|
+
['15', weT('15 分钟')], ['30', weT('30 分钟')], ['60', weT('60 分钟')],
|
|
22040
|
+
], (value) => update({ proactive: Object.assign({}, pro, { intervalMin: Number(value) }) }), pro.enabled !== true)));
|
|
22041
|
+
if (pro.enabled !== true) {
|
|
22042
|
+
behaviorPage.push(React.createElement('div', { key: 'pro-off', className: 'we-picker__hint', style: { margin: '0 0 6px' } },
|
|
22043
|
+
weT('关着的时候它只在你主动说话时回应;打开后每小时最多主动 2 次。')));
|
|
22044
|
+
}
|
|
22045
|
+
behaviorPage.push(row('quiet-from', '勿扰时段', React.createElement('div', { key: 'q', style: { display: 'flex', gap: '4px', alignItems: 'center' } },
|
|
22046
|
+
React.createElement('input', {
|
|
22047
|
+
type: 'time', value: pro.quietFrom, disabled: busy,
|
|
22048
|
+
onChange: (e) => update({ proactive: Object.assign({}, pro, { quietFrom: e.target.value }) }),
|
|
22049
|
+
}),
|
|
22050
|
+
React.createElement('span', null, '–'),
|
|
22051
|
+
React.createElement('input', {
|
|
22052
|
+
type: 'time', value: pro.quietTo, disabled: busy,
|
|
22053
|
+
onChange: (e) => update({ proactive: Object.assign({}, pro, { quietTo: e.target.value }) }),
|
|
22054
|
+
}))));
|
|
22055
|
+
|
|
22056
|
+
behaviorPage.push(React.createElement('div', { key: 'privacy-head', style: { marginTop: '12px', fontSize: '12px', fontWeight: 600 } },
|
|
22057
|
+
weT('屏幕感知(默认关)')));
|
|
22058
|
+
behaviorPage.push(React.createElement('div', { key: 'privacy-hint', className: 'we-picker__hint', style: { margin: '2px 0 6px' } },
|
|
22059
|
+
weT('只读前台应用名与窗口标题(可选再加屏幕 OCR);读不到别的 App 内部数据,绝不上传截图或 OCR 原文。')));
|
|
22060
|
+
behaviorPage.push(row('screen-mode', '屏幕感知', selectOf('screen', screen.mode, [
|
|
22061
|
+
['off', weT('关')], ['app', weT('前台应用')], ['ocr', weT('前台 + OCR')],
|
|
22062
|
+
], (value) => {
|
|
22063
|
+
if (value === 'off') {
|
|
22064
|
+
setScreenArmed('');
|
|
22065
|
+
update({ screen: { mode: 'off', confirmed: false } });
|
|
22066
|
+
} else {
|
|
22067
|
+
// 第一下只“上膛”,看说明再确认(不直接开)。
|
|
22068
|
+
setScreenArmed(value);
|
|
22069
|
+
}
|
|
22070
|
+
})));
|
|
22071
|
+
if (screenArmed) {
|
|
22072
|
+
behaviorPage.push(React.createElement('div', {
|
|
22073
|
+
key: 'screen-confirm', style: {
|
|
22074
|
+
border: '1px solid rgba(251,191,36,.45)', background: 'rgba(251,191,36,.08)',
|
|
22075
|
+
borderRadius: '8px', padding: '6px 8px', margin: '2px 0 6px', fontSize: '11px',
|
|
22076
|
+
},
|
|
22077
|
+
},
|
|
22078
|
+
React.createElement('div', { style: { marginBottom: '4px' } },
|
|
22079
|
+
weT('开启后它会知道你当前在用哪个应用、窗口标题是什么(前台+OCR 还会定时读取屏幕文字)。所有记录只存在本机记忆里,可随时查看、删除。')),
|
|
22080
|
+
React.createElement('div', { key: 'btn-row', style: { display: 'flex', gap: '6px' } },
|
|
22081
|
+
React.createElement('button', {
|
|
22082
|
+
type: 'button', className: 'we-picker__btn', disabled: busy,
|
|
22083
|
+
onClick: () => { update({ screen: { mode: screenArmed, confirmed: true } }); setScreenArmed(''); },
|
|
22084
|
+
}, weT('确认开启')),
|
|
22085
|
+
React.createElement('button', {
|
|
22086
|
+
type: 'button', className: 'we-picker__btn', disabled: busy,
|
|
22087
|
+
onClick: () => setScreenArmed(''),
|
|
22088
|
+
}, weT('取消')))));
|
|
22089
|
+
}
|
|
22090
|
+
behaviorPage.push(React.createElement('div', { key: 'status-line', className: 'we-picker__hint', style: { margin: '0 0 4px' } },
|
|
22091
|
+
screen.mode === 'off' ? weT('当前:关(不读前台窗口,也不截屏)') : weT('当前:已开启(可随时关)')));
|
|
22092
|
+
behaviorPage.push(React.createElement('div', { key: 'observe-row', style: { display: 'flex', gap: '6px', flexWrap: 'wrap', margin: '4px 0' } },
|
|
22093
|
+
React.createElement('button', { type: 'button', className: 'we-picker__btn', onClick: () => { void loadObserveRecords(); } }, weT('查看观察记录')),
|
|
22094
|
+
React.createElement('button', { type: 'button', className: 'we-picker__btn', onClick: () => { void clearObserveRecords(); } }, weT('清空观察记录'))));
|
|
22095
|
+
if (observeList !== null) {
|
|
22096
|
+
behaviorPage.push(React.createElement('div', { key: 'observe-list', className: 'we-picker__hint', style: { margin: '0 0 6px' } },
|
|
22097
|
+
observeList.length
|
|
22098
|
+
? observeList.slice(0, 8).map((item) => React.createElement('div', { key: item.id }, '· ' + String(item.text || '').slice(0, 80)))
|
|
22099
|
+
: weT('还没有观察记录')));
|
|
22100
|
+
}
|
|
22101
|
+
|
|
22102
|
+
behaviorPage.push(React.createElement('div', { key: 'memory-head', style: { marginTop: '12px', fontSize: '12px', fontWeight: 600 } },
|
|
22103
|
+
weT('记忆')));
|
|
22104
|
+
behaviorPage.push(React.createElement('div', { key: 'memory-row', style: { display: 'flex', gap: '6px', flexWrap: 'wrap', margin: '4px 0' } },
|
|
22105
|
+
React.createElement('button', { type: 'button', className: 'we-picker__btn', onClick: () => { void loadMemoryInfo(); } }, weT('查看记忆')),
|
|
22106
|
+
React.createElement('button', { type: 'button', className: 'we-picker__btn', onClick: () => { void memoryExport(); } }, weT('导出记忆'))));
|
|
22107
|
+
if (memoryInfo) {
|
|
22108
|
+
behaviorPage.push(React.createElement('div', { key: 'memory-info', className: 'we-picker__hint', style: { margin: '0 0 6px' } },
|
|
22109
|
+
weT('最近 {n} 条事件', { n: (memoryInfo.events || []).length })));
|
|
22110
|
+
}
|
|
22111
|
+
behaviorPage.push(row('memory-rollback', '按日期回滚', React.createElement('div', { key: 'r', style: { display: 'flex', gap: '4px' } },
|
|
22112
|
+
React.createElement('input', {
|
|
22113
|
+
type: 'date', value: rollbackDate, disabled: busy,
|
|
22114
|
+
onChange: (e) => setRollbackDate(e.target.value),
|
|
22115
|
+
}),
|
|
22116
|
+
React.createElement('button', { type: 'button', className: 'we-picker__btn', disabled: busy, onClick: () => { void memoryRollback(); } }, weT('回滚')))));
|
|
22117
|
+
if (memoryNote) {
|
|
22118
|
+
behaviorPage.push(React.createElement('div', {
|
|
22119
|
+
key: 'memory-note', className: 'we-picker__hint',
|
|
22120
|
+
style: { margin: '0 0 6px', color: memoryNote.ok ? '#4ade80' : '#f87171' },
|
|
22121
|
+
}, memoryNote.text));
|
|
22122
|
+
}
|
|
22123
|
+
behaviorPage.push(row('hotline', '树洞求助热线', React.createElement('input', {
|
|
22124
|
+
type: 'text', value: (draft.treehole && draft.treehole.hotline) || '12356', disabled: busy,
|
|
22125
|
+
onChange: (e) => update({ treehole: { hotline: e.target.value } }),
|
|
22126
|
+
})));
|
|
22127
|
+
child.push(React.createElement('div', { key: 'behavior-page' }, behaviorPage));
|
|
22128
|
+
}
|
|
22129
|
+
|
|
21780
22130
|
if (tab === 'voice') {
|
|
21781
22131
|
const voicePage = [];
|
|
21782
22132
|
voicePage.push(React.createElement('div', {
|
|
@@ -21841,6 +22191,12 @@ window.__ModuleLoader__.load({
|
|
|
21841
22191
|
voicePage.push(React.createElement('div', {
|
|
21842
22192
|
key: 'local-head', style: { marginTop: '10px', fontSize: '12px', fontWeight: 600 },
|
|
21843
22193
|
}, weT('音色(只列本机真实可用)')));
|
|
22194
|
+
if (voiceNotice) {
|
|
22195
|
+
voicePage.push(React.createElement('div', {
|
|
22196
|
+
key: 'voice-notice', className: 'we-picker__hint',
|
|
22197
|
+
style: { margin: '2px 0', color: '#fbbf24' },
|
|
22198
|
+
}, voiceNotice));
|
|
22199
|
+
}
|
|
21844
22200
|
if (selectableVoices.length) {
|
|
21845
22201
|
const groups = [];
|
|
21846
22202
|
for (const engine of ['edge', 'piper', 'sapi', 'openai', 'azure', 'elevenlabs']) {
|
|
@@ -22074,6 +22430,57 @@ window.__ModuleLoader__.load({
|
|
|
22074
22430
|
...detailProps,
|
|
22075
22431
|
}));
|
|
22076
22432
|
}
|
|
22433
|
+
// v1.2:角色音色只走「用户下载/导入」;内置只有 4 个系统音效。
|
|
22434
|
+
voicePage.push(React.createElement('div', {
|
|
22435
|
+
key: 'pack-head', style: { marginTop: '14px', fontSize: '12px', fontWeight: 600 },
|
|
22436
|
+
}, weT('用户音色包(角色语音只走导入)')));
|
|
22437
|
+
voicePage.push(React.createElement('div', {
|
|
22438
|
+
key: 'pack-policy', className: 'we-picker__hint', style: { margin: '2px 0 6px' },
|
|
22439
|
+
}, weT('本插件不携带角色/声优素材。导入前请确认你有权使用这段参考音频,并填写许可证与作者/来源。')));
|
|
22440
|
+
if (userPacks.length) {
|
|
22441
|
+
voicePage.push(React.createElement('div', { key: 'pack-list', style: { display: 'flex', flexDirection: 'column', gap: '3px', margin: '0 0 6px' } },
|
|
22442
|
+
userPacks.map((pack) => React.createElement('div', { key: pack.id, style: { display: 'flex', gap: '6px', alignItems: 'center', fontSize: '11px' } },
|
|
22443
|
+
React.createElement('span', { style: { flex: 1 } }, `${pack.name} · ${pack.engine} · ${pack.license || weT('未填许可证')}`),
|
|
22444
|
+
React.createElement('button', {
|
|
22445
|
+
type: 'button', className: 'we-picker__btn', onClick: () => { void removeUserPack(pack.id); },
|
|
22446
|
+
}, weT('删除'))))));
|
|
22447
|
+
}
|
|
22448
|
+
const packInput = (key, placeholder, value, onChange, type) => React.createElement('input', {
|
|
22449
|
+
key, type: type || 'text', value, placeholder, disabled: busy,
|
|
22450
|
+
onChange: (e) => onChange(e.target.value),
|
|
22451
|
+
style: { fontSize: '11px', padding: '2px 6px', minWidth: '0' },
|
|
22452
|
+
});
|
|
22453
|
+
voicePage.push(React.createElement('div', {
|
|
22454
|
+
key: 'pack-form', style: { display: 'flex', flexDirection: 'column', gap: '4px', margin: '0 0 6px' },
|
|
22455
|
+
},
|
|
22456
|
+
packInput('pname', weT('音色包名字'), packForm.name, (v) => setPackForm((prev) => ({ ...prev, name: v }))),
|
|
22457
|
+
packInput('plicense', weT('许可证(如:本人录制,仅自用)'), packForm.license, (v) => setPackForm((prev) => ({ ...prev, license: v }))),
|
|
22458
|
+
packInput('pauthor', weT('作者 / 来源'), packForm.author, (v) => setPackForm((prev) => ({ ...prev, author: v }))),
|
|
22459
|
+
packInput('pref', weT('参考音频对应的文字(可选)'), packForm.refText, (v) => setPackForm((prev) => ({ ...prev, refText: v }))),
|
|
22460
|
+
React.createElement('div', { key: 'import-row', style: { display: 'flex', gap: '6px', alignItems: 'center', flexWrap: 'wrap' } },
|
|
22461
|
+
React.createElement('input', {
|
|
22462
|
+
key: 'file', type: 'file', accept: 'audio/*',
|
|
22463
|
+
onChange: (e) => { const file = e.target.files && e.target.files[0]; void importUserPack(file); },
|
|
22464
|
+
}),
|
|
22465
|
+
React.createElement('span', { className: 'we-picker__hint', style: { margin: 0 } },
|
|
22466
|
+
weT('参考音频只存本机用户目录,不进 npm 包、不上传。')))));
|
|
22467
|
+
if (packNote && packNote.text) {
|
|
22468
|
+
voicePage.push(React.createElement('div', {
|
|
22469
|
+
key: 'pack-note', className: 'we-picker__hint',
|
|
22470
|
+
style: { margin: '0 0 6px', color: packNote.ok ? '#4ade80' : '#f87171' },
|
|
22471
|
+
}, packNote.text));
|
|
22472
|
+
}
|
|
22473
|
+
voicePage.push(React.createElement('div', { key: 'sound-head', className: 'we-picker__hint', style: { margin: '2px 0' } },
|
|
22474
|
+
weT('内置系统音效(4 个,MIT,本项目合成;不含角色语音)')));
|
|
22475
|
+
if (systemSounds.length) {
|
|
22476
|
+
voicePage.push(React.createElement('div', { key: 'sound-list', style: { display: 'flex', flexDirection: 'column', gap: '3px', margin: '0 0 6px' } },
|
|
22477
|
+
systemSounds.map((sound) => React.createElement('div', { key: sound.id, style: { display: 'flex', gap: '6px', alignItems: 'center', fontSize: '11px' } },
|
|
22478
|
+
React.createElement('span', null, `${sound.name} · ${sound.license || ''}`),
|
|
22479
|
+
React.createElement('audio', {
|
|
22480
|
+
controls: true, preload: 'none', style: { height: '22px' },
|
|
22481
|
+
src: apiUrl('/pet-chat/system-sounds/' + encodeURIComponent(sound.id) + '.wav'),
|
|
22482
|
+
})))));
|
|
22483
|
+
}
|
|
22077
22484
|
child.push(React.createElement('div', { key: 'voice-page' }, voicePage));
|
|
22078
22485
|
}
|
|
22079
22486
|
|
|
@@ -22161,13 +22568,36 @@ window.__ModuleLoader__.load({
|
|
|
22161
22568
|
}
|
|
22162
22569
|
|
|
22163
22570
|
/**
|
|
22164
|
-
* 「智能大肥鱼」一级设置页。只做版面装配:标题 +
|
|
22571
|
+
* 「智能大肥鱼」一级设置页。只做版面装配:标题 + 入口按钮 + 人设区。
|
|
22165
22572
|
* 设置导航的注册在 `src/client.js`(id=folia-assistant,order 502)。
|
|
22573
|
+
*
|
|
22574
|
+
* v1.3:**入口必须第一屏可见**。上一版只渲染 PersonaSection,PetChatSettings
|
|
22575
|
+
* 虽然存在却永远挂不上去(用户找不到「对话与隐私」)。
|
|
22166
22576
|
*/
|
|
22167
22577
|
function AssistantSection() {
|
|
22578
|
+
const [settingsOpen, setSettingsOpen] = React.useState(false);
|
|
22168
22579
|
return React.createElement('div', { className: 'we-assistant-section', style: { padding: '4px 2px' } },
|
|
22580
|
+
React.createElement('div', {
|
|
22581
|
+
style: { display: 'flex', alignItems: 'center', gap: '8px', flexWrap: 'wrap', marginBottom: '6px' },
|
|
22582
|
+
},
|
|
22169
22583
|
React.createElement('div', { style: { fontSize: '14px', fontWeight: 600 } }, weT('智能大肥鱼')),
|
|
22584
|
+
React.createElement('button', {
|
|
22585
|
+
type: 'button', className: 'we-picker__btn', id: 'we-assistant-settings-entry',
|
|
22586
|
+
style: { marginLeft: 'auto', fontSize: '12px' },
|
|
22587
|
+
onClick: () => setSettingsOpen((open) => !open),
|
|
22588
|
+
}, settingsOpen ? weT('收起设置') : weT('⚙ 对话与隐私 / 朗读 / 工作能力'))),
|
|
22170
22589
|
React.createElement(PersonaSection, null),
|
|
22590
|
+
settingsOpen
|
|
22591
|
+
? React.createElement('div', {
|
|
22592
|
+
key: 'assistant-settings',
|
|
22593
|
+
style: {
|
|
22594
|
+
marginTop: '10px', padding: '10px 10px 4px', borderRadius: '10px',
|
|
22595
|
+
border: '1px solid rgba(120,190,255,.28)', background: 'rgba(90,160,255,.05)',
|
|
22596
|
+
},
|
|
22597
|
+
},
|
|
22598
|
+
// v1.3:默认停在「对话与隐私」;四个页签在 PetChatSettings 内部切换,共用同一份草稿。
|
|
22599
|
+
React.createElement(PetChatSettings, { initialTab: 'behavior' }))
|
|
22600
|
+
: null,
|
|
22171
22601
|
);
|
|
22172
22602
|
}
|
|
22173
22603
|
|
|
@@ -25217,6 +25647,11 @@ window.__ModuleLoader__.load({
|
|
|
25217
25647
|
const PET_TTS_MAX_PIECES = 8;
|
|
25218
25648
|
/** 与宿主 `TTS_MAX_CHARS` 对齐的总上限。 */
|
|
25219
25649
|
const PET_TTS_MAX_CHARS = 240;
|
|
25650
|
+
/**
|
|
25651
|
+
* 句间静音(200–350ms,任务书 §11③):不靠标点让引擎停顿(那会被念成“逗号/句号”),
|
|
25652
|
+
* 而是由播放队列在两句之间插一段静音 —— 有停顿,但合成文本里已经没有标点。
|
|
25653
|
+
*/
|
|
25654
|
+
const PET_TTS_GAP_MS = 260;
|
|
25220
25655
|
|
|
25221
25656
|
/**
|
|
25222
25657
|
* 纯函数:把一段文字切成“适合一句一合成”的片段。
|
|
@@ -25439,6 +25874,11 @@ window.__ModuleLoader__.load({
|
|
|
25439
25874
|
onError(error);
|
|
25440
25875
|
break;
|
|
25441
25876
|
}
|
|
25877
|
+
// 句间 260ms 静音(任务书 §11③):合成文本已去标点,停顿只能由队列给。
|
|
25878
|
+
if (queue.length && queue[0].gen === gen) {
|
|
25879
|
+
await new Promise((resolve) => { setTimeout(resolve, PET_TTS_GAP_MS); });
|
|
25880
|
+
if (item.gen !== generation) break;
|
|
25881
|
+
}
|
|
25442
25882
|
}
|
|
25443
25883
|
} finally {
|
|
25444
25884
|
busy = false;
|
|
@@ -25484,13 +25924,23 @@ window.__ModuleLoader__.load({
|
|
|
25484
25924
|
if (disposed) return false;
|
|
25485
25925
|
const cfg = getVoice() || {};
|
|
25486
25926
|
if (cfg.muted === true) { onState('idle'); return false; }
|
|
25487
|
-
|
|
25927
|
+
let pieces = petTtsSplit(text);
|
|
25488
25928
|
if (!pieces.length) return false;
|
|
25489
25929
|
if (!AudioCtor) {
|
|
25490
25930
|
onError({ code: 'tts-no-audio', hint: '这个环境不能播放声音' });
|
|
25491
25931
|
return false;
|
|
25492
25932
|
}
|
|
25493
25933
|
const speechOpts = speech || {};
|
|
25934
|
+
/**
|
|
25935
|
+
* v1.2 故事模式:`group: 2|3` 把相邻 2–3 句合成**一段**再请求宿主
|
|
25936
|
+
* (每 1–3 句一段,减少碎片;默认 group=1 时行为与旧版完全一致)。
|
|
25937
|
+
*/
|
|
25938
|
+
const group = Math.min(3, Math.max(1, Math.round(Number(speechOpts.group) || 1)));
|
|
25939
|
+
if (group > 1 && pieces.length > 1) {
|
|
25940
|
+
const merged = [];
|
|
25941
|
+
for (let i = 0; i < pieces.length; i += group) merged.push(pieces.slice(i, i + group).join(''));
|
|
25942
|
+
pieces = merged;
|
|
25943
|
+
}
|
|
25494
25944
|
const voice = String(speechOpts.voice || cfg.name || '');
|
|
25495
25945
|
const rawRate = speechOpts.rate !== undefined ? speechOpts.rate : cfg.rate;
|
|
25496
25946
|
const rate = Number.isFinite(Number(rawRate)) ? Number(rawRate) : 0;
|
|
@@ -25688,6 +26138,21 @@ window.__ModuleLoader__.load({
|
|
|
25688
26138
|
let petChatVoice = { name: '', muted: false, rate: 0, continuous: true, listenPaused: false };
|
|
25689
26139
|
/** pre.65:本轮输入方式决定长度策略(语音 1–3 句;文字可长)。 */
|
|
25690
26140
|
let petChatInputMode = 'text';
|
|
26141
|
+
/**
|
|
26142
|
+
* v1.3:**本轮意图策略**(不持久化)。宿主在 meta.policy 里下发 chat/story/empathy;
|
|
26143
|
+
* 客户端只按这一轮决定 TTS 分批、气泡保留与故事按钮,下一轮自动回到 chat。
|
|
26144
|
+
*/
|
|
26145
|
+
let petChatTurnPolicy = 'chat';
|
|
26146
|
+
/** 上一轮策略:onIdle 在 done 之后才触发,不能丢。 */
|
|
26147
|
+
let petChatLastTurnPolicy = 'chat';
|
|
26148
|
+
/** v1.3 语音回答长度(0 = 不限;默认 8 句)。 */
|
|
26149
|
+
let petChatVoiceLength = 8;
|
|
26150
|
+
/** 故事轮:上一轮全文(「重讲 / 缩短」直接用它,不再问模型)。 */
|
|
26151
|
+
let petChatLastReply = '';
|
|
26152
|
+
/** 「继续讲」:下一轮不清空气泡,接在原文后面。 */
|
|
26153
|
+
let petChatKeepBubble = false;
|
|
26154
|
+
/** 屏幕感知状态(用于「👁 观察中」提示;只观察 = 屏幕感知开 + 主动搭话关)。 */
|
|
26155
|
+
let petChatScreenMode = 'off';
|
|
25691
26156
|
/** 当前 active persona(只用于提示/排障;宿主以 index.active 为准,避免切换后发旧 id)。 */
|
|
25692
26157
|
let petChatPersonaId = '';
|
|
25693
26158
|
async function petChatRefreshVoice() {
|
|
@@ -25705,6 +26170,10 @@ window.__ModuleLoader__.load({
|
|
|
25705
26170
|
listenPaused: doc.voice.listenPaused === true,
|
|
25706
26171
|
};
|
|
25707
26172
|
}
|
|
26173
|
+
// v1.3:设置只下发语音长度 / 屏幕感知 / 主动搭话;不再有“模式”。
|
|
26174
|
+
if (Number.isFinite(Number(doc.voiceLength))) petChatVoiceLength = Math.max(0, Math.round(Number(doc.voiceLength)));
|
|
26175
|
+
petChatProactiveEnabled = Boolean(doc.proactive && doc.proactive.enabled === true);
|
|
26176
|
+
petChatScreenMode = doc.screen && ['app', 'ocr'].includes(String(doc.screen.mode)) ? String(doc.screen.mode) : 'off';
|
|
25708
26177
|
} catch { /* 读不到就用默认(不静音) */ }
|
|
25709
26178
|
// 「暂停说话 / 暂停聆听」都是持久开关:设置页/右键改完立刻生效。
|
|
25710
26179
|
petChatSpeakPaused = petChatVoice.muted === true;
|
|
@@ -25712,9 +26181,26 @@ window.__ModuleLoader__.load({
|
|
|
25712
26181
|
petChatContinuousPaused = petChatVoice.listenPaused === true;
|
|
25713
26182
|
petBubble.setVoiceFlags({ speakPaused: petChatSpeakPaused, listenPaused: petChatContinuousPaused });
|
|
25714
26183
|
petChatPublishContinuousState();
|
|
26184
|
+
petChatApplyPrivacyUi();
|
|
26185
|
+
if (petChatProactiveEnabled) petChatMindStart();
|
|
25715
26186
|
return petChatVoice;
|
|
25716
26187
|
}
|
|
25717
26188
|
|
|
26189
|
+
/**
|
|
26190
|
+
* v1.3:只观察 = **屏幕感知开 + 主动搭话关**(隐私设置),不是对话模式。
|
|
26191
|
+
* 满足时状态条常驻「👁 观察中」;关闭屏幕感知即收起。
|
|
26192
|
+
*/
|
|
26193
|
+
function petChatApplyPrivacyUi() {
|
|
26194
|
+
try {
|
|
26195
|
+
if (petChatScreenMode !== 'off' && petChatProactiveEnabled !== true) {
|
|
26196
|
+
petBubble.status('info', '👁 ' + weT('观察中'), { delay: 0 });
|
|
26197
|
+
} else {
|
|
26198
|
+
petBubble.hideStatus(0);
|
|
26199
|
+
}
|
|
26200
|
+
} catch { /* 状态条是增强 */ }
|
|
26201
|
+
petChatPublishContinuousState();
|
|
26202
|
+
}
|
|
26203
|
+
|
|
25718
26204
|
/* ── 常驻聆听(任务 §4):装好就在听;半双工;「暂停说话 / 暂停聆听」两个开关 ── *
|
|
25719
26205
|
*
|
|
25720
26206
|
* 状态机:idle → listening → thinking → speaking → listening(循环)
|
|
@@ -25759,6 +26245,7 @@ window.__ModuleLoader__.load({
|
|
|
25759
26245
|
active: petChatContinuousActive === true,
|
|
25760
26246
|
paused: petChatContinuousPaused === true,
|
|
25761
26247
|
rounds: petChatContinuousRounds,
|
|
26248
|
+
voiceLength: petChatVoiceLength,
|
|
25762
26249
|
},
|
|
25763
26250
|
}));
|
|
25764
26251
|
window.dispatchEvent(new CustomEvent('we-pet-voice-state', {
|
|
@@ -26304,7 +26791,11 @@ window.__ModuleLoader__.load({
|
|
|
26304
26791
|
},
|
|
26305
26792
|
onState: (kind) => { petBubble.setState(kind); },
|
|
26306
26793
|
onIdle: () => {
|
|
26307
|
-
|
|
26794
|
+
// v1.3:故事轮读完保留气泡(可回看/「缩短」);情绪轮多留一会儿;其余 3 秒淡出。
|
|
26795
|
+
const policy = petChatLastTurnPolicy;
|
|
26796
|
+
if (policy === 'story') { /* 保留气泡,由用户点关闭或「缩短」 */ }
|
|
26797
|
+
else if (policy === 'empathy') petBubble.hide(10000);
|
|
26798
|
+
else petBubble.hide(3000);
|
|
26308
26799
|
petChatListeningNow = false;
|
|
26309
26800
|
// 播完 150ms 自动恢复听(半双工:朗读期间绝不录音)。
|
|
26310
26801
|
if (petChatContinuousActive && !petChatContinuousPaused) petChatContinuousArm(PET_CHAT_LISTEN_RESUME_MS);
|
|
@@ -26472,6 +26963,9 @@ window.__ModuleLoader__.load({
|
|
|
26472
26963
|
return;
|
|
26473
26964
|
}
|
|
26474
26965
|
petChatTurnBegin();
|
|
26966
|
+
// v1.3:每一轮都从 chat 开始;故事/情绪由宿主按这句话判定(meta.policy 回来后再切)。
|
|
26967
|
+
petChatTurnPolicy = 'chat';
|
|
26968
|
+
petChatStoryBarHide();
|
|
26475
26969
|
const turnStartAt = Date.now();
|
|
26476
26970
|
let firstTokenAt = 0;
|
|
26477
26971
|
let firstAudioAt = 0;
|
|
@@ -26485,7 +26979,13 @@ window.__ModuleLoader__.load({
|
|
|
26485
26979
|
// “想”态:模型还在回,先不给“说”的波形
|
|
26486
26980
|
petBubble.setState('think');
|
|
26487
26981
|
// 新一轮回答从空气泡开始(否则会追加到上一轮回答的尾部)。
|
|
26488
|
-
|
|
26982
|
+
// v1.2「继续」:不清空,用两个换行接在原文后面(故事分章阅读)。
|
|
26983
|
+
if (petChatKeepBubble) {
|
|
26984
|
+
petBubble.append('\n\n');
|
|
26985
|
+
petChatKeepBubble = false;
|
|
26986
|
+
} else {
|
|
26987
|
+
petBubble.clear();
|
|
26988
|
+
}
|
|
26489
26989
|
// v2 环境感知:壁纸名 / 正在播放由前端补(宿主不认识 selection 与媒体桥实例)。
|
|
26490
26990
|
const context = await petChatEnvSnapshot();
|
|
26491
26991
|
// ⚠️ apiFetch 的返回值里**已经带上了原始 Response**(字段 `response`)。
|
|
@@ -26534,16 +27034,30 @@ window.__ModuleLoader__.load({
|
|
|
26534
27034
|
*/
|
|
26535
27035
|
let speakBuffer = '';
|
|
26536
27036
|
let queuedSpeech = 0;
|
|
26537
|
-
|
|
26538
|
-
|
|
27037
|
+
/** v1.3:故事轮每 2 句合成一段(1–3 句/段的队列播放),减少碎片化。 */
|
|
27038
|
+
let speechBatch = '';
|
|
27039
|
+
/** 本轮回答全文(故事轮「重讲 / 缩短」用)。 */
|
|
27040
|
+
let turnReply = '';
|
|
27041
|
+
const enqueueSpeech = (piece, flush) => {
|
|
27042
|
+
let line = String(piece || '').trim();
|
|
26539
27043
|
if (!line) return;
|
|
26540
27044
|
// 任务 §4③:「暂停说话」= 跳过 TTS 队列,只出字幕;状态条显示「🔇 仅文字」。
|
|
26541
27045
|
if (petChatSpeakPaused) {
|
|
26542
27046
|
petBubble.setState('muted');
|
|
26543
27047
|
return;
|
|
26544
27048
|
}
|
|
27049
|
+
if (petChatTurnPolicy === 'story') {
|
|
27050
|
+
// 2 句一批;flush 时把尾句也送出去。每段仍受宿主 240 字上限约束(2 句通常 < 100 字)。
|
|
27051
|
+
speechBatch += line;
|
|
27052
|
+
if (!flush && speechBatch.length < 60) return;
|
|
27053
|
+
line = speechBatch;
|
|
27054
|
+
speechBatch = '';
|
|
27055
|
+
}
|
|
26545
27056
|
// v2:本轮语速由宿主 meta 给(夜间/疲惫 -1 = -10%);再叠加当前人设的 voice.rate。
|
|
26546
|
-
if (petSpeak(line, {
|
|
27057
|
+
if (petSpeak(line, {
|
|
27058
|
+
rate: petChatSpeechRate + (Number(petChatVoice.rate) || 0),
|
|
27059
|
+
...(petChatTurnPolicy === 'story' ? { group: 2 } : {}),
|
|
27060
|
+
})) {
|
|
26547
27061
|
queuedSpeech += 1;
|
|
26548
27062
|
if (!firstAudioAt) firstAudioAt = Date.now(); // 首段音频交给播放器的时刻
|
|
26549
27063
|
}
|
|
@@ -26573,6 +27087,11 @@ window.__ModuleLoader__.load({
|
|
|
26573
27087
|
if (eventName === 'meta') {
|
|
26574
27088
|
petChatMood = String(payload.mood || 'neutral');
|
|
26575
27089
|
petChatSpeechRate = Number.isFinite(Number(payload.rate)) ? Number(payload.rate) : 0;
|
|
27090
|
+
// v1.3:宿主按这一句话判定策略(chat/story/empathy),客户端只跟着本轮走。
|
|
27091
|
+
if (['chat', 'story', 'empathy'].includes(String(payload.policy || ''))) {
|
|
27092
|
+
petChatTurnPolicy = String(payload.policy);
|
|
27093
|
+
petChatLastTurnPolicy = petChatTurnPolicy;
|
|
27094
|
+
}
|
|
26576
27095
|
// v5 §5:深度档 >3s 显示「深度思考中…」(quick/standard 秒回,不闪这一下)。
|
|
26577
27096
|
if (payload.tier === 'deep') {
|
|
26578
27097
|
if (petChatDeepTimer != null) clearTimeout(petChatDeepTimer);
|
|
@@ -26604,6 +27123,31 @@ window.__ModuleLoader__.load({
|
|
|
26604
27123
|
}
|
|
26605
27124
|
if (eventName === 'done') {
|
|
26606
27125
|
if (Number.isFinite(Number(payload.rate))) petChatSpeechRate = Number(payload.rate);
|
|
27126
|
+
if (['chat', 'story', 'empathy'].includes(String(payload.policy || ''))) {
|
|
27127
|
+
petChatTurnPolicy = String(payload.policy);
|
|
27128
|
+
petChatLastTurnPolicy = petChatTurnPolicy;
|
|
27129
|
+
}
|
|
27130
|
+
// v1.3 静音指令:只切 TTS 开关,不进入任何“模式”;字幕继续。
|
|
27131
|
+
if (payload.muted === true) {
|
|
27132
|
+
petChatVoice.muted = true;
|
|
27133
|
+
petChatSpeakPaused = true;
|
|
27134
|
+
petBubble.setVoiceFlags({ speakPaused: true, listenPaused: petChatContinuousPaused });
|
|
27135
|
+
try { petSpeakStop(); } catch { /* ignore */ }
|
|
27136
|
+
} else if (payload.muted === false) {
|
|
27137
|
+
petChatVoice.muted = false;
|
|
27138
|
+
petChatSpeakPaused = false;
|
|
27139
|
+
petBubble.setVoiceFlags({ speakPaused: false, listenPaused: petChatContinuousPaused });
|
|
27140
|
+
}
|
|
27141
|
+
continue;
|
|
27142
|
+
}
|
|
27143
|
+
/**
|
|
27144
|
+
* v1.2:宿主失败事件(rate-limited / no-model / timeout / bad-request…)以前**完全静默**,
|
|
27145
|
+
* 气泡停在「在想」。这里补一条可见提示,并把这一轮收尾。
|
|
27146
|
+
*/
|
|
27147
|
+
if (eventName === 'error') {
|
|
27148
|
+
const hint = String(payload.hint || payload.code || weT('这次没答上来'));
|
|
27149
|
+
petBubble.status('error', hint, { delay: 5000 });
|
|
27150
|
+
replyDone = true;
|
|
26607
27151
|
continue;
|
|
26608
27152
|
}
|
|
26609
27153
|
// 防兜底:模型偶尔仍会输出 {"reply":"…","emotion":"…"} 信封,
|
|
@@ -26628,6 +27172,7 @@ window.__ModuleLoader__.load({
|
|
|
26628
27172
|
// 气泡始终显示**完整回答**(逐段追加,长文在 160px 内滚动);
|
|
26629
27173
|
// 朗读只负责切句与“说”状态,不再改写气泡内容。
|
|
26630
27174
|
petBubble.append(piece);
|
|
27175
|
+
turnReply += piece;
|
|
26631
27176
|
speakBuffer += piece;
|
|
26632
27177
|
const split = petTtsSentences(speakBuffer);
|
|
26633
27178
|
for (const sentence of split.sentences) enqueueSpeech(sentence);
|
|
@@ -26638,7 +27183,11 @@ window.__ModuleLoader__.load({
|
|
|
26638
27183
|
}
|
|
26639
27184
|
}
|
|
26640
27185
|
// 最后一段没有句末标点也要念(比如“我也在”)
|
|
26641
|
-
enqueueSpeech(speakBuffer);
|
|
27186
|
+
enqueueSpeech(speakBuffer, true);
|
|
27187
|
+
// v1.3:只有**本轮**是 story 才给「继续讲 / 重讲 / 缩短」;下一轮自动消失。
|
|
27188
|
+
petChatLastReply = String(turnReply || '').trim();
|
|
27189
|
+
petChatLastTurnPolicy = petChatTurnPolicy;
|
|
27190
|
+
if (petChatTurnPolicy === 'story' && petChatLastReply) petChatStoryBarShow();
|
|
26642
27191
|
if (typeof onState === 'function') onState({ state: 'idle' });
|
|
26643
27192
|
// 本轮成功:常驻聆听继续(任务 §4:装好就在听,不靠"点了才听");
|
|
26644
27193
|
// 有朗读时等 onIdle 播完再开麦(半双工),没朗读(暂停说话/静音)直接 150ms 后排下一轮。
|
|
@@ -26650,7 +27199,12 @@ window.__ModuleLoader__.load({
|
|
|
26650
27199
|
if (!queuedSpeech && !singStarted) petChatContinuousArm();
|
|
26651
27200
|
// 没有任何一句进入朗读(暂停说话 / 合成不可用)⇒ 字幕照常显示,3 秒后淡出。
|
|
26652
27201
|
// 唱歌时气泡归歌词用:不提前收,播完由 petChatSingPlay 收。
|
|
26653
|
-
|
|
27202
|
+
// v1.3:故事轮保留气泡(用户要能回看/点「缩短」);情绪轮多留一会儿。
|
|
27203
|
+
if (!queuedSpeech && !singStarted) {
|
|
27204
|
+
if (petChatTurnPolicy === 'story') { /* 不自动收 */ }
|
|
27205
|
+
else if (petChatTurnPolicy === 'empathy') petBubble.hide(10000);
|
|
27206
|
+
else petBubble.hide(3000);
|
|
27207
|
+
}
|
|
26654
27208
|
petChatReportLatency(turnStartAt, firstTokenAt, firstAudioAt);
|
|
26655
27209
|
petChatTurnEnd();
|
|
26656
27210
|
},
|
|
@@ -26740,6 +27294,114 @@ window.__ModuleLoader__.load({
|
|
|
26740
27294
|
if (!petSpeak(line)) petBubble.hide(3000);
|
|
26741
27295
|
}
|
|
26742
27296
|
|
|
27297
|
+
/* ── v1.2 故事模式:继续 / 重讲 / 缩短 ─────────────────────────────────── */
|
|
27298
|
+
|
|
27299
|
+
let petChatStoryBar = null;
|
|
27300
|
+
|
|
27301
|
+
function petChatStoryBarHide() {
|
|
27302
|
+
try { if (petChatStoryBar && petChatStoryBar.parentNode) petChatStoryBar.parentNode.removeChild(petChatStoryBar); } catch { /* ignore */ }
|
|
27303
|
+
petChatStoryBar = null;
|
|
27304
|
+
}
|
|
27305
|
+
|
|
27306
|
+
/** 把一段长文按句切成 ≤max 字的小段(重讲/朗读用;宿主单次上限 240 字)。 */
|
|
27307
|
+
function petChatStoryChunks(text, max) {
|
|
27308
|
+
const limit = Math.max(60, Number(max) || 180);
|
|
27309
|
+
const chunks = [];
|
|
27310
|
+
let buffer = '';
|
|
27311
|
+
for (const ch of String(text || '')) {
|
|
27312
|
+
buffer += ch;
|
|
27313
|
+
if (/[。!?!?;;\n]/.test(ch) && buffer.length >= limit * 0.5) {
|
|
27314
|
+
chunks.push(buffer.trim());
|
|
27315
|
+
buffer = '';
|
|
27316
|
+
} else if (buffer.length >= limit) {
|
|
27317
|
+
chunks.push(buffer.trim());
|
|
27318
|
+
buffer = '';
|
|
27319
|
+
}
|
|
27320
|
+
}
|
|
27321
|
+
if (buffer.trim()) chunks.push(buffer.trim());
|
|
27322
|
+
return chunks.filter(Boolean);
|
|
27323
|
+
}
|
|
27324
|
+
|
|
27325
|
+
function petChatStoryBarShow() {
|
|
27326
|
+
petChatStoryBarHide();
|
|
27327
|
+
if (typeof document === 'undefined' || !document.body || typeof document.createElement !== 'function') return;
|
|
27328
|
+
const bar = document.createElement('div');
|
|
27329
|
+
bar.id = 'we-pet-story-actions';
|
|
27330
|
+
bar.style.cssText = 'position:fixed;right:22px;bottom:104px;z-index:10000;display:flex;gap:6px;'
|
|
27331
|
+
+ 'background:rgba(20,22,28,.92);border:1px solid rgba(255,255,255,.16);border-radius:10px;padding:6px;'
|
|
27332
|
+
+ 'box-shadow:0 6px 20px rgba(0,0,0,.35);';
|
|
27333
|
+
const make = (label, onClick) => {
|
|
27334
|
+
const button = document.createElement('button');
|
|
27335
|
+
button.type = 'button';
|
|
27336
|
+
button.textContent = label;
|
|
27337
|
+
button.style.cssText = 'font-size:12px;padding:4px 9px;border-radius:7px;border:1px solid rgba(255,255,255,.18);'
|
|
27338
|
+
+ 'background:rgba(255,255,255,.08);color:#eee;cursor:pointer;';
|
|
27339
|
+
button.addEventListener('click', (event) => {
|
|
27340
|
+
try { event.stopPropagation(); } catch { /* ignore */ }
|
|
27341
|
+
onClick();
|
|
27342
|
+
});
|
|
27343
|
+
return button;
|
|
27344
|
+
};
|
|
27345
|
+
bar.appendChild(make(weT('继续讲'), () => {
|
|
27346
|
+
petChatStoryBarHide();
|
|
27347
|
+
petChatInputMode = 'text';
|
|
27348
|
+
petChatKeepBubble = true;
|
|
27349
|
+
petBubble.setState('think');
|
|
27350
|
+
void petVoiceIn.postChat('继续讲');
|
|
27351
|
+
}));
|
|
27352
|
+
bar.appendChild(make(weT('重讲'), () => {
|
|
27353
|
+
petChatStoryBarHide();
|
|
27354
|
+
petSpeakStop();
|
|
27355
|
+
const text = petChatLastReply;
|
|
27356
|
+
if (!text) return;
|
|
27357
|
+
petBubble.show(text);
|
|
27358
|
+
try { petBubble.setExpanded(true); } catch { /* ignore */ }
|
|
27359
|
+
for (const chunk of petChatStoryChunks(text)) petSpeak(chunk, { group: 2 });
|
|
27360
|
+
}));
|
|
27361
|
+
bar.appendChild(make(weT('缩短'), () => {
|
|
27362
|
+
petChatStoryBarHide();
|
|
27363
|
+
petSpeakStop();
|
|
27364
|
+
const text = petChatLastReply;
|
|
27365
|
+
if (!text) return;
|
|
27366
|
+
const sentences = (text.match(/[^。!?!?]+[。!?!?]?/g) || []).slice(0, 3).join('').trim() || text.slice(0, 160);
|
|
27367
|
+
petChatLastReply = sentences;
|
|
27368
|
+
petBubble.show(sentences);
|
|
27369
|
+
petSpeak(sentences);
|
|
27370
|
+
}));
|
|
27371
|
+
bar.appendChild(make(weT('收起'), () => {
|
|
27372
|
+
petChatStoryBarHide();
|
|
27373
|
+
petBubble.hide(0);
|
|
27374
|
+
}));
|
|
27375
|
+
document.body.appendChild(bar);
|
|
27376
|
+
petChatStoryBar = bar;
|
|
27377
|
+
}
|
|
27378
|
+
|
|
27379
|
+
/* ── v1.3 主动思维:客户端每 5 分钟问一次宿主“现在想不想说点什么” ─────── */
|
|
27380
|
+
|
|
27381
|
+
let petChatProactiveEnabled = false;
|
|
27382
|
+
let petChatMindTimer = null;
|
|
27383
|
+
|
|
27384
|
+
async function petChatMindPoll() {
|
|
27385
|
+
if (!petChatProactiveEnabled) return;
|
|
27386
|
+
if (!petChatProactiveAllowed()) return;
|
|
27387
|
+
try {
|
|
27388
|
+
const resp = await apiPostJson('/pet-chat/mind/tick', {
|
|
27389
|
+
speaking: (() => { try { return petTts.isSpeaking(); } catch { return false; } })(),
|
|
27390
|
+
listening: petChatListeningNow === true,
|
|
27391
|
+
turnBusy: petChatTurnBusy === true,
|
|
27392
|
+
activeMinutes: petChatWorkStart ? Math.round((Date.now() - petChatWorkStart) / 60000) : 0,
|
|
27393
|
+
}, { parse: 'always' });
|
|
27394
|
+
const doc = (resp && resp.data) || {};
|
|
27395
|
+
if (doc.ok && doc.line) petChatSay(String(doc.line));
|
|
27396
|
+
} catch { /* 主动是增强,失败静默 */ }
|
|
27397
|
+
}
|
|
27398
|
+
|
|
27399
|
+
function petChatMindStart() {
|
|
27400
|
+
if (petChatMindTimer != null || typeof setInterval !== 'function') return;
|
|
27401
|
+
petChatMindTimer = setInterval(() => { void petChatMindPoll(); }, 5 * 60 * 1000);
|
|
27402
|
+
if (typeof petChatMindTimer.unref === 'function') petChatMindTimer.unref();
|
|
27403
|
+
}
|
|
27404
|
+
|
|
26743
27405
|
/** 每次点桌宠递增;收起/重开时让旧的 ASR 等待自动作废。 */
|
|
26744
27406
|
let petChatWakeSeq = 0;
|
|
26745
27407
|
|
|
@@ -26995,6 +27657,8 @@ window.__ModuleLoader__.load({
|
|
|
26995
27657
|
// v5 §6:深度思考的 3s 提示定时器也要随卸载清掉(否则会在 dispose 后改气泡)。
|
|
26996
27658
|
if (petChatDeepTimer != null) { clearTimeout(petChatDeepTimer); petChatDeepTimer = null; }
|
|
26997
27659
|
if (petSingTimer != null) { clearInterval(petSingTimer); petSingTimer = null; }
|
|
27660
|
+
if (petChatMindTimer != null) { clearInterval(petChatMindTimer); petChatMindTimer = null; }
|
|
27661
|
+
petChatStoryBarHide();
|
|
26998
27662
|
petChatWallpaperTimer = null;
|
|
26999
27663
|
petChatWorkTimer = null;
|
|
27000
27664
|
petChatGreetingTimer = null;
|