Skip to content

Commit 58558da

Browse files
fix run commands
1 parent 26671e6 commit 58558da

File tree

4 files changed

+29
-21
lines changed

4 files changed

+29
-21
lines changed

src/SandboxClient.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { Client } from "@hey-api/client-fetch";
2-
import { createClient, createConfig } from "@hey-api/client-fetch";
32

43
import {
54
sandboxFork,
@@ -51,7 +50,13 @@ export class SandboxClient {
5150
{
5251
id: "clone-admin",
5352
permission: "write",
54-
gitAccessToken: opts.gitAccessToken,
53+
...(opts.config
54+
? {
55+
gitAccessToken: opts.config.accessToken,
56+
email: opts.config.email,
57+
name: opts.config.name,
58+
}
59+
: {}),
5560
}
5661
);
5762

@@ -63,7 +68,7 @@ export class SandboxClient {
6368
"git fetch origin",
6469
`git checkout -b ${opts.branch}`,
6570
`git reset --hard origin/${opts.branch}`,
66-
].join("&&")
71+
].join(" && ")
6772
);
6873

6974
await opts.setup?.(session);
@@ -102,8 +107,8 @@ export class SandboxClient {
102107

103108
return new Sandbox(
104109
sandbox.id,
105-
getStartResponse(sandbox.start_response),
106-
this.apiClient
110+
this.apiClient,
111+
getStartResponse(sandbox.start_response)
107112
);
108113
}
109114

@@ -139,7 +144,7 @@ export class SandboxClient {
139144
*/
140145
async resume(sandboxId: string) {
141146
const startResponse = await this.start(sandboxId);
142-
return new Sandbox(sandboxId, startResponse, this.apiClient);
147+
return new Sandbox(sandboxId, this.apiClient, startResponse);
143148
}
144149

145150
/**
@@ -168,7 +173,7 @@ export class SandboxClient {
168173
await this.shutdown(sandboxId);
169174
const startResponse = await this.start(sandboxId, opts);
170175

171-
return new Sandbox(sandboxId, startResponse, this.apiClient);
176+
return new Sandbox(sandboxId, this.apiClient, startResponse);
172177
}
173178

174179
/**

src/sandbox.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,20 @@ export class Sandbox {
3232
this.pitcherManagerResponse.pitcherVersion
3333
);
3434
}
35-
private get globalSession() {
36-
return {
35+
private defaultSession: SandboxSession;
36+
constructor(
37+
public id: string,
38+
private apiClient: Client,
39+
private pitcherManagerResponse: PitcherManagerResponse,
40+
customSession?: SandboxSession
41+
) {
42+
this.defaultSession = customSession || {
3743
sandboxId: this.id,
3844
pitcherToken: this.pitcherManagerResponse.pitcherToken,
3945
pitcherUrl: this.pitcherManagerResponse.pitcherURL,
4046
userWorkspacePath: this.pitcherManagerResponse.userWorkspacePath,
4147
};
4248
}
43-
constructor(
44-
public id: string,
45-
private pitcherManagerResponse: PitcherManagerResponse,
46-
private apiClient: Client
47-
) {}
4849

4950
/**
5051
* Updates the specs that this sandbox runs on. It will dynamically scale the sandbox to the
@@ -116,15 +117,15 @@ export class Sandbox {
116117
): Promise<WebSocketSession> {
117118
const session = customSession
118119
? await this.createSession(customSession)
119-
: this.globalSession;
120+
: this.defaultSession;
120121

121122
return WebSocketSession.init(session, this.apiClient);
122123
}
123124

124125
async createRestSession(customSession?: SessionCreateOptions) {
125126
const session = customSession
126127
? await this.createSession(customSession)
127-
: this.globalSession;
128+
: this.defaultSession;
128129

129130
return new RestSession(session);
130131
}
@@ -134,7 +135,7 @@ export class Sandbox {
134135
): Promise<SandboxBrowserSession> {
135136
const session = customSession
136137
? await this.createSession(customSession)
137-
: this.globalSession;
138+
: this.defaultSession;
138139

139140
return {
140141
id: this.id,

src/sessions/WebSocketSession/commands.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export class Commands {
5858
this.pitcherClient.workspacePath,
5959
opts?.dimensions ?? DEFAULT_SHELL_SIZE,
6060
commandWithEnv,
61-
"COMMAND",
61+
"TERMINAL",
6262
true
6363
);
6464

@@ -128,7 +128,6 @@ export class Command {
128128
if (shellId === this.id) {
129129
this.status = exitCode === 0 ? "FINISHED" : "ERROR";
130130
this.barrier.open();
131-
this.kill();
132131
}
133132
})
134133
);
@@ -138,7 +137,6 @@ export class Command {
138137
if (shellId === this.id) {
139138
this.status = "KILLED";
140139
this.barrier.open();
141-
this.kill();
142140
}
143141
})
144142
);

src/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,11 @@ export type CreateSandboxGitSourceOpts = CreateSandboxBaseOpts & {
206206
source: "git";
207207
url: string;
208208
branch: string;
209-
gitAccessToken?: string;
209+
config?: {
210+
accessToken: string;
211+
email: string;
212+
name?: string;
213+
};
210214
setup?: (session: WebSocketSession) => Promise<void>;
211215
};
212216

0 commit comments

Comments
 (0)