@aid-framework/spec

中文文档
0.1.98发布于 2026/11/03Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 1.3万

The AID Framework specification language: the spec v0.1 JSON Schema, a position-aware YAML parser, and structural validation.

原始使用文档
文档目录10 节
  1. Install
  2. What it does
  3. Quick start
  4. The document
  5. Pipeline step kinds
  6. Diagnostics
  7. JSON Schema
  8. What this package does not do
  9. API
  10. License

@aid-framework/spec

The spec language of AID Framework: the JSON Schema, a position-aware YAML parser, and the structural validator. This is the package that decides whether a document is a well-formed AID spec.

An AID application starts as one declarative YAML file. That file is the source of truth: models, prompts, tools, retrieval, agents, pipelines and evals are declared once, and everything downstream — the IR, the code generators, the runtimes — is derived from it.

specVersion: "0.1"
project:
  name: support-copilot

models:
  fast:
    provider: openai-compatible
    model: gpt-4o-2024-08-06
    capabilities: [tool-calling, json-schema]

prompts:
  answer:
    template: |
      Answer the customer's question.
      Question: {{ question }}

pipelines:
  answer:
    steps:
      - generate:
          model: fast
          prompt: answer
          input:
            question: "{{ request.question }}"

Install

npm install @aid-framework/spec

Requires Node.js 24 or newer. Shipped as ESM with TypeScript declarations.

What it does

  • Parses YAML into a typed document that remembers where every node came from, so a diagnostic can point at file:line:column instead of only naming a key.
  • Validates the document against the spec v0.1 JSON Schema, which is also exported for editor autocomplete and CI validation.
  • Tells the truth about versions. A construct the language defines but this build cannot serve is reported as spec/not-supported naming the version that can — never as a generic schema failure that reads like a typo.

Quick start

import { checkSpecText, formatDiagnostics } from '@aid-framework/spec';

const { ok, diagnostics } = checkSpecText(source, { file: 'app/app.spec.yaml' });

if (!ok) {
  process.stderr.write(formatDiagnostics(diagnostics));
  process.exit(1);
}

checkSpecText parses and validates in one step. It short-circuits on purpose: when the YAML itself cannot be parsed, semantic validation is skipped, because a semantic message about a half-parsed document is noise.

Working one layer down:

import { parseSpecDocument, validateSpec, formatDiagnostics } from '@aid-framework/spec';

const parsed = parseSpecDocument(source, { file: 'app/app.spec.yaml' });
const diagnostics = [
  ...parsed.diagnostics,
  ...validateSpec(parsed.value, { file: 'app/app.spec.yaml' }),
];

The document

SectionSinceDeclares
specVersion0.1The language version of the document
project0.1Name and metadata of the app
types0.1Named record types shared by prompts, tools and pipelines
models0.1Model aliases: provider, pinned model id, capabilities, limits, cost
prompts0.1Versioned prompt templates and their typed variables
tools0.1Tool contracts, handlers, side effects and auth policy
stores0.1Vector store declarations
retrievers0.1Retrieval sources, chunking, embeddings and ranking
evals0.1Datasets, metrics and gates
pipelines0.1The executable graph of steps
agents0.2Agent loops, tool sets, transfer/delegation and budgets
guardrails0.2Input/output policies and their enforcement
decisions0.6TypeSafe AI Jev decision points: a typed question, not a chat model
memory0.2Conversation, user and global memory scopes
deployments0.2Trigger, concurrency and streaming declarations

The build reads spec versions 0.1 through 0.9. A section listed as 0.2 is rejected in a 0.1 document, with a diagnostic naming the version that accepts it. deployments[].image is a 0.4 construct and needs target: container; both rules are reported at deployments.<id>.image. guardrails[].decision is a 0.7 construct: it answers the guardrail with a choice decision instead of detector policies, and is rejected in an earlier document. A decision eval metric is a 0.8 construct: it scores every prediction with a declared score decision, and is rejected in an earlier document. The route step is a 0.9 construct: it selects an arm from a choice decision's answer, and is rejected in an earlier document.

Pipeline step kinds

A pipeline step contains exactly one step kind. The validator implements twelve:

generate, retrieve, tool, emit, branch, route, parallel, map, reduce, rerank, guard, agent.

branch, route, parallel, map and reduce are the composite kinds — the only ones that may nest another step — and nesting is bounded. emit may not appear inside a composite step, because it terminates the pipeline. branch selects on the authenticated caller; route selects on data, by asking a choice decision and matching its answer against on.

No step kind is deferred in this build. human was retired rather than deferred: a human-in-the-loop pause is a property of an agent (agents[].humanInTheLoop), so the old spelling produces a diagnostic naming the replacement instead of "unknown key".

Diagnostics

Diagnostics are the public contract, not an implementation detail. Every code in DIAGNOSTIC_CODES is asserted by the test suite and printed by aid validate, so it is safe to match on in CI. Renaming one is a breaking change.

import {
  countBySeverity, formatDiagnostics, hasErrors, sortDiagnostics,
} from '@aid-framework/spec';

const { ok, diagnostics } = checkSpecText(source, { file: 'app/app.spec.yaml' });
const failing = hasErrors(diagnostics); // only error severity fails a check; warnings do not
const counts = countBySeverity(diagnostics);

Codes are namespaced spec/*. Two are worth calling out because they are easy to conflate:

  • spec/not-supported — the language defines this construct, but this build does not serve it yet. The message names the version that does.
  • spec/unknown-key — nothing defines this key. Almost always a typo.

Keeping them distinct is deliberate: a message saying "not supported" about a misspelled key sends the reader looking for a missing feature that does not exist.

JSON Schema

The schema is a package export, so editors and external tools use the same one the validator uses:

{
  "yaml.schemas": {
    "./node_modules/@aid-framework/spec/dist/schema/spec.schema.json": "app.spec.yaml"
  }
}
import schema from '@aid-framework/spec/spec.schema.json' with { type: 'json' };

What this package does not do

It validates one document in isolation. It performs no cross-section analysis: no referential integrity, no capability negotiation, no cost sanity, no security checks. Those need to see the whole program, so they live in the build-time gates of @aid-framework/ir.

Layering is one-directional: spec ← ir ← generator-sdk ← generators ← cli. Nothing here imports a package above it.

API

ExportPurpose
checkSpecText(text, options?)Parse and validate in one step; returns { ok, value, diagnostics }
parseSpecDocument(text, options?)YAML → typed document plus positioned diagnostics
validateSpec(value, options?)Structural validation of an already-parsed document
specJsonSchemaThe spec v0.1 JSON Schema as an object
SPEC_VERSION, SPEC_VERSION_LATESTThe version aid init writes, and the newest version read
SUPPORTED_SPEC_VERSIONS, SUPPORTED_SECTIONSThe version and section vocabularies
SUPPORTED_STEP_KINDS, COMPOSITE_STEP_KINDS, RETIRED_STEP_KINDSThe step-kind vocabularies
SECTION_MIN_VERSIONWhich version first accepts each later section
DIAGNOSTIC_CODES, SEVERITIESThe diagnostic vocabulary
formatDiagnostic, formatDiagnostics, sortDiagnosticsRendering
countBySeverity, hasErrorsInspection
SourceDocumentA parsed document that carries node positions

License

Apache-2.0. Code generated by AID Framework is not subject to this license.

版本与发布记录

@aid-framework/spec 共发布 52 个版本,首次发布于 2026/10/31;过去 12 个月发布了 52 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.1.98latest2026/11/032 天前
0.1.972026/11/032 天前
0.1.962026/11/033 天前
0.1.952026/11/033 天前
0.1.942026/11/033 天前
0.1.932026/11/033 天前

关于 @aid-framework/spec 的常见问题

@aid-framework/spec 是什么?

The AID Framework specification language: the spec v0.1 JSON Schema, a position-aware YAML parser, and structural validation.

如何安装 @aid-framework/spec?

在项目目录运行 npm install @aid-framework/spec,或使用 pnpm add / yarn add / bun add。

@aid-framework/spec 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@aid-framework/spec 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@aid-framework/spec 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=24。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@aid-framework/spec 可以商用吗?

@aid-framework/spec 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@aid-framework/spec 的下载量有多少?

根据 npm 官方下载统计,@aid-framework/spec 在 2026/10/06 – 2026/11/04 这 30 天内被下载 12,731 次,日均约 424 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aid-framework/spec 还在维护吗?

最新版本 0.1.98 发布于 2026/11/03(2 天前);至今共发布 52 个版本,其中过去 12 个月发布了 52 个;首次发布于 2026/10/31。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。