refactor(ai-lite): remove unsafe onToolCall any cast#6963
Open
refactor(ai-lite): remove unsafe onToolCall any cast#6963
Conversation
Type tool chunks by UI message tool definitions and propagate typed chunks through transport/parser. Replace the onToolCall any cast with InferUIMessageToolCall and keep dynamic tool calls explicitly flagged.
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
| Duplication | 0 |
TIP This summary will be updated as you push new changes. Give us feedback
More templates
algoliasearch-helper
instantsearch-ui-components
instantsearch.css
instantsearch.js
react-instantsearch
react-instantsearch-core
react-instantsearch-nextjs
react-instantsearch-router-nextjs
vue-instantsearch
commit: |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors ai-lite streaming types to remove an unsafe any cast in onToolCall by typing tool-related chunks based on the UIMessage tool definitions, and propagating those typed chunks through the transport and stream parser layers.
Changes:
- Introduces tool-aware chunk typing (
ToolUIMessageChunk) and extendsUIMessageChunk/InferUIMessageChunkto carry tool type information. - Updates HTTP transport and NDJSON/SSE parsing to return
InferUIMessageChunk<TUIMessage>streams instead of untypedUIMessageChunk. - Replaces the
onToolCallas anycast withInferUIMessageToolCall<TUIMessage>and adds explicit “dynamic tool” signaling on tool chunks.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/instantsearch.js/src/lib/ai-lite/types.ts | Adds tool-typed chunk unions, extends UIMessageChunk generics, and updates inferred chunk typing. |
| packages/instantsearch.js/src/lib/ai-lite/transport.ts | Propagates inferred chunk types through ChatTransport and HttpChatTransport stream return types. |
| packages/instantsearch.js/src/lib/ai-lite/stream-parser.ts | Makes the JSON event stream parser generic so callers can preserve the chunk type. |
| packages/instantsearch.js/src/lib/ai-lite/abstract-chat.ts | Replaces unsafe any cast for onToolCall with an inferred tool-call type. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
Type tool chunks by UI message tool definitions and propagate typed chunks through transport/parser.
Replace the onToolCall any cast with InferUIMessageToolCall and keep dynamic tool calls explicitly flagged.
Result
internal type doesn't cast as any