Skip to content

feat(chat): add initialMessages option#6978

Open
aymeric-giraudet wants to merge 3 commits intomasterfrom
feat/chat-initial-messages
Open

feat(chat): add initialMessages option#6978
aymeric-giraudet wants to merge 3 commits intomasterfrom
feat/chat-initial-messages

Conversation

@aymeric-giraudet
Copy link
Copy Markdown
Member

Summary

Adds an initialMessages option to the Chat connector, as discussed in #6956.

  • initialMessages pre-populates the chat with messages on initialization without triggering an AI response
  • Only applied when the chat has no existing messages (e.g., not restored from storage)
  • Not applied when resume is enabled
  • Can be used alongside initialUserMessageinitialMessages sets the displayed messages, then initialUserMessage sends a message that triggers AI

This serves a different purpose from initialUserMessage: use initialMessages for welcome messages or pre-seeded conversation history, and initialUserMessage to automatically trigger an AI response on init.

Test plan

  • Connector test: sets initialMessages on init
  • Connector test: does not set initialMessages when messages already exist
  • Connector test: applies initialMessages and sends initialUserMessage together
  • Widget test (JS + React): sets initialMessages on init
  • Widget test (JS + React): does not set initialMessages when messages already exist
  • Lint passes with 0 errors
  • Type-check passes (no new errors)

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.
Copilot AI review requested due to automatic review settings April 15, 2026 13:28
@codacy-production
Copy link
Copy Markdown

codacy-production bot commented Apr 15, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 12 complexity · 16 duplication

Metric Results
Complexity 12
Duplication 16

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 15, 2026

More templates

algoliasearch-helper

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

instantsearch-ui-components

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

instantsearch.css

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

instantsearch.js

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

react-instantsearch

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

react-instantsearch-core

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

react-instantsearch-nextjs

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

react-instantsearch-router-nextjs

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

vue-instantsearch

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

commit: dd4fb8c

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

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[] to connectChat params and apply it during init when there are no pre-existing messages and resume is disabled.
  • Update connector tests to cover initialMessages and the interaction with initialUserMessage.
  • Update widget-level options tests to validate initialMessages behavior.

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.

Comment thread tests/common/connectors/chat/options.ts
Comment thread packages/instantsearch.js/src/connectors/chat/connectChat.ts
- 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.
@aymeric-giraudet aymeric-giraudet requested review from a team, FabienMotte and afrencalg and removed request for a team April 15, 2026 16:32
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