feat(copilot): add openChainlitCopilot and closeChainlitCopilot functions#2797
Open
hztBUAA wants to merge 1 commit intoChainlit:mainfrom
Open
feat(copilot): add openChainlitCopilot and closeChainlitCopilot functions#2797hztBUAA wants to merge 1 commit intoChainlit:mainfrom
hztBUAA wants to merge 1 commit intoChainlit:mainfrom
Conversation
…ions Add two new window functions for programmatic control of the copilot widget state, complementing the existing toggleChainlitCopilot. This allows host pages to explicitly open or close the copilot window without needing to track its current state, enabling use cases like auto-opening the chat after a delay without disturbing users who already opened it themselves. Closes Chainlit#2579
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 two new window functions for programmatic control of the copilot widget:
window.openChainlitCopilot()- explicitly opens the copilot chat windowwindow.closeChainlitCopilot()- explicitly closes the copilot chat windowThese complement the existing
window.toggleChainlitCopilot()function by allowing host pages to set a specific open/close state without needing to track the current state of the widget.Motivation
As described in #2579, the toggle-only API is insufficient for common use cases like:
setTimeout(() => window.openChainlitCopilot(), 5000)) without disturbing users who already opened itChanges
libs/copilot/index.tsx: AddedopenChainlitCopilotandcloseChainlitCopilotto the globalWindowinterface type declarationslibs/copilot/src/app.tsx: Added the same type declarations to the duplicateWindowinterfacelibs/copilot/src/widget.tsx: Implemented the two functions usingsetIsOpen(true)andsetIsOpen(false), with proper cleanup on unmount (matching the existing pattern fortoggleChainlitCopilot)Test plan
window.openChainlitCopilot()from the browser console - copilot should openwindow.openChainlitCopilot()when already open - should remain open (no-op)window.closeChainlitCopilot()- copilot should closewindow.closeChainlitCopilot()when already closed - should remain closed (no-op)window.toggleChainlitCopilot()- should still work as beforewindow.openChainlitCopilot()- should log error to consoleCloses #2579
Summary by cubic
Add window.openChainlitCopilot() and window.closeChainlitCopilot() to let host pages explicitly open or close the Copilot chat. This complements the existing toggle and enables safe auto-open/close flows without tracking state.
Written for commit 94a03a1. Summary will update on new commits.