Skip to content

The open alternative to Salesforce, designed for AI.

Let application workflows add a command menu item (#27698)

Thomas Trompette489c21f33b06
diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-workflow-manifest-to-universal-flat-command-menu-item.util.spec.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-workflow-manifest-to-universal-flat-command-menu-item.util.spec.ts
new file mode 100644
index 00000000000..600d42e6eed
--- /dev/null
+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-workflow-manifest-to-universal-flat-command-menu-item.util.spec.ts
@@ -0,0 +1,93 @@
+import { type WorkflowManifest } from 'twenty-shared/application';
+import { CommandMenuItemAvailabilityType } from 'twenty-shared/types';
+
+import { fromWorkflowManifestToUniversalFlatCommandMenuItem } from 'src/engine/core-modules/application/application-manifest/converters/from-workflow-manifest-to-universal-flat-command-menu-item.util';
+import { EngineComponentKey } from 'src/engine/metadata-modules/command-menu-item/enums/engine-component-key.enum';
+
+const OBJECT_ID = '99999999-9999-4999-8999-999999999999';
+const VERSION_ID = '88888888-8888-4888-8888-888888888888';
+
+const manifestWithTriggerSettings = (
+ settings?: Extract<
+ WorkflowManifest['version']['trigger'],
+ { type: 'MANUAL' }
+ >['settings'],
+): WorkflowManifest => ({
+ universalIdentifier: '11111111-1111-4111-8111-111111111111',
+ name: 'Escalate ticket',
+ version: {
+ trigger: {
+ universalIdentifier: '33333333-3333-4333-8333-333333333333',
+ type: 'MANUAL',
+ nextStepIds: ['44444444-4444-4444-8444-444444444444'],
+ ...(settings ? { settings } : {}),
+ },
+ steps: [
+ {
+ universalIdentifier: '44444444-4444-4444-8444-444444444444',
+ name: 'Done',
+ type: 'EMPTY',
+ input: {},
+ nextStepIds: [],
+ },
+ ],
+ },
+});
+
+const build = (manifest: WorkflowManifest) =>
+ fromWorkflowManifestToUniversalFlatCommandMenuItem({
+ manifest,
+ applicationUniversalIdentifier: '66666666-6666-4666-8666-666666666666',
+ coreWorkflowVersionId: VERSION_ID,
+ now: '2026-10-09T10:00:00.000Z',
+ });
+
+describe('fromWorkflowManifestToUniversalFlatCommandMenuItem', () => {
+ it('creates no command menu item when the trigger declares no availability', () => {
+ expect(build(manifestWithTriggerSettings())).toBeNull();
+ expect(build(manifestWithTriggerSettings({ icon: 'IconBolt' }))).toBeNull();
+ });
+
+ it('starts the workflow version from record selection on the declared object', () => {
+ expect(
+ build(
+ manifestWithTriggerSettings({
+ availability: {
+ type: 'BULK_RECORDS',
+ objectUniversalIdentifier: OBJECT_ID,
+ },
+ icon: 'IconBolt',
+ isPinned: true,
+ }),
+ ),
+ ).toMatchObject({
+ label: 'Escalate ticket',
+ icon: 'IconBolt',
+ isPinned: true,
+ engineComponentKey: EngineComponentKey.TRIGGER_WORKFLOW_VERSION,
+ coreWorkflowVersionId: VERSION_ID,
+ workflowVersionId: null,
+ availabilityType: CommandMenuItemAvailabilityType.RECORD_SELECTION,
+ availabilityObjectMetadataUniversalIdentifier: OBJECT_ID,
+ });
+ });
+
+ it('makes a globally available workflow available everywhere', () => {
+ expect(
+ build(manifestWithTriggerSettings({ availability: { type: 'GLOBAL' } })),
+ ).toMatchObject({
+ availabilityType: CommandMenuItemAvailabilityType.GLOBAL,
+ availabilityObjectMetadataUniversalIdentifier: null,
+ isPinned: false,
+ });
+ });
+
+ it('hides the command while the core workflows index is off, since only the core path can start it', () => {
+ expect(
+ build(manifestWithTriggerSettings({ availability: { type: 'GLOBAL' } })),
+ ).toMatchObject({
+ conditionalAvailabilityExpression:
+ 'featureFlags.IS_WORKFLOW_CORE_INDEX_PAGE_ENABLED',
+ });
+ });
+});
diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-workflow-manifest-to-universal-flat-workflow-or-throw.util.spec.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-workflow-manifest-to-universal-flat-workflow-or-throw.util.spec.ts
index 92521249b16..c1d8be2c6f4 100644
--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-workflow-manifest-to-universal-flat-workflow-or-throw.util.spec.ts
+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-workflow-manifest-to-universal-flat-workflow-or-throw.util.spec.ts
@@ -62,6 +62,7 @@ describe('application workflow definitions', () => {
expect(version.coreWorkflowId).toBe(workflow.id);
expect(workflow.workspaceWorkflowId).toBeNull();
expect(workflow.isSystem).toBe(false);
+ expect(workflow.flatUniversalCommandMenuItem).toBeUndefined();
expect(version.workspaceWorkflowVersionId).toBeNull();
expect(version.status).toBe('ACTIVE');
expect(version.steps?.[0].settings.input).toEqual({
@@ -138,6 +139,75 @@ describe('application workflow definitions', () => {
).toThrow('missing application workflow action');
});
+ it('resolves the manual trigger availability object to its name', () => {
+ const OBJECT_ID = '99999999-9999-4999-8999-999999999999';
+ const { workflow, version } = convert({
+ ...options,
+ manifest: {
+ ...manifest,
+ version: {
+ ...manifest.version,
+ trigger: {
+ universalIdentifier: TRIGGER_ID,
+ type: 'MANUAL',
+ nextStepIds: [STEP_ID],
+ settings: {
+ availability: {
+ type: 'SINGLE_RECORD',
+ objectUniversalIdentifier: OBJECT_ID,
+ },
+ icon: 'IconBolt',
+ isPinned: true,
+ },
+ },
+ },
+ },
+ objectByUniversalIdentifier: new Map([
+ [OBJECT_ID, { nameSingular: 'ticket' }],
+ ]),
+ });
+
+ expect(version.triggers?.[0]).toMatchObject({
+ type: 'MANUAL',
+ settings: {
+ availability: { type: 'SINGLE_RECORD', objectNameSingular: 'ticket' },
+ icon: 'IconBolt',
+ isPinned: true,
+ },
+ });
+ expect(workflow.flatUniversalCommandMenuItem).toMatchObject({
+ coreWorkflowVersionId: version.id,
+ availabilityObjectMetadataUniversalIdentifier: OBJECT_ID,
+ isSystemSideEffect: true,
+ });
+ });
+
+ it('refuses a manual trigger available on a missing object', () => {
+ expect(() =>
+ convert({
+ ...options,
+ manifest: {
+ ...manifest,
+ version: {
+ ...manifest.version,
+ trigger: {
+ universalIdentifier: TRIGGER_ID,
+ type: 'MANUAL',
+ nextStepIds: [STEP_ID],
+ settings: {
+ availability: {
+ type: 'BULK_RECORDS',
+ objectUniversalIdentifier:
+ '99999999-9999-4999-8999-999999999999',
+ },
+ },
+ },
+ },
+ },
+ }),
+ ).toThrow('Workflow trigger: missing object');
+ });
+
it('rejects an unsupported trigger on the server too', () => {
const invalid = structuredClone(manifest);
Object.assign(invalid.version.trigger, { type: 'WEBHOOK' });
diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-workflow-manifest-to-universal-flat-command-menu-item.util.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-workflow-manifest-to-universal-flat-command-menu-item.util.ts
new file mode 100644
index 00000000000..b63e8830a52
--- /dev/null
+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-workflow-manifest-to-universal-flat-command-menu-item.util.ts
@@ -0,0 +1,68 @@
+import {
+ getWorkflowCommandMenuItemUniversalIdentifier,
+ type WorkflowManifest,
+} from 'twenty-shared/application';
+import {
+ CommandMenuItemAvailabilityType,
+ FeatureFlagKey,
+} from 'twenty-shared/types';
+import { isDefined } from 'twenty-shared/utils';
+
+import { EngineComponentKey } from 'src/engine/metadata-modules/command-menu-item/enums/engine-component-key.enum';
+import { type UniversalFlatCommandMenuItem } from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/types/universal-flat-command-menu-item.type';
+
+export const fromWorkflowManifestToUniversalFlatCommandMenuItem = ({
+ manifest,
+ applicationUniversalIdentifier,
+ coreWorkflowVersionId,
+ now,
+}: {
+ manifest: WorkflowManifest;
+ applicationUniversalIdentifier: string;
+ coreWorkflowVersionId: string;
+ now: string;
+}): UniversalFlatCommandMenuItem | null => {
+ const { trigger } = manifest.version;
+ const settings = trigger.type === 'MANUAL' ? trigger.settings : undefined;
+ const availability = settings?.availability;
+
+ if (!isDefined(settings) || !isDefined(availability)) {
+ return null;
+ }
+
+ const isRecordSelection = availability.type !== 'GLOBAL';
+
+ return {
+ universalIdentifier: getWorkflowCommandMenuItemUniversalIdentifier({
+ applicationUniversalIdentifier,
+ workflowUniversalIdentifier: manifest.universalIdentifier,
+ }),
+ applicationUniversalIdentifier,
+ label: manifest.name,
+ shortLabel: manifest.name,
+ position: 0,
+ icon: settings.icon ?? null,
+ isPinned: settings.isPinned ?? false,
+ availabilityType: isRecordSelection
+ ? CommandMenuItemAvailabilityType.RECORD_SELECTION
+ : CommandMenuItemAvailabilityType.GLOBAL,
+ conditionalAvailabilityExpression: `featureFlags.${FeatureFlagKey.IS_WORKFLOW_CORE_INDEX_PAGE_ENABLED}`,
+ conditionalPinnedExpression: null,
+ frontComponentUniversalIdentifier: null,
+ availabilityObjectMetadataUniversalIdentifier: isRecordSelection
+ ? availability.objectUniversalIdentifier
+ : null,
+ navigationTargetObjectMetadataUniversalIdentifier: null,
+ engineComponentKey: EngineComponentKey.TRIGGER_WORKFLOW_VERSION,
+ payload: null,
+ hotKeys: null,
+ workflowVersionId: null,
+ coreWorkflowVersionId,
+ pageLayoutUniversalIdentifier: null,
+ isActive: true,
+ isSystemSideEffect: true,
+ universalOverrides: null,
+ createdAt: now,
+ updatedAt: now,
+ };
+};
diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-workflow-manifest-to-universal-flat-workflow-or-throw.util.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-workflow-manifest-to-universal-flat-workflow-or-throw.util.ts
index df86d77f98d..daea853095d 100644
--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-workflow-manifest-to-universal-flat-workflow-or-throw.util.ts
+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-workflow-manifest-to-universal-flat-workflow-or-throw.util.ts
@@ -1,6 +1,8 @@
import { createHash } from 'crypto';
import { z } from 'zod';
+import { fromWorkflowManifestToUniversalFlatCommandMenuItem } from 'src/engine/core-modules/application/application-manifest/converters/from-workflow-manifest-to-universal-flat-command-menu-item.util';
import { fromWorkflowStepManifestToActionOrThrow } from 'src/engine/core-modules/application/application-manifest/converters/from-workflow-step-manifest-to-action-or-throw.util';
+import { fromWorkflowTriggerManifestToTriggerOrThrow } from 'src/engine/core-modules/application/application-manifest/converters/from-workflow-trigger-manifest-to-trigger-or-throw.util';
import { type WorkflowManifestReferences } from 'src/engine/core-modules/application/application-manifest/types/workflow-manifest-references.type';
import { msg } from '@lingui/core/macro';
import { isDefined } from 'twenty-shared/utils';
@@ -19,10 +21,6 @@ import { v4 } from 'uuid';
import { WorkflowVersionStatus } from 'src/engine/core-modules/workflow/entities/workflow-version.entity';
import { type FlatWorkflow } from 'src/engine/metadata-modules/flat-workflow/types/flat-workflow.type';
import { type FlatWorkflowVersion } from 'src/engine/metadata-modules/flat-workflow-version/types/flat-workflow-version.type';
-import {
- type WorkflowManualTrigger,
- WorkflowTriggerType,
-} from 'src/modules/workflow/workflow-trigger/types/workflow-trigger.type';
import { type UniversalFlatWorkflow } from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/types/universal-flat-workflow.type';
export const fromWorkflowManifestToUniversalFlatWorkflowOrThrow = ({
@@ -70,13 +68,16 @@ export const fromWorkflowManifestToUniversalFlatWorkflowOrThrow = ({
fromWorkflowStepManifestToActionOrThrow({ step, index, references }),
);
- const trigger = {
- ...definition.version.trigger,
- name: 'Manual trigger',
- type: WorkflowTriggerType.MANUAL,
- position: { x: 0, y: 0 },
- settings: { outputSchema: {} },
- } satisfies WorkflowManualTrigger;
+ const trigger = fromWorkflowTriggerManifestToTriggerOrThrow({
+ trigger: definition.version.trigger,
+ references,
+ });
+ const commandMenuItem = fromWorkflowManifestToUniversalFlatCommandMenuItem({
+ manifest: definition,
+ applicationUniversalIdentifier,
+ coreWorkflowVersionId: versionId,
+ now,
+ });
return {
id: workflowId,
universalIdentifier: definition.universalIdentifier,
@@ -107,5 +108,8 @@ export const fromWorkflowManifestToUniversalFlatWorkflowOrThrow = ({
createdAt: existingVersion?.createdAt ?? now,
updatedAt: now,
},
+ ...(isDefined(commandMenuItem)
+ ? { flatUniversalCommandMenuItem: commandMenuItem }
+ : {}),
};
};
diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-workflow-step-manifest-to-action-or-throw.util.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-workflow-step-manifest-to-action-or-throw.util.ts
index 70b5eaf9881..0a725676789 100644
--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-workflow-step-manifest-to-action-or-throw.util.ts
+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-workflow-step-manifest-to-action-or-throw.util.ts
@@ -1,5 +1,6 @@
import { computeWorkflowManifestOutputSchema } from 'src/engine/core-modules/application/application-manifest/utils/compute-workflow-manifest-output-schema.util';
import { computeWorkflowManifestOrderBy } from 'src/engine/core-modules/application/application-manifest/utils/compute-workflow-manifest-order-by.util';
+import { buildWorkflowManifestReferenceResolvers } from 'src/engine/core-modules/application/application-manifest/utils/build-workflow-manifest-reference-resolvers.util';
import { msg } from '@lingui/core/macro';
import { type WorkflowStepManifest } from 'twenty-shared/application';
import { isDefined } from 'twenty-shared/utils';
@@ -21,65 +22,11 @@ export const fromWorkflowStepManifestToActionOrThrow = ({
index: number;
references: WorkflowManifestReferences;
}): WorkflowAction => {
- const resolve = <T>(
- map: ReadonlyMap<string, T> | undefined,
- identifier: string,
- kind: string,
- ): T => {
- const value = map?.get(identifier);
- if (!isDefined(value)) {
- throw new ApplicationException(
- `Workflow step ${step.name}: missing ${kind} ${identifier}`,
- ApplicationExceptionCode.INVALID_INPUT,
- {
- userFriendlyMessage: msg`The workflow references metadata that is not available to this application.`,
- },
- );
- }
- return value;
- };
- const objectName = (identifier: string) =>
- resolve(references.objectByUniversalIdentifier, identifier, 'object')
- .nameSingular;
- const field = (identifier: string, objectUniversalIdentifier?: string) => {
- const resolved = resolve(
- references.fieldByUniversalIdentifier,
- identifier,
- 'field',
- );
- if (
- isDefined(objectUniversalIdentifier) &&
- resolved.objectUniversalIdentifier !== objectUniversalIdentifier
- ) {
- throw new ApplicationException(
- 'Workflow field does not belong to the referenced object',
- ApplicationExceptionCode.INVALID_INPUT,
- {
- userFriendlyMessage: msg`The workflow field does not belong to the referenced object.`,
- },
- );
- }
- return resolved;
- };
- const fieldReference = <
- T extends { fieldMetadataUniversalIdentifier?: string },
- >(
- reference: T,
- objectUniversalIdentifier?: string,
- ) => {
- const { fieldMetadataUniversalIdentifier, ...rest } = reference;
- return {
- ...rest,
- ...(isDefined(fieldMetadataUniversalIdentifier)
- ? {
- fieldMetadataId: field(
- fieldMetadataUniversalIdentifier,
- objectUniversalIdentifier,
- ).id,
- }
- : {}),
- };
- };
+ const { resolve, objectName, field, fieldReference } =
+ buildWorkflowManifestReferenceResolvers({
+ references,
+ subject: `Workflow step ${step.name}`,
+ });
let input: unknown;
switch (step.type) {
case 'LOGIC_FUNCTION':
diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-workflow-trigger-manifest-to-trigger-or-throw.util.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-workflow-trigger-manifest-to-trigger-or-throw.util.ts
new file mode 100644
index 00000000000..499da4b8f1d
--- /dev/null
+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-workflow-trigger-manifest-to-trigger-or-throw.util.ts
@@ -0,0 +1,72 @@
+import { type WorkflowTriggerManifest } from 'twenty-shared/application';
+import { isDefined } from 'twenty-shared/utils';
+
+import { type WorkflowManifestReferences } from 'src/engine/core-modules/application/application-manifest/types/workflow-manifest-references.type';
+import { buildWorkflowManifestReferenceResolvers } from 'src/engine/core-modules/application/application-manifest/utils/build-workflow-manifest-reference-resolvers.util';
+import {
+ type WorkflowManualTrigger,
+ type WorkflowTrigger,
+ WorkflowTriggerType,
+} from 'src/modules/workflow/workflow-trigger/types/workflow-trigger.type';
+
+type WorkflowManifestReferenceResolvers = ReturnType<
+ typeof buildWorkflowManifestReferenceResolvers
+>;
+
+type ManualTriggerManifest = Extract<
+ WorkflowTriggerManifest,
+ { type: 'MANUAL' }
+>;
+
+const fromManualTriggerManifest = ({
+ trigger,
+ resolvers,
+}: {
+ trigger: ManualTriggerManifest;
+ resolvers: WorkflowManifestReferenceResolvers;
+}): WorkflowManualTrigger => {
+ const { settings, ...identity } = trigger;
+ const availability = settings?.availability;
+ const icon = settings?.icon;
+ const isPinned = settings?.isPinned;
+
+ return {
+ ...identity,
+ name: 'Manual trigger',
+ type: WorkflowTriggerType.MANUAL,
+ position: { x: 0, y: 0 },
+ settings: {
+ outputSchema: {},
+ ...(isDefined(icon) ? { icon } : {}),
+ ...(isDefined(isPinned) ? { isPinned } : {}),
+ ...(isDefined(availability)
+ ? {
+ availability:
+ availability.type === 'GLOBAL'
+ ? { type: 'GLOBAL' as const }
+ : {
+ type: availability.type,
+ objectNameSingular: resolvers.objectName(
+ availability.objectUniversalIdentifier,
+ ),
+ },
+ }
+ : {}),
+ },
+ } satisfies WorkflowManualTrigger;
+};
+
+export const fromWorkflowTriggerManifestToTriggerOrThrow = ({
+ trigger,
+ references,
+}: {
+ trigger: WorkflowTriggerManifest;
+ references: WorkflowManifestReferences;
+}): WorkflowTrigger => {
+ const resolvers = buildWorkflowManifestReferenceResolvers({
+ references,
+ subject: 'Workflow trigger',
+ });
+
+ return fromManualTriggerManifest({ trigger, resolvers });
+};
diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/build-workflow-manifest-reference-resolvers.util.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/build-workflow-manifest-reference-resolvers.util.ts
new file mode 100644
index 00000000000..3be7aec4b5d
--- /dev/null
+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/build-workflow-manifest-reference-resolvers.util.ts
@@ -0,0 +1,78 @@
+import { msg } from '@lingui/core/macro';
+import { isDefined } from 'twenty-shared/utils';
+
+import { type WorkflowManifestReferences } from 'src/engine/core-modules/application/application-manifest/types/workflow-manifest-references.type';
+import {
+ ApplicationException,
+ ApplicationExceptionCode,
+} from 'src/engine/core-modules/application/application.exception';
+
+export const buildWorkflowManifestReferenceResolvers = ({
+ references,
+ subject,
+}: {
+ references: WorkflowManifestReferences;
+ subject: string;
+}) => {
+ const resolve = <T>(
+ map: ReadonlyMap<string, T> | undefined,
+ identifier: string,
+ kind: string,
+ ): T => {
+ const value = map?.get(identifier);
+ if (!isDefined(value)) {
+ throw new ApplicationException(
+ `${subject}: missing ${kind} ${identifier}`,
+ ApplicationExceptionCode.INVALID_INPUT,
+ {
+ userFriendlyMessage: msg`The workflow references metadata that is not available to this application.`,
+ },
+ );
+ }
+ return value;
+ };
+ const objectName = (identifier: string) =>
+ resolve(references.objectByUniversalIdentifier, identifier, 'object')
+ .nameSingular;
+ const field = (identifier: string, objectUniversalIdentifier?: string) => {
+ const resolved = resolve(
+ references.fieldByUniversalIdentifier,
+ identifier,
+ 'field',
+ );
+ if (
+ isDefined(objectUniversalIdentifier) &&
+ resolved.objectUniversalIdentifier !== objectUniversalIdentifier
+ ) {
+ throw new ApplicationException(
+ 'Workflow field does not belong to the referenced object',
+ ApplicationExceptionCode.INVALID_INPUT,
+ {
+ userFriendlyMessage: msg`The workflow field does not belong to the referenced object.`,
+ },
+ );
+ }
+ return resolved;
+ };
+ const fieldReference = <
+ T extends { fieldMetadataUniversalIdentifier?: string },
+ >(
+ reference: T,
+ objectUniversalIdentifier?: string,
+ ) => {
+ const { fieldMetadataUniversalIdentifier, ...rest } = reference;
+ return {
+ ...rest,
+ ...(isDefined(fieldMetadataUniversalIdentifier)
+ ? {
+ fieldMetadataId: field(
+ fieldMetadataUniversalIdentifier,
+ objectUniversalIdentifier,
+ ).id,
+ }
+ : {}),
+ };
+ };
+
+ return { resolve, objectName, field, fieldReference };
+};
diff --git a/packages/twenty-server/src/engine/metadata-modules/metadata-side-effect/handlers/workflow/utils/__tests__/build-workflow-version-side-effects.util.spec.ts b/packages/twenty-server/src/engine/metadata-modules/metadata-side-effect/handlers/workflow/utils/__tests__/build-workflow-version-side-effects.util.spec.ts
index e0359122193..aa0a8a9554a 100644
--- a/packages/twenty-server/src/engine/metadata-modules/metadata-side-effect/handlers/workflow/utils/__tests__/build-workflow-version-side-effects.util.spec.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/metadata-side-effect/handlers/workflow/utils/__tests__/build-workflow-version-side-effects.util.spec.ts
@@ -1,6 +1,8 @@
+import { WorkflowTriggerType } from 'src/modules/workflow/workflow-trigger/types/workflow-trigger.type';
import { buildWorkflowVersionSideEffects } from 'src/engine/metadata-modules/metadata-side-effect/handlers/workflow/utils/build-workflow-version-side-effects.util';
import { validateApplicationWorkflowVersion } from 'src/engine/workspace-manager/workspace-migration/workspace-migration-builder/validators/utils/validate-application-workflow-version.util';
import {
+ getWorkflowCommandMenuItemUniversalIdentifier,
getWorkflowVersionUniversalIdentifier,
type WorkflowManifest,
} from 'twenty-shared/application';
@@ -8,6 +10,7 @@ import { isDefined } from 'twenty-shared/utils';
import { fromWorkflowManifestToUniversalFlatWorkflowOrThrow } from 'src/engine/core-modules/application/application-manifest/converters/from-workflow-manifest-to-universal-flat-workflow-or-throw.util';
import { buildAllFlatEntityOperationRecordByMetadataNameFromFromTo } from 'src/engine/core-modules/application/application-manifest/utils/build-all-flat-entity-operation-record-by-metadata-name-from-from-to.util';
+import { type FlatCommandMenuItem } from 'src/engine/metadata-modules/flat-command-menu-item/types/flat-command-menu-item.type';
import { createEmptyAllFlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/constant/create-empty-all-flat-entity-maps.constant';
import { type FlatWorkflow } from 'src/engine/metadata-modules/flat-workflow/types/flat-workflow.type';
import { flatEntityToScalarFlatEntity } from 'src/engine/workspace-manager/workspace-migration/workspace-migration-runner/utils/flat-entity-to-scalar-flat-entity.util';
@@ -68,10 +71,34 @@ const convert = (
return { workflow, version };
};
+const WORKSPACE_APPLICATION_ID = '77777777-7777-4777-8777-777777777777';
+const COMMAND_MENU_ITEM_ID = getWorkflowCommandMenuItemUniversalIdentifier({
+ applicationUniversalIdentifier: APPLICATION_ID,
+ workflowUniversalIdentifier: WORKFLOW_ID,
+});
+
const persisted = ({ workflow, version }: ReturnType<typeof convert>) => {
const maps = createEmptyAllFlatEntityMaps();
- const { flatUniversalWorkflowVersion: _payload, ...storedWorkflow } =
- workflow;
+ const {
+ flatUniversalWorkflowVersion: _payload,
+ flatUniversalCommandMenuItem: commandMenuItem,
+ ...storedWorkflow
+ } = workflow;
+ if (isDefined(commandMenuItem)) {
+ const storedCommandMenuItem: FlatCommandMenuItem = {
+ ...commandMenuItem,
+ id: '66666666-6666-4666-8666-666666666666',
+ workspaceId: APPLICATION_ID,
+ applicationId: APPLICATION_ID,
+ overrides: null,
+ frontComponentId: null,
+ availabilityObjectMetadataId: null,
+ navigationTargetObjectMetadataId: null,
+ pageLayoutId: null,
+ };
+ maps.flatCommandMenuItemMaps.byUniversalIdentifier[COMMAND_MENU_ITEM_ID] =
+ storedCommandMenuItem;
+ }
maps.flatWorkflowMaps.byUniversalIdentifier[WORKFLOW_ID] = {
...storedWorkflow,
workspaceId: APPLICATION_ID,
@@ -133,6 +160,7 @@ describe('application workflow version side effects', () => {
flatEntity: workflow as FlatWorkflow,
}),
).not.toHaveProperty('flatUniversalWorkflowVersion');
+ expect(operations.commandMenuItem).toBeUndefined();
});
it('updates the same version for a graph-only change without mutating the previous definition', () => {
@@ -200,6 +228,71 @@ describe('application workflow version side effects', () => {
});
});
+describe('application workflow command menu item side effects', () => {
+ const withAvailability = (icon: string) => {
+ const definition = structuredClone(manifest);
+ definition.version.trigger = {
+ ...manifest.version.trigger,
+ type: 'MANUAL',
+ settings: { availability: { type: 'GLOBAL' }, icon, isPinned: true },
+ };
+ return definition;
+ };
+
+ it('creates the command menu item next to its version, owned by the engine', () => {
+ const { workflow, version } = convert(withAvailability('IconBolt'));
+ const operations = expand(workflow);
+ expect(
+ operations.commandMenuItem?.flatEntityToCreate?.[COMMAND_MENU_ITEM_ID],
+ ).toMatchObject({
+ coreWorkflowVersionId: version.id,
+ icon: 'IconBolt',
+ isSystemSideEffect: true,
+ });
+ expect(
+ flatEntityToScalarFlatEntity({
+ metadataName: 'workflow',
+ flatEntity: workflow as FlatWorkflow,
+ }),
+ ).not.toHaveProperty('flatUniversalCommandMenuItem');
+ });
+
+ it('updates the command menu item in place and keeps what the workspace changed', () => {
+ const existing = persisted(convert(withAvailability('IconBolt')));
+ const storedCommandMenuItem =
+ existing.flatCommandMenuItemMaps.byUniversalIdentifier[
+ COMMAND_MENU_ITEM_ID
+ ]!;
+ storedCommandMenuItem.position = 7;
+ storedCommandMenuItem.universalOverrides = {
+ [WORKSPACE_APPLICATION_ID]: { isPinned: false },
+ };
+ const { workflow } = convert(withAvailability('IconRocket'), existing);
+ expect(
+ expand(workflow, existing).commandMenuItem?.flatEntityToUpdate?.[
+ COMMAND_MENU_ITEM_ID
+ ],
+ ).toMatchObject({
+ icon: 'IconRocket',
+ position: 7,
+ universalOverrides: { [WORKSPACE_APPLICATION_ID]: { isPinned: false } },
+ });
+ });
+
+ it('deletes the command menu item once the trigger no longer declares an availability', () => {
+ const existing = persisted(convert(withAvailability('IconBolt')));
+ const { workflow } = convert(manifest, existing);
+ expect(
+ expand(workflow, existing).commandMenuItem?.flatEntityToDelete,
+ ).toEqual({
+ [COMMAND_MENU_ITEM_ID]:
+ existing.flatCommandMenuItemMaps.byUniversalIdentifier[
+ COMMAND_MENU_ITEM_ID
+ ],
+ });
+ });
+});
+
const validate = (version: ReturnType<typeof convert>['version']) => ({
errors: validateApplicationWorkflowVersion({ version }),
});
@@ -215,6 +308,17 @@ describe('managed workflow version validation', () => {
expect(validate(version).errors.length).toBeGreaterThan(1);
});
+ it('refuses a trigger type applications cannot use', () => {
+ const { version } = convert();
+ const [trigger] = version.triggers ?? [];
+ expect(
+ validate({
+ ...version,
+ triggers: [{ ...trigger, type: WorkflowTriggerType.WEBHOOK }],
+ } as typeof version).errors[0]?.message,
+ ).toContain('Application workflows require one trigger of type MANUAL');
+ });
+
it('validates a managed definition but leaves API definitions unchanged', () => {
const definition = convert();
const invalid = { ...definition.version, triggers: null };
diff --git a/packages/twenty-server/src/engine/metadata-modules/metadata-side-effect/handlers/workflow/utils/build-workflow-version-side-effects.util.ts b/packages/twenty-server/src/engine/metadata-modules/metadata-side-effect/handlers/workflow/utils/build-workflow-version-side-effects.util.ts
index 02d74bfd34a..e3976bfd0db 100644
--- a/packages/twenty-server/src/engine/metadata-modules/metadata-side-effect/handlers/workflow/utils/build-workflow-version-side-effects.util.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/metadata-side-effect/handlers/workflow/utils/build-workflow-version-side-effects.util.ts
@@ -1,8 +1,13 @@
-import { getWorkflowVersionUniversalIdentifier } from 'twenty-shared/application';
+import {
+ getWorkflowCommandMenuItemUniversalIdentifier,
+ getWorkflowVersionUniversalIdentifier,
+} from 'twenty-shared/application';
import { isDefined } from 'twenty-shared/utils';
import { type BuildSideEffectsArgs } from 'src/engine/metadata-modules/metadata-side-effect/interfaces/base-metadata-side-effect-handler.service';
+import { type MetadataSideEffectOperationsByMetadataName } from 'src/engine/metadata-modules/metadata-side-effect/types/metadata-side-effect-operations-by-metadata-name.type';
import { type MetadataSideEffectResult } from 'src/engine/metadata-modules/metadata-side-effect/types/metadata-side-effect-result.type';
+import { type UniversalFlatWorkflow } from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/types/universal-flat-workflow.type';
export const buildWorkflowVersionSideEffects = ({
flatEntity,
@@ -34,6 +39,62 @@ export const buildWorkflowVersionSideEffects = ({
[universalIdentifier]: { ...version, universalIdentifier },
},
},
+ ...buildWorkflowCommandMenuItemOperations({
+ flatEntity,
+ relatedFlatEntityMaps,
+ }),
+ },
+ };
+};
+
+const buildWorkflowCommandMenuItemOperations = ({
+ flatEntity,
+ relatedFlatEntityMaps,
+}: {
+ flatEntity: UniversalFlatWorkflow;
+ relatedFlatEntityMaps: BuildSideEffectsArgs<'workflow'>['relatedFlatEntityMaps'];
+}): MetadataSideEffectOperationsByMetadataName => {
+ const commandMenuItem = flatEntity.flatUniversalCommandMenuItem;
+ const universalIdentifier = getWorkflowCommandMenuItemUniversalIdentifier({
+ applicationUniversalIdentifier: flatEntity.applicationUniversalIdentifier,
+ workflowUniversalIdentifier: flatEntity.universalIdentifier,
+ });
+ const existingCommandMenuItem =
+ relatedFlatEntityMaps.flatCommandMenuItemMaps.byUniversalIdentifier[
+ universalIdentifier
+ ];
+
+ if (!isDefined(commandMenuItem)) {
+ return isDefined(existingCommandMenuItem)
+ ? {
+ commandMenuItem: {
+ flatEntityToDelete: {
+ [universalIdentifier]: existingCommandMenuItem,
+ },
+ },
+ }
+ : {};
+ }
+
+ if (!isDefined(existingCommandMenuItem)) {
+ return {
+ commandMenuItem: {
+ flatEntityToCreate: { [universalIdentifier]: commandMenuItem },
+ },
+ };
+ }
+
+ return {
+ commandMenuItem: {
+ flatEntityToUpdate: {
+ [universalIdentifier]: {
+ ...commandMenuItem,
+ position: existingCommandMenuItem.position,
+ isActive: existingCommandMenuItem.isActive,
+ universalOverrides: existingCommandMenuItem.universalOverrides,
+ createdAt: existingCommandMenuItem.createdAt,
+ },
+ },
},
};
};
diff --git a/packages/twenty-server/src/engine/workspace-manager/workspace-migration/universal-flat-entity/types/universal-flat-workflow.type.ts b/packages/twenty-server/src/engine/workspace-manager/workspace-migration/universal-flat-entity/types/universal-flat-workflow.type.ts
index 46758050604..506a94b2b04 100644
--- a/packages/twenty-server/src/engine/workspace-manager/workspace-migration/universal-flat-entity/types/universal-flat-workflow.type.ts
+++ b/packages/twenty-server/src/engine/workspace-manager/workspace-migration/universal-flat-entity/types/universal-flat-workflow.type.ts
@@ -1,3 +1,4 @@
+import { type UniversalFlatCommandMenuItem } from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/types/universal-flat-command-menu-item.type';
import { type UniversalFlatWorkflowVersion } from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/types/universal-flat-workflow-version.type';
import { type WorkflowEntity } from 'src/engine/core-modules/workflow/entities/workflow.entity';
import { type UniversalFlatEntityFrom } from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/types/universal-flat-entity-from.type';
@@ -7,4 +8,5 @@ export type UniversalFlatWorkflow = UniversalFlatEntityFrom<
'workflow'
> & {
flatUniversalWorkflowVersion?: UniversalFlatWorkflowVersion & { id: string };
+ flatUniversalCommandMenuItem?: UniversalFlatCommandMenuItem;
};
diff --git a/packages/twenty-server/src/engine/workspace-manager/workspace-migration/workspace-migration-builder/validators/utils/validate-application-workflow-version.util.ts b/packages/twenty-server/src/engine/workspace-manager/workspace-migration/workspace-migration-builder/validators/utils/validate-application-workflow-version.util.ts
index f1e9c1e4581..f8a24bfd439 100644
--- a/packages/twenty-server/src/engine/workspace-manager/workspace-migration/workspace-migration-builder/validators/utils/validate-application-workflow-version.util.ts
+++ b/packages/twenty-server/src/engine/workspace-manager/workspace-migration/workspace-migration-builder/validators/utils/validate-application-workflow-version.util.ts
@@ -1,4 +1,5 @@
import { msg } from '@lingui/core/macro';
+import { APPLICATION_WORKFLOW_TRIGGER_TYPES } from 'twenty-shared/application';
import { isDefined } from 'twenty-shared/utils';
import {
buildWorkflowGraph,
@@ -27,9 +28,11 @@ export const validateApplicationWorkflowVersion = ({
if (
!isDefined(trigger) ||
version.triggers?.length !== 1 ||
- trigger.type !== 'MANUAL'
+ !APPLICATION_WORKFLOW_TRIGGER_TYPES.includes(trigger.type)
) {
- messages.push('Application workflows require one manual trigger');
+ messages.push(
+ `Application workflows require one trigger of type ${APPLICATION_WORKFLOW_TRIGGER_TYPES.join(', ')}`,
+ );
} else {
const identities = [
version.universalIdentifier,
diff --git a/packages/twenty-shared/src/application/__tests__/workflowManifestType.spec.ts b/packages/twenty-shared/src/application/__tests__/workflowManifestType.spec.ts
index 38a57b0da0b..3e5600728df 100644
--- a/packages/twenty-shared/src/application/__tests__/workflowManifestType.spec.ts
+++ b/packages/twenty-shared/src/application/__tests__/workflowManifestType.spec.ts
@@ -140,3 +140,66 @@ describe('workflow manifest step types', () => {
},
);
});
+
+describe('workflow manifest manual trigger', () => {
+ const OBJECT_ID = '99999999-9999-4999-8999-999999999999';
+
+ const withTrigger = (trigger: Record<string, unknown>) => ({
+ ...workflow,
+ version: {
+ ...workflow.version,
+ trigger: { ...workflow.version.trigger, ...trigger },
+ },
+ });
+
+ it('accepts where the workflow can be launched from', () => {
+ for (const availability of [
+ { type: 'GLOBAL' },
+ { type: 'SINGLE_RECORD', objectUniversalIdentifier: OBJECT_ID },
+ { type: 'BULK_RECORDS', objectUniversalIdentifier: OBJECT_ID },
+ ]) {
+ expect(
+ workflowManifestSchema.safeParse(
+ withTrigger({ settings: { availability, icon: 'IconBolt' } }),
+ ).success,
+ ).toBe(true);
+ }
+ });
+
+ it('requires the object a record availability runs on', () => {
+ const result = workflowManifestSchema.safeParse(
+ withTrigger({ settings: { availability: { type: 'SINGLE_RECORD' } } }),
+ );
+ expect(result.success).toBe(false);
+ expect(result.error?.issues[0]?.path).toEqual([
+ 'version',
+ 'trigger',
+ 'settings',
+ 'availability',
+ 'objectUniversalIdentifier',
+ ]);
+ });
+
+ it('needs an availability before an icon or pin can show in the command menu', () => {
+ const result = workflowManifestSchema.safeParse(
+ withTrigger({ settings: { isPinned: true } }),
+ );
+ expect(result.success).toBe(false);
+ expect(result.error?.issues[0]?.path).toEqual([
+ 'version',
+ 'trigger',
+ 'settings',
+ 'availability',
+ ]);
+ });
+
+ it('names the supported trigger types when the type is unknown', () => {
+ const result = workflowManifestSchema.safeParse(
+ withTrigger({ type: 'WEBHOOK' }),
+ );
+ expect(result.success).toBe(false);
+ expect(result.error?.issues[0]?.message).toBe(
+ 'Unsupported trigger type. Application workflows support: MANUAL',
+ );
+ });
+});
diff --git a/packages/twenty-shared/src/application/deterministic-identifier/__tests__/get-workflow-command-menu-item-universal-identifier.util.spec.ts b/packages/twenty-shared/src/application/deterministic-identifier/__tests__/get-workflow-command-menu-item-universal-identifier.util.spec.ts
new file mode 100644
index 00000000000..383290d70f3
--- /dev/null
+++ b/packages/twenty-shared/src/application/deterministic-identifier/__tests__/get-workflow-command-menu-item-universal-identifier.util.spec.ts
@@ -0,0 +1,41 @@
+import { getWorkflowCommandMenuItemUniversalIdentifier } from '@/application/deterministic-identifier/get-workflow-command-menu-item-universal-identifier.util';
+import { getWorkflowVersionUniversalIdentifier } from '@/application/deterministic-identifier/get-workflow-version-universal-identifier.util';
+
+const APP = '11111111-1111-4111-8111-111111111111';
+const WORKFLOW = '22222222-2222-4222-8222-222222222222';
+
+describe('getWorkflowCommandMenuItemUniversalIdentifier', () => {
+ it('derives a deterministic id from the workflow within its application', () => {
+ const identifier = getWorkflowCommandMenuItemUniversalIdentifier({
+ applicationUniversalIdentifier: APP,
+ workflowUniversalIdentifier: WORKFLOW,
+ });
+
+ expect(identifier).toBe(
+ getWorkflowCommandMenuItemUniversalIdentifier({
+ applicationUniversalIdentifier: APP,
+ workflowUniversalIdentifier: WORKFLOW,
+ }),
+ );
+ expect(identifier).not.toBe(
+ getWorkflowVersionUniversalIdentifier({
+ applicationUniversalIdentifier: APP,
+ workflowUniversalIdentifier: WORKFLOW,
+ }),
+ );
+ });
+
+ it('gives each workflow its own command menu item identifier', () => {
+ expect(
+ getWorkflowCommandMenuItemUniversalIdentifier({
+ applicationUniversalIdentifier: APP,
+ workflowUniversalIdentifier: WORKFLOW,
+ }),
+ ).not.toBe(
+ getWorkflowCommandMenuItemUniversalIdentifier({
+ applicationUniversalIdentifier: APP,
+ workflowUniversalIdentifier: '33333333-3333-4333-8333-333333333333',
+ }),
+ );
+ });
+});
diff --git a/packages/twenty-shared/src/application/deterministic-identifier/get-workflow-command-menu-item-universal-identifier.util.ts b/packages/twenty-shared/src/application/deterministic-identifier/get-workflow-command-menu-item-universal-identifier.util.ts
new file mode 100644
index 00000000000..3a174e25f2e
--- /dev/null
+++ b/packages/twenty-shared/src/application/deterministic-identifier/get-workflow-command-menu-item-universal-identifier.util.ts
@@ -0,0 +1,16 @@
+import { computeDeterministicUuid } from '@/application/deterministic-identifier/compute-deterministic-uuid.util';
+
+const WORKFLOW_COMMAND_DISCRIMINATOR = 'workflow';
+
+export const getWorkflowCommandMenuItemUniversalIdentifier = ({
+ applicationUniversalIdentifier,
+ workflowUniversalIdentifier,
+}: {
+ applicationUniversalIdentifier: string;
+ workflowUniversalIdentifier: string;
+}): string =>
+ computeDeterministicUuid({
+ entityNamespace: 'commandMenuItem',
+ value: `${workflowUniversalIdentifier}:${WORKFLOW_COMMAND_DISCRIMINATOR}`,
+ applicationUniversalIdentifier,
+ });
diff --git a/packages/twenty-shared/src/application/index.ts b/packages/twenty-shared/src/application/index.ts
index 3d31fce23e7..d877914913a 100644
--- a/packages/twenty-shared/src/application/index.ts
+++ b/packages/twenty-shared/src/application/index.ts
@@ -151,6 +151,7 @@ export { getViewFilterUniversalIdentifier } from './deterministic-identifier/get
export { getViewGroupUniversalIdentifier } from './deterministic-identifier/get-view-group-universal-identifier.util';
export { getViewSortUniversalIdentifier } from './deterministic-identifier/get-view-sort-universal-identifier.util';
export { getViewUniversalIdentifier } from './deterministic-identifier/get-view-universal-identifier.util';
+export { getWorkflowCommandMenuItemUniversalIdentifier } from './deterministic-identifier/get-workflow-command-menu-item-universal-identifier.util';
export { getWorkflowVersionUniversalIdentifier } from './deterministic-identifier/get-workflow-version-universal-identifier.util';
export type {
EnqueueJobOptions,
@@ -287,3 +288,8 @@ export type { WorkflowManifest } from './workflowManifestType';
export { workflowManifestSchema } from './workflowManifestType';
export type { WorkflowStepManifest } from './workflowStepManifestType';
export { workflowStepManifestSchema } from './workflowStepManifestType';
+export type { WorkflowTriggerManifest } from './workflowTriggerManifestType';
+export {
+ APPLICATION_WORKFLOW_TRIGGER_TYPES,
+ workflowTriggerManifestSchema,
+} from './workflowTriggerManifestType';
diff --git a/packages/twenty-shared/src/application/workflowManifestType.ts b/packages/twenty-shared/src/application/workflowManifestType.ts
index 0a0fa55ab7e..5bcdc1e26e5 100644
--- a/packages/twenty-shared/src/application/workflowManifestType.ts
+++ b/packages/twenty-shared/src/application/workflowManifestType.ts
@@ -3,6 +3,7 @@ import { z } from 'zod';
import { validateWorkflowVariableReferences } from '@/workflow/validation/utils/validate-workflow-variable-references.util';
import { workflowStepManifestSchema } from '@/application/workflowStepManifestType';
+import { workflowTriggerManifestSchema } from '@/application/workflowTriggerManifestType';
import { buildWorkflowGraph } from '@/workflow/validation/utils/build-workflow-graph.util';
import { validateWorkflowExecutionPaths } from '@/workflow/validation/utils/validate-workflow-execution-paths.util';
import { validateWorkflowGraph } from '@/workflow/validation/utils/validate-workflow-graph.util';
@@ -12,11 +13,7 @@ export const workflowManifestSchema = z
universalIdentifier: z.uuid(),
name: z.string().min(1),
version: z.strictObject({
- trigger: z.strictObject({
- universalIdentifier: z.uuid(),
- type: z.literal('MANUAL'),
- nextStepIds: z.array(z.uuid()).min(1),
- }),
+ trigger: workflowTriggerManifestSchema,
steps: z.array(workflowStepManifestSchema).min(1),
}),
})
@@ -37,7 +34,7 @@ export const workflowManifestSchema = z
}
const validatableWorkflow = {
- trigger,
+ trigger: { type: trigger.type, nextStepIds: trigger.nextStepIds },
steps: steps.map((step) => ({
...step,
id: step.universalIdentifier,
diff --git a/packages/twenty-shared/src/application/workflowTriggerManifestType.ts b/packages/twenty-shared/src/application/workflowTriggerManifestType.ts
new file mode 100644
index 00000000000..aab4450d4c8
--- /dev/null
+++ b/packages/twenty-shared/src/application/workflowTriggerManifestType.ts
@@ -0,0 +1,61 @@
+import { z } from 'zod';
+
+import { isDefined } from '@/utils/validation/isDefined';
+
+const manualTriggerAvailabilityManifestSchema = z.discriminatedUnion('type', [
+ z.strictObject({ type: z.literal('GLOBAL') }),
+ z.strictObject({
+ type: z.literal('SINGLE_RECORD'),
+ objectUniversalIdentifier: z.uuid(),
+ }),
+ z.strictObject({
+ type: z.literal('BULK_RECORDS'),
+ objectUniversalIdentifier: z.uuid(),
+ }),
+]);
+
+const workflowTriggerManifestOptions = [
+ z.strictObject({
+ universalIdentifier: z.uuid(),
+ type: z.literal('MANUAL'),
+ nextStepIds: z.array(z.uuid()).min(1),
+ settings: z
+ .strictObject({
+ availability: manualTriggerAvailabilityManifestSchema.optional(),
+ icon: z.string().optional(),
+ isPinned: z.boolean().optional(),
+ })
+ .superRefine((settings, context) => {
+ if (
+ !isDefined(settings.availability) &&
+ (isDefined(settings.icon) || isDefined(settings.isPinned))
+ ) {
+ context.addIssue({
+ code: 'custom',
+ path: ['availability'],
+ message:
+ 'Set an availability for the icon and pin to show in the command menu',
+ });
+ }
+ })
+ .optional(),
+ }),
+] as const;
+
+export const APPLICATION_WORKFLOW_TRIGGER_TYPES: readonly string[] =
+ workflowTriggerManifestOptions.map((option) => option.shape.type.value);
+
+export const workflowTriggerManifestSchema = z.discriminatedUnion(
+ 'type',
+ workflowTriggerManifestOptions,
+ {
+ error: (issue) =>
+ issue.code === 'invalid_union'
+ ? `Unsupported trigger type. Application workflows support: ${APPLICATION_WORKFLOW_TRIGGER_TYPES.join(', ')}`
+ : undefined,
+ },
+);
+
+export type WorkflowTriggerManifest = z.infer<
+ typeof workflowTriggerManifestSchema
+>;