feat: add server endpoint#2648
Conversation
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (10)
✅ Files skipped from review due to trivial changes (2)
🚧 Files skipped from review as they are similar to previous changes (6)
📝 WalkthroughWalkthroughAdds size-limited JSON parsing and message validation to a2ui shared utilities, applies them across chat/action/stream routes with structured CORS error responses, tightens CORS behavior, updates frontend endpoint origin handling, and includes small TypeScript/config and env-access refactors. ChangesA2UI validation and endpoint configuration
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 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 |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
packages/genui/a2ui-playground/src/pages/AIChatPage.tsx (1)
71-71: ⚡ Quick winConsider sourcing the online origin from build-time configuration.
Hardcoding
https://genui-server.vercel.appcouples the playground to a specific Vercel deployment, making it awkward to point at staging/preview backends or to rebrand the production host. Since this project uses Vite, consider reading it fromimport.meta.env.VITE_A2UI_SERVER_ORIGINwith the current value as a fallback, similar to howLOCAL_A2UI_SERVER_PORTis already extracted as a constant.♻️ Suggested refactor
-const ONLINE_A2UI_SERVER_ORIGIN = 'https://genui-server.vercel.app'; +const ONLINE_A2UI_SERVER_ORIGIN = import.meta.env.VITE_A2UI_SERVER_ORIGIN + ?? 'https://genui-server.vercel.app';🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/genui/a2ui-playground/src/pages/AIChatPage.tsx` at line 71, Replace the hardcoded ONLINE_A2UI_SERVER_ORIGIN value with a build-time environment fallback: read import.meta.env.VITE_A2UI_SERVER_ORIGIN and fall back to 'https://genui-server.vercel.app' if undefined, mirroring how LOCAL_A2UI_SERVER_PORT is obtained; update the constant ONLINE_A2UI_SERVER_ORIGIN so runtime host selection can be driven by Vite env vars while preserving the current default.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/genui/a2ui-playground/src/pages/AIChatPage.tsx`:
- Around line 71-72: The ONLINE_A2UI_CHAT_URL constant currently points to
/a2ui/stream while getA2UIChatEndpoint routes to /a2ui/chat, causing mismatched
handlers; choose the intended endpoint and make both match — e.g., if /a2ui/chat
is correct, update ONLINE_A2UI_CHAT_URL to
`${ONLINE_A2UI_SERVER_ORIGIN}/a2ui/chat`, or if /a2ui/stream is intended, change
getA2UIChatEndpoint to return the /a2ui/stream path and rename
functions/constants (ONLINE_A2UI_CHAT_URL, getA2UIChatEndpoint) to reflect
“stream” if you keep that route so names and branches are consistent.
In `@packages/genui/server/app/a2ui/_shared.ts`:
- Around line 153-159: The check currently compares raw.length (characters)
against MAX_BODY_BYTES, which fails for multibyte UTF-8 characters; replace the
character-length check with a UTF-8 byte-length check (e.g., compute the UTF-8
byte size of raw and compare that to MAX_BODY_BYTES) so the conditional guarding
the request body (the block returning { ok: false, status: 413, error: ... })
correctly enforces the byte limit; ensure you use the computed byte length (not
raw.length) in the error message and comparison.
- Around line 19-27: The parsePositiveInt function currently floors fractional
values which lets inputs like "0.5" become 0 instead of falling back; change
parsePositiveInt to reject non-integer numerical inputs by checking
Number.isFinite(n) and Number.isInteger(n) (or === Math.trunc(n)) and returning
fallback if not integer or if n <= 0, so only positive integers are accepted
before Math.floor/returning the value.
---
Nitpick comments:
In `@packages/genui/a2ui-playground/src/pages/AIChatPage.tsx`:
- Line 71: Replace the hardcoded ONLINE_A2UI_SERVER_ORIGIN value with a
build-time environment fallback: read import.meta.env.VITE_A2UI_SERVER_ORIGIN
and fall back to 'https://genui-server.vercel.app' if undefined, mirroring how
LOCAL_A2UI_SERVER_PORT is obtained; update the constant
ONLINE_A2UI_SERVER_ORIGIN so runtime host selection can be driven by Vite env
vars while preserving the current default.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 7f413734-d3cc-4d51-b4b5-bd8284180ce1
📒 Files selected for processing (7)
packages/genui/a2ui-playground/src/pages/AIChatPage.tsxpackages/genui/server/app/a2ui/_shared.tspackages/genui/server/app/a2ui/action/route.tspackages/genui/server/app/a2ui/chat/route.tspackages/genui/server/app/a2ui/cors.tspackages/genui/server/app/a2ui/stream/route.tspackages/genui/server/tsconfig.json
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Merging this PR will improve performance by 9.59%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ⚡ | transform 1000 view elements |
47.2 ms | 43.1 ms | +9.59% |
Tip
Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.
Comparing Sherry-hue:feat/server-endpoint (bc9a270) with main (676d1b3)
Footnotes
-
26 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
React Example with Element Template#642 Bundle Size — 199.95KiB (0%).bc9a270(current) vs 4e6b228 main#639(baseline) Bundle metrics
Bundle size by type
|
| Current #642 |
Baseline #639 |
|
|---|---|---|
145.76KiB |
145.76KiB |
|
54.19KiB |
54.19KiB |
Bundle analysis report Branch Sherry-hue:feat/server-endpoint Project dashboard
Generated by RelativeCI Documentation Report issue
React MTF Example#1506 Bundle Size — 208.1KiB (0%).bc9a270(current) vs 4e6b228 main#1503(baseline) Bundle metrics
|
| Current #1506 |
Baseline #1503 |
|
|---|---|---|
0B |
0B |
|
0B |
0B |
|
0% |
0% |
|
0 |
0 |
|
3 |
3 |
|
192 |
192 |
|
77 |
77 |
|
44.4% |
44.4% |
|
2 |
2 |
|
0 |
0 |
Bundle size by type no changes
| Current #1506 |
Baseline #1503 |
|
|---|---|---|
111.23KiB |
111.23KiB |
|
96.86KiB |
96.86KiB |
Bundle analysis report Branch Sherry-hue:feat/server-endpoint Project dashboard
Generated by RelativeCI Documentation Report issue
React Example#8373 Bundle Size — 237.15KiB (0%).bc9a270(current) vs 4e6b228 main#8371(baseline) Bundle metrics
|
| Current #8373 |
Baseline #8371 |
|
|---|---|---|
0B |
0B |
|
0B |
0B |
|
0% |
0% |
|
0 |
0 |
|
4 |
4 |
|
197 |
197 |
|
80 |
80 |
|
44.89% |
44.89% |
|
2 |
2 |
|
0 |
0 |
Bundle size by type no changes
| Current #8373 |
Baseline #8371 |
|
|---|---|---|
145.76KiB |
145.76KiB |
|
91.39KiB |
91.39KiB |
Bundle analysis report Branch Sherry-hue:feat/server-endpoint Project dashboard
Generated by RelativeCI Documentation Report issue
Web Explorer#9947 Bundle Size — 901.35KiB (0%).bc9a270(current) vs 4e6b228 main#9944(baseline) Bundle metrics
|
| Current #9947 |
Baseline #9944 |
|
|---|---|---|
45.06KiB |
45.06KiB |
|
2.22KiB |
2.22KiB |
|
0% |
0% |
|
9 |
9 |
|
11 |
11 |
|
229 |
229 |
|
11 |
11 |
|
27.22% |
27.22% |
|
10 |
10 |
|
0 |
0 |
Bundle size by type no changes
| Current #9947 |
Baseline #9944 |
|
|---|---|---|
497.08KiB |
497.08KiB |
|
402.06KiB |
402.06KiB |
|
2.22KiB |
2.22KiB |
Bundle analysis report Branch Sherry-hue:feat/server-endpoint Project dashboard
Generated by RelativeCI Documentation Report issue
React External#1488 Bundle Size — 695.33KiB (0%).bc9a270(current) vs 4e6b228 main#1485(baseline) Bundle metrics
|
| Current #1488 |
Baseline #1485 |
|
|---|---|---|
0B |
0B |
|
0B |
0B |
|
0% |
0% |
|
0 |
0 |
|
3 |
3 |
|
17 |
17 |
|
5 |
5 |
|
8.59% |
8.59% |
|
0 |
0 |
|
0 |
0 |
Bundle analysis report Branch Sherry-hue:feat/server-endpoint Project dashboard
Generated by RelativeCI Documentation Report issue
`Vitest (Windows)` failed on
`packages/rspeedy/plugin-react/test/background-only.test.ts:153`:
AssertionError: expected error.message === 'Rspack build failed.'
Expected: "Rspack build failed."
Received: "ENOENT: no such file or directory,
open 'C:\\…\\test\\dist\\.rspeedy\\rspeedy.config.js'"
The test expects rsbuild to report `Rspack build failed.` when the
configured entry is missing, but on Windows the failure surfaces
earlier as an ENOENT trying to open a generated config file under the
test's dist tree. This PR doesn't touch
`packages/rspeedy/plugin-react`; Vitest (Ubuntu) passed; the same
Vitest (Windows) check passes on other open PRs against the same
upstream (lynx-family#2645, lynx-family#2646, lynx-family#2648). Windows-only rspeedy infrastructure
flake — same family as the `validate is not a function` race we hit
earlier. Empty commit to retry.
7633abd to
186440d
Compare
186440d to
bc9a270
Compare
Summary by CodeRabbit
New Features
Improvements
Checklist