diff --git a/apps/shinkai-desktop/src/components/chat/conversation-header.tsx b/apps/shinkai-desktop/src/components/chat/conversation-header.tsx index 0c1ecf759..e5983f320 100644 --- a/apps/shinkai-desktop/src/components/chat/conversation-header.tsx +++ b/apps/shinkai-desktop/src/components/chat/conversation-header.tsx @@ -1,6 +1,8 @@ import { PlusIcon } from '@radix-ui/react-icons'; import { useTranslation } from '@shinkai_network/shinkai-i18n'; import { extractJobIdFromInbox } from '@shinkai_network/shinkai-message-ts/utils'; +import { useGetListDirectoryContents } from '@shinkai_network/shinkai-node-state/v2/queries/getDirectoryContents/useGetListDirectoryContents'; +import { useGetJobFolderName } from '@shinkai_network/shinkai-node-state/v2/queries/getJobFolderName/useGetJobFolderName'; import { useGetJobScope } from '@shinkai_network/shinkai-node-state/v2/queries/getJobScope/useGetJobScope'; import { Badge, @@ -138,11 +140,33 @@ const ConversationHeaderWithInboxId = () => { { enabled: !!inboxId }, ); + const { data: jobFolderData } = useGetJobFolderName({ + jobId: extractJobIdFromInbox(inboxId), + nodeAddress: auth?.node_address ?? '', + token: auth?.api_v2_key ?? '', + }); + + const { data: fileInfoArray, isSuccess: isVRFilesSuccess } = + useGetListDirectoryContents( + { + nodeAddress: auth?.node_address ?? '', + token: auth?.api_v2_key ?? '', + path: decodeURIComponent(jobFolderData?.folder_name ?? '') ?? '', + }, + { + enabled: !!jobFolderData?.folder_name, + }, + ); + + const hasFilesJobFolder = isVRFilesSuccess && fileInfoArray.length > 0; + const hasFolders = isSuccess && jobScope.vector_fs_folders.length > 0; const hasFiles = isSuccess && jobScope.vector_fs_items.length > 0; const filesAndFoldersCount = isSuccess - ? jobScope.vector_fs_folders.length + jobScope.vector_fs_items.length + ? jobScope.vector_fs_folders.length + + jobScope.vector_fs_items.length + + (hasFilesJobFolder ? 1 : 0) : 0; const hasConversationContext = hasFolders || hasFiles; @@ -150,7 +174,8 @@ const ConversationHeaderWithInboxId = () => { if ( isSuccess && inboxId && - (jobScope.vector_fs_folders?.length > 0 || + (hasFilesJobFolder || + jobScope.vector_fs_folders?.length > 0 || jobScope.vector_fs_items?.length > 0) ) { const selectedVRFilesPathMap = jobScope.vector_fs_items.reduce( @@ -177,10 +202,17 @@ const ConversationHeaderWithInboxId = () => { onSelectedKeysChange({ ...selectedVRFilesPathMap, + ...(jobFolderData?.folder_name && { + [jobFolderData.folder_name]: { + checked: true, + }, + }), ...selectedVRFoldersPathMap, }); } }, [ + hasFilesJobFolder, + jobFolderData?.folder_name, jobScope?.vector_fs_folders, jobScope?.vector_fs_items, isSuccess, diff --git a/apps/shinkai-desktop/src/components/chat/set-conversation-context.tsx b/apps/shinkai-desktop/src/components/chat/set-conversation-context.tsx index 6a17e6367..c7633fd47 100644 --- a/apps/shinkai-desktop/src/components/chat/set-conversation-context.tsx +++ b/apps/shinkai-desktop/src/components/chat/set-conversation-context.tsx @@ -10,6 +10,7 @@ import { useGetVRSeachSimplified } from '@shinkai_network/shinkai-node-state/lib import { transformDataToTreeNodes } from '@shinkai_network/shinkai-node-state/lib/utils/files'; import { useUpdateJobScope } from '@shinkai_network/shinkai-node-state/v2/mutations/updateJobScope/useUpdateJobScope'; import { useGetListDirectoryContents } from '@shinkai_network/shinkai-node-state/v2/queries/getDirectoryContents/useGetListDirectoryContents'; +import { useGetJobFolderName } from '@shinkai_network/shinkai-node-state/v2/queries/getJobFolderName/useGetJobFolderName'; import { Badge, Button, @@ -65,6 +66,7 @@ export const SetJobScopeDrawer = () => { nodeAddress: auth?.node_address ?? '', token: auth?.api_v2_key ?? '', path: '/', + depth: 6, }); const { mutateAsync: updateJobScope, isPending: isUpdatingJobScope } = @@ -79,11 +81,21 @@ export const SetJobScopeDrawer = () => { }, }); + const { data: jobFolderData } = useGetJobFolderName({ + jobId: inboxId ? extractJobIdFromInbox(inboxId) : '', + nodeAddress: auth?.node_address ?? '', + token: auth?.api_v2_key ?? '', + }); + + const selectedPaths = jobFolderData ? [jobFolderData.folder_name] : []; + useEffect(() => { if (isVRFilesSuccess) { - setNodes(transformDataToTreeNodes(fileInfoArray)); + setNodes( + transformDataToTreeNodes(fileInfoArray, undefined, selectedPaths), + ); } - }, [fileInfoArray, isVRFilesSuccess]); + }, [fileInfoArray, isVRFilesSuccess, jobFolderData]); useEffect(() => { if (!isSetJobScopeOpen) { @@ -94,6 +106,7 @@ export const SetJobScopeDrawer = () => { } }, [isSetJobScopeOpen]); + console.log(selectedKeys, 'selectedKeys'); return ( @@ -174,7 +187,7 @@ export const SetJobScopeDrawer = () => { size="sm" type="button" > - {t('common.done')} + {inboxId ? t('common.saveChanges') : t('common.done')} 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 index 7d57a2bc4..426542e6a 100644 --- 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 @@ -24,6 +24,7 @@ export default function RemoveToolButton({ toolKey }: { toolKey: string }) { return ( +
+
+

Enabled

+ { + await updateTool({ + toolKey: toolKey ?? '', + toolType: toolType, + toolPayload: {} as ShinkaiTool, + isToolEnabled: !isEnabled, + nodeAddress: auth?.node_address ?? '', + token: auth?.api_v2_key ?? '', + }); + }} + /> +
+ {[ + { + label: 'Description', + value: tool.description, + }, + 'author' in tool && + tool.author && { + label: 'Author', + value: tool.author, + }, + 'keywords' in tool && + tool.keywords.length > 0 && { + label: 'Keyword', + value: tool.keywords.join(', '), + }, + ] + .filter((item) => !!item) + .map(({ label, value }) => ( +
+ {label} + {value} +
+ ))} + + {'config' in tool && tool.config.length > 0 && ( +
+
+

Configuration

+

+ Configure the settings for this tool +

+
+ + setFormData(e.formData)} + onSubmit={handleSaveToolConfig} + schema={toolConfigSchema} + uiSchema={{ 'ui:submitButtonOptions': { norender: true } }} + validator={validator} + /> +
+ +
+
+ )} + +
+ {isPlaygroundTool && ( + + Go Playground + + )} + +
+
+ + ); +} diff --git a/apps/shinkai-desktop/src/components/tools/deno-tool.tsx b/apps/shinkai-desktop/src/components/tools/deno-tool.tsx index 0d791f3b8..6673bfbc8 100644 --- a/apps/shinkai-desktop/src/components/tools/deno-tool.tsx +++ b/apps/shinkai-desktop/src/components/tools/deno-tool.tsx @@ -1,46 +1,6 @@ -import { zodResolver } from '@hookform/resolvers/zod'; -import { useTranslation } from '@shinkai_network/shinkai-i18n'; -import { - DenoShinkaiTool, - ShinkaiTool, -} from '@shinkai_network/shinkai-message-ts/api/tools/types'; -import { useExportTool } from '@shinkai_network/shinkai-node-state/v2/mutations/exportTool/useExportTool'; -import { useUpdateTool } from '@shinkai_network/shinkai-node-state/v2/mutations/updateTool/useUpdateTool'; -import { - Button, - buttonVariants, - Form, - FormField, - Switch, - TextField, -} from '@shinkai_network/shinkai-ui'; -import { - formatCamelCaseText, - formatText, -} from '@shinkai_network/shinkai-ui/helpers'; -import { cn } from '@shinkai_network/shinkai-ui/utils'; -import { save } from '@tauri-apps/plugin-dialog'; -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 { toast } from 'sonner'; -import { z } from 'zod'; +import { DenoShinkaiTool } from '@shinkai_network/shinkai-message-ts/api/tools/types'; -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({ - key_name: z.string(), - key_value: z.string().optional(), - required: z.boolean(), - }), - ), -}); -type JsToolFormSchema = z.infer; +import ToolCard from './components/tool-card'; export default function DenoTool({ tool, @@ -51,217 +11,12 @@ export default function DenoTool({ isEnabled: boolean; isPlaygroundTool?: boolean; }) { - const auth = useAuth((state) => state.auth); - const { toolKey } = useParams(); - - const { t } = useTranslation(); - const { mutateAsync: updateTool, isPending } = useUpdateTool({ - onSuccess: (_, variables) => { - if ( - 'config' in variables.toolPayload && - variables.toolPayload.config?.length > 0 - ) { - toast.success('Tool configuration updated successfully'); - } - }, - onError: (error) => { - toast.error('Failed to update tool', { - description: error.response?.data?.message ?? error.message, - }); - }, - }); - - const { mutateAsync: exportTool, isPending: isExportingTool } = useExportTool( - { - onSuccess: async (response, variables) => { - const toolName = variables.toolKey.split(':::')?.[1] ?? 'untitled_tool'; - const file = new Blob([response ?? ''], { - type: 'application/octet-stream', - }); - - const arrayBuffer = await file.arrayBuffer(); - const content = new Uint8Array(arrayBuffer); - - const savePath = await save({ - defaultPath: `${toolName}.zip`, - filters: [ - { - name: 'Zip File', - extensions: ['zip'], - }, - ], - }); - - if (!savePath) { - toast.info('File saving cancelled'); - return; - } - - await fs.writeFile(savePath, content, { - baseDir: BaseDirectory.Download, - }); - - toast.success('Tool exported successfully'); - }, - onError: (error) => { - toast.error('Failed to export tool', { - description: error.response?.data?.message ?? error.message, - }); - }, - }, - ); - - const form = useForm({ - resolver: zodResolver(jsToolSchema), - defaultValues: { - config: tool.config.map((conf) => ({ - key_name: conf.BasicConfig.key_name, - key_value: conf.BasicConfig.key_value ?? '', - required: conf.BasicConfig.required, - })), - }, - }); - - const onSubmit = async (data: JsToolFormSchema) => { - let enabled = isEnabled; - - if ( - data.config.every( - (conf) => !conf.required || (conf.required && conf.key_value !== ''), - ) - ) { - enabled = true; - } - - await updateTool({ - toolKey: toolKey ?? '', - toolType: 'Deno', - toolPayload: { - config: data.config.map((conf) => ({ - BasicConfig: { - key_name: conf.key_name, - key_value: conf.key_value, - }, - })), - } as ShinkaiTool, - isToolEnabled: enabled, - nodeAddress: auth?.node_address ?? '', - token: auth?.api_v2_key ?? '', - }); - }; - return ( - - -
-
-

Enabled

- { - await updateTool({ - toolKey: toolKey ?? '', - toolType: 'Deno', - toolPayload: {} as ShinkaiTool, - isToolEnabled: !isEnabled, - nodeAddress: auth?.node_address ?? '', - token: auth?.api_v2_key ?? '', - }); - }} - /> -
- {[ - { - label: 'Description', - value: tool.description, - }, - tool.author && { - label: 'Author', - value: tool.author, - }, - tool.keywords.length > 0 && { - label: 'Keyword', - value: tool.keywords.join(', '), - }, - ] - .filter((item) => !!item) - .map(({ label, value }) => ( -
- {label} - {value} -
- ))} - - {tool.config.length > 0 && ( -
-
Tool Configuration
- -
- -
- {tool.config.map((conf, index) => ( - ( - - )} - /> - ))} -
- -
- -
- )} -
- {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 752eb8f2d..f99136942 100644 --- a/apps/shinkai-desktop/src/components/tools/network-tool.tsx +++ b/apps/shinkai-desktop/src/components/tools/network-tool.tsx @@ -1,45 +1,6 @@ -// import { zodResolver } from '@hookform/resolvers/zod'; -// import { useTranslation } from '@shinkai_network/shinkai-i18n'; -import { - NetworkShinkaiTool, - ShinkaiTool, -} from '@shinkai_network/shinkai-message-ts/api/tools/types'; -import { useExportTool } from '@shinkai_network/shinkai-node-state/v2/mutations/exportTool/useExportTool'; -import { useUpdateTool } from '@shinkai_network/shinkai-node-state/v2/mutations/updateTool/useUpdateTool'; -import { - Button, - // Button, - // buttonVariants, - // Form, - // FormField, - Switch, - // TextField, -} from '@shinkai_network/shinkai-ui'; -import { formatText } from '@shinkai_network/shinkai-ui/helpers'; -import { save } from '@tauri-apps/plugin-dialog'; -import * as fs from '@tauri-apps/plugin-fs'; -import { BaseDirectory } from '@tauri-apps/plugin-fs'; -import { DownloadIcon } from 'lucide-react'; -// import { cn } from '@shinkai_network/shinkai-ui/utils'; -// import { useForm } from 'react-hook-form'; -import { useParams } from 'react-router-dom'; -import { toast } from 'sonner'; +import { NetworkShinkaiTool } from '@shinkai_network/shinkai-message-ts/api/tools/types'; -// 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({ -// key_name: z.string(), -// key_value: z.string().optional(), -// required: z.boolean(), -// }), -// ), -// }); -// type JsToolFormSchema = z.infer; +import ToolCard from './components/tool-card'; export default function NetworkTool({ tool, @@ -48,210 +9,5 @@ export default function NetworkTool({ tool: NetworkShinkaiTool; isEnabled: boolean; }) { - const auth = useAuth((state) => state.auth); - const { toolKey } = useParams(); - - const { mutateAsync: updateTool } = useUpdateTool({ - onSuccess: (_, variables) => { - if ( - 'config' in variables.toolPayload && - variables.toolPayload.config?.length > 0 - ) { - toast.success('Tool configuration updated successfully'); - } - }, - }); - const { mutateAsync: exportTool, isPending: isExportingTool } = useExportTool( - { - onSuccess: async (response, variables) => { - const toolName = variables.toolKey.split(':::')?.[1] ?? 'untitled_tool'; - const file = new Blob([response ?? ''], { - type: 'application/octet-stream', - }); - - const arrayBuffer = await file.arrayBuffer(); - const content = new Uint8Array(arrayBuffer); - - const savePath = await save({ - defaultPath: `${toolName}.zip`, - filters: [ - { - name: 'Zip File', - extensions: ['zip'], - }, - ], - }); - - if (!savePath) { - toast.info('File saving cancelled'); - return; - } - - await fs.writeFile(savePath, content, { - baseDir: BaseDirectory.Download, - }); - - toast.success('Tool exported successfully'); - }, - onError: (error) => { - toast.error('Failed to export tool', { - description: error.response?.data?.message ?? error.message, - }); - }, - }, - ); - - // const form = useForm({ - // resolver: zodResolver(jsToolSchema), - // defaultValues: { - // // config: tool.config.map((conf) => ({ - // // key_name: conf.BasicConfig.key_name, - // // key_value: conf.BasicConfig.key_value ?? '', - // // required: conf.BasicConfig.required, - // // })), - // }, - // }); - - // const onSubmit = async (data: JsToolFormSchema) => { - // let enabled = isEnabled; - // - // if ( - // data.config.every( - // (conf) => !conf.required || (conf.required && conf.key_value !== ''), - // ) - // ) { - // enabled = true; - // } - // - // await updateTool({ - // toolKey: toolKey ?? '', - // toolType: 'Network', - // toolPayload: { - // config: data.config.map((conf) => ({ - // BasicConfig: { - // key_name: conf.key_name, - // key_value: conf.key_value, - // }, - // })), - // } as ShinkaiTool, - // isToolEnabled: enabled, - // nodeAddress: auth?.node_address ?? '', - // token: auth?.api_v2_key ?? '', - // }); - // }; - - return ( - - -
-
-

Enabled

- { - await updateTool({ - toolKey: toolKey ?? '', - toolType: 'Network', - toolPayload: {} as ShinkaiTool, - isToolEnabled: !isEnabled, - nodeAddress: auth?.node_address ?? '', - token: auth?.api_v2_key ?? '', - }); - }} - /> -
- {/*{[*/} - {/* {*/} - {/* label: 'Description',*/} - {/* value: tool.description,*/} - {/* },*/} - {/* tool.author && {*/} - {/* label: 'Author',*/} - {/* value: tool.author,*/} - {/* },*/} - {/* tool.keywords.length > 0 && {*/} - {/* label: 'Keyword',*/} - {/* value: tool.keywords,*/} - {/* },*/} - {/*]*/} - {/* .filter((item) => !!item)*/} - {/* .map(({ label, value }) => (*/} - {/*
*/} - {/* {label}*/} - {/* {value}*/} - {/*
*/} - {/* ))}*/} - - {/*{tool.config.length > 0 && (*/} - {/*
*/} - {/*
Tool Configuration
*/} - - {/*
*/} - {/* */} - {/*
*/} - {/* {tool.config.map((conf, index) => (*/} - {/* (*/} - {/* */} - {/* )}*/} - {/* />*/} - {/* ))}*/} - {/*
*/} - {/* */} - {/* {t('common.save')}*/} - {/* */} - {/* */} - {/* */} - {/*
*/} - {/*)}*/} - {/*{isPlaygroundTool && (*/} - {/* */} - {/* Go Playground*/} - {/* */} - {/*)}*/} -
- -
-
-
- ); + return ; } diff --git a/apps/shinkai-desktop/src/components/tools/python-tool.tsx b/apps/shinkai-desktop/src/components/tools/python-tool.tsx index cbd1357ec..596e3ccfb 100644 --- a/apps/shinkai-desktop/src/components/tools/python-tool.tsx +++ b/apps/shinkai-desktop/src/components/tools/python-tool.tsx @@ -1,46 +1,6 @@ -import { zodResolver } from '@hookform/resolvers/zod'; -import { useTranslation } from '@shinkai_network/shinkai-i18n'; -import { - PythonShinkaiTool, - ShinkaiTool, -} from '@shinkai_network/shinkai-message-ts/api/tools/types'; -import { useExportTool } from '@shinkai_network/shinkai-node-state/v2/mutations/exportTool/useExportTool'; -import { useUpdateTool } from '@shinkai_network/shinkai-node-state/v2/mutations/updateTool/useUpdateTool'; -import { - Button, - buttonVariants, - Form, - FormField, - Switch, - TextField, -} from '@shinkai_network/shinkai-ui'; -import { - formatCamelCaseText, - formatText, -} from '@shinkai_network/shinkai-ui/helpers'; -import { cn } from '@shinkai_network/shinkai-ui/utils'; -import { save } from '@tauri-apps/plugin-dialog'; -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 { toast } from 'sonner'; -import { z } from 'zod'; +import { PythonShinkaiTool } from '@shinkai_network/shinkai-message-ts/api/tools/types'; -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({ - key_name: z.string(), - key_value: z.string().optional(), - required: z.boolean(), - }), - ), -}); -type JsToolFormSchema = z.infer; +import ToolCard from './components/tool-card'; export default function PythonTool({ tool, @@ -51,217 +11,12 @@ export default function PythonTool({ isEnabled: boolean; isPlaygroundTool?: boolean; }) { - const auth = useAuth((state) => state.auth); - const { toolKey } = useParams(); - - const { t } = useTranslation(); - const { mutateAsync: updateTool, isPending } = useUpdateTool({ - onSuccess: (_, variables) => { - if ( - 'config' in variables.toolPayload && - variables.toolPayload.config?.length > 0 - ) { - toast.success('Tool configuration updated successfully'); - } - }, - onError: (error) => { - toast.error('Failed to update tool', { - description: error.response?.data?.message ?? error.message, - }); - }, - }); - - const { mutateAsync: exportTool, isPending: isExportingTool } = useExportTool( - { - onSuccess: async (response, variables) => { - const toolName = variables.toolKey.split(':::')?.[1] ?? 'untitled_tool'; - const file = new Blob([response ?? ''], { - type: 'application/octet-stream', - }); - - const arrayBuffer = await file.arrayBuffer(); - const content = new Uint8Array(arrayBuffer); - - const savePath = await save({ - defaultPath: `${toolName}.zip`, - filters: [ - { - name: 'Zip File', - extensions: ['zip'], - }, - ], - }); - - if (!savePath) { - toast.info('File saving cancelled'); - return; - } - - await fs.writeFile(savePath, content, { - baseDir: BaseDirectory.Download, - }); - - toast.success('Tool exported successfully'); - }, - onError: (error) => { - toast.error('Failed to export tool', { - description: error.response?.data?.message ?? error.message, - }); - }, - }, - ); - - const form = useForm({ - resolver: zodResolver(jsToolSchema), - defaultValues: { - config: tool.config.map((conf) => ({ - key_name: conf.BasicConfig.key_name, - key_value: conf.BasicConfig.key_value ?? '', - required: conf.BasicConfig.required, - })), - }, - }); - - const onSubmit = async (data: JsToolFormSchema) => { - let enabled = isEnabled; - - if ( - data.config.every( - (conf) => !conf.required || (conf.required && conf.key_value !== ''), - ) - ) { - enabled = true; - } - - await updateTool({ - toolKey: toolKey ?? '', - toolType: 'Python', - toolPayload: { - config: data.config.map((conf) => ({ - BasicConfig: { - key_name: conf.key_name, - key_value: conf.key_value, - }, - })), - } as ShinkaiTool, - isToolEnabled: enabled, - nodeAddress: auth?.node_address ?? '', - token: auth?.api_v2_key ?? '', - }); - }; - return ( - - -
-
-

Enabled

- { - await updateTool({ - toolKey: toolKey ?? '', - toolType: 'Python', - toolPayload: {} as ShinkaiTool, - isToolEnabled: !isEnabled, - nodeAddress: auth?.node_address ?? '', - token: auth?.api_v2_key ?? '', - }); - }} - /> -
- {[ - { - label: 'Description', - value: tool.description, - }, - tool.author && { - label: 'Author', - value: tool.author, - }, - tool.keywords.length > 0 && { - label: 'Keyword', - value: tool.keywords.join(', '), - }, - ] - .filter((item) => !!item) - .map(({ label, value }) => ( -
- {label} - {value} -
- ))} - - {tool.config.length > 0 && ( -
-
Tool Configuration
- -
- -
- {tool.config.map((conf, index) => ( - ( - - )} - /> - ))} -
- -
- -
- )} -
- {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 2115e66d6..4a369d50f 100644 --- a/apps/shinkai-desktop/src/components/tools/rust-tool.tsx +++ b/apps/shinkai-desktop/src/components/tools/rust-tool.tsx @@ -1,198 +1,13 @@ -// import { zodResolver } from '@hookform/resolvers/zod'; -// import { useTranslation } from '@shinkai_network/shinkai-i18n'; -import { - RustShinkaiTool, - ShinkaiTool, -} from '@shinkai_network/shinkai-message-ts/api/tools/types'; -import { useUpdateTool } from '@shinkai_network/shinkai-node-state/v2/mutations/updateTool/useUpdateTool'; -import { - // Button, - // buttonVariants, - // Form, - // FormField, - Switch, - // TextField, -} from '@shinkai_network/shinkai-ui'; -import { formatText } from '@shinkai_network/shinkai-ui/helpers'; -// import { cn } from '@shinkai_network/shinkai-ui/utils'; -// import { useForm } from 'react-hook-form'; -import { useParams } from 'react-router-dom'; -import { toast } from 'sonner'; +import { RustShinkaiTool } from '@shinkai_network/shinkai-message-ts/api/tools/types'; -// 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({ -// key_name: z.string(), -// key_value: z.string().optional(), -// required: z.boolean(), -// }), -// ), -// }); -// type JsToolFormSchema = z.infer; +import ToolCard from './components/tool-card'; export default function RustTool({ tool, isEnabled, - // isPlaygroundTool, }: { tool: RustShinkaiTool; isEnabled: boolean; - // isPlaygroundTool?: boolean; }) { - const auth = useAuth((state) => state.auth); - - // const { t } = useTranslation(); - const { mutateAsync: updateTool } = useUpdateTool({ - onSuccess: (_, variables) => { - if ( - 'config' in variables.toolPayload && - variables.toolPayload.config?.length > 0 - ) { - toast.success('Tool configuration updated successfully'); - } - }, - }); - const { toolKey } = useParams(); - - // const form = useForm({ - // resolver: zodResolver(jsToolSchema), - // defaultValues: { - // // config: tool.config.map((conf) => ({ - // // key_name: conf.BasicConfig.key_name, - // // key_value: conf.BasicConfig.key_value ?? '', - // // required: conf.BasicConfig.required, - // // })), - // }, - // }); - // - // const onSubmit = async (data: JsToolFormSchema) => { - // let enabled = isEnabled; - // - // if ( - // data.config.every( - // (conf) => !conf.required || (conf.required && conf.key_value !== ''), - // ) - // ) { - // enabled = true; - // } - // - // await updateTool({ - // toolKey: toolKey ?? '', - // toolType: 'Rust', - // toolPayload: { - // config: data.config.map((conf) => ({ - // BasicConfig: { - // key_name: conf.key_name, - // key_value: conf.key_value, - // }, - // })), - // } as ShinkaiTool, - // isToolEnabled: enabled, - // nodeAddress: auth?.node_address ?? '', - // token: auth?.api_v2_key ?? '', - // }); - // }; - - return ( - -
-
-

Enabled

- { - await updateTool({ - toolKey: toolKey ?? '', - toolType: 'Rust', - toolPayload: {} as ShinkaiTool, - isToolEnabled: !isEnabled, - nodeAddress: auth?.node_address ?? '', - token: auth?.api_v2_key ?? '', - }); - }} - /> -
- {[ - { - label: 'Description', - value: tool.description, - }, - // tool.author && { - // label: 'Author', - // value: tool.author, - // }, - // tool.keywords.length > 0 && { - // label: 'Keyword', - // value: tool.keywords, - // }, - ] - .filter((item) => !!item) - .map(({ label, value }) => ( -
- {label} - {value} -
- ))} - - {/*{tool.config.length > 0 && (*/} - {/*
*/} - {/*
Tool Configuration
*/} - - {/*
*/} - {/* */} - {/*
*/} - {/* {tool.config.map((conf, index) => (*/} - {/* (*/} - {/* */} - {/* )}*/} - {/* />*/} - {/* ))}*/} - {/*
*/} - {/* */} - {/* {t('common.save')}*/} - {/* */} - {/* */} - {/* */} - {/*
*/} - {/*)}*/} - {/*{isPlaygroundTool && (*/} - {/* */} - {/* Go Playground*/} - {/* */} - {/*)}*/} -
- -
-
-
- ); + return ; } diff --git a/apps/shinkai-desktop/src/components/tools/tool-details.tsx b/apps/shinkai-desktop/src/components/tools/tool-details.tsx index 3d9d489be..b93ccc755 100644 --- a/apps/shinkai-desktop/src/components/tools/tool-details.tsx +++ b/apps/shinkai-desktop/src/components/tools/tool-details.tsx @@ -21,6 +21,12 @@ export function isDenoShinkaiTool(tool: ShinkaiTool): tool is DenoShinkaiTool { return (tool as DenoShinkaiTool).js_code !== undefined; } +export function isPythonShinkaiTool( + tool: ShinkaiTool, +): tool is PythonShinkaiTool { + return (tool as PythonShinkaiTool).py_code !== undefined; +} + export default function ToolDetails() { const auth = useAuth((state) => state.auth); diff --git a/apps/shinkai-desktop/src/components/tools/utils/tool-config.ts b/apps/shinkai-desktop/src/components/tools/utils/tool-config.ts new file mode 100644 index 000000000..646fe21e5 --- /dev/null +++ b/apps/shinkai-desktop/src/components/tools/utils/tool-config.ts @@ -0,0 +1,27 @@ +import { RJSFSchema } from '@rjsf/utils'; +import { ToolConfig } from '@shinkai_network/shinkai-message-ts/api/tools/types'; +import { JSONSchema7TypeName } from 'json-schema'; + +export function parseConfigToJsonSchema(config: ToolConfig[]): RJSFSchema { + const schema: RJSFSchema = { + type: 'object', + required: [], + properties: {}, + }; + + config.forEach((item) => { + const { BasicConfig } = item; + const { key_name, description, required, type } = BasicConfig; + + if (required) { + schema.required?.push(key_name); + } + + schema.properties![key_name] = { + type: (type || 'string') as JSONSchema7TypeName, + description, + }; + }); + + return schema; +} diff --git a/apps/shinkai-desktop/src/components/vector-fs/components/all-files-tab.tsx b/apps/shinkai-desktop/src/components/vector-fs/components/all-files-tab.tsx index 6d023c979..e9e71faef 100644 --- a/apps/shinkai-desktop/src/components/vector-fs/components/all-files-tab.tsx +++ b/apps/shinkai-desktop/src/components/vector-fs/components/all-files-tab.tsx @@ -19,7 +19,7 @@ import { DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, - Input, + // Input, ScrollArea, Separator, Tooltip, @@ -41,12 +41,13 @@ import { ChevronRight, FileType2Icon, PlusIcon, - SearchIcon, + // SearchIcon, XIcon, } from 'lucide-react'; import React, { useEffect } from 'react'; import { useLocation, useNavigate } from 'react-router-dom'; +import config from '../../../config'; import { useDebounce } from '../../../hooks/use-debounce'; import { useURLQueryParams } from '../../../hooks/use-url-query-params'; import { useAuth } from '../../../store/auth'; @@ -122,7 +123,7 @@ const AllFiles = () => { profile_identity_sk: auth?.profile_identity_sk ?? '', }, { - enabled: !!debouncedSearchQuery, + enabled: !!debouncedSearchQuery && config.isDev, }, ); @@ -249,29 +250,29 @@ const AllFiles = () => {
- { - setSearchQuery(e.target.value); - }} - placeholder={t('common.searchPlaceholder')} - value={searchQuery} - /> - - {searchQuery && ( - - )} + {/* {*/} + {/* setSearchQuery(e.target.value);*/} + {/* }}*/} + {/* placeholder={t('common.searchPlaceholder')}*/} + {/* value={searchQuery}*/} + {/*/>*/} + {/**/} + {/*{searchQuery && (*/} + {/* {*/} + {/* setSearchQuery('');*/} + {/* }}*/} + {/* size="auto"*/} + {/* type="button"*/} + {/* variant="ghost"*/} + {/* >*/} + {/* */} + {/* {t('common.clearSearch')}*/} + {/* */} + {/*)}*/}
@@ -413,14 +414,16 @@ const AllFiles = () => { {t('vectorFs.emptyState.noFiles')}
)} - {searchQuery && + {config.isDev && + searchQuery && isSearchVRItemsSuccess && searchVRItems?.length === 0 && (
{t('vectorFs.emptyState.noFiles')}
)} - {searchQuery && + {config.isDev && + searchQuery && isSearchVRItemsSuccess && searchQuery === debouncedSearchQuery && searchVRItems?.map((item) => { diff --git a/apps/shinkai-desktop/src/globals.css b/apps/shinkai-desktop/src/globals.css index e0f3efa25..022b1cd24 100644 --- a/apps/shinkai-desktop/src/globals.css +++ b/apps/shinkai-desktop/src/globals.css @@ -30,3 +30,13 @@ html { scrollbar-width: none; -ms-overflow-style: none; } + +.p-node-disabled { + pointer-events: none; + & .p-checkbox-box { + @apply !bg-gray-100; + } + & .p-icon.p-checkbox-icon { + @apply !pointer-events-none ; + } +} diff --git a/apps/shinkai-desktop/src/lib/constants.ts b/apps/shinkai-desktop/src/lib/constants.ts index b803a9e3a..42e0552bf 100644 --- a/apps/shinkai-desktop/src/lib/constants.ts +++ b/apps/shinkai-desktop/src/lib/constants.ts @@ -44,6 +44,7 @@ export const treeOptions: TreePassThroughOptions = { context.isLeaf && 'invisible', ), }), + nodeIcon: { className: 'mr-2 text-gray-50' }, subgroup: { className: cn('m-0 list-none', 'space-y-1 p-0 pl-4'), diff --git a/apps/shinkai-desktop/src/pages/layout/main-layout.tsx b/apps/shinkai-desktop/src/pages/layout/main-layout.tsx index 5ab530eb9..827681b32 100644 --- a/apps/shinkai-desktop/src/pages/layout/main-layout.tsx +++ b/apps/shinkai-desktop/src/pages/layout/main-layout.tsx @@ -352,7 +352,7 @@ export function MainNav() { // href: '/my-subscriptions', // icon: , // }, - { + optInExperimental && { title: 'Shinkai Sheet', href: '/sheets', icon: , diff --git a/apps/shinkai-desktop/src/pages/layout/simple-layout.tsx b/apps/shinkai-desktop/src/pages/layout/simple-layout.tsx index 6b15007a8..6caf0efcd 100644 --- a/apps/shinkai-desktop/src/pages/layout/simple-layout.tsx +++ b/apps/shinkai-desktop/src/pages/layout/simple-layout.tsx @@ -7,32 +7,42 @@ import { Link, To } from 'react-router-dom'; export const SubpageLayout = ({ title, children, + rightElement, className, alignLeft, }: { title: React.ReactNode; children: React.ReactNode; + rightElement?: React.ReactNode; className?: string; alignLeft?: boolean; }) => { const { t } = useTranslation(); return (
- - - {t('common.back')} - -

- {title} -

+
+
+ + + {t('common.back')} + +

+ {title} +

+ {alignLeft ? null :
} +
+ {rightElement} +
{children}
); diff --git a/apps/shinkai-desktop/src/pages/tools.tsx b/apps/shinkai-desktop/src/pages/tools.tsx index 17878676c..005ed2a40 100644 --- a/apps/shinkai-desktop/src/pages/tools.tsx +++ b/apps/shinkai-desktop/src/pages/tools.tsx @@ -22,10 +22,12 @@ import { Tooltip, TooltipContent, TooltipPortal, - TooltipProvider, TooltipTrigger, } from '@shinkai_network/shinkai-ui'; -import { formatText, getVersionFromTool } from '@shinkai_network/shinkai-ui/helpers'; +import { + formatText, + getVersionFromTool, +} from '@shinkai_network/shinkai-ui/helpers'; import { cn } from '@shinkai_network/shinkai-ui/utils'; import { BoltIcon, @@ -176,30 +178,28 @@ export const Tools = () => { {t('common.configure')} - - - - { - await updateTool({ - toolKey: tool.tool_router_key, - toolType: tool.tool_type, - toolPayload: {} as ShinkaiTool, - isToolEnabled: !tool.enabled, - nodeAddress: auth?.node_address ?? '', - token: auth?.api_v2_key ?? '', - }); - }} - /> - - - - {t('common.enabled')} - - - - + + + { + await updateTool({ + toolKey: tool.tool_router_key, + toolType: tool.tool_type, + toolPayload: {} as ShinkaiTool, + isToolEnabled: !tool.enabled, + nodeAddress: auth?.node_address ?? '', + token: auth?.api_v2_key ?? '', + }); + }} + /> + + + + {t('common.enabled')} + + +
))} {searchQuery && @@ -243,30 +243,29 @@ export const Tools = () => { {t('common.configure')} - - - - { - await updateTool({ - toolKey: tool.tool_router_key, - toolType: tool.tool_type, - toolPayload: {} as ShinkaiTool, - isToolEnabled: !tool.enabled, - nodeAddress: auth?.node_address ?? '', - token: auth?.api_v2_key ?? '', - }); - }} - /> - - - - {t('common.enabled')} - - - - + + + + { + await updateTool({ + toolKey: tool.tool_router_key, + toolType: tool.tool_type, + toolPayload: {} as ShinkaiTool, + isToolEnabled: !tool.enabled, + nodeAddress: auth?.node_address ?? '', + token: auth?.api_v2_key ?? '', + }); + }} + /> + + + + {t('common.enabled')} + + +
))} {searchQuery && isSearchQuerySynced && searchToolList?.length === 0 && ( diff --git a/apps/shinkai-desktop/src/routes/index.tsx b/apps/shinkai-desktop/src/routes/index.tsx index 131735204..b37f35959 100644 --- a/apps/shinkai-desktop/src/routes/index.tsx +++ b/apps/shinkai-desktop/src/routes/index.tsx @@ -325,7 +325,11 @@ const AppRoutes = () => { - + + + + + } path={'tools'} diff --git a/libs/shinkai-i18n/locales/en-US.json b/libs/shinkai-i18n/locales/en-US.json index 13294ac72..7009a22c5 100644 --- a/libs/shinkai-i18n/locales/en-US.json +++ b/libs/shinkai-i18n/locales/en-US.json @@ -405,6 +405,7 @@ "fileWithCount_one": "{{count}} File", "fileWithCount_other": "{{count}} Files", "save": "Save", + "saveChanges": "Save Changes", "cancel": "Cancel", "continue": "Continue", "connect": "Connect", diff --git a/libs/shinkai-i18n/locales/es-ES.json b/libs/shinkai-i18n/locales/es-ES.json index 2bccd899f..457716cb7 100644 --- a/libs/shinkai-i18n/locales/es-ES.json +++ b/libs/shinkai-i18n/locales/es-ES.json @@ -1,4 +1,6 @@ { + "": { + }, "aiFilesSearch": { "description": "Busca para encontrar contenido en todos los archivos de tus archivos AI fácilmente", "filesSelected": "Seleccionados {{count}} archivos", @@ -128,6 +130,7 @@ "restore": "Restaurar", "retry": "Reintentar", "save": "Guardar", + "saveChanges": "Guardar cambios", "search": "Buscar", "searchPlaceholder": "Buscar...", "seeOptions": "Ver Opciones", diff --git a/libs/shinkai-i18n/locales/id-ID.json b/libs/shinkai-i18n/locales/id-ID.json index c3d96f2b6..93f94ef06 100644 --- a/libs/shinkai-i18n/locales/id-ID.json +++ b/libs/shinkai-i18n/locales/id-ID.json @@ -128,6 +128,7 @@ "restore": "Pulihkan", "retry": "Coba lagi", "save": "Simpan", + "saveChanges": "Simpan Perubahan", "search": "Cari", "searchPlaceholder": "Cari...", "seeOptions": "Lihat Opsi", diff --git a/libs/shinkai-i18n/locales/ja-JP.json b/libs/shinkai-i18n/locales/ja-JP.json index 2dab6343c..5a6626816 100644 --- a/libs/shinkai-i18n/locales/ja-JP.json +++ b/libs/shinkai-i18n/locales/ja-JP.json @@ -128,6 +128,7 @@ "restore": "復元", "retry": "再試行", "save": "保存", + "saveChanges": "変更を保存", "search": "検索", "searchPlaceholder": "検索...", "seeOptions": "オプションを表示", diff --git a/libs/shinkai-i18n/locales/tr-TR.json b/libs/shinkai-i18n/locales/tr-TR.json index f6c3c2ce1..0d864fe7a 100644 --- a/libs/shinkai-i18n/locales/tr-TR.json +++ b/libs/shinkai-i18n/locales/tr-TR.json @@ -128,6 +128,7 @@ "restore": "Geri Yükle", "retry": "Tekrar Dene", "save": "Kaydet", + "saveChanges": "Değişiklikleri Kaydet", "search": "Ara", "searchPlaceholder": "Ara...", "seeOptions": "Seçenekleri Gör", diff --git a/libs/shinkai-i18n/locales/zh-CN.json b/libs/shinkai-i18n/locales/zh-CN.json index 0172e4211..637644870 100644 --- a/libs/shinkai-i18n/locales/zh-CN.json +++ b/libs/shinkai-i18n/locales/zh-CN.json @@ -128,6 +128,7 @@ "restore": "恢复", "retry": "重试", "save": "保存", + "saveChanges": "保存更改", "search": "搜索", "searchPlaceholder": "搜索...", "seeOptions": "查看选项", diff --git a/libs/shinkai-i18n/src/lib/default/index.ts b/libs/shinkai-i18n/src/lib/default/index.ts index ca3dde37c..4cf2651c1 100644 --- a/libs/shinkai-i18n/src/lib/default/index.ts +++ b/libs/shinkai-i18n/src/lib/default/index.ts @@ -444,6 +444,7 @@ export default { fileWithCount_one: '{{count}} File', fileWithCount_other: '{{count}} Files', save: 'Save', + saveChanges: 'Save Changes', cancel: 'Cancel', continue: 'Continue', connect: 'Connect', diff --git a/libs/shinkai-message-ts/src/api/tools/types.ts b/libs/shinkai-message-ts/src/api/tools/types.ts index 49d0e8e5c..9fe5fff70 100644 --- a/libs/shinkai-message-ts/src/api/tools/types.ts +++ b/libs/shinkai-message-ts/src/api/tools/types.ts @@ -21,6 +21,7 @@ export type ToolConfig = { key_name: string; key_value: string | null; required: boolean; + type: string | null; }; }; diff --git a/libs/shinkai-message-ts/src/api/vector-fs/types.ts b/libs/shinkai-message-ts/src/api/vector-fs/types.ts index 178ceaa49..5ded43ee7 100644 --- a/libs/shinkai-message-ts/src/api/vector-fs/types.ts +++ b/libs/shinkai-message-ts/src/api/vector-fs/types.ts @@ -1,5 +1,6 @@ export type GetListDirectoryContentsRequest = { path: string; + depth?: number; }; export type DirectoryContent = { diff --git a/libs/shinkai-node-state/src/lib/utils/files.ts b/libs/shinkai-node-state/src/lib/utils/files.ts index cb5d20cf9..de453e051 100644 --- a/libs/shinkai-node-state/src/lib/utils/files.ts +++ b/libs/shinkai-node-state/src/lib/utils/files.ts @@ -4,6 +4,7 @@ import { TreeNode } from 'primereact/treenode'; export function transformDataToTreeNodes( data: DirectoryContent[], parentPath = '/', + selectedPaths?: string[], ): TreeNode[] { const result: TreeNode[] = []; @@ -14,15 +15,19 @@ export function transformDataToTreeNodes( data: item, icon: item.is_directory ? 'icon-folder' : 'icon-file', children: item.is_directory - ? transformDataToTreeNodes(item.children ?? [], item.path) + ? transformDataToTreeNodes( + item.children ?? [], + item.path, + selectedPaths, + ) : undefined, + className: selectedPaths?.includes(item.path) ? 'p-node-disabled' : '', }; result.push(itemNode); } return result; } - export function getFlatChildItems( data: DirectoryContent[], ): DirectoryContent[] { diff --git a/libs/shinkai-node-state/src/v2/constants.ts b/libs/shinkai-node-state/src/v2/constants.ts index 99cc90f5d..59df7e01f 100644 --- a/libs/shinkai-node-state/src/v2/constants.ts +++ b/libs/shinkai-node-state/src/v2/constants.ts @@ -41,6 +41,7 @@ export enum FunctionKeyV2 { GET_SHINKAI_FILE_PROTOCOL = 'GET_SHINKAI_FILE_PROTOCOL', GET_ALL_TOOL_ASSETS = 'GET_ALL_TOOL_ASSETS', GET_JOB_CONTENTS = 'GET_JOB_CONTENTS', + GET_JOB_FOLDER_NAME = 'GET_JOB_FOLDER_NAME', } export const DEFAULT_CHAT_CONFIG = { diff --git a/libs/shinkai-node-state/src/v2/mutations/createJob/useCreateJob.ts b/libs/shinkai-node-state/src/v2/mutations/createJob/useCreateJob.ts index 591a5b86e..89782bf3d 100644 --- a/libs/shinkai-node-state/src/v2/mutations/createJob/useCreateJob.ts +++ b/libs/shinkai-node-state/src/v2/mutations/createJob/useCreateJob.ts @@ -18,6 +18,13 @@ export const useCreateJob = (options?: Options) => { queryKey: [FunctionKeyV2.GET_INBOXES], }); + queryClient.invalidateQueries({ + queryKey: [FunctionKeyV2.GET_JOB_SCOPE], + }); + queryClient.invalidateQueries({ + queryKey: [FunctionKeyV2.GET_VR_FILES], + }); + if (options?.onSuccess) { options.onSuccess(response, variables, context); } diff --git a/libs/shinkai-node-state/src/v2/mutations/sendMessageToJob/useSendMessageToJob.ts b/libs/shinkai-node-state/src/v2/mutations/sendMessageToJob/useSendMessageToJob.ts index 4b61a1431..6ddf6c697 100644 --- a/libs/shinkai-node-state/src/v2/mutations/sendMessageToJob/useSendMessageToJob.ts +++ b/libs/shinkai-node-state/src/v2/mutations/sendMessageToJob/useSendMessageToJob.ts @@ -70,6 +70,12 @@ export const useSendMessageToJob = (options?: Options) => { }; }, onSuccess: (response, variables, context) => { + queryClient.invalidateQueries({ + queryKey: [FunctionKeyV2.GET_JOB_SCOPE], + }); + queryClient.invalidateQueries({ + queryKey: [FunctionKeyV2.GET_VR_FILES], + }); if (options?.onSuccess) { options.onSuccess(response, variables, context); } diff --git a/libs/shinkai-node-state/src/v2/queries/getDirectoryContents/index.ts b/libs/shinkai-node-state/src/v2/queries/getDirectoryContents/index.ts index 116b51e12..1c9b3b722 100644 --- a/libs/shinkai-node-state/src/v2/queries/getDirectoryContents/index.ts +++ b/libs/shinkai-node-state/src/v2/queries/getDirectoryContents/index.ts @@ -6,9 +6,11 @@ export const getListDirectoryContents = async ({ nodeAddress, path, token, + depth, }: GetVRPathSimplifiedInput) => { const response = await getListDirectoryContentsApi(nodeAddress, token, { path: path, + depth, }); return response; diff --git a/libs/shinkai-node-state/src/v2/queries/getDirectoryContents/types.ts b/libs/shinkai-node-state/src/v2/queries/getDirectoryContents/types.ts index 8d1c027d3..64e66e847 100644 --- a/libs/shinkai-node-state/src/v2/queries/getDirectoryContents/types.ts +++ b/libs/shinkai-node-state/src/v2/queries/getDirectoryContents/types.ts @@ -7,6 +7,7 @@ import { FunctionKeyV2 } from '../../constants'; export type GetVRPathSimplifiedInput = Token & { nodeAddress: string; path: string; + depth?: number; }; export type UseGetDirectoryContents = [ diff --git a/libs/shinkai-node-state/src/v2/queries/getJobFolderName/index.ts b/libs/shinkai-node-state/src/v2/queries/getJobFolderName/index.ts new file mode 100644 index 000000000..7c85caadd --- /dev/null +++ b/libs/shinkai-node-state/src/v2/queries/getJobFolderName/index.ts @@ -0,0 +1,14 @@ +import { getJobFolderName as getJobFolderNameApi } from '@shinkai_network/shinkai-message-ts/api/jobs/index'; + +import type { GetJobFolderNameInput } from './types'; + +export const getJobFolderName = async ({ + nodeAddress, + token, + jobId, +}: GetJobFolderNameInput) => { + const result = await getJobFolderNameApi(nodeAddress, token, { + job_id: jobId, + }); + return result; +}; diff --git a/libs/shinkai-node-state/src/v2/queries/getJobFolderName/types.ts b/libs/shinkai-node-state/src/v2/queries/getJobFolderName/types.ts new file mode 100644 index 000000000..28b68fb2c --- /dev/null +++ b/libs/shinkai-node-state/src/v2/queries/getJobFolderName/types.ts @@ -0,0 +1,9 @@ +import { GetAgentResponse } from '@shinkai_network/shinkai-message-ts/api/agents/types'; +import { Token } from '@shinkai_network/shinkai-message-ts/api/general/types'; + +export type GetJobFolderNameInput = Token & { + nodeAddress: string; + jobId: string; +}; + +export type GetJobFolderNameOutput = GetAgentResponse; diff --git a/libs/shinkai-node-state/src/v2/queries/getJobFolderName/useGetJobFolderName.ts b/libs/shinkai-node-state/src/v2/queries/getJobFolderName/useGetJobFolderName.ts new file mode 100644 index 000000000..0163fac4c --- /dev/null +++ b/libs/shinkai-node-state/src/v2/queries/getJobFolderName/useGetJobFolderName.ts @@ -0,0 +1,13 @@ +import { useQuery } from '@tanstack/react-query'; + +import { FunctionKeyV2 } from '../../constants'; +import { getJobFolderName } from './index'; +import { GetJobFolderNameInput } from './types'; + +export const useGetJobFolderName = (input: GetJobFolderNameInput) => { + const response = useQuery({ + queryKey: [FunctionKeyV2.GET_JOB_FOLDER_NAME, input], + queryFn: () => getJobFolderName(input), + }); + return response; +}; diff --git a/libs/shinkai-ui/src/components/rjsf/FieldTemplate/FieldTemplate.tsx b/libs/shinkai-ui/src/components/rjsf/FieldTemplate/FieldTemplate.tsx index 0f4e5d997..0ab5ddaba 100644 --- a/libs/shinkai-ui/src/components/rjsf/FieldTemplate/FieldTemplate.tsx +++ b/libs/shinkai-ui/src/components/rjsf/FieldTemplate/FieldTemplate.tsx @@ -7,6 +7,7 @@ import { StrictRJSFSchema, } from '@rjsf/utils'; +import { formatText } from '../../../helpers/format-text'; import { cn } from '../../../utils'; export default function FieldTemplate< @@ -69,7 +70,7 @@ export default function FieldTemplate< )} htmlFor={id} > - {label} + {formatText(label)} {required ? '*' : null} )} diff --git a/libs/shinkai-ui/src/helpers/format-text.ts b/libs/shinkai-ui/src/helpers/format-text.ts index ade55ac37..22361e700 100644 --- a/libs/shinkai-ui/src/helpers/format-text.ts +++ b/libs/shinkai-ui/src/helpers/format-text.ts @@ -1,15 +1,12 @@ -import { ShinkaiToolHeader } from "@shinkai_network/shinkai-message-ts/api/tools/types"; +import { ShinkaiToolHeader } from '@shinkai_network/shinkai-message-ts/api/tools/types'; export const formatText = (text: string) => { - const words = text.split('_'); - - const formattedWords = words.map((word) => { - return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase(); - }); - - const result = formattedWords.join(' '); - - return result.charAt(0).toUpperCase() + result.slice(1); + const camelToSpaces = text.replace(/([a-z])([A-Z])/g, '$1 $2'); + const snakeToSpaces = camelToSpaces.replace(/_/g, ' '); + return snakeToSpaces + .split(' ') + .map((word) => word.charAt(0).toUpperCase() + word.slice(1)) + .join(' '); }; export const formatCamelCaseText = (text: string) => {