Skip to content

🙌 OpenHands: AI-Driven Development

fix: show Agent Profile picker in blank conversations (#1629)

Devind68bbc8d38ee
diff --git a/__tests__/api/agent-server-conversation-service.test.ts b/__tests__/api/agent-server-conversation-service.test.ts
index 3c218dfc3f..b93c2957f1 100644
--- a/__tests__/api/agent-server-conversation-service.test.ts
+++ b/__tests__/api/agent-server-conversation-service.test.ts
@@ -557,6 +557,32 @@ describe("AgentServerConversationService", () => {
expect(result.items[0]?.sandbox_status).toBe("PAUSED");
});
+ it("preserves the launched Agent Profile through the wire normalizer", async () => {
+ mockHttpGet.mockResolvedValue({
+ data: [
+ {
+ id: "conv-profile",
+ created_at: "2024-01-01",
+ updated_at: "2024-01-01",
+ launched_agent_profile: {
+ agent_profile_id: "profile-1",
+ revision: 3,
+ },
+ },
+ ],
+ });
+
+ const [conversation] =
+ await AgentServerConversationService.batchGetAppConversations([
+ "conv-profile",
+ ]);
+
+ expect(conversation?.launched_agent_profile).toEqual({
+ agent_profile_id: "profile-1",
+ revision: 3,
+ });
+ });
+
it("passes sandbox_status null through when field is absent", async () => {
mockHttpGet.mockResolvedValue({
data: [
diff --git a/__tests__/components/features/chat/components/chat-input-actions.test.tsx b/__tests__/components/features/chat/components/chat-input-actions.test.tsx
index b7fb19bed0..a55fe8361c 100644
--- a/__tests__/components/features/chat/components/chat-input-actions.test.tsx
+++ b/__tests__/components/features/chat/components/chat-input-actions.test.tsx
@@ -102,15 +102,39 @@ describe("ChatInputActions", () => {
).not.toBeInTheDocument();
});
- it("renders the LLM-profile switcher inside a local OpenHands conversation", () => {
+ it("renders the AgentProfile picker inside a blank local OpenHands conversation", () => {
useActiveConversationMock.mockReturnValue({
- data: { conversation_id: "test-conversation-id", llm_model: "gpt-4o" },
+ data: { conversation_id: "test-conversation-id", llm_model: null },
});
- renderWithProviders(<ChatInputActions disabled={false} />, {
- navigation: { conversationId: "test-conversation-id" },
+ renderWithProviders(
+ <ChatInputActions disabled={false} hasStartedConversation={false} />,
+ {
+ navigation: { conversationId: "test-conversation-id" },
+ },
+ );
+
+ expect(screen.getByTestId("agent-profile-picker-stub")).toBeInTheDocument();
+ expect(
+ screen.queryByTestId("llm-profile-picker-stub"),
+ ).not.toBeInTheDocument();
+ expect(
+ screen.queryByTestId("chat-input-llm-model"),
+ ).not.toBeInTheDocument();
+ });
+
+ it("renders the LLM-profile switcher inside a started local OpenHands conversation", () => {
+ useActiveConversationMock.mockReturnValue({
+ data: { conversation_id: "test-conversation-id", llm_model: "gpt-4o" },
});
+ renderWithProviders(
+ <ChatInputActions disabled={false} hasStartedConversation />,
+ {
+ navigation: { conversationId: "test-conversation-id" },
+ },
+ );
+
// In a conversation the user live-switches the LLM profile, not start-new.
expect(screen.getByTestId("llm-profile-picker-stub")).toBeInTheDocument();
expect(
@@ -130,9 +154,12 @@ describe("ChatInputActions", () => {
},
});
- renderWithProviders(<ChatInputActions disabled={false} />, {
- navigation: { conversationId: "test-conversation-id" },
- });
+ renderWithProviders(
+ <ChatInputActions disabled={false} hasStartedConversation />,
+ {
+ navigation: { conversationId: "test-conversation-id" },
+ },
+ );
// ACP in a conversation live-switches the running model via ChatInputModel.
expect(screen.getByTestId("chat-input-llm-model")).toBeInTheDocument();
@@ -157,7 +184,7 @@ describe("ChatInputActions", () => {
renderWithProviders(
<ActiveBackendProvider>
- <ChatInputActions disabled={false} />
+ <ChatInputActions disabled={false} hasStartedConversation />
</ActiveBackendProvider>,
);
@@ -182,7 +209,7 @@ describe("ChatInputActions", () => {
renderWithProviders(
<ActiveBackendProvider>
- <ChatInputActions disabled={false} />
+ <ChatInputActions disabled={false} hasStartedConversation />
</ActiveBackendProvider>,
);
@@ -203,7 +230,7 @@ describe("ChatInputActions", () => {
renderWithProviders(
<ActiveBackendProvider>
- <ChatInputActions disabled={false} />
+ <ChatInputActions disabled={false} hasStartedConversation />
</ActiveBackendProvider>,
);
diff --git a/__tests__/components/features/chat/components/chat-input-profile-picker.test.tsx b/__tests__/components/features/chat/components/chat-input-profile-picker.test.tsx
index 38f2b7a1a5..fd975199c9 100644
--- a/__tests__/components/features/chat/components/chat-input-profile-picker.test.tsx
+++ b/__tests__/components/features/chat/components/chat-input-profile-picker.test.tsx
@@ -1,14 +1,26 @@
import { fireEvent, screen } from "@testing-library/react";
import { describe, it, expect, vi, beforeEach } from "vitest";
import { renderWithProviders } from "test-utils";
+import { setStoredConversationMetadata } from "#/api/conversation-metadata-store";
const useAgentProfilesMock = vi.fn();
+const useActiveConversationMock = vi.fn();
const activateProfileMutate = vi.fn();
+const createConversationMutate = vi.fn();
vi.mock("#/hooks/query/use-agent-profiles", () => ({
useAgentProfiles: () => useAgentProfilesMock(),
}));
+vi.mock("#/hooks/query/use-active-conversation", () => ({
+ useActiveConversation: () => useActiveConversationMock(),
+}));
+
+vi.mock("#/hooks/mutation/use-create-conversation", () => ({
+ useCreateConversation: () => ({ mutate: createConversationMutate }),
+ CREATE_CONVERSATION_MUTATION_KEY: ["create-conversation"],
+}));
+
vi.mock("#/hooks/mutation/use-activate-agent-profile", () => ({
useActivateAgentProfile: () => ({
mutate: activateProfileMutate,
@@ -24,38 +36,56 @@ const PROFILES = [
{ id: "id-codex", name: "Codex", agent_kind: "acp" },
];
-// The picker is home-only (a running conversation shows the LLM-profile / model
-// picker instead), so selecting a profile activates it as the launch default.
describe("ChatInputProfilePicker", () => {
beforeEach(() => {
useAgentProfilesMock.mockReset();
+ useActiveConversationMock.mockReset();
activateProfileMutate.mockReset();
+ createConversationMutate.mockReset();
+ localStorage.clear();
useAgentProfilesMock.mockReturnValue({
data: { profiles: PROFILES, active_agent_profile_id: "id-default" },
isLoading: false,
});
+ useActiveConversationMock.mockReturnValue({
+ data: undefined,
+ isLoading: false,
+ });
});
+ const renderHomePicker = () =>
+ renderWithProviders(<ChatInputProfilePicker />, {
+ navigation: { conversationId: null },
+ });
+
it("renders nothing when there are no profiles", () => {
useAgentProfilesMock.mockReturnValue({
data: { profiles: [], active_agent_profile_id: null },
isLoading: false,
});
- const { container } = renderWithProviders(<ChatInputProfilePicker />);
+ const { container } = renderHomePicker();
+ expect(container).toBeEmptyDOMElement();
+ });
+
+ it("renders nothing while a cloud start task is provisioning", () => {
+ const { container } = renderWithProviders(<ChatInputProfilePicker />, {
+ navigation: { conversationId: "task-start-1" },
+ });
+
expect(container).toBeEmptyDOMElement();
});
it("labels the button with the active profile", () => {
- renderWithProviders(<ChatInputProfilePicker />);
+ renderHomePicker();
expect(screen.getByTestId("chat-input-agent-profile")).toHaveTextContent(
"Default",
);
});
it("activates the picked profile", () => {
- renderWithProviders(<ChatInputProfilePicker />);
+ renderHomePicker();
fireEvent.click(screen.getByTestId("chat-input-agent-profile"));
fireEvent.click(
screen.getByTestId("chat-input-agent-profile-option-Codex"),
@@ -65,7 +95,7 @@ describe("ChatInputProfilePicker", () => {
});
it("does not activate when the active profile is re-selected", () => {
- renderWithProviders(<ChatInputProfilePicker />);
+ renderHomePicker();
fireEvent.click(screen.getByTestId("chat-input-agent-profile"));
fireEvent.click(
screen.getByTestId("chat-input-agent-profile-option-Default"),
@@ -75,11 +105,132 @@ describe("ChatInputProfilePicker", () => {
});
it("links to the AgentProfile library in settings", () => {
- const { container } = renderWithProviders(<ChatInputProfilePicker />);
+ const { container } = renderHomePicker();
fireEvent.click(screen.getByTestId("chat-input-agent-profile"));
expect(
container.ownerDocument.querySelector('a[href="/settings/agents"]'),
).not.toBeNull();
});
+
+ it("shows the launched profile inside a blank conversation", () => {
+ useAgentProfilesMock.mockReturnValue({
+ data: { profiles: PROFILES, active_agent_profile_id: "id-codex" },
+ isLoading: false,
+ });
+ useActiveConversationMock.mockReturnValue({
+ data: {
+ id: "conv-1",
+ launched_agent_profile: {
+ agent_profile_id: "id-default",
+ revision: 2,
+ },
+ },
+ isLoading: false,
+ });
+
+ renderWithProviders(<ChatInputProfilePicker />, {
+ navigation: { conversationId: "conv-1" },
+ });
+
+ expect(screen.getByTestId("chat-input-agent-profile")).toHaveTextContent(
+ "Default",
+ );
+ });
+
+ it("starts a replacement conversation with the selected profile and workspace", () => {
+ const navigate = vi.fn();
+ useActiveConversationMock.mockReturnValue({
+ data: {
+ id: "conv-workspace",
+ selected_repository: null,
+ selected_workspace: "/workspace/alpha",
+ launched_agent_profile: {
+ agent_profile_id: "id-default",
+ revision: 1,
+ },
+ },
+ isLoading: false,
+ });
+
+ renderWithProviders(<ChatInputProfilePicker />, {
+ navigation: { conversationId: "conv-workspace", navigate },
+ });
+ fireEvent.click(screen.getByTestId("chat-input-agent-profile"));
+
+ expect(screen.getByText("CHAT$START_NEW_WITH_PROFILE_HINT")).toBeVisible();
+ fireEvent.click(
+ screen.getByTestId("chat-input-agent-profile-option-Codex"),
+ );
+
+ expect(createConversationMutate).toHaveBeenCalledWith(
+ {
+ agentProfileId: "id-codex",
+ entryPoint: "blank_conversation_profile_picker",
+ workingDir: "/workspace/alpha",
+ workspaceMode: "local_repo",
+ },
+ expect.objectContaining({ onSuccess: expect.any(Function) }),
+ );
+ expect(activateProfileMutate).not.toHaveBeenCalled();
+
+ const onSuccess = createConversationMutate.mock.calls[0]?.[1]?.onSuccess;
+ onSuccess({ conversation_id: "conv-2" });
+ expect(navigate).toHaveBeenCalledWith("/conversations/conv-2");
+ });
+
+ it("preserves repository and plugin context when changing a blank conversation profile", () => {
+ setStoredConversationMetadata("conv-repo", {
+ selected_repository: "OpenHands/agent-canvas",
+ selected_branch: "feature",
+ git_provider: "github",
+ plugins: [
+ {
+ source: "github:OpenHands/extensions",
+ ref: "v1",
+ repo_path: "plugins/weather",
+ },
+ ],
+ });
+ useActiveConversationMock.mockReturnValue({
+ data: {
+ id: "conv-repo",
+ selected_repository: "OpenHands/agent-canvas",
+ selected_branch: "feature",
+ git_provider: "github",
+ launched_agent_profile: {
+ agent_profile_id: "id-default",
+ revision: 1,
+ },
+ },
+ isLoading: false,
+ });
+
+ renderWithProviders(<ChatInputProfilePicker />, {
+ navigation: { conversationId: "conv-repo" },
+ });
+ fireEvent.click(screen.getByTestId("chat-input-agent-profile"));
+ fireEvent.click(
+ screen.getByTestId("chat-input-agent-profile-option-Codex"),
+ );
+
+ expect(createConversationMutate).toHaveBeenCalledWith(
+ expect.objectContaining({
+ agentProfileId: "id-codex",
+ repository: {
+ name: "OpenHands/agent-canvas",
+ gitProvider: "github",
+ branch: "feature",
+ },
+ plugins: [
+ {
+ source: "github:OpenHands/extensions",
+ ref: "v1",
+ repo_path: "plugins/weather",
+ },
+ ],
+ }),
+ expect.any(Object),
+ );
+ });
});
diff --git a/__tests__/components/features/chat/components/resolve-picker-kind.test.ts b/__tests__/components/features/chat/components/resolve-picker-kind.test.ts
index 573eded5e4..ae9e81b7b6 100644
--- a/__tests__/components/features/chat/components/resolve-picker-kind.test.ts
+++ b/__tests__/components/features/chat/components/resolve-picker-kind.test.ts
@@ -1,5 +1,6 @@
import { describe, expect, it } from "vitest";
import {
+ hasConversationStarted,
resolvePickerKind,
type ResolvePickerKindInput,
} from "#/components/features/chat/components/resolve-picker-kind";
@@ -53,11 +54,46 @@ describe("resolvePickerKind", () => {
});
describe("inside a conversation", () => {
+ it("shows the agent-profile picker for an unstarted conversation when profiles exist", () => {
+ expect(
+ resolvePickerKind({
+ ...base,
+ hasConversation: true,
+ hasStartedConversation: false,
+ isCloud: false,
+ isAcp: false,
+ profilesAvailable: true,
+ }),
+ ).toBe("agent-profile");
+ });
+
+ it("uses the pre-run fallback for an unstarted conversation when profiles are unavailable", () => {
+ expect(
+ resolvePickerKind({
+ ...base,
+ hasConversation: true,
+ hasStartedConversation: false,
+ isCloud: false,
+ profilesAvailable: false,
+ }),
+ ).toBe("llm-profile");
+ expect(
+ resolvePickerKind({
+ ...base,
+ hasConversation: true,
+ hasStartedConversation: false,
+ isCloud: true,
+ profilesAvailable: false,
+ }),
+ ).toBe("model");
+ });
+
it("shows the model picker for an ACP conversation regardless of backend", () => {
expect(
resolvePickerKind({
...base,
hasConversation: true,
+ hasStartedConversation: true,
isCloud: false,
isAcp: true,
}),
@@ -66,6 +102,7 @@ describe("resolvePickerKind", () => {
resolvePickerKind({
...base,
hasConversation: true,
+ hasStartedConversation: true,
isCloud: true,
isAcp: true,
}),
@@ -80,6 +117,7 @@ describe("resolvePickerKind", () => {
resolvePickerKind({
...base,
hasConversation: true,
+ hasStartedConversation: true,
isCloud: false,
isAcp: false,
}),
@@ -88,6 +126,7 @@ describe("resolvePickerKind", () => {
resolvePickerKind({
...base,
hasConversation: true,
+ hasStartedConversation: true,
isCloud: true,
isAcp: false,
}),
@@ -99,6 +138,7 @@ describe("resolvePickerKind", () => {
resolvePickerKind({
...base,
hasConversation: true,
+ hasStartedConversation: true,
isCloud: false,
isAcp: false,
profilesAvailable: false,
@@ -107,3 +147,27 @@ describe("resolvePickerKind", () => {
});
});
});
+
+describe("hasConversationStarted", () => {
+ const empty = {
+ isLoadingHistory: false,
+ hasUserEvents: false,
+ hasPendingUserMessages: false,
+ hasSubstantiveAgentActions: false,
+ hasModelEntries: false,
+ };
+
+ it("keeps a fully loaded blank conversation in pre-run state", () => {
+ expect(hasConversationStarted(empty)).toBe(false);
+ });
+
+ it.each([
+ "isLoadingHistory",
+ "hasUserEvents",
+ "hasPendingUserMessages",
+ "hasSubstantiveAgentActions",
+ "hasModelEntries",
+ ] as const)("treats %s as started", (field) => {
+ expect(hasConversationStarted({ ...empty, [field]: true })).toBe(true);
+ });
+});
diff --git a/__tests__/hooks/query/use-task-polling.test.tsx b/__tests__/hooks/query/use-task-polling.test.tsx
index eab273ca86..0b760b460a 100644
--- a/__tests__/hooks/query/use-task-polling.test.tsx
+++ b/__tests__/hooks/query/use-task-polling.test.tsx
@@ -13,6 +13,7 @@ import {
setPendingTaskDraft,
} from "#/utils/conversation-local-storage";
import { resetPendingTaskMessageLinkState } from "#/utils/pending-task-message-link";
+import { getStoredConversationMetadata } from "#/api/conversation-metadata-store";
vi.mock(
"#/api/conversation-service/agent-server-conversation-service.api",
@@ -100,6 +101,45 @@ describe("useTaskPolling", () => {
);
});
+ it("stores cloud task plugin coordinates on the real conversation", async () => {
+ vi.mocked(AgentServerConversationService.getStartTask).mockResolvedValue({
+ ...readyTask,
+ request: {
+ selected_repository: "OpenHands/agent-canvas",
+ selected_branch: "main",
+ git_provider: "github",
+ plugins: [
+ {
+ source: "github:OpenHands/extensions",
+ ref: "v1",
+ repo_path: "plugins/weather",
+ parameters: { apiKey: "secret" },
+ },
+ ],
+ },
+ });
+
+ renderHook(() => useTaskPolling(), { wrapper: createWrapper() });
+
+ await waitFor(() => {
+ expect(navigate).toHaveBeenCalledWith("/conversations/conversation-1", {
+ replace: true,
+ });
+ });
+ expect(getStoredConversationMetadata("conversation-1")).toEqual({
+ selected_repository: "OpenHands/agent-canvas",
+ selected_branch: "main",
+ git_provider: "github",
+ plugins: [
+ {
+ source: "github:OpenHands/extensions",
+ ref: "v1",
+ repo_path: "plugins/weather",
+ },
+ ],
+ });
+ });
+
it("reassigns optimistic pending messages on the real conversation route", async () => {
vi.mocked(AgentServerConversationService.getStartTask).mockResolvedValue(
readyTask,
diff --git a/src/api/agent-server-adapter.ts b/src/api/agent-server-adapter.ts
index 203046b02e..ed07c28a56 100644
--- a/src/api/agent-server-adapter.ts
+++ b/src/api/agent-server-adapter.ts
@@ -82,6 +82,10 @@ export interface DirectConversationInfo {
* values are opaque strings.
*/
tags?: Record<string, string> | null;
+ launched_agent_profile?: {
+ agent_profile_id: string;
+ revision: number;
+ } | null;
}
// Module qualname for the Canvas-UI tool. The agent-server imports this via
@@ -329,6 +333,7 @@ export function toAppConversation(
pr_number: [],
agent_kind: isAcp ? "acp" : "openhands",
acp_server: acpServer,
+ launched_agent_profile: info.launched_agent_profile ?? null,
// Chip path: omit ``providerDefault`` so that when no concrete model
// resolves, the chip falls back to the provider display name in
// ConversationCardFooter rather than a registry default the session may
diff --git a/src/api/conversation-metadata-store.ts b/src/api/conversation-metadata-store.ts
index 60388b57f7..be059b3682 100644
--- a/src/api/conversation-metadata-store.ts
+++ b/src/api/conversation-metadata-store.ts
@@ -35,18 +35,16 @@ export interface ConversationMetadata {
* is ambiguous (issue #1082).
*/
active_profile?: string | null;
- /**
- * Snapshot of the plugins loaded into the conversation, captured at creation
- * (coordinates only — `parameters` are stripped): plugins explicitly attached
- * at creation plus the enabled installed plugins the SDK auto-loads into new
- * local conversations. The agent-server doesn't expose a live conversation's
- * loaded plugins, so this is the client-side source for the in-conversation
- * plugins view. Local + forward-only: only set for conversations created
- * after this shipped, and only when `app_conversation_id` is known.
- */
+ /** Store plugin coordinates only; parameters may contain secrets. */
plugins?: PluginSpec[] | null;
}
+export const toPluginCoordinates = (plugin: PluginSpec): PluginSpec => ({
+ source: plugin.source,
+ ref: plugin.ref ?? null,
+ repo_path: plugin.repo_path ?? null,
+});
+
type StoredMetadata = Record<string, ConversationMetadata>;
const readAll = (): StoredMetadata => {
diff --git a/src/api/conversation-service/agent-server-conversation-service.api.ts b/src/api/conversation-service/agent-server-conversation-service.api.ts
index ed0afcf710..f330a8bcff 100644
--- a/src/api/conversation-service/agent-server-conversation-service.api.ts
+++ b/src/api/conversation-service/agent-server-conversation-service.api.ts
@@ -181,6 +181,17 @@ function normalizeTags(value: unknown): Record<string, string> | null {
return tags;
}
+function normalizeLaunchedAgentProfile(
+ value: unknown,
+): DirectConversationInfo["launched_agent_profile"] {
+ if (!isRecord(value)) return null;
+ const { agent_profile_id: agentProfileId, revision } = value;
+ if (typeof agentProfileId !== "string" || typeof revision !== "number") {
+ return null;
+ }
+ return { agent_profile_id: agentProfileId, revision };
+}
+
function normalizeAbsolutePath(path: string): string | null {
if (!path.startsWith("/")) return null;
@@ -231,6 +242,9 @@ function requireDirectConversationInfo(item: unknown): DirectConversationInfo {
agent: normalizeAgent(item.agent),
workspace: normalizeWorkspace(item.workspace),
tags: normalizeTags(item.tags),
+ launched_agent_profile: normalizeLaunchedAgentProfile(
+ item.launched_agent_profile,
+ ),
// SDK-runtime ACP model fields (populated when the agent-server supports
// ``ConversationInfo.current_model_*``). Consumed by the conversation
// adapter to drive the per-card chip's model text. Older agent-servers
diff --git a/src/api/conversation-service/agent-server-conversation-service.types.ts b/src/api/conversation-service/agent-server-conversation-service.types.ts
index 787725551b..9f273c0e2b 100644
--- a/src/api/conversation-service/agent-server-conversation-service.types.ts
+++ b/src/api/conversation-service/agent-server-conversation-service.types.ts
@@ -126,6 +126,11 @@ export interface ConversationWorkspace {
working_dir: string | null;
}
+export interface LaunchedAgentProfile {
+ agent_profile_id: string;
+ revision: number;
+}
+
export interface AppConversation {
id: string;
created_by_user_id: string | null;
@@ -144,6 +149,7 @@ export interface AppConversation {
* carry the ACP subprocess model for display).
*/
agent_kind?: "openhands" | "acp" | null;
+ launched_agent_profile?: LaunchedAgentProfile | null;
/**
* For ACP conversations, the registry key of the ACP CLI server the
* conversation was launched against (e.g. ``"claude-code"``, ``"codex"``,
diff --git a/src/components/features/chat/chat-interface.tsx b/src/components/features/chat/chat-interface.tsx
index 8afbd03403..4ae3971665 100644
--- a/src/components/features/chat/chat-interface.tsx
+++ b/src/components/features/chat/chat-interface.tsx
@@ -49,6 +49,7 @@ import { useNewConversationCommand } from "#/hooks/mutation/use-new-conversation
import { useOptionalConversationId } from "#/hooks/use-conversation-id";
import { useActiveConversation } from "#/hooks/query/use-active-conversation";
import { I18nKey } from "#/i18n/declaration";
+import { hasConversationStarted } from "./components/resolve-picker-kind";
function getEntryPoint(
hasRepository: boolean | null,
@@ -250,6 +251,19 @@ export function ChatInterface() {
[pendingMessages, conversationId],
);
+ const hasModelEntries = useModelStore((s) =>
+ conversationId
+ ? (s.entriesByConversation[conversationId]?.length ?? 0) > 0
+ : false,
+ );
+ const hasStartedConversation = hasConversationStarted({
+ isLoadingHistory: conversationWebSocket?.isLoadingHistory === true,
+ hasUserEvents: userEventsExist,
+ hasPendingUserMessages,
+ hasSubstantiveAgentActions,
+ hasModelEntries,
+ });
+
// Show V1 messages immediately if events exist in store (e.g., remount),
// if the user already has a locally-tracked pending bubble (home-page cloud
// submit while history/WS catch up), or once loading completes. This
@@ -267,17 +281,6 @@ export function ChatInterface() {
const isHistoryLoading = !showConversationMessages;
const isChatLoading = isHistoryLoading && !isTask;
- // The empty-state ChatSuggestions overlay is absolutely positioned with
- // `pointer-events-auto`, so it would block clicks on any /model entry
- // rendered behind it. Once the user has run /model, the conversation is
- // no longer logically empty — hide suggestions so the profile list is
- // interactive.
- const hasModelEntries = useModelStore((s) =>
- conversationId
- ? (s.entriesByConversation[conversationId]?.length ?? 0) > 0
- : false,
- );
-
const handleSendMessage = async (
content: string,
originalImages: File[],
@@ -630,6 +633,7 @@ export function ChatInterface() {
<InteractiveChatBox
onSubmit={handleSendMessage}
disabled={isNewConversationPending || llmBlocked}
+ hasStartedConversation={hasStartedConversation}
/>
</div>
)}
diff --git a/src/components/features/chat/components/chat-input-actions.tsx b/src/components/features/chat/components/chat-input-actions.tsx
index a8ee86dea4..2ba1fa8a5c 100644
--- a/src/components/features/chat/components/chat-input-actions.tsx
+++ b/src/components/features/chat/components/chat-input-actions.tsx
@@ -46,6 +46,7 @@ import {
interface ChatInputActionsProps {
disabled: boolean;
canSubmit?: boolean;
+ hasStartedConversation?: boolean;
onAddFileClick?: () => void;
showButton?: boolean;
buttonClassName?: string;
@@ -55,6 +56,7 @@ interface ChatInputActionsProps {
export function ChatInputActions({
disabled,
canSubmit = true,
+ hasStartedConversation,
onAddFileClick = () => {},
showButton = true,
buttonClassName = "",
@@ -247,6 +249,7 @@ export function ChatInputActions({
// `resolve-picker-kind.test.ts`).
const pickerKind = resolvePickerKind({
hasConversation: !!conversationId,
+ hasStartedConversation,
isCloud,
isAcp: modelState.isAcpContext,
profilesAvailable: !agentProfilesUnavailableOnHome,
diff --git a/src/components/features/chat/components/chat-input-container.tsx b/src/components/features/chat/components/chat-input-container.tsx
index 684c5bb7d0..2905bcb24a 100644
--- a/src/components/features/chat/components/chat-input-container.tsx
+++ b/src/components/features/chat/components/chat-input-container.tsx
@@ -13,6 +13,7 @@ interface ChatInputContainerProps {
isDragOver: boolean;
disabled: boolean;
canSubmit: boolean;
+ hasStartedConversation?: boolean;
isNewConversationPending?: boolean;
showButton: boolean;
buttonClassName: string;
@@ -38,6 +39,7 @@ export function ChatInputContainer({
isDragOver,
disabled,
canSubmit,
+ hasStartedConversation,
isNewConversationPending = false,
showButton,
buttonClassName,
@@ -102,6 +104,7 @@ export function ChatInputContainer({
<ChatInputActions
disabled={disabled}
canSubmit={canSubmit}
+ hasStartedConversation={hasStartedConversation}
onAddFileClick={() => handleFileIconClick(disabled)}
showButton={showButton}
buttonClassName={buttonClassName}
diff --git a/src/components/features/chat/components/chat-input-profile-picker.tsx b/src/components/features/chat/components/chat-input-profile-picker.tsx
index 24c86ec1a9..ad70673d54 100644
--- a/src/components/features/chat/components/chat-input-profile-picker.tsx
+++ b/src/components/features/chat/components/chat-input-profile-picker.tsx
@@ -36,8 +36,13 @@ export function ChatInputProfileMenuContent({
settingsIconClassName,
}: ChatInputProfileMenuContentProps) {
const { t } = useTranslation("openhands");
- const { profiles, currentProfileId, selectProfile } =
- useChatInputProfileState();
+ const {
+ profiles,
+ currentProfileId,
+ isInConversation,
+ isSwitching,
+ selectProfile,
+ } = useChatInputProfileState();
const handleSelect = (profile: (typeof profiles)[number]) => {
selectProfile(profile);
@@ -62,6 +67,7 @@ export function ChatInputProfileMenuContent({
<ContextMenuListItem
key={profile.id ?? profile.name}
testId={`chat-input-agent-profile-option-${profile.name}`}
+ isDisabled={isSwitching}
onClick={(event) => {
event.preventDefault();
event.stopPropagation();
@@ -93,6 +99,13 @@ export function ChatInputProfileMenuContent({
</ContextMenuListItem>
);
})}
+ {isInConversation && (
+ <li role="presentation" className="px-2 pt-0.5 pb-1">
+ <Typography.Text className="text-[11px] text-[var(--oh-text-dim)] leading-4">
+ {t(I18nKey.CHAT$START_NEW_WITH_PROFILE_HINT)}
+ </Typography.Text>
+ </li>
+ )}
</>
)}
{profiles.length > 0 && <Divider inset={dividerInset} />}
diff --git a/src/components/features/chat/components/resolve-picker-kind.ts b/src/components/features/chat/components/resolve-picker-kind.ts
index 3fb75ab733..4f7dadfdef 100644
--- a/src/components/features/chat/components/resolve-picker-kind.ts
+++ b/src/components/features/chat/components/resolve-picker-kind.ts
@@ -1,40 +1,44 @@
export type PickerKind = "model" | "agent-profile" | "llm-profile";
+export interface ConversationStartState {
+ isLoadingHistory: boolean;
+ hasUserEvents: boolean;
+ hasPendingUserMessages: boolean;
+ hasSubstantiveAgentActions: boolean;
+ hasModelEntries: boolean;
+}
+
+export function hasConversationStarted({
+ isLoadingHistory,
+ hasUserEvents,
+ hasPendingUserMessages,
+ hasSubstantiveAgentActions,
+ hasModelEntries,
+}: ConversationStartState) {
+ return (
+ isLoadingHistory ||
+ hasUserEvents ||
+ hasPendingUserMessages ||
+ hasSubstantiveAgentActions ||
+ hasModelEntries
+ );
+}
+
export interface ResolvePickerKindInput {
- /** A conversation is active (i.e. we're inside a conversation, not on home). */
hasConversation: boolean;
- /** The active backend is cloud (vs. a local agent-server). */
+ hasStartedConversation?: boolean;
isCloud: boolean;
- /** The current context runs an ACP agent (active conv or home ACP settings). */
isAcp: boolean;
- /** At least one AgentProfile exists to launch the next conversation from. */
profilesAvailable: boolean;
}
-
-/**
- * Decide which chat-input model/profile picker to show. Pure so the matrix is
- * unit-tested directly (see `resolve-picker-kind.test.ts`).
- *
- * - Home (local or cloud): the AgentProfile picker, which starts a new
- * conversation / activates the default (#3727, cloud via #15060). When no
- * profiles exist yet, fall back — cloud → model, local → LLM-profile (cloud
- * has no home LLM-profile activate path).
- * - In an ACP conversation (local or cloud): the model picker — ACP owns its
- * LLM via the subprocess/session, so the picker just live-switches the
- * session model (set_session_model / cloud's switch_acp_model proxy).
- * - In an OpenHands conversation (local or cloud): the LLM-profile picker,
- * which live-switches the running conversation's LLM profile via
- * /switch_profile — a real endpoint on both backends (cloud proxies
- * POST /api/v1/app-conversations/{id}/switch_profile, unchanged since
- * OpenHands#14288). There is no cloud-specific restriction here.
- */
export function resolvePickerKind({
hasConversation,
+ hasStartedConversation = hasConversation,
isCloud,
isAcp,
profilesAvailable,
}: ResolvePickerKindInput): PickerKind {
- if (!hasConversation) {
+ if (!hasConversation || !hasStartedConversation) {
if (profilesAvailable) return "agent-profile";
return isCloud ? "model" : "llm-profile";
}
diff --git a/src/components/features/chat/custom-chat-input.tsx b/src/components/features/chat/custom-chat-input.tsx
index 5ec0da8afa..682daac488 100644
--- a/src/components/features/chat/custom-chat-input.tsx
+++ b/src/components/features/chat/custom-chat-input.tsx
@@ -14,6 +14,7 @@ import { cn } from "#/utils/utils";
export interface CustomChatInputProps {
disabled?: boolean;
isNewConversationPending?: boolean;
+ hasStartedConversation?: boolean;
showButton?: boolean;
onSubmit: (message: string) => void;
onFocus?: () => void;
@@ -29,6 +30,7 @@ export interface CustomChatInputProps {
export function CustomChatInput({
disabled = false,
isNewConversationPending = false,
+ hasStartedConversation,
showButton = true,
onSubmit,
onFocus,
@@ -184,6 +186,7 @@ export function CustomChatInput({
isDragOver={isDragOver}
disabled={isDisabled}
canSubmit={canSubmit}
+ hasStartedConversation={hasStartedConversation}
isNewConversationPending={isNewConversationPending}
showButton={showButton}
buttonClassName={buttonClassName}
diff --git a/src/components/features/chat/interactive-chat-box.tsx b/src/components/features/chat/interactive-chat-box.tsx
index b5fa7eb550..bc411162ea 100644
--- a/src/components/features/chat/interactive-chat-box.tsx
+++ b/src/components/features/chat/interactive-chat-box.tsx
@@ -16,11 +16,13 @@ import { isTaskPolling } from "#/utils/utils";
interface InteractiveChatBoxProps {
onSubmit: (message: string, images: File[], files: File[]) => void;
disabled?: boolean;
+ hasStartedConversation?: boolean;
}
export function InteractiveChatBox({
onSubmit,
disabled = false,
+ hasStartedConversation,
}: InteractiveChatBoxProps) {
const {
images,
@@ -67,6 +69,7 @@ export function InteractiveChatBox({
<CustomChatInput
disabled={isDisabled}
isNewConversationPending={disabled}
+ hasStartedConversation={hasStartedConversation}
onSubmit={handleSubmit}
onFilesPaste={handleUpload}
/>
diff --git a/src/hooks/mutation/use-create-conversation.ts b/src/hooks/mutation/use-create-conversation.ts
index 2112b2f55c..7632e4d37b 100644
--- a/src/hooks/mutation/use-create-conversation.ts
+++ b/src/hooks/mutation/use-create-conversation.ts
@@ -25,10 +25,11 @@ import { pluginReferenceKey } from "#/utils/plugin-display";
import {
getStoredConversationMetadata,
setStoredConversationMetadata,
+ toPluginCoordinates,
type WorkspaceMode,
} from "#/api/conversation-metadata-store";
-interface CreateConversationVariables {
+export interface CreateConversationVariables {
query?: string;
repository?: {
name: string;
@@ -49,6 +50,8 @@ interface CreateConversationVariables {
entryPoint?: string; // analytics only; not forwarded to the service
}
+export const CREATE_CONVERSATION_MUTATION_KEY = ["create-conversation"];
+
interface CreateConversationResponse {
conversation_id: string;
session_api_key: string | null;
@@ -73,7 +76,7 @@ export const useCreateConversation = () => {
useAgentProfiles();
return useMutation({
- mutationKey: ["create-conversation"],
+ mutationKey: CREATE_CONVERSATION_MUTATION_KEY,
mutationFn: async (
variables: CreateConversationVariables,
): Promise<CreateConversationResponse> => {
@@ -238,12 +241,7 @@ export const useCreateConversation = () => {
// 1. plugins explicitly attached at creation (e.g. the /launch flow);
// 2. enabled installed plugins, which the SDK auto-loads into every new
// local conversation (see use-set-plugin-enabled).
- const explicitPlugins =
- plugins?.map((plugin) => ({
- source: plugin.source,
- ref: plugin.ref ?? null,
- repo_path: plugin.repo_path ?? null,
- })) ?? [];
+ const explicitPlugins = plugins?.map(toPluginCoordinates) ?? [];
let attachedPlugins: PluginSpec[] = explicitPlugins;
if (localConversationId) {
let installed: InstalledPluginInfo[] = [];
diff --git a/src/hooks/query/use-task-polling.ts b/src/hooks/query/use-task-polling.ts
index 15c5099963..8d0e92e14f 100644
--- a/src/hooks/query/use-task-polling.ts
+++ b/src/hooks/query/use-task-polling.ts
@@ -1,6 +1,12 @@
import { useEffect, useLayoutEffect, useRef } from "react";
import { useQuery } from "@tanstack/react-query";
import AgentServerConversationService from "#/api/conversation-service/agent-server-conversation-service.api";
+import type { AppConversationStartTask } from "#/api/conversation-service/agent-server-conversation-service.types";
+import {
+ getStoredConversationMetadata,
+ setStoredConversationMetadata,
+ toPluginCoordinates,
+} from "#/api/conversation-metadata-store";
import { useNavigation } from "#/context/navigation-context";
import { useOptionalConversationId } from "#/hooks/use-conversation-id";
import {
@@ -16,6 +22,25 @@ import {
schedulePendingTaskMessageReassign,
} from "#/utils/pending-task-message-link";
+const storeTaskPlugins = (
+ task: AppConversationStartTask,
+ conversationId: string,
+) => {
+ const plugins = task.request.plugins?.map(toPluginCoordinates);
+ if (!plugins?.length) return;
+
+ const metadata = getStoredConversationMetadata(conversationId);
+ setStoredConversationMetadata(conversationId, {
+ ...metadata,
+ selected_repository:
+ metadata?.selected_repository ?? task.request.selected_repository ?? null,
+ selected_branch:
+ metadata?.selected_branch ?? task.request.selected_branch ?? null,
+ git_provider: metadata?.git_provider ?? task.request.git_provider ?? null,
+ plugins,
+ });
+};
+
/**
* Hook that polls V1 conversation start tasks and navigates when ready.
*
@@ -92,35 +117,34 @@ export const useTaskPolling = () => {
// Navigate to conversation ID when task is ready
useEffect(() => {
const task = taskQuery.data;
+ const appConversationId = task?.app_conversation_id;
if (
!taskId ||
task?.status !== "READY" ||
- !task.app_conversation_id ||
+ !appConversationId ||
handledReadyTaskIdRef.current === taskId
) {
return;
}
handledReadyTaskIdRef.current = taskId;
+ storeTaskPlugins(task, appConversationId);
void (async () => {
- await flushPendingTaskAttachments(taskId, task.app_conversation_id!);
+ await flushPendingTaskAttachments(taskId, appConversationId);
const taskConversationId = `task-${taskId}`;
- linkPendingTaskMessages(task.app_conversation_id!, taskConversationId);
- schedulePendingTaskMessageReassign(
- taskConversationId,
- task.app_conversation_id!,
- );
+ linkPendingTaskMessages(appConversationId, taskConversationId);
+ schedulePendingTaskMessageReassign(taskConversationId, appConversationId);
const pendingDraft = consumePendingTaskDraft(taskId);
if (pendingDraft) {
- setConversationState(task.app_conversation_id!, {
+ setConversationState(appConversationId, {
draftMessage: pendingDraft,
});
}
- navigate(`/conversations/${task.app_conversation_id}`, { replace: true });
+ navigate(`/conversations/${appConversationId}`, { replace: true });
})();
}, [taskQuery.data, navigate, taskId]);
diff --git a/src/hooks/use-chat-input-profile-state.ts b/src/hooks/use-chat-input-profile-state.ts
index a77f49d494..57b3cbb883 100644
--- a/src/hooks/use-chat-input-profile-state.ts
+++ b/src/hooks/use-chat-input-profile-state.ts
@@ -1,7 +1,15 @@
import { useCallback } from "react";
import { useIsMutating } from "@tanstack/react-query";
import type { AgentProfileSummary } from "#/api/agent-profiles-service/agent-profiles-service.api";
+import { getStoredConversationMetadata } from "#/api/conversation-metadata-store";
+import { useNavigation } from "#/context/navigation-context";
import { useAgentProfiles } from "#/hooks/query/use-agent-profiles";
+import { useActiveConversation } from "#/hooks/query/use-active-conversation";
+import {
+ CREATE_CONVERSATION_MUTATION_KEY,
+ useCreateConversation,
+ type CreateConversationVariables,
+} from "#/hooks/mutation/use-create-conversation";
import {
useActivateAgentProfile,
ACTIVATE_AGENT_PROFILE_MUTATION_KEY,
@@ -9,51 +17,98 @@ import {
export interface ChatInputProfileState {
profiles: AgentProfileSummary[];
- /** id of the active profile the next conversation will launch from. */
currentProfileId: string | null;
currentProfileName: string | null;
+ isInConversation: boolean;
isLoading: boolean;
isSwitching: boolean;
- /** Activate a profile so the next conversation launches from it. */
selectProfile: (profile: AgentProfileSummary) => void;
}
-/**
- * Backs the home chat-input AgentProfile picker. This picker is only rendered
- * on the home screen — inside a conversation the chat input shows the
- * in-conversation LLM-profile picker (OpenHands) or model picker (ACP) instead
- * (see `chat-input-actions.tsx` `pickerKind`). So selecting a profile here
- * simply activates it as the launch default; `useCreateConversation` reads the
- * active profile when the next conversation starts.
- */
export function useChatInputProfileState(): ChatInputProfileState {
- const { data: agentProfiles, isLoading } = useAgentProfiles();
+ const { conversationId, navigate } = useNavigation();
+ const { data: conversation, isLoading: isLoadingConversation } =
+ useActiveConversation();
+ const { data: agentProfiles, isLoading: isLoadingProfiles } =
+ useAgentProfiles();
+ const createConversation = useCreateConversation();
const activateProfile = useActivateAgentProfile();
- // Observe the activation globally by mutation key so the picker button (a
- // separate hook instance from the menu that fires it) disables correctly
- // while a switch is in flight (#1571).
+ const activatingProfiles = useIsMutating({
+ mutationKey: ACTIVATE_AGENT_PROFILE_MUTATION_KEY,
+ });
+ const creatingConversations = useIsMutating({
+ mutationKey: CREATE_CONVERSATION_MUTATION_KEY,
+ });
+ const isTaskRoute = conversationId?.startsWith("task-") ?? false;
const isSwitching =
- useIsMutating({ mutationKey: ACTIVATE_AGENT_PROFILE_MUTATION_KEY }) > 0;
+ isTaskRoute || activatingProfiles > 0 || creatingConversations > 0;
const profiles = agentProfiles?.profiles ?? [];
- const currentProfileId = agentProfiles?.active_agent_profile_id ?? null;
+ const isInConversation = Boolean(conversationId);
+ const currentProfileId = isInConversation
+ ? (conversation?.launched_agent_profile?.agent_profile_id ??
+ agentProfiles?.active_agent_profile_id ??
+ null)
+ : (agentProfiles?.active_agent_profile_id ?? null);
const currentProfileName =
profiles.find((p) => p.id != null && p.id === currentProfileId)?.name ??
null;
const selectProfile = useCallback(
(profile: AgentProfileSummary) => {
- if (!profile.id || profile.id === currentProfileId) return;
- activateProfile.mutate(profile.id);
+ if (isTaskRoute || !profile.id || profile.id === currentProfileId) return;
+ if (!isInConversation) {
+ activateProfile.mutate(profile.id);
+ return;
+ }
+
+ const metadata = conversationId
+ ? getStoredConversationMetadata(conversationId)
+ : null;
+ const variables: CreateConversationVariables = {
+ agentProfileId: profile.id,
+ entryPoint: "blank_conversation_profile_picker",
+ };
+ if (conversation?.selected_repository) {
+ variables.repository = {
+ name: conversation.selected_repository,
+ gitProvider: conversation.git_provider ?? "github",
+ branch: conversation.selected_branch ?? undefined,
+ };
+ }
+ if (conversation?.selected_workspace) {
+ variables.workingDir = conversation.selected_workspace;
+ variables.workspaceMode = metadata?.workspace_mode ?? "local_repo";
+ }
+ if (metadata?.plugins?.length) {
+ variables.plugins = metadata.plugins;
+ }
+
+ createConversation.mutate(variables, {
+ onSuccess: (data) => navigate(`/conversations/${data.conversation_id}`),
+ });
},
- [currentProfileId, activateProfile],
+ [
+ activateProfile,
+ conversation,
+ conversationId,
+ createConversation,
+ currentProfileId,
+ isInConversation,
+ isTaskRoute,
+ navigate,
+ ],
);
return {
profiles,
currentProfileId,
currentProfileName,
- isLoading,
+ isInConversation,
+ isLoading:
+ isLoadingProfiles ||
+ isTaskRoute ||
+ (isInConversation && isLoadingConversation),
isSwitching,
selectProfile,
};
diff --git a/src/i18n/translation.json b/src/i18n/translation.json
index 55796b61dd..8bb1dbefd8 100644
--- a/src/i18n/translation.json
+++ b/src/i18n/translation.json
@@ -2396,6 +2396,23 @@
"uk": "Керувати профілями агента",
"ca": "Gestiona els perfils d'agent"
},
+ "CHAT$START_NEW_WITH_PROFILE_HINT": {
+ "en": "Selecting starts a new conversation",
+ "ja": "選択すると新しい会話が始まります",
+ "zh-CN": "选择后将开始新对话",
+ "zh-TW": "選擇後將開始新對話",
+ "ko-KR": "선택하면 새 대화가 시작됩니다",
+ "no": "Å velge starter en ny samtale",
+ "it": "La selezione avvia una nuova conversazione",
+ "pt": "Selecionar inicia uma nova conversa",
+ "es": "Seleccionar inicia una nueva conversación",
+ "ar": "يؤدي التحديد إلى بدء محادثة جديدة",
+ "fr": "La sélection démarre une nouvelle conversation",
+ "tr": "Seçim yeni bir sohbet başlatır",
+ "de": "Die Auswahl startet eine neue Unterhaltung",
+ "uk": "Вибір розпочинає нову розмову",
+ "ca": "Seleccionar inicia una nova conversa"
+ },
"SETTINGS$ENABLE_MEMORY_CONDENSATION": {
"en": "Enable memory condensation",
"ja": "メモリ凝縮を有効にする",