Skip to content

API 文档 ​

Neo-MoFox 为插件开发者提供了一套完整的 API 接口,涵盖消息收发、LLM 调用、数据库操作、事件系统、日志记录等核心功能。

设计理念

所有 API 都采用扁平化设计,函数命名清晰直观,支持关键字参数调用,提供开箱即用的类型提示。

API 模块总览 ​

模块说明
Action APIAction 组件查询、Schema 获取、执行与缓存管理
Adapter API适配器启动、停止、重启、查询与命令调用
Agent APIAgent 组件查询、执行与可用工具管理
Chat APIChatter 组件查询、实例管理与流绑定
Command API命令匹配、注册、执行与帮助信息
Config API插件配置的加载与重载
Database APICRUD、查询构建、聚合统计、分页、批量迭代
Event API事件发布、处理器注册与临时监听器
LLM APILLM 请求创建、模型集获取、工具注册与统计查询
Log API日志记录器创建
Media API图片/表情识别与信息管理
Message API消息查询、计数与可读格式化
Permission API用户身份标识生成与权限管理
Person API用户记录管理、名称变更历史、印象与态度维护
Plugin API插件加载、卸载、重载与查询
Prompt API提示词模板注册与系统提醒(含流隔离)
Router APIHTTP Router 查询、挂载与卸载
Send API文本、图片、表情、语音、视频、文件发送与广播
Service APIService 组件查询
Storage APIJSON 存储与 PluginDatabase(SQLite)
Stream API聊天流创建、查询、消息管理与上下文操作

通用约定 ​

异步调用 ​

所有涉及 I/O 操作的 API 都是异步函数,必须使用 await 调用:

python
# ✅ 正确
messages = await get_recent_messages(stream_id=stream_id)

# ❌ 错误:返回 coroutine 对象
messages = get_recent_messages(stream_id=stream_id)

类型提示 ​

所有 API 函数都提供完整的类型注解,建议启用类型检查工具(Pylance、mypy)。

错误处理 ​

python
try:
    await send_text(stream_id=stream_id, platform=platform, content="Hello")
except Exception as e:
    logger.error(f"发送失败: {e}")

相关章节 ​

贡献者

The avatar of contributor named as minecraft1024a minecraft1024a
The avatar of contributor named as micraft1024a micraft1024a
The avatar of contributor named as Windpicker-owo Windpicker-owo

页面历史

Released under the GPL-3.0 License.