-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
integrate smart inboxes in shinkai web/mobile
- Loading branch information
1 parent
44894ef
commit fd8499e
Showing
7 changed files
with
245 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
libs/shinkai-node-state/src/lib/mutations/updateInboxName/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { ApiConfig, handleHttpError } from "@shinkai_network/shinkai-message-ts/api"; | ||
import { | ||
type CredentialsPayload, | ||
type ShinkaiMessage, | ||
} from "@shinkai_network/shinkai-message-ts/models"; | ||
import { | ||
ShinkaiMessageBuilderWrapper, | ||
} from "@shinkai_network/shinkai-message-ts/wasm"; | ||
|
||
export type SmartInbox = { | ||
custom_name: string; | ||
inbox_id: string; | ||
last_message: ShinkaiMessage; | ||
}; | ||
|
||
export const updateInboxNameApi = async ( | ||
sender: string, | ||
sender_subidentity: string, | ||
receiver: string, | ||
receiver_subidentity: string, | ||
setupDetailsState: CredentialsPayload, | ||
inboxName: string, | ||
inboxId: string | ||
): Promise<SmartInbox[]> => { | ||
try { | ||
const messageString = ShinkaiMessageBuilderWrapper.update_shinkai_inbox_name( | ||
setupDetailsState.my_device_encryption_sk, | ||
setupDetailsState.my_device_identity_sk, | ||
setupDetailsState.node_encryption_pk, | ||
sender, | ||
sender_subidentity, | ||
receiver, | ||
receiver_subidentity, | ||
inboxId, | ||
inboxName | ||
); | ||
|
||
const message = JSON.parse(messageString); | ||
|
||
const apiEndpoint = ApiConfig.getInstance().getEndpoint(); | ||
const response = await fetch(`${apiEndpoint}/v1/update_smart_inbox_name`, { | ||
method: "POST", | ||
body: JSON.stringify(message), | ||
headers: { "Content-Type": "application/json" }, | ||
}); | ||
const data = await response.json(); | ||
await handleHttpError(response); | ||
return data.data; | ||
} catch (error) { | ||
console.error("Error updating inbox name:", error); | ||
throw error; | ||
} | ||
}; | ||
|
||
export const updateInboxName = async ({ | ||
senderSubidentity, | ||
sender, | ||
receiver, | ||
receiverSubidentity, | ||
my_device_encryption_sk, | ||
my_device_identity_sk, | ||
node_encryption_pk, | ||
profile_encryption_sk, | ||
profile_identity_sk, // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
inboxName, | ||
inboxId, // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
}: { | ||
senderSubidentity: string; | ||
sender: string; | ||
receiver: string; | ||
receiverSubidentity: string; | ||
my_device_encryption_sk: string; | ||
my_device_identity_sk: string; | ||
node_encryption_pk: string; | ||
profile_encryption_sk: string; | ||
profile_identity_sk: string; | ||
inboxName: string; | ||
inboxId: string; | ||
}) => { | ||
const response = await updateInboxNameApi( | ||
sender, | ||
senderSubidentity, | ||
receiver, | ||
receiverSubidentity, | ||
{ | ||
my_device_encryption_sk, | ||
my_device_identity_sk, | ||
node_encryption_pk, | ||
profile_encryption_sk, | ||
profile_identity_sk, | ||
}, | ||
inboxName, | ||
inboxId | ||
); | ||
console.log("updateInboxName response:", response); | ||
|
||
return response; | ||
}; |
5 changes: 5 additions & 0 deletions
5
libs/shinkai-node-state/src/lib/mutations/updateInboxName/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
|
||
export type UpdateInboxNamebInput = any; | ||
|
||
export type UpdateInboxNameOutput = any; |
15 changes: 15 additions & 0 deletions
15
libs/shinkai-node-state/src/lib/mutations/updateInboxName/useUpdateInboxName.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { UseMutationOptions } from "@tanstack/react-query"; | ||
import { useMutation } from "@tanstack/react-query"; | ||
|
||
import { updateInboxName } from "."; | ||
import type { UpdateInboxNamebInput,UpdateInboxNameOutput } from "./types"; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
type Options = UseMutationOptions<UpdateInboxNameOutput, Error, UpdateInboxNamebInput>; | ||
|
||
export const useUpdateInboxName = (options?: Options) => { | ||
return useMutation({ | ||
mutationFn: updateInboxName, | ||
...options, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters