|
| 1 | +# AGENTS.md |
| 2 | + |
| 3 | +Guidance for AI agents and developers working on `promptfoo/example-app`. |
| 4 | + |
| 5 | +## Repository Purpose |
| 6 | + |
| 7 | +This is a TypeScript/Express example API gateway for AI chat. It exposes public and authenticated chat endpoints, maps fish-named path levels (`minnow`, `shark`) to internal prompt-safety levels, issues RS256 JWTs through OAuth-style token endpoints, and forwards chat completions to LiteLLM. |
| 8 | + |
| 9 | +This repo is intentionally useful as a security-scanning example, so preserve clear auth, prompt, and model-routing boundaries when making changes. |
| 10 | + |
| 11 | +## Common Commands |
| 12 | + |
| 13 | +```bash |
| 14 | +# Install dependencies |
| 15 | +npm install |
| 16 | + |
| 17 | +# Compile TypeScript to dist/ |
| 18 | +npm run build |
| 19 | + |
| 20 | +# Start the compiled server |
| 21 | +npm start |
| 22 | + |
| 23 | +# Run the development server with ts-node |
| 24 | +npm run dev |
| 25 | + |
| 26 | +# Start LiteLLM from the local compose file |
| 27 | +docker compose up -d |
| 28 | +``` |
| 29 | + |
| 30 | +There is no local test script in `package.json` today, so use `npm run build` as the minimum validation command for code changes. |
| 31 | + |
| 32 | +## Code Layout |
| 33 | + |
| 34 | +- `src/server.ts`: Express app startup, middleware registration, route wiring, and in-memory RSA key generation. |
| 35 | +- `src/routes/chat.ts`: request validation, fish-level to prompt-level mapping, model allowlist enforcement, and LiteLLM request forwarding. |
| 36 | +- `src/routes/oauth.ts`: OAuth token and JWKS handlers for client credentials and password grants. |
| 37 | +- `src/middleware/auth.ts`: JWT Bearer-token verification middleware. |
| 38 | +- `src/domains/`: per-domain prompt text and prompt loaders for `general`, `finance`, `medicine`, `taxes`, and `vacation-rental`. |
| 39 | +- `src/utils/jwt-keys.ts`: in-memory RSA key generation plus public/private key accessors and JWKS export. |
| 40 | +- `src/utils/litellm-config.ts`: reads `litellm_config.yaml` and caches allowed model names. |
| 41 | +- `litellm_config.yaml` and `docker-compose.yml`: local LiteLLM runtime configuration. |
| 42 | + |
| 43 | +## Implementation Rules |
| 44 | + |
| 45 | +- Load environment variables before modules that depend on them; `src/server.ts` intentionally calls `dotenv.config()` first. |
| 46 | +- Preserve the `minnow`/`shark` API contract even though the implementation maps those names to `insecure`/`secure` prompt files internally. |
| 47 | +- Keep Zod validation and explicit JSON error responses when changing route handlers. |
| 48 | +- Do not commit real `.env` files, client secrets, user passwords, private keys, or API keys. |
| 49 | +- Be careful with domain prompt edits: `secure.txt` files encode the safety/compliance behavior this app is meant to demonstrate. |
| 50 | +- `src/utils/litellm-config.ts` currently fails open when the model config cannot be read; do not silently change that behavior without calling it out in the PR. |
| 51 | + |
| 52 | +## Validation |
| 53 | + |
| 54 | +- Run `npm run build` after TypeScript changes. |
| 55 | +- Run `npm run dev` with `docker compose up -d` when you need to manually verify chat/OAuth flows against LiteLLM. |
| 56 | +- CI currently runs the Promptfoo Code Scan workflow and requires the aggregate `CI Success` check. |
| 57 | + |
| 58 | +## Git Workflow |
| 59 | + |
| 60 | +- Do not push directly to `main`; create a branch and open a PR. |
| 61 | +- Use Conventional Commit subjects (`feat:`, `fix:`, `docs:`, `refactor:`, `build:`, `ci:`, `chore:`) to match current repo history. |
| 62 | +- Keep PR descriptions specific about API behavior, auth/prompt-safety impact, and manual validation performed. |
0 commit comments