{"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":486,"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":468,"sourceCodeEnd":504,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/assets.go#L468-L504","documentation":"PrepareAgentMessageImage only accepts global workspace asset paths under assets/ (after stripping query strings). Paths outside assets/ — absolute paths, URLs, or notebook-relative paths — are rejected because this API reads images from the global workspace data/assets directory.","triggerScenarios":"Calling PrepareAgentMessageImage with \"https://...\", \"/tmp/x.jpg\", \"notebook/assets/x.png\", or any path not starting with assets/ when the agent processes a user message image.","commonSituations":"An agent passes an image URL extracted from chat text; caller passes a path relative to a notebook instead of the workspace root; user pastes a full filesystem path.","solutions":["Pass a workspace-global path of the form assets/<file>","First import the image into the workspace assets directory, then pass its assets/ path","Convert remote URLs by downloading into assets/ before invoking"],"exampleFix":"// before\nmodel.PrepareAgentMessageImage(\"/home/user/photo.jpg\")\n// after\nassetPath, err := model.ImportFileAsAsset(\"/home/user/photo.jpg\") // → \"assets/photo.jpg\"\nmodel.PrepareAgentMessageImage(assetPath)","handlingStrategy":"validation","validationCode":"if !strings.HasPrefix(model.AssetPathWithoutQuery(assetPath), \"assets/\") {\n    return errors.New(\"pass a global workspace asset path like assets/foo.png\")\n}","typeGuard":"func isGlobalAsset(p string) bool {\n    return strings.HasPrefix(model.AssetPathWithoutQuery(p), \"assets/\")\n}","tryCatchPattern":"prepared, err := model.PrepareAgentMessageImage(assetPath)\nif err != nil && strings.Contains(err.Error(), \"only global assets\") {\n    // import the image into assets/ and retry once\n}","preventionTips":["Only pass workspace-global assets/... paths to this API","Download remote images into assets/ before invoking","Do not pass notebook-relative or absolute paths"],"tags":["go","validation","path-safety"],"backgroundTag":"invalid-argument-value","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}