The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
feat(workflow): optional instructions on a form step, with variables (#27251)
Félix Malfait0a219cfe672d
diff --git a/packages/twenty-docs/user-guide/workflows/capabilities/workflow-actions.mdx b/packages/twenty-docs/user-guide/workflows/capabilities/workflow-actions.mdxindex 3e5062f0870..762435353c8 100644--- a/packages/twenty-docs/user-guide/workflows/capabilities/workflow-actions.mdx+++ b/packages/twenty-docs/user-guide/workflows/capabilities/workflow-actions.mdx@@ -230,6 +230,7 @@ Opens a form for the person who launches the workflow, to collect input on the s- a label- a default value under `Placeholder` (optional)- Edit the form title+- Add instructions shown above the fields (optional). They can include variables from previous steps, for example the name of the record the form is about.**Output**: Form responses are available for use in subsequent steps.diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/components/WorkflowEditActionFormBuilder.tsx b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/components/WorkflowEditActionFormBuilder.tsxindex 5c5e71af63f..7219e5cdeeb 100644--- a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/components/WorkflowEditActionFormBuilder.tsx+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/components/WorkflowEditActionFormBuilder.tsx@@ -1,6 +1,7 @@import { FormFieldInputInnerContainer } from '@/object-record/record-field/ui/form-types/components/FormFieldInputInnerContainer';import { FormFieldInputRowContainer } from '@/object-record/record-field/ui/form-types/components/FormFieldInputRowContainer';import { FormFieldPlaceholder } from '@/object-record/record-field/ui/form-types/components/FormFieldPlaceholder';+import { FormTextFieldInput } from '@/object-record/record-field/ui/form-types/components/FormTextFieldInput';import { FormFieldInputContainer } from '@/ui/input/components/FormFieldInputContainer';import { InputLabel } from '@/ui/input/components/internal/InputLabel/InputLabel';import { DraggableItem } from '@/ui/layout/draggable-list/components/DraggableItem';@@ -16,6 +17,7 @@ import { WorkflowStepFooter } from '@/workflow/workflow-steps/components/Workfloimport { WorkflowEditActionFormFieldSettings } from '@/workflow/workflow-steps/workflow-actions/form-action/components/WorkflowEditActionFormFieldSettings';import { type WorkflowFormActionField } from '@/workflow/workflow-steps/workflow-actions/form-action/types/WorkflowFormActionField';import { getDefaultFormFieldSettings } from '@/workflow/workflow-steps/workflow-actions/form-action/utils/getDefaultFormFieldSettings';+import { WorkflowVariablePicker } from '@/workflow/workflow-variables/components/WorkflowVariablePicker';import { styled } from '@linaria/react';import { useLingui } from '@lingui/react/macro';import { isNonEmptyString } from '@sniptt/guards';@@ -141,6 +143,13 @@ const StyledCalloutContainer = styled.div`padding-top: ${themeCssVariables.spacing[2]};`;+const StyledInstructionsContainer = styled.div`+ padding-bottom: ${themeCssVariables.spacing[4]};+ padding-left: ${themeCssVariables.spacing[7]};+ padding-right: ${themeCssVariables.spacing[7]};+ padding-top: ${themeCssVariables.spacing[2]};+`;+const StyledNotClosableCalloutContainer = styled.div`padding-bottom: ${themeCssVariables.spacing[4]};padding-left: ${themeCssVariables.spacing[7]};@@ -157,6 +166,9 @@ export const WorkflowEditActionFormBuilder = ({const theme = useTheme();const [formData, setFormData] = useState<FormData>(action.settings.input);+ const [instructions, setInstructions] = useState(+ action.settings.instructions,+ );const [isCalloutVisible, setIsCalloutVisible] = useState<boolean>(true);const [selectedField, setSelectedField] = useState<string | null>(null);@@ -189,7 +201,7 @@ export const WorkflowEditActionFormBuilder = ({setFormData(updatedFormData);- saveAction(updatedFormData);+ saveAction({ input: updatedFormData, instructions });};const handleDragEnd = ({ source, destination }: DraggableListDropResult) => {@@ -210,22 +222,32 @@ export const WorkflowEditActionFormBuilder = ({setFormData(copiedFormData);- saveAction(copiedFormData);+ saveAction({ input: copiedFormData, instructions });};- const saveAction = useDebouncedCallback(async (formData: FormData) => {+ const saveAction = useDebouncedCallback(+ (settings: { input: FormData; instructions: string | undefined }) => {+ if (actionOptions.readonly === true) {+ return;+ }++ actionOptions.onActionUpdate({+ ...action,+ settings: { ...action.settings, ...settings },+ });+ },+ 1_000,+ );++ const handleInstructionsChange = (updatedInstructions: string) => {if (actionOptions.readonly === true) {return;}- actionOptions.onActionUpdate({- ...action,- settings: {- ...action.settings,- input: formData,- },- });- }, 1_000);+ setInstructions(updatedInstructions);++ saveAction({ input: formData, instructions: updatedInstructions });+ };useEffect(() => {return () => {@@ -261,6 +283,17 @@ export const WorkflowEditActionFormBuilder = ({/></StyledCalloutContainer>)}+ <StyledInstructionsContainer>+ <FormTextFieldInput+ label={t`Instructions`}+ placeholder={t`Shown above the fields, for example what to fill in and why`}+ multiline+ readonly={actionOptions.readonly}+ defaultValue={instructions}+ onChange={handleInstructionsChange}+ VariablePicker={WorkflowVariablePicker}+ />+ </StyledInstructionsContainer>{formData.length === 0 && (<StyledNotClosableCalloutContainer><Callout@@ -357,13 +390,11 @@ export const WorkflowEditActionFormBuilder = ({setFormData(updatedFormData);- actionOptions.onActionUpdate({- ...action,- settings: {- ...action.settings,- input: updatedFormData,- },+ saveAction({+ input: updatedFormData,+ instructions,});+ saveAction.flush();}}><IconTrash />@@ -410,15 +441,12 @@ export const WorkflowEditActionFormBuilder = ({label,};- setFormData([...formData, newField]);+ const updatedFormData = [...formData, newField];++ setFormData(updatedFormData);- actionOptions.onActionUpdate({- ...action,- settings: {- ...action.settings,- input: [...action.settings.input, newField],- },- });+ saveAction({ input: updatedFormData, instructions });+ saveAction.flush();setSelectedField(newField.id);}}diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/components/WorkflowEditActionFormFiller.tsx b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/components/WorkflowEditActionFormFiller.tsxindex 17cafb23b9b..a1d166cbf85 100644--- a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/components/WorkflowEditActionFormFiller.tsx+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/components/WorkflowEditActionFormFiller.tsx@@ -1,5 +1,9 @@import { useSidePanelHistory } from '@/side-panel/hooks/useSidePanelHistory';+import { workflowRunIteratorSubStepIterationIndexComponentState } from '@/side-panel/pages/workflow/step/view-run/states/workflowRunIteratorSubStepIterationIndexComponentState';+import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';+import { styled } from '@linaria/react';import { SidePanelFooter } from '@/ui/layout/side-panel/components/SidePanelFooter';+import { useWorkflowRun } from '@/workflow/hooks/useWorkflowRun';import { useWorkflowRunIdOrThrow } from '@/workflow/hooks/useWorkflowRunIdOrThrow';import { type WorkflowFormAction } from '@/workflow/types/Workflow';import { WorkflowRunSSESubscribeEffect } from '@/workflow/workflow-diagram/components/WorkflowRunSSESubscribeEffect';@@ -8,8 +12,11 @@ import { useUpdateWorkflowRunStep } from '@/workflow/workflow-steps/hooks/useUpdimport { WorkflowFormFields } from '@/workflow/workflow-steps/workflow-actions/form-action/components/WorkflowFormFields';import { WorkflowFormStepSubmitButton } from '@/workflow/workflow-steps/workflow-actions/form-action/components/WorkflowFormStepSubmitButton';import { type WorkflowFormActionField } from '@/workflow/workflow-steps/workflow-actions/form-action/types/WorkflowFormActionField';+import { getFormInstructionsContext } from '@/workflow/workflow-steps/workflow-actions/form-action/utils/getFormInstructionsContext';+import { resolveFormInstructions } from '@/workflow/workflow-steps/workflow-actions/form-action/utils/resolveFormInstructions';import { useEffect, useState } from 'react';import { isDefined } from 'twenty-shared/utils';+import { themeCssVariables } from 'twenty-ui/theme';import { useDebouncedCallback } from 'use-debounce';export type WorkflowEditActionFormFillerProps = {@@ -21,12 +28,33 @@ export type WorkflowEditActionFormFillerProps = {type FormData = WorkflowFormActionField[];+const StyledInstructions = styled.div`+ color: ${themeCssVariables.font.color.secondary};+ white-space: pre-wrap;+ word-break: break-word;+`;+export const WorkflowEditActionFormFiller = ({action,actionOptions,}: WorkflowEditActionFormFillerProps) => {const [formData, setFormData] = useState<FormData>(action.settings.input);const workflowRunId = useWorkflowRunIdOrThrow();+ const workflowRun = useWorkflowRun({ workflowRunId });+ const workflowRunIteratorSubStepIterationIndex = useAtomComponentStateValue(+ workflowRunIteratorSubStepIterationIndexComponentState,+ );+ const instructionsContext = getFormInstructionsContext({+ stepId: action.id,+ workflowRun,+ iterationIndex: workflowRunIteratorSubStepIterationIndex,+ });+ const instructions = isDefined(instructionsContext)+ ? resolveFormInstructions({+ instructions: action.settings.instructions,+ context: instructionsContext,+ })+ : undefined;const { goBackFromSidePanel } = useSidePanelHistory();const { updateWorkflowRunStep } = useUpdateWorkflowRunStep();const [error, setError] = useState<string | undefined>(undefined);@@ -79,6 +107,9 @@ export const WorkflowEditActionFormFiller = ({<><WorkflowRunSSESubscribeEffect workflowRunId={workflowRunId} /><WorkflowStepBody>+ {isDefined(instructions) && (+ <StyledInstructions>{instructions}</StyledInstructions>+ )}<WorkflowFormFieldsfields={formData}readonly={actionOptions.readonly}diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/components/__stories__/WorkflowEditActionFormBuilder.stories.tsx b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/components/__stories__/WorkflowEditActionFormBuilder.stories.tsxindex 7e478f03ae7..b6cf052cd92 100644--- a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/components/__stories__/WorkflowEditActionFormBuilder.stories.tsx+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/components/__stories__/WorkflowEditActionFormBuilder.stories.tsx@@ -190,3 +190,24 @@ export const EmptyForm: Story = {expect(addFieldButton).toBeVisible();},};++export const WithInstructions: Story = {+ args: {+ action: {+ ...DEFAULT_ACTION,+ settings: {+ ...DEFAULT_ACTION.settings,+ instructions:+ 'Review the deal with {{trigger.properties.after.name}} before the renewal call.',+ },+ },+ actionOptions: {+ onActionUpdate: fn(),+ },+ },+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);++ expect(await canvas.findByText('Instructions')).toBeVisible();+ },+};diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/components/__stories__/WorkflowEditActionFormFiller.stories.tsx b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/components/__stories__/WorkflowEditActionFormFiller.stories.tsxindex b92e09c0e2f..02804018527 100644--- a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/components/__stories__/WorkflowEditActionFormFiller.stories.tsx+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/components/__stories__/WorkflowEditActionFormFiller.stories.tsx@@ -1,6 +1,8 @@+import { SidePanelWorkflowRunStepContentComponentInstanceContext } from '@/side-panel/pages/workflow/step/view-run/states/contexts/SidePanelWorkflowRunStepContentComponentInstanceContext';import { type WorkflowFormAction } from '@/workflow/types/Workflow';import { WorkflowEditActionFormFiller } from '@/workflow/workflow-steps/workflow-actions/form-action/components/WorkflowEditActionFormFiller';import { type Meta, type StoryObj } from '@storybook/react-vite';+import { graphql, HttpResponse } from 'msw';import { expect, within } from 'storybook/test';import { FieldMetadataType } from 'twenty-shared/types';import { ComponentDecorator } from 'twenty-ui/testing';@@ -11,6 +13,7 @@ import { WorkflowStepDecorator } from '~/testing/decorators/WorkflowStepDecoratoimport { WorkspaceDecorator } from '~/testing/decorators/WorkspaceDecorator';import { graphqlMocks } from '~/testing/graphqlMocks';import { MemoryRouterDecorator } from '~/testing/decorators/MemoryRouterDecorator';+import { oneSucceededWorkflowRunQueryResult } from '~/testing/mock-data/workflow-run';const meta: Meta<typeof WorkflowEditActionFormFiller> = {title: 'Modules/Workflow/Actions/Form/WorkflowEditActionFormFiller',@@ -19,6 +22,13 @@ const meta: Meta<typeof WorkflowEditActionFormFiller> = {msw: graphqlMocks,},decorators: [+ (Story) => (+ <SidePanelWorkflowRunStepContentComponentInstanceContext.Provider+ value={{ instanceId: 'workflow-run-step-content' }}+ >+ <Story />+ </SidePanelWorkflowRunStepContentComponentInstanceContext.Provider>+ ),WorkflowStepActionDrawerDecorator,ComponentDecorator,WorkflowStepDecorator,@@ -126,3 +136,64 @@ export const ReadonlyMode: Story = {expect(submitButton).not.toBeInTheDocument();},};++const actionWithInstructions: WorkflowFormAction = {+ ...mockAction,+ id: '6d9ac9a1-b5f9-4f63-9ab6-3d4b2f0f2a71',+ settings: {+ ...mockAction.settings,+ input: mockAction.settings.input.slice(0, 2),+ instructions:+ 'Review the deal with {{trigger.properties.after.name}} before the renewal call.\nSet the discount you agreed on, in percent.',+ },+};++const pendingRunWithCompany = {+ workflowRun: {+ ...oneSucceededWorkflowRunQueryResult.workflowRun,+ status: 'RUNNING',+ endedAt: null,+ state: {+ ...oneSucceededWorkflowRunQueryResult.workflowRun.state,+ flow: {+ ...oneSucceededWorkflowRunQueryResult.workflowRun.state.flow,+ steps: [actionWithInstructions],+ },+ stepInfos: {+ trigger: {+ status: 'SUCCESS',+ result: { properties: { after: { name: 'Airbnb' } } },+ },+ [actionWithInstructions.id]: { status: 'PENDING' },+ },+ },+ },+};++export const WithInstructions: Story = {+ args: {+ action: actionWithInstructions,+ actionOptions: {+ readonly: false,+ },+ },+ parameters: {+ msw: {+ handlers: [+ graphql.query('FindOneWorkflowRun', () =>+ HttpResponse.json({ data: pendingRunWithCompany }),+ ),+ ...graphqlMocks.handlers,+ ],+ },+ },+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);++ expect(+ await canvas.findByText(+ /Review the deal with Airbnb before the renewal call/,+ ),+ ).toBeVisible();+ },+};diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/utils/__tests__/resolveFormInstructions.test.ts b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/utils/__tests__/resolveFormInstructions.test.tsnew file mode 100644index 00000000000..53848742413--- /dev/null+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/utils/__tests__/resolveFormInstructions.test.ts@@ -0,0 +1,63 @@+import { resolveFormInstructions } from '@/workflow/workflow-steps/workflow-actions/form-action/utils/resolveFormInstructions';++const CONTEXT = {+ trigger: { company: { name: 'Airbnb' } },+ 'find-step': { first: { amount: 1200 } },+};++describe('resolveFormInstructions', () => {+ it('replaces variables with the values of the run', () => {+ expect(+ resolveFormInstructions({+ instructions:+ 'Review the deal with {{trigger.company.name}} for {{find-step.first.amount}}.',+ context: CONTEXT,+ }),+ ).toBe('Review the deal with Airbnb for 1200.');+ });++ it('shows a lone variable holding an object as JSON', () => {+ expect(+ resolveFormInstructions({+ instructions: '{{trigger.company}}',+ context: CONTEXT,+ }),+ ).toBe('{"name":"Airbnb"}');+ });++ it('keeps a lone variable that does not resolve', () => {+ expect(+ resolveFormInstructions({+ instructions: '{{missing-step.value}}',+ context: CONTEXT,+ }),+ ).toBe('{{missing-step.value}}');+ });++ it('keeps a variable that does not resolve inside text', () => {+ expect(+ resolveFormInstructions({+ instructions: 'Read {{missing-step.name}} and confirm.',+ context: CONTEXT,+ }),+ ).toBe('Read {{missing-step.name}} and confirm.');+ });++ it('shows a variable holding null', () => {+ expect(+ resolveFormInstructions({+ instructions: 'Owner: {{trigger.owner}}',+ context: { trigger: { owner: null } },+ }),+ ).toBe('Owner: null');+ });++ it('shows nothing without instructions', () => {+ expect(+ resolveFormInstructions({ instructions: ' ', context: CONTEXT }),+ ).toBeUndefined();+ expect(+ resolveFormInstructions({ instructions: undefined, context: CONTEXT }),+ ).toBeUndefined();+ });+});diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/utils/getFormInstructionsContext.ts b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/utils/getFormInstructionsContext.tsnew file mode 100644index 00000000000..ff5a707a3d6--- /dev/null+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/utils/getFormInstructionsContext.ts@@ -0,0 +1,39 @@+import { type WorkflowRun } from '@/workflow/types/Workflow';+import { getIsDescendantOfIterator } from '@/workflow/workflow-steps/utils/getIsDescendantOfIterator';+import { getWorkflowRunStepContext } from '@/workflow/workflow-steps/utils/getWorkflowRunStepContext';+import { isDefined } from 'twenty-shared/utils';++export const getFormInstructionsContext = ({+ stepId,+ workflowRun,+ iterationIndex,+}: {+ stepId: string;+ workflowRun: WorkflowRun | undefined;+ iterationIndex: number;+}): Record<string, unknown> | undefined => {+ const state = workflowRun?.state;++ if (+ !isDefined(state) ||+ !state.flow.steps.some((step) => step.id === stepId)+ ) {+ return undefined;+ }++ const stepContext = getWorkflowRunStepContext({+ stepId,+ stepInfos: state.stepInfos,+ flow: state.flow,+ currentLoopIterationIndex: getIsDescendantOfIterator({+ stepId,+ steps: state.flow.steps,+ })+ ? iterationIndex+ : undefined,+ });++ return Object.fromEntries(+ stepContext.map(({ id, context }) => [id, context]),+ );+};diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/utils/resolveFormInstructions.ts b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/utils/resolveFormInstructions.tsnew file mode 100644index 00000000000..08152bbaef2--- /dev/null+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/utils/resolveFormInstructions.ts@@ -0,0 +1,27 @@+import { isNonEmptyString, isString, isUndefined } from '@sniptt/guards';+import { resolveInput } from 'twenty-shared/utils';++const VARIABLE_PATTERN = /\{\{[^{}]+\}\}/g;++// each variable is resolved on its own, so one the run cannot resolve keeps its text instead of reading "undefined"+export const resolveFormInstructions = ({+ instructions,+ context,+}: {+ instructions: string | undefined;+ context: Record<string, unknown>;+}): string | undefined => {+ if (!isNonEmptyString(instructions?.trim())) {+ return undefined;+ }++ return instructions.replace(VARIABLE_PATTERN, (variable) => {+ const value = resolveInput(variable, context);++ if (isUndefined(value)) {+ return variable;+ }++ return isString(value) ? value : JSON.stringify(value);+ });+};diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/form/types/workflow-form-action-settings.type.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/form/types/workflow-form-action-settings.type.tsindex 5ebe8c9627b..6168660dd8d 100644--- a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/form/types/workflow-form-action-settings.type.ts+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/form/types/workflow-form-action-settings.type.ts@@ -15,4 +15,5 @@ export type FormFieldMetadata = {export type WorkflowFormActionSettings = BaseWorkflowActionSettings & {input: FormFieldMetadata[];+ instructions?: string;};diff --git a/packages/twenty-server/test/integration/endpoint-permissions/__snapshots__/endpoint-permission-declarations.integration-spec.ts.snap b/packages/twenty-server/test/integration/endpoint-permissions/__snapshots__/endpoint-permission-declarations.integration-spec.ts.snapindex 1c164a96f30..ba77a855e16 100644--- a/packages/twenty-server/test/integration/endpoint-permissions/__snapshots__/endpoint-permission-declarations.integration-spec.ts.snap+++ b/packages/twenty-server/test/integration/endpoint-permissions/__snapshots__/endpoint-permission-declarations.integration-spec.ts.snap@@ -664,6 +664,7 @@ exports[`endpoint permission declarations should match the AuthPrincipalGuard an"WorkflowVersionStepResolver.createWorkflowVersionStep {"applicationTarget":null,"authPrincipalGuards":[{"apiKey":false,"application":{"withUser":true,"withoutUser":false},"oauthClient":{"withUser":true,"withoutUser":false},"userSession":{"impersonated":true,"playground":true,"standard":true,"workspaceAgnostic":false}}]}","WorkflowVersionStepResolver.deleteWorkflowVersionStep {"applicationTarget":null,"authPrincipalGuards":[{"apiKey":false,"application":{"withUser":true,"withoutUser":false},"oauthClient":{"withUser":true,"withoutUser":false},"userSession":{"impersonated":true,"playground":true,"standard":true,"workspaceAgnostic":false}}]}","WorkflowVersionStepResolver.duplicateWorkflowVersionStep {"applicationTarget":null,"authPrincipalGuards":[{"apiKey":false,"application":{"withUser":true,"withoutUser":false},"oauthClient":{"withUser":true,"withoutUser":false},"userSession":{"impersonated":true,"playground":true,"standard":true,"workspaceAgnostic":false}}]}",+ "WorkflowVersionStepResolver.submitFormStep {"applicationTarget":null,"authPrincipalGuards":[{"apiKey":false,"application":{"withUser":true,"withoutUser":false},"oauthClient":{"withUser":true,"withoutUser":false},"userSession":{"impersonated":true,"playground":true,"standard":true,"workspaceAgnostic":false}}]}","WorkflowVersionStepResolver.testHttpRequest {"applicationTarget":null,"authPrincipalGuards":[{"apiKey":false,"application":{"withUser":true,"withoutUser":false},"oauthClient":{"withUser":true,"withoutUser":false},"userSession":{"impersonated":true,"playground":true,"standard":true,"workspaceAgnostic":false}}]}","WorkflowVersionStepResolver.updateWorkflowRunStep {"applicationTarget":null,"authPrincipalGuards":[{"apiKey":false,"application":{"withUser":true,"withoutUser":false},"oauthClient":{"withUser":true,"withoutUser":false},"userSession":{"impersonated":true,"playground":true,"standard":true,"workspaceAgnostic":false}}]}","WorkflowVersionStepResolver.updateWorkflowVersionStep {"applicationTarget":null,"authPrincipalGuards":[{"apiKey":false,"application":{"withUser":true,"withoutUser":false},"oauthClient":{"withUser":true,"withoutUser":false},"userSession":{"impersonated":true,"playground":true,"standard":true,"workspaceAgnostic":false}}]}",diff --git a/packages/twenty-server/test/integration/upgrade/suites/2-44-workspace-command-1790772993322-record-pending-form-conversations.integration-spec.ts b/packages/twenty-server/test/integration/upgrade/suites/2-44-workspace-command-1790772993322-record-pending-form-conversations.integration-spec.tsindex e2354baea4a..fcd1d0e5630 100644--- a/packages/twenty-server/test/integration/upgrade/suites/2-44-workspace-command-1790772993322-record-pending-form-conversations.integration-spec.ts+++ b/packages/twenty-server/test/integration/upgrade/suites/2-44-workspace-command-1790772993322-record-pending-form-conversations.integration-spec.ts@@ -1,3 +1,7 @@+import { randomUUID } from 'node:crypto';++import { FieldMetadataType } from 'twenty-shared/types';+import { isDefined } from 'twenty-shared/utils';import { StepStatus, WorkflowActionType } from 'twenty-shared/workflow';import { getAppProviderByClassName } from 'test/integration/utils/get-app-provider-by-class-name.util';@@ -23,6 +27,8 @@ describe('2-44 workspace command 1790772993322 - RecordPendingFormConversationsClet workspaceOrmManager: WorkspaceOrmManager;let workflowRun: Pick<WorkflowRunWorkspaceEntity, 'id' | 'state'>;let formStepId: string;+ let originalState: WorkflowRunWorkspaceEntity['state'];+ let seededThreadId: string;const inWorkspace = <TResult>(work: () => Promise<TResult>) =>workspaceOrmManager.executeInWorkspaceContext(@@ -73,32 +79,92 @@ describe('2-44 workspace command 1790772993322 - RecordPendingFormConversationsC'WorkspaceOrmManager',);- const runningWorkflowRuns = (await inWorkspace(() =>+ const [runningWorkflowRun] = (await inWorkspace(() =>repository('workflowRun').find({where: { status: WorkflowRunStatus.RUNNING },select: { id: true, state: true },+ take: 1,}),)) as Pick<WorkflowRunWorkspaceEntity, 'id' | 'state'>[];- for (const runningWorkflowRun of runningWorkflowRuns) {- const formStep = runningWorkflowRun.state?.flow?.steps.find(- (step) =>- step.type === WorkflowActionType.FORM &&- runningWorkflowRun.state?.stepInfos[step.id]?.status ===- StepStatus.PENDING,- );-- if (formStep !== undefined) {- workflowRun = runningWorkflowRun;- formStepId = formStep.id;- break;- }+ if (!isDefined(runningWorkflowRun?.state)) {+ throw new Error('The seed has no running workflow run to add a form to');}++ originalState = runningWorkflowRun.state;+ formStepId = randomUUID();+ seededThreadId = randomUUID();++ // a form step waiting since before 2.44, with the conversation 2.44 recorded for it+ workflowRun = {+ id: runningWorkflowRun.id,+ state: {+ ...originalState,+ flow: {+ ...originalState.flow,+ steps: [+ ...originalState.flow.steps,+ {+ id: formStepId,+ name: 'Approve the discount',+ type: WorkflowActionType.FORM,+ valid: true,+ settings: {+ input: [+ {+ id: randomUUID(),+ name: 'discount',+ label: 'Discount',+ type: FieldMetadataType.NUMBER,+ },+ ],+ outputSchema: {},+ errorHandlingOptions: {+ retryOnFailure: { value: 0 },+ continueOnFailure: { value: false },+ },+ },+ nextStepIds: [],+ },+ ],+ },+ stepInfos: {+ ...originalState.stepInfos,+ [formStepId]: {+ status: StepStatus.PENDING,+ threadId: seededThreadId,+ },+ },+ },+ };++ await inWorkspace(async () => {+ await repository('workflowRun').update(workflowRun.id, {+ state: workflowRun.state,+ });+ await repository('agentChatThread').insert({+ id: seededThreadId,+ title: 'Approve the discount',+ workflowRunId: workflowRun.id,+ });+ });+ });++ afterAll(async () => {+ if (!isDefined(workflowRun) || !isDefined(originalState)) {+ return;+ }++ await inWorkspace(async () => {+ await repository('agentChatThread').delete({ id: seededThreadId });+ await repository('workflowRun').update(workflowRun.id, {+ state: originalState,+ });+ });});afterEach(async () => {const threadId = await findFormThreadId();- const seededThreadId = workflowRun.state?.stepInfos[formStepId]?.threadId;await inWorkspace(async () => {if (threadId !== undefined && threadId !== seededThreadId) {@@ -166,11 +232,8 @@ describe('2-44 workspace command 1790772993322 - RecordPendingFormConversationsC});it('leaves a form whose conversation is recorded alone', async () => {- const seededThreadId = workflowRun.state?.stepInfos[formStepId]?.threadId;-await runCommand();- expect(seededThreadId).toBeDefined();expect(await findFormThreadId()).toBe(seededThreadId);});});diff --git a/packages/twenty-shared/src/workflow/schemas/form-action-settings-schema.ts b/packages/twenty-shared/src/workflow/schemas/form-action-settings-schema.tsindex b6d0660a15b..66b0ea397dc 100644--- a/packages/twenty-shared/src/workflow/schemas/form-action-settings-schema.ts+++ b/packages/twenty-shared/src/workflow/schemas/form-action-settings-schema.ts@@ -22,4 +22,5 @@ export const workflowFormFieldSchema = z.object({export const workflowFormActionSettingsSchema =baseWorkflowActionSettingsSchema.extend({input: z.array(workflowFormFieldSchema),+ instructions: z.string().optional(),});