From bc94e53c062c509398b340df5db325bb381c8690 Mon Sep 17 00:00:00 2001 From: Nico Arqueros Date: Sat, 4 Jan 2025 11:20:26 -0600 Subject: [PATCH 1/8] merge agents --- .../src/components/agent/add-agent.tsx | 650 +--------------- .../src/components/agent/agent-form.tsx | 712 ++++++++++++++++++ .../src/components/agent/edit-agent.tsx | 541 +------------ .../src/components/chat/constants.ts | 2 +- 4 files changed, 717 insertions(+), 1188 deletions(-) create mode 100644 apps/shinkai-desktop/src/components/agent/agent-form.tsx diff --git a/apps/shinkai-desktop/src/components/agent/add-agent.tsx b/apps/shinkai-desktop/src/components/agent/add-agent.tsx index 64cf57fac..92a3d4f14 100644 --- a/apps/shinkai-desktop/src/components/agent/add-agent.tsx +++ b/apps/shinkai-desktop/src/components/agent/add-agent.tsx @@ -1,653 +1,7 @@ -import { zodResolver } from '@hookform/resolvers/zod'; -import { useTranslation } from '@shinkai_network/shinkai-i18n'; -import { DEFAULT_CHAT_CONFIG } from '@shinkai_network/shinkai-node-state/v2/constants'; -import { useCreateAgent } from '@shinkai_network/shinkai-node-state/v2/mutations/createAgent/useCreateAgent'; -import { useGetLLMProviders } from '@shinkai_network/shinkai-node-state/v2/queries/getLLMProviders/useGetLLMProviders'; -import { useGetTools } from '@shinkai_network/shinkai-node-state/v2/queries/getToolsList/useGetToolsList'; -import { - Button, - Form, - FormControl, - FormField, - FormItem, - FormLabel, - FormMessage, - HoverCard, - HoverCardContent, - HoverCardTrigger, - Label, - Select, - SelectContent, - SelectItem, - SelectTrigger, - SelectValue, - Slider, - Switch, - Textarea, - TextField, - Tooltip, - TooltipContent, - TooltipPortal, - TooltipProvider, - TooltipTrigger, -} from '@shinkai_network/shinkai-ui'; -import { formatText } from '@shinkai_network/shinkai-ui/helpers'; -import { BoltIcon, PlusIcon } from 'lucide-react'; -import { InfoCircleIcon } from 'primereact/icons/infocircle'; -import { useForm } from 'react-hook-form'; -import { Link, useNavigate } 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 { useSettings } from '../../store/settings'; - -const addAgentFormSchema = z.object({ - name: z - .string() - .regex( - /^[a-zA-Z0-9]+(_[a-zA-Z0-9]+)*$/, - 'It just accepts alphanumeric characters and underscores', - ), - llmProviderId: z.string(), - uiDescription: z.string(), - storage_path: z.string(), - knowledge: z.array(z.string()), - tools: z.array(z.string()), - debugMode: z.boolean(), - config: z - .object({ - custom_prompt: z.string(), - custom_system_prompt: z.string(), - temperature: z.number(), - top_k: z.number(), - top_p: z.number(), - use_tools: z.boolean(), - stream: z.boolean(), - other_model_params: z.record(z.string()), - }) - .nullable(), -}); - -type AddAgentFormValues = z.infer; +import AgentForm from './agent-form'; function AddAgentPage() { - const defaultAgentId = useSettings((state) => state.defaultAgentId); - const auth = useAuth((state) => state.auth); - const navigate = useNavigate(); - const { t } = useTranslation(); - const form = useForm({ - resolver: zodResolver(addAgentFormSchema), - defaultValues: { - name: '', - uiDescription: '', - storage_path: '', - knowledge: [], - tools: [], - debugMode: false, - config: { - stream: DEFAULT_CHAT_CONFIG.stream, - temperature: DEFAULT_CHAT_CONFIG.temperature, - top_p: DEFAULT_CHAT_CONFIG.top_p, - top_k: DEFAULT_CHAT_CONFIG.top_k, - custom_prompt: '', - custom_system_prompt: '', - other_model_params: {}, - use_tools: true, - }, - llmProviderId: defaultAgentId, - }, - }); - - const { data: toolsList } = useGetTools({ - nodeAddress: auth?.node_address ?? '', - token: auth?.api_v2_key ?? '', - }); - - const { mutateAsync: createAgent, isPending } = useCreateAgent({ - onError: (error) => { - toast.error('Failed to create agent', { - description: error.response?.data?.message ?? error.message, - }); - }, - onSuccess: () => { - navigate('/ais?tab=agents'); - }, - }); - - const { llmProviders } = useGetLLMProviders({ - nodeAddress: auth?.node_address ?? '', - token: auth?.api_v2_key ?? '', - }); - - const submit = async (values: AddAgentFormValues) => { - await createAgent({ - nodeAddress: auth?.node_address ?? '', - token: auth?.api_v2_key ?? '', - agent: { - agent_id: values.name, - full_identity_name: `${auth?.shinkai_identity}/main/agent/${values.name}`, - llm_provider_id: values.llmProviderId, - ui_description: values.uiDescription, - storage_path: values.storage_path, - knowledge: values.knowledge, - tools: values.tools, - debug_mode: values.debugMode, - config: values.config, - name: values.name, - }, - }); - }; - - return ( - - -

- Create and explore custom AI agents with tailored instructions and - diverse skills. -

-
- -
-
- ( - { - const value = e.target.value; - const alphanumericValue = value.replace( - /[^a-zA-Z0-9_]/g, - '_', - ); - field.onChange({ - ...e, - target: { - value: alphanumericValue, - }, - }); - }, - }} - label="Agent Name" - /> - )} - /> - - ( - - Description - -