Skip to content

Commit c1b4e1f

Browse files
thdxractions-user
andauthored
Upgrade to Zod v4 (anomalyco#2605)
Co-authored-by: GitHub Action <action@github.com>
1 parent 89d820b commit c1b4e1f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1075
-1273
lines changed

bun.lock

Lines changed: 22 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cloud/core/src/util/fn.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { z } from "zod"
22

3-
export function fn<T extends z.ZodType, Result>(schema: T, cb: (input: z.output<T>) => Result) {
4-
const result = (input: z.input<T>) => {
3+
export function fn<T extends z.ZodType, Result>(schema: T, cb: (input: z.infer<T>) => Result) {
4+
const result = (input: z.infer<T>) => {
55
const parsed = schema.parse(input)
66
return cb(parsed)
77
}
8-
result.force = (input: z.input<T>) => cb(input)
8+
result.force = (input: z.infer<T>) => cb(input)
99
result.schema = schema
1010
return result
1111
}

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"ai": "5.0.8",
2525
"hono": "4.7.10",
2626
"typescript": "5.8.2",
27-
"zod": "3.25.76",
27+
"zod": "4.1.8",
2828
"remeda": "2.26.0",
2929
"solid-js": "1.9.9"
3030
}
@@ -33,7 +33,7 @@
3333
"pulumi-stripe": "0.0.24"
3434
},
3535
"devDependencies": {
36-
"prettier": "3.5.3",
36+
"prettier": "3.6.2",
3737
"sst": "3.17.13"
3838
},
3939
"repository": {
@@ -54,7 +54,7 @@
5454
"web-tree-sitter"
5555
],
5656
"overrides": {
57-
"zod": "3.25.76"
57+
"zod": "4.1.8"
5858
},
5959
"patchedDependencies": {
6060
"@solidjs/start@1.1.7": "patches/@solidjs%2Fstart@1.1.7.patch"

packages/opencode/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
},
2929
"dependencies": {
3030
"@clack/prompts": "1.0.0-alpha.1",
31+
"@hono/standard-validator": "0.1.5",
3132
"@hono/zod-validator": "catalog:",
3233
"@modelcontextprotocol/sdk": "1.15.1",
3334
"@openauthjs/openauth": "0.4.3",
@@ -40,7 +41,7 @@
4041
"diff": "8.0.2",
4142
"gray-matter": "4.0.3",
4243
"hono": "catalog:",
43-
"hono-openapi": "0.4.8",
44+
"hono-openapi": "1.0.7",
4445
"ignore": "7.0.5",
4546
"jsonc-parser": "3.3.1",
4647
"minimatch": "10.0.3",
@@ -54,7 +55,6 @@
5455
"web-tree-sitter": "0.22.6",
5556
"xdg-basedir": "5.1.0",
5657
"yargs": "18.0.0",
57-
"zod": "catalog:",
58-
"zod-openapi": "4.1.0"
58+
"zod": "catalog:"
5959
}
6060
}

packages/opencode/script/schema.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
#!/usr/bin/env bun
22

3-
import "zod-openapi/extend"
3+
import { z } from "zod/v4"
44
import { Config } from "../src/config/config"
5-
import { zodToJsonSchema } from "zod-to-json-schema"
65

76
const file = process.argv[2]
87
console.log(file)
98

10-
const result = zodToJsonSchema(Config.Info, {
9+
const result = z.toJSONSchema(Config.Info, {
1110
/**
1211
* We'll use the `default` values of the field as the only value in `examples`.
1312
* This will ensure no docs are needed to be read, as the configuration is
1413
* self-documenting.
1514
*
1615
* See https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-00#rfc.section.9.5
1716
*/
18-
postProcess(jsonSchema) {
19-
const schema = jsonSchema as typeof jsonSchema & {
20-
examples?: unknown[]
21-
}
17+
override(input) {
18+
const schema = input.jsonSchema
2219
if (schema && typeof schema === "object" && "type" in schema && schema.type === "string" && schema?.default) {
2320
if (!schema.examples) {
2421
schema.examples = [schema.default]
@@ -29,8 +26,6 @@ const result = zodToJsonSchema(Config.Info, {
2926
.join("\n\n")
3027
.trim()
3128
}
32-
33-
return jsonSchema
3429
},
3530
}) as Record<string, unknown> & {
3631
allowComments?: boolean

packages/opencode/src/agent/agent.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Config } from "../config/config"
2-
import z from "zod"
2+
import z from "zod/v4"
33
import { Provider } from "../provider/provider"
44
import { generateObject, type ModelMessage } from "ai"
55
import PROMPT_GENERATE from "./generate.txt"
@@ -28,10 +28,10 @@ export namespace Agent {
2828
})
2929
.optional(),
3030
prompt: z.string().optional(),
31-
tools: z.record(z.boolean()),
31+
tools: z.record(z.string(), z.boolean()),
3232
options: z.record(z.string(), z.any()),
3333
})
34-
.openapi({
34+
.meta({
3535
ref: "Agent",
3636
})
3737
export type Info = z.infer<typeof Info>

packages/opencode/src/auth/github-copilot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { z } from "zod"
1+
import z from "zod/v4"
22
import { Auth } from "./index"
33
import { NamedError } from "../util/error"
44

packages/opencode/src/auth/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path from "path"
22
import { Global } from "../global"
33
import fs from "fs/promises"
4-
import { z } from "zod"
4+
import z from "zod/v4"
55

66
export namespace Auth {
77
export const Oauth = z
@@ -11,24 +11,24 @@ export namespace Auth {
1111
access: z.string(),
1212
expires: z.number(),
1313
})
14-
.openapi({ ref: "OAuth" })
14+
.meta({ ref: "OAuth" })
1515

1616
export const Api = z
1717
.object({
1818
type: z.literal("api"),
1919
key: z.string(),
2020
})
21-
.openapi({ ref: "ApiAuth" })
21+
.meta({ ref: "ApiAuth" })
2222

2323
export const WellKnown = z
2424
.object({
2525
type: z.literal("wellknown"),
2626
key: z.string(),
2727
token: z.string(),
2828
})
29-
.openapi({ ref: "WellKnownAuth" })
29+
.meta({ ref: "WellKnownAuth" })
3030

31-
export const Info = z.discriminatedUnion("type", [Oauth, Api, WellKnown]).openapi({ ref: "Auth" })
31+
export const Info = z.discriminatedUnion("type", [Oauth, Api, WellKnown]).meta({ ref: "Auth" })
3232
export type Info = z.infer<typeof Info>
3333

3434
const filepath = path.join(Global.Path.data, "auth.json")

packages/opencode/src/bun/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { z } from "zod"
1+
import z from "zod/v4"
22
import { Global } from "../global"
33
import { Log } from "../util/log"
44
import path from "path"

packages/opencode/src/bus/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { z, type ZodType } from "zod"
1+
import z from "zod/v4"
2+
import type { ZodType } from "zod/v4"
23
import { Log } from "../util/log"
34
import { Instance } from "../project/instance"
45

@@ -38,7 +39,7 @@ export namespace Bus {
3839
type: z.literal(type),
3940
properties: def.properties,
4041
})
41-
.openapi({
42+
.meta({
4243
ref: "Event" + "." + def.type,
4344
}),
4445
)

0 commit comments

Comments
 (0)