Compare commits

..
7 Commits
Author SHA1 Message Date
ZyyandCodex e9627168a7 chore: bump version to 3.54.1
Co-authored-by: Codex <noreply@openai.com>
2026-11-21 12:02:26 +08:00
Zyy 5a4f49036b feat(frontend): share model access controls and separate request country settings
Let accounts and groups manage model lists with the same editor, including custom IDs and common image models. Tighten spacing in the group form and give the request country policy its own settings card.
2026-11-21 11:52:45 +08:00
ZyyandCodex 8041ddab65 refactor(frontend): consolidate chart, form, icon and proxy display rules
Co-authored-by: Codex <noreply@openai.com>
2026-11-21 10:55:06 +08:00
ZyyandCodex e645d6d4c9 fix(usage): unify timestamp columns across record tables
Co-authored-by: Codex <noreply@openai.com>
2026-11-21 10:55:01 +08:00
ZyyandCodex 5079700190 fix(ui): update shared UI to v0.13.1 for WebKit tables
Co-authored-by: Codex <noreply@openai.com>
2026-11-21 10:38:38 +08:00
ZyyandCodex 4db65d8e12 chore(deploy): update PostgreSQL to 18.7 and Redis to 8.10.3
Co-authored-by: Codex <noreply@openai.com>
2026-11-20 23:25:43 +08:00
github-actions[bot] da866de2c7 chore(release): update release channels to 3.54.0 2026-11-20 14:45:41 +00:00
42 changed files with 366 additions and 407 deletions
+2 -2
View File
@@ -35,7 +35,7 @@ jobs:
CPR_TEST_REDIS_URL: redis://127.0.0.1:6379
services:
postgres:
image: postgres:18-bookworm@sha256:bbf83594798e144bff365a9c191c5d779f181fb3135902064ab8ff11918020fc
image: postgres:18-bookworm@sha256:194e55feb2597b1465dbee81cc9fd8d204566cd2eb42c8d22fd6c931a38781b1
env:
POSTGRES_DB: codex_proxy
POSTGRES_USER: codex_proxy
@@ -49,7 +49,7 @@ jobs:
--health-timeout 5s
--health-retries 10
redis:
image: redis:8-alpine@sha256:0bf6577d7774e592b29d093e3ac9390eb91e13d72c21e506afce736de5e0eeb0
image: redis:8-alpine@sha256:7958cfbb9d152f87dadfbc89f1b0b15938f0b81ff8982feb327476f4911935c3
ports:
- 6379:6379
options: >-
+1 -1
View File
@@ -2,7 +2,7 @@
# PostgreSQL 服务端镜像:备份客户端(pg_dump/pg_restore)从这里取,与 compose 同源、
# 版本严格一致。升级数据库版本时只需同步修改这里与 deploy/compose.yaml。
ARG POSTGRES_IMAGE=postgres:18-bookworm@sha256:bbf83594798e144bff365a9c191c5d779f181fb3135902064ab8ff11918020fc
ARG POSTGRES_IMAGE=postgres:18-bookworm@sha256:194e55feb2597b1465dbee81cc9fd8d204566cd2eb42c8d22fd6c931a38781b1
FROM node:26.13.1-bookworm-slim@sha256:5df79989ed685e09f0a98019db4cebfb22fb9df1a53c0161664a011f7ff6b0f1 AS frontend-builder
+1 -1
View File
@@ -418,7 +418,7 @@ PostgreSQL/Redis 启动密码。日常校验使用 `config --quiet`
| 并发与排队 | “系统设置 → 运行设置”;Key 与账号分别设置排队容量和超时,可选择账号排队失败后换号,见[排队规则](../docs/api.md#并发与排队) |
| 账号错误保护 | “系统设置 → 运行设置 → 错误保护”;默认关闭,按[自定义规则](../docs/api.md#账号错误保护)暂停账号调度 |
| 全局请求位置 | “系统设置 → 上游配置 → 请求位置覆盖”,默认关闭 |
| OpenAI 请求国家 | “系统设置 → 上游配置 → 请求位置覆盖”中默认选中“跟随位置”,可选择“空值”“透传”或“自定义” |
| OpenAI 请求国家 | “系统设置 → 上游配置 → 请求国家”,默认跟随位置,也可选择“空值”“透传”或“自定义” |
| OpenAI OAuth 同步审核模型 | “系统设置 → 上游配置 → 模型映射”中的“专用审核模型”默认开启,关闭后沿用客户端模型。[适用条件](../docs/api.md#正文兼容) |
| 代理位置 | “代理管理”;优先于全局位置,全局关闭时仍可独立生效 |
+2 -2
View File
@@ -11,7 +11,7 @@ services:
extends:
file: config.yaml
service: postgres-credentials
image: postgres:18-bookworm@sha256:bbf83594798e144bff365a9c191c5d779f181fb3135902064ab8ff11918020fc
image: postgres:18-bookworm@sha256:194e55feb2597b1465dbee81cc9fd8d204566cd2eb42c8d22fd6c931a38781b1
restart: unless-stopped
# 小内存部署可在此调整数据库预算,保留 UTC 参数,详见 README.md#小内存优化
command:
@@ -46,7 +46,7 @@ services:
extends:
file: config.yaml
service: redis-credentials
image: redis:8-alpine@sha256:0bf6577d7774e592b29d093e3ac9390eb91e13d72c21e506afce736de5e0eeb0
image: redis:8-alpine@sha256:7958cfbb9d152f87dadfbc89f1b0b15938f0b81ff8982feb327476f4911935c3
restart: unless-stopped
volumes:
- type: bind
+2 -2
View File
@@ -1410,7 +1410,7 @@ Key 预算及其访问状态随互联默认公开,不要求开启 `shareQuota`
最多 256 项,每个 ID 最多 256 字节;重复 ID 去重,不接受空白、控制字符、`__` 前缀或 `*` 通配符。
允许保存当前上游目录尚未返回的 ID。限制按全局模型映射后的上游 ID 判断,不扩大账号本身的上游权限。
管理端刷新目录只更新目录,不修改模型限制。全选与取消全选只作用于上游目录中符合当前搜索条件的模型。
账号白名单中,“添加模型”旁的图片按钮可勾选 `gpt-image-2` 和 `gpt-image-1.5`。
账号和分组白名单均可一键勾选 `gpt-image-2` 和 `gpt-image-1.5`。
自定义模型取消勾选后在本次编辑期间保留,可再次勾选。保存时以最终选中项更新限制,关闭或取消编辑会丢弃草稿。
白名单的清理按钮列出当前目录未返回的已选 ID,默认不选中任何项,
由管理员确认后从当前表单移除,保存账号后生效。目录未就绪、刷新失败或返回空目录时不能清理,清理也不能将白名单置空。
@@ -1994,7 +1994,7 @@ GET 和 POST 均返回 `enabled`、`leadMinutes`、`weeklyTriggerRemainingPercen
分组详情和完整列表返回 `modelAccess`、`fastMode`、`allowImageGeneration` 和 `allowSubagents`。创建时省略这些字段使用默认值,更新时省略或传 `null` 保留现值。
`modelAccess` 复用账号的模型规则。默认 `{"mode":"all","models":[]}` 允许成员账号原本可以使用的模型。
`allowlist` 和 `denylist` 使用区分大小写的完整模型 ID。编辑器候选取自该组成员账号,账号自身的限制继续生效。
`allowlist` 和 `denylist` 使用区分大小写的完整模型 ID。分组与账号共用[模型限制编辑器](#账号模型限制)。可从成员账号的目录勾选模型,也可在创建或编辑分组时手动添加目录外的 ID。分组和账号分别保存规则,账号自身的限制继续生效。
Key 绑定多个组时,按模型分别合并启用组中的合格账号。例如两个组分别允许 X 和 Y,X 请求只能使用允许 X 的组内账号。
`fastMode` 默认跟随客户端。策略合并包括 Key 绑定的禁用分组,优先级依次为 `disabled`、`enabled`、`ultrafast`、`default`。未绑定分组的 Key 跟随客户端
+1 -1
View File
@@ -361,7 +361,7 @@ Provider 可为模型提供来源账号集合;Core 在公开目录查询时结
| `views/<页面>/index.vue`、`views/<页面>/components/` | 页面组合与局部交互;复杂组件按职责拆成目录入口和相邻模块 |
| `views/<页面>/composables/` | 页面查询、轮询、表单及操作生命周期 |
| `presenter.ts`、页面 `utils/` | 纯展示投影或该页面拥有的业务转换,不启动请求 |
| `components/usage/`、`components/account/` | 跨页面复用的用量、健康时间线、套餐和额度窗口展示 |
| `components/usage/`、`components/account/` | 跨页面复用的用量、健康时间线、套餐和额度窗口展示,以及账号与分组共用的模型限制编辑器 |
| `composables/` | 请求取消与过期结果隔离、分页、选择、异步动作、目录加载等共享机制 |
| `i18n/` | Vue I18n 实例、三语资源和应用语言策略;从全局 Composer 派生 UI 库语言,不翻译用户数据或远端自由文本 |
| `utils/` | 按用途分开的数据解析、数字与时长格式化、位置校验、客户端配置、插件导航及颜色工具 |
+1 -1
View File
@@ -17,7 +17,7 @@
},
"dependencies": {
"@boxicons/vue": "1.0.1",
"@codex-proxy/ui": "github:zyycn/codex-proxy-ui#v0.13.0",
"@codex-proxy/ui": "github:zyycn/codex-proxy-ui#v0.13.1",
"@fontsource-variable/inter": "^5.3.0",
"@fontsource-variable/jetbrains-mono": "^5.3.0",
"@lucide/vue": "^1.73.0",
+6 -6
View File
@@ -195,8 +195,8 @@ importers:
specifier: 1.0.1
version: 1.0.1(vue@3.5.45(typescript@6.0.3))
'@codex-proxy/ui':
specifier: github:zyycn/codex-proxy-ui#v0.13.0
version: https://codeload.github.com/zyycn/codex-proxy-ui/tar.gz/498a491ea97dbb8c5cedbffd97064edab6969341(axios@1.21.1(debug@4.4.3))(change-case@5.4.4)(jiti@2.7.0)(postcss@8.5.30)(vite@8.3.8(@types/node@26.6.6)(jiti@2.7.0)(yaml@2.9.0))(vue@3.5.45(typescript@6.0.3))(yaml@2.9.0)
specifier: github:zyycn/codex-proxy-ui#v0.13.1
version: https://codeload.github.com/zyycn/codex-proxy-ui/tar.gz/501495d5b1e9d65840d4cdee5e0e228f361613ee(axios@1.21.1(debug@4.4.3))(change-case@5.4.4)(jiti@2.7.0)(postcss@8.5.30)(vite@8.3.8(@types/node@26.6.6)(jiti@2.7.0)(yaml@2.9.0))(vue@3.5.45(typescript@6.0.3))(yaml@2.9.0)
'@fontsource-variable/inter':
specifier: ^5.3.0
version: 5.3.0
@@ -456,9 +456,9 @@ packages:
resolution: {integrity: sha512-dlT1m5e/0yUL0kRNcQn7yGLVThkgbB0Ga/1AmfDDC/8ik6AIiSf2QLQO2zPYvefsHP0aFgxO93cVLCCfDp7kzQ==}
engines: {node: '>= 20.12.0'}
'@codex-proxy/ui@https://codeload.github.com/zyycn/codex-proxy-ui/tar.gz/498a491ea97dbb8c5cedbffd97064edab6969341':
resolution: {gitHosted: true, integrity: sha512-/3G0XsMSCcijhwvwHL7HNLLaI9sEL03m0DDX/aVVGvqu13qsqn6rrsoBvSMgxjYgsvfd5ZnzvbI+ZCva8n/rhQ==, tarball: https://codeload.github.com/zyycn/codex-proxy-ui/tar.gz/498a491ea97dbb8c5cedbffd97064edab6969341}
version: 0.13.0
'@codex-proxy/ui@https://codeload.github.com/zyycn/codex-proxy-ui/tar.gz/501495d5b1e9d65840d4cdee5e0e228f361613ee':
resolution: {gitHosted: true, integrity: sha512-pPner6XWo+saTWErInK+LLSUxbSmTtd274hrWorFnOfLqDNN2cTwl1UwDsPvaRShl7jy4dVxPC5vDWAgszwdZQ==, tarball: https://codeload.github.com/zyycn/codex-proxy-ui/tar.gz/501495d5b1e9d65840d4cdee5e0e228f361613ee}
version: 0.13.1
engines: {node: '>=24'}
peerDependencies:
vite: ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0
@@ -3571,7 +3571,7 @@ snapshots:
fast-wrap-ansi: 0.2.2
sisteransi: 1.0.5
'@codex-proxy/ui@https://codeload.github.com/zyycn/codex-proxy-ui/tar.gz/498a491ea97dbb8c5cedbffd97064edab6969341(axios@1.21.1(debug@4.4.3))(change-case@5.4.4)(jiti@2.7.0)(postcss@8.5.30)(vite@8.3.8(@types/node@26.6.6)(jiti@2.7.0)(yaml@2.9.0))(vue@3.5.45(typescript@6.0.3))(yaml@2.9.0)':
'@codex-proxy/ui@https://codeload.github.com/zyycn/codex-proxy-ui/tar.gz/501495d5b1e9d65840d4cdee5e0e228f361613ee(axios@1.21.1(debug@4.4.3))(change-case@5.4.4)(jiti@2.7.0)(postcss@8.5.30)(vite@8.3.8(@types/node@26.6.6)(jiti@2.7.0)(yaml@2.9.0))(vue@3.5.45(typescript@6.0.3))(yaml@2.9.0)':
dependencies:
'@ant-design/colors': 8.0.1
'@ant-design/fast-color': 3.0.1
+11 -26
View File
@@ -23,27 +23,12 @@ const providerIconComponent = computed(() => normalizedProvider.value
: undefined)
const authenticationIconComponent = computed(() => authenticationIcon(props.authenticationKind))
const showAuthenticationKind = computed(() => props.authenticationKind !== undefined)
const groupGapClass = computed(() => {
if (props.size === 'xs')
return 'gap-0.75'
return props.size === 'sm'
? 'gap-1'
: 'gap-2'
})
const iconContainerClass = computed(() => {
if (props.size === 'xs')
return 'size-4.5 rounded-md'
return props.size === 'sm'
? 'size-5 rounded-md'
: 'size-7 rounded-lg'
})
const iconClass = computed(() => {
if (props.size === 'xs')
return 'size-2.5'
return props.size === 'sm'
? 'size-3'
: 'size-4'
})
const sizeClasses = {
xs: { gap: 'gap-0.75', container: 'size-4.5 rounded-md', icon: 'size-2.5' },
sm: { gap: 'gap-1', container: 'size-5 rounded-md', icon: 'size-3' },
md: { gap: 'gap-2', container: 'size-7 rounded-lg', icon: 'size-4' },
}
const classes = computed(() => sizeClasses[props.size])
const providerLabel = computed(() => formatProviderLabel(props.provider, t('common.providers.unknown')))
@@ -51,23 +36,23 @@ const authenticationLabel = computed(() => formatAuthenticationLabel(props.authe
</script>
<template>
<span class="inline-flex items-center whitespace-nowrap" :class="groupGapClass">
<span class="inline-flex items-center whitespace-nowrap" :class="classes.gap">
<span
class="inline-flex shrink-0 items-center justify-center bg-z-fill-secondary/80 text-z-text"
:class="iconContainerClass"
:class="classes.container"
:title="providerLabel"
>
<component :is="providerIconComponent" v-if="providerIconComponent" :class="iconClass" />
<component :is="providerIconComponent" v-if="providerIconComponent" :class="classes.icon" />
<span v-else class="text-[10px] font-heavy text-z-text-quaternary">?</span>
</span>
<span
v-if="showAuthenticationKind"
class="inline-flex shrink-0 items-center justify-center bg-z-fill-secondary/80 text-z-text"
:class="iconContainerClass"
:class="classes.container"
:title="authenticationLabel"
>
<component :is="authenticationIconComponent" v-if="authenticationIconComponent" :class="iconClass" />
<component :is="authenticationIconComponent" v-if="authenticationIconComponent" :class="classes.icon" />
<span v-else class="text-[10px] font-heavy text-z-text-quaternary">?</span>
</span>
@@ -8,9 +8,9 @@ import { computed, ref, useTemplateRef, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import { getAccountGroupModels, getAccountModels, refreshAccountModels } from '@/api'
import { useRequestState } from '@/composables/useRequestState'
import { accountModelAccessError, accountModelIdError, commonImageModels } from '../utils/modelAccess'
import AccountModelCleanupPopover from './AccountModelCleanupPopover.vue'
import AccountModelOption from './AccountModelOption.vue'
import { accountModelAccessError, accountModelIdError, commonImageModels } from './modelAccess'
const props = withDefaults(defineProps<{
accountId?: string
@@ -53,12 +53,10 @@ const modes = computed(() => [
},
{
value: 'allowlist',
disabled: props.groupId === null,
label: t('accounts.modelAccess.allowlist'),
},
{
value: 'denylist',
disabled: props.groupId === null,
label: t('accounts.modelAccess.blocklist'),
},
])
@@ -115,7 +113,7 @@ const groups = computed(() => [
ids: catalogResults.value,
},
].filter(group => group.ids.length))
const newModelId = computed(() => groupCatalog.value || groups.value.length
const newModelId = computed(() => groups.value.length
? ''
: search.value.trim())
const inputError = computed(() => selectionError.value || (newModelId.value && accountModelIdError(newModelId.value)))
@@ -301,17 +299,17 @@ watch(search, () => {
</ZFormItem>
<template v-if="restricted">
<div class="flex min-w-0 items-center gap-2">
<ZInput ref="searchInput" v-model="search" class="min-w-0 flex-1" :aria-label="groupCatalog ? t('groups.editor.searchModels') : t('accounts.modelAccess.searchOrAddModels')" :placeholder="groupCatalog ? t('groups.editor.searchModels') : t('accounts.modelAccess.searchOrEnterId')" :disabled="disabled" :aria-invalid="Boolean(inputError)" @keydown.enter="handleSearchEnter">
<ZInput ref="searchInput" v-model="search" class="min-w-0 flex-1" :aria-label="t('accounts.modelAccess.searchOrAddModels')" :placeholder="t('accounts.modelAccess.searchOrEnterId')" :disabled="disabled" :aria-invalid="Boolean(inputError)" @keydown.enter="handleSearchEnter">
<template #prefix>
<Search class="size-4" aria-hidden="true" />
</template>
</ZInput>
<ZButton v-if="!groupCatalog" class="shrink-0" :disabled="disabled || !canAdd" @click="addModels([newModelId])">
<ZButton class="shrink-0" :disabled="disabled || !canAdd" @click="addModels([newModelId])">
<Plus class="size-4" aria-hidden="true" />
{{ t('accounts.modelAccess.addModel') }}
</ZButton>
<ZIconButton
v-if="!groupCatalog && mode === 'allowlist'"
v-if="mode === 'allowlist'"
variant="plain"
:aria-label="t('accounts.modelAccess.addImageModels')"
:title="t('accounts.modelAccess.addImageModels')"
@@ -360,7 +358,7 @@ watch(search, () => {
<p v-else-if="mode === 'denylist' && canAdd" class="m-0 text-z-xs text-z-text-secondary">
{{ t('accounts.modelAccess.addToDenylistHint') }}
</p>
<ZEmpty v-else-if="!error && !search" :title="groupCatalog ? t('groups.editor.emptyCatalog') : t('accounts.modelAccess.noModels')" size="small" surface="none" />
<ZEmpty v-else-if="!error && !search" :title="t('accounts.modelAccess.noModels')" size="small" surface="none" />
</template>
</div>
</template>
+20 -16
View File
@@ -24,20 +24,24 @@ const parsed = computed(() => parseJsonObject(text.value, props.maximumBytes))
const error = computed(() => parsed.value.error)
const value = computed(() => parsed.value.value)
const fields = computed(() => inputFields(props.schema))
const hasExtra = computed(() => Object.keys(value.value ?? {}).some(key => !fields.value?.some(field => field.key === key)))
const incompatibleValue = computed(() => fields.value?.some((field) => {
const item = inputValue(field.key)
if (item === undefined)
const fieldsByKey = computed(() => new Map(fields.value?.map(field => [field.key, field])))
const canUseForm = computed(() => {
if (fields.value === null || error.value)
return false
if (field.values)
return !field.values.some(option => option === item)
if (field.type === 'number' || field.type === 'integer')
return typeof item !== 'number' && typeof item !== 'string'
return field.type === 'boolean'
? typeof item !== 'boolean'
: typeof item !== 'string'
}) ?? false)
const showJson = computed(() => jsonMode.value || fields.value === null || hasExtra.value || incompatibleValue.value || Boolean(error.value))
return Object.entries(value.value ?? {}).every(([key, item]) => {
const field = fieldsByKey.value.get(key)
if (!field)
return false
if (field.values)
return field.values.some(option => option === item)
if (field.type === 'number' || field.type === 'integer')
return typeof item === 'number' || typeof item === 'string'
return field.type === 'boolean'
? typeof item === 'boolean'
: typeof item === 'string'
})
})
const showJson = computed(() => jsonMode.value || !canUseForm.value)
const empty = computed(() => fields.value?.length === 0 && props.schema.additionalProperties === false && !showJson.value)
function fieldValue(field: InputField) {
@@ -105,8 +109,8 @@ function update(field: InputField, input: string) {
}
async function focusField(key?: string) {
const editableField = key && fields.value?.some(field => field.key === key)
if (editableField && jsonMode.value && !error.value && !hasExtra.value && !incompatibleValue.value)
const editableField = key && fieldsByKey.value.has(key)
if (editableField && canUseForm.value)
jsonMode.value = false
await nextTick()
@@ -128,7 +132,7 @@ defineExpose({ focusField })
<ZForm v-if="showJson">
<ZFormItem :label="t('common.form.inputPlaceholder')" :error="error">
<template #extra>
<ZIconButton v-if="fields !== null" :aria-label="t('common.form.useForm')" class="size-4!" variant="link" :disabled="disabled || Boolean(error) || hasExtra || incompatibleValue" @click="jsonMode = false">
<ZIconButton v-if="fields !== null" :aria-label="t('common.form.useForm')" class="size-4!" variant="link" :disabled="disabled || !canUseForm" @click="jsonMode = false">
<List class="size-3.5" />
</ZIconButton>
</template>
@@ -28,7 +28,6 @@ withDefaults(
defineProps<{
columns: TableColumn<UsageListRecord>[]
rows: UsageListRecord[]
requestDetails?: boolean
loading?: boolean
emptyText?: string
}>(),
@@ -97,7 +96,7 @@ const { t } = useI18n({ useScope: 'global' })
</template>
<template #createdAtDisplay="{ row }">
<UsageTimeCell :value="row.createdAtDisplay" :datetime="requestDetails ? row.createdAt : undefined" />
<UsageTimeCell :value="row.createdAtDisplay" :datetime="row.createdAt" />
</template>
<template #clientIp="{ row }">
@@ -1,12 +1,12 @@
<script setup lang="ts">
import { computed } from 'vue'
const props = defineProps<{ value: string, datetime?: string }>()
const props = defineProps<{ value: string, datetime: string }>()
const parts = computed(() => props.value?.split(' '))
</script>
<template>
<time v-if="datetime && parts?.length === 2" :datetime="datetime" :title="value" class="grid gap-1 font-mono tabular-nums">
<time v-if="parts?.length === 2" :datetime="datetime" :title="value" class="grid gap-1 font-mono tabular-nums">
<span class="text-z-sm font-bold text-z-text">{{ parts[1] }}</span>
<span class="text-z-xs text-z-text-tertiary">{{ parts[0] }}</span>
</time>
@@ -58,6 +58,7 @@ export const usageDataColumns = computed(() => ([
key: 'createdAtDisplay',
label: t('usage.fields.time'),
kind: 'datetime',
width: 128,
},
{
key: 'clientIp',
+1 -1
View File
@@ -224,7 +224,7 @@
"upstreamCatalog": "Upstream catalog",
"selectAll": "Select all",
"deselectAll": "Deselect all",
"addToDenylistHint": "Saving blocks this ID on the account",
"addToDenylistHint": "Add and save to block this model",
"loadingModel": "Loading model",
"noModels": "No models",
"selectOrAddAtLeastOneModel": "Please select or add at least one model",
-2
View File
@@ -43,8 +43,6 @@
"forceUltrafast": "Force Ultrafast",
"subagents": "Collaborative subagents",
"memberModels": "Member account models",
"searchModels": "Search member models",
"emptyCatalog": "Add an account with available models to this group first",
"fastModeHelp": "Default follows the client. Disable downgrades both accelerated tiers to standard. A forced tier overrides the client selection when the model supports it.",
"subagentsHelp": "Enable lets the client decide when to start a collaborative subagent. Disable rejects requests identified as coming from a collaborative subagent."
},
@@ -315,7 +315,9 @@
"day": "d",
"location": {
"requestCountry": "Request country",
"requestCountryDescription": "Choose how Codex requests send the country code",
"countryHelp": "Request country mode help",
"countryMode": "Policy",
"countryModes": {
"default": "Null",
"passthrough": "Pass through",
@@ -224,7 +224,7 @@
"upstreamCatalog": "上游目录",
"selectAll": "全选",
"deselectAll": "取消全选",
"addToDenylistHint": "保存后,此账号将拒绝该模型",
"addToDenylistHint": "添加并保存后将拒绝该模型",
"loadingModel": "加载模型中",
"noModels": "暂无模型",
"selectOrAddAtLeastOneModel": "请至少选择或添加一个模型",
@@ -43,8 +43,6 @@
"forceUltrafast": "超快速",
"subagents": "协作子代理",
"memberModels": "成员账号模型",
"searchModels": "搜索成员账号模型",
"emptyCatalog": "暂无成员模型,请先将有模型的账号加入分组",
"fastModeHelp": "默认跟随客户端。禁用会将加速请求降为标准档。选择快速或超快速时,若模型支持该档位,分组设置会覆盖客户端选择",
"subagentsHelp": "启用后由客户端决定是否启动协作子代理。禁用会拒绝可识别的协作子代理请求"
},
@@ -315,7 +315,9 @@
"day": "天",
"location": {
"requestCountry": "请求国家",
"requestCountryDescription": "设置 Codex 请求如何发送国家代码",
"countryHelp": "请求国家模式说明",
"countryMode": "策略",
"countryModes": {
"default": "空值",
"passthrough": "透传",
@@ -224,7 +224,7 @@
"upstreamCatalog": "上游目錄",
"selectAll": "全選",
"deselectAll": "取消全選",
"addToDenylistHint": "保存後,此賬號將拒絕該模型",
"addToDenylistHint": "加入並儲存後將拒絕此模型",
"loadingModel": "加載模型中",
"noModels": "暫無模型",
"selectOrAddAtLeastOneModel": "請至少選擇或添加一個模型",
@@ -43,8 +43,6 @@
"forceUltrafast": "超快速",
"subagents": "協作子代理",
"memberModels": "成員帳號模型",
"searchModels": "搜尋成員帳號模型",
"emptyCatalog": "暫無成員模型,請先將有模型的帳號加入分組",
"fastModeHelp": "預設跟隨用戶端。禁用會將加速請求降為標準檔。選擇快速或超快速時,若模型支援該檔位,分組設定會覆寫用戶端選擇",
"subagentsHelp": "啟用後由用戶端決定是否啟動協作子代理。禁用會拒絕可識別的協作子代理請求"
},
@@ -315,7 +315,9 @@
"day": "天",
"location": {
"requestCountry": "請求國家",
"requestCountryDescription": "設定 Codex 請求如何傳送國家代碼",
"countryHelp": "請求國家模式說明",
"countryMode": "策略",
"countryModes": {
"default": "空值",
"passthrough": "透傳",
@@ -3,8 +3,8 @@ import type { AccountGroupRef, AccountModelAccess } from '@/api'
import { ZFormItem, ZInput, ZSwitch, ZTextarea } from '@codex-proxy/ui'
import { useI18n } from 'vue-i18n'
import AccountModelAccessField from '@/components/account/model-access/index.vue'
import AccountGroupCheckboxGrid from '@/components/AccountGroupCheckboxGrid.vue'
import AccountModelAccessField from './AccountModelAccessField.vue'
import AccountNameField from './AccountNameField.vue'
import AccountProxyField from './AccountProxyField.vue'
@@ -2,8 +2,8 @@ import type { FormRules } from '@codex-proxy/ui'
import type { AccountModelAccess } from '@/api'
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'
import { accountModelAccessError } from '@/components/account/model-access/modelAccess'
import { accountNameValid } from '../utils/accountName'
import { accountModelAccessError } from '../utils/modelAccess'
interface AccountSettingsFormValue {
name?: string
@@ -7,9 +7,9 @@ import { normalizeRgbaHexColor, ZButton, ZColorPicker, ZDialog, ZForm, ZFormItem
import { computed, useTemplateRef, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import AccountModelAccessField from '@/components/account/model-access/index.vue'
import { accountModelAccessError } from '@/components/account/model-access/modelAccess'
import HelpPopover from '@/components/HelpPopover.vue'
import AccountModelAccessField from '@/views/accounts/components/AccountModelAccessField.vue'
import { accountModelAccessError } from '@/views/accounts/utils/modelAccess'
import { ACCOUNT_GROUP_COLOR_PRESETS } from '../constants'
const props = defineProps<{
@@ -81,7 +81,7 @@ const description = computed(() => props.group
width="42rem"
:show-close="!saving" :close-on-click-modal="!saving" :close-on-press-escape="!saving"
>
<ZForm ref="formElement" :model="form" :rules="rules" class="sm:grid-cols-[minmax(0,1fr)_fit-content(10rem)] sm:gap-x-6" scroll-to-error focus-on-error novalidate @submit="requestSave">
<ZForm ref="formElement" :model="form" :rules="rules" class="sm:grid-cols-[minmax(0,1fr)_fit-content(10rem)] sm:gap-x-6 md:grid-cols-[minmax(0,1fr)_fit-content(11rem)]" scroll-to-error focus-on-error novalidate @submit="requestSave">
<ZFormItem prop="name" :show-message="false" :label="t('groups.editor.groupName')" required>
<ZInput
v-model="form.name"
@@ -99,7 +99,7 @@ const description = computed(() => props.group
:disabled="saving"
/>
</ZFormItem>
<div class="col-span-full grid grid-cols-2 items-start gap-x-6 gap-y-4.5 sm:grid-cols-subgrid **:[[role=radio]]:px-3.5">
<div class="col-span-full grid grid-cols-2 items-start gap-x-6 gap-y-4.5 sm:grid-cols-subgrid **:[[role=radio]]:px-3.5 md:**:[[role=radio]]:px-4.5">
<div class="contents sm:flex sm:min-w-0 sm:flex-wrap sm:items-start sm:gap-x-6 sm:gap-y-4.5">
<ZFormItem :label="t('groups.editor.fastMode')" class="col-span-full sm:flex-auto">
<template #label-extra>
@@ -65,7 +65,7 @@ const { visibleColumns, columnOptions, setColumnVisible, setColumnOrder, resetCo
<UsagePerformanceCell :record="row" />
</template>
<template #createdAtDisplay="{ row }">
<UsageTimeCell :value="row.createdAtDisplay" />
<UsageTimeCell :value="row.createdAtDisplay" :datetime="row.createdAt" />
</template>
<template #clientIp="{ row }">
<UsageClientIpCell :record="row" />
@@ -4,7 +4,7 @@ import type { ProxyBatchItem } from '../utils/batch'
import { ZScrollbar } from '@codex-proxy/ui'
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'
import { proxyBatchStates } from '../utils/batch'
import { proxyBatchStates, summarizeProxyBatch, summarizeProxyTests } from '../utils/batch'
import ProxyRegion from './ProxyRegion.vue'
const props = defineProps<{ items: ProxyBatchItem[], tests?: ProxyBatchItem[] }>()
@@ -12,51 +12,61 @@ const props = defineProps<{ items: ProxyBatchItem[], tests?: ProxyBatchItem[] }>
const { t } = useI18n({ useScope: 'global' })
const testItems = computed(() => props.tests ?? [])
function resultMessage(item: ProxyBatchItem, test?: ProxyBatchItem) {
if (test && test.status !== 'succeeded')
return test.message
const detection = test?.record?.lastTest?.location
if (detection?.status === 'failed')
return detection.message
return item.status === 'succeeded'
? ''
: item.message
}
const rows = computed(() => {
const tests = new Map(testItems.value.map(item => [item.key, item]))
return props.items.map((item) => {
const test = item.record
? tests.get(item.record.id)
: undefined
const detection = test?.record?.lastTest?.location
const status = (test ?? item).status
const state = proxyBatchStates.value[status]
let label = state.label
if (status === 'succeeded') {
label = test
? t('proxies.batchTest.connectionIsNormal')
: t('proxies.batchTest.addedStatus')
}
return {
item,
test,
result: test ?? item,
message: test && test.status !== 'succeeded'
? test.message
: detection?.status === 'failed'
? detection.message
: item.status !== 'succeeded'
? item.message
: '',
label,
tone: state.tone,
message: resultMessage(item, test),
messageTone: status === 'succeeded'
? 'text-z-warning-text'
: state.tone,
}
})
})
const completed = computed(() => props.items.filter(item => !['pending', 'running', 'skipped'].includes(item.status)).length)
const created = computed(() => props.items.filter(item => item.status === 'succeeded').length)
const invalid = computed(() => props.items.filter(item => item.status === 'failed').length)
const succeeded = computed(() => testItems.value.filter(item => item.status === 'succeeded').length)
const failed = computed(() => testItems.value.filter(item => item.status === 'failed').length)
const allOperations = computed(() => [
...props.items,
...testItems.value,
])
const attention = computed(() => allOperations.value.filter(item => ['error', 'conflict', 'busy', 'unknown'].includes(item.status)).length)
const skipped = computed(() => allOperations.value.filter(item => item.status === 'skipped').length)
const locationPending = computed(() => testItems.value.filter(item => item.status === 'succeeded' && item.record?.lastTest?.location.status !== 'detected').length)
const additions = computed(() => summarizeProxyBatch(props.items))
const connections = computed(() => summarizeProxyTests(testItems.value))
const attention = computed(() => additions.value.attention + connections.value.attention)
const skipped = computed(() => additions.value.skipped + connections.value.skipped)
</script>
<template>
<section class="min-w-0 space-y-3" :aria-label="t('proxies.batchTest.resultsTitle')">
<div class="flex flex-wrap items-center gap-x-4 gap-y-1 text-z-xs text-z-text-secondary" role="status" aria-live="polite">
<span>{{ t('proxies.batchTest.processed') }} <strong class="font-mono font-medium text-z-text">{{ completed }} / {{ items.length }}</strong></span>
<span>{{ t('proxies.batchTest.added', { created }) }}</span>
<span v-if="invalid">{{ t('proxies.batchTest.invalidFormat', { invalid }) }}</span>
<span>{{ t('proxies.batchTest.processed') }} <strong class="font-mono font-medium text-z-text">{{ additions.completed }} / {{ items.length }}</strong></span>
<span>{{ t('proxies.batchTest.added', { created: additions.succeeded }) }}</span>
<span v-if="additions.failed">{{ t('proxies.batchTest.invalidFormat', { invalid: additions.failed }) }}</span>
<template v-if="testItems.length">
<span>{{ t('proxies.batchTest.connected', { succeeded }) }}</span>
<span>{{ t('proxies.batchTest.connectionFailed', { failed }) }}</span>
<span v-if="locationPending">{{ t('proxies.batchTest.locationPending', { locationPending }) }}</span>
<span>{{ t('proxies.batchTest.connected', { succeeded: connections.succeeded }) }}</span>
<span>{{ t('proxies.batchTest.connectionFailed', { failed: connections.failed }) }}</span>
<span v-if="connections.locationPending">{{ t('proxies.batchTest.locationPending', { locationPending: connections.locationPending }) }}</span>
</template>
<span v-if="attention">{{ t('proxies.batchTest.needsAttention', { attention }) }}</span>
<span v-if="skipped">{{ t('proxies.batchTest.skipped', { skipped }) }}</span>
@@ -65,9 +75,9 @@ const locationPending = computed(() => testItems.value.filter(item => item.statu
<ol class="m-0 list-none space-y-1 p-0">
<li v-for="row in rows" :key="row.item.key" class="grid grid-cols-[minmax(0,1fr)_auto] gap-x-3 gap-y-1 rounded-z-sm px-3 py-2.5 odd:bg-z-fill-quaternary">
<span class="min-w-0 truncate font-mono text-z-xs text-z-text" :title="row.item.endpoint">{{ row.item.endpoint || t('proxies.batchTest.lineNumber', { key: row.item.key }) }}</span>
<span class="flex flex-wrap justify-end gap-x-2 text-z-xs" :class="proxyBatchStates[row.result.status].tone">
<span class="flex flex-wrap justify-end gap-x-2 text-z-xs" :class="row.tone">
<span v-if="row.test" class="text-z-text-secondary">{{ t('proxies.batchTest.addedStatus') }}</span>
<span>{{ row.result.status === 'succeeded' ? row.test ? t('proxies.batchTest.connectionIsNormal') : t('proxies.batchTest.addedStatus') : proxyBatchStates[row.result.status].label }}</span>
<span>{{ row.label }}</span>
</span>
<div class="col-span-2 flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1 text-z-xs text-z-text-secondary">
<span class="max-w-full truncate" :title="row.item.name">{{ row.item.name }}</span>
@@ -76,7 +86,7 @@ const locationPending = computed(() => testItems.value.filter(item => item.statu
<span class="whitespace-nowrap">{{ row.test.record.lastTest.latencyMs }} ms</span><span v-if="row.test.record.lastTest.exitIpv4"> · IPv4 {{ row.test.record.lastTest.exitIpv4 }}</span><span v-if="row.test.record.lastTest.exitIpv6"> · IPv6 {{ row.test.record.lastTest.exitIpv6 }}</span>
</span>
</div>
<span v-if="row.message" class="col-span-2 text-z-xs leading-relaxed wrap-anywhere" :class="row.result.status === 'succeeded' ? 'text-z-warning-text' : proxyBatchStates[row.result.status].tone">{{ row.message }}</span>
<span v-if="row.message" class="col-span-2 text-z-xs leading-relaxed wrap-anywhere" :class="row.messageTone">{{ row.message }}</span>
</li>
</ol>
</ZScrollbar>
@@ -4,6 +4,7 @@ import { getProxies } from '@/api'
import { useRequestState } from '@/composables/useRequestState'
import { t } from '@/i18n'
import { notification as ZNotification } from '@/utils/notification'
import { summarizeProxyTests } from '../utils/batch'
import { useProxyBatchTest } from './useProxyBatchTest'
export function useProxyBatchTesting(options: { test: ProxyTestExecutor, reload: () => Promise<unknown> }) {
@@ -48,23 +49,22 @@ export function useProxyBatchTesting(options: { test: ProxyTestExecutor, reload:
await options.reload()
if (!request.isCurrent(requestId))
return
const succeeded = tests.items.value.filter(item => item.status === 'succeeded').length
const incomplete = tests.items.value.filter(item => item.status !== 'succeeded')
const locationPending = tests.items.value.filter(item => item.status === 'succeeded' && item.record?.lastTest?.location.status !== 'detected').length
const { succeeded, locationPending } = summarizeProxyTests(tests.items.value)
const incomplete = tests.items.value.length - succeeded
const missing = wanted.size - collected.size
const summary = [
t('proxies.batchTest.batchTestCompletedConnected', { succeeded }),
]
if (incomplete.length)
summary.push(t('proxies.batchTest.unsuccessful', { count: incomplete.length }))
if (incomplete)
summary.push(t('proxies.batchTest.unsuccessful', { count: incomplete }))
if (locationPending)
summary.push(t('proxies.batchTest.locationsPending', { locationPending }))
if (missing)
summary.push(t('proxies.batchTest.proxiesNoLongerAvailable', { missing }))
const firstFailure = incomplete.find(item => item.status !== 'skipped')
const firstFailure = tests.items.value.find(item => item.status !== 'succeeded' && item.status !== 'skipped')
if (firstFailure)
summary.push(`${firstFailure.name}:${firstFailure.message}`)
const notify = incomplete.length || locationPending || missing
const notify = incomplete || locationPending || missing
? ZNotification.warning
: ZNotification.success
notify({
+20
View File
@@ -1,4 +1,5 @@
import type { OutboundProxyRecord, ProxyBatchResult } from '@/api'
import { countBy } from 'es-toolkit'
import { computed } from 'vue'
import { ApiError } from '@/api/request'
import { t } from '@/i18n'
@@ -23,6 +24,25 @@ export interface ProxyBatchItem {
record?: OutboundProxyRecord
}
export function summarizeProxyBatch(items: ProxyBatchItem[]) {
const counts = countBy(items, item => item.status)
const skipped = counts.skipped ?? 0
return {
completed: items.length - (counts.pending ?? 0) - (counts.running ?? 0) - skipped,
succeeded: counts.succeeded ?? 0,
failed: counts.failed ?? 0,
attention: (counts.error ?? 0) + (counts.conflict ?? 0) + (counts.busy ?? 0) + (counts.unknown ?? 0),
skipped,
}
}
export function summarizeProxyTests(items: ProxyBatchItem[]) {
return {
...summarizeProxyBatch(items),
locationPending: items.filter(item => item.status === 'succeeded' && item.record?.lastTest?.location.status !== 'detected').length,
}
}
export interface ProxyBatchInput {
line: number
raw: string
@@ -0,0 +1,77 @@
<script setup lang="ts">
import type { SelectOption } from '@codex-proxy/ui/select'
import type { OpenAiRequestCountry } from '@/api'
import { ZCard, ZFormItem, ZSelect } from '@codex-proxy/ui'
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'
import CountryCodeField from '@/components/CountryCodeField.vue'
import HelpPopover from '@/components/HelpPopover.vue'
defineProps<{ disabled: boolean }>()
const { t } = useI18n({ useScope: 'global' })
const requestCountry = defineModel<OpenAiRequestCountry>({ required: true })
const modes = computed<Array<SelectOption<OpenAiRequestCountry['mode']> & { help: string }>>(() => [
{
value: 'follow_location',
label: t('settings.location.countryModes.follow_location'),
help: t('settings.location.countryHints.follow_location'),
},
{
value: 'default',
label: t('settings.location.countryModes.default'),
help: t('settings.location.countryHints.default'),
},
{
value: 'passthrough',
label: t('settings.location.countryModes.passthrough'),
help: t('settings.location.countryHints.passthrough'),
},
{
value: 'custom',
label: t('settings.location.countryModes.custom'),
help: t('settings.location.countryHints.custom'),
},
])
function setMode(mode: OpenAiRequestCountry['mode'] | undefined) {
if (mode && mode !== requestCountry.value.mode) {
requestCountry.value = mode === 'custom'
? { mode, country: '' }
: { mode }
}
}
</script>
<template>
<ZCard :description="t('settings.location.requestCountryDescription')">
<template #title>
<span class="inline-flex items-center gap-1.5">
{{ t('settings.location.requestCountry') }}
<HelpPopover :label="t('settings.location.countryHelp')">
<dl class="grid grid-cols-[auto_1fr] gap-x-3 gap-y-2">
<template v-for="mode in modes" :key="mode.value">
<dt class="font-emphasis text-z-text">
{{ mode.label }}
</dt>
<dd>{{ mode.help }}</dd>
</template>
</dl>
</HelpPopover>
</span>
</template>
<div class="grid min-w-0 max-w-6xl items-start gap-4.5 sm:grid-cols-2">
<ZFormItem :label="t('settings.location.countryMode')">
<ZSelect :model-value="requestCountry.mode" :options="modes" :aria-label="t('settings.location.countryMode')" :disabled="disabled" @update:model-value="setMode" />
</ZFormItem>
<CountryCodeField
v-if="requestCountry.mode === 'custom'"
:model-value="requestCountry.country"
form-prop="openaiRequestCountry.country"
:label="t('settings.location.customCountryCode')"
:disabled="disabled"
@update:model-value="requestCountry = { mode: 'custom', country: $event }"
/>
</div>
</ZCard>
</template>
@@ -1,12 +1,8 @@
<script setup lang="ts">
import type { SelectOption } from '@codex-proxy/ui/select'
import type { OpenAiRequestCountry, RequestLocation } from '@/api'
import type { RequestLocation } from '@/api'
import { ZCard, ZFormItem, ZSelect, ZSwitch } from '@codex-proxy/ui'
import { computed } from 'vue'
import { ZCard, ZSwitch } from '@codex-proxy/ui'
import { useI18n } from 'vue-i18n'
import CountryCodeField from '@/components/CountryCodeField.vue'
import HelpPopover from '@/components/HelpPopover.vue'
import RequestLocationDetectButton from '@/components/RequestLocationDetectButton.vue'
import RequestLocationFields from '@/components/RequestLocationFields.vue'
@@ -18,37 +14,6 @@ const { t } = useI18n({ useScope: 'global' })
const location = defineModel<RequestLocation>({ required: true })
const enabled = defineModel<boolean>('enabled', { required: true })
const requestCountry = defineModel<OpenAiRequestCountry>('requestCountry', { required: true })
const modes = computed<Array<SelectOption<OpenAiRequestCountry['mode']> & { help: string }>>(() => [
{
value: 'follow_location',
label: t('settings.location.countryModes.follow_location'),
help: t('settings.location.countryHints.follow_location'),
},
{
value: 'default',
label: t('settings.location.countryModes.default'),
help: t('settings.location.countryHints.default'),
},
{
value: 'passthrough',
label: t('settings.location.countryModes.passthrough'),
help: t('settings.location.countryHints.passthrough'),
},
{
value: 'custom',
label: t('settings.location.countryModes.custom'),
help: t('settings.location.countryHints.custom'),
},
])
function setMode(mode: OpenAiRequestCountry['mode'] | undefined) {
if (mode && mode !== requestCountry.value.mode) {
requestCountry.value = mode === 'custom'
? { mode, country: '' }
: { mode }
}
}
</script>
<template>
@@ -58,34 +23,7 @@ function setMode(mode: OpenAiRequestCountry['mode'] | undefined) {
<ZSwitch v-model="enabled" :label="t('settings.location.enableLocationOverlay')" :disabled="disabled" />
<RequestLocationDetectButton :loading="detectingLocation" :disabled="disabled" @detect="emit('detectLocation')" />
</div>
<div class="grid min-w-0 gap-4.5 mt-4 max-w-6xl">
<RequestLocationFields v-model="location" :form-prop="enabled ? 'requestLocation' : undefined" :disabled="disabled || !enabled" />
<div class="grid gap-4.5 sm:grid-cols-2">
<ZFormItem :label="t('settings.location.requestCountry')">
<template #label-extra>
<HelpPopover :label="t('settings.location.countryHelp')">
<dl class="grid grid-cols-[auto_1fr] gap-x-3 gap-y-2">
<template v-for="mode in modes" :key="mode.value">
<dt class="font-emphasis text-z-text">
{{ mode.label }}
</dt>
<dd>{{ mode.help }}</dd>
</template>
</dl>
</HelpPopover>
</template>
<ZSelect :model-value="requestCountry.mode" :options="modes" :aria-label="t('settings.location.requestCountry')" :disabled="disabled" @update:model-value="setMode" />
</ZFormItem>
<CountryCodeField
v-if="requestCountry.mode === 'custom'"
:model-value="requestCountry.country"
form-prop="openaiRequestCountry.country"
:label="t('settings.location.customCountryCode')"
:disabled="disabled"
@update:model-value="requestCountry = { mode: 'custom', country: $event }"
/>
</div>
</div>
<RequestLocationFields v-model="location" class="mt-4 max-w-6xl" :form-prop="enabled ? 'requestLocation' : undefined" :disabled="disabled || !enabled" />
</template>
</ZCard>
</template>
+2 -1
View File
@@ -17,6 +17,7 @@ import ConcurrencyPolicyCard from './components/ConcurrencyPolicyCard.vue'
import AccountErrorProtectionCard from './components/error-protection/AccountErrorProtectionCard.vue'
import ModelAliasesCard from './components/ModelAliasesCard.vue'
import PrivacyPolicyCard from './components/privacy/PrivacyPolicyCard.vue'
import RequestCountryCard from './components/RequestCountryCard.vue'
import RequestHistoryCard from './components/RequestHistoryCard.vue'
import RequestLocationCard from './components/RequestLocationCard.vue'
import ResetCreditCard from './components/ResetCreditCard.vue'
@@ -246,11 +247,11 @@ watch(section, (value) => {
<RequestLocationCard
v-model="form.requestLocation"
v-model:enabled="form.requestLocationEnabled"
v-model:request-country="form.openaiRequestCountry"
:disabled="disabled"
:detecting-location="detectingLocation"
@detect-location="detectLocation"
/>
<RequestCountryCard v-model="form.openaiRequestCountry" :disabled="disabled" />
<PrivacyPolicyCard v-model="form.codexPrivacyPolicy" :disabled="disabled" />
<ModelAliasesCard
:mappings="mappings"
@@ -1,5 +1,5 @@
<script setup lang="ts">
import type { EChartsOption, LineSeriesOption } from 'echarts'
import type { EChartsOption } from 'echarts'
import type { UsageCostMetric, UsageMetricResponse } from '@/api'
import { ZCard, ZEmpty, ZSegmented } from '@codex-proxy/ui'
@@ -7,12 +7,10 @@ import { ZCard, ZEmpty, ZSegmented } from '@codex-proxy/ui'
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'
import BaseChart from '@/components/charts/BaseChart.vue'
import {
zeroInactiveValues,
} from '@/components/charts/timeSeriesGap'
import { zeroInactiveValues } from '@/components/charts/timeSeriesGap'
import { chartTooltipContent, tooltipIndex, tooltipRows } from '@/components/charts/tooltip'
import { useChartPalette } from '@/composables/useChartPalette'
import { decimalDisplayNumber, formatLocalizedCompactNumber as formatCompactNumber, formatPercent, formatUsd } from '@/utils/format'
import { decimalDisplayNumber, formatPercent, formatUsd } from '@/utils/format'
import {
formatUsdAxis,
@@ -37,23 +35,19 @@ const props = withDefaults(
const { t } = useI18n({ useScope: 'global' })
type UsageChartPalette = ReturnType<typeof useChartPalette>['palette']['value']
interface CostSeries {
label: string
color: string
values: (number | null)[]
area?: 'strong'
tooltipValue: (index: number) => string | null
}
const activeView = defineModel<UsageCostMetric>({ required: true })
const { palette } = useChartPalette()
const cost = computed(() => props.result?.data.summary ?? null)
const points = computed(() => props.result?.data.points ?? [])
const costPoints = computed(() => props.result?.metric === 'cost'
? props.result.data.points
: [])
const savingsPoints = computed(() => props.result?.metric === 'savings'
? props.result.data.points
: [])
const cachePoints = computed(() => props.result?.metric === 'cache'
? props.result.data.points
: [])
const requestActivity = computed(() => points.value.map(point => point.requestCount > 0))
const hasNoCacheCost = computed(() => costPoints.value.some(point => point.value.noCacheCost != null))
const coverageRate = computed(() => {
if (!cost.value)
return null
@@ -79,21 +73,79 @@ const viewOptions = computed(() => ([
},
]))
const hasData = computed(() => {
if (props.loading || props.result?.metric !== activeView.value)
return false
if (activeView.value === 'cost')
return costPoints.value.some(point => point.value.estimatedCost != null || point.value.noCacheCost != null)
if (activeView.value === 'savings')
return savingsPoints.value.some(point => point.value != null)
return cachePoints.value.some(({ value }) => value.inputTokens > 0 || value.cachedTokenRate > 0 || (value.cacheHitRequestRate ?? 0) > 0)
function amountValues(amounts: (string | null)[]) {
return zeroInactiveValues(amounts.map(amount => decimalDisplayNumber(amount)), requestActivity.value)
}
function primaryAmountSeries(label: string, amounts: (string | null)[]): CostSeries {
return {
label,
color: palette.value.success,
area: 'strong',
values: amountValues(amounts),
tooltipValue: index => formatUsd(amounts[index] ?? (requestActivity.value[index] === false
? '0'
: null)),
}
}
function rateSeries(label: string, color: string, values: (number | null)[]): CostSeries {
return {
label,
color,
values,
tooltipValue: index => formatPercent(values[index] ?? null),
}
}
const chart = computed<{ hasData: boolean, series: CostSeries[] }>(() => {
const response = props.result
if (props.loading || !response || response.metric !== activeView.value)
return { hasData: false, series: [] }
if (response.metric === 'cost') {
const actual = response.data.points.map(({ value }) => value.estimatedCost)
const comparison = response.data.points.map(({ value }) => value.noCacheCost)
const hasComparison = comparison.some(amount => amount != null)
const series = [
primaryAmountSeries(t('usage.cost.actualCost'), actual),
]
if (hasComparison) {
series.push({
label: t('usage.cost.withoutCacheEstimate'),
color: palette.value.textMuted,
values: amountValues(comparison),
// 对比曲线允许补零,提示只展示该时间桶实际提供的估算
tooltipValue: index => comparison[index] == null
? null
: formatUsd(comparison[index]),
})
}
return { hasData: hasComparison || actual.some(amount => amount != null), series }
}
if (response.metric === 'savings') {
const savings = response.data.points.map(point => point.value)
return {
hasData: savings.some(amount => amount != null),
series: [
primaryAmountSeries(t('usage.cost.cacheSavings'), savings),
],
}
}
const { points } = response.data
return {
hasData: points.some(({ value }) => value.inputTokens > 0 || value.cachedTokenRate > 0 || (value.cacheHitRequestRate ?? 0) > 0),
series: [
rateSeries(t('usage.cost.cacheTokenProportion'), palette.value.normal, points.map(({ value }) => value.cachedTokenRate)),
rateSeries(t('usage.cost.hitRequestRate'), palette.value.success, points.map(({ value }) => value.cacheHitRequestRate)),
],
}
})
const chartOption = computed<EChartsOption>(() => {
const theme = palette.value
const legend = legendNames()
const series = chartSeries(theme)
const series = chart.value.series
return {
animationDuration: 240,
grid: {
@@ -104,157 +156,34 @@ const chartOption = computed<EChartsOption>(() => {
outerBoundsMode: 'same',
outerBoundsContain: 'axisLabel',
},
legend: usageLegend(theme, legend),
legend: usageLegend(theme, series.map(item => item.label)),
tooltip: usageTooltip(theme, formatTooltip),
xAxis: usageCategoryAxis(
points.value.map(point => point.label),
theme,
),
yAxis: usageValueAxis(theme, axisFormatter(), {
min: activeView.value === 'cache'
? 0
: undefined,
max: activeView.value === 'cache'
? 1
: undefined,
}),
series,
yAxis: activeView.value === 'cache'
? usageValueAxis(theme, formatPercent, { min: 0, max: 1 })
: usageValueAxis(theme, formatUsdAxis),
series: series.flatMap(item => usageGapAwareLineSeries(item.label, item.values, item.color, { area: item.area })),
}
})
function legendNames() {
if (activeView.value === 'savings') {
return [
t('usage.cost.cacheSavings'),
]
}
if (activeView.value === 'cache') {
return [
t('usage.cost.cacheTokenProportion'),
t('usage.cost.hitRequestRate'),
]
}
return hasNoCacheCost.value
? [
t('usage.cost.actualCost'),
t('usage.cost.withoutCacheEstimate'),
]
: [
t('usage.cost.actualCost'),
]
}
function axisFormatter() {
if (activeView.value === 'cost' || activeView.value === 'savings')
return formatUsdAxis
if (activeView.value === 'cache')
return (value: number) => formatPercent(value)
return (value: number) => formatCompactNumber(value)
}
function chartSeries(theme: UsageChartPalette): LineSeriesOption[] {
if (activeView.value === 'savings') {
return [
...usageGapAwareLineSeries(
t('usage.cost.cacheSavings'),
zeroInactiveValues(
savingsPoints.value.map(point => decimalDisplayNumber(point.value)),
requestActivity.value,
),
theme.success,
{ area: 'strong' },
),
]
}
if (activeView.value === 'cache') {
return [
...usageGapAwareLineSeries(
t('usage.cost.cacheTokenProportion'),
cachePoints.value.map(point => point.value.cachedTokenRate),
theme.normal,
),
...usageGapAwareLineSeries(
t('usage.cost.hitRequestRate'),
cachePoints.value.map(point => point.value.cacheHitRequestRate),
theme.success,
),
]
}
const series = [
...usageGapAwareLineSeries(
t('usage.cost.actualCost'),
zeroInactiveValues(
costPoints.value.map(point => decimalDisplayNumber(point.value.estimatedCost)),
requestActivity.value,
),
theme.success,
{ area: 'strong' },
),
]
if (hasNoCacheCost.value) {
series.push(
...usageGapAwareLineSeries(
t('usage.cost.withoutCacheEstimate'),
zeroInactiveValues(
costPoints.value.map(point => decimalDisplayNumber(point.value.noCacheCost)),
requestActivity.value,
),
theme.textMuted,
),
)
}
return series
}
function formatTooltip(params: unknown) {
const rows = tooltipRows(params)
const pointIndex = tooltipIndex(rows[0])
const point = points.value[pointIndex]
const index = tooltipIndex(tooltipRows(params)[0])
const point = points.value[index]
if (!point)
return ''
const theme = palette.value
if (activeView.value === 'savings') {
return chartTooltipContent(point.label, [
usageTooltipItem(
t('usage.cost.cacheSavings'),
formatUsd(costAmount(savingsPoints.value[pointIndex]?.value ?? null, pointIndex)),
theme.success,
),
])
}
if (activeView.value === 'cache') {
return chartTooltipContent(point.label, [
usageTooltipItem(t('usage.cost.cacheTokenProportion'), formatPercent(cachePoints.value[pointIndex]?.value.cachedTokenRate ?? null), theme.normal),
usageTooltipItem(t('usage.cost.hitRequestRate'), formatPercent(cachePoints.value[pointIndex]?.value.cacheHitRequestRate ?? null), theme.success),
])
}
const lines = [
usageTooltipItem(
t('usage.cost.actualCost'),
formatUsd(costAmount(costPoints.value[pointIndex]?.value.estimatedCost ?? null, pointIndex)),
theme.success,
),
]
if (costPoints.value[pointIndex]?.value.noCacheCost != null) {
lines.push(usageTooltipItem(
t('usage.cost.withoutCacheEstimate'),
formatUsd(costAmount(costPoints.value[pointIndex]?.value.noCacheCost ?? null, pointIndex)),
theme.textMuted,
))
}
const lines = chart.value.series.flatMap((series) => {
const value = series.tooltipValue(index)
return value == null
? []
: [
usageTooltipItem(series.label, value, series.color),
]
})
return chartTooltipContent(point.label, lines)
}
function costAmount(value: string | null, pointIndex: number) {
return value ?? (requestActivity.value[pointIndex] === false
? '0'
: null)
}
</script>
<template>
@@ -271,8 +200,8 @@ function costAmount(value: string | null, pointIndex: number) {
</template>
<template #body>
<div class="grid min-h-66" :class="hasData ? 'gap-3' : 'flex-1'">
<div v-if="hasData && cost" class="grid grid-cols-2 gap-x-1 gap-y-3 rounded-xl bg-z-fill-quaternary/45 p-2 @min-[24rem]/cost:grid-cols-3 @min-[40rem]/cost:grid-cols-5">
<div class="grid min-h-66" :class="chart.hasData ? 'gap-3' : 'flex-1'">
<div v-if="chart.hasData && cost" class="grid grid-cols-2 gap-x-1 gap-y-3 rounded-xl bg-z-fill-quaternary/45 p-2 @min-[24rem]/cost:grid-cols-3 @min-[40rem]/cost:grid-cols-5">
<div class="grid min-w-0 gap-1 px-1.5">
<span class="text-[10px] font-bold text-z-text-quaternary" :title="t('usage.billing.totalCost')">{{ t('usage.cost.actualCost') }}</span>
<strong class="wrap-anywhere font-mono text-z-sm font-heavy tabular-nums text-z-text">
@@ -304,7 +233,7 @@ function costAmount(value: string | null, pointIndex: number) {
</strong>
</div>
</div>
<BaseChart v-if="hasData" :option="chartOption" :height="210" />
<BaseChart v-if="chart.hasData" :option="chartOption" :height="210" />
<ZEmpty
v-else
size="small"
@@ -2,25 +2,39 @@ import type { TableColumn } from '@codex-proxy/ui'
import type { Ref } from 'vue'
import type { UsageListRecord, UsageRecordStatus } from '@/api'
import { useTableColumns } from '@codex-proxy/ui'
import { clamp, partition } from 'es-toolkit'
import { computed } from 'vue'
import { usageRecordColumns } from '@/components/usage/shared/columns'
import { t } from '@/i18n'
export function useUsageRecordColumns(status: Ref<UsageRecordStatus>, tableWidth: Readonly<Ref<number>>) {
const columns = computed(() => usageRecordColumns.value.map((column) => {
if (column.key === 'createdAtDisplay')
return { ...column, width: 128 }
if (column.key === 'accountEmail')
return { ...column, width: 280, hideable: true }
return ['clientApiKeyName', 'model', 'reasoningEffort'].includes(column.key)
? { ...column, fixedWidth: true }
: column
type ColumnLayout = Record<string, Pick<TableColumn, 'width' | 'fixedWidth' | 'hideable'>>
const requestLayout: ColumnLayout = {
clientApiKeyName: { fixedWidth: true },
accountEmail: { width: 280, hideable: true },
model: { fixedWidth: true },
reasoningEffort: { fixedWidth: true },
}
const errorActionWidth = 72
const maxErrorWidth = 370
const errorLayout: ColumnLayout = {
...requestLayout,
transport: { width: 112 },
actions: { width: errorActionWidth },
}
function columnsWithLayout(layout: ColumnLayout) {
return usageRecordColumns.value.map(column => ({
...column,
...layout[column.key],
}))
const usage = useTableColumns(columns, 'usage-records')
}
export function useUsageRecordColumns(status: Ref<UsageRecordStatus>, tableWidth: Readonly<Ref<number>>) {
const usage = useTableColumns(() => columnsWithLayout(requestLayout), 'usage-records')
const errors = useTableColumns(() => {
const time = columns.value.find(column => column.key === 'createdAtDisplay')!
const actionWidth = 72
const errorWidth = 370
const [time, details] = partition(columnsWithLayout(errorLayout), column => column.key === 'createdAtDisplay')
return [
{
key: 'errorMessage',
@@ -28,18 +42,12 @@ export function useUsageRecordColumns(status: Ref<UsageRecordStatus>, tableWidth
kind: 'custom',
fixed: 'left',
minWidth: tableWidth.value
? Math.min(errorWidth, Math.max(96, (tableWidth.value - actionWidth) / 2))
: errorWidth,
? clamp((tableWidth.value - errorActionWidth) / 2, 96, maxErrorWidth)
: maxErrorWidth,
hideable: false,
},
time,
...columns.value.filter(column => column.key !== time.key).map((column) => {
if (column.key === 'transport')
return { ...column, width: 112 }
if (column.key === 'actions')
return { ...column, width: actionWidth }
return column
}),
...time,
...details,
] satisfies TableColumn<UsageListRecord>[]
}, 'usage-error-records')
return computed(() => status.value === 'error'
-1
View File
@@ -171,7 +171,6 @@ watch(timeRange, () => {
<UsageRecordsTable
class="min-h-0 flex-1"
:columns="columns.visibleColumns.value"
request-details
:rows="records"
:loading="loading"
:empty-text="t('usage.page.noRequestsMatchTheseFilters')"
+9 -19
View File
@@ -1,25 +1,15 @@
# v3.54.0
## 新增功能
- 账号分组可设置模型允许或拒绝列表、子代理权限及 Ultrafast 档位,已有分组默认允许全部模型和子代理
- API 密钥支持批量编辑,可查看近 7 天或 30 天的模型用量、费用和请求数,也可将本期日、周预算窗口对齐到指定账号
- OpenAI 请求国家默认跟随代理或全局位置,也可在「系统设置 → 上游配置 → 请求位置覆盖」中选择发送空值、透传或指定国家
- OpenAI OAuth 同步审核默认优先使用有权限的 `codex-auto-review`,可在「系统设置 → 上游配置 → 模型映射」中关闭「专用审核模型」
## 优化改进
- 账号模型白名单可快速添加图片模型,账号额度页区分定时预热和额度重置后的预热
- 账号授权或凭据刷新失败时,管理端显示更具体的原因
# v3.54.1
## 问题修复
- OpenAI Responses 回退到 HTTP/SSE 后,继续使用已失效的响应 ID 会返回 `previous_response_not_found`,客户端可移除旧 ID 并携带完整历史重试
- OpenAI OAuth 配额刷新识别到访问令牌被撤销时会使其过期,刷新模型目录时保留凭据错误原因
- 修复 Safari 等 WebKit 浏览器中固定表头遮挡数据行的问题
- 统一用量记录的时间列,管理端和密钥用量页都分行显示时间和日期
## 优化改进
- 创建或编辑账号分组时,可像编辑账号一样搜索、手动添加模型,并在白名单中一键添加常用图片模型
- 「请求国家」现位于「系统设置 → 上游配置」,可独立于「请求位置覆盖」选择策略
## 升级须知
- 从正式版 `v3.53.1` 可直接升级,已验证分组、密钥和运行设置保留。运行过旧 `0045_account_group_policies` 或 `0046_openai_request_settings` 的源码部署无法直接复用该数据库,需从执行旧迁移前的备份升级,或另行迁移业务数据
- 自建管理 API 客户端保存运行设置时,须提交 `resetCreditOnLowWeeklyQuota`、`openaiOauthGuardianReviewModel` 和 `openaiRequestCountry`,可从当前设置读取并原样回传
- 管理 API 的账号代理绑定改用 `outboundProxyId`,全局和密钥的客户端身份配置分别改用 `providerRequestProfiles` 和 `providerRequestProfileOverrides`
- 读取仪表盘账号用量的客户端请改用 `metric`、`metricValueRaw` 和 `lastUsedRelative`,需要原始时间时读取 `lastUsedAt`
- Docker Compose 部署使用的 PostgreSQL 镜像更新至 18.7,Redis 镜像更新至 8.10.3
+5 -5
View File
@@ -1,7 +1,7 @@
version: 3.54.0
version: 3.54.1
published:
'3':
stable: 3.53.1
rc: 3.53.1
beta: 3.53.1
alpha: 3.53.1
stable: 3.54.0
rc: 3.54.0
beta: 3.54.0
alpha: 3.54.0