feat(apps): split AI tool and workflow action triggers in LogicFunction manifest (#20208)

## Summary

Replaces the bolted-on `isTool` + `toolInputSchema` fields on
`LogicFunctionManifest` with two distinct, opt-in triggers that align
with the existing `cron` / `databaseEvent` / `httpRoute` trigger
pattern:

- **`toolTriggerSettings`** — exposes the function as an AI tool (chat /
MCP / function calling). Uses standard JSON Schema (the format LLMs
natively understand).
- **`workflowActionTriggerSettings`** — exposes the function as a step
in the visual workflow builder. Uses Twenty's rich `InputSchema` so the
builder can render proper `FieldMetadataType`-aware editors, variable
pickers, labels, and an optional `outputSchema`.

A function can opt into none, one, or both. Each surface gets the schema
format appropriate for it.

### Why

`isTool: true` previously exposed the function as both an AI tool AND a
workflow node, with the same JSON Schema feeding both — but the workflow
builder really wants Twenty's `InputSchema` (with `CURRENCY`,
`RELATION`, `EMAILS`, etc.) and the AI surface really wants standard
JSON Schema. Today the workflow builder hacks around this by treating
JSON Schema as `InputSchema`, which silently breaks for any
non-primitive field type. Splitting the triggers fixes that and lets
each surface evolve independently.

### Migration

- **Fast** instance command adds the two new nullable columns.
- **Slow** instance command backfills `toolTriggerSettings` +
`workflowActionTriggerSettings` from `isTool=true` rows (preserving
today's both-surfaces behaviour) then drops the legacy columns.

### Stacked

Stacked on top of #20181. Merge that first, then this.

## Test plan

- [ ] CI green (oxlint, typecheck, jest, vitest)
- [ ] Run `--include-slow` upgrade against a workspace with existing
`isTool=true` logic functions; verify both new columns populated and old
columns dropped
- [ ] Verify AI chat sees migrated tool functions (Linear create-issue,
Exa search) and can call them with the JSON Schema
- [ ] Add an AI-tool function from the Settings UI (toggles
`toolTriggerSettings`) and verify it shows up in chat
- [ ] Add a workflow-action function from the Settings UI (toggles
`workflowActionTriggerSettings`) and verify it appears in the workflow
node picker
- [ ] In the workflow builder, edit a `LOGIC_FUNCTION` step and verify
input fields render (no more JSON-Schema-as-InputSchema hack)
- [ ] Try defining a function with no triggers in the SDK and verify
`defineLogicFunction` rejects it

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: martmull <martmull@hotmail.fr>
This commit is contained in:
Félix Malfait
2026-05-05 14:56:09 +02:00
committed by GitHub
parent 36452ecc8b
commit 53fdac1417
66 changed files with 820 additions and 357 deletions
@@ -54,8 +54,8 @@ describe('WorkflowVersionStepOperationsWorkspaceService', () => {
builtHandlerPath: 'index.mjs',
handlerName: 'main',
checksum: null,
toolInputSchema: null,
isTool: false,
toolTriggerSettings: null,
workflowActionTriggerSettings: null,
universalIdentifier: 'universal-id',
applicationId: 'application-id',
cronTriggerSettings: null,
@@ -77,8 +77,8 @@ describe('WorkflowVersionStepOperationsWorkspaceService', () => {
builtHandlerPath: 'index.mjs',
handlerName: 'main',
checksum: null,
toolInputSchema: null,
isTool: false,
toolTriggerSettings: null,
workflowActionTriggerSettings: null,
universalIdentifier: 'universal-id',
applicationId: 'application-id',
cronTriggerSettings: null,
@@ -182,10 +182,13 @@ export class WorkflowVersionStepOperationsWorkspaceService {
},
input: {
logicFunctionId: newLogicFunction.id,
logicFunctionInput: isDefined(newLogicFunction.toolInputSchema)
? (getFunctionInputFromInputSchema([
newLogicFunction.toolInputSchema,
])[0] ?? {})
logicFunctionInput: isDefined(
newLogicFunction.workflowActionTriggerSettings?.inputSchema,
)
? (getFunctionInputFromInputSchema(
newLogicFunction.workflowActionTriggerSettings
.inputSchema,
)[0] ?? {})
: {},
},
},
@@ -235,10 +238,13 @@ export class WorkflowVersionStepOperationsWorkspaceService {
},
input: {
logicFunctionId,
logicFunctionInput: isDefined(flatLogicFunction.toolInputSchema)
? (getFunctionInputFromInputSchema([
flatLogicFunction.toolInputSchema,
])[0] ?? {})
logicFunctionInput: isDefined(
flatLogicFunction.workflowActionTriggerSettings?.inputSchema,
)
? (getFunctionInputFromInputSchema(
flatLogicFunction.workflowActionTriggerSettings
.inputSchema,
)[0] ?? {})
: {},
},
},
@@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';
import { resolveInput } from 'twenty-shared/utils';
import { isDefined, resolveInput } from 'twenty-shared/utils';
import { type WorkflowAction } from 'src/modules/workflow/workflow-executor/interfaces/workflow-action.interface';
@@ -69,6 +69,13 @@ export class LogicFunctionWorkflowAction implements WorkflowAction {
);
}
if (!isDefined(logicFunction.workflowActionTriggerSettings)) {
throw new WorkflowStepExecutorException(
`Logic function ${logicFunction.name} is not exposed as a workflow action`,
WorkflowStepExecutorExceptionCode.INVALID_STEP_TYPE,
);
}
const result = await this.logicFunctionExecutorService.execute({
logicFunctionId: workflowActionInput.logicFunctionId,
workspaceId,
@@ -15,7 +15,7 @@ export const createListLogicFunctionToolsTool = (
) => ({
name: 'list_logic_function_tools' as const,
description:
'List all logic functions marked as tools that can be added as LOGIC_FUNCTION steps in workflows. Returns their IDs, names, and descriptions.',
'List all logic functions exposed as workflow actions, which can be added as LOGIC_FUNCTION steps in workflows. Returns their IDs, names, and descriptions.',
inputSchema: listLogicFunctionToolsSchema,
execute: async () => {
const { flatLogicFunctionMaps } =
@@ -26,16 +26,18 @@ export const createListLogicFunctionToolsTool = (
},
);
const toolFunctions = Object.values(
const workflowActionFunctions = Object.values(
flatLogicFunctionMaps.byUniversalIdentifier,
).filter(
(fn): fn is FlatLogicFunction =>
isDefined(fn) && fn.isTool === true && fn.deletedAt === null,
isDefined(fn) &&
isDefined(fn.workflowActionTriggerSettings) &&
fn.deletedAt === null,
);
return {
success: true,
logicFunctions: toolFunctions.map((fn) => ({
logicFunctions: workflowActionFunctions.map((fn) => ({
id: fn.id,
name: fn.name,
description: fn.description,