Skip to content

Commit 40fb303

Browse files
committed
refactoring and consolidation
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
1 parent e7bd8a0 commit 40fb303

14 files changed

Lines changed: 937 additions & 140 deletions

core/http/endpoints/localai/agents.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ func GetAgentObservablesEndpoint(app *application.Application) echo.HandlerFunc
251251
return c.JSON(http.StatusNotFound, map[string]string{"error": err.Error()})
252252
}
253253
if history == nil {
254-
history = []any{}
254+
history = []json.RawMessage{}
255255
}
256256
return c.JSON(http.StatusOK, map[string]any{
257257
"Name": name,

core/services/advisorylock/advisorylock_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package advisorylock
22

33
import (
4+
"runtime"
45
"sync"
56
"sync/atomic"
67
"time"
@@ -18,6 +19,9 @@ var _ = Describe("AdvisoryLock", func() {
1819
var db *gorm.DB
1920

2021
BeforeEach(func() {
22+
if runtime.GOOS == "darwin" {
23+
Skip("testcontainers requires Docker, not available on macOS CI")
24+
}
2125
db = testutil.SetupTestDB()
2226
})
2327

core/services/agentpool/agent_config_backend.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package agentpool
22

33
import (
4+
"encoding/json"
5+
46
"github.com/mudler/LocalAGI/core/agent"
57
"github.com/mudler/LocalAGI/core/sse"
68
"github.com/mudler/LocalAGI/core/state"
@@ -26,7 +28,7 @@ type AgentConfigBackend interface {
2628
GetAgent(userID, name string) *agent.Agent
2729
GetSSEManager(userID, name string) sse.Manager
2830
GetStatus(userID, name string) *state.Status
29-
GetObservables(userID, name string) (any, error)
31+
GetObservables(userID, name string) ([]json.RawMessage, error)
3032
ClearObservables(userID, name string) error
3133

3234
// Admin aggregation

core/services/agentpool/agent_config_distributed.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,14 @@ func (b *distributedAgentConfigBackend) GetStatus(_, _ string) *state.Status {
121121
}
122122

123123
// GetObservables reads from the PostgreSQL observables table.
124-
func (b *distributedAgentConfigBackend) GetObservables(userID, name string) (any, error) {
124+
func (b *distributedAgentConfigBackend) GetObservables(userID, name string) ([]json.RawMessage, error) {
125125
records, err := b.store.GetObservables(agents.AgentKey(userID, name), defaultObservableLimit)
126126
if err != nil {
127127
return nil, err
128128
}
129-
// Convert database records to generic maps for JSON serialization.
130-
var result []map[string]any
129+
result := make([]json.RawMessage, 0, len(records))
131130
for _, rec := range records {
132-
var obs map[string]any
133-
if json.Unmarshal([]byte(rec.PayloadJSON), &obs) == nil {
134-
result = append(result, obs)
135-
}
131+
result = append(result, json.RawMessage(rec.PayloadJSON))
136132
}
137133
return result, nil
138134
}

core/services/agentpool/agent_config_local.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,21 @@ func (b *localAgentConfigBackend) GetStatus(userID, name string) *state.Status {
117117
return b.svc.pool.GetStatusHistory(agents.AgentKey(userID, name))
118118
}
119119

120-
func (b *localAgentConfigBackend) GetObservables(userID, name string) (any, error) {
120+
func (b *localAgentConfigBackend) GetObservables(userID, name string) ([]json.RawMessage, error) {
121121
ag := b.svc.pool.GetAgent(agents.AgentKey(userID, name))
122122
if ag == nil {
123123
return nil, fmt.Errorf("%w: %s", ErrAgentNotFound, name)
124124
}
125-
return ag.Observer().History(), nil
125+
history := ag.Observer().History()
126+
result := make([]json.RawMessage, 0, len(history))
127+
for _, obs := range history {
128+
data, err := json.Marshal(obs)
129+
if err != nil {
130+
continue
131+
}
132+
result = append(result, data)
133+
}
134+
return result, nil
126135
}
127136

128137
func (b *localAgentConfigBackend) ClearObservables(userID, name string) error {

0 commit comments

Comments
 (0)