Skip to content

Commit f414de4

Browse files
edburnsCopilot
andcommitted
Add Java scenarios: Phase 1 (size S, #1-#16)
Add 16 Java scenario implementations covering: - modes: default, minimal - prompts: system-message, reasoning-effort - sessions: streaming, infinite-sessions - tools: no-tools, tool-filtering - transport: stdio, tcp - callbacks: user-input - auth: byok-openai, byok-azure, byok-anthropic - bundling: fully-bundled, app-direct-server All scenarios compile successfully with mvn compile. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 5b9902c commit f414de4

32 files changed

Lines changed: 962 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
5+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
6+
<modelVersion>4.0.0</modelVersion>
7+
8+
<groupId>com.github.copilot.sdk.scenarios</groupId>
9+
<artifactId>scenario-auth-byok-anthropic</artifactId>
10+
<version>1.0.0</version>
11+
<packaging>jar</packaging>
12+
13+
<properties>
14+
<maven.compiler.release>17</maven.compiler.release>
15+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16+
</properties>
17+
18+
<dependencies>
19+
<dependency>
20+
<groupId>com.github</groupId>
21+
<artifactId>copilot-sdk-java</artifactId>
22+
<version>1.0.0-beta-java.5-SNAPSHOT</version>
23+
</dependency>
24+
</dependencies>
25+
</project>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import com.github.copilot.sdk.CopilotClient;
2+
import com.github.copilot.sdk.json.MessageOptions;
3+
import com.github.copilot.sdk.json.ProviderConfig;
4+
import com.github.copilot.sdk.json.SessionConfig;
5+
import com.github.copilot.sdk.json.SystemMessageConfig;
6+
import com.github.copilot.sdk.SystemMessageMode;
7+
8+
import java.util.List;
9+
10+
public class Main {
11+
public static void main(String[] args) throws Exception {
12+
var apiKey = System.getenv("ANTHROPIC_API_KEY");
13+
var model = System.getenv("ANTHROPIC_MODEL");
14+
if (model == null) model = "claude-sonnet-4-20250514";
15+
var baseUrl = System.getenv("ANTHROPIC_BASE_URL");
16+
if (baseUrl == null) baseUrl = "https://api.anthropic.com";
17+
18+
if (apiKey == null || apiKey.isEmpty()) {
19+
System.err.println("Missing ANTHROPIC_API_KEY.");
20+
System.exit(1);
21+
}
22+
23+
try (var client = new CopilotClient()) {
24+
client.start().get();
25+
var session = client.createSession(
26+
new SessionConfig()
27+
.setModel(model)
28+
.setProvider(new ProviderConfig()
29+
.setType("anthropic")
30+
.setBaseUrl(baseUrl)
31+
.setApiKey(apiKey))
32+
.setAvailableTools(List.of())
33+
.setSystemMessage(new SystemMessageConfig()
34+
.setMode(SystemMessageMode.REPLACE)
35+
.setContent("You are a helpful assistant. Answer concisely.")))
36+
.get();
37+
var response = session.sendAndWait(
38+
new MessageOptions().setPrompt("What is the capital of France?"))
39+
.get();
40+
if (response != null) {
41+
System.out.println(response.getData().content());
42+
}
43+
client.stop().get();
44+
}
45+
}
46+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
5+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
6+
<modelVersion>4.0.0</modelVersion>
7+
8+
<groupId>com.github.copilot.sdk.scenarios</groupId>
9+
<artifactId>scenario-auth-byok-azure</artifactId>
10+
<version>1.0.0</version>
11+
<packaging>jar</packaging>
12+
13+
<properties>
14+
<maven.compiler.release>17</maven.compiler.release>
15+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16+
</properties>
17+
18+
<dependencies>
19+
<dependency>
20+
<groupId>com.github</groupId>
21+
<artifactId>copilot-sdk-java</artifactId>
22+
<version>1.0.0-beta-java.5-SNAPSHOT</version>
23+
</dependency>
24+
</dependencies>
25+
</project>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import com.github.copilot.sdk.CopilotClient;
2+
import com.github.copilot.sdk.json.AzureOptions;
3+
import com.github.copilot.sdk.json.MessageOptions;
4+
import com.github.copilot.sdk.json.ProviderConfig;
5+
import com.github.copilot.sdk.json.SessionConfig;
6+
import com.github.copilot.sdk.json.SystemMessageConfig;
7+
import com.github.copilot.sdk.SystemMessageMode;
8+
9+
import java.util.List;
10+
11+
public class Main {
12+
public static void main(String[] args) throws Exception {
13+
var endpoint = System.getenv("AZURE_OPENAI_ENDPOINT");
14+
var apiKey = System.getenv("AZURE_OPENAI_API_KEY");
15+
var model = System.getenv("AZURE_OPENAI_MODEL");
16+
if (model == null) model = "claude-haiku-4.5";
17+
var apiVersion = System.getenv("AZURE_API_VERSION");
18+
if (apiVersion == null) apiVersion = "2024-10-21";
19+
20+
if (endpoint == null || endpoint.isEmpty() || apiKey == null || apiKey.isEmpty()) {
21+
System.err.println("Required: AZURE_OPENAI_ENDPOINT and AZURE_OPENAI_API_KEY");
22+
System.exit(1);
23+
}
24+
25+
try (var client = new CopilotClient()) {
26+
client.start().get();
27+
var session = client.createSession(
28+
new SessionConfig()
29+
.setModel(model)
30+
.setProvider(new ProviderConfig()
31+
.setType("azure")
32+
.setBaseUrl(endpoint)
33+
.setApiKey(apiKey)
34+
.setAzure(new AzureOptions()
35+
.setApiVersion(apiVersion)))
36+
.setAvailableTools(List.of())
37+
.setSystemMessage(new SystemMessageConfig()
38+
.setMode(SystemMessageMode.REPLACE)
39+
.setContent("You are a helpful assistant. Answer concisely.")))
40+
.get();
41+
var response = session.sendAndWait(
42+
new MessageOptions().setPrompt("What is the capital of France?"))
43+
.get();
44+
if (response != null) {
45+
System.out.println(response.getData().content());
46+
}
47+
client.stop().get();
48+
}
49+
}
50+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
5+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
6+
<modelVersion>4.0.0</modelVersion>
7+
8+
<groupId>com.github.copilot.sdk.scenarios</groupId>
9+
<artifactId>scenario-auth-byok-openai</artifactId>
10+
<version>1.0.0</version>
11+
<packaging>jar</packaging>
12+
13+
<properties>
14+
<maven.compiler.release>17</maven.compiler.release>
15+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16+
</properties>
17+
18+
<dependencies>
19+
<dependency>
20+
<groupId>com.github</groupId>
21+
<artifactId>copilot-sdk-java</artifactId>
22+
<version>1.0.0-beta-java.5-SNAPSHOT</version>
23+
</dependency>
24+
</dependencies>
25+
</project>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import com.github.copilot.sdk.CopilotClient;
2+
import com.github.copilot.sdk.json.MessageOptions;
3+
import com.github.copilot.sdk.json.ProviderConfig;
4+
import com.github.copilot.sdk.json.SessionConfig;
5+
6+
public class Main {
7+
public static void main(String[] args) throws Exception {
8+
var apiKey = System.getenv("OPENAI_API_KEY");
9+
var model = System.getenv("OPENAI_MODEL");
10+
if (model == null) model = "claude-haiku-4.5";
11+
var baseUrl = System.getenv("OPENAI_BASE_URL");
12+
if (baseUrl == null) baseUrl = "https://api.openai.com/v1";
13+
14+
if (apiKey == null || apiKey.isEmpty()) {
15+
System.err.println("Missing OPENAI_API_KEY.");
16+
System.exit(1);
17+
}
18+
19+
try (var client = new CopilotClient()) {
20+
client.start().get();
21+
var session = client.createSession(
22+
new SessionConfig()
23+
.setModel(model)
24+
.setProvider(new ProviderConfig()
25+
.setType("openai")
26+
.setBaseUrl(baseUrl)
27+
.setApiKey(apiKey)))
28+
.get();
29+
var response = session.sendAndWait(
30+
new MessageOptions().setPrompt("What is the capital of France?"))
31+
.get();
32+
if (response != null) {
33+
System.out.println(response.getData().content());
34+
}
35+
client.stop().get();
36+
}
37+
}
38+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
5+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
6+
<modelVersion>4.0.0</modelVersion>
7+
8+
<groupId>com.github.copilot.sdk.scenarios</groupId>
9+
<artifactId>scenario-bundling-app-direct-server</artifactId>
10+
<version>1.0.0</version>
11+
<packaging>jar</packaging>
12+
13+
<properties>
14+
<maven.compiler.release>17</maven.compiler.release>
15+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16+
</properties>
17+
18+
<dependencies>
19+
<dependency>
20+
<groupId>com.github</groupId>
21+
<artifactId>copilot-sdk-java</artifactId>
22+
<version>1.0.0-beta-java.5-SNAPSHOT</version>
23+
</dependency>
24+
</dependencies>
25+
</project>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import com.github.copilot.sdk.CopilotClient;
2+
import com.github.copilot.sdk.json.CopilotClientOptions;
3+
import com.github.copilot.sdk.json.MessageOptions;
4+
import com.github.copilot.sdk.json.SessionConfig;
5+
6+
public class Main {
7+
public static void main(String[] args) throws Exception {
8+
var cliUrl = System.getenv("COPILOT_CLI_URL");
9+
if (cliUrl == null) {
10+
cliUrl = "localhost:3000";
11+
}
12+
13+
try (var client = new CopilotClient(new CopilotClientOptions().setCliUrl(cliUrl))) {
14+
client.start().get();
15+
var session = client.createSession(
16+
new SessionConfig()
17+
.setModel("claude-haiku-4.5"))
18+
.get();
19+
var response = session.sendAndWait(
20+
new MessageOptions().setPrompt("What is the capital of France?"))
21+
.get();
22+
if (response != null) {
23+
System.out.println(response.getData().content());
24+
} else {
25+
System.err.println("No response content received");
26+
System.exit(1);
27+
}
28+
client.stop().get();
29+
}
30+
}
31+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
5+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
6+
<modelVersion>4.0.0</modelVersion>
7+
8+
<groupId>com.github.copilot.sdk.scenarios</groupId>
9+
<artifactId>scenario-bundling-fully-bundled</artifactId>
10+
<version>1.0.0</version>
11+
<packaging>jar</packaging>
12+
13+
<properties>
14+
<maven.compiler.release>17</maven.compiler.release>
15+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16+
</properties>
17+
18+
<dependencies>
19+
<dependency>
20+
<groupId>com.github</groupId>
21+
<artifactId>copilot-sdk-java</artifactId>
22+
<version>1.0.0-beta-java.5-SNAPSHOT</version>
23+
</dependency>
24+
</dependencies>
25+
</project>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import com.github.copilot.sdk.CopilotClient;
2+
import com.github.copilot.sdk.json.CopilotClientOptions;
3+
import com.github.copilot.sdk.json.MessageOptions;
4+
import com.github.copilot.sdk.json.SessionConfig;
5+
6+
public class Main {
7+
public static void main(String[] args) throws Exception {
8+
var cliPath = System.getenv("COPILOT_CLI_PATH");
9+
var options = new CopilotClientOptions();
10+
if (cliPath != null) {
11+
options.setCliPath(cliPath);
12+
}
13+
14+
try (var client = new CopilotClient(options)) {
15+
client.start().get();
16+
var session = client.createSession(
17+
new SessionConfig()
18+
.setModel("claude-haiku-4.5"))
19+
.get();
20+
var response = session.sendAndWait(
21+
new MessageOptions().setPrompt("What is the capital of France?"))
22+
.get();
23+
if (response != null) {
24+
System.out.println(response.getData().content());
25+
}
26+
client.stop().get();
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)