Upgrade to Zod v4 (#2605)

Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
Dax 2025-09-15 03:12:07 -04:00 • committed by GitHub
commit c1b4e1f19d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
55 changed files with 1075 additions and 1273 deletions

View file

@ -28,6 +28,7 @@
},
"dependencies": {
"@clack/prompts": "1.0.0-alpha.1",
"@hono/standard-validator": "0.1.5",
"@hono/zod-validator": "catalog:",
"@modelcontextprotocol/sdk": "1.15.1",
"@openauthjs/openauth": "0.4.3",
@ -40,7 +41,7 @@
"diff": "8.0.2",
"gray-matter": "4.0.3",
"hono": "catalog:",
"hono-openapi": "0.4.8",
"hono-openapi": "1.0.7",
"ignore": "7.0.5",
"jsonc-parser": "3.3.1",
"minimatch": "10.0.3",
@ -54,7 +55,6 @@
"web-tree-sitter": "0.22.6",
"xdg-basedir": "5.1.0",
"yargs": "18.0.0",
"zod": "catalog:",
"zod-openapi": "4.1.0"
"zod": "catalog:"
}
}

View file

@ -1,13 +1,12 @@
#!/usr/bin/env bun
import "zod-openapi/extend"
import { z } from "zod/v4"
import { Config } from "../src/config/config"
import { zodToJsonSchema } from "zod-to-json-schema"
const file = process.argv[2]
console.log(file)
const result = zodToJsonSchema(Config.Info, {
const result = z.toJSONSchema(Config.Info, {
/**
* We'll use the `default` values of the field as the only value in `examples`.
* This will ensure no docs are needed to be read, as the configuration is
@ -15,10 +14,8 @@ const result = zodToJsonSchema(Config.Info, {
*
* See https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-00#rfc.section.9.5
*/
postProcess(jsonSchema) {
const schema = jsonSchema as typeof jsonSchema & {
examples?: unknown[]
}
override(input) {
const schema = input.jsonSchema
if (schema && typeof schema === "object" && "type" in schema && schema.type === "string" && schema?.default) {
if (!schema.examples) {
schema.examples = [schema.default]
@ -29,8 +26,6 @@ const result = zodToJsonSchema(Config.Info, {
.join("\n\n")
.trim()
}
return jsonSchema
},
}) as Record<string, unknown> & {
allowComments?: boolean

View file

@ -1,5 +1,5 @@
import { Config } from "../config/config"
import z from "zod"
import z from "zod/v4"
import { Provider } from "../provider/provider"
import { generateObject, type ModelMessage } from "ai"
import PROMPT_GENERATE from "./generate.txt"
@ -28,10 +28,10 @@ export namespace Agent {
})
.optional(),
prompt: z.string().optional(),
tools: z.record(z.boolean()),
tools: z.record(z.string(), z.boolean()),
options: z.record(z.string(), z.any()),
})
.openapi({
.meta({
ref: "Agent",
})
export type Info = z.infer<typeof Info>

View file

@ -1,4 +1,4 @@
import { z } from "zod"
import z from "zod/v4"
import { Auth } from "./index"
import { NamedError } from "../util/error"

View file

@ -1,7 +1,7 @@
import path from "path"
import { Global } from "../global"
import fs from "fs/promises"
import { z } from "zod"
import z from "zod/v4"
export namespace Auth {
export const Oauth = z
@ -11,14 +11,14 @@ export namespace Auth {
access: z.string(),
expires: z.number(),
})
.openapi({ ref: "OAuth" })
.meta({ ref: "OAuth" })
export const Api = z
.object({
type: z.literal("api"),
key: z.string(),
})
.openapi({ ref: "ApiAuth" })
.meta({ ref: "ApiAuth" })
export const WellKnown = z
.object({
@ -26,9 +26,9 @@ export namespace Auth {
key: z.string(),
token: z.string(),
})
.openapi({ ref: "WellKnownAuth" })
.meta({ ref: "WellKnownAuth" })
export const Info = z.discriminatedUnion("type", [Oauth, Api, WellKnown]).openapi({ ref: "Auth" })
export const Info = z.discriminatedUnion("type", [Oauth, Api, WellKnown]).meta({ ref: "Auth" })
export type Info = z.infer<typeof Info>
const filepath = path.join(Global.Path.data, "auth.json")

View file

@ -1,4 +1,4 @@
import { z } from "zod"
import z from "zod/v4"
import { Global } from "../global"
import { Log } from "../util/log"
import path from "path"

View file

@ -1,4 +1,5 @@
import { z, type ZodType } from "zod"
import z from "zod/v4"
import type { ZodType } from "zod/v4"
import { Log } from "../util/log"
import { Instance } from "../project/instance"
@ -38,7 +39,7 @@ export namespace Bus {
type: z.literal(type),
properties: def.properties,
})
.openapi({
.meta({
ref: "Event" + "." + def.type,
}),
)

View file

@ -1,4 +1,4 @@
import { z } from "zod"
import z from "zod/v4"
import { EOL } from "os"
import { NamedError } from "../util/error"

View file

@ -1,4 +1,4 @@
import z from "zod"
import z from "zod/v4"
import { Config } from "../config/config"
import { Instance } from "../project/instance"
@ -12,7 +12,7 @@ export namespace Command {
template: z.string(),
subtask: z.boolean().optional(),
})
.openapi({
.meta({
ref: "Command",
})
export type Info = z.infer<typeof Info>

View file

@ -1,7 +1,7 @@
import { Log } from "../util/log"
import path from "path"
import os from "os"
import { z } from "zod"
import z from "zod/v4"
import { Filesystem } from "../util/filesystem"
import { ModelsDev } from "../provider/models"
import { mergeDeep, pipe } from "remeda"
@ -217,7 +217,7 @@ export namespace Config {
enabled: z.boolean().optional().describe("Enable or disable the MCP server on startup"),
})
.strict()
.openapi({
.meta({
ref: "McpLocalConfig",
})
@ -229,7 +229,7 @@ export namespace Config {
headers: z.record(z.string(), z.string()).optional().describe("Headers to send with the request"),
})
.strict()
.openapi({
.meta({
ref: "McpRemoteConfig",
})
@ -267,7 +267,7 @@ export namespace Config {
.optional(),
})
.catchall(z.any())
.openapi({
.meta({
ref: "AgentConfig",
})
export type Agent = z.infer<typeof Agent>
@ -342,7 +342,7 @@ export namespace Config {
messages_revert: z.string().optional().default("none").describe("@deprecated use messages_undo. Revert message"),
})
.strict()
.openapi({
.meta({
ref: "KeybindsConfig",
})
@ -350,7 +350,7 @@ export namespace Config {
scroll_speed: z.number().min(1).optional().default(2).describe("TUI scroll speed"),
})
export const Layout = z.enum(["auto", "stretch"]).openapi({
export const Layout = z.enum(["auto", "stretch"]).meta({
ref: "LayoutConfig",
})
export type Layout = z.infer<typeof Layout>
@ -407,9 +407,10 @@ export namespace Config {
.describe("Agent configuration, see https://opencode.ai/docs/agent"),
provider: z
.record(
z.string(),
ModelsDev.Provider.partial()
.extend({
models: z.record(ModelsDev.Model.partial()).optional(),
models: z.record(z.string(), ModelsDev.Model.partial()).optional(),
options: z
.object({
apiKey: z.string().optional(),
@ -505,7 +506,7 @@ export namespace Config {
.optional(),
})
.strict()
.openapi({
.meta({
ref: "Config",
})
@ -644,7 +645,7 @@ export namespace Config {
"ConfigInvalidError",
z.object({
path: z.string(),
issues: z.custom<z.ZodIssue[]>().optional(),
issues: z.custom<z.core.$ZodIssue[]>().optional(),
message: z.string().optional(),
}),
)

View file

@ -1,7 +1,7 @@
import path from "path"
import { Global } from "../global"
import fs from "fs/promises"
import { z } from "zod"
import z from "zod/v4"
import { NamedError } from "../util/error"
import { lazy } from "../util/lazy"
import { Log } from "../util/log"

View file

@ -1,4 +1,4 @@
import { z } from "zod"
import z from "zod/v4"
import { Bus } from "../bus"
import { $ } from "bun"
import { formatPatch, structuredPatch } from "diff"
@ -18,7 +18,7 @@ export namespace File {
removed: z.number().int(),
status: z.enum(["added", "deleted", "modified"]),
})
.openapi({
.meta({
ref: "File",
})
@ -32,7 +32,7 @@ export namespace File {
type: z.enum(["file", "directory"]),
ignored: z.boolean(),
})
.openapi({
.meta({
ref: "FileNode",
})
export type Node = z.infer<typeof Node>
@ -60,7 +60,7 @@ export namespace File {
})
.optional(),
})
.openapi({
.meta({
ref: "FileContent",
})
export type Content = z.infer<typeof Content>

View file

@ -2,7 +2,7 @@
import path from "path"
import { Global } from "../global"
import fs from "fs/promises"
import { z } from "zod"
import z from "zod/v4"
import { NamedError } from "../util/error"
import { lazy } from "../util/lazy"
import { $ } from "bun"

View file

@ -1,4 +1,4 @@
import { z } from "zod"
import z from "zod/v4"
import { Bus } from "../bus"
import fs from "fs"
import { Log } from "../util/log"

View file

@ -1,4 +1,4 @@
import { z } from "zod"
import z from "zod/v4"
import { randomBytes } from "crypto"
export namespace Identifier {

View file

@ -1,5 +1,5 @@
import { spawn } from "bun"
import { z } from "zod"
import z from "zod/v4"
import { NamedError } from "../util/error"
import { Log } from "../util/log"
import { Bus } from "../bus"

View file

@ -1,4 +1,3 @@
import "zod-openapi/extend"
import yargs from "yargs"
import { hideBin } from "yargs/helpers"
import { RunCommand } from "./cli/cmd/run"

View file

@ -1,6 +1,6 @@
import path from "path"
import { $ } from "bun"
import { z } from "zod"
import z from "zod/v4"
import { NamedError } from "../util/error"
import { Bus } from "../bus"
import { Log } from "../util/log"
@ -28,7 +28,7 @@ export namespace Installation {
version: z.string(),
latest: z.string(),
})
.openapi({
.meta({
ref: "InstallationInfo",
})
export type Info = z.infer<typeof Info>

View file

@ -4,7 +4,7 @@ import type { Diagnostic as VSCodeDiagnostic } from "vscode-languageserver-types
import { Log } from "../util/log"
import { LANGUAGE_EXTENSIONS } from "./language"
import { Bus } from "../bus"
import z from "zod"
import z from "zod/v4"
import type { LSPServer } from "./server"
import { NamedError } from "../util/error"
import { withTimeout } from "../util/timeout"

View file

@ -2,7 +2,7 @@ import { Log } from "../util/log"
import { LSPClient } from "./client"
import path from "path"
import { LSPServer } from "./server"
import { z } from "zod"
import z from "zod/v4"
import { Config } from "../config/config"
import { spawn } from "child_process"
import { Instance } from "../project/instance"
@ -21,7 +21,7 @@ export namespace LSP {
character: z.number(),
}),
})
.openapi({
.meta({
ref: "Range",
})
export type Range = z.infer<typeof Range>
@ -35,7 +35,7 @@ export namespace LSP {
range: Range,
}),
})
.openapi({
.meta({
ref: "Symbol",
})
export type Symbol = z.infer<typeof Symbol>
@ -48,7 +48,7 @@ export namespace LSP {
range: Range,
selectionRange: Range,
})
.openapi({
.meta({
ref: "DocumentSymbol",
})
export type DocumentSymbol = z.infer<typeof DocumentSymbol>

Some files were not shown because too many files have changed in this diff Show more