Skip to content

Commit 9f272aa

Browse files
committed
Add tooltips on the tool item
1 parent fe0012b commit 9f272aa

File tree

4 files changed

+40
-37
lines changed

4 files changed

+40
-37
lines changed

schema/chat.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"UseTool": {
2727
"type": "boolean",
2828
"title": "Use tool",
29-
"description": "Whether to be able to use or not a tool in chat",
29+
"description": "Whether tools are available in chat or not",
3030
"default": false
3131
}
3232
},

src/components/tool-select.tsx

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
import { InputToolbarRegistry, TooltippedButton } from '@jupyter/chat';
77
import { checkIcon } from '@jupyterlab/ui-components';
88
import BuildIcon from '@mui/icons-material/Build';
9-
import { Menu, MenuItem, Typography } from '@mui/material';
9+
import { Menu, MenuItem, Tooltip, Typography } from '@mui/material';
1010
import React, { useCallback, useEffect, useState } from 'react';
1111

1212
import { ChatHandler } from '../chat-handler';
13+
import { Tool } from '../tokens';
1314

1415
const SELECT_ITEM_CLASS = 'jp-AIToolSelect-item';
1516

@@ -23,10 +24,8 @@ export function toolSelect(
2324
const toolRegistry = chatContext.toolsRegistry;
2425

2526
const [useTool, setUseTool] = useState<boolean>(chatContext.useTool);
26-
const [selectedTool, setSelectedTool] = useState<string | null>(null);
27-
const [toolNames, setToolNames] = useState<string[]>(
28-
toolRegistry?.toolNames || []
29-
);
27+
const [selectedTool, setSelectedTool] = useState<Tool | null>(null);
28+
const [tools, setTools] = useState<Tool[]>(toolRegistry?.tools || []);
3029
const [menuAnchorEl, setMenuAnchorEl] = useState<HTMLElement | null>(null);
3130
const [menuOpen, setMenuOpen] = useState(false);
3231

@@ -40,15 +39,15 @@ export function toolSelect(
4039
}, []);
4140

4241
const onClick = useCallback(
43-
(tool: string | null) => {
42+
(tool: Tool | null) => {
4443
setSelectedTool(tool);
45-
chatContext.tool = toolRegistry?.get(tool) || null;
44+
chatContext.tool = tool;
4645
},
4746
[props.model]
4847
);
4948

5049
useEffect(() => {
51-
const updateTools = () => setToolNames(toolRegistry?.toolNames || []);
50+
const updateTools = () => setTools(toolRegistry?.tools || []);
5251
toolRegistry?.toolsChanged.connect(updateTools);
5352
return () => {
5453
toolRegistry?.toolsChanged.disconnect(updateTools);
@@ -63,13 +62,13 @@ export function toolSelect(
6362
};
6463
}, [chatContext]);
6564

66-
return useTool && toolNames.length ? (
65+
return useTool && tools.length ? (
6766
<>
6867
<TooltippedButton
6968
onClick={e => {
7069
openMenu(e.currentTarget);
7170
}}
72-
disabled={!toolNames.length}
71+
disabled={!tools.length}
7372
tooltip="Tool"
7473
buttonProps={{
7574
variant: 'contained',
@@ -105,42 +104,46 @@ export function toolSelect(
105104
}}
106105
sx={{
107106
'& .MuiMenuItem-root': {
108-
gap: '4px',
109-
padding: '6px'
107+
padding: '0.5em',
108+
paddingRight: '2em'
110109
}
111110
}}
112111
>
113-
<MenuItem
114-
className={SELECT_ITEM_CLASS}
115-
onClick={e => {
116-
onClick(null);
117-
// prevent sending second message with no selection
118-
e.stopPropagation();
119-
}}
120-
>
121-
{selectedTool === null ? (
122-
<checkIcon.react className={'lm-Menu-itemIcon'} />
123-
) : (
124-
<div className={'lm-Menu-itemIcon'} />
125-
)}
126-
<Typography display="block">No tool</Typography>
127-
</MenuItem>
128-
{toolNames.map(tool => (
112+
<Tooltip title={'Do not use a tool'}>
129113
<MenuItem
130114
className={SELECT_ITEM_CLASS}
131115
onClick={e => {
132-
onClick(tool);
116+
onClick(null);
133117
// prevent sending second message with no selection
134118
e.stopPropagation();
135119
}}
136120
>
137-
{selectedTool === tool ? (
121+
{selectedTool === null ? (
138122
<checkIcon.react className={'lm-Menu-itemIcon'} />
139123
) : (
140124
<div className={'lm-Menu-itemIcon'} />
141125
)}
142-
<Typography display="block">{tool}</Typography>
126+
<Typography display="block">No tool</Typography>
143127
</MenuItem>
128+
</Tooltip>
129+
{tools.map(tool => (
130+
<Tooltip title={tool.description}>
131+
<MenuItem
132+
className={SELECT_ITEM_CLASS}
133+
onClick={e => {
134+
onClick(tool);
135+
// prevent sending second message with no selection
136+
e.stopPropagation();
137+
}}
138+
>
139+
{selectedTool === tool ? (
140+
<checkIcon.react className={'lm-Menu-itemIcon'} />
141+
) : (
142+
<div className={'lm-Menu-itemIcon'} />
143+
)}
144+
<Typography display="block">{tool.name}</Typography>
145+
</MenuItem>
146+
</Tooltip>
144147
))}
145148
</Menu>
146149
</>

src/tokens.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@ export type Tool = StructuredToolInterface;
169169
*/
170170
export interface IToolRegistry {
171171
/**
172-
* The registered tool names.
172+
* The registered tools.
173173
*/
174-
readonly toolNames: string[];
174+
readonly tools: Tool[];
175175
/**
176176
* A signal triggered when the tools has changed;
177177
*/

src/tool-registry.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { IToolRegistry, Tool } from './tokens';
33

44
export class ToolsRegistry implements IToolRegistry {
55
/**
6-
* The registered tool names.
6+
* The registered tools.
77
*/
8-
get toolNames(): string[] {
9-
return this._tools.map(tool => tool.name);
8+
get tools(): Tool[] {
9+
return this._tools;
1010
}
1111

1212
/**

0 commit comments

Comments
 (0)