Skip to content

Commit a3d6837

Browse files
committed
change api key name in app module, enhance error logging
1 parent 269d489 commit a3d6837

File tree

6 files changed

+62
-17
lines changed

6 files changed

+62
-17
lines changed
File renamed without changes.

README.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,42 @@ This application provides both CLI and web interfaces for interacting with AI mo
77

88
### Project Statistics
99

10-
- **Total Commits**: 68
11-
- **AI-Assisted Commits**: 45 (66.18%)
12-
- **Total Lines Added**: 9342
13-
- **AI-Assisted Lines Added**: 7536 (80.67%)
14-
- **Total Lines Changed**: 13812
15-
- **AI-Assisted Lines Changed**: 11238 (81.36%)
10+
- **Total Commits**: 69
11+
- **AI-Assisted Commits**: 46 (66.67%)
12+
- **Total Lines Added**: 9487
13+
- **AI-Assisted Lines Added**: 7681 (80.96%)
14+
- **Total Lines Changed**: 13978
15+
- **AI-Assisted Lines Changed**: 11404 (81.59%)
1616

1717
### Breakdown by AI Assistant
1818

1919
#### Claude Code
2020

21-
- **Commits**: 34 (50.00%)
21+
- **Commits**: 34 (49.28%)
2222
- **Lines Added**: 6156
2323
- **Lines Deleted**: 2768
24-
- **Lines Changed**: 8924 (64.61%)
24+
- **Lines Changed**: 8924 (63.84%)
2525

2626
#### Amp
2727

28-
- **Commits**: 9 (13.24%)
28+
- **Commits**: 9 (13.04%)
2929
- **Lines Added**: 1309
3030
- **Lines Deleted**: 860
31-
- **Lines Changed**: 2169 (15.70%)
31+
- **Lines Changed**: 2169 (15.52%)
3232

3333
#### GitHub Copilot
3434

35-
- **Commits**: 2 (2.94%)
35+
- **Commits**: 2 (2.90%)
3636
- **Lines Added**: 71
3737
- **Lines Deleted**: 74
38-
- **Lines Changed**: 145 (1.05%)
38+
- **Lines Changed**: 145 (1.04%)
39+
40+
#### AI (Generic)
41+
42+
- **Commits**: 1 (1.45%)
43+
- **Lines Added**: 145
44+
- **Lines Deleted**: 21
45+
- **Lines Changed**: 166 (1.19%)
3946

4047

4148
*Statistics are automatically updated on each commit.*

app/src/main/java/com/larseckart/adapters/ai/AIProviderFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static AIProvider createFromEnvironment() {
3737

3838
ApiKey apiKey =
3939
switch (type) {
40-
case ANTHROPIC -> ApiKey.fromEnvironment("code_editing_agent_api_key");
40+
case ANTHROPIC -> ApiKey.fromEnvironment("ANTHROPIC_API_KEY");
4141
case GEMINI -> ApiKey.fromEnvironment("GOOGLE_API_KEY");
4242
};
4343

app/src/main/java/com/larseckart/adapters/ai/AnthropicProvider.java

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.anthropic.client.AnthropicClient;
66
import com.anthropic.client.okhttp.AnthropicOkHttpClient;
77
import com.anthropic.core.JsonValue;
8+
import com.anthropic.errors.AnthropicServiceException;
89
import com.anthropic.models.messages.ContentBlock;
910
import com.anthropic.models.messages.MessageCreateParams;
1011
import com.anthropic.models.messages.Model;
@@ -56,7 +57,7 @@ public AIResponse sendMessage(AIRequest request) {
5657
try {
5758
var paramsBuilder =
5859
MessageCreateParams.builder()
59-
.model(Model.CLAUDE_3_5_HAIKU_LATEST)
60+
.model(Model.CLAUDE_HAIKU_4_5)
6061
.maxTokens((long) request.maxTokens())
6162
.system(request.systemPrompt());
6263

@@ -89,7 +90,7 @@ public AIResponse sendMessage(AIRequest request) {
8990
return aiResponse;
9091

9192
} catch (Exception e) {
92-
log.error("Error calling Anthropic API", e);
93+
logAnthropicError(e);
9394
throw new RuntimeException("Anthropic API call failed", e);
9495
}
9596
}
@@ -205,4 +206,39 @@ private AIResponse handleToolExecution(AIRequest originalRequest, AIResponse too
205206
throw new RuntimeException("Tool execution failed", e);
206207
}
207208
}
209+
210+
private void logAnthropicError(Exception e) {
211+
// Surface meaningful server details when available.
212+
Throwable cause = e;
213+
while (cause != null) {
214+
if (cause instanceof AnthropicServiceException serviceEx) {
215+
String bodyString = "<unavailable>";
216+
try {
217+
JsonNode bodyNode = serviceEx.body().convert(JsonNode.class);
218+
bodyString = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(bodyNode);
219+
} catch (Exception conversionError) {
220+
bodyString = String.valueOf(serviceEx.body());
221+
log.debug("Failed to convert Anthropic error body", conversionError);
222+
}
223+
224+
String requestId =
225+
serviceEx.headers().values("request-id").isEmpty()
226+
? "n/a"
227+
: serviceEx.headers().values("request-id").getFirst();
228+
229+
log.error(
230+
"Anthropic service error. status={} request-id={} message={} body={}",
231+
serviceEx.statusCode(),
232+
requestId,
233+
serviceEx.getMessage(),
234+
bodyString,
235+
e);
236+
return;
237+
}
238+
cause = cause.getCause();
239+
}
240+
241+
// Fallback logging when no structured Anthropic details are present.
242+
log.error("Error calling Anthropic API", e);
243+
}
208244
}

app/src/main/java/com/larseckart/adapters/web/WebApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public ConversationContext conversationContext() {
2323

2424
@Bean
2525
public ApiKey apiKey() {
26-
return ApiKey.fromEnvironment("code_editing_agent_api_key");
26+
return ApiKey.fromEnvironment("ANTHROPIC_API_KEY");
2727
}
2828

2929
@Bean

app/src/main/java/com/larseckart/core/tools/ListFilesTool.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ public String execute(JsonNode parameters) {
111111
}
112112
}
113113

114-
return result.toString();
114+
String string = result.toString();
115+
log.info("Tool Output: " + string);
116+
return string;
115117
} catch (IOException e) {
116118
if (e.getMessage() != null && e.getMessage().contains("ermission")) {
117119
return "Error: Permission denied - " + e.getMessage();

0 commit comments

Comments
 (0)