-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathjbang-example.java
More file actions
40 lines (33 loc) · 1.48 KB
/
jbang-example.java
File metadata and controls
40 lines (33 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//DEPS io.github.copilot-community-sdk:copilot-sdk:1.0.10
import com.github.copilot.sdk.*;
import com.github.copilot.sdk.events.*;
import com.github.copilot.sdk.json.*;
import java.util.concurrent.CompletableFuture;
import static java.lang.System.out;
class CopilotSDK {
public static void main(String[] args) throws Exception {
// Create and start client
try (var client = new CopilotClient()) {
client.start().get();
// Create a session
var session = client.createSession(
new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL).setModel("claude-sonnet-4.5")).get();
// Handle assistant message events
session.on(AssistantMessageEvent.class, msg -> {
out.println(msg.getData().content());
});
// Handle session usage info events
session.on(SessionUsageInfoEvent.class, usage -> {
var data = usage.getData();
out.println("\n--- Usage Metrics ---");
out.println("Current tokens: " + (int) data.currentTokens());
out.println("Token limit: " + (int) data.tokenLimit());
out.println("Messages count: " + (int) data.messagesLength());
});
// Send a message
var completable = session.sendAndWait(new MessageOptions().setPrompt("What is 2+2?"));
// and wait for completion
completable.get();
}
}
}