( data: Omit<LLMConfig, 'id' | 'createdAt' | 'order' | 'parentFolderId'>, afterItemId?: string, inFolderId?: string )
| 40 | // ==================== LLM 配置 ==================== |
| 41 | |
| 42 | export function createLLMConfig( |
| 43 | data: Omit<LLMConfig, 'id' | 'createdAt' | 'order' | 'parentFolderId'>, |
| 44 | afterItemId?: string, |
| 45 | inFolderId?: string |
| 46 | ): LLMConfig { |
| 47 | const { settings } = stores |
| 48 | let parentFolderId: string | undefined |
| 49 | let order: number |
| 50 | |
| 51 | if (inFolderId) { |
| 52 | parentFolderId = inFolderId |
| 53 | const itemsInFolder = [ |
| 54 | ...settings.settings.llmConfigs.items.filter((i) => i.parentFolderId === inFolderId), |
| 55 | ...settings.settings.llmConfigs.folders.filter((f) => f.parentFolderId === inFolderId) |
| 56 | ] |
| 57 | order = itemsInFolder.length > 0 ? Math.max(...itemsInFolder.map((i) => i.order ?? 0)) + 1 : 0 |
| 58 | } else { |
| 59 | const position = prepareInsertPosition(settings.settings.llmConfigs, afterItemId) |
| 60 | parentFolderId = position.parentFolderId |
| 61 | order = position.order |
| 62 | } |
| 63 | |
| 64 | const config: LLMConfig = { |
| 65 | ...data, |
| 66 | id: uuidv4(), |
| 67 | parentFolderId, |
| 68 | order, |
| 69 | createdAt: Date.now() |
| 70 | } |
| 71 | |
| 72 | settings.addLLMConfig(config) |
| 73 | return config |
| 74 | } |
| 75 | |
| 76 | export function updateLLMConfig(id: string, updates: Partial<LLMConfig>): void { |
| 77 | stores.settings.updateLLMConfig(id, updates) |
no test coverage detected