Add unit tests for OpenAI plugin and establish coding standards

- Introduced comprehensive unit tests for the OpenAI plugin, covering SSE parsing, sentinel matching, delta extraction, request building, and more.
- Created a new markdown file detailing coding and naming conventions for the dstalk project, including guidelines for comments, naming rules, code organization, and memory management practices.
This commit is contained in:
2026-05-31 00:51:59 +08:00
parent f2da0f2ed4
commit f6cb51b40a
21 changed files with 343 additions and 131 deletions

View File

@@ -0,0 +1,76 @@
# dstalk 模块目录和功能说明
## 一、核心网关模块
| 目录 | 功能说明 |
|------|---------|
| `dstalk-core/` | 核心网关库dstalk.dll / libdstalk.so提供插件加载、服务注册、事件总线、配置存储、日志、内存管理 |
## 二、前端模块
| 目录 | 功能说明 |
|------|---------|
| `dstalk-cli/` | 命令行前端ANSI 终端交互、命令解析、流式对话、工具调用、批处理/管道模式 |
| `dstalk-gui/` | 图形界面前端SDL3 窗口化界面、暗色主题、流式对话(默认关闭) |
| `dstalk-web/` | Web 前端Boost.Beast HTTP + SSE 流式推送、内嵌 HTML/CSS/JS 聊天界面(默认关闭) |
## 三、插件模块
所有插件位于 `plugins/` 目录下,通过 C ABI 与核心网关通信。
### 3.1 基础插件(无依赖)
不依赖任何其他插件,可独立加载运行。
| 目录 | 服务名 | 功能说明 |
|------|--------|---------|
| `plugins/config/` | `"config"` | TOML 配置文件解析、键值读写 |
| `plugins/file-io/` | `"file_io"` | 文件读写服务 |
| `plugins/lsp/` | `"lsp"` | 语言服务器协议 JSON-RPC 客户端(诊断、悬停、补全),自行管理子进程 |
### 3.2 只依赖基础插件的插件
仅依赖 3.1 中的基础插件,不依赖同级或上层插件。
| 目录 | 服务名 | 功能说明 | 依赖 |
|------|--------|---------|------|
| `plugins/network/` | `"http"` | HTTP/HTTPS POST 和流式请求Boost.Beast + OpenSSL | `config` |
| `plugins/session/` | `"session"` | 会话消息历史管理、保存/加载、Token 计数 | `file_io` |
| `plugins/tools/` | `"tools"` | 工具注册、Schema 管理、执行分发(内置 file_read/file_write | `file_io` |
### 3.3 依赖其他插件的插件
依赖 3.2 或更多层级的插件。
| 目录 | 服务名 | 功能说明 | 依赖 |
|------|--------|---------|------|
| `plugins/context/` | `"context"` | Token 计数UTF-8 字节估算)、上下文窗口裁剪 | `session` |
| `plugins/openai/` | `"ai.openai"` | OpenAI 兼容格式 AI 接入chat/stream/tools、SSE 解析) | `http``config` |
| `plugins/anthropic/` | `"ai.anthropic"` | Anthropic Claude Messages API 接入chat/stream、SSE 解析) | `http``config` |
### 3.4 规划中的插件(尚未实现)
| 模块 | 服务名(建议) | 功能说明 | 分类 |
|------|---------------|---------|------|
| Anthropic↔OpenAI 格式转换 | `"format.convert"` | 双向请求/响应/SSE 流格式转换 | 依赖其他插件 |
| AI 自动识别接口 | `"ai.auto"` | 自动检测可用 AI 提供者并统一路由 | 依赖其他插件 |
| 数据库 | `"database"` | 数据库连接和查询服务 | 基础插件 |
## 四、插件依赖关系图
```
第一层(基础插件,无依赖):
config file_io lsp
第二层(只依赖基础插件):
network ← config
session ← file_io
tools ← file_io
第三层(依赖其他插件):
context ← session
openai ← http, config
anthropic ← http, config
```
加载顺序由 Kahn 拓扑排序自动计算。