feat: add a 'pseudoCode' flag for request viewers to default showing …#1234
feat: add a 'pseudoCode' flag for request viewers to default showing …#1234
Conversation
WalkthroughThe pull request introduces a new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
|
There was a problem hiding this comment.
Pull request overview
Adds a pseudoCodeMode option to request snippet viewers so they can default to showing pseudocode (RPC) and optionally toggle to SDK syntax.
Changes:
- Introduces
pseudoCodeMode?: booleanon several RequestViewer option types and uses it in the shared tabbed viewer. - Adds a pseudocode-first rendering path with a “View SDK syntax” toggle in
DefaultTabbedViewer. - Simplifies some pseudocode (RPC) outputs by removing authorization model ID parameters and adjusts one doc page to enable pseudocode mode.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/components/Docs/SnippetViewer/DefaultTabbedViewer.tsx | Adds pseudoCodeMode handling and a toggle UI to switch between pseudocode and non-RPC views. |
| src/components/Docs/SnippetViewer/CheckRequestViewer.tsx | Adds pseudoCodeMode opt and tweaks RPC pseudocode formatting/fields. |
| src/components/Docs/SnippetViewer/ListUsersRequestViewer.tsx | Adds pseudoCodeMode opt and simplifies RPC pseudocode. |
| src/components/Docs/SnippetViewer/ListObjectsRequestViewer.tsx | Adds pseudoCodeMode opt and simplifies RPC pseudocode. |
| src/components/Docs/SnippetViewer/BatchCheckRequestViewer.tsx | Adds pseudoCodeMode opt and removes SDK version requirement comments from snippets. |
| src/components/Docs/SnippetViewer/WriteRequestViewer.tsx | Simplifies RPC pseudocode for write/delete calls. |
| docs/content/modeling/agents/agents-as-principals.mdx | Enables pseudocode-first view for the embedded Check examples. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/components/Docs/SnippetViewer/CheckRequestViewer.tsx (1)
257-279:⚠️ Potential issue | 🟠 MajorPreserve custom headers in the RPC/pseudocode renderer.
This branch now drops
opts.headersentirely. BecausedefaultOperationsViewer()makes the RPC block the default view whenpseudoCodeModeis enabled, any example that depends on custom headers now renders an incomplete request unless the reader manually switches views.Suggested fix
return `check( user = "${user}", // check if the user \`${user}\` relation = "${relation}", // has an \`${relation}\` relation object = "${object}", // with the object \`${object}\`${ + headers && Object.keys(headers).length > 0 + ? ` + headers = { ${Object.entries(headers) + .map(([key, value]) => `${key} = "${value}"`) + .join(', ')} },` + : '' + }${ contextualTuples ? ` contextual_tuples = [ // Assuming the following is true🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/components/Docs/SnippetViewer/CheckRequestViewer.tsx` around lines 257 - 279, The pseudocode renderer in CheckRequestViewer.tsx currently omits opts.headers, causing examples relying on custom headers to render incomplete RPC blocks; update the string template that returns the check(...) snippet (the block that uses user, relation, object, contextualTuples, context, and Reply: ${allowed}) to include a headers section when opts.headers exists—format it similarly to the context block (map Object.entries(opts.headers) into key = "value" or "Key: Value" lines) so headers are rendered into the pseudocode by default when pseudoCodeMode/defaultOperationsViewer() selects this view.
🧹 Nitpick comments (1)
src/components/Docs/SnippetViewer/BatchCheckRequestViewer.tsx (1)
16-21: Consider inheriting the shared viewer options.
skipSetup/pseudoCodeModeare now duplicated across multiple*RequestViewerOptstypes. ExtendingDefaultTabbedViewerOptshere would keep the shared contract in one place and reduce drift the next time a common viewer option is added.Suggested refactor
-import { defaultOperationsViewer } from './DefaultTabbedViewer'; +import { defaultOperationsViewer, type DefaultTabbedViewerOpts } from './DefaultTabbedViewer'; @@ -interface BatchCheckRequestViewerOpts { +interface BatchCheckRequestViewerOpts extends DefaultTabbedViewerOpts { authorizationModelId?: string; checks: Check[]; - skipSetup?: boolean; - pseudoCodeMode?: boolean; allowedLanguages?: SupportedLanguage[]; }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/components/Docs/SnippetViewer/BatchCheckRequestViewer.tsx` around lines 16 - 21, The BatchCheckRequestViewerOpts type duplicates common viewer options (skipSetup, pseudoCodeMode) — change its declaration to extend the shared DefaultTabbedViewerOpts so these shared fields are inherited; update the interface name BatchCheckRequestViewerOpts to `extends DefaultTabbedViewerOpts` and remove the duplicated skipSetup and pseudoCodeMode properties, keeping unique fields like authorizationModelId, checks, and allowedLanguages as-is.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/components/Docs/SnippetViewer/DefaultTabbedViewer.tsx`:
- Around line 81-93: The current render guard uses pseudoCodeMode && hasRpc
which still shows the SdkToggle when RPC is the only allowed language; change
the condition so the toggle only renders if there is at least one SDK language
besides RPC (e.g., compute sdkLanguages = allowedLanguages.filter(l => l !==
SupportedLanguage.RPC) or check allowedLanguages.some(l => l !==
SupportedLanguage.RPC) and require sdkLanguages.length > 0) before returning the
SdkToggle; update the condition around pseudoCodeMode/hasRpc and ensure any
downstream code that expects sdkLanguages uses the new filtered list to avoid an
empty panel when switching to "View SDK syntax".
---
Outside diff comments:
In `@src/components/Docs/SnippetViewer/CheckRequestViewer.tsx`:
- Around line 257-279: The pseudocode renderer in CheckRequestViewer.tsx
currently omits opts.headers, causing examples relying on custom headers to
render incomplete RPC blocks; update the string template that returns the
check(...) snippet (the block that uses user, relation, object,
contextualTuples, context, and Reply: ${allowed}) to include a headers section
when opts.headers exists—format it similarly to the context block (map
Object.entries(opts.headers) into key = "value" or "Key: Value" lines) so
headers are rendered into the pseudocode by default when
pseudoCodeMode/defaultOperationsViewer() selects this view.
---
Nitpick comments:
In `@src/components/Docs/SnippetViewer/BatchCheckRequestViewer.tsx`:
- Around line 16-21: The BatchCheckRequestViewerOpts type duplicates common
viewer options (skipSetup, pseudoCodeMode) — change its declaration to extend
the shared DefaultTabbedViewerOpts so these shared fields are inherited; update
the interface name BatchCheckRequestViewerOpts to `extends
DefaultTabbedViewerOpts` and remove the duplicated skipSetup and pseudoCodeMode
properties, keeping unique fields like authorizationModelId, checks, and
allowedLanguages as-is.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f4309895-2253-4680-938d-0e21567d52d8
📒 Files selected for processing (7)
docs/content/modeling/agents/agents-as-principals.mdxsrc/components/Docs/SnippetViewer/BatchCheckRequestViewer.tsxsrc/components/Docs/SnippetViewer/CheckRequestViewer.tsxsrc/components/Docs/SnippetViewer/DefaultTabbedViewer.tsxsrc/components/Docs/SnippetViewer/ListObjectsRequestViewer.tsxsrc/components/Docs/SnippetViewer/ListUsersRequestViewer.tsxsrc/components/Docs/SnippetViewer/WriteRequestViewer.tsx
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| function SdkToggle<T extends DefaultTabbedViewerOpts>({ | ||
| allowedLanguages, | ||
| opts, | ||
| tabViewFn, | ||
| langMappings, | ||
| }: { | ||
| allowedLanguages: SupportedLanguage[]; | ||
| opts: T; | ||
| tabViewFn: (lang: SupportedLanguage, opts: T, langMappings: LanguageMappings) => string; | ||
| langMappings: LanguageMappings; | ||
| }): JSX.Element { | ||
| const [showSdk, setShowSdk] = useState(false); | ||
|
|
||
| const sdkLanguages = allowedLanguages.filter((language) => language !== SupportedLanguage.RPC); | ||
| const toggleLabel = showSdk ? 'View pseudocode' : 'View code'; | ||
|
|
There was a problem hiding this comment.
SdkToggle, sdkLanguages, and showSdk are named as if the toggle only switches SDK languages, but the implementation includes all non-RPC languages (e.g., CLI/curl) by filtering only SupportedLanguage.RPC. Consider renaming to reflect the actual behavior (e.g., CodeToggle, codeLanguages, showCode) or tighten the filter to SDK languages if that’s the intent.
…just pseudocode
Description
What problem is being solved?
When we want to explain a specific use case, showing the API syntax in every language adds noise, and makes the document more complex to read.
I'm adding a parameter to RequestViewer widgets that makes them show a pseudo code version by default and allow viewing the SDK syntax. By default it shows the SDK view,
I like to get the team's opinion and we probably need to adjust the design of the action link. I think we should change the default to show the pseudo code view in most places besides that pages that explain how to use the APIs.
How is it being solved?
What changes are made to solve it?
References
Review Checklist
mainSummary by CodeRabbit
New Features
Documentation
Style