11import { Api } from "coder/site/src/api/api"
22import { getErrorMessage } from "coder/site/src/api/errors"
33import { User , Workspace , WorkspaceAgent } from "coder/site/src/api/typesGenerated"
4+ import path from "node:path"
45import * as vscode from "vscode"
56import { makeCoderSdk , needToken } from "./api"
67import { extractAgents } from "./api-helper"
78import { CertificateError } from "./error"
89import { Storage } from "./storage"
910import { toRemoteAuthority , toSafeHost } from "./util"
1011import { OpenableTreeItem } from "./workspacesProvider"
11- import path from "node:path"
1212
1313export class Commands {
1414 // These will only be populated when actively connected to a workspace and are
@@ -26,7 +26,7 @@ export class Commands {
2626 private readonly vscodeProposed : typeof vscode ,
2727 private readonly restClient : Api ,
2828 private readonly storage : Storage ,
29- ) { }
29+ ) { }
3030
3131 /**
3232 * Find the requested agent if specified, otherwise return the agent if there
@@ -417,38 +417,46 @@ export class Commands {
417417 } ) : Promise < void > {
418418 // Launch and run command in terminal if command is provided
419419 if ( app . command ) {
420- return vscode . window . withProgress ( {
421- location : vscode . ProgressLocation . Notification ,
422- title : `Connecting to AI Agent...` ,
423- cancellable : false
424- } , async ( ) => {
425- const terminal = vscode . window . createTerminal ( app . name )
426-
427- // If workspace_name is provided, run coder ssh before the command
428-
429- let url = this . storage . getUrl ( )
430- if ( ! url ) {
431- throw new Error ( "No coder url found for sidebar" ) ;
432- }
433- let binary = await this . storage . fetchBinary ( this . restClient , toSafeHost ( url ) )
434- const escape = ( str : string ) : string => `"${ str . replace ( / " / g, '\\"' ) } "`
435- terminal . sendText ( `${ escape ( binary ) } ssh --global-config ${ escape (
436- path . dirname ( this . storage . getSessionTokenPath ( toSafeHost ( url ) ) ) ,
437- ) } ${ app . workspace_name } `)
438- await new Promise ( ( resolve ) => setTimeout ( resolve , 5000 ) )
439- terminal . sendText ( app . command ?? "" )
440- terminal . show ( false )
441- } ) ;
420+ return vscode . window . withProgress (
421+ {
422+ location : vscode . ProgressLocation . Notification ,
423+ title : `Connecting to AI Agent...` ,
424+ cancellable : false ,
425+ } ,
426+ async ( ) => {
427+ const terminal = vscode . window . createTerminal ( app . name )
428+
429+ // If workspace_name is provided, run coder ssh before the command
430+
431+ const url = this . storage . getUrl ( )
432+ if ( ! url ) {
433+ throw new Error ( "No coder url found for sidebar" )
434+ }
435+ const binary = await this . storage . fetchBinary ( this . restClient , toSafeHost ( url ) )
436+ const escape = ( str : string ) : string => `"${ str . replace ( / " / g, '\\"' ) } "`
437+ terminal . sendText (
438+ `${ escape ( binary ) } ssh --global-config ${ escape (
439+ path . dirname ( this . storage . getSessionTokenPath ( toSafeHost ( url ) ) ) ,
440+ ) } ${ app . workspace_name } `,
441+ )
442+ await new Promise ( ( resolve ) => setTimeout ( resolve , 5000 ) )
443+ terminal . sendText ( app . command ?? "" )
444+ terminal . show ( false )
445+ } ,
446+ )
442447 }
443448 // Check if app has a URL to open
444449 if ( app . url ) {
445- return vscode . window . withProgress ( {
446- location : vscode . ProgressLocation . Notification ,
447- title : `Opening ${ app . name || "application" } in browser...` ,
448- cancellable : false
449- } , async ( ) => {
450- await vscode . env . openExternal ( vscode . Uri . parse ( app . url ! ) )
451- } ) ;
450+ return vscode . window . withProgress (
451+ {
452+ location : vscode . ProgressLocation . Notification ,
453+ title : `Opening ${ app . name || "application" } in browser...` ,
454+ cancellable : false ,
455+ } ,
456+ async ( ) => {
457+ await vscode . env . openExternal ( vscode . Uri . parse ( app . url ! ) )
458+ } ,
459+ )
452460 }
453461
454462 // If no URL or command, show information about the app status
0 commit comments