From 3ea08895b89386f60bc1a9915945aad3c82030d8 Mon Sep 17 00:00:00 2001 From: ramnique <30795890+ramnique@users.noreply.github.com> Date: Fri, 7 Mar 2025 01:23:13 +0530 Subject: [PATCH] Autorun chat in playground to show greeting --- apps/rowboat/app/lib/types/workflow_types.ts | 1 + .../projects/[projectId]/playground/app.tsx | 8 +++ .../projects/[projectId]/playground/chat.tsx | 30 ++++++------ .../[projectId]/playground/messages.tsx | 49 +++++++++---------- 4 files changed, 47 insertions(+), 41 deletions(-) diff --git a/apps/rowboat/app/lib/types/workflow_types.ts b/apps/rowboat/app/lib/types/workflow_types.ts index 160fc645..5d9599d8 100644 --- a/apps/rowboat/app/lib/types/workflow_types.ts +++ b/apps/rowboat/app/lib/types/workflow_types.ts @@ -27,6 +27,7 @@ export const WorkflowPrompt = z.object({ type: z.union([ z.literal('base_prompt'), z.literal('style_prompt'), + z.literal('greeting'), ]), prompt: z.string(), }); diff --git a/apps/rowboat/app/projects/[projectId]/playground/app.tsx b/apps/rowboat/app/projects/[projectId]/playground/app.tsx index 2b6db148..17d304d4 100644 --- a/apps/rowboat/app/projects/[projectId]/playground/app.tsx +++ b/apps/rowboat/app/projects/[projectId]/playground/app.tsx @@ -25,6 +25,7 @@ export function App({ }) { const [counter, setCounter] = useState(0); const [testProfile, setTestProfile] = useState | null>(null); + const [systemMessage, setSystemMessage] = useState(defaultSystemMessage); const [chat, setChat] = useState>({ projectId, createdAt: new Date().toISOString(), @@ -33,6 +34,11 @@ export function App({ systemMessage: defaultSystemMessage, }); + function handleSystemMessageChange(message: string) { + setSystemMessage(message); + setCounter(counter + 1); + } + function handleTestProfileChange(profile: WithStringId> | null) { setTestProfile(profile); setCounter(counter + 1); @@ -105,6 +111,8 @@ export function App({ testProfile={testProfile} messageSubscriber={messageSubscriber} onTestProfileChange={handleTestProfileChange} + systemMessage={systemMessage} + onSystemMessageChange={handleSystemMessageChange} /> diff --git a/apps/rowboat/app/projects/[projectId]/playground/chat.tsx b/apps/rowboat/app/projects/[projectId]/playground/chat.tsx index 8eadcd3a..01c3b5ef 100644 --- a/apps/rowboat/app/projects/[projectId]/playground/chat.tsx +++ b/apps/rowboat/app/projects/[projectId]/playground/chat.tsx @@ -24,6 +24,8 @@ export function Chat({ messageSubscriber, testProfile=null, onTestProfileChange, + systemMessage, + onSystemMessageChange, }: { chat: z.infer; projectId: string; @@ -31,6 +33,8 @@ export function Chat({ messageSubscriber?: (messages: z.infer[]) => void; testProfile?: z.infer | null; onTestProfileChange: (profile: WithStringId> | null) => void; + systemMessage: string; + onSystemMessageChange: (message: string) => void; }) { const [messages, setMessages] = useState[]>(chat.messages); const [loadingAssistantResponse, setLoadingAssistantResponse] = useState(false); @@ -42,7 +46,6 @@ export function Chat({ const [fetchResponseError, setFetchResponseError] = useState(null); const [lastAgenticRequest, setLastAgenticRequest] = useState(null); const [lastAgenticResponse, setLastAgenticResponse] = useState(null); - const [systemMessage, setSystemMessage] = useState(testProfile?.context); const [isProfileSelectorOpen, setIsProfileSelectorOpen] = useState(false); // collect published tool call results @@ -142,18 +145,17 @@ export function Chat({ } } - // if no messages, return - if (messages.length === 0) { - return; - } - // if last message is not from role user // or tool, return - const last = messages[messages.length - 1]; - if (fetchResponseError) { - return; + if (messages.length > 0) { + const last = messages[messages.length - 1]; + if (last.role !== 'user' && last.role !== 'tool') { + return; + } } - if (last.role !== 'user' && last.role !== 'tool') { + + // if there is an error, return + if (fetchResponseError) { return; } @@ -274,10 +276,6 @@ export function Chat({ navigator.clipboard.writeText(jsonString); } - function handleSystemMessageChange(message: string) { - setSystemMessage(message); - } - return
@@ -304,14 +302,14 @@ export function Chat({
{fetchResponseError && ( diff --git a/apps/rowboat/app/projects/[projectId]/playground/messages.tsx b/apps/rowboat/app/projects/[projectId]/playground/messages.tsx index 5b3c6045..dd8d667a 100644 --- a/apps/rowboat/app/projects/[projectId]/playground/messages.tsx +++ b/apps/rowboat/app/projects/[projectId]/playground/messages.tsx @@ -94,7 +94,7 @@ function ToolCalls({ messages, sender, workflow, - testProfile=null, + testProfile = null, systemMessage, }: { toolCalls: z.infer['tool_calls']; @@ -143,7 +143,7 @@ function ToolCall({ messages, sender, workflow, - testProfile=null, + testProfile = null, systemMessage, }: { toolCall: z.infer['tool_calls'][number]; @@ -186,8 +186,8 @@ function ToolCall({ sender={sender} />; } - if (!matchingWorkflowTool || - matchingWorkflowTool.mockTool || + if (!matchingWorkflowTool || + matchingWorkflowTool.mockTool || (testProfile && testProfile.mockTools)) { return void, - locked: boolean + locked?: boolean, }) { - return ( -
-
CONTEXT
- -
- ); + return
+ +
; } export function Messages({ projectId, - systemMessage, messages, toolCallResults, handleToolCallResults, loadingAssistantResponse, loadingUserResponse, workflow, - testProfile=null, + testProfile = null, + systemMessage, onSystemMessageChange, }: { projectId: string; - systemMessage: string | undefined; messages: z.infer[]; toolCallResults: Record>; handleToolCallResults: (results: z.infer[]) => void; @@ -637,6 +635,7 @@ export function Messages({ loadingUserResponse: boolean; workflow: z.infer; testProfile: z.infer | null; + systemMessage: string | undefined; onSystemMessageChange: (message: string) => void; }) { const messagesEndRef = useRef(null); @@ -652,7 +651,7 @@ export function Messages({ 0} + locked={testProfile !== null} /> {messages.map((message, index) => { if (message.role === 'assistant') {