中文

开发者指南 内部机制

参考库格式

参考架构的 JSON 格式,以及 insurer 条目是如何构建的。

本页内容

参考架构是参考库文件夹中的一个 JSON 文件:默认是 server/library/,或 ARCHIPELEGO_LIBRARY 中指定的文件夹。服务器代码是 server/src/library.ts。

条目

ts
interface LibraryEntry {
  id: string;
  title: string;
  description?: string;
  tags?: string[];
  canvas: {
    title: string;
    layers?: { id: string; name: string; height: number }[];
    blocks: { id: string }[];
    links: { id: string }[];
    notes?: { id: string }[];
  };
}

canvas 对象是一个完整的画布文件:format: 'archipelego'、version: 1、title、layers、blocks、links 和 notes,如数据模型所述。生成的条目还带有一个 source 字段,指明它们来自哪个研究文件。

校验

  • 去掉 .json 的文件名就是条目 id。它必须匹配 ^[a-z0-9-]{1,64}$。
  • 文件必须能解析为 JSON,并且有 canvas.blocks 数组。其他任何情况都会被跳过。
  • 列表按标题排序。

最小条目

json
{
  "id": "two-tier-web",
  "title": "Two-tier web app",
  "description": "A browser, one application and its database.",
  "tags": ["web"],
  "canvas": {
    "format": "archipelego",
    "version": 1,
    "title": "Two-tier web app",
    "layers": [
      { "id": "experience", "name": "Experience", "height": 288 },
      { "id": "apps", "name": "Applications & Agents", "height": 288 },
      { "id": "data", "name": "Data & Platforms", "height": 288 }
    ],
    "blocks": [
      { "id": "b_user", "kind": "persona", "x": 0, "y": 72, "w": 168, "h": 96, "title": "Customer" },
      { "id": "b_app", "kind": "application", "x": 0, "y": 360, "w": 168, "h": 96, "title": "Web app", "subtitle": "node 24" },
      { "id": "b_db", "kind": "database", "x": 0, "y": 648, "w": 168, "h": 96, "title": "Orders", "subtitle": "postgres 17" }
    ],
    "links": [
      { "id": "l_0", "from": "b_user", "to": "b_app", "kind": "sync", "label": "HTTPS" },
      { "id": "l_1", "from": "b_app", "to": "b_db", "kind": "sync", "label": "reads, writes" }
    ],
    "notes": []
  }
}

把它保存为 server/library/two-tier-web.json。参考库会在下一个请求时读取到它,无需重启。

API

GET /api/library 为每个条目返回一份摘要:

ts
export interface LibrarySummary {
  id: string;
  title: string;
  description: string;
  tags: string[];
  layers: string[];
  blocks: number;
  links: number;
  notes: number;
}

POST /api/library/<id>/open 调用 openLibraryEntry。它创建一个新的画布 id(32 个随机字节,URL 安全的 base64),构建一个 Y.Doc,并把它以 <id>.yjs 为名写入数据文件夹。meta map 会得到 title、版本 1.0.0、source(条目 id),以及在条目有层时,以 JSON 形式写入的 layers。块、连接和便利贴原样放入各自的 map。成功时响应是 201,内容为 { "id": "<new canvas id>" };条目未知时是 404。

构建 insurer 条目

server/library/agentic-insurer.json 是生成的。用下面的命令重新生成它:

bash
npm run library

scripts/build-library.mjs 读取 docs/research/agentic-insurer-reference.json 并排布画布。

输入

字段 结构
id、title、description 条目的身份。
layers { id, name, description },从上到下。
blocks { key, layer, kind, proposedKind?, title, subtitle, domain, ... }。domain 是 shared 或一条业务线。
links { from, to, kind, label },使用块的 key。
stickies { text, attachTo? }。attachTo 是块的 key。

块在 proposedKind 是已知类型时使用它,否则使用 kind,再否则回退到 application。块 id 变成 b_<key>。

布局

常量 值
GRID 24
W 168,块的宽度
H 96,块的高度
  • 层作为有引导的条带从上到下堆叠。每个条带的高度向上取整到整数个网格行。
  • 在每个条带中,共享的块排在最前面。
  • 然后每条业务线有一个虚线的 Zone:P&C (IARD)、Health、Life & savings、Wealth management 和 Asset management。Zone 的 id 是 z_<layer>_<line>。
  • 一条业务线在每一层都占用同一列,所以工作坊可以直接从上到下阅读一条业务线。
  • Zone 的宽度取其业务线中最拥挤的那一层所需的宽度,横向最多四个块。
  • 带 attachTo 的便利贴钉在它们的块上。其他的排列在画布的右侧。颜色在蓝、粉、黄、绿和紫之间循环。

脚本会打印层、块、Zone、连接、损坏连接和便利贴的数量,以及每个层的行数。