|
@@ -3,59 +3,29 @@ import { and, Database, eq, isNull } from "@opencode-ai/console-core/drizzle/ind
|
|
|
import { KeyTable } from "@opencode-ai/console-core/schema/key.sql.js"
|
|
import { KeyTable } from "@opencode-ai/console-core/schema/key.sql.js"
|
|
|
import { WorkspaceTable } from "@opencode-ai/console-core/schema/workspace.sql.js"
|
|
import { WorkspaceTable } from "@opencode-ai/console-core/schema/workspace.sql.js"
|
|
|
import { ModelTable } from "@opencode-ai/console-core/schema/model.sql.js"
|
|
import { ModelTable } from "@opencode-ai/console-core/schema/model.sql.js"
|
|
|
-import { ZenData } from "@opencode-ai/console-core/model.js"
|
|
|
|
|
|
|
+import { optionsHandler, getHandler } from "~/routes/zen/util/modelsHandler"
|
|
|
|
|
|
|
|
export async function OPTIONS(_input: APIEvent) {
|
|
export async function OPTIONS(_input: APIEvent) {
|
|
|
- return new Response(null, {
|
|
|
|
|
- status: 200,
|
|
|
|
|
- headers: {
|
|
|
|
|
- "Access-Control-Allow-Origin": "*",
|
|
|
|
|
- "Access-Control-Allow-Methods": "GET, POST, OPTIONS",
|
|
|
|
|
- "Access-Control-Allow-Headers": "Content-Type, Authorization",
|
|
|
|
|
- },
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ return optionsHandler()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export async function GET(input: APIEvent) {
|
|
export async function GET(input: APIEvent) {
|
|
|
- const zenData = ZenData.list("full")
|
|
|
|
|
- const disabledModels = await authenticate()
|
|
|
|
|
-
|
|
|
|
|
- return new Response(
|
|
|
|
|
- JSON.stringify({
|
|
|
|
|
- object: "list",
|
|
|
|
|
- data: Object.entries(zenData.models)
|
|
|
|
|
- .filter(([id]) => !disabledModels.includes(id))
|
|
|
|
|
- .filter(([id]) => !id.startsWith("alpha-"))
|
|
|
|
|
- .map(([id, _model]) => ({
|
|
|
|
|
- id,
|
|
|
|
|
- object: "model",
|
|
|
|
|
- created: Math.floor(Date.now() / 1000),
|
|
|
|
|
- owned_by: "opencode",
|
|
|
|
|
- })),
|
|
|
|
|
- }),
|
|
|
|
|
- {
|
|
|
|
|
- headers: {
|
|
|
|
|
- "Content-Type": "application/json",
|
|
|
|
|
- },
|
|
|
|
|
- },
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- async function authenticate() {
|
|
|
|
|
|
|
+ const disabledModels = await (() => {
|
|
|
const apiKey = input.request.headers.get("authorization")?.split(" ")[1]
|
|
const apiKey = input.request.headers.get("authorization")?.split(" ")[1]
|
|
|
if (!apiKey) return []
|
|
if (!apiKey) return []
|
|
|
|
|
|
|
|
- const disabledModels = await Database.use((tx) =>
|
|
|
|
|
|
|
+ return Database.use((tx) =>
|
|
|
tx
|
|
tx
|
|
|
.select({
|
|
.select({
|
|
|
model: ModelTable.model,
|
|
model: ModelTable.model,
|
|
|
})
|
|
})
|
|
|
.from(KeyTable)
|
|
.from(KeyTable)
|
|
|
.innerJoin(WorkspaceTable, eq(WorkspaceTable.id, KeyTable.workspaceID))
|
|
.innerJoin(WorkspaceTable, eq(WorkspaceTable.id, KeyTable.workspaceID))
|
|
|
- .leftJoin(ModelTable, and(eq(ModelTable.workspaceID, KeyTable.workspaceID), isNull(ModelTable.timeDeleted)))
|
|
|
|
|
|
|
+ .innerJoin(ModelTable, and(eq(ModelTable.workspaceID, KeyTable.workspaceID), isNull(ModelTable.timeDeleted)))
|
|
|
.where(and(eq(KeyTable.key, apiKey), isNull(KeyTable.timeDeleted)))
|
|
.where(and(eq(KeyTable.key, apiKey), isNull(KeyTable.timeDeleted)))
|
|
|
.then((rows) => rows.map((row) => row.model)),
|
|
.then((rows) => rows.map((row) => row.model)),
|
|
|
)
|
|
)
|
|
|
|
|
+ })()
|
|
|
|
|
|
|
|
- return disabledModels
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ return getHandler({ modelList: "full", disabledModels })
|
|
|
}
|
|
}
|