feat(resource): add stable resource registry with LLM-context alias compaction

Introduce resource://<handle> as the stable application identity for stored
objects, decoupling API responses, persisted rich text, and LLM prompts from
physical storage paths. Adds a resource catalog service (register/resolve/bind,
revocable expiring access grants), a request-local alias registry that compacts
resource references while in the LLM context and restores them (including across
streaming chunks), plus router, IM, chat-pipeline, and multimodal integration.

Includes schema migrations (resources, resource_bindings, resource_access_grants)
for sqlite, and hardens URL/output security handling.
This commit is contained in:
wizardchen
2026-07-15 16:31:21 +08:00
committed by lyingbug
parent 9733bd28bf
commit 6d14cc3536
32 changed files with 1790 additions and 59 deletions
+12 -4
View File
@@ -12,12 +12,13 @@ import (
// resolveImageURLForLLM converts stored image paths to a format that LLM APIs can consume.
// - data: URIs and http(s):// URLs are returned as-is.
// - local:// paths are read from disk and converted to base64 data URIs.
// - resource:// and provider-backed local paths are read through the
// application resolver and converted to base64 data URIs.
func resolveImageURLForLLM(imageURL string) string {
if strings.HasPrefix(imageURL, "data:") || strings.HasPrefix(imageURL, "http://") || strings.HasPrefix(imageURL, "https://") {
return imageURL
}
if strings.HasPrefix(imageURL, "local://") {
if isApplicationStoredImage(imageURL) {
data := readLocalStorageBytes(imageURL)
if data != nil {
mime := http.DetectContentType(data)
@@ -40,14 +41,21 @@ func resolveImageURLForOllama(imageURL string) []byte {
}
return decoded
}
if strings.HasPrefix(imageURL, "local://") {
if isApplicationStoredImage(imageURL) {
return readLocalStorageBytes(imageURL)
}
return nil
}
func isApplicationStoredImage(imageURL string) bool {
return strings.HasPrefix(imageURL, "resource://") ||
strings.HasPrefix(imageURL, "local://") ||
strings.HasPrefix(imageURL, "storage://")
}
// LocalImageResolver, when set by the application layer at startup, resolves a
// local:// storage URL to its bytes using the owning tenant's storage config.
// resource:// or provider storage URL to bytes using the owning tenant's
// storage config.
// Stored local:// URLs are relative to the storage base dir and do NOT encode
// the tenant's configured PathPrefix, so a plain env-based join would miss the
// prefix. When nil (e.g. in tests), callers fall back to the env-based