f4c-bot-service v0.1.0
subsystem
capsule://quake0day/[email protected]
Manages per-room AI chat sessions, including message history persistence and hourly rate limiting, using Cloudflare Durable Objects and Cloudflare AI Gateway. It provides an API endpoint for external services to interact with the bot.
Owns
- AI chat bot logic and persona ('Luna')
- Message history storage and management within Durable Objects
- Hourly rate limiting for AI interactions
- API endpoint for proxying messages to the bot Durable Object
Does not own
- Frontend UI for chat messages
- General room management or participant authentication
- Real-time communication infrastructure
AI orientation
This capsule implements the AI bot's core logic and API. Agents should focus on improving bot responses, managing AI model integration, or refining rate limiting. Pay attention to the `BOT_SYSTEM_PROMPT` and `BOT_MODEL` for AI behavior.
Avoid
- Introducing direct UI components or client-side logic.
- Changing the core Durable Object state management without careful consideration of data migration.
Provides
http_api:/api/bot— API endpoint for sending user messages to the AI bot and receiving replies.event:DurableObject:BotSession— Cloudflare Durable Object for stateful AI bot sessions.
Requires
env:CF_AIG_TOKEN— Authentication token for Cloudflare AI Gateway.env:CF_AI_GATEWAY_BASEURL— Base URL for the Cloudflare AI Gateway (OpenAI-compatible endpoint).env:ROOMS_KV— Cloudflare KV Namespace for rate limiting and checking room existence/bot enablement.env:BOT_SESSION— Durable Object Namespace binding for BotSession.
Dependencies
Capsules
f4c-room-api>=0.1.0
Invariants (must always hold)
- The bot must maintain per-room message history up to `MAX_HISTORY`.
- The bot must adhere to `HOURLY_RATE_LIMIT` per room.
- The `/api/bot` endpoint must correctly route requests to the appropriate `BotSession` Durable Object.
Source files (2)
Click any file to view its content; the path on the right shows where the file lands when this capsule is installed.
src/app/src/do/BotSession.ts→do/BotSession.tssrc/app/src/pages/api/bot.ts→api/bot.ts
Plus capsule.yaml and
install.json.