Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class CopilotSDK {

// Create a session
var session = client.createSession(
new SessionConfig().setModel("claude-sonnet-4.5")).get();
new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL).setModel("claude-sonnet-4.5")).get();

// Handle assistant message events
session.on(AssistantMessageEvent.class, msg -> {
Expand Down
2 changes: 1 addition & 1 deletion jbang-example.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static void main(String[] args) throws Exception {

// Create a session
var session = client.createSession(
new SessionConfig().setModel("claude-sonnet-4.5")).get();
new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL).setModel("claude-sonnet-4.5")).get();

// Handle assistant message events
session.on(AssistantMessageEvent.class, msg -> {
Expand Down
32 changes: 16 additions & 16 deletions src/site/markdown/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ var lookupTool = ToolDefinition.create(
);

var session = client.createSession(
new SessionConfig()
new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
.setTools(List.of(lookupTool))
).get();
```
Expand All @@ -85,7 +85,7 @@ Use `APPEND` mode to add constraints while keeping default guardrails:

```java
var session = client.createSession(
new SessionConfig()
new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
.setSystemMessage(new SystemMessageConfig()
.setMode(SystemMessageMode.APPEND)
.setContent("""
Expand All @@ -103,7 +103,7 @@ Use `REPLACE` mode for complete control (removes default guardrails):

```java
var session = client.createSession(
new SessionConfig()
new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
.setSystemMessage(new SystemMessageConfig()
.setMode(SystemMessageMode.REPLACE)
.setContent("You are a helpful coding assistant."))
Expand Down Expand Up @@ -164,7 +164,7 @@ Supported providers:

```java
var session = client.createSession(
new SessionConfig()
new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
.setProvider(new ProviderConfig()
.setType("openai")
.setBaseUrl("https://api.openai.com/v1")
Expand All @@ -178,7 +178,7 @@ Some providers require bearer token authentication instead of API keys:

```java
var session = client.createSession(
new SessionConfig()
new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
.setProvider(new ProviderConfig()
.setType("openai")
.setBaseUrl("https://my-custom-endpoint.example.com/v1")
Expand All @@ -194,7 +194,7 @@ var session = client.createSession(

```java
var session = client.createSession(
new SessionConfig()
new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
.setProvider(new ProviderConfig()
.setType("openai")
.setBaseUrl("http://localhost:<PORT>/v1"))
Expand Down Expand Up @@ -248,7 +248,7 @@ When enabled (default), the session automatically compacts older messages as the

```java
var session = client.createSession(
new SessionConfig()
new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
.setInfiniteSessions(new InfiniteSessionConfig()
.setEnabled(true)
.setBackgroundCompactionThreshold(0.80) // Start compacting at 80%
Expand Down Expand Up @@ -295,7 +295,7 @@ Map<String, Object> server = Map.of(
);

var session = client.createSession(
new SessionConfig()
new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
.setMcpServers(Map.of("filesystem", server))
).get();
```
Expand All @@ -317,7 +317,7 @@ var reviewer = new CustomAgentConfig()
.setTools(List.of("read_file", "search_code"));

var session = client.createSession(
new SessionConfig()
new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
.setCustomAgents(List.of(reviewer))
).get();

Expand Down Expand Up @@ -355,7 +355,7 @@ var agents = List.of(
);

var session = client.createSession(
new SessionConfig().setCustomAgents(agents)
new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL).setCustomAgents(agents)
).get();
```

Expand All @@ -373,7 +373,7 @@ Skills are loaded from `SKILL.md` files in subdirectories of the specified skill

```java
var session = client.createSession(
new SessionConfig()
new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
.setSkillDirectories(List.of("/path/to/skills"))
).get();
```
Expand All @@ -397,7 +397,7 @@ Disable specific skills by name:

```java
var session = client.createSession(
new SessionConfig()
new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
.setSkillDirectories(List.of("/path/to/skills"))
.setDisabledSkills(List.of("my-skill"))
).get();
Expand All @@ -411,7 +411,7 @@ Use a custom configuration directory for session settings:

```java
var session = client.createSession(
new SessionConfig()
new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
.setConfigDir("/path/to/custom/config")
).get();
```
Expand All @@ -426,7 +426,7 @@ Handle user input requests when the AI uses the `ask_user` tool to gather inform

```java
var session = client.createSession(
new SessionConfig()
new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
.setOnUserInputRequest((request, invocation) -> {
System.out.println("Agent asks: " + request.getQuestion());

Expand Down Expand Up @@ -471,7 +471,7 @@ Approve or deny permission requests from the AI.

```java
var session = client.createSession(
new SessionConfig()
new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
.setOnPermissionRequest((request, invocation) -> {
// Inspect request and approve/deny
var result = new PermissionRequestResult();
Expand Down Expand Up @@ -499,7 +499,7 @@ var hooks = new SessionHooks()
});

var session = client.createSession(
new SessionConfig().setHooks(hooks)
new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL).setHooks(hooks)
).get();
```

Expand Down
6 changes: 3 additions & 3 deletions src/site/markdown/cookbook/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class BasicErrorHandling {
client.start().get();

var session = client.createSession(
new SessionConfig().setModel("gpt-5")).get();
new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL).setModel("gpt-5")).get();

session.on(AssistantMessageEvent.class, msg -> {
System.out.println(msg.getData().getContent());
Expand Down Expand Up @@ -206,7 +206,7 @@ public class TryWithResources {
client.start().get();

try (var session = client.createSession(
new SessionConfig().setModel("gpt-5")).get()) {
new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL).setModel("gpt-5")).get()) {

session.on(AssistantMessageEvent.class, msg -> {
System.out.println(msg.getData().getContent());
Expand Down Expand Up @@ -251,7 +251,7 @@ public class ToolErrorHandling {
client.start().get();

var session = client.createSession(
new SessionConfig().setTools(List.of(errorTool))).get();
new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL).setTools(List.of(errorTool))).get();

session.on(AssistantMessageEvent.class, msg -> {
System.out.println(msg.getData().getContent());
Expand Down
4 changes: 2 additions & 2 deletions src/site/markdown/cookbook/managing-local-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class ManagingLocalFiles {

// Create session
var session = client.createSession(
new SessionConfig().setModel("gpt-5")).get();
new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL).setModel("gpt-5")).get();

// Set up event handlers
var done = new CountDownLatch(1);
Expand Down Expand Up @@ -168,7 +168,7 @@ public class InteractiveFileOrganizer {
client.start().get();

var session = client.createSession(
new SessionConfig().setModel("gpt-5")).get();
new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL).setModel("gpt-5")).get();

session.on(AssistantMessageEvent.class, msg ->
System.out.println("\nCopilot: " + msg.getData().getContent())
Expand Down
14 changes: 7 additions & 7 deletions src/site/markdown/cookbook/multiple-sessions.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public class MultipleSessions {

// Create multiple independent sessions
var session1 = client.createSession(
new SessionConfig().setModel("gpt-5")).get();
new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL).setModel("gpt-5")).get();
var session2 = client.createSession(
new SessionConfig().setModel("gpt-5")).get();
new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL).setModel("gpt-5")).get();
var session3 = client.createSession(
new SessionConfig().setModel("claude-sonnet-4.5")).get();
new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL).setModel("claude-sonnet-4.5")).get();

// Set up event handlers for each session
session1.on(AssistantMessageEvent.class, msg ->
Expand Down Expand Up @@ -90,7 +90,7 @@ Use custom IDs for easier tracking:

```java
var session = client.createSession(
new SessionConfig()
new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
.setSessionId("user-123-chat")
.setModel("gpt-5")
).get();
Expand Down Expand Up @@ -129,9 +129,9 @@ public class ParallelSessions {
public static void runParallelSessions(CopilotClient client) throws Exception {
// Create sessions in parallel
var sessionFutures = List.of(
client.createSession(new SessionConfig().setModel("gpt-5")),
client.createSession(new SessionConfig().setModel("gpt-5")),
client.createSession(new SessionConfig().setModel("claude-sonnet-4.5"))
client.createSession(new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL).setModel("gpt-5")),
client.createSession(new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL).setModel("gpt-5")),
client.createSession(new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL).setModel("claude-sonnet-4.5"))
);

// Wait for all sessions to be created
Expand Down
14 changes: 7 additions & 7 deletions src/site/markdown/cookbook/persisting-sessions.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class PersistingSessions {

// Create session with a memorable ID
var session = client.createSession(
new SessionConfig()
new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
.setSessionId("user-123-conversation")
.setModel("gpt-5")
).get();
Expand Down Expand Up @@ -73,7 +73,7 @@ public class ResumeSession {
client.start().get();

// Resume the previous session
var session = client.resumeSession("user-123-conversation").get();
var session = client.resumeSession("user-123-conversation", new ResumeSessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL)).get();

session.on(AssistantMessageEvent.class, msg ->
System.out.println(msg.getData().getContent())
Expand Down Expand Up @@ -135,7 +135,7 @@ public class SessionHistory {
try (var client = new CopilotClient()) {
client.start().get();

var session = client.resumeSession("user-123-conversation").get();
var session = client.resumeSession("user-123-conversation", new ResumeSessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL)).get();

var messages = session.getMessages().get();
for (var event : messages) {
Expand Down Expand Up @@ -184,7 +184,7 @@ public class SessionManager {
System.out.print("Enter session ID: ");
String sessionId = scanner.nextLine();
session = client.createSession(
new SessionConfig()
new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
.setSessionId(sessionId)
.setModel("gpt-5")
).get();
Expand All @@ -195,7 +195,7 @@ public class SessionManager {
System.out.print("Enter session ID to resume: ");
String resumeId = scanner.nextLine();
try {
session = client.resumeSession(resumeId).get();
session = client.resumeSession(resumeId, new ResumeSessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL)).get();
System.out.println("Resumed session: " + resumeId);
} catch (Exception ex) {
System.err.println("Failed to resume session: " + ex.getMessage());
Expand Down Expand Up @@ -264,13 +264,13 @@ public class CheckSession {

if (sessionExists(client, sessionId)) {
System.out.println("Session exists, resuming...");
var session = client.resumeSession(sessionId).get();
var session = client.resumeSession(sessionId, new ResumeSessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL)).get();
// ... use session ...
session.close();
} else {
System.out.println("Session doesn't exist, creating new one...");
var session = client.createSession(
new SessionConfig().setSessionId(sessionId).setModel("gpt-5")
new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL).setSessionId(sessionId).setModel("gpt-5")
).get();
// ... use session ...
session.close();
Expand Down
2 changes: 1 addition & 1 deletion src/site/markdown/cookbook/pr-visualization.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public class PRVisualization {
""", owner, repoName, cwd);

var session = client.createSession(
new SessionConfig()
new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
.setModel("gpt-5")
.setSystemMessage(new SystemMessageConfig().setContent(systemMessage))
).get();
Expand Down
Loading
Loading