mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-03 06:24:30 +00:00
feat(provider): refresh models from the public Pi catalog
This commit is contained in:
@@ -6,8 +6,8 @@
|
||||
"main": "./src/index.ts",
|
||||
"types": "./src/index.ts",
|
||||
"dependencies": {
|
||||
"@earendil-works/pi-ai": "1.5.0",
|
||||
"@earendil-works/pi-durable": "1.5.0",
|
||||
"@earendil-works/pi-ai": "1.7.0",
|
||||
"@earendil-works/pi-durable": "1.7.0",
|
||||
"zod": "4.5.4"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,10 @@ export const KNOWN_APIS = [
|
||||
'google-vertex',
|
||||
] as const
|
||||
|
||||
const jsonObjectSchema = z
|
||||
.record(z.string(), z.unknown())
|
||||
.refine((value) => z.json().safeParse(value).success)
|
||||
|
||||
// We define a serializable version of ProviderConfig for our API and DB
|
||||
// as the original ProviderConfig interface includes non-serializable fields (functions)
|
||||
export const providerModelConfigSchema = z.object({
|
||||
@@ -21,6 +25,9 @@ export const providerModelConfigSchema = z.object({
|
||||
input: z.array(z.enum(['text', 'image'])).default(['text']),
|
||||
contextWindow: z.number().int().positive().default(128000),
|
||||
maxTokens: z.number().int().positive().default(4096),
|
||||
compat: jsonObjectSchema.optional(),
|
||||
thinkingLevelMap: jsonObjectSchema.optional(),
|
||||
headers: z.record(z.string(), z.string()).optional(),
|
||||
cost: z.object({
|
||||
input: z.number().nonnegative().default(0),
|
||||
output: z.number().nonnegative().default(0),
|
||||
@@ -78,60 +85,58 @@ export const updateModelRequestSchema = z.object({
|
||||
|
||||
export type UpdateModelRequest = z.infer<typeof updateModelRequestSchema>
|
||||
|
||||
export const providerRefreshUnavailableReasonSchema = z.enum([
|
||||
'unsupported_connection',
|
||||
'legacy_kimi_connection',
|
||||
'azure_deployment_required',
|
||||
'catalog_unavailable',
|
||||
])
|
||||
|
||||
export type ProviderRefreshUnavailableReason = z.infer<
|
||||
typeof providerRefreshUnavailableReasonSchema
|
||||
>
|
||||
|
||||
export const providerResponseSchema = z.object({
|
||||
id: z.string(),
|
||||
teamId: z.string(),
|
||||
name: z.string(),
|
||||
isBuiltin: z.boolean(),
|
||||
config: providerConfigSchema,
|
||||
models: z.array(providerModelSchema).optional(),
|
||||
modelsCount: z.number().optional(),
|
||||
configured: z.boolean(),
|
||||
refreshUnavailableReason: providerRefreshUnavailableReasonSchema.nullable(),
|
||||
createdAt: z.date(),
|
||||
updatedAt: z.date(),
|
||||
})
|
||||
|
||||
export type ProviderResponse = z.infer<typeof providerResponseSchema>
|
||||
|
||||
export const syncModelItemSchema = z.object({
|
||||
modelId: z.string().min(1),
|
||||
name: z.string().default(''),
|
||||
config: providerModelConfigSchema,
|
||||
export const refreshedProviderModelSchema = createModelRequestSchema.pick({
|
||||
modelId: true,
|
||||
name: true,
|
||||
config: true,
|
||||
})
|
||||
|
||||
export type SyncModelItem = z.infer<typeof syncModelItemSchema>
|
||||
export type RefreshedProviderModel = z.infer<typeof refreshedProviderModelSchema>
|
||||
|
||||
export const syncProviderItemSchema = z.object({
|
||||
name: z.string(),
|
||||
isNewProvider: z.boolean(),
|
||||
config: providerConfigSchema,
|
||||
models: z.array(syncModelItemSchema),
|
||||
export const providerModelRefreshResponseSchema = z.discriminatedUnion('status', [
|
||||
z.object({
|
||||
status: z.literal('ready'),
|
||||
providerUpdatedAt: z.iso.datetime(),
|
||||
models: z.array(refreshedProviderModelSchema),
|
||||
}),
|
||||
z.object({
|
||||
status: z.literal('unavailable'),
|
||||
reason: providerRefreshUnavailableReasonSchema,
|
||||
}),
|
||||
])
|
||||
|
||||
export type ProviderModelRefreshResponse = z.infer<typeof providerModelRefreshResponseSchema>
|
||||
|
||||
export const importProviderModelsRequestSchema = z.object({
|
||||
providerUpdatedAt: z.iso.datetime(),
|
||||
modelIds: z.array(z.string().min(1)).min(1),
|
||||
})
|
||||
|
||||
export type SyncProviderItem = z.infer<typeof syncProviderItemSchema>
|
||||
|
||||
export const syncCheckResponseSchema = z.object({
|
||||
providers: z.array(syncProviderItemSchema),
|
||||
totalNewProviders: z.number(),
|
||||
totalNewModels: z.number(),
|
||||
})
|
||||
|
||||
export type SyncCheckResponse = z.infer<typeof syncCheckResponseSchema>
|
||||
|
||||
export const syncApplyRequestSchema = z.object({
|
||||
providers: z.array(
|
||||
z.object({
|
||||
name: z.string(),
|
||||
isNewProvider: z.boolean(),
|
||||
config: providerConfigSchema,
|
||||
models: z.array(syncModelItemSchema),
|
||||
}),
|
||||
),
|
||||
})
|
||||
|
||||
export type SyncApplyRequest = z.infer<typeof syncApplyRequestSchema>
|
||||
|
||||
export const syncApplyResponseSchema = z.object({
|
||||
addedProviders: z.number(),
|
||||
addedModels: z.number(),
|
||||
})
|
||||
|
||||
export type SyncApplyResponse = z.infer<typeof syncApplyResponseSchema>
|
||||
export type ImportProviderModelsRequest = z.infer<typeof importProviderModelsRequestSchema>
|
||||
|
||||
Reference in New Issue
Block a user