dsh-folia 1.0.1 → 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/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",
@@ -1001,6 +1058,31 @@ window.__ModuleLoader__.load({
1001
1058
  "前提:": "Requires: ",
1002
1059
  "读取失败,重开设置页再试": "Failed to load; reopen settings and retry",
1003
1060
  "这些是可选插件:装好后能力给 DSH 助手用,桌宠本身不受影响。不做一键安装,复制命令自行安装。已装插件可由助手交给 DSH 执行,未装只能看说明。": "Optional plugins: they add abilities to the DSH assistant, not the pet. No one-click install — copy the command and install it yourself. Installed plugins can be executed by the assistant through DSH; uninstalled ones are description-only.",
1061
+ "这些是可选的插件与个人工具。安装方式:复制包名命令或 GitHub 地址 → 粘贴到 DSH 对话 → 让助手帮你下载安装(会先确认)。已装插件可由助手交给 DSH 执行;未装的只能看说明。非 DSH 插件的个人工具(Docker/Windows 应用)需要按 README 安装,助手只给步骤。":
1062
+ "Optional plugins and personal tools. To install: copy the package command or GitHub URL → paste it into the DSH chat → let the assistant download and install it (it will confirm first). Installed plugins can be run by the assistant through DSH; uninstalled ones are description-only. Personal tools that are not DSH plugins (Docker/Windows apps) must be installed per their README; the assistant only provides steps.",
1063
+ // pre.79:精选 → 场景组合 / 个人工具
1064
+ "场景组合": "Scenario bundles",
1065
+ "个人工具": "Personal tools",
1066
+ "复制仓库地址": "Copy repo URL",
1067
+ "打开 GitHub": "Open GitHub",
1068
+ "非 DSH 插件": "Not a DSH plugin",
1069
+ "需按 README 安装;助手只给步骤,不盲装。": "Install per the README; the assistant only gives steps and won't blind-install.",
1070
+ "已复制。粘贴到 DSH 对话,让助手帮你安装(会先确认)。": "Copied. Paste it into the DSH chat and let the assistant install it (it will confirm first).",
1071
+ "搜索个人工具": "Search personal tools",
1072
+ "共 {n} 项": "{n} items",
1073
+ "没有匹配的个人工具": "No matching personal tools",
1074
+ "许可:": "License: ",
1075
+ "语音文档": "Speech & documents",
1076
+ "相册影音": "Photos & media",
1077
+ "文档效率": "Document productivity",
1078
+ "笔记阅读": "Notes & reading",
1079
+ "家庭生活": "Home & life",
1080
+ "自动化运维": "Automation & ops",
1081
+ "备份文件": "Backup & files",
1082
+ "隐私安全": "Privacy & security",
1083
+ "财务": "Finance",
1084
+ "创作设计": "Creative & design",
1085
+ "AI": "AI",
1004
1086
  // pre.79:能力页精选(20 套组合 / 场景向导 / 筛选 / 导出)
1005
1087
  "精选": "Curated",
1006
1088
  "场景向导": "Scenario guide",
@@ -8589,6 +8671,16 @@ window.__ModuleLoader__.load({
8589
8671
  voice: { name: '', muted: false },
8590
8672
  // 唤醒:点一下默认开;叫名字默认关(S6 才实现,先在设置里留位)
8591
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' },
8592
8684
  // 对话记忆默认开启且**不暴露开关**(追加决定 1):能力常开,用户只能在右键里查看/清空
8593
8685
  },
8594
8686
  };
@@ -9305,6 +9397,19 @@ window.__ModuleLoader__.load({
9305
9397
  const PET_CHAT_API_KEY_MAX = 400;
9306
9398
  const PET_CHAT_MODEL_MAX = 120;
9307
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
+ };
9308
9413
 
9309
9414
  const petChatStr = (v, max) => (typeof v === 'string' ? v.slice(0, max) : '');
9310
9415
  const petChatFloat = (v, lo, hi, fallback) => {
@@ -9347,6 +9452,9 @@ window.__ModuleLoader__.load({
9347
9452
  const src = raw && typeof raw === 'object' && !Array.isArray(raw) ? raw : {};
9348
9453
  const persona = src.persona && typeof src.persona === 'object' && !Array.isArray(src.persona) ? src.persona : {};
9349
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 : {};
9350
9458
  const baseUrl = petChatStr(src.baseUrl, PET_CHAT_BASE_URL_MAX).trim();
9351
9459
  return {
9352
9460
  enabled: src.enabled === true,
@@ -9364,6 +9472,25 @@ window.__ModuleLoader__.load({
9364
9472
  name: wake.name === true,
9365
9473
  keyword: petChatStr(wake.keyword, 40).trim(),
9366
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
+ },
9367
9494
  // 记忆常开:设置里没有这个开关(追加决定 1),旧档里的 false 也不再尊重
9368
9495
  memoryEnabled: true,
9369
9496
  };
@@ -20813,6 +20940,8 @@ window.__ModuleLoader__.load({
20813
20940
  const currentItem = builtin.items.concat(edge.items, providers.items).find((item) => item.id === currentId);
20814
20941
  const edgeByLang = {};
20815
20942
  for (const item of edge.items) {
20943
+ // 用户口径:声音里不可用的不要出现(429/不可用从主列表隐藏,只留一条提示)
20944
+ if (item.status === 'rate-limited' || item.status === 'unavailable') continue;
20816
20945
  const key = item.langGroup || '其他';
20817
20946
  if (!edgeByLang[key]) edgeByLang[key] = [];
20818
20947
  edgeByLang[key].push(item);
@@ -20871,7 +21000,7 @@ window.__ModuleLoader__.load({
20871
21000
  '免费在线 · Edge', personaTag('可能限流', 'warn')),
20872
21001
  voiceCatalog && voiceCatalog.edgeRateLimited
20873
21002
  ? React.createElement('div', { className: 'we-picker__hint', style: { color: '#fcd34d' } },
20874
- `在线音色被限流(429):已保留 ${voiceCatalog.rateLimitedCount || 0} 个并标注“暂不可用”,合成时会自动回落到内置音色。`)
21003
+ `在线音色被限流(429):不可用项已隐藏;可先用内置音色,稍后自动恢复。`)
20875
21004
  : null,
20876
21005
  Object.keys(edgeByLang).length
20877
21006
  ? Object.keys(edgeByLang).map((lang) => React.createElement('div', { key: 'pick-edge-' + lang },
@@ -21087,6 +21216,12 @@ window.__ModuleLoader__.load({
21087
21216
  ownerName: '',
21088
21217
  // v0.2:朗读 = voice.muted 取反;音色 = voice.name;SAPI = voice.sapiEnabled(默认 false)。
21089
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' },
21090
21225
  };
21091
21226
 
21092
21227
  /** apiJson 的返回是 { ok, status, data },而 /pet-chat/* 的 data 里还套一层 { ok, data }。 */
@@ -21263,6 +21398,8 @@ window.__ModuleLoader__.load({
21263
21398
  const [tab, setTab] = React.useState('assistant');
21264
21399
  const [workPlugins, setWorkPlugins] = React.useState(null);
21265
21400
  const [voices, setVoices] = React.useState(null);
21401
+ /** v1.2:Edge 429 等“在线音色暂时不可用”的提示(列表里不再堆灰项)。 */
21402
+ const [voiceNotice, setVoiceNotice] = React.useState('');
21266
21403
  const [voiceMeta, setVoiceMeta] = React.useState({});
21267
21404
  const [voiceCfg, setVoiceCfg] = React.useState({ sapiEnabled: false, enabledEngine: 'edge', continuous: true, listenPaused: false });
21268
21405
  const [setupBusy, setSetupBusy] = React.useState(false);
@@ -21274,6 +21411,16 @@ window.__ModuleLoader__.load({
21274
21411
  const [enableBusy, setEnableBusy] = React.useState('');
21275
21412
  const [enableNote, setEnableNote] = React.useState(null);
21276
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);
21277
21424
  const [providers, setProviders] = React.useState(null);
21278
21425
  const [providerBusy, setProviderBusy] = React.useState(false);
21279
21426
  const [providerNote, setProviderNote] = React.useState(null);
@@ -21340,6 +21487,9 @@ window.__ModuleLoader__.load({
21340
21487
  const doc = unwrapPetChat(resp);
21341
21488
  const items = (doc && Array.isArray(doc.voices) ? doc.voices : []).filter((v) => v && v.usable === true);
21342
21489
  setVoices(items);
21490
+ setVoiceNotice(doc && doc.rateLimited === true
21491
+ ? weT('在线音色暂不可用(429 限流):先用本地音色,稍后再试。')
21492
+ : '');
21343
21493
  setVoiceMeta((doc && doc.meta) || {});
21344
21494
  const engine = ['edge', 'piper', 'sapi'].includes(String(doc && doc.enabledEngine || '')) ? doc.enabledEngine : 'edge';
21345
21495
  setEnabledEngine(engine);
@@ -21360,8 +21510,106 @@ window.__ModuleLoader__.load({
21360
21510
  }
21361
21511
  }, []);
21362
21512
 
21363
- const loadFfmpeg = React.useCallback(async () => {
21364
- const resp = await apiJson('/pet-chat/voice/diagnose?light=1', { parse: 'always' }).catch(() => null);
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);
21365
21613
  const doc = unwrapPetChat(resp);
21366
21614
  const st = doc && doc.steps && doc.steps.ffmpeg;
21367
21615
  if (st && st.phase) setFfmpeg(st);
@@ -21705,10 +21953,11 @@ window.__ModuleLoader__.load({
21705
21953
  : null);
21706
21954
  child.push(React.createElement('div', { key: 'title', style: { fontWeight: 600, margin: '14px 0 4px', fontSize: '13px' } }, weT('智能大肥鱼')));
21707
21955
  child.push(React.createElement('div', { key: 'hint', className: 'we-picker__hint', style: { margin: '0 0 6px' } },
21708
- weT('填 Key、起名字、选音色,再决定要不要朗读。主动搭话与记忆是固定策略;停止/恢复对它说一声就行。')));
21956
+ weT('填 Key、起名字、选音色;对话模式、主动搭话、屏幕感知都在「对话与隐私」里,默认全关。')));
21709
21957
 
21710
21958
  const tabs = [
21711
21959
  ['assistant', weT('助手')],
21960
+ ['behavior', weT('对话与隐私')],
21712
21961
  ['voice', weT('朗读与音色')],
21713
21962
  ['work', weT('工作能力')],
21714
21963
  ];
@@ -21752,6 +22001,128 @@ window.__ModuleLoader__.load({
21752
22001
  child.push(React.createElement(MicTestBlock, { key: 'mic-test' }));
21753
22002
  }
21754
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
+
21755
22126
  if (tab === 'voice') {
21756
22127
  const voicePage = [];
21757
22128
  voicePage.push(React.createElement('div', {
@@ -21816,6 +22187,12 @@ window.__ModuleLoader__.load({
21816
22187
  voicePage.push(React.createElement('div', {
21817
22188
  key: 'local-head', style: { marginTop: '10px', fontSize: '12px', fontWeight: 600 },
21818
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
+ }
21819
22196
  if (selectableVoices.length) {
21820
22197
  const groups = [];
21821
22198
  for (const engine of ['edge', 'piper', 'sapi', 'openai', 'azure', 'elevenlabs']) {
@@ -22049,6 +22426,57 @@ window.__ModuleLoader__.load({
22049
22426
  ...detailProps,
22050
22427
  }));
22051
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
+ }
22052
22480
  child.push(React.createElement('div', { key: 'voice-page' }, voicePage));
22053
22481
  }
22054
22482
 
@@ -22433,6 +22861,11 @@ window.__ModuleLoader__.load({
22433
22861
  step.optional ? React.createElement(CuratedTag, null, weT('可选')) : null,
22434
22862
  step.alt ? React.createElement(CuratedTag, null, weT('可替代')) : null),
22435
22863
  React.createElement('div', { className: 'we-picker__hint', style: { marginTop: '2px' } }, step.why || ''),
22864
+ step.detail && step.detail !== step.why
22865
+ ? React.createElement('div', { className: 'we-picker__hint', style: { marginTop: '2px' } }, step.detail)
22866
+ : null,
22867
+ step.repo ? React.createElement('div', { style: { marginTop: '2px', fontSize: '10px' } },
22868
+ React.createElement('a', { href: step.repo, target: '_blank', rel: 'noreferrer', style: { color: 'inherit', textDecoration: 'underline' } }, step.repo)) : null,
22436
22869
  step.alt ? React.createElement('div', { className: 'we-picker__hint', style: { marginTop: '2px' } },
22437
22870
  weT('替代:') + step.alt + '(' + CURATED_PREFIX + step.alt + ')') : null,
22438
22871
  React.createElement('div', { style: { display: 'flex', gap: '6px', alignItems: 'center', marginTop: '4px' } },
@@ -22445,11 +22878,12 @@ window.__ModuleLoader__.load({
22445
22878
  if (onCopy) onCopy(command);
22446
22879
  setTimeout(() => setCopied(false), 1500);
22447
22880
  },
22448
- }, copied ? weT('已复制') : weT('复制')) : null));
22881
+ }, copied ? weT('已复制') : weT('复制安装命令')) : null));
22449
22882
  }
22450
22883
 
22451
22884
  function CuratedCard({ bundle, installed, favorite, recommended, agentsAvailable, onToggleFavorite, onCopy, onExport }) {
22452
22885
  const [open, setOpen] = React.useState(false);
22886
+ const [copyNote, setCopyNote] = React.useState('');
22453
22887
  const steps = Array.isArray(bundle.steps) ? bundle.steps : [];
22454
22888
  const installedCount = steps.filter((s) => installed && installed[s.pkg]).length;
22455
22889
  const callMode = curatedCallMode(bundle, installed, agentsAvailable);
@@ -22457,6 +22891,11 @@ window.__ModuleLoader__.load({
22457
22891
  const risk = CURATED_RISK_LABELS[bundle.risk] || bundle.risk || '';
22458
22892
  const budgets = (Array.isArray(bundle.budget) ? bundle.budget : []).map((b) => CURATED_BUDGET_LABELS[b] || b).join(' / ');
22459
22893
  const high = bundle.risk === 'high';
22894
+ const copyWithNote = (text) => {
22895
+ onCopy(text);
22896
+ setCopyNote(weT('已复制。粘贴到 DSH 对话,让助手帮你安装(会先确认)。'));
22897
+ setTimeout(() => setCopyNote(''), 3500);
22898
+ };
22460
22899
  return React.createElement('div', {
22461
22900
  style: {
22462
22901
  ...CAP_CARD,
@@ -22498,16 +22937,17 @@ window.__ModuleLoader__.load({
22498
22937
  weT('冲突:') + bundle.conflicts.join(';'))
22499
22938
  : null,
22500
22939
  React.createElement('div', { style: { display: 'flex', gap: '6px', flexWrap: 'wrap' } },
22501
- React.createElement('button', { type: 'button', className: 'we-picker__btn', onClick: () => onCopy(commands.join('\n')) },
22940
+ React.createElement('button', { type: 'button', className: 'we-picker__btn', onClick: () => copyWithNote(commands.join('\n')) },
22502
22941
  weT('复制全部命令')),
22503
22942
  React.createElement('button', { type: 'button', className: 'we-picker__btn', onClick: () => setOpen((v) => !v) },
22504
22943
  open ? weT('收起步骤') : weT('展开步骤')),
22505
22944
  React.createElement('button', { type: 'button', className: 'we-picker__btn', onClick: () => onExport(bundle, 'powershell') }, 'PowerShell'),
22506
22945
  React.createElement('button', { type: 'button', className: 'we-picker__btn', onClick: () => onExport(bundle, 'bash') }, 'bash'),
22507
22946
  React.createElement('button', { type: 'button', className: 'we-picker__btn', onClick: () => onExport(bundle, 'json') }, 'JSON')),
22947
+ copyNote ? React.createElement('div', { className: 'we-picker__hint', style: { color: '#4caf7d' } }, copyNote) : null,
22508
22948
  open ? React.createElement('div', { style: { display: 'flex', flexDirection: 'column', gap: '4px' } },
22509
22949
  steps.map((step) => React.createElement(CuratedStep, {
22510
- key: step.pkg, step, version: installed ? installed[step.pkg] : null, onCopy,
22950
+ key: step.pkg, step, version: installed ? installed[step.pkg] : null, onCopy: copyWithNote,
22511
22951
  }))) : null);
22512
22952
  }
22513
22953
 
@@ -22535,7 +22975,91 @@ window.__ModuleLoader__.load({
22535
22975
  weT('推荐:') + recommended.map((id) => (bundleById[id] ? bundleById[id].name : id)).join(' / ')) : null);
22536
22976
  }
22537
22977
 
22538
- function CuratedPanel({ data, favorites, onToggleFavorite }) {
22978
+ /* ── 个人工具(Docker/Windows,非 DSH 插件;只给仓库 + README 安装说明)── */
22979
+
22980
+ const PERSONAL_CATEGORY_LABELS = {
22981
+ all: '全部', ai: 'AI', 'speech-doc': '语音文档', media: '相册影音', docs: '文档效率',
22982
+ notes: '笔记阅读', home: '家庭生活', ops: '自动化运维', backup: '备份文件',
22983
+ privacy: '隐私安全', finance: '财务', creative: '创作设计', dev: '开发',
22984
+ };
22985
+
22986
+ function PersonalToolCard({ tool }) {
22987
+ const [open, setOpen] = React.useState(false);
22988
+ const [copied, setCopied] = React.useState(false);
22989
+ const [note, setNote] = React.useState('');
22990
+ const risk = CURATED_RISK_LABELS[tool.risk] || tool.risk || '';
22991
+ const copyRepo = () => {
22992
+ copyPlainText(tool.repo);
22993
+ setCopied(true);
22994
+ setNote(weT('已复制。粘贴到 DSH 对话,让助手帮你安装(会先确认)。'));
22995
+ setTimeout(() => { setCopied(false); setNote(''); }, 3500);
22996
+ };
22997
+ return React.createElement('div', { style: CAP_CARD },
22998
+ React.createElement('div', { style: { display: 'flex', gap: '8px', alignItems: 'flex-start' } },
22999
+ React.createElement('div', { style: CAP_ICON }, '🧰'),
23000
+ React.createElement('div', { style: { flex: 1, minWidth: 0 } },
23001
+ React.createElement('div', { style: { fontWeight: 600, fontSize: '13px', display: 'flex', gap: '6px', flexWrap: 'wrap', alignItems: 'center' } },
23002
+ tool.name,
23003
+ React.createElement(CuratedTag, { tone: tool.risk }, risk),
23004
+ React.createElement(CuratedTag, null, weT('非 DSH 插件'))),
23005
+ React.createElement('div', { className: 'we-picker__hint' }, tool.desc),
23006
+ React.createElement('div', { style: { display: 'flex', gap: '6px', flexWrap: 'wrap', marginTop: '4px' } },
23007
+ React.createElement(CuratedTag, null, tool.license),
23008
+ React.createElement(CuratedTag, null, tool.requires))),
23009
+ React.createElement('span', { style: { fontSize: '10px', opacity: 0.6 } }, PERSONAL_CATEGORY_LABELS[tool.category] || tool.category)),
23010
+ React.createElement('div', { style: { display: 'flex', gap: '6px', flexWrap: 'wrap' } },
23011
+ React.createElement('button', { type: 'button', className: 'we-picker__btn', onClick: copyRepo },
23012
+ copied ? weT('已复制') : weT('复制仓库地址')),
23013
+ React.createElement('a', {
23014
+ className: 'we-picker__btn', href: tool.repo, target: '_blank', rel: 'noreferrer',
23015
+ style: { textDecoration: 'none' },
23016
+ }, weT('打开 GitHub')),
23017
+ React.createElement('button', { type: 'button', className: 'we-picker__btn', onClick: () => setOpen((v) => !v) },
23018
+ open ? weT('收起') : weT('详情'))),
23019
+ note ? React.createElement('div', { className: 'we-picker__hint', style: { color: '#4caf7d' } }, note) : null,
23020
+ React.createElement('div', { className: 'we-picker__hint' },
23021
+ weT('需按 README 安装;助手只给步骤,不盲装。')),
23022
+ open ? React.createElement('div', { style: { display: 'flex', flexDirection: 'column', gap: '4px' } },
23023
+ React.createElement('div', { className: 'we-picker__hint' }, tool.detail),
23024
+ React.createElement('div', { className: 'we-picker__hint' }, weT('前置:') + tool.requires),
23025
+ React.createElement('div', { className: 'we-picker__hint' }, weT('许可:') + tool.license),
23026
+ React.createElement('a', { href: tool.repo, target: '_blank', rel: 'noreferrer', style: { fontSize: '11px', color: 'inherit' } }, tool.repo),
23027
+ (tool.repos || []).length ? React.createElement('div', { style: { display: 'flex', flexDirection: 'column', gap: '2px' } },
23028
+ tool.repos.map((r) => React.createElement('a', {
23029
+ key: r.repo, href: r.repo, target: '_blank', rel: 'noreferrer', style: { fontSize: '11px', color: 'inherit' },
23030
+ }, r.name + ' · ' + r.repo))) : null) : null);
23031
+ }
23032
+
23033
+ function PersonalPanel({ tools }) {
23034
+ const [category, setCategory] = React.useState('all');
23035
+ const [query, setQuery] = React.useState('');
23036
+ const list = (Array.isArray(tools) ? tools : []).filter((t) => {
23037
+ if (category !== 'all' && t.category !== category) return false;
23038
+ const q = String(query || '').trim().toLowerCase();
23039
+ if (!q) return true;
23040
+ return [t.name, t.desc, t.repo, t.category].join(' ').toLowerCase().includes(q);
23041
+ });
23042
+ return React.createElement('div', { style: { marginTop: '8px' } },
23043
+ React.createElement('div', { style: { display: 'flex', gap: '4px', flexWrap: 'wrap' } },
23044
+ Object.keys(PERSONAL_CATEGORY_LABELS).map((id) => React.createElement('button', {
23045
+ key: id, type: 'button',
23046
+ className: 'we-picker__btn' + (category === id ? ' we-picker__btn--primary' : ''),
23047
+ onClick: () => setCategory(id),
23048
+ }, weT(PERSONAL_CATEGORY_LABELS[id])))),
23049
+ React.createElement('div', { style: { display: 'flex', gap: '8px', alignItems: 'center', marginTop: '6px' } },
23050
+ React.createElement('input', {
23051
+ type: 'text', value: query, placeholder: weT('搜索个人工具'),
23052
+ onChange: (e) => setQuery(e.target.value),
23053
+ style: { flex: '1 1 180px', fontSize: '11px', padding: '4px 6px', borderRadius: '6px', border: '1px solid rgba(255,255,255,0.16)', background: 'transparent', color: 'inherit' },
23054
+ }),
23055
+ React.createElement('span', { className: 'we-picker__hint' }, weT('共 {n} 项', { n: list.length }))),
23056
+ list.length ? React.createElement('div', {
23057
+ style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(340px, 1fr))', gap: '8px', marginTop: '8px' },
23058
+ }, list.map((tool) => React.createElement(PersonalToolCard, { key: tool.id, tool })))
23059
+ : React.createElement('div', { className: 'we-picker__hint', style: { marginTop: '10px' } }, weT('没有匹配的个人工具')));
23060
+ }
23061
+
23062
+ function CuratedPanel({ data, favorites, onToggleFavorite, agentsAvailable }) {
22539
23063
  const [family, setFamily] = React.useState('all');
22540
23064
  const [favOnly, setFavOnly] = React.useState(false);
22541
23065
  const [query, setQuery] = React.useState('');
@@ -22609,7 +23133,7 @@ window.__ModuleLoader__.load({
22609
23133
 
22610
23134
  function CapabilitiesSection() {
22611
23135
  // items = 市场快照;curated = 20 套组合;page = 精选/工作能力/娱乐(精选默认)
22612
- const [state, setState] = React.useState({ items: null, curated: null, page: "curated", error: null, agentsAvailable: false });
23136
+ const [state, setState] = React.useState({ items: null, curated: null, page: "curated", curatedTab: "bundles", error: null, agentsAvailable: false });
22613
23137
  const [favorites, setFavorites] = React.useState(() => new Set(readCuratedFavorites()));
22614
23138
 
22615
23139
  React.useEffect(() => {
@@ -22655,7 +23179,7 @@ window.__ModuleLoader__.load({
22655
23179
  return React.createElement("div", { style: { padding: "4px 2px" } },
22656
23180
  React.createElement("div", { style: { fontSize: "14px", fontWeight: 600 } }, weT("能力")),
22657
23181
  React.createElement("div", { className: "we-picker__hint", style: { marginTop: "2px" } },
22658
- weT("这些是可选插件:装好后能力给 DSH 助手用,桌宠本身不受影响。不做一键安装,复制命令自行安装。已装插件可由助手交给 DSH 执行,未装只能看说明。")),
23182
+ weT("这些是可选的插件与个人工具。安装方式:复制包名命令或 GitHub 地址 → 粘贴到 DSH 对话 → 让助手帮你下载安装(会先确认)。已装插件可由助手交给 DSH 执行;未装的只能看说明。非 DSH 插件的个人工具(Docker/Windows 应用)需要按 README 安装,助手只给步骤。")),
22659
23183
  // 三个页面之间切换(页内 tab),精选默认打开
22660
23184
  React.createElement("div", { style: { display: "flex", gap: "6px", marginTop: "10px" } },
22661
23185
  tabs.map((tab) => React.createElement("button", {
@@ -22666,7 +23190,20 @@ window.__ModuleLoader__.load({
22666
23190
  }, tab.label))),
22667
23191
  page === "curated"
22668
23192
  ? (state.curated
22669
- ? React.createElement(CuratedPanel, { data: state.curated, favorites, onToggleFavorite: toggleFavorite })
23193
+ ? [
23194
+ React.createElement("div", { key: "curated-segments", style: { display: "flex", gap: "4px", marginTop: "8px" } },
23195
+ [["bundles", weT("场景组合")], ["personal", weT("个人工具")]].map(([id, label]) => React.createElement("button", {
23196
+ key: id, type: "button",
23197
+ className: "we-picker__btn" + (state.curatedTab === id ? " we-picker__btn--primary" : ""),
23198
+ onClick: () => setState((prev) => ({ ...prev, curatedTab: id })),
23199
+ }, label))),
23200
+ state.curatedTab === "personal"
23201
+ ? React.createElement(PersonalPanel, { key: "personal", tools: state.curated.personalTools })
23202
+ : React.createElement(CuratedPanel, {
23203
+ key: "bundles", data: state.curated, favorites, onToggleFavorite: toggleFavorite,
23204
+ agentsAvailable: state.agentsAvailable === true,
23205
+ }),
23206
+ ]
22670
23207
  : React.createElement("div", { className: "we-picker__hint", style: { marginTop: "10px" } }, weT("精选读取失败,重开设置页再试")))
22671
23208
  : React.createElement(CapGroup, {
22672
23209
  title: page === "work" ? weT("工作能力") : weT("娱乐"),
@@ -23183,6 +23720,19 @@ window.__ModuleLoader__.load({
23183
23720
  try { window.dispatchEvent(new CustomEvent("we-pet-talk")); } catch { /* ignore */ }
23184
23721
  closeMenu();
23185
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
+ });
23186
23736
  menu.appendChild(buildMenuItem(weT("再大一点"), () => { applyScale(scale + 0.2); closeMenu(); }));
23187
23737
  menu.appendChild(buildMenuItem(weT("再小一点"), () => { applyScale(Math.max(0.5, scale - 0.2)); closeMenu(); }));
23188
23738
  menu.appendChild(buildMenuItem(weT("回右下角"), () => {
@@ -25083,6 +25633,11 @@ window.__ModuleLoader__.load({
25083
25633
  const PET_TTS_MAX_PIECES = 8;
25084
25634
  /** 与宿主 `TTS_MAX_CHARS` 对齐的总上限。 */
25085
25635
  const PET_TTS_MAX_CHARS = 240;
25636
+ /**
25637
+ * 句间静音(200–350ms,任务书 §11③):不靠标点让引擎停顿(那会被念成“逗号/句号”),
25638
+ * 而是由播放队列在两句之间插一段静音 —— 有停顿,但合成文本里已经没有标点。
25639
+ */
25640
+ const PET_TTS_GAP_MS = 260;
25086
25641
 
25087
25642
  /**
25088
25643
  * 纯函数:把一段文字切成“适合一句一合成”的片段。
@@ -25305,6 +25860,11 @@ window.__ModuleLoader__.load({
25305
25860
  onError(error);
25306
25861
  break;
25307
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
+ }
25308
25868
  }
25309
25869
  } finally {
25310
25870
  busy = false;
@@ -25350,13 +25910,23 @@ window.__ModuleLoader__.load({
25350
25910
  if (disposed) return false;
25351
25911
  const cfg = getVoice() || {};
25352
25912
  if (cfg.muted === true) { onState('idle'); return false; }
25353
- const pieces = petTtsSplit(text);
25913
+ let pieces = petTtsSplit(text);
25354
25914
  if (!pieces.length) return false;
25355
25915
  if (!AudioCtor) {
25356
25916
  onError({ code: 'tts-no-audio', hint: '这个环境不能播放声音' });
25357
25917
  return false;
25358
25918
  }
25359
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
+ }
25360
25930
  const voice = String(speechOpts.voice || cfg.name || '');
25361
25931
  const rawRate = speechOpts.rate !== undefined ? speechOpts.rate : cfg.rate;
25362
25932
  const rate = Number.isFinite(Number(rawRate)) ? Number(rawRate) : 0;
@@ -25554,6 +26124,17 @@ window.__ModuleLoader__.load({
25554
26124
  let petChatVoice = { name: '', muted: false, rate: 0, continuous: true, listenPaused: false };
25555
26125
  /** pre.65:本轮输入方式决定长度策略(语音 1–3 句;文字可长)。 */
25556
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;
25557
26138
  /** 当前 active persona(只用于提示/排障;宿主以 index.active 为准,避免切换后发旧 id)。 */
25558
26139
  let petChatPersonaId = '';
25559
26140
  async function petChatRefreshVoice() {
@@ -25571,6 +26152,10 @@ window.__ModuleLoader__.load({
25571
26152
  listenPaused: doc.voice.listenPaused === true,
25572
26153
  };
25573
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);
25574
26159
  } catch { /* 读不到就用默认(不静音) */ }
25575
26160
  // 「暂停说话 / 暂停聆听」都是持久开关:设置页/右键改完立刻生效。
25576
26161
  petChatSpeakPaused = petChatVoice.muted === true;
@@ -25578,9 +26163,29 @@ window.__ModuleLoader__.load({
25578
26163
  petChatContinuousPaused = petChatVoice.listenPaused === true;
25579
26164
  petBubble.setVoiceFlags({ speakPaused: petChatSpeakPaused, listenPaused: petChatContinuousPaused });
25580
26165
  petChatPublishContinuousState();
26166
+ petChatApplyModeUi();
26167
+ if (petChatProactiveEnabled) petChatMindStart();
25581
26168
  return petChatVoice;
25582
26169
  }
25583
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
+
25584
26189
  /* ── 常驻聆听(任务 §4):装好就在听;半双工;「暂停说话 / 暂停聆听」两个开关 ── *
25585
26190
  *
25586
26191
  * 状态机:idle → listening → thinking → speaking → listening(循环)
@@ -25625,6 +26230,8 @@ window.__ModuleLoader__.load({
25625
26230
  active: petChatContinuousActive === true,
25626
26231
  paused: petChatContinuousPaused === true,
25627
26232
  rounds: petChatContinuousRounds,
26233
+ mode: petChatConversationMode,
26234
+ voiceLength: petChatVoiceLength,
25628
26235
  },
25629
26236
  }));
25630
26237
  window.dispatchEvent(new CustomEvent('we-pet-voice-state', {
@@ -26170,7 +26777,10 @@ window.__ModuleLoader__.load({
26170
26777
  },
26171
26778
  onState: (kind) => { petBubble.setState(kind); },
26172
26779
  onIdle: () => {
26173
- petBubble.hide(3000);
26780
+ // v1.2:故事/树洞读完不马上收起(否则 800 字故事刚读完就消失,没法回看)。
26781
+ if (petChatConversationMode === 'story') { /* 保留气泡,由用户点关闭或「缩短」 */ }
26782
+ else if (petChatConversationMode === 'treehole') petBubble.hide(10000);
26783
+ else petBubble.hide(3000);
26174
26784
  petChatListeningNow = false;
26175
26785
  // 播完 150ms 自动恢复听(半双工:朗读期间绝不录音)。
26176
26786
  if (petChatContinuousActive && !petChatContinuousPaused) petChatContinuousArm(PET_CHAT_LISTEN_RESUME_MS);
@@ -26338,6 +26948,16 @@ window.__ModuleLoader__.load({
26338
26948
  return;
26339
26949
  }
26340
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
+ }
26341
26961
  const turnStartAt = Date.now();
26342
26962
  let firstTokenAt = 0;
26343
26963
  let firstAudioAt = 0;
@@ -26351,7 +26971,13 @@ window.__ModuleLoader__.load({
26351
26971
  // “想”态:模型还在回,先不给“说”的波形
26352
26972
  petBubble.setState('think');
26353
26973
  // 新一轮回答从空气泡开始(否则会追加到上一轮回答的尾部)。
26354
- petBubble.clear();
26974
+ // v1.2「继续」:不清空,用两个换行接在原文后面(故事分章阅读)。
26975
+ if (petChatKeepBubble) {
26976
+ petBubble.append('\n\n');
26977
+ petChatKeepBubble = false;
26978
+ } else {
26979
+ petBubble.clear();
26980
+ }
26355
26981
  // v2 环境感知:壁纸名 / 正在播放由前端补(宿主不认识 selection 与媒体桥实例)。
26356
26982
  const context = await petChatEnvSnapshot();
26357
26983
  // ⚠️ apiFetch 的返回值里**已经带上了原始 Response**(字段 `response`)。
@@ -26369,6 +26995,8 @@ window.__ModuleLoader__.load({
26369
26995
  context,
26370
26996
  // pre.65:显式输入方式让宿主做“语音 1–3 句 / 文字可长”的长度策略。
26371
26997
  inputMode: petChatInputMode === 'voice' ? 'voice' : 'text',
26998
+ // v1.2:会话模式随每次请求上报(旧宿主安全忽略未知字段)。
26999
+ conversationMode: petChatConversationMode,
26372
27000
  }),
26373
27001
  // ⚠️ 必须 parse:'none'。默认路径会 await response.json(),
26374
27002
  // 那会把 SSE 流**整个消费掉**(等到生成结束、再解析失败),
@@ -26400,16 +27028,30 @@ window.__ModuleLoader__.load({
26400
27028
  */
26401
27029
  let speakBuffer = '';
26402
27030
  let queuedSpeech = 0;
26403
- const enqueueSpeech = (piece) => {
26404
- const line = String(piece || '').trim();
27031
+ /** v1.2:故事模式每 2 句合成一段(1–3 句/段的队列播放),减少碎片化。 */
27032
+ let speechBatch = '';
27033
+ /** 本轮回答全文(故事模式的「重讲 / 缩短」用)。 */
27034
+ let turnReply = '';
27035
+ const enqueueSpeech = (piece, flush) => {
27036
+ let line = String(piece || '').trim();
26405
27037
  if (!line) return;
26406
27038
  // 任务 §4③:「暂停说话」= 跳过 TTS 队列,只出字幕;状态条显示「🔇 仅文字」。
26407
27039
  if (petChatSpeakPaused) {
26408
27040
  petBubble.setState('muted');
26409
27041
  return;
26410
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
+ }
26411
27050
  // v2:本轮语速由宿主 meta 给(夜间/疲惫 -1 = -10%);再叠加当前人设的 voice.rate。
26412
- if (petSpeak(line, { rate: petChatSpeechRate + (Number(petChatVoice.rate) || 0) })) {
27051
+ if (petSpeak(line, {
27052
+ rate: petChatSpeechRate + (Number(petChatVoice.rate) || 0),
27053
+ ...(petChatConversationMode === 'story' ? { group: 2 } : {}),
27054
+ })) {
26413
27055
  queuedSpeech += 1;
26414
27056
  if (!firstAudioAt) firstAudioAt = Date.now(); // 首段音频交给播放器的时刻
26415
27057
  }
@@ -26472,6 +27114,16 @@ window.__ModuleLoader__.load({
26472
27114
  if (Number.isFinite(Number(payload.rate))) petChatSpeechRate = Number(payload.rate);
26473
27115
  continue;
26474
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
+ }
26475
27127
  // 防兜底:模型偶尔仍会输出 {"reply":"…","emotion":"…"} 信封,
26476
27128
  // 这里只把 reply 的正文喂给气泡(不显示大括号/字段名/emotion)。
26477
27129
  if (typeof payload.t === 'string') {
@@ -26494,6 +27146,7 @@ window.__ModuleLoader__.load({
26494
27146
  // 气泡始终显示**完整回答**(逐段追加,长文在 160px 内滚动);
26495
27147
  // 朗读只负责切句与“说”状态,不再改写气泡内容。
26496
27148
  petBubble.append(piece);
27149
+ turnReply += piece;
26497
27150
  speakBuffer += piece;
26498
27151
  const split = petTtsSentences(speakBuffer);
26499
27152
  for (const sentence of split.sentences) enqueueSpeech(sentence);
@@ -26504,7 +27157,10 @@ window.__ModuleLoader__.load({
26504
27157
  }
26505
27158
  }
26506
27159
  // 最后一段没有句末标点也要念(比如“我也在”)
26507
- enqueueSpeech(speakBuffer);
27160
+ enqueueSpeech(speakBuffer, true);
27161
+ // v1.2:故事模式记住全文(「重讲 / 缩短」不再问模型),并给出操作按钮。
27162
+ petChatLastReply = String(turnReply || '').trim();
27163
+ if (petChatConversationMode === 'story' && petChatLastReply) petChatStoryBarShow();
26508
27164
  if (typeof onState === 'function') onState({ state: 'idle' });
26509
27165
  // 本轮成功:常驻聆听继续(任务 §4:装好就在听,不靠"点了才听");
26510
27166
  // 有朗读时等 onIdle 播完再开麦(半双工),没朗读(暂停说话/静音)直接 150ms 后排下一轮。
@@ -26516,7 +27172,12 @@ window.__ModuleLoader__.load({
26516
27172
  if (!queuedSpeech && !singStarted) petChatContinuousArm();
26517
27173
  // 没有任何一句进入朗读(暂停说话 / 合成不可用)⇒ 字幕照常显示,3 秒后淡出。
26518
27174
  // 唱歌时气泡归歌词用:不提前收,播完由 petChatSingPlay 收。
26519
- if (!queuedSpeech && !singStarted) petBubble.hide(3000);
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
+ }
26520
27181
  petChatReportLatency(turnStartAt, firstTokenAt, firstAudioAt);
26521
27182
  petChatTurnEnd();
26522
27183
  },
@@ -26606,6 +27267,122 @@ window.__ModuleLoader__.load({
26606
27267
  if (!petSpeak(line)) petBubble.hide(3000);
26607
27268
  }
26608
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
+
26609
27386
  /** 每次点桌宠递增;收起/重开时让旧的 ASR 等待自动作废。 */
26610
27387
  let petChatWakeSeq = 0;
26611
27388
 
@@ -26799,6 +27576,12 @@ window.__ModuleLoader__.load({
26799
27576
  };
26800
27577
  window.addEventListener('we-pet-speak-pause', onSpeakPauseEvent);
26801
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);
26802
27585
  // 页面隐藏:暂时停麦(不持久化,回到页面自动恢复);不偷偷在后台开麦。
26803
27586
  const onVisibility = () => {
26804
27587
  if (typeof document === 'undefined') return;
@@ -26844,6 +27627,9 @@ window.__ModuleLoader__.load({
26844
27627
  isListening: () => petChatListeningNow === true,
26845
27628
  isSpeakPaused: () => petChatSpeakPaused === true,
26846
27629
  isListenPaused: () => petChatContinuousPaused === true,
27630
+ // v1.2:会话模式(右键/设置页切换;判据也用它)
27631
+ getMode: () => petChatConversationMode,
27632
+ setMode: (mode) => petChatSetMode(mode),
26847
27633
  };
26848
27634
  } catch { /* 被别的插件占用就只保留事件通道 */ }
26849
27635
  return () => {
@@ -26852,6 +27638,7 @@ window.__ModuleLoader__.load({
26852
27638
  window.removeEventListener('we-pet-continuous', onContinuousEvent);
26853
27639
  window.removeEventListener('we-pet-speak-pause', onSpeakPauseEvent);
26854
27640
  window.removeEventListener('we-pet-listen-pause', onListenPauseEvent);
27641
+ window.removeEventListener('we-pet-mode', onModeEvent);
26855
27642
  document.removeEventListener('click', onDocumentClick, true);
26856
27643
  document.removeEventListener('keydown', onKeyDown, true);
26857
27644
  document.removeEventListener('visibilitychange', onVisibility);
@@ -26861,6 +27648,8 @@ window.__ModuleLoader__.load({
26861
27648
  // v5 §6:深度思考的 3s 提示定时器也要随卸载清掉(否则会在 dispose 后改气泡)。
26862
27649
  if (petChatDeepTimer != null) { clearTimeout(petChatDeepTimer); petChatDeepTimer = null; }
26863
27650
  if (petSingTimer != null) { clearInterval(petSingTimer); petSingTimer = null; }
27651
+ if (petChatMindTimer != null) { clearInterval(petChatMindTimer); petChatMindTimer = null; }
27652
+ petChatStoryBarHide();
26864
27653
  petChatWallpaperTimer = null;
26865
27654
  petChatWorkTimer = null;
26866
27655
  petChatGreetingTimer = null;