diff --git a/packages/console/core/script/lookup-user.ts b/packages/console/core/script/lookup-user.ts index 6b856d1c3e..0011ae052f 100644 --- a/packages/console/core/script/lookup-user.ts +++ b/packages/console/core/script/lookup-user.ts @@ -14,6 +14,7 @@ import { KeyTable } from "../src/schema/key.sql.js" import { BlackData } from "../src/black.js" import { centsToMicroCents } from "../src/util/price.js" import { getWeekBounds } from "../src/util/date.js" +import { ModelTable } from "../src/schema/model.sql.js" // get input from command line const identifier = process.argv[2] @@ -222,6 +223,50 @@ async function printWorkspace(workspaceID: string) { ), ) + await printTable("28-Day Usage", (tx) => + tx + .select({ + date: sql`DATE(${UsageTable.timeCreated})`.as("date"), + requests: sql`COUNT(*)`.as("requests"), + inputTokens: sql`SUM(${UsageTable.inputTokens})`.as("input_tokens"), + outputTokens: sql`SUM(${UsageTable.outputTokens})`.as("output_tokens"), + reasoningTokens: sql`SUM(${UsageTable.reasoningTokens})`.as("reasoning_tokens"), + cacheReadTokens: sql`SUM(${UsageTable.cacheReadTokens})`.as("cache_read_tokens"), + cacheWrite5mTokens: sql`SUM(${UsageTable.cacheWrite5mTokens})`.as("cache_write_5m_tokens"), + cacheWrite1hTokens: sql`SUM(${UsageTable.cacheWrite1hTokens})`.as("cache_write_1h_tokens"), + cost: sql`SUM(${UsageTable.cost})`.as("cost"), + }) + .from(UsageTable) + .where( + and( + eq(UsageTable.workspaceID, workspace.id), + sql`${UsageTable.timeCreated} >= DATE_SUB(NOW(), INTERVAL 28 DAY)`, + ), + ) + .groupBy(sql`DATE(${UsageTable.timeCreated})`) + .orderBy(sql`DATE(${UsageTable.timeCreated}) DESC`) + .then((rows) => { + const totalCost = rows.reduce((sum, r) => sum + Number(r.cost), 0) + const mapped = rows.map((row) => ({ + ...row, + cost: `$${(Number(row.cost) / 100000000).toFixed(2)}`, + })) + if (mapped.length > 0) { + mapped.push({ + date: "TOTAL", + requests: null as any, + inputTokens: null as any, + outputTokens: null as any, + reasoningTokens: null as any, + cacheReadTokens: null as any, + cacheWrite5mTokens: null as any, + cacheWrite1hTokens: null as any, + cost: `$${(totalCost / 100000000).toFixed(2)}`, + }) + } + return mapped + }), + ) /* await printTable("Usage", (tx) => tx @@ -247,6 +292,22 @@ async function printWorkspace(workspaceID: string) { cost: `$${(row.cost / 100000000).toFixed(2)}`, })), ), + ) + await printTable("Disabled Models", (tx) => + tx + .select({ + model: ModelTable.model, + timeCreated: ModelTable.timeCreated, + }) + .from(ModelTable) + .where(eq(ModelTable.workspaceID, workspace.id)) + .orderBy(sql`${ModelTable.timeCreated} DESC`) + .then((rows) => + rows.map((row) => ({ + model: row.model, + timeCreated: formatDate(row.timeCreated), + })), + ), ) */ }