diff options
Diffstat (limited to 'packages/console/core/script')
| -rw-r--r-- | packages/console/core/script/credit-workspace.ts | 20 | ||||
| -rw-r--r-- | packages/console/core/script/lookup-user.ts | 28 |
2 files changed, 47 insertions, 1 deletions
diff --git a/packages/console/core/script/credit-workspace.ts b/packages/console/core/script/credit-workspace.ts new file mode 100644 index 000000000..29fb1fa64 --- /dev/null +++ b/packages/console/core/script/credit-workspace.ts @@ -0,0 +1,20 @@ +import { Billing } from "../src/billing.js" + +// get input from command line +const workspaceID = process.argv[2] +const dollarAmount = process.argv[3] + +if (!workspaceID || !dollarAmount) { + console.error("Usage: bun credit-workspace.ts <workspaceID> <dollarAmount>") + process.exit(1) +} + +const amountInDollars = parseFloat(dollarAmount) +if (isNaN(amountInDollars) || amountInDollars <= 0) { + console.error("Error: dollarAmount must be a positive number") + process.exit(1) +} + +await Billing.grantCredit(workspaceID, amountInDollars) + +console.log(`Added payment of $${amountInDollars.toFixed(2)} to workspace ${workspaceID}`) diff --git a/packages/console/core/script/lookup-user.ts b/packages/console/core/script/lookup-user.ts index bb919e34d..d0b583a18 100644 --- a/packages/console/core/script/lookup-user.ts +++ b/packages/console/core/script/lookup-user.ts @@ -1,7 +1,7 @@ import { Database, eq, sql, inArray } from "../src/drizzle/index.js" import { AuthTable } from "../src/schema/auth.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" // 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) { |
