
供应商改了 API,前端不应该同时重写文本、卡片、引用和错误显示。BFF 的价值,是把供应商变化限制在适配层,并给页面一份稳定、可回归的公开契约。
Claude 官方发布日志确认:2026 年 10 月 21 日发布了新 API 版本及默认使用该版本的新 SDK。但本轮迁移指南页面不可读取,无法逐项核对具体字段。因此本文不猜测移除参数、默认值或兼容行为,也不声称迁移已经完成。
页面需要的是 UI 产物
公开契约可以包含 text、card、citation、tool-error 与 terminal,明确 schemaVersion、任务与卡片 ID。可编辑卡片还要保留用户版本,迟到生成不能覆盖已编辑值。具体供应商对象、原始错误和密钥不能直接透传。
拒绝、中途中断、结构非法、工具失败、正常完成应有不同终态。前端据此决定保留草稿、显示错误或允许重试,不能把“HTTP 返回成功”一律解释为业务完成。

先用离线夹具约束公开输出
下方的 kind 是自建的内部夹具,不是 Claude 响应字段。真正供应商适配器仍待官方迁移资料与锁定 SDK 验证。保存为 bff-contract.mjs,执行 node bff-contract.mjs:
import assert from "node:assert/strict";
function publicEvents(internal) {
const out = []; let terminal = false;
const emit = event => out.push({ schemaVersion: 1, ...event });
const fail = code => {
emit({ type: "tool-error", code });
emit({ type: "terminal", status: "failed" }); terminal = true;
};
for (const x of internal) {
if (terminal) break;
if (x.kind === "text" && typeof x.value === "string") {
emit({ type: "text", value: x.value });
} else if (x.kind === "card" && x.component === "ProductCard" &&
typeof x.id === "string" && typeof x.title === "string" &&
Number.isSafeInteger(x.baseUserVersion) && x.baseUserVersion >= 0) {
emit({ type: "card", id: x.id, component: x.component,
title: x.title, baseUserVersion: x.baseUserVersion });
} else if (x.kind === "reference") {
let url; try { url = new URL(x.url); } catch { fail("invalid-reference"); continue; }
if (url.protocol !== "https:" || url.username || url.password) {
fail("invalid-reference"); continue;
}
emit({ type: "citation", url: url.href });
} else if (x.kind === "refusal") {
emit({ type: "terminal", status: "refused" }); terminal = true;
} else if (x.kind === "end") {
emit({ type: "terminal", status: "completed" }); terminal = true;
} else fail("adapter-output-invalid");
}
if (!terminal) fail("missing-terminal");
return out;
}
const good = publicEvents([
{ kind: "text", value: "候选如下" },
{ kind: "card", id: "c1", component: "ProductCard", title: "演示", baseUserVersion: 1 },
{ kind: "end" }
]);
assert.equal(good.at(-1).status, "completed");
assert.equal(good[1].baseUserVersion, 1);
assert.equal(publicEvents([{ kind: "refusal", secret: "never-public" }]).at(-1).status, "refused");
assert.equal(publicEvents([{ kind: "reference", url: "javascript:alert(1)" }]).at(-1).status, "failed");
assert.equal(publicEvents([{ kind: "card", component: "Script" }])[0].code, "adapter-output-invalid");
assert.equal(publicEvents([{ kind: "text", value: "半条" }])[1].code, "missing-terminal");
assert.equal(JSON.stringify(publicEvents([{ kind: "error", secret: "never-public" }])).includes("never-public"), false);
console.log("offline public-contract fixtures passed; no Claude API invoked");
引用 URL 通过语法检查,不代表来源可信或内容正确。真实产品还需要来源策略、文本标签、权限、大小限制与引用完整性检查。卡片也需要字段白名单与业务校验,不能用这个小例子代替完整 schema。
升级分成两份清单
第一份是供应商清单:API 版本、SDK 版本、请求与返回字段、流事件、错误、权限和渠道。当前迁移页不可读的部分留缺证,不根据旧记忆填空。第二份是 UI 清单:文本是否完整,用户编辑是否保留,引用是否可用,拒绝和中断是否给出明确终态。
适配器回归至少重放用户编辑后收到旧卡片、供应商拒绝、中途工具失败三个场景。离线夹具证明页面契约稳定;真实 API 调用则确认适配字段与终态语义。两种证据不能互相冒充。
本轮已在 Node v26.3.0 执行公开输出夹具;没有调用 Claude,没有安装或升级 SDK,也未运行浏览器 Playwright。因而结论只到 BFF 契约设计,不能称 API 升级成功。
参考资料:Claude 发布日志,相关条目 2026-10-21、22;迁移指南,本轮不可读取,字段待核;Playwright 断言,滚动文档。采用前人工复核迁移指南与真实适配结果;当天仍属未来,不能补写未发生的体验。
转载自 CSDN-专业IT技术社区
原文链接:https://blog.csdn.net/cannonmonster01/article/details/169336775




