Simplify user agent handling. (#828)

This commit is contained in:
Tommaso Sciortino 2025-06-09 09:31:27 -07:00 committed by GitHub
parent 87474e52d7
commit 0613062fc8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 3 additions and 10 deletions

View File

@ -18,7 +18,6 @@ import {
} from '@gemini-cli/core'; } from '@gemini-cli/core';
import { Settings } from './settings.js'; import { Settings } from './settings.js';
import { getEffectiveModel } from '../utils/modelCheck.js'; import { getEffectiveModel } from '../utils/modelCheck.js';
import { getCliVersion } from '../utils/version.js';
// Simple console logger for now - replace with actual logger if available // Simple console logger for now - replace with actual logger if available
const logger = { const logger = {
@ -206,7 +205,6 @@ async function createContentGeneratorConfig(
model: argv.model || DEFAULT_GEMINI_MODEL, model: argv.model || DEFAULT_GEMINI_MODEL,
apiKey: geminiApiKey || googleApiKey || '', apiKey: geminiApiKey || googleApiKey || '',
vertexai: hasGeminiApiKey ? false : undefined, vertexai: hasGeminiApiKey ? false : undefined,
userAgent: `GeminiCLI/${getCliVersion()}/(${process.platform}; ${process.arch})`,
}; };
if (config.apiKey) { if (config.apiKey) {

View File

@ -182,7 +182,6 @@ describe('App UI', () => {
contentGeneratorConfig: { contentGeneratorConfig: {
apiKey: 'test-key', apiKey: 'test-key',
model: 'test-model', model: 'test-model',
userAgent: 'test-agent',
}, },
embeddingModel: 'test-embedding-model', embeddingModel: 'test-embedding-model',
sandbox: false, sandbox: false,

View File

@ -46,7 +46,6 @@ describe('Server Config (config.ts)', () => {
const DEBUG_MODE = false; const DEBUG_MODE = false;
const QUESTION = 'test question'; const QUESTION = 'test question';
const FULL_CONTEXT = false; const FULL_CONTEXT = false;
const USER_AGENT = 'ServerTestAgent/1.0';
const USER_MEMORY = 'Test User Memory'; const USER_MEMORY = 'Test User Memory';
const TELEMETRY = false; const TELEMETRY = false;
const EMBEDDING_MODEL = 'gemini-embedding'; const EMBEDDING_MODEL = 'gemini-embedding';
@ -54,7 +53,6 @@ describe('Server Config (config.ts)', () => {
contentGeneratorConfig: { contentGeneratorConfig: {
apiKey: API_KEY, apiKey: API_KEY,
model: MODEL, model: MODEL,
userAgent: USER_AGENT,
}, },
embeddingModel: EMBEDDING_MODEL, embeddingModel: EMBEDDING_MODEL,
sandbox: SANDBOX, sandbox: SANDBOX,

View File

@ -35,18 +35,18 @@ export type ContentGeneratorConfig = {
model: string; model: string;
apiKey?: string; apiKey?: string;
vertexai?: boolean; vertexai?: boolean;
userAgent: string;
}; };
export function createContentGenerator( export function createContentGenerator(
config: ContentGeneratorConfig, config: ContentGeneratorConfig,
): ContentGenerator { ): ContentGenerator {
const version = process.env.CLI_VERSION || process.version;
const googleGenAI = new GoogleGenAI({ const googleGenAI = new GoogleGenAI({
apiKey: config.apiKey === '' ? undefined : config.apiKey, apiKey: config.apiKey === '' ? undefined : config.apiKey,
vertexai: config.vertexai, vertexai: config.vertexai,
httpOptions: { httpOptions: {
headers: { headers: {
'User-Agent': config.userAgent, 'User-Agent': `GeminiCLI/${version}/(${process.platform}; ${process.arch})`,
}, },
}, },
}); });

View File

@ -64,10 +64,9 @@ export function initializeTelemetry(config: Config): void {
return; return;
} }
const geminiCliVersion = config.getContentGeneratorConfig().userAgent;
const resource = new Resource({ const resource = new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: SERVICE_NAME, [SemanticResourceAttributes.SERVICE_NAME]: SERVICE_NAME,
[SemanticResourceAttributes.SERVICE_VERSION]: geminiCliVersion, [SemanticResourceAttributes.SERVICE_VERSION]: process.version,
'session.id': sessionId, 'session.id': sessionId,
}); });

View File

@ -128,7 +128,6 @@ const baseConfigParams: ConfigParameters = {
model: 'test-model', model: 'test-model',
apiKey: 'test-api-key', apiKey: 'test-api-key',
vertexai: false, vertexai: false,
userAgent: 'TestAgent/1.0',
}, },
embeddingModel: 'test-embedding-model', embeddingModel: 'test-embedding-model',
sandbox: false, sandbox: false,