# Handoff to Sommatic App

> Nodo terminal: entrega el resultado de un workflow terminado a una Sommatic AI App.

Source: https://docs.sommatic.ai/es/nodes/sommatic.app.handoff/

- Slug: `sommatic.app.handoff`
- Familia: Human in the loop
- Versión: 1.0.0
- Estado: Disponible
- Ejecución: sync

Nodo terminal: entrega el resultado de un workflow terminado a una Sommatic AI App. Crea una tarea HITL persistente con el descriptor de apertura y, si hay una sesión activa de Command Center suscrita, abre la app al instante. Es la contraparte simétrica de sommatic.app.execute (la app como compuerta); aquí la app es el destino final: el workflow termina y no se reanuda.

## Configuración

- `target` (object, obligatorio)
  - `app_slug` (string, obligatorio): Slug de la Sommatic AI App que recibe la entrega (p. ej. my-review-app).
  - `route` (string, opcional): Ruta que se abre dentro de la app (p. ej. /new-sentence). De forma predeterminada, /. Por defecto: `/`.
  - `launch_mode` (string, opcional): Cómo se abre la app cuando hay una sesión activa. Por defecto: `command-center`.
- `input_mapping` (object, opcional): Payload que se precarga en la app, resuelto en el servidor a partir de expresiones {{...}}.
- `organization_id` (string, obligatorio): Organización dueña de la tarea creada.
- `assignee` (string, obligatorio): Identidad (correo) a la que se asigna la tarea.
- `task_title` (string, obligatorio): Título de la tarea HITL persistente que se crea para la entrega.
- `task_type` (object, opcional): Descriptor del tipo de tarea. De forma predeterminada, review.
- `task_priority` (object, opcional): Descriptor de la prioridad de la tarea. De forma predeterminada, medium.

Su configuración muestra los ajustes de ejecución compartidos, pero este nodo aún no aplica reintentos (`retryOnFail`, `maxTries`). Ningún nodo aplica `continueOnFail`.

## Puertos de salida

- `out` (por defecto): Entrega realizada (tarea creada; la app se abre si hay una sesión activa).
- `error`: Error

## Contrato de entrada

- `target` (object, opcional)
- `input_mapping` (object, opcional)
- `organization_id` (string, opcional)
- `assignee` (string, opcional)
- `task_title` (string, opcional)

## Contrato de salida

- `app_handoff_descriptor` (object, opcional)
- `task_id` (string, opcional)
- `task_title` (string, opcional)

## En expresiones

Lo que un nodo posterior puede leer de la salida de este nodo con `$("Handoff to Sommatic App").item.json.<ruta>` (escribe la etiqueta de tu nodo en lugar de `Handoff to Sommatic App`). **Editor** marca las rutas que sugiere el editor de workflows en Previous Nodes (el contrato de salida); **Worker** marca las rutas que el worker devuelve de verdad por `out`, según la salida que muestra Puertos.

- `$("Handoff to Sommatic App").item.json.app_handoff_descriptor` (object) = `{…}`
- `$("Handoff to Sommatic App").item.json.task_id` (string) = `"task-xxxxxxxxxxxxxxx"`
- `$("Handoff to Sommatic App").item.json.task_title` (string) = `"Approve order ord_123"`
- `$("Handoff to Sommatic App").item.json.port` (string) = `"out"` (El editor no la sugiere)
- `$("Handoff to Sommatic App").item.json.app_handoff_descriptor.app_slug` (string) = `"sommatic-approval-desk"` (El editor no la sugiere)
- `$("Handoff to Sommatic App").item.json.app_handoff_descriptor.route_path` (string) = `"/"` (El editor no la sugiere)
- `$("Handoff to Sommatic App").item.json.app_handoff_descriptor.input_payload` (object) = `{…}` (El editor no la sugiere)
- `$("Handoff to Sommatic App").item.json.app_handoff_descriptor.launch_mode` (string) = `"command-center"` (El editor no la sugiere)


## Cómo funciona

Entrega final: crea una tarea para un usuario con un descriptor de apertura de app (slug, ruta, entrada, modo de apertura) y devuelve el descriptor para que el resultado de la ejecución pueda abrir la app.

1. Resuelve la configuración y la combina sobre el payload de entrada (gana la configuración); los `{{ }}` de `input_mapping` se resuelven en el servidor.
2. Arma el descriptor: `app_slug` de `target.app_slug`, `route_path` de `target.route` (por defecto `/`), `launch_mode` de `target.launch_mode` (por defecto `command-center`) e `input_payload` de `input_mapping` (por defecto `{}`).
3. Comprueba `app_slug`, `organization_id`, `assignee` y `task_title`.
4. Envía una tarea con un responsable de tipo usuario, estado `queued`, `source` `workflow` y `metadata.app_handoff_descriptor`; el backend la reclama para esa persona. `task_type` vale `review` y `task_priority` `medium` por defecto.
5. Devuelve `{ app_handoff_descriptor, task_id, task_title }` en el nivel superior por `out`, donde el resultado de la ejecución puede tomar el descriptor; abrir la tarea después vuelve a lanzar la app con los datos cargados.

## En un workflow

### Nodo

```json
{
  "node_id": "node-handoff-approval",
  "label": "Hand off to approval desk",
  "operator_slug": "sommatic.app.handoff",
  "operator_version": "1.0.0",
  "config": {
    "target": {
      "app_slug": "sommatic-approval-desk",
      "route": "/",
      "launch_mode": "command-center"
    },
    "input_mapping": {
      "order_id": "{{ $json.order_id }}",
      "amount": "{{ $json.amount }}"
    },
    "organization_id": "<organization_id>",
    "assignee": "approver@example.com",
    "task_title": "Approve order {{ $json.order_id }}"
  }
}
```

### Envelope

```json
{
  "ok": true,
  "port": "out",
  "app_handoff_descriptor": {
    "app_slug": "sommatic-approval-desk",
    "route_path": "/",
    "input_payload": {
      "order_id": "ord_123",
      "amount": 1250
    },
    "launch_mode": "command-center"
  },
  "task_id": "task-xxxxxxxxxxxxxxx",
  "task_title": "Approve order ord_123"
}
```

## Puertos de salida (comportamiento en el código)

### `out`

La tarea se creó. La ejecución debería terminar aquí; no se suspende.

```json
{
  "port": "out",
  "app_handoff_descriptor": {
    "app_slug": "sommatic-approval-desk",
    "route_path": "/",
    "input_payload": {
      "order_id": "ord_123",
      "amount": 1250
    },
    "launch_mode": "command-center"
  },
  "task_id": "task-xxxxxxxxxxxxxxx",
  "task_title": "Approve order ord_123"
}
```

### `error`

Falta un campo obligatorio o la llamada al backend falló.

```json
{
  "port": "error",
  "error": "Missing 'assignee'"
}
```

## Comportamiento en el código

- `task_type`: El objeto por defecto es `{ id: 1, name: "review", title: "Review" }`, mientras que el catálogo del backend lista `review` con id 12. Define `task_type` de forma explícita si tu bandeja filtra por id.
- `target`: También se leen alternativas no declaradas en el nivel superior: `app_slug`, `route`, `launch_mode`, `input_payload`, `title`, `type` y `priority`.

## Errores

| Mensaje | Puerto | Causa y solución |
| --- | --- | --- |
| `Missing 'target.app_slug'` | `error` | No hay `target.app_slug` (ni un `app_slug` en el nivel superior). |
| `Missing 'organization_id'` | `error` | No está en la configuración ni en el payload. |
| `Missing 'assignee'` | `error` | La entrega siempre necesita una identidad de usuario (correo). |
| `Missing 'task_title'` | `error` | `task_title` (o `title`) está vacío. |
| `Backend did not return a task id` | `error` | El backend respondió sin `result.id`. |
| `Request failed with status code <status>` | `error` | El backend rechazó la tarea. |
| `services.apiManager.uri is not resolved in dependencies.config — check Link Loom Cloud environment config.` | `error` | El orquestador no tiene configurada la dirección del backend. Es un problema de configuración del servicio, no del nodo. |

## Notas y límites

- No se suspende ni espera: lo que esté conectado a `out` se ejecuta enseguida. Úsalo como último nodo de la ejecución.
- El `context.workflow_instance_id` y el `context.trace_id` de la tarea se envían vacíos: el worker los lee de campos que el entorno de ejecución no define, así que la tarea no queda vinculada a la ejecución.
- No es idempotente: cada ejecución crea una tarea nueva. La llamada HTTP no tiene reintentos.
- El worker devuelve sus campos en el nivel superior del sobre, sin `data`, así que el motor usa el sobre completo (incluida la clave `port`) como payload del siguiente nodo.
- El worker no define `ok` (el ejemplo muestra `true`); el motor enruta solo por `port`.


## Contratos (JSON Schema)

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

```json
{
  "slug": "sommatic.app.handoff",
  "name": "Handoff to Sommatic App",
  "category": "hitl",
  "version": "1.0.0",
  "description": "Terminal node: hands a finished workflow's result to a Sommatic AI App. Creates a durable HITL Task carrying the open descriptor and, if a live Command Center session is subscribed, opens the app instantly. Symmetric counterpart of sommatic.app.execute (app-as-gate); this is app-as-terminal — the workflow ends and does not resume.",
  "capabilities": [
    "ui",
    "human",
    "terminal"
  ],
  "config_schema": {
    "type": "object",
    "required": [
      "target",
      "organization_id",
      "assignee",
      "task_title"
    ],
    "properties": {
      "target": {
        "type": "object",
        "title": "Target App",
        "required": [
          "app_slug"
        ],
        "properties": {
          "app_slug": {
            "type": "string",
            "title": "App Slug",
            "description": "Slug of the Sommatic AI App to hand off to (e.g. my-review-app)."
          },
          "route": {
            "type": "string",
            "title": "Route Path",
            "description": "Route opened inside the app (e.g. /new-sentence). Defaults to /.",
            "default": "/"
          },
          "launch_mode": {
            "type": "string",
            "title": "Launch Mode",
            "description": "How the app is opened when a live session exists.",
            "default": "command-center"
          }
        }
      },
      "input_mapping": {
        "type": "object",
        "title": "Input Payload",
        "description": "Payload pre-filled into the app, resolved server-side from {{...}} expressions."
      },
      "organization_id": {
        "type": "string",
        "title": "Organization",
        "description": "Organization that owns the created Task."
      },
      "assignee": {
        "type": "string",
        "title": "Assignee",
        "ui_widget": "user_picker",
        "description": "Identity (email) the Task is assigned to."
      },
      "task_title": {
        "type": "string",
        "title": "Task Title",
        "description": "Title of the durable HITL Task created for the handoff."
      },
      "task_type": {
        "type": "object",
        "title": "Task Type",
        "description": "Task type descriptor. Defaults to review."
      },
      "task_priority": {
        "type": "object",
        "title": "Task Priority",
        "description": "Task priority descriptor. Defaults to medium."
      },
      "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": {
      "target": {
        "type": "object"
      },
      "input_mapping": {
        "type": "object"
      },
      "organization_id": {
        "type": "string"
      },
      "assignee": {
        "type": "string"
      },
      "task_title": {
        "type": "string"
      }
    }
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "app_handoff_descriptor": {
        "type": "object"
      },
      "task_id": {
        "type": "string"
      },
      "task_title": {
        "type": "string"
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Out",
      "is_default": true,
      "description": "Handoff delivered (Task created; app opened if live session)."
    },
    {
      "port_id": "error",
      "label": "Error"
    }
  ],
  "execution_mode": "sync",
  "tags": [
    "ui",
    "terminal",
    "handoff"
  ],
  "is_stateful": false,
  "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": [
    "target",
    "organization_id",
    "assignee",
    "task_title"
  ],
  "properties": {
    "target": {
      "type": "object",
      "title": "Target App",
      "required": [
        "app_slug"
      ],
      "properties": {
        "app_slug": {
          "type": "string",
          "title": "App Slug",
          "description": "Slug of the Sommatic AI App to hand off to (e.g. my-review-app)."
        },
        "route": {
          "type": "string",
          "title": "Route Path",
          "description": "Route opened inside the app (e.g. /new-sentence). Defaults to /.",
          "default": "/"
        },
        "launch_mode": {
          "type": "string",
          "title": "Launch Mode",
          "description": "How the app is opened when a live session exists.",
          "default": "command-center"
        }
      }
    },
    "input_mapping": {
      "type": "object",
      "title": "Input Payload",
      "description": "Payload pre-filled into the app, resolved server-side from {{...}} expressions."
    },
    "organization_id": {
      "type": "string",
      "title": "Organization",
      "description": "Organization that owns the created Task."
    },
    "assignee": {
      "type": "string",
      "title": "Assignee",
      "ui_widget": "user_picker",
      "description": "Identity (email) the Task is assigned to."
    },
    "task_title": {
      "type": "string",
      "title": "Task Title",
      "description": "Title of the durable HITL Task created for the handoff."
    },
    "task_type": {
      "type": "object",
      "title": "Task Type",
      "description": "Task type descriptor. Defaults to review."
    },
    "task_priority": {
      "type": "object",
      "title": "Task Priority",
      "description": "Task priority descriptor. Defaults to medium."
    },
    "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": {
    "target": {
      "type": "object"
    },
    "input_mapping": {
      "type": "object"
    },
    "organization_id": {
      "type": "string"
    },
    "assignee": {
      "type": "string"
    },
    "task_title": {
      "type": "string"
    }
  }
}
```

### output_contract_schema

```json
{
  "type": "object",
  "properties": {
    "app_handoff_descriptor": {
      "type": "object"
    },
    "task_id": {
      "type": "string"
    },
    "task_title": {
      "type": "string"
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "out",
    "label": "Out",
    "is_default": true,
    "description": "Handoff delivered (Task created; app opened if live session)."
  },
  {
    "port_id": "error",
    "label": "Error"
  }
]
```
