Skip to content

token billing#211

Closed
jsyqrt wants to merge 4 commits into
mainfrom
feature/token-billing
Closed

token billing#211
jsyqrt wants to merge 4 commits into
mainfrom
feature/token-billing

Conversation

@jsyqrt

@jsyqrt jsyqrt commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

📋 基本信息

  • 提交者: Backend Developer (ID: agt_45ee41456c2a1e988a9c19fd)
  • 关联任务: TASK-tsk_9e372e0d8f2cc7f40993cd1a
  • 目标分支: main (feature/token-billing branch)

🎯 背景与动机 (Why)

Create the Cloudflare Worker proxy skeleton as the first step of the token-billing infrastructure. This provides routing, middleware chain, error handling, and a health check endpoint.

🔧 变更内容 (What)

  • 13 new files in packages/cloudflare-worker/
  • wrangler.toml — dev server config on port 8765
  • tsconfig.json + package.json — Worker-targeted TypeScript config
  • src/index.ts — Entry point with composable middleware chain
  • src/middleware/ — CORS, auth (subscription_key header), logging, rate-limit (in-memory), timeout (5s)
  • src/routes/ — health.ts (GET) + chat.ts (POST stub)
  • src/utils/ — errors.ts (ErrorResponse types + helpers) + response.ts (HTTP response builders)
  • pnpm-lock.yaml updated with cloudflare-worker dependencies

✅ 验证方式 (How to Verify)

  • pnpm typecheck 通过 (full workspace clean)

👤 评审人

  • Reviewer: Code Reviewer

… skeleton

- Create packages/cloudflare-worker/ with wrangler.toml + tsconfig + package.json
- Implement 5 middleware: CORS, auth, logging, rate-limit, timeout
- Implement 2 routes: /health (GET) and /v1/chat/completions (POST stub)
- Error utilities (errors.ts) and HTTP response helpers (response.ts)
- Composable middleware chain with Env + Context request passing
@jsyqrt jsyqrt force-pushed the feature/token-billing branch from c6731c0 to cb7ad41 Compare June 25, 2026 12:01
… — real auth and LLM forwarding

- Hub: POST /api/auth/token JWT endpoint with plan-based claims
- Hub: JWT verify + refresh support
- Worker: JWT verify (jose) middleware replacing auth stub
- Worker: auth context extraction (userId/planType/quota)
- Worker: Chat proxy route with upstream URL building + CU quota checks
- Test: 19 tests across 3 files (jwt-verify, auth-context, chat route)
@jsyqrt jsyqrt changed the title [TASK-tsk_9e372e0d8f2cc7f40993cd1a][Backend Developer] feat: add Cloudflare Worker proxy skeleton token billing Jun 25, 2026
jsyqrt added 2 commits June 25, 2026 21:05
…quota, AbortController for streaming

- Issue 1: Changed 403→429 for QUOTA_EXCEEDED and INSUFFICIENT_QUOTA
- Issue 2: Added AbortController + DEFAULT_TIMEOUT_MS to streaming fetch path
  (catch AbortError as UPSTREAM_TIMEOUT 504, other errors as UPSTREAM_UNREACHABLE 502)
- Non-blocking suggestions kept for future rounds
…525317e

[TASK-tsk_5319d992235c56638525317e][Backend Developer] feat: JWT auth + Chat proxy route — real auth and LLM forwarding
@jsyqrt

jsyqrt commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

已合并到 feature/token-billing,PR 关闭。

@jsyqrt jsyqrt closed this Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant