|
4 | 4 |
|
5 | 5 | **Tech Stack**: TypeScript • Bun • Vercel AI SDK • Zod |
6 | 6 | **Inspired by**: Claude Code tools |
7 | | -**Version**: 0.3.0 |
| 7 | +**Version**: 0.4.0 |
8 | 8 |
|
9 | 9 | --- |
10 | 10 |
|
@@ -148,12 +148,42 @@ Zod schemas define and validate all tool inputs: |
148 | 148 | ```typescript |
149 | 149 | const bashInputSchema = z.object({ |
150 | 150 | command: z.string(), |
151 | | - description: z.string(), |
152 | | - restart: z.boolean().optional() |
| 151 | + description: z.string().nullable(), |
| 152 | + timeout: z.number().nullable() |
153 | 153 | }); |
154 | 154 | ``` |
155 | 155 |
|
156 | | -#### 6. Tool Result Caching |
| 156 | +#### 6. Nullable Types for AI Provider Compatibility |
| 157 | + |
| 158 | +All optional tool parameters use `.nullable()` instead of `.optional()` for OpenAI structured outputs compatibility. |
| 159 | + |
| 160 | +**Why `.nullable()` instead of `.optional()`:** |
| 161 | +- OpenAI structured outputs require all properties in the `required` array |
| 162 | +- `.optional()` removes properties from `required` (breaks OpenAI) |
| 163 | +- `.nullable()` keeps properties in `required` but allows `null` values |
| 164 | +- Works with both OpenAI and Anthropic models |
| 165 | + |
| 166 | +**Pattern for handling nullable values:** |
| 167 | +```typescript |
| 168 | +// Zod schema uses .nullable() |
| 169 | +const schema = z.object({ |
| 170 | + timeout: z.number().nullable(), |
| 171 | + replace_all: z.boolean().nullable(), |
| 172 | +}); |
| 173 | + |
| 174 | +// In execute function, use ?? for defaults |
| 175 | +// NOTE: Destructuring defaults (= value) only work with undefined, NOT null |
| 176 | +const { timeout, replace_all: rawReplaceAll } = input; |
| 177 | +const effectiveTimeout = timeout ?? 120000; |
| 178 | +const replaceAll = rawReplaceAll ?? false; |
| 179 | +``` |
| 180 | + |
| 181 | +**Type conventions:** |
| 182 | +- Zod schemas: `.nullable()` → produces `T | null` |
| 183 | +- Exported interfaces: `T | null` (e.g., `description: string | null`) |
| 184 | +- Internal functions: `T | null` for parameters that accept nullable values |
| 185 | + |
| 186 | +#### 7. Tool Result Caching |
157 | 187 | Optional caching for tool execution results: |
158 | 188 | ```typescript |
159 | 189 | // Enable with defaults (LRU, 5min TTL) |
@@ -841,5 +871,5 @@ const { tools } = createAgentTools(sandbox, { |
841 | 871 |
|
842 | 872 | --- |
843 | 873 |
|
844 | | -*Last Updated*: 2026-01-02 |
| 874 | +*Last Updated*: 2026-01-22 |
845 | 875 | *For*: Claude Code and AI coding assistants |
0 commit comments