DevelopersAI integration

AI Integration

PWFabric provides first-class AI integration for intelligent surface creation, content generation, and adaptive experiences.

The AI Composer is built into PhiCo and available in every plan; programmatic access is available through the /api/ai/* REST endpoints.

AI capabilities

CapabilityStatusWhat it does
AI Composer (PhiCo)AvailableStreaming composer with four conversation modes (structure, styling, behavior, data).
Block CompositionAvailableGenerates correct block types and props from natural language. Understands every block type and its schema.
Surface Generation APIAvailableProgrammatic surface generation via /api/ai/composer/stream (SSE) — callable from your own application.
Adaptive RenderingComingSurfaces that adapt their presentation based on user behavior and preferences.

AI Composer (PhiCo)

The AI Composer is the streaming PhiCo system built into the PWFabric web app. A single backend pipeline (/api/ai/composer/stream) powers four conversation modes in the UI — each mode shapes prompts toward a specific surface concern but talks to the same composer.

Conversation modes

ModeFocus
ComposerStructure & block composition
🎨 StyleTheme tokens & visual design
CapabilitiesBehavior & interactions
📊 DataData sources & bindings

Custom modes can be added via /api/ai/agents.

Key features

  • Streaming responses (SSE)
  • Per-mode conversation threads
  • Surface mutation undo/redo
  • Metrics tracking per mode
  • Custom mode support

API endpoints

POST /api/ai/composer/stream   # SSE streaming
GET  /api/ai/metrics            # Per-agent usage metrics
GET  /api/ai/agents             # List custom agents
POST /api/ai/agents             # Create custom agent

Programmatic surface generation

Generate surfaces from your own application by calling the composer endpoint directly — it is the same pipeline the PhiCo uses.

// Stream a composer turn over SSE
const res = await fetch(`${baseUrl}/api/ai/composer/stream`, {
  method: 'POST',
  headers: {
    'content-type': 'application/json',
    authorization: `Bearer ${token}`,
  },
  body: JSON.stringify({
    intent: 'A landing page for a SaaS product with pricing',
    context: { worldId: 'wld_123' },
  }),
})

For short, non-streaming prompts use POST /api/ai/complete.

API reference

MethodEndpointPurpose
POST/api/ai/composer/streamStream a PhiCo conversation (SSE). The only composer endpoint — there is no non-streaming variant.
POST/api/ai/completeSynchronous completion for short prompts.
GET/api/ai/metricsPer-agent usage metrics for the current day
GET/api/ai/agentsList custom AI agents configured for the World
POST/api/ai/agentsCreate a new custom AI agent

Best practices

  • Be specific. Detailed prompts produce better results. Include target audience, style preferences, and required sections.
  • Iterate incrementally. Start with a basic generation, then refine with follow-up prompts. The AI retains context within a thread.
  • Review generated code. AI assists, it does not replace judgment. Always review before publishing.
  • Provide examples. Reference surfaces or screenshots help the AI match existing styles and patterns.