Skip to content

The open alternative to Salesforce, designed for AI.

Let the workspace custom application's workflows call other apps' actions (#28927)

Félix Malfaitaeb41adc36f0
diff --git a/packages/twenty-docs/developers/extend/apps/logic/workflows.mdx b/packages/twenty-docs/developers/extend/apps/logic/workflows.mdx
index d33064887a0..bb3f94674a9 100644
--- a/packages/twenty-docs/developers/extend/apps/logic/workflows.mdx
+++ b/packages/twenty-docs/developers/extend/apps/logic/workflows.mdx
@@ -76,7 +76,7 @@ Key points:
Steps and triggers point at metadata by universal identifier, never by name or id:
- **Objects and fields**: your app's own, or standard ones through `STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS`. The example above assumes the app also defines a `leadScore` number field on Company with [`defineField()`](/developers/extend/apps/data/extending-objects): a record step that writes a field missing from the workspace fails the install.
-- **Logic functions**: your app's own, exposed as a [workflow action](/developers/extend/apps/logic/logic-functions#exposing-a-function-as-an-ai-tool-or-workflow-action) with `workflowActionTriggerSettings`.
+- **Logic functions**: your app's own, exposed as a [workflow action](/developers/extend/apps/logic/logic-functions#exposing-a-function-as-an-ai-tool-or-workflow-action) with `workflowActionTriggerSettings`. The workspace Custom application can also reference the workflow actions of the other apps installed in the workspace, as workflows built in the app can.
- **Agents**: your app's own, from [`defineAgent()`](/developers/extend/apps/logic/skills-and-agents).
A reference Twenty can't resolve fails the install.
diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/application-manifest-migration.service.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/application-manifest-migration.service.ts
index 4df7e5f0b4e..4003924b521 100644
--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/application-manifest-migration.service.ts
+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/application-manifest-migration.service.ts
@@ -221,13 +221,22 @@ export class ApplicationManifestMigrationService {
inferDeletionFromMissingEntities,
});
- const idByUniversalIdentifierByMetadataName =
- (manifest.workflows ?? []).length > 0
- ? preallocateWorkflowReferenceIds({
- fromAllFlatEntityMaps,
- toAllUniversalFlatEntityMaps,
- })
- : {};
+ const hasWorkflows = (manifest.workflows ?? []).length > 0;
+
+ const workspaceCustomFlatApplication = hasWorkflows
+ ? (
+ await this.applicationService.findWorkspaceTwentyStandardAndCustomApplicationOrThrow(
+ { workspaceId },
+ )
+ ).workspaceCustomFlatApplication
+ : undefined;
+
+ const idByUniversalIdentifierByMetadataName = hasWorkflows
+ ? preallocateWorkflowReferenceIds({
+ fromAllFlatEntityMaps,
+ toAllUniversalFlatEntityMaps,
+ })
+ : {};
const applicationWorkflows = addWorkflowManifestsToFlatEntityMapsOrThrow({
workflows: manifest.workflows ?? [],
@@ -236,6 +245,9 @@ export class ApplicationManifestMigrationService {
toAllUniversalFlatEntityMaps,
existingAllFlatEntityMaps,
idByUniversalIdentifierByMetadataName,
+ // Its workflows run as workspace workflows, which may already call any app's actions
+ canReferenceOtherApplicationsWorkflowActions:
+ ownerFlatApplication.id === workspaceCustomFlatApplication?.id,
now,
});
diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/__tests__/add-workflow-manifests-to-flat-entity-maps-or-throw.util.spec.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/__tests__/add-workflow-manifests-to-flat-entity-maps-or-throw.util.spec.ts
index 3eb0c3f8808..3867093dcbb 100644
--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/__tests__/add-workflow-manifests-to-flat-entity-maps-or-throw.util.spec.ts
+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/__tests__/add-workflow-manifests-to-flat-entity-maps-or-throw.util.spec.ts
@@ -63,6 +63,7 @@ const compute = ({
toAllUniversalFlatEntityMaps,
existingAllFlatEntityMaps: fromAllFlatEntityMaps,
idByUniversalIdentifierByMetadataName: {},
+ canReferenceOtherApplicationsWorkflowActions: false,
now: '2026-09-28T00:00:00.000Z',
});
diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/__tests__/prepare-workflow-manifest-references.util.spec.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/__tests__/prepare-workflow-manifest-references.util.spec.ts
index e1ea0d5c69a..efe2f01ad48 100644
--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/__tests__/prepare-workflow-manifest-references.util.spec.ts
+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/__tests__/prepare-workflow-manifest-references.util.spec.ts
@@ -131,4 +131,86 @@ describe('workflow manifest references', () => {
expect(references.fieldByUniversalIdentifier?.has('field')).toBe(false);
expect(references.agentIdByUniversalIdentifier?.size).toBe(0);
});
+
+ describe("other applications' workflow actions", () => {
+ const installedWithOtherApplicationFunctions = () => {
+ const installed = createEmptyAllFlatEntityMaps();
+ const otherApplicationFunction = (
+ overrides: Partial<FlatLogicFunction>,
+ ) =>
+ ({
+ applicationId: 'other-application',
+ deletedAt: null,
+ workflowActionTriggerSettings: {
+ outputSchema: [
+ { type: 'object', properties: { matched: { type: 'number' } } },
+ ],
+ },
+ ...overrides,
+ }) as FlatLogicFunction;
+ installed.flatLogicFunctionMaps.byUniversalIdentifier.enrich =
+ otherApplicationFunction({
+ id: 'enrich-id',
+ universalIdentifier: 'enrich',
+ });
+ installed.flatLogicFunctionMaps.byUniversalIdentifier.internal =
+ otherApplicationFunction({
+ id: 'internal-id',
+ universalIdentifier: 'internal',
+ workflowActionTriggerSettings: null,
+ });
+ installed.flatLogicFunctionMaps.byUniversalIdentifier.removed =
+ otherApplicationFunction({
+ id: 'removed-id',
+ universalIdentifier: 'removed',
+ deletedAt: '2026-10-26T00:00:00.000Z',
+ });
+ installed.flatLogicFunctionMaps.byUniversalIdentifier.dropped =
+ otherApplicationFunction({
+ id: 'dropped-id',
+ universalIdentifier: 'dropped',
+ applicationId: OWNER,
+ });
+ return installed;
+ };
+
+ it('are resolved when the owner may reference them', () => {
+ const references = prepareWorkflowManifestReferences({
+ existingAllFlatEntityMaps: installedWithOtherApplicationFunctions(),
+ toAllUniversalFlatEntityMaps: createEmptyAllFlatEntityMaps(),
+ ownerApplicationId: OWNER,
+ idByUniversalIdentifierByMetadataName: {},
+ canReferenceOtherApplicationsWorkflowActions: true,
+ });
+
+ expect(
+ references.logicFunctionIdByUniversalIdentifier.get('enrich'),
+ ).toBe('enrich-id');
+ expect(
+ references.logicFunctionOutputSchemaByUniversalIdentifier?.get(
+ 'enrich',
+ ),
+ ).toMatchObject({ matched: { isLeaf: true, type: 'number' } });
+ expect(
+ references.logicFunctionIdByUniversalIdentifier.has('internal'),
+ ).toBe(false);
+ expect(
+ references.logicFunctionIdByUniversalIdentifier.has('removed'),
+ ).toBe(false);
+ expect(
+ references.logicFunctionIdByUniversalIdentifier.has('dropped'),
+ ).toBe(false);
+ });
+
+ it('are not resolved otherwise', () => {
+ const references = prepareWorkflowManifestReferences({
+ existingAllFlatEntityMaps: installedWithOtherApplicationFunctions(),
+ toAllUniversalFlatEntityMaps: createEmptyAllFlatEntityMaps(),
+ ownerApplicationId: OWNER,
+ idByUniversalIdentifierByMetadataName: {},
+ });
+
+ expect(references.logicFunctionIdByUniversalIdentifier.size).toBe(0);
+ });
+ });
});
diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/add-workflow-manifests-to-flat-entity-maps-or-throw.util.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/add-workflow-manifests-to-flat-entity-maps-or-throw.util.ts
index 2d65fc9a2af..44ee82cd303 100644
--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/add-workflow-manifests-to-flat-entity-maps-or-throw.util.ts
+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/add-workflow-manifests-to-flat-entity-maps-or-throw.util.ts
@@ -25,6 +25,7 @@ export const addWorkflowManifestsToFlatEntityMapsOrThrow = ({
toAllUniversalFlatEntityMaps,
existingAllFlatEntityMaps,
idByUniversalIdentifierByMetadataName,
+ canReferenceOtherApplicationsWorkflowActions,
now,
}: {
workflows: WorkflowManifest[];
@@ -33,6 +34,7 @@ export const addWorkflowManifestsToFlatEntityMapsOrThrow = ({
toAllUniversalFlatEntityMaps: AllFlatEntityMaps;
existingAllFlatEntityMaps: AllFlatEntityMaps;
idByUniversalIdentifierByMetadataName: IdByUniversalIdentifierByMetadataName;
+ canReferenceOtherApplicationsWorkflowActions: boolean;
now: string;
}): (UniversalFlatWorkflow & { id: string })[] => {
const applicationUniversalIdentifier =
@@ -45,6 +47,7 @@ export const addWorkflowManifestsToFlatEntityMapsOrThrow = ({
existingAllFlatEntityMaps,
ownerApplicationId: ownerFlatApplication.id,
idByUniversalIdentifierByMetadataName,
+ canReferenceOtherApplicationsWorkflowActions,
});
const recordFieldErrors: string[] = [];
for (const workflowManifest of workflows) {
diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/prepare-workflow-manifest-references.util.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/prepare-workflow-manifest-references.util.ts
index 5781206a92a..d2e75254763 100644
--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/prepare-workflow-manifest-references.util.ts
+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/prepare-workflow-manifest-references.util.ts
@@ -16,11 +16,13 @@ export const prepareWorkflowManifestReferences = ({
existingAllFlatEntityMaps,
ownerApplicationId,
idByUniversalIdentifierByMetadataName,
+ canReferenceOtherApplicationsWorkflowActions = false,
}: {
toAllUniversalFlatEntityMaps: AllFlatEntityMaps;
existingAllFlatEntityMaps: AllFlatEntityMaps;
ownerApplicationId: string;
idByUniversalIdentifierByMetadataName: IdByUniversalIdentifierByMetadataName;
+ canReferenceOtherApplicationsWorkflowActions?: boolean;
}): WorkflowManifestReferences => {
const logicFunctionOutputSchemaByUniversalIdentifier = new Map<
string,
@@ -41,6 +43,32 @@ export const prepareWorkflowManifestReferences = ({
WorkflowManifestFieldReference
>();
+ if (canReferenceOtherApplicationsWorkflowActions) {
+ for (const logicFunction of Object.values(
+ existingAllFlatEntityMaps.flatLogicFunctionMaps.byUniversalIdentifier,
+ )) {
+ if (
+ !isDefined(logicFunction) ||
+ logicFunction.applicationId === ownerApplicationId ||
+ isDefined(logicFunction.deletedAt) ||
+ !isDefined(logicFunction.workflowActionTriggerSettings)
+ ) {
+ continue;
+ }
+ const declaredOutputSchema =
+ logicFunction.workflowActionTriggerSettings.outputSchema;
+ if (isDefined(declaredOutputSchema)) {
+ logicFunctionOutputSchemaByUniversalIdentifier.set(
+ logicFunction.universalIdentifier,
+ inputSchemaToOutputSchema(declaredOutputSchema),
+ );
+ }
+ logicFunctionIdByUniversalIdentifier.set(
+ logicFunction.universalIdentifier,
+ logicFunction.id,
+ );
+ }
+ }
for (const logicFunction of Object.values(
toAllUniversalFlatEntityMaps.flatLogicFunctionMaps.byUniversalIdentifier,
)) {
diff --git a/packages/twenty-server/test/integration/metadata/suites/application/successful-sync-workspace-custom-application-cross-application-workflow-action.integration-spec.ts b/packages/twenty-server/test/integration/metadata/suites/application/successful-sync-workspace-custom-application-cross-application-workflow-action.integration-spec.ts
new file mode 100644
index 00000000000..9f314f6fba5
--- /dev/null
+++ b/packages/twenty-server/test/integration/metadata/suites/application/successful-sync-workspace-custom-application-cross-application-workflow-action.integration-spec.ts
@@ -0,0 +1,135 @@
+import { randomUUID } from 'node:crypto';
+
+import {
+ buildTestApplicationManifest,
+ buildTestApplicationWorkflow,
+ logicFunctionStep,
+ type TestApplicationWorkflow,
+} from 'test/integration/graphql/suites/workflow/utils/application-workflow-test.util';
+import { findManyApplications } from 'test/integration/graphql/utils/find-many-applications.util';
+import { cleanupApplicationAndAppRegistration } from 'test/integration/metadata/suites/application/utils/cleanup-application-and-app-registration.util';
+import { exportApplication } from 'test/integration/metadata/suites/application/utils/export-application.util';
+import { setupApplicationForSync } from 'test/integration/metadata/suites/application/utils/setup-application-for-sync.util';
+import { syncApplication } from 'test/integration/metadata/suites/application/utils/sync-application.util';
+import { jestExpectToBeDefined } from 'test/utils/jest-expect-to-be-defined.util.test';
+import { type Manifest } from 'twenty-shared/application';
+
+import { WORKSPACE_CUSTOM_APPLICATION_NAME } from 'src/engine/core-modules/application/constants/workspace-custom-application.constant';
+
+const PROVIDER_APP_ID = randomUUID();
+const PROVIDER_FUNCTION_ID = randomUUID();
+const CONSUMER_APP_ID = randomUUID();
+
+const toWorkflowManifest = (
+ workflow: TestApplicationWorkflow,
+): NonNullable<Manifest['workflows']>[number] => ({
+ universalIdentifier: workflow.universalIdentifier,
+ name: workflow.name,
+ version: {
+ trigger: {
+ universalIdentifier: workflow.triggerUniversalIdentifier,
+ type: 'MANUAL',
+ nextStepIds: [workflow.steps[0].universalIdentifier],
+ },
+ steps: workflow.steps,
+ },
+});
+
+describe('Workflows calling another application workflow action', () => {
+ beforeAll(async () => {
+ await setupApplicationForSync({
+ applicationUniversalIdentifier: PROVIDER_APP_ID,
+ name: 'Workflow action provider',
+ description: 'Application exposing a workflow action',
+ sourcePath: 'cross-application-workflow-action-provider',
+ });
+ await setupApplicationForSync({
+ applicationUniversalIdentifier: CONSUMER_APP_ID,
+ name: 'Workflow action consumer',
+ description: 'Installed application calling another one action',
+ sourcePath: 'cross-application-workflow-action-consumer',
+ });
+
+ const providerInstallation = await syncApplication({
+ manifest: buildTestApplicationManifest({
+ applicationUniversalIdentifier: PROVIDER_APP_ID,
+ roleUniversalIdentifier: randomUUID(),
+ companyPermissionUniversalIdentifier: randomUUID(),
+ logicFunctionUniversalIdentifier: PROVIDER_FUNCTION_ID,
+ workflows: [],
+ }),
+ });
+
+ expect(providerInstallation.errors).toBeUndefined();
+ }, 120000);
+
+ afterAll(async () => {
+ await cleanupApplicationAndAppRegistration({
+ applicationUniversalIdentifier: CONSUMER_APP_ID,
+ });
+ await cleanupApplicationAndAppRegistration({
+ applicationUniversalIdentifier: PROVIDER_APP_ID,
+ });
+ });
+
+ it('resolves the action from the workspace Custom application', async () => {
+ const { data: applicationsData } = await findManyApplications({
+ expectToFail: false,
+ });
+ const customApplication = applicationsData.findManyApplications.find(
+ ({ name }) => name === WORKSPACE_CUSTOM_APPLICATION_NAME,
+ );
+
+ jestExpectToBeDefined(customApplication);
+
+ const { data } = await exportApplication({
+ universalIdentifier: customApplication.universalIdentifier,
+ expectToFail: false,
+ });
+ const workflow = buildTestApplicationWorkflow(
+ 'Call the provider action from the Custom application',
+ [logicFunctionStep(PROVIDER_FUNCTION_ID)],
+ );
+
+ const dryRun = await syncApplication({
+ manifest: {
+ ...data.exportApplication.manifest,
+ workflows: [toWorkflowManifest(workflow)],
+ },
+ dryRun: true,
+ inferDeletionFromMissingEntities: false,
+ expectToFail: false,
+ });
+
+ expect(dryRun.errors).toBeUndefined();
+ expect(dryRun.data.syncApplication.actions).toEqual(
+ expect.arrayContaining([
+ expect.objectContaining({
+ type: 'create',
+ metadataName: 'workflow',
+ }),
+ ]),
+ );
+ }, 60000);
+
+ it('refuses the action from another installed application', async () => {
+ const workflow = buildTestApplicationWorkflow(
+ 'Call the provider action from an installed application',
+ [logicFunctionStep(PROVIDER_FUNCTION_ID)],
+ );
+
+ const sync = await syncApplication({
+ manifest: buildTestApplicationManifest({
+ applicationUniversalIdentifier: CONSUMER_APP_ID,
+ roleUniversalIdentifier: randomUUID(),
+ companyPermissionUniversalIdentifier: randomUUID(),
+ logicFunctionUniversalIdentifier: randomUUID(),
+ workflows: [workflow],
+ }),
+ dryRun: true,
+ expectToFail: true,
+ });
+
+ expect(sync.errors).toBeDefined();
+ }, 60000);
+});
diff --git a/packages/twenty-server/test/integration/upgrade/suites/campaign-delivery-claim.integration-spec.ts b/packages/twenty-server/test/integration/upgrade/suites/campaign-delivery-claim.integration-spec.ts
index de9fdca50df..d1312aa1791 100644
--- a/packages/twenty-server/test/integration/upgrade/suites/campaign-delivery-claim.integration-spec.ts
+++ b/packages/twenty-server/test/integration/upgrade/suites/campaign-delivery-claim.integration-spec.ts
@@ -1,9 +1,9 @@
import { config } from 'dotenv';
-import { isDefined } from 'twenty-shared/utils';
import { DataSource } from 'typeorm';
import { v4 } from 'uuid';
import { getWorkspaceSchemaName } from 'src/engine/workspace-datasource/utils/get-workspace-schema-name.util';
+import { SEED_APPLE_WORKSPACE_ID } from 'src/engine/workspace-manager/dev-seeder/core/constants/seeder-workspaces.constant';
jest.useRealTimers();
@@ -84,17 +84,7 @@ describe('campaignDelivery claim protocol (integration)', () => {
});
await dataSource.initialize();
- const [seedWorkspaceRow] = await dataSource.query(
- `SELECT id AS "workspaceId" FROM "core"."workspace" LIMIT 1`,
- );
-
- if (!isDefined(seedWorkspaceRow)) {
- throw new Error(
- 'No seeded workspace row found; run database:reset before the integration suite.',
- );
- }
-
- campaignDeliveryTableName = `"${getWorkspaceSchemaName(seedWorkspaceRow.workspaceId)}"."campaignDelivery"`;
+ campaignDeliveryTableName = `"${getWorkspaceSchemaName(SEED_APPLE_WORKSPACE_ID)}"."campaignDelivery"`;
});
afterAll(async () => {