Skip to content

refactor(server): consolidate intent-extraction logic into a single module #241

Closed

Description

@gkhngyk

Summary

The intent-extraction logic is copy-pasted between the volumes route and the manual smoke script, and the two copies have already drifted apart — so the script no longer tests what production actually does.

Three definitions are duplicated:

  • intentKeywordSchema
  • INTENT_SYSTEM_PROMPT
  • AI_VOLUME_MULTIPLIER

in both server/src/routes/volumes.js and server/src/test-volumes.js.

The drift

routes/volumes.js (production) test-volumes.js (smoke)
Prompt "5 short HEAD keywords, 1–3 words (strict)", with worked examples and a "strip modifiers" rule "5 keyword phrases, 2–5 words each", no examples
Schema intent enum 9 values (includes other) 7 values
keyword field described as a Google head term with measurable volume undescribed

Production deliberately asks for short head terms (because Google Ads returns 0 volume for long-tail strings); the smoke script still asks for 2–5 word phrases. The script tests a prompt/schema that production no longer uses.

Duplication inside the route, too

The same generateObject({ model, schema: intentKeywordSchema, system: INTENT_SYSTEM_PROMPT, prompt: ... }) call appears twice in volumes.js — at volumes.js:201 and volumes.js:321 — with identical arguments.

Suggested fix

Extract a single source of truth, e.g. server/src/lib/intent-extraction.js, exporting:

  • intentKeywordSchema
  • INTENT_SYSTEM_PROMPT
  • AI_VOLUME_MULTIPLIER
  • a small helper, e.g. extractIntentKeywords(promptText, model), that wraps the shared generateObject call and returns { intent, keywords }.

Then:

Relationship to #240

This overlaps with #240 (move/remove the manual smoke scripts):

  • If test-volumes.js is deleted there, the cross-file duplication disappears and this issue narrows to the in-route dedup (lines 201/321) plus the lib extraction.
  • If it is moved and kept, this extraction is what lets it import the canonical definitions instead of a drifted copy.

Either way, the production-side extraction stands on its own and is worth doing.

Type

refactor — no behavior change to the volumes endpoint; production keeps its current (head-term) prompt and schema.

Activity

  1. added
    enhancement
    good first issue
    on Jun 12, 2026
  2. added a commit that references this issue on Jun 27, 2026
    7f8c0e7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementgood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions