package memory import ( "context" "errors" "strings" "time" "github.com/google/uuid" "github.com/samcharles93/archie-core/modules/memory/internal/store" ) // maxNotes bounds the facts a conversation is given, so memory can't crowd // out the conversation itself. const maxNotes = 200 // Note is a fact the operator asked Archie to remember across conversations. type Note struct { ID uuid.UUID `json:"id"` Text string `json:"text"` CreatedAt time.Time `json:"created_at"` } type noteStore interface { AddNote(ctx context.Context, orgID string, n store.Note) error Notes(ctx context.Context, orgID string, limit int) ([]store.Note, error) DeleteNote(ctx context.Context, orgID string, id uuid.UUID) (bool, error) } // Remember stores a fact and returns it. func (m *Module) Remember(ctx context.Context, text string) (Note, error) { text = strings.TrimSpace(text) if text == "" { return Note{}, errors.New("a note needs text") } n := store.Note{ID: uuid.New(), Text: text, CreatedAt: time.Now().UTC()} if err := m.notes.AddNote(ctx, m.orgID, n); err != nil { return Note{}, err } return Note(n), nil } // Notes returns the remembered facts, oldest first. func (m *Module) Notes(ctx context.Context) ([]Note, error) { rows, err := m.notes.Notes(ctx, m.orgID, maxNotes) if err != nil { return nil, err } out := make([]Note, 0, len(rows)) for _, r := range rows { out = append(out, Note(r)) } return out, nil } // Forget removes a fact and reports whether there was one. func (m *Module) Forget(ctx context.Context, id uuid.UUID) (bool, error) { return m.notes.DeleteNote(ctx, m.orgID, id) }