GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — wip: zen · f2dmarques/opencode@cf069dd

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/console
    • app/src/routes/workspace/[id]/billing
      • payment-section.module.css
      • payment-section.tsx
    • core
      • script
        • credit-workspace.ts
        • lookup-user.ts
      • src
        • billing.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/console/app/src/routes/workspace/[id]/billing/payment-section.module.css‎

Copy file name to clipboardExpand all lines: packages/console/app/src/routes/workspace/[id]/billing/payment-section.module.css
+23-3Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@
4545
text-decoration: line-through;
4646
}
4747
}
48+
49+
&[data-slot="payment-receipt"] {
50+
span {
51+
display: inline-block;
52+
padding: var(--space-3) var(--space-4);
53+
font-size: var(--font-size-sm);
54+
line-height: 1.5;
55+
}
56+
57+
button {
58+
font-size: var(--font-size-sm);
59+
}
60+
}
4861
}
4962

5063
tbody tr {
@@ -54,23 +67,30 @@
5467
}
5568

5669
@media (max-width: 40rem) {
70+
5771
th,
5872
td {
5973
padding: var(--space-2) var(--space-3);
6074
font-size: var(--font-size-xs);
6175
}
6276

6377
th {
64-
&:nth-child(2) /* Payment ID */ {
78+
&:nth-child(2)
79+
80+
/* Payment ID */
81+
{
6582
display: none;
6683
}
6784
}
6885

6986
td {
70-
&:nth-child(2) /* Payment ID */ {
87+
&:nth-child(2)
88+
89+
/* Payment ID */
90+
{
7191
display: none;
7292
}
7393
}
7494
}
7595
}
76-
}
96+
}
Collapse file

‎packages/console/app/src/routes/workspace/[id]/billing/payment-section.tsx‎

Copy file name to clipboardExpand all lines: packages/console/app/src/routes/workspace/[id]/billing/payment-section.tsx
+17-11Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export function PaymentSection() {
7777
<For each={payments()!}>
7878
{(payment) => {
7979
const date = new Date(payment.timeCreated)
80+
const isCredit = !payment.paymentID
8081
return (
8182
<tr>
8283
<td data-slot="payment-date" title={formatDateUTC(date)}>
@@ -85,19 +86,24 @@ export function PaymentSection() {
8586
<td data-slot="payment-id">{payment.id}</td>
8687
<td data-slot="payment-amount" data-refunded={!!payment.timeRefunded}>
8788
${((payment.amount ?? 0) / 100000000).toFixed(2)}
89+
{isCredit ? " (credit)" : ""}
8890
</td>
8991
<td data-slot="payment-receipt">
90-
<button
91-
onClick={async () => {
92-
const receiptUrl = await downloadReceiptAction(params.id!, payment.paymentID!)
93-
if (receiptUrl) {
94-
window.open(receiptUrl, "_blank")
95-
}
96-
}}
97-
data-slot="receipt-button"
98-
>
99-
View
100-
</button>
92+
{isCredit ? (
93+
<span>-</span>
94+
) : (
95+
<button
96+
onClick={async () => {
97+
const receiptUrl = await downloadReceiptAction(params.id!, payment.paymentID!)
98+
if (receiptUrl) {
99+
window.open(receiptUrl, "_blank")
100+
}
101+
}}
102+
data-slot="receipt-button"
103+
>
104+
View
105+
</button>
106+
)}
101107
</td>
102108
</tr>
103109
)
Collapse file

‎packages/console/core/script/credit-workspace.ts‎

Copy file name to clipboard
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Billing } from "../src/billing.js"
2+
3+
// get input from command line
4+
const workspaceID = process.argv[2]
5+
const dollarAmount = process.argv[3]
6+
7+
if (!workspaceID || !dollarAmount) {
8+
console.error("Usage: bun credit-workspace.ts <workspaceID> <dollarAmount>")
9+
process.exit(1)
10+
}
11+
12+
const amountInDollars = parseFloat(dollarAmount)
13+
if (isNaN(amountInDollars) || amountInDollars <= 0) {
14+
console.error("Error: dollarAmount must be a positive number")
15+
process.exit(1)
16+
}
17+
18+
await Billing.grantCredit(workspaceID, amountInDollars)
19+
20+
console.log(`Added payment of $${amountInDollars.toFixed(2)} to workspace ${workspaceID}`)
Collapse file

‎packages/console/core/script/lookup-user.ts‎

Copy file name to clipboardExpand all lines: packages/console/core/script/lookup-user.ts
+27-1Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Database, eq, sql, inArray } from "../src/drizzle/index.js"
22
import { AuthTable } from "../src/schema/auth.sql.js"
33
import { UserTable } from "../src/schema/user.sql.js"
4-
import { BillingTable, PaymentTable } from "../src/schema/billing.sql.js"
4+
import { BillingTable, PaymentTable, UsageTable } from "../src/schema/billing.sql.js"
55
import { WorkspaceTable } from "../src/schema/workspace.sql.js"
66

77
// get input from command line
@@ -95,6 +95,32 @@ async function printWorkspace(workspaceID: string) {
9595
})),
9696
),
9797
)
98+
99+
await printTable("Usage", (tx) =>
100+
tx
101+
.select({
102+
model: UsageTable.model,
103+
provider: UsageTable.provider,
104+
inputTokens: UsageTable.inputTokens,
105+
outputTokens: UsageTable.outputTokens,
106+
reasoningTokens: UsageTable.reasoningTokens,
107+
cacheReadTokens: UsageTable.cacheReadTokens,
108+
cacheWrite5mTokens: UsageTable.cacheWrite5mTokens,
109+
cacheWrite1hTokens: UsageTable.cacheWrite1hTokens,
110+
cost: UsageTable.cost,
111+
timeCreated: UsageTable.timeCreated,
112+
})
113+
.from(UsageTable)
114+
.where(eq(UsageTable.workspaceID, workspace.id))
115+
.orderBy(sql`${UsageTable.timeCreated} DESC`)
116+
.limit(1000)
117+
.then((rows) =>
118+
rows.map((row) => ({
119+
...row,
120+
cost: `$${(row.cost / 100000000).toFixed(2)}`,
121+
})),
122+
),
123+
)
98124
}
99125

100126
function printHeader(title: string) {
Collapse file

‎packages/console/core/src/billing.ts‎

Copy file name to clipboardExpand all lines: packages/console/core/src/billing.ts
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,24 @@ export namespace Billing {
157157
})
158158
}
159159

160+
export const grantCredit = async (workspaceID: string, dollarAmount: number) => {
161+
const amountInMicroCents = centsToMicroCents(dollarAmount * 100)
162+
await Database.transaction(async (tx) => {
163+
await tx
164+
.update(BillingTable)
165+
.set({
166+
balance: sql`${BillingTable.balance} + ${amountInMicroCents}`,
167+
})
168+
.where(eq(BillingTable.workspaceID, workspaceID))
169+
await tx.insert(PaymentTable).values({
170+
workspaceID,
171+
id: Identifier.create("payment"),
172+
amount: amountInMicroCents,
173+
})
174+
})
175+
return amountInMicroCents
176+
}
177+
160178
export const setMonthlyLimit = fn(z.number(), async (input) => {
161179
return await Database.use((tx) =>
162180
tx

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.