Skip to content

Commit

Permalink
vector fs changes, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
paulclindo committed Dec 31, 2024
1 parent 8dc5194 commit e3d8c3f
Show file tree
Hide file tree
Showing 19 changed files with 107 additions and 114 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ShinkaiPath } from '@shinkai_network/shinkai-message-ts/models';
import { ShinkaiPath } from '@shinkai_network/shinkai-message-ts/api/jobs/types';
import { TreeCheckboxSelectionKeys } from 'primereact/tree';
import React, { createContext, useContext, useState } from 'react';
import { createStore, useStore } from 'zustand';
Expand Down
8 changes: 4 additions & 4 deletions apps/shinkai-desktop/src/components/sheet/data-table-cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@ export const VectorFsScopeDrawer = ({
const [nodes, setNodes] = useState<TreeNode[]>([]);
const auth = useAuth((state) => state.auth);

const { data: fileInfoArray, isSuccess: isVRFilesSuccess } = useGetVRPathSimplified(
{
const { data: fileInfoArray, isSuccess: isVRFilesSuccess } =
useGetVRPathSimplified({
nodeAddress: auth?.node_address ?? '',
profile: auth?.profile ?? '',
shinkaiIdentity: auth?.shinkai_identity ?? '',
Expand All @@ -397,8 +397,7 @@ export const VectorFsScopeDrawer = ({
node_encryption_pk: auth?.node_encryption_pk ?? '',
profile_encryption_sk: auth?.profile_encryption_sk ?? '',
profile_identity_sk: auth?.profile_identity_sk ?? '',
},
);
});

useEffect(() => {
if (isVRFilesSuccess) {
Expand Down Expand Up @@ -482,6 +481,7 @@ const FileUploadButton = ({
onDrop: async (acceptedFiles) => {
if (!auth || !fileInboxId) return;
try {
// TODO: we need a jobId to upload files in shinkai sheet
await addFileToInbox(auth.node_address, auth.api_v2_key, {
file: acceptedFiles[0],
filename: encodeURIComponent(acceptedFiles[0].name),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,10 @@ const AllFiles = () => {
} else {
navigate('/inboxes', {
state: {
selectedVRFiles: selectedFiles,
selectedVRFolders: selectedFolders,
selectedVRFiles: selectedFiles.map((file) => file.path),
selectedVRFolders: selectedFolders.map(
(folder) => folder.path,
),
},
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ const VectorFsFolder = ({
layout === VectorFSLayout.Grid && 'bg-gray-400/30 p-2',
);
const totalItem =
(folder.child_folders?.length ?? 0) + (folder.child_items?.length ?? 0);
// (folder.child_folders?.length ?? 0) + (folder.child_items?.length ?? 0);
0;

const FolderIcon = isSharedFolder ? SharedFolderIcon : DirectoryTypeIcon;

Expand Down Expand Up @@ -144,7 +145,7 @@ const VectorFsFolder = ({
event.stopPropagation();
navigate('/inboxes', {
state: {
selectedVRFolders: [folder],
selectedVRFolders: [folder.path],
},
});
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ const VectorFsItem = ({
layout === VectorFSLayout.Grid && 'bg-gray-400/30 p-2',
);

const createdDatetime = formatDateToUSLocaleString(new Date(file.created_time));
const createdDatetime = formatDateToUSLocaleString(
new Date(file.created_time),
);
// const fileSize = size(file.size);

if (isVRSelectionActive) {
Expand All @@ -94,12 +96,7 @@ const VectorFsItem = ({
className="flex flex-1 items-center gap-3"
htmlFor={`item-${file.path}`}
>
{/* <FileTypeIcon
type={
file?.vr_header?.resource_source?.Standard?.FileRef?.file_type
?.Document
}
/> */}
<FileTypeIcon type={file?.extension ?? ''} />
<VectorFsItemInfo
createdDatetime={createdDatetime}
file={file}
Expand All @@ -112,12 +109,7 @@ const VectorFsItem = ({

return (
<button className={wrapperClassname} onClick={onClick}>
{/* <FileTypeIcon
type={
file?.vr_header?.resource_source?.Standard?.FileRef?.file_type
?.Document
}
/> */}
<FileTypeIcon type={file?.extension ?? ''} />
<VectorFsItemInfo
createdDatetime={createdDatetime}
file={file}
Expand All @@ -139,7 +131,7 @@ const VectorFsItem = ({
event.stopPropagation();
navigate('/inboxes', {
state: {
selectedVRFiles: [file],
selectedVRFiles: [file.path],
},
});
}}
Expand Down
4 changes: 1 addition & 3 deletions apps/shinkai-visor/src/components/create-job/create-job.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { zodResolver } from '@hookform/resolvers/zod';
import { useTranslation } from '@shinkai_network/shinkai-i18n';
import {
ShinkaiPath,
} from '@shinkai_network/shinkai-message-ts/models/SchemaTypes';
import { ShinkaiPath } from '@shinkai_network/shinkai-message-ts/api/jobs/types';
import { buildInboxIdFromJobId } from '@shinkai_network/shinkai-message-ts/utils';
import {
CreateJobFormSchema,
Expand Down
35 changes: 30 additions & 5 deletions libs/shinkai-message-ts/src/api/jobs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { urlJoin } from '../../utils/url-join';
import {
AddFileToInboxRequest,
AddFileToInboxResponse,
AddFileToJobRequest,
AddLLMProviderRequest,
AddLLMProviderResponse,
CreateFilesInboxResponse,
Expand Down Expand Up @@ -152,20 +153,44 @@ export const addFileToInbox = async (
return response.data as AddFileToInboxResponse;
};

export const uploadFilesToInbox = async (
export const addFileToJob = async (
nodeAddress: string,
bearerToken: string,

payload: AddFileToJobRequest,
) => {
const fileData = await payload.file.arrayBuffer();

const formData = new FormData();
formData.append('job_id', payload.job_id);
formData.append('filename', payload.filename);
formData.append('file_data', new Blob([fileData]));

const response = await httpClient.post(
urlJoin(nodeAddress, '/v2/upload_file_to_job'),
formData,
{
headers: { Authorization: `Bearer ${bearerToken}` },
responseType: 'json',
},
);

return response.data as AddFileToInboxResponse;
};

export const uploadFilesToJob = async (
nodeAddress: string,
bearerToken: string,
jobId: string,
files: File[],
) => {
const folderId = await createFilesInbox(nodeAddress, bearerToken);
for (const file of files) {
await addFileToInbox(nodeAddress, bearerToken, {
await addFileToJob(nodeAddress, bearerToken, {
filename: encodeURIComponent(file.name),
file_inbox_name: folderId,
job_id: jobId,
file,
});
}
return folderId;
};

export const downloadFileFromInbox = async (
Expand Down
30 changes: 21 additions & 9 deletions libs/shinkai-message-ts/src/api/jobs/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { JobScope } from '../../models/SchemaTypes';
import { AgentInbox } from '../../models/ShinkaiMessage';

type ResourceSource = {
Expand Down Expand Up @@ -69,16 +68,23 @@ export type VRItemScope = Pick<VRItem, 'name' | 'path'> & {
source: ResourceSource;
};

export enum VectorSearchMode {
FillUpTo25k = 'FillUpTo25k',
MergeSiblings = 'MergeSiblings',
}

export type ShinkaiPath = string;

export type JobScope = {
vector_fs_items: ShinkaiPath[];
vector_fs_folders: ShinkaiPath[];
vector_search_mode?: VectorSearchMode[];
};

export type CreateJobRequest = {
llm_provider: string;
job_creation_info: {
scope: {
network_folders: [];
vector_fs_folders: VRFolderScope[];
vector_fs_items: VRItemScope[];
local_vrpack: [];
local_vrkai: [];
};
scope: JobScope;
associated_ui:
| 'Playground'
| {
Expand All @@ -96,9 +102,9 @@ export type JobMessageRequest = {
job_message: {
job_id: string;
content: string;
files_inbox: string;
parent: string | null;
tool_key?: string;
files?: string[];
};
};
export type JobMessageResponse = {
Expand Down Expand Up @@ -308,3 +314,9 @@ export type RetryMessageRequest = {
export type RemoveJobRequest = {
job_id: string;
};
export type AddFileToJobRequest = {
job_id: string;
filename: string;
file: File;
};
export type AddFileToJobResponse = string;
25 changes: 17 additions & 8 deletions libs/shinkai-message-ts/src/api/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export const sendTextMessageWithFilesToJob = async (
nodeAddress,
bearerToken,
job_id,
files
files,
);

if (uploadResponse.status !== 'success') {
Expand All @@ -171,9 +171,9 @@ export const sendTextMessageWithFilesToJob = async (
{
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${bearerToken}`,
Authorization: `Bearer ${bearerToken}`,
},
}
},
);

const data = response.data;
Expand Down Expand Up @@ -505,7 +505,16 @@ export const retrieveVRPathSimplified = async (
receiver_subidentity: string,
path = '/',
setupDetailsState: CredentialsPayload,
): Promise<{ data: any; status: string }> => {
): Promise<{
data: {
created_time: string;
has_embeddings: boolean;
is_directory: boolean;
modified_time: string;
path: string;
}[];
status: string;
}> => {
const messageStr = ShinkaiMessageBuilderWrapper.retrievePathSimplified(
setupDetailsState.profile_encryption_sk,
setupDetailsState.profile_identity_sk,
Expand Down Expand Up @@ -595,9 +604,9 @@ export const uploadFilesToVR = async (
{
headers: {
'Content-Type': 'multipart/form-data',
'Authorization': `Bearer ${bearerToken}`,
Authorization: `Bearer ${bearerToken}`,
},
}
},
);

if (response.status !== 200) {
Expand Down Expand Up @@ -1688,9 +1697,9 @@ export const uploadFilesToJob = async (
{
headers: {
'Content-Type': 'multipart/form-data',
'Authorization': `Bearer ${bearerToken}`,
Authorization: `Bearer ${bearerToken}`,
},
}
},
);

if (response.status !== 200) {
Expand Down
14 changes: 3 additions & 11 deletions libs/shinkai-message-ts/src/api/recurring-tasks/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
JobConfig,
JobMessage,
VRFolderScope,
VRItemScope,
} from '../jobs/types';
import { JobConfig, JobMessage } from '../jobs/types';

export type RecurringTaskAction =
| {
Expand All @@ -19,11 +14,8 @@ export type RecurringTaskAction =
llm_provider: string;
job_creation_info: {
scope: {
network_folders: [];
vector_fs_folders: VRFolderScope[];
vector_fs_items: VRItemScope[];
local_vrpack: [];
local_vrkai: [];
vector_fs_folders: string[];
vector_fs_items: string[];
};
is_hidden?: boolean;
associated_ui?: null;
Expand Down
22 changes: 0 additions & 22 deletions libs/shinkai-message-ts/src/models/SchemaTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,28 +67,6 @@ export enum MessageSchemaType {
SearchShinkaiTool = 'SearchShinkaiTool',
}

export enum VectorSearchMode {
FillUpTo25k = 'FillUpTo25k',
MergeSiblings = 'MergeSiblings'
}

export type ShinkaiPath = string;

export interface JobScope {
vector_fs_items: ShinkaiPath[];
vector_fs_folders: ShinkaiPath[];
vector_search_mode: VectorSearchMode[];
}

export interface JobCreation {
scope: JobScope;
}

export interface JobMessage {
job_id: string;
content: string;
}

export interface JobToolCall {
tool_id: string;
inputs: Record<string, string>;
Expand Down
12 changes: 1 addition & 11 deletions libs/shinkai-message-ts/src/models/ShinkaiMessage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { JobScope, MessageSchemaType, TSEncryptionMethod } from './SchemaTypes';
import { MessageSchemaType, TSEncryptionMethod } from './SchemaTypes';

export interface InternalMetadata {
sender_subidentity: string;
Expand Down Expand Up @@ -69,16 +69,6 @@ export type AgentInbox = {
type: 'Agent' | 'LLMProvider';
};

export type SmartInbox = {
custom_name: string;
inbox_id: string;
last_message?: ShinkaiMessage;
is_finished: boolean;
job_scope?: JobScope;
agent?: AgentInbox;
datetime_created: string;
};

export type CreateChatInboxResponse = {
status: string;
message: string;
Expand Down
Loading

0 comments on commit e3d8c3f

Please sign in to comment.