Main client for interacting with the Copilot CLI.
The CopilotClient manages the connection to the Copilot CLI server and provides methods to create and manage conversation sessions. It can either spawn a CLI server process or connect to an existing server.
Main client for interacting with the Copilot CLI. The CopilotClient manages the connection to the Copilot CLI server and provides methods to create and manage conversation sessions. It can either spawn a CLI server process or connect to an existing server.
(apply-mode-defaults params mode)Apply the client mode defaults to a grouped payload. Internal; exposed for testing. In the :empty mode the empty-mode defaults are filled in where the caller left a member unset; :coding-agent leaves the payload unchanged.
Apply the client mode defaults to a grouped payload. Internal; exposed for testing. In the :empty mode the empty-mode defaults are filled in where the caller left a member unset; :coding-agent leaves the payload unchanged.
(clear-managed-settings-cache! client-atom)Clear the runtime's cached managed (enterprise) settings
(managedSettings.clearCache) so they are fetched again.
Clear the runtime's cached managed (enterprise) settings (`managedSettings.clearCache`) so they are fetched again.
(create-client & {:as opts})Create a new CopilotClient.
Returns a client map (atom-backed) that manages the CLI process, JSON-RPC connection, and sessions.
Options (all optional): :cli-path, :cli-args, :cwd, :port, :use-stdio, :cli-url, :log-level, :auto-start, :auto-restart, :env, :github-token, :use-logged-in-user, :client-info, :mode, :network
See copilot.types/client-options for full documentation.
Create a new CopilotClient. Returns a client map (atom-backed) that manages the CLI process, JSON-RPC connection, and sessions. Options (all optional): :cli-path, :cli-args, :cwd, :port, :use-stdio, :cli-url, :log-level, :auto-start, :auto-restart, :env, :github-token, :use-logged-in-user, :client-info, :mode, :network See `copilot.types/client-options` for full documentation.
(create-session! client-atom & {:as config})Create a new conversation session with the Copilot CLI.
config - session configuration map (see copilot.types/session-config)
Returns a session atom that can be used with copilot.session functions.
Create a new conversation session with the Copilot CLI. `config` - session configuration map (see `copilot.types/session-config`) Returns a session atom that can be used with `copilot.session` functions.
(delete-session! client-atom session-id)Delete a session and its data from disk.
Delete a session and its data from disk.
(force-stop! client-atom)Forcefully stop the CLI server without graceful cleanup.
Forcefully stop the CLI server without graceful cleanup.
(get-auth-status! client-atom)Get current authentication status.
Get current authentication status.
(get-foreground-session-id! client-atom)Get the foreground session ID (TUI+server mode only).
Get the foreground session ID (TUI+server mode only).
(get-last-session-id! client-atom)Get the ID of the most recently updated session.
Get the ID of the most recently updated session.
(get-mode client-atom)Get the client mode: "coding-agent" or "empty".
Get the client mode: "coding-agent" or "empty".
(get-session-metadata! client-atom session-id)Get metadata for a session by ID.
Returns the metadata map, or nil if the session is not found.
Get metadata for a session by ID. Returns the metadata map, or nil if the session is not found.
(get-state client-atom)Get the current connection state: :disconnected :connecting :connected :error
Get the current connection state: :disconnected :connecting :connected :error
(get-status! client-atom)Get CLI status including version and protocol information.
Get CLI status including version and protocol information.
(group-session-params flat resume?)Convert the flat session payload built by this SDK into the SDK protocol 4
grouped payload sent with session.create (resume? false) and
session.resume (resume? true). Internal; exposed for testing.
Protocol 4 runtimes reject the old flat keys and unknown group members but tolerate unknown root keys. Known flat keys move to their exact group.member (for example :streaming to events.streaming and :hooks true to hooks.hasHandlers); root keys and unrecognized keys stay at the top level; nil values are skipped (except an explicit :defaultProvider nil on resume, which clears the default); members invalid for the method are dropped (filesystem.trustWorkingDirectory and instructions.refreshCustomInstructions on resume, canvases.open on create); and empty groups are not emitted. Already-grouped maps are merged and their members win. The legacy single :provider becomes the named "default" connection.
Convert the flat session payload built by this SDK into the SDK protocol 4 grouped payload sent with session.create (`resume?` false) and session.resume (`resume?` true). Internal; exposed for testing. Protocol 4 runtimes reject the old flat keys and unknown group members but tolerate unknown root keys. Known flat keys move to their exact group.member (for example :streaming to events.streaming and :hooks true to hooks.hasHandlers); root keys and unrecognized keys stay at the top level; nil values are skipped (except an explicit :defaultProvider nil on resume, which clears the default); members invalid for the method are dropped (filesystem.trustWorkingDirectory and instructions.refreshCustomInstructions on resume, canvases.open on create); and empty groups are not emitted. Already-grouped maps are merged and their members win. The legacy single :provider becomes the named "default" connection.
(list-models! client-atom)List available models. Results are cached after the first call.
Returns a vector of model-info maps.
List available models. Results are cached after the first call. Returns a vector of model-info maps.
(list-sessions! client-atom)List all available sessions.
Returns a vector of session-metadata maps.
List all available sessions. Returns a vector of session-metadata maps.
(on-lifecycle! client-atom handler)Subscribe to session lifecycle events.
handler - (fn [event]) where event is a session-lifecycle-event map.
Returns a zero-arg function that unsubscribes the handler.
Subscribe to session lifecycle events. `handler` - (fn [event]) where event is a session-lifecycle-event map. Returns a zero-arg function that unsubscribes the handler.
(on-lifecycle-type! client-atom event-type handler)Subscribe to a specific session lifecycle event type.
event-type - string like "session.created", "session.deleted", etc.
handler - (fn [event])
Returns an unsubscribe function.
Subscribe to a specific session lifecycle event type. `event-type` - string like "session.created", "session.deleted", etc. `handler` - (fn [event]) Returns an unsubscribe function.
(ping! client-atom & {:keys [message]})Send a ping request to the server.
Returns {:message ... :timestamp ... :protocol-version ...}
Send a ping request to the server.
Returns {:message ... :timestamp ... :protocol-version ...}(resume-session! client-atom session-id & {:as config})Resume an existing conversation session.
session-id - the ID of the session to resume
config - optional resume configuration map
Returns a session atom.
Resume an existing conversation session. `session-id` - the ID of the session to resume `config` - optional resume configuration map Returns a session atom.
(set-foreground-session-id! client-atom session-id)Set the foreground session (TUI+server mode only).
Set the foreground session (TUI+server mode only).
(start! client-atom)Start the CLI server and establish a connection.
If the client was created with :cli-url, only establishes the connection. Otherwise spawns the CLI server process and connects via stdio or TCP.
This is called automatically when creating a session if :auto-start is true (the default).
Start the CLI server and establish a connection. If the client was created with :cli-url, only establishes the connection. Otherwise spawns the CLI server process and connects via stdio or TCP. This is called automatically when creating a session if :auto-start is true (the default).
(stop! client-atom)Stop the CLI server and close all active sessions.
Returns a vector of error messages encountered during cleanup.
Stop the CLI server and close all active sessions. Returns a vector of error messages encountered during cleanup.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |