Add session to agents (#4216)
Co-authored-by: Douwe Osinga <douwe@squareup.com> Co-authored-by: Jack Amadeo <jackamadeo@squareup.com> Co-authored-by: Jack Amadeo <jackamadeo@block.xyz>
This commit is contained in:
@@ -13,7 +13,6 @@ import { DirSwitcher } from './bottom_menu/DirSwitcher';
|
||||
import ModelsBottomBar from './settings/models/bottom_bar/ModelsBottomBar';
|
||||
import { BottomMenuModeSelection } from './bottom_menu/BottomMenuModeSelection';
|
||||
import { AlertType, useAlerts } from './alerts';
|
||||
import { useToolCount } from './alerts/useToolCount';
|
||||
import { useConfig } from './ConfigContext';
|
||||
import { useModelAndProvider } from './ModelAndProviderContext';
|
||||
import { useWhisper } from '../hooks/useWhisper';
|
||||
@@ -58,6 +57,7 @@ interface ModelLimit {
|
||||
}
|
||||
|
||||
interface ChatInputProps {
|
||||
sessionId: string | null;
|
||||
handleSubmit: (e: React.FormEvent) => void;
|
||||
chatState: ChatState;
|
||||
onStop?: () => void;
|
||||
@@ -83,6 +83,7 @@ interface ChatInputProps {
|
||||
recipeConfig?: Recipe | null;
|
||||
recipeAccepted?: boolean;
|
||||
initialPrompt?: string;
|
||||
toolCount: number;
|
||||
autoSubmit: boolean;
|
||||
setAncestorMessages?: (messages: Message[]) => void;
|
||||
append?: (message: Message) => void;
|
||||
@@ -90,6 +91,7 @@ interface ChatInputProps {
|
||||
}
|
||||
|
||||
export default function ChatInput({
|
||||
sessionId,
|
||||
handleSubmit,
|
||||
chatState = ChatState.Idle,
|
||||
onStop,
|
||||
@@ -109,6 +111,7 @@ export default function ChatInput({
|
||||
recipeConfig,
|
||||
recipeAccepted,
|
||||
initialPrompt,
|
||||
toolCount,
|
||||
autoSubmit = false,
|
||||
append,
|
||||
setAncestorMessages,
|
||||
@@ -133,7 +136,6 @@ export default function ChatInput({
|
||||
const dropdownRef: React.RefObject<HTMLDivElement> = useRef<HTMLDivElement>(
|
||||
null
|
||||
) as React.RefObject<HTMLDivElement>;
|
||||
const toolCount = useToolCount();
|
||||
const { isCompacting, handleManualCompaction } = useContextManager();
|
||||
const { getProviders, read } = useConfig();
|
||||
const { getCurrentModelAndProvider, currentModel, currentProvider } = useModelAndProvider();
|
||||
@@ -296,33 +298,16 @@ export default function ChatInput({
|
||||
setHasUserTyped(false);
|
||||
}, [initialValue]); // Keep only initialValue as a dependency
|
||||
|
||||
// Track if we've already set the recipe prompt to avoid re-setting it
|
||||
const hasSetRecipePromptRef = useRef(false);
|
||||
|
||||
// Handle recipe prompt updates
|
||||
useEffect(() => {
|
||||
// If recipe is accepted and we have an initial prompt, and no messages yet, and we haven't set it before
|
||||
if (
|
||||
recipeAccepted &&
|
||||
initialPrompt &&
|
||||
messages.length === 0 &&
|
||||
!hasSetRecipePromptRef.current
|
||||
) {
|
||||
if (recipeAccepted && initialPrompt && messages.length === 0) {
|
||||
setDisplayValue(initialPrompt);
|
||||
setValue(initialPrompt);
|
||||
hasSetRecipePromptRef.current = true;
|
||||
setTimeout(() => {
|
||||
textAreaRef.current?.focus();
|
||||
}, 0);
|
||||
}
|
||||
// we don't need hasSetRecipePromptRef in the dependency array because it is a ref that persists across renders
|
||||
}, [recipeAccepted, initialPrompt, messages.length]);
|
||||
|
||||
// Reset the recipe prompt flag when the recipe changes or messages are added
|
||||
useEffect(() => {
|
||||
if (messages.length > 0 || !recipeAccepted || !initialPrompt) {
|
||||
hasSetRecipePromptRef.current = false;
|
||||
}
|
||||
}, [recipeAccepted, initialPrompt, messages.length]);
|
||||
|
||||
// Draft functionality - load draft if no initial value or recipe
|
||||
@@ -920,6 +905,14 @@ export default function ChatInput({
|
||||
return true; // Return true if message was queued
|
||||
};
|
||||
|
||||
const canSubmit =
|
||||
!isLoading &&
|
||||
!isCompacting &&
|
||||
agentIsReady &&
|
||||
(displayValue.trim() ||
|
||||
pastedImages.some((img) => img.filePath && !img.error && !img.isLoading) ||
|
||||
allDroppedFiles.some((file) => !file.error && !file.isLoading));
|
||||
|
||||
const performSubmit = useCallback(
|
||||
(text?: string) => {
|
||||
const validPastedImageFilesPaths = pastedImages
|
||||
@@ -1061,13 +1054,6 @@ export default function ChatInput({
|
||||
return;
|
||||
}
|
||||
|
||||
const canSubmit =
|
||||
!isLoading &&
|
||||
!isCompacting &&
|
||||
agentIsReady &&
|
||||
(displayValue.trim() ||
|
||||
pastedImages.some((img) => img.filePath && !img.error && !img.isLoading) ||
|
||||
allDroppedFiles.some((file) => !file.error && !file.isLoading));
|
||||
if (canSubmit) {
|
||||
performSubmit();
|
||||
}
|
||||
@@ -1575,6 +1561,7 @@ export default function ChatInput({
|
||||
<Tooltip>
|
||||
<div>
|
||||
<ModelsBottomBar
|
||||
sessionId={sessionId}
|
||||
dropdownRef={dropdownRef}
|
||||
setView={setView}
|
||||
alerts={alerts}
|
||||
|
||||
Reference in New Issue
Block a user