<span id="按节点身份读取自定义算子源码"></span>

# Read custom operator source by node identity

```{raw} html
<div class="mo-api-page-show-toc" aria-hidden="true"></div>
```

`GET /workflow/v2/custom-operators/source` requires exactly one nonempty `X-Workspace-ID`. Supply canonical `node_id` and `version`, with optional `task_id`. The result envelope uses string `code: "OK"`, `msg: "OK"`, and `data`.

<span id="查询参数"></span>

<span id="两种来源"></span>

## Two sources

With nonempty `task_id`, only the task workspace source is selected, returning `origin: "workspace"`. The task must belong to the current workspace and have context. Task and context are rechecked before reading. The loader currently accepts only `version=draft`, with node prefix `moi:custom.operator:{workspace_id}:` followed by a valid identifier. It reads `operator.json` and `main.py` from that task workspace's operator directory. Input/output schemas must be objects and the manifest is strictly validated. Identity, handler, and language derive from the trusted workspace, currently Python and `main.handle`. Missing task files do not fall back to saved operators.

On first workspace read, this GET may restore a local directory from a persisted snapshot and write a readiness manifest. It is therefore not entirely free of local filesystem writes. It neither publishes the operator nor starts execution.

Without `task_id`, exact `node_id + version` lookup finds a persisted operator in the current tenant and returns `origin: "published"`. Up to two rows are read to detect ambiguity; exactly one is required. published is a protocol source value, not independent proof that the operator is enabled or the workflow published. The operator must be a code type with nonempty SourceFileID. Catalog supplies the source, and whitespace-only content is invalid. Current detail reads do not separately filter disabled state; do not invent an enabled-only restriction.

Each source passes its generated authorization boundary. Internal Platform calls selecting a source do not make the HTTP endpoint authorization-free.

<span id="请求示例"></span>

## Request example

:::::::{div} mo-api-tabs
::::::{tab-set}
:::::{tab-item} Request example

Obtain exact node identity and version from an existing workflow node. Add the current authoring task ID only when reading a task workspace draft:

```bash
curl --get "$PRODUCT_API_BASE_URL/workflow/v2/custom-operators/source" \
  -H "X-API-Key: $PRODUCT_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  --data-urlencode "node_id=$NODE_ID" \
  --data-urlencode "version=$NODE_VERSION" \
  --data-urlencode "task_id=$AUTHORING_TASK_ID"
```

Omit the last parameter when reading a persisted operator. `task_id` selects the source; it is not a fallback hint after a draft read fails.

`PRODUCT_API_BASE_URL` uses the product API prefix `https://api.moi.matrixorigin.cn/v5`.

:::::
:::::{tab-item} Parameters

| Field | Type | Required | Constraints |
| --- | --- | --- | --- |
| `node_id` | string | Yes | Canonical node identity, not an integer operator ID. Exactly once, nonempty, without surrounding whitespace |
| `version` | string | Yes | Exact version for that identity. Exactly once, nonempty, without surrounding whitespace |
| `task_id` | string | No | At most once; nonempty values cannot have surrounding whitespace. Empty means omitted |

:::::
::::::
:::::::

<span id="响应字段"></span>

## Response fields

:::::::{div} mo-api-tabs mo-api-response-tabs
::::::{tab-set}
:::::{tab-item} Fields

| Field | Type | Description |
| --- | --- | --- |
| `data.source` | string | Complete source text, potentially containing sensitive business information. Store according to code and secret handling rules |
| `data.origin` | string | `workspace` or `published` |
| `data.node_id` | string | Node identity |
| `data.version` | string | Node version |
| `data.language` | string | Optional source language |
| `data.handler` | string | Optional entry function |
| `data.name` | string | Optional operator name |
| `data.identifier` | string | Optional operator identifier |

:::::
::::::
:::::::

<span id="错误与待验"></span>

## Errors and pending verification

Duplicate/empty parameters, noncanonical whitespace, and missing source map to 400/ErrParamInvalid; missing workspace headers map to 400/ErrWorkspaceRequired. Missing persisted identities/tasks and task mismatches follow service error mappings. Ambiguous identities and wrapped source-read errors map to 500/ErrServer. Raw file-read errors in task directories are not consistently converted to ErrNotFound; do not describe every missing-file case as404.

Frontend helper comments still describe draft-first with published fallback, unlike current service branches. Existing Go/Python/CLI fixture tests still use origin=draft. Both are maintenance candidates; passing tests do not establish protocol enums.
