From aa6c0654ac70279a3c3a00d37d746fabea81749b Mon Sep 17 00:00:00 2001 From: GitHub Copilot Date: Tue, 31 Mar 2026 14:36:12 +0000 Subject: [PATCH] Port onElicitationRequest handler from upstream PR #908 - Add :on-elicitation-request option to create-session and resume-session - Registers client as elicitation provider (requestElicitation on wire) - Handle elicitation.requested broadcast events in v3 protocol router - Auto-merge capabilities.changed events into session capabilities - Add handle-elicitation-request! in session.clj following same pattern as handle-user-input-request! and handle-permission-request! - Add new event types: capabilities.changed, sampling.requested, sampling.completed, session.remote_steerable_changed - Update session-config, resume-session-config, join-session-config specs to include ::on-elicitation-request Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- CHANGELOG.md | 3 ++ src/github/copilot_sdk/client.clj | 62 +++++++++++++++++++++++++++++- src/github/copilot_sdk/session.clj | 27 ++++++++++++- src/github/copilot_sdk/specs.clj | 18 ++++++--- 4 files changed, 102 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4696e3d4..8ea2cd33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. This change ## [Unreleased] ### Added (v0.2.1 sync) +- **`onElicitationRequest` handler** — new `:on-elicitation-request` option in session config (both `create-session` and `resume-session`). When provided, the session registers as an elicitation provider: the `requestElicitation` capability is advertised on the wire, and incoming `elicitation.requested` broadcast events are dispatched to the handler. The handler receives a request map `{:message :requested-schema :mode :elicitation-source :url}` and an invocation map `{:session-id}`, and must return a result map `{:action "accept"|"decline"|"cancel" :content {..}}`. On handler failure, a cancel response is automatically sent to avoid hanging requests (upstream PR #908). +- **`capabilities.changed` event handling** — sessions now automatically merge incoming `capabilities.changed` broadcast events into their stored capabilities, so `(capabilities session)` reflects the latest state as providers join/leave (upstream PR #908). +- **New event types**: `capabilities.changed`, `sampling.requested`, `sampling.completed`, `session.remote_steerable_changed` added to the event type enum (upstream PR #908). - **`steerable` field on `session.start` events** — `session.start` event data now includes optional `:steerable?` boolean field indicating whether the session supports remote steering via Mission Control. New `::steerable?` spec added (upstream PR #927). - **`get-session-metadata`** — new function on client for efficient O(1) session lookup by ID. Returns session metadata map if found, or `nil` if not found. Sends `session.getMetadata` JSON-RPC call. Shared `wire->session-metadata` helper extracted from `list-sessions` to eliminate duplication (upstream PR #899). diff --git a/src/github/copilot_sdk/client.clj b/src/github/copilot_sdk/client.clj index ba2a4e28..dcc9842e 100644 --- a/src/github/copilot_sdk/client.clj +++ b/src/github/copilot_sdk/client.clj @@ -351,7 +351,53 @@ :error (ex-message e)})))) (catch Exception _ nil)))))))) -(defn- handle-v3-broadcast-event! +(defn- handle-v3-elicitation-requested! + "Handle v3 elicitation.requested broadcast event. + Calls the session's elicitation handler and responds via the + session.ui.handlePendingElicitation RPC method. + On handler failure, sends a cancel response so the request doesn't hang." + [client session-id event] + (let [data (:data event) + request-id (:request-id data) + request (select-keys data [:message :requested-schema :mode :elicitation-source :url])] + (when request-id + (go + (try + (let [elicit-response (