Lines 82-122javascript
82// ---------------------------------------------------------------------------
84// Walk up from __dirname to find @opencode-ai/sdk/dist/index.js.
85// We import by absolute path to bypass the exports map resolution entirely —
86// bare specifier import('@opencode-ai/sdk') uses CJS resolution in a CJS bundle
87// and fails because the package only defines an "import" condition (no "require").
88function _findSdkEntryPath() {
90 // eslint-disable-next-line no-constant-condition
92 const candidate = path.join(dir, 'node_modules', '@opencode-ai', 'sdk', 'dist', 'index.js');
93 if (fs.existsSync(candidate)) {
96 const parent = path.dirname(dir);
98 throw new Error('@opencode-ai/sdk not found in any node_modules above ' + __dirname);
103// Use new Function() to prevent esbuild from transforming import(path) to require(path).
104// require() cannot load ESM files; a native ESM import() is required.
LowEval
Package source references a known benign dynamic code generation pattern.
out/providers/opencodeSdkProvider.jsView on unpkg · L102 105const _dynamicImport = new Function('p', 'return import(p)');
106async function _getSdk() {
108 const sdkPath = _findSdkEntryPath();
109 // pathToFileURL handles Windows drive-letter paths (e.g. H:\...) which
110 // Node's ESM loader rejects as unknown URL schemes unless converted to file://
111 const sdkUrl = (0, url_1.pathToFileURL)(sdkPath).href;
112 _sdkCache = (await _dynamicImport(sdkUrl));
116// ---------------------------------------------------------------------------
117// Free-port finder — tries ports starting at BASE_PORT, increments until one
118// is not bound, so multiple VS Code instances on the same machine each get
120// ---------------------------------------------------------------------------
121const BASE_PORT = 4096;
122const MAX_PORT = 4200;