Spaces:
Running
feat(api): expose category taxonomy to clients
Browse filesShips the closed category taxonomy alongside the apps payload so
clients (mobile shell, future website filter chips) no longer have
to mirror the slug list by hand, which silently drifted over time
(e.g. `games` missing from the mobile mirror, `dance` outliving
its rename to `motion`).
- `getPublicTaxonomy()` in `categories.js`: stable, minimal
projection (`{slug, label, emoji, order}`) - the LLM-only
`description` field stays internal.
- `/api/js-apps` embeds it under `categorization.taxonomy` so the
mobile catalog fetch stays a single round-trip.
- New `GET /api/categories` for clients that only want the slug
list (early UI scaffolding, tooling). 5-min cache aligned with
the catalog TTL.
Forward-compatible: old clients ignore the new fields; new clients
fall back to a local snapshot when the field is missing.
Co-authored-by: Cursor <cursoragent@cursor.com>
Files changed (2)
152 unmodified lines153154155156157158152 unmodified linesreturn ALLOWED_SLUGS.has(slug);}/*** Render the taxonomy as a bulleted list for the LLM prompt.* Format mirrors what the model is asked to output (slug first)152 unmodified lines153154155156157158159160161162163164165166167168169170171172173174175176177178179180181152 unmodified linesreturn ALLOWED_SLUGS.has(slug);}/*** Public projection of the taxonomy meant to be shipped to clients* (mobile shell, website filter chips). We strip the `description`* field on purpose: it is sized + worded for the LLM prompt and* carries no UI value (clients render `label` + `emoji`). Render* order is the index in `CATEGORIES`, surfaced as `order` so a* client that needs to re-sort (e.g. alphabetical view) keeps the* canonical order one field-away.** The shape is intentionally minimal and stable:* `{ slug, label, emoji, order }`. Adding optional fields later* (e.g. `color`, `shortLabel`) is forward-compatible; renaming or* dropping one is a breaking change for any client mirror.*/export function getPublicTaxonomy() {return CATEGORIES.map((c, index) => ({slug: c.slug,label: c.label,emoji: c.emoji,order: index,}));}/*** Render the taxonomy as a bulleted list for the LLM prompt.* Format mirrors what the model is asked to output (slug first)
4 unmodified lines5678910490 unmodified lines50150250350450550634 unmodified lines5415425435445455464 unmodified linesimport { categorizeApp, HfTokenMissingError } from './categorize.js';import { categoryCache } from './categoryCache.js';const __dirname = path.dirname(fileURLToPath(import.meta.url));490 unmodified linesclassified: withCategories,pending: jsApps.length - withCategories,inProgress: categorizationBatchRunning,...categoryCache.stats(),};}34 unmodified lines}});// Manual trigger for a categorization sweep, useful when// hand-tuning the taxonomy or testing the LLM prompt without// waiting for the next /api/js-apps hit.4 unmodified lines567891011490 unmodified lines50250350450550650750850951051151251334 unmodified lines5485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805814 unmodified linesimport { categorizeApp, HfTokenMissingError } from './categorize.js';import { categoryCache } from './categoryCache.js';import { getPublicTaxonomy } from './categories.js';const __dirname = path.dirname(fileURLToPath(import.meta.url));490 unmodified linesclassified: withCategories,pending: jsApps.length - withCategories,inProgress: categorizationBatchRunning,// Authoritative taxonomy shipped alongside the apps so the// mobile shell (and any future client) doesn't have to mirror// the slug list by hand. Pairs with `taxonomyVersion` from// `categoryCache.stats()` so clients can detect drift between// the catalog payload and a stale on-device cache.taxonomy: getPublicTaxonomy(),...categoryCache.stats(),};}34 unmodified lines}});// =====================================================================// Public taxonomy endpoint// =====================================================================//// Standalone read-only projection of the closed category taxonomy// (`server/categories.js`). Lets clients consume the slug list,// labels and emojis without paying the cost of a full apps fetch -// useful for early UI scaffolding (filter chips, empty states) and// for tooling that lints app metadata against the live taxonomy.//// `/api/js-apps` ALSO embeds the same payload under// `categorization.taxonomy`, so a mobile shell that fetches the// catalog never needs a second round-trip. This endpoint exists// for the "I just want the categories" use case.//// Cache headers: 5 minutes, same TTL as the catalog. The taxonomy// is stable across many catalog refreshes (it only moves when we// bump `TAXONOMY_VERSION`), but co-aligning the TTLs keeps the// reasoning simple - a client that polls both gets a coherent view.app.get('/api/categories', (_req, res) => {res.set('Cache-Control', 'public, max-age=300');const stats = categoryCache.stats();res.json({taxonomy: getPublicTaxonomy(),taxonomyVersion: stats.taxonomyVersion,});});// Manual trigger for a categorization sweep, useful when// hand-tuning the taxonomy or testing the LLM prompt without// waiting for the next /api/js-apps hit.