{"record":{"id":"d740ef11ca2f42d2","repo":"siyuan-note/siyuan","slug":"ai-configuration-is-unavailable","errorCode":null,"errorMessage":"AI configuration is unavailable","messagePattern":"AI configuration is unavailable","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/assets.go","lineNumber":415,"sourceCode":"\t}\n\tprepared, err := util.PrepareModelImage(\n\t\tdata, documentImageMaxBytes, documentImageMaxPixels, documentImageMaxEdge,\n\t)\n\tif err != nil {\n\t\treturn PreparedDocumentImage{}, err\n\t}\n\treturn PreparedDocumentImage{\n\t\tArtifact: ImageArtifactRef{Kind: \"image\", Path: assetPath, DocumentID: bt.RootID},\n\t\tData:     prepared.Data,\n\t\tMIMEType: prepared.MIMEType,\n\t\tPrepared: prepared,\n\t}, nil\n}\n\n// GenerateImage 使用全局图片生成配置创建图片字节，可供文档资源、编辑器和其他图片入口复用。\nfunc GenerateImage(ctx context.Context, request GenerateImageRequest) (GenerateImageResult, error) {\n\tif Conf == nil || Conf.AI == nil {\n\t\treturn GenerateImageResult{}, errors.New(\"AI configuration is unavailable\")\n\t}\n\tprovider, generationModel := Conf.AI.GetImageGenerationModel()\n\tif err := validateImageModel(provider, generationModel); err != nil {\n\t\treturn GenerateImageResult{}, err\n\t}\n\tprompt := strings.TrimSpace(request.Prompt)\n\tif prompt == \"\" {\n\t\treturn GenerateImageResult{}, errors.New(\"prompt is required for image generation\")\n\t}\n\tsize := multimodalValueOrDefault(request.Size, Conf.AI.ImageGeneration.Size)\n\tquality := multimodalValueOrDefault(request.Quality, Conf.AI.ImageGeneration.Quality)\n\toutputFormat := strings.ToLower(multimodalValueOrDefault(request.OutputFormat, Conf.AI.ImageGeneration.OutputFormat))\n\tif outputFormat != \"png\" && outputFormat != \"jpeg\" && outputFormat != \"webp\" {\n\t\treturn GenerateImageResult{}, errors.New(\"unsupported image output format\")\n\t}\n\tgenerated, err := util.NewOpenAIImageAdapter(\n\t\tprovider.APIKey, provider.BaseURL, generationModel.Name, Conf.AI.ImageGeneration.RequestTimeout,\n\t).Generate(ctx, util.GenerateImageRequest{","sourceCodeStart":397,"sourceCodeEnd":433,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/model/assets.go#L397-L433","documentation":"Returned by GenerateImage when the global Conf is nil or Conf.AI is nil — i.e. the kernel configuration has not been loaded (or the AI subsystem was never initialized). It fires before any model lookup, so it indicates the feature is entirely unavailable in this build/session, not a misconfigured model.","triggerScenarios":"Calling GenerateImage during kernel boot before Conf is populated; calling it in a context (mobile binding, headless tool) where the AI config was never read; a corrupted conf.json that deserialized to a nil AI block.","commonSituations":"An integration test invokes GenerateImage without booting the kernel; a plugin runs against a kernel that hasn't finished Boot(); the user deleted or zeroed out the AI section of their config.","solutions":["Ensure the kernel is fully booted (util.Boot completed) and conf.json is loaded before invoking GenerateImage.","If the AI section was removed, restore it from a backup or re-create it through the settings UI.","Guard callers: check model.Conf != nil && model.Conf.AI != nil before offering image-generation actions in the UI."],"exampleFix":"// before\nres, err := model.GenerateImage(ctx, req)\n\n// after — guard the feature gate\nif model.Conf == nil || model.Conf.AI == nil {\n    return errors.New(\"image generation unavailable: AI not configured\")\n}\nres, err := model.GenerateImage(ctx, req)","handlingStrategy":"validation","validationCode":"if model.Conf == nil || model.Conf.AI == nil {\n    return errors.New(\"AI subsystem not initialized\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only expose image-generation UI actions after the kernel boot completes and Conf.AI loads.","In tests, bootstrap a minimal Conf.AI before exercising GenerateImage.","Treat a nil Conf.AI as a feature-unavailable signal and disable the entry point."],"tags":["config","ai","initialization"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}