# Execute Sommatic App

> 请求用户与指定的 Sommatic AI App 界面进行交互。

Source: https://docs.sommatic.ai/zh/nodes/sommatic.app.execute/

- 标识: `sommatic.app.execute`
- 类别: 人工介入
- 版本: 1.0.0
- 状态: 部分可用. 在后端创建应用交互后返回 `__signal: 'SUSPEND'`，但执行引擎从不处理该信号：工作流不会等待应用输出，而是经由默认端口继续。
- 执行方式: async

请求用户与指定的 Sommatic AI App 界面进行交互。

## 配置

- `app_identifier` (string, 必填): 前端应用/微前端的 slug 或 ID
- `assignee` (string, 可选)
- `timeout_ms` (integer, 可选): 默认值: `3600000`.
- `configuration` (object, 可选): 传给 UI 应用的 props 或上下文

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

## 输出端口

- `completed` (默认): 交互已完成
- `timeout`: 交互已过期
- `error`: Error

## 输入契约

- `app_identifier` (string, 可选)
- `assignee` (string, 可选)
- `timeout_ms` (integer, 可选)
- `configuration` (object, 可选)

## 输出契约

- `result` (object, 可选)
- `status` (string, 可选)

## 在表达式中

后续节点可通过 `$("Execute Sommatic App").item.json.<路径>` 读取此节点输出中的内容，即工作流编辑器在 Previous Nodes 中提示的路径（输出契约）。

- `$("Execute Sommatic App").item.json.result` (object)
- `$("Execute Sommatic App").item.json.status` (string)


## 工作原理

部分实现。请求后端创建应用交互，并返回引擎不会处理的挂起信号：运行既不等待应用，也不会沿 `completed` 或 `timeout` 继续。

1. 解析配置并合并到输入 payload 之上（配置优先）。
2. 缺少 `app_identifier` 时抛出异常：运行失败，除非被 `flow.try` 作用域捕获。
3. 向后端 HITL 交互端点提交 `{ type: "app_execution", app_identifier, configuration, assignee, expires_in_ms: timeout_ms }`；HTTP 失败会被重新抛出。
4. 返回 `{ __signal: "SUSPEND", __metadata: { type: "sommatic_app_interaction", id, resume_on: ["completed", "timeout"] } }`。
5. 信封没有端口，引擎将其路由到本节点未声明的 `out`：`completed` 或 `timeout` 的连线永远不会被执行，分支结束，运行在不等待的情况下完成。

## 在工作流中

### 节点

```json
{
  "node_id": "node-open-intake",
  "label": "Open intake app",
  "operator_slug": "sommatic.app.execute",
  "operator_version": "1.0.0",
  "config": {
    "app_identifier": "sommatic-structured-intake",
    "assignee": "operator@example.com",
    "timeout_ms": 3600000,
    "configuration": {
      "case_id": "{{ $json.case_id }}"
    }
  }
}
```

### Envelope

```json
{
  "ok": true,
  "port": "out",
  "__signal": "SUSPEND",
  "__metadata": {
    "type": "sommatic_app_interaction",
    "id": "<interaction_id>",
    "resume_on": [
      "completed",
      "timeout"
    ]
  }
}
```

## 输出端口 (代码中的行为)

### `completed`

从不触发。

### `timeout`

从不触发。

### `error`

从不触发：失败会以异常抛出并导致运行失败。

## 代码中的行为

- `timeout_ms`: 仅作为 `expires_in_ms` 发送给后端；编排器不会强制执行。

## 错误

| 消息 | 端口 | 原因与处理 |
| --- | --- | --- |
| `Missing 'app_identifier'` | `error` | 以异常抛出。运行失败并报 `Node <node_id> (sommatic.app.execute) failed: Missing 'app_identifier'`，或进入外层 `flow.try` 的 catch 节点。 |
| `Request failed with status code <status>` | `error` | 后端拒绝交互请求时抛出；效果同上。 |

## 说明与限制

- 审阅时，Sommatic AI 后端未提供处理该交互请求的接口，因此该调用预计会失败，运行也随之失败。编排器的恢复操作仅接受 `stoneos.industry.apply`。
- 如今需要人工步骤时，请使用 `human.task.create`（不阻塞运行的任务）或 `sommatic.app.handoff`（交给应用的终止节点）。
- 示例信封中的 `ok` 和 `port` 是引擎的解读；worker 只返回 `__signal` 和 `__metadata`。


## 契约（JSON Schema）

### All (`*.definition.js`)

```json
{
  "slug": "sommatic.app.execute",
  "name": "Execute Sommatic App",
  "category": "hitl",
  "version": "1.0.0",
  "description": "Requests a user to interact with a specific Sommatic AI App UI.",
  "capabilities": [
    "ui",
    "interactive",
    "human"
  ],
  "config_schema": {
    "type": "object",
    "required": [
      "app_identifier"
    ],
    "properties": {
      "app_identifier": {
        "type": "string",
        "title": "App Identifier",
        "description": "Slug or ID of the frontend app/micro-frontend"
      },
      "assignee": {
        "type": "string",
        "title": "Assignee",
        "ui_widget": "user_picker"
      },
      "timeout_ms": {
        "type": "integer",
        "default": 3600000
      },
      "configuration": {
        "type": "object",
        "title": "App Configuration",
        "description": "Props or context passed to the UI app"
      },
      "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": {
      "app_identifier": {
        "type": "string"
      },
      "assignee": {
        "type": "string"
      },
      "timeout_ms": {
        "type": "integer"
      },
      "configuration": {
        "type": "object"
      }
    }
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "result": {
        "type": "object"
      },
      "status": {
        "type": "string"
      }
    }
  },
  "ports": [
    {
      "port_id": "completed",
      "label": "Completed",
      "is_default": true,
      "description": "Interaction completed"
    },
    {
      "port_id": "timeout",
      "label": "Timeout",
      "description": "Interaction expired"
    },
    {
      "port_id": "error",
      "label": "Error"
    }
  ],
  "execution_mode": "async",
  "tags": [
    "ui",
    "interactive"
  ],
  "is_stateful": true,
  "publisher": {
    "identity": "org_sommatic_ai",
    "profile": {
      "name": "Sommatic AI",
      "verified": true,
      "url": "https://me.veripass.com/sommatic",
      "logo_url": null
    }
  }
}
```

### config_schema

```json
{
  "type": "object",
  "required": [
    "app_identifier"
  ],
  "properties": {
    "app_identifier": {
      "type": "string",
      "title": "App Identifier",
      "description": "Slug or ID of the frontend app/micro-frontend"
    },
    "assignee": {
      "type": "string",
      "title": "Assignee",
      "ui_widget": "user_picker"
    },
    "timeout_ms": {
      "type": "integer",
      "default": 3600000
    },
    "configuration": {
      "type": "object",
      "title": "App Configuration",
      "description": "Props or context passed to the UI app"
    },
    "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

```json
{
  "type": "object",
  "properties": {
    "app_identifier": {
      "type": "string"
    },
    "assignee": {
      "type": "string"
    },
    "timeout_ms": {
      "type": "integer"
    },
    "configuration": {
      "type": "object"
    }
  }
}
```

### output_contract_schema

```json
{
  "type": "object",
  "properties": {
    "result": {
      "type": "object"
    },
    "status": {
      "type": "string"
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "completed",
    "label": "Completed",
    "is_default": true,
    "description": "Interaction completed"
  },
  {
    "port_id": "timeout",
    "label": "Timeout",
    "description": "Interaction expired"
  },
  {
    "port_id": "error",
    "label": "Error"
  }
]
```
