瀏覽代碼

完善中

zb 2 年之前
父節點
當前提交
3eeefe399c

+ 4 - 4
SEChat-frontend/src/store/modules/agent/helper.ts

@@ -7,16 +7,16 @@ export function defaultState(): Agent.AgentState {
 	return {
 		active: uuid,
 		usingContext: true,
-		history: [{ uuid, title: t('chat.newChatTitle'), isEdit: false }],
-		chat: [{ uuid, data: [] }],
+		history: [{ uuid, title: t('agent.newAgentTitle'), isEdit: false }],
+		agent: [{ uuid, data: [] }],
 	}
 }
 
-export function getLocalState(): Chat.ChatState {
+export function getLocalState(): Agent.AgentState {
 	const localState = ss.get(LOCAL_NAME)
 	return { ...defaultState(), ...localState }
 }
 
-export function setLocalState(state: Chat.ChatState) {
+export function setLocalState(state: Agent.AgentState) {
 	ss.set(LOCAL_NAME, state)
 }

+ 32 - 6
SEChat-frontend/src/store/modules/agent/index.ts

@@ -1,15 +1,41 @@
 import { defineStore } from 'pinia'
-import type { AgentState } from './helper'
-import { getLocalSetting } from './helper'
-import { store } from '@/store/helper'
+import { defaultState, getLocalState, setLocalState } from './helper'
+import { router } from '@/router'
+import { t } from '@/locales'
 
 export const useAgentStore = defineStore('agent-store', {
-	state: (): AgentState => getLocalSetting(),
-	actions: {
+	state: (): Agent.AgentState => getLocalState(),
+	getters: {
+		getAgentHistoryByCurrentActive(state: Agent.AgentState) {
+			const index = state.history.findIndex(item => item.uuid === state.active)
+			if (index !== -1)
+				return state.history[index]
+			return null
+		},
 
+		getAgentByUuid(state: Agent.AgentState) {
+			return (uuid?: number) => {
+				if (uuid)
+					return state.agent.find(item => item.uuid === uuid)?.data ?? []
+				return state.agent.find(item => item.uuid === state.active)?.data ?? []
+			}
+		},
+	},
+	actions: {
+		clearHistory() {
+			this.$state = { ...defaultState() }
+			this.recordState()
+		},
+		async reloadRoute(uuid?: number) {
+			this.recordState()
+			await router.push({ name: 'Agent', params: { uuid } })
+		},
+		recordState() {
+			setLocalState(this.$state)
+		},
 	},
 })
 
 export function useAgentStoreWithOut() {
-	return useAgentStore(store)
+
 }

+ 22 - 7
SEChat-frontend/src/typings/agent.d.ts

@@ -1,18 +1,33 @@
 declare namespace Agent{
+	//agent属性
 	interface Agent{
-		dateTime: string
-		text: string
+		createTime: string
+		taskText: string
 		inversion?: boolean
 		error?: boolean
 		loading?: boolean
-		conversationOptions?: ConversationRequest | null
-		requestOptions: { prompt: string; options?: ConversationRequest | null }
-	}
-	interface AgentState{
-		
+		isSelectKnowledgeBase?:boolean //是否选择了知识库
+		knowledgeBase:string //搭载了什么知识库
+		promptList:string[]//?不确定是不是这样写,提示词列表
+		knowledgeGraph:string//?不确定是不是这样写,知识图谱
 
 	}
+	interface AgentHistory {
+		title: string
+		isEdit: boolean
+		uuid: number
+	}
+	interface AgentState {//agent列表
+		active: number | null
+		usingContext: boolean;
+		history: AgentHistory[]
+		agent: { uuid: number; data: Agent[] }[]
+	}
+	interface AgentRequest{//post后端的格式
 
+	}
+	interface AgentResponse{//get后端的格式
 
+	}
 
 }