|
1 | 1 | import { AxiosInstance } from "axios"
|
2 | 2 | import { spawn } from "child_process"
|
3 | 3 | import { Api } from "coder/site/src/api/api"
|
4 |
| -import { ProvisionerJobLog, Workspace } from "coder/site/src/api/typesGenerated" |
| 4 | +import { ProvisionerJobLog, Workspace, WorkspaceAgent } from "coder/site/src/api/typesGenerated" |
5 | 5 | import { FetchLikeInit } from "eventsource"
|
6 | 6 | import fs from "fs/promises"
|
7 | 7 | import { ProxyAgent } from "proxy-agent"
|
@@ -276,3 +276,45 @@ export async function waitForBuild(
|
276 | 276 | writeEmitter.fire(`Workspace is now ${updatedWorkspace.latest_build.status}\r\n`)
|
277 | 277 | return updatedWorkspace
|
278 | 278 | }
|
| 279 | + |
| 280 |
8000
+// 1. First, get a workspace by owner and name |
| 281 | +export async function getAITasksForWorkspace( |
| 282 | + restClient: Api, |
| 283 | + writeEmitter: vscode.EventEmitter<string>, |
| 284 | + workspace: Workspace, |
| 285 | +) { |
| 286 | + |
| 287 | + // The workspace will include agents, and within each agent you can find tasks |
| 288 | + // You can access the agents from the workspace resource |
| 289 | + const resources = workspace.latest_build.resources; |
| 290 | + |
| 291 | + // Go through each resource |
| 292 | + for (const resource of resources) { |
| 293 | + // Each resource can have multiple agents |
| 294 | + if (!resource.agents) { |
| 295 | + continue |
| 296 | + } |
| 297 | + |
| 298 | + for (const agent of resource.agents) { |
| 299 | + // Check if this agent has any AI tasks |
| 300 | + if (agent.tasks && agent.tasks.length > 0) { |
| 301 | + // This agent has AI tasks! |
| 302 | + console.log(`Agent ${agent.name} (${agent.id}) has ${agent.tasks.length} tasks`); |
| 303 | + |
| 304 | + // Examine task details |
| 305 | + for (const task of agent.tasks) { |
| 306 | + console.log(`Task: ${task.summary}`); |
| 307 | + console.log(`Reporter: ${task.reporter}`); |
| 308 | + console.log(`Status: ${task.completion ? 'Completed' : 'In Progress'}`); |
| 309 | + console.log(`URL: ${task.url}`); |
| 310 | + console.log(`Icon: ${task.icon}`); |
| 311 | + } |
| 312 | + |
| 313 | + // Check if the agent is waiting for user input |
| 314 | + if (agent.task_waiting_for_user_input) { |
| 315 | + console.log("This agent is waiting for user input!"); |
| 316 | + } |
| 317 | + } |
| 318 | + } |
| 319 | + } |
| 320 | +} |
0 commit comments