表达式 API 参考
表达式可使用的全部变量与辅助函数,包含签名、参数、返回值、错误,以及在 Sommatic AI 实际运行的引擎上执行过的示例。
{{ }} 中的表达式可以读取或调用的全部内容。这些页面上的每个示例都在已部署的编排器表达式引擎上、基于同一个示例上下文运行过,所示结果即引擎的实际返回值。
Previous Nodes
Previous Nodes: 每个节点的表达式 API:后续节点通过 $("Label").item.json 读取的输出路径,包括编辑器提示的路径与 worker 实际返回的路径。
Input Data
到达当前节点的数据。
| 签名 | 返回 | 说明 |
|---|---|---|
$json | object | 当前节点的输入。 |
$binary | object | 附加到当前条目的二进制数据(文件)。保留:始终为 {}。 |
$itemIndex | number | 当前条目在批次中的索引。保留:始终为 0。 |
$runIndex | number | 当前尝试的索引。保留:始终为 0。 |
Input Access
以条目形式呈现的同一输入:当前条目与条目列表。
| 签名 | 返回 | 说明 |
|---|---|---|
$input.item | { json, binary } | 当前输入条目:{ json, binary }。 |
$input.all() | list | 所有输入条目,以列表形式返回。每次执行一个条目。 |
$input.first() | { json, binary } | 第一个输入条目(即当前条目)。 |
$input.last() | { json, binary } | 最后一个输入条目(即当前条目)。 |
$input.params | object | 上一个节点的配置。保留:始终为 {}。 |
$input.context | object | 上一个节点传递的上下文。保留:始终为 {}。 |
Node Reference
本次运行中任何已执行节点的输出、上一个节点,以及串联工作流的入口点。
| 签名 | 返回 | 说明 |
|---|---|---|
$(label) | NodeAccessor | 之前某个节点的输出,按标签查找。 |
$prevNode | object | 上一个节点的元数据。保留:始终为 Start。 |
$('Chain Entry Point').item.json | { …data, chain_context } | 由 workflow.chain 启动的工作流所接收的内容:数据和链上下文。 |
Execution Context
当前运行、正在执行的工作流与节点的 id,以及环境。
| 签名 | 返回 | 说明 |
|---|---|---|
$execution | object | 当前运行的 id。 |
$workflow | object | 正在运行的工作流的 slug 和版本。 |
$node | object | 当前节点的 id 和标签。 |
$env | object | 环境变量。保留:始终为 {}。 |
$vars | object | 工作流变量。保留:始终为 {}。 |
$nodeVersion | number | 当前节点算子的版本。保留:始终为 1。 |
Date & Time
当前时刻与今天,均为 Luxon DateTime 值。
| 签名 | 返回 | 说明 |
|---|---|---|
$now | DateTime | 节点运行的时刻,类型为 Luxon DateTime。 |
$today | DateTime | 当天的起始时刻,类型为 Luxon DateTime。 |
Generators
新生成的随机标识符。
| 签名 | 返回 | 说明 |
|---|---|---|
$uuid | string | 每次读取都生成新的 UUID v4。 |
$randomId({ length, prefix }) | string | 带前缀的随机 id。 |
Encoders
Base64 与 URL 查询字符串。
| 签名 | 返回 | 说明 |
|---|---|---|
$base64Encode(value) | string | 文本或 JSON 值的 URL 安全 Base64 编码。 |
$base64Decode(text) | string | Base64 字符串所编码的文本。 |
$toQueryString(object) | string | 以 ? 开头的 URL 查询字符串。 |
Validators
对值的检查。
| 签名 | 返回 | 说明 |
|---|---|---|
$isEmpty(value) | boolean | 值没有自有键时为 true。 |
Helpers
空值的默认值、slug、JMESPath 查询与 lodash。
| 签名 | 返回 | 说明 |
|---|---|---|
$ifEmpty(value, fallback) | any | 返回 value;value 为空时返回 fallback。 |
$slugify(text) | string | 小写、以连字符分隔的 slug。 |
$jmespath(data, query) | any | 对任意值执行 JMESPath 查询的结果。 |
_ | lodash | lodash:约 300 个用于列表、对象和文本的函数。 |
JavaScript Globals
JavaScript Globals: Math、JSON、字符串、数字、列表、对象、日期、正则表达式、Map 与 Set、Intl,以及不可用的部分。
库
表达式可使用的各个库的完整参考,依据编排器内置的确切版本生成。
- lodash: 全部 lodash 函数,通过
_调用。 - Luxon 日期:
$now与$today的全部 DateTime 方法。 - JMESPath:
$jmespath使用的查询语言。 - JSONata 函数: JSONata 字段中的函数。
不存在的名称
开发者常从其他工具或旧文档中期待、但引擎并未提供的名称。使用不存在的名称会抛出 … is not defined。
| 名称 | 替代方案 |
|---|---|
$node["X"].json | $node 仅指当前节点。读取其他节点请用 $('X').item.json。 |
$items() | 使用 $input.all() 或 $('X').all()。 |
$parameter | 节点自身的配置不对其表达式开放。 |
$config | 服务配置从不开放。 |
DateTime | 不是全局名称。请使用 $now.constructor。 |
Several items per node | 每次节点执行只处理一个条目。请用 flow.split 和 flow.join 迭代,或在单个表达式中使用 map。 |
示例上下文
示例基于以下数据运行:当前节点的输入($json)、已运行的节点($(…))、本次运行的 ID 以及当前节点。时钟固定为 2026-11-26T14:30:00.000Z,服务器时区为 UTC,因此各页面中 $now 与 $today 的值都相同。
{
"$json": {
"body": {
"order_id": "ord_1042",
"email": "ana.perez@example.com",
"customer": {
"name": "Ana Pérez",
"segment": "gold"
},
"priority": "",
"items": [
{
"sku": "A-100",
"qty": 2,
"price": 10.5
},
{
"sku": "B-200",
"qty": 0,
"price": 4
},
{
"sku": "C-300",
"qty": 1,
"price": 25
}
],
"tags": [
"new",
"web",
"new"
],
"created_at": "2026-11-25T09:15:00Z"
},
"headers": {
"content-type": "application/json"
},
"query": {},
"method": "POST"
}
}{
"Webhook Receiver": "= $json",
"Normalize input": {
"correlation_id": "c-7f3a",
"channel": "web"
},
"Classify": {
"label": "billing",
"confidence": 0.92
}
}{
"$execution": {
"id": "fir-xxxx",
"flow_instance_id": "fi-xxxx",
"flow_definition_id": "fd-xxxx",
"flow_version_id": "fv-xxxx",
"flow_slug": "order-intake"
},
"$node": {
"id": "node-notify",
"label": "Notify customer"
}
}串联工作流的示例基于第二个上下文运行:一个由 workflow.chain 启动的工作流,其 workflow.trigger 节点的标签为 Chain Entry Point。
{
"$json": {
"order_id": "ord_1042",
"customer_email": "ana.perez@example.com",
"amount": 46,
"chain_context": {
"caller_flow_definition_id": "fd-caller-xxxx",
"caller_flow_instance_id": "fi-caller-xxxx",
"caller_flow_slug": "order-intake",
"caller_node_id": "node-chain-billing",
"correlation_id": "chain-7Hq2Lw9sKd3pXa1mZr4t",
"root_flow_instance_result_id": "fir-root-xxxx"
}
},
"nodes": {
"Chain Entry Point": {
"order_id": "ord_1042",
"customer_email": "ana.perez@example.com",
"amount": 46,
"chain_context": {
"caller_flow_definition_id": "fd-caller-xxxx",
"caller_flow_instance_id": "fi-caller-xxxx",
"caller_flow_slug": "order-intake",
"caller_node_id": "node-chain-billing",
"correlation_id": "chain-7Hq2Lw9sKd3pXa1mZr4t",
"root_flow_instance_result_id": "fir-root-xxxx"
}
}
},
"$execution": {
"id": "fir-root-xxxx",
"run_flow_instance_result_id": "fir-hop-xxxx",
"flow_slug": "billing-review"
}
} 示例运行所基于的编排器提交 31e874b