From 77a67f2dc4f9bceb095962524eb4ad7e6aa27429 Mon Sep 17 00:00:00 2001 From: Alfredo Gallardo Date: Thu, 9 Nov 2023 10:48:25 -0300 Subject: [PATCH] - improve: added agent pre selection when it was recently added --- .../src/components/add-agent/add-agent.tsx | 2 +- .../src/components/create-job/create-job.tsx | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/shinkai-visor/src/components/add-agent/add-agent.tsx b/apps/shinkai-visor/src/components/add-agent/add-agent.tsx index c9d6cf9cb..c677801ea 100644 --- a/apps/shinkai-visor/src/components/add-agent/add-agent.tsx +++ b/apps/shinkai-visor/src/components/add-agent/add-agent.tsx @@ -60,7 +60,7 @@ export const AddAgent = () => { }); const { mutateAsync: createAgent, isLoading } = useCreateAgent({ onSuccess: () => { - history.replace({ pathname: '/inboxes/create-job' }); + history.replace({ pathname: '/inboxes/create-job' }, { agentName: form.getValues().agentName }); }, }); const modelOptions: { value: Models; label: string }[] = [ diff --git a/apps/shinkai-visor/src/components/create-job/create-job.tsx b/apps/shinkai-visor/src/components/create-job/create-job.tsx index a53126268..bd3d21ba5 100644 --- a/apps/shinkai-visor/src/components/create-job/create-job.tsx +++ b/apps/shinkai-visor/src/components/create-job/create-job.tsx @@ -44,7 +44,7 @@ type FormSchemaType = z.infer; export const CreateJob = () => { const history = useHistory(); const intl = useIntl(); - const location = useLocation<{ files: File[] }>(); + const location = useLocation<{ files: File[], agentName: string }>(); const query = useQuery(); const auth = useAuth((state) => state.auth); const form = useForm({ @@ -84,6 +84,14 @@ export const CreateJob = () => { useEffect(() => { form.setValue('files', location?.state?.files || []); }, [location, form]); + useEffect(() => { + if (location?.state?.agentName) { + const agent = agents.find(agent => (agent.full_identity_name as any)?.subidentity_name === location.state.agentName); + if (agent) { + form.setValue('agent', agent.id); + } + } + }, [form, location, agents]); const submit = (values: FormSchemaType) => { if (!auth) return; let content = values.content;