mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-05-25 18:55:19 +02:00
Add test profiles and overhaul testing
This commit is contained in:
parent
8c1b5346f3
commit
768c5749a0
30 changed files with 3473 additions and 1644 deletions
|
|
@ -4,16 +4,15 @@ import { useEffect, useState, useMemo, useCallback } from "react";
|
|||
import { z } from "zod";
|
||||
import { PlaygroundChat } from "../../../lib/types/types";
|
||||
import { Workflow } from "../../../lib/types/workflow_types";
|
||||
import { SimulationData } from "../../../lib/types/testing_types";
|
||||
import { SimulationScenarioData } from "../../../lib/types/testing_types";
|
||||
import { Chat } from "./chat";
|
||||
import { useSearchParams, useRouter } from "next/navigation";
|
||||
import { ActionButton, Pane } from "../workflow/pane";
|
||||
import { apiV1 } from "rowboat-shared";
|
||||
import { EllipsisVerticalIcon, MessageSquarePlusIcon, PlayIcon } from "lucide-react";
|
||||
import { getScenario } from "../../../actions/simulation_actions";
|
||||
import { getScenario } from "../../../actions/testing_actions";
|
||||
import clsx from "clsx";
|
||||
|
||||
import { TestProfile, TestScenario } from "@/app/lib/types/testing_types";
|
||||
import { WithStringId } from "@/app/lib/types/types";
|
||||
function SimulateLabel() {
|
||||
return <span>Simulate<sup className="pl-1">beta</sup></span>;
|
||||
}
|
||||
|
|
@ -25,18 +24,16 @@ export function App({
|
|||
projectId,
|
||||
workflow,
|
||||
messageSubscriber,
|
||||
initialTestProfile,
|
||||
}: {
|
||||
hidden?: boolean;
|
||||
projectId: string;
|
||||
workflow: z.infer<typeof Workflow>;
|
||||
messageSubscriber?: (messages: z.infer<typeof apiV1.ChatMessage>[]) => void;
|
||||
initialTestProfile: z.infer<typeof TestProfile>;
|
||||
}) {
|
||||
const searchParams = useSearchParams();
|
||||
const router = useRouter();
|
||||
const initialChatId = useMemo(() => searchParams.get('chatId'), [searchParams]);
|
||||
const [existingChatId, setExistingChatId] = useState<string | null>(initialChatId);
|
||||
const [loadingChat, setLoadingChat] = useState<boolean>(false);
|
||||
const [counter, setCounter] = useState<number>(0);
|
||||
const [testProfile, setTestProfile] = useState<z.infer<typeof TestProfile>>(initialTestProfile);
|
||||
const [chat, setChat] = useState<z.infer<typeof PlaygroundChat>>({
|
||||
projectId,
|
||||
createdAt: new Date().toISOString(),
|
||||
|
|
@ -45,49 +42,45 @@ export function App({
|
|||
systemMessage: defaultSystemMessage,
|
||||
});
|
||||
|
||||
const beginSimulation = useCallback((data: z.infer<typeof SimulationData>) => {
|
||||
setExistingChatId(null);
|
||||
setLoadingChat(true);
|
||||
function handleTestProfileChange(profile: WithStringId<z.infer<typeof TestProfile>>) {
|
||||
setTestProfile(profile);
|
||||
setCounter(counter + 1);
|
||||
setChat({
|
||||
projectId,
|
||||
createdAt: new Date().toISOString(),
|
||||
messages: [],
|
||||
simulated: true,
|
||||
simulationData: data,
|
||||
systemMessage: 'context' in data ? data.context : '',
|
||||
});
|
||||
}, [counter, projectId]);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const scenarioId = localStorage.getItem('pendingScenarioId');
|
||||
if (scenarioId && projectId) {
|
||||
console.log('Scenario Effect triggered:', { scenarioId, projectId });
|
||||
getScenario(projectId, scenarioId).then((scenario) => {
|
||||
console.log('Scenario data received:', scenario);
|
||||
beginSimulation({
|
||||
...scenario,
|
||||
systemMessage: scenario.context || '',
|
||||
} as z.infer<typeof SimulationScenarioData>);
|
||||
localStorage.removeItem('pendingScenarioId');
|
||||
}).catch(error => {
|
||||
console.error('Error fetching scenario:', error);
|
||||
localStorage.removeItem('pendingScenarioId');
|
||||
});
|
||||
}
|
||||
}, [projectId, beginSimulation]);
|
||||
// const beginSimulation = useCallback((scenario: string) => {
|
||||
// setExistingChatId(null);
|
||||
// setLoadingChat(true);
|
||||
// setCounter(counter + 1);
|
||||
// setChat({
|
||||
// projectId,
|
||||
// createdAt: new Date().toISOString(),
|
||||
// messages: [],
|
||||
// simulated: true,
|
||||
// simulationScenario: scenario,
|
||||
// systemMessage: '',
|
||||
// });
|
||||
// }, [counter, projectId]);
|
||||
|
||||
// useEffect(() => {
|
||||
// const scenarioId = localStorage.getItem('pendingScenarioId');
|
||||
// if (scenarioId && projectId) {
|
||||
// console.log('Scenario Effect triggered:', { scenarioId, projectId });
|
||||
// getScenario(projectId, scenarioId).then((scenario) => {
|
||||
// console.log('Scenario data received:', scenario);
|
||||
// beginSimulation(scenario.description);
|
||||
// localStorage.removeItem('pendingScenarioId');
|
||||
// }).catch(error => {
|
||||
// console.error('Error fetching scenario:', error);
|
||||
// localStorage.removeItem('pendingScenarioId');
|
||||
// });
|
||||
// }
|
||||
// }, [projectId, beginSimulation]);
|
||||
|
||||
if (hidden) {
|
||||
return <></>;
|
||||
}
|
||||
|
||||
function handleSimulateButtonClick() {
|
||||
router.push(`/projects/${projectId}/simulation`);
|
||||
}
|
||||
|
||||
function handleNewChatButtonClick() {
|
||||
setExistingChatId(null);
|
||||
setLoadingChat(true);
|
||||
setCounter(counter + 1);
|
||||
setChat({
|
||||
projectId,
|
||||
|
|
@ -110,27 +103,18 @@ export function App({
|
|||
>
|
||||
New chat
|
||||
</ActionButton>,
|
||||
<ActionButton
|
||||
key="simulate"
|
||||
icon={<PlayIcon size={16} />}
|
||||
onClick={handleSimulateButtonClick}
|
||||
>
|
||||
Simulate
|
||||
</ActionButton>,
|
||||
]}
|
||||
>
|
||||
<div className="h-full overflow-auto">
|
||||
{loadingChat && <div className="flex justify-center items-center h-full">
|
||||
<Spinner />
|
||||
</div>}
|
||||
{!loadingChat && <Chat
|
||||
key={existingChatId || 'chat-' + counter}
|
||||
<Chat
|
||||
key={`chat-${counter}`}
|
||||
chat={chat}
|
||||
initialChatId={existingChatId || null}
|
||||
projectId={projectId}
|
||||
workflow={workflow}
|
||||
testProfile={testProfile}
|
||||
messageSubscriber={messageSubscriber}
|
||||
/>}
|
||||
onTestProfileChange={handleTestProfileChange}
|
||||
/>
|
||||
</div>
|
||||
</Pane>
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue