feat(chat): add initialMessages option#6978
Open
aymeric-giraudet wants to merge 3 commits intomasterfrom
Open
Conversation
Allows pre-populating the chat with messages on initialization without triggering an AI response. Unlike `initialUserMessage` which sends a message and triggers a response, `initialMessages` simply sets the messages in the UI. Both options can be used together.
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 12 |
| Duplication | 16 |
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
Adds a new initialMessages option to the Chat connector to pre-seed chat history on initialization (without triggering an AI response), while preserving existing/restored messages and respecting resume.
Changes:
- Add
initialMessages?: TUiMessage[]toconnectChatparams and apply it duringinitwhen there are no pre-existing messages andresumeis disabled. - Update connector tests to cover
initialMessagesand the interaction withinitialUserMessage. - Update widget-level options tests to validate
initialMessagesbehavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/common/widgets/chat/options.tsx | Adds widget tests asserting initial messages are displayed on init and not applied when messages already exist. |
| tests/common/connectors/chat/options.ts | Adds connector tests for initialMessages and its interaction with initialUserMessage. |
| packages/instantsearch.js/src/connectors/chat/connectChat.ts | Introduces the initialMessages option and applies it during initialization before callback registration. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Clear sessionStorage in `sets initialMessages on init` test to avoid order-dependent flakiness - Add test for `initialMessages` being skipped when `resume` is enabled
The new `initialMessages` option adds JSDoc and logic to the development bundle.
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
Adds an
initialMessagesoption to the Chat connector, as discussed in #6956.initialMessagespre-populates the chat with messages on initialization without triggering an AI responseresumeis enabledinitialUserMessage—initialMessagessets the displayed messages, theninitialUserMessagesends a message that triggers AIThis serves a different purpose from
initialUserMessage: useinitialMessagesfor welcome messages or pre-seeded conversation history, andinitialUserMessageto automatically trigger an AI response on init.Test plan
initialMessageson initinitialMessageswhen messages already existinitialMessagesand sendsinitialUserMessagetogetherinitialMessageson initinitialMessageswhen messages already exist