W17: extract ai_common shared module + fix anthropic data race + brace bugs

- New plugins_upper/ai_common/ static library: shared PluginConfig, ToolCallAccum,
  StreamContext, secure_zero, extract_host_port, serialize_tool_calls, free_chat_result
- Refactored openai/anthropic plugins to use dstalk_ai:: namespace from ai_common
- Fixed anthropic g_config raw pointer → std::atomic (data race)
- Added SSE parse error counter with threshold abort (kMaxSseParseErrors=5)
- Fixed missing closing brace in both plugins' error-body catch block
- Updated test targets: ai_common include path + link, using namespace dstalk_ai
- plugin_loader_test: added stub_unreg + service_registry.cpp for unregister_service
- Includes pre-existing uncommitted changes from prior waves

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-31 16:58:25 +08:00
parent ba7382db2a
commit 8faa02c3d5
49 changed files with 1062 additions and 413 deletions

View File

@@ -1,21 +1,21 @@
cmake_minimum_required(VERSION 3.21)
# ============================================================
# plugin-anthropic — Anthropic Claude AI 服务
# plugin_anthropic — Anthropic Claude AI 服务
# 依赖: http 服务 (查询), config 服务 (查询)
# ============================================================
add_library(plugin-anthropic SHARED
add_library(plugin_anthropic SHARED
src/anthropic_plugin.cpp
)
target_link_libraries(plugin-anthropic PRIVATE dstalk)
target_link_libraries(plugin_anthropic PRIVATE dstalk ai_common)
# Boost.JSON 用于构建/解析请求和响应
find_package(Boost REQUIRED CONFIG)
target_link_libraries(plugin-anthropic PRIVATE boost::boost dstalk_boost_config)
target_link_libraries(plugin_anthropic PRIVATE boost::boost dstalk_boost_config)
set_target_properties(plugin-anthropic PROPERTIES
set_target_properties(plugin_anthropic PROPERTIES
PREFIX ""
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/plugins"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/plugins"