From c8a9056e4a6765443fc387369e0eb754d8bf3e96 Mon Sep 17 00:00:00 2001 From: hkr04 Date: Tue, 18 Mar 2025 16:40:16 +0800 Subject: [PATCH] fix compilation error on Windows --- CMakeLists.txt | 24 ++++++++++++++++++++++++ agent/base.h | 11 ++++++++--- agent/toolcall.cpp | 2 +- config.h | 5 +++-- flow/planning.cpp | 2 +- logger.cpp | 2 ++ mcp | 2 +- schema.cpp | 2 +- schema.h | 7 ++++++- 9 files changed, 47 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 580b05c..2063d97 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,30 @@ cmake_minimum_required(VERSION 3.10) project(humanus.cpp VERSION 0.1.0) +set(CMAKE_WARN_UNUSED_CLI YES) + +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +if (NOT XCODE AND NOT MSVC AND NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") +endif() + +option(BUILD_SHARED_LIBS "build shared libraries" ${BUILD_SHARED_LIBS_DEFAULT}) + +if (WIN32) + add_compile_definitions(_CRT_SECURE_NO_WARNINGS) +endif() + +if (MSVC) + add_compile_options("$<$:/utf-8>") + add_compile_options("$<$:/utf-8>") + add_compile_options("$<$:/bigobj>") + add_compile_options("$<$:/bigobj>") + add_compile_options(/wd4244 /wd4267) +endif() + +# Set C++ standard set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) diff --git a/agent/base.h b/agent/base.h index 5f521b5..3ec1cbd 100644 --- a/agent/base.h +++ b/agent/base.h @@ -4,6 +4,11 @@ #include "../llm.h" #include "../schema.h" #include "../logger.h" +#include +#include +#include +#include +#include namespace humanus { @@ -103,7 +108,7 @@ struct BaseAgent : std::enable_shared_from_this { step_result = step(); } catch (const std::exception& e) { logger->error("Error executing step " + std::to_string(current_step) + ": " + std::string(e.what())); - state = AgentState::ERROR; + state = AgentState::ERR; break; } @@ -116,7 +121,7 @@ struct BaseAgent : std::enable_shared_from_this { if (current_step >= max_steps) { results.push_back("Terminated: Reached max steps (" + std::to_string(max_steps) + ")"); } - if (state == AgentState::ERROR) { + if (state == AgentState::ERR) { results.push_back("Terminated: Agent state is " + agent_state_map[state]); } else { state = AgentState::IDLE; // FINISHED -> IDLE @@ -182,6 +187,6 @@ struct BaseAgent : std::enable_shared_from_this { } }; -} +} // namespace humanus #endif // HUMANUS_AGENT_BASE_H diff --git a/agent/toolcall.cpp b/agent/toolcall.cpp index 27e60b1..78624a5 100644 --- a/agent/toolcall.cpp +++ b/agent/toolcall.cpp @@ -142,7 +142,7 @@ std::string ToolCallAgent::execute_tool(ToolCall tool_call) { _handle_special_tool(name, result); return observation; - } catch (const json::exception& e) { + } catch (const json::exception& /* e */) { std::string error_msg = "Error parsing arguments for " + name + ": Invalid JSON format"; logger->error( "📝 Oops! The arguments for '" + name + "' don't make sense - invalid JSON" diff --git a/config.h b/config.h index 48c6461..15f507d 100644 --- a/config.h +++ b/config.h @@ -18,8 +18,9 @@ static std::filesystem::path get_project_root() { return std::filesystem::path(__FILE__).parent_path(); } -inline const std::filesystem::path PROJECT_ROOT = get_project_root(); -inline const std::filesystem::path WORKSPACE_ROOT = PROJECT_ROOT / "workspace"; +// Windows环境下使用静态变量 +static const std::filesystem::path PROJECT_ROOT = get_project_root(); +static const std::filesystem::path WORKSPACE_ROOT = PROJECT_ROOT / "workspace"; struct LLMSettings { std::string model; diff --git a/flow/planning.cpp b/flow/planning.cpp index 989d496..80459d0 100644 --- a/flow/planning.cpp +++ b/flow/planning.cpp @@ -58,7 +58,7 @@ std::string PlanningFlow::execute(const std::string& input) { result += step_result + "\n"; // Check if agent wants to terminate - if (executor->state == AgentState::FINISHED || executor->state == AgentState::ERROR) { + if (executor->state == AgentState::FINISHED || executor->state == AgentState::ERR) { break; } } diff --git a/logger.cpp b/logger.cpp index 0a7fb05..d73efd1 100644 --- a/logger.cpp +++ b/logger.cpp @@ -1,6 +1,8 @@ #include "logger.h" +#include "config.h" #include #include +#include namespace humanus { diff --git a/mcp b/mcp index 7f9862f..5e9ff48 160000 --- a/mcp +++ b/mcp @@ -1 +1 @@ -Subproject commit 7f9862f91ca82118f31834570ee409381574eba0 +Subproject commit 5e9ff48b070a11ba20529feb22c68d0e9ef46f3d diff --git a/schema.cpp b/schema.cpp index 699c597..60d4990 100644 --- a/schema.cpp +++ b/schema.cpp @@ -6,7 +6,7 @@ std::map agent_state_map = { {AgentState::IDLE, "IDLE"}, {AgentState::RUNNING, "RUNNING"}, {AgentState::FINISHED, "FINISHED"}, - {AgentState::ERROR, "ERROR"} + {AgentState::ERR, "ERROR"} }; } // namespace humanus \ No newline at end of file diff --git a/schema.h b/schema.h index 9d35b5e..585f66c 100644 --- a/schema.h +++ b/schema.h @@ -2,6 +2,10 @@ #define HUMANUS_SCHEMA_H #include "mcp_message.h" +#include +#include +#include +#include namespace humanus { @@ -12,9 +16,10 @@ enum class AgentState { IDLE = 0, RUNNING = 1, FINISHED = 2, - ERROR = 3 + ERR = 3 // Don't use ERROR }; +// 定义全局map extern std::map agent_state_map; struct Function {