Skip to content

Commit 4376586

Browse files
chore: add fields to codersdk.Task (coder#19619)
Closes coder/internal#949 Adds the following fields to `codersdk.Task` - OwnerName - TemplateName - TemplateDisplayName - TemplateIcon - WorkspaceAgentID - WorkspaceAgentLifecycle - WorkspaceAgentHealth The implementation is unfortunately not compatible with multiple agents as we have no reliable way to tell which agent has the AI task running in it. For now we just pick the first agent found, but in the future this will need to be changed.
1 parent c095e9c commit 4376586

File tree

4 files changed

+67
-22
lines changed

4 files changed

+67
-22
lines changed

cli/exp_task_status_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,16 @@ STATE CHANGED STATUS STATE MESSAGE
188188
"id": "11111111-1111-1111-1111-111111111111",
189189
"organization_id": "00000000-0000-0000-0000-000000000000",
190190
"owner_id": "00000000-0000-0000-0000-000000000000",
191+
"owner_name": "",
191192
"name": "",
192193
"template_id": "00000000-0000-0000-0000-000000000000",
194+
"template_name": "",
195+
"template_display_name": "",
196+
"template_icon": "",
193197
"workspace_id": null,
198+
"workspace_agent_id": null,
199+
"workspace_agent_lifecycle": null,
200+
"workspace_agent_health": null,
194201
"initial_prompt": "",
195202
"status": "running",
196203
"current_state": {

coderd/aitasks.go

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,22 @@ func (api *API) tasksFromWorkspaces(ctx context.Context, apiWorkspaces []codersd
213213

214214
tasks := make([]codersdk.Task, 0, len(apiWorkspaces))
215215
for _, ws := range apiWorkspaces {
216+
// TODO(DanielleMaywood):
217+
// This just picks up the first agent it discovers.
218+
// This approach _might_ break when a task has multiple agents,
219+
// depending on which agent was found first.
220+
var taskAgentID uuid.NullUUID
221+
var taskAgentLifecycle *codersdk.WorkspaceAgentLifecycle
222+
var taskAgentHealth *codersdk.WorkspaceAgentHealth
223+
for _, resource := range ws.LatestBuild.Resources {
224+
for _, agent := range resource.Agents {
225+
taskAgentID = uuid.NullUUID{Valid: true, UUID: agent.ID}
226+
taskAgentLifecycle = &agent.LifecycleState
227+
taskAgentHealth = &agent.Health
228+
break
229+
}
230+
}
231+
216232
var currentState *codersdk.TaskStateEntry
217233
if ws.LatestAppStatus != nil {
218234
currentState = &codersdk.TaskStateEntry{
@@ -222,18 +238,26 @@ func (api *API) tasksFromWorkspaces(ctx context.Context, apiWorkspaces []codersd
222238
URI: ws.LatestAppStatus.URI,
223239
}
224240
}
241+
225242
tasks = append(tasks, codersdk.Task{
226-
ID: ws.ID,
227-
OrganizationID: ws.OrganizationID,
228-
OwnerID: ws.OwnerID,
229-
Name: ws.Name,
230-
TemplateID: ws.TemplateID,
231-
WorkspaceID: uuid.NullUUID{Valid: true, UUID: ws.ID},
232-
CreatedAt: ws.CreatedAt,
233-
UpdatedAt: ws.UpdatedAt,
234-
InitialPrompt: promptsByBuildID[ws.LatestBuild.ID],
235-
Status: ws.LatestBuild.Status,
236-
CurrentState: currentState,
243+
ID: ws.ID,
244+
OrganizationID: ws.OrganizationID,
245+
OwnerID: ws.OwnerID,
246+
OwnerName: ws.OwnerName,
247+
Name: ws.Name,
248+
TemplateID: ws.TemplateID,
249+
TemplateName: ws.TemplateName,
250+
TemplateDisplayName: ws.TemplateDisplayName,
251+
TemplateIcon: ws.TemplateIcon,
252+
WorkspaceID: uuid.NullUUID{Valid: true, UUID: ws.ID},
253+
WorkspaceAgentID: taskAgentID,
254+
WorkspaceAgentLifecycle: taskAgentLifecycle,
255+
WorkspaceAgentHealth: taskAgentHealth,
256+
CreatedAt: ws.CreatedAt,
257+
UpdatedAt: ws.UpdatedAt,
258+
InitialPrompt: promptsByBuildID[ws.LatestBuild.ID],
259+
Status: ws.LatestBuild.Status,
260+
CurrentState: currentState,
237261
})
238262
}
239263

codersdk/aitasks.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,24 @@ const (
8888
//
8989
// Experimental: This type is experimental and may change in the future.
9090
type Task struct {
91-
ID uuid.UUID `json:"id" format:"uuid" table:"id"`
92-
OrganizationID uuid.UUID `json:"organization_id" format:"uuid" table:"organization id"`
93-
OwnerID uuid.UUID `json:"owner_id" format:"uuid" table:"owner id"`
94-
Name string `json:"name" table:"name,default_sort"`
95-
TemplateID uuid.UUID `json:"template_id" format:"uuid" table:"template id"`
96-
WorkspaceID uuid.NullUUID `json:"workspace_id" format:"uuid" table:"workspace id"`
97-
InitialPrompt string `json:"initial_prompt" table:"initial prompt"`
98-
Status WorkspaceStatus `json:"status" enums:"pending,starting,running,stopping,stopped,failed,canceling,canceled,deleting,deleted" table:"status"`
99-
CurrentState *TaskStateEntry `json:"current_state" table:"cs,recursive_inline"`
100-
CreatedAt time.Time `json:"created_at" format:"date-time" table:"created at"`
101-
UpdatedAt time.Time `json:"updated_at" format:"date-time" table:"updated at"`
91+
ID uuid.UUID `json:"id" format:"uuid" table:"id"`
92+
OrganizationID uuid.UUID `json:"organization_id" format:"uuid" table:"organization id"`
93+
OwnerID uuid.UUID `json:"owner_id" format:"uuid" table:"owner id"`
94+
OwnerName string `json:"owner_name" table:"owner name"`
95+
Name string `json:"name" table:"name,default_sort"`
96+
TemplateID uuid.UUID `json:"template_id" format:"uuid" table:"template id"`
97+
TemplateName string `json:"template_name" table:"template name"`
98+
TemplateDisplayName string `json:"template_display_name" table:"template display name"`
99+
TemplateIcon string `json:"template_icon" table:"template icon"`
100+
WorkspaceID uuid.NullUUID `json:"workspace_id" format:"uuid" table:"workspace id"`
101+
WorkspaceAgentID uuid.NullUUID `json:"workspace_agent_id" format:"uuid" table:"workspace agent id"`
102+
WorkspaceAgentLifecycle *WorkspaceAgentLifecycle `json:"workspace_agent_lifecycle" table:"workspace agent lifecycle"`
103+
WorkspaceAgentHealth *WorkspaceAgentHealth `json:"workspace_agent_health" table:"workspace agent health"`
104+
InitialPrompt string `json:"initial_prompt" table:"initial prompt"`
105+
Status WorkspaceStatus `json:"status" enums:"pending,starting,running,stopping,stopped,failed,canceling,canceled,deleting,deleted" table:"status"`
106+
CurrentState *TaskStateEntry `json:"current_state" table:"cs,recursive_inline"`
107+
CreatedAt time.Time `json:"created_at" format:"date-time" table:"created at"`
108+
UpdatedAt time.Time `json:"updated_at" format:"date-time" table:"updated at"`
102109
}
103110

104111
// TaskStateEntry represents a single entry in the task's state history.

site/src/api/typesGenerated.ts

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)