Skip to content

Commit 641aa67

Browse files
committed
fix(llm): 消息补 source 字段——严格 provider 下不再于序列化阶段抛 TypeError(#189)
dsh-llm 的消息契约要求每条消息带 source(lib/types/message.d.ts:119-129, 「Required source fields supplied by the producer」)。mneme 手拼的 13 处 LLM 消息缺该字段,遇到会读 message.source.kind 的 provider 适配器 (如 dsh-commandcode-provider 的 messagesToCC)时,请求在序列化阶段同步抛 TypeError —— 0–8ms 失败且不发出任何网络请求。内置 dsh-llm-deepseek 从不读 该字段,所以这个契约违背长期潜伏,只在更换 provider 时一次性暴露。 按契约补 source: { kind: "plugin", plugin: "dsh-mneme" },不改 content 形状、 不新增 import(peer 0.1.0-rc.8 未导出 createSystemMessage,用字面量才能同时 兼容 rc.6 / rc.8 / 2.0.x)。 覆盖 13 处:dream.js ×2(consolidation / dream summary)、dream/sleep.js ×2 (conflict / pattern)、entities/extractor.js、summarize.js(system 消息 + createUserMessage 调用)、api.js(连接探测用的 system 消息)。 新增 test/llm-message-source.test.js:4 个用例以严格桩驱动真实管线 (dream / summarize / sleep / entity extraction),逐条断言 message.source.kind === "plugin"。
1 parent 00c67ea commit 641aa67

11 files changed

Lines changed: 203 additions & 26 deletions

File tree

‎dsh-mneme/lib/api.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ export function createApi(ctx, service, settings, commands, embedder, semantic =
330330
// 按钮无放大风险。
331331
maxTokens: 1024,
332332
...(reasoningEffort && reasoningEffort !== "none" ? { reasoningEffort } : {}),
333-
messages: [{ role: "system", content: [{ type: "text", text: "Reply with exactly one word: ok" }] }]
333+
messages: [{ role: "system", content: [{ type: "text", text: "Reply with exactly one word: ok" }], source: { kind: "plugin", plugin: "dsh-mneme" } }]
334334
})) {
335335
if (chunk.type === "text-delta" && typeof chunk.text === "string") reply += chunk.text;
336336
if (chunk.type === "finish" && (chunk.reason?.kind === "error" || chunk.reason?.kind === "aborted")) {

‎dsh-mneme/lib/dream.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -910,8 +910,8 @@ export function createDreamScheduler({ onRun, thresholdCount = 10, thresholdChar
910910
maxTokens: config.dreamMaxTokens ?? 4096,
911911
...(withEffort && effort ? { reasoningEffort: effort } : {}),
912912
messages: [
913-
{ role: "system", content: [{ type: "text", text: consolidationPrompt }] },
914-
{ role: "user", content: [{ type: "text", text: listText }] }
913+
{ role: "system", content: [{ type: "text", text: consolidationPrompt }], source: { kind: "plugin", plugin: "dsh-mneme" } },
914+
{ role: "user", content: [{ type: "text", text: listText }], source: { kind: "plugin", plugin: "dsh-mneme" } }
915915
]
916916
}, reportUsage, (reason) => { streamFailure = describeStreamFailure(reason); }));
917917
};
@@ -1130,8 +1130,8 @@ export function createDreamScheduler({ onRun, thresholdCount = 10, thresholdChar
11301130
maxTokens: config.dreamMaxTokens ?? 2048,
11311131
...(withEffort && effort ? { reasoningEffort: effort } : {}),
11321132
messages: [
1133-
{ role: "system", content: [{ type: "text", text: STR.prompts.dreamSummary[language] }] },
1134-
{ role: "user", content: [{ type: "text", text: service.all().filter((m) => !m.archived && m.type !== "summary").map((m) => `- ${m.title}: ${m.content}`).join("\n") }] }
1133+
{ role: "system", content: [{ type: "text", text: STR.prompts.dreamSummary[language] }], source: { kind: "plugin", plugin: "dsh-mneme" } },
1134+
{ role: "user", content: [{ type: "text", text: service.all().filter((m) => !m.archived && m.type !== "summary").map((m) => `- ${m.title}: ${m.content}`).join("\n") }], source: { kind: "plugin", plugin: "dsh-mneme" } }
11351135
]
11361136
}, reportUsage, (reason) => { summaryStreamFailure = describeStreamFailure(reason); }));
11371137
};

‎dsh-mneme/lib/dream/sleep.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ async function phaseConflicts(ctx, service, config, logger, runId, semantic = nu
239239
maxTokens: 2048,
240240
...(withEffort && sleepEffort ? { reasoningEffort: sleepEffort } : {}),
241241
messages: [
242-
{ role: "system", content: [{ type: "text", text: conflictPrompt }] },
243-
{ role: "user", content: [{ type: "text", text: listText }] }
242+
{ role: "system", content: [{ type: "text", text: conflictPrompt }], source: { kind: "plugin", plugin: "dsh-mneme" } },
243+
{ role: "user", content: [{ type: "text", text: listText }], source: { kind: "plugin", plugin: "dsh-mneme" } }
244244
]
245245
}, (reason) => { conflictStreamFailure = describeStreamFailure(reason); });
246246
};
@@ -390,8 +390,8 @@ async function phasePatterns(ctx, service, config, logger, runId, signal = null)
390390
maxTokens: 2048,
391391
...(withEffort && sleepEffort ? { reasoningEffort: sleepEffort } : {}),
392392
messages: [
393-
{ role: "system", content: [{ type: "text", text: STR.prompts.pattern[language].replace("N", String(maxPatterns)) }] },
394-
{ role: "user", content: [{ type: "text", text: listText }] }
393+
{ role: "system", content: [{ type: "text", text: STR.prompts.pattern[language].replace("N", String(maxPatterns)) }], source: { kind: "plugin", plugin: "dsh-mneme" } },
394+
{ role: "user", content: [{ type: "text", text: listText }], source: { kind: "plugin", plugin: "dsh-mneme" } }
395395
]
396396
}, (reason) => { patternStreamFailure = describeStreamFailure(reason); });
397397
};

‎dsh-mneme/lib/entities/extractor.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ export async function extractEntities(memory, { store, config, callLLM, logger }
150150
const userText = buildUserMessage(memory.content);
151151

152152
const messages = [
153-
{ role: "system", content: [{ type: "text", text: systemPrompt }] },
154-
{ role: "user", content: [{ type: "text", text: userText }] }
153+
{ role: "system", content: [{ type: "text", text: systemPrompt }], source: { kind: "plugin", plugin: "dsh-mneme" } },
154+
{ role: "user", content: [{ type: "text", text: userText }], source: { kind: "plugin", plugin: "dsh-mneme" } }
155155
];
156156

157157
// Issue #109: optional provider/model override + reasoning effort are

‎dsh-mneme/lib/summarize.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ function collectMessages(session, maxChars = 8000, language = "zh") {
144144
break;
145145
}
146146
}
147-
return lines.length ? [createUserMessage({ content: [{ type: "text", text: trim(lines.join("\n"), maxChars) }] })] : [];
147+
return lines.length ? [createUserMessage({ content: [{ type: "text", text: trim(lines.join("\n"), maxChars) }], source: { kind: "plugin", plugin: "dsh-mneme" } })] : [];
148148
}
149149

150150
// ── 智能调速器(429 保护)─────────────────────────────────────────────
@@ -265,7 +265,7 @@ export function createSummarizer(ctx, service, config) {
265265
model: route.model,
266266
purpose: "summarization",
267267
messages: [
268-
{ role: "system", content: [{ type: "text", text: config.codingRetrospect ? STR.prompts.codingSummary[langOf(config)] : STR.prompts.summary[langOf(config)] }] },
268+
{ role: "system", content: [{ type: "text", text: config.codingRetrospect ? STR.prompts.codingSummary[langOf(config)] : STR.prompts.summary[langOf(config)] }], source: { kind: "plugin", plugin: "dsh-mneme" } },
269269
...messages
270270
],
271271
signal: controller.signal

‎dsh-mneme/src/api.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ export function createApi(ctx, service, settings, commands, embedder, semantic =
330330
// 按钮无放大风险。
331331
maxTokens: 1024,
332332
...(reasoningEffort && reasoningEffort !== "none" ? { reasoningEffort } : {}),
333-
messages: [{ role: "system", content: [{ type: "text", text: "Reply with exactly one word: ok" }] }]
333+
messages: [{ role: "system", content: [{ type: "text", text: "Reply with exactly one word: ok" }], source: { kind: "plugin", plugin: "dsh-mneme" } }]
334334
})) {
335335
if (chunk.type === "text-delta" && typeof chunk.text === "string") reply += chunk.text;
336336
if (chunk.type === "finish" && (chunk.reason?.kind === "error" || chunk.reason?.kind === "aborted")) {

‎dsh-mneme/src/dream.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -910,8 +910,8 @@ export function createDreamScheduler({ onRun, thresholdCount = 10, thresholdChar
910910
maxTokens: config.dreamMaxTokens ?? 4096,
911911
...(withEffort && effort ? { reasoningEffort: effort } : {}),
912912
messages: [
913-
{ role: "system", content: [{ type: "text", text: consolidationPrompt }] },
914-
{ role: "user", content: [{ type: "text", text: listText }] }
913+
{ role: "system", content: [{ type: "text", text: consolidationPrompt }], source: { kind: "plugin", plugin: "dsh-mneme" } },
914+
{ role: "user", content: [{ type: "text", text: listText }], source: { kind: "plugin", plugin: "dsh-mneme" } }
915915
]
916916
}, reportUsage, (reason) => { streamFailure = describeStreamFailure(reason); }));
917917
};
@@ -1130,8 +1130,8 @@ export function createDreamScheduler({ onRun, thresholdCount = 10, thresholdChar
11301130
maxTokens: config.dreamMaxTokens ?? 2048,
11311131
...(withEffort && effort ? { reasoningEffort: effort } : {}),
11321132
messages: [
1133-
{ role: "system", content: [{ type: "text", text: STR.prompts.dreamSummary[language] }] },
1134-
{ role: "user", content: [{ type: "text", text: service.all().filter((m) => !m.archived && m.type !== "summary").map((m) => `- ${m.title}: ${m.content}`).join("\n") }] }
1133+
{ role: "system", content: [{ type: "text", text: STR.prompts.dreamSummary[language] }], source: { kind: "plugin", plugin: "dsh-mneme" } },
1134+
{ role: "user", content: [{ type: "text", text: service.all().filter((m) => !m.archived && m.type !== "summary").map((m) => `- ${m.title}: ${m.content}`).join("\n") }], source: { kind: "plugin", plugin: "dsh-mneme" } }
11351135
]
11361136
}, reportUsage, (reason) => { summaryStreamFailure = describeStreamFailure(reason); }));
11371137
};

‎dsh-mneme/src/dream/sleep.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ async function phaseConflicts(ctx, service, config, logger, runId, semantic = nu
239239
maxTokens: 2048,
240240
...(withEffort && sleepEffort ? { reasoningEffort: sleepEffort } : {}),
241241
messages: [
242-
{ role: "system", content: [{ type: "text", text: conflictPrompt }] },
243-
{ role: "user", content: [{ type: "text", text: listText }] }
242+
{ role: "system", content: [{ type: "text", text: conflictPrompt }], source: { kind: "plugin", plugin: "dsh-mneme" } },
243+
{ role: "user", content: [{ type: "text", text: listText }], source: { kind: "plugin", plugin: "dsh-mneme" } }
244244
]
245245
}, (reason) => { conflictStreamFailure = describeStreamFailure(reason); });
246246
};
@@ -390,8 +390,8 @@ async function phasePatterns(ctx, service, config, logger, runId, signal = null)
390390
maxTokens: 2048,
391391
...(withEffort && sleepEffort ? { reasoningEffort: sleepEffort } : {}),
392392
messages: [
393-
{ role: "system", content: [{ type: "text", text: STR.prompts.pattern[language].replace("N", String(maxPatterns)) }] },
394-
{ role: "user", content: [{ type: "text", text: listText }] }
393+
{ role: "system", content: [{ type: "text", text: STR.prompts.pattern[language].replace("N", String(maxPatterns)) }], source: { kind: "plugin", plugin: "dsh-mneme" } },
394+
{ role: "user", content: [{ type: "text", text: listText }], source: { kind: "plugin", plugin: "dsh-mneme" } }
395395
]
396396
}, (reason) => { patternStreamFailure = describeStreamFailure(reason); });
397397
};

‎dsh-mneme/src/entities/extractor.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ export async function extractEntities(memory, { store, config, callLLM, logger }
150150
const userText = buildUserMessage(memory.content);
151151

152152
const messages = [
153-
{ role: "system", content: [{ type: "text", text: systemPrompt }] },
154-
{ role: "user", content: [{ type: "text", text: userText }] }
153+
{ role: "system", content: [{ type: "text", text: systemPrompt }], source: { kind: "plugin", plugin: "dsh-mneme" } },
154+
{ role: "user", content: [{ type: "text", text: userText }], source: { kind: "plugin", plugin: "dsh-mneme" } }
155155
];
156156

157157
// Issue #109: optional provider/model override + reasoning effort are

‎dsh-mneme/src/summarize.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ function collectMessages(session, maxChars = 8000, language = "zh") {
144144
break;
145145
}
146146
}
147-
return lines.length ? [createUserMessage({ content: [{ type: "text", text: trim(lines.join("\n"), maxChars) }] })] : [];
147+
return lines.length ? [createUserMessage({ content: [{ type: "text", text: trim(lines.join("\n"), maxChars) }], source: { kind: "plugin", plugin: "dsh-mneme" } })] : [];
148148
}
149149

150150
// ── 智能调速器(429 保护)─────────────────────────────────────────────
@@ -265,7 +265,7 @@ export function createSummarizer(ctx, service, config) {
265265
model: route.model,
266266
purpose: "summarization",
267267
messages: [
268-
{ role: "system", content: [{ type: "text", text: config.codingRetrospect ? STR.prompts.codingSummary[langOf(config)] : STR.prompts.summary[langOf(config)] }] },
268+
{ role: "system", content: [{ type: "text", text: config.codingRetrospect ? STR.prompts.codingSummary[langOf(config)] : STR.prompts.summary[langOf(config)] }], source: { kind: "plugin", plugin: "dsh-mneme" } },
269269
...messages
270270
],
271271
signal: controller.signal

0 commit comments

Comments
 (0)