diff options
| author | Jay V <[email protected]> | 2025-09-16 16:16:30 -0400 |
|---|---|---|
| committer | Jay V <[email protected]> | 2025-09-16 16:16:30 -0400 |
| commit | 4b1eca73eb64c62ebdf668eb18d587510066bd9d (patch) | |
| tree | 19be45b8df61b5db1514887e4307c2bc17f6b19d /cloud/app/src/component/workspace/usage-section.tsx | |
| parent | fffcf69cd45ce98cee37b7bf455a81a69f0fe83c (diff) | |
| download | opencode-4b1eca73eb64c62ebdf668eb18d587510066bd9d.tar.gz opencode-4b1eca73eb64c62ebdf668eb18d587510066bd9d.zip | |
ignore: zen
Diffstat (limited to 'cloud/app/src/component/workspace/usage-section.tsx')
| -rw-r--r-- | cloud/app/src/component/workspace/usage-section.tsx | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/cloud/app/src/component/workspace/usage-section.tsx b/cloud/app/src/component/workspace/usage-section.tsx new file mode 100644 index 000000000..a2ad507af --- /dev/null +++ b/cloud/app/src/component/workspace/usage-section.tsx @@ -0,0 +1,66 @@ +import { Billing } from "@opencode/cloud-core/billing.js" +import { query, useParams, createAsync } from "@solidjs/router" +import { createMemo, For, Show } from "solid-js" +import { formatDateUTC, formatDateForTable } from "./common" +import { withActor } from "~/context/auth.withActor" + +const getUsageInfo = query(async (workspaceID: string) => { + "use server" + return withActor(async () => { + return await Billing.usages() + }, workspaceID) +}, "usage.list") + +export function UsageSection() { + const params = useParams() + const usage = createAsync(() => getUsageInfo(params.id)) + + return ( + <section data-component="usage-section"> + <div data-slot="section-title"> + <h2>Usage History</h2> + <p>Recent API usage and costs.</p> + </div> + <div data-slot="usage-table"> + <Show + when={usage() && usage()!.length > 0} + fallback={ + <div data-component="empty-state"> + <p>Make your first API call to get started.</p> + </div> + } + > + <table data-slot="usage-table-element"> + <thead> + <tr> + <th>Date</th> + <th>Model</th> + <th>Input</th> + <th>Output</th> + <th>Cost</th> + </tr> + </thead> + <tbody> + <For each={usage()!}> + {(usage) => { + const date = createMemo(() => new Date(usage.timeCreated)) + return ( + <tr> + <td data-slot="usage-date" title={formatDateUTC(date())}> + {formatDateForTable(date())} + </td> + <td data-slot="usage-model">{usage.model}</td> + <td data-slot="usage-tokens">{usage.inputTokens}</td> + <td data-slot="usage-tokens">{usage.outputTokens}</td> + <td data-slot="usage-cost">${((usage.cost ?? 0) / 100000000).toFixed(4)}</td> + </tr> + ) + }} + </For> + </tbody> + </table> + </Show> + </div> + </section> + ) +} |
