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
| Capability | Status | What it does |
|---|---|---|
| AI Composer (PhiCo) | Available | Streaming composer with four conversation modes (structure, styling, behavior, data). |
| Block Composition | Available | Generates correct block types and props from natural language. Understands every block type and its schema. |
| Surface Generation API | Available | Programmatic surface generation via /api/ai/composer/stream (SSE) — callable from your own application. |
| Adaptive Rendering | Coming | Surfaces 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
| Mode | Focus |
|---|---|
| ✨ Composer | Structure & block composition |
| 🎨 Style | Theme tokens & visual design |
| ⚡ Capabilities | Behavior & interactions |
| 📊 Data | Data 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 agentProgrammatic 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
| Method | Endpoint | Purpose |
|---|---|---|
POST | /api/ai/composer/stream | Stream a PhiCo conversation (SSE). The only composer endpoint — there is no non-streaming variant. |
POST | /api/ai/complete | Synchronous completion for short prompts. |
GET | /api/ai/metrics | Per-agent usage metrics for the current day |
GET | /api/ai/agents | List custom AI agents configured for the World |
POST | /api/ai/agents | Create 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.