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.

Refactor FormEmbodimentModal to utilize useAgentEndpointComponents hook for improved agent endpoint data retrieval. Removed legacy useAgentComponentsData hook and streamlined component imports for better organization.

Muhammad Hamza Khane9567ded7c32
diff --git a/packages/app/src/react/features/embodiments/form-embodiment-modal.tsx b/packages/app/src/react/features/embodiments/form-embodiment-modal.tsx
index d653c6b5..7eb99f5d 100644
--- a/packages/app/src/react/features/embodiments/form-embodiment-modal.tsx
+++ b/packages/app/src/react/features/embodiments/form-embodiment-modal.tsx
@@ -1,38 +1,11 @@
+import { useAgentEndpointComponents } from '@src/react/features/embodiments/hooks/use-agent-endpoint-components';
+import ModalHeaderEmbodiment from '@src/react/features/embodiments/modal-header-embodiment';
+import { Button } from '@src/react/shared/components/ui/newDesign/button';
+import { Spinner } from '@src/react/shared/components/ui/spinner';
import { ArrowRightIcon } from 'lucide-react';
-import React, { useEffect, 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';
+import { FC, useEffect, useRef, useState } from 'react';
// Import the useAgent hook for fallback when workspace is not available
-import { useAgent } from '../../shared/hooks/agent';
-
-/**
- * Simple hook to get agent components data
- * Uses workspace if available, otherwise falls back to API
- */
-const useAgentComponentsData = (agentId?: string) => {
- // Try to get data from workspace first (builder context)
- const workspaceData = window.workspace?.agent?.data;
-
- // Fallback to API if no workspace data and agentId provided
- const { data: apiData, isLoading } = useAgent(agentId || '', {
- enabled: !!agentId && !workspaceData,
- refetchOnWindowFocus: false,
- });
-
- // Use workspace data if available, otherwise use API data
- const agentData = workspaceData || apiData?.data;
-
- return {
- components:
- agentData?.components?.filter(
- (component: any) =>
- component.inputs && component.inputs.length > 0 && component.data?.endpoint,
- ) || [],
- isLoading: !workspaceData && isLoading,
- };
-};
/**
* Props for the FormEmbodimentModal component.
@@ -71,7 +44,7 @@ export interface FormEmbodimentModalProps {
* @param {FormEmbodimentModalProps} props - The component props.
* @returns {JSX.Element} The rendered modal.
*/
-const FormEmbodimentModal: React.FC<FormEmbodimentModalProps> = ({
+const FormEmbodimentModal: FC<FormEmbodimentModalProps> = ({
onClose,
domain = 'your-domain.com',
isLoading = false,
@@ -83,7 +56,7 @@ const FormEmbodimentModal: React.FC<FormEmbodimentModalProps> = ({
const textareaRef = useRef<HTMLTextAreaElement>(null);
// Get agent components data (from workspace or API)
- const { components, isLoading: isComponentsLoading } = useAgentComponentsData(propAgentId);
+ const { components, isLoading: isComponentsLoading } = useAgentEndpointComponents(propAgentId);
if (typeof onClose !== 'function') {
throw new Error('FormEmbodimentModal: onClose prop must be a function');
diff --git a/packages/app/src/react/features/embodiments/hooks/use-agent-endpoint-components.tsx b/packages/app/src/react/features/embodiments/hooks/use-agent-endpoint-components.tsx
new file mode 100644
index 00000000..3c24d75f
--- /dev/null
+++ b/packages/app/src/react/features/embodiments/hooks/use-agent-endpoint-components.tsx
@@ -0,0 +1,28 @@
+import { useAgent } from '@src/react/shared/hooks/agent';
+
+/**
+ * Simple hook to get agent endpoint components data
+ * Uses workspace if available, otherwise falls back to API
+ */
+export const useAgentEndpointComponents = (agentId?: string) => {
+ // Try to get data from workspace first (builder context)
+ const workspaceData = window.workspace?.agent?.data;
+
+ // Fallback to API if no workspace data and agentId provided
+ const { data: apiData, isLoading } = useAgent(agentId || '', {
+ enabled: !!agentId && !workspaceData,
+ refetchOnWindowFocus: false,
+ });
+
+ // Use workspace data if available, otherwise use API data
+ const agentData = workspaceData || apiData?.data;
+
+ return {
+ components:
+ agentData?.components?.filter(
+ (component: any) =>
+ component.inputs && component.inputs.length > 0 && component.data?.endpoint,
+ ) || [],
+ isLoading: !workspaceData && isLoading,
+ };
+};