Skip to content

🎥 Make videos programmatically with React

`@remotion/studio`: Open fix prompts in coding agents

Jonny Burger082ca3aa9dc0
diff --git a/packages/studio/src/components/FixComputedValueModal.tsx b/packages/studio/src/components/FixComputedValueModal.tsx
index 415ac6ee13..a39945fd04 100644
--- a/packages/studio/src/components/FixComputedValueModal.tsx
+++ b/packages/studio/src/components/FixComputedValueModal.tsx
@@ -1,13 +1,28 @@
+import type {DefaultCodingAgent} from '@remotion/renderer';
import React, {useCallback} from 'react';
-import {LIGHT_TEXT, SELECTED_BACKGROUND, WHITE} from '../helpers/colors';
+import {
+ LIGHT_TEXT,
+ SELECTED_BACKGROUND,
+ TRANSPARENT,
+ WHITE,
+ getBackgroundFromHoverState,
+} from '../helpers/colors';
import {copyText} from '../helpers/copy-text';
+import {openInCodingAgent} from '../helpers/open-in-editor';
+import {CaretDown} from '../icons/caret';
import {ClipboardIcon} from '../icons/clipboard';
import type {ModalState} from '../state/modals';
+import {useZIndex} from '../state/z-index';
+import {CodingAgentIcon} from './CodingAgentIcon';
import type {RenderInlineAction} from './InlineAction';
import {InlineAction} from './InlineAction';
+import {InlineDropdown} from './InlineDropdown';
+import {ModalFooterContainer} from './ModalFooter';
import {ModalHeader} from './ModalHeader';
+import type {ComboboxValue} from './NewComposition/ComboBox';
import {DismissableModal} from './NewComposition/DismissableModal';
import {showNotification} from './Notifications/NotificationCenter';
+import {useSettings} from './SettingsContext';
const panelStyle: React.CSSProperties = {
borderRadius: 6,
@@ -54,6 +69,54 @@ const copyIcon: React.CSSProperties = {
width: 12,
};
+const footer: React.CSSProperties = {
+ display: 'flex',
+ flex: 'none',
+ justifyContent: 'flex-end',
+};
+
+const splitButton: React.CSSProperties = {
+ alignItems: 'center',
+ borderRadius: 4,
+ display: 'inline-flex',
+ flexDirection: 'row',
+ gap: 1,
+ height: 24,
+ overflow: 'hidden',
+};
+
+const mainButtonBase: React.CSSProperties = {
+ alignItems: 'center',
+ background: TRANSPARENT,
+ border: 'none',
+ borderRadius: '4px 0 0 4px',
+ color: LIGHT_TEXT,
+ display: 'inline-flex',
+ fontFamily: 'sans-serif',
+ fontSize: 12,
+ gap: 6,
+ height: 24,
+ padding: '0 9px',
+ whiteSpace: 'nowrap',
+};
+
+const singleButton: React.CSSProperties = {
+ borderRadius: 4,
+};
+
+const dropdownButton: React.CSSProperties = {
+ borderRadius: '0 4px 4px 0',
+ height: 24,
+ width: 24,
+};
+
+const menuLabel: React.CSSProperties = {
+ color: 'inherit',
+ fontFamily: 'sans-serif',
+ fontSize: 13,
+ lineHeight: '16px',
+};
+
type FixComputedValueModalState = Extract<
ModalState,
{type: 'fix-computed-value'}
@@ -62,8 +125,19 @@ type FixComputedValueModalState = Extract<
export const FixComputedValueModal: React.FC<{
readonly state: FixComputedValueModalState;
}> = ({state}) => {
+ const {codingAgentInfo} = useSettings();
+ const {tabIndex} = useZIndex();
+ const [hovered, setHovered] = React.useState(false);
const prompt = `/remotion-interactivity ${state.context} make "${state.prop}" interactive`;
const installCommand = 'npx remotion skills add';
+ const installedCodingAgents = codingAgentInfo?.installedCodingAgents ?? [];
+ const defaultCodingAgent =
+ installedCodingAgents.find(
+ (agent) => agent.id === codingAgentInfo?.defaultCodingAgent,
+ ) ?? installedCodingAgents[0];
+ const alternativeCodingAgents = installedCodingAgents.filter(
+ (agent) => agent.id !== defaultCodingAgent?.id,
+ );
const onCopyPrompt = useCallback(() => {
copyText(prompt).catch((err) => {
@@ -81,6 +155,57 @@ export const FixComputedValueModal: React.FC<{
return <ClipboardIcon color={color} style={copyIcon} />;
}, []);
+ const openWithCodingAgent = useCallback(
+ async (codingAgentId: DefaultCodingAgent, codingAgentName: string) => {
+ try {
+ const response = await openInCodingAgent(
+ codingAgentId,
+ codingAgentId === 'copilot' ? null : prompt,
+ );
+ if (!response.success) {
+ showNotification(`Could not open ${codingAgentName}`, 2000);
+ }
+ } catch (err) {
+ showNotification((err as Error).message, 2000);
+ }
+ },
+ [prompt],
+ );
+
+ const agentMenuItems = React.useMemo((): ComboboxValue[] => {
+ return alternativeCodingAgents.map((codingAgent) => ({
+ id: `fix-computed-value-in-${codingAgent.id}`,
+ keyHint: null,
+ label: <span style={menuLabel}>{codingAgent.name}</span>,
+ leftItem: <CodingAgentIcon codingAgentId={codingAgent.id} size={18} />,
+ onClick: () => {
+ openWithCodingAgent(codingAgent.id, codingAgent.nameWithType).catch(
+ () => undefined,
+ );
+ },
+ quickSwitcherLabel: null,
+ subMenu: null,
+ type: 'item',
+ value: `coding-agent-${codingAgent.id}`,
+ }));
+ }, [alternativeCodingAgents, openWithCodingAgent]);
+
+ const renderDropdownAction: RenderInlineAction = useCallback((color) => {
+ return <CaretDown color={color} small />;
+ }, []);
+
+ const mainButtonStyle = React.useMemo((): React.CSSProperties => {
+ return {
+ ...mainButtonBase,
+ ...(alternativeCodingAgents.length === 0 ? singleButton : null),
+ background: getBackgroundFromHoverState({
+ hovered,
+ selected: false,
+ }),
+ color: hovered ? WHITE : LIGHT_TEXT,
+ };
+ }, [alternativeCodingAgents.length, hovered]);
+
return (
<DismissableModal panelStyle={panelStyle}>
<ModalHeader title="Fix computed value" />
@@ -119,6 +244,44 @@ export const FixComputedValueModal: React.FC<{
/>
</div>
</div>
+ {defaultCodingAgent ? (
+ <ModalFooterContainer style={footer}>
+ <div
+ style={splitButton}
+ onPointerEnter={() => setHovered(true)}
+ onPointerLeave={() => setHovered(false)}
+ >
+ <button
+ aria-label={`Open in ${defaultCodingAgent.nameWithType}`}
+ onClick={() => {
+ openWithCodingAgent(
+ defaultCodingAgent.id,
+ defaultCodingAgent.nameWithType,
+ ).catch(() => undefined);
+ }}
+ style={mainButtonStyle}
+ tabIndex={tabIndex}
+ title={`Open in ${defaultCodingAgent.nameWithType}`}
+ type="button"
+ >
+ <CodingAgentIcon
+ codingAgentId={defaultCodingAgent.id}
+ size={18}
+ />
+ Open in {defaultCodingAgent.name}
+ </button>
+ {alternativeCodingAgents.length > 0 ? (
+ <InlineDropdown
+ renderAction={renderDropdownAction}
+ style={dropdownButton}
+ title="Open in another coding agent"
+ values={agentMenuItems}
+ variant={null}
+ />
+ ) : null}
+ </div>
+ </ModalFooterContainer>
+ ) : null}
</DismissableModal>
);
};