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.
34 lines
884 B
Go
34 lines
884 B
Go
// Copyright 2026 MarketAlly. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package ai
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"code.gitcaddy.com/server/v3/modules/graceful"
|
|
"code.gitcaddy.com/server/v3/modules/queue"
|
|
"code.gitcaddy.com/server/v3/modules/setting"
|
|
notify_service "code.gitcaddy.com/server/v3/services/notify"
|
|
)
|
|
|
|
var aiOperationQueue *queue.WorkerPoolQueue[*AIOperationRequest]
|
|
|
|
// Init initializes the AI service integration: queue and notifier.
|
|
func Init(ctx context.Context) error {
|
|
if !setting.AI.Enabled {
|
|
return nil
|
|
}
|
|
|
|
aiOperationQueue = queue.CreateUniqueQueue(graceful.GetManager().ShutdownContext(), "ai_operations", handleAIOperation)
|
|
if aiOperationQueue == nil {
|
|
return errors.New("unable to create ai_operations queue")
|
|
}
|
|
go graceful.GetManager().RunWithCancel(aiOperationQueue)
|
|
|
|
notify_service.RegisterNotifier(NewNotifier())
|
|
|
|
return nil
|
|
}
|