dsh-lcx-codex 0.5.1 → 0.6.0-pre.1

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/README.md CHANGED
@@ -37,16 +37,22 @@ LCX Codex 是 [DeepSeek Harness](https://github.com/deepseek-ai/DeepSeek-Harness
37
37
 
38
38
  | 你的 DSH 版本 | 安装的 LCX 版本 | 安装命令中的标签 |
39
39
  | --- | --- | --- |
40
- | `0.2.1-alpha.2` 及以后 | `0.5.1-pre.1`(预发布版) | `@prelatest` |
40
+ | `0.2.1-alpha.2` 及以后 | `0.6.0-pre.1`(预发布版) | `@prelatest` |
41
41
  | `0.2.0` 系列(`0.2.0-rc.2`,早于 `0.2.1-alpha.2`) | `0.5.1`(稳定版) | `@latest` |
42
42
  | `0.1.6` 系列(`0.1.6-alpha.2` 及以后) | `0.4.4-pre.1`(旧预发布版) | `@0.4.4-pre.1` |
43
43
  | `0.1.5` 系列(`0.1.5-rc.1` 及以后) | `0.4.3`(稳定版) | `@0.4.3` |
44
44
 
45
- 请务必按表格选择:几个版本互不兼容,装错版本时安装命令可能只给出依赖警告,但插件可能无法正常工作。`@latest` 是稳定版 `0.5.1`(发布基线 DSH `0.2.0-rc.2`,host / plugin Pi `0.87.1`;相对 `0.5.0` 只包含缺陷修复),DSH `0.1.5` 用户请固定安装 `@0.4.3`。
45
+ 请务必按表格选择:几个版本互不兼容,装错版本时安装命令可能只给出依赖警告,但插件可能无法正常工作。`@latest` 是稳定版 `0.5.1`(发布基线 DSH `0.2.0-rc.2`,host / plugin Pi `0.87.1`),DSH `0.1.5` 用户请固定安装 `@0.4.3`。
46
46
 
47
- `0.5.1-pre.1` 是预发布版,面向 DSH `0.2.1-alpha.2`。它的安装范围**只有下限**(`>=0.2.1-alpha.2`),没有上限:更新的 DSH 版本也能装上,但**没有经过验证**。本次预发布的验证基线只有 DSH `0.2.1-alpha.2`(host Pi `1.1.0`,plugin Pi `0.87.1`),请不要据此认为其他 DSH 版本受支持。
47
+ `0.6.0-pre.1` 是预发布版,面向 DSH `0.2.1-alpha.2`。它的安装范围**只有下限**(`>=0.2.1-alpha.2`),没有上限:更新的 DSH 版本也能装上,但**没有经过验证**。本次预发布的验证基线只有 DSH `0.2.1-alpha.2`(host Pi `1.1.0`,plugin Pi `0.87.1`),请不要据此认为其他 DSH 版本受支持。
48
48
 
49
- > 注意:稳定版 `0.5.1` 的安装范围写作 `>=0.2.0-rc.2 <0.2.1`,按 DSH 的版本范围规则,`0.2.1` 的预发布版(如 `0.2.1-alpha.2`)也可能被放行安装,但这些版本**不在** `0.5.1` 的支持和验证范围内;DSH `0.2.1-alpha.2` 及以后请使用 `@prelatest`。
49
+ 本版本开始适配 DSH `0.2.1` 的插件相关新能力:
50
+
51
+ - **增量工具更新(只增不改)**:在 DSH 声明支持该模式的 GPT Responses 路由上,会话中途新增工具(例如打开联网搜索、启用 MCP 或技能)时,请求里的工具列表保持不变,新增的工具以历史项的形式声明,因此不再改变已缓存的前缀。设置卡片里有“增量工具更新”开关,默认开启,关闭后每次请求都发送完整的当前工具列表。删除工具或同名重定义仍会让缓存失效一次。Grok、自定义命名路由、分叉与路由迁移的回放、压缩检查点仍然发送完整工具列表。
52
+ - **程序化工具调用里的搜索**:在 `run_code` 程序里调用 `web_search` / `websearch_gpt_advanced` 时,搜索用量和返回的图片也会计入并显示。
53
+ - **插件管理页卡片**:LCX 在插件管理页显示自己的名称(LCX Codex)、简介和图标。
54
+
55
+ > 注意:稳定版 `0.5.x` 的安装范围写作 `>=0.2.0-rc.2 <0.2.1`,按 DSH 的版本范围规则,`0.2.1` 的预发布版(如 `0.2.1-alpha.2`)也可能被放行安装,但这些版本**不在** `0.5.x` 的支持和验证范围内;DSH `0.2.1-alpha.2` 及以后请使用 `@prelatest`。
50
56
 
51
57
  ### 2. 安装并启动
52
58
 
@@ -94,6 +100,7 @@ dsh web
94
100
  | **使用 GPT Hosted Search 作为 DSH web_search 后端** | GPT 联网搜索 | 需要联网时打开 |
95
101
  | **启用高级 Hosted 工具** | 图片搜索、限定网站、指定位置等(需先打开上一项) | 按需 |
96
102
  | **启用 Alpha command** | 实验功能:让 GPT 继续打开、查找搜索结果中的页面 | 日常不需要 |
103
+ | **增量工具更新(addition-only)** | 会话中途新增工具时保持请求前缀不变以保护缓存,仅对 DSH 声明支持的 GPT 路由生效;关闭后每次请求都发送完整工具列表 | 默认开启,一般不用改 |
97
104
 
98
105
  **Grok 原生搜索**(与“启用 LCX”相互独立)
99
106
 
@@ -124,11 +131,11 @@ dsh web
124
131
 
125
132
  ## 从旧版本升级
126
133
 
127
- - **DSH 升级到 `0.2.1-alpha.2` 或更新版本**:把插件换成 `@prelatest`(`0.5.1-pre.1`),稳定版 `0.5.1` 没有在这些 DSH 版本上验证。
134
+ - **DSH 升级到 `0.2.1-alpha.2` 或更新版本**:把插件换成 `@prelatest`(`0.6.0-pre.1`),稳定版 `0.5.x` 没有在这些 DSH 版本上验证。
128
135
  - **DSH 升级到 `0.2.0` 系列**:把插件换成 `@latest`(`0.5.1`),旧版 `0.4.x` 不支持 DSH `0.2`。
129
136
  - **DSH `0.1.6` 系列**:继续使用 `@0.4.4-pre.1`。
130
137
  - **DSH `0.1.5` 系列**:继续使用 `@0.4.3`;`@latest` 现在指向支持 DSH `0.2` 的 `0.5.1`。
131
- - **已装了 `0.5.0` 或 `0.5.0-pre.1`**:DSH `0.2.0` 系列重新运行 `@latest` 的 `add` 命令即可升到 `0.5.1`(修复了若干缺陷,安装范围不变,详见 CHANGELOG);DSH `0.2.1-alpha.2` 及以后用 `@prelatest`。
138
+ - **已装了 `0.5.0-pre.1`**:DSH `0.2.0` 系列重新运行 `@latest` 的 `add` 命令即可升到稳定版(`0.5.0-pre.1` 与 `0.5.0` 运行时代码一致);DSH `0.2.1-alpha.2` 及以后用 `@prelatest`。
132
139
  - **升级后建议新建会话**:旧版本保存的压缩状态不保证兼容。DSH `0.2` 迁移过的旧长会话如果带有旧版 LCX 压缩检查点,LCX 会提示 `LCX_CHECKPOINT_UNSUPPORTED`,新建会话即可;其他模型不受影响。
133
140
 
134
141
  ## 停用与卸载
@@ -148,8 +155,8 @@ dsh web
148
155
  - **Alpha 仍是实验功能**:连续打开/查找页面在已测试的 OAuth 类上游上可用;API Key 类上游账号不在支持范围内。目标页面抓取失败时会提示 `LCX_ALPHA_PAGE_FETCH_FAILED`,模型可以换一个结果继续。
149
156
  - **Markdown 图片换行**:为避免 DSH `0.2` 中图片后的文字挤到图片右侧,LCX 会让回答里的 Markdown 图片单独占一行,这一点与“搜索媒体预览”开关无关;句中的小图也会因此换行。
150
157
  - **DSH `0.1.5` + LCX `0.4.3`**:在插件设置中启用或停用 LCX 后,已打开的浏览器页面可能需要刷新。
151
- - **DSH `0.2.1` 的工具更新**:DSH `0.2.1` 的“只增不改”增量工具更新没有实现,LCX 仍然每次请求都发送完整的当前工具列表;这一变化带来的缓存收益不在声明范围内。
152
- - **验证范围**:`0.5.1-pre.1` 的验证基线只有 DSH `0.2.1-alpha.2`(预发布,host Pi `1.1.0`),安装范围没有上限,更新的 DSH 版本未经验证;该基线上的真实运行验证覆盖 GPT 路由、搜索和压缩等主要场景,Grok 路由、Alpha 搜索和用户图片输入没有在这一轮覆盖。`0.5.1` 的发布基线为 DSH `0.2.0-rc.2`(host / plugin Pi `0.87.1`);`0.4.4-pre.1` 在 DSH `0.1.6-alpha.2` 上完整验证;`0.4.3` 的稳定发布基线是 DSH `0.1.5-rc.1`,并已另外验证 DSH `0.1.5-rc.2`。同一安装范围内其他后续版本仍需单独评估,遇到问题欢迎反馈。
158
+ - **DSH `0.2.1` 的工具更新**:增量工具更新只在 DSH 声明“只增不改”的 GPT Responses 路由上生效;当 DSH 的工具历史或模型信息缺失、路由不支持或设置卡片里关闭了开关时,LCX 回到每次发送完整工具列表。删除工具或同名重定义仍会让缓存失效一次。缓存命中受上游影响有波动:在 `openai/gpt-6-sol` 上用同一操作序列对比,开启时新增工具后的首个请求约 80% 命中缓存,关闭时为 0%。LCX 自带的模型目录冻结在 Pi `0.86`,目录里没有的新模型(如 `gpt-6-sol`)按 DSH 的声明处理。
159
+ - **验证范围**:`0.6.0-pre.1` 的验证基线只有 DSH `0.2.1-alpha.2`(预发布,host Pi `1.1.0`),安装范围没有上限,更新的 DSH 版本未经验证;该基线上的真实运行验证覆盖 GPT 路由、搜索、压缩、增量工具更新、`run_code` 内的搜索和插件管理页卡片等主要场景;其中 `run_code` 的实机检查在隔离环境里使用了完全访问的权限模式(DSH 的 Windows 文件沙箱在该机器上无法启动 `run_code`),程序只做了搜索调用。Grok 原生搜索和用户图片输入只做了有限的回归检查,Alpha 搜索和自然触发的压缩压力档位没有在这一轮覆盖。稳定版 `0.5.1` 的发布基线为 DSH `0.2.0-rc.2`(`0.5.0` 同);`0.4.4-pre.1` 在 DSH `0.1.6-alpha.2` 上完整验证;`0.4.3` 的稳定发布基线是 DSH `0.1.5-rc.1`,并已另外验证 DSH `0.1.5-rc.2`。同一安装范围内其他后续版本仍需单独评估,遇到问题欢迎反馈。
153
160
 
154
161
  ## 常见问题
155
162
 
@@ -166,7 +173,7 @@ dsh web
166
173
  从较早版本一路升级上来的配置目录里可能残留旧的依赖包。先停止 `dsh web`,把 DSH 主目录(默认 `~/.dsh`,或 `DSH_HOME` 指定的目录)下 `profiles/web/` 里的 `node_modules` 和 `pnpm-lock.yaml` 移走或删除,再重新运行对应的 `dsh plugin --profile web add dsh-lcx-codex@latest`(DSH `0.2.1-alpha.2` 及以后用 `@prelatest`),然后启动 `dsh web`。
167
174
 
168
175
  **刚发布新版时 `@latest` / `@prelatest` 装到了旧版本?**
169
- 包管理器的缓存可能还没刷新,DSH 会因版本不兼容拒绝安装。稍等几分钟重试,或直接指定版本号,例如 `dsh-lcx-codex@0.5.1-pre.1` 或 `dsh-lcx-codex@0.5.1`。
176
+ 包管理器的缓存可能还没刷新,DSH 会因版本不兼容拒绝安装。稍等几分钟重试,或直接指定版本号,例如 `dsh-lcx-codex@0.6.0-pre.1` 或 `dsh-lcx-codex@0.5.1`。
170
177
 
171
178
  ## 反馈问题
172
179
 
package/icon.svg ADDED
@@ -0,0 +1 @@
1
+ <svg width="36" height="36" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" stroke-width="1"><circle cx="6.9" cy="6.9" r="5.4" stroke="#658EFF"></circle><path d="M10.9 10.9L14.8 14.8" stroke="#658EFF" stroke-linecap="round"></path><path d="M6.9 3.9L7.8 6L9.9 6.9L7.8 7.8L6.9 9.9L6 7.8L3.9 6.9L6 6Z" stroke="#658EFF" stroke-linejoin="round"></path></svg>
package/lib/client.js CHANGED
@@ -398,16 +398,18 @@ a.lcx-media-chip:hover{text-decoration:underline;text-underline-offset:2px}
398
398
  return { ...group[0], sources: group.map((value) => value.url) };
399
399
  });
400
400
  }
401
+ var CHAT_FLOW_SLOT = "conversation.chat.flow";
401
402
  var activeDialogByDocument = /* @__PURE__ */ new WeakMap();
402
403
  function inlineMediaAnswer(marker) {
403
404
  const row = marker.closest('[data-chat-flow-kind="lcx-search-media"]');
404
405
  const ElementClass = marker.ownerDocument.defaultView?.HTMLElement;
405
406
  if (!ElementClass || !row || !row.dataset.chatTurn) return null;
406
407
  const group = row.closest("[data-chat-group-key][data-step-process]");
407
- const column = group?.parentElement;
408
- if (!group || !(column instanceof ElementClass) || !column.hasAttribute("data-chat-flow") || group.dataset.chatTurn !== row.dataset.chatTurn) return null;
408
+ const siblings = group?.parentElement;
409
+ const column = siblings?.dataset.slot === CHAT_FLOW_SLOT ? siblings.parentElement : siblings;
410
+ if (!group || !(siblings instanceof ElementClass) || !(column instanceof ElementClass) || !column.hasAttribute("data-chat-flow") || group.dataset.chatTurn !== row.dataset.chatTurn) return null;
409
411
  let answer = null;
410
- for (const child of column.children) {
412
+ for (const child of siblings.children) {
411
413
  if (child === group) break;
412
414
  if (child instanceof ElementClass && child.dataset.chatFlowKind === "assistant-step" && child.dataset.chatGroupPart === "response" && child.dataset.chatTurn === row.dataset.chatTurn) {
413
415
  answer = child;
@@ -806,10 +808,16 @@ a.lcx-media-chip:hover{text-decoration:underline;text-underline-offset:2px}
806
808
  var object = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
807
809
  var count = (v) => typeof v === "number" && Number.isSafeInteger(v) && v >= 0;
808
810
  var isSearchTool = (name) => name === "web_search" || name === "websearch_gpt_advanced";
811
+ var NESTED_SETTLE_EVENT = "tool/ptc-dispatch";
812
+ function searchSettlementOf(event, pendingName) {
813
+ if (!object(event) || !object(event.data) || !object(event.data.meta)) return;
814
+ const name = event.type === NESTED_SETTLE_EVENT ? event.data.name : event.type === "tool/result" ? pendingName : void 0;
815
+ return isSearchTool(name) ? { name, meta: event.data.meta } : void 0;
816
+ }
809
817
  function auxiliaryUsageOf(event, toolName) {
810
- if (!object(event) || event.type !== "tool/result" || !object(event.data?.meta)) return [];
811
- if (!isSearchTool(toolName)) return [];
812
- const raw = event.data.meta.auxiliaryUsage;
818
+ const settled = searchSettlementOf(event, toolName);
819
+ if (!settled) return [];
820
+ const raw = settled.meta.auxiliaryUsage;
813
821
  if (!Array.isArray(raw)) return [];
814
822
  const ids = /* @__PURE__ */ new Set(), result = [];
815
823
  for (const item of raw) {
@@ -822,12 +830,34 @@ a.lcx-media-chip:hover{text-decoration:underline;text-underline-offset:2px}
822
830
  return result;
823
831
  }
824
832
 
833
+ // src/client/nested-calls.ts
834
+ function createCallTurns(limit = 4096) {
835
+ const turns = /* @__PURE__ */ new Map();
836
+ return {
837
+ remember(callId, turn) {
838
+ if (typeof callId !== "string" || !Number.isSafeInteger(turn)) return;
839
+ turns.delete(callId);
840
+ turns.set(callId, turn);
841
+ if (turns.size > limit) turns.delete(turns.keys().next().value);
842
+ },
843
+ turnOf(callId) {
844
+ return typeof callId === "string" ? turns.get(callId) : void 0;
845
+ }
846
+ };
847
+ }
848
+
825
849
  // src/client/search-usage-ui.ts
850
+ var callTurns = createCallTurns();
826
851
  var searchUsageDefinition = {
827
852
  kind: "lcx-search-usage",
828
853
  match(event) {
829
854
  if (event.type === "turn/start") return { id: String(event.data.turn), role: "start" };
855
+ if (event.type === "tool/call") callTurns.remember(event.data.callId, event.data.turn);
830
856
  if (event.type === "turn/end" || event.type === "tool/result" || event.type === "tool/call") return { id: String(event.data.turn), role: "update" };
857
+ if (event.type === NESTED_SETTLE_EVENT) {
858
+ const turn = callTurns.turnOf(event.data.rootCallId);
859
+ return turn === void 0 ? null : { id: String(turn), role: "update" };
860
+ }
831
861
  return null;
832
862
  },
833
863
  start(_context, match) {
@@ -940,10 +970,11 @@ a.lcx-media-chip:hover{text-decoration:underline;text-underline-offset:2px}
940
970
  "alphaSearch",
941
971
  "grokNativeWebSearch",
942
972
  "grokNativeXSearch",
943
- "searchMediaPreview"
973
+ "searchMediaPreview",
974
+ "incrementalToolUpdates"
944
975
  ];
945
976
  const DEFAULTS = Object.fromEntries(
946
- FIELDS.map((field) => [field, false])
977
+ FIELDS.map((field) => [field, field === "incrementalToolUpdates"])
947
978
  );
948
979
  const css = `.lcx-card{border:1px solid var(--dsw-alias-border-l2);border-radius:8px;list-style:none}.lcx-head{width:100%;display:flex;justify-content:space-between;padding:14px 16px;border:0;background:transparent;color:inherit}.lcx-body{border-top:1px solid var(--dsw-alias-border-l2);padding:12px 16px}.lcx-row{display:flex;gap:9px;padding:8px 0}.lcx-row small,.lcx-help{display:block;font-size:12px;line-height:17px;color:var(--dsw-alias-label-tertiary)}.lcx-group{border-top:1px solid var(--dsw-alias-border-l2);margin-top:10px;padding-top:14px}.lcx-group strong{font-size:14px}.lcx-foot{display:flex;justify-content:flex-end;gap:8px;margin-top:10px}.lcx-foot button{padding:6px 12px;border-radius:8px;border:1px solid var(--dsw-alias-border-l2);background:transparent;color:inherit}.lcx-search-usage{display:inline-flex;align-items:center;gap:4px;margin:2px 0;color:var(--dsw-alias-label-tertiary);font:12px/18px system-ui}.lcx-search-usage-session{padding:0 4px}.lcx-search-usage-turn{padding:0 6px}` + inlineMediaCss + nativeMarkdownImageCss;
949
980
  function mountCss() {
@@ -971,6 +1002,8 @@ a.lcx-media-chip:hover{text-decoration:underline;text-underline-offset:2px}
971
1002
  advancedHelp: "\u53EA\u5728\u9700\u8981\u57DF\u540D\u8FC7\u6EE4\u3001\u4F4D\u7F6E\u3001search context\u3001\u56FE\u7247\u7B49\u539F\u751F Hosted \u53C2\u6570\u65F6\u4F7F\u7528\uFF1B\u9ED8\u8BA4\u5173\u95ED\u4EE5\u4FDD\u6301\u5DE5\u5177 schema \u7A33\u5B9A\u3002",
972
1003
  alpha: "\u542F\u7528 Alpha command\uFF08websearch_alpha\uFF09",
973
1004
  alphaHelp: "\u4EC5 capability probe \u5BF9\u5F53\u524D route/schema \u9A8C\u8BC1\u901A\u8FC7\u540E\u624D\u771F\u6B63\u6CE8\u518C\u3002",
1005
+ tools: "\u589E\u91CF\u5DE5\u5177\u66F4\u65B0\uFF08addition-only\uFF09",
1006
+ toolsHelp: "\u4F1A\u8BDD\u4E2D\u9014\u65B0\u589E\u5DE5\u5177\u65F6\u4FDD\u6301\u8BF7\u6C42\u524D\u7F00\u4E0D\u53D8\u4EE5\u4FDD\u62A4 prompt \u7F13\u5B58\uFF0C\u65B0\u589E\u5DE5\u5177\u4F5C\u4E3A\u5386\u53F2\u9879\u58F0\u660E\u3002\u4EC5\u5BF9\u652F\u6301\u7684 GPT Responses \u6A21\u578B\u751F\u6548\uFF1B\u5173\u95ED\u540E\u6BCF\u6B21\u8BF7\u6C42\u53D1\u9001\u5B8C\u6574\u5DE5\u5177\u5217\u8868\uFF08\u56DE\u9000\u6216\u5BF9\u7167\u7528\uFF09\u3002\u5220\u9664\u6216\u4FEE\u6539\u5DE5\u5177\u4ECD\u4F1A\u91CD\u7F6E\u4E00\u6B21\u7F13\u5B58\u3002",
974
1007
  mediaPreview: "\u641C\u7D22\u5A92\u4F53\u9884\u89C8",
975
1008
  mediaPreviewHelp: "\u5728\u56DE\u7B54\u4E0B\u65B9\u663E\u793A\u641C\u7D22\u8FD4\u56DE\u7684\u56FE\u7247\u3001\u56DE\u7B54\u91CC\u7684\u56FE\u7247\u76F4\u94FE\uFF0C\u4EE5\u53CA\u53EF\u76F4\u63A5\u64AD\u653E\u7684\u89C6\u9891\u76F4\u94FE\uFF1B\u70B9\u51FB\u653E\u5927\u6216\u64AD\u653E\u3002\u56DE\u7B54\u6B63\u6587\u91CC\u7684 Markdown \u56FE\u7247\u7531 DSH \u539F\u751F\u6E32\u67D3\uFF0C\u666E\u901A\u7F51\u9875\u94FE\u63A5\u4FDD\u6301\u4E3A\u94FE\u63A5\u3002\u6B64\u8BBE\u7F6E\u53EA\u6539\u53D8\u754C\u9762\u663E\u793A\u3002",
976
1009
  mediaTitle: "\u89C6\u9891\u9884\u89C8",
@@ -1009,6 +1042,8 @@ a.lcx-media-chip:hover{text-decoration:underline;text-underline-offset:2px}
1009
1042
  advancedHelp: "Only for native Hosted controls such as domains, location, context size and image search; off by default for stable tool schemas.",
1010
1043
  alpha: "Enable Alpha command (websearch_alpha)",
1011
1044
  alphaHelp: "Registered only after a matching capability probe.",
1045
+ tools: "Incremental tool updates (addition-only)",
1046
+ toolsHelp: "When a tool is added mid-session, keep the request prefix unchanged to protect the prompt cache; the new tool is declared in history. Applies only to supporting GPT Responses models. Off sends the complete tool list on every request (rollback or comparison). Removing or redefining a tool still resets the cache once.",
1012
1047
  mediaPreview: "Search media previews",
1013
1048
  mediaPreviewHelp: "Show images returned by search, direct image links in the answer and directly playable video links below the answer; click to enlarge or play. Markdown images in the answer are rendered natively by DSH, and ordinary page links stay links. This setting changes presentation only.",
1014
1049
  mediaTitle: "Video preview",
@@ -1041,19 +1076,29 @@ a.lcx-media-chip:hover{text-decoration:underline;text-underline-offset:2px}
1041
1076
  return {
1042
1077
  ...DEFAULTS,
1043
1078
  ...Object.fromEntries(
1044
- FIELDS.map((field) => [field, Boolean(value[field])])
1079
+ FIELDS.map((field) => [
1080
+ field,
1081
+ value[field] === void 0 ? DEFAULTS[field] : Boolean(value[field])
1082
+ ])
1045
1083
  )
1046
1084
  };
1047
1085
  }
1048
1086
  const hostedMediaTool = (value) => value === "web_search" || value === "websearch_gpt_advanced";
1087
+ const callTurns2 = createCallTurns();
1049
1088
  const searchMediaDefinition = {
1050
1089
  kind: SEARCH_MEDIA_KIND,
1051
1090
  target: "chat",
1052
1091
  match(event) {
1053
1092
  if (event.type === "turn/start")
1054
1093
  return { id: String(event.data.turn), role: "start" };
1094
+ if (event.type === "tool/call")
1095
+ callTurns2.remember(event.data.callId, event.data.turn);
1055
1096
  if (event.type === "tool/result" || event.type === "tool/call")
1056
1097
  return { id: String(event.data.turn), role: "update" };
1098
+ if (event.type === NESTED_SETTLE_EVENT) {
1099
+ const turn = callTurns2.turnOf(event.data.rootCallId);
1100
+ return turn === void 0 ? null : { id: String(turn), role: "update" };
1101
+ }
1057
1102
  if (event.type !== "assistant/message" || event.surfaceOp !== "append" || event.data.interrupted === true)
1058
1103
  return null;
1059
1104
  const source = event.data.message.source;
@@ -1086,6 +1131,17 @@ a.lcx-media-chip:hover{text-decoration:underline;text-underline-offset:2px}
1086
1131
  }
1087
1132
  };
1088
1133
  }
1134
+ if (match.event.type === NESTED_SETTLE_EVENT) {
1135
+ const { name, meta } = match.event.data;
1136
+ if (!hostedMediaTool(name)) return context.state;
1137
+ return {
1138
+ ...context.state,
1139
+ structuredItems: mergeSearchMedia(
1140
+ context.state.structuredItems,
1141
+ structuredSearchMedia(meta, name)
1142
+ )
1143
+ };
1144
+ }
1089
1145
  if (match.event.type === "tool/result") {
1090
1146
  const callId = match.event.data.message.source.callId;
1091
1147
  const tool = context.state.pending[callId];
@@ -1355,6 +1411,14 @@ a.lcx-media-chip:hover{text-decoration:underline;text-underline-offset:2px}
1355
1411
  disabled: disabled || !s.enabled.value,
1356
1412
  onChange: (value) => props.edit("alphaSearch", value)
1357
1413
  }),
1414
+ React.createElement(Row, {
1415
+ id: "lcx-tools",
1416
+ label: t("tools"),
1417
+ help: t("toolsHelp"),
1418
+ checked: s.incrementalToolUpdates.value,
1419
+ disabled,
1420
+ onChange: (value) => props.edit("incrementalToolUpdates", value)
1421
+ }),
1358
1422
  React.createElement(
1359
1423
  "section",
1360
1424
  { className: "lcx-group" },
@@ -2,6 +2,7 @@ import { IMAGE_OFFLOAD_REQUIRED_CODE, LlmError, offloadedImageText, projectOfflo
2
2
  import { requestImageDimensions } from "@deepseek-ai/dsh-attachment";
3
3
  import { convertResponsesMessages, convertResponsesTools, createGrammarToolInputProperties, getBuiltinModels, normalizeContext, } from "./pi-responses-runtime.js";
4
4
  import { wasPi086ResponsesModel } from "./pi086-responses-allowlist.js";
5
+ import { withoutDeferLoading } from "./tool-surface.js";
5
6
  const DEFAULT_MAX_REQUEST_IMAGE_BYTES = 20 * 1024 * 1024;
6
7
  const DEFAULT_REQUEST_IMAGE_PIXEL_BUDGET = 2048 * 2048;
7
8
  const DEFAULT_REQUEST_IMAGE_MAX_BYTES = 1024 * 1024;
@@ -72,11 +73,15 @@ function imageAccess(ctx, attachments, ref) {
72
73
  : () => undefined;
73
74
  return attachments.resolveAccess(mapper, ref);
74
75
  }
75
- /** One adapter-owned lookup supplies the model facts a route needs: image support and reasoning efforts. */
76
+ /**
77
+ * Facts DSH resolves for the exact routed model through `llm.resolveModelInfo`, the same
78
+ * adapter-owned metadata the agent loop uses to choose how a system prompt change is recorded.
79
+ * Resolution failure reports `resolved: false` with conservative defaults (unknown image support, no in-history mode).
80
+ */
76
81
  export async function resolveRouteModelFacts(ctx, route, signal) {
77
82
  const llm = ctx?.llm;
78
83
  if (llm === undefined)
79
- return { imageSupport: "unknown", reasoning: undefined, resolved: false };
84
+ return { imageSupport: "unknown", systemPromptUpdate: undefined, toolUpdate: undefined, reasoning: undefined, resolved: false };
80
85
  try {
81
86
  const info = await llm.resolveModelInfo(stringValue(route.provider), stringValue(route.model), signal);
82
87
  const modalities = info.inputModalities;
@@ -86,6 +91,8 @@ export async function resolveRouteModelFacts(ctx, route, signal) {
86
91
  : modalities !== undefined
87
92
  ? "unsupported"
88
93
  : "unknown",
94
+ systemPromptUpdate: info.systemPromptUpdate === "in-history" ? "in-history" : undefined,
95
+ toolUpdate: info.toolUpdate === "addition-only" || info.toolUpdate === "in-history" ? info.toolUpdate : undefined,
89
96
  reasoning: info.reasoning === undefined
90
97
  ? undefined
91
98
  : { efforts: info.reasoning.efforts.map((effort) => String(effort.id)) },
@@ -93,7 +100,9 @@ export async function resolveRouteModelFacts(ctx, route, signal) {
93
100
  };
94
101
  }
95
102
  catch {
96
- return { imageSupport: "unknown", reasoning: undefined, resolved: false };
103
+ // `resolved: false` tells callers the mode is unknown rather than known-absent, so they can refuse
104
+ // to downgrade history that only an in-history route may legitimately contain.
105
+ return { imageSupport: "unknown", systemPromptUpdate: undefined, toolUpdate: undefined, reasoning: undefined, resolved: false };
97
106
  }
98
107
  }
99
108
  export async function resolveModelImageSupport(ctx, route, signal) {
@@ -366,6 +375,15 @@ async function prepareRequestImageVersions(messages, ctx, options) {
366
375
  }));
367
376
  return new Map(versions);
368
377
  }
378
+ /** A full system prompt snapshot written by DSH's own system-prompt projection. */
379
+ export function isPromptSnapshotMessage(message) {
380
+ return message.role === "system" && message.source?.kind === "system-prompt";
381
+ }
382
+ /** Whether history after the leading head holds a non-empty DSH prompt snapshot (an in-history update). */
383
+ export function hasMidHistoryPromptSnapshot(messages) {
384
+ return messages.slice(1).some((message) => isPromptSnapshotMessage(message) &&
385
+ message.content.some((block) => block.type === "text" && block.text.length > 0));
386
+ }
369
387
  function flattenMessageText(message) {
370
388
  return message.content.map((block) => {
371
389
  if (block.type !== "text")
@@ -378,11 +396,41 @@ async function dshToPiMessages(messages, ctx, options, imageMap, requestImages)
378
396
  const toolNames = new Map();
379
397
  for (const message of messages) {
380
398
  if (message.role === "system") {
399
+ if (options.inHistorySystem === true) {
400
+ // In-history routes record a changed system prompt as a full later `system` message that keeps
401
+ // instruction authority. Pi renders a non-leading system message with the model's instruction
402
+ // role (developer for reasoning models, system otherwise) at this exact position.
403
+ const text = flattenMessageText(message);
404
+ if (text.length > 0) {
405
+ // A throwaway marker message directly before a DSH prompt snapshot lets the serializer trace the
406
+ // rendered item back to its source message without inspecting text; it is removed afterwards.
407
+ if (options.snapshotMarker !== undefined && isPromptSnapshotMessage(message))
408
+ result.push({ role: "user", content: options.snapshotMarker, timestamp: 0 });
409
+ result.push({ role: "system", content: text, timestamp: 0 });
410
+ }
411
+ continue;
412
+ }
381
413
  result.push({ role: "user", content: flattenMessageText(message), timestamp: 0 });
382
414
  continue;
383
415
  }
384
- if (message.role === "developer")
385
- throw unsupportedContent("developer message");
416
+ if (message.role === "developer") {
417
+ // Mirrors the host adapter's `appendDeveloper`: one tool-registry event becomes one system update that
418
+ // carries the added declarations; Pi renders it as `additional_tools` at this exact position.
419
+ if (options.anchoredTools === undefined)
420
+ throw unsupportedContent("developer message");
421
+ const toolsAdded = [];
422
+ for (const block of message.content) {
423
+ if (block.type !== "tool-addition")
424
+ throw unsupportedContent(block.type);
425
+ const tool = options.anchoredTools.find((candidate) => candidate.name === block.toolName);
426
+ if (tool === undefined)
427
+ throw error(`LCX tool update references undeclared tool "${block.toolName}"`, "LCX_RESPONSES_INVALID_INPUT");
428
+ toolsAdded.push(tool);
429
+ }
430
+ if (toolsAdded.length > 0)
431
+ result.push({ role: "system", content: [], toolsAdded, timestamp: 0 });
432
+ continue;
433
+ }
386
434
  if (message.role === "assistant") {
387
435
  const assistant = toPiAssistant(message, options.onReplayDegrade);
388
436
  for (const block of assistant.content)
@@ -443,26 +491,40 @@ export function resolvePiResponsesModel(options) {
443
491
  return { ...builtinRecord, ...explicit, id, name: stringValue(explicit.name, stringValue(builtinRecord.name, id)), api: "openai-responses", provider, baseUrl: stringValue(explicit.baseUrl, stringValue(route.baseURL, stringValue(builtinRecord.baseUrl))), reasoning: typeof explicit.reasoning === "boolean" ? explicit.reasoning : typeof builtinRecord.reasoning === "boolean" ? builtinRecord.reasoning : true, input, cost: explicit.cost ?? builtinRecord.cost ?? { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }, contextWindow: positiveSafeInteger(explicit.contextWindow ?? builtinRecord.contextWindow, 262144), maxTokens: positiveSafeInteger(explicit.maxTokens ?? builtinRecord.maxTokens, 32768), ...(Object.keys(compat).length > 0 ? { compat } : {}) };
444
492
  }
445
493
  export async function serializeDshMessages(messages, ctx, options = {}) {
494
+ const anchored = options.toolUpdate === "addition-only";
495
+ if (anchored && options.systemPromptUpdate !== "in-history")
496
+ throw error("LCX addition-only tool updates require an in-history route", "LCX_RESPONSES_INVALID_INPUT");
446
497
  for (const message of messages) {
447
- if (message.role === "developer")
498
+ if (message.role === "developer" && !anchored)
448
499
  throw unsupportedContent("developer message");
449
500
  for (const block of message.content)
450
- if (block.type === "tool-addition" || block.type === "tool-removal")
451
- throw unsupportedContent(block.type);
501
+ if (block.type === "tool-addition" || block.type === "tool-removal") {
502
+ // Removals never reach a serializer: the host projection drops them on an addition-only route.
503
+ if (!anchored || message.role !== "developer" || block.type === "tool-removal")
504
+ throw unsupportedContent(block.type);
505
+ }
452
506
  }
453
507
  for (const tool of options.tools ?? [])
454
- if ("deferLoading" in tool && tool.deferLoading === true)
508
+ if (!anchored && "deferLoading" in tool && tool.deferLoading === true)
455
509
  throw unsupportedContent("deferLoading tool declaration");
510
+ // Declared = every tool the history may reference; immediate = the subset that stays in the request `tools`.
511
+ const declaredTools = (Array.isArray(options.tools) ? options.tools : []).map((tool) => withoutDeferLoading(tool));
512
+ const immediateDeclared = (Array.isArray(options.tools) ? options.tools : [])
513
+ .filter((tool) => !("deferLoading" in tool && tool.deferLoading === true))
514
+ .map((tool) => withoutDeferLoading(tool));
456
515
  const normalized = {
457
516
  imageSupport: options.imageSupport === "supported" || options.imageSupport === "unsupported" ? options.imageSupport : "unknown",
458
517
  signal: options.signal instanceof AbortSignal ? options.signal : undefined,
459
518
  route: options.route ?? {}, model: options.model, responsesCompat: options.responsesCompat,
460
519
  systemPrompt: typeof options.systemPrompt === "string" ? options.systemPrompt : undefined,
461
520
  includeSystemPrompt: options.includeSystemPrompt === true, onReplayDegrade: options.onReplayDegrade,
521
+ inHistorySystem: options.systemPromptUpdate === "in-history",
522
+ snapshotMarker: options.systemPromptUpdate === "in-history" ? `\u0000lcx-prompt-snapshot:${globalThis.crypto.randomUUID()}` : undefined,
462
523
  maxRequestImageBytes: positiveSafeInteger(options.maxRequestImageBytes, DEFAULT_MAX_REQUEST_IMAGE_BYTES),
463
524
  requestImagePixelBudget: positiveSafeInteger(options.requestImagePixelBudget, DEFAULT_REQUEST_IMAGE_PIXEL_BUDGET),
464
525
  requestImageMaxBytes: positiveSafeInteger(options.requestImageMaxBytes, DEFAULT_REQUEST_IMAGE_MAX_BYTES),
465
- tools: Array.isArray(options.tools) ? options.tools : [],
526
+ tools: immediateDeclared,
527
+ ...(anchored ? { anchoredTools: declaredTools } : {}),
466
528
  };
467
529
  const imageMap = new Map();
468
530
  const fileProjected = projectFiles(messages, ctx);
@@ -490,19 +552,57 @@ export async function serializeDshMessages(messages, ctx, options = {}) {
490
552
  const supportsAdditionalTools = compat.supportsAdditionalTools === true;
491
553
  const supportsToolSearch = compat.supportsToolSearch === true;
492
554
  const deferredToolsMode = supportsAdditionalTools ? "additional-tools" : supportsToolSearch ? "tool-search" : undefined;
493
- const grammarToolInputProperties = createGrammarToolInputProperties(dshContext.tools, supportsOpenAIGrammarTools);
494
- // These routes consume no tool updates; projectToolUpdates supplies the current immediate declarations.
555
+ const grammarToolInputProperties = createGrammarToolInputProperties([...(normalized.anchoredTools ?? dshContext.tools)], supportsOpenAIGrammarTools);
556
+ // Immediate declarations only: on an anchored surface deferred tools are declared by their history additions.
495
557
  const immediateTools = new Map();
496
558
  for (const tool of dshContext.tools)
497
559
  if (tool.name)
498
560
  immediateTools.set(tool.name, tool);
499
561
  const toolOptions = { supportsStrictMode, supportsOpenAIGrammarTools, toolSearchResult: false };
500
- const piContext = normalizeContext(dshContext);
562
+ const normalizedContext = normalizeContext(dshContext);
563
+ // Pi treats whichever system message is first in the transcript as the leading prompt: it skips it when
564
+ // includeSystemPrompt is false and renders it without the update framing. A serialization batch carrying
565
+ // no caller-owned head (no systemPrompt/tools) must never promote a history update to that slot, so an
566
+ // empty placeholder holds the leading position and renders nothing.
567
+ const piContext = normalized.inHistorySystem && normalizedContext.messages[0]?.role === "system" && normalizedContext.messages === dshContext.messages
568
+ ? { ...normalizedContext, messages: [{ role: "system", content: "", timestamp: 0 }, ...normalizedContext.messages] }
569
+ : normalizedContext;
501
570
  const piModel = model;
502
- const convertedInput = convertResponsesMessages(piModel, piContext, new Set(["openai", "openai-codex", "opencode"]), { includeSystemPrompt: normalized.includeSystemPrompt, grammarToolInputProperties, supportsAdditionalTools, supportsToolSearch, toolOptions });
503
- const input = restorePortableAssistantPhases(convertedInput, dshContext.messages, { provider: model.provider, id: model.id, api: model.api });
571
+ // Pi collapses every system message into the leading one unless the transport accepts mid-conversation
572
+ // system messages, which would drop or reorder in-history updates in batched serialization.
573
+ const convertedInput = convertResponsesMessages(piModel, piContext, new Set(["openai", "openai-codex", "opencode"]), { includeSystemPrompt: normalized.includeSystemPrompt, grammarToolInputProperties, supportsAdditionalTools, supportsToolSearch, supportsMidConvoSystemMessages: normalized.inHistorySystem, toolOptions });
574
+ const supersededInstructionItems = [];
575
+ const unmarkedInput = [];
576
+ let markersFound = 0;
577
+ for (let position = 0; position < convertedInput.length; position += 1) {
578
+ const item = convertedInput[position];
579
+ if (normalized.snapshotMarker !== undefined && isMarkerItem(item, normalized.snapshotMarker)) {
580
+ markersFound += 1;
581
+ const rendered = convertedInput[position + 1];
582
+ if (!isObject(rendered) || (rendered.role !== "developer" && rendered.role !== "system"))
583
+ throw error("LCX could not trace a rendered system prompt snapshot", "LCX_RESPONSES_INVALID_INPUT");
584
+ supersededInstructionItems.push(unmarkedInput.length);
585
+ continue;
586
+ }
587
+ unmarkedInput.push(item);
588
+ }
589
+ if (normalized.snapshotMarker !== undefined) {
590
+ // Markers are inserted only before non-empty snapshots (empty ones render nothing), so each inserted
591
+ // marker must be found exactly once and none may survive in the output, even if a future Pi merged
592
+ // adjacent user messages.
593
+ const inserted = dshContext.messages.filter((message) => message.role === "user" && message.content === normalized.snapshotMarker).length;
594
+ const nonce = normalized.snapshotMarker.slice(normalized.snapshotMarker.lastIndexOf(":") + 1);
595
+ if (markersFound !== inserted || JSON.stringify(unmarkedInput).includes(nonce))
596
+ throw error("LCX could not remove a system prompt snapshot marker", "LCX_RESPONSES_INVALID_INPUT");
597
+ }
598
+ const input = restorePortableAssistantPhases(unmarkedInput, dshContext.messages, { provider: model.provider, id: model.id, api: model.api });
504
599
  const tools = options.tools === undefined ? undefined : convertResponsesTools([...immediateTools.values()], toolOptions);
505
- return { input, imageMap, tools, model: piModel, grammarToolInputProperties, deferredToolsMode };
600
+ return { input, supersededInstructionItems, imageMap, tools, model: piModel, grammarToolInputProperties, deferredToolsMode };
601
+ }
602
+ function isMarkerItem(item, marker) {
603
+ if (!isObject(item) || item.role !== "user" || !Array.isArray(item.content))
604
+ return false;
605
+ return item.content.length === 1 && isObject(item.content[0]) && item.content[0].text === marker;
506
606
  }
507
607
  export function responsesTools(tools) {
508
608
  if (tools === undefined)
package/lib/index.js CHANGED
@@ -12,10 +12,11 @@ import { join } from "node:path";
12
12
  import { AsyncLocalStorage } from "node:async_hooks";
13
13
  import { getSupportedThinkingLevels } from "./pi-responses-runtime.js";
14
14
  import { fetchJsonWithRetry } from "./transport.js";
15
+ import { DEFAULT_TOOL_UPDATES, planToolSurface, withoutDeferLoading } from "./tool-surface.js";
15
16
  import { agentSessionId, agentUsesSession, compactionConfigState, compactionPatchCandidate, installCompactionPatch, patchCompactionConfig, patchToolResultPruner, readAgentRouteState, readSelectedAgentRouteState, recordAgentRouteEvent, resolveAgentService, resolveContextService, resolveScopedService, restoreCompactionConfig, restoreCompactionPatches, restoreToolResultPruner, sessionFor, sessionFromAgent, scopedToolRuntime, onScopedToolExecute, tokenMeterTotal, toolResultPrunerState, } from "./dsh-compat.js";
16
17
  import { InvocationPolicyScope } from "./invocation-policy-scope.js";
17
18
  import { authenticatedGrokHeaders, authenticatedHeaders, currentRoute, generationControlsFromSession, grokPromptCacheSessionId, promptCacheKey, promptCacheRetention, promptCacheSessionId, resolveGrokResponsesRouteConfig, resolveResponsesRouteConfig, routeFingerprint, } from "./route.js";
18
- import { DEFAULT_MAX_REQUEST_IMAGE_BYTES, DEFAULT_REQUEST_IMAGE_PIXEL_BUDGET, DEFAULT_REQUEST_IMAGE_MAX_BYTES, assertAggregateImageBudget, hydrateNativeImageReferences, inputImageBase64Lengths, resolveRouteModelFacts, responseInputItems, serializeDshMessages, } from "./dsh-responses.js";
19
+ import { DEFAULT_MAX_REQUEST_IMAGE_BYTES, DEFAULT_REQUEST_IMAGE_PIXEL_BUDGET, DEFAULT_REQUEST_IMAGE_MAX_BYTES, assertAggregateImageBudget, hydrateNativeImageReferences, inputImageBase64Lengths, resolveRouteModelFacts, hasMidHistoryPromptSnapshot, responseInputItems, serializeDshMessages, } from "./dsh-responses.js";
19
20
  import { mergeFeatureHeader, requestNativeCompaction } from "./compact-v2.js";
20
21
  import { buildResponsesBody } from "./responses-request.js";
21
22
  import { managedFailureChunk, streamResponsesRequest, } from "./responses-stream.js";
@@ -57,6 +58,7 @@ function routeWithPolicies(route, config) {
57
58
  portableReplayMaxChars: config.portableReplayMaxChars,
58
59
  requestImageMaxBytes: route.requestImageMaxBytes ?? config.requestImageMaxBytes,
59
60
  requestImagePixelBudget: route.requestImagePixelBudget ?? config.requestImagePixelBudget,
61
+ toolUpdates: config.toolUpdates,
60
62
  webMaxResults: config.webMaxResults,
61
63
  };
62
64
  }
@@ -100,6 +102,7 @@ export const Config = z.object({
100
102
  grokNativeWebSearch: z.boolean().default(false).volatile(),
101
103
  grokNativeXSearch: z.boolean().default(false).volatile(),
102
104
  searchMediaPreview: z.boolean().default(false).volatile(),
105
+ incrementalToolUpdates: z.boolean().default(true).volatile(),
103
106
  supportsLongCacheRetention: z.boolean().default(false),
104
107
  supportsExplicitPromptCacheMode: z.boolean().default(false),
105
108
  alphaCapabilityPath: z.string().default(""),
@@ -147,6 +150,7 @@ function normalizeConfig(input = {}) {
147
150
  ? input.assistantRetentionTokenReserve
148
151
  : 24_000,
149
152
  assistantRetentionPerMessageTokenCap: positiveInteger(input.assistantRetentionPerMessageTokenCap, 3_000),
153
+ toolUpdates: DEFAULT_TOOL_UPDATES,
150
154
  };
151
155
  }
152
156
  function webError(message, code, cause) {
@@ -549,6 +553,27 @@ function mergeMap(target, source) {
549
553
  for (const [key, value] of source ?? [])
550
554
  target.set(key, value);
551
555
  }
556
+ /**
557
+ * Follow traced item positions through the Grok replay restoration, which may splice items. When the
558
+ * item count is unchanged the positions are exact; otherwise each traced item is found again by exact
559
+ * structural equality in order (restoration never alters instruction items).
560
+ */
561
+ function locateSupersededItems(original, restored, positions) {
562
+ if (positions.length === 0 || original.length === restored.length)
563
+ return [...positions];
564
+ const located = [];
565
+ let cursor = 0;
566
+ for (const position of positions) {
567
+ const wanted = JSON.stringify(original[position]);
568
+ while (cursor < restored.length && JSON.stringify(restored[cursor]) !== wanted)
569
+ cursor += 1;
570
+ if (cursor >= restored.length)
571
+ throw Object.assign(new Error("LCX lost track of a superseded system prompt item"), { code: "LCX_RESPONSES_INVALID_INPUT" });
572
+ located.push(cursor);
573
+ cursor += 1;
574
+ }
575
+ return located;
576
+ }
552
577
  /**
553
578
  * The reasoning projection a GPT route serializes and sends with. A profile's declared
554
579
  * `reasoningEfforts` wins (wire mapping, or `false` for a non-reasoning model); otherwise the catalog
@@ -571,23 +596,77 @@ function assertSupportedReasoningEffort(effort, facts) {
571
596
  return;
572
597
  throw Object.assign(new Error(`Responses route does not support reasoning effort "${String(effort)}"`), { code: "LCX_RESPONSES_UNSUPPORTED_OPTION" });
573
598
  }
574
- async function serializeNativeAware(messages, route, routeConfig, ctx, options) {
599
+ const reportedToolSurfaceFallbacks = new Set();
600
+ /**
601
+ * Say why a request carries the complete tool list although the policy asked for addition-only updates.
602
+ * One line per session and reason: a warning when the host declared addition-only (LCX should have been able to
603
+ * follow), a debug line otherwise. The reasons are fixed phrases; no request content, key or header is logged.
604
+ */
605
+ function reportToolSurfaceFallback(ctx, route, surface) {
606
+ const reason = surface.fallbackReason ?? "unknown";
607
+ const key = `${route.sessionId}${reason}`;
608
+ if (reportedToolSurfaceFallbacks.has(key))
609
+ return;
610
+ if (reportedToolSurfaceFallbacks.size >= 256)
611
+ reportedToolSurfaceFallbacks.clear();
612
+ reportedToolSurfaceFallbacks.add(key);
613
+ const message = `[lcx-codex] tool updates: sending the complete tool list on ${route.provider}/${route.model} (${reason})`;
614
+ if (surface.fallbackUnexpected === true)
615
+ ctx.logger?.warn?.(message);
616
+ else
617
+ ctx.logger?.debug?.(message);
618
+ }
619
+ async function serializeNativeAware(rawMessages, route, routeConfig, ctx, options) {
575
620
  const session = sessionFor(ctx, route.sessionId);
621
+ // One adapter-owned lookup supplies image support and the route's system-prompt update mode. On an
622
+ // "in-history" route DSH appends a changed prompt as a later full system message; it must reach the
623
+ // model in place with instruction authority instead of being demoted to user context.
576
624
  const modelFacts = await resolveRouteModelFacts(ctx, route, options.signal);
577
- const { imageSupport } = modelFacts;
625
+ const { imageSupport, systemPromptUpdate, resolved } = modelFacts;
578
626
  const modelOverride = options.grokNativeReplayRoute === undefined
579
627
  ? gptModelOverride(routeConfig, modelFacts)
580
628
  : undefined;
629
+ let messages = rawMessages;
630
+ let tools = options.tools;
631
+ let anchoredTools = false;
632
+ let toolSurfaceCompat;
633
+ if (options.toolSurface !== undefined) {
634
+ const surface = planToolSurface({
635
+ mode: routeConfig.toolUpdates ?? DEFAULT_TOOL_UPDATES,
636
+ messages: rawMessages,
637
+ tools: options.tools,
638
+ toolHistory: options.toolSurface.history,
639
+ facts: modelFacts,
640
+ compat: routeConfig.responsesCompat,
641
+ });
642
+ messages = surface.messages;
643
+ tools = surface.tools;
644
+ anchoredTools = surface.anchored;
645
+ toolSurfaceCompat = surface.compat;
646
+ if (surface.fallbackReason !== undefined)
647
+ reportToolSurfaceFallback(ctx, route, surface);
648
+ }
649
+ // An unreadable model mode must not demote instructions: history that holds a DSH prompt snapshot after
650
+ // the head can only come from an in-history route, and sending it as user text would silently lower its
651
+ // authority. Without such history the conservative default is harmless, so ordinary requests proceed.
652
+ if (!resolved && hasMidHistoryPromptSnapshot(messages))
653
+ throw Object.assign(new Error("LCX could not read the route's model information, so in-history system prompt updates cannot be sent safely; retry once the route is available"), { code: "LCX_SYSTEM_PROMPT_MODE_UNKNOWN" });
581
654
  const input = [];
582
655
  const imageMap = new Map();
583
656
  let nativeTools;
584
657
  let nativeModel;
585
658
  let grammarToolInputProperties;
586
659
  let normal = [];
660
+ /** Absolute `input` positions rendered from DSH prompt snapshots that a checkpoint supersedes. */
661
+ const supersededInstructionItems = [];
587
662
  const serializeOptions = (imageMapOverride = undefined, extra = {}) => requestImageOptions(routeConfig, imageSupport, options.signal, imageMapOverride, {
588
663
  route,
589
- tools: options.tools,
590
- responsesCompat: routeConfig.responsesCompat,
664
+ tools,
665
+ responsesCompat: toolSurfaceCompat === undefined
666
+ ? routeConfig.responsesCompat
667
+ : { ...routeConfig.responsesCompat, ...toolSurfaceCompat },
668
+ systemPromptUpdate,
669
+ ...(anchoredTools ? { toolUpdate: "addition-only" } : {}),
591
670
  ...(modelOverride === undefined ? {} : { model: modelOverride }),
592
671
  ...extra,
593
672
  });
@@ -618,11 +697,18 @@ async function serializeNativeAware(messages, route, routeConfig, ctx, options)
618
697
  normal = [];
619
698
  const serialized = await serializeDshMessages(batch, ctx, serializeOptions());
620
699
  surfaceImageBytes.push(...inputImageBase64Lengths(serialized.input));
700
+ // Every batch derives its request tools from the same immediate declarations; a difference would
701
+ // change the cached prefix between batches of one request.
702
+ if (anchoredTools && JSON.stringify(serialized.tools) !== JSON.stringify(nativeTools))
703
+ throw Object.assign(new Error("LCX anchored tool declarations diverged between serialization batches"), { code: "LCX_RESPONSES_INVALID_INPUT" });
621
704
  nativeTools = serialized.tools ?? nativeTools;
622
705
  nativeModel = serialized.model ?? nativeModel;
623
706
  grammarToolInputProperties =
624
707
  serialized.grammarToolInputProperties ?? grammarToolInputProperties;
625
- input.push(...restoreGrokNativeReplay(serialized.input, batch.filter(isPersistedMessage), options.grokNativeReplayRoute));
708
+ const restored = restoreGrokNativeReplay(serialized.input, batch.filter(isPersistedMessage), options.grokNativeReplayRoute);
709
+ const base = input.length;
710
+ supersededInstructionItems.push(...locateSupersededItems(serialized.input, restored, serialized.supersededInstructionItems).map((position) => base + position));
711
+ input.push(...restored);
626
712
  mergeMap(imageMap, serialized.imageMap);
627
713
  };
628
714
  for (const message of surfaceMessages ?? []) {
@@ -649,7 +735,17 @@ async function serializeNativeAware(messages, route, routeConfig, ctx, options)
649
735
  }
650
736
  else {
651
737
  const portable = await portableMessagesForCheckpoint(ctx, session, checkpointId, { maxChars: routeConfig.portableReplayMaxChars });
652
- const serialized = await serializeDshMessages(portable, ctx, serializeOptions());
738
+ // Shadowed history is superseded by the head DSH re-rendered when the compaction began its new
739
+ // series, so its old system messages stay ordinary context instead of regaining instruction
740
+ // authority behind the current prompt.
741
+ const serialized = await serializeDshMessages(portable, ctx,
742
+ // Portable history is plain context: it carries no developer updates, and deferred declarations are
743
+ // only meaningful to the anchored surface itself.
744
+ serializeOptions(undefined, {
745
+ systemPromptUpdate: undefined,
746
+ toolUpdate: undefined,
747
+ tools: tools?.map((tool) => withoutDeferLoading(tool)),
748
+ }));
653
749
  for (const bytes of inputImageBase64Lengths(serialized.input))
654
750
  fixedImageBytes += bytes;
655
751
  input.push(...serialized.input);
@@ -672,6 +768,7 @@ async function serializeNativeAware(messages, route, routeConfig, ctx, options)
672
768
  return {
673
769
  input,
674
770
  ephemeralPreludeItemCount,
771
+ supersededInstructionItems,
675
772
  imageMap,
676
773
  imageSupport,
677
774
  tools: nativeTools,
@@ -691,11 +788,14 @@ function fallbackEligible(error, signal) {
691
788
  return ["LCX_HTTP_RETRYABLE", "LCX_RETRY_EXHAUSTED"].includes(String(details.code ?? ""));
692
789
  }
693
790
  async function* remoteCompactionStream(options, routeConfig, ctx, next) {
694
- const projected = projectToolUpdates(options.messages, options.tools, undefined, options.toolHistory);
695
- const history = stripCompactionDirective(projected.messages);
791
+ const history = stripCompactionDirective(options.messages);
696
792
  const route = currentRoute(options, routeConfig);
697
793
  try {
698
- const prepared = await serializeNativeAware(history, route, routeConfig, ctx, { signal: options.signal, tools: projected.tools && [...projected.tools] });
794
+ const prepared = await serializeNativeAware(history, route, routeConfig, ctx, {
795
+ signal: options.signal,
796
+ tools: options.tools && [...options.tools],
797
+ toolSurface: { history: options.toolHistory },
798
+ });
699
799
  const cacheSessionId = promptCacheSessionId(route, routeConfig, ctx);
700
800
  const headers = await authenticatedHeaders(ctx, routeConfig, cacheSessionId, cacheSessionId === undefined ? null : route.sessionId);
701
801
  const generation = generationControlsFromSession(sessionFor(ctx, route.sessionId), route);
@@ -704,7 +804,7 @@ async function* remoteCompactionStream(options, routeConfig, ctx, next) {
704
804
  model: route.model,
705
805
  modelDescriptor: prepared.model,
706
806
  input: prepared.input,
707
- tools: prepared.tools ?? (projected.tools && [...projected.tools]),
807
+ tools: prepared.tools,
708
808
  promptCacheKey: promptCacheKey(route, routeConfig, ctx),
709
809
  promptCacheRetention: promptCacheRetention(routeConfig),
710
810
  cacheRetention: routeConfig.cacheRetention,
@@ -728,6 +828,7 @@ async function* remoteCompactionStream(options, routeConfig, ctx, next) {
728
828
  result,
729
829
  input: prepared.input,
730
830
  ephemeralPreludeItemCount: prepared.ephemeralPreludeItemCount,
831
+ supersededItemIndices: prepared.supersededInstructionItems,
731
832
  imageMap: prepared.imageMap,
732
833
  retentionOptions: {
733
834
  tokenBudget: routeConfig.nativeRetentionTokenBudget,
@@ -968,7 +1069,7 @@ function inputHasNativeState(input) {
968
1069
  /**
969
1070
  * One redacted line per failed provider request. Only the LCX class and machine-safe provider
970
1071
  * identifiers are logged: never the provider message, a payload, a header or a credential.
971
- * `warn` matches the compaction failure line; DSH ships no persistent plugin-logger exporter by default
1072
+ * `warn` matches the compaction failure line; DSH 0.2.1-alpha.2 ships no persistent logger exporter
972
1073
  * (see ERRORS.md), so the line is visible wherever the host attaches one.
973
1074
  */
974
1075
  function logStreamFailure(ctx, route, info) {
@@ -992,15 +1093,18 @@ async function* managedResponsesStream(options, routeConfig, ctx) {
992
1093
  try {
993
1094
  if (options.stop !== undefined)
994
1095
  throw Object.assign(new Error("LCX Responses does not support GenerateOptions.stop"), { code: "LCX_RESPONSES_UNSUPPORTED_OPTION" });
995
- const projected = projectToolUpdates(options.messages, options.tools, undefined, options.toolHistory);
996
- const prepared = await serializeNativeAware(projected.messages, route, routeConfig, ctx, { signal: options.signal, tools: projected.tools && [...projected.tools] });
1096
+ const prepared = await serializeNativeAware(options.messages, route, routeConfig, ctx, {
1097
+ signal: options.signal,
1098
+ tools: options.tools && [...options.tools],
1099
+ toolSurface: { history: options.toolHistory },
1100
+ });
997
1101
  assertSupportedReasoningEffort(options.reasoningEffort, prepared.modelFacts);
998
1102
  const cacheSessionId = promptCacheSessionId(route, routeConfig, ctx);
999
1103
  const headers = await authenticatedHeaders(ctx, routeConfig, cacheSessionId, cacheSessionId === undefined ? null : route.sessionId);
1000
1104
  const body = buildResponsesBody({
1001
1105
  model: prepared.model,
1002
1106
  input: prepared.input,
1003
- tools: prepared.tools ?? (projected.tools && [...projected.tools]),
1107
+ tools: prepared.tools,
1004
1108
  sessionId: cacheSessionId,
1005
1109
  promptCacheKey: promptCacheKey(route, routeConfig, ctx),
1006
1110
  promptCacheRetention: promptCacheRetention(routeConfig),
@@ -1165,7 +1269,11 @@ function installInjected(ctx, configInput) {
1165
1269
  state.alphaSearch = configInput.alphaSearch.get();
1166
1270
  state.grokNativeWebSearch = configInput.grokNativeWebSearch.get();
1167
1271
  state.grokNativeXSearch = configInput.grokNativeXSearch.get();
1168
- runtimeConfig = baseConfig;
1272
+ // Absent (older config shapes) means the default: addition-only. Only an explicit false selects the full list.
1273
+ runtimeConfig =
1274
+ configInput.incrementalToolUpdates?.get() === false
1275
+ ? { ...baseConfig, toolUpdates: "full" }
1276
+ : baseConfig;
1169
1277
  refreshTools();
1170
1278
  };
1171
1279
  syncSettings();
@@ -321,11 +321,32 @@ export async function activeCompactionId(ctx, session) {
321
321
  lease[Symbol.dispose]();
322
322
  }
323
323
  }
324
+ /**
325
+ * On "in-history" routes DSH records every system prompt change as a full later `system` message
326
+ * (source `system-prompt`). A checkpoint begins a new DSH series whose head is re-rendered with the
327
+ * CURRENT prompt, so those snapshots in the retained window are superseded by that head. Retaining
328
+ * one, as developer/system or even as user text, would keep a stale full prompt (for example plan-mode
329
+ * policy that has since been switched off) in front of the model after the compaction.
330
+ *
331
+ * Only items the serializer traced back to such snapshots (`supersededItemIndices`, absolute positions
332
+ * in `input`) are removed. Any other retained developer/system item is genuine client context and
333
+ * stays. The ephemeral prelude is removed by the caller's slice, and the retention budget is computed
334
+ * over what is actually kept.
335
+ */
336
+ function dropSupersededItems(input, preludeCount, superseded) {
337
+ const drop = new Set();
338
+ for (const position of superseded) {
339
+ if (!Number.isSafeInteger(position) || position < preludeCount || position >= input.length)
340
+ throw Object.assign(new Error("Native compaction superseded-item provenance is invalid"), { code: "LCX_COMPACTION_PRELUDE_PROVENANCE_INVALID" });
341
+ drop.add(position);
342
+ }
343
+ return input.slice(preludeCount).filter((_, offset) => !drop.has(preludeCount + offset));
344
+ }
324
345
  /**
325
346
  * @param {CreateCheckpointOptions} options
326
347
  * @returns {Promise<NativeCheckpointV5>}
327
348
  */
328
- export async function createNativeCheckpointBlock({ ctx, session, route, result, input = [], ephemeralPreludeItemCount = 0, imageMap, retentionOptions = {}, }) {
349
+ export async function createNativeCheckpointBlock({ ctx, session, route, result, input = [], ephemeralPreludeItemCount = 0, supersededItemIndices = [], imageMap, retentionOptions = {}, }) {
329
350
  const compactionId = await activeCompactionId(ctx, session);
330
351
  if (!compactionId) {
331
352
  const error = new Error("Native compaction could not correlate the active DSH compaction transaction");
@@ -337,7 +358,7 @@ export async function createNativeCheckpointBlock({ ctx, session, route, result,
337
358
  ephemeralPreludeItemCount > input.length) {
338
359
  throw Object.assign(new Error("Native compaction prelude provenance is invalid"), { code: "LCX_COMPACTION_PRELUDE_PROVENANCE_INVALID" });
339
360
  }
340
- const retention = retainedConversationPlan(input.slice(ephemeralPreludeItemCount), retentionOptions);
361
+ const retention = retainedConversationPlan(dropSupersededItems(input, ephemeralPreludeItemCount, supersededItemIndices), retentionOptions);
341
362
  /** @type {NativeOutputItem[]} */
342
363
  const nativeOutput = persistNativeImageReferences([...retention.items, structuredClone(result.compaction)], imageMap ?? new Map());
343
364
  return {
@@ -694,6 +715,22 @@ function groupMessages(messages) {
694
715
  }
695
716
  return groups;
696
717
  }
718
+ /**
719
+ * A shadowed `system/message` (source `system-prompt`) is a full system prompt snapshot DSH appended
720
+ * when the prompt changed on an "in-history" route. Portable replay is only used when the checkpoint
721
+ * cannot be replayed natively (fork, route or model migration), and the request that follows always
722
+ * carries a head rendered with the current prompt, so every snapshot in the shadowed range is
723
+ * superseded: replaying it, even as user text, would put stale instructions (for example plan-mode
724
+ * policy that was switched off) back in front of the model.
725
+ *
726
+ * Only messages DSH itself marks as system-prompt snapshots are dropped. The head is never inside a
727
+ * compaction range, and a Session V3 log (where later system messages were ordinary context) cannot
728
+ * reach this path: LCX refuses V3 checkpoints before transport. Other system-role messages without that
729
+ * source keep the previous ordinary-context mapping.
730
+ */
731
+ export function withoutSupersededPromptSnapshots(messages) {
732
+ return messages.filter((message) => !(message.role === "system" && message.source?.kind === "system-prompt"));
733
+ }
697
734
  /**
698
735
  * @param {Session} session
699
736
  * @param {string} compactionId
@@ -708,7 +745,8 @@ export async function portableMessagesForCheckpoint(ctx, session, compactionId,
708
745
  ? configuredMaxChars
709
746
  : 80_000;
710
747
  const maxTokens = portableTokenCeiling(maxChars) ?? 1;
711
- const expanded = await shadowedMessagesForCheckpoint(ctx, session, compactionId);
748
+ // Superseded prompt snapshots are removed before grouping so they never consume the replay budget.
749
+ const expanded = withoutSupersededPromptSnapshots(await shadowedMessagesForCheckpoint(ctx, session, compactionId));
712
750
  if (expanded.length === 0)
713
751
  return [];
714
752
  const groups = groupMessages(expanded);
@@ -210,7 +210,8 @@ export function managedFailure(error, signal, upstream) {
210
210
  else if (sourceCodes.has("LCX_GROK_NATIVE_PROTOCOL_ERROR"))
211
211
  code = "GROK_NATIVE_PROTOCOL_ERROR";
212
212
  else if (sourceCodes.has("LCX_RESPONSES_ROUTE_UNAVAILABLE") ||
213
- sourceCodes.has("LCX_RESPONSES_MODEL_UNAVAILABLE"))
213
+ sourceCodes.has("LCX_RESPONSES_MODEL_UNAVAILABLE") ||
214
+ sourceCodes.has("LCX_SYSTEM_PROMPT_MODE_UNKNOWN"))
214
215
  code = "NO_ADAPTER";
215
216
  else if (sourceCodes.has("LCX_INSUFFICIENT_QUOTA"))
216
217
  code = "INSUFFICIENT_QUOTA";
@@ -253,7 +254,9 @@ export function managedFailure(error, signal, upstream) {
253
254
  AUTH: "Responses request was rejected by authentication",
254
255
  INSUFFICIENT_QUOTA: "服务商额度不足或未满足请求预留额度,请检查中转额度(并非 API 密钥无效) / Provider quota is insufficient for this request",
255
256
  UNSUPPORTED_OPTION: "LCX Responses does not support this request option",
256
- NO_ADAPTER: "LCX could not resolve the selected Responses route",
257
+ NO_ADAPTER: sourceCodes.has("LCX_SYSTEM_PROMPT_MODE_UNKNOWN")
258
+ ? "LCX could not read the route's model information, so in-history system prompt updates cannot be sent safely; retry once the route is available"
259
+ : "LCX could not resolve the selected Responses route",
257
260
  RATE_LIMIT: "Responses provider rate limit was reached",
258
261
  SERVER: "Responses provider returned a server failure",
259
262
  INVALID_REQUEST: sourceCodes.has("LCX_CHECKPOINT_UNSUPPORTED")
@@ -8,14 +8,27 @@ export function sanitizeContextDetails(value) {
8
8
  }
9
9
  export const zeroBuckets = () => ({ uncachedInputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheWriteTokens: 0 });
10
10
  export const isSearchTool = (name) => name === 'web_search' || name === 'websearch_gpt_advanced';
11
+ /** DSH 0.2.1 settles a tool called from inside programmatic tool calling (`run_code`) with this event, not `tool/result`. */
12
+ export const NESTED_SETTLE_EVENT = 'tool/ptc-dispatch';
13
+ /**
14
+ * A search call's settlement and its tool-owned presentation `meta`, from either event that carries one: a
15
+ * model-direct call settles as `tool/result` (its name comes from the earlier `tool/call`); a nested call settles
16
+ * as `tool/ptc-dispatch`, whose `name`, `subCallId` and `meta` are its own fields.
17
+ */
18
+ export function searchSettlementOf(event, pendingName) {
19
+ if (!object(event) || !object(event.data) || !object(event.data.meta))
20
+ return;
21
+ // Official ToolMessageSource carries only callId; a direct result resolves its name from tool/call.
22
+ // A nested settlement states the tool it dispatched, so it needs no pending entry.
23
+ const name = event.type === NESTED_SETTLE_EVENT ? event.data.name : event.type === 'tool/result' ? pendingName : undefined;
24
+ // Only our owned search results may contribute auxiliary billing or media.
25
+ return isSearchTool(name) ? { name, meta: event.data.meta } : undefined;
26
+ }
11
27
  export function auxiliaryUsageOf(event, toolName) {
12
- if (!object(event) || event.type !== 'tool/result' || !object(event.data?.meta))
13
- return [];
14
- // Only our owned search results may contribute auxiliary billing.
15
- // Official ToolMessageSource carries only callId; resolve its name from tool/call.
16
- if (!isSearchTool(toolName))
28
+ const settled = searchSettlementOf(event, toolName);
29
+ if (!settled)
17
30
  return [];
18
- const raw = event.data.meta.auxiliaryUsage;
31
+ const raw = settled.meta.auxiliaryUsage;
19
32
  if (!Array.isArray(raw))
20
33
  return [];
21
34
  const ids = new Set(), result = [];
@@ -0,0 +1,107 @@
1
+ import { projectToolUpdates } from "@deepseek-ai/dsh-llm";
2
+ export const DEFAULT_TOOL_UPDATES = "addition-only";
3
+ /** Reason used when the route compat explicitly declines both declaration kinds; a deliberate configuration. */
4
+ export const COMPAT_OPT_OUT = "route compat opts out of additional_tools and tool_search";
5
+ /**
6
+ * Which declaration item carries a mid-session addition. DSH declares `toolUpdate: "addition-only"` only for
7
+ * models whose host catalog supports `additional_tools` or `tool_search`, so a route compat that says nothing
8
+ * (LCX's frozen Pi 0.86 catalog does not know newer models such as gpt-6-sol) is not evidence against it. Only
9
+ * an explicit `false` on a declaration kind that is not backed by an explicit `true` opts the route out.
10
+ */
11
+ export function declarationKind(compat) {
12
+ const additional = compat?.supportsAdditionalTools;
13
+ const search = compat?.supportsToolSearch;
14
+ if (additional === true)
15
+ return "additional_tools";
16
+ if (search === true)
17
+ return "tool_search";
18
+ if (additional === false || search === false)
19
+ return undefined;
20
+ return "additional_tools";
21
+ }
22
+ /** Remove the activation marker; the wire never carries it. */
23
+ export function withoutDeferLoading(tool) {
24
+ if (!("deferLoading" in tool))
25
+ return tool;
26
+ const { deferLoading: _deferred, ...rest } = tool;
27
+ return rest;
28
+ }
29
+ function full(messages, tools, toolHistory, fallbackReason, fallbackUnexpected) {
30
+ // Same projection DSH applies for a route without `toolUpdate`: developer updates are dropped and
31
+ // `deferLoading` is cleared, so every declared tool is immediately usable.
32
+ const projected = projectToolUpdates(messages, tools, undefined, toolHistory);
33
+ return {
34
+ messages: projected.messages,
35
+ tools: projected.tools,
36
+ anchored: false,
37
+ ...(fallbackReason === undefined ? {} : { fallbackReason, fallbackUnexpected: fallbackUnexpected === true }),
38
+ };
39
+ }
40
+ /**
41
+ * Decide the tool surface of one GPT Responses request.
42
+ *
43
+ * Addition-only is used only when every condition holds, otherwise the full current list is sent:
44
+ * the policy is on, DSH reports `toolUpdate: "addition-only"` with an in-history system prompt, the route
45
+ * compat does not explicitly opt out of `additional_tools`/`tool_search` (silence is accepted: the host
46
+ * declares addition-only only for models that support them), and DSH supplied its tool history. The host
47
+ * projection is then re-verified (LCX-owned self check); any inconsistency falls back to the full list.
48
+ * Removals and same-name redefinitions need no extra handling: the host history fold already yields a
49
+ * shrunken or fully redeclared baseline for them (one-time cache loss), which this function passes through.
50
+ */
51
+ export function planToolSurface(input) {
52
+ const { mode, messages, tools, toolHistory, facts, compat } = input;
53
+ const fallback = (reason) => full(messages, tools, toolHistory, mode === "addition-only" ? reason : undefined, facts.toolUpdate === "addition-only" && reason !== COMPAT_OPT_OUT);
54
+ if (mode !== "addition-only")
55
+ return full(messages, tools, toolHistory);
56
+ if (tools === undefined)
57
+ return fallback("no tools");
58
+ if (!facts.resolved)
59
+ return fallback("model information unavailable");
60
+ if (facts.toolUpdate !== "addition-only")
61
+ return fallback("route does not declare addition-only tool updates");
62
+ if (facts.systemPromptUpdate !== "in-history")
63
+ return fallback("route is not in-history");
64
+ const kind = declarationKind(compat);
65
+ if (kind === undefined)
66
+ return fallback(COMPAT_OPT_OUT);
67
+ if (toolHistory === undefined)
68
+ return fallback("no DSH tool history");
69
+ const projected = projectToolUpdates(messages, tools, "addition-only", toolHistory);
70
+ const projectedTools = projected.tools;
71
+ if (projectedTools === undefined)
72
+ return fallback("host projection returned no tools");
73
+ const added = new Set();
74
+ for (const message of projected.messages) {
75
+ if (message.role !== "developer")
76
+ continue;
77
+ for (const block of message.content) {
78
+ if (block.type !== "tool-addition")
79
+ return fallback(`unsupported developer block ${block.type}`);
80
+ if (added.has(block.toolName))
81
+ return fallback("duplicate tool addition");
82
+ added.add(block.toolName);
83
+ }
84
+ }
85
+ const deferred = new Set();
86
+ for (const tool of projectedTools) {
87
+ if (tool.deferLoading === true)
88
+ deferred.add(tool.name);
89
+ }
90
+ // Without any deferred tool or retained addition the request equals the full list; use the ordinary path
91
+ // so the common no-change turn stays byte-identical with the 0.5.1 behaviour.
92
+ if (deferred.size === 0 && added.size === 0)
93
+ return full(messages, tools, toolHistory);
94
+ if (deferred.size !== added.size || [...deferred].some((name) => !added.has(name)))
95
+ return fallback("deferred tools and retained additions disagree");
96
+ // The declared surface must equal the active surface; a mismatch means the history fold and the live
97
+ // header diverged (restore, fork or migration), where only the full list is known to be correct.
98
+ const active = new Set(tools.map((tool) => tool.name));
99
+ if (active.size !== projectedTools.length || projectedTools.some((tool) => !active.has(tool.name)))
100
+ return fallback("declared tools differ from the active tools");
101
+ return {
102
+ messages: projected.messages,
103
+ tools: projectedTools,
104
+ anchored: true,
105
+ compat: kind === "additional_tools" ? { supportsAdditionalTools: true } : { supportsAdditionalTools: false, supportsToolSearch: true },
106
+ };
107
+ }
@@ -34,6 +34,8 @@ type LiveSettingsConfig = {
34
34
  grokNativeWebSearch: Volatile<boolean>;
35
35
  grokNativeXSearch: Volatile<boolean>;
36
36
  searchMediaPreview: Volatile<boolean>;
37
+ /** Defaults to true: addition-only tool updates on routes that support them. */
38
+ incrementalToolUpdates: Volatile<boolean>;
37
39
  };
38
40
  type HostContext = Context;
39
41
  export declare const Config: z<Schemastery.ObjectS<NoInfer<{
@@ -44,6 +46,7 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
44
46
  grokNativeWebSearch: z<boolean, boolean, "volatile-defined">;
45
47
  grokNativeXSearch: z<boolean, boolean, "volatile-defined">;
46
48
  searchMediaPreview: z<boolean, boolean, "volatile-defined">;
49
+ incrementalToolUpdates: z<boolean, boolean, "volatile-defined">;
47
50
  supportsLongCacheRetention: z<boolean, boolean, "defined">;
48
51
  supportsExplicitPromptCacheMode: z<boolean, boolean, "defined">;
49
52
  alphaCapabilityPath: z<string, string, "defined">;
@@ -71,6 +74,7 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
71
74
  grokNativeWebSearch: z<boolean, boolean, "volatile-defined">;
72
75
  grokNativeXSearch: z<boolean, boolean, "volatile-defined">;
73
76
  searchMediaPreview: z<boolean, boolean, "volatile-defined">;
77
+ incrementalToolUpdates: z<boolean, boolean, "volatile-defined">;
74
78
  supportsLongCacheRetention: z<boolean, boolean, "defined">;
75
79
  supportsExplicitPromptCacheMode: z<boolean, boolean, "defined">;
76
80
  alphaCapabilityPath: z<string, string, "defined">;
package/locale/en.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "LCX Codex",
4
+ "description": "GPT Responses lifecycle, long-session compaction, web search and Grok native search for DeepSeek Harness."
5
+ }
6
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "LCX Codex",
4
+ "description": "为 DeepSeek Harness 补充 GPT Responses 生命周期、长会话压缩、网页搜索与 Grok 原生搜索。"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "dsh-lcx-codex",
3
- "version": "0.5.1",
3
+ "version": "0.6.0-pre.1",
4
4
  "description": "Model-scoped DSH plugin: GPT Responses lifecycle, Native V2 compaction and Hosted/Alpha Search; Grok native Web/X Search",
5
+ "icon": "./icon.svg",
5
6
  "keywords": [
6
7
  "deepseek-harness",
7
8
  "dsh",
@@ -37,9 +38,12 @@
37
38
  "default": "./lib/client.js"
38
39
  },
39
40
  "./cordis.patch.yml": "./cordis.patch.yml",
41
+ "./locale/*.json": "./locale/*.json",
40
42
  "./package.json": "./package.json"
41
43
  },
42
44
  "files": [
45
+ "icon.svg",
46
+ "locale/*.json",
43
47
  "lib/*.js",
44
48
  "lib/types/index.d.ts",
45
49
  "lib/types/client/index.d.ts",
@@ -62,9 +66,9 @@
62
66
  }
63
67
  },
64
68
  "devDependencies": {
65
- "@deepseek-ai/dsh": "0.2.0-rc.2",
69
+ "@deepseek-ai/dsh": "0.2.1-alpha.2",
66
70
  "@earendil-works/pi-ai": "0.87.1",
67
- "@deepseek-ai/schemastery": "^3.18.2",
71
+ "@deepseek-ai/schemastery": "~3.18.5-alpha.1",
68
72
  "@types/node": "^22.20.0",
69
73
  "@types/react": "~18.3.1",
70
74
  "esbuild": "^0.28.2",
@@ -72,31 +76,31 @@
72
76
  "typescript": "7.0.2"
73
77
  },
74
78
  "peerDependencies": {
75
- "@deepseek-ai/cordis": "^4.0.2",
76
- "@deepseek-ai/cordis-plugin-loader": "~1.0.5",
77
- "@deepseek-ai/dsh-agent": ">=0.2.0-rc.2 <0.2.1",
78
- "@deepseek-ai/dsh-attachment": ">=0.2.0-rc.2 <0.2.1",
79
- "@deepseek-ai/dsh-client-locale": ">=0.2.0-rc.2 <0.2.1",
80
- "@deepseek-ai/dsh-client-modules": ">=0.2.0-rc.2 <0.2.1",
81
- "@deepseek-ai/dsh-client-store": ">=0.2.0-rc.2 <0.2.1",
82
- "@deepseek-ai/dsh-client-ui-chat": ">=0.2.0-rc.2 <0.2.1",
83
- "@deepseek-ai/dsh-client-ui-conversation": ">=0.2.0-rc.2 <0.2.1",
84
- "@deepseek-ai/dsh-client-ui-plugin-manager": ">=0.2.0-rc.2 <0.2.1",
85
- "@deepseek-ai/dsh-client-ui-settings": ">=0.2.0-rc.2 <0.2.1",
86
- "@deepseek-ai/dsh-compaction": ">=0.2.0-rc.2 <0.2.1",
87
- "@deepseek-ai/dsh-credentials": ">=0.2.0-rc.2 <0.2.1",
88
- "@deepseek-ai/dsh-fs": ">=0.2.0-rc.2 <0.2.1",
89
- "@deepseek-ai/dsh-llm": ">=0.2.0-rc.2 <0.2.1",
90
- "@deepseek-ai/dsh-session": ">=0.2.0-rc.2 <0.2.1",
91
- "@deepseek-ai/dsh-session-query": ">=0.2.0-rc.2 <0.2.1",
92
- "@deepseek-ai/dsh-settings": ">=0.2.0-rc.2 <0.2.1",
93
- "@deepseek-ai/dsh-tool-web": ">=0.2.0-rc.2 <0.2.1",
94
- "@deepseek-ai/dsh-tools": ">=0.2.0-rc.2 <0.2.1",
95
- "@deepseek-ai/dsh-web": ">=0.2.0-rc.2 <0.2.1",
96
- "@deepseek-ai/schemastery": "^3.18.2",
79
+ "@deepseek-ai/cordis": ">=4.0.5-alpha.1",
80
+ "@deepseek-ai/cordis-plugin-loader": ">=1.0.6-alpha.1",
81
+ "@deepseek-ai/dsh-agent": ">=0.2.1-alpha.2",
82
+ "@deepseek-ai/dsh-attachment": ">=0.2.1-alpha.2",
83
+ "@deepseek-ai/dsh-client-locale": ">=0.2.1-alpha.2",
84
+ "@deepseek-ai/dsh-client-modules": ">=0.2.1-alpha.2",
85
+ "@deepseek-ai/dsh-client-store": ">=0.2.1-alpha.2",
86
+ "@deepseek-ai/dsh-client-ui-chat": ">=0.2.1-alpha.2",
87
+ "@deepseek-ai/dsh-client-ui-conversation": ">=0.2.1-alpha.2",
88
+ "@deepseek-ai/dsh-client-ui-plugin-manager": ">=0.2.1-alpha.2",
89
+ "@deepseek-ai/dsh-client-ui-settings": ">=0.2.1-alpha.2",
90
+ "@deepseek-ai/dsh-compaction": ">=0.2.1-alpha.2",
91
+ "@deepseek-ai/dsh-credentials": ">=0.2.1-alpha.2",
92
+ "@deepseek-ai/dsh-fs": ">=0.2.1-alpha.2",
93
+ "@deepseek-ai/dsh-llm": ">=0.2.1-alpha.2",
94
+ "@deepseek-ai/dsh-session": ">=0.2.1-alpha.2",
95
+ "@deepseek-ai/dsh-session-query": ">=0.2.1-alpha.2",
96
+ "@deepseek-ai/dsh-settings": ">=0.2.1-alpha.2",
97
+ "@deepseek-ai/dsh-tool-web": ">=0.2.1-alpha.2",
98
+ "@deepseek-ai/dsh-tools": ">=0.2.1-alpha.2",
99
+ "@deepseek-ai/dsh-web": ">=0.2.1-alpha.2",
100
+ "@deepseek-ai/schemastery": ">=3.18.5-alpha.1",
97
101
  "react": "^18.2.0",
98
- "@deepseek-ai/dsh-token-meter": ">=0.2.0-rc.2 <0.2.1",
99
- "@deepseek-ai/dsh-session-projection": ">=0.2.0-rc.2 <0.2.1",
102
+ "@deepseek-ai/dsh-token-meter": ">=0.2.1-alpha.2",
103
+ "@deepseek-ai/dsh-session-projection": ">=0.2.1-alpha.2",
100
104
  "zod": "^4.5.4"
101
105
  },
102
106
  "peerDependenciesMeta": {
@@ -168,6 +172,7 @@
168
172
  "test": "node --test tests/*.test.mjs",
169
173
  "typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.client.json --noEmit",
170
174
  "probe:alpha": "node scripts/probe-alpha.mjs",
175
+ "probe:tool-updates": "node scripts/probe-tool-updates.mjs",
171
176
  "pack:local": "npm pack --ignore-scripts",
172
177
  "test:schema": "node scripts/validate-dsh-schema.mjs"
173
178
  },
@@ -179,9 +184,9 @@
179
184
  },
180
185
  "license": "MIT",
181
186
  "lcxCompatibility": {
182
- "dshInstallRange": ">=0.2.0-rc.2 <0.2.1",
183
- "verifiedDsh": "0.2.0-rc.2",
184
- "verifiedHostPi": "0.87.1",
187
+ "dshInstallRange": ">=0.2.1-alpha.2",
188
+ "verifiedDsh": "0.2.1-alpha.2",
189
+ "verifiedHostPi": "1.1.0",
185
190
  "verifiedPluginPi": "0.87.1"
186
191
  }
187
192
  }