Cloudflare stack
Bindings
Section titled “Bindings”| Binding | Product | Role |
|---|---|---|
AI |
Workers AI (+ AI Gateway) | Embeddings and chat completion |
VECTORIZE |
Vectorize | Semantic search over doc chunks |
DOCS |
KV | Full page Markdown + nav JSON |
SESSION |
KV | Astro sessions + rate-limit counters |
DocsAgent |
Durable Object | Chat agent with SQLite history |
ASSETS |
Static Assets | Prerendered Starlight HTML/CSS/JS |
DocsAgent
Section titled “DocsAgent”DocsAgent extends AIChatAgent from @cloudflare/ai-chat. On each turn it:
- Persists messages in SQLite on the Durable Object
- Applies a per-session rate limit (via
SESSION/DOCSKV) - Retrieves relevant chunks (lexical over KV locally; Vectorize when available)
- Generates a grounded answer with Workers AI (
generateText) - Attaches citation metadata for the chat UI
Abuse controls
Section titled “Abuse controls”POST /api/prompton/reindexrequiresx-prompton-reindex-secret(orAuthorization: Bearer …) and is rate-limited per client IP- Optionally set Worker var
PROMPTON_REINDEX_ALLOW_ACCESS=1and protect/api/prompton/reindexwith Cloudflare Access — Access-authenticated requests may reindex without the shared secret /agents/*connection attempts are rate-limited per client IP- Chat turns are rate-limited per session Durable Object name
Worker entry
Section titled “Worker entry”The custom Worker routes /agents/* to the Agents SDK first, then falls through to Astro:
import { handle } from "@astrojs/cloudflare/handler";import { routeAgentRequest } from "agents";import { DocsAgent } from "@prompton-dev/agent";
export { DocsAgent };
export default { async fetch(request, env, ctx) { const agentResponse = await routeAgentRequest(request, env); if (agentResponse) return agentResponse; return handle(request, env, ctx); },};Chat with the docs
Loading chat…