-
Notifications
You must be signed in to change notification settings - Fork 17.7k
feat(extensions): add Chat contribution type (SIP-214) #41205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
michael-s-molina
wants to merge
18
commits into
apache:master
Choose a base branch
from
michael-s-molina:chat-contribution-type
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
380e700
feat(extensions): define the superset.chatbot contribution point (#40…
EnxDev 94e0071
Merge branch 'master' into enxdev/chat-prototype
EnxDev c65c952
refactor(extensions): remove install/lifecycle/dependency machinery …
EnxDev 09c09f3
refactor: rename chatbot registration location
EnxDev f170dc1
refactor(chatbot): drop extension settings layer; resolve last-loaded…
EnxDev 568337f
feat(extensions): add dedicated chat contribution type (#41000)
EnxDev a1eba0f
chore: Cleanup changes in chat feature branch (#41008)
michael-s-molina 715c07b
chore(extensions): remove out-of-scope scaffolding from chat SIP branch
EnxDev 5c1609e
chore(extensions): align naming conventions
EnxDev 395bbb9
chore: More cleanup of chat extension code (#41116)
michael-s-molina ec623f3
Merge branch 'master' into enxdev/chat-prototype
michael-s-molina d88a673
chore: Chat extension improvements (#41117)
michael-s-molina ce0fcf9
Merge branch 'master' into enxdev/chat-prototype
EnxDev bc3d0af
feat(extensions): add Chat contribution type (SIP-214)
michael-s-molina 43f623c
Merge branch 'master' into chat-contribution-type
michael-s-molina 1847608
Address CodeAnt comments
michael-s-molina bb9ee35
Fix CI errors
michael-s-molina 0ad3ef2
Remove promise error listener
michael-s-molina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
140 changes: 140 additions & 0 deletions
140
docs/developer_docs/extensions/extension-points/chat.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| --- | ||
| title: Chat | ||
| sidebar_position: 3 | ||
| --- | ||
|
|
||
| <!-- | ||
| Licensed to the Apache Software Foundation (ASF) under one | ||
| or more contributor license agreements. See the NOTICE file | ||
| distributed with this work for additional information | ||
| regarding copyright ownership. The ASF licenses this file | ||
| to you under the Apache License, Version 2.0 (the | ||
| "License"); you may not use this file except in compliance | ||
| with the License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, | ||
| software distributed under the License is distributed on an | ||
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| KIND, either express or implied. See the License for the | ||
| specific language governing permissions and limitations | ||
| under the License. | ||
| --> | ||
|
|
||
| # Chat Contributions | ||
|
|
||
| Extensions can add a chat interface to Superset by registering a trigger and a panel. The host owns the layout, open/close state, and display mode — the extension only needs to provide the UI components. | ||
|
|
||
| ## Overview | ||
|
|
||
| A chat registration consists of two React components: | ||
|
|
||
| | Component | Role | | ||
| |-----------|------| | ||
| | **Trigger** | Always-visible entry point (e.g., a floating button). Rendered in the bottom-right corner in floating mode, or as a fixed overlay in panel mode. | | ||
| | **Panel** | The chat UI itself (message list, input, etc.). Mounted by the host in the active display mode. | | ||
|
|
||
| ## Display Modes | ||
|
|
||
| The host supports two display modes, switchable by the user or the extension at runtime: | ||
|
|
||
| | Mode | Behavior | | ||
| |------|----------| | ||
| | `floating` | Panel floats above page content, anchored to the bottom-right corner. | | ||
| | `panel` | Panel is docked to the right side of the application as a resizable sidebar, sitting beside the page content. | | ||
|
|
||
| The user's last selected mode and open/closed state are persisted across page reloads. | ||
|
|
||
| ## Registering a Chat | ||
|
|
||
| Call `chat.registerChat` from your extension's entry point with a descriptor, a trigger factory, and a panel factory: | ||
|
|
||
| ```tsx | ||
| import { chat } from '@apache-superset/core'; | ||
| import ChatTrigger from './ChatTrigger'; | ||
| import ChatPanel from './ChatPanel'; | ||
|
|
||
| chat.registerChat( | ||
| { id: 'my-org.my-chat', name: 'My Chat' }, | ||
| ChatTrigger, | ||
| ChatPanel, | ||
| ); | ||
| ``` | ||
|
|
||
| Only one chat registration is active at a time. If a second extension calls `registerChat`, it replaces the first and a warning is logged. | ||
|
|
||
| ## Opening and Closing the Chat | ||
|
|
||
| The trigger component is responsible for toggling the panel. Use `chat.isOpen()`, `chat.open()`, and `chat.close()` to control visibility: | ||
|
|
||
| ```tsx | ||
| import { chat } from '@apache-superset/core'; | ||
|
|
||
| export default function ChatTrigger() { | ||
| return ( | ||
| <button onClick={() => (chat.isOpen() ? chat.close() : chat.open())}> | ||
| 💬 | ||
| </button> | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
| You can also subscribe to open/close events from any component: | ||
|
|
||
| ```tsx | ||
| useEffect(() => { | ||
| const { dispose } = chat.onDidOpen(() => console.log('chat opened')); | ||
| return dispose; | ||
| }, []); | ||
| ``` | ||
|
|
||
| ## Changing the Display Mode | ||
|
|
||
| Call `chat.setDisplayMode` to switch between `'floating'` and `'panel'` modes. In your panel component, subscribe to `onDidChangeDisplayMode` to react to changes (including those triggered by the user): | ||
|
|
||
| ```tsx | ||
| import { useState, useEffect } from 'react'; | ||
| import { chat } from '@apache-superset/core'; | ||
|
|
||
| export default function ChatPanel() { | ||
| const [mode, setMode] = useState(chat.getDisplayMode()); | ||
|
|
||
| useEffect(() => { | ||
| const { dispose } = chat.onDidChangeDisplayMode(m => setMode(m)); | ||
| return dispose; | ||
| }, []); | ||
|
|
||
| return ( | ||
| <div style={{ height: mode === 'panel' ? '100%' : '80vh' }}> | ||
| <button onClick={() => chat.setDisplayMode(mode === 'panel' ? 'floating' : 'panel')}> | ||
| {mode === 'panel' ? 'Float' : 'Dock'} | ||
| </button> | ||
| {/* message list and input */} | ||
| </div> | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
| ## Chat API Reference | ||
|
|
||
| All methods are available on the `chat` namespace from `@apache-superset/core`: | ||
|
|
||
| | Method / Event | Description | | ||
| |----------------|-------------| | ||
| | `registerChat(descriptor, trigger, panel)` | Register a chat extension. Returns a `Disposable` to unregister. | | ||
| | `open()` | Open the chat panel. No-op if already open or no registration. | | ||
| | `close()` | Close the chat panel. | | ||
| | `isOpen()` | Returns `true` if the panel is currently open. | | ||
| | `getDisplayMode()` | Returns the current display mode (`'floating'` or `'panel'`). | | ||
| | `setDisplayMode(mode)` | Switch between `'floating'` and `'panel'` mode. | | ||
| | `onDidOpen(listener)` | Subscribe to panel open events. Returns a `Disposable`. | | ||
| | `onDidClose(listener)` | Subscribe to panel close events. Returns a `Disposable`. | | ||
| | `onDidChangeDisplayMode(listener)` | Subscribe to display mode changes. Returns a `Disposable`. | | ||
| | `onDidRegisterChat(listener)` | Subscribe to registration events. | | ||
| | `onDidUnregisterChat(listener)` | Subscribe to unregistration events. | | ||
|
|
||
| ## Next Steps | ||
|
|
||
| - **[Contribution Types](../contribution-types.md)** — Explore other contribution types | ||
| - **[Development](../development.md)** — Set up your development environment | ||
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michael-s-molina would it make sense to add
onDidResizePanel()here?