Some checks failed
- Introduced `ai_endpoint_mgr` plugin to manage multiple AI provider endpoints. - Added configuration reference documentation for `config.toml`. - Implemented endpoint loading, active endpoint switching, and model mutation. - Included error handling for missing endpoints and configuration failures. - Developed unit tests covering various scenarios including error paths and concurrency.
67 lines
2.8 KiB
C++
67 lines
2.8 KiB
C++
// ============================================================================
|
||
// dstalk_frontend_common — 前端公共初始化模块
|
||
// ============================================================================
|
||
// 提供所有前端(CLI / GUI / Web)共享的启动逻辑:
|
||
// - 配置文件发现(argv / 默认路径 / 平台 fopen)
|
||
// - dstalk_init() 调用
|
||
// - 常用服务查询(ai / endpoint_mgr / session / file_io / tools / context)
|
||
// - AI 服务默认配置(从 config 读取,带 fallback)
|
||
// ============================================================================
|
||
|
||
#ifndef DSTALK_FRONTEND_COMMON_HPP
|
||
#define DSTALK_FRONTEND_COMMON_HPP
|
||
|
||
#include <string>
|
||
|
||
#include "dstalk/dstalk_host.h"
|
||
|
||
struct FrontendServices {
|
||
const dstalk_ai_service_t* ai = nullptr;
|
||
const dstalk_session_service_t* session = nullptr;
|
||
const dstalk_file_io_service_t* file_io = nullptr;
|
||
const dstalk_tools_service_t* tools = nullptr;
|
||
const dstalk_ai_endpoint_mgr_t* endpoint_mgr = nullptr; // I08: AI endpoint manager(可选)/ optional
|
||
|
||
std::string provider; // "ai.deepseek" / "ai.openai" / "ai.anthropic"
|
||
std::string model; // e.g. "deepseek-v4-pro"
|
||
std::string base_url; // e.g. "https://api.deepseek.com/v1"
|
||
std::string api_key;
|
||
|
||
// 是否已成功初始化 dstalk 核心
|
||
bool initialized = false;
|
||
};
|
||
|
||
// ---- 前端公共初始化 ----
|
||
//
|
||
// 功能:
|
||
// 1. 发现配置文件:优先 argv[1](跳过已知标志),其次 default_config(如 "config.toml")
|
||
// 2. 调用 dstalk_init(config_path)
|
||
// 3. 查询常用插件服务(ai / endpoint_mgr / session / file_io / tools)
|
||
// 4. 用 dstalk_config_get 读取 api.* 键并调用 ai->configure() 设置旧单 provider 默认值
|
||
//
|
||
// 参数:
|
||
// svc - [out] 填入查询到的服务指针和配置信息
|
||
// argc/argv - 命令行参数(可为 0/nullptr,例如 GUI 没有命令行参数)
|
||
// default_cfg- 默认配置文件名(如 "config.toml"),当 argv 未提供时使用
|
||
// skip_flags - 以 NULL 结尾的字符串数组,argv 扫描时跳过这些标志及其下一个参数
|
||
//
|
||
// 返回值:
|
||
// 0 - 成功,svc.initialized == true,至少 ai + session 已就绪
|
||
// 1 - dstalk_init 失败
|
||
// 2 - AI 服务未找到
|
||
// 3 - Session 服务未找到
|
||
//
|
||
int dstalk_frontend_init(FrontendServices& svc,
|
||
int argc = 0, char* argv[] = nullptr,
|
||
const char* default_cfg = "config.toml",
|
||
const char* const* skip_flags = nullptr);
|
||
|
||
// ---- 便捷辅助 ----
|
||
|
||
// 将 dstalk_message_t 数组的内容追加到 session 服务(一次一条)。
|
||
// 常用于 Ctrl+O 加载会话后重建前端消息列表。
|
||
// 返回实际追加的条数。
|
||
int dstalk_frontend_replay_history(FrontendServices& svc);
|
||
|
||
#endif // DSTALK_FRONTEND_COMMON_HPP
|