Files
lingji-work-fe/src/stores/modules/chat/index.ts

53 lines
1.3 KiB
TypeScript
Raw Normal View History

import { defineStore } from 'pinia';
2025-08-28 12:03:52 +08:00
import { createSession, getAgentData } from '@/api/all/chat';
2025-08-25 18:01:04 +08:00
import { handleUserHome } from '@/utils/user';
2025-08-28 12:03:52 +08:00
import { glsWithCatch, slsWithCatch, rlsWithCatch } from '@/utils/stroage';
interface ChatState {
searchValue?: string;
agentInfo?: agentInfo;
}
type agentInfo = {
agent_id?: string;
name?: string;
description?: string;
};
export const useChatStore = defineStore('chat', {
state: (): ChatState => ({
searchValue: '',
2025-08-28 12:03:52 +08:00
agentInfo: (glsWithCatch('agentInfo') && JSON.parse(glsWithCatch('agentInfo') as string)) || {},
}),
actions: {
setSearchValue(searchValue: string) {
this.searchValue = searchValue;
},
clearSearchValue() {
this.searchValue = '';
},
2025-08-25 18:01:04 +08:00
async getAgentInfo() {
2025-08-28 12:03:52 +08:00
const { code, data } = await getAgentData();
2025-08-25 18:01:04 +08:00
if (code === 200) {
this.setAgentInfo(data);
}
},
setAgentInfo(agentInfo: agentInfo) {
this.agentInfo = agentInfo;
2025-08-28 12:03:52 +08:00
slsWithCatch('agentInfo', JSON.stringify(agentInfo));
},
clearAgentInfo() {
this.agentInfo = {};
this.searchValue = '';
},
async onCreateSession() {
const { code, data } = await createSession();
if (code === 200) {
handleUserHome({
conversationId: data.session_id,
});
}
},
},
});