You've already forked agentic-coding-workflow
feat(web): acp store sessions state + actions
This commit is contained in:
@@ -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<string | null>(null)
|
||||
|
||||
const sessions = ref<AcpSession[]>([])
|
||||
const currentSession = ref<AcpSession | null>(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,
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user