Spaces:
Running
Running
Commit ·
247fc9b
1
Parent(s): 96c7faf
fix(agent-canvas): change initial canvas ownership to system agent account to support unclaimed state
Browse files81 unmodified lines82838485868788899091921 unmodified line94959697989910010110210310410510610710810911011111211311411511681 unmodified linestry{// Ensure user exists in database to prevent Foreign Key constraints failurevar user = await _userRepo.GetByIdAsync(CurrentUserId);if (user == null){user = new User{Id = CurrentUserId,Email = User.FindFirst(ClaimTypes.Email)?.Value ?? $"{CurrentUserId}@questboard.ai",1 unmodified linePasswordHash = "",CreatedAt = DateTime.UtcNow};await _userRepo.CreateAsync(user);}// 1. Create the Graph record in the databasevar createDto = new CreateGraphDto{Title = string.IsNullOrWhiteSpace(schema.Title) ? "QuestboardAI Plan" : schema.Title.Trim(),Description = schema.Description};var graphResponse = await _graphService.CreateAsync(createDto, CurrentUserId);// 2. Perform Auto-Layout to assign visual coordinates PosX and PosYvar fullGraph = AutoLayoutEngine.LayoutGraph(schema, CurrentUserId);fullGraph.Id = graphResponse.Id; // Sync graph ID// 3. Save all nodes and dependency edges in the databasevar saveResult = await _graphService.SaveFullGraphAsync(graphResponse.Id, fullGraph, CurrentUserId);if (!saveResult){return BadRequest(new { message = "Failed to store generated task nodes in database." });81 unmodified lines8283848586878889909192939495969798991001011021031041051061071081091101111121131141151161 unmodified line11811912012112212312412512612712812913013113213313413513613713813914081 unmodified linestry{var agentId = Guid.Parse("33d1ae31-bf51-4b12-89d0-8e574e7916ab");// Ensure default system agent user exists in database to prevent Foreign Key constraints failurevar agentUser = await _userRepo.GetByIdAsync(agentId);if (agentUser == null){var existingByEmail = await _userRepo.GetByEmailAsync("dan9228335@gmail.com");if (existingByEmail != null){agentUser = existingByEmail;}else{agentUser = new User{Id = agentId,Email = "dan9228335@gmail.com",DisplayName = "Dodikuser",PasswordHash = "",CreatedAt = DateTime.UtcNow};await _userRepo.CreateAsync(agentUser);}}// Also ensure the current authenticated user requesting this has a record in the databasevar requestUser = await _userRepo.GetByIdAsync(CurrentUserId);if (requestUser == null){requestUser = new User{Id = CurrentUserId,Email = User.FindFirst(ClaimTypes.Email)?.Value ?? $"{CurrentUserId}@questboard.ai",1 unmodified linePasswordHash = "",CreatedAt = DateTime.UtcNow};await _userRepo.CreateAsync(requestUser);}// 1. Create the Graph record in the database, owned by the agent system user (unclaimed)var createDto = new CreateGraphDto{Title = string.IsNullOrWhiteSpace(schema.Title) ? "QuestboardAI Plan" : schema.Title.Trim(),Description = schema.Description};var graphResponse = await _graphService.CreateAsync(createDto, agentId);// 2. Perform Auto-Layout to assign visual coordinates PosX and PosYvar fullGraph = AutoLayoutEngine.LayoutGraph(schema, agentId);fullGraph.Id = graphResponse.Id; // Sync graph ID// 3. Save all nodes and dependency edges in the databasevar saveResult = await _graphService.SaveFullGraphAsync(graphResponse.Id, fullGraph, agentId);if (!saveResult){return BadRequest(new { message = "Failed to store generated task nodes in database." });
FlowAPI/Controllers/AgentCanvasController.cs+33-9