# OS Notification

> 显示系统通知。

Source: https://docs.sommatic.ai/zh/nodes/io.desktop.notify/

- 标识: `io.desktop.notify`
- 类别: 输入与输出
- 版本: 1.0.0
- 状态: 可用
- 执行方式: async

显示系统通知。

## 配置

- `title` (string, 可选)
- `message` (string, 必填)
- `icon` (string, 可选): 图标路径
- `appName` (string, 可选): 默认值: `Sommatic Orchestrator`.

## 输出端口

- `out` (默认): 通知已发送
- `error`: 通知失败

## 输入契约

- `title` (string, 可选)
- `message` (string, 必填)
- `icon` (string, 可选)
- `appName` (string, 可选)

## 输出契约

- `response` (string, 可选): 通知发送结果

## 在表达式中

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

- `$("OS Notification").item.json.response` (string) = `"<notifier response>"`: 通知发送结果


## 工作原理

在运行 worker 的机器上显示操作系统原生通知，并返回通知程序的响应。

1. 解析配置。`title`、`message`、`icon` 和 `appName` 缺失时回退到输入 payload 中的同名键。
2. 发送通知，使用 `title`（默认 `Alert`）、`message`、`icon`，并以 `appName` 作为应用标识。
3. 等待通知程序回调：成功时从 `out` 输出 `{ response }`，失败时从 `error` 输出。

## 在工作流中

### 节点

```json
{
  "node_id": "node-notify-operator",
  "label": "Notify operator",
  "operator_slug": "io.desktop.notify",
  "operator_version": "1.0.0",
  "config": {
    "title": "Batch finished",
    "message": "{{ $json.processed }} documents processed",
    "appName": "Sommatic Orchestrator"
  }
}
```

### Envelope

```json
{
  "ok": true,
  "data": {
    "response": "<notifier response>"
  },
  "port": "out"
}
```

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

### `out`

通知程序已接受通知。`response` 为平台通知程序返回的值。

```json
{
  "response": "<notifier response>"
}
```

### `error`

通知程序失败。`error` 为通知程序传回的错误对象；若调用抛出异常，则为错误消息。

```json
{
  "error": "<notifier error>"
}
```

## 代码中的行为

- `appName`: 代码不会应用 schema 默认值 `Sommatic Orchestrator`；为空时不发送应用标识。
- `message`: 声明为必填，但 worker 不做校验；请始终设置。

## 错误

| 消息 | 端口 | 原因与处理 |
| --- | --- | --- |
| `<notifier error>` | `error` | 主机没有可用的通知服务（例如无显示器的服务器）。请在有桌面会话的机器上运行该节点。 |

## 说明与限制

- 通知显示在运行编排器 worker 的主机上，而不是 Sommatic AI Web 客户端中。如需通知用户，请使用任务或消息类节点。
- 持久化时，通知程序返回的错误对象可能被序列化为空对象。


## 契约（JSON Schema）

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

```json
{
  "slug": "io.desktop.notify",
  "name": "OS Notification",
  "category": "io",
  "version": "1.0.0",
  "description": "Show system notification.",
  "capabilities": [
    "notification",
    "desktop"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "title": {
        "type": "string"
      },
      "message": {
        "type": "string"
      },
      "icon": {
        "type": "string",
        "description": "Path to icon"
      },
      "appName": {
        "type": "string",
        "default": "Sommatic Orchestrator"
      }
    },
    "required": [
      "message"
    ]
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "title": {
        "type": "string"
      },
      "message": {
        "type": "string"
      },
      "icon": {
        "type": "string"
      },
      "appName": {
        "type": "string"
      }
    },
    "required": [
      "message"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "response": {
        "type": "string",
        "description": "Notification dispatch result"
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Shown",
      "description": "Notification dispatched",
      "is_default": true,
      "supports_condition": true
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "Notification failed",
      "is_default": false,
      "supports_condition": false
    }
  ],
  "execution_mode": "async",
  "required_resources": [],
  "compatible_worker_pools": [
    "desktop-agent"
  ],
  "tags": [
    "desktop",
    "notification"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_link_loom",
    "profile": {
      "name": "Link Loom",
      "verified": true,
      "url": "https://me.veripass.com/link-loom",
      "logo_url": null
    }
  }
}
```

### config_schema

```json
{
  "type": "object",
  "properties": {
    "title": {
      "type": "string"
    },
    "message": {
      "type": "string"
    },
    "icon": {
      "type": "string",
      "description": "Path to icon"
    },
    "appName": {
      "type": "string",
      "default": "Sommatic Orchestrator"
    }
  },
  "required": [
    "message"
  ]
}
```

### input_contract_schema

```json
{
  "type": "object",
  "properties": {
    "title": {
      "type": "string"
    },
    "message": {
      "type": "string"
    },
    "icon": {
      "type": "string"
    },
    "appName": {
      "type": "string"
    }
  },
  "required": [
    "message"
  ]
}
```

### output_contract_schema

```json
{
  "type": "object",
  "properties": {
    "response": {
      "type": "string",
      "description": "Notification dispatch result"
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "out",
    "label": "Shown",
    "description": "Notification dispatched",
    "is_default": true,
    "supports_condition": true
  },
  {
    "port_id": "error",
    "label": "Error",
    "description": "Notification failed",
    "is_default": false,
    "supports_condition": false
  }
]
```
