| 273 | } |
| 274 | |
| 275 | function getFilePath( |
| 276 | modelsDir: string, |
| 277 | modelId: string |
| 278 | ): { filePath: string; dirPath: string } { |
| 279 | if (modelId.includes("/")) { |
| 280 | // e.g., "deepseek/deepseek-r1-0528" -> models/deepseek/deepseek-r1-0528.toml |
| 281 | const parts = modelId.split("/"); |
| 282 | const fileName = `${parts[parts.length - 1]}.toml`; |
| 283 | const subDir = parts.slice(0, -1).join("/"); |
| 284 | const dirPath = path.join(modelsDir, subDir); |
| 285 | const filePath = path.join(dirPath, fileName); |
| 286 | return { filePath, dirPath }; |
| 287 | } else { |
| 288 | // e.g., "claude-opus-4-6" -> models/claude-opus-4-6.toml |
| 289 | return { |
| 290 | filePath: path.join(modelsDir, `${modelId}.toml`), |
| 291 | dirPath: modelsDir, |
| 292 | }; |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | async function ensureDir(dirPath: string): Promise<void> { |
| 297 | try { |