A CopilotSession maintains conversation state, handles events, and manages
tool execution. Sessions are created via copilot.client/create-session!
or resumed via copilot.client/resume-session!.
A CopilotSession maintains conversation state, handles events, and manages tool execution. Sessions are created via `copilot.client/create-session!` or resumed via `copilot.client/resume-session!`.
(abort! session-atom)Abort the currently processing message in this session.
Abort the currently processing message in this session.
(create-session session-id rpc-client workspace-path)Create a new session atom. Internal -- use copilot.client/create-session!.
Returns an atom containing the session state map.
Create a new session atom. Internal -- use `copilot.client/create-session!`. Returns an atom containing the session state map.
(destroy! session-atom)Destroy this session and release resources.
After calling this, the session can no longer be used.
Destroy this session and release resources. After calling this, the session can no longer be used.
(detach! session-atom)Detach from this session (session.detach) without deleting it. The
server keeps the session state, so it can be resumed later; this client
stops receiving its events and releases local resources.
Detach from this session (`session.detach`) without deleting it. The server keeps the session state, so it can be resumed later; this client stops receiving its events and releases local resources.
(dispatch-event! session-atom event)Dispatch an event to all registered handlers. Internal.
Dispatch an event to all registered handlers. Internal.
(get-managed-settings! session-atom)Get the managed (enterprise) settings snapshot in effect
(session.managedSettings.get). Use copilot.types/policy-helper-failure
on the result to read a reported policy helper failure.
Get the managed (enterprise) settings snapshot in effect (`session.managedSettings.get`). Use `copilot.types/policy-helper-failure` on the result to read a reported policy helper failure.
(get-messages! session-atom)Retrieve all events/messages from this session's history.
Retrieve all events/messages from this session's history.
(get-metadata! session-atom)Retrieve metadata for this session.
Retrieve metadata for this session.
(get-tool-handler session-atom tool-name)Get the handler function for a named tool, or nil.
Get the handler function for a named tool, or nil.
(handle-exit-plan-mode! session-atom request)Handle an incoming exitPlanMode.request. Internal. Approves when no handler is registered.
Handle an incoming exitPlanMode.request. Internal. Approves when no handler is registered.
(handle-hooks-invoke! session-atom hook-type input)Handle an incoming hooks invoke request. Internal.
Handle an incoming hooks invoke request. Internal.
(handle-memory-store! session-atom memory)Invoke the memory store callback. Internal.
Invoke the memory store callback. Internal.
(handle-permission-request! session-atom request)Handle an incoming permission request. Internal.
Handle an incoming permission request. Internal.
(handle-shell-authentication-request! session-atom request)Invoke the shell authentication handler and return the reply map. Internal. Cancels when no handler is registered or the handler throws.
Invoke the shell authentication handler and return the reply map. Internal. Cancels when no handler is registered or the handler throws.
(handle-user-input-request! session-atom request)Handle an incoming user input request. Internal.
Handle an incoming user input request. Internal.
(on! session-atom handler)Subscribe to all session events.
handler - (fn [event]) called for every event.
Returns a zero-arg unsubscribe function.
Subscribe to all session events. `handler` - (fn [event]) called for every event. Returns a zero-arg unsubscribe function.
(on-type! session-atom event-type handler)Subscribe to a specific event type.
event-type - string, e.g. "assistant.message", "session.idle"
handler - (fn [event])
Returns a zero-arg unsubscribe function.
Subscribe to a specific event type. `event-type` - string, e.g. "assistant.message", "session.idle" `handler` - (fn [event]) Returns a zero-arg unsubscribe function.
(recheck-policy-helper! session-atom)Re-run the managed-settings policy helper
(session.managedSettings.recheckPolicyHelper). Returns the raw result.
Re-run the managed-settings policy helper (`session.managedSettings.recheckPolicyHelper`). Returns the raw result.
(register-cleanup! session-atom f)Register a zero-arg fn run once when the session is destroyed or detached. Internal.
Register a zero-arg fn run once when the session is destroyed or detached. Internal.
(register-exit-plan-mode-handler! session-atom handler)Register an exit plan mode handler.
handler - (fn [request invocation] -> {:approved bool ...})
Register an exit plan mode handler.
`handler` - (fn [request invocation] -> {:approved bool ...})(register-hooks! session-atom hooks)Register session hooks.
hooks - map with optional keys:
:on-pre-tool-use, :on-post-tool-use, :on-pre-mcp-tool-call,
:on-user-prompt-submitted, :on-user-prompt-transformed,
:on-session-start, :on-session-end, :on-error-occurred,
:on-subagent-start, :on-subagent-stop
Register session hooks. `hooks` - map with optional keys: :on-pre-tool-use, :on-post-tool-use, :on-pre-mcp-tool-call, :on-user-prompt-submitted, :on-user-prompt-transformed, :on-session-start, :on-session-end, :on-error-occurred, :on-subagent-start, :on-subagent-stop
(register-memory-store! session-atom store-fn)Register the memory store callback (session option :store-memory).
store-fn - (fn [memory]) where memory is a copilot.types/stored-memory
map; throw to report a failed store.
Register the memory store callback (session option :store-memory).
`store-fn` - (fn [memory]) where `memory` is a `copilot.types/stored-memory`
map; throw to report a failed store.(register-permission-handler! session-atom handler)Register a permission handler.
handler - (fn [request invocation] -> permission-result-map)
Register a permission handler. `handler` - (fn [request invocation] -> permission-result-map)
(register-session-fs-handler! session-atom handler)Register a session filesystem handler.
handler - map with function-valued keys:
:read-file, :write-file, :append-file, :exists?, :stat,
:mkdir, :readdir, :readdir-with-types, :rm, :rename
Register a session filesystem handler. `handler` - map with function-valued keys: :read-file, :write-file, :append-file, :exists?, :stat, :mkdir, :readdir, :readdir-with-types, :rm, :rename
(register-shell-authentication-handler! session-atom handler)Register the shell authentication handler (session option :on-shell-authentication-request).
handler - (fn [request] -> value string to accept, or nil to cancel);
request is a copilot.types/shell-authentication-request map.
Register the shell authentication handler (session option
:on-shell-authentication-request).
`handler` - (fn [request] -> value string to accept, or nil to cancel);
`request` is a `copilot.types/shell-authentication-request` map.(register-tools! session-atom tools)Register tool handlers for this session.
tools - vector of tool maps (see copilot.types/tool)
Register tool handlers for this session. `tools` - vector of tool maps (see `copilot.types/tool`)
(register-trace-context-provider! session-atom provider)Register a trace context provider. provider is a zero-arg fn returning
{:traceparent s :tracestate s} (see copilot.types/trace-context); the
values are attached to every send!.
Register a trace context provider. `provider` is a zero-arg fn returning
{:traceparent s :tracestate s} (see `copilot.types/trace-context`); the
values are attached to every `send!`.(register-user-input-handler! session-atom handler)Register a user input handler.
handler - (fn [request invocation] -> {:answer str :wasFreeform bool})
Register a user input handler.
`handler` - (fn [request invocation] -> {:answer str :wasFreeform bool})(send! session-atom options)Send a message to this session.
options - message options map with :prompt and optional :attachments, :mode,
:response-format, :image-options, :agent-mode, :display-prompt,
:request-headers, :source ("user", "system", or "agent-<id>";
see copilot.types/message-source), :response-schema (JSON Schema
map for structured output; takes precedence over :response-format),
:client-turn-id (opaque caller-chosen turn identifier)
Returns the message ID string.
Send a message to this session.
`options` - message options map with :prompt and optional :attachments, :mode,
:response-format, :image-options, :agent-mode, :display-prompt,
:request-headers, :source ("user", "system", or "agent-<id>";
see `copilot.types/message-source`), :response-schema (JSON Schema
map for structured output; takes precedence over :response-format),
:client-turn-id (opaque caller-chosen turn identifier)
Returns the message ID string.(send-and-wait! session-atom options)(send-and-wait! session-atom options timeout-ms)Send a message and wait until the session becomes idle.
Returns the last assistant.message event, or nil if none received.
options - message options map with :prompt
timeout-ms - timeout in milliseconds (default 60000)
Send a message and wait until the session becomes idle. Returns the last assistant.message event, or nil if none received. `options` - message options map with :prompt `timeout-ms` - timeout in milliseconds (default 60000)
(set-permission-mode! session-atom mode)Change the permission mode (session.permissions.setMode), for example
"manual", "assisted", or "allow-all". Returns
{:success bool :mode str :reason str}; a refused change has :success false
and, when known, :reason "managed_policy"
(copilot.types/permission-mode-refusals).
Change the permission mode (`session.permissions.setMode`), for example
"manual", "assisted", or "allow-all". Returns
{:success bool :mode str :reason str}; a refused change has :success false
and, when known, :reason "managed_policy"
(`copilot.types/permission-mode-refusals`).(switch-auto-tier! session-atom tier)Change the Auto routing preference without changing the selected model
(session.model.switchAutoTier). tier is "fast", "efficiency",
"balance", or "intelligence" (see copilot.types/auto-tiers); nil
returns to the provider's default Auto routing. Returns the raw result.
Change the Auto routing preference without changing the selected model (`session.model.switchAutoTier`). `tier` is "fast", "efficiency", "balance", or "intelligence" (see `copilot.types/auto-tiers`); nil returns to the provider's default Auto routing. Returns the raw result.
(workspace-path session-atom)Get the workspace path (when infinite sessions are enabled), or nil.
Get the workspace path (when infinite sessions are enabled), or nil.
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 |