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.

Add Preview Functionality to Chatbot Deployment Modal (#158)

ali-inkco43d5fb61a5f1
diff --git a/packages/app/src/react/features/builder/contexts/deployment-sidebar.context.tsx b/packages/app/src/react/features/builder/contexts/deployment-sidebar.context.tsx
index 715cd2cc..e1156ebb 100644
--- a/packages/app/src/react/features/builder/contexts/deployment-sidebar.context.tsx
+++ b/packages/app/src/react/features/builder/contexts/deployment-sidebar.context.tsx
@@ -100,7 +100,7 @@ export const DeploymentSidebarProvider: FC<DeploymentSidebarProviderProps> = ({
});
const latestDeployment = useQuery({
- queryKey: ['latest-deployment', workspace.agent.id],
+ queryKey: ['latest_deployment', workspace.agent.id],
queryFn: () =>
fetch(`/api/page/builder/ai-agent/${workspace.agent.id}/deployments/latest`).then((res) =>
res.json(),
diff --git a/packages/app/src/react/features/embodiments/chatbot-embodiment-modal.tsx b/packages/app/src/react/features/embodiments/chatbot-embodiment-modal.tsx
index 4f267ff5..b4c2e7b9 100644
--- a/packages/app/src/react/features/embodiments/chatbot-embodiment-modal.tsx
+++ b/packages/app/src/react/features/embodiments/chatbot-embodiment-modal.tsx
@@ -1,6 +1,8 @@
+import { ArrowRightIcon } from '@radix-ui/react-icons';
import React, { useRef, useState } from 'react';
import { Button } from '../../shared/components/ui/newDesign/button';
import { Spinner } from '../../shared/components/ui/spinner';
+import { useDeploymentSidebarCtx } from '../builder/contexts/deployment-sidebar.context';
import ModalHeaderEmbodiment from './modal-header-embodiment';
/**
@@ -47,6 +49,11 @@ const ChatbotEmbodimentModal: React.FC<ChatbotEmbodimentModalProps> = ({
const [copied, setCopied] = useState(false);
const textareaRef = useRef<HTMLTextAreaElement>(null);
+ /**
+ * Get deployment status from the existing deployment sidebar context.
+ */
+ const { latestDeployment } = useDeploymentSidebarCtx();
+
if (typeof onClose !== 'function') {
throw new Error('ChatbotEmbodimentModal: onClose prop must be a function');
}
@@ -69,6 +76,14 @@ const ChatbotEmbodimentModal: React.FC<ChatbotEmbodimentModalProps> = ({
const allowFileAttachments = embodimentData?.properties?.allowFileAttachments;
const isUsingFullScreen = Boolean(isFullScreen);
+ /**
+ * Checks if the agent is deployed by verifying if there's a latest deployment.
+ * @returns {boolean} True if agent is deployed, false otherwise.
+ */
+ const isAgentDeployed = Boolean(
+ latestDeployment?.data?.deployment && !latestDeployment?.isLoading,
+ );
+
const chatbotContainer = `
<div id="smythos-chatbot-container"></div>
<!-- Chatbot Container: You can place it anywhere you want and style it as needed -->
@@ -117,6 +132,7 @@ const ChatbotEmbodimentModal: React.FC<ChatbotEmbodimentModalProps> = ({
/>
{/* Content */}
+
<div className="flex flex-col gap-4">
{isLoading ? (
/* Loading state */
@@ -142,6 +158,27 @@ const ChatbotEmbodimentModal: React.FC<ChatbotEmbodimentModalProps> = ({
{/* Code snippet container */}
<div className="flex flex-col gap-4">
+ <div className="flex justify-end items-center text-base -mb-4 -mt-4">
+ {isAgentDeployed ? (
+ <a
+ href={`${getFullDomain(domain)}/chatBot`}
+ target="_blank"
+ rel="noopener noreferrer"
+ >
+ <span className="text-[#707070] flex items-center gap-1">
+ Preview <ArrowRightIcon className="w-5 h-5" />
+ </span>
+ </a>
+ ) : (
+ <span
+ className="text-gray-400 flex items-center gap-1 cursor-not-allowed tooltip-trigger relative"
+ data-tooltip="Agent needs to be deployed first to preview it."
+ data-tooltip-position="left"
+ >
+ Preview <ArrowRightIcon className="w-5 h-5" />
+ </span>
+ )}
+ </div>
<textarea
ref={textareaRef}
readOnly