2
0
Files
gitcaddy-server/modules/ai/types.go
logikonline f42c6c39f9
All checks were successful
Build and Release / Create Release (push) Has been skipped
Build and Release / Unit Tests (push) Successful in 6m49s
Build and Release / Integration Tests (PostgreSQL) (push) Successful in 7m6s
Build and Release / Lint (push) Successful in 7m15s
Build and Release / Build Binaries (amd64, windows, windows-latest) (push) Has been skipped
Build and Release / Build Binaries (amd64, darwin, macos) (push) Has been skipped
Build and Release / Build Binaries (amd64, linux, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (arm64, darwin, macos) (push) Has been skipped
Build and Release / Build Binary (linux/arm64) (push) Has been skipped
feat(ai-service): complete ai production readiness tasks
Implement critical production readiness features for AI integration: per-request provider config, admin dashboard, workflow inspection, and plugin framework foundation.

Per-Request Provider Config:
- Add ProviderConfig struct to all AI request types
- Update queue to resolve provider/model/API key from cascade (repo > org > system)
- Pass resolved config to AI sidecar on every request
- Fixes multi-tenant issue where all orgs shared sidecar's hardcoded config

Admin AI Dashboard:
- Add /admin/ai page with sidecar health status
- Display global operation stats (total, 24h, success/fail/escalated counts)
- Show operations by tier, top 5 repos, token usage
- Recent operations table with repo, operation, status, duration
- Add GetGlobalOperationStats model method

Workflow Inspection:
- Add InspectWorkflow client method and types
- Implement workflow-inspect queue handler
- Add notifier trigger on workflow file push
- Analyzes YAML for syntax errors, security issues, best practices
- Returns structured issues with line numbers and suggested fixes

Plugin Framework (Phase 5 Foundation):
- Add external plugin config loading from app.ini
- Define ExternalPlugin interface and manager
- Add plugin.proto contract (Initialize, Shutdown, HealthCheck, OnEvent, HandleHTTP)
- Implement health monitoring with auto-restart for managed plugins
- Add event routing to subscribed plugins
- HTTP proxy support for plugin-served routes

This completes Tasks 1-4 from the production readiness plan and establishes the foundation for managed plugin lifecycle.
2026-02-13 01:16:58 -05:00

278 lines
11 KiB
Go

// Copyright 2026 MarketAlly. All rights reserved.
// SPDX-License-Identifier: MIT
package ai
// ProviderConfig contains per-request AI provider configuration.
// When sent to the AI sidecar, it overrides the sidecar's default provider/model/key.
// Fields left empty fall back to the sidecar's defaults.
type ProviderConfig struct {
Provider string `json:"provider,omitempty"` // "claude", "openai", "gemini"
Model string `json:"model,omitempty"`
APIKey string `json:"api_key,omitempty"`
}
// FileDiff represents a file diff for code review
type FileDiff struct {
Path string `json:"path"`
OldPath string `json:"old_path,omitempty"`
Status string `json:"status"` // added, modified, deleted, renamed
Patch string `json:"patch"`
Content string `json:"content,omitempty"`
Language string `json:"language,omitempty"`
}
// ReviewOptions contains options for code review
type ReviewOptions struct {
CheckSecurity bool `json:"check_security"`
CheckPerformance bool `json:"check_performance"`
CheckStyle bool `json:"check_style"`
CheckTests bool `json:"check_tests"`
SuggestImprovements bool `json:"suggest_improvements"`
FocusAreas string `json:"focus_areas,omitempty"`
LanguageHints string `json:"language_hints,omitempty"`
}
// ReviewComment represents a code review comment
type ReviewComment struct {
Path string `json:"path"`
Line int `json:"line"`
EndLine int `json:"end_line,omitempty"`
Body string `json:"body"`
Severity string `json:"severity"` // info, warning, error, critical
Category string `json:"category"` // security, performance, style, bug
SuggestedFix string `json:"suggested_fix,omitempty"`
}
// SecurityIssue represents a security issue found during review
type SecurityIssue struct {
Path string `json:"path"`
Line int `json:"line"`
IssueType string `json:"issue_type"`
Description string `json:"description"`
Severity string `json:"severity"`
Remediation string `json:"remediation"`
}
// SecurityAnalysis contains security analysis results
type SecurityAnalysis struct {
Issues []SecurityIssue `json:"issues"`
RiskScore int `json:"risk_score"`
Summary string `json:"summary"`
}
// ReviewPullRequestRequest is the request for reviewing a pull request
type ReviewPullRequestRequest struct {
ProviderConfig *ProviderConfig `json:"provider_config,omitempty"`
RepoID int64 `json:"repo_id"`
PullRequestID int64 `json:"pull_request_id"`
BaseBranch string `json:"base_branch"`
HeadBranch string `json:"head_branch"`
Files []FileDiff `json:"files"`
PRTitle string `json:"pr_title"`
PRDescription string `json:"pr_description"`
Options ReviewOptions `json:"options"`
}
// ReviewPullRequestResponse is the response from reviewing a pull request
type ReviewPullRequestResponse struct {
Summary string `json:"summary"`
Comments []ReviewComment `json:"comments"`
Verdict string `json:"verdict"` // approve, request_changes, comment
Suggestions []string `json:"suggestions"`
Security SecurityAnalysis `json:"security"`
EstimatedReviewMinutes int `json:"estimated_review_minutes"`
}
// TriageIssueRequest is the request for triaging an issue
type TriageIssueRequest struct {
ProviderConfig *ProviderConfig `json:"provider_config,omitempty"`
RepoID int64 `json:"repo_id"`
IssueID int64 `json:"issue_id"`
Title string `json:"title"`
Body string `json:"body"`
ExistingLabels []string `json:"existing_labels"`
AvailableLabels []string `json:"available_labels"`
}
// TriageIssueResponse is the response from triaging an issue
type TriageIssueResponse struct {
Priority string `json:"priority"` // critical, high, medium, low
Category string `json:"category"` // bug, feature, question, docs
SuggestedLabels []string `json:"suggested_labels"`
SuggestedAssignees []string `json:"suggested_assignees"`
Summary string `json:"summary"`
IsDuplicate bool `json:"is_duplicate"`
DuplicateOf int64 `json:"duplicate_of,omitempty"`
}
// SuggestLabelsRequest is the request for suggesting labels
type SuggestLabelsRequest struct {
ProviderConfig *ProviderConfig `json:"provider_config,omitempty"`
RepoID int64 `json:"repo_id"`
Title string `json:"title"`
Body string `json:"body"`
AvailableLabels []string `json:"available_labels"`
}
// LabelSuggestion represents a suggested label
type LabelSuggestion struct {
Label string `json:"label"`
Confidence float32 `json:"confidence"`
Reason string `json:"reason"`
}
// SuggestLabelsResponse is the response from suggesting labels
type SuggestLabelsResponse struct {
Suggestions []LabelSuggestion `json:"suggestions"`
}
// ExplainCodeRequest is the request for explaining code
type ExplainCodeRequest struct {
ProviderConfig *ProviderConfig `json:"provider_config,omitempty"`
RepoID int64 `json:"repo_id"`
FilePath string `json:"file_path"`
Code string `json:"code"`
StartLine int `json:"start_line"`
EndLine int `json:"end_line"`
Question string `json:"question,omitempty"`
}
// CodeReference represents a reference to related documentation
type CodeReference struct {
Description string `json:"description"`
URL string `json:"url"`
}
// ExplainCodeResponse is the response from explaining code
type ExplainCodeResponse struct {
Explanation string `json:"explanation"`
KeyConcepts []string `json:"key_concepts"`
References []CodeReference `json:"references"`
}
// GenerateDocumentationRequest is the request for generating documentation
type GenerateDocumentationRequest struct {
ProviderConfig *ProviderConfig `json:"provider_config,omitempty"`
RepoID int64 `json:"repo_id"`
FilePath string `json:"file_path"`
Code string `json:"code"`
DocType string `json:"doc_type"` // function, class, module, api
Language string `json:"language"`
Style string `json:"style"` // jsdoc, docstring, xml, markdown
}
// DocumentationSection represents a section of documentation
type DocumentationSection struct {
Title string `json:"title"`
Content string `json:"content"`
}
// GenerateDocumentationResponse is the response from generating documentation
type GenerateDocumentationResponse struct {
Documentation string `json:"documentation"`
Sections []DocumentationSection `json:"sections"`
}
// GenerateCommitMessageRequest is the request for generating a commit message
type GenerateCommitMessageRequest struct {
ProviderConfig *ProviderConfig `json:"provider_config,omitempty"`
RepoID int64 `json:"repo_id"`
Files []FileDiff `json:"files"`
Style string `json:"style"` // conventional, descriptive, brief
}
// GenerateCommitMessageResponse is the response from generating a commit message
type GenerateCommitMessageResponse struct {
Message string `json:"message"`
Alternatives []string `json:"alternatives"`
}
// SummarizeChangesRequest is the request for summarizing changes
type SummarizeChangesRequest struct {
ProviderConfig *ProviderConfig `json:"provider_config,omitempty"`
RepoID int64 `json:"repo_id"`
Files []FileDiff `json:"files"`
Context string `json:"context"`
}
// SummarizeChangesResponse is the response from summarizing changes
type SummarizeChangesResponse struct {
Summary string `json:"summary"`
BulletPoints []string `json:"bullet_points"`
ImpactAssessment string `json:"impact_assessment"`
}
// IssueComment represents a comment on an issue for AI context
type IssueComment struct {
Author string `json:"author"`
Body string `json:"body"`
CreatedAt string `json:"created_at,omitempty"`
}
// GenerateIssueResponseRequest is the request for generating an AI response to an issue
type GenerateIssueResponseRequest struct {
ProviderConfig *ProviderConfig `json:"provider_config,omitempty"`
RepoID int64 `json:"repo_id"`
IssueID int64 `json:"issue_id"`
Title string `json:"title"`
Body string `json:"body"`
Comments []IssueComment `json:"comments,omitempty"`
ResponseType string `json:"response_type,omitempty"` // clarification, solution, acknowledgment
CustomInstructions string `json:"custom_instructions,omitempty"`
}
// GenerateIssueResponseResponse is the response from generating an issue response
type GenerateIssueResponseResponse struct {
Response string `json:"response"`
FollowUpQuestions []string `json:"follow_up_questions,omitempty"`
Confidence float64 `json:"confidence"`
InputTokens int `json:"input_tokens"`
OutputTokens int `json:"output_tokens"`
}
// InspectWorkflowRequest is the request for inspecting a workflow file
type InspectWorkflowRequest struct {
ProviderConfig *ProviderConfig `json:"provider_config,omitempty"`
RepoID int64 `json:"repo_id"`
FilePath string `json:"file_path"`
Content string `json:"content"`
RunnerLabels []string `json:"runner_labels,omitempty"`
}
// WorkflowIssue represents an issue found in a workflow file
type WorkflowIssue struct {
Line int `json:"line"`
Severity string `json:"severity"` // "error", "warning", "info"
Message string `json:"message"`
Fix string `json:"fix,omitempty"`
}
// InspectWorkflowResponse is the response from inspecting a workflow file
type InspectWorkflowResponse struct {
Valid bool `json:"valid"`
Issues []WorkflowIssue `json:"issues"`
Suggestions []string `json:"suggestions"`
Confidence float64 `json:"confidence"`
InputTokens int `json:"input_tokens"`
OutputTokens int `json:"output_tokens"`
}
// HealthCheckResponse is the response from a health check
type HealthCheckResponse struct {
Healthy bool `json:"healthy"`
Version string `json:"version"`
ProviderStatus map[string]string `json:"provider_status"`
License *LicenseInfo `json:"license,omitempty"`
}
// LicenseInfo contains AI service license information
type LicenseInfo struct {
Tier string `json:"tier"`
Customer string `json:"customer"`
ExpiresAt string `json:"expires_at"`
Features []string `json:"features"`
SeatCount int `json:"seat_count"`
IsTrial bool `json:"is_trial"`
}