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 {
|
import {
|
||||||
acpApi,
|
acpApi,
|
||||||
isAgentKindAdmin,
|
isAgentKindAdmin,
|
||||||
|
type AcpSession,
|
||||||
type AgentKindAdmin,
|
type AgentKindAdmin,
|
||||||
type AgentKindPublic,
|
type AgentKindPublic,
|
||||||
type CreateAgentKindReq,
|
type CreateAgentKindReq,
|
||||||
|
type CreateSessionReq,
|
||||||
type UpdateAgentKindReq,
|
type UpdateAgentKindReq,
|
||||||
} from '@/api/acp'
|
} from '@/api/acp'
|
||||||
|
|
||||||
@@ -16,6 +18,9 @@ export const useAcpStore = defineStore('acp', () => {
|
|||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const error = ref<string | null>(null)
|
const error = ref<string | null>(null)
|
||||||
|
|
||||||
|
const sessions = ref<AcpSession[]>([])
|
||||||
|
const currentSession = ref<AcpSession | null>(null)
|
||||||
|
|
||||||
async function listAgentKinds(asAdmin: boolean) {
|
async function listAgentKinds(asAdmin: boolean) {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
error.value = null
|
error.value = null
|
||||||
@@ -55,6 +60,41 @@ export const useAcpStore = defineStore('acp', () => {
|
|||||||
return acpApi.agentKinds.get(id)
|
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 {
|
return {
|
||||||
agentKinds,
|
agentKinds,
|
||||||
enabledAgentKinds,
|
enabledAgentKinds,
|
||||||
@@ -65,5 +105,11 @@ export const useAcpStore = defineStore('acp', () => {
|
|||||||
updateAgentKind,
|
updateAgentKind,
|
||||||
deleteAgentKind,
|
deleteAgentKind,
|
||||||
getAgentKind,
|
getAgentKind,
|
||||||
|
sessions,
|
||||||
|
currentSession,
|
||||||
|
listSessions,
|
||||||
|
getSession,
|
||||||
|
createSession,
|
||||||
|
terminateSession,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user