Files
AX-Copilot-Codex/src/AxCopilot/Views/ChatWindow.xaml.cs.pre-restore

12694 lines
403 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#define DEBUG
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Effects;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;
using AxCopilot.Models;
using AxCopilot.Services;
using AxCopilot.Services.Agent;
using Microsoft.Web.WebView2.Core;
using Microsoft.Win32;
namespace AxCopilot.Views;
public partial class ChatWindow : Window
{
private sealed class ConversationMeta
{
public string Id { get; init; } = "";
public string Title { get; init; } = "";
public string UpdatedAtText { get; init; } = "";
public bool Pinned { get; init; }
public string Category { get; init; } = "?쇰컲";
public string Symbol { get; init; } = "\ue8bd";
public string ColorHex { get; init; } = "#6B7280";
public string Tab { get; init; } = "Chat";
public DateTime UpdatedAt { get; init; }
public string Preview { get; init; } = "";
public string? ParentId { get; init; }
public int ExecutionEventCount { get; init; }
public int ErrorEventCount { get; init; }
}
private readonly SettingsService _settings;
private readonly ChatStorageService _storage;
private readonly LlmService _llm;
private readonly ToolRegistry _toolRegistry;
private readonly AgentLoopService _agentLoop;
private readonly ModelRouterService _router;
private readonly object _convLock = new object();
private ChatConversation? _currentConversation;
private CancellationTokenSource? _streamCts;
private bool _isStreaming;
private bool _sidebarVisible = true;
private bool _showExecutionHistory = true;
private readonly List<string> _draftQueue = new List<string>();
private bool _autoContinuingQueuedDraft;
private string _selectedCategory = "";
private bool _forceClose = false;
private readonly DispatcherTimer _cursorTimer;
private bool _cursorVisible = true;
private TextBlock? _activeStreamText;
private string _cachedStreamContent = "";
private TextBlock? _activeAiIcon;
private bool _aiIconPulseStopped;
private WorkflowAnalyzerWindow? _analyzerWindow;
private PlanViewerWindow? _planViewerWindow;
private bool _userScrolled;
private readonly DispatcherTimer _elapsedTimer;
private DateTime _streamStartTime;
private TextBlock? _elapsedLabel;
private readonly DispatcherTimer _typingTimer;
private int _displayedLength;
private string _activeTab = "Chat";
private readonly Dictionary<string, string?> _tabConversationId = new Dictionary<string, string>
{
["Chat"] = null,
["Cowork"] = null,
["Code"] = null
};
private readonly List<string> _attachedFiles = new List<string>();
private readonly List<ImageAttachment> _pendingImages = new List<ImageAttachment>();
private bool _autoWarningDismissed;
private static readonly HashSet<string> ImageExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { ".png", ".jpg", ".jpeg", ".gif", ".bmp", ".webp" };
private const int ConversationPageSize = 50;
private List<ConversationMeta>? _pendingConversations;
private bool _isEditing;
private List<(string Cmd, string Label, bool IsSkill)> _slashAllMatches = new List<(string, string, bool)>();
private int _slashPageOffset = 0;
private int _slashSelectedIndex = -1;
private string? _activeSlashCmd = null;
private static readonly Dictionary<string, (string Label, string SystemPrompt, string Tab)> SlashCommands = new Dictionary<string, (string, string, string)>(StringComparer.OrdinalIgnoreCase)
{
["/summary"] = ("Summary", "?ъ슜?먭? ?쒓났???댁슜???듭떖 ?ъ씤???꾩<濡?媛꾧껐?섍쾶 ?붿빟??二쇱꽭?? 遺덈┸ ?ъ씤???뺤떇???ъ슜?섏꽭??", "all"),
["/translate"] = ("Translate", "?ъ슜?먭? ?쒓났???띿뒪?몃? ?곸뼱濡?踰덉뿭??二쇱꽭?? ?먮Ц???ㅺ낵 ?섏븰?ㅻ? ?좎??섏꽭??", "all"),
["/explain"] = ("Explain", "?ъ슜?먭? ?쒓났???댁슜???쎄퀬 ?먯꽭?섍쾶 ?ㅻ챸??二쇱꽭?? ?꾩슂?섎㈃ ?덉떆瑜??ы븿?섏꽭??", "all"),
["/fix"] = ("Fix", "?ъ슜?먭? ?쒓났???띿뒪?몄쓽 留욎땄踰? 臾몃쾿, ?먯뿰?ㅻ윭???쒗쁽??援먯젙??二쇱꽭?? ?섏젙 ?ы빆??紐낇솗???쒖떆?섏꽭??", "all"),
["/review"] = ("Code Review", "?묒뾽 ?대뜑??git diff瑜?遺꾩꽍?섏뿬 肄붾뱶 由щ럭瑜??섑뻾??二쇱꽭?? code_review ?꾧뎄瑜??ъ슜?섏꽭??", "dev"),
["/pr"] = ("PR Summary", "?묒뾽 ?대뜑??蹂€寃쎌궗??쓣 PR ?ㅻ챸 ?뺤떇?쇰줈 ?붿빟??二쇱꽭?? code_review(action: pr_summary) ?꾧뎄瑜??ъ슜?섏꽭??", "dev"),
["/test"] = ("Test", "?묒뾽 ?대뜑??肄붾뱶???€???⑥쐞 ?뚯뒪?몃? ?앹꽦??二쇱꽭?? test_loop ?꾧뎄瑜??ъ슜?섏꽭??", "dev"),
["/structure"] = ("Structure", "?묒뾽 ?대뜑???꾨줈?앺듃 援ъ“瑜?遺꾩꽍?섍퀬 ?ㅻ챸??二쇱꽭?? folder_map ?꾧뎄瑜??ъ슜?섏꽭??", "dev"),
["/build"] = ("Build", "?묒뾽 ?대뜑???꾨줈?앺듃瑜?鍮뚮뱶??二쇱꽭?? build_run ?꾧뎄瑜??ъ슜?섏꽭??", "dev"),
["/search"] = ("Search", "?묒뾽 ?대뜑?먯꽌 愿€??肄붾뱶瑜?寃€?됲빐 二쇱꽭?? search_codebase ?꾧뎄瑜??ъ슜?섏꽭??", "dev"),
["/help"] = ("Help", "__HELP__", "all")
};
private static readonly Dictionary<string, List<(string Label, string Icon, string Prompt)>> DropActions;
private static readonly HashSet<string> CodeExtensions;
private static readonly HashSet<string> DataExtensions;
private Popup? _dropActionPopup;
private int _agentCumulativeInputTokens;
private int _agentCumulativeOutputTokens;
private static readonly HashSet<string> WriteToolNames;
private Border? _planningCard;
private StackPanel? _planStepsPanel;
private System.Windows.Controls.ProgressBar? _planProgressBar;
private TextBlock? _planProgressText;
private List<int> _searchMatchIndices = new List<int>();
private int _searchCurrentIndex = -1;
private static readonly string[] Tips;
private int _tipIndex;
private DispatcherTimer? _tipDismissTimer;
private DispatcherTimer? _rainbowTimer;
private DateTime _rainbowStartTime;
private DispatcherTimer? _toastHideTimer;
private string _selectedMood = null;
private string _selectedLanguage = "auto";
private string _folderDataUsage = null;
private string? _promptCardPlaceholder;
private static readonly (string Id, string Label)[] GeminiModels;
private static readonly (string Id, string Label)[] ClaudeModels;
private static readonly HashSet<string> _previewableExtensions;
private readonly List<string> _previewTabs = new List<string>();
private string? _activePreviewTab;
private bool _webViewInitialized;
private static readonly string WebView2DataFolder;
private Popup? _previewTabPopup;
private DateTime _progressStartTime;
private DispatcherTimer? _progressElapsedTimer;
private static readonly HashSet<string> _ignoredDirs;
private DispatcherTimer? _fileBrowserRefreshTimer;
private Storyboard? _statusSpinStoryboard;
private int SlashPageSize => Math.Clamp(_settings.Settings.Llm.SlashPopupPageSize, 3, 20);
public ChatWindow(SettingsService settings)
{
//IL_0210: Unknown result type (might be due to invalid IL or missing references)
//IL_0215: Unknown result type (might be due to invalid IL or missing references)
//IL_022f: Expected O, but got Unknown
//IL_0248: Unknown result type (might be due to invalid IL or missing references)
//IL_024d: Unknown result type (might be due to invalid IL or missing references)
//IL_0267: Expected O, but got Unknown
//IL_0280: Unknown result type (might be due to invalid IL or missing references)
//IL_0285: Unknown result type (might be due to invalid IL or missing references)
//IL_029f: Expected O, but got Unknown
InitializeComponent();
_settings = settings;
_storage = new ChatStorageService();
_llm = new LlmService(settings);
_router = new ModelRouterService(settings);
_toolRegistry = ToolRegistry.CreateDefault();
_agentLoop = new AgentLoopService(_llm, _toolRegistry, settings)
{
Dispatcher = delegate(Action action)
{
((DispatcherObject)System.Windows.Application.Current).Dispatcher.Invoke(action);
},
AskPermissionCallback = async delegate(string toolName, string filePath)
{
MessageBoxResult result = MessageBoxResult.None;
await ((DispatcherObject)System.Windows.Application.Current).Dispatcher.InvokeAsync((Action)delegate
{
result = CustomMessageBox.Show($"?꾧뎄 '{toolName}'??媛€) ?ㅼ쓬 ?뚯씪???묎렐?섎젮 ?⑸땲??\n\n{filePath}\n\n?덉슜?섏떆寃좎뒿?덇퉴?", "AX Agent ??沅뚰븳 ?뺤씤", MessageBoxButton.YesNo, MessageBoxImage.Question);
});
return result == MessageBoxResult.Yes;
},
UserAskCallback = async delegate(string question, List<string> options, string defaultValue)
{
string response = null;
await ((DispatcherObject)System.Windows.Application.Current).Dispatcher.InvokeAsync((Action)delegate
{
response = UserAskDialog.Show(question, options, defaultValue);
});
return response;
}
};
SubAgentTool.StatusChanged += OnSubAgentStatusChanged;
_selectedMood = settings.Settings.Llm.DefaultMood ?? "modern";
_folderDataUsage = settings.Settings.Llm.FolderDataUsage ?? "active";
_cursorTimer = new DispatcherTimer
{
Interval = TimeSpan.FromMilliseconds(530.0)
};
_cursorTimer.Tick += CursorTimer_Tick;
_elapsedTimer = new DispatcherTimer
{
Interval = TimeSpan.FromSeconds(1.0)
};
_elapsedTimer.Tick += ElapsedTimer_Tick;
_typingTimer = new DispatcherTimer
{
Interval = TimeSpan.FromMilliseconds(12.0)
};
_typingTimer.Tick += TypingTimer_Tick;
base.KeyDown += ChatWindow_KeyDown;
base.Loaded += delegate
{
SetupUserInfo();
_selectedMood = _settings.Settings.Llm.DefaultMood ?? "modern";
_folderDataUsage = _settings.Settings.Llm.FolderDataUsage ?? "active";
UpdateAnalyzerButtonVisibility();
UpdateModelLabel();
InputBox.Focus();
UpdateDraftPreviewCard();
MessageScroll.ScrollChanged += MessageScroll_ScrollChanged;
((DispatcherObject)this).Dispatcher.BeginInvoke((Delegate)(Action)delegate
{
TemplateService.LoadCustomMoods(_settings.Settings.Llm.CustomMoods);
BuildTopicButtons();
RestoreLastConversations();
RefreshConversationList();
LoadMcpToolsAsync();
UpdateExecutionHistoryUi();
RefreshSubAgentIndicator();
Task.Run(delegate
{
int retentionDays = _settings.Settings.Llm.RetentionDays;
if (retentionDays > 0)
{
_storage.PurgeExpired(retentionDays);
}
_storage.PurgeForDiskSpace();
});
}, (DispatcherPriority)2, Array.Empty<object>());
System.Windows.Media.Brush accentBrush = (TryFindResource("AccentColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Blue;
System.Windows.Media.Brush borderBrush = (TryFindResource("BorderColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
InputBox.GotFocus += delegate
{
InputBorder.BorderBrush = accentBrush;
};
InputBox.LostFocus += delegate
{
InputBorder.BorderBrush = borderBrush;
};
InputBorder.AllowDrop = true;
InputBorder.DragOver += delegate(object obj, System.Windows.DragEventArgs de)
{
de.Effects = (de.Data.GetDataPresent(System.Windows.DataFormats.FileDrop) ? System.Windows.DragDropEffects.Copy : System.Windows.DragDropEffects.None);
de.Handled = true;
};
InputBorder.Drop += delegate(object obj, System.Windows.DragEventArgs de)
{
if (de.Data.GetData(System.Windows.DataFormats.FileDrop) is string[] array && array.Length != 0)
{
if (_settings.Settings.Llm.EnableDragDropAiActions && array.Length <= 5)
{
ShowDropActionMenu(array);
}
else
{
string[] array2 = array;
foreach (string filePath in array2)
{
AddAttachedFile(filePath);
}
}
}
};
if (_settings.Settings.Llm.EnableSkillSystem)
{
SkillService.EnsureSkillFolder();
SkillService.LoadSkills(_settings.Settings.Llm.SkillsFolderPath);
}
SlashNavUp.MouseLeftButtonUp += delegate
{
_slashPageOffset = Math.Max(0, _slashPageOffset - SlashPageSize);
RenderSlashPage();
};
SlashNavDown.MouseLeftButtonUp += delegate
{
_slashPageOffset = Math.Min(_slashAllMatches.Count - 1, _slashPageOffset + SlashPageSize);
RenderSlashPage();
};
SlashChipClose.MouseLeftButtonUp += delegate
{
HideSlashChip(restoreText: true);
InputBox.Focus();
};
InputBox.PreviewMouseWheel += delegate(object obj, MouseWheelEventArgs me)
{
if (SlashPopup.IsOpen)
{
me.Handled = true;
SlashPopup_ScrollByDelta(me.Delta);
}
};
UpdateFolderBar();
ApplyHoverBounceAnimation(BtnModelSelector);
ApplyHoverBounceAnimation(BtnTemplateSelector, -1.5);
ApplyHoverScaleAnimation(BtnSend, 1.12);
ApplyHoverScaleAnimation(BtnStop, 1.12);
};
base.Closed += delegate
{
_streamCts?.Cancel();
_cursorTimer.Stop();
_elapsedTimer.Stop();
_typingTimer.Stop();
SubAgentTool.StatusChanged -= OnSubAgentStatusChanged;
_llm.Dispose();
};
}
private async Task LoadMcpToolsAsync()
{
try
{
List<McpServerEntry> servers = _settings.Settings.Llm.McpServers;
if (servers != null && servers.Count != 0)
{
int count = await _toolRegistry.RegisterMcpToolsAsync(servers);
if (count > 0)
{
LogService.Info($"MCP tools registered for AX Agent: {count}");
}
}
}
catch (Exception ex)
{
Exception ex2 = ex;
LogService.Warn("Failed to register MCP tools: " + ex2.Message);
}
}
protected override void OnClosing(CancelEventArgs e)
{
if (!_forceClose)
{
e.Cancel = true;
Hide();
}
else
{
base.OnClosing(e);
}
}
public void ForceClose()
{
lock (_convLock)
{
if (_currentConversation != null && _currentConversation.Messages.Count > 0)
{
_tabConversationId[_activeTab] = _currentConversation.Id;
try
{
_storage.Save(_currentConversation);
}
catch
{
}
}
}
SaveLastConversations();
_forceClose = true;
Close();
}
private void SetupUserInfo()
{
string userName = Environment.UserName;
string text = userName;
char[] array = new char[3] { '\\', '/', ':' };
foreach (char value in array)
{
int num = text.LastIndexOf(value);
if (num >= 0)
{
string text2 = text;
int num2 = num + 1;
text = text2.Substring(num2, text2.Length - num2);
}
}
string text3 = ((text.Length > 0) ? text.Substring(0, 1).ToUpper() : "U");
string machineName = Environment.MachineName;
UserInitialSidebar.Text = text3;
UserInitialIconBar.Text = text3;
UserNameText.Text = text;
UserPcText.Text = machineName;
BtnUserIconBar.ToolTip = text + " (" + machineName + ")";
}
private void MessageScroll_ScrollChanged(object sender, ScrollChangedEventArgs e)
{
if (MessageScroll.ScrollableHeight <= 1.0)
{
_userScrolled = false;
}
else if (!(Math.Abs(e.ExtentHeightChange) > 0.5))
{
bool flag = MessageScroll.VerticalOffset >= MessageScroll.ScrollableHeight - 40.0;
_userScrolled = !flag;
}
}
private void AutoScrollIfNeeded()
{
if (!_userScrolled)
{
SmoothScrollToEnd();
}
}
private void ForceScrollToEnd()
{
_userScrolled = false;
((DispatcherObject)this).Dispatcher.InvokeAsync((Action)delegate
{
SmoothScrollToEnd();
}, (DispatcherPriority)4);
}
private void SmoothScrollToEnd()
{
//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
//IL_0103: Expected O, but got Unknown
double targetOffset = MessageScroll.ScrollableHeight;
double currentOffset = MessageScroll.VerticalOffset;
double diff = targetOffset - currentOffset;
if (diff <= 60.0)
{
MessageScroll.ScrollToEnd();
return;
}
DoubleAnimation doubleAnimation = new DoubleAnimation
{
From = currentOffset,
To = targetOffset,
Duration = TimeSpan.FromMilliseconds(200.0),
EasingFunction = new CubicEase
{
EasingMode = EasingMode.EaseOut
}
};
doubleAnimation.Completed += delegate
{
MessageScroll.ScrollToVerticalOffset(targetOffset);
};
DateTime startTime = DateTime.UtcNow;
DispatcherTimer timer = new DispatcherTimer
{
Interval = TimeSpan.FromMilliseconds(16.0)
};
EventHandler tickHandler = null;
tickHandler = delegate
{
double totalMilliseconds = (DateTime.UtcNow - startTime).TotalMilliseconds;
double num = Math.Min(totalMilliseconds / 200.0, 1.0);
double num2 = 1.0 - Math.Pow(1.0 - num, 3.0);
double offset = currentOffset + diff * num2;
MessageScroll.ScrollToVerticalOffset(offset);
if (num >= 1.0)
{
timer.Stop();
timer.Tick -= tickHandler;
}
};
timer.Tick += tickHandler;
timer.Start();
}
private void ChatTitle_MouseDown(object sender, MouseButtonEventArgs e)
{
lock (_convLock)
{
if (_currentConversation == null)
{
return;
}
}
ChatTitle.Visibility = Visibility.Collapsed;
ChatTitleEdit.Text = ChatTitle.Text;
ChatTitleEdit.Visibility = Visibility.Visible;
ChatTitleEdit.Focus();
ChatTitleEdit.SelectAll();
}
private void ChatTitleEdit_LostFocus(object sender, RoutedEventArgs e)
{
CommitTitleEdit();
}
private void ChatTitleEdit_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Invalid comparison between Unknown and I4
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Invalid comparison between Unknown and I4
if ((int)e.Key == 6)
{
CommitTitleEdit();
e.Handled = true;
}
if ((int)e.Key == 13)
{
CancelTitleEdit();
e.Handled = true;
}
}
private void CommitTitleEdit()
{
string text = ChatTitleEdit.Text.Trim();
ChatTitleEdit.Visibility = Visibility.Collapsed;
ChatTitle.Visibility = Visibility.Visible;
if (string.IsNullOrEmpty(text))
{
return;
}
lock (_convLock)
{
if (_currentConversation == null)
{
return;
}
_currentConversation.Title = text;
}
ChatTitle.Text = text;
try
{
ChatConversation currentConversation;
lock (_convLock)
{
currentConversation = _currentConversation;
}
_storage.Save(currentConversation);
}
catch
{
}
RefreshConversationList();
}
private void CancelTitleEdit()
{
ChatTitleEdit.Visibility = Visibility.Collapsed;
ChatTitle.Visibility = Visibility.Visible;
}
private void BtnCategoryDrop_Click(object sender, RoutedEventArgs e)
{
System.Windows.Media.Brush background = (TryFindResource("LauncherBackground") as System.Windows.Media.Brush) ?? new SolidColorBrush(System.Windows.Media.Color.FromRgb(26, 27, 46));
System.Windows.Media.Brush borderBrush = (TryFindResource("BorderColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
System.Windows.Media.Brush primaryText = (TryFindResource("PrimaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.White;
System.Windows.Media.Brush iconColor = (TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
System.Windows.Media.Brush hoverBg = (TryFindResource("ItemHoverBackground") as System.Windows.Media.Brush) ?? new SolidColorBrush(System.Windows.Media.Color.FromArgb(30, byte.MaxValue, byte.MaxValue, byte.MaxValue));
System.Windows.Media.Brush accentBrush = (TryFindResource("AccentColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.CornflowerBlue;
Popup popup = new Popup
{
StaysOpen = false,
AllowsTransparency = true,
PopupAnimation = PopupAnimation.Fade,
PlacementTarget = BtnCategoryDrop,
Placement = PlacementMode.Bottom,
HorizontalOffset = 0.0,
VerticalOffset = 4.0
};
Border border = new Border
{
Background = background,
BorderBrush = borderBrush,
BorderThickness = new Thickness(1.0),
CornerRadius = new CornerRadius(12.0),
Padding = new Thickness(6.0),
MinWidth = 180.0,
Effect = new DropShadowEffect
{
BlurRadius = 16.0,
ShadowDepth = 4.0,
Opacity = 0.3,
Color = Colors.Black
}
};
StackPanel stackPanel = new StackPanel();
string activeTab = _activeTab;
if (1 == 0)
{
}
string text = ((activeTab == "Cowork") ? "紐⑤뱺 ?묒뾽" : ((!(activeTab == "Code")) ? "紐⑤뱺 二쇱젣" : "紐⑤뱺 ?묒뾽"));
if (1 == 0)
{
}
string text2 = text;
stackPanel.Children.Add(CreateCatItem("\ue8bd", text2, iconColor, string.IsNullOrEmpty(_selectedCategory), delegate
{
_selectedCategory = "";
UpdateCategoryLabel();
RefreshConversationList();
}));
stackPanel.Children.Add(CreateSep());
if (_activeTab == "Cowork" || _activeTab == "Code")
{
IReadOnlyList<TopicPreset> byTabWithCustom = PresetService.GetByTabWithCustom(_activeTab, _settings.Settings.Llm.CustomPresets);
HashSet<string> hashSet = new HashSet<string>();
foreach (TopicPreset item5 in byTabWithCustom)
{
if (!item5.IsCustom && hashSet.Add(item5.Category))
{
string capturedCat = item5.Category;
stackPanel.Children.Add(CreateCatItem(item5.Symbol, item5.Label, BrushFromHex(item5.Color), _selectedCategory == capturedCat, delegate
{
_selectedCategory = capturedCat;
UpdateCategoryLabel();
RefreshConversationList();
}));
}
}
if (byTabWithCustom.Any((TopicPreset p) => p.IsCustom))
{
stackPanel.Children.Add(CreateSep());
stackPanel.Children.Add(CreateCatItem("\ue710", "而ㅼ뒪?€ ?꾨━??, iconColor, _selectedCategory == "__custom__", delegate
{
_selectedCategory = "__custom__";
UpdateCategoryLabel();
RefreshConversationList();
}));
}
}
else
{
(string, string, string, string)[] all = ChatCategory.All;
for (int num = 0; num < all.Length; num++)
{
(string, string, string, string) tuple = all[num];
string item = tuple.Item1;
string item2 = tuple.Item2;
string item3 = tuple.Item3;
string item4 = tuple.Item4;
string capturedKey = item;
stackPanel.Children.Add(CreateCatItem(item3, item2, BrushFromHex(item4), _selectedCategory == capturedKey, delegate
{
_selectedCategory = capturedKey;
UpdateCategoryLabel();
RefreshConversationList();
}));
}
List<CustomPresetEntry> list = _settings.Settings.Llm.CustomPresets.Where((CustomPresetEntry c) => c.Tab == "Chat").ToList();
if (list.Count > 0)
{
stackPanel.Children.Add(CreateSep());
stackPanel.Children.Add(CreateCatItem("\ue710", "而ㅼ뒪?€ ?꾨━??, iconColor, _selectedCategory == "__custom__", delegate
{
_selectedCategory = "__custom__";
UpdateCategoryLabel();
RefreshConversationList();
}));
}
}
border.Child = stackPanel;
popup.Child = border;
popup.IsOpen = true;
Border CreateCatItem(string icon, string text3, System.Windows.Media.Brush foreground, bool isSelected, Action onClick)
{
Border border2 = new Border
{
Background = System.Windows.Media.Brushes.Transparent,
CornerRadius = new CornerRadius(8.0),
Padding = new Thickness(10.0, 7.0, 10.0, 7.0),
Margin = new Thickness(0.0, 1.0, 0.0, 1.0),
Cursor = System.Windows.Input.Cursors.Hand
};
Grid grid = new Grid
{
ColumnDefinitions =
{
new ColumnDefinition
{
Width = new GridLength(24.0)
},
new ColumnDefinition
{
Width = new GridLength(1.0, GridUnitType.Star)
},
new ColumnDefinition
{
Width = new GridLength(20.0)
}
}
};
TextBlock element = new TextBlock
{
Text = icon,
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 12.0,
Foreground = foreground,
VerticalAlignment = VerticalAlignment.Center
};
Grid.SetColumn(element, 0);
grid.Children.Add(element);
TextBlock element2 = new TextBlock
{
Text = text3,
FontSize = 12.5,
Foreground = primaryText,
VerticalAlignment = VerticalAlignment.Center
};
Grid.SetColumn(element2, 1);
grid.Children.Add(element2);
if (isSelected)
{
FrameworkElement element3 = CreateSimpleCheck(accentBrush);
Grid.SetColumn(element3, 2);
grid.Children.Add(element3);
}
border2.Child = grid;
border2.MouseEnter += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border border3)
{
border3.Background = hoverBg;
}
};
border2.MouseLeave += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border border3)
{
border3.Background = System.Windows.Media.Brushes.Transparent;
}
};
border2.MouseLeftButtonUp += delegate
{
popup.IsOpen = false;
onClick();
};
return border2;
}
Border CreateSep()
{
return new Border
{
Height = 1.0,
Background = borderBrush,
Opacity = 0.3,
Margin = new Thickness(8.0, 4.0, 8.0, 4.0)
};
}
}
private void UpdateCategoryLabel()
{
if (string.IsNullOrEmpty(_selectedCategory))
{
TextBlock categoryLabel = CategoryLabel;
string activeTab = _activeTab;
if (1 == 0)
{
}
string text = ((!(activeTab == "Cowork") && !(activeTab == "Code")) ? "紐⑤뱺 二쇱젣" : "紐⑤뱺 ?묒뾽");
if (1 == 0)
{
}
categoryLabel.Text = text;
CategoryIcon.Text = "\ue8bd";
return;
}
if (_selectedCategory == "__custom__")
{
CategoryLabel.Text = "而ㅼ뒪?€ ?꾨━??;
CategoryIcon.Text = "\ue710";
return;
}
(string, string, string, string)[] all = ChatCategory.All;
for (int i = 0; i < all.Length; i++)
{
var (text2, text3, text4, _) = all[i];
if (text2 == _selectedCategory)
{
CategoryLabel.Text = text3;
CategoryIcon.Text = text4;
return;
}
}
IReadOnlyList<TopicPreset> byTabWithCustom = PresetService.GetByTabWithCustom(_activeTab, _settings.Settings.Llm.CustomPresets);
TopicPreset topicPreset = byTabWithCustom.FirstOrDefault((TopicPreset p) => p.Category == _selectedCategory);
if (topicPreset != null)
{
CategoryLabel.Text = topicPreset.Label;
CategoryIcon.Text = topicPreset.Symbol;
}
else
{
CategoryLabel.Text = _selectedCategory;
CategoryIcon.Text = "\ue8bd";
}
}
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
HwndSource.FromHwnd(new WindowInteropHelper(this).Handle)?.AddHook(WndProc);
}
private nint WndProc(nint hwnd, int msg, nint wParam, nint lParam, ref bool handled)
{
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
if (msg == 36)
{
Screen screen = Screen.FromHandle(hwnd);
System.Drawing.Rectangle workingArea = screen.WorkingArea;
System.Drawing.Rectangle bounds = screen.Bounds;
HwndSource hwndSource = HwndSource.FromHwnd(hwnd);
double? obj;
if (hwndSource == null)
{
obj = null;
}
else
{
HwndTarget compositionTarget = hwndSource.CompositionTarget;
if (compositionTarget == null)
{
obj = null;
}
else
{
Matrix transformToDevice = compositionTarget.TransformToDevice;
obj = transformToDevice.M11;
}
}
double num = obj ?? 1.0;
Marshal.WriteInt32(lParam, 8, workingArea.Width);
Marshal.WriteInt32(lParam, 12, workingArea.Height);
Marshal.WriteInt32(lParam, 16, workingArea.Left - bounds.Left);
Marshal.WriteInt32(lParam, 20, workingArea.Top - bounds.Top);
handled = true;
}
return IntPtr.Zero;
}
private void BtnMinimize_Click(object sender, RoutedEventArgs e)
{
base.WindowState = WindowState.Minimized;
}
private void BtnMaximize_Click(object sender, RoutedEventArgs e)
{
base.WindowState = ((base.WindowState != WindowState.Maximized) ? WindowState.Maximized : WindowState.Normal);
MaximizeIcon.Text = ((base.WindowState == WindowState.Maximized) ? "\ue923" : "\ue739");
}
private void BtnClose_Click(object sender, RoutedEventArgs e)
{
Close();
}
private void SaveCurrentTabConversationId()
{
lock (_convLock)
{
if (_currentConversation != null && _currentConversation.Messages.Count > 0)
{
_tabConversationId[_activeTab] = _currentConversation.Id;
try
{
_storage.Save(_currentConversation);
}
catch
{
}
}
}
SaveLastConversations();
}
private void StopStreamingIfActive()
{
if (_isStreaming)
{
_streamCts?.Cancel();
_cursorTimer.Stop();
_elapsedTimer.Stop();
_typingTimer.Stop();
StopRainbowGlow();
HideStickyProgress();
_activeStreamText = null;
_elapsedLabel = null;
_cachedStreamContent = "";
_isStreaming = false;
BtnSend.IsEnabled = true;
BtnStop.Visibility = Visibility.Collapsed;
BtnPause.Visibility = Visibility.Collapsed;
PauseIcon.Text = "\ue769";
BtnSend.Visibility = Visibility.Visible;
_streamCts?.Dispose();
_streamCts = null;
SetStatusIdle();
}
}
private void TabChat_Checked(object sender, RoutedEventArgs e)
{
if (!(_activeTab == "Chat"))
{
StopStreamingIfActive();
SaveCurrentTabConversationId();
_activeTab = "Chat";
_selectedCategory = "";
UpdateCategoryLabel();
UpdateTabUI();
}
}
private void TabCowork_Checked(object sender, RoutedEventArgs e)
{
if (!(_activeTab == "Cowork"))
{
StopStreamingIfActive();
SaveCurrentTabConversationId();
_activeTab = "Cowork";
_selectedCategory = "";
UpdateCategoryLabel();
UpdateTabUI();
}
}
private void TabCode_Checked(object sender, RoutedEventArgs e)
{
if (!(_activeTab == "Code"))
{
StopStreamingIfActive();
SaveCurrentTabConversationId();
_activeTab = "Code";
_selectedCategory = "";
UpdateCategoryLabel();
UpdateTabUI();
}
}
private void UpdateTabUI()
{
if (FolderBar != null)
{
FolderBar.Visibility = ((!(_activeTab != "Chat")) ? Visibility.Collapsed : Visibility.Visible);
}
if (InputWatermark != null)
{
TextBlock inputWatermark = InputWatermark;
string activeTab = _activeTab;
if (1 == 0)
{
}
string text = ((activeTab == "Cowork") ? "?먯씠?꾪듃?먭쾶 ?묒뾽???붿껌?섏꽭??(?뚯씪 ?쎄린/?곌린, 臾몄꽌 ?앹꽦...)" : ((!(activeTab == "Code")) ? _promptCardPlaceholder : "肄붾뱶 愿€???묒뾽???붿껌?섏꽭??.."));
if (1 == 0)
{
}
inputWatermark.Text = text;
}
ApplyTabDefaultPermission();
if (_activeTab == "Cowork")
{
BuildBottomBar();
if (_settings.Settings.Llm.ShowFileBrowser && FileBrowserPanel != null)
{
FileBrowserPanel.Visibility = Visibility.Visible;
BuildFileTree();
}
}
else if (_activeTab == "Code")
{
BuildCodeBottomBar();
if (_settings.Settings.Llm.ShowFileBrowser && FileBrowserPanel != null)
{
FileBrowserPanel.Visibility = Visibility.Visible;
BuildFileTree();
}
}
else
{
MoodIconPanel.Children.Clear();
if (FormatMoodSeparator != null)
{
FormatMoodSeparator.Visibility = Visibility.Collapsed;
}
if (FileBrowserPanel != null)
{
FileBrowserPanel.Visibility = Visibility.Collapsed;
}
}
BuildTopicButtons();
SwitchToTabConversation();
ShowRandomTip();
}
private void SwitchToTabConversation()
{
lock (_convLock)
{
if (_currentConversation != null && _currentConversation.Messages.Count > 0)
{
try
{
_storage.Save(_currentConversation);
}
catch
{
}
}
}
string valueOrDefault = _tabConversationId.GetValueOrDefault(_activeTab);
if (!string.IsNullOrEmpty(valueOrDefault))
{
ChatConversation chatConversation = _storage.Load(valueOrDefault);
if (chatConversation != null)
{
if (string.IsNullOrEmpty(chatConversation.Tab))
{
chatConversation.Tab = _activeTab;
}
lock (_convLock)
{
_currentConversation = chatConversation;
}
MessagePanel.Children.Clear();
foreach (ChatMessage message in chatConversation.Messages)
{
AddMessageBubble(message.Role, message.Content, animate: false, message);
}
EmptyState.Visibility = ((chatConversation.Messages.Count > 0) ? Visibility.Collapsed : Visibility.Visible);
UpdateChatTitle();
RefreshConversationList();
UpdateFolderBar();
return;
}
}
lock (_convLock)
{
_currentConversation = new ChatConversation
{
Tab = _activeTab
};
string workFolder = _settings.Settings.Llm.WorkFolder;
if (!string.IsNullOrEmpty(workFolder) && _activeTab != "Chat")
{
_currentConversation.WorkFolder = workFolder;
}
}
MessagePanel.Children.Clear();
EmptyState.Visibility = Visibility.Visible;
_attachedFiles.Clear();
RefreshAttachedFilesUI();
UpdateChatTitle();
RefreshConversationList();
UpdateFolderBar();
}
private void FolderPathLabel_Click(object sender, MouseButtonEventArgs e)
{
ShowFolderMenu();
}
private void ShowFolderMenu()
{
FolderMenuItems.Children.Clear();
System.Windows.Media.Brush brush = (TryFindResource("AccentColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.CornflowerBlue;
System.Windows.Media.Brush foreground = (TryFindResource("PrimaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.White;
System.Windows.Media.Brush foreground2 = (TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
int count = Math.Clamp(_settings.Settings.Llm.MaxRecentFolders, 3, 30);
List<string> list = _settings.Settings.Llm.RecentWorkFolders.Where((string p) => IsPathAllowed(p) && Directory.Exists(p)).Take(count).ToList();
if (list.Count > 0)
{
FolderMenuItems.Children.Add(new TextBlock
{
Text = "理쒓렐 ?대뜑",
FontSize = 12.5,
FontWeight = FontWeights.SemiBold,
Foreground = foreground2,
Margin = new Thickness(10.0, 6.0, 10.0, 4.0)
});
string currentWorkFolder = GetCurrentWorkFolder();
foreach (string item in list)
{
bool flag = item.Equals(currentWorkFolder, StringComparison.OrdinalIgnoreCase);
string text = System.IO.Path.GetFileName(item);
if (string.IsNullOrEmpty(text))
{
text = item;
}
StackPanel stackPanel = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal
};
if (flag)
{
FrameworkElement frameworkElement = CreateSimpleCheck(brush);
frameworkElement.Margin = new Thickness(0.0, 0.0, 8.0, 0.0);
stackPanel.Children.Add(frameworkElement);
}
TextBlock element = new TextBlock
{
Text = text,
FontSize = 14.0,
FontWeight = (flag ? FontWeights.SemiBold : FontWeights.Normal),
Foreground = foreground,
VerticalAlignment = VerticalAlignment.Center,
MaxWidth = 340.0,
TextTrimming = TextTrimming.CharacterEllipsis
};
stackPanel.Children.Add(element);
Border border = new Border
{
Child = stackPanel,
Background = System.Windows.Media.Brushes.Transparent,
CornerRadius = new CornerRadius(8.0),
Cursor = System.Windows.Input.Cursors.Hand,
Padding = new Thickness(10.0, 7.0, 10.0, 7.0),
ToolTip = item
};
border.MouseEnter += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border border3)
{
border3.Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(24, byte.MaxValue, byte.MaxValue, byte.MaxValue));
}
};
border.MouseLeave += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border border3)
{
border3.Background = System.Windows.Media.Brushes.Transparent;
}
};
string capturedPath = item;
border.MouseLeftButtonUp += delegate
{
FolderMenuPopup.IsOpen = false;
SetWorkFolder(capturedPath);
};
border.MouseRightButtonUp += delegate(object _, MouseButtonEventArgs re)
{
re.Handled = true;
ShowRecentFolderContextMenu(capturedPath);
};
FolderMenuItems.Children.Add(border);
}
FolderMenuItems.Children.Add(new Border
{
Height = 1.0,
Background = ((TryFindResource("BorderColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray),
Margin = new Thickness(8.0, 4.0, 8.0, 4.0),
Opacity = 0.5
});
}
StackPanel stackPanel2 = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal
};
stackPanel2.Children.Add(new TextBlock
{
Text = "\ued25",
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 14.0,
Foreground = brush,
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(0.0, 0.0, 8.0, 0.0)
});
stackPanel2.Children.Add(new TextBlock
{
Text = "?대뜑 李얠븘蹂닿린...",
FontSize = 14.0,
Foreground = foreground,
VerticalAlignment = VerticalAlignment.Center
});
Border border2 = new Border
{
Child = stackPanel2,
Background = System.Windows.Media.Brushes.Transparent,
CornerRadius = new CornerRadius(8.0),
Cursor = System.Windows.Input.Cursors.Hand,
Padding = new Thickness(10.0, 7.0, 10.0, 7.0)
};
border2.MouseEnter += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border border3)
{
border3.Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(24, byte.MaxValue, byte.MaxValue, byte.MaxValue));
}
};
border2.MouseLeave += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border border3)
{
border3.Background = System.Windows.Media.Brushes.Transparent;
}
};
border2.MouseLeftButtonUp += delegate
{
FolderMenuPopup.IsOpen = false;
BrowseWorkFolder();
};
FolderMenuItems.Children.Add(border2);
FolderMenuPopup.IsOpen = true;
}
private void BrowseWorkFolder()
{
FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog
{
Description = "?묒뾽 ?대뜑瑜??좏깮?섏꽭??,
ShowNewFolderButton = false,
UseDescriptionForTitle = true
};
string currentWorkFolder = GetCurrentWorkFolder();
if (!string.IsNullOrEmpty(currentWorkFolder) && Directory.Exists(currentWorkFolder))
{
folderBrowserDialog.SelectedPath = currentWorkFolder;
}
if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
if (!IsPathAllowed(folderBrowserDialog.SelectedPath))
{
CustomMessageBox.Show("??寃쎈줈???묒뾽 ?대뜑濡??좏깮?????놁뒿?덈떎.", "寃쎈줈 ?쒗븳", MessageBoxButton.OK, MessageBoxImage.Exclamation);
}
else
{
SetWorkFolder(folderBrowserDialog.SelectedPath);
}
}
}
private static bool IsPathAllowed(string path)
{
if (string.IsNullOrWhiteSpace(path))
{
return false;
}
string text = path.TrimEnd('\\', '/');
if (text.Equals("C:", StringComparison.OrdinalIgnoreCase))
{
return false;
}
if (path.IndexOf("Document", StringComparison.OrdinalIgnoreCase) >= 0)
{
return false;
}
return true;
}
private void SetWorkFolder(string path)
{
string fullPath = System.IO.Path.GetFullPath(path);
string pathRoot = System.IO.Path.GetPathRoot(fullPath);
if (!string.IsNullOrEmpty(pathRoot) && fullPath.TrimEnd('\\', '/').Equals(pathRoot.TrimEnd('\\', '/'), StringComparison.OrdinalIgnoreCase))
{
ShowToast("?쒕씪?대툕 猷⑦듃(" + pathRoot + ")???묒뾽怨듦컙?쇰줈 ?ㅼ젙?????놁뒿?덈떎. ?섏쐞 ?대뜑瑜??좏깮?섏꽭??", "\ue783", 3000);
return;
}
FolderPathLabel.Text = path;
FolderPathLabel.ToolTip = path;
lock (_convLock)
{
if (_currentConversation != null)
{
_currentConversation.WorkFolder = path;
}
}
List<string> recentWorkFolders = _settings.Settings.Llm.RecentWorkFolders;
recentWorkFolders.RemoveAll((string p) => !IsPathAllowed(p));
recentWorkFolders.Remove(path);
recentWorkFolders.Insert(0, path);
int num = Math.Clamp(_settings.Settings.Llm.MaxRecentFolders, 3, 30);
if (recentWorkFolders.Count > num)
{
recentWorkFolders.RemoveRange(num, recentWorkFolders.Count - num);
}
_settings.Settings.Llm.WorkFolder = path;
_settings.Save();
}
private string GetCurrentWorkFolder()
{
lock (_convLock)
{
if (_currentConversation != null && !string.IsNullOrEmpty(_currentConversation.WorkFolder))
{
return _currentConversation.WorkFolder;
}
}
return _settings.Settings.Llm.WorkFolder;
}
private ContextMenu CreateThemedContextMenu()
{
System.Windows.Media.Brush background = (TryFindResource("LauncherBackground") as System.Windows.Media.Brush) ?? new SolidColorBrush(System.Windows.Media.Color.FromRgb(30, 30, 46));
System.Windows.Media.Brush borderBrush = (TryFindResource("BorderColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
return new ContextMenu
{
Background = background,
BorderBrush = borderBrush,
BorderThickness = new Thickness(1.0),
Padding = new Thickness(4.0)
};
}
private void ShowRecentFolderContextMenu(string folderPath)
{
ContextMenu menu = CreateThemedContextMenu();
System.Windows.Media.Brush primaryText = (TryFindResource("PrimaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.White;
System.Windows.Media.Brush secondaryText = (TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
AddItem("\ued25", "?대뜑 ?닿린", delegate
{
try
{
Process.Start(new ProcessStartInfo
{
FileName = folderPath,
UseShellExecute = true
});
}
catch
{
}
});
AddItem("\ue8c8", "寃쎈줈 蹂듭궗", delegate
{
try
{
System.Windows.Clipboard.SetText(folderPath);
}
catch
{
}
});
menu.Items.Add(new Separator());
AddItem("\ue74d", "紐⑸줉?먯꽌 ??젣", delegate
{
_settings.Settings.Llm.RecentWorkFolders.RemoveAll((string p) => p.Equals(folderPath, StringComparison.OrdinalIgnoreCase));
_settings.Save();
if (FolderMenuPopup.IsOpen)
{
ShowFolderMenu();
}
});
menu.IsOpen = true;
void AddItem(string icon, string label, Action action)
{
StackPanel stackPanel = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal
};
stackPanel.Children.Add(new TextBlock
{
Text = icon,
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 12.0,
Foreground = secondaryText,
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(0.0, 0.0, 8.0, 0.0)
});
stackPanel.Children.Add(new TextBlock
{
Text = label,
FontSize = 12.0,
Foreground = primaryText,
VerticalAlignment = VerticalAlignment.Center
});
MenuItem menuItem = new MenuItem
{
Header = stackPanel,
Padding = new Thickness(8.0, 6.0, 16.0, 6.0)
};
menuItem.Click += delegate
{
action();
};
menu.Items.Add(menuItem);
}
}
private void BtnFolderClear_Click(object sender, RoutedEventArgs e)
{
FolderPathLabel.Text = "?대뜑瑜??좏깮?섏꽭??;
FolderPathLabel.ToolTip = null;
lock (_convLock)
{
if (_currentConversation != null)
{
_currentConversation.WorkFolder = "";
}
}
}
private void UpdateFolderBar()
{
if (FolderBar == null)
{
return;
}
if (_activeTab == "Chat")
{
FolderBar.Visibility = Visibility.Collapsed;
return;
}
FolderBar.Visibility = Visibility.Visible;
string currentWorkFolder = GetCurrentWorkFolder();
if (!string.IsNullOrEmpty(currentWorkFolder))
{
FolderPathLabel.Text = currentWorkFolder;
FolderPathLabel.ToolTip = currentWorkFolder;
}
else
{
FolderPathLabel.Text = "?대뜑瑜??좏깮?섏꽭??;
FolderPathLabel.ToolTip = null;
}
LoadConversationSettings();
UpdatePermissionUI();
UpdateDataUsageUI();
}
private void LoadConversationSettings()
{
ChatConversation currentConversation;
lock (_convLock)
{
currentConversation = _currentConversation;
}
LlmSettings llm = _settings.Settings.Llm;
if (currentConversation != null && currentConversation.Permission != null)
{
_settings.Settings.Llm.FilePermission = currentConversation.Permission;
}
_folderDataUsage = currentConversation?.DataUsage ?? llm.FolderDataUsage ?? "active";
_selectedMood = currentConversation?.Mood ?? llm.DefaultMood ?? "modern";
}
private void SaveConversationSettings()
{
ChatConversation currentConversation;
lock (_convLock)
{
currentConversation = _currentConversation;
}
if (currentConversation == null)
{
return;
}
currentConversation.Permission = _settings.Settings.Llm.FilePermission;
currentConversation.DataUsage = _folderDataUsage;
currentConversation.Mood = _selectedMood;
try
{
_storage.Save(currentConversation);
}
catch (Exception ex)
{
LogService.Debug("?€???€???ㅽ뙣: " + ex.Message);
}
}
private void BtnPermission_Click(object sender, RoutedEventArgs e)
{
if (PermissionPopup == null)
{
return;
}
PermissionItems.Children.Clear();
(string, string, string, string)[] array = new(string, string, string, string)[3]
{
("Ask", "\ue8d7", "留ㅻ쾲 ?뺤씤 ???뚯씪 ?묎렐 ???ъ슜?먯뿉寃?臾살뒿?덈떎", "#4B5EFC"),
("Auto", "\ue73e", "?먮룞 ?덉슜 ???뚯씪???먮룞?쇰줈 ?쎄퀬 ?곷땲??, "#DD6B20"),
("Deny", "\ue711", "?묎렐 李⑤떒 ???뚯씪 ?묎렐???덉슜?섏? ?딆뒿?덈떎", "#C50F1F")
};
string filePermission = _settings.Settings.Llm.FilePermission;
(string, string, string, string)[] array2 = array;
for (int i = 0; i < array2.Length; i++)
{
(string, string, string, string) tuple = array2[i];
string item = tuple.Item1;
string item2 = tuple.Item2;
string item3 = tuple.Item3;
string item4 = tuple.Item4;
bool isChecked = item.Equals(filePermission, StringComparison.OrdinalIgnoreCase);
ControlTemplate controlTemplate = new ControlTemplate(typeof(System.Windows.Controls.Button));
FrameworkElementFactory frameworkElementFactory = new FrameworkElementFactory(typeof(Border));
frameworkElementFactory.SetValue(Border.BackgroundProperty, System.Windows.Media.Brushes.Transparent);
frameworkElementFactory.SetValue(Border.CornerRadiusProperty, new CornerRadius(8.0));
frameworkElementFactory.SetValue(Border.PaddingProperty, new Thickness(12.0, 8.0, 12.0, 8.0));
frameworkElementFactory.Name = "Bd";
FrameworkElementFactory frameworkElementFactory2 = new FrameworkElementFactory(typeof(ContentPresenter));
frameworkElementFactory2.SetValue(FrameworkElement.HorizontalAlignmentProperty, System.Windows.HorizontalAlignment.Left);
frameworkElementFactory2.SetValue(FrameworkElement.VerticalAlignmentProperty, VerticalAlignment.Center);
frameworkElementFactory.AppendChild(frameworkElementFactory2);
controlTemplate.VisualTree = frameworkElementFactory;
Trigger trigger = new Trigger
{
Property = UIElement.IsMouseOverProperty,
Value = true
};
trigger.Setters.Add(new Setter(Border.BackgroundProperty, new SolidColorBrush(System.Windows.Media.Color.FromArgb(24, byte.MaxValue, byte.MaxValue, byte.MaxValue)), "Bd"));
controlTemplate.Triggers.Add(trigger);
System.Windows.Controls.Button button = new System.Windows.Controls.Button
{
Template = controlTemplate,
BorderThickness = new Thickness(0.0),
Cursor = System.Windows.Input.Cursors.Hand,
HorizontalContentAlignment = System.Windows.HorizontalAlignment.Left,
Margin = new Thickness(0.0, 1.0, 0.0, 1.0)
};
ApplyHoverScaleAnimation(button, 1.02);
StackPanel stackPanel = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal
};
stackPanel.Children.Add(CreateCheckIcon(isChecked));
stackPanel.Children.Add(new TextBlock
{
Text = item2,
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 14.0,
Foreground = BrushFromHex(item4),
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(0.0, 0.0, 10.0, 0.0)
});
StackPanel stackPanel2 = new StackPanel();
stackPanel2.Children.Add(new TextBlock
{
Text = item,
FontSize = 13.0,
FontWeight = FontWeights.Bold,
Foreground = BrushFromHex(item4)
});
stackPanel2.Children.Add(new TextBlock
{
Text = item3,
FontSize = 11.0,
Foreground = ((TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray),
TextWrapping = TextWrapping.Wrap,
MaxWidth = 220.0
});
stackPanel.Children.Add(stackPanel2);
button.Content = stackPanel;
string capturedLevel = item;
button.Click += delegate
{
_settings.Settings.Llm.FilePermission = capturedLevel;
UpdatePermissionUI();
SaveConversationSettings();
PermissionPopup.IsOpen = false;
};
PermissionItems.Children.Add(button);
}
PermissionPopup.IsOpen = true;
}
private void BtnAutoWarningClose_Click(object sender, RoutedEventArgs e)
{
_autoWarningDismissed = true;
if (AutoPermissionWarning != null)
{
AutoPermissionWarning.Visibility = Visibility.Collapsed;
}
}
private void UpdatePermissionUI()
{
if (PermissionLabel == null || PermissionIcon == null)
{
return;
}
string filePermission = _settings.Settings.Llm.FilePermission;
PermissionLabel.Text = filePermission;
TextBlock permissionIcon = PermissionIcon;
if (1 == 0)
{
}
string text = ((filePermission == "Auto") ? "\ue73e" : ((!(filePermission == "Deny")) ? "\ue8d7" : "\ue711"));
if (1 == 0)
{
}
permissionIcon.Text = text;
if (filePermission == "Auto")
{
SolidColorBrush foreground = new SolidColorBrush(System.Windows.Media.Color.FromRgb(221, 107, 32));
PermissionLabel.Foreground = foreground;
PermissionIcon.Foreground = foreground;
ChatConversation currentConversation;
lock (_convLock)
{
currentConversation = _currentConversation;
}
bool flag = currentConversation != null && currentConversation.Messages.Count > 0 && currentConversation.Permission == "Auto";
if (AutoPermissionWarning != null && !_autoWarningDismissed && !flag)
{
AutoPermissionWarning.Visibility = Visibility.Visible;
}
}
else
{
_autoWarningDismissed = false;
System.Windows.Media.Brush foreground2 = (TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
SolidColorBrush foreground3 = ((filePermission == "Deny") ? new SolidColorBrush(System.Windows.Media.Color.FromRgb(197, 15, 31)) : new SolidColorBrush(System.Windows.Media.Color.FromRgb(75, 94, 252)));
PermissionLabel.Foreground = foreground2;
PermissionIcon.Foreground = foreground3;
if (AutoPermissionWarning != null)
{
AutoPermissionWarning.Visibility = Visibility.Collapsed;
}
}
}
private void BtnDataUsage_Click(object sender, MouseButtonEventArgs e)
{
if (DataUsagePopup == null)
{
return;
}
DataUsageItems.Children.Clear();
(string, string, string, string, string)[] array = new(string, string, string, string, string)[3]
{
("active", "\ue9f5", "?곴레 ?쒖슜", "?대뜑 ??臾몄꽌瑜??먮룞 ?먯깋?섏뿬 蹂닿퀬???묒꽦???곴레 ?쒖슜?⑸땲??, "#107C10"),
("passive", "\ue8fd", "?뚭레 ?쒖슜", "?ъ슜?먭? ?붿껌???뚮쭔 ?대뜑 ?곗씠?곕? 李몄“?⑸땲??, "#D97706"),
("none", "\ue8d8", "?쒖슜?섏? ?딆쓬", "?대뜑 ??臾몄꽌瑜??쎄굅??李몄“?섏? ?딆뒿?덈떎", "#9CA3AF")
};
(string, string, string, string, string)[] array2 = array;
for (int i = 0; i < array2.Length; i++)
{
(string, string, string, string, string) tuple = array2[i];
string item = tuple.Item1;
string item2 = tuple.Item2;
string item3 = tuple.Item3;
string item4 = tuple.Item4;
string item5 = tuple.Item5;
bool isChecked = item.Equals(_folderDataUsage, StringComparison.OrdinalIgnoreCase);
ControlTemplate controlTemplate = new ControlTemplate(typeof(System.Windows.Controls.Button));
FrameworkElementFactory frameworkElementFactory = new FrameworkElementFactory(typeof(Border));
frameworkElementFactory.SetValue(Border.BackgroundProperty, System.Windows.Media.Brushes.Transparent);
frameworkElementFactory.SetValue(Border.CornerRadiusProperty, new CornerRadius(8.0));
frameworkElementFactory.SetValue(Border.PaddingProperty, new Thickness(12.0, 8.0, 12.0, 8.0));
frameworkElementFactory.Name = "Bd";
FrameworkElementFactory frameworkElementFactory2 = new FrameworkElementFactory(typeof(ContentPresenter));
frameworkElementFactory2.SetValue(FrameworkElement.HorizontalAlignmentProperty, System.Windows.HorizontalAlignment.Left);
frameworkElementFactory2.SetValue(FrameworkElement.VerticalAlignmentProperty, VerticalAlignment.Center);
frameworkElementFactory.AppendChild(frameworkElementFactory2);
controlTemplate.VisualTree = frameworkElementFactory;
Trigger trigger = new Trigger
{
Property = UIElement.IsMouseOverProperty,
Value = true
};
trigger.Setters.Add(new Setter(Border.BackgroundProperty, new SolidColorBrush(System.Windows.Media.Color.FromArgb(24, byte.MaxValue, byte.MaxValue, byte.MaxValue)), "Bd"));
controlTemplate.Triggers.Add(trigger);
System.Windows.Controls.Button button = new System.Windows.Controls.Button
{
Template = controlTemplate,
BorderThickness = new Thickness(0.0),
Cursor = System.Windows.Input.Cursors.Hand,
HorizontalContentAlignment = System.Windows.HorizontalAlignment.Left,
Margin = new Thickness(0.0, 1.0, 0.0, 1.0)
};
ApplyHoverScaleAnimation(button, 1.02);
StackPanel stackPanel = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal
};
stackPanel.Children.Add(CreateCheckIcon(isChecked));
stackPanel.Children.Add(new TextBlock
{
Text = item2,
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 14.0,
Foreground = BrushFromHex(item5),
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(0.0, 0.0, 10.0, 0.0)
});
StackPanel stackPanel2 = new StackPanel();
stackPanel2.Children.Add(new TextBlock
{
Text = item3,
FontSize = 13.0,
FontWeight = FontWeights.Bold,
Foreground = BrushFromHex(item5)
});
stackPanel2.Children.Add(new TextBlock
{
Text = item4,
FontSize = 11.0,
Foreground = ((TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray),
TextWrapping = TextWrapping.Wrap,
MaxWidth = 240.0
});
stackPanel.Children.Add(stackPanel2);
button.Content = stackPanel;
string capturedKey = item;
button.Click += delegate
{
_folderDataUsage = capturedKey;
UpdateDataUsageUI();
SaveConversationSettings();
DataUsagePopup.IsOpen = false;
};
DataUsageItems.Children.Add(button);
}
DataUsagePopup.IsOpen = true;
}
private void UpdateDataUsageUI()
{
if (DataUsageLabel != null && DataUsageIcon != null)
{
string folderDataUsage = _folderDataUsage;
if (1 == 0)
{
}
(string, string, string) tuple = ((folderDataUsage == "passive") ? ("?뚭레", "\ue8fd", "#D97706") : ((!(folderDataUsage == "none")) ? ("?곴레", "\ue9f5", "#107C10") : ("誘몄궗??, "\ue8d8", "#9CA3AF")));
if (1 == 0)
{
}
var (text, text2, hex) = tuple;
DataUsageLabel.Text = text;
DataUsageIcon.Text = text2;
DataUsageIcon.Foreground = BrushFromHex(hex);
}
}
private void ApplyTabDefaultPermission()
{
if (_activeTab == "Chat")
{
_settings.Settings.Llm.FilePermission = "Ask";
UpdatePermissionUI();
return;
}
string defaultAgentPermission = _settings.Settings.Llm.DefaultAgentPermission;
if (!string.IsNullOrEmpty(defaultAgentPermission))
{
_settings.Settings.Llm.FilePermission = defaultAgentPermission;
UpdatePermissionUI();
}
}
private void BtnAttach_Click(object sender, RoutedEventArgs e)
{
Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog
{
Multiselect = true,
Title = "泥⑤????뚯씪???좏깮?섏꽭??,
Filter = "紐⑤뱺 ?뚯씪 (*.*)|*.*|?띿뒪??(*.txt;*.md;*.csv)|*.txt;*.md;*.csv|肄붾뱶 (*.cs;*.py;*.js;*.ts)|*.cs;*.py;*.js;*.ts"
};
string currentWorkFolder = GetCurrentWorkFolder();
if (!string.IsNullOrEmpty(currentWorkFolder) && Directory.Exists(currentWorkFolder))
{
openFileDialog.InitialDirectory = currentWorkFolder;
}
if (openFileDialog.ShowDialog() == true)
{
string[] fileNames = openFileDialog.FileNames;
foreach (string filePath in fileNames)
{
AddAttachedFile(filePath);
}
}
}
private void AddAttachedFile(string filePath)
{
if (_attachedFiles.Contains(filePath))
{
return;
}
try
{
FileInfo fileInfo = new FileInfo(filePath);
if (fileInfo.Length > 10485760)
{
CustomMessageBox.Show("?뚯씪???덈Т ?쎈땲??(10MB 珥덇낵):\n" + fileInfo.Name, "泥⑤? ?쒗븳", MessageBoxButton.OK, MessageBoxImage.Exclamation);
return;
}
string text = fileInfo.Extension.ToLowerInvariant();
if (ImageExtensions.Contains(text) && _settings.Settings.Llm.EnableImageInput)
{
int num = _settings.Settings.Llm.MaxImageSizeKb;
if (num <= 0)
{
num = 5120;
}
if (fileInfo.Length > num * 1024)
{
CustomMessageBox.Show($"?대?吏€媛€ ?덈Т ?쎈땲??({fileInfo.Length / 1024}KB, 理쒕? {num}KB).", "?대?吏€ ?ш린 珥덇낵", MessageBoxButton.OK, MessageBoxImage.Exclamation);
return;
}
byte[] inArray = File.ReadAllBytes(filePath);
if (1 == 0)
{
}
string text2;
switch (text)
{
case ".jpg":
case ".jpeg":
text2 = "image/jpeg";
break;
case ".gif":
text2 = "image/gif";
break;
case ".bmp":
text2 = "image/bmp";
break;
case ".webp":
text2 = "image/webp";
break;
default:
text2 = "image/png";
break;
}
if (1 == 0)
{
}
string mimeType = text2;
ImageAttachment attachment = new ImageAttachment
{
Base64 = Convert.ToBase64String(inArray),
MimeType = mimeType,
FileName = fileInfo.Name
};
if (!_pendingImages.Any((ImageAttachment i) => i.FileName == attachment.FileName))
{
_pendingImages.Add(attachment);
AddImagePreview(attachment);
}
return;
}
}
catch
{
return;
}
_attachedFiles.Add(filePath);
RefreshAttachedFilesUI();
}
private void RemoveAttachedFile(string filePath)
{
_attachedFiles.Remove(filePath);
RefreshAttachedFilesUI();
}
private void RefreshAttachedFilesUI()
{
AttachedFilesPanel.Items.Clear();
if (_attachedFiles.Count == 0)
{
AttachedFilesPanel.Visibility = Visibility.Collapsed;
return;
}
AttachedFilesPanel.Visibility = Visibility.Visible;
System.Windows.Media.Brush foreground = (TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
System.Windows.Media.Brush background = (TryFindResource("HintBackground") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.LightGray;
foreach (string item in _attachedFiles.ToList())
{
string fileName = System.IO.Path.GetFileName(item);
string capturedFile = item;
Border border = new Border
{
Background = background,
CornerRadius = new CornerRadius(6.0),
Padding = new Thickness(8.0, 4.0, 4.0, 4.0),
Margin = new Thickness(0.0, 0.0, 4.0, 4.0),
Cursor = System.Windows.Input.Cursors.Hand
};
StackPanel stackPanel = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal
};
stackPanel.Children.Add(new TextBlock
{
Text = "\ue8a5",
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 10.0,
Foreground = foreground,
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(0.0, 0.0, 4.0, 0.0)
});
stackPanel.Children.Add(new TextBlock
{
Text = fileName,
FontSize = 11.0,
Foreground = foreground,
VerticalAlignment = VerticalAlignment.Center,
MaxWidth = 150.0,
TextTrimming = TextTrimming.CharacterEllipsis,
ToolTip = item
});
System.Windows.Controls.Button button = new System.Windows.Controls.Button
{
Content = new TextBlock
{
Text = "\ue711",
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 8.0,
Foreground = foreground
},
Background = System.Windows.Media.Brushes.Transparent,
BorderThickness = new Thickness(0.0),
Cursor = System.Windows.Input.Cursors.Hand,
Padding = new Thickness(4.0, 2.0, 4.0, 2.0),
Margin = new Thickness(2.0, 0.0, 0.0, 0.0)
};
button.Click += delegate
{
RemoveAttachedFile(capturedFile);
};
stackPanel.Children.Add(button);
border.Child = stackPanel;
AttachedFilesPanel.Items.Add(border);
}
}
private string BuildFileContextPrompt()
{
if (_attachedFiles.Count == 0)
{
return "";
}
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("\n[泥⑤? ?뚯씪 而⑦뀓?ㅽ듃]");
foreach (string attachedFile in _attachedFiles)
{
try
{
bool flag;
switch (System.IO.Path.GetExtension(attachedFile).ToLowerInvariant())
{
case ".exe":
case ".dll":
case ".zip":
case ".7z":
case ".rar":
case ".tar":
case ".gz":
case ".png":
case ".jpg":
case ".jpeg":
case ".gif":
case ".bmp":
case ".ico":
case ".webp":
case ".svg":
case ".pdf":
case ".docx":
case ".xlsx":
case ".pptx":
case ".doc":
case ".xls":
case ".ppt":
case ".mp3":
case ".mp4":
case ".avi":
case ".mov":
case ".mkv":
case ".wav":
case ".flac":
case ".psd":
case ".ai":
case ".sketch":
case ".fig":
case ".msi":
case ".iso":
case ".img":
case ".bin":
case ".dat":
case ".db":
case ".sqlite":
flag = true;
break;
default:
flag = false;
break;
}
StringBuilder stringBuilder2;
StringBuilder.AppendInterpolatedStringHandler handler;
if (flag)
{
stringBuilder2 = stringBuilder;
StringBuilder stringBuilder3 = stringBuilder2;
handler = new StringBuilder.AppendInterpolatedStringHandler(26, 1, stringBuilder2);
handler.AppendLiteral("\n--- ");
handler.AppendFormatted(System.IO.Path.GetFileName(attachedFile));
handler.AppendLiteral(" (諛붿씠?덈━ ?뚯씪, ?댁슜 ?앸왂) ---");
stringBuilder3.AppendLine(ref handler);
continue;
}
string text = File.ReadAllText(attachedFile);
if (text.Length > 8000)
{
text = text.Substring(0, 8000) + "\n... (?댄븯 ?앸왂)";
}
stringBuilder2 = stringBuilder;
StringBuilder stringBuilder4 = stringBuilder2;
handler = new StringBuilder.AppendInterpolatedStringHandler(9, 1, stringBuilder2);
handler.AppendLiteral("\n--- ");
handler.AppendFormatted(System.IO.Path.GetFileName(attachedFile));
handler.AppendLiteral(" ---");
stringBuilder4.AppendLine(ref handler);
stringBuilder.AppendLine(text);
}
catch (Exception ex)
{
StringBuilder stringBuilder2 = stringBuilder;
StringBuilder stringBuilder5 = stringBuilder2;
StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(19, 2, stringBuilder2);
handler.AppendLiteral("\n--- ");
handler.AppendFormatted(System.IO.Path.GetFileName(attachedFile));
handler.AppendLiteral(" (?쎄린 ?ㅽ뙣: ");
handler.AppendFormatted(ex.Message);
handler.AppendLiteral(") ---");
stringBuilder5.AppendLine(ref handler);
}
}
return stringBuilder.ToString();
}
private void ResizeGrip_DragDelta(object sender, DragDeltaEventArgs e)
{
double num = base.Width + e.HorizontalChange;
double num2 = base.Height + e.VerticalChange;
if (num >= base.MinWidth)
{
base.Width = num;
}
if (num2 >= base.MinHeight)
{
base.Height = num2;
}
}
private void BtnToggleSidebar_Click(object sender, RoutedEventArgs e)
{
_sidebarVisible = !_sidebarVisible;
if (_sidebarVisible)
{
IconBarColumn.Width = new GridLength(0.0);
IconBarPanel.Visibility = Visibility.Collapsed;
SidebarPanel.Visibility = Visibility.Visible;
ToggleSidebarIcon.Text = "\ue76b";
AnimateSidebar(0.0, 270.0, delegate
{
SidebarColumn.MinWidth = 200.0;
});
}
else
{
SidebarColumn.MinWidth = 0.0;
ToggleSidebarIcon.Text = "\ue76c";
AnimateSidebar(270.0, 0.0, delegate
{
SidebarPanel.Visibility = Visibility.Collapsed;
IconBarColumn.Width = new GridLength(52.0);
IconBarPanel.Visibility = Visibility.Visible;
});
}
}
private void AnimateSidebar(double from, double to, Action? onComplete = null)
{
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Expected O, but got Unknown
double duration = 200.0;
DateTime start = DateTime.UtcNow;
DispatcherTimer timer = new DispatcherTimer
{
Interval = TimeSpan.FromMilliseconds(10.0)
};
EventHandler tickHandler = null;
tickHandler = delegate
{
double totalMilliseconds = (DateTime.UtcNow - start).TotalMilliseconds;
double num = Math.Min(totalMilliseconds / duration, 1.0);
num = 1.0 - (1.0 - num) * (1.0 - num);
SidebarColumn.Width = new GridLength(from + (to - from) * num);
if (totalMilliseconds >= duration)
{
timer.Stop();
timer.Tick -= tickHandler;
SidebarColumn.Width = new GridLength(to);
onComplete?.Invoke();
}
};
timer.Tick += tickHandler;
timer.Start();
}
public void RefreshConversationList()
{
List<ChatConversation> source = _storage.LoadAllMeta();
IEnumerable<TopicPreset> enumerable = PresetService.GetByTabWithCustom("Cowork", _settings.Settings.Llm.CustomPresets).Concat(PresetService.GetByTabWithCustom("Code", _settings.Settings.Llm.CustomPresets)).Concat(PresetService.GetByTabWithCustom("Chat", _settings.Settings.Llm.CustomPresets));
Dictionary<string, (string Symbol, string Color)> presetMap = new Dictionary<string, (string, string)>(StringComparer.OrdinalIgnoreCase);
foreach (TopicPreset item in enumerable)
{
presetMap.TryAdd(item.Category, (item.Symbol, item.Color));
}
List<ConversationMeta> source2 = source.Select(delegate(ChatConversation c)
{
string text = ChatCategory.GetSymbol(c.Category);
string text2 = ChatCategory.GetColor(c.Category);
if (text == "\ue8bd" && text2 == "#6B7280" && c.Category != "?쇰컲" && presetMap.TryGetValue(c.Category, out (string, string) value))
{
(text, text2) = value;
}
return new ConversationMeta
{
Id = c.Id,
Title = c.Title,
Pinned = c.Pinned,
Category = c.Category,
Symbol = text,
ColorHex = text2,
Tab = (string.IsNullOrEmpty(c.Tab) ? "Chat" : c.Tab),
UpdatedAtText = FormatDate(c.UpdatedAt),
UpdatedAt = c.UpdatedAt,
Preview = (c.Preview ?? ""),
ParentId = c.ParentId,
ExecutionEventCount = (c.ExecutionEvents?.Count ?? 0),
ErrorEventCount = (c.ExecutionEvents?.Count((ChatExecutionEvent x) => string.Equals(x.Type, "Error", StringComparison.OrdinalIgnoreCase)) ?? 0)
};
}).ToList();
source2 = source2.Where((ConversationMeta i) => i.Tab == _activeTab).ToList();
if (_selectedCategory == "__custom__")
{
HashSet<string> customCats = _settings.Settings.Llm.CustomPresets.Select((CustomPresetEntry c) => "custom_" + c.Id).ToHashSet();
source2 = source2.Where((ConversationMeta i) => customCats.Contains(i.Category)).ToList();
}
else if (!string.IsNullOrEmpty(_selectedCategory))
{
source2 = source2.Where((ConversationMeta i) => i.Category == _selectedCategory).ToList();
}
string search = SearchBox?.Text?.Trim() ?? "";
if (!string.IsNullOrEmpty(search))
{
source2 = source2.Where((ConversationMeta i) => i.Title.Contains(search, StringComparison.OrdinalIgnoreCase) || i.Preview.Contains(search, StringComparison.OrdinalIgnoreCase)).ToList();
}
RenderConversationList(source2);
}
private void RenderConversationList(List<ConversationMeta> items)
{
ConversationPanel.Children.Clear();
_pendingConversations = null;
if (items.Count == 0)
{
TextBlock textBlock = new TextBlock();
textBlock.Text = "?€?붽? ?놁뒿?덈떎";
textBlock.FontSize = 12.0;
textBlock.Foreground = (TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
textBlock.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
textBlock.Margin = new Thickness(0.0, 20.0, 0.0, 0.0);
TextBlock element = textBlock;
ConversationPanel.Children.Add(element);
return;
}
DateTime today = DateTime.Today;
List<ConversationMeta> list = items.Where((ConversationMeta i) => i.UpdatedAt.Date == today).ToList();
List<ConversationMeta> list2 = items.Where((ConversationMeta i) => i.UpdatedAt.Date < today).ToList();
List<(string, ConversationMeta)> list3 = new List<(string, ConversationMeta)>();
foreach (ConversationMeta item2 in list)
{
list3.Add(("?ㅻ뒛", item2));
}
foreach (ConversationMeta item3 in list2)
{
list3.Add(("?댁쟾", item3));
}
List<(string, ConversationMeta)> list4 = list3.Take(50).ToList();
string text = null;
foreach (var (text2, item) in list4)
{
if (text2 != text)
{
AddGroupHeader(text2);
text = text2;
}
AddConversationItem(item);
}
if (list3.Count > 50)
{
_pendingConversations = items;
AddLoadMoreButton(list3.Count - 50);
}
}
private void AddLoadMoreButton(int remaining)
{
System.Windows.Media.Brush brush = (TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
System.Windows.Media.Brush foreground = (TryFindResource("AccentColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.CornflowerBlue;
Border border = new Border
{
Background = System.Windows.Media.Brushes.Transparent,
CornerRadius = new CornerRadius(8.0),
Cursor = System.Windows.Input.Cursors.Hand,
Padding = new Thickness(8.0, 10.0, 8.0, 10.0),
Margin = new Thickness(6.0, 4.0, 6.0, 4.0),
HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch
};
StackPanel stackPanel = new StackPanel
{
HorizontalAlignment = System.Windows.HorizontalAlignment.Center
};
stackPanel.Children.Add(new TextBlock
{
Text = $"??蹂닿린 ({remaining}媛??⑥쓬)",
FontSize = 12.0,
Foreground = foreground,
HorizontalAlignment = System.Windows.HorizontalAlignment.Center
});
border.Child = stackPanel;
border.MouseEnter += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border border2)
{
border2.Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(18, byte.MaxValue, byte.MaxValue, byte.MaxValue));
}
};
border.MouseLeave += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border border2)
{
border2.Background = System.Windows.Media.Brushes.Transparent;
}
};
border.MouseLeftButtonUp += delegate
{
if (_pendingConversations != null)
{
List<ConversationMeta> pendingConversations = _pendingConversations;
_pendingConversations = null;
ConversationPanel.Children.Clear();
DateTime today = DateTime.Today;
List<ConversationMeta> list = pendingConversations.Where((ConversationMeta i) => i.UpdatedAt.Date == today).ToList();
List<ConversationMeta> list2 = pendingConversations.Where((ConversationMeta i) => i.UpdatedAt.Date < today).ToList();
if (list.Count > 0)
{
AddGroupHeader("?ㅻ뒛");
foreach (ConversationMeta item in list)
{
AddConversationItem(item);
}
}
if (list2.Count > 0)
{
AddGroupHeader("?댁쟾");
foreach (ConversationMeta item2 in list2)
{
AddConversationItem(item2);
}
}
}
};
ConversationPanel.Children.Add(border);
}
private void AddGroupHeader(string text)
{
TextBlock textBlock = new TextBlock();
textBlock.Text = text;
textBlock.FontSize = 11.0;
textBlock.FontWeight = FontWeights.SemiBold;
textBlock.Foreground = (TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
textBlock.Margin = new Thickness(8.0, 12.0, 0.0, 4.0);
TextBlock element = textBlock;
ConversationPanel.Children.Add(element);
}
private void AddConversationItem(ConversationMeta item)
{
//IL_0846: Unknown result type (might be due to invalid IL or missing references)
bool isSelected = false;
lock (_convLock)
{
isSelected = _currentConversation?.Id == item.Id;
}
bool flag = !string.IsNullOrEmpty(item.ParentId);
Border border = new Border
{
Background = (isSelected ? new SolidColorBrush(System.Windows.Media.Color.FromArgb(48, 75, 94, 252)) : System.Windows.Media.Brushes.Transparent),
CornerRadius = new CornerRadius(8.0),
Padding = new Thickness(10.0, 8.0, 10.0, 8.0),
Margin = (flag ? new Thickness(16.0, 1.0, 0.0, 1.0) : new Thickness(0.0, 1.0, 0.0, 1.0)),
Cursor = System.Windows.Input.Cursors.Hand
};
Grid grid = new Grid();
grid.ColumnDefinitions.Add(new ColumnDefinition
{
Width = new GridLength(28.0)
});
grid.ColumnDefinitions.Add(new ColumnDefinition
{
Width = new GridLength(1.0, GridUnitType.Star)
});
grid.ColumnDefinitions.Add(new ColumnDefinition
{
Width = GridLength.Auto
});
System.Windows.Media.Brush foreground;
if (item.Pinned)
{
foreground = System.Windows.Media.Brushes.Orange;
}
else
{
try
{
foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(item.ColorHex));
}
catch
{
foreground = (TryFindResource("AccentColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Blue;
}
}
string text = (item.Pinned ? "\ue718" : ((!string.IsNullOrEmpty(item.ParentId)) ? "\ue8a5" : item.Symbol));
if (!string.IsNullOrEmpty(item.ParentId))
{
foreground = new SolidColorBrush(System.Windows.Media.Color.FromRgb(139, 92, 246));
}
TextBlock element = new TextBlock
{
Text = text,
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 13.0,
Foreground = foreground,
VerticalAlignment = VerticalAlignment.Center
};
Grid.SetColumn(element, 0);
grid.Children.Add(element);
System.Windows.Media.Brush titleColor = (TryFindResource("PrimaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.White;
System.Windows.Media.Brush foreground2 = (TryFindResource("HintText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.DarkGray;
StackPanel stackPanel = new StackPanel
{
VerticalAlignment = VerticalAlignment.Center
};
TextBlock title = new TextBlock
{
Text = item.Title,
FontSize = 12.5,
Foreground = titleColor,
TextTrimming = TextTrimming.CharacterEllipsis
};
TextBlock element2 = new TextBlock
{
Text = item.UpdatedAtText,
FontSize = 10.0,
Foreground = foreground2,
Margin = new Thickness(0.0, 2.0, 0.0, 0.0)
};
StackPanel stackPanel2 = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal,
Margin = new Thickness(0.0, 4.0, 0.0, 0.0),
Visibility = ((item.ExecutionEventCount <= 0) ? Visibility.Collapsed : Visibility.Visible)
};
stackPanel2.Children.Add(new Border
{
Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(24, 37, 99, 235)),
CornerRadius = new CornerRadius(4.0),
Padding = new Thickness(5.0, 1.0, 5.0, 1.0),
Margin = new Thickness(0.0, 0.0, 6.0, 0.0),
Child = new TextBlock
{
Text = $"?ㅽ뻾 {item.ExecutionEventCount}",
FontSize = 9.5,
Foreground = new SolidColorBrush(System.Windows.Media.Color.FromRgb(37, 99, 235))
}
});
if (item.ErrorEventCount > 0)
{
stackPanel2.Children.Add(new Border
{
Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(24, 220, 38, 38)),
CornerRadius = new CornerRadius(4.0),
Padding = new Thickness(5.0, 1.0, 5.0, 1.0),
Child = new TextBlock
{
Text = $"?ㅻ쪟 {item.ErrorEventCount}",
FontSize = 9.5,
Foreground = new SolidColorBrush(System.Windows.Media.Color.FromRgb(220, 38, 38))
}
});
}
stackPanel.Children.Add(title);
stackPanel.Children.Add(element2);
stackPanel.Children.Add(stackPanel2);
Grid.SetColumn(stackPanel, 1);
grid.Children.Add(stackPanel);
System.Windows.Controls.Button catBtn = new System.Windows.Controls.Button
{
Content = new TextBlock
{
Text = "\ue70f",
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 10.0,
Foreground = ((TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray)
},
Background = System.Windows.Media.Brushes.Transparent,
BorderThickness = new Thickness(0.0),
Cursor = System.Windows.Input.Cursors.Hand,
VerticalAlignment = VerticalAlignment.Center,
Visibility = Visibility.Collapsed,
Padding = new Thickness(4.0),
ToolTip = ((_activeTab == "Cowork") ? "?묒뾽 ?좏삎" : "?€??二쇱젣 蹂€寃?)
};
string capturedId = item.Id;
catBtn.Click += delegate
{
ShowConversationMenu(capturedId);
};
Grid.SetColumn(catBtn, 2);
grid.Children.Add(catBtn);
if (isSelected)
{
border.BorderBrush = (TryFindResource("AccentColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.CornflowerBlue;
border.BorderThickness = new Thickness(2.0, 0.0, 0.0, 0.0);
}
border.Child = grid;
border.RenderTransformOrigin = new Point(0.5, 0.5);
border.RenderTransform = new ScaleTransform(1.0, 1.0);
SolidColorBrush solidColorBrush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(48, 75, 94, 252));
border.MouseEnter += delegate
{
if (!isSelected)
{
border.Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(21, byte.MaxValue, byte.MaxValue, byte.MaxValue));
}
catBtn.Visibility = Visibility.Visible;
ScaleTransform scaleTransform = border.RenderTransform as ScaleTransform;
scaleTransform?.BeginAnimation(ScaleTransform.ScaleXProperty, new DoubleAnimation(1.02, TimeSpan.FromMilliseconds(120.0)));
scaleTransform?.BeginAnimation(ScaleTransform.ScaleYProperty, new DoubleAnimation(1.02, TimeSpan.FromMilliseconds(120.0)));
};
border.MouseLeave += delegate
{
if (!isSelected)
{
border.Background = System.Windows.Media.Brushes.Transparent;
}
catBtn.Visibility = Visibility.Collapsed;
ScaleTransform scaleTransform = border.RenderTransform as ScaleTransform;
scaleTransform?.BeginAnimation(ScaleTransform.ScaleXProperty, new DoubleAnimation(1.0, TimeSpan.FromMilliseconds(150.0)));
scaleTransform?.BeginAnimation(ScaleTransform.ScaleYProperty, new DoubleAnimation(1.0, TimeSpan.FromMilliseconds(150.0)));
};
border.MouseLeftButtonDown += delegate
{
try
{
if (isSelected)
{
EnterTitleEditMode(title, item.Id, titleColor);
}
else
{
if (_isStreaming)
{
_streamCts?.Cancel();
_cursorTimer.Stop();
_typingTimer.Stop();
_elapsedTimer.Stop();
_activeStreamText = null;
_elapsedLabel = null;
_isStreaming = false;
}
ChatConversation chatConversation = _storage.Load(item.Id);
if (chatConversation != null)
{
if (string.IsNullOrEmpty(chatConversation.Tab))
{
chatConversation.Tab = _activeTab;
}
lock (_convLock)
{
_currentConversation = chatConversation;
}
_tabConversationId[_activeTab] = chatConversation.Id;
UpdateChatTitle();
RenderMessages();
RefreshConversationList();
}
}
}
catch (Exception ex)
{
LogService.Error("?€???꾪솚 ?ㅻ쪟: " + ex.Message);
}
};
border.MouseRightButtonUp += delegate(object _, MouseButtonEventArgs me)
{
me.Handled = true;
if (!isSelected)
{
ChatConversation chatConversation = _storage.Load(item.Id);
if (chatConversation != null)
{
if (string.IsNullOrEmpty(chatConversation.Tab))
{
chatConversation.Tab = _activeTab;
}
lock (_convLock)
{
_currentConversation = chatConversation;
}
_tabConversationId[_activeTab] = chatConversation.Id;
UpdateChatTitle();
RenderMessages();
}
}
((DispatcherObject)this).Dispatcher.BeginInvoke((Delegate)(Action)delegate
{
ShowConversationMenu(item.Id);
}, (DispatcherPriority)5, Array.Empty<object>());
};
ConversationPanel.Children.Add(border);
}
private void EnterTitleEditMode(TextBlock titleTb, string conversationId, System.Windows.Media.Brush titleColor)
{
try
{
StackPanel parent = titleTb.Parent as StackPanel;
if (parent == null)
{
return;
}
int num = parent.Children.IndexOf(titleTb);
if (num < 0)
{
return;
}
System.Windows.Controls.TextBox editBox = new System.Windows.Controls.TextBox
{
Text = titleTb.Text,
FontSize = 12.5,
Foreground = titleColor,
Background = System.Windows.Media.Brushes.Transparent,
BorderBrush = ((TryFindResource("AccentColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Blue),
BorderThickness = new Thickness(0.0, 0.0, 0.0, 1.0),
CaretBrush = titleColor,
Padding = new Thickness(0.0),
Margin = new Thickness(0.0)
};
parent.Children.RemoveAt(num);
parent.Children.Insert(num, editBox);
bool committed = false;
editBox.KeyDown += delegate(object _, System.Windows.Input.KeyEventArgs ke)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Invalid comparison between Unknown and I4
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Invalid comparison between Unknown and I4
if ((int)ke.Key == 6)
{
ke.Handled = true;
CommitEdit();
}
if ((int)ke.Key == 13)
{
ke.Handled = true;
CancelEdit();
}
};
editBox.LostFocus += delegate
{
CommitEdit();
};
editBox.Focus();
editBox.SelectAll();
void CancelEdit()
{
if (committed)
{
return;
}
committed = true;
try
{
int num2 = parent.Children.IndexOf(editBox);
if (num2 >= 0)
{
parent.Children.RemoveAt(num2);
parent.Children.Insert(num2, titleTb);
}
}
catch
{
}
}
void CommitEdit()
{
if (!committed)
{
committed = true;
string text = editBox.Text.Trim();
if (string.IsNullOrEmpty(text))
{
text = titleTb.Text;
}
titleTb.Text = text;
try
{
int num2 = parent.Children.IndexOf(editBox);
if (num2 >= 0)
{
parent.Children.RemoveAt(num2);
parent.Children.Insert(num2, titleTb);
}
}
catch
{
}
ChatConversation chatConversation = _storage.Load(conversationId);
if (chatConversation != null)
{
chatConversation.Title = text;
_storage.Save(chatConversation);
lock (_convLock)
{
if (_currentConversation?.Id == conversationId)
{
_currentConversation.Title = text;
}
}
UpdateChatTitle();
}
}
}
}
catch (Exception ex)
{
LogService.Error("?쒕ぉ ?몄쭛 ?ㅻ쪟: " + ex.Message);
}
}
private void ShowConversationMenu(string conversationId)
{
ChatConversation conv = _storage.Load(conversationId);
bool flag = conv?.Pinned ?? false;
System.Windows.Media.Brush background = (TryFindResource("LauncherBackground") as System.Windows.Media.Brush) ?? new SolidColorBrush(System.Windows.Media.Color.FromRgb(26, 27, 46));
System.Windows.Media.Brush borderBrush = (TryFindResource("BorderColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
System.Windows.Media.Brush primaryText = (TryFindResource("PrimaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.White;
System.Windows.Media.Brush brush = (TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
System.Windows.Media.Brush hoverBg = (TryFindResource("ItemHoverBackground") as System.Windows.Media.Brush) ?? new SolidColorBrush(System.Windows.Media.Color.FromArgb(30, byte.MaxValue, byte.MaxValue, byte.MaxValue));
Popup popup = new Popup
{
StaysOpen = false,
AllowsTransparency = true,
PopupAnimation = PopupAnimation.Fade,
Placement = PlacementMode.MousePoint
};
Border border = new Border
{
Background = background,
BorderBrush = borderBrush,
BorderThickness = new Thickness(1.0),
CornerRadius = new CornerRadius(12.0),
Padding = new Thickness(6.0),
MinWidth = 200.0,
Effect = new DropShadowEffect
{
BlurRadius = 16.0,
ShadowDepth = 4.0,
Opacity = 0.3,
Color = Colors.Black
}
};
StackPanel stackPanel = new StackPanel();
stackPanel.Children.Add(CreateMenuItem(flag ? "\ue77a" : "\ue718", flag ? "怨좎젙 ?댁젣" : "?곷떒 怨좎젙", (TryFindResource("AccentColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Blue, delegate
{
ChatConversation chatConversation = _storage.Load(conversationId);
if (chatConversation != null)
{
chatConversation.Pinned = !chatConversation.Pinned;
_storage.Save(chatConversation);
lock (_convLock)
{
if (_currentConversation?.Id == conversationId)
{
_currentConversation.Pinned = chatConversation.Pinned;
}
}
RefreshConversationList();
}
}));
stackPanel.Children.Add(CreateMenuItem("\ue8ac", "?대쫫 蹂€寃?, brush, delegate
{
foreach (UIElement child2 in ConversationPanel.Children)
{
if (child2 is Border { Child: Grid child })
{
foreach (UIElement child3 in child.Children)
{
if (child3 is StackPanel stackPanel3 && stackPanel3.Children.Count > 0 && stackPanel3.Children[0] is TextBlock textBlock && conv != null && textBlock.Text == conv.Title)
{
System.Windows.Media.Brush titleColor = (TryFindResource("PrimaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.White;
EnterTitleEditMode(textBlock, conversationId, titleColor);
return;
}
}
}
}
}));
if ((_activeTab == "Cowork" || _activeTab == "Code") && conv != null)
{
string catKey = conv.Category ?? "?쇰컲";
string text = "\ue8bd";
string text2 = catKey;
string value = "#6B7280";
(string, string, string, string) tuple = ChatCategory.All.FirstOrDefault(((string Key, string Label, string Symbol, string Color) c) => c.Key == catKey);
(string, string, string, string) tuple2 = tuple;
if ((tuple2.Item1 != null || tuple2.Item2 != null || tuple2.Item3 != null || tuple2.Item4 != null) && tuple.Item1 != "?쇰컲")
{
text = tuple.Item3;
text2 = tuple.Item2;
value = tuple.Item4;
}
else
{
TopicPreset topicPreset = PresetService.GetByTabWithCustom(_activeTab, _settings.Settings.Llm.CustomPresets).FirstOrDefault((TopicPreset p) => p.Category == catKey);
if (topicPreset != null)
{
text = topicPreset.Symbol;
text2 = topicPreset.Label;
value = topicPreset.Color;
}
}
stackPanel.Children.Add(CreateSeparator());
StackPanel stackPanel2 = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal,
Margin = new Thickness(10.0, 4.0, 10.0, 4.0)
};
try
{
SolidColorBrush foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(value));
stackPanel2.Children.Add(new TextBlock
{
Text = text,
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 12.0,
Foreground = foreground,
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(0.0, 0.0, 6.0, 0.0)
});
stackPanel2.Children.Add(new TextBlock
{
Text = text2,
FontSize = 12.0,
Foreground = primaryText,
VerticalAlignment = VerticalAlignment.Center
});
}
catch
{
stackPanel2.Children.Add(new TextBlock
{
Text = text2,
FontSize = 12.0,
Foreground = primaryText
});
}
stackPanel.Children.Add(stackPanel2);
}
if (_activeTab == "Chat")
{
stackPanel.Children.Add(CreateSeparator());
stackPanel.Children.Add(new TextBlock
{
Text = "遺꾨쪟 蹂€寃?,
FontSize = 10.5,
Foreground = brush,
Margin = new Thickness(10.0, 4.0, 0.0, 4.0),
FontWeight = FontWeights.SemiBold
});
string text3 = conv?.Category ?? "?쇰컲";
System.Windows.Media.Brush color = (TryFindResource("AccentColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.CornflowerBlue;
(string, string, string, string)[] all = ChatCategory.All;
for (int num = 0; num < all.Length; num++)
{
(string, string, string, string) tuple3 = all[num];
string item = tuple3.Item1;
string item2 = tuple3.Item2;
string item3 = tuple3.Item3;
string item4 = tuple3.Item4;
string capturedKey = item;
bool flag2 = capturedKey == text3;
Border border2 = new Border
{
Background = System.Windows.Media.Brushes.Transparent,
CornerRadius = new CornerRadius(8.0),
Padding = new Thickness(10.0, 7.0, 10.0, 7.0),
Margin = new Thickness(0.0, 1.0, 0.0, 1.0),
Cursor = System.Windows.Input.Cursors.Hand
};
Grid grid = new Grid();
grid.ColumnDefinitions.Add(new ColumnDefinition
{
Width = new GridLength(24.0)
});
grid.ColumnDefinitions.Add(new ColumnDefinition
{
Width = new GridLength(1.0, GridUnitType.Star)
});
grid.ColumnDefinitions.Add(new ColumnDefinition
{
Width = new GridLength(20.0)
});
TextBlock element = new TextBlock
{
Text = item3,
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 12.0,
Foreground = BrushFromHex(item4),
VerticalAlignment = VerticalAlignment.Center
};
Grid.SetColumn(element, 0);
grid.Children.Add(element);
TextBlock element2 = new TextBlock
{
Text = item2,
FontSize = 12.5,
Foreground = primaryText,
VerticalAlignment = VerticalAlignment.Center,
FontWeight = (flag2 ? FontWeights.Bold : FontWeights.Normal)
};
Grid.SetColumn(element2, 1);
grid.Children.Add(element2);
if (flag2)
{
FrameworkElement element3 = CreateSimpleCheck(color);
Grid.SetColumn(element3, 2);
grid.Children.Add(element3);
}
border2.Child = grid;
border2.MouseEnter += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border border3)
{
border3.Background = hoverBg;
}
};
border2.MouseLeave += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border border3)
{
border3.Background = System.Windows.Media.Brushes.Transparent;
}
};
border2.MouseLeftButtonUp += delegate
{
popup.IsOpen = false;
ChatConversation chatConversation = _storage.Load(conversationId);
if (chatConversation != null)
{
chatConversation.Category = capturedKey;
TopicPreset byCategory = PresetService.GetByCategory(capturedKey);
if (byCategory != null)
{
chatConversation.SystemCommand = byCategory.SystemPrompt;
}
_storage.Save(chatConversation);
lock (_convLock)
{
if (_currentConversation?.Id == conversationId)
{
_currentConversation.Category = capturedKey;
if (byCategory != null)
{
_currentConversation.SystemCommand = byCategory.SystemPrompt;
}
}
}
bool flag3;
lock (_convLock)
{
flag3 = _currentConversation?.Id == conversationId;
}
if (flag3 && byCategory != null && !string.IsNullOrEmpty(byCategory.Placeholder))
{
_promptCardPlaceholder = byCategory.Placeholder;
UpdateWatermarkVisibility();
if (string.IsNullOrEmpty(InputBox.Text))
{
InputWatermark.Text = byCategory.Placeholder;
InputWatermark.Visibility = Visibility.Visible;
}
}
else if (flag3)
{
ClearPromptCardPlaceholder();
}
RefreshConversationList();
}
};
stackPanel.Children.Add(border2);
}
}
stackPanel.Children.Add(CreateSeparator());
stackPanel.Children.Add(CreateMenuItem("\ue74d", "???€????젣", System.Windows.Media.Brushes.IndianRed, delegate
{
MessageBoxResult messageBoxResult = CustomMessageBox.Show("???€?붾? ??젣?섏떆寃좎뒿?덇퉴?", "?€????젣", MessageBoxButton.YesNo, MessageBoxImage.Question);
if (messageBoxResult == MessageBoxResult.Yes)
{
_storage.Delete(conversationId);
lock (_convLock)
{
if (_currentConversation?.Id == conversationId)
{
_currentConversation = null;
MessagePanel.Children.Clear();
EmptyState.Visibility = Visibility.Visible;
UpdateChatTitle();
}
}
RefreshConversationList();
}
}));
border.Child = stackPanel;
popup.Child = border;
popup.IsOpen = true;
Border CreateMenuItem(string icon, string text4, System.Windows.Media.Brush iconColor, Action onClick)
{
Border border3 = new Border
{
Background = System.Windows.Media.Brushes.Transparent,
CornerRadius = new CornerRadius(8.0),
Padding = new Thickness(10.0, 7.0, 10.0, 7.0),
Margin = new Thickness(0.0, 1.0, 0.0, 1.0),
Cursor = System.Windows.Input.Cursors.Hand
};
Grid grid2 = new Grid
{
ColumnDefinitions =
{
new ColumnDefinition
{
Width = new GridLength(24.0)
},
new ColumnDefinition
{
Width = new GridLength(1.0, GridUnitType.Star)
}
}
};
TextBlock element4 = new TextBlock
{
Text = icon,
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 12.0,
Foreground = iconColor,
VerticalAlignment = VerticalAlignment.Center
};
Grid.SetColumn(element4, 0);
grid2.Children.Add(element4);
TextBlock element5 = new TextBlock
{
Text = text4,
FontSize = 12.5,
Foreground = primaryText,
VerticalAlignment = VerticalAlignment.Center
};
Grid.SetColumn(element5, 1);
grid2.Children.Add(element5);
border3.Child = grid2;
border3.MouseEnter += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border border4)
{
border4.Background = hoverBg;
}
};
border3.MouseLeave += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border border4)
{
border4.Background = System.Windows.Media.Brushes.Transparent;
}
};
border3.MouseLeftButtonUp += delegate
{
popup.IsOpen = false;
onClick();
};
return border3;
}
Border CreateSeparator()
{
return new Border
{
Height = 1.0,
Background = borderBrush,
Opacity = 0.3,
Margin = new Thickness(8.0, 4.0, 8.0, 4.0)
};
}
}
private void SearchBox_TextChanged(object sender, TextChangedEventArgs e)
{
RefreshConversationList();
}
private static string FormatDate(DateTime dt)
{
TimeSpan timeSpan = DateTime.Now - dt;
if (timeSpan.TotalMinutes < 1.0)
{
return "諛⑷툑 ??;
}
if (timeSpan.TotalHours < 1.0)
{
return $"{(int)timeSpan.TotalMinutes}遺???;
}
if (timeSpan.TotalDays < 1.0)
{
return $"{(int)timeSpan.TotalHours}?쒓컙 ??;
}
if (timeSpan.TotalDays < 7.0)
{
return $"{(int)timeSpan.TotalDays}????;
}
return dt.ToString("MM/dd");
}
private void UpdateChatTitle()
{
lock (_convLock)
{
ChatTitle.Text = _currentConversation?.Title ?? "";
}
}
private void RenderMessages()
{
MessagePanel.Children.Clear();
UpdateExecutionHistoryUi();
ChatConversation currentConversation;
lock (_convLock)
{
currentConversation = _currentConversation;
}
if (currentConversation == null || (currentConversation.Messages.Count == 0 && currentConversation.ExecutionEvents.Count == 0))
{
EmptyState.Visibility = Visibility.Visible;
return;
}
EmptyState.Visibility = Visibility.Collapsed;
List<(DateTime, int, ChatMessage, ChatExecutionEvent)> list = new List<(DateTime, int, ChatMessage, ChatExecutionEvent)>();
int num = 0;
foreach (ChatMessage message in currentConversation.Messages)
{
if (!(message.Role == "system"))
{
list.Add((message.Timestamp, num++, message, null));
}
}
if (_showExecutionHistory)
{
foreach (ChatExecutionEvent executionEvent in currentConversation.ExecutionEvents)
{
list.Add((executionEvent.Timestamp, num++, null, executionEvent));
}
}
foreach (var item in from x in list
orderby x.Timestamp, x.Sequence
select x)
{
if (item.Item3 != null)
{
AddMessageBubble(item.Item3.Role, item.Item3.Content, animate: false, item.Item3);
}
else if (item.Item4 != null)
{
AddAgentEventBanner(ToAgentEvent(item.Item4), animate: false);
}
}
((DispatcherObject)this).Dispatcher.InvokeAsync((Action)delegate
{
MessageScroll.ScrollToEnd();
}, (DispatcherPriority)4);
}
private static AgentEvent ToAgentEvent(ChatExecutionEvent stored)
{
Enum.TryParse<AgentEventType>(stored.Type, ignoreCase: true, out var result);
return new AgentEvent
{
Timestamp = stored.Timestamp,
Type = result,
ToolName = stored.ToolName,
Summary = stored.Summary,
FilePath = stored.FilePath,
Success = stored.Success,
StepCurrent = stored.StepCurrent,
StepTotal = stored.StepTotal,
Steps = stored.Steps,
ElapsedMs = stored.ElapsedMs,
InputTokens = stored.InputTokens,
OutputTokens = stored.OutputTokens,
ToolInput = stored.ToolInput,
Iteration = stored.Iteration
};
}
private static ChatExecutionEvent ToStoredAgentEvent(AgentEvent evt)
{
return new ChatExecutionEvent
{
Timestamp = evt.Timestamp,
Type = evt.Type.ToString(),
ToolName = evt.ToolName,
Summary = evt.Summary,
FilePath = evt.FilePath,
Success = evt.Success,
StepCurrent = evt.StepCurrent,
StepTotal = evt.StepTotal,
Steps = evt.Steps?.ToList(),
ElapsedMs = evt.ElapsedMs,
InputTokens = evt.InputTokens,
OutputTokens = evt.OutputTokens,
ToolInput = evt.ToolInput,
Iteration = evt.Iteration
};
}
private bool ShouldPersistAgentEvent(AgentEvent evt)
{
string agentLogLevel = _settings.Settings.Llm.AgentLogLevel;
if (agentLogLevel == "simple" && evt.Type == AgentEventType.ToolCall)
{
return false;
}
AgentEventType type = evt.Type;
if (1 == 0)
{
}
bool result;
switch (type)
{
case AgentEventType.Planning:
{
List<string> steps = evt.Steps;
result = steps != null && steps.Count > 0;
break;
}
case AgentEventType.StepStart:
result = evt.StepTotal > 0;
break;
default:
result = true;
break;
}
if (1 == 0)
{
}
return result;
}
private void PersistAgentEvent(AgentEvent evt)
{
if (!ShouldPersistAgentEvent(evt))
{
return;
}
ChatConversation currentConversation;
lock (_convLock)
{
currentConversation = _currentConversation;
currentConversation?.ExecutionEvents.Add(ToStoredAgentEvent(evt));
}
if (currentConversation != null)
{
try
{
_storage.Save(currentConversation);
}
catch (Exception ex)
{
LogService.Debug("?ㅽ뻾 ?대젰 ?€???ㅽ뙣: " + ex.Message);
}
UpdateExecutionHistoryUi();
}
}
private int GetExecutionEventCount()
{
lock (_convLock)
{
return _currentConversation?.ExecutionEvents.Count ?? 0;
}
}
private void UpdateExecutionHistoryUi()
{
if (ExecutionLogLabel != null && ExecutionLogIcon != null && BtnToggleExecutionLog != null)
{
int executionEventCount = GetExecutionEventCount();
ExecutionLogLabel.Text = (_showExecutionHistory ? $"?ㅽ뻾 濡쒓렇 {executionEventCount}" : $"?ㅽ뻾 濡쒓렇 ?④? ({executionEventCount})");
ExecutionLogIcon.Text = (_showExecutionHistory ? "\ue7c1" : "\ue8f8");
BtnToggleExecutionLog.ToolTip = (_showExecutionHistory ? "?ㅽ뻾 濡쒓렇瑜??④퉩?덈떎" : "?ㅽ뻾 濡쒓렇瑜??ㅼ떆 ?쒖떆?⑸땲??);
}
}
private void RefreshSubAgentIndicator()
{
if (SubAgentIndicator == null || SubAgentIndicatorLabel == null)
{
return;
}
List<SubAgentTask> list = (from x in SubAgentTool.ActiveTasks.Values
where !x.CompletedAt.HasValue
orderby x.StartedAt
select x).ToList();
if (list.Count == 0)
{
SubAgentIndicator.Visibility = Visibility.Collapsed;
SubAgentIndicator.ToolTip = "?ㅽ뻾 以묒씤 ?쒕툕?먯씠?꾪듃媛€ ?놁뒿?덈떎";
return;
}
SubAgentIndicator.Visibility = Visibility.Visible;
SubAgentIndicatorLabel.Text = $"?쒕툕?먯씠?꾪듃 {list.Count}";
SubAgentIndicator.ToolTip = string.Join(Environment.NewLine, list.Select((SubAgentTask x) => x.Id + ": " + TruncateForStatus(x.Task, 48)));
}
private void AddMessageBubble(string role, string content, bool animate = true, ChatMessage? message = null)
{
//IL_05d5: Unknown result type (might be due to invalid IL or missing references)
Border border;
if (role == "user")
{
StackPanel wrapper = new StackPanel
{
HorizontalAlignment = System.Windows.HorizontalAlignment.Right,
MaxWidth = 620.0,
Margin = new Thickness(160.0, 10.0, 48.0, 10.0)
};
border = new Border();
border.Background = (TryFindResource("AccentColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Blue;
border.CornerRadius = new CornerRadius(16.0, 4.0, 16.0, 16.0);
border.Padding = new Thickness(16.0, 10.0, 16.0, 10.0);
border.Child = new TextBlock
{
Text = content,
FontSize = 13.5,
Foreground = System.Windows.Media.Brushes.White,
TextWrapping = TextWrapping.Wrap,
LineHeight = 21.0
};
Border element = border;
wrapper.Children.Add(element);
StackPanel userActionBar = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal,
HorizontalAlignment = System.Windows.HorizontalAlignment.Right,
Opacity = 0.0,
Margin = new Thickness(0.0, 2.0, 0.0, 0.0)
};
string capturedUserContent = content;
System.Windows.Media.Brush foreground = (TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
userActionBar.Children.Add(CreateActionButton("\ue8c8", "蹂듭궗", foreground, delegate
{
try
{
System.Windows.Clipboard.SetText(capturedUserContent);
}
catch
{
}
}));
userActionBar.Children.Add(CreateActionButton("\ue70f", "?몄쭛", foreground, delegate
{
EnterEditMode(wrapper, capturedUserContent);
}));
Grid grid = new Grid
{
Margin = new Thickness(0.0, 2.0, 0.0, 0.0)
};
DateTime dateTime = message?.Timestamp ?? DateTime.Now;
grid.Children.Add(new TextBlock
{
Text = dateTime.ToString("HH:mm"),
FontSize = 10.0,
Opacity = 0.5,
Foreground = ((TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray),
HorizontalAlignment = System.Windows.HorizontalAlignment.Right,
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(0.0, 0.0, 4.0, 0.0)
});
grid.Children.Add(userActionBar);
wrapper.Children.Add(grid);
wrapper.MouseEnter += delegate
{
userActionBar.Opacity = 1.0;
};
wrapper.MouseLeave += delegate
{
userActionBar.Opacity = 0.0;
};
string userContent = content;
wrapper.MouseRightButtonUp += delegate(object _, MouseButtonEventArgs re)
{
re.Handled = true;
ShowMessageContextMenu(userContent, "user");
};
if (animate)
{
ApplyMessageEntryAnimation(wrapper);
}
MessagePanel.Children.Add(wrapper);
return;
}
StackPanel stackPanel = new StackPanel
{
HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
MaxWidth = GetMessageMaxWidth(),
Margin = new Thickness(48.0, 10.0, 120.0, 10.0)
};
if (animate)
{
ApplyMessageEntryAnimation(stackPanel);
}
border = new Border();
border.Background = (TryFindResource("ItemBackground") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.White;
border.BorderBrush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(24, 17, 24, 39));
border.BorderThickness = new Thickness(1.0);
border.CornerRadius = new CornerRadius(18.0);
border.Padding = new Thickness(16.0, 14.0, 16.0, 12.0);
border.Effect = new DropShadowEffect
{
BlurRadius = 16.0,
ShadowDepth = 0.0,
Opacity = 0.06
};
Border border2 = border;
StackPanel stackPanel2 = new StackPanel();
(string Name, string Symbol, string Color) agentIdentity = GetAgentIdentity();
string item = agentIdentity.Name;
string item2 = agentIdentity.Symbol;
string item3 = agentIdentity.Color;
SolidColorBrush foreground2 = BrushFromHex(item3);
StackPanel stackPanel3 = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal,
Margin = new Thickness(0.0, 0.0, 0.0, 8.0)
};
TextBlock textBlock = new TextBlock
{
Text = "??,
FontSize = 13.0,
Foreground = foreground2,
VerticalAlignment = VerticalAlignment.Center,
RenderTransformOrigin = new Point(0.5, 0.5),
RenderTransform = new RotateTransform(0.0)
};
if (animate)
{
DoubleAnimation animation = new DoubleAnimation
{
From = 0.0,
To = 360.0,
Duration = TimeSpan.FromSeconds(1.2),
EasingFunction = new CubicEase
{
EasingMode = EasingMode.EaseOut
}
};
((RotateTransform)textBlock.RenderTransform).BeginAnimation(RotateTransform.AngleProperty, animation);
}
stackPanel3.Children.Add(textBlock);
stackPanel3.Children.Add(new TextBlock
{
Text = item,
FontSize = 11.0,
FontWeight = FontWeights.SemiBold,
Foreground = foreground2,
Margin = new Thickness(6.0, 0.0, 0.0, 0.0),
VerticalAlignment = VerticalAlignment.Center
});
stackPanel2.Children.Add(stackPanel3);
MarkdownRenderer.EnableFilePathHighlight = ((!(System.Windows.Application.Current is App app)) ? ((bool?)null) : app.SettingsService?.Settings.Llm.EnableFilePathHighlight) ?? true;
System.Windows.Media.Brush textColor = (TryFindResource("PrimaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.White;
System.Windows.Media.Brush secondaryColor = (TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
System.Windows.Media.Brush accentColor = (TryFindResource("AccentColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Blue;
System.Windows.Media.Brush codeBg = (TryFindResource("HintBackground") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.DarkGray;
StackPanel stackPanel4 = MarkdownRenderer.Render(content, textColor, secondaryColor, accentColor, codeBg);
stackPanel4.Margin = new Thickness(0.0, 0.0, 0.0, 6.0);
stackPanel2.Children.Add(stackPanel4);
StackPanel stackPanel5 = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal,
HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
Margin = new Thickness(0.0, 6.0, 0.0, 0.0)
};
System.Windows.Media.Brush brush = (TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
SolidColorBrush solidColorBrush = new SolidColorBrush(System.Windows.Media.Color.FromRgb(139, 144, 176));
string capturedContent = content;
stackPanel5.Children.Add(CreateActionButton("\ue8c8", "蹂듭궗", brush, delegate
{
try
{
System.Windows.Clipboard.SetText(capturedContent);
}
catch
{
}
}));
stackPanel5.Children.Add(CreateActionButton("\ue72c", "?ㅼ떆 ?앹꽦", brush, delegate
{
RegenerateLastAsync();
}));
stackPanel5.Children.Add(CreateActionButton("\ue70f", "?섏젙 ???ъ떆??, brush, delegate
{
ShowRetryWithFeedbackInput();
}));
AddLinkedFeedbackButtons(stackPanel5, brush, message);
DateTime dateTime2 = message?.Timestamp ?? DateTime.Now;
stackPanel5.Children.Add(new TextBlock
{
Text = dateTime2.ToString("HH:mm"),
FontSize = 10.0,
Opacity = 0.5,
Foreground = brush,
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(8.0, 0.0, 0.0, 0.0)
});
stackPanel2.Children.Add(stackPanel5);
border2.Child = stackPanel2;
stackPanel.Children.Add(border2);
string aiContent = content;
border2.MouseRightButtonUp += delegate(object _, MouseButtonEventArgs re)
{
re.Handled = true;
ShowMessageContextMenu(aiContent, "assistant");
};
MessagePanel.Children.Add(stackPanel);
}
private string GetCheckStyle()
{
string text = (_settings.Settings.Launcher.Theme ?? "system").ToLowerInvariant();
if (1 == 0)
{
}
string result;
switch (text)
{
case "dark":
case "system":
result = "circle";
break;
case "oled":
result = "glow";
break;
case "light":
result = "roundrect";
break;
case "nord":
result = "diamond";
break;
case "catppuccin":
result = "pill";
break;
case "monokai":
result = "square";
break;
case "sepia":
result = "stamp";
break;
case "alfred":
result = "minimal";
break;
case "alfredlight":
result = "minimal";
break;
default:
result = "circle";
break;
}
if (1 == 0)
{
}
return result;
}
private FrameworkElement CreateCheckIcon(bool isChecked, System.Windows.Media.Brush? accentBrush = null)
{
System.Windows.Media.Brush color = accentBrush ?? (TryFindResource("AccentColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.CornflowerBlue;
if (isChecked)
{
return CreateSimpleCheck(color);
}
return new System.Windows.Shapes.Rectangle
{
Width = 14.0,
Height = 14.0,
Fill = System.Windows.Media.Brushes.Transparent,
Margin = new Thickness(0.0, 0.0, 10.0, 0.0)
};
}
private static void AnimateScale(FrameworkElement el, double from, double to, int ms, IEasingFunction ease)
{
if (el.RenderTransform is TransformGroup transformGroup)
{
ScaleTransform scaleTransform = transformGroup.Children.OfType<ScaleTransform>().FirstOrDefault();
if (scaleTransform != null)
{
DoubleAnimation animation = new DoubleAnimation(from, to, TimeSpan.FromMilliseconds(ms))
{
EasingFunction = ease
};
scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, animation);
scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, animation);
return;
}
}
if (el.RenderTransform is ScaleTransform scaleTransform2)
{
DoubleAnimation animation2 = new DoubleAnimation(from, to, TimeSpan.FromMilliseconds(ms))
{
EasingFunction = ease
};
scaleTransform2.BeginAnimation(ScaleTransform.ScaleXProperty, animation2);
scaleTransform2.BeginAnimation(ScaleTransform.ScaleYProperty, animation2);
}
}
private static void ApplyHoverScaleAnimation(FrameworkElement element, double hoverScale = 1.08)
{
element.Loaded += delegate
{
EnsureTransform();
};
element.MouseEnter += delegate
{
EnsureTransform();
ScaleTransform scaleTransform = (ScaleTransform)element.RenderTransform;
DoubleAnimation animation = new DoubleAnimation(hoverScale, TimeSpan.FromMilliseconds(150.0))
{
EasingFunction = new CubicEase
{
EasingMode = EasingMode.EaseOut
}
};
scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, animation);
scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, animation);
};
element.MouseLeave += delegate
{
EnsureTransform();
ScaleTransform scaleTransform = (ScaleTransform)element.RenderTransform;
DoubleAnimation animation = new DoubleAnimation(1.0, TimeSpan.FromMilliseconds(200.0))
{
EasingFunction = new CubicEase
{
EasingMode = EasingMode.EaseOut
}
};
scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, animation);
scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, animation);
};
void EnsureTransform()
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
element.RenderTransformOrigin = new Point(0.5, 0.5);
if (!(element.RenderTransform is ScaleTransform) || ((Freezable)element.RenderTransform).IsFrozen)
{
element.RenderTransform = new ScaleTransform(1.0, 1.0);
}
}
}
private static void ApplyHoverBounceAnimation(FrameworkElement element, double bounceY = -2.5)
{
element.Loaded += delegate
{
EnsureTransform();
};
element.MouseEnter += delegate
{
EnsureTransform();
TranslateTransform translateTransform = (TranslateTransform)element.RenderTransform;
translateTransform.BeginAnimation(TranslateTransform.YProperty, new DoubleAnimation(bounceY, TimeSpan.FromMilliseconds(200.0))
{
EasingFunction = new CubicEase
{
EasingMode = EasingMode.EaseOut
}
});
};
element.MouseLeave += delegate
{
EnsureTransform();
TranslateTransform translateTransform = (TranslateTransform)element.RenderTransform;
translateTransform.BeginAnimation(TranslateTransform.YProperty, new DoubleAnimation(0.0, TimeSpan.FromMilliseconds(250.0))
{
EasingFunction = new ElasticEase
{
EasingMode = EasingMode.EaseOut,
Oscillations = 1,
Springiness = 10.0
}
});
};
void EnsureTransform()
{
if (!(element.RenderTransform is TranslateTransform) || ((Freezable)element.RenderTransform).IsFrozen)
{
element.RenderTransform = new TranslateTransform(0.0, 0.0);
}
}
}
private static FrameworkElement CreateSimpleCheck(System.Windows.Media.Brush color, double size = 14.0)
{
return new System.Windows.Shapes.Path
{
Data = Geometry.Parse($"M {size * 0.15} {size * 0.5} L {size * 0.4} {size * 0.75} L {size * 0.85} {size * 0.28}"),
Stroke = color,
StrokeThickness = 2.0,
StrokeStartLineCap = PenLineCap.Round,
StrokeEndLineCap = PenLineCap.Round,
StrokeLineJoin = PenLineJoin.Round,
Width = size,
Height = size,
Margin = new Thickness(0.0, 0.0, 10.0, 0.0),
VerticalAlignment = VerticalAlignment.Center
};
}
private static void ApplyMenuItemHover(Border item)
{
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
System.Windows.Media.Brush originalBg = item.Background?.Clone() ?? System.Windows.Media.Brushes.Transparent;
if (((Freezable)originalBg).CanFreeze)
{
((Freezable)originalBg).Freeze();
}
item.RenderTransformOrigin = new Point(0.5, 0.5);
item.RenderTransform = new ScaleTransform(1.0, 1.0);
item.MouseEnter += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border border)
{
if (originalBg is SolidColorBrush { Color: { A: >32 } })
{
border.Opacity = 0.85;
}
else
{
border.Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(24, byte.MaxValue, byte.MaxValue, byte.MaxValue));
}
}
ScaleTransform scaleTransform = item.RenderTransform as ScaleTransform;
scaleTransform?.BeginAnimation(ScaleTransform.ScaleXProperty, new DoubleAnimation(1.02, TimeSpan.FromMilliseconds(120.0)));
scaleTransform?.BeginAnimation(ScaleTransform.ScaleYProperty, new DoubleAnimation(1.02, TimeSpan.FromMilliseconds(120.0)));
};
item.MouseLeave += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border border)
{
border.Opacity = 1.0;
border.Background = originalBg;
}
ScaleTransform scaleTransform = item.RenderTransform as ScaleTransform;
scaleTransform?.BeginAnimation(ScaleTransform.ScaleXProperty, new DoubleAnimation(1.0, TimeSpan.FromMilliseconds(150.0)));
scaleTransform?.BeginAnimation(ScaleTransform.ScaleYProperty, new DoubleAnimation(1.0, TimeSpan.FromMilliseconds(150.0)));
};
}
private System.Windows.Controls.Button CreateActionButton(string symbol, string tooltip, System.Windows.Media.Brush foreground, Action onClick)
{
System.Windows.Media.Brush hoverBrush = (TryFindResource("PrimaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.White;
TextBlock icon = new TextBlock
{
Text = symbol,
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 12.0,
Foreground = foreground,
VerticalAlignment = VerticalAlignment.Center
};
System.Windows.Controls.Button button = new System.Windows.Controls.Button
{
Content = icon,
Background = System.Windows.Media.Brushes.Transparent,
BorderThickness = new Thickness(0.0),
Cursor = System.Windows.Input.Cursors.Hand,
Padding = new Thickness(6.0, 4.0, 6.0, 4.0),
Margin = new Thickness(0.0, 0.0, 4.0, 0.0),
ToolTip = tooltip
};
button.MouseEnter += delegate
{
icon.Foreground = hoverBrush;
};
button.MouseLeave += delegate
{
icon.Foreground = foreground;
};
button.Click += delegate
{
onClick();
};
ApplyHoverScaleAnimation(button, 1.15);
return button;
}
private System.Windows.Controls.Button CreateFeedbackButton(string outline, string filled, string tooltip, System.Windows.Media.Brush normalColor, System.Windows.Media.Brush activeColor, ChatMessage? message = null, string feedbackType = "", Action? resetSibling = null, Action<Action>? registerReset = null)
{
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
System.Windows.Media.Brush hoverBrush = (TryFindResource("PrimaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.White;
bool isActive = message?.Feedback == feedbackType;
TextBlock icon = new TextBlock
{
Text = (isActive ? filled : outline),
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 12.0,
Foreground = (isActive ? activeColor : normalColor),
VerticalAlignment = VerticalAlignment.Center,
RenderTransformOrigin = new Point(0.5, 0.5),
RenderTransform = new ScaleTransform(1.0, 1.0)
};
System.Windows.Controls.Button button = new System.Windows.Controls.Button
{
Content = icon,
Background = System.Windows.Media.Brushes.Transparent,
BorderThickness = new Thickness(0.0),
Cursor = System.Windows.Input.Cursors.Hand,
Padding = new Thickness(6.0, 4.0, 6.0, 4.0),
Margin = new Thickness(0.0, 0.0, 4.0, 0.0),
ToolTip = tooltip
};
registerReset?.Invoke(delegate
{
isActive = false;
icon.Text = outline;
icon.Foreground = normalColor;
});
button.MouseEnter += delegate
{
if (!isActive)
{
icon.Foreground = hoverBrush;
}
};
button.MouseLeave += delegate
{
if (!isActive)
{
icon.Foreground = normalColor;
}
};
button.Click += delegate
{
isActive = !isActive;
icon.Text = (isActive ? filled : outline);
icon.Foreground = (isActive ? activeColor : normalColor);
if (isActive)
{
resetSibling?.Invoke();
}
if (message != null)
{
message.Feedback = (isActive ? feedbackType : null);
try
{
ChatConversation currentConversation;
lock (_convLock)
{
currentConversation = _currentConversation;
}
if (currentConversation != null)
{
_storage.Save(currentConversation);
}
}
catch
{
}
}
ScaleTransform scaleTransform = (ScaleTransform)icon.RenderTransform;
DoubleAnimation animation = new DoubleAnimation(1.3, 1.0, TimeSpan.FromMilliseconds(250.0))
{
EasingFunction = new ElasticEase
{
EasingMode = EasingMode.EaseOut,
Oscillations = 1,
Springiness = 5.0
}
};
scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, animation);
scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, animation);
};
return button;
}
private void AddLinkedFeedbackButtons(StackPanel actionBar, System.Windows.Media.Brush btnColor, ChatMessage? message)
{
Action resetLikeAction = null;
Action resetDislikeAction = null;
System.Windows.Controls.Button element = CreateFeedbackButton("\ue8e1", "\ueb51", "醫뗭븘??, btnColor, new SolidColorBrush(System.Windows.Media.Color.FromRgb(56, 161, 105)), message, "like", delegate
{
resetDislikeAction?.Invoke();
}, delegate(Action reset)
{
resetLikeAction = reset;
});
System.Windows.Controls.Button element2 = CreateFeedbackButton("\ue8e0", "\ueb50", "?レ뼱??, btnColor, new SolidColorBrush(System.Windows.Media.Color.FromRgb(229, 62, 62)), message, "dislike", delegate
{
resetLikeAction?.Invoke();
}, delegate(Action reset)
{
resetDislikeAction = reset;
});
actionBar.Children.Add(element);
actionBar.Children.Add(element2);
}
private static void ApplyMessageEntryAnimation(FrameworkElement element)
{
element.Opacity = 0.0;
element.RenderTransform = new TranslateTransform(0.0, 16.0);
element.BeginAnimation(UIElement.OpacityProperty, new DoubleAnimation(0.0, 1.0, TimeSpan.FromMilliseconds(350.0))
{
EasingFunction = new CubicEase
{
EasingMode = EasingMode.EaseOut
}
});
((TranslateTransform)element.RenderTransform).BeginAnimation(TranslateTransform.YProperty, new DoubleAnimation(16.0, 0.0, TimeSpan.FromMilliseconds(400.0))
{
EasingFunction = new CubicEase
{
EasingMode = EasingMode.EaseOut
}
});
}
private void EnterEditMode(StackPanel wrapper, string originalText)
{
if (_isStreaming || _isEditing)
{
return;
}
_isEditing = true;
int idx = MessagePanel.Children.IndexOf(wrapper);
if (idx < 0)
{
_isEditing = false;
return;
}
StackPanel stackPanel = new StackPanel
{
HorizontalAlignment = System.Windows.HorizontalAlignment.Right,
MaxWidth = 540.0,
Margin = wrapper.Margin
};
System.Windows.Controls.TextBox editBox = new System.Windows.Controls.TextBox
{
Text = originalText,
FontSize = 13.5,
Foreground = ((TryFindResource("PrimaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.White),
Background = ((TryFindResource("ItemBackground") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.DarkGray),
CaretBrush = ((TryFindResource("AccentColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Blue),
BorderBrush = ((TryFindResource("AccentColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Blue),
BorderThickness = new Thickness(1.5),
Padding = new Thickness(14.0, 10.0, 14.0, 10.0),
TextWrapping = TextWrapping.Wrap,
AcceptsReturn = false,
MaxHeight = 200.0,
VerticalScrollBarVisibility = ScrollBarVisibility.Auto
};
Border element = new Border
{
CornerRadius = new CornerRadius(14.0),
Child = editBox,
ClipToBounds = true
};
stackPanel.Children.Add(element);
StackPanel stackPanel2 = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal,
HorizontalAlignment = System.Windows.HorizontalAlignment.Right,
Margin = new Thickness(0.0, 6.0, 0.0, 0.0)
};
System.Windows.Media.Brush brush = (TryFindResource("AccentColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Blue;
System.Windows.Media.Brush foreground = (TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
System.Windows.Controls.Button button = new System.Windows.Controls.Button
{
Content = new TextBlock
{
Text = "痍⑥냼",
FontSize = 12.0,
Foreground = foreground
},
Background = System.Windows.Media.Brushes.Transparent,
BorderThickness = new Thickness(0.0),
Cursor = System.Windows.Input.Cursors.Hand,
Padding = new Thickness(12.0, 5.0, 12.0, 5.0),
Margin = new Thickness(0.0, 0.0, 6.0, 0.0)
};
button.Click += delegate
{
_isEditing = false;
if (idx >= 0 && idx < MessagePanel.Children.Count)
{
MessagePanel.Children[idx] = wrapper;
}
};
stackPanel2.Children.Add(button);
System.Windows.Controls.Button button2 = new System.Windows.Controls.Button
{
Cursor = System.Windows.Input.Cursors.Hand,
Padding = new Thickness(0.0)
};
button2.Template = (ControlTemplate)XamlReader.Parse("<ControlTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' TargetType='Button'><Border Background='" + ((brush is SolidColorBrush { Color: var color }) ? color.ToString() : "#4B5EFC") + "' CornerRadius='8' Padding='12,5,12,5'><TextBlock Text='?꾩넚' FontSize='12' Foreground='White' HorizontalAlignment='Center'/></Border></ControlTemplate>");
button2.Click += delegate
{
string text = editBox.Text.Trim();
if (!string.IsNullOrEmpty(text))
{
SubmitEditAsync(idx, text);
}
};
stackPanel2.Children.Add(button2);
stackPanel.Children.Add(stackPanel2);
MessagePanel.Children[idx] = stackPanel;
editBox.KeyDown += delegate(object _, System.Windows.Input.KeyEventArgs ke)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Invalid comparison between Unknown and I4
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Invalid comparison between Unknown and I4
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Invalid comparison between Unknown and I4
if ((int)ke.Key == 6 && (int)Keyboard.Modifiers == 0)
{
ke.Handled = true;
string text = editBox.Text.Trim();
if (!string.IsNullOrEmpty(text))
{
_ = SubmitEditAsync(idx, text);
}
}
if ((int)ke.Key == 13)
{
ke.Handled = true;
_isEditing = false;
if (idx >= 0 && idx < MessagePanel.Children.Count)
{
MessagePanel.Children[idx] = wrapper;
}
}
};
editBox.Focus();
editBox.SelectAll();
}
private async Task SubmitEditAsync(int bubbleIndex, string newText)
{
_isEditing = false;
if (_isStreaming)
{
return;
}
ChatConversation conv;
lock (_convLock)
{
if (_currentConversation == null)
{
return;
}
conv = _currentConversation;
}
int userMsgIdx = -1;
int uiIdx = 0;
lock (_convLock)
{
for (int i = 0; i < conv.Messages.Count; i++)
{
if (!(conv.Messages[i].Role == "system"))
{
if (uiIdx == bubbleIndex)
{
userMsgIdx = i;
break;
}
uiIdx++;
}
}
}
if (userMsgIdx < 0)
{
return;
}
lock (_convLock)
{
conv.Messages[userMsgIdx].Content = newText;
while (conv.Messages.Count > userMsgIdx + 1)
{
conv.Messages.RemoveAt(conv.Messages.Count - 1);
}
}
while (MessagePanel.Children.Count > bubbleIndex + 1)
{
MessagePanel.Children.RemoveAt(MessagePanel.Children.Count - 1);
}
MessagePanel.Children.RemoveAt(bubbleIndex);
AddMessageBubble("user", newText, animate: false);
await SendRegenerateAsync(conv);
try
{
_storage.Save(conv);
}
catch (Exception ex)
{
LogService.Debug("?€???€???ㅽ뙣: " + ex.Message);
}
RefreshConversationList();
}
private void StopAiIconPulse()
{
if (!_aiIconPulseStopped && _activeAiIcon != null)
{
_activeAiIcon.BeginAnimation(UIElement.OpacityProperty, null);
_activeAiIcon.Opacity = 1.0;
_activeAiIcon = null;
_aiIconPulseStopped = true;
}
}
private void CursorTimer_Tick(object? sender, EventArgs e)
{
_cursorVisible = !_cursorVisible;
if (_activeStreamText != null && _displayedLength > 0)
{
string text = ((_cachedStreamContent.Length > 0) ? _cachedStreamContent.Substring(0, Math.Min(_displayedLength, _cachedStreamContent.Length)) : "");
_activeStreamText.Text = text + (_cursorVisible ? "?? : " ");
}
}
private void ElapsedTimer_Tick(object? sender, EventArgs e)
{
int value = (int)(DateTime.UtcNow - _streamStartTime).TotalSeconds;
if (_elapsedLabel != null)
{
_elapsedLabel.Text = $"{value}s";
}
if (StatusElapsed != null)
{
StatusElapsed.Text = $"{value}珥?;
}
}
private void TypingTimer_Tick(object? sender, EventArgs e)
{
if (_activeStreamText == null || string.IsNullOrEmpty(_cachedStreamContent))
{
return;
}
int length = _cachedStreamContent.Length;
if (_displayedLength < length)
{
int num = length - _displayedLength;
int num2 = ((num > 200) ? Math.Min(num / 5, 40) : ((num <= 50) ? Math.Min(3, num) : Math.Min(num / 4, 15)));
_displayedLength += num2;
string text = _cachedStreamContent.Substring(0, _displayedLength);
_activeStreamText.Text = text + (_cursorVisible ? "?? : " ");
if (!_userScrolled)
{
MessageScroll.ScrollToVerticalOffset(MessageScroll.ScrollableHeight);
}
}
}
public void SendInitialMessage(string message)
{
StartNewConversation();
InputBox.Text = message;
SendMessageAsync();
}
private void StartNewConversation()
{
lock (_convLock)
{
if (_currentConversation != null && _currentConversation.Messages.Count > 0)
{
try
{
_storage.Save(_currentConversation);
}
catch
{
}
}
_currentConversation = new ChatConversation
{
Tab = _activeTab
};
string workFolder = _settings.Settings.Llm.WorkFolder;
if (!string.IsNullOrEmpty(workFolder) && _activeTab != "Chat")
{
_currentConversation.WorkFolder = workFolder;
}
}
_tabConversationId[_activeTab] = null;
MessagePanel.Children.Clear();
EmptyState.Visibility = Visibility.Visible;
_attachedFiles.Clear();
RefreshAttachedFilesUI();
UpdateChatTitle();
RefreshConversationList();
UpdateFolderBar();
if (_activeTab == "Cowork")
{
BuildBottomBar();
}
}
private void RestoreLastConversations()
{
Dictionary<string, string> lastConversationIds = _settings.Settings.Llm.LastConversationIds;
if (lastConversationIds == null || lastConversationIds.Count == 0)
{
return;
}
foreach (KeyValuePair<string, string> item in lastConversationIds)
{
if (_tabConversationId.ContainsKey(item.Key) && !string.IsNullOrEmpty(item.Value))
{
_tabConversationId[item.Key] = item.Value;
}
}
string valueOrDefault = _tabConversationId.GetValueOrDefault(_activeTab);
if (string.IsNullOrEmpty(valueOrDefault))
{
return;
}
ChatConversation chatConversation = _storage.Load(valueOrDefault);
if (chatConversation != null)
{
if (string.IsNullOrEmpty(chatConversation.Tab))
{
chatConversation.Tab = _activeTab;
}
lock (_convLock)
{
_currentConversation = chatConversation;
}
RenderMessages();
UpdateChatTitle();
UpdateFolderBar();
LoadConversationSettings();
}
}
private void SaveLastConversations()
{
Dictionary<string, string> dictionary = new Dictionary<string, string>();
foreach (KeyValuePair<string, string> item in _tabConversationId)
{
if (!string.IsNullOrEmpty(item.Value))
{
dictionary[item.Key] = item.Value;
}
}
_settings.Settings.Llm.LastConversationIds = dictionary;
try
{
_settings.Save();
}
catch
{
}
}
private async void BtnSend_Click(object sender, RoutedEventArgs e)
{
await SendMessageAsync();
}
private async void InputBox_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
if ((int)e.Key == 65 && ((Enum)Keyboard.Modifiers).HasFlag((Enum)(object)(ModifierKeys)2) && TryPasteClipboardImage())
{
e.Handled = true;
}
else if ((int)e.Key == 6 && !((Enum)Keyboard.Modifiers).HasFlag((Enum)(object)(ModifierKeys)4))
{
if (SlashPopup.IsOpen && _slashSelectedIndex >= 0)
{
e.Handled = true;
ExecuteSlashSelectedItem();
}
else if (InputBox.Text.Trim().Equals("/help", StringComparison.OrdinalIgnoreCase))
{
e.Handled = true;
InputBox.Text = "";
SlashPopup.IsOpen = false;
ShowSlashHelpWindow();
}
else
{
e.Handled = true;
await SendMessageAsync();
}
}
}
private bool TryPasteClipboardImage()
{
if (!_settings.Settings.Llm.EnableImageInput)
{
return false;
}
if (!System.Windows.Clipboard.ContainsImage())
{
return false;
}
try
{
BitmapSource image = System.Windows.Clipboard.GetImage();
if (image == null)
{
return false;
}
PngBitmapEncoder pngBitmapEncoder = new PngBitmapEncoder();
pngBitmapEncoder.Frames.Add(BitmapFrame.Create(image));
using MemoryStream memoryStream = new MemoryStream();
pngBitmapEncoder.Save(memoryStream);
byte[] array = memoryStream.ToArray();
int num = _settings.Settings.Llm.MaxImageSizeKb;
if (num <= 0)
{
num = 5120;
}
if (array.Length > num * 1024)
{
CustomMessageBox.Show($"?대?吏€媛€ ?덈Т ?쎈땲??({array.Length / 1024}KB, 理쒕? {num}KB).", "?대?吏€ ?ш린 珥덇낵", MessageBoxButton.OK, MessageBoxImage.Exclamation);
return true;
}
string @base = Convert.ToBase64String(array);
ImageAttachment imageAttachment = new ImageAttachment
{
Base64 = @base,
MimeType = "image/png",
FileName = $"clipboard_{DateTime.Now:HHmmss}.png"
};
_pendingImages.Add(imageAttachment);
AddImagePreview(imageAttachment, image);
return true;
}
catch (Exception ex)
{
LogService.Debug("?대┰蹂대뱶 ?대?吏€ 遺숈뿬?j린 ?ㅽ뙣: " + ex.Message);
return false;
}
}
private void AddImagePreview(ImageAttachment attachment, BitmapSource? thumbnail = null)
{
System.Windows.Media.Brush foreground = (TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
System.Windows.Media.Brush background = (TryFindResource("HintBackground") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.LightGray;
Border border = new Border
{
Background = background,
CornerRadius = new CornerRadius(6.0),
Padding = new Thickness(4.0),
Margin = new Thickness(0.0, 0.0, 4.0, 4.0)
};
StackPanel stackPanel = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal
};
if (thumbnail != null)
{
stackPanel.Children.Add(new System.Windows.Controls.Image
{
Source = thumbnail,
MaxHeight = 48.0,
MaxWidth = 64.0,
Stretch = Stretch.Uniform,
Margin = new Thickness(0.0, 0.0, 4.0, 0.0)
});
}
else
{
stackPanel.Children.Add(new TextBlock
{
Text = "\ue8b9",
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 16.0,
Foreground = foreground,
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(2.0, 0.0, 4.0, 0.0)
});
}
stackPanel.Children.Add(new TextBlock
{
Text = attachment.FileName,
FontSize = 10.0,
Foreground = foreground,
VerticalAlignment = VerticalAlignment.Center,
MaxWidth = 100.0,
TextTrimming = TextTrimming.CharacterEllipsis
});
ImageAttachment capturedAttachment = attachment;
Border capturedChip = border;
System.Windows.Controls.Button button = new System.Windows.Controls.Button
{
Content = new TextBlock
{
Text = "\ue711",
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 8.0,
Foreground = foreground
},
Background = System.Windows.Media.Brushes.Transparent,
BorderThickness = new Thickness(0.0),
Cursor = System.Windows.Input.Cursors.Hand,
Padding = new Thickness(4.0, 2.0, 4.0, 2.0),
Margin = new Thickness(2.0, 0.0, 0.0, 0.0)
};
button.Click += delegate
{
_pendingImages.Remove(capturedAttachment);
AttachedFilesPanel.Items.Remove(capturedChip);
if (_pendingImages.Count == 0 && _attachedFiles.Count == 0)
{
AttachedFilesPanel.Visibility = Visibility.Collapsed;
}
};
stackPanel.Children.Add(button);
border.Child = stackPanel;
AttachedFilesPanel.Items.Add(border);
AttachedFilesPanel.Visibility = Visibility.Visible;
}
private void InputBox_TextChanged(object sender, TextChangedEventArgs e)
{
UpdateWatermarkVisibility();
UpdateDraftPreviewCard();
string text = InputBox.Text;
if (_activeSlashCmd != null && text.StartsWith("/"))
{
HideSlashChip();
}
if (text.StartsWith("/") && !text.Contains(' '))
{
string activeTab = _activeTab;
bool flag = ((activeTab == "Cowork" || activeTab == "Code") ? true : false);
bool isDev = flag;
List<(string, string, bool)> list = (from kv in SlashCommands
where kv.Key.StartsWith(text, StringComparison.OrdinalIgnoreCase)
where kv.Value.Tab == "all" || (isDev && kv.Value.Tab == "dev")
select (Cmd: kv.Key, Label: kv.Value.Label, IsSkill: false)).ToList();
if (_settings.Settings.Llm.EnableSkillSystem)
{
IEnumerable<(string, string, bool, bool)> enumerable = from s in SkillService.MatchSlashCommand(text)
where s.IsVisibleInTab(_activeTab)
select (Cmd: "/" + s.Name, Label: s.IsAvailable ? s.Label : (s.Label + " " + s.UnavailableHint), IsSkill: true, Available: s.IsAvailable);
foreach (var item in enumerable)
{
list.Add((item.Item1, item.Item2, item.Item3));
}
}
if (list.Count > 0)
{
List<string> favorites = _settings.Settings.Llm.FavoriteSlashCommands;
if (favorites.Count > 0)
{
list = list.OrderByDescending<(string, string, bool), bool>(((string Cmd, string Label, bool IsSkill) m) => favorites.Contains<string>(m.Cmd, StringComparer.OrdinalIgnoreCase)).ToList();
}
_slashAllMatches = list;
_slashPageOffset = 0;
_slashSelectedIndex = -1;
RenderSlashPage();
SlashPopup.IsOpen = true;
return;
}
}
SlashPopup.IsOpen = false;
}
private void UpdateDraftPreviewCard()
{
if (DraftPreviewCard != null && DraftPreviewText != null && InputBox != null)
{
string text = InputBox.Text?.Trim() ?? "";
string activeSlashCmd = _activeSlashCmd;
string text2 = ((activeSlashCmd != null && activeSlashCmd.Length > 0) ? (_activeSlashCmd + " ") : "");
string text3 = (text2 + text).Trim();
if (string.IsNullOrWhiteSpace(text3))
{
DraftPreviewCard.Visibility = Visibility.Collapsed;
DraftPreviewText.Text = "";
RebuildDraftQueuePanel();
}
else
{
DraftPreviewCard.Visibility = Visibility.Visible;
DraftPreviewText.Text = ((text3.Length > 140) ? (text3.Substring(0, 140) + "...") : text3);
RebuildDraftQueuePanel();
}
}
}
private string GetPreparedDraftText()
{
string text = InputBox?.Text?.Trim() ?? "";
return (_activeSlashCmd != null) ? (_activeSlashCmd + " " + text).Trim() : text;
}
private void RebuildDraftQueuePanel()
{
if (DraftQueuePanel == null)
{
return;
}
DraftQueuePanel.Children.Clear();
DraftQueuePanel.Visibility = ((_draftQueue.Count <= 0) ? Visibility.Collapsed : Visibility.Visible);
if (_draftQueue.Count == 0)
{
return;
}
DraftQueuePanel.Children.Add(new TextBlock
{
Text = $"?ㅼ쓬 ?묒뾽 ?€湲곗뿴 {_draftQueue.Count}",
FontSize = 10.5,
FontWeight = FontWeights.SemiBold,
Foreground = ((TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray),
Margin = new Thickness(4.0, 0.0, 0.0, 6.0)
});
for (int i = 0; i < _draftQueue.Count; i++)
{
int index = i;
string text = _draftQueue[i];
Border border = new Border();
border.Background = (TryFindResource("ItemBackground") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.White;
border.BorderBrush = (TryFindResource("BorderColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.LightGray;
border.BorderThickness = new Thickness(1.0);
border.CornerRadius = new CornerRadius(16.0);
border.Padding = new Thickness(12.0, 9.0, 12.0, 9.0);
border.Margin = new Thickness(0.0, 0.0, 0.0, 6.0);
Border border2 = border;
Grid grid = new Grid();
grid.ColumnDefinitions.Add(new ColumnDefinition
{
Width = new GridLength(1.0, GridUnitType.Star)
});
grid.ColumnDefinitions.Add(new ColumnDefinition
{
Width = GridLength.Auto
});
grid.ColumnDefinitions.Add(new ColumnDefinition
{
Width = GridLength.Auto
});
StackPanel stackPanel = new StackPanel();
stackPanel.Children.Add(new TextBlock
{
Text = ((index == 0) ? "?ㅼ쓬 ?쒖꽌" : $"?€湲?{index + 1}"),
FontSize = 10.0,
Foreground = ((TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray)
});
stackPanel.Children.Add(new TextBlock
{
Text = ((text.Length > 160) ? (text.Substring(0, 160) + "...") : text),
FontSize = 12.5,
Foreground = ((TryFindResource("PrimaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Black),
Margin = new Thickness(0.0, 4.0, 0.0, 0.0),
TextTrimming = TextTrimming.CharacterEllipsis
});
Grid.SetColumn(stackPanel, 0);
grid.Children.Add(stackPanel);
System.Windows.Controls.Button button = new System.Windows.Controls.Button();
button.Style = TryFindResource("GhostBtn") as Style;
button.Padding = new Thickness(8.0, 4.0, 8.0, 4.0);
button.Margin = new Thickness(8.0, 0.0, 0.0, 0.0);
button.ToolTip = "吏€湲?諛붾줈 ?ㅽ뻾";
button.Content = new TextBlock
{
Text = "\ue768",
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 10.0,
Foreground = ((TryFindResource("AccentColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.CornflowerBlue)
};
System.Windows.Controls.Button button2 = button;
button2.Click += async delegate
{
if (index >= 0 && index < _draftQueue.Count && !_isStreaming)
{
string next = _draftQueue[index];
_draftQueue.RemoveAt(index);
RebuildDraftQueuePanel();
InputBox.Text = next;
InputBox.CaretIndex = InputBox.Text.Length;
UpdateDraftPreviewCard();
await SendMessageAsync();
}
};
Grid.SetColumn(button2, 1);
grid.Children.Add(button2);
button = new System.Windows.Controls.Button();
button.Style = TryFindResource("GhostBtn") as Style;
button.Padding = new Thickness(6.0, 4.0, 6.0, 4.0);
button.Margin = new Thickness(8.0, 0.0, 0.0, 0.0);
button.ToolTip = "?€湲곗뿴?먯꽌 ?쒓굅";
button.Content = new TextBlock
{
Text = "\ue711",
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 10.0,
Foreground = ((TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray)
};
System.Windows.Controls.Button button3 = button;
button3.Click += delegate
{
if (index >= 0 && index < _draftQueue.Count)
{
_draftQueue.RemoveAt(index);
RebuildDraftQueuePanel();
}
};
Grid.SetColumn(button3, 2);
grid.Children.Add(button3);
border2.Child = grid;
DraftQueuePanel.Children.Add(border2);
}
}
private void BtnDraftEnqueue_Click(object sender, RoutedEventArgs e)
{
string preparedDraftText = GetPreparedDraftText();
if (!string.IsNullOrWhiteSpace(preparedDraftText))
{
_draftQueue.Add(preparedDraftText);
if (_activeSlashCmd != null)
{
HideSlashChip();
}
InputBox.Clear();
RebuildDraftQueuePanel();
UpdateDraftPreviewCard();
InputBox.Focus();
}
}
private void StartNextQueuedDraftIfAny()
{
if (_autoContinuingQueuedDraft || _isStreaming || _draftQueue.Count == 0)
{
return;
}
string next = _draftQueue[0];
_draftQueue.RemoveAt(0);
_autoContinuingQueuedDraft = true;
RebuildDraftQueuePanel();
((DispatcherObject)this).Dispatcher.BeginInvoke((Delegate)(Func<Task>)async delegate
{
try
{
InputBox.Text = next;
InputBox.CaretIndex = InputBox.Text.Length;
UpdateDraftPreviewCard();
await SendMessageAsync();
}
finally
{
_autoContinuingQueuedDraft = false;
}
}, (DispatcherPriority)4, Array.Empty<object>());
}
private void BtnDraftEdit_Click(object sender, RoutedEventArgs e)
{
InputBox.Focus();
InputBox.CaretIndex = InputBox.Text?.Length ?? 0;
}
private void BtnDraftClear_Click(object sender, RoutedEventArgs e)
{
if (_activeSlashCmd != null)
{
HideSlashChip();
}
InputBox.Clear();
UpdateDraftPreviewCard();
InputBox.Focus();
}
private void RenderSlashPage()
{
SlashItems.Items.Clear();
int count = _slashAllMatches.Count;
int slashPageOffset = _slashPageOffset;
int num = Math.Min(slashPageOffset + SlashPageSize, count);
int value = _slashAllMatches.Count<(string, string, bool)>(((string Cmd, string Label, bool IsSkill) x) => !x.IsSkill);
int num2 = _slashAllMatches.Count<(string, string, bool)>(((string Cmd, string Label, bool IsSkill) x) => x.IsSkill);
if (SlashPopupTitle != null)
{
SlashPopupTitle.Text = ((num2 > 0) ? "紐낅졊?댁? ?ㅽ궗" : "鍮좊Ⅸ 紐낅졊??);
}
if (SlashPopupHint != null)
{
SlashPopupHint.Text = ((num2 > 0) ? $"紐낅졊 {value}媛?쨌 ?ㅽ궗 {num2}媛? : $"紐낅졊 {value}媛?);
}
if (slashPageOffset > 0)
{
SlashNavUp.Visibility = Visibility.Visible;
SlashNavUpText.Text = $"?? ?꾨줈 {slashPageOffset}媛?;
}
else
{
SlashNavUp.Visibility = Visibility.Collapsed;
}
bool? flag = null;
for (int num3 = slashPageOffset; num3 < num; num3++)
{
(string Cmd, string Label, bool IsSkill) tuple = _slashAllMatches[num3];
string item = tuple.Cmd;
string item2 = tuple.Label;
bool item3 = tuple.IsSkill;
string capturedCmd = item;
SkillDefinition skillDefinition = (item3 ? SkillService.Find(item.TrimStart('/')) : null);
bool flag2 = skillDefinition?.IsAvailable ?? true;
bool flag3 = _settings.Settings.Llm.FavoriteSlashCommands.Contains<string>(item, StringComparer.OrdinalIgnoreCase);
int num4 = num3 - slashPageOffset;
bool flag4 = num4 == _slashSelectedIndex;
System.Windows.Media.Brush brush = (TryFindResource("ItemHoverBackground") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.LightGray;
string toolTip = ((item3 && skillDefinition != null && !string.IsNullOrWhiteSpace(skillDefinition.Description)) ? skillDefinition.Description : item2);
if (flag != item3)
{
flag = item3;
SlashItems.Items.Add(new TextBlock
{
Text = (item3 ? "?ㅽ궗" : "紐낅졊??),
FontSize = 10.5,
FontWeight = FontWeights.SemiBold,
Foreground = ((TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray),
Margin = new Thickness(8.0, (num3 == slashPageOffset) ? 2 : 10, 8.0, 6.0)
});
}
Border item4 = new Border
{
Background = (flag4 ? brush : System.Windows.Media.Brushes.Transparent),
BorderBrush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(18, 17, 24, 39)),
BorderThickness = new Thickness(1.0),
CornerRadius = new CornerRadius(12.0),
Padding = new Thickness(12.0, 10.0, 12.0, 10.0),
Margin = new Thickness(4.0, 2.0, 4.0, 2.0),
Cursor = (flag2 ? System.Windows.Input.Cursors.Hand : System.Windows.Input.Cursors.Arrow),
Opacity = (flag2 ? 1.0 : 0.5),
ToolTip = toolTip
};
Grid grid = new Grid();
grid.ColumnDefinitions.Add(new ColumnDefinition
{
Width = GridLength.Auto
});
grid.ColumnDefinitions.Add(new ColumnDefinition
{
Width = new GridLength(1.0, GridUnitType.Star)
});
grid.ColumnDefinitions.Add(new ColumnDefinition
{
Width = GridLength.Auto
});
Border element = new Border
{
Width = 28.0,
Height = 28.0,
CornerRadius = new CornerRadius(8.0),
Background = (item3 ? new SolidColorBrush(System.Windows.Media.Color.FromArgb(22, 37, 99, 235)) : new SolidColorBrush(System.Windows.Media.Color.FromArgb(18, 107, 114, 128))),
Margin = new Thickness(0.0, 0.0, 10.0, 0.0),
Child = new TextBlock
{
Text = ((!item3) ? "\ue8a7" : (skillDefinition?.Icon ?? "\ue768")),
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 11.0,
Foreground = (item3 ? new SolidColorBrush(System.Windows.Media.Color.FromRgb(37, 99, 235)) : new SolidColorBrush(System.Windows.Media.Color.FromRgb(107, 114, 128))),
HorizontalAlignment = System.Windows.HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
}
};
Grid.SetColumn(element, 0);
grid.Children.Add(element);
StackPanel stackPanel = new StackPanel();
if (flag3)
{
stackPanel.Children.Add(new TextBlock
{
Text = "\ue735 ",
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 10.0,
Foreground = new SolidColorBrush(System.Windows.Media.Color.FromRgb(245, 158, 11)),
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(0.0, 0.0, 2.0, 0.0)
});
}
stackPanel.Children.Add(new TextBlock
{
Text = item,
FontSize = 13.0,
FontWeight = FontWeights.SemiBold,
Foreground = (flag2 ? ((TryFindResource("AccentColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Blue) : ((TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray)),
VerticalAlignment = VerticalAlignment.Center
});
stackPanel.Children.Add(new TextBlock
{
Text = " ??" + item2,
FontSize = 11.5,
Foreground = ((TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray),
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(0.0, 4.0, 0.0, 0.0),
TextWrapping = TextWrapping.Wrap
});
Grid.SetColumn(stackPanel, 1);
grid.Children.Add(stackPanel);
string favCapturedCmd = item;
Border border = new Border();
border.Width = 24.0;
border.Height = 24.0;
border.CornerRadius = new CornerRadius(4.0);
border.Background = System.Windows.Media.Brushes.Transparent;
border.Cursor = System.Windows.Input.Cursors.Hand;
border.VerticalAlignment = VerticalAlignment.Center;
border.Child = new TextBlock
{
Text = (flag3 ? "\ue735" : "\ue734"),
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 11.0,
Foreground = (flag3 ? new SolidColorBrush(System.Windows.Media.Color.FromRgb(245, 158, 11)) : ((TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray)),
HorizontalAlignment = System.Windows.HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
Opacity = (flag3 ? 1.0 : 0.4)
};
Border border2 = border;
border2.MouseEnter += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
((Border)s).Opacity = 0.8;
};
border2.MouseLeave += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
((Border)s).Opacity = 1.0;
};
border2.MouseLeftButtonDown += delegate(object _, MouseButtonEventArgs me)
{
me.Handled = true;
ToggleSlashFavorite(favCapturedCmd);
};
Grid.SetColumn(border2, 2);
grid.Children.Add(border2);
item4.Child = grid;
if (flag2)
{
System.Windows.Media.Brush hoverBrush = (TryFindResource("ItemHoverBackground") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.LightGray;
item4.MouseEnter += delegate
{
item4.Background = hoverBrush;
};
item4.MouseLeave += delegate
{
item4.Background = System.Windows.Media.Brushes.Transparent;
};
item4.MouseLeftButtonDown += delegate
{
SlashPopup.IsOpen = false;
if (capturedCmd.Equals("/help", StringComparison.OrdinalIgnoreCase))
{
InputBox.Text = "";
ShowSlashHelpWindow();
}
else
{
ShowSlashChip(capturedCmd);
InputBox.Focus();
}
};
}
SlashItems.Items.Add(item4);
}
if (num < count)
{
SlashNavDown.Visibility = Visibility.Visible;
SlashNavDownText.Text = $"?? ?꾨옒濡?{count - num}媛?;
}
else
{
SlashNavDown.Visibility = Visibility.Collapsed;
}
}
private void SlashPopup_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
{
e.Handled = true;
SlashPopup_ScrollByDelta(e.Delta);
}
private void SlashPopup_ScrollByDelta(int delta)
{
if (_slashAllMatches.Count == 0)
{
return;
}
int num = Math.Min(SlashPageSize, _slashAllMatches.Count - _slashPageOffset);
if (delta > 0)
{
if (_slashSelectedIndex > 0)
{
_slashSelectedIndex--;
}
else if (_slashSelectedIndex == 0 && _slashPageOffset > 0)
{
_slashPageOffset = Math.Max(0, _slashPageOffset - 1);
_slashSelectedIndex = 0;
}
}
else if (_slashSelectedIndex < 0)
{
_slashSelectedIndex = 0;
}
else if (_slashSelectedIndex < num - 1)
{
_slashSelectedIndex++;
}
else if (_slashPageOffset + SlashPageSize < _slashAllMatches.Count)
{
_slashPageOffset++;
_slashSelectedIndex = Math.Min(SlashPageSize - 1, _slashAllMatches.Count - _slashPageOffset - 1);
}
RenderSlashPage();
}
private void ExecuteSlashSelectedItem()
{
int num = _slashPageOffset + _slashSelectedIndex;
if (num < 0 || num >= _slashAllMatches.Count)
{
return;
}
(string Cmd, string Label, bool IsSkill) tuple = _slashAllMatches[num];
string item = tuple.Cmd;
SkillDefinition skillDefinition = (tuple.IsSkill ? SkillService.Find(item.TrimStart('/')) : null);
if (skillDefinition == null || skillDefinition.IsAvailable)
{
SlashPopup.IsOpen = false;
_slashSelectedIndex = -1;
if (item.Equals("/help", StringComparison.OrdinalIgnoreCase))
{
InputBox.Text = "";
ShowSlashHelpWindow();
}
else
{
ShowSlashChip(item);
InputBox.Focus();
}
}
}
private void ToggleSlashFavorite(string cmd)
{
List<string> favoriteSlashCommands = _settings.Settings.Llm.FavoriteSlashCommands;
string text = favoriteSlashCommands.FirstOrDefault((string f) => f.Equals(cmd, StringComparison.OrdinalIgnoreCase));
if (text != null)
{
favoriteSlashCommands.Remove(text);
}
else
{
favoriteSlashCommands.Add(cmd);
}
_settings.Save();
string text2 = InputBox.Text;
InputBox.TextChanged -= InputBox_TextChanged;
InputBox.Text = "";
InputBox.TextChanged += InputBox_TextChanged;
InputBox.Text = text2;
}
private void ShowSlashChip(string cmd)
{
_activeSlashCmd = cmd;
SlashChipText.Text = cmd;
SlashCommandChip.Visibility = Visibility.Visible;
SlashCommandChip.UpdateLayout();
double left = SlashCommandChip.Margin.Left + SlashCommandChip.ActualWidth + 6.0;
InputBox.Padding = new Thickness(left, 10.0, 14.0, 10.0);
InputBox.Text = "";
UpdateDraftPreviewCard();
}
private void HideSlashChip(bool restoreText = false)
{
if (_activeSlashCmd != null)
{
string activeSlashCmd = _activeSlashCmd;
_activeSlashCmd = null;
SlashCommandChip.Visibility = Visibility.Collapsed;
InputBox.Padding = new Thickness(14.0, 10.0, 14.0, 10.0);
if (restoreText)
{
InputBox.Text = activeSlashCmd + " ";
InputBox.CaretIndex = InputBox.Text.Length;
}
UpdateDraftPreviewCard();
}
}
private static (string? slashSystem, string userText) ParseSlashCommand(string input)
{
foreach (KeyValuePair<string, (string, string, string)> slashCommand in SlashCommands)
{
slashCommand.Deconstruct(out var key, out var value);
(string, string, string) tuple = value;
string text = key;
string item = tuple.Item2;
if (input.StartsWith(text, StringComparison.OrdinalIgnoreCase))
{
if (item == "__HELP__")
{
return (slashSystem: null, userText: input);
}
key = input;
int length = text.Length;
string text2 = key.Substring(length, key.Length - length).Trim();
return (slashSystem: item, userText: string.IsNullOrEmpty(text2) ? text : text2);
}
}
foreach (SkillDefinition skill in SkillService.Skills)
{
string text3 = "/" + skill.Name;
if (input.StartsWith(text3, StringComparison.OrdinalIgnoreCase))
{
string key = input;
int length = text3.Length;
string text4 = key.Substring(length, key.Length - length).Trim();
return (slashSystem: skill.SystemPrompt, userText: string.IsNullOrEmpty(text4) ? skill.Label : text4);
}
}
return (slashSystem: null, userText: input);
}
private void ShowDropActionMenu(string[] files)
{
string item = System.IO.Path.GetExtension(files[0]).ToLowerInvariant();
List<(string, string, string)> list = CollectionExtensions.GetValueOrDefault(key: CodeExtensions.Contains(item) ? "code" : (DataExtensions.Contains(item) ? "data" : ((!ImageExtensions.Contains(item)) ? "document" : "image")), dictionary: DropActions) ?? DropActions["document"];
Popup? dropActionPopup = _dropActionPopup;
if (dropActionPopup != null)
{
((DependencyObject)dropActionPopup).SetValue(Popup.IsOpenProperty, (object)false);
}
StackPanel stackPanel = new StackPanel();
TextBlock textBlock = new TextBlock();
textBlock.Text = "\ud83d\udcce " + System.IO.Path.GetFileName(files[0]) + ((files.Length > 1) ? $" ??{files.Length - 1}媛? : "");
textBlock.FontSize = 11.0;
textBlock.Foreground = (TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
textBlock.Margin = new Thickness(12.0, 8.0, 12.0, 6.0);
TextBlock element = textBlock;
stackPanel.Children.Add(element);
System.Windows.Media.Brush hoverBrush = (TryFindResource("ItemHoverBackground") as System.Windows.Media.Brush) ?? new SolidColorBrush(System.Windows.Media.Color.FromArgb(24, byte.MaxValue, byte.MaxValue, byte.MaxValue));
System.Windows.Media.Brush foreground = (TryFindResource("AccentColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Blue;
System.Windows.Media.Brush foreground2 = (TryFindResource("PrimaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.White;
foreach (var item5 in list)
{
string item2 = item5.Item1;
string item3 = item5.Item2;
string item4 = item5.Item3;
string capturedPrompt = item4;
Border row = new Border
{
Background = System.Windows.Media.Brushes.Transparent,
CornerRadius = new CornerRadius(6.0),
Padding = new Thickness(12.0, 7.0, 12.0, 7.0),
Margin = new Thickness(4.0, 1.0, 4.0, 1.0),
Cursor = System.Windows.Input.Cursors.Hand
};
StackPanel stackPanel2 = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal
};
stackPanel2.Children.Add(new TextBlock
{
Text = item3,
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 13.0,
Foreground = foreground,
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(0.0, 0.0, 8.0, 0.0)
});
stackPanel2.Children.Add(new TextBlock
{
Text = item2,
FontSize = 13.0,
FontWeight = FontWeights.SemiBold,
Foreground = foreground2,
VerticalAlignment = VerticalAlignment.Center
});
row.Child = stackPanel2;
row.MouseEnter += delegate
{
row.Background = hoverBrush;
};
row.MouseLeave += delegate
{
row.Background = System.Windows.Media.Brushes.Transparent;
};
row.MouseLeftButtonUp += delegate
{
if (_dropActionPopup != null)
{
_dropActionPopup.IsOpen = false;
}
string[] array = files;
foreach (string filePath in array)
{
AddAttachedFile(filePath);
}
InputBox.Text = capturedPrompt;
InputBox.CaretIndex = InputBox.Text.Length;
InputBox.Focus();
if (_settings.Settings.Llm.DragDropAutoSend)
{
SendMessageAsync();
}
};
stackPanel.Children.Add(row);
}
Border attachOnly = new Border
{
Background = System.Windows.Media.Brushes.Transparent,
CornerRadius = new CornerRadius(6.0),
Padding = new Thickness(12.0, 7.0, 12.0, 7.0),
Margin = new Thickness(4.0, 1.0, 4.0, 1.0),
Cursor = System.Windows.Input.Cursors.Hand
};
StackPanel stackPanel3 = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal
};
stackPanel3.Children.Add(new TextBlock
{
Text = "\ue723",
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 13.0,
Foreground = ((TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray),
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(0.0, 0.0, 8.0, 0.0)
});
stackPanel3.Children.Add(new TextBlock
{
Text = "泥⑤?留?,
FontSize = 13.0,
Foreground = ((TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray),
VerticalAlignment = VerticalAlignment.Center
});
attachOnly.Child = stackPanel3;
attachOnly.MouseEnter += delegate
{
attachOnly.Background = hoverBrush;
};
attachOnly.MouseLeave += delegate
{
attachOnly.Background = System.Windows.Media.Brushes.Transparent;
};
attachOnly.MouseLeftButtonUp += delegate
{
if (_dropActionPopup != null)
{
_dropActionPopup.IsOpen = false;
}
string[] array = files;
foreach (string filePath in array)
{
AddAttachedFile(filePath);
}
InputBox.Focus();
};
stackPanel.Children.Add(attachOnly);
Border border = new Border();
border.Background = (TryFindResource("LauncherBackground") as System.Windows.Media.Brush) ?? new SolidColorBrush(System.Windows.Media.Color.FromRgb(26, 27, 46));
border.CornerRadius = new CornerRadius(12.0);
border.BorderBrush = (TryFindResource("BorderColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
border.BorderThickness = new Thickness(1.0);
border.Padding = new Thickness(4.0, 4.0, 4.0, 6.0);
border.Child = stackPanel;
border.MinWidth = 200.0;
border.Effect = new DropShadowEffect
{
Color = Colors.Black,
BlurRadius = 16.0,
ShadowDepth = 4.0,
Opacity = 0.3
};
Border child = border;
_dropActionPopup = new Popup
{
PlacementTarget = InputBorder,
Placement = PlacementMode.Top,
StaysOpen = false,
AllowsTransparency = true,
PopupAnimation = PopupAnimation.Fade,
Child = child
};
_dropActionPopup.IsOpen = true;
}
private void ShowSlashHelpWindow()
{
//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
//IL_0303: Unknown result type (might be due to invalid IL or missing references)
System.Windows.Media.Brush background = (TryFindResource("LauncherBackground") as System.Windows.Media.Brush) ?? new SolidColorBrush(System.Windows.Media.Color.FromRgb(26, 27, 46));
System.Windows.Media.Brush brush = (TryFindResource("PrimaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.White;
System.Windows.Media.Brush brush2 = (TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
System.Windows.Media.Brush accent = (TryFindResource("AccentColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Blue;
System.Windows.Media.Brush itemBg = (TryFindResource("ItemBackground") as System.Windows.Media.Brush) ?? new SolidColorBrush(System.Windows.Media.Color.FromArgb(30, byte.MaxValue, byte.MaxValue, byte.MaxValue));
System.Windows.Media.Brush hoverBg = (TryFindResource("ItemHoverBackground") as System.Windows.Media.Brush) ?? new SolidColorBrush(System.Windows.Media.Color.FromArgb(40, byte.MaxValue, byte.MaxValue, byte.MaxValue));
Window win = new Window
{
Title = "AX Agent ???щ옒??紐낅졊???꾩?留?,
Width = 560.0,
Height = 640.0,
MinWidth = 440.0,
MinHeight = 500.0,
WindowStyle = WindowStyle.None,
AllowsTransparency = true,
Background = System.Windows.Media.Brushes.Transparent,
ResizeMode = ResizeMode.CanResize,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
Owner = this,
Icon = base.Icon
};
Border border = new Border();
border.Background = background;
border.CornerRadius = new CornerRadius(16.0);
border.BorderBrush = (TryFindResource("BorderColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
border.BorderThickness = new Thickness(1.0);
border.Margin = new Thickness(10.0);
border.Effect = new DropShadowEffect
{
Color = Colors.Black,
BlurRadius = 20.0,
ShadowDepth = 4.0,
Opacity = 0.3
};
Border border2 = border;
Grid grid = new Grid();
grid.RowDefinitions.Add(new RowDefinition
{
Height = new GridLength(52.0)
});
grid.RowDefinitions.Add(new RowDefinition
{
Height = new GridLength(1.0, GridUnitType.Star)
});
Border border3 = new Border
{
CornerRadius = new CornerRadius(16.0, 16.0, 0.0, 0.0),
Background = new LinearGradientBrush(System.Windows.Media.Color.FromRgb(26, 27, 46), System.Windows.Media.Color.FromRgb(59, 78, 204), new Point(0.0, 0.0), new Point(1.0, 1.0)),
Padding = new Thickness(20.0, 0.0, 20.0, 0.0)
};
Grid grid2 = new Grid();
StackPanel stackPanel = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal,
VerticalAlignment = VerticalAlignment.Center
};
stackPanel.Children.Add(new TextBlock
{
Text = "\ue946",
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 16.0,
Foreground = System.Windows.Media.Brushes.LightCyan,
Margin = new Thickness(0.0, 0.0, 10.0, 0.0),
VerticalAlignment = VerticalAlignment.Center
});
stackPanel.Children.Add(new TextBlock
{
Text = "?щ옒??紐낅졊??(/ Commands)",
FontSize = 15.0,
FontWeight = FontWeights.SemiBold,
Foreground = System.Windows.Media.Brushes.White,
VerticalAlignment = VerticalAlignment.Center
});
grid2.Children.Add(stackPanel);
Border closeBtn = new Border
{
Width = 30.0,
Height = 30.0,
CornerRadius = new CornerRadius(8.0),
Background = System.Windows.Media.Brushes.Transparent,
Cursor = System.Windows.Input.Cursors.Hand,
HorizontalAlignment = System.Windows.HorizontalAlignment.Right,
VerticalAlignment = VerticalAlignment.Center
};
closeBtn.Child = new TextBlock
{
Text = "\ue711",
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 11.0,
Foreground = new SolidColorBrush(System.Windows.Media.Color.FromArgb(136, 170, byte.MaxValue, 204)),
HorizontalAlignment = System.Windows.HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
closeBtn.MouseEnter += delegate
{
closeBtn.Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(34, byte.MaxValue, byte.MaxValue, byte.MaxValue));
};
closeBtn.MouseLeave += delegate
{
closeBtn.Background = System.Windows.Media.Brushes.Transparent;
};
closeBtn.MouseLeftButtonDown += delegate(object _, MouseButtonEventArgs me)
{
me.Handled = true;
win.Close();
};
grid2.Children.Add(closeBtn);
border3.Child = grid2;
Grid.SetRow(border3, 0);
grid.Children.Add(border3);
ScrollViewer scrollViewer = new ScrollViewer
{
VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
Padding = new Thickness(20.0, 14.0, 20.0, 20.0)
};
StackPanel stackPanel2 = new StackPanel();
stackPanel2.Children.Add(new TextBlock
{
Text = "?낅젰李쎌뿉 /瑜??낅젰?섎㈃ ?ъ슜?????덈뒗 紐낅졊?닿? ?쒖떆?⑸땲??\n紐낅졊?대? ?좏깮?????댁슜???낅젰?섎㈃ ?대떦 湲곕뒫???곸슜?⑸땲??",
FontSize = 12.0,
Foreground = brush2,
TextWrapping = TextWrapping.Wrap,
Margin = new Thickness(0.0, 0.0, 0.0, 16.0),
LineHeight = 20.0
});
AddHelpSection(stackPanel2, "\ud83d\udccc 怨듯넻 紐낅졊??, "紐⑤뱺 ??Chat, Cowork, Code)?먯꽌 ?ъ슜 媛€??, brush, brush2, accent, itemBg, hoverBg, ("/summary", "?띿뒪??臾몄꽌瑜??듭떖 ?ъ씤??以묒떖?쇰줈 ?붿빟?⑸땲??"), ("/translate", "?띿뒪?몃? ?곸뼱濡?踰덉뿭?⑸땲?? ?먮Ц???ㅼ쓣 ?좎??⑸땲??"), ("/explain", "?댁슜???쎄퀬 ?먯꽭?섍쾶 ?ㅻ챸?⑸땲?? ?덉떆瑜??ы븿?⑸땲??"), ("/fix", "留욎땄踰? 臾몃쾿, ?먯뿰?ㅻ윭???쒗쁽??援먯젙?⑸땲??"));
AddHelpSection(stackPanel2, "\ud83d\udee0\ufe0f 媛쒕컻 紐낅졊??, "Cowork, Code ??뿉?쒕쭔 ?ъ슜 媛€??, brush, brush2, accent, itemBg, hoverBg, ("/review", "Git diff瑜?遺꾩꽍?섏뿬 踰꾧렇, ?깅뒫, 蹂댁븞 ?댁뒋瑜?李얠뒿?덈떎."), ("/pr", "蹂€寃쎌궗??쓣 PR ?ㅻ챸 ?뺤떇(Summary, Changes, Test Plan)?쇰줈 ?붿빟?⑸땲??"), ("/test", "肄붾뱶???€???⑥쐞 ?뚯뒪?몃? ?먮룞 ?앹꽦?⑸땲??"), ("/structure", "?꾨줈?앺듃???대뜑/?뚯씪 援ъ“瑜?遺꾩꽍?섍퀬 ?ㅻ챸?⑸땲??"), ("/build", "?꾨줈?앺듃瑜?鍮뚮뱶?⑸땲?? ?ㅻ쪟 諛쒖깮 ??遺꾩꽍?⑸땲??"), ("/search", "?먯뿰?대줈 肄붾뱶踰좎씠?ㅻ? ?쒕㎤??寃€?됲빀?덈떎."));
IReadOnlyList<SkillDefinition> skills = SkillService.Skills;
if (skills.Count > 0)
{
(string, string)[] items = skills.Select((SkillDefinition s) => ("/" + s.Name, Description: s.Description)).ToArray();
AddHelpSection(stackPanel2, "???ㅽ궗 紐낅졊??, $"{skills.Count}媛?濡쒕뱶????%APPDATA%\\AxCopilot\\skills\\?먯꽌 異붽? 媛€??, brush, brush2, accent, itemBg, hoverBg, items);
}
stackPanel2.Children.Add(new Border
{
Height = 1.0,
Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(30, byte.MaxValue, byte.MaxValue, byte.MaxValue)),
Margin = new Thickness(0.0, 12.0, 0.0, 12.0)
});
StackPanel stackPanel3 = new StackPanel();
stackPanel3.Children.Add(new TextBlock
{
Text = "\ud83d\udca1 ?ъ슜 ??,
FontSize = 13.0,
FontWeight = FontWeights.SemiBold,
Foreground = brush,
Margin = new Thickness(0.0, 0.0, 0.0, 8.0)
});
string[] array = new string[4] { "/ ?낅젰 ???꾩옱 ??뿉 留욌뒗 紐낅졊?대쭔 ?먮룞?꾩꽦?⑸땲??", "?뚯씪???쒕옒洹명븯硫??좏삎蹂?AI ?≪뀡 ?앹뾽???섑??⑸땲??", "?ㅽ궗 ?뚯씪(*.skill.md)??異붽??섎㈃ ?섎쭔???뚰겕?뚮줈?곕? 留뚮뱾 ???덉뒿?덈떎.", "Cowork/Code ??뿉???먯씠?꾪듃媛€ ?꾧뎄瑜??쒖슜?섏뿬 ??媛뺣젰???묒뾽???섑뻾?⑸땲??" };
string[] array2 = array;
foreach (string text in array2)
{
stackPanel3.Children.Add(new TextBlock
{
Text = "??" + text,
FontSize = 12.0,
Foreground = brush2,
Margin = new Thickness(8.0, 2.0, 0.0, 2.0),
TextWrapping = TextWrapping.Wrap,
LineHeight = 18.0
});
}
stackPanel2.Children.Add(stackPanel3);
scrollViewer.Content = stackPanel2;
Grid.SetRow(scrollViewer, 1);
grid.Children.Add(scrollViewer);
border2.Child = grid;
win.Content = border2;
border3.MouseLeftButtonDown += delegate
{
try
{
win.DragMove();
}
catch
{
}
};
win.ShowDialog();
}
private static void AddHelpSection(StackPanel parent, string title, string subtitle, System.Windows.Media.Brush fg, System.Windows.Media.Brush fg2, System.Windows.Media.Brush accent, System.Windows.Media.Brush itemBg, System.Windows.Media.Brush hoverBg, params (string Cmd, string Desc)[] items)
{
parent.Children.Add(new TextBlock
{
Text = title,
FontSize = 14.0,
FontWeight = FontWeights.SemiBold,
Foreground = fg,
Margin = new Thickness(0.0, 8.0, 0.0, 2.0)
});
parent.Children.Add(new TextBlock
{
Text = subtitle,
FontSize = 11.0,
Foreground = fg2,
Margin = new Thickness(0.0, 0.0, 0.0, 8.0)
});
for (int i = 0; i < items.Length; i++)
{
(string Cmd, string Desc) tuple = items[i];
string item = tuple.Cmd;
string item2 = tuple.Desc;
Border row = new Border
{
Background = itemBg,
CornerRadius = new CornerRadius(8.0),
Padding = new Thickness(12.0, 8.0, 12.0, 8.0),
Margin = new Thickness(0.0, 3.0, 0.0, 3.0)
};
Grid grid = new Grid();
grid.ColumnDefinitions.Add(new ColumnDefinition
{
Width = new GridLength(120.0)
});
grid.ColumnDefinitions.Add(new ColumnDefinition
{
Width = new GridLength(1.0, GridUnitType.Star)
});
TextBlock element = new TextBlock
{
Text = item,
FontSize = 13.0,
FontWeight = FontWeights.SemiBold,
Foreground = accent,
VerticalAlignment = VerticalAlignment.Center,
FontFamily = new System.Windows.Media.FontFamily("Consolas")
};
Grid.SetColumn(element, 0);
grid.Children.Add(element);
TextBlock element2 = new TextBlock
{
Text = item2,
FontSize = 12.0,
Foreground = fg2,
VerticalAlignment = VerticalAlignment.Center,
TextWrapping = TextWrapping.Wrap
};
Grid.SetColumn(element2, 1);
grid.Children.Add(element2);
row.Child = grid;
row.MouseEnter += delegate
{
row.Background = hoverBg;
};
row.MouseLeave += delegate
{
row.Background = itemBg;
};
parent.Children.Add(row);
}
}
private async Task SendMessageAsync()
{
string rawText = InputBox.Text.Trim();
string text = ((_activeSlashCmd != null) ? (_activeSlashCmd + " " + rawText).Trim() : rawText);
HideSlashChip();
if (string.IsNullOrEmpty(text) || _isStreaming)
{
return;
}
ClearPromptCardPlaceholder();
(string, string) tuple = ParseSlashCommand(text);
var (slashSystem, _) = tuple;
_ = tuple.Item2;
string originTab = _activeTab;
ChatConversation conv;
lock (_convLock)
{
if (_currentConversation == null)
{
_currentConversation = new ChatConversation
{
Tab = _activeTab
};
}
conv = _currentConversation;
}
ChatMessage userMsg = new ChatMessage
{
Role = "user",
Content = text
};
lock (_convLock)
{
conv.Messages.Add(userMsg);
}
if (conv.Messages.Count((ChatMessage m) => m.Role == "user") == 1)
{
conv.Title = ((text.Length > 30) ? (text.Substring(0, 30) + "??) : text);
}
UpdateChatTitle();
AddMessageBubble("user", text);
InputBox.Text = "";
EmptyState.Visibility = Visibility.Collapsed;
UsageStatisticsService.RecordChat(_activeTab);
ForceScrollToEnd();
PlayRainbowGlow();
_isStreaming = true;
BtnSend.IsEnabled = false;
BtnSend.Visibility = Visibility.Collapsed;
BtnStop.Visibility = Visibility.Visible;
if (_activeTab == "Cowork" || _activeTab == "Code")
{
BtnPause.Visibility = Visibility.Visible;
}
_streamCts = new CancellationTokenSource();
ChatMessage assistantMsg = new ChatMessage
{
Role = "assistant",
Content = ""
};
lock (_convLock)
{
conv.Messages.Add(assistantMsg);
}
TextBlock streamText;
StackPanel streamContainer = CreateStreamingContainer(out streamText);
MessagePanel.Children.Add(streamContainer);
ForceScrollToEnd();
StringBuilder sb = new StringBuilder();
_activeStreamText = streamText;
_cachedStreamContent = "";
_displayedLength = 0;
_cursorVisible = true;
_aiIconPulseStopped = false;
_cursorTimer.Start();
_typingTimer.Start();
_streamStartTime = DateTime.UtcNow;
_elapsedTimer.Start();
SetStatus("?묐떟 ?앹꽦 以?..", spinning: true);
ModelRouteResult routeResult = null;
bool queueContinuationAllowed = true;
try
{
List<ChatMessage> sendMessages;
lock (_convLock)
{
sendMessages = conv.Messages.SkipLast(1).ToList();
}
if (!string.IsNullOrEmpty(conv.SystemCommand))
{
sendMessages.Insert(0, new ChatMessage
{
Role = "system",
Content = conv.SystemCommand
});
}
if (!string.IsNullOrEmpty(slashSystem))
{
sendMessages.Insert(0, new ChatMessage
{
Role = "system",
Content = slashSystem
});
}
if (_attachedFiles.Count > 0)
{
string fileContext = BuildFileContextPrompt();
if (!string.IsNullOrEmpty(fileContext))
{
int lastUserIdx = sendMessages.FindLastIndex((ChatMessage m) => m.Role == "user");
if (lastUserIdx >= 0)
{
sendMessages[lastUserIdx] = new ChatMessage
{
Role = "user",
Content = sendMessages[lastUserIdx].Content + fileContext
};
}
}
userMsg.AttachedFiles = _attachedFiles.ToList();
_attachedFiles.Clear();
RefreshAttachedFilesUI();
}
if (_pendingImages.Count > 0)
{
userMsg.Images = _pendingImages.ToList();
int lastUserIdx2 = sendMessages.FindLastIndex((ChatMessage m) => m.Role == "user");
if (lastUserIdx2 >= 0)
{
sendMessages[lastUserIdx2] = new ChatMessage
{
Role = "user",
Content = sendMessages[lastUserIdx2].Content,
Images = _pendingImages.ToList()
};
}
_pendingImages.Clear();
AttachedFilesPanel.Items.Clear();
if (_attachedFiles.Count == 0)
{
AttachedFilesPanel.Visibility = Visibility.Collapsed;
}
}
if (_settings.Settings.Llm.EnableAutoRouter)
{
routeResult = _router.Route(text);
if (routeResult != null)
{
_llm.PushRouteOverride(routeResult.Service, routeResult.Model);
SetStatus("?쇱슦?? " + routeResult.DetectedIntent + " ??" + routeResult.DisplayName, spinning: true);
}
}
if (_activeTab == "Cowork")
{
OpenWorkflowAnalyzerIfEnabled();
_agentCumulativeInputTokens = 0;
_agentCumulativeOutputTokens = 0;
_agentLoop.EventOccurred += OnAgentEvent;
_agentLoop.UserDecisionCallback = CreatePlanDecisionCallback();
try
{
string coworkSystem = BuildCoworkSystemPrompt();
if (!string.IsNullOrEmpty(coworkSystem))
{
sendMessages.Insert(0, new ChatMessage
{
Role = "system",
Content = coworkSystem
});
}
_agentLoop.ActiveTab = _activeTab;
string response = await _agentLoop.RunAsync(sendMessages, _streamCts.Token);
sb.Append(response);
assistantMsg.Content = response;
StopAiIconPulse();
_cachedStreamContent = response;
if (_settings.Settings.Llm.NotifyOnComplete)
{
NotificationService.Notify("AX Cowork Agent", "肄붿썙???묒뾽???꾨즺?섏뿀?듬땲??");
}
}
finally
{
_agentLoop.EventOccurred -= OnAgentEvent;
_agentLoop.UserDecisionCallback = null;
}
}
else if (_activeTab == "Code")
{
OpenWorkflowAnalyzerIfEnabled();
_agentCumulativeInputTokens = 0;
_agentCumulativeOutputTokens = 0;
_agentLoop.EventOccurred += OnAgentEvent;
_agentLoop.UserDecisionCallback = CreatePlanDecisionCallback();
try
{
string codeSystem = BuildCodeSystemPrompt();
if (!string.IsNullOrEmpty(codeSystem))
{
sendMessages.Insert(0, new ChatMessage
{
Role = "system",
Content = codeSystem
});
}
_agentLoop.ActiveTab = "Code";
string response2 = await _agentLoop.RunAsync(sendMessages, _streamCts.Token);
sb.Append(response2);
assistantMsg.Content = response2;
StopAiIconPulse();
_cachedStreamContent = response2;
if (_settings.Settings.Llm.NotifyOnComplete)
{
NotificationService.Notify("AX Code Agent", "肄붾뱶 ?묒뾽???꾨즺?섏뿀?듬땲??");
}
}
finally
{
_agentLoop.EventOccurred -= OnAgentEvent;
_agentLoop.UserDecisionCallback = null;
}
}
else if (_settings.Settings.Llm.Streaming)
{
await foreach (string chunk in _llm.StreamAsync(sendMessages, _streamCts.Token))
{
sb.Append(chunk);
StopAiIconPulse();
_cachedStreamContent = sb.ToString();
await ((DispatcherObject)this).Dispatcher.InvokeAsync((Action)delegate
{
}, (DispatcherPriority)4);
}
_cachedStreamContent = sb.ToString();
assistantMsg.Content = _cachedStreamContent;
DateTime drainStart = DateTime.UtcNow;
while (_displayedLength < _cachedStreamContent.Length && (DateTime.UtcNow - drainStart).TotalMilliseconds < 600.0)
{
await ((DispatcherObject)this).Dispatcher.InvokeAsync((Action)delegate
{
}, (DispatcherPriority)4);
}
}
else
{
string response3 = await _llm.SendAsync(sendMessages, _streamCts.Token);
sb.Append(response3);
assistantMsg.Content = response3;
}
}
catch (OperationCanceledException)
{
if (sb.Length == 0)
{
sb.Append("(痍⑥냼??");
}
queueContinuationAllowed = false;
assistantMsg.Content = sb.ToString();
}
catch (Exception ex2)
{
Exception ex3 = ex2;
string errMsg = "???ㅻ쪟: " + ex3.Message;
sb.Clear();
sb.Append(errMsg);
queueContinuationAllowed = false;
assistantMsg.Content = errMsg;
AddRetryButton();
}
finally
{
if (routeResult != null)
{
_llm.ClearRouteOverride();
UpdateModelLabel();
}
_cursorTimer.Stop();
_elapsedTimer.Stop();
_typingTimer.Stop();
HideStickyProgress();
StopRainbowGlow();
_activeStreamText = null;
_elapsedLabel = null;
_cachedStreamContent = "";
_isStreaming = false;
BtnSend.IsEnabled = true;
BtnStop.Visibility = Visibility.Collapsed;
BtnSend.Visibility = Visibility.Visible;
_streamCts?.Dispose();
_streamCts = null;
SetStatusIdle();
}
FinalizeStreamingContainer(streamContainer, streamText, assistantMsg.Content, assistantMsg);
AutoScrollIfNeeded();
try
{
_storage.Save(conv);
}
catch (Exception ex4)
{
LogService.Debug("?€???€???ㅽ뙣: " + ex4.Message);
}
_tabConversationId[originTab] = conv.Id;
RefreshConversationList();
if (queueContinuationAllowed)
{
StartNextQueuedDraftIfAny();
}
}
private string BuildCoworkSystemPrompt()
{
string currentWorkFolder = GetCurrentWorkFolder();
LlmSettings llm = _settings.Settings.Llm;
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("You are AX Copilot Agent. You can read, write, and edit files using the provided tools.");
StringBuilder stringBuilder2 = stringBuilder;
StringBuilder stringBuilder3 = stringBuilder2;
StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(20, 3, stringBuilder2);
handler.AppendLiteral("Today's date: ");
handler.AppendFormatted(DateTime.Now, "yyyy??M??d??);
handler.AppendLiteral(" (");
handler.AppendFormatted(DateTime.Now, "yyyy-MM-dd");
handler.AppendLiteral(", ");
handler.AppendFormatted(DateTime.Now, "dddd");
handler.AppendLiteral(").");
stringBuilder3.AppendLine(ref handler);
stringBuilder.AppendLine("Available skills: excel_create (.xlsx), docx_create (.docx), csv_create (.csv), markdown_create (.md), html_create (.html), script_create (.bat/.ps1), document_review (?덉쭏 寃€利?, format_convert (?щ㎎ 蹂€??.");
stringBuilder.AppendLine("Parallel tools: spawn_agent, wait_agents. Use them for independent side research, codebase inspection, or document evidence gathering.");
stringBuilder.AppendLine("Always explain your plan step by step BEFORE executing tools. After creating files, summarize what was created.");
stringBuilder.AppendLine("IMPORTANT: When creating documents with dates, always use today's actual date above. Never use placeholder or fictional dates.");
stringBuilder.AppendLine("IMPORTANT: When asked to create a document with multiple sections (reports, proposals, analyses, etc.), you MUST:");
stringBuilder.AppendLine(" 1. First, plan the document: decide the exact sections (headings), their order, and key points for each section based on the topic.");
stringBuilder.AppendLine(" 2. Call document_plan with sections_hint = your planned section titles (comma-separated). Example: sections_hint=\"?뚯궗 媛쒖슂, ?ъ뾽 ?꾪솴, ?щТ 遺꾩꽍, SWOT, ?꾨왂 ?쒖뼵, 寃곕줎\"");
stringBuilder.AppendLine(" This ensures the document structure matches YOUR plan, not a generic template.");
stringBuilder.AppendLine(" 3. Then immediately call html_create (or docx_create/file_write) using the scaffold from document_plan.");
stringBuilder.AppendLine(" 4. Write actual detailed content for EVERY section ??no skipping, no placeholders, no minimal content.");
stringBuilder.AppendLine(" 5. Do NOT call html_create directly without document_plan for multi-section documents.");
stringBuilder.AppendLine("\n## Document Quality Review");
stringBuilder.AppendLine("After creating any document (html_create, docx_create, excel_create, etc.), you MUST perform a self-review:");
stringBuilder.AppendLine("1. Use file_read to read the generated file and verify the content is complete");
stringBuilder.AppendLine("2. Check for logical errors: incorrect dates, inconsistent data, missing sections, broken formatting");
stringBuilder.AppendLine("3. Verify all requested topics/sections from the user's original request are covered");
stringBuilder.AppendLine("4. If issues found, fix them using file_write or file_edit, then re-verify");
stringBuilder.AppendLine("5. Report the review result to the user: what was checked and whether corrections were made");
stringBuilder.Append(BuildSubAgentGuidanceSection(isCodeAgent: false));
stringBuilder.AppendLine("\n## Format Conversion");
stringBuilder.AppendLine("When the user requests format conversion (e.g., HTML?뭌ord, Excel?묬SV, Markdown?묱TML):");
stringBuilder.AppendLine("1. Use file_read or document_read to read the source file content");
stringBuilder.AppendLine("2. Create a new file in the target format using the appropriate skill (docx_create, html_create, etc.)");
stringBuilder.AppendLine("3. Preserve the content structure, formatting, and data as closely as possible");
string defaultOutputFormat = llm.DefaultOutputFormat;
if (!string.IsNullOrEmpty(defaultOutputFormat) && defaultOutputFormat != "auto")
{
Dictionary<string, string> dictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
["xlsx"] = "Excel (.xlsx) using excel_create",
["docx"] = "Word (.docx) using docx_create",
["html"] = "HTML (.html) using html_create",
["md"] = "Markdown (.md) using markdown_create",
["csv"] = "CSV (.csv) using csv_create"
};
if (dictionary.TryGetValue(defaultOutputFormat, out var value))
{
stringBuilder2 = stringBuilder;
StringBuilder stringBuilder4 = stringBuilder2;
handler = new StringBuilder.AppendInterpolatedStringHandler(93, 1, stringBuilder2);
handler.AppendLiteral("IMPORTANT: User prefers output format: ");
handler.AppendFormatted(value);
handler.AppendLiteral(". Use this format unless the user specifies otherwise.");
stringBuilder4.AppendLine(ref handler);
}
}
if (!string.IsNullOrEmpty(_selectedMood) && _selectedMood != "modern")
{
stringBuilder2 = stringBuilder;
StringBuilder stringBuilder5 = stringBuilder2;
handler = new StringBuilder.AppendInterpolatedStringHandler(83, 1, stringBuilder2);
handler.AppendLiteral("When creating HTML documents with html_create, use mood=\"");
handler.AppendFormatted(_selectedMood);
handler.AppendLiteral("\" for the design template.");
stringBuilder5.AppendLine(ref handler);
}
else
{
stringBuilder.AppendLine("When creating HTML documents with html_create, you can set 'mood' parameter: modern, professional, creative, minimal, elegant, dark, colorful, corporate, magazine, dashboard.");
}
if (!string.IsNullOrEmpty(currentWorkFolder))
{
stringBuilder2 = stringBuilder;
StringBuilder stringBuilder6 = stringBuilder2;
handler = new StringBuilder.AppendInterpolatedStringHandler(21, 1, stringBuilder2);
handler.AppendLiteral("Current work folder: ");
handler.AppendFormatted(currentWorkFolder);
stringBuilder6.AppendLine(ref handler);
}
stringBuilder2 = stringBuilder;
StringBuilder stringBuilder7 = stringBuilder2;
handler = new StringBuilder.AppendInterpolatedStringHandler(22, 1, stringBuilder2);
handler.AppendLiteral("File permission mode: ");
handler.AppendFormatted(llm.FilePermission);
stringBuilder7.AppendLine(ref handler);
string folderDataUsage = _folderDataUsage;
string text = folderDataUsage;
if (!(text == "active"))
{
if (text == "passive")
{
stringBuilder.AppendLine("Folder Data Usage = PASSIVE. You have 'document_read' and 'folder_map' tools. Only read folder documents when the user explicitly asks you to reference or use them.");
}
else
{
stringBuilder.AppendLine("Folder Data Usage = NONE. Do NOT read or reference documents in the work folder unless the user explicitly provides a file path.");
}
}
else
{
stringBuilder.AppendLine("IMPORTANT: Folder Data Usage = ACTIVE. You have 'document_read' and 'folder_map' tools available.");
stringBuilder.AppendLine("Before creating reports, use folder_map to scan the work folder structure. Then EVALUATE whether each document is RELEVANT to the user's current request topic. Only use document_read on files that are clearly related to the conversation subject. Do NOT read or reference files that are unrelated to the user's request, even if they exist in the folder. In your planning step, list which files you plan to read and explain WHY they are relevant.");
}
lock (_convLock)
{
if (_currentConversation != null && !string.IsNullOrEmpty(_currentConversation.SystemCommand))
{
stringBuilder.AppendLine("\n" + _currentConversation.SystemCommand);
}
}
stringBuilder.Append(LoadProjectContext(currentWorkFolder));
stringBuilder.Append(BuildProjectRulesSection(currentWorkFolder));
stringBuilder.Append(BuildMemorySection(currentWorkFolder));
stringBuilder.Append(BuildFeedbackContext());
return stringBuilder.ToString();
}
private string BuildCodeSystemPrompt()
{
string currentWorkFolder = GetCurrentWorkFolder();
LlmSettings llm = _settings.Settings.Llm;
CodeSettings code = llm.Code;
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("You are AX Copilot Code Agent ??a senior software engineer for enterprise development.");
StringBuilder stringBuilder2 = stringBuilder;
StringBuilder stringBuilder3 = stringBuilder2;
StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(18, 2, stringBuilder2);
handler.AppendLiteral("Today's date: ");
handler.AppendFormatted(DateTime.Now, "yyyy??M??d??);
handler.AppendLiteral(" (");
handler.AppendFormatted(DateTime.Now, "yyyy-MM-dd");
handler.AppendLiteral(").");
stringBuilder3.AppendLine(ref handler);
stringBuilder.AppendLine("Available tools: file_read, file_write, file_edit (supports replace_all), glob, grep (supports context_lines, case_sensitive), folder_map, process, dev_env_detect, build_run, git_tool.");
stringBuilder.AppendLine("Parallel tools: spawn_agent, wait_agents. Use them when side tasks can run independently.");
stringBuilder.AppendLine("IMPORTANT: When creating documents with dates, always use today's actual date above.");
stringBuilder.AppendLine("\n## Core Workflow (MANDATORY ??follow this order)");
stringBuilder.AppendLine("1. ORIENT: Run folder_map (depth=2) to understand project structure. Check .gitignore, README, config files.");
stringBuilder.AppendLine("2. BASELINE: If tests exist, run build_run action='test' FIRST to establish baseline. Record pass/fail count.");
stringBuilder.AppendLine("3. ANALYZE: Use grep (with context_lines=2) + file_read to deeply understand the code you'll modify.");
stringBuilder.AppendLine(" - Always check callers/references: grep for function/class names to find all usage points.");
stringBuilder.AppendLine(" - Read test files related to the code you're changing to understand expected behavior.");
stringBuilder.AppendLine("4. PLAN: Present your analysis + impact assessment. List ALL files that will be modified.");
stringBuilder.AppendLine(" - Explain WHY each change is needed and what could break.");
stringBuilder.AppendLine(" - Wait for user approval before proceeding.");
stringBuilder.AppendLine("5. IMPLEMENT: Apply changes using file_edit (preferred ??shows diff). Use file_write only for new files.");
stringBuilder.AppendLine(" - Make the MINIMUM changes needed. Don't refactor unrelated code.");
stringBuilder.AppendLine(" - Prefer file_edit with replace_all=false for precision edits.");
stringBuilder.AppendLine("6. VERIFY: Run build_run action='build' then action='test'. Compare results with baseline.");
stringBuilder.AppendLine(" - If tests fail that passed before, fix immediately.");
stringBuilder.AppendLine(" - If build fails, analyze error output and correct.");
stringBuilder.AppendLine("7. GIT: Use git_tool to check status, create diff, and optionally commit.");
stringBuilder.AppendLine("8. REPORT: Summarize changes, test results, and any remaining concerns.");
stringBuilder.Append(BuildSubAgentGuidanceSection(isCodeAgent: true));
stringBuilder.AppendLine("\n## Development Environment");
stringBuilder.AppendLine("Use dev_env_detect to check installed IDEs, runtimes, and build tools before running commands.");
stringBuilder.AppendLine("IMPORTANT: Do NOT attempt to install compilers, IDEs, or build tools. Only use what is already installed.");
stringBuilder.AppendLine("\n## Package Repositories");
if (!string.IsNullOrEmpty(code.NexusBaseUrl))
{
stringBuilder2 = stringBuilder;
StringBuilder stringBuilder4 = stringBuilder2;
handler = new StringBuilder.AppendInterpolatedStringHandler(18, 1, stringBuilder2);
handler.AppendLiteral("Enterprise Nexus: ");
handler.AppendFormatted(code.NexusBaseUrl);
stringBuilder4.AppendLine(ref handler);
}
stringBuilder2 = stringBuilder;
StringBuilder stringBuilder5 = stringBuilder2;
handler = new StringBuilder.AppendInterpolatedStringHandler(14, 1, stringBuilder2);
handler.AppendLiteral("NuGet (.NET): ");
handler.AppendFormatted(code.NugetSource);
stringBuilder5.AppendLine(ref handler);
stringBuilder2 = stringBuilder;
StringBuilder stringBuilder6 = stringBuilder2;
handler = new StringBuilder.AppendInterpolatedStringHandler(21, 1, stringBuilder2);
handler.AppendLiteral("PyPI/Conda (Python): ");
handler.AppendFormatted(code.PypiSource);
stringBuilder6.AppendLine(ref handler);
stringBuilder2 = stringBuilder;
StringBuilder stringBuilder7 = stringBuilder2;
handler = new StringBuilder.AppendInterpolatedStringHandler(14, 1, stringBuilder2);
handler.AppendLiteral("Maven (Java): ");
handler.AppendFormatted(code.MavenSource);
stringBuilder7.AppendLine(ref handler);
stringBuilder2 = stringBuilder;
StringBuilder stringBuilder8 = stringBuilder2;
handler = new StringBuilder.AppendInterpolatedStringHandler(18, 1, stringBuilder2);
handler.AppendLiteral("npm (JavaScript): ");
handler.AppendFormatted(code.NpmSource);
stringBuilder8.AppendLine(ref handler);
stringBuilder.AppendLine("When adding dependencies, use these repository URLs.");
if (!string.IsNullOrEmpty(code.PreferredIdePath))
{
stringBuilder2 = stringBuilder;
StringBuilder stringBuilder9 = stringBuilder2;
handler = new StringBuilder.AppendInterpolatedStringHandler(16, 1, stringBuilder2);
handler.AppendLiteral("\nPreferred IDE: ");
handler.AppendFormatted(code.PreferredIdePath);
stringBuilder9.AppendLine(ref handler);
}
if (_selectedLanguage != "auto")
{
string selectedLanguage = _selectedLanguage;
if (1 == 0)
{
}
string text = selectedLanguage switch
{
"python" => "Python",
"java" => "Java",
"csharp" => "C# (.NET)",
"cpp" => "C/C++",
"javascript" => "JavaScript/TypeScript",
_ => _selectedLanguage,
};
if (1 == 0)
{
}
string value = text;
stringBuilder2 = stringBuilder;
StringBuilder stringBuilder10 = stringBuilder2;
handler = new StringBuilder.AppendInterpolatedStringHandler(96, 1, stringBuilder2);
handler.AppendLiteral("\nIMPORTANT: User selected language: ");
handler.AppendFormatted(value);
handler.AppendLiteral(". Prioritize this language for code analysis and generation.");
stringBuilder10.AppendLine(ref handler);
}
stringBuilder.AppendLine("\n## Language Guidelines");
stringBuilder.AppendLine("- C# (.NET): Use dotnet CLI. NuGet for packages. Follow Microsoft naming conventions.");
stringBuilder.AppendLine("- Python: Use conda/pip. Follow PEP8. Use type hints. Virtual env preferred.");
stringBuilder.AppendLine("- Java: Use Maven/Gradle. Follow Google Java Style Guide.");
stringBuilder.AppendLine("- C++: Use CMake for build. Follow C++ Core Guidelines.");
stringBuilder.AppendLine("- JavaScript/TypeScript: Use npm/yarn. Follow ESLint rules. Vue3 uses Composition API.");
stringBuilder.AppendLine("\n## Code Quality & Safety");
stringBuilder.AppendLine("- NEVER delete or overwrite files without user confirmation.");
stringBuilder.AppendLine("- ALWAYS read a file before editing it. Don't guess contents.");
stringBuilder.AppendLine("- Prefer file_edit over file_write for existing files (shows diff).");
stringBuilder.AppendLine("- Use grep to find ALL references before renaming/removing anything.");
stringBuilder.AppendLine("- If unsure about a change's impact, ask the user first.");
stringBuilder.AppendLine("- For large refactors, do them incrementally with build verification between steps.");
stringBuilder.AppendLine("- Use git_tool action='diff' to review your changes before committing.");
stringBuilder.AppendLine("\n## Lint & Format");
stringBuilder.AppendLine("After code changes, check for available linters:");
stringBuilder.AppendLine("- Python: ruff, black, flake8, pylint");
stringBuilder.AppendLine("- JavaScript: eslint, prettier");
stringBuilder.AppendLine("- C#: dotnet format");
stringBuilder.AppendLine("- C++: clang-format");
stringBuilder.AppendLine("Run the appropriate linter via process tool if detected by dev_env_detect.");
if (!string.IsNullOrEmpty(currentWorkFolder))
{
stringBuilder2 = stringBuilder;
StringBuilder stringBuilder11 = stringBuilder2;
handler = new StringBuilder.AppendInterpolatedStringHandler(22, 1, stringBuilder2);
handler.AppendLiteral("\nCurrent work folder: ");
handler.AppendFormatted(currentWorkFolder);
stringBuilder11.AppendLine(ref handler);
}
stringBuilder2 = stringBuilder;
StringBuilder stringBuilder12 = stringBuilder2;
handler = new StringBuilder.AppendInterpolatedStringHandler(22, 1, stringBuilder2);
handler.AppendLiteral("File permission mode: ");
handler.AppendFormatted(llm.FilePermission);
stringBuilder12.AppendLine(ref handler);
stringBuilder.AppendLine("\nFolder Data Usage = ACTIVE. Use folder_map and file_read to understand the codebase.");
stringBuilder.AppendLine("Analyze project structure before making changes. Read relevant files to understand context.");
lock (_convLock)
{
string text2 = _currentConversation?.SystemCommand;
if (text2 != null && text2.Length > 0)
{
stringBuilder.AppendLine("\n" + text2);
}
}
stringBuilder.Append(LoadProjectContext(currentWorkFolder));
stringBuilder.Append(BuildProjectRulesSection(currentWorkFolder));
stringBuilder.Append(BuildMemorySection(currentWorkFolder));
stringBuilder.Append(BuildFeedbackContext());
return stringBuilder.ToString();
}
private string BuildSubAgentGuidanceSection(bool isCodeAgent)
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("\n## Sub-Agent Delegation");
stringBuilder.AppendLine("Use spawn_agent only for bounded side tasks that do not block your immediate next step.");
stringBuilder.AppendLine("Good uses:");
stringBuilder.AppendLine(isCodeAgent ? "- Inspect another module, trace references, review a diff, or summarize a subsystem while you continue main-line analysis." : "- Gather evidence from several files, inspect a side topic, or summarize background material while you continue the main task.");
stringBuilder.AppendLine("- Launch multiple independent read-only investigations in parallel when they answer different questions.");
stringBuilder.AppendLine("Avoid spawn_agent when:");
stringBuilder.AppendLine("- The very next action depends on that result.");
stringBuilder.AppendLine("- The task is tiny and faster to do directly.");
stringBuilder.AppendLine("- The task requires file edits, shell commands, or user interaction.");
stringBuilder.AppendLine("Delegation rules:");
stringBuilder.AppendLine("- Give each sub-agent a concrete task and unique id.");
stringBuilder.AppendLine("- Keep the prompt self-contained: mention target files, folders, functions, or the exact question.");
stringBuilder.AppendLine("- After launching sub-agents, continue non-overlapping work locally.");
stringBuilder.AppendLine("- Use wait_agents(ids:[...]) when you need specific results now.");
stringBuilder.AppendLine("- Use wait_agents(completed_only=true) to collect finished background results without blocking.");
stringBuilder.AppendLine("- When a sub-agent returns, integrate only the relevant findings into your final answer.");
return stringBuilder.ToString();
}
private string BuildProjectRulesSection(string? workFolder)
{
if (string.IsNullOrEmpty(workFolder))
{
return "";
}
if (!_settings.Settings.Llm.EnableProjectRules)
{
return "";
}
try
{
List<ProjectRulesService.ProjectRule> list = ProjectRulesService.LoadRules(workFolder);
if (list.Count == 0)
{
return "";
}
string when = ((_activeTab == "Code") ? "always" : "always");
List<ProjectRulesService.ProjectRule> rules = ProjectRulesService.FilterRules(list, when);
return ProjectRulesService.FormatForSystemPrompt(rules);
}
catch
{
return "";
}
}
private string BuildMemorySection(string? workFolder)
{
if (!_settings.Settings.Llm.EnableAgentMemory)
{
return "";
}
AgentMemoryService agentMemoryService = ((System.Windows.Application.Current is App app) ? app.MemoryService : null);
if (agentMemoryService == null || agentMemoryService.Count == 0)
{
return "";
}
agentMemoryService.Load(workFolder ?? "");
IReadOnlyList<MemoryEntry> all = agentMemoryService.All;
if (all.Count == 0)
{
return "";
}
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("\n## ?꾨줈?앺듃 硫붾え由?(?댁쟾 ?€?붿뿉???숈뒿???댁슜)");
stringBuilder.AppendLine("?꾨옒???댁쟾 ?€?붿뿉???숈뒿??洹쒖튃怨??좏샇?꾩엯?덈떎. ?묒뾽 ??李멸퀬?섏꽭??");
stringBuilder.AppendLine("?덈줈??洹쒖튃?대굹 ?좏샇?꾨? 諛쒓껄?섎㈃ memory ?꾧뎄??save ?≪뀡?쇰줈 ?€?ν븯?몄슂.");
stringBuilder.AppendLine("?ъ슜?먭? ?댁쟾 ?숈뒿 ?댁슜怨??ㅻⅨ 吏€?쒕? ?섎㈃ memory ?꾧뎄??delete ???덈줈 save ?섏꽭??\n");
foreach (IGrouping<string, MemoryEntry> item in from e in all
group e by e.Type)
{
string key = item.Key;
if (1 == 0)
{
}
string text = key switch
{
"rule" => "?꾨줈?앺듃 洹쒖튃",
"preference" => "?ъ슜???좏샇",
"fact" => "?꾨줈?앺듃 ?ъ떎",
"correction" => "?댁쟾 援먯젙",
_ => item.Key,
};
if (1 == 0)
{
}
string value = text;
StringBuilder stringBuilder2 = stringBuilder;
StringBuilder stringBuilder3 = stringBuilder2;
StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(2, 1, stringBuilder2);
handler.AppendLiteral("[");
handler.AppendFormatted(value);
handler.AppendLiteral("]");
stringBuilder3.AppendLine(ref handler);
foreach (MemoryEntry item2 in item.OrderByDescending((MemoryEntry e) => e.UseCount).Take(15))
{
stringBuilder2 = stringBuilder;
StringBuilder stringBuilder4 = stringBuilder2;
handler = new StringBuilder.AppendInterpolatedStringHandler(2, 1, stringBuilder2);
handler.AppendLiteral("- ");
handler.AppendFormatted(item2.Content);
stringBuilder4.AppendLine(ref handler);
}
stringBuilder.AppendLine();
}
return stringBuilder.ToString();
}
private void OpenWorkflowAnalyzerIfEnabled()
{
LlmSettings llm = _settings.Settings.Llm;
if (!llm.DevMode || !llm.WorkflowVisualizer)
{
return;
}
if (_analyzerWindow == null)
{
_analyzerWindow = new WorkflowAnalyzerWindow();
_analyzerWindow.Closed += delegate
{
_analyzerWindow = null;
};
foreach (ResourceDictionary mergedDictionary in System.Windows.Application.Current.Resources.MergedDictionaries)
{
_analyzerWindow.Resources.MergedDictionaries.Add(mergedDictionary);
}
_analyzerWindow.Show();
}
else if (!_analyzerWindow.IsVisible)
{
_analyzerWindow.Show();
_analyzerWindow.Activate();
}
else
{
_analyzerWindow.Reset();
_analyzerWindow.Activate();
}
_analyzerWindow.SwitchToTimelineTab();
_agentLoop.EventOccurred -= _analyzerWindow.OnAgentEvent;
_agentLoop.EventOccurred += _analyzerWindow.OnAgentEvent;
}
private void UpdateAnalyzerButtonVisibility()
{
LlmSettings llm = _settings.Settings.Llm;
BtnShowAnalyzer.Visibility = ((!llm.DevMode || !llm.WorkflowVisualizer) ? Visibility.Collapsed : Visibility.Visible);
}
private void BtnShowAnalyzer_Click(object sender, MouseButtonEventArgs e)
{
if (_analyzerWindow == null)
{
_analyzerWindow = new WorkflowAnalyzerWindow();
_analyzerWindow.Closed += delegate
{
_analyzerWindow = null;
};
foreach (ResourceDictionary mergedDictionary in System.Windows.Application.Current.Resources.MergedDictionaries)
{
_analyzerWindow.Resources.MergedDictionaries.Add(mergedDictionary);
}
_agentLoop.EventOccurred -= _analyzerWindow.OnAgentEvent;
_agentLoop.EventOccurred += _analyzerWindow.OnAgentEvent;
_analyzerWindow.Show();
}
else if (!_analyzerWindow.IsVisible)
{
_analyzerWindow.Show();
_analyzerWindow.Activate();
}
else
{
_analyzerWindow.Activate();
}
}
private void OnAgentEvent(AgentEvent evt)
{
if (_showExecutionHistory)
{
AddAgentEventBanner(evt);
}
PersistAgentEvent(evt);
AutoScrollIfNeeded();
UpdateStatusBar(evt);
if (evt.InputTokens > 0 || evt.OutputTokens > 0)
{
_agentCumulativeInputTokens += evt.InputTokens;
_agentCumulativeOutputTokens += evt.OutputTokens;
UpdateStatusTokens(_agentCumulativeInputTokens, _agentCumulativeOutputTokens);
}
UpdateAgentProgressBar(evt);
if (evt.StepCurrent > 0 && evt.StepTotal > 0)
{
UpdatePlanViewerStep(evt);
}
if (evt.Type == AgentEventType.Complete)
{
CompletePlanViewer();
}
if (evt.Success && !string.IsNullOrEmpty(evt.FilePath))
{
RefreshFileTreeIfVisible();
}
if (evt.Type == AgentEventType.ToolResult && evt.ToolName == "suggest_actions" && evt.Success)
{
RenderSuggestActionChips(evt.Summary);
}
if (!evt.Success || string.IsNullOrEmpty(evt.FilePath) || (evt.Type != AgentEventType.ToolResult && evt.Type != AgentEventType.Complete) || !WriteToolNames.Contains(evt.ToolName))
{
return;
}
string autoPreview = _settings.Settings.Llm.AutoPreview;
if (autoPreview == "auto")
{
if (PreviewWindow.IsOpen)
{
PreviewWindow.RefreshIfOpen(evt.FilePath);
}
else
{
TryShowPreview(evt.FilePath);
}
if (!PreviewWindow.IsOpen)
{
TryShowPreview(evt.FilePath);
}
}
}
private void OnSubAgentStatusChanged(SubAgentStatusEvent evt)
{
if (!((DispatcherObject)this).Dispatcher.CheckAccess())
{
((DispatcherObject)this).Dispatcher.Invoke((Action)delegate
{
OnSubAgentStatusChanged(evt);
});
return;
}
RefreshSubAgentIndicator();
SubAgentRunStatus status = evt.Status;
if (1 == 0)
{
}
AgentEvent agentEvent = status switch
{
SubAgentRunStatus.Started => new AgentEvent
{
Timestamp = evt.Timestamp,
Type = AgentEventType.Thinking,
ToolName = "sub_agent",
Summary = "Sub-agent " + evt.Id + " started\nTask: " + evt.Task
},
SubAgentRunStatus.Completed => new AgentEvent
{
Timestamp = evt.Timestamp,
Type = AgentEventType.ToolResult,
ToolName = "sub_agent",
Summary = "Sub-agent " + evt.Id + " completed\n" + (evt.Result ?? evt.Summary),
Success = true
},
_ => new AgentEvent
{
Timestamp = evt.Timestamp,
Type = AgentEventType.Error,
ToolName = "sub_agent",
Summary = "Sub-agent " + evt.Id + " failed\n" + (evt.Result ?? evt.Summary),
Success = false
},
};
if (1 == 0)
{
}
AgentEvent evt2 = agentEvent;
OnAgentEvent(evt2);
}
private void BtnToggleExecutionLog_Click(object sender, RoutedEventArgs e)
{
_showExecutionHistory = !_showExecutionHistory;
UpdateExecutionHistoryUi();
RenderMessages();
}
private void AddPlanningCard(AgentEvent evt, bool animate = true)
{
List<string> steps = evt.Steps;
Border border = new Border
{
Background = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#F0F4FF")),
CornerRadius = new CornerRadius(10.0),
Padding = new Thickness(14.0, 10.0, 14.0, 10.0),
Margin = new Thickness(40.0, 4.0, 80.0, 4.0),
HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
MaxWidth = 560.0
};
StackPanel stackPanel = new StackPanel();
StackPanel stackPanel2 = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal,
Margin = new Thickness(0.0, 0.0, 0.0, 6.0)
};
stackPanel2.Children.Add(new TextBlock
{
Text = "\ue9d5",
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 13.0,
Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#4B5EFC")),
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(0.0, 0.0, 6.0, 0.0)
});
stackPanel2.Children.Add(new TextBlock
{
Text = $"?묒뾽 怨꾪쉷 ??{steps.Count}?④퀎",
FontSize = 12.5,
FontWeight = FontWeights.SemiBold,
Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#3730A3")),
VerticalAlignment = VerticalAlignment.Center
});
stackPanel.Children.Add(stackPanel2);
Grid grid = new Grid
{
Margin = new Thickness(0.0, 0.0, 0.0, 8.0)
};
grid.ColumnDefinitions.Add(new ColumnDefinition
{
Width = new GridLength(1.0, GridUnitType.Star)
});
grid.ColumnDefinitions.Add(new ColumnDefinition
{
Width = GridLength.Auto
});
_planProgressBar = new System.Windows.Controls.ProgressBar
{
Minimum = 0.0,
Maximum = steps.Count,
Value = 0.0,
Height = 4.0,
Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#4B5EFC")),
Background = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#D0D5FF")),
VerticalAlignment = VerticalAlignment.Center
};
_planProgressBar.BorderThickness = new Thickness(0.0);
Grid.SetColumn(_planProgressBar, 0);
grid.Children.Add(_planProgressBar);
_planProgressText = new TextBlock
{
Text = "0%",
FontSize = 10.5,
FontWeight = FontWeights.SemiBold,
Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#4B5EFC")),
Margin = new Thickness(8.0, 0.0, 0.0, 0.0),
VerticalAlignment = VerticalAlignment.Center
};
Grid.SetColumn(_planProgressText, 1);
grid.Children.Add(_planProgressText);
stackPanel.Children.Add(grid);
_planStepsPanel = new StackPanel();
for (int i = 0; i < steps.Count; i++)
{
StackPanel stackPanel3 = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal,
Margin = new Thickness(0.0, 1.0, 0.0, 1.0),
Tag = i
};
stackPanel3.Children.Add(new TextBlock
{
Text = "??,
FontSize = 11.0,
Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#9CA3AF")),
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(0.0, 0.0, 6.0, 0.0),
Tag = "status"
});
stackPanel3.Children.Add(new TextBlock
{
Text = $"{i + 1}. {steps[i]}",
FontSize = 11.5,
Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#4B5563")),
TextWrapping = TextWrapping.Wrap,
MaxWidth = 480.0,
VerticalAlignment = VerticalAlignment.Center
});
_planStepsPanel.Children.Add(stackPanel3);
}
stackPanel.Children.Add(_planStepsPanel);
border.Child = stackPanel;
_planningCard = border;
if (animate)
{
border.Opacity = 0.0;
border.BeginAnimation(UIElement.OpacityProperty, new DoubleAnimation(0.0, 1.0, TimeSpan.FromMilliseconds(300.0)));
}
MessagePanel.Children.Add(border);
}
private void AddDecisionButtons(TaskCompletionSource<string?> tcs, List<string> options)
{
System.Windows.Media.Brush accentBrush = (TryFindResource("AccentColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.CornflowerBlue;
System.Windows.Media.Color color = ((SolidColorBrush)accentBrush).Color;
System.Windows.Media.Brush foreground = (TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
Border border = new Border
{
Margin = new Thickness(40.0, 2.0, 80.0, 6.0),
HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
MaxWidth = 560.0
};
StackPanel outerStack = new StackPanel();
StackPanel stackPanel = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal,
Margin = new Thickness(0.0, 0.0, 0.0, 0.0)
};
Border border2 = new Border
{
Background = accentBrush,
CornerRadius = new CornerRadius(16.0),
Padding = new Thickness(16.0, 7.0, 16.0, 7.0),
Margin = new Thickness(0.0, 0.0, 8.0, 0.0),
Cursor = System.Windows.Input.Cursors.Hand
};
StackPanel stackPanel2 = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal
};
stackPanel2.Children.Add(new TextBlock
{
Text = "\ue73e",
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 11.0,
Foreground = System.Windows.Media.Brushes.White,
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(0.0, 0.0, 5.0, 0.0)
});
stackPanel2.Children.Add(new TextBlock
{
Text = "?뱀씤",
FontSize = 12.5,
FontWeight = FontWeights.SemiBold,
Foreground = System.Windows.Media.Brushes.White
});
border2.Child = stackPanel2;
ApplyMenuItemHover(border2);
border2.MouseLeftButtonUp += delegate
{
CollapseDecisionButtons(outerStack, "???뱀씤??, accentBrush);
tcs.TrySetResult(null);
};
stackPanel.Children.Add(border2);
Border border3 = new Border
{
Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(24, color.R, color.G, color.B)),
CornerRadius = new CornerRadius(16.0),
Padding = new Thickness(14.0, 7.0, 14.0, 7.0),
Margin = new Thickness(0.0, 0.0, 8.0, 0.0),
Cursor = System.Windows.Input.Cursors.Hand,
BorderBrush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(64, color.R, color.G, color.B)),
BorderThickness = new Thickness(1.0)
};
StackPanel stackPanel3 = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal
};
stackPanel3.Children.Add(new TextBlock
{
Text = "\ue70f",
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 11.0,
Foreground = accentBrush,
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(0.0, 0.0, 5.0, 0.0)
});
stackPanel3.Children.Add(new TextBlock
{
Text = "?섏젙 ?붿껌",
FontSize = 12.5,
FontWeight = FontWeights.SemiBold,
Foreground = accentBrush
});
border3.Child = stackPanel3;
ApplyMenuItemHover(border3);
Border editInputPanel = new Border
{
Visibility = Visibility.Collapsed,
Background = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#F8F9FC")),
CornerRadius = new CornerRadius(10.0),
Padding = new Thickness(10.0, 8.0, 10.0, 8.0),
Margin = new Thickness(0.0, 8.0, 0.0, 0.0)
};
StackPanel stackPanel4 = new StackPanel();
stackPanel4.Children.Add(new TextBlock
{
Text = "?섏젙 ?ы빆???낅젰?섏꽭??",
FontSize = 11.5,
Foreground = foreground,
Margin = new Thickness(0.0, 0.0, 0.0, 6.0)
});
System.Windows.Controls.TextBox editTextBox = new System.Windows.Controls.TextBox
{
MinHeight = 36.0,
MaxHeight = 100.0,
AcceptsReturn = true,
TextWrapping = TextWrapping.Wrap,
FontSize = 12.5,
Background = System.Windows.Media.Brushes.White,
BorderBrush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(64, color.R, color.G, color.B)),
BorderThickness = new Thickness(1.0),
Padding = new Thickness(8.0, 6.0, 8.0, 6.0)
};
stackPanel4.Children.Add(editTextBox);
Border border4 = new Border
{
Background = accentBrush,
CornerRadius = new CornerRadius(8.0),
Padding = new Thickness(12.0, 5.0, 12.0, 5.0),
Margin = new Thickness(0.0, 6.0, 0.0, 0.0),
Cursor = System.Windows.Input.Cursors.Hand,
HorizontalAlignment = System.Windows.HorizontalAlignment.Right
};
border4.Child = new TextBlock
{
Text = "?꾩넚",
FontSize = 12.0,
FontWeight = FontWeights.SemiBold,
Foreground = System.Windows.Media.Brushes.White
};
ApplyHoverScaleAnimation(border4, 1.05);
border4.MouseLeftButtonUp += delegate
{
string text = editTextBox.Text.Trim();
if (!string.IsNullOrEmpty(text))
{
CollapseDecisionButtons(outerStack, "???섏젙 ?붿껌??, accentBrush);
tcs.TrySetResult(text);
}
};
stackPanel4.Children.Add(border4);
editInputPanel.Child = stackPanel4;
border3.MouseLeftButtonUp += delegate
{
editInputPanel.Visibility = ((editInputPanel.Visibility == Visibility.Visible) ? Visibility.Collapsed : Visibility.Visible);
if (editInputPanel.Visibility == Visibility.Visible)
{
editTextBox.Focus();
}
};
stackPanel.Children.Add(border3);
Border border5 = new Border
{
Background = System.Windows.Media.Brushes.Transparent,
CornerRadius = new CornerRadius(16.0),
Padding = new Thickness(14.0, 7.0, 14.0, 7.0),
Cursor = System.Windows.Input.Cursors.Hand,
BorderBrush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(48, 220, 38, 38)),
BorderThickness = new Thickness(1.0)
};
StackPanel stackPanel5 = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal
};
stackPanel5.Children.Add(new TextBlock
{
Text = "\ue711",
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 11.0,
Foreground = new SolidColorBrush(System.Windows.Media.Color.FromRgb(220, 38, 38)),
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(0.0, 0.0, 5.0, 0.0)
});
stackPanel5.Children.Add(new TextBlock
{
Text = "痍⑥냼",
FontSize = 12.5,
FontWeight = FontWeights.SemiBold,
Foreground = new SolidColorBrush(System.Windows.Media.Color.FromRgb(220, 38, 38))
});
border5.Child = stackPanel5;
ApplyMenuItemHover(border5);
border5.MouseLeftButtonUp += delegate
{
CollapseDecisionButtons(outerStack, "??痍⑥냼??, new SolidColorBrush(System.Windows.Media.Color.FromRgb(220, 38, 38)));
tcs.TrySetResult("痍⑥냼");
};
stackPanel.Children.Add(border5);
outerStack.Children.Add(stackPanel);
outerStack.Children.Add(editInputPanel);
border.Child = outerStack;
ApplyMessageEntryAnimation(border);
MessagePanel.Children.Add(border);
ForceScrollToEnd();
StackPanel capturedOuterStack = outerStack;
System.Windows.Media.Brush capturedAccent = accentBrush;
tcs.Task.ContinueWith(delegate(Task<string?> t)
{
((DispatcherObject)this).Dispatcher.BeginInvoke((Delegate)(Action)delegate
{
if (capturedOuterStack.Children.Count > 1)
{
string resultText = ((t.Result == null) ? "???뱀씤?? : ((t.Result == "痍⑥냼") ? "??痍⑥냼?? : "???섏젙 ?붿껌??));
System.Windows.Media.Brush fg = ((t.Result == "痍⑥냼") ? new SolidColorBrush(System.Windows.Media.Color.FromRgb(220, 38, 38)) : capturedAccent);
CollapseDecisionButtons(capturedOuterStack, resultText, fg);
}
}, Array.Empty<object>());
}, TaskScheduler.Default);
}
private void CollapseDecisionButtons(StackPanel outerStack, string resultText, System.Windows.Media.Brush fg)
{
outerStack.Children.Clear();
TextBlock element = new TextBlock
{
Text = resultText,
FontSize = 12.0,
FontWeight = FontWeights.SemiBold,
Foreground = fg,
Opacity = 0.8,
Margin = new Thickness(0.0, 2.0, 0.0, 2.0)
};
outerStack.Children.Add(element);
}
private Func<string, List<string>, Task<string?>> CreatePlanDecisionCallback()
{
return async delegate(string planSummary, List<string> options)
{
TaskCompletionSource<string?> tcs = new TaskCompletionSource<string>();
List<string> steps = TaskDecomposer.ExtractSteps(planSummary);
await ((DispatcherObject)this).Dispatcher.InvokeAsync((Action)delegate
{
if (_planViewerWindow == null || !IsWindowAlive(_planViewerWindow))
{
_planViewerWindow = new PlanViewerWindow();
_planViewerWindow.Closing += delegate(object? _, CancelEventArgs e)
{
e.Cancel = true;
_planViewerWindow.Hide();
};
}
_planViewerWindow.ShowPlanAsync(planSummary, steps, tcs);
AddDecisionButtons(tcs, options);
ShowPlanButton(show: true);
});
if (await Task.WhenAny(tcs.Task, Task.Delay(TimeSpan.FromMinutes(5.0))) != tcs.Task)
{
await ((DispatcherObject)this).Dispatcher.InvokeAsync((Action)delegate
{
_planViewerWindow?.Hide();
});
return "痍⑥냼";
}
string result = await tcs.Task;
if (result != null)
{
await ((DispatcherObject)this).Dispatcher.InvokeAsync((Action)delegate
{
_planViewerWindow?.Hide();
});
}
else
{
await ((DispatcherObject)this).Dispatcher.InvokeAsync((Action)delegate
{
_planViewerWindow?.SwitchToExecutionMode();
_planViewerWindow?.Hide();
});
}
return result;
};
}
private void ShowPlanButton(bool show)
{
if (!show)
{
for (int num = MoodIconPanel.Children.Count - 1; num >= 0; num--)
{
if (MoodIconPanel.Children[num] is Border { Tag: var tag } && tag?.ToString() == "PlanBtn")
{
if (num > 0 && MoodIconPanel.Children[num - 1] is Border { Tag: var tag2 } && tag2?.ToString() == "PlanSep")
{
MoodIconPanel.Children.RemoveAt(num - 1);
}
if (num < MoodIconPanel.Children.Count)
{
MoodIconPanel.Children.RemoveAt(Math.Min(num, MoodIconPanel.Children.Count - 1));
}
break;
}
}
return;
}
foreach (object child in MoodIconPanel.Children)
{
if (child is Border { Tag: var tag3 } && tag3?.ToString() == "PlanBtn")
{
return;
}
}
Border border4 = new Border();
border4.Width = 1.0;
border4.Height = 18.0;
border4.Background = (TryFindResource("SeparatorColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
border4.Margin = new Thickness(4.0, 0.0, 4.0, 0.0);
border4.VerticalAlignment = VerticalAlignment.Center;
border4.Tag = "PlanSep";
Border element = border4;
MoodIconPanel.Children.Add(element);
Border border5 = CreateFolderBarButton("\ue9d2", "怨꾪쉷", "?ㅽ뻾 怨꾪쉷 蹂닿린", "#10B981");
border5.Tag = "PlanBtn";
border5.MouseLeftButtonUp += delegate(object _, MouseButtonEventArgs e)
{
e.Handled = true;
if (_planViewerWindow != null && IsWindowAlive(_planViewerWindow))
{
_planViewerWindow.Show();
_planViewerWindow.Activate();
}
};
MoodIconPanel.Children.Add(border5);
}
private void UpdatePlanViewerStep(AgentEvent evt)
{
if (_planViewerWindow != null && IsWindowAlive(_planViewerWindow) && evt.StepCurrent > 0)
{
_planViewerWindow.UpdateCurrentStep(evt.StepCurrent - 1);
}
}
private void CompletePlanViewer()
{
if (_planViewerWindow != null && IsWindowAlive(_planViewerWindow))
{
_planViewerWindow.MarkComplete();
}
ShowPlanButton(show: false);
}
private static bool IsWindowAlive(Window? w)
{
if (w == null)
{
return false;
}
try
{
bool isVisible = w.IsVisible;
return true;
}
catch
{
return false;
}
}
private void RenderSuggestActionChips(string jsonSummary)
{
List<(string, string)> list = new List<(string, string)>();
try
{
if (jsonSummary.Contains("\"label\""))
{
using JsonDocument jsonDocument = JsonDocument.Parse(jsonSummary);
if (jsonDocument.RootElement.ValueKind == JsonValueKind.Array)
{
foreach (JsonElement item4 in jsonDocument.RootElement.EnumerateArray())
{
JsonElement value;
string text = (item4.TryGetProperty("label", out value) ? (value.GetString() ?? "") : "");
JsonElement value2;
string item = (item4.TryGetProperty("command", out value2) ? (value2.GetString() ?? text) : text);
if (!string.IsNullOrEmpty(text))
{
list.Add((text, item));
}
}
}
}
else
{
string[] array = jsonSummary.Split('\n');
foreach (string text2 in array)
{
string text3 = text2.Trim().TrimStart('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', ' ');
if (!string.IsNullOrEmpty(text3))
{
string[] array2 = text3.Split('??, ':', '??);
if (array2.Length >= 2)
{
list.Add((array2[0].Trim(), array2[1].Trim()));
}
else if (!string.IsNullOrEmpty(text3))
{
list.Add((text3, text3));
}
}
}
}
}
catch
{
return;
}
if (list.Count == 0)
{
return;
}
System.Windows.Media.Brush brush = (TryFindResource("AccentColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.CornflowerBlue;
System.Windows.Media.Brush foreground = (TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
System.Windows.Media.Brush brush2 = (TryFindResource("ItemHoverBackground") as System.Windows.Media.Brush) ?? new SolidColorBrush(System.Windows.Media.Color.FromArgb(24, byte.MaxValue, byte.MaxValue, byte.MaxValue));
Border container = new Border
{
Margin = new Thickness(40.0, 4.0, 40.0, 8.0),
HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch
};
StackPanel stackPanel = new StackPanel
{
Margin = new Thickness(0.0, 0.0, 0.0, 6.0)
};
stackPanel.Children.Add(new TextBlock
{
Text = "\ud83d\udca1 ?ㅼ쓬 ?묒뾽 ?쒖븞:",
FontSize = 12.0,
Foreground = foreground
});
WrapPanel wrapPanel = new WrapPanel
{
Margin = new Thickness(0.0, 2.0, 0.0, 0.0)
};
foreach (var item5 in list.Take(5))
{
string item2 = item5.Item1;
string item3 = item5.Item2;
string capturedCmd = item3;
Border border = new Border
{
CornerRadius = new CornerRadius(16.0),
Padding = new Thickness(14.0, 7.0, 14.0, 7.0),
Margin = new Thickness(0.0, 0.0, 8.0, 6.0),
Cursor = System.Windows.Input.Cursors.Hand,
Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(21, ((SolidColorBrush)brush).Color.R, ((SolidColorBrush)brush).Color.G, ((SolidColorBrush)brush).Color.B)),
BorderBrush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(64, ((SolidColorBrush)brush).Color.R, ((SolidColorBrush)brush).Color.G, ((SolidColorBrush)brush).Color.B)),
BorderThickness = new Thickness(1.0)
};
border.Child = new TextBlock
{
Text = item2,
FontSize = 12.5,
Foreground = brush,
FontWeight = FontWeights.SemiBold
};
border.MouseEnter += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
((Border)s).Opacity = 0.8;
};
border.MouseLeave += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
((Border)s).Opacity = 1.0;
};
border.MouseLeftButtonUp += delegate
{
MessagePanel.Children.Remove(container);
if (capturedCmd.StartsWith("/"))
{
InputBox.Text = capturedCmd + " ";
InputBox.CaretIndex = InputBox.Text.Length;
InputBox.Focus();
}
else
{
InputBox.Text = capturedCmd;
SendMessageAsync();
}
};
wrapPanel.Children.Add(border);
}
StackPanel stackPanel2 = new StackPanel();
stackPanel2.Children.Add(stackPanel);
stackPanel2.Children.Add(wrapPanel);
container.Child = stackPanel2;
ApplyMessageEntryAnimation(container);
MessagePanel.Children.Add(container);
ForceScrollToEnd();
}
private string BuildFeedbackContext()
{
try
{
List<ChatConversation> list = (from m in _storage.LoadAllMeta()
orderby m.UpdatedAt descending
select m).Take(20).ToList();
List<string> list2 = new List<string>();
List<string> list3 = new List<string>();
foreach (ChatConversation item2 in list)
{
ChatConversation chatConversation = _storage.Load(item2.Id);
if (chatConversation == null)
{
continue;
}
foreach (ChatMessage item3 in chatConversation.Messages.Where((ChatMessage m) => m.Role == "assistant" && m.Feedback != null))
{
string content = item3.Content;
string item = ((content != null && content.Length > 80) ? item3.Content.Substring(0, 80) : (item3.Content ?? ""));
if (item3.Feedback == "like")
{
list2.Add(item);
}
else if (item3.Feedback == "dislike")
{
list3.Add(item);
}
}
}
if (list2.Count == 0 && list3.Count == 0)
{
return "";
}
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("\n[?ъ슜???좏샇??李멸퀬]");
if (list2.Count > 0)
{
StringBuilder stringBuilder2 = stringBuilder;
StringBuilder stringBuilder3 = stringBuilder2;
StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(20, 1, stringBuilder2);
handler.AppendLiteral("?ъ슜?먭? 醫뗭븘???묐떟 ?ㅽ???(");
handler.AppendFormatted(list2.Count);
handler.AppendLiteral("嫄?:");
stringBuilder3.AppendLine(ref handler);
foreach (string item4 in list2.Take(5))
{
stringBuilder2 = stringBuilder;
StringBuilder stringBuilder4 = stringBuilder2;
handler = new StringBuilder.AppendInterpolatedStringHandler(9, 1, stringBuilder2);
handler.AppendLiteral(" - \"");
handler.AppendFormatted(item4);
handler.AppendLiteral("...\"");
stringBuilder4.AppendLine(ref handler);
}
}
if (list3.Count > 0)
{
StringBuilder stringBuilder2 = stringBuilder;
StringBuilder stringBuilder5 = stringBuilder2;
StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(20, 1, stringBuilder2);
handler.AppendLiteral("?ъ슜?먭? ?レ뼱???묐떟 ?ㅽ???(");
handler.AppendFormatted(list3.Count);
handler.AppendLiteral("嫄?:");
stringBuilder5.AppendLine(ref handler);
foreach (string item5 in list3.Take(5))
{
stringBuilder2 = stringBuilder;
StringBuilder stringBuilder6 = stringBuilder2;
handler = new StringBuilder.AppendInterpolatedStringHandler(9, 1, stringBuilder2);
handler.AppendLiteral(" - \"");
handler.AppendFormatted(item5);
handler.AppendLiteral("...\"");
stringBuilder6.AppendLine(ref handler);
}
}
stringBuilder.AppendLine("???좏샇?꾨? 李멸퀬?섏뿬 ?묐떟 ?ㅽ??쇱쓣 議곗젙?섏꽭??");
return stringBuilder.ToString();
}
catch
{
return "";
}
}
private void UpdateProgressBar(AgentEvent evt)
{
if (_planProgressBar == null || _planStepsPanel == null || _planProgressText == null)
{
return;
}
int num = evt.StepCurrent - 1;
int stepTotal = evt.StepTotal;
_planProgressBar.Value = evt.StepCurrent;
int value = (int)((double)evt.StepCurrent / (double)stepTotal * 100.0);
_planProgressText.Text = $"{value}%";
for (int i = 0; i < _planStepsPanel.Children.Count; i++)
{
if (!(_planStepsPanel.Children[i] is StackPanel stackPanel) || stackPanel.Children.Count < 2)
{
continue;
}
TextBlock textBlock = stackPanel.Children[0] as TextBlock;
TextBlock textBlock2 = stackPanel.Children[1] as TextBlock;
if (textBlock != null && textBlock2 != null)
{
if (i < num)
{
textBlock.Text = "??;
textBlock.Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#16A34A"));
textBlock2.Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#6B7280"));
}
else if (i == num)
{
textBlock.Text = "??;
textBlock.Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#4B5EFC"));
textBlock2.Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#1E293B"));
textBlock2.FontWeight = FontWeights.SemiBold;
}
else
{
textBlock.Text = "??;
textBlock.Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#9CA3AF"));
textBlock2.Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#4B5563"));
textBlock2.FontWeight = FontWeights.Normal;
}
}
}
}
private static UIElement BuildDiffView(string text)
{
StackPanel stackPanel = new StackPanel
{
Background = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#FAFAFA")),
MaxWidth = 520.0
};
bool flag = false;
string[] array = text.Split('\n');
foreach (string text2 in array)
{
string text3 = text2.TrimEnd('\r');
if (!flag && !text3.StartsWith("--- "))
{
stackPanel.Children.Add(new TextBlock
{
Text = text3,
FontSize = 11.0,
Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#4B5563")),
FontFamily = new System.Windows.Media.FontFamily("Consolas"),
Margin = new Thickness(0.0, 0.0, 0.0, 1.0)
});
continue;
}
flag = true;
string text4;
string value;
if (text3.StartsWith("---") || text3.StartsWith("+++"))
{
text4 = "#F3F4F6";
value = "#374151";
}
else if (text3.StartsWith("@@"))
{
text4 = "#EFF6FF";
value = "#3B82F6";
}
else if (text3.StartsWith("+"))
{
text4 = "#ECFDF5";
value = "#059669";
}
else if (text3.StartsWith("-"))
{
text4 = "#FEF2F2";
value = "#DC2626";
}
else
{
text4 = "Transparent";
value = "#6B7280";
}
TextBlock textBlock = new TextBlock
{
Text = text3,
FontSize = 10.5,
FontFamily = new System.Windows.Media.FontFamily("Consolas"),
Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(value)),
Padding = new Thickness(4.0, 1.0, 4.0, 1.0)
};
if (text4 != "Transparent")
{
textBlock.Background = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(text4));
}
stackPanel.Children.Add(textBlock);
}
return stackPanel;
}
private void AddAgentEventBanner(AgentEvent evt, bool animate = true)
{
string agentLogLevel = _settings.Settings.Llm.AgentLogLevel;
if (evt.Type == AgentEventType.Planning)
{
List<string> steps = evt.Steps;
if (steps != null && steps.Count > 0)
{
AddPlanningCard(evt, animate);
return;
}
}
if (evt.Type == AgentEventType.StepStart && evt.StepTotal > 0)
{
UpdateProgressBar(evt);
}
else
{
if (agentLogLevel == "simple" && evt.Type == AgentEventType.ToolCall)
{
return;
}
bool flag = evt.Type == AgentEventType.StepDone && evt.ToolName == "total_stats";
string text;
string text2;
string value;
string value2;
if (flag)
{
text = "\ue9d2";
text2 = "Total Stats";
value = "#F3EEFF";
value2 = "#7C3AED";
(string, string, string, string) tuple = ("\ue9d2", "Total Stats", "#F3EEFF", "#7C3AED");
}
else
{
AgentEventType type = evt.Type;
if (1 == 0)
{
}
(string, string, string, string) tuple2 = type switch
{
AgentEventType.Thinking => ("\ue8bd", "Thinking", "#F0F0FF", "#6B7BC4"),
AgentEventType.ToolCall => ("\ue8a7", evt.ToolName, "#EEF6FF", "#3B82F6"),
AgentEventType.ToolResult => ("\ue73e", evt.ToolName, "#EEF9EE", "#16A34A"),
AgentEventType.SkillCall => ("\ue8a5", evt.ToolName, "#FFF7ED", "#EA580C"),
AgentEventType.Error => ("\ue783", "Error", "#FEF2F2", "#DC2626"),
AgentEventType.Complete => ("\ue930", "Complete", "#F0FFF4", "#15803D"),
AgentEventType.StepDone => ("\ue73e", "Step Done", "#EEF9EE", "#16A34A"),
AgentEventType.Paused => ("\ue769", "Paused", "#FFFBEB", "#D97706"),
AgentEventType.Resumed => ("\ue768", "Resumed", "#ECFDF5", "#059669"),
_ => ("\ue946", "Agent", "#F5F5F5", "#6B7280"),
};
if (1 == 0)
{
}
(string, string, string, string) tuple3 = tuple2;
text = tuple3.Item1;
text2 = tuple3.Item2;
value = tuple3.Item3;
value2 = tuple3.Item4;
(string, string, string, string) tuple = (tuple3.Item1, tuple3.Item2, tuple3.Item3, tuple3.Item4);
}
Border border = new Border
{
Background = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(value)),
BorderBrush = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(value2)),
BorderThickness = new Thickness(1.0),
CornerRadius = new CornerRadius(16.0),
Padding = new Thickness(14.0, 10.0, 14.0, 10.0),
Margin = new Thickness(48.0, 4.0, 120.0, 4.0),
HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
MaxWidth = GetMessageMaxWidth(),
Effect = new DropShadowEffect
{
BlurRadius = 12.0,
ShadowDepth = 0.0,
Opacity = 0.05
}
};
StackPanel stackPanel = new StackPanel();
Grid grid = new Grid();
grid.ColumnDefinitions.Add(new ColumnDefinition
{
Width = new GridLength(1.0, GridUnitType.Star)
});
grid.ColumnDefinitions.Add(new ColumnDefinition
{
Width = GridLength.Auto
});
StackPanel stackPanel2 = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal
};
stackPanel2.Children.Add(new TextBlock
{
Text = text,
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 11.0,
Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(value2)),
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(0.0, 0.0, 6.0, 0.0)
});
stackPanel2.Children.Add(new TextBlock
{
Text = text2,
FontSize = 11.5,
FontWeight = FontWeights.SemiBold,
Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(value2)),
VerticalAlignment = VerticalAlignment.Center
});
Grid.SetColumn(stackPanel2, 0);
StackPanel stackPanel3 = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal
};
if (agentLogLevel != "simple" && evt.ElapsedMs > 0)
{
stackPanel3.Children.Add(new TextBlock
{
Text = ((evt.ElapsedMs < 1000) ? $"{evt.ElapsedMs}ms" : $"{(double)evt.ElapsedMs / 1000.0:F1}s"),
FontSize = 10.0,
Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#9CA3AF")),
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(8.0, 0.0, 0.0, 0.0)
});
}
if (agentLogLevel != "simple" && (evt.InputTokens > 0 || evt.OutputTokens > 0))
{
string text3 = ((evt.InputTokens > 0 && evt.OutputTokens > 0) ? $"{evt.InputTokens}??evt.OutputTokens}t" : ((evt.InputTokens > 0) ? $"??evt.InputTokens}t" : $"??evt.OutputTokens}t"));
stackPanel3.Children.Add(new Border
{
Background = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#F0F0F5")),
CornerRadius = new CornerRadius(4.0),
Padding = new Thickness(5.0, 1.0, 5.0, 1.0),
Margin = new Thickness(6.0, 0.0, 0.0, 0.0),
VerticalAlignment = VerticalAlignment.Center,
Child = new TextBlock
{
Text = text3,
FontSize = 9.5,
Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#8B8FA3")),
FontFamily = new System.Windows.Media.FontFamily("Consolas")
}
});
}
Grid.SetColumn(stackPanel3, 1);
grid.Children.Add(stackPanel2);
grid.Children.Add(stackPanel3);
StackPanel stackPanel4 = stackPanel2;
stackPanel.Children.Add(grid);
if (agentLogLevel == "simple")
{
if (!string.IsNullOrEmpty(evt.Summary))
{
string text4 = ((evt.Summary.Length > 100) ? (evt.Summary.Substring(0, 100) + "??) : evt.Summary);
stackPanel.Children.Add(new TextBlock
{
Text = text4,
FontSize = 11.0,
Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#6B7280")),
TextWrapping = TextWrapping.NoWrap,
TextTrimming = TextTrimming.CharacterEllipsis,
Margin = new Thickness(0.0, 2.0, 0.0, 0.0)
});
}
}
else if (!string.IsNullOrEmpty(evt.Summary))
{
string summary = evt.Summary;
if ((evt.Type == AgentEventType.ToolCall || evt.Type == AgentEventType.ToolResult) && summary.Length > 60)
{
string text5 = ((summary.Length > 80) ? (summary.Substring(0, 80) + "...") : summary);
TextBlock summaryTb = new TextBlock
{
Text = text5,
FontSize = 11.5,
Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#4B5563")),
TextWrapping = TextWrapping.Wrap,
Margin = new Thickness(0.0, 3.0, 0.0, 0.0),
Cursor = System.Windows.Input.Cursors.Hand
};
UIElement fullContent;
if (summary.Contains("--- ") && summary.Contains("+++ "))
{
fullContent = BuildDiffView(summary);
}
else
{
fullContent = new TextBlock
{
Text = summary,
FontSize = 11.0,
Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#6B7280")),
TextWrapping = TextWrapping.Wrap,
FontFamily = new System.Windows.Media.FontFamily("Consolas")
};
}
fullContent.Visibility = Visibility.Collapsed;
((FrameworkElement)fullContent).Margin = new Thickness(0.0, 4.0, 0.0, 0.0);
TextBlock expandIcon = new TextBlock
{
Text = "\ue70d",
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 9.0,
Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#9CA3AF")),
Margin = new Thickness(6.0, 0.0, 0.0, 0.0),
VerticalAlignment = VerticalAlignment.Center
};
stackPanel4.Children.Add(expandIcon);
bool isExpanded = false;
border.MouseLeftButtonDown += delegate
{
isExpanded = !isExpanded;
fullContent.Visibility = ((!isExpanded) ? Visibility.Collapsed : Visibility.Visible);
summaryTb.Visibility = (isExpanded ? Visibility.Collapsed : Visibility.Visible);
expandIcon.Text = (isExpanded ? "\ue70e" : "\ue70d");
};
stackPanel.Children.Add(summaryTb);
stackPanel.Children.Add(fullContent);
}
else
{
stackPanel.Children.Add(new TextBlock
{
Text = summary,
FontSize = 11.5,
Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#4B5563")),
TextWrapping = TextWrapping.Wrap,
Margin = new Thickness(0.0, 3.0, 0.0, 0.0)
});
}
}
if (agentLogLevel == "debug" && !string.IsNullOrEmpty(evt.ToolInput))
{
stackPanel.Children.Add(new Border
{
Background = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#F8F8FC")),
CornerRadius = new CornerRadius(4.0),
Padding = new Thickness(8.0, 4.0, 8.0, 4.0),
Margin = new Thickness(0.0, 4.0, 0.0, 0.0),
Child = new TextBlock
{
Text = ((evt.ToolInput.Length > 500) ? (evt.ToolInput.Substring(0, 500) + "??) : evt.ToolInput),
FontSize = 10.0,
Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#7C7F93")),
FontFamily = new System.Windows.Media.FontFamily("Consolas"),
TextWrapping = TextWrapping.Wrap
}
});
}
if (!string.IsNullOrEmpty(evt.FilePath))
{
Border border2 = new Border
{
Background = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#F8FAFC")),
CornerRadius = new CornerRadius(4.0),
Padding = new Thickness(8.0, 4.0, 8.0, 4.0),
Margin = new Thickness(0.0, 4.0, 0.0, 0.0)
};
StackPanel stackPanel5 = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal
};
stackPanel5.Children.Add(new TextBlock
{
Text = "\ue8b7",
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 10.0,
Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#9CA3AF")),
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(0.0, 0.0, 4.0, 0.0)
});
stackPanel5.Children.Add(new TextBlock
{
Text = evt.FilePath,
FontSize = 10.5,
Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#6B7280")),
FontFamily = new System.Windows.Media.FontFamily("Consolas"),
VerticalAlignment = VerticalAlignment.Center,
TextTrimming = TextTrimming.CharacterEllipsis
});
StackPanel element = BuildFileQuickActions(evt.FilePath);
stackPanel5.Children.Add(element);
border2.Child = stackPanel5;
stackPanel.Children.Add(border2);
}
border.Child = stackPanel;
if (flag)
{
border.Cursor = System.Windows.Input.Cursors.Hand;
border.ToolTip = "?대┃?섏뿬 蹂묐ぉ 遺꾩꽍 蹂닿린";
border.MouseLeftButtonUp += delegate
{
OpenWorkflowAnalyzerIfEnabled();
_analyzerWindow?.SwitchToBottleneckTab();
_analyzerWindow?.Activate();
};
}
if (animate)
{
border.Opacity = 0.0;
border.BeginAnimation(UIElement.OpacityProperty, new DoubleAnimation(0.0, 1.0, TimeSpan.FromMilliseconds(200.0)));
}
MessagePanel.Children.Add(border);
}
}
private StackPanel BuildFileQuickActions(string filePath)
{
StackPanel panel = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal,
Margin = new Thickness(6.0, 0.0, 0.0, 0.0),
VerticalAlignment = VerticalAlignment.Center
};
System.Windows.Media.Color color = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#3B82F6");
SolidColorBrush accentBrush = new SolidColorBrush(color);
string item = System.IO.Path.GetExtension(filePath).ToLowerInvariant();
if (_previewableExtensions.Contains(item))
{
string path1 = filePath;
panel.Children.Add(MakeBtn("\ue8a1", "?꾨━酉?, delegate
{
ShowPreviewPanel(path1);
}));
}
string path2 = filePath;
panel.Children.Add(MakeBtn("\ue8a7", "?닿린", delegate
{
try
{
Process.Start(new ProcessStartInfo
{
FileName = path2,
UseShellExecute = true
});
}
catch
{
}
}));
string path3 = filePath;
panel.Children.Add(MakeBtn("\ued25", "?대뜑", delegate
{
try
{
Process.Start("explorer.exe", "/select,\"" + path3 + "\"");
}
catch
{
}
}));
string path4 = filePath;
panel.Children.Add(MakeBtn("\ue8c8", "蹂듭궗", delegate
{
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Expected O, but got Unknown
try
{
System.Windows.Clipboard.SetText(path4);
UIElementCollection children = panel.Children;
if (children[children.Count - 1] is Border { Child: StackPanel child })
{
TextBlock origLabel = child.Children.OfType<TextBlock>().LastOrDefault();
if (origLabel != null)
{
string prev = origLabel.Text;
origLabel.Text = "蹂듭궗????;
DispatcherTimer timer = new DispatcherTimer
{
Interval = TimeSpan.FromMilliseconds(1500.0)
};
timer.Tick += delegate
{
origLabel.Text = prev;
timer.Stop();
};
timer.Start();
}
}
}
catch
{
}
}));
return panel;
Border MakeBtn(string mdlIcon, string label, Action action)
{
StackPanel stackPanel = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal
};
stackPanel.Children.Add(new TextBlock
{
Text = mdlIcon,
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 9.0,
Foreground = accentBrush,
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(0.0, 0.0, 3.0, 0.0)
});
stackPanel.Children.Add(new TextBlock
{
Text = label,
FontSize = 10.0,
Foreground = accentBrush,
VerticalAlignment = VerticalAlignment.Center
});
Border border = new Border
{
Child = stackPanel,
Background = System.Windows.Media.Brushes.Transparent,
CornerRadius = new CornerRadius(4.0),
Padding = new Thickness(5.0, 2.0, 5.0, 2.0),
Cursor = System.Windows.Input.Cursors.Hand
};
border.MouseEnter += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border border2)
{
border2.Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(21, 59, 130, 246));
}
};
border.MouseLeave += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border border2)
{
border2.Background = System.Windows.Media.Brushes.Transparent;
}
};
border.MouseLeftButtonUp += delegate
{
action();
};
return border;
}
}
private async Task RegenerateLastAsync()
{
if (_isStreaming)
{
return;
}
ChatConversation conv;
lock (_convLock)
{
if (_currentConversation == null)
{
return;
}
conv = _currentConversation;
}
lock (_convLock)
{
int num;
if (conv.Messages.Count > 0)
{
List<ChatMessage> messages = conv.Messages;
num = ((messages[messages.Count - 1].Role == "assistant") ? 1 : 0);
}
else
{
num = 0;
}
if (num != 0)
{
conv.Messages.RemoveAt(conv.Messages.Count - 1);
}
}
if (MessagePanel.Children.Count > 0)
{
MessagePanel.Children.RemoveAt(MessagePanel.Children.Count - 1);
}
await SendRegenerateAsync(conv);
}
private void ShowRetryWithFeedbackInput()
{
if (_isStreaming)
{
return;
}
System.Windows.Media.Brush background = (TryFindResource("AccentColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.CornflowerBlue;
System.Windows.Media.Brush background2 = (TryFindResource("ItemBackground") as System.Windows.Media.Brush) ?? new SolidColorBrush(System.Windows.Media.Color.FromRgb(42, 43, 64));
System.Windows.Media.Brush brush = (TryFindResource("PrimaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.White;
System.Windows.Media.Brush foreground = (TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
System.Windows.Media.Brush borderBrush = (TryFindResource("BorderColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
Border container = new Border
{
Margin = new Thickness(40.0, 4.0, 40.0, 8.0),
Padding = new Thickness(14.0, 10.0, 14.0, 10.0),
CornerRadius = new CornerRadius(12.0),
Background = background2,
HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch
};
StackPanel stackPanel = new StackPanel();
stackPanel.Children.Add(new TextBlock
{
Text = "?대뼸寃??섏젙?섎㈃ 醫뗭쓣吏€ ?뚮젮二쇱꽭??",
FontSize = 12.0,
Foreground = foreground,
Margin = new Thickness(0.0, 0.0, 0.0, 6.0)
});
System.Windows.Controls.TextBox textBox = new System.Windows.Controls.TextBox
{
MinHeight = 38.0,
MaxHeight = 80.0,
AcceptsReturn = true,
TextWrapping = TextWrapping.Wrap,
FontSize = 13.0,
Background = ((TryFindResource("LauncherBackground") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Black),
Foreground = brush,
CaretBrush = brush,
BorderBrush = borderBrush,
BorderThickness = new Thickness(1.0),
Padding = new Thickness(10.0, 6.0, 10.0, 6.0)
};
stackPanel.Children.Add(textBox);
StackPanel stackPanel2 = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal,
HorizontalAlignment = System.Windows.HorizontalAlignment.Right,
Margin = new Thickness(0.0, 8.0, 0.0, 0.0)
};
Border border = new Border
{
Background = background,
CornerRadius = new CornerRadius(8.0),
Padding = new Thickness(14.0, 6.0, 14.0, 6.0),
Cursor = System.Windows.Input.Cursors.Hand,
Margin = new Thickness(6.0, 0.0, 0.0, 0.0)
};
border.Child = new TextBlock
{
Text = "?ъ떆??,
FontSize = 12.0,
FontWeight = FontWeights.SemiBold,
Foreground = System.Windows.Media.Brushes.White
};
border.MouseEnter += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
((Border)s).Opacity = 0.85;
};
border.MouseLeave += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
((Border)s).Opacity = 1.0;
};
border.MouseLeftButtonUp += delegate
{
string text = textBox.Text.Trim();
if (!string.IsNullOrEmpty(text))
{
MessagePanel.Children.Remove(container);
RetryWithFeedbackAsync(text);
}
};
Border border2 = new Border
{
Background = System.Windows.Media.Brushes.Transparent,
CornerRadius = new CornerRadius(8.0),
Padding = new Thickness(12.0, 6.0, 12.0, 6.0),
Cursor = System.Windows.Input.Cursors.Hand
};
border2.Child = new TextBlock
{
Text = "痍⑥냼",
FontSize = 12.0,
Foreground = foreground
};
border2.MouseLeftButtonUp += delegate
{
MessagePanel.Children.Remove(container);
};
stackPanel2.Children.Add(border2);
stackPanel2.Children.Add(border);
stackPanel.Children.Add(stackPanel2);
container.Child = stackPanel;
ApplyMessageEntryAnimation(container);
MessagePanel.Children.Add(container);
ForceScrollToEnd();
textBox.Focus();
}
private async Task RetryWithFeedbackAsync(string feedback)
{
if (_isStreaming)
{
return;
}
ChatConversation conv;
lock (_convLock)
{
if (_currentConversation == null)
{
return;
}
conv = _currentConversation;
}
lock (_convLock)
{
int num;
if (conv.Messages.Count > 0)
{
List<ChatMessage> messages = conv.Messages;
num = ((messages[messages.Count - 1].Role == "assistant") ? 1 : 0);
}
else
{
num = 0;
}
if (num != 0)
{
conv.Messages.RemoveAt(conv.Messages.Count - 1);
}
}
if (MessagePanel.Children.Count > 0)
{
MessagePanel.Children.RemoveAt(MessagePanel.Children.Count - 1);
}
ChatMessage feedbackMsg = new ChatMessage
{
Role = "user",
Content = "[?댁쟾 ?묐떟???€???섏젙 ?붿껌] " + feedback + "\n\n???쇰뱶諛깆쓣 諛섏쁺?섏뿬 ?ㅼ떆 ?묒꽦?댁<?몄슂."
};
lock (_convLock)
{
conv.Messages.Add(feedbackMsg);
}
AddMessageBubble("user", "[?섏젙 ?붿껌] " + feedback);
await SendRegenerateAsync(conv);
}
private async Task SendRegenerateAsync(ChatConversation conv)
{
_isStreaming = true;
BtnSend.IsEnabled = false;
BtnSend.Visibility = Visibility.Collapsed;
BtnStop.Visibility = Visibility.Visible;
_streamCts = new CancellationTokenSource();
ChatMessage assistantMsg = new ChatMessage
{
Role = "assistant",
Content = ""
};
lock (_convLock)
{
conv.Messages.Add(assistantMsg);
}
TextBlock streamText;
StackPanel streamContainer = CreateStreamingContainer(out streamText);
MessagePanel.Children.Add(streamContainer);
ForceScrollToEnd();
StringBuilder sb = new StringBuilder();
_activeStreamText = streamText;
_cachedStreamContent = "";
_displayedLength = 0;
_cursorVisible = true;
_aiIconPulseStopped = false;
_cursorTimer.Start();
_typingTimer.Start();
_streamStartTime = DateTime.UtcNow;
_elapsedTimer.Start();
SetStatus("?먯씠?꾪듃 ?묒뾽 以?..", spinning: true);
try
{
List<ChatMessage> sendMessages;
lock (_convLock)
{
sendMessages = conv.Messages.SkipLast(1).ToList();
}
if (!string.IsNullOrEmpty(conv.SystemCommand))
{
sendMessages.Insert(0, new ChatMessage
{
Role = "system",
Content = conv.SystemCommand
});
}
await foreach (string chunk in _llm.StreamAsync(sendMessages, _streamCts.Token))
{
sb.Append(chunk);
StopAiIconPulse();
_cachedStreamContent = sb.ToString();
await ((DispatcherObject)this).Dispatcher.InvokeAsync((Action)delegate
{
}, (DispatcherPriority)4);
}
_cachedStreamContent = sb.ToString();
assistantMsg.Content = _cachedStreamContent;
DateTime drainStart2 = DateTime.UtcNow;
while (_displayedLength < _cachedStreamContent.Length && (DateTime.UtcNow - drainStart2).TotalMilliseconds < 600.0)
{
await ((DispatcherObject)this).Dispatcher.InvokeAsync((Action)delegate
{
}, (DispatcherPriority)4);
}
}
catch (OperationCanceledException)
{
if (sb.Length == 0)
{
sb.Append("(痍⑥냼??");
}
assistantMsg.Content = sb.ToString();
}
catch (Exception ex2)
{
Exception ex3 = ex2;
string errMsg = "???ㅻ쪟: " + ex3.Message;
sb.Clear();
sb.Append(errMsg);
assistantMsg.Content = errMsg;
AddRetryButton();
}
finally
{
_cursorTimer.Stop();
_elapsedTimer.Stop();
_typingTimer.Stop();
HideStickyProgress();
StopRainbowGlow();
_activeStreamText = null;
_elapsedLabel = null;
_cachedStreamContent = "";
_isStreaming = false;
BtnSend.IsEnabled = true;
BtnStop.Visibility = Visibility.Collapsed;
BtnSend.Visibility = Visibility.Visible;
_streamCts?.Dispose();
_streamCts = null;
SetStatusIdle();
}
FinalizeStreamingContainer(streamContainer, streamText, assistantMsg.Content, assistantMsg);
AutoScrollIfNeeded();
try
{
_storage.Save(conv);
}
catch (Exception ex4)
{
LogService.Debug("?€???€???ㅽ뙣: " + ex4.Message);
}
_tabConversationId[conv.Tab ?? _activeTab] = conv.Id;
RefreshConversationList();
}
private double GetMessageMaxWidth()
{
double num = MessageScroll.ActualWidth;
if (num < 100.0)
{
num = 700.0;
}
double value = (num - 180.0) * 0.82;
return Math.Clamp(value, 520.0, 900.0);
}
private StackPanel CreateStreamingContainer(out TextBlock streamText)
{
double messageMaxWidth = GetMessageMaxWidth();
StackPanel stackPanel = new StackPanel
{
HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
Width = messageMaxWidth,
MaxWidth = messageMaxWidth,
Margin = new Thickness(40.0, 8.0, 80.0, 8.0),
Opacity = 0.0,
RenderTransform = new TranslateTransform(0.0, 10.0)
};
stackPanel.BeginAnimation(UIElement.OpacityProperty, new DoubleAnimation(0.0, 1.0, TimeSpan.FromMilliseconds(280.0)));
((TranslateTransform)stackPanel.RenderTransform).BeginAnimation(TranslateTransform.YProperty, new DoubleAnimation(10.0, 0.0, TimeSpan.FromMilliseconds(300.0))
{
EasingFunction = new QuadraticEase
{
EasingMode = EasingMode.EaseOut
}
});
Grid grid = new Grid
{
Margin = new Thickness(0.0, 0.0, 0.0, 4.0)
};
grid.ColumnDefinitions.Add(new ColumnDefinition
{
Width = GridLength.Auto
});
grid.ColumnDefinitions.Add(new ColumnDefinition
{
Width = GridLength.Auto
});
grid.ColumnDefinitions.Add(new ColumnDefinition
{
Width = new GridLength(1.0, GridUnitType.Star)
});
TextBlock textBlock = new TextBlock();
textBlock.Text = "\ue8bd";
textBlock.FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets");
textBlock.FontSize = 12.0;
textBlock.Foreground = (TryFindResource("AccentColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Blue;
textBlock.VerticalAlignment = VerticalAlignment.Center;
TextBlock textBlock2 = textBlock;
textBlock2.BeginAnimation(UIElement.OpacityProperty, new DoubleAnimation(1.0, 0.35, TimeSpan.FromMilliseconds(700.0))
{
AutoReverse = true,
RepeatBehavior = RepeatBehavior.Forever,
EasingFunction = new SineEase()
});
_activeAiIcon = textBlock2;
Grid.SetColumn(textBlock2, 0);
grid.Children.Add(textBlock2);
string item = GetAgentIdentity().Name;
textBlock = new TextBlock();
textBlock.Text = item;
textBlock.FontSize = 11.0;
textBlock.FontWeight = FontWeights.SemiBold;
textBlock.Foreground = (TryFindResource("AccentColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Blue;
textBlock.Margin = new Thickness(6.0, 0.0, 0.0, 0.0);
textBlock.VerticalAlignment = VerticalAlignment.Center;
TextBlock element = textBlock;
Grid.SetColumn(element, 1);
grid.Children.Add(element);
_elapsedLabel = new TextBlock
{
Text = "0s",
FontSize = 10.5,
Foreground = ((TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray),
HorizontalAlignment = System.Windows.HorizontalAlignment.Right,
VerticalAlignment = VerticalAlignment.Center,
Opacity = 0.5
};
Grid.SetColumn(_elapsedLabel, 2);
grid.Children.Add(_elapsedLabel);
stackPanel.Children.Add(grid);
streamText = new TextBlock
{
Text = "??,
FontSize = 13.5,
Foreground = ((TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray),
TextWrapping = TextWrapping.Wrap,
LineHeight = 22.0
};
stackPanel.Children.Add(streamText);
return stackPanel;
}
private void FinalizeStreamingContainer(StackPanel container, TextBlock streamText, string finalContent, ChatMessage? message = null)
{
//IL_06ca: Unknown result type (might be due to invalid IL or missing references)
container.Children.Remove(streamText);
System.Windows.Media.Brush textColor = (TryFindResource("PrimaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.White;
System.Windows.Media.Brush secondaryColor = (TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
System.Windows.Media.Brush accentColor = (TryFindResource("AccentColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Blue;
System.Windows.Media.Brush codeBg = (TryFindResource("HintBackground") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.DarkGray;
StackPanel stackPanel = MarkdownRenderer.Render(finalContent, textColor, secondaryColor, accentColor, codeBg);
stackPanel.Margin = new Thickness(0.0, 0.0, 0.0, 4.0);
stackPanel.Opacity = 0.0;
container.Children.Add(stackPanel);
stackPanel.BeginAnimation(UIElement.OpacityProperty, new DoubleAnimation(0.0, 1.0, TimeSpan.FromMilliseconds(180.0)));
System.Windows.Media.Brush brush = (TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
string capturedContent = finalContent;
StackPanel stackPanel2 = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal,
HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
Margin = new Thickness(0.0, 6.0, 0.0, 0.0)
};
stackPanel2.Children.Add(CreateActionButton("\ue8c8", "蹂듭궗", brush, delegate
{
try
{
System.Windows.Clipboard.SetText(capturedContent);
}
catch
{
}
}));
stackPanel2.Children.Add(CreateActionButton("\ue72c", "?ㅼ떆 ?앹꽦", brush, delegate
{
RegenerateLastAsync();
}));
stackPanel2.Children.Add(CreateActionButton("\ue70f", "?섏젙 ???ъ떆??, brush, delegate
{
ShowRetryWithFeedbackInput();
}));
AddLinkedFeedbackButtons(stackPanel2, brush, message);
container.Children.Add(stackPanel2);
TimeSpan timeSpan = DateTime.UtcNow - _streamStartTime;
string text = ((timeSpan.TotalSeconds < 60.0) ? $"{timeSpan.TotalSeconds:0.#}s" : $"{(int)timeSpan.TotalMinutes}m {timeSpan.Seconds}s");
TokenUsage lastTokenUsage = _llm.LastTokenUsage;
string activeTab = _activeTab;
bool flag = ((activeTab == "Cowork" || activeTab == "Code") ? true : false);
bool flag2 = flag;
int num = ((flag2 && _agentCumulativeInputTokens > 0) ? _agentCumulativeInputTokens : (lastTokenUsage?.PromptTokens ?? 0));
int num2 = ((flag2 && _agentCumulativeOutputTokens > 0) ? _agentCumulativeOutputTokens : (lastTokenUsage?.CompletionTokens ?? 0));
if (num > 0 || num2 > 0)
{
UpdateStatusTokens(num, num2);
UsageStatisticsService.RecordTokens(num, num2);
}
string text2 = ((num > 0 || num2 > 0) ? $"{FormatTokenCount(num)} + {FormatTokenCount(num2)} = {FormatTokenCount(num + num2)} tokens" : ((!(lastTokenUsage != null)) ? ("~" + FormatTokenCount(EstimateTokenCount(finalContent)) + " tokens") : $"{FormatTokenCount(lastTokenUsage.PromptTokens)} + {FormatTokenCount(lastTokenUsage.CompletionTokens)} = {FormatTokenCount(lastTokenUsage.TotalTokens)} tokens"));
TextBlock textBlock = new TextBlock();
textBlock.Text = text + " 쨌 " + text2;
textBlock.FontSize = 10.5;
textBlock.Foreground = (TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
textBlock.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
textBlock.Margin = new Thickness(0.0, 6.0, 0.0, 0.0);
textBlock.Opacity = 0.6;
TextBlock element = textBlock;
container.Children.Add(element);
List<(string, string)> list = ParseSuggestionChips(finalContent);
if (list.Count <= 0)
{
return;
}
WrapPanel wrapPanel = new WrapPanel
{
Margin = new Thickness(0.0, 8.0, 0.0, 4.0),
HorizontalAlignment = System.Windows.HorizontalAlignment.Left
};
foreach (var item3 in list)
{
string item = item3.Item1;
string item2 = item3.Item2;
Border border = new Border();
border.Background = (TryFindResource("ItemBackground") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Transparent;
border.BorderBrush = (TryFindResource("BorderColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
border.BorderThickness = new Thickness(1.0);
border.CornerRadius = new CornerRadius(16.0);
border.Padding = new Thickness(14.0, 7.0, 14.0, 7.0);
border.Margin = new Thickness(0.0, 0.0, 8.0, 6.0);
border.Cursor = System.Windows.Input.Cursors.Hand;
border.RenderTransformOrigin = new Point(0.5, 0.5);
border.RenderTransform = new ScaleTransform(1.0, 1.0);
Border border2 = border;
border2.Child = new TextBlock
{
Text = item + ". " + item2,
FontSize = 12.5,
Foreground = ((TryFindResource("PrimaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.White)
};
System.Windows.Media.Brush chipHover = (TryFindResource("ItemHoverBackground") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Transparent;
System.Windows.Media.Brush chipNormal = (TryFindResource("ItemBackground") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Transparent;
border2.MouseEnter += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border { RenderTransform: ScaleTransform renderTransform } border3)
{
renderTransform.ScaleX = 1.02;
renderTransform.ScaleY = 1.02;
border3.Background = chipHover;
}
};
border2.MouseLeave += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border { RenderTransform: ScaleTransform renderTransform } border3)
{
renderTransform.ScaleX = 1.0;
renderTransform.ScaleY = 1.0;
border3.Background = chipNormal;
}
};
string capturedLabel = item + ". " + item2;
WrapPanel capturedPanel = wrapPanel;
border2.MouseLeftButtonDown += delegate
{
if (capturedPanel.Parent is System.Windows.Controls.Panel panel)
{
panel.Children.Remove(capturedPanel);
}
InputBox.Text = capturedLabel;
SendMessageAsync();
};
wrapPanel.Children.Add(border2);
}
container.Children.Add(wrapPanel);
}
private static List<(string Num, string Label)> ParseSuggestionChips(string content)
{
List<(string, string)> list = new List<(string, string)>();
if (string.IsNullOrEmpty(content))
{
return list;
}
string[] array = content.Split('\n');
List<(string, string)> list2 = new List<(string, string)>();
int num = -1;
for (int i = 0; i < array.Length; i++)
{
string text = array[i].Trim();
Match match = Regex.Match(text, "^(\\d+)[.\\)]\\s+(.+)$");
if (match.Success)
{
if (num < 0 || i == num + list2.Count)
{
if (num < 0)
{
num = i;
list2.Clear();
}
list2.Add((match.Groups[1].Value, match.Groups[2].Value.TrimEnd()));
}
else
{
num = i;
list2.Clear();
list2.Add((match.Groups[1].Value, match.Groups[2].Value.TrimEnd()));
}
}
else if (!string.IsNullOrWhiteSpace(text))
{
num = -1;
list2.Clear();
}
}
if (list2.Count >= 2 && list2.Count <= 10)
{
list.AddRange(list2);
}
return list;
}
private static string FormatTokenCount(int count)
{
if (1 == 0)
{
}
string result = ((count >= 1000000) ? $"{(double)count / 1000000.0:0.#}m" : ((count < 1000) ? count.ToString() : $"{(double)count / 1000.0:0.#}k"));
if (1 == 0)
{
}
return result;
}
private static int EstimateTokenCount(string text)
{
if (string.IsNullOrEmpty(text))
{
return 0;
}
int num = 0;
foreach (char c in text)
{
if ((c >= '媛€' && c <= '??) || (c >= '\u3000' && c <= '涌?))
{
num++;
}
}
double num2 = ((text.Length > 0) ? ((double)num / (double)text.Length) : 0.0);
double num3 = 4.0 - num2 * 2.0;
return Math.Max(1, (int)Math.Round((double)text.Length / num3));
}
private void StopGeneration()
{
_streamCts?.Cancel();
}
private void ForkConversation(ChatConversation source, int atIndex)
{
int value = _storage.LoadAllMeta().Count((ChatConversation m) => m.ParentId == source.Id) + 1;
ChatConversation chatConversation = new ChatConversation
{
Title = $"{source.Title} (遺꾧린 {value})",
Tab = source.Tab,
Category = source.Category,
WorkFolder = source.WorkFolder,
SystemCommand = source.SystemCommand,
ParentId = source.Id,
BranchLabel = $"遺꾧린 {value}",
BranchAtIndex = atIndex
};
for (int num = 0; num <= atIndex && num < source.Messages.Count; num++)
{
ChatMessage chatMessage = source.Messages[num];
chatConversation.Messages.Add(new ChatMessage
{
Role = chatMessage.Role,
Content = chatMessage.Content,
Timestamp = chatMessage.Timestamp
});
}
try
{
_storage.Save(chatConversation);
ShowToast("遺꾧린 ?앹꽦: " + chatConversation.Title);
lock (_convLock)
{
_currentConversation = chatConversation;
}
ChatTitle.Text = chatConversation.Title;
RenderMessages();
RefreshConversationList();
}
catch (Exception ex)
{
ShowToast("遺꾧린 ?ㅽ뙣: " + ex.Message, "\ue783");
}
}
private void OpenCommandPalette()
{
CommandPaletteWindow commandPaletteWindow = new CommandPaletteWindow(ExecuteCommand)
{
Owner = this
};
commandPaletteWindow.ShowDialog();
}
private void ExecuteCommand(string commandId)
{
switch (commandId)
{
case "tab:chat":
TabChat.IsChecked = true;
break;
case "tab:cowork":
TabCowork.IsChecked = true;
break;
case "tab:code":
if (TabCode.IsEnabled)
{
TabCode.IsChecked = true;
}
break;
case "new_conversation":
StartNewConversation();
break;
case "search_conversation":
ToggleMessageSearch();
break;
case "change_model":
BtnModelSelector_Click(this, new RoutedEventArgs());
break;
case "open_settings":
BtnSettings_Click(this, new RoutedEventArgs());
break;
case "open_statistics":
new StatisticsWindow().Show();
break;
case "change_folder":
FolderPathLabel_Click(FolderPathLabel, null);
break;
case "toggle_devmode":
{
LlmSettings llm = _settings.Settings.Llm;
llm.DevMode = !llm.DevMode;
_settings.Save();
UpdateAnalyzerButtonVisibility();
ShowToast(llm.DevMode ? "媛쒕컻??紐⑤뱶 耳쒖쭚" : "媛쒕컻??紐⑤뱶 爰쇱쭚");
break;
}
case "open_audit_log":
try
{
Process.Start("explorer.exe", AuditLogService.GetAuditFolder());
break;
}
catch
{
break;
}
case "paste_clipboard":
try
{
string text = System.Windows.Clipboard.GetText();
if (!string.IsNullOrEmpty(text))
{
InputBox.Text += text;
}
break;
}
catch
{
break;
}
case "export_conversation":
ExportConversation();
break;
}
}
private void ExportConversation()
{
ChatConversation currentConversation;
lock (_convLock)
{
currentConversation = _currentConversation;
}
if (currentConversation == null || currentConversation.Messages.Count == 0)
{
return;
}
Microsoft.Win32.SaveFileDialog saveFileDialog = new Microsoft.Win32.SaveFileDialog
{
FileName = (currentConversation.Title ?? ""),
DefaultExt = ".md",
Filter = "Markdown (*.md)|*.md|JSON (*.json)|*.json|HTML (*.html)|*.html|PDF ?몄뇙??HTML (*.pdf.html)|*.pdf.html|Text (*.txt)|*.txt"
};
if (saveFileDialog.ShowDialog() != true)
{
return;
}
string text = System.IO.Path.GetExtension(saveFileDialog.FileName).ToLowerInvariant();
string contents;
if (text == ".json")
{
contents = JsonSerializer.Serialize(currentConversation, new JsonSerializerOptions
{
WriteIndented = true,
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
});
}
else
{
if (saveFileDialog.FileName.EndsWith(".pdf.html"))
{
contents = PdfExportService.BuildHtml(currentConversation);
File.WriteAllText(saveFileDialog.FileName, contents, Encoding.UTF8);
PdfExportService.OpenInBrowser(saveFileDialog.FileName);
ShowToast("PDF ?몄뇙??HTML???앹꽦?섏뼱 釉뚮씪?곗??먯꽌 ?대졇?듬땲??);
return;
}
if (text == ".html")
{
contents = ExportToHtml(currentConversation);
}
else
{
StringBuilder stringBuilder = new StringBuilder();
StringBuilder stringBuilder2 = stringBuilder;
StringBuilder stringBuilder3 = stringBuilder2;
StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(2, 1, stringBuilder2);
handler.AppendLiteral("# ");
handler.AppendFormatted(currentConversation.Title);
stringBuilder3.AppendLine(ref handler);
stringBuilder2 = stringBuilder;
StringBuilder stringBuilder4 = stringBuilder2;
handler = new StringBuilder.AppendInterpolatedStringHandler(13, 2, stringBuilder2);
handler.AppendLiteral("_?앹꽦: ");
handler.AppendFormatted(currentConversation.CreatedAt, "yyyy-MM-dd HH:mm");
handler.AppendLiteral(" 쨌 二쇱젣: ");
handler.AppendFormatted(currentConversation.Category);
handler.AppendLiteral("_");
stringBuilder4.AppendLine(ref handler);
stringBuilder.AppendLine();
foreach (ChatMessage message in currentConversation.Messages)
{
if (!(message.Role == "system"))
{
string value = ((message.Role == "user") ? "**?ъ슜??*" : "**AI**");
stringBuilder2 = stringBuilder;
StringBuilder stringBuilder5 = stringBuilder2;
handler = new StringBuilder.AppendInterpolatedStringHandler(3, 2, stringBuilder2);
handler.AppendFormatted(value);
handler.AppendLiteral(" (");
handler.AppendFormatted(message.Timestamp, "HH:mm");
handler.AppendLiteral(")");
stringBuilder5.AppendLine(ref handler);
stringBuilder.AppendLine();
stringBuilder.AppendLine(message.Content);
List<string> attachedFiles = message.AttachedFiles;
if (attachedFiles != null && attachedFiles.Count > 0)
{
stringBuilder.AppendLine();
stringBuilder.AppendLine("_泥⑤? ?뚯씪: " + string.Join(", ", message.AttachedFiles.Select(System.IO.Path.GetFileName)) + "_");
}
stringBuilder.AppendLine();
stringBuilder.AppendLine("---");
stringBuilder.AppendLine();
}
}
contents = stringBuilder.ToString();
}
}
File.WriteAllText(saveFileDialog.FileName, contents, Encoding.UTF8);
}
private static string ExportToHtml(ChatConversation conv)
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("<!DOCTYPE html><html><head><meta charset=\"utf-8\">");
StringBuilder stringBuilder2 = stringBuilder;
StringBuilder stringBuilder3 = stringBuilder2;
StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(15, 1, stringBuilder2);
handler.AppendLiteral("<title>");
handler.AppendFormatted(WebUtility.HtmlEncode(conv.Title));
handler.AppendLiteral("</title>");
stringBuilder3.AppendLine(ref handler);
stringBuilder.AppendLine("<style>body{font-family:'Segoe UI',sans-serif;max-width:800px;margin:0 auto;padding:20px;background:#1a1a2e;color:#e0e0e0}");
stringBuilder.AppendLine(".msg{margin:12px 0;padding:12px 16px;border-radius:12px}.user{background:#2d2d5e;margin-left:60px}.ai{background:#1e1e3a;margin-right:60px}");
stringBuilder.AppendLine(".meta{font-size:11px;color:#888;margin-bottom:6px}.content{white-space:pre-wrap;line-height:1.6}");
stringBuilder.AppendLine("h1{text-align:center;color:#8b6dff}pre{background:#111;padding:12px;border-radius:8px;overflow-x:auto}</style></head><body>");
stringBuilder2 = stringBuilder;
StringBuilder stringBuilder4 = stringBuilder2;
handler = new StringBuilder.AppendInterpolatedStringHandler(9, 1, stringBuilder2);
handler.AppendLiteral("<h1>");
handler.AppendFormatted(WebUtility.HtmlEncode(conv.Title));
handler.AppendLiteral("</h1>");
stringBuilder4.AppendLine(ref handler);
stringBuilder2 = stringBuilder;
StringBuilder stringBuilder5 = stringBuilder2;
handler = new StringBuilder.AppendInterpolatedStringHandler(55, 2, stringBuilder2);
handler.AppendLiteral("<p style='text-align:center;color:#888'>?앹꽦: ");
handler.AppendFormatted(conv.CreatedAt, "yyyy-MM-dd HH:mm");
handler.AppendLiteral(" 쨌 二쇱젣: ");
handler.AppendFormatted(conv.Category);
handler.AppendLiteral("</p>");
stringBuilder5.AppendLine(ref handler);
foreach (ChatMessage message in conv.Messages)
{
if (!(message.Role == "system"))
{
string value = ((message.Role == "user") ? "user" : "ai");
string value2 = ((message.Role == "user") ? "?ъ슜?? : "AI");
stringBuilder2 = stringBuilder;
StringBuilder stringBuilder6 = stringBuilder2;
handler = new StringBuilder.AppendInterpolatedStringHandler(18, 1, stringBuilder2);
handler.AppendLiteral("<div class='msg ");
handler.AppendFormatted(value);
handler.AppendLiteral("'>");
stringBuilder6.AppendLine(ref handler);
stringBuilder2 = stringBuilder;
StringBuilder stringBuilder7 = stringBuilder2;
handler = new StringBuilder.AppendInterpolatedStringHandler(27, 2, stringBuilder2);
handler.AppendLiteral("<div class='meta'>");
handler.AppendFormatted(value2);
handler.AppendLiteral(" 쨌 ");
handler.AppendFormatted(message.Timestamp, "HH:mm");
handler.AppendLiteral("</div>");
stringBuilder7.AppendLine(ref handler);
stringBuilder2 = stringBuilder;
StringBuilder stringBuilder8 = stringBuilder2;
handler = new StringBuilder.AppendInterpolatedStringHandler(27, 1, stringBuilder2);
handler.AppendLiteral("<div class='content'>");
handler.AppendFormatted(WebUtility.HtmlEncode(message.Content));
handler.AppendLiteral("</div>");
stringBuilder8.AppendLine(ref handler);
stringBuilder.AppendLine("</div>");
}
}
stringBuilder.AppendLine("</body></html>");
return stringBuilder.ToString();
}
private void ChatWindow_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Invalid comparison between Unknown and I4
//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
//IL_01b8: Invalid comparison between Unknown and I4
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Invalid comparison between Unknown and I4
//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
//IL_02d8: Invalid comparison between Unknown and I4
//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
//IL_01d4: Invalid comparison between Unknown and I4
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Expected I4, but got Unknown
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Expected I4, but got Unknown
//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
//IL_01f0: Invalid comparison between Unknown and I4
//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
//IL_01da: Invalid comparison between Unknown and I4
//IL_033c: Unknown result type (might be due to invalid IL or missing references)
//IL_0343: Invalid comparison between Unknown and I4
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Invalid comparison between Unknown and I4
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Expected I4, but got Unknown
//IL_036c: Unknown result type (might be due to invalid IL or missing references)
//IL_0373: Invalid comparison between Unknown and I4
//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
//IL_01fb: Invalid comparison between Unknown and I4
//IL_01de: Unknown result type (might be due to invalid IL or missing references)
//IL_01e2: Invalid comparison between Unknown and I4
//IL_0391: Unknown result type (might be due to invalid IL or missing references)
//IL_0398: Invalid comparison between Unknown and I4
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: Invalid comparison between Unknown and I4
//IL_03b6: Unknown result type (might be due to invalid IL or missing references)
//IL_03bc: Invalid comparison between Unknown and I4
ModifierKeys modifiers = Keyboard.Modifiers;
if ((int)modifiers == 2)
{
Key key = e.Key;
Key val = key;
if ((int)val <= 49)
{
switch (val - 35)
{
default:
switch (val - 45)
{
case 3:
ExportConversation();
e.Handled = true;
break;
case 0:
BtnToggleSidebar_Click(this, new RoutedEventArgs());
e.Handled = true;
break;
case 4:
ToggleMessageSearch();
e.Handled = true;
break;
}
break;
case 0:
TabChat.IsChecked = true;
e.Handled = true;
break;
case 1:
TabCowork.IsChecked = true;
e.Handled = true;
break;
case 2:
if (TabCode.IsEnabled)
{
TabCode.IsChecked = true;
}
e.Handled = true;
break;
}
}
else
{
switch (val - 55)
{
default:
if ((int)val != 66)
{
if ((int)val == 142)
{
BtnSettings_Click(this, new RoutedEventArgs());
e.Handled = true;
}
}
else
{
Close();
e.Handled = true;
}
break;
case 2:
BtnNewChat_Click(this, new RoutedEventArgs());
e.Handled = true;
break;
case 0:
InputBox.Text = "";
InputBox.Focus();
e.Handled = true;
break;
case 1:
BtnModelSelector_Click(this, new RoutedEventArgs());
e.Handled = true;
break;
}
}
}
if ((int)modifiers == 6)
{
Key key2 = e.Key;
Key val2 = key2;
if ((int)val2 <= 47)
{
if ((int)val2 != 46)
{
if ((int)val2 == 47)
{
BtnDeleteAll_Click(this, new RoutedEventArgs());
e.Handled = true;
}
}
else
{
ChatConversation currentConversation;
lock (_convLock)
{
currentConversation = _currentConversation;
}
if (currentConversation != null)
{
ChatMessage chatMessage = currentConversation.Messages.LastOrDefault((ChatMessage m) => m.Role == "assistant");
if (chatMessage != null)
{
try
{
System.Windows.Clipboard.SetText(chatMessage.Content);
}
catch
{
}
}
}
e.Handled = true;
}
}
else if ((int)val2 != 59)
{
if ((int)val2 == 61)
{
RegenerateLastAsync();
e.Handled = true;
}
}
else
{
OpenCommandPalette();
e.Handled = true;
}
}
if ((int)e.Key == 13)
{
if (MessageSearchBar.Visibility == Visibility.Visible)
{
CloseMessageSearch();
e.Handled = true;
}
else if (_isStreaming)
{
StopGeneration();
e.Handled = true;
}
}
if (SlashPopup.IsOpen)
{
if ((int)e.Key == 13)
{
SlashPopup.IsOpen = false;
_slashSelectedIndex = -1;
e.Handled = true;
}
else if ((int)e.Key == 24)
{
SlashPopup_ScrollByDelta(120);
e.Handled = true;
}
else if ((int)e.Key == 26)
{
SlashPopup_ScrollByDelta(-120);
e.Handled = true;
}
else if ((int)e.Key == 6 && _slashSelectedIndex >= 0)
{
e.Handled = true;
ExecuteSlashSelectedItem();
}
}
}
private void BtnStop_Click(object sender, RoutedEventArgs e)
{
StopGeneration();
}
private void BtnPause_Click(object sender, MouseButtonEventArgs e)
{
if (_agentLoop.IsPaused)
{
_agentLoop.Resume();
PauseIcon.Text = "\ue769";
BtnPause.ToolTip = "?쇱떆?뺤?";
}
else
{
_agentLoop.PauseAsync();
PauseIcon.Text = "\ue768";
BtnPause.ToolTip = "?ш컻";
}
}
private void BtnExport_Click(object sender, RoutedEventArgs e)
{
ExportConversation();
}
private void ToggleMessageSearch()
{
if (MessageSearchBar.Visibility == Visibility.Visible)
{
CloseMessageSearch();
return;
}
MessageSearchBar.Visibility = Visibility.Visible;
SearchTextBox.Focus();
SearchTextBox.SelectAll();
}
private void CloseMessageSearch()
{
MessageSearchBar.Visibility = Visibility.Collapsed;
SearchTextBox.Text = "";
SearchResultCount.Text = "";
_searchMatchIndices.Clear();
_searchCurrentIndex = -1;
ClearSearchHighlights();
}
private void SearchTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
string value = SearchTextBox.Text.Trim();
if (string.IsNullOrEmpty(value))
{
SearchResultCount.Text = "";
_searchMatchIndices.Clear();
_searchCurrentIndex = -1;
ClearSearchHighlights();
return;
}
ChatConversation currentConversation;
lock (_convLock)
{
currentConversation = _currentConversation;
}
if (currentConversation == null)
{
return;
}
_searchMatchIndices.Clear();
for (int i = 0; i < currentConversation.Messages.Count; i++)
{
if (currentConversation.Messages[i].Content.Contains(value, StringComparison.OrdinalIgnoreCase))
{
_searchMatchIndices.Add(i);
}
}
if (_searchMatchIndices.Count > 0)
{
_searchCurrentIndex = 0;
SearchResultCount.Text = $"1/{_searchMatchIndices.Count}";
HighlightSearchResult();
}
else
{
_searchCurrentIndex = -1;
SearchResultCount.Text = "寃곌낵 ?놁쓬";
}
}
private void SearchPrev_Click(object sender, RoutedEventArgs e)
{
if (_searchMatchIndices.Count != 0)
{
_searchCurrentIndex = (_searchCurrentIndex - 1 + _searchMatchIndices.Count) % _searchMatchIndices.Count;
SearchResultCount.Text = $"{_searchCurrentIndex + 1}/{_searchMatchIndices.Count}";
HighlightSearchResult();
}
}
private void SearchNext_Click(object sender, RoutedEventArgs e)
{
if (_searchMatchIndices.Count != 0)
{
_searchCurrentIndex = (_searchCurrentIndex + 1) % _searchMatchIndices.Count;
SearchResultCount.Text = $"{_searchCurrentIndex + 1}/{_searchMatchIndices.Count}";
HighlightSearchResult();
}
}
private void SearchClose_Click(object sender, RoutedEventArgs e)
{
CloseMessageSearch();
}
private void HighlightSearchResult()
{
if (_searchCurrentIndex < 0 || _searchCurrentIndex >= _searchMatchIndices.Count)
{
return;
}
int num = _searchMatchIndices[_searchCurrentIndex];
if (num < MessagePanel.Children.Count)
{
if (MessagePanel.Children[num] is FrameworkElement frameworkElement)
{
frameworkElement.BringIntoView();
}
}
else if (MessagePanel.Children.Count > 0)
{
UIElementCollection children = MessagePanel.Children;
(children[children.Count - 1] as FrameworkElement)?.BringIntoView();
}
}
private void ClearSearchHighlights()
{
}
private void AddRetryButton()
{
((DispatcherObject)this).Dispatcher.Invoke((Action)delegate
{
Border border = new Border
{
Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(24, 239, 68, 68)),
CornerRadius = new CornerRadius(8.0),
Padding = new Thickness(12.0, 8.0, 12.0, 8.0),
Margin = new Thickness(40.0, 4.0, 80.0, 4.0),
HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
Cursor = System.Windows.Input.Cursors.Hand
};
StackPanel stackPanel = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal
};
stackPanel.Children.Add(new TextBlock
{
Text = "\ue72c",
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 12.0,
Foreground = new SolidColorBrush(System.Windows.Media.Color.FromRgb(239, 68, 68)),
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(0.0, 0.0, 6.0, 0.0)
});
stackPanel.Children.Add(new TextBlock
{
Text = "?ъ떆??,
FontSize = 12.0,
FontWeight = FontWeights.SemiBold,
Foreground = new SolidColorBrush(System.Windows.Media.Color.FromRgb(239, 68, 68)),
VerticalAlignment = VerticalAlignment.Center
});
border.Child = stackPanel;
border.MouseEnter += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border border2)
{
border2.Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(48, 239, 68, 68));
}
};
border.MouseLeave += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border border2)
{
border2.Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(24, 239, 68, 68));
}
};
border.MouseLeftButtonUp += delegate
{
lock (_convLock)
{
if (_currentConversation != null)
{
int num = _currentConversation.Messages.Count - 1;
if (num >= 0 && _currentConversation.Messages[num].Role == "assistant")
{
_currentConversation.Messages.RemoveAt(num);
}
}
}
RegenerateLastAsync();
};
MessagePanel.Children.Add(border);
ForceScrollToEnd();
});
}
private void ShowMessageContextMenu(string content, string role)
{
ContextMenu menu = CreateThemedContextMenu();
System.Windows.Media.Brush primaryText = (TryFindResource("PrimaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.White;
System.Windows.Media.Brush secondaryText = (TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
AddItem("\ue8c8", "?띿뒪??蹂듭궗", delegate
{
try
{
System.Windows.Clipboard.SetText(content);
ShowToast("蹂듭궗?섏뿀?듬땲??);
}
catch
{
}
});
AddItem("\ue943", "留덊겕?ㅼ슫 蹂듭궗", delegate
{
try
{
System.Windows.Clipboard.SetText(content);
ShowToast("留덊겕?ㅼ슫?쇰줈 蹂듭궗??);
}
catch
{
}
});
AddItem("\ue97a", "?몄슜?섏뿬 ?듭옣", delegate
{
string text = ((content.Length > 200) ? (content.Substring(0, 200) + "...") : content);
string[] source = text.Split('\n');
string text2 = string.Join("\n", source.Select((string l) => "> " + l));
InputBox.Text = text2 + "\n\n";
InputBox.Focus();
InputBox.CaretIndex = InputBox.Text.Length;
});
menu.Items.Add(new Separator());
if (role == "assistant")
{
AddItem("\ue72c", "?묐떟 ?ъ깮??, delegate
{
RegenerateLastAsync();
});
}
AddItem("\ue8a5", "?ш린??遺꾧린", delegate
{
ChatConversation currentConversation;
lock (_convLock)
{
currentConversation = _currentConversation;
}
if (currentConversation != null)
{
int num = currentConversation.Messages.FindLastIndex((ChatMessage m) => m.Role == role && m.Content == content);
if (num >= 0)
{
ForkConversation(currentConversation, num);
}
}
});
menu.Items.Add(new Separator());
string msgContent = content;
string msgRole = role;
AddItem("\ue74d", "?댄썑 硫붿떆吏€ 紐⑤몢 ??젣", delegate
{
ChatConversation currentConversation;
lock (_convLock)
{
currentConversation = _currentConversation;
}
if (currentConversation != null)
{
int num = currentConversation.Messages.FindLastIndex((ChatMessage m) => m.Role == msgRole && m.Content == msgContent);
if (num >= 0)
{
int num2 = currentConversation.Messages.Count - num;
if (System.Windows.MessageBox.Show($"??硫붿떆吏€ ?ы븿 {num2}媛?硫붿떆吏€瑜???젣?섏떆寃좎뒿?덇퉴?", "硫붿떆吏€ ??젣", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes)
{
currentConversation.Messages.RemoveRange(num, num2);
try
{
_storage.Save(currentConversation);
}
catch (Exception ex)
{
LogService.Debug("?€???€???ㅽ뙣: " + ex.Message);
}
RenderMessages();
ShowToast($"{num2}媛?硫붿떆吏€ ??젣??);
}
}
}
});
menu.IsOpen = true;
void AddItem(string icon, string label, Action action)
{
StackPanel stackPanel = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal
};
stackPanel.Children.Add(new TextBlock
{
Text = icon,
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 12.0,
Foreground = secondaryText,
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(0.0, 0.0, 8.0, 0.0)
});
stackPanel.Children.Add(new TextBlock
{
Text = label,
FontSize = 12.0,
Foreground = primaryText,
VerticalAlignment = VerticalAlignment.Center
});
MenuItem menuItem = new MenuItem
{
Header = stackPanel,
Padding = new Thickness(8.0, 6.0, 16.0, 6.0)
};
menuItem.Click += delegate
{
action();
};
menu.Items.Add(menuItem);
}
}
private void ShowRandomTip()
{
if (_settings.Settings.Llm.ShowTips && (!(_activeTab != "Cowork") || !(_activeTab != "Code")))
{
string message = Tips[_tipIndex % Tips.Length];
_tipIndex++;
ShowTip(message);
}
}
private void ShowTip(string message)
{
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Expected O, but got Unknown
DispatcherTimer? tipDismissTimer = _tipDismissTimer;
if (tipDismissTimer != null)
{
tipDismissTimer.Stop();
}
ToastText.Text = message;
ToastIcon.Text = "\ue82f";
ToastBorder.Visibility = Visibility.Visible;
ToastBorder.BeginAnimation(UIElement.OpacityProperty, new DoubleAnimation(0.0, 1.0, TimeSpan.FromMilliseconds(300.0)));
int tipDurationSeconds = _settings.Settings.Llm.TipDurationSeconds;
if (tipDurationSeconds <= 0)
{
return;
}
_tipDismissTimer = new DispatcherTimer
{
Interval = TimeSpan.FromSeconds(tipDurationSeconds)
};
_tipDismissTimer.Tick += delegate
{
_tipDismissTimer.Stop();
DoubleAnimation doubleAnimation = new DoubleAnimation(1.0, 0.0, TimeSpan.FromMilliseconds(300.0));
doubleAnimation.Completed += delegate
{
ToastBorder.Visibility = Visibility.Collapsed;
};
ToastBorder.BeginAnimation(UIElement.OpacityProperty, doubleAnimation);
};
_tipDismissTimer.Start();
}
private static string LoadProjectContext(string workFolder)
{
if (string.IsNullOrEmpty(workFolder))
{
return "";
}
List<string> list = new List<string>();
string text = workFolder;
for (int i = 0; i < 3; i++)
{
if (string.IsNullOrEmpty(text))
{
break;
}
list.Add(text);
text = Directory.GetParent(text)?.FullName;
}
list.Reverse();
HashSet<string> seen = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
List<string> orderedFiles = new List<string>();
foreach (string item in list)
{
AddIfExists(System.IO.Path.Combine(item, "AX.md"));
AddIfExists(System.IO.Path.Combine(item, "AX.local.md"));
AddIfExists(System.IO.Path.Combine(item, ".ax", "AX.md"));
string path = System.IO.Path.Combine(item, ".ax", "rules");
if (!Directory.Exists(path))
{
continue;
}
foreach (string item2 in Directory.GetFiles(path, "*.md").OrderBy<string, string>((string p) => p, StringComparer.OrdinalIgnoreCase))
{
if (seen.Add(item2))
{
orderedFiles.Add(item2);
}
}
}
if (orderedFiles.Count == 0)
{
return "";
}
StringBuilder stringBuilder = new StringBuilder();
foreach (string item3 in orderedFiles)
{
try
{
string text2 = File.ReadAllText(item3);
if (!string.IsNullOrWhiteSpace(text2))
{
if (text2.Length > 6000)
{
text2 = text2.Substring(0, 6000) + "\n... (truncated)";
}
string fileName = System.IO.Path.GetFileName(item3);
string value = (item3.StartsWith(workFolder, StringComparison.OrdinalIgnoreCase) ? System.IO.Path.GetRelativePath(workFolder, item3) : item3);
StringBuilder stringBuilder2 = stringBuilder;
StringBuilder stringBuilder3 = stringBuilder2;
StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(22, 1, stringBuilder2);
handler.AppendLiteral("\n## Project Context (");
handler.AppendFormatted(fileName);
handler.AppendLiteral(")");
stringBuilder3.AppendLine(ref handler);
stringBuilder2 = stringBuilder;
StringBuilder stringBuilder4 = stringBuilder2;
handler = new StringBuilder.AppendInterpolatedStringHandler(8, 1, stringBuilder2);
handler.AppendLiteral("Source: ");
handler.AppendFormatted(value);
stringBuilder4.AppendLine(ref handler);
stringBuilder.AppendLine(text2);
}
}
catch
{
}
}
return stringBuilder.ToString();
void AddIfExists(string text3)
{
if (File.Exists(text3) && seen.Add(text3))
{
orderedFiles.Add(text3);
}
}
}
private void PlayRainbowGlow()
{
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_009a: Expected O, but got Unknown
if (!_settings.Settings.Llm.EnableChatRainbowGlow)
{
return;
}
DispatcherTimer? rainbowTimer = _rainbowTimer;
if (rainbowTimer != null)
{
rainbowTimer.Stop();
}
_rainbowStartTime = DateTime.UtcNow;
InputGlowBorder.BeginAnimation(UIElement.OpacityProperty, new DoubleAnimation(0.0, 0.9, TimeSpan.FromMilliseconds(150.0)));
_rainbowTimer = new DispatcherTimer
{
Interval = TimeSpan.FromMilliseconds(16.0)
};
_rainbowTimer.Tick += delegate
{
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
double totalMilliseconds = (DateTime.UtcNow - _rainbowStartTime).TotalMilliseconds;
double num = totalMilliseconds / 1500.0 % 1.0;
if (InputGlowBorder.BorderBrush is LinearGradientBrush linearGradientBrush)
{
double num2 = num * Math.PI * 2.0;
linearGradientBrush.StartPoint = new Point(0.5 + 0.5 * Math.Cos(num2), 0.5 + 0.5 * Math.Sin(num2));
linearGradientBrush.EndPoint = new Point(0.5 - 0.5 * Math.Cos(num2), 0.5 - 0.5 * Math.Sin(num2));
}
};
_rainbowTimer.Start();
}
private void StopRainbowGlow()
{
DispatcherTimer? rainbowTimer = _rainbowTimer;
if (rainbowTimer != null)
{
rainbowTimer.Stop();
}
_rainbowTimer = null;
if (InputGlowBorder.Opacity > 0.0)
{
DoubleAnimation doubleAnimation = new DoubleAnimation(InputGlowBorder.Opacity, 0.0, TimeSpan.FromMilliseconds(600.0));
doubleAnimation.Completed += delegate
{
InputGlowBorder.Opacity = 0.0;
};
InputGlowBorder.BeginAnimation(UIElement.OpacityProperty, doubleAnimation);
}
}
private void ShowToast(string message, string icon = "\ue73e", int durationMs = 2000)
{
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Expected O, but got Unknown
DispatcherTimer? toastHideTimer = _toastHideTimer;
if (toastHideTimer != null)
{
toastHideTimer.Stop();
}
ToastText.Text = message;
ToastIcon.Text = icon;
ToastBorder.Visibility = Visibility.Visible;
ToastBorder.BeginAnimation(UIElement.OpacityProperty, new DoubleAnimation(0.0, 1.0, TimeSpan.FromMilliseconds(200.0)));
_toastHideTimer = new DispatcherTimer
{
Interval = TimeSpan.FromMilliseconds(durationMs)
};
_toastHideTimer.Tick += delegate
{
_toastHideTimer.Stop();
DoubleAnimation doubleAnimation = new DoubleAnimation(1.0, 0.0, TimeSpan.FromMilliseconds(300.0));
doubleAnimation.Completed += delegate
{
ToastBorder.Visibility = Visibility.Collapsed;
};
ToastBorder.BeginAnimation(UIElement.OpacityProperty, doubleAnimation);
};
_toastHideTimer.Start();
}
private void BuildTopicButtons()
{
//IL_022e: Unknown result type (might be due to invalid IL or missing references)
//IL_07bc: Unknown result type (might be due to invalid IL or missing references)
//IL_0bd7: Unknown result type (might be due to invalid IL or missing references)
TopicButtonPanel.Children.Clear();
TopicButtonPanel.Visibility = Visibility.Visible;
if (_activeTab == "Cowork" || _activeTab == "Code")
{
if (EmptyStateTitle != null)
{
EmptyStateTitle.Text = "?묒뾽 ?좏삎???좏깮?섏꽭??;
}
if (EmptyStateDesc != null)
{
EmptyStateDesc.Text = ((_activeTab == "Code") ? "肄붾뵫 ?먯씠?꾪듃媛€ 肄붾뱶 遺꾩꽍, ?섏젙, 鍮뚮뱶, ?뚯뒪?몃? ?섑뻾?⑸땲?? : "?먯씠?꾪듃媛€ ?곸꽭???곗씠?곕? ?묒꽦?⑸땲??);
}
}
else
{
if (EmptyStateTitle != null)
{
EmptyStateTitle.Text = "?€??二쇱젣瑜??좏깮?섏꽭??;
}
if (EmptyStateDesc != null)
{
EmptyStateDesc.Text = "二쇱젣??留욌뒗 ?꾨Ц ?꾨━?뗭씠 ?먮룞 ?곸슜?⑸땲??;
}
}
IReadOnlyList<TopicPreset> byTabWithCustom = PresetService.GetByTabWithCustom(_activeTab, _settings.Settings.Llm.CustomPresets);
Border border;
foreach (TopicPreset item in byTabWithCustom)
{
TopicPreset capturedPreset = item;
SolidColorBrush solidColorBrush = BrushFromHex(item.Color);
border = new Border();
border.Background = (TryFindResource("ItemBackground") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Transparent;
border.CornerRadius = new CornerRadius(14.0);
border.Padding = new Thickness(14.0, 12.0, 14.0, 12.0);
border.Margin = new Thickness(4.0, 4.0, 4.0, 8.0);
border.Cursor = System.Windows.Input.Cursors.Hand;
border.Width = 120.0;
border.Height = 105.0;
border.ClipToBounds = true;
border.RenderTransformOrigin = new Point(0.5, 0.5);
border.RenderTransform = new ScaleTransform(1.0, 1.0);
Border border2 = border;
StackPanel stackPanel = new StackPanel
{
HorizontalAlignment = System.Windows.HorizontalAlignment.Center
};
Border border3 = new Border
{
Width = 40.0,
Height = 40.0,
CornerRadius = new CornerRadius(20.0),
Background = new SolidColorBrush(solidColorBrush.Color)
{
Opacity = 0.15
},
HorizontalAlignment = System.Windows.HorizontalAlignment.Center,
Margin = new Thickness(0.0, 0.0, 0.0, 10.0)
};
TextBlock child = new TextBlock
{
Text = item.Symbol,
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 18.0,
Foreground = solidColorBrush,
HorizontalAlignment = System.Windows.HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
border3.Child = child;
stackPanel.Children.Add(border3);
stackPanel.Children.Add(new TextBlock
{
Text = item.Label,
FontSize = 13.0,
FontWeight = FontWeights.SemiBold,
Foreground = ((TryFindResource("PrimaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.White),
HorizontalAlignment = System.Windows.HorizontalAlignment.Center
});
stackPanel.Children.Add(new TextBlock
{
Text = item.Description,
FontSize = 9.0,
TextWrapping = TextWrapping.Wrap,
TextTrimming = TextTrimming.CharacterEllipsis,
MaxHeight = 28.0,
Foreground = ((TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray),
HorizontalAlignment = System.Windows.HorizontalAlignment.Center,
Margin = new Thickness(0.0, 2.0, 0.0, 0.0),
TextAlignment = TextAlignment.Center
});
if (capturedPreset.IsCustom)
{
Grid grid = new Grid();
grid.Children.Add(stackPanel);
Border border4 = new Border
{
Width = 16.0,
Height = 16.0,
CornerRadius = new CornerRadius(4.0),
Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(96, byte.MaxValue, byte.MaxValue, byte.MaxValue)),
HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top,
Margin = new Thickness(2.0, 2.0, 0.0, 0.0),
ToolTip = "而ㅼ뒪?€ ?꾨━??
};
border4.Child = new TextBlock
{
Text = "\ue710",
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 8.0,
Foreground = solidColorBrush,
HorizontalAlignment = System.Windows.HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
grid.Children.Add(border4);
border2.Child = grid;
}
else
{
border2.Child = stackPanel;
}
System.Windows.Media.Brush hoverBg = (TryFindResource("ItemHoverBackground") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Transparent;
System.Windows.Media.Brush normalBg = (TryFindResource("ItemBackground") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Transparent;
border2.MouseEnter += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border { RenderTransform: ScaleTransform renderTransform } border8)
{
renderTransform.ScaleX = 1.03;
renderTransform.ScaleY = 1.03;
border8.Background = hoverBg;
}
};
border2.MouseLeave += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border { RenderTransform: ScaleTransform renderTransform } border8)
{
renderTransform.ScaleX = 1.0;
renderTransform.ScaleY = 1.0;
border8.Background = normalBg;
}
};
border2.MouseLeftButtonDown += delegate
{
SelectTopic(capturedPreset);
};
if (capturedPreset.IsCustom)
{
border2.MouseRightButtonUp += delegate(object s, MouseButtonEventArgs e)
{
e.Handled = true;
ShowCustomPresetContextMenu(s as Border, capturedPreset);
};
}
TopicButtonPanel.Children.Add(border2);
}
SolidColorBrush solidColorBrush2 = BrushFromHex("#6B7280");
border = new Border();
border.Background = (TryFindResource("ItemBackground") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Transparent;
border.CornerRadius = new CornerRadius(14.0);
border.Padding = new Thickness(14.0, 12.0, 14.0, 12.0);
border.Margin = new Thickness(4.0, 4.0, 4.0, 8.0);
border.Cursor = System.Windows.Input.Cursors.Hand;
border.Width = 120.0;
border.Height = 105.0;
border.ClipToBounds = true;
border.RenderTransformOrigin = new Point(0.5, 0.5);
border.RenderTransform = new ScaleTransform(1.0, 1.0);
Border border5 = border;
StackPanel stackPanel2 = new StackPanel
{
HorizontalAlignment = System.Windows.HorizontalAlignment.Center
};
Border border6 = new Border
{
Width = 40.0,
Height = 40.0,
CornerRadius = new CornerRadius(20.0),
Background = new SolidColorBrush(solidColorBrush2.Color)
{
Opacity = 0.15
},
HorizontalAlignment = System.Windows.HorizontalAlignment.Center,
Margin = new Thickness(0.0, 0.0, 0.0, 10.0)
};
border6.Child = new TextBlock
{
Text = "\ue70f",
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 18.0,
Foreground = solidColorBrush2,
HorizontalAlignment = System.Windows.HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
stackPanel2.Children.Add(border6);
stackPanel2.Children.Add(new TextBlock
{
Text = "湲고?",
FontSize = 13.0,
FontWeight = FontWeights.SemiBold,
Foreground = ((TryFindResource("PrimaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.White),
HorizontalAlignment = System.Windows.HorizontalAlignment.Center
});
stackPanel2.Children.Add(new TextBlock
{
Text = "?꾨━???놁씠 ?먯쑀濡?쾶 ?€?뷀빀?덈떎",
FontSize = 9.0,
TextWrapping = TextWrapping.Wrap,
TextTrimming = TextTrimming.CharacterEllipsis,
MaxHeight = 28.0,
Foreground = ((TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray),
HorizontalAlignment = System.Windows.HorizontalAlignment.Center,
Margin = new Thickness(0.0, 2.0, 0.0, 0.0),
TextAlignment = TextAlignment.Center
});
border5.Child = stackPanel2;
System.Windows.Media.Brush hoverBg2 = (TryFindResource("ItemHoverBackground") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Transparent;
System.Windows.Media.Brush normalBg2 = (TryFindResource("ItemBackground") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Transparent;
border5.MouseEnter += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border { RenderTransform: ScaleTransform renderTransform } border8)
{
renderTransform.ScaleX = 1.03;
renderTransform.ScaleY = 1.03;
border8.Background = hoverBg2;
}
};
border5.MouseLeave += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border { RenderTransform: ScaleTransform renderTransform } border8)
{
renderTransform.ScaleX = 1.0;
renderTransform.ScaleY = 1.0;
border8.Background = normalBg2;
}
};
border5.MouseLeftButtonDown += delegate
{
EmptyState.Visibility = Visibility.Collapsed;
InputBox.Focus();
};
TopicButtonPanel.Children.Add(border5);
SolidColorBrush solidColorBrush3 = BrushFromHex("#6366F1");
border = new Border();
border.Background = System.Windows.Media.Brushes.Transparent;
border.CornerRadius = new CornerRadius(14.0);
border.Padding = new Thickness(14.0, 12.0, 14.0, 12.0);
border.Margin = new Thickness(4.0, 4.0, 4.0, 8.0);
border.Cursor = System.Windows.Input.Cursors.Hand;
border.Width = 120.0;
border.Height = 105.0;
border.ClipToBounds = true;
border.BorderBrush = (TryFindResource("BorderColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
border.BorderThickness = new Thickness(1.5);
border.RenderTransformOrigin = new Point(0.5, 0.5);
border.RenderTransform = new ScaleTransform(1.0, 1.0);
Border border7 = border;
if (border7.BorderBrush is SolidColorBrush brush)
{
System.Windows.Media.Pen pen = new System.Windows.Media.Pen(brush, 1.5)
{
DashStyle = DashStyles.Dash
};
}
StackPanel stackPanel3 = new StackPanel
{
HorizontalAlignment = System.Windows.HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
TextBlock textBlock = new TextBlock();
textBlock.Text = "\ue710";
textBlock.FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets");
textBlock.FontSize = 24.0;
textBlock.Foreground = (TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
textBlock.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
textBlock.Margin = new Thickness(0.0, 8.0, 0.0, 8.0);
TextBlock element = textBlock;
stackPanel3.Children.Add(element);
stackPanel3.Children.Add(new TextBlock
{
Text = "?꾨━??異붽?",
FontSize = 12.0,
Foreground = ((TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray),
HorizontalAlignment = System.Windows.HorizontalAlignment.Center
});
border7.Child = stackPanel3;
System.Windows.Media.Brush hoverBg3 = (TryFindResource("ItemHoverBackground") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Transparent;
border7.MouseEnter += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border { RenderTransform: ScaleTransform renderTransform } border8)
{
renderTransform.ScaleX = 1.03;
renderTransform.ScaleY = 1.03;
border8.Background = hoverBg3;
}
};
border7.MouseLeave += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border { RenderTransform: ScaleTransform renderTransform } border8)
{
renderTransform.ScaleX = 1.0;
renderTransform.ScaleY = 1.0;
border8.Background = System.Windows.Media.Brushes.Transparent;
}
};
border7.MouseLeftButtonDown += delegate
{
ShowCustomPresetDialog();
};
TopicButtonPanel.Children.Add(border7);
}
private void ShowCustomPresetDialog(CustomPresetEntry? existing = null)
{
bool flag = existing != null;
CustomPresetDialog customPresetDialog = new CustomPresetDialog(existing?.Label ?? "", existing?.Description ?? "", existing?.SystemPrompt ?? "", existing?.Color ?? "#6366F1", existing?.Symbol ?? "\ue713", existing?.Tab ?? _activeTab)
{
Owner = this
};
if (customPresetDialog.ShowDialog() == true)
{
if (flag)
{
existing.Label = customPresetDialog.PresetName;
existing.Description = customPresetDialog.PresetDescription;
existing.SystemPrompt = customPresetDialog.PresetSystemPrompt;
existing.Color = customPresetDialog.PresetColor;
existing.Symbol = customPresetDialog.PresetSymbol;
existing.Tab = customPresetDialog.PresetTab;
}
else
{
_settings.Settings.Llm.CustomPresets.Add(new CustomPresetEntry
{
Label = customPresetDialog.PresetName,
Description = customPresetDialog.PresetDescription,
SystemPrompt = customPresetDialog.PresetSystemPrompt,
Color = customPresetDialog.PresetColor,
Symbol = customPresetDialog.PresetSymbol,
Tab = customPresetDialog.PresetTab
});
}
_settings.Save();
BuildTopicButtons();
}
}
private void ShowCustomPresetContextMenu(Border? anchor, TopicPreset preset)
{
if (anchor == null || preset.CustomId == null)
{
return;
}
Popup popup = new Popup
{
PlacementTarget = anchor,
Placement = PlacementMode.Bottom,
StaysOpen = false,
AllowsTransparency = true
};
System.Windows.Media.Brush background = (TryFindResource("LauncherBackground") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Black;
System.Windows.Media.Brush fg = (TryFindResource("PrimaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.White;
System.Windows.Media.Brush secondaryFg = (TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
System.Windows.Media.Brush borderBrush = (TryFindResource("BorderColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
Border border = new Border
{
Background = background,
CornerRadius = new CornerRadius(10.0),
BorderBrush = borderBrush,
BorderThickness = new Thickness(1.0),
Padding = new Thickness(4.0),
MinWidth = 120.0,
Effect = new DropShadowEffect
{
BlurRadius = 12.0,
ShadowDepth = 2.0,
Opacity = 0.3,
Color = Colors.Black
}
};
StackPanel stackPanel = new StackPanel();
Border border2 = CreateContextMenuItem("\ue70f", "?몄쭛", fg, secondaryFg);
border2.MouseLeftButtonDown += delegate
{
popup.IsOpen = false;
CustomPresetEntry customPresetEntry = _settings.Settings.Llm.CustomPresets.FirstOrDefault((CustomPresetEntry c) => c.Id == preset.CustomId);
if (customPresetEntry != null)
{
ShowCustomPresetDialog(customPresetEntry);
}
};
stackPanel.Children.Add(border2);
Border border3 = CreateContextMenuItem("\ue74d", "??젣", new SolidColorBrush(System.Windows.Media.Color.FromRgb(239, 68, 68)), secondaryFg);
border3.MouseLeftButtonDown += delegate
{
popup.IsOpen = false;
MessageBoxResult messageBoxResult = CustomMessageBox.Show("'" + preset.Label + "' ?꾨━?뗭쓣 ??젣?섏떆寃좎뒿?덇퉴?", "?꾨━????젣", MessageBoxButton.YesNo, MessageBoxImage.Question);
if (messageBoxResult == MessageBoxResult.Yes)
{
_settings.Settings.Llm.CustomPresets.RemoveAll((CustomPresetEntry c) => c.Id == preset.CustomId);
_settings.Save();
BuildTopicButtons();
}
};
stackPanel.Children.Add(border3);
border.Child = stackPanel;
popup.Child = border;
popup.IsOpen = true;
}
private Border CreateContextMenuItem(string icon, string label, System.Windows.Media.Brush fg, System.Windows.Media.Brush secondaryFg)
{
Border border = new Border
{
Background = System.Windows.Media.Brushes.Transparent,
CornerRadius = new CornerRadius(6.0),
Padding = new Thickness(10.0, 6.0, 14.0, 6.0),
Cursor = System.Windows.Input.Cursors.Hand
};
StackPanel stackPanel = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal
};
stackPanel.Children.Add(new TextBlock
{
Text = icon,
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 13.0,
Foreground = fg,
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(0.0, 0.0, 8.0, 0.0)
});
stackPanel.Children.Add(new TextBlock
{
Text = label,
FontSize = 13.0,
Foreground = fg,
VerticalAlignment = VerticalAlignment.Center
});
border.Child = stackPanel;
System.Windows.Media.Brush hoverBg = (TryFindResource("ItemHoverBackground") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Transparent;
border.MouseEnter += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border border2)
{
border2.Background = hoverBg;
}
};
border.MouseLeave += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border border2)
{
border2.Background = System.Windows.Media.Brushes.Transparent;
}
};
return border;
}
private void SelectTopic(TopicPreset preset)
{
bool flag;
lock (_convLock)
{
ChatConversation? currentConversation = _currentConversation;
flag = currentConversation != null && currentConversation.Messages.Count > 0;
}
bool flag2 = !string.IsNullOrEmpty(InputBox.Text);
bool flag3 = flag || flag2;
if (!flag3)
{
StartNewConversation();
}
lock (_convLock)
{
if (_currentConversation != null)
{
_currentConversation.SystemCommand = preset.SystemPrompt;
_currentConversation.Category = preset.Category;
}
}
if (!flag3)
{
EmptyState.Visibility = Visibility.Collapsed;
}
InputBox.Focus();
if (!string.IsNullOrEmpty(preset.Placeholder))
{
_promptCardPlaceholder = preset.Placeholder;
if (!flag3)
{
ShowPlaceholder();
}
}
if (flag3)
{
ShowToast("?꾨━??蹂€寃? " + preset.Label);
}
if (_activeTab == "Cowork")
{
BuildBottomBar();
}
}
private void BuildBottomBar()
{
MoodIconPanel.Children.Clear();
System.Windows.Media.Brush brush = (TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
string key = _settings.Settings.Llm.DefaultOutputFormat ?? "auto";
string formatLabel = GetFormatLabel(key);
Border border = CreateFolderBarButton("\ue9f9", formatLabel, "蹂닿퀬???뺥깭 ?좏깮", "#8B5CF6");
border.MouseLeftButtonUp += delegate(object _, MouseButtonEventArgs e)
{
e.Handled = true;
ShowFormatMenu();
};
try
{
RegisterName("BtnFormatMenu", border);
}
catch
{
try
{
UnregisterName("BtnFormatMenu");
RegisterName("BtnFormatMenu", border);
}
catch
{
}
}
MoodIconPanel.Children.Add(border);
MoodIconPanel.Children.Add(new Border
{
Width = 1.0,
Height = 18.0,
Background = ((TryFindResource("SeparatorColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray),
Margin = new Thickness(4.0, 0.0, 4.0, 0.0),
VerticalAlignment = VerticalAlignment.Center
});
TemplateMood templateMood = TemplateService.AllMoods.FirstOrDefault((TemplateMood m) => m.Key == _selectedMood);
string text = templateMood?.Label ?? "紐⑤뜕";
string text2 = templateMood?.Icon ?? "\ud83d\udd37";
Border border2 = CreateFolderBarButton(null, text2 + " " + text, "?붿옄??臾대뱶 ?좏깮");
border2.MouseLeftButtonUp += delegate(object _, MouseButtonEventArgs e)
{
e.Handled = true;
ShowMoodMenu();
};
try
{
RegisterName("BtnMoodMenu", border2);
}
catch
{
try
{
UnregisterName("BtnMoodMenu");
RegisterName("BtnMoodMenu", border2);
}
catch
{
}
}
MoodIconPanel.Children.Add(border2);
MoodIconPanel.Children.Add(new Border
{
Width = 1.0,
Height = 18.0,
Background = ((TryFindResource("SeparatorColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray),
Margin = new Thickness(4.0, 0.0, 4.0, 0.0),
VerticalAlignment = VerticalAlignment.Center
});
Border border3 = CreateFolderBarButton("\ued25", "?뚯씪", "?뚯씪 ?먯깋湲??닿린/?リ린", "#D97706");
border3.MouseLeftButtonUp += delegate(object _, MouseButtonEventArgs e)
{
e.Handled = true;
ToggleFileBrowser();
};
MoodIconPanel.Children.Add(border3);
AppendLogLevelButton();
if (FormatMoodSeparator != null)
{
FormatMoodSeparator.Visibility = Visibility.Visible;
}
}
private void BuildCodeBottomBar()
{
MoodIconPanel.Children.Clear();
System.Windows.Media.Brush brush = (TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
string selectedLanguage = _selectedLanguage;
if (1 == 0)
{
}
string text = selectedLanguage switch
{
"python" => "\ud83d\udc0d Python",
"java" => "??Java",
"csharp" => "\ud83d\udd37 C#",
"cpp" => "??C++",
"javascript" => "\ud83c\udf10 JavaScript",
_ => "\ud83d\udd27 ?먮룞 媛먯?",
};
if (1 == 0)
{
}
string label = text;
Border border = CreateFolderBarButton(null, label, "媛쒕컻 ?몄뼱 ?좏깮");
border.MouseLeftButtonUp += delegate(object _, MouseButtonEventArgs e)
{
e.Handled = true;
ShowLanguageMenu();
};
try
{
RegisterName("BtnLangMenu", border);
}
catch
{
try
{
UnregisterName("BtnLangMenu");
RegisterName("BtnLangMenu", border);
}
catch
{
}
}
MoodIconPanel.Children.Add(border);
MoodIconPanel.Children.Add(new Border
{
Width = 1.0,
Height = 18.0,
Background = ((TryFindResource("SeparatorColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray),
Margin = new Thickness(4.0, 0.0, 4.0, 0.0),
VerticalAlignment = VerticalAlignment.Center
});
Border border2 = CreateFolderBarButton("\ued25", "?뚯씪", "?뚯씪 ?먯깋湲??닿린/?リ린", "#D97706");
border2.MouseLeftButtonUp += delegate(object _, MouseButtonEventArgs e)
{
e.Handled = true;
ToggleFileBrowser();
};
MoodIconPanel.Children.Add(border2);
AppendLogLevelButton();
if (FormatMoodSeparator != null)
{
FormatMoodSeparator.Visibility = Visibility.Visible;
}
}
private void AppendLogLevelButton()
{
MoodIconPanel.Children.Add(new Border
{
Width = 1.0,
Height = 18.0,
Background = ((TryFindResource("SeparatorColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray),
Margin = new Thickness(4.0, 0.0, 4.0, 0.0),
VerticalAlignment = VerticalAlignment.Center
});
string text = _settings.Settings.Llm.AgentLogLevel ?? "simple";
if (1 == 0)
{
}
string text2 = ((text == "debug") ? "?붾쾭洹? : ((!(text == "detailed")) ? "媛꾨왂" : "?곸꽭"));
if (1 == 0)
{
}
string label = text2;
Border border = CreateFolderBarButton("\ue946", label, "?ㅽ뻾 ?대젰 ?곸꽭??, "#059669");
border.MouseLeftButtonUp += delegate(object _, MouseButtonEventArgs e)
{
e.Handled = true;
ShowLogLevelMenu();
};
try
{
RegisterName("BtnLogLevelMenu", border);
}
catch
{
try
{
UnregisterName("BtnLogLevelMenu");
RegisterName("BtnLogLevelMenu", border);
}
catch
{
}
}
MoodIconPanel.Children.Add(border);
}
private void ShowLogLevelMenu()
{
FormatMenuItems.Children.Clear();
System.Windows.Media.Brush brush = (TryFindResource("PrimaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.White;
System.Windows.Media.Brush brush2 = (TryFindResource("AccentColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.CornflowerBlue;
System.Windows.Media.Brush foreground = (TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
(string, string, string)[] array = new(string, string, string)[3]
{
("simple", "Simple (媛꾨왂)", "?꾧뎄 寃곌낵留???以꾨줈 ?쒖떆"),
("detailed", "Detailed (?곸꽭)", "?꾧뎄 ?몄텧/寃곌낵 + ?묒씠???곸꽭"),
("debug", "Debug (?붾쾭洹?", "紐⑤뱺 ?뺣낫 + ?뚮씪誘명꽣 ?쒖떆")
};
string text = _settings.Settings.Llm.AgentLogLevel ?? "simple";
(string, string, string)[] array2 = array;
for (int i = 0; i < array2.Length; i++)
{
(string, string, string) tuple = array2[i];
string key = tuple.Item1;
string item = tuple.Item2;
string item2 = tuple.Item3;
bool flag = text == key;
StackPanel stackPanel = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal
};
stackPanel.Children.Add(CreateCheckIcon(flag, brush2));
stackPanel.Children.Add(new TextBlock
{
Text = item,
FontSize = 13.0,
Foreground = (flag ? brush2 : brush),
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(0.0, 0.0, 8.0, 0.0)
});
stackPanel.Children.Add(new TextBlock
{
Text = item2,
FontSize = 10.0,
Foreground = foreground,
VerticalAlignment = VerticalAlignment.Center
});
Border border = new Border
{
Child = stackPanel,
Padding = new Thickness(12.0, 8.0, 12.0, 8.0),
CornerRadius = new CornerRadius(6.0),
Background = System.Windows.Media.Brushes.Transparent,
Cursor = System.Windows.Input.Cursors.Hand
};
System.Windows.Media.Brush hoverBg = (TryFindResource("ItemHoverBackground") as System.Windows.Media.Brush) ?? new SolidColorBrush(System.Windows.Media.Color.FromArgb(24, byte.MaxValue, byte.MaxValue, byte.MaxValue));
border.MouseEnter += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
((Border)s).Background = hoverBg;
};
border.MouseLeave += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
((Border)s).Background = System.Windows.Media.Brushes.Transparent;
};
border.MouseLeftButtonUp += delegate
{
_settings.Settings.Llm.AgentLogLevel = key;
_settings.Save();
FormatMenuPopup.IsOpen = false;
if (_activeTab == "Cowork")
{
BuildBottomBar();
}
else if (_activeTab == "Code")
{
BuildCodeBottomBar();
}
};
FormatMenuItems.Children.Add(border);
}
try
{
if (FindName("BtnLogLevelMenu") is UIElement placementTarget)
{
FormatMenuPopup.PlacementTarget = placementTarget;
}
}
catch
{
}
FormatMenuPopup.IsOpen = true;
}
private void ShowLanguageMenu()
{
FormatMenuItems.Children.Clear();
System.Windows.Media.Brush brush = (TryFindResource("PrimaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.White;
System.Windows.Media.Brush brush2 = (TryFindResource("AccentColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.CornflowerBlue;
(string, string, string)[] array = new(string, string, string)[6]
{
("auto", "?먮룞 媛먯?", "\ud83d\udd27"),
("python", "Python", "\ud83d\udc0d"),
("java", "Java", "??),
("csharp", "C# (.NET)", "\ud83d\udd37"),
("cpp", "C/C++", "??),
("javascript", "JavaScript / Vue", "\ud83c\udf10")
};
(string, string, string)[] array2 = array;
for (int i = 0; i < array2.Length; i++)
{
(string, string, string) tuple = array2[i];
string item = tuple.Item1;
string item2 = tuple.Item2;
string item3 = tuple.Item3;
bool flag = _selectedLanguage == item;
StackPanel stackPanel = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal
};
stackPanel.Children.Add(CreateCheckIcon(flag, brush2));
stackPanel.Children.Add(new TextBlock
{
Text = item3,
FontSize = 13.0,
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(0.0, 0.0, 8.0, 0.0)
});
stackPanel.Children.Add(new TextBlock
{
Text = item2,
FontSize = 13.0,
Foreground = (flag ? brush2 : brush),
FontWeight = (flag ? FontWeights.SemiBold : FontWeights.Normal)
});
Border border = new Border
{
Child = stackPanel,
Background = System.Windows.Media.Brushes.Transparent,
CornerRadius = new CornerRadius(8.0),
Cursor = System.Windows.Input.Cursors.Hand,
Padding = new Thickness(8.0, 7.0, 12.0, 7.0)
};
ApplyMenuItemHover(border);
string capturedKey = item;
border.MouseLeftButtonUp += delegate
{
FormatMenuPopup.IsOpen = false;
_selectedLanguage = capturedKey;
BuildCodeBottomBar();
};
FormatMenuItems.Children.Add(border);
}
if (FindName("BtnLangMenu") is UIElement placementTarget)
{
FormatMenuPopup.PlacementTarget = placementTarget;
}
FormatMenuPopup.IsOpen = true;
}
private Border CreateFolderBarButton(string? mdlIcon, string label, string tooltip, string? iconColorHex = null)
{
System.Windows.Media.Brush brush = (TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
System.Windows.Media.Brush foreground = ((iconColorHex != null) ? BrushFromHex(iconColorHex) : brush);
StackPanel stackPanel = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal
};
if (mdlIcon != null)
{
stackPanel.Children.Add(new TextBlock
{
Text = mdlIcon,
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 12.0,
Foreground = foreground,
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(0.0, 0.0, 4.0, 0.0)
});
}
stackPanel.Children.Add(new TextBlock
{
Text = label,
FontSize = 12.0,
Foreground = brush,
VerticalAlignment = VerticalAlignment.Center
});
return new Border
{
Child = stackPanel,
Background = System.Windows.Media.Brushes.Transparent,
Padding = new Thickness(6.0, 4.0, 6.0, 4.0),
Cursor = System.Windows.Input.Cursors.Hand,
ToolTip = tooltip
};
}
private static string GetFormatLabel(string key)
{
if (1 == 0)
{
}
string result = key switch
{
"xlsx" => "Excel",
"html" => "HTML 蹂닿퀬??,
"docx" => "Word",
"md" => "Markdown",
"csv" => "CSV",
_ => "AI ?먮룞",
};
if (1 == 0)
{
}
return result;
}
private (string Name, string Symbol, string Color) GetAgentIdentity()
{
string text = null;
lock (_convLock)
{
text = _currentConversation?.Category;
}
string text2 = text;
if (1 == 0)
{
}
(string, string, string) result = text2 switch
{
"蹂닿퀬?? => ("蹂닿퀬???먯씠?꾪듃", "??, "#3B82F6"),
"?곗씠?? => ("?곗씠??遺꾩꽍 ?먯씠?꾪듃", "??, "#10B981"),
"臾몄꽌" => ("臾몄꽌 ?묒꽦 ?먯씠?꾪듃", "??, "#6366F1"),
"?쇰Ц" => ("?쇰Ц 遺꾩꽍 ?먯씠?꾪듃", "??, "#6366F1"),
"?뚯씪" => ("?뚯씪 愿€由??먯씠?꾪듃", "??, "#8B5CF6"),
"?먮룞?? => ("?먮룞???먯씠?꾪듃", "??, "#EF4444"),
"肄붾뱶媛쒕컻" => ("肄붾뱶 媛쒕컻 ?먯씠?꾪듃", "??, "#3B82F6"),
"由ы뙥?곕쭅" => ("由ы뙥?곕쭅 ?먯씠?꾪듃", "??, "#6366F1"),
"肄붾뱶由щ럭" => ("肄붾뱶 由щ럭 ?먯씠?꾪듃", "??, "#10B981"),
"蹂댁븞?먭?" => ("蹂댁븞 ?먭? ?먯씠?꾪듃", "??, "#EF4444"),
"?뚯뒪?? => ("?뚯뒪???먯씠?꾪듃", "??, "#F59E0B"),
"?곌뎄媛쒕컻" => ("?곌뎄媛쒕컻 ?먯씠?꾪듃", "??, "#0EA5E9"),
"?쒖뒪?? => ("?쒖뒪???먯씠?꾪듃", "??, "#64748B"),
"?섏쑉遺꾩꽍" => ("?섏쑉遺꾩꽍 ?먯씠?꾪듃", "??, "#F59E0B"),
"?쒗뭹遺꾩꽍" => ("?쒗뭹遺꾩꽍 ?먯씠?꾪듃", "??, "#EC4899"),
"寃쎌쁺" => ("寃쎌쁺 遺꾩꽍 ?먯씠?꾪듃", "??, "#8B5CF6"),
"?몄궗" => ("?몄궗 愿€由??먯씠?꾪듃", "??, "#14B8A6"),
"?쒖“湲곗닠" => ("?쒖“湲곗닠 ?먯씠?꾪듃", "??, "#F97316"),
"?щТ" => ("?щТ 遺꾩꽍 ?먯씠?꾪듃", "??, "#6366F1"),
_ => (_activeTab == "Code") ? ("肄붾뱶 ?먯씠?꾪듃", "??, "#3B82F6") : ((!(_activeTab == "Cowork")) ? ("AX ?먯씠?꾪듃", "??, "#4B5EFC") : ("肄붿썙???먯씠?꾪듃", "??, "#4B5EFC")),
};
if (1 == 0)
{
}
return result;
}
private void ShowFormatMenu()
{
FormatMenuItems.Children.Clear();
System.Windows.Media.Brush foreground = (TryFindResource("PrimaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.White;
System.Windows.Media.Brush brush = (TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
System.Windows.Media.Brush accentBrush = (TryFindResource("AccentColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.CornflowerBlue;
string text = _settings.Settings.Llm.DefaultOutputFormat ?? "auto";
(string, string, string, string)[] array = new(string, string, string, string)[6]
{
("auto", "AI ?먮룞 ?좏깮", "\ue8bd", "#8B5CF6"),
("xlsx", "Excel", "\ue9f9", "#217346"),
("html", "HTML 蹂닿퀬??, "\ue12b", "#E44D26"),
("docx", "Word", "\ue8a5", "#2B579A"),
("md", "Markdown", "\ue943", "#6B7280"),
("csv", "CSV", "\ue9d9", "#10B981")
};
(string, string, string, string)[] array2 = array;
for (int i = 0; i < array2.Length; i++)
{
(string, string, string, string) tuple = array2[i];
string item = tuple.Item1;
string item2 = tuple.Item2;
string item3 = tuple.Item3;
string item4 = tuple.Item4;
bool isChecked = item == text;
StackPanel stackPanel = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal
};
stackPanel.Children.Add(CreateCheckIcon(isChecked, accentBrush));
stackPanel.Children.Add(new TextBlock
{
Text = item3,
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 13.0,
Foreground = BrushFromHex(item4),
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(0.0, 0.0, 8.0, 0.0)
});
stackPanel.Children.Add(new TextBlock
{
Text = item2,
FontSize = 13.0,
Foreground = foreground,
VerticalAlignment = VerticalAlignment.Center
});
Border border = new Border
{
Child = stackPanel,
Background = System.Windows.Media.Brushes.Transparent,
CornerRadius = new CornerRadius(8.0),
Cursor = System.Windows.Input.Cursors.Hand,
Padding = new Thickness(8.0, 7.0, 12.0, 7.0)
};
ApplyMenuItemHover(border);
string capturedKey = item;
border.MouseLeftButtonUp += delegate
{
FormatMenuPopup.IsOpen = false;
_settings.Settings.Llm.DefaultOutputFormat = capturedKey;
_settings.Save();
BuildBottomBar();
};
FormatMenuItems.Children.Add(border);
}
if (FindName("BtnFormatMenu") is UIElement placementTarget)
{
FormatMenuPopup.PlacementTarget = placementTarget;
}
FormatMenuPopup.IsOpen = true;
}
private void ShowMoodMenu()
{
MoodMenuItems.Children.Clear();
System.Windows.Media.Brush foreground = (TryFindResource("PrimaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.White;
System.Windows.Media.Brush foreground2 = (TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
System.Windows.Media.Brush brush = (TryFindResource("AccentColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.CornflowerBlue;
System.Windows.Media.Brush fill = (TryFindResource("BorderColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
UniformGrid uniformGrid = new UniformGrid
{
Columns = 2
};
foreach (TemplateMood mood in TemplateService.AllMoods)
{
bool flag = _selectedMood == mood.Key;
bool flag2 = _settings.Settings.Llm.CustomMoods.Any((CustomMoodEntry cm) => cm.Key == mood.Key);
TemplateService.MoodColors moodColors = TemplateService.GetMoodColors(mood.Key);
Border border = new Border
{
Width = 160.0,
Height = 80.0,
CornerRadius = new CornerRadius(6.0),
Background = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(moodColors.Background)),
BorderBrush = (flag ? brush : new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(moodColors.Border))),
BorderThickness = new Thickness((!flag) ? 1 : 2),
Padding = new Thickness(8.0, 6.0, 8.0, 6.0),
Margin = new Thickness(2.0)
};
StackPanel stackPanel = new StackPanel();
stackPanel.Children.Add(new Border
{
Width = 60.0,
Height = 6.0,
CornerRadius = new CornerRadius(2.0),
Background = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(moodColors.PrimaryText)),
HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
Margin = new Thickness(0.0, 0.0, 0.0, 4.0)
});
stackPanel.Children.Add(new Border
{
Width = 40.0,
Height = 3.0,
CornerRadius = new CornerRadius(1.0),
Background = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(moodColors.Accent)),
HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
Margin = new Thickness(0.0, 0.0, 0.0, 6.0)
});
for (int num = 0; num < 3; num++)
{
stackPanel.Children.Add(new Border
{
Width = 120 - num * 20,
Height = 3.0,
CornerRadius = new CornerRadius(1.0),
Background = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(moodColors.SecondaryText))
{
Opacity = 0.5
},
HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
Margin = new Thickness(0.0, 0.0, 0.0, 3.0)
});
}
StackPanel stackPanel2 = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal,
Margin = new Thickness(0.0, 2.0, 0.0, 0.0)
};
for (int num2 = 0; num2 < 2; num2++)
{
stackPanel2.Children.Add(new Border
{
Width = 28.0,
Height = 14.0,
CornerRadius = new CornerRadius(2.0),
Background = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(moodColors.CardBg)),
BorderBrush = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(moodColors.Border)),
BorderThickness = new Thickness(0.5),
Margin = new Thickness(0.0, 0.0, 4.0, 0.0)
});
}
stackPanel.Children.Add(stackPanel2);
border.Child = stackPanel;
StackPanel stackPanel3 = new StackPanel
{
Margin = new Thickness(4.0, 2.0, 4.0, 4.0)
};
StackPanel stackPanel4 = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal
};
stackPanel4.Children.Add(new TextBlock
{
Text = mood.Icon,
FontSize = 12.0,
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(0.0, 0.0, 4.0, 0.0)
});
stackPanel4.Children.Add(new TextBlock
{
Text = mood.Label,
FontSize = 11.5,
Foreground = foreground,
FontWeight = (flag ? FontWeights.SemiBold : FontWeights.Normal),
VerticalAlignment = VerticalAlignment.Center
});
if (flag)
{
stackPanel4.Children.Add(new TextBlock
{
Text = " ??,
FontSize = 11.0,
Foreground = brush,
VerticalAlignment = VerticalAlignment.Center
});
}
stackPanel3.Children.Add(stackPanel4);
Border border2 = new Border
{
CornerRadius = new CornerRadius(8.0),
Background = System.Windows.Media.Brushes.Transparent,
Cursor = System.Windows.Input.Cursors.Hand,
Padding = new Thickness(4.0),
Margin = new Thickness(2.0)
};
StackPanel stackPanel5 = new StackPanel();
stackPanel5.Children.Add(border);
stackPanel5.Children.Add(stackPanel3);
border2.Child = stackPanel5;
border2.MouseEnter += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border border4)
{
border4.Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(18, byte.MaxValue, byte.MaxValue, byte.MaxValue));
}
};
border2.MouseLeave += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border border4)
{
border4.Background = System.Windows.Media.Brushes.Transparent;
}
};
TemplateMood capturedMood = mood;
border2.MouseLeftButtonUp += delegate
{
MoodMenuPopup.IsOpen = false;
_selectedMood = capturedMood.Key;
_settings.Settings.Llm.DefaultMood = capturedMood.Key;
_settings.Save();
BuildBottomBar();
};
if (flag2)
{
border2.MouseRightButtonUp += delegate(object s, MouseButtonEventArgs e)
{
e.Handled = true;
MoodMenuPopup.IsOpen = false;
ShowCustomMoodContextMenu(s as Border, capturedMood.Key);
};
}
uniformGrid.Children.Add(border2);
}
MoodMenuItems.Children.Add(uniformGrid);
MoodMenuItems.Children.Add(new System.Windows.Shapes.Rectangle
{
Height = 1.0,
Fill = fill,
Margin = new Thickness(8.0, 4.0, 8.0, 4.0),
Opacity = 0.4
});
StackPanel stackPanel6 = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal
};
stackPanel6.Children.Add(new TextBlock
{
Text = "\ue710",
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 13.0,
Foreground = foreground2,
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(4.0, 0.0, 8.0, 0.0)
});
stackPanel6.Children.Add(new TextBlock
{
Text = "而ㅼ뒪?€ 臾대뱶 異붽?",
FontSize = 13.0,
Foreground = foreground2,
VerticalAlignment = VerticalAlignment.Center
});
Border border3 = new Border
{
Child = stackPanel6,
Background = System.Windows.Media.Brushes.Transparent,
CornerRadius = new CornerRadius(8.0),
Cursor = System.Windows.Input.Cursors.Hand,
Padding = new Thickness(8.0, 6.0, 12.0, 6.0)
};
ApplyMenuItemHover(border3);
border3.MouseLeftButtonUp += delegate
{
MoodMenuPopup.IsOpen = false;
ShowCustomMoodDialog();
};
MoodMenuItems.Children.Add(border3);
if (FindName("BtnMoodMenu") is UIElement placementTarget)
{
MoodMenuPopup.PlacementTarget = placementTarget;
}
MoodMenuPopup.IsOpen = true;
}
private void ShowCustomMoodDialog(CustomMoodEntry? existing = null)
{
bool flag = existing != null;
CustomMoodDialog customMoodDialog = new CustomMoodDialog(existing?.Key ?? "", existing?.Label ?? "", existing?.Icon ?? "\ud83c\udfaf", existing?.Description ?? "", existing?.Css ?? "")
{
Owner = this
};
if (customMoodDialog.ShowDialog() == true)
{
if (flag)
{
existing.Label = customMoodDialog.MoodLabel;
existing.Icon = customMoodDialog.MoodIcon;
existing.Description = customMoodDialog.MoodDescription;
existing.Css = customMoodDialog.MoodCss;
}
else
{
_settings.Settings.Llm.CustomMoods.Add(new CustomMoodEntry
{
Key = customMoodDialog.MoodKey,
Label = customMoodDialog.MoodLabel,
Icon = customMoodDialog.MoodIcon,
Description = customMoodDialog.MoodDescription,
Css = customMoodDialog.MoodCss
});
}
_settings.Save();
TemplateService.LoadCustomMoods(_settings.Settings.Llm.CustomMoods);
BuildBottomBar();
}
}
private void ShowCustomMoodContextMenu(Border? anchor, string moodKey)
{
if (anchor == null)
{
return;
}
Popup popup = new Popup
{
PlacementTarget = anchor,
Placement = PlacementMode.Right,
StaysOpen = false,
AllowsTransparency = true
};
System.Windows.Media.Brush background = (TryFindResource("LauncherBackground") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Black;
System.Windows.Media.Brush fg = (TryFindResource("PrimaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.White;
System.Windows.Media.Brush secondaryFg = (TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
System.Windows.Media.Brush borderBrush = (TryFindResource("BorderColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
Border border = new Border
{
Background = background,
CornerRadius = new CornerRadius(10.0),
BorderBrush = borderBrush,
BorderThickness = new Thickness(1.0),
Padding = new Thickness(4.0),
MinWidth = 120.0,
Effect = new DropShadowEffect
{
BlurRadius = 12.0,
ShadowDepth = 2.0,
Opacity = 0.3,
Color = Colors.Black
}
};
StackPanel stackPanel = new StackPanel();
Border border2 = CreateContextMenuItem("\ue70f", "?몄쭛", fg, secondaryFg);
border2.MouseLeftButtonDown += delegate
{
popup.IsOpen = false;
CustomMoodEntry customMoodEntry = _settings.Settings.Llm.CustomMoods.FirstOrDefault((CustomMoodEntry c) => c.Key == moodKey);
if (customMoodEntry != null)
{
ShowCustomMoodDialog(customMoodEntry);
}
};
stackPanel.Children.Add(border2);
Border border3 = CreateContextMenuItem("\ue74d", "??젣", new SolidColorBrush(System.Windows.Media.Color.FromRgb(239, 68, 68)), secondaryFg);
border3.MouseLeftButtonDown += delegate
{
popup.IsOpen = false;
MessageBoxResult messageBoxResult = CustomMessageBox.Show("???붿옄??臾대뱶瑜???젣?섏떆寃좎뒿?덇퉴?", "臾대뱶 ??젣", MessageBoxButton.YesNo, MessageBoxImage.Question);
if (messageBoxResult == MessageBoxResult.Yes)
{
_settings.Settings.Llm.CustomMoods.RemoveAll((CustomMoodEntry c) => c.Key == moodKey);
if (_selectedMood == moodKey)
{
_selectedMood = "modern";
}
_settings.Save();
TemplateService.LoadCustomMoods(_settings.Settings.Llm.CustomMoods);
BuildBottomBar();
}
};
stackPanel.Children.Add(border3);
border.Child = stackPanel;
popup.Child = border;
popup.IsOpen = true;
}
private void ShowPlaceholder()
{
if (!string.IsNullOrEmpty(_promptCardPlaceholder))
{
InputWatermark.Text = _promptCardPlaceholder;
InputWatermark.Visibility = Visibility.Visible;
InputBox.Text = "";
InputBox.Focus();
}
}
private void UpdateWatermarkVisibility()
{
if (_activeSlashCmd != null)
{
InputWatermark.Visibility = Visibility.Collapsed;
}
else if (_promptCardPlaceholder != null && string.IsNullOrEmpty(InputBox.Text))
{
InputWatermark.Visibility = Visibility.Visible;
}
else
{
InputWatermark.Visibility = Visibility.Collapsed;
}
}
private void ClearPromptCardPlaceholder()
{
_promptCardPlaceholder = null;
InputWatermark.Visibility = Visibility.Collapsed;
}
private void BtnSettings_Click(object sender, RoutedEventArgs e)
{
if (System.Windows.Application.Current is App app)
{
app.OpenSettingsFromChat();
}
}
private void BtnTemplateSelector_Click(object sender, RoutedEventArgs e)
{
List<PromptTemplate> promptTemplates = _settings.Settings.Llm.PromptTemplates;
TemplateItems.Items.Clear();
if (promptTemplates == null || promptTemplates.Count == 0)
{
TemplateEmptyHint.Visibility = Visibility.Visible;
TemplatePopup.IsOpen = true;
return;
}
TemplateEmptyHint.Visibility = Visibility.Collapsed;
foreach (PromptTemplate item in promptTemplates)
{
Border border = new Border
{
Background = System.Windows.Media.Brushes.Transparent,
CornerRadius = new CornerRadius(8.0),
Padding = new Thickness(10.0, 8.0, 10.0, 8.0),
Margin = new Thickness(2.0),
Cursor = System.Windows.Input.Cursors.Hand,
Tag = item.Content
};
StackPanel stackPanel = new StackPanel();
stackPanel.Children.Add(new TextBlock
{
Text = item.Name,
FontSize = 13.0,
FontWeight = FontWeights.SemiBold,
Foreground = (System.Windows.Media.Brush)FindResource("PrimaryText")
});
string text = ((item.Content.Length > 60) ? (item.Content.Substring(0, 60) + "??) : item.Content);
stackPanel.Children.Add(new TextBlock
{
Text = text,
FontSize = 11.0,
Foreground = (System.Windows.Media.Brush)FindResource("SecondaryText"),
TextTrimming = TextTrimming.CharacterEllipsis,
Margin = new Thickness(0.0, 2.0, 0.0, 0.0)
});
border.Child = stackPanel;
border.MouseEnter += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border border2)
{
border2.Background = (System.Windows.Media.Brush)FindResource("ItemBackground");
}
};
border.MouseLeave += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border border2)
{
border2.Background = System.Windows.Media.Brushes.Transparent;
}
};
border.MouseLeftButtonUp += delegate(object s, MouseButtonEventArgs _)
{
if (s is Border { Tag: string tag })
{
InputBox.Text = tag;
InputBox.CaretIndex = InputBox.Text.Length;
InputBox.Focus();
TemplatePopup.IsOpen = false;
}
};
TemplateItems.Items.Add(border);
}
TemplatePopup.IsOpen = true;
}
private string GetCurrentModelDisplayName()
{
LlmSettings llm = _settings.Settings.Llm;
string text = llm.Service.ToLowerInvariant();
if ((text == "ollama" || text == "vllm") ? true : false)
{
RegisteredModel registeredModel = llm.RegisteredModels.FirstOrDefault((RegisteredModel rm) => rm.EncryptedModelName == llm.Model);
if (registeredModel != null)
{
return registeredModel.Alias;
}
return string.IsNullOrEmpty(llm.Model) ? "(誘몄꽕??" : "?™€™€™€?;
}
if (text == "gemini")
{
return GeminiModels.FirstOrDefault(((string Id, string Label) g) => g.Id == llm.Model).Label ?? llm.Model;
}
if (text == "claude")
{
return ClaudeModels.FirstOrDefault(((string Id, string Label) c) => c.Id == llm.Model).Label ?? llm.Model;
}
return string.IsNullOrEmpty(llm.Model) ? "(誘몄꽕??" : llm.Model;
}
private void UpdateModelLabel()
{
string text = _settings.Settings.Llm.Service.ToLowerInvariant();
if (1 == 0)
{
}
string text2 = text switch
{
"gemini" => "Gemini",
"claude" => "Claude",
"vllm" => "vLLM",
_ => "Ollama",
};
if (1 == 0)
{
}
string text3 = text2;
ModelLabel.Text = text3 + " 쨌 " + GetCurrentModelDisplayName();
}
private void BtnModelSelector_Click(object sender, RoutedEventArgs e)
{
LlmSettings llm = _settings.Settings.Llm;
string originalService = llm.Service;
string originalModel = llm.Model;
bool modelConfirmed = false;
System.Windows.Media.Brush background = (TryFindResource("LauncherBackground") as System.Windows.Media.Brush) ?? new SolidColorBrush(System.Windows.Media.Color.FromRgb(26, 27, 46));
System.Windows.Media.Brush borderBrush = (TryFindResource("BorderColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
System.Windows.Media.Brush primaryText = (TryFindResource("PrimaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.White;
System.Windows.Media.Brush secondaryText = (TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
System.Windows.Media.Brush hoverBg = (TryFindResource("ItemHoverBackground") as System.Windows.Media.Brush) ?? new SolidColorBrush(System.Windows.Media.Color.FromArgb(30, byte.MaxValue, byte.MaxValue, byte.MaxValue));
SolidColorBrush checkColor = new SolidColorBrush(System.Windows.Media.Color.FromRgb(56, 161, 105));
SolidColorBrush solidColorBrush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(24, 75, 94, 252));
Popup popup = new Popup
{
StaysOpen = false,
AllowsTransparency = true,
PopupAnimation = PopupAnimation.Fade,
PlacementTarget = BtnModelSelector,
Placement = PlacementMode.Top
};
Border border = new Border
{
Background = background,
BorderBrush = borderBrush,
BorderThickness = new Thickness(1.0),
CornerRadius = new CornerRadius(12.0),
Padding = new Thickness(6.0),
MinWidth = 240.0,
MaxHeight = 460.0,
Effect = new DropShadowEffect
{
BlurRadius = 16.0,
ShadowDepth = 4.0,
Opacity = 0.3,
Color = Colors.Black
}
};
ScrollViewer scrollViewer = new ScrollViewer
{
VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
MaxHeight = 440.0
};
StackPanel stackPanel = new StackPanel();
StackPanel modelSection = new StackPanel();
stackPanel.Children.Add(new TextBlock
{
Text = "?쒕퉬??,
FontSize = 11.0,
Foreground = secondaryText,
Margin = new Thickness(10.0, 4.0, 0.0, 4.0),
FontWeight = FontWeights.SemiBold
});
StackPanel serviceItems = new StackPanel();
(string, string)[] services = new(string, string)[4]
{
("ollama", "Ollama"),
("vllm", "vLLM"),
("gemini", "Gemini"),
("claude", "Claude")
};
BuildServiceItems();
stackPanel.Children.Add(serviceItems);
stackPanel.Children.Add(CreateSeparator());
RebuildModelList(llm.Service.ToLowerInvariant());
stackPanel.Children.Add(modelSection);
popup.Closed += delegate
{
if (!modelConfirmed)
{
_settings.Settings.Llm.Service = originalService;
_settings.Settings.Llm.Model = originalModel;
UpdateModelLabel();
}
};
scrollViewer.Content = stackPanel;
border.Child = scrollViewer;
popup.Child = border;
popup.IsOpen = true;
void BuildServiceItems()
{
serviceItems.Children.Clear();
string text = llm.Service.ToLowerInvariant();
(string, string)[] array = services;
for (int i = 0; i < array.Length; i++)
{
(string, string) tuple = array[i];
string item = tuple.Item1;
string item2 = tuple.Item2;
string capturedSvc = item;
serviceItems.Children.Add(CreateMenuItem(item2, text == item, delegate
{
_settings.Settings.Llm.Service = capturedSvc;
UpdateModelLabel();
BuildServiceItems();
RebuildModelList(capturedSvc);
}, closeOnClick: false));
}
}
Border CreateMenuItem(string text, bool isChecked, Action onClick, bool closeOnClick = true)
{
//IL_021d: Unknown result type (might be due to invalid IL or missing references)
Border item = new Border
{
Background = System.Windows.Media.Brushes.Transparent,
CornerRadius = new CornerRadius(8.0),
Padding = new Thickness(10.0, 7.0, 10.0, 7.0),
Margin = new Thickness(0.0, 1.0, 0.0, 1.0),
Cursor = System.Windows.Input.Cursors.Hand
};
Grid grid = new Grid
{
ColumnDefinitions =
{
new ColumnDefinition
{
Width = new GridLength(1.0, GridUnitType.Star)
},
new ColumnDefinition
{
Width = new GridLength(20.0)
}
}
};
TextBlock element = new TextBlock
{
Text = text,
FontSize = 13.0,
Foreground = primaryText,
VerticalAlignment = VerticalAlignment.Center
};
Grid.SetColumn(element, 0);
grid.Children.Add(element);
if (isChecked)
{
Canvas canvas = new Canvas
{
Width = 14.0,
Height = 14.0,
VerticalAlignment = VerticalAlignment.Center
};
canvas.Children.Add(new System.Windows.Shapes.Path
{
Data = Geometry.Parse("M 2 7 L 5.5 10.5 L 12 4"),
Stroke = checkColor,
StrokeThickness = 2.0,
StrokeStartLineCap = PenLineCap.Round,
StrokeEndLineCap = PenLineCap.Round,
StrokeLineJoin = PenLineJoin.Round
});
Grid.SetColumn(canvas, 1);
grid.Children.Add(canvas);
}
item.Child = grid;
item.RenderTransformOrigin = new Point(0.5, 0.5);
item.RenderTransform = new ScaleTransform(1.0, 1.0);
item.MouseEnter += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border border2)
{
border2.Background = hoverBg;
}
ScaleTransform scaleTransform = item.RenderTransform as ScaleTransform;
scaleTransform?.BeginAnimation(ScaleTransform.ScaleXProperty, new DoubleAnimation(1.02, TimeSpan.FromMilliseconds(120.0)));
scaleTransform?.BeginAnimation(ScaleTransform.ScaleYProperty, new DoubleAnimation(1.02, TimeSpan.FromMilliseconds(120.0)));
};
item.MouseLeave += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border border2)
{
border2.Background = System.Windows.Media.Brushes.Transparent;
}
ScaleTransform scaleTransform = item.RenderTransform as ScaleTransform;
scaleTransform?.BeginAnimation(ScaleTransform.ScaleXProperty, new DoubleAnimation(1.0, TimeSpan.FromMilliseconds(150.0)));
scaleTransform?.BeginAnimation(ScaleTransform.ScaleYProperty, new DoubleAnimation(1.0, TimeSpan.FromMilliseconds(150.0)));
};
item.MouseLeftButtonUp += delegate
{
if (closeOnClick)
{
popup.IsOpen = false;
}
onClick();
};
return item;
}
Border CreateSeparator()
{
return new Border
{
Height = 1.0,
Background = borderBrush,
Opacity = 0.3,
Margin = new Thickness(8.0, 4.0, 8.0, 4.0)
};
}
void RebuildModelList(string service)
{
modelSection.Children.Clear();
modelSection.Children.Add(new TextBlock
{
Text = "紐⑤뜽",
FontSize = 11.0,
Foreground = secondaryText,
Margin = new Thickness(10.0, 4.0, 0.0, 4.0),
FontWeight = FontWeights.SemiBold
});
string text = service;
if ((text == "ollama" || text == "vllm") ? true : false)
{
List<RegisteredModel> list = llm.RegisteredModels.Where((RegisteredModel rm) => rm.Service == service).ToList();
if (list.Count != 0)
{
foreach (RegisteredModel item5 in list)
{
string capturedEnc = item5.EncryptedModelName;
modelSection.Children.Add(CreateMenuItem(item5.Alias, llm.Model == item5.EncryptedModelName, delegate
{
_settings.Settings.Llm.Model = capturedEnc;
_settings.Save();
modelConfirmed = true;
UpdateModelLabel();
}));
}
return;
}
modelSection.Children.Add(new TextBlock
{
Text = "?깅줉??紐⑤뜽 ?놁쓬 ???ㅼ젙?먯꽌 異붽?",
FontSize = 11.5,
Foreground = secondaryText,
FontStyle = FontStyles.Italic,
Margin = new Thickness(10.0, 4.0, 10.0, 4.0)
});
}
else if (service == "gemini")
{
(string, string)[] geminiModels = GeminiModels;
for (int num = 0; num < geminiModels.Length; num++)
{
(string, string) tuple = geminiModels[num];
string item = tuple.Item1;
string item2 = tuple.Item2;
string capturedId = item;
modelSection.Children.Add(CreateMenuItem(item2, llm.Model == item, delegate
{
_settings.Settings.Llm.Model = capturedId;
_settings.Save();
modelConfirmed = true;
UpdateModelLabel();
}));
}
}
else if (service == "claude")
{
(string, string)[] claudeModels = ClaudeModels;
for (int num2 = 0; num2 < claudeModels.Length; num2++)
{
(string, string) tuple2 = claudeModels[num2];
string item3 = tuple2.Item1;
string item4 = tuple2.Item2;
string capturedId2 = item3;
modelSection.Children.Add(CreateMenuItem(item4, llm.Model == item3, delegate
{
_settings.Settings.Llm.Model = capturedId2;
_settings.Save();
modelConfirmed = true;
UpdateModelLabel();
}));
}
}
}
}
private void BtnNewChat_Click(object sender, RoutedEventArgs e)
{
StartNewConversation();
InputBox.Focus();
}
public void ResumeConversation(string conversationId)
{
ChatConversation chatConversation = _storage.Load(conversationId);
if (chatConversation != null)
{
lock (_convLock)
{
_currentConversation = chatConversation;
}
UpdateChatTitle();
RefreshConversationList();
RenderMessages();
UpdateFolderBar();
}
InputBox.Focus();
}
public void StartNewAndFocus()
{
StartNewConversation();
InputBox.Focus();
}
private void BtnDeleteAll_Click(object sender, RoutedEventArgs e)
{
MessageBoxResult messageBoxResult = CustomMessageBox.Show("?€?λ맂 紐⑤뱺 ?€???댁뿭????젣?섏떆寃좎뒿?덇퉴?\n???묒뾽?€ ?섎룎由????놁뒿?덈떎.", "?€???꾩껜 ??젣", MessageBoxButton.YesNo, MessageBoxImage.Exclamation);
if (messageBoxResult == MessageBoxResult.Yes)
{
_storage.DeleteAll();
lock (_convLock)
{
_currentConversation = null;
}
MessagePanel.Children.Clear();
EmptyState.Visibility = Visibility.Visible;
UpdateChatTitle();
RefreshConversationList();
}
}
private void TryShowPreview(string filePath)
{
if (!string.IsNullOrEmpty(filePath) && File.Exists(filePath))
{
PreviewWindow.ShowPreview(filePath, _selectedMood);
}
}
private void ShowPreviewPanel(string filePath)
{
if (!_previewTabs.Contains<string>(filePath, StringComparer.OrdinalIgnoreCase))
{
_previewTabs.Add(filePath);
}
_activePreviewTab = filePath;
if (PreviewColumn.Width.Value < 100.0)
{
PreviewColumn.Width = new GridLength(420.0);
SplitterColumn.Width = new GridLength(5.0);
}
PreviewPanel.Visibility = Visibility.Visible;
PreviewSplitter.Visibility = Visibility.Visible;
BtnPreviewToggle.Visibility = Visibility.Visible;
RebuildPreviewTabs();
LoadPreviewContent(filePath);
}
private void RebuildPreviewTabs()
{
PreviewTabPanel.Children.Clear();
System.Windows.Media.Brush brush = (TryFindResource("AccentColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.CornflowerBlue;
System.Windows.Media.Brush brush2 = (TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
System.Windows.Media.Brush brush3 = (TryFindResource("PrimaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.White;
System.Windows.Media.Brush background = (TryFindResource("BorderColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
foreach (string previewTab in _previewTabs)
{
string fileName = System.IO.Path.GetFileName(previewTab);
bool flag = string.Equals(previewTab, _activePreviewTab, StringComparison.OrdinalIgnoreCase);
Border border = new Border
{
Background = (flag ? new SolidColorBrush(System.Windows.Media.Color.FromArgb(21, byte.MaxValue, byte.MaxValue, byte.MaxValue)) : System.Windows.Media.Brushes.Transparent),
BorderBrush = (flag ? brush : System.Windows.Media.Brushes.Transparent),
BorderThickness = new Thickness(0.0, 0.0, 0.0, flag ? 2 : 0),
Padding = new Thickness(8.0, 6.0, 4.0, 6.0),
Cursor = System.Windows.Input.Cursors.Hand,
MaxWidth = ((_previewTabs.Count <= 3) ? 200 : ((_previewTabs.Count <= 5) ? 140 : 100))
};
StackPanel stackPanel = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal
};
stackPanel.Children.Add(new TextBlock
{
Text = fileName,
FontSize = 11.0,
Foreground = (flag ? brush3 : brush2),
FontWeight = (flag ? FontWeights.SemiBold : FontWeights.Normal),
VerticalAlignment = VerticalAlignment.Center,
TextTrimming = TextTrimming.CharacterEllipsis,
MaxWidth = border.MaxWidth - 30.0,
ToolTip = previewTab
});
System.Windows.Media.Brush closeFg = (flag ? brush3 : brush2);
TextBlock child = new TextBlock
{
Text = "\ue711",
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 10.0,
Foreground = closeFg,
VerticalAlignment = VerticalAlignment.Center
};
Border border2 = new Border
{
Background = System.Windows.Media.Brushes.Transparent,
CornerRadius = new CornerRadius(3.0),
Padding = new Thickness(3.0, 2.0, 3.0, 2.0),
Margin = new Thickness(5.0, 0.0, 0.0, 0.0),
Cursor = System.Windows.Input.Cursors.Hand,
VerticalAlignment = VerticalAlignment.Center,
Visibility = ((!flag) ? Visibility.Hidden : Visibility.Visible),
Child = child
};
string closePath = previewTab;
border2.MouseEnter += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border border3)
{
border3.Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(64, byte.MaxValue, 80, 80));
if (border3.Child is TextBlock textBlock)
{
textBlock.Foreground = new SolidColorBrush(System.Windows.Media.Color.FromRgb(byte.MaxValue, 96, 96));
}
}
};
border2.MouseLeave += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border border3)
{
border3.Background = System.Windows.Media.Brushes.Transparent;
if (border3.Child is TextBlock textBlock)
{
textBlock.Foreground = closeFg;
}
}
};
border2.Tag = "close";
border2.MouseLeftButtonUp += delegate(object _, MouseButtonEventArgs e)
{
e.Handled = true;
ClosePreviewTab(closePath);
};
stackPanel.Children.Add(border2);
border.Child = stackPanel;
string clickPath = previewTab;
border.MouseLeftButtonUp += delegate(object _, MouseButtonEventArgs e)
{
if (!e.Handled)
{
e.Handled = true;
_activePreviewTab = clickPath;
RebuildPreviewTabs();
LoadPreviewContent(clickPath);
}
};
string ctxPath = previewTab;
border.MouseRightButtonUp += delegate(object _, MouseButtonEventArgs e)
{
e.Handled = true;
ShowPreviewTabContextMenu(ctxPath);
};
string dblPath = previewTab;
border.MouseLeftButtonDown += delegate(object _, MouseButtonEventArgs e)
{
if (!e.Handled && e.ClickCount == 2)
{
e.Handled = true;
OpenPreviewPopupWindow(dblPath);
}
};
bool capturedIsActive = flag;
Border capturedCloseBtn = border2;
border.MouseEnter += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border border3 && !capturedIsActive)
{
border3.Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(16, byte.MaxValue, byte.MaxValue, byte.MaxValue));
}
if (!capturedIsActive)
{
capturedCloseBtn.Visibility = Visibility.Visible;
}
};
border.MouseLeave += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border border3 && !capturedIsActive)
{
border3.Background = System.Windows.Media.Brushes.Transparent;
}
if (!capturedIsActive)
{
capturedCloseBtn.Visibility = Visibility.Hidden;
}
};
PreviewTabPanel.Children.Add(border);
List<string> previewTabs = _previewTabs;
if (previewTab != previewTabs[previewTabs.Count - 1])
{
PreviewTabPanel.Children.Add(new Border
{
Width = 1.0,
Height = 14.0,
Background = background,
Margin = new Thickness(0.0, 4.0, 0.0, 4.0),
VerticalAlignment = VerticalAlignment.Center
});
}
}
}
private void ClosePreviewTab(string filePath)
{
_previewTabs.Remove(filePath);
if (_previewTabs.Count == 0)
{
HidePreviewPanel();
return;
}
if (string.Equals(filePath, _activePreviewTab, StringComparison.OrdinalIgnoreCase))
{
List<string> previewTabs = _previewTabs;
_activePreviewTab = previewTabs[previewTabs.Count - 1];
LoadPreviewContent(_activePreviewTab);
}
RebuildPreviewTabs();
}
private async void LoadPreviewContent(string filePath)
{
string ext = System.IO.Path.GetExtension(filePath).ToLowerInvariant();
PreviewWebView.Visibility = Visibility.Collapsed;
PreviewTextScroll.Visibility = Visibility.Collapsed;
PreviewDataGrid.Visibility = Visibility.Collapsed;
PreviewEmpty.Visibility = Visibility.Collapsed;
if (!File.Exists(filePath))
{
PreviewEmpty.Text = "?뚯씪??李얠쓣 ???놁뒿?덈떎";
PreviewEmpty.Visibility = Visibility.Visible;
return;
}
try
{
switch (ext)
{
case ".html":
case ".htm":
await EnsureWebViewInitializedAsync();
PreviewWebView.Source = new Uri(filePath);
PreviewWebView.Visibility = Visibility.Visible;
break;
case ".csv":
LoadCsvPreview(filePath);
PreviewDataGrid.Visibility = Visibility.Visible;
break;
case ".md":
{
await EnsureWebViewInitializedAsync();
string mdText = File.ReadAllText(filePath);
if (mdText.Length > 50000)
{
mdText = mdText.Substring(0, 50000);
}
string mdHtml = TemplateService.RenderMarkdownToHtml(mdText, _selectedMood);
PreviewWebView.NavigateToString(mdHtml);
PreviewWebView.Visibility = Visibility.Visible;
break;
}
case ".txt":
case ".json":
case ".xml":
case ".log":
{
string text = File.ReadAllText(filePath);
if (text.Length > 50000)
{
text = text.Substring(0, 50000) + "\n\n... (?댄썑 ?앸왂)";
}
PreviewTextBlock.Text = text;
PreviewTextScroll.Visibility = Visibility.Visible;
break;
}
default:
PreviewEmpty.Text = "誘몃━蹂닿린?????녿뒗 ?뚯씪 ?뺤떇?낅땲??;
PreviewEmpty.Visibility = Visibility.Visible;
break;
}
}
catch (Exception ex)
{
PreviewTextBlock.Text = "誘몃━蹂닿린 ?ㅻ쪟: " + ex.Message;
PreviewTextScroll.Visibility = Visibility.Visible;
}
}
private async Task EnsureWebViewInitializedAsync()
{
if (_webViewInitialized)
{
return;
}
try
{
CoreWebView2Environment env = await CoreWebView2Environment.CreateAsync(null, WebView2DataFolder);
await PreviewWebView.EnsureCoreWebView2Async(env);
_webViewInitialized = true;
}
catch (Exception ex)
{
LogService.Warn("WebView2 珥덇린???ㅽ뙣: " + ex.Message);
}
}
private void LoadCsvPreview(string filePath)
{
try
{
string[] array = File.ReadAllLines(filePath);
if (array.Length == 0)
{
return;
}
DataTable dataTable = new DataTable();
string[] array2 = ParseCsvLine(array[0]);
string[] array3 = array2;
foreach (string columnName in array3)
{
dataTable.Columns.Add(columnName);
}
int num = Math.Min(array.Length, 501);
for (int j = 1; j < num; j++)
{
string[] array4 = ParseCsvLine(array[j]);
DataRow dataRow = dataTable.NewRow();
for (int k = 0; k < Math.Min(array4.Length, array2.Length); k++)
{
dataRow[k] = array4[k];
}
dataTable.Rows.Add(dataRow);
}
PreviewDataGrid.ItemsSource = dataTable.DefaultView;
}
catch (Exception ex)
{
PreviewTextBlock.Text = "CSV 濡쒕뱶 ?ㅻ쪟: " + ex.Message;
PreviewTextScroll.Visibility = Visibility.Visible;
PreviewDataGrid.Visibility = Visibility.Collapsed;
}
}
private static string[] ParseCsvLine(string line)
{
List<string> list = new List<string>();
StringBuilder stringBuilder = new StringBuilder();
bool flag = false;
for (int i = 0; i < line.Length; i++)
{
char c = line[i];
if (flag)
{
if (c == '"' && i + 1 < line.Length && line[i + 1] == '"')
{
stringBuilder.Append('"');
i++;
}
else if (c == '"')
{
flag = false;
}
else
{
stringBuilder.Append(c);
}
continue;
}
switch (c)
{
case '"':
flag = true;
break;
case ',':
list.Add(stringBuilder.ToString());
stringBuilder.Clear();
break;
default:
stringBuilder.Append(c);
break;
}
}
list.Add(stringBuilder.ToString());
return list.ToArray();
}
private void HidePreviewPanel()
{
_previewTabs.Clear();
_activePreviewTab = null;
PreviewColumn.Width = new GridLength(0.0);
SplitterColumn.Width = new GridLength(0.0);
PreviewPanel.Visibility = Visibility.Collapsed;
PreviewSplitter.Visibility = Visibility.Collapsed;
PreviewWebView.Visibility = Visibility.Collapsed;
PreviewTextScroll.Visibility = Visibility.Collapsed;
PreviewDataGrid.Visibility = Visibility.Collapsed;
try
{
if (_webViewInitialized)
{
PreviewWebView.CoreWebView2?.NavigateToString("<html></html>");
}
}
catch
{
}
}
private void PreviewTabBar_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
if ((PreviewWebView.IsFocused || PreviewWebView.IsKeyboardFocusWithin) && sender is Border border)
{
border.Focus();
}
}
private void BtnClosePreview_Click(object sender, RoutedEventArgs e)
{
HidePreviewPanel();
BtnPreviewToggle.Visibility = Visibility.Collapsed;
}
private void BtnPreviewToggle_Click(object sender, RoutedEventArgs e)
{
if (PreviewPanel.Visibility == Visibility.Visible)
{
PreviewPanel.Visibility = Visibility.Collapsed;
PreviewSplitter.Visibility = Visibility.Collapsed;
PreviewColumn.Width = new GridLength(0.0);
SplitterColumn.Width = new GridLength(0.0);
}
else if (_previewTabs.Count > 0)
{
PreviewPanel.Visibility = Visibility.Visible;
PreviewSplitter.Visibility = Visibility.Visible;
PreviewColumn.Width = new GridLength(420.0);
SplitterColumn.Width = new GridLength(5.0);
RebuildPreviewTabs();
if (_activePreviewTab != null)
{
LoadPreviewContent(_activePreviewTab);
}
}
}
private void BtnOpenExternal_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(_activePreviewTab) || !File.Exists(_activePreviewTab))
{
return;
}
try
{
Process.Start(new ProcessStartInfo
{
FileName = _activePreviewTab,
UseShellExecute = true
});
}
catch (Exception ex)
{
Debug.WriteLine("?몃? ?꾨줈洹몃옩 ?ㅽ뻾 ?ㅻ쪟: " + ex.Message);
}
}
private void ShowPreviewTabContextMenu(string filePath)
{
if (_previewTabPopup != null)
{
_previewTabPopup.IsOpen = false;
}
System.Windows.Media.Brush background = (TryFindResource("LauncherBackground") as System.Windows.Media.Brush) ?? new SolidColorBrush(System.Windows.Media.Color.FromRgb(30, 30, 46));
System.Windows.Media.Brush borderBrush = (TryFindResource("BorderColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
System.Windows.Media.Brush primaryText = (TryFindResource("PrimaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.White;
System.Windows.Media.Brush secondaryText = (TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
System.Windows.Media.Brush hoverBg = (TryFindResource("ItemHoverBackground") as System.Windows.Media.Brush) ?? new SolidColorBrush(System.Windows.Media.Color.FromArgb(24, byte.MaxValue, byte.MaxValue, byte.MaxValue));
StackPanel stack = new StackPanel();
AddItem("\ue8a7", "#64B5F6", "?몃? ?꾨줈洹몃옩?쇰줈 ?닿린", delegate
{
try
{
Process.Start(new ProcessStartInfo
{
FileName = filePath,
UseShellExecute = true
});
}
catch
{
}
});
AddItem("\ue838", "#FFB74D", "?뚯씪 ?꾩튂 ?닿린", delegate
{
try
{
Process.Start("explorer.exe", "/select,\"" + filePath + "\"");
}
catch
{
}
});
AddItem("\ue8a7", "#81C784", "蹂꾨룄 李쎌뿉??蹂닿린", delegate
{
OpenPreviewPopupWindow(filePath);
});
AddSeparator();
AddItem("\ue8c8", "", "寃쎈줈 蹂듭궗", delegate
{
try
{
System.Windows.Clipboard.SetText(filePath);
}
catch
{
}
});
AddSeparator();
AddItem("\ue711", "#EF5350", "?????リ린", delegate
{
ClosePreviewTab(filePath);
});
if (_previewTabs.Count > 1)
{
AddItem("\ue8bb", "#EF5350", "?ㅻⅨ ??紐⑤몢 ?リ린", delegate
{
string keep = filePath;
_previewTabs.RemoveAll((string p) => !string.Equals(p, keep, StringComparison.OrdinalIgnoreCase));
_activePreviewTab = keep;
RebuildPreviewTabs();
LoadPreviewContent(keep);
});
}
Border child = new Border
{
Background = background,
BorderBrush = borderBrush,
BorderThickness = new Thickness(1.0),
CornerRadius = new CornerRadius(12.0),
Padding = new Thickness(4.0, 6.0, 4.0, 6.0),
MinWidth = 180.0,
Effect = new DropShadowEffect
{
BlurRadius = 16.0,
Opacity = 0.4,
ShadowDepth = 4.0,
Color = Colors.Black
},
Child = stack
};
_previewTabPopup = new Popup
{
Child = child,
Placement = PlacementMode.MousePoint,
StaysOpen = false,
AllowsTransparency = true,
PopupAnimation = PopupAnimation.Fade
};
_previewTabPopup.IsOpen = true;
void AddItem(string icon, string iconColor, string label, Action action)
{
Border border = new Border
{
Background = System.Windows.Media.Brushes.Transparent,
CornerRadius = new CornerRadius(6.0),
Padding = new Thickness(10.0, 7.0, 16.0, 7.0),
Cursor = System.Windows.Input.Cursors.Hand
};
StackPanel stackPanel = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal
};
stackPanel.Children.Add(new TextBlock
{
Text = icon,
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 12.0,
Foreground = (string.IsNullOrEmpty(iconColor) ? secondaryText : new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(iconColor))),
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(0.0, 0.0, 8.0, 0.0)
});
stackPanel.Children.Add(new TextBlock
{
Text = label,
FontSize = 13.0,
Foreground = primaryText,
VerticalAlignment = VerticalAlignment.Center
});
border.Child = stackPanel;
border.MouseEnter += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border border2)
{
border2.Background = hoverBg;
}
};
border.MouseLeave += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border border2)
{
border2.Background = System.Windows.Media.Brushes.Transparent;
}
};
border.MouseLeftButtonUp += delegate
{
_previewTabPopup.IsOpen = false;
action();
};
stack.Children.Add(border);
}
void AddSeparator()
{
stack.Children.Add(new Border
{
Height = 1.0,
Background = borderBrush,
Margin = new Thickness(8.0, 3.0, 8.0, 3.0)
});
}
}
private void OpenPreviewPopupWindow(string filePath)
{
if (!File.Exists(filePath))
{
return;
}
string text = System.IO.Path.GetExtension(filePath).ToLowerInvariant();
string fileName = System.IO.Path.GetFileName(filePath);
System.Windows.Media.Brush background = (TryFindResource("LauncherBackground") as System.Windows.Media.Brush) ?? new SolidColorBrush(System.Windows.Media.Color.FromRgb(30, 30, 46));
System.Windows.Media.Brush foreground = (TryFindResource("PrimaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.White;
Window window = new Window
{
Title = "誘몃━蹂닿린 ??" + fileName,
Width = 900.0,
Height = 700.0,
WindowStartupLocation = WindowStartupLocation.CenterScreen,
Background = background
};
FrameworkElement content;
switch (text)
{
case ".html":
case ".htm":
{
WebView2 wv = new WebView2();
wv.Loaded += async delegate
{
try
{
CoreWebView2Environment env = await CoreWebView2Environment.CreateAsync(null, WebView2DataFolder);
await wv.EnsureCoreWebView2Async(env);
wv.Source = new Uri(filePath);
}
catch
{
}
};
content = wv;
break;
}
case ".md":
{
WebView2 mdWv = new WebView2();
string mdMood = _selectedMood;
mdWv.Loaded += async delegate
{
try
{
CoreWebView2Environment env = await CoreWebView2Environment.CreateAsync(null, WebView2DataFolder);
await mdWv.EnsureCoreWebView2Async(env);
string mdSrc = File.ReadAllText(filePath);
if (mdSrc.Length > 100000)
{
mdSrc = mdSrc.Substring(0, 100000);
}
string html = TemplateService.RenderMarkdownToHtml(mdSrc, mdMood);
mdWv.NavigateToString(html);
}
catch
{
}
};
content = mdWv;
break;
}
case ".csv":
{
DataGrid dataGrid = new DataGrid
{
AutoGenerateColumns = true,
IsReadOnly = true,
Background = System.Windows.Media.Brushes.Transparent,
Foreground = System.Windows.Media.Brushes.White,
BorderThickness = new Thickness(0.0),
FontSize = 12.0
};
try
{
string[] array = File.ReadAllLines(filePath);
if (array.Length != 0)
{
DataTable dataTable = new DataTable();
string[] array2 = ParseCsvLine(array[0]);
string[] array3 = array2;
foreach (string columnName in array3)
{
dataTable.Columns.Add(columnName);
}
for (int num2 = 1; num2 < Math.Min(array.Length, 1001); num2++)
{
string[] array4 = ParseCsvLine(array[num2]);
DataRow dataRow = dataTable.NewRow();
for (int num3 = 0; num3 < Math.Min(array4.Length, dataTable.Columns.Count); num3++)
{
dataRow[num3] = array4[num3];
}
dataTable.Rows.Add(dataRow);
}
dataGrid.ItemsSource = dataTable.DefaultView;
}
}
catch
{
}
content = dataGrid;
break;
}
default:
{
string text2 = File.ReadAllText(filePath);
if (text2.Length > 100000)
{
text2 = text2.Substring(0, 100000) + "\n\n... (?댄썑 ?앸왂)";
}
ScrollViewer scrollViewer = new ScrollViewer
{
VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
Padding = new Thickness(20.0),
Content = new TextBlock
{
Text = text2,
TextWrapping = TextWrapping.Wrap,
FontFamily = new System.Windows.Media.FontFamily("Consolas"),
FontSize = 13.0,
Foreground = foreground
}
};
content = scrollViewer;
break;
}
}
window.Content = content;
window.Show();
}
private void UpdateAgentProgressBar(AgentEvent evt)
{
switch (evt.Type)
{
case AgentEventType.Planning:
{
List<string> steps = evt.Steps;
if (steps != null && steps.Count > 0)
{
ShowStickyProgress(evt.Steps.Count);
}
break;
}
case AgentEventType.StepStart:
if (evt.StepTotal > 0)
{
UpdateStickyProgress(evt.StepCurrent, evt.StepTotal, evt.Summary);
}
break;
case AgentEventType.Complete:
HideStickyProgress();
break;
}
}
private void ShowStickyProgress(int totalSteps)
{
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: Expected O, but got Unknown
_progressStartTime = DateTime.Now;
AgentProgressBar.Visibility = Visibility.Visible;
ProgressIcon.Text = "\ue768";
ProgressStepLabel.Text = $"?묒뾽 以€鍮?以?.. (0/{totalSteps})";
ProgressPercent.Text = "0%";
ProgressElapsed.Text = "0:00";
ProgressFill.Width = 0.0;
DispatcherTimer? progressElapsedTimer = _progressElapsedTimer;
if (progressElapsedTimer != null)
{
progressElapsedTimer.Stop();
}
_progressElapsedTimer = new DispatcherTimer
{
Interval = TimeSpan.FromSeconds(1.0)
};
_progressElapsedTimer.Tick += delegate
{
TimeSpan timeSpan = DateTime.Now - _progressStartTime;
ProgressElapsed.Text = ((timeSpan.TotalHours >= 1.0) ? timeSpan.ToString("h\\:mm\\:ss") : timeSpan.ToString("m\\:ss"));
};
_progressElapsedTimer.Start();
}
private void UpdateStickyProgress(int currentStep, int totalSteps, string stepDescription)
{
if (AgentProgressBar.Visibility == Visibility.Visible)
{
double num = ((totalSteps > 0) ? ((double)currentStep / (double)totalSteps) : 0.0);
ProgressStepLabel.Text = $"{stepDescription} ({currentStep}/{totalSteps})";
ProgressPercent.Text = $"{(int)(num * 100.0)}%";
if (ProgressFill.Parent is Border border)
{
double toValue = border.ActualWidth * num;
DoubleAnimation animation = new DoubleAnimation(ProgressFill.Width, toValue, TimeSpan.FromMilliseconds(300.0))
{
EasingFunction = new QuadraticEase()
};
ProgressFill.BeginAnimation(FrameworkElement.WidthProperty, animation);
}
}
}
private void HideStickyProgress()
{
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_00ea: Expected O, but got Unknown
DispatcherTimer? progressElapsedTimer = _progressElapsedTimer;
if (progressElapsedTimer != null)
{
progressElapsedTimer.Stop();
}
_progressElapsedTimer = null;
if (AgentProgressBar.Visibility != Visibility.Visible)
{
return;
}
ProgressIcon.Text = "\ue930";
ProgressStepLabel.Text = "?묒뾽 ?꾨즺";
ProgressPercent.Text = "100%";
if (ProgressFill.Parent is Border border)
{
DoubleAnimation animation = new DoubleAnimation(ProgressFill.Width, border.ActualWidth, TimeSpan.FromMilliseconds(200.0));
ProgressFill.BeginAnimation(FrameworkElement.WidthProperty, animation);
}
DispatcherTimer hideTimer = new DispatcherTimer
{
Interval = TimeSpan.FromSeconds(3.0)
};
hideTimer.Tick += delegate
{
hideTimer.Stop();
DoubleAnimation doubleAnimation = new DoubleAnimation(1.0, 0.0, TimeSpan.FromMilliseconds(300.0));
doubleAnimation.Completed += delegate
{
AgentProgressBar.Visibility = Visibility.Collapsed;
AgentProgressBar.Opacity = 1.0;
ProgressFill.BeginAnimation(FrameworkElement.WidthProperty, null);
ProgressFill.Width = 0.0;
};
AgentProgressBar.BeginAnimation(UIElement.OpacityProperty, doubleAnimation);
};
hideTimer.Start();
}
private void ToggleFileBrowser()
{
if (FileBrowserPanel.Visibility == Visibility.Visible)
{
FileBrowserPanel.Visibility = Visibility.Collapsed;
_settings.Settings.Llm.ShowFileBrowser = false;
}
else
{
FileBrowserPanel.Visibility = Visibility.Visible;
_settings.Settings.Llm.ShowFileBrowser = true;
BuildFileTree();
}
_settings.Save();
}
private void BtnFileBrowserRefresh_Click(object sender, RoutedEventArgs e)
{
BuildFileTree();
}
private void BtnFileBrowserOpenFolder_Click(object sender, RoutedEventArgs e)
{
string currentWorkFolder = GetCurrentWorkFolder();
if (string.IsNullOrEmpty(currentWorkFolder) || !Directory.Exists(currentWorkFolder))
{
return;
}
try
{
Process.Start(new ProcessStartInfo
{
FileName = currentWorkFolder,
UseShellExecute = true
});
}
catch
{
}
}
private void BtnFileBrowserClose_Click(object sender, RoutedEventArgs e)
{
FileBrowserPanel.Visibility = Visibility.Collapsed;
}
private void BuildFileTree()
{
FileTreeView.Items.Clear();
string currentWorkFolder = GetCurrentWorkFolder();
if (string.IsNullOrEmpty(currentWorkFolder) || !Directory.Exists(currentWorkFolder))
{
FileTreeView.Items.Add(new TreeViewItem
{
Header = "?묒뾽 ?대뜑瑜??좏깮?섏꽭??,
IsEnabled = false
});
}
else
{
FileBrowserTitle.Text = "?뚯씪 ?먯깋湲???" + System.IO.Path.GetFileName(currentWorkFolder);
int count = 0;
PopulateDirectory(new DirectoryInfo(currentWorkFolder), FileTreeView.Items, 0, ref count);
}
}
private void PopulateDirectory(DirectoryInfo dir, ItemCollection items, int depth, ref int count)
{
if (depth > 4 || count > 200)
{
return;
}
try
{
foreach (DirectoryInfo item in from d in dir.GetDirectories()
orderby d.Name
select d)
{
if (count > 200)
{
break;
}
if (_ignoredDirs.Contains(item.Name) || item.Name.StartsWith('.'))
{
continue;
}
count++;
TreeViewItem treeViewItem = new TreeViewItem
{
Header = CreateFileTreeHeader("\ued25", item.Name, null),
Tag = item.FullName,
IsExpanded = (depth < 1)
};
if (depth < 3)
{
treeViewItem.Items.Add(new TreeViewItem
{
Header = "濡쒕뵫 以?.."
});
DirectoryInfo capturedDir = item;
int capturedDepth = depth;
treeViewItem.Expanded += delegate(object s, RoutedEventArgs _)
{
if (s is TreeViewItem treeViewItem3 && treeViewItem3.Items.Count == 1 && treeViewItem3.Items[0] is TreeViewItem { Header: var header } && header?.ToString() == "濡쒕뵫 以?..")
{
treeViewItem3.Items.Clear();
int count2 = 0;
PopulateDirectory(capturedDir, treeViewItem3.Items, capturedDepth + 1, ref count2);
}
};
}
else
{
PopulateDirectory(item, treeViewItem.Items, depth + 1, ref count);
}
items.Add(treeViewItem);
}
}
catch
{
}
try
{
foreach (FileInfo item2 in from f in dir.GetFiles()
orderby f.Name
select f)
{
if (count > 200)
{
break;
}
count++;
string ext = item2.Extension.ToLowerInvariant();
string fileIcon = GetFileIcon(ext);
string sizeText = FormatFileSize(item2.Length);
TreeViewItem treeViewItem2 = new TreeViewItem
{
Header = CreateFileTreeHeader(fileIcon, item2.Name, sizeText),
Tag = item2.FullName
};
string capturedPath = item2.FullName;
treeViewItem2.MouseDoubleClick += delegate(object s, MouseButtonEventArgs e)
{
e.Handled = true;
TryShowPreview(capturedPath);
};
treeViewItem2.MouseRightButtonUp += delegate(object s, MouseButtonEventArgs e)
{
e.Handled = true;
if (s is TreeViewItem treeViewItem3)
{
treeViewItem3.IsSelected = true;
}
ShowFileTreeContextMenu(capturedPath);
};
items.Add(treeViewItem2);
}
}
catch
{
}
}
private static StackPanel CreateFileTreeHeader(string icon, string name, string? sizeText)
{
StackPanel stackPanel = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal
};
stackPanel.Children.Add(new TextBlock
{
Text = icon,
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 11.0,
Foreground = new SolidColorBrush(System.Windows.Media.Color.FromRgb(156, 163, 175)),
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(0.0, 0.0, 5.0, 0.0)
});
stackPanel.Children.Add(new TextBlock
{
Text = name,
FontSize = 11.5,
VerticalAlignment = VerticalAlignment.Center
});
if (sizeText != null)
{
stackPanel.Children.Add(new TextBlock
{
Text = " " + sizeText,
FontSize = 10.0,
Foreground = new SolidColorBrush(System.Windows.Media.Color.FromRgb(107, 114, 128)),
VerticalAlignment = VerticalAlignment.Center
});
}
return stackPanel;
}
private static string GetFileIcon(string ext)
{
if (1 == 0)
{
}
string result;
switch (ext)
{
case ".html":
case ".htm":
result = "\ueb41";
break;
case ".xlsx":
case ".xls":
result = "\ue9f9";
break;
case ".docx":
case ".doc":
result = "\ue8a5";
break;
case ".pdf":
result = "\uea90";
break;
case ".csv":
result = "\ue80a";
break;
case ".md":
result = "\ue70b";
break;
case ".json":
case ".xml":
result = "\ue943";
break;
case ".png":
case ".jpg":
case ".jpeg":
case ".gif":
case ".svg":
case ".webp":
result = "\ueb9f";
break;
case ".cs":
case ".py":
case ".js":
case ".ts":
case ".java":
case ".cpp":
result = "\ue943";
break;
case ".bat":
case ".cmd":
case ".ps1":
case ".sh":
result = "\ue756";
break;
case ".txt":
case ".log":
result = "\ue8a5";
break;
default:
result = "\ue7c3";
break;
}
if (1 == 0)
{
}
return result;
}
private static string FormatFileSize(long bytes)
{
if (1 == 0)
{
}
string result = ((bytes < 1024) ? $"{bytes} B" : ((bytes >= 1048576) ? $"{(double)bytes / 1048576.0:F1} MB" : $"{(double)bytes / 1024.0:F1} KB"));
if (1 == 0)
{
}
return result;
}
private void ShowFileTreeContextMenu(string filePath)
{
System.Windows.Media.Brush background = (TryFindResource("LauncherBackground") as System.Windows.Media.Brush) ?? new SolidColorBrush(System.Windows.Media.Color.FromRgb(30, 30, 46));
System.Windows.Media.Brush borderBrush = (TryFindResource("BorderColor") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
System.Windows.Media.Brush primaryText = (TryFindResource("PrimaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.White;
System.Windows.Media.Brush secondaryText = (TryFindResource("SecondaryText") as System.Windows.Media.Brush) ?? System.Windows.Media.Brushes.Gray;
System.Windows.Media.Brush hoverBg = (TryFindResource("HintBackground") as System.Windows.Media.Brush) ?? new SolidColorBrush(System.Windows.Media.Color.FromArgb(24, byte.MaxValue, byte.MaxValue, byte.MaxValue));
SolidColorBrush solidColorBrush = new SolidColorBrush(System.Windows.Media.Color.FromRgb(231, 76, 60));
Popup popup = new Popup
{
StaysOpen = false,
AllowsTransparency = true,
PopupAnimation = PopupAnimation.Fade,
Placement = PlacementMode.MousePoint
};
StackPanel panel = new StackPanel
{
Margin = new Thickness(2.0)
};
Border child = new Border
{
Background = background,
BorderBrush = borderBrush,
BorderThickness = new Thickness(1.0),
CornerRadius = new CornerRadius(10.0),
Padding = new Thickness(6.0),
MinWidth = 200.0,
Effect = new DropShadowEffect
{
BlurRadius = 16.0,
ShadowDepth = 4.0,
Opacity = 0.3,
Color = Colors.Black,
Direction = 270.0
},
Child = panel
};
popup.Child = child;
string item = System.IO.Path.GetExtension(filePath).ToLowerInvariant();
if (_previewableExtensions.Contains(item))
{
AddItem("\ue8a1", "誘몃━蹂닿린", delegate
{
ShowPreviewPanel(filePath);
});
}
AddItem("\ue8a7", "?몃? ?꾨줈洹몃옩?쇰줈 ?닿린", delegate
{
try
{
Process.Start(new ProcessStartInfo
{
FileName = filePath,
UseShellExecute = true
});
}
catch
{
}
});
AddItem("\ued25", "?대뜑?먯꽌 蹂닿린", delegate
{
try
{
Process.Start("explorer.exe", "/select,\"" + filePath + "\"");
}
catch
{
}
});
AddItem("\ue8c8", "寃쎈줈 蹂듭궗", delegate
{
try
{
System.Windows.Clipboard.SetText(filePath);
ShowToast("寃쎈줈 蹂듭궗??);
}
catch
{
}
});
AddSep();
AddItem("\ue8ac", "?대쫫 蹂€寃?, delegate
{
string path = System.IO.Path.GetDirectoryName(filePath) ?? "";
string fileName = System.IO.Path.GetFileName(filePath);
InputDialog inputDialog = new InputDialog("?대쫫 蹂€寃?, "???뚯씪 ?대쫫:", fileName)
{
Owner = this
};
if (inputDialog.ShowDialog() == true && !string.IsNullOrWhiteSpace(inputDialog.ResponseText))
{
string destFileName = System.IO.Path.Combine(path, inputDialog.ResponseText.Trim());
try
{
File.Move(filePath, destFileName);
BuildFileTree();
ShowToast("?대쫫 蹂€寃? " + inputDialog.ResponseText.Trim());
}
catch (Exception ex)
{
ShowToast("?대쫫 蹂€寃??ㅽ뙣: " + ex.Message, "\ue783");
}
}
});
AddItem("\ue74d", "??젣", delegate
{
MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("?뚯씪????젣?섏떆寃좎뒿?덇퉴?\n" + System.IO.Path.GetFileName(filePath), "?뚯씪 ??젣 ?뺤씤", MessageBoxButton.YesNo, MessageBoxImage.Exclamation);
if (messageBoxResult == MessageBoxResult.Yes)
{
try
{
File.Delete(filePath);
BuildFileTree();
ShowToast("?뚯씪 ??젣??);
}
catch (Exception ex)
{
ShowToast("??젣 ?ㅽ뙣: " + ex.Message, "\ue783");
}
}
}, solidColorBrush, solidColorBrush);
((DispatcherObject)this).Dispatcher.BeginInvoke((Delegate)(Action)delegate
{
popup.IsOpen = true;
}, (DispatcherPriority)5, Array.Empty<object>());
void AddItem(string icon, string label, Action action, System.Windows.Media.Brush? labelColor = null, System.Windows.Media.Brush? iconColor = null)
{
StackPanel stackPanel = new StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal
};
stackPanel.Children.Add(new TextBlock
{
Text = icon,
FontFamily = new System.Windows.Media.FontFamily("Segoe MDL2 Assets"),
FontSize = 13.0,
Foreground = (iconColor ?? secondaryText),
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(0.0, 0.0, 10.0, 0.0)
});
stackPanel.Children.Add(new TextBlock
{
Text = label,
FontSize = 12.5,
Foreground = (labelColor ?? primaryText),
VerticalAlignment = VerticalAlignment.Center
});
Border border = new Border
{
Child = stackPanel,
Background = System.Windows.Media.Brushes.Transparent,
CornerRadius = new CornerRadius(7.0),
Cursor = System.Windows.Input.Cursors.Hand,
Padding = new Thickness(10.0, 8.0, 14.0, 8.0),
Margin = new Thickness(0.0, 1.0, 0.0, 1.0)
};
border.MouseEnter += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border border2)
{
border2.Background = hoverBg;
}
};
border.MouseLeave += delegate(object s, System.Windows.Input.MouseEventArgs _)
{
if (s is Border border2)
{
border2.Background = System.Windows.Media.Brushes.Transparent;
}
};
border.MouseLeftButtonUp += delegate
{
popup.IsOpen = false;
action();
};
panel.Children.Add(border);
}
void AddSep()
{
panel.Children.Add(new Border
{
Height = 1.0,
Margin = new Thickness(10.0, 4.0, 10.0, 4.0),
Background = borderBrush,
Opacity = 0.3
});
}
}
private void RefreshFileTreeIfVisible()
{
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Expected O, but got Unknown
if (FileBrowserPanel.Visibility == Visibility.Visible)
{
DispatcherTimer? fileBrowserRefreshTimer = _fileBrowserRefreshTimer;
if (fileBrowserRefreshTimer != null)
{
fileBrowserRefreshTimer.Stop();
}
_fileBrowserRefreshTimer = new DispatcherTimer
{
Interval = TimeSpan.FromMilliseconds(500.0)
};
_fileBrowserRefreshTimer.Tick += delegate
{
_fileBrowserRefreshTimer.Stop();
BuildFileTree();
};
_fileBrowserRefreshTimer.Start();
}
}
private void UpdateStatusBar(AgentEvent evt)
{
string toolName = evt.ToolName;
if (1 == 0)
{
}
string text;
switch (toolName)
{
case "sub_agent":
text = "?쒕툕?먯씠?꾪듃";
break;
case "file_read":
case "document_read":
text = "?뚯씪 ?쎄린";
break;
case "file_write":
text = "?뚯씪 ?곌린";
break;
case "file_edit":
text = "?뚯씪 ?섏젙";
break;
case "html_create":
text = "HTML ?앹꽦";
break;
case "xlsx_create":
text = "Excel ?앹꽦";
break;
case "docx_create":
text = "Word ?앹꽦";
break;
case "csv_create":
text = "CSV ?앹꽦";
break;
case "md_create":
text = "Markdown ?앹꽦";
break;
case "folder_map":
text = "?대뜑 ?먯깋";
break;
case "glob":
text = "?뚯씪 寃€??;
break;
case "grep":
text = "?댁슜 寃€??;
break;
case "process":
text = "紐낅졊 ?ㅽ뻾";
break;
default:
text = evt.ToolName;
break;
}
if (1 == 0)
{
}
string text2 = text;
switch (evt.Type)
{
case AgentEventType.Thinking:
SetStatus("?앷컖 以?..", spinning: true);
break;
case AgentEventType.Planning:
SetStatus($"怨꾪쉷 ?섎┰ 以???{evt.StepTotal}?④퀎", spinning: true);
break;
case AgentEventType.ToolCall:
SetStatus(text2 + " ?ㅽ뻾 以?..", spinning: true);
break;
case AgentEventType.ToolResult:
SetStatus(evt.Success ? (text2 + " ?꾨즺") : (text2 + " ?ㅽ뙣"), spinning: false);
break;
case AgentEventType.StepStart:
SetStatus($"[{evt.StepCurrent}/{evt.StepTotal}] {TruncateForStatus(evt.Summary)}", spinning: true);
break;
case AgentEventType.StepDone:
SetStatus($"[{evt.StepCurrent}/{evt.StepTotal}] ?④퀎 ?꾨즺", spinning: true);
break;
case AgentEventType.SkillCall:
SetStatus("?ㅽ궗 ?ㅽ뻾 以? " + TruncateForStatus(evt.Summary), spinning: true);
break;
case AgentEventType.Complete:
SetStatus("?묒뾽 ?꾨즺", spinning: false);
StopStatusAnimation();
break;
case AgentEventType.Error:
SetStatus("?ㅻ쪟 諛쒖깮", spinning: false);
StopStatusAnimation();
break;
case AgentEventType.Paused:
SetStatus("???쇱떆?뺤?", spinning: false);
break;
case AgentEventType.Resumed:
SetStatus("???ш컻??, spinning: true);
break;
case AgentEventType.Decision:
break;
}
}
private void SetStatus(string text, bool spinning)
{
if (StatusLabel != null)
{
StatusLabel.Text = text;
}
if (spinning)
{
StartStatusAnimation();
}
}
private void StartStatusAnimation()
{
if (_statusSpinStoryboard == null)
{
DoubleAnimation doubleAnimation = new DoubleAnimation
{
From = 0.0,
To = 360.0,
Duration = TimeSpan.FromSeconds(2.0),
RepeatBehavior = RepeatBehavior.Forever
};
_statusSpinStoryboard = new Storyboard();
Storyboard.SetTarget((DependencyObject)(object)doubleAnimation, (DependencyObject)(object)StatusDiamond);
Storyboard.SetTargetProperty((DependencyObject)(object)doubleAnimation, new PropertyPath("(UIElement.RenderTransform).(RotateTransform.Angle)"));
_statusSpinStoryboard.Children.Add(doubleAnimation);
_statusSpinStoryboard.Begin();
}
}
private void StopStatusAnimation()
{
_statusSpinStoryboard?.Stop();
_statusSpinStoryboard = null;
}
private void SetStatusIdle()
{
StopStatusAnimation();
if (StatusLabel != null)
{
StatusLabel.Text = "?€湲?以?;
}
if (StatusElapsed != null)
{
StatusElapsed.Text = "";
}
if (StatusTokens != null)
{
StatusTokens.Text = "";
}
}
private void UpdateStatusTokens(int inputTokens, int outputTokens)
{
if (StatusTokens != null)
{
LlmSettings llm = _settings.Settings.Llm;
(double InputCost, double OutputCost) tuple = TokenEstimator.EstimateCost(inputTokens, outputTokens, llm.Service, llm.Model);
double item = tuple.InputCost;
double item2 = tuple.OutputCost;
double num = item + item2;
string value = ((num > 0.0) ? (" 쨌 " + TokenEstimator.FormatCost(num)) : "");
StatusTokens.Text = $"??TokenEstimator.Format(inputTokens)} ??TokenEstimator.Format(outputTokens)}{value}";
}
}
private static string TruncateForStatus(string? text, int max = 40)
{
if (string.IsNullOrEmpty(text))
{
return "";
}
return (text.Length <= max) ? text : (text.Substring(0, max) + "??);
}
private static SolidColorBrush BrushFromHex(string hex)
{
System.Windows.Media.Color color = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(hex);
return new SolidColorBrush(color);
}
[DebuggerNonUserCode]
[GeneratedCode("PresentationBuildTasks", "10.0.5.0")]
static ChatWindow()
{
Dictionary<string, List<(string, string, string)>> dictionary = new Dictionary<string, List<(string, string, string)>>(StringComparer.OrdinalIgnoreCase);
int num = 4;
List<(string, string, string)> list = new List<(string, string, string)>(num);
CollectionsMarshal.SetCount(list, num);
Span<(string, string, string)> span = CollectionsMarshal.AsSpan(list);
span[0] = ("肄붾뱶 由щ럭", "\ue943", "泥⑤???肄붾뱶瑜?由щ럭??二쇱꽭?? 踰꾧렇, ?깅뒫 ?댁뒋, 蹂댁븞 痍⑥빟?? 媛쒖꽑?먯쓣 李얠븘 援ъ껜?곸쑝濡??쒖븞?섏꽭??");
span[1] = ("肄붾뱶 ?ㅻ챸", "\ue946", "泥⑤???肄붾뱶瑜??곸꽭???ㅻ챸??二쇱꽭?? 二쇱슂 ?⑥닔, ?곗씠???먮쫫, ?ㅺ퀎 ?⑦꽩???ы븿?섏꽭??");
span[2] = ("由ы뙥?좊쭅 ?쒖븞", "\ue70f", "泥⑤???肄붾뱶??由ы뙥?좊쭅 諛⑹븞???쒖븞??二쇱꽭?? 媛€?낆꽦, ?좎?蹂댁닔?? ?깅뒫??怨좊젮?섏꽭??");
span[3] = ("?뚯뒪???앹꽦", "\ue9d5", "泥⑤???肄붾뱶???€???⑥쐞 ?뚯뒪??肄붾뱶瑜??앹꽦??二쇱꽭??");
dictionary["code"] = list;
num = 3;
List<(string, string, string)> list2 = new List<(string, string, string)>(num);
CollectionsMarshal.SetCount(list2, num);
Span<(string, string, string)> span2 = CollectionsMarshal.AsSpan(list2);
span2[0] = ("?붿빟", "\ue8ab", "泥⑤???臾몄꽌瑜??듭떖 ?ъ씤???꾩<濡?媛꾧껐?섍쾶 ?붿빟??二쇱꽭??");
span2[1] = ("遺꾩꽍", "\ue9d9", "泥⑤???臾몄꽌???댁슜??遺꾩꽍?섍퀬 二쇱슂 ?몄궗?댄듃瑜??꾩텧??二쇱꽭??");
span2[2] = ("踰덉뿭", "\ue8c1", "泥⑤???臾몄꽌瑜??곸뼱濡?踰덉뿭??二쇱꽭?? ?먮Ц???ㅺ낵 ?섏븰?ㅻ? ?좎??섏꽭??");
dictionary["document"] = list2;
num = 3;
List<(string, string, string)> list3 = new List<(string, string, string)>(num);
CollectionsMarshal.SetCount(list3, num);
Span<(string, string, string)> span3 = CollectionsMarshal.AsSpan(list3);
span3[0] = ("?곗씠??遺꾩꽍", "\ue9d9", "泥⑤????곗씠?곕? 遺꾩꽍??二쇱꽭?? ?듦퀎, 異붿꽭, ?댁긽移섎? 李얠븘 蹂닿퀬?섏꽭??");
span3[1] = ("?쒓컖???쒖븞", "\ue9d9", "泥⑤????곗씠?곕? ?쒓컖?뷀븷 理쒖쟻??李⑦듃 ?좏삎???쒖븞?섍퀬 chart_create濡??앹꽦??二쇱꽭??");
span3[2] = ("?щ㎎ 蹂€??, "\ue8ab", "泥⑤????곗씠?곕? ?ㅻⅨ ?뺤떇?쇰줈 蹂€?섑빐 二쇱꽭?? (CSV?봋SON?봂xcel ??");
dictionary["data"] = list3;
num = 2;
List<(string, string, string)> list4 = new List<(string, string, string)>(num);
CollectionsMarshal.SetCount(list4, num);
Span<(string, string, string)> span4 = CollectionsMarshal.AsSpan(list4);
span4[0] = ("?대?吏€ ?ㅻ챸", "\ue946", "泥⑤????대?吏€瑜??먯꽭???ㅻ챸??二쇱꽭?? ?댁슜, ?덉씠?꾩썐, ?띿뒪?몃? 遺꾩꽍?섏꽭??");
span4[1] = ("UI 由щ럭", "\ue70f", "泥⑤???UI ?ㅽ겕由곗꺑??由щ럭??二쇱꽭?? UX 媛쒖꽑?? ?묎렐?? ?붿옄???쇨??깆쓣 ?됯??섏꽭??");
dictionary["image"] = list4;
DropActions = dictionary;
CodeExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
".cs", ".py", ".js", ".ts", ".tsx", ".jsx", ".java", ".cpp", ".c", ".h",
".go", ".rs", ".rb", ".php", ".swift", ".kt", ".scala", ".sh", ".ps1", ".bat",
".cmd", ".sql", ".xaml", ".vue"
};
DataExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { ".csv", ".json", ".xml", ".yaml", ".yml", ".tsv" };
WriteToolNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "file_write", "file_edit", "html_create", "xlsx_create", "docx_create", "csv_create", "md_create", "script_create", "diff_preview", "open_external" };
Tips = new string[24]
{
"\ud83d\udca1 ?묒뾽 ?대뜑??AX.md ?뚯씪??留뚮뱾硫?留ㅻ쾲 ?쒖뒪???꾨\?꾪듃???먮룞 二쇱엯?⑸땲?? ?꾨줈?앺듃 ?ㅺ퀎 ?먯튃?대굹 肄붾뵫 洹쒖튃??湲곕줉?섏꽭??", "\ud83d\udca1 Ctrl+1/2/3?쇰줈 Chat/Cowork/Code ??쓣 鍮좊Ⅴ寃??꾪솚?????덉뒿?덈떎.", "\ud83d\udca1 Ctrl+F濡??꾩옱 ?€????硫붿떆吏€瑜?寃€?됲븷 ???덉뒿?덈떎.", "\ud83d\udca1 硫붿떆吏€瑜??고겢由?븯硫?蹂듭궗, ?몄슜 ?듭옣, ?ъ깮?? ??젣瑜??????덉뒿?덈떎.", "\ud83d\udca1 肄붾뱶 釉붾줉???붾툝?대┃?섎㈃ ?꾩껜?붾㈃?쇰줈 蹂????덇퀬, \ud83d\udcbe 踰꾪듉?쇰줈 ?뚯씪 ?€?μ씠 媛€?ν빀?덈떎.", "\ud83d\udca1 Cowork ?먯씠?꾪듃媛€ 留뚮뱺 ?뚯씪?€ ?먮룞?쇰줈 ?좎쭨_?쒓컙 ?묐??ш? 遺숈뼱 ??뼱?곌린瑜?諛⑹??⑸땲??", "\ud83d\udca1 Code ??뿉??媛쒕컻 ?몄뼱瑜??좏깮?섎㈃ ?대떦 ?몄뼱 ?곗꽑?쇰줈 肄붾뱶瑜??앹꽦?⑸땲??", "\ud83d\udca1 ?뚯씪 ?먯깋湲??섎떒 諛?'?뚯씪' 踰꾪듉)?먯꽌 ?붾툝?대┃?쇰줈 ?꾨━酉? ?고겢由?쑝濡?愿€由ы븷 ???덉뒿?덈떎.", "\ud83d\udca1 ?먯씠?꾪듃媛€ 怨꾪쉷???쒖떆?섎㈃ '?섏젙 ?붿껌'?쇰줈 諛⑺뼢??諛붽씀嫄곕굹 '痍⑥냼'濡?以묐떒?????덉뒿?덈떎.", "\ud83d\udca1 Code ??? 鍮뚮뱶/?뚯뒪?몃? ?먮룞?쇰줈 ?ㅽ뻾?⑸땲?? ?꾨줈?앺듃 ?대뜑瑜?癒쇱? ?좏깮?섏꽭??",
"\ud83d\udca1 臾대뱶 媛ㅻ윭由ъ뿉??10媛€€ ?붿옄???쒗뵆由?以??먰븯???ㅽ??쇱쓣 誘몃━蹂닿린濡??좏깮?????덉뒿?덈떎.", "\ud83d\udca1 Git ?곕룞: Code ??뿉???먯씠?꾪듃媛€ git status, diff, commit???섑뻾?⑸땲?? (push??吏곸젒)", "\ud83d\udca1 ?ㅼ젙 ??AX Agent ??怨듯넻?먯꽌 媛쒕컻??紐⑤뱶瑜?耳쒕㈃ ?먯씠?꾪듃 ?숈옉???ㅽ뀦蹂꾨줈 寃€利앺븷 ???덉뒿?덈떎.", "\ud83d\udca1 ?몃젅???꾩씠肄??고겢由???'?ъ슜 ?듦퀎'?먯꽌 ?€??鍮덈룄?€ ?좏겙 ?ъ슜?됱쓣 ?뺤씤?????덉뒿?덈떎.", "\ud83d\udca1 ?€???쒕ぉ???대┃?섎㈃ ?대쫫??蹂€寃쏀븷 ???덉뒿?덈떎.", "\ud83d\udca1 LLM ?ㅻ쪟 諛쒖깮 ??'?ъ떆?? 踰꾪듉???먮룞?쇰줈 ?섑??⑸땲??", "\ud83d\udca1 寃€?됰??먯꽌 ?€???쒕ぉ肉??꾨땲??泥?硫붿떆吏€ ?댁슜源뚯? 寃€?됰맗?덈떎.", "\ud83d\udca1 ?꾨━???좏깮 ?꾩뿉???€?붽? 由ъ뀑?섏? ?딆뒿?덈떎. 吏꾪뻾 以묒씤 ?€?붿뿉???꾨━?뗭쓣 蹂€寃쏀븷 ???덉뒿?덈떎.", "\ud83d\udca1 Shift+Enter濡??쇱? 寃€??寃곌낵???뚯씪???덈뒗 ?대뜑瑜??????덉뒿?덈떎.", "\ud83d\udca1 理쒓렐 ?대뜑瑜??고겢由?븯硫?'?대뜑 ?닿린', '寃쎈줈 蹂듭궗', '紐⑸줉?먯꽌 ??젣'媛€ 媛€?ν빀?덈떎.",
"\ud83d\udca1 Cowork/Code ?먯씠?꾪듃 ?묒뾽 ?꾨즺 ???쒖뒪???몃젅?댁뿉 ?뚮┝???쒖떆?⑸땲??", "\ud83d\udca1 留덊겕?ㅼ슫 ?뚯씠釉? ?몄슜(>), 痍⑥냼??~~), 留곹겕([text](url))媛€ 紐⑤몢 ?뚮뜑留곷맗?덈떎.", "\ud83d\udca1 ???곗씠???대뜑瑜??뚰겕?ㅽ럹?댁뒪濡?吏€?뺥븷 ?뚮뒗 諛섎뱶??諛깆뾽??癒쇱? 留뚮뱶?몄슂!", "\ud83d\udca1 ?쒕씪?대툕 猷⑦듃(C:\\, D:\\)???묒뾽怨듦컙?쇰줈 ?ㅼ젙?????놁뒿?덈떎. ?섏쐞 ?대뜑瑜??좏깮?섏꽭??"
};
GeminiModels = new(string, string)[5]
{
("gemini-2.5-pro", "Gemini 2.5 Pro"),
("gemini-2.5-flash", "Gemini 2.5 Flash"),
("gemini-2.5-flash-lite", "Gemini 2.5 Flash Lite"),
("gemini-2.0-flash", "Gemini 2.0 Flash"),
("gemini-2.0-flash-lite", "Gemini 2.0 Flash Lite")
};
ClaudeModels = new(string, string)[5]
{
("claude-opus-4-6", "Claude Opus 4.6"),
("claude-sonnet-4-6", "Claude Sonnet 4.6"),
("claude-haiku-4-5-20251001", "Claude Haiku 4.5"),
("claude-sonnet-4-5-20250929", "Claude Sonnet 4.5"),
("claude-opus-4-20250514", "Claude Opus 4")
};
_previewableExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { ".html", ".htm", ".md", ".txt", ".csv", ".json", ".xml", ".log" };
WebView2DataFolder = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "AxCopilot", "WebView2");
_ignoredDirs = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
"bin", "obj", "node_modules", ".git", ".vs", ".idea", ".vscode", "__pycache__", ".mypy_cache", ".pytest_cache",
"dist", "build", ".cache", ".next", ".nuxt", "coverage", ".terraform"
};
}
}