jodit-ai-adapter 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +39 -0
- package/.env.production +4 -0
- package/.prettierrc.json +8 -0
- package/CHANGELOG.md +36 -0
- package/CONTRIBUTING.md +209 -0
- package/LICENSE +21 -0
- package/README.md +671 -0
- package/SUMMARY.md +95 -0
- package/config.example.json +21 -0
- package/coverage/clover.xml +246 -0
- package/coverage/coverage-final.json +7 -0
- package/coverage/lcov-report/adapters/base-adapter.ts.html +568 -0
- package/coverage/lcov-report/adapters/index.html +146 -0
- package/coverage/lcov-report/adapters/openai-adapter.ts.html +1249 -0
- package/coverage/lcov-report/adapters/openai-image-adapter.ts.html +571 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/helpers/index.html +131 -0
- package/coverage/lcov-report/helpers/logger.ts.html +187 -0
- package/coverage/lcov-report/helpers/proxy.ts.html +205 -0
- package/coverage/lcov-report/index.html +146 -0
- package/coverage/lcov-report/middlewares/auth.ts.html +607 -0
- package/coverage/lcov-report/middlewares/index.html +116 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +210 -0
- package/coverage/lcov.info +504 -0
- package/dist/index.d.mts +518 -0
- package/dist/index.d.ts +518 -0
- package/dist/index.js +1745 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1733 -0
- package/dist/index.mjs.map +1 -0
- package/dist/run.d.mts +1 -0
- package/dist/run.d.ts +1 -0
- package/dist/run.js +1798 -0
- package/dist/run.js.map +1 -0
- package/dist/run.mjs +1786 -0
- package/dist/run.mjs.map +1 -0
- package/docker-compose.dev.yml +40 -0
- package/docker-compose.yml +64 -0
- package/package.json +97 -0
- package/tsconfig.json +22 -0
package/.env.example
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Server Configuration
|
|
2
|
+
PORT=8082
|
|
3
|
+
NODE_ENV=development
|
|
4
|
+
LOG_LEVEL=debug
|
|
5
|
+
|
|
6
|
+
# CORS Configuration
|
|
7
|
+
CORS_ORIGIN=*
|
|
8
|
+
|
|
9
|
+
# OpenAI Configuration
|
|
10
|
+
OPENAI_API_KEY=your-openai-api-key-here
|
|
11
|
+
OPENAI_API_ENDPOINT=https://api.openai.com/v1
|
|
12
|
+
OPENAI_DEFAULT_MODEL=gpt-4o
|
|
13
|
+
|
|
14
|
+
# HTTP Proxy (optional)
|
|
15
|
+
# HTTP_PROXY=http://proxy:8080
|
|
16
|
+
# HTTP_PROXY=socks5://proxy:1080
|
|
17
|
+
|
|
18
|
+
# DeepSeek Configuration (future)
|
|
19
|
+
# DEEPSEEK_API_KEY=your-deepseek-api-key-here
|
|
20
|
+
# DEEPSEEK_DEFAULT_MODEL=deepseek-chat
|
|
21
|
+
|
|
22
|
+
# Anthropic Configuration (future)
|
|
23
|
+
# ANTHROPIC_API_KEY=your-anthropic-api-key-here
|
|
24
|
+
# ANTHROPIC_DEFAULT_MODEL=claude-3-opus-20240229
|
|
25
|
+
|
|
26
|
+
# Rate Limiting
|
|
27
|
+
RATE_LIMIT_ENABLED=true
|
|
28
|
+
RATE_LIMIT_TYPE=memory
|
|
29
|
+
RATE_LIMIT_MAX_REQUESTS=100
|
|
30
|
+
RATE_LIMIT_WINDOW_MS=60000
|
|
31
|
+
|
|
32
|
+
# Redis Configuration (required if RATE_LIMIT_TYPE=redis)
|
|
33
|
+
# REDIS_URL=redis://localhost:6379
|
|
34
|
+
# REDIS_PASSWORD=your-redis-password
|
|
35
|
+
# REDIS_DB=0
|
|
36
|
+
# RATE_LIMIT_KEY_PREFIX=rl:
|
|
37
|
+
|
|
38
|
+
# Configuration File (optional)
|
|
39
|
+
# CONFIG_FILE=./config.json
|
package/.env.production
ADDED
package/.prettierrc.json
ADDED
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Initial project setup
|
|
12
|
+
- OpenAI adapter using Vercel AI SDK
|
|
13
|
+
- Authentication middleware with API key validation (32 chars, A-F0-9-)
|
|
14
|
+
- Referer validation support
|
|
15
|
+
- CORS middleware
|
|
16
|
+
- Streaming support via Server-Sent Events (SSE)
|
|
17
|
+
- Tool calling support
|
|
18
|
+
- Docker configuration
|
|
19
|
+
- Comprehensive test suite with nock
|
|
20
|
+
- Documentation and examples
|
|
21
|
+
- TypeScript configuration with strict mode
|
|
22
|
+
- ESLint and Prettier configuration
|
|
23
|
+
|
|
24
|
+
### Security
|
|
25
|
+
- Server-side API key storage
|
|
26
|
+
- Custom authentication callback support
|
|
27
|
+
- Referer header validation
|
|
28
|
+
|
|
29
|
+
## [0.1.0] - 2025-01-22
|
|
30
|
+
|
|
31
|
+
### Added
|
|
32
|
+
- Initial release
|
|
33
|
+
- OpenAI provider support
|
|
34
|
+
- Basic authentication
|
|
35
|
+
- Streaming responses
|
|
36
|
+
- Docker support
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
# Contributing to Jodit AI Adapter
|
|
2
|
+
|
|
3
|
+
Thank you for your interest in contributing to Jodit AI Adapter! This document provides guidelines and instructions for contributing.
|
|
4
|
+
|
|
5
|
+
## Code of Conduct
|
|
6
|
+
|
|
7
|
+
Be respectful and constructive in all interactions. We aim to maintain a welcoming and inclusive environment.
|
|
8
|
+
|
|
9
|
+
## How to Contribute
|
|
10
|
+
|
|
11
|
+
### Reporting Bugs
|
|
12
|
+
|
|
13
|
+
1. Check if the bug has already been reported in [Issues](https://github.com/jodit/jodit-ai-adapter/issues)
|
|
14
|
+
2. If not, create a new issue with:
|
|
15
|
+
- Clear title and description
|
|
16
|
+
- Steps to reproduce
|
|
17
|
+
- Expected vs actual behavior
|
|
18
|
+
- Environment details (Node version, OS, etc.)
|
|
19
|
+
- Code samples if applicable
|
|
20
|
+
|
|
21
|
+
### Suggesting Features
|
|
22
|
+
|
|
23
|
+
1. Check existing feature requests
|
|
24
|
+
2. Create a new issue with:
|
|
25
|
+
- Clear use case
|
|
26
|
+
- Proposed solution
|
|
27
|
+
- Alternative solutions considered
|
|
28
|
+
- Potential impact
|
|
29
|
+
|
|
30
|
+
### Pull Requests
|
|
31
|
+
|
|
32
|
+
1. Fork the repository
|
|
33
|
+
2. Create a feature branch: `git checkout -b feature/my-feature`
|
|
34
|
+
3. Make your changes
|
|
35
|
+
4. Write/update tests
|
|
36
|
+
5. Run tests: `npm test`
|
|
37
|
+
6. Run linter: `npm run lint`
|
|
38
|
+
7. Commit with descriptive message
|
|
39
|
+
8. Push to your fork
|
|
40
|
+
9. Create a Pull Request
|
|
41
|
+
|
|
42
|
+
## Development Setup
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
# Clone your fork
|
|
46
|
+
git clone https://github.com/YOUR-USERNAME/jodit-ai-adapter.git
|
|
47
|
+
cd jodit-ai-adapter
|
|
48
|
+
|
|
49
|
+
# Install dependencies
|
|
50
|
+
npm install
|
|
51
|
+
|
|
52
|
+
# Copy environment file
|
|
53
|
+
cp .env.example .env
|
|
54
|
+
|
|
55
|
+
# Run development server
|
|
56
|
+
npm run dev
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Coding Standards
|
|
60
|
+
|
|
61
|
+
### TypeScript
|
|
62
|
+
|
|
63
|
+
- Use strict TypeScript settings
|
|
64
|
+
- Provide types for all function parameters and return values
|
|
65
|
+
- Avoid `any` type unless absolutely necessary
|
|
66
|
+
|
|
67
|
+
### Code Style
|
|
68
|
+
|
|
69
|
+
- Use Prettier for formatting: `npm run format`
|
|
70
|
+
- Use ESLint for linting: `npm run lint`
|
|
71
|
+
- Follow existing code patterns
|
|
72
|
+
|
|
73
|
+
### Testing
|
|
74
|
+
|
|
75
|
+
- Write tests for new features
|
|
76
|
+
- Maintain or improve code coverage
|
|
77
|
+
- Use nock for mocking HTTP requests
|
|
78
|
+
- Follow AAA pattern (Arrange, Act, Assert)
|
|
79
|
+
|
|
80
|
+
Example:
|
|
81
|
+
```typescript
|
|
82
|
+
describe('MyFeature', () => {
|
|
83
|
+
it('should do something', () => {
|
|
84
|
+
// Arrange
|
|
85
|
+
const input = ...;
|
|
86
|
+
|
|
87
|
+
// Act
|
|
88
|
+
const result = myFunction(input);
|
|
89
|
+
|
|
90
|
+
// Assert
|
|
91
|
+
expect(result).toBe(expected);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Commit Messages
|
|
97
|
+
|
|
98
|
+
Follow conventional commits:
|
|
99
|
+
|
|
100
|
+
- `feat: add new provider adapter`
|
|
101
|
+
- `fix: correct authentication validation`
|
|
102
|
+
- `docs: update README with examples`
|
|
103
|
+
- `test: add tests for streaming`
|
|
104
|
+
- `refactor: simplify error handling`
|
|
105
|
+
- `chore: update dependencies`
|
|
106
|
+
|
|
107
|
+
## Adding a New AI Provider
|
|
108
|
+
|
|
109
|
+
1. **Create Adapter Class**
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
// src/adapters/my-provider-adapter.ts
|
|
113
|
+
import { BaseAdapter } from './base-adapter';
|
|
114
|
+
|
|
115
|
+
export class MyProviderAdapter extends BaseAdapter {
|
|
116
|
+
protected async processRequest(context, signal) {
|
|
117
|
+
// Implement using Vercel AI SDK
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
2. **Register in Factory**
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
// src/adapters/adapter-factory.ts
|
|
126
|
+
import { MyProviderAdapter } from './my-provider-adapter';
|
|
127
|
+
|
|
128
|
+
AdapterFactory.adapters.set('myprovider', MyProviderAdapter);
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
3. **Add Configuration**
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
// src/config/default-config.ts
|
|
135
|
+
myprovider: {
|
|
136
|
+
type: 'myprovider',
|
|
137
|
+
apiKey: process.env.MYPROVIDER_API_KEY,
|
|
138
|
+
defaultModel: 'model-name'
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
4. **Write Tests**
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
// src/adapters/my-provider-adapter.test.ts
|
|
146
|
+
describe('MyProviderAdapter', () => {
|
|
147
|
+
// Test cases
|
|
148
|
+
});
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
5. **Update Documentation**
|
|
152
|
+
|
|
153
|
+
- Add to README.md
|
|
154
|
+
- Update configuration examples
|
|
155
|
+
- Add usage examples
|
|
156
|
+
|
|
157
|
+
## Testing Guidelines
|
|
158
|
+
|
|
159
|
+
### Unit Tests
|
|
160
|
+
|
|
161
|
+
- Test individual functions/classes
|
|
162
|
+
- Mock external dependencies
|
|
163
|
+
- Cover edge cases and error conditions
|
|
164
|
+
|
|
165
|
+
### Integration Tests
|
|
166
|
+
|
|
167
|
+
- Test API endpoints
|
|
168
|
+
- Test middleware chain
|
|
169
|
+
- Test provider integration
|
|
170
|
+
|
|
171
|
+
### Running Tests
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
# Run all tests
|
|
175
|
+
npm test
|
|
176
|
+
|
|
177
|
+
# Run specific test file
|
|
178
|
+
npm test -- auth.test.ts
|
|
179
|
+
|
|
180
|
+
# Run with coverage
|
|
181
|
+
npm run test:coverage
|
|
182
|
+
|
|
183
|
+
# Watch mode
|
|
184
|
+
npm run test:watch
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Documentation
|
|
188
|
+
|
|
189
|
+
- Update README.md for user-facing changes
|
|
190
|
+
- Add JSDoc comments for public APIs
|
|
191
|
+
- Update inline comments for complex logic
|
|
192
|
+
- Create examples in `docs/` directory
|
|
193
|
+
|
|
194
|
+
## Release Process
|
|
195
|
+
|
|
196
|
+
1. Update version in `package.json`
|
|
197
|
+
2. Update CHANGELOG.md
|
|
198
|
+
3. Create git tag: `git tag v0.2.0`
|
|
199
|
+
4. Push tag: `git push --tags`
|
|
200
|
+
5. GitHub Actions will handle the rest
|
|
201
|
+
|
|
202
|
+
## Questions?
|
|
203
|
+
|
|
204
|
+
Feel free to:
|
|
205
|
+
- Open an issue for questions
|
|
206
|
+
- Start a discussion
|
|
207
|
+
- Reach out to maintainers
|
|
208
|
+
|
|
209
|
+
Thank you for contributing! 🎉
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Chupurnov Valeriy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|