@@ -13,6 +13,7 @@ const logger = createLogger('Workspaces')
1313
1414const createWorkspaceSchema = z . object ( {
1515 name : z . string ( ) . trim ( ) . min ( 1 , 'Name is required' ) ,
16+ skipDefaultWorkflow : z . boolean ( ) . optional ( ) . default ( false ) ,
1617} )
1718
1819// Get all workspaces for the current user
@@ -63,9 +64,9 @@ export async function POST(req: Request) {
6364 }
6465
6566 try {
66- const { name } = createWorkspaceSchema . parse ( await req . json ( ) )
67+ const { name, skipDefaultWorkflow } = createWorkspaceSchema . parse ( await req . json ( ) )
6768
68- const newWorkspace = await createWorkspace ( session . user . id , name )
69+ const newWorkspace = await createWorkspace ( session . user . id , name , skipDefaultWorkflow )
6970
7071 return NextResponse . json ( { workspace : newWorkspace } )
7172 } catch ( error ) {
@@ -80,7 +81,7 @@ async function createDefaultWorkspace(userId: string, userName?: string | null)
8081 return createWorkspace ( userId , workspaceName )
8182}
8283
83- async function createWorkspace ( userId : string , name : string ) {
84+ async function createWorkspace ( userId : string , name : string , skipDefaultWorkflow = false ) {
8485 const workspaceId = crypto . randomUUID ( )
8586 const workflowId = crypto . randomUUID ( )
8687 const now = new Date ( )
@@ -97,7 +98,6 @@ async function createWorkspace(userId: string, name: string) {
9798 updatedAt : now ,
9899 } )
99100
100- // Create admin permissions for the workspace owner
101101 await tx . insert ( permissions ) . values ( {
102102 id : crypto . randomUUID ( ) ,
103103 entityType : 'workspace' as const ,
@@ -108,37 +108,41 @@ async function createWorkspace(userId: string, name: string) {
108108 updatedAt : now ,
109109 } )
110110
111- // Create initial workflow for the workspace (empty canvas)
112- // Create the workflow
113- await tx . insert ( workflow ) . values ( {
114- id : workflowId ,
115- userId ,
116- workspaceId ,
117- folderId : null ,
118- name : 'default-agent ' ,
119- description : 'Your first workflow - start building here! ',
120- color : '#3972F6' ,
121- lastSynced : now ,
122- createdAt : now ,
123- updatedAt : now ,
124- isDeployed : false ,
125- runCount : 0 ,
126- variables : { } ,
127- } )
111+ if ( ! skipDefaultWorkflow ) {
112+ await tx . insert ( workflow ) . values ( {
113+ id : workflowId ,
114+ userId ,
115+ workspaceId ,
116+ folderId : null ,
117+ name : 'default-agent' ,
118+ description : 'Your first workflow - start building here! ' ,
119+ color : '#3972F6 ',
120+ lastSynced : now ,
121+ createdAt : now ,
122+ updatedAt : now ,
123+ isDeployed : false ,
124+ runCount : 0 ,
125+ variables : { } ,
126+ } )
127+ }
128128
129129 logger . info (
130- `Created workspace ${ workspaceId } with initial workflow ${ workflowId } for user ${ userId } `
130+ skipDefaultWorkflow
131+ ? `Created workspace ${ workspaceId } for user ${ userId } `
132+ : `Created workspace ${ workspaceId } with initial workflow ${ workflowId } for user ${ userId } `
131133 )
132134 } )
133135
134- const { workflowState } = buildDefaultWorkflowArtifacts ( )
135- const seedResult = await saveWorkflowToNormalizedTables ( workflowId , workflowState )
136+ if ( ! skipDefaultWorkflow ) {
137+ const { workflowState } = buildDefaultWorkflowArtifacts ( )
138+ const seedResult = await saveWorkflowToNormalizedTables ( workflowId , workflowState )
136139
137- if ( ! seedResult . success ) {
138- throw new Error ( seedResult . error || 'Failed to seed default workflow state' )
140+ if ( ! seedResult . success ) {
141+ throw new Error ( seedResult . error || 'Failed to seed default workflow state' )
142+ }
139143 }
140144 } catch ( error ) {
141- logger . error ( `Failed to create workspace ${ workspaceId } with initial workflow :` , error )
145+ logger . error ( `Failed to create workspace ${ workspaceId } :` , error )
142146 throw error
143147 }
144148
0 commit comments