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
8 changes: 8 additions & 0 deletions out/cli.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -84644,6 +84644,14 @@ var OpenAiEngine = class {
clientOptions.defaultHeaders = headers;
}
}
// The OpenAI SDK's internal fetch may resolve before globalThis.fetch is
// available in some Node.js versions, causing premature connection errors.
// Explicitly binding globalThis.fetch here defers resolution to call time,
// ensuring the runtime's native fetch is used instead of the SDK's bundled
// undici — which also avoids double-initialisation in newer Node (>=18).
if (!clientOptions.fetch && typeof globalThis.fetch === "function") {
clientOptions.fetch = (...args) => globalThis.fetch(...args);
}
this.client = new OpenAI(clientOptions);
}
};
Expand Down
9 changes: 9 additions & 0 deletions src/engine/openAi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ export class OpenAiEngine implements AiEngine {
}
}

// The OpenAI SDK's internal fetch may resolve before globalThis.fetch is
// available in some Node.js versions, causing premature connection errors.
// Explicitly binding globalThis.fetch here defers resolution to call time,
// ensuring the runtime's native fetch is used instead of the SDK's bundled
// undici — which also avoids double-initialisation in newer Node (>=18).
if (!clientOptions.fetch && typeof globalThis.fetch === 'function') {
clientOptions.fetch = (...args) => globalThis.fetch(...args);
}

this.client = new OpenAI(clientOptions);
}

Expand Down
Loading