2025-01-13 15:31:31 +05:30
|
|
|
'use client';
|
2025-03-10 16:56:16 +05:30
|
|
|
import { useState } from "react";
|
2025-01-13 15:31:31 +05:30
|
|
|
import { z } from "zod";
|
2025-03-20 17:05:13 +05:30
|
|
|
import { MCPServer, PlaygroundChat } from "../../../lib/types/types";
|
2025-02-14 13:36:01 +05:30
|
|
|
import { Workflow } from "../../../lib/types/workflow_types";
|
2025-01-13 15:31:31 +05:30
|
|
|
import { Chat } from "./chat";
|
|
|
|
|
import { ActionButton, Pane } from "../workflow/pane";
|
|
|
|
|
import { apiV1 } from "rowboat-shared";
|
2025-03-10 16:56:16 +05:30
|
|
|
import { MessageSquarePlusIcon } from "lucide-react";
|
|
|
|
|
import { TestProfile } from "@/app/lib/types/testing_types";
|
2025-02-27 23:42:04 +05:30
|
|
|
import { WithStringId } from "@/app/lib/types/types";
|
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-01-13 15:31:31 +05:30
|
|
|
}: {
|
|
|
|
|
hidden?: boolean;
|
|
|
|
|
projectId: string;
|
|
|
|
|
workflow: z.infer<typeof Workflow>;
|
|
|
|
|
messageSubscriber?: (messages: z.infer<typeof apiV1.ChatMessage>[]) => void;
|
2025-03-20 17:05:13 +05:30
|
|
|
mcpServerUrls: Array<z.infer<typeof MCPServer>>;
|
|
|
|
|
toolWebhookUrl: string;
|
2025-01-13 15:31:31 +05:30
|
|
|
}) {
|
|
|
|
|
const [counter, setCounter] = useState<number>(0);
|
2025-03-03 19:39:51 +05:30
|
|
|
const [testProfile, setTestProfile] = useState<z.infer<typeof TestProfile> | null>(null);
|
2025-03-07 01:23:13 +05:30
|
|
|
const [systemMessage, setSystemMessage] = useState<string>(defaultSystemMessage);
|
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-07 01:23:13 +05:30
|
|
|
function handleSystemMessageChange(message: string) {
|
|
|
|
|
setSystemMessage(message);
|
|
|
|
|
setCounter(counter + 1);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-03 19:39:51 +05:30
|
|
|
function handleTestProfileChange(profile: WithStringId<z.infer<typeof TestProfile>> | null) {
|
2025-02-27 23:42:04 +05:30
|
|
|
setTestProfile(profile);
|
2025-01-13 15:31:31 +05:30
|
|
|
setCounter(counter + 1);
|
2025-02-27 23:42:04 +05:30
|
|
|
}
|
2025-02-13 17:20:39 +05:30
|
|
|
|
|
|
|
|
function handleNewChatButtonClick() {
|
2025-01-13 15:31:31 +05:30
|
|
|
setCounter(counter + 1);
|
|
|
|
|
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-03-25 01:42:22 +05:30
|
|
|
if (hidden) {
|
|
|
|
|
return <></>;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-13 17:20:39 +05:30
|
|
|
return (
|
2025-02-17 16:37:54 +05:30
|
|
|
<Pane
|
|
|
|
|
title="PLAYGROUND"
|
|
|
|
|
tooltip="Test your agents and see their responses in this interactive chat interface"
|
|
|
|
|
actions={[
|
|
|
|
|
<ActionButton
|
|
|
|
|
key="new-chat"
|
|
|
|
|
icon={<MessageSquarePlusIcon size={16} />}
|
|
|
|
|
onClick={handleNewChatButtonClick}
|
|
|
|
|
>
|
|
|
|
|
New chat
|
|
|
|
|
</ActionButton>,
|
|
|
|
|
]}
|
|
|
|
|
>
|
2025-02-13 17:20:39 +05:30
|
|
|
<div className="h-full overflow-auto">
|
2025-02-27 23:42:04 +05:30
|
|
|
<Chat
|
|
|
|
|
key={`chat-${counter}`}
|
2025-02-13 17:20:39 +05:30
|
|
|
chat={chat}
|
|
|
|
|
projectId={projectId}
|
|
|
|
|
workflow={workflow}
|
2025-02-27 23:42:04 +05:30
|
|
|
testProfile={testProfile}
|
2025-02-13 17:20:39 +05:30
|
|
|
messageSubscriber={messageSubscriber}
|
2025-02-27 23:42:04 +05:30
|
|
|
onTestProfileChange={handleTestProfileChange}
|
2025-03-07 01:23:13 +05:30
|
|
|
systemMessage={systemMessage}
|
|
|
|
|
onSystemMessageChange={handleSystemMessageChange}
|
2025-03-20 17:05:13 +05:30
|
|
|
mcpServerUrls={mcpServerUrls}
|
|
|
|
|
toolWebhookUrl={toolWebhookUrl}
|
2025-02-27 23:42:04 +05:30
|
|
|
/>
|
2025-02-13 17:20:39 +05:30
|
|
|
</div>
|
|
|
|
|
</Pane>
|
|
|
|
|
);
|
2025-01-13 15:31:31 +05:30
|
|
|
}
|