resumeSession method

Future<CopilotSession> resumeSession({
  1. required ResumeSessionConfig config,
})

Resumes an existing session.

Implementation

Future<CopilotSession> resumeSession({
  required ResumeSessionConfig config,
}) async {
  await _autoStartIfNeeded();

  // Build payload with merged tools and sdkProtocolVersion
  final payload = config.toJson();
  if (options.tools.isNotEmpty) {
    final seen = <String>{};
    final merged = <Map<String, dynamic>>[];
    for (final t in options.tools) {
      if (seen.add(t.name)) merged.add(t.toRegistrationJson());
    }
    for (final t in config.tools) {
      if (seen.add(t.name)) merged.add(t.toRegistrationJson());
    }
    payload['tools'] = merged;
  }

  final result = await _connection!.sendRequest(
    'session.resume',
    payload,
    const Duration(seconds: 30),
  );

  final resultMap = result as Map<String, dynamic>;
  final sessionId = resultMap['sessionId'] as String;
  final workspacePath = resultMap['workspacePath'] as String?;
  final session = CopilotSession(
    sessionId: sessionId,
    connection: _connection!,
    config: SessionConfig(
      tools: config.tools,
      hooks: config.hooks ?? options.hooks,
      model: config.model,
      systemMessage: config.systemMessage,
      provider: config.provider,
      reasoningEffort: config.reasoningEffort,
      mcpServers: config.mcpServers,
      customAgents: config.customAgents,
      onPermissionRequest: config.onPermissionRequest,
      onUserInputRequest:
          config.onUserInputRequest ?? options.onUserInputRequest,
    ),
    workspacePath: workspacePath,
  );

  _sessions[sessionId] = session;
  session.onDestroyed = () => _sessions.remove(sessionId);

  return session;
}