mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: track ai seat usage (#22682)
When a user uses an AI feature, we record them in the `ai_seat_state` as consuming a seat. Added in debouching to prevent excessive writes to the db for this feature. There is no need for frequent updates.
This commit is contained in:
@@ -45,6 +45,7 @@ import (
|
||||
agplusage "github.com/coder/coder/v2/coderd/usage"
|
||||
"github.com/coder/coder/v2/coderd/wsbuilder"
|
||||
"github.com/coder/coder/v2/codersdk"
|
||||
"github.com/coder/coder/v2/enterprise/aiseats"
|
||||
entchatd "github.com/coder/coder/v2/enterprise/coderd/chatd"
|
||||
"github.com/coder/coder/v2/enterprise/coderd/connectionlog"
|
||||
"github.com/coder/coder/v2/enterprise/coderd/dbauthz"
|
||||
@@ -217,7 +218,10 @@ func New(ctx context.Context, options *Options) (_ *API, err error) {
|
||||
},
|
||||
})
|
||||
|
||||
api.aiSeatTracker = aiseats.New(options.Database, api.Logger.Named("aiseats"), quartz.NewReal())
|
||||
|
||||
api.AGPL = coderd.New(options.Options)
|
||||
api.AGPL.AISeatTracker = api.aiSeatTracker
|
||||
defer func() {
|
||||
if err != nil {
|
||||
_ = api.Close()
|
||||
@@ -785,6 +789,7 @@ type API struct {
|
||||
|
||||
aibridgedHandler http.Handler
|
||||
aibridgeproxydHandler http.Handler
|
||||
aiSeatTracker *aiseats.SeatTracker
|
||||
}
|
||||
|
||||
// writeEntitlementWarningsHeader writes the entitlement warnings to the response header
|
||||
|
||||
Reference in New Issue
Block a user