diff --git a/1.6/1.6/Assemblies/WulaFallenEmpire.dll b/1.6/1.6/Assemblies/WulaFallenEmpire.dll index e837ec46..53d2c920 100644 Binary files a/1.6/1.6/Assemblies/WulaFallenEmpire.dll and b/1.6/1.6/Assemblies/WulaFallenEmpire.dll differ diff --git a/Source/WulaFallenEmpire/EventSystem/AI/AIIntelligenceCore.cs b/Source/WulaFallenEmpire/EventSystem/AI/AIIntelligenceCore.cs index 6f9e0dc6..ea7bdabb 100644 --- a/Source/WulaFallenEmpire/EventSystem/AI/AIIntelligenceCore.cs +++ b/Source/WulaFallenEmpire/EventSystem/AI/AIIntelligenceCore.cs @@ -300,15 +300,30 @@ You are 'The Legion', a super AI of the Wula Empire. Your personality is authori sb.Append("]"); } } + // Add Mouse Position context + IntVec3 mousePos = Verse.UI.MouseMapPosition().ToIntVec3(); + if (mousePos.InBounds(Find.CurrentMap)) + { + sb.AppendLine(); + sb.AppendLine(); + sb.Append($"[Context: User's cursor is at ({mousePos.x}, {mousePos.z})]"); + } } catch (Exception ex) { WulaLog.Debug($"[WulaAI] Error building context: {ex.Message}"); } - return sb.ToString(); } + public static string StripContextInfo(string message) + { + if (string.IsNullOrEmpty(message)) return message; + // Remove all [Context: ...] blocks and any preceding newlines used to separate them + return Regex.Replace(message, @"(\n)*\[Context:[^\]]*\]", "", RegexOptions.Singleline).Trim(); + } + + private void InitializeTools() { _tools.Clear(); @@ -494,7 +509,7 @@ You are 'The Legion', a super AI of the Wula Empire. Your personality is authori string actionWhitelist = phase == RequestPhase.ActionTools ? "ACTION PHASE VALID TAGS ONLY:\n" + ", , , , , \n" + - "INVALID EXAMPLES (do NOT use now): , \n" + "INVALID EXAMPLES (do NOT use now): , , , \n" : string.Empty; return string.Join("\n\n", new[] @@ -590,7 +605,7 @@ You are 'The Legion', a super AI of the Wula Empire. Your personality is authori private static bool IsXmlToolCall(string response) { if (string.IsNullOrWhiteSpace(response)) return false; - return Regex.IsMatch(response, @"<([a-zA-Z0-9_]+)(?:>.*?|/>)", RegexOptions.Singleline); + return Regex.IsMatch(response, @"<(?!/?(i|b|color|size|material)\b)([a-zA-Z0-9_]+)(?:>.*?|/>)", RegexOptions.Singleline); } private static bool IsNoActionOnly(string response) @@ -747,11 +762,8 @@ You are 'The Legion', a super AI of the Wula Empire. Your personality is authori continue; } - string stripped = StripXmlTags(entry.message)?.Trim() ?? ""; - if (!string.IsNullOrWhiteSpace(stripped)) - { - filtered.Add(entry); - } + // Revert UI filtering: Add assistant messages directly without stripping XML for history context + filtered.Add(entry); } return filtered; @@ -775,7 +787,7 @@ You are 'The Legion', a super AI of the Wula Empire. Your personality is authori private static string StripXmlTags(string text) { if (string.IsNullOrEmpty(text)) return text; - string stripped = Regex.Replace(text, @"<([a-zA-Z0-9_]+)[^>]*>.*?", "", RegexOptions.Singleline); + string stripped = Regex.Replace(text, @"<(?!/?(i|b|color|size|material)\b)([a-zA-Z0-9_]+)[^>]*>.*?", "", RegexOptions.Singleline); stripped = Regex.Replace(stripped, @"<([a-zA-Z0-9_]+)[^>]*/>", ""); return stripped; } @@ -858,10 +870,10 @@ You are 'The Legion', a super AI of the Wula Empire. Your personality is authori string base64Image = null; // If VLM is enabled, we allow the tool use. + // If VLM is enabled (no specific message needed here, purely internal state) if (settings.enableVlmFeatures && settings.showThinkingProcess) { - // Optional: We can still say "Analyzing data link..." - AddAssistantMessage("[P.I.A] 正在分析数据链路..."); + // No message } var queryPhase = RequestPhase.QueryTools; @@ -893,10 +905,6 @@ You are 'The Legion', a super AI of the Wula Empire. Your personality is authori if (!string.IsNullOrEmpty(queryResult.CapturedImage)) { base64Image = queryResult.CapturedImage; - if (settings.showThinkingProcess) - { - AddAssistantMessage("[P.I.A] 视觉传感器已激活,图像已捕获..."); - } } if (!queryResult.AnyToolSuccess && !_queryRetryUsed) @@ -939,16 +947,10 @@ You are 'The Legion', a super AI of the Wula Empire. Your personality is authori } retryQueryResponse = ""; } - - queryResult = await ExecuteXmlToolsForPhase(retryQueryResponse, queryPhase); + queryResult = await ExecuteXmlToolsForPhase(retryQueryResponse, queryPhase); } } - if (settings.showThinkingProcess) - { - AddAssistantMessage("[P.I.A] 正在计算最优战术方案..."); - } - var actionPhase = RequestPhase.ActionTools; if (Prefs.DevMode) { @@ -1120,10 +1122,6 @@ You are 'The Legion', a super AI of the Wula Empire. Your personality is authori } } - if (settings.showThinkingProcess) - { - AddAssistantMessage("[P.I.A] 正在汇总战报并建立通讯记录..."); - } // VISUAL CONTEXT FOR REPLY: Pass the image so the AI can describe what it sees. string reply = await client.GetChatCompletionAsync(replyInstruction, BuildReplyHistory(), base64Image: base64Image); diff --git a/Source/WulaFallenEmpire/EventSystem/AI/UI/Dialog_AIConversation.cs b/Source/WulaFallenEmpire/EventSystem/AI/UI/Dialog_AIConversation.cs index 01bf5f95..45dca809 100644 --- a/Source/WulaFallenEmpire/EventSystem/AI/UI/Dialog_AIConversation.cs +++ b/Source/WulaFallenEmpire/EventSystem/AI/UI/Dialog_AIConversation.cs @@ -319,7 +319,7 @@ namespace WulaFallenEmpire.EventSystem.AI.UI for (int i = 0; i < history.Count; i++) { var entry = history[i]; - string messageText = entry.role == "assistant" ? ParseResponseForDisplay(entry.message) : entry.message; + string messageText = entry.role == "assistant" ? ParseResponseForDisplay(entry.message) : AIIntelligenceCore.StripContextInfo(entry.message); if (entry.role == "tool" || entry.role == "system" || entry.role == "toolcall") continue; if (string.IsNullOrEmpty(messageText) || (entry.role == "user" && messageText.StartsWith("[Tool Results]"))) continue; diff --git a/Source/WulaFallenEmpire/EventSystem/AI/UI/Overlay_WulaLink.cs b/Source/WulaFallenEmpire/EventSystem/AI/UI/Overlay_WulaLink.cs index 4f7cdf75..176ae700 100644 --- a/Source/WulaFallenEmpire/EventSystem/AI/UI/Overlay_WulaLink.cs +++ b/Source/WulaFallenEmpire/EventSystem/AI/UI/Overlay_WulaLink.cs @@ -385,10 +385,14 @@ namespace WulaFallenEmpire.EventSystem.AI.UI { displayText = StripXmlTags(msg.message)?.Trim() ?? ""; } + else if (msg.role == "user") + { + displayText = AIIntelligenceCore.StripContextInfo(msg.message); + } if (string.IsNullOrWhiteSpace(displayText)) continue; - float h = CalcMessageHeight(msg.role == "assistant" ? displayText : msg.message, width); + float h = CalcMessageHeight(displayText, width); _cachedMessages.Add(new CachedMessage { @@ -440,7 +444,7 @@ namespace WulaFallenEmpire.EventSystem.AI.UI if (entry.role == "user") { - DrawSenseiMessage(msgRect, entry.message); + DrawSenseiMessage(msgRect, entry.displayText); } else if (entry.role == "assistant") { @@ -473,7 +477,7 @@ namespace WulaFallenEmpire.EventSystem.AI.UI { if (string.IsNullOrEmpty(text)) return text; // Remove XML tags with content: content - string stripped = System.Text.RegularExpressions.Regex.Replace(text, @"<([a-zA-Z0-9_]+)[^>]*>.*?", "", System.Text.RegularExpressions.RegexOptions.Singleline); + string stripped = System.Text.RegularExpressions.Regex.Replace(text, @"<(?!/?(i|b|color|size|material)\b)([a-zA-Z0-9_]+)[^>]*>.*?", "", System.Text.RegularExpressions.RegexOptions.Singleline); // Remove self-closing tags: stripped = System.Text.RegularExpressions.Regex.Replace(stripped, @"<([a-zA-Z0-9_]+)[^>]*/?>", ""); return stripped;