2
0
Files
gitcaddy-server/models/user/user_system.go
logikonline 8ad6664b92 feat(ai): add ai service layer with agent and queue system
Implement core AI service infrastructure including agent operations, escalation handling, and asynchronous queue processing.

New services:
- Agent service: Handles Tier 2 AI operations with action runner integration
- Queue service: Asynchronous processing of AI operations with retry logic
- Escalation service: Routes complex issues to staff with configurable rules
- Notifier service: Sends notifications for AI operation results

Additional changes:
- Add GitCaddy AI system user (ID: -3) for bot operations
- Add AIConfig to repository units
- Add AI-specific error codes (rate limiting, service errors, etc.)
- Extend AI client with GenerateIssueResponse method
- Add AISettingsV2 struct for repository-level AI configuration

The queue system enables non-blocking AI operations with proper error handling and rate limiting.
2026-02-12 00:02:49 -05:00

110 lines
2.4 KiB
Go

// Copyright 2022 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package user
import (
"strings"
"code.gitcaddy.com/server/v3/modules/structs"
)
const (
GhostUserID int64 = -1
GhostUserName = "Ghost"
)
// NewGhostUser creates and returns a fake user for someone has deleted their account.
func NewGhostUser() *User {
return &User{
ID: GhostUserID,
Name: GhostUserName,
LowerName: strings.ToLower(GhostUserName),
}
}
func IsGhostUserName(name string) bool {
return strings.EqualFold(name, GhostUserName)
}
// IsGhost check if user is fake user for a deleted account
func (u *User) IsGhost() bool {
if u == nil {
return false
}
return u.ID == GhostUserID && u.Name == GhostUserName
}
const (
ActionsUserID int64 = -2
ActionsUserName = "gitea-actions"
ActionsUserEmail = "teabot@gitea.io"
)
func IsGiteaActionsUserName(name string) bool {
return strings.EqualFold(name, ActionsUserName)
}
// NewActionsUser creates and returns a fake user for running the actions.
func NewActionsUser() *User {
return &User{
ID: ActionsUserID,
Name: ActionsUserName,
LowerName: ActionsUserName,
IsActive: true,
FullName: "Gitea Actions",
Email: ActionsUserEmail,
KeepEmailPrivate: true,
LoginName: ActionsUserName,
Type: UserTypeBot,
Visibility: structs.VisibleTypePublic,
}
}
func (u *User) IsGiteaActions() bool {
return u != nil && u.ID == ActionsUserID
}
func GetSystemUserByName(name string) *User {
if IsGhostUserName(name) {
return NewGhostUser()
}
if IsGiteaActionsUserName(name) {
return NewActionsUser()
}
if IsAIUserName(name) {
return NewAIUser()
}
return nil
}
const (
AIUserID int64 = -3
AIUserName = "gitcaddy-ai"
AIUserEmail = "ai@gitcaddy.com"
)
func IsAIUserName(name string) bool {
return strings.EqualFold(name, AIUserName)
}
// NewAIUser creates and returns the system bot user for AI operations.
func NewAIUser() *User {
return &User{
ID: AIUserID,
Name: AIUserName,
LowerName: strings.ToLower(AIUserName),
IsActive: true,
FullName: "GitCaddy AI",
Email: AIUserEmail,
KeepEmailPrivate: true,
LoginName: AIUserName,
Type: UserTypeBot,
Visibility: structs.VisibleTypePublic,
}
}
func (u *User) IsAI() bool {
return u != nil && u.ID == AIUserID
}