2025-10-29 10:22:14 +08:00
|
|
|
|
import { ref } from 'vue'
|
|
|
|
|
|
import { defineStore } from 'pinia'
|
|
|
|
|
|
import { v4 as uuidv4 } from 'uuid'
|
|
|
|
|
|
|
|
|
|
|
|
import { store } from '../index'
|
|
|
|
|
|
import { useStorage } from '@vueuse/core'
|
2025-10-31 18:42:31 +08:00
|
|
|
|
import type { IExecuteRawResponse } from '@/api'
|
2025-11-04 15:26:52 +08:00
|
|
|
|
import { useConfigStore } from '@/stores/modules/config.ts'
|
2025-10-29 10:22:14 +08:00
|
|
|
|
|
|
|
|
|
|
export interface Agent {
|
|
|
|
|
|
Name: string
|
|
|
|
|
|
Profile: string
|
|
|
|
|
|
Icon: string
|
2025-11-03 09:44:14 +08:00
|
|
|
|
Classification: string
|
2025-10-29 10:22:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type HslColorVector = [number, number, number]
|
|
|
|
|
|
|
|
|
|
|
|
export interface IRichText {
|
2025-11-04 15:26:52 +08:00
|
|
|
|
template: string
|
|
|
|
|
|
data: Record<
|
|
|
|
|
|
string,
|
|
|
|
|
|
{
|
|
|
|
|
|
text: string
|
|
|
|
|
|
style?: Record<string, string>
|
|
|
|
|
|
color?: HslColorVector
|
|
|
|
|
|
}
|
|
|
|
|
|
>
|
2025-10-29 10:22:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface TaskProcess {
|
|
|
|
|
|
ActionType: string
|
|
|
|
|
|
AgentName: string
|
|
|
|
|
|
Description: string
|
|
|
|
|
|
ID: string
|
|
|
|
|
|
ImportantInput: string[]
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface IRawStepTask {
|
|
|
|
|
|
Id?: string
|
|
|
|
|
|
StepName?: string
|
|
|
|
|
|
TaskContent?: string
|
|
|
|
|
|
InputObject_List?: string[]
|
|
|
|
|
|
OutputObject?: string
|
|
|
|
|
|
AgentSelection?: string[]
|
|
|
|
|
|
Collaboration_Brief_FrontEnd: IRichText
|
|
|
|
|
|
TaskProcess: TaskProcess[]
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface IRawPlanResponse {
|
|
|
|
|
|
'Initial Input Object'?: string[] | string
|
|
|
|
|
|
'General Goal'?: string
|
|
|
|
|
|
'Collaboration Process'?: IRawStepTask[]
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-04 15:26:52 +08:00
|
|
|
|
const storageKey = '$agents' as const
|
|
|
|
|
|
|
|
|
|
|
|
// 清除所有以 storageKey 开头的 localStorage
|
|
|
|
|
|
function clearStorageByVersion() {
|
|
|
|
|
|
Object.keys(localStorage)
|
|
|
|
|
|
.filter((key) => key.startsWith(storageKey))
|
|
|
|
|
|
.forEach((key) => localStorage.removeItem(key))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export const useAgentsStore = defineStore('agents', () => {
|
|
|
|
|
|
const configStore = useConfigStore()
|
|
|
|
|
|
|
|
|
|
|
|
const agents = useStorage<Agent[]>(`${storageKey}-repository`, [])
|
2025-10-29 10:22:14 +08:00
|
|
|
|
function setAgents(agent: Agent[]) {
|
|
|
|
|
|
agents.value = agent
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 任务搜索的内容
|
2025-11-04 15:26:52 +08:00
|
|
|
|
const searchValue = useStorage<string>(`${storageKey}-search-value`, '')
|
2025-10-29 10:22:14 +08:00
|
|
|
|
function setSearchValue(value: string) {
|
|
|
|
|
|
searchValue.value = value
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-04 15:26:52 +08:00
|
|
|
|
const storageVersionIdentifier = useStorage<string>(`${storageKey}-storage-version-identifier`, '')
|
|
|
|
|
|
// 监听 configStore.config.agentRepository.storageVersionIdentifier 改变
|
|
|
|
|
|
watch(
|
|
|
|
|
|
() => configStore.config.agentRepository.storageVersionIdentifier,
|
|
|
|
|
|
(value) => {
|
|
|
|
|
|
// value与storageVersionIdentifier不一致清除所有storageKey开头的localStorage
|
|
|
|
|
|
if (value !== storageVersionIdentifier.value) {
|
|
|
|
|
|
clearStorageByVersion()
|
|
|
|
|
|
storageVersionIdentifier.value = value
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
immediate: true,
|
|
|
|
|
|
}
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2025-10-29 10:22:14 +08:00
|
|
|
|
// 当前的展示的任务流程
|
|
|
|
|
|
const currentTask = ref<IRawStepTask>()
|
|
|
|
|
|
function setCurrentTask(task: IRawStepTask) {
|
|
|
|
|
|
currentTask.value = task
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const agentRawPlan = ref<{ data?: IRawPlanResponse; loading?: boolean }>({ loading: false })
|
|
|
|
|
|
|
|
|
|
|
|
function setAgentRawPlan(plan: { data?: IRawPlanResponse; loading?: boolean }) {
|
|
|
|
|
|
if (plan.data) {
|
2025-11-04 15:26:52 +08:00
|
|
|
|
plan.data['Collaboration Process'] = plan.data['Collaboration Process']?.map((item) => ({
|
2025-10-29 10:22:14 +08:00
|
|
|
|
...item,
|
|
|
|
|
|
Id: uuidv4(),
|
|
|
|
|
|
}))
|
|
|
|
|
|
}
|
|
|
|
|
|
agentRawPlan.value = {
|
|
|
|
|
|
...agentRawPlan.value,
|
|
|
|
|
|
...plan,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-31 18:42:31 +08:00
|
|
|
|
// 执行完任务的结果
|
|
|
|
|
|
const executePlan = ref<IExecuteRawResponse[]>([])
|
|
|
|
|
|
function setExecutePlan(plan: IExecuteRawResponse[]) {
|
|
|
|
|
|
executePlan.value = plan
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function resetAgent() {
|
|
|
|
|
|
agentRawPlan.value = {
|
|
|
|
|
|
loading: false,
|
|
|
|
|
|
}
|
|
|
|
|
|
currentTask.value = undefined
|
|
|
|
|
|
executePlan.value = []
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-29 10:22:14 +08:00
|
|
|
|
return {
|
|
|
|
|
|
agents,
|
|
|
|
|
|
setAgents,
|
|
|
|
|
|
searchValue,
|
|
|
|
|
|
setSearchValue,
|
|
|
|
|
|
currentTask,
|
|
|
|
|
|
setCurrentTask,
|
|
|
|
|
|
agentRawPlan,
|
2025-10-31 18:42:31 +08:00
|
|
|
|
setAgentRawPlan,
|
|
|
|
|
|
executePlan,
|
|
|
|
|
|
setExecutePlan,
|
|
|
|
|
|
resetAgent,
|
2025-10-29 10:22:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 用于在组件外部(如在Pinia Store 中)使用 Pinia 提供的 store 实例。
|
|
|
|
|
|
* 官方文档解释了如何在组件外部使用 Pinia Store:
|
|
|
|
|
|
* https://pinia.vuejs.org/core-concepts/outside-component-usage.html#using-a-store-outside-of-a-component
|
|
|
|
|
|
*/
|
|
|
|
|
|
export function useAgentsStoreHook() {
|
|
|
|
|
|
return useAgentsStore(store)
|
|
|
|
|
|
}
|