diff --git a/libs/copilot/index.tsx b/libs/copilot/index.tsx index 9dc840612e..d5c4d99bc4 100644 --- a/libs/copilot/index.tsx +++ b/libs/copilot/index.tsx @@ -30,6 +30,8 @@ declare global { mountChainlitWidget: (config: IWidgetConfig) => void; unmountChainlitWidget: () => void; toggleChainlitCopilot: () => void; + openChainlitCopilot: () => void; + closeChainlitCopilot: () => void; sendChainlitMessage: (message: IStep) => void; getChainlitCopilotThreadId: () => string | null; clearChainlitCopilotThreadId: (newThreadId?: string) => void; diff --git a/libs/copilot/src/app.tsx b/libs/copilot/src/app.tsx index 256ecabd1e..d499149438 100644 --- a/libs/copilot/src/app.tsx +++ b/libs/copilot/src/app.tsx @@ -22,6 +22,8 @@ declare global { interface Window { cl_shadowRootElement: HTMLDivElement; toggleChainlitCopilot: () => void; + openChainlitCopilot: () => void; + closeChainlitCopilot: () => void; theme?: { light: Record; dark: Record; diff --git a/libs/copilot/src/widget.tsx b/libs/copilot/src/widget.tsx index f41e72de3b..0eb28a0b82 100644 --- a/libs/copilot/src/widget.tsx +++ b/libs/copilot/src/widget.tsx @@ -32,11 +32,15 @@ const Widget = ({ config, error }: Props) => { useEffect(() => { window.toggleChainlitCopilot = () => setIsOpen((prev) => !prev); + window.openChainlitCopilot = () => setIsOpen(true); + window.closeChainlitCopilot = () => setIsOpen(false); window.getChainlitCopilotThreadId = getChainlitCopilotThreadId; window.clearChainlitCopilotThreadId = clearChainlitCopilotThreadId; return () => { window.toggleChainlitCopilot = () => console.error('Widget not mounted.'); + window.openChainlitCopilot = () => console.error('Widget not mounted.'); + window.closeChainlitCopilot = () => console.error('Widget not mounted.'); window.getChainlitCopilotThreadId = () => null; window.clearChainlitCopilotThreadId = () =>