Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

function-tool.test.ts

62 lines1.6 KB

1import { describe, expect, it } from 'vitest'
2import { convertFunctionToolToAdapterFormat } from './function-tool'
3import type { Tool } from '@tanstack/ai'
4​
5describe('function-tool adapter converter', () => {
6 it('falls back from strict mode when an anyOf variant needs null widening', () => {
7 const out = convertFunctionToolToAdapterFormat(anyOfOptionalVariantTool)
8​
9 expect(out.strict).toBe(false)
10 })
11​
12 it('falls back from strict mode for boolean schema nodes', () => {
13 const out = convertFunctionToolToAdapterFormat(booleanSchemaTool)
14​
15 expect(out.strict).toBe(false)
16 expect(out.parameters).toEqual(booleanSchemaTool.inputSchema)
17 })
18})
19​
20const booleanSchemaInput = {
21 type: 'object',
22 properties: {},
23 required: [],
25Reflect.set(booleanSchemaInput.properties, 'acceptAnything', true)
26​
27const booleanSchemaTool = {
28 name: 'accept_anything',
29 description: 'Accept any value',
30 inputSchema: booleanSchemaInput,
31} satisfies Tool
32​
33const anyOfOptionalVariantTool: Tool = {
34 name: 'store_variant',
35 description: 'Store a union variant',
36 inputSchema: {
37 type: 'object',
38 properties: {
39 value: {
40 anyOf: [
41 {
42 type: 'object',
43 properties: {
44 kind: { const: 'optional' },
45 note: { type: 'string' },
46 },
47 required: ['kind'],
48 },
49 {
50 type: 'object',
51 properties: {
52 kind: { const: 'nullable' },
53 note: { type: ['string', 'null'] },
54 },
55 required: ['kind', 'note'],
56 },
57 ],
58 },
59 },
60 required: ['value'],
61 },