dsh-plugin-om 0.0.28 → 0.0.29
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 +1 -1
- package/dist/compaction-log.d.ts +12 -8
- package/dist/compaction-log.d.ts.map +1 -1
- package/dist/index.mjs +55 -12
- package/dist/summarize.d.ts +2 -2
- package/dist/summarize.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
## 功能
|
|
8
8
|
|
|
9
9
|
- **自动压缩**:仅主会话,在 agent/pre-step 阻塞串行执行。净压力达到 `observeThresholdTokens` 后再累计 `tailMessageCount` 条完整消息时,把触发点前的全部消息摘要为新 `<history>` 块并精确替换对应消息区间;全部 `<history>` 块 token 合计达到 `reflectThresholdTokens` 时把全部块内文拼合为单个 `<history>` 块送入摘要,合并为一条更紧凑的摘要。待定标记以 log-only 会话事件持久化,重启后从日志恢复
|
|
10
|
-
- **输出容错**:摘要输出按 `<history>` 标签定位,整块非法时按条目标签模糊提取并重建为合法块。重试全部耗尽后拒绝当前 step
|
|
10
|
+
- **输出容错**:摘要输出按 `<history>` 标签定位,整块非法时按条目标签模糊提取并重建为合法块。重试全部耗尽后拒绝当前 step;每次实际发出的摘要调用无论成功失败都把完整提示词与模型完整输出(thinking、文本、工具调用)即时落盘为 one-shot 诊断子会话
|
|
11
11
|
- **降级容错**:systemPrompt 或 tokenMeter 服务异常时按 0 计继续压缩,问题通过 console 输出与 log-only 会话事件上报,同会话同一问题至多一条
|
|
12
12
|
- **recall 工具**:按完整消息 index 区间回看原始会话,含被压缩内容,图片附件随结果保留
|
|
13
13
|
- **recall-semantic 工具**:本地嵌入模型 paraphrase-multilingual-MiniLM-L12-v2 按语义检索全部完整消息,只匹配文本,纯图片消息不进候选池
|
package/dist/compaction-log.d.ts
CHANGED
|
@@ -1,31 +1,35 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 压缩调用日志落盘:摘要 run 的每次 LLM 调用(每次尝试,无论成功失败)完成后,
|
|
3
|
-
*
|
|
3
|
+
* 把该次尝试的完整提示词与模型完整输出原样落盘为一个 one-shot 诊断子会话
|
|
4
4
|
* (header origin 'subagent' + 首事件 subagent/descriptor),使其以 subagent 形式
|
|
5
5
|
* 出现在宿主子代理列表中,便于查验每次调用的完整会话。导出 recordCompactionAttempt /
|
|
6
6
|
* SummaryAttemptRecord / compactionLogLabel / COMPACTION_LOG_PROVIDER。
|
|
7
7
|
*
|
|
8
8
|
* - 子会话内容零加工:一对 user/message(实际提示词全文,含 <history> 块)
|
|
9
|
-
* + assistant/message
|
|
10
|
-
*
|
|
9
|
+
* + assistant/message(完整内容块:thinking/reasoning、文本输出、工具调用,
|
|
10
|
+
* 异常/中止时为已收集的部分输出),不插入任何额外消息;
|
|
11
|
+
* 成败与原因不进子会话,由调用方写入主会话日志并关联子会话 id
|
|
11
12
|
* - 落盘自身绝不抛错:任何失败仅 logger.warn 并返回 undefined,不影响压缩流程
|
|
12
13
|
*/
|
|
14
|
+
import type { ToolCallBlock } from '@deepseek-ai/dsh-llm';
|
|
13
15
|
import type { Context, Session } from './types.ts';
|
|
14
16
|
import { type RoutedTarget } from './utils.ts';
|
|
15
17
|
/** 诊断子会话的 descriptor provider(宿主子代理列表识别用)。 */
|
|
16
18
|
export declare const COMPACTION_LOG_PROVIDER = "om-compaction-log";
|
|
17
|
-
/** 一次摘要尝试的完整记录:prompt=实际提示词全文(含 <history> 块),rawOutput
|
|
19
|
+
/** 一次摘要尝试的完整记录:prompt=实际提示词全文(含 <history> 块),rawOutput=模型原始文本输出;reasoning=模型 thinking 输出(无则省略),toolCalls=模型请求的工具调用(无则省略)。 */
|
|
18
20
|
export type SummaryAttemptRecord = {
|
|
19
21
|
prompt: string;
|
|
20
22
|
rawOutput: string;
|
|
23
|
+
reasoning?: string;
|
|
24
|
+
toolCalls?: ToolCallBlock[];
|
|
21
25
|
};
|
|
22
|
-
/** 诊断子会话 label
|
|
26
|
+
/** 诊断子会话 label:`OM会话-<阶段>`,有重试时追加 `-重试N`(N = 尝试序号 - 1,首次不写)。 */
|
|
23
27
|
export declare function compactionLogLabel(phase: 'observe' | 'reflect' | undefined, attemptNo: number): string;
|
|
24
28
|
/**
|
|
25
29
|
* 把一次摘要尝试落盘为诊断子会话:ctx.sessions.create 创建子会话(header origin
|
|
26
30
|
* 'subagent'、parentSession 指向主会话、delegationDepth = 父 + 1、cwd 继承主会话),
|
|
27
|
-
* 追加 one-shot descriptor(provider om-compaction-log,label
|
|
28
|
-
* 原样追加「提示词 +
|
|
31
|
+
* 追加 one-shot descriptor(provider om-compaction-log,label 为 `OM会话-<阶段>`,重试时追加 `-重试N`),
|
|
32
|
+
* 原样追加「提示词 + 完整输出内容块(thinking/reasoning、文本、工具调用)」消息组,flush 持久化检查点,返回子会话 id。落盘自身
|
|
29
33
|
* 绝不抛错:任何失败仅 logger.warn 并返回 undefined(不影响压缩流程)。
|
|
30
34
|
*/
|
|
31
35
|
export declare function recordCompactionAttempt(ctx: Context, parentSession: Session, options: {
|
|
@@ -33,7 +37,7 @@ export declare function recordCompactionAttempt(ctx: Context, parentSession: Ses
|
|
|
33
37
|
phase: 'observe' | 'reflect' | undefined;
|
|
34
38
|
/** 摘要调用的路由目标(assistant/message 的 model 来源标记)。 */
|
|
35
39
|
target: RoutedTarget;
|
|
36
|
-
/** 本次尝试的完整记录(提示词 +
|
|
40
|
+
/** 本次尝试的完整记录(提示词 + thinking + 文本输出 + 工具调用)。 */
|
|
37
41
|
attempt: SummaryAttemptRecord;
|
|
38
42
|
/** 尝试序号(1 起,label 与消息 step 标注用)。 */
|
|
39
43
|
attemptNo: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compaction-log.d.ts","sourceRoot":"","sources":["../src/compaction-log.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"compaction-log.d.ts","sourceRoot":"","sources":["../src/compaction-log.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAoB,aAAa,EAAe,MAAM,sBAAsB,CAAC;AAKzF,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,KAAK,YAAY,EAAQ,MAAM,YAAY,CAAC;AAErD,8CAA8C;AAC9C,eAAO,MAAM,uBAAuB,sBAAsB,CAAC;AAE3D,6HAA6H;AAC7H,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,aAAa,EAAE,CAAC;CAC7B,CAAC;AASF,gEAAgE;AAChE,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,EACxC,SAAS,EAAE,MAAM,GAChB,MAAM,CAGR;AAuCD;;;;;;GAMG;AACH,wBAAsB,uBAAuB,CAC3C,GAAG,EAAE,OAAO,EACZ,aAAa,EAAE,OAAO,EACtB,OAAO,EAAE;IACP,8BAA8B;IAC9B,KAAK,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;IACzC,iDAAiD;IACjD,MAAM,EAAE,YAAY,CAAC;IACrB,+CAA+C;IAC/C,OAAO,EAAE,oBAAoB,CAAC;IAC9B,oCAAoC;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,uCAAuC;IACvC,KAAK,EAAE,OAAO,CAAC;CAChB,GACA,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CA+B7B"}
|
package/dist/index.mjs
CHANGED
|
@@ -7539,11 +7539,12 @@ function phaseLabel(phase) {
|
|
|
7539
7539
|
if (phase === "reflect") return "反思";
|
|
7540
7540
|
return "压缩";
|
|
7541
7541
|
}
|
|
7542
|
-
/** 诊断子会话 label
|
|
7542
|
+
/** 诊断子会话 label:`OM会话-<阶段>`,有重试时追加 `-重试N`(N = 尝试序号 - 1,首次不写)。 */
|
|
7543
7543
|
function compactionLogLabel(phase, attemptNo) {
|
|
7544
|
-
|
|
7544
|
+
const retry = attemptNo > 1 ? `-重试${attemptNo - 1}` : "";
|
|
7545
|
+
return `OM会话-${phaseLabel(phase)}${retry}`;
|
|
7545
7546
|
}
|
|
7546
|
-
/** 追加一次尝试的「提示词 →
|
|
7547
|
+
/** 追加一次尝试的「提示词 → 完整输出内容块」消息组(surfaceOp append;id 为品牌类型,session.append 运行时校验)。 */
|
|
7547
7548
|
function appendAttemptMessages(child, attempt, step, target) {
|
|
7548
7549
|
const userMessage = {
|
|
7549
7550
|
id: uuid(),
|
|
@@ -7558,13 +7559,20 @@ function appendAttemptMessages(child, attempt, step, target) {
|
|
|
7558
7559
|
}
|
|
7559
7560
|
};
|
|
7560
7561
|
child.append("user/message", userMessage, { surfaceOp: "append" });
|
|
7562
|
+
const content = [];
|
|
7563
|
+
if (attempt.reasoning !== void 0) content.push({
|
|
7564
|
+
type: "reasoning",
|
|
7565
|
+
text: attempt.reasoning
|
|
7566
|
+
});
|
|
7567
|
+
content.push({
|
|
7568
|
+
type: "text",
|
|
7569
|
+
text: attempt.rawOutput
|
|
7570
|
+
});
|
|
7571
|
+
if (attempt.toolCalls !== void 0) content.push(...attempt.toolCalls);
|
|
7561
7572
|
const assistantMessage = {
|
|
7562
7573
|
id: uuid(),
|
|
7563
7574
|
role: "assistant",
|
|
7564
|
-
content
|
|
7565
|
-
type: "text",
|
|
7566
|
-
text: attempt.rawOutput
|
|
7567
|
-
}],
|
|
7575
|
+
content,
|
|
7568
7576
|
source: {
|
|
7569
7577
|
kind: "model",
|
|
7570
7578
|
provider: target.provider,
|
|
@@ -7580,8 +7588,8 @@ function appendAttemptMessages(child, attempt, step, target) {
|
|
|
7580
7588
|
/**
|
|
7581
7589
|
* 把一次摘要尝试落盘为诊断子会话:ctx.sessions.create 创建子会话(header origin
|
|
7582
7590
|
* 'subagent'、parentSession 指向主会话、delegationDepth = 父 + 1、cwd 继承主会话),
|
|
7583
|
-
* 追加 one-shot descriptor(provider om-compaction-log,label
|
|
7584
|
-
* 原样追加「提示词 +
|
|
7591
|
+
* 追加 one-shot descriptor(provider om-compaction-log,label 为 `OM会话-<阶段>`,重试时追加 `-重试N`),
|
|
7592
|
+
* 原样追加「提示词 + 完整输出内容块(thinking/reasoning、文本、工具调用)」消息组,flush 持久化检查点,返回子会话 id。落盘自身
|
|
7585
7593
|
* 绝不抛错:任何失败仅 logger.warn 并返回 undefined(不影响压缩流程)。
|
|
7586
7594
|
*/
|
|
7587
7595
|
async function recordCompactionAttempt(ctx, parentSession, options) {
|
|
@@ -7808,17 +7816,36 @@ function renderMessages(session, seqs, skipReasoning = true) {
|
|
|
7808
7816
|
const serializer = new import_lib.XMLSerializer();
|
|
7809
7817
|
return `<${HISTORY_TAG}>\n${entries.map((el) => serializer.serializeToString(el)).join("\n")}\n</${HISTORY_TAG}>`;
|
|
7810
7818
|
}
|
|
7811
|
-
/**
|
|
7819
|
+
/** 流收集器:提取 thinking + 文本输出 + 工具调用 + usage + finish(不依赖宿主 BlockAssembler)。 */
|
|
7812
7820
|
var StreamCollector = class {
|
|
7813
7821
|
textBuf = "";
|
|
7822
|
+
reasoningBuf = "";
|
|
7823
|
+
/** tool-call-delta 按 index 聚合(id/name 首次给定后固定,arguments 增量拼接)。 */
|
|
7824
|
+
toolCallParts = /* @__PURE__ */ new Map();
|
|
7814
7825
|
_usage;
|
|
7815
7826
|
_finish;
|
|
7816
|
-
/** 喂入一个流 chunk
|
|
7827
|
+
/** 喂入一个流 chunk(消费 reasoning/文本/工具调用/usage/finish,其余忽略)。 */
|
|
7817
7828
|
push(chunk) {
|
|
7818
7829
|
switch (chunk.type) {
|
|
7819
7830
|
case "text-delta":
|
|
7820
7831
|
this.textBuf += chunk.text;
|
|
7821
7832
|
break;
|
|
7833
|
+
case "reasoning-delta":
|
|
7834
|
+
this.reasoningBuf += chunk.text;
|
|
7835
|
+
break;
|
|
7836
|
+
case "tool-call-delta": {
|
|
7837
|
+
let part = this.toolCallParts.get(chunk.index);
|
|
7838
|
+
if (part === void 0) {
|
|
7839
|
+
part = {
|
|
7840
|
+
id: chunk.id,
|
|
7841
|
+
args: ""
|
|
7842
|
+
};
|
|
7843
|
+
this.toolCallParts.set(chunk.index, part);
|
|
7844
|
+
}
|
|
7845
|
+
if (chunk.name !== void 0) part.name = chunk.name;
|
|
7846
|
+
part.args += chunk.argumentsDelta;
|
|
7847
|
+
break;
|
|
7848
|
+
}
|
|
7822
7849
|
case "usage":
|
|
7823
7850
|
this._usage = chunk.usage;
|
|
7824
7851
|
break;
|
|
@@ -7829,6 +7856,20 @@ var StreamCollector = class {
|
|
|
7829
7856
|
get text() {
|
|
7830
7857
|
return this.textBuf;
|
|
7831
7858
|
}
|
|
7859
|
+
/** thinking 输出(reasoning-delta 拼接;无则 undefined)。 */
|
|
7860
|
+
get reasoning() {
|
|
7861
|
+
return this.reasoningBuf === "" ? void 0 : this.reasoningBuf;
|
|
7862
|
+
}
|
|
7863
|
+
/** 模型请求的工具调用(按 index 流序还原为完整 tool-call 块;无则 undefined)。 */
|
|
7864
|
+
get toolCalls() {
|
|
7865
|
+
if (this.toolCallParts.size === 0) return void 0;
|
|
7866
|
+
return [...this.toolCallParts.entries()].sort(([a], [b]) => a - b).map(([, part]) => ({
|
|
7867
|
+
type: "tool-call",
|
|
7868
|
+
id: part.id,
|
|
7869
|
+
name: part.name ?? "",
|
|
7870
|
+
arguments: part.args
|
|
7871
|
+
}));
|
|
7872
|
+
}
|
|
7832
7873
|
/** 摘要 token usage(无则 undefined)。 */
|
|
7833
7874
|
get usage() {
|
|
7834
7875
|
return this._usage;
|
|
@@ -8138,7 +8179,9 @@ async function runSummarySubagent(ctx, agent, instruction, contextText, maxToken
|
|
|
8138
8179
|
target,
|
|
8139
8180
|
attempt: {
|
|
8140
8181
|
prompt,
|
|
8141
|
-
rawOutput: collector.text
|
|
8182
|
+
rawOutput: collector.text,
|
|
8183
|
+
...collector.reasoning === void 0 ? {} : { reasoning: collector.reasoning },
|
|
8184
|
+
...collector.toolCalls === void 0 ? {} : { toolCalls: collector.toolCalls }
|
|
8142
8185
|
},
|
|
8143
8186
|
attemptNo: attempt,
|
|
8144
8187
|
debug
|
package/dist/summarize.d.ts
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
* 模糊提取重建 / 无 reasoning / index 连续),失败按 maxAttempts 重试;每次尝试的
|
|
9
9
|
* 结果或报错始终写入日志(成功 info / 失败 warn,失败原因说明具体问题而非解析器
|
|
10
10
|
* 原始报错);全部耗尽返回失败结果(携带最后一次尝试的实际报错)。最终失败
|
|
11
|
-
* (含 signal
|
|
12
|
-
* 原样落盘为诊断子会话,sessionId 随失败结果向上传播进主会话日志。每次请求前
|
|
11
|
+
* (含 signal 中止)时把每次尝试的完整提示词与模型原始输出(含 thinking 与工具调用块)
|
|
12
|
+
* 经 compaction-log.ts 原样落盘为诊断子会话,sessionId 随失败结果向上传播进主会话日志。每次请求前
|
|
13
13
|
* 过全局限流等待门;token usage 归入主会话记录。
|
|
14
14
|
*/
|
|
15
15
|
import type { Agent, Context, Session, TokenUsage } from './types.ts';
|
package/dist/summarize.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"summarize.d.ts","sourceRoot":"","sources":["../src/summarize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;
|
|
1
|
+
{"version":3,"file":"summarize.d.ts","sourceRoot":"","sources":["../src/summarize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AA2BH,OAAO,KAAK,EAAE,KAAK,EAAmB,OAAO,EAAE,OAAO,EAAE,UAAU,EAAe,MAAM,YAAY,CAAC;AACpG,OAAO,EAAE,KAAK,YAAY,EAAQ,MAAM,YAAY,CAAC;AAErD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,aAAa,UAAO,GAAG,MAAM,CA0C/D;AA0CD;;;;;;GAMG;AACH,wBAAgB,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