import { defineLogicFunction } from 'twenty-sdk/define'; import { LOGIC_FUNCTION_CONSTANTS, OBJECT_UNIVERSAL_IDENTIFIERS, } from 'src/constants/universal-identifiers'; import { submitForReviewCore } from 'src/logic-functions/handlers/submit-for-review'; import { extractBody, extractUserWorkspaceId, normalizeRecordId, } from 'src/logic-functions/utils/route-input'; import { type SubmitForReviewInput, type SubmitForReviewOutcome, } from 'src/types/logic-function-io'; const handler = (input: unknown): Promise => { const body = extractBody(input as never); const contractId = normalizeRecordId(body?.contractId); if (contractId === undefined) { return Promise.resolve({ success: false, recordId: '', error: 'Missing contractId.', }); } return submitForReviewCore({ input: { contractId }, eventUserWorkspaceId: extractUserWorkspaceId(input), }); }; export default defineLogicFunction({ universalIdentifier: LOGIC_FUNCTION_CONSTANTS.submitForReview.universalIdentifier, name: 'submit-for-review', description: 'Submits a Contract for review: marks it pending AI review, records the submitter, and runs the AI review directly.', timeoutSeconds: 120, handler, httpRouteTriggerSettings: { path: LOGIC_FUNCTION_CONSTANTS.submitForReview.path, httpMethod: 'POST', isAuthRequired: true, }, workflowActionTriggerSettings: { label: 'Submit contract for review', icon: 'IconFileUpload', inputSchema: [ { type: 'object', properties: { contractId: { type: 'record', objectUniversalIdentifier: OBJECT_UNIVERSAL_IDENTIFIERS.contract, label: 'Contract', }, }, }, ], outputSchema: [ { type: 'object', properties: { success: { type: 'boolean', label: 'Success' }, recordId: { type: 'string', label: 'Record Id' }, }, }, ], }, });