diff options
| author | Kujtim Hoxha <[email protected]> | 2025-04-13 13:17:17 +0200 |
|---|---|---|
| committer | Kujtim Hoxha <[email protected]> | 2025-04-21 13:41:25 +0200 |
| commit | 3ad983db0f2c08826d56cb5de274d706c95b3353 (patch) | |
| tree | 3151e7f361dc2b468429791d581eb5f3d658f84f /internal/session | |
| parent | 5601466fe1610b777895682050b1b458f80c0ac8 (diff) | |
| download | opencode-3ad983db0f2c08826d56cb5de274d706c95b3353.tar.gz opencode-3ad983db0f2c08826d56cb5de274d706c95b3353.zip | |
cleanup app, config and root
Diffstat (limited to 'internal/session')
| -rw-r--r-- | internal/session/session.go | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/internal/session/session.go b/internal/session/session.go index 13f420b7c..9a16224c3 100644 --- a/internal/session/session.go +++ b/internal/session/session.go @@ -23,22 +23,21 @@ type Session struct { type Service interface { pubsub.Suscriber[Session] - Create(title string) (Session, error) - CreateTaskSession(toolCallID, parentSessionID, title string) (Session, error) - Get(id string) (Session, error) - List() ([]Session, error) - Save(session Session) (Session, error) - Delete(id string) error + Create(ctx context.Context, title string) (Session, error) + CreateTaskSession(ctx context.Context, toolCallID, parentSessionID, title string) (Session, error) + Get(ctx context.Context, id string) (Session, error) + List(ctx context.Context) ([]Session, error) + Save(ctx context.Context, session Session) (Session, error) + Delete(ctx context.Context, id string) error } type service struct { *pubsub.Broker[Session] - q db.Querier - ctx context.Context + q db.Querier } -func (s *service) Create(title string) (Session, error) { - dbSession, err := s.q.CreateSession(s.ctx, db.CreateSessionParams{ +func (s *service) Create(ctx context.Context, title string) (Session, error) { + dbSession, err := s.q.CreateSession(ctx, db.CreateSessionParams{ ID: uuid.New().String(), Title: title, }) @@ -50,8 +49,8 @@ func (s *service) Create(title string) (Session, error) { return session, nil } -func (s *service) CreateTaskSession(toolCallID, parentSessionID, title string) (Session, error) { - dbSession, err := s.q.CreateSession(s.ctx, db.CreateSessionParams{ +func (s *service) CreateTaskSession(ctx context.Context, toolCallID, parentSessionID, title string) (Session, error) { + dbSession, err := s.q.CreateSession(ctx, db.CreateSessionParams{ ID: toolCallID, ParentSessionID: sql.NullString{String: parentSessionID, Valid: true}, Title: title, @@ -64,12 +63,12 @@ func (s *service) CreateTaskSession(toolCallID, parentSessionID, title string) ( return session, nil } -func (s *service) Delete(id string) error { - session, err := s.Get(id) +func (s *service) Delete(ctx context.Context, id string) error { + session, err := s.Get(ctx, id) if err != nil { return err } - err = s.q.DeleteSession(s.ctx, session.ID) + err = s.q.DeleteSession(ctx, session.ID) if err != nil { return err } @@ -77,16 +76,16 @@ func (s *service) Delete(id string) error { return nil } -func (s *service) Get(id string) (Session, error) { - dbSession, err := s.q.GetSessionByID(s.ctx, id) +func (s *service) Get(ctx context.Context, id string) (Session, error) { + dbSession, err := s.q.GetSessionByID(ctx, id) if err != nil { return Session{}, err } return s.fromDBItem(dbSession), nil } -func (s *service) Save(session Session) (Session, error) { - dbSession, err := s.q.UpdateSession(s.ctx, db.UpdateSessionParams{ +func (s *service) Save(ctx context.Context, session Session) (Session, error) { + dbSession, err := s.q.UpdateSession(ctx, db.UpdateSessionParams{ ID: session.ID, Title: session.Title, PromptTokens: session.PromptTokens, @@ -101,8 +100,8 @@ func (s *service) Save(session Session) (Session, error) { return session, nil } -func (s *service) List() ([]Session, error) { - dbSessions, err := s.q.ListSessions(s.ctx) +func (s *service) List(ctx context.Context) ([]Session, error) { + dbSessions, err := s.q.ListSessions(ctx) if err != nil { return nil, err } @@ -127,11 +126,10 @@ func (s service) fromDBItem(item db.Session) Session { } } -func NewService(ctx context.Context, q db.Querier) Service { +func NewService(q db.Querier) Service { broker := pubsub.NewBroker[Session]() return &service{ broker, q, - ctx, } } |
