You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(prompts): add GET /v2/orgs/:spaceCatId/brands/:brandId/prompts/stats endpoint (#2528)
## Summary
Adds a new aggregate endpoint that returns prompt counts per brand for
the `project-elmo-ui` Prompts Management tab status bar.
- `GET /v2/orgs/:spaceCatId/brands/:brandId/prompts/stats`
- Returns `{ branded, unbranded, intents: { informational,
instructional, comparative, transactional, planning, delegation } }`
- Backed by the `rpc_brand_prompt_stats` PostgREST RPC in
`mysticat-data-service` - all classification logic stays in SQL, no
write-path changes or backfill required on the API side
## Design note
This replaces the originally-spec'd approach of storing a derived
`branded` column on `prompts` and reclassifying inside brand-mutation
transactions. The RPC computes counts at read time using the current
brand name + aliases, which removes the consistency model complexity
(transactional reclassify, 250K row-count gate, backfill script) at the
cost of slightly slower reads. Partial index on `(organization_id,
brand_id, status) WHERE status = 'active'` keeps the query fast.
Intent counts read 0 until the DRS to Postgres ingestion workstream
forwards `intent` on prompts upsert (separate, prerequisite workstream).
## Test plan
- [ ] Unit tests for `getPromptStats` (RPC happy path, error path,
missing intents hydration)
- [ ] Unit tests for `getPromptStatsByBrand` controller (auth, org not
found, brand not found, postgrest unavailable)
- [ ] Integration test in `test/it/postgres/`
- [ ] Manual smoke against staging: `curl
/v2/orgs/<orgId>/brands/<brandId>/prompts/stats` returns flat shape with
all 6 intent keys
Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
0 commit comments