diff --git a/products/skills/frontend/LLMSkillScene.stories.tsx b/products/skills/frontend/LLMSkillScene.stories.tsx index a9dc3c8ae1df4..d03dd6aa10b50 100644 --- a/products/skills/frontend/LLMSkillScene.stories.tsx +++ b/products/skills/frontend/LLMSkillScene.stories.tsx @@ -67,6 +67,8 @@ const SKILL: LLMSkillApi = { allowed_tools: ['read', 'shell'], metadata: {}, category: '', + is_global: false, + team_id: 1, files: [ { path: 'scripts/extract.sh', content_type: 'text/x-shellscript' }, { path: 'references/pdf-spec.md', content_type: 'text/markdown' }, @@ -103,6 +105,8 @@ const SKILL_LIST_ENTRY: LLMSkillListApi = { allowed_tools: SKILL.allowed_tools, metadata: {}, category: SKILL.category, + is_global: SKILL.is_global, + team_id: SKILL.team_id, outline: SKILL.outline, version: SKILL.version, created_by: SKILL.created_by, diff --git a/products/skills/frontend/LLMSkillScene.tsx b/products/skills/frontend/LLMSkillScene.tsx index 642d1298ba2bf..ee57765697cf3 100644 --- a/products/skills/frontend/LLMSkillScene.tsx +++ b/products/skills/frontend/LLMSkillScene.tsx @@ -8,6 +8,7 @@ import { IconColumns, IconDocument, IconDownload, + IconGlobe, IconPencil, IconPlus, IconTrash, @@ -27,7 +28,9 @@ import { LemonSkeleton } from 'lib/lemon-ui/LemonSkeleton' import { copyToClipboard } from 'lib/utils/copyToClipboard' import { lazyWithRetry } from 'lib/utils/retryImport' import { SceneExport } from 'scenes/sceneTypes' +import { teamLogic } from 'scenes/teamLogic' import { urls } from 'scenes/urls' +import { userLogic } from 'scenes/userLogic' import { themeLogic } from '~/layout/navigation-3000/themeLogic' import { SceneContent } from '~/layout/scenes/components/SceneContent' @@ -42,7 +45,7 @@ import type { SkillFormFileValues } from './llmSkillLogic' import { SkillLogicProps, SkillMode, isSkill, llmSkillLogic } from './llmSkillLogic' import { SKILL_NAME_MAX_LENGTH, SKILL_DESCRIPTION_MAX_LENGTH } from './skillConstants' import { skillFileLogic } from './skillFileLogic' -import { openArchiveSkillDialog } from './skillSceneComponents' +import { openArchiveSkillDialog, openSkillVisibilityDialog } from './skillSceneComponents' const MonacoDiffEditor = lazyWithRetry(() => import('lib/components/MonacoDiffEditor')) @@ -73,11 +76,26 @@ export function LLMSkillScene(): JSX.Element { canLoadMoreVersions, fileContentsLoading, downloadingZip, + settingVisibility, } = useValues(llmSkillLogic) const { searchParams } = useValues(router) + const { user } = useValues(userLogic) + const { currentTeamId } = useValues(teamLogic) - const { submitSkillForm, deleteSkill, setMode, setSkillFormValues, loadMoreVersions, downloadSkill } = - useActions(llmSkillLogic) + const { + submitSkillForm, + deleteSkill, + setMode, + setSkillFormValues, + loadMoreVersions, + downloadSkill, + setGlobalVisibility, + } = useActions(llmSkillLogic) + + // A global skill surfaced from another team is read-only here — only its owning project can + // edit it, and only staff can change its visibility (and only from the owning project). + const isOwnedByCurrentTeam = isSkill(skill) && skill.team_id === currentTeamId + const canManageVisibility = !!user?.is_staff && isOwnedByCurrentTeam if (isSkillMissing) { return @@ -99,49 +117,57 @@ export function LLMSkillScene(): JSX.Element { name={skill && 'name' in skill ? skill.name : 'Skill'} resourceType={{ type: 'llm_analytics' }} isLoading={skillLoading} + nameSuffix={ + isSkill(skill) && skill.is_global ? ( + } size="medium"> + Global + + ) : undefined + } actions={ <> - {isSkill(skill) && skill.is_latest ? ( - - } - onClick={() => setMode(SkillMode.Edit)} - size="small" - data-attr="llma-skill-edit-button" + {isOwnedByCurrentTeam && + (isSkill(skill) && skill.is_latest ? ( + - Edit latest - - - ) : ( - - { - if (isSkill(skill)) { - setSkillFormValues({ - name: skill.name, - description: skill.description, - body: skill.body, - license: skill.license || '', - compatibility: skill.compatibility || '', - }) - setMode(SkillMode.Edit) - } - }} - size="small" - data-attr="llma-skill-use-as-latest-button" + } + onClick={() => setMode(SkillMode.Edit)} + size="small" + data-attr="llma-skill-edit-button" + > + Edit latest + + + ) : ( + - Use as latest - - - )} + { + if (isSkill(skill)) { + setSkillFormValues({ + name: skill.name, + description: skill.description, + body: skill.body, + license: skill.license || '', + compatibility: skill.compatibility || '', + }) + setMode(SkillMode.Edit) + } + }} + size="small" + data-attr="llma-skill-use-as-latest-button" + > + Use as latest + + + ))} {isSkill(skill) && ( )} - + {canManageVisibility && isSkill(skill) && ( } - onClick={() => openArchiveSkillDialog(deleteSkill)} + icon={} + onClick={() => + openSkillVisibilityDialog(!skill.is_global, () => + setGlobalVisibility(!skill.is_global) + ) + } + loading={settingVisibility} size="small" - data-attr="llma-skill-delete-button" + tooltip={ + skill.is_global + ? 'Restrict this skill to this project' + : 'Make this skill visible to every PostHog customer' + } + data-attr="llma-skill-visibility-button" > - Archive + {skill.is_global ? 'Make private' : 'Make visible to everyone'} - + )} + + {isOwnedByCurrentTeam && ( + + } + onClick={() => openArchiveSkillDialog(deleteSkill)} + size="small" + data-attr="llma-skill-delete-button" + > + Archive + + + )} } /> diff --git a/products/skills/frontend/LLMSkillsScene.tsx b/products/skills/frontend/LLMSkillsScene.tsx index f1fc76fbcc736..e1237906321ea 100644 --- a/products/skills/frontend/LLMSkillsScene.tsx +++ b/products/skills/frontend/LLMSkillsScene.tsx @@ -2,7 +2,7 @@ import { useActions, useValues } from 'kea' import { combineUrl, router } from 'kea-router' import { useMemo, useRef } from 'react' -import { IconDownload, IconPlusSmall, IconUpload } from '@posthog/icons' +import { IconDownload, IconGlobe, IconPlusSmall, IconUpload } from '@posthog/icons' import { LemonDivider, LemonModal, LemonSwitch, LemonTabs, LemonTag, Link } from '@posthog/lemon-ui' import { AccessControlAction } from 'lib/components/AccessControlAction' @@ -16,6 +16,7 @@ import { LemonCollapse } from 'lib/lemon-ui/LemonCollapse' import { ProfilePicture } from 'lib/lemon-ui/ProfilePicture' import { Spinner } from 'lib/lemon-ui/Spinner' import { SceneExport } from 'scenes/sceneTypes' +import { teamLogic } from 'scenes/teamLogic' import { urls } from 'scenes/urls' import { SceneContent } from '~/layout/scenes/components/SceneContent' @@ -61,6 +62,7 @@ function buildSkillColumns( duplicateSkill: (name: string, newName: string) => void, deleteSkill: (name: string) => void, downloadSkillZip: (name: string) => void, + currentTeamId: number | null, options?: { showScoutOrigin?: boolean } ): LemonTableColumns { return [ @@ -71,9 +73,16 @@ function buildSkillColumns( width: '20%', render: function renderName(_, skill) { return ( - - {skill.name} - +
+ + {skill.name} + + {skill.is_global && ( + }> + Global + + )} +
) }, }, @@ -150,55 +159,61 @@ function buildSkillColumns( Download .zip
- - { - LemonDialog.openForm({ - title: 'Duplicate skill', - initialValues: { - newName: `${skill.name}-copy`, - }, - content: ( - - - - ), - errors: { - newName: (name: string) => validateSkillName(name), - }, - onSubmit: async ({ newName }) => { - duplicateSkill(skill.name, newName) - }, - }) - }} - data-attr="llma-skill-dropdown-duplicate" - fullWidth - > - Duplicate - - - - - openArchiveSkillDialog(() => deleteSkill(skill.name))} - data-attr="llma-skill-dropdown-delete" - fullWidth - > - Archive - - + {/* Duplicate and archive act on the owning team's skill, so a global surfaced + from another team is view/download-only here. */} + {skill.team_id === currentTeamId && ( + <> + + { + LemonDialog.openForm({ + title: 'Duplicate skill', + initialValues: { + newName: `${skill.name}-copy`, + }, + content: ( + + + + ), + errors: { + newName: (name: string) => validateSkillName(name), + }, + onSubmit: async ({ newName }) => { + duplicateSkill(skill.name, newName) + }, + }) + }} + data-attr="llma-skill-dropdown-duplicate" + fullWidth + > + Duplicate + + + + + openArchiveSkillDialog(() => deleteSkill(skill.name))} + data-attr="llma-skill-dropdown-delete" + fullWidth + > + Archive + + + + )} } /> @@ -443,6 +458,7 @@ export function LLMSkillsScene(): JSX.Element { visibleCategoryTabs, } = useValues(llmSkillsLogic) const { searchParams } = useValues(router) + const { currentTeamId } = useValues(teamLogic) const skillUrl = (name: string): string => combineUrl(urls.skill(name), searchParams).url const fileInputRef = useRef(null) @@ -451,9 +467,12 @@ export function LLMSkillsScene(): JSX.Element { // Memoize columns so the array reference doesn't change every render — otherwise every // nested LemonTable inside the grouped tree reconciles on each parent re-render. const columns = useMemo( - () => buildSkillColumns(skillUrl, duplicateSkill, deleteSkill, downloadSkillZip, { showScoutOrigin }), + () => + buildSkillColumns(skillUrl, duplicateSkill, deleteSkill, downloadSkillZip, currentTeamId, { + showScoutOrigin, + }), // eslint-disable-next-line react-hooks/exhaustive-deps - [searchParams, duplicateSkill, deleteSkill, downloadSkillZip, showScoutOrigin] + [searchParams, duplicateSkill, deleteSkill, downloadSkillZip, currentTeamId, showScoutOrigin] ) const showGroupedView = filters.group_by_prefix && groupedSkills && !skillsLoading diff --git a/products/skills/frontend/llmSkillLogic.ts b/products/skills/frontend/llmSkillLogic.ts index 62b1449a7eb3b..bb9ccb4dc8507 100644 --- a/products/skills/frontend/llmSkillLogic.ts +++ b/products/skills/frontend/llmSkillLogic.ts @@ -13,6 +13,7 @@ import { llmSkillsNameArchiveCreate, llmSkillsNameFilesRetrieve, llmSkillsNamePartialUpdate, + llmSkillsNameVisibilityCreate, llmSkillsResolveNameRetrieve, } from 'products/skills/frontend/generated/api' import type { @@ -137,6 +138,8 @@ export const llmSkillLogic = kea([ setCompareVersion: (compareVersion: number | null) => ({ compareVersion }), downloadSkill: true, setDownloadingZip: (downloadingZip: boolean) => ({ downloadingZip }), + setGlobalVisibility: (isGlobal: boolean) => ({ isGlobal }), + setSettingVisibility: (settingVisibility: boolean) => ({ settingVisibility }), }), reducers(({ props }) => ({ @@ -201,6 +204,12 @@ export const llmSkillLogic = kea([ setDownloadingZip: (_, { downloadingZip }) => downloadingZip, }, ], + settingVisibility: [ + false, + { + setSettingVisibility: (_, { settingVisibility }) => settingVisibility, + }, + ], })), loaders(({ props }) => ({ @@ -424,6 +433,34 @@ export const llmSkillLogic = kea([ } }, + setGlobalVisibility: async ({ isGlobal }) => { + const skill = values.skill + if (props.skillName === 'new' || !isSkill(skill)) { + return + } + actions.setSettingVisibility(true) + try { + const updated = await llmSkillsNameVisibilityCreate(String(ApiConfig.getCurrentTeamId()), skill.name, { + is_global: isGlobal, + }) + const current = values.skill + if (isSkill(current)) { + actions.setSkill({ ...current, is_global: updated.is_global }) + } + lemonToast.success( + isGlobal ? 'Skill is now visible to everyone.' : 'Skill is now private to this project.' + ) + llmSkillsLogic.findMounted()?.actions.loadSkills(false) + } catch (e) { + console.error('Failed to update skill visibility', e) + const detail = + e !== null && typeof e === 'object' && 'detail' in e ? (e as { detail?: string }).detail : undefined + lemonToast.error(detail || 'Failed to update skill visibility') + } finally { + actions.setSettingVisibility(false) + } + }, + deleteSkill: async () => { if (props.skillName !== 'new' && values.skill && isSkill(values.skill)) { try { diff --git a/products/skills/frontend/skillSceneComponents.tsx b/products/skills/frontend/skillSceneComponents.tsx index f1ee60021cbfc..733798abda54b 100644 --- a/products/skills/frontend/skillSceneComponents.tsx +++ b/products/skills/frontend/skillSceneComponents.tsx @@ -11,3 +11,23 @@ export function openArchiveSkillDialog(onConfirm: () => void): void { secondaryButton: { children: 'Cancel' }, }) } + +export function openSkillVisibilityDialog(isGlobal: boolean, onConfirm: () => void): void { + LemonDialog.open( + isGlobal + ? { + title: 'Make this skill visible to everyone?', + description: + 'Every PostHog customer will be able to see and use this skill in their own projects. ' + + 'Only PostHog staff can do this.', + primaryButton: { children: 'Make visible to everyone', onClick: onConfirm }, + secondaryButton: { children: 'Cancel' }, + } + : { + title: 'Make this skill private?', + description: "It will stop appearing in other customers' projects and go back to this project only.", + primaryButton: { children: 'Make private', onClick: onConfirm }, + secondaryButton: { children: 'Cancel' }, + } + ) +}