github.copilot-sdk.client
CopilotClient - manages connection to the Copilot CLI server.
+Generated by Codox
github.copilot-sdk.client
CopilotClient - manages connection to the Copilot CLI server.
<create-session
(<create-session client config)Async version of create-session. Returns a channel that delivers a CopilotSession.
Same config options as create-session (:on-permission-request is required). Validation is performed synchronously (throws immediately on invalid config). The RPC call parks instead of blocking, making this safe to use inside go blocks.
On RPC error, delivers an ExceptionInfo to the channel (not nil). Callers should check the result with (instance? Throwable result).
@@ -21,8 +21,13 @@Options: - :cli-path - Path to CLI executable (default: “copilot”) - :cli-args - Extra arguments for CLI - :cli-url - URL of existing server (e.g., “localhost:8080”) - :cwd - Working directory for CLI process - :port - TCP port (default: 0 for random) - :use-stdio? - Use stdio transport (default: true) - :log-level - :none :error :warning :info :debug :all - :auto-start? - Auto-start on first use (default: true) - :auto-restart? - DEPRECATED: This option has no effect and will be removed in a future release. - :notification-queue-size - Max queued protocol notifications (default: 4096) - :router-queue-size - Max queued non-session notifications (default: 4096) - :tool-timeout-ms - Timeout for tool calls that return a channel (default: 120000) - :env - Environment variables map - :github-token - GitHub token for authentication (sets COPILOT_SDK_AUTH_TOKEN env var) - :use-logged-in-user? - Whether to use logged-in user auth (default: true, false when github-token provided) - :is-child-process? - When true, SDK is a child of an existing Copilot CLI process and uses stdio to communicate with it (no process spawning) - :on-list-models - Zero-arg fn returning a seq of model info maps; bypasses the RPC call and does not require start! - :telemetry - OpenTelemetry config map with optional keys :otlp-endpoint, :file-path, :exporter-type, :source-name, :capture-content? - :on-get-trace-context - Zero-arg fn returning {:traceparent … :tracestate …} for distributed trace propagation
connect-with-streams!
(connect-with-streams! client in out)Connect to a server using pre-existing input/output streams. For testing purposes only.
create-session
(create-session client config)Create a new conversation session.
-Config options (:on-permission-request is required): - :on-permission-request - Permission handler function (required, e.g. approve-all) - :session-id - Custom session ID - :client-name - Client name to identify the application (included in User-Agent header) - :model - Model to use (e.g., “gpt-5.4”) - :tools - Vector of tool definitions - :commands - Vector of command definitions (slash commands for TUI) - :system-message - System message config - :available-tools - List of allowed tool names - :excluded-tools - List of excluded tool names - :provider - Custom provider config (BYOK) - :streaming? - Enable streaming - :mcp-servers - MCP server configs map - :custom-agents - Custom agent configs - :config-dir - Override config directory for CLI (configDir) - :skill-directories - Additional skill directories to load - :disabled-skills - Disable specific skills by name - :large-output - (Experimental) Tool output handling config {:enabled :max-size-bytes :output-dir} Note: CLI protocol feature, not in official SDK. outputDir may be ignored. - :working-directory - Working directory for the session (tool operations relative to this) - :infinite-sessions - Infinite session config for automatic context compaction {:enabled (default true) :background-compaction-threshold (0.0-1.0, default 0.80) :buffer-exhaustion-threshold (0.0-1.0, default 0.95)} - :reasoning-effort - Reasoning effort level: “low”, “medium”, “high”, or “xhigh” (PR #302) - :on-user-input-request - Handler for ask_user requests (PR #269) - :on-elicitation-request - Handler for elicitation requests from the agent (upstream PRs #908, #960). When provided, sends requestElicitation=true and enables the elicitation capability. Single-arg handler receives an ElicitationContext map with :session-id, :message, :requested-schema, :mode, :elicitation-source, :url. Returns an ElicitationResult map. - :hooks - Lifecycle hooks map (PR #269): {:on-pre-tool-use, :on-post-tool-use, :on-user-prompt-submitted, :on-session-start, :on-session-end, :on-error-occurred} - :on-event - Event handler (1-arg fn) registered before the RPC call. Guarantees early events like session.start are not missed.
Config options (:on-permission-request is required): - :on-permission-request - Permission handler function (required, e.g. approve-all) - :session-id - Custom session ID - :client-name - Client name to identify the application (included in User-Agent header) - :model - Model to use (e.g., “gpt-5.4”) - :tools - Vector of tool definitions - :commands - Vector of command definitions (slash commands for TUI) - :system-message - System message config - :available-tools - List of allowed tool names - :excluded-tools - List of excluded tool names - :provider - Custom provider config (BYOK) - :streaming? - Enable streaming - :mcp-servers - MCP server configs map - :custom-agents - Custom agent configs - :config-dir - Override config directory for CLI (configDir) - :skill-directories - Additional skill directories to load - :disabled-skills - Disable specific skills by name - :large-output - (Experimental) Tool output handling config {:enabled :max-size-bytes :output-dir} Note: CLI protocol feature, not in official SDK. outputDir may be ignored. - :working-directory - Working directory for the session (tool operations relative to this) - :infinite-sessions - Infinite session config for automatic context compaction {:enabled (default true) :background-compaction-threshold (0.0-1.0, default 0.80) :buffer-exhaustion-threshold (0.0-1.0, default 0.95)} - :reasoning-effort - Reasoning effort level: “low”, “medium”, “high”, or “xhigh” (PR #302) - :on-user-input-request - Handler for ask_user requests (PR #269) - :on-elicitation-request - Handler for elicitation requests from the agent (upstream PRs #908, #960). When provided, sends requestElicitation=true and enables the elicitation capability. Single-arg handler receives an ElicitationContext map with :session-id, :message, :requested-schema, :mode, :elicitation-source, :url. Returns an ElicitationResult map. - :hooks - Lifecycle hooks map (PR #269): {:on-pre-tool-use, :on-post-tool-use, :on-user-prompt-submitted, :on-session-start, :on-session-end, :on-error-occurred} - :on-event - Event handler (1-arg fn) registered before the RPC call. Guarantees early events like session.start are not missed. - :enable-config-discovery - Boolean. Auto-discover .mcp.json, .vscode/mcp.json, skills, etc. Instruction files are always loaded regardless. (upstream PR #1044) - :model-capabilities - Model capabilities override map (upstream PR #1029). DeepPartial of model capabilities, e.g. {:model-supports {:supports-vision true}}
Returns a CopilotSession.
+default-join-session-permission-handler
(default-join-session-permission-handler _request _ctx)Default permission handler for resuming sessions.
+Returns {:kind :no-result} — the CLI handles permission decisions itself. When used with resume-session, tells the CLI that this client does NOT want to handle permission requests (requestPermission: false on the wire).
Use this when reconnecting to a session where the original client already established permission handling:
+(copilot/resume-session client session-id {:on-permission-request copilot/default-join-session-permission-handler})
+Equivalent to the upstream defaultJoinSessionPermissionHandler export.
delete-session!
(delete-session! client session-id)Permanently deletes a session and all its data from disk, including conversation history, planning state, and artifacts. Unlike disconnect!, which only releases in-memory resources and preserves session data for later resumption, this method is irreversible.
force-stop!
(force-stop! client)Force stop the CLI server without graceful cleanup.
get-auth-status
(get-auth-status client)Get current authentication status. Returns {:authenticated? :auth-type :host :login :status-message}.
@@ -42,6 +47,10 @@list-models
(list-models client)List available models with their metadata. Results are cached per client connection to prevent rate limiting under concurrency. Cache is cleared on stop!/force-stop!. When :on-list-models handler is provided in client options, calls the handler instead of the RPC method. The handler does not require a CLI connection. Requires authentication (unless :on-list-models handler is provided). Returns a vector of model info maps with keys: :id :name :vendor :family :version :max-input-tokens :max-output-tokens :preview? :default-temperature :model-picker-priority :model-capabilities {:model-supports {:supports-vision :supports-reasoning-effort} :model-limits {:max-prompt-tokens :max-context-window-tokens :vision-capabilities {:supported-media-types :max-prompt-images :max-prompt-image-size}}} :model-policy {:policy-state :terms} :model-billing {:multiplier} :supported-reasoning-efforts :default-reasoning-effort :supports-reasoning-effort (legacy flat key) :vision-limits {:supported-media-types :max-prompt-images :max-prompt-image-size} (legacy)
list-sessions
(list-sessions client)(list-sessions client filter-opts)List all available sessions. Returns a vector of session metadata maps. Optional filter map narrows results by context fields: {:cwd :git-root :repository :branch}
list-tools
(list-tools client)(list-tools client model)List available tools with their metadata. Optional :model param returns model-specific tool overrides. Returns a vector of tool info maps with keys: :name :namespaced-name :description :parameters :instructions
+mcp-config-add!
(mcp-config-add! client params)Add an MCP server configuration. params is a map with server config using plain keys (:name, :command, :args, :tools, etc.) — NOT the :mcp-prefixed keys used in session config :mcp-servers.
+mcp-config-list
(mcp-config-list client)List all MCP server configurations. Returns a map with :servers (vector of server config maps).
+mcp-config-remove!
(mcp-config-remove! client params)Remove an MCP server configuration. params is a map identifying the server using plain keys (see mcp-config-add!).
+mcp-config-update!
(mcp-config-update! client params)Update an MCP server configuration. params is a map with server config using plain keys (see mcp-config-add!).
notifications
(notifications client)Get the channel that receives non-session notifications. Notifications are dropped if the channel is full.
on-lifecycle-event
(on-lifecycle-event client handler)(on-lifecycle-event client event-type handler)Subscribe to session lifecycle events.
Two arities: (on-lifecycle-event client handler) Subscribe to ALL lifecycle events. Handler receives the full event map with keys :lifecycle-event-type, :session-id, and optionally :metadata.
@@ -50,7 +59,7 @@options
(options client)Get the client options that were used to create this client. Returns the user-provided options merged with defaults. Note: This reflects SDK configuration, not necessarily server state.
ping
(ping client)(ping client message)Ping the server to check connectivity. Returns {:message :timestamp :protocol-version}.
resume-session
(resume-session client session-id config)Resume an existing session by ID.
-Config options (:on-permission-request is required): - :on-permission-request - Permission handler function (required, e.g. approve-all) - :client-name - Client name to identify the application (included in User-Agent header) - :model - Change the model for the resumed session - :tools - Tools exposed to the CLI server - :system-message - System message configuration {:mode :content} - :available-tools - List of tool names to allow - :excluded-tools - List of tool names to disable - :provider - Custom provider configuration (BYOK) - :streaming? - Enable streaming responses - :mcp-servers - MCP server configurations - :custom-agents - Custom agent configurations - :config-dir - Override configuration directory - :skill-directories - Directories to load skills from - :disabled-skills - Skills to disable - :infinite-sessions - Infinite session configuration - :reasoning-effort - Reasoning effort level: “low”, “medium”, “high”, or “xhigh” - :on-user-input-request - Handler for ask_user requests - :on-elicitation-request - Handler for elicitation requests (upstream PRs #908, #960). Single-arg handler receives an ElicitationContext map with :session-id, :message, :requested-schema, :mode, :elicitation-source, :url. Returns an ElicitationResult map. - :hooks - Lifecycle hooks map - :on-event - Event handler (1-arg fn) registered before the RPC call. Guarantees early events like session.start are not missed.
Config options (:on-permission-request is required): - :on-permission-request - Permission handler function (required, e.g. approve-all) - :client-name - Client name to identify the application (included in User-Agent header) - :model - Change the model for the resumed session - :tools - Tools exposed to the CLI server - :system-message - System message configuration {:mode :content} - :available-tools - List of tool names to allow - :excluded-tools - List of tool names to disable - :provider - Custom provider configuration (BYOK) - :streaming? - Enable streaming responses - :mcp-servers - MCP server configurations - :custom-agents - Custom agent configurations - :config-dir - Override configuration directory - :skill-directories - Directories to load skills from - :disabled-skills - Skills to disable - :infinite-sessions - Infinite session configuration - :reasoning-effort - Reasoning effort level: “low”, “medium”, “high”, or “xhigh” - :on-user-input-request - Handler for ask_user requests - :on-elicitation-request - Handler for elicitation requests (upstream PRs #908, #960). Single-arg handler receives an ElicitationContext map with :session-id, :message, :requested-schema, :mode, :elicitation-source, :url. Returns an ElicitationResult map. - :hooks - Lifecycle hooks map - :on-event - Event handler (1-arg fn) registered before the RPC call. Guarantees early events like session.start are not missed. - :enable-config-discovery - Boolean. Auto-discover .mcp.json, skills, etc. (upstream PR #1044) - :model-capabilities - Model capabilities override map (upstream PR #1029).
Returns a CopilotSession.
set-foreground-session-id!
(set-foreground-session-id! client session-id)Set the foreground session (TUI+server mode). Requests the TUI to switch to displaying the specified session.
start!
(start! client)Start the CLI server and establish connection. Blocks until connected or throws on error.
diff --git a/doc/api/github.copilot-sdk.html b/doc/api/github.copilot-sdk.html index 21ea50c..0172123 100644 --- a/doc/api/github.copilot-sdk.html +++ b/doc/api/github.copilot-sdk.html @@ -1,6 +1,6 @@ -Generated by Codox
github.copilot-sdk
Clojure SDK for programmatic control of GitHub Copilot CLI via JSON-RPC.
+Generated by Codox
github.copilot-sdk
Clojure SDK for programmatic control of GitHub Copilot CLI via JSON-RPC.
Quick Start:
(require '[github.copilot-sdk :as copilot])
@@ -70,12 +70,14 @@
(when (copilot/confirm! session "Deploy to production?")
(println "Deploying..."))
+convert-mcp-call-tool-result
Convert an MCP CallToolResult into the SDK’s ToolResultObject format. See github.copilot-sdk.tools/convert-mcp-call-tool-result.
create-session
(create-session client config)Create a new conversation session.
Config options (:on-permission-request is required): - :on-permission-request - Permission handler function (required, e.g. approve-all) - :session-id - Custom session ID - :model - Model to use (e.g., “gpt-5.4”, “claude-sonnet-4.5”) - :tools - Vector of tool definitions (use define-tool) - :system-message - {:mode :append/:replace :content “…”} - :available-tools - List of allowed tool names - :excluded-tools - List of excluded tool names - :provider - Custom provider config (BYOK) - :streaming? - Enable streaming deltas - :mcp-servers - MCP server configs map (keyed by server ID) - :custom-agents - Custom agent configs - :config-dir - Override config directory for CLI (configDir) - :skill-directories - Additional skill directories to load - :disabled-skills - Disable specific skills by name - :large-output - (Experimental) Tool output handling config {:enabled :max-size-bytes :output-dir} Note: CLI protocol feature, not in official SDK. outputDir may be ignored. - :working-directory - Working directory for the session (tool operations relative to this)
Example:
(def session (copilot/create-session client {:on-permission-request copilot/approve-all
:model "gpt-5.4"}))
+default-join-session-permission-handler
Default permission handler for resuming sessions. Returns {:kind :no-result} — the CLI handles permissions itself. When used with resume-session, sends requestPermission: false on the wire. See github.copilot-sdk.client/default-join-session-permission-handler.
define-tool
(define-tool name opts)Define a tool with a handler function.
Arguments: - name - Tool name (string) - opts map: - :description - Tool description - :parameters - JSON schema for parameters - :handler - Function (fn args invocation -> result) - :overrides-built-in-tool - When true, overrides a built-in tool of the same name
The handler receives: - args - The parsed arguments from the LLM - invocation - Map with :session-id, :tool-call-id, :tool-name, :arguments
diff --git a/doc/api/github.copilot-sdk.session.html b/doc/api/github.copilot-sdk.session.html index 43922c8..72206de 100644 --- a/doc/api/github.copilot-sdk.session.html +++ b/doc/api/github.copilot-sdk.session.html @@ -1,14 +1,19 @@ -Generated by Codox
github.copilot-sdk.session
CopilotSession - session operations using centralized client state.
+Generated by Codox
github.copilot-sdk.session
CopilotSession - session operations using centralized client state.
All session state is stored in the client’s :state atom under: - :sessions session-id -> {:tool-handlers {} :permission-handler nil :destroyed? false :workspace-path nil} - :session-io session-id -> {:event-chan :event-mult}
Functions take client + session-id, accessing state through the client.
<send!
(<send! session opts)Send a message and return a channel that delivers the final content string. This is the async equivalent of send-and-wait! - use inside go blocks.
Options: - :timeout-ms - Timeout in milliseconds (default: 300000, set to nil to disable)
The returned channel delivers a single value (the response content) then closes.
abort!
(abort! session)Abort the currently processing message in this session.
+agent-deselect!
(agent-deselect! session)Deselect the current custom agent.
+agent-get-current
(agent-get-current session)Get the currently active custom agent for the session. Returns a map with :name (string or nil).
+agent-list
(agent-list session)List all custom agents available to the session. Returns a map with :agents (vector of agent info maps).
+agent-reload!
(agent-reload! session)Reload all custom agents.
+agent-select!
(agent-select! session agent-name)Select a custom agent by name.
capabilities
(capabilities session)Get the host capabilities reported when the session was created or resumed. Returns a map, e.g. {:ui {:elicitation true}}.
compaction-compact!
(compaction-compact! session)Trigger manual compaction of the session context.
+compaction-compact!
(compaction-compact! session)Trigger manual compaction of the session context. Note: renamed from session.compaction.compact to session.history.compact in upstream #1039.
config
(config session)Get the session configuration that was used to create this session. Returns the user-provided config. Note: This reflects what was requested, not necessarily what the server is using. The session.start event contains the actual selectedModel if validation is needed.
confirm!
(confirm! session message)Show a confirmation dialog and return the user’s boolean answer. Returns false if the user declines or cancels. Throws if the host does not support elicitation.
create-session
(create-session client session-id {:keys [tools on-permission-request on-user-input-request on-elicitation-request hooks workspace-path on-event config commands]})Create a new session. Internal use - called by client. Initializes session state in client’s atom and returns a CopilotSession handle. If :on-event is provided, taps a subscriber that forwards events to the handler on a dedicated thread. Uses a sliding buffer, so events may be dropped under extreme backpressure if the handler cannot keep up with the event rate.
@@ -26,6 +31,7 @@extensions-enable!
(extensions-enable! session extension-id)Enable an extension by its source-qualified ID.
extensions-list
(extensions-list session)List all extensions for the session. Returns a map with :extensions (vector of extension info maps).
extensions-reload!
(extensions-reload! session)Reload all extensions.
+fleet-start!
(fleet-start! session params)Start a fleet of parallel sub-sessions. params is a map forwarded to the session.fleet.start RPC.
get-current-model
(get-current-model session)Get the current model for this session. Returns the model ID string, or nil if none set.
get-messages
(get-messages session)Get all events/messages from this session’s history.
handle-command-execute!
(handle-command-execute! client session-id {:keys [command-name command args]})Handle an incoming command.execute event. Returns a channel with the result. Looks up the command handler by name and calls it with a context map. Returns {:result nil} on success or {:error message} on failure.
@@ -38,12 +44,19 @@handle-tool-call!
(handle-tool-call! client session-id tool-call-id tool-name arguments & {:keys [traceparent tracestate]})Handle an incoming tool call request. Returns a channel with the result wrapper.
handle-user-input-request!
(handle-user-input-request! client session-id request)Handle an incoming user input request (ask_user). Returns a channel with the result. PR #269 feature.
The handler should return a map with :answer (string) and optionally :was-freeform (boolean). For backwards compatibility, :response is also accepted as an alias for :answer.
+history-truncate!
(history-truncate! session)Trigger manual truncation of the session context (upstream #1039).
input!
(input! session message)(input! session message opts)Show a text input dialog. Returns the entered text, or nil if the user declines/cancels. opts is an optional map with :title, :description, :min-length, :max-length, :format, and :default keys. Throws if the host does not support elicitation.
log!
(log! session message)(log! session message opts)Log a message to the session timeline. Options (optional map): - :level - “info”, “warning”, or “error” (default: “info”) - :ephemeral? - when true, message is not persisted to disk (default: false) Returns the event ID string.
mcp-disable!
(mcp-disable! session server-name)Disable an MCP server by name.
+mcp-discover
(mcp-discover session)(mcp-discover session opts)Discover MCP servers in the working directory. opts is an optional map with :working-directory.
mcp-enable!
(mcp-enable! session server-name)Enable an MCP server by name.
mcp-list
(mcp-list session)List all MCP servers configured for the session. Returns a map with :servers (vector of server info maps).
mcp-reload!
(mcp-reload! session)Reload all MCP servers.
+mode-get
(mode-get session)Get the current agent mode for the session. Returns a map with :mode (“interactive”, “plan”, or “autopilot”).
+mode-set!
(mode-set! session mode)Set the agent mode for the session. mode should be “interactive”, “plan”, or “autopilot”.
+plan-delete!
(plan-delete! session)Delete the plan file for the session.
+plan-read
(plan-read session)Read the plan file for the session. Returns a map with :exists? (boolean), :content (string or nil), and :file-path (string or nil).
+plan-update!
(plan-update! session content)Update the plan file content for the session.
plugins-list
(plugins-list session)List all plugins for the session. Returns a map with :plugins (vector of plugin info maps).
register-transform-callbacks!
(register-transform-callbacks! client session-id callbacks)Store system message transform callbacks on a session. Callbacks is a map of wire section ID strings to 1-arity functions that receive current content and return transformed content.
remove-session!
(remove-session! client session-id)Remove a session from client state. Called on RPC failure during pre-registration.
@@ -57,6 +70,9 @@Options: - :timeout-ms - Timeout in milliseconds (default: 300000, set to nil to disable)
send-async-with-id
(send-async-with-id session opts)Send a message and return {:message-id :events-ch}.
session-id
(session-id session)Get the session ID.
+session-name-get
(session-name-get session)Get the session name (or auto-generated summary). Returns a map with :name (string or nil).
+session-name-set!
(session-name-set! session name)Set the session name (1–100 characters).
+sessions-fork!
(sessions-fork! session)Fork the current session (upstream #1039). This is a server-scoped RPC.
set-capabilities!
(set-capabilities! client session-id capabilities)Store host capabilities in session state. Called after session.create/session.resume RPC.
set-model!
(set-model! session model-id)(set-model! session model-id opts)Alias for switch-model!. Matches the upstream SDK’s setModel() API. See switch-model! for details.
set-session-fs-handler!
(set-session-fs-handler! client session-id handler)Store a sessionFs handler map on a session. Called by client during create/resume when :session-fs is enabled. Handler is a map of keyword→fn for FS operations.
@@ -72,10 +88,15 @@Drop behavior: If this subscriber’s channel buffer is full when mult tries to deliver an event, that specific event is silently dropped for this subscriber only. Other subscribers with available buffer space still receive the event. The returned channel has a buffer of 1024 events which should be sufficient for most use cases.
This is a convenience wrapper around (tap (events session) ch).
switch-model!
(switch-model! session model-id)(switch-model! session model-id opts)Switch the model for this session. The new model takes effect for the next message. Conversation history is preserved.
-Optional opts map: - :reasoning-effort - Reasoning effort level for the new model (“low”, “medium”, “high”, “xhigh”)
+Optional opts map: - :reasoning-effort - Reasoning effort level for the new model (“low”, “medium”, “high”, “xhigh”) - :model-capabilities - Model capabilities override map (upstream PR #1029) e.g. {:model-supports {:supports-vision true}}
Returns the new model ID string, or nil.
ui-elicitation!
(ui-elicitation! session params)Request structured user input via an elicitation prompt. params is a map with :message and :requested-schema keys. Throws if the host does not support elicitation.
unsubscribe-events
(unsubscribe-events session ch)Unsubscribe a channel from session events.
update-capabilities!
(update-capabilities! client session-id capability-changes)Deep-merge capability changes into the session’s capabilities map. Called when a capabilities.changed broadcast event is received.
+usage-get-metrics
(usage-get-metrics session)Get usage metrics for the session.
+workspace-create-file!
(workspace-create-file! session path content)Create a file in the session workspace. path is relative to the workspace files directory.
+workspace-get-workspace
(workspace-get-workspace session)Get current workspace metadata. Returns a map with :workspace (map or nil).
+workspace-list-files
(workspace-list-files session)List files in the session workspace directory. Returns a map with :files (vector of relative file paths).
workspace-path
(workspace-path session)Get the session workspace path when provided by the CLI.
+workspace-read-file
(workspace-read-file session path)Read a file from the session workspace. path is relative to the workspace files directory. Returns a map with :content (string).
Generated by Codox
github.copilot-sdk.tools
Helper functions for defining tools.
-define-tool
(define-tool name {:keys [description parameters handler overrides-built-in-tool]})Define a tool with a handler function.
+Generated by Codox
github.copilot-sdk.tools
Helper functions for defining tools.
+convert-mcp-call-tool-result
(convert-mcp-call-tool-result {:keys [content is-error]})Convert an MCP CallToolResult into the SDK’s ToolResultObject format.
+The input map should have Clojure-idiomatic keys: - :content - vector of content blocks, each with :type and type-specific fields - :is-error - optional boolean, when true the result-type is “failure”
+Content block types: - {:type “text” :text “…”} - {:type “image” :data “base64…” :mime-type “image/png”} - {:type “resource” :resource {:uri “…” :text “…” :blob “…” :mime-type “…”}}
+Returns a ToolResultObject map with :text-result-for-llm, :result-type, and optionally :binary-results-for-llm.
+define-tool
(define-tool name {:keys [description parameters handler overrides-built-in-tool]})Define a tool with a handler function.
Arguments: - name - Tool name (string) - opts map: - :description - Tool description - :parameters - JSON schema for parameters (or nil) - :handler - Function (fn args invocation -> result) - :overrides-built-in-tool - When true, explicitly overrides a built-in tool of the same name. Without this flag, name clashes with built-in tools cause an error.
The handler receives: - args - The parsed arguments from the LLM (no key conversion) - invocation - Map with :session-id, :tool-call-id, :tool-name, :arguments
The handler should return one of: - A string (treated as success) - A map with :text-result-for-llm and :result-type - Any other value (JSON-encoded as success) - A core.async channel that will yield one of the above
diff --git a/doc/reference/API.md b/doc/reference/API.md index e8aed62..0e18725 100644 --- a/doc/reference/API.md +++ b/doc/reference/API.md @@ -238,9 +238,9 @@ Create a client and session together, ensuring both are cleaned up on exit. | `:available-tools` | vector | List of allowed tool names | | `:excluded-tools` | vector | List of excluded tool names | | `:provider` | map | Provider config for BYOK (see [BYOK docs](../auth/byok.md)). Required key: `:base-url`. Optional: `:provider-type` (`:openai`/`:azure`/`:anthropic`), `:wire-api` (`:completions`/`:responses`), `:api-key`, `:bearer-token`, `:azure-options` | -| `:mcp-servers` | map | MCP server configs keyed by server ID (see [MCP docs](../mcp/overview.md)). Local servers: `:mcp-command`, `:mcp-args`, `:mcp-tools`. Remote servers: `:mcp-server-type` (`:http`/`:sse`), `:mcp-url`, `:mcp-tools` | +| `:mcp-servers` | map | MCP server configs keyed by server ID (see [MCP docs](../mcp/overview.md)). Local (stdio) servers: `:mcp-command`, `:mcp-args`, `:mcp-tools`. Remote (HTTP/SSE) servers: `:mcp-server-type` (`:http`/`:sse`), `:mcp-url`, `:mcp-tools`. Spec aliases: `::mcp-stdio-server` = `::mcp-local-server`, `::mcp-http-server` = `::mcp-remote-server` | | `:commands` | vector | Command definitions (slash commands). See [Commands](#commands) | -| `:custom-agents` | vector | Custom agent configs | +| `:custom-agents` | vector | Custom agent configs. Each agent map: `:agent-name` (required), `:agent-prompt` (required), `:agent-display-name`, `:agent-description`, `:agent-tools`, `:agent-infer?`, `:agent-skills` (vector of strings), `:mcp-servers` | | `:on-permission-request` | fn | **Required.** Permission handler function. Use `copilot/approve-all` to approve everything. | | `:streaming?` | boolean | Enable streaming deltas | | `:config-dir` | string | Override config directory for CLI | @@ -271,12 +271,18 @@ Resume an existing session by ID. The `config` map accepts the same options as ` |---|---|---| | `:disable-resume?` | boolean | When true, skip emitting the session.resume event (default: false) | +When `:on-permission-request` is set to `default-join-session-permission-handler`, the SDK sends `requestPermission: false` on the wire, telling the CLI that this client does not handle permission requests. Any other handler sends `requestPermission: true`. + ```clojure ;; Resume with a different model and reasoning effort (copilot/resume-session client "session-123" {:model "claude-sonnet-4" :reasoning-effort "high" :on-permission-request copilot/approve-all}) + +;; Resume without handling permissions (join-style) +(copilot/resume-session client "session-123" + {:on-permission-request copilot/default-join-session-permission-handler}) ``` #### `