Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions ui/desktop/src/hooks/useRecipeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const useRecipeManager = (chat: ChatType, recipe?: Recipe | null) => {

const messagesRef = useRef(messages);
const isCreatingRecipeRef = useRef(false);
const hasCheckedRecipeRef = useRef(false);

useEffect(() => {
messagesRef.current = messages;
Expand Down Expand Up @@ -54,6 +55,7 @@ export const useRecipeManager = (chat: ChatType, recipe?: Recipe | null) => {
setRecipeAccepted(false);
setIsParameterModalOpen(false);
setIsRecipeWarningModalOpen(false);
hasCheckedRecipeRef.current = false; // Reset check flag for new recipe

chatContext.setChat({
...chatContext.chat,
Expand All @@ -75,17 +77,27 @@ export const useRecipeManager = (chat: ChatType, recipe?: Recipe | null) => {

useEffect(() => {
const checkRecipeAcceptance = async () => {
// Only check once per recipe load
if (hasCheckedRecipeRef.current) {
return;
}

if (finalRecipe) {
// If the recipe comes from session metadata (not from navigation state),
// it means it was already accepted in a previous session, so auto-accept it
const isFromSessionMetadata = !recipe && finalRecipe;
const hasMessages = chat.messages.length > 0;
const isFromSessionMetadata = !recipe && finalRecipe && hasMessages;

if (isFromSessionMetadata) {
// Recipe loaded from session metadata should be automatically accepted
setRecipeAccepted(true);
setIsRecipeWarningModalOpen(false);
hasCheckedRecipeRef.current = true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we just move this to happen one time immediately after the early return check?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks makes sense, needed to put it after the check for the recipe so we handle the no recipe case.. the real issue here is its re-rendering multiple times so there is a race condition before the recipe is ready. This is a hack around that, will come back to that multiple rendering issue when we refactor this soon.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok got it

return;
}

hasCheckedRecipeRef.current = true;

try {
const hasAccepted = await window.electron.hasAcceptedRecipeBefore(finalRecipe);

Expand All @@ -108,7 +120,7 @@ export const useRecipeManager = (chat: ChatType, recipe?: Recipe | null) => {
};

checkRecipeAcceptance();
}, [finalRecipe, recipe]);
}, [finalRecipe, recipe, chat.messages.length]);

// Filter parameters to only show valid ones that are actually used in the recipe
const filteredParameters = useMemo(() => {
Expand Down
2 changes: 2 additions & 0 deletions ui/desktop/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ app.on('open-url', async (_event, url) => {
recipeDeeplink || undefined,
scheduledJobId || undefined
);
windowDeeplinkURL = null;
return; // Skip the rest of the handler
}

Expand All @@ -366,6 +367,7 @@ app.on('open-url', async (_event, url) => {
} else if (parsedUrl.hostname === 'sessions') {
firstOpenWindow.webContents.send('open-shared-session', pendingDeepLink);
}
pendingDeepLink = null;
}
});

Expand Down
Loading