Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
fix(js-sdk): unpin useDefineForClassFields — make caller-directory resolution emit-invariant (#1539)
Mish Ushakov64e9bc02b6eb
diff --git a/.changeset/lucky-buttons-repair.md b/.changeset/lucky-buttons-repair.mdnew file mode 100644index 000000000..3e1e2ad04--- /dev/null+++ b/.changeset/lucky-buttons-repair.md@@ -0,0 +1,5 @@+---+'e2b': patch+---++Resolve the template builder's default file context path in the constructor instead of a class field initializer. Under `[[Define]]` class-field semantics (the default at `target: es2022+`), field initializers run in an extra `<instance_members_initializer>` stack frame, which threw off the fixed-depth caller-directory resolution — `.copy()` sources resolved against the SDK's own directory instead of the caller's. The constructor-body call is emit-invariant, so the `useDefineForClassFields: false` pin in tsconfig is no longer needed and has been removed.diff --git a/packages/js-sdk/src/template/index.ts b/packages/js-sdk/src/template/index.tsindex 7e75c92d6..5d1176f52 100644--- a/packages/js-sdk/src/template/index.ts+++ b/packages/js-sdk/src/template/index.ts@@ -66,8 +66,7 @@ export class TemplateBase// Force the next layer to be rebuiltprivate forceNextLayer: boolean = falseprivate instructions: Instruction[] = []- private fileContextPath: PathLike =- runtime === 'browser' ? '.' : (getCallerDirectory(STACK_TRACE_DEPTH) ?? '.')+ private fileContextPath: PathLikeprivate fileIgnorePatterns: string[] = []private logsRefreshFrequency: number = 200private stackTraces: (string | undefined)[] = []@@ -75,7 +74,11 @@ export class TemplateBaseprivate stackTracesOverride: string | undefined = undefinedconstructor(options?: TemplateOptions) {- this.fileContextPath = options?.fileContextPath ?? this.fileContextPath+ this.fileContextPath =+ options?.fileContextPath ??+ (runtime === 'browser'+ ? '.'+ : (getCallerDirectory(STACK_TRACE_DEPTH) ?? '.'))this.fileIgnorePatterns =options?.fileIgnorePatterns ?? this.fileIgnorePatterns}diff --git a/packages/js-sdk/tsconfig.json b/packages/js-sdk/tsconfig.jsonindex c922e3151..f81cbc5da 100644--- a/packages/js-sdk/tsconfig.json+++ b/packages/js-sdk/tsconfig.json@@ -3,12 +3,6 @@"outDir": "dist","target": "es2022","module": "esnext",- // Keep assignment (not `[[Define]]`) semantics for class fields. `target:- // es2022` would default this to `true`, which changes class-field emit and- // shifts stack frames — breaking the template builder's fixed-depth caller- // resolution (getCallerDirectory / per-step stack traces). Adopting define- // semantics should be a separate, deliberately tested change.- "useDefineForClassFields": false,"lib": ["dom","es2022"