Skip to content

feat: Add dual language selector for AI Transport guides#3176

Open
GregHolmes wants to merge 6 commits intomainfrom
AIT-108-Framework-language-feature-combos-investigate-and-design-navigation
Open

feat: Add dual language selector for AI Transport guides#3176
GregHolmes wants to merge 6 commits intomainfrom
AIT-108-Framework-language-feature-combos-investigate-and-design-navigation

Conversation

@GregHolmes
Copy link
Contributor

@GregHolmes GregHolmes commented Feb 2, 2026

Summary

Adds dual language selection for AI Transport guide pages, allowing users to independently choose Client (frontend) and Agent (backend) languages for code examples.

Changes

  • Dual language selector UI: Two dropdowns ("Client" and "Agent") replace the single language selector on AI Transport guide pages
  • URL param support: ?fe_lang=xxx&be_lang=yyy for bookmarking and sharing specific language combinations
  • Navigation preservation: Language params persist when navigating between guide pages
  • Code block prefixes: MDX files use fe_ and be_ prefixes (e.g., fe_javascript, be_python) to distinguish frontend vs backend code
  • aiTransport languages: javascript, python, swift, java with SDK versions

Supported languages

  • Client: JavaScript, Swift, Java
  • Agent: JavaScript, Python, Java

Dependencies

  • Requires @ably/ui@17.13.1-dev.c839343a (or later) with fe_/be_ prefix support in CodeSnippet
  • Also removes stale CookieMessage CSS import that was breaking builds with newer ably-ui versions

Summary by CodeRabbit

  • New Features

    • Dual-language selection supporting client and agent language preferences
    • Expanded multi-language code examples for Anthropic integration guides
    • Updated language support versions for AI Transport
  • Documentation

    • Enhanced guides with per-language setup instructions and implementations for JavaScript, Python, Java, and Swift

@GregHolmes GregHolmes self-assigned this Feb 2, 2026
@GregHolmes GregHolmes added the review-app Create a Heroku review app label Feb 2, 2026
@coderabbitai
Copy link

coderabbitai bot commented Feb 2, 2026

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.

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

Walkthrough

This pull request implements dual-language support for Client and Agent code blocks across the documentation platform. Changes introduce language selection infrastructure, context providers, and conditional rendering logic, along with updated language data and comprehensive guide documentation with per-language implementations.

Changes

Cohort / File(s) Summary
Language Selection Infrastructure
src/components/Layout/LanguageSelector.tsx
Refactored to support dual-language mode with new DualLanguageSelector and DualLanguageDropdown components alongside existing SingleLanguageSelector. Adds logic to determine rendering mode based on activePage.isDualLanguage and updates URL query parameters for client_lang and agent_lang.
Context & Provider
src/contexts/layout-context.tsx
Added CLIENT_LANGUAGES and AGENT_LANGUAGES arrays, isDualLanguagePath detection function, and helpers for deriving clientLanguage, agentLanguage, and isDualLanguage. Extended LayoutContext to include these fields in activePage object.
Navigation Types & Utilities
src/components/Layout/utils/nav.ts
Extended ActivePage type with optional clientLanguage, agentLanguage, and isDualLanguage fields to support dual-language metadata.
Sidebar Navigation
src/components/Layout/LeftSidebar.tsx
Added buildLinkWithParams helper to construct links with appropriate language query parameters based on dual-language support. Updated link generation to preserve client_lang/agent_lang for dual-language targets.
MDX Code Block Handling
src/components/Layout/MDXWrapper.tsx
Enhanced code-block language detection to support client_ and agent_ prefixed languages and dual-language filtering. Extended SDKContextType to allow SDKType | undefined. Adds detection and conditional rendering for dual-language code blocks.
Conditional Content Rendering
src/components/Layout/mdx/If.tsx
Added three optional props (client_lang, agent_lang, client_or_agent_lang) to enable per-language content filtering. Extended activePage to expose clientLanguage and agentLanguage.
Language Selector Display
src/components/Layout/mdx/PageHeader.tsx
Updated showLanguageSelector logic to always display for dual-language pages via activePage.isDualLanguage.
Language & SDK Data
src/data/languages/languageData.ts
Updated JavaScript version in aiTransport from 2.11 to 2.16 and added Swift 1.2 entry.
Navigation Structure
src/data/nav/aitransport.ts
Restructured Guides section to group token-streaming entries by provider (OpenAI, Anthropic, LangGraph, Vercel AI SDK) with nested "Message per response" and "Message per token" items.
Guide Documentation
src/pages/docs/guides/ai-transport/anthropic-message-per-response.mdx, anthropic-message-per-token.mdx
Significantly expanded guides with multi-language conditional sections (JavaScript, Python, Java, Swift), separate agent and client code blocks, and step-by-step implementations with language-specific setup and event handling.
Dependencies
package.json
Updated @ably/ui from 17.13.2 to 17.13.2-dev.aa83caf92f.
Test Mocks
src/components/Layout/LeftSidebar.test.tsx
Added isDualLanguagePath to layout context mock.

Sequence Diagram

sequenceDiagram
    participant User
    participant LanguageSelector
    participant LayoutContext
    participant LeftSidebar
    participant MDXWrapper
    participant CodeBlock as If/CodeBlock
    
    User->>LanguageSelector: Select client language
    LanguageSelector->>LanguageSelector: Check activePage.isDualLanguage
    alt isDualLanguage true
        LanguageSelector->>LanguageSelector: Render DualLanguageSelector
        LanguageSelector->>LanguageSelector: Update client_lang/agent_lang params
    else isDualLanguage false
        LanguageSelector->>LanguageSelector: Render SingleLanguageSelector
        LanguageSelector->>LanguageSelector: Update lang param
    end
    
    LanguageSelector->>LayoutContext: Update URL query params
    LayoutContext->>LayoutContext: determineClientLanguage/determineAgentLanguage
    LayoutContext->>LayoutContext: Set clientLanguage & agentLanguage in activePage
    
    LeftSidebar->>LayoutContext: Read isDualLanguagePath
    LeftSidebar->>LeftSidebar: buildLinkWithParams preserves lang params
    
    MDXWrapper->>MDXWrapper: Detect client_/agent_ prefixed languages
    MDXWrapper->>MDXWrapper: Filter code blocks based on clientLanguage/agentLanguage
    MDXWrapper->>CodeBlock: Pass language selection context
    
    CodeBlock->>CodeBlock: Evaluate If conditions (client_lang, agent_lang, etc.)
    CodeBlock->>User: Render filtered content for selected language
Loading

Estimated Code Review Effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Poem

🐰 Dual tongues now dance in harmony,
Client whispers, Agent speaks free,
Language selectors bloom and split,
Context flows—dual-language knit!
Guides expand in every tongue, 🌍✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: introducing a dual language selector feature for AI Transport guides, which is the core objective of this PR.
Linked Issues check ✅ Passed The PR comprehensively addresses AIT-108 by implementing dual language selection (Client/Agent) for framework/language combinations in AI Transport guides with UI, routing, and content updates.
Out of Scope Changes check ✅ Passed All changes are within scope of AIT-108: dual language selector implementation, language-aware navigation, MDX updates for client/agent code blocks, and supporting infrastructure.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch AIT-108-Framework-language-feature-combos-investigate-and-design-navigation

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 and usage tips.

@ably-ci ably-ci temporarily deployed to ably-docs-ait-108-frame-bxs5nk February 2, 2026 16:56 Inactive
@ably-ci ably-ci temporarily deployed to ably-docs-ait-108-frame-gtap38 February 2, 2026 17:03 Inactive
@ably-ci ably-ci temporarily deployed to ably-docs-ait-108-frame-6jgsbd February 4, 2026 14:34 Inactive
@GregHolmes GregHolmes temporarily deployed to ably-docs-ait-108-frame-6jgsbd February 4, 2026 14:52 Inactive
@GregHolmes GregHolmes temporarily deployed to ably-docs-ait-108-frame-6jgsbd February 6, 2026 12:28 Inactive
@GregHolmes GregHolmes temporarily deployed to ably-docs-ait-108-frame-6jgsbd February 6, 2026 12:29 Inactive
@GregHolmes GregHolmes had a problem deploying to ably-docs-ait-108-frame-6jgsbd February 6, 2026 13:51 Failure
@GregHolmes GregHolmes had a problem deploying to ably-docs-ait-108-frame-6jgsbd February 6, 2026 13:55 Failure
@GregHolmes GregHolmes force-pushed the AIT-108-Framework-language-feature-combos-investigate-and-design-navigation branch from a5fe2ec to c5eb002 Compare February 6, 2026 13:55
@GregHolmes GregHolmes temporarily deployed to ably-docs-ait-108-frame-6jgsbd February 6, 2026 13:56 Inactive
@mschristensen
Copy link
Contributor

I haven't reviewed the code in detail, I will leave that to someone in the docs/deved team. But from a UX perspective, I really like the approach and I am happy with this :)

@GregHolmes GregHolmes force-pushed the AIT-108-Framework-language-feature-combos-investigate-and-design-navigation branch from c5eb002 to 71caaea Compare February 11, 2026 09:59
@GregHolmes GregHolmes temporarily deployed to ably-docs-ait-108-frame-6jgsbd February 11, 2026 09:59 Inactive
@GregHolmes GregHolmes had a problem deploying to ably-docs-ait-108-frame-6jgsbd February 11, 2026 17:01 Failure
@GregHolmes GregHolmes temporarily deployed to ably-docs-ait-108-frame-6jgsbd February 11, 2026 17:02 Inactive
@GregHolmes GregHolmes requested a deployment to ably-docs-ait-108-frame-6jgsbd February 12, 2026 09:58 Abandoned
@GregHolmes
Copy link
Contributor Author

This branch is heavily dependant on https://github.com/ably/ably-ui/pull/1060. Which I need the devex web team to review. I'm very sorry but you're not going to be able to view the deployment as it stands as I've made changes to the ably-ui.

Note: I've asked April to make me a early release candidate version for ably-ui that I can use in this branch. I'll update with a new comment when it happens.

I've added quite a few people to the reviews. I think I'd like to recommend what each person reviews!

@m-hulbert Could I please have you review this from the docs perspective?
@lawrence-forooghian and @ttypic Could you please review the JS/Swift/Java/Python code snippets that these two guides compile into? I think I've got them where they should be but would be happier with some experts in the languages checking them out.
@kennethkalmer and @matt423 Would it be possible for you to first review https://github.com/ably/ably-ui/pull/1060 as this branch won't work without those changes. Then hopefully could you review the code in this PR following that?

Let me know if you have any questions.

@GregHolmes
Copy link
Contributor Author

I've now moved the ably-ui code over to the new package in website repo: https://github.com/ably/website/pull/7827

@lawrence-forooghian
Copy link
Contributor

I'm gonna see if the skill from #3192 can be helpful here

@GregHolmes GregHolmes temporarily deployed to ably-docs-ait-108-frame-6jgsbd February 13, 2026 13:39 Inactive
@GregHolmes GregHolmes force-pushed the AIT-108-Framework-language-feature-combos-investigate-and-design-navigation branch from 5911152 to de2bf59 Compare February 13, 2026 14:11
@GregHolmes GregHolmes temporarily deployed to ably-docs-ait-108-frame-6jgsbd February 13, 2026 14:12 Inactive
{
name: 'LangGraph token streaming - message per response',
link: '/docs/guides/ai-transport/lang-graph-message-per-response',
name: 'Anthropic',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we auto expand these to help with visibility? Like we do for spaces

}

// Check client language condition if client_lang prop is provided
if (client_lang !== undefined && clientLanguage) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

client_lang and clientLanguage are essentially the same variable names(just shorthand difference). Would be good to rename to clearly separate what they do. Echo previous comment about using camelCase

Copy link
Contributor

@m-hulbert m-hulbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, Greg. I have a few comments for consideration though:

  • I'm not sure on the text within the page header that we're using for 'agent' and 'client' - might be worth a quick screenshot and DM to design.
  • I think we need to introduce a label on the codeblocks that denotes whether it's related to the agent or client.

These two are maybe conflicting depending on how we solve them, but worth your thoughts:

  • Should we go generic for the params with something like lang and lang2 so that we don't force ourselves into agent/client terminology and can reuse this for FE/BE in other places (thinking auth as the most likely culprit)?
  • Obviously if we do this, we need a way per page (in frontmatter), or per section (in data files) to label what these mean on the page. That also impacts the 2nd point I made about labelling on the blocks themselves.
  • Related to both of the above, in the example of auth we'd need to see how this interacts with the REST/realtime switcher too.

- Add Client/Agent dropdowns for separate frontend/backend language selection
- Support fe_/be_ prefixed code blocks in MDX files
- Preserve language params when navigating between guide pages
- Add aiTransport languages (javascript, python, swift, java)
- Add Guides section to AI Transport nav
- Update anthropic-message-per-response guide with dual language code blocks
- Update @ably/ui to 17.13.1-dev.c839343a

URL params: ?fe_lang=xxx&be_lang=yyy
The test mock for layout-context was missing the isDualLanguagePath
function that LeftSidebar imports, causing TypeError during test runs.
Extends the If component to support dual-language page conditionals:
- fe_lang: show content when frontend language matches
- be_lang: show content when backend language matches
- fe_or_be_lang: show content when either matches (with deduplication)

Used in AI Transport guides for language-specific prerequisites and SDK links.
- Add directory references to file creation instructions (e.g., "In your
  ably-anthropic-agent directory, create publisher.mjs")
- Add cd commands to run instructions for publisher and subscriber
- Add directory context to Step 6 rewind instructions
- Fix Swift Package.swift code block to use fe_swift prefix
- Wrap URL code block in Code component with text language
@GregHolmes GregHolmes force-pushed the AIT-108-Framework-language-feature-combos-investigate-and-design-navigation branch from 972f7f5 to 0c553a9 Compare February 26, 2026 09:30
@GregHolmes GregHolmes added review-app Create a Heroku review app and removed review-app Create a Heroku review app labels Feb 26, 2026
@ably-ci ably-ci temporarily deployed to ably-docs-ait-108-frame-ihn97z February 26, 2026 12:22 Inactive
@GregHolmes GregHolmes temporarily deployed to ably-docs-ait-108-frame-ihn97z February 26, 2026 14:05 Inactive
@GregHolmes GregHolmes temporarily deployed to ably-docs-ait-108-frame-ihn97z February 26, 2026 14:06 Inactive
@GregHolmes GregHolmes temporarily deployed to ably-docs-ait-108-frame-ihn97z February 26, 2026 14:07 Inactive
@GregHolmes GregHolmes temporarily deployed to ably-docs-ait-108-frame-ihn97z February 26, 2026 14:08 Inactive
@GregHolmes GregHolmes temporarily deployed to ably-docs-ait-108-frame-ihn97z February 26, 2026 14:09 Inactive
@GregHolmes GregHolmes temporarily deployed to ably-docs-ait-108-frame-ihn97z February 26, 2026 14:12 Inactive
@GregHolmes GregHolmes temporarily deployed to ably-docs-ait-108-frame-ihn97z February 26, 2026 14:14 Inactive
@GregHolmes GregHolmes temporarily deployed to ably-docs-ait-108-frame-ihn97z February 26, 2026 14:21 Inactive
@GregHolmes GregHolmes temporarily deployed to ably-docs-ait-108-frame-ihn97z February 26, 2026 14:23 Inactive
@GregHolmes GregHolmes force-pushed the AIT-108-Framework-language-feature-combos-investigate-and-design-navigation branch from 05f5832 to e4b42ce Compare February 26, 2026 14:30
@GregHolmes GregHolmes temporarily deployed to ably-docs-ait-108-frame-ihn97z February 26, 2026 14:30 Inactive
@GregHolmes GregHolmes temporarily deployed to ably-docs-ait-108-frame-ihn97z February 26, 2026 15:36 Inactive
@GregHolmes GregHolmes temporarily deployed to ably-docs-ait-108-frame-ihn97z February 26, 2026 15:43 Inactive
…age-per-token guide

- Add multi-language support (Python, Java, Swift) to message-per-token
  guide, matching the structure of message-per-response
- Fix Python code in both guides: use AsyncAnthropic with async/await,
  use Message objects for publish with extras and append_message,
  use transport_params for echo suppression
- Scope "without await" asides to JavaScript only
@GregHolmes GregHolmes temporarily deployed to ably-docs-ait-108-frame-ihn97z February 26, 2026 15:46 Inactive
@GregHolmes GregHolmes force-pushed the AIT-108-Framework-language-feature-combos-investigate-and-design-navigation branch from 88f8c70 to d85abb3 Compare February 26, 2026 15:46
@GregHolmes GregHolmes temporarily deployed to ably-docs-ait-108-frame-ihn97z February 26, 2026 15:46 Inactive
@GregHolmes
Copy link
Contributor Author

This is great, Greg. I have a few comments for consideration though:

  • I'm not sure on the text within the page header that we're using for 'agent' and 'client' - might be worth a quick screenshot and DM to design.
  • I think we need to introduce a label on the codeblocks that denotes whether it's related to the agent or client.

These two are maybe conflicting depending on how we solve them, but worth your thoughts:

  • Should we go generic for the params with something like lang and lang2 so that we don't force ourselves into agent/client terminology and can reuse this for FE/BE in other places (thinking auth as the most likely culprit)?
  • Obviously if we do this, we need a way per page (in frontmatter), or per section (in data files) to label what these mean on the page. That also impacts the 2nd point I made about labelling on the blocks themselves.
  • Related to both of the above, in the example of auth we'd need to see how this interacts with the REST/realtime switcher too.

Thanks Mark,

I think if we go with something generic like lang and lang2 we're going to have potential issues in two places:
1 - The developers producing guides will need to try to figure out what is what.
2 - The url params just look odd, so anyone wanting to go direct to a link may get confused.

I think from a backend (docs ) perspective, does it really matter if we have two, (possibly three with auth) options of functionality?

These are what I can see as possibilities

Option A: Keep specific (agent_lang / client_lang)
• URL: ?agent_lang=javascript&client_lang=swift
• Code blocks: agent_javascript, client_swift
• MDX:
• Pros: Clear semantics, simple, works now
• Cons: Not reusable for auth or other page types

Option B: Generic (lang1 / lang2) with frontmatter labels
• URL: ?lang1=javascript&lang2=swift
• Code blocks: lang1_javascript, lang2_swift
• MDX:
• Labels defined per-page in frontmatter (e.g. lang1.label: "Agent", lang2.label: "Client")
• Pros: Reusable across all page types (AI Transport, auth, etc.)
• Cons: More abstract, harder to read in MDX, every dual-language page needs frontmatter config

Option C: Hybrid (recommended)
• Ship agent_lang / client_lang now for AI Transport
• Add new specific pairs later when needed (e.g. frontend / backend for auth)
• Extract a shared abstraction once 2-3 concrete use cases exist
• Pros: Pragmatic, low risk, ships now
• Cons: Multiple conventions to maintain short-term

I think personally C is where I'm leaning towards but it won't be me maintaining it so I'd need people to decide what's best for them to maintain down the line.

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.

7 participants