// Copyright (c) 2025 Elias Bachaalany // SPDX-License-Identifier: MIT #include #include namespace copilot { FactoryHandle define_factory( json meta, std::function run) { if (!meta.is_object() || !meta.contains("name") || !meta["name"].is_string() || meta["name"].get().empty()) { throw std::invalid_argument("factory metadata requires a non-empty name"); } if (!run) throw std::invalid_argument("factory run handler is required"); return FactoryHandle{std::move(meta), std::move(run)}; } std::future SessionFactoryApi::run( const std::string& name, json options) { options["name"] = name; return session_.invoke_typed( "session.factory.run", std::move(options)); } std::future SessionFactoryApi::resume( const std::string& run_id, json options) { options["runId"] = run_id; return session_.invoke_typed( "session.factory.resume", std::move(options)); } std::future SessionFactoryApi::get_run( const std::string& run_id) { return session_.invoke_typed( "session.factory.getRun", json{{"runId", run_id}}); } std::future SessionFactoryApi::list_runs( json options) { return session_.invoke_typed( "session.factory.listRuns", std::move(options)); } std::future SessionFactoryApi::get_run_detail( const std::string& run_id) { return session_.invoke_typed( "session.factory.getRunDetail", json{{"runId", run_id}}); } std::future SessionFactoryApi::get_run_progress( const std::string& run_id, json options) { options["runId"] = run_id; return session_.invoke_typed( "session.factory.getRunProgress", std::move(options)); } std::future SessionFactoryApi::cancel( const std::string& run_id) { return session_.invoke_typed( "session.factory.cancel", json{{"runId", run_id}}); } std::future SessionFactoryApi::run_from_tool( json params) { return session_.invoke_typed( "session.factory.runFromTool", std::move(params)); } std::future SessionFactoryApi::resume_from_tool(json params) { return session_.invoke_typed( "session.factory.resumeFromTool", std::move(params)); } } // namespace copilot