@shuind/dsh-codex-harness 0.1.26 → 0.1.28
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 +7 -8
- package/lib/client.js +161 -129
- package/lib/compaction.js +30 -4
- package/lib/index.js +38 -11
- package/lib/types/client/index.d.ts +2 -17
- package/lib/types/client/index.js +119 -129
- package/lib/types/compaction.js +45 -6
- package/lib/types/index.d.ts +8 -9
- package/lib/types/index.js +3 -4
- package/lib/types/remote.d.ts +5 -1
- package/lib/types/remote.js +36 -8
- package/package.json +8 -7
- package/presets/codex/preset.yml +1 -1
- package/presets/codex-collaboration/agent.cordis.yml +4 -4
- package/presets/codex-collaboration/preset.yml +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @shuind/dsh-codex-harness
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
使用精简版 Codex 提示词和工具,以及改善体验的功能。
|
|
4
4
|
|
|
5
5
|
## 功能
|
|
6
6
|
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
- **后台任务**:`exec_command` 支持 `run_in_background: true`,立即返回 DSH `job_id`;使用 `job_output` 读取输出、`job_kill` 停止任务。任务完成时,忙碌中的 agent 会在下一步收到 inbox 注入;空闲 agent 默认保持安静,等下一次唤醒时再处理完成消息。
|
|
10
10
|
- **GPT 能力补全**:为 GPT 系列模型补充图片输入和思考强度选项;不会覆盖用户已有的显式配置。
|
|
11
11
|
- **Fast**:仅在 Codex preset 的模型选择菜单中显示,开启后向 Responses 请求发送 `service_tier: "priority"`。
|
|
12
|
-
- **旧版 Web 兼容**:在未提供新版模型设置/上下文设置 slot 的 DSH Web 中,Fast 和上下文容量会自动回退到旧版 composer slot
|
|
12
|
+
- **旧版 Web 兼容**:在未提供新版模型设置/上下文设置 slot 的 DSH Web 中,Fast 和上下文容量会自动回退到旧版 composer inline slot;上下文容量使用紧凑按钮和弹层,不占用整行;client 注入不依赖纯类型 slot 包。
|
|
13
13
|
- **Responses 原生 apply_patch**:在 GPT Responses 请求的插件传输边界,把普通 JSON function tool 改写为 `type: "custom"` + OpenAI `lark` grammar;下一轮历史同步改写为 `custom_tool_call`。如果中转站拒绝 custom tool,则自动回退到普通 function tool,不改变 DSH 工具执行器。
|
|
14
14
|
- **远程搜索与压缩**:OpenAI Responses 请求默认优先使用 hosted `web_search` 和 `/responses/compact`;失败时回退到 DSH 的本地实现。
|
|
15
15
|
- **远程压缩用量**:`/responses/compact` 返回标准 `usage` 时,插件会把 `input_tokens`、缓存读写和 `output_tokens` 原样拆分为 DSH 的用量字段;不再把远程压缩伪造成 `0`。中转站缺失或返回不一致的 usage 时,插件不会编造数字。
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
## 安装
|
|
21
21
|
|
|
22
22
|
```sh
|
|
23
|
-
dsh plugin --profile web add @shuind/dsh-codex-harness@0.1.
|
|
23
|
+
dsh plugin --profile web add @shuind/dsh-codex-harness@0.1.28
|
|
24
24
|
```
|
|
25
25
|
|
|
26
26
|
重启 Web,创建新会话,在模式菜单中选择 **Codex 模式**。
|
|
@@ -59,7 +59,7 @@ Fast 设置保存在 `codex` 命名空间,只对 Codex preset 生效。
|
|
|
59
59
|
|
|
60
60
|
### 活动状态
|
|
61
61
|
|
|
62
|
-
Codex 发起模型请求时,Web 会在 `Deep diving...` 右侧显示
|
|
62
|
+
Codex 发起模型请求时,Web 会在 `Deep diving...` 右侧显示 `请求中... · Ns`;收到首个非空模型 token(非流式适配器则收到 `assistant/message`)后切换为 `回复中... · Ns`。模型回复结束、进入工具调用、压缩结束或下一轮开始后自动隐藏。该状态由 Host 的 `sessionProjections` 投影驱动,因此本地压缩和远程 `/responses/compact` 都会显示同一种状态。
|
|
63
63
|
|
|
64
64
|
如果当前 DSH 组合没有加载 projection 服务,插件会跳过注册,客户端也会自动隐藏这行,不影响普通会话。
|
|
65
65
|
|
|
@@ -67,8 +67,8 @@ Codex 发起模型请求时,Web 会在 `Deep diving...` 右侧显示 `请求
|
|
|
67
67
|
|
|
68
68
|
安装插件后,首次启动对应的 DSH profile 时,插件会安装两套随包提供的 preset:
|
|
69
69
|
|
|
70
|
-
- **Codex 模式**:使用精简版 Codex
|
|
71
|
-
- **Codex
|
|
70
|
+
- **Codex 模式**:使用精简版 Codex 提示词和工具,以及改善体验的功能。
|
|
71
|
+
- **Codex 协作模式**:额外加入协作提示词,预期获得更好的体验。
|
|
72
72
|
|
|
73
73
|
它们分别位于 `${DSH_HOME:-$HOME/.dsh}/.agent-presets/codex/` 和 `${DSH_HOME:-$HOME/.dsh}/.agent-presets/codex-collaboration/`。如果对应目录已经存在,插件会保留你的文件,不会覆盖自定义内容。
|
|
74
74
|
|
|
@@ -123,11 +123,10 @@ order: 10
|
|
|
123
123
|
开启后,Codex preset 会在系统提示词中注入以下协作要求:
|
|
124
124
|
|
|
125
125
|
```text
|
|
126
|
-
|
|
126
|
+
Gather enough context from the user then achieve the user's goal through the clearest, most effective path.
|
|
127
127
|
Keep only the essential logic and core actions. There's no need to explain or test what was removed or why something wasn't done.
|
|
128
128
|
Convey enough valuable information with as few words as possible. Stay focused on the end goal.
|
|
129
129
|
Solve problems by thinking from first principles and at a higher level.
|
|
130
|
-
Make things as effortless as possible for the user.
|
|
131
130
|
```
|
|
132
131
|
|
|
133
132
|
## 注意事项
|
package/lib/client.js
CHANGED
|
@@ -72,12 +72,9 @@ window.__ModuleLoader__.load({
|
|
|
72
72
|
/** Browser controls for the Codex request settings mounted by the Host plugin. */
|
|
73
73
|
const NS = "codex";
|
|
74
74
|
const SETTINGS_NAMESPACE = "codex";
|
|
75
|
-
const MODEL_SETTINGS_SLOT = "conversation.input.model.settings";
|
|
76
|
-
const CONTEXT_SETTINGS_SLOT = "conversation.input.context.settings";
|
|
77
|
-
const ACTIVITY_SLOT = "conversation.chat.status";
|
|
78
75
|
const ACTIVITY_FALLBACK_SLOT = "conversation.composer.dock";
|
|
79
76
|
const FAST_FALLBACK_SLOT = "conversation.input.right";
|
|
80
|
-
const CONTEXT_FALLBACK_SLOT = "conversation.input.
|
|
77
|
+
const CONTEXT_FALLBACK_SLOT = "conversation.input.right";
|
|
81
78
|
const DEFAULT_CONTEXT_WINDOW = 262144;
|
|
82
79
|
const en = {
|
|
83
80
|
fast: "Fast mode",
|
|
@@ -86,7 +83,7 @@ window.__ModuleLoader__.load({
|
|
|
86
83
|
fastStateOn: "On",
|
|
87
84
|
fastStateOff: "Off",
|
|
88
85
|
contextSize: "Context size",
|
|
89
|
-
contextSizeDescription: "Next request capacity in K tokens.
|
|
86
|
+
contextSizeDescription: "Next request capacity in K tokens.",
|
|
90
87
|
contextRestore: "Restore model default",
|
|
91
88
|
activityCompacting: "Compacting context...",
|
|
92
89
|
activityRequestingModel: "Requesting model...",
|
|
@@ -99,55 +96,12 @@ window.__ModuleLoader__.load({
|
|
|
99
96
|
fastStateOn: "开",
|
|
100
97
|
fastStateOff: "关",
|
|
101
98
|
contextSize: "上下文大小",
|
|
102
|
-
contextSizeDescription: "设置下次请求的上下文容量,单位为 K tokens
|
|
99
|
+
contextSizeDescription: "设置下次请求的上下文容量,单位为 K tokens。",
|
|
103
100
|
contextRestore: "恢复模型默认值",
|
|
104
101
|
activityCompacting: "正在压缩上下文...",
|
|
105
|
-
activityRequestingModel: "
|
|
106
|
-
activityModelReply: "
|
|
102
|
+
activityRequestingModel: "请求中...",
|
|
103
|
+
activityModelReply: "回复中..."
|
|
107
104
|
};
|
|
108
|
-
function FastModeButton({ sessionId, useSessions, useSettings, setSetting, t }) {
|
|
109
|
-
const agentPreset = useSessions((state) => state.byId[sessionId]?.agentPreset);
|
|
110
|
-
const snapshot = useSettings((state) => state);
|
|
111
|
-
const fast = snapshot.value?.fast ?? false;
|
|
112
|
-
if (!isCodexPresetId(agentPreset)) return null;
|
|
113
|
-
return (0, react_jsx_runtime.jsxs)("button", {
|
|
114
|
-
type: "button",
|
|
115
|
-
role: "menuitemcheckbox",
|
|
116
|
-
disabled: snapshot.writable === false,
|
|
117
|
-
"aria-pressed": fast,
|
|
118
|
-
"aria-label": fast ? t("fastOn") : t("fastOff"),
|
|
119
|
-
title: fast ? t("fastOn") : t("fastOff"),
|
|
120
|
-
onClick: () => {
|
|
121
|
-
setSetting("fast", !fast);
|
|
122
|
-
},
|
|
123
|
-
style: {
|
|
124
|
-
boxSizing: "border-box",
|
|
125
|
-
display: "flex",
|
|
126
|
-
alignItems: "center",
|
|
127
|
-
justifyContent: "space-between",
|
|
128
|
-
width: "100%",
|
|
129
|
-
height: 40,
|
|
130
|
-
border: 0,
|
|
131
|
-
borderRadius: 10,
|
|
132
|
-
padding: "0 10px",
|
|
133
|
-
color: fast ? "var(--dsw-static-blue-500)" : "var(--dsw-alias-label-secondary)",
|
|
134
|
-
background: fast ? "var(--dsw-alias-interactive-bg-selected)" : "transparent",
|
|
135
|
-
cursor: snapshot.writable === false ? "default" : "pointer",
|
|
136
|
-
font: "inherit",
|
|
137
|
-
fontSize: 14,
|
|
138
|
-
lineHeight: "22px",
|
|
139
|
-
fontWeight: fast ? 600 : 400,
|
|
140
|
-
textAlign: "left"
|
|
141
|
-
},
|
|
142
|
-
children: [(0, react_jsx_runtime.jsx)("span", { children: t("fast") }), (0, react_jsx_runtime.jsx)("span", {
|
|
143
|
-
style: {
|
|
144
|
-
color: "var(--dsw-alias-label-tertiary)",
|
|
145
|
-
fontSize: 12
|
|
146
|
-
},
|
|
147
|
-
children: fast ? t("fastStateOn") : t("fastStateOff")
|
|
148
|
-
})]
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
105
|
/** The legacy composer seat is a compact inline row, not a menu panel. */
|
|
152
106
|
function FastModeFallback(props) {
|
|
153
107
|
const { sessionId, useSessions, useSettings, setSetting, t } = props;
|
|
@@ -171,9 +125,9 @@ window.__ModuleLoader__.load({
|
|
|
171
125
|
alignItems: "center",
|
|
172
126
|
gap: 5,
|
|
173
127
|
height: 28,
|
|
174
|
-
border:
|
|
128
|
+
border: 0,
|
|
175
129
|
borderRadius: 7,
|
|
176
|
-
padding: "0
|
|
130
|
+
padding: "0 6px",
|
|
177
131
|
color: fast ? "var(--dsw-static-blue-500)" : "var(--dsw-alias-label-secondary)",
|
|
178
132
|
background: fast ? "var(--dsw-alias-interactive-bg-selected)" : "transparent",
|
|
179
133
|
cursor: snapshot.writable === false ? "default" : "pointer",
|
|
@@ -192,6 +146,11 @@ window.__ModuleLoader__.load({
|
|
|
192
146
|
})]
|
|
193
147
|
});
|
|
194
148
|
}
|
|
149
|
+
function contextWindowFromProjection(useProjection) {
|
|
150
|
+
const pressure = useProjection("contextPressure");
|
|
151
|
+
return pressure?.contextWindow !== void 0 && pressure.contextWindow > 0 ? pressure.contextWindow : DEFAULT_CONTEXT_WINDOW;
|
|
152
|
+
}
|
|
153
|
+
/** Settings form kept inside the official composer slot's popover. */
|
|
195
154
|
function ContextSizeControl({ contextWindow, useSettings, setSetting, unsetSetting, t }) {
|
|
196
155
|
const snapshot = useSettings((state) => state);
|
|
197
156
|
const configured = snapshot.value?.contextWindow;
|
|
@@ -205,9 +164,9 @@ window.__ModuleLoader__.load({
|
|
|
205
164
|
};
|
|
206
165
|
return (0, react_jsx_runtime.jsxs)("div", {
|
|
207
166
|
style: {
|
|
208
|
-
marginTop:
|
|
167
|
+
marginTop: 0,
|
|
209
168
|
display: "grid",
|
|
210
|
-
gap:
|
|
169
|
+
gap: 8
|
|
211
170
|
},
|
|
212
171
|
children: [
|
|
213
172
|
(0, react_jsx_runtime.jsxs)("div", {
|
|
@@ -220,13 +179,14 @@ window.__ModuleLoader__.load({
|
|
|
220
179
|
children: [(0, react_jsx_runtime.jsx)("strong", {
|
|
221
180
|
style: {
|
|
222
181
|
color: "var(--dsw-alias-label-primary)",
|
|
223
|
-
fontSize:
|
|
182
|
+
fontSize: 13
|
|
224
183
|
},
|
|
225
184
|
children: t("contextSize")
|
|
226
185
|
}), (0, react_jsx_runtime.jsxs)("span", {
|
|
227
186
|
style: {
|
|
228
187
|
color: "var(--dsw-alias-label-secondary)",
|
|
229
|
-
fontSize:
|
|
188
|
+
fontSize: 12,
|
|
189
|
+
fontVariantNumeric: "tabular-nums"
|
|
230
190
|
},
|
|
231
191
|
children: [valueK, "K"]
|
|
232
192
|
})]
|
|
@@ -241,16 +201,25 @@ window.__ModuleLoader__.load({
|
|
|
241
201
|
"aria-label": t("contextSize"),
|
|
242
202
|
onChange: (event) => {
|
|
243
203
|
setValueK(Number(event.target.value));
|
|
204
|
+
},
|
|
205
|
+
style: {
|
|
206
|
+
display: "block",
|
|
207
|
+
width: "100%",
|
|
208
|
+
accentColor: "var(--dsw-static-blue-500)"
|
|
244
209
|
}
|
|
245
210
|
}),
|
|
246
211
|
(0, react_jsx_runtime.jsxs)("div", {
|
|
247
212
|
style: {
|
|
248
|
-
display: "
|
|
249
|
-
|
|
250
|
-
gap: 7
|
|
213
|
+
display: "grid",
|
|
214
|
+
gap: 4
|
|
251
215
|
},
|
|
252
|
-
children: [
|
|
253
|
-
|
|
216
|
+
children: [(0, react_jsx_runtime.jsxs)("div", {
|
|
217
|
+
style: {
|
|
218
|
+
display: "flex",
|
|
219
|
+
alignItems: "center",
|
|
220
|
+
gap: 6
|
|
221
|
+
},
|
|
222
|
+
children: [(0, react_jsx_runtime.jsx)("input", {
|
|
254
223
|
type: "number",
|
|
255
224
|
min: 1,
|
|
256
225
|
max: maxK,
|
|
@@ -262,31 +231,31 @@ window.__ModuleLoader__.load({
|
|
|
262
231
|
setValueK(Number(event.target.value));
|
|
263
232
|
},
|
|
264
233
|
style: {
|
|
265
|
-
width:
|
|
234
|
+
width: 68,
|
|
266
235
|
border: "1px solid var(--dsw-alias-border-primary)",
|
|
267
|
-
borderRadius:
|
|
268
|
-
padding: "
|
|
236
|
+
borderRadius: 6,
|
|
237
|
+
padding: "4px 6px",
|
|
269
238
|
color: "var(--dsw-alias-label-primary)",
|
|
270
239
|
background: "var(--dsw-alias-fill-primary)",
|
|
271
240
|
font: "inherit",
|
|
272
|
-
fontSize:
|
|
241
|
+
fontSize: 12,
|
|
242
|
+
fontVariantNumeric: "tabular-nums"
|
|
273
243
|
}
|
|
274
|
-
}),
|
|
275
|
-
(0, react_jsx_runtime.jsx)("span", {
|
|
244
|
+
}), (0, react_jsx_runtime.jsx)("span", {
|
|
276
245
|
style: {
|
|
277
246
|
color: "var(--dsw-alias-label-secondary)",
|
|
278
247
|
fontSize: 11
|
|
279
248
|
},
|
|
280
249
|
children: "K"
|
|
281
|
-
})
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
]
|
|
250
|
+
})]
|
|
251
|
+
}), (0, react_jsx_runtime.jsx)("span", {
|
|
252
|
+
style: {
|
|
253
|
+
color: "var(--dsw-alias-label-tertiary)",
|
|
254
|
+
fontSize: 11,
|
|
255
|
+
lineHeight: "16px"
|
|
256
|
+
},
|
|
257
|
+
children: t("contextSizeDescription")
|
|
258
|
+
})]
|
|
290
259
|
}),
|
|
291
260
|
configured !== void 0 && (0, react_jsx_runtime.jsx)("button", {
|
|
292
261
|
type: "button",
|
|
@@ -308,14 +277,110 @@ window.__ModuleLoader__.load({
|
|
|
308
277
|
]
|
|
309
278
|
});
|
|
310
279
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
280
|
+
/** Compact trigger used when the host has no ContextMeter settings child slot. */
|
|
281
|
+
function LegacyContextSizeControl({ sessionId, useSessions, useProjection, useSettings, setSetting, unsetSetting, t }) {
|
|
282
|
+
const agentPreset = useSessions((state) => state.byId[sessionId]?.agentPreset);
|
|
283
|
+
const contextWindow = contextWindowFromProjection(useProjection);
|
|
284
|
+
const snapshot = useSettings((state) => state);
|
|
285
|
+
const configured = snapshot.value?.contextWindow;
|
|
286
|
+
const valueK = Math.min(CODEX_CONTEXT_MAX / CODEX_CONTEXT_UNIT, Math.max(1, Math.round((configured ?? contextWindow) / CODEX_CONTEXT_UNIT)));
|
|
287
|
+
const [open, setOpen] = (0, react.useState)(false);
|
|
288
|
+
const rootRef = (0, react.useRef)(null);
|
|
289
|
+
(0, react.useEffect)(() => {
|
|
290
|
+
if (!open) return void 0;
|
|
291
|
+
const onPointerDown = (event) => {
|
|
292
|
+
if (event.target instanceof Node && rootRef.current?.contains(event.target) === true) return;
|
|
293
|
+
setOpen(false);
|
|
294
|
+
};
|
|
295
|
+
const onKeyDown = (event) => {
|
|
296
|
+
if (event.key === "Escape") setOpen(false);
|
|
297
|
+
};
|
|
298
|
+
document.addEventListener("pointerdown", onPointerDown);
|
|
299
|
+
document.addEventListener("keydown", onKeyDown);
|
|
300
|
+
return () => {
|
|
301
|
+
document.removeEventListener("pointerdown", onPointerDown);
|
|
302
|
+
document.removeEventListener("keydown", onKeyDown);
|
|
303
|
+
};
|
|
304
|
+
}, [open]);
|
|
305
|
+
if (!isCodexPresetId(agentPreset)) return null;
|
|
306
|
+
return (0, react_jsx_runtime.jsxs)("span", {
|
|
307
|
+
ref: rootRef,
|
|
308
|
+
style: {
|
|
309
|
+
position: "relative",
|
|
310
|
+
display: "inline-flex",
|
|
311
|
+
alignItems: "center"
|
|
312
|
+
},
|
|
313
|
+
children: [(0, react_jsx_runtime.jsxs)("button", {
|
|
314
|
+
type: "button",
|
|
315
|
+
"aria-label": `${t("contextSize")}: ${valueK}K`,
|
|
316
|
+
"aria-haspopup": "dialog",
|
|
317
|
+
"aria-expanded": open,
|
|
318
|
+
disabled: snapshot.writable === false,
|
|
319
|
+
title: t("contextSize"),
|
|
320
|
+
onMouseDown: (event) => {
|
|
321
|
+
event.preventDefault();
|
|
322
|
+
},
|
|
323
|
+
onClick: () => {
|
|
324
|
+
setOpen((value) => !value);
|
|
325
|
+
},
|
|
326
|
+
style: {
|
|
327
|
+
boxSizing: "border-box",
|
|
328
|
+
display: "inline-flex",
|
|
329
|
+
alignItems: "center",
|
|
330
|
+
gap: 3,
|
|
331
|
+
height: 28,
|
|
332
|
+
border: 0,
|
|
333
|
+
borderRadius: 7,
|
|
334
|
+
padding: "0 6px",
|
|
335
|
+
color: configured === void 0 ? "var(--dsw-alias-label-secondary)" : "var(--dsw-static-blue-500)",
|
|
336
|
+
background: open ? "var(--dsw-alias-interactive-bg-hover)" : "transparent",
|
|
337
|
+
cursor: snapshot.writable === false ? "default" : "pointer",
|
|
338
|
+
font: "inherit",
|
|
339
|
+
fontSize: 12,
|
|
340
|
+
lineHeight: "20px",
|
|
341
|
+
fontWeight: configured === void 0 ? 400 : 600,
|
|
342
|
+
whiteSpace: "nowrap"
|
|
343
|
+
},
|
|
344
|
+
children: [(0, react_jsx_runtime.jsxs)("span", { children: [valueK, "K"] }), (0, react_jsx_runtime.jsx)("svg", {
|
|
345
|
+
viewBox: "0 0 12 12",
|
|
346
|
+
width: "12",
|
|
347
|
+
height: "12",
|
|
348
|
+
"aria-hidden": true,
|
|
349
|
+
children: (0, react_jsx_runtime.jsx)("path", {
|
|
350
|
+
d: "M3 4.5 6 7.5 9 4.5",
|
|
351
|
+
fill: "none",
|
|
352
|
+
stroke: "currentColor",
|
|
353
|
+
strokeWidth: "1.25",
|
|
354
|
+
strokeLinecap: "round",
|
|
355
|
+
strokeLinejoin: "round"
|
|
356
|
+
})
|
|
357
|
+
})]
|
|
358
|
+
}), open && (0, react_jsx_runtime.jsx)("div", {
|
|
359
|
+
role: "dialog",
|
|
360
|
+
"aria-label": t("contextSize"),
|
|
361
|
+
style: {
|
|
362
|
+
position: "absolute",
|
|
363
|
+
right: 0,
|
|
364
|
+
bottom: "calc(100% + 8px)",
|
|
365
|
+
zIndex: 20,
|
|
366
|
+
boxSizing: "border-box",
|
|
367
|
+
width: 300,
|
|
368
|
+
maxWidth: "calc(100vw - 24px)",
|
|
369
|
+
padding: "10px 12px 12px",
|
|
370
|
+
border: "1px solid var(--dsw-alias-border-l2)",
|
|
371
|
+
borderRadius: 10,
|
|
372
|
+
color: "var(--dsw-alias-label-primary)",
|
|
373
|
+
background: "var(--dsw-alias-bg-base)",
|
|
374
|
+
boxShadow: "var(--dsw-shadow-lv2)"
|
|
375
|
+
},
|
|
376
|
+
children: (0, react_jsx_runtime.jsx)(ContextSizeControl, {
|
|
377
|
+
contextWindow,
|
|
378
|
+
useSettings,
|
|
379
|
+
setSetting,
|
|
380
|
+
unsetSetting,
|
|
381
|
+
t
|
|
382
|
+
})
|
|
383
|
+
})]
|
|
319
384
|
});
|
|
320
385
|
}
|
|
321
386
|
function elapsedSeconds(startedAt, now) {
|
|
@@ -363,11 +428,12 @@ window.__ModuleLoader__.load({
|
|
|
363
428
|
(0, react_jsx_runtime.jsx)("span", {
|
|
364
429
|
"aria-hidden": "true",
|
|
365
430
|
style: {
|
|
366
|
-
width:
|
|
367
|
-
height:
|
|
431
|
+
width: 5,
|
|
432
|
+
height: 5,
|
|
368
433
|
flex: "0 0 auto",
|
|
369
434
|
borderRadius: "50%",
|
|
370
|
-
background: "var(--dsw-static-blue-500)"
|
|
435
|
+
background: "var(--dsw-static-blue-500)",
|
|
436
|
+
opacity: .55
|
|
371
437
|
}
|
|
372
438
|
}),
|
|
373
439
|
(0, react_jsx_runtime.jsx)("span", { children: label }),
|
|
@@ -399,25 +465,7 @@ window.__ModuleLoader__.load({
|
|
|
399
465
|
"locale",
|
|
400
466
|
"settingsScope"
|
|
401
467
|
];
|
|
402
|
-
/**
|
|
403
|
-
function chooseDeclaredSlot(preferred, fallback, isDeclared) {
|
|
404
|
-
return isDeclared(preferred) ? preferred : fallback;
|
|
405
|
-
}
|
|
406
|
-
function slotIsDeclared(ctx, slot) {
|
|
407
|
-
const registry = ctx.slots;
|
|
408
|
-
return typeof registry.spec === "function" && registry.spec.call(ctx.slots, slot) !== void 0;
|
|
409
|
-
}
|
|
410
|
-
/** Register an optional host slot without claiming it in older SlotMap declarations. */
|
|
411
|
-
function injectOptionalActivitySlot(ctx, slot) {
|
|
412
|
-
const registry = ctx.slots;
|
|
413
|
-
registry.inject(slot, () => registry.register({
|
|
414
|
-
name: slot,
|
|
415
|
-
id: "codex-activity",
|
|
416
|
-
order: 5,
|
|
417
|
-
locale: NS
|
|
418
|
-
}, ActivityLine));
|
|
419
|
-
}
|
|
420
|
-
/** Mount Codex controls in the newest named seats, with legacy composer fallbacks. */
|
|
468
|
+
/** Mount all controls through the official composer seats shared by every DSH release. */
|
|
421
469
|
function apply(ctx) {
|
|
422
470
|
ctx.effect(() => ctx.locale.register(NS, {
|
|
423
471
|
en,
|
|
@@ -429,36 +477,21 @@ window.__ModuleLoader__.load({
|
|
|
429
477
|
setSetting: (field, value) => settings.set(field, value),
|
|
430
478
|
unsetSetting: (field) => settings.unset(field)
|
|
431
479
|
});
|
|
432
|
-
|
|
433
|
-
name: MODEL_SETTINGS_SLOT,
|
|
434
|
-
id: "codex-fast",
|
|
435
|
-
order: 0,
|
|
436
|
-
locale: NS,
|
|
437
|
-
inject: injected
|
|
438
|
-
}, FastModeButton));
|
|
439
|
-
else ctx.slots.inject(FAST_FALLBACK_SLOT, () => ctx.slots.register({
|
|
480
|
+
ctx.slots.inject(FAST_FALLBACK_SLOT, () => ctx.slots.register({
|
|
440
481
|
name: FAST_FALLBACK_SLOT,
|
|
441
|
-
id: "codex-fast
|
|
482
|
+
id: "codex-fast",
|
|
442
483
|
order: 0,
|
|
443
484
|
locale: NS,
|
|
444
485
|
inject: injected
|
|
445
486
|
}, FastModeFallback));
|
|
446
|
-
|
|
447
|
-
name: CONTEXT_SETTINGS_SLOT,
|
|
448
|
-
id: "codex-context-size",
|
|
449
|
-
order: 0,
|
|
450
|
-
locale: NS,
|
|
451
|
-
inject: injected
|
|
452
|
-
}, ContextSizeControl));
|
|
453
|
-
else ctx.slots.inject(CONTEXT_FALLBACK_SLOT, () => ctx.slots.register({
|
|
487
|
+
ctx.slots.inject(CONTEXT_FALLBACK_SLOT, () => ctx.slots.register({
|
|
454
488
|
name: CONTEXT_FALLBACK_SLOT,
|
|
455
|
-
id: "codex-context-size
|
|
456
|
-
order:
|
|
489
|
+
id: "codex-context-size",
|
|
490
|
+
order: 1,
|
|
457
491
|
locale: NS,
|
|
458
492
|
inject: injected
|
|
459
493
|
}, LegacyContextSizeControl));
|
|
460
|
-
|
|
461
|
-
else ctx.slots.inject(ACTIVITY_FALLBACK_SLOT, () => ctx.slots.register({
|
|
494
|
+
ctx.slots.inject(ACTIVITY_FALLBACK_SLOT, () => ctx.slots.register({
|
|
462
495
|
name: ACTIVITY_FALLBACK_SLOT,
|
|
463
496
|
id: "codex-activity",
|
|
464
497
|
order: 5,
|
|
@@ -472,7 +505,6 @@ window.__ModuleLoader__.load({
|
|
|
472
505
|
//#endregion
|
|
473
506
|
exports.ActivityLine = ActivityLine;
|
|
474
507
|
exports.apply = apply;
|
|
475
|
-
exports.chooseDeclaredSlot = chooseDeclaredSlot;
|
|
476
508
|
exports.default = client_default;
|
|
477
509
|
exports.inject = inject;
|
|
478
510
|
return module.exports;
|
package/lib/compaction.js
CHANGED
|
@@ -1,19 +1,45 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
2
|
import BasicCompactionEngine from "@deepseek-ai/dsh-compaction-basic";
|
|
3
|
+
import { settingsNamespace } from "@deepseek-ai/dsh-settings";
|
|
3
4
|
//#region lib/types/compaction.js
|
|
4
5
|
/** Codex compaction backend that honors the latest durable request capacity. */
|
|
6
|
+
const CODEX_SETTINGS_NAMESPACE = settingsNamespace("codex");
|
|
7
|
+
/** Codex context overrides apply only to GPT-compatible model routes. */
|
|
8
|
+
function isGptModel(model) {
|
|
9
|
+
return /(?:^|\/)(?:gpt|chatgpt)(?:[-_.]|\d|$)/i.test(model);
|
|
10
|
+
}
|
|
11
|
+
/** Read the live Codex capacity without requiring a custom LLM service API. */
|
|
12
|
+
function configuredContextWindow(ctx) {
|
|
13
|
+
const settings = ctx.get("settings");
|
|
14
|
+
if (settings?.get === void 0) return { available: false };
|
|
15
|
+
const value = settings?.get?.(CODEX_SETTINGS_NAMESPACE);
|
|
16
|
+
return {
|
|
17
|
+
available: true,
|
|
18
|
+
...value?.contextWindow !== void 0 && Number.isSafeInteger(value.contextWindow) && value.contextWindow > 0 ? { value: value.contextWindow } : {}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** Read an explicit capacity persisted in the request header when settings are unavailable. */
|
|
22
|
+
function requestContextWindow(session, provider, model) {
|
|
23
|
+
const config = session.requestHeader()?.config;
|
|
24
|
+
if (config?.provider !== provider || config.model !== model) return void 0;
|
|
25
|
+
const value = config.contextWindow;
|
|
26
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : void 0;
|
|
27
|
+
}
|
|
5
28
|
/** Overlay only the capacity lookup used by pressure compaction. */
|
|
6
|
-
function withDurableContextCapacity(llm, activeSession) {
|
|
29
|
+
function withDurableContextCapacity(llm, ctx, activeSession) {
|
|
7
30
|
return new Proxy(llm, { get(target, property) {
|
|
8
31
|
if (property === "resolveModelInfo") return async (provider, model, signal) => {
|
|
9
32
|
const info = await target.resolveModelInfo(provider, model, signal);
|
|
10
33
|
const requestContext = activeSession.getStore()?.requestContext();
|
|
11
|
-
|
|
34
|
+
const session = activeSession.getStore();
|
|
35
|
+
const configured = isGptModel(model) ? configuredContextWindow(ctx) : { available: false };
|
|
36
|
+
const contextWindow = configured.available ? configured.value : (session === void 0 ? void 0 : requestContextWindow(session, provider, model)) ?? (requestContext?.provider === provider && requestContext.model === model ? requestContext.contextWindow : void 0);
|
|
37
|
+
if (contextWindow === void 0) return info;
|
|
12
38
|
return {
|
|
13
39
|
...info,
|
|
14
40
|
context: {
|
|
15
41
|
...info.context,
|
|
16
|
-
contextWindow
|
|
42
|
+
contextWindow
|
|
17
43
|
}
|
|
18
44
|
};
|
|
19
45
|
};
|
|
@@ -34,7 +60,7 @@ var CodexCompactionEngine = class extends BasicCompactionEngine {
|
|
|
34
60
|
const activeSession = new AsyncLocalStorage();
|
|
35
61
|
const llm = ctx.get("llm");
|
|
36
62
|
if (llm === void 0) throw new Error("codex compaction requires ctx.llm");
|
|
37
|
-
super(ctx.extend({ llm: withDurableContextCapacity(llm, activeSession) }), config);
|
|
63
|
+
super(ctx.extend({ llm: withDurableContextCapacity(llm, ctx, activeSession) }), config);
|
|
38
64
|
this.activeSession = activeSession;
|
|
39
65
|
}
|
|
40
66
|
compactIfNeeded(agent, trigger, signal) {
|
package/lib/index.js
CHANGED
|
@@ -530,6 +530,10 @@ const REMOTE_COMPACTION_CLOSE = "</codex-remote-compaction>";
|
|
|
530
530
|
const HOSTED_REQUESTS = new AsyncLocalStorage();
|
|
531
531
|
let hostedPatchUsers = 0;
|
|
532
532
|
let hostedPatchRestore;
|
|
533
|
+
function serviceTierOf(options) {
|
|
534
|
+
const value = options.serviceTier;
|
|
535
|
+
return typeof value === "string" ? value : void 0;
|
|
536
|
+
}
|
|
533
537
|
function isGptModel$1(model) {
|
|
534
538
|
return typeof model === "string" && /(?:^|\/)(?:gpt|chatgpt)(?:[-_.]|\d|$)/i.test(model);
|
|
535
539
|
}
|
|
@@ -750,6 +754,14 @@ function hasRemoteCompaction(body) {
|
|
|
750
754
|
function canPatchBody(body) {
|
|
751
755
|
return isGptModel$1(body.model) && (hasWebSearchTool(body) || hasRemoteCompaction(body) || hasFunctionApplyPatchTool(body) && canRewriteApplyPatchHistory(body));
|
|
752
756
|
}
|
|
757
|
+
/** Add provider options that older pi-ai adapters do not copy themselves. */
|
|
758
|
+
function applyRequestWireOptions(body, options) {
|
|
759
|
+
if (options.serviceTier === void 0 || !isGptModel$1(body.model)) return body;
|
|
760
|
+
return {
|
|
761
|
+
...body,
|
|
762
|
+
service_tier: options.serviceTier
|
|
763
|
+
};
|
|
764
|
+
}
|
|
753
765
|
/**
|
|
754
766
|
* Install a scoped fetch shim for pi-ai's already-built Responses request.
|
|
755
767
|
* The generic DSH adapter remains the owner of auth, streaming, replay, and
|
|
@@ -759,7 +771,8 @@ function canPatchBody(body) {
|
|
|
759
771
|
function installGlobalHostedWebSearchPatch() {
|
|
760
772
|
const original = globalThis.fetch;
|
|
761
773
|
const patched = async (input, init) => {
|
|
762
|
-
|
|
774
|
+
const options = HOSTED_REQUESTS.getStore();
|
|
775
|
+
if (options === void 0) return original(input, init);
|
|
763
776
|
const request = new Request(input, init);
|
|
764
777
|
if (!isResponsesRequest(request.url)) return original(input, init);
|
|
765
778
|
let body;
|
|
@@ -768,12 +781,26 @@ function installGlobalHostedWebSearchPatch() {
|
|
|
768
781
|
} catch {
|
|
769
782
|
return original(input, init);
|
|
770
783
|
}
|
|
771
|
-
|
|
772
|
-
|
|
784
|
+
const requestBody = applyRequestWireOptions(body, options);
|
|
785
|
+
if (!canPatchBody(requestBody)) {
|
|
786
|
+
if (requestBody === body) return original(input, init);
|
|
787
|
+
const headers = new Headers(request.headers);
|
|
788
|
+
headers.delete("content-length");
|
|
789
|
+
return original(new Request(request, {
|
|
790
|
+
body: JSON.stringify(requestBody),
|
|
791
|
+
headers
|
|
792
|
+
}));
|
|
793
|
+
}
|
|
794
|
+
const fallbackHeaders = new Headers(request.headers);
|
|
795
|
+
fallbackHeaders.delete("content-length");
|
|
796
|
+
const fallbackRequest = requestBody === body ? request.clone() : new Request(request, {
|
|
797
|
+
body: JSON.stringify(requestBody),
|
|
798
|
+
headers: fallbackHeaders
|
|
799
|
+
});
|
|
773
800
|
const headers = new Headers(request.headers);
|
|
774
801
|
headers.delete("content-length");
|
|
775
802
|
const hostedRequest = new Request(request, {
|
|
776
|
-
body: JSON.stringify(rewriteCodexResponsesBody(
|
|
803
|
+
body: JSON.stringify(rewriteCodexResponsesBody(requestBody)),
|
|
777
804
|
headers
|
|
778
805
|
});
|
|
779
806
|
try {
|
|
@@ -802,13 +829,13 @@ function installHostedWebSearch() {
|
|
|
802
829
|
};
|
|
803
830
|
}
|
|
804
831
|
/** Iterate an existing DSH stream with the hosted-request context installed. */
|
|
805
|
-
function hostedWebSearchStream(next) {
|
|
832
|
+
function hostedWebSearchStream(next, options = {}) {
|
|
806
833
|
return (async function* () {
|
|
807
834
|
const iterator = next()[Symbol.asyncIterator]();
|
|
808
835
|
let completed = false;
|
|
809
836
|
try {
|
|
810
837
|
while (true) {
|
|
811
|
-
const item = await HOSTED_REQUESTS.run(
|
|
838
|
+
const item = await HOSTED_REQUESTS.run(options, () => iterator.next());
|
|
812
839
|
if (item.done) {
|
|
813
840
|
completed = true;
|
|
814
841
|
return;
|
|
@@ -975,7 +1002,8 @@ function remoteCompactStream(ctx, options, next) {
|
|
|
975
1002
|
if (options.signal?.aborted) throw error;
|
|
976
1003
|
ctx.logger.warn("codex: remote compaction failed; using dsh-compaction-basic fallback");
|
|
977
1004
|
ctx.logger.warn(error);
|
|
978
|
-
|
|
1005
|
+
const serviceTier = serviceTierOf(options);
|
|
1006
|
+
yield* hostedWebSearchStream(next, serviceTier === void 0 ? {} : { serviceTier });
|
|
979
1007
|
}
|
|
980
1008
|
})();
|
|
981
1009
|
}
|
|
@@ -1208,17 +1236,16 @@ const CODEX_BASE_PROMPT = String.raw`## General
|
|
|
1208
1236
|
## Presenting your work
|
|
1209
1237
|
|
|
1210
1238
|
- Be concise, direct, friendly, and actionable.
|
|
1211
|
-
- For substantial work, explain what changed and why, then
|
|
1239
|
+
- For substantial work, explain what changed and why, then briefly note how the work was verified and what comes next.
|
|
1212
1240
|
- Do not dump large files into the conversation; refer to their paths.
|
|
1213
1241
|
- Use plain text with short sections only when they improve scanability.
|
|
1214
1242
|
`;
|
|
1215
1243
|
const CODEX_COLLABORATION_PROMPT = String.raw`## Collaboration
|
|
1216
1244
|
|
|
1217
|
-
-
|
|
1245
|
+
- Gather enough context from the user then achieve the user's goal through the clearest, most effective path.
|
|
1218
1246
|
- Keep only the essential logic and core actions. There's no need to explain or test what was removed or why something wasn't done.
|
|
1219
1247
|
- Convey enough valuable information with as few words as possible. Stay focused on the end goal.
|
|
1220
1248
|
- Solve problems by thinking from first principles and at a higher level.
|
|
1221
|
-
- Make things as effortless as possible for the user.
|
|
1222
1249
|
`;
|
|
1223
1250
|
/** Put the agent persona first and omit the generic Harness identity opener. */
|
|
1224
1251
|
function normalizeCodexPromptAssembly(assembly) {
|
|
@@ -1626,7 +1653,7 @@ function apply(ctx, config = {}) {
|
|
|
1626
1653
|
}
|
|
1627
1654
|
ctx.on("llm/stream", ((options, next) => {
|
|
1628
1655
|
if (resolved.remoteCompact && options.purpose === "compaction" && isGptModel(options.model)) return remoteCompactStream(ctx, options, next);
|
|
1629
|
-
if (options.purpose === void 0 && isGptModel(options.model)) return hostedWebSearchStream(next);
|
|
1656
|
+
if (options.purpose === void 0 && isGptModel(options.model)) return hostedWebSearchStream(next, { serviceTier: options.serviceTier });
|
|
1630
1657
|
return next();
|
|
1631
1658
|
}));
|
|
1632
1659
|
ctx.on("system-prompt/assemble", async (_assembly, _context, next) => normalizeCodexPromptAssembly(await next()));
|