Skip to content

SmythOS Studio: Open-Source Visual AI Agent Builder and deployable runtime stack from SmythOS. Start with an intuitive drag-and-drop workspace, extend with custom code, and deploy your agents anywhere — local, cloud, or edge — with full governance and control.

feat: add FormEmbodimentModal and integrate with DeployAgentModal

Muhammad Hamza Khan95aeabe413df
diff --git a/packages/app/src/react/features/agents/components/modals/deploy-agent-modal.tsx b/packages/app/src/react/features/agents/components/modals/deploy-agent-modal.tsx
index 01ff53fa..279120e1 100644
--- a/packages/app/src/react/features/agents/components/modals/deploy-agent-modal.tsx
+++ b/packages/app/src/react/features/agents/components/modals/deploy-agent-modal.tsx
@@ -18,6 +18,7 @@ import { Textarea } from '@react/shared/components/ui/textarea';
import { useAppState } from '@react/shared/contexts/AppStateContext';
import { OnboardingTaskType } from '@react/shared/types/onboard.types';
import { UserSettingsKey } from '@src/backend/types/user-data';
+import FormEmbodimentModal from '@src/react/features/embodiments/form-embodiment-modal';
import LovableEmbodimentModal from '@src/react/features/embodiments/lovable-embodiment-modal';
import { errorToast, successToast } from '@src/shared/components/toast';
import { SMYTHOS_DOCS_URL } from '@src/shared/constants/general';
@@ -82,7 +83,7 @@ function DeployAgentModal({ userInfo, deploymentSidebarCtx }) {
const [hasDeployment, setHasDeployment] = useState(false);
const [isCollapsed, setIsCollapsed] = useState(false);
- type PanelType = 'none' | 'gpt' | 'alexa' | 'chatbot' | 'api' | 'mcp' | 'lovable';
+ type PanelType = 'none' | 'gpt' | 'alexa' | 'chatbot' | 'api' | 'mcp' | 'lovable' | 'form';
const [openPanel, setOpenPanel] = useState<PanelType>('none');
const [dialogModal, setDialogModal] = useState<{
open: boolean;
@@ -449,6 +450,13 @@ function DeployAgentModal({ userInfo, deploymentSidebarCtx }) {
isLoading={isLoadingEmbodiments}
/>
)}
+ {openPanel === 'form' && (
+ <FormEmbodimentModal
+ onClose={handleClosePanel}
+ domain={chatbotDomain}
+ isLoading={isLoadingEmbodiments}
+ />
+ )}
{openPanel === 'api' && <ApiEmbodimentModal onClose={handleClosePanel} />}
{openPanel === 'mcp' && <McpEmbodimentModal onClose={handleClosePanel} />}
{openPanel === 'lovable' && <LovableEmbodimentModal onClose={handleClosePanel} />}
@@ -843,6 +851,7 @@ function DeployAgentModal({ userInfo, deploymentSidebarCtx }) {
onOpenCodeSnippetModal={handleOpenCodeSnippetModal}
onOpenAlexaPanel={() => handleOpenPanel('alexa')}
onOpenChatbotPanel={() => handleOpenPanel('chatbot')}
+ onOpenFormPanel={() => handleOpenPanel('form')}
onOpenApiPanel={() => handleOpenPanel('api')}
onOpenMcpPanel={() => handleOpenPanel('mcp')}
onOpenLovablePanel={() => handleOpenPanel('lovable')}
diff --git a/packages/app/src/react/features/embodiments/form-embodiment-modal.tsx b/packages/app/src/react/features/embodiments/form-embodiment-modal.tsx
new file mode 100644
index 00000000..518d44f4
--- /dev/null
+++ b/packages/app/src/react/features/embodiments/form-embodiment-modal.tsx
@@ -0,0 +1,138 @@
+import React, { useRef, useState } from 'react';
+import { Button } from '../../shared/components/ui/newDesign/button';
+import { Spinner } from '../../shared/components/ui/spinner';
+import ModalHeaderEmbodiment from './modal-header-embodiment';
+
+/**
+ * Props for the FormEmbodimentModal component.
+ */
+export interface FormEmbodimentModalProps {
+ /**
+ * Callback to close the modal (also used for back button).
+ */
+ onClose: () => void;
+ /**
+ * Domain for the form preview integration.
+ */
+ domain?: string;
+ /**
+ * Loading state while embodiment data is being fetched.
+ */
+ isLoading?: boolean;
+}
+
+/**
+ * Form Preview Modal for showing Form Preview integration instructions or status.
+ * Matches the design and UX of LLM/GPT/Alexa modals.
+ *
+ * @param {FormEmbodimentModalProps} props - The component props.
+ * @returns {JSX.Element} The rendered modal.
+ */
+const FormEmbodimentModal: React.FC<FormEmbodimentModalProps> = ({
+ onClose,
+ domain = 'your-domain.com',
+ isLoading = false,
+}) => {
+ const [copied, setCopied] = useState(false);
+ const textareaRef = useRef<HTMLTextAreaElement>(null);
+
+ if (typeof onClose !== 'function') {
+ throw new Error('FormEmbodimentModal: onClose prop must be a function');
+ }
+
+ /**
+ * Ensures domain has proper protocol prefix.
+ * @param {string} domain - The domain to format.
+ * @returns {string} The formatted domain with protocol.
+ */
+ const getFullDomain = (domain: string): string => {
+ // Check if the domain already includes http:// or https://
+ if (!/^https?:\/\//i.test(domain)) {
+ // Assume HTTPS by default
+ return `https://${domain}`;
+ }
+ return domain;
+ };
+
+ const codeSnippet = `
+ <script src="${getFullDomain(domain)}/static/embodiment/formPreview/form-preview-minified.js"></script>
+ <script>
+ FormPreview.init({
+ domain: '${domain}',
+ // ... additional settings ...
+ });
+ </script>`;
+
+ /**
+ * Handles copying the code snippet to clipboard.
+ */
+ const handleCopyClick = async (): Promise<void> => {
+ try {
+ if (textareaRef.current) {
+ textareaRef.current.select();
+ await navigator.clipboard.writeText(codeSnippet);
+ setCopied(true);
+ setTimeout(() => setCopied(false), 2000);
+ }
+ } catch (error) {
+ console.error('Failed to copy code snippet:', error);
+ }
+ };
+
+ return (
+ <div className="fixed inset-0 bg-black/25 flex items-center justify-center z-50">
+ <div className="relative bg-white rounded-2xl shadow-lg w-full p-6 flex flex-col gap-4 overflow-auto max-h-[90vh] max-w-[520px]">
+ {/* Header with back and close buttons */}
+ <ModalHeaderEmbodiment
+ title="Form Preview Integration Snippet"
+ onBack={onClose}
+ onClose={onClose}
+ />
+
+ {/* Content */}
+ <div className="flex flex-col gap-4">
+ {isLoading ? (
+ /* Loading state */
+ <div className="flex flex-col items-center justify-center py-12 gap-4">
+ <Spinner size="lg" />
+ <p className="text-sm text-gray-600">Loading form preview configuration...</p>
+ </div>
+ ) : (
+ <>
+ {/* Instructions */}
+ <div className="text-sm text-gray-700">
+ <p>
+ Copy and paste this snippet into your website before the closing &lt;/body&gt;
+ tag.
+ </p>
+ </div>
+
+ {/* Code snippet container */}
+ <div className="flex flex-col gap-4">
+ <textarea
+ ref={textareaRef}
+ readOnly
+ className="w-full h-64 p-3 text-sm text-gray-800 bg-white rounded-lg border border-gray-200 font-mono resize-none focus:outline-none focus:border-b-2 focus:border-b-blue-500 transition-colors"
+ value={codeSnippet}
+ />
+
+ {/* Copy Code button */}
+ <div className="flex justify-end">
+ <Button
+ variant="primary"
+ handleClick={handleCopyClick}
+ label={copied ? 'Copied' : 'Copy Code'}
+ className="text-sm"
+ aria-label={copied ? 'Copied' : 'Copy code'}
+ />
+ </div>
+ </div>
+ </>
+ )}
+ </div>
+ </div>
+ </div>
+ );
+};
+
+export default FormEmbodimentModal;
diff --git a/packages/app/src/react/features/embodiments/post-deployment-modal.tsx b/packages/app/src/react/features/embodiments/post-deployment-modal.tsx
index e8e5479d..8c731132 100644
--- a/packages/app/src/react/features/embodiments/post-deployment-modal.tsx
+++ b/packages/app/src/react/features/embodiments/post-deployment-modal.tsx
@@ -81,6 +81,10 @@ interface Props {
* Called when the user requests to open the Lovable panel.
*/
onOpenLovablePanel: () => void;
+ /**
+ * Called when the user requests to open the Form panel.
+ */
+ onOpenFormPanel: () => void;
/**
* If true, the card is visible; otherwise, hidden.
*/
@@ -101,6 +105,7 @@ function PostDeploymentModal({
onOpenCodeSnippetModal,
onOpenAlexaPanel,
onOpenChatbotPanel,
+ onOpenFormPanel,
onOpenApiPanel,
onOpenMcpPanel,
onOpenLovablePanel,
@@ -354,7 +359,7 @@ function PostDeploymentModal({
label="Get Code"
variant="tertiary"
className="px-3 py-1 h-8 text-xs"
- handleClick={() => onOpenChatbotPanel()}
+ handleClick={() => onOpenFormPanel()}
aria-label="Get Code"
type="button"
/>,
@@ -427,20 +432,19 @@ function PostDeploymentModal({
type="button"
/>,
);
+ } else if (key === EMBODIMENT_TYPE.LOVABLE) {
+ buttons.push(
+ <Button
+ key={'get-endpoints-' + EMBODIMENT_TYPE.LOVABLE}
+ label="Get Code"
+ variant="tertiary"
+ className="px-3 py-1 h-8 text-xs"
+ handleClick={onOpenLovablePanel}
+ aria-label="Get Code"
+ type="button"
+ />,
+ );
}
- else if (key === EMBODIMENT_TYPE.LOVABLE) {
- buttons.push(
- <Button
- key={'get-endpoints-' + EMBODIMENT_TYPE.LOVABLE}
- label="Get Code"
- variant="tertiary"
- className="px-3 py-1 h-8 text-xs"
- handleClick={onOpenLovablePanel}
- aria-label="Get Code"
- type="button"
- />,
- );
- }
const embodimentName = capitalizeFirstLetter(
key === EMBODIMENT_TYPE.CHAT_GPT ? 'Custom GPT' : setting.embTitle || 'Untitled Embodiment',
);