Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions browser_tests/fixtures/data/customerEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import type { BillingEventsResponse } from '@comfyorg/ingest-types'
export const AGENT_USAGE_EVENT_TYPE = 'Agent Usage'
export const PARTNER_NODE_USAGE_EVENT_TYPE = 'Partner Node Usage'
export const API_USAGE_EVENT_TYPE = 'API Usage'
export const GPU_USAGE_EVENT_TYPE = 'GPU Usage'

/** `/api/billing/events` page with whole, sub-credit and non-numeric `charge_micro_usd`. */
/** `/api/billing/events` page with whole, one-credit, sub-credit and non-numeric `charge_micro_usd`. */
export const AGENT_USAGE_CUSTOMER_EVENTS = {
events: [
{
Expand All @@ -28,6 +29,15 @@ export const AGENT_USAGE_CUSTOMER_EVENTS = {
input_tokens: 96
}
},
{
event_id: 'evt-gpu-usage-one-credit',
event_type: 'gpu_usage',
createdAt: '2026-09-20T11:15:00Z',
params: {
charge_micro_usd: 4_740,
gpu_seconds: 3
}
},
{
event_id: 'evt-partner-node-usage',
event_type: 'api_node_usage',
Expand All @@ -40,6 +50,6 @@ export const AGENT_USAGE_CUSTOMER_EVENTS = {
],
page: 1,
limit: 7,
total: 3,
total: 4,
totalPages: 1
} satisfies BillingEventsResponse
15 changes: 15 additions & 0 deletions browser_tests/tests/dialogs/usageLogsChargeTooltip.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
AGENT_USAGE_CUSTOMER_EVENTS,
AGENT_USAGE_EVENT_TYPE,
API_USAGE_EVENT_TYPE,
GPU_USAGE_EVENT_TYPE,
PARTNER_NODE_USAGE_EVENT_TYPE
} from '@e2e/fixtures/data/customerEvents'
import { localAuthFixture as test } from '@e2e/fixtures/localAuthFixture'
Expand Down Expand Up @@ -51,6 +52,20 @@ test.describe(
)
})

test('says Credit for a one-credit charge', async ({ comfyPage }) => {
const table = new UsageLogsTable(comfyPage.settingDialog)
const tooltip = new Tooltip(comfyPage.page)

await table.additionalInfoButton(GPU_USAGE_EVENT_TYPE).hover()

await expect(tooltip.open).toContainText('Charge: 1 Credit')
await expect(tooltip.open).not.toContainText('1 Credits')
await expectElementScreenshot(
tooltip.surface(tooltip.open),
'activity-charge-tooltip-one-credit.png'
)
})

test('passes a non-numeric charge through unchanged', async ({
comfyPage
}) => {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/locales/ar/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,7 @@
"apiPricing": "أسعار API",
"charge": "تحصيل رسوم",
"credits": "الرصيد",
"creditUnit": "الرصيد",
"creditsAvailable": "الرصيد المتاح",
"details": "التفاصيل",
"eventType": "نوع الحدث",
Expand Down
1 change: 1 addition & 0 deletions src/locales/de/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,7 @@
"apiPricing": "API-Preise",
"charge": "Abbuchung",
"credits": "Credits",
"creditUnit": "Credits",
"creditsAvailable": "Verfügbare Credits",
"details": "Details",
"eventType": "Ereignistyp",
Expand Down
1 change: 1 addition & 0 deletions src/locales/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -3085,6 +3085,7 @@
"additionalInfo": "Additional Info",
"charge": "Charge",
"lessThanOne": "<1",
"creditUnit": "Credit | Credits",
"model": "Model",
"api": "API",
"added": "Added",
Expand Down
1 change: 1 addition & 0 deletions src/locales/es/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,7 @@
"apiPricing": "Precios de la API",
"charge": "Cobro",
"credits": "Créditos",
"creditUnit": "Créditos",
"creditsAvailable": "Créditos disponibles",
"details": "Detalles",
"eventType": "Tipo de evento",
Expand Down
1 change: 1 addition & 0 deletions src/locales/fa/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,7 @@
"apiPricing": "قیمت‌گذاری API",
"charge": "هزینه",
"credits": "اعتبار",
"creditUnit": "اعتبار",
"creditsAvailable": "اعتبار موجود",
"details": "جزئیات",
"eventType": "نوع رویداد",
Expand Down
1 change: 1 addition & 0 deletions src/locales/fr/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,7 @@
"apiPricing": "Tarification de l’API",
"charge": "Débiter",
"credits": "Crédits",
"creditUnit": "Crédits",
"creditsAvailable": "Crédits disponibles",
"details": "Détails",
"eventType": "Type d'événement",
Expand Down
1 change: 1 addition & 0 deletions src/locales/he/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,7 @@
"apiPricing": "תמחור API",
"charge": "חיוב",
"credits": "קרדיטים",
"creditUnit": "קרדיטים",
"creditsAvailable": "קרדיטים זמינים",
"details": "פרטים",
"eventType": "סוג האירוע",
Expand Down
1 change: 1 addition & 0 deletions src/locales/it/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,7 @@
"apiPricing": "Prezzi API",
"charge": "Addebito",
"credits": "Crediti",
"creditUnit": "Crediti",
"creditsAvailable": "Crediti disponibili",
"details": "Dettagli",
"eventType": "Tipo di evento",
Expand Down
1 change: 1 addition & 0 deletions src/locales/ja/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,7 @@
"apiPricing": "API料金",
"charge": "請求",
"credits": "クレジット",
"creditUnit": "クレジット",
"creditsAvailable": "利用可能なクレジット",
"details": "詳細",
"eventType": "イベントタイプ",
Expand Down
1 change: 1 addition & 0 deletions src/locales/ko/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,7 @@
"apiPricing": "API 가격",
"charge": "청구",
"credits": "크레딧",
"creditUnit": "크레딧",
"creditsAvailable": "사용 가능한 크레딧",
"details": "세부 정보",
"eventType": "이벤트 유형",
Expand Down
1 change: 1 addition & 0 deletions src/locales/pt-BR/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,7 @@
"apiPricing": "Preços da API",
"charge": "Cobrar",
"credits": "Créditos",
"creditUnit": "Créditos",
"creditsAvailable": "Créditos disponíveis",
"details": "Detalhes",
"eventType": "Tipo de evento",
Expand Down
1 change: 1 addition & 0 deletions src/locales/ru/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,7 @@
"apiPricing": "Цены на API",
"charge": "Списать средства",
"credits": "Кредиты",
"creditUnit": "Кредиты",
"creditsAvailable": "Доступно кредитов",
"details": "Детали",
"eventType": "Тип события",
Expand Down
1 change: 1 addition & 0 deletions src/locales/tr/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,7 @@
"apiPricing": "API Fiyatlandırması",
"charge": "Ücretlendirme",
"credits": "Krediler",
"creditUnit": "Krediler",
"creditsAvailable": "Mevcut kredi",
"details": "Detaylar",
"eventType": "Etkinlik Türü",
Expand Down
1 change: 1 addition & 0 deletions src/locales/zh-TW/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,7 @@
"apiPricing": "API 價格",
"charge": "扣款",
"credits": "點數",
"creditUnit": "點數",
"creditsAvailable": "可用點數",
"details": "詳細資料",
"eventType": "事件類型",
Expand Down
1 change: 1 addition & 0 deletions src/locales/zh/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,7 @@
"apiPricing": "API 价格",
"charge": "扣费",
"credits": "积分",
"creditUnit": "积分",
"creditsAvailable": "积分可用",
"details": "详情",
"eventType": "事件类型",
Expand Down
40 changes: 30 additions & 10 deletions src/services/customerEventsService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ vi.mock(import('@/i18n'), async () => {
const { createI18n } = await import('vue-i18n')
return {
d: mockI18n.d,
t: (key: string) => key,
t: (key: string, plural?: unknown) =>
typeof plural === 'number' ? `${key}[${plural}]` : key,
i18n: createI18n({ legacy: false, locale: 'en' })
}
})
Expand Down Expand Up @@ -231,27 +232,27 @@ describe('useCustomerEventsService', () => {
})

it.for([
{ charge: 33_044, expected: 'credits.charge: 7 credits.credits' },
{ charge: '36209', expected: 'credits.charge: 8 credits.credits' },
{ charge: 33_044, expected: 'credits.charge: 7 credits.creditUnit[7]' },
{ charge: '36209', expected: 'credits.charge: 8 credits.creditUnit[8]' },
{
charge: 10_000_000_000,
expected: 'credits.charge: 2,110,000 credits.credits'
expected: 'credits.charge: 2,110,000 credits.creditUnit[2110000]'
},
{ charge: 0, expected: 'credits.charge: 0 credits.credits' },
{ charge: 0, expected: 'credits.charge: 0 credits.creditUnit[0]' },
{
charge: 1,
expected: 'credits.charge: credits.lessThanOne credits.credits'
expected: 'credits.charge: credits.lessThanOne credits.creditUnit[2]'
},
{
charge: 1_000,
expected: 'credits.charge: credits.lessThanOne credits.credits'
expected: 'credits.charge: credits.lessThanOne credits.creditUnit[2]'
},
{
charge: 3_318,
expected: 'credits.charge: credits.lessThanOne credits.credits'
expected: 'credits.charge: credits.lessThanOne credits.creditUnit[2]'
},
{ charge: 4_740, expected: 'credits.charge: 1 credits.credits' },
{ charge: 6_636, expected: 'credits.charge: 1 credits.credits' },
{ charge: 4_740, expected: 'credits.charge: 1 credits.creditUnit[1]' },
{ charge: 6_636, expected: 'credits.charge: 1 credits.creditUnit[1]' },
{ charge: 'n/a', expected: 'Charge Micro Usd: n/a' }
])(
'should render charge_micro_usd $charge as $expected',
Expand All @@ -262,6 +263,25 @@ describe('useCustomerEventsService', () => {
}
)

it.for([
[0, 'Credits'],
[1, 'Credit'],
[2, 'Credits'],
[7, 'Credits']
] as const)(
'English charge unit for a count of %s is %s',
async ([count, unit]) => {
const { createI18n } = await import('vue-i18n')
const { default: en } = await import('@/locales/en/main.json')
const english = createI18n({
legacy: false,
locale: 'en',
messages: { en }
})
expect(english.global.t('credits.creditUnit', count)).toBe(unit)
}
)

const withNothingToRender: ParamsCase[] = [
['params carry only non-allowlisted keys', unrenderableParams],
[
Expand Down
17 changes: 9 additions & 8 deletions src/services/customerEventsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,15 @@ export const useCustomerEventsService = () => {

function formatChargeCredits(microUsd: number) {
const credits = microUsdToCredits(microUsd)
const amount = isSubCreditCharge(credits)
? t('credits.lessThanOne')
: formatCredits({
value: credits,
locale: i18n.global.locale.value,
numberOptions: { minimumFractionDigits: 0, maximumFractionDigits: 0 }
})
return `${amount} ${t('credits.credits')}`
if (isSubCreditCharge(credits)) {
return `${t('credits.lessThanOne')} ${t('credits.creditUnit', 2)}`
}
const amount = formatCredits({
value: credits,
locale: i18n.global.locale.value,
numberOptions: { minimumFractionDigits: 0, maximumFractionDigits: 0 }
})
return `${amount} ${t('credits.creditUnit', Math.round(credits))}`
}

function formatTooltipParam(key: string, value: unknown) {
Expand Down
Loading