AI Adventure Endpoint

Route

POST /wp-json/extrachill/v1/blog/ai-adventure

Purpose

Powers the ExtraChill Blog "AI Adventure" block by proxying structured story prompts to the AI provider defined in the extrachill-ai-client ecosystem.

Dependencies

  • EXTRACHILL_BLOG_PLUGIN_DIR must be defined so the route can include src/blocks/ai-adventure/includes/prompt-builder.php.
  • ExtraChill_Blog_Prompt_Builder supplies all prompt templates.
  • AI calls are delegated via apply_filters( 'chubes_ai_request', $payload, 'openai' ).

Request Body

All parameters are provided as JSON:

FieldTypeRequiredNotes
isIntroductionbooleanNoWhen true, triggers the introduction flow.
characterNamestringNoSanitized text.
adventureTitlestringNoSanitized text.
adventurePromptstringNoDetailed story setup.
pathPromptstringNoOptional branch direction.
stepPromptstringNoOptional step-specific instruction.
gameMasterPersonastringNoPersona description for the AI narrator.
storyProgressionarrayNoPrior narrative segments.
playerInputstringNoLatest user choice.
triggersarrayNoTrigger definitions with id + destination used for progression analysis.
conversationHistoryarrayNoRolling chat history.
transitionContextarrayNoAdditional context for scene transitions.

Processing Flow

  1. Validates prompt builder availability, returning a 500 error if missing.
  2. Sanitizes every field before use.
  3. When isIntroduction is true:
    • Builds introduction messages via ExtraChill_Blog_Prompt_Builder::build_introduction_messages().
    • Sends payload to the AI filter with model = gpt-5-nano.
    • Returns { "narrative": "..." }.
  4. Otherwise, it:
    • Builds conversation messages.
    • Calls the AI filter.
    • Optionally runs analyze_progression() if triggers exist, which issues a second AI request to decide nextStepId.

Response Structures

Introduction

json
{ "narrative": "Opening story prose" }

Step Progression

json
{
  "narrative": "Narrative text or empty when nextStepId is set",
  "nextStepId": "trigger destination id or null"
}

Failure Modes

CodeStatusDescription
extrachill_blog_missing500Blog plugin not available.
prompt_builder_missing / prompt_builder_unavailable500Prompt builder file/class missing.
chubes_ai_request_failed500Upstream AI provider returned an error.

Usage Guidelines

  • Builds introduction messages via ExtraChill_Blog_Prompt_Builder::build_introduction_messages().
  • Sends payload to the AI filter with model = gpt-5-nano.
  • Returns { "narrative": "..." }.