Skip to content
Source
Sign inSign up
TanStack/ai

tool definition does not infer types in .server and .client #235

Send to my agent
Closedsatvikreddy(GitHub profile, opens in a new tab) opened this issue 11 comments

TanStack AI version

v0.2.2

Framework/Library version

v19.2.3

Describe the bug and the steps to reproduce it

Tanstack ai docs mention that tool definition is fully typesafe.

But the client function shows input as unknown.

Image

Minimal repro:

import { toolDefinition } from '@tanstack/ai'
import z from 'zod'

export const saveToLocalStorageDef = toolDefinition({
  name: 'save_to_local_storage',
  description: 'Save data to browser local storage',
  inputSchema: z.object({
    key: z.string().describe('Storage key'),
    value: z.string().describe('Value to store'),
  }),
  outputSchema: z.object({
    saved: z.boolean(),
  }),
})

const saveToLocalStorage = saveToLocalStorageDef.client((input) => {
  localStorage.setItem(input.key, input.value)
  return { saved: true }
})

None

Screenshots or Videos (Optional)

No response

Do you intend to try to help solve this bug with your own PR?

None

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. What framework are you using? I can infer the type in TanStack Start, though.

    Image
  2. I am using tanstack start.

    You can check out this codesandbox as well. Same issue in this.

  3. I was having the same problem, installing @standard-schema/spec fixed it

  4. installing @standard-schema/spec also fixed it I did not even have tools passed, but without installing standard schema the return type of chat was any

  5. Version 0.10.1 and this is not fixed yet (discovered in 0.2.2). Any progress here? Also, installing @standard-schema/spec does not solve the problem.

    "@tanstack/ai": "^0.10.1",
    "@tanstack/ai-openrouter": "^0.7.2",
    "@tanstack/ai-react": "^0.7.9",
  6. @ctrhub mind trying using pkg.pr.new versions of the package, you have the related open pr with the fix above in this issue? If you could confirm if it solves/doesnt solve the problem

  7. @AlemTuzlak I've tried. But for some reason, i was not able to install any pr from page 5, including yours (basically any pr that is 3 days old +). Downloading always stacks at @tanstack/ai-event-client package. But i was able to install any prs from page 1-4. Weird. However, i created a patch (with bun patch) and it din't work.

    diff --git a/package.json b/package.json
    index 3d69c84bd12ec4ac71ea0797d791c3e6f8ec434e..6ead3c8a1070f2ecb68069a8cf7533055a7cd805 100644
    --- a/package.json
    +++ b/package.json
    @@ -46,10 +46,10 @@
       ],
       "dependencies": {
         "partial-json": "^0.1.7",
    +    "@standard-schema/spec": "^1.1.0",
         "@tanstack/ai-event-client": "0.2.1"
       },
       "devDependencies": {
    -    "@standard-schema/spec": "^1.1.0",
         "@vitest/coverage-v8": "4.0.14",
         "zod": "^4.2.0"
       },
    
    Image
  8. Okay, I will look into what exactly is going on here! Thank you!

  9. @AlemTuzlak Found it. The problem was in the zod version. I was using "zod": "^3.24.2". Upgrading it to version "zod": "^4.3.6" fixed the problem.

    Image
  10. Yeah it requires zod version 4.2 i think because older ones dont have the spec implemented 😅

  11. AlemTuzlak closed this

Sign in to join this conversation.