fix(core): load documented provider packages
This commit is contained in:
parent
f019bb3abf
commit
4b66e5484d
3 changed files with 109 additions and 0 deletions
|
|
@ -53,6 +53,9 @@ export const Plugin = define({
|
|||
catalog.provider.update(providerID, (provider) => {
|
||||
if (item.name !== undefined) provider.name = item.name
|
||||
if (item.api !== undefined) provider.api = { ...item.api }
|
||||
if (item.package !== undefined || item.settings !== undefined) {
|
||||
provider.api = configuredApi(provider.api, item.package, item.settings)
|
||||
}
|
||||
if (item.request !== undefined) {
|
||||
Object.assign(provider.request.headers, item.request.headers)
|
||||
Object.assign(provider.request.body, item.request.body)
|
||||
|
|
@ -63,6 +66,16 @@ export const Plugin = define({
|
|||
if (config.family !== undefined) model.family = config.family
|
||||
if (config.name !== undefined) model.name = config.name
|
||||
if (config.api !== undefined) model.api = { ...model.api, ...config.api }
|
||||
if (config.package !== undefined || config.settings !== undefined) {
|
||||
model.api = {
|
||||
...configuredApi(
|
||||
config.api === undefined ? catalog.provider.get(providerID)!.provider.api : model.api,
|
||||
config.package,
|
||||
config.settings,
|
||||
),
|
||||
id: model.api.id,
|
||||
}
|
||||
}
|
||||
if (config.capabilities !== undefined) {
|
||||
model.capabilities = {
|
||||
tools: config.capabilities.tools,
|
||||
|
|
@ -111,3 +124,25 @@ export const Plugin = define({
|
|||
)
|
||||
}),
|
||||
})
|
||||
|
||||
function configuredApi(api: ProviderV2.MutableApi, packageName?: string, settings?: Record<string, unknown>) {
|
||||
const merged = { ...api.settings, ...settings }
|
||||
const baseURL = typeof merged.baseURL === "string" ? merged.baseURL : api.url
|
||||
if (packageName?.startsWith("aisdk:")) {
|
||||
return {
|
||||
type: "aisdk" as const,
|
||||
package: packageName.slice("aisdk:".length),
|
||||
...(baseURL === undefined ? {} : { url: baseURL }),
|
||||
settings: merged,
|
||||
}
|
||||
}
|
||||
if (packageName !== undefined) {
|
||||
return {
|
||||
type: "native" as const,
|
||||
package: packageName,
|
||||
...(baseURL === undefined ? {} : { url: baseURL }),
|
||||
settings: merged,
|
||||
}
|
||||
}
|
||||
return { ...api, ...(baseURL === undefined ? {} : { url: baseURL }), settings: merged }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,6 +47,8 @@ const ModelApi = Schema.Union([
|
|||
class Model extends Schema.Class<Model>("ConfigV2.Model")({
|
||||
family: ModelV2.Family.pipe(Schema.optional),
|
||||
name: Schema.String.pipe(Schema.optional),
|
||||
package: Schema.String.pipe(Schema.optional),
|
||||
settings: Schema.Record(Schema.String, Schema.Unknown).pipe(Schema.optional),
|
||||
api: ModelApi.pipe(Schema.optional),
|
||||
capabilities: ModelV2.Capabilities.pipe(Schema.optional),
|
||||
request: Schema.Struct({
|
||||
|
|
@ -65,6 +67,8 @@ class Model extends Schema.Class<Model>("ConfigV2.Model")({
|
|||
export class Info extends Schema.Class<Info>("ConfigV2.Provider")({
|
||||
name: Schema.String.pipe(Schema.optional),
|
||||
env: Schema.String.pipe(Schema.Array, Schema.optional),
|
||||
package: Schema.String.pipe(Schema.optional),
|
||||
settings: Schema.Record(Schema.String, Schema.Unknown).pipe(Schema.optional),
|
||||
api: ProviderV2.Api.pipe(Schema.optional),
|
||||
request: Request.pipe(Schema.optional),
|
||||
models: Schema.Record(Schema.String, Model).pipe(Schema.optional),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue