Skip to content
Source
Sign inSign up
TanStack/ai

Unable to assign JSON Schema to toolDefinition #178

Closedsinclairzx81(GitHub profile, opens in a new tab) opened this issue 1 comment

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.

Reproduction | Example

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
}

https://tsplay.dev/wXM3QN

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.
  1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

    📝 CodeRabbit Plan Mode

    Generate an implementation plan and prompts that you can use with your favorite coding agent.

    • Create Plan
    Examples

    🔗 Related PRs

    TanStack/ai#165 - feat: standard (json) schema compliance [merged]

    👤 Suggested Assignees


  2. 🧪 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:

    issue_enrichment:
      auto_enrich:
        enabled: false

    💬 Have feedback or questions? Drop into our discord or schedule a call!

  • AlemTuzlak closed this

  • Sign in to join this conversation.