🙌 OpenHands: AI-Driven Development
fix(automations): hide agent profiles for preset actions (#17971)
Qingsong Li72b48b71b01d
diff --git a/__tests__/components/manifest/manifest-setup-dialog.test.tsx b/__tests__/components/manifest/manifest-setup-dialog.test.tsxindex 974d60a461..774980f131 100644--- a/__tests__/components/manifest/manifest-setup-dialog.test.tsx+++ b/__tests__/components/manifest/manifest-setup-dialog.test.tsx@@ -1,4 +1,5 @@import { QueryClient, QueryClientProvider } from "@tanstack/react-query";+import { AUTOMATION_CATALOG } from "@openhands/extensions/automations";import { render, screen, waitFor } from "@testing-library/react";import userEvent from "@testing-library/user-event";import { beforeEach, describe, expect, it, vi } from "vitest";@@ -95,6 +96,9 @@ const NOTHING_TO_CONNECT: SetupPrerequisitesResult = {};const ENTRY: SetupEntry = createSetupEntry();+const CUSTOM_AUTOMATION_ENTRY = AUTOMATION_CATALOG.find(+ (entry) => entry.id === "custom-automation",+) as SetupEntry;function renderDialog(entry: SetupEntry = ENTRY) {const user = userEvent.setup();@@ -191,6 +195,12 @@ const CRON_ONLY_CAPABILITIES: DeploymentCapabilities = {features: [],};+const ACTION_CAPABILITIES: DeploymentCapabilities = {+ ...CRON_ONLY_CAPABILITIES,+ triggerKinds: ["cron", "event"],+ features: ["agentProfiles", "presetPrompt", "presetPlugin", "customTarball"],+};+const EVENT_FIRST_MIXED_TRIGGER_ENTRY: SetupEntry = (() => {const { form } = createSetup();return createSetupEntry({@@ -250,6 +260,43 @@ const LLM_PROFILE_ENTRY: SetupEntry = (() => {})();describe("SetupDialog", () => {+ it("offers agent profiles only for actions that accept them", async () => {+ mocks.capabilities.mockReturnValue({+ capabilities: ACTION_CAPABILITIES,+ supported: true,+ unmet: [],+ isLoading: false,+ });+ const { user } = renderDialog(CUSTOM_AUTOMATION_ENTRY);++ await waitFor(() =>+ expect(screen.getByTestId("setup-action-kind")).toBeInTheDocument(),+ );+ expect(+ screen.queryByTestId("automation-agent-profile"),+ ).not.toBeInTheDocument();++ await user.click(screen.getByTestId("setup-action-kind"));+ await user.click(await screen.findByText("Upload tarball"));+ await waitFor(() =>+ expect(+ screen.getByTestId("automation-agent-profile"),+ ).toBeInTheDocument(),+ );++ await user.click(screen.getByTestId("automation-agent-profile"));+ await user.click(await screen.findByText("Reviewer"));+ await user.click(screen.getByTestId("setup-action-kind"));+ await user.click(await screen.findByText("Prompt"));++ await waitFor(() => {+ expect(+ screen.queryByTestId("automation-agent-profile"),+ ).not.toBeInTheDocument();+ expect(screen.getByTestId("setup-field-model")).toBeInTheDocument();+ });+ });+it("asks about an unconnected integration before it asks anything else", async () => {// Arrange — an advisory integration, which is shown but does not block.mocks.prerequisites.mockReturnValue({diff --git a/src/components/features/manifest/manifest-setup-dialog.tsx b/src/components/features/manifest/manifest-setup-dialog.tsxindex 1151631d37..afd893c516 100644--- a/src/components/features/manifest/manifest-setup-dialog.tsx+++ b/src/components/features/manifest/manifest-setup-dialog.tsx@@ -25,6 +25,7 @@ import {buildCreatePayload,deriveErrorMap,missingCreateEndpoints,+ supportsAgentProfile,} from "#/manifests/automation-setup";import {actionKinds,@@ -173,6 +174,9 @@ export function SetupDialog({ entry, onClose }: SetupDialogProps) {),): fields;+ const canSelectAgentProfile =+ capabilities.capabilities?.features.includes("agentProfiles") === true &&+ supportsAgentProfile(entry, selectedAction);const hasLlmProfileField = useMemo(() => Object.values(fields).some((field) => field.type === "llm-profile"),[fields],@@ -269,7 +273,11 @@ export function SetupDialog({ entry, onClose }: SetupDialogProps) {const setActionValue = (kind: string) => {setSelectedAction(kind);const defaults = getInitialFormValues(entry.setup, selectedTrigger, kind);- valuesRef.current = { ...defaults, ...valuesRef.current };+ valuesRef.current = {+ ...defaults,+ ...valuesRef.current,+ ...(supportsAgentProfile(entry, kind) ? {} : { agent_profile_id: "" }),+ };setValues(valuesRef.current);setLocalErrors({});setServiceErrors(NO_SERVICE_ERRORS);@@ -535,9 +543,7 @@ export function SetupDialog({ entry, onClose }: SetupDialogProps) {</p></div>)}- {capabilities.capabilities?.features.includes(- "agentProfiles",- ) && (+ {canSelectAgentProfile && (<AutomationAgentProfileSelectorvalue={typeof values.agent_profile_id === "string"diff --git a/src/manifests/automation-setup.test.ts b/src/manifests/automation-setup.test.tsindex dd6e41ba1b..c7be253f0e 100644--- a/src/manifests/automation-setup.test.ts+++ b/src/manifests/automation-setup.test.ts@@ -1,7 +1,11 @@import { AUTOMATION_CATALOG } from "@openhands/extensions/automations";import customAutomationFixture from "@openhands/extensions/testing/automations/custom-automation.json";import { describe, expect, it } from "vitest";-import { buildCreatePayload, buildPreflightBody } from "./automation-setup";+import {+ buildCreatePayload,+ buildPreflightBody,+ supportsAgentProfile,+} from "./automation-setup";import type { SetupEntry, SetupFormValues, SetupRequestBody } from "./types";import { validateSetupEntry } from "./manifest-validation";@@ -10,7 +14,7 @@ const customAutomation = AUTOMATION_CATALOG.find() as SetupEntry | undefined;describe("custom automation setup actions", () => {- it("uses the selected agent profile instead of a second model authority", () => {+ it("does not send an agent profile to the prompt endpoint", () => {const scenario = customAutomationFixture.scenarios[0];const values = {...scenario.formValues,@@ -24,8 +28,34 @@ describe("custom automation setup actions", () => {scenario.selectedTrigger,scenario.selectedAction,);+ expect(payload).not.toHaveProperty("agent_profile_id");+ expect(payload?.model).toBe(values.model);+ expect(+ supportsAgentProfile(customAutomation!, scenario.selectedAction),+ ).toBe(false);+ });++ it("uses the selected agent profile for the raw upload endpoint", () => {+ const scenario = customAutomationFixture.scenarios.find(+ (candidate) => candidate.selectedAction === "upload",+ );+ expect(scenario).toBeDefined();+ const values = {+ ...scenario!.formValues,+ agent_profile_id: "11111111-1111-4111-8111-111111111111",+ } as unknown as SetupFormValues;+ const payload = buildCreatePayload(+ customAutomation!,+ values,+ undefined,+ scenario!.selectedTrigger,+ scenario!.selectedAction,+ );expect(payload?.agent_profile_id).toBe(values.agent_profile_id);expect(payload).not.toHaveProperty("model");+ expect(+ supportsAgentProfile(customAutomation!, scenario!.selectedAction),+ ).toBe(true);});it("admits the custom automation action manifest", () => {expect(customAutomation).toBeDefined();diff --git a/src/manifests/automation-setup.ts b/src/manifests/automation-setup.tsindex 9026ba5ebf..c4c0a912d9 100644--- a/src/manifests/automation-setup.ts+++ b/src/manifests/automation-setup.ts@@ -141,6 +141,15 @@ export function selectedActionKind(return "prompt";}+/** 判断当前创建端点是否接受 Agent profile。 */+export function supportsAgentProfile(+ entry: SetupEntry,+ selectedAction?: string | null,+): boolean {+ const kind = selectedActionKind(entry, selectedAction);+ return kind === "upload" || kind === "bundle";+}+/*** The `tarball_path` a preflight draft carries.*@@ -272,10 +281,14 @@ function optionalCreateProperties(setup: SetupBlock,values: SetupFormValues,selectedAction?: string | null,+ includeAgentProfile = false,): SetupRequestBody {return Object.fromEntries(OPTIONAL_CREATE_PROPERTIES.flatMap((name) => {- if (name === "model" && values.agent_profile_id) return [];+ if (name === "agent_profile_id" && !includeAgentProfile) return [];+ if (name === "model" && includeAgentProfile && values.agent_profile_id) {+ return [];+ }const field = collectFields(setup, null, selectedAction)[name];const value = fieldPayloadValue(field?.type, values[name]);return hasPayloadValue(value) ? [[name, value]] : [];@@ -416,7 +429,12 @@ function buildActionPayload(Object.assign(payload,- optionalCreateProperties(setup, values, selectedActionKey),+ optionalCreateProperties(+ setup,+ values,+ selectedActionKey,+ kind === "upload",+ ),);if (kind === "upload") {@@ -557,7 +575,7 @@ function buildBundlePayload(const payload: SetupRequestBody = {name: deriveName(entry, values),- ...optionalCreateProperties(entry.setup, values),+ ...optionalCreateProperties(entry.setup, values, undefined, true),};const trigger = buildTrigger(entry, values, selectedTrigger);