Skip to content

🙌 OpenHands: AI-Driven Development

feat(apps): add Update action for installed Canvas Apps (#17736)

Vasco Schiavo29b0281bf085
diff --git a/__tests__/hooks/mutation/use-install-canvas-extension.test.ts b/__tests__/hooks/mutation/use-install-canvas-extension.test.ts
index d7085908ef..b0f64fbaa3 100644
--- a/__tests__/hooks/mutation/use-install-canvas-extension.test.ts
+++ b/__tests__/hooks/mutation/use-install-canvas-extension.test.ts
@@ -3,7 +3,10 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { renderHook, waitFor } from "@testing-library/react";
import { describe, expect, it, vi, beforeEach } from "vitest";
import CanvasExtensionsService from "#/api/canvas-extensions-service";
-import { useInstallCanvasExtension } from "#/hooks/mutation/use-manage-canvas-extensions";
+import {
+ useInstallCanvasExtension,
+ useRefreshCanvasExtension,
+} from "#/hooks/mutation/use-manage-canvas-extensions";
import { CORS_OR_NETWORK_ERROR_MESSAGE } from "#/utils/user-facing-error";
const displayErrorToast = vi.fn();
@@ -77,3 +80,56 @@ describe("useInstallCanvasExtension", () => {
);
});
});
+
+describe("useRefreshCanvasExtension", () => {
+ const installed = {
+ name: "demo",
+ version: "0.1.0",
+ enabled: true,
+ source: "github:example/apps",
+ requested_ref: "v1",
+ resolved_ref: "abc123",
+ repo_path: "demo",
+ installed_at: "2026-08-01T00:00:00Z",
+ install_path: "/tmp/demo",
+ };
+
+ beforeEach(() => {
+ vi.clearAllMocks();
+ });
+
+ it("force-reinstalls from the recorded source coordinates", async () => {
+ const install = vi
+ .spyOn(CanvasExtensionsService, "install")
+ .mockResolvedValue({} as never);
+
+ const { result } = renderHook(() => useRefreshCanvasExtension(), {
+ wrapper: createWrapper(),
+ });
+ result.current.mutate(installed);
+
+ await waitFor(() => expect(result.current.isSuccess).toBe(true));
+ expect(install).toHaveBeenCalledWith({
+ source: "github:example/apps",
+ ref: "v1",
+ repo_path: "demo",
+ force: true,
+ });
+ });
+
+ it("surfaces the server's validation error", async () => {
+ const detail =
+ "entrypoint 'dist/missing.js' does not resolve to a file in the extension package";
+ vi.spyOn(CanvasExtensionsService, "install").mockRejectedValue(
+ new HttpError(422, detail),
+ );
+
+ const { result } = renderHook(() => useRefreshCanvasExtension(), {
+ wrapper: createWrapper(),
+ });
+ result.current.mutate(installed);
+
+ await waitFor(() => expect(displayErrorToast).toHaveBeenCalled());
+ expect(displayErrorToast).toHaveBeenCalledWith(detail);
+ });
+});
diff --git a/src/components/features/canvas-extensions/canvas-extension-card.tsx b/src/components/features/canvas-extensions/canvas-extension-card.tsx
index ca3f25d6ac..4112c2d962 100644
--- a/src/components/features/canvas-extensions/canvas-extension-card.tsx
+++ b/src/components/features/canvas-extensions/canvas-extension-card.tsx
@@ -12,6 +12,7 @@ interface CanvasExtensionCardProps {
extension: InstalledCanvasExtensionInfo;
isBusy: boolean;
onToggle: () => void;
+ onRefresh: () => void;
onUninstall: () => void;
}
@@ -19,6 +20,7 @@ export function CanvasExtensionCard({
extension,
isBusy,
onToggle,
+ onRefresh,
onUninstall,
}: CanvasExtensionCardProps) {
const { t } = useTranslation("openhands");
@@ -109,6 +111,15 @@ export function CanvasExtensionCard({
) : null}
<footer className="flex justify-end gap-2 border-t border-border pt-3">
+ <BrandButton
+ type="button"
+ variant="secondary"
+ testId={`canvas-extension-refresh-${extension.name}`}
+ isDisabled={isBusy}
+ onClick={onRefresh}
+ >
+ {t(I18nKey.SETTINGS$PLUGINS_REFRESH)}
+ </BrandButton>
<BrandButton
type="button"
variant="ghost-danger"
diff --git a/src/components/features/canvas-extensions/canvas-extensions-runtime.test.tsx b/src/components/features/canvas-extensions/canvas-extensions-runtime.test.tsx
index 0d8b3a64a4..0fe2ad5e37 100644
--- a/src/components/features/canvas-extensions/canvas-extensions-runtime.test.tsx
+++ b/src/components/features/canvas-extensions/canvas-extensions-runtime.test.tsx
@@ -74,7 +74,7 @@ function renderRuntime(
const queryClient = new QueryClient({
defaultOptions: { queries: { retry: false } },
});
- return render(
+ const rendered = render(
<QueryClientProvider client={queryClient}>
<ActiveBackendProvider>
<MemoryRouter>
@@ -85,6 +85,7 @@ function renderRuntime(
</ActiveBackendProvider>
</QueryClientProvider>,
);
+ return { ...rendered, queryClient };
}
describe("CanvasExtensionsRuntimeProvider", () => {
@@ -131,6 +132,24 @@ describe("CanvasExtensionsRuntimeProvider", () => {
expect(disposeActivation).toHaveBeenCalledTimes(1);
});
+ it("re-activates an extension refreshed without a version change", async () => {
+ const disposeActivation = vi.fn();
+ const moduleLoader = vi.fn().mockResolvedValue({
+ activate: () => disposeActivation,
+ });
+
+ const { queryClient } = renderRuntime(moduleLoader);
+ await waitFor(() => expect(moduleLoader).toHaveBeenCalledTimes(1));
+
+ vi.mocked(CanvasExtensionsService.listInstalled).mockResolvedValue([
+ { ...extension, installed_at: "2026-08-02T00:00:00Z" },
+ ]);
+ await queryClient.invalidateQueries();
+
+ await waitFor(() => expect(moduleLoader).toHaveBeenCalledTimes(2));
+ expect(disposeActivation).toHaveBeenCalledTimes(1);
+ });
+
it("rejects registrations that were not declared in the manifest", async () => {
const moduleLoader = vi.fn().mockResolvedValue({
activate: (host: CanvasExtensionHost) => {
diff --git a/src/components/features/canvas-extensions/canvas-extensions-runtime.tsx b/src/components/features/canvas-extensions/canvas-extensions-runtime.tsx
index 21565d43b7..bda286ed4d 100644
--- a/src/components/features/canvas-extensions/canvas-extensions-runtime.tsx
+++ b/src/components/features/canvas-extensions/canvas-extensions-runtime.tsx
@@ -113,8 +113,9 @@ export function CanvasExtensionsRuntimeProvider({
// (e.g. when mounted without an <ActiveBackendProvider>), and refetches
// produce new extension arrays with identical content. The activation effect
// therefore keys on this value signature — backend identity plus the enabled
- // inventory — and reads the current objects from refs, so referential churn
- // never tears down and re-activates extensions.
+ // inventory, whose `installedAt` catches a same-version refresh — and reads
+ // the current objects from refs, so referential churn never tears down and
+ // re-activates extensions.
const activationSignature = React.useMemo(
() =>
JSON.stringify({
@@ -126,6 +127,7 @@ export function CanvasExtensionsRuntimeProvider({
name: extension.name,
version: extension.version,
resolvedRef: extension.resolved_ref ?? null,
+ installedAt: extension.installed_at,
pages: extension.manifest?.contributes?.pages ?? [],
})),
}),
diff --git a/src/hooks/mutation/use-manage-canvas-extensions.ts b/src/hooks/mutation/use-manage-canvas-extensions.ts
index 726f550f46..66caddd94d 100644
--- a/src/hooks/mutation/use-manage-canvas-extensions.ts
+++ b/src/hooks/mutation/use-manage-canvas-extensions.ts
@@ -1,7 +1,10 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { useTranslation } from "react-i18next";
import CanvasExtensionsService from "#/api/canvas-extensions-service";
-import type { InstallCanvasExtensionRequest } from "#/types/canvas-extension";
+import type {
+ InstallCanvasExtensionRequest,
+ InstalledCanvasExtensionInfo,
+} from "#/types/canvas-extension";
import { CANVAS_EXTENSIONS_QUERY_KEYS } from "#/hooks/query/query-keys";
import { I18nKey } from "#/i18n/declaration";
import {
@@ -19,6 +22,16 @@ function useInvalidateCanvasExtensions() {
});
}
+// A transport failure carries no response body, so keep the shared
+// "Disconnected" wording for it and use the server's detail otherwise.
+function displayInstallError(error: unknown, fallback: string) {
+ displayErrorToast(
+ getApiErrorBody(error)
+ ? getApiErrorMessage(error, fallback)
+ : retrieveAxiosErrorMessage(error) || fallback,
+ );
+}
+
export function useInstallCanvasExtension() {
const invalidate = useInvalidateCanvasExtensions();
const { t } = useTranslation("openhands");
@@ -32,14 +45,31 @@ export function useInstallCanvasExtension() {
void invalidate();
displaySuccessToast(t(I18nKey.SETTINGS$APPS_INSTALL_SUCCESS));
},
- onError: (error) => {
- // A transport failure carries no response body, so keep the shared
- // "Disconnected" wording for it and use the server's detail otherwise.
- const message = getApiErrorBody(error)
- ? getApiErrorMessage(error, t(I18nKey.ERROR$GENERIC))
- : retrieveAxiosErrorMessage(error) || t(I18nKey.ERROR$GENERIC);
- displayErrorToast(message);
+ onError: (error) => displayInstallError(error, t(I18nKey.ERROR$GENERIC)),
+ });
+}
+
+/**
+ * Re-install an App from its recorded source. The server validates the new
+ * copy before replacing the old one and carries over its enabled state.
+ */
+export function useRefreshCanvasExtension() {
+ const invalidate = useInvalidateCanvasExtensions();
+ const { t } = useTranslation("openhands");
+ return useMutation({
+ meta: { disableToast: true },
+ mutationFn: (extension: InstalledCanvasExtensionInfo) =>
+ CanvasExtensionsService.install({
+ source: extension.source,
+ ref: extension.requested_ref,
+ repo_path: extension.repo_path,
+ force: true,
+ }),
+ onSuccess: () => {
+ void invalidate();
+ displaySuccessToast(t(I18nKey.SETTINGS$APPS_REFRESH_SUCCESS));
},
+ onError: (error) => displayInstallError(error, t(I18nKey.ERROR$GENERIC)),
});
}
diff --git a/src/i18n/translation.json b/src/i18n/translation.json
index fa4cf54571..1c751ce862 100644
--- a/src/i18n/translation.json
+++ b/src/i18n/translation.json
@@ -34560,6 +34560,23 @@
"uk": "Застосунок встановлено. Перевірте його тут і ввімкніть, коли будете готові.",
"ca": "Aplicació instal·lada. Revisa-la aquí i activa-la quan estiguis a punt."
},
+ "SETTINGS$APPS_REFRESH_SUCCESS": {
+ "en": "App updated.",
+ "ja": "アプリを更新しました。",
+ "zh-CN": "应用已更新。",
+ "zh-TW": "應用程式已更新。",
+ "ko-KR": "앱이 업데이트되었습니다.",
+ "no": "Appen er oppdatert.",
+ "ar": "تم تحديث التطبيق.",
+ "de": "App aktualisiert.",
+ "fr": "Application mise à jour.",
+ "it": "App aggiornata.",
+ "pt": "Aplicativo atualizado.",
+ "es": "Aplicación actualizada.",
+ "tr": "Uygulama güncellendi.",
+ "uk": "Застосунок оновлено.",
+ "ca": "Aplicació actualitzada."
+ },
"SETTINGS$APPS_UNINSTALL_SUCCESS": {
"en": "App uninstalled.",
"ja": "アプリをアンインストールしました。",
diff --git a/src/routes/canvas-extensions.tsx b/src/routes/canvas-extensions.tsx
index b3db58b308..fcb4b3731f 100644
--- a/src/routes/canvas-extensions.tsx
+++ b/src/routes/canvas-extensions.tsx
@@ -14,6 +14,7 @@ import { isNoBackend } from "#/api/backend-registry/active-store";
import { useActiveBackend } from "#/contexts/active-backend-context";
import { useCanvasExtensions } from "#/hooks/query/use-canvas-extensions";
import {
+ useRefreshCanvasExtension,
useSetCanvasExtensionEnabled,
useUninstallCanvasExtension,
} from "#/hooks/mutation/use-manage-canvas-extensions";
@@ -43,13 +44,15 @@ export default function CanvasExtensionsScreen() {
const query = useCanvasExtensions();
const setEnabled = useSetCanvasExtensionEnabled();
const uninstall = useUninstallCanvasExtension();
+ const refresh = useRefreshCanvasExtension();
const backendCanSupportExtensions =
!isNoBackend(backend) && backend.kind === "local";
const unsupported =
!backendCanSupportExtensions ||
isCanvasExtensionsUnsupportedError(query.error);
- const isBusy = setEnabled.isPending || uninstall.isPending;
+ const isBusy =
+ setEnabled.isPending || uninstall.isPending || refresh.isPending;
const confirmAction = () => {
if (!pendingAction) return;
@@ -184,6 +187,7 @@ export default function CanvasExtensionsScreen() {
setPendingAction({ type: "enable", extension });
}
}}
+ onRefresh={() => refresh.mutate(extension)}
onUninstall={() =>
setPendingAction({ type: "uninstall", extension })
}