11import { Global } from "../global"
22import { Log } from "../util"
33import path from "path"
4- import z from "zod "
4+ import { Schema } from "effect "
55import { Installation } from "../installation"
66import { Flag } from "../flag/flag"
77import { lazy } from "@/util/lazy"
@@ -21,91 +21,85 @@ const filepath = path.join(
2121)
2222const ttl = 5 * 60 * 1000
2323
24- type JsonValue = string | number | boolean | null | { [ key : string ] : JsonValue } | JsonValue [ ]
25-
26- const JsonValue : z . ZodType < JsonValue > = z . lazy ( ( ) =>
27- z . union ( [ z . string ( ) , z . number ( ) , z . boolean ( ) , z . null ( ) , z . array ( JsonValue ) , z . record ( z . string ( ) , JsonValue ) ] ) ,
28- )
29-
30- const Cost = z . object ( {
31- input : z . number ( ) ,
32- output : z . number ( ) ,
33- cache_read : z . number ( ) . optional ( ) ,
34- cache_write : z . number ( ) . optional ( ) ,
35- context_over_200k : z
36- . object ( {
37- input : z . number ( ) ,
38- output : z . number ( ) ,
39- cache_read : z . number ( ) . optional ( ) ,
40- cache_write : z . number ( ) . optional ( ) ,
41- } )
42- . optional ( ) ,
24+ const Cost = Schema . Struct ( {
25+ input : Schema . Number ,
26+ output : Schema . Number ,
27+ cache_read : Schema . optional ( Schema . Number ) ,
28+ cache_write : Schema . optional ( Schema . Number ) ,
29+ context_over_200k : Schema . optional (
30+ Schema . Struct ( {
31+ input : Schema . Number ,
32+ output : Schema . Number ,
33+ cache_read : Schema . optional ( Schema . Number ) ,
34+ cache_write : Schema . optional ( Schema . Number ) ,
35+ } ) ,
36+ ) ,
4337} )
4438
45- export const Model = z . object ( {
46- id : z . string ( ) ,
47- name : z . string ( ) ,
48- family : z . string ( ) . optional ( ) ,
49- release_date : z . string ( ) ,
50- attachment : z . boolean ( ) ,
51- reasoning : z . boolean ( ) ,
52- temperature : z . boolean ( ) ,
53- tool_call : z . boolean ( ) ,
54- interleaved : z
55- . union ( [
56- z . literal ( true ) ,
57- z
58- . object ( {
59- field : z . enum ( [ "reasoning_content" , "reasoning_details" ] ) ,
60- } )
61- . strict ( ) ,
62- ] )
63- . optional ( ) ,
64- cost : Cost . optional ( ) ,
65- limit : z . object ( {
66- context : z . number ( ) ,
67- input : z . number ( ) . optional ( ) ,
68- output : z . number ( ) ,
39+ export const Model = Schema . Struct ( {
40+ id : Schema . String ,
41+ name : Schema . String ,
42+ family : Schema . optional ( Schema . String ) ,
43+ release_date : Schema . String ,
44+ attachment : Schema . Boolean ,
45+ reasoning : Schema . Boolean ,
46+ temperature : Schema . Boolean ,
47+ tool_call : Schema . Boolean ,
48+ interleaved : Schema . optional (
49+ Schema . Union ( [
50+ Schema . Literal ( true ) ,
51+ Schema . Struct ( {
52+ field : Schema . Literals ( [ "reasoning_content" , "reasoning_details" ] ) ,
53+ } ) ,
54+ ] ) ,
55+ ) ,
56+ cost : Schema . optional ( Cost ) ,
57+ limit : Schema . Struct ( {
58+ context : Schema . Number ,
59+ input : Schema . optional ( Schema . Number ) ,
60+ output : Schema . Number ,
6961 } ) ,
70- modalities : z
71- . object ( {
72- input : z . array ( z . enum ( [ "text" , "audio" , "image" , "video" , "pdf" ] ) ) ,
73- output : z . array ( z . enum ( [ "text" , "audio" , "image" , "video" , "pdf" ] ) ) ,
74- } )
75- . optional ( ) ,
76- experimental : z
77- . object ( {
78- modes : z
79- . record (
80- z . string ( ) ,
81- z . object ( {
82- cost : Cost . optional ( ) ,
83- provider : z
84- . object ( {
85- body : z . record ( z . string ( ) , JsonValue ) . optional ( ) ,
86- headers : z . record ( z . string ( ) , z . string ( ) ) . optional ( ) ,
87- } )
88- . optional ( ) ,
62+ modalities : Schema . optional (
63+ Schema . Struct ( {
64+ input : Schema . Array ( Schema . Literals ( [ "text" , "audio" , "image" , "video" , "pdf" ] ) ) ,
65+ output : Schema . Array ( Schema . Literals ( [ "text" , "audio" , "image" , "video" , "pdf" ] ) ) ,
66+ } ) ,
67+ ) ,
68+ experimental : Schema . optional (
69+ Schema . Struct ( {
70+ modes : Schema . optional (
71+ Schema . Record (
72+ Schema . String ,
73+ Schema . Struct ( {
74+ cost : Schema . optional ( Cost ) ,
75+ provider : Schema . optional (
76+ Schema . Struct ( {
77+ body : Schema . optional ( Schema . Record ( Schema . String , Schema . MutableJson ) ) ,
78+ headers : Schema . optional ( Schema . Record ( Schema . String , Schema . String ) ) ,
79+ } ) ,
80+ ) ,
8981 } ) ,
90- )
91- . optional ( ) ,
92- } )
93- . optional ( ) ,
94- status : z . enum ( [ "alpha" , "beta" , "deprecated" ] ) . optional ( ) ,
95- provider : z . object ( { npm : z . string ( ) . optional ( ) , api : z . string ( ) . optional ( ) } ) . optional ( ) ,
82+ ) ,
83+ ) ,
84+ } ) ,
85+ ) ,
86+ status : Schema . optional ( Schema . Literals ( [ "alpha" , "beta" , "deprecated" ] ) ) ,
87+ provider : Schema . optional (
88+ Schema . Struct ( { npm : Schema . optional ( Schema . String ) , api : Schema . optional ( Schema . String ) } ) ,
89+ ) ,
9690} )
97- export type Model = z . infer < typeof Model >
98-
99- export const Provider = z . object ( {
100- api : z . string ( ) . optional ( ) ,
101- name : z . string ( ) ,
102- env : z . array ( z . string ( ) ) ,
103- id : z . string ( ) ,
104- npm : z . string ( ) . optional ( ) ,
105- models : z . record ( z . string ( ) , Model ) ,
91+ export type Model = Schema . Schema . Type < typeof Model >
92+
93+ export const Provider = Schema . Struct ( {
94+ api : Schema . optional ( Schema . String ) ,
95+ name : Schema . String ,
96+ env : Schema . Array ( Schema . String ) ,
97+ id : Schema . String ,
98+ npm : Schema . optional ( Schema . String ) ,
99+ models : Schema . Record ( Schema . String , Model ) ,
106100} )
107101
108- export type Provider = z . infer < typeof Provider >
102+ export type Provider = Schema . Schema . Type < typeof Provider >
109103
110104function url ( ) {
111105 return Flag . OPENCODE_MODELS_URL || "https://models.dev"
0 commit comments