图片预览

滚轮缩放 · 拖动移动 · Esc 关闭

Skip to content

官方技能仓库前端调用手册 ​

本手册中的 officialReleasePath 是发布修订的挂载路径。启用 Git 后,后续修订可以在读取或挂载时再展开。当前管理端的历史回填与回退步骤见技能管理机制,存储与下载流程见技能与轻应用的 Git 版本管理。

1. 功能说明 ​

官方 Skill 管理分为两个阶段:

  1. 首次新增:管理员上传一个完整 ZIP,后端读取 ZIP 唯一顶层目录中的根 SKILL.md,创建 ai_skill 并生成第一版分发包。
  2. 后续维护:管理员直接浏览和修改已展开的源码目录;修改只形成待发布内容,点击“发布版本”后才同步生成新的 release 和 revision 分发 ZIP。

前端不传仓库类型、服务器地址、账号、密码或 root-path。官方仓库使用独立的 file/SFTP 配置,不复用用户 room 的 default-cloud;沙箱只读挂载已发布 release。

2. 基础约定 ​

2.1 接口前缀 ​

通过网关访问时使用 /ai 前缀:

text
POST /ai/v1/skill/official
GET  /ai/v1/skill-repository/resources

直接访问 muotai-ai 服务时去掉 /ai。

2.2 鉴权 ​

所有官方 Skill 上传和仓库管理接口都需要登录。生产环境应给管理员账号授予 ai_skill_add 权限:

http
Authorization: Bearer {accessToken}

2.3 响应格式 ​

接口统一返回 R<T>:

json
{
  "code": 0,
  "msg": null,
  "data": {}
}

仓库资源接口的 data 为 FilebrowserResourceVO。

2.4 仓库路径 ​

前端文件管理接口展示的是源码虚拟根目录。路径统一使用 /:

text
/muotai-doc-review/assets/rule-packs/contract_review.json

后端会自动映射到真实仓库的 sources 分支,前端不要自行添加 /sources。平台内部仓库结构为:

Skill 详情中的 officialSourcePath 是内部路径(例如 sources/muotai-doc-review)。资源接口也兼容直接传入该字段,后端会识别已有的 sources/ 前缀,不会重复拼接;接口响应仍统一返回源码虚拟根目录下的公开路径。

text
{vfs.official-skill-repository.root-path}/
├── sources/{skillName}/
├── releases/{skillName}/rN/
├── packages/{skillName}/{skillName}.__dist_rN.zip
└── .internal/building/

前端不能传服务器绝对路径、协议地址或越级路径:

text
../
C:\data\skills
file:///data/skills
sftp://host/path

路径中包含中文、空格等字符时逐段 URL 编码,保留 /:

javascript
export function encodeRepositoryPath(path) {
  return path
    .split('/')
    .map(segment => encodeURIComponent(segment))
    .join('/')
}

3. 标准 ZIP 结构 ​

首次上传的 ZIP 必须只有一个安全的顶层目录。顶层目录名称可以任意,不入库,也不参与仓库路径、分发包名称或沙箱挂载路径。

顶层目录必须直接包含根 SKILL.md:

text
任意顶层目录/
├── SKILL.md
├── references/
├── scripts/
└── assets/

文档审查示例:

text
doc-review-source/
├── SKILL.md
├── references/
│   ├── doc-review-http.md
│   └── doc-review-chat.md
├── scripts/
└── assets/
    └── rule-packs/
        ├── contract_review.json
        └── resume_review.json

根 SKILL.md 必须以 YAML frontmatter 开头,至少包含:

markdown
---
name: muotai-doc-review
description: 文档审查总入口。
metadata:
  muotai:
    capability: doc-review
    rulePackPath: assets/rule-packs
---

# 文档审查

校验规则:

  • name 必填,必须是 kebab-case,只能包含小写字母、数字和单个连字符,最长 64 个字符。
  • description 必填且不能为空。
  • name 在未删除的 ai_skill 中必须唯一。
  • 入口固定为顶层目录下的 SKILL.md,前端不能传 entryPath。
  • ZIP 只能有一个顶层目录,不能在该目录外放文件。
  • 禁止绝对路径、..、盘符等不安全路径。
  • 禁止包含 __pycache__ 目录和 .pyc 文件。
  • ZIP 内所有 JSON 文件都必须是合法 JSON。
  • 声明 metadata.muotai.rulePackPath 时,该值必须是安全相对路径,目录必须存在。
  • 规则目录内每个 JSON 的文件名必须与 JSON 的 module 一致,且 module 不能重复。

后端会忽略上传时的顶层目录名,并按 SKILL.md.name 重新规范化:

text
sources/muotai-doc-review/
releases/muotai-doc-review/r1/
packages/muotai-doc-review/muotai-doc-review.__dist_r1.zip

官方 Skill 不再下载或安装到用户 room。Agent 启动沙箱时,将对应 release 只读挂载为:

text
/workspace/skills/official/muotai-doc-review

4. 首次新增官方技能 ​

4.1 接口 ​

http
POST /ai/v1/skill/official
Content-Type: multipart/form-data

4.2 FormData 参数 ​

Part类型必填说明
metadataapplication/json是业务元数据 JSON
packageZIP 文件是完整标准 Skill ZIP

metadata 字段:

字段类型必填说明
skillTypeString是例如 WORKFLOW、TOOL
versionString是业务版本,例如 1.0.0
licenseString否许可证
authorString否作者
tagsString[]否标签列表
enabledBoolean否导入成功后是否启用,默认 true

name、description 和入口路径不由前端提交,统一从根 SKILL.md 读取。

4.3 Axios 示例 ​

javascript
export async function createOfficialSkill(form, zipFile, onProgress) {
  const metadata = {
    skillType: form.skillType,
    version: form.version,
    license: form.license || null,
    author: form.author || null,
    tags: form.tags || [],
    enabled: form.enabled !== false
  }

  const formData = new FormData()
  formData.append(
    'metadata',
    new Blob([JSON.stringify(metadata)], {
      type: 'application/json'
    })
  )
  formData.append('package', zipFile, zipFile.name)

  return axios.post('/ai/v1/skill/official', formData, {
    onUploadProgress(event) {
      if (event.total && onProgress) {
        onProgress(Math.round(event.loaded * 100 / event.total))
      }
    }
  })
}

不要手工设置 Content-Type: multipart/form-data,浏览器会自动补充 multipart boundary。

4.4 cURL 示例 ​

bash
curl -X POST "http://host/ai/v1/skill/official" \
  -H "Authorization: Bearer TOKEN" \
  -F 'metadata={"skillType":"WORKFLOW","version":"1.0.0","license":"Proprietary","author":"Muotai","tags":["review"],"enabled":true};type=application/json' \
  -F "package=@doc-review.zip;type=application/zip"

4.5 成功响应 ​

json
{
  "code": 0,
  "data": {
    "skillId": 2075000000000000001,
    "name": "muotai-doc-review",
    "officialSourcePath": "sources/muotai-doc-review",
    "officialReleasePath": "releases/muotai-doc-review/r1",
    "officialPackagePath": "packages/muotai-doc-review/muotai-doc-review.__dist_r1.zip",
    "sourceRevision": 1,
    "packageRevision": 1,
    "packageStatus": "IMPORTING",
    "packageSha256": "4a7d1ed414...",
    "fileCount": 16,
    "uncompressedSizeBytes": 284476
  }
}

接口返回 IMPORTING 表示 ZIP 已完成校验、ai_skill 已创建、第一版分发 ZIP 已保存,sources 和 releases/r1 正在后台展开。首次导入仍需轮询状态;后续手动发布是同步接口,不轮询。

5. 查询导入和构建状态 ​

5.1 接口 ​

http
GET /ai/v1/skill/{skillId}
javascript
export async function getSkillDetail(skillId) {
  const response = await axios.get(`/ai/v1/skill/${skillId}`)
  return response.data.data
}

5.2 状态说明 ​

状态含义前端展示建议
IMPORTING正在首次展开源码目录导入中
DIRTY源码已变更,但尚未点击发布有未发布修改
BUILDING正在生成新分发 ZIP构建中
READY当前源码、release 与分发 ZIP 一致可用
FAILED首次导入或手动发布失败发布失败
DELETING正在同步清理官方仓库资产删除中
DELETE_FAILED仓库或关联记录清理失败删除失败,可重试

前端应重点展示:

text
officialPackageStatus
officialPackageError
officialSourceRevision
officialPackageRevision
officialPackageSha256
officialSourcePath
officialReleasePath
officialPackagePath

5.3 首次导入轮询示例 ​

javascript
export async function waitSkillReady(skillId, timeoutMs = 120000) {
  const startedAt = Date.now()

  while (Date.now() - startedAt < timeoutMs) {
    const skill = await getSkillDetail(skillId)

    if (skill.officialPackageStatus === 'READY') {
      return skill
    }
    if (skill.officialPackageStatus === 'FAILED') {
      throw new Error(skill.officialPackageError || 'Skill 导入或构建失败')
    }

    await new Promise(resolve => setTimeout(resolve, 1500))
  }

  throw new Error('等待 Skill 就绪超时')
}

6. 浏览仓库资源 ​

6.1 查询根目录 ​

http
GET /ai/v1/skill-repository/resources

6.2 查询指定目录 ​

http
GET /ai/v1/skill-repository/resources/muotai-doc-review/assets/rule-packs

可选查询参数:

参数类型默认值说明
recursiveBooleanfalse是否递归返回子资源
javascript
export async function getRepositoryResource(path = '/', recursive = false) {
  const encoded = path === '/' ? '' : encodeRepositoryPath(path)
  const response = await axios.get(
    `/ai/v1/skill-repository/resources${encoded}`,
    { params: { recursive } }
  )
  return response.data.data
}

后台生成的 .__dist_r*.zip 和 .__building_*.part 不会展示,也不能通过管理接口操作。

7. 创建目录 ​

http
POST /ai/v1/skill-repository/directories
Content-Type: application/json

请求体:

json
{
  "parentPath": "/muotai-doc-review/assets",
  "name": "templates"
}
javascript
export async function createRepositoryDirectory(parentPath, name) {
  const response = await axios.post(
    '/ai/v1/skill-repository/directories',
    { parentPath, name }
  )
  return response.data.data
}

不能创建或删除已注册 Skill 的根目录。

8. 上传或覆盖单个文件 ​

http
POST /ai/v1/skill-repository/files?parentPath={parentPath}&override={boolean}
Content-Type: multipart/form-data
参数位置必填说明
filePart是单个文件
parentPathQuery否目标目录,默认仓库根目录
overrideQuery否是否覆盖同名文件,默认 false

新增审查类型:

javascript
export async function uploadRuleFile(file) {
  const formData = new FormData()
  formData.append('file', file, file.name)

  const response = await axios.post(
    '/ai/v1/skill-repository/files',
    formData,
    {
      params: {
        parentPath: '/muotai-doc-review/assets/rule-packs',
        override: false
      }
    }
  )
  return response.data.data
}

覆盖已有文件时把 override 改为 true。上传 JSON 时,后端会先校验 JSON 格式。

9. 在线更新文件内容 ​

http
PUT /ai/v1/skill-repository/resources/{path}
Content-Type: application/octet-stream

更新引用 Markdown:

javascript
export async function updateRepositoryText(path, content) {
  await axios.put(
    `/ai/v1/skill-repository/resources${encodeRepositoryPath(path)}`,
    new TextEncoder().encode(content),
    { headers: { 'Content-Type': 'application/octet-stream' } }
  )
}

await updateRepositoryText(
  '/muotai-doc-review/references/doc-review-http.md',
  markdownContent
)

更新根 SKILL.md 时允许修改说明正文和 description,但不能修改 name。修改成功后,后端会把新 description 和完整 SKILL.md 内容同步到 ai_skill。

10. 删除文件或目录 ​

http
DELETE /ai/v1/skill-repository/resources/{path}
javascript
export async function deleteRepositoryResource(path) {
  await axios.delete(
    `/ai/v1/skill-repository/resources${encodeRepositoryPath(path)}`
  )
}

限制:

  • 不能删除已注册 Skill 根目录。
  • 不能删除根 SKILL.md。
  • 不能删除根 SKILL.md 的父目录。
  • 不能操作内部生成的分发 ZIP 和临时文件。

11. 移动、重命名或复制资源 ​

http
PATCH /ai/v1/skill-repository/resources/{sourcePath}
  ?action={move|copy}
  &destination={targetPath}
  &override={boolean}

重命名规则文件:

javascript
export async function moveRepositoryResource(source, destination, override = false) {
  await axios.patch(
    `/ai/v1/skill-repository/resources${encodeRepositoryPath(source)}`,
    null,
    { params: { action: 'move', destination, override } }
  )
}

await moveRepositoryResource(
  '/muotai-doc-review/assets/rule-packs/old-name.json',
  '/muotai-doc-review/assets/rule-packs/new-name.json'
)

复制文件:

javascript
export async function copyRepositoryResource(source, destination, override = false) {
  await axios.patch(
    `/ai/v1/skill-repository/resources${encodeRepositoryPath(source)}`,
    null,
    { params: { action: 'copy', destination, override } }
  )
}

不能跨两个官方 Skill 根目录移动或复制资源,也不能移动根 SKILL.md。

12. 读取文本文件 ​

http
GET /ai/v1/skill-repository/raw/{path}

当前接口按 UTF-8 文本返回 R<String>,适合 Markdown、JSON、YAML 和脚本预览:

javascript
export async function readRepositoryText(path) {
  const response = await axios.get(
    `/ai/v1/skill-repository/raw${encodeRepositoryPath(path)}`
  )
  return response.data.data
}

二进制模板或图片的下载应使用单独的二进制下载接口,本接口不要用于 .docx、.pptx 或图片。

13. 手动发布版本 ​

源码修改后不会自动压缩。管理员确认全部修改完成后调用:

http
POST /ai/v1/skill/{skillId}/publish

接口无请求体。后端会同步等待分发 ZIP 构建完成,成功后直接返回最终结果:

json
{
  "code": 0,
  "data": {
    "skillId": 2075000000000000001,
    "sourceRevision": 8,
    "targetPackageRevision": 2,
    "packageStatus": "READY",
    "officialPackagePath": "packages/muotai-doc-review/muotai-doc-review.__dist_r2.zip",
    "officialReleasePath": "releases/muotai-doc-review/r2",
    "packageSha256": "5d41402abc4b2a76b9719d911017c592...",
    "fileCount": 126,
    "uncompressedSizeBytes": 2048576
  }
}
javascript
export async function publishOfficialSkill(skillId) {
  const response = await axios.post(
    `/ai/v1/skill/${skillId}/publish`,
    null,
    {
      // 后端发布业务超时为 30 分钟,前端需预留网络返回时间。
      timeout: 31 * 60 * 1000
    }
  )
  return response.data.data
}

发布规则:

  • 多次源码编辑可以合并为一次发布,只生成一个新 ZIP。
  • targetPackageRevision 按成功发布次数加一,与源码编辑次数无关。
  • BUILDING 期间禁止继续修改源码,也不能重复发布。
  • 发布失败时旧 release 和旧分发 ZIP 继续可用,管理员可再次点击发布。
  • 已发布的历史 ZIP 永久保留。
  • 接口最长同步等待 30 分钟;超时、构建失败或线程池拒绝时直接返回错误,不返回 BUILDING。

前端在请求期间显示发布中状态并禁用编辑、删除、移动和重复发布操作。接口成功后直接使用响应中的版本、路径、SHA-256、文件数和解压大小刷新页面,不需要轮询 Skill 详情。

网关、Nginx 和其他反向代理的响应超时必须大于后端 30 分钟业务超时,建议配置为 35 分钟。若通过 Feign 转发此接口,Feign readTimeout 同样需要大于 30 分钟。

13.1 删除官方 Skill ​

http
DELETE /ai/v1/skill/{skillId}

删除接口同步执行。成功后会清理 sources/{skillName}、releases/{skillName}、packages/{skillName}、临时构建文件和该 Skill 的 muotai_skill_package_change 记录,然后逻辑删除 ai_skill。

官方 Skill 不再写入用户 room,因此删除时没有 room 文件需要处理。Agent 中保存的历史 Skill ID 不会修改,运行时查询不到已删除 Skill 时会跳过该 ID。

处于 IMPORTING 或 BUILDING 的 Skill 不能删除。仓库清理失败时 Skill 保留为禁用状态并进入 DELETE_FAILED,前端展示 officialPackageError,允许管理员再次调用同一删除接口重试。

14. 启用和禁用技能 ​

Skill 启用状态继续使用现有技能更新接口。首次导入时,enabled 只在异步展开成功后生效。

DIRTY 表示源码有未发布修改,FAILED 也可能只是新版本发布失败;这两种情况下上一个成功发布的 release 仍可供 Agent 使用。前端应以 Skill 已发布、已启用且存在 release 作为可用条件:

前端至少同时判断:

javascript
const agentUsable = skill.enabled === true
  && skill.status === 'PUBLISHED'
  && Boolean(skill.officialReleasePath)

15. 推荐页面流程 ​

15.1 首次新增 ​

  1. 用户选择 ZIP。
  2. 前端只填写 skillType、version、license、author、tags、enabled。
  3. 调用 POST /v1/skill/official。
  4. 从响应读取由根 SKILL.md 解析出的 name。
  5. 轮询 Skill 详情,直到 READY 或 FAILED。
  6. READY 后进入源码管理页面。

15.2 源码维护 ​

  1. 从 officialSourcePath 打开对应仓库目录。
  2. 通过目录、上传、更新、删除和移动接口维护单个资源。
  3. 修改后展示 DIRTY 和“发布版本”按钮,不自动构建 ZIP。
  4. 管理员点击发布后,在同步请求完成前禁用源码编辑和发布按钮。
  5. 接口成功返回 READY 时直接展示新的 targetPackageRevision 和分发包信息;失败时展示接口错误并允许重试。
  6. 用户下次使用绑定该 Skill 的 Agent 时,沙箱直接只读挂载最新成功发布的 release。

16. 官方仓库独立连接配置 ​

Windows 应用连接 Linux 存储服务器时使用 SFTP:

yaml
vfs:
  official-skill-repository:
    mount-type: sftp
    host: 192.168.4.37
    port: 22
    root-path: /home/ljf/muotai/official_skill_repository
    auth-config:
      username: root
      password: ${OFFICIAL_SKILL_PASSWORD}
      strictHostKeyChecking: no

应用与仓库同机时也可以使用 file:

yaml
vfs:
  official-skill-repository:
    mount-type: file
    root-path: /home/ljf/muotai/official_skill_repository

云集市文档模板仓库同理,独立根路径,不复用官方 Skill 目录:

yaml
fs:
  doc-template-repository:
    mount-type: sftp
    host: 192.168.4.37
    port: 22
    root-path: /home/ljf/muotai/doc_template_repository
    auth-config:
      username: root
      password: ${DOC_TEMPLATE_PASSWORD}
      strictHostKeyChecking: no

同机 file:

yaml
fs:
  doc-template-repository:
    mount-type: file
    root-path: /home/ljf/muotai/doc_template_repository

说明:Java 绑定前缀为 fs(2026-08 起由 vfs 改名)。Skill 文档上文示例仍写 vfs: 为历史写法,现网 Nacos 应以 fs: 为准。

root-path 始终表示存储服务器和 Sandbox Worker 上的真实绝对路径。SFTP 仅供管理端访问;Sandbox 不挂载 SFTP URL,而是直接挂载:

text
{root-path}/releases/{skillName}/rN

因此 SFTP 存储服务器必须与 Sandbox Worker 同机,或者 Worker 上必须存在完全相同的共享挂载路径。

前端永远不能上传这些连接信息,也不需要感知宿主机目录结构。

17. 文档审查规则与启动 ​

17.1 获取规则 ​

http
GET /ai/doc-review/rules?roomId={roomId}&agentId={agentId}&module={module}

roomId、agentId、module 都是必传参数。后端校验 room 归属后,从 Agent 绑定的文档审查 Skill 当前 release 读取:

text
{officialReleasePath}/{rulePackPath}/{module}.json

响应包含规则内容以及规则来源信息,不再向前端暴露或要求维护发布 revision:

json
{
  "skillId": 1001,
  "rulePackPath": "assets/rule-packs",
  "module": "contract_review",
  "rules": []
}

17.2 启动审查 ​

调用 POST /ai/doc-review/start 时不传 skillRevision:

javascript
await axios.post('/ai/doc-review/start', {
  roomId: form.roomId,
  agentId: form.agentId,
  filePath: form.filePath,
  module: form.module,
  perspectiveCode: form.perspectiveCode,
  selectedRuleIds: form.selectedRuleIds || []
})

后端在任务启动时自动选择当前最新发布 release,并把实际 revision 写入审查批次快照和会话上下文。规则读取和沙箱挂载使用同一次解析结果;前端提交的规则ID若已被新版删除,接口会提示刷新规则后重新选择。

18. 常见错误 ​

错误原因处理方式
官方Skill ZIP不能为空未上传 package选择 ZIP 后重试
首次导入只支持标准ZIP包文件扩展名不是 .zip上传 ZIP
标准Skill ZIP只能包含一个顶层目录ZIP 有多个顶层目录重新打包为单顶层目录
Skill入口文件不存在: SKILL.md顶层目录下没有根 SKILL.md把入口放到顶层目录
技能名称必须使用 kebab-caseSKILL.md.name 格式错误改为如 muotai-doc-review
技能名称长度不能超过64个字符name 过长缩短 name
缺少必填字段: descriptiondescription 缺失或为空补充根 frontmatter
技能名称已存在name 与现有未删除 Skill 重复修改 name 或删除冲突记录
Skill ZIP不能包含Python运行缓存包含 .pyc 或 __pycache__清理缓存后重新打包
不能通过源码维护修改SKILL.md.name后续编辑改变了唯一标识恢复原 name
目标资源已存在override=false 且同名文件存在确认后使用 override=true
不能跨官方Skill根目录移动或复制资源源目标属于不同 Skill在同一 Skill 内操作
没有待发布变更Skill 当前没有 PENDING 修改先修改源码再发布
官方Skill正在发布重复点击发布或 BUILDING 期间编辑等待当前发布结束

19. 前端接口封装 ​

javascript
export const officialSkillApi = {
  create(form, zipFile, onProgress) {
    return createOfficialSkill(form, zipFile, onProgress)
  },

  detail(skillId) {
    return getSkillDetail(skillId)
  },

  publish(skillId) {
    return publishOfficialSkill(skillId)
  },

  resource(path = '/', recursive = false) {
    return getRepositoryResource(path, recursive)
  },

  createDirectory(parentPath, name) {
    return createRepositoryDirectory(parentPath, name)
  },

  uploadFile(parentPath, file, override = false) {
    const formData = new FormData()
    formData.append('file', file, file.name)
    return axios.post('/ai/v1/skill-repository/files', formData, {
      params: { parentPath, override }
    })
  },

  updateText(path, content) {
    return updateRepositoryText(path, content)
  },

  remove(path) {
    return deleteRepositoryResource(path)
  },

  move(source, destination, override = false) {
    return moveRepositoryResource(source, destination, override)
  },

  copy(source, destination, override = false) {
    return copyRepositoryResource(source, destination, override)
  },

  readText(path) {
    return readRepositoryText(path)
  }
}