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 lines828384858586878687888990919293949596899798991001011021031041051061071081091101111121131141151161 unmodified line1181191209712112212310012412512612712812910613013113210913313413513611313713813914081 unmodified lines
try { var agentId = Guid.Parse("33d1ae31-bf51-4b12-89d0-8e574e7916ab"); // Ensure user exists in database to prevent Foreign Key constraints failure var user = await _userRepo.GetByIdAsync(CurrentUserId); if (user == null) // Ensure default system agent user exists in database to prevent Foreign Key constraints failure var agentUser = await _userRepo.GetByIdAsync(agentId); if (agentUser == null) { var existingByEmail = await _userRepo.GetByEmailAsync("dan9228335@gmail.com"); if (existingByEmail != null) { agentUser = existingByEmail; } else { user = new User 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 database var requestUser = await _userRepo.GetByIdAsync(CurrentUserId); if (requestUser == null) { requestUser = new User { Id = CurrentUserId, Email = User.FindFirst(ClaimTypes.Email)?.Value ?? $"{CurrentUserId}@questboard.ai",1 unmodified line PasswordHash = "", CreatedAt = DateTime.UtcNow }; await _userRepo.CreateAsync(user); await _userRepo.CreateAsync(requestUser); }
// 1. Create the Graph record in the database // 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, CurrentUserId); var graphResponse = await _graphService.CreateAsync(createDto, agentId);
// 2. Perform Auto-Layout to assign visual coordinates PosX and PosY var fullGraph = AutoLayoutEngine.LayoutGraph(schema, CurrentUserId); var fullGraph = AutoLayoutEngine.LayoutGraph(schema, agentId); fullGraph.Id = graphResponse.Id; // Sync graph ID
// 3. Save all nodes and dependency edges in the database var saveResult = await _graphService.SaveFullGraphAsync(graphResponse.Id, fullGraph, CurrentUserId); var 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