From a54ad12bf1bf8874b7d6e61018a872897cc73a42 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Fri, 3 Oct 2025 17:37:45 +0530 Subject: [PATCH] feat: add custom tools frontend --- .../dashboard/api/captain/customTools.js | 36 +++++++++++++++++++ .../dashboard/store/captain/customTools.js | 35 ++++++++++++++++++ app/javascript/dashboard/store/index.js | 2 ++ 3 files changed, 73 insertions(+) create mode 100644 app/javascript/dashboard/api/captain/customTools.js create mode 100644 app/javascript/dashboard/store/captain/customTools.js diff --git a/app/javascript/dashboard/api/captain/customTools.js b/app/javascript/dashboard/api/captain/customTools.js new file mode 100644 index 000000000..d0818d941 --- /dev/null +++ b/app/javascript/dashboard/api/captain/customTools.js @@ -0,0 +1,36 @@ +/* global axios */ +import ApiClient from '../ApiClient'; + +class CaptainCustomTools extends ApiClient { + constructor() { + super('captain/custom_tools', { accountScoped: true }); + } + + get({ page = 1, searchKey } = {}) { + return axios.get(this.url, { + params: { page, searchKey }, + }); + } + + show(id) { + return axios.get(`${this.url}/${id}`); + } + + create(data = {}) { + return axios.post(this.url, { + custom_tool: data, + }); + } + + update(id, data = {}) { + return axios.put(`${this.url}/${id}`, { + custom_tool: data, + }); + } + + delete(id) { + return axios.delete(`${this.url}/${id}`); + } +} + +export default new CaptainCustomTools(); diff --git a/app/javascript/dashboard/store/captain/customTools.js b/app/javascript/dashboard/store/captain/customTools.js new file mode 100644 index 000000000..3d3af03c0 --- /dev/null +++ b/app/javascript/dashboard/store/captain/customTools.js @@ -0,0 +1,35 @@ +import CaptainCustomTools from 'dashboard/api/captain/customTools'; +import { createStore } from './storeFactory'; +import { throwErrorMessage } from 'dashboard/store/utils/api'; + +export default createStore({ + name: 'CaptainCustomTool', + API: CaptainCustomTools, + actions: mutations => ({ + update: async ({ commit }, { id, ...updateObj }) => { + commit(mutations.SET_UI_FLAG, { updatingItem: true }); + try { + const response = await CaptainCustomTools.update(id, updateObj); + commit(mutations.EDIT, response.data); + commit(mutations.SET_UI_FLAG, { updatingItem: false }); + return response.data; + } catch (error) { + commit(mutations.SET_UI_FLAG, { updatingItem: false }); + return throwErrorMessage(error); + } + }, + + delete: async ({ commit }, id) => { + commit(mutations.SET_UI_FLAG, { deletingItem: true }); + try { + await CaptainCustomTools.delete(id); + commit(mutations.DELETE, id); + commit(mutations.SET_UI_FLAG, { deletingItem: false }); + return id; + } catch (error) { + commit(mutations.SET_UI_FLAG, { deletingItem: false }); + return throwErrorMessage(error); + } + }, + }), +}); diff --git a/app/javascript/dashboard/store/index.js b/app/javascript/dashboard/store/index.js index 16bcab3f9..d56958eb5 100755 --- a/app/javascript/dashboard/store/index.js +++ b/app/javascript/dashboard/store/index.js @@ -57,6 +57,7 @@ import copilotThreads from './captain/copilotThreads'; import copilotMessages from './captain/copilotMessages'; import captainScenarios from './captain/scenarios'; import captainTools from './captain/tools'; +import captainCustomTools from './captain/customTools'; const plugins = []; @@ -119,6 +120,7 @@ export default createStore({ copilotMessages, captainScenarios, captainTools, + captainCustomTools, }, plugins, });