Skip to main content

Crate copilot_sdk

Crate copilot_sdk 

Source
Expand description

§Copilot SDK for Rust

A Rust SDK for interacting with the GitHub Copilot CLI.

§Quick Start

use copilot_sdk::{Client, SessionConfig, SessionEventData};

#[tokio::main]
async fn main() -> copilot_sdk::Result<()> {
    let client = Client::builder().build()?;
    client.start().await?;

    let session = client.create_session(SessionConfig::default()).await?;
    let mut events = session.subscribe();

    session.send("What is the capital of France?").await?;

    while let Ok(event) = events.recv().await {
        match &event.data {
            SessionEventData::AssistantMessage(msg) => println!("{}", msg.content),
            SessionEventData::SessionIdle(_) => break,
            _ => {}
        }
    }

    client.stop().await;
    Ok(())
}

Re-exports§

pub use tools::define_tool;
pub use error::CopilotError;
pub use error::Result;
pub use types::session_lifecycle_event_types;
pub use types::AttachmentType;
pub use types::AzureOptions;
pub use types::ClientOptions;
pub use types::ConnectionState;
pub use types::CustomAgentConfig;
pub use types::ErrorOccurredHandler;
pub use types::ErrorOccurredHookInput;
pub use types::ErrorOccurredHookOutput;
pub use types::GetAuthStatusResponse;
pub use types::GetForegroundSessionResponse;
pub use types::GetStatusResponse;
pub use types::InfiniteSessionConfig;
pub use types::LogLevel;
pub use types::McpLocalServerConfig;
pub use types::McpRemoteServerConfig;
pub use types::McpServerConfig;
pub use types::MessageOptions;
pub use types::ModelBilling;
pub use types::ModelCapabilities;
pub use types::ModelInfo;
pub use types::ModelLimits;
pub use types::ModelPolicy;
pub use types::ModelSupports;
pub use types::ModelVisionLimits;
pub use types::PermissionRequest;
pub use types::PermissionRequestResult;
pub use types::PingResponse;
pub use types::PostToolUseHandler;
pub use types::PostToolUseHookInput;
pub use types::PostToolUseHookOutput;
pub use types::PreToolUseHandler;
pub use types::PreToolUseHookInput;
pub use types::PreToolUseHookOutput;
pub use types::ProviderConfig;
pub use types::ResumeSessionConfig;
pub use types::SelectionAttachment;
pub use types::SelectionPosition;
pub use types::SelectionRange;
pub use types::SessionConfig;
pub use types::SessionEndHandler;
pub use types::SessionEndHookInput;
pub use types::SessionEndHookOutput;
pub use types::SessionHooks;
pub use types::SessionLifecycleEvent;
pub use types::SessionLifecycleEventMetadata;
pub use types::SessionMetadata;
pub use types::SessionStartHandler;
pub use types::SessionStartHookInput;
pub use types::SessionStartHookOutput;
pub use types::SetForegroundSessionResponse;
pub use types::StopError;
pub use types::SystemMessageConfig;
pub use types::SystemMessageMode;
pub use types::Tool;
pub use types::ToolBinaryResult;
pub use types::ToolInvocation;
pub use types::ToolResult;
pub use types::ToolResultObject;
pub use types::UserInputInvocation;
pub use types::UserInputRequest;
pub use types::UserInputResponse;
pub use types::UserMessageAttachment;
pub use types::UserPromptSubmittedHandler;
pub use types::UserPromptSubmittedHookInput;
pub use types::UserPromptSubmittedHookOutput;
pub use types::SDK_PROTOCOL_VERSION;
pub use events::AbortData;
pub use events::AssistantIntentData;
pub use events::AssistantMessageData;
pub use events::AssistantMessageDeltaData;
pub use events::AssistantReasoningData;
pub use events::AssistantReasoningDeltaData;
pub use events::AssistantTurnEndData;
pub use events::AssistantTurnStartData;
pub use events::AssistantUsageData;
pub use events::CompactionTokensUsed;
pub use events::CustomAgentCompletedData;
pub use events::CustomAgentFailedData;
pub use events::CustomAgentSelectedData;
pub use events::CustomAgentStartedData;
pub use events::HandoffSourceType;
pub use events::HookEndData;
pub use events::HookError;
pub use events::HookStartData;
pub use events::PendingMessagesModifiedData;
pub use events::RawSessionEvent;
pub use events::RepositoryInfo;
pub use events::SessionCompactionCompleteData;
pub use events::SessionCompactionStartData;
pub use events::SessionErrorData;
pub use events::SessionEvent;
pub use events::SessionEventData;
pub use events::SessionHandoffData;
pub use events::SessionIdleData;
pub use events::SessionInfoData;
pub use events::SessionModelChangeData;
pub use events::SessionResumeData;
pub use events::SessionShutdownData;
pub use events::SessionSnapshotRewindData;
pub use events::SessionStartData;
pub use events::SessionTruncationData;
pub use events::SessionUsageInfoData;
pub use events::ShutdownCodeChanges;
pub use events::ShutdownType;
pub use events::SkillInvokedData;
pub use events::SystemMessageEventData;
pub use events::SystemMessageMetadata;
pub use events::SystemMessageRole;
pub use events::ToolExecutionCompleteData;
pub use events::ToolExecutionError;
pub use events::ToolExecutionPartialResultData;
pub use events::ToolExecutionProgressData;
pub use events::ToolExecutionStartData;
pub use events::ToolRequestItem;
pub use events::ToolResultContent;
pub use events::ToolUserRequestedData;
pub use events::UserMessageAttachmentItem;
pub use events::UserMessageData;
pub use transport::MessageFramer;
pub use transport::StdioTransport;
pub use transport::Transport;
pub use jsonrpc::JsonRpcClient;
pub use jsonrpc::JsonRpcError;
pub use jsonrpc::JsonRpcId;
pub use jsonrpc::JsonRpcRequest;
pub use jsonrpc::JsonRpcResponse;
pub use jsonrpc::NotificationHandler;
pub use jsonrpc::RequestHandler;
pub use process::find_copilot_cli;
pub use process::find_executable;
pub use process::find_node;
pub use process::is_node_script;
pub use process::CopilotProcess;
pub use process::ProcessOptions;
pub use session::EventHandler;
pub use session::EventSubscription;
pub use session::InvokeFuture;
pub use session::PermissionHandler;
pub use session::RegisteredTool;
pub use session::Session;
pub use session::ToolHandler;
pub use session::UserInputHandler;
pub use client::Client;
pub use client::ClientBuilder;
pub use client::LifecycleHandler;

Modules§

client
Copilot client for managing connections and sessions.
error
Error types for the Copilot SDK.
events
Session event types for the Copilot SDK.
jsonrpc
JSON-RPC 2.0 client for the Copilot SDK.
process
Process management for the Copilot SDK.
session
Session management for the Copilot SDK.
tools
Tool definition utilities for the Copilot SDK.
transport
Transport layer for the Copilot SDK.
types
Core types for the Copilot SDK.