-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ai): Add toolbar actions for chat nodes (#14181)
Introduces a `ChatNodeToolbarActionContribution` which allows to add icons to the chat nodes in the Chat UI on hover. Clicking these icons will trigger a command that gets the respective chat node as argument. Possible use cases are actions for reporting the content, giving feedback, or perform other actions within the tool based on the response. Contributed on behalf of STMicroelectronics. Co-authored-by: Stefan Dirix <[email protected]>
- Loading branch information
Showing
9 changed files
with
175 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
41 changes: 41 additions & 0 deletions
41
examples/api-samples/src/browser/chat/chat-node-toolbar-action-contribution.ts
This file contains 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,41 @@ | ||
// ***************************************************************************** | ||
// Copyright (C) 2024 STMicroelectronics and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0. | ||
// | ||
// This Source Code may also be made available under the following Secondary | ||
// Licenses when the conditions for such availability set forth in the Eclipse | ||
// Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
// with the GNU Classpath Exception which is available at | ||
// https://www.gnu.org/software/classpath/license.html. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 | ||
// ***************************************************************************** | ||
|
||
import { | ||
ChatNodeToolbarActionContribution | ||
} from '@theia/ai-chat-ui/lib/browser/chat-node-toolbar-action-contribution'; | ||
import { | ||
isResponseNode, | ||
RequestNode, | ||
ResponseNode | ||
} from '@theia/ai-chat-ui/lib/browser/chat-tree-view'; | ||
import { interfaces } from '@theia/core/shared/inversify'; | ||
|
||
export function bindChatNodeToolbarActionContribution(bind: interfaces.Bind): void { | ||
bind(ChatNodeToolbarActionContribution).toDynamicValue(context => ({ | ||
getToolbarActions: (args: RequestNode | ResponseNode) => { | ||
if (isResponseNode(args)) { | ||
return [{ | ||
commandId: 'sample-command', | ||
icon: 'codicon codicon-feedback', | ||
tooltip: 'Example command' | ||
}]; | ||
} else { | ||
return []; | ||
} | ||
} | ||
})); | ||
} |
This file contains 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
This file contains 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
63 changes: 63 additions & 0 deletions
63
packages/ai-chat-ui/src/browser/chat-node-toolbar-action-contribution.ts
This file contains 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,63 @@ | ||
// ***************************************************************************** | ||
// Copyright (C) 2024 EclipseSource GmbH. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0. | ||
// | ||
// This Source Code may also be made available under the following Secondary | ||
// Licenses when the conditions for such availability set forth in the Eclipse | ||
// Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
// with the GNU Classpath Exception which is available at | ||
// https://www.gnu.org/software/classpath/license.html. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 | ||
// ***************************************************************************** | ||
import { RequestNode, ResponseNode } from './chat-tree-view'; | ||
|
||
export interface ChatNodeToolbarAction { | ||
/** | ||
* The command to execute when the item is selected. The handler will receive the `RequestNode` or `ResponseNode` as first argument. | ||
*/ | ||
commandId: string; | ||
/** | ||
* Icon class name(s) for the item (e.g. 'codicon codicon-feedback'). | ||
*/ | ||
icon: string; | ||
/** | ||
* Priority among the items. Can be negative. The smaller the number the left-most the item will be placed in the toolbar. It is `0` by default. | ||
*/ | ||
priority?: number; | ||
/** | ||
* Optional tooltip for the item. | ||
*/ | ||
tooltip?: string; | ||
} | ||
|
||
/** | ||
* Clients implement this interface if they want to contribute to the toolbar of chat nodes. | ||
* | ||
* ### Example | ||
* ```ts | ||
* bind(ChatNodeToolbarActionContribution).toDynamicValue(context => ({ | ||
* getToolbarActions: (args: RequestNode | ResponseNode) => { | ||
* if (isResponseNode(args)) { | ||
* return [{ | ||
* commandId: 'core.about', | ||
* icon: 'codicon codicon-feedback', | ||
* tooltip: 'Show about dialog on response nodes' | ||
* }]; | ||
* } else { | ||
* return []; | ||
* } | ||
* } | ||
* })); | ||
* ``` | ||
*/ | ||
export const ChatNodeToolbarActionContribution = Symbol('ChatNodeToolbarActionContribution'); | ||
export interface ChatNodeToolbarActionContribution { | ||
/** | ||
* Returns the toolbar actions for the given node. | ||
*/ | ||
getToolbarActions(node: RequestNode | ResponseNode): ChatNodeToolbarAction[]; | ||
} |
This file contains 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
This file contains 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