GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — opencode/packages/opencode/script/schema.ts at dev · githubhjs/opencode Expand file tree/ Copy pathschema.tsMore file actions executable file ·77 lines (62 loc) · 2.67 KB / Copy pathschema.tsFile metadata and controlsexecutable file ·77 lines (62 loc) · 2.67 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 #!/usr/bin/env bun import { Config } from "@/config/config" import { ConfigV1 } from "@opencode-ai/core/v1/config/config" import { TuiConfig } from "@opencode-ai/tui/config" import { Schema } from "effect" type JsonSchema = Record<string, unknown> const MODEL_REF = "https://models.dev/model-schema.json#/$defs/Model" function generateEffect(schema: Schema.Top) { const document = Schema.toJsonSchemaDocument(schema) const normalized = normalize({ $schema: "https://json-schema.org/draft/2020-12/schema", ...document.schema, $defs: document.definitions, }) if (!isRecord(normalized)) throw new Error("schema generator produced a non-object schema") const restored = restoreModelRefs(normalized) if (!isRecord(restored)) throw new Error("schema generator produced a non-object schema") restored.allowComments = true restored.allowTrailingCommas = true return restored } function normalize(value: unknown): unknown { if (Array.isArray(value)) return value.map(normalize) if (!isRecord(value)) return value const schema = Object.fromEntries(Object.entries(value).map(([key, item]) => [key, normalize(item)])) if (Array.isArray(schema.anyOf)) { const anyOf = schema.anyOf.filter((item) => !isRecord(item) || item.type !== "null") if (anyOf.length !== schema.anyOf.length) { const { anyOf: _, ...rest } = schema if (anyOf.length === 1 && isRecord(anyOf[0])) return normalize({ ...anyOf[0], ...rest }) return { ...rest, anyOf } } } if (Array.isArray(schema.allOf) && schema.allOf.length === 1 && isRecord(schema.allOf[0])) { const { allOf: _, ...rest } = schema return normalize({ ...schema.allOf[0], ...rest }) } if (schema.type === "integer" && schema.maximum === undefined) { return { ...schema, maximum: Number.MAX_SAFE_INTEGER } } return schema } function restoreModelRefs(value: unknown, key?: string): unknown { if (Array.isArray(value)) return value.map((item) => restoreModelRefs(item)) if (!isRecord(value)) return value const schema = Object.fromEntries(Object.entries(value).map(([name, item]) => [name, restoreModelRefs(item, name)])) if ((key === "model" || key === "small_model") && schema.type === "string") { return { ...schema, $ref: MODEL_REF } } return schema } function isRecord(value: unknown): value is JsonSchema { return typeof value === "object" && value !== null && !Array.isArray(value) } const configFile = process.argv[2] const tuiFile = process.argv[3] console.log(configFile) await Bun.write(configFile, JSON.stringify(generateEffect(ConfigV1.Info), null, 2)) if (tuiFile) { console.log(tuiFile) await Bun.write(tuiFile, JSON.stringify(generateEffect(TuiConfig.Info), null, 2)) } |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |