feat: 迁移到 zod 4(dependabot #34) - #71
Open
Last-emo-boy wants to merge 4 commits into
Open
Conversation
- 所有包 zod ^3.25.76 -> ^4.4.3;plugin-sdk peer 放宽 ^3.0.0 || ^4.0.0 - codemod: z.record(value) -> z.record(z.string(), value)(zod4 要求显式 key schema;zod3 单参默认 key 即 z.string(),语义不变),144 文件 540 处 - 剩余 77 个 zod4 API 杂项错误将在后续提交逐项修复 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- tool-help + zod-schema-converter: _def.* -> 公开 .unwrap()/.element/.options/
.values/.valueType + _zod.def;删除已移除的 ZodEffects/ZodBranded 分支(改 ZodPipe);
ZodDefault.defaultValue 由函数改为值
- config/plugin-sdk/runtime-node: .default({}) -> .prefault({})(zod4 default 语义变更)
- tool-executor + report-summarize: ZodError.errors -> .issues;
SafeParseSuccess -> ZodSafeParseSuccess;invalid_enum_value -> 'invalid_value'
- shared runtime-control-plane: 两处 z.enum 加 as const(修 zod4 重载误匹配导致
枚举长度泄漏进推导类型,如 RuntimeTaskStatus 出现 5)
- packages 内 z.record codemod(7 处)
tsc 0 错误、npm run build(4 包 + emit)通过。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- zod-schema-converter: applyString/Number/ArrayChecks 改读 zod4 的 _zod.def.checks 结构(min_length/max_length/string_format/number_format/greater_than/less_than/ multiple_of),恢复 JSON schema 的 minLength/maxLength/format/minimum/integer 等约束; getSchemaGuidance 按 custom check 识别 refinement(ZodEffects 已移除)恢复 x-guidance - 测试期望更新到 zod4 默认消息:ZodError.errors->.issues; 'Expected object, received array'->'Invalid input: expected record...'; 数字 'Number must be >='->'Too small: expected number to be >=1'; 'Invalid enum value'->'Invalid option: expected one of'(自定义消息保持不变) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
将 zod 从 3.25.76 升级到 4.4.3,完成全量 API 迁移。对应 dependabot PR #34(运行时核心依赖、大版本迁移)。
迁移规模
主要变更
1. z.record 签名(540 + 7 处,codemod)
zod4 要求显式 key schema:
z.record(value)→z.record(z.string(), value)(zod3 单参默认 key 即z.string(),语义不变)。2. 内部 introspection 重写(
zod-schema-converter.ts、tool-help.ts)_def.*→ 公开.unwrap()/.element/.options/.values/.valueType+_zod.defZodEffects/ZodBranded分支(transform 改用ZodPipe)ZodDefault.defaultValue由函数改为值_zod.def.checks(min_length/max_length/string_format/number_format/greater_than/less_than/multiple_of),恢复 JSON schema 的 minLength/format/minimum/integer 等约束getSchemaGuidance按customcheck 识别 refinement,恢复x-guidance3.
.default({})→.prefault({})(config / plugin-sdk / runtime-node / external-re-bridge)zod4
.default()值需匹配 output;依赖嵌套默认填充的对象改用.prefault()(= zod3 旧 default 行为)。4. API 重命名 / 枚举推导
ZodError.errors→.issues;SafeParseSuccess→ZodSafeParseSuccess;ZodIssueCode.invalid_enum_value→'invalid_value'runtime-control-plane:两处z.enum加as const,修复 zod4 重载误匹配导致枚举长度泄漏进z.infer(如RuntimeTaskStatus出现5)5. 依赖
所有包 zod
^4.4.3;@rikune/plugin-sdkpeer 放宽^3.0.0 || ^4.0.0。6. 测试期望
3 处更新到 zod4 默认错误消息(
Invalid input: expected record.../Too small: expected number to be >=1/Invalid option: expected one of);自定义错误消息保持不变。验证
tsc --noEmit:0 错误(主项目 + 4 个 workspace 包)npm run build:通过;npm run lint:0 错误🤖 Generated with Claude Code