mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-31 16:33:34 +08:00
refactor: rewrite provider types — simplified model mapping, preset-based structure
This commit is contained in:
parent
08cd15ed1b
commit
9806bef5ec
@ -1,46 +1,48 @@
|
|||||||
/**
|
/**
|
||||||
* Provider 类型定义
|
* Provider types — preset-based provider configuration.
|
||||||
*
|
*
|
||||||
* Provider 是自定义 API 供应商的配置单元,包含 Base URL、API Key 和可用模型列表。
|
* Providers are stored in ~/.claude/cc-haha/providers.json as a lightweight index.
|
||||||
* 激活 Provider 时,其配置会写入 ~/.claude/settings.json 的 env 字段。
|
* The active provider's env vars are written to ~/.claude/settings.json.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { z } from 'zod'
|
import { z } from 'zod'
|
||||||
|
|
||||||
// ─── Zod Schemas ──────────────────────────────────────────────────────────────
|
export const ModelMappingSchema = z.object({
|
||||||
|
main: z.string(),
|
||||||
export const ProviderModelSchema = z.object({
|
haiku: z.string(),
|
||||||
id: z.string().min(1),
|
sonnet: z.string(),
|
||||||
name: z.string().min(1),
|
opus: z.string(),
|
||||||
description: z.string().optional(),
|
|
||||||
context: z.string().optional(),
|
|
||||||
})
|
})
|
||||||
|
|
||||||
export const ProviderSchema = z.object({
|
export const SavedProviderSchema = z.object({
|
||||||
id: z.string().uuid(),
|
id: z.string(),
|
||||||
|
presetId: z.string(),
|
||||||
name: z.string().min(1),
|
name: z.string().min(1),
|
||||||
baseUrl: z.string().url(),
|
apiKey: z.string(),
|
||||||
apiKey: z.string().min(1),
|
baseUrl: z.string(),
|
||||||
models: z.array(ProviderModelSchema).min(1),
|
models: ModelMappingSchema,
|
||||||
isActive: z.boolean(),
|
|
||||||
createdAt: z.number(),
|
|
||||||
updatedAt: z.number(),
|
|
||||||
notes: z.string().optional(),
|
notes: z.string().optional(),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const ProvidersIndexSchema = z.object({
|
||||||
|
activeId: z.string().nullable(),
|
||||||
|
providers: z.array(SavedProviderSchema),
|
||||||
|
})
|
||||||
|
|
||||||
export const CreateProviderSchema = z.object({
|
export const CreateProviderSchema = z.object({
|
||||||
|
presetId: z.string().min(1),
|
||||||
name: z.string().min(1),
|
name: z.string().min(1),
|
||||||
baseUrl: z.string().url(),
|
apiKey: z.string(),
|
||||||
apiKey: z.string().min(1),
|
baseUrl: z.string(),
|
||||||
models: z.array(ProviderModelSchema).min(1),
|
models: ModelMappingSchema,
|
||||||
notes: z.string().optional(),
|
notes: z.string().optional(),
|
||||||
})
|
})
|
||||||
|
|
||||||
export const UpdateProviderSchema = z.object({
|
export const UpdateProviderSchema = z.object({
|
||||||
name: z.string().min(1).optional(),
|
name: z.string().min(1).optional(),
|
||||||
baseUrl: z.string().url().optional(),
|
apiKey: z.string().optional(),
|
||||||
apiKey: z.string().min(1).optional(),
|
baseUrl: z.string().optional(),
|
||||||
models: z.array(ProviderModelSchema).min(1).optional(),
|
models: ModelMappingSchema.optional(),
|
||||||
notes: z.string().optional(),
|
notes: z.string().optional(),
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -50,25 +52,13 @@ export const TestProviderSchema = z.object({
|
|||||||
modelId: z.string().min(1),
|
modelId: z.string().min(1),
|
||||||
})
|
})
|
||||||
|
|
||||||
export const ActivateProviderSchema = z.object({
|
// TypeScript types
|
||||||
modelId: z.string().min(1),
|
export type ModelMapping = z.infer<typeof ModelMappingSchema>
|
||||||
})
|
export type SavedProvider = z.infer<typeof SavedProviderSchema>
|
||||||
|
export type ProvidersIndex = z.infer<typeof ProvidersIndexSchema>
|
||||||
export const ProvidersConfigSchema = z.object({
|
|
||||||
providers: z.array(ProviderSchema),
|
|
||||||
activeModel: z.string().optional(),
|
|
||||||
version: z.number(),
|
|
||||||
})
|
|
||||||
|
|
||||||
// ─── TypeScript Types ─────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
export type ProviderModel = z.infer<typeof ProviderModelSchema>
|
|
||||||
export type Provider = z.infer<typeof ProviderSchema>
|
|
||||||
export type CreateProviderInput = z.infer<typeof CreateProviderSchema>
|
export type CreateProviderInput = z.infer<typeof CreateProviderSchema>
|
||||||
export type UpdateProviderInput = z.infer<typeof UpdateProviderSchema>
|
export type UpdateProviderInput = z.infer<typeof UpdateProviderSchema>
|
||||||
export type TestProviderInput = z.infer<typeof TestProviderSchema>
|
export type TestProviderInput = z.infer<typeof TestProviderSchema>
|
||||||
export type ActivateProviderInput = z.infer<typeof ActivateProviderSchema>
|
|
||||||
export type ProvidersConfig = z.infer<typeof ProvidersConfigSchema>
|
|
||||||
|
|
||||||
export interface ProviderTestResult {
|
export interface ProviderTestResult {
|
||||||
success: boolean
|
success: boolean
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user