Sfoglia il codice sorgente

fix(tui): 区分科研内部额度与实际 token 上限

预算卡片按服务端返回的具体额度给出建议,避免把字符或调用次数误报为 token 上限。

- 展示实际受限的配置项,兼容旧版预算响应。
- 超过平台可配置上限时提示缩小请求,不展示无效追加值。
- 展示测试 21 项通过,TUI 类型检查通过。
邵勃源 1 giorno fa
parent
commit
7f5eeba0aa

+ 5 - 1
packages/tui/src/util/agentpaas.ts

@@ -82,7 +82,11 @@ export function paasCard(metadata: Record<string, unknown>, input: Record<string
       record(acceptance?.plan_review)?.status === "not_reassessed" ? "原方案:本次未重审,原有待修订项继续保留;review-parent-gate.json" : "",
       text(science?.next_step) ? `下一步研究:${text(science?.next_step)}` : "",
       budget ? `科研预算:已用 ${number(budget.actual_tokens)} / 计划 ${number(budget.token_budget)} tokens;${text(budget.budget_message)}` : "",
-      record(budget?.extension_request) ? `追加建议:将 max_actual_tokens 调整至 ${number(record(budget?.extension_request)?.suggested_limit)} 后继续;未自动增加上限` : "",
+      record(budget?.extension_request)
+        ? record(budget?.extension_request)?.next_action === "reduce_next_request"
+          ? "下一步请求超过平台上限,请压缩上下文或缩小任务后继续"
+          : `追加建议:将 ${text(record(budget?.extension_request)?.option) || "max_actual_tokens"} 调整至 ${number(record(budget?.extension_request)?.suggested_limit)} 后继续;未自动增加上限`
+        : "",
       decisionSupport ? `验证选择:${number(decisionSupport.hypotheses)} 个假设、${number(decisionSupport.candidate_checks)} 项候选检查;未代表执行或独立验收;research-decisions.json 查看依据与缺口` : "",
       control?.continue_automatically === false ? "本次已停止;上述后续建议尚未自动执行,可在当前会话继续补充条件或反馈" : "",
       capabilities?.status === "plans_only_no_registered_input" ? "当前可生成研究计划;实际计算需先注册数据或选择模拟器" : "",

+ 13 - 0
packages/tui/test/util/agentpaas.test.ts

@@ -215,3 +215,16 @@ test("shows research soft overrun and the explicit hard-limit extension separate
   })
   expect(blocked.lines.join("\n")).toContain("300000 后继续;未自动增加上限")
 })
+
+test("research internal limits name their dimension rather than actual tokens", () => {
+  const card = paasCard({ status: "completed", research: { science: { budget: {
+    extension_request: { option: "max_total_input_chars", suggested_limit: 1200000 },
+  } } } })
+  expect(card.lines.join("\n")).toContain("将 max_total_input_chars 调整至 1200000")
+  expect(card.lines.join("\n")).not.toContain("将 max_actual_tokens")
+  const oversized = paasCard({ status: "completed", research: { science: { budget: {
+    extension_request: { option: "max_input_chars_per_call", suggested_limit: null, next_action: "reduce_next_request" },
+  } } } })
+  expect(oversized.lines.join("\n")).toContain("压缩上下文或缩小任务")
+  expect(oversized.lines.join("\n")).not.toContain("调整至")
+})