mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-23 18:54:21 +01:00
wip: zen
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
import { $ } from "bun"
|
||||
import path from "path"
|
||||
import { ZenModel } from "../src/model"
|
||||
import { ZenData } from "../src/model"
|
||||
|
||||
const stage = process.argv[2]
|
||||
if (!stage) throw new Error("Stage is required")
|
||||
@@ -18,7 +18,7 @@ const value = ret
|
||||
if (!value) throw new Error("ZEN_MODELS not found")
|
||||
|
||||
// validate value
|
||||
ZenModel.ModelsSchema.parse(JSON.parse(value))
|
||||
ZenData.validate(JSON.parse(value))
|
||||
|
||||
// update the secret
|
||||
await $`bun sst secret set ZEN_MODELS ${value} --stage ${stage}`
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import { $ } from "bun"
|
||||
import path from "path"
|
||||
import os from "os"
|
||||
import { ZenModel } from "../src/model"
|
||||
import { ZenData } from "../src/model"
|
||||
|
||||
const root = path.resolve(process.cwd(), "..", "..", "..")
|
||||
const models = await $`bun sst secret list`.cwd(root).text()
|
||||
@@ -26,7 +26,7 @@ console.log("tempFile", tempFile.name)
|
||||
// open temp file in vim and read the file on close
|
||||
await $`vim ${tempFile.name}`
|
||||
const newValue = JSON.parse(await tempFile.text())
|
||||
ZenModel.ModelsSchema.parse(newValue)
|
||||
ZenData.validate(newValue)
|
||||
|
||||
// update the secret
|
||||
await $`bun sst secret set ZEN_MODELS ${JSON.stringify(newValue)}`
|
||||
|
||||
@@ -7,7 +7,7 @@ import { fn } from "./util/fn"
|
||||
import { Actor } from "./actor"
|
||||
import { Resource } from "@opencode-ai/console-resource"
|
||||
|
||||
export namespace ZenModel {
|
||||
export namespace ZenData {
|
||||
const ModelCostSchema = z.object({
|
||||
input: z.number(),
|
||||
output: z.number(),
|
||||
@@ -16,7 +16,7 @@ export namespace ZenModel {
|
||||
cacheWrite1h: z.number().optional(),
|
||||
})
|
||||
|
||||
export const ModelSchema = z.object({
|
||||
const ModelSchema = z.object({
|
||||
name: z.string(),
|
||||
cost: ModelCostSchema,
|
||||
cost200K: ModelCostSchema.optional(),
|
||||
@@ -24,19 +24,32 @@ export namespace ZenModel {
|
||||
providers: z.array(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
api: z.string(),
|
||||
apiKey: z.string(),
|
||||
model: z.string(),
|
||||
weight: z.number().optional(),
|
||||
headerMappings: z.record(z.string(), z.string()).optional(),
|
||||
disabled: z.boolean().optional(),
|
||||
}),
|
||||
),
|
||||
})
|
||||
|
||||
export const ModelsSchema = z.record(z.string(), ModelSchema)
|
||||
const ProviderSchema = z.object({
|
||||
api: z.string(),
|
||||
apiKey: z.string(),
|
||||
headerMappings: z.record(z.string(), z.string()).optional(),
|
||||
})
|
||||
|
||||
export const list = fn(z.void(), () => ModelsSchema.parse(JSON.parse(Resource.ZEN_MODELS.value)))
|
||||
const ModelsSchema = z.object({
|
||||
models: z.record(z.string(), ModelSchema),
|
||||
providers: z.record(z.string(), ProviderSchema),
|
||||
})
|
||||
|
||||
export const validate = fn(ModelsSchema, (input) => {
|
||||
return input
|
||||
})
|
||||
|
||||
export const list = fn(z.void(), () => {
|
||||
const json = JSON.parse(Resource.ZEN_MODELS.value)
|
||||
return ModelsSchema.parse(json)
|
||||
})
|
||||
}
|
||||
|
||||
export namespace Model {
|
||||
|
||||
Reference in New Issue
Block a user