Skip to content
Closed
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
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
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

@seratch seratch Jul 28, 2025

Choose a reason for hiding this comment

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

Thanks for changing this. This change looks reasonable, but we need to verify these before merging the change:

I will spend time on this later this week soon.

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