feat(acp): handler refactor + sessions REST endpoints (list/create/get/delete/events)

This commit is contained in:
2026-05-07 14:34:47 +08:00
parent 26011975b4
commit 72cd353757
4 changed files with 232 additions and 9 deletions
+66
View File
@@ -46,3 +46,69 @@ type UpdateAgentKindReq struct {
Env map[string]string `json:"env,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
}
// CreateSessionReq is the request body for POST /api/v1/acp/sessions.
type CreateSessionReq struct {
WorkspaceID string `json:"workspace_id"`
AgentKindID string `json:"agent_kind_id"`
Branch *string `json:"branch,omitempty"`
IssueNumber *int `json:"issue_number,omitempty"`
RequirementNumber *int `json:"requirement_number,omitempty"`
InitialPrompt *string `json:"initial_prompt,omitempty"`
}
// SessionDTO is the response shape for sessions.
type SessionDTO struct {
ID string `json:"id"`
WorkspaceID string `json:"workspace_id"`
ProjectID string `json:"project_id"`
AgentKindID string `json:"agent_kind_id"`
UserID string `json:"user_id"`
IssueID *string `json:"issue_id"`
RequirementID *string `json:"requirement_id"`
AgentSessionID *string `json:"agent_session_id"`
Branch string `json:"branch"`
CwdPath string `json:"cwd_path"`
IsMainWorktree bool `json:"is_main_worktree"`
Status string `json:"status"`
PID *int32 `json:"pid"`
ExitCode *int32 `json:"exit_code"`
LastError *string `json:"last_error"`
StartedAt string `json:"started_at"`
EndedAt *string `json:"ended_at"`
}
func sessionToDTO(s *Session) SessionDTO {
var issueID, reqID, ended *string
if s.IssueID != nil {
v := s.IssueID.String()
issueID = &v
}
if s.RequirementID != nil {
v := s.RequirementID.String()
reqID = &v
}
if s.EndedAt != nil {
v := s.EndedAt.UTC().Format("2006-01-02T15:04:05Z")
ended = &v
}
return SessionDTO{
ID: s.ID.String(),
WorkspaceID: s.WorkspaceID.String(),
ProjectID: s.ProjectID.String(),
AgentKindID: s.AgentKindID.String(),
UserID: s.UserID.String(),
IssueID: issueID,
RequirementID: reqID,
AgentSessionID: s.AgentSessionID,
Branch: s.Branch,
CwdPath: s.CwdPath,
IsMainWorktree: s.IsMainWorktree,
Status: string(s.Status),
PID: s.PID,
ExitCode: s.ExitCode,
LastError: s.LastError,
StartedAt: s.StartedAt.UTC().Format("2006-01-02T15:04:05Z"),
EndedAt: ended,
}
}