File tree Expand file tree Collapse file tree 5 files changed +36
-5
lines changed
sessions/WebSocketSession Expand file tree Collapse file tree 5 files changed +36
-5
lines changed Original file line number Diff line number Diff line change @@ -103,7 +103,7 @@ export class Sandbox {
103103 opts : SessionCreateOptions
104104 ) : Promise < SandboxSession > {
105105 if ( opts . id . length > 20 ) {
106- throw new Error ( "Session ID must be 32 characters or less" ) ;
106+ throw new Error ( "Session ID must be 20 characters or less" ) ;
107107 }
108108
109109 const response = await vmCreateSession ( {
@@ -208,6 +208,10 @@ export class Sandbox {
208208 ) ;
209209
210210 return new WebSocketSession ( pitcherClient , {
211+ username : customSession
212+ ? // @ts -ignore
213+ pitcherClient [ "joinResult" ] . client . username
214+ : undefined ,
211215 env : customSession ?. env ,
212216 hostToken : customSession ?. hostToken ,
213217 } ) ;
@@ -237,6 +241,7 @@ export class Sandbox {
237241 return {
238242 id : this . id ,
239243 env : customSession ?. env ,
244+ sessionId : customSession ?. id ,
240245 hostToken : customSession ?. hostToken ,
241246 bootupType : this . bootupType ,
242247 cluster : this . cluster ,
Original file line number Diff line number Diff line change @@ -46,6 +46,10 @@ export async function connectToSandbox(options: {
4646 ) ;
4747
4848 return new WebSocketSession ( pitcherClient , {
49+ username : options . session . sessionId
50+ ? // @ts -ignore
51+ pitcherClient [ "joinResult" ] . client . username
52+ : undefined ,
4953 env : options . session . env ,
5054 hostToken : options . session . hostToken ,
5155 } ) ;
Original file line number Diff line number Diff line change @@ -42,7 +42,8 @@ export class FileSystem {
4242 private disposable = new Disposable ( ) ;
4343 constructor (
4444 sessionDisposable : Disposable ,
45- private pitcherClient : IPitcherClient
45+ private pitcherClient : IPitcherClient ,
46+ private username ?: string
4647 ) {
4748 sessionDisposable . onWillDispose ( ( ) => {
4849 this . disposable . dispose ( ) ;
@@ -212,7 +213,18 @@ export class FileSystem {
212213 const result = await this . pitcherClient . clients . fs . watch (
213214 path ,
214215 options ,
215- ( event ) => emitter . fire ( event )
216+ ( event ) => {
217+ if ( this . username ) {
218+ emitter . fire ( {
219+ ...event ,
220+ paths : event . paths . map ( ( path ) =>
221+ path . replace ( `home/${ this . username } /workspace/` , "sandbox/" )
222+ ) ,
223+ } ) ;
224+ } else {
225+ emitter . fire ( event ) ;
226+ }
227+ }
216228 ) ;
217229
218230 if ( result . type === "error" ) {
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ export class WebSocketSession {
3131 /**
3232 * Namespace for all filesystem operations on this Sandbox
3333 */
34- public readonly fs = new FileSystem ( this . disposable , this . pitcherClient ) ;
34+ public readonly fs : FileSystem ;
3535
3636 /**
3737 * Namespace for hosts
@@ -75,7 +75,15 @@ export class WebSocketSession {
7575
7676 constructor (
7777 protected pitcherClient : IPitcherClient ,
78- { env, hostToken } : { env ?: Record < string , string > ; hostToken ?: HostToken }
78+ {
79+ env,
80+ hostToken,
81+ username,
82+ } : {
83+ env ?: Record < string , string > ;
84+ hostToken ?: HostToken ;
85+ username ?: string ;
86+ }
7987 ) {
8088 // TODO: Bring this back once metrics polling does not reset inactivity
8189 // const metricsDisposable = {
@@ -84,6 +92,7 @@ export class WebSocketSession {
8492 // };
8593
8694 // this.addDisposable(metricsDisposable);
95+ this . fs = new FileSystem ( this . disposable , this . pitcherClient , username ) ;
8796 this . terminals = new Terminals ( this . disposable , this . pitcherClient , env ) ;
8897 this . commands = new Commands ( this . disposable , this . pitcherClient , env ) ;
8998
Original file line number Diff line number Diff line change @@ -237,6 +237,7 @@ export type SandboxOpts = {
237237
238238export type SandboxBrowserSession = PitcherManagerResponse & {
239239 id : string ;
240+ sessionId ?: string ;
240241 env ?: Record < string , string > ;
241242 hostToken ?: HostToken ;
242243} ;
You can’t perform that action at this time.
0 commit comments