Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Adjusted JS SDK logging levels (#117)

Pavel 'Strajk' Dolecek4362a0b1ee5d
diff --git a/.changeset/tasty-rules-agree.md b/.changeset/tasty-rules-agree.md
new file mode 100644
index 000000000..c1eeeb1cc
--- /dev/null
+++ b/.changeset/tasty-rules-agree.md
@@ -0,0 +1,5 @@
+---
+"@e2b/sdk": patch
+---
+
+Adjusted logging levels
diff --git a/packages/js-sdk/src/session/sessionConnection.ts b/packages/js-sdk/src/session/sessionConnection.ts
index 03edeb8ff..566bc3566 100644
--- a/packages/js-sdk/src/session/sessionConnection.ts
+++ b/packages/js-sdk/src/session/sessionConnection.ts
@@ -199,7 +199,8 @@ export class SessionConnection {
const sessionURL = `${protocol}://${hostname}${WS_ROUTE}`
this.rpc.onError(err => {
- this.logger.warn?.(
+ // not warn, because this is somewhat expected behaviour during initialization
+ this.logger.debug?.(
`Error in WS session "${this.session?.sessionID}": ${
err.message ?? err.code ?? err.toString()
}. Trying to reconnect...`,
@@ -243,7 +244,8 @@ export class SessionConnection {
this.logger.debug?.(`Reconnected to session "${this.session?.sessionID}"`)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) {
- this.logger.warn?.(
+ // not warn, because this is somewhat expected behaviour during initialization
+ this.logger.debug?.(
`Failed reconnecting to session "${this.session?.sessionID}": ${
err.message ?? err.code ?? err.toString()
}`,
@@ -262,7 +264,8 @@ export class SessionConnection {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) {
- this.logger.warn?.(
+ // not warn, because this is somewhat expected behaviour during initialization
+ this.logger.debug?.(
`Error connecting to session "${this.session?.sessionID}": ${
err.message ?? err.code ?? err.toString()
}`,
@@ -372,7 +375,7 @@ export class SessionConnection {
// eslint-disable-next-line no-constant-condition
while (true) {
if (!this.isOpen) {
- this.logger.warn?.(
+ this.logger.debug?.(
`Cannot refresh session ${this.session?.sessionID} - it was closed`,
)
return
diff --git a/packages/js-sdk/testground/README.md b/packages/js-sdk/testground/README.md
new file mode 100644
index 000000000..ec061def4
--- /dev/null
+++ b/packages/js-sdk/testground/README.md
@@ -0,0 +1,2 @@
+Various example scripts that comes in handy when testing/debugging/reasoning about the SDK.
+Probably only useful for the dev team behind the SDK.
diff --git a/packages/js-sdk/testground/basic.cjs b/packages/js-sdk/testground/basic.cjs
new file mode 100644
index 000000000..080948ac8
--- /dev/null
+++ b/packages/js-sdk/testground/basic.cjs
@@ -0,0 +1,42 @@
+const e2b = require("../dist/cjs/index")
+
+async function main() {
+ const session = await e2b.Session.create({
+ id: 'Nodejs',
+ apiKey: process.env.E2B_API_KEY
+ })
+
+ await session.filesystem.write(
+ '/code/package.json',
+ JSON.stringify({
+ dependencies: {
+ "is-odd": '3.0.1',
+ },
+ }),
+ )
+
+ const proc = await session.process.start({
+ cmd: 'npm i --silent',
+ envVars: { NPM_CONFIG_UPDATE_NOTIFIER: "false" },
+ rootdir: '/code',
+ onStdout: ({ line }) => console.log('STDOUT', line),
+ onStderr: ({ line }) => console.log('STDERR', line),
+ })
+
+ await proc.finished
+
+ // list node_modules
+ const files = await session.filesystem.list('/code/node_modules')
+ console.log(
+ 'installed node_modules (first 10 of them):',
+ files
+ .map(f => f.name)
+ .slice(0, 10)
+ .join(', '),
+ )
+
+ await session.close()
+}
+
+main().catch(console.error)
+