@@ -5,6 +5,8 @@ import * as TypesGen from "api/typesGenerated";
5
5
import CheckCircle from "@mui/icons-material/CheckCircle" ;
6
6
import CircularProgress from "@mui/material/CircularProgress" ;
7
7
import ErrorIcon from "@mui/icons-material/Error" ;
8
+ import CodeIcon from "@mui/icons-material/Code" ;
9
+ import ArticleIcon from "@mui/icons-material/Article" ;
8
10
9
11
interface ChatToolInvocationProps {
10
12
toolInvocation : ChatToolInvocations ;
@@ -14,25 +16,44 @@ export const ChatToolInvocation: FC<ChatToolInvocationProps> = ({
14
16
toolInvocation,
15
17
} ) => {
16
18
const theme = useTheme ( ) ;
19
+ const friendlyName = useMemo ( ( ) => {
20
+ return toolInvocation . toolName
21
+ . replace ( "coder_" , "" )
22
+ . replace ( / _ / g, " " )
23
+ . replace ( / \b \w / g, ( char ) => char . toUpperCase ( ) ) ;
24
+ } , [ toolInvocation . toolName ] ) ;
17
25
18
26
let preview : React . ReactNode ;
19
27
switch ( toolInvocation . toolName ) {
20
28
case "coder_get_workspace" :
21
29
switch ( toolInvocation . state ) {
22
30
case "partial-call" :
23
31
case "call" :
24
- preview = < div > Getting Workspace By ID...</ div > ;
32
+ preview = (
33
+ < div css = { { display : "flex" , alignItems : "center" , gap : theme . spacing ( 1 ) , color : theme . palette . text . secondary } } >
34
+ < CircularProgress size = { 14 } color = "inherit" />
35
+ < span > Fetching workspace details...</ span >
36
+ </ div >
37
+ ) ;
25
38
break ;
26
39
case "result" :
27
40
preview = (
28
- < div css = { { display : "flex" , alignItems : "center" } } >
41
+ < div css = { { display : "flex" , alignItems : "center" , gap : theme . spacing ( 1.5 ) } } >
29
42
< img
30
43
src = { toolInvocation . result . template_icon || "/icon/code.svg" }
31
- alt = { toolInvocation . result . name }
44
+ alt = { toolInvocation . result . template_display_name || "Template" }
45
+ css = { {
46
+ width : 32 ,
47
+ height : 32 ,
48
+ borderRadius : theme . shape . borderRadius / 2 ,
49
+ objectFit : "contain" ,
50
+ } }
32
51
/>
33
52
< div >
34
- < div > { toolInvocation . result . name } </ div >
35
- < div > { toolInvocation . result . template_display_name } </ div >
53
+ < div css = { { fontWeight : 500 , lineHeight : 1.4 } } > { toolInvocation . result . name } </ div >
54
+ < div css = { { fontSize : "0.875rem" , color : theme . palette . text . secondary , lineHeight : 1.4 } } >
55
+ { toolInvocation . result . template_display_name }
56
+ </ div >
36
57
</ div >
37
58
</ div >
38
59
) ;
@@ -43,10 +64,20 @@ export const ChatToolInvocation: FC<ChatToolInvocationProps> = ({
43
64
switch ( toolInvocation . state ) {
44
65
case "partial-call" :
45
66
case "call" :
46
- preview = < div > Running Tool...</ div > ;
67
+ preview = (
68
+ < div css = { { display : "flex" , alignItems : "center" , gap : theme . spacing ( 1 ) , color : theme . palette . text . secondary } } >
69
+ < CircularProgress size = { 14 } color = "inherit" />
70
+ < span > Executing { friendlyName } ...</ span >
71
+ </ div >
72
+ ) ;
47
73
break ;
48
74
case "result" :
49
- preview = < pre > { JSON . stringify ( toolInvocation . result , null , 2 ) } </ pre > ;
75
+ preview = (
76
+ < div css = { { display : 'flex' , alignItems : 'center' , gap : theme . spacing ( 1 ) , color : theme . palette . text . secondary } } >
77
+ < ArticleIcon sx = { { fontSize : 16 } } />
78
+ < span > { friendlyName } result received.</ span >
79
+ </ div >
80
+ ) ;
50
81
break ;
51
82
}
52
83
}
@@ -57,35 +88,30 @@ export const ChatToolInvocation: FC<ChatToolInvocationProps> = ({
57
88
}
58
89
return (
59
90
typeof toolInvocation . result === "object" &&
91
+ toolInvocation . result !== null &&
60
92
"error" in toolInvocation . result
61
93
) ;
62
94
} , [ toolInvocation ] ) ;
63
95
const statusColor = useMemo ( ( ) => {
64
96
if ( toolInvocation . state !== "result" ) {
65
- return theme . palette . primary . main ;
97
+ return theme . palette . info . main ;
66
98
}
67
99
return hasError ? theme . palette . error . main : theme . palette . success . main ;
68
- } , [ toolInvocation , hasError ] ) ;
69
- const friendlyName = useMemo ( ( ) => {
70
- return toolInvocation . toolName
71
- . replace ( "coder_" , "" )
72
- . replace ( "_" , " " )
73
- . replace ( / \b \w / g, ( char ) => char . toUpperCase ( ) ) ;
74
- } , [ toolInvocation . toolName ] ) ;
100
+ } , [ toolInvocation , hasError , theme ] ) ;
75
101
76
102
return (
77
103
< div
78
104
css = { {
79
105
marginTop : theme . spacing ( 1 ) ,
80
- marginLeft : theme . spacing ( 2 ) ,
81
- borderLeft : `2px solid ${ theme . palette . info . light } ` ,
106
+ marginLeft : theme . spacing ( 3 ) ,
107
+ borderLeft : `2px solid ${ theme . palette . divider } ` ,
82
108
paddingLeft : theme . spacing ( 1.5 ) ,
83
109
display : "flex" ,
84
110
flexDirection : "column" ,
85
- gap : theme . spacing ( 1 ) ,
111
+ gap : theme . spacing ( 0.75 ) ,
86
112
} }
87
113
>
88
- < div css = { { display : "flex" , alignItems : "center" } } >
114
+ < div css = { { display : "flex" , alignItems : "center" , gap : theme . spacing ( 1 ) } } >
89
115
{ toolInvocation . state !== "result" && (
90
116
< CircularProgress
91
117
size = { 16 }
@@ -104,12 +130,15 @@ export const ChatToolInvocation: FC<ChatToolInvocationProps> = ({
104
130
< div
105
131
css = { {
106
132
flex : 1 ,
133
+ fontSize : '0.9rem' ,
134
+ fontWeight : 500 ,
135
+ color : theme . palette . text . primary ,
107
136
} }
108
137
>
109
138
{ friendlyName }
110
139
</ div >
111
140
</ div >
112
- < div > { preview } </ div >
141
+ < div css = { { paddingLeft : theme . spacing ( 3 ) } } > { preview } </ div >
113
142
</ div >
114
143
) ;
115
144
} ;
@@ -120,7 +149,7 @@ export type ChatToolInvocations =
120
149
{
121
150
id : string ;
122
151
} ,
123
- TypesGen . Workspace
152
+ TypesGen . Workspace & { error ?: any }
124
153
>
125
154
| ToolInvocation <
126
155
"coder_create_workspace" ,
@@ -130,7 +159,7 @@ export type ChatToolInvocations =
130
159
name : string ;
131
160
rich_parameters : Record < string , any > ;
132
161
} ,
133
- TypesGen . Workspace
162
+ TypesGen . Workspace & { error ?: any }
134
163
>
135
164
| ToolInvocation <
136
165
"coder_list_workspaces" ,
@@ -147,7 +176,7 @@ export type ChatToolInvocations =
147
176
| "template_icon"
148
177
| "template_active_version_id"
149
178
| "outdated"
150
- > [ ]
179
+ > [ ] & { error ?: any }
151
180
>
152
181
| ToolInvocation <
153
182
"coder_list_templates" ,
@@ -159,83 +188,84 @@ export type ChatToolInvocations =
159
188
| "description"
160
189
| "active_version_id"
161
190
| "active_user_count"
162
- > [ ]
191
+ > [ ] & { error ?: any }
163
192
>
164
193
| ToolInvocation <
165
194
"coder_template_version_parameters" ,
166
195
{
167
196
template_version_id : string ;
168
197
} ,
169
- TypesGen . TemplateVersionParameter [ ]
198
+ TypesGen . TemplateVersionParameter [ ] & { error ?: any }
170
199
>
171
- | ToolInvocation < "coder_get_authenticated_user" , { } , TypesGen . User >
200
+ | ToolInvocation < "coder_get_authenticated_user" , { } , TypesGen . User & { error ?: any } >
172
201
| ToolInvocation <
173
202
"coder_create_workspace_build" ,
174
203
{
175
204
workspace_id : string ;
176
205
transition : "start" | "stop" | "delete" ;
177
206
} ,
178
- TypesGen . WorkspaceBuild
207
+ TypesGen . WorkspaceBuild & { error ?: any }
179
208
>
180
209
| ToolInvocation <
181
210
"coder_create_template_version" ,
182
211
{
183
212
template_id ?: string ;
184
213
file_id : string ;
185
214
} ,
186
- TypesGen . TemplateVersion
215
+ TypesGen . TemplateVersion & { error ?: any }
187
216
>
188
217
| ToolInvocation <
189
218
"coder_get_workspace_agent_logs" ,
190
219
{
191
220
workspace_agent_id : string ;
192
221
} ,
193
- string [ ]
222
+ string [ ] & { error ?: any }
194
223
>
195
224
| ToolInvocation <
196
225
"coder_get_workspace_build_logs" ,
197
226
{
198
227
workspace_build_id : string ;
199
228
} ,
200
- string [ ]
229
+ string [ ] & { error ?: any }
201
230
>
202
231
| ToolInvocation <
203
232
"coder_get_template_version_logs" ,
204
233
{
205
234
template_version_id : string ;
206
235
} ,
207
- string [ ]
236
+ string [ ] & { error ?: any }
208
237
>
209
238
| ToolInvocation <
210
239
"coder_update_template_active_version" ,
211
240
{
212
241
template_id : string ;
213
242
template_version_id : string ;
214
243
} ,
215
- string
244
+ string & { error ?: any }
216
245
>
217
246
| ToolInvocation <
218
247
"coder_upload_tar_file" ,
219
248
{
220
249
mime_type : string ;
221
250
files : Record < string , string > ;
222
251
} ,
223
- TypesGen . UploadResponse
252
+ TypesGen . UploadResponse & { error ?: any }
224
253
>
225
254
| ToolInvocation <
226
255
"coder_create_template" ,
227
256
{
228
257
name : string ;
229
258
} ,
230
- TypesGen . Template
259
+ TypesGen . Template & { error ?: any }
231
260
>
232
261
| ToolInvocation <
233
262
"coder_delete_template" ,
234
263
{
235
264
template_id : string ;
236
265
} ,
237
- string
238
- > ;
266
+ string & { error ?: any }
267
+ >
268
+ | ToolInvocation < string , Record < string , any > , any & { error ?: any } > ;
239
269
240
270
type ToolInvocation < N extends string , A , R > =
241
271
| ( {
@@ -249,4 +279,4 @@ type ToolInvocation<N extends string, A, R> =
249
279
| ( {
250
280
state : "result" ;
251
281
step ?: number ;
252
- } & ToolResult < N , A , R > ) ;
282
+ } & ToolResult < N , A , R & { error ?: any } > ) ;
0 commit comments