Skip to content

Commit

Permalink
feat: Misc improvements and fixes (#594)
Browse files Browse the repository at this point in the history
* fix tool config

* refactor: tool

* clean up

* fixes and i18n

* hide: search folder/items

* feat: select and disable folder job inbox

* fix: context providers

* feat: move sheets to experimental

* fixes

* fix file explorer depth

* fixes
  • Loading branch information
paulclindo authored Jan 9, 2025
1 parent 84ff564 commit 59c26ca
Show file tree
Hide file tree
Showing 38 changed files with 578 additions and 1,074 deletions.
36 changes: 34 additions & 2 deletions apps/shinkai-desktop/src/components/chat/conversation-header.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -138,19 +140,42 @@ 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;

useEffect(() => {
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(
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -65,6 +66,7 @@ export const SetJobScopeDrawer = () => {
nodeAddress: auth?.node_address ?? '',
token: auth?.api_v2_key ?? '',
path: '/',
depth: 6,
});

const { mutateAsync: updateJobScope, isPending: isUpdatingJobScope } =
Expand All @@ -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) {
Expand All @@ -94,6 +106,7 @@ export const SetJobScopeDrawer = () => {
}
}, [isSetJobScopeOpen]);

console.log(selectedKeys, 'selectedKeys');
return (
<Sheet onOpenChange={setSetJobScopeOpen} open={isSetJobScopeOpen}>
<SheetContent>
Expand Down Expand Up @@ -174,7 +187,7 @@ export const SetJobScopeDrawer = () => {
size="sm"
type="button"
>
{t('common.done')}
{inboxId ? t('common.saveChanges') : t('common.done')}
</Button>
</SheetFooter>
</SheetContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default function RemoveToolButton({ toolKey }: { toolKey: string }) {

return (
<Button
className="rounded-lg"
disabled={isRemoveToolPending}
isLoading={isRemoveToolPending}
onClick={async () => {
Expand Down
37 changes: 17 additions & 20 deletions apps/shinkai-desktop/src/components/playground-tool/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
ResizableHandle,
ResizablePanel,
ResizablePanelGroup,
TooltipProvider,
} from '@shinkai_network/shinkai-ui';
import { ReactNode } from 'react';

Expand All @@ -15,24 +14,22 @@ export default function PlaygroundToolLayout({
rightElement,
}: PlaygroundToolLayoutProps) {
return (
<TooltipProvider delayDuration={0}>
<div className="flex h-full">
<ResizablePanelGroup direction="horizontal">
<ResizablePanel className="flex h-full flex-col px-3 py-4 pt-6">
{leftElement}
</ResizablePanel>
<ResizableHandle className="bg-gray-300" withHandle />
<ResizablePanel
className="flex h-full flex-col px-3 py-4 pt-6"
collapsible
defaultSize={70}
maxSize={70}
minSize={40}
>
{rightElement}
</ResizablePanel>
</ResizablePanelGroup>
</div>
</TooltipProvider>
<div className="flex h-full">
<ResizablePanelGroup direction="horizontal">
<ResizablePanel className="flex h-full flex-col px-3 py-4 pt-6">
{leftElement}
</ResizablePanel>
<ResizableHandle className="bg-gray-300" withHandle />
<ResizablePanel
className="flex h-full flex-col px-3 py-4 pt-6"
collapsible
defaultSize={70}
maxSize={70}
minSize={40}
>
{rightElement}
</ResizablePanel>
</ResizablePanelGroup>
</div>
);
}
Loading

0 comments on commit 59c26ca

Please sign in to comment.