11import type {
2+ SandboxEnvironment ,
3+ SandboxEnvironmentInput ,
24 SignalReportArtefact ,
35 SignalReportArtefactsResponse ,
46 SignalReportSignalsResponse ,
@@ -504,6 +506,7 @@ export class PostHogAPIClient {
504506 taskId : string ,
505507 branch ?: string | null ,
506508 resumeOptions ?: { resumeFromRunId : string ; pendingUserMessage : string } ,
509+ sandboxEnvironmentId ?: string ,
507510 ) : Promise < Task > {
508511 const teamId = await this . getTeamId ( ) ;
509512 const body : Record < string , unknown > = { mode : "interactive" } ;
@@ -514,6 +517,9 @@ export class PostHogAPIClient {
514517 body . resume_from_run_id = resumeOptions . resumeFromRunId ;
515518 body . pending_user_message = resumeOptions . pendingUserMessage ;
516519 }
520+ if ( sandboxEnvironmentId ) {
521+ body . sandbox_environment_id = sandboxEnvironmentId ;
522+ }
517523
518524 const data = await this . api . post (
519525 `/api/projects/{project_id}/tasks/{id}/run/` ,
@@ -1164,4 +1170,81 @@ export class PostHogAPIClient {
11641170 return false ;
11651171 }
11661172 }
1173+
1174+ // Sandbox Environments
1175+
1176+ async listSandboxEnvironments ( ) : Promise < SandboxEnvironment [ ] > {
1177+ const teamId = await this . getTeamId ( ) ;
1178+ const url = new URL (
1179+ `${ this . api . baseUrl } /api/projects/${ teamId } /sandbox_environments/` ,
1180+ ) ;
1181+ const response = await this . api . fetcher . fetch ( {
1182+ method : "get" ,
1183+ url,
1184+ path : `/api/projects/${ teamId } /sandbox_environments/` ,
1185+ } ) ;
1186+ if ( ! response . ok ) {
1187+ throw new Error ( `Failed to fetch sandbox environments: ${ response . statusText } ` ) ;
1188+ }
1189+ const data = await response . json ( ) ;
1190+ return ( data . results ?? data ) as SandboxEnvironment [ ] ;
1191+ }
1192+
1193+ async createSandboxEnvironment (
1194+ input : SandboxEnvironmentInput ,
1195+ ) : Promise < SandboxEnvironment > {
1196+ const teamId = await this . getTeamId ( ) ;
1197+ const url = new URL (
1198+ `${ this . api . baseUrl } /api/projects/${ teamId } /sandbox_environments/` ,
1199+ ) ;
1200+ const response = await this . api . fetcher . fetch ( {
1201+ method : "post" ,
1202+ url,
1203+ path : `/api/projects/${ teamId } /sandbox_environments/` ,
1204+ overrides : {
1205+ body : JSON . stringify ( input ) ,
1206+ } ,
1207+ } ) ;
1208+ if ( ! response . ok ) {
1209+ throw new Error ( `Failed to create sandbox environment: ${ response . statusText } ` ) ;
1210+ }
1211+ return ( await response . json ( ) ) as SandboxEnvironment ;
1212+ }
1213+
1214+ async updateSandboxEnvironment (
1215+ id : string ,
1216+ input : Partial < SandboxEnvironmentInput > ,
1217+ ) : Promise < SandboxEnvironment > {
1218+ const teamId = await this . getTeamId ( ) ;
1219+ const url = new URL (
1220+ `${ this . api . baseUrl } /api/projects/${ teamId } /sandbox_environments/${ id } /` ,
1221+ ) ;
1222+ const response = await this . api . fetcher . fetch ( {
1223+ method : "patch" ,
1224+ url,
1225+ path : `/api/projects/${ teamId } /sandbox_environments/${ id } /` ,
1226+ overrides : {
1227+ body : JSON . stringify ( input ) ,
1228+ } ,
1229+ } ) ;
1230+ if ( ! response . ok ) {
1231+ throw new Error ( `Failed to update sandbox environment: ${ response . statusText } ` ) ;
1232+ }
1233+ return ( await response . json ( ) ) as SandboxEnvironment ;
1234+ }
1235+
1236+ async deleteSandboxEnvironment ( id : string ) : Promise < void > {
1237+ const teamId = await this . getTeamId ( ) ;
1238+ const url = new URL (
1239+ `${ this . api . baseUrl } /api/projects/${ teamId } /sandbox_environments/${ id } /` ,
1240+ ) ;
1241+ const response = await this . api . fetcher . fetch ( {
1242+ method : "delete" ,
1243+ url,
1244+ path : `/api/projects/${ teamId } /sandbox_environments/${ id } /` ,
1245+ } ) ;
1246+ if ( ! response . ok ) {
1247+ throw new Error ( `Failed to delete sandbox environment: ${ response . statusText } ` ) ;
1248+ }
1249+ }
11671250}
0 commit comments