Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion BlazorServerChat2/Controllers/AiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace BlazorServerChat2.Controllers;
[Route("api/[controller]")]
[Authorize]
public class AiController(
AgentFrameworkLogic agentLogic,
IAgentFrameworkLogic agentLogic,
ApplicationDbContext context,
IHubContext<BlazorChatHub> hubContext,
ILogger<AiController> logger) : ControllerBase
Expand Down
2 changes: 1 addition & 1 deletion BlazorServerChat2/Controllers/ChatController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace BlazorServerChat2.Controllers;
public class ChatController(
ApplicationDbContext context,
Room room,
UserChatSettingCache userChatSettingCache,
IUserChatSettingCache userChatSettingCache,
ILogger<ChatController> logger) : ControllerBase
{
/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion BlazorServerChat2/Data/AgentFrameworkLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace BlazorServerChat2.Data
/// dotnet add package Azure.AI.OpenAI --prerelease
/// dotnet add package Azure.Identity
/// </remarks>
public class AgentFrameworkLogic
public class AgentFrameworkLogic : IAgentFrameworkLogic
{
private readonly ILoggerFactory _logger;
private readonly IConfiguration _configuration;
Expand Down
22 changes: 22 additions & 0 deletions BlazorServerChat2/Data/IAgentFrameworkLogic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace BlazorServerChat2.Data;

/// <summary>
/// AIエージェントロジックのインターフェース(テスト容易性のため)
/// </summary>
public interface IAgentFrameworkLogic
{
/// <summary>シングルエージェント(ほのか)への問いかけ。HTML文字列を返す。</summary>
Task<string> Run(string input);

/// <summary>グループチャット(ほのか&みずき)。各エージェントの応答をコールバックで通知する。</summary>
Task RunGroupChat(string input, Func<string, string, Task> onMessageReceived);

/// <summary>会話履歴をクリアして新しいスレッドを開始する。</summary>
Task ClearAsync();

/// <summary>ユーザーメッセージを履歴に追加する(AI応答なし)。</summary>
void NonGenerateMessage(string input);

/// <summary>アシスタントメッセージを履歴に追加する。</summary>
void AddAssistantMessage(string message);
}
18 changes: 18 additions & 0 deletions BlazorServerChat2/Data/IUserChatSettingCache.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace BlazorServerChat2.Data;

/// <summary>
/// ユーザーチャット設定キャッシュのインターフェース(テスト容易性のため)
/// </summary>
public interface IUserChatSettingCache
{
Task InitializeAsync();
UserChatSetting? GetUserChatSetting(string? userId);
string? GetUserIconBase64(string? userId);
string? GetIconBase64(int iconNumber);
Task<string?> GetUserNameAsync(string? userId);
string? GetUserName(string? userId);
Task LoadUserNamesAsync(IEnumerable<string> userIds);
void UpdateUserSetting(UserChatSetting setting);
void UpdateIcon(IconMaster icon);
Task RefreshAsync();
}
2 changes: 1 addition & 1 deletion BlazorServerChat2/Data/UserChatSettingCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace BlazorServerChat2.Data;
/// ユーザーチャット設定とアイコンマスタのキャッシュサービス
/// DBアクセスを削減し、会話ごとのSQL Server負荷を軽減します 🚀
/// </summary>
public class UserChatSettingCache : IDisposable
public class UserChatSettingCache : IUserChatSettingCache, IDisposable
{
private readonly IServiceScopeFactory _scopeFactory;
private readonly ILogger<UserChatSettingCache> _logger;
Expand Down
4 changes: 2 additions & 2 deletions BlazorServerChat2/Mcp/ChatMcpTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ namespace BlazorServerChat2.Mcp;
[McpServerToolType]
public class ChatMcpTools
{
private readonly AgentFrameworkLogic _agentLogic;
private readonly IAgentFrameworkLogic _agentLogic;
private readonly ILogger<ChatMcpTools> _logger;

public ChatMcpTools(AgentFrameworkLogic agentLogic, ILogger<ChatMcpTools> logger)
public ChatMcpTools(IAgentFrameworkLogic agentLogic, ILogger<ChatMcpTools> logger)
{
_agentLogic = agentLogic;
_logger = logger;
Expand Down
4 changes: 2 additions & 2 deletions BlazorServerChat2/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
@inject ClientHub clientHub
@inject Room room
@inject HttpClient http
@inject AgentFrameworkLogic agentFrameworkLogic
@inject IAgentFrameworkLogic agentFrameworkLogic
@inject ScreenModePlugin screenModePlugin
@inject IKeyCodeService keyCodeService
@inject UserChatSettingCache userChatSettingCache
@inject IUserChatSettingCache userChatSettingCache
@implements IAsyncDisposable

<PageTitle>あびや</PageTitle>
Expand Down
2 changes: 1 addition & 1 deletion BlazorServerChat2/Pages/IndexAuto.razor.server.bak
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@inject IDbContextFactory<ApplicationDbContext>? DbContextFactory
@inject Room? RoomService
@inject AuthenticationStateProvider? AuthStateProvider
@inject AgentFrameworkLogic? AgentLogic
@inject IAgentFrameworkLogic? AgentLogic
@inject IHubContext<BlazorChatHub>? HubContext
@implements IAsyncDisposable

Expand Down
4 changes: 2 additions & 2 deletions BlazorServerChat2/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
builder.Services.AddScoped<ClientHub>();
builder.Services.AddSingleton<Room>();
builder.Services.AddSingleton<HttpClient>();
builder.Services.AddSingleton<UserChatSettingCache>();
builder.Services.AddSingleton<IUserChatSettingCache, UserChatSettingCache>();

// InteractiveAuto用のHttpClient認証サポート
builder.Services.AddHttpContextAccessor();
Expand All @@ -222,7 +222,7 @@
.UseOpenTelemetry(sourceName: openTelemetrySourceName, configure: (cfg) => cfg.EnableSensitiveData = true)
.Build();
builder.Services.AddSingleton<IChatClient>(client);
builder.Services.AddScoped<AgentFrameworkLogic>();
builder.Services.AddScoped<IAgentFrameworkLogic, AgentFrameworkLogic>();
builder.Services.AddScoped<ScreenModePlugin>();
builder.Services.AddScoped<WeatherPlugin>();

Expand Down
Loading