Skip to main content

copilot_sdk/
lib.rs

1// Copyright (c) 2026 Elias Bachaalany
2// SPDX-License-Identifier: MIT
3
4#![forbid(unsafe_code)]
5
6//! # Copilot SDK for Rust
7//!
8//! A Rust SDK for interacting with the GitHub Copilot CLI.
9//!
10//! ## Quick Start
11//!
12//! ```no_run
13//! use copilot_sdk::{Client, SessionConfig, SessionEventData};
14//!
15//! #[tokio::main]
16//! async fn main() -> copilot_sdk::Result<()> {
17//!     let client = Client::builder().build()?;
18//!     client.start().await?;
19//!
20//!     let session = client.create_session(SessionConfig::default()).await?;
21//!     let mut events = session.subscribe();
22//!
23//!     session.send("What is the capital of France?").await?;
24//!
25//!     while let Ok(event) = events.recv().await {
26//!         match &event.data {
27//!             SessionEventData::AssistantMessage(msg) => println!("{}", msg.content),
28//!             SessionEventData::SessionIdle(_) => break,
29//!             _ => {}
30//!         }
31//!     }
32//!
33//!     client.stop().await;
34//!     Ok(())
35//! }
36//! ```
37
38pub mod client;
39pub mod error;
40pub mod events;
41pub mod jsonrpc;
42pub mod process;
43pub mod session;
44pub mod tools;
45pub mod transport;
46pub mod types;
47
48// Re-export tool utilities
49pub use tools::define_tool;
50
51// Re-export main types at crate root for convenience
52pub use error::{CopilotError, Result};
53pub use types::{
54    // Session lifecycle event type constants
55    session_lifecycle_event_types,
56    // Enums
57    AttachmentType,
58    // Config types
59    AzureOptions,
60    ClientOptions,
61    ConnectionState,
62    CustomAgentConfig,
63    // Hook types
64    ErrorOccurredHandler,
65    ErrorOccurredHookInput,
66    ErrorOccurredHookOutput,
67    // Response types
68    GetAuthStatusResponse,
69    GetForegroundSessionResponse,
70    GetStatusResponse,
71    InfiniteSessionConfig,
72    LogLevel,
73    McpLocalServerConfig,
74    McpRemoteServerConfig,
75    McpServerConfig,
76    MessageOptions,
77    ModelBilling,
78    ModelCapabilities,
79    ModelInfo,
80    ModelLimits,
81    ModelPolicy,
82    ModelSupports,
83    ModelVisionLimits,
84    // Permission types
85    PermissionRequest,
86    PermissionRequestResult,
87    PingResponse,
88    PostToolUseHandler,
89    PostToolUseHookInput,
90    PostToolUseHookOutput,
91    PreToolUseHandler,
92    PreToolUseHookInput,
93    PreToolUseHookOutput,
94    ProviderConfig,
95    ResumeSessionConfig,
96    // Selection types
97    SelectionAttachment,
98    SelectionPosition,
99    SelectionRange,
100    SessionConfig,
101    SessionEndHandler,
102    SessionEndHookInput,
103    SessionEndHookOutput,
104    SessionHooks,
105    // Session lifecycle types
106    SessionLifecycleEvent,
107    SessionLifecycleEventMetadata,
108    SessionMetadata,
109    SessionStartHandler,
110    SessionStartHookInput,
111    SessionStartHookOutput,
112    SetForegroundSessionResponse,
113    StopError,
114    SystemMessageConfig,
115    SystemMessageMode,
116    // Tool types
117    Tool,
118    ToolBinaryResult,
119    ToolInvocation,
120    ToolResult,
121    ToolResultObject,
122    // User input types
123    UserInputInvocation,
124    UserInputRequest,
125    UserInputResponse,
126    UserMessageAttachment,
127    UserPromptSubmittedHandler,
128    UserPromptSubmittedHookInput,
129    UserPromptSubmittedHookOutput,
130    // Constants
131    SDK_PROTOCOL_VERSION,
132};
133
134// Re-export event types
135pub use events::{
136    // Event data types
137    AbortData,
138    AssistantIntentData,
139    AssistantMessageData,
140    AssistantMessageDeltaData,
141    AssistantReasoningData,
142    AssistantReasoningDeltaData,
143    AssistantTurnEndData,
144    AssistantTurnStartData,
145    AssistantUsageData,
146    CompactionTokensUsed,
147    CustomAgentCompletedData,
148    CustomAgentFailedData,
149    CustomAgentSelectedData,
150    CustomAgentStartedData,
151    HandoffSourceType,
152    HookEndData,
153    HookError,
154    HookStartData,
155    PendingMessagesModifiedData,
156    // Main event types
157    RawSessionEvent,
158    RepositoryInfo,
159    SessionCompactionCompleteData,
160    SessionCompactionStartData,
161    SessionErrorData,
162    SessionEvent,
163    SessionEventData,
164    SessionHandoffData,
165    SessionIdleData,
166    SessionInfoData,
167    SessionModelChangeData,
168    SessionResumeData,
169    SessionShutdownData,
170    SessionSnapshotRewindData,
171    SessionStartData,
172    SessionTruncationData,
173    SessionUsageInfoData,
174    ShutdownCodeChanges,
175    ShutdownType,
176    SkillInvokedData,
177    SystemMessageEventData,
178    SystemMessageMetadata,
179    SystemMessageRole,
180    ToolExecutionCompleteData,
181    ToolExecutionError,
182    ToolExecutionPartialResultData,
183    ToolExecutionProgressData,
184    ToolExecutionStartData,
185    ToolRequestItem,
186    ToolResultContent,
187    ToolUserRequestedData,
188    UserMessageAttachmentItem,
189    UserMessageData,
190};
191
192// Re-export transport types
193pub use transport::{MessageFramer, StdioTransport, Transport};
194
195// Re-export JSON-RPC types
196pub use jsonrpc::{
197    JsonRpcClient, JsonRpcError, JsonRpcId, JsonRpcRequest, JsonRpcResponse, NotificationHandler,
198    RequestHandler,
199};
200
201// Re-export process types
202pub use process::{
203    find_copilot_cli, find_executable, find_node, is_node_script, CopilotProcess, ProcessOptions,
204};
205
206// Re-export session types
207pub use session::{
208    EventHandler, EventSubscription, InvokeFuture, PermissionHandler, RegisteredTool, Session,
209    ToolHandler, UserInputHandler,
210};
211
212// Re-export client types
213pub use client::{Client, ClientBuilder, LifecycleHandler};