Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions AGENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ npm run pack:release # 发布打包:本体 JS + 本体豹包 + 完整
4. **新增消息级能力优先做成"工具"**(`src/tool/tools/` 下新建文件导出 `registerXxx()`,在 `src/tool/tools/init.ts` 注册);敏感操作(发消息/禁言/改名等)置 `sensitive = true`;工具名不要与已有工具重复。
5. **`registerTemplateConfig` 默认值不能是空数组**,至少保留一个元素(占位用 `['']`)。
6. **配置项描述要引导用户**:写清格式、必填/可选参数、示例;配置页签按重要性排列(基础/模型/对话/消息接收/消息触发/回复/工具/记忆/图片/后端/prompt模板/资源)。
7. **模板文案放配置模板**(`src/config/configs/prompt.ts`),不要硬编码在业务逻辑。
7. **模板文案放内置模板**(`src/prompt/templates.ts`),不要硬编码在业务逻辑。
8. **日志统一走 `Logger`**(脱敏/截断),不要直接打明文密钥;网络请求统一 `withTimeout` + `fetchData`/`requestModel`,避免卡死。
9. **修改持久化类字段后检查 `validKeysMap`** 是否需要同步更新(用 `revive()` 恢复)。
10. **新增对外 API**(`globalThis.aiplugin4`)时同步更新 `docs/07-开发指南.md` 的「为其他插件提供 API」表格与示例。
Expand All @@ -58,7 +58,7 @@ npm run pack:release # 发布打包:本体 JS + 本体豹包 + 完整

## 发布流程

1. 版本推进:`src/config/static_config.ts` 的 `VERSION`、`header.txt` 的 `@version`、`sealpack/info.toml` 的 `version`(由 `scripts/prepare-sealpack.js` 自动同步)、`src/update.ts` 新增对应版本条目,走 PR 合并到 main。
1. 版本推进:`src/config/static_config/meta.ts` 的 `VERSION`、`header.txt` 的 `@version`、`sealpack/info.toml` 的 `version`(由 `scripts/prepare-sealpack.js` 自动同步)、`src/update.ts` 新增对应版本条目,走 PR 合并到 main。
2. 推送 `v<版本>` 标签 → GitHub Actions `release.yml` 自动:verify(校验标签与 VERSION/update.ts 一致)→ `node scripts/build-release.js` 打包(本体 JS + 本体豹包 + 完整豹包)→ 用 `SEALPACK_TOKEN` 发布两个豹包到 SealRepo → 从 `update.ts` 提取版本日志创建 GitHub Release。
3. 完整包依赖插件在 `scripts/deps.cjs` 的 `dependencies` 配置(`url` 为 raw 地址);包图标 `sealpack/assets/icon.png`;SealRepo Token 放仓库 secrets(`SEALPACK_TOKEN`)。

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ max_tokens = 2048
|:---:|:---|
| 图片全局识别豹语条件 | 填 `'1'` 开启所有图片自动识别转文字;或填豹语表达式限制群/用户范围 |
| 识别图片时将url转换为base64 | 永不 / 自动 / 总是,解决大模型无法正常获取 QQ 图床图片的问题 |
| 图片识别默认prompt | 识图时的默认提示词 |

### 工具

Expand Down Expand Up @@ -325,6 +324,7 @@ max_tokens = 2048
| 命令 | 使用示例 | 说明 |
|:---:|:---:|:---|
| `.ai status` | - | 查看当前会话设置 |
| `.ai help <子指令>` / `.ai <子指令> help` | `.ai help tool` | 查看子命令帮助;`.ai <子指令> help` 带更多参数时交由子命令自身处理(如 `.ai tool help <函数名>`) |
| `.ai ctxn status` | - | 查看上下文中的名字与自动修改状态 |
| `.ai ctxn set [nick/card]` | - | 将上下文中的名字设置为昵称/群名片 |
| `.ai ctxn mod <0\|1\|2>` | - | 自动修改上下文中的名字:0 不修改,1 昵称,2 群名片 |
Expand Down
2 changes: 1 addition & 1 deletion docs/01-项目概览.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ AI 骰娘4(`aiplugin4`)是运行在 SealDice 上的 JavaScript 插件,为骰娘

## 版本信息

- `src/config/static_config.ts` 中 `VERSION = "4.15.0"`,作者 `baiyu&错误`,插件名 `aiplugin4`。
- `src/config/static_config/meta.ts` 中 `VERSION = "4.15.0"`,作者 `baiyu&错误`,插件名 `aiplugin4`。
- 开发遵循「分支 + squash PR」流程(见 [07-开发指南](07-开发指南.md));近期工作围绕:模型配置 TOML 化、Provider 统一请求(超时/重试/用量上报)、智能体编排重构、MCP/技能、日志治理、消息管线、配套后端独立仓库化等。
- README 顶部徽章与 `VERSION` 保持一致(当前 4.15.0)(详见 [09-注意事项与常见问题](09-注意事项与常见问题.md))。

Expand Down
4 changes: 2 additions & 2 deletions docs/02-架构设计.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
┌──────────────────────────────────────────────────────────────┐
│ 智能体 src/agent/agent.ts │
│ run() / runStream():构建消息 → 请求模型 → 工具调用循环 → 回复 │
轮次上限(MAX_TOOL_TURNS=10)、复读检测、最多尝试 3 次
工具轮数由配置 MAX_CALL_COUNT 控制(0 不限制)、复读检测、最多尝试 3 次 │
└───────────────┬──────────────────────────────────────────────┘
┌──────────────────────────────────────────────────────────────┐
Expand Down Expand Up @@ -103,7 +103,7 @@
3. `Agent.run()`:
- `handleMessages()` 组装请求消息:system prompt(分节)+ 示例对话 + 会话上下文(按 `INSERT_COUNT` 周期插入 system、按 `MAX_CONTEXT_TOKENS` 裁剪、过滤无回调的 tool_calls)。
- `streamService.sendChatRequest()` 请求模型。
- 若开启函数调用且返回 `tool_calls`(或提示词工程模式匹配 ```function 代码块),先发送已生成文本,把工具调用写入上下文,执行工具(`ToolRunner`),把回调写回上下文,然后进入下一轮,直至模型给出最终回复或达到 `MAX_TOOL_TURNS`
- 若开启函数调用且返回 `tool_calls`(或提示词工程模式匹配 ```function 代码块),先发送已生成文本,把工具调用写入上下文,执行工具(`ToolRunner`),把回调写回上下文,然后进入下一轮,直至模型给出最终回复(工具轮数由「允许连续调用函数次数」配置控制,0 为不限制)
- `checkRepeat()` 检测复读,检测到则重新请求,一轮对话最多尝试 3 次(含首次)。
4. `Session.reply()`:对每段回复调用 `replyToSender` 发送(ob11 依赖可用时拿到 message_id),把助手消息写入上下文。
5. 上下文写入助手消息时触发记忆权重更新与短期记忆总结检查(`SUMMARY_INTERVAL`),最后 `session.save()` 持久化。
Expand Down
10 changes: 5 additions & 5 deletions docs/03-核心模块详解.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@
- 读取带缓存:`CONFIG_CACHE_TTL = 60000` 毫秒,`Object.defineProperty` 把 `Config.<分组>` 变为缓存 getter;`ModelConfig.get()` 在注册时预热并同步模型静态列表。
- `getRegexConfig()`:把模板配置的多行正则拼接为单个 `RegExp`,失败时返回永不匹配的 `/(?!)/`。

### static_config.ts(静态常量)
### static_config/(静态常量)

- `VERSION`(当前 4.15.0)、`AUTHOR`、`NAME`、`STORAGE_VERSION`、`CONFIG_CACHE_TTL`、`CQ_TYPES_ALLOW`。
- `PRIVILEGE_LEVEL_MAP`:master=100 / whitelist=70 / owner=60 / admin=50 / inviter=40 / user=0 / blacklist=-30。
- `HELP_MAP`、`ALIAS_MAP`(命令别名表)、`FACE_MAP`(QQ 表情编号 → 名称)。
- `PROVIDER_MAP`:10 家厂商的 OpenAI 兼容 base_url。
- `CHAT_MODEL_MAP` / `IMAGE_MODEL_MAP` / `EMBEDDING_MODEL_MAP` 及反向映射:模型名 → 提供商自动识别。
- `DEFAULT_CHAT_MODEL_BODY` / `DEFAULT_IMAGE_MODEL_BODY` / `DEFAULT_EMBEDDING_MODEL_BODY`:默认请求体兜底。
- 按类别拆分为 `meta.ts`(版本/作者/插件名/缓存 TTL/存储版本)、`cq.ts`、`permission.ts`、`help.ts`、`alias.ts`、`face.ts`、`providers.ts`(厂商与模型映射)、`model_defaults.ts`、`memory.ts`(记忆检索内置常量),由 `index.ts` 统一 re-export,历史导入路径 `../config/static_config` 保持不变。

### configs/(12 个分组)
### configs/(11 个分组)

| 文件 | 分组 | 主要配置项 |
| --- | --- | --- |
Expand All @@ -52,14 +53,13 @@
| `memory.ts` | 记忆 | 长期/总结/知识库开关、总结上限/间隔/参与轮数、短期记忆上限、知识库注入阈值、知识库(Markdown 模板) |
| `reply.ts` | 回复 | 引用(含戳戳跳过)、最大字数、去空白、禁止复读与相似度、过滤正则与模板 |
| `message.ts` | 对话 | 角色扮演设定(每条第一行为名称,以 `.` 开头隐藏)、示例对话、轮数、token 上限、system 插入间隔、压缩阈值 |
| `prompt.ts` | prompt 模板 | 6 个内置 Handlebars 模板(见下文,不再注册为配置项) |
| `resource.ts` | 资源 | 本地图片路径、本地语音路径(`语音名=路径`,供 system prompt 列出资源) |

注意:本地图片/语音路径由资源分组统一注册;图片发送与 system prompt 资源列表读取同一份配置(本地语音路径支持 `语音名=路径`,省略语音名时用文件名)。

### prompt 模板(configs/prompt.ts)
### prompt 模板(src/prompt/templates.ts)

模板在代码中以 `TEMPLATES` 常量内置(不再注册为配置项,避免误改导致渲染损坏),读取时 `compileTemplate` 编译,渲染抛错时回退空函数。模板清单:
模板在代码中以 `TEMPLATES` 常量内置(不再注册为配置项,避免误改导致渲染损坏),读取时 `compileTemplate` 编译,仅在编译失败时回退空函数;渲染期异常不兜底,由调用方处理。模板清单:

- `system prompt模板`
- `长期记忆prompt模板`
Expand Down
1 change: 0 additions & 1 deletion docs/04-工具系统.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
防失控限制:

- `允许连续调用函数次数`(`MAX_CALL_COUNT`,默认 10):单次触发内会话累计工具调用次数上限,设为 0 不限制。
- `MAX_TOOL_TURNS = 10`(`src/agent/agent.ts`):单次对话中允许的连续工具调用轮次上限。

## 工具回调压缩

Expand Down
2 changes: 1 addition & 1 deletion docs/05-命令与配置.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## `.ai` 命令体系

根命令 `.ai`(`AI` 大写同样注册),子命令别名经 `ALIAS_MAP` 归一(常用:`priv→privilege`、`ses→session`、`st→set`、`ck→check`、`clr→clear`、`sb→standby`、`fgt→forget`、`memo→memory`、`p→private`、`g→group`、`tk→token`、`y→year`、`m→month`、`lcl→local`、`ran→random`、`lst→list`、`rm→remove`)。支持 `--page=<数字>`(别名 `--p`)翻页;`.ai help <一级子指令>` 可查看对应子命令帮助。
根命令 `.ai`(`AI` 大写同样注册),子命令别名经 `ALIAS_MAP` 归一(常用:`priv→privilege`、`ses→session`、`st→set`、`ck→check`、`clr→clear`、`sb→standby`、`fgt→forget`、`memo→memory`、`p→private`、`g→group`、`tk→token`、`y→year`、`m→month`、`lcl→local`、`ran→random`、`lst→list`、`rm→remove`)。支持 `--page=<数字>`(别名 `--p`)翻页;`.ai help <一级子指令>` 或 `.ai <一级子指令> help` 可查看对应子命令帮助(后者带更多参数时交由子命令自身处理,如 `.ai tool help <函数名>`)

### 子命令一览(源码为准)

Expand Down
6 changes: 4 additions & 2 deletions docs/07-开发指南.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ registerSay();

`SubCmdContext` 提供:ctx、msg、cmdArgs、epId、uid、gid、sid、session、page、ret。

> `.ai <子指令> help`(无更多参数)是内置保留用法:根命令直接展示该子指令的 `cmd.help`,不校验权限;若子指令需要处理 `help` 后的更多参数(如 `.ai tool help <函数名>`),在 `solve` 内自行处理。新增子命令务必填写 `cmd.help`。

## 添加一个智能体

1. 在 `src/agent/agents/` 新建文件,导出 `init()`,内部用 `Agent.get(name)` 获取实例并配置 name/description/instruction/use。
Expand Down Expand Up @@ -173,7 +175,7 @@ api.registerTool({

## 修改 prompt 模板

- 模板在 `src/config/configs/prompt.ts` 中定义默认值(注意改动需要同时更新默认注册内容,WebUI 中"刷子"可还原默认)。
- 模板在 `src/prompt/templates.ts` 中以内置常量定义(不再注册为配置项,WebUI 无默认值可还原;改动模板后需重新构建)。
- system prompt 的分节组装逻辑在 `src/prompt/builder.ts`,新增节时需要同步修改模板骨架与构建函数。
- 记忆/知识库/工具段的开关在 `src/memory/manager.ts` 与 `src/config/configs/memory.ts`。

Expand All @@ -197,7 +199,7 @@ api.registerTool({

配套后端服务已迁移到独立仓库 [aiplugin4-backends](https://github.com/error2913/aiplugin4-backends),由 `launcher.py` 一键管理(list/setup/start/stop/status/port/package/webui),Windows/Linux 通用;默认不启动任何后端,首次启动某后端时才自动安装其环境(独立 venv),由该仓库自身发版流程打包发布。详见 [08-相关后端项目](08-相关后端项目.md)。

发版前记得同步:`src/config/static_config.ts` 的 `VERSION`、`header.txt` 的 `@version`、`src/update.ts` 的 `updateInfo`(且需包含新版本条目)。
发版前记得同步:`src/config/static_config/meta.ts` 的 `VERSION`、`header.txt` 的 `@version`、`src/update.ts` 的 `updateInfo`(且需包含新版本条目)。

## 开发小贴士

Expand Down
2 changes: 1 addition & 1 deletion docs/09-注意事项与常见问题.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

## 代码中的已知不一致

- `src/config/static_config.ts` 的 `VERSION` 与 `src/update.ts` 的 `updateInfo` 最新条目需保持一致(当前 4.15.0);`checkUpdate` 按 `VERSION` 比较输出对应更新日志。
- `src/config/static_config/meta.ts` 的 `VERSION` 与 `src/update.ts` 的 `updateInfo` 最新条目需保持一致(当前 4.15.0);`checkUpdate` 按 `VERSION` 比较输出对应更新日志。
- `package.json` 的 `main`/`typings` 指向 `build/index.js`/`build/index.d.ts`,但实际构建产物是 `dist/aiplugin4.js`(esbuild),`build/` 目录是陈旧的 tsc 输出,与构建流程无关。
- `engines.node >= 10` 是模板遗留,实际构建依赖 esbuild,建议使用较新 Node。
- `sub_cmd/sample.ts` 与 `agent/agents/samples.ts` 是开发示例,未注册到运行时。
Expand Down
4 changes: 2 additions & 2 deletions scripts/build-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ const FULL_PACKAGE_NAME = 'AI骰娘4-扩展';
const FULL_PACKAGE_DESC = 'AI骰娘4 扩展包(完整包):包含本体与依赖插件,安装即用';

function getVersion() {
const src = fs.readFileSync(path.join(root, 'src', 'config', 'static_config.ts'), 'utf8');
const src = fs.readFileSync(path.join(root, 'src', 'config', 'static_config', 'meta.ts'), 'utf8');
const m = src.match(/VERSION\s*=\s*["']([^"']+)["']/);
if (!m) {
console.error('未能在 src/config/static_config.ts 中找到 VERSION');
console.error('未能在 src/config/static_config/meta.ts 中找到 VERSION');
process.exit(1);
}
return m[1];
Expand Down
6 changes: 3 additions & 3 deletions scripts/prepare-sealpack.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// 构建 sealpack 打包源目录(sealpack/):
// 1. 从 src/config/static_config.ts 读取插件版本 VERSION;
// 1. 从 src/config/static_config/meta.ts 读取插件版本 VERSION;
// 2. 将构建产物 dist/aiplugin4.js 复制为 sealpack/scripts/main.js;
// 3. 同步 sealpack/info.toml 中的 version,保证与插件版本一致;
// 4. 在 stdout 输出版本号,供 CI 拼装产物文件名。
const fs = require('fs');
const path = require('path');

const root = path.resolve(__dirname, '..');
const staticConfig = path.join(root, 'src', 'config', 'static_config.ts');
const staticConfig = path.join(root, 'src', 'config', 'static_config', 'meta.ts');
const bundle = path.join(root, 'dist', 'aiplugin4.js');
const sealpackDir = path.join(root, 'sealpack');
const mainJs = path.join(sealpackDir, 'scripts', 'main.js');
Expand All @@ -16,7 +16,7 @@ const infoToml = path.join(sealpackDir, 'info.toml');
const src = fs.readFileSync(staticConfig, 'utf8');
const m = src.match(/VERSION\s*=\s*["']([^"']+)["']/);
if (!m) {
console.error('未能在 src/config/static_config.ts 中找到 VERSION');
console.error('未能在 src/config/static_config/meta.ts 中找到 VERSION');
process.exit(1);
}
const version = m[1];
Expand Down
2 changes: 1 addition & 1 deletion sealpack/info.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
format_version = "1.0.0"

# 包基础信息。id 必须使用 namespace/package 格式;version 必须是 semver,
# 与插件版本(src/config/static_config.ts 的 VERSION)保持一致,
# 与插件版本(src/config/static_config/meta.ts 的 VERSION)保持一致,
# 构建时会由 scripts/prepare-sealpack.js 自动同步。
[package]
id = "error2913/aiplugin4"
Expand Down
Loading
Loading