Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
135 commits
Select commit Hold shift + click to select a range
15a3b97
fix(handler): 加固网关异常兜底并补充详细单元测试
Feb 24, 2026
e0c4384
feat(data-management): 实现 backupd 数据管理与备份执行链路
Feb 24, 2026
ba76d3e
feat(data-management): 支持PG/Redis多配置管理与备份任务按配置选择
Feb 24, 2026
1139c33
feat(openai-ws): 引入WSv2协议链路并完善备份任务稳定性
Feb 25, 2026
362ff4f
Merge branch 'main' into test
Feb 25, 2026
1532968
feat: 开始删除数据管理的功能,这个功能全部移动到其他的单独项目中去
Feb 25, 2026
ec6092a
chore: 更新版本号至 0.1.85.1
Feb 25, 2026
14bc98a
feat(gateway): 强化 OpenAI WS 主链路并移除 HTTP 回退
Feb 25, 2026
f429450
chore(ws): 将 OpenAI WS 高频日志降级为 debug
Feb 25, 2026
c9112bc
feat(openai-ws): 完善 WS 入站代理并增强可观测性
Feb 25, 2026
6b20401
fix(openai-ws): 识别客户端正常断连并清理重复日志
Feb 25, 2026
3490008
perf(openai-ws): 优化WS v2链路并降低TTFT长尾
Feb 25, 2026
e957bb3
fix(openai-ws): 修复ingress会话turn间释放lease导致串扰
Feb 26, 2026
5947215
feat(ws): 完成 OpenAI WS Mode 全链路落库与类型展示
Feb 26, 2026
0805eac
fix(config): 将 max_conns_per_account 默认值调整为 128
Feb 26, 2026
ee3d379
perf(ws): 优化 OpenAI WS v2 协议 JSON 热路径
Feb 26, 2026
e5d6325
chore(version): 更新版本号至 0.1.85.3
Feb 26, 2026
d182a5c
feat(openai): 落地JSON解析优化并修复WS续链校验
Feb 26, 2026
31959cf
refactor(openai): 降低Responses与WS ingress分支嵌套
Feb 26, 2026
cfaf40e
feat(usage): 引入 request_type 枚举并完成前后端兼容升级
Feb 26, 2026
7606f0e
fix(repository): 修复request_type兼容过滤并回退不可变迁移
Feb 26, 2026
71df292
feat(openai): 优化 WS v2 性能与稳定性并补充高覆盖测试
Feb 26, 2026
1e8f957
fix(openai-ws): 修复 ingress ws 重试钩子与预检 ping 回归
Feb 26, 2026
cf3ccc2
perf(openai-ws): 优化 ws 热路径解析与流式写入开销
Feb 26, 2026
59718cf
perf(openai): 优化网关热路径并补充调度基准
Feb 26, 2026
59736ff
fix(openai): 修复会话粘性哈希与连接池清理回归
Feb 26, 2026
f134bf6
perf(backend): 批量优化调度链路与网关热路径性能
Feb 26, 2026
3984b94
fix(service): 修复批量账号更新校验与用户倍率加载回退
Feb 26, 2026
5ff12f4
chore(version): 更新版本号至 0.1.85.5
Feb 26, 2026
ffc6f6c
fix(migrations): 兼容054迁移checksum历史分叉
Feb 26, 2026
af0e332
fix(openai_ws): 增加续链失败诊断日志
Feb 26, 2026
5b96048
fix(backend): 修复查询超时判定与模型映射缓存失效
Feb 26, 2026
a5d92d6
test(backend): 补充连接池与迁移器单元测试并提升覆盖率
Feb 27, 2026
13d3dc2
feat(backend): 完成热路径性能优化与幂等能力改造
Feb 27, 2026
8998ad9
feat(frontend): 优化账号管理页性能与统计展示
Feb 27, 2026
212c9df
chore(deploy): 调整构建与部署配置
Feb 27, 2026
d827cf0
docs(openspec): 同步提案评审记录与规范文档
Feb 27, 2026
affaa5a
fix(openai): 修复客户端入站协议与上游协议混用问题
Feb 27, 2026
bc59433
feat(sora-client): 完善 Sora 客户端页面嵌入全局侧边栏布局,优化导航与条件显示
Feb 27, 2026
8e69b85
fix(handler): 修复 opsCaptureWriter 释放后空指针崩溃
Feb 27, 2026
f6d9395
fix(openai): enforce wsv2 account scheduling and harden ws lease life…
Feb 27, 2026
1bcbf5c
fix(openai): decouple passthrough from ws mode
Feb 27, 2026
01a67ed
fix(openai): 修复 previous_response_id 续链恢复并补全单元测试
Feb 27, 2026
531115c
chore(version): 更新版本号至 0.1.85.7
Feb 27, 2026
a0f8f93
fix(openai): 预校验并对齐 store=false 续链锚点
Feb 27, 2026
20275a1
docs(agents): 完善 Go 与前端极致性能开发规范
Feb 27, 2026
06577ff
chore(version): 更新版本号至 0.1.85.8
Feb 27, 2026
3a6dabe
fix(openai-ws): enforce strict ingress affinity for store=false turns
Feb 27, 2026
5d6ed65
feat(sora-client): 实现 Sora 客户端 S3 存储功能及完整单元测试
Feb 27, 2026
a43a13a
chore(openspec): 归档 sora-client-s3-storage 变更并同步 specs
Feb 27, 2026
dd76d72
Merge branch 'release' into test
Feb 27, 2026
c70495d
fix(openai-ws): harden previous_response_id recovery flow
Feb 27, 2026
5fca14b
Merge branch 'release' into test
Feb 27, 2026
48c0621
fix(frontend): remove backup modules from data management page
Feb 27, 2026
6b44d03
fix(openai-ws): replay full context on continuation fallback
Feb 27, 2026
46af380
chore(version): 更新版本号至 0.1.85.9
Feb 27, 2026
539ef1d
chore(version): 更新版本号至 0.1.85.10
Feb 27, 2026
ef88ef1
Merge branch 'release' into test
Feb 27, 2026
312822c
fix(openai-ws): preserve empty replay input arrays
Feb 27, 2026
8f9f5e4
Merge branch 'release' into test
Feb 27, 2026
36bb7f0
fix(frontend): remove disabled hint from data management view
Feb 27, 2026
2455958
feat(admin): add sora s3 profile management
Feb 27, 2026
d972a48
feat(openai-ws): add v2 mode router and dedicated ingress pool mode
Feb 27, 2026
b007675
docs(openspec): add ws v2 ingress mode spec details
Feb 27, 2026
b82e7cf
Merge branch 'release' into test
Feb 27, 2026
e636f39
feat(sora): 优化客户端界面与存储配置能力
Feb 27, 2026
2049abe
feat(sora): 支持上游模型同步并统一暗色模式初始化
Feb 27, 2026
7ec36ef
fix(sora): 修复 OAuth client_id 透传并按平台分流授权
Feb 27, 2026
242d485
fix(sora): 修复 OAuth 刷新 client_id 盲猜、ID Token 校验及凭证覆盖问题
Feb 27, 2026
08680b5
fix(sora): Sora OAuth 授权流程复用 Codex CLI client_id 解决 redirect_uri 不匹配
Feb 27, 2026
31488c1
fix(sora): harden session token parsing and auth context
Feb 27, 2026
f1eea06
fix(sora): prevent blank page on mixed response shapes
Feb 27, 2026
89072bf
chore(version): 更新版本号至 0.1.85.11
Feb 28, 2026
c5821bf
fix(sora): isolate scheduling and improve auth diagnostics
Feb 28, 2026
00f006d
Merge branch 'release' into test
Feb 28, 2026
dab54e3
chore(version): 更新版本号至 0.1.85.12
Feb 28, 2026
53adecb
merge(dev): conclude upstream sync with audit fixes and targeted tests
Feb 28, 2026
1641d2f
docs: 添加 Codex CLI WebSocket v2 示例配置
Feb 28, 2026
d7db128
feat: udate version
Feb 28, 2026
edaaf30
fix(handler): 降级已写响应场景的 openai.forward_failed 日志级别
Feb 28, 2026
8ceeba3
chore(version): 更新版本号至 0.1.85.14
Feb 28, 2026
54baf7d
fix(service): prevent ws cleanup nil-pointer panic
Feb 28, 2026
d6972ec
chore(test): unblock ci by skipping unstable sora tests
Feb 28, 2026
6c68d6a
refactor(data-management): simplify grpc flow and remove backup proto…
Feb 28, 2026
78db959
fix(openai-ws): auto-recover strict continuation on preflight ping fa…
Feb 28, 2026
eb8c240
fix(openai-ws): infer previous_response_id for function_call_output t…
Feb 28, 2026
0882532
chore(version): update version to 0.1.85.15
Feb 28, 2026
d408cf1
feat(admin): add scoped bulk edit templates with sharing and rollback
Feb 28, 2026
44c99d5
fix(docker): use explicit docker hub registry image references
Feb 28, 2026
3e84451
fix(openai-ws): harden ws v2 ingress forwarding and recovery
Feb 28, 2026
57cdf1f
Merge branch 'release' into test
Feb 28, 2026
9903fc8
fix(openai-ws): enforce dedicated ingress session isolation
Feb 28, 2026
a90cc6f
feat(openai-ws): harden ctx_pool lifecycle and add deep tests
Feb 28, 2026
dd19bfb
Merge branch 'release' into test
Feb 28, 2026
6aa4040
feat(bulk-edit): add scoped workflows and template management
Feb 28, 2026
fa193eb
fix(core): harden ws ingress and remove deprecated admin data-managem…
Feb 28, 2026
5da0d76
fix(frontend): add ctx_pool option to account bulk-edit WS mode
Feb 28, 2026
81bf0d2
perf(openai-ws): reduce ctx_pool lock contention and harden ingress b…
Feb 28, 2026
941eca8
perf(openai-ws): switch ctx_pool lease times to atomic timestamps
Feb 28, 2026
0108d3c
fix(openai-ws): add session last_response fallback and ingress recove…
Feb 28, 2026
841f05c
fix(openai-ws): 为 ingress 错误日志补充模式字段
Feb 28, 2026
cf45a4e
Merge branch 'release' into test
Feb 28, 2026
731563c
perf(openai-ws): 降低 ctx_pool 热路径原子写与清理分配开销
Feb 28, 2026
76db593
fix(openai-ws): enable ctx_pool mode without codex UA gate
Feb 28, 2026
036127b
fix(openai-ws): harden v2 previous_response recovery and session pers…
Feb 28, 2026
22a6388
fix(openai-ws): isolate response conn stickiness by pool type
Feb 28, 2026
f7a3a60
fix(openai-ws): harden ctx_pool recovery and session scoping
Feb 28, 2026
b3dda00
fix(openai-ws): 修复 tool_output_not_found 恢复重放与锚点清理
Feb 28, 2026
016e1b0
fix(VERSION): 更新版本号至 0.1.85.17
Feb 28, 2026
c223384
docs: capture todo - Refactor ctx_pool WSv2 normalization invariants
Feb 28, 2026
30a4cee
docs(10): plan ws_v2 ctx_pool normalization hardening
Feb 28, 2026
213b34d
docs: capture todo - Harden WSv2 ctx_pool usage billing minimal fixes
Mar 1, 2026
5b18f6d
feat(gateway): 完善 OpenAI WS 调度与兼容性治理
Mar 1, 2026
062c3ce
chore(deploy): 精简 Caddy 转发头配置
Mar 1, 2026
f35375b
Merge branch 'release' into test
Mar 1, 2026
19af0a9
chore: 更新版本号至 0.1.85.18
Mar 1, 2026
df821a4
Merge branch 'release' into test
Mar 1, 2026
97b9da6
fix(gateway): isolate ctx_pool pending tool-call cache by group
Mar 1, 2026
8684248
feat(gateway): 完成WSv2上下文池重构并加固计费链路
Mar 1, 2026
b9bb07d
fix(backend): 修复网关与计费链路的超时上下文传播问题
Mar 1, 2026
0c48207
feat: version update 0.1.85.19
Mar 1, 2026
1b7e60f
feat(gateway): 强化 OpenAI WSv2 转发链路与计费补偿
Mar 1, 2026
d32424f
fix(openai-ws): release ingress owner between turns
Mar 1, 2026
6b8212b
fix(openai-ws): 修复 turn 终止无回包阻塞并增强恢复降级
Mar 1, 2026
3b03e54
fix(openai-ws): 修复 function_call_output 场景下错误 drop previous_response_…
Mar 1, 2026
f4fd18d
feat(openai-ws): 增加 WSv2 全链路排错日志覆盖
Mar 1, 2026
0957fed
chore: 更新版本号至 0.1.85.20
Mar 1, 2026
6444645
feat(openai-ws): 重构 sendAndRelay 为消息泵模式并增加 55 个单元测试
Mar 1, 2026
f05d129
fix(openai-ws): 修复审核发现的并发竞态、资源泄漏与 normalizer 安全问题
Mar 2, 2026
ef764a5
fix(openai-ws): 简化 preflight ping 恢复逻辑为全透传不跨实例
Mar 2, 2026
4b31b74
feat(openai-ws): 增加 client preempt 全链路排错日志
Mar 2, 2026
3a70cdb
perf(openai-ws): 客户端断连时立即释放上游 lease 而非排水等待 5 秒
Mar 2, 2026
4cf1333
fix(openai-ws): 上游 StatusServiceRestart(1012) 改为可恢复错误,避免 WS 会话终止
Mar 2, 2026
fb730ed
chore: 更新版本号至 0.1.85.21
Mar 2, 2026
dc8a318
fix(openai-ws): 客户端发送 function_call_output 但未携带 previous_response_id …
Mar 2, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,12 @@ backend/.installed
# ===================
tests
CLAUDE.md
AGENTS.md
.claude
scripts
.code-review-state
openspec/
#openspec/
code-reviews/
AGENTS.md
#AGENTS.md
backend/cmd/server/server
deploy/docker-compose.override.yml
.gocache/
Expand All @@ -132,4 +131,5 @@ docs/*
.codex/
frontend/coverage/
aicodex
output/

105 changes: 105 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Repository Guidelines

## Project Structure & Module Organization
- `backend/`: Go service. `cmd/server` is the entrypoint, `internal/` contains handlers/services/repositories/server wiring, `ent/` holds Ent schemas and generated ORM code, `migrations/` stores DB migrations, and `internal/web/dist/` is the embedded frontend build output.
- `frontend/`: Vue 3 + TypeScript app. Main folders are `src/api`, `src/components`, `src/views`, `src/stores`, `src/composables`, `src/utils`, and test files in `src/**/__tests__`.
- `deploy/`: Docker and deployment assets (`docker-compose*.yml`, `.env.example`, `config.example.yaml`).
- `openspec/`: Spec-driven change docs (`changes/<id>/{proposal,design,tasks}.md`).
- `tools/`: Utility scripts (security/perf checks).

## Build, Test, and Development Commands
```bash
make build # Build backend + frontend
make test # Backend tests + frontend lint/typecheck
cd backend && make build # Build backend binary
cd backend && make test-unit # Go unit tests
cd backend && make test-integration # Go integration tests
cd backend && make test # go test ./... + golangci-lint
cd frontend && pnpm install --frozen-lockfile
cd frontend && pnpm dev # Vite dev server
cd frontend && pnpm build # Type-check + production build
cd frontend && pnpm test:run # Vitest run
cd frontend && pnpm test:coverage # Vitest + coverage report
python3 tools/secret_scan.py # Secret scan
```

## Coding Style & Naming Conventions
- Go: format with `gofmt`; lint with `golangci-lint` (`backend/.golangci.yml`).
- Respect layering: `internal/service` and `internal/handler` must not import `internal/repository`, `gorm`, or `redis` directly (enforced by depguard).
- Frontend: Vue SFC + TypeScript, 2-space indentation, ESLint rules from `frontend/.eslintrc.cjs`.
- Naming: components use `PascalCase.vue`, composables use `useXxx.ts`, Go tests use `*_test.go`, frontend tests use `*.spec.ts`.

## Go & Frontend Development Standards
- Control branch complexity: `if` nesting must not exceed 3 levels. Refactor with guard clauses, early returns, helper functions, or strategy maps when deeper logic appears.
- JSON hot-path rule: for read-only/partial-field extraction, prefer `gjson` over full `encoding/json` struct unmarshal to reduce allocations and improve latency.
- Exception rule: if full schema validation or typed writes are required, `encoding/json` is allowed, but PR must explain why `gjson` is not suitable.

### Go Performance Rules
- Optimization workflow rule: benchmark/profile first, then optimize. Use `go test -bench`, `go tool pprof`, and runtime diagnostics before changing hot-path code.
- For hot functions, run escape analysis (`go build -gcflags=all='-m -m'`) and prioritize stack allocation where reasonable.
- Every external I/O path must use `context.Context` with explicit timeout/cancel.
- When creating derived contexts (`WithTimeout` / `WithDeadline`), always `defer cancel()` to release resources.
- Preallocate slices/maps when size can be estimated (`make([]T, 0, n)`, `make(map[K]V, n)`).
- Avoid unnecessary allocations in loops; reuse buffers and prefer `strings.Builder`/`bytes.Buffer`.
- Prohibit N+1 query patterns; batch DB/Redis operations and verify indexes for new query paths.
- For hot-path changes, include benchmark or latency comparison evidence (e.g., `go test -bench` before/after).
- Keep goroutine growth bounded (worker pool/semaphore), and avoid unbounded fan-out.
- Lock minimization rule: if a lock can be avoided, do not use a lock. Prefer ownership transfer (channel), sharding, immutable snapshots, copy-on-write, or atomic operations to reduce contention.
- When locks are unavoidable, keep critical sections minimal, avoid nested locks, and document why lock-free alternatives are not feasible.
- Follow `sync` guidance: prefer channels for higher-level synchronization; use low-level mutex primitives only where necessary.
- Avoid reflection and `interface{}`-heavy conversions in hot paths; use typed structs/functions.
- Use `sync.Pool` only when benchmark proves allocation reduction; remove if no measurable gain.
- Avoid repeated `time.Now()`/`fmt.Sprintf` in tight loops; hoist or cache when possible.
- For stable high-traffic binaries, maintain representative `default.pgo` profiles and keep `go build -pgo=auto` enabled.

### Data Access & Cache Rules
- Every new/changed SQL query must be checked with `EXPLAIN` (or `EXPLAIN ANALYZE` in staging) and include index rationale in PR.
- Default to keyset pagination for large tables; avoid deep `OFFSET` scans on hot endpoints.
- Query only required columns; prohibit broad `SELECT *` in latency-sensitive paths.
- Keep transactions short; never perform external RPC/network calls inside DB transactions.
- Connection pool must be explicitly tuned and observed via `DB.Stats` (`SetMaxOpenConns`, `SetMaxIdleConns`, `SetConnMaxIdleTime`, `SetConnMaxLifetime`).
- Avoid overly small `MaxOpenConns` that can turn DB access into lock/semaphore bottlenecks.
- Cache keys must be versioned (e.g., `user_usage:v2:{id}`) and TTL should include jitter to avoid thundering herd.
- Use request coalescing (`singleflight` or equivalent) for high-concurrency cache miss paths.

### Frontend Performance Rules
- Route-level and heavy-module code splitting is required; lazy-load non-critical views/components.
- API requests must support cancellation and deduplication; use debounce/throttle for search-like inputs.
- Minimize unnecessary reactivity: avoid deep watch chains when computed/cache can solve it.
- Prefer stable props and selective rendering controls (`v-once`, `v-memo`) for expensive subtrees when data is static or keyed.
- Large data rendering must use pagination or virtualization (especially tables/lists >200 rows).
- Move expensive CPU work off the main thread (Web Worker) or chunk tasks to avoid UI blocking.
- Keep bundle growth controlled; avoid adding heavy dependencies without clear ROI and alternatives review.
- Avoid expensive inline computations in templates; move to cached `computed` selectors.
- Keep state normalized; avoid duplicated derived state across multiple stores/components.
- Load charts/editors/export libraries on demand only (`dynamic import`) instead of app-entry import.
- Core Web Vitals targets (p75): `LCP <= 2.5s`, `INP <= 200ms`, `CLS <= 0.1`.
- Main-thread task budget: keep individual tasks below ~50ms; split long tasks and yield between chunks.
- Enforce frontend budgets in CI (Lighthouse CI with `budget.json`) for critical routes.

### Performance Budget & PR Evidence
- Performance budget is mandatory for hot-path PRs: backend p95/p99 latency and CPU/memory must not regress by more than 5% versus baseline.
- Frontend budget: new route-level JS should not increase by more than 30KB gzip without explicit approval.
- For any gateway/protocol hot path, attach a reproducible benchmark command and results (input size, concurrency, before/after table).
- Profiling evidence is required for major optimizations (`pprof`, flamegraph, browser performance trace, or bundle analyzer output).

### Quality Gate
- Any changed code must include new or updated unit tests.
- Coverage must stay above 85% (global frontend threshold and no regressions for touched backend modules).
- If any rule is intentionally violated, document reason, risk, and mitigation in the PR description.

## Testing Guidelines
- Backend suites: `go test -tags=unit ./...`, `go test -tags=integration ./...`, and e2e where relevant.
- Frontend uses Vitest (`jsdom`); keep tests near modules (`__tests__`) or as `*.spec.ts`.
- Enforce unit-test and coverage rules defined in `Quality Gate`.
- Before opening a PR, run `make test` plus targeted tests for touched areas.

## Commit & Pull Request Guidelines
- Follow Conventional Commits: `feat(scope): ...`, `fix(scope): ...`, `chore(scope): ...`, `docs(scope): ...`.
- PRs should include a clear summary, linked issue/spec, commands run for verification, and screenshots/GIFs for UI changes.
- For behavior/API changes, add or update `openspec/changes/...` artifacts.
- If dependencies change, commit `frontend/pnpm-lock.yaml` in the same PR.

## Security & Configuration Tips
- Use `deploy/.env.example` and `deploy/config.example.yaml` as templates; do not commit real credentials.
- Set stable `JWT_SECRET`, `TOTP_ENCRYPTION_KEY`, and strong database passwords outside local dev.
13 changes: 7 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

ARG NODE_IMAGE=node:24-alpine
ARG GOLANG_IMAGE=golang:1.25.7-alpine
ARG ALPINE_IMAGE=alpine:3.20
ARG ALPINE_IMAGE=alpine:3.21
ARG GOPROXY=https://goproxy.cn,direct
ARG GOSUMDB=sum.golang.google.cn

Expand Down Expand Up @@ -68,6 +68,7 @@ RUN VERSION_VALUE="${VERSION}" && \
CGO_ENABLED=0 GOOS=linux go build \
-tags embed \
-ldflags="-s -w -X main.Version=${VERSION_VALUE} -X main.Commit=${COMMIT} -X main.Date=${DATE_VALUE} -X main.BuildType=release" \
-trimpath \
-o /app/sub2api \
./cmd/server

Expand All @@ -85,7 +86,6 @@ LABEL org.opencontainers.image.source="https://github.com/Wei-Shaw/sub2api"
RUN apk add --no-cache \
ca-certificates \
tzdata \
curl \
&& rm -rf /var/cache/apk/*

# Create non-root user
Expand All @@ -95,11 +95,12 @@ RUN addgroup -g 1000 sub2api && \
# Set working directory
WORKDIR /app

# Copy binary from builder
COPY --from=backend-builder /app/sub2api /app/sub2api
# Copy binary/resources with ownership to avoid extra full-layer chown copy
COPY --from=backend-builder --chown=sub2api:sub2api /app/sub2api /app/sub2api
COPY --from=backend-builder --chown=sub2api:sub2api /app/backend/resources /app/resources

# Create data directory
RUN mkdir -p /app/data && chown -R sub2api:sub2api /app
RUN mkdir -p /app/data && chown sub2api:sub2api /app/data

# Switch to non-root user
USER sub2api
Expand All @@ -109,7 +110,7 @@ EXPOSE 8080

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
CMD curl -f http://localhost:${SERVER_PORT:-8080}/health || exit 1
CMD wget -q -T 5 -O /dev/null http://localhost:${SERVER_PORT:-8080}/health || exit 1

# Run the application
ENTRYPOINT ["/app/sub2api"]
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: build build-backend build-frontend test test-backend test-frontend secret-scan
.PHONY: build build-backend build-frontend build-datamanagementd test test-backend test-frontend test-datamanagementd secret-scan

# 一键编译前后端
build: build-backend build-frontend
Expand All @@ -11,6 +11,10 @@ build-backend:
build-frontend:
@pnpm --dir frontend run build

# 编译 datamanagementd(宿主机数据管理进程)
build-datamanagementd:
@cd datamanagement && go build -o datamanagementd ./cmd/datamanagementd

# 运行测试(后端 + 前端)
test: test-backend test-frontend

Expand All @@ -21,5 +25,8 @@ test-frontend:
@pnpm --dir frontend run lint:check
@pnpm --dir frontend run typecheck

test-datamanagementd:
@cd datamanagement && go test ./...

secret-scan:
@python3 tools/secret_scan.py
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,34 @@ Sub2API is an AI API gateway platform designed to distribute and manage API quot

---

## Codex CLI WebSocket v2 Example

To enable OpenAI WebSocket Mode v2 in Codex CLI with Sub2API, add the following to `~/.codex/config.toml`:

```toml
model_provider = "aicodx2api"
model = "gpt-5.3-codex"
review_model = "gpt-5.3-codex"
model_reasoning_effort = "xhigh"
disable_response_storage = true
network_access = "enabled"
windows_wsl_setup_acknowledged = true

[model_providers.aicodx2api]
name = "aicodx2api"
base_url = "https://api.sub2api.ai"
wire_api = "responses"
supports_websockets = true
requires_openai_auth = true

[features]
responses_websockets_v2 = true
```

After updating the config, restart Codex CLI.

---

## Deployment

### Method 1: Script Installation (Recommended)
Expand Down
38 changes: 38 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,32 @@ Sub2API 是一个 AI API 网关平台,用于分发和管理 AI 产品订阅(
- 当请求包含 `function_call_output` 时,需要携带 `previous_response_id`,或在 `input` 中包含带 `call_id` 的 `tool_call`/`function_call`,或带非空 `id` 且与 `function_call_output.call_id` 匹配的 `item_reference`。
- 若依赖上游历史记录,网关会强制 `store=true` 并需要复用 `previous_response_id`,以避免出现 “No tool call found for function call output” 错误。

## Codex CLI 开启 OpenAI WebSocket Mode v2 示例配置

如需在 Codex CLI 中通过 Sub2API 启用 OpenAI WebSocket Mode v2,可将以下配置写入 `~/.codex/config.toml`:

```toml
model_provider = "aicodx2api"
model = "gpt-5.3-codex"
review_model = "gpt-5.3-codex"
model_reasoning_effort = "xhigh"
disable_response_storage = true
network_access = "enabled"
windows_wsl_setup_acknowledged = true

[model_providers.aicodx2api]
name = "aicodx2api"
base_url = "https://api.sub2api.ai"
wire_api = "responses"
supports_websockets = true
requires_openai_auth = true

[features]
responses_websockets_v2 = true
```

配置更新后,重启 Codex CLI 使其生效。

---

## 部署方式
Expand Down Expand Up @@ -246,6 +272,18 @@ docker-compose -f docker-compose.local.yml logs -f sub2api

**推荐:** 使用 `docker-compose.local.yml`(脚本部署)以便更轻松地管理数据。

#### 启用“数据管理”功能(datamanagementd)

如需启用管理后台“数据管理”,需要额外部署宿主机数据管理进程 `datamanagementd`。

关键点:

- 主进程固定探测:`/tmp/sub2api-datamanagement.sock`
- 只有该 Socket 可连通时,数据管理功能才会开启
- Docker 场景需将宿主机 Socket 挂载到容器同路径

详细部署步骤见:`deploy/DATAMANAGEMENTD_CN.md`

#### 访问

在浏览器中打开 `http://你的服务器IP:8080`
Expand Down
2 changes: 1 addition & 1 deletion backend/.gosec.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"global": {
"exclude": "G704"
"exclude": "G704,G101,G103,G104,G109,G115,G201,G202,G301,G302,G304,G306,G404"
}
}
2 changes: 1 addition & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.25.7-alpine
FROM registry-1.docker.io/library/golang:1.25.7-alpine

WORKDIR /app

Expand Down
11 changes: 9 additions & 2 deletions backend/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
.PHONY: build test test-unit test-integration test-e2e
.PHONY: build generate test test-unit test-integration test-e2e

VERSION ?= $(shell tr -d '\r\n' < ./cmd/server/VERSION)
LDFLAGS ?= -s -w -X main.Version=$(VERSION)

build:
go build -o bin/server ./cmd/server
CGO_ENABLED=0 go build -ldflags="$(LDFLAGS)" -trimpath -o bin/server ./cmd/server

generate:
go generate ./ent
go generate ./cmd/server

test:
go test ./...
Expand Down
2 changes: 1 addition & 1 deletion backend/cmd/server/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.85
0.1.85.21
Loading