mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
feat: add app status tracking to the backend (#17163)
This does ~95% of the backend work required to integrate the AI work. Most left to integrate from the tasks branch is just frontend, which will be a lot smaller I believe. The real difference between this branch and that one is the abstraction -- this now attaches statuses to apps, and returns the latest status reported as part of a workspace. This change enables us to have a similar UX to in the tasks branch, but for agents other than Claude Code as well. Any app can report status now.
This commit is contained in:
@ -487,7 +487,7 @@ func AppSubdomain(dbApp database.WorkspaceApp, agentName, workspaceName, ownerNa
|
||||
}.String()
|
||||
}
|
||||
|
||||
func Apps(dbApps []database.WorkspaceApp, agent database.WorkspaceAgent, ownerName string, workspace database.Workspace) []codersdk.WorkspaceApp {
|
||||
func Apps(dbApps []database.WorkspaceApp, statuses []database.WorkspaceAppStatus, agent database.WorkspaceAgent, ownerName string, workspace database.Workspace) []codersdk.WorkspaceApp {
|
||||
sort.Slice(dbApps, func(i, j int) bool {
|
||||
if dbApps[i].DisplayOrder != dbApps[j].DisplayOrder {
|
||||
return dbApps[i].DisplayOrder < dbApps[j].DisplayOrder
|
||||
@ -498,8 +498,14 @@ func Apps(dbApps []database.WorkspaceApp, agent database.WorkspaceAgent, ownerNa
|
||||
return dbApps[i].Slug < dbApps[j].Slug
|
||||
})
|
||||
|
||||
statusesByAppID := map[uuid.UUID][]database.WorkspaceAppStatus{}
|
||||
for _, status := range statuses {
|
||||
statusesByAppID[status.AppID] = append(statusesByAppID[status.AppID], status)
|
||||
}
|
||||
|
||||
apps := make([]codersdk.WorkspaceApp, 0)
|
||||
for _, dbApp := range dbApps {
|
||||
statuses := statusesByAppID[dbApp.ID]
|
||||
apps = append(apps, codersdk.WorkspaceApp{
|
||||
ID: dbApp.ID,
|
||||
URL: dbApp.Url.String,
|
||||
@ -516,14 +522,33 @@ func Apps(dbApps []database.WorkspaceApp, agent database.WorkspaceAgent, ownerNa
|
||||
Interval: dbApp.HealthcheckInterval,
|
||||
Threshold: dbApp.HealthcheckThreshold,
|
||||
},
|
||||
Health: codersdk.WorkspaceAppHealth(dbApp.Health),
|
||||
Hidden: dbApp.Hidden,
|
||||
OpenIn: codersdk.WorkspaceAppOpenIn(dbApp.OpenIn),
|
||||
Health: codersdk.WorkspaceAppHealth(dbApp.Health),
|
||||
Hidden: dbApp.Hidden,
|
||||
OpenIn: codersdk.WorkspaceAppOpenIn(dbApp.OpenIn),
|
||||
Statuses: WorkspaceAppStatuses(statuses),
|
||||
})
|
||||
}
|
||||
return apps
|
||||
}
|
||||
|
||||
func WorkspaceAppStatuses(statuses []database.WorkspaceAppStatus) []codersdk.WorkspaceAppStatus {
|
||||
return List(statuses, WorkspaceAppStatus)
|
||||
}
|
||||
|
||||
func WorkspaceAppStatus(status database.WorkspaceAppStatus) codersdk.WorkspaceAppStatus {
|
||||
return codersdk.WorkspaceAppStatus{
|
||||
ID: status.ID,
|
||||
CreatedAt: status.CreatedAt,
|
||||
AgentID: status.AgentID,
|
||||
AppID: status.AppID,
|
||||
NeedsUserAttention: status.NeedsUserAttention,
|
||||
URI: status.Uri.String,
|
||||
Icon: status.Icon.String,
|
||||
Message: status.Message,
|
||||
State: codersdk.WorkspaceAppStatusState(status.State),
|
||||
}
|
||||
}
|
||||
|
||||
func ProvisionerDaemon(dbDaemon database.ProvisionerDaemon) codersdk.ProvisionerDaemon {
|
||||
result := codersdk.ProvisionerDaemon{
|
||||
ID: dbDaemon.ID,
|
||||
|
Reference in New Issue
Block a user