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:
+84
@@ -0,0 +1,84 @@
|
||||
import { jsonSchemaToInputSchema } from '@/logic-function/json-schema-to-input-schema';
|
||||
|
||||
describe('jsonSchemaToInputSchema', () => {
|
||||
it('wraps a JSON Schema object into a single-element InputSchema array', () => {
|
||||
const result = jsonSchemaToInputSchema({
|
||||
type: 'object',
|
||||
properties: {
|
||||
name: { type: 'string', description: 'A name' },
|
||||
age: { type: 'number' },
|
||||
},
|
||||
required: ['name'],
|
||||
});
|
||||
|
||||
expect(result).toEqual([
|
||||
{
|
||||
type: 'object',
|
||||
properties: {
|
||||
name: { type: 'string' },
|
||||
age: { type: 'number' },
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('maps integer to number', () => {
|
||||
const result = jsonSchemaToInputSchema({
|
||||
type: 'object',
|
||||
properties: { count: { type: 'integer' } },
|
||||
});
|
||||
|
||||
expect(result[0].properties).toEqual({ count: { type: 'number' } });
|
||||
});
|
||||
|
||||
it('maps null to unknown', () => {
|
||||
const result = jsonSchemaToInputSchema({
|
||||
type: 'object',
|
||||
properties: { value: { type: 'null' } },
|
||||
});
|
||||
|
||||
expect(result[0].properties).toEqual({ value: { type: 'unknown' } });
|
||||
});
|
||||
|
||||
it('preserves array items', () => {
|
||||
const result = jsonSchemaToInputSchema({
|
||||
type: 'array',
|
||||
items: { type: 'string' },
|
||||
});
|
||||
|
||||
expect(result).toEqual([
|
||||
{
|
||||
type: 'array',
|
||||
items: { type: 'string' },
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('preserves enum on string properties', () => {
|
||||
const result = jsonSchemaToInputSchema({
|
||||
type: 'object',
|
||||
properties: {
|
||||
color: { type: 'string', enum: ['red', 'green', 'blue'] },
|
||||
},
|
||||
});
|
||||
|
||||
expect(result[0].properties?.color).toEqual({
|
||||
type: 'string',
|
||||
enum: ['red', 'green', 'blue'],
|
||||
});
|
||||
});
|
||||
|
||||
it('drops non-string enum values silently', () => {
|
||||
const result = jsonSchemaToInputSchema({
|
||||
type: 'object',
|
||||
properties: {
|
||||
mixed: { type: 'string', enum: ['a', 1, true, 'b'] },
|
||||
},
|
||||
});
|
||||
|
||||
expect(result[0].properties?.mixed).toEqual({
|
||||
type: 'string',
|
||||
enum: ['a', 'b'],
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,9 +0,0 @@
|
||||
import { type InputJsonSchema } from '@/logic-function';
|
||||
|
||||
export const SEED_LOGIC_FUNCTION_INPUT_SCHEMA: InputJsonSchema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
a: { type: 'string' },
|
||||
b: { type: 'number' },
|
||||
},
|
||||
};
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
export { DEFAULT_TOOL_INPUT_SCHEMA } from './constants/DefaultToolInputSchema';
|
||||
export { SEED_LOGIC_FUNCTION_INPUT_SCHEMA } from './constants/SeedLogicFunctionInputSchema';
|
||||
export { getInputSchemaFromSourceCode } from './get-input-schema-from-source-code';
|
||||
export { getOutputSchemaFromValue } from './get-output-schema-from-value';
|
||||
export type { InputJsonSchema } from './input-json-schema.type';
|
||||
export { jsonSchemaToInputSchema } from './json-schema-to-input-schema';
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
import { type InputJsonSchema } from '@/logic-function/input-json-schema.type';
|
||||
import {
|
||||
type InputSchema,
|
||||
type InputSchemaProperty,
|
||||
} from '@/workflow/types/InputSchema';
|
||||
|
||||
const convertProperty = (jsonSchema: InputJsonSchema): InputSchemaProperty => {
|
||||
const property: InputSchemaProperty = { type: 'unknown' };
|
||||
|
||||
switch (jsonSchema.type) {
|
||||
case 'string':
|
||||
property.type = 'string';
|
||||
break;
|
||||
case 'number':
|
||||
case 'integer':
|
||||
property.type = 'number';
|
||||
break;
|
||||
case 'boolean':
|
||||
property.type = 'boolean';
|
||||
break;
|
||||
case 'array':
|
||||
property.type = 'array';
|
||||
if (jsonSchema.items) {
|
||||
property.items = convertProperty(jsonSchema.items);
|
||||
}
|
||||
break;
|
||||
case 'object':
|
||||
property.type = 'object';
|
||||
if (jsonSchema.properties) {
|
||||
property.properties = Object.fromEntries(
|
||||
Object.entries(jsonSchema.properties).map(([key, value]) => [
|
||||
key,
|
||||
convertProperty(value),
|
||||
]),
|
||||
);
|
||||
}
|
||||
break;
|
||||
case 'null':
|
||||
default:
|
||||
property.type = 'unknown';
|
||||
}
|
||||
|
||||
if (Array.isArray(jsonSchema.enum)) {
|
||||
property.enum = jsonSchema.enum.filter(
|
||||
(value): value is string => typeof value === 'string',
|
||||
);
|
||||
}
|
||||
|
||||
return property;
|
||||
};
|
||||
|
||||
// Wraps in a single-element array because Twenty's InputSchema represents
|
||||
// the parameter list of a function -- logic functions take a single params
|
||||
// object, hence a one-element array containing it.
|
||||
export const jsonSchemaToInputSchema = (
|
||||
jsonSchema: InputJsonSchema,
|
||||
): InputSchema => {
|
||||
return [convertProperty(jsonSchema)];
|
||||
};
|
||||
Reference in New Issue
Block a user