{"record":{"id":"c85667a82cf43e93","repo":"linshenkx/prompt-optimizer","slug":"unable-to-build-model-selectedmodelid-value","errorCode":null,"errorMessage":"Unable to build model ${selectedModelId.value}: ${error instanceof Error ? error.message : String(error)}","messagePattern":"Unable to build model (.+?): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/ui/src/composables/model/useImageModelManager.ts","lineNumber":621,"sourceCode":"\n    isSaving.value = true\n\n    try {\n      const cachedProvider = providers.value.find(p => p.id === selectedProviderId.value)\n\n      if (!cachedProvider) {\n        throw new Error(`Provider not found: ${selectedProviderId.value}`)\n      }\n\n      // 获取模型信息：优先使用缓存，不存在时通过registry构建\n      let cachedModel = models.value.find(m => m.id === selectedModelId.value)\n      if (!cachedModel) {\n        // 对于自定义模型ID，使用adapter的buildDefaultModel方法构建\n        try {\n          const adapter = registry.getAdapter(selectedProviderId.value)\n          cachedModel = adapter.buildDefaultModel(selectedModelId.value)\n        } catch (error) {\n          throw new Error(\n            `Unable to build model ${selectedModelId.value}: ${error instanceof Error ? error.message : String(error)}`,\n            { cause: error }\n          )\n        }\n      }\n\n      // Manager owns authoritative provider/model metadata resolution.\n      const completeConfig: ImageModelConfigInput = {\n        ...configForm.value,\n        providerId: selectedProviderId.value,\n        modelId: selectedModelId.value\n      }\n\n      if (configForm.value.id) {\n        await imageModelManager.updateConfig(configForm.value.id, completeConfig)\n        toast.success(t('image.config.updateSuccess'))\n      } else {\n        const newConfig = { ...completeConfig, id: generateConfigId() }","sourceCodeStart":603,"sourceCodeEnd":639,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/ui/src/composables/model/useImageModelManager.ts#L603-L639","documentation":"During saveConfig, if the selected model ID isn't in the cached models list, useImageModelManager builds it via the provider adapter's buildDefaultModel. A builder failure (unknown/invalid model ID for that provider) is wrapped as 'Unable to build model <id>' with the original error attached as cause.","triggerScenarios":"Saving a config whose model ID is custom (not in models.value) and not constructible by the adapter — wrong model name, unsupported model on that provider, or an adapter that doesn't implement defaults for that ID.","commonSituations":"Custom model ID typos; provider renamed/deprecated the model; adapter version older than the model catalog.","solutions":["Verify the model ID against the provider's current model list and fix it.","Refresh the model list (so cachedModel exists) before saving.","Read error.cause to identify the exact builder rejection and update the adapter/package if the model is legitimately new."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (!models.value.some(m => m.id === selectedModelId.value)) { await loadModels() /* or verify ID with adapter */ }","typeGuard":null,"tryCatchPattern":"catch (e) { if (e instanceof Error && e.message.startsWith('Unable to build model')) { console.error(e.cause); alertInvalidModelId(selectedModelId.value); return } throw e }","preventionTips":["Refresh model list before save","Check custom IDs for typos against provider docs","Update adapter packages for new models"],"tags":["model-id","adapter","configuration"],"backgroundTag":"invalid-model-id","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}