Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

feat(forms): clearer Human Input step forms, plus hosted form and chat fixes (#15256)

Talal Jaber2b6ac46282e3
diff --git a/bun.lock b/bun.lock
index 6f02bd64d67..cc360ffc019 100644
--- a/bun.lock
+++ b/bun.lock
@@ -10417,7 +10417,7 @@
},
"packages/pieces/core/forms": {
"name": "@activepieces/piece-forms",
- "version": "0.4.22",
+ "version": "0.5.0",
"dependencies": {
"@activepieces/core-piece-types": "workspace:*",
"@activepieces/core-utils": "workspace:*",
diff --git a/packages/pieces/core/forms/package.json b/packages/pieces/core/forms/package.json
index 444838446f1..3a422df9325 100644
--- a/packages/pieces/core/forms/package.json
+++ b/packages/pieces/core/forms/package.json
@@ -1,6 +1,6 @@
{
"name": "@activepieces/piece-forms",
- "version": "0.4.22",
+ "version": "0.5.0",
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
"scripts": {
diff --git a/packages/pieces/core/forms/src/lib/actions/return-response.ts b/packages/pieces/core/forms/src/lib/actions/return-response.ts
index 0c4b360a30e..a30a2067517 100644
--- a/packages/pieces/core/forms/src/lib/actions/return-response.ts
+++ b/packages/pieces/core/forms/src/lib/actions/return-response.ts
@@ -13,11 +13,14 @@ export const returnResponse = createAction({
aiMetadata: { description: 'Sends markdown text and/or one file attachment back to the person waiting on the Web Form or Chat UI trigger that started the flow. Pick it as the replying step when that trigger has "Wait for Response" enabled; it produces nothing visible in flows started any other way. Not idempotent: each call emits a response to the waiting caller and stores a new file for any attachment.', idempotent: false },
props: {
markdown: Property.LongText({
- displayName: 'Text (Markdown)',
+ displayName: 'Text',
+ description: 'Shown to the person waiting. Markdown is supported.',
+ placeholder: 'Thanks, we received your request.',
required: false,
}),
file: Property.File({
displayName: 'Attachment',
+ description: 'A file the person can download with the response.',
required: false,
}),
},
diff --git a/packages/pieces/core/forms/src/lib/triggers/chat-trigger.ts b/packages/pieces/core/forms/src/lib/triggers/chat-trigger.ts
index 3182a6c6657..5b16781a42b 100644
--- a/packages/pieces/core/forms/src/lib/triggers/chat-trigger.ts
+++ b/packages/pieces/core/forms/src/lib/triggers/chat-trigger.ts
@@ -10,17 +10,21 @@ import {
} from '@activepieces/pieces-framework';
import { chatSubmissionTriggerOutputSchema } from '../output-schemas';
-const responseMarkdown = `
-This trigger sets up a chat interface. Ensure that **Respond on UI** is used in your flow`;
+const responseMarkdown = `The sender waits for a **Respond on UI** step in this flow.
+Without one, they see an error after {{webhookTimeoutSeconds}} seconds.`;
-const markdown = `
-**Published Chat URL:**
+const markdown = `**Published Chat URL:**
\`\`\`text
{{chatUrl}}
\`\`\`
-Use this for production, views the published version of the chat flow.
-<br>
-<br>
+Production link. Serves the published version of the chat.
+
+**Draft Chat URL:**
+\`\`\`text
+{{chatUrl}}?${USE_DRAFT_QUERY_PARAM_NAME}=true
+\`\`\`
+Testing link. Serves the draft you are editing now.
+Or press **Open Chat** in the builder to try it in a side panel.
`;
export const onChatSubmission = createTrigger({
@@ -38,11 +42,11 @@ export const onChatSubmission = createTrigger({
}),
responseMarkdown: Property.MarkDown({
value: responseMarkdown,
- variant: MarkdownVariant.WARNING,
+ variant: MarkdownVariant.INFO,
}),
botName: Property.ShortText({
displayName: 'Bot Name',
- description: 'The name of the chatbot',
+ description: 'Shown in the greeting above the chat box.',
required: true,
defaultValue: 'AI Bot',
}),
diff --git a/packages/pieces/core/forms/src/lib/triggers/form-trigger.ts b/packages/pieces/core/forms/src/lib/triggers/form-trigger.ts
index bb3299ebd15..9f2f6f15fcb 100644
--- a/packages/pieces/core/forms/src/lib/triggers/form-trigger.ts
+++ b/packages/pieces/core/forms/src/lib/triggers/form-trigger.ts
@@ -14,18 +14,16 @@ const markdown = `**Published Form URL:**
\`\`\`text
{{formUrl}}
\`\`\`
-Use this for production, views the published version of the form.
-<br>
-<br>
+Production link. Serves the published version of the form.
+
**Draft Form URL:**
\`\`\`text
{{formUrl}}?${USE_DRAFT_QUERY_PARAM_NAME}=true
\`\`\`
-Use this to generate sample data, views the draft version of the form (the one you are editing now).
-`;
-const responseMarkdown = `
-If **Wait for Response** is enabled, use **Respond on UI** in your flow to provide a response back to the form.
+Testing link. Serves the draft you are editing now.
`;
+const responseMarkdown = `With **Wait for Response** on, the form waits for a **Respond on UI** step.
+Without one, it errors after {{webhookTimeoutSeconds}} seconds.`;
type FormInput = {
displayName: string;
@@ -60,21 +58,24 @@ export const onFormSubmission = createTrigger({
value: markdown,
variant: MarkdownVariant.BORDERLESS,
}),
- response: Property.MarkDown({
- value: responseMarkdown,
- variant: MarkdownVariant.WARNING,
- }),
waitForResponse: Property.Checkbox({
displayName: 'Wait for Response',
+ description: 'Keeps the submitter on the form until the flow replies.',
defaultValue: false,
- required: true,
+ required: false,
+ }),
+ response: Property.MarkDown({
+ value: responseMarkdown,
+ variant: MarkdownVariant.INFO,
}),
inputs: Property.Array({
displayName: 'Inputs',
+ description: 'One row per field shown on the form.',
required: true,
properties: {
displayName: Property.ShortText({
displayName: 'Field Name',
+ placeholder: 'e.g. Email address',
required: true,
}),
type: Property.StaticDropdown({
@@ -91,11 +92,13 @@ export const onFormSubmission = createTrigger({
}),
description: Property.ShortText({
displayName: 'Field Description',
+ placeholder: 'Shown under the field',
required: false,
}),
required: Property.Checkbox({
displayName: 'Required',
- required: true,
+ defaultValue: false,
+ required: false,
}),
},
}),
diff --git a/packages/tests-e2e/scenarios/betterstack/webhook-should-return-response.flat.spec.js b/packages/tests-e2e/scenarios/betterstack/webhook-should-return-response.flat.spec.js
index caea3b55201..26d6ac3f263 100644
--- a/packages/tests-e2e/scenarios/betterstack/webhook-should-return-response.flat.spec.js
+++ b/packages/tests-e2e/scenarios/betterstack/webhook-should-return-response.flat.spec.js
@@ -52,9 +52,8 @@ test('should handle webhook with return response', async ({ page }) => {
await page.getByText('Catch Webhook').click();
// Grab webhook URL and build test URL
- const webhookUrl = await page
- .locator('input.grow.bg-background')
- .inputValue();
+ const webhookUrl =
+ (await page.getByTestId('markdown-code-block').textContent())?.trim() ?? '';
const runVersion = Math.floor(Math.random() * 100000);
const urlWithParams = `${webhookUrl}/sync?targetRunVersion=${runVersion}`;
diff --git a/packages/tests-e2e/scenarios/ce/flows/webhook-should-return-response.spec.ts b/packages/tests-e2e/scenarios/ce/flows/webhook-should-return-response.spec.ts
index 0810f0b9815..9b374a02553 100644
--- a/packages/tests-e2e/scenarios/ce/flows/webhook-should-return-response.spec.ts
+++ b/packages/tests-e2e/scenarios/ce/flows/webhook-should-return-response.spec.ts
@@ -13,8 +13,8 @@ test.describe('Webhooks', () => {
trigger: 'Catch Webhook'
});
- const webhookInput = page.locator('input.grow.bg-background');
- const webhookUrl = await webhookInput.inputValue();
+ const webhookUrlBlock = page.getByTestId('markdown-code-block');
+ const webhookUrl = (await webhookUrlBlock.textContent())?.trim() ?? '';
const runVersion = Math.floor(Math.random() * 100000);
const urlWithParams = `${webhookUrl}/sync?targetRunVersion=${runVersion}`;
diff --git a/packages/tests-e2e/scenarios/ce/pieces/piece-isolation.spec.ts b/packages/tests-e2e/scenarios/ce/pieces/piece-isolation.spec.ts
index b9fdf4e06d4..d47b43d04e8 100644
--- a/packages/tests-e2e/scenarios/ce/pieces/piece-isolation.spec.ts
+++ b/packages/tests-e2e/scenarios/ce/pieces/piece-isolation.spec.ts
@@ -26,8 +26,8 @@ test.describe('Piece isolation — CE', () => {
trigger: 'Catch Webhook'
});
- const webhookInput = page.locator('input.grow.bg-background');
- const webhookUrl = await webhookInput.inputValue();
+ const webhookUrlBlock = page.getByTestId('markdown-code-block');
+ const webhookUrl = (await webhookUrlBlock.textContent())?.trim() ?? '';
await builderPage.testTrigger();
diff --git a/packages/tests-e2e/scenarios/ee/pieces/piece-isolation.spec.ts b/packages/tests-e2e/scenarios/ee/pieces/piece-isolation.spec.ts
index a082459f661..fa322db7274 100644
--- a/packages/tests-e2e/scenarios/ee/pieces/piece-isolation.spec.ts
+++ b/packages/tests-e2e/scenarios/ee/pieces/piece-isolation.spec.ts
@@ -56,8 +56,8 @@ test.describe('Piece isolation — EE', () => {
trigger: 'Catch Webhook'
});
- const webhookInput = page.locator('input.grow.bg-background');
- const webhookUrl = await webhookInput.inputValue();
+ const webhookUrlBlock = page.getByTestId('markdown-code-block');
+ const webhookUrl = (await webhookUrlBlock.textContent())?.trim() ?? '';
await builderPage.testTrigger();
diff --git a/packages/web/src/app/routes/chat/flow-chat.tsx b/packages/web/src/app/routes/chat/flow-chat.tsx
index 334a2571004..84bf9c5e000 100644
--- a/packages/web/src/app/routes/chat/flow-chat.tsx
+++ b/packages/web/src/app/routes/chat/flow-chat.tsx
@@ -5,6 +5,7 @@ import {
} from '@activepieces/shared';
import { useMutation, useQuery } from '@tanstack/react-query';
import { AxiosError } from 'axios';
+import { t } from 'i18next';
import { nanoid } from 'nanoid';
import { useEffect, useRef, useState } from 'react';
@@ -53,20 +54,16 @@ export function FlowChat({
const messagesRef = useRef<HTMLDivElement>(null);
const chatInputRef = useRef<HTMLTextAreaElement>(null);
+ const useDraft =
+ mode === ChatDrawerSource.TEST_FLOW || mode === ChatDrawerSource.TEST_STEP;
+
const {
data: chatUI,
isLoading,
isError: isLoadingError,
} = useQuery<ChatUIResponse | null, Error>({
- queryKey: ['chat', flowId],
- queryFn: () =>
- humanInputApi.getChatUI(
- flowId,
- mode === ChatDrawerSource.TEST_FLOW ||
- mode === ChatDrawerSource.TEST_STEP
- ? true
- : false,
- ),
+ queryKey: ['chat', flowId, useDraft],
+ queryFn: () => humanInputApi.getChatUI(flowId, useDraft),
enabled: !isNil(flowId),
staleTime: Infinity,
retry: false,
@@ -227,8 +224,7 @@ export function FlowChat({
return (
<main
className={cn(
- 'flex w-full flex-col items-center justify-center pb-6',
- messages.length > 0 ? 'h-screen' : 'h-screen',
+ 'flex h-screen w-full flex-col items-center justify-center pb-6',
className,
)}
>
@@ -249,7 +245,7 @@ export function FlowChat({
ref={chatInputRef}
onSendMessage={handleSendMessage}
disabled={isSending}
- placeholder="Type your message here..."
+ placeholder={t('Type your message here...')}
/>
</div>
</>
@@ -263,7 +259,7 @@ export function FlowChat({
ref={chatInputRef}
onSendMessage={handleSendMessage}
disabled={isSending}
- placeholder="Type your message here..."
+ placeholder={t('Type your message here...')}
/>
</div>
</>
diff --git a/packages/web/src/components/custom/markdown.tsx b/packages/web/src/components/custom/markdown.tsx
index 265d21467bc..6f0df19b79d 100644
--- a/packages/web/src/components/custom/markdown.tsx
+++ b/packages/web/src/components/custom/markdown.tsx
@@ -114,13 +114,13 @@ const ApMarkdown = React.memo(
const codeContent = String(props.children).trim();
const isCopying = codeContent === copiedText;
return (
- <div className="relative w-full items-center flex bg-background border border-solid text-sm rounded block w-full gap-1 p-1.5">
- <input
- type="text"
- className="grow bg-background"
- value={codeContent}
- disabled
- />
+ <div className="relative flex w-full max-w-full items-center gap-1 rounded border border-solid bg-background p-1.5 text-sm">
+ <code
+ data-testid="markdown-code-block"
+ className="grow min-w-0 whitespace-pre-wrap break-all select-all px-1 py-1.5 font-mono text-sm"
+ >
+ {codeContent}
+ </code>
<Button
variant="ghost"
className="bg-background rounded p-2 inline-flex items-center justify-center h-8"
diff --git a/packages/web/src/features/chat/chat-input/index.tsx b/packages/web/src/features/chat/chat-input/index.tsx
index c42f821ee23..96eb856b2ab 100644
--- a/packages/web/src/features/chat/chat-input/index.tsx
+++ b/packages/web/src/features/chat/chat-input/index.tsx
@@ -1,4 +1,5 @@
import { isNil } from '@activepieces/core-utils';
+import { t } from 'i18next';
import { ArrowUpIcon, Paperclip } from 'lucide-react';
import * as React from 'react';
import { useRef, useState } from 'react';
@@ -27,7 +28,7 @@ const ChatInput = React.forwardRef<HTMLTextAreaElement, ChatInputProps>(
className,
onSendMessage,
disabled = false,
- placeholder = 'Type your message here...',
+ placeholder = t('Type your message here...'),
...props
},
ref,
diff --git a/packages/web/src/features/forms/components/ap-form.tsx b/packages/web/src/features/forms/components/ap-form.tsx
index 6895f698b7d..a555f1864bb 100644
--- a/packages/web/src/features/forms/components/ap-form.tsx
+++ b/packages/web/src/features/forms/components/ap-form.tsx
@@ -28,6 +28,7 @@ import {
FormField,
FormLabel,
FormItem,
+ FormMessage,
} from '@/components/ui/form';
import { Input } from '@/components/ui/input';
import { Separator } from '@/components/ui/separator';
@@ -68,7 +69,14 @@ const createPropertySchema = (input: FormInputWithName): ZodType => {
? z.string().min(1, t('This field is required'))
: z.string();
case FormInputType.FILE:
- return z.unknown();
+ return input.required
+ ? z
+ .unknown()
+ .refine(
+ (value) => value instanceof File,
+ t('This field is required'),
+ )
+ : z.unknown();
}
};
@@ -89,6 +97,9 @@ function buildSchema(inputs: FormInputWithName[]) {
),
};
}
+const isTruthyQueryValue = (value: string) =>
+ ['true', '1', 'yes', 'on'].includes(value.toLowerCase());
+
const handleDownloadFile = (fileBase: FileResponseInterface) => {
const link = document.createElement('a');
if ('url' in fileBase) {
@@ -130,7 +141,10 @@ const ApForm = ({ form, useDraft }: ApFormProps) => {
inputs.current.forEach((input) => {
const queryValue = queryParamsLowerCase[input.name.toLowerCase()];
if (queryValue !== undefined) {
- defaultValues[input.name] = queryValue;
+ defaultValues[input.name] =
+ input.type === FormInputType.TOGGLE
+ ? isTruthyQueryValue(queryValue)
+ : queryValue;
}
});
@@ -197,7 +211,7 @@ const ApForm = ({ form, useDraft }: ApFormProps) => {
<div className="container py-20">
<Form {...reactForm}>
<form onSubmit={(e) => reactForm.handleSubmit(() => mutate())(e)}>
- <Card className="w-[500px] mx-auto">
+ <Card className="w-full max-w-[500px] mx-auto">
<CardHeader>
<CardTitle className="text-center">{form?.title}</CardTitle>
</CardHeader>
@@ -212,77 +226,83 @@ const ApForm = ({ form, useDraft }: ApFormProps) => {
render={({ field }) => (
<>
{input.type === FormInputType.TOGGLE && (
- <>
- <FormItem className="flex items-center gap-2 h-full">
+ <FormItem className="flex flex-col gap-1">
+ <div className="flex items-center gap-2">
<FormControl>
<Checkbox
+ id={input.name}
onCheckedChange={(e) => field.onChange(e)}
- checked={field.value as boolean}
+ checked={field.value === true}
></Checkbox>
</FormControl>
<FormLabel
htmlFor={input.name}
- className="flex items-center"
+ className="flex items-center gap-1"
+ showRequiredIndicator={input.required}
>
{input.displayName}
</FormLabel>
- </FormItem>
- <ReadMoreDescription
- text={input.description ?? ''}
- />
- </>
+ </div>
+ {input.description && (
+ <ReadMoreDescription
+ text={input.description}
+ />
+ )}
+ <FormMessage />
+ </FormItem>
)}
{input.type !== FormInputType.TOGGLE && (
<FormItem className="flex flex-col gap-1">
<FormLabel
htmlFor={input.name}
- className="flex items-center justify-between"
+ className="flex items-center gap-1"
+ showRequiredIndicator={input.required}
>
- {input.displayName} {input.required && '*'}
+ {input.displayName}
</FormLabel>
- <FormControl className="flex flex-col gap-1">
- <>
- {input.type === FormInputType.TEXT_AREA && (
- <Textarea
- {...field}
- name={input.name}
- id={input.name}
- onChange={field.onChange}
- value={
- field.value as string | undefined
- }
- />
- )}
- {input.type === FormInputType.TEXT && (
- <Input
- {...field}
- onChange={field.onChange}
- id={input.name}
- name={input.name}
- value={
- field.value as string | undefined
+ {input.type === FormInputType.TEXT_AREA && (
+ <FormControl>
+ <Textarea
+ {...field}
+ name={input.name}
+ id={input.name}
+ onChange={field.onChange}
+ value={String(field.value ?? '')}
+ />
+ </FormControl>
+ )}
+ {input.type === FormInputType.TEXT && (
+ <FormControl>
+ <Input
+ {...field}
+ onChange={field.onChange}
+ id={input.name}
+ name={input.name}
+ value={String(field.value ?? '')}
+ />
+ </FormControl>
+ )}
+ {input.type === FormInputType.FILE && (
+ <FormControl>
+ <Input
+ name={input.name}
+ id={input.name}
+ onChange={(e) => {
+ const file = e.target.files?.[0];
+ if (file) {
+ field.onChange(file);
}
- />
- )}
- {input.type === FormInputType.FILE && (
- <Input
- name={input.name}
- id={input.name}
- onChange={(e) => {
- const file = e.target.files?.[0];
- if (file) {
- field.onChange(file);
- }
- }}
- placeholder={input.displayName}
- type="file"
- />
- )}
- <ReadMoreDescription
- text={input.description ?? ''}
+ }}
+ type="file"
/>
- </>
- </FormControl>
+ </FormControl>
+ )}
+ {input.description && (
+ <ReadMoreDescription
+ text={input.description}
+ />
+ )}
+ <FormMessage />
</FormItem>
)}
</>
diff --git a/packages/web/src/features/forms/hooks/forms-hooks.ts b/packages/web/src/features/forms/hooks/forms-hooks.ts
index c889bb24243..ac26da041c5 100644
--- a/packages/web/src/features/forms/hooks/forms-hooks.ts
+++ b/packages/web/src/features/forms/hooks/forms-hooks.ts
@@ -4,13 +4,14 @@ import { useMutation, useQuery } from '@tanstack/react-query';
import { humanInputApi } from '../api/human-input-api';
export const formsKeys = {
- form: (flowId: string) => ['form', flowId] as const,
+ form: (flowId: string, useDraft: boolean) =>
+ ['form', flowId, useDraft] as const,
};
export const formsQueries = {
useForm: (flowId: string, useDraft: boolean, enabled: boolean) =>
useQuery<FormResponse | null, Error>({
- queryKey: formsKeys.form(flowId),
+ queryKey: formsKeys.form(flowId, useDraft),
queryFn: () => humanInputApi.getForm(flowId, useDraft),
enabled,
retry: false,