|
| 1 | +# Contributing to the OpenRouter AI SDK Provider |
| 2 | + |
| 3 | +Thank you for your interest in contributing to the OpenRouter provider for the Vercel AI SDK! This guide will help you get started as a contributor. |
| 4 | + |
| 5 | +## Getting Started |
| 6 | + |
| 7 | +### Prerequisites |
| 8 | + |
| 9 | +- Node.js v18 or higher |
| 10 | +- pnpm v9.15.0 or higher (the project uses pnpm as its package manager) |
| 11 | + |
| 12 | +### Setting Up the Repository |
| 13 | + |
| 14 | +1. Fork the repository on GitHub |
| 15 | +2. Clone your fork locally: |
| 16 | + |
| 17 | + ```bash |
| 18 | + git clone https://github.com/YOUR-USERNAME/ai-sdk-provider.git |
| 19 | + cd ai-sdk-provider |
| 20 | + ``` |
| 21 | + |
| 22 | +3. Install dependencies: |
| 23 | + |
| 24 | + ```bash |
| 25 | + pnpm install |
| 26 | + ``` |
| 27 | + |
| 28 | +4. Build the project: |
| 29 | + |
| 30 | + ```bash |
| 31 | + pnpm build |
| 32 | + ``` |
| 33 | + |
| 34 | +## Development Workflow |
| 35 | + |
| 36 | +### Building |
| 37 | + |
| 38 | +To build the package during development: |
| 39 | + |
| 40 | +```bash |
| 41 | +# Build once |
| 42 | +pnpm build |
| 43 | + |
| 44 | +# Build in watch mode for continuous development |
| 45 | +pnpm dev |
| 46 | +``` |
| 47 | + |
| 48 | +### Code Style and Formatting |
| 49 | + |
| 50 | +We use Prettier for code formatting. Before submitting a PR, make sure your code is properly formatted: |
| 51 | + |
| 52 | +```bash |
| 53 | +# Check formatting |
| 54 | +pnpm stylecheck |
| 55 | + |
| 56 | +# Fix formatting issues |
| 57 | +pnpm format |
| 58 | +``` |
| 59 | + |
| 60 | +### Type Checking |
| 61 | + |
| 62 | +Ensure your changes pass TypeScript type checking: |
| 63 | + |
| 64 | +```bash |
| 65 | +pnpm typecheck |
| 66 | +``` |
| 67 | + |
| 68 | +## Testing |
| 69 | + |
| 70 | +The project includes tests for both Node.js and Edge environments. Make sure to run the tests before submitting a PR: |
| 71 | + |
| 72 | +```bash |
| 73 | +# Run all tests |
| 74 | +pnpm test |
| 75 | + |
| 76 | +# Run only Node.js tests |
| 77 | +pnpm test:node |
| 78 | + |
| 79 | +# Run only Edge environment tests |
| 80 | +pnpm test:edge |
| 81 | +``` |
| 82 | + |
| 83 | +### Writing Tests |
| 84 | + |
| 85 | +When adding new features or fixing bugs, please include tests. Test files follow the naming convention of `*.test.ts` and are located in the same directory as the files they test. |
| 86 | + |
| 87 | +Examples of test files include: |
| 88 | + |
| 89 | +- `openrouter-chat-language-model.test.ts` |
| 90 | +- `openrouter-usage-accounting.test.ts` |
| 91 | +- `openrouter-stream-usage-accounting.test.ts` |
| 92 | + |
| 93 | +## Adding New Features |
| 94 | + |
| 95 | +When adding new features to the OpenRouter provider: |
| 96 | + |
| 97 | +1. Start by understanding the existing architecture in the `src` directory |
| 98 | +2. Update the relevant type definitions in `types.ts` if needed |
| 99 | +3. Implement the feature in the appropriate files |
| 100 | +4. Add tests to verify the functionality |
| 101 | +5. Update the README.md to document the new feature |
| 102 | +6. Update the CHANGELOG.md if applicable |
| 103 | + |
| 104 | +### Example: Usage Accounting Feature |
| 105 | + |
| 106 | +The usage accounting feature provides an example of how to add features to the provider: |
| 107 | + |
| 108 | +1. Added types in `types.ts` for usage accounting |
| 109 | +2. Enhanced response schemas to include usage data |
| 110 | +3. Updated the implementation in `openrouter-chat-language-model.ts` |
| 111 | +4. Added tests in `openrouter-usage-accounting.test.ts` and `openrouter-stream-usage-accounting.test.ts` |
| 112 | +5. Updated README.md with usage examples |
| 113 | + |
| 114 | +## Pull Request Process |
| 115 | + |
| 116 | +1. Create a new branch for your changes |
| 117 | +2. Make your changes, including tests and documentation updates |
| 118 | +3. Ensure all tests pass |
| 119 | +4. Run formatting checks and fix any issues |
| 120 | +5. Commit with clear, descriptive messages |
| 121 | +6. Push to your fork and submit a pull request |
| 122 | +7. Update the PR description with any relevant information |
| 123 | + |
| 124 | +### PR Title Convention |
| 125 | + |
| 126 | +Use a descriptive title that explains the change: |
| 127 | + |
| 128 | +- `fix: <description>` for bug fixes |
| 129 | +- `feat: <description>` for new features |
| 130 | +- `docs: <description>` for documentation changes |
| 131 | +- `test: <description>` for test changes |
| 132 | +- `chore: <description>` for maintenance tasks |
| 133 | + |
| 134 | +## Release Process |
| 135 | + |
| 136 | +The project maintainers will handle versioning and publishing. When your contribution is merged, it will be included in the next release. |
| 137 | + |
| 138 | +## Getting Help |
| 139 | + |
| 140 | +If you have questions about contributing, please open a GitHub issue in the repository. |
| 141 | + |
| 142 | +Thank you for contributing to the OpenRouter AI SDK Provider! |
0 commit comments