Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
25 changes: 2 additions & 23 deletions ui/desktop/src/components/hub.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import ChatInput from './ChatInput';
import { ChatState } from '../types/chatState';
import 'react-toastify/dist/ReactToastify.css';
import { View, ViewOptions } from '../utils/navigationUtils';
import { startAgent } from '../api';
import { startNewSession } from '../sessions';

export default function Hub({
setView,
Expand All @@ -37,28 +37,7 @@ export default function Hub({
const combinedTextFromInput = customEvent.detail?.value || '';

if (combinedTextFromInput.trim()) {
if (process.env.ALPHA) {
const newAgent = await startAgent({
body: {
working_dir: window.appConfig.get('GOOSE_WORKING_DIR') as string,
},
throwOnError: true,
});
const session = newAgent.data;
setView('pair', {
disableAnimation: true,
initialMessage: combinedTextFromInput,
resumeSessionId: session.id,
});
} else {
// Navigate to pair page with the message to be submitted
// Pair will handle creating the new chat session
resetChat();
setView('pair', {
disableAnimation: true,
initialMessage: combinedTextFromInput,
});
}
await startNewSession(combinedTextFromInput, resetChat, setView);
e.preventDefault();
}
};
Expand Down
4 changes: 2 additions & 2 deletions ui/desktop/src/components/pair.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useEffect, useState } from 'react';
import { View, ViewOptions } from '../utils/navigationUtils';
import BaseChat from './BaseChat';
import { useRecipeManager } from '../hooks/useRecipeManager';
import { useIsMobile } from '../hooks/use-mobile';
Expand All @@ -10,6 +9,7 @@ import { cn } from '../utils';

import { ChatType } from '../types/chat';
import { useSearchParams } from 'react-router-dom';
import type { setViewType } from '../hooks/useNavigation';

export interface PairRouteState {
resumeSessionId?: string;
Expand All @@ -19,7 +19,7 @@ export interface PairRouteState {
interface PairProps {
chat: ChatType;
setChat: (chat: ChatType) => void;
setView: (view: View, viewOptions?: ViewOptions) => void;
setView: setViewType;
setIsGoosehintsModalOpen: (isOpen: boolean) => void;
setFatalError: (value: ((prevState: string | null) => string | null) | string | null) => void;
setAgentWaitingMessage: (msg: string | null) => void;
Expand Down
10 changes: 6 additions & 4 deletions ui/desktop/src/components/sessions/SessionHistoryView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { SearchView } from '../conversation/SearchView';
import BackButton from '../ui/BackButton';
import { Tooltip, TooltipContent, TooltipTrigger } from '../ui/Tooltip';
import { Message, Session } from '../../api';
import { useNavigation } from '../../hooks/useNavigation';

// Helper function to determine if a message is a user message (same as useChatEngine)
const isUserMessage = (message: Message): boolean => {
Expand Down Expand Up @@ -150,6 +151,8 @@ const SessionHistoryView: React.FC<SessionHistoryViewProps> = ({

const messages = session.conversation || [];

const setView = useNavigation();

useEffect(() => {
const savedSessionConfig = localStorage.getItem('session_sharing_config');
if (savedSessionConfig) {
Expand Down Expand Up @@ -212,15 +215,14 @@ const SessionHistoryView: React.FC<SessionHistoryViewProps> = ({
});
};

const handleLaunchInNewWindow = () => {
const handleResumeSession = () => {
try {
resumeSession(session);
resumeSession(session, setView);
} catch (error) {
toast.error(`Could not launch session: ${error instanceof Error ? error.message : error}`);
}
};

// Define action buttons
const actionButtons = showActionButtons ? (
<>
<Tooltip>
Expand Down Expand Up @@ -254,7 +256,7 @@ const SessionHistoryView: React.FC<SessionHistoryViewProps> = ({
</TooltipContent>
) : null}
</Tooltip>
<Button onClick={handleLaunchInNewWindow} size="sm" variant="outline">
<Button onClick={handleResumeSession} size="sm" variant="outline">
<Sparkles className="w-4 h-4" />
Resume
</Button>
Expand Down
6 changes: 3 additions & 3 deletions ui/desktop/src/components/sessions/SessionsInsights.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
SessionInsights as ApiSessionInsights,
} from '../../api';
import { resumeSession } from '../../sessions';
import { useNavigation } from '../../hooks/useNavigation';

export function SessionInsights() {
const [insights, setInsights] = useState<ApiSessionInsights | null>(null);
Expand All @@ -21,6 +22,7 @@ export function SessionInsights() {
const [isLoading, setIsLoading] = useState(true);
const [isLoadingSessions, setIsLoadingSessions] = useState(true);
const navigate = useNavigate();
const setView = useNavigation();

useEffect(() => {
let loadingTimeout: ReturnType<typeof setTimeout>;
Expand Down Expand Up @@ -86,9 +88,7 @@ export function SessionInsights() {

const handleSessionClick = async (session: Session) => {
try {
resumeSession(session, (sessionId: string) => {
navigate(`/pair?resumeSessionId=${sessionId}`);
});
resumeSession(session, setView);
} catch (error) {
console.error('Failed to start session:', error);
navigate('/sessions', {
Expand Down
6 changes: 6 additions & 0 deletions ui/desktop/src/components/settings/extensions/agent-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,17 @@ export async function addToAgent(
toastService.dismiss(toastId);
}
const errMsg = errorMessage(error);
const recoverHints =
`Explain the following error: ${errMsg}. ` +
'This happened while trying to install an extension. Look out for issues that the ' +
"extension tried to run something faulty, didn't exist or there was trouble with " +
'the network configuration - VPNs like WARP often cause issues.';
const msg = errMsg.length < 70 ? errMsg : `Failed to add extension`;
toastService.error({
title: extensionName,
msg: msg,
traceback: errMsg,
recoverHints,
});
throw error;
}
Expand Down
2 changes: 2 additions & 0 deletions ui/desktop/src/hooks/useNavigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ export const useNavigation = () => {
const navigate = useNavigate();
return createNavigationHandler(navigate);
};

export type setViewType = ReturnType<typeof useNavigation>;
53 changes: 39 additions & 14 deletions ui/desktop/src/sessions.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import { Session } from './api';
import { Session, startAgent } from './api';
import type { setViewType } from './hooks/useNavigation';

export function resumeSession(
session: Session,
navigateInSameWindow?: (sessionId: string) => void
) {
const workingDir = session.working_dir;
if (!workingDir) {
throw new Error('Cannot resume session: working directory is missing in session');
}

// When ALPHA is true and we have a navigation callback, resume in the same window
// Otherwise, open in a new window (old behavior)
if (process.env.ALPHA && navigateInSameWindow) {
navigateInSameWindow(session.id);
export function resumeSession(session: Session, setView: setViewType) {
if (process.env.ALPHA) {
setView('pair', {
disableAnimation: true,
resumeSessionId: session.id,
});
} else {
const workingDir = session.working_dir;
if (!workingDir) {
throw new Error('Cannot resume session: working directory is missing in session');
}
window.electron.createChatWindow(
undefined, // query
workingDir,
Expand All @@ -22,3 +20,30 @@ export function resumeSession(
);
}
}

export async function startNewSession(
initialText: string | undefined,
resetChat: (() => void) | null,
setView: setViewType
) {
if (!resetChat || process.env.ALPHA) {
const newAgent = await startAgent({
body: {
working_dir: window.appConfig.get('GOOSE_WORKING_DIR') as string,
},
throwOnError: true,
});
const session = newAgent.data;
setView('pair', {
disableAnimation: true,
initialMessage: initialText,
resumeSessionId: session.id,
});
} else {
resetChat();
setView('pair', {
disableAnimation: true,
initialMessage: initialText,
});
}
}
67 changes: 35 additions & 32 deletions ui/desktop/src/toasts.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { toast, ToastOptions } from 'react-toastify';
import { Button } from './components/ui/button';
import { startNewSession } from './sessions';
import { useNavigation } from './hooks/useNavigation';

export interface ToastServiceOptions {
silent?: boolean;
shouldThrow?: boolean;
}

export default class ToastService {
class ToastService {
private silent: boolean = false;
private shouldThrow: boolean = false;

Expand All @@ -30,13 +32,13 @@ export default class ToastService {
}
}

error({ title, msg, traceback }: { title: string; msg: string; traceback: string }): void {
error(props: ToastErrorProps): void {
if (!this.silent) {
toastError({ title, msg, traceback });
toastError(props);
}

if (this.shouldThrow) {
throw new Error(msg);
throw new Error(props.msg);
}
}

Expand Down Expand Up @@ -68,7 +70,7 @@ export default class ToastService {
handleError(title: string, message: string, options: ToastServiceOptions = {}): void {
this.configure(options);
this.error({
title: title || 'Error',
title: title,
msg: message,
traceback: message,
});
Expand All @@ -88,6 +90,7 @@ const commonToastOptions: ToastOptions = {
};

type ToastSuccessProps = { title?: string; msg?: string; toastOptions?: ToastOptions };

export function toastSuccess({ title, msg, toastOptions = {} }: ToastSuccessProps) {
return toast.success(
<div>
Expand All @@ -99,26 +102,42 @@ export function toastSuccess({ title, msg, toastOptions = {} }: ToastSuccessProp
}

type ToastErrorProps = {
title?: string;
msg?: string;
title: string;
msg: string;
traceback?: string;
toastOptions?: ToastOptions;
recoverHints?: string;
};

export function toastError({ title, msg, traceback, toastOptions }: ToastErrorProps) {
return toast.error(
function ToastErrorContent({
title,
msg,
traceback,
recoverHints,
}: Omit<ToastErrorProps, 'setView'>) {
const setView = useNavigation();
const showRecovery = recoverHints && setView;

return (
<div className="flex gap-4">
<div className="flex-grow">
{title ? <strong className="font-medium">{title}</strong> : null}
{msg ? <div>{msg}</div> : null}
{title && <strong className="font-medium">{title}</strong>}
{msg && <div>{msg}</div>}
</div>
<div className="flex-none flex items-center">
{traceback ? (
<div className="flex-none flex items-center gap-2">
{showRecovery ? (
<Button onClick={() => startNewSession(recoverHints, null, setView)}>Ask goose</Button>
) : traceback ? (
<Button onClick={() => navigator.clipboard.writeText(traceback)}>Copy error</Button>
) : null}
</div>
</div>,
{ ...commonToastOptions, autoClose: traceback ? false : 5000, ...toastOptions }
</div>
);
}

export function toastError({ title, msg, traceback, recoverHints }: ToastErrorProps) {
return toast.error(
<ToastErrorContent title={title} msg={msg} traceback={traceback} recoverHints={recoverHints} />,
{ ...commonToastOptions, autoClose: traceback ? false : 5000 }
);
}

Expand All @@ -137,19 +156,3 @@ export function toastLoading({ title, msg, toastOptions }: ToastLoadingProps) {
{ ...commonToastOptions, autoClose: false, ...toastOptions }
);
}

type ToastInfoProps = {
title?: string;
msg?: string;
toastOptions?: ToastOptions;
};

export function toastInfo({ title, msg, toastOptions }: ToastInfoProps) {
return toast.info(
<div>
{title ? <strong className="font-medium">{title}</strong> : null}
{msg ? <div>{msg}</div> : null}
</div>,
{ ...commonToastOptions, ...toastOptions }
);
}
Loading