agent-nodejs icon indicating copy to clipboard operation
agent-nodejs copied to clipboard

feat(ai-proxy): add Zod validation for route bodies

Open Scra3 opened this issue 3 weeks ago • 2 comments

Summary

  • Add schemas.ts with Zod schemas for runtime route validation
  • Validate dispatchBody (ai-query route) - requires messages array with at least one message
  • Validate invokeRemoteToolBody - requires inputs array with at least one message
  • Validate invokeToolQuery - requires tool-name parameter
  • Use permissive validation with .passthrough() - validates structure, lets OpenAI SDK handle field details
  • Throw AIUnprocessableError with clear messages on validation failure

Files

  • New: packages/ai-proxy/src/schemas.ts - Zod schemas
  • New: packages/ai-proxy/test/schemas.test.ts - 12 unit tests
  • Modified: packages/ai-proxy/src/router.ts - Integrate validation
  • Modified: packages/ai-proxy/package.json - Add zod dependency

Test plan

  • [x] All unit tests pass (yarn workspace @forestadmin/ai-proxy test)
  • [x] Lint passes (yarn workspace @forestadmin/ai-proxy lint)
  • [x] Build passes (yarn workspace @forestadmin/ai-proxy build)

🤖 Generated with Claude Code

Scra3 avatar Jan 16 '26 21:01 Scra3