@@ -14,6 +14,7 @@ import { KeyTable } from "../src/schema/key.sql.js"
1414import { BlackData } from "../src/black.js"
1515import { centsToMicroCents } from "../src/util/price.js"
1616import { getWeekBounds } from "../src/util/date.js"
17+ import { ModelTable } from "../src/schema/model.sql.js"
1718
1819// get input from command line
1920const identifier = process . argv [ 2 ]
@@ -222,6 +223,50 @@ async function printWorkspace(workspaceID: string) {
222223 ) ,
223224 )
224225
226+ await printTable ( "28-Day Usage" , ( tx ) =>
227+ tx
228+ . select ( {
229+ date : sql < string > `DATE(${ UsageTable . timeCreated } )` . as ( "date" ) ,
230+ requests : sql < number > `COUNT(*)` . as ( "requests" ) ,
231+ inputTokens : sql < number > `SUM(${ UsageTable . inputTokens } )` . as ( "input_tokens" ) ,
232+ outputTokens : sql < number > `SUM(${ UsageTable . outputTokens } )` . as ( "output_tokens" ) ,
233+ reasoningTokens : sql < number > `SUM(${ UsageTable . reasoningTokens } )` . as ( "reasoning_tokens" ) ,
234+ cacheReadTokens : sql < number > `SUM(${ UsageTable . cacheReadTokens } )` . as ( "cache_read_tokens" ) ,
235+ cacheWrite5mTokens : sql < number > `SUM(${ UsageTable . cacheWrite5mTokens } )` . as ( "cache_write_5m_tokens" ) ,
236+ cacheWrite1hTokens : sql < number > `SUM(${ UsageTable . cacheWrite1hTokens } )` . as ( "cache_write_1h_tokens" ) ,
237+ cost : sql < number > `SUM(${ UsageTable . cost } )` . as ( "cost" ) ,
238+ } )
239+ . from ( UsageTable )
240+ . where (
241+ and (
242+ eq ( UsageTable . workspaceID , workspace . id ) ,
243+ sql `${ UsageTable . timeCreated } >= DATE_SUB(NOW(), INTERVAL 28 DAY)` ,
244+ ) ,
245+ )
246+ . groupBy ( sql `DATE(${ UsageTable . timeCreated } )` )
247+ . orderBy ( sql `DATE(${ UsageTable . timeCreated } ) DESC` )
248+ . then ( ( rows ) => {
249+ const totalCost = rows . reduce ( ( sum , r ) => sum + Number ( r . cost ) , 0 )
250+ const mapped = rows . map ( ( row ) => ( {
251+ ...row ,
252+ cost : `$${ ( Number ( row . cost ) / 100000000 ) . toFixed ( 2 ) } ` ,
253+ } ) )
254+ if ( mapped . length > 0 ) {
255+ mapped . push ( {
256+ date : "TOTAL" ,
257+ requests : null as any ,
258+ inputTokens : null as any ,
259+ outputTokens : null as any ,
260+ reasoningTokens : null as any ,
261+ cacheReadTokens : null as any ,
262+ cacheWrite5mTokens : null as any ,
263+ cacheWrite1hTokens : null as any ,
264+ cost : `$${ ( totalCost / 100000000 ) . toFixed ( 2 ) } ` ,
265+ } )
266+ }
267+ return mapped
268+ } ) ,
269+ )
225270 /*
226271 await printTable("Usage", (tx) =>
227272 tx
@@ -247,6 +292,22 @@ async function printWorkspace(workspaceID: string) {
247292 cost: `$${(row.cost / 100000000).toFixed(2)}`,
248293 })),
249294 ),
295+ )
296+ await printTable("Disabled Models", (tx) =>
297+ tx
298+ .select({
299+ model: ModelTable.model,
300+ timeCreated: ModelTable.timeCreated,
301+ })
302+ .from(ModelTable)
303+ .where(eq(ModelTable.workspaceID, workspace.id))
304+ .orderBy(sql`${ModelTable.timeCreated} DESC`)
305+ .then((rows) =>
306+ rows.map((row) => ({
307+ model: row.model,
308+ timeCreated: formatDate(row.timeCreated),
309+ })),
310+ ),
250311 )
251312 */
252313}
0 commit comments