-
Notifications
You must be signed in to change notification settings - Fork 1
Port upstream PRs #908, #916, #917, #970: elicitation provider, sessionFs, event fields #81
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| (ns elicitation-provider | ||
| "Example: Acting as an elicitation provider. | ||
|
|
||
| When an MCP server or sub-agent needs user input (e.g., OAuth consent, | ||
| configuration choices), the runtime sends an elicitation request to the | ||
| SDK client. This example shows how to handle those requests. | ||
|
|
||
| The example simulates a scenario where an MCP server triggers an OAuth | ||
| consent flow — the handler prints the request and auto-approves it." | ||
| (:require [clojure.core.async :refer [chan tap go-loop <!]] | ||
| [github.copilot-sdk :as copilot :refer [evt]])) | ||
|
|
||
| ;; See examples/README.md for usage | ||
|
|
||
| (defn handle-elicitation | ||
| "Handle an elicitation request from the runtime. | ||
| In a real app this would render a UI dialog or open a browser. | ||
| Here we print the request and auto-approve." | ||
| [request {:keys [session-id]}] | ||
| (println "\n📋 Elicitation request received!") | ||
| (println " Session:" session-id) | ||
| (println " Message:" (:message request)) | ||
| (when-let [mode (:mode request)] | ||
| (println " Mode:" mode)) | ||
| (when-let [source (:elicitation-source request)] | ||
| (println " Source:" source)) | ||
| (when-let [url (:url request)] | ||
| (println " URL:" url)) | ||
| (when-let [schema (:requested-schema request)] | ||
| (println " Schema:" (pr-str schema))) | ||
|
|
||
| ;; Decide how to respond based on mode | ||
| (case (:mode request) | ||
| ;; URL mode: the server wants us to open a browser | ||
| "url" | ||
| (do | ||
| (println " → Auto-approving URL-based elicitation (would open browser)") | ||
| {:action "accept"}) | ||
|
|
||
| ;; Form mode (or nil): the server wants form field values | ||
| (if-let [props (get-in request [:requested-schema :properties])] | ||
| (do | ||
| (println " → Auto-filling form fields:") | ||
| (let [content (reduce-kv | ||
| (fn [acc field-name field-schema] | ||
| (let [field-type (get field-schema "type" (:type field-schema)) | ||
| value (case field-type | ||
| "boolean" true | ||
| "string" "auto-filled" | ||
| ("number" "integer") 42 | ||
| "auto-filled")] | ||
| (println (str " " field-name " (" field-type "): " value)) | ||
| (assoc acc (keyword field-name) value))) | ||
| {} | ||
| props)] | ||
| {:action "accept" :content content})) | ||
| (do | ||
| (println " → No schema provided, approving without content") | ||
| {:action "accept"})))) | ||
|
|
||
| (defn run | ||
| "Run a session configured as an elicitation provider. | ||
|
|
||
| The agent is asked to interact with an MCP server that may trigger | ||
| elicitation requests. Even if no elicitation is triggered (model's | ||
| choice), the handler is registered and ready." | ||
| [_] | ||
| (println "=== Elicitation Provider Example ===") | ||
| (println "This example shows how to handle elicitation requests from MCP servers.\n") | ||
| (println "The session registers an :on-elicitation-request handler that auto-approves") | ||
| (println "any elicitation requests (OAuth consent, form inputs, etc.).\n") | ||
|
|
||
| (copilot/with-client-session [session {:on-permission-request copilot/approve-all | ||
| :model "claude-haiku-4.5" | ||
| :on-elicitation-request handle-elicitation}] | ||
| ;; Check if elicitation capability is advertised | ||
| (println "Elicitation supported:" (copilot/elicitation-supported? session)) | ||
|
|
||
| (let [events-ch (chan 256) | ||
| done (promise)] | ||
| (tap (copilot/events session) events-ch) | ||
|
|
||
| (go-loop [] | ||
| (when-let [event (<! events-ch)] | ||
| (condp = (:type event) | ||
| (evt :assistant.message) | ||
| (println "\n🤖 Agent:" (get-in event [:data :content])) | ||
|
|
||
| (evt :elicitation.requested) | ||
| (println "\n🔔 Elicitation event observed:" (get-in event [:data :message])) | ||
|
|
||
| (evt :capabilities.changed) | ||
| (println "\n🔄 Capabilities changed:" (:data event)) | ||
|
|
||
| (evt :session.idle) | ||
| (deliver done true) | ||
|
|
||
| (evt :session.error) | ||
| (do | ||
| (println "❌ Error:" (get-in event [:data :message])) | ||
| (deliver done (ex-info "Session error" {:event event}))) | ||
|
|
||
| nil) | ||
| (recur))) | ||
|
|
||
| (let [prompt "Say hello and tell me what capabilities this session has."] | ||
| (println "📤 You:" prompt) | ||
| (copilot/send! session {:prompt prompt})) | ||
|
|
||
| (let [result @done] | ||
| (when (instance? Exception result) | ||
| (throw result)) | ||
| (println "\n=== Session Complete ==="))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.