Skip to content

Commit 02cd869

Browse files
Add debugging logs to trace API key/model name confusion
- Added HTTP request body logging in http-client.ts - Added agent object and request logging in remote-conversation.ts - These logs will help identify where model name is being passed as API key - Investigating 401 authentication errors in conversation creation
1 parent 2bfb2ba commit 02cd869

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

example/src/components/ConversationManager.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const ConversationManager: React.FC = () => {
2424
const [selectedConversation, setSelectedConversation] = useState<string | null>(null);
2525
const [messageInput, setMessageInput] = useState('');
2626
const [activeConversations, setActiveConversations] = useState<Map<string, RemoteConversation>>(new Map());
27+
const [currentAgent, setCurrentAgent] = useState<AgentBase | null>(null);
2728

2829
// Initialize conversation manager
2930
useEffect(() => {
@@ -67,9 +68,27 @@ export const ConversationManager: React.FC = () => {
6768
const createConversation = async () => {
6869
if (!manager) return;
6970

71+
// Validate required settings
72+
if (!settings.apiKey.trim()) {
73+
setError('LLM API Key is required. Please configure it in settings.');
74+
return;
75+
}
76+
77+
if (!settings.modelName.trim()) {
78+
setError('Model name is required. Please configure it in settings.');
79+
return;
80+
}
81+
7082
setLoading(true);
7183
setError(null);
7284
try {
85+
console.log('Settings values:', {
86+
modelName: settings.modelName,
87+
apiKey: settings.apiKey ? `${settings.apiKey.substring(0, 10)}...` : 'EMPTY',
88+
agentServerUrl: settings.agentServerUrl,
89+
agentServerApiKey: settings.agentServerApiKey ? `${settings.agentServerApiKey.substring(0, 10)}...` : 'EMPTY'
90+
});
91+
7392
const agent: AgentBase = {
7493
name: 'CodeActAgent',
7594
llm: {
@@ -78,6 +97,16 @@ export const ConversationManager: React.FC = () => {
7897
},
7998
};
8099

100+
console.log('Creating conversation with agent:', {
101+
name: agent.name,
102+
model: agent.llm.model,
103+
hasApiKey: !!agent.llm.api_key,
104+
apiKeyValue: agent.llm.api_key
105+
});
106+
107+
// Store the current agent configuration
108+
setCurrentAgent(agent);
109+
81110
const conversation = await manager.createConversation(agent, {
82111
initialMessage: 'Hello! I\'m ready to help you with your tasks.',
83112
maxIterations: 50,
@@ -143,16 +172,21 @@ export const ConversationManager: React.FC = () => {
143172
let conversation = activeConversations.get(conversationId);
144173

145174
if (!conversation) {
175+
console.log('Loading conversation:', conversationId);
146176
// Load the conversation if not already active
147177
conversation = await manager.loadConversation(conversationId);
148178
setActiveConversations(prev => new Map(prev.set(conversationId, conversation!)));
149179
}
150180

181+
console.log('Sending message to conversation:', conversationId, 'Message:', message);
151182
await conversation.sendMessage(message);
183+
184+
console.log('Running conversation:', conversationId);
152185
await conversation.run();
153186

154187
setMessageInput('');
155188
} catch (err) {
189+
console.error('Error sending message:', err);
156190
setError(err instanceof Error ? err.message : 'Failed to send message');
157191
}
158192
};

src/client/http-client.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ export class HttpClient {
8383
delete headers['Content-Type'];
8484
requestInit.body = options.data;
8585
} else {
86-
requestInit.body = JSON.stringify(options.data);
86+
const bodyData = JSON.stringify(options.data);
87+
console.log('HTTP Request Body:', bodyData);
88+
requestInit.body = bodyData;
8789
}
8890
}
8991

src/conversation/remote-conversation.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ export class RemoteConversation {
213213
};
214214
}
215215

216+
console.log('Agent object before request:', JSON.stringify(agent, null, 2));
217+
216218
const request: CreateConversationRequest = {
217219
agent,
218220
initial_message: initialMessage,
@@ -221,6 +223,8 @@ export class RemoteConversation {
221223
workspace: options.workspace || { type: 'local', working_dir: '/tmp' },
222224
};
223225

226+
console.log('Full request object:', JSON.stringify(request, null, 2));
227+
224228
const response = await client.post<ConversationInfo>('/api/conversations', request);
225229
const conversationInfo = response.data;
226230

0 commit comments

Comments
 (0)