Files
sub2api/frontend/src/components/account/AccountUsageCell.vue

742 lines
25 KiB
Vue
Raw Normal View History

2025-12-18 13:50:39 +08:00
<template>
2025-12-22 22:58:31 +08:00
<div v-if="showUsageWindows">
<!-- Anthropic OAuth and Setup Token accounts: fetch real usage data -->
<template
v-if="
account.platform === 'anthropic' &&
(account.type === 'oauth' || account.type === 'setup-token')
"
>
2025-12-18 13:50:39 +08:00
<!-- Loading state -->
<div v-if="loading" class="space-y-1.5">
<!-- OAuth: 3 rows, Setup Token: 1 row -->
2025-12-18 13:50:39 +08:00
<div class="flex items-center gap-1">
<div class="h-3 w-[32px] animate-pulse rounded bg-gray-200 dark:bg-gray-700"></div>
<div class="h-1.5 w-8 animate-pulse rounded-full bg-gray-200 dark:bg-gray-700"></div>
<div class="h-3 w-[32px] animate-pulse rounded bg-gray-200 dark:bg-gray-700"></div>
2025-12-18 13:50:39 +08:00
</div>
<template v-if="account.type === 'oauth'">
<div class="flex items-center gap-1">
<div class="h-3 w-[32px] animate-pulse rounded bg-gray-200 dark:bg-gray-700"></div>
<div class="h-1.5 w-8 animate-pulse rounded-full bg-gray-200 dark:bg-gray-700"></div>
<div class="h-3 w-[32px] animate-pulse rounded bg-gray-200 dark:bg-gray-700"></div>
</div>
<div class="flex items-center gap-1">
<div class="h-3 w-[32px] animate-pulse rounded bg-gray-200 dark:bg-gray-700"></div>
<div class="h-1.5 w-8 animate-pulse rounded-full bg-gray-200 dark:bg-gray-700"></div>
<div class="h-3 w-[32px] animate-pulse rounded bg-gray-200 dark:bg-gray-700"></div>
</div>
</template>
2025-12-18 13:50:39 +08:00
</div>
<!-- Error state -->
<div v-else-if="error" class="text-xs text-red-500">
{{ error }}
</div>
<!-- Usage data -->
<div v-else-if="usageInfo" class="space-y-1">
<!-- 5h Window -->
<UsageProgressBar
v-if="usageInfo.five_hour"
label="5h"
:utilization="usageInfo.five_hour.utilization"
:resets-at="usageInfo.five_hour.resets_at"
:window-stats="usageInfo.five_hour.window_stats"
color="indigo"
/>
<!-- 7d Window (OAuth only) -->
2025-12-18 13:50:39 +08:00
<UsageProgressBar
v-if="usageInfo.seven_day"
label="7d"
:utilization="usageInfo.seven_day.utilization"
:resets-at="usageInfo.seven_day.resets_at"
color="emerald"
/>
<!-- 7d Sonnet Window (OAuth only) -->
2025-12-18 13:50:39 +08:00
<UsageProgressBar
v-if="usageInfo.seven_day_sonnet"
label="7d S"
:utilization="usageInfo.seven_day_sonnet.utilization"
:resets-at="usageInfo.seven_day_sonnet.resets_at"
color="purple"
/>
</div>
<!-- No data yet -->
<div v-else class="text-xs text-gray-400">-</div>
2025-12-18 13:50:39 +08:00
</template>
<!-- OpenAI OAuth accounts: show Codex usage from extra field -->
<template v-else-if="account.platform === 'openai' && account.type === 'oauth'">
<div v-if="hasCodexUsage" class="space-y-1">
fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 (#30) * fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 问题描述: - 账号管理页面中,OpenAI OAuth 账号的 5h 列显示 7 天的剩余时间 - 7d 列却显示几小时的剩余时间 - 根本原因: OpenAI 响应头中 primary/secondary 的实际含义与代码假设相反 修复方案: 1. 后端归一化 (openai_gateway_service.go): - 根据 window_minutes 动态判断哪个是 5h/7d 限制 - 新增规范字段 codex_5h_* 和 codex_7d_* - 保留旧字段以兼容性 2. 前端适配 (AccountUsageCell.vue): - 优先使用新的规范字段 - Fallback 到旧字段时基于 window_minutes 动态判断 - 更新 computed 属性命名 3. 类型定义更新 (types/index.ts): - 添加新的规范字段定义 - 更新注释说明实际语义由 window_minutes 决定 🤖 Generated with Claude Code and Codex collaboration Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Co-Authored-By: OpenAI Codex <noreply@openai.com> * fix: 改进窗口判断逻辑,修复两个窗口都小于阈值时的bug 问题: 当两个窗口都小于360分钟时(如 primary=180分钟,secondary=300分钟), 之前的逻辑会导致: - primary5h = true, secondary5h = true - 5h 字段会使用 primary(错误) - 7d 字段没有数据(bug) 修复方案: 改用比较策略: 1. 当两个窗口都存在时:较小的分配给5h,较大的分配给7d 2. 当只有一个窗口时:根据大小(<=360分钟)判断是5h还是7d 3. 确保数据不会丢失,逻辑更健壮 示例: - Primary: 180分钟, Secondary: 300分钟 → 5h 使用 Primary(180分钟), 7d 使用 Secondary(300分钟) ✓ 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修正窗口大小判断逻辑 - 不能用剩余时间判断窗口类型 **严重bug修复:** 之前的 fallback 逻辑错误地使用 reset_after_seconds 来判断窗口大小。 问题示例: - 周限制(7d)剩余 2h → reset_after_seconds = 7200秒 - 5h限制 剩余 4h → reset_after_seconds = 14400秒 - 错误逻辑:7200/60 < 14400/60,把周限制当成5h ❌ 根本问题: - window_minutes = 窗口的总大小(300 or 10080) - reset_after_seconds = 距离重置的剩余时间(变化的) - 不能用剩余时间来判断窗口类型! 修复方案: 1. **只使用 window_minutes** 来判断窗口大小 2. 移除错误的 reset_after_seconds fallback 3. 如果 window_minutes 都不存在,使用传统假设 4. 添加详细注释说明这个陷阱 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修复 lint 问题 - 改进 fallback 逻辑的变量赋值 问题: 第882-883行的简单布尔赋值可能触发 ineffassign 或 staticcheck 警告: use5hFromSecondary = snapshot.SecondaryUsedPercent != nil use7dFromPrimary = snapshot.PrimaryUsedPercent != nil 修复: 改用明确的 if 语句检查任意字段是否存在,更符合代码意图: - 如果 secondary 的任意字段存在,将其视为 5h - 如果 primary 的任意字段存在,将其视为 7d 这样逻辑更清晰,也避免了 lint 警告。 --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com> Co-authored-by: OpenAI Codex <noreply@openai.com>
2025-12-25 17:00:02 +08:00
<!-- 5h Window -->
<UsageProgressBar
fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 (#30) * fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 问题描述: - 账号管理页面中,OpenAI OAuth 账号的 5h 列显示 7 天的剩余时间 - 7d 列却显示几小时的剩余时间 - 根本原因: OpenAI 响应头中 primary/secondary 的实际含义与代码假设相反 修复方案: 1. 后端归一化 (openai_gateway_service.go): - 根据 window_minutes 动态判断哪个是 5h/7d 限制 - 新增规范字段 codex_5h_* 和 codex_7d_* - 保留旧字段以兼容性 2. 前端适配 (AccountUsageCell.vue): - 优先使用新的规范字段 - Fallback 到旧字段时基于 window_minutes 动态判断 - 更新 computed 属性命名 3. 类型定义更新 (types/index.ts): - 添加新的规范字段定义 - 更新注释说明实际语义由 window_minutes 决定 🤖 Generated with Claude Code and Codex collaboration Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Co-Authored-By: OpenAI Codex <noreply@openai.com> * fix: 改进窗口判断逻辑,修复两个窗口都小于阈值时的bug 问题: 当两个窗口都小于360分钟时(如 primary=180分钟,secondary=300分钟), 之前的逻辑会导致: - primary5h = true, secondary5h = true - 5h 字段会使用 primary(错误) - 7d 字段没有数据(bug) 修复方案: 改用比较策略: 1. 当两个窗口都存在时:较小的分配给5h,较大的分配给7d 2. 当只有一个窗口时:根据大小(<=360分钟)判断是5h还是7d 3. 确保数据不会丢失,逻辑更健壮 示例: - Primary: 180分钟, Secondary: 300分钟 → 5h 使用 Primary(180分钟), 7d 使用 Secondary(300分钟) ✓ 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修正窗口大小判断逻辑 - 不能用剩余时间判断窗口类型 **严重bug修复:** 之前的 fallback 逻辑错误地使用 reset_after_seconds 来判断窗口大小。 问题示例: - 周限制(7d)剩余 2h → reset_after_seconds = 7200秒 - 5h限制 剩余 4h → reset_after_seconds = 14400秒 - 错误逻辑:7200/60 < 14400/60,把周限制当成5h ❌ 根本问题: - window_minutes = 窗口的总大小(300 or 10080) - reset_after_seconds = 距离重置的剩余时间(变化的) - 不能用剩余时间来判断窗口类型! 修复方案: 1. **只使用 window_minutes** 来判断窗口大小 2. 移除错误的 reset_after_seconds fallback 3. 如果 window_minutes 都不存在,使用传统假设 4. 添加详细注释说明这个陷阱 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修复 lint 问题 - 改进 fallback 逻辑的变量赋值 问题: 第882-883行的简单布尔赋值可能触发 ineffassign 或 staticcheck 警告: use5hFromSecondary = snapshot.SecondaryUsedPercent != nil use7dFromPrimary = snapshot.PrimaryUsedPercent != nil 修复: 改用明确的 if 语句检查任意字段是否存在,更符合代码意图: - 如果 secondary 的任意字段存在,将其视为 5h - 如果 primary 的任意字段存在,将其视为 7d 这样逻辑更清晰,也避免了 lint 警告。 --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com> Co-authored-by: OpenAI Codex <noreply@openai.com>
2025-12-25 17:00:02 +08:00
v-if="codex5hUsedPercent !== null"
label="5h"
fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 (#30) * fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 问题描述: - 账号管理页面中,OpenAI OAuth 账号的 5h 列显示 7 天的剩余时间 - 7d 列却显示几小时的剩余时间 - 根本原因: OpenAI 响应头中 primary/secondary 的实际含义与代码假设相反 修复方案: 1. 后端归一化 (openai_gateway_service.go): - 根据 window_minutes 动态判断哪个是 5h/7d 限制 - 新增规范字段 codex_5h_* 和 codex_7d_* - 保留旧字段以兼容性 2. 前端适配 (AccountUsageCell.vue): - 优先使用新的规范字段 - Fallback 到旧字段时基于 window_minutes 动态判断 - 更新 computed 属性命名 3. 类型定义更新 (types/index.ts): - 添加新的规范字段定义 - 更新注释说明实际语义由 window_minutes 决定 🤖 Generated with Claude Code and Codex collaboration Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Co-Authored-By: OpenAI Codex <noreply@openai.com> * fix: 改进窗口判断逻辑,修复两个窗口都小于阈值时的bug 问题: 当两个窗口都小于360分钟时(如 primary=180分钟,secondary=300分钟), 之前的逻辑会导致: - primary5h = true, secondary5h = true - 5h 字段会使用 primary(错误) - 7d 字段没有数据(bug) 修复方案: 改用比较策略: 1. 当两个窗口都存在时:较小的分配给5h,较大的分配给7d 2. 当只有一个窗口时:根据大小(<=360分钟)判断是5h还是7d 3. 确保数据不会丢失,逻辑更健壮 示例: - Primary: 180分钟, Secondary: 300分钟 → 5h 使用 Primary(180分钟), 7d 使用 Secondary(300分钟) ✓ 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修正窗口大小判断逻辑 - 不能用剩余时间判断窗口类型 **严重bug修复:** 之前的 fallback 逻辑错误地使用 reset_after_seconds 来判断窗口大小。 问题示例: - 周限制(7d)剩余 2h → reset_after_seconds = 7200秒 - 5h限制 剩余 4h → reset_after_seconds = 14400秒 - 错误逻辑:7200/60 < 14400/60,把周限制当成5h ❌ 根本问题: - window_minutes = 窗口的总大小(300 or 10080) - reset_after_seconds = 距离重置的剩余时间(变化的) - 不能用剩余时间来判断窗口类型! 修复方案: 1. **只使用 window_minutes** 来判断窗口大小 2. 移除错误的 reset_after_seconds fallback 3. 如果 window_minutes 都不存在,使用传统假设 4. 添加详细注释说明这个陷阱 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修复 lint 问题 - 改进 fallback 逻辑的变量赋值 问题: 第882-883行的简单布尔赋值可能触发 ineffassign 或 staticcheck 警告: use5hFromSecondary = snapshot.SecondaryUsedPercent != nil use7dFromPrimary = snapshot.PrimaryUsedPercent != nil 修复: 改用明确的 if 语句检查任意字段是否存在,更符合代码意图: - 如果 secondary 的任意字段存在,将其视为 5h - 如果 primary 的任意字段存在,将其视为 7d 这样逻辑更清晰,也避免了 lint 警告。 --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com> Co-authored-by: OpenAI Codex <noreply@openai.com>
2025-12-25 17:00:02 +08:00
:utilization="codex5hUsedPercent"
:resets-at="codex5hResetAt"
color="indigo"
/>
fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 (#30) * fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 问题描述: - 账号管理页面中,OpenAI OAuth 账号的 5h 列显示 7 天的剩余时间 - 7d 列却显示几小时的剩余时间 - 根本原因: OpenAI 响应头中 primary/secondary 的实际含义与代码假设相反 修复方案: 1. 后端归一化 (openai_gateway_service.go): - 根据 window_minutes 动态判断哪个是 5h/7d 限制 - 新增规范字段 codex_5h_* 和 codex_7d_* - 保留旧字段以兼容性 2. 前端适配 (AccountUsageCell.vue): - 优先使用新的规范字段 - Fallback 到旧字段时基于 window_minutes 动态判断 - 更新 computed 属性命名 3. 类型定义更新 (types/index.ts): - 添加新的规范字段定义 - 更新注释说明实际语义由 window_minutes 决定 🤖 Generated with Claude Code and Codex collaboration Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Co-Authored-By: OpenAI Codex <noreply@openai.com> * fix: 改进窗口判断逻辑,修复两个窗口都小于阈值时的bug 问题: 当两个窗口都小于360分钟时(如 primary=180分钟,secondary=300分钟), 之前的逻辑会导致: - primary5h = true, secondary5h = true - 5h 字段会使用 primary(错误) - 7d 字段没有数据(bug) 修复方案: 改用比较策略: 1. 当两个窗口都存在时:较小的分配给5h,较大的分配给7d 2. 当只有一个窗口时:根据大小(<=360分钟)判断是5h还是7d 3. 确保数据不会丢失,逻辑更健壮 示例: - Primary: 180分钟, Secondary: 300分钟 → 5h 使用 Primary(180分钟), 7d 使用 Secondary(300分钟) ✓ 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修正窗口大小判断逻辑 - 不能用剩余时间判断窗口类型 **严重bug修复:** 之前的 fallback 逻辑错误地使用 reset_after_seconds 来判断窗口大小。 问题示例: - 周限制(7d)剩余 2h → reset_after_seconds = 7200秒 - 5h限制 剩余 4h → reset_after_seconds = 14400秒 - 错误逻辑:7200/60 < 14400/60,把周限制当成5h ❌ 根本问题: - window_minutes = 窗口的总大小(300 or 10080) - reset_after_seconds = 距离重置的剩余时间(变化的) - 不能用剩余时间来判断窗口类型! 修复方案: 1. **只使用 window_minutes** 来判断窗口大小 2. 移除错误的 reset_after_seconds fallback 3. 如果 window_minutes 都不存在,使用传统假设 4. 添加详细注释说明这个陷阱 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修复 lint 问题 - 改进 fallback 逻辑的变量赋值 问题: 第882-883行的简单布尔赋值可能触发 ineffassign 或 staticcheck 警告: use5hFromSecondary = snapshot.SecondaryUsedPercent != nil use7dFromPrimary = snapshot.PrimaryUsedPercent != nil 修复: 改用明确的 if 语句检查任意字段是否存在,更符合代码意图: - 如果 secondary 的任意字段存在,将其视为 5h - 如果 primary 的任意字段存在,将其视为 7d 这样逻辑更清晰,也避免了 lint 警告。 --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com> Co-authored-by: OpenAI Codex <noreply@openai.com>
2025-12-25 17:00:02 +08:00
<!-- 7d Window -->
<UsageProgressBar
fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 (#30) * fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 问题描述: - 账号管理页面中,OpenAI OAuth 账号的 5h 列显示 7 天的剩余时间 - 7d 列却显示几小时的剩余时间 - 根本原因: OpenAI 响应头中 primary/secondary 的实际含义与代码假设相反 修复方案: 1. 后端归一化 (openai_gateway_service.go): - 根据 window_minutes 动态判断哪个是 5h/7d 限制 - 新增规范字段 codex_5h_* 和 codex_7d_* - 保留旧字段以兼容性 2. 前端适配 (AccountUsageCell.vue): - 优先使用新的规范字段 - Fallback 到旧字段时基于 window_minutes 动态判断 - 更新 computed 属性命名 3. 类型定义更新 (types/index.ts): - 添加新的规范字段定义 - 更新注释说明实际语义由 window_minutes 决定 🤖 Generated with Claude Code and Codex collaboration Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Co-Authored-By: OpenAI Codex <noreply@openai.com> * fix: 改进窗口判断逻辑,修复两个窗口都小于阈值时的bug 问题: 当两个窗口都小于360分钟时(如 primary=180分钟,secondary=300分钟), 之前的逻辑会导致: - primary5h = true, secondary5h = true - 5h 字段会使用 primary(错误) - 7d 字段没有数据(bug) 修复方案: 改用比较策略: 1. 当两个窗口都存在时:较小的分配给5h,较大的分配给7d 2. 当只有一个窗口时:根据大小(<=360分钟)判断是5h还是7d 3. 确保数据不会丢失,逻辑更健壮 示例: - Primary: 180分钟, Secondary: 300分钟 → 5h 使用 Primary(180分钟), 7d 使用 Secondary(300分钟) ✓ 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修正窗口大小判断逻辑 - 不能用剩余时间判断窗口类型 **严重bug修复:** 之前的 fallback 逻辑错误地使用 reset_after_seconds 来判断窗口大小。 问题示例: - 周限制(7d)剩余 2h → reset_after_seconds = 7200秒 - 5h限制 剩余 4h → reset_after_seconds = 14400秒 - 错误逻辑:7200/60 < 14400/60,把周限制当成5h ❌ 根本问题: - window_minutes = 窗口的总大小(300 or 10080) - reset_after_seconds = 距离重置的剩余时间(变化的) - 不能用剩余时间来判断窗口类型! 修复方案: 1. **只使用 window_minutes** 来判断窗口大小 2. 移除错误的 reset_after_seconds fallback 3. 如果 window_minutes 都不存在,使用传统假设 4. 添加详细注释说明这个陷阱 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修复 lint 问题 - 改进 fallback 逻辑的变量赋值 问题: 第882-883行的简单布尔赋值可能触发 ineffassign 或 staticcheck 警告: use5hFromSecondary = snapshot.SecondaryUsedPercent != nil use7dFromPrimary = snapshot.PrimaryUsedPercent != nil 修复: 改用明确的 if 语句检查任意字段是否存在,更符合代码意图: - 如果 secondary 的任意字段存在,将其视为 5h - 如果 primary 的任意字段存在,将其视为 7d 这样逻辑更清晰,也避免了 lint 警告。 --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com> Co-authored-by: OpenAI Codex <noreply@openai.com>
2025-12-25 17:00:02 +08:00
v-if="codex7dUsedPercent !== null"
label="7d"
fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 (#30) * fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 问题描述: - 账号管理页面中,OpenAI OAuth 账号的 5h 列显示 7 天的剩余时间 - 7d 列却显示几小时的剩余时间 - 根本原因: OpenAI 响应头中 primary/secondary 的实际含义与代码假设相反 修复方案: 1. 后端归一化 (openai_gateway_service.go): - 根据 window_minutes 动态判断哪个是 5h/7d 限制 - 新增规范字段 codex_5h_* 和 codex_7d_* - 保留旧字段以兼容性 2. 前端适配 (AccountUsageCell.vue): - 优先使用新的规范字段 - Fallback 到旧字段时基于 window_minutes 动态判断 - 更新 computed 属性命名 3. 类型定义更新 (types/index.ts): - 添加新的规范字段定义 - 更新注释说明实际语义由 window_minutes 决定 🤖 Generated with Claude Code and Codex collaboration Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Co-Authored-By: OpenAI Codex <noreply@openai.com> * fix: 改进窗口判断逻辑,修复两个窗口都小于阈值时的bug 问题: 当两个窗口都小于360分钟时(如 primary=180分钟,secondary=300分钟), 之前的逻辑会导致: - primary5h = true, secondary5h = true - 5h 字段会使用 primary(错误) - 7d 字段没有数据(bug) 修复方案: 改用比较策略: 1. 当两个窗口都存在时:较小的分配给5h,较大的分配给7d 2. 当只有一个窗口时:根据大小(<=360分钟)判断是5h还是7d 3. 确保数据不会丢失,逻辑更健壮 示例: - Primary: 180分钟, Secondary: 300分钟 → 5h 使用 Primary(180分钟), 7d 使用 Secondary(300分钟) ✓ 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修正窗口大小判断逻辑 - 不能用剩余时间判断窗口类型 **严重bug修复:** 之前的 fallback 逻辑错误地使用 reset_after_seconds 来判断窗口大小。 问题示例: - 周限制(7d)剩余 2h → reset_after_seconds = 7200秒 - 5h限制 剩余 4h → reset_after_seconds = 14400秒 - 错误逻辑:7200/60 < 14400/60,把周限制当成5h ❌ 根本问题: - window_minutes = 窗口的总大小(300 or 10080) - reset_after_seconds = 距离重置的剩余时间(变化的) - 不能用剩余时间来判断窗口类型! 修复方案: 1. **只使用 window_minutes** 来判断窗口大小 2. 移除错误的 reset_after_seconds fallback 3. 如果 window_minutes 都不存在,使用传统假设 4. 添加详细注释说明这个陷阱 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修复 lint 问题 - 改进 fallback 逻辑的变量赋值 问题: 第882-883行的简单布尔赋值可能触发 ineffassign 或 staticcheck 警告: use5hFromSecondary = snapshot.SecondaryUsedPercent != nil use7dFromPrimary = snapshot.PrimaryUsedPercent != nil 修复: 改用明确的 if 语句检查任意字段是否存在,更符合代码意图: - 如果 secondary 的任意字段存在,将其视为 5h - 如果 primary 的任意字段存在,将其视为 7d 这样逻辑更清晰,也避免了 lint 警告。 --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com> Co-authored-by: OpenAI Codex <noreply@openai.com>
2025-12-25 17:00:02 +08:00
:utilization="codex7dUsedPercent"
:resets-at="codex7dResetAt"
color="emerald"
/>
</div>
<div v-else class="text-xs text-gray-400">-</div>
</template>
<!-- Antigravity OAuth accounts: fetch usage from API -->
<template v-else-if="account.platform === 'antigravity' && account.type === 'oauth'">
<!-- 账户类型徽章 -->
<div v-if="antigravityTierLabel" class="mb-1 flex items-center gap-1">
<span
:class="[
'inline-block rounded px-1.5 py-0.5 text-[10px] font-medium',
antigravityTierClass
]"
>
{{ antigravityTierLabel }}
</span>
<!-- 不合格账户警告图标 -->
<span
v-if="hasIneligibleTiers"
class="group relative cursor-help"
>
<svg
class="h-3.5 w-3.5 text-red-500"
fill="currentColor"
viewBox="0 0 20 20"
>
<path
fill-rule="evenodd"
d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z"
clip-rule="evenodd"
/>
</svg>
<span
class="pointer-events-none absolute left-0 top-full z-50 mt-1 w-80 whitespace-normal break-words rounded bg-gray-900 px-3 py-2 text-xs leading-relaxed text-white opacity-0 shadow-lg transition-opacity group-hover:opacity-100 dark:bg-gray-700"
>
{{ t('admin.accounts.ineligibleWarning') }}
</span>
</span>
</div>
<!-- Loading state -->
<div v-if="loading" class="space-y-1.5">
<div class="flex items-center gap-1">
<div class="h-3 w-[32px] animate-pulse rounded bg-gray-200 dark:bg-gray-700"></div>
<div class="h-1.5 w-8 animate-pulse rounded-full bg-gray-200 dark:bg-gray-700"></div>
<div class="h-3 w-[32px] animate-pulse rounded bg-gray-200 dark:bg-gray-700"></div>
</div>
</div>
<!-- Error state -->
<div v-else-if="error" class="text-xs text-red-500">
{{ error }}
</div>
<!-- Usage data from API -->
<div v-else-if="hasAntigravityQuotaFromAPI" class="space-y-1">
<!-- Gemini 3 Pro -->
<UsageProgressBar
v-if="antigravity3ProUsageFromAPI !== null"
:label="t('admin.accounts.usageWindow.gemini3Pro')"
:utilization="antigravity3ProUsageFromAPI.utilization"
:resets-at="antigravity3ProUsageFromAPI.resetTime"
color="indigo"
/>
<!-- Gemini 3 Flash -->
<UsageProgressBar
v-if="antigravity3FlashUsageFromAPI !== null"
:label="t('admin.accounts.usageWindow.gemini3Flash')"
:utilization="antigravity3FlashUsageFromAPI.utilization"
:resets-at="antigravity3FlashUsageFromAPI.resetTime"
color="emerald"
/>
<!-- Gemini 3 Image -->
<UsageProgressBar
v-if="antigravity3ImageUsageFromAPI !== null"
:label="t('admin.accounts.usageWindow.gemini3Image')"
:utilization="antigravity3ImageUsageFromAPI.utilization"
:resets-at="antigravity3ImageUsageFromAPI.resetTime"
color="purple"
/>
<!-- Claude 4.5 -->
<UsageProgressBar
v-if="antigravityClaude45UsageFromAPI !== null"
:label="t('admin.accounts.usageWindow.claude45')"
:utilization="antigravityClaude45UsageFromAPI.utilization"
:resets-at="antigravityClaude45UsageFromAPI.resetTime"
color="amber"
/>
</div>
<div v-else class="text-xs text-gray-400">-</div>
</template>
<!-- Gemini platform: show quota + local usage window -->
<template v-else-if="account.platform === 'gemini'">
<!-- Auth Type + Tier Badge (first line) -->
<div v-if="geminiAuthTypeLabel" class="mb-1 flex items-center gap-1">
<span
:class="[
'inline-block rounded px-1.5 py-0.5 text-[10px] font-medium',
geminiTierClass
]"
>
{{ geminiAuthTypeLabel }}
</span>
<!-- Help icon -->
<span
class="group relative cursor-help"
>
<svg
class="h-3.5 w-3.5 text-gray-400 hover:text-gray-600 dark:text-gray-500 dark:hover:text-gray-300"
fill="currentColor"
viewBox="0 0 20 20"
>
<path
fill-rule="evenodd"
d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-8-3a1 1 0 00-.867.5 1 1 0 11-1.731-1A3 3 0 0113 8a3.001 3.001 0 01-2 2.83V11a1 1 0 11-2 0v-1a1 1 0 011-1 1 1 0 100-2zm0 8a1 1 0 100-2 1 1 0 000 2z"
clip-rule="evenodd"
/>
</svg>
<span
class="pointer-events-none absolute left-0 top-full z-50 mt-1 w-80 whitespace-normal break-words rounded bg-gray-900 px-3 py-2 text-xs leading-relaxed text-white opacity-0 shadow-lg transition-opacity group-hover:opacity-100 dark:bg-gray-700"
>
<div class="font-semibold mb-1">{{ t('admin.accounts.gemini.quotaPolicy.title') }}</div>
<div class="mb-2 text-gray-300">{{ t('admin.accounts.gemini.quotaPolicy.note') }}</div>
<div class="space-y-1">
<div><strong>{{ geminiQuotaPolicyChannel }}:</strong></div>
<div class="pl-2"> {{ geminiQuotaPolicyLimits }}</div>
<div class="mt-2">
<a :href="geminiQuotaPolicyDocsUrl" target="_blank" rel="noopener noreferrer" class="text-blue-400 hover:text-blue-300 underline">
{{ t('admin.accounts.gemini.quotaPolicy.columns.docs') }}
</a>
</div>
</div>
</span>
</span>
</div>
<!-- Usage data or unlimited flow -->
<div class="space-y-1">
<div v-if="loading" class="space-y-1">
<div class="flex items-center gap-1">
<div class="h-3 w-[32px] animate-pulse rounded bg-gray-200 dark:bg-gray-700"></div>
<div class="h-1.5 w-8 animate-pulse rounded-full bg-gray-200 dark:bg-gray-700"></div>
<div class="h-3 w-[32px] animate-pulse rounded bg-gray-200 dark:bg-gray-700"></div>
</div>
</div>
<div v-else-if="error" class="text-xs text-red-500">
{{ error }}
</div>
<!-- Code Assist: show model usage bars -->
<div v-else-if="isGeminiCodeAssist && geminiUsageAvailable" class="space-y-1">
<UsageProgressBar
v-if="usageInfo?.gemini_pro_daily"
label="Pro"
:utilization="usageInfo.gemini_pro_daily.utilization"
:resets-at="usageInfo.gemini_pro_daily.resets_at"
:window-stats="usageInfo.gemini_pro_daily.window_stats"
color="indigo"
/>
<UsageProgressBar
v-if="usageInfo?.gemini_flash_daily"
label="Flash"
:utilization="usageInfo.gemini_flash_daily.utilization"
:resets-at="usageInfo.gemini_flash_daily.resets_at"
:window-stats="usageInfo.gemini_flash_daily.window_stats"
color="emerald"
/>
<p class="mt-1 text-[9px] leading-tight text-gray-400 dark:text-gray-500 italic">
* {{ t('admin.accounts.gemini.quotaPolicy.simulatedNote') || 'Simulated quota' }}
</p>
</div>
<!-- AI Studio & Google One: show unlimited flow -->
<div v-else class="text-xs text-gray-400">
{{ t('admin.accounts.gemini.rateLimit.unlimited') }}
</div>
</div>
</template>
<!-- Other accounts: no usage window -->
2025-12-22 22:58:31 +08:00
<template v-else>
<div class="text-xs text-gray-400">-</div>
</template>
2025-12-18 13:50:39 +08:00
</div>
2025-12-22 22:58:31 +08:00
<!-- Non-OAuth/Setup-Token accounts -->
<div v-else>
<!-- Gemini API Key accounts: show quota info -->
<AccountQuotaInfo v-if="account.platform === 'gemini'" :account="account" />
<div v-else class="text-xs text-gray-400">-</div>
</div>
2025-12-18 13:50:39 +08:00
</template>
<script setup lang="ts">
2025-12-22 22:58:31 +08:00
import { ref, computed, onMounted } from 'vue'
feat(frontend): 前端界面优化与使用统计功能增强 (#46) * feat(frontend): 前端界面优化与使用统计功能增强 主要改动: 1. 表格布局统一优化 - 新增 TablePageLayout 通用布局组件 - 统一所有管理页面的表格样式和交互 - 优化 DataTable、Pagination、Select 等通用组件 2. 使用统计功能增强 - 管理端: 添加完整的筛选和显示功能 - 用户端: 完善 API Key 列显示 - 后端: 优化使用统计数据结构和查询 3. 账户组件优化 - 优化 AccountStatsModal、AccountUsageCell 等组件 - 统一进度条和统计显示样式 4. 其他改进 - 完善中英文国际化 - 统一页面样式和交互体验 - 优化各视图页面的响应式布局 * fix(test): 修复 stubUsageLogRepo.ListWithFilters 测试 stub 测试用例 GET /api/v1/usage 返回 500 是因为 stub 方法未实现, 现在正确返回基于 UserID 过滤的日志数据。 * feat(frontend): 统一日期时间显示格式 **主要改动**: 1. 增强 utils/format.ts: - 新增 formatDateOnly() - 格式: YYYY-MM-DD - 新增 formatDateTime() - 格式: YYYY-MM-DD HH:mm:ss 2. 全局替换视图中的格式化函数: - 移除各视图中的自定义 formatDate 函数 - 统一导入使用 @/utils/format 中的函数 - created_at/updated_at 使用 formatDateTime - expires_at 使用 formatDateOnly 3. 受影响的视图 (8个): - frontend/src/views/user/KeysView.vue - frontend/src/views/user/DashboardView.vue - frontend/src/views/user/UsageView.vue - frontend/src/views/user/RedeemView.vue - frontend/src/views/admin/UsersView.vue - frontend/src/views/admin/UsageView.vue - frontend/src/views/admin/RedeemView.vue - frontend/src/views/admin/SubscriptionsView.vue **效果**: - 日期统一显示为 YYYY-MM-DD - 时间统一显示为 YYYY-MM-DD HH:mm:ss - 提升可维护性,避免格式不一致 * fix(frontend): 补充遗漏的时间格式化统一 **补充修复**(基于 code review 发现的遗漏): 1. 增强 utils/format.ts: - 新增 formatTime() - 格式: HH:mm 2. 修复 4 个遗漏的文件: - src/views/admin/UsersView.vue * 删除 formatExpiresAt(),改用 formatDateTime() * 修复订阅过期时间 tooltip 显示格式不一致问题 - src/views/user/ProfileView.vue * 删除 formatMemberSince(),改用 formatDate(date, 'YYYY-MM') * 统一会员起始时间显示格式 - src/views/user/SubscriptionsView.vue * 修改 formatExpirationDate() 使用 formatDateOnly() * 保留天数计算逻辑 - src/components/account/AccountStatusIndicator.vue * 删除本地 formatTime(),改用 utils/format 中的统一函数 * 修复 rate limit 和 overload 重置时间显示 **验证**: - TypeScript 类型检查通过 ✓ - 前端构建成功 ✓ - 所有剩余的 toLocaleString() 都是数字格式化,属于正确用法 ✓ **效果**: - 订阅过期时间统一为 YYYY-MM-DD HH:mm:ss - 会员起始时间统一为 YYYY-MM - 重置时间统一为 HH:mm - 消除所有不规范的原生 locale 方法调用
2025-12-27 10:50:25 +08:00
import { useI18n } from 'vue-i18n'
2025-12-18 13:50:39 +08:00
import { adminAPI } from '@/api/admin'
import type { Account, AccountUsageInfo, GeminiCredentials } from '@/types'
2025-12-18 13:50:39 +08:00
import UsageProgressBar from './UsageProgressBar.vue'
import AccountQuotaInfo from './AccountQuotaInfo.vue'
2025-12-18 13:50:39 +08:00
const props = defineProps<{
account: Account
}>()
feat(frontend): 前端界面优化与使用统计功能增强 (#46) * feat(frontend): 前端界面优化与使用统计功能增强 主要改动: 1. 表格布局统一优化 - 新增 TablePageLayout 通用布局组件 - 统一所有管理页面的表格样式和交互 - 优化 DataTable、Pagination、Select 等通用组件 2. 使用统计功能增强 - 管理端: 添加完整的筛选和显示功能 - 用户端: 完善 API Key 列显示 - 后端: 优化使用统计数据结构和查询 3. 账户组件优化 - 优化 AccountStatsModal、AccountUsageCell 等组件 - 统一进度条和统计显示样式 4. 其他改进 - 完善中英文国际化 - 统一页面样式和交互体验 - 优化各视图页面的响应式布局 * fix(test): 修复 stubUsageLogRepo.ListWithFilters 测试 stub 测试用例 GET /api/v1/usage 返回 500 是因为 stub 方法未实现, 现在正确返回基于 UserID 过滤的日志数据。 * feat(frontend): 统一日期时间显示格式 **主要改动**: 1. 增强 utils/format.ts: - 新增 formatDateOnly() - 格式: YYYY-MM-DD - 新增 formatDateTime() - 格式: YYYY-MM-DD HH:mm:ss 2. 全局替换视图中的格式化函数: - 移除各视图中的自定义 formatDate 函数 - 统一导入使用 @/utils/format 中的函数 - created_at/updated_at 使用 formatDateTime - expires_at 使用 formatDateOnly 3. 受影响的视图 (8个): - frontend/src/views/user/KeysView.vue - frontend/src/views/user/DashboardView.vue - frontend/src/views/user/UsageView.vue - frontend/src/views/user/RedeemView.vue - frontend/src/views/admin/UsersView.vue - frontend/src/views/admin/UsageView.vue - frontend/src/views/admin/RedeemView.vue - frontend/src/views/admin/SubscriptionsView.vue **效果**: - 日期统一显示为 YYYY-MM-DD - 时间统一显示为 YYYY-MM-DD HH:mm:ss - 提升可维护性,避免格式不一致 * fix(frontend): 补充遗漏的时间格式化统一 **补充修复**(基于 code review 发现的遗漏): 1. 增强 utils/format.ts: - 新增 formatTime() - 格式: HH:mm 2. 修复 4 个遗漏的文件: - src/views/admin/UsersView.vue * 删除 formatExpiresAt(),改用 formatDateTime() * 修复订阅过期时间 tooltip 显示格式不一致问题 - src/views/user/ProfileView.vue * 删除 formatMemberSince(),改用 formatDate(date, 'YYYY-MM') * 统一会员起始时间显示格式 - src/views/user/SubscriptionsView.vue * 修改 formatExpirationDate() 使用 formatDateOnly() * 保留天数计算逻辑 - src/components/account/AccountStatusIndicator.vue * 删除本地 formatTime(),改用 utils/format 中的统一函数 * 修复 rate limit 和 overload 重置时间显示 **验证**: - TypeScript 类型检查通过 ✓ - 前端构建成功 ✓ - 所有剩余的 toLocaleString() 都是数字格式化,属于正确用法 ✓ **效果**: - 订阅过期时间统一为 YYYY-MM-DD HH:mm:ss - 会员起始时间统一为 YYYY-MM - 重置时间统一为 HH:mm - 消除所有不规范的原生 locale 方法调用
2025-12-27 10:50:25 +08:00
const { t } = useI18n()
2025-12-18 13:50:39 +08:00
const loading = ref(false)
const error = ref<string | null>(null)
const usageInfo = ref<AccountUsageInfo | null>(null)
2025-12-22 22:58:31 +08:00
// Show usage windows for OAuth and Setup Token accounts
const showUsageWindows = computed(
() => props.account.type === 'oauth' || props.account.type === 'setup-token'
2025-12-22 22:58:31 +08:00
)
const shouldFetchUsage = computed(() => {
if (props.account.platform === 'anthropic') {
return props.account.type === 'oauth' || props.account.type === 'setup-token'
}
if (props.account.platform === 'gemini') {
return props.account.type === 'oauth'
}
if (props.account.platform === 'antigravity') {
return props.account.type === 'oauth'
}
return false
})
const geminiUsageAvailable = computed(() => {
return (
!!usageInfo.value?.gemini_pro_daily ||
!!usageInfo.value?.gemini_flash_daily
)
})
// OpenAI Codex usage computed properties
const hasCodexUsage = computed(() => {
const extra = props.account.extra
return (
extra &&
fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 (#30) * fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 问题描述: - 账号管理页面中,OpenAI OAuth 账号的 5h 列显示 7 天的剩余时间 - 7d 列却显示几小时的剩余时间 - 根本原因: OpenAI 响应头中 primary/secondary 的实际含义与代码假设相反 修复方案: 1. 后端归一化 (openai_gateway_service.go): - 根据 window_minutes 动态判断哪个是 5h/7d 限制 - 新增规范字段 codex_5h_* 和 codex_7d_* - 保留旧字段以兼容性 2. 前端适配 (AccountUsageCell.vue): - 优先使用新的规范字段 - Fallback 到旧字段时基于 window_minutes 动态判断 - 更新 computed 属性命名 3. 类型定义更新 (types/index.ts): - 添加新的规范字段定义 - 更新注释说明实际语义由 window_minutes 决定 🤖 Generated with Claude Code and Codex collaboration Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Co-Authored-By: OpenAI Codex <noreply@openai.com> * fix: 改进窗口判断逻辑,修复两个窗口都小于阈值时的bug 问题: 当两个窗口都小于360分钟时(如 primary=180分钟,secondary=300分钟), 之前的逻辑会导致: - primary5h = true, secondary5h = true - 5h 字段会使用 primary(错误) - 7d 字段没有数据(bug) 修复方案: 改用比较策略: 1. 当两个窗口都存在时:较小的分配给5h,较大的分配给7d 2. 当只有一个窗口时:根据大小(<=360分钟)判断是5h还是7d 3. 确保数据不会丢失,逻辑更健壮 示例: - Primary: 180分钟, Secondary: 300分钟 → 5h 使用 Primary(180分钟), 7d 使用 Secondary(300分钟) ✓ 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修正窗口大小判断逻辑 - 不能用剩余时间判断窗口类型 **严重bug修复:** 之前的 fallback 逻辑错误地使用 reset_after_seconds 来判断窗口大小。 问题示例: - 周限制(7d)剩余 2h → reset_after_seconds = 7200秒 - 5h限制 剩余 4h → reset_after_seconds = 14400秒 - 错误逻辑:7200/60 < 14400/60,把周限制当成5h ❌ 根本问题: - window_minutes = 窗口的总大小(300 or 10080) - reset_after_seconds = 距离重置的剩余时间(变化的) - 不能用剩余时间来判断窗口类型! 修复方案: 1. **只使用 window_minutes** 来判断窗口大小 2. 移除错误的 reset_after_seconds fallback 3. 如果 window_minutes 都不存在,使用传统假设 4. 添加详细注释说明这个陷阱 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修复 lint 问题 - 改进 fallback 逻辑的变量赋值 问题: 第882-883行的简单布尔赋值可能触发 ineffassign 或 staticcheck 警告: use5hFromSecondary = snapshot.SecondaryUsedPercent != nil use7dFromPrimary = snapshot.PrimaryUsedPercent != nil 修复: 改用明确的 if 语句检查任意字段是否存在,更符合代码意图: - 如果 secondary 的任意字段存在,将其视为 5h - 如果 primary 的任意字段存在,将其视为 7d 这样逻辑更清晰,也避免了 lint 警告。 --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com> Co-authored-by: OpenAI Codex <noreply@openai.com>
2025-12-25 17:00:02 +08:00
// Check for new canonical fields first
(extra.codex_5h_used_percent !== undefined ||
extra.codex_7d_used_percent !== undefined ||
// Fallback to legacy fields
extra.codex_primary_used_percent !== undefined ||
extra.codex_secondary_used_percent !== undefined)
)
})
fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 (#30) * fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 问题描述: - 账号管理页面中,OpenAI OAuth 账号的 5h 列显示 7 天的剩余时间 - 7d 列却显示几小时的剩余时间 - 根本原因: OpenAI 响应头中 primary/secondary 的实际含义与代码假设相反 修复方案: 1. 后端归一化 (openai_gateway_service.go): - 根据 window_minutes 动态判断哪个是 5h/7d 限制 - 新增规范字段 codex_5h_* 和 codex_7d_* - 保留旧字段以兼容性 2. 前端适配 (AccountUsageCell.vue): - 优先使用新的规范字段 - Fallback 到旧字段时基于 window_minutes 动态判断 - 更新 computed 属性命名 3. 类型定义更新 (types/index.ts): - 添加新的规范字段定义 - 更新注释说明实际语义由 window_minutes 决定 🤖 Generated with Claude Code and Codex collaboration Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Co-Authored-By: OpenAI Codex <noreply@openai.com> * fix: 改进窗口判断逻辑,修复两个窗口都小于阈值时的bug 问题: 当两个窗口都小于360分钟时(如 primary=180分钟,secondary=300分钟), 之前的逻辑会导致: - primary5h = true, secondary5h = true - 5h 字段会使用 primary(错误) - 7d 字段没有数据(bug) 修复方案: 改用比较策略: 1. 当两个窗口都存在时:较小的分配给5h,较大的分配给7d 2. 当只有一个窗口时:根据大小(<=360分钟)判断是5h还是7d 3. 确保数据不会丢失,逻辑更健壮 示例: - Primary: 180分钟, Secondary: 300分钟 → 5h 使用 Primary(180分钟), 7d 使用 Secondary(300分钟) ✓ 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修正窗口大小判断逻辑 - 不能用剩余时间判断窗口类型 **严重bug修复:** 之前的 fallback 逻辑错误地使用 reset_after_seconds 来判断窗口大小。 问题示例: - 周限制(7d)剩余 2h → reset_after_seconds = 7200秒 - 5h限制 剩余 4h → reset_after_seconds = 14400秒 - 错误逻辑:7200/60 < 14400/60,把周限制当成5h ❌ 根本问题: - window_minutes = 窗口的总大小(300 or 10080) - reset_after_seconds = 距离重置的剩余时间(变化的) - 不能用剩余时间来判断窗口类型! 修复方案: 1. **只使用 window_minutes** 来判断窗口大小 2. 移除错误的 reset_after_seconds fallback 3. 如果 window_minutes 都不存在,使用传统假设 4. 添加详细注释说明这个陷阱 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修复 lint 问题 - 改进 fallback 逻辑的变量赋值 问题: 第882-883行的简单布尔赋值可能触发 ineffassign 或 staticcheck 警告: use5hFromSecondary = snapshot.SecondaryUsedPercent != nil use7dFromPrimary = snapshot.PrimaryUsedPercent != nil 修复: 改用明确的 if 语句检查任意字段是否存在,更符合代码意图: - 如果 secondary 的任意字段存在,将其视为 5h - 如果 primary 的任意字段存在,将其视为 7d 这样逻辑更清晰,也避免了 lint 警告。 --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com> Co-authored-by: OpenAI Codex <noreply@openai.com>
2025-12-25 17:00:02 +08:00
// 5h window usage (prefer canonical field)
const codex5hUsedPercent = computed(() => {
const extra = props.account.extra
fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 (#30) * fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 问题描述: - 账号管理页面中,OpenAI OAuth 账号的 5h 列显示 7 天的剩余时间 - 7d 列却显示几小时的剩余时间 - 根本原因: OpenAI 响应头中 primary/secondary 的实际含义与代码假设相反 修复方案: 1. 后端归一化 (openai_gateway_service.go): - 根据 window_minutes 动态判断哪个是 5h/7d 限制 - 新增规范字段 codex_5h_* 和 codex_7d_* - 保留旧字段以兼容性 2. 前端适配 (AccountUsageCell.vue): - 优先使用新的规范字段 - Fallback 到旧字段时基于 window_minutes 动态判断 - 更新 computed 属性命名 3. 类型定义更新 (types/index.ts): - 添加新的规范字段定义 - 更新注释说明实际语义由 window_minutes 决定 🤖 Generated with Claude Code and Codex collaboration Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Co-Authored-By: OpenAI Codex <noreply@openai.com> * fix: 改进窗口判断逻辑,修复两个窗口都小于阈值时的bug 问题: 当两个窗口都小于360分钟时(如 primary=180分钟,secondary=300分钟), 之前的逻辑会导致: - primary5h = true, secondary5h = true - 5h 字段会使用 primary(错误) - 7d 字段没有数据(bug) 修复方案: 改用比较策略: 1. 当两个窗口都存在时:较小的分配给5h,较大的分配给7d 2. 当只有一个窗口时:根据大小(<=360分钟)判断是5h还是7d 3. 确保数据不会丢失,逻辑更健壮 示例: - Primary: 180分钟, Secondary: 300分钟 → 5h 使用 Primary(180分钟), 7d 使用 Secondary(300分钟) ✓ 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修正窗口大小判断逻辑 - 不能用剩余时间判断窗口类型 **严重bug修复:** 之前的 fallback 逻辑错误地使用 reset_after_seconds 来判断窗口大小。 问题示例: - 周限制(7d)剩余 2h → reset_after_seconds = 7200秒 - 5h限制 剩余 4h → reset_after_seconds = 14400秒 - 错误逻辑:7200/60 < 14400/60,把周限制当成5h ❌ 根本问题: - window_minutes = 窗口的总大小(300 or 10080) - reset_after_seconds = 距离重置的剩余时间(变化的) - 不能用剩余时间来判断窗口类型! 修复方案: 1. **只使用 window_minutes** 来判断窗口大小 2. 移除错误的 reset_after_seconds fallback 3. 如果 window_minutes 都不存在,使用传统假设 4. 添加详细注释说明这个陷阱 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修复 lint 问题 - 改进 fallback 逻辑的变量赋值 问题: 第882-883行的简单布尔赋值可能触发 ineffassign 或 staticcheck 警告: use5hFromSecondary = snapshot.SecondaryUsedPercent != nil use7dFromPrimary = snapshot.PrimaryUsedPercent != nil 修复: 改用明确的 if 语句检查任意字段是否存在,更符合代码意图: - 如果 secondary 的任意字段存在,将其视为 5h - 如果 primary 的任意字段存在,将其视为 7d 这样逻辑更清晰,也避免了 lint 警告。 --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com> Co-authored-by: OpenAI Codex <noreply@openai.com>
2025-12-25 17:00:02 +08:00
if (!extra) return null
// Prefer canonical field
if (extra.codex_5h_used_percent !== undefined) {
return extra.codex_5h_used_percent
}
// Fallback: detect from legacy fields using window_minutes
if (
extra.codex_primary_window_minutes !== undefined &&
extra.codex_primary_window_minutes <= 360
) {
fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 (#30) * fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 问题描述: - 账号管理页面中,OpenAI OAuth 账号的 5h 列显示 7 天的剩余时间 - 7d 列却显示几小时的剩余时间 - 根本原因: OpenAI 响应头中 primary/secondary 的实际含义与代码假设相反 修复方案: 1. 后端归一化 (openai_gateway_service.go): - 根据 window_minutes 动态判断哪个是 5h/7d 限制 - 新增规范字段 codex_5h_* 和 codex_7d_* - 保留旧字段以兼容性 2. 前端适配 (AccountUsageCell.vue): - 优先使用新的规范字段 - Fallback 到旧字段时基于 window_minutes 动态判断 - 更新 computed 属性命名 3. 类型定义更新 (types/index.ts): - 添加新的规范字段定义 - 更新注释说明实际语义由 window_minutes 决定 🤖 Generated with Claude Code and Codex collaboration Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Co-Authored-By: OpenAI Codex <noreply@openai.com> * fix: 改进窗口判断逻辑,修复两个窗口都小于阈值时的bug 问题: 当两个窗口都小于360分钟时(如 primary=180分钟,secondary=300分钟), 之前的逻辑会导致: - primary5h = true, secondary5h = true - 5h 字段会使用 primary(错误) - 7d 字段没有数据(bug) 修复方案: 改用比较策略: 1. 当两个窗口都存在时:较小的分配给5h,较大的分配给7d 2. 当只有一个窗口时:根据大小(<=360分钟)判断是5h还是7d 3. 确保数据不会丢失,逻辑更健壮 示例: - Primary: 180分钟, Secondary: 300分钟 → 5h 使用 Primary(180分钟), 7d 使用 Secondary(300分钟) ✓ 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修正窗口大小判断逻辑 - 不能用剩余时间判断窗口类型 **严重bug修复:** 之前的 fallback 逻辑错误地使用 reset_after_seconds 来判断窗口大小。 问题示例: - 周限制(7d)剩余 2h → reset_after_seconds = 7200秒 - 5h限制 剩余 4h → reset_after_seconds = 14400秒 - 错误逻辑:7200/60 < 14400/60,把周限制当成5h ❌ 根本问题: - window_minutes = 窗口的总大小(300 or 10080) - reset_after_seconds = 距离重置的剩余时间(变化的) - 不能用剩余时间来判断窗口类型! 修复方案: 1. **只使用 window_minutes** 来判断窗口大小 2. 移除错误的 reset_after_seconds fallback 3. 如果 window_minutes 都不存在,使用传统假设 4. 添加详细注释说明这个陷阱 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修复 lint 问题 - 改进 fallback 逻辑的变量赋值 问题: 第882-883行的简单布尔赋值可能触发 ineffassign 或 staticcheck 警告: use5hFromSecondary = snapshot.SecondaryUsedPercent != nil use7dFromPrimary = snapshot.PrimaryUsedPercent != nil 修复: 改用明确的 if 语句检查任意字段是否存在,更符合代码意图: - 如果 secondary 的任意字段存在,将其视为 5h - 如果 primary 的任意字段存在,将其视为 7d 这样逻辑更清晰,也避免了 lint 警告。 --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com> Co-authored-by: OpenAI Codex <noreply@openai.com>
2025-12-25 17:00:02 +08:00
return extra.codex_primary_used_percent ?? null
}
if (
extra.codex_secondary_window_minutes !== undefined &&
extra.codex_secondary_window_minutes <= 360
) {
fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 (#30) * fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 问题描述: - 账号管理页面中,OpenAI OAuth 账号的 5h 列显示 7 天的剩余时间 - 7d 列却显示几小时的剩余时间 - 根本原因: OpenAI 响应头中 primary/secondary 的实际含义与代码假设相反 修复方案: 1. 后端归一化 (openai_gateway_service.go): - 根据 window_minutes 动态判断哪个是 5h/7d 限制 - 新增规范字段 codex_5h_* 和 codex_7d_* - 保留旧字段以兼容性 2. 前端适配 (AccountUsageCell.vue): - 优先使用新的规范字段 - Fallback 到旧字段时基于 window_minutes 动态判断 - 更新 computed 属性命名 3. 类型定义更新 (types/index.ts): - 添加新的规范字段定义 - 更新注释说明实际语义由 window_minutes 决定 🤖 Generated with Claude Code and Codex collaboration Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Co-Authored-By: OpenAI Codex <noreply@openai.com> * fix: 改进窗口判断逻辑,修复两个窗口都小于阈值时的bug 问题: 当两个窗口都小于360分钟时(如 primary=180分钟,secondary=300分钟), 之前的逻辑会导致: - primary5h = true, secondary5h = true - 5h 字段会使用 primary(错误) - 7d 字段没有数据(bug) 修复方案: 改用比较策略: 1. 当两个窗口都存在时:较小的分配给5h,较大的分配给7d 2. 当只有一个窗口时:根据大小(<=360分钟)判断是5h还是7d 3. 确保数据不会丢失,逻辑更健壮 示例: - Primary: 180分钟, Secondary: 300分钟 → 5h 使用 Primary(180分钟), 7d 使用 Secondary(300分钟) ✓ 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修正窗口大小判断逻辑 - 不能用剩余时间判断窗口类型 **严重bug修复:** 之前的 fallback 逻辑错误地使用 reset_after_seconds 来判断窗口大小。 问题示例: - 周限制(7d)剩余 2h → reset_after_seconds = 7200秒 - 5h限制 剩余 4h → reset_after_seconds = 14400秒 - 错误逻辑:7200/60 < 14400/60,把周限制当成5h ❌ 根本问题: - window_minutes = 窗口的总大小(300 or 10080) - reset_after_seconds = 距离重置的剩余时间(变化的) - 不能用剩余时间来判断窗口类型! 修复方案: 1. **只使用 window_minutes** 来判断窗口大小 2. 移除错误的 reset_after_seconds fallback 3. 如果 window_minutes 都不存在,使用传统假设 4. 添加详细注释说明这个陷阱 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修复 lint 问题 - 改进 fallback 逻辑的变量赋值 问题: 第882-883行的简单布尔赋值可能触发 ineffassign 或 staticcheck 警告: use5hFromSecondary = snapshot.SecondaryUsedPercent != nil use7dFromPrimary = snapshot.PrimaryUsedPercent != nil 修复: 改用明确的 if 语句检查任意字段是否存在,更符合代码意图: - 如果 secondary 的任意字段存在,将其视为 5h - 如果 primary 的任意字段存在,将其视为 7d 这样逻辑更清晰,也避免了 lint 警告。 --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com> Co-authored-by: OpenAI Codex <noreply@openai.com>
2025-12-25 17:00:02 +08:00
return extra.codex_secondary_used_percent ?? null
}
// Legacy assumption: secondary = 5h (may be incorrect)
return extra.codex_secondary_used_percent ?? null
})
fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 (#30) * fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 问题描述: - 账号管理页面中,OpenAI OAuth 账号的 5h 列显示 7 天的剩余时间 - 7d 列却显示几小时的剩余时间 - 根本原因: OpenAI 响应头中 primary/secondary 的实际含义与代码假设相反 修复方案: 1. 后端归一化 (openai_gateway_service.go): - 根据 window_minutes 动态判断哪个是 5h/7d 限制 - 新增规范字段 codex_5h_* 和 codex_7d_* - 保留旧字段以兼容性 2. 前端适配 (AccountUsageCell.vue): - 优先使用新的规范字段 - Fallback 到旧字段时基于 window_minutes 动态判断 - 更新 computed 属性命名 3. 类型定义更新 (types/index.ts): - 添加新的规范字段定义 - 更新注释说明实际语义由 window_minutes 决定 🤖 Generated with Claude Code and Codex collaboration Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Co-Authored-By: OpenAI Codex <noreply@openai.com> * fix: 改进窗口判断逻辑,修复两个窗口都小于阈值时的bug 问题: 当两个窗口都小于360分钟时(如 primary=180分钟,secondary=300分钟), 之前的逻辑会导致: - primary5h = true, secondary5h = true - 5h 字段会使用 primary(错误) - 7d 字段没有数据(bug) 修复方案: 改用比较策略: 1. 当两个窗口都存在时:较小的分配给5h,较大的分配给7d 2. 当只有一个窗口时:根据大小(<=360分钟)判断是5h还是7d 3. 确保数据不会丢失,逻辑更健壮 示例: - Primary: 180分钟, Secondary: 300分钟 → 5h 使用 Primary(180分钟), 7d 使用 Secondary(300分钟) ✓ 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修正窗口大小判断逻辑 - 不能用剩余时间判断窗口类型 **严重bug修复:** 之前的 fallback 逻辑错误地使用 reset_after_seconds 来判断窗口大小。 问题示例: - 周限制(7d)剩余 2h → reset_after_seconds = 7200秒 - 5h限制 剩余 4h → reset_after_seconds = 14400秒 - 错误逻辑:7200/60 < 14400/60,把周限制当成5h ❌ 根本问题: - window_minutes = 窗口的总大小(300 or 10080) - reset_after_seconds = 距离重置的剩余时间(变化的) - 不能用剩余时间来判断窗口类型! 修复方案: 1. **只使用 window_minutes** 来判断窗口大小 2. 移除错误的 reset_after_seconds fallback 3. 如果 window_minutes 都不存在,使用传统假设 4. 添加详细注释说明这个陷阱 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修复 lint 问题 - 改进 fallback 逻辑的变量赋值 问题: 第882-883行的简单布尔赋值可能触发 ineffassign 或 staticcheck 警告: use5hFromSecondary = snapshot.SecondaryUsedPercent != nil use7dFromPrimary = snapshot.PrimaryUsedPercent != nil 修复: 改用明确的 if 语句检查任意字段是否存在,更符合代码意图: - 如果 secondary 的任意字段存在,将其视为 5h - 如果 primary 的任意字段存在,将其视为 7d 这样逻辑更清晰,也避免了 lint 警告。 --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com> Co-authored-by: OpenAI Codex <noreply@openai.com>
2025-12-25 17:00:02 +08:00
const codex5hResetAt = computed(() => {
const extra = props.account.extra
fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 (#30) * fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 问题描述: - 账号管理页面中,OpenAI OAuth 账号的 5h 列显示 7 天的剩余时间 - 7d 列却显示几小时的剩余时间 - 根本原因: OpenAI 响应头中 primary/secondary 的实际含义与代码假设相反 修复方案: 1. 后端归一化 (openai_gateway_service.go): - 根据 window_minutes 动态判断哪个是 5h/7d 限制 - 新增规范字段 codex_5h_* 和 codex_7d_* - 保留旧字段以兼容性 2. 前端适配 (AccountUsageCell.vue): - 优先使用新的规范字段 - Fallback 到旧字段时基于 window_minutes 动态判断 - 更新 computed 属性命名 3. 类型定义更新 (types/index.ts): - 添加新的规范字段定义 - 更新注释说明实际语义由 window_minutes 决定 🤖 Generated with Claude Code and Codex collaboration Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Co-Authored-By: OpenAI Codex <noreply@openai.com> * fix: 改进窗口判断逻辑,修复两个窗口都小于阈值时的bug 问题: 当两个窗口都小于360分钟时(如 primary=180分钟,secondary=300分钟), 之前的逻辑会导致: - primary5h = true, secondary5h = true - 5h 字段会使用 primary(错误) - 7d 字段没有数据(bug) 修复方案: 改用比较策略: 1. 当两个窗口都存在时:较小的分配给5h,较大的分配给7d 2. 当只有一个窗口时:根据大小(<=360分钟)判断是5h还是7d 3. 确保数据不会丢失,逻辑更健壮 示例: - Primary: 180分钟, Secondary: 300分钟 → 5h 使用 Primary(180分钟), 7d 使用 Secondary(300分钟) ✓ 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修正窗口大小判断逻辑 - 不能用剩余时间判断窗口类型 **严重bug修复:** 之前的 fallback 逻辑错误地使用 reset_after_seconds 来判断窗口大小。 问题示例: - 周限制(7d)剩余 2h → reset_after_seconds = 7200秒 - 5h限制 剩余 4h → reset_after_seconds = 14400秒 - 错误逻辑:7200/60 < 14400/60,把周限制当成5h ❌ 根本问题: - window_minutes = 窗口的总大小(300 or 10080) - reset_after_seconds = 距离重置的剩余时间(变化的) - 不能用剩余时间来判断窗口类型! 修复方案: 1. **只使用 window_minutes** 来判断窗口大小 2. 移除错误的 reset_after_seconds fallback 3. 如果 window_minutes 都不存在,使用传统假设 4. 添加详细注释说明这个陷阱 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修复 lint 问题 - 改进 fallback 逻辑的变量赋值 问题: 第882-883行的简单布尔赋值可能触发 ineffassign 或 staticcheck 警告: use5hFromSecondary = snapshot.SecondaryUsedPercent != nil use7dFromPrimary = snapshot.PrimaryUsedPercent != nil 修复: 改用明确的 if 语句检查任意字段是否存在,更符合代码意图: - 如果 secondary 的任意字段存在,将其视为 5h - 如果 primary 的任意字段存在,将其视为 7d 这样逻辑更清晰,也避免了 lint 警告。 --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com> Co-authored-by: OpenAI Codex <noreply@openai.com>
2025-12-25 17:00:02 +08:00
if (!extra) return null
// Prefer canonical field
if (extra.codex_5h_reset_after_seconds !== undefined) {
const resetTime = new Date(Date.now() + extra.codex_5h_reset_after_seconds * 1000)
return resetTime.toISOString()
}
// Fallback: detect from legacy fields using window_minutes
if (
extra.codex_primary_window_minutes !== undefined &&
extra.codex_primary_window_minutes <= 360
) {
fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 (#30) * fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 问题描述: - 账号管理页面中,OpenAI OAuth 账号的 5h 列显示 7 天的剩余时间 - 7d 列却显示几小时的剩余时间 - 根本原因: OpenAI 响应头中 primary/secondary 的实际含义与代码假设相反 修复方案: 1. 后端归一化 (openai_gateway_service.go): - 根据 window_minutes 动态判断哪个是 5h/7d 限制 - 新增规范字段 codex_5h_* 和 codex_7d_* - 保留旧字段以兼容性 2. 前端适配 (AccountUsageCell.vue): - 优先使用新的规范字段 - Fallback 到旧字段时基于 window_minutes 动态判断 - 更新 computed 属性命名 3. 类型定义更新 (types/index.ts): - 添加新的规范字段定义 - 更新注释说明实际语义由 window_minutes 决定 🤖 Generated with Claude Code and Codex collaboration Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Co-Authored-By: OpenAI Codex <noreply@openai.com> * fix: 改进窗口判断逻辑,修复两个窗口都小于阈值时的bug 问题: 当两个窗口都小于360分钟时(如 primary=180分钟,secondary=300分钟), 之前的逻辑会导致: - primary5h = true, secondary5h = true - 5h 字段会使用 primary(错误) - 7d 字段没有数据(bug) 修复方案: 改用比较策略: 1. 当两个窗口都存在时:较小的分配给5h,较大的分配给7d 2. 当只有一个窗口时:根据大小(<=360分钟)判断是5h还是7d 3. 确保数据不会丢失,逻辑更健壮 示例: - Primary: 180分钟, Secondary: 300分钟 → 5h 使用 Primary(180分钟), 7d 使用 Secondary(300分钟) ✓ 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修正窗口大小判断逻辑 - 不能用剩余时间判断窗口类型 **严重bug修复:** 之前的 fallback 逻辑错误地使用 reset_after_seconds 来判断窗口大小。 问题示例: - 周限制(7d)剩余 2h → reset_after_seconds = 7200秒 - 5h限制 剩余 4h → reset_after_seconds = 14400秒 - 错误逻辑:7200/60 < 14400/60,把周限制当成5h ❌ 根本问题: - window_minutes = 窗口的总大小(300 or 10080) - reset_after_seconds = 距离重置的剩余时间(变化的) - 不能用剩余时间来判断窗口类型! 修复方案: 1. **只使用 window_minutes** 来判断窗口大小 2. 移除错误的 reset_after_seconds fallback 3. 如果 window_minutes 都不存在,使用传统假设 4. 添加详细注释说明这个陷阱 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修复 lint 问题 - 改进 fallback 逻辑的变量赋值 问题: 第882-883行的简单布尔赋值可能触发 ineffassign 或 staticcheck 警告: use5hFromSecondary = snapshot.SecondaryUsedPercent != nil use7dFromPrimary = snapshot.PrimaryUsedPercent != nil 修复: 改用明确的 if 语句检查任意字段是否存在,更符合代码意图: - 如果 secondary 的任意字段存在,将其视为 5h - 如果 primary 的任意字段存在,将其视为 7d 这样逻辑更清晰,也避免了 lint 警告。 --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com> Co-authored-by: OpenAI Codex <noreply@openai.com>
2025-12-25 17:00:02 +08:00
if (extra.codex_primary_reset_after_seconds !== undefined) {
const resetTime = new Date(Date.now() + extra.codex_primary_reset_after_seconds * 1000)
return resetTime.toISOString()
}
}
if (
extra.codex_secondary_window_minutes !== undefined &&
extra.codex_secondary_window_minutes <= 360
) {
fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 (#30) * fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 问题描述: - 账号管理页面中,OpenAI OAuth 账号的 5h 列显示 7 天的剩余时间 - 7d 列却显示几小时的剩余时间 - 根本原因: OpenAI 响应头中 primary/secondary 的实际含义与代码假设相反 修复方案: 1. 后端归一化 (openai_gateway_service.go): - 根据 window_minutes 动态判断哪个是 5h/7d 限制 - 新增规范字段 codex_5h_* 和 codex_7d_* - 保留旧字段以兼容性 2. 前端适配 (AccountUsageCell.vue): - 优先使用新的规范字段 - Fallback 到旧字段时基于 window_minutes 动态判断 - 更新 computed 属性命名 3. 类型定义更新 (types/index.ts): - 添加新的规范字段定义 - 更新注释说明实际语义由 window_minutes 决定 🤖 Generated with Claude Code and Codex collaboration Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Co-Authored-By: OpenAI Codex <noreply@openai.com> * fix: 改进窗口判断逻辑,修复两个窗口都小于阈值时的bug 问题: 当两个窗口都小于360分钟时(如 primary=180分钟,secondary=300分钟), 之前的逻辑会导致: - primary5h = true, secondary5h = true - 5h 字段会使用 primary(错误) - 7d 字段没有数据(bug) 修复方案: 改用比较策略: 1. 当两个窗口都存在时:较小的分配给5h,较大的分配给7d 2. 当只有一个窗口时:根据大小(<=360分钟)判断是5h还是7d 3. 确保数据不会丢失,逻辑更健壮 示例: - Primary: 180分钟, Secondary: 300分钟 → 5h 使用 Primary(180分钟), 7d 使用 Secondary(300分钟) ✓ 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修正窗口大小判断逻辑 - 不能用剩余时间判断窗口类型 **严重bug修复:** 之前的 fallback 逻辑错误地使用 reset_after_seconds 来判断窗口大小。 问题示例: - 周限制(7d)剩余 2h → reset_after_seconds = 7200秒 - 5h限制 剩余 4h → reset_after_seconds = 14400秒 - 错误逻辑:7200/60 < 14400/60,把周限制当成5h ❌ 根本问题: - window_minutes = 窗口的总大小(300 or 10080) - reset_after_seconds = 距离重置的剩余时间(变化的) - 不能用剩余时间来判断窗口类型! 修复方案: 1. **只使用 window_minutes** 来判断窗口大小 2. 移除错误的 reset_after_seconds fallback 3. 如果 window_minutes 都不存在,使用传统假设 4. 添加详细注释说明这个陷阱 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修复 lint 问题 - 改进 fallback 逻辑的变量赋值 问题: 第882-883行的简单布尔赋值可能触发 ineffassign 或 staticcheck 警告: use5hFromSecondary = snapshot.SecondaryUsedPercent != nil use7dFromPrimary = snapshot.PrimaryUsedPercent != nil 修复: 改用明确的 if 语句检查任意字段是否存在,更符合代码意图: - 如果 secondary 的任意字段存在,将其视为 5h - 如果 primary 的任意字段存在,将其视为 7d 这样逻辑更清晰,也避免了 lint 警告。 --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com> Co-authored-by: OpenAI Codex <noreply@openai.com>
2025-12-25 17:00:02 +08:00
if (extra.codex_secondary_reset_after_seconds !== undefined) {
const resetTime = new Date(Date.now() + extra.codex_secondary_reset_after_seconds * 1000)
return resetTime.toISOString()
}
}
// Legacy assumption: secondary = 5h
if (extra.codex_secondary_reset_after_seconds !== undefined) {
const resetTime = new Date(Date.now() + extra.codex_secondary_reset_after_seconds * 1000)
return resetTime.toISOString()
}
return null
})
fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 (#30) * fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 问题描述: - 账号管理页面中,OpenAI OAuth 账号的 5h 列显示 7 天的剩余时间 - 7d 列却显示几小时的剩余时间 - 根本原因: OpenAI 响应头中 primary/secondary 的实际含义与代码假设相反 修复方案: 1. 后端归一化 (openai_gateway_service.go): - 根据 window_minutes 动态判断哪个是 5h/7d 限制 - 新增规范字段 codex_5h_* 和 codex_7d_* - 保留旧字段以兼容性 2. 前端适配 (AccountUsageCell.vue): - 优先使用新的规范字段 - Fallback 到旧字段时基于 window_minutes 动态判断 - 更新 computed 属性命名 3. 类型定义更新 (types/index.ts): - 添加新的规范字段定义 - 更新注释说明实际语义由 window_minutes 决定 🤖 Generated with Claude Code and Codex collaboration Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Co-Authored-By: OpenAI Codex <noreply@openai.com> * fix: 改进窗口判断逻辑,修复两个窗口都小于阈值时的bug 问题: 当两个窗口都小于360分钟时(如 primary=180分钟,secondary=300分钟), 之前的逻辑会导致: - primary5h = true, secondary5h = true - 5h 字段会使用 primary(错误) - 7d 字段没有数据(bug) 修复方案: 改用比较策略: 1. 当两个窗口都存在时:较小的分配给5h,较大的分配给7d 2. 当只有一个窗口时:根据大小(<=360分钟)判断是5h还是7d 3. 确保数据不会丢失,逻辑更健壮 示例: - Primary: 180分钟, Secondary: 300分钟 → 5h 使用 Primary(180分钟), 7d 使用 Secondary(300分钟) ✓ 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修正窗口大小判断逻辑 - 不能用剩余时间判断窗口类型 **严重bug修复:** 之前的 fallback 逻辑错误地使用 reset_after_seconds 来判断窗口大小。 问题示例: - 周限制(7d)剩余 2h → reset_after_seconds = 7200秒 - 5h限制 剩余 4h → reset_after_seconds = 14400秒 - 错误逻辑:7200/60 < 14400/60,把周限制当成5h ❌ 根本问题: - window_minutes = 窗口的总大小(300 or 10080) - reset_after_seconds = 距离重置的剩余时间(变化的) - 不能用剩余时间来判断窗口类型! 修复方案: 1. **只使用 window_minutes** 来判断窗口大小 2. 移除错误的 reset_after_seconds fallback 3. 如果 window_minutes 都不存在,使用传统假设 4. 添加详细注释说明这个陷阱 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修复 lint 问题 - 改进 fallback 逻辑的变量赋值 问题: 第882-883行的简单布尔赋值可能触发 ineffassign 或 staticcheck 警告: use5hFromSecondary = snapshot.SecondaryUsedPercent != nil use7dFromPrimary = snapshot.PrimaryUsedPercent != nil 修复: 改用明确的 if 语句检查任意字段是否存在,更符合代码意图: - 如果 secondary 的任意字段存在,将其视为 5h - 如果 primary 的任意字段存在,将其视为 7d 这样逻辑更清晰,也避免了 lint 警告。 --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com> Co-authored-by: OpenAI Codex <noreply@openai.com>
2025-12-25 17:00:02 +08:00
// 7d window usage (prefer canonical field)
const codex7dUsedPercent = computed(() => {
const extra = props.account.extra
fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 (#30) * fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 问题描述: - 账号管理页面中,OpenAI OAuth 账号的 5h 列显示 7 天的剩余时间 - 7d 列却显示几小时的剩余时间 - 根本原因: OpenAI 响应头中 primary/secondary 的实际含义与代码假设相反 修复方案: 1. 后端归一化 (openai_gateway_service.go): - 根据 window_minutes 动态判断哪个是 5h/7d 限制 - 新增规范字段 codex_5h_* 和 codex_7d_* - 保留旧字段以兼容性 2. 前端适配 (AccountUsageCell.vue): - 优先使用新的规范字段 - Fallback 到旧字段时基于 window_minutes 动态判断 - 更新 computed 属性命名 3. 类型定义更新 (types/index.ts): - 添加新的规范字段定义 - 更新注释说明实际语义由 window_minutes 决定 🤖 Generated with Claude Code and Codex collaboration Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Co-Authored-By: OpenAI Codex <noreply@openai.com> * fix: 改进窗口判断逻辑,修复两个窗口都小于阈值时的bug 问题: 当两个窗口都小于360分钟时(如 primary=180分钟,secondary=300分钟), 之前的逻辑会导致: - primary5h = true, secondary5h = true - 5h 字段会使用 primary(错误) - 7d 字段没有数据(bug) 修复方案: 改用比较策略: 1. 当两个窗口都存在时:较小的分配给5h,较大的分配给7d 2. 当只有一个窗口时:根据大小(<=360分钟)判断是5h还是7d 3. 确保数据不会丢失,逻辑更健壮 示例: - Primary: 180分钟, Secondary: 300分钟 → 5h 使用 Primary(180分钟), 7d 使用 Secondary(300分钟) ✓ 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修正窗口大小判断逻辑 - 不能用剩余时间判断窗口类型 **严重bug修复:** 之前的 fallback 逻辑错误地使用 reset_after_seconds 来判断窗口大小。 问题示例: - 周限制(7d)剩余 2h → reset_after_seconds = 7200秒 - 5h限制 剩余 4h → reset_after_seconds = 14400秒 - 错误逻辑:7200/60 < 14400/60,把周限制当成5h ❌ 根本问题: - window_minutes = 窗口的总大小(300 or 10080) - reset_after_seconds = 距离重置的剩余时间(变化的) - 不能用剩余时间来判断窗口类型! 修复方案: 1. **只使用 window_minutes** 来判断窗口大小 2. 移除错误的 reset_after_seconds fallback 3. 如果 window_minutes 都不存在,使用传统假设 4. 添加详细注释说明这个陷阱 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修复 lint 问题 - 改进 fallback 逻辑的变量赋值 问题: 第882-883行的简单布尔赋值可能触发 ineffassign 或 staticcheck 警告: use5hFromSecondary = snapshot.SecondaryUsedPercent != nil use7dFromPrimary = snapshot.PrimaryUsedPercent != nil 修复: 改用明确的 if 语句检查任意字段是否存在,更符合代码意图: - 如果 secondary 的任意字段存在,将其视为 5h - 如果 primary 的任意字段存在,将其视为 7d 这样逻辑更清晰,也避免了 lint 警告。 --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com> Co-authored-by: OpenAI Codex <noreply@openai.com>
2025-12-25 17:00:02 +08:00
if (!extra) return null
// Prefer canonical field
if (extra.codex_7d_used_percent !== undefined) {
return extra.codex_7d_used_percent
}
// Fallback: detect from legacy fields using window_minutes
if (
extra.codex_primary_window_minutes !== undefined &&
extra.codex_primary_window_minutes >= 10000
) {
fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 (#30) * fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 问题描述: - 账号管理页面中,OpenAI OAuth 账号的 5h 列显示 7 天的剩余时间 - 7d 列却显示几小时的剩余时间 - 根本原因: OpenAI 响应头中 primary/secondary 的实际含义与代码假设相反 修复方案: 1. 后端归一化 (openai_gateway_service.go): - 根据 window_minutes 动态判断哪个是 5h/7d 限制 - 新增规范字段 codex_5h_* 和 codex_7d_* - 保留旧字段以兼容性 2. 前端适配 (AccountUsageCell.vue): - 优先使用新的规范字段 - Fallback 到旧字段时基于 window_minutes 动态判断 - 更新 computed 属性命名 3. 类型定义更新 (types/index.ts): - 添加新的规范字段定义 - 更新注释说明实际语义由 window_minutes 决定 🤖 Generated with Claude Code and Codex collaboration Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Co-Authored-By: OpenAI Codex <noreply@openai.com> * fix: 改进窗口判断逻辑,修复两个窗口都小于阈值时的bug 问题: 当两个窗口都小于360分钟时(如 primary=180分钟,secondary=300分钟), 之前的逻辑会导致: - primary5h = true, secondary5h = true - 5h 字段会使用 primary(错误) - 7d 字段没有数据(bug) 修复方案: 改用比较策略: 1. 当两个窗口都存在时:较小的分配给5h,较大的分配给7d 2. 当只有一个窗口时:根据大小(<=360分钟)判断是5h还是7d 3. 确保数据不会丢失,逻辑更健壮 示例: - Primary: 180分钟, Secondary: 300分钟 → 5h 使用 Primary(180分钟), 7d 使用 Secondary(300分钟) ✓ 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修正窗口大小判断逻辑 - 不能用剩余时间判断窗口类型 **严重bug修复:** 之前的 fallback 逻辑错误地使用 reset_after_seconds 来判断窗口大小。 问题示例: - 周限制(7d)剩余 2h → reset_after_seconds = 7200秒 - 5h限制 剩余 4h → reset_after_seconds = 14400秒 - 错误逻辑:7200/60 < 14400/60,把周限制当成5h ❌ 根本问题: - window_minutes = 窗口的总大小(300 or 10080) - reset_after_seconds = 距离重置的剩余时间(变化的) - 不能用剩余时间来判断窗口类型! 修复方案: 1. **只使用 window_minutes** 来判断窗口大小 2. 移除错误的 reset_after_seconds fallback 3. 如果 window_minutes 都不存在,使用传统假设 4. 添加详细注释说明这个陷阱 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修复 lint 问题 - 改进 fallback 逻辑的变量赋值 问题: 第882-883行的简单布尔赋值可能触发 ineffassign 或 staticcheck 警告: use5hFromSecondary = snapshot.SecondaryUsedPercent != nil use7dFromPrimary = snapshot.PrimaryUsedPercent != nil 修复: 改用明确的 if 语句检查任意字段是否存在,更符合代码意图: - 如果 secondary 的任意字段存在,将其视为 5h - 如果 primary 的任意字段存在,将其视为 7d 这样逻辑更清晰,也避免了 lint 警告。 --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com> Co-authored-by: OpenAI Codex <noreply@openai.com>
2025-12-25 17:00:02 +08:00
return extra.codex_primary_used_percent ?? null
}
if (
extra.codex_secondary_window_minutes !== undefined &&
extra.codex_secondary_window_minutes >= 10000
) {
fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 (#30) * fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 问题描述: - 账号管理页面中,OpenAI OAuth 账号的 5h 列显示 7 天的剩余时间 - 7d 列却显示几小时的剩余时间 - 根本原因: OpenAI 响应头中 primary/secondary 的实际含义与代码假设相反 修复方案: 1. 后端归一化 (openai_gateway_service.go): - 根据 window_minutes 动态判断哪个是 5h/7d 限制 - 新增规范字段 codex_5h_* 和 codex_7d_* - 保留旧字段以兼容性 2. 前端适配 (AccountUsageCell.vue): - 优先使用新的规范字段 - Fallback 到旧字段时基于 window_minutes 动态判断 - 更新 computed 属性命名 3. 类型定义更新 (types/index.ts): - 添加新的规范字段定义 - 更新注释说明实际语义由 window_minutes 决定 🤖 Generated with Claude Code and Codex collaboration Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Co-Authored-By: OpenAI Codex <noreply@openai.com> * fix: 改进窗口判断逻辑,修复两个窗口都小于阈值时的bug 问题: 当两个窗口都小于360分钟时(如 primary=180分钟,secondary=300分钟), 之前的逻辑会导致: - primary5h = true, secondary5h = true - 5h 字段会使用 primary(错误) - 7d 字段没有数据(bug) 修复方案: 改用比较策略: 1. 当两个窗口都存在时:较小的分配给5h,较大的分配给7d 2. 当只有一个窗口时:根据大小(<=360分钟)判断是5h还是7d 3. 确保数据不会丢失,逻辑更健壮 示例: - Primary: 180分钟, Secondary: 300分钟 → 5h 使用 Primary(180分钟), 7d 使用 Secondary(300分钟) ✓ 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修正窗口大小判断逻辑 - 不能用剩余时间判断窗口类型 **严重bug修复:** 之前的 fallback 逻辑错误地使用 reset_after_seconds 来判断窗口大小。 问题示例: - 周限制(7d)剩余 2h → reset_after_seconds = 7200秒 - 5h限制 剩余 4h → reset_after_seconds = 14400秒 - 错误逻辑:7200/60 < 14400/60,把周限制当成5h ❌ 根本问题: - window_minutes = 窗口的总大小(300 or 10080) - reset_after_seconds = 距离重置的剩余时间(变化的) - 不能用剩余时间来判断窗口类型! 修复方案: 1. **只使用 window_minutes** 来判断窗口大小 2. 移除错误的 reset_after_seconds fallback 3. 如果 window_minutes 都不存在,使用传统假设 4. 添加详细注释说明这个陷阱 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修复 lint 问题 - 改进 fallback 逻辑的变量赋值 问题: 第882-883行的简单布尔赋值可能触发 ineffassign 或 staticcheck 警告: use5hFromSecondary = snapshot.SecondaryUsedPercent != nil use7dFromPrimary = snapshot.PrimaryUsedPercent != nil 修复: 改用明确的 if 语句检查任意字段是否存在,更符合代码意图: - 如果 secondary 的任意字段存在,将其视为 5h - 如果 primary 的任意字段存在,将其视为 7d 这样逻辑更清晰,也避免了 lint 警告。 --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com> Co-authored-by: OpenAI Codex <noreply@openai.com>
2025-12-25 17:00:02 +08:00
return extra.codex_secondary_used_percent ?? null
}
// Legacy assumption: primary = 7d (may be incorrect)
return extra.codex_primary_used_percent ?? null
})
fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 (#30) * fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 问题描述: - 账号管理页面中,OpenAI OAuth 账号的 5h 列显示 7 天的剩余时间 - 7d 列却显示几小时的剩余时间 - 根本原因: OpenAI 响应头中 primary/secondary 的实际含义与代码假设相反 修复方案: 1. 后端归一化 (openai_gateway_service.go): - 根据 window_minutes 动态判断哪个是 5h/7d 限制 - 新增规范字段 codex_5h_* 和 codex_7d_* - 保留旧字段以兼容性 2. 前端适配 (AccountUsageCell.vue): - 优先使用新的规范字段 - Fallback 到旧字段时基于 window_minutes 动态判断 - 更新 computed 属性命名 3. 类型定义更新 (types/index.ts): - 添加新的规范字段定义 - 更新注释说明实际语义由 window_minutes 决定 🤖 Generated with Claude Code and Codex collaboration Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Co-Authored-By: OpenAI Codex <noreply@openai.com> * fix: 改进窗口判断逻辑,修复两个窗口都小于阈值时的bug 问题: 当两个窗口都小于360分钟时(如 primary=180分钟,secondary=300分钟), 之前的逻辑会导致: - primary5h = true, secondary5h = true - 5h 字段会使用 primary(错误) - 7d 字段没有数据(bug) 修复方案: 改用比较策略: 1. 当两个窗口都存在时:较小的分配给5h,较大的分配给7d 2. 当只有一个窗口时:根据大小(<=360分钟)判断是5h还是7d 3. 确保数据不会丢失,逻辑更健壮 示例: - Primary: 180分钟, Secondary: 300分钟 → 5h 使用 Primary(180分钟), 7d 使用 Secondary(300分钟) ✓ 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修正窗口大小判断逻辑 - 不能用剩余时间判断窗口类型 **严重bug修复:** 之前的 fallback 逻辑错误地使用 reset_after_seconds 来判断窗口大小。 问题示例: - 周限制(7d)剩余 2h → reset_after_seconds = 7200秒 - 5h限制 剩余 4h → reset_after_seconds = 14400秒 - 错误逻辑:7200/60 < 14400/60,把周限制当成5h ❌ 根本问题: - window_minutes = 窗口的总大小(300 or 10080) - reset_after_seconds = 距离重置的剩余时间(变化的) - 不能用剩余时间来判断窗口类型! 修复方案: 1. **只使用 window_minutes** 来判断窗口大小 2. 移除错误的 reset_after_seconds fallback 3. 如果 window_minutes 都不存在,使用传统假设 4. 添加详细注释说明这个陷阱 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修复 lint 问题 - 改进 fallback 逻辑的变量赋值 问题: 第882-883行的简单布尔赋值可能触发 ineffassign 或 staticcheck 警告: use5hFromSecondary = snapshot.SecondaryUsedPercent != nil use7dFromPrimary = snapshot.PrimaryUsedPercent != nil 修复: 改用明确的 if 语句检查任意字段是否存在,更符合代码意图: - 如果 secondary 的任意字段存在,将其视为 5h - 如果 primary 的任意字段存在,将其视为 7d 这样逻辑更清晰,也避免了 lint 警告。 --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com> Co-authored-by: OpenAI Codex <noreply@openai.com>
2025-12-25 17:00:02 +08:00
const codex7dResetAt = computed(() => {
const extra = props.account.extra
fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 (#30) * fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 问题描述: - 账号管理页面中,OpenAI OAuth 账号的 5h 列显示 7 天的剩余时间 - 7d 列却显示几小时的剩余时间 - 根本原因: OpenAI 响应头中 primary/secondary 的实际含义与代码假设相反 修复方案: 1. 后端归一化 (openai_gateway_service.go): - 根据 window_minutes 动态判断哪个是 5h/7d 限制 - 新增规范字段 codex_5h_* 和 codex_7d_* - 保留旧字段以兼容性 2. 前端适配 (AccountUsageCell.vue): - 优先使用新的规范字段 - Fallback 到旧字段时基于 window_minutes 动态判断 - 更新 computed 属性命名 3. 类型定义更新 (types/index.ts): - 添加新的规范字段定义 - 更新注释说明实际语义由 window_minutes 决定 🤖 Generated with Claude Code and Codex collaboration Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Co-Authored-By: OpenAI Codex <noreply@openai.com> * fix: 改进窗口判断逻辑,修复两个窗口都小于阈值时的bug 问题: 当两个窗口都小于360分钟时(如 primary=180分钟,secondary=300分钟), 之前的逻辑会导致: - primary5h = true, secondary5h = true - 5h 字段会使用 primary(错误) - 7d 字段没有数据(bug) 修复方案: 改用比较策略: 1. 当两个窗口都存在时:较小的分配给5h,较大的分配给7d 2. 当只有一个窗口时:根据大小(<=360分钟)判断是5h还是7d 3. 确保数据不会丢失,逻辑更健壮 示例: - Primary: 180分钟, Secondary: 300分钟 → 5h 使用 Primary(180分钟), 7d 使用 Secondary(300分钟) ✓ 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修正窗口大小判断逻辑 - 不能用剩余时间判断窗口类型 **严重bug修复:** 之前的 fallback 逻辑错误地使用 reset_after_seconds 来判断窗口大小。 问题示例: - 周限制(7d)剩余 2h → reset_after_seconds = 7200秒 - 5h限制 剩余 4h → reset_after_seconds = 14400秒 - 错误逻辑:7200/60 < 14400/60,把周限制当成5h ❌ 根本问题: - window_minutes = 窗口的总大小(300 or 10080) - reset_after_seconds = 距离重置的剩余时间(变化的) - 不能用剩余时间来判断窗口类型! 修复方案: 1. **只使用 window_minutes** 来判断窗口大小 2. 移除错误的 reset_after_seconds fallback 3. 如果 window_minutes 都不存在,使用传统假设 4. 添加详细注释说明这个陷阱 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修复 lint 问题 - 改进 fallback 逻辑的变量赋值 问题: 第882-883行的简单布尔赋值可能触发 ineffassign 或 staticcheck 警告: use5hFromSecondary = snapshot.SecondaryUsedPercent != nil use7dFromPrimary = snapshot.PrimaryUsedPercent != nil 修复: 改用明确的 if 语句检查任意字段是否存在,更符合代码意图: - 如果 secondary 的任意字段存在,将其视为 5h - 如果 primary 的任意字段存在,将其视为 7d 这样逻辑更清晰,也避免了 lint 警告。 --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com> Co-authored-by: OpenAI Codex <noreply@openai.com>
2025-12-25 17:00:02 +08:00
if (!extra) return null
// Prefer canonical field
if (extra.codex_7d_reset_after_seconds !== undefined) {
const resetTime = new Date(Date.now() + extra.codex_7d_reset_after_seconds * 1000)
return resetTime.toISOString()
}
// Fallback: detect from legacy fields using window_minutes
if (
extra.codex_primary_window_minutes !== undefined &&
extra.codex_primary_window_minutes >= 10000
) {
fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 (#30) * fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 问题描述: - 账号管理页面中,OpenAI OAuth 账号的 5h 列显示 7 天的剩余时间 - 7d 列却显示几小时的剩余时间 - 根本原因: OpenAI 响应头中 primary/secondary 的实际含义与代码假设相反 修复方案: 1. 后端归一化 (openai_gateway_service.go): - 根据 window_minutes 动态判断哪个是 5h/7d 限制 - 新增规范字段 codex_5h_* 和 codex_7d_* - 保留旧字段以兼容性 2. 前端适配 (AccountUsageCell.vue): - 优先使用新的规范字段 - Fallback 到旧字段时基于 window_minutes 动态判断 - 更新 computed 属性命名 3. 类型定义更新 (types/index.ts): - 添加新的规范字段定义 - 更新注释说明实际语义由 window_minutes 决定 🤖 Generated with Claude Code and Codex collaboration Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Co-Authored-By: OpenAI Codex <noreply@openai.com> * fix: 改进窗口判断逻辑,修复两个窗口都小于阈值时的bug 问题: 当两个窗口都小于360分钟时(如 primary=180分钟,secondary=300分钟), 之前的逻辑会导致: - primary5h = true, secondary5h = true - 5h 字段会使用 primary(错误) - 7d 字段没有数据(bug) 修复方案: 改用比较策略: 1. 当两个窗口都存在时:较小的分配给5h,较大的分配给7d 2. 当只有一个窗口时:根据大小(<=360分钟)判断是5h还是7d 3. 确保数据不会丢失,逻辑更健壮 示例: - Primary: 180分钟, Secondary: 300分钟 → 5h 使用 Primary(180分钟), 7d 使用 Secondary(300分钟) ✓ 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修正窗口大小判断逻辑 - 不能用剩余时间判断窗口类型 **严重bug修复:** 之前的 fallback 逻辑错误地使用 reset_after_seconds 来判断窗口大小。 问题示例: - 周限制(7d)剩余 2h → reset_after_seconds = 7200秒 - 5h限制 剩余 4h → reset_after_seconds = 14400秒 - 错误逻辑:7200/60 < 14400/60,把周限制当成5h ❌ 根本问题: - window_minutes = 窗口的总大小(300 or 10080) - reset_after_seconds = 距离重置的剩余时间(变化的) - 不能用剩余时间来判断窗口类型! 修复方案: 1. **只使用 window_minutes** 来判断窗口大小 2. 移除错误的 reset_after_seconds fallback 3. 如果 window_minutes 都不存在,使用传统假设 4. 添加详细注释说明这个陷阱 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修复 lint 问题 - 改进 fallback 逻辑的变量赋值 问题: 第882-883行的简单布尔赋值可能触发 ineffassign 或 staticcheck 警告: use5hFromSecondary = snapshot.SecondaryUsedPercent != nil use7dFromPrimary = snapshot.PrimaryUsedPercent != nil 修复: 改用明确的 if 语句检查任意字段是否存在,更符合代码意图: - 如果 secondary 的任意字段存在,将其视为 5h - 如果 primary 的任意字段存在,将其视为 7d 这样逻辑更清晰,也避免了 lint 警告。 --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com> Co-authored-by: OpenAI Codex <noreply@openai.com>
2025-12-25 17:00:02 +08:00
if (extra.codex_primary_reset_after_seconds !== undefined) {
const resetTime = new Date(Date.now() + extra.codex_primary_reset_after_seconds * 1000)
return resetTime.toISOString()
}
}
if (
extra.codex_secondary_window_minutes !== undefined &&
extra.codex_secondary_window_minutes >= 10000
) {
fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 (#30) * fix: 修复 OpenAI 账号 5h/7d 使用限制显示错误的问题 问题描述: - 账号管理页面中,OpenAI OAuth 账号的 5h 列显示 7 天的剩余时间 - 7d 列却显示几小时的剩余时间 - 根本原因: OpenAI 响应头中 primary/secondary 的实际含义与代码假设相反 修复方案: 1. 后端归一化 (openai_gateway_service.go): - 根据 window_minutes 动态判断哪个是 5h/7d 限制 - 新增规范字段 codex_5h_* 和 codex_7d_* - 保留旧字段以兼容性 2. 前端适配 (AccountUsageCell.vue): - 优先使用新的规范字段 - Fallback 到旧字段时基于 window_minutes 动态判断 - 更新 computed 属性命名 3. 类型定义更新 (types/index.ts): - 添加新的规范字段定义 - 更新注释说明实际语义由 window_minutes 决定 🤖 Generated with Claude Code and Codex collaboration Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Co-Authored-By: OpenAI Codex <noreply@openai.com> * fix: 改进窗口判断逻辑,修复两个窗口都小于阈值时的bug 问题: 当两个窗口都小于360分钟时(如 primary=180分钟,secondary=300分钟), 之前的逻辑会导致: - primary5h = true, secondary5h = true - 5h 字段会使用 primary(错误) - 7d 字段没有数据(bug) 修复方案: 改用比较策略: 1. 当两个窗口都存在时:较小的分配给5h,较大的分配给7d 2. 当只有一个窗口时:根据大小(<=360分钟)判断是5h还是7d 3. 确保数据不会丢失,逻辑更健壮 示例: - Primary: 180分钟, Secondary: 300分钟 → 5h 使用 Primary(180分钟), 7d 使用 Secondary(300分钟) ✓ 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修正窗口大小判断逻辑 - 不能用剩余时间判断窗口类型 **严重bug修复:** 之前的 fallback 逻辑错误地使用 reset_after_seconds 来判断窗口大小。 问题示例: - 周限制(7d)剩余 2h → reset_after_seconds = 7200秒 - 5h限制 剩余 4h → reset_after_seconds = 14400秒 - 错误逻辑:7200/60 < 14400/60,把周限制当成5h ❌ 根本问题: - window_minutes = 窗口的总大小(300 or 10080) - reset_after_seconds = 距离重置的剩余时间(变化的) - 不能用剩余时间来判断窗口类型! 修复方案: 1. **只使用 window_minutes** 来判断窗口大小 2. 移除错误的 reset_after_seconds fallback 3. 如果 window_minutes 都不存在,使用传统假设 4. 添加详细注释说明这个陷阱 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: 修复 lint 问题 - 改进 fallback 逻辑的变量赋值 问题: 第882-883行的简单布尔赋值可能触发 ineffassign 或 staticcheck 警告: use5hFromSecondary = snapshot.SecondaryUsedPercent != nil use7dFromPrimary = snapshot.PrimaryUsedPercent != nil 修复: 改用明确的 if 语句检查任意字段是否存在,更符合代码意图: - 如果 secondary 的任意字段存在,将其视为 5h - 如果 primary 的任意字段存在,将其视为 7d 这样逻辑更清晰,也避免了 lint 警告。 --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com> Co-authored-by: OpenAI Codex <noreply@openai.com>
2025-12-25 17:00:02 +08:00
if (extra.codex_secondary_reset_after_seconds !== undefined) {
const resetTime = new Date(Date.now() + extra.codex_secondary_reset_after_seconds * 1000)
return resetTime.toISOString()
}
}
// Legacy assumption: primary = 7d
if (extra.codex_primary_reset_after_seconds !== undefined) {
const resetTime = new Date(Date.now() + extra.codex_primary_reset_after_seconds * 1000)
return resetTime.toISOString()
}
return null
})
// Antigravity quota types (用于 API 返回的数据)
interface AntigravityUsageResult {
utilization: number
resetTime: string | null
}
// ===== Antigravity quota from API (usageInfo.antigravity_quota) =====
// 检查是否有从 API 获取的配额数据
const hasAntigravityQuotaFromAPI = computed(() => {
return usageInfo.value?.antigravity_quota && Object.keys(usageInfo.value.antigravity_quota).length > 0
})
// 从 API 配额数据中获取使用率(多模型取最高使用率)
const getAntigravityUsageFromAPI = (
modelNames: string[]
): AntigravityUsageResult | null => {
const quota = usageInfo.value?.antigravity_quota
if (!quota) return null
let maxUtilization = 0
let earliestReset: string | null = null
for (const model of modelNames) {
const modelQuota = quota[model]
if (!modelQuota) continue
if (modelQuota.utilization > maxUtilization) {
maxUtilization = modelQuota.utilization
}
if (modelQuota.reset_time) {
if (!earliestReset || modelQuota.reset_time < earliestReset) {
earliestReset = modelQuota.reset_time
}
}
}
// 如果没有找到任何匹配的模型
if (maxUtilization === 0 && earliestReset === null) {
const hasAnyData = modelNames.some((m) => quota[m])
if (!hasAnyData) return null
}
return {
utilization: maxUtilization,
resetTime: earliestReset
}
}
// Gemini 3 Pro from API
const antigravity3ProUsageFromAPI = computed(() =>
getAntigravityUsageFromAPI(['gemini-3-pro-low', 'gemini-3-pro-high', 'gemini-3-pro-preview'])
)
// Gemini 3 Flash from API
const antigravity3FlashUsageFromAPI = computed(() => getAntigravityUsageFromAPI(['gemini-3-flash']))
// Gemini 3 Image from API
const antigravity3ImageUsageFromAPI = computed(() => getAntigravityUsageFromAPI(['gemini-3-pro-image']))
// Claude 4.5 from API
const antigravityClaude45UsageFromAPI = computed(() =>
getAntigravityUsageFromAPI(['claude-sonnet-4-5', 'claude-opus-4-5-thinking'])
)
// Antigravity 账户类型(从 load_code_assist 响应中提取)
const antigravityTier = computed(() => {
const extra = props.account.extra as Record<string, unknown> | undefined
if (!extra) return null
const loadCodeAssist = extra.load_code_assist as Record<string, unknown> | undefined
if (!loadCodeAssist) return null
// 优先取 paidTier否则取 currentTier
const paidTier = loadCodeAssist.paidTier as Record<string, unknown> | undefined
if (paidTier && typeof paidTier.id === 'string') {
return paidTier.id
}
const currentTier = loadCodeAssist.currentTier as Record<string, unknown> | undefined
if (currentTier && typeof currentTier.id === 'string') {
return currentTier.id
}
return null
})
// Gemini 账户类型(从 credentials 中提取)
const geminiTier = computed(() => {
if (props.account.platform !== 'gemini') return null
const creds = props.account.credentials as GeminiCredentials | undefined
return creds?.tier_id || null
})
// Gemini 是否为 Code Assist OAuth
const isGeminiCodeAssist = computed(() => {
if (props.account.platform !== 'gemini') return false
const creds = props.account.credentials as GeminiCredentials | undefined
return creds?.oauth_type === 'code_assist' || (!creds?.oauth_type && !!creds?.project_id)
})
// Gemini 认证类型 + Tier 组合标签(简洁版)
const geminiAuthTypeLabel = computed(() => {
feat(gemini): 添加 Google One 存储空间推断 Tier 功能 ## 功能概述 通过 Google Drive API 获取存储空间配额来推断 Google One 订阅等级,并优化统一的配额显示系统。 ## 后端改动 - 新增 Drive API 客户端 (drive_client.go) - 支持代理和指数退避重试 - 处理 403/429 错误 - 添加 Tier 推断逻辑 (inferGoogleOneTier) - 支持 6 种 tier 类型:AI_PREMIUM, GOOGLE_ONE_STANDARD, GOOGLE_ONE_BASIC, FREE, GOOGLE_ONE_UNKNOWN, GOOGLE_ONE_UNLIMITED - 集成到 OAuth 流程 - ExchangeCode: 授权时自动获取 tier - RefreshAccountToken: Token 刷新时更新 tier (24小时缓存) - 新增管理 API 端点 - POST /api/v1/admin/accounts/:id/refresh-tier (单个账号刷新) - POST /api/v1/admin/accounts/batch-refresh-tier (批量刷新) ## 前端改动 - 更新 AccountQuotaInfo.vue - 添加 Google One tier 标签映射 - 添加 tier 颜色样式 (紫色/蓝色/绿色/灰色/琥珀色) - 更新 AccountUsageCell.vue - 添加 Google One tier 显示逻辑 - 根据 oauth_type 区分显示方式 - 添加国际化翻译 (en.ts, zh.ts) - aiPremium, standard, basic, free, personal, unlimited ## Tier 推断规则 - >= 2TB: AI Premium - >= 200GB: Google One Standard - >= 100GB: Google One Basic - >= 15GB: Free - > 100TB: Unlimited (G Suite legacy) - 其他/失败: Unknown (显示为 Personal) ## 优雅降级 - Drive API 失败时使用 GOOGLE_ONE_UNKNOWN - 不阻断 OAuth 流程 - 24小时缓存避免频繁调用 ## 测试 - ✅ 后端编译成功 - ✅ 前端构建成功 - ✅ 所有代码符合现有规范
2025-12-31 21:45:24 -08:00
const creds = props.account.credentials as GeminiCredentials | undefined
const oauthType = creds?.oauth_type
feat(gemini): 添加 Google One 存储空间推断 Tier 功能 ## 功能概述 通过 Google Drive API 获取存储空间配额来推断 Google One 订阅等级,并优化统一的配额显示系统。 ## 后端改动 - 新增 Drive API 客户端 (drive_client.go) - 支持代理和指数退避重试 - 处理 403/429 错误 - 添加 Tier 推断逻辑 (inferGoogleOneTier) - 支持 6 种 tier 类型:AI_PREMIUM, GOOGLE_ONE_STANDARD, GOOGLE_ONE_BASIC, FREE, GOOGLE_ONE_UNKNOWN, GOOGLE_ONE_UNLIMITED - 集成到 OAuth 流程 - ExchangeCode: 授权时自动获取 tier - RefreshAccountToken: Token 刷新时更新 tier (24小时缓存) - 新增管理 API 端点 - POST /api/v1/admin/accounts/:id/refresh-tier (单个账号刷新) - POST /api/v1/admin/accounts/batch-refresh-tier (批量刷新) ## 前端改动 - 更新 AccountQuotaInfo.vue - 添加 Google One tier 标签映射 - 添加 tier 颜色样式 (紫色/蓝色/绿色/灰色/琥珀色) - 更新 AccountUsageCell.vue - 添加 Google One tier 显示逻辑 - 根据 oauth_type 区分显示方式 - 添加国际化翻译 (en.ts, zh.ts) - aiPremium, standard, basic, free, personal, unlimited ## Tier 推断规则 - >= 2TB: AI Premium - >= 200GB: Google One Standard - >= 100GB: Google One Basic - >= 15GB: Free - > 100TB: Unlimited (G Suite legacy) - 其他/失败: Unknown (显示为 Personal) ## 优雅降级 - Drive API 失败时使用 GOOGLE_ONE_UNKNOWN - 不阻断 OAuth 流程 - 24小时缓存避免频繁调用 ## 测试 - ✅ 后端编译成功 - ✅ 前端构建成功 - ✅ 所有代码符合现有规范
2025-12-31 21:45:24 -08:00
// For API Key accounts, don't show auth type label
if (props.account.type !== 'oauth') return null
if (oauthType === 'google_one') {
// Google One: show "Google One" + tier
feat(gemini): 添加 Google One 存储空间推断 Tier 功能 ## 功能概述 通过 Google Drive API 获取存储空间配额来推断 Google One 订阅等级,并优化统一的配额显示系统。 ## 后端改动 - 新增 Drive API 客户端 (drive_client.go) - 支持代理和指数退避重试 - 处理 403/429 错误 - 添加 Tier 推断逻辑 (inferGoogleOneTier) - 支持 6 种 tier 类型:AI_PREMIUM, GOOGLE_ONE_STANDARD, GOOGLE_ONE_BASIC, FREE, GOOGLE_ONE_UNKNOWN, GOOGLE_ONE_UNLIMITED - 集成到 OAuth 流程 - ExchangeCode: 授权时自动获取 tier - RefreshAccountToken: Token 刷新时更新 tier (24小时缓存) - 新增管理 API 端点 - POST /api/v1/admin/accounts/:id/refresh-tier (单个账号刷新) - POST /api/v1/admin/accounts/batch-refresh-tier (批量刷新) ## 前端改动 - 更新 AccountQuotaInfo.vue - 添加 Google One tier 标签映射 - 添加 tier 颜色样式 (紫色/蓝色/绿色/灰色/琥珀色) - 更新 AccountUsageCell.vue - 添加 Google One tier 显示逻辑 - 根据 oauth_type 区分显示方式 - 添加国际化翻译 (en.ts, zh.ts) - aiPremium, standard, basic, free, personal, unlimited ## Tier 推断规则 - >= 2TB: AI Premium - >= 200GB: Google One Standard - >= 100GB: Google One Basic - >= 15GB: Free - > 100TB: Unlimited (G Suite legacy) - 其他/失败: Unknown (显示为 Personal) ## 优雅降级 - Drive API 失败时使用 GOOGLE_ONE_UNKNOWN - 不阻断 OAuth 流程 - 24小时缓存避免频繁调用 ## 测试 - ✅ 后端编译成功 - ✅ 前端构建成功 - ✅ 所有代码符合现有规范
2025-12-31 21:45:24 -08:00
const tierMap: Record<string, string> = {
AI_PREMIUM: 'AI Premium',
GOOGLE_ONE_STANDARD: 'Standard',
GOOGLE_ONE_BASIC: 'Basic',
FREE: 'Free',
GOOGLE_ONE_UNKNOWN: 'Personal',
GOOGLE_ONE_UNLIMITED: 'Unlimited'
feat(gemini): 添加 Google One 存储空间推断 Tier 功能 ## 功能概述 通过 Google Drive API 获取存储空间配额来推断 Google One 订阅等级,并优化统一的配额显示系统。 ## 后端改动 - 新增 Drive API 客户端 (drive_client.go) - 支持代理和指数退避重试 - 处理 403/429 错误 - 添加 Tier 推断逻辑 (inferGoogleOneTier) - 支持 6 种 tier 类型:AI_PREMIUM, GOOGLE_ONE_STANDARD, GOOGLE_ONE_BASIC, FREE, GOOGLE_ONE_UNKNOWN, GOOGLE_ONE_UNLIMITED - 集成到 OAuth 流程 - ExchangeCode: 授权时自动获取 tier - RefreshAccountToken: Token 刷新时更新 tier (24小时缓存) - 新增管理 API 端点 - POST /api/v1/admin/accounts/:id/refresh-tier (单个账号刷新) - POST /api/v1/admin/accounts/batch-refresh-tier (批量刷新) ## 前端改动 - 更新 AccountQuotaInfo.vue - 添加 Google One tier 标签映射 - 添加 tier 颜色样式 (紫色/蓝色/绿色/灰色/琥珀色) - 更新 AccountUsageCell.vue - 添加 Google One tier 显示逻辑 - 根据 oauth_type 区分显示方式 - 添加国际化翻译 (en.ts, zh.ts) - aiPremium, standard, basic, free, personal, unlimited ## Tier 推断规则 - >= 2TB: AI Premium - >= 200GB: Google One Standard - >= 100GB: Google One Basic - >= 15GB: Free - > 100TB: Unlimited (G Suite legacy) - 其他/失败: Unknown (显示为 Personal) ## 优雅降级 - Drive API 失败时使用 GOOGLE_ONE_UNKNOWN - 不阻断 OAuth 流程 - 24小时缓存避免频繁调用 ## 测试 - ✅ 后端编译成功 - ✅ 前端构建成功 - ✅ 所有代码符合现有规范
2025-12-31 21:45:24 -08:00
}
const tierLabel = geminiTier.value ? tierMap[geminiTier.value] || 'Personal' : 'Personal'
return `Google One ${tierLabel}`
} else if (oauthType === 'code_assist' || (!oauthType && isGeminiCodeAssist.value)) {
// Code Assist: show "GCP" + tier
const tierMap: Record<string, string> = {
LEGACY: 'Free',
PRO: 'Pro',
ULTRA: 'Ultra'
}
const tierLabel = geminiTier.value ? tierMap[geminiTier.value] || 'Free' : 'Free'
return `GCP ${tierLabel}`
} else if (oauthType === 'ai_studio') {
// 自定义 OAuth Client: show "Client" (no tier)
return 'Client'
feat(gemini): 添加 Google One 存储空间推断 Tier 功能 ## 功能概述 通过 Google Drive API 获取存储空间配额来推断 Google One 订阅等级,并优化统一的配额显示系统。 ## 后端改动 - 新增 Drive API 客户端 (drive_client.go) - 支持代理和指数退避重试 - 处理 403/429 错误 - 添加 Tier 推断逻辑 (inferGoogleOneTier) - 支持 6 种 tier 类型:AI_PREMIUM, GOOGLE_ONE_STANDARD, GOOGLE_ONE_BASIC, FREE, GOOGLE_ONE_UNKNOWN, GOOGLE_ONE_UNLIMITED - 集成到 OAuth 流程 - ExchangeCode: 授权时自动获取 tier - RefreshAccountToken: Token 刷新时更新 tier (24小时缓存) - 新增管理 API 端点 - POST /api/v1/admin/accounts/:id/refresh-tier (单个账号刷新) - POST /api/v1/admin/accounts/batch-refresh-tier (批量刷新) ## 前端改动 - 更新 AccountQuotaInfo.vue - 添加 Google One tier 标签映射 - 添加 tier 颜色样式 (紫色/蓝色/绿色/灰色/琥珀色) - 更新 AccountUsageCell.vue - 添加 Google One tier 显示逻辑 - 根据 oauth_type 区分显示方式 - 添加国际化翻译 (en.ts, zh.ts) - aiPremium, standard, basic, free, personal, unlimited ## Tier 推断规则 - >= 2TB: AI Premium - >= 200GB: Google One Standard - >= 100GB: Google One Basic - >= 15GB: Free - > 100TB: Unlimited (G Suite legacy) - 其他/失败: Unknown (显示为 Personal) ## 优雅降级 - Drive API 失败时使用 GOOGLE_ONE_UNKNOWN - 不阻断 OAuth 流程 - 24小时缓存避免频繁调用 ## 测试 - ✅ 后端编译成功 - ✅ 前端构建成功 - ✅ 所有代码符合现有规范
2025-12-31 21:45:24 -08:00
}
return null
})
// Gemini 账户类型徽章样式
const geminiTierClass = computed(() => {
const creds = props.account.credentials as GeminiCredentials | undefined
const oauthType = creds?.oauth_type
// AI Studio: use neutral gray color (no tier)
if (oauthType === 'ai_studio') {
return 'bg-gray-100 text-gray-600 dark:bg-gray-700 dark:text-gray-300'
}
feat(gemini): 添加 Google One 存储空间推断 Tier 功能 ## 功能概述 通过 Google Drive API 获取存储空间配额来推断 Google One 订阅等级,并优化统一的配额显示系统。 ## 后端改动 - 新增 Drive API 客户端 (drive_client.go) - 支持代理和指数退避重试 - 处理 403/429 错误 - 添加 Tier 推断逻辑 (inferGoogleOneTier) - 支持 6 种 tier 类型:AI_PREMIUM, GOOGLE_ONE_STANDARD, GOOGLE_ONE_BASIC, FREE, GOOGLE_ONE_UNKNOWN, GOOGLE_ONE_UNLIMITED - 集成到 OAuth 流程 - ExchangeCode: 授权时自动获取 tier - RefreshAccountToken: Token 刷新时更新 tier (24小时缓存) - 新增管理 API 端点 - POST /api/v1/admin/accounts/:id/refresh-tier (单个账号刷新) - POST /api/v1/admin/accounts/batch-refresh-tier (批量刷新) ## 前端改动 - 更新 AccountQuotaInfo.vue - 添加 Google One tier 标签映射 - 添加 tier 颜色样式 (紫色/蓝色/绿色/灰色/琥珀色) - 更新 AccountUsageCell.vue - 添加 Google One tier 显示逻辑 - 根据 oauth_type 区分显示方式 - 添加国际化翻译 (en.ts, zh.ts) - aiPremium, standard, basic, free, personal, unlimited ## Tier 推断规则 - >= 2TB: AI Premium - >= 200GB: Google One Standard - >= 100GB: Google One Basic - >= 15GB: Free - > 100TB: Unlimited (G Suite legacy) - 其他/失败: Unknown (显示为 Personal) ## 优雅降级 - Drive API 失败时使用 GOOGLE_ONE_UNKNOWN - 不阻断 OAuth 流程 - 24小时缓存避免频繁调用 ## 测试 - ✅ 后端编译成功 - ✅ 前端构建成功 - ✅ 所有代码符合现有规范
2025-12-31 21:45:24 -08:00
if (!geminiTier.value) return ''
const isGoogleOne = creds?.oauth_type === 'google_one'
if (isGoogleOne) {
// Google One tier 颜色
const colorMap: Record<string, string> = {
AI_PREMIUM: 'bg-purple-100 text-purple-600 dark:bg-purple-900/40 dark:text-purple-300',
GOOGLE_ONE_STANDARD: 'bg-blue-100 text-blue-600 dark:bg-blue-900/40 dark:text-blue-300',
GOOGLE_ONE_BASIC: 'bg-green-100 text-green-600 dark:bg-green-900/40 dark:text-green-300',
FREE: 'bg-gray-100 text-gray-600 dark:bg-gray-700 dark:text-gray-300',
GOOGLE_ONE_UNKNOWN: 'bg-gray-100 text-gray-600 dark:bg-gray-700 dark:text-gray-300',
GOOGLE_ONE_UNLIMITED: 'bg-amber-100 text-amber-600 dark:bg-amber-900/40 dark:text-amber-300'
}
return colorMap[geminiTier.value] || 'bg-gray-100 text-gray-600 dark:bg-gray-700 dark:text-gray-300'
}
// Code Assist tier 颜色
switch (geminiTier.value) {
case 'LEGACY':
return 'bg-gray-100 text-gray-600 dark:bg-gray-700 dark:text-gray-300'
case 'PRO':
return 'bg-blue-100 text-blue-600 dark:bg-blue-900/40 dark:text-blue-300'
case 'ULTRA':
return 'bg-purple-100 text-purple-600 dark:bg-purple-900/40 dark:text-purple-300'
default:
return ''
}
})
// Gemini 配额政策信息
const geminiQuotaPolicyChannel = computed(() => {
if (isGeminiCodeAssist.value) {
return t('admin.accounts.gemini.quotaPolicy.rows.cli.channel')
}
return t('admin.accounts.gemini.quotaPolicy.rows.aiStudio.channel')
})
const geminiQuotaPolicyLimits = computed(() => {
if (isGeminiCodeAssist.value) {
if (geminiTier.value === 'PRO' || geminiTier.value === 'ULTRA') {
return t('admin.accounts.gemini.quotaPolicy.rows.cli.limitsPremium')
}
return t('admin.accounts.gemini.quotaPolicy.rows.cli.limitsFree')
}
// AI Studio - 默认显示免费层限制
return t('admin.accounts.gemini.quotaPolicy.rows.aiStudio.limitsFree')
})
const geminiQuotaPolicyDocsUrl = computed(() => {
if (isGeminiCodeAssist.value) {
return 'https://cloud.google.com/products/gemini/code-assist#pricing'
}
return 'https://ai.google.dev/pricing'
})
// 账户类型显示标签
const antigravityTierLabel = computed(() => {
switch (antigravityTier.value) {
case 'free-tier':
return t('admin.accounts.tier.free')
case 'g1-pro-tier':
return t('admin.accounts.tier.pro')
case 'g1-ultra-tier':
return t('admin.accounts.tier.ultra')
default:
return null
}
})
// 账户类型徽章样式
const antigravityTierClass = computed(() => {
switch (antigravityTier.value) {
case 'free-tier':
return 'bg-gray-100 text-gray-600 dark:bg-gray-700 dark:text-gray-300'
case 'g1-pro-tier':
return 'bg-blue-100 text-blue-600 dark:bg-blue-900/40 dark:text-blue-300'
case 'g1-ultra-tier':
return 'bg-purple-100 text-purple-600 dark:bg-purple-900/40 dark:text-purple-300'
default:
return ''
}
})
// 检测账户是否有不合格状态ineligibleTiers
const hasIneligibleTiers = computed(() => {
const extra = props.account.extra as Record<string, unknown> | undefined
if (!extra) return false
const loadCodeAssist = extra.load_code_assist as Record<string, unknown> | undefined
if (!loadCodeAssist) return false
const ineligibleTiers = loadCodeAssist.ineligibleTiers as unknown[] | undefined
return Array.isArray(ineligibleTiers) && ineligibleTiers.length > 0
})
2025-12-18 13:50:39 +08:00
const loadUsage = async () => {
if (!shouldFetchUsage.value) return
2025-12-18 13:50:39 +08:00
loading.value = true
error.value = null
try {
usageInfo.value = await adminAPI.accounts.getUsage(props.account.id)
} catch (e: any) {
feat(frontend): 前端界面优化与使用统计功能增强 (#46) * feat(frontend): 前端界面优化与使用统计功能增强 主要改动: 1. 表格布局统一优化 - 新增 TablePageLayout 通用布局组件 - 统一所有管理页面的表格样式和交互 - 优化 DataTable、Pagination、Select 等通用组件 2. 使用统计功能增强 - 管理端: 添加完整的筛选和显示功能 - 用户端: 完善 API Key 列显示 - 后端: 优化使用统计数据结构和查询 3. 账户组件优化 - 优化 AccountStatsModal、AccountUsageCell 等组件 - 统一进度条和统计显示样式 4. 其他改进 - 完善中英文国际化 - 统一页面样式和交互体验 - 优化各视图页面的响应式布局 * fix(test): 修复 stubUsageLogRepo.ListWithFilters 测试 stub 测试用例 GET /api/v1/usage 返回 500 是因为 stub 方法未实现, 现在正确返回基于 UserID 过滤的日志数据。 * feat(frontend): 统一日期时间显示格式 **主要改动**: 1. 增强 utils/format.ts: - 新增 formatDateOnly() - 格式: YYYY-MM-DD - 新增 formatDateTime() - 格式: YYYY-MM-DD HH:mm:ss 2. 全局替换视图中的格式化函数: - 移除各视图中的自定义 formatDate 函数 - 统一导入使用 @/utils/format 中的函数 - created_at/updated_at 使用 formatDateTime - expires_at 使用 formatDateOnly 3. 受影响的视图 (8个): - frontend/src/views/user/KeysView.vue - frontend/src/views/user/DashboardView.vue - frontend/src/views/user/UsageView.vue - frontend/src/views/user/RedeemView.vue - frontend/src/views/admin/UsersView.vue - frontend/src/views/admin/UsageView.vue - frontend/src/views/admin/RedeemView.vue - frontend/src/views/admin/SubscriptionsView.vue **效果**: - 日期统一显示为 YYYY-MM-DD - 时间统一显示为 YYYY-MM-DD HH:mm:ss - 提升可维护性,避免格式不一致 * fix(frontend): 补充遗漏的时间格式化统一 **补充修复**(基于 code review 发现的遗漏): 1. 增强 utils/format.ts: - 新增 formatTime() - 格式: HH:mm 2. 修复 4 个遗漏的文件: - src/views/admin/UsersView.vue * 删除 formatExpiresAt(),改用 formatDateTime() * 修复订阅过期时间 tooltip 显示格式不一致问题 - src/views/user/ProfileView.vue * 删除 formatMemberSince(),改用 formatDate(date, 'YYYY-MM') * 统一会员起始时间显示格式 - src/views/user/SubscriptionsView.vue * 修改 formatExpirationDate() 使用 formatDateOnly() * 保留天数计算逻辑 - src/components/account/AccountStatusIndicator.vue * 删除本地 formatTime(),改用 utils/format 中的统一函数 * 修复 rate limit 和 overload 重置时间显示 **验证**: - TypeScript 类型检查通过 ✓ - 前端构建成功 ✓ - 所有剩余的 toLocaleString() 都是数字格式化,属于正确用法 ✓ **效果**: - 订阅过期时间统一为 YYYY-MM-DD HH:mm:ss - 会员起始时间统一为 YYYY-MM - 重置时间统一为 HH:mm - 消除所有不规范的原生 locale 方法调用
2025-12-27 10:50:25 +08:00
error.value = t('common.error')
2025-12-18 13:50:39 +08:00
console.error('Failed to load usage:', e)
} finally {
loading.value = false
}
}
onMounted(() => {
loadUsage()
})
</script>