dsh-lcx-codex 0.5.0 → 0.5.1-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 +22 -10
- package/lib/client.js +5 -3
- package/lib/dsh-responses.js +89 -12
- package/lib/index.js +44 -4
- package/lib/native-checkpoint.js +41 -3
- package/lib/responses-stream.js +5 -2
- package/package.json +30 -30
package/README.md
CHANGED
|
@@ -37,17 +37,27 @@ LCX Codex 是 [DeepSeek Harness](https://github.com/deepseek-ai/DeepSeek-Harness
|
|
|
37
37
|
|
|
38
38
|
| 你的 DSH 版本 | 安装的 LCX 版本 | 安装命令中的标签 |
|
|
39
39
|
| --- | --- | --- |
|
|
40
|
-
| `0.2.
|
|
40
|
+
| `0.2.1-alpha.2` 及以后 | `0.5.1-pre.1`(预发布版) | `@prelatest` |
|
|
41
|
+
| `0.2.0` 系列(`0.2.0-rc.2`,早于 `0.2.1-alpha.2`) | `0.5.0`(稳定版) | `@latest` |
|
|
41
42
|
| `0.1.6` 系列(`0.1.6-alpha.2` 及以后) | `0.4.4-pre.1`(旧预发布版) | `@0.4.4-pre.1` |
|
|
42
43
|
| `0.1.5` 系列(`0.1.5-rc.1` 及以后) | `0.4.3`(稳定版) | `@0.4.3` |
|
|
43
44
|
|
|
44
|
-
|
|
45
|
+
请务必按表格选择:几个版本互不兼容,装错版本时安装命令可能只给出依赖警告,但插件可能无法正常工作。`@latest` 是稳定版 `0.5.0`(发布基线 DSH `0.2.0-rc.2`,host / plugin Pi `0.87.1`),DSH `0.1.5` 用户请固定安装 `@0.4.3`。
|
|
45
46
|
|
|
46
|
-
|
|
47
|
+
`0.5.1-pre.1` 是预发布版,面向 DSH `0.2.1-alpha.2`。它的安装范围**只有下限**(`>=0.2.1-alpha.2`),没有上限:更新的 DSH 版本也能装上,但**没有经过验证**。本次预发布的验证基线只有 DSH `0.2.1-alpha.2`(host Pi `1.1.0`,plugin Pi `0.87.1`),请不要据此认为其他 DSH 版本受支持。
|
|
48
|
+
|
|
49
|
+
> 注意:稳定版 `0.5.0` 的安装范围写作 `>=0.2.0-rc.2 <0.2.1`,按 DSH 的版本范围规则,`0.2.1` 的预发布版(如 `0.2.1-alpha.2`)也可能被放行安装,但这些版本**不在** `0.5.0` 的支持和验证范围内;DSH `0.2.1-alpha.2` 及以后请使用 `@prelatest`。
|
|
47
50
|
|
|
48
51
|
### 2. 安装并启动
|
|
49
52
|
|
|
50
|
-
DSH `0.2.
|
|
53
|
+
DSH `0.2.1-alpha.2` 及以后(预发布版):
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
dsh plugin --profile web add dsh-lcx-codex@prelatest
|
|
57
|
+
dsh web
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
DSH `0.2.0` 系列(稳定版):
|
|
51
61
|
|
|
52
62
|
```sh
|
|
53
63
|
dsh plugin --profile web add dsh-lcx-codex@latest
|
|
@@ -114,10 +124,11 @@ dsh web
|
|
|
114
124
|
|
|
115
125
|
## 从旧版本升级
|
|
116
126
|
|
|
127
|
+
- **DSH 升级到 `0.2.1-alpha.2` 或更新版本**:把插件换成 `@prelatest`(`0.5.1-pre.1`),稳定版 `0.5.0` 没有在这些 DSH 版本上验证。
|
|
117
128
|
- **DSH 升级到 `0.2.0` 系列**:把插件换成 `@latest`(`0.5.0`),旧版 `0.4.x` 不支持 DSH `0.2`。
|
|
118
129
|
- **DSH `0.1.6` 系列**:继续使用 `@0.4.4-pre.1`。
|
|
119
130
|
- **DSH `0.1.5` 系列**:继续使用 `@0.4.3`;`@latest` 现在指向支持 DSH `0.2` 的 `0.5.0`。
|
|
120
|
-
- **已装了 `0.5.0-pre.1
|
|
131
|
+
- **已装了 `0.5.0-pre.1`**:DSH `0.2.0` 系列重新运行 `@latest` 的 `add` 命令即可升到 `0.5.0`(两者运行时代码一致);DSH `0.2.1-alpha.2` 及以后用 `@prelatest`。
|
|
121
132
|
- **升级后建议新建会话**:旧版本保存的压缩状态不保证兼容。DSH `0.2` 迁移过的旧长会话如果带有旧版 LCX 压缩检查点,LCX 会提示 `LCX_CHECKPOINT_UNSUPPORTED`,新建会话即可;其他模型不受影响。
|
|
122
133
|
|
|
123
134
|
## 停用与卸载
|
|
@@ -133,11 +144,12 @@ dsh web
|
|
|
133
144
|
|
|
134
145
|
- **网关能力因人而异**:搜索、压缩、Alpha 都依赖对应的服务端能力,不同网关支持程度不同。
|
|
135
146
|
- **Grok**:支持 API Key / API 网关路由,不支持 xAI OAuth / SuperGrok 登录。原生 X Search 目前只在 `grok-4.6` 上验证过。
|
|
136
|
-
- **Grok 长对话压力**:xAI
|
|
147
|
+
- **Grok 长对话压力**:xAI 的智能体调用会把多次内部请求的用量累加计费。LCX 在服务端返回完整的实时上下文数据时,用它来判断何时压缩,缺失时退回估算;计费数字本身保持不变。
|
|
137
148
|
- **Alpha 仍是实验功能**:连续打开/查找页面在已测试的 OAuth 类上游上可用;API Key 类上游账号不在支持范围内。目标页面抓取失败时会提示 `LCX_ALPHA_PAGE_FETCH_FAILED`,模型可以换一个结果继续。
|
|
138
149
|
- **Markdown 图片换行**:为避免 DSH `0.2` 中图片后的文字挤到图片右侧,LCX 会让回答里的 Markdown 图片单独占一行,这一点与“搜索媒体预览”开关无关;句中的小图也会因此换行。
|
|
139
150
|
- **DSH `0.1.5` + LCX `0.4.3`**:在插件设置中启用或停用 LCX 后,已打开的浏览器页面可能需要刷新。
|
|
140
|
-
-
|
|
151
|
+
- **DSH `0.2.1` 的工具更新**:DSH `0.2.1` 的“只增不改”增量工具更新没有实现,LCX 仍然每次请求都发送完整的当前工具列表;这一变化带来的缓存收益不在声明范围内。
|
|
152
|
+
- **验证范围**:`0.5.1-pre.1` 的验证基线只有 DSH `0.2.1-alpha.2`(预发布,host Pi `1.1.0`),安装范围没有上限,更新的 DSH 版本未经验证;该基线上的真实运行验证覆盖 GPT 路由、搜索和压缩等主要场景,Grok 路由、Alpha 搜索和用户图片输入没有在这一轮覆盖。`0.5.0` 的发布基线为 DSH `0.2.0-rc.2`;`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`。同一安装范围内其他后续版本仍需单独评估,遇到问题欢迎反馈。
|
|
141
153
|
|
|
142
154
|
## 常见问题
|
|
143
155
|
|
|
@@ -151,10 +163,10 @@ dsh web
|
|
|
151
163
|
通常是 DSH 版本和插件版本不匹配,按[上面的表格](#1-按-dsh-版本选择插件版本)重新选择。
|
|
152
164
|
|
|
153
165
|
**升级到 DSH 0.2 后插件“导入失败”(failed to import)?**
|
|
154
|
-
从较早版本一路升级上来的配置目录里可能残留旧的依赖包。先停止 `dsh web`,把 DSH 主目录(默认 `~/.dsh`,或 `DSH_HOME` 指定的目录)下 `profiles/web/` 里的 `node_modules` 和 `pnpm-lock.yaml`
|
|
166
|
+
从较早版本一路升级上来的配置目录里可能残留旧的依赖包。先停止 `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`。
|
|
155
167
|
|
|
156
|
-
**刚发布新版时 `@latest` 装到了旧版本?**
|
|
157
|
-
包管理器的缓存可能还没刷新,DSH 会因版本不兼容拒绝安装。稍等几分钟重试,或直接指定版本号,例如 `dsh-lcx-codex@0.5.0`。
|
|
168
|
+
**刚发布新版时 `@latest` / `@prelatest` 装到了旧版本?**
|
|
169
|
+
包管理器的缓存可能还没刷新,DSH 会因版本不兼容拒绝安装。稍等几分钟重试,或直接指定版本号,例如 `dsh-lcx-codex@0.5.1-pre.1` 或 `dsh-lcx-codex@0.5.0`。
|
|
158
170
|
|
|
159
171
|
## 反馈问题
|
|
160
172
|
|
package/lib/client.js
CHANGED
|
@@ -396,16 +396,18 @@ a.lcx-media-chip:hover{text-decoration:underline;text-underline-offset:2px}
|
|
|
396
396
|
return { ...group[0], sources: group.map((value) => value.url) };
|
|
397
397
|
});
|
|
398
398
|
}
|
|
399
|
+
var CHAT_FLOW_SLOT = "conversation.chat.flow";
|
|
399
400
|
var activeDialogByDocument = /* @__PURE__ */ new WeakMap();
|
|
400
401
|
function inlineMediaAnswer(marker) {
|
|
401
402
|
const row = marker.closest('[data-chat-flow-kind="lcx-search-media"]');
|
|
402
403
|
const ElementClass = marker.ownerDocument.defaultView?.HTMLElement;
|
|
403
404
|
if (!ElementClass || !row || !row.dataset.chatTurn) return null;
|
|
404
405
|
const group = row.closest("[data-chat-group-key][data-step-process]");
|
|
405
|
-
const
|
|
406
|
-
|
|
406
|
+
const siblings = group?.parentElement;
|
|
407
|
+
const column = siblings?.dataset.slot === CHAT_FLOW_SLOT ? siblings.parentElement : siblings;
|
|
408
|
+
if (!group || !(siblings instanceof ElementClass) || !(column instanceof ElementClass) || !column.hasAttribute("data-chat-flow") || group.dataset.chatTurn !== row.dataset.chatTurn) return null;
|
|
407
409
|
let answer = null;
|
|
408
|
-
for (const child of
|
|
410
|
+
for (const child of siblings.children) {
|
|
409
411
|
if (child === group) break;
|
|
410
412
|
if (child instanceof ElementClass && child.dataset.chatFlowKind === "assistant-step" && child.dataset.chatGroupPart === "response" && child.dataset.chatTurn === row.dataset.chatTurn) {
|
|
411
413
|
answer = child;
|
package/lib/dsh-responses.js
CHANGED
|
@@ -72,23 +72,37 @@ function imageAccess(ctx, attachments, ref) {
|
|
|
72
72
|
: () => undefined;
|
|
73
73
|
return attachments.resolveAccess(mapper, ref);
|
|
74
74
|
}
|
|
75
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Facts DSH resolves for the exact routed model through `llm.resolveModelInfo`, the same
|
|
77
|
+
* adapter-owned metadata the agent loop uses to choose how a system prompt change is recorded.
|
|
78
|
+
* Resolution failure reports `resolved: false` with conservative defaults (unknown image support, no in-history mode).
|
|
79
|
+
*/
|
|
80
|
+
export async function resolveRouteModelFacts(ctx, route, signal) {
|
|
76
81
|
const llm = ctx?.llm;
|
|
77
82
|
if (llm === undefined)
|
|
78
|
-
return "unknown";
|
|
83
|
+
return { imageSupport: "unknown", systemPromptUpdate: undefined, resolved: false };
|
|
79
84
|
try {
|
|
80
85
|
const info = await llm.resolveModelInfo(stringValue(route.provider), stringValue(route.model), signal);
|
|
81
86
|
const modalities = info.inputModalities;
|
|
82
|
-
return
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
+
return {
|
|
88
|
+
imageSupport: modalities?.includes("image")
|
|
89
|
+
? "supported"
|
|
90
|
+
: modalities !== undefined
|
|
91
|
+
? "unsupported"
|
|
92
|
+
: "unknown",
|
|
93
|
+
systemPromptUpdate: info.systemPromptUpdate === "in-history" ? "in-history" : undefined,
|
|
94
|
+
resolved: true,
|
|
95
|
+
};
|
|
87
96
|
}
|
|
88
97
|
catch {
|
|
89
|
-
|
|
98
|
+
// `resolved: false` tells callers the mode is unknown rather than known-absent, so they can refuse
|
|
99
|
+
// to downgrade history that only an in-history route may legitimately contain.
|
|
100
|
+
return { imageSupport: "unknown", systemPromptUpdate: undefined, resolved: false };
|
|
90
101
|
}
|
|
91
102
|
}
|
|
103
|
+
export async function resolveModelImageSupport(ctx, route, signal) {
|
|
104
|
+
return (await resolveRouteModelFacts(ctx, route, signal)).imageSupport;
|
|
105
|
+
}
|
|
92
106
|
function attachmentResolver(ctx, options, requestImages) {
|
|
93
107
|
const attachments = attachmentServices(ctx?.attachments);
|
|
94
108
|
return async (block, signal) => {
|
|
@@ -356,6 +370,15 @@ async function prepareRequestImageVersions(messages, ctx, options) {
|
|
|
356
370
|
}));
|
|
357
371
|
return new Map(versions);
|
|
358
372
|
}
|
|
373
|
+
/** A full system prompt snapshot written by DSH's own system-prompt projection. */
|
|
374
|
+
export function isPromptSnapshotMessage(message) {
|
|
375
|
+
return message.role === "system" && message.source?.kind === "system-prompt";
|
|
376
|
+
}
|
|
377
|
+
/** Whether history after the leading head holds a non-empty DSH prompt snapshot (an in-history update). */
|
|
378
|
+
export function hasMidHistoryPromptSnapshot(messages) {
|
|
379
|
+
return messages.slice(1).some((message) => isPromptSnapshotMessage(message) &&
|
|
380
|
+
message.content.some((block) => block.type === "text" && block.text.length > 0));
|
|
381
|
+
}
|
|
359
382
|
function flattenMessageText(message) {
|
|
360
383
|
return message.content.map((block) => {
|
|
361
384
|
if (block.type !== "text")
|
|
@@ -368,6 +391,20 @@ async function dshToPiMessages(messages, ctx, options, imageMap, requestImages)
|
|
|
368
391
|
const toolNames = new Map();
|
|
369
392
|
for (const message of messages) {
|
|
370
393
|
if (message.role === "system") {
|
|
394
|
+
if (options.inHistorySystem === true) {
|
|
395
|
+
// In-history routes record a changed system prompt as a full later `system` message that keeps
|
|
396
|
+
// instruction authority. Pi renders a non-leading system message with the model's instruction
|
|
397
|
+
// role (developer for reasoning models, system otherwise) at this exact position.
|
|
398
|
+
const text = flattenMessageText(message);
|
|
399
|
+
if (text.length > 0) {
|
|
400
|
+
// A throwaway marker message directly before a DSH prompt snapshot lets the serializer trace the
|
|
401
|
+
// rendered item back to its source message without inspecting text; it is removed afterwards.
|
|
402
|
+
if (options.snapshotMarker !== undefined && isPromptSnapshotMessage(message))
|
|
403
|
+
result.push({ role: "user", content: options.snapshotMarker, timestamp: 0 });
|
|
404
|
+
result.push({ role: "system", content: text, timestamp: 0 });
|
|
405
|
+
}
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
371
408
|
result.push({ role: "user", content: flattenMessageText(message), timestamp: 0 });
|
|
372
409
|
continue;
|
|
373
410
|
}
|
|
@@ -449,6 +486,8 @@ export async function serializeDshMessages(messages, ctx, options = {}) {
|
|
|
449
486
|
route: options.route ?? {}, model: options.model, responsesCompat: options.responsesCompat,
|
|
450
487
|
systemPrompt: typeof options.systemPrompt === "string" ? options.systemPrompt : undefined,
|
|
451
488
|
includeSystemPrompt: options.includeSystemPrompt === true, onReplayDegrade: options.onReplayDegrade,
|
|
489
|
+
inHistorySystem: options.systemPromptUpdate === "in-history",
|
|
490
|
+
snapshotMarker: options.systemPromptUpdate === "in-history" ? `\u0000lcx-prompt-snapshot:${globalThis.crypto.randomUUID()}` : undefined,
|
|
452
491
|
maxRequestImageBytes: positiveSafeInteger(options.maxRequestImageBytes, DEFAULT_MAX_REQUEST_IMAGE_BYTES),
|
|
453
492
|
requestImagePixelBudget: positiveSafeInteger(options.requestImagePixelBudget, DEFAULT_REQUEST_IMAGE_PIXEL_BUDGET),
|
|
454
493
|
requestImageMaxBytes: positiveSafeInteger(options.requestImageMaxBytes, DEFAULT_REQUEST_IMAGE_MAX_BYTES),
|
|
@@ -487,12 +526,50 @@ export async function serializeDshMessages(messages, ctx, options = {}) {
|
|
|
487
526
|
if (tool.name)
|
|
488
527
|
immediateTools.set(tool.name, tool);
|
|
489
528
|
const toolOptions = { supportsStrictMode, supportsOpenAIGrammarTools, toolSearchResult: false };
|
|
490
|
-
const
|
|
529
|
+
const normalizedContext = normalizeContext(dshContext);
|
|
530
|
+
// Pi treats whichever system message is first in the transcript as the leading prompt: it skips it when
|
|
531
|
+
// includeSystemPrompt is false and renders it without the update framing. A serialization batch carrying
|
|
532
|
+
// no caller-owned head (no systemPrompt/tools) must never promote a history update to that slot, so an
|
|
533
|
+
// empty placeholder holds the leading position and renders nothing.
|
|
534
|
+
const piContext = normalized.inHistorySystem && normalizedContext.messages[0]?.role === "system" && normalizedContext.messages === dshContext.messages
|
|
535
|
+
? { ...normalizedContext, messages: [{ role: "system", content: "", timestamp: 0 }, ...normalizedContext.messages] }
|
|
536
|
+
: normalizedContext;
|
|
491
537
|
const piModel = model;
|
|
492
|
-
|
|
493
|
-
|
|
538
|
+
// Pi collapses every system message into the leading one unless the transport accepts mid-conversation
|
|
539
|
+
// system messages, which would drop or reorder in-history updates in batched serialization.
|
|
540
|
+
const convertedInput = convertResponsesMessages(piModel, piContext, new Set(["openai", "openai-codex", "opencode"]), { includeSystemPrompt: normalized.includeSystemPrompt, grammarToolInputProperties, supportsAdditionalTools, supportsToolSearch, supportsMidConvoSystemMessages: normalized.inHistorySystem, toolOptions });
|
|
541
|
+
const supersededInstructionItems = [];
|
|
542
|
+
const unmarkedInput = [];
|
|
543
|
+
let markersFound = 0;
|
|
544
|
+
for (let position = 0; position < convertedInput.length; position += 1) {
|
|
545
|
+
const item = convertedInput[position];
|
|
546
|
+
if (normalized.snapshotMarker !== undefined && isMarkerItem(item, normalized.snapshotMarker)) {
|
|
547
|
+
markersFound += 1;
|
|
548
|
+
const rendered = convertedInput[position + 1];
|
|
549
|
+
if (!isObject(rendered) || (rendered.role !== "developer" && rendered.role !== "system"))
|
|
550
|
+
throw error("LCX could not trace a rendered system prompt snapshot", "LCX_RESPONSES_INVALID_INPUT");
|
|
551
|
+
supersededInstructionItems.push(unmarkedInput.length);
|
|
552
|
+
continue;
|
|
553
|
+
}
|
|
554
|
+
unmarkedInput.push(item);
|
|
555
|
+
}
|
|
556
|
+
if (normalized.snapshotMarker !== undefined) {
|
|
557
|
+
// Markers are inserted only before non-empty snapshots (empty ones render nothing), so each inserted
|
|
558
|
+
// marker must be found exactly once and none may survive in the output, even if a future Pi merged
|
|
559
|
+
// adjacent user messages.
|
|
560
|
+
const inserted = dshContext.messages.filter((message) => message.role === "user" && message.content === normalized.snapshotMarker).length;
|
|
561
|
+
const nonce = normalized.snapshotMarker.slice(normalized.snapshotMarker.lastIndexOf(":") + 1);
|
|
562
|
+
if (markersFound !== inserted || JSON.stringify(unmarkedInput).includes(nonce))
|
|
563
|
+
throw error("LCX could not remove a system prompt snapshot marker", "LCX_RESPONSES_INVALID_INPUT");
|
|
564
|
+
}
|
|
565
|
+
const input = restorePortableAssistantPhases(unmarkedInput, dshContext.messages, { provider: model.provider, id: model.id, api: model.api });
|
|
494
566
|
const tools = options.tools === undefined ? undefined : convertResponsesTools([...immediateTools.values()], toolOptions);
|
|
495
|
-
return { input, imageMap, tools, model: piModel, grammarToolInputProperties, deferredToolsMode };
|
|
567
|
+
return { input, supersededInstructionItems, imageMap, tools, model: piModel, grammarToolInputProperties, deferredToolsMode };
|
|
568
|
+
}
|
|
569
|
+
function isMarkerItem(item, marker) {
|
|
570
|
+
if (!isObject(item) || item.role !== "user" || !Array.isArray(item.content))
|
|
571
|
+
return false;
|
|
572
|
+
return item.content.length === 1 && isObject(item.content[0]) && item.content[0].text === marker;
|
|
496
573
|
}
|
|
497
574
|
export function responsesTools(tools) {
|
|
498
575
|
if (tools === undefined)
|
package/lib/index.js
CHANGED
|
@@ -15,7 +15,7 @@ import { fetchJsonWithRetry } from "./transport.js";
|
|
|
15
15
|
import { agentSessionId, agentUsesSession, compactionConfigState, compactionPatchCandidate, installCompactionPatch, patchCompactionConfig, patchToolResultPruner, readAgentRouteState, readSelectedAgentRouteState, recordAgentRouteEvent, resolveAgentService, resolveContextService, resolveScopedService, restoreCompactionConfig, restoreCompactionPatches, restoreToolResultPruner, sessionFor, sessionFromAgent, scopedToolRuntime, tokenMeterTotal, toolResultPrunerState, } from "./dsh-compat.js";
|
|
16
16
|
import { InvocationPolicyScope } from "./invocation-policy-scope.js";
|
|
17
17
|
import { authenticatedGrokHeaders, authenticatedHeaders, currentRoute, generationControlsFromSession, grokPromptCacheSessionId, promptCacheKey, promptCacheRetention, promptCacheSessionId, resolveGrokResponsesRouteConfig, resolveResponsesRouteConfig, routeFingerprint, } from "./route.js";
|
|
18
|
-
import { DEFAULT_MAX_REQUEST_IMAGE_BYTES, DEFAULT_REQUEST_IMAGE_PIXEL_BUDGET, DEFAULT_REQUEST_IMAGE_MAX_BYTES, hydrateNativeImageReferences,
|
|
18
|
+
import { DEFAULT_MAX_REQUEST_IMAGE_BYTES, DEFAULT_REQUEST_IMAGE_PIXEL_BUDGET, DEFAULT_REQUEST_IMAGE_MAX_BYTES, hydrateNativeImageReferences, resolveRouteModelFacts, hasMidHistoryPromptSnapshot, responseInputItems, serializeDshMessages, } from "./dsh-responses.js";
|
|
19
19
|
import { mergeFeatureHeader, requestNativeCompaction } from "./compact-v2.js";
|
|
20
20
|
import { buildResponsesBody } from "./responses-request.js";
|
|
21
21
|
import { managedFailureChunk, streamResponsesRequest, } from "./responses-stream.js";
|
|
@@ -544,19 +544,51 @@ function mergeMap(target, source) {
|
|
|
544
544
|
for (const [key, value] of source ?? [])
|
|
545
545
|
target.set(key, value);
|
|
546
546
|
}
|
|
547
|
+
/**
|
|
548
|
+
* Follow traced item positions through the Grok replay restoration, which may splice items. When the
|
|
549
|
+
* item count is unchanged the positions are exact; otherwise each traced item is found again by exact
|
|
550
|
+
* structural equality in order (restoration never alters instruction items).
|
|
551
|
+
*/
|
|
552
|
+
function locateSupersededItems(original, restored, positions) {
|
|
553
|
+
if (positions.length === 0 || original.length === restored.length)
|
|
554
|
+
return [...positions];
|
|
555
|
+
const located = [];
|
|
556
|
+
let cursor = 0;
|
|
557
|
+
for (const position of positions) {
|
|
558
|
+
const wanted = JSON.stringify(original[position]);
|
|
559
|
+
while (cursor < restored.length && JSON.stringify(restored[cursor]) !== wanted)
|
|
560
|
+
cursor += 1;
|
|
561
|
+
if (cursor >= restored.length)
|
|
562
|
+
throw Object.assign(new Error("LCX lost track of a superseded system prompt item"), { code: "LCX_RESPONSES_INVALID_INPUT" });
|
|
563
|
+
located.push(cursor);
|
|
564
|
+
cursor += 1;
|
|
565
|
+
}
|
|
566
|
+
return located;
|
|
567
|
+
}
|
|
547
568
|
async function serializeNativeAware(messages, route, routeConfig, ctx, options) {
|
|
548
569
|
const session = sessionFor(ctx, route.sessionId);
|
|
549
|
-
|
|
570
|
+
// One adapter-owned lookup supplies image support and the route's system-prompt update mode. On an
|
|
571
|
+
// "in-history" route DSH appends a changed prompt as a later full system message; it must reach the
|
|
572
|
+
// model in place with instruction authority instead of being demoted to user context.
|
|
573
|
+
const { imageSupport, systemPromptUpdate, resolved } = await resolveRouteModelFacts(ctx, route, options.signal);
|
|
574
|
+
// An unreadable model mode must not demote instructions: history that holds a DSH prompt snapshot after
|
|
575
|
+
// the head can only come from an in-history route, and sending it as user text would silently lower its
|
|
576
|
+
// authority. Without such history the conservative default is harmless, so ordinary requests proceed.
|
|
577
|
+
if (!resolved && hasMidHistoryPromptSnapshot(messages))
|
|
578
|
+
throw Object.assign(new Error("LCX could not read the route's model information, so in-history system prompt updates cannot be sent safely; retry once the route is available"), { code: "LCX_SYSTEM_PROMPT_MODE_UNKNOWN" });
|
|
550
579
|
const input = [];
|
|
551
580
|
const imageMap = new Map();
|
|
552
581
|
let nativeTools;
|
|
553
582
|
let nativeModel;
|
|
554
583
|
let grammarToolInputProperties;
|
|
555
584
|
let normal = [];
|
|
585
|
+
/** Absolute `input` positions rendered from DSH prompt snapshots that a checkpoint supersedes. */
|
|
586
|
+
const supersededInstructionItems = [];
|
|
556
587
|
const serializeOptions = (imageMapOverride = undefined, extra = {}) => requestImageOptions(routeConfig, imageSupport, options.signal, imageMapOverride, {
|
|
557
588
|
route,
|
|
558
589
|
tools: options.tools,
|
|
559
590
|
responsesCompat: routeConfig.responsesCompat,
|
|
591
|
+
systemPromptUpdate,
|
|
560
592
|
...extra,
|
|
561
593
|
});
|
|
562
594
|
const firstMessage = messages[0];
|
|
@@ -585,7 +617,10 @@ async function serializeNativeAware(messages, route, routeConfig, ctx, options)
|
|
|
585
617
|
nativeModel = serialized.model ?? nativeModel;
|
|
586
618
|
grammarToolInputProperties =
|
|
587
619
|
serialized.grammarToolInputProperties ?? grammarToolInputProperties;
|
|
588
|
-
|
|
620
|
+
const restored = restoreGrokNativeReplay(serialized.input, batch.filter(isPersistedMessage), options.grokNativeReplayRoute);
|
|
621
|
+
const base = input.length;
|
|
622
|
+
supersededInstructionItems.push(...locateSupersededItems(serialized.input, restored, serialized.supersededInstructionItems).map((position) => base + position));
|
|
623
|
+
input.push(...restored);
|
|
589
624
|
mergeMap(imageMap, serialized.imageMap);
|
|
590
625
|
};
|
|
591
626
|
for (const message of surfaceMessages ?? []) {
|
|
@@ -609,7 +644,10 @@ async function serializeNativeAware(messages, route, routeConfig, ctx, options)
|
|
|
609
644
|
}
|
|
610
645
|
else {
|
|
611
646
|
const portable = await portableMessagesForCheckpoint(ctx, session, checkpointId, { maxChars: routeConfig.portableReplayMaxChars });
|
|
612
|
-
|
|
647
|
+
// Shadowed history is superseded by the head DSH re-rendered when the compaction began its new
|
|
648
|
+
// series, so its old system messages stay ordinary context instead of regaining instruction
|
|
649
|
+
// authority behind the current prompt.
|
|
650
|
+
const serialized = await serializeDshMessages(portable, ctx, serializeOptions(undefined, { systemPromptUpdate: undefined }));
|
|
613
651
|
input.push(...serialized.input);
|
|
614
652
|
mergeMap(imageMap, serialized.imageMap);
|
|
615
653
|
}
|
|
@@ -623,6 +661,7 @@ async function serializeNativeAware(messages, route, routeConfig, ctx, options)
|
|
|
623
661
|
return {
|
|
624
662
|
input,
|
|
625
663
|
ephemeralPreludeItemCount,
|
|
664
|
+
supersededInstructionItems,
|
|
626
665
|
imageMap,
|
|
627
666
|
imageSupport,
|
|
628
667
|
tools: nativeTools,
|
|
@@ -678,6 +717,7 @@ async function* remoteCompactionStream(options, routeConfig, ctx, next) {
|
|
|
678
717
|
result,
|
|
679
718
|
input: prepared.input,
|
|
680
719
|
ephemeralPreludeItemCount: prepared.ephemeralPreludeItemCount,
|
|
720
|
+
supersededItemIndices: prepared.supersededInstructionItems,
|
|
681
721
|
imageMap: prepared.imageMap,
|
|
682
722
|
retentionOptions: {
|
|
683
723
|
tokenBudget: routeConfig.nativeRetentionTokenBudget,
|
package/lib/native-checkpoint.js
CHANGED
|
@@ -321,11 +321,32 @@ export async function activeCompactionId(ctx, session) {
|
|
|
321
321
|
lease[Symbol.dispose]();
|
|
322
322
|
}
|
|
323
323
|
}
|
|
324
|
+
/**
|
|
325
|
+
* On "in-history" routes DSH records every system prompt change as a full later `system` message
|
|
326
|
+
* (source `system-prompt`). A checkpoint begins a new DSH series whose head is re-rendered with the
|
|
327
|
+
* CURRENT prompt, so those snapshots in the retained window are superseded by that head. Retaining
|
|
328
|
+
* one, as developer/system or even as user text, would keep a stale full prompt (for example plan-mode
|
|
329
|
+
* policy that has since been switched off) in front of the model after the compaction.
|
|
330
|
+
*
|
|
331
|
+
* Only items the serializer traced back to such snapshots (`supersededItemIndices`, absolute positions
|
|
332
|
+
* in `input`) are removed. Any other retained developer/system item is genuine client context and
|
|
333
|
+
* stays. The ephemeral prelude is removed by the caller's slice, and the retention budget is computed
|
|
334
|
+
* over what is actually kept.
|
|
335
|
+
*/
|
|
336
|
+
function dropSupersededItems(input, preludeCount, superseded) {
|
|
337
|
+
const drop = new Set();
|
|
338
|
+
for (const position of superseded) {
|
|
339
|
+
if (!Number.isSafeInteger(position) || position < preludeCount || position >= input.length)
|
|
340
|
+
throw Object.assign(new Error("Native compaction superseded-item provenance is invalid"), { code: "LCX_COMPACTION_PRELUDE_PROVENANCE_INVALID" });
|
|
341
|
+
drop.add(position);
|
|
342
|
+
}
|
|
343
|
+
return input.slice(preludeCount).filter((_, offset) => !drop.has(preludeCount + offset));
|
|
344
|
+
}
|
|
324
345
|
/**
|
|
325
346
|
* @param {CreateCheckpointOptions} options
|
|
326
347
|
* @returns {Promise<NativeCheckpointV5>}
|
|
327
348
|
*/
|
|
328
|
-
export async function createNativeCheckpointBlock({ ctx, session, route, result, input = [], ephemeralPreludeItemCount = 0, imageMap, retentionOptions = {}, }) {
|
|
349
|
+
export async function createNativeCheckpointBlock({ ctx, session, route, result, input = [], ephemeralPreludeItemCount = 0, supersededItemIndices = [], imageMap, retentionOptions = {}, }) {
|
|
329
350
|
const compactionId = await activeCompactionId(ctx, session);
|
|
330
351
|
if (!compactionId) {
|
|
331
352
|
const error = new Error("Native compaction could not correlate the active DSH compaction transaction");
|
|
@@ -337,7 +358,7 @@ export async function createNativeCheckpointBlock({ ctx, session, route, result,
|
|
|
337
358
|
ephemeralPreludeItemCount > input.length) {
|
|
338
359
|
throw Object.assign(new Error("Native compaction prelude provenance is invalid"), { code: "LCX_COMPACTION_PRELUDE_PROVENANCE_INVALID" });
|
|
339
360
|
}
|
|
340
|
-
const retention = retainedConversationPlan(input
|
|
361
|
+
const retention = retainedConversationPlan(dropSupersededItems(input, ephemeralPreludeItemCount, supersededItemIndices), retentionOptions);
|
|
341
362
|
/** @type {NativeOutputItem[]} */
|
|
342
363
|
const nativeOutput = persistNativeImageReferences([...retention.items, structuredClone(result.compaction)], imageMap ?? new Map());
|
|
343
364
|
return {
|
|
@@ -689,6 +710,22 @@ function groupMessages(messages) {
|
|
|
689
710
|
}
|
|
690
711
|
return groups;
|
|
691
712
|
}
|
|
713
|
+
/**
|
|
714
|
+
* A shadowed `system/message` (source `system-prompt`) is a full system prompt snapshot DSH appended
|
|
715
|
+
* when the prompt changed on an "in-history" route. Portable replay is only used when the checkpoint
|
|
716
|
+
* cannot be replayed natively (fork, route or model migration), and the request that follows always
|
|
717
|
+
* carries a head rendered with the current prompt, so every snapshot in the shadowed range is
|
|
718
|
+
* superseded: replaying it, even as user text, would put stale instructions (for example plan-mode
|
|
719
|
+
* policy that was switched off) back in front of the model.
|
|
720
|
+
*
|
|
721
|
+
* Only messages DSH itself marks as system-prompt snapshots are dropped. The head is never inside a
|
|
722
|
+
* compaction range, and a Session V3 log (where later system messages were ordinary context) cannot
|
|
723
|
+
* reach this path: LCX refuses V3 checkpoints before transport. Other system-role messages without that
|
|
724
|
+
* source keep the previous ordinary-context mapping.
|
|
725
|
+
*/
|
|
726
|
+
export function withoutSupersededPromptSnapshots(messages) {
|
|
727
|
+
return messages.filter((message) => !(message.role === "system" && message.source?.kind === "system-prompt"));
|
|
728
|
+
}
|
|
692
729
|
/**
|
|
693
730
|
* @param {Session} session
|
|
694
731
|
* @param {string} compactionId
|
|
@@ -703,7 +740,8 @@ export async function portableMessagesForCheckpoint(ctx, session, compactionId,
|
|
|
703
740
|
? configuredMaxChars
|
|
704
741
|
: 80_000;
|
|
705
742
|
const maxTokens = portableTokenCeiling(maxChars) ?? 1;
|
|
706
|
-
|
|
743
|
+
// Superseded prompt snapshots are removed before grouping so they never consume the replay budget.
|
|
744
|
+
const expanded = withoutSupersededPromptSnapshots(await shadowedMessagesForCheckpoint(ctx, session, compactionId));
|
|
707
745
|
if (expanded.length === 0)
|
|
708
746
|
return [];
|
|
709
747
|
const groups = groupMessages(expanded);
|
package/lib/responses-stream.js
CHANGED
|
@@ -104,7 +104,8 @@ export function managedFailure(error, signal) {
|
|
|
104
104
|
else if (sourceCodes.has("LCX_GROK_NATIVE_PROTOCOL_ERROR"))
|
|
105
105
|
code = "GROK_NATIVE_PROTOCOL_ERROR";
|
|
106
106
|
else if (sourceCodes.has("LCX_RESPONSES_ROUTE_UNAVAILABLE") ||
|
|
107
|
-
sourceCodes.has("LCX_RESPONSES_MODEL_UNAVAILABLE")
|
|
107
|
+
sourceCodes.has("LCX_RESPONSES_MODEL_UNAVAILABLE") ||
|
|
108
|
+
sourceCodes.has("LCX_SYSTEM_PROMPT_MODE_UNKNOWN"))
|
|
108
109
|
code = "NO_ADAPTER";
|
|
109
110
|
else if (sourceCodes.has("LCX_INSUFFICIENT_QUOTA"))
|
|
110
111
|
code = "INSUFFICIENT_QUOTA";
|
|
@@ -143,7 +144,9 @@ export function managedFailure(error, signal) {
|
|
|
143
144
|
AUTH: "Responses request was rejected by authentication",
|
|
144
145
|
INSUFFICIENT_QUOTA: "服务商额度不足或未满足请求预留额度,请检查中转额度(并非 API 密钥无效) / Provider quota is insufficient for this request",
|
|
145
146
|
UNSUPPORTED_OPTION: "LCX Responses does not support this request option",
|
|
146
|
-
NO_ADAPTER: "
|
|
147
|
+
NO_ADAPTER: sourceCodes.has("LCX_SYSTEM_PROMPT_MODE_UNKNOWN")
|
|
148
|
+
? "LCX could not read the route's model information, so in-history system prompt updates cannot be sent safely; retry once the route is available"
|
|
149
|
+
: "LCX could not resolve the selected Responses route",
|
|
147
150
|
RATE_LIMIT: "Responses provider rate limit was reached",
|
|
148
151
|
SERVER: "Responses provider returned a server failure",
|
|
149
152
|
INVALID_REQUEST: sourceCodes.has("LCX_CHECKPOINT_UNSUPPORTED")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-lcx-codex",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1-pre.1",
|
|
4
4
|
"description": "Model-scoped DSH plugin: GPT Responses lifecycle, Native V2 compaction and Hosted/Alpha Search; Grok native Web/X Search",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"deepseek-harness",
|
|
@@ -62,9 +62,9 @@
|
|
|
62
62
|
}
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@deepseek-ai/dsh": "0.2.
|
|
65
|
+
"@deepseek-ai/dsh": "0.2.1-alpha.2",
|
|
66
66
|
"@earendil-works/pi-ai": "0.87.1",
|
|
67
|
-
"@deepseek-ai/schemastery": "
|
|
67
|
+
"@deepseek-ai/schemastery": "~3.18.5-alpha.1",
|
|
68
68
|
"@types/node": "^22.20.0",
|
|
69
69
|
"@types/react": "~18.3.1",
|
|
70
70
|
"esbuild": "^0.28.2",
|
|
@@ -72,31 +72,31 @@
|
|
|
72
72
|
"typescript": "7.0.2"
|
|
73
73
|
},
|
|
74
74
|
"peerDependencies": {
|
|
75
|
-
"@deepseek-ai/cordis": "
|
|
76
|
-
"@deepseek-ai/cordis-plugin-loader": "
|
|
77
|
-
"@deepseek-ai/dsh-agent": ">=0.2.
|
|
78
|
-
"@deepseek-ai/dsh-attachment": ">=0.2.
|
|
79
|
-
"@deepseek-ai/dsh-client-locale": ">=0.2.
|
|
80
|
-
"@deepseek-ai/dsh-client-modules": ">=0.2.
|
|
81
|
-
"@deepseek-ai/dsh-client-store": ">=0.2.
|
|
82
|
-
"@deepseek-ai/dsh-client-ui-chat": ">=0.2.
|
|
83
|
-
"@deepseek-ai/dsh-client-ui-conversation": ">=0.2.
|
|
84
|
-
"@deepseek-ai/dsh-client-ui-plugin-manager": ">=0.2.
|
|
85
|
-
"@deepseek-ai/dsh-client-ui-settings": ">=0.2.
|
|
86
|
-
"@deepseek-ai/dsh-compaction": ">=0.2.
|
|
87
|
-
"@deepseek-ai/dsh-credentials": ">=0.2.
|
|
88
|
-
"@deepseek-ai/dsh-fs": ">=0.2.
|
|
89
|
-
"@deepseek-ai/dsh-llm": ">=0.2.
|
|
90
|
-
"@deepseek-ai/dsh-session": ">=0.2.
|
|
91
|
-
"@deepseek-ai/dsh-session-query": ">=0.2.
|
|
92
|
-
"@deepseek-ai/dsh-settings": ">=0.2.
|
|
93
|
-
"@deepseek-ai/dsh-tool-web": ">=0.2.
|
|
94
|
-
"@deepseek-ai/dsh-tools": ">=0.2.
|
|
95
|
-
"@deepseek-ai/dsh-web": ">=0.2.
|
|
96
|
-
"@deepseek-ai/schemastery": "
|
|
75
|
+
"@deepseek-ai/cordis": ">=4.0.5-alpha.1",
|
|
76
|
+
"@deepseek-ai/cordis-plugin-loader": ">=1.0.6-alpha.1",
|
|
77
|
+
"@deepseek-ai/dsh-agent": ">=0.2.1-alpha.2",
|
|
78
|
+
"@deepseek-ai/dsh-attachment": ">=0.2.1-alpha.2",
|
|
79
|
+
"@deepseek-ai/dsh-client-locale": ">=0.2.1-alpha.2",
|
|
80
|
+
"@deepseek-ai/dsh-client-modules": ">=0.2.1-alpha.2",
|
|
81
|
+
"@deepseek-ai/dsh-client-store": ">=0.2.1-alpha.2",
|
|
82
|
+
"@deepseek-ai/dsh-client-ui-chat": ">=0.2.1-alpha.2",
|
|
83
|
+
"@deepseek-ai/dsh-client-ui-conversation": ">=0.2.1-alpha.2",
|
|
84
|
+
"@deepseek-ai/dsh-client-ui-plugin-manager": ">=0.2.1-alpha.2",
|
|
85
|
+
"@deepseek-ai/dsh-client-ui-settings": ">=0.2.1-alpha.2",
|
|
86
|
+
"@deepseek-ai/dsh-compaction": ">=0.2.1-alpha.2",
|
|
87
|
+
"@deepseek-ai/dsh-credentials": ">=0.2.1-alpha.2",
|
|
88
|
+
"@deepseek-ai/dsh-fs": ">=0.2.1-alpha.2",
|
|
89
|
+
"@deepseek-ai/dsh-llm": ">=0.2.1-alpha.2",
|
|
90
|
+
"@deepseek-ai/dsh-session": ">=0.2.1-alpha.2",
|
|
91
|
+
"@deepseek-ai/dsh-session-query": ">=0.2.1-alpha.2",
|
|
92
|
+
"@deepseek-ai/dsh-settings": ">=0.2.1-alpha.2",
|
|
93
|
+
"@deepseek-ai/dsh-tool-web": ">=0.2.1-alpha.2",
|
|
94
|
+
"@deepseek-ai/dsh-tools": ">=0.2.1-alpha.2",
|
|
95
|
+
"@deepseek-ai/dsh-web": ">=0.2.1-alpha.2",
|
|
96
|
+
"@deepseek-ai/schemastery": ">=3.18.5-alpha.1",
|
|
97
97
|
"react": "^18.2.0",
|
|
98
|
-
"@deepseek-ai/dsh-token-meter": ">=0.2.
|
|
99
|
-
"@deepseek-ai/dsh-session-projection": ">=0.2.
|
|
98
|
+
"@deepseek-ai/dsh-token-meter": ">=0.2.1-alpha.2",
|
|
99
|
+
"@deepseek-ai/dsh-session-projection": ">=0.2.1-alpha.2",
|
|
100
100
|
"zod": "^4.5.4"
|
|
101
101
|
},
|
|
102
102
|
"peerDependenciesMeta": {
|
|
@@ -179,9 +179,9 @@
|
|
|
179
179
|
},
|
|
180
180
|
"license": "MIT",
|
|
181
181
|
"lcxCompatibility": {
|
|
182
|
-
"dshInstallRange": ">=0.2.
|
|
183
|
-
"verifiedDsh": "0.2.
|
|
184
|
-
"verifiedHostPi": "
|
|
182
|
+
"dshInstallRange": ">=0.2.1-alpha.2",
|
|
183
|
+
"verifiedDsh": "0.2.1-alpha.2",
|
|
184
|
+
"verifiedHostPi": "1.1.0",
|
|
185
185
|
"verifiedPluginPi": "0.87.1"
|
|
186
186
|
}
|
|
187
187
|
}
|