feat(quota): add 2-level database-backed resource quota system (#318)

* feat(quota): add database-backed resource quota system

* feat(webui): add resource quota management in team settings (#319)

* feat(webui): add resource quota settings in team management

* refactor(webui): update quotas list to full row layout and restrict skill/mcp to select list

* feat(quota): refactor quota system to 2-level rules and records

* fix(webui): fix overflow and scroll area in quota usage records dialog

* fix(webui): ensure quota records scroll area has explicit max height

* feat(webui): improve quota cards interaction and restrict editable fields in edit mode

* fix(quota): serialize initial records, validate merged updates, and reset on dimension changes (#320)

* feat(quota): replace network quota with agent tools quota (#321)

* feat(webui): show remaining time until next refresh in quota usage records

* fix(webui): rename bash quota resource to Agent Bash Calls

* refactor(quota): remove unused reserved field from quota records

* refactor(quota): remove quota rule cache (#322)
This commit is contained in:
Yiling-J
2026-08-17 20:24:05 +08:00
committed by GitHub
parent dd82daf65c
commit eed0264b9c
200 changed files with 13118 additions and 50 deletions
+46
View File
@@ -0,0 +1,46 @@
import { describe, it, expect } from 'vitest'
import { formatRemainingTime } from './time'
describe('formatRemainingTime', () => {
const baseNow = new Date('2026-08-17T12:00:00Z')
it('formats hours and minutes', () => {
const target = new Date('2026-08-17T15:18:00Z')
expect(formatRemainingTime(target, baseNow)).toBe('3h 18m')
})
it('formats exact hours', () => {
const target = new Date('2026-08-17T15:00:00Z')
expect(formatRemainingTime(target, baseNow)).toBe('3h')
})
it('formats minutes only', () => {
const target = new Date('2026-08-17T12:45:00Z')
expect(formatRemainingTime(target, baseNow)).toBe('45m')
})
it('formats days and hours', () => {
const target = new Date('2026-08-19T16:00:00Z')
expect(formatRemainingTime(target, baseNow)).toBe('2d 4h')
})
it('formats days only', () => {
const target = new Date('2026-08-19T12:00:00Z')
expect(formatRemainingTime(target, baseNow)).toBe('2d')
})
it('handles less than 1 minute', () => {
const target = new Date('2026-08-17T12:00:30Z')
expect(formatRemainingTime(target, baseNow)).toBe('< 1m')
})
it('handles past or equal dates', () => {
const past = new Date('2026-08-17T11:00:00Z')
expect(formatRemainingTime(past, baseNow)).toBe('< 1m')
expect(formatRemainingTime(baseNow, baseNow)).toBe('< 1m')
})
it('accepts ISO strings', () => {
expect(formatRemainingTime('2026-08-17T15:18:00Z', baseNow)).toBe('3h 18m')
})
})
+29
View File
@@ -42,3 +42,32 @@ export const formatDateAgo = (dateString: string) => {
const count = daysAgo >= 0 ? daysAgo : 0
return count === 1 ? m.n_days_ago_singular({ count }) : m.n_days_ago_plural({ count })
}
export const formatRemainingTime = (targetDate: string | Date, now: Date = new Date()): string => {
const targetMs =
typeof targetDate === 'string'
? parseISO(targetDate).getTime()
: targetDate instanceof Date
? targetDate.getTime()
: NaN
if (isNaN(targetMs)) {
return '< 1m'
}
const diffMs = targetMs - now.getTime()
if (diffMs <= 0) {
return '< 1m'
}
const totalSeconds = Math.floor(diffMs / 1000)
const days = Math.floor(totalSeconds / 86400)
const hours = Math.floor((totalSeconds % 86400) / 3600)
const minutes = Math.floor((totalSeconds % 3600) / 60)
if (days > 0) {
return hours > 0 ? `${days}d ${hours}h` : `${days}d`
}
if (hours > 0) {
return minutes > 0 ? `${hours}h ${minutes}m` : `${hours}h`
}
return minutes > 0 ? `${minutes}m` : '< 1m'
}