Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/attachments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ int main()
try
{
copilot::ClientOptions options;
options.log_level = "info";
options.log_level = copilot::LogLevel::Info;

copilot::Client client(options);

Expand Down
2 changes: 1 addition & 1 deletion examples/basic_chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ int main()
{
// Create client with default options (uses stdio transport)
copilot::ClientOptions options;
options.log_level = "info";
options.log_level = copilot::LogLevel::Info;

copilot::Client client(options);

Expand Down
2 changes: 1 addition & 1 deletion examples/byok.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ int main(int argc, char* argv[])

// Create client
copilot::ClientOptions options;
options.log_level = "info";
options.log_level = copilot::LogLevel::Info;

copilot::Client client(options);

Expand Down
2 changes: 1 addition & 1 deletion examples/compaction_events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ int main()
try
{
copilot::ClientOptions options;
options.log_level = "info";
options.log_level = copilot::LogLevel::Info;

copilot::Client client(options);

Expand Down
2 changes: 1 addition & 1 deletion examples/custom_agents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ int main()
try
{
copilot::ClientOptions options;
options.log_level = "info";
options.log_level = copilot::LogLevel::Info;

copilot::Client client(options);

Expand Down
2 changes: 1 addition & 1 deletion examples/fluent_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ int main()
std::cout << "=== Starting Copilot Session ===\n\n";

ClientOptions opts;
opts.log_level = "info";
opts.log_level = LogLevel::Info;
opts.use_stdio = true;
Client client(opts);

Expand Down
2 changes: 1 addition & 1 deletion examples/list_models.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ int main()
try
{
copilot::ClientOptions options;
options.log_level = "info";
options.log_level = copilot::LogLevel::Info;

copilot::Client client(options);

Expand Down
2 changes: 1 addition & 1 deletion examples/mcp/inprocess/mcp_inprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ int main()
std::cout << "Creating Copilot SDK client...\n";

copilot::ClientOptions client_opts;
client_opts.log_level = "info";
client_opts.log_level = copilot::LogLevel::Info;

copilot::Client client(client_opts);
client.start().get();
Expand Down
2 changes: 1 addition & 1 deletion examples/mcp_servers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ int main()
try
{
copilot::ClientOptions options;
options.log_level = "info";
options.log_level = copilot::LogLevel::Info;

copilot::Client client(options);

Expand Down
2 changes: 1 addition & 1 deletion examples/permission_callback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ int main()

// Create client
copilot::ClientOptions options;
options.log_level = "info";
options.log_level = copilot::LogLevel::Info;

copilot::Client client(options);

Expand Down
2 changes: 1 addition & 1 deletion examples/reasoning_effort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int main()

// Create session with reasoning effort
copilot::SessionConfig config;
config.reasoning_effort = "medium";
config.reasoning_effort = copilot::ReasoningEffort::Medium;

// Permission handler
config.on_permission_request = [](const copilot::PermissionRequest&)
Expand Down
8 changes: 4 additions & 4 deletions examples/resume_with_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ copilot::ToolResultObject secret_handler(const copilot::ToolInvocation& invocati
if (it != secrets.end())
{
result.text_result_for_llm = "Secret value for '" + key + "': " + it->second;
result.result_type = "success";
result.result_type = copilot::ToolResultType::Success;
}
else
{
result.text_result_for_llm = "No secret found for key: " + key;
result.result_type = "failure";
result.result_type = copilot::ToolResultType::Failure;
result.error = "Key not found";
}
}
catch (const std::exception& e)
{
result.text_result_for_llm = "Error retrieving secret";
result.result_type = "failure";
result.result_type = copilot::ToolResultType::Failure;
result.error = e.what();
}

Expand All @@ -64,7 +64,7 @@ int main()
{
// Create client
copilot::ClientOptions options;
options.log_level = "info";
options.log_level = copilot::LogLevel::Info;
copilot::Client client(options);

std::cout << "=== Phase 1: Create Initial Session ===\n\n";
Expand Down
2 changes: 1 addition & 1 deletion examples/streaming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ int main(int argc, char* argv[])
{
// Create client with streaming enabled
copilot::ClientOptions options;
options.log_level = "info";
options.log_level = copilot::LogLevel::Info;

copilot::Client client(options);

Expand Down
2 changes: 1 addition & 1 deletion examples/system_prompt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ int main()
try
{
copilot::ClientOptions options;
options.log_level = "info";
options.log_level = copilot::LogLevel::Info;

copilot::Client client(options);

Expand Down
6 changes: 3 additions & 3 deletions examples/tool_progress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ copilot::ToolResultObject word_count_handler(const copilot::ToolInvocation& invo
}
catch (const std::exception& e)
{
result.result_type = "failure";
result.result_type = copilot::ToolResultType::Failure;
result.error = e.what();
result.text_result_for_llm = std::string("Error: ") + e.what();
}
Expand Down Expand Up @@ -70,7 +70,7 @@ copilot::ToolResultObject search_handler(const copilot::ToolInvocation& invocati
}
catch (const std::exception& e)
{
result.result_type = "failure";
result.result_type = copilot::ToolResultType::Failure;
result.error = e.what();
result.text_result_for_llm = std::string("Error: ") + e.what();
}
Expand All @@ -83,7 +83,7 @@ int main()
try
{
copilot::ClientOptions options;
options.log_level = "info";
options.log_level = copilot::LogLevel::Info;

copilot::Client client(options);

Expand Down
10 changes: 5 additions & 5 deletions examples/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ copilot::ToolResultObject calculate_handler(const copilot::ToolInvocation& invoc
{
if (b == 0)
{
result.result_type = "failure";
result.result_type = copilot::ToolResultType::Failure;
result.error = "Division by zero";
result.text_result_for_llm = "Error: Cannot divide by zero";
return result;
Expand All @@ -59,7 +59,7 @@ copilot::ToolResultObject calculate_handler(const copilot::ToolInvocation& invoc
}
else
{
result.result_type = "failure";
result.result_type = copilot::ToolResultType::Failure;
result.error = "Unknown operation: " + operation;
result.text_result_for_llm = "Error: Unknown operation '" + operation + "'";
return result;
Expand All @@ -72,7 +72,7 @@ copilot::ToolResultObject calculate_handler(const copilot::ToolInvocation& invoc
}
catch (const std::exception& e)
{
result.result_type = "failure";
result.result_type = copilot::ToolResultType::Failure;
result.error = e.what();
result.text_result_for_llm = std::string("Error: ") + e.what();
}
Expand Down Expand Up @@ -105,7 +105,7 @@ copilot::ToolResultObject get_time_handler(const copilot::ToolInvocation& invoca
}
catch (const std::exception& e)
{
result.result_type = "failure";
result.result_type = copilot::ToolResultType::Failure;
result.error = e.what();
result.text_result_for_llm = std::string("Error: ") + e.what();
}
Expand All @@ -132,7 +132,7 @@ int main()
{
// Create client
copilot::ClientOptions options;
options.log_level = "info";
options.log_level = copilot::LogLevel::Info;

copilot::Client client(options);

Expand Down
29 changes: 26 additions & 3 deletions include/copilot/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace copilot

// Forward declaration
class Session;
class Subscription;

// =============================================================================
// Request Builder Helpers (for unit testing request JSON shape)
Expand Down Expand Up @@ -57,7 +58,7 @@ json build_session_resume_request(const std::string& session_id, const ResumeSes
/// Example usage:
/// @code
/// ClientOptions opts;
/// opts.log_level = "debug";
/// opts.log_level = LogLevel::Debug;
///
/// Client client(opts);
/// client.start().get();
Expand Down Expand Up @@ -95,8 +96,8 @@ class Client

/// Stop the client gracefully
/// Destroys all sessions and closes the connection
/// @return Future that completes when stopped
std::future<void> stop();
/// @return Future that completes with any errors encountered during cleanup
std::future<std::vector<StopError>> stop();

/// Force stop the client immediately
/// Kills the CLI process without graceful cleanup
Expand Down Expand Up @@ -156,6 +157,24 @@ class Client
/// @throws Error if not authenticated
std::future<std::vector<ModelInfo>> list_models();

// =========================================================================
// Lifecycle Events
// =========================================================================

/// Subscribe to session lifecycle events (created, deleted, updated, foreground, background)
using LifecycleHandler = std::function<void(const SessionLifecycleEvent&)>;
Subscription on_lifecycle(LifecycleHandler handler);

// =========================================================================
// Foreground Session
// =========================================================================

/// Get the current foreground session ID
std::future<std::optional<std::string>> get_foreground_session_id();

/// Set the foreground session
std::future<void> set_foreground_session_id(const std::string& session_id);

// =========================================================================
// Internal API (used by Session)
// =========================================================================
Expand Down Expand Up @@ -221,6 +240,10 @@ class Client
// Models cache
mutable std::mutex models_cache_mutex_;
std::optional<std::vector<ModelInfo>> models_cache_;

// Lifecycle handlers
mutable std::mutex lifecycle_mutex_;
std::vector<LifecycleHandler> lifecycle_handlers_;
};

} // namespace copilot
Loading