feat(sdk-ts): accept Standard Schema validators for tool input/output schema - #133
Open
vishnu-77 wants to merge 1 commit into
Open
feat(sdk-ts): accept Standard Schema validators for tool input/output schema#133vishnu-77 wants to merge 1 commit into
vishnu-77 wants to merge 1 commit into
Conversation
… schema ToolCatalog.register() now accepts a Zod/Effect Schema (or any Standard Schema-compliant validator) as inputSchema/outputSchema, not just a bare JSON Schema object. Generalizes the ~standard.jsonSchema conversion the mastra and vercel-ai-sdk adapters already did internally into the shared catalog layer. Closes ratel-ai#53
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #53.
ToolCatalog.register()(and theExecutableTooltype) only accepted a bare JSON Schema object forinputSchema/outputSchema. A caller using Zod, Effect Schema, or any Standard Schema-compliant validator had no conversion path when usingToolCatalogdirectly.Both framework adapters (
@ratel-ai/mastra,@ratel-ai/vercel-ai-sdk) already solved this internally (toJsonSchema()readingschema["~standard"].jsonSchema.input(...)), but the fix never made it into the shared catalog layer. This generalizes that same pattern intoToolCatalog.Changes
ExecutableTool.inputSchema/outputSchemawidened fromJSONSchema7to a newToolSchema = JSONSchema7 | StandardJsonSchemaunion.toJsonSchema()helper incatalog.ts, called once inregister()and reused for both the native registry and the catalog's internal metadata cache — socatalog.get(id)never leaks a raw Zod/validator object back to a caller.~standardkey, so it passes through the helper unchanged. Existing bare-JSON-Schema callers are unaffected.ToolSchema/StandardJsonSchemaexported from the package's public entrypoint.catalog.test.tsregistering a tool with a realzodschema, asserting it's searchable and that the stored/indexed metadata is plain JSON Schema.Test plan
pnpm typecheck && pnpm lint && pnpm testscoped tosrc/sdk/tspnpm -r typecheck && pnpm -r lint && pnpm -r testfrom repo root (no regressions elsewhere)cargo build/clippy/fmt/test --workspace(no Rust files touched; confirms no regression)