Skip to content

Add Zod validation to server actions and API chat route; replace root interfaces with Zod schemas#197

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/add-zod-validation-server-actions
Draft

Add Zod validation to server actions and API chat route; replace root interfaces with Zod schemas#197
Copilot wants to merge 2 commits intomainfrom
copilot/add-zod-validation-server-actions

Conversation

Copy link
Contributor

Copilot AI commented Mar 18, 2026

app/actions/ server action parameters and the app/api/chat/ POST body lacked runtime validation. Types like MarkdownSection, ReplCommand, etc. were defined as bare interfaces, requiring a separate schema to validate — so the types themselves are rewritten as Zod schemas with z.output<typeof schema>.

Type definitions replaced with Zod schemas

  • app/lib/docs.tsinterface PagePathPagePathSchema, interface MarkdownSectionMarkdownSectionSchema. Also adds ReplacedRangeSchema and DynamicMarkdownSectionSchema (consolidated here from client files to make schemas server-importable).
  • packages/runtime/src/interface.tsReplOutputType, ReplOutput, UpdatedFile, ReplCommand interfaces all replaced with Zod schemas + z.output<> types. Added zod to the package's deps.
  • app/markdown/multiHighlight.tsx / pageContent.tsx — local interface ReplacedRange / interface DynamicMarkdownSection removed; re-export the types from @/lib/docs.
// Before
export interface MarkdownSection { file: string; id: SectionId; ... }

// After
export const MarkdownSectionSchema = z.object({
  file: z.string(),
  id: z.string().transform((s) => s as SectionId),
  ...
});
export type MarkdownSection = z.output<typeof MarkdownSectionSchema>;

Validation added

  • app/api/chat/route.tstype ChatParams replaced by ChatParamsSchema (composed from all sub-schemas above); POST body is now validated via safeParse, returning HTTP 400 on invalid input.
  • app/actions/deleteChat.ts / app/actions/getRedirectFromChat.tschatId parameter validated with z.string().uuid() before use.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • workers.cloudflare.com
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node node_modules/.bin/next lint (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

- Replace `interface MarkdownSection`, `interface PagePath` in docs.ts
  with Zod schemas + `z.output<typeof schema>` types
- Add `ReplacedRangeSchema` and `DynamicMarkdownSectionSchema` to docs.ts,
  moving the type definitions out of the client-only pageContent.tsx
- Remove `interface ReplacedRange` from multiHighlight.tsx; re-export
  `ReplacedRange` type from @/lib/docs
- Remove `interface DynamicMarkdownSection` from pageContent.tsx; re-export
  `DynamicMarkdownSection` type from @/lib/docs
- Replace `ReplOutputType` union, `ReplOutput`, `UpdatedFile`, `ReplCommand`
  interfaces in packages/runtime/src/interface.ts with Zod schemas +
  `z.output<typeof schema>` types; add zod dependency to runtime package
- Replace `type ChatParams` in route.ts with `ChatParamsSchema` + Zod
  validation of POST request body (returns 400 on invalid input)
- Add `z.string().uuid()` validation to deleteChat and getRedirectFromChat
  server action parameters

Co-authored-by: na-trium-144 <100704180+na-trium-144@users.noreply.github.com>
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Mar 18, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
my-code 2d6a4d9 Commit Preview URL

Branch Preview URL
Mar 18 2026, 01:23 PM

Copilot AI changed the title [WIP] Add Zod validation for ServerAction parameters Add Zod validation to server actions and API chat route; replace root interfaces with Zod schemas Mar 18, 2026
Copilot AI requested a review from na-trium-144 March 18, 2026 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

server functionにバリデーション

2 participants