You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor(types): replace JsonDict with type-fest JsonObject and JsonValue (#228)
* refactor(types): replace JsonDict with type-fest JsonObject and JsonValue
Remove the custom `JsonDict = Record<string, unknown>` type alias in
favour of type-fest's stricter `JsonObject` and `JsonValue` types.
Key changes to src/types.ts:
- Import and re-export `JsonObject` and `JsonValue` from type-fest
- Update `JSONSchema` interface to use `JsonValue` instead of `unknown`
for properties like `enum`, `const`, `default`, and `examples`
- Add explicit index signature union type for JSONSchema extensibility
This provides stronger type safety by ensuring values are actually
JSON-serialisable rather than accepting arbitrary `unknown` values.
* refactor(core): update source files to use JsonObject type
Migrate all source files from the removed `JsonDict` type to the
type-fest `JsonObject` type. This commit updates method signatures
and internal type annotations across the codebase.
Files updated:
- src/tool.ts: Update execute method signatures and meta tool returns
- src/toolsets.ts: Update parameter and return types
- src/feedback.ts: Add explicit array types for results/errors,
use JsonValue for parsed responses
- src/headers.ts: Update normaliseHeaders parameter type
Notable implementation changes:
- meta_search_tools now uses JSON.parse(JSON.stringify(...)) to ensure
the return value is JSON-serialisable (removes undefined values from
JSONSchema objects)
- Feedback tool now explicitly types its internal arrays to ensure
type safety with the stricter JsonObject constraint
* refactor(requestBuilder): add stringifyValue helper for type-safe serialisation
Add a dedicated `stringifyValue()` function to safely convert JsonValue
types to strings for use in URLs, headers, and form data. This replaces
direct `String()` calls which could produce `[object Object]` for
complex values.
The helper function:
- Returns strings as-is
- Converts numbers and booleans via String()
- Returns empty string for null values
- JSON-stringifies arrays and objects
Also updates the dry run response to properly serialise headers and body
to JSON-compatible values using `satisfies JsonObject` for type checking.
* test: update tests for JsonObject type changes
Update test files to work with the stricter JsonObject type:
src/tool.test.ts:
- Add isMetaToolSearchResults type guard function
- Add getSearchResults helper to safely extract search results
- Replace direct type assertions with type-safe helper calls
src/requestBuilder.test.ts:
- Update dry run test expectation: body is now `null` instead of
`undefined` when no body params exist (null is JSON-serialisable)
- Add explicit type casts for runtime edge case tests that
intentionally pass invalid types (Date, RegExp, circular refs)
src/headers.test.ts:
- Remove test for undefined values (not valid in JsonObject)
- Keep null value test (null is a valid JSON value)
* docs(examples): update examples to use JsonObject type
Update example files to work with the new JsonObject type:
examples/meta-tools.ts:
- Import JsonObject from @stackone/ai
- Add explicit type annotation for intents array using
`as const satisfies Array<{ intent: string; params: JsonObject }>`
examples/tanstack-ai-integration.test.ts:
- Simplify test structure and remove redundant assertions
0 commit comments