@thincoder/core 0.11.1 → 0.11.3
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/CHANGELOG.md +64 -2
- package/advisor/compaction.mjs +7 -5
- package/advisor/convergence.mjs +34 -3
- package/advisor/history.mjs +24 -11
- package/advisor/loop.mjs +49 -12
- package/advisor/messages.mjs +114 -33
- package/advisor/project-context.mjs +171 -42
- package/advisor/run.mjs +24 -10
- package/advisor.mjs +36 -46
- package/agent/batch-attribution.mjs +87 -0
- package/agent/batch-changed-surface.mjs +129 -0
- package/agent/chat-call.mjs +14 -9
- package/agent/completion.mjs +70 -41
- package/agent/continue-decision.mjs +14 -8
- package/agent/digest-account.mjs +133 -59
- package/agent/dispatch-gates.mjs +6 -0
- package/agent/dispatch-run.mjs +1 -1
- package/agent/dispatch.mjs +10 -4
- package/agent/family-tools.mjs +37 -23
- package/agent/helpers.mjs +139 -73
- package/agent/image-heal.mjs +18 -4
- package/agent/offload.mjs +25 -29
- package/agent/post-turn.mjs +36 -35
- package/agent/record-results.mjs +39 -7
- package/agent/run-stages.mjs +132 -52
- package/agent/run-start.mjs +150 -78
- package/agent/setup-reminders.mjs +194 -91
- package/agent/setup.mjs +219 -140
- package/agent/spawn-child.mjs +40 -3
- package/agent/suspension.mjs +43 -15
- package/agent/timers.mjs +9 -4
- package/agent/turn-domain-text.mjs +105 -0
- package/agent/turn-loop.mjs +84 -27
- package/agent/turn-projection.mjs +286 -0
- package/agent/turn-task-state.mjs +274 -0
- package/agent/turn-tool-process.mjs +163 -0
- package/agent/write-gate-ledger.mjs +569 -0
- package/agent/write-gate.mjs +29 -352
- package/agent-tools/advisor-async.mjs +35 -172
- package/agent-tools/advisor-launch.mjs +178 -0
- package/agent-tools/advisor-settle.mjs +28 -1
- package/agent-tools/advisor.mjs +37 -48
- package/agent-tools/async-discard.mjs +7 -2
- package/agent-tools/async-settle.mjs +18 -12
- package/agent-tools/audit-block.mjs +6 -6
- package/agent-tools/bash-async.mjs +5 -2
- package/agent-tools/batch-closeout.mjs +223 -35
- package/agent-tools/batch-gate.mjs +142 -342
- package/agent-tools/batch-ledger-bind.mjs +240 -20
- package/agent-tools/batch-ledger-view.mjs +109 -0
- package/agent-tools/batch-lifecycle.mjs +197 -48
- package/agent-tools/batch-paths.mjs +29 -8
- package/agent-tools/batch-read.mjs +151 -4
- package/agent-tools/batch-record-write.mjs +417 -0
- package/agent-tools/batch-regions.mjs +215 -0
- package/agent-tools/batch-reopen.mjs +23 -11
- package/agent-tools/batch-segment-vocab.mjs +459 -0
- package/agent-tools/batch-skeleton.mjs +196 -239
- package/agent-tools/batch-supersede.mjs +232 -0
- package/agent-tools/batch-tier-gate.mjs +214 -0
- package/agent-tools/batch.mjs +192 -439
- package/agent-tools/browser-async.mjs +5 -2
- package/agent-tools/consult.mjs +17 -11
- package/agent-tools/context.mjs +76 -33
- package/agent-tools/design-review-record.mjs +225 -0
- package/agent-tools/design-slots.mjs +1 -1
- package/agent-tools/design-token.mjs +279 -81
- package/agent-tools/digest-budget.mjs +10 -9
- package/agent-tools/doc-check.mjs +43 -33
- package/agent-tools/doc-graph.mjs +140 -0
- package/agent-tools/eng.mjs +12 -12
- package/agent-tools/escalate-async.mjs +5 -5
- package/agent-tools/goal.mjs +5 -2
- package/agent-tools/judge-domain.mjs +347 -0
- package/agent-tools/manifest.mjs +34 -18
- package/agent-tools/parent-channel.mjs +6 -3
- package/agent-tools/plan.mjs +11 -10
- package/agent-tools/read-history.mjs +112 -11
- package/agent-tools/review-facts.mjs +19 -6
- package/agent-tools/settings.mjs +23 -2
- package/agent-tools/skill.mjs +7 -8
- package/agent-tools/spawn-gates.mjs +14 -24
- package/agent-tools/ssh-session.mjs +8 -5
- package/agent-tools/ssh-text.mjs +155 -0
- package/agent-tools/ssh-transfer.mjs +1 -1
- package/agent-tools/ssh-transport.mjs +19 -148
- package/agent-tools/subagent-actions-query.mjs +10 -6
- package/agent-tools/subagent-actions.mjs +2 -2
- package/agent-tools/subagent-async.mjs +19 -17
- package/agent-tools/subagent-brief.mjs +76 -0
- package/agent-tools/subagent-design-token.mjs +168 -0
- package/agent-tools/subagent-run.mjs +1 -1
- package/agent-tools/subagent-scheduler.mjs +13 -13
- package/agent-tools/subagent-spawn.mjs +92 -112
- package/agent-tools/subagent.mjs +16 -28
- package/agent-tools/task.mjs +0 -8
- package/agent-tools/taskbook-block.mjs +94 -0
- package/agent-tools/timer.mjs +12 -8
- package/agent-tools/verify.mjs +13 -4
- package/agent-tools.mjs +7 -3
- package/agent.mjs +26 -7
- package/attachments.mjs +3 -3
- package/auto-think.mjs +5 -2
- package/browser/actions.mjs +9 -3
- package/browser/cdp.mjs +45 -17
- package/browser/launch.mjs +25 -43
- package/browser/pool.mjs +299 -0
- package/browser/queue.mjs +2 -0
- package/browser/session-state.mjs +450 -0
- package/browser/session.mjs +127 -151
- package/browser/snapshot.mjs +89 -0
- package/client-identity.mjs +1 -1
- package/compaction-work-state.mjs +230 -0
- package/compress-form.mjs +41 -6
- package/config-defaults.mjs +7 -3
- package/config-migrate.mjs +40 -0
- package/config-normalize.mjs +28 -2
- package/config-reload.mjs +59 -0
- package/config.mjs +110 -110
- package/context-degrade.mjs +93 -34
- package/context-echo.mjs +6 -15
- package/context-push.mjs +328 -31
- package/context.mjs +298 -170
- package/conventions.mjs +11 -9
- package/declaration.mjs +126 -22
- package/declared-repos.mjs +94 -0
- package/doc-check/doc-names.mjs +73 -0
- package/doc-check/doc-tokens.mjs +110 -0
- package/doc-check/existence.mjs +160 -0
- package/doc-check/index.mjs +309 -213
- package/doc-check/line-refs.mjs +27 -101
- package/doc-check/paragraph.mjs +218 -102
- package/doc-graph/anchors.mjs +474 -0
- package/doc-graph/doc-batch-face.mjs +59 -0
- package/doc-graph/doc-suffix.mjs +27 -0
- package/doc-graph/graph-tokens.mjs +160 -0
- package/doc-graph.mjs +778 -0
- package/escape.mjs +6 -5
- package/explore-distill.mjs +41 -8
- package/generate-title.mjs +10 -1
- package/i18n.mjs +1 -1
- package/instance-inbox-watch.mjs +272 -0
- package/instance-inbox.mjs +218 -0
- package/instance-registry.mjs +179 -0
- package/knowledge/README.md +3 -0
- package/knowledge/prompt-resources.md +10 -0
- package/ledger-close-proof.mjs +100 -49
- package/ledger-close.mjs +188 -0
- package/ledger-cmd.mjs +47 -91
- package/ledger-consistency.mjs +113 -0
- package/ledger-db.mjs +47 -15
- package/ledger-executors.mjs +1 -1
- package/ledger-tools.mjs +121 -62
- package/ledger-write-ops.mjs +162 -46
- package/ledger.mjs +1 -1
- package/manifest-discovery.mjs +3 -1
- package/manifest-schema.mjs +27 -5
- package/memory/docs.mjs +51 -15
- package/memory/file-list.mjs +6 -0
- package/memory/schema.mjs +2 -2
- package/model-specs.mjs +87 -21
- package/origin-guard.mjs +190 -0
- package/package.json +3 -1
- package/path-resolve.mjs +338 -57
- package/prompt-files.mjs +114 -2
- package/prompt-overlays.mjs +21 -11
- package/prompts/advisor-design.md +96 -36
- package/prompts/advisor-round1.md +48 -4
- package/prompts/advisor-round2.md +54 -10
- package/prompts/advisor-round3.md +53 -9
- package/prompts/common.md +99 -434
- package/prompts/consult-base.md +7 -4
- package/prompts/discipline-engineering.md +504 -295
- package/prompts/discipline-normal.md +106 -281
- package/prompts/knowledge/business-gates.md +30 -0
- package/prompts/knowledge/decision-quality.md +21 -0
- package/prompts/knowledge/doc-lookup.md +30 -0
- package/prompts/knowledge/document-writing.md +33 -0
- package/prompts/knowledge/documentation-evaluation.md +48 -0
- package/prompts/knowledge/evidence-discipline.md +38 -0
- package/prompts/knowledge/normal-coding-workflow.md +110 -0
- package/prompts/knowledge/normal-delivery-collaboration.md +124 -0
- package/prompts/knowledge/normal-work-management.md +60 -0
- package/prompts/knowledge/product-security.md +28 -0
- package/prompts/knowledge/project-records.md +73 -0
- package/prompts/knowledge/tool-advisor.md +29 -0
- package/prompts/knowledge/tool-apply-patch.md +17 -0
- package/prompts/knowledge/tool-bash.md +48 -0
- package/prompts/knowledge/tool-batch-eng-coder.md +19 -0
- package/prompts/knowledge/tool-batch-eng-designer.md +20 -0
- package/prompts/knowledge/tool-batch-review.md +18 -0
- package/prompts/knowledge/tool-batch.md +94 -0
- package/prompts/knowledge/tool-browser.md +68 -0
- package/prompts/knowledge/tool-code-search.md +4 -0
- package/prompts/knowledge/tool-consult-start.md +12 -0
- package/prompts/knowledge/tool-consult-stop.md +6 -0
- package/prompts/knowledge/tool-context.md +6 -0
- package/prompts/knowledge/tool-delete.md +21 -0
- package/prompts/knowledge/tool-doc-check.md +71 -0
- package/prompts/knowledge/tool-doc-graph-read.md +20 -0
- package/prompts/knowledge/tool-doc-graph.md +49 -0
- package/prompts/knowledge/tool-doc-search.md +6 -0
- package/prompts/knowledge/tool-edit.md +41 -0
- package/prompts/knowledge/tool-eng.md +2 -0
- package/prompts/knowledge/tool-execute.md +21 -0
- package/prompts/knowledge/tool-fetch.md +18 -0
- package/prompts/knowledge/tool-file-ops.md +21 -0
- package/prompts/knowledge/tool-get-current-time.md +7 -0
- package/prompts/knowledge/tool-git-read.md +21 -0
- package/prompts/knowledge/tool-git.md +29 -0
- package/prompts/knowledge/tool-glob.md +17 -0
- package/prompts/knowledge/tool-goal.md +8 -0
- package/prompts/knowledge/tool-grep.md +21 -0
- package/prompts/knowledge/tool-hashline-edit.md +16 -0
- package/prompts/knowledge/tool-insert-after.md +17 -0
- package/prompts/knowledge/tool-instance-list.md +6 -0
- package/prompts/knowledge/tool-instance-send.md +10 -0
- package/prompts/knowledge/tool-knowledge.md +18 -0
- package/prompts/knowledge/tool-ledger-read.md +28 -0
- package/prompts/knowledge/tool-ledger.md +46 -0
- package/prompts/knowledge/tool-lint.md +16 -0
- package/prompts/knowledge/tool-ls.md +15 -0
- package/prompts/knowledge/tool-lsp.md +11 -0
- package/prompts/knowledge/tool-main-history.md +2 -0
- package/prompts/knowledge/tool-manifest-read.md +14 -0
- package/prompts/knowledge/tool-manifest.md +34 -0
- package/prompts/knowledge/tool-memory-read.md +20 -0
- package/prompts/knowledge/tool-memory.md +19 -0
- package/prompts/knowledge/tool-notify-parent.md +12 -0
- package/prompts/knowledge/tool-operations.md +102 -0
- package/prompts/knowledge/tool-peer-instances.md +2 -0
- package/prompts/knowledge/tool-plan.md +5 -0
- package/prompts/knowledge/tool-process-read.md +13 -0
- package/prompts/knowledge/tool-process.md +15 -0
- package/prompts/knowledge/tool-question.md +16 -0
- package/prompts/knowledge/tool-read-history-batch.md +22 -0
- package/prompts/knowledge/tool-read-history.md +35 -0
- package/prompts/knowledge/tool-read-image.md +11 -0
- package/prompts/knowledge/tool-read.md +22 -0
- package/prompts/knowledge/tool-recent-changes.md +6 -0
- package/prompts/knowledge/tool-repo-outline.md +4 -0
- package/prompts/knowledge/tool-settings-read.md +12 -0
- package/prompts/knowledge/tool-settings.md +17 -0
- package/prompts/knowledge/tool-skill.md +6 -0
- package/prompts/knowledge/tool-ssh.md +74 -0
- package/prompts/knowledge/tool-subagent.md +57 -0
- package/prompts/knowledge/tool-task.md +14 -0
- package/prompts/knowledge/tool-team-ledger-read.md +11 -0
- package/prompts/knowledge/tool-team-ledger.md +15 -0
- package/prompts/knowledge/tool-timer.md +23 -0
- package/prompts/knowledge/tool-tree.md +16 -0
- package/prompts/knowledge/tool-verify.md +19 -0
- package/prompts/knowledge/tool-wait-for.md +25 -0
- package/prompts/knowledge/tool-websearch.md +19 -0
- package/prompts/knowledge/tool-write.md +12 -0
- package/prompts/knowledge/upstream-protocol.md +45 -0
- package/prompts/persona-coder.md +1 -3
- package/prompts/persona-eng-coder.md +24 -6
- package/prompts/persona-eng-designer.md +150 -171
- package/prompts/persona-engineering.md +531 -442
- package/prompts/persona-explore.md +1 -3
- package/prompts/persona-normal.md +17 -9
- package/prompts/persona-plan.md +5 -3
- package/prompts/persona-tester.md +0 -2
- package/prompts/subagent-base.md +2 -2
- package/provider/anthropic.mjs +10 -6
- package/provider/core.mjs +8 -5
- package/provider/errors.mjs +63 -4
- package/provider/google.mjs +29 -10
- package/provider/reasoning-echo.mjs +16 -0
- package/provider/responses.mjs +7 -3
- package/provider/sse.mjs +11 -6
- package/provider-flows.mjs +2 -2
- package/rules.mjs +11 -10
- package/session-index-build.mjs +1 -1
- package/session-index-pass.mjs +1 -1
- package/session-index-query.mjs +1 -1
- package/session-index.mjs +1 -1
- package/session-lifecycle.mjs +131 -42
- package/session-slot-write.mjs +38 -6
- package/session.mjs +30 -11
- package/shell-identity.mjs +129 -22
- package/skip-dirs.mjs +26 -2
- package/team-ledger.mjs +34 -30
- package/text-budget.mjs +1 -1
- package/think-off.mjs +27 -0
- package/token-ttl.mjs +74 -5
- package/token-window.mjs +371 -47
- package/tool-docs/advisor.md +2 -27
- package/tool-docs/apply_patch.md +1 -15
- package/tool-docs/bash.md +2 -43
- package/tool-docs/batch-eng-coder.md +3 -0
- package/tool-docs/batch-eng-designer.md +3 -0
- package/tool-docs/batch-review.md +3 -0
- package/tool-docs/batch.md +2 -84
- package/tool-docs/browser.md +2 -49
- package/tool-docs/code_search.md +2 -2
- package/tool-docs/consult_start.md +2 -8
- package/tool-docs/consult_stop.md +2 -4
- package/tool-docs/context.md +1 -5
- package/tool-docs/delete.md +2 -17
- package/tool-docs/doc_check.md +2 -107
- package/tool-docs/doc_graph-read.md +3 -0
- package/tool-docs/doc_graph.md +3 -0
- package/tool-docs/doc_search.md +2 -4
- package/tool-docs/edit.md +1 -38
- package/tool-docs/eng.md +3 -1
- package/tool-docs/execute.md +2 -18
- package/tool-docs/fetch.md +2 -14
- package/tool-docs/file_ops.md +2 -18
- package/tool-docs/get_current_time.md +1 -6
- package/tool-docs/git-read.md +3 -0
- package/tool-docs/git.md +2 -35
- package/tool-docs/glob.md +2 -10
- package/tool-docs/goal.md +1 -6
- package/tool-docs/grep.md +2 -18
- package/tool-docs/hashline_edit.md +2 -15
- package/tool-docs/insert_after.md +2 -16
- package/tool-docs/instance_list.md +3 -0
- package/tool-docs/instance_send.md +3 -0
- package/tool-docs/knowledge.md +3 -0
- package/tool-docs/ledger-read.md +3 -0
- package/tool-docs/ledger.md +3 -8
- package/tool-docs/lint.md +2 -10
- package/tool-docs/ls.md +2 -11
- package/tool-docs/lsp.md +2 -9
- package/tool-docs/main_history.md +3 -1
- package/tool-docs/manifest-read.md +2 -8
- package/tool-docs/manifest.md +2 -35
- package/tool-docs/memory-read.md +3 -0
- package/tool-docs/memory.md +2 -20
- package/tool-docs/notify_parent.md +2 -13
- package/tool-docs/peer_instances.md +3 -1
- package/tool-docs/plan.md +1 -5
- package/tool-docs/process-read.md +3 -0
- package/tool-docs/process.md +2 -13
- package/tool-docs/question.md +3 -17
- package/tool-docs/read.md +2 -19
- package/tool-docs/read_history-batch.md +3 -0
- package/tool-docs/read_history.md +2 -18
- package/tool-docs/read_image.md +2 -9
- package/tool-docs/recent_changes.md +2 -2
- package/tool-docs/repo_outline.md +2 -2
- package/tool-docs/settings-read.md +3 -0
- package/tool-docs/settings.md +1 -12
- package/tool-docs/skill.md +2 -6
- package/tool-docs/ssh.md +1 -62
- package/tool-docs/subagent.md +2 -100
- package/tool-docs/task.md +1 -7
- package/tool-docs/team_ledger-read.md +3 -0
- package/tool-docs/team_ledger.md +3 -9
- package/tool-docs/timer.md +2 -19
- package/tool-docs/tree.md +2 -13
- package/tool-docs/verify.md +2 -12
- package/tool-docs/wait_for.md +2 -32
- package/tool-docs/websearch.md +2 -19
- package/tool-docs/write.md +2 -12
- package/tools/browser.mjs +54 -9
- package/tools/doc-write-gate.mjs +73 -0
- package/tools/edit-batch.mjs +170 -92
- package/tools/edit-diff.mjs +78 -62
- package/tools/edit-receipt.mjs +39 -0
- package/tools/execute.mjs +3 -3
- package/tools/file.mjs +28 -14
- package/tools/git.mjs +36 -21
- package/tools/index.mjs +6 -0
- package/tools/knowledge.mjs +143 -0
- package/tools/linter.mjs +3 -3
- package/tools/ops.mjs +5 -3
- package/tools/patch.mjs +124 -44
- package/tools/process-doc-mark.mjs +33 -4
- package/tools/repomap.mjs +25 -3
- package/tools/search.mjs +74 -26
- package/tools/shared.mjs +29 -27
- package/tools/ssh.mjs +5 -5
- package/tools/tree.mjs +32 -10
- package/tools/web-deepseek.mjs +1 -1
- package/tools/web.mjs +2 -2
- package/tools/write-gate-params.mjs +31 -0
- package/tools/write-path.mjs +16 -4
- package/window-policy.mjs +243 -0
- package/doc-check/anchors.mjs +0 -235
package/model-specs.mjs
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { listedContextTokens, manualContextK, warnContextOnce } from "./model-context.mjs"
|
|
11
|
+
import { logEvent } from "./log.mjs"
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Known model capability spec table (prefix match within the model's last "/"-segment, longer first).
|
|
@@ -111,13 +112,20 @@ const MODEL_SPECS = [
|
|
|
111
112
|
// (6 levels), 3.8-flash adds it (7); enum order = the server's literal order, first member "none"
|
|
112
113
|
// (D-5) — never re-sort by strength. context = doc/web statement (1M class, not API-measured);
|
|
113
114
|
// partialMode / thinkApi / tempRange = same-family carry-over (not independently
|
|
114
|
-
// measured on these rows); reasoningEcho stays undeclared
|
|
115
|
+
// measured on these rows); reasoningEcho stays undeclared(qwen3.8-max / qwen3.7-flash / qwen4-max 真机实测:带 tools 的续跑请求里,历史工具轮缺 `reasoning_content` 键照样 200——DashScope 不强制跨轮回声,故不声明 required)。
|
|
115
116
|
["qwen3.7-flash", { context: 1_000_000, maxOutput: 131_072, thinking: true, partialMode: true, multimodal: true, thinkApi: "effort", reasoningEffortEnum: ["none", "minimal", "low", "medium", "high", "xhigh"], tempRange: [0, 2] }],
|
|
116
117
|
// qwen3.7-plus(2026-09-24 bench 名单批):context = **官方口径(网络转述)**(2026-09-20 qwen-flash-specs 批 AC-6 已裁允许入表——「100 万长文档」族点名);
|
|
117
118
|
// maxOutput / partialMode / thinkApi / tempRange / thinking = **族沿用 qwen3.7-flash 行**;枚举 / 视觉面 = **未探**(不声明)。
|
|
118
119
|
["qwen3.7-plus", { context: 1_000_000, maxOutput: 131_072, thinking: true, partialMode: true, thinkApi: "effort", tempRange: [0, 2] }],
|
|
119
120
|
["qwen3.8-flash", { context: 1_000_000, maxOutput: 131_072, thinking: true, partialMode: true, multimodal: true, thinkApi: "effort", reasoningEffortEnum: ["none", "minimal", "low", "medium", "high", "xhigh", "max"], tempRange: [0, 2] }],
|
|
120
121
|
["qwen3.8-max", { context: 1_000_000, maxOutput: 131_072, thinking: true, partialMode: true, multimodal: true, thinkApi: "effort", reasoningEffortEnum: ["xhigh", "medium", "low"], tempRange: [0, 2] }],
|
|
122
|
+
// qwen4-max(2026-11-19 批)——行注即标级(`MODEL-SPECS.md` §1「逐字段记录当前一手来源或实测证据;不能从名字猜能力」):
|
|
123
|
+
// context 1_000_000 = **官方口径**(`https://help.aliyun.com/zh/model-studio/qwen4-max-preview` 原文「Context length,
|
|
124
|
+
// 1M tokens」);maxOutput 393_216 = **官方口径**(同页原文「Maximum output, 393,216 tokens, shared by thinking and
|
|
125
|
+
// the final answer」);thinking = 同句(thinking 与最终答案共享输出上限 ⇒ 该模型走 thinking)。
|
|
126
|
+
// partialMode ∥ multimodal ∥ thinkApi ∥ reasoningEffortEnum ∥ tempRange = **未探**(不声明——不拿邻行猜值);
|
|
127
|
+
// thinkApi 不声明 ⇒ 无 off 路径,UI 不给假 off(`MODEL-SPECS.md` §4)。
|
|
128
|
+
["qwen4-max", { context: 1_000_000, maxOutput: 393_216, thinking: true }],
|
|
121
129
|
// qwen3.8-omni-flash / qwen3.8-27b — parent 80-token probe (batch §1.8-①): reasoning_content
|
|
122
130
|
// present, reasoning_tokens 49, `effort:"none"` removes it ⇒ thinking MEASURED; enum / maxOutput
|
|
123
131
|
// / image intake measured the same way. omni-flash: context = doc/web statement (1M class, not
|
|
@@ -130,7 +138,7 @@ const MODEL_SPECS = [
|
|
|
130
138
|
// undeclared (cross-turn echo unverified — R-4).
|
|
131
139
|
["qwen3.8-27b", { context: 262_144, maxOutput: 131_072, thinking: true, partialMode: true, multimodal: true, thinkApi: "effort", reasoningEffortEnum: ["none", "minimal", "low", "medium", "high", "xhigh", "max"], tempRange: [0, 2] }],
|
|
132
140
|
// No generic "qwen" fallback row: unlisted qwen names deliberately resolve to DEFAULT_SPEC
|
|
133
|
-
// (
|
|
141
|
+
// (256K / 32K, no vision) — per-name disposition in docs/core/design/MODEL-SPECS.md §3.
|
|
134
142
|
// Do not re-add a blanket prefix row (silent inheritance is how missing rows stayed invisible).
|
|
135
143
|
|
|
136
144
|
// qwen3.6 系五行(批 2026-09-20-qwen36-family-rows · 五名同形,取证叙述落此一处全量):
|
|
@@ -246,7 +254,10 @@ const MODEL_SPECS = [
|
|
|
246
254
|
// 生效值同值);行键 = 裸名(渠道名录形 stepfun/step-3.7-flash——命名空间剥离同命中)。
|
|
247
255
|
["step-3.7-flash", { context: 262_144, maxOutput: 32_000 }],
|
|
248
256
|
]
|
|
249
|
-
|
|
257
|
+
// 回落规格(`MODEL-SPECS.md` §3):窗口 262_144 / 输出 32_000。窗口取 256K 不取 128K 的理由不对称——
|
|
258
|
+
// 常见输出预留 131,072 落在 128K 窗上算出负的输入窗口(128,000 − 131,072 < 0),回落因此连一条请求都发不出;
|
|
259
|
+
// 256K 让同一份预留仍留出输入窗口。
|
|
260
|
+
const DEFAULT_SPEC = { context: 262_144, maxOutput: 32_000 }
|
|
250
261
|
|
|
251
262
|
/** 查表规则(单源 = PROVIDER.md §6.9 · 用户 2026-10-23 17:34 裁定「匹配 / 拆分以后的最后一段」):
|
|
252
263
|
*
|
|
@@ -279,14 +290,14 @@ function lookupSpec(model) {
|
|
|
279
290
|
}
|
|
280
291
|
|
|
281
292
|
/** Unknown model: warn ONCE (not per request) so a typo'd ID or a missing alias surfaces
|
|
282
|
-
* instead of silently degrading to the
|
|
293
|
+
* instead of silently degrading to the 256K default (IK5VGJ). The dedupe set is shared by
|
|
283
294
|
* specForModel / specMatch (PROVIDER.md §16 M5). */
|
|
284
295
|
function warnUnknownModel(model) {
|
|
285
296
|
// 非串 model(脏载)归一空串 ⇒ 不警告(未登记 ≠ 拼错——不刷屏;#638 与 lookupSpec 同归一)
|
|
286
297
|
const m = (typeof model === "string" ? model : "").toLowerCase()
|
|
287
298
|
if (m && !warnedModels.has(m)) {
|
|
288
299
|
warnedModels.add(m)
|
|
289
|
-
console.warn(`[config] model "${model}" not found in MODEL_SPECS — using default spec (
|
|
300
|
+
console.warn(`[config] model "${model}" not found in MODEL_SPECS — using default spec (256K context, 32K output). Check the model ID or add an alias.`)
|
|
290
301
|
}
|
|
291
302
|
}
|
|
292
303
|
|
|
@@ -333,13 +344,13 @@ export function formatDeclaredContextK(k) {
|
|
|
333
344
|
* L2 `providers[].context`(旧键,K;仅未被 L1 点名的模型) → ×1024(同一乘点)
|
|
334
345
|
* L3 `/models` 自报(三字段任一,token) → 不乘
|
|
335
346
|
* L4 `MODEL_SPECS` 静态表(token) → 不乘
|
|
336
|
-
* L5 `DEFAULT_SPEC`(
|
|
347
|
+
* L5 `DEFAULT_SPEC`(256K,token) → 不乘
|
|
337
348
|
*
|
|
338
349
|
* L2 位于 L3 之上:旧键也是人工声明(2026-10-23 17:30 裁定「人工声明 > 列表」),只是粒度不对、
|
|
339
350
|
* 单位事故出过两次;`modelContext` 点名的模型一律走 L1,L2 不参与。L2 实际被用到时告警一次
|
|
340
351
|
* (provider 名去重——装载期告警会在 L1 已完全覆盖时误报)。
|
|
341
352
|
*
|
|
342
|
-
* 量级守卫(R32):L1 ∥ L2 的 K 值换算后 > 静态表 ×4(表无行时 = 4 ×
|
|
353
|
+
* 量级守卫(R32):L1 ∥ L2 的 K 值换算后 > 静态表 ×4(表无行时 = 4 × 256K)⇒ 照用 + 告警一次,
|
|
343
354
|
* 不截断、不拒写——与 L3 的 4× 守卫对称。守卫住在核里:值可能来自手改 JSON(不经任何界面),
|
|
344
355
|
* 端上守不到;手改 ∥ CLI ∥ VSC ∥ 桌面四条来源在这里同判。
|
|
345
356
|
*
|
|
@@ -352,7 +363,7 @@ export function formatDeclaredContextK(k) {
|
|
|
352
363
|
* 与其余能力位仍取静态表 ∥ DEFAULT_SPEC(需求边界:不改 maxOutput 来源)。
|
|
353
364
|
*
|
|
354
365
|
* `source` 闭集五值(`windowSource` 的唯一来源,不并类):`modelContext` ∥ `provider-override` ∥
|
|
355
|
-
* `list` ∥ `spec` ∥ `default`。`warnUnknownModel` 只在链落到 L4/L5 时触发(L1-L3 供值时
|
|
366
|
+
* `list` ∥ `spec` ∥ `default`。`warnUnknownModel` 只在链落到 L4/L5 时触发(L1-L3 供值时 256K 告警为假)。
|
|
356
367
|
*/
|
|
357
368
|
export function providerSpecResolution(provider) {
|
|
358
369
|
const model = provider?.model ?? ""
|
|
@@ -408,34 +419,89 @@ export function providerSpec(provider) {
|
|
|
408
419
|
}
|
|
409
420
|
|
|
410
421
|
/**
|
|
411
|
-
*
|
|
422
|
+
* assistantEchoMessage(response, spec, thinkingMode) — the tool-round assistant message pushed onto the
|
|
412
423
|
* machine line (D-CC22, #109 — live-push face of the echo-safety family; single construction
|
|
413
|
-
* point, CONTEXT-COMPACTION.md §6.10 #9).
|
|
424
|
+
* point, CONTEXT-COMPACTION.md §6.10 #9). 机制正文 = `docs/core/design/AGENT-LOOP.md` §5.4。
|
|
414
425
|
*
|
|
415
|
-
*
|
|
416
|
-
*
|
|
417
|
-
* `
|
|
418
|
-
*
|
|
419
|
-
*
|
|
426
|
+
* 取值次序固定,第三参只参与「手里没有原文」那一支:
|
|
427
|
+
* - `reasoningEcho:"required"` 族(deepseek / kimi / mimo)握着非空 `response.reasoning` ⇒ 逐字带上
|
|
428
|
+
* `reasoning_content`,其值就是那串原文,不改写——**不因 `thinkingMode === false` 省键**(关闭标记不保证
|
|
429
|
+
* 服务端没有思考,丢掉手里已有的原文会让带 `tools` 的下一轮缺回声);
|
|
430
|
+
* - 同族没有非空原文且 `thinkingMode === true` ⇒ **写空串**并写 `echo:missing` 留痕事件(provider、model、
|
|
431
|
+
* toolCount),不抛错(#2645 降级、#2647 改正写法)。服务端拒的是缺键,空串是合法的「没有原文」编码:
|
|
432
|
+
* 真机读数——同一具 39 条失败请求体只把缺失的键补成空串即 200,键缺失则 400;
|
|
433
|
+
* - 同族没有非空原文且 `thinkingMode === false` ⇒ 不带该键、不抛错——需求 §7「非思考模式下服务端不返回该字段,
|
|
434
|
+
* 此时不带它,不算缺陷」;
|
|
435
|
+
* - `optional` ∥ 未声明的族(含 `spec` 为 `null` 与 DEFAULT_SPEC)⇒ 不带该键。
|
|
436
|
+
*
|
|
437
|
+
* 边界(无默认值):`response` 未传 ⇒ 点名报错;`spec` 未传(`undefined`)⇒ 点名报错;`thinkingMode`
|
|
438
|
+
* 未传 ∥ 非布尔 ⇒ 各自点名报错。`spec` 传 `null` 是合法的「未声明族」值——服务端 live 工具轮在名字不可解
|
|
439
|
+
* ∥ 缺核时回落的正是它,不带该键、不抛错。`thinkingMode` 由 `isThinkingRequest(provider, spec)` 算出
|
|
440
|
+
* (`thincoder-core/think-off.mjs`,经 `config.mjs` 转口);本函数不重算模式。
|
|
441
|
+
* `response.toolCalls` 为空 ⇒ 入口报错并点名 `toolCalls`:工具轮消息必须带工具调用,不写成 `tool_calls: []`。
|
|
442
|
+
* 纯文本轮走同档的 `assistantTextMessage`,回声键的取值次序与边界与之逐条相同。
|
|
420
443
|
*
|
|
421
444
|
* 思考签名(PROVIDER.md §6.24):`tool_calls[].extra_content` 在场才带(缺 ⇒ 键不存在——无签名上游键集逐字不变)。
|
|
422
445
|
*
|
|
423
|
-
*
|
|
424
|
-
*
|
|
425
|
-
*
|
|
446
|
+
* 调用点:`thincoder-core/agent/turn-loop.mjs`(主循环)· `thincoder-core/advisor/loop.mjs`(评审镜像)·
|
|
447
|
+
* `bench/lib/client.mjs`(bench 客户端)· `prompt-fixture/runner.mjs`(夹具跑器)——各自解析自己的 spec 面、
|
|
448
|
+
* 各自算好自己的模式;服务端 live 工具轮 = `thincoder-server/src/agent/chat-compact.mjs` 的 `assistantTurnOf`
|
|
449
|
+
* (动载后调用);VSC 转口 `thincoder-vscode/src/specs.mjs` 的 `providerSpec` ∕ `assistantEchoMessage` 再导出
|
|
450
|
+
* (本仓零调用点)。
|
|
426
451
|
*/
|
|
427
|
-
export function
|
|
452
|
+
export function assistantEchoMessage(response, spec, thinkingMode, provider = null) {
|
|
453
|
+
if (response === undefined || response === null) throw new Error("assistantEchoMessage: response is required — 工具轮消息由调用方手里那次响应构造,本函数不替调用方补默认")
|
|
454
|
+
if (spec === undefined) throw new Error("assistantEchoMessage: spec is required — 传该族的规格(未声明的族传 null),本函数不替调用方补默认")
|
|
455
|
+
if (thinkingMode === undefined) throw new Error("assistantEchoMessage: thinkingMode is required — 传 isThinkingRequest(provider, spec) 的结果,本函数不替调用方补默认")
|
|
456
|
+
if (typeof thinkingMode !== "boolean") throw new Error(`assistantEchoMessage: thinkingMode must be a boolean — 收到 ${typeof thinkingMode}`)
|
|
457
|
+
const toolCalls = Array.isArray(response.toolCalls) ? response.toolCalls : []
|
|
458
|
+
if (toolCalls.length === 0) throw new Error("assistantEchoMessage: toolCalls is empty — 工具轮消息必须带工具调用;纯文本轮不经本函数构造,也不写 tool_calls: []")
|
|
428
459
|
const msg = {
|
|
429
460
|
role: "assistant",
|
|
430
461
|
content: response.content || null,
|
|
431
|
-
tool_calls:
|
|
462
|
+
tool_calls: toolCalls.map((tc) => ({
|
|
432
463
|
id: tc.id, type: "function",
|
|
433
464
|
function: { name: tc.name, arguments: tc.arguments },
|
|
434
465
|
...(tc.extra_content ? { extra_content: tc.extra_content } : {}),
|
|
435
466
|
})),
|
|
436
467
|
}
|
|
437
468
|
if (spec?.reasoningEcho === "required") {
|
|
438
|
-
|
|
469
|
+
const echo = response.reasoning
|
|
470
|
+
if (typeof echo === "string" && echo !== "") {
|
|
471
|
+
msg.reasoning_content = echo
|
|
472
|
+
} else if (thinkingMode) {
|
|
473
|
+
// 思考模式下服务端没给回声:写空串 + 留痕,不抛错(#2645 降级、#2647 把省键改成空串)。
|
|
474
|
+
// 服务端拒的是缺键;空串是合法的「没有原文」编码(真机:补键 200、缺键 400)。
|
|
475
|
+
msg.reasoning_content = ""
|
|
476
|
+
logEvent("echo:missing", { provider: provider?.name ?? undefined, model: provider?.model ?? undefined, toolCount: toolCalls.length, thinkingMode })
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
return msg
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* assistantTextMessage(response, spec, thinkingMode, provider) — 纯文本轮的 assistant 消息(无工具调用)。
|
|
484
|
+
*
|
|
485
|
+
* 与 `assistantEchoMessage` 同住一个取值次序:有非空 `response.reasoning` 就逐字带上;`required` 族、
|
|
486
|
+
* `thinkingMode` 为真而无原文时写空串并留痕;其余情形不带该键。差别只有一条——不带 `tool_calls`。
|
|
487
|
+
* 机制正文 = `docs/core/design/AGENT-LOOP.md` §5.4(写面是回声键的源头)。
|
|
488
|
+
*
|
|
489
|
+
* 边界同档:`response` ∥ `spec` ∥ `thinkingMode` 缺一在入口点名报错;`spec` 传 `null` 是合法的「未声明族」。
|
|
490
|
+
*/
|
|
491
|
+
export function assistantTextMessage(response, spec, thinkingMode, provider = null) {
|
|
492
|
+
if (response === undefined || response === null) throw new Error("assistantTextMessage: response is required — 消息由调用方手里那次响应构造,本函数不替调用方补默认")
|
|
493
|
+
if (spec === undefined) throw new Error("assistantTextMessage: spec is required — 传该族的规格(未声明的族传 null),本函数不替调用方补默认")
|
|
494
|
+
if (thinkingMode === undefined) throw new Error("assistantTextMessage: thinkingMode is required — 传 isThinkingRequest(provider, spec) 的结果,本函数不替调用方补默认")
|
|
495
|
+
if (typeof thinkingMode !== "boolean") throw new Error(`assistantTextMessage: thinkingMode must be a boolean — 收到 ${typeof thinkingMode}`)
|
|
496
|
+
const msg = { role: "assistant", content: response.content || null }
|
|
497
|
+
if (spec?.reasoningEcho === "required") {
|
|
498
|
+
const echo = response.reasoning
|
|
499
|
+
if (typeof echo === "string" && echo !== "") {
|
|
500
|
+
msg.reasoning_content = echo
|
|
501
|
+
} else if (thinkingMode) {
|
|
502
|
+
msg.reasoning_content = ""
|
|
503
|
+
logEvent("echo:missing", { provider: provider?.name ?? undefined, model: provider?.model ?? undefined, toolCount: 0, thinkingMode })
|
|
504
|
+
}
|
|
439
505
|
}
|
|
440
506
|
return msg
|
|
441
507
|
}
|
package/origin-guard.mjs
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* origin-guard.mjs — 跨 provider 历史来源的判据单点(机制正文 = `docs/core/design/AGENT-LOOP.md` §5.5)。
|
|
3
|
+
*
|
|
4
|
+
* 三端一个判据,实现只此一处:
|
|
5
|
+
* ① 打标 `tagOriginProvider`:消息出生点(`thincoder-core/context-push.mjs` 的 `pushReal`,真实消息的唯一入口)给
|
|
6
|
+
* `role === "assistant"` 的消息写产出它的 provider 名;
|
|
7
|
+
* ② 隔离 `quarantineForeignOrigin`:请求装配的每个构造点按来源隔离异 provider 回声,并给 `required`、思考开且携带
|
|
8
|
+
* 工具声明的请求里缺 `reasoning_content` 键的 assistant 消息补上空串(缺键才是 400 的来源,空串是合法占位);
|
|
9
|
+
* ③ 补来源 `fillOriginFromSlot`:`applySession` 装回旧线(无标记)时按槽 `activeProvider` 补会话级来源。
|
|
10
|
+
*
|
|
11
|
+
* 标记 `originProvider` 是仅本地字段(与 `ts` 同级),出线前由 `escape.mjs` 的 `stripLocalMessageFields` 剥掉。
|
|
12
|
+
* 只记名字、不记族:判据只问「是不是同一个 provider 产出」;当前族要什么回声从当下的 spec 读(§5.5.5)。
|
|
13
|
+
*
|
|
14
|
+
* 隔离表(§5.5.5):
|
|
15
|
+
* - 无标记、当前 provider 名不可得、来源相同 ⇒ 来源隔离不动;它们仍受下方缺键补空串判据约束;
|
|
16
|
+
* - 来源不同、当前族 `reasoningEcho === "required"`、且该消息带 `tool_calls` ⇒ 退掉工具调用;
|
|
17
|
+
* - 来源不同、其余情形 ⇒ 删 `reasoning_content` 与 `tool_calls[].extra_content`,文本与工具调用保留;
|
|
18
|
+
* - 任一条 assistant 无正文、无非空回声、无工具调用 ⇒ 整条退出本次请求副本,不看来源、不看这条消息这回有没有被改过;
|
|
19
|
+
* - `required` + 思考开 + 携带工具声明 ⇒ 缺 `reasoning_content` 键的 assistant 补空串,正文与工具轮都保留。
|
|
20
|
+
* 行序 = 来源两支 → 空轮退场 → 缺键补空串:要被丢掉的那条不该先被记一次补键。
|
|
21
|
+
*
|
|
22
|
+
* 读数(§5.5.6):`strippedEcho` = 删掉的私有字段处数;`retiredToolRounds` = 异源退轮条数;
|
|
23
|
+
* `filledMissingEcho` = 补空串的条数;`droppedEmptyAssistant` = 空 assistant 退场条数;
|
|
24
|
+
* `origins` = 入参里出现过的来源 provider 名(去重、按名排序)。读数非零时记 `llm:origin-quarantine`。
|
|
25
|
+
*
|
|
26
|
+
* 纪律:`quarantineForeignOrigin` 与 `fillOriginFromSlot` 零 IO、不改入参消息对象
|
|
27
|
+
* (copy-on-write:没有一条被改过时 `messages` / `history` 就是入参本身,有改动时只有被改的那几条 / 那一轮是新对象)。
|
|
28
|
+
* `thinkingMode` 与 `toolsDeclared` 是 `quarantineForeignOrigin` 的必填布尔判据,缺参或非布尔在入口点名抛错。
|
|
29
|
+
* `tagOriginProvider` 是**出生点的就地打标**(§5.5.4 写行):`pushReal` 传进来的正是那条新消息,打标与它给 `ts` 打点是同一形体。
|
|
30
|
+
* `logOriginQuarantine` 是 fire-and-forget 事件面(住 `thincoder-core/log.mjs`),构造点的返回值仍是消息数组,两形调用面零改。
|
|
31
|
+
*/
|
|
32
|
+
import { logEvent } from "./log.mjs"
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 打标(就地,与 `pushReal` 给 `ts` 打点是同一形体):`role === "assistant"` 的消息写 `originProvider = providerName`。
|
|
36
|
+
* provider 名不可得(`undefined` ∥ 空串)⇒ 不打标,原消息不动——出生点没有判据可写,就不写一个猜的名字。
|
|
37
|
+
* 返回入参消息本身(就地改过或原样),调用点按需取用。
|
|
38
|
+
*/
|
|
39
|
+
export function tagOriginProvider(msg, providerName) {
|
|
40
|
+
if (!msg || typeof msg !== "object" || Array.isArray(msg)) return msg
|
|
41
|
+
if (msg.role !== "assistant") return msg
|
|
42
|
+
if (typeof providerName !== "string" || providerName === "") return msg
|
|
43
|
+
msg.originProvider = providerName
|
|
44
|
+
return msg
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 隔离(§5.5.5 隔离表):先处理异来源私有字段,再对完整历史补缺键。零 IO、不改入参消息对象。
|
|
49
|
+
* 返回 `{ messages, reading }`。`thinkingMode` 与 `toolsDeclared` 必须显式传入布尔值;构造器不替调用方猜请求形态。
|
|
50
|
+
*/
|
|
51
|
+
export function quarantineForeignOrigin(messages, { providerName, spec, thinkingMode, toolsDeclared } = {}) {
|
|
52
|
+
if (typeof thinkingMode !== "boolean") {
|
|
53
|
+
throw new Error(`quarantineForeignOrigin: thinkingMode 必填且必须是布尔值——实收 ${JSON.stringify(thinkingMode)}`)
|
|
54
|
+
}
|
|
55
|
+
if (typeof toolsDeclared !== "boolean") {
|
|
56
|
+
throw new Error(`quarantineForeignOrigin: toolsDeclared 必填且必须是布尔值——实收 ${JSON.stringify(toolsDeclared)}`)
|
|
57
|
+
}
|
|
58
|
+
const reading = { strippedEcho: 0, retiredToolRounds: 0, filledMissingEcho: 0, droppedEmptyAssistant: 0, origins: [] }
|
|
59
|
+
if (!Array.isArray(messages)) return { messages, reading }
|
|
60
|
+
const present = new Set()
|
|
61
|
+
for (const m of messages) {
|
|
62
|
+
if (m && typeof m === "object" && typeof m.originProvider === "string" && m.originProvider) present.add(m.originProvider)
|
|
63
|
+
}
|
|
64
|
+
reading.origins = [...present].sort()
|
|
65
|
+
const current = typeof providerName === "string" && providerName ? providerName : ""
|
|
66
|
+
const required = spec?.reasoningEcho === "required"
|
|
67
|
+
const enforceEchoKey = required && thinkingMode && toolsDeclared
|
|
68
|
+
let out = null
|
|
69
|
+
for (let i = 0; i < messages.length; i += 1) {
|
|
70
|
+
const m = messages[i]
|
|
71
|
+
if (!m || typeof m !== "object" || Array.isArray(m) || m.role !== "assistant") {
|
|
72
|
+
if (out !== null) out.push(m)
|
|
73
|
+
continue
|
|
74
|
+
}
|
|
75
|
+
const origin = typeof m.originProvider === "string" ? m.originProvider : ""
|
|
76
|
+
// 异源 = 当前 provider 之外产出的回声;无标记与同源都不是异源。
|
|
77
|
+
const foreign = Boolean(current && origin && origin !== current)
|
|
78
|
+
let next = m
|
|
79
|
+
let changed = false
|
|
80
|
+
if (foreign) {
|
|
81
|
+
if ("reasoning_content" in next) {
|
|
82
|
+
const { reasoning_content, ...rest } = next
|
|
83
|
+
next = rest
|
|
84
|
+
reading.strippedEcho += 1
|
|
85
|
+
changed = true
|
|
86
|
+
}
|
|
87
|
+
if (Array.isArray(next.tool_calls)) {
|
|
88
|
+
let extra = 0
|
|
89
|
+
const tool_calls = next.tool_calls.map((tc) => {
|
|
90
|
+
if (!tc || typeof tc !== "object" || !("extra_content" in tc)) return tc
|
|
91
|
+
const { extra_content, ...rest } = tc
|
|
92
|
+
extra += 1
|
|
93
|
+
return rest
|
|
94
|
+
})
|
|
95
|
+
if (extra > 0) {
|
|
96
|
+
reading.strippedEcho += extra
|
|
97
|
+
next = { ...next, tool_calls }
|
|
98
|
+
changed = true
|
|
99
|
+
}
|
|
100
|
+
if (required && next.tool_calls.length > 0) {
|
|
101
|
+
const { tool_calls, ...pure } = next
|
|
102
|
+
next = pure
|
|
103
|
+
reading.strippedEcho += 1
|
|
104
|
+
reading.retiredToolRounds += 1
|
|
105
|
+
changed = true
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// 空 assistant 是服务端会拒的请求形(`assistant must not be empty`):判据挂在消息本身,
|
|
110
|
+
// 不挂在「这条消息这回有没有被改过」上。关思考打开旧会话时没有补键动作(`enforceEchoKey` 为假),
|
|
111
|
+
// 旧版本留下的空轮照样要退出请求副本——否则它会带着 `content: null` 上街。
|
|
112
|
+
// 它排在补键之前:要被丢掉的消息不该先被记一次补键。
|
|
113
|
+
const hasContent = (typeof next.content === "string" && next.content !== "")
|
|
114
|
+
|| (Array.isArray(next.content) && next.content.length > 0)
|
|
115
|
+
const hasEcho = typeof next.reasoning_content === "string" && next.reasoning_content !== ""
|
|
116
|
+
const hasTools = Array.isArray(next.tool_calls) && next.tool_calls.length > 0
|
|
117
|
+
if (!hasContent && !hasEcho && !hasTools) {
|
|
118
|
+
if (out === null) out = messages.slice(0, i)
|
|
119
|
+
reading.droppedEmptyAssistant += 1
|
|
120
|
+
continue
|
|
121
|
+
}
|
|
122
|
+
// 缺键才是缺陷(#2647 真机读数):`required` + 思考开 + 携带工具声明的请求里,每条 assistant 都要带键。
|
|
123
|
+
// 手里没有原文就写空串——空串是合法的「没有原文」编码,缺键才会被 400 打回;正文与工具轮都保留,
|
|
124
|
+
// 不再退轮(退轮只会白丢上下文,旧消息还要靠这一行补键才能上街)。键已是字符串(含空串)则不动。
|
|
125
|
+
if (enforceEchoKey && typeof next.reasoning_content !== "string") {
|
|
126
|
+
next = { ...next, reasoning_content: "" }
|
|
127
|
+
reading.filledMissingEcho += 1
|
|
128
|
+
changed = true
|
|
129
|
+
}
|
|
130
|
+
if (changed) {
|
|
131
|
+
if (out === null) out = messages.slice(0, i)
|
|
132
|
+
out.push(next)
|
|
133
|
+
} else if (out !== null) out.push(m)
|
|
134
|
+
}
|
|
135
|
+
return { messages: out === null ? messages : out, reading }
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* 补来源(§5.5.4 补行):槽 `activeProvider` 是**非空字符串**且与运行态 `agent.provider.name` 不同时,给无标记的 assistant
|
|
140
|
+
* 消息补 `originProvider = slotProvider`。空串与缺键都是「没有会话级证据」,一律不补;运行态名不可得时同样不补
|
|
141
|
+
* (没有「谁跟谁不同」可比,补来源就成了猜)。
|
|
142
|
+
* 入参 = 机读线本身(外层每个元素是一轮 `{ messages }`,见 `context-push.mjs` 头注),返回值同形。copy-on-write 分两层:
|
|
143
|
+
* 没有一条被改过时返回入参数组本身(同一引用);某一轮有改动时只换那一轮的 `{ messages }` 对象与它的内层副本,其余轮元素与消息仍是原对象。
|
|
144
|
+
*/
|
|
145
|
+
export function fillOriginFromSlot(history, { slotProvider, runtimeProviderName } = {}) {
|
|
146
|
+
if (!Array.isArray(history)) return history
|
|
147
|
+
const slot = typeof slotProvider === "string" ? slotProvider : ""
|
|
148
|
+
const runtime = typeof runtimeProviderName === "string" ? runtimeProviderName : ""
|
|
149
|
+
if (!slot || !runtime || slot === runtime) return history
|
|
150
|
+
let out = null
|
|
151
|
+
for (let t = 0; t < history.length; t += 1) {
|
|
152
|
+
const turn = history[t]
|
|
153
|
+
const messages = Array.isArray(turn?.messages) ? turn.messages : null
|
|
154
|
+
if (!messages) continue
|
|
155
|
+
let inner = null
|
|
156
|
+
for (let i = 0; i < messages.length; i += 1) {
|
|
157
|
+
const m = messages[i]
|
|
158
|
+
if (!m || typeof m !== "object" || Array.isArray(m) || m.role !== "assistant") continue
|
|
159
|
+
if (typeof m.originProvider === "string" && m.originProvider) continue
|
|
160
|
+
if (inner === null) inner = messages.slice()
|
|
161
|
+
inner[i] = { ...m, originProvider: slot }
|
|
162
|
+
}
|
|
163
|
+
if (inner) {
|
|
164
|
+
if (out === null) out = history.slice()
|
|
165
|
+
out[t] = { ...turn, messages: inner }
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return out === null ? history : out
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* 读数留痕(§5.5.6):隔离读数非零时记一条 `llm:origin-quarantine` 事件,字段 = 构造点、当前 provider 名与读数。
|
|
173
|
+
* 读数为零(没有一条被隔离)时不写事件——零读数不是一次隔离。fire-and-forget:`logEvent` 自身静默降级,主流程零影响。
|
|
174
|
+
*/
|
|
175
|
+
export function logOriginQuarantine({ site, providerName, reading } = {}) {
|
|
176
|
+
if (!reading) return
|
|
177
|
+
const strippedEcho = Number(reading.strippedEcho) || 0
|
|
178
|
+
const retiredToolRounds = Number(reading.retiredToolRounds) || 0
|
|
179
|
+
const filledMissingEcho = Number(reading.filledMissingEcho) || 0
|
|
180
|
+
if (strippedEcho === 0 && retiredToolRounds === 0 && filledMissingEcho === 0) return
|
|
181
|
+
logEvent("llm:origin-quarantine", {
|
|
182
|
+
site,
|
|
183
|
+
provider: typeof providerName === "string" && providerName ? providerName : undefined,
|
|
184
|
+
strippedEcho,
|
|
185
|
+
retiredToolRounds,
|
|
186
|
+
filledMissingEcho,
|
|
187
|
+
droppedEmptyAssistant: Number(reading.droppedEmptyAssistant) || 0,
|
|
188
|
+
origins: Array.isArray(reading.origins) ? reading.origins.join(",") : "",
|
|
189
|
+
})
|
|
190
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thincoder/core",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.3",
|
|
4
4
|
"description": "ThinCoder shared core — shared mechanism modules + shared prompt content (CLI ↔ VS Code extension).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"agent-tools/",
|
|
43
43
|
"browser/",
|
|
44
44
|
"doc-check/",
|
|
45
|
+
"doc-graph/",
|
|
45
46
|
"git/",
|
|
46
47
|
"mcp/",
|
|
47
48
|
"memory/",
|
|
@@ -50,6 +51,7 @@
|
|
|
50
51
|
"tools/",
|
|
51
52
|
"traces/",
|
|
52
53
|
"prompts/",
|
|
54
|
+
"knowledge/",
|
|
53
55
|
"tool-docs/"
|
|
54
56
|
]
|
|
55
57
|
}
|