Skip to content

Commit

Permalink
- feature: added support to upload multiple files (#93)
Browse files Browse the repository at this point in the history
* - feature: added support to upload multiple files

* - refactor: adapted shinkai app to new methods
  • Loading branch information
agallardol authored Nov 28, 2023
1 parent 47d4897 commit 4b1a2e1
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion apps/shinkai-app/src/pages/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const Chat: React.FC = () => {
receiver,
message: data.message,
inboxId: deserializedId as string,
file,
files: [file],
my_device_encryption_sk: auth.my_device_encryption_sk,
my_device_identity_sk: auth.my_device_identity_sk,
node_encryption_pk: auth.node_encryption_pk,
Expand Down
2 changes: 1 addition & 1 deletion apps/shinkai-app/src/pages/CreateJob.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const CreateJob: React.FC = () => {
agentId: data.model,
content: data.description,
files_inbox: '',
file: undefined,
files: [],
my_device_encryption_sk: auth.my_device_encryption_sk,
my_device_identity_sk: auth.my_device_identity_sk,
node_encryption_pk: auth.node_encryption_pk,
Expand Down
2 changes: 1 addition & 1 deletion apps/shinkai-app/src/pages/JobChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ const JobChat: React.FC = () => {
receiver: auth.shinkai_identity,
message: message_to_send,
inboxId: deserializedId as string,
file: selectedFile,
files: [selectedFile],
my_device_encryption_sk: auth.my_device_encryption_sk,
my_device_identity_sk: auth.my_device_identity_sk,
node_encryption_pk: auth.node_encryption_pk,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export const CreateJob = () => {
agentId: values.agent,
content: content,
files_inbox: '',
file: values.files[0],
files: values.files,
my_device_encryption_sk: auth.my_device_encryption_sk,
my_device_identity_sk: auth.my_device_identity_sk,
node_encryption_pk: auth.node_encryption_pk,
Expand Down
6 changes: 4 additions & 2 deletions libs/shinkai-message-ts/src/api/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export const sendTextMessageWithFilesForInbox = async (
receiver: string,
text_message: string,
job_inbox: string,
selectedFile: File,
files: File[],
setupDetailsState: CredentialsPayload,
): Promise<{ inboxId: string; message: ShinkaiMessage }> => {
try {
Expand All @@ -172,7 +172,9 @@ export const sendTextMessageWithFilesForInbox = async (
);

await fileUploader.createFolder();
await fileUploader.uploadEncryptedFile(selectedFile);
for (const fileToUpload of files) {
await fileUploader.uploadEncryptedFile(fileToUpload);
}
const responseText = await fileUploader.finalizeAndSend(text_message);
const message: ShinkaiMessage = JSON.parse(responseText);

Expand Down
6 changes: 3 additions & 3 deletions libs/shinkai-node-state/src/lib/mutations/createJob/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const createJob = async ({
agentId,
content,
files_inbox,
file,
files,
my_device_encryption_sk,
my_device_identity_sk,
node_encryption_pk,
Expand Down Expand Up @@ -48,14 +48,14 @@ export const createJob = async ({
},
);

const response = file
const response = files?.length
? await sendTextMessageWithFilesForInbox(
shinkaiIdentity,
profile, // sender subidentity
receiver,
content,
buildInboxIdFromJobId(jobId),
file,
files,
{
my_device_encryption_sk: my_device_encryption_sk,
my_device_identity_sk: my_device_identity_sk,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type CreateJobInput = JobCredentialsPayload & {
agentId: string;
content: string;
files_inbox: string;
file?: File;
files?: File[];
};

export type CreateJobOutput = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const sendMessageWithFilesToInbox = async ({
receiver,
message,
inboxId,
file,
files,
my_device_encryption_sk,
my_device_identity_sk,
node_encryption_pk,
Expand All @@ -21,7 +21,7 @@ export const sendMessageWithFilesToInbox = async ({
receiver,
message,
inboxId,
file,
files,
{
my_device_encryption_sk,
my_device_identity_sk,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ export type SendMessageWithFilesToInboxInput = CredentialsPayload & {
senderSubidentity: string;
message: string;
inboxId: string;
file: File;
files: File[];
};

0 comments on commit 4b1a2e1

Please sign in to comment.