@@ -24,8 +24,7 @@ import { rageDetectors } from './rage-detectors'
2424import { logAndHandleStartup } from './startup-process-handler'
2525import { recreateShell } from './terminal/run-command'
2626import { validateAgentDefinitionsIfAuthenticated } from './utils/agent-validation'
27- import { getUserCredentials } from './credentials'
28- import { API_KEY_ENV_VAR } from '@codebuff/common/constants'
27+ import { createAuthHeaders } from './utils/auth-headers'
2928import { initAnalytics , trackEvent } from './utils/analytics'
3029import { logger } from './utils/logger'
3130import { Spinner } from './utils/spinner'
@@ -36,22 +35,6 @@ export async function validateAgent(
3635 agent : string ,
3736 localAgents ?: Record < string , any > ,
3837) : Promise < void > {
39- // Check what credentials are available at this point
40- const userCredentials = getUserCredentials ( )
41- const apiKeyEnvVar = process . env [ API_KEY_ENV_VAR ]
42-
43- logger . info (
44- {
45- agent,
46- hasUserCredentials : ! ! userCredentials ,
47- hasApiKeyEnvVar : ! ! apiKeyEnvVar ,
48- userId : userCredentials ?. id ,
49- userEmail : userCredentials ?. email ,
50- hasAuthToken : ! ! userCredentials ?. authToken ,
51- } ,
52- '[startup] validateAgent: checking available credentials' ,
53- )
54-
5538 const agents = localAgents ?? { }
5639
5740 // if local agents are loaded, they're already validated
@@ -64,31 +47,10 @@ export async function validateAgent(
6447 Spinner . get ( ) . start ( 'Checking agent...' )
6548 try {
6649 const url = `${ backendUrl } /api/agents/validate-name?agentId=${ encodeURIComponent ( agent ) } `
67-
68- // Add auth headers if available
69- const headers : Record < string , string> = {
70- 'Content-Type' : 'application/json' ,
71- }
72-
73- if ( userCredentials ?. authToken ) {
74- headers . Authorization = `Bearer ${ userCredentials . authToken } `
75- logger . debug (
76- { hasAuthHeader : true } ,
77- '[startup] Adding Authorization header to agent validation request' ,
78- )
79- } else if ( apiKeyEnvVar ) {
80- headers [ 'X - API - Key '] = apiKeyEnvVar
81- logger . debug (
82- { hasApiKey : true } ,
83- '[startup] Adding API key header to agent validation request' ,
84- )
85- } else {
86- logger . warn (
87- { } ,
88- '[startup] No authentication credentials available for agent validation' ,
89- )
90- }
91-
50+
51+ // Use helper to create headers with x-codebuff-api-key
52+ const headers = createAuthHeaders ( )
53+
9254 const resp = await fetch ( url , {
9355 method : 'GET' ,
9456 headers,
0 commit comments