import { Global } from "../global" import path from "path" import z from "zod" import { data } from "./models-macro" with { type: "macro" } export namespace ModelsDev { const filepath = path.join(Global.Path.cache, "models.json") export const Model = z.object({ id: z.string(), name: z.string(), family: z.string().optional(), release_date: z.string(), attachment: z.boolean(), reasoning: z.boolean(), temperature: z.boolean(), tool_call: z.boolean(), interleaved: z .union([ z.literal(true), z .object({ field: z.enum(["reasoning_content", "reasoning_details"]), }) .strict(), ]) .optional(), cost: z .object({ input: z.number(), output: z.number(), cache_read: z.number().optional(), cache_write: z.number().optional(), context_over_200k: z .object({ input: z.number(), output: z.number(), cache_read: z.number().optional(), cache_write: z.number().optional(), }) .optional(), }) .optional(), limit: z.object({ context: z.number(), output: z.number(), }), modalities: z .object({ input: z.array(z.enum(["text", "audio", "image", "video", "pdf"])), output: z.array(z.enum(["text", "audio", "image", "video", "pdf"])), }) .optional(), experimental: z.boolean().optional(), status: z.enum(["alpha", "beta", "deprecated"]).optional(), options: z.record(z.string(), z.any()), headers: z.record(z.string(), z.string()).optional(), provider: z.object({ npm: z.string() }).optional(), variants: z.record(z.string(), z.record(z.string(), z.any())).optional(), }) export type Model = z.infer export const Provider = z.object({ api: z.string().optional(), name: z.string(), env: z.array(z.string()), id: z.string(), npm: z.string().optional(), models: z.record(z.string(), Model), }) export type Provider = z.infer export async function get() { refresh() const file = Bun.file(filepath) const result = await file.json().catch(() => {}) if (result) return result as Record const json = await data() return JSON.parse(json) as Record } export async function refresh() { // Disabled for Tinfoil-only fork - models are fetched from Tinfoil API } }