Skip to content

Commit 7633e32

Browse files
build(deps): bump @codesandbox/sdk from 0.6.2 to 2.2.0 (#1652)
* build(deps): bump @codesandbox/sdk from 0.6.2 to 2.2.0 Bumps [@codesandbox/sdk](https://github.com/codesandbox/codesandbox-sdk) from 0.6.2 to 2.2.0. - [Release notes](https://github.com/codesandbox/codesandbox-sdk/releases) - [Changelog](https://github.com/codesandbox/codesandbox-sdk/blob/main/CHANGELOG.md) - [Commits](codesandbox/codesandbox-sdk@v0.6.2...v2.2.0) --- updated-dependencies: - dependency-name: "@codesandbox/sdk" dependency-version: 2.2.0 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * chore: adapt code to new sandbox version --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Gerard <clos.gerard@gmail.com>
1 parent 546cadc commit 7633e32

File tree

7 files changed

+1143
-212
lines changed

7 files changed

+1143
-212
lines changed

apps/gateway/src/presenters/documentPresenter.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ export function documentPresenterWithProviderAndMetadata({
4040
const parameters =
4141
rawParams.length > 0
4242
? rawParams.reduce(
43-
(acc, rawParam) => {
44-
if (acc[rawParam]) return acc
45-
acc[rawParam] = { type: ParameterType.Text }
43+
(acc, rawParam) => {
44+
if (acc[rawParam]) return acc
45+
acc[rawParam] = { type: ParameterType.Text }
4646

47-
return acc
48-
},
49-
{ ...configParams },
50-
)
47+
return acc
48+
},
49+
{ ...configParams },
50+
)
5151
: configParams
5252

5353
return {

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
"@aws-sdk/client-s3": "3.850.0",
145145
"@aws-sdk/s3-request-presigner": "3.850.0",
146146
"@google-cloud/storage": "^7.7.0",
147-
"@codesandbox/sdk": "0.6.2",
147+
"@codesandbox/sdk": "2.2.1",
148148
"@kubernetes/client-node": "1.0.0",
149149
"@latitude-data/compiler": "workspace:^",
150150
"@latitude-data/constants": "workspace:*",

packages/core/src/services/latitudeTools/runCode/sandbox.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ async function createSandbox() {
1818
return Result.error(new BadRequestError('CODESANDBOX_API_KEY is not set'))
1919
}
2020
const sdk = new CodeSandbox(env.CODESANDBOX_API_KEY)
21-
const sandbox = await sdk.sandbox.create()
22-
return Result.ok(sandbox)
21+
const sandbox = await sdk.sandboxes.create()
22+
return Result.ok({ sandbox, sdk })
2323
} catch (error) {
2424
return Result.error(error as LatitudeError)
2525
}
@@ -34,7 +34,7 @@ export const withSafeSandbox = async <
3434
): Promise<T> => {
3535
const sandboxResult = await createSandbox()
3636
if (sandboxResult.error) throw sandboxResult.error
37-
const sandbox = sandboxResult.unwrap()
37+
const { sandbox, sdk } = sandboxResult.unwrap()
3838

3939
const timeoutPromise = new Promise<T>((resolve) => {
4040
setTimeout(() => {
@@ -51,6 +51,6 @@ export const withSafeSandbox = async <
5151
} catch (error) {
5252
return Result.error(error as LatitudeError) as T
5353
} finally {
54-
sandbox.shutdown()
54+
await sdk.sandboxes.shutdown(sandbox.id)
5555
}
5656
}

packages/core/src/services/latitudeTools/runCode/withDependencies.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,24 @@ export async function runCodeWithDependencies({
3535
dependencies,
3636
}: CodeToolArgs): PromisedResult<CodeRunResult, LatitudeError> {
3737
return withSafeSandbox(async (sandbox) => {
38+
const client = await sandbox.connect()
3839
const filename = getFilename({ language })
3940
const buildDependency = getDependencyBuilder({ language })
4041

41-
await sandbox.fs.writeFile(filename, new TextEncoder().encode(code))
42+
await client.fs.writeFile(filename, new TextEncoder().encode(code))
4243

4344
for await (const dep of dependencies!) {
44-
const installResult = await sandbox.shells.run(buildDependency(dep))
45-
if (installResult.exitCode !== 0) {
45+
const installResult = await client.commands.run(buildDependency(dep))
46+
if (!installResult) {
4647
return Result.error(
47-
new BadRequestError(
48-
`Failed to install dependency: '${dep}'\n${installResult.output}`,
49-
),
48+
new BadRequestError(`Failed to install dependency: '${dep}'`),
5049
)
5150
}
5251
}
5352

54-
const scriptResult = await sandbox.shells.run(
53+
const scriptResult = await client.commands.run(
5554
getRunCommand({ language, filename }),
5655
)
57-
return Result.ok(normalizedResult(scriptResult))
56+
return Result.ok(normalizedResult({ output: scriptResult, exitCode: 0 }))
5857
})
5958
}

packages/core/src/services/latitudeTools/runCode/withoutDependencies.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ export async function runCodeWithoutDependencies({
99
language,
1010
}: CodeToolArgs): PromisedResult<CodeRunResult, LatitudeError> {
1111
return withSafeSandbox(async (sandbox) => {
12+
const client = await sandbox.connect()
1213
const interpreter = (() => {
13-
if (language === 'python') return sandbox.shells.python
14-
if (language === 'javascript') return sandbox.shells.js
14+
if (language === 'python') return client.interpreters.python
15+
if (language === 'javascript') return client.interpreters.javascript
1516

1617
throw new BadRequestError(`Language ${language} is not supported`)
1718
})()
1819

19-
const result = await interpreter.run(code)
20-
return Result.ok(normalizedResult(result))
20+
const result = await interpreter(code)
21+
return Result.ok(normalizedResult({ output: result, exitCode: 0 }))
2122
})
2223
}

packages/core/src/tests/factories/documentLogs.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ async function generateProviderLogs({
6666
typeof message.content === 'string'
6767
? message.content
6868
: message.content
69-
.map((c) => (c.type === 'text' ? c.text : ''))
70-
.join('')
69+
.map((c) => (c.type === 'text' ? c.text : ''))
70+
.join('')
7171
return acc + content.length
7272
}, 0)
7373
const completionTokens = mockedResponse.length
@@ -133,7 +133,7 @@ export async function createDocumentLog({
133133
const duration =
134134
totalDuration ??
135135
Math.floor(Math.random() * 100) +
136-
providerLogs.reduce((acc, log) => acc + (log?.duration ?? 0), 0)
136+
providerLogs.reduce((acc, log) => acc + (log?.duration ?? 0), 0)
137137

138138
let documentLog = await ogCreateDocumentLog({
139139
commit,

0 commit comments

Comments
 (0)