Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 129 additions & 0 deletions autobot-frontend/src/composables/analytics/useApiEndpointAnalysis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
// AutoBot - AI-Powered Automation Platform
// Copyright (c) 2025 mrveiss
// Author: mrveiss

/**
* Composable: useApiEndpointAnalysis
*
* API endpoint coverage scanning and endpoint group management.
* Extracted from useSpecializedAnalysis (Issue #2372).
*/

import { reactive } from 'vue'
import { fetchWithAuth } from '@/utils/fetchWithAuth'
import appConfig from '@/config/AppConfig.js'
import { useAnalyticsFetch } from '@/composables/useAnalyticsFetch'
import { createLogger } from '@/utils/debugUtils'
import type {
UseCodeIntelAnalysisDeps,
ApiEndpointAnalysisResult,
} from './codeIntelTypes'

const logger = createLogger('useApiEndpointAnalysis')

export function useApiEndpointAnalysis(
deps: UseCodeIntelAnalysisDeps,
) {
const { sourceIdQuery, withSourceId, t, notify } = deps

const {
data: apiEndpointAnalysis,
loading: loadingApiEndpoints,
error: apiEndpointsError,
load: _loadApiEndpoints,
} = useAnalyticsFetch<ApiEndpointAnalysisResult>(
'/api/analytics/codebase/endpoint-analysis',
(r) => {
if (r.status === 'success' && r.analysis) {
return r.analysis as unknown as ApiEndpointAnalysisResult
}
return undefined
},
)

const expandedApiEndpointGroups = reactive({
orphaned: false,
missing: false,
used: false,
})

const loadApiEndpointAnalysis = () =>
_loadApiEndpoints(sourceIdQuery.value)

const getApiEndpointCoverage = async () => {
loadingApiEndpoints.value = true
apiEndpointsError.value = ''
const startTime = Date.now()
try {
const backendUrl = await appConfig.getServiceUrl('backend')
const response = await fetchWithAuth(
withSourceId(
`${backendUrl}/api/analytics/codebase/endpoint-analysis`,
),
{
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
},
)
if (!response.ok) {
const errorText = await response.text()
throw new Error(`Status ${response.status}: ${errorText}`)
}
const data = await response.json()
const responseTime = Date.now() - startTime
if (data.status === 'success' && data.analysis) {
apiEndpointAnalysis.value = data.analysis
const coverage =
data.analysis.coverage_percentage?.toFixed(1) || 0
const orphaned = data.analysis.orphaned_endpoints || 0
const missing = data.analysis.missing_endpoints || 0
notify(
t('analytics.codebase.notify.apiCoverageResult', {
coverage,
orphaned,
missing,
time: responseTime,
}),
'success',
)
} else {
throw new Error('Invalid response format')
}
} catch (error: unknown) {
const responseTime = Date.now() - startTime
const errorMessage =
error instanceof Error ? error.message : String(error)
logger.error('API Endpoint analysis failed:', error)
apiEndpointsError.value = errorMessage
notify(
t('analytics.codebase.notify.apiAnalysisFailed', {
error: errorMessage,
time: responseTime,
}),
'error',
)
} finally {
loadingApiEndpoints.value = false
}
}

const getCoverageClass = (percentage: number): string => {
if (!percentage || percentage < 50) return 'critical'
if (percentage < 75) return 'warning'
if (percentage < 90) return 'info'
return 'success'
}

return {
apiEndpointAnalysis,
loadingApiEndpoints,
apiEndpointsError,
expandedApiEndpointGroups,
loadApiEndpointAnalysis,
getApiEndpointCoverage,
getCoverageClass,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// AutoBot - AI-Powered Automation Platform
// Copyright (c) 2025 mrveiss
// Author: mrveiss

/**
* Composable: useConfigDuplicates
*
* Configuration duplicate detection analysis.
* Extracted from useSpecializedAnalysis (Issue #2372).
*/

import { useAnalyticsFetch } from '@/composables/useAnalyticsFetch'
import type {
UseCodeIntelAnalysisDeps,
ConfigDuplicatesResult,
} from './codeIntelTypes'

export function useConfigDuplicates(
deps: UseCodeIntelAnalysisDeps,
) {
const { sourceIdQuery } = deps

const {
data: configDuplicatesAnalysis,
loading: loadingConfigDuplicates,
error: configDuplicatesError,
load: _loadConfigDuplicates,
} = useAnalyticsFetch<ConfigDuplicatesResult>(
'/api/analytics/codebase/config-duplicates',
(r) => {
if (r.status === 'success') {
return {
duplicates_found: (r.duplicates_found as number) || 0,
duplicates:
(r.duplicates as ConfigDuplicatesResult['duplicates']) ||
[],
report: (r.report as string) || '',
}
}
return undefined
},
)

const loadConfigDuplicates = () =>
_loadConfigDuplicates(sourceIdQuery.value)

return {
configDuplicatesAnalysis,
loadingConfigDuplicates,
configDuplicatesError,
loadConfigDuplicates,
}
}
Loading
Loading