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.
JavaScript a2aagentic-aiai-agentsdevtoolsmcp-clientn8n-alternativeno-codeopen-sourceorchestrationsmythosvisual-builder
feat: add Form Preview embodiment support
Muhammad Hamza Khan670290c4c33b
diff --git a/packages/app/src/builder-ui/Agent.class.ts b/packages/app/src/builder-ui/Agent.class.tsindex 856dff9d..afdd5b0f 100644--- a/packages/app/src/builder-ui/Agent.class.ts+++ b/packages/app/src/builder-ui/Agent.class.ts@@ -481,6 +481,7 @@ export class Agent extends EventEmitter {embodiments['chatgpt'] = {};embodiments['chatbot'] = {};embodiments['llm'] = {};+ embodiments['form'] = {};}return embodiments;diff --git a/packages/app/src/react/features/agent-settings/dialogs/FormPreview.tsx b/packages/app/src/react/features/agent-settings/dialogs/FormPreview.tsxnew file mode 100644index 00000000..bb6f9eab--- /dev/null+++ b/packages/app/src/react/features/agent-settings/dialogs/FormPreview.tsx@@ -0,0 +1,317 @@+import { Dialog, Transition } from '@headlessui/react';+import { mapFormPreviewEmbodimentProperties } from '@react/features/agent-settings/utils';+import { Button } from '@react/shared/components/ui/newDesign/button';+import { Spinner } from '@react/shared/components/ui/spinner';+import { EMBODIMENT_TYPE } from '@react/shared/enums';+import { extractError } from '@react/shared/utils/errors';+import { validateDomains, validateURL } from '@react/shared/utils/utils';+import { FormPreviewEmbodimentData } from '@src/react/shared/types/api-results.types';+import { errorToast, successToast, warningToast } from '@src/shared/components/toast';+import { useQueryClient } from '@tanstack/react-query';+import { Tooltip } from 'flowbite-react';+import { ErrorMessage, Field, Form, Formik, FormikProps } from 'formik';+import { Info } from 'lucide-react';+import { Fragment, useEffect, useState } from 'react';+import { IoClose } from 'react-icons/io5';++interface IFormPreviewDialogProps {+ isOpen: boolean;+ closeModal: () => void;+ currentData: any;+ refreshEmbodiments: (agentId: string, embodimentId: string) => void;+ style: any;+ activeAgent: any;+ agentId: string;+}++const FormPreviewDialog = ({+ isOpen,+ closeModal,+ currentData,+ refreshEmbodiments,+ style,+ activeAgent,+ agentId,+}: IFormPreviewDialogProps) => {+ const [activeData, setActiveData] = useState(null);+ const [isSubmitting, setIsSubmitting] = useState(false);+ const [domainError, setDomainError] = useState(false);+ const queryClient = useQueryClient();++ // Default values to prevent uncontrolled to controlled input warning+ const defaultFormValues = {+ name: '',+ allowedDomains: [],+ };++ useEffect(() => {+ const properties = currentData?.properties;+ const _activeData = mapFormPreviewEmbodimentProperties(properties, activeAgent);++ setActiveData(_activeData);+ }, [currentData, activeAgent]);++ const submitForm = async (data) => {+ if (isSubmitting) {+ return; // If submission is already in progress, do nothing+ }++ if (data.allowedDomains?.filter((domain) => domain)?.length > 0) {+ const hasInvalidDomains = !validateDomains(data.allowedDomains);++ if (hasInvalidDomains) {+ setDomainError(true);+ return;+ }+ }++ if (data.icon && !validateURL(data.icon)) {+ warningToast('The URL entered for icon does not appear to be valid.');+ }++ try {+ setIsSubmitting(true); // Set the flag to true to indicate that submission is in progress+ const dataToSend = {+ type: EMBODIMENT_TYPE.FORM,+ properties: {+ ...data,+ allowedDomains: data?.allowedDomains+ ?.filter((domain) => domain && domain.trim() !== '')+ ?.map((item) => item.trim()),+ },+ };++ const requestOptions = {+ method: currentData ? 'PUT' : 'POST',+ headers: {+ 'Content-Type': 'application/json',+ },+ body: JSON.stringify(+ currentData+ ? { ...dataToSend, embodimentId: currentData?.id }+ : { ...dataToSend, aiAgentId: agentId },+ ),+ };++ fetch('/api/page/agents/embodiment', requestOptions)+ .then((response) => {+ response.json().then((data) => {+ // Invalidate the agentEmbodiments query to ensure fresh data+ queryClient.invalidateQueries({ queryKey: ['agentEmbodiments', agentId] });+ // Also invalidate the embodiments query used in deploy modal+ queryClient.invalidateQueries({ queryKey: ['embodiments', agentId] });+ // Invalidate the agent_embodiments query used in OverviewWidgetsContainer+ queryClient.invalidateQueries({ queryKey: ['agent_embodiments', agentId] });+ // Invalidate the availableEmbodiments query+ queryClient.invalidateQueries({ queryKey: ['availableEmbodiments', agentId] });+ refreshEmbodiments(agentId, currentData?.id);+ successToast('Embodiment saved');+ closeModal();+ });+ })+ .catch((error) => {+ errorToast(extractError(error) || 'Embodiment not saved. Please try again.');+ console.log(error);+ })+ .finally(() => {+ setIsSubmitting(false); // Reset the flag after submission is complete+ });+ } catch (error) {+ console.error('Error:', error);+ }+ };++ return (+ <Transition appear show={isOpen} as={Fragment}>+ <Dialog as="div" className="relative z-50" onClose={closeModal} style={style}>+ <Transition.Child+ as={Fragment}+ enter="ease-out duration-300"+ enterFrom="opacity-0"+ enterTo="opacity-100"+ leave="ease-in duration-200"+ leaveFrom="opacity-100"+ leaveTo="opacity-0"+ >+ <div className="fixed inset-0 bg-black bg-opacity-25" />+ </Transition.Child>++ <div className="fixed inset-0 overflow-y-auto">+ <div className="flex min-h-full items-center justify-center p-4 text-center">+ <Transition.Child+ as={Fragment}+ enter="ease-out duration-300"+ enterFrom="opacity-0 scale-95"+ enterTo="opacity-100 scale-100"+ leave="ease-in duration-200"+ leaveFrom="opacity-100 scale-100"+ leaveTo="opacity-0 scale-95"+ >+ <div className="w-[80vw] max-w-[1000px]">+ <Dialog.Panel className="w-full relative transform overflow-hidden rounded-2xl bg-white p-8 text-left align-middle shadow-xl transition-all">+ <Dialog.Title className="text-xl font-semibold leading-6 text-[#1E1E1E] mb-4 flex justify-between items-center">+ <span>Form Preview Configuration</span>+ <IoClose className="cursor-pointer" size={24} onClick={() => closeModal()} />+ </Dialog.Title>+ <Formik+ initialValues={activeData || defaultFormValues}+ enableReinitialize={true}+ // validate={(values) => validateForm(values)}+ onSubmit={(values) => {+ submitForm(values);+ }}+ >+ {(props: FormikProps<FormPreviewEmbodimentData>) => {+ return (+ <Form>+ <div className="gap-4">+ <div className="mt-5">+ <div>+ <label+ htmlFor="name"+ className="block text-[#1E1E1E] mb-1 text-base font-normal"+ >+ Name+ </label>+ <Field+ type="text"+ className="bg-white+ border+ text-gray-900+ rounded+ block+ w-full+ outline-none+ focus:outline-none+ focus:ring-0+ focus:ring-offset-0+ focus:ring-shadow-none+ text-sm+ font-normal+ placeholder:text-sm+ placeholder:font-normal+ mb-4+ border-gray-300 border-b-gray-500 focus:border-b-2 focus:border-b-blue-500 focus-visible:border-b-2 focus-visible:border-b-blue-500"+ name="name"+ id="name"+ onChange={props.handleChange}+ onBlur={props.handleBlur}+ value={props.values?.name}+ placeholder="Enter form preview name"+ disabled={true}+ />+ <ErrorMessage+ name="name"+ component="div"+ className="text-red-500 text-sm"+ />+ </div>++ {/* ALLOWED DOMAINS START */}+ <div>+ <label+ htmlFor="allowedDomains"+ className="text-[#1E1E1E] mb-1 text-base font-normal flex items-center"+ >+ Allowed Domains{' '}+ <Tooltip+ className="w-52 text-center"+ content={+ <div>+ Restrict form preview to specific domains.+ <br /> Use commas to separate multiple domains (e.g.,+ example.com, mysite.org).+ <br /> Leave empty for no restrictions.+ </div>+ }+ >+ <Info className="w-5 h-5 ml-1" />+ </Tooltip>+ </label>++ <Field+ type="text"+ id="allowedDomains"+ className={`bg-white+ border+ text-gray-900+ rounded+ block+ w-full+ outline-none+ focus:outline-none+ focus:ring-0+ focus:ring-offset-0+ focus:ring-shadow-none+ text-sm+ font-normal+ placeholder:text-sm+ placeholder:font-normal+ mb-4+ border-gray-300 border-b-gray-500 focus:border-b-2 focus:border-b-blue-500 focus-visible:border-b-2 focus-visible:border-b-blue-500 ${+ domainError+ ? 'border-red-500 text-red-900 placeholder-red-700 focus:border-red-500 dark:text-red-500 dark:placeholder-red-500 dark:border-red-500'+ : ''+ }`}+ name="allowedDomains"+ placeholder="Enter comma separated values for domains"+ value={+ Array.isArray(props.values?.allowedDomains)+ ? props.values.allowedDomains.join(',')+ : props.values?.allowedDomains || ''+ }+ onChange={(e) => {+ if (domainError) {+ setDomainError(false);+ }+ const newValue = e.target.value+ ? e.target.value.split(',')+ : [];+ props.setFieldValue('allowedDomains', newValue);+ }}+ />++ {domainError && (+ <p className="mb-2 text-sm text-red-600 dark:text-red-500">+ <span className="font-medium">+ One or more domains are invalid. Make sure there is no+ trailing comma.+ </span>+ </p>+ )}++ <ErrorMessage+ name="allowedDomains"+ component="div"+ className="text-red-500 text-sm mb-2"+ />+ </div>+ {/* ALLOWED DOMAINS END */}+ </div>+ </div>+ <div className="flex justify-end w-full mt-4">+ <Button+ handleClick={() => submitForm(props.values)}+ label="Save"+ addIcon={isSubmitting}+ Icon={<Spinner classes="w-4 h-4 mr-2" />}+ disabled={isSubmitting}+ type="submit"+ className="px-8 h-[48px] rounded-lg"+ />+ </div>+ </Form>+ );+ }}+ </Formik>+ </Dialog.Panel>+ </div>+ </Transition.Child>+ </div>+ </div>+ </Dialog>+ </Transition>+ );+};++export default FormPreviewDialog;diff --git a/packages/app/src/react/features/agent-settings/utils/index.ts b/packages/app/src/react/features/agent-settings/utils/index.tsindex 11c78a75..e659a231 100644--- a/packages/app/src/react/features/agent-settings/utils/index.ts+++ b/packages/app/src/react/features/agent-settings/utils/index.ts@@ -2,11 +2,12 @@ import { SYNTAX_HIGHLIGHT_THEMES } from '@react/features/agent-settings/constantimport { DEFAULT_CHAT_COLORS } from '@react/shared/enums';import { Input } from '@react/shared/types/agent-data.types';import {- TGptEmbodimentProperties+ TChatBotProperties,+ TFormPreviewProperties,+ TGptEmbodimentProperties,} from '@react/shared/types/embodiment.types';import * as Yup from 'yup';-export const generateComponentInputsSchema = (inputs: Input[]) => {return Yup.object().shape(inputs.reduce((acc, input) => {@@ -122,6 +123,16 @@ export const mapBotEmbodimentProperties = (properties: TChatBotProperties, activ};};+export const mapFormPreviewEmbodimentProperties = (+ properties: TFormPreviewProperties,+ activeAgent,+) => {+ return {+ name: properties?.name || activeAgent?.name || '',+ allowedDomains: properties?.allowedDomains || [],+ };+};+export const mapGptEmbodimentProperties = (properties: TGptEmbodimentProperties, activeAgent) => {return {humanName: properties?.humanName || activeAgent?.name || '',diff --git a/packages/app/src/react/features/embodiments/embodiment-configs.tsx b/packages/app/src/react/features/embodiments/embodiment-configs.tsxindex 32cccb13..ffc8277d 100644--- a/packages/app/src/react/features/embodiments/embodiment-configs.tsx+++ b/packages/app/src/react/features/embodiments/embodiment-configs.tsx@@ -6,6 +6,7 @@ import ChatGptDialog from '../agent-settings/dialogs/ChatGpt';import ChatbotCodeSnippetModal from '../agent-settings/modals/chatbotCode.modal';import { AlexaIcon, ChatGptIcon, MCPIcon } from '../../shared/components/svgs';+import FormPreviewDialog from '../agent-settings/dialogs/FormPreview';export const AlwaysAvailableEmbodiments = ['API', EMBODIMENT_TYPE.MCP, EMBODIMENT_TYPE.ALEXA];@@ -38,6 +39,8 @@ export const getEmbodimentTitle = (embodimentType: string): string => {return 'LLM';case EMBODIMENT_TYPE.MCP:return 'MCP';+ case EMBODIMENT_TYPE.FORM:+ return 'Form Preview';default:return embodimentType;}@@ -57,6 +60,8 @@ export const getEmbodimentDescription = (embodimentType: string): string => {return 'Enable Alexa to communicate with your agent.';case EMBODIMENT_TYPE.LLM:return 'Use your agent as an OpenAI-compatible API endpoint for seamless integration with existing LLM workflows.';+ case EMBODIMENT_TYPE.FORM:+ return 'Preview your agent as a form for seamless integration with existing workflows.';default:return '';}@@ -76,6 +81,8 @@ export const getEmbodimentDataAttribute = (embodimentType: string): string => {return 'alexa-embodiment-card';case EMBODIMENT_TYPE.LLM:return 'agentllm-embodiment-card';+ case EMBODIMENT_TYPE.FORM:+ return 'form-embodiment-card';default:return '';}@@ -129,6 +136,30 @@ export const getChatBotDialog = ();};+export const getFormPreviewDialog = (+ isOpen: boolean,+ closeModal: () => void,+ agent,+ agentId,+ currentData,+ refreshEmbodiments,+ activeModal,+) => {+ // Always render the component for preloading, HeadlessUI Transition handles visibility+ // This ensures the component is initialized and ready when the user opens it+ return (+ <FormPreviewDialog+ isOpen={isOpen}+ closeModal={closeModal}+ activeAgent={agent}+ agentId={agentId}+ currentData={currentData}+ refreshEmbodiments={() => refreshEmbodiments()}+ style={{}}+ />+ );+};+export const getCodeSnippetModal = (isOpen: boolean,closeModal: () => void,diff --git a/packages/app/src/react/features/embodiments/embodiment-helper.ts b/packages/app/src/react/features/embodiments/embodiment-helper.tsindex 8bddd543..ae2eccf6 100644--- a/packages/app/src/react/features/embodiments/embodiment-helper.ts+++ b/packages/app/src/react/features/embodiments/embodiment-helper.ts@@ -12,6 +12,7 @@ import {getEmbodimentDescription,getEmbodimentIcon,getEmbodimentTitle,+ getFormPreviewDialog,} from './embodiment-configs';type AgentSetting = {@@ -142,6 +143,20 @@ export function structureAgentSetting();}+ if (key === EMBODIMENT_TYPE.FORM) {+ result.dialogComponent = getFormPreviewDialog(+ modalHandlers.activeModal === key, // Pass visibility state+ modalHandlers.closeModal,+ modalHandlers.agent,+ agentData.agentId,+ modalHandlers.embodimentsData?.find(+ (e) => e.aiAgentId === agentData.agentId && e.type === EMBODIMENT_TYPE.FORM,+ ),+ modalHandlers.refreshEmbodiments,+ modalHandlers.activeModal,+ );+ }+// Add code snippet modal for chat bot (preload when it should be visible)// Note: iframe-based components are conditionally rendered to allow reload as requestedif (key === EMBODIMENT_TYPE.CHAT_BOT && shouldCodeSnippetVisible(key, agentData)) {diff --git a/packages/app/src/react/features/embodiments/post-deployment-modal.tsx b/packages/app/src/react/features/embodiments/post-deployment-modal.tsxindex 701ea1d2..a1fef692 100644--- a/packages/app/src/react/features/embodiments/post-deployment-modal.tsx+++ b/packages/app/src/react/features/embodiments/post-deployment-modal.tsx@@ -327,6 +327,35 @@ function PostDeploymentModal({);}}+ // Form Preview+ else if (key === EMBODIMENT_TYPE.FORM) {+ if (setting.openCodeSnippet) {+ buttons.push(+ <button+ key={'configuration-' + EMBODIMENT_TYPE.FORM}+ className="flex items-center px-2 py-1 h-8 text-xl text-blue-600 hover:bg-smythos-blue-500 hover:text-white rounded"+ onClick={() => setting.openModal()}+ type="button"+ aria-label="Configuration"+ >+ <FaSliders />+ </button>,+ );+ }+ if (setting.openModal) {+ buttons.push(+ <Button+ key="get-code"+ label="Get Code"+ variant="tertiary"+ className="px-3 py-1 h-8 text-xs"+ handleClick={() => onOpenChatbotPanel()}+ aria-label="Get Code"+ type="button"+ />,+ );+ }+ }// LLMelse if (key === EMBODIMENT_TYPE.LLM) {buttons.push(diff --git a/packages/app/src/react/shared/types/api-results.types.ts b/packages/app/src/react/shared/types/api-results.types.tsindex 1cbc7bf3..e9c7b49a 100644--- a/packages/app/src/react/shared/types/api-results.types.ts+++ b/packages/app/src/react/shared/types/api-results.types.ts@@ -90,6 +90,11 @@ export interface DeploymentWithAgentSnapshot extends Deployment {aiAgent: { name: string; domain: { name: string; id: string }[] };}+export interface FormPreviewEmbodimentData {+ name: string;+ allowedDomains: string[];+}+export interface ChatbotEmbodimentData {name: string;introMessage: string;diff --git a/packages/app/src/react/shared/types/embodiment.types.ts b/packages/app/src/react/shared/types/embodiment.types.tsindex fef41ad3..d3064255 100644--- a/packages/app/src/react/shared/types/embodiment.types.ts+++ b/packages/app/src/react/shared/types/embodiment.types.ts@@ -35,6 +35,11 @@ export type TChatBotProperties = {allowFileAttachments?: boolean;};+export type TFormPreviewProperties = {+ name: string;+ allowedDomains: string[];+};+export type TGptEmbodimentProperties = {humanName: string;modelName: string;