From b044c86728ad29211a3e5f4bfb7cbf18ba51ccf7 Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Thu, 7 May 2026 11:45:41 +0800 Subject: [PATCH] feat(web): acp pinia store (agent_kinds) --- web/src/stores/acp.ts | 69 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 web/src/stores/acp.ts diff --git a/web/src/stores/acp.ts b/web/src/stores/acp.ts new file mode 100644 index 0000000..2b94f14 --- /dev/null +++ b/web/src/stores/acp.ts @@ -0,0 +1,69 @@ +import { defineStore } from 'pinia' +import { ref } from 'vue' + +import { + acpApi, + isAgentKindAdmin, + type AgentKindAdmin, + type AgentKindPublic, + type CreateAgentKindReq, + type UpdateAgentKindReq, +} from '@/api/acp' + +export const useAcpStore = defineStore('acp', () => { + const agentKinds = ref([]) // admin view (full DTO) + const enabledAgentKinds = ref([]) // public view (redacted DTO) + const loading = ref(false) + const error = ref(null) + + async function listAgentKinds(asAdmin: boolean) { + loading.value = true + error.value = null + try { + const data = await acpApi.agentKinds.list() + if (asAdmin) { + agentKinds.value = data.filter(isAgentKindAdmin) + } else { + enabledAgentKinds.value = data as AgentKindPublic[] + } + } catch (e) { + error.value = e instanceof Error ? e.message : 'failed' + } finally { + loading.value = false + } + } + + async function createAgentKind(req: CreateAgentKindReq) { + const k = await acpApi.agentKinds.create(req) + agentKinds.value.unshift(k) + return k + } + + async function updateAgentKind(id: string, req: UpdateAgentKindReq) { + const updated = await acpApi.agentKinds.update(id, req) + const idx = agentKinds.value.findIndex((k) => k.id === id) + if (idx >= 0) agentKinds.value[idx] = updated + return updated + } + + async function deleteAgentKind(id: string) { + await acpApi.agentKinds.remove(id) + agentKinds.value = agentKinds.value.filter((k) => k.id !== id) + } + + async function getAgentKind(id: string) { + return acpApi.agentKinds.get(id) + } + + return { + agentKinds, + enabledAgentKinds, + loading, + error, + listAgentKinds, + createAgentKind, + updateAgentKind, + deleteAgentKind, + getAgentKind, + } +})