diff --git a/.changeset/clear-pans-nail.md b/.changeset/clear-pans-nail.md new file mode 100644 index 00000000..b0895a6f --- /dev/null +++ b/.changeset/clear-pans-nail.md @@ -0,0 +1,5 @@ +--- +'@openai/agents-core': patch +--- + +fix: ensure process.on exists and is a function before adding event handlers diff --git a/packages/agents-core/src/index.ts b/packages/agents-core/src/index.ts index 1a457f1c..80101f76 100644 --- a/packages/agents-core/src/index.ts +++ b/packages/agents-core/src/index.ts @@ -153,7 +153,7 @@ const cleanup = async () => { await getGlobalTraceProvider().shutdown(); }; -if (typeof process !== 'undefined') { +if (typeof process !== 'undefined' && typeof process.on === 'function') { // handling Node.js process termination // Handle normal termination diff --git a/packages/agents-core/src/tracing/index.ts b/packages/agents-core/src/tracing/index.ts index 7869699f..a50e6932 100644 --- a/packages/agents-core/src/tracing/index.ts +++ b/packages/agents-core/src/tracing/index.ts @@ -52,7 +52,7 @@ const cleanup = async () => { await getGlobalTraceProvider().shutdown(); }; -if (typeof process !== 'undefined') { +if (typeof process !== 'undefined' && typeof process.on === 'function') { // handling Node.js process termination // Handle normal termination