Commit 134b0c2
authored
refactor(types): replace json-schema library with custom JSONSchema type (#220)
* refactor(types): replace json-schema library with custom JSONSchema type
- 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.
* refactor(tool): use toJsonSchema() in toAISDK method
Consolidate schema generation by reusing toJsonSchema() instead of
manually constructing the schema object. This reduces duplication
and ensures consistency across all conversion methods.
* refactor(tool): add type-safe schema validation for AI SDK
- 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
* refactor(utils): add tryImport utility for optional dependencies
- 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(utils): add tests for tryImport utility
- Test successful import of existing modules
- Test StackOneError is thrown for non-existent modules
- Verify error message includes module name and install hint
* refactor(tool): clean up toAISDK method
- 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
* chore(oxfmt): ignore .claude/settings.local.json
* chore(deps): move @ai-sdk/provider to catalog:dev
* docs: tanstack ai jsonschema
* Revert "chore(oxfmt): ignore .claude/settings.local.json"
This reverts commit 91d6c79.1 parent e131433 commit 134b0c2
8 files changed
Lines changed: 204 additions & 112 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
42 | 41 | | |
43 | 42 | | |
44 | 43 | | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
48 | 47 | | |
49 | 48 | | |
50 | 49 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | | - | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
39 | 38 | | |
40 | 39 | | |
41 | 40 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | 2 | | |
4 | | - | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
5 | 9 | | |
6 | 10 | | |
7 | 11 | | |
| |||
1107 | 1111 | | |
1108 | 1112 | | |
1109 | 1113 | | |
1110 | | - | |
1111 | | - | |
| 1114 | + | |
1112 | 1115 | | |
1113 | 1116 | | |
1114 | | - | |
| 1117 | + | |
1115 | 1118 | | |
1116 | 1119 | | |
1117 | 1120 | | |
| |||
1144 | 1147 | | |
1145 | 1148 | | |
1146 | 1149 | | |
1147 | | - | |
| 1150 | + | |
1148 | 1151 | | |
1149 | 1152 | | |
1150 | 1153 | | |
| |||
1185 | 1188 | | |
1186 | 1189 | | |
1187 | 1190 | | |
1188 | | - | |
| 1191 | + | |
1189 | 1192 | | |
1190 | 1193 | | |
1191 | 1194 | | |
| |||
1220 | 1223 | | |
1221 | 1224 | | |
1222 | 1225 | | |
1223 | | - | |
| 1226 | + | |
1224 | 1227 | | |
1225 | 1228 | | |
1226 | 1229 | | |
1227 | 1230 | | |
1228 | 1231 | | |
1229 | 1232 | | |
1230 | | - | |
| 1233 | + | |
1231 | 1234 | | |
1232 | 1235 | | |
1233 | 1236 | | |
| |||
0 commit comments