Thank you for considering contributing to TokenFirewall. This document provides guidelines for contributing to the project.
Be respectful and professional. We welcome contributions from everyone.
Open an issue at https://github.com/Ruthwik000/tokenfirewall/issues with:
- Clear description of the bug
- Steps to reproduce
- Expected vs actual behavior
- Environment details (Node version, OS)
Open an issue with:
- Clear description of the feature
- Use case and benefits
- Proposed implementation (optional)
- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature - Make your changes
- Run build:
npm run build - Commit with clear message:
git commit -m "Add feature: description" - Push to your fork:
git push origin feature/your-feature - Open a Pull Request
# Clone your fork
git clone https://github.com/YOUR_USERNAME/tokenfirewall.git
cd tokenfirewall
# Install dependencies
npm install
# Build TypeScript
npm run build
# Test your changes
node examples/1-basic-usage.jssrc/
├── core/ # Budget management, cost calculation, pricing
├── adapters/ # Provider-specific adapters (OpenAI, Anthropic, etc.)
├── interceptors/ # Fetch and SDK interception
├── introspection/ # Model discovery and context registry
├── router/ # Intelligent routing and failover
│ ├── detectors/ # Task detection methods (keyword, pattern, language, context)
│ ├── taskTypes.ts # Task type definitions
│ ├── taskRegistry.ts # Task configuration registry
│ └── taskClassifier.ts # Main classification engine
├── analytics/ # Task analytics and monitoring
├── index.ts # Main exports
├── logger.ts # Structured logging
└── registry.ts # Adapter registry
examples/ # Working examples
dist/ # Compiled JavaScript (generated)
We're currently implementing a Smart Model Selection feature that automatically routes requests to the optimal LLM model based on task type. This is a major feature being developed for v2.2.0.
Complete documentation: SMART-MODEL-SELECTION.md
This document contains:
- Feature overview and architecture
- 12 built-in task types (code generation, math reasoning, document analysis, etc.)
- Task detection methods (keyword, pattern, language, context)
- API reference and usage examples
- Cost savings analysis
- Implementation guidelines
There are 29 GitHub issues for this feature, labeled with gssoc'26 and feature: smart-routing. Issues are categorized by difficulty:
- Level 1 (Easy): Good for beginners - 11 issues
- Level 2 (Medium): Intermediate - 13 issues
- Level 3 (Hard): Advanced - 5 issues
Good First Issues: Look for issues labeled good first issue - these are perfect for new contributors!
- Phase 1: Foundation - Type definitions and registries
- Phase 2: Detection - Keyword, pattern, language, and context detectors
- Phase 3: Routing - Smart routing strategy integration
- Phase 4: Analytics - Task analytics and monitoring
- Phase 5: API - Public APIs for manual classification
- Phase 6: Testing - Comprehensive test coverage
- Phase 7: Documentation - README and examples
- Phase 8: Release - Performance optimization and release
View all Smart Model Selection issues: https://github.com/Ruthwik000/tokenfirewall/issues?q=is%3Aissue+label%3A%22feature%3A+smart-routing%22
- Read SMART-MODEL-SELECTION.md to understand the feature
- Pick an issue that matches your skill level
- Check issue dependencies (some issues depend on others)
- Comment on the issue to let others know you're working on it
- Follow the deliverables and acceptance criteria in the issue
- Use strict TypeScript with no implicit any
- Include type definitions for all exports
- Keep functions under 60 lines where possible
- Use 2 spaces for indentation
- Use semicolons
- Use double quotes for strings
- Add JSDoc comments for public APIs
- Do NOT modify core/ files unless necessary
- Do NOT introduce circular dependencies
- Keep router optional and opt-in
- Maintain backward compatibility
- Create adapter in
src/adapters/your-provider.ts:
import { ProviderAdapter, NormalizedUsage } from "../core/types";
export const yourProviderAdapter: ProviderAdapter = {
name: "your-provider",
detect(response: Response): boolean {
return response.url.includes("your-provider.com");
},
async normalize(response: Response): Promise<NormalizedUsage> {
const data = await response.json();
return {
provider: "your-provider",
model: data.model,
inputTokens: data.usage.prompt_tokens,
outputTokens: data.usage.completion_tokens,
totalTokens: data.usage.total_tokens
};
}
};- Register in
src/adapters/index.ts - Add pricing in
src/core/pricingRegistry.ts - Add context limits in
src/introspection/contextRegistry.ts - Create example in
examples/
Update src/core/pricingRegistry.ts:
// In constructor
this.register("provider", "model-name", {
input: 1.0, // per 1M tokens
output: 2.0
});# Build
npm run build
# Test basic functionality
node examples/1-basic-usage.js
# Test your specific feature
node examples/your-example.jstype: brief description
Detailed explanation (optional)
Examples:
- feat: add support for Cohere API
- fix: resolve race condition in budget tracking
- docs: update README with new examples
- refactor: simplify router error detection
- chore: update dependencies
- Keep PRs focused on a single feature or fix
- Include tests or examples demonstrating the change
- Update documentation (README, CHANGELOG)
- Ensure build passes:
npm run build - Reference related issues: "Fixes #123"
- New provider adapters (Cohere, Mistral, etc.)
- Bug fixes and edge cases
- Performance improvements
- Documentation improvements
- New routing strategies
- Enhanced error handling
- Additional examples
- TypeScript improvements
- Code refactoring (must maintain compatibility)
- Style changes
- Minor optimizations
Open an issue or discussion at https://github.com/Ruthwik000/tokenfirewall
By contributing, you agree that your contributions will be licensed under the MIT License.