-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommands.clj
More file actions
39 lines (34 loc) · 1.53 KB
/
commands.clj
File metadata and controls
39 lines (34 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
(ns commands
"Example: Registering slash commands on a session.
Commands allow users to invoke named actions via /command-name in chat.
Each command has a name, optional description, and a handler function
that receives a CommandContext map with :session-id, :command-name,
:command (raw text), and :args."
(:require [github.copilot-sdk :as copilot]))
;; See examples/README.md for usage
(defn handle-status
"Handler for /status command — prints session info."
[{:keys [session-id command-name]}]
(println (str " [" command-name "] Session: " session-id)))
(defn handle-help
"Handler for /help command — shows available commands."
[{:keys [command-name]}]
(println (str " [" command-name "] Available commands: /status, /help")))
(defn run
"Run the commands example."
[_opts]
(copilot/with-client-session
[session {:on-permission-request copilot/approve-all
:model "claude-haiku-4.5"
:commands [{:name "status"
:description "Show session status"
:command-handler handle-status}
{:name "help"
:description "List available commands"
:command-handler handle-help}]}]
(println "Session created with commands: /status, /help")
(println "Sending a message...")
(let [response (copilot/send-and-wait! session
{:prompt "Say hello briefly."})]
(println "\nAssistant:" (get-in response [:data :content]))
(println "\nDone."))))