# Open File/URL

> 用系统默认应用打开文件或 URL。

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

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

用系统默认应用打开文件或 URL。

## 配置

- `target` (string, 必填): URL 或文件路径
- `app` (string, 可选): 可选，指定应用名称

## 输出端口

- `out` (默认): 目标已成功打开
- `error`: 无法打开目标

## 输入契约

- `target` (string, 必填)
- `app` (string, 可选)

## 输出契约

- `opened` (string, 可选): 目标已打开

## 在表达式中

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

- `$("Open File/URL").item.json.opened` (string) = `"https://app.example.com/reports/2026-11"`: 目标已打开


## 工作原理

在运行 worker 的机器上，使用默认应用或指定应用打开 URL 或文件。

1. 解析配置。`target` 和 `app` 缺失时回退到输入 payload 中的同名键。
2. `target` 为空时从 `error` 失败输出。
3. 使用系统默认处理程序或 `app` 指定的应用打开 `target`。
4. 打开命令启动后，从 `out` 返回 `{ opened: <target> }`。

## 在工作流中

### 节点

```json
{
  "node_id": "node-open-report",
  "label": "Open report",
  "operator_slug": "io.desktop.open",
  "operator_version": "1.0.0",
  "config": {
    "target": "https://app.example.com/reports/{{ $json.period }}"
  }
}
```

### Envelope

```json
{
  "ok": true,
  "data": {
    "opened": "https://app.example.com/reports/2026-11"
  },
  "port": "out"
}
```

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

### `out`

已为 `target` 启动打开命令。

```json
{
  "opened": "https://app.example.com/reports/2026-11"
}
```

### `error`

缺少 `target`，或无法启动打开命令。

```json
{
  "error": "target is required"
}
```

## 错误

| 消息 | 端口 | 原因与处理 |
| --- | --- | --- |
| `target is required` | `error` | 配置和输入 payload 中都没有 `target`。请设置 URL 或文件的绝对路径。 |
| `<open command error message>` | `error` | 主机无法启动处理程序或 `app` 指定的应用。请确认该应用存在于该机器上。 |

## 说明与限制

- `out` 仅表示已启动打开命令，并不代表应用已完成加载目标。根据平台处理程序的不同，不存在的文件路径也可能到达 `out`。
- 目标在运行编排器 worker 的主机上打开，而不是在用户设备上。


## 契约（JSON Schema）

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

```json
{
  "slug": "io.desktop.open",
  "name": "Open File/URL",
  "category": "io",
  "version": "1.0.0",
  "description": "Open a file or URL in default system application.",
  "capabilities": [
    "desktop",
    "open",
    "launch"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "target": {
        "type": "string",
        "description": "URL or File Path"
      },
      "app": {
        "type": "string",
        "description": "Optional specific app name"
      }
    },
    "required": [
      "target"
    ]
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "target": {
        "type": "string"
      },
      "app": {
        "type": "string"
      }
    },
    "required": [
      "target"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "opened": {
        "type": "string",
        "description": "Target opened"
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Opened",
      "description": "Target opened successfully",
      "is_default": true,
      "supports_condition": true
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "Failed to open target",
      "is_default": false,
      "supports_condition": false
    }
  ],
  "execution_mode": "async",
  "required_resources": [],
  "compatible_worker_pools": [
    "desktop-agent"
  ],
  "tags": [
    "desktop",
    "utility"
  ],
  "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": {
    "target": {
      "type": "string",
      "description": "URL or File Path"
    },
    "app": {
      "type": "string",
      "description": "Optional specific app name"
    }
  },
  "required": [
    "target"
  ]
}
```

### input_contract_schema

```json
{
  "type": "object",
  "properties": {
    "target": {
      "type": "string"
    },
    "app": {
      "type": "string"
    }
  },
  "required": [
    "target"
  ]
}
```

### output_contract_schema

```json
{
  "type": "object",
  "properties": {
    "opened": {
      "type": "string",
      "description": "Target opened"
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "out",
    "label": "Opened",
    "description": "Target opened successfully",
    "is_default": true,
    "supports_condition": true
  },
  {
    "port_id": "error",
    "label": "Error",
    "description": "Failed to open target",
    "is_default": false,
    "supports_condition": false
  }
]
```
