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:
@@ -1,15 +1,15 @@
|
||||
find_package(Boost REQUIRED CONFIG)
|
||||
find_package(OpenSSL REQUIRED CONFIG)
|
||||
|
||||
add_library(plugin-network SHARED src/network_plugin.cpp)
|
||||
add_library(plugin_network SHARED src/network_plugin.cpp)
|
||||
|
||||
target_link_libraries(plugin-network PRIVATE
|
||||
target_link_libraries(plugin_network PRIVATE
|
||||
dstalk
|
||||
boost::boost
|
||||
openssl::openssl
|
||||
)
|
||||
|
||||
set_target_properties(plugin-network PROPERTIES
|
||||
set_target_properties(plugin_network PROPERTIES
|
||||
PREFIX ""
|
||||
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/plugins"
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/plugins"
|
||||
|
||||
@@ -278,7 +278,13 @@ static int do_post_stream(
|
||||
beast::get_lowest_layer(stream).expires_after(
|
||||
std::chrono::seconds(ctx.request_timeout));
|
||||
http::read_some(stream, buffer, parser, ec);
|
||||
if (ec) break;
|
||||
if (ec) {
|
||||
if (ec != http::error::end_of_stream && ec != asio::error::eof) {
|
||||
if (g_host) g_host->log(DSTALK_LOG_WARN,
|
||||
"[http] stream read error: %s", ec.message().c_str());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
const std::string& full_body = parser.get().body();
|
||||
if (full_body.size() > processed) {
|
||||
@@ -301,7 +307,13 @@ static int do_post_stream(
|
||||
beast::get_lowest_layer(stream).expires_after(
|
||||
std::chrono::seconds(ctx.request_timeout));
|
||||
http::read_some(stream, buffer, parser, ec);
|
||||
if (ec) break;
|
||||
if (ec) {
|
||||
if (ec != http::error::end_of_stream && ec != asio::error::eof) {
|
||||
if (g_host) g_host->log(DSTALK_LOG_WARN,
|
||||
"[http] stream read error: %s", ec.message().c_str());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
add_library(plugin-session SHARED src/session_plugin.cpp)
|
||||
add_library(plugin_session SHARED src/session_plugin.cpp)
|
||||
|
||||
target_link_libraries(plugin-session PRIVATE dstalk)
|
||||
target_link_libraries(plugin_session PRIVATE dstalk)
|
||||
|
||||
find_package(Boost REQUIRED CONFIG)
|
||||
target_link_libraries(plugin-session PRIVATE boost::boost dstalk_boost_config)
|
||||
target_link_libraries(plugin_session PRIVATE boost::boost dstalk_boost_config)
|
||||
|
||||
set_target_properties(plugin-session PROPERTIES
|
||||
set_target_properties(plugin_session PROPERTIES
|
||||
PREFIX ""
|
||||
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/plugins"
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/plugins"
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* Copyright (c) 2026 dstalk contributors. GPLv3.
|
||||
*/
|
||||
|
||||
// plugin-session: 会话管理服务插件 / Session management service plugin
|
||||
// plugin_session: 会话管理服务插件 / Session management service plugin
|
||||
// 提供 dstalk_session_service_t vtable 实现 / Provides dstalk_session_service_t vtable implementation
|
||||
// 依赖: file_io (save/load 需要文件操作) / Depends on: file_io (save/load needs file operations)
|
||||
#include "dstalk/dstalk_host.h"
|
||||
@@ -356,7 +356,7 @@ static int on_init(const dstalk_host_api_t* host) {
|
||||
// 查询依赖服务: file_io / Query dependency service: file_io
|
||||
void* raw = host->query_service("file_io", 1);
|
||||
if (!raw) {
|
||||
host->log(DSTALK_LOG_ERROR, "[plugin-session] required service 'file_io' not found");
|
||||
host->log(DSTALK_LOG_ERROR, "[plugin_session] required service 'file_io' not found");
|
||||
return -1;
|
||||
}
|
||||
g_file_io.store(static_cast<const dstalk_file_io_service_t*>(raw), std::memory_order_release);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
add_library(plugin-tools SHARED src/tools_plugin.cpp)
|
||||
add_library(plugin_tools SHARED src/tools_plugin.cpp)
|
||||
|
||||
target_link_libraries(plugin-tools PRIVATE dstalk)
|
||||
target_link_libraries(plugin_tools PRIVATE dstalk)
|
||||
|
||||
find_package(Boost REQUIRED CONFIG)
|
||||
target_link_libraries(plugin-tools PRIVATE boost::boost dstalk_boost_config)
|
||||
target_link_libraries(plugin_tools PRIVATE boost::boost dstalk_boost_config)
|
||||
|
||||
set_target_properties(plugin-tools PROPERTIES
|
||||
set_target_properties(plugin_tools PROPERTIES
|
||||
PREFIX ""
|
||||
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/plugins"
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/plugins"
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* Copyright (c) 2026 dstalk contributors. GPLv3.
|
||||
*/
|
||||
|
||||
// plugin-tools: 工具注册服务插件 / Tool registration service plugin
|
||||
// plugin_tools: 工具注册服务插件 / Tool registration service plugin
|
||||
// 提供 dstalk_tools_service_t vtable 实现 / Provides dstalk_tools_service_t vtable implementation
|
||||
// 依赖: file_io (内置 file_read / file_write 工具) / Depends on: file_io (built-in file_read / file_write tools)
|
||||
#include "dstalk/dstalk_host.h"
|
||||
@@ -323,7 +323,7 @@ static int on_init(const dstalk_host_api_t* host) {
|
||||
// 查询依赖服务: file_io / Query dependency service: file_io
|
||||
void* raw = host->query_service("file_io", 1);
|
||||
if (!raw) {
|
||||
host->log(DSTALK_LOG_ERROR, "[plugin-tools] required service 'file_io' not found");
|
||||
host->log(DSTALK_LOG_ERROR, "[plugin_tools] required service 'file_io' not found");
|
||||
return -1;
|
||||
}
|
||||
g_file_io.store(static_cast<const dstalk_file_io_service_t*>(raw), std::memory_order_release);
|
||||
|
||||
Reference in New Issue
Block a user