AI Content Generation (Enhance With AI)
This page documents the generation flow that is currently shipped for Enhance With AI.
End-to-End Sequence

Request and Response Contracts
Generate request (GenerateInput)
| Field | Type | Notes |
|---|---|---|
topic |
string |
Comes from description input in Enhance With AI form |
contentType |
ContentTypeEnum |
Sent as route path segment and body value |
fields |
Record<keyof GeneratedContent, boolean> |
Selects generated output keys |
controls |
EnhanceControls |
Optional tone, mood, audience, optimization |
Generate response (GeneratedContent)
| Field | Type | Used by |
|---|---|---|
title |
string |
Review + apply to content form |
description |
string |
Review + apply to content form |
categories |
string[] |
Converted to { title }[] before apply |
tags |
string[] |
Converted to { title }[] before apply |
articleBody |
string |
Mapped to articleContent in review/apply |
Field Mapping Bridge
useContentEnhanceWithAi maps UI field names to domain keys before API call.
| Form field | API/domain field | Apply target key |
|---|---|---|
title |
title |
title |
description |
description |
description |
tags |
tags |
tags |
category |
categories |
categories |
articleContent |
articleBody |
articleContent |
Review/apply key definitions are centralized in src/config/content/content-tools/enhance-ai/reviewFields.ts.
Controls and Prompting
Creative controls passed from UI:
tonemoodaudienceoptimization
The domain prompt builder (prompt.ts) translates enums into explicit instruction strings and enforces a strict output contract:
- JSON only
- no extra keys
- requested fields only
Validation and Failure Behavior
Server-side generation path (domain/content/generate.ts + schema.ts):
- Reject empty field selection (
NO_FIELDS_REQUESTED). - Parse provider output as JSON (
INVALID_JSON_RESPONSEif parse fails). - Validate against Zod schema for requested subset.
- Throw
MISSING_REQUIRED_FIELD:<field>when requested key is absent.
Route behavior (route.ts):
- Returns
400forAIError. - Returns
500for unexpected errors. - Writes success/failure generation audit payloads to
console.debug.
Gating
Enhance With AI is currently gated by:
- Content type allowlist in content-tools registry (
vod,live,series,article). - Auth cookies required by AI route (
siteId,id,site). - Proxy matcher includes
/api/ai/content/:path*.
There is no feature-flag gate for this feature today.
Apply and Persist Path
Apply flow in useContentEnhanceWithAi:
- User selects output fields in Review (or applies all available fields).
- Hook writes selected values into content detail form with
shouldDirty. - Array fields are normalized through
ContentEnhanceWithAiHelpers.toTitleOnlyEntries. - Hook calls existing
save(contentType)from content details context. - Save persists through
ContentDetailsService.update(...)with existing content mutation registry.
This keeps AI stateless: AI generates suggestions, while persistence remains in the existing content save pipeline.
API Surface
| Intent | Endpoint | Status |
|---|---|---|
generate |
POST /api/ai/content/:contentType/generate |
Active |
enhance |
POST /api/ai/content/:contentType/enhance |
Returns 501 ENHANCE_NOT_IMPLEMENTED |