siyuan-note/siyuan · error

only global assets/... images are supported

Error message

only global assets/... images are supported

What it means

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.

Solutions

  1. Ensure the image is stored in the workspace-global assets directory (data/assets/...) and pass that path
  2. Import the image via the standard asset upload flow to obtain a global assets path
  3. Strip any ?query suffix and confirm the cleaned path starts with assets/ before calling

Example fix

// before
PrepareAgentMessageImage("/notebooks/20240101120000-ab12cd3/assets/local.png")
// after
PrepareAgentMessageImage("assets/global-20240101120000-ab12cd3.png")
Defensive patterns

Strategy: validation

Validate before calling

cleanPath := AssetPathWithoutQuery(assetPath)
if !strings.HasPrefix(cleanPath, "assets/") { return errors.New("agent images must be global assets/") }

Type guard

func isGlobalAsset(p string) bool { return strings.HasPrefix(AssetPathWithoutQuery(p), "assets/") }

Try / catch

prepared, err := PrepareAgentMessageImage(assetPath)
if err != nil && strings.Contains(err.Error(), "only global assets") { /* upload image to global assets, then retry */ }

Prevention

When it happens

Trigger: Calling PrepareAgentMessageImage with a network URL, an absolute path, or a notebook-scoped path not under the global assets/ directory.

Common situations: 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.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/164bef294be93ef9. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/assets.go:490

		data, documentImageMaxBytes, documentImageMaxPixels, documentImageMaxEdge,
	)
	if err != nil {
		return PreparedDocumentImage{}, err
	}
	return PreparedDocumentImage{
		Artifact: ImageArtifactRef{Kind: "image", Path: assetPath, DocumentID: bt.RootID},
		Data:     prepared.Data,
		MIMEType: prepared.MIMEType,
		Prepared: prepared,
	}, nil
}

// PrepareAgentMessageImage 校验并读取智能体用户消息引用的全局资源图片。
func PrepareAgentMessageImage(assetPath string) (PreparedDocumentImage, error) {
	assetPath = strings.TrimSpace(assetPath)
	cleanPath := AssetPathWithoutQuery(assetPath)
	if !strings.HasPrefix(cleanPath, "assets/") {
		return PreparedDocumentImage{}, errors.New("only global assets/... images are supported")
	}
	relativePath, absPath, err := ResolveDataAssetPath(cleanPath)
	if err != nil {
		return PreparedDocumentImage{}, err
	}
	if !strings.HasPrefix(relativePath, "assets/") {
		return PreparedDocumentImage{}, errors.New("only global assets/... images are supported")
	}
	if err = EnsureAssetLocal(absPath); err != nil {
		return PreparedDocumentImage{}, err
	}
	data, err := os.ReadFile(absPath)
	if err != nil {
		return PreparedDocumentImage{}, fmt.Errorf("read image failed: %w", err)
	}
	prepared, err := util.PrepareModelImage(
		data, documentImageMaxBytes, documentImageMaxPixels, documentImageMaxEdge,
	)

View on GitHub (pinned to 9f775e8a12)