/** * Builds graphicalEditor-compatible graph structures for trustee pipeline execution. * * The consolidated automation system runs all workflows through the graphicalEditor * execution engine (POST /api/workflows/{instanceId}/execute). These helpers build * the graph format expected by that engine: { nodes, connections } with _method/_action * mappings to the unified Action Library. */ interface TrusteeGraphNode { id: string; type: string; label: string; _method: string; _action: string; parameters: Record; position: { x: number; y: number }; } /** Matches automation2 ``buildConnectionMap`` (``sourceOutput`` / ``targetInput``). */ interface TrusteeGraphConnection { source: string; sourceOutput: number; target: string; targetInput: number; } export interface TrusteeGraph { nodes: TrusteeGraphNode[]; connections: TrusteeGraphConnection[]; } /** * Build a graph for the scan/upload pipeline (UC1): * trigger.manual → trustee.extractFromFiles → trustee.processDocuments → trustee.syncToAccounting */ export function _buildScanUploadGraph( trusteeInstanceId: string, fileIds: string[], extractionPrompt: string ): TrusteeGraph { const nodes: TrusteeGraphNode[] = [ { id: 'trigger-manual', type: 'trigger.manual', label: 'Start', _method: '', _action: '', parameters: {}, position: { x: 0, y: 0 }, }, { id: 'extract', type: 'trustee.extractFromFiles', label: 'Extract Documents', _method: 'trustee', _action: 'extractFromFiles', parameters: { fileIds, featureInstanceId: trusteeInstanceId, prompt: extractionPrompt, }, position: { x: 250, y: 0 }, }, { id: 'process', type: 'trustee.processDocuments', label: 'Process Documents', _method: 'trustee', _action: 'processDocuments', parameters: { documentList: { type: 'ref', nodeId: 'extract', path: ['documents'] }, featureInstanceId: trusteeInstanceId, }, position: { x: 500, y: 0 }, }, { id: 'sync', type: 'trustee.syncToAccounting', label: 'Sync to Accounting', _method: 'trustee', _action: 'syncToAccounting', parameters: { documentList: { type: 'ref', nodeId: 'process', path: ['documents'] }, featureInstanceId: trusteeInstanceId, }, position: { x: 750, y: 0 }, }, ]; const connections: TrusteeGraphConnection[] = [ { source: 'trigger-manual', sourceOutput: 0, target: 'extract', targetInput: 0 }, { source: 'extract', sourceOutput: 0, target: 'process', targetInput: 0 }, { source: 'process', sourceOutput: 0, target: 'sync', targetInput: 0 }, ]; return { nodes, connections }; } /** * Build a graph for the expense import pipeline (SharePoint-based): * trigger.manual → trustee.extractFromFiles (SharePoint) → trustee.processDocuments → trustee.syncToAccounting */ export function _buildExpenseImportGraph( trusteeInstanceId: string, connectionReference: string, sharepointFolder: string, extractionPrompt: string ): TrusteeGraph { const nodes: TrusteeGraphNode[] = [ { id: 'trigger-manual', type: 'trigger.manual', label: 'Start', _method: '', _action: '', parameters: {}, position: { x: 0, y: 0 }, }, { id: 'extract', type: 'trustee.extractFromFiles', label: 'Extract from SharePoint', _method: 'trustee', _action: 'extractFromFiles', parameters: { connectionReference, sharepointFolder, featureInstanceId: trusteeInstanceId, prompt: extractionPrompt, }, position: { x: 250, y: 0 }, }, { id: 'process', type: 'trustee.processDocuments', label: 'Process Documents', _method: 'trustee', _action: 'processDocuments', parameters: { documentList: { type: 'ref', nodeId: 'extract', path: ['documents'] }, featureInstanceId: trusteeInstanceId, }, position: { x: 500, y: 0 }, }, { id: 'sync', type: 'trustee.syncToAccounting', label: 'Sync to Accounting', _method: 'trustee', _action: 'syncToAccounting', parameters: { documentList: { type: 'ref', nodeId: 'process', path: ['documents'] }, featureInstanceId: trusteeInstanceId, }, position: { x: 750, y: 0 }, }, ]; const connections: TrusteeGraphConnection[] = [ { source: 'trigger-manual', sourceOutput: 0, target: 'extract', targetInput: 0 }, { source: 'extract', sourceOutput: 0, target: 'process', targetInput: 0 }, { source: 'process', sourceOutput: 0, target: 'sync', targetInput: 0 }, ]; return { nodes, connections }; } /** * Build a scheduled workflow graph for daily expense import: * trigger.schedule (cron) → trustee.extractFromFiles → trustee.processDocuments → trustee.syncToAccounting */ export function _buildScheduledExpenseImportGraph( trusteeInstanceId: string, connectionReference: string, sharepointFolder: string, extractionPrompt: string, cronExpression: string ): TrusteeGraph { const nodes: TrusteeGraphNode[] = [ { id: 'trigger-schedule', type: 'trigger.schedule', label: 'Daily Schedule', _method: '', _action: '', parameters: { cron: cronExpression, enabled: true, }, position: { x: 0, y: 0 }, }, { id: 'extract', type: 'trustee.extractFromFiles', label: 'Extract from SharePoint', _method: 'trustee', _action: 'extractFromFiles', parameters: { connectionReference, sharepointFolder, featureInstanceId: trusteeInstanceId, prompt: extractionPrompt, }, position: { x: 250, y: 0 }, }, { id: 'process', type: 'trustee.processDocuments', label: 'Process Documents', _method: 'trustee', _action: 'processDocuments', parameters: { documentList: { type: 'ref', nodeId: 'extract', path: ['documents'] }, featureInstanceId: trusteeInstanceId, }, position: { x: 500, y: 0 }, }, { id: 'sync', type: 'trustee.syncToAccounting', label: 'Sync to Accounting', _method: 'trustee', _action: 'syncToAccounting', parameters: { documentList: { type: 'ref', nodeId: 'process', path: ['documents'] }, featureInstanceId: trusteeInstanceId, }, position: { x: 750, y: 0 }, }, ]; const connections: TrusteeGraphConnection[] = [ { source: 'trigger-schedule', sourceOutput: 0, target: 'extract', targetInput: 0 }, { source: 'extract', sourceOutput: 0, target: 'process', targetInput: 0 }, { source: 'process', sourceOutput: 0, target: 'sync', targetInput: 0 }, ]; return { nodes, connections }; }