diff --git a/eslint.config.mjs b/eslint.config.mjs index 151a3817..1573ebc1 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -24,6 +24,7 @@ export default tseslint.config( 'examples/realtime-demo/**', 'examples/nextjs/**', 'integration-tests//**', + 'tsc-multi.json', ]), eslint.configs.recommended, tseslint.configs.recommended, diff --git a/integration-tests/node.test.ts b/integration-tests/node.test.ts index c8a40c9c..b12cdf62 100644 --- a/integration-tests/node.test.ts +++ b/integration-tests/node.test.ts @@ -1,7 +1,15 @@ import { describe, test, expect, beforeAll } from 'vitest'; import { execa as execaBase } from 'execa'; -const execa = execaBase({ cwd: './integration-tests/node' }); +const execa = execaBase({ + cwd: './integration-tests/node', + env: { + ...process.env, + NODE_OPTIONS: '', + TS_NODE_PROJECT: '', + TS_NODE_COMPILER_OPTIONS: '', + }, +}); describe('Node.js', () => { beforeAll(async () => { diff --git a/integration-tests/node/package.json b/integration-tests/node/package.json index 676a1219..d4a455ac 100644 --- a/integration-tests/node/package.json +++ b/integration-tests/node/package.json @@ -1,10 +1,12 @@ { "private": true, + "type": "commonjs", "scripts": { - "start:cjs": "node index.cjs", - "start:esm": "node index.mjs" + "start:cjs": "node --no-experimental-require-module index.cjs", + "start:esm": "node --no-experimental-require-module index.mjs" }, "dependencies": { - "@openai/agents": "latest" + "@openai/agents": "latest", + "typescript": "^5.9.2" } } diff --git a/packages/agents-core/package.json b/packages/agents-core/package.json index 6672371e..9d699feb 100644 --- a/packages/agents-core/package.json +++ b/packages/agents-core/package.json @@ -14,67 +14,49 @@ }, "exports": { ".": { - "require": { - "types": "./dist/index.d.ts", - "default": "./dist/index.js" - }, "types": "./dist/index.d.ts", - "default": "./dist/index.mjs" + "require": "./dist/index.js", + "import": "./dist/index.mjs" }, "./model": { - "require": { - "types": "./dist/model.d.ts", - "default": "./dist/model.js" - }, "types": "./dist/model.d.ts", - "default": "./dist/model.mjs" + "require": "./dist/model.js", + "import": "./dist/model.mjs" }, "./utils": { - "require": { - "types": "./dist/utils/index.d.ts", - "default": "./dist/utils/index.js" - }, "types": "./dist/utils/index.d.ts", - "default": "./dist/utils/index.mjs" + "require": "./dist/utils/index.js", + "import": "./dist/utils/index.mjs" }, "./extensions": { - "require": { - "types": "./dist/extensions/index.d.ts", - "default": "./dist/extensions/index.js" - }, "types": "./dist/extensions/index.d.ts", - "default": "./dist/extensions/index.mjs" + "require": "./dist/extensions/index.js", + "import": "./dist/extensions/index.mjs" }, "./types": { - "require": { - "types": "./dist/types/index.d.ts", - "default": "./dist/types/index.js" - }, "types": "./dist/types/index.d.ts", - "default": "./dist/types/index.mjs" + "require": "./dist/types/index.js", + "import": "./dist/types/index.mjs" }, "./_shims": { "workerd": { - "require": "./dist/shims/shims-workerd.js", "types": "./dist/shims/shims-workerd.d.ts", - "default": "./dist/shims/shims-workerd.mjs" + "require": "./dist/shims/shims-workerd.js", + "import": "./dist/shims/shims-workerd.mjs" }, "browser": { - "require": "./dist/shims/shims-browser.js", "types": "./dist/shims/shims-browser.d.ts", - "default": "./dist/shims/shims-browser.mjs" + "require": "./dist/shims/shims-browser.js", + "import": "./dist/shims/shims-browser.mjs" }, "node": { - "require": "./dist/shims/shims-node.js", "types": "./dist/shims/shims-node.d.ts", - "default": "./dist/shims/shims-node.mjs" - }, - "require": { - "types": "./dist/shims/shims-node.d.ts", - "default": "./dist/shims/shims-node.js" + "require": "./dist/shims/shims-node.js", + "import": "./dist/shims/shims-node.mjs" }, - "types": "./dist/shims/shims-node.d.ts", - "default": "./dist/shims/shims-node.mjs" + "types": "./dist/shims/shims.d.ts", + "require": "./dist/shims/shims.js", + "import": "./dist/shims/shims.mjs" } }, "keywords": [ diff --git a/packages/agents-core/src/shims/shims-node.ts b/packages/agents-core/src/shims/shims-node.ts index 1bb0086d..8258d0d4 100644 --- a/packages/agents-core/src/shims/shims-node.ts +++ b/packages/agents-core/src/shims/shims-node.ts @@ -14,11 +14,18 @@ declare global { // circular dependency resolution issues caused by other exports in '@openai/agents-core/_shims' export function loadEnv(): Record { if (typeof process === 'undefined' || typeof process.env === 'undefined') { - if ( - typeof import.meta === 'object' && - typeof import.meta.env === 'object' - ) { - return import.meta.env as unknown as Record; + // In CommonJS builds, import.meta is not available, so we return empty object + try { + // Use eval to avoid TypeScript compilation errors in CommonJS builds + const importMeta = (0, eval)('import.meta'); + if ( + typeof importMeta === 'object' && + typeof importMeta.env === 'object' + ) { + return importMeta.env as unknown as Record; + } + } catch { + // import.meta not available (CommonJS build) } return {}; } diff --git a/packages/agents-core/src/shims/shims-workerd.ts b/packages/agents-core/src/shims/shims-workerd.ts index 110cdb20..d183cbcc 100644 --- a/packages/agents-core/src/shims/shims-workerd.ts +++ b/packages/agents-core/src/shims/shims-workerd.ts @@ -15,11 +15,18 @@ declare global { // circular dependency resolution issues caused by other exports in '@openai/agents-core/_shims' export function loadEnv(): Record { if (typeof process === 'undefined' || typeof process.env === 'undefined') { - if ( - typeof import.meta === 'object' && - typeof import.meta.env === 'object' - ) { - return import.meta.env as unknown as Record; + // In CommonJS builds, import.meta is not available, so we return empty object + try { + // Use eval to avoid TypeScript compilation errors in CommonJS builds + const importMeta = (0, eval)('import.meta'); + if ( + typeof importMeta === 'object' && + typeof importMeta.env === 'object' + ) { + return importMeta.env as unknown as Record; + } + } catch { + // import.meta not available (CommonJS build) } return {}; } diff --git a/packages/agents-extensions/package.json b/packages/agents-extensions/package.json index fbfdc61d..9026baf3 100644 --- a/packages/agents-extensions/package.json +++ b/packages/agents-extensions/package.json @@ -19,12 +19,9 @@ }, "exports": { ".": { - "require": { - "types": "./dist/index.d.ts", - "default": "./dist/index.js" - }, "types": "./dist/index.d.ts", - "default": "./dist/index.mjs" + "require": "./dist/index.js", + "import": "./dist/index.mjs" } }, "peerDependencies": { diff --git a/packages/agents-openai/package.json b/packages/agents-openai/package.json index 5a1750e3..6262e12d 100644 --- a/packages/agents-openai/package.json +++ b/packages/agents-openai/package.json @@ -9,12 +9,9 @@ "types": "dist/index.d.ts", "exports": { ".": { - "require": { - "types": "./dist/index.d.ts", - "default": "./dist/index.js" - }, "types": "./dist/index.d.ts", - "default": "./dist/index.mjs" + "require": "./dist/index.js", + "import": "./dist/index.mjs" } }, "dependencies": { diff --git a/packages/agents-realtime/package.json b/packages/agents-realtime/package.json index 41452781..1fee1509 100644 --- a/packages/agents-realtime/package.json +++ b/packages/agents-realtime/package.json @@ -11,39 +11,33 @@ "exports": { ".": { "browser": { - "require": "./dist/index.js", - "types": "./dist/index.d.ts", - "default": "./dist/index.mjs" - }, - "require": { "types": "./dist/index.d.ts", - "default": "./dist/index.js" + "require": "./dist/index.js", + "import": "./dist/index.mjs" }, "types": "./dist/index.d.ts", - "default": "./dist/index.mjs" + "require": "./dist/index.js", + "import": "./dist/index.mjs" }, "./_shims": { "workerd": { - "require": "./dist/shims/shims-workerd.js", "types": "./dist/shims/shims-workerd.d.ts", - "default": "./dist/shims/shims-workerd.mjs" + "require": "./dist/shims/shims-workerd.js", + "import": "./dist/shims/shims-workerd.mjs" }, "browser": { - "require": "./dist/shims/shims-browser.js", "types": "./dist/shims/shims-browser.d.ts", - "default": "./dist/shims/shims-browser.mjs" + "require": "./dist/shims/shims-browser.js", + "import": "./dist/shims/shims-browser.mjs" }, "node": { - "require": "./dist/shims/shims-node.js", "types": "./dist/shims/shims-node.d.ts", - "default": "./dist/shims/shims-node.mjs" - }, - "require": { - "types": "./dist/shims/shims-node.d.ts", - "default": "./dist/shims/shims-node.js" + "require": "./dist/shims/shims-node.js", + "import": "./dist/shims/shims-node.mjs" }, - "types": "./dist/shims/shims-node.d.ts", - "default": "./dist/shims/shims-node.mjs" + "types": "./dist/shims/shims.d.ts", + "require": "./dist/shims/shims.js", + "import": "./dist/shims/shims.mjs" } }, "typesVersions": { diff --git a/packages/agents/package.json b/packages/agents/package.json index b40c3437..0b882a3d 100644 --- a/packages/agents/package.json +++ b/packages/agents/package.json @@ -9,28 +9,19 @@ "types": "dist/index.d.ts", "exports": { ".": { - "require": { - "types": "./dist/index.d.ts", - "default": "./dist/index.js" - }, "types": "./dist/index.d.ts", - "default": "./dist/index.mjs" + "require": "./dist/index.js", + "import": "./dist/index.mjs" }, "./realtime": { - "require": { - "types": "./dist/realtime/index.d.ts", - "default": "./dist/realtime/index.js" - }, "types": "./dist/realtime/index.d.ts", - "default": "./dist/realtime/index.mjs" + "require": "./dist/realtime/index.js", + "import": "./dist/realtime/index.mjs" }, "./utils": { - "require": { - "types": "./dist/utils/index.d.ts", - "default": "./dist/utils/index.js" - }, "types": "./dist/utils/index.d.ts", - "default": "./dist/utils/index.mjs" + "require": "./dist/utils/index.js", + "import": "./dist/utils/index.mjs" } }, "scripts": { diff --git a/tsc-multi.json b/tsc-multi.json index 104f0829..ddf444ca 100644 --- a/tsc-multi.json +++ b/tsc-multi.json @@ -1,6 +1,6 @@ { "targets": [ - { "extname": ".js", "module": "es2022", "moduleResolution": "node" }, + { "extname": ".js", "module": "commonjs", "moduleResolution": "node" }, { "extname": ".mjs", "module": "esnext" } ], "projects": [