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

View File

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

View File

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

View File

@ -35,18 +35,18 @@ export type ContentGeneratorConfig = {
model: string;
apiKey?: string;
vertexai?: boolean;
userAgent: string;
};
export function createContentGenerator(
config: ContentGeneratorConfig,
): ContentGenerator {
const version = process.env.CLI_VERSION || process.version;
const googleGenAI = new GoogleGenAI({
apiKey: config.apiKey === '' ? undefined : config.apiKey,
vertexai: config.vertexai,
httpOptions: {
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;
}
const geminiCliVersion = config.getContentGeneratorConfig().userAgent;
const resource = new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: SERVICE_NAME,
[SemanticResourceAttributes.SERVICE_VERSION]: geminiCliVersion,
[SemanticResourceAttributes.SERVICE_VERSION]: process.version,
'session.id': sessionId,
});

View File

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