diff --git a/web/src/stores/acp.ts b/web/src/stores/acp.ts index 2b94f14..f79a2e4 100644 --- a/web/src/stores/acp.ts +++ b/web/src/stores/acp.ts @@ -4,9 +4,11 @@ import { ref } from 'vue' import { acpApi, isAgentKindAdmin, + type AcpSession, type AgentKindAdmin, type AgentKindPublic, type CreateAgentKindReq, + type CreateSessionReq, type UpdateAgentKindReq, } from '@/api/acp' @@ -16,6 +18,9 @@ export const useAcpStore = defineStore('acp', () => { const loading = ref(false) const error = ref(null) + const sessions = ref([]) + const currentSession = ref(null) + async function listAgentKinds(asAdmin: boolean) { loading.value = true error.value = null @@ -55,6 +60,41 @@ export const useAcpStore = defineStore('acp', () => { return acpApi.agentKinds.get(id) } + async function listSessions(all = false) { + loading.value = true + error.value = null + try { + sessions.value = await acpApi.sessions.list(all) + } catch (e) { + error.value = e instanceof Error ? e.message : 'failed' + } finally { + loading.value = false + } + } + + async function getSession(id: string) { + const s = await acpApi.sessions.get(id) + currentSession.value = s + return s + } + + async function createSession(req: CreateSessionReq) { + const s = await acpApi.sessions.create(req) + sessions.value.unshift(s) + return s + } + + async function terminateSession(id: string) { + await acpApi.sessions.terminate(id) + const idx = sessions.value.findIndex((x) => x.id === id) + if (idx >= 0) { + sessions.value[idx] = { ...sessions.value[idx], status: 'exited' as const } + } + if (currentSession.value?.id === id) { + currentSession.value = { ...currentSession.value, status: 'exited' as const } + } + } + return { agentKinds, enabledAgentKinds, @@ -65,5 +105,11 @@ export const useAcpStore = defineStore('acp', () => { updateAgentKind, deleteAgentKind, getAgentKind, + sessions, + currentSession, + listSessions, + getSession, + createSession, + terminateSession, } })