Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 85f3400076 | |||
| a5cbe98f25 | |||
| 5b0e3a19f6 | |||
| e1d6b1eeb3 |
@@ -95,11 +95,11 @@ public class DashboardController(OpenClawGatewayClient gateway, ILogger<Dashboar
|
||||
|
||||
try
|
||||
{
|
||||
var sessionKey = string.IsNullOrWhiteSpace(request.SessionKey)
|
||||
var agentId = string.IsNullOrWhiteSpace(request.AgentId)
|
||||
? "iris"
|
||||
: request.SessionKey.Trim();
|
||||
: request.AgentId.Trim();
|
||||
|
||||
return await gateway.SendChatMessageAsync(sessionKey, request.Message.Trim());
|
||||
return await gateway.SendChatMessageAsync(agentId, request.Message.Trim());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -119,7 +119,7 @@ public class DashboardController(OpenClawGatewayClient gateway, ILogger<Dashboar
|
||||
{
|
||||
try
|
||||
{
|
||||
var key = string.IsNullOrWhiteSpace(sessionKey) ? "iris" : sessionKey.Trim();
|
||||
var key = string.IsNullOrWhiteSpace(sessionKey) ? "agent:iris:main" : sessionKey.Trim();
|
||||
var messages = await gateway.GetSessionHistoryAsync(key, Math.Clamp(limit, 1, 200), Math.Max(0, offset));
|
||||
|
||||
// Filter: only user and assistant messages (exclude tool/system)
|
||||
|
||||
@@ -17,7 +17,7 @@ public sealed record MessageEntry(
|
||||
|
||||
public sealed record ChatRequest(
|
||||
string Message,
|
||||
string? SessionKey
|
||||
string? AgentId
|
||||
);
|
||||
|
||||
public sealed record ChatResponse(
|
||||
|
||||
@@ -173,18 +173,21 @@ public sealed class OpenClawGatewayClient(HttpClient httpClient, IConfiguration
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ChatResponse> SendChatMessageAsync(string sessionKey, string message)
|
||||
public async Task<ChatResponse> SendChatMessageAsync(string agentId, string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await InvokeToolAsync("sessions_send", new { sessionKey, message });
|
||||
var result = await InvokeToolAsync("sessions_send", new { agentId, message });
|
||||
if (result is null) return new ChatResponse(false, null, "Gateway nicht erreichbar");
|
||||
|
||||
var ok = result["ok"]?.GetValue<bool>() ?? false;
|
||||
var reply = result["reply"]?.GetValue<string>()
|
||||
// sessions_send reply is in details.reply or content[0].text
|
||||
var details = result["details"];
|
||||
var ok = (details?["status"]?.GetValue<string>() ?? result["status"]?.GetValue<string>()) == "ok";
|
||||
var reply = details?["reply"]?.GetValue<string>()
|
||||
?? result["reply"]?.GetValue<string>()
|
||||
?? result["response"]?.GetValue<string>()
|
||||
?? result["content"]?[0]?["text"]?.GetValue<string>();
|
||||
var error = result["error"]?.GetValue<string>();
|
||||
var error = details?["error"]?.GetValue<string>() ?? result["error"]?.GetValue<string>();
|
||||
|
||||
return new ChatResponse(ok, reply, error);
|
||||
}
|
||||
|
||||
@@ -280,12 +280,19 @@ async function fetchChatMessages(): Promise<void> {
|
||||
const res = await apiFetch('/api/dashboard/chat/messages?limit=50')
|
||||
if (!res.ok) return
|
||||
const data: DashboardChatMessage[] = await res.json()
|
||||
chatMessages.value = data.map((msg, idx) => ({
|
||||
id: `msg-${idx}`,
|
||||
// Merge instead of replace — only add messages not already present
|
||||
const existingTexts = new Set(chatMessages.value.map(m => m.text))
|
||||
const existingTimestamps = new Set(chatMessages.value.map(m => m.timestamp))
|
||||
for (const msg of data) {
|
||||
const msgTime = new Date(msg.timestamp).getTime()
|
||||
if (existingTexts.has(msg.content) && existingTimestamps.has(msgTime)) continue
|
||||
chatMessages.value.push({
|
||||
id: `msg-${msgTime}-${msg.role}`,
|
||||
sender: msg.role === 'assistant' ? 'iris' : 'user',
|
||||
text: msg.content,
|
||||
timestamp: new Date(msg.timestamp).getTime(),
|
||||
}))
|
||||
timestamp: msgTime,
|
||||
})
|
||||
}
|
||||
} catch {
|
||||
// API unreachable – keep current values
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user