no more esc toasts (#2109)
This commit is contained in:
@@ -23,6 +23,7 @@ export default function ExtensionsSection() {
|
|||||||
const [selectedExtension, setSelectedExtension] = useState<FixedExtensionEntry | null>(null);
|
const [selectedExtension, setSelectedExtension] = useState<FixedExtensionEntry | null>(null);
|
||||||
const [isModalOpen, setIsModalOpen] = useState(false);
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||||
const [isAddModalOpen, setIsAddModalOpen] = useState(false);
|
const [isAddModalOpen, setIsAddModalOpen] = useState(false);
|
||||||
|
// We don't need errorFormData anymore since we're not reopening modals on failure
|
||||||
|
|
||||||
const fetchExtensions = async () => {
|
const fetchExtensions = async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
@@ -72,38 +73,54 @@ export default function ExtensionsSection() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleAddExtension = async (formData: ExtensionFormData) => {
|
const handleAddExtension = async (formData: ExtensionFormData) => {
|
||||||
|
// Close the modal immediately
|
||||||
|
handleModalClose();
|
||||||
|
|
||||||
const extensionConfig = createExtensionConfig(formData);
|
const extensionConfig = createExtensionConfig(formData);
|
||||||
try {
|
try {
|
||||||
await activateExtension({ addToConfig: addExtension, extensionConfig: extensionConfig });
|
await activateExtension({ addToConfig: addExtension, extensionConfig: extensionConfig });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Even if activation fails, the extension is added as disabled, so we want to show it
|
|
||||||
console.error('Failed to activate extension:', error);
|
console.error('Failed to activate extension:', error);
|
||||||
|
// Even if activation fails, we don't reopen the modal
|
||||||
} finally {
|
} finally {
|
||||||
handleModalClose();
|
// Refresh the extensions list regardless of success or failure
|
||||||
await fetchExtensions();
|
await fetchExtensions();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleUpdateExtension = async (formData: ExtensionFormData) => {
|
const handleUpdateExtension = async (formData: ExtensionFormData) => {
|
||||||
const extensionConfig = createExtensionConfig(formData);
|
// Close the modal immediately
|
||||||
|
|
||||||
await updateExtension({
|
|
||||||
enabled: formData.enabled,
|
|
||||||
extensionConfig: extensionConfig,
|
|
||||||
addToConfig: addExtension,
|
|
||||||
});
|
|
||||||
|
|
||||||
// First refresh the extensions list
|
|
||||||
await fetchExtensions();
|
|
||||||
|
|
||||||
// Then close the modal after data is refreshed
|
|
||||||
handleModalClose();
|
handleModalClose();
|
||||||
|
|
||||||
|
const extensionConfig = createExtensionConfig(formData);
|
||||||
|
try {
|
||||||
|
await updateExtension({
|
||||||
|
enabled: formData.enabled,
|
||||||
|
extensionConfig: extensionConfig,
|
||||||
|
addToConfig: addExtension,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to update extension:', error);
|
||||||
|
// We don't reopen the modal on failure
|
||||||
|
} finally {
|
||||||
|
// Refresh the extensions list regardless of success or failure
|
||||||
|
await fetchExtensions();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDeleteExtension = async (name: string) => {
|
const handleDeleteExtension = async (name: string) => {
|
||||||
await deleteExtension({ name, removeFromConfig: removeExtension });
|
// Close the modal immediately
|
||||||
handleModalClose();
|
handleModalClose();
|
||||||
await fetchExtensions();
|
|
||||||
|
try {
|
||||||
|
await deleteExtension({ name, removeFromConfig: removeExtension });
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to delete extension:', error);
|
||||||
|
// We don't reopen the modal on failure
|
||||||
|
} finally {
|
||||||
|
// Refresh the extensions list regardless of success or failure
|
||||||
|
await fetchExtensions();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleModalClose = () => {
|
const handleModalClose = () => {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export async function activateExtension({
|
|||||||
}: ActivateExtensionProps): Promise<void> {
|
}: ActivateExtensionProps): Promise<void> {
|
||||||
try {
|
try {
|
||||||
// AddToAgent
|
// AddToAgent
|
||||||
await addToAgent(extensionConfig, { silent: false, showEscMessage: true });
|
await addToAgent(extensionConfig, { silent: false });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to add extension to agent:', error);
|
console.error('Failed to add extension to agent:', error);
|
||||||
// add to config with enabled = false
|
// add to config with enabled = false
|
||||||
@@ -89,18 +89,15 @@ export async function addToAgentOnStartup({
|
|||||||
extensionConfig,
|
extensionConfig,
|
||||||
}: AddToAgentOnStartupProps): Promise<void> {
|
}: AddToAgentOnStartupProps): Promise<void> {
|
||||||
try {
|
try {
|
||||||
await retryWithBackoff(
|
await retryWithBackoff(() => addToAgent(extensionConfig, { silent: true }), {
|
||||||
() => addToAgent(extensionConfig, { silent: true, showEscMessage: false }),
|
retries: 3,
|
||||||
{
|
delayMs: 1000,
|
||||||
retries: 3,
|
shouldRetry: (error: any) =>
|
||||||
delayMs: 1000,
|
error.message &&
|
||||||
shouldRetry: (error: any) =>
|
(error.message.includes('428') ||
|
||||||
error.message &&
|
error.message.includes('Precondition Required') ||
|
||||||
(error.message.includes('428') ||
|
error.message.includes('Agent is not initialized')),
|
||||||
error.message.includes('Precondition Required') ||
|
});
|
||||||
error.message.includes('Agent is not initialized')),
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} catch (finalError) {
|
} catch (finalError) {
|
||||||
toastService.configure({ silent: false });
|
toastService.configure({ silent: false });
|
||||||
toastService.error({
|
toastService.error({
|
||||||
@@ -190,8 +187,6 @@ export async function toggleExtension({
|
|||||||
// add to agent with toast options
|
// add to agent with toast options
|
||||||
await addToAgent(extensionConfig, {
|
await addToAgent(extensionConfig, {
|
||||||
...toastOptions,
|
...toastOptions,
|
||||||
// For toggle operations, we want to show toast but no ESC message
|
|
||||||
showEscMessage: false,
|
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error adding extension to agent. Will try to toggle back off.');
|
console.error('Error adding extension to agent. Will try to toggle back off.');
|
||||||
|
|||||||
@@ -4,13 +4,11 @@ import { Button } from './components/ui/button';
|
|||||||
|
|
||||||
export interface ToastServiceOptions {
|
export interface ToastServiceOptions {
|
||||||
silent?: boolean;
|
silent?: boolean;
|
||||||
showEscMessage?: boolean;
|
|
||||||
shouldThrow?: boolean;
|
shouldThrow?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class ToastService {
|
export default class ToastService {
|
||||||
private silent: boolean = false;
|
private silent: boolean = false;
|
||||||
private showEscMessage: boolean = true;
|
|
||||||
private shouldThrow: boolean = false;
|
private shouldThrow: boolean = false;
|
||||||
|
|
||||||
// Create a singleton instance
|
// Create a singleton instance
|
||||||
@@ -27,9 +25,7 @@ export default class ToastService {
|
|||||||
if (options.silent !== undefined) {
|
if (options.silent !== undefined) {
|
||||||
this.silent = options.silent;
|
this.silent = options.silent;
|
||||||
}
|
}
|
||||||
if (options.showEscMessage !== undefined) {
|
|
||||||
this.showEscMessage = options.showEscMessage;
|
|
||||||
}
|
|
||||||
if (options.shouldThrow !== undefined) {
|
if (options.shouldThrow !== undefined) {
|
||||||
this.shouldThrow = options.shouldThrow;
|
this.shouldThrow = options.shouldThrow;
|
||||||
}
|
}
|
||||||
@@ -52,11 +48,6 @@ export default class ToastService {
|
|||||||
|
|
||||||
const toastId = toastLoading({ title, msg });
|
const toastId = toastLoading({ title, msg });
|
||||||
|
|
||||||
if (this.showEscMessage) {
|
|
||||||
toast.info(
|
|
||||||
'Press the ESC key on your keyboard to continue using goose while extension loads'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return toastId;
|
return toastId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user