fix(schema): adapt legacy catalog responses
This commit is contained in:
parent
5436b55a7e
commit
8efd8783d0
4 changed files with 51 additions and 3 deletions
|
|
@ -78,6 +78,34 @@ export const Info = Schema.Struct({
|
|||
|
||||
export type MutableInfo = Omit<DeepMutable<Info>, "api"> & { api: ProviderV2.MutableApi<Api> }
|
||||
|
||||
export function flatten(info: Info): Model.Info {
|
||||
return Model.Info.make({
|
||||
id: info.id,
|
||||
modelID: info.api.id === info.id ? undefined : info.api.id,
|
||||
providerID: info.providerID,
|
||||
family: info.family,
|
||||
name: info.name,
|
||||
package: info.api.type === "aisdk" ? `aisdk:${info.api.package}` : undefined,
|
||||
settings: {
|
||||
...info.api.settings,
|
||||
...(info.api.url === undefined ? {} : { baseURL: info.api.url }),
|
||||
},
|
||||
headers: info.request.headers,
|
||||
body: info.request.body,
|
||||
capabilities: info.capabilities,
|
||||
variants: info.variants.map((variant) => ({
|
||||
id: variant.id,
|
||||
headers: variant.headers,
|
||||
body: variant.body,
|
||||
})),
|
||||
time: info.time,
|
||||
cost: info.cost,
|
||||
status: info.status,
|
||||
enabled: info.enabled,
|
||||
limit: info.limit,
|
||||
})
|
||||
}
|
||||
|
||||
export function parse(input: string): { providerID: ProviderV2.ID; modelID: ID } {
|
||||
const [providerID, ...modelID] = input.split("/")
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -59,3 +59,19 @@ export type MutableApi<T extends Api = Api> = T extends Api
|
|||
: never
|
||||
|
||||
export type MutableInfo = Omit<DeepMutable<Info>, "api"> & { api: MutableApi }
|
||||
|
||||
export function flatten(info: Info): Provider.Info {
|
||||
return Provider.Info.make({
|
||||
id: info.id,
|
||||
integrationID: info.integrationID,
|
||||
name: info.name,
|
||||
disabled: info.disabled,
|
||||
package: info.api.type === "aisdk" ? `aisdk:${info.api.package}` : "",
|
||||
settings: {
|
||||
...info.api.settings,
|
||||
...(info.api.url === undefined ? {} : { baseURL: info.api.url }),
|
||||
},
|
||||
headers: info.request.headers,
|
||||
body: info.request.body,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue