Commit Graph
100 Commits
Author SHA1 Message Date
Sakurasan ca4dc4b3b7 fix: 缓存 token 计费按上游协议区分口径
- 新增 ComputeCost:OpenAI 系 prompt 含缓存读需扣减(异常数据钳制为 0);
  Anthropic input_tokens 不含缓存,按原值计费,缓存写按输入价 ×1.25(原实现误用输出价)
- recordUsage 传入上游协议(用量语义跟随解析它的上游响应,而非客户端协议)
- 补充单元测试覆盖两种协议口径与边界情况
2026-09-02 02:36:28 +08:00
Sakurasan 0628d5050f feat: 用量统计页改版,月度汇总支持多指标图表
- 新增 GET /api/usage/monthly?year= 年度按自然月聚合,每月含按模型分解(token 降序)
- 月度汇总改为堆叠柱状图:Token/消费金额/调用次数三指标切换,按模型分色(图例取前 8,其余归入「其他」)
- 选中月份概览卡片(金额/次数/token 分解),点击柱体或图例联动切换
- 年份切换、悬停明细 tooltip、请求明细保留
2026-09-02 02:36:28 +08:00
Sakurasan a376ac0722 feat: add Redis support for distributed passkey sessions
- Implement SessionStore interface for pluggable storage backends
- Add redisStore for distributed environment
- Add memoryStore as fallback for single instance
- Update router to initialize Redis client when configured
- Update .env.example with Redis documentation
2026-09-01 23:03:39 +08:00
Sakurasan 9733b3c20b refactor: restructure passkey with dedicated package
- Create internal/passkey/ package with challenge session management
- Add HTTP handler layer in internal/api/passkey.go
- Simplify Passkey model to use blob credential storage
- Register passkey routes in router
- Update frontend to match new API endpoints
- Add .env.example template
2026-09-01 22:34:44 +08:00
Sakurasan d28fca8ee6 chore: sqlite 默认数据库文件调整为 db/openteam.db,运行时自动创建目录 2026-09-01 21:36:15 +08:00
Sakurasan a2cef00908 fix: 未登录访问管理后台不再闪现页面,路由守卫改为服务端校验
- 守卫先经 /profile 校验 token 有效后才放行受保护路由,无效 token 直接跳登录并带 redirect 回跳
- DashboardLayout 用户信息就绪前只渲染 spinner,不渲染后台内容
- manager 路由增加 requiresAdmin 校验(role >= 10),非管理员重定向回仪表盘
- 401 拦截器改用 router.push 软跳转,避免整页刷新与双重跳转
- pinia 先于 router 安装;登录页支持 redirect 参数回跳原目标
2026-09-01 20:20:05 +08:00
Sakurasan d41bcdc371 修复backend dist文件路径 2026-09-01 17:22:26 +08:00
Sakurasan 8d949eff18 修改图标配色 2026-09-01 15:38:32 +08:00
Sakurasan c65d497551 feat: add docker build commands to Makefile 2026-09-01 15:22:37 +08:00
Sakurasan 19232567f2 chore: 忽略 paseo 任务运行时目录 .pi/ 2026-09-01 03:41:18 +08:00
Sakurasan 20f365d11a fix: 识别上游 HTTP 200 错误体,正确记账并返回 502
问题:OpenRouter 等上游超时时返回 HTTP 200 但响应体/SSE 内含
error 字段(如 {"error":{"code":504}}),网关只检查 StatusCode>=400,
导致:1) 客户端收到假 200 + 空内容;2) 用量被错误记为 success。

修复:
- bufferResponse 检测 JSON 错误体(openai 风格 error / anthropic 风格 type=error),
  识别时以 502 返回给客户端,并向 Dispatch 返回错误码
- streamResponse 扫描 SSE data 载荷中的 error 字段,识别时返回错误码
- Dispatch 对带错误码的响应按失败记账(status=error, error_code=upstream_error),
  不产生费用
2026-09-01 03:31:55 +08:00
Sakurasan 104ecc4691 fix: 原始数据弹窗改为标签页切换,手机友好
- 原始请求/响应不再上下堆叠,改为「请求 / 响应」两个标签页
- 单个内容区(pre 内滚动 + 自动换行),避免手机上需要长距离滚动
- 打开时默认停在有内容的标签(请求优先);仅有一个数据时只显示对应标签
- 弹窗标题补充模型名与协议信息
2026-09-01 03:16:22 +08:00
Sakurasan a259e5eb4d feat: 普通用户用量统计 + 管理后台用量明细
后端
- /api/usage/stats:当前用户按日聚合统计(请求数/输入/输出/缓存 tokens/费用)
- /api/usage/logs:当前用户用量明细分页
- /api/admin/usage/logs:全量明细(分页 + 协议/状态/模型/用户筛选 + 用户名关联)
- /api/admin/usage/summary:全量汇总(按用户分组)
- dao:UsageFilter 支持筛选分页;DailyUsageDAO.ListAll
- 路由加固:新增 middleware.AdminOnly,既有 /api/admin/* 全部迁移到
  带管理员角色校验的分组(此前登录即可访问,属安全隐患)

前端
- 普通用户「用量统计」页:统计卡片 + 纯 CSS 每日请求量条形图 + 明细表格分页
- 管理后台「用量明细」页:汇总卡片 + 协议/状态/模型/用户筛选 +
  明细表格 + 原始请求/响应查看弹窗(记录开关开启时)
- stores/usage.ts 与类型定义;控制台/管理菜单挂载
2026-09-01 02:55:55 +08:00
Sakurasan f9e9a1572f feat: 系统设置新增原始请求/响应记录开关(仅管理员)
- 系统配置键 log_raw_requests:开启后,仅管理员账号的每次请求
  在用量明细中保存客户端原始请求体与上游原始响应体
  (流式含全部 SSE 事件),用于排障
- UsageLog 新增 raw_request / raw_response 字段(type:text)
- AuthLLM 附带 user_role 供网关判断管理员
- gateway:10s TTL 缓存开关;streamResponse/bufferResponse
  支持累积上游原始响应;recordUsage 填充原始字段
- 前端 SystemConfig 新增开关(会显著增加存储的提示)
- 新增 doc/flow.md 网关调用流程示意图
2026-09-01 02:32:31 +08:00
Sakurasan 9f4d631fc4 feat: 网关路由对齐参考实现 + 用量落库 + e2e 全绿
路由与故障转移(参考 openteam 语义)
- channel.Candidates:绑定模型优先(携带 upstream_model 映射),
  未绑定模型回退到权重最低的健康备用渠道;新增 Pick 加权随机与 FilterHealthy 内存健康过滤
- gateway.Dispatch:遍历候选渠道,可重试失败(连接错误/429/5xx)自动故障转移,
  4xx 透传;不再使用单一 SelectChannel
- 修复 gorm default 标签把渠道 weight=0 静默改写为 1 的问题(去掉 default,
  权重 0 语义 = 不参与加权选择,仅作备用承接 unbound 流量)
- RecordFailure 连续 2 次进入 degraded 快速熔断,健康检查成功或冷却过期后复位

网关功能补全
- /v1/models 返回 DB 中启用的模型列表(替换 TODO 存根)
- 请求级 request_id 生成与用量记录接入:流式 SSE 逐块累计 usage、
  非流式从响应提取,按模型定价计算成本后经 usage.Recorder 异步落库
- 流式结束检测:chat 的 [DONE]、messages 的 message_stop、responses 的
  response.completed,避免 keep-alive 上游发完不关连接导致读阻塞到超时
- ResponsesRequest.input 兼容字符串与条目数组两种客户端写法

测试
- 修复 convert_test 对新 input 形态的断言
- 网关 e2e(/tmp/test_gateway.py + mock upstream)72/72 全部通过,连续 3 次稳定
2026-09-01 00:46:05 +08:00
Sakurasan f81b364436 feat: 三协议互转网关 + 鉴权修复 + 管理端增强
后端
- 新增 proxy/convert 三协议(chat/messages/responses)请求、响应与 SSE 流式互转,
  以 Chat 为中间模型;usage.go 统一提取三协议 token 用量(含单测)
- gateway: 跨协议调度(渠道未声明客户端协议时转为渠道首选格式),
  streamResponse 按 \n\n 分块逐行转换直通,bufferResponse 转换失败时剥非 JSON 前缀
- gateway: 新增 SetUsageRecorder 注入异步用量记录器
- auth_llm: 修复 key_prefix 查询长度错配([:8] vs 存储的 [:12])导致全部 401;
  修复长度 8-11 的 key 切片越界 panic;统一 unauthorized 响应
- usage: 日报表改为增量累加 upsert,避免多次 flush 互相清零;记录协议/错误码/时延等字段
- channel: 新增渠道并发槽 TryAcquire;健康检查支持可配置参数
- api: 新增 admin 渠道/模型/系统配置管理端点(旧端点保留兼容)

前端
- 新增渠道管理、模型管理、系统配置视图与 ChannelModelsDrawer
- 新增 ui 基础组件(Button/Badge/Input/Modal)与 protocol.ts
- 调整 Toast 样式、密钥页、路由菜单;dev 代理默认指向 3000 端口
2026-08-31 22:29:09 +08:00
Sakurasan e472ed93d5 交换图表位置 2026-08-30 18:07:04 +08:00
Sakurasan 80ecf38676 fix: responsive Home header buttons for mobile and desktop 2026-08-30 17:57:24 +08:00
Sakurasan 4b845e14fc feat: redesign LineSegmentFlow + dev improvements
- LineSegmentFlow: LobeHub brand icons, concave left curves, glow effects
- Dark mode: line colors adapt, animated lines glow in dark theme
- Vite: enable LAN access (host: 0.0.0.0)
- VSCode: workspace settings for performance optimization
- Toast: redesign with icons, progress bar, better animations
2026-08-30 17:05:41 +08:00
Sakurasan 8f6acb981d 缩短dashboard名称 调整通知样式 2026-08-30 15:53:11 +08:00
Sakurasan 6cc76c6767 chore: add hot reload for development
- Makefile: add dev-backend (air) and dev-frontend (vite) targets
- backend/.air.toml: air config for Go live reload
- .gitignore: exclude backend/tmp/
2026-08-30 15:33:16 +08:00
Sakurasan f3af42a65f chore: upgrade Go version to 1.26
- backend/go.mod: go 1.26
- deploy/docker/Dockerfile: golang:1.26-alpine
- deploy/docker/Dockerfile.cn: golang:1.26-alpine
2026-08-30 15:29:02 +08:00
Sakurasan 094230a293 feat: API key management improvements
- Rename routes: /dashboard/tokens → /dashboard/apikeys, /dashboard/manager/keys → /dashboard/manager/channels
- Add KeyPlain field to store plaintext API keys for re-viewing
- API key list shows masked key (sk-ot-123456****abcd) with eye toggle to reveal
- Copy button with 2s feedback on key list
- TokenNew shows full key + copy after creation
- Increase key prefix display to 12 characters
- Fix SQLite driver: replace gorm.io/driver/sqlite with ncruces/go-sqlite3/gormlite
- Fix user.status === 'active' checks across frontend views
- Add channel store for new channels API
- Update Makefile frontend build to work reliably

BREAKING CHANGE: Existing API keys created before this change will not show their plaintext value (only prefix visible).
2026-08-30 15:21:49 +08:00
Sakurasan 96e4853d6e 移除旧文档 2026-08-30 13:45:29 +08:00
Sakurasan 253e968c9d chore: restore REFACTOR_PLAN.md (frontend refactoring plan) 2026-08-30 12:12:12 +08:00
Sakurasan eadf9525ee chore: clean up unused files
Removed:
- openteam binary from root (use bin/)
- opencatd.db (runtime artifact)
- dist/ (duplicate, already in backend/cmd/openteam/dist/)
- REFACTOR_PLAN.md (superseded by BACKEND_REFACTOR_PLAN.md)
- .pi/ (IDE artifact)

Updated .gitignore for new backend/ paths.
2026-08-30 12:10:23 +08:00
Sakurasan 902ecaeacc refactor: move backend files to backend/ directory
Reorganize project structure:
- backend/cmd/openteam/ — entry point
- backend/internal/ — core packages
- backend/middleware/ — HTTP middleware
- backend/router/ — route setup
- backend/wire/ — dependency injection
- backend/pkg/ — shared utilities
- backend/go.mod, go.sum — Go module files

Updated Makefile to work from backend/ directory.
Removed old lowercase makefile.
2026-08-30 12:02:52 +08:00
Sakurasan ef3025dd80 refactor: complete backend rewrite for multi-protocol proxy
Major rewrite of the Go backend to support:
- Three API format imports: openai, anthropic, compatible
- Three protocol conversions: Chat Completions, Responses, Messages
- Hub-and-spoke architecture with Chat as intermediate format

Deleted:
- opencat.go (old entry)
- store/, team/, pkg/team/, pkg/store/ (old data layer)
- internal/model/, internal/consts/ (old types)
- internal/service/team/, internal/controller/team/ (old handlers)
- llm/ (removed LLM client library, pure proxy mode)
- dist/, assets/ (old build artifacts)

Added:
- internal/store/ — 9 GORM models + multi-DB support
- internal/pkg/ — crypto (AES-GCM), apikey, jwt, ratelimit, resp, tokenizer
- internal/channel/ — channel selection, weighted LB, health checks
- internal/proxy/convert/ — 6 protocol conversion functions + SSE streaming
- internal/proxy/ — gateway with request dispatch and upstream selection
- internal/usage/ — async usage recorder with batch writes
- internal/api/ — management API (auth, users, keys, channels, models)
- Makefile for build/test/deploy

Fixed API to match frontend expectations:
- Login response wraps token in { data: { token } }
- GET /api/profile route added
- Profile response wraps user in { code, data }
- Role returned as number (10=admin, 1=user)
2026-08-30 11:49:31 +08:00
Sakurasan aa0d87f132 fix(proxy): guard nil SupportModels before dereference in setModelCache 2026-08-30 03:16:50 +08:00
Sakurasan 963da99fd6 ci: add multi-arch dev image build script
- deploy/docker/build-dev.sh + make image-dev: linux/amd64+arm64 build & push,
  dev/dev-<sha>/dev-<date> tags, registry inline cache, auto create buildx builder
- PUSH=0 falls back to host-arch build with --load for local verification
- verified end-to-end (PUSH=0): container frontend build, CGO-free cross compile,
  upx pack 31.7MB->11.8MB, image smoke test 200
2026-08-30 02:11:11 +08:00
Sakurasan 33f5e7b71a rewrite: toast stacking with daisyui toast container
- module-level reactive toast list in composables/toast (setToast signature unchanged, 13 call sites untouched)
- multiple toasts stack simultaneously in daisyUI toast container, each auto-dismisses (3s) with close button
- TransitionGroup enter/leave animation (transform/opacity, honors reduced-motion)
- drop provide/inject queue that blocked consecutive toasts
2026-08-30 01:54:57 +08:00
Sakurasan 1e07c5903f redesign: site-wide UI/UX overhaul per web-interface-guidelines
- unified design system: focus-visible rings, reduced-motion, color-scheme,
  theme persistence, tightened emerald radius tokens (checkbox circle bug)
- redesigned all pages: Home/Login/Signup/404, dashboard shell, Overview hero
  (time-based gradient), list pages with empty states, form modals, detail pages
- role-scoped navigation: console menu vs admin console with cross-switch
  entries, Chinese route titles and breadcrumbs
- theme switcher (light/dark/auto) via composables/theme, home + dashboard
- state-driven dropdowns (touch-safe logout), menu divider pointer-events fix
- btn-primary unified to black-on-white / white-on-black per theme
- update REFACTOR_PLAN.md (increments 2-6)
2026-08-30 01:35:10 +08:00
Sakurasan ac0a6808ec refactor: frontend TS migration + Tailwind4/daisyUI5 unify + BUILDPLATFORM docker build
- migrate frontend to TypeScript (vue-tsc strict in build), upgrade all deps to latest (Vite 8, Tailwind 4, daisyUI 5, Pinia 4, vue-router 5)
- restructure frontend dirs (api/components/common/layouts/styles/types/views)
- drop Element Plus, add daisyUI TagInput; main CSS 490KB->163KB, entry JS 618KB->1.3KB
- rewrite Dockerfile(.cn): frontend/backend stages pinned to $BUILDPLATFORM, CGO_ENABLED=0 cross-compile, no QEMU in multi-arch builds; add .dockerignore
- local dev: Vite /api proxy + make dev targets; go:embed all:dist with .gitkeep so backend runs without prior frontend build
- fix latent bugs: Keys.vue users ref, Settings.vue undefined userStore, Login.vue Ref-as-error display, res.error misuse
- add REFACTOR_PLAN.md (phased refactor log)
2026-08-29 23:27:31 +08:00
Sakurasan 4a68ff6162 add claude proxy 2025-07-30 11:18:47 +08:00
Sakurasan 6b2d78fe56 fix:maxTokens 2025-05-04 02:52:04 +08:00
Sakurasan 9c604460b1 fix empty models 2025-04-22 02:52:56 +08:00
Sakurasan 8d34f8d6fe up 2025-04-22 02:16:28 +08:00
Sakurasan 6d1d0f3b6b up 2025-04-22 02:08:32 +08:00
Sakurasan 24529189d9 fix daily usage 2025-04-22 01:50:50 +08:00
Sakurasan 000162b1b1 fix usage 2025-04-22 01:06:03 +08:00
Sakurasan 6662ea5e04 fix record usage 2025-04-22 00:48:24 +08:00
Sakurasan 5789d50e9e update record usage 2025-04-21 23:59:30 +08:00
Sakurasan ca3d89751d fix stream usage 2025-04-21 22:48:28 +08:00
Sakurasan 2bc857cf88 add log 2025-04-21 21:59:13 +08:00
Sakurasan a9ff7e1c94 add log 2025-04-21 21:50:29 +08:00
Sakurasan 51d4651c6c up 2025-04-21 20:19:48 +08:00
Sakurasan e112f3af12 collect usage 2025-04-21 19:10:27 +08:00
Sakurasan 73e53c2333 add models task 2025-04-21 01:40:06 +08:00
Sakurasan 470e49b850 support fetch models 2025-04-21 01:30:17 +08:00
Sakurasan d426781e47 UP 2025-04-20 19:21:51 +08:00
Sakurasan b80f0759a5 fix select key 2025-04-20 18:33:59 +08:00
Sakurasan b83c6d9786 fix active key,suffix 2025-04-20 16:22:23 +08:00
Sakurasan fe0f2a7e88 key icon 2025-04-20 02:59:08 +08:00
Sakurasan ed42f3ded7 fix UI & token copy 2025-04-20 02:03:13 +08:00
Sakurasan 54246c542a up 2025-04-19 01:35:18 +08:00
Sakurasan ca305f4199 fetch model & add apitype 2025-04-19 01:21:28 +08:00
Sakurasan f8e539c9b4 add cli load 2025-04-18 19:05:23 +08:00
Sakurasan e0b531c578 fix passkey 2025-04-18 02:47:10 +08:00
Sakurasan afb51b0a94 remove 2025-04-17 23:56:28 +08:00
Sakurasan 3c4619b98c fix UI 2025-04-17 23:50:02 +08:00
Sakurasan efd38034ac push home 2025-04-17 23:35:03 +08:00
Sakurasan d4bf227cd8 fix UI 2025-04-17 23:15:43 +08:00
Sakurasan fca67cae40 fix UI 2025-04-17 23:09:57 +08:00
Sakurasan 20c3cda4a7 fix bugs 2025-04-17 21:02:00 +08:00
Sakurasan 9045130778 fix findkey 2025-04-17 20:42:08 +08:00
Sakurasan 5403ed0cba fix store bug 2025-04-17 20:15:41 +08:00
Sakurasan 87778326ea fix auth bug 2025-04-17 19:58:46 +08:00
Sakurasan a32a9543e2 fix bug 2025-04-17 18:57:19 +08:00
Sakurasan 9e0c33ad93 fix filepath 2025-04-17 18:38:34 +08:00
Sakurasan c8e565c6a4 fix db path 2025-04-17 02:37:41 +08:00
Sakurasan 9ed162ff0c up 2025-04-17 02:27:46 +08:00
Sakurasan b0d68ba338 fix bugs 2025-04-17 02:17:19 +08:00
Sakurasan d4cbc27a77 fix bug 2025-04-16 23:39:56 +08:00
Sakurasan 2360e7d2bf update baseurl 2025-04-16 19:04:22 +08:00
Sakurasan 81845e3f30 new logo 2025-04-16 18:19:26 +08:00
Sakurasan 15f17f4e8d frontend 2025-04-16 18:14:53 +08:00
Sakurasan ffb4496fd8 remove old frontend 2025-04-16 18:04:53 +08:00
Sakurasan 7bb8f8d012 Merge branch 'dev' into team 2025-04-16 18:02:58 +08:00
Sakurasan e7ffc9e8b9 reface to openteam 2025-04-16 18:01:27 +08:00
Sakurasan 1e00905dcb o3 2025-02-02 00:31:46 +08:00
Sakurasan bc223d6530 team api 2025-02-01 23:52:55 +08:00
Sakurasan 8b5c6feb5e add azure o1 2025-01-01 23:12:05 +08:00
Sakurasan 65d6d12972 refact:openteam 2025-01-01 23:10:01 +08:00
Sakurasan 1f5e1c221c fix: classify chatgpt-4o-latest 2024-12-20 03:49:30 +08:00
Sakurasan 24bac8e38d update: openai struct 2024-12-20 03:25:56 +08:00
Sakurasan fb5b1a55ae update openai struct 2024-12-20 02:42:49 +08:00
Sakurasan 07bcabc5d4 fix: model prefix 2024-12-18 15:58:43 +08:00
Sakurasan 8f6f3313f5 fix: custom_endpoint 2024-12-18 01:08:23 +08:00
Sakurasan f8b364a052 fix: custom_endpoint 2024-12-18 01:00:45 +08:00
Sakurasan 000fc2f616 new claude model 2024-12-12 16:25:35 +08:00
Sakurasan 97887035da update gemini model 2024-12-12 16:13:56 +08:00
Sakurasan fde0e46cbd update gemini model 2024-12-03 16:28:21 +08:00
Sakurasan 5181ba4552 up 2024-11-18 03:52:34 +08:00
Sakurasan 39a81688a9 up 2024-11-18 03:27:54 +08:00
Sakurasan 59063b40e1 up 2024-11-18 03:12:04 +08:00
Sakurasan b7190c6eb5 up 2024-11-18 02:56:48 +08:00
Sakurasan d5d87a9bb0 up 2024-11-18 02:37:15 +08:00
Sakurasan 653b68c644 up 2024-11-18 00:13:54 +08:00
Sakurasan 78e3be4575 update: allow cors 2024-11-17 22:32:14 +08:00
Sakurasan 4b60e17fec remove: action cache 2024-11-17 22:13:29 +08:00