Skip to main content

Crate copilot_sdk_supercharged

Crate copilot_sdk_supercharged 

Source
Expand description

§Copilot SDK for Rust

A Rust client library for programmatic control of GitHub Copilot CLI via JSON-RPC 2.0.

This SDK communicates with the Copilot CLI server using JSON-RPC 2.0 over stdio or TCP, with Content-Length header framing (LSP protocol style).

§Quick Start

use copilot_sdk::*;

#[tokio::main]
async fn main() -> Result<(), CopilotError> {
    // Create and start a client
    let client = CopilotClient::new(CopilotClientOptions {
        cli_path: Some("/path/to/copilot-cli".to_string()),
        ..Default::default()
    });
    client.start().await?;

    // Create a session
    let session = client.create_session(SessionConfig::default()).await?;

    // Send a message and wait for completion
    let response = session.send_and_wait(
        MessageOptions {
            prompt: "What is 2 + 2?".to_string(),
            attachments: None,
            mode: None,
        },
        None,
    ).await?;

    if let Some(event) = response {
        if let Some(content) = event.assistant_message_content() {
            println!("Assistant: {}", content);
        }
    }

    // Clean up
    session.destroy().await?;
    client.stop().await?;
    Ok(())
}

Re-exports§

pub use client::CopilotClient;
pub use session::CopilotSession;
pub use session::HooksHandlerFn;
pub use session::PermissionHandlerFn;
pub use session::Subscription;
pub use session::ToolHandler;
pub use session::UserInputHandlerFn;
pub use types::*;

Modules§

client
CopilotClient - Main entry point for the Copilot SDK.
jsonrpc
JSON-RPC 2.0 client implementation for stdio and TCP transports.
sdk_protocol_version
session
CopilotSession - represents a single conversation session with the Copilot CLI.
types
Type definitions for the Copilot SDK.

Enums§

CopilotError
Error types for the Copilot SDK.