-
Notifications
You must be signed in to change notification settings - Fork 3
refactor(types): replace json-schema library with custom JSONSchema type #220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Define comprehensive JSONSchema interface in types.ts covering all JSON Schema draft-07 properties - Add toJsonSchema() method to BaseTool and Tools classes for framework-agnostic schema export - Refactor toOpenAI(), toAnthropic(), and toOpenAIResponses() to use toJsonSchema() internally, reducing code duplication - Use type-fest OverrideProperties for ObjectJSONSchema type to ensure type: 'object' is always set - Remove json-schema and @types/json-schema dependencies This reduces external dependencies while providing a more flexible JSONSchema type that works seamlessly with OpenAI, Anthropic, and other LLM providers.
commit: |
Consolidate schema generation by reusing toJsonSchema() instead of manually constructing the schema object. This reduces duplication and ensures consistency across all conversion methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR removes external JSON Schema dependencies (json-schema and @types/json-schema) in favor of a custom JSONSchema interface, reducing external dependencies while maintaining full compatibility with OpenAI, Anthropic, and other LLM providers.
Key Changes:
- Introduced a comprehensive custom
JSONSchemainterface covering all JSON Schema draft-07 properties - Added
toJsonSchema()methods toBaseToolandToolsclasses for framework-agnostic schema export - Refactored existing methods (
toOpenAI(),toAnthropic(),toOpenAIResponses()) to use the newtoJsonSchema()internally
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/types.ts | Defines custom JSONSchema interface with all draft-07 properties and updates type references |
| src/tool.ts | Adds ObjectJSONSchema type and toJsonSchema() methods; refactors conversion methods to use it |
| src/tool.test.ts | Updates type imports and test assertions from JSONSchema7 to custom JSONSchema |
| pnpm-workspace.yaml | Removes json-schema and @types/json-schema from catalog dependencies |
| pnpm-lock.yaml | Removes dependency resolution entries for json-schema and @types/json-schema |
| package.json | Removes json-schema and @types/json-schema from dependencies and devDependencies |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No issues found across 6 files
- Import JSONSchema7 type from @ai-sdk/provider as AISDKJSONSchema - Use satisfies AISDKJSONSchema to validate schema at compile time - Move jsonSchema type import to top-level for cleaner code - Add @ai-sdk/provider as dev dependency for type checking
- Create tryImport() helper function for dynamic imports with friendly error messages when optional dependencies are not installed - Refactor toAISDK() to use tryImport() for cleaner code - Remove unused jsonSchema type import from top-level
- Test successful import of existing modules - Test StackOneError is thrown for non-existent modules - Verify error message includes module name and install hint
- Remove deprecated v4 parameters property - Use satisfies for type-safe tool definition - Remove outdated TODO comment about ts-ignore - Simplify tool definition by constructing all properties upfront
This reverts commit 91d6c79.
468aea6 to
fafd7ff
Compare
glebedel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Summary
JSONSchemainterface intypes.tscovering all JSON Schema draft-07 propertiestoJsonSchema()method toBaseToolandToolsclasses for framework-agnostic schema exporttoOpenAI(),toAnthropic(), andtoOpenAIResponses()to usetoJsonSchema()internallyjson-schemaand@types/json-schemadependenciesWhy
This reduces external dependencies while providing a more flexible JSONSchema type that works seamlessly with OpenAI, Anthropic, and other LLM providers. The custom type also uses
type-fest'sOverridePropertiesfor cleaner type narrowing (ObjectJSONSchema).The
toJsonSchema()method enables integration with any framework that accepts standard JSON Schema for tool definitions, such as:Test plan