Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
8 changes: 0 additions & 8 deletions ui/desktop/scripts/unregister-deeplink-protocols.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,6 @@ function unregisterAllProtocolHandlers() {
}
});

// Clean up temporary files

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

noticed some local debug code that wasn't needed

console.log('\nCleaning up temporary files...');
try {
execSync('rm -rf /tmp/GooseDevApp.app', { stdio: 'ignore' });
} catch (error) {
// Ignore cleanup errors
}

// Force Launch Services to rebuild its database
console.log('Rebuilding Launch Services database...');
try {
Expand Down
129 changes: 90 additions & 39 deletions ui/desktop/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,23 @@ const PairRouteWrapper = ({

// Check if we have a resumed session or recipe config from navigation state
useEffect(() => {
// Only process if we actually have navigation state
const appConfig = window.appConfig?.get('recipe');
if (appConfig && !chatRef.current.recipeConfig) {
const recipe = appConfig as Recipe;

const updatedChat: ChatType = {
...chatRef.current,
recipeConfig: recipe,
title: recipe.title || chatRef.current.title,
messages: [], // Start fresh for recipe from deeplink
messageHistoryIndex: 0,
};
setChat(updatedChat);
setPairChat(updatedChat);
return;
}

// Only process navigation state if we actually have it
if (!location.state) {
console.log('No navigation state, preserving existing chat state');
return;
Expand Down Expand Up @@ -232,8 +248,6 @@ const PairRouteWrapper = ({
// Clear the navigation state to prevent reloading on navigation
window.history.replaceState({}, document.title);
} else if (recipeConfig && !chatRef.current.recipeConfig) {
// Only set recipe config if we don't already have one (e.g., from deeplinks)

const updatedChat: ChatType = {
...chatRef.current,
recipeConfig: recipeConfig,
Expand Down Expand Up @@ -824,6 +838,59 @@ export default function App() {
return;
}

// Check for recipe config - this also needs provider initialization
if (recipeConfig && typeof recipeConfig === 'object') {
console.log('Recipe deeplink detected, initializing system for recipe');

const initializeForRecipe = async () => {
try {
await initConfig();
await readAllConfig({ throwOnError: true });

const config = window.electron.getConfig();
const provider = (await read('GOOSE_PROVIDER', false)) ?? config.GOOSE_DEFAULT_PROVIDER;
const model = (await read('GOOSE_MODEL', false)) ?? config.GOOSE_DEFAULT_MODEL;

if (provider && model) {
await initializeSystem(provider as string, model as string, {
getExtensions,
addExtension,
});

// Set up the recipe in pair chat after system is initialized
setPairChat((prevChat) => ({
...prevChat,
recipeConfig: recipeConfig as Recipe,
title: (recipeConfig as Recipe)?.title || 'Recipe Chat',
messages: [], // Start fresh for recipe
messageHistoryIndex: 0,
}));

// Navigate to pair view
window.location.hash = '#/pair';
window.history.replaceState(
{
recipeConfig: recipeConfig,
resetChat: true,
},
'',
'#/pair'
);
} else {
throw new Error('No provider/model configured for recipe');
}
} catch (error) {
console.error('Failed to initialize system for recipe:', error);
setFatalError(
`Failed to initialize system for recipe: ${error instanceof Error ? error.message : 'Unknown error'}`
);
}
};

initializeForRecipe();
return;
}

if (viewType) {
if (viewType === 'recipeEditor' && recipeConfig) {
// Handle recipe editor deep link - use hash routing
Expand Down Expand Up @@ -925,40 +992,6 @@ export default function App() {
}

await Promise.all(initPromises);

const recipeConfig = window.appConfig.get('recipe');
if (
recipeConfig &&
typeof recipeConfig === 'object' &&
!window.sessionStorage.getItem('ignoreRecipeConfigChanges')
) {
console.log(
'Recipe deeplink detected, navigating to pair view with config:',
recipeConfig
);
// Set the recipe config in the pair chat state
setPairChat((prevChat) => ({
...prevChat,
recipeConfig: recipeConfig as Recipe,
title: (recipeConfig as Recipe).title || 'Recipe Chat',
messages: [], // Start fresh for recipe
messageHistoryIndex: 0,
}));
// Navigate to pair view with recipe config using hash routing
window.location.hash = '#/pair';
window.history.replaceState(
{
recipeConfig: recipeConfig,
resetChat: true,
},
'',
'#/pair'
);
} else if (window.sessionStorage.getItem('ignoreRecipeConfigChanges')) {
console.log(
'Ignoring recipe config changes to prevent navigation conflicts with new window creation'
);
}
} catch (error) {
console.error('Error in system initialization:', error);
if (error instanceof MalformedConfigError) {
Expand Down Expand Up @@ -1051,9 +1084,25 @@ export default function App() {

// Handle recipe decode events from main process
useEffect(() => {
const handleLoadRecipeDeeplink = (_event: IpcRendererEvent, ...args: unknown[]) => {
const recipeDeeplink = args[0] as string;
const scheduledJobId = args[1] as string | undefined;

// Store the deeplink info in app config for processing
const config = window.electron.getConfig();
config.recipeDeeplink = recipeDeeplink;
if (scheduledJobId) {
config.scheduledJobId = scheduledJobId;
}

// Navigate to pair view to handle the recipe loading
if (window.location.hash !== '#/pair') {
window.location.hash = '#/pair';
}
};

const handleRecipeDecoded = (_event: IpcRendererEvent, ...args: unknown[]) => {
const decodedRecipe = args[0] as Recipe;
console.log('[App] Recipe decoded successfully:', decodedRecipe);

// Update the pair chat with the decoded recipe
setPairChat((prevChat) => ({
Expand All @@ -1079,14 +1128,16 @@ export default function App() {
window.location.hash = '#/recipes';
};

window.electron.on('load-recipe-deeplink', handleLoadRecipeDeeplink);
window.electron.on('recipe-decoded', handleRecipeDecoded);
window.electron.on('recipe-decode-error', handleRecipeDecodeError);

return () => {
window.electron.off('load-recipe-deeplink', handleLoadRecipeDeeplink);
window.electron.off('recipe-decoded', handleRecipeDecoded);
window.electron.off('recipe-decode-error', handleRecipeDecodeError);
};
}, [setPairChat]);
}, [setPairChat, pairChat.id]);

useEffect(() => {
console.log('Setting up keyboard shortcuts');
Expand Down
2 changes: 1 addition & 1 deletion ui/desktop/src/components/hub.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ export default function Hub({
setPairChat(newPairChat);

// Navigate to pair page with the message to be submitted immediately
// No delay needed since we're updating state synchronously
setView('pair', {
disableAnimation: true,
initialMessage: combinedTextFromInput,
resetChat: true,
});
}

Expand Down
16 changes: 15 additions & 1 deletion ui/desktop/src/components/pair.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ export default function Pair({
// Handle initial message from hub page
useEffect(() => {
const messageFromHub = location.state?.initialMessage;
const resetChat = location.state?.resetChat;

// If we have a resetChat flag from Hub, clear any existing recipe config

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't follow the logic here. in what scenario is this going to be triggered? there was a recipe, the user went to the hub ...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added a comment to help but yeah basically if they decide to start a new chat from home/hub after loading a recipe for whatever reason it should clear the current recipe and start a new chat. Basically anytime a chat is started from hub/home it should be a fresh chat regardless of the scenario.

@DOsinga DOsinga Aug 14, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

that's probably the best we can do at this point, yeah. I guess right now if you restart a session that was started by a recipe, this doesn't actually have the recipe stuff in it anymore? /cc @lifeizhou-ap

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah its always worked like that where the recipe details are lost when resuming a session, we'd need to add the recipe to the session metadata if we wanted to do that.

if (resetChat) {
const newChat: ChatType = {
...chat,
recipeConfig: null,
recipeParameters: null,
title: 'New Chat',
messages: [], // Clear messages for fresh start
messageHistoryIndex: 0,
};

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this should probably be/use a constant seeing that we have 'New Chat' already 4 times

setChat(newChat);
}

// Reset processing state when we have a new message from hub
if (messageFromHub) {
Expand All @@ -100,7 +114,7 @@ export default function Pair({
window.history.replaceState({}, '', '/pair');
}
}
}, [location.state, hasProcessedInitialInput, initialMessage, chat]);
}, [location.state, hasProcessedInitialInput, initialMessage, chat, setChat]);

// Auto-submit the initial message after it's been set and component is ready
useEffect(() => {
Expand Down
5 changes: 5 additions & 0 deletions ui/desktop/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,11 @@ const createChat = async (
: `?view=${encodeURIComponent(viewType)}`;
}

// For recipe deeplinks, navigate directly to pair view
if (recipe || recipeDeeplink) {
queryParams = queryParams ? `${queryParams}&view=pair` : `?view=pair`;
}

// Increment window counter to track number of windows
const windowId = ++windowCounter;

Expand Down
Loading