Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default tseslint.config(
'examples/realtime-demo/**',
'examples/nextjs/**',
'integration-tests//**',
'tsc-multi.json',
]),
eslint.configs.recommended,
tseslint.configs.recommended,
Expand Down
10 changes: 9 additions & 1 deletion integration-tests/node.test.ts
Original file line number Diff line number Diff line change
@@ -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: '',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove all the pre-set node options too

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, makes sense ..will prevent hidden loader/interop from leaking in

TS_NODE_PROJECT: '',
TS_NODE_COMPILER_OPTIONS: '',
},
});

describe('Node.js', () => {
beforeAll(async () => {
Expand Down
8 changes: 5 additions & 3 deletions integration-tests/node/package.json
Original file line number Diff line number Diff line change
@@ -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",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this option is necessary to turn the esmodule interop option off

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it! sounds good :)

"start:esm": "node --no-experimental-require-module index.mjs"
},
"dependencies": {
"@openai/agents": "latest"
"@openai/agents": "latest",
"typescript": "^5.9.2"
}
}
56 changes: 19 additions & 37 deletions packages/agents-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,67 +14,49 @@
},
"exports": {
".": {
"require": {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to repeat types and default under require; simplified much

"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"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"default" works too but "import" works with clearer intention with ESModule

},
"./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": [
Expand Down
17 changes: 12 additions & 5 deletions packages/agents-core/src/shims/shims-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@ declare global {
// circular dependency resolution issues caused by other exports in '@openai/agents-core/_shims'
export function loadEnv(): Record<string, string | undefined> {
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<string, string | undefined>;
// 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<string, string | undefined>;
}
} catch {
// import.meta not available (CommonJS build)
}
return {};
}
Expand Down
17 changes: 12 additions & 5 deletions packages/agents-core/src/shims/shims-workerd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,18 @@ declare global {
// circular dependency resolution issues caused by other exports in '@openai/agents-core/_shims'
export function loadEnv(): Record<string, string | undefined> {
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<string, string | undefined>;
// 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<string, string | undefined>;
}
} catch {
// import.meta not available (CommonJS build)
}
return {};
}
Expand Down
7 changes: 2 additions & 5 deletions packages/agents-extensions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
7 changes: 2 additions & 5 deletions packages/agents-openai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
32 changes: 13 additions & 19 deletions packages/agents-realtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shims/shims is just a reference to shims/shims-node, but there is no downside of this change

"require": "./dist/shims/shims.js",
"import": "./dist/shims/shims.mjs"
}
},
"typesVersions": {
Expand Down
21 changes: 6 additions & 15 deletions packages/agents/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion tsc-multi.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"targets": [
{ "extname": ".js", "module": "es2022", "moduleResolution": "node" },
{ "extname": ".js", "module": "commonjs", "moduleResolution": "node" },
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*.js files are CJS compat; *.mjs are ESModule compat

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the .js ---> CJS / .mjs --> ESM flip is clear. wondering if will we align each packages/* exports (incl. subpaths) so import --> *.mjs, require --> *.js, and drop "type":"module" where .js is CJS? If top-level only is intended, all good!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly. I've revised package.json files to be simpler and clearer to use "require" and "import". Verified the behavior with the integration tests, plus did additional manual tests with a simple project too.

{ "extname": ".mjs", "module": "esnext" }
],
"projects": [
Expand Down