Unable to assign JSON Schema to toolDefinition #178
TanStack AI version#
0.2.0
Framework/Library version#
TypeScript, Node
Describe the bug and the steps to reproduce it#
Hi,
I have come across a small type related issue when assigning JSON Schema to tool definitions via factory function. The issue appears to be caused by the JSONSchema type used to constrain toolDefinition signature. Reproduction code below.
import { toolDefinition } from '@tanstack/ai'
// ---------------------------------------------------------
// Case A: Error
// ---------------------------------------------------------
export interface XString {
type: 'string'
}
function string(): XString {
return { type: 'string' }
}
const A = toolDefinition({ // 'XString' is not assignable to type 'SchemaInput | undefined'.
inputSchema: string(),
name: 'A string',
description: 'A string',
})
// ---------------------------------------------------------
// Case B: Ok
// ---------------------------------------------------------
const B = toolDefinition({
inputSchema: { type: 'string' },
name: 'A string',
description: 'A string',
})
// ---------------------------------------------------------
// Case C: Ok
// ---------------------------------------------------------
import * as z from 'zod'
const C = toolDefinition({
inputSchema: z.string(),
name: 'A string',
description: 'A string',
})
The issue appears to be caused by the indexer property on the JSONSchema (used for property extension)
https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L63
{
[key: string]: unknown // Allow additional properties for extensibility
}
... where unknown can be substituted for any to resolve the issue.
{
[key: string]: any // Allow additional properties for extensibility
}
Your Minimal, Reproducible Example - (Sandbox Highly Recommended)#
Screenshots or Videos (Optional)#
No response
Do you intend to try to help solve this bug with your own PR?#
Maybe, I'll investigate and start debugging
Terms & Code of Conduct#
- I agree to follow this project's Code of Conduct
- I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
AlemTuzlak closed this
Sign in to join this conversation.
📝 CodeRabbit Plan Mode#
Generate an implementation plan and prompts that you can use with your favorite coding agent.
Examples
🔗 Related PRs
TanStack/ai#165 - feat: standard (json) schema compliance [merged]
👤 Suggested Assignees
🧪 Issue enrichment is currently in open beta.
You can configure auto-planning by selecting labels in the issue_enrichment configuration.
To disable automatic issue enrichment, add the following to your
.coderabbit.yaml:💬 Have feedback or questions? Drop into our discord or schedule a call!