@@ -4,13 +4,15 @@ import * as path from "path";
44import OpenAI from "openai" ;
55import { Agent , fetch as undiciFetch } from "undici" ;
66import { resolveCurrentSettings } from "../settings" ;
7+ import { APP_VERSION } from "./package-info" ;
78
89// Custom undici Agent with a 180-second keepAlive timeout. The default
910// global fetch (undici) only keeps connections alive for 4 seconds, which
1011// is too short for a CLI where the user may spend 10–30 seconds reading
1112// output between prompts. By passing a dedicated Agent to undiciFetch we
1213// keep connections reusable for three minutes after the last request.
1314const keepAliveAgent = new Agent ( { keepAliveTimeout : 180_000 } ) ;
15+ const USER_AGENT = `deepcode-cli/${ APP_VERSION } ` ;
1416
1517// Module-level cache for the OpenAI client instance. The client itself is
1618// a stateless fetch wrapper, so it is safe to share across calls as long as
@@ -73,7 +75,11 @@ export function createOpenAIClient(projectRoot: string = process.cwd()): {
7375 apiKey : settings . apiKey ,
7476 baseURL : settings . baseURL || undefined ,
7577 // eslint-disable-next-line @typescript-eslint/no-explicit-any
76- fetch : ( url : any , init : any ) => undiciFetch ( url , { ...init , dispatcher : keepAliveAgent } ) ,
78+ fetch : ( url : any , init : any ) => {
79+ const headers = new Headers ( init ?. headers ) ;
80+ headers . set ( "User-Agent" , USER_AGENT ) ;
81+ return undiciFetch ( url , { ...init , headers, dispatcher : keepAliveAgent } ) ;
82+ } ,
7783 } ) ;
7884 cachedOpenAIKey = cacheKey ;
7985
0 commit comments