Skip to content

refactor(ai-lite): remove unsafe onToolCall any cast#6963

Open
Haroenv wants to merge 2 commits intomasterfrom
refactor/internal-type-cleanup
Open

refactor(ai-lite): remove unsafe onToolCall any cast#6963
Haroenv wants to merge 2 commits intomasterfrom
refactor/internal-type-cleanup

Conversation

@Haroenv
Copy link
Copy Markdown
Contributor

@Haroenv Haroenv commented Apr 10, 2026

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

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.
@Haroenv Haroenv requested review from a team, FabienMotte, Copilot and shaejaz and removed request for a team April 10, 2026 08:29
@codacy-production
Copy link
Copy Markdown

codacy-production bot commented Apr 10, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 10, 2026

More templates

algoliasearch-helper

npm i https://pkg.pr.new/algolia/instantsearch/algoliasearch-helper@6963

instantsearch-ui-components

npm i https://pkg.pr.new/algolia/instantsearch/instantsearch-ui-components@6963

instantsearch.css

npm i https://pkg.pr.new/algolia/instantsearch/instantsearch.css@6963

instantsearch.js

npm i https://pkg.pr.new/algolia/instantsearch/instantsearch.js@6963

react-instantsearch

npm i https://pkg.pr.new/algolia/instantsearch/react-instantsearch@6963

react-instantsearch-core

npm i https://pkg.pr.new/algolia/instantsearch/react-instantsearch-core@6963

react-instantsearch-nextjs

npm i https://pkg.pr.new/algolia/instantsearch/react-instantsearch-nextjs@6963

react-instantsearch-router-nextjs

npm i https://pkg.pr.new/algolia/instantsearch/react-instantsearch-router-nextjs@6963

vue-instantsearch

npm i https://pkg.pr.new/algolia/instantsearch/vue-instantsearch@6963

commit: e94ab28

Copy link
Copy Markdown
Contributor

Copilot AI left a 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 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 extends UIMessageChunk / InferUIMessageChunk to carry tool type information.
  • Updates HTTP transport and NDJSON/SSE parsing to return InferUIMessageChunk<TUIMessage> streams instead of untyped UIMessageChunk.
  • Replaces the onToolCall as any cast with InferUIMessageToolCall<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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants