refactor(schema): flatten provider identity

This commit is contained in:
Shoubhit Dash 2026-06-25 19:49:14 +05:30
commit 1a9bd8c1fd
16 changed files with 262 additions and 436 deletions

View file

@ -1,6 +1,8 @@
import { Types } from "effect"
import { Schema } from "effect"
import { Model } from "@opencode-ai/schema/model"
import { ProviderV2 } from "./provider"
import { withStatics } from "./schema"
import type { DeepMutable } from "./schema"
export const ID = Model.ID
export type ID = typeof ID.Type
@ -8,10 +10,6 @@ export type ID = typeof ID.Type
export const VariantID = Model.VariantID
export type VariantID = typeof VariantID.Type
export const Package = Model.Package
export type Package = Model.Package
// Grouping of models, eg claude opus, claude sonnet
export const Family = Model.Family
export type Family = Model.Family
@ -23,15 +21,62 @@ export const Cost = Model.Cost
export const Ref = Model.Ref
export type Ref = typeof Ref.Type
export const Api = Model.Api
export type Api = Model.Api
// Temporary runtime schema until core catalog consumers migrate to the flat
// package identity in @opencode-ai/schema.
export const Api = Schema.Union([
Schema.Struct({ id: ID, ...ProviderV2.AISDK.fields }),
Schema.Struct({ id: ID, ...ProviderV2.Native.fields }),
]).pipe(Schema.toTaggedUnion("type"))
export type Api = typeof Api.Type
export const Info = Model.Info
export type Info = Model.Info
export interface Info extends Schema.Schema.Type<typeof Info> {}
export const Info = Schema.Struct({
id: ID,
providerID: ProviderV2.ID,
family: Family.pipe(Schema.optional),
name: Schema.String,
api: Api,
capabilities: Capabilities,
request: Schema.Struct({
...ProviderV2.Request.fields,
variant: Schema.String.pipe(Schema.optional),
}),
variants: Schema.Struct({
id: VariantID,
...ProviderV2.Request.fields,
}).pipe(Schema.Array, Schema.mutable),
time: Schema.Struct({ released: Schema.Finite }),
cost: Cost.pipe(Schema.Array, Schema.mutable),
status: Schema.Literals(["alpha", "beta", "deprecated", "active"]),
enabled: Schema.Boolean,
limit: Schema.Struct({
context: Schema.Int,
input: Schema.Int.pipe(Schema.optional),
output: Schema.Int,
}),
})
.annotate({ identifier: "ModelV2.Info" })
.pipe(
withStatics((schema) => ({
empty: (providerID: ProviderV2.ID, modelID: ID) =>
schema.make({
id: modelID,
providerID,
name: modelID,
api: { id: modelID, type: "native", settings: {} },
capabilities: { tools: false, input: [], output: [] },
request: { headers: {}, body: {} },
variants: [],
time: { released: 0 },
cost: [],
status: "active",
enabled: true,
limit: { context: 0, output: 0 },
}),
})),
)
export type MutableInfo = Omit<Types.DeepMutable<Info>, "api"> & {
api: ProviderV2.MutableApi<Api>
}
export type MutableInfo = Omit<DeepMutable<Info>, "api"> & { api: ProviderV2.MutableApi<Api> }
export function parse(input: string): { providerID: ProviderV2.ID; modelID: ID } {
const [providerID, ...modelID] = input.split("/")