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:
46
dstalk_core/src/service_registry.hpp
Normal file
46
dstalk_core/src/service_registry.hpp
Normal 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 用 shared,register/unregister 用 unique / RW lock: shared for query, unique for register/unregister
|
||||
std::unordered_map<std::string, ServiceEntry> services_;
|
||||
};
|
||||
|
||||
} // namespace dstalk
|
||||
Reference in New Issue
Block a user