feat: add OpenAI-compatible AI provider plugin with SSE streaming support

- Implemented the OpenAI-compatible AI provider plugin, including configuration, chat, and chat_stream functionalities.
- Added support for SSE streaming and tool calls.
- Integrated Boost.JSON for JSON handling.
- Created CMake configuration for the plugin.
- Added error handling and logging throughout the plugin.
This commit is contained in:
2026-05-31 05:37:04 +08:00
parent f6cb51b40a
commit ba7382db2a
61 changed files with 163 additions and 147 deletions

View File

@@ -0,0 +1,46 @@
/* @file service_registry.hpp
* @brief Name-versioned service registry for decoupled plugin communication.
* 基于名称+版本的服务注册表,用于插件间解耦通信。
* Copyright (c) 2026 dstalk contributors. GPLv3.
*/
#pragma once
#include <mutex>
#include <shared_mutex>
#include <string>
#include <unordered_map>
namespace dstalk {
// 名称 + 最低版本服务目录 / Name + minimum-version service directory.
// 插件注册 vtable消费者按名称和版本约束查询 /
// Plugins register vtables; consumers query by name and version constraint.
// 读取query使用 shared_lock写入register/unregister使用 unique_lock /
// Reads (query) use shared_lock; writes (register/unregister) use unique_lock.
class ServiceRegistry {
public:
ServiceRegistry() = default;
~ServiceRegistry() = default;
// 注册服务 / Register a named service at a given version
int register_service(const char* name, int version, void* vtable);
// 查询服务(返回 vtable 指针,或 nullptr/ Query a service by name and minimum version
void* query_service(const char* name, int min_version) const;
// 注销服务 / Unregister a named service
void unregister_service(const char* name);
private:
struct ServiceEntry {
std::string name;
int version;
void* vtable;
};
mutable std::shared_mutex mutex_; // 读写锁query 用 sharedregister/unregister 用 unique / RW lock: shared for query, unique for register/unregister
std::unordered_map<std::string, ServiceEntry> services_;
};
} // namespace dstalk