# Versions

Every upload is compiled and stored as a version, named by the content hash of what was compiled. A turn runs the version that was current when it opened, from start to finish.

Upload: YAML uploaded → Compile: Compiled → Version: Stored by hash → Current: Becomes current

Uploading the same YAML again stores nothing new: the workflow points back at the version it already holds.

## Endpoints

| Endpoint | Does |
| --- | --- |
| `POST /workflow/workflows` | Uploads a new workflow. The body is its YAML. Answers 201 with its id, name and contentHash. |
| `PUT /workflow/workflows/{workflowId}` | Uploads a new version of a workflow, which becomes its current version. Answers 200. |
| `GET /workflow/workflows` | The workflows you reach by name, your organization's own and Momor's shared ones, a page at a time as { count, items }, with skip and take; each says whether it is shared. |
| `GET /workflow/workflows/{workflowId}` | The current version: id, name, contentHash, the YAML, and shared, true for Momor's own workflows, which you read and run but never change. |
| `GET /workflow/workflows/{workflowId}/versions/{hash}` | One version: its contentHash, its YAML and when it was uploaded. |

```bash
curl -X PUT "https://api.momor.ai/workflow/workflows/$WORKFLOW_ID" \
  -H "Authorization: Bearer $MOMOR_API_KEY" \
  -H "Content-Type: application/yaml" \
  --data-binary @triage.yaml
```

## Turns pin their version

- **At the start.** A turn records the content hash of the version it opened on, and every later step of that turn, including after a restart or a resume, runs that version.
- **Never migrated.** A newer upload affects only turns that open after it. A turn that failed and is resumed still runs the version it started with.
- **Called workflows too.** A workflow called from a step pins its own version when the call starts.

To see what a turn ran, read its `workflowContentHash` from the run and fetch that version.

## Workflows Momor shares

Some workflows are shared with every organization, such as the Answer and Intent workflows behind Search. An organization can read and run them but not change them: a `PUT` to a shared workflow stores the upload as the organization’s own workflow, under a new id, and answers `201`. The shared workflow is left as it was.

> **Not yet available**
> There is no endpoint that lists a workflow’s versions or one that lists an organization’s workflows. Keep the ids and hashes the upload returns.
