Skip to content

Commit 603b292

Browse files
committed
Address skill analytics feedback follow-ups
1 parent 7f5245e commit 603b292

2 files changed

Lines changed: 8 additions & 39 deletions

File tree

packages/web/src/ee/features/chat/skills/actions.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -970,15 +970,14 @@ export const deletePersonalAgentSkill = async (
970970
}
971971

972972
refreshSkillSettingsViews();
973-
void captureEvent('ask_skill_deleted', {
973+
emitSkillEvent('ask_skill_deleted', {
974974
source: SKILL_ANALYTICS_SOURCE,
975975
entryPoint: getSkillAnalyticsEntryPoint(analytics),
976976
scope: 'personal',
977977
isSynced: isSyncedSkill(skill),
978978
skillIdHash: hashSkillId(skill.id),
979979
actorRelationship: 'creator',
980-
success: true,
981-
});
980+
}, { success: true });
982981
return { success: true };
983982
}));
984983

@@ -1446,15 +1445,14 @@ export const deleteSharedAgentSkill = async (
14461445
});
14471446

14481447
refreshSkillSettingsViews();
1449-
void captureEvent('ask_skill_deleted', {
1448+
emitSkillEvent('ask_skill_deleted', {
14501449
source: SKILL_ANALYTICS_SOURCE,
14511450
entryPoint: getSkillAnalyticsEntryPoint(analytics),
14521451
scope: 'shared',
14531452
isSynced: isSyncedSkill(existingSkill),
14541453
skillIdHash: hashSkillId(existingSkill.id),
14551454
actorRelationship: getSharedSkillActorRelationship(existingSkill, user.id, role),
1456-
success: true,
1457-
});
1455+
}, { success: true });
14581456
return { success: true };
14591457
}));
14601458

packages/web/src/ee/features/chat/skills/skillAnalytics.server.ts

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
sharedAgentSkillVisibleToUserWhere,
1010
type PrismaClient,
1111
} from "@sourcebot/db";
12+
import { filterSkillsBySourceRepoAccess } from "./sourceRepoAccess";
1213

1314
export type AskSkillAvailabilityAnalytics = {
1415
availableSkillCount: number;
@@ -30,36 +31,6 @@ const emptyAskSkillAvailability: AskSkillAvailabilityAnalytics = {
3031
};
3132

3233
type 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

6435
export 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

Comments
 (0)