CopilotClient class
Client for communicating with the Copilot CLI server.
When no transport is provided, the client automatically creates a
StdioTransport using CopilotClientOptions.cliPath and appends the
required --headless --stdio --no-auto-update flags. Additional CLI
arguments (e.g. --model) can be passed via CopilotClientOptions.cliArgs.
// Minimal — spawns CLI automatically
final client = CopilotClient(
options: CopilotClientOptions(cliPath: '/usr/local/bin/copilot'),
);
await client.start();
final session = await client.createSession(
config: SessionConfig(
model: 'gpt-4',
onPermissionRequest: approveAllPermissions,
),
);
Constructors
- CopilotClient({CopilotClientOptions options = const CopilotClientOptions(), JsonRpcTransport? transport})
- Creates a new client.
Properties
- connectionState → ConnectionState
-
Current connection state.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- isConnected → bool
-
Whether the client is connected.
no setter
- onConnectionStateChanged ↔ void Function(ConnectionState state)?
-
getter/setter pair
- onError ↔ void Function(Object error)?
-
getter/setter pair
- options → CopilotClientOptions
-
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
sessions
→ Map<
String, CopilotSession> -
Active sessions.
no setter
Methods
-
createSession(
{required SessionConfig config}) → Future< CopilotSession> - Creates a new Copilot session.
-
deleteSession(
String sessionId) → Future< void> - Deletes a session by ID.
-
forceStop(
) → Future< void> - Force-stops the client immediately without graceful session cleanup.
-
getAccountQuota(
) → Future< AccountQuota> - Gets account quota information.
-
getAuthStatus(
) → Future< GetAuthStatusResponse> - Gets the authentication status.
-
getForegroundSessionId(
) → Future< ForegroundSessionInfo> - Gets the foreground session ID and workspace path.
-
getLastSessionId(
) → Future< String?> - Gets the last session ID.
-
getStatus(
) → Future< GetStatusResponse> - Gets the CLI server status.
-
listModels(
{bool forceRefresh = false}) → Future< List< ModelInfo> > - Lists available models.
-
listSessions(
{SessionListFilter? filter}) → Future< List< SessionMetadata> > - Lists available sessions.
-
listTools(
{String? model}) → Future< List< ToolInfo> > - Lists available built-in tools.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onLifecycleEvent(
void handler(SessionLifecycleEvent event), [SessionLifecycleEventType? type]) → void Function() - Subscribe to all session lifecycle events. Returns an unsubscribe fn.
-
ping(
{String? message}) → Future< Map< String, dynamic> > - Pings the CLI server. Returns pong response.
-
refreshModelsCache(
) → Future< List< ModelInfo> > - Force-refreshes the models cache and returns the updated list.
-
resumeSession(
{required ResumeSessionConfig config}) → Future< CopilotSession> - Resumes an existing session.
-
setForegroundSessionId(
String sessionId) → Future< void> - Sets the foreground session.
-
start(
) → Future< void> - Starts the client and establishes a connection to the CLI server.
-
stop(
) → Future< List< Exception> > - Stops the client and closes all sessions.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited