|
1 | 1 | import { validateDecisions, applyDecisions } from "./dream/decisions.js"; |
2 | 2 | import { clusterMemories, findPotentialConflicts } from "./dream/clustering.js"; |
3 | 3 | import { createHash, randomUUID } from "node:crypto"; |
4 | | -export { validateDecisions, applyDecisions, withEffortFallback, describeStreamFailure }; |
| 4 | +export { validateDecisions, applyDecisions, withEffortFallback, describeStreamFailure, resolveDreamEffort }; |
5 | 5 |
|
6 | 6 |
|
7 | 7 | // Extract the first JSON array from LLM output, tolerating markdown fences, |
@@ -373,6 +373,60 @@ async function withEffortFallback(ctx, effort, attempt, fallback, getStreamError |
373 | 373 | } |
374 | 374 | } |
375 | 375 |
|
| 376 | +/** |
| 377 | + * Resolve the reasoning effort to actually send for a dream/sleep route. |
| 378 | + * |
| 379 | + * Reasoning-effort config that the provider does not accept trips the harness's |
| 380 | + * UNSUPPORTED_REASONING_EFFORT, and the defaultEffort trap makes retrying |
| 381 | + * "without the field" useless: the harness substitutes `reasoning.defaultEffort`, |
| 382 | + * which may itself be unsupported (DSH Desktop volcano-engine adapter declares |
| 383 | + * defaultEffort=low that its model rejects). So instead of blind retries, ask |
| 384 | + * the harness for the model's declared capability and pick a value that is |
| 385 | + * actually accepted — or omit the field entirely when the model declares no |
| 386 | + * reasoning capability at all. |
| 387 | + * |
| 388 | + * @returns a supported effort id, or null when no effort should be sent, or the |
| 389 | + * configured value unchanged when the capability query is unavailable. |
| 390 | + */ |
| 391 | +async function resolveDreamEffort(ctx, route, configuredEffort, logger) { |
| 392 | + if (!configuredEffort || configuredEffort === "none") return null; |
| 393 | + // Capability query unavailable (older harness / minimal mocks): forward the |
| 394 | + // configured value as before — absence of the API proves nothing about the |
| 395 | + // model, and withEffortFallback still guards against rejection. |
| 396 | + if (typeof ctx?.llm?.resolveModelInfo !== "function") return configuredEffort; |
| 397 | + try { |
| 398 | + const info = await ctx.llm.resolveModelInfo(route.provider, route.model); |
| 399 | + const reasoning = info?.reasoning; |
| 400 | + if (!reasoning) { |
| 401 | + // Model declares no reasoning capability: the harness rejects ANY |
| 402 | + // explicit effort for such a model, and omitting the field is safe |
| 403 | + // (no reasoning capability → no defaultEffort substitution). |
| 404 | + logger?.warn?.(`dsh-mneme dream: model ${route.provider}:${route.model} declares no reasoning capability; ignoring configured effort "${configuredEffort}"`); |
| 405 | + return null; |
| 406 | + } |
| 407 | + const supported = reasoning.efforts?.map((effort) => effort.id) ?? []; |
| 408 | + if (supported.includes(configuredEffort)) return configuredEffort; |
| 409 | + // Configured effort unsupported → pick defaultEffort if it is supported, |
| 410 | + // else the first declared effort, so the run never trips |
| 411 | + // UNSUPPORTED_REASONING_EFFORT (nor the defaultEffort trap: we always |
| 412 | + // pass an explicit value, so the harness never falls back to a poison |
| 413 | + // default). |
| 414 | + const picked = reasoning.defaultEffort && supported.includes(reasoning.defaultEffort) |
| 415 | + ? reasoning.defaultEffort |
| 416 | + : supported[0]; |
| 417 | + if (picked) { |
| 418 | + logger?.warn?.(`dsh-mneme dream: model ${route.provider}:${route.model} does not support effort "${configuredEffort}" (supported: ${supported.join(", ")}); using "${picked}"`); |
| 419 | + return picked; |
| 420 | + } |
| 421 | + return null; |
| 422 | + } catch (error) { |
| 423 | + // Capability query failed — forward the configured value; withEffortFallback |
| 424 | + // still retries on rejection as before. |
| 425 | + logger?.warn?.(`dsh-mneme dream: resolveModelInfo failed (${String(error?.message ?? error)}); forwarding effort as configured`); |
| 426 | + return configuredEffort; |
| 427 | + } |
| 428 | +} |
| 429 | + |
376 | 430 | /** |
377 | 431 | * Resolve the LLM route (Issue #25): an explicit plugin config |
378 | 432 | * (dreamProvider/dreamModel) is the user's declared override and wins; the |
@@ -665,7 +719,7 @@ export function createDreamScheduler({ onRun, thresholdCount = 10, thresholdChar |
665 | 719 | // (不带该字段),避免 thinking 模型配置 low/medium 直接整单失败。解析放 |
666 | 720 | // 在 auditError 检查器里、闭包交回主流程,避免二次解析;解析失败同时如实 |
667 | 721 | // 记 audit error 并在日志带原始输出前 300 字节,便于定位"推理吞预算返回空体"。 |
668 | | - const effort = config.dreamReasoningEffort && config.dreamReasoningEffort !== "none" ? config.dreamReasoningEffort : null; |
| 722 | + const effort = await resolveDreamEffort(ctx, route, config.dreamReasoningEffort, logger); |
669 | 723 | let decisions = null; |
670 | 724 | let streamFailure = ""; |
671 | 725 | const runConsolidation = (withEffort) => { |
|
0 commit comments