99 sharedAgentSkillVisibleToUserWhere ,
1010 type PrismaClient ,
1111} from "@sourcebot/db" ;
12+ import { filterSkillsBySourceRepoAccess } from "./sourceRepoAccess" ;
1213
1314export type AskSkillAvailabilityAnalytics = {
1415 availableSkillCount : number ;
@@ -30,36 +31,6 @@ const emptyAskSkillAvailability: AskSkillAvailabilityAnalytics = {
3031} ;
3132
3233type AskSkillAvailabilityPrismaClient = Pick < PrismaClient , "agentSkill" | "repo" > ;
33- type SkillAvailabilityRow = {
34- sourceRepoName : string | null ;
35- } ;
36-
37- const distinctSourceRepoNames = ( skills : SkillAvailabilityRow [ ] ) : string [ ] =>
38- [ ...new Set (
39- skills
40- . map ( ( skill ) => skill . sourceRepoName )
41- . filter ( ( name ) : name is string => typeof name === "string" && name . length > 0 ) ,
42- ) ] ;
43-
44- const countSkillsAccessibleBySourceRepo = async (
45- skills : SkillAvailabilityRow [ ] ,
46- { prisma, orgId } : { prisma : AskSkillAvailabilityPrismaClient ; orgId : number } ,
47- ) : Promise < number > => {
48- const repoNames = distinctSourceRepoNames ( skills ) ;
49- if ( repoNames . length === 0 ) {
50- return skills . length ;
51- }
52-
53- const visibleRepos = await prisma . repo . findMany ( {
54- where : { name : { in : repoNames } , orgId } ,
55- select : { name : true } ,
56- } ) ;
57- const visibleRepoNames = new Set ( visibleRepos . map ( ( repo ) => repo . name ) ) ;
58-
59- return skills . filter (
60- ( skill ) => ! skill . sourceRepoName || visibleRepoNames . has ( skill . sourceRepoName ) ,
61- ) . length ;
62- } ;
6334
6435export async function getAskSkillAvailabilityAnalytics ( {
6536 prisma,
@@ -89,12 +60,12 @@ export async function getAskSkillAvailabilityAnalytics({
8960 } ) ,
9061 ] ) ;
9162
92- const availableSkillCount = await countSkillsAccessibleBySourceRepo (
63+ const accessibleSkills = await filterSkillsBySourceRepoAccess (
9364 [ ...personalSkills , ...sharedSkills ] ,
94- { prisma, orgId } ,
65+ { prisma : prisma as PrismaClient , orgId } ,
9566 ) ;
9667
97- return { availableSkillCount } ;
68+ return { availableSkillCount : accessibleSkills . length } ;
9869 } catch {
9970 return emptyAskSkillAvailability ;
10071 }
0 commit comments