diff options
| author | Frank <[email protected]> | 2025-08-29 19:34:56 -0400 |
|---|---|---|
| committer | Frank <[email protected]> | 2025-08-29 19:34:58 -0400 |
| commit | c3a25eff78635725472096fe2626021ee50f36b0 (patch) | |
| tree | adecb00a9340d2baea27b3f30f254054810d9490 /cloud | |
| parent | b40c02e2583c6e35f97849e98f66609e67dac322 (diff) | |
| download | opencode-c3a25eff78635725472096fe2626021ee50f36b0.tar.gz opencode-c3a25eff78635725472096fe2626021ee50f36b0.zip | |
wip: cloud
Diffstat (limited to 'cloud')
| -rw-r--r-- | cloud/app/app.config.ts | 13 | ||||
| -rw-r--r-- | cloud/app/src/global.d.ts | 1 | ||||
| -rw-r--r-- | cloud/app/src/routes/auth/callback.ts | 3 | ||||
| -rw-r--r-- | cloud/app/src/routes/gateway/v1/chat/completions.ts | 2 | ||||
| -rw-r--r-- | cloud/app/src/routes/index.tsx | 6 | ||||
| -rw-r--r-- | cloud/app/src/routes/stripe/webhook.ts | 2 | ||||
| -rw-r--r-- | cloud/core/drizzle.config.ts | 2 | ||||
| -rw-r--r-- | cloud/core/src/billing.ts | 2 | ||||
| -rw-r--r-- | cloud/core/src/drizzle/index.ts | 2 | ||||
| -rw-r--r-- | cloud/core/src/util/resource.ts | 14 | ||||
| -rw-r--r-- | cloud/function/src/auth.ts | 6 | ||||
| -rw-r--r-- | cloud/function/src/gateway.ts | 2 | ||||
| -rw-r--r-- | cloud/function/sst-env.d.ts | 4 |
13 files changed, 46 insertions, 13 deletions
diff --git a/cloud/app/app.config.ts b/cloud/app/app.config.ts index 0ffa557f9..4dd799edc 100644 --- a/cloud/app/app.config.ts +++ b/cloud/app/app.config.ts @@ -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, + }, }, }) diff --git a/cloud/app/src/global.d.ts b/cloud/app/src/global.d.ts index dc6f10c22..a44606d2e 100644 --- a/cloud/app/src/global.d.ts +++ b/cloud/app/src/global.d.ts @@ -1 +1,2 @@ /// <reference types="@solidjs/start/env" /> +declare module "cloudflare:workers" diff --git a/cloud/app/src/routes/auth/callback.ts b/cloud/app/src/routes/auth/callback.ts index edeb35790..4e38df07e 100644 --- a/cloud/app/src/routes/auth/callback.ts +++ b/cloud/app/src/routes/auth/callback.ts @@ -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) diff --git a/cloud/app/src/routes/gateway/v1/chat/completions.ts b/cloud/app/src/routes/gateway/v1/chat/completions.ts index f69feade1..95c2c268d 100644 --- a/cloud/app/src/routes/gateway/v1/chat/completions.ts +++ b/cloud/app/src/routes/gateway/v1/chat/completions.ts @@ -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" diff --git a/cloud/app/src/routes/index.tsx b/cloud/app/src/routes/index.tsx index b9344bc55..5a4e07978 100644 --- a/cloud/app/src/routes/index.tsx +++ b/cloud/app/src/routes/index.tsx @@ -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> diff --git a/cloud/app/src/routes/stripe/webhook.ts b/cloud/app/src/routes/stripe/webhook.ts index 258ebe413..29f0f2484 100644 --- a/cloud/app/src/routes/stripe/webhook.ts +++ b/cloud/app/src/routes/stripe/webhook.ts @@ -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( diff --git a/cloud/core/drizzle.config.ts b/cloud/core/drizzle.config.ts index c65363cb8..82c487834 100644 --- a/cloud/core/drizzle.config.ts +++ b/cloud/core/drizzle.config.ts @@ -1,5 +1,5 @@ import { defineConfig } from "drizzle-kit" -import { Resource } from "sst" +import { Resource } from "./src/util/resource" export default defineConfig({ out: "./migrations/", diff --git a/cloud/core/src/billing.ts b/cloud/core/src/billing.ts index 94ba23b83..705999c26 100644 --- a/cloud/core/src/billing.ts +++ b/cloud/core/src/billing.ts @@ -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 = () => diff --git a/cloud/core/src/drizzle/index.ts b/cloud/core/src/drizzle/index.ts index f35ce0a34..894f578f8 100644 --- a/cloud/core/src/drizzle/index.ts +++ b/cloud/core/src/drizzle/index.ts @@ -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" diff --git a/cloud/core/src/util/resource.ts b/cloud/core/src/util/resource.ts new file mode 100644 index 000000000..1543145dc --- /dev/null +++ b/cloud/core/src/util/resource.ts @@ -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>; diff --git a/cloud/function/src/auth.ts b/cloud/function/src/auth.ts index 5d7c852cb..79d7805de 100644 --- a/cloud/function/src/auth.ts +++ b/cloud/function/src/auth.ts @@ -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) { diff --git a/cloud/function/src/gateway.ts b/cloud/function/src/gateway.ts index 2f498276f..c8b39990f 100644 --- a/cloud/function/src/gateway.ts +++ b/cloud/function/src/gateway.ts @@ -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" diff --git a/cloud/function/sst-env.d.ts b/cloud/function/sst-env.d.ts index f60ec81a0..9c4f5cc0d 100644 --- a/cloud/function/sst-env.d.ts +++ b/cloud/function/sst-env.d.ts @@ -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 |
