dsh-lcx-codex 0.6.0-pre.2 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  <div align="center">
2
2
 
3
- <img src="https://raw.githubusercontent.com/kk3ya03-star/dsh-lcx-codex/main/assets/dsh-lcx-codex-banner.svg" alt="LCX Codex" width="100%" />
3
+ <img src="https://raw.githubusercontent.com/kk3ya03-star/dsh-lcx-codex/stable/0.6.x/assets/dsh-lcx-codex-banner.svg" alt="LCX Codex" width="100%" />
4
4
 
5
5
  # LCX Codex
6
6
 
@@ -8,9 +8,9 @@
8
8
 
9
9
  [![npm latest](https://img.shields.io/npm/v/dsh-lcx-codex/latest?label=latest)](https://www.npmjs.com/package/dsh-lcx-codex)
10
10
  [![npm prelatest](https://img.shields.io/npm/v/dsh-lcx-codex/prelatest?label=prelatest&color=orange)](https://www.npmjs.com/package/dsh-lcx-codex?activeTab=versions)
11
- [![License](https://img.shields.io/badge/license-MIT-555)](LICENSE)
11
+ [![License](https://img.shields.io/badge/license-MIT-555)](https://github.com/kk3ya03-star/dsh-lcx-codex/blob/stable/0.6.x/LICENSE)
12
12
 
13
- **简体中文** · [English](README_EN.md) · [更新日志](CHANGELOG.md) · [问题反馈](https://github.com/kk3ya03-star/dsh-lcx-codex/issues)
13
+ **简体中文** · [English](https://github.com/kk3ya03-star/dsh-lcx-codex/blob/stable/0.6.x/README_EN.md) · [更新日志](https://github.com/kk3ya03-star/dsh-lcx-codex/blob/stable/0.6.x/CHANGELOG.md) · [问题反馈](https://github.com/kk3ya03-star/dsh-lcx-codex/issues)
14
14
 
15
15
  </div>
16
16
 
@@ -37,39 +37,56 @@ 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.0-pre.2`(预发布版) | `@prelatest` |
41
- | `0.2.0` 系列(`0.2.0-rc.2`,早于 `0.2.1-alpha.2`) | `0.5.2`(稳定版) | `@latest` |
40
+ | `0.2.2-alpha.3` 及以后(DSH `0.2.2` 预发布系列) | `0.7.0-pre.1`(预发布版) | `@prelatest` |
41
+ | `0.2.1` 系列(`0.2.1-rc.5` 及以后的 `0.2.1` 版本,DSH `latest` 通道) | `0.6.0`(稳定版) | `@latest` |
42
+ | `0.2.0` 系列(`0.2.0-rc.2`,早于 `0.2.1-alpha.2`) | `0.5.2`(旧稳定版) | `@0.5.2` |
42
43
  | `0.1.6` 系列(`0.1.6-alpha.2` 及以后) | `0.4.4-pre.1`(旧预发布版) | `@0.4.4-pre.1` |
43
44
  | `0.1.5` 系列(`0.1.5-rc.1` 及以后) | `0.4.3`(稳定版) | `@0.4.3` |
44
45
 
45
- 请务必按表格选择:几个版本互不兼容,装错版本时安装命令可能只给出依赖警告,但插件可能无法正常工作。`@latest` 是稳定版 `0.5.2`(发布基线 DSH `0.2.0-rc.2`,host / plugin Pi `0.87.1`),DSH `0.1.5` 用户请固定安装 `@0.4.3`。
46
+ 请务必按表格选择:几个版本互不兼容,装错版本时安装命令可能只给出依赖警告,但插件可能无法正常工作。`@latest` 是稳定版 `0.6.0`(发布基线 DSH `0.2.1-rc.5`,host / plugin Pi `1.5.0`);DSH `0.2.0` 用户请固定安装 `@0.5.2`,DSH `0.1.5` 用户请固定安装 `@0.4.3`。历史说明:`0.6.0-pre.2` 是面向 DSH `0.2.1-alpha.2` 的历史预发布版,只在 DSH `0.2.1-alpha.2` 上验证过;`0.2.1-rc.5` 之前的其他早期 `0.2.1` 构建都没有经过验证。使用早期 `0.2.1` 构建时,请把 DSH 升级到 `0.2.1-rc.5`,再安装 `0.6.0`(`@latest`)。DSH `0.2.2-alpha.1` / `0.2.2-alpha.2` 没有经过验证的 LCX 版本,请升级到 `0.2.2-alpha.3` 或更新版本。
46
47
 
47
- `0.6.0-pre.2` 是预发布版,面向 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 `1.1.0`),请不要据此认为其他 DSH 版本受支持。
48
+ 稳定版 `0.6.0` 的安装范围是 `>=0.2.1-rc.5 <0.2.2-0`:之后的 DSH `0.2.1` 版本也能装上,但**没有经过验证**;上限写成 `<0.2.2-0` 是为了不放行 DSH `0.2.2` 的预发布版。本版本的验证基线只有 DSH `0.2.1-rc.5`(host Pi `1.5.0`,plugin Pi `1.5.0`)。
48
49
 
49
- 本版本开始适配 DSH `0.2.1` 的插件相关新能力:
50
+ `0.7.0-pre.1` 是预发布版,面向 DSH `0.2.2` 预发布系列(从 `0.2.2-alpha.3` 起)。它的安装范围**只有下限**(`>=0.2.2-alpha.3`),没有上限:更新的 DSH 版本也能装上,但**没有经过验证**。本次预发布的验证基线只有 DSH `0.2.2-alpha.3`(host Pi `1.5.0`,plugin Pi `1.5.0`),请不要据此认为其他 DSH 版本受支持。
51
+
52
+ `0.6.0` 和 `0.7.0-pre.1` 的主要变化(详见[更新日志](https://github.com/kk3ya03-star/dsh-lcx-codex/blob/stable/0.6.x/CHANGELOG.md)):
53
+
54
+ - **内置 Pi 跟随 DSH 升级到 `1.5.0`**:GPT-5.6 / GPT-6 系列模型的工具声明与 DSH 自己的发送方式一致(全部以 `additional_tools` 形式声明,不再发送顶层 `tools`),会话中途新增或删除工具、重启、分叉和压缩之后也保持一致。
55
+ - **切换推理强度不再让缓存失效**:在 `openai` 的 GPT-6 系列模型上,会话中途切换推理强度会保留已缓存的前缀,与 DSH 自己的处理一致。
56
+ - **自动审查修复**:GPT 路由上 DSH 自动审查(auto-review)的请求现在会带上它自己的系统提示词,不再以 `AUTO_REVIEW_FAILED` 失败。
57
+ - **仅 `0.7.0-pre.1`**:适配 DSH `0.2.2` 的插件接口;LCX 发出的 GPT 请求也会应用其他插件通过 `llm-pi-ai/request-headers` 提供的请求头,但这些插件不能替换凭据、会话亲和和请求关联相关的请求头。
58
+
59
+ 从 `0.6.0-pre` 系列开始适配的 DSH `0.2.1` 插件新能力(`0.6.0` 和 `0.7.0-pre.1` 都包含):
50
60
 
51
61
  - **增量工具更新(只增不改)**:在 DSH 声明支持该模式的 GPT Responses 路由上,会话中途新增工具(例如打开联网搜索、启用 MCP 或技能)时,请求里的工具列表保持不变,新增的工具以历史项的形式声明,因此不再改变已缓存的前缀。设置卡片里有“增量工具更新”开关,默认开启,关闭后每次请求都发送完整的当前工具列表。删除工具或同名重定义仍会让缓存失效一次。Grok、自定义命名路由、分叉与路由迁移的回放、压缩检查点仍然发送完整工具列表。
52
62
  - **程序化工具调用里的搜索**:在 `run_code` 程序里调用 `web_search` / `websearch_gpt_advanced` 时,搜索用量和返回的图片也会计入并显示。
53
63
  - **插件管理页卡片**:LCX 在插件管理页显示自己的名称(LCX Codex)、简介和图标。
54
64
 
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`。
65
+ > 注意:旧稳定版 `0.5.x` 的安装范围写作 `>=0.2.0-rc.2 <0.2.1`,按 DSH 的版本范围规则,`0.2.1` 的预发布版(如 `0.2.1-rc.5`)也可能被放行安装,但这些版本**不在** `0.5.x` 的支持和验证范围内;DSH `0.2.1-rc.5` 及以后的 `0.2.1` 版本请使用 `@latest`(`0.6.0`),DSH `0.2.2-alpha.3` 及以后请使用 `@prelatest`。
56
66
 
57
67
  ### 2. 安装并启动
58
68
 
59
- DSH `0.2.1-alpha.2` 及以后(预发布版):
69
+ DSH `0.2.2-alpha.3` 及以后(预发布版):
60
70
 
61
71
  ```sh
62
72
  dsh plugin --profile web add dsh-lcx-codex@prelatest
63
73
  dsh web
64
74
  ```
65
75
 
66
- DSH `0.2.0` 系列(稳定版):
76
+ DSH `0.2.1` 系列(`0.2.1-rc.5` 及以后,稳定版;更早的 `0.2.1` 构建请先把 DSH 升级到 `0.2.1-rc.5`):
67
77
 
68
78
  ```sh
69
79
  dsh plugin --profile web add dsh-lcx-codex@latest
70
80
  dsh web
71
81
  ```
72
82
 
83
+ DSH `0.2.0` 系列(注意固定版本号,不要用 `@latest`):
84
+
85
+ ```sh
86
+ dsh plugin --profile web add dsh-lcx-codex@0.5.2
87
+ dsh web
88
+ ```
89
+
73
90
  DSH `0.1.6` 系列:
74
91
 
75
92
  ```sh
@@ -90,7 +107,7 @@ dsh web
90
107
 
91
108
  打开 DSH Web 的插件页面,在 LCX 的配置卡片 **Responses / Codex 能力** 中按需打开下列开关,然后点击 **保存**。
92
109
 
93
- <img src="https://raw.githubusercontent.com/kk3ya03-star/dsh-lcx-codex/main/assets/settings-card.png" alt="LCX 插件配置卡片" width="720" />
110
+ <img src="https://raw.githubusercontent.com/kk3ya03-star/dsh-lcx-codex/stable/0.6.x/assets/settings-card.png" alt="LCX 插件配置卡片" width="720" />
94
111
 
95
112
  **GPT**
96
113
 
@@ -131,11 +148,12 @@ dsh web
131
148
 
132
149
  ## 从旧版本升级
133
150
 
134
- - **DSH 升级到 `0.2.1-alpha.2` 或更新版本**:把插件换成 `@prelatest`(`0.6.0-pre.2`),稳定版 `0.5.x` 没有在这些 DSH 版本上验证。
135
- - **DSH 升级到 `0.2.0` 系列**:把插件换成 `@latest`(`0.5.2`),旧版 `0.4.x` 不支持 DSH `0.2`。
151
+ - **DSH 升级到 `0.2.2-alpha.3` 或更新版本(DSH `0.2.2` 预发布系列)**:把插件换成 `@prelatest`(`0.7.0-pre.1`),`0.6.x` 没有在这些 DSH 版本上验证。
152
+ - **DSH 升级到 `0.2.1-rc.5`(DSH `latest` 通道)**:把插件换成 `@latest`(`0.6.0`);已装 `0.6.0-pre.2` 的用户也用这条命令换到稳定版。
153
+ - **DSH `0.2.0` 系列**:继续使用 `@0.5.2`;`@latest` 现在指向支持 DSH `0.2.1` 的 `0.6.0`,旧版 `0.4.x` 不支持 DSH `0.2`。
136
154
  - **DSH `0.1.6` 系列**:继续使用 `@0.4.4-pre.1`。
137
- - **DSH `0.1.5` 系列**:继续使用 `@0.4.3`;`@latest` 现在指向支持 DSH `0.2` 的 `0.5.2`。
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`。
155
+ - **DSH `0.1.5` 系列**:继续使用 `@0.4.3`;`@latest` 现在指向支持 DSH `0.2.1` 的 `0.6.0`。
156
+ - **已装了 `0.5.0`、`0.5.1` 或 `0.5.0-pre.1`**:DSH `0.2.0` 系列运行 `@0.5.2` 的 `add` 命令即可升到 `0.5.2`(只包含缺陷修复,安装范围不变)。
139
157
  - **升级后建议新建会话**:旧版本保存的压缩状态不保证兼容。DSH `0.2` 迁移过的旧长会话如果带有旧版 LCX 压缩检查点,LCX 会提示 `LCX_CHECKPOINT_UNSUPPORTED`,新建会话即可;其他模型不受影响。
140
158
 
141
159
  ## 停用与卸载
@@ -150,13 +168,14 @@ dsh web
150
168
  ## 已知限制
151
169
 
152
170
  - **网关能力因人而异**:搜索、压缩、Alpha 都依赖对应的服务端能力,不同网关支持程度不同。
153
- - **Grok**:支持 API Key / API 网关路由,不支持 xAI OAuth / SuperGrok 登录。原生 X Search 目前只在 `grok-4.6` 上验证过。
171
+ - **Grok**:支持 API Key / API 网关路由,不支持 xAI OAuth / SuperGrok 登录。本次发布的真实运行验证了 `grok-4.6` 的原生 Web Search;原生 X Search 没有在本次发布的真实运行中单独重新验证(上一次单独验证是 `0.4.4-pre.1` 在 `grok-4.6` 上)。`grok-4.7` 在本次发布的测试网关上没有可用渠道,原生搜索没有在它上面验证。
172
+ - **Grok 的 `maxTokens` 设置(DSH `0.2.2`)**:如果 provider 配置里 Grok 模型的 `maxTokens` 等于 `contextWindow`,DSH `0.2.2` 不允许在会话中从其他模型切换到这个 Grok 模型(这是 DSH 的行为,DSH `0.2.1` 只给出警告)。请把 `maxTokens` 设得明显小于 `contextWindow`,为输入上下文和 DSH 的压缩预留留出空间;只是比 `contextWindow` 小一点,并不能保证可以切换过去。
154
173
  - **Grok 长对话压力**:xAI 的智能体调用会把多次内部请求的用量累加计费。LCX 在服务端返回完整的实时上下文数据时,用它来判断何时压缩,缺失时退回估算;计费数字本身保持不变。
155
174
  - **Alpha 仍是实验功能**:连续打开/查找页面在已测试的 OAuth 类上游上可用;API Key 类上游账号不在支持范围内。目标页面抓取失败时会提示 `LCX_ALPHA_PAGE_FETCH_FAILED`,模型可以换一个结果继续。
156
175
  - **Markdown 图片换行**:为避免 DSH `0.2` 中图片后的文字挤到图片右侧,LCX 会让回答里的 Markdown 图片单独占一行,这一点与“搜索媒体预览”开关无关;句中的小图也会因此换行。
157
176
  - **DSH `0.1.5` + LCX `0.4.3`**:在插件设置中启用或停用 LCX 后,已打开的浏览器页面可能需要刷新。
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.2` 的验证基线只有 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.2` 的发布基线为 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`。同一安装范围内其他后续版本仍需单独评估,遇到问题欢迎反馈。
177
+ - **DSH `0.2.1` 的工具更新**:增量工具更新只在 DSH 声明“只增不改”的 GPT Responses 路由上生效;当 DSH 的工具历史或模型信息缺失、路由不支持或设置卡片里关闭了开关时,LCX 回到每次发送完整工具列表。删除工具或同名重定义仍会让缓存失效一次。缓存命中受上游影响有波动:在 `openai/gpt-6-sol` 上用同一操作序列对比,开启时新增工具后的首个请求约 80% 命中缓存,关闭时为 0%。LCX 内置与 DSH 相同的 Pi `1.5.0` 模型目录,目录里没有的更新模型按 DSH 的声明处理。GPT-5.6 / GPT-6 系列模型的工具全部以 `additional_tools` 形式声明(与 DSH 一致),网关需要支持这种请求格式。
178
+ - **验证范围**:`0.6.0` 的验证基线只有 DSH `0.2.1-rc.5`,`0.7.0-pre.1` 的验证基线只有 DSH `0.2.2-alpha.3`(两者都是 host / plugin Pi `1.5.0`);各自安装范围内更新的 DSH 版本未经验证。两个基线上的真实运行验证覆盖 GPT 路由(`gpt-6-sol`、`gpt-6.1-sol`)、联网搜索(含高级搜索和 `run_code` 内的搜索)、手动压缩和自然触发的压缩压力档位、重启恢复、分叉与路由迁移、推理强度切换、自动审查、搜索媒体预览、插件管理页卡片和 `grok-4.6` 原生 Web Search。以下情况没有单独的完整实机验证:`gpt-5.6-sol` 的首轮对话、`gpt-5.4` / `gpt-5.5` 这类不带推理档的模型、`gpt-6-sol` 上的推理强度切换(切换验证在 `gpt-6.1-sol` 上进行)、从 GPT 切换到非 GPT 模型时的压缩、需要生成摘要的 GPT 到 GPT 模型切换、在当前 Grok 配置下从 GPT 切换到 Grok 的实际对话,以及 Alpha 搜索。旧版本:`0.6.0-pre.2` 的验证基线为 DSH `0.2.1-alpha.2`;稳定版 `0.5.2` 的发布基线为 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`。同一安装范围内其他后续版本仍需单独评估,遇到问题欢迎反馈。
160
179
 
161
180
  ## 常见问题
162
181
 
@@ -170,10 +189,10 @@ dsh web
170
189
  通常是 DSH 版本和插件版本不匹配,按[上面的表格](#1-按-dsh-版本选择插件版本)重新选择。
171
190
 
172
191
  **升级到 DSH 0.2 后插件“导入失败”(failed to import)?**
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`。
192
+ 从较早版本一路升级上来的配置目录里可能残留旧的依赖包。先停止 `dsh web`,把 DSH 主目录(默认 `~/.dsh`,或 `DSH_HOME` 指定的目录)下 `profiles/web/` 里的 `node_modules` 和 `pnpm-lock.yaml` 移走或删除,再按[上面的表格](#1-按-dsh-版本选择插件版本)重新运行对应的 `dsh plugin --profile web add` 命令,然后启动 `dsh web`。
174
193
 
175
194
  **刚发布新版时 `@latest` / `@prelatest` 装到了旧版本?**
176
- 包管理器的缓存可能还没刷新,DSH 会因版本不兼容拒绝安装。稍等几分钟重试,或直接指定版本号,例如 `dsh-lcx-codex@0.6.0-pre.2` 或 `dsh-lcx-codex@0.5.2`。
195
+ 包管理器的缓存可能还没刷新,DSH 会因版本不兼容拒绝安装。稍等几分钟重试,或直接指定版本号,例如 `dsh-lcx-codex@0.6.0` 或 `dsh-lcx-codex@0.7.0-pre.1`。
177
196
 
178
197
  ## 反馈问题
179
198
 
@@ -183,11 +202,11 @@ dsh web
183
202
 
184
203
  ## 更多
185
204
 
186
- - [更新日志](CHANGELOG.md)
187
- - [架构说明](ARCHITECTURE.md)
188
- - [第三方许可](THIRD_PARTY_NOTICES.md)
189
- - [参与贡献](CONTRIBUTING.md)
205
+ - [更新日志](https://github.com/kk3ya03-star/dsh-lcx-codex/blob/stable/0.6.x/CHANGELOG.md)
206
+ - [架构说明](https://github.com/kk3ya03-star/dsh-lcx-codex/blob/stable/0.6.x/ARCHITECTURE.md)
207
+ - [第三方许可](https://github.com/kk3ya03-star/dsh-lcx-codex/blob/stable/0.6.x/THIRD_PARTY_NOTICES.md)
208
+ - [参与贡献](https://github.com/kk3ya03-star/dsh-lcx-codex/blob/stable/0.6.x/CONTRIBUTING.md)
190
209
 
191
210
  ## 许可证
192
211
 
193
- [MIT](LICENSE)。独立社区插件,与 OpenAI、xAI、DeepSeek、Sub2API、NewAPI 无隶属关系,也未获得其官方背书。
212
+ [MIT](https://github.com/kk3ya03-star/dsh-lcx-codex/blob/stable/0.6.x/LICENSE)。独立社区插件,与 OpenAI、xAI、DeepSeek、Sub2API、NewAPI 无隶属关系,也未获得其官方背书。
@@ -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 1.1.0
5
+ ## @earendil-works/pi-ai 1.5.0
6
6
 
7
- Upstream source: https://github.com/earendil-works/pi/tree/v1.1.0/packages/ai
7
+ Upstream source: https://github.com/earendil-works/pi/tree/v1.5.0/packages/ai
8
8
 
9
9
  Included public Responses helpers and model catalogs:
10
10
 
@@ -1,6 +1,6 @@
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";
3
+ import { convertResponsesMessages, convertResponsesTools, createGrammarToolInputProperties, normalizeContext, resolveTranscript, resolveTranscriptTools, getResponsesToolSupport, } from "./pi-responses-runtime.js";
4
4
  import { resolveCatalogModel } from "./model-catalog.js";
5
5
  import { withoutDeferLoading } from "./tool-surface.js";
6
6
  import { isRecord, codedError, positiveSafeInteger } from "./util.js";
@@ -183,6 +183,11 @@ function unsupportedContent(type) {
183
183
  function replayBlockType(type) {
184
184
  return type === "text" || type === "reasoning" || type === "tool-call" ? type : undefined;
185
185
  }
186
+ /** A Responses `configuration_update` input item carrying exactly this reasoning effort. */
187
+ function isConfigurationUpdate(item, effort) {
188
+ return isRecord(item) && item.type === "configuration_update" && isRecord(item.reasoning) &&
189
+ typeof item.reasoning.effort === "string" && (effort === undefined || item.reasoning.effort === effort);
190
+ }
186
191
  function replayTextPhase(signature) {
187
192
  if (typeof signature !== "string" || !signature.startsWith("{"))
188
193
  return undefined;
@@ -205,16 +210,15 @@ function restorePortableAssistantPhases(input, messages, target) {
205
210
  continue;
206
211
  const sameProviderAndApi = message.provider === target.provider && message.api === target.api;
207
212
  const sameModel = sameProviderAndApi && message.model === target.id;
213
+ // Pi drops thinking from another model (it no longer becomes assistant text), so only text blocks
214
+ // become assistant message items.
208
215
  for (const block of message.content) {
209
- if (block.type === "text") {
210
- const phase = sameProviderAndApi && !sameModel
211
- ? replayTextPhase(block.textSignature)
212
- : undefined;
213
- slots.push({ text: block.text, ...(phase === undefined ? {} : { phase }) });
214
- }
215
- else if (block.type === "thinking" && !sameModel && !block.redacted && block.thinking.trim()) {
216
- slots.push({ text: block.thinking });
217
- }
216
+ if (block.type !== "text")
217
+ continue;
218
+ const phase = sameProviderAndApi && !sameModel
219
+ ? replayTextPhase(block.textSignature)
220
+ : undefined;
221
+ slots.push({ text: block.text, ...(phase === undefined ? {} : { phase }) });
218
222
  }
219
223
  }
220
224
  const output = structuredClone(input);
@@ -250,6 +254,8 @@ export function readDshPiReplayState(value) {
250
254
  throw invalidReplay("responseModel must be a string");
251
255
  if (responseValue.responseId !== undefined && typeof responseValue.responseId !== "string")
252
256
  throw invalidReplay("responseId must be a string");
257
+ if (responseValue.providerThinkingLevel !== undefined && typeof responseValue.providerThinkingLevel !== "string")
258
+ throw invalidReplay("providerThinkingLevel must be a string");
253
259
  if (!Array.isArray(value.blocks))
254
260
  throw invalidReplay("blocks must be an array");
255
261
  const blocks = value.blocks.map((block, index) => {
@@ -301,7 +307,7 @@ function replayedAssistant(message, source) {
301
307
  return { type: "toolCall", id: String(block.id), name: block.name, arguments: parseArguments(block.arguments), ...(typeof replay.thoughtSignature === "string" ? { thoughtSignature: replay.thoughtSignature } : {}), ...(typeof replay.namespace === "string" ? { namespace: replay.namespace } : {}) };
302
308
  throw invalidReplay(`block ${index} has an unsupported type`);
303
309
  });
304
- return { role: "assistant", content, api: state.response.api, provider: state.response.provider, model: state.response.model, ...(typeof state.response.responseModel === "string" ? { responseModel: state.response.responseModel } : {}), ...(typeof state.response.responseId === "string" ? { responseId: state.response.responseId } : {}), usage: emptyUsage(), stopReason: state.response.stopReason, timestamp: 0 };
310
+ return { role: "assistant", content, api: state.response.api, provider: state.response.provider, model: state.response.model, ...(typeof state.response.responseModel === "string" ? { responseModel: state.response.responseModel } : {}), ...(typeof state.response.responseId === "string" ? { responseId: state.response.responseId } : {}), ...(typeof state.response.providerThinkingLevel === "string" ? { providerThinkingLevel: state.response.providerThinkingLevel } : {}), usage: emptyUsage(), stopReason: state.response.stopReason, timestamp: 0 };
305
311
  }
306
312
  function toPiAssistant(message, onReplayDegrade) {
307
313
  const source = message.source;
@@ -381,9 +387,22 @@ async function prepareRequestImageVersions(messages, ctx, options) {
381
387
  export function isPromptSnapshotMessage(message) {
382
388
  return message.role === "system" && message.source?.kind === "system-prompt";
383
389
  }
384
- /** Whether history after the leading head holds a non-empty DSH prompt snapshot (an in-history update). */
390
+ /**
391
+ * Mirrors the host adapter's `splitSystemPrompt`: the request-level `system` text and every leading system
392
+ * message form the initial prompt, joined by a blank line; empty parts drop out, on every route.
393
+ */
394
+ export function splitSystemPrompt(system, messages) {
395
+ let end = 0;
396
+ while (messages[end]?.role === "system")
397
+ end++;
398
+ const text = [system, ...messages.slice(0, end).map((message) => message.content
399
+ .filter((block) => block.type === "text")
400
+ .map((block) => block.text).join(""))];
401
+ return { systemPrompt: text.filter(Boolean).join("\n\n") || undefined, messages: messages.slice(end) };
402
+ }
403
+ /** Whether history after the leading system messages holds a non-empty DSH prompt snapshot (an in-history update). */
385
404
  export function hasMidHistoryPromptSnapshot(messages) {
386
- return messages.slice(1).some((message) => isPromptSnapshotMessage(message) &&
405
+ return splitSystemPrompt(undefined, messages).messages.some((message) => isPromptSnapshotMessage(message) &&
387
406
  message.content.some((block) => block.type === "text" && block.text.length > 0));
388
407
  }
389
408
  function flattenMessageText(message) {
@@ -404,11 +423,9 @@ async function dshToPiMessages(messages, ctx, options, imageMap, requestImages)
404
423
  // role (developer for reasoning models, system otherwise) at this exact position.
405
424
  const text = flattenMessageText(message);
406
425
  if (text.length > 0) {
407
- // A throwaway marker message directly before a DSH prompt snapshot lets the serializer trace the
408
- // rendered item back to its source message without inspecting text; it is removed afterwards.
409
- if (options.snapshotMarker !== undefined && isPromptSnapshotMessage(message))
410
- result.push({ role: "user", content: options.snapshotMarker, timestamp: 0 });
411
- result.push({ role: "system", content: text, timestamp: 0 });
426
+ // A throwaway prefix traces the rendered snapshot without adding a Pi message (message
427
+ // positions seed Pi's synthetic tool-search and assistant IDs). It is removed afterwards.
428
+ result.push({ role: "system", content: options.snapshotMarker !== undefined && isPromptSnapshotMessage(message) ? options.snapshotMarker + text : text, timestamp: 0 });
412
429
  }
413
430
  continue;
414
431
  }
@@ -421,7 +438,12 @@ async function dshToPiMessages(messages, ctx, options, imageMap, requestImages)
421
438
  if (options.anchoredTools === undefined)
422
439
  throw unsupportedContent("developer message");
423
440
  const toolsAdded = [];
441
+ const toolsRemoved = [];
424
442
  for (const block of message.content) {
443
+ if (block.type === "tool-removal") {
444
+ toolsRemoved.push({ name: block.toolName });
445
+ continue;
446
+ }
425
447
  if (block.type !== "tool-addition")
426
448
  throw unsupportedContent(block.type);
427
449
  const tool = options.anchoredTools.find((candidate) => candidate.name === block.toolName);
@@ -429,8 +451,9 @@ async function dshToPiMessages(messages, ctx, options, imageMap, requestImages)
429
451
  throw codedError(`LCX tool update references undeclared tool "${block.toolName}"`, "LCX_RESPONSES_INVALID_INPUT");
430
452
  toolsAdded.push(tool);
431
453
  }
432
- if (toolsAdded.length > 0)
433
- result.push({ role: "system", content: [], toolsAdded, timestamp: 0 });
454
+ if (toolsAdded.length > 0 || toolsRemoved.length > 0) {
455
+ result.push({ role: "system", content: options.toolUpdateMarker ?? "", toolsAdded, toolsRemoved, timestamp: 0 });
456
+ }
434
457
  continue;
435
458
  }
436
459
  if (message.role === "assistant") {
@@ -494,8 +517,8 @@ export async function serializeDshMessages(messages, ctx, options = {}) {
494
517
  throw unsupportedContent("developer message");
495
518
  for (const block of message.content)
496
519
  if (block.type === "tool-addition" || block.type === "tool-removal") {
497
- // Removals never reach a serializer: the host projection drops them on an addition-only route.
498
- if (!anchored || message.role !== "developer" || block.type === "tool-removal")
520
+ // DSH normally folds removals on addition-only routes; direct transcripts still follow Pi.
521
+ if (!anchored || message.role !== "developer")
499
522
  throw unsupportedContent(block.type);
500
523
  }
501
524
  }
@@ -518,6 +541,7 @@ export async function serializeDshMessages(messages, ctx, options = {}) {
518
541
  maxRequestImageBytes: positiveSafeInteger(options.maxRequestImageBytes, DEFAULT_MAX_REQUEST_IMAGE_BYTES),
519
542
  requestImagePixelBudget: positiveSafeInteger(options.requestImagePixelBudget, DEFAULT_REQUEST_IMAGE_PIXEL_BUDGET),
520
543
  requestImageMaxBytes: positiveSafeInteger(options.requestImageMaxBytes, DEFAULT_REQUEST_IMAGE_MAX_BYTES),
544
+ toolUpdateMarker: anchored ? `lcx-tool-update:${globalThis.crypto.randomUUID()}` : undefined,
521
545
  tools: immediateDeclared,
522
546
  ...(anchored ? { anchoredTools: declaredTools } : {}),
523
547
  };
@@ -540,6 +564,8 @@ export async function serializeDshMessages(messages, ctx, options = {}) {
540
564
  }
541
565
  const projected = projectOffloadedImages(fileProjected, (ref) => offloadedImageText(ref, attachments === undefined ? undefined : imageAccess(ctx, attachments, ref)));
542
566
  const model = resolvePiResponsesModel(normalized);
567
+ if (getResponsesToolSupport({ ...(isRecord(model.compat) ? model.compat : {}), supportsMidConvoSystemMessages: normalized.inHistorySystem }) !== "changes")
568
+ normalized.toolUpdateMarker = undefined;
543
569
  const dshContext = { systemPrompt: normalized.systemPrompt, messages: await dshToPiMessages(projected, ctx, normalized, imageMap, requestImages), tools: [...normalized.tools] };
544
570
  const compat = isRecord(model.compat) ? model.compat : {};
545
571
  const supportsStrictMode = compat.supportsStrictMode === true;
@@ -548,56 +574,93 @@ export async function serializeDshMessages(messages, ctx, options = {}) {
548
574
  const supportsToolSearch = compat.supportsToolSearch === true;
549
575
  const deferredToolsMode = supportsAdditionalTools ? "additional-tools" : supportsToolSearch ? "tool-search" : undefined;
550
576
  const grammarToolInputProperties = createGrammarToolInputProperties([...(normalized.anchoredTools ?? dshContext.tools)], supportsOpenAIGrammarTools);
551
- // Immediate declarations only: on an anchored surface deferred tools are declared by their history additions.
552
- const immediateTools = new Map();
553
- for (const tool of dshContext.tools)
554
- if (tool.name)
555
- immediateTools.set(tool.name, tool);
556
577
  const toolOptions = { supportsStrictMode, supportsOpenAIGrammarTools, toolSearchResult: false };
557
578
  const normalizedContext = normalizeContext(dshContext);
558
579
  // Pi treats whichever system message is first in the transcript as the leading prompt: it skips it when
559
580
  // includeSystemPrompt is false and renders it without the update framing. A serialization batch carrying
560
581
  // no caller-owned head (no systemPrompt/tools) must never promote a history update to that slot, so an
561
582
  // empty placeholder holds the leading position and renders nothing.
562
- const piContext = normalized.inHistorySystem && normalizedContext.messages[0]?.role === "system" && normalizedContext.messages === dshContext.messages
583
+ let piContext = normalized.inHistorySystem && normalizedContext.messages[0]?.role === "system" && normalizedContext.messages === dshContext.messages
563
584
  ? { ...normalizedContext, messages: [{ role: "system", content: "", timestamp: 0 }, ...normalizedContext.messages] }
564
585
  : normalizedContext;
586
+ const preludeMarker = options.tracePrelude && (normalized.systemPrompt || normalized.tools.length > 0)
587
+ ? `lcx-prelude:${globalThis.crypto.randomUUID()}` : undefined;
588
+ if (preludeMarker !== undefined) {
589
+ const head = piContext.messages[0];
590
+ if (head?.role !== "system" || typeof head.content !== "string")
591
+ throw codedError("LCX could not trace the request prelude", "LCX_RESPONSES_INVALID_INPUT");
592
+ piContext = { ...piContext, messages: [{ ...head, content: preludeMarker + head.content }, ...piContext.messages.slice(1)] };
593
+ }
565
594
  const piModel = model;
566
595
  // Pi collapses every system message into the leading one unless the transport accepts mid-conversation
567
596
  // system messages, which would drop or reorder in-history updates in batched serialization.
568
- const convertedInput = convertResponsesMessages(piModel, piContext, new Set(["openai", "openai-codex", "opencode"]), { includeSystemPrompt: normalized.includeSystemPrompt, grammarToolInputProperties, supportsAdditionalTools, supportsToolSearch, supportsMidConvoSystemMessages: normalized.inHistorySystem, toolOptions });
597
+ const configurationUpdateEffort = typeof options.configurationUpdateEffort === "string" ? options.configurationUpdateEffort : undefined;
598
+ const convertedInput = convertResponsesMessages(piModel, piContext, new Set(["openai", "openai-codex", "opencode"]), { includeSystemPrompt: normalized.includeSystemPrompt, grammarToolInputProperties, supportsAdditionalTools, supportsToolSearch, supportsMidConvoSystemMessages: normalized.inHistorySystem, toolOptions, configurationUpdateEffort });
599
+ if (configurationUpdateEffort !== undefined) {
600
+ const tail = convertedInput.pop();
601
+ if (!isConfigurationUpdate(tail, configurationUpdateEffort))
602
+ throw codedError("LCX could not trace the request's configuration update", "LCX_RESPONSES_INVALID_INPUT");
603
+ }
569
604
  const supersededInstructionItems = [];
570
605
  const unmarkedInput = [];
571
606
  let markersFound = 0;
572
- for (let position = 0; position < convertedInput.length; position += 1) {
573
- const item = convertedInput[position];
574
- if (normalized.snapshotMarker !== undefined && isMarkerItem(item, normalized.snapshotMarker)) {
607
+ let toolUpdatesFound = 0;
608
+ let preludeItemCount = preludeMarker === undefined ? 0 : -1;
609
+ let additionalDeclarationsSeen = 0;
610
+ for (const [position, candidate] of convertedInput.entries()) {
611
+ if (candidate.type === "additional_tools")
612
+ additionalDeclarationsSeen += 1;
613
+ let item = candidate;
614
+ const instruction = isRecord(item) && (item.role === "developer" || item.role === "system") &&
615
+ (item.type === undefined || item.type === "message") && typeof item.content === "string" ? item : undefined;
616
+ if (instruction && preludeMarker !== undefined && String(instruction.content).startsWith(preludeMarker)) {
617
+ if (preludeItemCount !== -1)
618
+ throw codedError("LCX duplicated the request prelude", "LCX_RESPONSES_INVALID_INPUT");
619
+ const content = String(instruction.content).slice(preludeMarker.length);
620
+ if (content)
621
+ unmarkedInput.push({ ...instruction, content });
622
+ preludeItemCount = unmarkedInput.length;
623
+ continue;
624
+ }
625
+ if (instruction && normalized.toolUpdateMarker !== undefined && String(instruction.content).startsWith(normalized.toolUpdateMarker)) {
626
+ toolUpdatesFound += 1;
627
+ const content = String(instruction.content).slice(normalized.toolUpdateMarker.length);
628
+ if (content !== "" && !content.startsWith("\n\n"))
629
+ throw codedError("LCX could not trace Pi's tool removal output", "LCX_RESPONSES_INVALID_INPUT");
630
+ // Pi places its own incremental notice immediately before each later declaration. Track
631
+ // that output by provenance, so it cannot survive as an orphan after checkpoint retention.
632
+ const declaration = convertedInput[position - 1];
633
+ if (isRecord(declaration) && declaration.type === "additional_tools" && additionalDeclarationsSeen > 1) {
634
+ const notice = unmarkedInput.at(-2);
635
+ if (!isRecord(notice) || (notice.role !== "developer" && notice.role !== "system") || notice.type !== undefined)
636
+ throw codedError("LCX could not trace Pi's incremental tools notice", "LCX_RESPONSES_INVALID_INPUT");
637
+ supersededInstructionItems.push(unmarkedInput.length - 2);
638
+ }
639
+ if (content.length > 0) {
640
+ supersededInstructionItems.push(unmarkedInput.length);
641
+ unmarkedInput.push({ ...instruction, content: content.slice(2) });
642
+ }
643
+ continue;
644
+ }
645
+ if (instruction && normalized.snapshotMarker !== undefined && String(instruction.content).startsWith(normalized.snapshotMarker)) {
575
646
  markersFound += 1;
576
- const rendered = convertedInput[position + 1];
577
- if (!isRecord(rendered) || (rendered.role !== "developer" && rendered.role !== "system"))
578
- throw codedError("LCX could not trace a rendered system prompt snapshot", "LCX_RESPONSES_INVALID_INPUT");
579
647
  supersededInstructionItems.push(unmarkedInput.length);
580
- continue;
648
+ item = { ...instruction, content: String(instruction.content).slice(normalized.snapshotMarker.length) };
581
649
  }
582
650
  unmarkedInput.push(item);
583
651
  }
584
- if (normalized.snapshotMarker !== undefined) {
585
- // Markers are inserted only before non-empty snapshots (empty ones render nothing), so each inserted
586
- // marker must be found exactly once and none may survive in the output, even if a future Pi merged
587
- // adjacent user messages.
588
- const inserted = dshContext.messages.filter((message) => message.role === "user" && message.content === normalized.snapshotMarker).length;
589
- const nonce = normalized.snapshotMarker.slice(normalized.snapshotMarker.lastIndexOf(":") + 1);
590
- if (markersFound !== inserted || JSON.stringify(unmarkedInput).includes(nonce))
591
- throw codedError("LCX could not remove a system prompt snapshot marker", "LCX_RESPONSES_INVALID_INPUT");
652
+ const expectedMarkedSystems = (marker) => dshContext.messages.filter(message => message.role === "system" && typeof message.content === "string" && message.content.startsWith(marker)).length;
653
+ for (const [marker, found] of [[normalized.snapshotMarker, markersFound], [normalized.toolUpdateMarker, toolUpdatesFound]]) {
654
+ if (marker !== undefined && (found !== expectedMarkedSystems(marker) || JSON.stringify(unmarkedInput).includes(marker)))
655
+ throw codedError("LCX could not remove instruction provenance markers", "LCX_RESPONSES_INVALID_INPUT");
592
656
  }
657
+ if (preludeItemCount < 0 || (preludeMarker !== undefined && JSON.stringify(unmarkedInput).includes(preludeMarker)))
658
+ throw codedError("LCX could not remove the prelude marker", "LCX_RESPONSES_INVALID_INPUT");
593
659
  const input = restorePortableAssistantPhases(unmarkedInput, dshContext.messages, { provider: model.provider, id: model.id, api: model.api });
594
- const tools = options.tools === undefined ? undefined : convertResponsesTools([...immediateTools.values()], toolOptions);
595
- return { input, supersededInstructionItems, imageMap, tools, model: piModel, grammarToolInputProperties, deferredToolsMode };
596
- }
597
- function isMarkerItem(item, marker) {
598
- if (!isRecord(item) || item.role !== "user" || !Array.isArray(item.content))
599
- return false;
600
- return item.content.length === 1 && isRecord(item.content[0]) && item.content[0].text === marker;
660
+ const toolSupport = getResponsesToolSupport({ supportsAdditionalTools, supportsToolSearch, supportsMidConvoSystemMessages: normalized.inHistorySystem });
661
+ const { requestTools } = resolveTranscriptTools(resolveTranscript(piContext, normalized.inHistorySystem).messages, toolSupport);
662
+ const tools = requestTools.length === 0 ? undefined : convertResponsesTools(requestTools, toolOptions);
663
+ return { input, preludeItemCount, supersededInstructionItems, imageMap, tools, model: piModel, grammarToolInputProperties, deferredToolsMode };
601
664
  }
602
665
  export function responsesTools(tools) {
603
666
  if (tools === undefined)