---
url: /another-agentic-system/decisions/0090-published-clients-of-the-chat-api-are-built-on-the-reference-client.md
---

# ADR 0090 — Published clients of the chat API are generated from the contract and built on the reference client

* **Status:** **proposed (2026-11-24)** (task ANR-275, the sixth gap of M11 in [ROADMAP.md](../../ROADMAP.md),
  epic [#407](https://github.com/vymalo/another-agentic-system/issues/407)). **Nothing is built, and nothing is
  published.** On the owner's decision of 2026-11-24, this plan **proposes** package names and registries, and the
  owner picks them at the first release. A release is the owner's to ask for, so no slice below publishes a package.
  The clients build on the reference client of [#336](https://github.com/vymalo/another-agentic-system/issues/336)
  (its slice 10), which is not built yet.

## Context

Read on 2026-11-24 at `eddee8f9`.

**What exists:**

* **The contract.** `docs/api/chat-api.yaml` (OpenAPI 3.1, `info.version: 0.1.0`) describes the resource API.
  `docs/api/agui.md` and the goldens in `docs/api/examples/agui/` describe the AG-UI stream. The stream is prose plus
  examples, not a schema.
* **The web's client.** The web generates its types from the contract at build time:

  * `pnpm gen:api` runs `openapi-typescript` 7.13.0 into `web/src/lib/api/schema.d.ts`, which is git-ignored and
    generated in CI (`.github/workflows/web.yml:39`);
  * it calls the API through `openapi-fetch` 0.17.0 (`web/src/lib/api/client.ts`);
  * `contract.typecheck.ts` holds drift guards: lines that must fail to compile, so a contract change that makes one
    compile fails the typecheck.

  The desktop app (`apps/tauri`) uses the same web client. The web's client is the app's, not a package: it owns
  sign-in, the DPoP proofs ([ADR 0054](0054-the-web-holds-its-own-tokens-dpop-bound-in-indexeddb.md)) and the
  session refresh.
* **The web's mock server** (`web/mock/server.ts`) answers the contract. Its answers are validated against
  `chat-api.yaml` by `web/mock/server.contract.test.ts` and `sessions.contract.test.ts`.
* **An AG-UI reference reader.** `tools/agui-conformance` reads every golden through `@ag-ui/client` 1.0.0, in CI
  (`.github/workflows/docs.yml`, job `agui-goldens`).
* **Other clients, not of the chat API.** Rust has clients of A2A (adam) and of the Platform API (plat), and there is
  no Swift client of anything (`ROADMAP.md`, M11, "Clients in TypeScript, React, Rust and Swift", **Partial**).

**What doesn't exist yet: the reference client.** #336's slice 10 plans "a small client with no UI that runs the
`forkThread`, tool-server and Choices recipes against the mock and the stack, in CI". Its folder, a new one under
`tools/`, isn't on `main`, and it depends on #336's slices 1 to 8 (the eight API gaps of
[ADR 0067](0067-the-plan-to-librechat-grade-and-the-client-agnostic-rule.md)). **This plan doesn't build that
client and doesn't duplicate it.** It turns the reference client into the first published client once it exists.

## Decision

1. **The reference client comes first, and the TypeScript package is its library.** #336 slice 10 builds the
   reference client as a library plus a recipe runner. The library half becomes the TypeScript package (slice C1). No
   published client starts before slice 10 merges, because a client written before the eight gaps close would copy
   what the web does privately, which ADR 0067 forbids.

2. **Four clients, one contract.**

   | Client | What it is | Built from |
   |---|---|---|
   | **TypeScript** | Framework-free: the resource API, plus the AG-UI stream as typed events | The REST types generated by `openapi-typescript` and `openapi-fetch` (as the web does), and the stream through `@ag-ui/client` (as `tools/agui-conformance` does) |
   | **React** | Thin hooks over the TypeScript package (`useThreads`, `useThread`, `useRun`), **no components**. Components stay the web's, so a host draws its own UI | The TypeScript package only |
   | **Rust** | A crate with async calls and a typed AG-UI event stream | REST types generated from `chat-api.yaml`. The AG-UI events are written by hand, as serde types, and tested against every golden |
   | **Swift** | A Swift package with `async` calls and an `AsyncSequence` of AG-UI events | REST types generated from `chat-api.yaml`. The event reader is written by hand over `URLSession`'s byte stream, and tested against every golden |

3. **Generated where the contract is a schema, hand-written where it is prose.** The REST types are generated from
   `chat-api.yaml` in every language and never edited by hand, so the contract stays the one source. The AG-UI events
   are written by hand, because `agui.md` is prose and its goldens are the only machine-readable form. Every client's
   test suite reads every golden.

   **The generator for Rust and Swift is to be chosen in its slice.** It must read OpenAPI 3.1, which not every
   generator does (*unverified* here for any candidate). If none fits, the slice writes the types by hand and adds a
   check that compares them with the contract's schema names and required members.

4. **No client owns sign-in.** Each takes a transport hook that adds the credentials to a request: a `fetch` for
   TypeScript (as the web's `authenticatedFetch`), a middleware for Rust, and a request hook for Swift. The host app
   keeps the tokens and makes the DPoP proofs, as the web does
   ([ADR 0047](0047-one-ui-for-web-desktop-and-mobile-each-signs-in-as-a-public-oauth-client.md), ADR 0054). So a
   client stores no token and opens no sign-in page. A `401` is handed back to the host.

5. **Drift fails CI, in each client.**
   * **The types:** each client generates its types in CI from the `chat-api.yaml` of the same commit, as the web
     does, and carries drift guards like `contract.typecheck.ts`.
   * **The behaviour:** each client runs the reference client's recipes against the web's mock server, which is
     itself held to the contract, and reads every AG-UI golden.
   * A change to `chat-api.yaml` or to a golden therefore turns every client's job red until the client follows it,
     in the same pull request.

6. **Versioning follows the contract.**
   * A client's version follows the contract's `info.version`, and the client states the contract version it was
     built from.
   * Adding a member is a new minor version of both. A breaking change is a new version of the contract (#336's
     constraint), and a new major version of each client.
   * A client reads `GET /api/config` and `GET /api/me` for what the deployment offers and never assumes a capability
     (ADR 0067's client-agnostic rule).

7. **Where they live.** In this repository, under `clients/typescript`, `clients/react`, `clients/rust` and
   `clients/swift`, next to the contract they follow, so one pull request changes the contract and every client. The
   Rust client is a workspace of its own, not a member of `orchestrator/`, so it never depends on the orchestrator's
   internal crates.

8. **What Swift needs that the others don't:**
   * **A macOS CI runner**, for `swift test` against the mock.
   * **No registry.** A Swift package is resolved from a git repository and a tag, so its publication is a tag of
     this repository, or of a mirror, which is again the owner's.
   * **The host's key store.** A DPoP key held in the system's key store (for example the Secure Enclave on Apple
     devices) is the host app's concern, through the transport hook of decision 4. The package only exposes the hook.
   * **A stream that resumes**, which matters most on a phone, whose connection drops more often than a browser's. Every
     client's reader follows [ADR 0082](0082-a-stream-ends-after-a-minute-and-a-message-keeps-its-id.md), as the web's
     reader does:

     * a stream ends after a minute;
     * the reader reconnects with `Last-Event-ID`;
     * it treats two missed heartbeats (one at least every 15 s) as a dead stream;
     * it backs off with jitter, at most 30 s.

     Whether `@ag-ui/client` does this for the TypeScript reader is *unverified* here, and is checked in slice C1.

## Open questions for the owner

1. **The package names and registries** (the owner picks at the first release). **Proposed:**

   * npm: `@vymalo/another-chat-client` and `@vymalo/another-chat-react`;
   * crates.io: `another-chat-client`;
   * Swift: the package `AnotherChatClient`, resolved from this repository's git tags.

   Until the owner picks, every package is `private` or unpublished (`"private": true`, `publish = false`), and no
   workflow holds a registry token.
2. **A Dart client** for a Flutter app (the owner's 2026-11-14 note that started #336): add it as a fifth client, or
   leave it to the Flutter app's own repository. **Recommendation:** leave it to the app, generated by the same rules
   (decisions 3 to 6), because Dart wasn't in M11's list.
3. **`clients/` in this repository, or one repository per client.** **Recommendation:** this repository (decision 7),
   so a contract change and its clients merge together.

## Slices

One pull request each, in this repository. None publishes a package.

| # | What | Depends on | Decisive test |
|---|---|---|---|
| S0 | **The reference client** (#336 slice 10): the library, and a runner of the `forkThread`, tool-server and Choices recipes | #336 slices 1 to 8 | #336's own. It isn't a slice of this plan |
| C1 | **TypeScript.** The reference client's library moved to `clients/typescript`, with generated types, the transport hook, drift guards and a CI job. `"private": true` | S0 | The three recipes pass against the web's mock server, and every golden reads cleanly. **Change a required member's name in a copy of `chat-api.yaml` and the job fails** at the drift guard |
| C2 | **React.** `clients/react`: the hooks over C1, and a test renderer. `"private": true` | C1 | A hook test against the mock server: `useRun` on the `echo` scenario yields the run's events in order and ends at `RUN_FINISHED`. **Drop the stream's close handling and the test times out** |
| C3 | **Rust.** `clients/rust`, its own workspace: generated types (or hand-written with a schema check), the AG-UI serde types, a middleware hook and a CI job. `publish = false` | S0 | The three recipes pass against the mock server, and every golden parses with no unknown event. **Remove one event variant and the golden test fails, naming the golden** |
| C4 | **Swift.** `clients/swift`, a Swift package: generated types, the event reader with resume, the request hook, and a macOS CI job | S0 | The three recipes pass against the mock server, and every golden parses. **Drop the reconnect from the reader, and the test that cuts the stream after a minute fails** |
| C5 | **Release dry run.** One workflow packs every client (`npm pack`, `cargo package`, a Swift build) and checks that each states the contract version. It **publishes nothing**, and holds no token | C1 to C4 | The workflow fails when a client's stated contract version differs from `chat-api.yaml`'s `info.version`. Publishing is a later card, only once the owner has picked the names and asked for a release |

## Consequences

* The contract gains four consumers in this repository. A change to `chat-api.yaml` or to an AG-UI golden updates
  them in the same pull request, or CI is red. That is the point, and it makes a contract change larger.
* CI gains four jobs, one of them on macOS.
* Nothing is public until the owner picks the names and asks for a release.
* The web keeps its own client. It may move onto the TypeScript package later, which this plan doesn't decide.

## Alternatives rejected

* **Hand-written REST types:** two sources of truth, which is what the contract exists to avoid.
* **Generating the AG-UI events from a new schema:** `agui.md` would need a schema first. That's a contract change of
  its own and isn't needed while the goldens are the test.
* **A client that signs in by itself:** it would hold tokens, which ADR 0054 keeps in the host. And on a phone, the
  key store is the host app's.
* **Starting before the reference client:** it would copy what the web does privately (ADR 0067).
