Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
20 changes: 18 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<string | null>(null);

useEffect(() => {
messagesRef.current = messages;
Expand Down Expand Up @@ -75,17 +76,29 @@ export const useRecipeManager = (chat: ChatType, recipe?: Recipe | null) => {

useEffect(() => {
const checkRecipeAcceptance = async () => {
// Create a unique key for this recipe to prevent duplicate checks
const recipeKey = finalRecipe ? `${finalRecipe.title}-${finalRecipe.instructions}` : null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would this need to include all aspects of the recipe? Like extensions included as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good point at first I didn't think it was necessary but now I think it should behave the same as the other checks, will update

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ended up removing these checks altogether, wasn't necessary since we can just check if we've checked the recipe or not in the same chat session


// If we've already checked this exact recipe, don't check again
if (recipeKey && hasCheckedRecipeRef.current === recipeKey) {
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);
return;
}

hasCheckedRecipeRef.current = recipeKey;

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

Expand All @@ -98,17 +111,19 @@ export const useRecipeManager = (chat: ChatType, recipe?: Recipe | null) => {
setRecipeAccepted(true);
}
} catch {
hasCheckedRecipeRef.current = null;
setHasSecurityWarnings(false);
setIsRecipeWarningModalOpen(true);
}
} else {
hasCheckedRecipeRef.current = null;
setRecipeAccepted(false);
setIsRecipeWarningModalOpen(false);
}
};

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 Expand Up @@ -231,6 +246,7 @@ export const useRecipeManager = (chat: ChatType, recipe?: Recipe | null) => {
};

const handleRecipeCancel = () => {
hasCheckedRecipeRef.current = null;
setIsRecipeWarningModalOpen(false);
window.electron.closeWindow();
};
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