Skip to content

docs(ai-transport): add token streaming example, reframe append example#3448

Open
rainbowFi wants to merge 5 commits into
mainfrom
AIT-1030-ai-transport-token-streaming-example
Open

docs(ai-transport): add token streaming example, reframe append example#3448
rainbowFi wants to merge 5 commits into
mainfrom
AIT-1030-ai-transport-token-streaming-example

Conversation

@rainbowFi

@rainbowFi rainbowFi commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Refreshes the out-of-date AI Transport streaming examples (AIT-1030): adds a runnable token streaming example built on the AI Transport SDK, reframes the old append example under Pub/Sub, and fixes two example-gallery gaps found along the way.

How to review

The branch is five single-purpose commits, best read in order:

  1. fix(examples): product badge fix. Example product keys (ai_transport, liveobjects) did not match @ably/ui's ProductTile keys, so those gallery cards rendered without a badge. ExamplesGrid now maps them.
  2. feat(examples): redirects for renamed example pages. Gallery pages are generated at /examples/<id> from src/data/examples, and redirects were previously only sourced from MDX frontmatter, so renaming an example left a 404. Adds an optional redirectFrom field to Example, mirroring the MDX flow.
  3. docs(pub-sub): reframe ai-transport-message-per-response as pub-sub-message-append. The example always used raw Pub/Sub appendMessage + rewind rather than the SDK, so the READMEs, UI copy, and gallery entry now describe it accurately and point to AI Transport as the recommended approach for AI streaming. The code now models a generic text stream rather than an LLM response: MockLLM becomes MockTextStream, Agent becomes Publisher, and prompt-and-response naming becomes stream naming throughout. The channel stays in the ai: namespace because that namespace has mutable messages enabled, which appendMessage() requires; a code comment records that constraint. Also includes review fixes: a working appendMessage() doc link (/docs/messages#append; the API-reference anchor targets an H4 that gets no anchor generated), dead markup removed, API key placeholder aligned. The old URL redirects to the new one.
  4. docs(ai-transport): the token streaming example (React + JavaScript), on @ably/ai-transport 0.4. Mirrors the Core SDK getting started: the agent flow (createAgentSessioncreateRunstart → drain run.viewpipeend) and the client hooks (ClientSessionProvider, useView, useClientSession). The model is mocked so it runs without an API key, but the fake LLM emits the exact UIMessageChunk stream that streamText(...).toUIMessageStream() produces, so the agent code matches a production integration; the two necessary deviations (agent runs in-browser, token source mocked) are commented in the code. Both variants re-render on run lifecycle events (session.tree.on('run')) and gate streaming on status === 'active', because useView alone would leave the UI stuck in the streaming state when a run reaches a terminal status (related SDK gap: AIT-1128). A Refresh button demonstrates recovery from channel history. Includes Sandpack deps, the root workspace dependency (@ably/ai-transport ~0.4.0, ai ^6, ably ~2.23.0) with the regenerated yarn.lock, gallery entry and image, and docs cross-links.
  5. docs(ai-transport): remove ai-transport-message-per-token, superseded by the token streaming example. Pure deletion plus a redirect for its URL.

Verification

  • Every @ably/ai-transport 0.4 call and every mocked UIMessageChunk shape was checked against the package's type definitions; both variants mirror the Core SDK getting started guide.
  • All four changed example workspaces typecheck against the pinned 0.4.0 and build with vite; yarn install leaves the committed yarn.lock unchanged.
  • Examples component and data tests pass (12), ETL tests pass (302), eslint clean on changed files.

Known simplifications (intentional)

  • There is a brief window after send, before the run is observed, where the prompt button re-enables; guarding it needs extra state that adds noise to a teaching example, and the in-browser agent responds within milliseconds.
  • The React variant reloads history with a single useView({ limit: 30 }) page while the JavaScript variant drains history via hasOlder()/loadOlder(); the JavaScript variant deliberately demonstrates the paging API.
  • The append example keeps its pre-existing StrictMode quirk (a state update nested in an updater); its code is intentionally unchanged in this PR beyond the reframing copy.

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 77582273-ec14-4e27-ab7a-0e22f7873d0c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch AIT-1030-ai-transport-token-streaming-example

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@rainbowFi rainbowFi added the review-app Create a Heroku review app label Jun 26, 2026
@rainbowFi rainbowFi force-pushed the AIT-1030-ai-transport-token-streaming-example branch 2 times, most recently from fd3ecc2 to 00cbf76 Compare June 26, 2026 13:41
@ably-ci ably-ci temporarily deployed to ably-docs-ait-1030-ai-t-xxqlrp June 26, 2026 13:42 Inactive
@rainbowFi rainbowFi force-pushed the AIT-1030-ai-transport-token-streaming-example branch from 00cbf76 to d2f09c4 Compare July 8, 2026 15:35
@rainbowFi rainbowFi added review-app Create a Heroku review app and removed review-app Create a Heroku review app labels Jul 9, 2026
@ably-ci ably-ci temporarily deployed to ably-docs-ait-1030-ai-t-hibixo July 9, 2026 11:36 Inactive
@rainbowFi rainbowFi force-pushed the AIT-1030-ai-transport-token-streaming-example branch from d2f09c4 to f27495c Compare July 9, 2026 11:36
@ably-ci ably-ci temporarily deployed to ably-docs-ait-1030-ai-t-hibixo July 9, 2026 11:36 Inactive
@ably-ci ably-ci temporarily deployed to ably-docs-ait-1030-ai-t-hibixo July 9, 2026 12:10 Inactive
@ably-ci ably-ci temporarily deployed to ably-docs-ait-1030-ai-t-hibixo July 9, 2026 12:31 Inactive
@ably-ci ably-ci temporarily deployed to ably-docs-ait-1030-ai-t-hibixo July 9, 2026 13:41 Inactive
@ably-ci ably-ci temporarily deployed to ably-docs-ait-1030-ai-t-hibixo July 9, 2026 16:27 Inactive
@ably-ci ably-ci temporarily deployed to ably-docs-ait-1030-ai-t-hibixo July 9, 2026 17:06 Inactive
@ably-ci ably-ci temporarily deployed to ably-docs-ait-1030-ai-t-hibixo July 9, 2026 20:37 Inactive
@rainbowFi rainbowFi force-pushed the AIT-1030-ai-transport-token-streaming-example branch from f4de9f1 to f078c15 Compare July 9, 2026 21:24
@ably-ci ably-ci temporarily deployed to ably-docs-ait-1030-ai-t-hibixo July 9, 2026 21:24 Inactive
@rainbowFi rainbowFi force-pushed the AIT-1030-ai-transport-token-streaming-example branch from f078c15 to ba5edcf Compare July 9, 2026 21:37
@ably-ci ably-ci temporarily deployed to ably-docs-ait-1030-ai-t-hibixo July 9, 2026 21:37 Inactive
@rainbowFi rainbowFi force-pushed the AIT-1030-ai-transport-token-streaming-example branch from ba5edcf to 13ebbad Compare July 9, 2026 21:38
@ably-ci ably-ci temporarily deployed to ably-docs-ait-1030-ai-t-hibixo July 9, 2026 21:38 Inactive
@rainbowFi rainbowFi force-pushed the AIT-1030-ai-transport-token-streaming-example branch from 13ebbad to d3e619b Compare July 9, 2026 21:52
@ably-ci ably-ci temporarily deployed to ably-docs-ait-1030-ai-t-hibixo July 9, 2026 21:52 Inactive
rainbowFi added 5 commits July 9, 2026 22:54
Example product keys (ai_transport, liveobjects) do not match @ably/ui's
ProductTile keys (aiTransport, liveObjects), so gallery cards for those
products rendered without a product badge. Map the keys in ExamplesGrid.
Example gallery pages are generated from src/data/examples at
/examples/<id>, and redirects were previously only sourced from MDX
redirect_from frontmatter, so renaming or removing an example left its
old URL as a 404. Add an optional redirectFrom field to Example and
write nginx and client-side redirects for it, mirroring the MDX flow.
…e-append

The example always used raw Pub/Sub appendMessage and rewind rather than
the AI Transport SDK, so present it as a Pub/Sub message append example.
The READMEs, UI text, and gallery entry now describe Pub/Sub append, and
point to AI Transport as the recommended approach for streaming AI
responses. The old example URL redirects to the new one.

Rework the code to model a generic text stream rather than an LLM
response: MockLLM becomes MockTextStream, Agent becomes Publisher, and
prompt-and-response naming becomes stream naming throughout. The channel
stays in the ai namespace, which has mutable messages enabled, as
appendMessage() requires; a comment now records that constraint.

Also fix issues found in review: link appendMessage() to
/docs/messages#append (the previous API reference anchor targets an H4,
which gets no anchor generated), remove dead prompt-display and cursor
spans from the JavaScript variant, and align its fallback API key
placeholder with the other examples.
…port SDK

Add a runnable token streaming example (React and JavaScript) on
@ably/ai-transport 0.4, mirroring the Core SDK getting started guide:
the agent flow (createAgentSession, createRun, start, drain run.view,
pipe, end) and the client hooks (ClientSessionProvider, useView,
useClientSession).

The model is mocked so the example runs without an API key, but the
fake LLM emits the exact UIMessageChunk stream that
streamText(...).toUIMessageStream() produces, so the agent code matches
a production integration. The two necessary deviations (agent runs
in-browser, token source mocked) are commented in the code.

Both variants re-render on run lifecycle events (session.tree.on('run'))
and gate streaming on status === 'active', because useView alone only
re-renders on visible message-content changes and would leave the UI
stuck in the streaming state when a run reaches a terminal status
(related SDK gap: AIT-1128). A Refresh button demonstrates recovery:
the full response is served from channel history on rejoin.

Wire up the gallery entry, Sandpack dependencies, and docs cross-links,
and reuse the message-per-response gallery image for the new example.
Superseded by the ai-transport-token-streaming example, which shows the
same token-by-token streaming through the AI Transport SDK rather than
raw Pub/Sub. Remove the example, its gallery entry, its workspace
entries, and its gallery image, and redirect its URL to the new
example.
@rainbowFi rainbowFi force-pushed the AIT-1030-ai-transport-token-streaming-example branch from d3e619b to ce029a2 Compare July 9, 2026 21:54
@rainbowFi rainbowFi marked this pull request as ready for review July 9, 2026 21:56
@rainbowFi rainbowFi requested a review from VeskeR July 9, 2026 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review-app Create a Heroku review app

Development

Successfully merging this pull request may close these issues.

2 participants