Skip to content

feat: multiple agent support #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 28, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 48 additions & 4 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export class Commands {
public async open(...args: string[]): Promise<void> {
let workspaceOwner: string
let workspaceName: string
let workspaceAgent: string
let folderPath: string | undefined

if (args.length === 0) {
Expand Down Expand Up @@ -158,24 +159,67 @@ export class Commands {
workspaceOwner = workspace.owner_name
workspaceName = workspace.name

// TODO: multiple agent support
const agents = workspace.latest_build.resources.reduce((acc, resource) => {
return acc.concat(resource.agents || [])
}, [] as WorkspaceAgent[])

if (agents.length === 1) {
folderPath = agents[0].expanded_directory
}
workspaceAgent = agents[0].name
}else{
const agentQuickPick = vscode.window.createQuickPick()
let lastAgents: WorkspaceAgent[]
agentQuickPick.title = `Connect to a agent`;

agentQuickPick.busy = true;
lastAgents = agents
const agentItems: vscode.QuickPickItem[] = agents.map((agent) => {
let icon = "$(debug-start)"
if (agent.status !== "connected") {
icon = "$(debug-stop)"
}
return {
alwaysShow: true,
label: `${icon} ${agent.name}`,
detail: `${agent.name} • Status: ${agent.status}`,
}
})
agentQuickPick.items = agentItems
agentQuickPick.busy = false
agentQuickPick.show()

const agent = await new Promise<WorkspaceAgent | undefined>((resolve) => {
agentQuickPick.onDidHide(() => {
resolve(undefined)
})
agentQuickPick.onDidChangeSelection((selected) => {
if (selected.length < 1) {
return resolve(undefined)
}
const agent = lastAgents[agentQuickPick.items.indexOf(selected[0])]
resolve(agent)
})
})

if(agent != undefined){
folderPath = agent.expanded_directory
workspaceAgent = agent.name
}else{
folderPath = ''
workspaceAgent = ''
}
}

} else {
workspaceOwner = args[0]
workspaceName = args[1]
// workspaceAgent is reserved for args[2], but multiple agents aren't supported yet.
workspaceAgent = args[2]
folderPath = args[3]
}

// A workspace can have multiple agents, but that's handled
// when opening a workspace unless explicitly specified.
const remoteAuthority = `ssh-remote+${Remote.Prefix}${workspaceOwner}--${workspaceName}`
const remoteAuthority = `ssh-remote+${Remote.Prefix}${workspaceOwner}--${workspaceName}--${workspaceAgent}`

let newWindow = true
// Open in the existing window if no workspaces are open.
Expand Down