Skip to content

🙌 OpenHands: AI-Driven Development

feat: add agent-assisted automation form updates (#17201)

Rohit Malhotra5ce3d0be2b18
diff --git a/__tests__/api/agent-server-adapter.test.ts b/__tests__/api/agent-server-adapter.test.ts
index bd21ade4f3..b3afb920c2 100644
--- a/__tests__/api/agent-server-adapter.test.ts
+++ b/__tests__/api/agent-server-adapter.test.ts
@@ -3,6 +3,7 @@ import type { MockInstance } from "vitest";
import { getAcpProvider as getClientAcpProvider } from "@openhands/typescript-client";
import { CANVAS_UI_CLIENT_TOOL_NAME } from "#/constants/canvas-ui";
import { LAUNCH_CHILD_CONVERSATION_TOOL_NAME } from "#/constants/child-conversation";
+import { AUTOMATION_FORM_UPDATE_TOOL_NAME } from "#/constants/automation-form";
import {
ACP_SERVER_TAG_KEY,
@@ -856,6 +857,36 @@ describe("buildStartConversationRequest", () => {
]);
});
+ it.each([
+ {
+ automationSetup: false,
+ expectedTools: [
+ CANVAS_UI_CLIENT_TOOL_NAME,
+ LAUNCH_CHILD_CONVERSATION_TOOL_NAME,
+ ],
+ },
+ {
+ automationSetup: true,
+ expectedTools: [
+ CANVAS_UI_CLIENT_TOOL_NAME,
+ LAUNCH_CHILD_CONVERSATION_TOOL_NAME,
+ AUTOMATION_FORM_UPDATE_TOOL_NAME,
+ ],
+ },
+ ])(
+ "builds client tools for automationSetup=$automationSetup",
+ ({ automationSetup, expectedTools }) => {
+ const payload = buildStartConversationRequest({
+ settings: DEFAULT_SETTINGS,
+ automationSetup,
+ });
+
+ expect(payload.client_tools.map((tool) => tool.name)).toEqual(
+ expectedTools,
+ );
+ },
+ );
+
it("sends the client tool when resuming a conversation", () => {
const payload = buildStartConversationRequest({
settings: DEFAULT_SETTINGS,
diff --git a/__tests__/api/agent-server-conversation-service.test.ts b/__tests__/api/agent-server-conversation-service.test.ts
index 7a2b143ba4..f11447309a 100644
--- a/__tests__/api/agent-server-conversation-service.test.ts
+++ b/__tests__/api/agent-server-conversation-service.test.ts
@@ -1413,6 +1413,63 @@ describe("AgentServerConversationService", () => {
});
});
+ it("forwards automation client tools and setup tag to cloud OpenHands conversations", async () => {
+ const requests = captureRequests(["post"], {
+ id: "task-automation",
+ status: "WORKING",
+ app_conversation_id: null,
+ agent_server_url: null,
+ request: {},
+ created_at: "2024-01-01",
+ updated_at: "2024-01-01",
+ });
+
+ await AgentServerConversationService.createConversation({
+ initialUserMsg: "Create a daily report automation",
+ automationSetup: true,
+ agentProfileKind: "openhands",
+ });
+
+ expect(requests).toHaveLength(1);
+ const [request] = requests;
+ const body = request.body as {
+ tags?: Record<string, string>;
+ client_tools: Array<{ name: string }>;
+ };
+ expect(body.tags).toEqual({ automationsetup: "draft" });
+ expect(body.client_tools.map((tool) => tool.name)).toEqual([
+ "canvas_ui_control",
+ "launch_child_conversation",
+ "automation_form_update",
+ ]);
+ });
+
+ it("does not forward automation client tools to cloud ACP conversations", async () => {
+ const requests = captureRequests(["post"], {
+ id: "task-acp",
+ status: "WORKING",
+ app_conversation_id: null,
+ agent_server_url: null,
+ request: {},
+ created_at: "2024-01-01",
+ updated_at: "2024-01-01",
+ });
+
+ await AgentServerConversationService.createConversation({
+ automationSetup: true,
+ agentProfileKind: "acp",
+ });
+
+ expect(requests).toHaveLength(1);
+ const [request] = requests;
+ const body = request.body as {
+ tags?: Record<string, string>;
+ client_tools?: Array<{ name: string }>;
+ };
+ expect(body.tags).toEqual({ automationsetup: "draft" });
+ expect(body.client_tools).toBeUndefined();
+ });
+
it("routes readConversationFile to the cloud file endpoint with the file_path query param", async () => {
// Arrange
const requests = captureRequests(["get"], "# PLAN content");
diff --git a/__tests__/components/automations/automation-setup-panel.test.tsx b/__tests__/components/automations/automation-setup-panel.test.tsx
index adaddabafc..a89ab5bee6 100644
--- a/__tests__/components/automations/automation-setup-panel.test.tsx
+++ b/__tests__/components/automations/automation-setup-panel.test.tsx
@@ -1,14 +1,21 @@
-import { render, screen, waitFor } from "@testing-library/react";
+import { act, render, screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
-import { beforeEach, describe, expect, it, vi } from "vitest";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import {
NavigationProvider,
type NavigationContextValue,
} from "#/context/navigation-context";
-import { AutomationSetupPanel } from "#/components/features/automations/setup/automation-setup-panel";
+import {
+ AGENT_FIELD_STREAM_CHARACTER_DELAY_MS,
+ AGENT_FIELD_STREAM_SETTLE_DELAY_MS,
+ AutomationSetupPanel,
+} from "#/components/features/automations/setup/automation-setup-panel";
import AutomationService from "#/api/automation-service/automation-service.api";
+import { initializeAutomationFormSession } from "#/api/automation-form-session";
import type { AutomationSetupDraft } from "#/api/automation-setup-types";
import { packTarGzip } from "#/utils/tar-gzip";
+import { handleAutomationFormUpdateAction } from "#/services/automation-form";
+import { AUTOMATION_FORM_UPDATE_ACTION_KIND } from "#/constants/automation-form";
const mockNavigate = vi.fn();
const mockToastSuccess = vi.fn();
@@ -80,23 +87,25 @@ function renderPanel(
prompt: "Review every pull request",
kind: "prompt",
},
+ conversationId = "conv-1",
) {
const value: NavigationContextValue = {
- currentPath: "/conversations/conv-1",
- conversationId: "conv-1",
+ currentPath: `/conversations/${conversationId}`,
+ conversationId,
isNavigating: false,
navigate: mockNavigate,
};
return render(
<NavigationProvider value={value}>
- <AutomationSetupPanel draft={draft} />
+ <AutomationSetupPanel draft={draft} conversationId={conversationId} />
</NavigationProvider>,
);
}
describe("AutomationSetupPanel", () => {
beforeEach(() => {
+ window.sessionStorage.clear();
vi.clearAllMocks();
mockUseGitRepositories.mockReturnValue({
data: { pages: [] },
@@ -106,6 +115,10 @@ describe("AutomationSetupPanel", () => {
});
});
+ afterEach(() => {
+ vi.useRealTimers();
+ });
+
it("switches between prompt, plugin, and custom form types", async () => {
const user = userEvent.setup();
renderPanel();
@@ -134,6 +147,10 @@ describe("AutomationSetupPanel", () => {
) as HTMLTextAreaElement
).value,
).toContain("Review every pull request");
+ expect(screen.queryByText("AUTOMATIONS$TIMEZONE")).not.toBeInTheDocument();
+ expect(screen.getByLabelText("AUTOMATIONS$TIMEZONE")).toBe(
+ screen.getByTestId("automation-setup-timezone"),
+ );
expect(
screen.queryByTestId("automation-setup-rendered-code"),
).not.toBeInTheDocument();
@@ -225,6 +242,81 @@ describe("AutomationSetupPanel", () => {
).not.toBeInTheDocument();
});
+ it("streams agent form updates field by field without overwriting user edits", async () => {
+ vi.useFakeTimers();
+ const conversationId = "conv-agent-updates";
+ const draft: AutomationSetupDraft = {
+ prompt: "Review every pull request",
+ kind: "prompt",
+ };
+ initializeAutomationFormSession(conversationId, draft);
+ renderPanel(draft, conversationId);
+
+ await act(async () => {
+ handleAutomationFormUpdateAction(
+ {
+ kind: AUTOMATION_FORM_UPDATE_ACTION_KIND,
+ fields: {
+ name: "PR Review Assistant",
+ prompt: "Watch pull requests and draft review notes",
+ frequency: "weekly",
+ time: "10:30",
+ timezone: "UTC",
+ },
+ },
+ conversationId,
+ "agent-event-1",
+ "2026-01-01T00:00:00.000Z",
+ );
+ });
+
+ const nameInput = screen.getByTestId("automation-setup-name");
+ const promptInput = screen.getByTestId("automation-setup-prompt");
+ expect(nameInput.closest("label")).toHaveAttribute(
+ "data-streaming-active",
+ "true",
+ );
+ expect(promptInput).toHaveValue("Review every pull request");
+
+ await act(async () => {
+ await vi.advanceTimersByTimeAsync(AGENT_FIELD_STREAM_CHARACTER_DELAY_MS);
+ });
+ expect(nameInput).toHaveValue("P");
+ expect(promptInput).toHaveValue("Review every pull request");
+
+ await act(async () => {
+ await vi.advanceTimersByTimeAsync(
+ "PR Review Assistant".length * AGENT_FIELD_STREAM_CHARACTER_DELAY_MS +
+ AGENT_FIELD_STREAM_SETTLE_DELAY_MS +
+ AGENT_FIELD_STREAM_CHARACTER_DELAY_MS,
+ );
+ });
+ expect(nameInput).toHaveValue("PR Review Assistant");
+ expect(promptInput.closest("label")).toHaveAttribute(
+ "data-streaming-active",
+ "true",
+ );
+ expect((promptInput as HTMLTextAreaElement).value).toMatch(/^W/);
+ expect((promptInput as HTMLTextAreaElement).value).not.toBe(
+ "Watch pull requests and draft review notes",
+ );
+
+ await act(async () => {
+ await vi.runAllTimersAsync();
+ });
+ expect(promptInput).toHaveValue(
+ "Watch pull requests and draft review notes",
+ );
+ expect(
+ screen.getByTestId("automation-setup-frequency-weekly"),
+ ).toHaveAttribute("aria-checked", "true");
+ expect(screen.getByTestId("automation-setup-time")).toHaveValue("10:30");
+ expect(screen.getByTestId("automation-setup-timezone")).toHaveValue("UTC");
+ expect(
+ screen.getAllByText("AUTOMATION_SETUP$FILLED_BY_OPENHANDS").length,
+ ).toBeGreaterThan(0);
+ });
+
it("creates plugin drafts with the selected plugin source", async () => {
vi.mocked(AutomationService.createAutomationDraft).mockResolvedValue({
id: "automation-1",
diff --git a/__tests__/components/features/conversation/conversation-main.test.tsx b/__tests__/components/features/conversation/conversation-main.test.tsx
index 9cdfeba906..08dca2aeae 100644
--- a/__tests__/components/features/conversation/conversation-main.test.tsx
+++ b/__tests__/components/features/conversation/conversation-main.test.tsx
@@ -143,8 +143,10 @@ vi.mock(
const { createPortal } = require("react-dom");
return {
AutomationSetupPanel: ({
+ conversationId,
toolbarPortal,
}: {
+ conversationId?: string | null;
toolbarPortal?: HTMLElement | null;
}) => (
<>
@@ -154,7 +156,10 @@ vi.mock(
toolbarPortal,
)
: null}
- <div data-testid="automation-setup-panel" />
+ <div
+ data-testid="automation-setup-panel"
+ data-conversation-id={conversationId ?? ""}
+ />
</>
),
};
@@ -245,6 +250,10 @@ describe("ConversationMain - Layout Transition Stability", () => {
renderConversationMain();
expect(screen.getByTestId("automation-setup-topbar")).toBeInTheDocument();
+ expect(screen.getByTestId("automation-setup-panel")).toHaveAttribute(
+ "data-conversation-id",
+ "conv-1",
+ );
expect(screen.queryByTestId("chat-pane-header")).not.toBeInTheDocument();
expect(
screen.getByTestId("automation-setup-conversation-title"),
@@ -277,7 +286,10 @@ describe("ConversationMain - Layout Transition Stability", () => {
renderConversationMain();
expect(screen.getByTestId("automation-setup-topbar")).toBeInTheDocument();
- expect(screen.getByTestId("automation-setup-panel")).toBeInTheDocument();
+ expect(screen.getByTestId("automation-setup-panel")).toHaveAttribute(
+ "data-conversation-id",
+ "conv-1",
+ );
expect(
screen.getByTestId("automation-setup-docked-composer"),
).toBeInTheDocument();
diff --git a/__tests__/components/features/home/home-chat-launcher.test.tsx b/__tests__/components/features/home/home-chat-launcher.test.tsx
index 9e94795f16..b03e9d84d9 100644
--- a/__tests__/components/features/home/home-chat-launcher.test.tsx
+++ b/__tests__/components/features/home/home-chat-launcher.test.tsx
@@ -391,10 +391,6 @@ describe("HomeChatLauncher", () => {
"data-placeholder",
"SUGGESTIONS$WHAT_TO_BUILD",
);
- expect(
- screen.getByTestId("recommended-automations-rail"),
- ).toBeInTheDocument();
-
await user.click(screen.getByTestId("home-launcher-mode-automate"));
expect(screen.getByTestId("home-launcher-mode-automate")).toHaveAttribute(
@@ -516,9 +512,11 @@ describe("HomeChatLauncher", () => {
await user.click(screen.getByTestId("stub-chat-submit"));
await waitFor(() => expect(createSpy).toHaveBeenCalledTimes(1));
- expect(createSpy).toHaveBeenCalledWith({
+ expect(createSpy.mock.calls[0]?.[0]).toMatchObject({
initialUserMsg: "hello world",
metadata: null,
+ workingDirOverride: undefined,
+ workspaceMode: undefined,
});
});
@@ -613,6 +611,37 @@ describe("HomeChatLauncher", () => {
).toBeInTheDocument();
});
+ it("allows Automate mode on cloud backends", async () => {
+ mockUseActiveBackend.mockReturnValue(cloudBackend);
+ const createSpy = vi
+ .spyOn(AgentServerConversationService, "createConversation")
+ .mockResolvedValue(makeConversationResponse());
+
+ renderLauncher();
+ const user = userEvent.setup();
+
+ expect(
+ screen.queryByText("HOME$AUTOMATE_LOCAL_BACKEND_ONLY"),
+ ).not.toBeInTheDocument();
+ await user.click(screen.getByTestId("home-launcher-mode-automate"));
+
+ expect(screen.getByTestId("home-launcher-mode-automate")).toHaveAttribute(
+ "aria-checked",
+ "true",
+ );
+ expect(screen.getByTestId("stub-chat-submit")).toHaveAttribute(
+ "data-placeholder",
+ "HOME$AUTOMATE_PROMPT_PLACEHOLDER",
+ );
+
+ await user.click(screen.getByTestId("stub-chat-submit"));
+
+ await waitFor(() => expect(createSpy).toHaveBeenCalledTimes(1));
+ expect(createSpy).toHaveBeenCalledWith(
+ expect.objectContaining({ automationSetup: true }),
+ );
+ });
+
it("passes the picked repository + branch payload on a cloud backend", async () => {
mockUseActiveBackend.mockReturnValue(cloudBackend);
const createSpy = vi
@@ -786,6 +815,7 @@ describe("HomeChatLauncher", () => {
await userEvent.click(await screen.findByTestId("stub-plugin-pick"));
},
expectedPlugins: [{ source: "github:o/a", ref: null, repo_path: null }],
+ expectedAutomationSetup: false,
marksAutomationSetup: false,
},
{
@@ -796,11 +826,17 @@ describe("HomeChatLauncher", () => {
);
},
expectedPlugins: undefined,
+ expectedAutomationSetup: true,
marksAutomationSetup: true,
},
])(
"creates a conversation in $name",
- async ({ prepare, expectedPlugins, marksAutomationSetup }) => {
+ async ({
+ prepare,
+ expectedPlugins,
+ expectedAutomationSetup,
+ marksAutomationSetup,
+ }) => {
const createSpy = vi
.spyOn(AgentServerConversationService, "createConversation")
.mockResolvedValue(makeConversationResponse());
@@ -815,6 +851,7 @@ describe("HomeChatLauncher", () => {
expect.objectContaining({
initialUserMsg: "hello world",
plugins: expectedPlugins,
+ automationSetup: expectedAutomationSetup,
metadata: null,
}),
);
diff --git a/__tests__/services/automation-form.test.ts b/__tests__/services/automation-form.test.ts
new file mode 100644
index 0000000000..04d83a5fce
--- /dev/null
+++ b/__tests__/services/automation-form.test.ts
@@ -0,0 +1,136 @@
+import { beforeEach, describe, expect, it } from "vitest";
+
+import {
+ getAutomationFormSession,
+ initializeAutomationFormSession,
+ patchAutomationFormSession,
+} from "#/api/automation-form-session";
+import { AUTOMATION_FORM_UPDATE_ACTION_KIND } from "#/constants/automation-form";
+import { handleAutomationFormUpdateAction } from "#/services/automation-form";
+import { isAutomationFormUpdateActionEvent } from "#/types/agent-server/type-guards";
+
+describe("handleAutomationFormUpdateAction", () => {
+ beforeEach(() => {
+ window.sessionStorage.clear();
+ });
+
+ it("recognizes automation form update action events", () => {
+ expect(
+ isAutomationFormUpdateActionEvent({
+ id: "event-1",
+ timestamp: "2026-01-01T00:00:00.000Z",
+ source: "agent",
+ tool_name: "automation_form_update",
+ tool_call_id: "tool-call-1",
+ action: {
+ kind: AUTOMATION_FORM_UPDATE_ACTION_KIND,
+ fields: { name: "Daily triage" },
+ },
+ } as never),
+ ).toBe(true);
+ });
+
+ it("applies agent patches to an existing automation setup draft", () => {
+ initializeAutomationFormSession("conv-1", {
+ prompt: "Initial automation",
+ kind: "prompt",
+ });
+
+ const result = handleAutomationFormUpdateAction(
+ {
+ kind: AUTOMATION_FORM_UPDATE_ACTION_KIND,
+ fields: {
+ name: "Daily triage",
+ prompt: "Summarize incoming issues every morning",
+ triggerKind: "cron",
+ frequency: "daily",
+ },
+ },
+ "conv-1",
+ "event-1",
+ "2026-01-01T00:00:00.000Z",
+ );
+
+ expect(result).toEqual({
+ applied: ["name", "prompt", "triggerKind", "frequency"],
+ skipped: [],
+ duplicate: false,
+ });
+ expect(getAutomationFormSession("conv-1")?.form).toMatchObject({
+ name: "Daily triage",
+ prompt: "Summarize incoming issues every morning",
+ frequency: "daily",
+ });
+ expect(
+ getAutomationFormSession("conv-1")?.fieldMetadata?.name,
+ ).toMatchObject({
+ updatedBy: "agent",
+ userDirty: false,
+ });
+ });
+
+ it("does not replay duplicate agent events", () => {
+ initializeAutomationFormSession("conv-1", {
+ prompt: "Initial automation",
+ kind: "prompt",
+ });
+
+ handleAutomationFormUpdateAction(
+ {
+ kind: AUTOMATION_FORM_UPDATE_ACTION_KIND,
+ fields: { name: "First value" },
+ },
+ "conv-1",
+ "event-1",
+ );
+ const result = handleAutomationFormUpdateAction(
+ {
+ kind: AUTOMATION_FORM_UPDATE_ACTION_KIND,
+ fields: { name: "Second value" },
+ },
+ "conv-1",
+ "event-1",
+ );
+
+ expect(result.duplicate).toBe(true);
+ expect(getAutomationFormSession("conv-1")?.form?.name).toBe("First value");
+ });
+
+ it.each([
+ {
+ name: "protects user-edited fields by default",
+ overwriteUserEdits: undefined,
+ expectedResult: { applied: [], skipped: ["name"] },
+ expectedName: "Manual title",
+ },
+ {
+ name: "overwrites user-edited fields when explicit",
+ overwriteUserEdits: true,
+ expectedResult: { applied: ["name"], skipped: [] },
+ expectedName: "Agent title",
+ },
+ ])("$name", ({ overwriteUserEdits, expectedResult, expectedName }) => {
+ initializeAutomationFormSession("conv-1", {
+ prompt: "Initial automation",
+ kind: "prompt",
+ });
+ patchAutomationFormSession(
+ "conv-1",
+ { name: "Manual title" },
+ { source: "user" },
+ );
+
+ const result = handleAutomationFormUpdateAction(
+ {
+ kind: AUTOMATION_FORM_UPDATE_ACTION_KIND,
+ fields: { name: "Agent title" },
+ overwrite_user_edits: overwriteUserEdits,
+ },
+ "conv-1",
+ "event-2",
+ );
+
+ expect(result).toMatchObject(expectedResult);
+ expect(getAutomationFormSession("conv-1")?.form?.name).toBe(expectedName);
+ });
+});
diff --git a/__tests__/tools/automation-form-tool.test.ts b/__tests__/tools/automation-form-tool.test.ts
new file mode 100644
index 0000000000..59ad277282
--- /dev/null
+++ b/__tests__/tools/automation-form-tool.test.ts
@@ -0,0 +1,46 @@
+import { describe, expect, it } from "vitest";
+
+import {
+ AUTOMATION_FORM_UPDATE_ACTION_KIND,
+ AUTOMATION_FORM_UPDATE_CLIENT_TOOL,
+ AUTOMATION_FORM_UPDATE_TOOL_NAME,
+} from "#/api/automation-form-client-tool";
+
+describe("automation_form_update client tool", () => {
+ it("defines the automation form update client tool contract", () => {
+ expect(AUTOMATION_FORM_UPDATE_TOOL_NAME).toBe("automation_form_update");
+ expect(AUTOMATION_FORM_UPDATE_ACTION_KIND).toBe(
+ "ClientAction_automation_form_update",
+ );
+ expect(AUTOMATION_FORM_UPDATE_CLIENT_TOOL).toMatchObject({
+ name: AUTOMATION_FORM_UPDATE_TOOL_NAME,
+ parameters: {
+ type: "object",
+ additionalProperties: false,
+ properties: {
+ fields: {
+ type: "object",
+ additionalProperties: false,
+ properties: {
+ kind: { enum: ["prompt", "plugin", "custom"] },
+ triggerKind: { enum: ["cron", "event"] },
+ frequency: {
+ enum: ["hourly", "daily", "weekdays", "weekly", "custom"],
+ },
+ customCode: { type: "string" },
+ setupScript: { type: "string" },
+ },
+ },
+ overwrite_user_edits: { type: "boolean" },
+ },
+ required: ["fields"],
+ },
+ annotations: {
+ readOnlyHint: false,
+ destructiveHint: false,
+ idempotentHint: false,
+ openWorldHint: false,
+ },
+ });
+ });
+});
diff --git a/src/api/agent-server-adapter.ts b/src/api/agent-server-adapter.ts
index 2b7fc51951..12149aeeb3 100644
--- a/src/api/agent-server-adapter.ts
+++ b/src/api/agent-server-adapter.ts
@@ -59,6 +59,7 @@ import {
LAUNCH_CHILD_CONVERSATION_CLIENT_TOOL,
LAUNCH_CHILD_CONVERSATION_TOOL_NAME,
} from "./launch-child-conversation-client-tool";
+import { AUTOMATION_FORM_UPDATE_CLIENT_TOOL } from "./automation-form-client-tool";
import {
buildPlanPath,
LOCAL_PLANNER_PARENT_TAG_KEY,
@@ -1196,6 +1197,7 @@ type RawAgentStartConversationPayload = StartConversationPayloadBase & {
export interface StartConversationOptions {
settings: Settings;
query?: string;
+ automationSetup?: boolean;
conversationInstructions?: string;
plugins?: PluginSpec[];
conversationId?: string;
@@ -1356,7 +1358,13 @@ export function buildStartConversationRequest(
// conversations can start.
client_tools:
launchAgentKind === "openhands"
- ? [CANVAS_UI_CLIENT_TOOL, LAUNCH_CHILD_CONVERSATION_CLIENT_TOOL]
+ ? [
+ CANVAS_UI_CLIENT_TOOL,
+ LAUNCH_CHILD_CONVERSATION_CLIENT_TOOL,
+ ...(options.automationSetup
+ ? [AUTOMATION_FORM_UPDATE_CLIENT_TOOL]
+ : []),
+ ]
: [],
confirmation_policy:
getConversationConfirmationPolicy(conversationSettings),
@@ -1713,6 +1721,7 @@ export async function assertSubscriptionAuthReady(
export async function buildStartConversationRequestWithEncryptedSettings(options: {
settings: Settings;
query?: string;
+ automationSetup?: boolean;
conversationInstructions?: string;
plugins?: PluginSpec[];
conversationId?: string;
diff --git a/src/api/automation-form-client-tool.ts b/src/api/automation-form-client-tool.ts
new file mode 100644
index 0000000000..d71781a141
--- /dev/null
+++ b/src/api/automation-form-client-tool.ts
@@ -0,0 +1,79 @@
+import { AUTOMATION_FORM_UPDATE_TOOL_NAME } from "#/constants/automation-form";
+import type { ClientToolSpec } from "./canvas-ui-client-tool";
+
+export {
+ AUTOMATION_FORM_UPDATE_ACTION_KIND,
+ AUTOMATION_FORM_UPDATE_TOOL_NAME,
+} from "#/constants/automation-form";
+
+const AUTOMATION_FORM_UPDATE_DESCRIPTION = `Update the automation setup form that is open beside this conversation. Use this only when the user asks you to help fill, revise, or complete automation configuration fields in the UI.
+
+The user can keep editing the form while you converse. By default, your updates fill empty fields or fields the user has not manually edited. If the user already edited a field, do not overwrite it unless they explicitly asked you to replace their value; set overwrite_user_edits=true only in that case.
+
+Useful fields:
+* kind: "prompt", "plugin", or "custom".
+* name: short automation name.
+* prompt: natural-language instruction for prompt/plugin automations.
+* repository: optional GitHub repository URL or owner/repo for prompt/plugin automations.
+* pluginSource and pluginRef: plugin source and optional ref for plugin automations.
+* customCode, entrypoint, setupScriptPath, setupScript: custom Python bundle fields.
+* triggerKind: "cron" or "event".
+* frequency: "hourly", "daily", "weekdays", "weekly", or "custom" for cron triggers.
+* time, timezone, customSchedule: cron scheduling fields.
+* eventSource, eventKey, eventFilter: event trigger fields.
+* showTimeout and timeoutSeconds: optional timeout controls.
+
+Call this with only the fields you are changing. After calling it, briefly tell the user which fields you filled and ask them to review anything uncertain.`;
+
+export const AUTOMATION_FORM_UPDATE_CLIENT_TOOL: ClientToolSpec = {
+ name: AUTOMATION_FORM_UPDATE_TOOL_NAME,
+ description: AUTOMATION_FORM_UPDATE_DESCRIPTION,
+ parameters: {
+ type: "object",
+ additionalProperties: false,
+ properties: {
+ fields: {
+ type: "object",
+ additionalProperties: false,
+ properties: {
+ kind: { type: "string", enum: ["prompt", "plugin", "custom"] },
+ name: { type: "string" },
+ prompt: { type: "string" },
+ repository: { type: "string" },
+ pluginSource: { type: "string" },
+ pluginRef: { type: "string" },
+ customCode: { type: "string" },
+ entrypoint: { type: "string" },
+ setupScriptPath: { type: "string" },
+ setupScript: { type: "string" },
+ triggerKind: { type: "string", enum: ["cron", "event"] },
+ frequency: {
+ type: "string",
+ enum: ["hourly", "daily", "weekdays", "weekly", "custom"],
+ },
+ time: { type: "string", description: "24-hour HH:MM time." },
+ timezone: { type: "string" },
+ customSchedule: { type: "string", description: "Cron expression." },
+ eventSource: { type: "string" },
+ eventKey: { type: "string" },
+ eventFilter: { type: "string" },
+ showTimeout: { type: "boolean" },
+ timeoutSeconds: { type: "string" },
+ },
+ description: "Automation form field values to patch in the visible UI.",
+ },
+ overwrite_user_edits: {
+ type: "boolean",
+ description:
+ "Set true only when the user explicitly asks you to replace values they edited manually.",
+ },
+ },
+ required: ["fields"],
+ },
+ annotations: {
+ readOnlyHint: false,
+ destructiveHint: false,
+ idempotentHint: false,
+ openWorldHint: false,
+ },
+};
diff --git a/src/api/automation-form-session.ts b/src/api/automation-form-session.ts
new file mode 100644
index 0000000000..fa2b9f667c
--- /dev/null
+++ b/src/api/automation-form-session.ts
@@ -0,0 +1,321 @@
+import type {
+ AutomationSetupDraft,
+ AutomationSetupField,
+ AutomationSetupFieldUpdateSource,
+ AutomationSetupFormPatch,
+ AutomationSetupFormValues,
+ AutomationSetupKind,
+ AutomationSetupPatchResult,
+ AutomationSetupTriggerKind,
+ AutomationSetupFrequency,
+} from "#/api/automation-setup-types";
+
+const AUTOMATION_FORM_SESSION_CHANGED_EVENT =
+ "openhands:automation-form-session-changed";
+const AUTOMATION_SETUP_KINDS: AutomationSetupKind[] = [
+ "prompt",
+ "plugin",
+ "custom",
+];
+const AUTOMATION_SETUP_TRIGGER_KINDS: AutomationSetupTriggerKind[] = [
+ "cron",
+ "event",
+];
+const AUTOMATION_SETUP_FREQUENCIES: AutomationSetupFrequency[] = [
+ "hourly",
+ "daily",
+ "weekdays",
+ "weekly",
+ "custom",
+];
+const STRING_FIELDS = [
+ "name",
+ "prompt",
+ "repository",
+ "pluginSource",
+ "pluginRef",
+ "customCode",
+ "entrypoint",
+ "setupScriptPath",
+ "setupScript",
+ "time",
+ "timezone",
+ "customSchedule",
+ "eventSource",
+ "eventKey",
+ "eventFilter",
+ "timeoutSeconds",
+] as const satisfies readonly AutomationSetupField[];
+
+const sessions = new Map<string, AutomationSetupDraft>();
+
+function isAutomationSetupKind(value: unknown): value is AutomationSetupKind {
+ return (
+ typeof value === "string" &&
+ AUTOMATION_SETUP_KINDS.includes(value as AutomationSetupKind)
+ );
+}
+
+function normalizeString(value: unknown): string | null {
+ return typeof value === "string" ? value : null;
+}
+
+function normalizeFormPatch(value: unknown): AutomationSetupFormPatch {
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
+ return {};
+ }
+
+ const source = value as Record<string, unknown>;
+ const form: AutomationSetupFormPatch = {};
+ for (const field of STRING_FIELDS) {
+ const fieldValue = normalizeString(source[field]);
+ if (fieldValue !== null) form[field] = fieldValue;
+ }
+ if (isAutomationSetupKind(source.kind)) form.kind = source.kind;
+ if (
+ typeof source.triggerKind === "string" &&
+ AUTOMATION_SETUP_TRIGGER_KINDS.includes(
+ source.triggerKind as AutomationSetupTriggerKind,
+ )
+ ) {
+ form.triggerKind = source.triggerKind as AutomationSetupTriggerKind;
+ }
+ if (
+ typeof source.frequency === "string" &&
+ AUTOMATION_SETUP_FREQUENCIES.includes(
+ source.frequency as AutomationSetupFrequency,
+ )
+ ) {
+ form.frequency = source.frequency as AutomationSetupFrequency;
+ }
+ if (typeof source.showTimeout === "boolean") {
+ form.showTimeout = source.showTimeout;
+ }
+ return form;
+}
+
+function normalizeFieldMetadata(
+ value: AutomationSetupDraft["fieldMetadata"],
+): AutomationSetupDraft["fieldMetadata"] {
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
+ return undefined;
+ }
+
+ const metadata: AutomationSetupDraft["fieldMetadata"] = {};
+ for (const [field, entry] of Object.entries(value)) {
+ if (
+ typeof entry === "object" &&
+ entry !== null &&
+ !Array.isArray(entry) &&
+ (entry.updatedBy === "agent" || entry.updatedBy === "user") &&
+ typeof entry.updatedAt === "string" &&
+ typeof entry.userDirty === "boolean"
+ ) {
+ metadata[field as AutomationSetupField] = entry;
+ }
+ }
+ return Object.keys(metadata).length > 0 ? metadata : undefined;
+}
+
+function normalizeDraft(value: AutomationSetupDraft): AutomationSetupDraft {
+ const form = normalizeFormPatch(value.form);
+ const prompt = form.prompt ?? value.prompt;
+ const kind = form.kind ?? value.kind;
+ if (typeof prompt !== "string" || !isAutomationSetupKind(kind)) {
+ return { prompt: "", kind: "prompt" };
+ }
+
+ const plugins = Array.isArray(value.plugins)
+ ? value.plugins.filter(
+ (plugin): plugin is string => typeof plugin === "string",
+ )
+ : [];
+ const pluginSource = form.pluginSource ?? plugins[0];
+ const normalizedForm: AutomationSetupFormPatch = {
+ ...form,
+ prompt,
+ kind,
+ ...(pluginSource ? { pluginSource } : {}),
+ };
+ const normalizedPlugins = pluginSource ? [pluginSource] : plugins;
+ const fieldMetadata = normalizeFieldMetadata(value.fieldMetadata);
+ const appliedAgentEventIds = Array.isArray(value.appliedAgentEventIds)
+ ? [
+ ...new Set(
+ value.appliedAgentEventIds.filter((id) => typeof id === "string"),
+ ),
+ ]
+ : undefined;
+
+ return {
+ prompt,
+ kind,
+ ...(normalizedPlugins.length > 0 ? { plugins: normalizedPlugins } : {}),
+ form: normalizedForm,
+ ...(fieldMetadata ? { fieldMetadata } : {}),
+ ...(appliedAgentEventIds && appliedAgentEventIds.length > 0
+ ? { appliedAgentEventIds }
+ : {}),
+ };
+}
+
+function isEmptyValue(value: AutomationSetupFormValues[AutomationSetupField]) {
+ if (typeof value === "string") return value.trim() === "";
+ return value === false;
+}
+
+function eventDetail(
+ conversationId: string,
+ draft: AutomationSetupDraft | null,
+ result?: AutomationSetupPatchResult,
+) {
+ return { conversationId, draft, result };
+}
+
+function notifySessionChanged(
+ conversationId: string,
+ draft: AutomationSetupDraft | null,
+ result?: AutomationSetupPatchResult,
+) {
+ if (typeof window === "undefined") return;
+ window.dispatchEvent(
+ new CustomEvent(AUTOMATION_FORM_SESSION_CHANGED_EVENT, {
+ detail: eventDetail(conversationId, draft, result),
+ }),
+ );
+}
+
+export function initializeAutomationFormSession(
+ conversationId: string,
+ draft: AutomationSetupDraft,
+) {
+ sessions.set(conversationId, normalizeDraft(draft));
+}
+
+export function getAutomationFormSession(
+ conversationId: string | null | undefined,
+): AutomationSetupDraft | null {
+ if (!conversationId) return null;
+ return sessions.get(conversationId) ?? null;
+}
+
+export function patchAutomationFormSession(
+ conversationId: string,
+ patch: AutomationSetupFormPatch,
+ options: {
+ source: AutomationSetupFieldUpdateSource;
+ overwriteUserEdits?: boolean;
+ eventId?: string | null;
+ updatedAt?: string;
+ },
+): AutomationSetupPatchResult {
+ const existing = sessions.get(conversationId);
+ const result: AutomationSetupPatchResult = {
+ applied: [],
+ skipped: [],
+ duplicate: false,
+ };
+ if (!existing) return result;
+
+ if (
+ options.source === "agent" &&
+ options.eventId &&
+ existing.appliedAgentEventIds?.includes(options.eventId)
+ ) {
+ return { ...result, duplicate: true };
+ }
+
+ const normalizedPatch = normalizeFormPatch(patch);
+ const nextForm: AutomationSetupFormPatch = { ...(existing.form ?? {}) };
+ const nextMetadata: NonNullable<AutomationSetupDraft["fieldMetadata"]> = {
+ ...(existing.fieldMetadata ?? {}),
+ };
+ const updatedAt = options.updatedAt ?? new Date().toISOString();
+
+ for (const [fieldName, value] of Object.entries(normalizedPatch)) {
+ const field = fieldName as AutomationSetupField;
+ const currentValue = nextForm[field];
+ const metadata = nextMetadata[field];
+ const userDirty = metadata?.userDirty === true;
+ if (
+ options.source === "agent" &&
+ userDirty &&
+ !options.overwriteUserEdits
+ ) {
+ result.skipped.push(field);
+ continue;
+ }
+ if (
+ options.source === "agent" &&
+ metadata?.updatedAt &&
+ metadata.updatedAt > updatedAt &&
+ !options.overwriteUserEdits
+ ) {
+ result.skipped.push(field);
+ continue;
+ }
+ if (
+ options.source === "agent" &&
+ currentValue !== undefined &&
+ !isEmptyValue(currentValue) &&
+ userDirty &&
+ !options.overwriteUserEdits
+ ) {
+ result.skipped.push(field);
+ continue;
+ }
+
+ (nextForm as Record<string, unknown>)[field] = value;
+ nextMetadata[field] = {
+ updatedBy: options.source,
+ updatedAt,
+ userDirty: options.source === "user" || userDirty,
+ };
+ result.applied.push(field);
+ }
+
+ const nextDraft = normalizeDraft({
+ ...existing,
+ form: nextForm,
+ prompt: nextForm.prompt ?? existing.prompt,
+ kind: nextForm.kind ?? existing.kind,
+ plugins:
+ typeof nextForm.pluginSource === "string" && nextForm.pluginSource
+ ? [nextForm.pluginSource]
+ : existing.plugins,
+ fieldMetadata: nextMetadata,
+ appliedAgentEventIds:
+ options.source === "agent" && options.eventId
+ ? [...(existing.appliedAgentEventIds ?? []), options.eventId]
+ : existing.appliedAgentEventIds,
+ });
+
+ sessions.set(conversationId, nextDraft);
+ notifySessionChanged(conversationId, nextDraft, result);
+ return result;
+}
+
+export function subscribeAutomationFormSession(
+ conversationId: string,
+ listener: (
+ draft: AutomationSetupDraft | null,
+ result?: AutomationSetupPatchResult,
+ ) => void,
+): () => void {
+ if (typeof window === "undefined") return () => {};
+
+ const handler = (event: Event) => {
+ const detail = (event as CustomEvent<ReturnType<typeof eventDetail>>)
+ .detail;
+ if (detail?.conversationId !== conversationId) return;
+ listener(detail.draft, detail.result);
+ };
+ window.addEventListener(AUTOMATION_FORM_SESSION_CHANGED_EVENT, handler);
+ return () =>
+ window.removeEventListener(AUTOMATION_FORM_SESSION_CHANGED_EVENT, handler);
+}
+
+export function clearAutomationFormSession(conversationId: string) {
+ sessions.delete(conversationId);
+ notifySessionChanged(conversationId, null);
+}
diff --git a/src/api/automation-setup-types.ts b/src/api/automation-setup-types.ts
index 8bc9b88b26..73268cbbf5 100644
--- a/src/api/automation-setup-types.ts
+++ b/src/api/automation-setup-types.ts
@@ -1,7 +1,58 @@
export type AutomationSetupKind = "prompt" | "plugin" | "custom";
+export type AutomationSetupTriggerKind = "cron" | "event";
+export type AutomationSetupFrequency =
+ | "hourly"
+ | "daily"
+ | "weekdays"
+ | "weekly"
+ | "custom";
+export type AutomationSetupFieldUpdateSource = "agent" | "user";
+
+export interface AutomationSetupFormValues {
+ kind: AutomationSetupKind;
+ name: string;
+ prompt: string;
+ repository: string;
+ pluginSource: string;
+ pluginRef: string;
+ customCode: string;
+ entrypoint: string;
+ setupScriptPath: string;
+ setupScript: string;
+ triggerKind: AutomationSetupTriggerKind;
+ frequency: AutomationSetupFrequency;
+ time: string;
+ timezone: string;
+ customSchedule: string;
+ eventSource: string;
+ eventKey: string;
+ eventFilter: string;
+ showTimeout: boolean;
+ timeoutSeconds: string;
+}
+
+export type AutomationSetupField = keyof AutomationSetupFormValues;
+export type AutomationSetupFormPatch = Partial<AutomationSetupFormValues>;
+
+export interface AutomationSetupFieldMetadata {
+ updatedBy: AutomationSetupFieldUpdateSource;
+ updatedAt: string;
+ userDirty: boolean;
+}
+
+export interface AutomationSetupPatchResult {
+ applied: AutomationSetupField[];
+ skipped: AutomationSetupField[];
+ duplicate: boolean;
+}
export interface AutomationSetupDraft {
prompt: string;
kind: AutomationSetupKind;
plugins?: string[];
+ form?: AutomationSetupFormPatch;
+ fieldMetadata?: Partial<
+ Record<AutomationSetupField, AutomationSetupFieldMetadata>
+ >;
+ appliedAgentEventIds?: string[];
}
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 4d4e89171b..37d112b37d 100644
--- a/src/api/conversation-service/agent-server-conversation-service.api.ts
+++ b/src/api/conversation-service/agent-server-conversation-service.api.ts
@@ -66,6 +66,10 @@ import {
} from "../conversation-metadata-store";
import { resolveTitleLlmProfile } from "#/utils/title-llm-profile";
import { isPlannerConversationOf } from "#/utils/plan-file";
+import { buildAutomationSetupModeTags } from "#/utils/automation-draft-tags";
+import { AUTOMATION_FORM_UPDATE_CLIENT_TOOL } from "../automation-form-client-tool";
+import { CANVAS_UI_CLIENT_TOOL } from "../canvas-ui-client-tool";
+import { LAUNCH_CHILD_CONVERSATION_CLIENT_TOOL } from "../launch-child-conversation-client-tool";
import type {
GetHooksResponse,
PluginSpec,
@@ -399,6 +403,7 @@ function requireAppConversation(
*/
export interface CreateConversationOptions {
initialUserMsg?: string;
+ automationSetup?: boolean;
conversationInstructions?: string;
plugins?: PluginSpec[];
metadata?: ConversationMetadata | null;
@@ -480,6 +485,7 @@ class AgentServerConversationService {
): Promise<AppConversationStartTask> {
const {
initialUserMsg,
+ automationSetup,
conversationInstructions,
plugins,
metadata,
@@ -532,6 +538,18 @@ class AgentServerConversationService {
}
: {}),
trigger: "gui",
+ ...(automationSetup
+ ? { tags: buildAutomationSetupModeTags(null) }
+ : {}),
+ ...(automationSetup && agentProfileKind !== "acp"
+ ? {
+ client_tools: [
+ CANVAS_UI_CLIENT_TOOL,
+ LAUNCH_CHILD_CONVERSATION_CLIENT_TOOL,
+ AUTOMATION_FORM_UPDATE_CLIENT_TOOL,
+ ],
+ }
+ : {}),
};
return createCloudAppConversation(request);
}
@@ -560,6 +578,7 @@ class AgentServerConversationService {
const payload = await buildStartConversationRequestWithEncryptedSettings({
settings,
query: initialUserMsg,
+ automationSetup,
conversationInstructions,
plugins,
conversationId,
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 2d7d7e97e0..663e15d471 100644
--- a/src/api/conversation-service/agent-server-conversation-service.types.ts
+++ b/src/api/conversation-service/agent-server-conversation-service.types.ts
@@ -1,4 +1,5 @@
import { ConversationTrigger } from "../open-hands.types";
+import type { ClientToolSpec } from "../canvas-ui-client-tool";
import { Provider } from "#/types/settings";
import { SuggestedTask } from "#/utils/types";
import { ExecutionStatus } from "#/types/agent-server/core";
@@ -82,6 +83,8 @@ export interface AppConversationStartRequest {
agent_type?: "default" | "plan";
sandbox_id?: string | null;
plugins?: PluginSpec[] | null; // Plugins to load when starting the conversation
+ client_tools?: ClientToolSpec[] | null; // Browser/client-handled tools registered with the runtime
+ tags?: Record<string, string> | null; // Conversation tags to persist at start
// One-off launch from a saved AgentProfile, resolved server-side (#3727).
// Accepted by the cloud app-server (OpenHands #15060) on
// POST /api/v1/app-conversations; the local path uses the encrypted
diff --git a/src/components/features/automations/setup/automation-setup-panel.tsx b/src/components/features/automations/setup/automation-setup-panel.tsx
index 11a762f6be..432a4a7e95 100644
--- a/src/components/features/automations/setup/automation-setup-panel.tsx
+++ b/src/components/features/automations/setup/automation-setup-panel.tsx
@@ -1,4 +1,10 @@
-import { useState, type ReactNode } from "react";
+import {
+ useCallback,
+ useEffect,
+ useRef,
+ useState,
+ type ReactNode,
+} from "react";
import { createPortal } from "react-dom";
import toast from "react-hot-toast";
import { useTranslation } from "react-i18next";
@@ -12,8 +18,17 @@ import {
Zap,
} from "lucide-react";
import AutomationService from "#/api/automation-service/automation-service.api";
+import {
+ clearAutomationFormSession,
+ initializeAutomationFormSession,
+ patchAutomationFormSession,
+ subscribeAutomationFormSession,
+} from "#/api/automation-form-session";
import type {
AutomationSetupDraft,
+ AutomationSetupField,
+ AutomationSetupFormPatch,
+ AutomationSetupFormValues,
AutomationSetupKind,
} from "#/api/automation-setup-types";
import {
@@ -56,6 +71,8 @@ const DEFAULT_CUSTOM_SETUP_SCRIPT = `#!/usr/bin/env bash
const DEFAULT_TIMEOUT_SECONDS = "600";
const PREFLIGHT_TARBALL_PATH =
"oh-internal://uploads/00000000-0000-0000-0000-000000000000";
+export const AGENT_FIELD_STREAM_CHARACTER_DELAY_MS = 12;
+export const AGENT_FIELD_STREAM_SETTLE_DELAY_MS = 160;
const FREQUENCIES = [
"hourly",
@@ -64,6 +81,37 @@ const FREQUENCIES = [
"weekly",
"custom",
] as const;
+const AUTOMATION_SETUP_FIELD_RENDER_ORDER: AutomationSetupField[] = [
+ "kind",
+ "name",
+ "prompt",
+ "pluginSource",
+ "pluginRef",
+ "repository",
+ "customCode",
+ "entrypoint",
+ "setupScriptPath",
+ "setupScript",
+ "triggerKind",
+ "frequency",
+ "time",
+ "timezone",
+ "customSchedule",
+ "eventSource",
+ "eventKey",
+ "eventFilter",
+ "showTimeout",
+ "timeoutSeconds",
+];
+const NON_CHARACTER_STREAM_FIELDS = new Set<AutomationSetupField>([
+ "kind",
+ "triggerKind",
+ "frequency",
+ "showTimeout",
+ "time",
+]);
+const streamingFieldHighlightClassName =
+ "rounded-xl ring-2 ring-[#D5C76B]/80 ring-offset-2 ring-offset-base shadow-[0_0_24px_rgba(213,199,107,0.24)]";
export function parseAutomationSetupRepositories(value: string): string[] {
const seen = new Set<string>();
@@ -87,11 +135,11 @@ function buildRepositorySource(url: string): {
}
type Frequency = (typeof FREQUENCIES)[number];
-type TriggerKind = "cron" | "event";
type StatusMessage = { kind: "success" | "error"; text: string } | null;
interface AutomationSetupPanelProps {
draft: AutomationSetupDraft;
+ conversationId?: string | null;
toolbarPortal?: HTMLElement | null;
showInlineHeader?: boolean;
reserveComposerSpace?: boolean;
@@ -134,6 +182,57 @@ function buildStarterPython(prompt: string): string {
return `import json\nimport os\nimport urllib.request\n\n\ndef fire_callback(status="COMPLETED", error=None):\n url = os.environ.get("AUTOMATION_CALLBACK_URL", "")\n if not url:\n return\n body = {"status": status, "run_id": os.environ.get("AUTOMATION_RUN_ID", "")}\n if error:\n body["error"] = error\n request = urllib.request.Request(\n url,\n data=json.dumps(body).encode(),\n headers={\n "Content-Type": "application/json",\n "Authorization": f"Bearer {os.environ.get('AUTOMATION_CALLBACK_API_KEY', '')}",\n },\n )\n urllib.request.urlopen(request, timeout=10)\n\n\ndef main():\n prompt = ${JSON.stringify(prompt)}\n print(f"Automation prompt: {prompt}")\n\n\nif __name__ == "__main__":\n try:\n main()\n fire_callback("COMPLETED")\n except Exception as exc:\n fire_callback("FAILED", str(exc))\n raise\n`;
}
+function sortFieldsByRenderOrder(
+ fields: AutomationSetupField[],
+): AutomationSetupField[] {
+ return [...fields].sort(
+ (first, second) =>
+ AUTOMATION_SETUP_FIELD_RENDER_ORDER.indexOf(first) -
+ AUTOMATION_SETUP_FIELD_RENDER_ORDER.indexOf(second),
+ );
+}
+
+function shouldCharacterStreamField(
+ field: AutomationSetupField,
+ value: AutomationSetupFormValues[AutomationSetupField],
+): value is string {
+ return typeof value === "string" && !NON_CHARACTER_STREAM_FIELDS.has(field);
+}
+
+function streamingHighlightClassName(isStreaming: boolean) {
+ return isStreaming ? streamingFieldHighlightClassName : undefined;
+}
+
+function buildInitialForm(
+ draft: AutomationSetupDraft,
+): AutomationSetupFormValues {
+ const form = draft.form ?? {};
+ const prompt = form.prompt ?? draft.prompt;
+ const kind = form.kind ?? draft.kind;
+ return {
+ kind,
+ name: form.name ?? deriveName(prompt),
+ prompt,
+ repository: form.repository ?? "",
+ pluginSource: form.pluginSource ?? draft.plugins?.[0] ?? "",
+ pluginRef: form.pluginRef ?? "",
+ customCode: form.customCode ?? buildStarterPython(prompt),
+ entrypoint: form.entrypoint ?? DEFAULT_CUSTOM_ENTRYPOINT,
+ setupScriptPath: form.setupScriptPath ?? DEFAULT_CUSTOM_SETUP_SCRIPT_PATH,
+ setupScript: form.setupScript ?? DEFAULT_CUSTOM_SETUP_SCRIPT,
+ triggerKind: form.triggerKind ?? "cron",
+ frequency: form.frequency ?? "daily",
+ time: form.time ?? DEFAULT_TIME,
+ timezone: form.timezone ?? DEFAULT_TIMEZONE,
+ customSchedule: form.customSchedule ?? DEFAULT_CUSTOM_SCHEDULE,
+ eventSource: form.eventSource ?? DEFAULT_EVENT_SOURCE,
+ eventKey: form.eventKey ?? DEFAULT_EVENT_KEY,
+ eventFilter: form.eventFilter ?? "",
+ showTimeout: form.showTimeout ?? false,
+ timeoutSeconds: form.timeoutSeconds ?? DEFAULT_TIMEOUT_SECONDS,
+ };
+}
+
function endpointName(kind: AutomationSetupKind): InterfaceEndpointName {
if (kind === "plugin") return "createPlugin";
if (kind === "custom") return "createBundle";
@@ -157,6 +256,7 @@ function frequencyLabelKey(frequency: Frequency): I18nKey {
export function AutomationSetupPanel({
draft,
+ conversationId,
toolbarPortal,
showInlineHeader = true,
reserveComposerSpace = false,
@@ -165,32 +265,241 @@ export function AutomationSetupPanel({
const [agentProfileId, setAgentProfileId] = useState("");
const { t } = useTranslation("openhands");
const { navigate } = useNavigation();
- const [kind, setKind] = useState<AutomationSetupKind>(draft.kind);
- const [name, setName] = useState(() => deriveName(draft.prompt));
- const [prompt, setPrompt] = useState(draft.prompt);
- const [repository, setRepository] = useState("");
- const [pluginSource, setPluginSource] = useState(draft.plugins?.[0] ?? "");
- const [pluginRef, setPluginRef] = useState("");
- const [customCode, setCustomCode] = useState(() =>
- buildStarterPython(draft.prompt),
- );
- const [entrypoint, setEntrypoint] = useState(DEFAULT_CUSTOM_ENTRYPOINT);
- const [setupScriptPath, setSetupScriptPath] = useState(
- DEFAULT_CUSTOM_SETUP_SCRIPT_PATH,
+ const [form, setForm] = useState(() => buildInitialForm(draft));
+ const [fieldMetadata, setFieldMetadata] = useState(
+ () => draft.fieldMetadata ?? {},
);
- const [setupScript, setSetupScript] = useState(DEFAULT_CUSTOM_SETUP_SCRIPT);
- const [triggerKind, setTriggerKind] = useState<TriggerKind>("cron");
- const [frequency, setFrequency] = useState<Frequency>("daily");
- const [time, setTime] = useState(DEFAULT_TIME);
- const [timezone, setTimezone] = useState(DEFAULT_TIMEZONE);
- const [customSchedule, setCustomSchedule] = useState(DEFAULT_CUSTOM_SCHEDULE);
- const [eventSource, setEventSource] = useState(DEFAULT_EVENT_SOURCE);
- const [eventKey, setEventKey] = useState(DEFAULT_EVENT_KEY);
- const [eventFilter, setEventFilter] = useState("");
- const [showTimeout, setShowTimeout] = useState(false);
- const [timeoutSeconds, setTimeoutSeconds] = useState(DEFAULT_TIMEOUT_SECONDS);
const [statusMessage, setStatusMessage] = useState<StatusMessage>(null);
const [isSubmitting, setIsSubmitting] = useState(false);
+ const [streamingField, setStreamingField] =
+ useState<AutomationSetupField | null>(null);
+ const streamQueueRef = useRef<
+ {
+ field: AutomationSetupField;
+ value: AutomationSetupFormValues[AutomationSetupField];
+ metadata?: NonNullable<
+ AutomationSetupDraft["fieldMetadata"]
+ >[AutomationSetupField];
+ }[]
+ >([]);
+ const isStreamProcessingRef = useRef(false);
+ const streamGenerationRef = useRef(0);
+ const streamTimeoutsRef = useRef<number[]>([]);
+ const processQueuedStreamsRef = useRef<() => void>(() => {});
+
+ const {
+ kind,
+ name,
+ prompt,
+ repository,
+ pluginSource,
+ pluginRef,
+ customCode,
+ entrypoint,
+ setupScriptPath,
+ setupScript,
+ triggerKind,
+ frequency,
+ time,
+ timezone,
+ customSchedule,
+ eventSource,
+ eventKey,
+ eventFilter,
+ showTimeout,
+ timeoutSeconds,
+ } = form;
+
+ const clearQueuedStreams = useCallback(() => {
+ streamGenerationRef.current += 1;
+ for (const timeoutId of streamTimeoutsRef.current) {
+ window.clearTimeout(timeoutId);
+ }
+ streamTimeoutsRef.current = [];
+ streamQueueRef.current = [];
+ isStreamProcessingRef.current = false;
+ setStreamingField(null);
+ }, []);
+
+ const scheduleStreamStep = useCallback(
+ (callback: () => void, delay: number, generation: number) => {
+ const timeoutId = window.setTimeout(() => {
+ streamTimeoutsRef.current = streamTimeoutsRef.current.filter(
+ (queuedTimeoutId) => queuedTimeoutId !== timeoutId,
+ );
+ if (generation !== streamGenerationRef.current) return;
+ callback();
+ }, delay);
+ streamTimeoutsRef.current.push(timeoutId);
+ },
+ [],
+ );
+
+ const finishCurrentStream = useCallback(
+ (
+ field: AutomationSetupField,
+ metadata:
+ | NonNullable<
+ AutomationSetupDraft["fieldMetadata"]
+ >[AutomationSetupField]
+ | undefined,
+ generation: number,
+ ) => {
+ if (metadata) {
+ setFieldMetadata((previous) => ({ ...previous, [field]: metadata }));
+ }
+ isStreamProcessingRef.current = false;
+ scheduleStreamStep(
+ () => processQueuedStreamsRef.current(),
+ AGENT_FIELD_STREAM_SETTLE_DELAY_MS,
+ generation,
+ );
+ },
+ [scheduleStreamStep],
+ );
+
+ const processQueuedStreams = useCallback(() => {
+ if (isStreamProcessingRef.current) return;
+ const nextStream = streamQueueRef.current.shift();
+ if (!nextStream) {
+ setStreamingField(null);
+ return;
+ }
+
+ const generation = streamGenerationRef.current;
+ isStreamProcessingRef.current = true;
+ setStreamingField(nextStream.field);
+
+ if (!shouldCharacterStreamField(nextStream.field, nextStream.value)) {
+ setForm((previous) => ({
+ ...previous,
+ [nextStream.field]: nextStream.value,
+ }));
+ finishCurrentStream(nextStream.field, nextStream.metadata, generation);
+ return;
+ }
+
+ const streamValue = nextStream.value;
+ setForm((previous) => ({ ...previous, [nextStream.field]: "" }));
+ let nextCharacterIndex = 0;
+ const streamNextCharacter = () => {
+ nextCharacterIndex += 1;
+ setForm((previous) => ({
+ ...previous,
+ [nextStream.field]: streamValue.slice(0, nextCharacterIndex),
+ }));
+ if (nextCharacterIndex < streamValue.length) {
+ scheduleStreamStep(
+ streamNextCharacter,
+ AGENT_FIELD_STREAM_CHARACTER_DELAY_MS,
+ generation,
+ );
+ return;
+ }
+ finishCurrentStream(nextStream.field, nextStream.metadata, generation);
+ };
+
+ scheduleStreamStep(
+ streamNextCharacter,
+ AGENT_FIELD_STREAM_CHARACTER_DELAY_MS,
+ generation,
+ );
+ }, [finishCurrentStream, scheduleStreamStep]);
+
+ processQueuedStreamsRef.current = processQueuedStreams;
+
+ useEffect(
+ () => () => {
+ clearQueuedStreams();
+ },
+ [clearQueuedStreams],
+ );
+
+ useEffect(() => {
+ if (!conversationId) return undefined;
+ initializeAutomationFormSession(conversationId, {
+ ...draft,
+ form,
+ fieldMetadata,
+ });
+ return () => clearAutomationFormSession(conversationId);
+ }, [conversationId]);
+
+ useEffect(() => {
+ if (!conversationId) return undefined;
+ return subscribeAutomationFormSession(
+ conversationId,
+ (nextDraft, result) => {
+ if (!nextDraft) return;
+ const nextForm = buildInitialForm(nextDraft);
+ const nextMetadata = nextDraft.fieldMetadata ?? {};
+ const agentFields = sortFieldsByRenderOrder(
+ (result?.applied ?? []).filter(
+ (field) => nextMetadata[field]?.updatedBy === "agent",
+ ),
+ );
+
+ if (agentFields.length === 0) {
+ clearQueuedStreams();
+ setForm(nextForm);
+ setFieldMetadata(nextMetadata);
+ return;
+ }
+
+ const protectedFields = new Set<AutomationSetupField>([
+ ...agentFields,
+ ...streamQueueRef.current.map((queuedStream) => queuedStream.field),
+ ...(streamingField ? [streamingField] : []),
+ ]);
+ setForm((previous) => {
+ const syncedForm = { ...nextForm };
+ for (const field of protectedFields) {
+ (syncedForm as Record<string, unknown>)[field] = previous[field];
+ }
+ return syncedForm;
+ });
+ setFieldMetadata((previous) => {
+ const syncedMetadata = { ...nextMetadata };
+ for (const field of agentFields) {
+ if (previous[field]) {
+ syncedMetadata[field] = previous[field];
+ } else {
+ delete syncedMetadata[field];
+ }
+ }
+ return syncedMetadata;
+ });
+ streamQueueRef.current.push(
+ ...agentFields.map((field) => ({
+ field,
+ value: nextForm[field],
+ metadata: nextMetadata[field],
+ })),
+ );
+ processQueuedStreamsRef.current();
+ },
+ );
+ }, [clearQueuedStreams, conversationId, streamingField]);
+
+ const updateField = <FieldName extends AutomationSetupField>(
+ field: FieldName,
+ value: AutomationSetupFormValues[FieldName],
+ ) => {
+ clearQueuedStreams();
+ setStatusMessage(null);
+ setForm((previous) => ({ ...previous, [field]: value }));
+ if (!conversationId) return;
+ patchAutomationFormSession(
+ conversationId,
+ { [field]: value } as AutomationSetupFormPatch,
+ { source: "user" },
+ );
+ };
+
+ const agentUpdatedSuffix = (field: AutomationSetupField) =>
+ fieldMetadata[field]?.updatedBy === "agent"
+ ? t(I18nKey.AUTOMATION_SETUP$FILLED_BY_OPENHANDS)
+ : undefined;
const normalizedName = () => name.trim() || deriveName(prompt);
const buildTrigger = () =>
@@ -422,12 +731,16 @@ export function AutomationSetupPanel({
)}
>
<div className="mx-auto flex w-full min-w-0 max-w-[800px] flex-col gap-6">
- <Field label={t(I18nKey.AUTOMATIONS$NAME)}>
+ <Field
+ label={t(I18nKey.AUTOMATIONS$NAME)}
+ suffix={agentUpdatedSuffix("name")}
+ isStreaming={streamingField === "name"}
+ >
<input
data-testid="automation-setup-name"
value={name}
placeholder={t(I18nKey.AUTOMATION_SETUP$NAME_PLACEHOLDER)}
- onChange={(event) => setName(event.target.value)}
+ onChange={(event) => updateField("name", event.target.value)}
className={formControlFieldClassName}
/>
</Field>
@@ -447,9 +760,13 @@ export function AutomationSetupPanel({
: "automation-setup-kind-custom"
}
onClick={() =>
- setKind(kind === "custom" ? "prompt" : "custom")
+ updateField("kind", kind === "custom" ? "prompt" : "custom")
}
- className={cn(addOptionButtonClassName, "ml-auto gap-1.5")}
+ className={cn(
+ addOptionButtonClassName,
+ "ml-auto gap-1.5",
+ streamingHighlightClassName(streamingField === "kind"),
+ )}
>
{kind === "custom" ? (
<FileText className="size-4" aria-hidden />
@@ -465,10 +782,14 @@ export function AutomationSetupPanel({
<AutomationSetupPromptStack
prompt={prompt}
repository={repository}
+ updatedSuffix={agentUpdatedSuffix("prompt")}
+ repositorySuffix={agentUpdatedSuffix("repository")}
showTitle={false}
- isStreaming={false}
- onPromptChange={setPrompt}
- onRepositoryChange={setRepository}
+ isStreaming={streamingField === "prompt"}
+ onPromptChange={(value) => updateField("prompt", value)}
+ onRepositoryChange={(value) =>
+ updateField("repository", value)
+ }
model={model}
onModelChange={setModel}
agentProfileId={agentProfileId}
@@ -480,10 +801,23 @@ export function AutomationSetupPanel({
entrypoint={entrypoint}
setupScriptPath={setupScriptPath}
setupScript={setupScript}
- onCodeChange={setCustomCode}
- onEntrypointChange={setEntrypoint}
- onSetupScriptPathChange={setSetupScriptPath}
- onSetupScriptChange={setSetupScript}
+ updatedSuffixes={{
+ customCode: agentUpdatedSuffix("customCode"),
+ entrypoint: agentUpdatedSuffix("entrypoint"),
+ setupScriptPath: agentUpdatedSuffix("setupScriptPath"),
+ setupScript: agentUpdatedSuffix("setupScript"),
+ }}
+ streamingField={streamingField}
+ onCodeChange={(value) => updateField("customCode", value)}
+ onEntrypointChange={(value) =>
+ updateField("entrypoint", value)
+ }
+ onSetupScriptPathChange={(value) =>
+ updateField("setupScriptPath", value)
+ }
+ onSetupScriptChange={(value) =>
+ updateField("setupScript", value)
+ }
/>
)}
</div>
@@ -492,21 +826,24 @@ export function AutomationSetupPanel({
<div
role="radiogroup"
aria-label={t(I18nKey.AUTOMATIONS$DETAIL$TRIGGER)}
- className="grid grid-cols-2 gap-2"
+ className={cn(
+ "grid grid-cols-2 gap-2",
+ streamingHighlightClassName(streamingField === "triggerKind"),
+ )}
>
<TriggerCard
icon={<CalendarDays className="size-4" aria-hidden />}
title={t(I18nKey.AUTOMATION_SETUP$SCHEDULE)}
description={t(I18nKey.AUTOMATION_SETUP$SCHEDULE_DESCRIPTION)}
selected={triggerKind === "cron"}
- onClick={() => setTriggerKind("cron")}
+ onClick={() => updateField("triggerKind", "cron")}
/>
<TriggerCard
icon={<Zap className="size-4" aria-hidden />}
title={t(I18nKey.AUTOMATIONS$DETAIL$TRIGGER_EVENT)}
description={t(I18nKey.AUTOMATION_SETUP$EVENT_DESCRIPTION)}
selected={triggerKind === "event"}
- onClick={() => setTriggerKind("event")}
+ onClick={() => updateField("triggerKind", "event")}
/>
</div>
</section>
@@ -517,19 +854,34 @@ export function AutomationSetupPanel({
time={time}
timezone={timezone}
customSchedule={customSchedule}
- setFrequency={setFrequency}
- setTime={setTime}
- setTimezone={setTimezone}
- setCustomSchedule={setCustomSchedule}
+ updatedSuffixes={{
+ frequency: agentUpdatedSuffix("frequency"),
+ time: agentUpdatedSuffix("time"),
+ timezone: agentUpdatedSuffix("timezone"),
+ customSchedule: agentUpdatedSuffix("customSchedule"),
+ }}
+ streamingField={streamingField}
+ setFrequency={(value) => updateField("frequency", value)}
+ setTime={(value) => updateField("time", value)}
+ setTimezone={(value) => updateField("timezone", value)}
+ setCustomSchedule={(value) =>
+ updateField("customSchedule", value)
+ }
/>
) : (
<EventFields
eventSource={eventSource}
eventKey={eventKey}
eventFilter={eventFilter}
- setEventSource={setEventSource}
- setEventKey={setEventKey}
- setEventFilter={setEventFilter}
+ updatedSuffixes={{
+ eventSource: agentUpdatedSuffix("eventSource"),
+ eventKey: agentUpdatedSuffix("eventKey"),
+ eventFilter: agentUpdatedSuffix("eventFilter"),
+ }}
+ streamingField={streamingField}
+ setEventSource={(value) => updateField("eventSource", value)}
+ setEventKey={(value) => updateField("eventKey", value)}
+ setEventFilter={(value) => updateField("eventFilter", value)}
/>
)}
@@ -544,7 +896,11 @@ export function AutomationSetupPanel({
>
<div className="flex min-w-0 items-end gap-2">
<div className="grid min-w-0 flex-1 gap-3 md:grid-cols-[2fr_1fr]">
- <Field label={t(I18nKey.AUTOMATION_SETUP$PLUGIN_SOURCE)}>
+ <Field
+ label={t(I18nKey.AUTOMATION_SETUP$PLUGIN_SOURCE)}
+ suffix={agentUpdatedSuffix("pluginSource")}
+ isStreaming={streamingField === "pluginSource"}
+ >
<input
data-testid="automation-setup-plugin-source"
value={pluginSource}
@@ -552,19 +908,25 @@ export function AutomationSetupPanel({
I18nKey.AUTOMATION_SETUP$PLUGIN_SOURCE_PLACEHOLDER,
)}
onChange={(event) =>
- setPluginSource(event.target.value)
+ updateField("pluginSource", event.target.value)
}
className={formControlFieldClassName}
/>
</Field>
- <Field label={t(I18nKey.AUTOMATION_SETUP$PLUGIN_REF)}>
+ <Field
+ label={t(I18nKey.AUTOMATION_SETUP$PLUGIN_REF)}
+ suffix={agentUpdatedSuffix("pluginRef")}
+ isStreaming={streamingField === "pluginRef"}
+ >
<input
data-testid="automation-setup-plugin-ref"
value={pluginRef}
placeholder={t(
I18nKey.AUTOMATION_SETUP$PLUGIN_REF_PLACEHOLDER,
)}
- onChange={(event) => setPluginRef(event.target.value)}
+ onChange={(event) =>
+ updateField("pluginRef", event.target.value)
+ }
className={formControlFieldClassName}
/>
</Field>
@@ -574,9 +936,9 @@ export function AutomationSetupPanel({
data-testid="automation-setup-plugin-remove"
aria-label={t(I18nKey.COMMON$REMOVE)}
onClick={() => {
- setPluginSource("");
- setPluginRef("");
- setKind("prompt");
+ updateField("pluginSource", "");
+ updateField("pluginRef", "");
+ updateField("kind", "prompt");
}}
className={cn(
"flex size-9 shrink-0 items-center justify-center rounded-lg border border-[var(--oh-border)] text-[var(--oh-muted)] hover:bg-white/5 hover:text-white",
@@ -591,14 +953,18 @@ export function AutomationSetupPanel({
{showTimeout ? (
<div className="flex min-w-0 items-end gap-2">
<div className="min-w-0 flex-1">
- <Field label={t(I18nKey.AUTOMATION_SETUP$TIMEOUT_SECONDS)}>
+ <Field
+ label={t(I18nKey.AUTOMATION_SETUP$TIMEOUT_SECONDS)}
+ suffix={agentUpdatedSuffix("timeoutSeconds")}
+ isStreaming={streamingField === "timeoutSeconds"}
+ >
<input
data-testid="automation-setup-timeout"
type="number"
min="1"
value={timeoutSeconds}
onChange={(event) =>
- setTimeoutSeconds(event.target.value)
+ updateField("timeoutSeconds", event.target.value)
}
className={formControlFieldClassName}
/>
@@ -608,7 +974,7 @@ export function AutomationSetupPanel({
type="button"
data-testid="automation-setup-timeout-remove"
aria-label={t(I18nKey.COMMON$REMOVE)}
- onClick={() => setShowTimeout(false)}
+ onClick={() => updateField("showTimeout", false)}
className={cn(
"flex size-9 shrink-0 items-center justify-center rounded-lg border border-[var(--oh-border)] text-[var(--oh-muted)] hover:bg-white/5 hover:text-white",
formControlTransitionClassName,
@@ -623,7 +989,7 @@ export function AutomationSetupPanel({
<button
type="button"
data-testid="automation-setup-add-plugin"
- onClick={() => setKind("plugin")}
+ onClick={() => updateField("kind", "plugin")}
className={cn(addOptionButtonClassName, "gap-1.5")}
>
<Plus className="size-4" aria-hidden />
@@ -634,8 +1000,14 @@ export function AutomationSetupPanel({
<button
type="button"
data-testid="automation-setup-add-timeout"
- onClick={() => setShowTimeout(true)}
- className={cn(addOptionButtonClassName, "gap-1.5")}
+ onClick={() => updateField("showTimeout", true)}
+ className={cn(
+ addOptionButtonClassName,
+ "gap-1.5",
+ streamingHighlightClassName(
+ streamingField === "showTimeout",
+ ),
+ )}
>
<Plus className="size-4" aria-hidden />
{t(I18nKey.AUTOMATION_SETUP$ADD_TIMEOUT)}
@@ -670,6 +1042,8 @@ function CustomCodeFields({
entrypoint,
setupScriptPath,
setupScript,
+ updatedSuffixes,
+ streamingField,
onCodeChange,
onEntrypointChange,
onSetupScriptPathChange,
@@ -679,6 +1053,13 @@ function CustomCodeFields({
entrypoint: string;
setupScriptPath: string;
setupScript: string;
+ updatedSuffixes: Partial<
+ Record<
+ "customCode" | "entrypoint" | "setupScriptPath" | "setupScript",
+ string | undefined
+ >
+ >;
+ streamingField: AutomationSetupField | null;
onCodeChange: (value: string) => void;
onEntrypointChange: (value: string) => void;
onSetupScriptPathChange: (value: string) => void;
@@ -688,7 +1069,11 @@ function CustomCodeFields({
return (
<div className="flex flex-col gap-4">
<div className="grid gap-3 md:grid-cols-[2fr_1fr]">
- <Field label={t(I18nKey.AUTOMATION_SETUP$ENTRYPOINT)}>
+ <Field
+ label={t(I18nKey.AUTOMATION_SETUP$ENTRYPOINT)}
+ suffix={updatedSuffixes.entrypoint}
+ isStreaming={streamingField === "entrypoint"}
+ >
<input
data-testid="automation-setup-entrypoint"
value={entrypoint}
@@ -696,7 +1081,11 @@ function CustomCodeFields({
className={formControlFieldClassName}
/>
</Field>
- <Field label={t(I18nKey.AUTOMATION_SETUP$SETUP_SCRIPT_PATH)}>
+ <Field
+ label={t(I18nKey.AUTOMATION_SETUP$SETUP_SCRIPT_PATH)}
+ suffix={updatedSuffixes.setupScriptPath}
+ isStreaming={streamingField === "setupScriptPath"}
+ >
<input
data-testid="automation-setup-setup-script-path"
value={setupScriptPath}
@@ -705,7 +1094,11 @@ function CustomCodeFields({
/>
</Field>
</div>
- <Field label={t(I18nKey.AUTOMATION_SETUP$PYTHON_CODE)}>
+ <Field
+ label={t(I18nKey.AUTOMATION_SETUP$PYTHON_CODE)}
+ suffix={updatedSuffixes.customCode}
+ isStreaming={streamingField === "customCode"}
+ >
<textarea
data-testid="automation-setup-custom-code"
rows={12}
@@ -718,7 +1111,11 @@ function CustomCodeFields({
)}
/>
</Field>
- <Field label={t(I18nKey.AUTOMATION_SETUP$SETUP_SCRIPT)}>
+ <Field
+ label={t(I18nKey.AUTOMATION_SETUP$SETUP_SCRIPT)}
+ suffix={updatedSuffixes.setupScript}
+ isStreaming={streamingField === "setupScript"}
+ >
<textarea
data-testid="automation-setup-setup-script"
rows={4}
@@ -740,6 +1137,8 @@ function ScheduleFields({
time,
timezone,
customSchedule,
+ updatedSuffixes,
+ streamingField,
setFrequency,
setTime,
setTimezone,
@@ -749,22 +1148,38 @@ function ScheduleFields({
time: string;
timezone: string;
customSchedule: string;
+ updatedSuffixes: Partial<
+ Record<
+ "frequency" | "time" | "timezone" | "customSchedule",
+ string | undefined
+ >
+ >;
+ streamingField: AutomationSetupField | null;
setFrequency: (value: Frequency) => void;
setTime: (value: string) => void;
setTimezone: (value: string) => void;
setCustomSchedule: (value: string) => void;
}) {
const { t } = useTranslation("openhands");
+ const atUpdatedSuffix = updatedSuffixes.time ?? updatedSuffixes.timezone;
return (
<section className="flex flex-col gap-2.5">
<div className="flex min-w-0 items-center gap-2">
<span className="shrink-0 text-sm">
{t(I18nKey.AUTOMATION_SETUP$FREQUENCY)}
</span>
+ {updatedSuffixes.frequency ? (
+ <span className="shrink-0 text-xs text-[var(--oh-muted)]">
+ {updatedSuffixes.frequency}
+ </span>
+ ) : null}
<div
role="radiogroup"
aria-label={t(I18nKey.AUTOMATION_SETUP$FREQUENCY)}
- className="inline-flex max-w-full min-w-0 items-center gap-0.5 overflow-x-auto rounded-lg bg-[var(--oh-surface-raised)] p-0.5"
+ className={cn(
+ "inline-flex max-w-full min-w-0 items-center gap-0.5 overflow-x-auto rounded-lg bg-[var(--oh-surface-raised)] p-0.5",
+ streamingHighlightClassName(streamingField === "frequency"),
+ )}
>
{FREQUENCIES.map((item) => (
<button
@@ -789,24 +1204,33 @@ function ScheduleFields({
</div>
<div className="flex w-full min-w-0 items-center gap-4 overflow-x-auto">
{frequency === "custom" ? (
- <label className="flex shrink-0 items-center gap-2.5">
- <span className="shrink-0 text-sm text-content">
- {t(I18nKey.AUTOMATION_SETUP$TYPE_CUSTOM)}
- </span>
+ <Field
+ label={t(I18nKey.AUTOMATION_SETUP$TYPE_CUSTOM)}
+ suffix={updatedSuffixes.customSchedule}
+ isStreaming={streamingField === "customSchedule"}
+ >
<input
data-testid="automation-setup-custom-schedule"
value={customSchedule}
onChange={(event) => setCustomSchedule(event.target.value)}
className={cn(formControlFieldClassName, "w-[14rem]")}
/>
- </label>
+ </Field>
) : (
<>
<label className="flex shrink-0 items-center gap-2.5">
<span className="shrink-0 text-sm text-content">
{t(I18nKey.AUTOMATION_SETUP$AT)}
</span>
- <div className="relative">
+ <div
+ data-streaming-active={
+ streamingField === "time" ? "true" : undefined
+ }
+ className={cn(
+ "relative",
+ streamingHighlightClassName(streamingField === "time"),
+ )}
+ >
<input
data-testid="automation-setup-time"
type="time"
@@ -816,8 +1240,17 @@ function ScheduleFields({
/>
</div>
</label>
- <div className="relative shrink-0">
+ <div
+ data-streaming-active={
+ streamingField === "timezone" ? "true" : undefined
+ }
+ className={cn(
+ "relative shrink-0",
+ streamingHighlightClassName(streamingField === "timezone"),
+ )}
+ >
<select
+ aria-label={t(I18nKey.AUTOMATIONS$TIMEZONE)}
data-testid="automation-setup-timezone"
value={timezone}
onChange={(event) => setTimezone(event.target.value)}
@@ -833,6 +1266,11 @@ function ScheduleFields({
aria-hidden
/>
</div>
+ {atUpdatedSuffix ? (
+ <span className="shrink-0 text-xs text-[var(--oh-muted)]">
+ {atUpdatedSuffix}
+ </span>
+ ) : null}
</>
)}
</div>
@@ -844,6 +1282,8 @@ function EventFields({
eventSource,
eventKey,
eventFilter,
+ updatedSuffixes,
+ streamingField,
setEventSource,
setEventKey,
setEventFilter,
@@ -851,6 +1291,10 @@ function EventFields({
eventSource: string;
eventKey: string;
eventFilter: string;
+ updatedSuffixes: Partial<
+ Record<"eventSource" | "eventKey" | "eventFilter", string | undefined>
+ >;
+ streamingField: AutomationSetupField | null;
setEventSource: (value: string) => void;
setEventKey: (value: string) => void;
setEventFilter: (value: string) => void;
@@ -858,7 +1302,11 @@ function EventFields({
const { t } = useTranslation("openhands");
return (
<section className="grid gap-3 md:grid-cols-2">
- <Field label={t(I18nKey.AUTOMATION_SETUP$EVENT_SOURCE)}>
+ <Field
+ label={t(I18nKey.AUTOMATION_SETUP$EVENT_SOURCE)}
+ suffix={updatedSuffixes.eventSource}
+ isStreaming={streamingField === "eventSource"}
+ >
<input
data-testid="automation-setup-event-source"
value={eventSource}
@@ -866,7 +1314,11 @@ function EventFields({
className={formControlFieldClassName}
/>
</Field>
- <Field label={t(I18nKey.AUTOMATION_SETUP$EVENT_KEY)}>
+ <Field
+ label={t(I18nKey.AUTOMATION_SETUP$EVENT_KEY)}
+ suffix={updatedSuffixes.eventKey}
+ isStreaming={streamingField === "eventKey"}
+ >
<input
data-testid="automation-setup-event-key"
value={eventKey}
@@ -877,7 +1329,8 @@ function EventFields({
<div className="md:col-span-2">
<Field
label={t(I18nKey.AUTOMATION_SETUP$EVENT_FILTER)}
- suffix={t(I18nKey.COMMON$OPTIONAL)}
+ suffix={updatedSuffixes.eventFilter ?? t(I18nKey.COMMON$OPTIONAL)}
+ isStreaming={streamingField === "eventFilter"}
>
<input
data-testid="automation-setup-event-filter"
@@ -895,16 +1348,23 @@ function Field({
label,
suffix,
horizontal = false,
+ isStreaming = false,
children,
}: {
label: string;
suffix?: string;
horizontal?: boolean;
+ isStreaming?: boolean;
children: ReactNode;
}) {
return (
<label
- className={cn("flex gap-2", horizontal ? "items-center" : "flex-col")}
+ data-streaming-active={isStreaming ? "true" : undefined}
+ className={cn(
+ "flex gap-2",
+ horizontal ? "items-center" : "flex-col",
+ streamingHighlightClassName(isStreaming),
+ )}
>
<span className="flex items-center gap-2 text-sm font-semibold text-white">
{label}
diff --git a/src/components/features/conversation/conversation-main/conversation-main.tsx b/src/components/features/conversation/conversation-main/conversation-main.tsx
index dfa0002f92..da18b05d4b 100644
--- a/src/components/features/conversation/conversation-main/conversation-main.tsx
+++ b/src/components/features/conversation/conversation-main/conversation-main.tsx
@@ -368,6 +368,7 @@ export function ConversationMain() {
>
<AutomationSetupPanel
draft={automationSetupDraft}
+ conversationId={conversationId}
toolbarPortal={automationToolbarElement}
showInlineHeader={false}
reserveComposerSpace
@@ -404,6 +405,7 @@ export function ConversationMain() {
{automationSetupDraft ? (
<AutomationSetupPanel
draft={automationSetupDraft}
+ conversationId={conversationId}
toolbarPortal={automationToolbarElement}
showInlineHeader={false}
reserveComposerSpace={showDockedComposer}
diff --git a/src/components/features/home/home-chat-launcher.tsx b/src/components/features/home/home-chat-launcher.tsx
index e27374dadf..a3efc68c37 100644
--- a/src/components/features/home/home-chat-launcher.tsx
+++ b/src/components/features/home/home-chat-launcher.tsx
@@ -68,7 +68,9 @@ export function HomeChatLauncher() {
const [selectedPlugins, setSelectedPlugins] = useState<PluginSpec[]>([]);
const [isPluginPickerOpen, setIsPluginPickerOpen] = useState(false);
const [launcherMode, setLauncherMode] = useState<HomeLauncherMode>("code");
+ const displayedLauncherMode = launcherMode;
const isAutomateMode = launcherMode === "automate";
+ const handleLauncherModeChange = setLauncherMode;
const isMountedRef = useRef(true);
useEffect(() => {
@@ -137,6 +139,7 @@ export function HomeChatLauncher() {
// query here would create a duplicate text-only initial_message.
let variables: Parameters<typeof createConversation>[0] = {
query: hasAttachments ? undefined : trimmed || undefined,
+ automationSetup: isAutomateMode,
entryPoint: "home_chat_launcher",
};
// An isolated backend owns its workspace, so a host selection left over
@@ -292,8 +295,8 @@ export function HomeChatLauncher() {
<div className="flex w-full justify-center">
<HomeLauncherModeToggle
- mode={launcherMode}
- onChange={setLauncherMode}
+ mode={displayedLauncherMode}
+ onChange={handleLauncherModeChange}
/>
</div>
diff --git a/src/constants/automation-form.ts b/src/constants/automation-form.ts
new file mode 100644
index 0000000000..6e3a568d59
--- /dev/null
+++ b/src/constants/automation-form.ts
@@ -0,0 +1,8 @@
+export const AUTOMATION_FORM_UPDATE_TOOL_NAME = "automation_form_update";
+
+/**
+ * Action discriminator generated by the SDK for the client-defined automation
+ * form tool (`ClientAction_<tool-name>`). Keep this convention centralized.
+ */
+export const AUTOMATION_FORM_UPDATE_ACTION_KIND =
+ `ClientAction_${AUTOMATION_FORM_UPDATE_TOOL_NAME}` as const;
diff --git a/src/contexts/conversation-websocket-context.tsx b/src/contexts/conversation-websocket-context.tsx
index 32f2ca50e8..770c837a0e 100644
--- a/src/contexts/conversation-websocket-context.tsx
+++ b/src/contexts/conversation-websocket-context.tsx
@@ -40,6 +40,7 @@ import {
isSwitchLLMObservationEvent,
isClassifyAndSwitchLLMObservationEvent,
isCanvasUIActionEvent,
+ isAutomationFormUpdateActionEvent,
isLaunchChildConversationActionEvent,
} from "#/types/agent-server/type-guards";
import {
@@ -51,6 +52,7 @@ import {
StreamingDeltaBatcher,
} from "#/utils/streaming-delta-batcher";
import { handleCanvasUIAction } from "#/services/canvas-ui";
+import { handleAutomationFormUpdateAction } from "#/services/automation-form";
import { handleLaunchChildConversationAction } from "#/services/child-conversation-launch";
import { ConversationStateUpdateEventStats } from "#/types/agent-server/core/events/conversation-state-event";
import type {
@@ -849,6 +851,15 @@ export function ConversationWebSocketProvider({
handleCanvasUIAction(event.action, conversationId ?? null);
}
+ if (isAutomationFormUpdateActionEvent(event)) {
+ handleAutomationFormUpdateAction(
+ event.action,
+ conversationId ?? null,
+ event.id,
+ event.timestamp,
+ );
+ }
+
// Same client-tool pattern, but the work is a network call: launch
// the requested child conversation and post the outcome back so the
// agent learns the id the server-side acknowledgement can't carry.
diff --git a/src/hooks/mutation/use-create-conversation.ts b/src/hooks/mutation/use-create-conversation.ts
index 25a3eab79c..ca2bf2a62d 100644
--- a/src/hooks/mutation/use-create-conversation.ts
+++ b/src/hooks/mutation/use-create-conversation.ts
@@ -33,6 +33,7 @@ import {
export interface CreateConversationVariables {
query?: string;
+ automationSetup?: boolean;
repository?: {
name: string;
gitProvider: Provider;
@@ -104,6 +105,7 @@ export const useCreateConversation = ({
): Promise<CreateConversationResponse> => {
const {
query,
+ automationSetup,
conversationInstructions,
plugins,
repository,
@@ -281,6 +283,7 @@ export const useCreateConversation = ({
const conversation =
await AgentServerConversationService.createConversation({
initialUserMsg: query,
+ automationSetup,
conversationInstructions,
plugins,
metadata: repository
diff --git a/src/i18n/translation.json b/src/i18n/translation.json
index b22984b6be..4c586496b1 100644
--- a/src/i18n/translation.json
+++ b/src/i18n/translation.json
@@ -46493,5 +46493,22 @@
"uk": "Custom Python",
"zh-CN": "Custom Python",
"zh-TW": "Custom Python"
+ },
+ "AUTOMATION_SETUP$FILLED_BY_OPENHANDS": {
+ "en": "✦ Filled by OpenHands",
+ "ja": "✦ OpenHands が入力",
+ "zh-CN": "✦ 由 OpenHands 填写",
+ "zh-TW": "✦ 由 OpenHands 填寫",
+ "ko-KR": "✦ OpenHands가 채움",
+ "no": "✦ Fylt ut av OpenHands",
+ "it": "✦ Compilato da OpenHands",
+ "pt": "✦ Preenchido pelo OpenHands",
+ "es": "✦ Rellenado por OpenHands",
+ "ar": "✦ تم ملؤه بواسطة OpenHands",
+ "fr": "✦ Rempli par OpenHands",
+ "tr": "✦ OpenHands tarafından dolduruldu",
+ "de": "✦ Von OpenHands ausgefüllt",
+ "uk": "✦ Заповнено OpenHands",
+ "ca": "✦ Emplenat per OpenHands"
}
}
diff --git a/src/services/automation-form.ts b/src/services/automation-form.ts
new file mode 100644
index 0000000000..62a969d553
--- /dev/null
+++ b/src/services/automation-form.ts
@@ -0,0 +1,28 @@
+import { patchAutomationFormSession } from "#/api/automation-form-session";
+import type {
+ AutomationSetupFormPatch,
+ AutomationSetupPatchResult,
+} from "#/api/automation-setup-types";
+import type { AutomationFormUpdateAction } from "#/types/agent-server/core";
+
+export function handleAutomationFormUpdateAction(
+ action: AutomationFormUpdateAction,
+ conversationId: string | null,
+ eventId?: string | null,
+ timestamp?: string,
+): AutomationSetupPatchResult {
+ if (!conversationId) {
+ return { applied: [], skipped: [], duplicate: false };
+ }
+
+ return patchAutomationFormSession(
+ conversationId,
+ action.fields as AutomationSetupFormPatch,
+ {
+ source: "agent",
+ overwriteUserEdits: action.overwrite_user_edits === true,
+ eventId,
+ updatedAt: timestamp,
+ },
+ );
+}
diff --git a/src/types/agent-server/core/base/action.ts b/src/types/agent-server/core/base/action.ts
index 60a502db03..52b4c03c81 100644
--- a/src/types/agent-server/core/base/action.ts
+++ b/src/types/agent-server/core/base/action.ts
@@ -1,3 +1,4 @@
+import { AUTOMATION_FORM_UPDATE_ACTION_KIND } from "#/constants/automation-form";
import { CANVAS_UI_CLIENT_ACTION_KIND } from "#/constants/canvas-ui";
import { LAUNCH_CHILD_CONVERSATION_ACTION_KIND } from "#/constants/child-conversation";
import { ActionBase } from "./base";
@@ -322,6 +323,18 @@ export interface CanvasUIAction extends ActionBase<
tab?: string | null;
}
+/**
+ * Request to patch the active automation setup form from an agent tool call.
+ * The concrete fields are normalized by the draft store because the SDK only
+ * validates the JSON schema at the client-tool boundary.
+ */
+export interface AutomationFormUpdateAction extends ActionBase<
+ typeof AUTOMATION_FORM_UPDATE_ACTION_KIND
+> {
+ fields: Record<string, unknown>;
+ overwrite_user_edits?: boolean | null;
+}
+
/**
* Request to launch a child conversation, emitted over the existing WebSocket
* and intercepted by handleLaunchChildConversationAction. The agent-server
@@ -366,4 +379,5 @@ export type Action =
| TaskAction
| SwitchLLMAction
| CanvasUIAction
+ | AutomationFormUpdateAction
| LaunchChildConversationAction;
diff --git a/src/types/agent-server/core/base/base.ts b/src/types/agent-server/core/base/base.ts
index d75cb66b0b..3a90a2e411 100644
--- a/src/types/agent-server/core/base/base.ts
+++ b/src/types/agent-server/core/base/base.ts
@@ -1,3 +1,4 @@
+import { AUTOMATION_FORM_UPDATE_ACTION_KIND } from "#/constants/automation-form";
import { CANVAS_UI_CLIENT_ACTION_KIND } from "#/constants/canvas-ui";
import { LAUNCH_CHILD_CONVERSATION_ACTION_KIND } from "#/constants/child-conversation";
@@ -40,6 +41,7 @@ type ActionEventType =
// The `task` tool delegating work to a spawned subagent.
| "TaskAction"
| typeof CANVAS_UI_CLIENT_ACTION_KIND
+ | typeof AUTOMATION_FORM_UPDATE_ACTION_KIND
| typeof LAUNCH_CHILD_CONVERSATION_ACTION_KIND;
type ObservationEventType =
| `${ObservationOnlyType}Observation`
diff --git a/src/types/agent-server/type-guards.ts b/src/types/agent-server/type-guards.ts
index 9d7ea70326..d709e01ecf 100644
--- a/src/types/agent-server/type-guards.ts
+++ b/src/types/agent-server/type-guards.ts
@@ -1,3 +1,4 @@
+import { AUTOMATION_FORM_UPDATE_TOOL_NAME } from "#/constants/automation-form";
import {
CANVAS_UI_CLIENT_TOOL_NAME,
LEGACY_CANVAS_UI_TOOL_NAME,
@@ -17,6 +18,7 @@ import {
BrowserNavigateAction,
SwitchLLMObservation,
ClassifyAndSwitchLLMObservation,
+ AutomationFormUpdateAction,
CanvasUIAction,
LaunchChildConversationAction,
} from "./core";
@@ -198,6 +200,11 @@ export const isCanvasUIActionEvent = (
(event.tool_name === LEGACY_CANVAS_UI_TOOL_NAME ||
event.tool_name === CANVAS_UI_CLIENT_TOOL_NAME);
+export const isAutomationFormUpdateActionEvent = (
+ event: OpenHandsEvent,
+): event is ActionEvent<AutomationFormUpdateAction> =>
+ isActionEvent(event) && event.tool_name === AUTOMATION_FORM_UPDATE_TOOL_NAME;
+
/**
* Type guard for launch-child-conversation tool ActionEvents.
*
diff --git a/src/utils/automation-draft-tags.ts b/src/utils/automation-draft-tags.ts
new file mode 100644
index 0000000000..43374db127
--- /dev/null
+++ b/src/utils/automation-draft-tags.ts
@@ -0,0 +1,11 @@
+export const AUTOMATION_SETUP_TAG_KEY = "automationsetup";
+export const AUTOMATION_SETUP_TAG_VALUE = "draft";
+
+export function buildAutomationSetupModeTags(
+ tags: Record<string, string> | null | undefined,
+): Record<string, string> {
+ return {
+ ...(tags ?? {}),
+ [AUTOMATION_SETUP_TAG_KEY]: AUTOMATION_SETUP_TAG_VALUE,
+ };
+}