Fix SEO payload generation contract#10
Merged
ChrisAdamsdevelopment merged 1 commit intoMay 4, 2026
Merged
Conversation
Reviewer's GuideBackend SEO endpoint now accepts either a raw prompt or structured SEO fields and safely normalizes them into a prompt, improves Gemini JSON parsing, and the frontend calls it with richer structured payloads and robust per-item error handling without wiping existing SEO data. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The inline
onClickhandler for generating SEO inapp.tsxhas grown quite large and imperative; consider extracting it into a named function or helper to improve readability and make error-handling logic easier to reuse and reason about. - Using the generic
errorfield onactiveItemfor SEO-generation failures may overwrite or conflate other error states; consider introducing a dedicatedseoError(or similar) field so SEO issues don’t mask unrelated item errors.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The inline `onClick` handler for generating SEO in `app.tsx` has grown quite large and imperative; consider extracting it into a named function or helper to improve readability and make error-handling logic easier to reuse and reason about.
- Using the generic `error` field on `activeItem` for SEO-generation failures may overwrite or conflate other error states; consider introducing a dedicated `seoError` (or similar) field so SEO issues don’t mask unrelated item errors.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
POST /api/generate-seowith structured fields (title,artist,genre,platform, etc.) while the backend only accepted{ promptText }, which could produce400 Invalid promptand break the "Generate AI SEO Payload" flow.Description
asCleanTextandbuildSeoPrompthelpers and updated the backendPOST /api/generate-seoto accept either a directpromptTextor structured fields (title,artist,genre,platform,description,tags,lyrics,vibe) and to build a clearpromptTextserver-side when required.promptTextis present and valid it is used directly, otherwise structured fields are validated and composed into a prompt, and a400is returned only when neither is provided.title,description, andtags, and added safe parsing that returns a JSON error (502) when Gemini returns malformed JSON instead of allowing the server to crash.app.tsxto POST richer structured payloads, handle non-OK responses and network failures per item, surface a per-item error, and avoid clearing existing SEO fields on failure.Testing
npm installsuccessfully.npm run buildsuccessfully (vite/tsc completed and bundles were generated).NODE_ENV=development JWT_SECRET=dev_jwt_secret_change_me ENABLE_MOCK_CHECKOUT=true DB_PATH=./spectra.db FRONTEND_URL=http://localhost:5173 PORT=3001 npm startand verified the server started.curlthat unauthenticatedPOST /api/generate-seoreturns a JSON401 Unauthorized(not HTML), and inspected code paths to confirm structured payloads are now accepted and invalid payloads are handled safely.Codex Task
Summary by Sourcery
Align the SEO generation API contract between frontend and backend, improving robustness, error handling, and resilience to malformed Gemini responses.
New Features:
Bug Fixes: