|
@@ -1,7 +1,7 @@
|
|
|
import { Database, eq, sql, inArray } from "../src/drizzle/index.js"
|
|
import { Database, eq, sql, inArray } from "../src/drizzle/index.js"
|
|
|
import { AuthTable } from "../src/schema/auth.sql.js"
|
|
import { AuthTable } from "../src/schema/auth.sql.js"
|
|
|
import { UserTable } from "../src/schema/user.sql.js"
|
|
import { UserTable } from "../src/schema/user.sql.js"
|
|
|
-import { BillingTable, PaymentTable } from "../src/schema/billing.sql.js"
|
|
|
|
|
|
|
+import { BillingTable, PaymentTable, UsageTable } from "../src/schema/billing.sql.js"
|
|
|
import { WorkspaceTable } from "../src/schema/workspace.sql.js"
|
|
import { WorkspaceTable } from "../src/schema/workspace.sql.js"
|
|
|
|
|
|
|
|
// get input from command line
|
|
// get input from command line
|
|
@@ -95,6 +95,32 @@ async function printWorkspace(workspaceID: string) {
|
|
|
})),
|
|
})),
|
|
|
),
|
|
),
|
|
|
)
|
|
)
|
|
|
|
|
+
|
|
|
|
|
+ await printTable("Usage", (tx) =>
|
|
|
|
|
+ tx
|
|
|
|
|
+ .select({
|
|
|
|
|
+ model: UsageTable.model,
|
|
|
|
|
+ provider: UsageTable.provider,
|
|
|
|
|
+ inputTokens: UsageTable.inputTokens,
|
|
|
|
|
+ outputTokens: UsageTable.outputTokens,
|
|
|
|
|
+ reasoningTokens: UsageTable.reasoningTokens,
|
|
|
|
|
+ cacheReadTokens: UsageTable.cacheReadTokens,
|
|
|
|
|
+ cacheWrite5mTokens: UsageTable.cacheWrite5mTokens,
|
|
|
|
|
+ cacheWrite1hTokens: UsageTable.cacheWrite1hTokens,
|
|
|
|
|
+ cost: UsageTable.cost,
|
|
|
|
|
+ timeCreated: UsageTable.timeCreated,
|
|
|
|
|
+ })
|
|
|
|
|
+ .from(UsageTable)
|
|
|
|
|
+ .where(eq(UsageTable.workspaceID, workspace.id))
|
|
|
|
|
+ .orderBy(sql`${UsageTable.timeCreated} DESC`)
|
|
|
|
|
+ .limit(1000)
|
|
|
|
|
+ .then((rows) =>
|
|
|
|
|
+ rows.map((row) => ({
|
|
|
|
|
+ ...row,
|
|
|
|
|
+ cost: `$${(row.cost / 100000000).toFixed(2)}`,
|
|
|
|
|
+ })),
|
|
|
|
|
+ ),
|
|
|
|
|
+ )
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function printHeader(title: string) {
|
|
function printHeader(title: string) {
|