mirror of
https://github.com/github/awesome-copilot.git
synced 2026-04-11 10:45:56 +00:00
Add Java SDK cookbook with 7 recipes
Add complete Java cookbook matching the pattern of existing .NET, Go, Node.js, and Python cookbooks. All 7 recipes included: - Ralph Loop: Autonomous AI task loops with JBang - Error Handling: try-with-resources, ExecutionException, timeouts - Multiple Sessions: Parallel sessions with CompletableFuture - Managing Local Files: AI-powered file organization - PR Visualization: Interactive PR age charts - Persisting Sessions: Save/resume with custom IDs - Accessibility Report: WCAG reports via Playwright MCP Each recipe includes both markdown documentation and a standalone JBang-runnable Java file in recipe/.
This commit is contained in:
34
cookbook/copilot-sdk/java/recipe/ErrorHandling.java
Normal file
34
cookbook/copilot-sdk/java/recipe/ErrorHandling.java
Normal file
@@ -0,0 +1,34 @@
|
||||
///usr/bin/env jbang "$0" "$@" ; exit $?
|
||||
//DEPS com.github:copilot-sdk-java:0.2.1-java.1
|
||||
|
||||
import com.github.copilot.sdk.*;
|
||||
import com.github.copilot.sdk.events.*;
|
||||
import com.github.copilot.sdk.json.*;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class ErrorHandling {
|
||||
public static void main(String[] args) {
|
||||
try (var client = new CopilotClient()) {
|
||||
client.start().get();
|
||||
|
||||
var session = client.createSession(
|
||||
new SessionConfig()
|
||||
.setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
|
||||
.setModel("gpt-5")).get();
|
||||
|
||||
session.on(AssistantMessageEvent.class,
|
||||
msg -> System.out.println(msg.getData().content()));
|
||||
|
||||
session.sendAndWait(
|
||||
new MessageOptions().setPrompt("Hello!")).get();
|
||||
|
||||
session.close();
|
||||
} catch (ExecutionException ex) {
|
||||
System.err.println("Error: " + ex.getCause().getMessage());
|
||||
ex.getCause().printStackTrace();
|
||||
} catch (Exception ex) {
|
||||
System.err.println("Error: " + ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user