# onboarding

> Guided console tour — step content, per-operator progress in state, and an injected page that spotlights the console element each step talks about.

| field | value |
|-------|-------|
| version | 0.1.21 |
| type | bundle |
| license | Apache-2.0 |
| repo | https://github.com/iii-hq/workers |
| author | iii |

## installation

```sh
iii call compose::add worker=onboarding@0.1.21
```

## dependencies

- `ade` @ `latest`
- `queue` @ `latest`
- `state` @ `latest`

## readme

# onboarding

The guided console tour. The page and its tab are called **learn-iii**; a
"tour" is one unit of content inside it, so a second tour can be added
without renaming anything.

Three parts:

| Part      | Lives in                                  | Owns                                                                          |
| --------- | ----------------------------------------- | ----------------------------------------------------------------------------- |
| Content   | `src/tours.mjs`                           | which tours exist, their steps, and the console element each step points at   |
| Progress  | the `state` worker, scope `learn-iii`     | how far each operator got, so a reload resumes mid-tour                       |
| Rendering | `ui/page.tsx` (injected into the console) | the tour card, the spotlight box, and the page an older console falls back to |

## Functions

- `learn-iii::tours::list` — every tour in curriculum order.
- `learn-iii::tours::get` — one tour with all of its steps.
- `learn-iii::progress::get` — the status of every step per tour, with the trigger evidence that closed it, plus the next tour to offer.
- `learn-iii::steps::complete` — mark one step complete. Pass `fired` when a trigger closed it; its type and payload are kept as evidence. The first time a step closes, it is also announced on the `onboarding:steps:complete` topic (see Events).
- `learn-iii::steps::reset` — forget one tour and start it again.
- `learn-iii::subscribe` — add an email address to the iii product-update list (the last step's signup box; the POST happens here, never in the browser).

Progress is written with `state::update` and its ordered atomic ops, never
`state::get` then `state::set`: two invocations can interleave around an
await, and a read-then-replace write would drop the earlier one. `merge`
walks and creates the path it names, so one step lands under its own tour.
A reset nulls its tour (the op set reaches top-level keys only for `remove`)
and the read drops nulls on the way out.

## Events

Each closed step is published to the `onboarding:steps:complete` topic through the
`queue` worker, so anything that follows a tour subscribes instead of reading
this worker's state. The payload:

```json
{
  "tour_id": "learn-iii",
  "tour_title": "Find your way around",
  "step_number": 3,
  "step_id": "coder",
  "step_title": "CODER"
}
```

The step number is the 1-based position in the tour, read from the ordered
step list. A step announces itself once per subject: a reload, or a second
report from the agent, writes the same progress again but publishes nothing.

Delivery is durable (`iii::durable::publish`, and subscribers bind the
`durable:subscriber` trigger type): the message waits in the queue and is
retried until a subscriber takes it, instead of being dropped when nothing is
listening at that instant. The publish itself is best effort — a project
without the `queue` worker logs the failure and still closes the step.

## api reference

```json
{
  "functions": [
    {
      "description": "Read an operator’s tour progress: per tour, the status of every step and the trigger evidence that closed it, plus which tour to offer next.",
      "metadata": {},
      "name": "learn-iii::progress::get",
      "request_schema": {
        "properties": {
          "subject": {
            "type": "string"
          }
        },
        "type": "object"
      },
      "response_schema": {
        "properties": {
          "next_tour_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "subscribed_at": {
            "type": [
              "number",
              "null"
            ]
          },
          "tours": {
            "properties": {},
            "type": "object"
          }
        },
        "required": [
          "tours",
          "next_tour_id"
        ],
        "type": "object"
      }
    },
    {
      "description": "Mark one tour step complete. Pass `fired` when a trigger closed it — its type and payload are kept as the evidence the tour shows back.",
      "metadata": {},
      "name": "learn-iii::steps::complete",
      "request_schema": {
        "properties": {
          "fired": {
            "properties": {
              "function_id": {
                "type": "string"
              },
              "payload": {},
              "trigger_type": {
                "type": "string"
              }
            },
            "type": "object"
          },
          "step_id": {
            "type": "string"
          },
          "subject": {
            "type": "string"
          },
          "tour_id": {
            "type": "string"
          }
        },
        "required": [
          "tour_id",
          "step_id"
        ],
        "type": "object"
      },
      "response_schema": {
        "properties": {
          "step": {
            "properties": {},
            "type": "object"
          }
        },
        "required": [
          "step"
        ],
        "type": "object"
      }
    },
    {
      "description": "Forget every step of one tour, so it starts from the beginning again.",
      "metadata": {},
      "name": "learn-iii::steps::reset",
      "request_schema": {
        "properties": {
          "subject": {
            "type": "string"
          },
          "tour_id": {
            "type": "string"
          }
        },
        "required": [
          "tour_id"
        ],
        "type": "object"
      },
      "response_schema": {
        "properties": {
          "reset": {
            "type": "boolean"
          }
        },
        "required": [
          "reset"
        ],
        "type": "object"
      }
    },
    {
      "description": "Add an email address to the iii product-update list, and record the signup time (not the address) on the subject’s progress as `subscribed_at`.",
      "metadata": {},
      "name": "learn-iii::subscribe",
      "request_schema": {
        "properties": {
          "email": {
            "type": "string"
          },
          "source": {
            "type": "string"
          },
          "subject": {
            "type": "string"
          }
        },
        "required": [
          "email"
        ],
        "type": "object"
      },
      "response_schema": {
        "properties": {
          "subscribed": {
            "type": "boolean"
          }
        },
        "required": [
          "subscribed"
        ],
        "type": "object"
      }
    },
    {
      "description": "Fetch one tour by id with every step: id, title, body, and the CSS anchor the console page spotlights for that step.",
      "metadata": {},
      "name": "learn-iii::tours::get",
      "request_schema": {
        "properties": {
          "id": {
            "type": "string"
          }
        },
        "required": [
          "id"
        ],
        "type": "object"
      },
      "response_schema": {
        "properties": {
          "tour": {
            "properties": {},
            "type": "object"
          }
        },
        "required": [
          "tour"
        ],
        "type": "object"
      }
    },
    {
      "description": "List every available tour in curriculum order with its id, title, description, and step count. Call this to find out what learn-iii content exists.",
      "metadata": {},
      "name": "learn-iii::tours::list",
      "request_schema": {
        "properties": {},
        "type": "object"
      },
      "response_schema": {
        "properties": {
          "tours": {
            "type": "array"
          }
        },
        "required": [
          "tours"
        ],
        "type": "object"
      }
    },
    {
      "description": "Serve the injectable learn-iii console page assets.",
      "metadata": {
        "internal": true
      },
      "name": "learn-iii::ui-content",
      "request_schema": {
        "properties": {
          "path": {
            "type": "string"
          }
        },
        "required": [
          "path"
        ],
        "type": "object"
      },
      "response_schema": {
        "properties": {
          "content": {
            "type": "string"
          },
          "content_type": {
            "type": "string"
          }
        },
        "required": [
          "content",
          "content_type"
        ],
        "type": "object"
      }
    }
  ]
}
```
