{"record":{"id":"50745bb12c214605","repo":"linshenkx/prompt-optimizer","slug":"unable-to-build-model-configform-value-modelid","errorCode":null,"errorMessage":"Unable to build model ${configForm.value.modelId}: ${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":436,"sourceCode":"        const parts: string[] = []\n        if (detail.missing.length) parts.push(t('image.connection.validation.missing', { fields: detail.missing.join(', ') }))\n        if (detail.typeErrors.length) {\n          parts.push(detail.typeErrors.map(e => t('image.connection.validation.invalidType', e)).join('; '))\n        }\n        connectionStatus.value = { type: 'error', messageKey: 'image.connection.testFailed', detail: parts.join('; ') }\n        toast.error(parts.join('; '))\n        return\n      }\n\n      // 获取选中的模型信息：优先使用缓存，不存在时通过registry构建\n      let selectedModel = models.value.find(m => m.id === configForm.value.modelId)\n      if (!selectedModel) {\n        // 对于自定义模型ID，使用adapter的buildDefaultModel方法构建\n        try {\n          const adapter = registry.getAdapter(selectedProviderId.value)\n          selectedModel = adapter.buildDefaultModel(configForm.value.modelId)\n        } catch (error) {\n          throw new Error(\n            `Unable to build model ${configForm.value.modelId}: ${error instanceof Error ? error.message : String(error)}`,\n            { cause: error }\n          )\n        }\n      }\n\n      // 根据模型能力确定测试类型\n      const testType = selectTestType(selectedModel)\n\n      // 构建完整的模型配置\n      const completeConfig: ImageModelConfig = {\n        id: configForm.value.id || 'test',\n        name: configForm.value.name || 'Test Config',\n        providerId: selectedProviderId.value,\n        modelId: configForm.value.modelId,\n        enabled: true,\n        connectionConfig: configForm.value.connectionConfig || {},\n        paramOverrides: configForm.value.paramOverrides || {},","sourceCodeStart":418,"sourceCodeEnd":454,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/ui/src/composables/model/useImageModelManager.ts#L418-L454","documentation":"While testing a connection, useImageModelManager needs a model instance. When the model ID isn't in the registry cache it falls back to adapter.buildDefaultModel(modelId); if that builder throws (unknown model ID, malformed ID, adapter limits), the error is rethrown wrapped with context about which model failed.","triggerScenarios":"Entering a custom model ID in the image provider config and clicking 'Test Connection' when the provider's adapter cannot construct a default model for that ID — e.g. ID doesn't match any known model pattern or the adapter requires extra parameters.","commonSituations":"Typos in custom model IDs; using a model name from a newer API version than the adapter supports; provider-specific naming conventions (dashes vs dots) not honored.","solutions":["Check the model ID against the provider's model list and correct typos before testing.","Update the adapter (or the package) to a version that recognizes the model ID.","If the model should be buildable, inspect the cause in the wrapped error's { cause } to see the underlying builder failure."],"exampleFix":"// before\nadapter.buildDefaultModel('flux--pro') // throws\n\n// after\nadapter.buildDefaultModel('flux-pro') // verify ID against provider docs/model list","handlingStrategy":"try-catch","validationCode":"const ids = adapter.listModels?.() ?? []\nif (!ids.includes(configForm.value.modelId)) { /* warn before test */ }","typeGuard":null,"tryCatchPattern":"try { await testConnection() } catch (e) { if (e instanceof Error && e.message.startsWith('Unable to build model')) { console.error(e.cause); showModelIdError(e.message); return } throw e }","preventionTips":["Validate custom model IDs against the provider's model list","Keep adapters updated when adopting new models","Inspect error.cause for the underlying builder failure"],"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"}