π OpenHands: AI-Driven Development
feat(secrets): ask for requested secrets inline in the chat (#18575)
Vasco Schiavo045290739f0a
diff --git a/.agents/skills/verify-openhands/references/feature-map/F14-secrets.md b/.agents/skills/verify-openhands/references/feature-map/F14-secrets.mdindex b63e379aca..0d851600ee 100644--- a/.agents/skills/verify-openhands/references/feature-map/F14-secrets.md+++ b/.agents/skills/verify-openhands/references/feature-map/F14-secrets.md@@ -4,7 +4,7 @@ Secrets are named values the agent can use during conversations. A user lists,adds, edits and deletes them under Settings β Secrets; saved values are nevershown again, and every new conversation receives them as environment variables.-Source: `src/routes/secrets-settings.tsx`, `src/components/features/settings/secrets-settings/`, `src/api/secrets-service.ts`, `src/components/features/conversation/secret-request-modal.tsx`, `src/services/secret-request.ts`, `src/stores/secret-request-store.ts`, `src/constants/secret-request.ts`, `src/api/request-secret-client-tool.ts`.+Source: `src/routes/secrets-settings.tsx`, `src/components/features/settings/secrets-settings/`, `src/api/secrets-service.ts`, `src/components/features/conversation/secret-request-card.tsx`, `src/services/secret-request.ts`, `src/stores/secret-request-store.ts`, `src/constants/secret-request.ts`, `src/api/request-secret-client-tool.ts`.## Sub-features@@ -19,14 +19,14 @@ Source: `src/routes/secrets-settings.tsx`, `src/components/features/settings/sec- `F14.rename`: the Edit form's name is editable; renaming with the value left blank keeps the stored value under the new name, and renaming onto an existing name is refused with `Secret already exists`.- `F14.edit-value`: typing a value in the Edit form (labelled "Secret Value (leave blank to preserve the existing value)") replaces the stored value for new conversations.- `F14.delete-escape`: Escape closes the delete confirmation without deleting.-- `F14.agent-request`: in a local conversation the agent's `request_secret` tool opens **The agent needs a secret** over the chat with its reason and the name prefilled; Add secret saves it, attaches it to the running conversation and reports `saved` to the agent, Cancel reports `not_saved`, and a name that is already saved is attached without a dialog. The value never reaches the agent's events.+- `F14.agent-request`: in a local conversation the agent's `request_secret` tool adds a **The agent needs a secret** card in the chat, right after the tool call, with its reason and the name prefilled; it does not block the conversation, so the agent can keep working and the user answers when ready. Add secret saves it, attaches it to the running conversation and reports `saved` to the agent, Cancel reports `not_saved`, and a name that is already saved is attached without a card. The value never reaches the agent's events.## How to get to it (user POV)- Sidebar settings gear (`backend-selector-settings-link`), then **Secrets** in the settings navigation (`sidebar-settings-/settings/secrets`).- Direct URL `/settings/secrets`.- Command menu (`Control+k` or `Meta+k`, or `command-menu-trigger` in the sidebar): search "Secrets", choose **Secrets settings**.-- The agent itself, in a conversation: its `request_secret` client tool opens the request dialog (`testid=secret-request-modal`) on `/conversations/<id>` (`F14.agent-request`).+- The agent itself, in a conversation: its `request_secret` client tool adds the request card (`testid=secret-request-card`) to the chat on `/conversations/<id>` (`F14.agent-request`).## Driving it with control-openhands@@ -50,19 +50,18 @@ Preconditions:- **Back discards the draft (`F14.form-back`).** On `/settings/secrets` run `control-openhands browser click 'testid=add-secret-button'` and `control-openhands browser text 'testid=secret-editor-title'` (`Add a Secret`). Fill `testid=add-secret-form >> testid=name-input` with `QA_BACK_SECRET` and `value-input` with `dummy`, then `control-openhands browser click 'testid=back-to-secrets'`. `control-openhands browser count 'testid=add-secret-form'` is `0`, the list is back (`browser count 'testid=secret-item'` > `0`) and `control-openhands api GET /api/settings/secrets` lists no `QA_BACK_SECRET`. Reopening Add shows an empty `name-input` (`browser value`); leave with `testid=back-to-secrets`. The Edit form shows `Edit a Secret` in the same `secret-editor-title`.- **Rename keeps the value (`F14.rename`).** Needs `QA_AGENT_SECRET` from Agent receives the secret. Run `control-openhands browser goto /settings/secrets`, `control-openhands browser click 'testid=secret-item >> has-text=QA_AGENT_SECRET >> testid=edit-secret-button'`, fill `testid=edit-secret-form >> testid=name-input` with `OPENHANDS_AUTOMATION_API_KEY` and click `testid=edit-secret-form >> testid=submit-button`: `control-openhands browser snapshot 'testid=edit-secret-form'` shows the paragraph `Secret already exists` and the form stays open. Fill `name-input` with `QA_RENAMED_SECRET` (value left blank), click submit, `control-openhands browser reload`; `browser count 'testid=secret-item >> has-text=QA_RENAMED_SECRET'` is `1`, the `QA_AGENT_SECRET` count is `0`, and `api GET /api/settings/secrets` lists only the new name. Then run `control-openhands conversation start --prompt "Run exactly this command and reply with only its output: python3 -c \"import os; print(os.environ.get('QA_RENAMED_SECRET') == 'qa-dummy-4821', 'QA_AGENT_SECRET' in os.environ)\"" --wait --timeout 240` and `control-openhands conversation events <id> --kinds ObservationEvent`: the observation is `True False`.- **Replace the value (`F14.edit-value`).** Run `control-openhands browser goto /settings/secrets`, `control-openhands browser click 'testid=secret-item >> has-text=QA_RENAMED_SECRET >> testid=edit-secret-button'` and `control-openhands browser snapshot 'testid=edit-secret-form'` (the value textbox is named `Secret Value (leave blank to preserve the existing value)`). Fill `testid=edit-secret-form >> testid=value-input` with `qa-dummy-7350`; `browser enabled 'testid=edit-secret-form >> testid=submit-button'` is `true`. Click submit; `browser count 'testid=edit-secret-form'` is `0`. Start a conversation with the prompt `Run exactly this command and reply with only its output: python3 -c "import os; print(os.environ.get('QA_RENAMED_SECRET') == 'qa-dummy-7350')"` (quoted as above) and read its `ObservationEvent`: `True`.-- **Agent requests a secret (`F14.agent-request`).** Run `control-openhands browser goto /`, then `control-openhands conversation start --prompt "Call the request_secret tool with name QA_REQ_SECRET and reason 'QA check: a dummy token for verification.' Do not run any other tools. After calling it, end your turn and wait." --wait --timeout 240` (prints `<req-id>`; it leaves the browser on the conversation). `control-openhands conversation events <req-id> --kinds ActionEvent,ObservationEvent` shows the `request_secret` action and the observation `Tool call dispatched to client.`; `control-openhands browser snapshot 'role=dialog'` reads `dialog "The agent needs a secret"`, the reason `QA check: a dummy token for verification.`, textbox `Name` holding `QA_REQ_SECRET`, `Value`, `Description Optional`, `Cancel` and `Add secret [disabled]` (`browser screenshot --feature F14.agent-request --name modal`). Focus starts in `name-input` and Tab cycles Name, Value, Description and Cancel without leaving the dialog (`control-openhands browser eval "document.activeElement.dataset.testid"` after each `browser press Tab`). `control-openhands browser press Escape` and `control-openhands browser mouse-click 30 500` leave it open (`browser count 'testid=secret-request-modal'` stays `1`), and so does `control-openhands browser reload`, with the name still prefilled. Run `control-openhands browser fill 'testid=secret-request-modal >> testid=value-input' qa-dummy-5190` and `control-openhands browser click 'testid=secret-request-modal >> testid=submit-button'`: the dialog closes, `control-openhands api GET /api/settings/secrets` lists `QA_REQ_SECRET`, and after `control-openhands conversation wait <req-id> --fresh --timeout 180` `control-openhands conversation events <req-id> --kinds MessageEvent` holds the user message `[secret-request] {"status":"saved","name":"QA_REQ_SECRET"}`, which the chat does not show (`browser count 'text=[secret-request]'` is `0`). The running conversation now has the value: `control-openhands conversation send <req-id> --prompt "Run exactly this command and reply with only its output: python3 -c \"import os; print(os.environ.get('QA_REQ_SECRET') == 'qa-dummy-5190')\"" --wait --timeout 240`, then the last terminal `ObservationEvent` is `True`. Cancel: `browser goto /`, start a second conversation with the same prompt naming `QA_REQ_CANCEL` and reason `QA cancel check.`, fill `value-input` with `should-not-save` and `control-openhands browser click 'testid=secret-request-modal >> testid=cancel-button'`: the dialog closes, `api GET /api/settings/secrets` lists no `QA_REQ_CANCEL`, the agent receives `[secret-request] {"status":"not_saved","name":"QA_REQ_CANCEL","guidance":...}`, and a reload does not bring the dialog back. Already saved: a third conversation asking for `QA_REQ_SECRET` again shows no dialog (`browser count 'testid=secret-request-modal'` `0`) and its events hold `[secret-request] {"status":"saved","name":"QA_REQ_SECRET"}`. Expected: at phone width the dialog fits the viewport (at most 90vw, 351 px at 390 px, `insideViewport` `true`) with the title, every field and both buttons visible. Known failure (reproduced 2026-10-14, #18432): at 390Γ844 `browser bbox 'testid=secret-request-modal'` is 520 px wide at x -65, `insideViewport` `false`, so the title, the field labels and Cancel are cut off on the left (and 65 px on the right); run the block below. Return with `browser viewport desktop`. `QA_REQ_SECRET` is deleted in the cleanup below.+- **Agent requests a secret (`F14.agent-request`).** Run `control-openhands browser goto /`, then `control-openhands conversation start --prompt "Call the request_secret tool with name QA_REQ_SECRET and reason 'QA check: a dummy token for verification.' Do not run any other tools. After calling it, end your turn and wait." --wait --timeout 240` (prints `<req-id>`; it leaves the browser on the conversation). `control-openhands conversation events <req-id> --kinds ActionEvent,ObservationEvent` shows the `request_secret` action and the observation `Tool call dispatched to client.`; `control-openhands browser snapshot 'testid=secret-request-card'` reads `region "The agent needs a secret"`, the reason `QA check: a dummy token for verification.`, textbox `Name` holding `QA_REQ_SECRET`, `Value`, `Description Optional`, `Cancel` and `Add secret [disabled]` (`browser screenshot --feature F14.agent-request --name card`). The chat input stays usable while the card is pending, and `control-openhands browser reload` keeps the card with the name still prefilled. Run `control-openhands browser fill 'testid=secret-request-card >> testid=value-input' qa-dummy-5190` and `control-openhands browser click 'testid=secret-request-card >> testid=submit-button'`: the card disappears, `control-openhands api GET /api/settings/secrets` lists `QA_REQ_SECRET`, and after `control-openhands conversation wait <req-id> --fresh --timeout 180` `control-openhands conversation events <req-id> --kinds MessageEvent` holds the user message `[secret-request] {"status":"saved","name":"QA_REQ_SECRET"}`, which the chat does not show (`browser count 'text=[secret-request]'` is `0`). The running conversation now has the value: `control-openhands conversation send <req-id> --prompt "Run exactly this command and reply with only its output: python3 -c \"import os; print(os.environ.get('QA_REQ_SECRET') == 'qa-dummy-5190')\"" --wait --timeout 240`, then the last terminal `ObservationEvent` is `True`. Cancel: `browser goto /`, start a second conversation with the same prompt naming `QA_REQ_CANCEL` and reason `QA cancel check.`, fill `value-input` with `should-not-save` and `control-openhands browser click 'testid=secret-request-card >> testid=cancel-button'`: the card disappears, `api GET /api/settings/secrets` lists no `QA_REQ_CANCEL`, the agent receives `[secret-request] {"status":"not_saved","name":"QA_REQ_CANCEL","guidance":...}`, and a reload does not bring the card back. Already saved: a third conversation asking for `QA_REQ_SECRET` again shows no card (`browser count 'testid=secret-request-card'` `0`) and its events hold `[secret-request] {"status":"saved","name":"QA_REQ_SECRET"}`. Expected: at phone width the card fits the chat column (`insideViewport` `true`) with the title, every field and both buttons visible; run the block below. Return with `browser viewport desktop`. `QA_REQ_SECRET` is deleted in the cleanup below.- ```sh known-bug F14.agent-request phone-width+ ```shcontrol-openhands browser viewport desktopcontrol-openhands browser goto /control-openhands conversation start --prompt "Call the request_secret tool with name QA_REQ_PHONE and reason 'QA phone check.' Do not run any other tools. After calling it, end your turn and wait." --wait --timeout 240- control-openhands browser wait 'testid=secret-request-modal'- control-openhands assert --field insideViewport --equals true -- browser bbox 'testid=secret-request-modal'+ control-openhands browser wait 'testid=secret-request-card'control-openhands browser viewport phonecontrol-openhands browser screenshot --feature F14.agent-request --name phone-width- control-openhands assert --field insideViewport --equals true --bug 'insideViewport eq false && box.width eq 520' -- browser bbox 'testid=secret-request-modal' # bug- control-openhands browser click 'testid=secret-request-modal >> role=button[name="Cancel"]'- control-openhands browser wait 'testid=secret-request-modal' --state detached+ control-openhands assert --field insideViewport --equals true -- browser bbox 'testid=secret-request-card'+ control-openhands browser click 'testid=secret-request-card >> role=button[name="Cancel"]'+ control-openhands browser wait 'testid=secret-request-card' --state detached```- **Escape cancels delete (`F14.delete-escape`).** Run `control-openhands browser goto /settings/secrets`, `control-openhands browser click 'testid=secret-item >> has-text=QA_RENAMED_SECRET >> testid=delete-secret-button'`, `control-openhands browser press Escape`, then `control-openhands browser count 'testid=confirmation-modal'` (`0`) and `browser count 'testid=secret-item >> has-text=QA_RENAMED_SECRET'` (`1`). Clean up: delete `QA_RENAMED_SECRET` and then `QA_REQ_SECRET` (from `F14.agent-request`), each with `delete-secret-button` β `testid=confirmation-modal >> testid=confirm-button`, `browser reload`; `api GET /api/settings/secrets` lists only `OPENHANDS_AUTOMATION_API_KEY`.diff --git a/.pr/secret-request-card-desktop.png b/.pr/secret-request-card-desktop.pngnew file mode 100644index 0000000000..373b53eb80Binary files /dev/null and b/.pr/secret-request-card-desktop.png differdiff --git a/.pr/secret-request-card-phone.png b/.pr/secret-request-card-phone.pngnew file mode 100644index 0000000000..b36cdd5386Binary files /dev/null and b/.pr/secret-request-card-phone.png differdiff --git a/__tests__/components/conversation-events/chat/messages-secret-request.test.tsx b/__tests__/components/conversation-events/chat/messages-secret-request.test.tsxnew file mode 100644index 0000000000..70a0a7b6e7--- /dev/null+++ b/__tests__/components/conversation-events/chat/messages-secret-request.test.tsx@@ -0,0 +1,114 @@+import { screen } from "@testing-library/react";+import { beforeEach, describe, expect, it, vi } from "vitest";+import { renderWithProviders } from "test-utils";+import { SecretsService } from "#/api/secrets-service";+import { Messages } from "#/components/conversation-events/chat/messages";+import {+ type SecretRequest,+ useSecretRequestStore,+} from "#/stores/secret-request-store";+import {+ ActionEvent,+ MessageEvent,+ SecurityRisk,+} from "#/types/agent-server/core";+import { ExecuteBashAction } from "#/types/agent-server/core/base/action";++const CONVERSATION_ID = "test-conversation-id";++const makeBashAction = (id: string): ActionEvent<ExecuteBashAction> => ({+ id,+ timestamp: new Date().toISOString(),+ source: "agent",+ thought: [],+ thinking_blocks: [],+ action: {+ kind: "ExecuteBashAction",+ command: `echo ${id}`,+ is_input: false,+ timeout: null,+ reset: false,+ },+ tool_name: "execute_bash",+ tool_call_id: `call_${id}`,+ tool_call: {+ id: `call_${id}`,+ type: "function",+ function: {+ name: "execute_bash",+ arguments: JSON.stringify({ command: `echo ${id}` }),+ },+ },+ llm_response_id: `response_${id}`,+ security_risk: SecurityRisk.UNKNOWN,+});++const agentMessage: MessageEvent = {+ id: "agent-msg-1",+ timestamp: new Date().toISOString(),+ source: "agent",+ llm_message: {+ role: "assistant",+ content: [{ type: "text", text: "Meanwhile, I ran the tests." }],+ },+ activated_skills: [],+ extended_content: [],+};++const makeRequest = (toolCallId: string, name: string): SecretRequest => ({+ conversationId: CONVERSATION_ID,+ toolCallId,+ name,+ reason: null,+});++const cardNames = () =>+ screen+ .getAllByTestId("secret-request-card")+ .map((card) => card.querySelector("input")?.value);++describe("Messages secret requests", () => {+ beforeEach(() => {+ vi.spyOn(SecretsService, "getSecrets").mockResolvedValue([]);+ });++ it("shows a pending request right after its tool call, above later messages", () => {+ const action = makeBashAction("action-1");+ useSecretRequestStore.setState({+ requests: [makeRequest(action.tool_call_id, "GITHUB_TOKEN")],+ });++ renderWithProviders(+ <Messages+ messages={[action, agentMessage]}+ allEvents={[action, agentMessage]}+ />,+ );++ const card = screen.getByTestId("secret-request-card");+ const laterMessage = screen.getByText("Meanwhile, I ran the tests.");+ expect(+ card.compareDocumentPosition(laterMessage) &+ Node.DOCUMENT_POSITION_FOLLOWING,+ ).toBeTruthy();+ });++ it("falls back to the end of the chat when the tool call is not loaded", () => {+ const action = makeBashAction("action-1");+ useSecretRequestStore.setState({+ requests: [+ makeRequest("call_unknown", "NPM_TOKEN"),+ makeRequest(action.tool_call_id, "GITHUB_TOKEN"),+ ],+ });++ renderWithProviders(+ <Messages+ messages={[action, agentMessage]}+ allEvents={[action, agentMessage]}+ />,+ );++ expect(cardNames()).toEqual(["GITHUB_TOKEN", "NPM_TOKEN"]);+ });+});diff --git a/__tests__/components/features/conversation/secret-request-modal.test.tsx b/__tests__/components/features/conversation/secret-request-card.test.tsxsimilarity index 71%rename from __tests__/components/features/conversation/secret-request-modal.test.tsxrename to __tests__/components/features/conversation/secret-request-card.test.tsxindex e9e2bda131..650aee576e 100644--- a/__tests__/components/features/conversation/secret-request-modal.test.tsx+++ b/__tests__/components/features/conversation/secret-request-card.test.tsx@@ -2,7 +2,10 @@ import { screen, waitFor } from "@testing-library/react";import userEvent from "@testing-library/user-event";import { beforeEach, describe, expect, it, vi } from "vitest";import { SecretsService } from "#/api/secrets-service";-import { SecretRequestModal } from "#/components/features/conversation/secret-request-modal";+import {+ SecretRequestCard,+ usePendingSecretRequests,+} from "#/components/features/conversation/secret-request-card";import {type SecretRequest,useSecretRequestStore,@@ -25,15 +28,21 @@ const request: SecretRequest = {reason: "Push the factory branch; needs repo scope.",};-const renderModal = async (requests: SecretRequest[] = [request]) => {+function PendingSecretRequestCards() {+ return usePendingSecretRequests().map((r) => (+ <SecretRequestCard key={r.toolCallId} request={r} />+ ));+}++const renderCards = async (requests: SecretRequest[] = [request]) => {useSecretRequestStore.setState({ requests });- renderWithProviders(<SecretRequestModal />);+ renderWithProviders(<PendingSecretRequestCards />);if (requests.some((r) => r.conversationId === request.conversationId)) {- await screen.findByTestId("secret-request-modal");+ await screen.findAllByTestId("secret-request-card");}};-describe("SecretRequestModal", () => {+describe("SecretRequestCard", () => {beforeEach(() => {vi.restoreAllMocks();// Like the real service, completing a request removes it from the queue.@@ -46,19 +55,29 @@ describe("SecretRequestModal", () => {});it("asks for the requested secret with the agent's reason", async () => {- await renderModal();+ await renderCards();expect(screen.getByText(request.reason!)).toBeInTheDocument();expect(screen.getByTestId("name-input")).toHaveValue("GITHUB_TOKEN");expect(screen.getByTestId("value-input")).toHaveValue("");});+ it("shows one card per pending request", async () => {+ await renderCards([+ request,+ { ...request, toolCallId: "tool-call-2", name: "NPM_TOKEN" },+ ]);++ const names = screen+ .getAllByTestId("name-input")+ .map((input) => (input as HTMLInputElement).value);+ expect(names).toEqual(["GITHUB_TOKEN", "NPM_TOKEN"]);+ });+it("ignores requests from other conversations", async () => {- await renderModal([{ ...request, conversationId: "other-conversation" }]);+ await renderCards([{ ...request, conversationId: "other-conversation" }]);- expect(- screen.queryByTestId("secret-request-modal"),- ).not.toBeInTheDocument();+ expect(screen.queryByTestId("secret-request-card")).not.toBeInTheDocument();});it("saves the value to the secrets store and completes with the secret's identity", async () => {@@ -66,14 +85,14 @@ describe("SecretRequestModal", () => {const createSecret = vi.spyOn(SecretsService, "createSecret").mockResolvedValue(undefined);- await renderModal();+ await renderCards();await user.type(screen.getByTestId("value-input"), "ghp_example");await user.click(screen.getByTestId("submit-button"));await waitFor(() =>expect(- screen.queryByTestId("secret-request-modal"),+ screen.queryByTestId("secret-request-card"),).not.toBeInTheDocument(),);// The form's later onCancel is a no-op for the real, already-completed@@ -89,12 +108,12 @@ describe("SecretRequestModal", () => {);});- it("stays open after a failed save so the user can retry or cancel", async () => {+ it("stays after a failed save so the user can retry or cancel", async () => {const user = userEvent.setup();vi.spyOn(SecretsService, "createSecret").mockRejectedValue(new Error("Save failed"),);- await renderModal();+ await renderCards();await user.type(screen.getByTestId("value-input"), "ghp_example");await user.click(screen.getByTestId("submit-button"));@@ -102,7 +121,7 @@ describe("SecretRequestModal", () => {await waitFor(() =>expect(screen.getByTestId("cancel-button")).toBeEnabled(),);- expect(screen.getByTestId("secret-request-modal")).toBeInTheDocument();+ expect(screen.getByTestId("secret-request-card")).toBeInTheDocument();expect(mockCompleteSecretRequest).not.toHaveBeenCalled();await user.click(screen.getByTestId("cancel-button"));diff --git a/__tests__/services/secret-request.test.ts b/__tests__/services/secret-request.test.tsindex 0aecf4a834..0cb37d7e5b 100644--- a/__tests__/services/secret-request.test.ts+++ b/__tests__/services/secret-request.test.ts@@ -86,7 +86,7 @@ beforeEach(() => {});describe("handleRequestSecretAction", () => {- it("queues one modal per tool call, ignoring replays", async () => {+ it("queues one request per tool call, ignoring replays", async () => {useSecretRequestStore.setState({ requests: [] });await handleRequestSecretAction(action, CONVERSATION_ID, "tool-call-1");await handleRequestSecretAction(action, CONVERSATION_ID, "tool-call-1");diff --git a/src/api/request-secret-client-tool.ts b/src/api/request-secret-client-tool.tsindex 1ae18f1f00..ed4002bad1 100644--- a/src/api/request-secret-client-tool.ts+++ b/src/api/request-secret-client-tool.ts@@ -4,7 +4,7 @@ import {} from "#/constants/secret-request";import type { ClientToolSpec } from "./canvas-ui-client-tool";-const REQUEST_SECRET_DESCRIPTION = `Ask the user to securely provide a secret you need (an API key, token, password or other credential) through a form shown over this conversation, without sending them to Settings.+const REQUEST_SECRET_DESCRIPTION = `Ask the user to securely provide a secret you need (an API key, token, password or other credential) through a form shown in this conversation, without sending them to Settings.Call this when a task needs a credential that is not among your availablesecrets β for example a GitHub token to push to a repository. Never ask the@@ -16,8 +16,10 @@ an environment variable named after the secret. Reference it as $NAME incommands; never print or echo it. One call per missing secret.What comes back: this tool is acknowledged immediately, before the user has-answered. End your turn after calling it and wait. The outcome arrives as a-follow-up message starting with "${SECRET_REQUEST_RESULT_PREFIX.trim()}". On "saved",+answered, and the user answers whenever they are ready. Keep working on+anything that does not need the secret, or end your turn if nothing is left;+do not wait in a loop or ask again. The outcome arrives as a follow-up message+starting with "${SECRET_REQUEST_RESULT_PREFIX.trim()}". On "saved",continue using the secret by the name it reports (the user may have renamedit). Otherwise, follow the guidance in the message; do not call this tool againunless the user asks you to.`;diff --git a/src/components/conversation-events/chat/messages.tsx b/src/components/conversation-events/chat/messages.tsxindex 91e85f391a..655dcdc1e6 100644--- a/src/components/conversation-events/chat/messages.tsx+++ b/src/components/conversation-events/chat/messages.tsx@@ -14,6 +14,11 @@ import { useModelStore } from "#/stores/model-store";import { ModelMessages } from "#/components/features/chat/model-messages";import { useOptionalConversationId } from "#/hooks/use-conversation-id";import { ConversationConfirmationButtons } from "#/components/shared/buttons/conversation-confirmation-buttons";+import type { SecretRequest } from "#/stores/secret-request-store";+import {+ SecretRequestCard,+ usePendingSecretRequests,+} from "#/components/features/conversation/secret-request-card";interface MessagesProps {messages: OpenHandsEvent[]; // UI events (actions replaced by observations)@@ -66,6 +71,31 @@ export const Messages: React.FC<MessagesProps> = React.memo();};+ // Pending `request_secret` forms sit right after their tool call, so what+ // the agent writes next lands below them. A call that is not loaded falls+ // back to the end of the chat.+ const pendingSecretRequests = usePendingSecretRequests();+ const secretRequests = React.useMemo(() => {+ const unanchored = new Map(+ pendingSecretRequests.map((request) => [request.toolCallId, request]),+ );+ const byAnchorId = new Map<string, SecretRequest>();+ for (const event of messages) {+ if (unanchored.size === 0) break;+ if (!isActionEvent(event) && !isObservationEvent(event)) continue;+ const request = unanchored.get(event.tool_call_id);+ if (!request) continue;+ unanchored.delete(event.tool_call_id);+ byAnchorId.set(event.id, request);+ }+ return { byAnchorId, unanchored: [...unanchored.values()] };+ }, [pendingSecretRequests, messages]);++ const maybeRenderSecretRequest = (eventId: string | undefined) => {+ const request = eventId && secretRequests.byAnchorId.get(eventId);+ return request ? <SecretRequestCard request={request} /> : null;+ };+// Fold consecutive action/observation events into collapsible groups so a// long sequence of tool calls doesn't dominate the chat scroll. Items that// can't be grouped (or that fall in a short run) are still rendered one by@@ -109,6 +139,7 @@ export const Messages: React.FC<MessagesProps> = React.memo(duplication. */}{renderEventMessage(item.event, item.index, true)}{maybeRenderModelMessages(item.event.id)}+ {maybeRenderSecretRequest(item.event.id)}</React.Fragment>);}@@ -142,11 +173,15 @@ export const Messages: React.FC<MessagesProps> = React.memo({item.events.map((event) => (<React.Fragment key={`model-${event.id}`}>{maybeRenderModelMessages(event.id)}+ {maybeRenderSecretRequest(event.id)}</React.Fragment>))}</React.Fragment>);})}+ {secretRequests.unanchored.map((request) => (+ <SecretRequestCard key={request.toolCallId} request={request} />+ ))}<ConversationConfirmationButtons /></>);diff --git a/src/components/features/conversation/secret-request-card.tsx b/src/components/features/conversation/secret-request-card.tsxnew file mode 100644index 0000000000..b495471f03--- /dev/null+++ b/src/components/features/conversation/secret-request-card.tsx@@ -0,0 +1,58 @@+import React from "react";+import { useTranslation } from "react-i18next";+import { SecretForm } from "#/components/features/settings/secrets-settings/secret-form";+import { useOptionalConversationId } from "#/hooks/use-conversation-id";+import { I18nKey } from "#/i18n/declaration";+import { completeSecretRequest } from "#/services/secret-request";+import {+ type SecretRequest,+ useSecretRequestStore,+} from "#/stores/secret-request-store";++/** The current conversation's pending secret requests, oldest first. */+export function usePendingSecretRequests(): SecretRequest[] {+ const { conversationId } = useOptionalConversationId();+ const requests = useSecretRequestStore((s) => s.requests);+ return React.useMemo(+ () => requests.filter((r) => r.conversationId === conversationId),+ [requests, conversationId],+ );+}++/**+ * Collects a secret the agent asked for with `request_secret`, as a card in+ * the chat. It does not block the conversation: the agent keeps working and+ * the user answers whenever they are ready. The value goes straight to the+ * secrets store; the agent only learns the outcome.+ */+export function SecretRequestCard({ request }: { request: SecretRequest }) {+ const { t } = useTranslation("openhands");++ return (+ <section+ data-testid="secret-request-card"+ aria-label={t(I18nKey.SECRETS$REQUEST_TITLE)}+ className="mt-4 flex flex-col gap-3 rounded-xl border border-border bg-surface p-4"+ >+ <div className="flex flex-col gap-1">+ <span className="text-sm font-medium text-contrast">+ {t(I18nKey.SECRETS$REQUEST_TITLE)}+ </span>+ {request.reason ? (+ <span className="text-sm text-muted">{request.reason}</span>+ ) : null}+ </div>+ {/* SecretForm also calls onCancel after a successful save; the request+ is already complete by then, so that call is a no-op. */}+ <SecretForm+ mode="add"+ selectedSecret={null}+ defaultName={request.name}+ keepOpenOnError+ valueRows={2}+ onSaved={(secret) => void completeSecretRequest(request, secret)}+ onCancel={() => void completeSecretRequest(request, null)}+ />+ </section>+ );+}diff --git a/src/components/features/conversation/secret-request-modal.tsx b/src/components/features/conversation/secret-request-modal.tsxdeleted file mode 100644index 31c674775d..0000000000--- a/src/components/features/conversation/secret-request-modal.tsx+++ /dev/null@@ -1,59 +0,0 @@-import { useTranslation } from "react-i18next";-import { SecretForm } from "#/components/features/settings/secrets-settings/secret-form";-import {- BaseModalDescription,- BaseModalTitle,-} from "#/components/shared/modals/confirmation-modals/base-modal";-import { ModalBackdrop } from "#/components/shared/modals/modal-backdrop";-import { ModalBody } from "#/components/shared/modals/modal-body";-import { useOptionalConversationId } from "#/hooks/use-conversation-id";-import { I18nKey } from "#/i18n/declaration";-import { completeSecretRequest } from "#/services/secret-request";-import { useSecretRequestStore } from "#/stores/secret-request-store";--/**- * Collects a secret the agent asked for with `request_secret`, over the- * current conversation. The value goes straight to the secrets store; the- * agent only learns the outcome.- */-export function SecretRequestModal() {- const { t } = useTranslation("openhands");- const { conversationId } = useOptionalConversationId();- const request = useSecretRequestStore((s) =>- s.requests.find((r) => r.conversationId === conversationId),- );-- if (!request) return null;-- const title = t(I18nKey.SECRETS$REQUEST_TITLE);-- return (- <ModalBackdrop- closeOnEscape={false}- closeOnBackdropClick={false}- aria-label={title}- >- <ModalBody testID="secret-request-modal" width="md">- <div className="flex flex-col gap-2 self-start">- <BaseModalTitle title={title} />- {request.reason ? (- <BaseModalDescription description={request.reason} />- ) : null}- </div>- <div className="w-full">- {/* SecretForm also calls onCancel after a successful save; the- request is already complete by then, so that call is a no-op. */}- <SecretForm- key={request.toolCallId}- mode="add"- selectedSecret={null}- defaultName={request.name}- keepOpenOnError- onSaved={(secret) => void completeSecretRequest(request, secret)}- onCancel={() => void completeSecretRequest(request, null)}- />- </div>- </ModalBody>- </ModalBackdrop>- );-}diff --git a/src/components/features/settings/secrets-settings/secret-form.tsx b/src/components/features/settings/secrets-settings/secret-form.tsxindex ded9c1724d..004ddafce0 100644--- a/src/components/features/settings/secrets-settings/secret-form.tsx+++ b/src/components/features/settings/secrets-settings/secret-form.tsx@@ -24,6 +24,8 @@ interface SecretFormProps {defaultName?: string;/** Keep the form open after a failed save so the user can retry. */keepOpenOnError?: boolean;+ /** Visible height of the value field, in lines. */+ valueRows?: number;}export function SecretForm({@@ -33,6 +35,7 @@ export function SecretForm({onSaved,defaultName = "",keepOpenOnError = false,+ valueRows = 8,}: SecretFormProps) {const queryClient = useQueryClient();const { t } = useTranslation("openhands");@@ -204,7 +207,7 @@ export function SecretForm({"placeholder:italic","disabled:bg-surface-raised disabled:border-border-subtle disabled:cursor-not-allowed",)}- rows={8}+ rows={valueRows}/></label>diff --git a/src/constants/secret-request.ts b/src/constants/secret-request.tsindex e1390df231..3f1b37b0a3 100644--- a/src/constants/secret-request.ts+++ b/src/constants/secret-request.ts@@ -9,8 +9,8 @@ export const REQUEST_SECRET_ACTION_KIND =`ClientAction_${REQUEST_SECRET_TOOL_NAME}` as const;/**- * Prefix of the message the frontend posts back once the user closes the- * secret request modal. Client tools are acknowledged before the user acts, so+ * Prefix of the message the frontend posts back once the user answers the+ * secret request card. Client tools are acknowledged before the user acts, so* this message is the only way to tell the agent whether the secret is now* available. It carries the outcome only, never the value, and the chat hides* it (see `should-render-event.ts`).diff --git a/src/contexts/conversation-websocket-context.tsx b/src/contexts/conversation-websocket-context.tsxindex 10684ca680..77bf5965dd 100644--- a/src/contexts/conversation-websocket-context.tsx+++ b/src/contexts/conversation-websocket-context.tsx@@ -890,8 +890,8 @@ export function ConversationWebSocketProvider({);}- // Same pattern again: the user answers in a modal, and the outcome- // is posted back once they close it.+ // Same pattern again: the user answers in a chat card, and the+ // outcome is posted back once they save or cancel it.if (conversationId && isRequestSecretActionEvent(event)) {void handleRequestSecretAction(event.action,diff --git a/src/routes/conversation.tsx b/src/routes/conversation.tsxindex dbd34834e2..6167d20563 100644--- a/src/routes/conversation.tsx+++ b/src/routes/conversation.tsx@@ -25,7 +25,6 @@ import { useTaskPollingController } from "#/hooks/query/use-task-polling";import { displayErrorToast } from "#/utils/custom-toast-handlers";import { useIsAuthed } from "#/hooks/query/use-is-authed";import { ConversationMain } from "#/components/features/conversation/conversation-main/conversation-main";-import { SecretRequestModal } from "#/components/features/conversation/secret-request-modal";import { ConversationMobilePanelPage } from "#/components/features/conversation/conversation-main/conversation-mobile-panel-page";import { ConversationOverviewDrawerProvider } from "#/components/features/conversation/conversation-overview-drawer-context";@@ -218,7 +217,6 @@ function AppContent() {<ConversationMain />)}</div>- <SecretRequestModal /></ConversationOverviewDrawerProvider></EventHandler>);diff --git a/src/services/secret-request.ts b/src/services/secret-request.tsindex 8529fdd7e9..8ef3697c2e 100644--- a/src/services/secret-request.ts+++ b/src/services/secret-request.ts@@ -37,7 +37,7 @@ async function findSavedSecret(* Execute a `request_secret` tool call. A secret the user already saved (for* example in Settings after this conversation started) is attached straight* away, as every saved secret is at conversation start; otherwise the request- * is queued for the modal, which reports through {@link completeSecretRequest}.+ * is queued for its chat card, which reports through {@link completeSecretRequest}.*/export async function handleRequestSecretAction(action: RequestSecretAction,@@ -96,7 +96,7 @@ async function resolveResult(/*** Hand the outcome of a secret request back to the agent. It never carries the- * value. Each request is reported once, whichever of the modal and the+ * value. Each request is reported once, whichever of the card and the* already-saved shortcut finishes first.** Never rejects: the user has already answered, so a failure to report isdiff --git a/src/stores/secret-request-store.ts b/src/stores/secret-request-store.tsindex 941f24074b..1476b8e855 100644--- a/src/stores/secret-request-store.ts+++ b/src/stores/secret-request-store.ts@@ -9,7 +9,7 @@ export interface SecretRequest {}interface SecretRequestState {- /** Pending requests, oldest first; the modal shows one at a time. */+ /** Pending requests, oldest first; each is shown as a card in the chat. */requests: SecretRequest[];}