Artifact 695a3810c409b232250bacc1e200bbdd744137d7ab0c2e26866010d7cf0d1d61:
- File
leaf/agent/notify/service_methods.go
— part of check-in
[02c7e2b781]
at
2026-05-04 18:42:12
on branch trunk
— feat(notify): libfossil-hidden Service methods (#111)
Adds methods on *Service that wrap the existing libfossil-typed free functions, so consumers can use notify's chat-over-NATS-with-fossil- durability behavior without seeing *libfossil.Repo in any signature:
- ListThreads(ctx, project) — wraps free ListThreads - ReadThread(ctx, project, threadShort) — wraps free ReadThread - MessageCount(ctx, project, threadShort) — len(ReadThread) - ListDevices / AddDevice / RemoveDevice (Device type) - CreatePairingToken / ValidateToken (PendingToken type)
The free *libfossil.Repo-typed functions are unchanged; advanced consumers and existing callers continue to work. Service.Repo() stays as an escape hatch with an updated doc comment recommending the new methods.
Note: ListThreads / ReadThread / MessageCount take an explicit project parameter (the brief listed them without one). The notify repo holds threads for multiple projects and the underlying free functions need project; carrying a default project on Service would be a reasonable follow-up but is out of scope here.
Closes #104 (user: [email protected], size: 2131) [annotate] [blame] [check-ins using]
package notify import ( "context" ) // ListThreads returns the threads for project from the agent's notify repo. // Thin delegation to the libfossil-typed free function ListThreads. // // project is required because the notify repo can hold threads for multiple // projects; the free-function shape requires it. A Service that tracks a // default project would be a reasonable follow-up but is out of scope. func (s *Service) ListThreads(ctx context.Context, project string) ([]ThreadSummary, error) { return ListThreads(s.repo, project) } // ReadThread returns the messages in (project, threadShort) ordered as // stored. Thin delegation to ReadThread. func (s *Service) ReadThread(ctx context.Context, project, threadShort string) ([]Message, error) { return ReadThread(s.repo, project, threadShort) } // MessageCount returns the number of messages in (project, threadShort). func (s *Service) MessageCount(ctx context.Context, project, threadShort string) (int, error) { msgs, err := ReadThread(s.repo, project, threadShort) if err != nil { return 0, err } return len(msgs), nil } // ListDevices returns the registered devices on the agent's notify repo. func (s *Service) ListDevices(ctx context.Context) ([]Device, error) { return ListDevices(s.repo) } // AddDevice registers a device on the agent's notify repo. func (s *Service) AddDevice(ctx context.Context, dev Device) error { return AddDevice(s.repo, dev) } // RemoveDevice removes a device by name from the agent's notify repo. func (s *Service) RemoveDevice(ctx context.Context, name string) error { return RemoveDevice(s.repo, name) } // CreatePairingToken generates a pairing token for name and stores it in // the agent's notify repo. func (s *Service) CreatePairingToken(ctx context.Context, name string) (string, error) { return CreatePairingToken(s.repo, name) } // ValidateToken validates a formatted pairing token against the agent's // notify repo and returns the matching pending token (or error if none). func (s *Service) ValidateToken(ctx context.Context, token string) (PendingToken, error) { return ValidateToken(s.repo, token) }