feat: Add dual language selector for AI Transport guides#3176
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughThis 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
Sequence DiagramsequenceDiagram
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
Estimated Code Review Effort🎯 4 (Complex) | ⏱️ ~50 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
a5fe2ec to
c5eb002
Compare
|
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 :) |
c5eb002 to
71caaea
Compare
|
This branch is heavily dependant on http://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? Let me know if you have any questions. |
|
I've now moved the ably-ui code over to the new package in website repo: http://github.com/ably/website/pull/7827 |
|
I'm gonna see if the skill from #3192 can be helpful here |
5911152 to
de2bf59
Compare
88f8c70 to
d85abb3
Compare
Thanks Mark, I think if we go with something generic like 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) Option B: Generic (lang1 / lang2) with frontmatter labels Option C: Hybrid (recommended) 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. |
9e4cb2a to
de6e819
Compare
src/pages/docs/guides/ai-transport/anthropic/anthropic-message-per-response.mdx
Show resolved
Hide resolved
src/pages/docs/guides/ai-transport/anthropic/anthropic-message-per-response.mdx
Outdated
Show resolved
Hide resolved
src/pages/docs/guides/ai-transport/anthropic/anthropic-message-per-response.mdx
Outdated
Show resolved
Hide resolved
src/pages/docs/guides/ai-transport/anthropic/anthropic-message-per-response.mdx
Outdated
Show resolved
Hide resolved
src/pages/docs/guides/ai-transport/anthropic/anthropic-message-per-response.mdx
Outdated
Show resolved
Hide resolved
src/pages/docs/guides/ai-transport/anthropic/anthropic-message-per-response.mdx
Outdated
Show resolved
Hide resolved
src/pages/docs/guides/ai-transport/anthropic/anthropic-message-per-token.mdx
Outdated
Show resolved
Hide resolved
m-hulbert
left a comment
There was a problem hiding this comment.
A couple of comments and also a note that the URL params are being cleared when you navigate between dual/single support and change the language.
| ), | ||
| }} | ||
| > | ||
| <p className="ui-text-overline2 text-left p-2 pb-3 text-neutral-700 dark:text-neutral-600">{label}</p> |
There was a problem hiding this comment.
Can we make the label style match the existing 'markdown' and 'open in' ones please?
src/pages/docs/guides/ai-transport/anthropic/anthropic-message-per-response.mdx
Outdated
Show resolved
Hide resolved
|
@m-hulbert I should have addressed and fixed all of your comments. |
src/pages/docs/guides/ai-transport/anthropic/anthropic-message-per-token.mdx
Outdated
Show resolved
Hide resolved
src/pages/docs/guides/ai-transport/anthropic/anthropic-message-per-token.mdx
Outdated
Show resolved
Hide resolved
src/pages/docs/guides/ai-transport/anthropic/anthropic-message-per-token.mdx
Outdated
Show resolved
Hide resolved
| <groupId>io.ably</groupId> | ||
| <artifactId>ably-java</artifactId> | ||
| <version>1.6.1</version> | ||
| </dependency> |
There was a problem hiding this comment.
I leave it to you, it's maybe too wordy to have gradle setup here as well, and also in message per token doc
There was a problem hiding this comment.
What would you suggest instead @ttypic ?
There was a problem hiding this comment.
Sorry it wasn't very clear. I meant we have in server section gradle as an option, but here and in the message per token we only have maven. Both option are popular and every java developer knows how to translate maven setup into gradle. But for LLMs maybe it's worth to have both. But it's a lot of boilerplate, I don't know the best solution for this
There was a problem hiding this comment.
Ok cool, I've added Gradle alternatives to all Java setup sections in both guides. Kept it brief by adding just the dependency line rather than full project setup.
m-hulbert
left a comment
There was a problem hiding this comment.
A few nitpicks to keep things tidy, and then 1 problem with the language display but it's looking good.
| <If clientLang="javascript"> | ||
| The client code requires Node.js 20 or higher. | ||
| </If> | ||
| <If clientLang="java"> | ||
| The client code requires Java 8 or higher. | ||
| </If> | ||
|
|
||
| <If agentLang="javascript"> | ||
| The agent code requires Node.js 20 or higher. | ||
| </If> | ||
| <If agentLang="python"> | ||
| The agent code requires Python 3.8 or higher. | ||
| </If> | ||
| <If agentLang="java"> | ||
| The agent code requires Java 8 or higher. | ||
| </If> |
There was a problem hiding this comment.
Small nitpick to keep these more concise - the prereqs are the same for the code, so do we really need to state "agent code" and "client code" and separate them out?
| <If lang="javascript"> | ||
| - [Ably JavaScript SDK getting started](/docs/getting-started/javascript) | ||
|
|
||
| Create a new NPM package, which will contain the publisher and subscriber code: | ||
| </If> | ||
| <If clientLang="swift"> | ||
| - [Ably Swift SDK getting started](/docs/getting-started/swift) | ||
| </If> | ||
| <If agentLang="python"> | ||
| - [Ably Python SDK getting started](/docs/getting-started/python) | ||
| </If> | ||
| <If lang="java"> | ||
| - [Ably Java SDK getting started](/docs/getting-started/java) |
There was a problem hiding this comment.
Small nitpick: do we want to be sending people to Pub/Sub getting started from AI Transport? Not sure that's the best UX
| <If agentLang="javascript"> | ||
| In your `ably-anthropic-agent` directory, create a new file `publisher.mjs` with the following contents: | ||
| </If> | ||
| <If agentLang="python"> | ||
| In your `ably-anthropic-agent` directory, create a new file `publisher.py` with the following contents: | ||
| </If> | ||
| <If agentLang="java"> | ||
| In your agent project, create a new file `Publisher.java` with the following contents: | ||
| </If> |
There was a problem hiding this comment.
Nitpick: can we make these more concise maybe with an inline If block on the file name? Just wary of making this readable.
| streamAnthropicResponse("Tell me a short joke"); | ||
| ``` | ||
|
|
||
| ```agent_python |
There was a problem hiding this comment.
These aren't correctly displaying in a block - Python just gets dropped unless you switch the language at the top of the page.
There was a problem hiding this comment.
All fixed!
- 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
…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
The lang param persists when navigating between pages (sticky language preference), but the dual-language params client_lang and agent_lang were lost on navigation. This was because neither the sidebar link builder nor the MDX content link handler propagated them. - MarkdownProvider Anchor: propagate client_lang/agent_lang alongside lang to all internal content links - LeftSidebar buildLinkWithParams: preserve all language params unconditionally instead of branching on target page type - Remove unused isDualLanguagePath import from LeftSidebar
Translated using the translate-examples-to-swift skill in the as-yet-unmerged PR #3192. I've reviewed them.
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
?fe_lang=xxx&be_lang=yyyfor bookmarking and sharing specific language combinationsfe_andbe_prefixes (e.g.,fe_javascript,be_python) to distinguish frontend vs backend codeSupported languages
Dependencies
@ably/ui@17.13.1-dev.c839343a(or later) withfe_/be_prefix support in CodeSnippetSummary by CodeRabbit
New Features
Documentation