You've already forked agentic-coding-workflow
feat(web): acp pinia store (agent_kinds)
This commit is contained in:
@@ -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<AgentKindAdmin[]>([]) // admin view (full DTO)
|
||||
const enabledAgentKinds = ref<AgentKindPublic[]>([]) // public view (redacted DTO)
|
||||
const loading = ref(false)
|
||||
const error = ref<string | null>(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,
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user