mirror of
https://github.com/coder/coder.git
synced 2026-09-23 05:43:53 +08:00
Adds `ai` to sqlc's `gen.go.initialisms` in `coderd/database/sqlc.yaml` so the generated DB code follows Go's initialism convention. Adds the matching `ai` -> `AI` case to the dbgen PascalCase helper (`scripts/dbgen/main.go`) so the corresponding `dbmem` / mock identifiers stay in sync. `make gen` regenerates the rest; hand-written call sites that consume DB-generated identifiers (`enterprise/audit/table.go`, `coderd/database/modelmethods.go`, `enterprise/coderd/aigatewaykeys.go`, `coderd/database/dbauthz/*`, etc.) are updated to match. Scope is deliberately limited to the database layer: - `coderd/rbac/*` (resource and scope generators) is untouched — `ResourceAi*` / `ScopeAi*` constants stay on main's casing. - `codersdk/*` (Go SDK) is untouched — `codersdk.ResourceAi*` / `codersdk.APIKeyScopeAi*` constants stay on main's casing, so external Go SDK consumers see no source-level break. - `Aibridge*` identifiers (one SQL token `aibridge`, not `ai_bridge`) are out of scope. On-the-wire values are unchanged: enum strings, RBAC resource type strings, API key scope strings, and JSON tags all stay the same. The HTTP/JSON surface is unaffected. Refs: [AIGOV-369](https://linear.app/codercom/issue/AIGOV-369/change-ai-references-in-coderddatabasemodelsgo-to-ai) 🤖 Generated with [Coder Agents](https://coder.com)
39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
// Package aiseats is the AGPL version the package.
|
|
// The actual implementation is in `enterprise/aiseats`.
|
|
package aiseats
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"github.com/coder/coder/v2/coderd/database"
|
|
)
|
|
|
|
type Reason struct {
|
|
EventType database.AISeatUsageReason
|
|
Description string
|
|
}
|
|
|
|
// ReasonAIBridge constructs a reason for usage originating from AI Bridge.
|
|
func ReasonAIBridge(description string) Reason {
|
|
return Reason{EventType: database.AISeatUsageReasonAibridge, Description: description}
|
|
}
|
|
|
|
// ReasonTask constructs a reason for usage originating from tasks.
|
|
func ReasonTask(description string) Reason {
|
|
return Reason{EventType: database.AISeatUsageReasonTask, Description: description}
|
|
}
|
|
|
|
// SeatTracker records AI seat consumption state.
|
|
type SeatTracker interface {
|
|
// RecordUsage does not return an error to prevent blocking the user from using
|
|
// AI features. This method is used to record usage, not enforce it.
|
|
RecordUsage(ctx context.Context, userID uuid.UUID, reason Reason)
|
|
}
|
|
|
|
// Noop is an AGPL seat tracker that does nothing.
|
|
type Noop struct{}
|
|
|
|
func (Noop) RecordUsage(context.Context, uuid.UUID, Reason) {}
|