本页内容
Sommatic 文档
打开控制台

Generate UUID

生成密码学强度的唯一标识符(UUID/NanoID)。

以 Markdown 查看
在以下应用中打开
数据 可用 data.uuid 版本 1.0.0 执行方式: sync

生成随机 v4 UUID、确定性 v5 UUID 或 20 位随机十六进制 id,以 { uuid, result } 返回。

该算子生成的唯一字符串可用作数据库键、交易 ID 或幂等令牌。

格式:

  • v4: 随机 UUID(标准)。
  • v5: 基于名称的 UUID(由 namespace + name 确定性生成)。
  • NanoID: 紧凑、URL 友好的唯一字符串。

适用场景:

  • 为新创建的资源分配 ID。
  • 生成用于跟踪请求链的关联 ID。

工作原理

  1. 解析配置;version 默认为 v4。
  2. v4:随机 UUID。
  3. v5:需要 namespace_id(UUID)和 name;相同组合总是得到相同的 UUID。
  4. nanoid:10 个随机字节的十六进制形式(20 个字符);并非真正的 nanoid。
  5. 通过 out 返回 { uuid, result }(同一个值两次);输入 payload 不会保留。

在工作流中

节点在工作流文件(draft_nodes[])中的写法,以及一次成功运行的 envelope。

{
  "node_id": "node-order-key",
  "label": "Order key",
  "operator_slug": "data.uuid",
  "operator_version": "1.0.0",
  "config": {
    "version": "v5",
    "namespace_id": "6ba7b811-9dad-11d1-80b4-00c04fd430c8",
    "name": "{{ $json.order_id }}"
  }
}

配置

version string 可选

要生成的 ID 类型。

默认值: v4

可选值: v4v5nanoid

namespace_id string 可选

用于确定性 v5 生成的命名空间 UUID。

name string 可选

用于确定性 v5 生成的输入名称。

配置中会显示通用执行设置,但该节点目前不执行重试(retryOnFail、maxTries)。所有节点均未实现 continueOnFail。

输出端口

out 默认

id 已生成。

数据
{
  "uuid": "3b1f8e2a-6c4d-4f7e-9a2b-8d5c1e0f7a34",
  "result": "3b1f8e2a-6c4d-4f7e-9a2b-8d5c1e0f7a34"
}
error

v5 所需输入缺失或无效,或 version 未知。

数据
{
  "ok": false,
  "errors": [
    "UUID Error: v5 requires namespace_id and name"
  ],
  "port": "error"
}

在表达式中

后续节点可通过 $("Generate UUID").item.json.<路径> 读取此节点输出中的内容(请把 Generate UUID 换成你的节点标签)。Editor 标记工作流编辑器在 Previous Nodes 中提示的路径(输出契约);Worker 标记 worker 实际通过 out 返回的路径,依据“端口”一节所示的输出。

表达式EditorWorker
$("Generate UUID").item.json.uuidstring= "3b1f8e2a-6c4d-4f7e-9a2b-8d5c1e0f7a34"生成的唯一标识符。
$("Generate UUID").item.json.resultstring编辑器不提示= "3b1f8e2a-6c4d-4f7e-9a2b-8d5c1e0f7a34"—

— Worker: worker 会返回它,但编辑器不会提示:请手动输入。对象内部的键可能取决于你的数据或配置(例如每个标签一个键)。

错误

消息 端口 原因与处理
UUID Error: v5 requires namespace_id and name error version 为 v5,但两个键之一为空。
UUID Error: Invalid UUID error namespace_id 不是有效的 UUID。
UUID Error: Unknown UUID version: <version> error version 不是 v4、v5 或 nanoid。

输入契约

name string 可选

用于 v5 生成的输入名称(可选)。

输出契约

uuid string 可选

生成的唯一标识符。

契约(JSON Schema)

与编排器声明完全一致的定义。All 是完整的 *.definition.js;可与上方各节对照,找出文档与 schema 之间的差异。发布前可用它校验节点。

{
  "slug": "data.uuid",
  "name": "Generate UUID",
  "category": "data",
  "version": "1.0.0",
  "description": "Generates a cryptographically strong unique identifier (UUID/NanoID).\n\n  This operator produces unique strings suitable for database keys, transaction IDs, or idempotency tokens.\n\n  **Formats:**\n  - **v4:** Random UUID (Standard).\n  - **v5:** Name-based UUID (Deterministic based on namespace + name).\n  - **NanoID:** Compact, URL-friendly unique string.\n\n  **Use Cases:**\n  - Assigning an ID to a newly created resource.\n  - Generating a correlation ID for tracking request chains.",
  "capabilities": [
    "utils",
    "id-generation",
    "security"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "version": {
        "type": "string",
        "enum": [
          "v4",
          "v5",
          "nanoid"
        ],
        "default": "v4",
        "title": "Format",
        "description": "Type of ID to generate."
      },
      "namespace_id": {
        "type": "string",
        "title": "Namespace UUID (v5 only)",
        "description": "Namespace UUID for deterministic v5 generation."
      },
      "name": {
        "type": "string",
        "title": "Name (v5 only)",
        "description": "Input name used for deterministic v5 generation."
      },
      "execution": {
        "type": "object",
        "title": "Execution Settings",
        "properties": {
          "alwaysOutputData": {
            "type": "boolean",
            "title": "Always Output Data",
            "description": "Always output data, even on error (if configured).",
            "default": false
          },
          "retryOnFail": {
            "type": "boolean",
            "title": "Retry On Fail",
            "description": "Retry the execution if it fails.",
            "default": false
          },
          "maxTries": {
            "type": "integer",
            "title": "Max Retries",
            "description": "Number of retries.",
            "default": 3,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "waitBetweenTries": {
            "type": "integer",
            "title": "Wait Between Retries (ms)",
            "default": 1000,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "continueOnFail": {
            "type": "boolean",
            "title": "Continue On Fail",
            "description": "Do not crash workflow on error.",
            "default": false
          },
          "timeout_ms": {
            "type": "integer",
            "title": "Timeout (ms)",
            "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
            "default": 300000
          }
        }
      }
    }
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "name": {
        "type": "string",
        "description": "Input name for v5 generation (optional)."
      }
    }
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "uuid": {
        "type": "string",
        "description": "The generated unique identifier."
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Generated",
      "is_default": true
    },
    {
      "port_id": "error",
      "label": "Error"
    }
  ],
  "execution_mode": "sync",
  "tags": [
    "id",
    "uuid",
    "key",
    "generator"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_link_loom",
    "profile": {
      "name": "Link Loom",
      "verified": true,
      "url": "https://me.veripass.com/link-loom",
      "logo_url": null
    }
  }
}

执行

执行方式
sync
有状态
否
重试(retryOnFail)
否
能力
utilsid-generationsecurity
标签
iduuidkeygenerator

说明与限制

  • payload 会被 { uuid, result } 替换:可用 $("Node") 引用之前的数据,或在其他节点中直接用 {{ $uuid }} 生成 id。
  • 当返回的信封没有 data(或 data 为假值)时,引擎会把整个信封作为节点输出:经 error 端口时,下一个节点收到的 payload 是 { ok: false, errors: [...], port: "error" }。

已对照编排器代码核实 · 31e874b · 2026-11-26

安装智能体工具

为你的编程智能体接入 Sommatic AI 官方文档:技能包、文档 MCP 服务器与 Markdown 页面,无需再抓取网页。

安装 Sommatic AI CLI,并为检测到的智能体配置合适的插件。

npx @sommatic/cli agent setup
智能体如何读取本文档