{"record":{"id":"164bef294be93ef9","repo":"siyuan-note/siyuan","slug":"only-global-assets-images-are-supported","errorCode":null,"errorMessage":"only global assets/... images are supported","messagePattern":"only global assets/\\.\\.\\. images are supported","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/assets.go","lineNumber":490,"sourceCode":"\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// PrepareAgentMessageImage 校验并读取智能体用户消息引用的全局资源图片。\nfunc PrepareAgentMessageImage(assetPath string) (PreparedDocumentImage, error) {\n\tassetPath = strings.TrimSpace(assetPath)\n\tcleanPath := AssetPathWithoutQuery(assetPath)\n\tif !strings.HasPrefix(cleanPath, \"assets/\") {\n\t\treturn PreparedDocumentImage{}, errors.New(\"only global assets/... images are supported\")\n\t}\n\trelativePath, absPath, err := ResolveDataAssetPath(cleanPath)\n\tif err != nil {\n\t\treturn PreparedDocumentImage{}, err\n\t}\n\tif !strings.HasPrefix(relativePath, \"assets/\") {\n\t\treturn PreparedDocumentImage{}, errors.New(\"only global assets/... images are supported\")\n\t}\n\tif err = EnsureAssetLocal(absPath); err != nil {\n\t\treturn PreparedDocumentImage{}, err\n\t}\n\tdata, err := os.ReadFile(absPath)\n\tif err != nil {\n\t\treturn PreparedDocumentImage{}, fmt.Errorf(\"read image failed: %w\", err)\n\t}\n\tprepared, err := util.PrepareModelImage(\n\t\tdata, documentImageMaxBytes, documentImageMaxPixels, documentImageMaxEdge,\n\t)","sourceCodeStart":472,"sourceCodeEnd":508,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/assets.go#L472-L508","documentation":"PrepareAgentMessageImage reads images referenced by agent user messages; it requires a global workspace asset path (starting with assets/ after query stripping) so the image resolves via ResolveDataAssetPath in the shared data directory rather than a notebook box.","triggerScenarios":"Calling PrepareAgentMessageImage with a network URL, an absolute path, or a notebook-scoped path not under the global assets/ directory.","commonSituations":"Passing a per-notebook asset path from a box-specific context into the agent message flow; forwarding a remote image URL from chat input; test TestPrepareAgentMessageImageReadsGlobalAsset covers the valid global case.","solutions":["Ensure the image is stored in the workspace-global assets directory (data/assets/...) and pass that path","Import the image via the standard asset upload flow to obtain a global assets path","Strip any ?query suffix and confirm the cleaned path starts with assets/ before calling"],"exampleFix":"// before\nPrepareAgentMessageImage(\"/notebooks/20240101120000-ab12cd3/assets/local.png\")\n// after\nPrepareAgentMessageImage(\"assets/global-20240101120000-ab12cd3.png\")","handlingStrategy":"validation","validationCode":"cleanPath := AssetPathWithoutQuery(assetPath)\nif !strings.HasPrefix(cleanPath, \"assets/\") { return errors.New(\"agent images must be global assets/\") }","typeGuard":"func isGlobalAsset(p string) bool { return strings.HasPrefix(AssetPathWithoutQuery(p), \"assets/\") }","tryCatchPattern":"prepared, err := PrepareAgentMessageImage(assetPath)\nif err != nil && strings.Contains(err.Error(), \"only global assets\") { /* upload image to global assets, then retry */ }","preventionTips":["Upload chat images through the standard asset flow so they land in data/assets/","Do not pass notebook-box-local paths into agent message flows","Strip query strings before path checks"],"tags":["go","validation","assets","ai","agents"],"backgroundTag":"invalid-argument-value","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}