mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-26 07:09:23 +00:00
* feat(provider): vendor and adapt pi model generator - Vendor generate-models.ts, model-data.ts, and models-dev-reasoning-options.ts from @earendil-works/pi tag v0.82.1 - Adapt imports to use @earendil-works/pi-ai and expose generateModels programmatic function - Add compare.test.ts to verify vendored generator against original built-in catalog - Add packages/core/src/provider/generator to eslint ignores * feat(provider): add provider and model sync api and ui * feat(webui): add checkbox for existing providers and clean dialog description * feat(webui): add expand all and collapse all to sync providers dialog * refactor(provider): remove compare.test.ts and cli overhead from generate-models * fix(provider): add 30s timeout and strict error handling to sync catalog fetching * fix(e2e): eliminate drag-and-drop race condition on webkit Allow requestAnimationFrame collision updates to settle in dragCard helper before releasing pointer, and scope fileCard locator via data-testid to avoid matching sidebar tree items.
138 lines
4.2 KiB
TypeScript
138 lines
4.2 KiB
TypeScript
import { z } from 'zod'
|
|
export { z }
|
|
|
|
export const KNOWN_APIS = [
|
|
'openai-completions',
|
|
'mistral-conversations',
|
|
'openai-responses',
|
|
'azure-openai-responses',
|
|
'openai-codex-responses',
|
|
'anthropic-messages',
|
|
'bedrock-converse-stream',
|
|
'google-generative-ai',
|
|
'google-vertex',
|
|
] as const
|
|
|
|
// 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({
|
|
api: z.enum(KNOWN_APIS).optional(),
|
|
reasoning: z.boolean().default(false),
|
|
input: z.array(z.enum(['text', 'image'])).default(['text']),
|
|
contextWindow: z.number().int().positive().default(128000),
|
|
maxTokens: z.number().int().positive().default(4096),
|
|
cost: z.object({
|
|
input: z.number().nonnegative().default(0),
|
|
output: z.number().nonnegative().default(0),
|
|
cacheRead: z.number().nonnegative().default(0),
|
|
cacheWrite: z.number().nonnegative().default(0),
|
|
}),
|
|
})
|
|
|
|
export const providerModelSchema = z.object({
|
|
id: z.string().optional(),
|
|
modelId: z.string().min(1, 'Model ID is required'),
|
|
name: z.string().min(0).default(''),
|
|
config: providerModelConfigSchema,
|
|
})
|
|
|
|
export const providerConfigSchema = z.object({
|
|
baseUrl: z.string().url('Must be a valid URL').optional().or(z.literal('')),
|
|
apiKey: z.string().optional().or(z.literal('')),
|
|
api: z.enum(KNOWN_APIS),
|
|
headers: z.record(z.string(), z.string()).optional(),
|
|
authHeader: z.boolean().optional(),
|
|
})
|
|
|
|
export type ProviderConfigSerializable = z.infer<typeof providerConfigSchema>
|
|
|
|
export const createProviderRequestSchema = z.object({
|
|
name: z.string().min(1, 'Provider name is required'),
|
|
config: providerConfigSchema,
|
|
models: z.array(providerModelSchema).default([]),
|
|
})
|
|
|
|
export type CreateProviderRequest = z.infer<typeof createProviderRequestSchema>
|
|
|
|
export const updateProviderRequestSchema = z.object({
|
|
name: z.string().min(1, 'Provider name is required').optional(),
|
|
config: providerConfigSchema,
|
|
models: z.array(providerModelSchema).optional(),
|
|
})
|
|
|
|
export type UpdateProviderRequest = z.infer<typeof updateProviderRequestSchema>
|
|
|
|
export const createModelRequestSchema = z.object({
|
|
modelId: z.string().min(1, 'Model ID is required'),
|
|
name: z.string().min(0).default(''),
|
|
config: providerModelConfigSchema,
|
|
})
|
|
|
|
export type CreateModelRequest = z.infer<typeof createModelRequestSchema>
|
|
|
|
export const updateModelRequestSchema = z.object({
|
|
modelId: z.string().min(1, 'Model ID is required').optional(),
|
|
name: z.string().min(0).optional(),
|
|
config: providerModelConfigSchema.optional(),
|
|
})
|
|
|
|
export type UpdateModelRequest = z.infer<typeof updateModelRequestSchema>
|
|
|
|
export const providerResponseSchema = z.object({
|
|
id: z.string(),
|
|
name: z.string(),
|
|
isBuiltin: z.boolean(),
|
|
config: providerConfigSchema,
|
|
models: z.array(providerModelSchema).optional(),
|
|
modelsCount: z.number().optional(),
|
|
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 type SyncModelItem = z.infer<typeof syncModelItemSchema>
|
|
|
|
export const syncProviderItemSchema = z.object({
|
|
name: z.string(),
|
|
isNewProvider: z.boolean(),
|
|
config: providerConfigSchema,
|
|
models: z.array(syncModelItemSchema),
|
|
})
|
|
|
|
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>
|