dsh-lcx-codex 0.4.2 → 0.4.3-pre.13

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.
Files changed (39) hide show
  1. package/README.md +75 -224
  2. package/THIRD_PARTY_NOTICES.md +64 -0
  3. package/cordis.patch.yml +3 -20
  4. package/lib/auxiliary-usage.js +63 -0
  5. package/lib/client.js +1398 -167
  6. package/lib/compact-v2.js +218 -199
  7. package/lib/dsh-compat.js +294 -100
  8. package/lib/dsh-responses.js +512 -277
  9. package/lib/grok-native-search.js +391 -0
  10. package/lib/index.js +1066 -758
  11. package/lib/invocation-policy-scope.js +261 -0
  12. package/lib/json-store.js +57 -31
  13. package/lib/native-checkpoint.js +520 -194
  14. package/lib/pi-responses-runtime.js +1571 -0
  15. package/lib/responses-request.js +109 -121
  16. package/lib/responses-stream.js +1280 -447
  17. package/lib/route.js +425 -369
  18. package/lib/search-accounting.js +86 -0
  19. package/lib/search-usage.js +86 -0
  20. package/lib/service-mutex.js +73 -64
  21. package/lib/token-budget.js +176 -108
  22. package/lib/transport.js +308 -68
  23. package/lib/types/client/index.d.ts +18 -0
  24. package/lib/types/client/search-media.d.ts +16 -0
  25. package/lib/types/index.d.ts +83 -0
  26. package/lib/web-run-output.js +189 -18
  27. package/lib/web-search-alpha.js +1067 -163
  28. package/lib/web-search-capability.js +80 -65
  29. package/lib/web-search-hosted.js +321 -33
  30. package/lib/web-search-ref-store.js +145 -60
  31. package/package.json +112 -32
  32. package/ARCHITECTURE.md +0 -117
  33. package/CHANGELOG.md +0 -224
  34. package/README_EN.md +0 -277
  35. package/assets/dsh-lcx-codex-banner.jpg +0 -0
  36. package/lib/legacy-v3.js +0 -20
  37. package/lib/responses-replay.js +0 -68
  38. package/scripts/probe-alpha.mjs +0 -43
  39. package/scripts/validate-dsh-schema.mjs +0 -31
package/README.md CHANGED
@@ -1,277 +1,128 @@
1
- # dsh-lcx-codex
1
+ <div align="center">
2
2
 
3
- [![npm](https://img.shields.io/npm/v/dsh-lcx-codex?label=stable&color=1677ff)](https://www.npmjs.com/package/dsh-lcx-codex)
4
- [![CI](https://github.com/kk3ya03-star/dsh-lcx-codex/actions/workflows/publish.yml/badge.svg)](https://github.com/kk3ya03-star/dsh-lcx-codex/actions/workflows/publish.yml)
5
- ![DSH](https://img.shields.io/badge/DSH-0.1.1--rc.2-4ea8ff)
6
- ![Node](https://img.shields.io/badge/Node-%5E22.19%20%7C%7C%20%3E%3D24-2f855a)
7
- ![Plugin Pi](https://img.shields.io/badge/plugin%20Pi-0.84.3-111827)
8
- ![License](https://img.shields.io/badge/license-MIT-6b7280)
3
+ <img src="https://raw.githubusercontent.com/kk3ya03-star/dsh-lcx-codex/main/assets/dsh-lcx-codex-banner.svg" alt="LCX Codex" width="100%" />
9
4
 
10
- **简体中文** · [English](README_EN.md) · [Architecture](ARCHITECTURE.md) · [Changelog](CHANGELOG.md) · [Releases](https://github.com/kk3ya03-star/dsh-lcx-codex/releases)
5
+ # LCX Codex
11
6
 
12
- > **让 DSH GPT Responses 会话从第一轮普通请求开始,到工具调用、Native V2 Compact / Replay、重启恢复和 GPT 模型切换,始终保持同一个最终 Responses wire owner。**
7
+ **让 DeepSeek Harness 里的 GPT Grok 更适合长任务、联网搜索和连续工作。**
13
8
 
14
- `dsh-lcx-codex` 不替换 DSH。DSH 仍负责 Agent、Session、模型选择、工具执行、附件和 compaction policy;当 **LCX ON** 时,LCX 接管当前 GPT Responses 会话的最终 request / SSE wire。
9
+ [![npm prerelease](https://img.shields.io/npm/v/dsh-lcx-codex/prelatest?label=prelatest)](https://www.npmjs.com/package/dsh-lcx-codex)
10
+ [![DSH](https://img.shields.io/badge/DSH-0.1.5--rc.1-16803c)](#安装)
11
+ [![License](https://img.shields.io/badge/license-MIT-555)](LICENSE)
15
12
 
16
- ## 当前稳定版
13
+ **简体中文** · [English](README_EN.md) · [更新日志](CHANGELOG.md) · [问题反馈](https://github.com/kk3ya03-star/dsh-lcx-codex/issues)
17
14
 
18
- **`0.4.2`** 是当前稳定版,也是已完成真实 DSH + Sub2API 验收的 `0.4.2-pre.1` 的 **zero-functional-change stable promotion**。
15
+ </div>
19
16
 
20
- ```powershell
21
- dsh plugin --profile web add dsh-lcx-codex
22
- dsh web
23
- ```
24
-
25
- - npm dist-tag:`latest`
26
- - DSH:`0.1.1-rc.2`
27
- - Plugin Pi:`0.84.3`
28
- - Node.js:`^22.19.0 || >=24.0.0`
29
-
30
- `0.4.2-pre.1` 保留为历史 prerelease;新用户直接安装 `latest` 即可。
31
-
32
- ## 产品约定
33
-
34
- ```text
35
- LCX OFF
36
- = 完全使用 DSH 原生 LLM 流程
37
-
38
- LCX ON
39
- = 当前 GPT Responses 会话从 ordinary turn 1 开始
40
- 由 LCX 持有最终 Responses request / SSE wire
41
- ```
42
-
43
- 切换 Claude、Gemini、DeepSeek 等非 GPT 模型前先关闭 LCX;模型切换本身不需要重启 DSH。
44
-
45
- ## 为什么需要 LCX
46
-
47
- DSH 原本已经拥有 Agent、Session、Tools 和 compaction lifecycle。LCX 解决的是 GPT Responses provider-native 路径的最后一层一致性:ordinary、tools、Native Compact、Replay、restart/resume 和 GPT route migration 不再在同一个会话中切换最终 wire owner。
48
-
49
- ```text
50
- DSH
51
- Agent / Session / Tools
52
-
53
- llm / stream seam
54
-
55
- ┌──────────┴──────────┐
56
- │ │
57
- LCX OFF LCX ON
58
- │ │
59
- native DSH adapter LCX Responses Core
60
-
61
- ordinary turn 1
62
-
63
- tools
64
-
65
- Native V2 Compact
66
-
67
- Replay
68
-
69
- Restart / Resume
70
-
71
- GPT Model Migration
72
- ```
17
+ LCX Codex 是 [DeepSeek Harness](https://github.com/deepseek-ai/DeepSeek-Harness)(DSH)的社区插件。
73
18
 
74
- Compact 因此只改变 history representation,不再同时改变 request owner。
19
+ 它不会替代 DSH,也不需要你重新配置模型、接口或 API Key。模型、凭据、会话和工具仍由 DSH 管理;LCX 只在需要时为 GPT 和 Grok 增加额外能力。
75
20
 
76
- ## 核心能力
21
+ ## 你可以用它做什么
77
22
 
78
- ### 1. Full GPT Responses lifecycle ownership
23
+ | 能力 | 适合场景 |
24
+ | --- | --- |
25
+ | GPT 联网搜索 | 让 GPT 直接通过 DSH 的 `web_search` 查询网页。 |
26
+ | GPT 高级搜索 | 搜图片、限定网站、加入位置等额外搜索条件。 |
27
+ | Grok 原生 Web / X Search | 直接使用 xAI Responses 的 Web Search 和 X Search。 |
28
+ | 长对话压缩 | GPT 长任务接近上下文上限时自动尝试远程压缩,并继续当前会话。 |
29
+ | 搜索媒体预览 | 在回答下方直接预览可用的图片和视频链接。 |
30
+ | Alpha 网页操作 | 实验性连续网页阅读能力,适合需要进一步打开、查找页面内容的任务。 |
79
31
 
80
- LCX ON 后,ordinary、tool continuation、Native Compact、Native Replay、restart/resume 和 portable GPT migration 使用同一套 LCX Responses request builder / transport owner。
32
+ 其他模型继续使用 DSH 原生路径,不会因为安装 LCX 而被接管。
81
33
 
82
- DSH 仍是 canonical session/history owner;LCX 不创建第二套会话数据库,也不替换 DSH Tool Executor。
34
+ ## 安装
83
35
 
84
- ### 2. GPT-5.6 Prompt Cache
85
-
86
- `0.4.2` 使用 GPT-5.6 当前 cache-options 路径,并保持同一会话的稳定 cache identity:
87
-
88
- - 默认使用 implicit caching;
89
- - 当前支持 route 发送 `prompt_cache_options.ttl = 30m`;
90
- - 普通连续 turn / tool-heavy workload 可以复用已 warm 前缀;
91
- - Native Compact 会按设计建立新的 history/cache epoch,旧未压缩前缀不会被承诺继续复用;
92
- - 真实长会话中,稳定 topology 下 warm request 多次观察到接近完整前缀复用。
93
-
94
- 缓存命中由 provider、模型、请求前缀、工具 schema 和会话状态共同决定,不是固定性能承诺。
95
-
96
- 一个已确认的边界:运行中激活 skill 若改变顶层 tool schema,会发生一次 cache reset;新 tool topology 稳定后下一请求即可重新 warm。当前支持 route 会拒绝 content-level `prompt_cache_breakpoint`,而 DSH `0.1.1-rc.2` 也没有可靠的 dynamic-tool provenance,因此 `0.4.2` 保留一次安全 reset,而不靠猜测重写工具历史。
97
-
98
- ### 3. Native V2 Compact + Replay
99
-
100
- DSH 仍决定 **何时压缩、压缩范围、事务与 recovery**;LCX 只负责 provider-native Responses V2 wire。
101
-
102
- 默认 pressure coordination:
103
-
104
- ```text
105
- 0% ─────────────────── 90% ───── 95% ───── 100%
106
- normal Native emergency hard cap
107
- V2 DSH prune
108
- ```
36
+ 当前预发布版:**`dsh-lcx-codex@0.4.3-pre.13`**
109
37
 
110
- - `90%`:优先 Native V2;
111
- - `95%`:允许 DSH emergency tool-result prune;
112
- - provider-confirmed overflow:继续交给 DSH recovery;
113
- - manual `/compact`:仍使用 DSH 原生 compaction transaction。
38
+ 兼容环境:
114
39
 
115
- Native checkpoint v5 会持久化 provider-native compaction state 与必要的可移植保留历史;同 session / compatible route 可 Native replay,不兼容 route 不会错误复用 opaque state。
116
-
117
- ### 4. Restart / Resume + GPT 热切换
118
-
119
- 同一个 DSH session 可以跨越:
120
-
121
- ```text
122
- Terra
123
- → Compact
124
- → Replay
125
- → Restart DSH
126
- → Resume same session
127
- → Switch to Sol
128
- → Continue
129
- ```
130
-
131
- compatible route/model 可恢复 Native opaque state;不兼容的 GPT model / route 会丢弃不安全 opaque state并重建 portable history,但仍保持 LCX Responses transport ownership。
132
-
133
- ### 5. Hosted Search + Stateful Web Actions
134
-
135
- 普通联网搜索仍使用 DSH 原生 `web_search`。LCX 可以把 SearchProvider 映射到当前 GPT Hosted Search,而不是再给模型暴露第二个普通搜索工具。
136
-
137
- | 需求 | 使用入口 |
138
- |---|---|
139
- | 普通联网搜索 | DSH `web_search` |
140
- | Hosted Search 高级参数 | `websearch_gpt_advanced` |
141
- | 连续网页 / PDF 操作 | `websearch_alpha` |
40
+ - DSH `0.1.5-rc.1` 起的 `0.1.5` 系列(当前完整验证基线:`0.1.5-rc.1`)
41
+ - Node.js `^22.19.0 || >=24.0.0`
142
42
 
143
- Alpha 支持:
43
+ 安装:
144
44
 
145
- ```text
146
- search open find / click → screenshot
45
+ ```sh
46
+ dsh plugin --profile web add dsh-lcx-codex@0.4.3-pre.13
47
+ dsh web
147
48
  ```
148
49
 
149
- Alpha 默认关闭;只有当前 endpoint / provider / model / schema 通过 capability probe 后才注册。未知部署 fail-closed。
150
-
151
- ### 6. Pi 0.84.3 隔离升级
152
-
153
- 插件独立使用 `@earendil-works/pi-ai 0.84.3`,不 override DSH host:
50
+ 后续预发布更新可以使用:
154
51
 
155
- ```text
156
- DSH 0.1.1-rc.2
157
- └─ host Pi 0.82.1 ← 不改
158
-
159
- dsh-lcx-codex 0.4.2
160
- └─ plugin Pi 0.84.3 ← 插件隔离依赖
52
+ ```sh
53
+ dsh plugin --profile web add dsh-lcx-codex@prelatest
161
54
  ```
162
55
 
163
- Pi 负责 canonical Responses message/tool serialization、reasoning、IDs、strict/grammar/custom tools、`additional_tools`、`tool_search`、namespace 和 stream semantics;LCX 不维护第二套通用 provider framework
56
+ 不指定版本或 dist-tag 时会安装稳定版。当前稳定版仍为 `0.4.2`,旧版用户可查看[稳定版文档](https://github.com/kk3ya03-star/dsh-lcx-codex/blob/v0.4.2/README.md)
164
57
 
165
- ## 30 秒配置
58
+ 本版已在官方 DSH `0.1.5-rc.1` 完整验证。后续同一 `0.1.5` 系列版本可以直接安装并进行兼容评估,不再需要仅因为 RC 版本号变化而发布新的 LCX 版本。
166
59
 
167
- ### 前提条件
60
+ ## 启用功能
168
61
 
169
- - Node.js `^22.19.0 || >=24.0.0`
170
- - DSH `0.1.1-rc.2`
171
- - DSH 中已有可工作的 GPT Responses route
172
- - 上游 endpoint 实际支持准备启用的 Hosted Search / Native V2 / Alpha 能力
62
+ 打开 DSH Web 的插件设置,找到 **Responses / Codex 能力**。
173
63
 
174
- ### 推荐初始设置
64
+ ### 使用 GPT
175
65
 
176
- | 设置 | 推荐值 | 说明 |
177
- |---|---:|---|
178
- | Enable LCX | **On** | 接管当前 GPT Responses 会话 |
179
- | Use GPT Hosted Search | 按需 | 让 DSH `web_search` 使用 GPT Hosted Search |
180
- | Advanced Hosted Search | Off | 需要高级 Hosted 参数时再开 |
181
- | Alpha Search | Off | capability probe 通过后再开 |
182
- | Native-first auto compaction | On | 使用 Native-first pressure coordination |
183
- | Native threshold | `90%` | 主动 Native V2 阈值 |
184
- | Emergency DSH prune | `95%` | 紧急 prune 阈值 |
185
- | Fallback to Basic Compaction | On | Native 首次失败时允许受控回退 |
186
- | `web_search` timeout | `240s` | 避免较慢 Hosted Search 被过早中断 |
66
+ 通常打开:
187
67
 
188
- ### 如何确认生效
68
+ 1. **启用 LCX**
69
+ 2. **GPT Hosted Search**(需要联网时)
189
70
 
190
- | 能力 | 预期行为 |
191
- |---|---|
192
- | LCX ownership | LCX ON 后第一轮 GPT ordinary request 就进入 LCX Responses path |
193
- | Prompt Cache | 稳定 warm turn 可出现 provider `cached_tokens` |
194
- | Hosted Search | 普通入口仍是 DSH `web_search` |
195
- | Advanced Hosted | 开启后出现 `websearch_gpt_advanced` |
196
- | Alpha | capability probe 通过后才出现 `websearch_alpha` |
197
- | Native V2 | Compact 产生 provider-native checkpoint,而不是把 Basic Compaction 伪装成 Native |
198
- | Replay | Compact 后继续同一 DSH session;restart/resume 仍可续接 |
71
+ 按需再打开:
199
72
 
200
- ## DSH LCX 的责任边界
73
+ - **高级 Hosted 工具**:需要图片搜索、限定域名、位置等高级搜索条件时使用;它依赖 GPT Hosted Search。
74
+ - **Alpha**:实验性网页连续操作。日常联网搜索不需要开启。
201
75
 
202
- | 组件 | 负责什么 |
203
- |---|---|
204
- | **DSH** | Agent loop、Session/history、GenerateOptions、模型/credential、工具执行、AttachmentStore、pressure policy、compaction transaction |
205
- | **DSH compatibility seam** | 把 DSH message / GenerateOptions 投影到 Pi Context,并把结果桥接回 DSH |
206
- | **Plugin Pi 0.84.3** | canonical Responses serialization / parser semantics |
207
- | **LCX** | ON/OFF ownership、最终 Responses body + HTTP/SSE wire、ordinary/compact/replay orchestration、Native opaque state、Search capabilities |
76
+ ### 使用 Grok
208
77
 
209
- 更多 checkpoint、portable replay、cache identity、RefStore、pressure coordination 与 protocol 细节见 [ARCHITECTURE.md](ARCHITECTURE.md)。
78
+ Grok 原生搜索与 GPT LCX 主开关相互独立:
210
79
 
211
- ## 兼容性
80
+ - **Grok 原生 Web Search**:搜索网页。
81
+ - **Grok 原生 X Search**:搜索 X 内容。
212
82
 
213
- | Plugin | DSH | DSH host Pi | Plugin Pi | 状态 |
214
- |---|---|---|---|---|
215
- | `0.4.2` | `0.1.1-rc.2` | `0.82.1` | `0.84.3` | **VERIFIED STABLE** |
216
- | `0.4.1` | `0.1.1-rc.2` | `0.82.1` | `0.82.1` | historical stable |
83
+ 开启 Grok 原生搜索后,LCX 会使用 xAI 的服务端搜索能力,同时保留页面读取和其他 DSH / MCP 工具。
217
84
 
218
- DSH `0.1.2-alpha.1` 和更新的 Pi 版本目前不属于 `0.4.2` 的正式兼容性声明;后续会按受影响 seam 单独验证,而不是自动视为兼容。
85
+ ### 搜索媒体预览
219
86
 
220
- ## 当前边界
87
+ **搜索媒体预览**可以独立开启。它只改变回答的显示方式,不会修改模型提示词、搜索请求、聊天历史或缓存。
221
88
 
222
- - 当前支持 route 使用 implicit Prompt Cache;content-level explicit breakpoint 在该 route 上会被拒绝,因此没有作为产品设置开放。
223
- - dynamic skill / plugin 若改变 top-level tool schema,可能触发一次 prompt-cache reset;功能不受影响,新 topology 会重新 warm。
224
- - `reasoning.context` / `reasoning.mode` 仍取决于 host/Pi 暴露能力,LCX 不额外造第二套控制面。
225
- - normal operational context 仍使用约 `262K` 级别配置;1.05M long context 不是默认开启项。
226
- - credentialed `ALPHA-004` runtime 仍为 `NOT_COVERED`,fail-closed 行为已有测试覆盖。
227
- - Programmatic Tool Calling 当前不作为已支持能力宣传。
89
+ 可识别的图片会显示缩略图并支持放大;直接视频链接可以点击播放。媒体加载失败时,原来的文字和链接仍会保留。
228
90
 
229
- ## 常见问题
91
+ ## 常见用法
230
92
 
231
- <details>
232
- <summary><strong>为什么切非 GPT 前要关闭 LCX?</strong></summary>
93
+ 直接像平时一样和模型说话,不需要手写工具参数。例如:
233
94
 
234
- LCX ON GPT Responses lifecycle ownership switch,不是通用多模型代理层。非 GPT 模型继续走 DSH 原生 adapter。
95
+ > 搜索 Python 官方文档,告诉我 `asyncio.TaskGroup` 应该怎么用。
235
96
 
236
- </details>
97
+ > 搜索几张金门大桥的照片,显示一张,并给我来源网页。
237
98
 
238
- <details>
239
- <summary><strong>为什么 web_search 还是同一个工具?</strong></summary>
99
+ > 用 Grok 搜一下 X 上最近关于这个项目的讨论。
240
100
 
241
- 这是刻意设计。LCX 改的是 DSH `web_search` 后面的 SearchProvider,不给模型重复暴露两个普通搜索工具。
101
+ 长任务也不需要自己盯着上下文。启用 LCX 后,兼容的 GPT 路由会在对话变得很长时自动尝试远程压缩并继续工作;你也可以使用 `/compact` 手动压缩。
242
102
 
243
- </details>
103
+ ## 兼容性与已知限制
244
104
 
245
- <details>
246
- <summary><strong>为什么 Alpha 有时不出现?</strong></summary>
105
+ - `0.4.3-pre.13` 的当前完整验证基线是 DSH `0.1.5-rc.1`。同一 `0.1.5` 系列后续版本处于可安装、可评估范围,但仍会单独记录兼容验证结果;`0.1.6` 及更高版本不会自动视为兼容。
106
+ - 从较旧的 LCX / DSH 版本升级时,建议新建会话;旧版保存的压缩状态不保证兼容。
107
+ - Grok 原生搜索支持 API Key / API 网关路由;xAI OAuth / SuperGrok 登录不在当前范围。
108
+ - Alpha 仍是实验功能。搜索可以正常使用,但连续 `open / find` 等操作在部分路由上仍可能失败;截图也不保证能作为可显示图片返回。
109
+ - 修改 DSH profile 中的插件启用状态后,已经打开的浏览器页面可能需要刷新。
110
+ - 不同 API 网关支持的能力可能不同。普通聊天可用,不代表搜索、长对话压缩或 Alpha 等功能也一定可用。
247
111
 
248
- 这是 fail-closed 行为。当前 route/schema 没通过 capability probe 时,`websearch_alpha` 不注册。
112
+ ## 遇到问题
249
113
 
250
- </details>
114
+ **安装后看不到变化**:确认安装和启动使用的是同一个 `web` profile,并检查对应功能开关是否已经保存。
251
115
 
252
- <details>
253
- <summary><strong>为什么加载 skill 后有时缓存会重新 warm?</strong></summary>
116
+ **对话正常,但搜索或压缩失败**:先确认当前 GPT / Grok Responses 路由确实提供对应服务端能力。网关名称本身不代表一定支持所有功能。
254
117
 
255
- 某些 skill 会动态注册新的顶层工具。工具 schema 属于可缓存 prompt prefix 的一部分,topology 改变时 provider 可能建立新的 cache epoch。`0.4.2` 优先保证工具定义正确,不通过猜测 provenance 来强行维持旧 cache。
256
-
257
- </details>
258
-
259
- ## 开发与验证
260
-
261
- ```bash
262
- npm run typecheck
263
- npm test
264
- npm run test:schema
265
- npm pack --ignore-scripts
266
- ```
118
+ 提交 [Issue](https://github.com/kk3ya03-star/dsh-lcx-codex/issues) 时,请附上插件版本、DSH 版本、Node.js 版本和复现步骤。不要上传 API Key、完整请求或未脱敏的会话日志。
267
119
 
268
- - 架构:[ARCHITECTURE.md](ARCHITECTURE.md)
269
- - 版本记录:[CHANGELOG.md](CHANGELOG.md)
270
- - GitHub Releases:[Releases](https://github.com/kk3ya03-star/dsh-lcx-codex/releases)
271
- - npm:[`dsh-lcx-codex`](https://www.npmjs.com/package/dsh-lcx-codex)
120
+ ## 更多信息
272
121
 
273
- ## License
122
+ - [更新日志](CHANGELOG.md)
123
+ - [架构说明](ARCHITECTURE.md)
124
+ - [第三方许可](THIRD_PARTY_NOTICES.md)
274
125
 
275
- MIT
126
+ ## 许可证
276
127
 
277
- > `LCX` 只是项目名称。本项目是社区项目,不隶属于 OpenAI、DeepSeek、Sub2API 或 NewAPI。
128
+ [MIT](LICENSE)。独立社区插件,与 OpenAI、DeepSeek、Sub2API、NewAPI 无隶属或官方背书关系。
@@ -0,0 +1,64 @@
1
+ # Third-party notices
2
+
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
+
5
+ ## @earendil-works/pi-ai 0.85.1
6
+
7
+ Upstream source: https://github.com/earendil-works/pi/tree/v0.85.1/packages/ai
8
+
9
+ Included public Responses helpers and model catalogs:
10
+
11
+ - `api/openai-responses-shared`
12
+ - `api/constrained-sampling`
13
+ - `api/openai-prompt-cache`
14
+ - `utils/event-stream`
15
+ - model helpers from the package root
16
+ - Responses-bearing catalogs for `cloudflare-ai-gateway`, `github-copilot`, `openai`, `opencode`, `opencode-go`, and `xai`
17
+
18
+ MIT License
19
+
20
+ Copyright (c) 2025 Mario Zechner
21
+
22
+ Permission is hereby granted, free of charge, to any person obtaining a copy
23
+ of this software and associated documentation files (the "Software"), to deal
24
+ in the Software without restriction, including without limitation the rights
25
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
26
+ copies of the Software, and to permit persons to whom the Software is
27
+ furnished to do so, subject to the following conditions:
28
+
29
+ The above copyright notice and this permission notice shall be included in all
30
+ copies or substantial portions of the Software.
31
+
32
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38
+ SOFTWARE.
39
+
40
+ ## partial-json 0.1.7
41
+
42
+ Upstream source: https://github.com/promplate/partial-json-parser-js
43
+
44
+ MIT License
45
+
46
+ Copyright (c) 2023 Promplate Dev Team
47
+
48
+ Permission is hereby granted, free of charge, to any person obtaining a copy
49
+ of this software and associated documentation files (the "Software"), to deal
50
+ in the Software without restriction, including without limitation the rights
51
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
52
+ copies of the Software, and to permit persons to whom the Software is
53
+ furnished to do so, subject to the following conditions:
54
+
55
+ The above copyright notice and this permission notice shall be included in all
56
+ copies or substantial portions of the Software.
57
+
58
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
59
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
60
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
61
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
62
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
63
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
64
+ SOFTWARE.
package/cordis.patch.yml CHANGED
@@ -1,25 +1,8 @@
1
- # Optional Responses/Codex capabilities for GPT routes already configured in llm-pi-ai.
2
- # This does not replace DSH's compaction service. Native V2 is installed as the
3
- # documented purpose=compaction llm/stream override, leaving compaction policy,
4
- # range selection, pruning, transactions and /compact owned by DSH.
1
+ # GPT Responses lifecycle plugin. Runtime defaults live in the plugin Config;
2
+ # the bundle declares only route capabilities that differ from conservative defaults.
5
3
  - insert:
6
4
  - id: lcx-codex
7
5
  name: dsh-lcx-codex
8
6
  config:
9
- provider: lcx
10
- baseURL: https://api.lcxbot.com/v1
11
- apiKeyEnv: LCX_API_KEY
12
- model: gpt-5.6-sol
7
+ supportsLongCacheRetention: true
13
8
  supportsExplicitPromptCacheMode: true
14
- legacyCheckpointPath: !!js dshHomePath('storages/lcx-codex/checkpoints-v3.json')
15
- alphaCapabilityPath: !!js dshHomePath('storages/lcx-codex/web-alpha-capabilities.json')
16
- alphaRefPath: !!js dshHomePath('storages/lcx-codex/web-alpha-refs.json')
17
- webSearchProvider: lcx-responses
18
- webMaxResults: 8
19
- timeoutMs: 300000
20
- maxAttempts: 3
21
- requestImagePixelBudget: 4194304
22
- requestImageMaxBytes: 1048576
23
- webSearchTimeoutMs: 240000
24
- autoCompactionThresholdPercent: 90
25
- emergencyPruneThresholdPercent: 95
@@ -0,0 +1,63 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ const calls = new AsyncLocalStorage();
3
+ const object = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
4
+ const count = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
5
+ /** Collect only authoritative Responses billing, independently of context size. */
6
+ export function recordHostedUsage(response, requestId, provider, model) {
7
+ const store = calls.getStore();
8
+ if (!store || !object(response) || !object(response.usage))
9
+ return;
10
+ const u = response.usage;
11
+ const input = u.input_tokens, output = u.output_tokens, total = u.total_tokens;
12
+ const cached = object(u.input_tokens_details) ? u.input_tokens_details.cached_tokens : undefined;
13
+ if (!count(input) || !count(output) || !count(total) || !count(cached)
14
+ || cached > input || input + output !== total)
15
+ return;
16
+ store.push({ requestId, provider, model, usage: {
17
+ inputTokens: input - cached, outputTokens: output, totalTokens: total,
18
+ cacheReadTokens: cached, cacheWriteTokens: 0,
19
+ } });
20
+ }
21
+ /** Extend only LCX-owned search output; rendering and request schemas stay intact. */
22
+ export function withAuxiliaryUsage(tool) {
23
+ const schema = tool.output.schema;
24
+ if (schema.type !== "object")
25
+ throw new Error("Search accounting requires an object output");
26
+ return {
27
+ ...tool,
28
+ output: {
29
+ ...tool.output,
30
+ schema: { ...schema, properties: { ...schema.properties, auxiliaryUsage: {
31
+ type: "array", items: { type: "object", additionalProperties: true },
32
+ } } },
33
+ render(args, value) {
34
+ if (!object(value))
35
+ return tool.output.render(args, value);
36
+ const { auxiliaryUsage: _billing, ...original } = value;
37
+ return tool.output.render(args, original);
38
+ },
39
+ presentationMeta(args, value) {
40
+ if (!object(value))
41
+ return tool.output.presentationMeta?.(args, value) ?? {};
42
+ const { auxiliaryUsage, ...original } = value;
43
+ const meta = tool.output.presentationMeta?.(args, original) ?? {};
44
+ if (!Array.isArray(auxiliaryUsage) || auxiliaryUsage.length === 0)
45
+ return meta;
46
+ if (!object(meta))
47
+ throw new Error("Search accounting requires object presentation metadata");
48
+ return { ...meta, auxiliaryUsage };
49
+ },
50
+ },
51
+ async execute(args, exec) {
52
+ const records = [];
53
+ return calls.run(records, async () => {
54
+ const value = await tool.execute(args, exec);
55
+ if (records.length === 0)
56
+ return value;
57
+ if (!object(value))
58
+ throw new Error("Search accounting requires an object result");
59
+ return { ...value, auxiliaryUsage: records };
60
+ });
61
+ },
62
+ };
63
+ }