feat(helpers): add zod realtime function helper#1996
Conversation
OkTest Summary❌ Failed for Node SDK PR #1996. SDK merge ( |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 15c277ef73
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| parameters: | ||
| isZodV4(zodSchema) ? | ||
| zodV4ToJsonSchema(zodSchema) | ||
| : zodV3ToJsonSchema(zodSchema, { name: options.name }), |
There was a problem hiding this comment.
Honor optional fields in Realtime schemas
When a Realtime tool has a normal optional parameter such as z.object({ limit: z.number().optional() }), this new helper still routes through the strict structured-output converters. Those converters reject .optional() without .nullable() and force nullable/defaulted fields into required, even though Realtime function tools only expose normal JSON Schema parameters and this helper intentionally omits the unsupported strict flag. As a result, valid non-strict Realtime function definitions cannot be produced, or are over-constrained, by the new helper.
Useful? React with 👍 / 👎.
Summary
zodRealtimeFunction()toopenai/helpers/zodstrict, which is not part of the RealtimeRealtimeFunctionToolshapeMotivation
Fixes #1809.
zodResponsesFunction()is close to what Realtime callers need, but it always emitsstrict: true. Realtime function tools use the flat{ type, name, description?, parameters }shape and do not support that field, so raw Realtime users currently have to convert Zod schemas by hand.Behavior
The new helper returns a regular Realtime function tool definition with
type,name, optionaldescription, and JSON Schemaparameters. It reuses the existing Zod conversion path so behavior stays consistent across the helper family, including current Zod v3, v4, and v4 mini support.The helper is intentionally definition-only. It does not attach callback or parser metadata because the raw Realtime client does not have a
runTools()-style consumer; callers still parse function-call arguments with their original Zod schema.Validation
pnpm exec jest tests/helpers/zod.test.ts --runInBandpnpm exec prettier --check src/helpers/zod.ts tests/helpers/zod.test.tsgit diff --checkpnpm run lint