AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(frontend): let users enter host-scoped and username/password credentials (#14679)
Reinier van der Leera1a716db631f
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/OnboardingWelcomeDialog/ConnectToolsPanel.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/OnboardingWelcomeDialog/ConnectToolsPanel.tsxindex fe1e42c4e4..ca32713b9a 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/OnboardingWelcomeDialog/ConnectToolsPanel.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/OnboardingWelcomeDialog/ConnectToolsPanel.tsx@@ -105,7 +105,7 @@ export function ConnectToolsPanel({ onBack, onNext }: Props) {// Without this, approving on the phone drops the user back on// the initial "Connect <provider>" screen, which reads as a// failure. OAuth and API key both return to the list.- onDeviceAuthSuccess={handleBackToList}+ onInlineConnectSuccess={handleBackToList}/></motion.div>) : (diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/OnboardingWelcomeDialog/__tests__/connect-flow.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/OnboardingWelcomeDialog/__tests__/connect-flow.test.tsxindex 2b807da96e..6c696594c8 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/OnboardingWelcomeDialog/__tests__/connect-flow.test.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/OnboardingWelcomeDialog/__tests__/connect-flow.test.tsx@@ -61,6 +61,11 @@ const REGISTRY = [description: "Mail relay",supported_auth_types: ["user_password"],},+ {+ name: "http",+ description: "Generic HTTP requests",+ supported_auth_types: ["host_scoped"],+ },];function stubPanel({@@ -169,7 +174,7 @@ describe("ConnectToolsPanel — picking a provider", () => {).toBeNull();});- it("offers no Continue for a method the dialog cannot drive", async () => {+ it("expands the user/password form in place, with no footer Continue", async () => {stubPanel();renderPanel();@@ -181,9 +186,12 @@ describe("ConnectToolsPanel — picking a provider", () => {screen.getByRole("button", { name: /Username & password/ }),);+ expect(await screen.findByLabelText("Username")).toBeDefined();expect(- await screen.findByText("No connection method available"),+ screen.getByLabelText("Password", { selector: "input" }),).toBeDefined();+ expect(screen.queryByText("No connection method available")).toBeNull();+ // The card submits itself, so the footer's Continue stays away.expect(screen.queryByRole("button", { name: "Continue" })).toBeNull();});@@ -218,6 +226,179 @@ describe("ConnectToolsPanel — picking a provider", () => {});});+describe("ConnectToolsPanel — inline host-scoped flow", () => {+ async function openHttpHostCard() {+ stubPanel({ recommended: ["github", "smtp", "http"] });+ renderPanel();++ const user = userEvent.setup();+ await user.click(await screen.findByRole("button", { name: /Http/ }));+ await screen.findByRole("heading", { name: "Connect AutoGPT to Http" });+ await user.click(screen.getByRole("button", { name: /^Website access/ }));+ return user;+ }++ it("expands the host form in place instead of the unsupported notice", async () => {+ const user = await openHttpHostCard();++ expect(await screen.findByLabelText("Host")).toBeDefined();+ expect(screen.getByLabelText("Header name")).toBeDefined();+ expect(screen.getByLabelText("Header value")).toBeDefined();+ expect(screen.queryByText("No connection method available")).toBeNull();+ // No block is in scope here, so the field says what to type rather than+ // presenting an unexplained empty box.+ expect(+ screen.getByText("The host of the URL this block will call."),+ ).toBeDefined();+ expect(screen.getByLabelText("Host")).toHaveProperty("readOnly", false);+ // The card submits itself, so the footer's Continue stays away.+ expect(screen.queryByRole("button", { name: "Continue" })).toBeNull();++ expect(screen.getByRole("button", { name: "Connect" })).toHaveProperty(+ "disabled",+ true,+ );++ // A host with no headers saves a credential that adds nothing to a+ // request, so the host alone must not be enough.+ await user.type(screen.getByLabelText("Host"), "api.example.com");+ await waitFor(() =>+ expect(screen.getByRole("button", { name: "Connect" })).toHaveProperty(+ "disabled",+ true,+ ),+ );++ await user.type(screen.getByLabelText("Header name"), "Authorization");+ await user.type(screen.getByLabelText("Header value"), "<test-token>");++ await waitFor(() =>+ expect(screen.getByRole("button", { name: "Connect" })).toHaveProperty(+ "disabled",+ false,+ ),+ );+ });++ it("rejects a full URL where the host belongs", async () => {+ const user = await openHttpHostCard();++ await user.type(+ await screen.findByLabelText("Host"),+ "https://api.example.com",+ );+ await user.type(screen.getByLabelText("Header name"), "Authorization");+ await user.type(screen.getByLabelText("Header value"), "<test-token>");++ expect(+ await screen.findByText(+ "Enter only the host (e.g. api.example.com), not a full URL",+ ),+ ).toBeDefined();+ expect(screen.getByRole("button", { name: "Connect" })).toHaveProperty(+ "disabled",+ true,+ );+ });++ it("posts the host and its headers to the picked provider", async () => {+ const requests: { provider: string; body: unknown }[] = [];+ server.use(+ http.post(CREATE_CREDENTIALS_URL, async ({ params, request }) => {+ requests.push({+ provider: String(params.provider),+ body: await request.json(),+ });+ return HttpResponse.json(+ {+ id: "cred-http",+ provider: "http",+ type: "host_scoped",+ title: "api.example.com",+ scopes: null,+ username: null,+ },+ { status: 201 },+ );+ }),+ );++ const user = await openHttpHostCard();+ await user.type(await screen.findByLabelText("Host"), "api.example.com");+ await user.type(screen.getByLabelText("Header name"), "Authorization");+ await user.type(screen.getByLabelText("Header value"), "<test-token>");++ await user.click(screen.getByRole("button", { name: "Connect" }));++ await waitFor(() => expect(requests).toHaveLength(1));+ expect(requests[0].provider).toBe("http");+ expect(requests[0].body).toMatchObject({+ provider: "http",+ type: "host_scoped",+ title: "api.example.com",+ host: "api.example.com",+ headers: { Authorization: "<test-token>" },+ });+ expect(toastSpy).toHaveBeenCalledWith({+ title: "Host credentials saved",+ variant: "success",+ });+ });+});++describe("ConnectToolsPanel — inline user/password flow", () => {+ it("posts the username and password to the picked provider", async () => {+ stubPanel();+ const requests: { provider: string; body: unknown }[] = [];+ server.use(+ http.post(CREATE_CREDENTIALS_URL, async ({ params, request }) => {+ requests.push({+ provider: String(params.provider),+ body: await request.json(),+ });+ return HttpResponse.json(+ {+ id: "cred-smtp",+ provider: "smtp",+ type: "user_password",+ title: "Mail relay",+ scopes: null,+ username: "postmaster",+ },+ { status: 201 },+ );+ }),+ );++ renderPanel();+ const user = userEvent.setup();+ await user.click(await screen.findByRole("button", { name: /Smtp/ }));+ await screen.findByRole("heading", { name: "Connect AutoGPT to Smtp" });+ await user.click(+ screen.getByRole("button", { name: /Username & password/ }),+ );++ await user.type(await screen.findByLabelText("Name"), "Mail relay");+ await user.type(screen.getByLabelText("Username"), "postmaster");+ await user.type(+ screen.getByLabelText("Password", { selector: "input" }),+ "<test-password>",+ );++ await user.click(screen.getByRole("button", { name: "Connect" }));++ await waitFor(() => expect(requests).toHaveLength(1));+ expect(requests[0].provider).toBe("smtp");+ expect(requests[0].body).toMatchObject({+ provider: "smtp",+ type: "user_password",+ title: "Mail relay",+ username: "postmaster",+ password: "<test-password>",+ });+ });+});+describe("ConnectToolsPanel — inline API key flow", () => {it("expands the key form in place and gates Continue on a valid form", async () => {stubPanel();diff --git a/autogpt_platform/frontend/src/app/(platform)/team/[expertId]/components/ExpertIntegrationsSection/ExpertConnectServiceDialog.tsx b/autogpt_platform/frontend/src/app/(platform)/team/[expertId]/components/ExpertIntegrationsSection/ExpertConnectServiceDialog.tsxindex 366ca29aea..af4bf72acc 100644--- a/autogpt_platform/frontend/src/app/(platform)/team/[expertId]/components/ExpertIntegrationsSection/ExpertConnectServiceDialog.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/team/[expertId]/components/ExpertIntegrationsSection/ExpertConnectServiceDialog.tsx@@ -121,7 +121,7 @@ export function ExpertConnectServiceDialog({onSelectMethod={setSelectedMethod}apiKeyForm={apiKeyForm}onApiKeySubmit={handleApiKeySubmit}- onDeviceAuthSuccess={handleSuccess}+ onInlineConnectSuccess={handleSuccess}/></motion.div>) : (diff --git a/autogpt_platform/frontend/src/components/contextual/CredentialsInput/CredentialsInput.tsx b/autogpt_platform/frontend/src/components/contextual/CredentialsInput/CredentialsInput.tsxindex 72557434fd..f5c0709f3c 100644--- a/autogpt_platform/frontend/src/components/contextual/CredentialsInput/CredentialsInput.tsx+++ b/autogpt_platform/frontend/src/components/contextual/CredentialsInput/CredentialsInput.tsx@@ -153,6 +153,7 @@ export function CredentialsInput({schema={schema}provider={provider}displayName={displayName}+ siblingInputs={siblingInputs}open={isConnectDialogOpen}onClose={() => setConnectDialogOpen(false)}/>diff --git a/autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/ConnectCredentialDialog/ConnectCredentialDialog.tsx b/autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/ConnectCredentialDialog/ConnectCredentialDialog.tsxindex 3841128177..7c77b21a64 100644--- a/autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/ConnectCredentialDialog/ConnectCredentialDialog.tsx+++ b/autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/ConnectCredentialDialog/ConnectCredentialDialog.tsx@@ -9,6 +9,8 @@ import {type ConnectableProvider,} from "@/components/contextual/IntegrationsPanel/components/ConnectServiceDialog/helpers";import { getConnectableCredentialTypes } from "@/hooks/useCredentials";+import { getDiscriminatorValue } from "@/components/renderers/InputRenderer/custom/CredentialField/helpers";+import { getHostFromUrl } from "@/lib/utils/url";import { Dialog } from "@/components/molecules/Dialog/Dialog";import type { BlockIOCredentialsSubSchema } from "@/lib/autogpt-server-api/types";import { useState } from "react";@@ -24,6 +26,9 @@ interface Props {schema: BlockIOCredentialsSubSchema;provider: string;displayName: string;+ /** The requesting node's other inputs, which carry the URL a host-scoped+ * credential is for. */+ siblingInputs?: Record<string, unknown>;/** Existing account to upgrade in place rather than signing in afresh. */credentialID?: string;/** Accounts to offer before the connect methods. With none, or once the@@ -45,6 +50,7 @@ export function ConnectCredentialDialog({schema,provider,displayName,+ siblingInputs,credentialID,existing,open,@@ -96,9 +102,9 @@ export function ConnectCredentialDialog({onClose();}- // Device auth completes inside ConnectMethodView, bypassing the hook, so- // this is the only place its reset can happen.- function handleDeviceAuthSuccess(credential?: CredentialsMetaResponse) {+ // The self-submitting methods complete inside ConnectMethodView, bypassing+ // the hook, so this is the only place their reset can happen.+ function handleInlineConnectSuccess(credential?: CredentialsMetaResponse) {reset();handleConnected(credential);}@@ -108,6 +114,13 @@ export function ConnectCredentialDialog({if (await existing.onUse(chosen)) handleClose();}+ // The block that wants the credential names the URL it will call, either+ // as a sibling input or, for a saved graph, in the schema's discriminator.+ const discriminatorUrl = getDiscriminatorValue(siblingInputs ?? {}, schema);+ const hostScopedHost = discriminatorUrl+ ? (getHostFromUrl(discriminatorUrl) ?? undefined)+ : undefined;+const connectable: ConnectableProvider = {id: provider,name: displayName,@@ -144,7 +157,8 @@ export function ConnectCredentialDialog({onSelectMethod={setSelectedMethod}apiKeyForm={apiKeyForm}onApiKeySubmit={handleApiKeySubmit}- onDeviceAuthSuccess={handleDeviceAuthSuccess}+ hostScopedHost={hostScopedHost}+ onInlineConnectSuccess={handleInlineConnectSuccess}/>)}{showExisting && existing?.error && (diff --git a/autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/ConnectCredentialDialog/__tests__/ConnectCredentialDialog.test.tsx b/autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/ConnectCredentialDialog/__tests__/ConnectCredentialDialog.test.tsxindex e66714da48..dda506a795 100644--- a/autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/ConnectCredentialDialog/__tests__/ConnectCredentialDialog.test.tsx+++ b/autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/ConnectCredentialDialog/__tests__/ConnectCredentialDialog.test.tsx@@ -26,12 +26,14 @@ vi.mock(provider,selectedMethod,onSelectMethod,- onDeviceAuthSuccess,+ hostScopedHost,+ onInlineConnectSuccess,}: {provider: { id: string; name: string; supportedAuthTypes: string[] };selectedMethod: string | null;onSelectMethod: (method: string) => void;- onDeviceAuthSuccess: () => void;+ hostScopedHost?: string;+ onInlineConnectSuccess: () => void;}) => (<div data-testid="connect-method-view"><span>Connect AutoGPT to {provider.name}</span>@@ -39,13 +41,14 @@ vi.mock({provider.supportedAuthTypes.join(",")}</span><span data-testid="selected-method">{selectedMethod ?? "none"}</span>+ <span data-testid="host-scoped-host">{hostScopedHost ?? "none"}</span>{provider.supportedAuthTypes.map((method) => (<button key={method} onClick={() => onSelectMethod(method)}>{`select-${method}`}</button>))}{provider.supportedAuthTypes.includes("device_code") && (- <button onClick={onDeviceAuthSuccess}>complete-device_code</button>+ <button onClick={onInlineConnectSuccess}>complete-device_code</button>)}</div>),@@ -108,7 +111,7 @@ function makeApiKeyReturn(reset: vi.fn(),formState: { isValid: overrides.isValid ?? false },handleSubmit: (onValid: (values: unknown) => void) => () =>- onValid({ title: "Key", apiKey: "sk-123", expiresAt: "" }),+ onValid({ title: "Key", apiKey: "sk-123", expiresAt: "" }), // pragma: allowlist secret},handleSubmit: vi.fn(),isPending: overrides.isPending ?? false,@@ -146,6 +149,55 @@ beforeEach(() => {afterEach(cleanup);describe("ConnectCredentialDialog", () => {+ it("takes the host-scoped host from the requesting node's URL input", () => {+ renderDialog({+ schema: {+ credentials_provider: ["http"],+ credentials_types: ["host_scoped"],+ discriminator: "url",+ } as unknown as BlockIOCredentialsSubSchema,+ provider: "http",+ displayName: "Http",+ siblingInputs: { url: "https://api.example.com/v1/orders" },+ });++ expect(screen.getByTestId("host-scoped-host").textContent).toBe(+ "api.example.com",+ );+ });++ it("falls back to the schema's discriminator for a saved graph's pinned URL", () => {+ // A run of a saved agent passes no sibling inputs; the aggregated+ // credentials schema carries the node's URL instead.+ renderDialog({+ schema: {+ credentials_provider: ["http"],+ credentials_types: ["host_scoped"],+ discriminator: "url",+ discriminator_values: ["https://api.stripe.com/v1/charges"],+ } as unknown as BlockIOCredentialsSubSchema,+ provider: "http",+ displayName: "Http",+ });++ expect(screen.getByTestId("host-scoped-host").textContent).toBe(+ "api.stripe.com",+ );+ });++ it("leaves the host unset where no block is in scope", () => {+ renderDialog({+ schema: {+ credentials_provider: ["http"],+ credentials_types: ["host_scoped"],+ } as unknown as BlockIOCredentialsSubSchema,+ provider: "http",+ displayName: "Http",+ });++ expect(screen.getByTestId("host-scoped-host").textContent).toBe("none");+ });+it("renders nothing while closed", () => {renderDialog({ open: false });expect(screen.queryByTestId("connect-method-view")).toBeNull();@@ -228,7 +280,7 @@ describe("ConnectCredentialDialog", () => {expect(apiKey.handleSubmit).toHaveBeenCalledWith({title: "Key",- apiKey: "sk-123",+ apiKey: "sk-123", // pragma: allowlist secretexpiresAt: "",});});diff --git a/autogpt_platform/frontend/src/components/contextual/IntegrationsPanel/components/ConnectServiceDialog/components/ConnectMethodView/ConnectMethodView.tsx b/autogpt_platform/frontend/src/components/contextual/IntegrationsPanel/components/ConnectServiceDialog/components/ConnectMethodView/ConnectMethodView.tsxindex 86ae9918ec..ec46f749af 100644--- a/autogpt_platform/frontend/src/components/contextual/IntegrationsPanel/components/ConnectServiceDialog/components/ConnectMethodView/ConnectMethodView.tsx+++ b/autogpt_platform/frontend/src/components/contextual/IntegrationsPanel/components/ConnectServiceDialog/components/ConnectMethodView/ConnectMethodView.tsx@@ -15,6 +15,8 @@ import {} from "@/components/contextual/IntegrationsPanel/components/ConnectServiceDialog/helpers";import type { UseFormReturn } from "react-hook-form";import { InlineApiKeyForm } from "./InlineApiKeyForm";+import { InlineHostScopedForm } from "./InlineHostScopedForm";+import { InlineUserPasswordForm } from "./InlineUserPasswordForm";import {GlobeIcon,Key01Icon,@@ -31,7 +33,11 @@ interface Props {onSelectMethod: (method: AuthMethod) => void;apiKeyForm: UseFormReturn<ApiKeyConnectFormValues>;onApiKeySubmit: (values: ApiKeyConnectFormValues) => void;- onDeviceAuthSuccess: (credential?: CredentialsMetaResponse) => void;+ /** The host the requesting block will call, when one is in scope. */+ hostScopedHost?: string;+ /** A method that completes inside this view rather than through the+ * panel footer's Continue: device auth, host-scoped, user/password. */+ onInlineConnectSuccess: (credential?: CredentialsMetaResponse) => void;}export const METHOD_ORDER: AuthMethod[] = [@@ -68,8 +74,8 @@ const METHOD_COPY: Record<icon: UserIcon,},[AuthType.host_scoped]: {- label: "Host",- description: "Scope credentials to one host.",+ label: "Website access",+ description: "Paste a key or headers used only for one website.",icon: GlobeIcon,},[AuthType.device_code]: {@@ -88,7 +94,8 @@ export function ConnectMethodView({onSelectMethod,apiKeyForm,onApiKeySubmit,- onDeviceAuthSuccess,+ hostScopedHost,+ onInlineConnectSuccess,}: Props) {const methods = METHOD_ORDER.filter((method) =>provider.supportedAuthTypes.includes(method),@@ -205,7 +212,19 @@ export function ConnectMethodView({<DeviceAuthConnectButtonprovider={provider.id}providerName={provider.name}- onSuccess={onDeviceAuthSuccess}+ onSuccess={onInlineConnectSuccess}+ />+ ) : method === AuthType.host_scoped ? (+ <InlineHostScopedForm+ provider={provider.id}+ host={hostScopedHost}+ onSuccess={onInlineConnectSuccess}+ />+ ) : method === AuthType.user_password ? (+ <InlineUserPasswordForm+ provider={provider.id}+ providerName={provider.name}+ onSuccess={onInlineConnectSuccess}/>) : (<UnsupportedNotice providerName={provider.name} />diff --git a/autogpt_platform/frontend/src/components/contextual/IntegrationsPanel/components/ConnectServiceDialog/components/ConnectMethodView/InlineHostScopedForm.tsx b/autogpt_platform/frontend/src/components/contextual/IntegrationsPanel/components/ConnectServiceDialog/components/ConnectMethodView/InlineHostScopedForm.tsxnew file mode 100644index 0000000000..d73b2b7c7f--- /dev/null+++ b/autogpt_platform/frontend/src/components/contextual/IntegrationsPanel/components/ConnectServiceDialog/components/ConnectMethodView/InlineHostScopedForm.tsx@@ -0,0 +1,218 @@+"use client";++import { useState } from "react";+import { useForm } from "react-hook-form";+import { zodResolver } from "@hookform/resolvers/zod";+import { z } from "zod";+import { Delete02Icon, PlusSignIcon } from "@hugeicons/core-free-icons";++import type { CredentialsMetaResponse } from "@/app/api/__generated__/models/credentialsMetaResponse";+import { Button } from "@/components/atoms/Button/Button";+import { Icon } from "@/components/atoms/Icon/Icon";+import { Input } from "@/components/atoms/Input/Input";+import { Text } from "@/components/atoms/Text/Text";+import {+ Form,+ FormControl,+ FormField,+ FormItem,+ FormMessage,+} from "@/components/molecules/Form/Form";+import {+ addHeaderPairToList,+ headerPairsToRecord,+ removeHeaderPairFromList,+ updateHeaderPairInList,+ type HeaderPair,+} from "@/components/contextual/CredentialsInput/helpers";++import { useInlineConnectForm } from "./useInlineConnectForm";++const hostScopedConnectSchema = z+ .object({+ host: z+ .string()+ .trim()+ .min(1, "Host is required")+ .refine((value) => !/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(value), {+ message: "Enter only the host (e.g. api.example.com), not a full URL",+ })+ .refine((value) => !value.includes("/"), {+ message:+ "Enter only the host, without a trailing path. A port is allowed.",+ }),+ })+ .strict();++type HostScopedConnectFormValues = z.infer<typeof hostScopedConnectSchema>;++interface Props {+ provider: string;+ /** The host the requesting block will call. Absent where no block is in+ * scope — the settings dialog and the copilot connect card. */+ host?: string;+ onSuccess: (credential?: CredentialsMetaResponse) => void;+}++// Host pattern plus the headers to attach to requests matching it. Carries its+// own submit, because the panel footer's Continue only drives OAuth and API key.+export function InlineHostScopedForm({ provider, host, onSuccess }: Props) {+ const [headerPairs, setHeaderPairs] = useState<HeaderPair[]>([+ { key: "", value: "" },+ ]);+ const { submit, isPending } = useInlineConnectForm({+ provider,+ successTitle: "Host credentials saved",+ failureTitle: "Couldn't save host credentials",+ onSuccess,+ });++ const form = useForm<HostScopedConnectFormValues>({+ resolver: zodResolver(hostScopedConnectSchema),+ defaultValues: { host: host ?? "" },+ mode: "onChange",+ });++ const headers = headerPairsToRecord(headerPairs);+ // Parsed rather than read off formState, which stays invalid until the+ // first change and so would reject a host we prefilled.+ const hostIsValid = hostScopedConnectSchema.safeParse({+ host: form.watch("host"),+ }).success;+ // A host-scoped credential with no headers adds nothing to a request, so+ // saving one would silently produce a credential that does nothing.+ const canSubmit = hostIsValid && Object.keys(headers).length > 0;++ function handleSubmit(values: HostScopedConnectFormValues) {+ submit({+ provider,+ type: "host_scoped",+ title: values.host,+ host: values.host,+ headers,+ });+ }++ return (+ <Form form={form} onSubmit={handleSubmit} className="space-y-2.5">+ <FormField+ control={form.control}+ name="host"+ render={({ field }) => (+ <FormItem>+ <FormControl>+ <Input+ {...field}+ id="host"+ autoComplete="off"+ spellCheck={false}+ label="Host"+ labelVariant="small-medium"+ size="small"+ readOnly={Boolean(host)}+ placeholder="api.example.com"+ wrapperClassName="!mb-0"+ />+ </FormControl>+ <Text variant="small" className="!text-zinc-500">+ {host+ ? "Taken from the URL this block calls."+ : "The host of the URL this block will call."}+ </Text>+ <FormMessage />+ </FormItem>+ )}+ />++ <div className="space-y-2">+ <Text variant="small-medium" className="text-zinc-900">+ Headers+ </Text>+ <Text variant="small" className="!text-zinc-500">+ Sent with every request to this host, such as Authorization.+ </Text>++ {headerPairs.map((pair, index) => (+ <div key={index} className="flex items-end gap-2">+ <Input+ id={`header-${index}-key`}+ label="Header name"+ hideLabel+ size="small"+ className="flex-1"+ wrapperClassName="!mb-0 flex-1"+ placeholder="Authorization"+ value={pair.key}+ onChange={(event) =>+ updateHeaderPair(index, "key", event.target.value)+ }+ />+ <Input+ id={`header-${index}-value`}+ label="Header value"+ hideLabel+ type="password"+ autoComplete="new-password"+ size="small"+ className="flex-1"+ wrapperClassName="!mb-0 flex-1"+ placeholder="Bearer …"+ value={pair.value}+ onChange={(event) =>+ updateHeaderPair(index, "value", event.target.value)+ }+ />+ <Button+ type="button"+ variant="icon"+ size="icon"+ aria-label={`Remove header ${index + 1}`}+ disabled={headerPairs.length === 1}+ onClick={() => removeHeaderPair(index)}+ >+ <Icon icon={Delete02Icon} size={16} />+ </Button>+ </div>+ ))}++ <Button+ type="button"+ variant="outline"+ size="small"+ onClick={addHeaderPair}+ >+ <Icon icon={PlusSignIcon} size={16} /> Add header+ </Button>+ </div>++ <Button+ type="submit"+ variant="primary"+ size="small"+ className="w-full"+ disabled={!canSubmit}+ loading={isPending}+ >+ {isPending ? "Connecting…" : "Connect"}+ </Button>+ </Form>+ );++ function addHeaderPair() {+ setHeaderPairs((pairs) => addHeaderPairToList(pairs));+ }++ function removeHeaderPair(index: number) {+ setHeaderPairs((pairs) => removeHeaderPairFromList(pairs, index));+ }++ function updateHeaderPair(+ index: number,+ field: "key" | "value",+ value: string,+ ) {+ setHeaderPairs((pairs) =>+ updateHeaderPairInList(pairs, index, field, value),+ );+ }+}diff --git a/autogpt_platform/frontend/src/components/contextual/IntegrationsPanel/components/ConnectServiceDialog/components/ConnectMethodView/InlineUserPasswordForm.tsx b/autogpt_platform/frontend/src/components/contextual/IntegrationsPanel/components/ConnectServiceDialog/components/ConnectMethodView/InlineUserPasswordForm.tsxnew file mode 100644index 0000000000..a2f6483b99--- /dev/null+++ b/autogpt_platform/frontend/src/components/contextual/IntegrationsPanel/components/ConnectServiceDialog/components/ConnectMethodView/InlineUserPasswordForm.tsx@@ -0,0 +1,150 @@+"use client";++import { useForm } from "react-hook-form";+import { zodResolver } from "@hookform/resolvers/zod";+import { z } from "zod";++import type { CredentialsMetaResponse } from "@/app/api/__generated__/models/credentialsMetaResponse";+import { Button } from "@/components/atoms/Button/Button";+import { Input } from "@/components/atoms/Input/Input";+import {+ Form,+ FormControl,+ FormField,+ FormItem,+ FormMessage,+} from "@/components/molecules/Form/Form";++import { useInlineConnectForm } from "./useInlineConnectForm";++const userPasswordConnectSchema = z+ .object({+ title: z+ .string()+ .trim()+ .min(1, "Name is required")+ .max(100, "Name must be 100 characters or less"),+ username: z.string().trim().min(1, "Username is required"),+ password: z.string().min(1, "Password is required"),+ })+ .strict();++type UserPasswordConnectFormValues = z.infer<typeof userPasswordConnectSchema>;++interface Props {+ provider: string;+ providerName: string;+ onSuccess: (credential?: CredentialsMetaResponse) => void;+}++// Carries its own submit, because the panel footer's Continue only drives+// OAuth and API key.+export function InlineUserPasswordForm({+ provider,+ providerName,+ onSuccess,+}: Props) {+ const { submit, isPending } = useInlineConnectForm({+ provider,+ successTitle: "Credentials saved",+ failureTitle: "Couldn't save credentials",+ onSuccess,+ });++ const form = useForm<UserPasswordConnectFormValues>({+ resolver: zodResolver(userPasswordConnectSchema),+ defaultValues: { title: "", username: "", password: "" },+ mode: "onChange",+ });++ function handleSubmit(values: UserPasswordConnectFormValues) {+ submit({+ provider,+ type: "user_password",+ title: values.title,+ username: values.username,+ password: values.password,+ });+ }++ return (+ <Form form={form} onSubmit={handleSubmit} className="space-y-2.5">+ <FormField+ control={form.control}+ name="title"+ render={({ field }) => (+ <FormItem>+ <FormControl>+ <Input+ {...field}+ id={field.name}+ autoComplete="off"+ label="Name"+ labelVariant="small-medium"+ size="small"+ placeholder={`My ${providerName} account`}+ wrapperClassName="!mb-0"+ />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />++ <FormField+ control={form.control}+ name="username"+ render={({ field }) => (+ <FormItem>+ <FormControl>+ <Input+ {...field}+ id={field.name}+ autoComplete="off"+ spellCheck={false}+ label="Username"+ labelVariant="small-medium"+ size="small"+ wrapperClassName="!mb-0"+ />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />++ <FormField+ control={form.control}+ name="password"+ render={({ field }) => (+ <FormItem>+ <FormControl>+ <Input+ {...field}+ id={field.name}+ type="password"+ autoComplete="new-password"+ label="Password"+ labelVariant="small-medium"+ size="small"+ wrapperClassName="!mb-0"+ />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />++ <Button+ type="submit"+ variant="primary"+ size="small"+ className="w-full"+ disabled={!form.formState.isValid}+ loading={isPending}+ >+ {isPending ? "Connecting…" : "Connect"}+ </Button>+ </Form>+ );+}diff --git a/autogpt_platform/frontend/src/components/contextual/IntegrationsPanel/components/ConnectServiceDialog/components/ConnectMethodView/useInlineConnectForm.ts b/autogpt_platform/frontend/src/components/contextual/IntegrationsPanel/components/ConnectServiceDialog/components/ConnectMethodView/useInlineConnectForm.tsnew file mode 100644index 0000000000..d577bfdcaf--- /dev/null+++ b/autogpt_platform/frontend/src/components/contextual/IntegrationsPanel/components/ConnectServiceDialog/components/ConnectMethodView/useInlineConnectForm.ts@@ -0,0 +1,59 @@+"use client";++import { useContext, useState } from "react";+import { useQueryClient } from "@tanstack/react-query";++import { postV1CreateCredentials } from "@/app/api/__generated__/endpoints/integrations/integrations";+import type { CredentialsMetaResponse } from "@/app/api/__generated__/models/credentialsMetaResponse";+import type { PostV1CreateCredentialsBody } from "@/app/api/__generated__/models/postV1CreateCredentialsBody";+import { toast } from "@/components/molecules/Toast/use-toast";+import { invalidateConnectionQueries } from "@/lib/react-query/invalidateConnections";+import { CredentialsActionsContext } from "@/providers/agent-credentials/credentials-provider";++interface Args {+ provider: string;+ successTitle: string;+ failureTitle: string;+ onSuccess: (credential?: CredentialsMetaResponse) => void;+}++/** Submit path for the method cards that save a credential themselves rather+ * than through the panel footer's Continue — host-scoped and user/password. */+export function useInlineConnectForm({+ provider,+ successTitle,+ failureTitle,+ onSuccess,+}: Args) {+ const queryClient = useQueryClient();+ const credentialsActions = useContext(CredentialsActionsContext);+ const [isPending, setIsPending] = useState(false);++ async function submit(body: PostV1CreateCredentialsBody) {+ setIsPending(true);+ try {+ // customMutator throws on non-2xx, so reaching this line means success.+ const created = await postV1CreateCredentials(provider, body);++ toast({ title: successTitle, variant: "success" });+ await invalidateConnectionQueries(queryClient);+ // Invalidation emits no cache event unless something already+ // subscribed to the credentials query.+ credentialsActions?.reload();+ // Narrow by shape, not status code, so a 201 ↔ 200 swap cannot break+ // this; only the success payload carries an id.+ onSuccess("id" in created.data ? created.data : undefined);+ } catch (error) {+ toast({+ title: failureTitle,+ description:+ error instanceof Error ? error.message : "Unexpected error",+ variant: "destructive",+ });+ } finally {+ setIsPending(false);+ }+ }++ return { submit, isPending };+}diff --git a/autogpt_platform/frontend/src/components/contextual/IntegrationsPanel/components/ConnectServiceDialog/components/DetailView/MethodPanel.tsx b/autogpt_platform/frontend/src/components/contextual/IntegrationsPanel/components/ConnectServiceDialog/components/DetailView/MethodPanel.tsxindex 1de909d33e..29fda7b1b7 100644--- a/autogpt_platform/frontend/src/components/contextual/IntegrationsPanel/components/ConnectServiceDialog/components/DetailView/MethodPanel.tsx+++ b/autogpt_platform/frontend/src/components/contextual/IntegrationsPanel/components/ConnectServiceDialog/components/DetailView/MethodPanel.tsx@@ -10,6 +10,8 @@ import {import { ApiKeyConnectForm } from "./ApiKeyConnectForm";import { DeviceAuthConnectButton } from "@/components/contextual/DeviceAuth/DeviceAuthConnectButton";import { ChatGPTConnectExplainer } from "./ChatGPTConnectExplainer";+import { InlineHostScopedForm } from "../ConnectMethodView/InlineHostScopedForm";+import { InlineUserPasswordForm } from "../ConnectMethodView/InlineUserPasswordForm";import { OAuthConnectButton } from "./OAuthConnectButton";import { UnsupportedNotice } from "./UnsupportedNotice";@@ -62,6 +64,20 @@ export function MethodPanel({ method, provider, onSuccess }: Props) {/>);}+ if (method === AuthType.host_scoped) {+ return (+ <InlineHostScopedForm provider={provider.id} onSuccess={onSuccess} />+ );+ }+ if (method === AuthType.user_password) {+ return (+ <InlineUserPasswordForm+ provider={provider.id}+ providerName={provider.name}+ onSuccess={onSuccess}+ />+ );+ }return (<UnsupportedNoticeproviderName={provider.name}