From 4d81f90dded0ad3d57a75c880c919e6809087948 Mon Sep 17 00:00:00 2001
From: Jay V
Date: Thu, 28 Aug 2025 17:10:41 -0400
Subject: ignore: cloud
---
cloud/app/src/routes/[workspaceID].tsx | 273 ----------------------
cloud/app/src/routes/index.tsx | 3 +-
cloud/app/src/routes/workspace/[workspaceID].tsx | 274 +++++++++++++++++++++++
3 files changed, 276 insertions(+), 274 deletions(-)
delete mode 100644 cloud/app/src/routes/[workspaceID].tsx
create mode 100644 cloud/app/src/routes/workspace/[workspaceID].tsx
(limited to 'cloud/app/src/routes')
diff --git a/cloud/app/src/routes/[workspaceID].tsx b/cloud/app/src/routes/[workspaceID].tsx
deleted file mode 100644
index 1afcc979e..000000000
--- a/cloud/app/src/routes/[workspaceID].tsx
+++ /dev/null
@@ -1,273 +0,0 @@
-import { Billing } from "@opencode/cloud-core/billing.js"
-import { Key } from "@opencode/cloud-core/key.js"
-import { action, createAsync, revalidate, query, useAction, useSubmission } from "@solidjs/router"
-import { createEffect, createSignal, For, onMount, Show } from "solid-js"
-import { getActor, withActor } from "~/context/auth"
-
-/////////////////////////////////////
-// Keys related queries and actions
-/////////////////////////////////////
-
-const listKeys = query(async () => {
- "use server"
- return withActor(() => Key.list())
-}, "keys")
-
-const createKey = action(async (name: string) => {
- "use server"
- return withActor(() => Key.create({ name }))
-}, "createKey")
-
-const removeKey = action(async (id: string) => {
- "use server"
- return withActor(() => Key.remove({ id }))
-}, "removeKey")
-
-/////////////////////////////////////
-// Billing related queries and actions
-/////////////////////////////////////
-
-const getBillingInfo = query(async () => {
- "use server"
- return withActor(async () => {
- const billing = await Billing.get()
- const payments = await Billing.payments()
- const usage = await Billing.usages()
- return { billing, payments, usage }
- })
-}, "billingInfo")
-
-const createCheckoutUrl = action(async (successUrl: string, cancelUrl: string) => {
- "use server"
- return withActor(() => Billing.generateCheckoutUrl({ successUrl, cancelUrl }))
-}, "checkoutUrl")
-
-//export const route = {
-// preload: () => listKeys(),
-//}
-
-export default function () {
- const actor = createAsync(() => getActor())
-
- /////////////////
- // Keys section
- /////////////////
- const keys = createAsync(() => listKeys())
- const createKeyAction = useAction(createKey)
- const removeKeyAction = useAction(removeKey)
- const createKeySubmission = useSubmission(createKey)
- const [showCreateForm, setShowCreateForm] = createSignal(false)
- const [keyName, setKeyName] = createSignal("")
-
- const formatDate = (date: Date) => {
- return date.toLocaleDateString()
- }
-
- const formatKey = (key: string) => {
- if (key.length <= 11) return key
- return `${key.slice(0, 7)}...${key.slice(-4)}`
- }
-
- const copyToClipboard = async (text: string) => {
- try {
- await navigator.clipboard.writeText(text)
- } catch (error) {
- console.error("Failed to copy to clipboard:", error)
- }
- }
-
- const handleCreateKey = async () => {
- if (!keyName().trim()) return
-
- try {
- await createKeyAction(keyName().trim())
- revalidate("keys")
- setKeyName("")
- setShowCreateForm(false)
- } catch (error) {
- console.error("Failed to create API key:", error)
- }
- }
-
- const handleDeleteKey = async (keyId: string) => {
- if (!confirm("Are you sure you want to delete this API key? This action cannot be undone.")) {
- return
- }
-
- try {
- await removeKeyAction(keyId)
- revalidate("keys")
- } catch (error) {
- console.error("Failed to delete API key:", error)
- }
- }
-
- /////////////////
- // Billing section
- /////////////////
- const billingInfo = createAsync(() => getBillingInfo())
- const [isLoading, setIsLoading] = createSignal(false)
- const createCheckoutUrlAction = useAction(createCheckoutUrl)
-
- // Run once on component mount to check URL parameters
- onMount(() => {
- const url = new URL(window.location.href)
- const result = url.hash
-
- console.log("STRIPE RESULT", result)
-
- if (url.hash === "#success") {
- setIsLoading(true)
- // Remove the hash from the URL
- window.history.replaceState(null, "", window.location.pathname + window.location.search)
- }
- })
-
- createEffect((old?: number) => {
- if (old && old !== billingInfo()?.billing?.balance) {
- setIsLoading(false)
- }
- return billingInfo()?.billing?.balance
- })
-
- const handleBuyCredits = async () => {
- try {
- setIsLoading(true)
- const baseUrl = window.location.href
- const successUrl = new URL(baseUrl)
- successUrl.hash = "success"
-
- const checkoutUrl = await createCheckoutUrlAction(successUrl.toString(), baseUrl)
- if (checkoutUrl) {
- window.location.href = checkoutUrl
- }
- } catch (error) {
- console.error("Failed to get checkout URL:", error)
- setIsLoading(false)
- }
- }
-
- return (
-
-
Actor
-
{JSON.stringify(actor())}
-
API Keys
-
- setKeyName(e.currentTarget.value)}
- onKeyPress={(e) => e.key === "Enter" && handleCreateKey()}
- />
-
-
-
-
-
- }
- >
-
-
-
-
- Create an API key to access opencode gateway
-
- }
- >
- {(key) => (
-
-
-
{key.name}
-
{formatKey(key.key)}
-
- Created: {formatDate(key.timeCreated)}
- {key.timeUsed && ` • Last used: ${formatDate(key.timeUsed)}`}
-
-
-
-
-
-
-
- )}
-
-
-
- Balance
- Manage your billing and add credits to your account.
-
- {(() => {
- const balanceStr = ((billingInfo()?.billing?.balance ?? 0) / 100000000).toFixed(2)
- return `$${balanceStr === "-0.00" ? "0.00" : balanceStr}`
- })()}
-
-
-
- Payments History
- Your recent payment transactions.
- No payments found.
}>
- {(payment) => (
-
- {payment.id}
- {" | "}
- ${((payment.amount ?? 0) / 100000000).toFixed(2)}
- {" | "}
- {new Date(payment.timeCreated).toLocaleDateString()}
-
- )}
-
-
- Usage History
- Your recent API usage and costs.
- No usage found.}>
- {(usage) => (
-
- {usage.model}
- {" | "}
- {usage.inputTokens + usage.outputTokens} tokens
- {" | "}
- ${((usage.cost ?? 0) / 100000000).toFixed(4)}
- {" | "}
- {new Date(usage.timeCreated).toLocaleDateString()}
-
- )}
-
-
- )
-}
diff --git a/cloud/app/src/routes/index.tsx b/cloud/app/src/routes/index.tsx
index 7f8433e7e..7a43f2624 100644
--- a/cloud/app/src/routes/index.tsx
+++ b/cloud/app/src/routes/index.tsx
@@ -23,9 +23,10 @@ function CopyStatus() {
const isLoggedIn = query(async () => {
"use server"
const actor = await getActor()
+ console.log(actor)
if (actor.type === "account") {
const workspaces = await withActor(() => Account.workspaces())
- throw redirect("/" + workspaces[0].id)
+ throw redirect(`/workspace/${workspaces[0].id}`)
}
return false
}, "isLoggedIn")
diff --git a/cloud/app/src/routes/workspace/[workspaceID].tsx b/cloud/app/src/routes/workspace/[workspaceID].tsx
new file mode 100644
index 000000000..00e61a0c7
--- /dev/null
+++ b/cloud/app/src/routes/workspace/[workspaceID].tsx
@@ -0,0 +1,274 @@
+import { Billing } from "@opencode/cloud-core/billing.js"
+import { Key } from "@opencode/cloud-core/key.js"
+import { action, createAsync, revalidate, query, useAction, useSubmission } from "@solidjs/router"
+import { createEffect, createSignal, For, onMount, Show } from "solid-js"
+import { getActor, withActor } from "~/context/auth"
+
+/////////////////////////////////////
+// Keys related queries and actions
+/////////////////////////////////////
+
+const listKeys = query(async () => {
+ "use server"
+ return withActor(() => Key.list())
+}, "keys")
+
+const createKey = action(async (name: string) => {
+ "use server"
+ return withActor(() => Key.create({ name }))
+}, "createKey")
+
+const removeKey = action(async (id: string) => {
+ "use server"
+ return withActor(() => Key.remove({ id }))
+}, "removeKey")
+
+/////////////////////////////////////
+// Billing related queries and actions
+/////////////////////////////////////
+
+const getBillingInfo = query(async () => {
+ "use server"
+ return withActor(async () => {
+ const billing = await Billing.get()
+ const payments = await Billing.payments()
+ const usage = await Billing.usages()
+ return { billing, payments, usage }
+ })
+}, "billingInfo")
+
+const createCheckoutUrl = action(async (successUrl: string, cancelUrl: string) => {
+ "use server"
+ return withActor(() => Billing.generateCheckoutUrl({ successUrl, cancelUrl }))
+}, "checkoutUrl")
+
+const createPortalUrl = action(async (returnUrl: string) => {
+ "use server"
+ return withActor(() => Billing.generatePortalUrl({ returnUrl }))
+}, "portalUrl")
+
+export default function() {
+ const actor = createAsync(() => getActor())
+
+ /////////////////
+ // Keys section
+ /////////////////
+ const keys = createAsync(() => listKeys())
+ const createKeyAction = useAction(createKey)
+ const removeKeyAction = useAction(removeKey)
+ const createKeySubmission = useSubmission(createKey)
+ const [showCreateForm, setShowCreateForm] = createSignal(false)
+ const [keyName, setKeyName] = createSignal("")
+
+ const formatDate = (date: Date) => {
+ return date.toLocaleDateString()
+ }
+
+ const formatKey = (key: string) => {
+ if (key.length <= 11) return key
+ return `${key.slice(0, 7)}...${key.slice(-4)}`
+ }
+
+ const copyToClipboard = async (text: string) => {
+ try {
+ await navigator.clipboard.writeText(text)
+ } catch (error) {
+ console.error("Failed to copy to clipboard:", error)
+ }
+ }
+
+ const handleCreateKey = async () => {
+ if (!keyName().trim()) return
+
+ try {
+ await createKeyAction(keyName().trim())
+ revalidate("keys")
+ setKeyName("")
+ setShowCreateForm(false)
+ } catch (error) {
+ console.error("Failed to create API key:", error)
+ }
+ }
+
+ const handleDeleteKey = async (keyId: string) => {
+ if (!confirm("Are you sure you want to delete this API key? This action cannot be undone.")) {
+ return
+ }
+
+ try {
+ await removeKeyAction(keyId)
+ revalidate("keys")
+ } catch (error) {
+ console.error("Failed to delete API key:", error)
+ }
+ }
+
+ /////////////////
+ // Billing section
+ /////////////////
+ const billingInfo = createAsync(() => getBillingInfo())
+ const [isLoading, setIsLoading] = createSignal(false)
+ const createCheckoutUrlAction = useAction(createCheckoutUrl)
+
+ // Run once on component mount to check URL parameters
+ onMount(() => {
+ const url = new URL(window.location.href)
+ const result = url.hash
+
+ console.log("STRIPE RESULT", result)
+
+ if (url.hash === "#success") {
+ setIsLoading(true)
+ // Remove the hash from the URL
+ window.history.replaceState(null, "", window.location.pathname + window.location.search)
+ }
+ })
+
+ createEffect((old?: number) => {
+ if (old && old !== billingInfo()?.billing?.balance) {
+ setIsLoading(false)
+ }
+ return billingInfo()?.billing?.balance
+ })
+
+ const handleBuyCredits = async () => {
+ try {
+ setIsLoading(true)
+ const baseUrl = window.location.href
+ const successUrl = new URL(baseUrl)
+ successUrl.hash = "success"
+
+ const checkoutUrl = await createCheckoutUrlAction(successUrl.toString(), baseUrl)
+ if (checkoutUrl) {
+ window.location.href = checkoutUrl
+ }
+ } catch (error) {
+ console.error("Failed to get checkout URL:", error)
+ setIsLoading(false)
+ }
+ }
+
+ return (
+
+
Actor
+
{JSON.stringify(actor())}
+
API Keys
+
+ setKeyName(e.currentTarget.value)}
+ onKeyPress={(e) => e.key === "Enter" && handleCreateKey()}
+ />
+
+
+
+
+
+ }
+ >
+
+
+
+
+ Create an API key to access opencode gateway
+
+ }
+ >
+ {(key) => (
+
+
+
{key.name}
+
{formatKey(key.key)}
+
+ Created: {formatDate(key.timeCreated)}
+ {key.timeUsed && ` • Last used: ${formatDate(key.timeUsed)}`}
+
+
+
+
+
+
+
+ )}
+
+
+
+ Balance
+ Manage your billing and add credits to your account.
+
+ {(() => {
+ const balanceStr = ((billingInfo()?.billing?.balance ?? 0) / 100000000).toFixed(2)
+ return `$${balanceStr === "-0.00" ? "0.00" : balanceStr}`
+ })()}
+
+
+
+ Payments History
+ Your recent payment transactions.
+ No payments found.}>
+ {(payment) => (
+
+ {payment.id}
+ {" | "}
+ ${((payment.amount ?? 0) / 100000000).toFixed(2)}
+ {" | "}
+ {new Date(payment.timeCreated).toLocaleDateString()}
+
+ )}
+
+
+ Usage History
+ Your recent API usage and costs.
+ No usage found.}>
+ {(usage) => (
+
+ {usage.model}
+ {" | "}
+ {usage.inputTokens + usage.outputTokens} tokens
+ {" | "}
+ ${((usage.cost ?? 0) / 100000000).toFixed(4)}
+ {" | "}
+ {new Date(usage.timeCreated).toLocaleDateString()}
+
+ )}
+
+
+ )
+}
--
cgit v1.2.3