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,89 @@ 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 (
1188+ `Failed to fetch sandbox environments: ${ response . statusText } ` ,
1189+ ) ;
1190+ }
1191+ const data = await response . json ( ) ;
1192+ return ( data . results ?? data ) as SandboxEnvironment [ ] ;
1193+ }
1194+
1195+ async createSandboxEnvironment (
1196+ input : SandboxEnvironmentInput ,
1197+ ) : Promise < SandboxEnvironment > {
1198+ const teamId = await this . getTeamId ( ) ;
1199+ const url = new URL (
1200+ `${ this . api . baseUrl } /api/projects/${ teamId } /sandbox_environments/` ,
1201+ ) ;
1202+ const response = await this . api . fetcher . fetch ( {
1203+ method : "post" ,
1204+ url,
1205+ path : `/api/projects/${ teamId } /sandbox_environments/` ,
1206+ overrides : {
1207+ body : JSON . stringify ( input ) ,
1208+ } ,
1209+ } ) ;
1210+ if ( ! response . ok ) {
1211+ throw new Error (
1212+ `Failed to create sandbox environment: ${ response . statusText } ` ,
1213+ ) ;
1214+ }
1215+ return ( await response . json ( ) ) as SandboxEnvironment ;
1216+ }
1217+
1218+ async updateSandboxEnvironment (
1219+ id : string ,
1220+ input : Partial < SandboxEnvironmentInput > ,
1221+ ) : Promise < SandboxEnvironment > {
1222+ const teamId = await this . getTeamId ( ) ;
1223+ const url = new URL (
1224+ `${ this . api . baseUrl } /api/projects/${ teamId } /sandbox_environments/${ id } /` ,
1225+ ) ;
1226+ const response = await this . api . fetcher . fetch ( {
1227+ method : "patch" ,
1228+ url,
1229+ path : `/api/projects/${ teamId } /sandbox_environments/${ id } /` ,
1230+ overrides : {
1231+ body : JSON . stringify ( input ) ,
1232+ } ,
1233+ } ) ;
1234+ if ( ! response . ok ) {
1235+ throw new Error (
1236+ `Failed to update sandbox environment: ${ response . statusText } ` ,
1237+ ) ;
1238+ }
1239+ return ( await response . json ( ) ) as SandboxEnvironment ;
1240+ }
1241+
1242+ async deleteSandboxEnvironment ( id : string ) : Promise < void > {
1243+ const teamId = await this . getTeamId ( ) ;
1244+ const url = new URL (
1245+ `${ this . api . baseUrl } /api/projects/${ teamId } /sandbox_environments/${ id } /` ,
1246+ ) ;
1247+ const response = await this . api . fetcher . fetch ( {
1248+ method : "delete" ,
1249+ url,
1250+ path : `/api/projects/${ teamId } /sandbox_environments/${ id } /` ,
1251+ } ) ;
1252+ if ( ! response . ok ) {
1253+ throw new Error (
1254+ `Failed to delete sandbox environment: ${ response . statusText } ` ,
1255+ ) ;
1256+ }
1257+ }
11671258}
0 commit comments