feat: Add dual language selector for AI Transport guides#3176
feat: Add dual language selector for AI Transport guides#3176GregHolmes wants to merge 6 commits intomainfrom
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the 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 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? Let me know if you have any questions. |
|
I've now moved the ably-ui code over to the new package in website repo: https://github.com/ably/website/pull/7827 |
|
I'm gonna see if the skill from #3192 can be helpful here |
5911152 to
de2bf59
Compare
| { | ||
| name: 'LangGraph token streaming - message per response', | ||
| link: '/docs/guides/ai-transport/lang-graph-message-per-response', | ||
| name: 'Anthropic', |
There was a problem hiding this comment.
Could we auto expand these to help with visibility? Like we do for spaces
src/components/Layout/mdx/If.tsx
Outdated
| } | ||
|
|
||
| // Check client language condition if client_lang prop is provided | ||
| if (client_lang !== undefined && clientLanguage) { |
There was a problem hiding this comment.
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
m-hulbert
left a comment
There was a problem hiding this comment.
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
langandlang2so 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
972f7f5 to
0c553a9
Compare
05f5832 to
e4b42ce
Compare
…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
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. |
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