From dde035343265cb7b6a5312c22f40574d9b254406 Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Sat, 14 Mar 2026 22:31:45 +0000 Subject: [PATCH] chore(api): add path to expose collection raw files Signed-off-by: Ettore Di Giacinto --- .../endpoints/localai/agent_collections.go | 20 +++++++++++++++++++ core/http/routes/agents.go | 1 + core/services/agent_pool.go | 4 ++++ go.mod | 4 ++-- go.sum | 8 ++++---- 5 files changed, 31 insertions(+), 6 deletions(-) diff --git a/core/http/endpoints/localai/agent_collections.go b/core/http/endpoints/localai/agent_collections.go index 83ca818c0..49b6ea386 100644 --- a/core/http/endpoints/localai/agent_collections.go +++ b/core/http/endpoints/localai/agent_collections.go @@ -203,6 +203,26 @@ func RemoveCollectionSourceEndpoint(app *application.Application) echo.HandlerFu } } +// GetCollectionEntryRawFileEndpoint serves the original uploaded binary file. +func GetCollectionEntryRawFileEndpoint(app *application.Application) echo.HandlerFunc { + return func(c echo.Context) error { + svc := app.AgentPoolService() + entryParam := c.Param("*") + entry, err := url.PathUnescape(entryParam) + if err != nil { + entry = entryParam + } + fpath, err := svc.GetCollectionEntryFilePath(c.Param("name"), entry) + if err != nil { + if strings.Contains(err.Error(), "not found") { + return c.JSON(http.StatusNotFound, map[string]string{"error": err.Error()}) + } + return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()}) + } + return c.File(fpath) + } +} + func ListCollectionSourcesEndpoint(app *application.Application) echo.HandlerFunc { return func(c echo.Context) error { svc := app.AgentPoolService() diff --git a/core/http/routes/agents.go b/core/http/routes/agents.go index 20e5f9ef5..e817df1dc 100644 --- a/core/http/routes/agents.go +++ b/core/http/routes/agents.go @@ -80,6 +80,7 @@ func RegisterAgentPoolRoutes(e *echo.Echo, app *application.Application) { g.POST("/collections/:name/upload", localai.UploadToCollectionEndpoint(app)) g.GET("/collections/:name/entries", localai.ListCollectionEntriesEndpoint(app)) g.GET("/collections/:name/entries/*", localai.GetCollectionEntryContentEndpoint(app)) + g.GET("/collections/:name/entries-raw/*", localai.GetCollectionEntryRawFileEndpoint(app)) g.POST("/collections/:name/search", localai.SearchCollectionEndpoint(app)) g.POST("/collections/:name/reset", localai.ResetCollectionEndpoint(app)) g.DELETE("/collections/:name/entry/delete", localai.DeleteCollectionEntryEndpoint(app)) diff --git a/core/services/agent_pool.go b/core/services/agent_pool.go index b42117f32..63a1dcd1d 100644 --- a/core/services/agent_pool.go +++ b/core/services/agent_pool.go @@ -1053,6 +1053,10 @@ func (s *AgentPoolService) CollectionEntryExists(collection, entry string) bool return s.collectionsBackend.EntryExists(collection, entry) } +func (s *AgentPoolService) GetCollectionEntryFilePath(collection, entry string) (string, error) { + return s.collectionsBackend.GetEntryFilePath(collection, entry) +} + // --- Actions --- // ListAvailableActions returns the list of all available action type names. diff --git a/go.mod b/go.mod index 0025bfcb7..ba23fea78 100644 --- a/go.mod +++ b/go.mod @@ -128,8 +128,8 @@ require ( github.com/kevinburke/ssh_config v1.2.0 // indirect github.com/labstack/gommon v0.4.2 // indirect github.com/mschoch/smat v0.2.0 // indirect - github.com/mudler/LocalAGI v0.0.0-20260311165347-2d2da7df95e1 - github.com/mudler/localrecall v0.5.7-0.20260314101322-43426c06c67a // indirect + github.com/mudler/LocalAGI v0.0.0-20260314222828-e38f13ab8cec + github.com/mudler/localrecall v0.5.9-0.20260314221856-96d63875cc47 // indirect github.com/mudler/skillserver v0.0.5-0.20260221145827-0639a82c8f49 github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/oxffaa/gopher-parse-sitemap v0.0.0-20191021113419-005d2eb1def4 // indirect diff --git a/go.sum b/go.sum index 04ad1e4a3..b477239d2 100644 --- a/go.sum +++ b/go.sum @@ -654,8 +654,8 @@ github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= github.com/mschoch/smat v0.2.0 h1:8imxQsjDm8yFEAVBe7azKmKSgzSkZXDuKkSq9374khM= github.com/mschoch/smat v0.2.0/go.mod h1:kc9mz7DoBKqDyiRL7VZN8KvXQMWeTaVnttLRXOlotKw= -github.com/mudler/LocalAGI v0.0.0-20260311165347-2d2da7df95e1 h1:EvG0FDIDGciO7laxgSTUuFjcpWEwhfUM9zfl/T3TVF0= -github.com/mudler/LocalAGI v0.0.0-20260311165347-2d2da7df95e1/go.mod h1:6LQyB+kxvh3LGrv4tXk9FVvBvaFRJ14vn09+4xWwmI8= +github.com/mudler/LocalAGI v0.0.0-20260314222828-e38f13ab8cec h1:Y6JYhfJidFktfmQC00SwHtQVh0lr0O52qihgTKddSNU= +github.com/mudler/LocalAGI v0.0.0-20260314222828-e38f13ab8cec/go.mod h1:yf+IlZzQCGgKPGFn5yclzA2Dxxhy75K3YDubkjCub04= github.com/mudler/cogito v0.9.5-0.20260313170202-42271c7e1a6b h1:Hs2Byjnukgkwm5Vw7z5aSZEjznPHaxjr2vLc5Uu1fHQ= github.com/mudler/cogito v0.9.5-0.20260313170202-42271c7e1a6b/go.mod h1:6sfja3lcu2nWRzEc0wwqGNu/eCG3EWgij+8s7xyUeQ4= github.com/mudler/edgevpn v0.31.1 h1:7qegiDWd0kAg6ljhNHxqvp8hbo/6BbzSdbb7/2WZfiY= @@ -664,8 +664,8 @@ github.com/mudler/go-piper v0.0.0-20241023091659-2494246fd9fc h1:RxwneJl1VgvikiX github.com/mudler/go-piper v0.0.0-20241023091659-2494246fd9fc/go.mod h1:O7SwdSWMilAWhBZMK9N9Y/oBDyMMzshE3ju8Xkexwig= github.com/mudler/go-processmanager v0.1.0 h1:fcSKgF9U/a1Z7KofAFeZnke5YseadCI5GqL9oT0LS3E= github.com/mudler/go-processmanager v0.1.0/go.mod h1:h6kmHUZeafr+k5hRYpGLMzJFH4hItHffgpRo2QIkP+o= -github.com/mudler/localrecall v0.5.7-0.20260314101322-43426c06c67a h1:Ah71V/UgF78i0I7yxu0EUweum6p3KwErz9qVFms9/VI= -github.com/mudler/localrecall v0.5.7-0.20260314101322-43426c06c67a/go.mod h1:TZVXQI840MqjDtilBLc7kfmnctK4oNf1IR+cE68zno8= +github.com/mudler/localrecall v0.5.9-0.20260314221856-96d63875cc47 h1:fHIkLJgfcYDF4bhwVZdfFcQB2HVw93ClOQSKRci8qQs= +github.com/mudler/localrecall v0.5.9-0.20260314221856-96d63875cc47/go.mod h1:TZVXQI840MqjDtilBLc7kfmnctK4oNf1IR+cE68zno8= github.com/mudler/memory v0.0.0-20251216220809-d1256471a6c2 h1:+WHsL/j6EWOMUiMVIOJNKOwSKiQt/qDPc9fePCf87fA= github.com/mudler/memory v0.0.0-20251216220809-d1256471a6c2/go.mod h1:EA8Ashhd56o32qN7ouPKFSRUs/Z+LrRCF4v6R2Oarm8= github.com/mudler/skillserver v0.0.5-0.20260221145827-0639a82c8f49 h1:dAF1ALXqqapRZo80x56BIBBcPrPbRNerbd66rdyO8J4=