|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with |
| 4 | +code in this repository. |
| 5 | + |
| 6 | +## Project Overview |
| 7 | + |
| 8 | +TypeScript SDK for the [Inference Gateway][ig] - a unified API for multiple |
| 9 | +LLM providers (OpenAI, Anthropic, Groq, Cohere, Ollama, Cloudflare, DeepSeek, |
| 10 | +Google, Mistral). |
| 11 | + |
| 12 | +[ig]: https://github.com/edenreich/inference-gateway |
| 13 | + |
| 14 | +## Commands |
| 15 | + |
| 16 | +```bash |
| 17 | +# Build |
| 18 | +npm run build |
| 19 | + |
| 20 | +# Test |
| 21 | +npm run test |
| 22 | + |
| 23 | +# Run a single test |
| 24 | +npx jest tests/client.test.ts -t "test name pattern" |
| 25 | + |
| 26 | +# Lint |
| 27 | +npm run lint |
| 28 | + |
| 29 | +# Format |
| 30 | +npm run format |
| 31 | + |
| 32 | +# Generate types from OpenAPI spec (downloads spec first) |
| 33 | +task oas-download && task generate-types |
| 34 | +``` |
| 35 | + |
| 36 | +## Architecture |
| 37 | + |
| 38 | +### Source Structure |
| 39 | + |
| 40 | +- `src/index.ts` - Package entry point, re-exports client and types |
| 41 | +- `src/client.ts` - Main `InferenceGatewayClient` class with all API methods |
| 42 | +- `src/types/generated/index.ts` - Auto-generated TypeScript types from OpenAPI |
| 43 | + spec (do not edit manually) |
| 44 | + |
| 45 | +### Client Architecture |
| 46 | + |
| 47 | +The SDK centers around `InferenceGatewayClient` which provides: |
| 48 | + |
| 49 | +- `listModels(provider?)` - List available models |
| 50 | +- `listTools()` - List MCP tools (when EXPOSE_MCP enabled) |
| 51 | +- `createChatCompletion(request, provider?)` - Non-streaming completions |
| 52 | +- `streamChatCompletion(request, callbacks, provider?, abortSignal?)` - |
| 53 | + Streaming completions with SSE |
| 54 | +- `proxy(provider, path, options)` - Direct provider proxy |
| 55 | +- `healthCheck()` - Gateway health check |
| 56 | +- `withOptions(options)` - Create new client with merged options |
| 57 | + |
| 58 | +### Streaming Implementation |
| 59 | + |
| 60 | +`StreamProcessor` class handles SSE parsing with callbacks for: |
| 61 | + |
| 62 | +- `onContent` - Text content chunks |
| 63 | +- `onReasoning` - Reasoning content (DeepSeek, Groq models) |
| 64 | +- `onTool` - Client-provided tool calls |
| 65 | +- `onMCPTool` - MCP tool calls (tools not in client's tool list) |
| 66 | +- `onUsageMetrics` - Token usage statistics |
| 67 | + |
| 68 | +### Type Generation |
| 69 | + |
| 70 | +Types in `src/types/generated/index.ts` are auto-generated from the OpenAPI |
| 71 | +spec using `openapi-typescript`. Regenerate with `task generate-types` after |
| 72 | +downloading the latest spec. |
| 73 | + |
| 74 | +### Path Aliases |
| 75 | + |
| 76 | +- `@/*` maps to `./src/*` |
| 77 | +- `@tests/*` maps to `./tests/*` |
| 78 | + |
| 79 | +## Testing |
| 80 | + |
| 81 | +Tests use Jest with ts-jest. Tests mock the fetch function to simulate API |
| 82 | +responses including streaming SSE events. Test file: `tests/client.test.ts`. |
| 83 | + |
| 84 | +## Commit Message Convention |
| 85 | + |
| 86 | +Use conventional commits: `feat:`, `fix:`, `refactor:`, `docs:`, `style:`, |
| 87 | +`test:`, `chore:`, `ci:`, `perf:` |
0 commit comments