mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-09-07 01:56:53 +00:00
* 🎨 feat(web/default): add shadcn-style theme presets, radius prefs, and fix selection badges Integrate the qn-platform–style OKLCH color system into the default frontend while keeping the existing blue-tinted dark tokens for the default theme. Add [data-theme-preset] palettes for seven named presets plus the default zinc-like scale, define [data-theme-radius] overrides so user radius beats preset --radius, and align the Tailwind @custom-variant dark helper with .dark usage. Introduce ThemeCustomizationProvider to own preset and radius state, persist choices in cookies (theme-preset, theme-radius), and sync data-theme-preset / data-theme-radius on <html>. Wrap the tree in main.tsx. Extend ConfigDrawer with theme preset swatches (scoped data-theme-preset) and radius previews wired to context; refactor swatch/card markup so selected CircleCheck badges sit outside clipped rows (remove outer overflow-hidden that hid the centered checkmark). Add i18n keys for preset names, radius, and accessibility labels across en, zh, fr, ja, ru, vi. * 🎨 fix(web): align segmented controls with theme radius tokens - Replace hard-coded inner pill radii (rounded-[5px]) on dashboard chart toolbars with radius-md so the active state follows --radius when users change Radius in Theme Settings. - Use nested radii consistent with TabsList/TabsTrigger: outer rounded-lg (var(--radius)) and inner rounded-md (calc(var(--radius) - 2px)) so the track and active thumb stay concentric at small scales (e.g. 0.3rem) instead of a squared “focus” block inside a rounded shell. - Apply the same pattern to pricing SegmentedControl and the segmented groups in consumption-distribution-chart, model-charts, and user-charts. Verified: bun run typecheck (web/default) * ✨ feat(pricing): enrich model details with uptime sparkline and API documentation Add a compact 30-day uptime sparkline (OpenRouter-style bars + aggregate %) with per-day tooltips, surface it in a status row under quick stats and in the per-group performance table, and extend mock data so uptime series are stable and optionally scoped by group. Introduce an API tab with Shiki-highlighted code samples (cURL, Python, TypeScript, JavaScript), endpoint-type switching, authentication guidance, a supported-parameters table, and mock per-group RPM/TPM/RPD limits. Infer vendor, tokenizer, license, and data-retention hints for a provider & data privacy card on the Overview tab (capabilities/modalities stay with model identity; rate limits stay with the API tab). Update i18n for all new user-facing strings across en, zh, fr, ja, ru, and vi. * 🏆 feat(rankings): add comprehensive rankings dashboard Add a mock-data powered rankings experience with period tabs, model, app, and vendor leaderboards, market share and history charts, movers, new releases, and per-category sections while backend analytics are pending. Link ranked models to pricing details and ranked vendors to filtered pricing results, and include localized copy for all supported frontend locales. * fix(theme): correct theme preset selection state - update Base UI Radio selectors to use data-checked/data-unchecked states. - fix unchecked theme options still showing selected indicators. - isolate the default theme preview tokens to prevent preset changes from leaking into it. * fix(setup): correct usage mode radio state - use Base UI data-checked/data-unchecked states for RadioGroup styling. - hide radio indicators when options are unchecked to avoid setup page display issues. - drive usage mode card and icon selection styles from Base UI state. * fix(auth): submit sign-in and sign-up forms * 🎨 refactor: Align default theme with shadcn Base Nova and prune legacy customization Migrate shadcn UI to Base UI primitives via CLI (`base-nova` / `components.json`) and reinstall full component registry with `--overwrite`, including Hugeicons-backed widgets and newly added registry components. - Remove custom multi-preset/theme-radius system (`ThemeCustomizationProvider`, cookies, preset UI from config drawer); rely on official semantic CSS tokens + light/dark only. - Replace `theme.css` with shadcn’s documented neutral `:root`/`.dark` palette and `@theme inline` mappings (plus skeleton token vars for existing shimmer usage). - Update global styles for Base UI: collapsible animation uses `--collapsible-panel-height`; clarify scroll-lock override comment. Application compatibility: - Keep minimal shims where app code diverged from official APIs (popover collision props, combobox legacy `options` callers, Spinner prop typing). - Switch interactive styling from Radix-era `data-state` / `--radix-*` selectors to Base UI semantics (`data-open`, `data-popup-open`, `data-panel-open`, `--anchor-width`, etc.) Tooling / docs / build: - Rename Rsbuild vendor chunk grouping to `@base-ui` + transitive `@radix-ui`. - Refresh AGENTS.md / CLAUDE.md / classic→default sync skill for Base UI stack. - Bump `package.json` / lockfile for shadcn-postinstall deps (Hugeicons, chart stack, themes, etc.) Verified: `bun run typecheck` passes. Note: `bun run lint` still reports pre-existing hooks rule violations elsewhere; not addressed in this change. * 🎨 chore(web/default): unify table toolbar, relocate usage stats, refine filters - Refactor DataTableToolbar to a single wrapping flex row with a right-aligned action cluster (Reset / Search / View / Expand) for a cleaner Ant Design Pro–style filter bar; remove the dedicated stats row and the toolbar `stats` prop. - Move Common Logs summary badges (Usage / RPM / TPM) and the sensitive- data visibility toggle into the page header via CommonLogsHeaderActions and SectionPageLayout.Actions so the toolbar stays focused on filters. - Slim CommonLogsFilterBar props (no stats / preActions eye control). - Improve CompactDateTimeRangePicker: show minute-precision labels on the trigger (seconds omitted; aligns with datetime-local inputs); widen the trigger on sm+ breakpoints so the full range is visible without truncation; apply the same width in task logs filters. - Simplify DataTableViewOptions: text-only “View” trigger, no sliders icon. - Earlier layout tweak: extra top padding on SectionPageLayout scroll content so control focus rings are not clipped by overflow. * feat(web/default): Base UI migration and component foundation Migrate from Radix UI to Base UI, rewrite core UI primitives, update dependencies (recharts, date-fns, next-themes), add shadcn agent skill documentation, and refresh AI element components. This is the foundational work from the v2/localmain lineage that was not covered by the individual feature commits above. --------- Co-authored-by: t0ng7u <dev@aiass.cc> Co-authored-by: QuentinHsu <xuquentinyang@gmail.com>
399 lines
12 KiB
TypeScript
Vendored
399 lines
12 KiB
TypeScript
Vendored
import { useCallback, useMemo, useState } from 'react'
|
|
import { ChevronDown, ChevronUp, Plus, Trash2 } from 'lucide-react'
|
|
import { useTranslation } from 'react-i18next'
|
|
import { Button } from '@/components/ui/button'
|
|
import {
|
|
Card,
|
|
CardContent,
|
|
CardDescription,
|
|
CardHeader,
|
|
CardTitle,
|
|
} from '@/components/ui/card'
|
|
import {
|
|
Collapsible,
|
|
CollapsibleContent,
|
|
CollapsibleTrigger,
|
|
} from '@/components/ui/collapsible'
|
|
import { Input } from '@/components/ui/input'
|
|
import {
|
|
Select,
|
|
SelectContent,
|
|
SelectItem,
|
|
SelectTrigger,
|
|
SelectValue,
|
|
} from '@/components/ui/select'
|
|
import { StatusBadge } from '@/components/status-badge'
|
|
|
|
const OP_ADD = 'add' as const
|
|
const OP_REMOVE = 'remove' as const
|
|
const OP_APPEND = 'append' as const
|
|
|
|
type OpType = typeof OP_ADD | typeof OP_REMOVE | typeof OP_APPEND
|
|
|
|
type Rule = {
|
|
_id: string
|
|
userGroup: string
|
|
op: OpType
|
|
targetGroup: string
|
|
description: string
|
|
}
|
|
|
|
let _idCounter = 0
|
|
function uid() {
|
|
return `gsu_${++_idCounter}`
|
|
}
|
|
|
|
function parsePrefix(rawKey: string): { op: OpType; groupName: string } {
|
|
if (rawKey.startsWith('+:')) return { op: OP_ADD, groupName: rawKey.slice(2) }
|
|
if (rawKey.startsWith('-:'))
|
|
return { op: OP_REMOVE, groupName: rawKey.slice(2) }
|
|
return { op: OP_APPEND, groupName: rawKey }
|
|
}
|
|
|
|
function toRawKey(op: OpType, groupName: string): string {
|
|
if (op === OP_ADD) return `+:${groupName}`
|
|
if (op === OP_REMOVE) return `-:${groupName}`
|
|
return groupName
|
|
}
|
|
|
|
function safeParseJson(str: string): Record<string, Record<string, string>> {
|
|
if (!str || !str.trim()) return {}
|
|
try {
|
|
return JSON.parse(str) as Record<string, Record<string, string>>
|
|
} catch {
|
|
return {}
|
|
}
|
|
}
|
|
|
|
function flattenRules(nested: Record<string, Record<string, string>>): Rule[] {
|
|
const rules: Rule[] = []
|
|
for (const [userGroup, inner] of Object.entries(nested)) {
|
|
if (typeof inner !== 'object' || inner === null) continue
|
|
for (const [rawKey, desc] of Object.entries(inner)) {
|
|
const { op, groupName } = parsePrefix(rawKey)
|
|
rules.push({
|
|
_id: uid(),
|
|
userGroup,
|
|
op,
|
|
targetGroup: groupName,
|
|
description:
|
|
op === OP_REMOVE ? 'remove' : typeof desc === 'string' ? desc : '',
|
|
})
|
|
}
|
|
}
|
|
return rules
|
|
}
|
|
|
|
function nestRules(rules: Rule[]): Record<string, Record<string, string>> {
|
|
const result: Record<string, Record<string, string>> = {}
|
|
for (const { userGroup, op, targetGroup, description } of rules) {
|
|
if (!userGroup || !targetGroup) continue
|
|
if (!result[userGroup]) result[userGroup] = {}
|
|
result[userGroup][toRawKey(op, targetGroup)] = description
|
|
}
|
|
return result
|
|
}
|
|
|
|
function serializeRules(rules: Rule[]): string {
|
|
const nested = nestRules(rules)
|
|
return Object.keys(nested).length === 0
|
|
? '{}'
|
|
: JSON.stringify(nested, null, 2)
|
|
}
|
|
|
|
const OP_BADGE_MAP: Record<
|
|
OpType,
|
|
{ variant: 'info' | 'danger' | 'neutral'; label: string }
|
|
> = {
|
|
[OP_ADD]: { variant: 'info', label: 'Add (+:)' },
|
|
[OP_REMOVE]: { variant: 'danger', label: 'Remove (-:)' },
|
|
[OP_APPEND]: { variant: 'neutral', label: 'Append' },
|
|
}
|
|
|
|
type GroupSpecialUsableRulesEditorProps = {
|
|
value: string
|
|
onChange: (value: string) => void
|
|
}
|
|
|
|
type GroupSectionProps = {
|
|
groupName: string
|
|
items: Rule[]
|
|
onUpdate: (id: string, field: keyof Rule, val: string) => void
|
|
onRemove: (id: string) => void
|
|
onAdd: (groupName: string) => void
|
|
onRemoveGroup: (groupName: string) => void
|
|
}
|
|
|
|
function GroupSection(props: GroupSectionProps) {
|
|
const { t } = useTranslation()
|
|
const [open, setOpen] = useState(false)
|
|
|
|
return (
|
|
<Collapsible open={open} onOpenChange={setOpen}>
|
|
<div className='rounded-lg border'>
|
|
<div className='flex items-center justify-between p-3'>
|
|
<div className='flex items-center gap-2'>
|
|
<CollapsibleTrigger
|
|
render={
|
|
<Button variant='ghost' size='sm' className='h-6 w-6 p-0' />
|
|
}
|
|
>
|
|
{open ? (
|
|
<ChevronUp className='h-4 w-4' />
|
|
) : (
|
|
<ChevronDown className='h-4 w-4' />
|
|
)}
|
|
</CollapsibleTrigger>
|
|
<span className='font-semibold'>{props.groupName}</span>
|
|
<StatusBadge variant='neutral' copyable={false}>
|
|
{props.items.length} {t('rules')}
|
|
</StatusBadge>
|
|
</div>
|
|
<div className='flex items-center gap-1'>
|
|
<Button
|
|
variant='ghost'
|
|
size='sm'
|
|
className='h-7 w-7 p-0'
|
|
onClick={() => props.onAdd(props.groupName)}
|
|
>
|
|
<Plus className='h-4 w-4' />
|
|
</Button>
|
|
<Button
|
|
variant='ghost'
|
|
size='sm'
|
|
className='text-destructive h-7 w-7 p-0'
|
|
onClick={() => props.onRemoveGroup(props.groupName)}
|
|
>
|
|
<Trash2 className='h-4 w-4' />
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
<CollapsibleContent>
|
|
<div className='space-y-2 border-t p-3'>
|
|
{props.items.map((rule) => (
|
|
<div key={rule._id} className='flex items-center gap-2'>
|
|
<Select
|
|
value={rule.op}
|
|
onValueChange={(v) =>
|
|
v !== null && props.onUpdate(rule._id, 'op', v)
|
|
}
|
|
>
|
|
<SelectTrigger className='w-[130px]'>
|
|
<SelectValue>
|
|
<StatusBadge
|
|
label={t(OP_BADGE_MAP[rule.op].label)}
|
|
variant={OP_BADGE_MAP[rule.op].variant}
|
|
copyable={false}
|
|
/>
|
|
</SelectValue>
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
<SelectItem value={OP_ADD}>
|
|
<StatusBadge
|
|
label={t(OP_BADGE_MAP[OP_ADD].label)}
|
|
variant={OP_BADGE_MAP[OP_ADD].variant}
|
|
copyable={false}
|
|
/>
|
|
</SelectItem>
|
|
<SelectItem value={OP_REMOVE}>
|
|
<StatusBadge
|
|
label={t(OP_BADGE_MAP[OP_REMOVE].label)}
|
|
variant={OP_BADGE_MAP[OP_REMOVE].variant}
|
|
copyable={false}
|
|
/>
|
|
</SelectItem>
|
|
<SelectItem value={OP_APPEND}>
|
|
<StatusBadge
|
|
label={t(OP_BADGE_MAP[OP_APPEND].label)}
|
|
variant={OP_BADGE_MAP[OP_APPEND].variant}
|
|
copyable={false}
|
|
/>
|
|
</SelectItem>
|
|
</SelectContent>
|
|
</Select>
|
|
<Input
|
|
className='flex-1'
|
|
value={rule.targetGroup}
|
|
placeholder={t('Group name')}
|
|
onChange={(e) =>
|
|
props.onUpdate(rule._id, 'targetGroup', e.target.value)
|
|
}
|
|
/>
|
|
{rule.op !== OP_REMOVE ? (
|
|
<Input
|
|
className='flex-1'
|
|
value={rule.description}
|
|
placeholder={t('Description')}
|
|
onChange={(e) =>
|
|
props.onUpdate(rule._id, 'description', e.target.value)
|
|
}
|
|
/>
|
|
) : (
|
|
<div className='text-muted-foreground flex-1 px-3 text-sm'>
|
|
-
|
|
</div>
|
|
)}
|
|
<Button
|
|
variant='ghost'
|
|
size='sm'
|
|
className='text-destructive h-8 w-8 p-0'
|
|
onClick={() => props.onRemove(rule._id)}
|
|
>
|
|
<Trash2 className='h-4 w-4' />
|
|
</Button>
|
|
</div>
|
|
))}
|
|
</div>
|
|
</CollapsibleContent>
|
|
</div>
|
|
</Collapsible>
|
|
)
|
|
}
|
|
|
|
export function GroupSpecialUsableRulesEditor(
|
|
props: GroupSpecialUsableRulesEditorProps
|
|
) {
|
|
const { t } = useTranslation()
|
|
const [rules, setRules] = useState<Rule[]>(() =>
|
|
flattenRules(safeParseJson(props.value))
|
|
)
|
|
const [newGroupName, setNewGroupName] = useState('')
|
|
|
|
const { onChange } = props
|
|
const emitChange = useCallback(
|
|
(newRules: Rule[]) => {
|
|
setRules(newRules)
|
|
onChange(serializeRules(newRules))
|
|
},
|
|
[onChange]
|
|
)
|
|
|
|
const updateRule = useCallback(
|
|
(id: string, field: keyof Rule, val: string) => {
|
|
emitChange(
|
|
rules.map((r) => {
|
|
if (r._id !== id) return r
|
|
const updated = { ...r, [field]: val }
|
|
if (field === 'op' && val === OP_REMOVE)
|
|
updated.description = 'remove'
|
|
else if (field === 'op' && r.op === OP_REMOVE && val !== OP_REMOVE) {
|
|
if (updated.description === 'remove') updated.description = ''
|
|
}
|
|
return updated
|
|
})
|
|
)
|
|
},
|
|
[rules, emitChange]
|
|
)
|
|
|
|
const removeRule = useCallback(
|
|
(id: string) => emitChange(rules.filter((r) => r._id !== id)),
|
|
[rules, emitChange]
|
|
)
|
|
|
|
const removeGroup = useCallback(
|
|
(groupName: string) =>
|
|
emitChange(rules.filter((r) => r.userGroup !== groupName)),
|
|
[rules, emitChange]
|
|
)
|
|
|
|
const addRuleToGroup = useCallback(
|
|
(groupName: string) => {
|
|
emitChange([
|
|
...rules,
|
|
{
|
|
_id: uid(),
|
|
userGroup: groupName,
|
|
op: OP_APPEND,
|
|
targetGroup: '',
|
|
description: '',
|
|
},
|
|
])
|
|
},
|
|
[rules, emitChange]
|
|
)
|
|
|
|
const addNewGroup = useCallback(() => {
|
|
const name = newGroupName.trim()
|
|
if (!name) return
|
|
emitChange([
|
|
...rules,
|
|
{
|
|
_id: uid(),
|
|
userGroup: name,
|
|
op: OP_APPEND,
|
|
targetGroup: '',
|
|
description: '',
|
|
},
|
|
])
|
|
setNewGroupName('')
|
|
}, [rules, emitChange, newGroupName])
|
|
|
|
const grouped = useMemo(() => {
|
|
const map: Record<string, Rule[]> = {}
|
|
const order: string[] = []
|
|
for (const r of rules) {
|
|
if (!r.userGroup) continue
|
|
if (!map[r.userGroup]) {
|
|
map[r.userGroup] = []
|
|
order.push(r.userGroup)
|
|
}
|
|
map[r.userGroup].push(r)
|
|
}
|
|
return order.map((name) => ({ name, items: map[name] }))
|
|
}, [rules])
|
|
|
|
return (
|
|
<Card>
|
|
<CardHeader>
|
|
<CardTitle>{t('Special usable group rules')}</CardTitle>
|
|
<CardDescription>
|
|
{t(
|
|
'Define per-group rules to add, remove, or append selectable groups for specific user groups.'
|
|
)}
|
|
</CardDescription>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<div className='space-y-3'>
|
|
{grouped.length === 0 ? (
|
|
<p className='text-muted-foreground py-4 text-center text-sm'>
|
|
{t('No rules yet. Add a group below to get started.')}
|
|
</p>
|
|
) : (
|
|
grouped.map((group) => (
|
|
<GroupSection
|
|
key={group.name}
|
|
groupName={group.name}
|
|
items={group.items}
|
|
onUpdate={updateRule}
|
|
onRemove={removeRule}
|
|
onAdd={addRuleToGroup}
|
|
onRemoveGroup={removeGroup}
|
|
/>
|
|
))
|
|
)}
|
|
|
|
<div className='flex items-center justify-center gap-2 pt-2'>
|
|
<Input
|
|
className='w-[200px]'
|
|
value={newGroupName}
|
|
placeholder={t('User group name')}
|
|
onChange={(e) => setNewGroupName(e.target.value)}
|
|
onKeyDown={(e) => {
|
|
if (e.key === 'Enter') {
|
|
e.preventDefault()
|
|
addNewGroup()
|
|
}
|
|
}}
|
|
/>
|
|
<Button variant='outline' size='sm' onClick={addNewGroup}>
|
|
<Plus className='mr-1 h-4 w-4' />
|
|
{t('Add group rules')}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</CardContent>
|
|
</Card>
|
|
)
|
|
}
|