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

47 lines
1017 B
TypeScript
Raw Normal View History

import { defineStore } from 'pinia';
import { createSession } from '@/api/all/chat';
import { handleUserHome } from '@/utils/user';
interface ChatState {
searchValue?: string;
agentInfo?: agentInfo;
}
type agentInfo = {
agent_id?: string;
name?: string;
description?: string;
};
export const useChatStore = defineStore('chat', {
state: (): ChatState => ({
searchValue: '',
agentInfo: {},
}),
actions: {
setSearchValue(searchValue: string) {
this.searchValue = searchValue;
},
clearSearchValue() {
this.searchValue = '';
},
setAgentInfo(agentInfo: agentInfo) {
this.agentInfo = agentInfo;
},
clearAgentInfo() {
this.agentInfo = {};
},
clearAllAgentInfo() {
this.agentInfo = {};
this.searchValue = '';
},
async onCreateSession() {
const { code, data } = await createSession();
if (code === 200) {
handleUserHome({
conversationId: data.session_id,
});
}
},
},
});