Skip to content

🙌 OpenHands: AI-Driven Development

feat(conversation): open shared automation conversations read-only on cloud (#17683)

Hiep Le7fa364f4a6a1
diff --git a/__tests__/api/cloud/shared-conversation-service.test.ts b/__tests__/api/cloud/shared-conversation-service.test.ts
new file mode 100644
index 0000000000..cfc3809e47
--- /dev/null
+++ b/__tests__/api/cloud/shared-conversation-service.test.ts
@@ -0,0 +1,115 @@
+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 {
+ getCloudSharedConversation,
+ searchCloudSharedEvents,
+} from "#/api/cloud/shared-conversation-service.api";
+import { getFetchCall, mockJsonResponse } from "./fetch-test-utils";
+
+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();
+
+function activateCloudBackend() {
+ setRegisteredBackends([cloudBackend]);
+ setActiveSelection({ backendId: cloudBackend.id });
+}
+
+beforeEach(() => {
+ window.localStorage.clear();
+ __resetActiveStoreForTests();
+ fetchMock.mockReset();
+ global.fetch = fetchMock as typeof fetch;
+});
+
+afterEach(() => {
+ window.localStorage.clear();
+ __resetActiveStoreForTests();
+ fetchMock.mockReset();
+ global.fetch = originalFetch;
+});
+
+describe("getCloudSharedConversation", () => {
+ it("GETs /api/shared-conversations for the id and returns the matching conversation", async () => {
+ // Arrange
+ activateCloudBackend();
+ fetchMock.mockResolvedValue(
+ mockJsonResponse([{ id: "conv-abc", created_by_user_id: "user-1" }]),
+ );
+
+ // Act
+ const conversation = await getCloudSharedConversation("conv-abc");
+
+ // Assert
+ const [url, init] = getFetchCall(fetchMock);
+ expect(url).toBe(
+ `${cloudBackend.host}/api/shared-conversations?ids=conv-abc`,
+ );
+ expect(init).toMatchObject({
+ method: "GET",
+ headers: { Authorization: "Bearer bearer-token" },
+ });
+ expect(conversation).toEqual({
+ id: "conv-abc",
+ created_by_user_id: "user-1",
+ });
+ });
+
+ it("returns null when the backend does not share the conversation with the caller", async () => {
+ // Arrange
+ activateCloudBackend();
+ fetchMock.mockResolvedValue(mockJsonResponse([null]));
+
+ // Act
+ const conversation = await getCloudSharedConversation("conv-abc");
+
+ // Assert
+ expect(conversation).toBeNull();
+ });
+
+ it("rejects without calling the cloud API when the active backend is local", async () => {
+ // Arrange — the default state after reset is the bundled local backend.
+ // Act / Assert
+ await expect(getCloudSharedConversation("conv-abc")).rejects.toThrow(
+ /cloud backend/,
+ );
+ expect(fetchMock).not.toHaveBeenCalled();
+ });
+});
+
+describe("searchCloudSharedEvents", () => {
+ it("GETs /api/shared-events/search with the conversation id, page size and cursor", async () => {
+ // Arrange
+ activateCloudBackend();
+ fetchMock.mockResolvedValue(
+ mockJsonResponse({ items: [], next_page_id: null }),
+ );
+
+ // Act
+ const page = await searchCloudSharedEvents({
+ conversationId: "conv-abc",
+ limit: 50,
+ pageId: "cursor-2",
+ });
+
+ // Assert
+ const [url, init] = getFetchCall(fetchMock);
+ expect(url).toBe(
+ `${cloudBackend.host}/api/shared-events/search?conversation_id=conv-abc&limit=50&page_id=cursor-2`,
+ );
+ expect(init).toMatchObject({ method: "GET" });
+ expect(page).toEqual({ items: [], next_page_id: null });
+ });
+});
diff --git a/__tests__/routes/conversation-backend-switch.test.tsx b/__tests__/routes/conversation-backend-switch.test.tsx
index a1a4d97849..4c90bb89d2 100644
--- a/__tests__/routes/conversation-backend-switch.test.tsx
+++ b/__tests__/routes/conversation-backend-switch.test.tsx
@@ -1,7 +1,8 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import React from "react";
import { render, screen, waitFor } from "@testing-library/react";
-import { MemoryRouter } from "react-router";
+import { MemoryRouter, Route, Routes } from "react-router";
+import type { SharedConversation } from "@openhands/typescript-client";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import AgentServerConversationService from "#/api/conversation-service/agent-server-conversation-service.api";
@@ -15,6 +16,8 @@ import { NavigationProvider } from "#/context/navigation-context";
import ConversationView from "#/routes/conversation";
import type { Backend } from "#/api/backend-registry/types";
import type { AppConversation } from "#/api/conversation-service/agent-server-conversation-service.types";
+import { getCloudSharedConversation } from "#/api/cloud/shared-conversation-service.api";
+import { displayErrorToast } from "#/utils/custom-toast-handlers";
// Mock the underlying service the conversation queries depend on.
vi.mock(
@@ -61,6 +64,15 @@ vi.mock("#/hooks/query/use-is-authed", () => ({
vi.mock("#/api/cloud/conversation-service.api", () => ({
resumeCloudSandbox: vi.fn(),
}));
+// Mock the cloud sharing service the read-only fallback probes.
+vi.mock("#/api/cloud/shared-conversation-service.api", () => ({
+ getCloudSharedConversation: vi.fn(),
+ searchCloudSharedEvents: vi.fn(),
+}));
+vi.mock("#/utils/custom-toast-handlers", async (importOriginal) => ({
+ ...(await importOriginal<typeof import("#/utils/custom-toast-handlers")>()),
+ displayErrorToast: vi.fn(),
+}));
const localBackend: Backend = {
id: "local-1",
@@ -127,9 +139,68 @@ function renderConversation() {
);
}
+function makeSharedConversation(id: string): SharedConversation {
+ return {
+ id,
+ created_by_user_id: "creator-1",
+ selected_repository: null,
+ selected_branch: null,
+ git_provider: null,
+ title: "Automated code review",
+ pr_number: [],
+ llm_model: null,
+ metrics: null,
+ parent_conversation_id: null,
+ sub_conversation_ids: [],
+ created_at: "2024-01-01T00:00:00Z",
+ updated_at: "2024-01-01T00:00:00Z",
+ };
+}
+
+// Render the route inside a router so the fallback's navigation lands on
+// observable destinations.
+function renderConversationRoute(conversationId: string) {
+ const queryClient = new QueryClient({
+ defaultOptions: { queries: { retry: false } },
+ });
+ return render(
+ <MemoryRouter initialEntries={[`/conversations/${conversationId}`]}>
+ <QueryClientProvider client={queryClient}>
+ <ActiveBackendProvider>
+ <NavigationProvider
+ value={{
+ currentPath: `/conversations/${conversationId}`,
+ conversationId,
+ isNavigating: false,
+ navigate: vi.fn(),
+ }}
+ >
+ <Routes>
+ <Route
+ path="/conversations/:conversationId"
+ element={<ConversationView />}
+ />
+ <Route
+ path="/shared/conversations/:conversationId"
+ element={<div data-testid="shared-conversation-view" />}
+ />
+ <Route
+ path="/conversations"
+ element={<div data-testid="conversations-home" />}
+ />
+ </Routes>
+ </NavigationProvider>
+ </ActiveBackendProvider>
+ </QueryClientProvider>
+ </MemoryRouter>,
+ );
+}
+
beforeEach(() => {
window.localStorage.clear();
__resetActiveStoreForTests();
+ vi.mocked(getCloudSharedConversation).mockReset();
+ vi.mocked(displayErrorToast).mockReset();
vi.mocked(
AgentServerConversationService.batchGetAppConversations,
).mockReset();
@@ -149,9 +220,7 @@ describe("conversation route — backend switch", () => {
// Arrange — the cloud conversation renders while the cloud backend is active.
setActiveSelection({ backendId: cloudBackend.id });
renderConversation();
- expect(
- await screen.findByTestId("conversation-main"),
- ).toBeInTheDocument();
+ expect(await screen.findByTestId("conversation-main")).toBeInTheDocument();
// Act — switch to the local backend without leaving the conversation.
setActiveSelection({ backendId: localBackend.id });
@@ -164,3 +233,61 @@ describe("conversation route — backend switch", () => {
});
});
});
+
+describe("conversation route — shared read-only fallback", () => {
+ it("sends an org member to the read-only shared view when only the shared lookup can see the conversation", async () => {
+ // Arrange — the owner lookup misses on cloud, but the conversation is
+ // shared with this user (an automation conversation from their org).
+ setActiveSelection({ backendId: cloudBackend.id });
+ vi.mocked(
+ AgentServerConversationService.batchGetAppConversations,
+ ).mockResolvedValue([null]);
+ vi.mocked(getCloudSharedConversation).mockResolvedValue(
+ makeSharedConversation(CLOUD_CONVERSATION_ID),
+ );
+
+ // Act
+ renderConversationRoute(CLOUD_CONVERSATION_ID);
+
+ // Assert
+ expect(
+ await screen.findByTestId("shared-conversation-view"),
+ ).toBeInTheDocument();
+ expect(getCloudSharedConversation).toHaveBeenCalledWith(
+ CLOUD_CONVERSATION_ID,
+ );
+ expect(displayErrorToast).not.toHaveBeenCalled();
+ });
+
+ it("reports the conversation as missing when neither lookup can see it on cloud", async () => {
+ // Arrange
+ setActiveSelection({ backendId: cloudBackend.id });
+ vi.mocked(
+ AgentServerConversationService.batchGetAppConversations,
+ ).mockResolvedValue([null]);
+ vi.mocked(getCloudSharedConversation).mockResolvedValue(null);
+
+ // Act
+ renderConversationRoute(CLOUD_CONVERSATION_ID);
+
+ // Assert
+ expect(await screen.findByTestId("conversations-home")).toBeInTheDocument();
+ expect(displayErrorToast).toHaveBeenCalledTimes(1);
+ });
+
+ it("does not consult the shared lookup on a local backend", async () => {
+ // Arrange
+ setActiveSelection({ backendId: localBackend.id });
+ vi.mocked(
+ AgentServerConversationService.batchGetAppConversations,
+ ).mockResolvedValue([null]);
+
+ // Act
+ renderConversationRoute(CLOUD_CONVERSATION_ID);
+
+ // Assert
+ expect(await screen.findByTestId("conversations-home")).toBeInTheDocument();
+ expect(getCloudSharedConversation).not.toHaveBeenCalled();
+ expect(displayErrorToast).toHaveBeenCalledTimes(1);
+ });
+});
diff --git a/__tests__/routes/shared-conversation-cloud-viewer.test.tsx b/__tests__/routes/shared-conversation-cloud-viewer.test.tsx
new file mode 100644
index 0000000000..59562ab911
--- /dev/null
+++ b/__tests__/routes/shared-conversation-cloud-viewer.test.tsx
@@ -0,0 +1,154 @@
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import { render, screen } from "@testing-library/react";
+import { MemoryRouter, Route, Routes } from "react-router";
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+import type { SharedConversation as SharedConversationData } from "@openhands/typescript-client";
+
+import SharedConversation from "#/routes/shared-conversation";
+import { I18nKey } from "#/i18n/declaration";
+import {
+ __resetActiveStoreForTests,
+ setActiveSelection,
+ setRegisteredBackends,
+} from "#/api/backend-registry/active-store";
+import type { Backend } from "#/api/backend-registry/types";
+import { ActiveBackendProvider } from "#/contexts/active-backend-context";
+import {
+ getCloudSharedConversation,
+ searchCloudSharedEvents,
+} from "#/api/cloud/shared-conversation-service.api";
+import { getCloudOrganizationMember } from "#/api/cloud/organization-service.api";
+
+// Mock the cloud services the shared-conversation queries depend on.
+vi.mock("#/api/cloud/shared-conversation-service.api", () => ({
+ getCloudSharedConversation: vi.fn(),
+ searchCloudSharedEvents: vi.fn(),
+}));
+vi.mock("#/api/cloud/organization-service.api", async (importOriginal) => ({
+ ...(await importOriginal<
+ typeof import("#/api/cloud/organization-service.api")
+ >()),
+ getCloudOrganizationMember: vi.fn(),
+}));
+
+// The message list is exercised by its own tests; keep this one on the header.
+vi.mock("#/components/conversation-events/chat/messages", () => ({
+ Messages: () => <section data-testid="shared-messages" />,
+}));
+
+const cloudBackend: Backend = {
+ id: "cloud-1",
+ name: "Production",
+ host: "https://app.all-hands.dev",
+ apiKey: "bearer-key",
+ kind: "cloud",
+};
+
+const ORG_ID = "org-1";
+const CREATOR_ID = "user-1";
+const CONVERSATION_ID = "conv-automation-1";
+
+function makeSharedConversation(): SharedConversationData {
+ return {
+ id: CONVERSATION_ID,
+ created_by_user_id: CREATOR_ID,
+ selected_repository: "OpenHands/agent-canvas",
+ selected_branch: "main",
+ git_provider: "github",
+ title: "Automated code review",
+ pr_number: [1688],
+ llm_model: "openhands/claude-haiku-4-5-20251001",
+ metrics: null,
+ parent_conversation_id: null,
+ sub_conversation_ids: [],
+ created_at: "2026-09-24T12:00:00.000Z",
+ updated_at: "2026-09-24T12:30:00.000Z",
+ };
+}
+
+function renderViewer() {
+ const queryClient = new QueryClient({
+ defaultOptions: { queries: { retry: false } },
+ });
+ return render(
+ <MemoryRouter initialEntries={[`/shared/conversations/${CONVERSATION_ID}`]}>
+ <QueryClientProvider client={queryClient}>
+ <ActiveBackendProvider>
+ <Routes>
+ <Route
+ path="/shared/conversations/:conversationId"
+ element={<SharedConversation />}
+ />
+ </Routes>
+ </ActiveBackendProvider>
+ </QueryClientProvider>
+ </MemoryRouter>,
+ );
+}
+
+beforeEach(() => {
+ window.localStorage.clear();
+ __resetActiveStoreForTests();
+ setRegisteredBackends([cloudBackend]);
+ setActiveSelection({ backendId: cloudBackend.id, orgId: ORG_ID });
+ vi.mocked(getCloudSharedConversation).mockReset();
+ vi.mocked(searchCloudSharedEvents).mockReset();
+ vi.mocked(getCloudOrganizationMember).mockReset();
+ vi.mocked(getCloudSharedConversation).mockResolvedValue(
+ makeSharedConversation(),
+ );
+ vi.mocked(searchCloudSharedEvents).mockResolvedValue({
+ items: [],
+ next_page_id: null,
+ });
+ vi.mocked(getCloudOrganizationMember).mockResolvedValue({
+ org_id: ORG_ID,
+ user_id: CREATOR_ID,
+ email: "[email protected]",
+ });
+});
+
+afterEach(() => {
+ window.localStorage.clear();
+ __resetActiveStoreForTests();
+});
+
+describe("shared conversation viewer — cloud backend", () => {
+ it("loads the conversation through the cloud backend and shows the creator's email", async () => {
+ // Arrange / Act
+ renderViewer();
+
+ // Assert
+ expect(
+ await screen.findByText(
+ `${I18nKey.CONVERSATION$CREATED_BY}: [email protected]`,
+ ),
+ ).toBeInTheDocument();
+ expect(getCloudSharedConversation).toHaveBeenCalledWith(CONVERSATION_ID);
+ expect(searchCloudSharedEvents).toHaveBeenCalledWith(
+ expect.objectContaining({ conversationId: CONVERSATION_ID }),
+ );
+ expect(getCloudOrganizationMember).toHaveBeenCalledWith(
+ ORG_ID,
+ CREATOR_ID,
+ expect.objectContaining({ id: cloudBackend.id }),
+ );
+ });
+
+ it("falls back to the creator's user id when the member lookup fails", async () => {
+ // Arrange — the creator belongs to an org the viewer is not browsing.
+ vi.mocked(getCloudOrganizationMember).mockRejectedValue(
+ new Error("Member not found"),
+ );
+
+ // Act
+ renderViewer();
+
+ // Assert
+ expect(
+ await screen.findByText(
+ `${I18nKey.CONVERSATION$CREATED_BY}: ${CREATOR_ID}`,
+ ),
+ ).toBeInTheDocument();
+ });
+});
diff --git a/src/api/cloud/shared-conversation-service.api.ts b/src/api/cloud/shared-conversation-service.api.ts
new file mode 100644
index 0000000000..c5af4d747d
--- /dev/null
+++ b/src/api/cloud/shared-conversation-service.api.ts
@@ -0,0 +1,59 @@
+import type { SharedConversation } from "@openhands/typescript-client";
+import type { OpenHandsEvent } from "#/types/agent-server/core";
+import { getActiveBackend } from "../backend-registry/active-store";
+import type { Backend } from "../backend-registry/types";
+import { callCloudProxy } from "./proxy";
+
+export interface SharedEventPage {
+ items: OpenHandsEvent[];
+ next_page_id: string | null;
+}
+
+function getActiveCloudBackend(): Backend {
+ const active = getActiveBackend().backend;
+ if (active.kind !== "cloud") {
+ throw new Error("Shared conversation calls require a cloud backend.");
+ }
+ return active;
+}
+
+/**
+ * Fetch a conversation shared with the caller from the cloud backend via
+ * `GET /api/shared-conversations?ids=<id>`. The endpoint serves public
+ * conversations to anyone and automation conversations to authenticated
+ * members of their org; it returns `null` for anything else.
+ */
+export async function getCloudSharedConversation(
+ conversationId: string,
+): Promise<SharedConversation | null> {
+ const backend = getActiveCloudBackend();
+ const params = new URLSearchParams({ ids: conversationId });
+ const data = await callCloudProxy<(SharedConversation | null)[]>({
+ backend,
+ method: "GET",
+ path: `/api/shared-conversations?${params.toString()}`,
+ });
+ return data?.[0] ?? null;
+}
+
+/**
+ * Page through the events of a shared conversation on the cloud backend via
+ * `GET /api/shared-events/search`.
+ */
+export async function searchCloudSharedEvents(options: {
+ conversationId: string;
+ limit?: number;
+ pageId?: string;
+}): Promise<SharedEventPage> {
+ const backend = getActiveCloudBackend();
+ const params = new URLSearchParams({
+ conversation_id: options.conversationId,
+ limit: String(options.limit ?? 100),
+ });
+ if (options.pageId) params.set("page_id", options.pageId);
+ return callCloudProxy<SharedEventPage>({
+ backend,
+ method: "GET",
+ path: `/api/shared-events/search?${params.toString()}`,
+ });
+}
diff --git a/src/hooks/query/use-shared-conversation-events.ts b/src/hooks/query/use-shared-conversation-events.ts
index 92aa5782d8..53a4811181 100644
--- a/src/hooks/query/use-shared-conversation-events.ts
+++ b/src/hooks/query/use-shared-conversation-events.ts
@@ -1,26 +1,25 @@
import { useInfiniteQuery } from "@tanstack/react-query";
import { SharedClient } from "@openhands/typescript-client/clients";
-import type { OpenHandsEvent } from "#/types/agent-server/core";
import { getAgentServerClientOptions } from "#/api/agent-server-client-options";
-
-interface SharedEventPage {
- items: OpenHandsEvent[];
- next_page_id: string | null;
-}
+import { getActiveBackend } from "#/api/backend-registry/active-store";
+import {
+ searchCloudSharedEvents,
+ type SharedEventPage,
+} from "#/api/cloud/shared-conversation-service.api";
export const useSharedConversationEvents = (conversationId?: string) =>
useInfiniteQuery({
queryKey: ["shared-conversation-events", conversationId],
- queryFn: ({ pageParam }) => {
+ queryFn: ({ pageParam }): Promise<SharedEventPage> => {
if (!conversationId) {
throw new Error("Conversation ID is required");
}
+ const request = { conversationId, limit: 100, pageId: pageParam };
+ if (getActiveBackend().backend.kind === "cloud") {
+ return searchCloudSharedEvents(request);
+ }
return new SharedClient(getAgentServerClientOptions()).searchSharedEvents(
- {
- conversationId,
- limit: 100,
- pageId: pageParam,
- },
+ request,
) as Promise<SharedEventPage>;
},
initialPageParam: undefined as string | undefined,
diff --git a/src/hooks/query/use-shared-conversation.ts b/src/hooks/query/use-shared-conversation.ts
index bb99eaddab..1f17c09103 100644
--- a/src/hooks/query/use-shared-conversation.ts
+++ b/src/hooks/query/use-shared-conversation.ts
@@ -1,18 +1,33 @@
import { useQuery } from "@tanstack/react-query";
import { SharedClient } from "@openhands/typescript-client/clients";
import { getAgentServerClientOptions } from "#/api/agent-server-client-options";
+import { getActiveBackend } from "#/api/backend-registry/active-store";
+import { getCloudSharedConversation } from "#/api/cloud/shared-conversation-service.api";
-export const useSharedConversation = (conversationId?: string) =>
+interface UseSharedConversationOptions {
+ enabled?: boolean;
+}
+
+export const useSharedConversation = (
+ conversationId?: string,
+ options: UseSharedConversationOptions = {},
+) =>
useQuery({
queryKey: ["shared-conversation", conversationId],
queryFn: () => {
if (!conversationId) {
throw new Error("Conversation ID is required");
}
+ if (getActiveBackend().backend.kind === "cloud") {
+ return getCloudSharedConversation(conversationId);
+ }
return new SharedClient(
getAgentServerClientOptions(),
).getSharedConversation(conversationId);
},
- enabled: !!conversationId,
+ enabled: !!conversationId && (options.enabled ?? true),
retry: false, // Don't retry for shared conversations
+ // The shared page renders its own not-found state, and the conversation
+ // route uses this query as a silent probe before reporting a miss.
+ meta: { disableToast: true },
});
diff --git a/src/i18n/translation.json b/src/i18n/translation.json
index be19e4add2..921b7450a3 100644
--- a/src/i18n/translation.json
+++ b/src/i18n/translation.json
@@ -10879,6 +10879,23 @@
"uk": "Створено",
"ca": "Creat"
},
+ "CONVERSATION$CREATED_BY": {
+ "en": "Created by",
+ "ja": "作成者",
+ "zh-CN": "创建者",
+ "zh-TW": "建立者",
+ "ko-KR": "작성자",
+ "de": "Erstellt von",
+ "no": "Opprettet av",
+ "it": "Creato da",
+ "pt": "Criado por",
+ "es": "Creado por",
+ "ar": "أنشأها",
+ "fr": "Créé par",
+ "tr": "Oluşturan",
+ "uk": "Створив",
+ "ca": "Creat per"
+ },
"CONVERSATION$AGO": {
"en": "ago",
"ja": "前",
diff --git a/src/routes/conversation.tsx b/src/routes/conversation.tsx
index 95bbc65fd2..14889dc217 100644
--- a/src/routes/conversation.tsx
+++ b/src/routes/conversation.tsx
@@ -17,6 +17,7 @@ import { AgentState } from "#/types/agent-state";
import { EventHandler } from "../wrapper/event-handler";
import { useActiveConversation } from "#/hooks/query/use-active-conversation";
+import { useSharedConversation } from "#/hooks/query/use-shared-conversation";
import { useTaskPollingController } from "#/hooks/query/use-task-polling";
import { displayErrorToast } from "#/utils/custom-toast-handlers";
@@ -103,27 +104,47 @@ function AppContent() {
}
}, [isTask, taskStatus, taskDetail, t, navigate, location.state]);
- React.useEffect(() => {
- if (!isFetched || !isAuthed) return;
- // The BackendSelector is in the middle of redirecting us away from
- // this route — don't toast/navigate based on a 404 that's just
- // "this id doesn't exist on the new backend".
- if (backendChanged) return;
+ // The BackendSelector is in the middle of redirecting us away from
+ // this route — don't toast/navigate based on a 404 that's just
+ // "this id doesn't exist on the new backend".
+ const ownerLookupMissed =
+ isFetched && !!isAuthed && !backendChanged && !conversation;
+
+ // On cloud, a conversation the owner lookup cannot see may still be shared
+ // with this user: public, or created by an automation in one of their orgs.
+ // Probe the shared lookup before giving up and send them to the read-only
+ // view when it resolves. Local backends have no sharing, and start-task ids
+ // are not conversations.
+ const shouldProbeShared =
+ ownerLookupMissed &&
+ active.backend.kind === "cloud" &&
+ !!conversationId &&
+ !conversationId.startsWith("task-");
+ const { data: sharedConversation, isFetched: isSharedProbeFetched } =
+ useSharedConversation(conversationId, { enabled: shouldProbeShared });
- if (!conversation) {
- // Clear the per-backend "last selected" slot so the next switch
- // to this backend doesn't try to revisit a stale id.
- clearLastConversationId(active.backend.id, active.orgId);
- displayErrorToast(t(I18nKey.CONVERSATION$NOT_EXIST_OR_NO_PERMISSION));
- navigate("/conversations");
+ React.useEffect(() => {
+ if (!ownerLookupMissed) return;
+ if (shouldProbeShared) {
+ if (!isSharedProbeFetched) return;
+ if (sharedConversation) {
+ navigate(`/shared/conversations/${conversationId}`, { replace: true });
+ return;
+ }
}
+ // Clear the per-backend "last selected" slot so the next switch
+ // to this backend doesn't try to revisit a stale id.
+ clearLastConversationId(active.backend.id, active.orgId);
+ displayErrorToast(t(I18nKey.CONVERSATION$NOT_EXIST_OR_NO_PERMISSION));
+ navigate("/conversations");
}, [
- conversation,
- isFetched,
- isAuthed,
+ ownerLookupMissed,
+ shouldProbeShared,
+ isSharedProbeFetched,
+ sharedConversation,
+ conversationId,
navigate,
t,
- backendChanged,
active.backend.id,
active.orgId,
]);
diff --git a/src/routes/shared-conversation.tsx b/src/routes/shared-conversation.tsx
index bd59a1838e..f09c98d1bc 100644
--- a/src/routes/shared-conversation.tsx
+++ b/src/routes/shared-conversation.tsx
@@ -4,6 +4,8 @@ import { useTranslation } from "react-i18next";
import { I18nKey } from "#/i18n/declaration";
import { useSharedConversation } from "#/hooks/query/use-shared-conversation";
import { useSharedConversationEvents } from "#/hooks/query/use-shared-conversation-events";
+import { useCloudOrgMember } from "#/hooks/query/use-cloud-org-member";
+import { useActiveBackend } from "#/contexts/active-backend-context";
import { Messages } from "#/components/conversation-events/chat/messages";
import { shouldRenderEvent } from "#/components/conversation-events/chat/event-content-helpers/should-render-event";
import { LoadingSpinner } from "#/components/shared/loading-spinner";
@@ -12,9 +14,22 @@ import { OpenHandsEvent } from "#/types/agent-server/core";
import OpenHandsLogo from "#/assets/branding/openhands-logo.svg?react";
import { useInfiniteScroll } from "#/hooks/use-infinite-scroll";
+/**
+ * Resolve the creator's email through the active cloud org, following the
+ * "Automation Runs As" precedent on the automation detail page. Falls back to
+ * the raw user id when the member lookup cannot resolve it (for example when
+ * the conversation belongs to another org the viewer is a member of).
+ */
+function SharedConversationCreator({ userId }: { userId: string }) {
+ const { data: creator, isFetching } = useCloudOrgMember(userId);
+ if (creator?.email) return <>{creator.email}</>;
+ return isFetching ? null : <>{userId}</>;
+}
+
export default function SharedConversation() {
const { t } = useTranslation("openhands");
const { conversationId } = useParams<{ conversationId: string }>();
+ const active = useActiveBackend();
const {
data: conversation,
@@ -111,6 +126,18 @@ export default function SharedConversation() {
{t(I18nKey.LLM$MODEL)}: {conversation.llm_model}
</div>
)}
+ {conversation?.created_by_user_id && (
+ <div className="text-sm text-muted">
+ {t(I18nKey.CONVERSATION$CREATED_BY)}:{" "}
+ {active.backend.kind === "cloud" ? (
+ <SharedConversationCreator
+ userId={conversation.created_by_user_id}
+ />
+ ) : (
+ conversation.created_by_user_id
+ )}
+ </div>
+ )}
</div>
</div>
</div>