6
6
import { InputToolbarRegistry , TooltippedButton } from '@jupyter/chat' ;
7
7
import { checkIcon } from '@jupyterlab/ui-components' ;
8
8
import BuildIcon from '@mui/icons-material/Build' ;
9
- import { Menu , MenuItem , Typography } from '@mui/material' ;
9
+ import { Menu , MenuItem , Tooltip , Typography } from '@mui/material' ;
10
10
import React , { useCallback , useEffect , useState } from 'react' ;
11
11
12
12
import { ChatHandler } from '../chat-handler' ;
13
+ import { Tool } from '../tokens' ;
13
14
14
15
const SELECT_ITEM_CLASS = 'jp-AIToolSelect-item' ;
15
16
@@ -23,10 +24,8 @@ export function toolSelect(
23
24
const toolRegistry = chatContext . toolsRegistry ;
24
25
25
26
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 || [ ] ) ;
30
29
const [ menuAnchorEl , setMenuAnchorEl ] = useState < HTMLElement | null > ( null ) ;
31
30
const [ menuOpen , setMenuOpen ] = useState ( false ) ;
32
31
@@ -40,15 +39,15 @@ export function toolSelect(
40
39
} , [ ] ) ;
41
40
42
41
const onClick = useCallback (
43
- ( tool : string | null ) => {
42
+ ( tool : Tool | null ) => {
44
43
setSelectedTool ( tool ) ;
45
- chatContext . tool = toolRegistry ?. get ( tool ) || null ;
44
+ chatContext . tool = tool ;
46
45
} ,
47
46
[ props . model ]
48
47
) ;
49
48
50
49
useEffect ( ( ) => {
51
- const updateTools = ( ) => setToolNames ( toolRegistry ?. toolNames || [ ] ) ;
50
+ const updateTools = ( ) => setTools ( toolRegistry ?. tools || [ ] ) ;
52
51
toolRegistry ?. toolsChanged . connect ( updateTools ) ;
53
52
return ( ) => {
54
53
toolRegistry ?. toolsChanged . disconnect ( updateTools ) ;
@@ -63,13 +62,13 @@ export function toolSelect(
63
62
} ;
64
63
} , [ chatContext ] ) ;
65
64
66
- return useTool && toolNames . length ? (
65
+ return useTool && tools . length ? (
67
66
< >
68
67
< TooltippedButton
69
68
onClick = { e => {
70
69
openMenu ( e . currentTarget ) ;
71
70
} }
72
- disabled = { ! toolNames . length }
71
+ disabled = { ! tools . length }
73
72
tooltip = "Tool"
74
73
buttonProps = { {
75
74
variant : 'contained' ,
@@ -105,42 +104,46 @@ export function toolSelect(
105
104
} }
106
105
sx = { {
107
106
'& .MuiMenuItem-root' : {
108
- gap : '4px ' ,
109
- padding : '6px '
107
+ padding : '0.5em ' ,
108
+ paddingRight : '2em '
110
109
}
111
110
} }
112
111
>
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' } >
129
113
< MenuItem
130
114
className = { SELECT_ITEM_CLASS }
131
115
onClick = { e => {
132
- onClick ( tool ) ;
116
+ onClick ( null ) ;
133
117
// prevent sending second message with no selection
134
118
e . stopPropagation ( ) ;
135
119
} }
136
120
>
137
- { selectedTool === tool ? (
121
+ { selectedTool === null ? (
138
122
< checkIcon . react className = { 'lm-Menu-itemIcon' } />
139
123
) : (
140
124
< div className = { 'lm-Menu-itemIcon' } />
141
125
) }
142
- < Typography display = "block" > { tool } </ Typography >
126
+ < Typography display = "block" > No tool</ Typography >
143
127
</ 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 >
144
147
) ) }
145
148
</ Menu >
146
149
</ >
0 commit comments