wip: cloud

This commit is contained in:
Frank
2025-08-29 19:45:17 -04:00
parent c3a25eff78
commit 46927ee9a5

View File

@@ -1,10 +1,12 @@
import { Billing } from "@opencode/cloud-core/billing.js" import { Billing } from "@opencode/cloud-core/billing.js"
import { Key } from "@opencode/cloud-core/key.js" import { Key } from "@opencode/cloud-core/key.js"
import { action, createAsync, revalidate, query, useAction, useSubmission } from "@solidjs/router" import { action, createAsync, revalidate, query, useAction, useSubmission, json } from "@solidjs/router"
import { createEffect, createSignal, For, onMount, Show } from "solid-js" import { createEffect, createSignal, For, onMount, Show } from "solid-js"
import { getActor } from "~/context/auth" import { getActor } from "~/context/auth"
import { withActor } from "~/context/auth.withActor" import { withActor } from "~/context/auth.withActor"
import "./index.css" import "./index.css"
import { User } from "@opencode/cloud-core/user.js"
import { Actor } from "@opencode/cloud-core/actor.js"
///////////////////////////////////// /////////////////////////////////////
// Keys related queries and actions // Keys related queries and actions
@@ -17,12 +19,18 @@ const listKeys = query(async () => {
const createKey = action(async (name: string) => { const createKey = action(async (name: string) => {
"use server" "use server"
return withActor(() => Key.create({ name })) return json(
withActor(() => Key.create({ name })),
{ revalidate: "keys" },
)
}, "createKey") }, "createKey")
const removeKey = action(async (id: string) => { const removeKey = action(async (id: string) => {
"use server" "use server"
return withActor(() => Key.remove({ id })) return json(
withActor(() => Key.remove({ id })),
{ revalidate: "keys" },
)
}, "removeKey") }, "removeKey")
///////////////////////////////////// /////////////////////////////////////
@@ -32,10 +40,14 @@ const removeKey = action(async (id: string) => {
const getBillingInfo = query(async () => { const getBillingInfo = query(async () => {
"use server" "use server"
return withActor(async () => { return withActor(async () => {
const billing = await Billing.get() const actor = Actor.assert("user")
const payments = await Billing.payments() const [user, billing, payments, usage] = await Promise.all([
const usage = await Billing.usages() User.fromID(actor.properties.userID),
return { billing, payments, usage } Billing.get(),
Billing.payments(),
Billing.usages(),
])
return { user, billing, payments, usage }
}) })
}, "billingInfo") }, "billingInfo")
@@ -194,7 +206,6 @@ export default function() {
try { try {
await createKeyAction(keyName().trim()) await createKeyAction(keyName().trim())
revalidate("keys")
setKeyName("") setKeyName("")
setShowCreateForm(false) setShowCreateForm(false)
} catch (error) { } catch (error) {
@@ -209,7 +220,6 @@ export default function() {
try { try {
await removeKeyAction(keyId) await removeKeyAction(keyId)
revalidate("keys")
} catch (error) { } catch (error) {
console.error("Failed to delete API key:", error) console.error("Failed to delete API key:", error)
} }