* chore: update core services and module export * Correct version of plugins (#374) Co-authored-by: Hien To <tominhhien97@gmail.com> * janhq/jan: Update tag build 1.0.2 for data-plugin * janhq/jan: Update tag build 1.0.2 for inference-plugin * janhq/jan: Update tag build 1.0.2 for model-management-plugin * janhq/jan: Update tag build 1.0.2 for monitoring-plugin * janhq/jan: Update tag build 1.0.2 for openai-plugin * chore: update web to use @janhq/core module --------- Co-authored-by: hiento09 <136591877+hiento09@users.noreply.github.com> Co-authored-by: Hien To <tominhhien97@gmail.com> Co-authored-by: Service Account <service@jan.ai>
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import { Conversation, ConversationState } from "@/_models/Conversation";
|
|
import { useSetAtom } from "jotai";
|
|
import { executeSerial } from "@/_services/pluginService";
|
|
import { DataService } from "@janhq/core";
|
|
import {
|
|
conversationStatesAtom,
|
|
userConversationsAtom,
|
|
} from "@/_helpers/atoms/Conversation.atom";
|
|
|
|
const useGetUserConversations = () => {
|
|
const setConversationStates = useSetAtom(conversationStatesAtom);
|
|
const setConversations = useSetAtom(userConversationsAtom);
|
|
|
|
const getUserConversations = async () => {
|
|
try {
|
|
const convos: Conversation[] | undefined = await executeSerial(
|
|
DataService.GetConversations
|
|
);
|
|
const convoStates: Record<string, ConversationState> = {};
|
|
convos?.forEach((convo) => {
|
|
convoStates[convo._id ?? ""] = {
|
|
hasMore: true,
|
|
waitingForResponse: false,
|
|
};
|
|
});
|
|
setConversationStates(convoStates);
|
|
setConversations(convos ?? []);
|
|
} catch (ex) {
|
|
console.log(ex);
|
|
}
|
|
};
|
|
|
|
return {
|
|
getUserConversations,
|
|
};
|
|
};
|
|
|
|
export default useGetUserConversations;
|