Skip to content

Commit 2dd5059

Browse files
deps: Upgrade to Zod 4 (#1461)
Co-authored-by: Charles Vien <charles.v@posthog.com>
1 parent be4db6f commit 2dd5059

File tree

8 files changed

+70
-81
lines changed

8 files changed

+70
-81
lines changed

.github/workflows/code-release.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,6 @@ jobs:
220220
env:
221221
GH_TOKEN: ${{ steps.app-token.outputs.token }}
222222
APP_VERSION: ${{ steps.version.outputs.version }}
223-
run: gh release edit "v$APP_VERSION" --repo PostHog/code --draft=false --generate-notes
223+
run: |
224+
gh api repos/PostHog/code/releases/generate-notes -f tag_name="v$APP_VERSION" --jq '.body' > /tmp/release-notes.md
225+
gh release edit "v$APP_VERSION" --repo PostHog/code --draft=false --notes-file /tmp/release-notes.md

apps/code/src/main/services/agent/schemas.ts

Lines changed: 41 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -63,50 +63,42 @@ export const modelOptionSchema = z.object({
6363

6464
export type ModelOption = z.infer<typeof modelOptionSchema>;
6565

66-
const sessionConfigSelectOptionSchema = z
67-
.object({
68-
value: z.string(),
69-
name: z.string(),
70-
description: z.string().nullish(),
71-
_meta: z.record(z.string(), z.unknown()).nullish(),
72-
})
73-
.passthrough();
74-
75-
const sessionConfigSelectGroupSchema = z
76-
.object({
77-
group: z.string(),
78-
name: z.string(),
79-
options: z.array(sessionConfigSelectOptionSchema),
80-
_meta: z.record(z.string(), z.unknown()).nullish(),
81-
})
82-
.passthrough();
83-
84-
const sessionConfigSelectSchema = z
85-
.object({
86-
id: z.string(),
87-
name: z.string(),
88-
type: z.literal("select"),
89-
currentValue: z.string(),
90-
options: z
91-
.array(sessionConfigSelectOptionSchema)
92-
.or(z.array(sessionConfigSelectGroupSchema)),
93-
category: z.string().nullish(),
94-
description: z.string().nullish(),
95-
_meta: z.record(z.string(), z.unknown()).nullish(),
96-
})
97-
.passthrough();
98-
99-
const sessionConfigBooleanSchema = z
100-
.object({
101-
id: z.string(),
102-
name: z.string(),
103-
type: z.literal("boolean"),
104-
currentValue: z.boolean(),
105-
category: z.string().nullish(),
106-
description: z.string().nullish(),
107-
_meta: z.record(z.string(), z.unknown()).nullish(),
108-
})
109-
.passthrough();
66+
const sessionConfigSelectOptionSchema = z.looseObject({
67+
value: z.string(),
68+
name: z.string(),
69+
description: z.string().nullish(),
70+
_meta: z.record(z.string(), z.unknown()).nullish(),
71+
});
72+
73+
const sessionConfigSelectGroupSchema = z.looseObject({
74+
group: z.string(),
75+
name: z.string(),
76+
options: z.array(sessionConfigSelectOptionSchema),
77+
_meta: z.record(z.string(), z.unknown()).nullish(),
78+
});
79+
80+
const sessionConfigSelectSchema = z.looseObject({
81+
id: z.string(),
82+
name: z.string(),
83+
type: z.literal("select"),
84+
currentValue: z.string(),
85+
options: z
86+
.array(sessionConfigSelectOptionSchema)
87+
.or(z.array(sessionConfigSelectGroupSchema)),
88+
category: z.string().nullish(),
89+
description: z.string().nullish(),
90+
_meta: z.record(z.string(), z.unknown()).nullish(),
91+
});
92+
93+
const sessionConfigBooleanSchema = z.looseObject({
94+
id: z.string(),
95+
name: z.string(),
96+
type: z.literal("boolean"),
97+
currentValue: z.boolean(),
98+
category: z.string().nullish(),
99+
description: z.string().nullish(),
100+
_meta: z.record(z.string(), z.unknown()).nullish(),
101+
});
110102

111103
export const sessionConfigOptionSchema = z.union([
112104
sessionConfigSelectSchema,
@@ -124,13 +116,11 @@ export const sessionResponseSchema = z.object({
124116
export type SessionResponse = z.infer<typeof sessionResponseSchema>;
125117

126118
// Prompt input/output
127-
export const contentBlockSchema = z
128-
.object({
129-
type: z.string(),
130-
text: z.string().optional(),
131-
_meta: z.record(z.string(), z.unknown()).nullish(),
132-
})
133-
.passthrough();
119+
export const contentBlockSchema = z.looseObject({
120+
type: z.string(),
121+
text: z.string().optional(),
122+
_meta: z.record(z.string(), z.unknown()).nullish(),
123+
});
134124

135125
export const promptInput = z.object({
136126
sessionId: z.string(),

apps/code/src/main/services/oauth/schemas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,6 @@ export const cancelFlowOutput = z.object({
6666
export type CancelFlowOutput = z.infer<typeof cancelFlowOutput>;
6767

6868
export const openExternalUrlInput = z.object({
69-
url: z.string().url(),
69+
url: z.url(),
7070
});
7171
export type OpenExternalUrlInput = z.infer<typeof openExternalUrlInput>;

packages/agent/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
"tar": "^7.5.0",
113113
"uuid": "13.0.0",
114114
"yoga-wasm-web": "^0.3.3",
115-
"zod": "^3.24.1"
115+
"zod": "^4.2.0"
116116
},
117117
"files": [
118118
"dist/**/*",

packages/agent/src/server/bin.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,21 @@ import { claudeCodeConfigSchema, mcpServersSchema } from "./schemas";
77
const envSchema = z.object({
88
JWT_PUBLIC_KEY: z
99
.string({
10-
required_error:
11-
"JWT_PUBLIC_KEY is required for authenticating client connections",
10+
error: "JWT_PUBLIC_KEY is required for authenticating client connections",
1211
})
1312
.min(1, "JWT_PUBLIC_KEY cannot be empty"),
14-
POSTHOG_API_URL: z
15-
.string({
16-
required_error:
17-
"POSTHOG_API_URL is required for LLM gateway communication",
18-
})
19-
.url("POSTHOG_API_URL must be a valid URL"),
13+
POSTHOG_API_URL: z.url({
14+
error: "POSTHOG_API_URL is required for LLM gateway communication",
15+
}),
2016
POSTHOG_PERSONAL_API_KEY: z
2117
.string({
22-
required_error:
18+
error:
2319
"POSTHOG_PERSONAL_API_KEY is required for authenticating with PostHog services",
2420
})
2521
.min(1, "POSTHOG_PERSONAL_API_KEY cannot be empty"),
2622
POSTHOG_PROJECT_ID: z
2723
.string({
28-
required_error:
24+
error:
2925
"POSTHOG_PROJECT_ID is required for routing requests to the correct project",
3026
})
3127
.regex(/^\d+$/, "POSTHOG_PROJECT_ID must be a numeric string")
@@ -34,7 +30,7 @@ const envSchema = z.object({
3430

3531
const program = new Command();
3632

37-
function parseJsonOption<S extends z.ZodTypeAny>(
33+
function parseJsonOption<S extends z.ZodType>(
3834
raw: string | undefined,
3935
schema: S,
4036
flag: string,

packages/agent/src/server/schemas.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const httpHeaderSchema = z.object({
88
const remoteMcpServerSchema = z.object({
99
type: z.enum(["http", "sse"]),
1010
name: z.string().min(1, "MCP server name is required"),
11-
url: z.string().url("MCP server url must be a valid URL"),
11+
url: z.url({ error: "MCP server url must be a valid URL" }),
1212
headers: z.array(httpHeaderSchema).default([]),
1313
});
1414

@@ -35,7 +35,7 @@ export const claudeCodeConfigSchema = z.object({
3535
export const jsonRpcRequestSchema = z.object({
3636
jsonrpc: z.literal("2.0"),
3737
method: z.string(),
38-
params: z.record(z.unknown()).optional(),
38+
params: z.record(z.string(), z.unknown()).optional(),
3939
id: z.union([z.string(), z.number()]).optional(),
4040
});
4141

packages/electron-trpc/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"typescript": "^5.8.3",
3939
"vite": "^6.0.7",
4040
"vitest": "^2.1.8",
41-
"zod": "^3.24.1"
41+
"zod": "^4.2.0"
4242
},
4343
"peerDependencies": {
4444
"@trpc/client": ">=11.0.0",

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)