-
Notifications
You must be signed in to change notification settings - Fork 5
Upstream sync: Port 39 new commits from copilot-sdk (2026-03-24) #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
0a28670
e5ed692
ca278a8
75c7ee1
6593665
dcfa9d4
2edf741
720cc87
a912420
abf63cd
3da4948
727e767
14b6672
1324222
2d85705
698da99
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -120,6 +120,7 @@ public final class CopilotSession implements AutoCloseable { | |||||||||
| private final AtomicReference<SessionHooks> hooksHandler = new AtomicReference<>(); | ||||||||||
| private volatile EventErrorHandler eventErrorHandler; | ||||||||||
| private volatile EventErrorPolicy eventErrorPolicy = EventErrorPolicy.PROPAGATE_AND_LOG_ERRORS; | ||||||||||
| private volatile Map<String, java.util.function.Function<String, CompletableFuture<String>>> transformCallbacks; | ||||||||||
|
|
||||||||||
| /** Tracks whether this session instance has been terminated via close(). */ | ||||||||||
| private volatile boolean isTerminated = false; | ||||||||||
|
|
@@ -709,6 +710,11 @@ private void executePermissionAndRespondAsync(String requestId, PermissionReques | |||||||||
| invocation.setSessionId(sessionId); | ||||||||||
| handler.handle(permissionRequest, invocation).thenAccept(result -> { | ||||||||||
| try { | ||||||||||
| if (PermissionRequestResultKind.NO_RESULT.equals(result.getKind())) { | ||||||||||
| // Handler explicitly abstains — leave the request unanswered | ||||||||||
| // so another client can handle it. | ||||||||||
| return; | ||||||||||
| } | ||||||||||
| rpc.invoke("session.permissions.handlePendingPermissionRequest", | ||||||||||
| Map.of("sessionId", sessionId, "requestId", requestId, "result", result), Object.class); | ||||||||||
| } catch (Exception e) { | ||||||||||
|
|
@@ -867,6 +873,67 @@ void registerHooks(SessionHooks hooks) { | |||||||||
| hooksHandler.set(hooks); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Registers transform callbacks for system message sections. | ||||||||||
| * <p> | ||||||||||
| * Called internally when creating or resuming a session with | ||||||||||
| * {@link com.github.copilot.sdk.SystemMessageMode#CUSTOMIZE} and transform | ||||||||||
| * callbacks. | ||||||||||
| * | ||||||||||
| * @param callbacks | ||||||||||
| * the transform callbacks keyed by section identifier; {@code null} | ||||||||||
| * clears any previously registered callbacks | ||||||||||
| */ | ||||||||||
| void registerTransformCallbacks( | ||||||||||
| Map<String, java.util.function.Function<String, CompletableFuture<String>>> callbacks) { | ||||||||||
| this.transformCallbacks = callbacks; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Handles a {@code systemMessage.transform} RPC call from the Copilot CLI. | ||||||||||
| * <p> | ||||||||||
| * The CLI sends section content; the SDK invokes the registered transform | ||||||||||
| * callbacks and returns the transformed sections. | ||||||||||
| * | ||||||||||
| * @param sections | ||||||||||
| * JSON node containing sections keyed by section identifier | ||||||||||
| * @return a future resolving with a map of transformed sections | ||||||||||
| */ | ||||||||||
| CompletableFuture<Map<String, Object>> handleSystemMessageTransform(JsonNode sections) { | ||||||||||
| var callbacks = this.transformCallbacks; | ||||||||||
| var result = new java.util.LinkedHashMap<String, Object>(); | ||||||||||
| var futures = new ArrayList<CompletableFuture<Void>>(); | ||||||||||
|
|
||||||||||
| if (sections != null && sections.isObject()) { | ||||||||||
| sections.fields().forEachRemaining(entry -> { | ||||||||||
| String sectionId = entry.getKey(); | ||||||||||
| String content = entry.getValue().has("content") ? entry.getValue().get("content").asText("") : ""; | ||||||||||
|
|
||||||||||
| java.util.function.Function<String, CompletableFuture<String>> cb = callbacks != null | ||||||||||
| ? callbacks.get(sectionId) | ||||||||||
| : null; | ||||||||||
|
|
||||||||||
| if (cb != null) { | ||||||||||
| CompletableFuture<Void> f = cb.apply(content).exceptionally(ex -> content) | ||||||||||
| .thenAccept(transformed -> { | ||||||||||
| synchronized (result) { | ||||||||||
| result.put(sectionId, Map.of("content", transformed != null ? transformed : "")); | ||||||||||
| } | ||||||||||
| }); | ||||||||||
| futures.add(f); | ||||||||||
| } else { | ||||||||||
| result.put(sectionId, Map.of("content", content)); | ||||||||||
|
||||||||||
| result.put(sectionId, Map.of("content", content)); | |
| synchronized (result) { | |
| result.put(sectionId, Map.of("content", content)); | |
| } |
Uh oh!
There was an error while loading. Please reload this page.