dsh-lcx-codex 0.5.2 → 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.6.x` 预发布线) | `@prelatest` |
41
- | `0.2.0` 系列(`0.2.0-rc.2`,早于 `0.2.1-alpha.2`) | `0.5.2`(稳定版) | `@latest` |
40
+ | `0.2.1-alpha.2` 及以后 | `0.6.0-pre.1`(预发布版) | `@prelatest` |
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.2`(发布基线 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
- `@prelatest` 指向 `0.6.x` 预发布线的最新预发布版,面向 DSH `0.2.1-alpha.2` 及以后。它的安装范围**只有下限**(`>=0.2.1-alpha.2`),没有上限:更新的 DSH 版本也能装上,但**没有经过验证**。每个预发布版只验证其发布说明里写明的 DSH 基线(目前为 DSH `0.2.1-alpha.2`),请不要据此认为其他 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.2` 的安装范围写作 `>=0.2.0-rc.2 <0.2.1`,按 DSH 的版本范围规则,`0.2.1` 的预发布版(如 `0.2.1-alpha.2`)也可能被放行安装,但这些版本**不在** `0.5.2` 的支持和验证范围内;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.6.x` 预发布线),稳定版 `0.5.2` 没有在这些 DSH 版本上验证。
128
- - **DSH 升级到 `0.2.0` 系列**:把插件换成 `@latest`(`0.5.2`),旧版 `0.4.x` 不支持 DSH `0.2`。
134
+ - **DSH 升级到 `0.2.1-alpha.2` 或更新版本**:把插件换成 `@prelatest`(`0.6.0-pre.1`),稳定版 `0.5.x` 没有在这些 DSH 版本上验证。
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
- - **DSH `0.1.5` 系列**:继续使用 `@0.4.3`;`@latest` 现在指向支持 DSH `0.2` 的 `0.5.2`。
131
- - **已装了 `0.5.0`、`0.5.1` 或 `0.5.0-pre.1`**:DSH `0.2.0` 系列重新运行 `@latest` 的 `add` 命令即可升到 `0.5.2`(修复了缺陷,安装范围不变,详见 CHANGELOG;`0.5.2` 修复了 profile 里没写 `api` 时 `gpt-6-sol` 等模型报 `NO_ADAPTER` 的问题);DSH `0.2.1-alpha.2` 及以后用 `@prelatest`。
137
+ - **DSH `0.1.5` 系列**:继续使用 `@0.4.3`;`@latest` 现在指向支持 DSH `0.2` 的 `0.5.1`。
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
- - **验证范围**:`@prelatest`(`0.6.x` 预发布线)只验证其发布说明里写明的 DSH 基线(目前为 DSH `0.2.1-alpha.2`),安装范围没有上限,更新的 DSH 版本未经验证;具体验证覆盖范围见对应预发布版的 CHANGELOG 和发布说明。`0.5.2` 的发布基线为 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.2`。
176
+ 包管理器的缓存可能还没刷新,DSH 会因版本不兼容拒绝安装。稍等几分钟重试,或直接指定版本号,例如 `dsh-lcx-codex@0.6.0-pre.1` 或 `dsh-lcx-codex@0.5.1`。
170
177
 
171
178
  ## 反馈问题
172
179
 
@@ -2,9 +2,9 @@
2
2
 
3
3
  `lib/pi-responses-runtime.js` is generated from public exports of the packages below. The build recipe in `scripts/build-pi-runtime.mjs` verifies that no other third-party package contributes output bytes.
4
4
 
5
- ## @earendil-works/pi-ai 0.87.1
5
+ ## @earendil-works/pi-ai 0.85.1
6
6
 
7
- Upstream source: https://github.com/earendil-works/pi/tree/v0.87.1/packages/ai
7
+ Upstream source: https://github.com/earendil-works/pi/tree/v0.85.1/packages/ai
8
8
 
9
9
  Included public Responses helpers and model catalogs:
10
10
 
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" },
@@ -1,7 +1,8 @@
1
1
  import { IMAGE_OFFLOAD_REQUIRED_CODE, LlmError, offloadedImageText, projectOffloadedImages, requiredImageOffload, requestImageHandleText, resolveImageAttachmentAccess, } from "@deepseek-ai/dsh-llm";
2
2
  import { requestImageDimensions } from "@deepseek-ai/dsh-attachment";
3
- import { convertResponsesMessages, convertResponsesTools, createGrammarToolInputProperties, normalizeContext, } from "./pi-responses-runtime.js";
4
- import { resolveCatalogModel } from "./model-catalog.js";
3
+ import { convertResponsesMessages, convertResponsesTools, createGrammarToolInputProperties, getBuiltinModels, normalizeContext, } from "./pi-responses-runtime.js";
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, contextWindow: 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,15 +91,18 @@ 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)) },
92
- contextWindow: positiveSafeInteger(info.context?.contextWindow, 0) || undefined,
93
99
  resolved: true,
94
100
  };
95
101
  }
96
102
  catch {
97
- return { imageSupport: "unknown", reasoning: undefined, contextWindow: 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 };
98
106
  }
99
107
  }
100
108
  export async function resolveModelImageSupport(ctx, route, signal) {
@@ -367,6 +375,15 @@ async function prepareRequestImageVersions(messages, ctx, options) {
367
375
  }));
368
376
  return new Map(versions);
369
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
+ }
370
387
  function flattenMessageText(message) {
371
388
  return message.content.map((block) => {
372
389
  if (block.type !== "text")
@@ -379,11 +396,41 @@ async function dshToPiMessages(messages, ctx, options, imageMap, requestImages)
379
396
  const toolNames = new Map();
380
397
  for (const message of messages) {
381
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
+ }
382
413
  result.push({ role: "user", content: flattenMessageText(message), timestamp: 0 });
383
414
  continue;
384
415
  }
385
- if (message.role === "developer")
386
- 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
+ }
387
434
  if (message.role === "assistant") {
388
435
  const assistant = toPiAssistant(message, options.onReplayDegrade);
389
436
  for (const block of assistant.content)
@@ -421,8 +468,15 @@ async function dshToPiMessages(messages, ctx, options, imageMap, requestImages)
421
468
  return result;
422
469
  }
423
470
  function builtinResponsesModel(provider, modelId) {
424
- // The exact bundled catalog entry (see `resolveCatalogModel`): the same descriptor the route resolution reads.
425
- return resolveCatalogModel(provider, modelId).descriptor;
471
+ // Keep descriptor and wire capabilities within the same frozen catalog scope as route ownership.
472
+ if (!wasPi086ResponsesModel(provider, modelId))
473
+ return undefined;
474
+ try {
475
+ return getBuiltinModels(provider).find((model) => model.id === modelId && model.api === "openai-responses");
476
+ }
477
+ catch {
478
+ return undefined;
479
+ }
426
480
  }
427
481
  export function resolvePiResponsesModel(options) {
428
482
  const route = isObject(options.route) ? options.route : {};
@@ -437,26 +491,40 @@ export function resolvePiResponsesModel(options) {
437
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 } : {}) };
438
492
  }
439
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");
440
497
  for (const message of messages) {
441
- if (message.role === "developer")
498
+ if (message.role === "developer" && !anchored)
442
499
  throw unsupportedContent("developer message");
443
500
  for (const block of message.content)
444
- if (block.type === "tool-addition" || block.type === "tool-removal")
445
- 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
+ }
446
506
  }
447
507
  for (const tool of options.tools ?? [])
448
- if ("deferLoading" in tool && tool.deferLoading === true)
508
+ if (!anchored && "deferLoading" in tool && tool.deferLoading === true)
449
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));
450
515
  const normalized = {
451
516
  imageSupport: options.imageSupport === "supported" || options.imageSupport === "unsupported" ? options.imageSupport : "unknown",
452
517
  signal: options.signal instanceof AbortSignal ? options.signal : undefined,
453
518
  route: options.route ?? {}, model: options.model, responsesCompat: options.responsesCompat,
454
519
  systemPrompt: typeof options.systemPrompt === "string" ? options.systemPrompt : undefined,
455
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,
456
523
  maxRequestImageBytes: positiveSafeInteger(options.maxRequestImageBytes, DEFAULT_MAX_REQUEST_IMAGE_BYTES),
457
524
  requestImagePixelBudget: positiveSafeInteger(options.requestImagePixelBudget, DEFAULT_REQUEST_IMAGE_PIXEL_BUDGET),
458
525
  requestImageMaxBytes: positiveSafeInteger(options.requestImageMaxBytes, DEFAULT_REQUEST_IMAGE_MAX_BYTES),
459
- tools: Array.isArray(options.tools) ? options.tools : [],
526
+ tools: immediateDeclared,
527
+ ...(anchored ? { anchoredTools: declaredTools } : {}),
460
528
  };
461
529
  const imageMap = new Map();
462
530
  const fileProjected = projectFiles(messages, ctx);
@@ -484,19 +552,57 @@ export async function serializeDshMessages(messages, ctx, options = {}) {
484
552
  const supportsAdditionalTools = compat.supportsAdditionalTools === true;
485
553
  const supportsToolSearch = compat.supportsToolSearch === true;
486
554
  const deferredToolsMode = supportsAdditionalTools ? "additional-tools" : supportsToolSearch ? "tool-search" : undefined;
487
- const grammarToolInputProperties = createGrammarToolInputProperties(dshContext.tools, supportsOpenAIGrammarTools);
488
- // 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.
489
557
  const immediateTools = new Map();
490
558
  for (const tool of dshContext.tools)
491
559
  if (tool.name)
492
560
  immediateTools.set(tool.name, tool);
493
561
  const toolOptions = { supportsStrictMode, supportsOpenAIGrammarTools, toolSearchResult: false };
494
- 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;
495
570
  const piModel = model;
496
- const convertedInput = convertResponsesMessages(piModel, piContext, new Set(["openai", "openai-codex", "opencode"]), { includeSystemPrompt: normalized.includeSystemPrompt, grammarToolInputProperties, supportsAdditionalTools, supportsToolSearch, toolOptions });
497
- 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 });
498
599
  const tools = options.tools === undefined ? undefined : convertResponsesTools([...immediateTools.values()], toolOptions);
499
- 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;
500
606
  }
501
607
  export function responsesTools(tools) {
502
608
  if (tools === undefined)