diff --git a/coderd/database/dump.sql b/coderd/database/dump.sql index a01ddb8d1f..11f668d2fc 100644 --- a/coderd/database/dump.sql +++ b/coderd/database/dump.sql @@ -1055,7 +1055,8 @@ CREATE TABLE aibridge_interceptions ( provider text NOT NULL, model text NOT NULL, started_at timestamp with time zone NOT NULL, - metadata jsonb + metadata jsonb, + ended_at timestamp with time zone ); COMMENT ON TABLE aibridge_interceptions IS 'Audit log of requests intercepted by AI Bridge'; diff --git a/coderd/database/migrations/000386_aibridge_interceptions_ended_at.down.sql b/coderd/database/migrations/000386_aibridge_interceptions_ended_at.down.sql new file mode 100644 index 0000000000..f578deb23c --- /dev/null +++ b/coderd/database/migrations/000386_aibridge_interceptions_ended_at.down.sql @@ -0,0 +1 @@ +ALTER TABLE aibridge_interceptions DROP COLUMN ended_at; diff --git a/coderd/database/migrations/000386_aibridge_interceptions_ended_at.up.sql b/coderd/database/migrations/000386_aibridge_interceptions_ended_at.up.sql new file mode 100644 index 0000000000..e4cca7e5a5 --- /dev/null +++ b/coderd/database/migrations/000386_aibridge_interceptions_ended_at.up.sql @@ -0,0 +1 @@ +ALTER TABLE aibridge_interceptions ADD COLUMN ended_at TIMESTAMP WITH TIME ZONE DEFAULT NULL; diff --git a/coderd/database/modelqueries.go b/coderd/database/modelqueries.go index 1400893a26..c9c7879627 100644 --- a/coderd/database/modelqueries.go +++ b/coderd/database/modelqueries.go @@ -804,6 +804,7 @@ func (q *sqlQuerier) ListAuthorizedAIBridgeInterceptions(ctx context.Context, ar &i.AIBridgeInterception.Model, &i.AIBridgeInterception.StartedAt, &i.AIBridgeInterception.Metadata, + &i.AIBridgeInterception.EndedAt, &i.VisibleUser.ID, &i.VisibleUser.Username, &i.VisibleUser.Name, diff --git a/coderd/database/models.go b/coderd/database/models.go index 2d02d2c14d..fe9b04755b 100644 --- a/coderd/database/models.go +++ b/coderd/database/models.go @@ -3613,6 +3613,7 @@ type AIBridgeInterception struct { Model string `db:"model" json:"model"` StartedAt time.Time `db:"started_at" json:"started_at"` Metadata pqtype.NullRawMessage `db:"metadata" json:"metadata"` + EndedAt sql.NullTime `db:"ended_at" json:"ended_at"` } // Audit log of tokens used by intercepted requests in AI Bridge diff --git a/coderd/database/queries.sql.go b/coderd/database/queries.sql.go index 5b4cf7b21e..524394c1e2 100644 --- a/coderd/database/queries.sql.go +++ b/coderd/database/queries.sql.go @@ -168,7 +168,7 @@ func (q *sqlQuerier) CountAIBridgeInterceptions(ctx context.Context, arg CountAI const getAIBridgeInterceptionByID = `-- name: GetAIBridgeInterceptionByID :one SELECT - id, initiator_id, provider, model, started_at, metadata + id, initiator_id, provider, model, started_at, metadata, ended_at FROM aibridge_interceptions WHERE @@ -185,13 +185,14 @@ func (q *sqlQuerier) GetAIBridgeInterceptionByID(ctx context.Context, id uuid.UU &i.Model, &i.StartedAt, &i.Metadata, + &i.EndedAt, ) return i, err } const getAIBridgeInterceptions = `-- name: GetAIBridgeInterceptions :many SELECT - id, initiator_id, provider, model, started_at, metadata + id, initiator_id, provider, model, started_at, metadata, ended_at FROM aibridge_interceptions ` @@ -212,6 +213,7 @@ func (q *sqlQuerier) GetAIBridgeInterceptions(ctx context.Context) ([]AIBridgeIn &i.Model, &i.StartedAt, &i.Metadata, + &i.EndedAt, ); err != nil { return nil, err } @@ -361,7 +363,7 @@ INSERT INTO aibridge_interceptions ( ) VALUES ( $1, $2, $3, $4, COALESCE($5::jsonb, '{}'::jsonb), $6 ) -RETURNING id, initiator_id, provider, model, started_at, metadata +RETURNING id, initiator_id, provider, model, started_at, metadata, ended_at ` type InsertAIBridgeInterceptionParams struct { @@ -390,6 +392,7 @@ func (q *sqlQuerier) InsertAIBridgeInterception(ctx context.Context, arg InsertA &i.Model, &i.StartedAt, &i.Metadata, + &i.EndedAt, ) return i, err } @@ -528,7 +531,7 @@ func (q *sqlQuerier) InsertAIBridgeUserPrompt(ctx context.Context, arg InsertAIB const listAIBridgeInterceptions = `-- name: ListAIBridgeInterceptions :many SELECT - aibridge_interceptions.id, aibridge_interceptions.initiator_id, aibridge_interceptions.provider, aibridge_interceptions.model, aibridge_interceptions.started_at, aibridge_interceptions.metadata, + aibridge_interceptions.id, aibridge_interceptions.initiator_id, aibridge_interceptions.provider, aibridge_interceptions.model, aibridge_interceptions.started_at, aibridge_interceptions.metadata, aibridge_interceptions.ended_at, visible_users.id, visible_users.username, visible_users.name, visible_users.avatar_url FROM aibridge_interceptions @@ -625,6 +628,7 @@ func (q *sqlQuerier) ListAIBridgeInterceptions(ctx context.Context, arg ListAIBr &i.AIBridgeInterception.Model, &i.AIBridgeInterception.StartedAt, &i.AIBridgeInterception.Metadata, + &i.AIBridgeInterception.EndedAt, &i.VisibleUser.ID, &i.VisibleUser.Username, &i.VisibleUser.Name,