()
| 277 | } |
| 278 | |
| 279 | const addNewTool = async () => { |
| 280 | try { |
| 281 | const obj = { |
| 282 | name: toolName, |
| 283 | description: toolDesc, |
| 284 | color: generateRandomGradient(), |
| 285 | schema: JSON.stringify(toolSchema), |
| 286 | func: toolFunc, |
| 287 | iconSrc: toolIcon |
| 288 | } |
| 289 | const createResp = await toolsApi.createNewTool(obj) |
| 290 | if (createResp.data) { |
| 291 | enqueueSnackbar({ |
| 292 | message: 'New Tool added', |
| 293 | options: { |
| 294 | key: new Date().getTime() + Math.random(), |
| 295 | variant: 'success', |
| 296 | action: (key) => ( |
| 297 | <Button style={{ color: 'white' }} onClick={() => closeSnackbar(key)}> |
| 298 | <IconX /> |
| 299 | </Button> |
| 300 | ) |
| 301 | } |
| 302 | }) |
| 303 | onConfirm(createResp.data.id) |
| 304 | } |
| 305 | } catch (error) { |
| 306 | enqueueSnackbar({ |
| 307 | message: `Failed to add new Tool: ${ |
| 308 | typeof error.response.data === 'object' ? error.response.data.message : error.response.data |
| 309 | }`, |
| 310 | options: { |
| 311 | key: new Date().getTime() + Math.random(), |
| 312 | variant: 'error', |
| 313 | persist: true, |
| 314 | action: (key) => ( |
| 315 | <Button style={{ color: 'white' }} onClick={() => closeSnackbar(key)}> |
| 316 | <IconX /> |
| 317 | </Button> |
| 318 | ) |
| 319 | } |
| 320 | }) |
| 321 | onCancel() |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | const saveTool = async () => { |
| 326 | try { |
no test coverage detected