dsh-preset-enhance 0.3.2-alpha.2 → 0.3.2-alpha.3

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/PRESET_FORMAT.md CHANGED
@@ -16,9 +16,10 @@
16
16
  "author": ""
17
17
  },
18
18
  "preset": {
19
- "format": "sillytavern",
20
- "data": {
21
- "prompts": [
19
+ "format": "sillytavern",
20
+ "data": {
21
+ "dsh_system_prompt_enabled": true,
22
+ "prompts": [
22
23
  { "identifier": "chatHistory", "marker": true, "role": "user" }
23
24
  ],
24
25
  "prompt_order": [
@@ -30,9 +31,10 @@
30
31
  }
31
32
  },
32
33
  "prefill": {
33
- "enabled": true,
34
- "toolCalls": true,
35
- "removeNonOfficialTools": true,
34
+ "enabled": true,
35
+ "toolCalls": true,
36
+ "extractOutput": false,
37
+ "removeNonOfficialTools": true,
36
38
  "postToolPrefix": {
37
39
  "mode": "inherit",
38
40
  "text": ""
@@ -54,19 +56,22 @@
54
56
  | `version` | 格式主版本,当前为整数 `1`,独立于 npm 插件版本。未知版本拒绝导入。 |
55
57
  | `metadata` | 可选的名称、说明、作者等分享信息;名称可在工作台编辑。 |
56
58
  | `preset.format` | 当前固定为 `sillytavern`。 |
57
- | `preset.data` | 完整 ST JSON,保留顺序表、宏、预填充及原有 `extensions` 等字段。 |
59
+ | `preset.data` | 完整 ST JSON,保留顺序表、宏、预填充及原有 `extensions` 等字段。 |
58
60
  | `prefill` | 可选的接口配置对象,省略或 `null` 表示不附带接口设置。 |
59
61
  | `tools` | 可选的工具预设与分组容器;导入不自动应用,需在工作台显式导入,详见下文。 |
60
62
  | `extensions` | 可选的扩展对象,建议使用插件名作为键,避免重名。 |
61
63
 
62
- `format`、`version`、`preset` 必填。文件大小限制与原 JSON 导入相同,为 8 MB。自定义提示词的换行按 JSON 规则写为 `\n`;宏保留源文本,在实际请求时展开。
64
+ `format`、`version`、`preset` 必填。文件大小限制与原 JSON 导入相同,为 8 MB。自定义提示词的换行按 JSON 规则写为 `\n`;宏保留源文本,在实际请求时展开。
65
+
66
+ `preset.data.dsh_system_prompt_enabled` 是可选布尔值,省略时按 `true` 处理。它对应工作台置顶的只读“DSH 系统提示词”模板:在其他 DSH 模式中启用该预设时,`true` 保留模式原有系统提示与运行时注入,`false` 将其移除。专用“预设模式”始终移除这些内容。
63
67
 
64
68
  ## 预填充配置
65
69
 
66
- `prefill` 非空时,下列字段全部必填:
70
+ `prefill` 非空时,原有字段保持必填;`extractOutput` 是同一主版本新增的可选字段,省略时按 `false` 处理:
67
71
 
68
72
  - `enabled`:是否启用预填充自动兼容。
69
- - `toolCalls`:是否启用 DSML 工具调用转换。
73
+ - `toolCalls`:是否启用 DSML 工具调用转换。
74
+ - `extractOutput`:是否启用实验性正文/工具调用提取;按照最终稳定性策略把切换前文本映射到思维链,并移除输出区控制标签。
70
75
  - `removeNonOfficialTools`:关闭 DSML 处理时,非官方接口是否移除原生工具字段。官方 Beta 的原有规则不变。
71
76
  - `postToolPrefix.mode`:`inherit` 继承原预设,`custom` 使用工具执行后的独立提示词。
72
77
  - `postToolPrefix.text`:自定义提示词文本;留空或宏展开为空时继承原预设。
package/README.md CHANGED
@@ -4,23 +4,19 @@
4
4
 
5
5
  ## 安装
6
6
 
7
- 从 npm 安装当前 alpha 预览版:
8
-
9
- ~~~powershell
10
- dsh plugin --profile web add dsh-preset-enhance@alpha
11
- ~~~
12
-
13
- 如需固定安装当前 alpha 版本:
14
-
15
- ~~~powershell
16
- dsh plugin --profile web add dsh-preset-enhance@0.3.2-alpha.2
17
- ~~~
18
-
19
- 也可以直接从 GitHub 安装 `alpha` 分支的最新源码:
20
-
21
- ~~~powershell
22
- dsh plugin --profile web add github:bychv/dsh-preset-enhance#alpha
23
- ~~~
7
+ 从 npm 安装当前 RC 版本:
8
+
9
+ ~~~powershell
10
+ dsh plugin --profile web add dsh-preset-enhance@0.3.2-rc.1
11
+ ~~~
12
+
13
+ 也可以直接安装 GitHub `main` 分支:
14
+
15
+ ~~~powershell
16
+ dsh plugin --profile web add github:bychv/dsh-preset-enhance#main
17
+ ~~~
18
+
19
+ `0.3.2-rc.1` 和当前 `main` 分支面向 DSH `>=0.1.5-rc.2 <0.1.6`。此版本之后的 `alpha` 分支将用于 DSH 0.1.6 兼容开发;继续使用 DSH 0.1.5 时请固定安装 `0.3.2-rc.1`。
24
20
 
25
21
  重新启动 `dsh web` 后,左侧栏会出现“预设工作台”,新建对话的模式列表中会出现“预设模式”。
26
22
 
@@ -38,9 +34,11 @@ dsh plugin --profile web add github:bychv/dsh-preset-enhance#alpha
38
34
 
39
35
  直接输入 `/preset` 会在开启和关闭之间切换。
40
36
 
41
- “预设模式”从当前安装的 `standard` 模式生成,因此拥有标准模式的工具集。它会移除 DSH 的身份 system prompt 和运行环境快照,使发送给模型的提示词完全由预设和真实聊天记录组成。其他模式保留各自原有提示词,同时可以叠加预设注入。
37
+ “预设模式”从当前安装的 `standard` 模式生成,因此拥有标准模式的工具集。它会移除 DSH 的身份 system prompt 和运行环境快照,使发送给模型的提示词完全由预设和真实聊天记录组成。其他模式叠加预设时,工作台提示词列表顶部的只读“DSH 系统提示词”模板可以控制是否保留这些模式原有的系统提示与运行时注入;旧预设默认开启。
42
38
 
43
- 提示词条目分为两个区域:
39
+ 提示词条目分为两个区域:
40
+
41
+ - 顶部固定显示“DSH 系统提示词”内置模板,正文从当前 DSH 模式动态读取,名称、角色、位置和正文均不可编辑,只能开关。
44
42
 
45
43
  - **顺序表内**:条目已经参与当前顺序表;复选框只控制是否启用,未勾选的条目仍属于顺序表。
46
44
  - **闲置条目**:条目没有加入当前顺序表,不参与注入;点击“加入”后才会移动到使用区。
@@ -53,11 +51,12 @@ dsh plugin --profile web add github:bychv/dsh-preset-enhance#alpha
53
51
 
54
52
  - **DeepSeek 官方地址**:自动把官方 Chat Completion 地址切到 `https://api.deepseek.com/beta`。官方 Beta 不接受原生工具字段,因此未开启 DSML 处理时也会移除 `tools`、`tool_choice` 和 `parallel_tool_calls`。
55
53
  - **非官方适配器地址**:直接处理适配器实际请求的 Chat Completion 地址,不改写地址,也不需要在工作台重复填写。关闭 DSML 处理时,可用“非官方接口移除原生工具字段”开关选择移除或原样发送工具字段。
56
- - **工具调用处理开启**:对官方和非官方地址都生效。插件把可用工具定义注入 system 提示,把历史 `tool_calls` 和工具结果转换为 DSML,再移除原生工具字段。模型返回的 DSML 会在流式或非流式响应中恢复为标准 `tool_calls`,交回 DSH 执行;工具结果中的常见 base64 图片也会转换为兼容的图片内容块。
54
+ - **工具调用处理开启**:对官方和非官方地址都生效。插件把可用工具定义注入 system 提示,把历史 `tool_calls` 和工具结果转换为 DSML,再移除原生工具字段。模型返回的 DSML 会在流式或非流式响应中恢复为标准 `tool_calls`,交回 DSH 执行;工具结果中的常见 base64 图片也会转换为兼容的图片内容块。
55
+ - **正文/工具调用提取(实验)**:按“独占一行的结束思考标记 + 10 token 窗口 + 输出区标签兜底”的最终稳定性策略处理流式和非流式响应。切换前文本进入 `reasoning_content`,输出区进入正文,输出区控制标签会被移除,随后继续执行 DSML 工具调用恢复。工作台内置与稳定性测试相同的完整格式提示词,可一键加入当前预设的 `chatHistory` 后方;该功能默认关闭。
57
56
 
58
57
  “工具调用后继续请求的预填充”默认继承原预设,也可设置独立提示词(支持变量宏与 `<think>` 前缀)。开启预填充自动兼容时,该设置仅替换同一轮工具执行后继续请求的末条 assistant 预填充;新一轮用户消息仍使用原预设。自定义文本留空或展开为空时继承原预设。设置全局保存,修改后从下一次请求生效。
59
58
 
60
- 普通请求、非预填充请求和没有命中当前会话末条 assistant 前缀的请求不受影响。接口要求见 [DeepSeek 对话前缀续写文档](https://api-docs.deepseek.com/zh-cn/guides/chat_prefix_completion)。
59
+ 普通请求、非预填充请求和没有命中当前会话末条 assistant 前缀的请求不受影响。接口要求见 [DeepSeek 对话前缀续写文档](https://api-docs.deepseek.com/zh-cn/guides/chat_prefix_completion)。
61
60
 
62
61
  ## 工具预设
63
62
 
@@ -75,8 +74,8 @@ dsh plugin --profile web add github:bychv/dsh-preset-enhance#alpha
75
74
  工具分组用于组织和批量编辑:
76
75
 
77
76
  - 工具区按标签页组织:固定的“全部”“未分组”,以及按排序值和名称排列的用户分组;标签显示 `名称 · 已启用/总数`,标签栏可收起为紧凑下拉框,窄屏自动使用下拉框。
78
- - 每个分组提供三态开关(部分启用显示为不确定状态)和“全开”“全关”“仅启用此组”“恢复预设值”批量操作;顶部“全选/全不选”始终处理当前模式的全部工具,不受标签筛选影响。
79
- - MCP 工具会从当前会话的实时工具目录获取,并按 MCP 服务自动生成“服务名 · MCP”分组;也可以像普通工具一样加入用户分组。“刷新工具列表”可重新读取刚连接或断开的 MCP 服务。服务名始终放在标签开头,过长时从中间省略并保留首尾,完整名称显示在悬浮提示和折叠下拉框中。标签栏展开时保持单行横向滚动并自动滚入当前项;也可折叠为下拉选择,避免大量 MCP 服务挤压页面。
77
+ - 每个分组提供三态开关(部分启用显示为不确定状态)和“全开”“全关”“仅启用此组”“恢复预设值”批量操作;顶部“全选/全不选”始终处理当前模式的全部工具,不受标签筛选影响。
78
+ - MCP 工具会从当前会话的实时工具目录获取,并按 MCP 服务自动生成“服务名 · MCP”分组;也可以像普通工具一样加入用户分组。“刷新工具列表”可重新读取刚连接或断开的 MCP 服务。服务名始终放在标签开头,过长时从中间省略并保留首尾,完整名称显示在悬浮提示和折叠下拉框中。标签栏展开时保持单行横向滚动并自动滚入当前项;也可折叠为下拉选择,避免大量 MCP 服务挤压页面。
80
79
  - “管理分组”可新增、重命名、排序、删除分组,并用复选框分配工具;同一个工具最多属于一个用户分组,未分组的工具显示在“未分组”标签。标签栏/内容区折叠状态、最后配置的模式和“自动保存工具开关”都只保存在浏览器 localStorage(键名以 `dsh-preset-enhance.tool-` 开头),不进入分享文件。
81
80
 
82
81
  工具视图提供“自动保存工具开关”,默认关闭:
@@ -86,11 +85,11 @@ dsh plugin --profile web add github:bychv/dsh-preset-enhance#alpha
86
85
  - 关闭时与手工保存一致:改动需要点击“保存工具开关”。该按钮始终可用,点击时会取消排队中的自动保存并等待在途请求结束,避免同一改动重复提交。
87
86
  - 开关状态只记在浏览器,不进入分享文件。
88
87
 
89
- 工作台会记住最后配置的 DSH 模式(切换模式或保存模式默认工具时记录),刷新页面后优先回到该模式;保存预设、接口设置等其他内容也不会丢弃尚未保存的工具开关草稿。
90
-
91
- 当前会话的实时目录会同时用于显示与保存校验,因此会话级 MCP 工具、其他插件动态注册的工具可以直接保存到当前会话覆盖,也可以从该会话保存为模式默认。
92
-
93
- 开发时可用 `npm run test:mcp:candidate` 运行双 MCP 接入测试。测试会在 candidate 的真实 DSH 工具注册表中启动两个隔离的 stdio MCP 服务,验证两个服务的同名工具都能被发现、分别调用并形成独立分组;测试结束后自动关闭服务,不写入 candidate 配置。
88
+ 工作台会记住最后配置的 DSH 模式(切换模式或保存模式默认工具时记录),刷新页面后优先回到该模式;保存预设、接口设置等其他内容也不会丢弃尚未保存的工具开关草稿。
89
+
90
+ 当前会话的实时目录会同时用于显示与保存校验,因此会话级 MCP 工具、其他插件动态注册的工具可以直接保存到当前会话覆盖,也可以从该会话保存为模式默认。
91
+
92
+ 开发时可用 `npm run test:mcp:candidate` 运行双 MCP 接入测试。测试会在 candidate 的真实 DSH 工具注册表中启动两个隔离的 stdio MCP 服务,验证两个服务的同名工具都能被发现、分别调用并形成独立分组;测试结束后自动关闭服务,不写入 candidate 配置。
94
93
 
95
94
  关闭的工具会从发给模型的工具 schema 中移除,执行守卫也会拒绝该工具,避免已有或手写工具调用绕过开关。工具目录通过 DSH 的模式注册表和 standing scope 实时解析;内置模式和其他插件引入的模式都会自动列出,各模式的每个实际工具都能独立开关。若第三方模式本身无法装载,工作台会显示该模式的解析错误。目录中暂时不存在的工具引用会保留并列为“未匹配”,安装对应插件后自动重新匹配。
96
95
 
package/client.js CHANGED
@@ -1,62 +1,62 @@
1
- window.__ModuleLoader__.load({
2
- id: 'dsh-preset-enhance',
3
- factory: require => {
4
- const React = require('react');
5
- const LOCK_ATTRIBUTE = 'data-preset-enhance-workbench';
6
- const LOCK_STYLE_ATTRIBUTE = 'data-preset-enhance-resize-lock';
7
- let mountedWorkbenches = 0;
8
-
9
- function useDshResizeLock() {
10
- React.useEffect(() => {
11
- const root = document.documentElement;
12
- let style = document.querySelector('style[' + LOCK_STYLE_ATTRIBUTE + ']');
13
- if (!style) {
14
- style = document.createElement('style');
15
- style.setAttribute(LOCK_STYLE_ATTRIBUTE, '');
16
- style.textContent = 'html[' + LOCK_ATTRIBUTE + '] div[data-side="sidebar"],html[' +
17
- LOCK_ATTRIBUTE + '] div[data-side="rightbar"]{display:none!important}';
18
- document.head.appendChild(style);
19
- }
20
- mountedWorkbenches++;
21
- root.setAttribute(LOCK_ATTRIBUTE, '');
22
- return () => {
23
- mountedWorkbenches = Math.max(0, mountedWorkbenches - 1);
24
- if (mountedWorkbenches > 0) return;
25
- root.removeAttribute(LOCK_ATTRIBUTE);
26
- style.remove();
27
- };
28
- }, []);
29
- }
30
-
31
- const Frame = props => {
32
- useDshResizeLock();
33
- const currentSessionId = typeof props.useSessions === 'function'
34
- ? props.useSessions(state => state.current)
35
- : undefined;
36
- const sessionId = props.sessionId ?? props.injected?.sessionId ?? currentSessionId ?? '';
37
- return React.createElement('iframe', {
38
- title: '预设查看与编辑',
39
- src: '/preset-enhance?sessionId=' + encodeURIComponent(sessionId),
40
- style: { width: '100%', height: '100%', minHeight: '640px', border: 0 },
41
- });
42
- };
43
- const PresetIcon = ({ size = 18 }) => React.createElement('svg', {
44
- width: size, height: size, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 1.8,
45
- strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true,
46
- }, React.createElement('path', { d: 'M5 4h14v16H5z' }),
47
- React.createElement('path', { d: 'M8 8h8M8 12h5M8 16h8' }),
48
- React.createElement('path', { d: 'M16 11v4M14 13h4' }));
49
- return { inject: ['slots', 'conversation'], apply(ctx) {
50
- ctx.slots.inject('conversation.view', () => ctx.slots.register({
51
- name: 'conversation.view', id: 'preset-enhance-editor', order: 25,
52
- label: '预设',
53
- }, Frame));
54
- ctx.slots.inject('main', () => ctx.slots.register({
55
- name: 'main', key: 'preset-enhance-editor',
56
- }, Frame));
57
- ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({
58
- name: 'sidebar.panellist', id: 'preset-enhance-editor', order: 30, label: '预设工作台',
59
- }, PresetIcon));
60
- } };
61
- },
62
- });
1
+ window.__ModuleLoader__.load({
2
+ id: 'dsh-preset-enhance',
3
+ factory: require => {
4
+ const React = require('react');
5
+ const LOCK_ATTRIBUTE = 'data-preset-enhance-workbench';
6
+ const LOCK_STYLE_ATTRIBUTE = 'data-preset-enhance-resize-lock';
7
+ let mountedWorkbenches = 0;
8
+
9
+ function useDshResizeLock() {
10
+ React.useEffect(() => {
11
+ const root = document.documentElement;
12
+ let style = document.querySelector('style[' + LOCK_STYLE_ATTRIBUTE + ']');
13
+ if (!style) {
14
+ style = document.createElement('style');
15
+ style.setAttribute(LOCK_STYLE_ATTRIBUTE, '');
16
+ style.textContent = 'html[' + LOCK_ATTRIBUTE + '] div[data-side="sidebar"],html[' +
17
+ LOCK_ATTRIBUTE + '] div[data-side="rightbar"]{display:none!important}';
18
+ document.head.appendChild(style);
19
+ }
20
+ mountedWorkbenches++;
21
+ root.setAttribute(LOCK_ATTRIBUTE, '');
22
+ return () => {
23
+ mountedWorkbenches = Math.max(0, mountedWorkbenches - 1);
24
+ if (mountedWorkbenches > 0) return;
25
+ root.removeAttribute(LOCK_ATTRIBUTE);
26
+ style.remove();
27
+ };
28
+ }, []);
29
+ }
30
+
31
+ const Frame = props => {
32
+ useDshResizeLock();
33
+ const currentSessionId = typeof props.useSessions === 'function'
34
+ ? props.useSessions(state => state.current)
35
+ : undefined;
36
+ const sessionId = props.sessionId ?? props.injected?.sessionId ?? currentSessionId ?? '';
37
+ return React.createElement('iframe', {
38
+ title: '预设查看与编辑',
39
+ src: '/preset-enhance?sessionId=' + encodeURIComponent(sessionId),
40
+ style: { width: '100%', height: '100%', minHeight: '640px', border: 0 },
41
+ });
42
+ };
43
+ const PresetIcon = ({ size = 18 }) => React.createElement('svg', {
44
+ width: size, height: size, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 1.8,
45
+ strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true,
46
+ }, React.createElement('path', { d: 'M5 4h14v16H5z' }),
47
+ React.createElement('path', { d: 'M8 8h8M8 12h5M8 16h8' }),
48
+ React.createElement('path', { d: 'M16 11v4M14 13h4' }));
49
+ return { inject: ['slots', 'conversation'], apply(ctx) {
50
+ ctx.slots.inject('conversation.view', () => ctx.slots.register({
51
+ name: 'conversation.view', id: 'preset-enhance-editor', order: 25,
52
+ label: '预设',
53
+ }, Frame));
54
+ ctx.slots.inject('main', () => ctx.slots.register({
55
+ name: 'main', key: 'preset-enhance-editor',
56
+ }, Frame));
57
+ ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({
58
+ name: 'sidebar.panellist', id: 'preset-enhance-editor', order: 30, label: '预设工作台',
59
+ }, PresetIcon));
60
+ } };
61
+ },
62
+ });
package/index.mjs CHANGED
@@ -3,9 +3,10 @@ import { resolve, join } from 'node:path';
3
3
  import { homedir } from 'node:os';
4
4
  import { createHash, randomUUID } from 'node:crypto';
5
5
  import { PresetStore } from './lib/store.mjs';
6
- import { compilePreset, validatePreset, getOrder } from './lib/preset.mjs';
6
+ import { compilePreset, validatePreset, getOrder, dshSystemPromptEnabled } from './lib/preset.mjs';
7
7
  import { decodePresetDocument, encodePresetPackage, attachPrefillSettings, applyPackagePrefill } from './lib/preset-package.mjs';
8
- import { installDeepSeekBetaBridge } from './lib/deepseek-beta.mjs';
8
+ import { installDeepSeekBetaBridge } from './lib/deepseek-beta.mjs';
9
+ import { OUTPUT_EXTRACTION_PROMPT_TEMPLATE } from './lib/output-extractor.mjs';
9
10
  import {
10
11
  normalizeToolGroups, normalizeToolPreset, normalizeToolSelection, assertPresetGroupIds,
11
12
  toolPolicySnapshot, effectiveToolEnabled, effectiveToolPolicy, remapToolPackage,
@@ -18,7 +19,7 @@ export const AGENT_PRESET_ID = 'st-preset';
18
19
  const BASE = '/preset-enhance';
19
20
  const DSH_SYSTEM_PROMPT = '@deepseek-ai/dsh-system-prompt';
20
21
  const digest = value => createHash('sha256').update(JSON.stringify(value)).digest('hex');
21
- const PRESET_COMPILER_VERSION = 3;
22
+ const PRESET_COMPILER_VERSION = 4;
22
23
  const ownGet = (object, key) => Object.hasOwn(object, key) ? object[key] : undefined;
23
24
  const assign = (object, key, value) => Object.defineProperty(object, key, { value, writable: true, enumerable: true, configurable: true });
24
25
  const isRecord = value => value && typeof value === 'object' && !Array.isArray(value);
@@ -81,12 +82,14 @@ export async function apply(ctx, config = {}) {
81
82
  if (!binding?.enabled) return null;
82
83
  const record = current.presets.find(p => p.id === binding.presetId);
83
84
  if (!record) throw new Error('当前会话启用的预设不存在');
84
- const postToolPrefix = current.deepseekBetaPrefix && current.postToolPrefixMode === 'custom'
85
- ? current.postToolPrefixText : undefined;
86
- const key = digest({ compiler: PRESET_COMPILER_VERSION, messages: history, preset: record, binding, postToolPrefix });
85
+ const presetHistory = !exclusive && !dshSystemPromptEnabled(record.preset)
86
+ ? presetModeHistory(history) : history;
87
+ const postToolPrefix = current.deepseekBetaPrefix && current.postToolPrefixMode === 'custom'
88
+ ? current.postToolPrefixText : undefined;
89
+ const key = digest({ compiler: PRESET_COMPILER_VERSION, messages: presetHistory, preset: record, binding, postToolPrefix });
87
90
  const prior = ownGet(current.sessions, options.sessionId);
88
91
  if (prior?.key === key) return prior.result;
89
- const result = compilePreset(record.preset, history, {
92
+ const result = compilePreset(record.preset, presetHistory, {
90
93
  ...binding, seed: key, local: prior?.result.local, global: current.global, postToolPrefix,
91
94
  });
92
95
  options.signal?.throwIfAborted();
@@ -108,8 +111,9 @@ export async function apply(ctx, config = {}) {
108
111
  const request = routedRequest(options, messages, filteredTools);
109
112
  const betaPrefix = initial.deepseekBetaPrefix === true && compiled?.assistantPrefix?.active === true;
110
113
  const releaseBeta = betaPrefix ? deepSeekBeta.activate(options.sessionId, messageText(messages.at(-1)), {
111
- toolCalls: initial.prefixToolCalls === true,
112
- removeNonOfficialTools: initial.prefixNonOfficialRemoveTools !== false,
114
+ toolCalls: initial.prefixToolCalls === true,
115
+ removeNonOfficialTools: initial.prefixNonOfficialRemoveTools !== false,
116
+ extractOutput: initial.prefixOutputExtraction === true,
113
117
  }) : () => {};
114
118
  routed.add(request);
115
119
  try { yield* ctx.llm.stream(request); } finally { releaseBeta(); routed.delete(request); }
@@ -145,11 +149,11 @@ export async function apply(ctx, config = {}) {
145
149
  const session = sessionId ? ctx.sessions.get(sessionId) : undefined;
146
150
  const fallback = !ownGet(state.bindings, sessionId) && shouldAutoEnable(state, session) ?
147
151
  defaultBinding(state) : undefined;
148
- const modeDefault = defaultRecord(state);
149
- const modes = await agentModeRows(ctx);
150
- const discovered = await discoverModeToolCatalogs(ctx, modes);
151
- const liveMode = sessionModeId(session);
152
- const catalogs = requestToolCatalogs(ctx, state, discovered.catalogs, sessionId);
152
+ const modeDefault = defaultRecord(state);
153
+ const modes = await agentModeRows(ctx);
154
+ const discovered = await discoverModeToolCatalogs(ctx, modes);
155
+ const liveMode = sessionModeId(session);
156
+ const catalogs = requestToolCatalogs(ctx, state, discovered.catalogs, sessionId);
153
157
  return respond(res, 200, {
154
158
  revision: state.revision,
155
159
  presets: state.presets,
@@ -158,17 +162,20 @@ export async function apply(ctx, config = {}) {
158
162
  postToolPrefixMode: state.postToolPrefixMode,
159
163
  postToolPrefixText: state.postToolPrefixText,
160
164
  deepseekBetaPrefix: state.deepseekBetaPrefix === true,
161
- prefixToolCalls: state.prefixToolCalls === true,
162
- prefixNonOfficialRemoveTools: state.prefixNonOfficialRemoveTools !== false,
165
+ prefixToolCalls: state.prefixToolCalls === true,
166
+ prefixOutputExtraction: state.prefixOutputExtraction === true,
167
+ prefixNonOfficialRemoveTools: state.prefixNonOfficialRemoveTools !== false,
168
+ outputExtractionTemplate: OUTPUT_EXTRACTION_PROMPT_TEMPLATE,
163
169
  modeDefaultPresetId: modeDefault?.id ?? null,
164
170
  modeDefaultName: modeDefault?.name ?? null,
165
171
  presetMode: liveMode === AGENT_PRESET_ID,
166
172
  sessionMode: liveMode,
167
173
  agentModes: modes,
168
- autoEnableModes: state.autoEnableModes,
169
- toolCatalogs: catalogs,
170
- mcpToolGroups: mcpToolGroups(catalogs),
171
- toolCatalogErrors: discovered.errors,
174
+ autoEnableModes: state.autoEnableModes,
175
+ dshSystemPromptText: dshSystemPromptText(session?.deriveMessages?.() ?? []),
176
+ toolCatalogs: catalogs,
177
+ mcpToolGroups: mcpToolGroups(catalogs),
178
+ toolCatalogErrors: discovered.errors,
172
179
  modeToolPolicies: state.modeToolPolicies,
173
180
  sessionToolPolicy: sessionId ? ownGet(state.sessionToolPolicies, sessionId) ?? null : null,
174
181
  toolGroups: state.toolGroups,
@@ -185,7 +192,7 @@ export async function apply(ctx, config = {}) {
185
192
  if (req.headers.origin && new URL(req.headers.origin).host !== req.headers.host) throw new Error('拒绝跨来源写入');
186
193
  const body = await readJson(req);
187
194
  if (body.action === 'preview') {
188
- return respond(res, 200, compilePreset(body.preset, previewHistory(ctx, body), {
195
+ return respond(res, 200, compilePreset(body.preset, previewHistory(ctx, body), {
189
196
  ...body.options, seed: 'preview',
190
197
  }));
191
198
  }
@@ -209,10 +216,10 @@ export async function apply(ctx, config = {}) {
209
216
  const discovered = CATALOG_ACTIONS.has(body.action) ?
210
217
  await discoverModeToolCatalogs(ctx, modeRows) : null;
211
218
 
212
- if (body.action === 'save-tool-groups') {
213
- const state = await store.read();
214
- const catalogs = requestToolCatalogs(
215
- ctx, state, discovered.catalogs, url.searchParams.get('sessionId') ?? '');
219
+ if (body.action === 'save-tool-groups') {
220
+ const state = await store.read();
221
+ const catalogs = requestToolCatalogs(
222
+ ctx, state, discovered.catalogs, url.searchParams.get('sessionId') ?? '');
216
223
  const groups = normalizeToolGroups(body.groups, { catalogs, existing: state.toolGroups });
217
224
  const warnings = unresolvedWarnings(unresolvedToolRefs({ toolGroups: groups }, catalogs));
218
225
  return respond(res, 200, await store.transaction(current => {
@@ -220,7 +227,7 @@ export async function apply(ctx, config = {}) {
220
227
  current.toolGroups = groups;
221
228
  current.revision++;
222
229
  refreshPolicies(current);
223
- return { groups: current.toolGroups, warnings };
230
+ return { revision: current.revision, groups: current.toolGroups, warnings };
224
231
  }));
225
232
  }
226
233
 
@@ -235,10 +242,10 @@ export async function apply(ctx, config = {}) {
235
242
  }
236
243
  const preset = normalizeToolPreset({ ...body.preset, id: existing ? requestedId : null });
237
244
  assertPresetGroupIds(preset, state.toolGroups);
238
- const record = { ...preset, id: existing ? requestedId : randomUUID() };
239
- const warnings = unresolvedWarnings(
240
- unresolvedToolRefs({ toolPresets: [record] }, requestToolCatalogs(
241
- ctx, state, discovered.catalogs, url.searchParams.get('sessionId') ?? '')));
245
+ const record = { ...preset, id: existing ? requestedId : randomUUID() };
246
+ const warnings = unresolvedWarnings(
247
+ unresolvedToolRefs({ toolPresets: [record] }, requestToolCatalogs(
248
+ ctx, state, discovered.catalogs, url.searchParams.get('sessionId') ?? '')));
242
249
  return respond(res, 200, await store.transaction(current => {
243
250
  assertRevision(current, body);
244
251
  const index = current.toolPresets.findIndex(item => item.id === record.id);
@@ -297,12 +304,12 @@ export async function apply(ctx, config = {}) {
297
304
  }));
298
305
  }
299
306
 
300
- if (body.action === 'save-mode-tools') {
301
- if (typeof body.modeId !== 'string' || !knownModes.has(body.modeId)) throw new Error('请选择有效的 DSH 模式');
302
- const state = await store.read();
303
- const catalogs = requestToolCatalogs(
304
- ctx, state, discovered.catalogs, url.searchParams.get('sessionId') ?? '');
305
- const policy = validateToolPolicy(body.policy, catalogs[body.modeId]);
307
+ if (body.action === 'save-mode-tools') {
308
+ if (typeof body.modeId !== 'string' || !knownModes.has(body.modeId)) throw new Error('请选择有效的 DSH 模式');
309
+ const state = await store.read();
310
+ const catalogs = requestToolCatalogs(
311
+ ctx, state, discovered.catalogs, url.searchParams.get('sessionId') ?? '');
312
+ const policy = validateToolPolicy(body.policy, catalogs[body.modeId]);
306
313
  const selection = { kind: 'custom' };
307
314
  return respond(res, 200, await store.transaction(current => {
308
315
  assertRevision(current, body);
@@ -317,12 +324,12 @@ export async function apply(ctx, config = {}) {
317
324
  if (body.action === 'save-session-tools') {
318
325
  const session = typeof body.sessionId === 'string' ? ctx.sessions.get(body.sessionId) : undefined;
319
326
  if (!session) throw new Error('缺少有效的会话 ID');
320
- const modeId = sessionModeId(session);
321
- if (!knownModes.has(modeId)) throw new Error('当前会话没有可识别的 DSH 模式');
322
- const inherit = body.inherit === true;
323
- const state = await store.read();
324
- const catalogs = requestToolCatalogs(ctx, state, discovered.catalogs, body.sessionId);
325
- const policy = inherit ? null : validateToolPolicy(body.policy, catalogs[modeId]);
327
+ const modeId = sessionModeId(session);
328
+ if (!knownModes.has(modeId)) throw new Error('当前会话没有可识别的 DSH 模式');
329
+ const inherit = body.inherit === true;
330
+ const state = await store.read();
331
+ const catalogs = requestToolCatalogs(ctx, state, discovered.catalogs, body.sessionId);
332
+ const policy = inherit ? null : validateToolPolicy(body.policy, catalogs[modeId]);
326
333
  return respond(res, 200, await store.transaction(current => {
327
334
  assertRevision(current, body);
328
335
  if (inherit) {
@@ -343,9 +350,9 @@ export async function apply(ctx, config = {}) {
343
350
  const record = state.presets.find(preset => preset.id === body.id);
344
351
  if (!record) throw new Error('请选择带有工具配置的预设包');
345
352
  if (!record.sharePackage?.tools) throw new Error('该预设包不包含工具配置');
346
- const plan = remapToolPackage(record.sharePackage.tools, state, {
347
- catalogs: requestToolCatalogs(
348
- ctx, state, discovered.catalogs, url.searchParams.get('sessionId') ?? ''),
353
+ const plan = remapToolPackage(record.sharePackage.tools, state, {
354
+ catalogs: requestToolCatalogs(
355
+ ctx, state, discovered.catalogs, url.searchParams.get('sessionId') ?? ''),
349
356
  });
350
357
  if (body.dryRun === true) {
351
358
  return respond(res, 200, {
@@ -431,10 +438,14 @@ export async function apply(ctx, config = {}) {
431
438
  }
432
439
  if (body.action === 'save-deepseek-beta') {
433
440
  if (typeof body.enabled !== 'boolean') throw new Error('预填充接口开关值无效');
434
- if (body.toolCalls !== undefined) {
441
+ if (body.toolCalls !== undefined) {
435
442
  if (typeof body.toolCalls !== 'boolean') throw new Error('工具调用处理开关值无效');
436
443
  state.prefixToolCalls = body.toolCalls;
437
- }
444
+ }
445
+ if (body.extractOutput !== undefined) {
446
+ if (typeof body.extractOutput !== 'boolean') throw new Error('正文/工具调用提取开关值无效');
447
+ state.prefixOutputExtraction = body.extractOutput;
448
+ }
438
449
  if (body.removeNonOfficialTools !== undefined) {
439
450
  if (typeof body.removeNonOfficialTools !== 'boolean') throw new Error('非官方接口工具移除开关值无效');
440
451
  state.prefixNonOfficialRemoveTools = body.removeNonOfficialTools;
@@ -454,9 +465,11 @@ export async function apply(ctx, config = {}) {
454
465
  attachPrefillSettings(record, state);
455
466
  }
456
467
  state.revision++;
457
- return {
458
- enabled: state.deepseekBetaPrefix,
459
- toolCalls: state.prefixToolCalls === true,
468
+ return {
469
+ revision: state.revision,
470
+ enabled: state.deepseekBetaPrefix,
471
+ toolCalls: state.prefixToolCalls === true,
472
+ extractOutput: state.prefixOutputExtraction === true,
460
473
  removeNonOfficialTools: state.prefixNonOfficialRemoveTools !== false,
461
474
  };
462
475
  }
@@ -472,12 +485,12 @@ export async function apply(ctx, config = {}) {
472
485
  state.autoEnableSince[AGENT_PRESET_ID] = 0;
473
486
  state.autoEnableModes = selected;
474
487
  state.revision++;
475
- return { modes: selected };
488
+ return { revision: state.revision, modes: selected };
476
489
  }
477
490
  if (body.action === 'bind') {
478
491
  validateBinding(state, body);
479
492
  state.revision++;
480
- return { ok: true };
493
+ return { revision: state.revision, ok: true };
481
494
  }
482
495
  throw new Error('未知操作');
483
496
  });
@@ -584,51 +597,55 @@ function shouldAutoEnable(state, session) {
584
597
  const createdAt = Number(session.header?.createdAt ?? Number.POSITIVE_INFINITY);
585
598
  return createdAt >= since;
586
599
  }
587
- function presetModeHistory(messages) {
588
- return messages.filter(message => message.role !== 'system' &&
589
- !(message.source?.kind === 'plugin' && message.source.plugin === DSH_SYSTEM_PROMPT));
590
- }
600
+ function presetModeHistory(messages) {
601
+ return messages.filter(message => message.role !== 'system' &&
602
+ !(message.source?.kind === 'plugin' && message.source.plugin === DSH_SYSTEM_PROMPT));
603
+ }
604
+ function dshSystemPromptText(messages) {
605
+ return messages.filter(message => message.role === 'system')
606
+ .map(messageText).filter(Boolean).join('\n\n');
607
+ }
591
608
 
592
609
  /** Live catalogs plus the last catalog seen for each mode, so a removed plugin is not silently forgotten. */
593
- function knownToolCatalogs(state, discovered) {
610
+ function knownToolCatalogs(state, discovered) {
594
611
  const catalogs = {};
595
612
  for (const source of [state?.toolCatalogs, discovered]) {
596
613
  for (const [modeId, catalog] of Object.entries(source ?? {})) {
597
614
  if (Array.isArray(catalog)) assign(catalogs, modeId, catalog);
598
615
  }
599
616
  }
600
- return catalogs;
601
- }
602
- /** Match GET's catalog view for writes opened from a live conversation. */
603
- function requestToolCatalogs(ctx, state, discovered, sessionId) {
604
- const catalogs = knownToolCatalogs(state, discovered);
605
- const session = sessionId ? ctx.sessions.get(sessionId) : undefined;
606
- const modeId = sessionModeId(session);
607
- const live = liveToolCatalog(ctx, sessionId);
608
- if (live.length > 0 && modeId) assign(catalogs, modeId, live);
609
- return catalogs;
610
- }
611
- /** Group DSH MCP public tool names by their stable server namespace. */
612
- export function mcpToolGroups(catalogs) {
613
- const result = {};
614
- for (const [modeId, catalog] of Object.entries(catalogs ?? {})) {
615
- if (!Array.isArray(catalog)) continue;
616
- const servers = new Map();
617
- for (const tool of catalog) {
618
- const match = /^mcp__([A-Za-z0-9_-]{1,32})__(.+)$/.exec(String(tool?.name ?? ''));
619
- if (!match) continue;
620
- const serverName = match[1];
621
- const tools = servers.get(serverName) ?? [];
622
- tools.push(tool.name);
623
- servers.set(serverName, tools);
624
- }
625
- const groups = [...servers].sort(([left], [right]) => left.localeCompare(right))
626
- .map(([serverName, tools]) => ({ serverName, tools: [...new Set(tools)].sort() }));
627
- if (groups.length > 0) assign(result, modeId, groups);
628
- }
629
- return result;
630
- }
631
- function unresolvedWarnings(refs) {
617
+ return catalogs;
618
+ }
619
+ /** Match GET's catalog view for writes opened from a live conversation. */
620
+ function requestToolCatalogs(ctx, state, discovered, sessionId) {
621
+ const catalogs = knownToolCatalogs(state, discovered);
622
+ const session = sessionId ? ctx.sessions.get(sessionId) : undefined;
623
+ const modeId = sessionModeId(session);
624
+ const live = liveToolCatalog(ctx, sessionId);
625
+ if (live.length > 0 && modeId) assign(catalogs, modeId, live);
626
+ return catalogs;
627
+ }
628
+ /** Group DSH MCP public tool names by their stable server namespace. */
629
+ export function mcpToolGroups(catalogs) {
630
+ const result = {};
631
+ for (const [modeId, catalog] of Object.entries(catalogs ?? {})) {
632
+ if (!Array.isArray(catalog)) continue;
633
+ const servers = new Map();
634
+ for (const tool of catalog) {
635
+ const match = /^mcp__([A-Za-z0-9_-]{1,32})__(.+)$/.exec(String(tool?.name ?? ''));
636
+ if (!match) continue;
637
+ const serverName = match[1];
638
+ const tools = servers.get(serverName) ?? [];
639
+ tools.push(tool.name);
640
+ servers.set(serverName, tools);
641
+ }
642
+ const groups = [...servers].sort(([left], [right]) => left.localeCompare(right))
643
+ .map(([serverName, tools]) => ({ serverName, tools: [...new Set(tools)].sort() }));
644
+ if (groups.length > 0) assign(result, modeId, groups);
645
+ }
646
+ return result;
647
+ }
648
+ function unresolvedWarnings(refs) {
632
649
  return refs.length > 0
633
650
  ? [`${refs.length} 条工具引用在当前模式目录中不存在,已保留待插件恢复后重新匹配`]
634
651
  : [];
@@ -741,10 +758,11 @@ export async function ensurePresetAgentMode(root, standard) {
741
758
  return destination;
742
759
  }
743
760
 
744
- function previewHistory(ctx, body) {
745
- const session = ctx.sessions.get(body.sessionId);
746
- const derived = session?.deriveMessages() ?? [];
747
- const history = sessionModeId(session) === AGENT_PRESET_ID ? presetModeHistory(derived) : derived;
761
+ function previewHistory(ctx, body) {
762
+ const session = ctx.sessions.get(body.sessionId);
763
+ const derived = session?.deriveMessages() ?? [];
764
+ const exclusive = sessionModeId(session) === AGENT_PRESET_ID;
765
+ const history = exclusive || !dshSystemPromptEnabled(body.preset) ? presetModeHistory(derived) : derived;
748
766
  return body.input ? [...history, {
749
767
  id: 'preview-user',
750
768
  role: 'user',