# 资源文件

> 每个工作流或知识资源都是一个带 sommatic 头部的 JSON 文件。工作流采用 Studio 导出格式并保持节点 id 稳定；运行时字段从不保存。

Source: https://docs.sommatic.ai/zh/git-sync/resource-files/ (updated 2026-11-26)

资源文件是一个工作流或一个知识资源的定义，写成便于在 Pull Request 中评审、并能加载到任何安装实例的形式。
它包含说明自身类型的头部、资源字段，以及在所有依赖安装实例的位置上使用的令牌。

## 头部

每个文件都以 `sommatic` 对象开头：

```json
{
  "sommatic": {
    "kind": "workflow",
    "key": "support.triage",
    "schema_version": "1.0"
  }
}
```

| 字段               | 说明                                 |
| ---------------- | ---------------------------------- |
| `kind`           | `workflow` 或 `knowledge-resource`。 |
| `key`            | 与包清单中该文件的 key 相同。                  |
| `schema_version` | 固定为 `1.0`。                         |

JSON Schema 发布在
[`https://docs.sommatic.ai/schemas/git-sync/resource-header.schema.json`](https://docs.sommatic.ai/schemas/git-sync/resource-header.schema.json)。

## 工作流文件

工作流文件采用 Studio 导出格式（`__export_version` 为 `2.0`）再加上头部。除描述性字段（`name`、`slug`、
`description`、`tags` 等）外，还包含草稿：

- `draft_nodes`：节点，每个节点包含 `node_id`、`label`、`operator_slug`、`operator_version`、`config` 和 `ports`。
- `draft_edges`：连线，`{ from: { node_id, port }, to: { node_id, port } }`。
- `editor_state`：画布布局，其中 `node_positions` 以 `node_id` 为键。

一个小例子：Webhook 接收请求，再用各安装实例各自的大模型提供方对请求分类：

```json
{
  "__export_version": "2.0",
  "description": "Classifies inbound support requests.",
  "draft_edges": [
    {
      "from": { "node_id": "node-webhook", "port": "out" },
      "id": "edge-webhook-classify",
      "to": { "node_id": "node-classify", "port": "in" }
    }
  ],
  "draft_nodes": [
    {
      "config": { "method": "POST", "response_mode": "immediate" },
      "label": "Webhook Receiver",
      "node_id": "node-webhook",
      "operator_slug": "webhook.trigger",
      "operator_version": "1.0.0",
      "ports": [
        { "is_default": true, "label": "Received", "port_id": "out" },
        { "label": "Error", "port_id": "error" }
      ]
    },
    {
      "config": {
        "invocation_mode": "sync",
        "labels": ["billing", "technical", "other"],
        "llm_provider_id": "@@env.LLM_PROVIDER_ID@@",
        "text": "{{ $json.body.message }}"
      },
      "label": "Classify request",
      "node_id": "node-classify",
      "operator_slug": "ai.classify",
      "operator_version": "1.0.0",
      "ports": [
        { "is_default": true, "label": "Classified", "port_id": "success" },
        { "label": "Error", "port_id": "error" }
      ]
    }
  ],
  "editor_state": {
    "node_positions": {
      "node-classify": { "x": 320, "y": 0 },
      "node-webhook": { "x": 0, "y": 0 }
    }
  },
  "name": "Support triage",
  "slug": "support-triage",
  "sommatic": { "key": "support.triage", "kind": "workflow", "schema_version": "1.0" }
}
```

每个节点的 `config` 和 `ports` 以节点目录中该节点的页面为准，例如 [`webhook.trigger`](https://docs.sommatic.ai/zh/nodes/webhook.trigger.md)
和 [`ai.classify`](https://docs.sommatic.ai/zh/nodes/ai.classify.md)。

### 保持 `node_id` 稳定

Sommatic AI 按 `node_id` 比较节点。编辑节点时请保留它的 id：这样预览会把它报告为“已变更”，以 `from: live`
声明的密钥会保留原值，布局也不会变化。换成新 id 则意味着删除了一个节点、又新增了一个节点。

## 知识资源文件

知识资源文件包含资源字段（`name`、`slug`、`description`、`resource_type`、`language`、`tags`、`governance`、
`capabilities`、`content` 等），头部中为 `"kind": "knowledge-resource"`。

## 从不保存的内容

运行时字段属于各个安装实例，从不写入文件：`id`、`created`、`modified`、`status`、`execution_state`、
`latest_version_id` 和 `version_counter`。资源头部 Schema 会拒绝包含其中任一字段的文件。

## 格式

请按 Sommatic AI 导出的方式书写文件，以保持 diff 简洁：键按字母排序、两个空格缩进、文件末尾保留换行。
获得准确格式最简单的方法，是从 Studio 中的 **Export for Git…** 开始（参见[导出与解除关联](https://docs.sommatic.ai/zh/git-sync/export-and-unlink.md)）。

> **注意: id 与密钥都用令牌表示**
>
> 不要在资源文件中写入任何安装实例的物理 id 或密钥。其他资源用 `@@ref.<key>@@`，提供方和凭据 id 用
> `@@env.NAME@@`，密钥用 `@@secret.NAME@@`。参见[环境与令牌](https://docs.sommatic.ai/zh/git-sync/environments-and-tokens.md)。

## 下一步

- [预览与应用](https://docs.sommatic.ai/zh/git-sync/preview-and-apply.md): 把文件加载到安装实例中。
- [分支与 CI](https://docs.sommatic.ai/zh/git-sync/ci.md): 用 Schema 校验每个 Pull Request。
