rowboat/apps/rowboat/app/projects/[projectId]/playground/app.tsx

98 lines
3.1 KiB
TypeScript
Raw Normal View History

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);
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,
});
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
}
function handleNewChatButtonClick() {
2025-01-13 15:31:31 +05:30
setCounter(counter + 1);
setChat({
projectId,
createdAt: new Date().toISOString(),
messages: [],
simulated: false,
systemMessage: defaultSystemMessage,
2025-01-13 15:31:31 +05:30
});
}
if (hidden) {
return <></>;
}
return (
<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>,
]}
>
<div className="h-full overflow-auto">
2025-02-27 23:42:04 +05:30
<Chat
key={`chat-${counter}`}
chat={chat}
projectId={projectId}
workflow={workflow}
2025-02-27 23:42:04 +05:30
testProfile={testProfile}
messageSubscriber={messageSubscriber}
2025-02-27 23:42:04 +05:30
onTestProfileChange={handleTestProfileChange}
systemMessage={systemMessage}
onSystemMessageChange={handleSystemMessageChange}
2025-03-20 17:05:13 +05:30
mcpServerUrls={mcpServerUrls}
toolWebhookUrl={toolWebhookUrl}
2025-02-27 23:42:04 +05:30
/>
</div>
</Pane>
);
2025-01-13 15:31:31 +05:30
}