π OpenHands: AI-Driven Development
feat: start a conversation with a plugin via the /launch path (#1788)
Hiep Le18badaebaae8
diff --git a/__tests__/routes/plugins-page.test.tsx b/__tests__/routes/plugins-page.test.tsxindex f95e7b5537..c5ab193e53 100644--- a/__tests__/routes/plugins-page.test.tsx+++ b/__tests__/routes/plugins-page.test.tsx@@ -16,6 +16,7 @@ import {import type { Backend } from "#/api/backend-registry/types";import { MOCK_DEFAULT_USER_SETTINGS } from "#/mocks/handlers";import { ActiveBackendProvider } from "#/contexts/active-backend-context";+import { buildPluginLaunchPath } from "#/utils/plugin-launch-url";const navigateMock = vi.fn();@@ -241,4 +242,42 @@ describe("SkillsPluginsScreen", () => {expect(screen.getByTestId("plugins-no-match")).toBeInTheDocument();});++ it("navigates to the launch flow with the plugin's coordinates when Start Conversation is clicked", async () => {+ const user = userEvent.setup();+ vi.spyOn(PluginsService, "getPluginsMarketplace").mockResolvedValue([+ buildCatalogPlugin(),+ ]);++ renderPluginsScreen();+ await user.click(await screen.findByTestId("plugin-card-demo-plugin"));+ await user.click(+ await screen.findByTestId("plugin-detail-start-conversation-demo-plugin"),+ );++ expect(navigateMock).toHaveBeenCalledWith(+ buildPluginLaunchPath([+ {+ source: "github:OpenHands/extensions",+ ref: null,+ repo_path: "plugins/demo-plugin",+ },+ ]),+ );+ });++ it("omits the Start Conversation action for a local plugin without a source", async () => {+ const user = userEvent.setup();+ vi.spyOn(PluginsService, "getLocalPlugins").mockResolvedValue([+ { name: "ambient-plugin", version: "1.0.0", description: "Ambient" },+ ]);++ renderPluginsScreen();+ await user.click(await screen.findByTestId("plugin-card-ambient-plugin"));+ await screen.findByTestId("plugin-detail-modal");++ expect(+ screen.queryByTestId("plugin-detail-start-conversation-ambient-plugin"),+ ).not.toBeInTheDocument();+ });});diff --git a/__tests__/utils/plugin-launch-url.test.ts b/__tests__/utils/plugin-launch-url.test.tsnew file mode 100644index 0000000000..7403ddf067--- /dev/null+++ b/__tests__/utils/plugin-launch-url.test.ts@@ -0,0 +1,25 @@+import { describe, expect, it } from "vitest";+import type { PluginSpec } from "#/api/conversation-service/agent-server-conversation-service.types";+import { buildPluginLaunchPath } from "#/utils/plugin-launch-url";++describe("buildPluginLaunchPath", () => {+ it("encodes plugins into a /launch path that decodes back to the same specs", () => {+ // Arrange: coordinates whose JSON base64-encodes with URL-special chars (+ / =).+ const plugins: PluginSpec[] = [+ {+ source: "github:OpenHands/extensions",+ ref: "v1.2+3",+ repo_path: "sub/dir",+ },+ ];++ // Act: build the path, then decode the `plugins` param the way /launch does.+ const path = buildPluginLaunchPath(plugins);+ const url = new URL(path, "http://localhost");+ const decoded = JSON.parse(atob(url.searchParams.get("plugins") ?? ""));++ // Assert: it targets /launch and round-trips the coordinates without corruption.+ expect(url.pathname).toBe("/launch");+ expect(decoded).toEqual(plugins);+ });+});diff --git a/src/components/features/plugins/plugin-detail-modal.tsx b/src/components/features/plugins/plugin-detail-modal.tsxindex 9011ddf1bf..c451873462 100644--- a/src/components/features/plugins/plugin-detail-modal.tsx+++ b/src/components/features/plugins/plugin-detail-modal.tsx@@ -18,6 +18,7 @@ interface PluginDetailModalProps {onUninstall: () => void;onRefresh: () => void;onClose: () => void;+ onStartConversation?: () => void;}export function PluginDetailModal({@@ -29,6 +30,7 @@ export function PluginDetailModal({onUninstall,onRefresh,onClose,+ onStartConversation,}: PluginDetailModalProps) {const { t } = useTranslation("openhands");const actionsDisabled = isDisabled || isBusy;@@ -128,7 +130,7 @@ export function PluginDetailModal({) : plugin.isLocal ? null : (<BrandButtontype="button"- variant="primary"+ variant="secondary"testId={`plugin-detail-install-${plugin.name}`}isDisabled={actionsDisabled}onClick={onInstall}@@ -140,6 +142,16 @@ export function PluginDetailModal({)}</BrandButton>)}+ {plugin.source && onStartConversation ? (+ <BrandButton+ type="button"+ variant="secondary"+ testId={`plugin-detail-start-conversation-${plugin.name}`}+ onClick={onStartConversation}+ >+ {t(I18nKey.COMMON$START_CONVERSATION)}+ </BrandButton>+ ) : null}<BrandButtontype="button"variant="secondary"diff --git a/src/routes/skills-plugins.tsx b/src/routes/skills-plugins.tsxindex dd44ef6b65..2a552d93c5 100644--- a/src/routes/skills-plugins.tsx+++ b/src/routes/skills-plugins.tsx@@ -21,8 +21,10 @@ import { useSetPluginEnabled } from "#/hooks/mutation/use-set-plugin-enabled";import { useUninstallPlugin } from "#/hooks/mutation/use-uninstall-plugin";import { useRefreshPlugin } from "#/hooks/mutation/use-refresh-plugin";import { useActiveBackend } from "#/contexts/active-backend-context";+import { useNavigation } from "#/context/navigation-context";import { I18nKey } from "#/i18n/declaration";import { cn } from "#/utils/utils";+import { buildPluginLaunchPath } from "#/utils/plugin-launch-url";import { settingsLikeMainScrollClassName } from "#/utils/settings-like-page-layout-classes";import {extensionModuleCardGridClassName,@@ -33,6 +35,7 @@ import {export default function SkillsPluginsScreen() {const { t } = useTranslation("openhands");const { backend } = useActiveBackend();+ const { navigate } = useNavigation();const isLocal = backend.kind === "local";const { data: marketplace, isLoading: marketplaceLoading } =@@ -108,6 +111,15 @@ export default function SkillsPluginsScreen() {refreshPlugin.mutate(plugin.name);};+ const handleStartConversation = (plugin: PluginViewModel) => {+ if (!plugin.source) return;+ navigate(+ buildPluginLaunchPath([+ { source: plugin.source, ref: plugin.ref, repo_path: plugin.repoPath },+ ]),+ );+ };+return (<divdata-testid="skills-plugins-screen"@@ -213,6 +225,9 @@ export default function SkillsPluginsScreen() {onInstall={() => handleInstall(selectedPlugin)}onUninstall={() => handleUninstall(selectedPlugin)}onRefresh={() => handleRefresh(selectedPlugin)}+ onStartConversation={() =>+ handleStartConversation(selectedPlugin)+ }onClose={() => setSelectedName(null)}/>)}diff --git a/src/utils/plugin-launch-url.ts b/src/utils/plugin-launch-url.tsnew file mode 100644index 0000000000..74914862e4--- /dev/null+++ b/src/utils/plugin-launch-url.ts@@ -0,0 +1,17 @@+import type { PluginSpec } from "#/api/conversation-service/agent-server-conversation-service.types";++/**+ * Build the in-app path to the `/launch` screen for the given plugins, so the+ * Plugins UI can start a conversation with a plugin by reusing the existing+ * launch flow. Inverse of `parsePluginsFromUrl` in `src/routes/launch.tsx` β+ * keep the base64-encoded JSON `plugins` format in sync with that decoder.+ *+ * The base64 payload can contain `+`, `/`, and `=`; encoding it through+ * `URLSearchParams` percent-escapes those so `/launch` reads back the exact+ * string (a raw `+` would otherwise be decoded as a space and break `atob`).+ */+export function buildPluginLaunchPath(plugins: PluginSpec[]): string {+ const encoded = btoa(JSON.stringify(plugins));+ const params = new URLSearchParams({ plugins: encoded });+ return `/launch?${params.toString()}`;+}