Skip to content

Commit

Permalink
fix: tool deletion button (#606)
Browse files Browse the repository at this point in the history
  • Loading branch information
guillevalin authored Jan 20, 2025
1 parent 26c4824 commit 3662b4a
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ import { toast } from 'sonner';

import { useAuth } from '../../../store/auth';

export default function RemoveToolButton({ toolKey }: { toolKey: string }) {
export default function RemoveToolButton({
isPlaygroundTool,
toolKey,
}: {
isPlaygroundTool: boolean;
toolKey: string;
}) {
const auth = useAuth((state) => state.auth);
const navigate = useNavigate();

Expand All @@ -32,6 +38,7 @@ export default function RemoveToolButton({ toolKey }: { toolKey: string }) {
toolKey: toolKey ?? '',
nodeAddress: auth?.node_address ?? '',
token: auth?.api_v2_key ?? '',
isPlaygroundTool,
});
}}
size="sm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,10 @@ export default function ToolCard({
Go Playground
</Link>
)}
<RemoveToolButton toolKey={toolKey as string} />
<RemoveToolButton
isPlaygroundTool={isPlaygroundTool}
toolKey={toolKey as string}
/>
</div>
</div>
</SubpageLayout>
Expand Down
17 changes: 17 additions & 0 deletions libs/shinkai-message-ts/src/api/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
ImportToolResponse,
PayInvoiceRequest,
RemovePlaygroundToolRequest,
RemoveToolRequest,
RemoveToolRequestRequest,
SaveToolCodeRequest,
SaveToolCodeResponse,
Expand Down Expand Up @@ -333,6 +334,22 @@ export const restoreToolConversation = async (
return response.data as UndoToolImplementationResponse;
};

export const removeTool = async (
nodeAddress: string,
bearerToken: string,
payload: RemoveToolRequest,
) => {
const response = await httpClient.delete(
urlJoin(nodeAddress, '/v2/remove_tool'),
{
params: { tool_key: payload.tool_key },
headers: { Authorization: `Bearer ${bearerToken}` },
responseType: 'json',
},
);
return response.data;
};

export const removePlaygroundTool = async (
nodeAddress: string,
bearerToken: string,
Expand Down
4 changes: 4 additions & 0 deletions libs/shinkai-message-ts/src/api/tools/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ export type RemovePlaygroundToolRequest = {
tool_key: string;
};

export type RemoveToolRequest = {
tool_key: string;
};

export type ImportToolRequest = {
url: string;
};
Expand Down
19 changes: 18 additions & 1 deletion libs/shinkai-node-state/src/v2/mutations/removeTool/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
import { removePlaygroundTool as removePlaygroundToolApi } from '@shinkai_network/shinkai-message-ts/api/tools/index';
import {
removePlaygroundTool as removePlaygroundToolApi,
removeTool as removeToolApi,
} from '@shinkai_network/shinkai-message-ts/api/tools/index';

import { RemoveToolInput } from './types';

export const removeTool = async ({
nodeAddress,
token,
toolKey,
isPlaygroundTool,
}: RemoveToolInput) => {
if (isPlaygroundTool) {
return await removePlaygroundTool({ nodeAddress, token, toolKey });
}
return await removeToolApi(nodeAddress, token, {
tool_key: toolKey,
});
};

export const removePlaygroundTool = async ({
nodeAddress,
token,
toolKey,
}: RemoveToolInput) => {
return await removePlaygroundToolApi(nodeAddress, token, {
tool_key: toolKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export type RemoveToolOutput = {
export type RemoveToolInput = Token & {
nodeAddress: string;
toolKey: string;
isPlaygroundTool?: boolean;
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const useRemoveTool = (options?: Options) => {
{
nodeAddress: variables.nodeAddress,
token: variables.token,
isPlaygroundTool: variables.isPlaygroundTool,
},
],
});
Expand Down

0 comments on commit 3662b4a

Please sign in to comment.