-
Notifications
You must be signed in to change notification settings - Fork 61
Implement AI Skills Studio settings #2862
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+273
−1
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7e460a0
Add skills as first pass
dc59cc5
Fix linter
5a96684
Add removal option
2a563fe
Add header to avaible
f919905
Misc style fixes
41fbcf6
Styling
643f19d
Merge branch 'trunk' of github.com:Automattic/studio into add/skills-…
238a14c
Fix background
1630195
Fix badge in the dark mode
93c003a
Wrap available skills in use memo
366ff12
Fix IPC handlers issue
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
202 changes: 202 additions & 0 deletions
202
apps/studio/src/modules/user-settings/components/skills-tab.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,202 @@ | ||
| import { DropdownMenu, MenuGroup, MenuItem } from '@wordpress/components'; | ||
| import { Icon, check, moreVertical } from '@wordpress/icons'; | ||
| import { useI18n } from '@wordpress/react-i18n'; | ||
| import { useCallback, useEffect, useMemo, useState } from 'react'; | ||
| import Button from 'src/components/button'; | ||
| import { getIpcApi } from 'src/lib/get-ipc-api'; | ||
| import { type SkillStatus } from 'src/modules/agent-instructions/lib/skills-constants'; | ||
|
|
||
| export function SkillsTab() { | ||
| const { __ } = useI18n(); | ||
| const [ statuses, setStatuses ] = useState< SkillStatus[] >( [] ); | ||
| const [ error, setError ] = useState< string | null >( null ); | ||
| const [ installingSkillId, setInstallingSkillId ] = useState< string | null >( null ); | ||
| const [ installingAll, setInstallingAll ] = useState( false ); | ||
|
|
||
| const refreshStatus = useCallback( async () => { | ||
| try { | ||
| const result = await getIpcApi().getWordPressSkillsStatusAllSites(); | ||
| setStatuses( result as SkillStatus[] ); | ||
| setError( null ); | ||
| } catch ( err ) { | ||
| const errorMessage = err instanceof Error ? err.message : String( err ); | ||
| setError( errorMessage ); | ||
| } | ||
| }, [] ); | ||
|
|
||
| useEffect( () => { | ||
| void refreshStatus(); | ||
| const handleFocus = () => void refreshStatus(); | ||
| window.addEventListener( 'focus', handleFocus ); | ||
| return () => window.removeEventListener( 'focus', handleFocus ); | ||
| }, [ refreshStatus ] ); | ||
|
|
||
| const handleRemoveSkill = useCallback( | ||
| async ( skillId: string ) => { | ||
| setError( null ); | ||
| try { | ||
| await getIpcApi().removeWordPressSkillFromAllSites( skillId ); | ||
| await refreshStatus(); | ||
| } catch ( err ) { | ||
| const errorMessage = err instanceof Error ? err.message : String( err ); | ||
| setError( errorMessage ); | ||
| } | ||
| }, | ||
| [ refreshStatus ] | ||
| ); | ||
|
|
||
| const handleInstallSkill = useCallback( | ||
| async ( skillId: string ) => { | ||
| setInstallingSkillId( skillId ); | ||
| setError( null ); | ||
| try { | ||
| await getIpcApi().installWordPressSkillsToAllSites( { skillId } ); | ||
| await refreshStatus(); | ||
| } catch ( err ) { | ||
| const errorMessage = err instanceof Error ? err.message : String( err ); | ||
| setError( errorMessage ); | ||
| } finally { | ||
| setInstallingSkillId( null ); | ||
| } | ||
| }, | ||
| [ refreshStatus ] | ||
| ); | ||
|
|
||
| const wordPressSkills = useMemo( | ||
| () => statuses.filter( ( s ) => s.id !== 'studio-cli' ), | ||
| [ statuses ] | ||
| ); | ||
| const installedSkills = useMemo( | ||
| () => wordPressSkills.filter( ( s ) => s.installed ), | ||
| [ wordPressSkills ] | ||
| ); | ||
| const availableSkills = useMemo( | ||
| () => wordPressSkills.filter( ( s ) => ! s.installed ), | ||
| [ wordPressSkills ] | ||
| ); | ||
|
|
||
| const handleInstallAll = useCallback( async () => { | ||
| setInstallingAll( true ); | ||
| setError( null ); | ||
| try { | ||
| for ( const skill of availableSkills ) { | ||
| await getIpcApi().installWordPressSkillsToAllSites( { skillId: skill.id } ); | ||
| } | ||
| await refreshStatus(); | ||
| } catch ( err ) { | ||
| const errorMessage = err instanceof Error ? err.message : String( err ); | ||
| setError( errorMessage ); | ||
| } finally { | ||
| setInstallingAll( false ); | ||
| } | ||
| }, [ availableSkills, refreshStatus ] ); | ||
katinthehatsite marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const isAnyInstalling = installingSkillId !== null || installingAll; | ||
|
|
||
| return ( | ||
| <div className="flex flex-col gap-4 pb-2"> | ||
| <p className="text-xs text-frame-text-secondary text-center"> | ||
| { __( 'Agents can decide to use skills to help them accomplish specialized tasks.' ) } | ||
| </p> | ||
|
|
||
| { error && ( | ||
| <div className="bg-red-50 border border-red-200 text-red-700 px-3 py-2 rounded text-sm"> | ||
| { error } | ||
| </div> | ||
| ) } | ||
|
|
||
| { installedSkills.length > 0 && ( | ||
| <div className="border border-frame-border rounded-md overflow-hidden"> | ||
| <div className="flex items-center px-3 py-2 bg-frame-surface border-b border-frame-border"> | ||
| <span className="text-[11px] font-semibold uppercase tracking-wide text-frame-text-secondary"> | ||
| { __( 'Installed' ) } | ||
| </span> | ||
| </div> | ||
| { installedSkills.map( ( skill ) => ( | ||
| <div | ||
| key={ skill.id } | ||
| className="flex items-center justify-between px-3 py-2.5 border-b border-frame-border last:border-b-0" | ||
| > | ||
| <div className="flex-1 min-w-0 pr-3"> | ||
| <div className="flex items-center gap-2"> | ||
| <span className="text-sm font-medium text-frame-text">{ skill.displayName }</span> | ||
| <span className="inline-flex items-center gap-1 text-[11px] text-green-900 bg-green-50 dark:!text-green-300 dark:bg-green-950 px-2 py-0.5 rounded-full"> | ||
| <Icon className="dark:fill-green-300" icon={ check } size={ 12 } /> | ||
| { __( 'Installed' ) } | ||
| </span> | ||
| </div> | ||
| <div className="text-xs text-frame-text-secondary">{ skill.description }</div> | ||
| </div> | ||
| <DropdownMenu | ||
| icon={ moreVertical } | ||
| label={ __( 'Skill actions' ) } | ||
| className="flex items-center" | ||
| popoverProps={ { position: 'bottom left', resize: true } } | ||
| > | ||
| { ( { onClose }: { onClose: () => void } ) => ( | ||
| <MenuGroup> | ||
| <MenuItem | ||
| isDestructive | ||
| onClick={ () => { | ||
| void handleRemoveSkill( skill.id ); | ||
| onClose(); | ||
| } } | ||
| > | ||
| { __( 'Remove' ) } | ||
| </MenuItem> | ||
| </MenuGroup> | ||
| ) } | ||
| </DropdownMenu> | ||
| </div> | ||
| ) ) } | ||
| </div> | ||
| ) } | ||
|
|
||
| { availableSkills.length > 0 && ( | ||
| <div className="border border-frame-border rounded-md overflow-hidden"> | ||
| <div className="flex items-center justify-between px-3 py-2 bg-frame-surface border-b border-frame-border"> | ||
| <span className="text-[11px] font-semibold uppercase tracking-wide text-frame-text-secondary"> | ||
| { __( 'Available' ) } | ||
| </span> | ||
| <Button | ||
| variant="secondary" | ||
| onClick={ handleInstallAll } | ||
| disabled={ isAnyInstalling } | ||
| className="text-xs py-1 px-2 [&.is-secondary]:bg-frame" | ||
| > | ||
| { installingAll ? __( 'Installing...' ) : __( 'Install all' ) } | ||
| </Button> | ||
| </div> | ||
| { availableSkills.map( ( skill ) => { | ||
| const isInstallingThis = installingSkillId === skill.id; | ||
| return ( | ||
| <div | ||
| key={ skill.id } | ||
| className="flex items-center justify-between px-3 py-2.5 border-b border-frame-border last:border-b-0" | ||
| > | ||
| <div className="flex-1 min-w-0 pr-3"> | ||
| <div className="text-sm font-medium text-frame-text">{ skill.displayName }</div> | ||
| <div className="text-xs text-frame-text-secondary">{ skill.description }</div> | ||
| </div> | ||
| <div className="flex-shrink-0"> | ||
| <Button | ||
| variant="secondary" | ||
| onClick={ () => handleInstallSkill( skill.id ) } | ||
| disabled={ isAnyInstalling } | ||
| className="text-xs py-1 px-2" | ||
| > | ||
| { isInstallingThis ? __( 'Installing...' ) : __( 'Install' ) } | ||
| </Button> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } ) } | ||
| </div> | ||
| ) } | ||
|
|
||
| { statuses.length === 0 && ! error && ( | ||
| <div className="text-sm text-gray-500 text-center py-4">{ __( 'Loading skills...' ) }</div> | ||
| ) } | ||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the follow-up STU-1451, Let's replace this logic and display user's selection saved in appdata.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds good to me, I will take a look at the follow up tomorrow morning 👀