refactor: improve type safety with openapi-fetch and simplify API with server functions#18
Conversation
Fixes the TanStack Start createServerFn return serialization type error by post-processing the openapi-typescript generated types. The generated 'unknown' types deep within nested events and dictionaries like 'state' are strictly rejected by the server payload bounds, but replacing them with '{}' satisfies the compiler natively without complex local mapped types or resorting to 'any'.
Co-authored-by: Antigravity <antigravity@google.com>
Updated MessageRole from 'agent' to 'model' to match the server-defined roles. Removed manual role mapping logic in applyEventToState. Co-authored-by: Antigravity <antigravity@google.com>
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly refactors the application's data fetching and API interaction layers. By adopting Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Warning Gemini encountered an error creating the review. You can try again by commenting |
- Add `runChat` server function with async generator streaming - Parse SSE on server side in `runChat` - Simplified `chatCache.ts` to use `runChat` instead of manual SSE parsing - Update `StartStreamOptions` and `useChat.ts` to use camelCase properties - Delete `/api/chat` route Co-authored-by: Antigravity <antigravity@google.com>
- Define `ChatInput` to hide `appName`, `userId`, and `streaming` from the client - `runChat` now prepends `ADK_APP_NAME` and `ADK_USER_ID` server-side - Update `chatCache.ts` to stop passing these internal details Co-authored-by: Antigravity <antigravity@google.com>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request is a significant and well-executed refactoring that improves type safety and simplifies the API layer. By replacing manual fetch calls with openapi-fetch and generated types, the frontend is now tightly coupled with the ADK's OpenAPI specification, reducing the chance of integration errors. The move to TanStack Server Functions is a major improvement, centralizing API logic, removing the need for a separate /api proxy layer, and simplifying client-side streaming logic.
My review includes a couple of suggestions to enhance portability and error handling for even greater robustness.
|
Google Jules, please help with the review comment I have tagged you. |
- Create handleAdkError and handleAdkResponseError in src/lib/server-utils.ts - In development, errors include detailed FastAPI messages - In production, full errors are logged to the server console while client receives a generic message - Remove duplicate constants and obsolete SSE logic from src/lib/adk.ts - Update sessions.functions.ts to use new error handlers Co-authored-by: Gemini CLI <gemini-cli@google.com>
- Renamed server-utils.ts to adk.server.ts following TanStack Start convention - Updated sessions.functions.ts imports - Added header comments to distinguish shared vs server-only ADK files Co-authored-by: Gemini CLI <gemini-cli@google.com>
This PR is stacked on top of
upgrade-adk. It focuses on improving type safety across the application and simplifying the API layer.Major Changes
1. Robust Type Safety with
openapi-fetchfetchcalls and hardcoded interfaces toopenapi-fetch.src/lib/adk.tswith types generated directly from the ADK OpenAPI spec.MessageRolefromagenttomodeland adjusted property casing (e.g.,grounding_metadatatogroundingMetadata) to match the latest ADK definitions.2. API Simplification with TanStack Server Functions
/apidirectory: Deleted the last remaining proxy route/api/chat. All backend communication is now handled via TanStack Server Functions.runChatserver function. SSE parsing logic is now handled on the server, allowing the client to consume typedAdkEventobjects via a simplefor awaitloop.appNameanduserIdwithin server functions. The client no longer needs to pass or maintain these internal identifiers, improving security and API cleanliness.3. OpenAPI Type Generation Improvements
unknownwith{}in generated types, resolving TypeScript issues whereunknownwas too restrictive for TanStack Start's expectations.Implementation Details
src/lib/chatCache.tsto use the newrunChatserver function and handle camelCase property names (appName,userId,sessionId,newMessage).src/hooks/useChat.tsand other components to align with the new server function signatures and camelCase naming conventions.src/routes/api/*files.Reviewer Notes
Please pay close attention to the
MessageRolerename and the removal of thesrc/routes/apidirectory. Ensure no client-side manual fetch calls remain (TypeScript should help verify this).