summaryrefslogtreecommitdiffhomepage
path: root/packages
diff options
context:
space:
mode:
authorFrank <[email protected]>2025-10-08 01:14:39 -0400
committerFrank <[email protected]>2025-10-08 01:14:39 -0400
commitaf684c80d4b7768f60defe8da4cd2811e4350dc2 (patch)
tree0cf8e8734dc48b6940a690ef64ddf2c97a99a8b6 /packages
parent99b72eb1ea136ef6569751061d50b6f691718564 (diff)
downloadopencode-af684c80d4b7768f60defe8da4cd2811e4350dc2.tar.gz
opencode-af684c80d4b7768f60defe8da4cd2811e4350dc2.zip
wip: zen
Diffstat (limited to 'packages')
-rw-r--r--packages/console/app/src/routes/workspace/model-section.tsx1
-rw-r--r--packages/console/app/src/routes/zen/handler.ts55
2 files changed, 28 insertions, 28 deletions
diff --git a/packages/console/app/src/routes/workspace/model-section.tsx b/packages/console/app/src/routes/workspace/model-section.tsx
index 078cbfa88..4128b4a2c 100644
--- a/packages/console/app/src/routes/workspace/model-section.tsx
+++ b/packages/console/app/src/routes/workspace/model-section.tsx
@@ -24,7 +24,6 @@ const updateModel = action(async (form: FormData) => {
const workspaceID = form.get("workspaceID")?.toString()
if (!workspaceID) return { error: "Workspace ID is required" }
const enabled = form.get("enabled")?.toString() === "true"
- console.log({ model, workspaceID, enabled })
return json(
withActor(async () => {
if (enabled) {
diff --git a/packages/console/app/src/routes/zen/handler.ts b/packages/console/app/src/routes/zen/handler.ts
index feb0c9c3e..19f80609f 100644
--- a/packages/console/app/src/routes/zen/handler.ts
+++ b/packages/console/app/src/routes/zen/handler.ts
@@ -12,6 +12,7 @@ import { Actor } from "@opencode-ai/console-core/actor.js"
import { WorkspaceTable } from "@opencode-ai/console-core/schema/workspace.sql.js"
import { ZenModel } from "@opencode-ai/console-core/model.js"
import { UserTable } from "@opencode-ai/console-core/schema/user.sql.js"
+import { ModelTable } from "@opencode-ai/console-core/schema/model.sql.js"
export async function handler(
input: APIEvent,
@@ -67,6 +68,7 @@ export async function handler(
const providerInfo = selectProvider(modelInfo)
const authInfo = await authenticate(modelInfo)
validateBilling(modelInfo, authInfo)
+ validateModelSettings(authInfo)
logger.metric({ provider: providerInfo.id })
// Request to model provider
@@ -222,14 +224,14 @@ export async function handler(
return { id: modelId, ...modelData }
}
- function selectProvider(model: Model) {
+ function selectProvider(model: Awaited<ReturnType<typeof validateModel>>) {
const providers = model.providers
.filter((provider) => !provider.disabled)
.flatMap((provider) => Array<typeof provider>(provider.weight ?? 1).fill(provider))
return providers[Math.floor(Math.random() * providers.length)]
}
- async function authenticate(model: Model) {
+ async function authenticate(model: Awaited<ReturnType<typeof validateModel>>) {
const apiKey = opts.parseApiKey(input.request.headers)
if (!apiKey) {
if (model.allowAnonymous) return
@@ -241,20 +243,26 @@ export async function handler(
.select({
apiKey: KeyTable.id,
workspaceID: KeyTable.workspaceID,
- balance: BillingTable.balance,
- paymentMethodID: BillingTable.paymentMethodID,
- monthlyLimit: BillingTable.monthlyLimit,
- monthlyUsage: BillingTable.monthlyUsage,
- timeMonthlyUsageUpdated: BillingTable.timeMonthlyUsageUpdated,
- userID: UserTable.id,
- userMonthlyLimit: UserTable.monthlyLimit,
- userMonthlyUsage: UserTable.monthlyUsage,
- timeUserMonthlyUsageUpdated: UserTable.timeMonthlyUsageUpdated,
+ billing: {
+ balance: BillingTable.balance,
+ paymentMethodID: BillingTable.paymentMethodID,
+ monthlyLimit: BillingTable.monthlyLimit,
+ monthlyUsage: BillingTable.monthlyUsage,
+ timeMonthlyUsageUpdated: BillingTable.timeMonthlyUsageUpdated,
+ },
+ user: {
+ id: UserTable.id,
+ monthlyLimit: UserTable.monthlyLimit,
+ monthlyUsage: UserTable.monthlyUsage,
+ timeMonthlyUsageUpdated: UserTable.timeMonthlyUsageUpdated,
+ },
+ timeDisabled: ModelTable.timeCreated,
})
.from(KeyTable)
.innerJoin(WorkspaceTable, eq(WorkspaceTable.id, KeyTable.workspaceID))
.innerJoin(BillingTable, eq(BillingTable.workspaceID, KeyTable.workspaceID))
.innerJoin(UserTable, and(eq(UserTable.workspaceID, KeyTable.workspaceID), eq(UserTable.id, KeyTable.userID)))
+ .leftJoin(ModelTable, and(eq(ModelTable.workspaceID, KeyTable.workspaceID), eq(ModelTable.model, model.id)))
.where(and(eq(KeyTable.key, apiKey), isNull(KeyTable.timeDeleted)))
.then((rows) => rows[0]),
)
@@ -265,25 +273,13 @@ export async function handler(
workspace: data.workspaceID,
})
- const isFree = FREE_WORKSPACES.includes(data.workspaceID)
-
return {
apiKeyId: data.apiKey,
workspaceID: data.workspaceID,
- billing: {
- paymentMethodID: data.paymentMethodID,
- balance: data.balance,
- monthlyLimit: data.monthlyLimit,
- monthlyUsage: data.monthlyUsage,
- timeMonthlyUsageUpdated: data.timeMonthlyUsageUpdated,
- },
- user: {
- id: data.userID,
- monthlyLimit: data.userMonthlyLimit,
- monthlyUsage: data.userMonthlyUsage,
- timeMonthlyUsageUpdated: data.timeUserMonthlyUsageUpdated,
- },
- isFree,
+ billing: data.billing,
+ user: data.user,
+ isFree: FREE_WORKSPACES.includes(data.workspaceID),
+ isDisabled: !!data.timeDisabled,
}
}
@@ -325,6 +321,11 @@ export async function handler(
}
}
+ function validateModelSettings(authInfo: Awaited<ReturnType<typeof authenticate>>) {
+ if (!authInfo) return
+ if (authInfo.isDisabled) throw new ModelError("Model is disabled")
+ }
+
async function trackUsage(
authInfo: Awaited<ReturnType<typeof authenticate>>,
modelInfo: ReturnType<typeof validateModel>,