π OpenHands: AI-Driven Development
fix: rename conversation title on cloud backends (#16966)
jpelletier1f95b9b71f76a
diff --git a/__tests__/api/cloud/conversation-title.test.ts b/__tests__/api/cloud/conversation-title.test.tsnew file mode 100644index 0000000000..1680c8ff76--- /dev/null+++ b/__tests__/api/cloud/conversation-title.test.ts@@ -0,0 +1,84 @@+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";+import {+ __resetActiveStoreForTests,+ setActiveSelection,+ setRegisteredBackends,+} from "#/api/backend-registry/active-store";+import type { Backend } from "#/api/backend-registry/types";+import AgentServerConversationService from "#/api/conversation-service/agent-server-conversation-service.api";+import {+ getFetchCall,+ getJsonBody,+ mockJsonResponse,+} from "./fetch-test-utils";++vi.mock("@openhands/typescript-client/clients", async (importOriginal) => {+ const actual =+ await importOriginal<+ typeof import("@openhands/typescript-client/clients")+ >();++ return {+ ...actual,+ ConversationClient: vi.fn().mockImplementation(() => ({+ updateConversation: vi+ .fn()+ .mockRejectedValue(+ new Error("Cloud title updates must not use ConversationClient"),+ ),+ })),+ };+});++const cloudBackend: Backend = {+ id: "prod",+ name: "Production",+ host: "https://app.all-hands.dev",+ apiKey: "bearer-token",+ kind: "cloud",+};++const originalFetch = global.fetch;+const fetchMock = vi.fn();++beforeEach(() => {+ window.localStorage.clear();+ __resetActiveStoreForTests();+ fetchMock.mockReset();+ fetchMock.mockResolvedValue(+ mockJsonResponse({ id: "conv-abc", title: "Renamed conversation" }),+ );+ global.fetch = fetchMock as typeof fetch;+});++afterEach(() => {+ window.localStorage.clear();+ __resetActiveStoreForTests();+ fetchMock.mockReset();+ global.fetch = originalFetch;+});++describe("AgentServerConversationService.updateConversationTitle", () => {+ it("PATCHes the app-conversation directly on a cloud backend", async () => {+ setRegisteredBackends([cloudBackend]);+ setActiveSelection({ backendId: cloudBackend.id });++ const result = await AgentServerConversationService.updateConversationTitle(+ "conv-abc",+ "Renamed conversation",+ );++ expect(fetchMock).toHaveBeenCalledOnce();+ const [url, init] = getFetchCall(fetchMock);+ expect(url).toBe(`${cloudBackend.host}/api/v1/app-conversations/conv-abc`);+ expect(init).toMatchObject({+ method: "PATCH",+ headers: { Authorization: "Bearer bearer-token" },+ });+ expect(getJsonBody(init)).toEqual({ title: "Renamed conversation" });+ expect(result).toMatchObject({+ id: "conv-abc",+ title: "Renamed conversation",+ });+ });+});diff --git a/src/api/cloud/conversation-service.api.ts b/src/api/cloud/conversation-service.api.tsindex 2c16777d7d..d807e4ff45 100644--- a/src/api/cloud/conversation-service.api.ts+++ b/src/api/cloud/conversation-service.api.ts@@ -220,6 +220,24 @@ export async function updateCloudConversationPublicFlag(return data;}+/**+ * Rename a cloud v1 app-conversation. The title belongs to the Cloud+ * app-conversation resource, so updating a runtime Agent Server would not+ * persist it in the Cloud conversation list.+ */+export async function updateCloudConversationTitle(+ conversationId: string,+ title: string,+): Promise<AppConversation> {+ const backend = getActiveCloudBackend();+ return callCloudProxy<AppConversation>({+ backend,+ method: "PATCH",+ path: `/api/v1/app-conversations/${conversationId}`,+ body: { title },+ });+}+/*** Pause the cloud sandbox backing a v1 app-conversation. Mirrors* OpenHands' `SandboxService.pauseSandbox`:diff --git a/src/api/conversation-service/agent-server-conversation-service.api.ts b/src/api/conversation-service/agent-server-conversation-service.api.tsindex 42b1c875fd..ac1958ca8f 100644--- a/src/api/conversation-service/agent-server-conversation-service.api.ts+++ b/src/api/conversation-service/agent-server-conversation-service.api.ts@@ -34,6 +34,7 @@ import {readCloudConversationFile,searchCloudConversations,updateCloudConversationPublicFlag,+ updateCloudConversationTitle,} from "../cloud/conversation-service.api";import {DirectConversationInfo,@@ -802,6 +803,10 @@ class AgentServerConversationService {conversationId: string,title: string,): Promise<AppConversation> {+ if (getActiveBackend().backend.kind === "cloud") {+ return updateCloudConversationTitle(conversationId, title);+ }+await new ConversationClient(getAgentServerClientOptions(),).updateConversation(conversationId, {