Open History to see the last commit
1import { describe, expect, it } from 'vitest'
2import { createToolInputNormalizer } from './tool-input-normalizer'
3import type { Tool } from '@tanstack/ai'
4
5describe('createToolInputNormalizer', () => {
6 it('removes only nulls synthesized for optional fields', () => {
7 const tool: Tool = {
8 name: 'optional_enum',
9 description: 'Uses optional and genuinely nullable values',
10 inputSchema: {
11 type: 'object',
12 properties: {
13 mode: { type: 'string', enum: ['canary'] },
14 note: { type: ['string', 'null'] },
15 },
16 required: [],
17 },
18 }
19 const normalize = createToolInputNormalizer([tool])
20
21 expect(normalize(tool.name, { mode: null, note: null })).toEqual({
22 note: null,
23 })
24 })
25
26 it('does not guess when public tool names are ambiguous', () => {
27 const tools: Array<Tool> = [
28 {
29 name: 'duplicate',
30 description: 'First tool',
31 inputSchema: {
32 type: 'object',
33 properties: { firstOptional: { type: 'string' } },
34 },
35 },
36 {
37 name: 'duplicate',
38 description: 'Second tool',
39 inputSchema: {
40 type: 'object',
41 properties: { secondOptional: { type: 'string' } },
42 },
43 },
44 ]
45 const normalize = createToolInputNormalizer(tools)
46 const input = { firstOptional: null, secondOptional: null }
47
48 expect(normalize('duplicate', input)).toBe(input)
49 })
50})