go: models endpoint
This commit is contained in:
@@ -1,10 +1,12 @@
|
|||||||
import type { APIEvent } from "@solidjs/start/server"
|
import type { APIEvent } from "@solidjs/start/server"
|
||||||
import { getHandler, optionsHandler } from "../../util/modelsHandler"
|
import { ZenData } from "@opencode-ai/console-core/model.js"
|
||||||
|
import { buildModelsResponse, buildOptionsResponse } from "../../util/modelsHandler"
|
||||||
|
|
||||||
export async function OPTIONS(_input: APIEvent) {
|
export async function OPTIONS(_input: APIEvent) {
|
||||||
return optionsHandler()
|
return buildOptionsResponse()
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function GET(input: APIEvent) {
|
export async function GET(_input: APIEvent) {
|
||||||
return getHandler({ modelList: "lite" })
|
const models = Object.keys(ZenData.list("lite").models)
|
||||||
|
return buildModelsResponse(models)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
import { ZenData } from "@opencode-ai/console-core/model.js"
|
export async function buildOptionsResponse() {
|
||||||
|
|
||||||
export async function optionsHandler() {
|
|
||||||
return new Response(null, {
|
return new Response(null, {
|
||||||
status: 200,
|
status: 200,
|
||||||
headers: {
|
headers: {
|
||||||
@@ -11,16 +9,13 @@ export async function optionsHandler() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getHandler(opts: { modelList: "lite" | "full"; disabledModels?: string[] }) {
|
export async function buildModelsResponse(models: string[]) {
|
||||||
const zenData = ZenData.list(opts.modelList)
|
|
||||||
|
|
||||||
return new Response(
|
return new Response(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
object: "list",
|
object: "list",
|
||||||
data: Object.entries(zenData.models)
|
data: models
|
||||||
.filter(([id]) => !opts.disabledModels?.includes(id))
|
.filter((id) => !id.startsWith("alpha-"))
|
||||||
.filter(([id]) => !id.startsWith("alpha-"))
|
.map((id) => ({
|
||||||
.map(([id, _model]) => ({
|
|
||||||
id,
|
id,
|
||||||
object: "model",
|
object: "model",
|
||||||
created: Math.floor(Date.now() / 1000),
|
created: Math.floor(Date.now() / 1000),
|
||||||
|
|||||||
@@ -1,18 +1,19 @@
|
|||||||
import type { APIEvent } from "@solidjs/start/server"
|
import type { APIEvent } from "@solidjs/start/server"
|
||||||
|
import { ZenData } from "@opencode-ai/console-core/model.js"
|
||||||
import { and, Database, eq, isNull } from "@opencode-ai/console-core/drizzle/index.js"
|
import { and, Database, eq, isNull } from "@opencode-ai/console-core/drizzle/index.js"
|
||||||
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 { optionsHandler, getHandler } from "~/routes/zen/util/modelsHandler"
|
import { buildOptionsResponse, buildModelsResponse } from "~/routes/zen/util/modelsHandler"
|
||||||
|
|
||||||
export async function OPTIONS(_input: APIEvent) {
|
export async function OPTIONS(_input: APIEvent) {
|
||||||
return optionsHandler()
|
return buildOptionsResponse()
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function GET(input: APIEvent) {
|
export async function GET(input: APIEvent) {
|
||||||
const disabledModels = await (() => {
|
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 [] as string[]
|
||||||
|
|
||||||
return Database.use((tx) =>
|
return Database.use((tx) =>
|
||||||
tx
|
tx
|
||||||
@@ -27,5 +28,7 @@ export async function GET(input: APIEvent) {
|
|||||||
)
|
)
|
||||||
})()
|
})()
|
||||||
|
|
||||||
return getHandler({ modelList: "full", disabledModels })
|
const models = Object.keys(ZenData.list("full").models).filter((id) => !disabledModels.includes(id))
|
||||||
|
|
||||||
|
return buildModelsResponse(models)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user