dsh-folia 1.2.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/lib/client.js CHANGED
@@ -783,6 +783,7 @@ window.__ModuleLoader__.load({
783
783
  "复制失败:这个环境没有剪贴板权限": "Copy failed: no clipboard permission in this environment",
784
784
  // v1.2:故事模式按钮 / 观察模式 / 宿主错误提示
785
785
  "继续": "Continue",
786
+ "继续讲": "Continue the story",
786
787
  "重讲": "Tell again",
787
788
  "缩短": "Shorten",
788
789
  "观察中": "Observing",
@@ -837,7 +838,10 @@ window.__ModuleLoader__.load({
837
838
  "读不到这个音频文件": "Could not read this audio file",
838
839
  "已导入:{n}": "Imported: {n}",
839
840
  "导入失败": "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.",
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.",
841
845
  // pre.64:大脑 v2(壁纸动作的客户端执行反馈)
842
846
  "正在换壁纸…": "Switching wallpaper…",
843
847
  "没找到叫「{name}」的壁纸": "No wallpaper named '{name}' was found",
@@ -8671,8 +8675,8 @@ window.__ModuleLoader__.load({
8671
8675
  voice: { name: '', muted: false },
8672
8676
  // 唤醒:点一下默认开;叫名字默认关(S6 才实现,先在设置里留位)
8673
8677
  wake: { click: true, name: false, keyword: '' },
8674
- // v1.2:会话模式(聊天 / 讲故事 / 树洞 / 只观察)。默认聊天。
8675
- conversationMode: 'chat',
8678
+ // v1.3:不再有“会话模式”。旧字段保留兼容(读档时强制 auto,运行时按每轮文本判定)。
8679
+ conversationMode: 'auto',
8676
8680
  // v1.2:语音回答长度(0 = 不限;默认 8 句 —— 旧版写死 3 句,讲故事被截断的根因)。
8677
8681
  voiceLength: 8,
8678
8682
  // v1.2:主动思维(默认关;15/30/60 分钟才开)。勿扰时段跨零点也支持。
@@ -9397,8 +9401,8 @@ window.__ModuleLoader__.load({
9397
9401
  const PET_CHAT_API_KEY_MAX = 400;
9398
9402
  const PET_CHAT_MODEL_MAX = 120;
9399
9403
  const PET_CHAT_PERSONA_MAX = 200;
9400
- /** v1.2:会话模式 / 语音长度 / 主动搭话 / 屏幕感知(全部**默认关闭**高风险项)。 */
9401
- const PET_CHAT_CONVERSATION_MODES = Object.freeze(['chat', 'story', 'treehole', 'observe']);
9404
+ /** v1.3:会话策略改为**每轮意图判定**;conversationMode 只保留旧字段兼容,运行时忽略。 */
9405
+ const PET_CHAT_CONVERSATION_MODES = Object.freeze(['auto', 'chat', 'story', 'treehole', 'observe']);
9402
9406
  /** 语音回答长度:0 = 不限;默认 8 句(v1.2 从 3 句改上来的)。 */
9403
9407
  const PET_CHAT_VOICE_LENGTHS = Object.freeze([0, 3, 8]);
9404
9408
  /** 主动搭话间隔(分钟):0 = 关。默认关。 */
@@ -9472,8 +9476,8 @@ window.__ModuleLoader__.load({
9472
9476
  name: wake.name === true,
9473
9477
  keyword: petChatStr(wake.keyword, 40).trim(),
9474
9478
  },
9475
- // v1.2:认不出的模式 / 长度 / 间隔一律回落默认(不猜近似值)
9476
- conversationMode: PET_CHAT_CONVERSATION_MODES.includes(src.conversationMode) ? src.conversationMode : def.conversationMode,
9479
+ // v1.3:conversationMode 只保留字段兼容;**一律回落 auto**(旧档里的 story/treehole 不再生效)。
9480
+ conversationMode: 'auto',
9477
9481
  voiceLength: PET_CHAT_VOICE_LENGTHS.includes(Number(src.voiceLength)) ? Number(src.voiceLength) : def.voiceLength,
9478
9482
  proactive: {
9479
9483
  enabled: proactive.enabled === true,
@@ -21389,13 +21393,17 @@ window.__ModuleLoader__.load({
21389
21393
  }, rows);
21390
21394
  }
21391
21395
 
21392
- /** 设置页:三分页 + 音色库 + 一键启用。 */
21396
+ /** 设置页:四分页 + 音色库 + 一键启用。 */
21393
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';
21394
21402
  const [draft, setDraft] = React.useState(CHAT_DEFAULTS);
21395
21403
  const [status, setStatus] = React.useState({ ok: null, text: '' });
21396
21404
  const [note, setNote] = React.useState(null);
21397
21405
  const [busy, setBusy] = React.useState(false);
21398
- const [tab, setTab] = React.useState('assistant');
21406
+ const [tab, setTab] = React.useState(initialTab);
21399
21407
  const [workPlugins, setWorkPlugins] = React.useState(null);
21400
21408
  const [voices, setVoices] = React.useState(null);
21401
21409
  /** v1.2:Edge 429 等“在线音色暂时不可用”的提示(列表里不再堆灰项)。 */
@@ -21953,7 +21961,7 @@ window.__ModuleLoader__.load({
21953
21961
  : null);
21954
21962
  child.push(React.createElement('div', { key: 'title', style: { fontWeight: 600, margin: '14px 0 4px', fontSize: '13px' } }, weT('智能大肥鱼')));
21955
21963
  child.push(React.createElement('div', { key: 'hint', className: 'we-picker__hint', style: { margin: '0 0 6px' } },
21956
- weT('填 Key、起名字、选音色;对话模式、主动搭话、屏幕感知都在「对话与隐私」里,默认全关。')));
21964
+ weT('填 Key、起名字、选音色;语音长度、主动搭话、屏幕感知都在「对话与隐私」里,默认全关。')));
21957
21965
 
21958
21966
  const tabs = [
21959
21967
  ['assistant', weT('助手')],
@@ -22002,8 +22010,6 @@ window.__ModuleLoader__.load({
22002
22010
  }
22003
22011
 
22004
22012
  if (tab === 'behavior') {
22005
- const mode = ['chat', 'story', 'treehole', 'observe'].includes(String(draft.conversationMode))
22006
- ? draft.conversationMode : 'chat';
22007
22013
  const pro = Object.assign({}, CHAT_DEFAULTS.proactive, draft.proactive || {});
22008
22014
  const screen = Object.assign({}, CHAT_DEFAULTS.screen, draft.screen || {});
22009
22015
  const behaviorPage = [];
@@ -22018,11 +22024,9 @@ window.__ModuleLoader__.load({
22018
22024
  type: 'checkbox', checked, disabled: busy, onChange: (e) => onChange(e.target.checked),
22019
22025
  }), weT(label));
22020
22026
 
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('聊天=日常短答;讲故事=不按句数截断;树洞=先接情绪;只观察=不回答、只记不说。')));
22027
+ // v1.3:不再有「对话模式」下拉 —— 讲故事/共情由每一句话自动判定。
22028
+ behaviorPage.push(React.createElement('div', { key: 'intent-hint', className: 'we-picker__hint', style: { margin: '0 0 6px' } },
22029
+ weT('不用先选模式:说「讲个故事」就直接讲,说「今天好累」就先共情;下一轮自动回到聊天。')));
22026
22030
 
22027
22031
  behaviorPage.push(row('voice-length', '语音回答长度', selectOf('vlen', String(draft.voiceLength), [
22028
22032
  ['3', weT('3 句')], ['8', weT('8 句')], ['0', weT('不限')],
@@ -22564,13 +22568,36 @@ window.__ModuleLoader__.load({
22564
22568
  }
22565
22569
 
22566
22570
  /**
22567
- * 「智能大肥鱼」一级设置页。只做版面装配:标题 + 三分页表单。
22571
+ * 「智能大肥鱼」一级设置页。只做版面装配:标题 + 入口按钮 + 人设区。
22568
22572
  * 设置导航的注册在 `src/client.js`(id=folia-assistant,order 502)。
22573
+ *
22574
+ * v1.3:**入口必须第一屏可见**。上一版只渲染 PersonaSection,PetChatSettings
22575
+ * 虽然存在却永远挂不上去(用户找不到「对话与隐私」)。
22569
22576
  */
22570
22577
  function AssistantSection() {
22578
+ const [settingsOpen, setSettingsOpen] = React.useState(false);
22571
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
+ },
22572
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('⚙ 对话与隐私 / 朗读 / 工作能力'))),
22573
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,
22574
22601
  );
22575
22602
  }
22576
22603
 
@@ -23720,19 +23747,6 @@ window.__ModuleLoader__.load({
23720
23747
  try { window.dispatchEvent(new CustomEvent("we-pet-talk")); } catch { /* ignore */ }
23721
23748
  closeMenu();
23722
23749
  }));
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
- });
23736
23750
  menu.appendChild(buildMenuItem(weT("再大一点"), () => { applyScale(scale + 0.2); closeMenu(); }));
23737
23751
  menu.appendChild(buildMenuItem(weT("再小一点"), () => { applyScale(Math.max(0.5, scale - 0.2)); closeMenu(); }));
23738
23752
  menu.appendChild(buildMenuItem(weT("回右下角"), () => {
@@ -26125,16 +26139,20 @@ window.__ModuleLoader__.load({
26125
26139
  /** pre.65:本轮输入方式决定长度策略(语音 1–3 句;文字可长)。 */
26126
26140
  let petChatInputMode = 'text';
26127
26141
  /**
26128
- * v1.2 会话模式:chat(默认)/ story(讲故事)/ treehole(树洞)/ observe(只观察)。
26129
- * 模式随每次 /pet-chat/chat 上报(宿主旧版本会安全忽略未知字段)。
26142
+ * v1.3:**本轮意图策略**(不持久化)。宿主在 meta.policy 里下发 chat/story/empathy;
26143
+ * 客户端只按这一轮决定 TTS 分批、气泡保留与故事按钮,下一轮自动回到 chat。
26130
26144
  */
26131
- let petChatConversationMode = 'chat';
26132
- /** v1.2 语音回答长度(0 = 不限;默认 8 句 —— 旧版宿主写死 3 句)。 */
26145
+ let petChatTurnPolicy = 'chat';
26146
+ /** 上一轮策略:onIdle 在 done 之后才触发,不能丢。 */
26147
+ let petChatLastTurnPolicy = 'chat';
26148
+ /** v1.3 语音回答长度(0 = 不限;默认 8 句)。 */
26133
26149
  let petChatVoiceLength = 8;
26134
- /** 故事模式:上一轮全文(「重讲 / 缩短」直接用它,不再问模型)。 */
26150
+ /** 故事轮:上一轮全文(「重讲 / 缩短」直接用它,不再问模型)。 */
26135
26151
  let petChatLastReply = '';
26136
- /** 「继续」:下一轮不清空气泡,接在原文后面。 */
26152
+ /** 「继续讲」:下一轮不清空气泡,接在原文后面。 */
26137
26153
  let petChatKeepBubble = false;
26154
+ /** 屏幕感知状态(用于「👁 观察中」提示;只观察 = 屏幕感知开 + 主动搭话关)。 */
26155
+ let petChatScreenMode = 'off';
26138
26156
  /** 当前 active persona(只用于提示/排障;宿主以 index.active 为准,避免切换后发旧 id)。 */
26139
26157
  let petChatPersonaId = '';
26140
26158
  async function petChatRefreshVoice() {
@@ -26152,10 +26170,10 @@ window.__ModuleLoader__.load({
26152
26170
  listenPaused: doc.voice.listenPaused === true,
26153
26171
  };
26154
26172
  }
26155
- // v1.2:会话模式 / 语音长度由宿主设置下发(默认 chat / 8)。
26156
- if (typeof doc.conversationMode === 'string') petChatConversationMode = petChatNormalizeMode(doc.conversationMode);
26173
+ // v1.3:设置只下发语音长度 / 屏幕感知 / 主动搭话;不再有“模式”。
26157
26174
  if (Number.isFinite(Number(doc.voiceLength))) petChatVoiceLength = Math.max(0, Math.round(Number(doc.voiceLength)));
26158
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';
26159
26177
  } catch { /* 读不到就用默认(不静音) */ }
26160
26178
  // 「暂停说话 / 暂停聆听」都是持久开关:设置页/右键改完立刻生效。
26161
26179
  petChatSpeakPaused = petChatVoice.muted === true;
@@ -26163,21 +26181,18 @@ window.__ModuleLoader__.load({
26163
26181
  petChatContinuousPaused = petChatVoice.listenPaused === true;
26164
26182
  petBubble.setVoiceFlags({ speakPaused: petChatSpeakPaused, listenPaused: petChatContinuousPaused });
26165
26183
  petChatPublishContinuousState();
26166
- petChatApplyModeUi();
26184
+ petChatApplyPrivacyUi();
26167
26185
  if (petChatProactiveEnabled) petChatMindStart();
26168
26186
  return petChatVoice;
26169
26187
  }
26170
26188
 
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() {
26189
+ /**
26190
+ * v1.3:只观察 = **屏幕感知开 + 主动搭话关**(隐私设置),不是对话模式。
26191
+ * 满足时状态条常驻「👁 观察中」;关闭屏幕感知即收起。
26192
+ */
26193
+ function petChatApplyPrivacyUi() {
26179
26194
  try {
26180
- if (petChatConversationMode === 'observe') {
26195
+ if (petChatScreenMode !== 'off' && petChatProactiveEnabled !== true) {
26181
26196
  petBubble.status('info', '👁 ' + weT('观察中'), { delay: 0 });
26182
26197
  } else {
26183
26198
  petBubble.hideStatus(0);
@@ -26230,7 +26245,6 @@ window.__ModuleLoader__.load({
26230
26245
  active: petChatContinuousActive === true,
26231
26246
  paused: petChatContinuousPaused === true,
26232
26247
  rounds: petChatContinuousRounds,
26233
- mode: petChatConversationMode,
26234
26248
  voiceLength: petChatVoiceLength,
26235
26249
  },
26236
26250
  }));
@@ -26777,9 +26791,10 @@ window.__ModuleLoader__.load({
26777
26791
  },
26778
26792
  onState: (kind) => { petBubble.setState(kind); },
26779
26793
  onIdle: () => {
26780
- // v1.2:故事/树洞读完不马上收起(否则 800 字故事刚读完就消失,没法回看)。
26781
- if (petChatConversationMode === 'story') { /* 保留气泡,由用户点关闭或「缩短」 */ }
26782
- else if (petChatConversationMode === 'treehole') petBubble.hide(10000);
26794
+ // v1.3:故事轮读完保留气泡(可回看/「缩短」);情绪轮多留一会儿;其余 3 秒淡出。
26795
+ const policy = petChatLastTurnPolicy;
26796
+ if (policy === 'story') { /* 保留气泡,由用户点关闭或「缩短」 */ }
26797
+ else if (policy === 'empathy') petBubble.hide(10000);
26783
26798
  else petBubble.hide(3000);
26784
26799
  petChatListeningNow = false;
26785
26800
  // 播完 150ms 自动恢复听(半双工:朗读期间绝不录音)。
@@ -26948,16 +26963,9 @@ window.__ModuleLoader__.load({
26948
26963
  return;
26949
26964
  }
26950
26965
  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
- }
26966
+ // v1.3:每一轮都从 chat 开始;故事/情绪由宿主按这句话判定(meta.policy 回来后再切)。
26967
+ petChatTurnPolicy = 'chat';
26968
+ petChatStoryBarHide();
26961
26969
  const turnStartAt = Date.now();
26962
26970
  let firstTokenAt = 0;
26963
26971
  let firstAudioAt = 0;
@@ -26995,8 +27003,6 @@ window.__ModuleLoader__.load({
26995
27003
  context,
26996
27004
  // pre.65:显式输入方式让宿主做“语音 1–3 句 / 文字可长”的长度策略。
26997
27005
  inputMode: petChatInputMode === 'voice' ? 'voice' : 'text',
26998
- // v1.2:会话模式随每次请求上报(旧宿主安全忽略未知字段)。
26999
- conversationMode: petChatConversationMode,
27000
27006
  }),
27001
27007
  // ⚠️ 必须 parse:'none'。默认路径会 await response.json(),
27002
27008
  // 那会把 SSE 流**整个消费掉**(等到生成结束、再解析失败),
@@ -27028,9 +27034,9 @@ window.__ModuleLoader__.load({
27028
27034
  */
27029
27035
  let speakBuffer = '';
27030
27036
  let queuedSpeech = 0;
27031
- /** v1.2:故事模式每 2 句合成一段(1–3 句/段的队列播放),减少碎片化。 */
27037
+ /** v1.3:故事轮每 2 句合成一段(1–3 句/段的队列播放),减少碎片化。 */
27032
27038
  let speechBatch = '';
27033
- /** 本轮回答全文(故事模式的「重讲 / 缩短」用)。 */
27039
+ /** 本轮回答全文(故事轮「重讲 / 缩短」用)。 */
27034
27040
  let turnReply = '';
27035
27041
  const enqueueSpeech = (piece, flush) => {
27036
27042
  let line = String(piece || '').trim();
@@ -27040,7 +27046,7 @@ window.__ModuleLoader__.load({
27040
27046
  petBubble.setState('muted');
27041
27047
  return;
27042
27048
  }
27043
- if (petChatConversationMode === 'story') {
27049
+ if (petChatTurnPolicy === 'story') {
27044
27050
  // 2 句一批;flush 时把尾句也送出去。每段仍受宿主 240 字上限约束(2 句通常 < 100 字)。
27045
27051
  speechBatch += line;
27046
27052
  if (!flush && speechBatch.length < 60) return;
@@ -27050,7 +27056,7 @@ window.__ModuleLoader__.load({
27050
27056
  // v2:本轮语速由宿主 meta 给(夜间/疲惫 -1 = -10%);再叠加当前人设的 voice.rate。
27051
27057
  if (petSpeak(line, {
27052
27058
  rate: petChatSpeechRate + (Number(petChatVoice.rate) || 0),
27053
- ...(petChatConversationMode === 'story' ? { group: 2 } : {}),
27059
+ ...(petChatTurnPolicy === 'story' ? { group: 2 } : {}),
27054
27060
  })) {
27055
27061
  queuedSpeech += 1;
27056
27062
  if (!firstAudioAt) firstAudioAt = Date.now(); // 首段音频交给播放器的时刻
@@ -27081,6 +27087,11 @@ window.__ModuleLoader__.load({
27081
27087
  if (eventName === 'meta') {
27082
27088
  petChatMood = String(payload.mood || 'neutral');
27083
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
+ }
27084
27095
  // v5 §5:深度档 >3s 显示「深度思考中…」(quick/standard 秒回,不闪这一下)。
27085
27096
  if (payload.tier === 'deep') {
27086
27097
  if (petChatDeepTimer != null) clearTimeout(petChatDeepTimer);
@@ -27112,6 +27123,21 @@ window.__ModuleLoader__.load({
27112
27123
  }
27113
27124
  if (eventName === 'done') {
27114
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
+ }
27115
27141
  continue;
27116
27142
  }
27117
27143
  /**
@@ -27158,9 +27184,10 @@ window.__ModuleLoader__.load({
27158
27184
  }
27159
27185
  // 最后一段没有句末标点也要念(比如“我也在”)
27160
27186
  enqueueSpeech(speakBuffer, true);
27161
- // v1.2:故事模式记住全文(「重讲 / 缩短」不再问模型),并给出操作按钮。
27187
+ // v1.3:只有**本轮**是 story 才给「继续讲 / 重讲 / 缩短」;下一轮自动消失。
27162
27188
  petChatLastReply = String(turnReply || '').trim();
27163
- if (petChatConversationMode === 'story' && petChatLastReply) petChatStoryBarShow();
27189
+ petChatLastTurnPolicy = petChatTurnPolicy;
27190
+ if (petChatTurnPolicy === 'story' && petChatLastReply) petChatStoryBarShow();
27164
27191
  if (typeof onState === 'function') onState({ state: 'idle' });
27165
27192
  // 本轮成功:常驻聆听继续(任务 §4:装好就在听,不靠"点了才听");
27166
27193
  // 有朗读时等 onIdle 播完再开麦(半双工),没朗读(暂停说话/静音)直接 150ms 后排下一轮。
@@ -27172,10 +27199,10 @@ window.__ModuleLoader__.load({
27172
27199
  if (!queuedSpeech && !singStarted) petChatContinuousArm();
27173
27200
  // 没有任何一句进入朗读(暂停说话 / 合成不可用)⇒ 字幕照常显示,3 秒后淡出。
27174
27201
  // 唱歌时气泡归歌词用:不提前收,播完由 petChatSingPlay 收。
27175
- // v1.2:故事保留气泡(用户要能回看/点「缩短」);树洞多留一会儿。
27202
+ // v1.3:故事轮保留气泡(用户要能回看/点「缩短」);情绪轮多留一会儿。
27176
27203
  if (!queuedSpeech && !singStarted) {
27177
- if (petChatConversationMode === 'story') { /* 不自动收 */ }
27178
- else if (petChatConversationMode === 'treehole') petBubble.hide(10000);
27204
+ if (petChatTurnPolicy === 'story') { /* 不自动收 */ }
27205
+ else if (petChatTurnPolicy === 'empathy') petBubble.hide(10000);
27179
27206
  else petBubble.hide(3000);
27180
27207
  }
27181
27208
  petChatReportLatency(turnStartAt, firstTokenAt, firstAudioAt);
@@ -27315,12 +27342,12 @@ window.__ModuleLoader__.load({
27315
27342
  });
27316
27343
  return button;
27317
27344
  };
27318
- bar.appendChild(make(weT('继续'), () => {
27345
+ bar.appendChild(make(weT('继续讲'), () => {
27319
27346
  petChatStoryBarHide();
27320
27347
  petChatInputMode = 'text';
27321
27348
  petChatKeepBubble = true;
27322
27349
  petBubble.setState('think');
27323
- void petVoiceIn.postChat('继续讲下去,接着刚才的情节,不要重复已经讲过的内容。');
27350
+ void petVoiceIn.postChat('继续讲');
27324
27351
  }));
27325
27352
  bar.appendChild(make(weT('重讲'), () => {
27326
27353
  petChatStoryBarHide();
@@ -27349,21 +27376,13 @@ window.__ModuleLoader__.load({
27349
27376
  petChatStoryBar = bar;
27350
27377
  }
27351
27378
 
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 分钟问一次宿主“现在想不想说点什么” ─────── */
27379
+ /* ── v1.3 主动思维:客户端每 5 分钟问一次宿主“现在想不想说点什么” ─────── */
27361
27380
 
27362
27381
  let petChatProactiveEnabled = false;
27363
27382
  let petChatMindTimer = null;
27364
27383
 
27365
27384
  async function petChatMindPoll() {
27366
- if (!petChatProactiveEnabled || petChatConversationMode === 'observe') return;
27385
+ if (!petChatProactiveEnabled) return;
27367
27386
  if (!petChatProactiveAllowed()) return;
27368
27387
  try {
27369
27388
  const resp = await apiPostJson('/pet-chat/mind/tick', {
@@ -27576,12 +27595,6 @@ window.__ModuleLoader__.load({
27576
27595
  };
27577
27596
  window.addEventListener('we-pet-speak-pause', onSpeakPauseEvent);
27578
27597
  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);
27585
27598
  // 页面隐藏:暂时停麦(不持久化,回到页面自动恢复);不偷偷在后台开麦。
27586
27599
  const onVisibility = () => {
27587
27600
  if (typeof document === 'undefined') return;
@@ -27627,9 +27640,6 @@ window.__ModuleLoader__.load({
27627
27640
  isListening: () => petChatListeningNow === true,
27628
27641
  isSpeakPaused: () => petChatSpeakPaused === true,
27629
27642
  isListenPaused: () => petChatContinuousPaused === true,
27630
- // v1.2:会话模式(右键/设置页切换;判据也用它)
27631
- getMode: () => petChatConversationMode,
27632
- setMode: (mode) => petChatSetMode(mode),
27633
27643
  };
27634
27644
  } catch { /* 被别的插件占用就只保留事件通道 */ }
27635
27645
  return () => {
@@ -27638,7 +27648,6 @@ window.__ModuleLoader__.load({
27638
27648
  window.removeEventListener('we-pet-continuous', onContinuousEvent);
27639
27649
  window.removeEventListener('we-pet-speak-pause', onSpeakPauseEvent);
27640
27650
  window.removeEventListener('we-pet-listen-pause', onListenPauseEvent);
27641
- window.removeEventListener('we-pet-mode', onModeEvent);
27642
27651
  document.removeEventListener('click', onDocumentClick, true);
27643
27652
  document.removeEventListener('keydown', onKeyDown, true);
27644
27653
  document.removeEventListener('visibilitychange', onVisibility);
@@ -781,22 +781,30 @@ export function buildPersonaSystemPrompt(persona, opts = {}) {
781
781
  if (express.emoji !== true) lines.push('不要使用表情符号。');
782
782
  const voiceMode = opts.inputMode === 'voice';
783
783
  /**
784
- * v1.2 会话模式:chat(默认)/ story(长故事)/ treehole(树洞)/ observe(只观察)。
785
- * 长度规则按模式分流 —— 故事必须讲完,不再被“语音 1–3 句”的旧提示砍断。
784
+ * v1.3:**每轮意图策略**(不持久化)。`turnPolicy` 由宿主按用户这一句话判定:
785
+ * chat / story / empathy。`conversationMode` 只作为旧判据的兼容入参。
786
786
  */
787
- const conversationMode = ['chat', 'story', 'treehole', 'observe'].includes(String(opts.conversationMode || ''))
788
- ? String(opts.conversationMode) : 'chat';
787
+ const legacyMode = String(opts.conversationMode || '');
788
+ const turnPolicy = ['chat', 'story', 'empathy'].includes(String(opts.turnPolicy || ''))
789
+ ? String(opts.turnPolicy)
790
+ : (legacyMode === 'story' ? 'story' : (legacyMode === 'treehole' || legacyMode === 'empathy' ? 'empathy' : 'chat'));
789
791
  const voiceLength = [0, 3, 8].includes(Number(opts.voiceLength)) ? Number(opts.voiceLength) : 8;
790
- if (conversationMode === 'story') {
792
+ if (turnPolicy === 'story') {
791
793
  lines.push('【讲故事的规则】完整讲完一件事:有开头、发展、结尾;不要只给梗概、不要一句话总结。'
792
- + '目标 800–1200 字(用户要求更长就继续写),段落之间空一行。'
794
+ + '目标 800–1500 字(用户要求更长就继续写),段落之间空一行。'
793
795
  + '不要用 Markdown 标题/列表/加粗/代码块;不要问“要不要继续”,除非故事已经讲完。'
794
796
  + '讲完就停,不要补免责声明。');
795
- } else if (conversationMode === 'treehole') {
796
- lines.push('【树洞模式】先接住情绪,再问一个开放问题;不急着给建议、不评判、不诊断、不说“你应该”。'
797
+ const storyContext = String(opts.storyContext || '').trim();
798
+ if (storyContext) {
799
+ lines.push('【上一段故事结尾·接着写】下面是上一段最后的内容(只用于衔接,不要整段复述):\n'
800
+ + clipChars(storyContext, 1500));
801
+ }
802
+ } else if (turnPolicy === 'empathy') {
803
+ lines.push('【情绪优先】先接住情绪,再问一个开放问题;不急着给建议、不评判、不诊断、不说“你应该”。'
804
+ + '这一轮不要列 1/2/3,也不要用“首先/其次”这种步骤腔。'
797
805
  + '允许短句,也允许只有一句“我在”。只有用户明确问“怎么办”时才给建议,且最多三条。'
798
806
  + '你不是心理治疗师,也不提供医疗/法律建议;遇到自伤/危机话题,先关心安全,再建议找专业人士。');
799
- } else if (voiceMode && conversationMode === 'chat') {
807
+ } else if (voiceMode) {
800
808
  lines.push(voiceLength === 0
801
809
  ? '【长度】当前是语音播报:不限句数,把事情完整说完;仍然口语、自然,不要念 Markdown。'
802
810
  : `【长度】当前是语音播报:最多 ${voiceLength} 句,短而自然;更长的内容等用户打字再展开。`);
@@ -872,6 +880,44 @@ export function detectCrisis(text) {
872
880
  return '';
873
881
  }
874
882
 
883
+ /**
884
+ * v1.3:**每轮意图策略**(不持久化、不改任何“模式”)。
885
+ * 返回 { policy: 'chat' | 'story' | 'empathy', reason, storyContinue }。
886
+ * 只认用户这句话本身 + 上一轮是不是故事(用于“继续讲/后来呢”)。
887
+ */
888
+ const STORY_REQUEST_RE = /(?:讲|说|编|写|来)\s*(?:个|一个|一段|一篇|一则|点)?\s*(?:长一点的|长的|有趣的|好听的)?\s*(?:故事|童话|睡前故事|段子)|(?:讲|说)长一点|(?:详细|展开)(?:讲|说)|(?:给我|帮我)(?:讲|说)(?:个|一个|一段)?(?:故事|童话)/;
889
+ const STORY_CONTINUE_RE = /^(?:继续讲|接着讲|继续|接着|然后呢|后来呢|再讲(?:一个|一段)?|往下讲)/;
890
+ /** 这些句子里虽然有“讲/故事”,但不是要长故事 */
891
+ const STORY_EXCLUDE_RE = /笑话|代码|函数|接口|算法|报错|bug|原理|讲一下这个|怎么实现|如何实现/i;
892
+ const EMPATHY_WORDS_RE = /累|烦|难受|难过|委屈|低落|压力|撑不住|崩溃|想哭|失眠|孤独/;
893
+ /** 有明确任务/求建议时,不抢成“只共情” */
894
+ const TASK_OR_ADVICE_RE = /怎么办|怎么解决|如何解决|给点建议|有什么建议|帮我|请帮|查一下|查下|搜索|打开|设置|提醒|换一|切换到/;
895
+
896
+ /**
897
+ * @param {string} text
898
+ * @param {{lastWasStory?:boolean}} [context]
899
+ */
900
+ export function resolveTurnPolicy(text, context = {}) {
901
+ const raw = String(text || '').trim();
902
+ const lastWasStory = context.lastWasStory === true;
903
+ if (!raw) return { policy: 'chat', reason: 'empty', storyContinue: false };
904
+ // 危机词优先走情绪策略(宿主随后用固定安全回应,不调模型)
905
+ if (detectCrisis(raw)) return { policy: 'empathy', reason: 'crisis', storyContinue: false };
906
+ const continueHit = STORY_CONTINUE_RE.test(raw);
907
+ const explicitContinue = /继续讲|接着讲|往下讲/.test(raw);
908
+ const storyRequest = !STORY_EXCLUDE_RE.test(raw)
909
+ && (STORY_REQUEST_RE.test(raw) || (continueHit && (lastWasStory || explicitContinue)));
910
+ if (storyRequest) {
911
+ const storyContinue = continueHit && (lastWasStory || /继续讲|接着讲|往下讲/.test(raw));
912
+ return { policy: 'story', reason: storyContinue ? 'story-continue' : 'story-request', storyContinue };
913
+ }
914
+ if (!TASK_OR_ADVICE_RE.test(raw) && EMPATHY_WORDS_RE.test(raw)) {
915
+ return { policy: 'empathy', reason: 'emotion', storyContinue: false };
916
+ }
917
+ return { policy: 'chat', reason: 'default', storyContinue: false };
918
+ }
919
+
920
+
875
921
  /**
876
922
  * 危机时的固定回应(可配置热线)。
877
923
  * 语气:先接住、再关心安全、给可执行的下一步;明确边界,不做诊断/治疗承诺。
@@ -884,7 +930,8 @@ export function treeholeSafetyReply(hotline = '12356') {
884
930
  + '我不是心理治疗,也不能替代专业帮助,但我可以一直听你说。';
885
931
  }
886
932
 
887
- const WALLPAPER_QUERY_RE = /(?:壁纸|桌面|背景).{0,6}(?:是什么|是哪张|哪张|叫什么|现在用|当前)|(?:现在|当前).{0,6}(?:壁纸|桌面)/;const WALLPAPER_ACTION_RE = /(?:(?:换|切换|改|设|来|挑|选|用).{0,8}(?:壁纸|桌面背景|背景图|桌面))|(?:(?:把|给|帮我把|帮我).{0,12}(?:壁纸|桌面|背景).{0,12}(?:换|改|设|切))/;
933
+ const WALLPAPER_QUERY_RE = /(?:壁纸|桌面|背景).{0,6}(?:是什么|是哪张|哪张|叫什么|现在用|当前)|(?:现在|当前).{0,6}(?:壁纸|桌面)/;
934
+ const WALLPAPER_ACTION_RE = /(?:(?:换|切换|改|设|来|挑|选|用).{0,8}(?:壁纸|桌面背景|背景图|桌面))|(?:(?:把|给|帮我把|帮我).{0,12}(?:壁纸|桌面|背景).{0,12}(?:换|改|设|切))/;
888
935
  const REMINDER_RE = /提醒|闹钟|定时/;
889
936
  const REMINDER_LIST_RE = /(?:有什么|还有|看看|列出).{0,4}提醒|提醒.{0,4}(?:列表|有什么)/;
890
937
  const PET_TOGGLE_RE = /(?:(?:关掉|关闭|隐藏|收起|打开|显示|出来).{0,6}(?:桌宠|宠物))|(?:(?:桌宠|宠物).{0,4}(?:关掉|关闭|隐藏|收起|打开|显示))/;
@@ -60,9 +60,9 @@ export const EVENT_RULES = Object.freeze({
60
60
  });
61
61
 
62
62
  /** 「静默」指令:命中任一即进入静默(到次日 0 点)。 */
63
- export const SILENCE_PATTERNS = ['别说了', '安静', '闭嘴', '别吵', '不要说话了'];
63
+ export const SILENCE_PATTERNS = ['别说了', '别说话了', '别说话', '安静', '闭嘴', '别吵', '不要说话了'];
64
64
  /** 「恢复」指令:命中任一即提前解除静默。 */
65
- export const RESUME_PATTERNS = ['可以说话了', '继续吧', '说点什么'];
65
+ export const RESUME_PATTERNS = ['可以说话了', '可以说了', '说话吧', '继续吧', '说点什么'];
66
66
 
67
67
  export function proactivePath() {
68
68
  const base = process.env.DSH_FOLIA_HOME || join(homedir(), '.dsh-folia');
@@ -57,7 +57,7 @@ import {
57
57
  timeAnswer, dateAnswer, isConfirmText, isCancelText, isKnownTool, toolNeedsConfirm,
58
58
  buildCapabilityPrompt, capabilityForText, localCapabilityAnswer, thinkingTier,
59
59
  buildSelfCheckPrompt, reasonerModelFor, buildTaskPlan, taskPlanSentence,
60
- detectCrisis, treeholeSafetyReply,
60
+ detectCrisis, treeholeSafetyReply, resolveTurnPolicy,
61
61
  } from '../pet-chat-brain.js';
62
62
  import {
63
63
  runTool, readPetConfig, dueReminders, markReminderFired,
@@ -719,6 +719,9 @@ export function registerPetChatRoutes(webServer, c) {
719
719
  return personaHistory.get(id);
720
720
  }
721
721
 
722
+ /** v1.3:上一段故事正文(内存,仅用于“继续讲/后来呢”;不落盘、不持久化)。 */
723
+ const lastStoryByPersona = new Map();
724
+
722
725
  /** 任务 §3⑤:最近几句回答(只用于「别重复同一句安慰话术」,不进历史)。 */
723
726
  const personaRecentReplies = new Map();
724
727
  /** v5 §3:多步任务的计划(进程内;重启清空,符合"这次会话里办完")。 */
@@ -771,6 +774,14 @@ export function registerPetChatRoutes(webServer, c) {
771
774
  try { appendEvent(persona.id, event); } catch { /* 记忆写失败不影响回复 */ }
772
775
  }
773
776
 
777
+ /** v1.3:静音指令只切 TTS 开关(字幕继续),不进入任何“模式”。 */
778
+ function setTtsMuted(muted) {
779
+ try {
780
+ const current = readVoiceRaw();
781
+ writeOverlay({ voice: { ...current, muted: muted === true } });
782
+ } catch { /* 写失败也不能拦住对话 */ }
783
+ }
784
+
774
785
  /** 非流式 JSON 调用(反思/摘要/两步策划共用;不写日志、不泄漏 Key)。 */
775
786
  async function callPersonaJson(config, system, user, maxTokens = 500, timeoutMs = 15000) {
776
787
  const controller = new AbortController();
@@ -843,7 +854,8 @@ export function registerPetChatRoutes(webServer, c) {
843
854
  memories: context.memories || [],
844
855
  userText: text,
845
856
  inputMode: context.inputMode,
846
- conversationMode: context.conversationMode,
857
+ turnPolicy: context.turnPolicy,
858
+ storyContext: context.storyContext,
847
859
  voiceLength: context.voiceLength,
848
860
  // 任务 §3:内心步骤 / 先想过的要点 / 别重复的安慰话(都只进 system,不进历史)
849
861
  innerStep: context.innerStep || '',
@@ -936,8 +948,8 @@ export function registerPetChatRoutes(webServer, c) {
936
948
  voice,
937
949
  resolvedVoice,
938
950
  memoryEnabled: true,
939
- // v1.2:客户端据此决定「讲故事/树洞/观察」的显示与朗读行为。
940
- conversationMode: config.conversationMode,
951
+ // v1.3:模式已删除;“policy”由每轮 meta 下发,这里只保留字段兼容(恒 auto)。
952
+ conversationMode: 'auto',
941
953
  voiceLength: config.voiceLength,
942
954
  proactive: config.proactive,
943
955
  screen: config.screen,
@@ -1740,15 +1752,17 @@ export function registerPetChatRoutes(webServer, c) {
1740
1752
  const command = parseSilenceCommand(text);
1741
1753
  if (command === 'silence') {
1742
1754
  enterSilence();
1755
+ setTtsMuted(true);
1743
1756
  sse(res, 'delta', { t: '好,那我安静一会儿。' });
1744
- sse(res, 'done', { emotion: 'calm', command: 'silence', personaId: persona.id });
1757
+ sse(res, 'done', { emotion: 'calm', command: 'silence', muted: true, personaId: persona.id });
1745
1758
  res.end();
1746
1759
  return;
1747
1760
  }
1748
1761
  if (command === 'resume') {
1749
1762
  clearSilence();
1763
+ setTtsMuted(false);
1750
1764
  sse(res, 'delta', { t: '好,我回来了。' });
1751
- sse(res, 'done', { emotion: 'happy', command: 'resume', personaId: persona.id });
1765
+ sse(res, 'done', { emotion: 'happy', command: 'resume', muted: false, personaId: persona.id });
1752
1766
  res.end();
1753
1767
  return;
1754
1768
  }
@@ -1760,34 +1774,29 @@ export function registerPetChatRoutes(webServer, c) {
1760
1774
 
1761
1775
  const mood = detectMood(text, now);
1762
1776
  const inputMode = body.inputMode === 'voice' ? 'voice' : 'text';
1763
- /** v1.2:本轮会话模式(请求可临时覆盖;最终回落设置里的默认模式)。 */
1764
- const conversationMode = ['chat', 'story', 'treehole', 'observe'].includes(String(body.conversationMode || ''))
1765
- ? String(body.conversationMode) : config.conversationMode;
1766
-
1767
1777
  /**
1768
- * 只观察模式:**不回答、不弹气泡**(宿主侧兜底;客户端也会在 mode=observe 时挡掉请求)。
1769
- * 真正的“观察记录”由 /observe 采样器写入,与对话无关。
1778
+ * v1.3:**每轮意图判定**(不持久化、没有“模式”)。
1779
+ * story / empathy 只看这一句话 + 上一轮是不是故事;旧字段 conversationMode 一律忽略。
1770
1780
  */
1771
- if (conversationMode === 'observe') {
1772
- sse(res, 'meta', { mood: mood.mood, rate: mood.rate, mode: 'observe' });
1773
- sse(res, 'done', { emotion: 'calm', skipped: 'observe', conversationMode, personaId: persona.id });
1774
- res.end();
1775
- return;
1776
- }
1777
-
1778
- /* ── 树洞安全:命中自伤/危机词先用固定回应接住,不交给模型自由发挥 ── */
1779
- if (conversationMode === 'treehole') {
1781
+ const turnInfo = resolveTurnPolicy(text, { lastWasStory: lastStoryByPersona.has(persona.id) });
1782
+ const turnPolicy = turnInfo.policy;
1783
+ const storyContext = turnPolicy === 'story' && turnInfo.storyContinue
1784
+ ? String(lastStoryByPersona.get(persona.id) || '')
1785
+ : '';
1786
+
1787
+ /* ── 情绪/危机:命中自伤词先用固定回应接住,不交给模型自由发挥 ── */
1788
+ if (turnPolicy === 'empathy') {
1780
1789
  const hit = detectCrisis(text);
1781
1790
  if (hit) {
1782
1791
  const safety = treeholeSafetyReply((config.treehole && config.treehole.hotline) || '12356');
1783
1792
  recordPersonaEvent(persona, {
1784
1793
  kind: 'treehole', importance: 8,
1785
- text: `树洞·危机词(${hit}):用户需要安全支持`,
1794
+ text: `情绪·危机词(${hit}):用户需要安全支持`,
1786
1795
  });
1787
- sse(res, 'meta', { mood: mood.mood, rate: mood.rate, mode: 'treehole', safety: true });
1796
+ sse(res, 'meta', { mood: mood.mood, rate: mood.rate, policy: 'empathy', safety: true });
1788
1797
  sse(res, 'delta', { t: safety });
1789
1798
  sse(res, 'done', {
1790
- emotion: 'calm', safety: true, crisis: hit, conversationMode, personaId: persona.id,
1799
+ emotion: 'calm', safety: true, crisis: hit, policy: 'empathy', personaId: persona.id,
1791
1800
  mood: mood.mood, rate: mood.rate,
1792
1801
  });
1793
1802
  res.end();
@@ -1831,6 +1840,10 @@ export function registerPetChatRoutes(webServer, c) {
1831
1840
  }
1832
1841
 
1833
1842
  let intent = classifyIntent(text, { now });
1843
+ // v1.3:故事 / 情绪轮不抢工具动作(“继续讲”“今天好累”都按对话处理)。
1844
+ if (turnPolicy !== 'chat') {
1845
+ intent = { intent: 'chat', tool: null, args: {}, confidence: 'rule', reason: 'turn-policy' };
1846
+ }
1834
1847
 
1835
1848
  // 特殊人设:任何系统动作都明确拒绝(不执行、不弹确认、不调工具)。
1836
1849
  if (!personaToolAllowed(persona) && intent.intent === 'action') {
@@ -2060,8 +2073,8 @@ export function registerPetChatRoutes(webServer, c) {
2060
2073
  : [];
2061
2074
  const request = buildRequest(config, text, {
2062
2075
  env, mood, memories: recalled.items, inputMode, innerStep: inner.text, outline, avoidLines,
2063
- conversationMode, voiceLength: config.voiceLength,
2064
- maxTokens: conversationMode === 'story' ? 6000 : 0,
2076
+ turnPolicy, storyContext, voiceLength: config.voiceLength,
2077
+ maxTokens: turnPolicy === 'story' ? 6000 : 0,
2065
2078
  }, persona);
2066
2079
  // v5 §5:三档思考(语音/寒暄 quick;文字复杂 standard;分析/规划/写作 deep)。
2067
2080
  const tier = thinkingTier(text, { inputMode });
@@ -2082,8 +2095,9 @@ export function registerPetChatRoutes(webServer, c) {
2082
2095
  emotion, usage: usage || null, intent: intent.intent, tier,
2083
2096
  mood: mood.mood, rate: mood.rate, personaId: persona.id, personaType: persona.type,
2084
2097
  memories: recalled.items.length, memoryTokens: recalled.tokens,
2085
- conversationMode, voiceLength: config.voiceLength,
2086
- ...(conversationMode === 'story' ? { story: true } : {}),
2098
+ policy: turnPolicy, conversationMode: 'auto', voiceLength: config.voiceLength,
2099
+ ...(turnPolicy === 'story' ? { story: true, storyContinue: turnInfo.storyContinue === true } : {}),
2100
+ ...(turnPolicy === 'empathy' ? { empathy: true } : {}),
2087
2101
  });
2088
2102
  res.end();
2089
2103
  };
@@ -2092,7 +2106,7 @@ export function registerPetChatRoutes(webServer, c) {
2092
2106
  * 深度档(仅文字;语音永远 quick):要点 → 草稿 → 自检 → 最终。
2093
2107
  * 可切 deepseek-reasoner(`reasonerModelFor`);>12s 直接降级用草稿,不让用户干等。
2094
2108
  */
2095
- if (tier === 'deep' && !teachConcept) {
2109
+ if (tier === 'deep' && !teachConcept && turnPolicy === 'chat') {
2096
2110
  const deepStart = Date.now();
2097
2111
  const deepConfig = { ...config, model: reasonerModelFor(config.model, tier) };
2098
2112
  let draft = '';
@@ -2115,6 +2129,7 @@ export function registerPetChatRoutes(webServer, c) {
2115
2129
  sse(res, 'meta', {
2116
2130
  mood: mood.mood, rate: mood.rate, intent: intent.intent, tier: 'deep',
2117
2131
  capability: capability ? capability.id : undefined, personaId: persona.id,
2132
+ policy: turnPolicy,
2118
2133
  deep: { model: deepConfig.model, selfCheck: true, ms: Date.now() - deepStart },
2119
2134
  });
2120
2135
  // 分块发出去,前端仍是逐字出现(不是一次性大段)。
@@ -2138,6 +2153,7 @@ export function registerPetChatRoutes(webServer, c) {
2138
2153
  sse(res, 'meta', {
2139
2154
  mood: mood.mood, rate: mood.rate, intent: intent.intent, tier,
2140
2155
  capability: capability ? capability.id : undefined, personaId: persona.id,
2156
+ policy: turnPolicy, ...(turnInfo.storyContinue ? { storyContinue: true } : {}),
2141
2157
  });
2142
2158
 
2143
2159
  try {
@@ -2156,15 +2172,14 @@ export function registerPetChatRoutes(webServer, c) {
2156
2172
  const decoder = new TextDecoder();
2157
2173
  let buffer = '';
2158
2174
  let full = '';
2159
- // 兼容老判据:不带 inputMode 的请求仍按旧 maxChars 截断;前端/新判据显式带 text/voice。
2160
- const legacyLimit = body.inputMode || conversationMode === 'story' ? 0 : (Number(config.legacyMaxChars) || 80);
2175
+ // 兼容老判据:不带 inputMode 的请求仍按旧 maxChars 截断;故事轮永不截断。
2176
+ const legacyLimit = body.inputMode || turnPolicy === 'story' ? 0 : (Number(config.legacyMaxChars) || 80);
2161
2177
  /**
2162
- * v1.2 语音回答长度:**只在 chat 模式**按句数限制(3/8/不限,默认 8)。
2163
- * story / treehole 不限制(讲故事必须完整到结尾;树洞允许短句但不受句数卡)。
2164
- * 到上限后**不 cancel 流**:模型继续生成、历史保留完整,只是不再往气泡推 delta ——
2165
- * 这样“截断只发生在显示/朗读层”,宿主不提前结束这一轮。
2178
+ * v1.3 语音回答长度:**只在 chat 轮**按句数限制(3/8/不限,默认 8)。
2179
+ * story / empathy 不限制(讲故事必须完整到结尾;共情允许短句但也可能多说两句)。
2180
+ * 到上限后**不 cancel 流**:模型继续生成、历史保留完整,只是不再往气泡推 delta。
2166
2181
  */
2167
- const voiceLimit = conversationMode === 'chat' && inputMode === 'voice'
2182
+ const voiceLimit = turnPolicy === 'chat' && inputMode === 'voice'
2168
2183
  ? Math.max(0, Number(config.voiceLength) || 0) : 0;
2169
2184
  let voiceLimitReached = false;
2170
2185
  let stopped = false;
@@ -2231,11 +2246,15 @@ export function registerPetChatRoutes(webServer, c) {
2231
2246
  pushRecentReply(persona.id, parsed.reply);
2232
2247
  recordPersonaEvent(persona, { kind: 'chat', importance: 4, text: `用户:${text.slice(0, 500)}` });
2233
2248
  recordPersonaEvent(persona, { kind: 'chat', importance: 5, text: `我:${parsed.reply.slice(0, 1000)}` });
2234
- // v1.2:树洞要记住“在意的事/情绪触发点”(importance 6–8),而不是普通闲聊。
2235
- if (conversationMode === 'treehole') {
2249
+ // v1.3:故事轮记住上一段正文(内存,供“继续讲”衔接;不落盘)。
2250
+ if (turnPolicy === 'story' && parsed.reply) {
2251
+ lastStoryByPersona.set(persona.id, String(parsed.reply).slice(-3000));
2252
+ }
2253
+ // v1.3:情绪轮记住“在意的事/情绪触发点”(importance 6–8),但**不持久化任何模式**。
2254
+ if (turnPolicy === 'empathy') {
2236
2255
  recordPersonaEvent(persona, {
2237
2256
  kind: 'treehole', importance: 7,
2238
- text: `树洞:用户说「${text.slice(0, 200)}」(先接情绪,不急着建议)`,
2257
+ text: `情绪:用户说「${text.slice(0, 200)}」(先接情绪,不急着建议)`,
2239
2258
  });
2240
2259
  }
2241
2260
  // v1.2:从对话里抽实体写关系/好感度(保守规则,见 memory-db.extractEntities)。
@@ -2765,7 +2784,7 @@ const roots = [
2765
2784
  voice: publicVoice(readVoiceRaw()),
2766
2785
  wake: config.wake,
2767
2786
  // v1.2
2768
- conversationMode: config.conversationMode,
2787
+ conversationMode: 'auto',
2769
2788
  voiceLength: config.voiceLength,
2770
2789
  proactive: config.proactive,
2771
2790
  screen: config.screen,
@@ -2823,10 +2842,7 @@ const roots = [
2823
2842
  }
2824
2843
 
2825
2844
  /* ── v1.2 会话模式 / 语音长度 / 主动思维 / 屏幕感知 / 树洞 ───────────── */
2826
- const modeList = ['chat', 'story', 'treehole', 'observe'];
2827
- if (typeof body.conversationMode === 'string' && modeList.includes(body.conversationMode)) {
2828
- patch.conversationMode = body.conversationMode;
2829
- }
2845
+ // v1.3:不再接受“会话模式”写入(旧字段保留在设置里仅为兼容,运行时忽略)。
2830
2846
  if ([0, 3, 8].includes(Number(body.voiceLength))) patch.voiceLength = Number(body.voiceLength);
2831
2847
  if (body.proactive && typeof body.proactive === 'object') {
2832
2848
  const previous = current.proactive || {};
@@ -1010,8 +1010,8 @@ const DEFAULTS = {
1010
1010
  voice: { name: '', muted: false },
1011
1011
  // 唤醒:点一下默认开;叫名字默认关(S6 才实现,先在设置里留位)
1012
1012
  wake: { click: true, name: false, keyword: '' },
1013
- // v1.2:会话模式(聊天 / 讲故事 / 树洞 / 只观察)。默认聊天。
1014
- conversationMode: 'chat',
1013
+ // v1.3:不再有“会话模式”。旧字段保留兼容(读档时强制 auto,运行时按每轮文本判定)。
1014
+ conversationMode: 'auto',
1015
1015
  // v1.2:语音回答长度(0 = 不限;默认 8 句 —— 旧版写死 3 句,讲故事被截断的根因)。
1016
1016
  voiceLength: 8,
1017
1017
  // v1.2:主动思维(默认关;15/30/60 分钟才开)。勿扰时段跨零点也支持。
@@ -1736,8 +1736,8 @@ const PET_CHAT_BASE_URL_MAX = 300;
1736
1736
  const PET_CHAT_API_KEY_MAX = 400;
1737
1737
  const PET_CHAT_MODEL_MAX = 120;
1738
1738
  const PET_CHAT_PERSONA_MAX = 200;
1739
- /** v1.2:会话模式 / 语音长度 / 主动搭话 / 屏幕感知(全部**默认关闭**高风险项)。 */
1740
- export const PET_CHAT_CONVERSATION_MODES = Object.freeze(['chat', 'story', 'treehole', 'observe']);
1739
+ /** v1.3:会话策略改为**每轮意图判定**;conversationMode 只保留旧字段兼容,运行时忽略。 */
1740
+ export const PET_CHAT_CONVERSATION_MODES = Object.freeze(['auto', 'chat', 'story', 'treehole', 'observe']);
1741
1741
  /** 语音回答长度:0 = 不限;默认 8 句(v1.2 从 3 句改上来的)。 */
1742
1742
  export const PET_CHAT_VOICE_LENGTHS = Object.freeze([0, 3, 8]);
1743
1743
  /** 主动搭话间隔(分钟):0 = 关。默认关。 */
@@ -1812,8 +1812,8 @@ export function readPetChat(raw) {
1812
1812
  name: wake.name === true,
1813
1813
  keyword: petChatStr(wake.keyword, 40).trim(),
1814
1814
  },
1815
- // v1.2:认不出的模式 / 长度 / 间隔一律回落默认(不猜近似值)
1816
- conversationMode: PET_CHAT_CONVERSATION_MODES.includes(src.conversationMode) ? src.conversationMode : def.conversationMode,
1815
+ // v1.3:conversationMode 只保留字段兼容;**一律回落 auto**(旧档里的 story/treehole 不再生效)。
1816
+ conversationMode: 'auto',
1817
1817
  voiceLength: PET_CHAT_VOICE_LENGTHS.includes(Number(src.voiceLength)) ? Number(src.voiceLength) : def.voiceLength,
1818
1818
  proactive: {
1819
1819
  enabled: proactive.enabled === true,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-folia",
3
3
  "displayName": "dshAI · 壁纸引擎与 AI 桌宠",
4
- "version": "1.2.0",
4
+ "version": "1.3.0",
5
5
  "description": "dshAI:壁纸引擎 + AI 桌宠语音助手 + 多人设角色卡 + 皮肤/开机动画 + 能力市场,一站式桌面伴侣。",
6
6
  "type": "module",
7
7
  "engines": {