- Router accepts full Dependencies (memory/voice/orchestrator/WShub) - Memory API: CRUD + search endpoints with PostgreSQL persistence - Voice API: STT/TTS endpoints - Admin dashboard: real uptime + service status - WebSocket chat: routes to AI-Core orchestrator pipeline - APIAdapter bridges memory domain model to REST interface - Smoke test: memory CRUD + session creation verified
87 lines
2.1 KiB
Go
87 lines
2.1 KiB
Go
package memory
|
|
|
|
import "context"
|
|
|
|
// APIAdapter adapts the memory Service to a simplified API interface.
|
|
// This bridges between the rich domain model and the Gateway's REST handler expectations.
|
|
type APIAdapter struct {
|
|
svc *Service
|
|
}
|
|
|
|
// APIEntry is the simplified memory entry for REST API responses.
|
|
type APIEntry struct {
|
|
ID string `json:"id"`
|
|
UserID string `json:"user_id"`
|
|
Content string `json:"content"`
|
|
Summary string `json:"summary"`
|
|
Keywords []string `json:"keywords"`
|
|
Category string `json:"category"`
|
|
Priority float64 `json:"priority"`
|
|
}
|
|
|
|
// NewAPIAdapter wraps a Service for REST API consumption.
|
|
func NewAPIAdapter(svc *Service) *APIAdapter {
|
|
return &APIAdapter{svc: svc}
|
|
}
|
|
|
|
func (a *APIAdapter) Search(ctx context.Context, userID, query string, limit int) (any, error) {
|
|
memories, err := a.svc.Search(ctx, SearchQuery{UserID: userID, Query: query, Limit: limit})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
result := make([]APIEntry, len(memories))
|
|
for i, m := range memories {
|
|
result[i] = toEntry(m)
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
func (a *APIAdapter) List(ctx context.Context, userID string, limit int) (any, error) {
|
|
memories, err := a.svc.List(ctx, userID, limit)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
result := make([]APIEntry, len(memories))
|
|
for i, m := range memories {
|
|
result[i] = toEntry(m)
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
func (a *APIAdapter) Add(ctx context.Context, userID, content, category string, priority float64) (any, error) {
|
|
m, err := a.svc.Add(ctx, userID, "", content, category, priority)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
e := toEntry(*m)
|
|
return &e, nil
|
|
}
|
|
|
|
func (a *APIAdapter) Get(ctx context.Context, id string) (any, error) {
|
|
m, err := a.svc.GetByID(ctx, id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
e := toEntry(*m)
|
|
return &e, nil
|
|
}
|
|
|
|
func (a *APIAdapter) Delete(ctx context.Context, id string) error {
|
|
return a.svc.Delete(ctx, id)
|
|
}
|
|
|
|
func toEntry(m Memory) APIEntry {
|
|
return APIEntry{
|
|
ID: m.ID,
|
|
UserID: m.UserID,
|
|
Content: m.Content,
|
|
Summary: m.Summary,
|
|
Keywords: m.Keywords,
|
|
Category: m.Category,
|
|
Priority: m.Priority,
|
|
}
|
|
}
|
|
|
|
// Ensure we use context
|
|
var _ = context.Background
|