MCPcopy Index your code
hub / github.com/simstudioai/sim / generateWorkflowJson

Function generateWorkflowJson

apps/sim/lib/workflows/operations/import-export.ts:777–816  ·  view source on GitHub ↗
(
  workflowState: WorkflowState,
  options: GenerateWorkflowJsonOptions
)

Source from the content-addressed store, hash-verified

775 * This is a pure function that takes the workflow state and metadata and returns the JSON string.
776 */
777export function generateWorkflowJson(
778 workflowState: WorkflowState,
779 options: GenerateWorkflowJsonOptions
780): string {
781 const variablesRecord: Record<string, Variable> | undefined = options.variables?.reduce(
782 (acc, v) => {
783 acc[v.id] = {
784 id: v.id,
785 name: v.name,
786 type: v.type,
787 value: v.value,
788 }
789 return acc
790 },
791 {} as Record<string, Variable>
792 )
793
794 const stateWithMetadata: WorkflowState = {
795 ...workflowState,
796 metadata: {
797 name: options.name,
798 description: options.description,
799 exportedAt: new Date().toISOString(),
800 },
801 variables: variablesRecord,
802 }
803
804 const exportState: ExportWorkflowState = sanitizeForExport(stateWithMetadata)
805 const jsonString = JSON.stringify(exportState, null, 2)
806
807 logger.info('Workflow JSON generated successfully', {
808 version: exportState.version,
809 exportedAt: exportState.exportedAt,
810 blocksCount: Object.keys(exportState.state.blocks).length,
811 edgesCount: exportState.state.edges.length,
812 jsonLength: jsonString.length,
813 })
814
815 return jsonString
816}

Callers 1

panel.tsxFile · 0.90

Calls 2

sanitizeForExportFunction · 0.90
infoMethod · 0.80

Tested by

no test coverage detected