zcode-builtin-integrity.test.ts 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129
  1. import { readFile } from "node:fs/promises";
  2. import { compileModelOptionMaps } from "@zcode/model-option-map";
  3. import { fileURLToPath } from "node:url";
  4. import {
  5. ApiKeyAccessConfig,
  6. ModelConfigRules,
  7. ProviderConfig,
  8. ProviderApiConfig,
  9. ProviderConfigMap,
  10. ProviderConfigResolver,
  11. ZhipuAccountAccessConfig,
  12. } from "@zcode/provider";
  13. import { describe, expect, it } from "vitest";
  14. import { NodeZCodeBuiltinProviderConfigSource } from "../src/index.js";
  15. // 发布验证必须指向最终上传的那份文件,而不是默认悄悄检查仓库源文件。
  16. const zcodeBuiltinProviderConfigFilePath =
  17. process.env.ZCODE_BUILTIN_RELEASE_TEST_FILE?.trim() ||
  18. fileURLToPath(new URL("../../../config/provider/zcode-builtin.json", import.meta.url));
  19. function reasoningPatch(map: string, reasoningLevel: string) {
  20. return compileModelOptionMaps({ reasoningLevel: { map }, maxOutputTokens: { map: "{}" } }).apply(
  21. {},
  22. { reasoningLevel, maxOutputTokens: 32000 },
  23. );
  24. }
  25. describe("ZCode Built-in Provider Config 完整性", () => {
  26. it.each(["anthropic-messages", "openai-chat-completions", "openai-responses"] as const)(
  27. "未知模型在 %s 下拥有完整两档兜底并可进入 Registry",
  28. async (apiType) => {
  29. const source = new NodeZCodeBuiltinProviderConfigSource({
  30. bundledFilePath: zcodeBuiltinProviderConfigFilePath,
  31. watch: false,
  32. });
  33. try {
  34. const snapshot = await source.read();
  35. const model = snapshot.models.resolve({
  36. providerId: "unknown-provider",
  37. modelId: "future-unknown-model",
  38. apiType,
  39. baseUrl: "https://unknown.example/v1",
  40. });
  41. expect(model.validateComplete()).toEqual([]);
  42. expect(model.optionSpecs?.maxOutputTokens?.max).toBe(32_000);
  43. expect(model.optionSpecs?.reasoningLevel?.values).toEqual(["disabled", "enabled"]);
  44. expect(model.properties?.inputFormat.supportsImage).toBe(false);
  45. const result = new ProviderConfigResolver().resolve({
  46. zcodeBuiltinProviders: snapshot.providers,
  47. zcodeBuiltinProviderTemplates: snapshot.providerTemplates,
  48. accountProviders: ProviderConfigMap.empty(),
  49. zcodeBuiltinModelRules: snapshot.models,
  50. personalModels: ModelConfigRules.empty(),
  51. personalProviders: new ProviderConfigMap([
  52. [
  53. "unknown-provider",
  54. new ProviderConfig({
  55. group: "standard-personal",
  56. api: new ProviderApiConfig({
  57. type: apiType,
  58. baseUrl: "https://unknown.example/v1",
  59. }),
  60. access: new ApiKeyAccessConfig({ apiKey: "test-only" }),
  61. personalModelIds: ["future-unknown-model"],
  62. }),
  63. ],
  64. ]),
  65. });
  66. expect(
  67. result.registryProviders
  68. .find((entry) => entry.providerId === "unknown-provider")
  69. ?.models.map((entry) => entry.modelId),
  70. ).toContain("future-unknown-model");
  71. } finally {
  72. source.dispose();
  73. }
  74. },
  75. );
  76. it("GLM-5.3-Flash 的媒体输入能力及 GLM-5.3 的套餐桥接保持明确", async () => {
  77. const source = new NodeZCodeBuiltinProviderConfigSource({
  78. bundledFilePath: zcodeBuiltinProviderConfigFilePath,
  79. watch: false,
  80. });
  81. try {
  82. const snapshot = await source.read();
  83. const rawRelease = JSON.parse(await readFile(zcodeBuiltinProviderConfigFilePath, "utf8")) as {
  84. revision: number;
  85. config: { modelConfigRules: Record<string, unknown> };
  86. };
  87. expect(rawRelease.config.modelConfigRules).toMatchObject({
  88. modelRules: expect.any(Array),
  89. modelApiRules: expect.any(Array),
  90. providerSiteRules: expect.any(Array),
  91. templateModelRules: expect.any(Array),
  92. builtinProviderModelRules: expect.any(Array),
  93. });
  94. expect(rawRelease.config.modelConfigRules).not.toHaveProperty("matchRules");
  95. expect(snapshot.revision).toMatch(
  96. new RegExp(`^zcode-builtin:${rawRelease.revision}:[a-f0-9]{64}$`, "u"),
  97. );
  98. const apiTemplateIds = [
  99. "zai-api",
  100. "bigmodel-api",
  101. "zai-standard-api",
  102. "bigmodel-standard-api",
  103. ] as const;
  104. const accountProviderIds = [
  105. "account:zai-individual-coding-plan",
  106. "account:zai-team-coding-plan",
  107. "account:zai-start-plan",
  108. "account:bigmodel-individual-coding-plan",
  109. "account:bigmodel-team-coding-plan",
  110. "account:bigmodel-start-plan",
  111. "account:zai-offpeak-idle-plan",
  112. "account:bigmodel-offpeak-idle-plan",
  113. ] as const;
  114. for (const templateId of apiTemplateIds) {
  115. const modelIds = snapshot.providerTemplates?.get(templateId)?.config.builtinModelIds ?? [];
  116. expect(modelIds, `${templateId} 必须同时提供 GLM-5.3 系列`).toEqual(
  117. expect.arrayContaining(["GLM-5.3", "GLM-5.3-Flash"]),
  118. );
  119. }
  120. for (const providerId of accountProviderIds) {
  121. const modelIds = snapshot.providers.get(providerId)?.builtinModelIds ?? [];
  122. expect(modelIds, `${providerId} 必须提供 GLM-5.3-Flash`).toContain("GLM-5.3-Flash");
  123. }
  124. for (const providerId of [
  125. "account:zai-individual-coding-plan",
  126. "account:zai-team-coding-plan",
  127. "account:bigmodel-individual-coding-plan",
  128. "account:bigmodel-team-coding-plan",
  129. ]) {
  130. expect(snapshot.providers.get(providerId)?.builtinModelIds).toEqual([
  131. "GLM-5.3",
  132. "GLM-5.3-Flash",
  133. ]);
  134. const planModel = snapshot.models.resolve({
  135. providerId,
  136. modelId: "GLM-5.3",
  137. apiType: "anthropic-messages",
  138. baseUrl: snapshot.providers.get(providerId)?.api?.baseUrl,
  139. });
  140. expect(planModel.properties?.inputFormat.toJSON()).toMatchObject({
  141. supportsImage: true,
  142. supportsVideo: true,
  143. supportsAudio: false,
  144. supportsPdf: false,
  145. });
  146. }
  147. // 加速卡换端点不换模型,能力事实必须与同 Family Coding Plan 站点逐项一致;
  148. // 否则同一会话里普通轮与加速轮的 system 折叠、WebSearch 暴露和附件合法性会互相打脸。
  149. for (const [highspeedProviderId, planProviderId] of [
  150. ["account:zai-highspeed-card", "account:zai-individual-coding-plan"],
  151. ["account:bigmodel-highspeed-card", "account:bigmodel-individual-coding-plan"],
  152. ] as const) {
  153. const resolveAt = (providerId: string, modelId: string) =>
  154. snapshot.models.resolve({
  155. providerId,
  156. modelId,
  157. apiType: "anthropic-messages",
  158. baseUrl: snapshot.providers.get(providerId)?.api?.baseUrl,
  159. });
  160. expect(snapshot.providers.get(highspeedProviderId)?.builtinModelIds).toEqual(
  161. snapshot.providers.get(planProviderId)?.builtinModelIds,
  162. );
  163. for (const modelId of snapshot.providers.get(highspeedProviderId)?.builtinModelIds ?? []) {
  164. const highspeedModel = resolveAt(highspeedProviderId, modelId);
  165. const planModel = resolveAt(planProviderId, modelId);
  166. expect(
  167. highspeedModel.properties?.inputFormat.toJSON(),
  168. `${highspeedProviderId}/${modelId} 输入形态偏离 Coding Plan 站点`,
  169. ).toEqual(planModel.properties?.inputFormat.toJSON());
  170. expect(
  171. highspeedModel.properties?.supportsMidConversationSystem,
  172. `${highspeedProviderId}/${modelId} MCS 偏离 Coding Plan 站点`,
  173. ).toBe(planModel.properties?.supportsMidConversationSystem);
  174. expect(
  175. highspeedModel.properties?.supportsNativeWebSearch,
  176. `${highspeedProviderId}/${modelId} 原生搜索偏离 Coding Plan 站点`,
  177. ).toBe(planModel.properties?.supportsNativeWebSearch);
  178. }
  179. }
  180. const resolve = (modelId: string) =>
  181. snapshot.models.resolve({
  182. providerId: "personal-zai",
  183. templateId: "zai-api",
  184. modelId,
  185. apiType: "anthropic-messages",
  186. // 模型层自身能力与 §6.3.1 已批准的站点覆盖分开验证。
  187. baseUrl: "https://other.example.com/anthropic",
  188. });
  189. const glm53 = resolve("glm-5.3").toJSON();
  190. const glm53Flash = resolve("glm-5.3-flash").toJSON();
  191. expect(glm53.optionSpecs?.reasoningLevel).toMatchObject({
  192. values: ["low", "high", "max"],
  193. });
  194. expect(glm53.optionSpecs?.reasoningLevel?.map).toContain("reasoningLevel");
  195. expect(reasoningPatch(glm53.optionSpecs!.reasoningLevel!.map!, "low")).toMatchObject({
  196. output_config: { effort: "low" },
  197. });
  198. expect(glm53.properties?.inputFormat).toMatchObject({
  199. supportsImage: false,
  200. supportsVideo: false,
  201. });
  202. expect(glm53Flash).toEqual({
  203. ...glm53,
  204. properties: {
  205. ...glm53.properties,
  206. inputFormat: {
  207. ...glm53.properties?.inputFormat,
  208. supportsImage: true,
  209. supportsVideo: true,
  210. supportsPdf: true,
  211. },
  212. },
  213. });
  214. const glm53FlashChat = snapshot.models.resolve({
  215. providerId: "personal-zai",
  216. templateId: "zai-api",
  217. modelId: "glm-5.3-flash",
  218. apiType: "openai-chat-completions",
  219. baseUrl: "https://api.z.ai/api/anthropic",
  220. });
  221. expect(glm53FlashChat.properties?.inputFormat.supportsPdf).toBe(true);
  222. } finally {
  223. source.dispose();
  224. }
  225. });
  226. it("按当前官方证据声明各厂商主推模型和关键静态属性", async () => {
  227. const source = new NodeZCodeBuiltinProviderConfigSource({
  228. bundledFilePath: zcodeBuiltinProviderConfigFilePath,
  229. watch: false,
  230. });
  231. try {
  232. const snapshot = await source.read();
  233. expect(
  234. snapshot.providerTemplates?.get("moonshot-kimi")?.config.builtinModelIds.slice(0, 3),
  235. ).toEqual(["kimi-k3", "kimi-k2.7-code", "kimi-k2.6"]);
  236. expect(
  237. snapshot.providerTemplates?.get("minimax")?.config.builtinModelIds.slice(0, 3),
  238. ).toEqual(["MiniMax-M3", "MiniMax-M2.7", "MiniMax-M2.7-highspeed"]);
  239. for (const providerId of ["qwen-alibaba-model-studio-cn", "qwen-alibaba-model-studio-intl"]) {
  240. expect(
  241. snapshot.providerTemplates?.get(providerId)?.config.builtinModelIds.slice(0, 2),
  242. ).toEqual(["qwen3.8-max", "qwen3.8-flash"]);
  243. }
  244. expect(snapshot.providerTemplates?.get("openai")?.config.builtinModelIds.slice(0, 4)).toEqual(
  245. ["gpt-6-astra", "gpt-5.6-sol", "gpt-5.6-terra", "gpt-5.6-luna"],
  246. );
  247. const resolve = (
  248. providerId: string,
  249. modelId: string,
  250. apiType: "anthropic-messages" | "openai-chat-completions" | "openai-responses",
  251. baseUrl: string,
  252. ) => snapshot.models.resolve({ providerId, modelId, apiType, baseUrl });
  253. const qwen38 = resolve(
  254. "qwen-alibaba-model-studio-intl",
  255. "qwen3.8-flash",
  256. "openai-chat-completions",
  257. "https://dashscope-intl.aliyuncs.com/compatible-mode/v1",
  258. );
  259. expect(qwen38.properties?.toJSON()).toMatchObject({
  260. contextWindow: 1_000_000,
  261. inputFormat: {
  262. supportsText: true,
  263. supportsImage: true,
  264. supportsVideo: true,
  265. supportsAudio: false,
  266. supportsPdf: false,
  267. },
  268. supportsToolCall: true,
  269. supportsJsonSchemaOutput: true,
  270. });
  271. expect(qwen38.optionSpecs?.maxOutputTokens).toMatchObject({
  272. max: 131_072,
  273. });
  274. const mimo = resolve(
  275. "xiaomi-mimo",
  276. "mimo-v2.5",
  277. "anthropic-messages",
  278. "https://api.xiaomimimo.com/anthropic",
  279. );
  280. expect(mimo.properties?.inputFormat.toJSON()).toMatchObject({
  281. supportsImage: true,
  282. supportsVideo: true,
  283. supportsAudio: true,
  284. });
  285. const kimiCode = resolve(
  286. "moonshot-kimi",
  287. "kimi-k2.7-code",
  288. "anthropic-messages",
  289. "https://api.moonshot.cn/anthropic",
  290. );
  291. expect(kimiCode.properties?.contextWindow).toBe(262_144);
  292. expect(kimiCode.properties?.inputFormat.toJSON()).toMatchObject({
  293. supportsText: true,
  294. supportsImage: true,
  295. supportsVideo: true,
  296. });
  297. const kimiK3 = resolve(
  298. "moonshot-kimi",
  299. "kimi-k3",
  300. "anthropic-messages",
  301. "https://api.moonshot.cn/anthropic",
  302. );
  303. expect(kimiK3.properties?.toJSON()).toMatchObject({
  304. contextWindow: 1_048_576,
  305. inputFormat: {
  306. supportsText: true,
  307. supportsImage: true,
  308. supportsVideo: true,
  309. },
  310. });
  311. const kimiK3Compact = resolve(
  312. "moonshot-kimi",
  313. "k3-256k",
  314. "anthropic-messages",
  315. "https://api.kimi.com/coding/",
  316. );
  317. expect(kimiK3Compact.properties?.toJSON()).toMatchObject({
  318. contextWindow: 262_144,
  319. inputFormat: {
  320. supportsText: true,
  321. supportsImage: true,
  322. supportsVideo: false,
  323. },
  324. });
  325. const minimax = resolve(
  326. "minimax",
  327. "MiniMax-M2.7",
  328. "anthropic-messages",
  329. "https://api.minimaxi.com/anthropic",
  330. );
  331. expect(minimax.properties?.toJSON()).toMatchObject({
  332. contextWindow: 204_800,
  333. inputFormat: {
  334. supportsText: true,
  335. supportsImage: false,
  336. supportsVideo: false,
  337. },
  338. });
  339. const minimaxM3 = resolve(
  340. "minimax",
  341. "MiniMax-M3",
  342. "anthropic-messages",
  343. "https://api.minimaxi.com/anthropic",
  344. );
  345. expect(minimaxM3.properties?.toJSON()).toMatchObject({
  346. contextWindow: 1_000_000,
  347. inputFormat: {
  348. supportsText: true,
  349. supportsImage: true,
  350. supportsVideo: true,
  351. },
  352. });
  353. } finally {
  354. source.dispose();
  355. }
  356. });
  357. it("聚合供应商按维护清单提供独立模板,不复用上游 Provider 配置", async () => {
  358. const source = new NodeZCodeBuiltinProviderConfigSource({
  359. bundledFilePath: zcodeBuiltinProviderConfigFilePath,
  360. watch: false,
  361. });
  362. try {
  363. const snapshot = await source.read();
  364. const openrouter = snapshot.providerTemplates?.get("openrouter")?.config;
  365. expect(openrouter?.api?.type).toBe("anthropic-messages");
  366. expect(openrouter?.api?.baseUrl).toBe("https://openrouter.ai/api");
  367. expect(openrouter?.builtinModelIds).toEqual(
  368. expect.arrayContaining(["openai/gpt-5.6-sol", "anthropic/claude-opus-5", "z-ai/glm-5.3"]),
  369. );
  370. for (const templateId of [
  371. "opencode-zen-responses",
  372. "opencode-zen-messages",
  373. "opencode-zen-chat",
  374. ]) {
  375. expect(snapshot.providerTemplates?.has(templateId)).toBe(true);
  376. }
  377. } finally {
  378. source.dispose();
  379. }
  380. });
  381. it("聚合供应商同型号命中模型规则和 API Map,保留完整 ID 且每家至少启用一个代表型号", async () => {
  382. const source = new NodeZCodeBuiltinProviderConfigSource({
  383. bundledFilePath: zcodeBuiltinProviderConfigFilePath,
  384. watch: false,
  385. });
  386. try {
  387. const snapshot = await source.read();
  388. const pairs = [
  389. ["openai/gpt-5.6-sol", "gpt-5.6-sol"],
  390. ["anthropic/claude-opus-5", "claude-opus-5"],
  391. ["anthropic/claude-haiku-4.5", "claude-haiku-4-5-20251001"],
  392. ["deepseek/deepseek-v4-pro", "deepseek-v4-pro"],
  393. ["moonshotai/kimi-k3", "kimi-k3"],
  394. ["z-ai/glm-5.3", "glm-5.3"],
  395. ["qwen/qwen3.8-max", "qwen3.8-max"],
  396. ["minimax/minimax-m3", "MiniMax-M3"],
  397. ["xiaomi/mimo-v2.5-pro", "mimo-v2.5-pro"],
  398. ["x-ai/grok-4.6", "grok-4.6"],
  399. ];
  400. for (const [aggregateId, directId] of pairs) {
  401. const resolve = (modelId: string, templateId?: string) =>
  402. snapshot.models.resolve({
  403. providerId: "aggregate-instance",
  404. templateId,
  405. modelId,
  406. apiType: "anthropic-messages",
  407. baseUrl: "https://openrouter.ai/api",
  408. });
  409. const aggregate = resolve(aggregateId!, "openrouter");
  410. const direct = resolve(directId!);
  411. expect(aggregate.properties?.toJSON(), aggregateId).toEqual(direct.properties?.toJSON());
  412. expect(aggregate.optionSpecs?.toJSON(), aggregateId).toEqual(direct.optionSpecs?.toJSON());
  413. }
  414. for (const templateId of ["openrouter", "opencode-zen-messages", "opencode-zen-chat"]) {
  415. const template = snapshot.providerTemplates!.get(templateId)!.config;
  416. const enabledByVendor = new Map<string, boolean>();
  417. for (const modelId of template.builtinModelIds!) {
  418. const vendor =
  419. templateId === "openrouter" ? modelId.split("/")[0]! : modelId.split("-")[0]!;
  420. const model = snapshot.models.resolve({
  421. providerId: "aggregate-instance",
  422. templateId,
  423. modelId,
  424. apiType: template.api!.type,
  425. baseUrl: template.api!.baseUrl,
  426. });
  427. enabledByVendor.set(
  428. vendor,
  429. (enabledByVendor.get(vendor) ?? false) || model.enabled === true,
  430. );
  431. }
  432. for (const [vendor, enabled] of enabledByVendor)
  433. expect(enabled, `${templateId}/${vendor}`).toBe(true);
  434. }
  435. const haiku = snapshot.models.resolve({
  436. providerId: "zen",
  437. templateId: "opencode-zen-messages",
  438. modelId: "claude-haiku-4-5",
  439. apiType: "anthropic-messages",
  440. baseUrl: "https://opencode.ai/zen/v1",
  441. });
  442. expect(haiku.properties?.inputFormat.supportsImage).toBe(true);
  443. expect(haiku.properties?.contextWindow).toBe(200_000);
  444. } finally {
  445. source.dispose();
  446. }
  447. });
  448. it("每个 Provider 的默认 enabled 模型形成成员前缀,历史或 alias 型号默认关闭", async () => {
  449. const source = new NodeZCodeBuiltinProviderConfigSource({
  450. bundledFilePath: zcodeBuiltinProviderConfigFilePath,
  451. watch: false,
  452. });
  453. try {
  454. const snapshot = await source.read();
  455. const exactEnabled = new Map(
  456. snapshot.models
  457. .rules()
  458. .flatMap((rule) =>
  459. rule.config.enabled === undefined ||
  460. (rule.type !== "provider-model" && rule.type !== "template-model")
  461. ? []
  462. : [
  463. [
  464. `${rule.type === "provider-model" ? rule.providerId : rule.templateId}\0${rule.modelId}`,
  465. rule.config.enabled,
  466. ] as const,
  467. ],
  468. ),
  469. );
  470. const memberships = [
  471. ...snapshot.providers.entries(),
  472. ...(snapshot.providerTemplates
  473. ?.entries()
  474. .map(([id, template]) => [id, template.config] as const) ?? []),
  475. ];
  476. for (const [ownerId, owner] of memberships) {
  477. const states = (owner.builtinModelIds ?? []).map((modelId) => {
  478. const enabled = exactEnabled.get(`${ownerId}\0${modelId}`);
  479. expect(enabled, `${ownerId}/${modelId} 必须显式声明 Built-in 默认 enabled`).toBeTypeOf(
  480. "boolean",
  481. );
  482. return enabled!;
  483. });
  484. const firstDisabled = states.indexOf(false);
  485. if (firstDisabled >= 0) {
  486. expect(
  487. states.slice(firstDisabled).every((enabled) => !enabled),
  488. `${ownerId} 的 enabled 成员必须在 disabled 成员之前`,
  489. ).toBe(true);
  490. }
  491. }
  492. expect(exactEnabled.get("openai\0gpt-5.6")).toBe(false);
  493. expect(exactEnabled.get("openai\0gpt-5.6-sol")).toBe(true);
  494. expect(exactEnabled.get("minimax\0MiniMax-M3")).toBe(true);
  495. expect(exactEnabled.get("xai\0grok-4.3")).toBe(false);
  496. } finally {
  497. source.dispose();
  498. }
  499. });
  500. it("按产品分组声明 Zhipu 系统 Provider 与外部主流 Provider", async () => {
  501. const source = new NodeZCodeBuiltinProviderConfigSource({
  502. bundledFilePath: zcodeBuiltinProviderConfigFilePath,
  503. watch: false,
  504. });
  505. try {
  506. const snapshot = await source.read();
  507. expect(snapshot.providers.keys()).toEqual([
  508. "account:zai-individual-coding-plan",
  509. "account:zai-team-coding-plan",
  510. "account:zai-start-plan",
  511. "account:bigmodel-individual-coding-plan",
  512. "account:bigmodel-team-coding-plan",
  513. "account:bigmodel-start-plan",
  514. "account:zai-offpeak-idle-plan",
  515. "account:bigmodel-offpeak-idle-plan",
  516. "account:zai-highspeed-card",
  517. "account:bigmodel-highspeed-card",
  518. ]);
  519. expect(snapshot.providerTemplates?.keys()).toEqual([
  520. "zai-api",
  521. "zai-standard-api",
  522. "bigmodel-api",
  523. "bigmodel-standard-api",
  524. "moonshot-kimi",
  525. "minimax",
  526. "deepseek",
  527. "qwen-alibaba-model-studio-cn",
  528. "qwen-alibaba-model-studio-intl",
  529. "xiaomi-mimo",
  530. "openai",
  531. "anthropic",
  532. "xai",
  533. "openrouter",
  534. "opencode-go-chat",
  535. "opencode-go-messages",
  536. "opencode-go-responses",
  537. "opencode-zen-responses",
  538. "opencode-zen-messages",
  539. "opencode-zen-chat",
  540. ]);
  541. for (const [templateId, template] of snapshot.providerTemplates?.entries() ?? []) {
  542. expect(
  543. template.templateNameMap["zh-CN"]?.trim(),
  544. `${templateId} 缺少中文 Template 名称`,
  545. ).toBeTruthy();
  546. expect(
  547. template.templateNameMap["en-US"]?.trim(),
  548. `${templateId} 缺少英文 Template 名称`,
  549. ).toBeTruthy();
  550. expect(template.config.logo, `${templateId} 缺少 Built-in Logo 引用`).toMatchObject({
  551. type: "builtin",
  552. });
  553. }
  554. for (const [providerId, provider] of snapshot.providers.entries()) {
  555. expect(provider.logo, `${providerId} 缺少 Built-in Logo 引用`).toMatchObject({
  556. type: "builtin",
  557. });
  558. }
  559. expect(snapshot.providerTemplates?.get("moonshot-kimi")?.templateNameMap).toEqual({
  560. "zh-CN": "Kimi",
  561. "en-US": "Kimi",
  562. });
  563. expect(
  564. snapshot.providerTemplates?.get("qwen-alibaba-model-studio-cn")?.templateNameMap,
  565. ).toEqual({
  566. "zh-CN": "阿里云百炼(中国)",
  567. "en-US": "Alibaba Cloud (China)",
  568. });
  569. expect(
  570. snapshot.providerTemplates?.get("qwen-alibaba-model-studio-intl")?.templateNameMap,
  571. ).toEqual({
  572. "zh-CN": "阿里云百炼(国际)",
  573. "en-US": "Alibaba Cloud (Global)",
  574. });
  575. expect(snapshot.providerTemplates?.get("openai")?.config.toJSON()).toMatchObject({
  576. builtinModelIds: [
  577. "gpt-6-astra",
  578. "gpt-5.6-sol",
  579. "gpt-5.6-terra",
  580. "gpt-5.6-luna",
  581. "gpt-5.6",
  582. "gpt-5.4",
  583. "gpt-5.4-pro",
  584. "gpt-5.4-mini",
  585. "gpt-5.4-nano",
  586. "gpt-5.3-codex",
  587. ],
  588. access: {
  589. type: "api-key",
  590. apiKeyManagementUrl: "https://platform.openai.com/api-keys",
  591. },
  592. api: { type: "openai-responses", baseUrl: "https://api.openai.com/v1" },
  593. });
  594. expect(snapshot.providerTemplates?.get("anthropic")?.config.toJSON()).toMatchObject({
  595. builtinModelIds: [
  596. "claude-fable-5-1",
  597. "claude-fable-5",
  598. "claude-opus-5",
  599. "claude-sonnet-5",
  600. "claude-haiku-4-5-20251001",
  601. ],
  602. access: {
  603. type: "api-key",
  604. apiKeyManagementUrl: "https://console.anthropic.com/settings/keys",
  605. },
  606. api: { type: "anthropic-messages", baseUrl: "https://api.anthropic.com/v1" },
  607. });
  608. expect(snapshot.providerTemplates?.get("xai")?.config.toJSON()).toMatchObject({
  609. builtinModelIds: ["grok-4.6", "grok-build-0.1", "grok-4.3"],
  610. access: {
  611. type: "api-key",
  612. apiKeyManagementUrl: "https://console.x.ai",
  613. },
  614. api: { type: "openai-responses", baseUrl: "https://api.x.ai/v1" },
  615. });
  616. expect(snapshot.providerTemplates?.get("zai-api")?.config.toJSON()).toMatchObject({
  617. access: { type: "zhipu-coding-plan-api-key" },
  618. });
  619. expect(snapshot.providerTemplates?.get("bigmodel-api")?.config.toJSON()).toMatchObject({
  620. access: { type: "zhipu-coding-plan-api-key" },
  621. });
  622. } finally {
  623. source.dispose();
  624. }
  625. });
  626. it("按模型家族连续排列 Rule,且不保留语义等价的重复 matcher", async () => {
  627. const source = new NodeZCodeBuiltinProviderConfigSource({
  628. bundledFilePath: zcodeBuiltinProviderConfigFilePath,
  629. watch: false,
  630. });
  631. try {
  632. const rules = (await source.read()).models.rules().filter((rule) => rule.type === "match");
  633. const selectorKeys = rules.map((rule) =>
  634. JSON.stringify([
  635. rule.providerMatch ?? "",
  636. rule.modelMatch.toLowerCase(),
  637. rule.apiMatch ?? "",
  638. rule.baseUrlMatch ?? "",
  639. ]),
  640. );
  641. expect(new Set(selectorKeys).size).toBe(selectorKeys.length);
  642. // 分组后“模型家族连续”只约束 Model Rule 本组;把 Model/API/Site 三组拼起来会
  643. // 人为制造重复家族,无法再验证原本想检查的书写顺序。
  644. const rawRelease = JSON.parse(await readFile(zcodeBuiltinProviderConfigFilePath, "utf8")) as {
  645. config: { modelConfigRules: { modelRules: readonly { modelMatch: string }[] } };
  646. };
  647. const modelRules = rawRelease.config.modelConfigRules.modelRules;
  648. const familySequence = modelRules
  649. .map((rule) => builtinRuleFamily(rule))
  650. .filter((family, index, families) => family !== families[index - 1]);
  651. expect(familySequence).toEqual([
  652. "fallback",
  653. "glm",
  654. "gpt",
  655. "claude",
  656. "grok",
  657. "kimi",
  658. "minimax",
  659. "deepseek",
  660. "qwen",
  661. "mimo",
  662. ]);
  663. } finally {
  664. source.dispose();
  665. }
  666. });
  667. it("Reasoning 公开档位按语义强度从低到高排列", async () => {
  668. const source = new NodeZCodeBuiltinProviderConfigSource({
  669. bundledFilePath: zcodeBuiltinProviderConfigFilePath,
  670. watch: false,
  671. });
  672. try {
  673. const levelRank: Readonly<Record<string, number>> = {
  674. disabled: 0,
  675. none: 0,
  676. nothink: 0,
  677. off: 0,
  678. enabled: 1,
  679. minimal: 0.5,
  680. low: 1,
  681. medium: 2,
  682. high: 3,
  683. xhigh: 4,
  684. max: 5,
  685. };
  686. for (const rule of (await source.read()).models.rules()) {
  687. const values = rule.config.optionSpecs?.reasoningLevel?.values;
  688. if (!values) continue;
  689. const ranks = values.map((value) => levelRank[value]);
  690. expect(
  691. ranks.every((rank) => rank !== undefined),
  692. `${rule.modelMatch} 存在未知 Reasoning 档位,需先声明其顺序语义`,
  693. ).toBe(true);
  694. expect(
  695. ranks.every((rank, index) => index === 0 || rank! >= ranks[index - 1]!),
  696. `${rule.modelMatch} 的 Reasoning 档位必须从低到高排列`,
  697. ).toBe(true);
  698. }
  699. } finally {
  700. source.dispose();
  701. }
  702. });
  703. it("解析 OpenAI Responses 与 Anthropic Messages 的模型事实和 reasoning 映射", async () => {
  704. const source = new NodeZCodeBuiltinProviderConfigSource({
  705. bundledFilePath: zcodeBuiltinProviderConfigFilePath,
  706. watch: false,
  707. });
  708. try {
  709. const snapshot = await source.read();
  710. const openAi = snapshot.models.resolve({
  711. providerId: "openai",
  712. modelId: "gpt-5.6-sol",
  713. apiType: "openai-responses",
  714. baseUrl: "https://api.openai.com/v1",
  715. });
  716. expect(openAi.properties?.toJSON()).toMatchObject({
  717. requiresMfjsToolSchema: false,
  718. contextWindow: 1_050_000,
  719. inputFormat: {
  720. supportsText: true,
  721. supportsImage: true,
  722. supportsVideo: false,
  723. supportsAudio: false,
  724. supportsPdf: true,
  725. },
  726. outputFormat: { supportsText: true },
  727. supportsToolCall: true,
  728. supportsJsonSchemaOutput: true,
  729. supportsNativeWebSearch: false,
  730. supportsMidConversationSystem: false,
  731. });
  732. expect(openAi.optionSpecs?.reasoningLevel).toMatchObject({
  733. values: ["none", "low", "medium", "high", "xhigh", "max"],
  734. });
  735. for (const effort of ["xhigh", "max"]) {
  736. expect(reasoningPatch(openAi.optionSpecs!.reasoningLevel!.map!, effort)).toEqual({
  737. reasoning: { effort },
  738. });
  739. }
  740. const grok46 = snapshot.models.resolve({
  741. providerId: "xai",
  742. modelId: "grok-4.6",
  743. apiType: "openai-responses",
  744. baseUrl: "https://api.x.ai/v1",
  745. });
  746. expect(grok46.properties?.toJSON()).toMatchObject({
  747. requiresMfjsToolSchema: false,
  748. contextWindow: 500_000,
  749. inputFormat: {
  750. supportsText: true,
  751. supportsImage: true,
  752. supportsVideo: false,
  753. supportsAudio: false,
  754. supportsPdf: false,
  755. },
  756. outputFormat: { supportsText: true },
  757. supportsToolCall: true,
  758. supportsJsonSchemaOutput: true,
  759. supportsNativeWebSearch: false,
  760. supportsMidConversationSystem: false,
  761. });
  762. expect(grok46.optionSpecs?.reasoningLevel).toMatchObject({
  763. values: ["low", "medium", "high", "xhigh"],
  764. });
  765. expect(reasoningPatch(grok46.optionSpecs!.reasoningLevel!.map!, "xhigh")).toEqual({
  766. reasoning: { effort: "xhigh" },
  767. });
  768. const grokBuild = snapshot.models.resolve({
  769. providerId: "xai",
  770. modelId: "grok-build-0.1",
  771. apiType: "openai-responses",
  772. baseUrl: "https://api.x.ai/v1",
  773. });
  774. expect(grokBuild.properties?.toJSON()).toMatchObject({
  775. requiresMfjsToolSchema: false,
  776. contextWindow: 256_000,
  777. inputFormat: { supportsText: true, supportsImage: true },
  778. outputFormat: { supportsText: true },
  779. supportsToolCall: true,
  780. supportsJsonSchemaOutput: true,
  781. });
  782. const grok43 = snapshot.models.resolve({
  783. providerId: "xai",
  784. modelId: "grok-4.3",
  785. apiType: "openai-responses",
  786. baseUrl: "https://api.x.ai/v1",
  787. });
  788. expect(grok43.properties?.contextWindow).toBe(1_000_000);
  789. expect(grok43.optionSpecs?.reasoningLevel?.toJSON()).toMatchObject({
  790. // 此模型未声明专用档位,继续继承 Model 通用兜底。
  791. values: ["disabled", "enabled"],
  792. });
  793. expect(reasoningPatch(grok43.optionSpecs!.reasoningLevel!.map!, "disabled")).toEqual({
  794. reasoning: { effort: "none" },
  795. });
  796. const anthropic = snapshot.models.resolve({
  797. providerId: "anthropic",
  798. modelId: "claude-opus-5",
  799. apiType: "anthropic-messages",
  800. baseUrl: "https://api.anthropic.com/v1",
  801. });
  802. expect(anthropic.properties?.toJSON()).toMatchObject({
  803. requiresMfjsToolSchema: false,
  804. contextWindow: 1_000_000,
  805. inputFormat: {
  806. supportsText: true,
  807. supportsImage: true,
  808. supportsVideo: false,
  809. supportsAudio: false,
  810. supportsPdf: true,
  811. },
  812. outputFormat: { supportsText: true },
  813. supportsToolCall: true,
  814. supportsJsonSchemaOutput: true,
  815. supportsNativeWebSearch: true,
  816. supportsMidConversationSystem: true,
  817. });
  818. expect(anthropic.optionSpecs?.reasoningLevel).toMatchObject({
  819. values: ["low", "medium", "high", "xhigh", "max"],
  820. });
  821. expect(anthropic.optionSpecs?.reasoningLevel?.map).toContain("reasoningLevel");
  822. expect(reasoningPatch(anthropic.optionSpecs!.reasoningLevel!.map!, "max")).toMatchObject({
  823. output_config: { effort: "max" },
  824. });
  825. const deepSeek = snapshot.models.resolve({
  826. providerId: "deepseek",
  827. modelId: "deepseek-v4-flash",
  828. apiType: "anthropic-messages",
  829. baseUrl: "https://api.deepseek.com/anthropic",
  830. });
  831. expect(deepSeek.properties?.supportsJsonSchemaOutput).toBe(false);
  832. expect(deepSeek.optionSpecs?.reasoningLevel).toMatchObject({
  833. values: ["disabled", "low", "high", "max"],
  834. });
  835. expect(deepSeek.optionSpecs?.reasoningLevel?.map).toContain("reasoningLevel");
  836. expect(reasoningPatch(deepSeek.optionSpecs!.reasoningLevel!.map!, "low")).toMatchObject({
  837. output_config: { effort: "low" },
  838. });
  839. for (const modelId of ["qwen3.5-plus", "qwen3.5-flash", "qwen3-vl-plus"]) {
  840. expect(
  841. snapshot.models.resolve({
  842. providerId: "qwen-alibaba-model-studio-cn",
  843. modelId,
  844. apiType: "anthropic-messages",
  845. baseUrl: "https://dashscope.aliyuncs.com/apps/anthropic",
  846. }).properties?.supportsJsonSchemaOutput,
  847. ).toBe(false);
  848. }
  849. const deepSeekResponses = snapshot.models.resolve({
  850. providerId: "deepseek",
  851. modelId: "deepseek-v4-pro",
  852. apiType: "openai-responses",
  853. baseUrl: "https://api.deepseek.com",
  854. });
  855. expect(deepSeekResponses.properties?.supportsJsonSchemaOutput).toBe(true);
  856. expect(reasoningPatch(deepSeekResponses.optionSpecs!.reasoningLevel!.map!, "max")).toEqual({
  857. reasoning: { effort: "max" },
  858. });
  859. } finally {
  860. source.dispose();
  861. }
  862. });
  863. it("每个 Built-in Provider 与模型成员都完整,启用成员在补齐访问材料后进入正式 Registry", async () => {
  864. const source = new NodeZCodeBuiltinProviderConfigSource({
  865. bundledFilePath: zcodeBuiltinProviderConfigFilePath,
  866. watch: false,
  867. });
  868. try {
  869. const snapshot = await source.read();
  870. const accountProviders: [string, ProviderConfig][] = [];
  871. const personalProviders: Array<{
  872. providerId: string;
  873. templateId: string;
  874. config: ProviderConfig;
  875. }> = [];
  876. const expectedModelIds = new Map<string, readonly string[]>();
  877. for (const [providerId, provider] of snapshot.providers.entries()) {
  878. const builtinModelIds = provider.builtinModelIds ?? [];
  879. expect(new Set(builtinModelIds).size, `${providerId} 存在重复 Built-in 模型成员`).toBe(
  880. builtinModelIds.length,
  881. );
  882. const enabledModelIds = builtinModelIds.filter((modelId) => {
  883. const model = snapshot.models.resolve({
  884. providerId,
  885. modelId,
  886. apiType: provider.api?.type,
  887. baseUrl: provider.api?.baseUrl,
  888. });
  889. expect(model.validateComplete(["providers", providerId, "models", modelId])).toEqual([]);
  890. return model.enabled !== false;
  891. });
  892. expectedModelIds.set(providerId, enabledModelIds);
  893. if (provider.access?.type === "zhipu-account") {
  894. accountProviders.push([
  895. providerId,
  896. new ProviderConfig({
  897. access: new ZhipuAccountAccessConfig({ entitled: true }),
  898. }),
  899. ]);
  900. }
  901. }
  902. for (const [templateId, template] of snapshot.providerTemplates?.entries() ?? []) {
  903. const providerId = `template:${templateId}`;
  904. const builtinModelIds = template.config.builtinModelIds ?? [];
  905. expect(new Set(builtinModelIds).size, `${templateId} 存在重复 Template 模型成员`).toBe(
  906. builtinModelIds.length,
  907. );
  908. const enabledModelIds = builtinModelIds.filter((modelId) => {
  909. const model = snapshot.models.resolve({
  910. providerId,
  911. templateId,
  912. modelId,
  913. apiType: template.config.api?.type,
  914. baseUrl: template.config.api?.baseUrl,
  915. });
  916. expect(model.validateComplete(["templates", templateId, "models", modelId])).toEqual([]);
  917. return model.enabled !== false;
  918. });
  919. expectedModelIds.set(providerId, enabledModelIds);
  920. expect(["api-key", "zhipu-coding-plan-api-key"]).toContain(template.config.access?.type);
  921. if (template.config.access?.type !== "zhipu-account") {
  922. expect(template.config.access.apiKey, `${templateId} 不得保存 API Key`).toBeUndefined();
  923. }
  924. personalProviders.push({
  925. providerId,
  926. templateId,
  927. config: new ProviderConfig({
  928. group: "standard-personal",
  929. access: new ApiKeyAccessConfig({
  930. type: template.config.access?.type,
  931. apiKey: `test-key-for-${templateId}`,
  932. }),
  933. }),
  934. });
  935. }
  936. const resolution = new ProviderConfigResolver().resolve({
  937. zcodeBuiltinProviders: snapshot.providers,
  938. zcodeBuiltinProviderTemplates: snapshot.providerTemplates,
  939. accountProviders: new ProviderConfigMap(accountProviders),
  940. personalProviders: new ProviderConfigMap(personalProviders),
  941. zcodeBuiltinModelRules: snapshot.models,
  942. personalModels: ModelConfigRules.empty(),
  943. });
  944. expect(resolution.issues).toEqual([]);
  945. expect(resolution.registryProviders.map(({ providerId }) => providerId)).toEqual([
  946. "account:zai-individual-coding-plan",
  947. "account:zai-team-coding-plan",
  948. "account:zai-start-plan",
  949. "account:bigmodel-individual-coding-plan",
  950. "account:bigmodel-team-coding-plan",
  951. "account:bigmodel-start-plan",
  952. "account:zai-offpeak-idle-plan",
  953. "account:bigmodel-offpeak-idle-plan",
  954. "account:zai-highspeed-card",
  955. "account:bigmodel-highspeed-card",
  956. "template:zai-api",
  957. "template:zai-standard-api",
  958. "template:bigmodel-api",
  959. "template:bigmodel-standard-api",
  960. "template:moonshot-kimi",
  961. "template:minimax",
  962. "template:deepseek",
  963. "template:qwen-alibaba-model-studio-cn",
  964. "template:qwen-alibaba-model-studio-intl",
  965. "template:xiaomi-mimo",
  966. "template:openai",
  967. "template:anthropic",
  968. "template:xai",
  969. "template:openrouter",
  970. "template:opencode-go-chat",
  971. "template:opencode-go-messages",
  972. "template:opencode-go-responses",
  973. "template:opencode-zen-responses",
  974. "template:opencode-zen-messages",
  975. "template:opencode-zen-chat",
  976. ]);
  977. for (const provider of resolution.registryProviders) {
  978. expect(
  979. provider.models.map(({ modelId }) => modelId),
  980. `${provider.providerId} 的 Registry 模型成员必须与 Built-in Config 一致`,
  981. ).toEqual(expectedModelIds.get(provider.providerId));
  982. for (const model of provider.models) {
  983. expect(
  984. model.config.validateComplete([
  985. "providers",
  986. provider.providerId,
  987. "models",
  988. model.modelId,
  989. ]),
  990. ).toEqual([]);
  991. }
  992. }
  993. for (const providerId of [
  994. "account:zai-offpeak-idle-plan",
  995. "account:bigmodel-offpeak-idle-plan",
  996. ]) {
  997. const offPeak = resolution.resolvedProviders.find(
  998. (provider) => provider.providerId === providerId,
  999. );
  1000. expect(offPeak?.models).not.toHaveLength(0);
  1001. for (const model of offPeak?.models ?? []) {
  1002. expect(model).toMatchObject({ executable: true, selectable: false });
  1003. }
  1004. }
  1005. } finally {
  1006. source.dispose();
  1007. }
  1008. });
  1009. it("正式 Built-in JSON 不携带旧模型能力字段", async () => {
  1010. const document = JSON.parse(
  1011. await readFile(zcodeBuiltinProviderConfigFilePath, "utf8"),
  1012. ) as unknown;
  1013. const keys = collectObjectKeys(document);
  1014. expect(keys).not.toContain("apiKey");
  1015. expect(keys).not.toContain("modalities");
  1016. expect(keys).not.toContain("magic_name");
  1017. expect(keys).not.toContain("supportsImages");
  1018. // Todo104:supportsPdf/Video 是 inputFormat 内的正式字段,不能因同名误判成旧扁平能力。
  1019. for (const key of [
  1020. "input_format",
  1021. "output_format",
  1022. "support_text",
  1023. "support_image",
  1024. "support_pdf",
  1025. "support_video",
  1026. "support_audio",
  1027. ]) {
  1028. expect(keys).not.toContain(key);
  1029. }
  1030. expect(keys).not.toContain("budget_tokens");
  1031. expect(keys).not.toContain("budgetTokens");
  1032. });
  1033. });
  1034. function builtinRuleFamily(rule: {
  1035. readonly providerMatch?: string;
  1036. readonly modelMatch: string;
  1037. readonly apiMatch?: string;
  1038. readonly baseUrlMatch?: string;
  1039. }): string {
  1040. const provider = rule.providerMatch?.toLowerCase() ?? "";
  1041. const baseUrl = rule.baseUrlMatch?.toLowerCase() ?? "";
  1042. const model = rule.modelMatch.toLowerCase();
  1043. if (!provider && !baseUrl && (model === ".*" || (!rule.apiMatch && model === ".*\\[1m\\]"))) {
  1044. return "fallback";
  1045. }
  1046. if (provider.includes("github-copilot") || model.includes("gpt")) return "gpt";
  1047. if (provider === "anthropic" || model.includes("claude")) return "claude";
  1048. if (model.includes("grok")) return "grok";
  1049. if (provider === "moonshot-kimi" || /(?:kimi|moonshot|k3)/.test(model)) return "kimi";
  1050. if (model.includes("minimax")) return "minimax";
  1051. if (provider === "deepseek" || model.includes("deepseek")) return "deepseek";
  1052. if (model.includes("qwen")) return "qwen";
  1053. if (model.includes("mimo")) return "mimo";
  1054. if (
  1055. model.includes("glm") ||
  1056. model.includes("ox-alpha") ||
  1057. model.includes("codegeex") ||
  1058. model.includes("emohaa") ||
  1059. provider.includes("zai") ||
  1060. provider.includes("bigmodel") ||
  1061. provider.includes("offpeak-idle-plan") ||
  1062. baseUrl.includes("z\\.ai") ||
  1063. baseUrl.includes("bigmodel\\.cn")
  1064. ) {
  1065. return "glm";
  1066. }
  1067. return "cross-model";
  1068. }
  1069. function collectObjectKeys(value: unknown): string[] {
  1070. if (Array.isArray(value)) return value.flatMap(collectObjectKeys);
  1071. if (!value || typeof value !== "object") return [];
  1072. return Object.entries(value).flatMap(([key, child]) => [key, ...collectObjectKeys(child)]);
  1073. }