Skip to content

🎥 Make videos programmatically with React

`@remotion/studio`: Add skill removal

Jonny Burgereb82341360d2
diff --git a/packages/example/e2e/studio.test.mts b/packages/example/e2e/studio.test.mts
index f064850c6f..fdb91ea967 100644
--- a/packages/example/e2e/studio.test.mts
+++ b/packages/example/e2e/studio.test.mts
@@ -1580,7 +1580,7 @@ test.describe('visual mode', () => {
}
});
- test('installs skills from settings and keeps progress when reopened', async ({
+ test('installs and removes skills while keeping progress when reopened', async ({
page,
}) => {
const skillsInfo = {
@@ -1595,7 +1595,7 @@ test.describe('visual mode', () => {
await page.route('**/api/remotion-skills-info', (route) =>
route.fulfill({json: {success: true, data: skillsInfo}}),
);
- // The server integration test covers the real installer boundary and filesystem.
+ // The server integration test covers the real CLI boundary and filesystem.
let installAttempts = 0;
let finishInstall: () => void = () => undefined;
const installFinished = new Promise<void>((resolve) => {
@@ -1615,6 +1615,18 @@ test.describe('visual mode', () => {
skillsInfo.skills[0].installedInProject = true;
await route.fulfill({json: {success: true, data: skillsInfo}});
});
+ let finishRemove: () => void = () => undefined;
+ const removeFinished = new Promise<void>((resolve) => {
+ finishRemove = resolve;
+ });
+ await page.route('**/api/remove-remotion-skill', async (route) => {
+ expect(route.request().postDataJSON()).toEqual({
+ skill: 'remotion-captions',
+ });
+ await removeFinished;
+ skillsInfo.skills[0].installedInProject = false;
+ await route.fulfill({json: {success: true, data: skillsInfo}});
+ });
await page.goto(`${STUDIO_URL}/schema-test`);
const openSkills = async () => {
await page.getByRole('button', {name: /Search\.\.\./}).click();
@@ -1668,6 +1680,31 @@ test.describe('visual mode', () => {
await expect(
captionsSkill.getByText('Project', {exact: true}),
).toBeVisible();
+ const removeButton = captionsSkill.getByRole('button', {
+ name: 'Remove remotion-captions from this project',
+ exact: true,
+ });
+ await removeButton.click();
+ await expect(
+ captionsSkill.getByText('Removing…', {exact: true}),
+ ).toBeVisible();
+ await expect(removeButton).toHaveCount(0);
+ await expect(
+ dialog
+ .getByRole('listitem')
+ .filter({hasText: '/remotion-create'})
+ .getByRole('button'),
+ ).toBeDisabled();
+ await page.keyboard.press('Escape');
+ await openSkills();
+ await expect(
+ captionsSkill.getByText('Removing…', {exact: true}),
+ ).toBeVisible();
+ finishRemove();
+ await expect(installButton).toBeVisible();
+ await expect(captionsSkill.getByText('Project', {exact: true})).toHaveCount(
+ 0,
+ );
});
test('should collapse programmatically duplicated timeline rows', async ({
diff --git a/packages/studio-server/src/preview-server/api-routes.ts b/packages/studio-server/src/preview-server/api-routes.ts
index 0d886bbec1..4390ce0255 100644
--- a/packages/studio-server/src/preview-server/api-routes.ts
+++ b/packages/studio-server/src/preview-server/api-routes.ts
@@ -27,7 +27,10 @@ import {duplicateJsxNodeHandler} from './routes/duplicate-jsx-node';
import {findInFileHandler} from './routes/find-in-file';
import {insertElementHandler} from './routes/insert-element';
import {insertJsxElementHandler} from './routes/insert-jsx-element';
-import {installRemotionSkillHandler} from './routes/install-remotion-skill';
+import {
+ installRemotionSkillHandler,
+ removeRemotionSkillHandler,
+} from './routes/install-remotion-skill';
import {logStudioErrorHandler} from './routes/log-studio-error';
import {moveKeyframesHandler} from './routes/move-keyframes';
import {openInEditorHandler} from './routes/open-in-editor';
@@ -127,6 +130,7 @@ export const allApiRoutes: {
'/api/release-notes': getReleaseNotesHandler,
'/api/remotion-skills-info': remotionSkillsInfoHandler,
'/api/install-remotion-skill': installRemotionSkillHandler,
+ '/api/remove-remotion-skill': removeRemotionSkillHandler,
'/api/project-info': projectInfoHandler,
'/api/delete-static-file': deleteStaticFileHandler,
'/api/rename-static-file': renameStaticFileHandler,
diff --git a/packages/studio-server/src/preview-server/routes/install-remotion-skill.ts b/packages/studio-server/src/preview-server/routes/install-remotion-skill.ts
index 6dd23824f7..4a82275e1a 100644
--- a/packages/studio-server/src/preview-server/routes/install-remotion-skill.ts
+++ b/packages/studio-server/src/preview-server/routes/install-remotion-skill.ts
@@ -3,6 +3,7 @@ import {RenderInternals} from '@remotion/renderer';
import type {
GetRemotionSkillsInfoResponse,
InstallRemotionSkillRequest,
+ RemoveRemotionSkillRequest,
} from '@remotion/studio-shared';
import {getPackageManagerSpawnOptions} from '../../helpers/package-manager-spawn-options';
import {remotionSkillNames} from '../../remotion-skill-names';
@@ -10,114 +11,154 @@ import type {ApiHandler} from '../api-types';
import {getPackageManager} from '../get-package-manager';
import {getRemotionSkillsInfo} from './remotion-skills-info';
-const installingInProjects = new Set<string>();
+const changingSkillsInProjects = new Set<string>();
-export const installRemotionSkillHandler: ApiHandler<
- InstallRemotionSkillRequest,
- GetRemotionSkillsInfoResponse
-> = async ({remotionRoot, input: {skill}, logLevel}) => {
+const changeRemotionSkill = async ({
+ action,
+ remotionRoot,
+ input: {skill},
+ logLevel,
+}: Parameters<
+ ApiHandler<InstallRemotionSkillRequest, GetRemotionSkillsInfoResponse>
+>[0] & {
+ readonly action: 'install' | 'remove';
+}): Promise<GetRemotionSkillsInfoResponse> => {
if (!remotionSkillNames.some((name) => name === skill)) {
throw new Error(`Unknown Remotion skill: ${JSON.stringify(skill)}`);
}
- if (installingInProjects.has(remotionRoot)) {
+ if (changingSkillsInProjects.has(remotionRoot)) {
throw new Error(
- 'A skill is already being installed. Please try again once it finishes.',
+ 'A skill is already being installed or removed. Please try again once it finishes.',
);
}
- installingInProjects.add(remotionRoot);
- const packageManager = getPackageManager({
- remotionRoot,
- packageManager: undefined,
- dirUp: 0,
- logLevel,
- });
- const useBunx =
- packageManager !== 'unknown' && packageManager.manager === 'bun';
- const executable = useBunx
- ? 'bunx'
- : process.platform === 'win32'
- ? 'npx.cmd'
- : 'npx';
- const args = useBunx
- ? [
- '--silent',
- 'add',
- `remotion-dev/skills@${skill}`,
- '--yes',
- ]
- : [
- '--yes',
- '--loglevel=error',
- 'add',
- `remotion-dev/skills@${skill}`,
- '--yes',
- ];
- RenderInternals.Log.info(
- {indent: false, logLevel},
- RenderInternals.chalk.gray(`╭─ ${executable} ${args.join(' ')}`),
- );
- const time = Date.now();
+ changingSkillsInProjects.add(remotionRoot);
try {
- await new Promise<void>((resolve, reject) => {
- const child = spawn(executable, args, {
- cwd: remotionRoot,
- env: {...process.env, DISABLE_TELEMETRY: '1'},
- stdio: ['ignore', 'pipe', 'pipe'],
- ...getPackageManagerSpawnOptions(),
- });
- let output = '';
- const onData = (data: Buffer) => {
- output = (output + data.toString()).slice(-8000);
- data
- .toString()
- .trim()
- .split('\n')
- .forEach((line) =>
- RenderInternals.Log.info({indent: true, logLevel}, line),
- );
- };
-
- child.stdout.on('data', onData);
- child.stderr.on('data', onData);
- child.on('error', reject);
- child.on('close', (code, signal) => {
- if (code === 0) {
- resolve();
- } else {
- reject(
- new Error(
- `Could not install ${skill} (exit code ${code}, signal ${signal}). ${output.trim()}`,
- ),
- );
- }
- });
- });
-
- const info = getRemotionSkillsInfo({remotionRoot});
- if (!info.skills.find(({name}) => name === skill)?.installedInProject) {
- throw new Error(
- `The installer finished, but ${skill} was not found in the project. Please try again.`,
- );
+ const installedSkill = getRemotionSkillsInfo({remotionRoot}).skills.find(
+ ({name}) => name === skill,
+ );
+ const removingGlobally =
+ action === 'remove' &&
+ installedSkill?.installedInProject === false &&
+ installedSkill.installedGlobally;
+ if (
+ action === 'remove' &&
+ !removingGlobally &&
+ !installedSkill?.installedInProject
+ ) {
+ throw new Error(`${skill} is not installed.`);
}
+ const packageManager = getPackageManager({
+ remotionRoot,
+ packageManager: undefined,
+ dirUp: 0,
+ logLevel,
+ });
+ const useBunx =
+ packageManager !== 'unknown' && packageManager.manager === 'bun';
+ const executable = useBunx
+ ? 'bunx'
+ : process.platform === 'win32'
+ ? 'npx.cmd'
+ : 'npx';
+ const commandArgs =
+ action === 'install'
+ ? ['add', `remotion-dev/skills@${skill}`, '--yes']
+ : ['remove', ...(removingGlobally ? ['--global'] : []), skill, '--yes'];
+ const args = useBunx
+ ? ['--silent', '[email protected]', ...commandArgs]
+ : ['--yes', '--loglevel=error', '[email protected]', ...commandArgs];
RenderInternals.Log.info(
{indent: false, logLevel},
- RenderInternals.chalk.gray('╰─ '),
- `Done in ${Date.now() - time}ms`,
- );
- return info;
- } catch (error) {
- RenderInternals.Log.info(
- {indent: false, logLevel},
- RenderInternals.chalk.gray('╰─ '),
- RenderInternals.chalk.red(`Errored in ${Date.now() - time}ms`),
+ RenderInternals.chalk.gray(`╭─ ${executable} ${args.join(' ')}`),
);
- throw error;
+ const time = Date.now();
+ try {
+ await new Promise<void>((resolve, reject) => {
+ const child = spawn(executable, args, {
+ cwd: remotionRoot,
+ env: {...process.env, DISABLE_TELEMETRY: '1'},
+ stdio: ['ignore', 'pipe', 'pipe'],
+ ...getPackageManagerSpawnOptions(),
+ });
+ let output = '';
+ const onData = (data: Buffer) => {
+ output = (output + data.toString()).slice(-8000);
+ data
+ .toString()
+ .trim()
+ .split('\n')
+ .forEach((line) =>
+ RenderInternals.Log.info({indent: true, logLevel}, line),
+ );
+ };
+
+ child.stdout.on('data', onData);
+ child.stderr.on('data', onData);
+ child.on('error', reject);
+ child.on('close', (code, signal) => {
+ if (code === 0) {
+ resolve();
+ } else {
+ reject(
+ new Error(
+ `Could not ${action} ${skill} (exit code ${code}, signal ${signal}). ${output.trim()}`,
+ ),
+ );
+ }
+ });
+ });
+
+ const info = getRemotionSkillsInfo({remotionRoot});
+ const updatedSkill = info.skills.find(({name}) => name === skill);
+ if (action === 'install' && !updatedSkill?.installedInProject) {
+ throw new Error(
+ `The installer finished, but ${skill} was not found in the project. Please try again.`,
+ );
+ }
+
+ if (
+ action === 'remove' &&
+ (removingGlobally
+ ? updatedSkill?.installedGlobally
+ : updatedSkill?.installedInProject)
+ ) {
+ throw new Error(
+ `The remover finished, but ${skill} is still installed ${removingGlobally ? 'globally' : 'in the project'}. Please try again.`,
+ );
+ }
+
+ RenderInternals.Log.info(
+ {indent: false, logLevel},
+ RenderInternals.chalk.gray('╰─ '),
+ `Done in ${Date.now() - time}ms`,
+ );
+ return info;
+ } catch (error) {
+ RenderInternals.Log.info(
+ {indent: false, logLevel},
+ RenderInternals.chalk.gray('╰─ '),
+ RenderInternals.chalk.red(`Errored in ${Date.now() - time}ms`),
+ );
+ throw error;
+ }
} finally {
- installingInProjects.delete(remotionRoot);
+ changingSkillsInProjects.delete(remotionRoot);
}
};
+
+export const installRemotionSkillHandler: ApiHandler<
+ InstallRemotionSkillRequest,
+ GetRemotionSkillsInfoResponse
+> = (input) => {
+ return changeRemotionSkill({...input, action: 'install'});
+};
+
+export const removeRemotionSkillHandler: ApiHandler<
+ RemoveRemotionSkillRequest,
+ GetRemotionSkillsInfoResponse
+> = (input) => {
+ return changeRemotionSkill({...input, action: 'remove'});
+};
diff --git a/packages/studio-server/src/test/install-remotion-skill.test.ts b/packages/studio-server/src/test/install-remotion-skill.test.ts
index 14fad6e223..badaa36910 100644
--- a/packages/studio-server/src/test/install-remotion-skill.test.ts
+++ b/packages/studio-server/src/test/install-remotion-skill.test.ts
@@ -8,7 +8,7 @@ import {handleRequest} from '../preview-server/handler';
// Replace only the external skills installer; exercise the real HTTP handler and filesystem.
test.skipIf(process.platform === 'win32')(
- 'Studio installs a skill in the project, reports failures, and allows retrying',
+ 'Studio installs and removes a skill in the project and allows retrying',
async () => {
const root = await mkdtemp(path.join(tmpdir(), 'studio-install-skill-'));
const previousPath = process.env.PATH;
@@ -22,24 +22,30 @@ test.skipIf(process.platform === 'win32')(
const fs = require('node:fs');
const path = require('node:path');
const args = process.argv.slice(2);
-fs.writeFileSync(
- 'install-call.json',
- JSON.stringify({
- args,
- disableTelemetry: process.env.DISABLE_TELEMETRY,
- launcher: path.basename(process.argv[1]),
- }),
+fs.appendFileSync(
+ 'skill-calls.jsonl',
+ JSON.stringify({
+ args,
+ disableTelemetry: process.env.DISABLE_TELEMETRY,
+ launcher: path.basename(process.argv[1]),
+ }) + '\\n',
);
if (fs.existsSync('fail')) {
- process.stderr.write('Could not download skills');
- process.stdout.end();
- setTimeout(() => process.exit(1), 100);
+ process.stderr.write('Could not download skills');
+ process.stdout.end();
+ setTimeout(() => process.exit(1), 100);
} else {
- const source = args.find((arg) => arg.startsWith('remotion-dev/skills@'));
- const skill = source.slice('remotion-dev/skills@'.length);
- const directory = path.join('.agents', 'skills', skill);
- fs.mkdirSync(directory, {recursive: true});
- fs.writeFileSync(path.join(directory, 'SKILL.md'), '# Installed skill');
+ const adding = args.includes('add');
+ const skill = adding
+ ? args.find((arg) => arg.startsWith('remotion-dev/skills@')).slice('remotion-dev/skills@'.length)
+ : args[args.indexOf('remove') + 1];
+ const directory = path.join('.agents', 'skills', skill);
+ if (adding) {
+ fs.mkdirSync(directory, {recursive: true});
+ fs.writeFileSync(path.join(directory, 'SKILL.md'), '# Installed skill');
+ } else {
+ fs.rmSync(directory, {recursive: true, force: true});
+ }
}
`,
);
@@ -55,10 +61,14 @@ process.exit(1);
await chmod(npx, 0o755);
process.env.PATH = `${bin}${path.delimiter}${previousPath}`;
const server = createServer((request, response) => {
+ const handler =
+ request.url === '/api/remove-remotion-skill'
+ ? allApiRoutes['/api/remove-remotion-skill']
+ : allApiRoutes['/api/install-remotion-skill'];
handleRequest({
request,
response,
- handler: allApiRoutes['/api/install-remotion-skill'],
+ handler,
remotionRoot: root,
entryPoint: '',
logLevel: 'error',
@@ -81,8 +91,11 @@ process.exit(1);
const address = server.address();
if (!address || typeof address === 'string') throw new Error('No port');
const origin = `http://127.0.0.1:${address.port}`;
- const request = async (skill: string) => {
- const response = await fetch(`${origin}/api/install-remotion-skill`, {
+ const request = async (
+ endpoint: 'install-remotion-skill' | 'remove-remotion-skill',
+ skill: string,
+ ) => {
+ const response = await fetch(`${origin}/api/${endpoint}`, {
method: 'POST',
headers: {origin, 'content-type': 'application/json'},
body: JSON.stringify({skill}),
@@ -90,18 +103,26 @@ process.exit(1);
return response.json();
};
- expect(await request('../untrusted-skill')).toMatchObject({
+ expect(
+ await request('install-remotion-skill', '../untrusted-skill'),
+ ).toMatchObject({
success: false,
});
await expect(
- readFile(path.join(root, 'install-call.json')),
+ readFile(path.join(root, 'skill-calls.jsonl')),
).rejects.toThrow();
await writeFile(path.join(root, 'fail'), '');
- const failed = await request('remotion-interactivity');
+ const failed = await request(
+ 'install-remotion-skill',
+ 'remotion-interactivity',
+ );
expect(failed.success).toBe(false);
expect(failed.error).toContain('Could not download skills');
await rm(path.join(root, 'fail'));
- const installed = await request('remotion-interactivity');
+ const installed = await request(
+ 'install-remotion-skill',
+ 'remotion-interactivity',
+ );
expect(installed.success).toBe(true);
expect(installed.data.remotionInteractivitySkillAvailable).toBe(true);
expect(
@@ -115,21 +136,52 @@ process.exit(1);
'utf8',
),
).toBe('# Installed skill');
- expect(
- JSON.parse(
- await readFile(path.join(root, 'install-call.json'), 'utf8'),
+ const removed = await request(
+ 'remove-remotion-skill',
+ 'remotion-interactivity',
+ );
+ expect(removed.success).toBe(true);
+ expect(removed.data.remotionInteractivitySkillAvailable).toBe(false);
+ await expect(
+ readFile(
+ path.join(root, '.agents/skills/remotion-interactivity/SKILL.md'),
),
- ).toEqual({
- args: [
- '--silent',
- 'add',
- 'remotion-dev/skills@remotion-interactivity',
- '--yes',
- ],
- disableTelemetry: '1',
- launcher: 'bunx',
- });
+ ).rejects.toThrow();
+ const calls = (
+ await readFile(path.join(root, 'skill-calls.jsonl'), 'utf8')
+ )
+ .trim()
+ .split('\n')
+ .map((line) => JSON.parse(line));
+ expect(calls).toEqual(
+ [
+ [
+ '--silent',
+ 'add',
+ 'remotion-dev/skills@remotion-interactivity',
+ '--yes',
+ ],
+ [
+ '--silent',
+ 'add',
+ 'remotion-dev/skills@remotion-interactivity',
+ '--yes',
+ ],
+ [
+ '--silent',
+ 'remove',
+ 'remotion-interactivity',
+ '--yes',
+ ],
+ ].map((args) => ({
+ args,
+ disableTelemetry: '1',
+ launcher: 'bunx',
+ })),
+ );
} finally {
process.env.PATH = previousPath;
server.closeAllConnections();
diff --git a/packages/studio-shared/src/api-requests.ts b/packages/studio-shared/src/api-requests.ts
index a8cbc69006..bcbb1353b9 100644
--- a/packages/studio-shared/src/api-requests.ts
+++ b/packages/studio-shared/src/api-requests.ts
@@ -1147,6 +1147,9 @@ export type GetRemotionSkillsInfoRequest = {};
export type InstallRemotionSkillRequest = {
skill: string;
};
+export type RemoveRemotionSkillRequest = {
+ skill: string;
+};
export type GetRemotionSkillsInfoResponse = {
remotionUpgradeSkillAvailable: boolean;
remotionInteractivitySkillAvailable: boolean;
@@ -1429,6 +1432,10 @@ export type ApiRoutes = {
InstallRemotionSkillRequest,
GetRemotionSkillsInfoResponse
>;
+ '/api/remove-remotion-skill': ReqAndRes<
+ RemoveRemotionSkillRequest,
+ GetRemotionSkillsInfoResponse
+ >;
'/api/apply-codemod': ReqAndRes<ApplyCodemodRequest, ApplyCodemodResponse>;
'/api/project-info': ReqAndRes<ProjectInfoRequest, ProjectInfoResponse>;
'/api/delete-static-file': ReqAndRes<
diff --git a/packages/studio-shared/src/index.ts b/packages/studio-shared/src/index.ts
index 9cb112bf1e..ea318ff60c 100644
--- a/packages/studio-shared/src/index.ts
+++ b/packages/studio-shared/src/index.ts
@@ -68,6 +68,7 @@ export {
GetRemotionSkillsInfoRequest,
GetRemotionSkillsInfoResponse,
InstallRemotionSkillRequest,
+ RemoveRemotionSkillRequest,
GetReleaseNotesRequest,
GetReleaseNotesResponse,
GoogleFontSourceEdit,
diff --git a/packages/studio/src/components/SettingsContext.tsx b/packages/studio/src/components/SettingsContext.tsx
index d233f1744a..278c4e550f 100644
--- a/packages/studio/src/components/SettingsContext.tsx
+++ b/packages/studio/src/components/SettingsContext.tsx
@@ -19,6 +19,11 @@ import {callApi} from './call-api';
import {showNotification} from './Notifications/NotificationCenter';
import {UpdateStatusProvider} from './UpdateStatusContext';
+type SkillAction = {
+ readonly skill: string;
+ readonly type: 'installing' | 'removing';
+};
+
type SettingsContextValue = {
readonly codingAgentInfo: GetDefaultCodingAgentInfoResponse | null;
readonly editorInfo: GetDefaultEditorInfoResponse | null;
@@ -30,8 +35,9 @@ type SettingsContextValue = {
readonly revision: number;
readonly setPublicLicenseKey: (publicLicenseKey: string | null) => void;
readonly installSkill: (skill: string) => Promise<void>;
- readonly installingSkill: string | null;
- readonly skillInstallError: string | null;
+ readonly removeSkill: (skill: string) => Promise<void>;
+ readonly skillAction: SkillAction | null;
+ readonly skillActionError: string | null;
};
const SettingsContext = createContext<SettingsContextValue | null>(null);
@@ -43,7 +49,10 @@ export const SettingsProvider: React.FC<{
StudioServerConnectionCtx,
);
const [settings, setSettings] = useState<
- Omit<SettingsContextValue, 'setPublicLicenseKey' | 'installSkill'>
+ Omit<
+ SettingsContextValue,
+ 'setPublicLicenseKey' | 'installSkill' | 'removeSkill'
+ >
>({
codingAgentInfo: null,
editorInfo: null,
@@ -53,8 +62,8 @@ export const SettingsProvider: React.FC<{
renderDefaults: window.remotion_renderDefaults ?? null,
studioRuntimeConfig: window.remotion_studioConfig ?? null,
revision: 0,
- installingSkill: null,
- skillInstallError: null,
+ skillAction: null,
+ skillActionError: null,
});
useEffect(() => {
@@ -156,8 +165,8 @@ export const SettingsProvider: React.FC<{
const installSkill = useCallback(async (skill: string) => {
setSettings((currentSettings) => ({
...currentSettings,
- installingSkill: skill,
- skillInstallError: null,
+ skillAction: {skill, type: 'installing'},
+ skillActionError: null,
}));
try {
const remotionSkillsInfo = await callApi('/api/install-remotion-skill', {
@@ -166,7 +175,7 @@ export const SettingsProvider: React.FC<{
setSettings((currentSettings) => ({
...currentSettings,
remotionSkillsInfo,
- installingSkill: null,
+ skillAction: null,
revision: currentSettings.revision + 1,
}));
showNotification(
@@ -176,14 +185,47 @@ export const SettingsProvider: React.FC<{
} catch (err) {
setSettings((currentSettings) => ({
...currentSettings,
- installingSkill: null,
- skillInstallError: (err as Error).message,
+ skillAction: null,
+ skillActionError: (err as Error).message,
+ }));
+ }
+ }, []);
+ const removeSkill = useCallback(async (skill: string) => {
+ setSettings((currentSettings) => ({
+ ...currentSettings,
+ skillAction: {skill, type: 'removing'},
+ skillActionError: null,
+ }));
+ try {
+ const remotionSkillsInfo = await callApi('/api/remove-remotion-skill', {
+ skill,
+ });
+ setSettings((currentSettings) => ({
+ ...currentSettings,
+ remotionSkillsInfo,
+ skillAction: null,
+ revision: currentSettings.revision + 1,
+ }));
+ const remainingSkill = remotionSkillsInfo.skills.find(
+ ({name}) => name === skill,
+ );
+ showNotification(
+ remainingSkill?.installedGlobally
+ ? `Removed ${skill} from this project. It is still installed globally.`
+ : `Removed ${skill}. Restart your coding agent to stop using it.`,
+ 5000,
+ );
+ } catch (err) {
+ setSettings((currentSettings) => ({
+ ...currentSettings,
+ skillAction: null,
+ skillActionError: (err as Error).message,
}));
}
}, []);
const value = useMemo<SettingsContextValue>(() => {
- return {...settings, setPublicLicenseKey, installSkill};
- }, [installSkill, setPublicLicenseKey, settings]);
+ return {...settings, setPublicLicenseKey, installSkill, removeSkill};
+ }, [installSkill, removeSkill, setPublicLicenseKey, settings]);
return (
<SettingsContext.Provider value={value}>
diff --git a/packages/studio/src/components/SkillsSettings.tsx b/packages/studio/src/components/SkillsSettings.tsx
index 88e053c74c..d14a5e3959 100644
--- a/packages/studio/src/components/SkillsSettings.tsx
+++ b/packages/studio/src/components/SkillsSettings.tsx
@@ -11,6 +11,7 @@ import {useCopyFeedback} from '../helpers/use-copy-feedback';
import {CheckCircleFilled} from '../icons/check-circle-filled';
import {CloudDownloadIcon} from '../icons/cloud-download';
import {CopyIcon} from '../icons/copy';
+import {TrashIcon} from '../icons/trash';
import type {RenderInlineAction} from './InlineAction';
import {InlineAction} from './InlineAction';
import {ValidationMessage} from './NewComposition/ValidationMessage';
@@ -129,8 +130,9 @@ export const SkillsSettings: React.FC = () => {
error,
remotionSkillsInfo,
installSkill,
- installingSkill,
- skillInstallError,
+ removeSkill,
+ skillAction,
+ skillActionError,
} = useSettings();
const {previewServerState} = useContext(StudioServerConnectionCtx);
const canInstall =
@@ -164,6 +166,10 @@ export const SkillsSettings: React.FC = () => {
const renderInstallAction: RenderInlineAction = useCallback((color) => {
return <CloudDownloadIcon color={color} style={actionIcon} />;
}, []);
+ const renderRemoveAction: RenderInlineAction = useCallback((color) => {
+ return <TrashIcon color={color} style={actionIcon} />;
+ }, []);
+ const actionInProgress = skillAction !== null;
return (
<div style={container}>
@@ -180,10 +186,10 @@ export const SkillsSettings: React.FC = () => {
Install skills in this project to use them with your coding agent.
</p>
) : null}
- {skillInstallError ? (
+ {skillActionError ? (
<div style={{marginTop: 14}}>
<ValidationMessage
- message={skillInstallError}
+ message={skillActionError}
align="flex-start"
type="error"
/>
@@ -211,7 +217,7 @@ export const SkillsSettings: React.FC = () => {
{remotionSkillsInfo.skills.map((skill, index) => {
const installed =
skill.installedInProject || skill.installedGlobally;
- const installingThisSkill = installingSkill === skill.name;
+ const processingThisSkill = skillAction?.skill === skill.name;
const installedLocation =
skill.installedInProject && skill.installedGlobally
? 'Project and global'
@@ -232,26 +238,41 @@ export const SkillsSettings: React.FC = () => {
}
>
<span style={skillName}>/{skill.name}</span>
- {installedLocation ? (
+ {processingThisSkill ? (
+ <span style={status}>
+ {skillAction.type === 'installing'
+ ? 'Installing…'
+ : 'Removing…'}
+ </span>
+ ) : installedLocation ? (
<span style={status}>{installedLocation}</span>
- ) : installingThisSkill ? (
- <span style={status}>Installing…</span>
) : null}
{installed ? (
- <span style={actionSlot}>
- <CheckCircleFilled
- aria-hidden
- style={{...statusIcon, fill: BLUE}}
- />
- </span>
- ) : installingThisSkill ? (
+ <CheckCircleFilled
+ aria-hidden
+ style={{...statusIcon, fill: BLUE}}
+ />
+ ) : null}
+ {processingThisSkill ? (
<span style={actionSlot}>
<Spinner duration={0.5} size={14} />
</span>
+ ) : installed && canInstall ? (
+ <InlineAction
+ title={
+ skill.installedInProject
+ ? `Remove ${skill.name} from this project`
+ : `Remove ${skill.name} globally`
+ }
+ disabled={actionInProgress}
+ onClick={() => removeSkill(skill.name)}
+ renderAction={renderRemoveAction}
+ variant={null}
+ />
) : canInstall ? (
<InlineAction
title={`Install ${skill.name} in this project`}
- disabled={installingSkill !== null}
+ disabled={actionInProgress}
onClick={() => installSkill(skill.name)}
renderAction={renderInstallAction}
variant={null}