🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(playground): empty message error when submitting all windows (#8686)
Leo Weigand2308495088d0
diff --git a/web/src/features/playground/page/context/index.tsx b/web/src/features/playground/page/context/index.tsxindex 0b828c1cc1..8bda02f8aa 100644--- a/web/src/features/playground/page/context/index.tsx+++ b/web/src/features/playground/page/context/index.tsx@@ -13,6 +13,7 @@ import { createEmptyMessage } from "@/src/components/ChatMessages/utils/createEmimport { useModelParams } from "@/src/features/playground/page/hooks/useModelParams";import usePlaygroundCache from "@/src/features/playground/page/hooks/usePlaygroundCache";import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";+import { showErrorToast } from "@/src/features/notifications/showErrorToast";import useProjectIdFromURL from "@/src/hooks/useProjectIdFromURL";import {ChatMessageRole,@@ -319,7 +320,7 @@ export const PlaygroundProvider: React.FC<PlaygroundProviderProps> = ({);if (finalMessages.length === 0) {- throw new Error("Please add at least one message with content");+ throw new Error("Please add at least one message with content.");}const leftOverVariables = extractVariables(@@ -422,8 +423,9 @@ export const PlaygroundProvider: React.FC<PlaygroundProviderProps> = ({isStructuredOutput: Boolean(structuredOutputSchema),});} catch (err) {- alert(err instanceof Error ? err.message : "An error occurred");- // TODO: add error handling via toast+ const errorMessage =+ err instanceof Error ? err.message : "An error occurred";+ showErrorToast("Error", errorMessage);} finally {setIsStreaming(false);}@@ -559,7 +561,22 @@ export const PlaygroundProvider: React.FC<PlaygroundProviderProps> = ({const handleGlobalExecute = () => {if (!isStreamingRef.current) {- handleSubmit(true);+ // Check if this window has any content at all (including placeholders)+ const hasAnyContent = messages.some((message) => {+ if (message.type === ChatMessageType.Placeholder) {+ return true; // Placeholders are considered content+ }+ if (typeof message.content === "string") {+ return message.content.trim().length > 0;+ }+ return true; // Non-string content (tool calls, etc.) is considered valid+ });++ if (hasAnyContent) {+ // Window has content - let it execute and show any validation errors+ handleSubmit(true).catch((err) => console.error(err));+ }+ // If no content, skip silently}};@@ -591,7 +608,7 @@ export const PlaygroundProvider: React.FC<PlaygroundProviderProps> = ({handleGlobalStop,);};- }, [windowId, handleSubmit, registerWindow, unregisterWindow]);+ }, [windowId, handleSubmit, registerWindow, unregisterWindow, messages]);// Keep ref in sync with state for external consumersuseEffect(() => {diff --git a/web/src/features/playground/page/hooks/useWindowCoordination.ts b/web/src/features/playground/page/hooks/useWindowCoordination.tsindex b495cde3a5..47d339287b 100644--- a/web/src/features/playground/page/hooks/useWindowCoordination.ts+++ b/web/src/features/playground/page/hooks/useWindowCoordination.ts@@ -1,9 +1,10 @@-import { useCallback, useEffect, useRef, useState } from "react";+import { useCallback, useRef, useState } from "react";import {type PlaygroundHandle,type WindowCoordinationReturn,PLAYGROUND_EVENTS,} from "../types";+import { showErrorToast } from "@/src/features/notifications/showErrorToast";/*** Playground window registry for coordinating actions across multiple playground windows@@ -33,7 +34,6 @@ const playgroundEventBus = new EventTarget();*/export const useWindowCoordination = (): WindowCoordinationReturn => {const [isExecutingAll, setIsExecutingAll] = useState(false);- const [executionVersion, setExecutionVersion] = useState(0);const executionTimeoutRef = useRef<NodeJS.Timeout | null>(null);/**@@ -96,44 +96,61 @@ export const useWindowCoordination = (): WindowCoordinationReturn => {return;}- setIsExecutingAll(true);-- // Clear any existing timeout- if (executionTimeoutRef.current) {- clearTimeout(executionTimeoutRef.current);- }-- // Dispatch execute-all event+ // Dispatch execute-all event firstplaygroundEventBus.dispatchEvent(new CustomEvent(PLAYGROUND_EVENTS.EXECUTE_ALL),);- // Set a timeout to reset the execution state- // This provides a fallback in case some windows don't respond- executionTimeoutRef.current = setTimeout(() => {- setIsExecutingAll(false);- }, 30000); // 30 second timeout-- // Monitor execution completion- const checkExecutionCompletion = () => {- const stillExecuting = Array.from(playgroundWindowRegistry.values()).some(+ // Check after a short delay if any windows started executing+ setTimeout(() => {+ const anyExecuting = Array.from(playgroundWindowRegistry.values()).some((handle) => handle.getIsStreaming(),);- if (!stillExecuting) {+ if (!anyExecuting) {+ // No windows are executing - they must all be empty+ showErrorToast(+ "No content to execute",+ "Please add at least one message with content to any window.",+ );setIsExecutingAll(false);+ } else {+ // At least one window is executing, set global state+ setIsExecutingAll(true);++ // Clear any existing timeoutif (executionTimeoutRef.current) {clearTimeout(executionTimeoutRef.current);- executionTimeoutRef.current = null;}- } else {- // Check again in a short interval- setTimeout(checkExecutionCompletion, 500);- }- };- // Start monitoring after a short delay to allow windows to start- setTimeout(checkExecutionCompletion, 1000);+ // Set a timeout to reset the execution state+ // This provides a fallback in case some windows don't respond+ executionTimeoutRef.current = setTimeout(() => {+ setIsExecutingAll(false);+ }, 30000); // 30 second timeout++ // Monitor execution completion+ const checkExecutionCompletion = () => {+ const stillExecuting = Array.from(+ playgroundWindowRegistry.values(),+ ).some((handle) => handle.getIsStreaming());++ if (!stillExecuting) {+ setIsExecutingAll(false);+ if (executionTimeoutRef.current) {+ clearTimeout(executionTimeoutRef.current);+ executionTimeoutRef.current = null;+ }+ } else {+ // Check again in a short interval+ setTimeout(checkExecutionCompletion, 500);+ }+ };++ // Start monitoring after a short delay to allow windows to start+ setTimeout(checkExecutionCompletion, 1000);+ }+ }, 500); // Check after 500ms}, []);/**@@ -184,34 +201,6 @@ export const useWindowCoordination = (): WindowCoordinationReturn => {return `Executing ${executingCount} of ${totalCount} windows`;}, []);- /**- * Cleanup function to clear timeouts when component unmounts- * Prevents memory leaks from lingering timeouts- */- useEffect(() => {- const handleExecutionChange = () => {- setExecutionVersion((v) => v + 1);- };-- playgroundEventBus.addEventListener(- PLAYGROUND_EVENTS.WINDOW_EXECUTION_STATE_CHANGE,- handleExecutionChange,- );-- return () => {- playgroundEventBus.removeEventListener(- PLAYGROUND_EVENTS.WINDOW_EXECUTION_STATE_CHANGE,- handleExecutionChange,- );-- if (executionTimeoutRef.current) {- clearTimeout(executionTimeoutRef.current);- }- };- }, []);-- executionVersion;-return {registerWindow,unregisterWindow,diff --git a/web/src/features/prompts/components/prompt-content-utils.tsx b/web/src/features/prompts/components/prompt-content-utils.tsxindex ebe59da580..29855e198e 100644--- a/web/src/features/prompts/components/prompt-content-utils.tsx+++ b/web/src/features/prompts/components/prompt-content-utils.tsx@@ -11,7 +11,12 @@ import { Button } from "@/src/components/ui/button";import { FileCode } from "lucide-react";const PromptVar = ({ name, isValid }: { name: string; isValid: boolean }) => (- <span className={cn(isValid ? "text-primary-accent" : "text-destructive")}>+ <span+ className={cn(+ isValid ? "text-primary-accent" : "text-destructive",+ "whitespace-nowrap",+ )}+ >{`{{${name}}}`}</span>);