Skip to content

适配器格式

一个 YAML adapter 注册一条命令。文件中包含 discovery metadata、参数、执行步骤、输出列和 schema-v2 metadata。

最小示例

yaml
site: hackernews
name: top
description: Hacker News top stories
domain: news.ycombinator.com
type: web-api
strategy: public
operation_effect: read

args:
  limit:
    type: int
    default: 20
    description: Number of stories

pipeline:
  - fetch:
      url: https://hacker-news.firebaseio.com/v0/topstories.json
  - limit: ${{ args.limit }}

columns: [id]

capabilities: ["http.fetch"]
minimum_capability: http.fetch
trust: public
confidentiality: public
quarantine: false
schema_version: v2

标识与连接

字段含义
site命令 namespace,例如 hackernews
nameSite 下的命令名
descriptionSearch 使用的一句话用户意图
domain主要远程域名
typeweb-apibrowserdesktopbridgeservice
strategypubliccookieheaderenvironmentinterceptui
browser标记需要 browser runtime 的命令
browserSessionautousercdp
auth_cookiesSite adapter 使用的 cookie 名称
binary / detectBridge adapter 的外部 CLI 与检测命令

Operation metadata

字段可用值
target_surfacewebdesktopsystemmobile
execution_operatorstructured-apibrowser-protocolnative-clibrowser-semanticdesktop-accessibilityvisual-observationvisual-coordinatelocal-runtime
operation_familysearchgetlistcreateupdatedeleteinvokecapturenavigatedownloadauthenticateunknown
operation_effectreaddownload_filesend_messagepublish_contentaccount_stateremote_transformremote_resourceservice_statelocal_applocal_filedestructiveunknown_write
idempotencyguaranteedconditionalnoneunknown
auth_requirementrequiredoptionalnone

配置可用性

使用进程凭据的命令单独声明配置要求。strategy: environment 表示 pipeline 从环境变量模板读取凭据,执行时不会访问浏览器 cookie 存储。

yaml
strategy: environment
auth_requirement: required
availability:
  environment: [SEARCH_API_KEY]
  discovery: configured
  setup_url: https://search.example.com/keys

availability.environment 中的变量全部为必填项。配置 discovery: configured 后,缺少凭据的命令不会进入 list、search、completion 和 expanded MCP。显式 describe 仍会返回命令合同,并列出 missing_environment。直接调用会在发起网络请求前结束。

Retrieval provider

只读 discovery 命令通过统一 retrieval metadata 加入 unicli retrieval search

yaml
retrieval:
  operation: discover
  result_kind: docs
  source_class: search-index
  selection: explicit
  arguments:
    query: query
    limit: limit

selection 默认使用 automatic。自动 selector 与 all 只选择已配置、无需认证的 automatic source。付费或消耗 quota 的 provider 使用 selection: explicit,调用方必须传入精确 source ref 或 site。

参数

YAML 参数以命令行名称为 key。

yaml
args:
  query:
    type: str
    required: true
    positional: true
    minLength: 1
    description: Search terms
  limit:
    type: int
    default: 10
    minimum: 1
    maximum: 100
  sort:
    type: str
    choices: [relevance, newest]
    default: relevance

类型包括 strstr[]intfloatnullable-floatstr-or-intbool

字符串参数可以使用 minLengthmaxLengthpatternuriuuiddatedate-timeemailhostnameipv4ipv6regex 等标准 format。Uni-CLI kind 提供 pathadapter-refselectorshell-safeid 验证。

Pipeline

pipeline 是按顺序执行的 action object 列表。

yaml
pipeline:
  - fetch:
      url: https://api.example.com/search
      params:
        q: ${{ args.query }}
  - select: data.items
  - map:
      title: ${{ item.title }}
      url: ${{ item.url }}
  - limit: ${{ args.limit }}

模板可以读取 args、当前 itemindex、环境变量和前面步骤存储的数据。详情见 Pipeline steps

输出

columns 控制默认 Markdown、table 和 CSV 的字段顺序。JSON 保留完整结果。

yaml
columns: [title, url, score]
defaultFormat: md

output 可为需要更明确合同的命令提供 result schema 和 agent hint。

Schema-v2 必填 metadata

提交到仓库的 YAML adapter 带有以下六个字段。

字段用途
schema_version: v2选择当前 adapter metadata schema
capabilities列出命令使用的 capability
minimum_capability执行所需的最小接口
trustpublicusersystem 来源
confidentialitypublicinternalprivate 数据类别
quarantine标记等待修复的 adapter

使用下面的命令为已有 adapter 加入当前 metadata。

bash
unicli migrate schema-v2 path/to/adapter.yaml --write

TypeScript adapter

SDK integration、streaming protocol、自定义 pagination 和 stateful flow 适合使用 TypeScript。

typescript
import { cli, Strategy } from "../../registry.js";

cli({
  site: "example",
  name: "search",
  description: "Search Example",
  strategy: Strategy.PUBLIC,
  args: [{ name: "query", type: "str", required: true, positional: true }],
  capabilities: ["http.fetch"],
  minimum_capability: "http.fetch",
  trust: "public",
  confidentiality: "public",
  quarantine: false,
  operation_effect: "read",
  execution_operator: "structured-api",
  operation_family: "search",
  func: async (_page, { query }) => {
    const response = await fetch(
      `https://api.example.com/search?q=${encodeURIComponent(String(query))}`,
    );
    return response.json();
  },
});

TypeScript registration 直接调用 registry API,因此参数使用 array。

验证

bash
npm run lint:adapters
npm run lint:schema-v2
unicli describe <site> <command>
unicli test <site>

Loader 位于 src/core/yaml-adapter.ts,v2 metadata schema 位于 src/core/schema-v2.ts

基于 Apache-2.0 许可证发布