mirror of
https://github.com/github/awesome-copilot.git
synced 2026-04-11 10:45:56 +00:00
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/.
35 lines
1.1 KiB
Java
35 lines
1.1 KiB
Java
///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();
|
|
}
|
|
}
|
|
}
|