This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
npm run build # Compile TypeScript to JavaScript (dist/)
npm run clean # Remove dist directory
npm run prepare # Auto-build on installnpm run test # Run tests once with Vitest
npm run test:watch # Run tests in watch mode
npm run test:coverage # Run tests with coverage reportnpm run lint # Check for lint errors in TypeScript files
npm run lint:fix # Auto-fix lint issues@just-every/ensemble is an LLM provider abstraction layer that provides a unified streaming interface for multiple AI providers (OpenAI, Anthropic, Google, DeepSeek, xAI, OpenRouter).
-
Provider System (
/model_providers/)- All providers extend
BaseModelProviderabstract class - Each provider implements
request(),embed(), and optionallyimage()methods - Provider selection is automatic based on the model name
- All providers extend
-
Request Flow (
/core/ensemble_request.ts)- Handles unified streaming for all providers
- Manages tool calling with automatic parameter mapping
- Uses
MessageHistoryfor conversation management - Supports parallel and sequential tool execution
- Implements timeout handling with background tracking
-
Tool Execution System
- Running Tool Tracker (
/utils/running_tool_tracker.ts): Tracks active tool executions - Sequential Queue (
/utils/sequential_queue.ts): Ensures sequential execution when needed - Tool Execution Manager (
/utils/tool_execution_manager.ts): Handles timeouts and lifecycle - Tool Result Processor (
/utils/tool_result_processor.ts): Summarizes/truncates results
- Running Tool Tracker (
-
Type System (
/types/)types.ts: Core types for agents, models, streams, and toolsapi_types.ts: Provider-specific API typestool_types.ts: Tool calling and function definitions
-
Model Registry (
/data/model_data.ts)- Contains all supported models with pricing information
- Models are categorized by class (small, large, etc.)
- External models can be registered dynamically
- Streaming Events: All providers emit standardized events (
message_delta,tool_start,cost_update, etc.) - Tool Calling:
- Parallel execution by default, sequential mode available
- Automatic timeout with background tracking
- Abort signal support for graceful cancellation
- Result summarization for long outputs
- Message History: Automatic compaction and management of conversation history
- Cost Tracking: Built-in tracking of token usage and API costs
- State Management: Support for stateful requests with
StateManager
- ES modules with NodeNext module resolution
- Strict mode is disabled (
"strict": false) - Outputs to
./dist/with source maps and declarations - All imports must use
.jsextension (even for.tsfiles)
BEFORE EVERY COMMIT AND PUSH, YOU MUST:
-
Run and fix linting errors:
npm run lint:fix
-
Run all tests and ensure they pass:
npm run test -
Run the build and ensure it compiles successfully:
npm run build
-
If ANY of the above fail, fix the issues before committing
NO EXCEPTIONS: Never commit or push code that fails linting, tests, or build. This is mandatory and must be done for every single commit.
- Use async generators for streaming responses
- Implement proper error handling with custom error types
- Follow provider abstraction patterns
- Use TypeScript generics appropriately
- Keep provider implementations consistent
- Run
npm testfor all tests - Use Vitest for unit and integration tests
- Mock API calls in tests
- Test streaming behavior thoroughly
- Verify tool calling edge cases
- Branch names:
feature/provider-name,fix/issue-description - Conventional commits required
- Update API documentation for changes
- Add tests for new providers/features
- Clone repository
- Run
npm install - Copy
.env.exampleto.env - Add provider API keys
- Run
npm testto verify setup - Run
npm run demoto test providers with interactive demos
- Keep provider dependencies optional
- Use peer dependencies where appropriate
- Minimize core dependencies
- Document provider-specific requirements
- Provider Limits: Each provider has different rate limits
- Streaming Differences: Providers emit events differently
- Tool Calling: Not all providers support all tool features
- Cost Tracking: Ensure accurate token counting per provider
- Type Safety: Strict mode is OFF - be extra careful
ensembleRequest(): Main streaming functionBaseModelProvider: Provider abstraction classMessageHistory: Conversation managementToolExecutionManager: Tool timeout handlingCostTracker: Usage and cost monitoringModelRegistry: Available models database
- Provider errors: Check API keys and quotas
- Streaming issues: Verify event handler setup
- Tool timeouts: Adjust timeout settings
- Memory leaks: Check stream cleanup
- Type errors: Remember strict mode is disabled
Enable detailed logging:
DEBUG=ensemble:* npm testTest specific provider:
npm test -- --grep "provider-name"