mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 16:57:46 +00:00
feat: Add User-Agent to API requests
This change introduces a User-Agent header to all API requests made by the Gemini CLI. The User-Agent string includes the CLI version, Node.js version, operating system, and architecture. This will help in tracking usage and identifying potential issues. Fixes https://b.corp.google.com/issues/416353675 Signed-off-by: Gemini
This commit is contained in:
committed by
N. Taylor Mullen
parent
2970f0a06c
commit
8537aabba4
@@ -13,6 +13,7 @@ import {
|
||||
createServerConfig,
|
||||
} from '@gemini-code/server';
|
||||
import { Settings } from './settings.js';
|
||||
import { readPackageUp } from 'read-package-up';
|
||||
|
||||
const DEFAULT_GEMINI_MODEL = 'gemini-2.5-pro-preview-05-06';
|
||||
|
||||
@@ -80,6 +81,8 @@ export async function loadCliConfig(settings: Settings): Promise<Config> {
|
||||
// Parse CLI arguments
|
||||
const argv = await parseArguments();
|
||||
|
||||
const userAgent = await createUserAgent();
|
||||
|
||||
// Create config using factory from server package
|
||||
return createServerConfig(
|
||||
process.env.GEMINI_API_KEY,
|
||||
@@ -92,5 +95,12 @@ export async function loadCliConfig(settings: Settings): Promise<Config> {
|
||||
settings.toolDiscoveryCommand,
|
||||
settings.toolCallCommand,
|
||||
settings.mcpServerCommand,
|
||||
userAgent,
|
||||
);
|
||||
}
|
||||
|
||||
async function createUserAgent(): Promise<string> {
|
||||
const packageJsonInfo = await readPackageUp({ cwd: import.meta.url });
|
||||
const cliVersion = packageJsonInfo?.packageJson.version || 'unknown';
|
||||
return `GeminiCLI/${cliVersion} Node.js/${process.version} (${process.platform}; ${process.arch})`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user