2025-01-13 15:31:31 +05:30
|
|
|
'use client';
|
2025-04-10 13:22:16 +05:30
|
|
|
import { useState, useCallback, useRef } from "react";
|
2025-01-13 15:31:31 +05:30
|
|
|
import { z } from "zod";
|
2025-06-23 08:38:26 +05:30
|
|
|
import { MCPServer, Message, PlaygroundChat } from "@/app/lib/types/types";
|
2025-05-15 18:24:25 +05:30
|
|
|
import { Workflow, WorkflowTool } from "@/app/lib/types/workflow_types";
|
2025-03-27 18:52:17 +05:30
|
|
|
import { Chat } from "./components/chat";
|
|
|
|
|
import { Panel } from "@/components/common/panel-common";
|
|
|
|
|
import { Button } from "@/components/ui/button";
|
2025-04-14 14:29:50 +05:30
|
|
|
import { Tooltip } from "@heroui/react";
|
2025-02-27 23:42:04 +05:30
|
|
|
import { WithStringId } from "@/app/lib/types/types";
|
2025-07-13 11:51:27 +05:30
|
|
|
import { CheckIcon, CopyIcon, PlusIcon, UserIcon, InfoIcon, BugIcon, BugOffIcon, CodeIcon } from "lucide-react";
|
2025-04-14 14:29:50 +05:30
|
|
|
import { clsx } from "clsx";
|
2025-01-13 15:31:31 +05:30
|
|
|
|
|
|
|
|
const defaultSystemMessage = '';
|
|
|
|
|
|
|
|
|
|
export function App({
|
|
|
|
|
hidden = false,
|
|
|
|
|
projectId,
|
|
|
|
|
workflow,
|
|
|
|
|
messageSubscriber,
|
2025-03-20 17:05:13 +05:30
|
|
|
mcpServerUrls,
|
|
|
|
|
toolWebhookUrl,
|
2025-04-14 14:29:50 +05:30
|
|
|
isInitialState = false,
|
|
|
|
|
onPanelClick,
|
2025-05-15 18:24:25 +05:30
|
|
|
projectTools,
|
2025-07-13 16:45:14 +05:30
|
|
|
triggerCopilotChat,
|
2025-01-13 15:31:31 +05:30
|
|
|
}: {
|
|
|
|
|
hidden?: boolean;
|
|
|
|
|
projectId: string;
|
|
|
|
|
workflow: z.infer<typeof Workflow>;
|
2025-06-23 08:38:26 +05:30
|
|
|
messageSubscriber?: (messages: z.infer<typeof Message>[]) => void;
|
2025-03-20 17:05:13 +05:30
|
|
|
mcpServerUrls: Array<z.infer<typeof MCPServer>>;
|
|
|
|
|
toolWebhookUrl: string;
|
2025-04-14 14:29:50 +05:30
|
|
|
isInitialState?: boolean;
|
|
|
|
|
onPanelClick?: () => void;
|
2025-05-15 18:24:25 +05:30
|
|
|
projectTools: z.infer<typeof WorkflowTool>[];
|
2025-07-13 16:45:14 +05:30
|
|
|
triggerCopilotChat?: (message: string) => void;
|
2025-01-13 15:31:31 +05:30
|
|
|
}) {
|
2025-04-10 19:21:00 +05:30
|
|
|
const [counter, setCounter] = useState<number>(0);
|
2025-03-07 01:23:13 +05:30
|
|
|
const [systemMessage, setSystemMessage] = useState<string>(defaultSystemMessage);
|
2025-05-07 15:56:30 +05:30
|
|
|
const [showDebugMessages, setShowDebugMessages] = useState<boolean>(true);
|
2025-01-13 15:31:31 +05:30
|
|
|
const [chat, setChat] = useState<z.infer<typeof PlaygroundChat>>({
|
|
|
|
|
projectId,
|
|
|
|
|
createdAt: new Date().toISOString(),
|
|
|
|
|
messages: [],
|
|
|
|
|
simulated: false,
|
|
|
|
|
systemMessage: defaultSystemMessage,
|
|
|
|
|
});
|
2025-03-27 18:52:17 +05:30
|
|
|
const [isProfileSelectorOpen, setIsProfileSelectorOpen] = useState(false);
|
|
|
|
|
const [showCopySuccess, setShowCopySuccess] = useState(false);
|
2025-04-10 13:22:16 +05:30
|
|
|
const getCopyContentRef = useRef<(() => string) | null>(null);
|
2025-01-13 15:31:31 +05:30
|
|
|
|
2025-03-07 01:23:13 +05:30
|
|
|
function handleSystemMessageChange(message: string) {
|
|
|
|
|
setSystemMessage(message);
|
2025-04-10 19:21:00 +05:30
|
|
|
setCounter(counter + 1);
|
2025-03-07 01:23:13 +05:30
|
|
|
}
|
|
|
|
|
|
2025-02-13 17:20:39 +05:30
|
|
|
function handleNewChatButtonClick() {
|
2025-04-10 19:21:00 +05:30
|
|
|
setCounter(counter + 1);
|
2025-01-13 15:31:31 +05:30
|
|
|
setChat({
|
|
|
|
|
projectId,
|
|
|
|
|
createdAt: new Date().toISOString(),
|
|
|
|
|
messages: [],
|
2025-02-13 17:20:39 +05:30
|
|
|
simulated: false,
|
|
|
|
|
systemMessage: defaultSystemMessage,
|
2025-01-13 15:31:31 +05:30
|
|
|
});
|
2025-04-10 13:22:16 +05:30
|
|
|
setSystemMessage(defaultSystemMessage);
|
2025-01-13 15:31:31 +05:30
|
|
|
}
|
|
|
|
|
|
2025-04-10 13:22:16 +05:30
|
|
|
const handleCopyJson = useCallback(() => {
|
|
|
|
|
if (getCopyContentRef.current) {
|
|
|
|
|
try {
|
|
|
|
|
const data = getCopyContentRef.current();
|
|
|
|
|
navigator.clipboard.writeText(data);
|
|
|
|
|
setShowCopySuccess(true);
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
setShowCopySuccess(false);
|
|
|
|
|
}, 2000);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Error copying:', error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, []);
|
2025-03-27 18:52:17 +05:30
|
|
|
|
2025-03-25 01:42:22 +05:30
|
|
|
if (hidden) {
|
|
|
|
|
return <></>;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-13 17:20:39 +05:30
|
|
|
return (
|
2025-03-27 18:52:17 +05:30
|
|
|
<>
|
|
|
|
|
<Panel
|
2025-04-14 14:29:50 +05:30
|
|
|
variant="playground"
|
|
|
|
|
tourTarget="playground"
|
2025-03-27 18:52:17 +05:30
|
|
|
title={
|
|
|
|
|
<div className="flex items-center gap-3">
|
2025-04-14 14:29:50 +05:30
|
|
|
<div className="flex items-center gap-2">
|
2025-07-11 21:06:49 +05:30
|
|
|
<div className="font-semibold text-zinc-700 dark:text-zinc-300">
|
|
|
|
|
Playground
|
2025-04-14 14:29:50 +05:30
|
|
|
</div>
|
|
|
|
|
<Tooltip content="Test your workflow and chat with your agents in real-time">
|
|
|
|
|
<InfoIcon className="w-4 h-4 text-gray-400 cursor-help" />
|
|
|
|
|
</Tooltip>
|
2025-03-27 18:52:17 +05:30
|
|
|
</div>
|
|
|
|
|
<Button
|
|
|
|
|
variant="primary"
|
|
|
|
|
size="sm"
|
|
|
|
|
onClick={handleNewChatButtonClick}
|
|
|
|
|
className="bg-blue-50 text-blue-700 hover:bg-blue-100"
|
|
|
|
|
showHoverContent={true}
|
|
|
|
|
hoverContent="New chat"
|
|
|
|
|
>
|
|
|
|
|
<PlusIcon className="w-4 h-4" />
|
|
|
|
|
</Button>
|
2025-05-07 15:56:30 +05:30
|
|
|
<Button
|
|
|
|
|
variant="primary"
|
|
|
|
|
size="sm"
|
|
|
|
|
onClick={() => setShowDebugMessages(!showDebugMessages)}
|
|
|
|
|
className={showDebugMessages ? "bg-blue-50 text-blue-700 hover:bg-blue-100" : "bg-gray-50 text-gray-500 hover:bg-gray-100"}
|
|
|
|
|
showHoverContent={true}
|
|
|
|
|
hoverContent={showDebugMessages ? "Hide debug messages" : "Show debug messages"}
|
|
|
|
|
>
|
|
|
|
|
{showDebugMessages ? (
|
|
|
|
|
<BugIcon className="w-4 h-4" />
|
|
|
|
|
) : (
|
|
|
|
|
<BugOffIcon className="w-4 h-4" />
|
|
|
|
|
)}
|
|
|
|
|
</Button>
|
2025-03-27 18:52:17 +05:30
|
|
|
</div>
|
|
|
|
|
}
|
|
|
|
|
rightActions={
|
|
|
|
|
<div className="flex items-center gap-3">
|
|
|
|
|
<Button
|
|
|
|
|
variant="secondary"
|
|
|
|
|
size="sm"
|
|
|
|
|
onClick={handleCopyJson}
|
|
|
|
|
showHoverContent={true}
|
|
|
|
|
hoverContent={showCopySuccess ? "Copied" : "Copy JSON"}
|
|
|
|
|
>
|
|
|
|
|
{showCopySuccess ? (
|
|
|
|
|
<CheckIcon className="w-4 h-4" />
|
|
|
|
|
) : (
|
|
|
|
|
<CopyIcon className="w-4 h-4" />
|
|
|
|
|
)}
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
}
|
2025-04-14 14:29:50 +05:30
|
|
|
onClick={onPanelClick}
|
2025-03-27 18:52:17 +05:30
|
|
|
>
|
|
|
|
|
<div className="h-full overflow-auto px-4 py-4">
|
|
|
|
|
<Chat
|
2025-04-10 19:21:00 +05:30
|
|
|
key={`chat-${counter}`}
|
2025-03-27 18:52:17 +05:30
|
|
|
chat={chat}
|
|
|
|
|
projectId={projectId}
|
|
|
|
|
workflow={workflow}
|
|
|
|
|
messageSubscriber={messageSubscriber}
|
|
|
|
|
systemMessage={systemMessage}
|
|
|
|
|
onSystemMessageChange={handleSystemMessageChange}
|
|
|
|
|
mcpServerUrls={mcpServerUrls}
|
|
|
|
|
toolWebhookUrl={toolWebhookUrl}
|
2025-04-10 13:22:16 +05:30
|
|
|
onCopyClick={(fn) => { getCopyContentRef.current = fn; }}
|
2025-05-07 15:56:30 +05:30
|
|
|
showDebugMessages={showDebugMessages}
|
2025-05-15 18:24:25 +05:30
|
|
|
projectTools={projectTools}
|
2025-07-13 16:45:14 +05:30
|
|
|
triggerCopilotChat={triggerCopilotChat}
|
2025-03-27 18:52:17 +05:30
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</Panel>
|
|
|
|
|
</>
|
2025-02-13 17:20:39 +05:30
|
|
|
);
|
2025-01-13 15:31:31 +05:30
|
|
|
}
|