From 61683d51b9964274503453d3efe23b99650a7841 Mon Sep 17 00:00:00 2001 From: paulclindo Date: Mon, 16 Dec 2024 17:44:18 -0500 Subject: [PATCH 1/6] feat: remove tools --- .../src/components/tools/deno-tool.tsx | 38 +++++++++++++++--- .../src/components/tools/python-tool.tsx | 39 ++++++++++++++++--- .../shinkai-message-ts/src/api/tools/index.ts | 17 ++++++++ .../shinkai-message-ts/src/api/tools/types.ts | 4 ++ .../src/v2/mutations/removeTool/index.ts | 13 +++++++ .../src/v2/mutations/removeTool/types.ts | 10 +++++ .../v2/mutations/removeTool/useRemoveTool.ts | 35 +++++++++++++++++ 7 files changed, 146 insertions(+), 10 deletions(-) create mode 100644 libs/shinkai-node-state/src/v2/mutations/removeTool/index.ts create mode 100644 libs/shinkai-node-state/src/v2/mutations/removeTool/types.ts create mode 100644 libs/shinkai-node-state/src/v2/mutations/removeTool/useRemoveTool.ts diff --git a/apps/shinkai-desktop/src/components/tools/deno-tool.tsx b/apps/shinkai-desktop/src/components/tools/deno-tool.tsx index ff3d7fc63..a2596586a 100644 --- a/apps/shinkai-desktop/src/components/tools/deno-tool.tsx +++ b/apps/shinkai-desktop/src/components/tools/deno-tool.tsx @@ -5,6 +5,7 @@ import { ShinkaiTool, } from '@shinkai_network/shinkai-message-ts/api/tools/types'; import { useExportTool } from '@shinkai_network/shinkai-node-state/v2/mutations/exportTool/useExportTool'; +import { useRemoveTool } from '@shinkai_network/shinkai-node-state/v2/mutations/removeTool/useRemoveTool'; import { useUpdateTool } from '@shinkai_network/shinkai-node-state/v2/mutations/updateTool/useUpdateTool'; import { Button, @@ -21,7 +22,7 @@ import * as fs from '@tauri-apps/plugin-fs'; import { BaseDirectory } from '@tauri-apps/plugin-fs'; import { DownloadIcon } from 'lucide-react'; import { useForm } from 'react-hook-form'; -import { Link, useParams } from 'react-router-dom'; +import { Link, useNavigate, useParams } from 'react-router-dom'; import { toast } from 'sonner'; import { z } from 'zod'; @@ -49,6 +50,7 @@ export default function DenoTool({ }) { const auth = useAuth((state) => state.auth); const { toolKey } = useParams(); + const navigate = useNavigate(); const { t } = useTranslation(); const { mutateAsync: updateTool, isPending } = useUpdateTool({ @@ -66,6 +68,18 @@ export default function DenoTool({ }); }, }); + const { mutateAsync: removeTool, isPending: isRemoveToolPending } = + useRemoveTool({ + onSuccess: () => { + toast.success('Tool has been removed successfully'); + navigate('/tools'); + }, + onError: (error) => { + toast.error('Failed to remove tool', { + description: error.response?.data?.message ?? error.message, + }); + }, + }); const { mutateAsync: exportTool, isPending: isExportingTool } = useExportTool( { @@ -241,8 +255,8 @@ export default function DenoTool({ )} -
- {isPlaygroundTool && ( + {isPlaygroundTool && ( +
Go Playground - )} -
+ +
+ )} ); diff --git a/apps/shinkai-desktop/src/components/tools/python-tool.tsx b/apps/shinkai-desktop/src/components/tools/python-tool.tsx index 641c63007..b32771c41 100644 --- a/apps/shinkai-desktop/src/components/tools/python-tool.tsx +++ b/apps/shinkai-desktop/src/components/tools/python-tool.tsx @@ -5,6 +5,7 @@ import { ShinkaiTool, } from '@shinkai_network/shinkai-message-ts/api/tools/types'; import { useExportTool } from '@shinkai_network/shinkai-node-state/v2/mutations/exportTool/useExportTool'; +import { useRemoveTool } from '@shinkai_network/shinkai-node-state/v2/mutations/removeTool/useRemoveTool'; import { useUpdateTool } from '@shinkai_network/shinkai-node-state/v2/mutations/updateTool/useUpdateTool'; import { Button, @@ -21,7 +22,7 @@ import * as fs from '@tauri-apps/plugin-fs'; import { BaseDirectory } from '@tauri-apps/plugin-fs'; import { DownloadIcon } from 'lucide-react'; import { useForm } from 'react-hook-form'; -import { Link, useParams } from 'react-router-dom'; +import { Link, useNavigate, useParams } from 'react-router-dom'; import { toast } from 'sonner'; import { z } from 'zod'; @@ -49,6 +50,7 @@ export default function PythonTool({ }) { const auth = useAuth((state) => state.auth); const { toolKey } = useParams(); + const navigate = useNavigate(); const { t } = useTranslation(); const { mutateAsync: updateTool, isPending } = useUpdateTool({ @@ -67,6 +69,19 @@ export default function PythonTool({ }, }); + const { mutateAsync: removeTool, isPending: isRemoveToolPending } = + useRemoveTool({ + onSuccess: () => { + toast.success('Tool has been removed successfully'); + navigate('/tools'); + }, + onError: (error) => { + toast.error('Failed to remove tool', { + description: error.response?.data?.message ?? error.message, + }); + }, + }); + const { mutateAsync: exportTool, isPending: isExportingTool } = useExportTool( { onSuccess: async (response, variables) => { @@ -241,8 +256,8 @@ export default function PythonTool({ )} -
- {isPlaygroundTool && ( + {isPlaygroundTool && ( +
Go Playground - )} -
+ +
+ )} ); diff --git a/libs/shinkai-message-ts/src/api/tools/index.ts b/libs/shinkai-message-ts/src/api/tools/index.ts index c14afcca9..e2e52739f 100644 --- a/libs/shinkai-message-ts/src/api/tools/index.ts +++ b/libs/shinkai-message-ts/src/api/tools/index.ts @@ -22,6 +22,7 @@ import { ImportToolRequest, ImportToolResponse, PayInvoiceRequest, + RemovePlaygroundToolRequest, SaveToolCodeRequest, SaveToolCodeResponse, SearchPromptsResponse, @@ -316,6 +317,22 @@ export const restoreToolConversation = async ( return response.data as UndoToolImplementationResponse; }; +export const removePlaygroundTool = async ( + nodeAddress: string, + bearerToken: string, + payload: RemovePlaygroundToolRequest, +) => { + const response = await httpClient.delete( + urlJoin(nodeAddress, '/v2/remove_playground_tool'), + { + params: { tool_key: payload.tool_key }, + headers: { Authorization: `Bearer ${bearerToken}` }, + responseType: 'json', + }, + ); + return response.data; +}; + export const updateToolCodeImplementation = async ( nodeAddress: string, bearerToken: string, diff --git a/libs/shinkai-message-ts/src/api/tools/types.ts b/libs/shinkai-message-ts/src/api/tools/types.ts index 0b10cadfe..97c42a597 100644 --- a/libs/shinkai-message-ts/src/api/tools/types.ts +++ b/libs/shinkai-message-ts/src/api/tools/types.ts @@ -293,6 +293,10 @@ export type UpdateToolCodeImplementationResponse = { status: string; }; +export type RemovePlaygroundToolRequest = { + tool_key: string; +}; + export type ImportToolRequest = { url: string; }; diff --git a/libs/shinkai-node-state/src/v2/mutations/removeTool/index.ts b/libs/shinkai-node-state/src/v2/mutations/removeTool/index.ts new file mode 100644 index 000000000..534314ae6 --- /dev/null +++ b/libs/shinkai-node-state/src/v2/mutations/removeTool/index.ts @@ -0,0 +1,13 @@ +import { removePlaygroundTool as removePlaygroundToolApi } from '@shinkai_network/shinkai-message-ts/api/tools/index'; + +import { RemoveToolInput } from './types'; + +export const removeTool = async ({ + nodeAddress, + token, + toolKey, +}: RemoveToolInput) => { + return await removePlaygroundToolApi(nodeAddress, token, { + tool_key: toolKey, + }); +}; diff --git a/libs/shinkai-node-state/src/v2/mutations/removeTool/types.ts b/libs/shinkai-node-state/src/v2/mutations/removeTool/types.ts new file mode 100644 index 000000000..f846e2612 --- /dev/null +++ b/libs/shinkai-node-state/src/v2/mutations/removeTool/types.ts @@ -0,0 +1,10 @@ +import { Token } from '@shinkai_network/shinkai-message-ts/api/general/types'; + +export type RemoveToolOutput = { + status: string; +}; + +export type RemoveToolInput = Token & { + nodeAddress: string; + toolKey: string; +}; diff --git a/libs/shinkai-node-state/src/v2/mutations/removeTool/useRemoveTool.ts b/libs/shinkai-node-state/src/v2/mutations/removeTool/useRemoveTool.ts new file mode 100644 index 000000000..fc51985eb --- /dev/null +++ b/libs/shinkai-node-state/src/v2/mutations/removeTool/useRemoveTool.ts @@ -0,0 +1,35 @@ +import { + useMutation, + type UseMutationOptions, + useQueryClient, +} from '@tanstack/react-query'; + +import { FunctionKeyV2 } from '../../constants'; +import { APIError } from '../../types'; +import { removeTool } from './index'; +import { RemoveToolInput, RemoveToolOutput } from './types'; + +type Options = UseMutationOptions; + +export const useRemoveTool = (options?: Options) => { + const queryClient = useQueryClient(); + return useMutation({ + mutationFn: removeTool, + ...options, + onSuccess: (response, variables, context) => { + queryClient.invalidateQueries({ + queryKey: [ + FunctionKeyV2.GET_PLAYGROUND_TOOLS, + { + nodeAddress: variables.nodeAddress, + token: variables.token, + }, + ], + }); + + if (options?.onSuccess) { + options.onSuccess(response, variables, context); + } + }, + }); +}; From 7813f408193b6109833d7d8134c16584cf736bd8 Mon Sep 17 00:00:00 2001 From: paulclindo Date: Mon, 16 Dec 2024 18:04:56 -0500 Subject: [PATCH 2/6] wip tool selection --- .../components/chat/conversation-footer.tsx | 137 ++++++++---------- .../shinkai-message-ts/src/api/tools/types.ts | 3 + 2 files changed, 67 insertions(+), 73 deletions(-) diff --git a/apps/shinkai-desktop/src/components/chat/conversation-footer.tsx b/apps/shinkai-desktop/src/components/chat/conversation-footer.tsx index 11b6ed836..5f3581c4c 100644 --- a/apps/shinkai-desktop/src/components/chat/conversation-footer.tsx +++ b/apps/shinkai-desktop/src/components/chat/conversation-footer.tsx @@ -421,42 +421,13 @@ function ConversationEmptyFooter() { <> {isDragActive && } {selectedTool && ( -
- - -
- -
- - {formatText(selectedTool.name)}{' '} - - -
-
-
- - - {selectedTool.description} - - -
- - -
+ { + chatForm.setValue('tool', undefined); + }} + /> )} {!isDragActive && currentFiles && @@ -513,7 +484,11 @@ function ConversationEmptyFooter() { - + {tool.description} @@ -778,42 +753,13 @@ function ConversationChatFooter({ inboxId }: { inboxId: string }) { <> {isDragActive && } {selectedTool && ( -
- - -
- -
- - {formatText(selectedTool.name)}{' '} - - -
-
-
- - - {selectedTool.description} - - -
- - -
+ { + chatForm.setValue('tool', undefined); + }} + /> )} {!isDragActive && currentFiles && @@ -1013,3 +959,48 @@ const DropFileActive = () => ( ); + +const SelectedToolChat = ({ + name, + description, + remove, +}: { + name: string; + description: string; + remove: () => void; +}) => { + return ( +
+ + +
+ +
+ {name} + +
+
+
+ + + {description} + + +
+ + +
+ ); +}; diff --git a/libs/shinkai-message-ts/src/api/tools/types.ts b/libs/shinkai-message-ts/src/api/tools/types.ts index 97c42a597..2dd469c0a 100644 --- a/libs/shinkai-message-ts/src/api/tools/types.ts +++ b/libs/shinkai-message-ts/src/api/tools/types.ts @@ -10,6 +10,9 @@ export type ShinkaiToolHeader = { tool_router_key: string; tool_type: ShinkaiToolType; version: string; + input_args: { + properties: Record; + }; }; export type ToolConfig = { From 509375d20bf899d40ca15c43e01e70011ca3808c Mon Sep 17 00:00:00 2001 From: paulclindo Date: Mon, 16 Dec 2024 18:33:07 -0500 Subject: [PATCH 3/6] feat: remove tool --- .../components/remove-tool-button.tsx | 43 +++++++++++++++++++ .../src/components/tools/deno-tool.tsx | 40 +++-------------- .../src/components/tools/network-tool.tsx | 4 ++ .../src/components/tools/python-tool.tsx | 41 +++--------------- .../src/components/tools/rust-tool.tsx | 4 ++ 5 files changed, 65 insertions(+), 67 deletions(-) create mode 100644 apps/shinkai-desktop/src/components/playground-tool/components/remove-tool-button.tsx diff --git a/apps/shinkai-desktop/src/components/playground-tool/components/remove-tool-button.tsx b/apps/shinkai-desktop/src/components/playground-tool/components/remove-tool-button.tsx new file mode 100644 index 000000000..9daa278c9 --- /dev/null +++ b/apps/shinkai-desktop/src/components/playground-tool/components/remove-tool-button.tsx @@ -0,0 +1,43 @@ +import { useRemoveTool } from '@shinkai_network/shinkai-node-state/v2/mutations/removeTool/useRemoveTool'; +import { Button } from '@shinkai_network/shinkai-ui'; +import { useNavigate } from 'react-router-dom'; +import { toast } from 'sonner'; + +import { useAuth } from '../../../store/auth'; + +export default function RemoveToolButton({ toolKey }: { toolKey: string }) { + const auth = useAuth((state) => state.auth); + const navigate = useNavigate(); + + const { mutateAsync: removeTool, isPending: isRemoveToolPending } = + useRemoveTool({ + onSuccess: () => { + toast.success('Tool has been removed successfully'); + navigate('/tools'); + }, + onError: (error) => { + toast.error('Failed to remove tool', { + description: error.response?.data?.message ?? error.message, + }); + }, + }); + + return ( + + ); +} diff --git a/apps/shinkai-desktop/src/components/tools/deno-tool.tsx b/apps/shinkai-desktop/src/components/tools/deno-tool.tsx index a2596586a..7112b66d9 100644 --- a/apps/shinkai-desktop/src/components/tools/deno-tool.tsx +++ b/apps/shinkai-desktop/src/components/tools/deno-tool.tsx @@ -5,7 +5,6 @@ import { ShinkaiTool, } from '@shinkai_network/shinkai-message-ts/api/tools/types'; import { useExportTool } from '@shinkai_network/shinkai-node-state/v2/mutations/exportTool/useExportTool'; -import { useRemoveTool } from '@shinkai_network/shinkai-node-state/v2/mutations/removeTool/useRemoveTool'; import { useUpdateTool } from '@shinkai_network/shinkai-node-state/v2/mutations/updateTool/useUpdateTool'; import { Button, @@ -22,12 +21,13 @@ import * as fs from '@tauri-apps/plugin-fs'; import { BaseDirectory } from '@tauri-apps/plugin-fs'; import { DownloadIcon } from 'lucide-react'; import { useForm } from 'react-hook-form'; -import { Link, useNavigate, useParams } from 'react-router-dom'; +import { Link, useParams } from 'react-router-dom'; import { toast } from 'sonner'; import { z } from 'zod'; import { SubpageLayout } from '../../pages/layout/simple-layout'; import { useAuth } from '../../store/auth'; +import RemoveToolButton from '../playground-tool/components/remove-tool-button'; const jsToolSchema = z.object({ config: z.array( z.object({ @@ -50,7 +50,6 @@ export default function DenoTool({ }) { const auth = useAuth((state) => state.auth); const { toolKey } = useParams(); - const navigate = useNavigate(); const { t } = useTranslation(); const { mutateAsync: updateTool, isPending } = useUpdateTool({ @@ -68,18 +67,6 @@ export default function DenoTool({ }); }, }); - const { mutateAsync: removeTool, isPending: isRemoveToolPending } = - useRemoveTool({ - onSuccess: () => { - toast.success('Tool has been removed successfully'); - navigate('/tools'); - }, - onError: (error) => { - toast.error('Failed to remove tool', { - description: error.response?.data?.message ?? error.message, - }); - }, - }); const { mutateAsync: exportTool, isPending: isExportingTool } = useExportTool( { @@ -255,8 +242,8 @@ export default function DenoTool({ )} - {isPlaygroundTool && ( -
+
+ {isPlaygroundTool && ( Go Playground - -
- )} + )} + +
); diff --git a/apps/shinkai-desktop/src/components/tools/network-tool.tsx b/apps/shinkai-desktop/src/components/tools/network-tool.tsx index a541f2f2c..21296166e 100644 --- a/apps/shinkai-desktop/src/components/tools/network-tool.tsx +++ b/apps/shinkai-desktop/src/components/tools/network-tool.tsx @@ -28,6 +28,7 @@ import { toast } from 'sonner'; // import { z } from 'zod'; import { SubpageLayout } from '../../pages/layout/simple-layout'; import { useAuth } from '../../store/auth'; +import RemoveToolButton from '../playground-tool/components/remove-tool-button'; // const jsToolSchema = z.object({ // config: z.array( @@ -247,6 +248,9 @@ export default function NetworkTool({ {/* Go Playground*/} {/* */} {/*)}*/} +
+ +
); diff --git a/apps/shinkai-desktop/src/components/tools/python-tool.tsx b/apps/shinkai-desktop/src/components/tools/python-tool.tsx index b32771c41..c62cd26b2 100644 --- a/apps/shinkai-desktop/src/components/tools/python-tool.tsx +++ b/apps/shinkai-desktop/src/components/tools/python-tool.tsx @@ -5,7 +5,6 @@ import { ShinkaiTool, } from '@shinkai_network/shinkai-message-ts/api/tools/types'; import { useExportTool } from '@shinkai_network/shinkai-node-state/v2/mutations/exportTool/useExportTool'; -import { useRemoveTool } from '@shinkai_network/shinkai-node-state/v2/mutations/removeTool/useRemoveTool'; import { useUpdateTool } from '@shinkai_network/shinkai-node-state/v2/mutations/updateTool/useUpdateTool'; import { Button, @@ -22,12 +21,13 @@ import * as fs from '@tauri-apps/plugin-fs'; import { BaseDirectory } from '@tauri-apps/plugin-fs'; import { DownloadIcon } from 'lucide-react'; import { useForm } from 'react-hook-form'; -import { Link, useNavigate, useParams } from 'react-router-dom'; +import { Link, useParams } from 'react-router-dom'; import { toast } from 'sonner'; import { z } from 'zod'; import { SubpageLayout } from '../../pages/layout/simple-layout'; import { useAuth } from '../../store/auth'; +import RemoveToolButton from '../playground-tool/components/remove-tool-button'; const jsToolSchema = z.object({ config: z.array( z.object({ @@ -50,7 +50,6 @@ export default function PythonTool({ }) { const auth = useAuth((state) => state.auth); const { toolKey } = useParams(); - const navigate = useNavigate(); const { t } = useTranslation(); const { mutateAsync: updateTool, isPending } = useUpdateTool({ @@ -69,19 +68,6 @@ export default function PythonTool({ }, }); - const { mutateAsync: removeTool, isPending: isRemoveToolPending } = - useRemoveTool({ - onSuccess: () => { - toast.success('Tool has been removed successfully'); - navigate('/tools'); - }, - onError: (error) => { - toast.error('Failed to remove tool', { - description: error.response?.data?.message ?? error.message, - }); - }, - }); - const { mutateAsync: exportTool, isPending: isExportingTool } = useExportTool( { onSuccess: async (response, variables) => { @@ -256,8 +242,8 @@ export default function PythonTool({ )} - {isPlaygroundTool && ( -
+
+ {isPlaygroundTool && ( Go Playground - -
- )} + )} + +
); diff --git a/apps/shinkai-desktop/src/components/tools/rust-tool.tsx b/apps/shinkai-desktop/src/components/tools/rust-tool.tsx index fbf0a875f..d7c8f78c7 100644 --- a/apps/shinkai-desktop/src/components/tools/rust-tool.tsx +++ b/apps/shinkai-desktop/src/components/tools/rust-tool.tsx @@ -22,6 +22,7 @@ import { toast } from 'sonner'; // import { z } from 'zod'; import { SubpageLayout } from '../../pages/layout/simple-layout'; import { useAuth } from '../../store/auth'; +import RemoveToolButton from '../playground-tool/components/remove-tool-button'; // const jsToolSchema = z.object({ // config: z.array( @@ -188,6 +189,9 @@ export default function RustTool({ {/* Go Playground*/} {/* */} {/*)}*/} +
+ +
); From 3032ed9b9bef44e1cd600d0c7fc2d9586664111d Mon Sep 17 00:00:00 2001 From: paulclindo Date: Mon, 16 Dec 2024 18:41:31 -0500 Subject: [PATCH 4/6] fix: add toolkey when sending message --- apps/shinkai-desktop/src/components/chat/conversation-footer.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/shinkai-desktop/src/components/chat/conversation-footer.tsx b/apps/shinkai-desktop/src/components/chat/conversation-footer.tsx index 5f3581c4c..d20179e9f 100644 --- a/apps/shinkai-desktop/src/components/chat/conversation-footer.tsx +++ b/apps/shinkai-desktop/src/components/chat/conversation-footer.tsx @@ -640,6 +640,7 @@ function ConversationChatFooter({ inboxId }: { inboxId: string }) { message: data.message, parent: '', // Note: we should set the parent if we want to retry or branch out files: currentFiles, + toolKey: selectedTool?.key, }); } else { const sender = `${auth.shinkai_identity}/${auth.profile}/device/${auth.registration_name}`; From fd3d90f081967367bb9e9ef4dbc914bf483bca30 Mon Sep 17 00:00:00 2001 From: paulclindo Date: Mon, 16 Dec 2024 19:57:32 -0500 Subject: [PATCH 5/6] feat: add tool description + inputs --- .../components/chat/components/message.tsx | 4 ++- .../components/chat/conversation-footer.tsx | 36 ++++++++++++++----- .../src/forms/chat/chat-message.ts | 1 + .../src/forms/chat/create-job.ts | 1 + .../v2/queries/getChatConversation/index.ts | 2 ++ .../src/components/chat/message.tsx | 4 ++- 6 files changed, 38 insertions(+), 10 deletions(-) diff --git a/apps/shinkai-desktop/src/components/chat/components/message.tsx b/apps/shinkai-desktop/src/components/chat/components/message.tsx index 8916ef681..edaa8f007 100644 --- a/apps/shinkai-desktop/src/components/chat/components/message.tsx +++ b/apps/shinkai-desktop/src/components/chat/components/message.tsx @@ -310,7 +310,9 @@ export const MessageBase = ({ svg]:hidden [&[data-state=open]]:bg-gray-500', + 'transition-colors hover:bg-gray-500 [&[data-state=open]]:bg-gray-500', + tool.status !== ToolStatusType.Complete && + '[&>svg]:hidden', )} > } {selectedTool && ( { @@ -475,6 +475,9 @@ function ConversationEmptyFooter() { key: tool.tool_router_key, name: tool.name, description: tool.description, + args: Object.keys( + tool.input_args.properties ?? {}, + ), }); }} type="button" @@ -513,7 +516,6 @@ function ConversationEmptyFooter() { ); } - function ConversationChatFooter({ inboxId }: { inboxId: string }) { const { t } = useTranslation(); @@ -755,6 +757,7 @@ function ConversationChatFooter({ inboxId }: { inboxId: string }) { {isDragActive && } {selectedTool && ( { @@ -808,6 +811,9 @@ function ConversationChatFooter({ inboxId }: { inboxId: string }) { key: tool.tool_router_key, name: tool.name, description: tool.description, + args: Object.keys( + tool.input_args.properties ?? {}, + ), }); }} type="button" @@ -964,21 +970,35 @@ const DropFileActive = () => ( const SelectedToolChat = ({ name, description, + args, remove, }: { name: string; description: string; + args: string[]; remove: () => void; }) => { return (
-
- -
- {name} - +
+ +
+ + {name} -{' '} + {description} + + {args.length > 0 && ( + +
+ Inputs: +
+ {args.join(', ')} +
+
+
+ )}
@@ -990,7 +1010,7 @@ const SelectedToolChat = ({ side="top" sideOffset={10} > - {description} + wellelele diff --git a/libs/shinkai-node-state/src/forms/chat/chat-message.ts b/libs/shinkai-node-state/src/forms/chat/chat-message.ts index 51052e669..8f9adaf8f 100644 --- a/libs/shinkai-node-state/src/forms/chat/chat-message.ts +++ b/libs/shinkai-node-state/src/forms/chat/chat-message.ts @@ -8,6 +8,7 @@ export const chatMessageFormSchema = z.object({ key: z.string().min(1), name: z.string().min(1), description: z.string().min(1), + args: z.array(z.string()).optional(), }) .optional(), }); diff --git a/libs/shinkai-node-state/src/forms/chat/create-job.ts b/libs/shinkai-node-state/src/forms/chat/create-job.ts index f24f8a321..3da279946 100644 --- a/libs/shinkai-node-state/src/forms/chat/create-job.ts +++ b/libs/shinkai-node-state/src/forms/chat/create-job.ts @@ -9,6 +9,7 @@ export const createJobFormSchema = z.object({ key: z.string().min(1), name: z.string().min(1), description: z.string().min(1), + args: z.array(z.string()).optional(), }) .optional(), }); diff --git a/libs/shinkai-node-state/src/v2/queries/getChatConversation/index.ts b/libs/shinkai-node-state/src/v2/queries/getChatConversation/index.ts index 78fb56411..a9cea84ff 100644 --- a/libs/shinkai-node-state/src/v2/queries/getChatConversation/index.ts +++ b/libs/shinkai-node-state/src/v2/queries/getChatConversation/index.ts @@ -1,3 +1,4 @@ +import { ToolStatusType } from '@shinkai_network/shinkai-message-ts/api/general/types'; import { downloadFileFromInbox, getFileNames, @@ -84,6 +85,7 @@ const createAssistantMessage = (message: ChatMessage): AssistantMessage => { toolRouterKey: tool.tool_router_key, name: tool.name, args: tool.arguments, + status: ToolStatusType.Complete, }), ); diff --git a/libs/shinkai-ui/src/components/chat/message.tsx b/libs/shinkai-ui/src/components/chat/message.tsx index 04896245c..74caed636 100644 --- a/libs/shinkai-ui/src/components/chat/message.tsx +++ b/libs/shinkai-ui/src/components/chat/message.tsx @@ -316,7 +316,9 @@ const MessageBase = ({ svg]:hidden [&[data-state=open]]:bg-gray-500', + 'transition-colors hover:bg-gray-500 [&[data-state=open]]:bg-gray-500', + tool.status !== ToolStatusType.Complete && + '[&>svg]:hidden', )} > Date: Mon, 16 Dec 2024 20:19:20 -0500 Subject: [PATCH 6/6] feat: add tool results info --- .../src/components/chat/components/message.tsx | 12 ++++++++++-- libs/shinkai-message-ts/src/api/jobs/types.ts | 1 + .../src/v2/queries/getChatConversation/index.ts | 1 + .../src/v2/queries/getChatConversation/types.ts | 2 +- libs/shinkai-ui/src/components/chat/message.tsx | 12 ++++++++++-- 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/apps/shinkai-desktop/src/components/chat/components/message.tsx b/apps/shinkai-desktop/src/components/chat/components/message.tsx index edaa8f007..35faf6213 100644 --- a/apps/shinkai-desktop/src/components/chat/components/message.tsx +++ b/apps/shinkai-desktop/src/components/chat/components/message.tsx @@ -322,18 +322,26 @@ export const MessageBase = ({ toolRouterKey={tool.toolRouterKey} /> - + {Object.keys(tool.args).length > 0 && ( {tool.name}( {Object.keys(tool.args).length > 0 && ( - + {JSON.stringify(tool.args)} )} ) )} + {tool.result && ( +
+ Response: + + {JSON.stringify(tool.result, null, 2)} + +
+ )}
); diff --git a/libs/shinkai-message-ts/src/api/jobs/types.ts b/libs/shinkai-message-ts/src/api/jobs/types.ts index 8ba083970..fedf749e8 100644 --- a/libs/shinkai-message-ts/src/api/jobs/types.ts +++ b/libs/shinkai-message-ts/src/api/jobs/types.ts @@ -141,6 +141,7 @@ export type JobMessage = { message: string; }; tool_router_key: string; + response?: string; }[]; }; }; diff --git a/libs/shinkai-node-state/src/v2/queries/getChatConversation/index.ts b/libs/shinkai-node-state/src/v2/queries/getChatConversation/index.ts index a9cea84ff..957695737 100644 --- a/libs/shinkai-node-state/src/v2/queries/getChatConversation/index.ts +++ b/libs/shinkai-node-state/src/v2/queries/getChatConversation/index.ts @@ -86,6 +86,7 @@ const createAssistantMessage = (message: ChatMessage): AssistantMessage => { name: tool.name, args: tool.arguments, status: ToolStatusType.Complete, + result: tool?.response ?? '', }), ); diff --git a/libs/shinkai-node-state/src/v2/queries/getChatConversation/types.ts b/libs/shinkai-node-state/src/v2/queries/getChatConversation/types.ts index f9c13a66f..37eabfd28 100644 --- a/libs/shinkai-node-state/src/v2/queries/getChatConversation/types.ts +++ b/libs/shinkai-node-state/src/v2/queries/getChatConversation/types.ts @@ -29,7 +29,7 @@ type ToolCall = { toolRouterKey: string; name: string; args: ToolArgs; - result?: unknown; + result?: string; status?: ToolStatusType; // TODO: remove isError?: boolean; }; diff --git a/libs/shinkai-ui/src/components/chat/message.tsx b/libs/shinkai-ui/src/components/chat/message.tsx index 74caed636..3ead83982 100644 --- a/libs/shinkai-ui/src/components/chat/message.tsx +++ b/libs/shinkai-ui/src/components/chat/message.tsx @@ -328,18 +328,26 @@ const MessageBase = ({ toolRouterKey={tool.toolRouterKey} /> - + {Object.keys(tool.args).length > 0 && ( {tool.name}( {Object.keys(tool.args).length > 0 && ( - + {JSON.stringify(tool.args)} )} ) )} + {tool.result && ( +
+ Response: + + {JSON.stringify(tool.result, null, 2)} + +
+ )}
);