13 Commits

Author SHA1 Message Date
empty
d1dc095cb1 feat: 添加请求认证中间件保护 API 端点
- 新增 auth-middleware.js 验证客户端 API Key
- 支持 Authorization: Bearer <key> 和 x-api-key 两种方式
- API Keys 只通过环境变量配置(安全最佳实践)
- 公开路径: /, /health, /status
- 可配置 /v1/models 是否需要认证
- 启动时输出认证状态日志

配置方式:
  AUTH_ENABLED=true
  API_KEYS=sk-key1,sk-key2

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-27 16:14:15 +08:00
empty
eef909c5dd feat: 实现可配置的 CORS 安全策略
- 添加 getCorsConfig() 函数支持灵活的 CORS 配置
- 支持三种模式:禁用 CORS、白名单、允许所有来源
- 环境变量可覆盖 config.json 配置 (CORS_ENABLED, CORS_ALLOW_ALL, CORS_ORIGINS)
- config.json 默认使用白名单模式,仅允许 localhost
- 动态验证 Origin 头,不在白名单的请求不设置 CORS 头
- 添加 Vary: Origin 头支持 CDN 缓存

安全改进:
- 生产环境默认 allow_all=false,避免 CORS 通配符
- 白名单模式下,未授权来源的请求会被浏览器拒绝

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 15:33:04 +08:00
empty
3dccbcfed1 feat: 添加全局错误处理机制
- 添加 unhandledRejection 处理器捕获未处理的 Promise rejection
- 添加 uncaughtException 处理器捕获未捕获的异常
- 添加 SIGTERM/SIGINT 信号处理实现优雅关闭
- 实现 gracefulShutdown 函数,给正在处理的请求3秒完成时间
- 错误信息经过 sanitizeForLog 脱敏处理
- 生产环境下隐藏堆栈信息

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 15:24:03 +08:00
empty
5e01993120 feat: add SLS toggle and sanitize logs 2025-12-27 15:07:28 +08:00
Claude Code
82a5a2cdfb feat: 集成阿里云日志服务(SLS)并增强日志记录详情
- 添加 SLS 日志上报模块(sls-logger.js)
  - 支持批量上报(每10条或5秒间隔)
  - 环境变量缺失时静默降级
  - 自动重试失败的日志

- 新增日志信息提取器(log-extractor.js)
  - 提取 Token 使用统计(input_tokens, output_tokens)
  - 提取用户标识信息(user_id, session_id, ip)
  - 提取请求参数(temperature, max_tokens, stream)
  - 提取消息摘要(message_count, role_distribution, tool_names)

- 增强所有 API 端点的日志记录
  - /v1/chat/completions
  - /v1/responses
  - /v1/messages
  - /v1/messages/count_tokens

- 修复日志字段序列化问题
  - 扁平化嵌套对象字段,避免 [object Object]
  - 数组字段转换为逗号分隔字符串

- 添加阿里云环境变量配置到 docker-compose.yml
  - ALIYUN_ACCESS_KEY_ID
  - ALIYUN_ACCESS_KEY_SECRET
  - ALIYUN_SLS_ENDPOINT
  - ALIYUN_SLS_PROJECT
  - ALIYUN_SLS_LOGSTORE

- 修改认证配置为自动刷新 Token 机制
  - 使用 DROID_REFRESH_KEY 替代固定的 FACTORY_API_KEY
  - 实现每6小时自动刷新(Token有效期8小时)
  - Token 持久化到 auth.json
2025-12-27 04:42:43 +00:00
1eon
c31b680d95 feat: add dynamic user-agent version updater
- Add user-agent-updater.js to automatically fetch latest factory-cli version
- Fetch version from https://downloads.factory.ai/factory-cli/LATEST on startup
- Automatically refresh version every hour
- Implement retry mechanism: max 3 retries with 1-minute intervals on failure
- Use user_agent from config.json as fallback value
- Update config.js to use dynamic user-agent
- Initialize updater in server.js startup sequence
2025-11-16 16:25:15 +08:00
itzhan
502922310c add claudecode count path 2025-10-09 19:19:06 +08:00
1e0n
4503604d04 支持Anthropic端点客户端x-api-key:\n- /v1/messages读取x-api-key并优先作为客户端授权传递\n- getAnthropicHeaders转发x-api-key并透传anthropic-version\n- CORS允许X-API-Key与anthropic-version 2025-10-09 14:58:56 +08:00
1e0n
25f89a12b7 实现双授权系统:支持FACTORY_API_KEY环境变量优先级和客户端授权回退机制
- 新增FACTORY_API_KEY环境变量支持(最高优先级)
- 保留现有refresh token自动刷新机制
- 添加客户端authorization头作为fallback
- 优化启动流程,无认证配置时不报错退出
- 更新所有端点支持新的授权优先级系统
- 修改GPT-5-Codex推理级别为off
2025-10-08 19:42:39 +08:00
1e0n
4d5ce26e7f Add /v1/messages endpoint for direct Anthropic forwarding
Features:
- Add new /v1/messages endpoint for transparent Anthropic request/response forwarding
- Only supports anthropic type endpoints (rejects openai with 400 error)
- No request transformation - forwards original request body as-is
- No response transformation - streams and non-streaming responses forwarded directly

Now supports three endpoint patterns:
- /v1/chat/completions: Universal with format conversion (anthropic, openai)
- /v1/responses: Direct proxy for openai endpoints only
- /v1/messages: Direct proxy for anthropic endpoints only
2025-10-07 05:26:57 +08:00
1e0n
79616ba3b9 Add /v1/responses endpoint for direct OpenAI forwarding
Features:
- Add new /v1/responses endpoint for transparent request/response forwarding
- Only supports openai type endpoints (rejects anthropic with 400 error)
- No request transformation - forwards original request body as-is
- No response transformation - streams and non-streaming responses forwarded directly
- /v1/chat/completions keeps original behavior with format conversion

Differences between endpoints:
- /v1/chat/completions: Converts formats for all endpoint types (anthropic, openai)
- /v1/responses: Direct proxy for openai endpoints only, zero transformation
2025-10-07 05:14:58 +08:00
1e0n
1bfbf5a31c Add detailed 404 error logging for invalid requests
- Log invalid request method, URL, path, and parameters
- Display query parameters and request body if present
- Show client IP and User-Agent information
- Return helpful error message with available endpoints
- Format console output with clear visual separators
2025-10-07 01:53:27 +08:00
1e0n
6dca025e96 Initial commit: OpenAI compatible API proxy with auto token refresh
- Implemented OpenAI compatible API proxy server
- Support for Anthropic and custom OpenAI format conversion
- Automatic API key refresh with WorkOS OAuth
- SSE streaming response transformation
- Smart header management for Factory endpoints
- Chinese documentation
2025-10-06 02:12:01 +08:00