π OpenHands: AI-Driven Development
fix: default v1 conversation title (#91)
Hiep Le5d85eb0f5d3a
diff --git a/__tests__/api/agent-server-adapter.test.ts b/__tests__/api/agent-server-adapter.test.tsindex fcf6b71f66..c5a742f25a 100644--- a/__tests__/api/agent-server-adapter.test.ts+++ b/__tests__/api/agent-server-adapter.test.ts@@ -1,6 +1,11 @@import { describe, expect, it, vi } from "vitest";-import { buildStartConversationRequest } from "#/api/agent-server-adapter";+import {+ buildStartConversationRequest,+ getDefaultConversationTitle,+ toV1AppConversation,+ type DirectConversationInfo,+} from "#/api/agent-server-adapter";import { DEFAULT_SETTINGS } from "#/services/settings";const { mockGetAgentServerWorkingDir } = vi.hoisted(() => ({@@ -170,3 +175,47 @@ describe("buildStartConversationRequest", () => {});});});++describe("getDefaultConversationTitle", () => {+ it("formats the title using the first 5 characters of the conversation id", () => {+ expect(getDefaultConversationTitle("372eb-1234-5678-9abc")).toBe(+ "Conversation 372eb",+ );+ });+});++describe("toV1AppConversation", () => {+ const baseInfo: DirectConversationInfo = {+ id: "372eb-1234-5678-9abc",+ created_at: "2026-01-01T00:00:00Z",+ updated_at: "2026-01-01T00:00:00Z",+ };++ it("falls back to the default title when the backend returns null", () => {+ const result = toV1AppConversation({ ...baseInfo, title: null });+ expect(result.title).toBe("Conversation 372eb");+ });++ it("falls back to the default title when the backend returns undefined", () => {+ const result = toV1AppConversation({ ...baseInfo });+ expect(result.title).toBe("Conversation 372eb");+ });++ it("falls back to the default title when the backend returns an empty string", () => {+ const result = toV1AppConversation({ ...baseInfo, title: "" });+ expect(result.title).toBe("Conversation 372eb");+ });++ it("falls back to the default title when the backend returns whitespace only", () => {+ const result = toV1AppConversation({ ...baseInfo, title: " " });+ expect(result.title).toBe("Conversation 372eb");+ });++ it("preserves a backend-provided title when one is set", () => {+ const result = toV1AppConversation({+ ...baseInfo,+ title: "My real title",+ });+ expect(result.title).toBe("My real title");+ });+});diff --git a/src/api/agent-server-adapter.ts b/src/api/agent-server-adapter.tsindex 7875c041a1..aa577b9c55 100644--- a/src/api/agent-server-adapter.ts+++ b/src/api/agent-server-adapter.ts@@ -55,6 +55,13 @@ export function toConversationUrl(conversationId: string): string {return `${getAgentServerBaseUrl()}/api/conversations/${conversationId}`;}+// TODO(i18n): extract "Conversation" once we add CONVERSATION$DEFAULT_TITLE+// with `{{shortId}}` interpolation. Kept as a literal for now to keep the+// fallback inside this pure adapter rather than fanning out to display sites.+export function getDefaultConversationTitle(conversationId: string): string {+ return `Conversation ${conversationId.slice(0, 5)}`;+}+export function toV1AppConversation(info: DirectConversationInfo,): V1AppConversation {@@ -64,7 +71,7 @@ export function toV1AppConversation(selected_repository: null,selected_branch: null,git_provider: null,- title: info.title ?? null,+ title: info.title?.trim() ? info.title : getDefaultConversationTitle(info.id),trigger: null,pr_number: [],llm_model: info.agent?.llm?.model ?? DEFAULT_SETTINGS.llm_model,diff --git a/src/api/conversation-service/v1-conversation-service.api.ts b/src/api/conversation-service/v1-conversation-service.api.tsindex 0eac4b1a98..9c3d704cdd 100644--- a/src/api/conversation-service/v1-conversation-service.api.ts+++ b/src/api/conversation-service/v1-conversation-service.api.ts@@ -10,6 +10,7 @@ import {buildStartConversationRequest,downloadTextFile,emptyHooksResponse,+ getDefaultConversationTitle,loadSkillsForConversation,toV1AppConversation,toV1ConversationPage,@@ -259,7 +260,7 @@ class V1ConversationService {return {id: data.id,- title: data.title ?? null,+ title: data.title?.trim() ? data.title : getDefaultConversationTitle(data.id),metrics: data.metrics? {accumulated_cost: data.metrics.accumulated_cost ?? null,