Contributing to ZhipuAI Node.js SDK
July 15, 2025 ยท View on GitHub
We welcome contributions to the ZhipuAI Node.js SDK! This document provides guidelines for contributing to the project.
๐ Getting Started
Prerequisites
- Node.js 14 or higher
- npm, yarn, or pnpm
- Git
Development Setup
-
Fork the Repository
Fork the repository on GitHub and clone your fork locally:
git clone https://github.com/your-username/zhipuai-sdk-nodejs-v4.git cd zhipuai-sdk-nodejs-v4 -
Install Dependencies
npm install # or yarn install # or pnpm install -
Set Up Environment
Create a
.envfile in the root directory:ZHIPUAI_API_KEY=your_api_key_hereYou can obtain an API key from the ZhipuAI Open Platform.
๐ Development Workflow
1. Create a Feature Branch
git checkout -b feature/your-feature-name
2. Make Your Changes
- Write clean, readable code
- Follow the existing code style
- Add tests for new functionality
- Update documentation as needed
3. Test Your Changes
# Run tests
npm test
# Run linting
npm run lint
# Run type checking (if TypeScript)
npm run type-check
4. Commit Your Changes
Use clear and descriptive commit messages:
git add .
git commit -m "feat: add support for new model parameter"
We follow the Conventional Commits specification:
feat:- New featuresfix:- Bug fixesdocs:- Documentation changesstyle:- Code style changes (formatting, etc.)refactor:- Code refactoringtest:- Adding or updating testschore:- Maintenance tasks
5. Push and Create Pull Request
git push origin feature/your-feature-name
Then create a pull request on GitHub with:
- Clear title and description
- Reference to any related issues
- Screenshots or examples if applicable
๐งช Testing
Running Tests
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm run test:coverage
Writing Tests
- Write unit tests for all new functionality
- Use descriptive test names
- Mock external dependencies
- Test both success and error cases
Example test structure:
describe('ZhipuAI Client', () => {
describe('createCompletions', () => {
it('should create completions successfully', async () => {
// Test implementation
});
it('should handle errors gracefully', async () => {
// Error test implementation
});
});
});
๐ Documentation
Code Documentation
- Use JSDoc comments for functions and classes
- Include parameter types and descriptions
- Provide usage examples
/**
* Creates a chat completion
* @param {Object} params - The completion parameters
* @param {string} params.model - The model to use
* @param {Array} params.messages - The messages array
* @param {boolean} [params.stream=false] - Whether to stream the response
* @returns {Promise<Object>} The completion response
* @example
* const result = await ai.createCompletions({
* model: 'glm-4',
* messages: [{ role: 'user', content: 'Hello' }]
* });
*/
async createCompletions(params) {
// Implementation
}
README Updates
When adding new features:
- Update both
README.mdandREADME_CN.md - Add usage examples
- Update the API reference section
๐ Code Review Process
- Automated Checks: All PRs must pass automated tests and linting
- Peer Review: At least one maintainer must review and approve
- Testing: Verify that examples work as expected
- Documentation: Ensure documentation is updated
๐ Bug Reports
When reporting bugs, please include:
- Node.js version
- SDK version
- Minimal reproduction code
- Expected vs actual behavior
- Error messages and stack traces
๐ก Feature Requests
For feature requests:
- Check existing issues first
- Provide clear use case and rationale
- Consider backward compatibility
- Offer to implement if possible
๐ Core Dependencies
The SDK uses these core dependencies:
| Library | Version | Purpose |
|---|---|---|
| axios | ^1.6.7 | HTTP client for API requests |
| jsonwebtoken | ^9.0.2 | JWT token generation and validation |
When adding new dependencies:
- Justify the need
- Choose well-maintained libraries
- Consider bundle size impact
- Update the dependencies table
๐ Security
For security-related issues:
- DO NOT open public issues
- Email security concerns to: open@zhipuai.cn
- Include detailed reproduction steps
- Allow time for assessment before disclosure
๐ Getting Help
If you need help:
- Check existing documentation
- Search existing issues
- Ask questions in discussions
- Contact maintainers: open@zhipuai.cn
๐ License
By contributing, you agree that your contributions will be licensed under the same license as the project (MIT License).
Thank you for contributing to ZhipuAI Node.js SDK! ๐