@@ -54,6 +54,39 @@ export interface RemoteSessionMetadata extends BaseSessionMetadata {
5454 remoteId : string ;
5555}
5656
57+ export interface AgentSessionMetadata {
58+ createdBy : string ;
59+ github_repo : string ;
60+ organizationId ?: string ;
61+ idempotencyKey ?: string ;
62+ source ?: string ;
63+ continueApiKeyId ?: string ;
64+ s3Url ?: string ;
65+ prompt ?: string | null ;
66+ createdBySlug ?: string ;
67+ }
68+
69+ export interface AgentSessionView {
70+ id : string ;
71+ devboxId : string | null ;
72+ name : string | null ;
73+ icon : string | null ;
74+ status : string ;
75+ agentStatus : string | null ;
76+ unread : boolean ;
77+ state : string ;
78+ metadata : AgentSessionMetadata ;
79+ repoUrl : string ;
80+ branch : string | null ;
81+ pullRequestUrl : string | null ;
82+ pullRequestStatus : string | null ;
83+ tunnelUrl : string | null ;
84+ createdAt : string ;
85+ updatedAt : string ;
86+ create_time_ms : string ;
87+ end_time_ms : string ;
88+ }
89+
5790export class ControlPlaneClient {
5891 constructor (
5992 readonly sessionInfoPromise : Promise < ControlPlaneSessionInfo | undefined > ,
@@ -545,23 +578,19 @@ export class ControlPlaneClient {
545578 } ) ;
546579
547580 const result = ( await resp . json ( ) ) as {
548- agents : any [ ] ;
581+ agents : AgentSessionView [ ] ;
549582 totalCount : number ;
550583 } ;
551584
552585 return {
553- agents : result . agents . map ( ( agent : any ) => ( {
586+ agents : result . agents . map ( ( agent ) => ( {
554587 id : agent . id ,
555- name : agent . name || agent . metadata ?. name || null ,
588+ name : agent . name ,
556589 status : agent . status ,
557- repoUrl : agent . metadata ?. repo_url || agent . repo_url || "" ,
558- createdAt :
559- agent . created_at || agent . create_time_ms
560- ? new Date ( agent . created_at || agent . create_time_ms ) . toISOString ( )
561- : new Date ( ) . toISOString ( ) ,
590+ repoUrl : agent . repoUrl ,
591+ createdAt : agent . createdAt ,
562592 metadata : {
563- github_repo :
564- agent . metadata ?. github_repo || agent . metadata ?. repo_url ,
593+ github_repo : agent . metadata . github_repo ,
565594 } ,
566595 } ) ) ,
567596 totalCount : result . totalCount ,
@@ -573,4 +602,73 @@ export class ControlPlaneClient {
573602 return { agents : [ ] , totalCount : 0 } ;
574603 }
575604 }
605+
606+ /**
607+ * Get the full agent session information
608+ * @param agentSessionId - The ID of the agent session
609+ * @returns The agent session view including metadata and status
610+ */
611+ public async getAgentSession (
612+ agentSessionId : string ,
613+ ) : Promise < AgentSessionView | null > {
614+ if ( ! ( await this . isSignedIn ( ) ) ) {
615+ return null ;
616+ }
617+
618+ try {
619+ const resp = await this . requestAndHandleError (
620+ `agents/${ agentSessionId } ` ,
621+ {
622+ method : "GET" ,
623+ } ,
624+ ) ;
625+
626+ return ( await resp . json ( ) ) as AgentSessionView ;
627+ } catch ( e ) {
628+ Logger . error ( e , {
629+ context : "control_plane_get_agent_session" ,
630+ agentSessionId,
631+ } ) ;
632+ return null ;
633+ }
634+ }
635+
636+ /**
637+ * Get the state of a specific background agent
638+ * @param agentSessionId - The ID of the agent session
639+ * @returns The agent's session state including history, workspace, and branch
640+ */
641+ public async getAgentState ( agentSessionId : string ) : Promise < {
642+ session : Session ;
643+ isProcessing : boolean ;
644+ messageQueueLength : number ;
645+ pendingPermission : any ;
646+ } | null > {
647+ if ( ! ( await this . isSignedIn ( ) ) ) {
648+ return null ;
649+ }
650+
651+ try {
652+ const resp = await this . requestAndHandleError (
653+ `agents/${ agentSessionId } /state` ,
654+ {
655+ method : "GET" ,
656+ } ,
657+ ) ;
658+
659+ const result = ( await resp . json ( ) ) as {
660+ session : Session ;
661+ isProcessing : boolean ;
662+ messageQueueLength : number ;
663+ pendingPermission : any ;
664+ } ;
665+ return result ;
666+ } catch ( e ) {
667+ Logger . error ( e , {
668+ context : "control_plane_get_agent_state" ,
669+ agentSessionId,
670+ } ) ;
671+ return null ;
672+ }
673+ }
576674}
0 commit comments