mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-13 23:52:06 +00:00
go: models endpoint
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
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) {
|
||||
return optionsHandler()
|
||||
return buildOptionsResponse()
|
||||
}
|
||||
|
||||
export async function GET(input: APIEvent) {
|
||||
return getHandler({ modelList: "lite" })
|
||||
export async function GET(_input: APIEvent) {
|
||||
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 optionsHandler() {
|
||||
export async function buildOptionsResponse() {
|
||||
return new Response(null, {
|
||||
status: 200,
|
||||
headers: {
|
||||
@@ -11,16 +9,13 @@ export async function optionsHandler() {
|
||||
})
|
||||
}
|
||||
|
||||
export async function getHandler(opts: { modelList: "lite" | "full"; disabledModels?: string[] }) {
|
||||
const zenData = ZenData.list(opts.modelList)
|
||||
|
||||
export async function buildModelsResponse(models: string[]) {
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
object: "list",
|
||||
data: Object.entries(zenData.models)
|
||||
.filter(([id]) => !opts.disabledModels?.includes(id))
|
||||
.filter(([id]) => !id.startsWith("alpha-"))
|
||||
.map(([id, _model]) => ({
|
||||
data: models
|
||||
.filter((id) => !id.startsWith("alpha-"))
|
||||
.map((id) => ({
|
||||
id,
|
||||
object: "model",
|
||||
created: Math.floor(Date.now() / 1000),
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
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 { KeyTable } from "@opencode-ai/console-core/schema/key.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 { optionsHandler, getHandler } from "~/routes/zen/util/modelsHandler"
|
||||
import { buildOptionsResponse, buildModelsResponse } from "~/routes/zen/util/modelsHandler"
|
||||
|
||||
export async function OPTIONS(_input: APIEvent) {
|
||||
return optionsHandler()
|
||||
return buildOptionsResponse()
|
||||
}
|
||||
|
||||
export async function GET(input: APIEvent) {
|
||||
const disabledModels = await (() => {
|
||||
const apiKey = input.request.headers.get("authorization")?.split(" ")[1]
|
||||
if (!apiKey) return []
|
||||
if (!apiKey) return [] as string[]
|
||||
|
||||
return Database.use((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