API voor het aanmaken en beheren van AI-bots
- TypeScript 98.6%
- Dockerfile 1.4%
- POST /v1/bots accepteert nu content_hash per source; voor PDFs met signed URLs wordt deze gebruikt als checksum zodat een ongewijzigde PDF niet opnieuw wordt geïndexeerd ondanks een roterende signed URL - Pipeline ruimt na elke deployment sources op die niet meer in de payload zitten (chunks worden via CASCADE verwijderd) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> |
||
|---|---|---|
| node_modules | ||
| src | ||
| tests | ||
| .env | ||
| .env.example | ||
| .gitignore | ||
| docker-compose.yml | ||
| Dockerfile | ||
| drizzle.config.ts | ||
| openapi.yaml | ||
| package-lock.json | ||
| package.json | ||
| README.md | ||
| tsconfig.build.json | ||
| tsconfig.json | ||
| vitest.config.ts | ||
API.Bot — Bot Server API
Production-ready Bot Server API in TypeScript (Fastify + pgvector + BullMQ + OpenAI).
Stack
| Layer | Tech |
|---|---|
| HTTP | Fastify 4, ESM, TypeScript strict |
| Queue | BullMQ + Redis |
| Database | PostgreSQL 16 + pgvector (HNSW index) |
| ORM | Drizzle ORM |
| LLM | OpenAI (pluggable) |
| Logging | pino (structured JSON) |
| Docs | Scalar UI at /docs |
Quick start (local)
cp .env.example .env
# Fill in BOT_SERVER_KEY and OPENAI_API_KEY
docker compose up --build
Server: http://localhost:8000
Swagger UI: http://localhost:8000/docs
Health: http://localhost:8000/healthz
Ontwikkelen zonder Docker
npm install
# Start postgres + redis via docker compose voor dependencies:
docker compose up postgres redis -d
cp .env.example .env # pas DATABASE_URL + REDIS_URL aan naar localhost
npm run dev
Scripts
| Script | Actie |
|---|---|
npm run dev |
Development server (tsx watch) |
npm run build |
TypeScript → dist/ |
npm start |
Production start |
npm test |
Vitest unit tests |
npm run check |
typecheck + test |
Deploy op Dokploy
- GitHub / Forgejo repo (code.pocfactory.nl/tenderadmin/api.bot) koppelen als Compose Stack.
- In Dokploy → Services → New → Docker Compose → kies de repo.
- Voeg environment variables toe via de Dokploy UI (zie
.env.example). - Stel een custom domain in met auto-TLS (Traefik).
- Deploy — Dokploy bouwt de image en start
docker compose up.
Alternatief:
dokploy deploy --compose docker-compose.yml
Environment variabelen
| Var | Beschrijving | Verplicht |
|---|---|---|
PORT |
HTTP poort (default 8000) | Nee |
BOT_SERVER_KEY |
Secret voor Bearer-auth (min 32 tekens) | Ja |
DATABASE_URL |
PostgreSQL connection string | Ja |
REDIS_URL |
Redis URL | Ja |
OPENAI_API_KEY |
OpenAI API sleutel | Ja |
EMBEDDING_MODEL |
Embedding model (default: text-embedding-3-small) | Nee |
CHAT_MODEL |
Chat model (default: gpt-4o-mini) | Nee |
CHAT_RATE_LIMIT |
Max chat requests/minuut per bot (default: 60) | Nee |
LOG_LEVEL |
pino log level (default: info) | Nee |
Een andere LLM-provider pluggen
- Maak
src/services/llm/myprovider.tsmet functiescreateEmbeddingencreateEmbeddingsBatch. - Wissel de imports in
src/services/ingest/pipeline.tsensrc/services/rag/chat.tsnaar jouw provider. - Pas
src/services/rag/chat.ts→ragChat/ragChatStreamaan voor de nieuwe chat API.
De structuur is bewust simpel gehouden — er is geen abstractie-laag, zodat je direct de juiste calls kan plaatsen.
API overzicht
| Method | Path | Beschrijving |
|---|---|---|
POST |
/v1/bots |
Publiceer/update bot (async ingest) |
GET |
/v1/bots/:id |
Status + source stats |
GET |
/v1/bots/:id/deployments/:dep_id |
Deployment details + steps |
GET |
/v1/bots/:id/deployments/:dep_id/logs |
Logs (JSON of SSE) |
POST |
/v1/bots/:id/chat |
Chat (RAG, optioneel SSE stream) |
POST |
/v1/bots/:id/deactivate |
Deactiveer |
DELETE |
/v1/bots/:id |
Verwijder |
GET |
/healthz |
Liveness |
GET |
/readyz |
Readiness (db + redis + llm) |
Volledige spec: /docs of openapi.yaml.
E2E tests
# Start de stack eerst
docker compose up -d
E2E=true API_URL=http://localhost:8000 BOT_SERVER_KEY=your-key npm test