This commit is contained in:
2025-11-09 02:08:31 +07:00
parent 1ed58d1a98
commit 7dba29c66f
57 changed files with 8362 additions and 359 deletions

View File

@@ -17,7 +17,7 @@ public class UserService : IUserService
private readonly IAccountService _accountService;
private readonly ILogger<UserService> _logger;
private readonly ICacheService _cacheService;
private readonly IGrainFactory _grainFactory;
private readonly IGrainFactory? _grainFactory;
private readonly IWhitelistService _whitelistService;
private readonly string[] _authorizedAddresses;
@@ -27,7 +27,7 @@ public class UserService : IUserService
IAccountService accountService,
ILogger<UserService> logger,
ICacheService cacheService,
IGrainFactory grainFactory,
IGrainFactory? grainFactory,
IWhitelistService whitelistService,
IConfiguration configuration)
{
@@ -134,17 +134,21 @@ public class UserService : IUserService
};
// Initialize AgentGrain for new user (with empty agent name initially)
try
// Only if Orleans is available (not available in compute workers)
if (_grainFactory != null)
{
var agentGrain = _grainFactory.GetGrain<IAgentGrain>(user.Id);
await agentGrain.InitializeAsync(user.Id, string.Empty);
_logger.LogInformation("AgentGrain initialized for new user {UserId}", user.Id);
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to initialize AgentGrain for new user {UserId}", user.Id);
SentrySdk.CaptureException(ex);
// Don't throw here to avoid breaking the user creation process
try
{
var agentGrain = _grainFactory.GetGrain<IAgentGrain>(user.Id);
await agentGrain.InitializeAsync(user.Id, string.Empty);
_logger.LogInformation("AgentGrain initialized for new user {UserId}", user.Id);
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to initialize AgentGrain for new user {UserId}", user.Id);
SentrySdk.CaptureException(ex);
// Don't throw here to avoid breaking the user creation process
}
}
}
@@ -199,18 +203,22 @@ public class UserService : IUserService
await _userRepository.SaveOrUpdateUserAsync(user);
// Update the AgentGrain with the new agent name (lightweight operation)
try
// Only if Orleans is available (not available in compute workers)
if (_grainFactory != null)
{
var agentGrain = _grainFactory.GetGrain<IAgentGrain>(user.Id);
await agentGrain.UpdateAgentNameAsync(agentName);
_logger.LogInformation("AgentGrain updated for user {UserId} with agent name {AgentName}", user.Id,
agentName);
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to update AgentGrain for user {UserId} with agent name {AgentName}",
user.Id, agentName);
// Don't throw here to avoid breaking the user update process
try
{
var agentGrain = _grainFactory.GetGrain<IAgentGrain>(user.Id);
await agentGrain.UpdateAgentNameAsync(agentName);
_logger.LogInformation("AgentGrain updated for user {UserId} with agent name {AgentName}", user.Id,
agentName);
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to update AgentGrain for user {UserId} with agent name {AgentName}",
user.Id, agentName);
// Don't throw here to avoid breaking the user update process
}
}
return user;