From 19a11439f0dbcae95141ab74642acf0c6cbf4482 Mon Sep 17 00:00:00 2001 From: paulclindo Date: Mon, 20 May 2024 11:48:02 -0500 Subject: [PATCH 1/9] fix: navbar create ai chat --- .../src/pages/layout/main-layout.tsx | 98 +++++++------------ 1 file changed, 35 insertions(+), 63 deletions(-) diff --git a/apps/shinkai-desktop/src/pages/layout/main-layout.tsx b/apps/shinkai-desktop/src/pages/layout/main-layout.tsx index 19b5fdd32..50e89706a 100644 --- a/apps/shinkai-desktop/src/pages/layout/main-layout.tsx +++ b/apps/shinkai-desktop/src/pages/layout/main-layout.tsx @@ -10,21 +10,13 @@ import { AlertDialogHeader, AlertDialogTitle, Button, - Popover, - PopoverContent, - PopoverTrigger, Tooltip, TooltipContent, TooltipPortal, TooltipProvider, TooltipTrigger, } from '@shinkai_network/shinkai-ui'; -import { - AddAgentIcon, - FilesIcon, - InboxIcon, - JobBubbleIcon, -} from '@shinkai_network/shinkai-ui/assets'; +import { FilesIcon, InboxIcon } from '@shinkai_network/shinkai-ui/assets'; import { cn } from '@shinkai_network/shinkai-ui/utils'; import { AnimatePresence, motion, TargetAndTransition } from 'framer-motion'; import { @@ -48,7 +40,6 @@ import { import { toast } from 'sonner'; import { openShinkaiNodeManagerWindow } from '../../lib/shinkai-node-manager/shinkai-node-manager-windows-utils'; -import { ONBOARDING_PATH } from '../../routes/name'; import { useAuth } from '../../store/auth'; import { useSettings } from '../../store/settings'; import { useShinkaiNodeManager } from '../../store/shinkai-node-manager'; @@ -139,7 +130,7 @@ const NavLink = ({ export function MainNav() { const navigate = useNavigate(); const logout = useAuth((state) => state.setLogout); - // const auth = useAuth((state) => state.auth); + const isLocalShinkaiNodeIsUse = useShinkaiNodeManager( (state) => state.isInUse, ); @@ -149,8 +140,6 @@ export function MainNav() { const sidebarExpanded = useSettings((state) => state.sidebarExpanded); const toggleSidebar = useSettings((state) => state.toggleSidebar); - const [showCreateNewActions, setShowCreateNewActions] = useState(false); - const confirmDisconnect = () => { setIsConfirmLogoutDialogOpened(true); }; @@ -259,59 +248,42 @@ export function MainNav() {
- - - setShowCreateNewActions(!showCreateNewActions)} - whileHover={{ scale: !sidebarExpanded ? 1.05 : 1 }} - > - - - {sidebarExpanded && ( - - Create New - + + + + - - - -
- navigate('/create-job')} + whileHover={{ scale: !sidebarExpanded ? 1.05 : 1 }} > - + + + {sidebarExpanded && ( + + Create New + + )} + + + + + Create AI Chat - - - - Create Agent - -
-
-
+ + + + + {navigationLinks.map((item) => { return ( Date: Mon, 20 May 2024 12:23:51 -0500 Subject: [PATCH 2/9] fixes --- apps/shinkai-desktop/src/pages/layout/main-layout.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/shinkai-desktop/src/pages/layout/main-layout.tsx b/apps/shinkai-desktop/src/pages/layout/main-layout.tsx index 50e89706a..eca67ea6b 100644 --- a/apps/shinkai-desktop/src/pages/layout/main-layout.tsx +++ b/apps/shinkai-desktop/src/pages/layout/main-layout.tsx @@ -270,7 +270,7 @@ export function MainNav() { initial="hidden" variants={showAnimation} > - Create New + Create AI Chat )} From cc91651ce1b1cc73b2e55544b21a0f17676dec48 Mon Sep 17 00:00:00 2001 From: paulclindo Date: Mon, 20 May 2024 17:45:11 -0500 Subject: [PATCH 3/9] feat: add models in onboarding flow --- .../components/model-quality-tag.tsx | 15 ++- .../components/model-speed-tag.tsx | 5 +- .../shinkai-node-manager/ollama-models.tsx | 126 ++++++++++-------- .../src/pages/ai-model-installation.tsx | 19 +-- .../shinkai-desktop/src/pages/get-started.tsx | 19 +-- libs/shinkai-ui/src/components/table.tsx | 16 +-- 6 files changed, 105 insertions(+), 95 deletions(-) diff --git a/apps/shinkai-desktop/src/components/shinkai-node-manager/components/model-quality-tag.tsx b/apps/shinkai-desktop/src/components/shinkai-node-manager/components/model-quality-tag.tsx index 9377801ae..a86b4b1e7 100644 --- a/apps/shinkai-desktop/src/components/shinkai-node-manager/components/model-quality-tag.tsx +++ b/apps/shinkai-desktop/src/components/shinkai-node-manager/components/model-quality-tag.tsx @@ -9,13 +9,18 @@ export const ModelQuailityTag = ({ quality: OllamaModelQuality; }) => { const colorMap: { [key in OllamaModelQuality]: string } = { - [OllamaModelQuality.Bad]: 'border-red-700 bg-red-400 text-red-600', - [OllamaModelQuality.Medium]: - 'border-yellow-700 bg-yellow-400 text-yellow-600', - [OllamaModelQuality.Great]: 'border-green-700 bg-green-400 text-green-600', + [OllamaModelQuality.Bad]: 'bg-red-900 text-red-400', + [OllamaModelQuality.Medium]: 'text-yellow-400 bg-yellow-900', + [OllamaModelQuality.Great]: 'text-green-400 bg-green-900', }; return ( - + {quality} ); diff --git a/apps/shinkai-desktop/src/components/shinkai-node-manager/components/model-speed-tag.tsx b/apps/shinkai-desktop/src/components/shinkai-node-manager/components/model-speed-tag.tsx index bce83b0c4..4b45b5bcc 100644 --- a/apps/shinkai-desktop/src/components/shinkai-node-manager/components/model-speed-tag.tsx +++ b/apps/shinkai-desktop/src/components/shinkai-node-manager/components/model-speed-tag.tsx @@ -1,4 +1,3 @@ -import { Badge } from '@shinkai_network/shinkai-ui'; import { cn } from '@shinkai_network/shinkai-ui/utils'; import { OllamaModelSpeed } from '../../../lib/shinkai-node-manager/ollama-models'; @@ -12,8 +11,8 @@ export const ModelSpeedTag = ({ speed }: { speed: OllamaModelSpeed }) => { [OllamaModelSpeed.VeryFast]: '🐆', }; return ( - +
{speed} {emojiMap[speed]} - +
); }; diff --git a/apps/shinkai-desktop/src/components/shinkai-node-manager/ollama-models.tsx b/apps/shinkai-desktop/src/components/shinkai-node-manager/ollama-models.tsx index 468b34d14..875771590 100644 --- a/apps/shinkai-desktop/src/components/shinkai-node-manager/ollama-models.tsx +++ b/apps/shinkai-desktop/src/components/shinkai-node-manager/ollama-models.tsx @@ -1,6 +1,5 @@ import { useSyncOllamaModels } from '@shinkai_network/shinkai-node-state/lib/mutations/syncOllamaModels/useSyncOllamaModels'; import { - Badge, Button, Progress, ScrollArea, @@ -12,7 +11,8 @@ import { TableRow, } from '@shinkai_network/shinkai-ui'; import { cn } from '@shinkai_network/shinkai-ui/utils'; -import { Loader2 } from 'lucide-react'; +import { motion } from 'framer-motion'; +import { Download, Loader2, Minus } from 'lucide-react'; import { ModelResponse, ProgressResponse } from 'ollama/browser'; import { useEffect, useRef, useState } from 'react'; import { toast } from 'sonner'; @@ -38,7 +38,9 @@ export const OllamaModels = () => { const ollamaConfig = { host: ollamaApiUrl || 'http://127.0.0.1:11435' }; const { data: isShinkaiNodeRunning } = useShinkaiNodeIsRunningQuery(); const { mutateAsync: shinkaiNodeSpawn } = useShinkaiNodeSpawnMutation({}); - const { mutateAsync: syncOllamaModels } = useSyncOllamaModels(OLLAMA_MODELS.map((value) => value.fullName)); + const { mutateAsync: syncOllamaModels } = useSyncOllamaModels( + OLLAMA_MODELS.map((value) => value.fullName), + ); const { isLoading: isOllamaListLoading, data: installedOllamaModels } = useOllamaListQuery(ollamaConfig, {}); const { mutateAsync: ollamaPull } = useOllamaPullMutation(ollamaConfig, { @@ -114,7 +116,7 @@ export const OllamaModels = () => { }>(); const getProgress = (progress: ProgressResponse): number => { - return Math.ceil((100 * progress.completed) / progress.total); + return Math.ceil((100 * (progress.completed ?? 0)) / (progress.total ?? 1)); }; useEffect(() => { @@ -149,33 +151,34 @@ export const OllamaModels = () => { ); } return ( - - - + +
+ - AI Name + AI Name Data Limit Quality Speed - Size - + Size + {OLLAMA_MODELS.map((model) => { return ( - + -
-
- {model.name} -
- +
+ {model.name} + {/**/} + {/* {model.fullName}*/} + {/**/} + {model.description} - - {model.fullName} -
@@ -189,40 +192,57 @@ export const OllamaModels = () => { {model.size} GB - {isOllamaListLoading ? ( - - ) : installedOllamaModelsMap.has(model.fullName) ? ( - - ) : pullingModelsMap.current?.[model.fullName] ? ( -
- - - {pullingModelsMap.current?.[model.fullName]?.status} - -
- ) : ( - - )} + + {isOllamaListLoading ? ( + + ) : installedOllamaModelsMap.has(model.fullName) ? ( + + ) : pullingModelsMap.current?.[model.fullName] ? ( +
+ + {getProgress( + pullingModelsMap.current?.[ + model.fullName + ] as ProgressResponse, + ) + '%'} + + + + {pullingModelsMap.current?.[model.fullName]?.status} + +
+ ) : ( + + )} +
); diff --git a/apps/shinkai-desktop/src/pages/ai-model-installation.tsx b/apps/shinkai-desktop/src/pages/ai-model-installation.tsx index 35bd7ef5b..a78a2d552 100644 --- a/apps/shinkai-desktop/src/pages/ai-model-installation.tsx +++ b/apps/shinkai-desktop/src/pages/ai-model-installation.tsx @@ -1,30 +1,31 @@ import { buttonVariants } from '@shinkai_network/shinkai-ui'; import { cn } from '@shinkai_network/shinkai-ui/utils'; +import { ArrowRight } from 'lucide-react'; import { Link } from 'react-router-dom'; +import { OllamaModels } from '../components/shinkai-node-manager/ollama-models'; import { SubpageLayout } from './layout/simple-layout'; const AIModelInstallation = () => { return ( - -
- AI Model Installation -
+ + Continue + ); diff --git a/apps/shinkai-desktop/src/pages/get-started.tsx b/apps/shinkai-desktop/src/pages/get-started.tsx index c902509a5..773ca47cf 100644 --- a/apps/shinkai-desktop/src/pages/get-started.tsx +++ b/apps/shinkai-desktop/src/pages/get-started.tsx @@ -42,7 +42,7 @@ const GetStartedPage = () => { node_encryption_pk: response.data?.encryption_public_key ?? '', }; setAuth(updatedSetupData); - navigate('/'); + navigate('/connect-ai'); } else { throw new Error('Failed to submit registration'); } @@ -73,27 +73,12 @@ const GetStartedPage = () => { } return ( -
+

Transform your desktop experience using AI with Shinkai Desktop{' '} 🔑

- {/* Note: Temporary disabled, model manager and http subscriptions are work in progress */} - {/**/} - {/* Shinkai Private (Local)*/} - {/**/}
+ )); TableHeader.displayName = 'TableHeader'; @@ -26,11 +30,7 @@ const TableBody = React.forwardRef< HTMLTableSectionElement, React.HTMLAttributes >(({ className, ...props }, ref) => ( - + )); TableBody.displayName = 'TableBody'; @@ -55,7 +55,7 @@ const TableRow = React.forwardRef< >(({ className, ...props }, ref) => ( (({ className, ...props }, ref) => (
Date: Mon, 20 May 2024 18:59:18 -0500 Subject: [PATCH 4/9] fix: query client --- .../src/pages/ai-model-installation.tsx | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/apps/shinkai-desktop/src/pages/ai-model-installation.tsx b/apps/shinkai-desktop/src/pages/ai-model-installation.tsx index a78a2d552..e54541a0a 100644 --- a/apps/shinkai-desktop/src/pages/ai-model-installation.tsx +++ b/apps/shinkai-desktop/src/pages/ai-model-installation.tsx @@ -1,33 +1,37 @@ import { buttonVariants } from '@shinkai_network/shinkai-ui'; import { cn } from '@shinkai_network/shinkai-ui/utils'; +import { QueryClientProvider } from '@tanstack/react-query'; import { ArrowRight } from 'lucide-react'; import { Link } from 'react-router-dom'; import { OllamaModels } from '../components/shinkai-node-manager/ollama-models'; +import { queryClient } from '../lib/shinkai-node-manager/shinkai-node-manager-client'; import { SubpageLayout } from './layout/simple-layout'; const AIModelInstallation = () => { return ( - - - + - Continue - - - + + + Continue + + + + ); }; From c49e676d60df4f446d2fe36630c0c78f34f1a691 Mon Sep 17 00:00:00 2001 From: paulclindo Date: Mon, 20 May 2024 19:27:05 -0500 Subject: [PATCH 5/9] fixes --- .../src/components/shinkai-node-manager/ollama-models.tsx | 2 +- apps/shinkai-desktop/src/pages/ai-model-installation.tsx | 2 +- apps/shinkai-desktop/src/pages/get-started.tsx | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/shinkai-desktop/src/components/shinkai-node-manager/ollama-models.tsx b/apps/shinkai-desktop/src/components/shinkai-node-manager/ollama-models.tsx index 875771590..2f9d0e397 100644 --- a/apps/shinkai-desktop/src/components/shinkai-node-manager/ollama-models.tsx +++ b/apps/shinkai-desktop/src/components/shinkai-node-manager/ollama-models.tsx @@ -155,7 +155,7 @@ export const OllamaModels = () => { - AI Name + AI Name Data Limit Quality Speed diff --git a/apps/shinkai-desktop/src/pages/ai-model-installation.tsx b/apps/shinkai-desktop/src/pages/ai-model-installation.tsx index e54541a0a..652e1d7a6 100644 --- a/apps/shinkai-desktop/src/pages/ai-model-installation.tsx +++ b/apps/shinkai-desktop/src/pages/ai-model-installation.tsx @@ -21,7 +21,7 @@ const AIModelInstallation = () => { buttonVariants({ size: 'auto', }), - 'absolute right-0 top-9 mx-auto gap-2 px-6 py-2.5', + 'absolute right-4 top-9 mx-auto gap-2 px-6 py-2.5', )} to={{ pathname: '/', diff --git a/apps/shinkai-desktop/src/pages/get-started.tsx b/apps/shinkai-desktop/src/pages/get-started.tsx index 773ca47cf..91c6251cf 100644 --- a/apps/shinkai-desktop/src/pages/get-started.tsx +++ b/apps/shinkai-desktop/src/pages/get-started.tsx @@ -42,7 +42,9 @@ const GetStartedPage = () => { node_encryption_pk: response.data?.encryption_public_key ?? '', }; setAuth(updatedSetupData); - navigate('/connect-ai'); + // Hide http subscription for now + // navigate('/connect-ai'); + navigate('/ai-model-installation'); } else { throw new Error('Failed to submit registration'); } From 84c1236384e7f725a9232ffe7e3efa497dc14554 Mon Sep 17 00:00:00 2001 From: paulclindo Date: Mon, 20 May 2024 19:43:58 -0500 Subject: [PATCH 6/9] fix UI --- .../src/pages/ai-model-installation.tsx | 34 +++++++++---------- .../src/pages/layout/main-layout.tsx | 1 + .../src/pages/layout/simple-layout.tsx | 27 ++++++++++++++- 3 files changed, 44 insertions(+), 18 deletions(-) diff --git a/apps/shinkai-desktop/src/pages/ai-model-installation.tsx b/apps/shinkai-desktop/src/pages/ai-model-installation.tsx index 652e1d7a6..1225bbfaf 100644 --- a/apps/shinkai-desktop/src/pages/ai-model-installation.tsx +++ b/apps/shinkai-desktop/src/pages/ai-model-installation.tsx @@ -6,31 +6,31 @@ import { Link } from 'react-router-dom'; import { OllamaModels } from '../components/shinkai-node-manager/ollama-models'; import { queryClient } from '../lib/shinkai-node-manager/shinkai-node-manager-client'; -import { SubpageLayout } from './layout/simple-layout'; +import { FixedHeaderLayout } from './layout/simple-layout'; const AIModelInstallation = () => { return ( - - - Continue - - - +
+ + Continue + + +
+
); }; diff --git a/apps/shinkai-desktop/src/pages/layout/main-layout.tsx b/apps/shinkai-desktop/src/pages/layout/main-layout.tsx index eca67ea6b..a7c3c91c6 100644 --- a/apps/shinkai-desktop/src/pages/layout/main-layout.tsx +++ b/apps/shinkai-desktop/src/pages/layout/main-layout.tsx @@ -428,6 +428,7 @@ const MainLayout = () => { '/connect-ai', '/free-subscriptions', '/ai-model-installation', + '/get-started', ]; const displaySidebar = diff --git a/apps/shinkai-desktop/src/pages/layout/simple-layout.tsx b/apps/shinkai-desktop/src/pages/layout/simple-layout.tsx index e8e196e8e..80b11046b 100644 --- a/apps/shinkai-desktop/src/pages/layout/simple-layout.tsx +++ b/apps/shinkai-desktop/src/pages/layout/simple-layout.tsx @@ -14,7 +14,7 @@ export const SubpageLayout = ({ }) => { return (
- + Back @@ -25,6 +25,31 @@ export const SubpageLayout = ({
); }; +export const FixedHeaderLayout = ({ + title, + children, + className, +}: { + title: React.ReactNode; + children: React.ReactNode; + className?: string; +}) => { + return ( +
+
+ + + Back + +

+ {title} +

+
+
+ {children} +
+ ); +}; export const SimpleLayout = ({ title, children, From a4739e9f4b40c041f273fe873e8030fac687646b Mon Sep 17 00:00:00 2001 From: paulclindo Date: Mon, 20 May 2024 20:06:47 -0500 Subject: [PATCH 7/9] fix: re-render when pulling --- .../shinkai-node-manager/ollama-models.tsx | 67 ++++++++----------- libs/shinkai-ui/src/hooks/index.ts | 1 + libs/shinkai-ui/src/hooks/use-map.ts | 26 +++++++ 3 files changed, 55 insertions(+), 39 deletions(-) create mode 100644 libs/shinkai-ui/src/hooks/use-map.ts diff --git a/apps/shinkai-desktop/src/components/shinkai-node-manager/ollama-models.tsx b/apps/shinkai-desktop/src/components/shinkai-node-manager/ollama-models.tsx index 2f9d0e397..37bf6234f 100644 --- a/apps/shinkai-desktop/src/components/shinkai-node-manager/ollama-models.tsx +++ b/apps/shinkai-desktop/src/components/shinkai-node-manager/ollama-models.tsx @@ -10,11 +10,12 @@ import { TableHeader, TableRow, } from '@shinkai_network/shinkai-ui'; +import { useMap } from '@shinkai_network/shinkai-ui/hooks'; import { cn } from '@shinkai_network/shinkai-ui/utils'; import { motion } from 'framer-motion'; import { Download, Loader2, Minus } from 'lucide-react'; import { ModelResponse, ProgressResponse } from 'ollama/browser'; -import { useEffect, useRef, useState } from 'react'; +import { useEffect } from 'react'; import { toast } from 'sonner'; import { @@ -36,6 +37,13 @@ export const OllamaModels = () => { const auth = useAuth((auth) => auth.auth); const { data: ollamaApiUrl } = useShinkaiNodeGetOllamaApiUrlQuery(); const ollamaConfig = { host: ollamaApiUrl || 'http://127.0.0.1:11435' }; + + const installedOllamaModelsMap = useMap(); + // const [pullingModelsMap, setPullingModelsMap] = useState<{ + // [model: string]: ProgressResponse | undefined; + // }>(); + const pullingModelsMap = useMap(); + const { data: isShinkaiNodeRunning } = useShinkaiNodeIsRunningQuery(); const { mutateAsync: shinkaiNodeSpawn } = useShinkaiNodeSpawnMutation({}); const { mutateAsync: syncOllamaModels } = useSyncOllamaModels( @@ -48,10 +56,7 @@ export const OllamaModels = () => { handlePullProgress(input.model, data); }, onError: (_, input) => { - pullingModelsMap.current = { - ...pullingModelsMap.current, - [input.model]: undefined, - }; + pullingModelsMap.set(input.model, undefined); }, }); const { mutateAsync: ollamaRemove } = useOllamaRemoveMutation(ollamaConfig, { @@ -72,10 +77,7 @@ export const OllamaModels = () => { if (!progress) { continue; } - pullingModelsMap.current = { - ...pullingModelsMap.current, - [model]: progress, - }; + pullingModelsMap.set(model, progress); if (progress.status === 'success') { toast.success(`Model ${model} pull completed`); if (auth) { @@ -99,36 +101,23 @@ export const OllamaModels = () => { } catch (error) { toast.error(`Error pulling model ${model}. ${error?.toString()}`); } finally { - pullingModelsMap.current = { - ...pullingModelsMap.current, - [model]: undefined, - }; + pullingModelsMap.set(model, undefined); } }; - const [installedOllamaModelsMap, setInstalledOllamaModelsMap] = useState( - new Map(), - ); - // const [pullingModelsMap, setPullingModelsMap] = useState<{ - // [model: string]: ProgressResponse | undefined; - // }>(); - const pullingModelsMap = useRef<{ - [model: string]: ProgressResponse | undefined; - }>(); + // const [installedOllamaModelsMap, setInstalledOllamaModelsMap] = useState( + // new Map(), + // ); const getProgress = (progress: ProgressResponse): number => { return Math.ceil((100 * (progress.completed ?? 0)) / (progress.total ?? 1)); }; useEffect(() => { - setInstalledOllamaModelsMap( - new Map( - installedOllamaModels?.models.map((modelResponse) => [ - modelResponse.name, - modelResponse, - ]) || [], - ), - ); - }, [installedOllamaModels, setInstalledOllamaModelsMap]); + installedOllamaModels?.models && + installedOllamaModels.models.forEach((modelResponse) => { + installedOllamaModelsMap.set(modelResponse.name, modelResponse); + }); + }, [installedOllamaModels, installedOllamaModelsMap]); if (!isShinkaiNodeRunning) { return ( @@ -210,25 +199,25 @@ export const OllamaModels = () => { Remove - ) : pullingModelsMap.current?.[model.fullName] ? ( + ) : pullingModelsMap.get(model.fullName) ? (
{getProgress( - pullingModelsMap.current?.[ - model.fullName - ] as ProgressResponse, + pullingModelsMap.get( + model.fullName, + ) as ProgressResponse, ) + '%'} - {pullingModelsMap.current?.[model.fullName]?.status} + {pullingModelsMap.get(model.fullName)?.status}
) : ( diff --git a/libs/shinkai-ui/src/hooks/index.ts b/libs/shinkai-ui/src/hooks/index.ts index a90088558..2319301b1 100644 --- a/libs/shinkai-ui/src/hooks/index.ts +++ b/libs/shinkai-ui/src/hooks/index.ts @@ -1 +1,2 @@ export * from './use-debounce'; +export * from './use-map'; diff --git a/libs/shinkai-ui/src/hooks/use-map.ts b/libs/shinkai-ui/src/hooks/use-map.ts new file mode 100644 index 000000000..5aadea8a0 --- /dev/null +++ b/libs/shinkai-ui/src/hooks/use-map.ts @@ -0,0 +1,26 @@ +import React from 'react'; + +export function useMap(initialState: [Key, Value][] = []) { + const mapRef = React.useRef(new Map(initialState)); + const [, reRender] = React.useReducer((x) => x + 1, 0); + + mapRef.current.set = (...args) => { + Map.prototype.set.apply(mapRef.current, args); + reRender(); + return mapRef.current; + }; + + mapRef.current.clear = (...args) => { + Map.prototype.clear.apply(mapRef.current, args); + reRender(); + }; + + mapRef.current.delete = (...args) => { + const res = Map.prototype.delete.apply(mapRef.current, args); + reRender(); + + return res; + }; + + return mapRef.current; +} From c36f421e9d654d00dc73893171590de261d46bc1 Mon Sep 17 00:00:00 2001 From: paulclindo Date: Mon, 20 May 2024 20:15:03 -0500 Subject: [PATCH 8/9] fixes --- .../shinkai-node-manager/ollama-models.tsx | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/apps/shinkai-desktop/src/components/shinkai-node-manager/ollama-models.tsx b/apps/shinkai-desktop/src/components/shinkai-node-manager/ollama-models.tsx index 37bf6234f..5915d76d4 100644 --- a/apps/shinkai-desktop/src/components/shinkai-node-manager/ollama-models.tsx +++ b/apps/shinkai-desktop/src/components/shinkai-node-manager/ollama-models.tsx @@ -39,10 +39,7 @@ export const OllamaModels = () => { const ollamaConfig = { host: ollamaApiUrl || 'http://127.0.0.1:11435' }; const installedOllamaModelsMap = useMap(); - // const [pullingModelsMap, setPullingModelsMap] = useState<{ - // [model: string]: ProgressResponse | undefined; - // }>(); - const pullingModelsMap = useMap(); + const pullingModelsMap = useMap(); const { data: isShinkaiNodeRunning } = useShinkaiNodeIsRunningQuery(); const { mutateAsync: shinkaiNodeSpawn } = useShinkaiNodeSpawnMutation({}); @@ -56,7 +53,7 @@ export const OllamaModels = () => { handlePullProgress(input.model, data); }, onError: (_, input) => { - pullingModelsMap.set(input.model, undefined); + pullingModelsMap.delete(input.model); }, }); const { mutateAsync: ollamaRemove } = useOllamaRemoveMutation(ollamaConfig, { @@ -101,12 +98,9 @@ export const OllamaModels = () => { } catch (error) { toast.error(`Error pulling model ${model}. ${error?.toString()}`); } finally { - pullingModelsMap.set(model, undefined); + pullingModelsMap.delete(model); } }; - // const [installedOllamaModelsMap, setInstalledOllamaModelsMap] = useState( - // new Map(), - // ); const getProgress = (progress: ProgressResponse): number => { return Math.ceil((100 * (progress.completed ?? 0)) / (progress.total ?? 1)); From a1faca639a5744ddbc946bc884f1113ff050ea7f Mon Sep 17 00:00:00 2001 From: paulclindo Date: Mon, 20 May 2024 21:04:28 -0500 Subject: [PATCH 9/9] fixes --- .../src/components/shinkai-node-manager/ollama-models.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/shinkai-desktop/src/components/shinkai-node-manager/ollama-models.tsx b/apps/shinkai-desktop/src/components/shinkai-node-manager/ollama-models.tsx index 5915d76d4..1bb016321 100644 --- a/apps/shinkai-desktop/src/components/shinkai-node-manager/ollama-models.tsx +++ b/apps/shinkai-desktop/src/components/shinkai-node-manager/ollama-models.tsx @@ -59,6 +59,7 @@ export const OllamaModels = () => { const { mutateAsync: ollamaRemove } = useOllamaRemoveMutation(ollamaConfig, { onSuccess: (_, input) => { toast.success(`Model ${input.model} removed`); + installedOllamaModelsMap.delete(input.model); }, onError: (error, input) => { toast.error(`Error removing ${input.model}. ${error.message}`); @@ -111,7 +112,7 @@ export const OllamaModels = () => { installedOllamaModels.models.forEach((modelResponse) => { installedOllamaModelsMap.set(modelResponse.name, modelResponse); }); - }, [installedOllamaModels, installedOllamaModelsMap]); + }, [installedOllamaModels]); if (!isShinkaiNodeRunning) { return (