<!-- AANCER Developer Reference (English): every field, limit and error code, part 10 of 16. All parts: https://aancer.ai/dev/llms.txt -->

## Field reference

JSON Schema: [hook.schema.json](https://aancer.ai/dev/schemas/hook.schema.json)

### Hook spec

| Field | Type | Required | Rules |
|---|---|---|---|
| `id` | string | yes | `^[a-z0-9][a-z0-9._-]{0,63}$`, unique per workspace |
| `workspace` | string | no | a workspace id or `{{param.<id>}}` |
| `title` | string | no | at most 120 characters. Default: the id |
| `event.name` | string | yes | one of the ten event names below |
| `event.version` | integer | no | `1` |
| `filter` | array | no | up to 8 clauses `{ path, op, value? }`. All must match. For "or", write two hooks |
| `handler.type` | string | yes | `workflow` or `agent` |
| `handler.ref` | string | yes | a workflow id, or an agent reference such as `agent:digest` |
| `delivery.atLeastOnce` | boolean | no | |
| `delivery.maxConcurrency` | integer | no | 1 to 20, default 1 |
| `delivery.retry.max` | integer | no | 0 to 10, applied up to the installation's setting (default 3) |
| `delivery.retry.backoffSeconds` | integer[] | no | up to 10 values, each 1 to 86400. Default `[30, 120, 480]`. The last value repeats |
| `enabled` | boolean | no | default `true` |

With the REST API you can also send `dataClassification` (`sovereign`, `internal` or `permitted`): the data class for agent handler runs. Leave it out of pack specs. For a pack hook, a workspace admin sets it after install.

### Filter clauses

- `path`: `actor.role`, or a dot path starting with `payload.` or `resource.`.
- `op`: `eq`, `neq`, `in`, `gt`, `gte`, `lt`, `lte`, `contains`, `exists`.
- `value`: required for every op except `exists`. `in` needs an array. `exists` with `value: false` means "absent".
- Types are strict: `"5"` does not equal `5`. `gt`, `gte`, `lt`, `lte` compare numbers only. `contains` is a case-insensitive substring match on text, or an element match on arrays. A type mismatch is simply false.

### Event catalog

Every handler receives this envelope:

```json
{
  "id": "evt_01",
  "name": "approval.decided",
  "version": 1,
  "workspaceId": "ws-finance",
  "occurredAt": "2026-11-20T10:00:00Z",
  "actor": { "sub": "u_admin", "role": "admin" },
  "resource": { "type": "approval", "id": "apr_01" },
  "payload": { "approvalId": "apr_01", "runId": "run_03", "flowId": "flow_invoices", "outcome": "rejected", "decidedBy": "u_admin", "note": "Amount exceeds budget" },
  "dataCategories": ["CONTACT"]
}
```

| Event | Payload fields (always) | Payload fields (sometimes) |
|---|---|---|
| `run.completed` | `runId`, `flowId` | `flowName`, `durationMs`, `stepCount`, `triggeredBy` |
| `run.failed` | `runId`, `flowId`, `status` (`FAILED`, `INTERNAL_ERROR`, `TIMEOUT`) | `flowName`, `errorRef` |
| `approval.decided` | `approvalId`, `runId`, `outcome` (`approved`, `rejected`), `decidedBy` | `flowId`, `note`, `via` (`web`, `teams`, `slack`) |
| `approval.requested` | `approvalId`, `runId`, `toolId`, `surface`, `expiresAt` | `conversationId` |
| `dataset.rows.published` | `datasetId`, `mode` (`append`, `upsert`, `replace`), `inserted`, `rowCount`, `source` | `updated`, `runId` |
| `dashboard.published` | `dashboardId`, `version`, `publishedBy` | |
| `document.ingested` | `knowledgeSetId`, `documentId` | `fileType`, `bytes`, `ocr` |
| `user.provisioned` | `sub`, `roleName`, `via` (`invite`, `scim`, `sso`, `admin`) | |
| `workspace.member.changed` | `workspaceId`, `sub`, `change` (`added`, `removed`, `role_changed`) | `roleName` |
| `schedule.run.completed` | `taskId`, `runId`, `trigger` (`schedule`, `manual`) | `conversationId`, `agentId` |

Events never carry document content or raw error text. `GET /api/events/catalog` returns the live catalog with schemas and sample events.

### What the handler gets

- **Workflow**: the workflow must be published with the **AANCER Event** trigger. If the trigger names an event, it must be the hook's event. The trigger output is `{ event, eventName, eventId, workspaceId, occurredAt, payload }`, so steps use `{{trigger.event}}` or `{{trigger.payload.datasetId}}`.
- **Agent**: a governed agent run. The task text holds the event name, time, workspace, resource and the payload as JSON.

A delivery counts as delivered when the run starts. If the run fails later, the failure is shown on the delivery, but it is not retried automatically.

## Full examples

### Alert when a dataset receives new rows

```json
{
  "id": "orders_alert",
  "title": "New orders alert",
  "event": { "name": "dataset.rows.published", "version": 1 },
  "filter": [
    { "path": "payload.datasetId", "op": "eq", "value": "sales_orders" },
    { "path": "payload.inserted", "op": "gt", "value": 0 }
  ],
  "handler": { "type": "workflow", "ref": "flow_orders_alert" },
  "delivery": { "maxConcurrency": 1, "retry": { "max": 3, "backoffSeconds": [30, 120, 480] } },
  "enabled": true
}
```

### An agent digest after every completed run, as a pack

```json
{
  "v": 2, "kind": "bundle", "id": "acme.run-digest", "version": "1.0.0", "title": "Run digest",
  "publisher": { "name": "Acme Example Ltd", "keyId": "pub-0123456789ab" },
  "requires": { "platform": ">=1.0.0" },
  "parameters": [ { "id": "target_workspace", "type": "workspace", "label": "Workspace", "required": true } ],
  "items": [
    { "kind": "hook", "schemaVersion": 1, "id": "run_digest", "scope": "workspace", "workspace": "{{param.target_workspace}}",
      "spec": { "id": "run_digest", "title": "Digest", "event": { "name": "run.completed" }, "handler": { "type": "agent", "ref": "agent:digest" } } }
  ]
}
```

### Failed runs of one workflow, with its own retry schedule

```json
{
  "id": "invoice_run_failed",
  "event": { "name": "run.failed" },
  "filter": [
    { "path": "payload.flowId", "op": "in", "value": ["flow_invoices", "flow_invoices_eu"] },
    { "path": "payload.status", "op": "neq", "value": "TIMEOUT" }
  ],
  "handler": { "type": "workflow", "ref": "flow_open_ticket" },
  "delivery": { "retry": { "max": 3, "backoffSeconds": [60, 300, 900] } }
}
```

## Install and test

### Test the filter first

`POST /api/event-hooks/test` checks a hook against a sample event. It never starts the handler. It needs `hooks.manage_own`.

```http
POST /api/event-hooks/test
Content-Type: application/json

{ "workspaceId": "ws-finance",
  "hook": { "id": "rejected_approvals", "event": { "name": "approval.decided" },
            "filter": [ { "path": "payload.outcome", "op": "eq", "value": "rejected" } ],
            "handler": { "type": "workflow", "ref": "flow_notify_requester" } },
  "sampleEvent": { "id": "evt_1", "name": "approval.decided", "version": 1, "workspaceId": "ws-finance",
                   "occurredAt": "2026-11-20T10:00:00Z", "actor": { "sub": "u_admin", "role": "admin" },
                   "resource": { "type": "approval", "id": "apr_01" },
                   "payload": { "approvalId": "apr_01", "runId": "run_03", "outcome": "rejected", "decidedBy": "u_admin" },
                   "dataCategories": ["CONTACT"] } }
```

Answer: `{"matches": true, "clauses": [{"path": "payload.outcome", "op": "eq", "matched": true}], "errors": []}`. In the UI, the hook editor has a **Test filter** button.

### Create it

| Call | Permission | Notes |
|---|---|---|
| `GET /api/events/catalog` | signed in | events, schemas, samples |
| `POST /api/event-hooks` | `hooks.manage_own` | `{workspaceId, definition}`, returns 201 |
| `GET /api/event-hooks?workspaceId=&event=` | `hooks.view_own` | |
| `PUT /api/event-hooks/{id}` | `hooks.manage_own` | not for pack hooks |
| `POST /api/event-hooks/{id}/enable`, `/disable` | `hooks.manage_own` | enable checks the handler again |
| `DELETE /api/event-hooks/{id}` | `hooks.manage_own` | retire |
| `GET /api/event-hooks/{id}/deliveries?state=` | `hooks.view_own` | `pending`, `delivered`, `failed`, `dead_lettered` |
| `POST /api/event-hooks/{id}/deliveries/{deliveryId}/retry` | `hooks.manage_own` | failed or dead-lettered only |
| `POST /api/event-hooks/{id}/replay {from, to, dryRun?}` | `hooks.manage_own` | up to 30 days and 1000 events |
| `PUT /api/event-hooks/{id}/data-classification` | `workspaces.manage_settings_own` | `{workspaceId, dataClassification}` |

### As a pack

Sign, import and activate the pack (see [Packs](/developers/packs)). Activation creates or updates the hook. Retiring the pack retires it. A pack hook can only be changed with a new pack version, except for its data class.

If the handler workflow is not yet published with an Event trigger, the hook is saved disabled with a warning. Publish the workflow, then enable the hook.

## Common errors

| Code | Status | Message | Fix |
|---|---|---|---|
| `VALIDATION` | 400 | definition is required | Wrap the hook in `{"definition": ...}` |
| `HOOK_FILTER_INVALID` | 400 | /id: must match ^[a-z0-9][a-z0-9._-]{0,63}$ | Lower-case id |
| `HOOK_FILTER_INVALID` | 400 | /id: a hook with this id already exists | Choose another id, or use PUT |
| `HOOK_EVENT_UNKNOWN` | 400 | /event/name: unknown event '...' | Use a catalog name |
| `HOOK_FILTER_INVALID` | 400 | /filter: at most 8 clauses (OR = two hooks) | Split into two hooks |
| `HOOK_FILTER_INVALID` | 400 | /filter/0/path: path must start with payload., resource. or be actor.role | |
| `HOOK_FILTER_INVALID` | 400 | /filter/0/value: in needs an array value / value is required | |
| `HOOK_LIMIT_EXCEEDED` | 422 | At most 100 hooks per workspace. | Retire unused hooks |
| `HOOK_HANDLER_NOT_FOUND` | 422 | Workflow '...' does not exist. / Agent '...' does not exist. | Create it first |
| `HOOK_HANDLER_FORBIDDEN` | 422 | Workflow '...' belongs to another workspace. | Use a handler in the hook's workspace |
| `HOOK_HANDLER_INACTIVE` | 422 | the workflow is not published with an Event trigger | Publish it with the AANCER Event trigger, then enable |
| `HOOK_INVALID` | 400 | /dataClassification: sovereign, internal or permitted | Use one of the three values |
| warning `HANDLER_INACTIVE` |  | the workflow is not published with an Event trigger; deliveries will fail until it is. | Publish it with the AANCER Event trigger, then enable |
| `HOOK_MANAGED_BY_PACK` | 409 | This hook is managed by pack '...'; edit the pack. | Ship a new pack version |
| `DELIVERY_NOT_RETRYABLE` |  | A '...' delivery cannot be retried. | Only failed or dead-lettered deliveries |
| `HOOK_DISABLED` | 409 | A disabled hook cannot replay; enable it first. | |
| `HOOK_REPLAY_WINDOW_INVALID` | 400 | The replay window is limited to 30 days. | Choose `from` and `to` within 30 days |
| `HOOK_REPLAY_TOO_LARGE` | 400 | More than 1000 events match; narrow the window. | Narrow the window |
| delivery `lastError` |  | HANDLER_INACTIVE: Workflow '...' listens to '...', not '...'. | Make the trigger event and the hook event match |
| `PACK_SCHEMA_INVALID` | 422 | /items/.../spec: must NOT have additional properties | For example `dataClassification` in a pack spec. Remove it |

## Limits and editions

- 100 hooks per workspace, 8 filter clauses per hook, 20 concurrent deliveries per hook.
- Replay reaches events the installation still keeps, up to 30 days per replay.
- Hooks are controlled by permissions: `hooks.view_own`, `hooks.manage_own`. Firing a workflow also needs the workflow to be allowed to run.
- Check your edition on [aancer.ai/pricing](https://aancer.ai/pricing).



## Themes

The look of AANCER is a set of design tokens such as `--bg`, `--ac` and `--t0`, defined for seven theme blocks: `light` (default), `dark`, `midnight`, `high-contrast`, `trust-authority`, `legal` and `terminal`. A **theme pack** is a signed pack with one `theme` item. It overrides those tokens and sets the platform name, tagline, fonts, logos, login page and e-mail colours. It is corporate identity as data: no code, no redeploy, nothing loaded from the internet. Fonts and logos ship inside the pack.

A theme can apply to the whole installation (including the login page and invitation e-mails) or to one workspace (the app shell only). A `locale` item in the same pack can rename UI words to match your organisation's vocabulary.

Without a pack, an administrator can set simple branding by hand under **Platform Settings > Branding**.

## Quick start

A theme with tokens only, no files. Use schema version 2.

```json
{
  "v": 2, "kind": "bundle", "id": "acme.ci", "version": "1.0.0", "title": "Acme corporate identity",
  "publisher": { "name": "Acme Example Ltd", "keyId": "pub-0123456789ab" },
  "requires": { "platform": ">=1.0.0" },
  "items": [
    {
      "kind": "theme", "schemaVersion": 2, "id": "acme-ci", "scope": "install",
      "spec": {
        "id": "acme-ci",
        "platformName": "Acme Cloud",
        "tagline": "Sovereign AI for Acme",
        "defaultTheme": "light",
        "typography": { "ui": "system-ui, sans-serif" },
        "themes": {
          "light": { "--bg": "#FAFAF7", "--s1": "#FAFAF7", "--s2": "#FFFFFF", "--t0": "#1B2430", "--ac": "#0F6E74", "--aci": "#FFFFFF", "--pr": "#0B1F3A" },
          "dark":  { "--bg": "#0E1420", "--s1": "#0E1420", "--s2": "#151C2A", "--t0": "#E9EDF3", "--ac": "#5CC6C9", "--aci": "#0B1F22" }
        },
        "login": { "backgroundColor": "#0B1F3A", "tagline": "Welcome to Acme Cloud", "legalFooter": "Acme Example Ltd" },
        "email": { "headerBackground": "#0B1F3A", "buttonColor": "#0F6E74" }
      }
    }
  ]
}
```

Keep the item `id` and `spec.id` equal.

## File layout

```text
acme-ci/
  manifest.json            # one theme item, "spec": {"$ref": "content/theme.json"}
  content/
    theme.json             # the theme document
    fonts/<name>.woff2     # woff2 only, at most 2 MiB each
    logos/<name>.png       # png, svg, jpg or ico, at most 2 MiB each
```

File names under `fonts/` and `logos/` use lower-case `[a-z0-9._-]` only. `aancer-pack sign` lists every file in `assets` with its hash.

Next part: https://aancer.ai/dev/parts/reference/11-field-reference.md
