oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package chatstate
2
3import (
4 "amadan.net/oficina/equipo/internal/runnerproto"
5 "errors"
6 "gorm.io/gorm"
7 "slices"
8)
9
10var ErrContextUnavailable = errors.New("coordinator_context_unavailable")
11
12func BoundContext(tx *gorm.DB, turn, binding string, generation int64, c runnerproto.CoordinatorContext) (runnerproto.CoordinatorContext, error) {
13 err := tx.Table("coordinator_turns").Where("binding_id=? AND generation=? AND (id=? OR superseded_by=?)", binding, generation, turn, turn).Order("sequence").Distinct("message_id").Pluck("message_id", &c.Pending).Error
14 if err != nil {
15 return c, err
16 }
17 for _, id := range c.Pending {
18 if !slices.ContainsFunc(c.Recent, func(m runnerproto.MessageRef) bool { return m.ID == id }) {
19 return c, ErrContextUnavailable
20 }
21 }
22 return runnerproto.BoundCoordinatorContext(c)
23}
24