wip: cloud
This commit is contained in:
@@ -5,5 +5,18 @@ export default defineConfig({
|
||||
server: {
|
||||
allowedHosts: true,
|
||||
},
|
||||
build: {
|
||||
rollupOptions: {
|
||||
external: ["cloudflare:workers"],
|
||||
},
|
||||
minify: false,
|
||||
},
|
||||
},
|
||||
server: {
|
||||
compatibilityDate: "2024-09-19",
|
||||
preset: "cloudflare_module",
|
||||
cloudflare: {
|
||||
nodeCompat: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
1
cloud/app/src/global.d.ts
vendored
1
cloud/app/src/global.d.ts
vendored
@@ -1 +1,2 @@
|
||||
/// <reference types="@solidjs/start/env" />
|
||||
declare module "cloudflare:workers"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { redirect } from "@solidjs/router"
|
||||
import type { APIEvent } from "@solidjs/start/server"
|
||||
import { AuthClient, useAuthSession } from "~/context/auth"
|
||||
import { AuthClient } from "~/context/auth"
|
||||
import { useAuthSession } from "~/context/auth.session"
|
||||
|
||||
export async function GET(input: APIEvent) {
|
||||
const url = new URL(input.request.url)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Resource } from "sst"
|
||||
import { Resource } from "@opencode/cloud-core/util/resource.js"
|
||||
import { Billing } from "@opencode/cloud-core/billing.js"
|
||||
import type { APIEvent } from "@solidjs/start/server"
|
||||
import { Database, eq, sql } from "@opencode/cloud-core/drizzle/index.js"
|
||||
|
||||
@@ -31,8 +31,6 @@ const isLoggedIn = query(async () => {
|
||||
return false
|
||||
}, "isLoggedIn")
|
||||
|
||||
|
||||
|
||||
export default function Home() {
|
||||
createAsync(() => isLoggedIn(), {
|
||||
deferStream: true,
|
||||
@@ -83,7 +81,9 @@ export default function Home() {
|
||||
</button>
|
||||
</div>
|
||||
<div data-slot="right">
|
||||
<a href="/auth/authorize" target="_self">Login</a>
|
||||
<a href="/auth/authorize" target="_self">
|
||||
Login
|
||||
</a>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { Resource } from "sst"
|
||||
import { Billing } from "@opencode/cloud-core/billing.js"
|
||||
import type { APIEvent } from "@solidjs/start/server"
|
||||
import { Database, eq, sql } from "@opencode/cloud-core/drizzle/index.js"
|
||||
@@ -6,6 +5,7 @@ import { BillingTable, PaymentTable } from "@opencode/cloud-core/schema/billing.
|
||||
import { Identifier } from "@opencode/cloud-core/identifier.js"
|
||||
import { centsToMicroCents } from "@opencode/cloud-core/util/price.js"
|
||||
import { Actor } from "@opencode/cloud-core/actor.js"
|
||||
import { Resource } from "@opencode/cloud-core/util/resource.js"
|
||||
|
||||
export async function POST(input: APIEvent) {
|
||||
const body = await Billing.stripe().webhooks.constructEventAsync(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { defineConfig } from "drizzle-kit"
|
||||
import { Resource } from "sst"
|
||||
import { Resource } from "./src/util/resource"
|
||||
|
||||
export default defineConfig({
|
||||
out: "./migrations/",
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { Resource } from "sst"
|
||||
import { Stripe } from "stripe"
|
||||
import { Database, eq, sql } from "./drizzle"
|
||||
import { BillingTable, PaymentTable, UsageTable } from "./schema/billing.sql"
|
||||
@@ -8,6 +7,7 @@ import { z } from "zod"
|
||||
import { Identifier } from "./identifier"
|
||||
import { centsToMicroCents } from "./util/price"
|
||||
import { User } from "./user"
|
||||
import { Resource } from "./util/resource"
|
||||
|
||||
export namespace Billing {
|
||||
export const stripe = () =>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { drizzle } from "drizzle-orm/postgres-js"
|
||||
import { Resource } from "sst"
|
||||
import { Resource } from "../util/resource"
|
||||
export * from "drizzle-orm"
|
||||
import postgres from "postgres"
|
||||
|
||||
|
||||
14
cloud/core/src/util/resource.ts
Normal file
14
cloud/core/src/util/resource.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { env } from "cloudflare:workers";
|
||||
|
||||
export const Resource = new Proxy(
|
||||
{},
|
||||
{
|
||||
get(_target, prop: string) {
|
||||
if (prop in env) {
|
||||
const value = env[prop];
|
||||
return typeof value === "string" ? JSON.parse(value) : value;
|
||||
}
|
||||
throw new Error(`"${prop}" is not linked in your sst.config.ts`);
|
||||
},
|
||||
}
|
||||
) as Record<string, any>;
|
||||
@@ -1,4 +1,3 @@
|
||||
import { Resource } from "sst"
|
||||
import { z } from "zod"
|
||||
import { issuer } from "@openauthjs/openauth"
|
||||
import type { Theme } from "@openauthjs/openauth/ui/theme"
|
||||
@@ -10,6 +9,7 @@ import { CloudflareStorage } from "@openauthjs/openauth/storage/cloudflare"
|
||||
import { Account } from "@opencode/cloud-core/account.js"
|
||||
import { Workspace } from "@opencode/cloud-core/workspace.js"
|
||||
import { Actor } from "@opencode/cloud-core/actor.js"
|
||||
import { Resource } from "@opencode/cloud-core/util/resource.js"
|
||||
|
||||
type Env = {
|
||||
AuthStorage: KVNamespace
|
||||
@@ -28,8 +28,8 @@ export const subjects = createSubjects({
|
||||
|
||||
const MY_THEME: Theme = {
|
||||
...THEME_OPENAUTH,
|
||||
logo: "https://opencode.ai/favicon.svg"
|
||||
};
|
||||
logo: "https://opencode.ai/favicon.svg",
|
||||
}
|
||||
|
||||
export default {
|
||||
async fetch(request: Request, env: Env, ctx: ExecutionContext) {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { Hono, MiddlewareHandler } from "hono"
|
||||
import { cors } from "hono/cors"
|
||||
import { HTTPException } from "hono/http-exception"
|
||||
import { zValidator } from "@hono/zod-validator"
|
||||
import { Resource } from "sst"
|
||||
import { Resource } from "@opencode/cloud-core/util/resource.js"
|
||||
import { type ProviderMetadata, type LanguageModelUsage, generateText, streamText } from "ai"
|
||||
import { createAnthropic } from "@ai-sdk/anthropic"
|
||||
import { createOpenAI } from "@ai-sdk/openai"
|
||||
|
||||
4
cloud/function/sst-env.d.ts
vendored
4
cloud/function/sst-env.d.ts
vendored
@@ -14,6 +14,10 @@ declare module "sst" {
|
||||
"type": "sst.sst.Linkable"
|
||||
"value": string
|
||||
}
|
||||
"Console": {
|
||||
"type": "sst.cloudflare.SolidStart"
|
||||
"url": string
|
||||
}
|
||||
"DATABASE_PASSWORD": {
|
||||
"type": "sst.sst.Secret"
|
||||
"value": string
|
||||
|
||||
Reference in New Issue
Block a user