-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.AgentHandlers.cs
More file actions
314 lines (276 loc) · 12.6 KB
/
Copy pathMainWindow.AgentHandlers.cs
File metadata and controls
314 lines (276 loc) · 12.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Verdict.Models;
using Verdict.Views;
namespace Verdict;
/// <summary>
/// Agent-related event handlers: add, edit, delete, generate jurors, chat, reports, context menus.
/// </summary>
public partial class MainWindow
{
private void AddAgent_Click(object sender, RoutedEventArgs e)
{
var menuItem = sender as FrameworkElement;
var agent = menuItem?.DataContext as Agent;
if (agent != null)
{
var agentToEdit = agent.IsOccupied ? agent : new Agent
{
Role = agent.Role,
Name = agent.Name.StartsWith("+") ? "" : agent.Name
};
if (!agent.IsOccupied)
{
ApplyRoleDefaults(agentToEdit);
var roleModel = ViewModels.MainViewModel.GetDefaultModelForRole(
agentToEdit.Role, agentToEdit.CommunicationTeam, _viewModel.CurrentCase);
if (!string.IsNullOrWhiteSpace(roleModel))
agentToEdit.SelectedModel = roleModel;
}
var profileWindow = new AgentProfileWindow(agentToEdit, _viewModel.EffectiveModels) { Owner = this };
if (profileWindow.ShowDialog() == true)
{
if (profileWindow.DataContext is AgentWithAvailableModels wrapper)
{
if (!agent.IsOccupied)
{
agent.Name = string.IsNullOrWhiteSpace(wrapper.Name) ? $"Active {wrapper.Role}" : wrapper.Name;
agent.Gender = wrapper.Gender;
agent.Age = wrapper.Age;
agent.Race = wrapper.Race;
agent.Occupation = wrapper.Occupation;
agent.EducationLevel = wrapper.EducationLevel;
agent.IncomeLevel = wrapper.IncomeLevel;
agent.ZipCode = wrapper.ZipCode;
agent.PoliticalAffiliation = wrapper.PoliticalAffiliation;
agent.ReligiousAffiliation = wrapper.ReligiousAffiliation;
agent.SpecializedKnowledge = wrapper.SpecializedKnowledge;
agent.MaritalStatus = wrapper.MaritalStatus;
agent.ParentalStatus = wrapper.ParentalStatus;
agent.SettlementAuthority = wrapper.SettlementAuthority;
agent.RiskPerception = wrapper.RiskPerception;
agent.MediaConsumption = wrapper.MediaConsumption;
agent.ConsumerSegment = wrapper.ConsumerSegment;
agent.Hobbies = wrapper.Hobbies;
agent.ViewingCharacteristics = wrapper.ViewingCharacteristics;
agent.CurrentStatus = wrapper.CurrentStatus;
agent.SystemPrompt = wrapper.SystemPrompt;
}
agent.SelectedModel = wrapper.SelectedModel;
}
_viewModel.OccupySlot(agent);
}
}
else
{
MessageBox.Show("Could not create agent profile. Invalid agent data.", "Error",
MessageBoxButton.OK, MessageBoxImage.Error);
}
}
/// <summary>
/// Applies role-appropriate default values for new agents.
/// </summary>
private static void ApplyRoleDefaults(Agent agent)
{
switch (agent.Role)
{
case AgentRole.Judge:
agent.CommunicationTeam = "Neutral";
agent.OnlyAnswerWhenAsked = true;
agent.Occupation = "Judge";
agent.EducationLevel = "Juris Doctor (JD)";
agent.Age = Math.Max(agent.Age, 40);
agent.SpecializedKnowledge = "Criminal Law, Tort Law, Civil Law, Family Law";
break;
case AgentRole.Lawyer:
agent.CommunicationTeam = "Neutral";
agent.Age = Math.Max(agent.Age, 25);
agent.Occupation = "Attorney";
agent.EducationLevel = "Juris Doctor (JD)";
agent.SpecializedKnowledge = "Criminal Law, Tort Law, Civil Law";
break;
case AgentRole.Witness:
agent.Occupation = string.IsNullOrWhiteSpace(agent.Occupation) || agent.Occupation == "Unemployed"
? "Professional" : agent.Occupation;
break;
case AgentRole.Reporter:
agent.Occupation = "Court Reporter";
agent.EducationLevel = "Associate Degree";
break;
}
}
private void GenerateLikelyJuror_Click(object sender, RoutedEventArgs e)
{
var menuItem = sender as MenuItem;
var agent = menuItem?.Tag as Agent;
if (agent == null) return;
if (agent.Role != AgentRole.Juror && agent.Role != AgentRole.AlternateJuror)
{
MessageBox.Show("This feature is only available for juror seats.", "Invalid Operation",
MessageBoxButton.OK, MessageBoxImage.Information);
return;
}
string jurisdiction = _viewModel.CurrentCase.JurisdictionSpecifics ?? "Richland County, South Carolina";
string[] parts = jurisdiction.Split(',');
string county = parts.Length > 0 && !string.IsNullOrWhiteSpace(parts[0]) ? parts[0].Trim() : "Richland County";
string state = parts.Length > 1 && !string.IsNullOrWhiteSpace(parts[1]) ? parts[1].Trim() : "South Carolina";
var newJuror = _viewModel.GenerateSingleJuror(county, state);
agent.Name = newJuror.Name;
agent.Gender = newJuror.Gender;
agent.Age = newJuror.Age;
agent.Race = newJuror.Race;
agent.Occupation = newJuror.Occupation;
agent.EducationLevel = newJuror.EducationLevel;
agent.IncomeLevel = newJuror.IncomeLevel;
agent.ZipCode = newJuror.ZipCode;
agent.PoliticalAffiliation = newJuror.PoliticalAffiliation;
agent.ReligiousAffiliation = newJuror.ReligiousAffiliation;
agent.SpecializedKnowledge = newJuror.SpecializedKnowledge;
agent.MaritalStatus = newJuror.MaritalStatus;
agent.ParentalStatus = newJuror.ParentalStatus;
agent.SettlementAuthority = newJuror.SettlementAuthority;
agent.RiskPerception = newJuror.RiskPerception;
agent.MediaConsumption = newJuror.MediaConsumption;
agent.ConsumerSegment = newJuror.ConsumerSegment;
agent.Hobbies = newJuror.Hobbies;
agent.ViewingCharacteristics = newJuror.ViewingCharacteristics;
agent.CurrentStatus = newJuror.CurrentStatus;
agent.SystemPrompt = newJuror.SystemPrompt;
agent.Profile = newJuror.Profile;
agent.Bias = newJuror.Bias;
agent.VerdictLean = newJuror.VerdictLean;
agent.Sentiment = newJuror.Sentiment;
agent.TrialEvents.Clear();
foreach (var mem in newJuror.TrialEvents)
agent.TrialEvents.Add(mem);
if (!agent.IsOccupied)
_viewModel.OccupySlot(agent);
_viewModel.TranscriptOutput = $"[JUROR GENERATED] New juror generated based on {county}, {state} demographics";
}
private void SaveAgent_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("Agent saved to global casefile.");
}
private void ExportCharacter_Click(object sender, RoutedEventArgs e)
{
if (sender is FrameworkElement element && element.DataContext is Agent agent && agent.IsOccupied)
{
Services.CharacterManager.SaveCharacter(agent);
MessageBox.Show($"Character profile saved to {Services.CharacterManager.RepositoryPath}");
}
}
private void DeleteAgent_Click(object sender, RoutedEventArgs e)
{
var menuItem = sender as FrameworkElement;
var agent = menuItem?.DataContext as Agent;
if (agent != null)
{
agent.IsOccupied = false;
agent.Name = "Unoccupied " + agent.Role;
}
}
private void EditReporterProfile_Click(object sender, RoutedEventArgs e)
{
var menuItem = sender as FrameworkElement;
var agent = menuItem?.DataContext as Agent;
if (agent == null) return;
var profileWindow = new AgentProfileWindow(agent, _viewModel.EffectiveModels) { Owner = this };
if (profileWindow.ShowDialog() == true)
{
if (profileWindow.DataContext is AgentWithAvailableModels wrapper)
{
agent.SelectedModel = wrapper.SelectedModel;
agent.SystemPrompt = wrapper.SystemPrompt;
}
}
}
private void AgentSeat_ContextMenuOpening(object sender, ContextMenuEventArgs e)
{
var border = sender as Border;
if (border?.ContextMenu == null) return;
var agent = border.DataContext as Agent;
foreach (var item in border.ContextMenu.Items.OfType<MenuItem>())
{
if (item.Header.ToString() == "Chat")
item.Visibility = (agent != null && agent.IsOccupied) ? Visibility.Visible : Visibility.Collapsed;
else if (item.Header.ToString() == "Juror Report")
item.Visibility = (agent != null && agent.IsOccupied &&
(agent.Role == AgentRole.Juror || agent.Role == AgentRole.AlternateJuror))
? Visibility.Visible : Visibility.Collapsed;
else if (item.Header.ToString() == "Opinion Drift ▸")
item.Visibility = (agent != null && agent.IsOccupied)
? Visibility.Visible : Visibility.Collapsed;
else
item.Visibility = Visibility.Visible;
}
}
private void AddClientToLawyer_Click(object sender, RoutedEventArgs e)
{
var menuItem = sender as FrameworkElement;
var agent = menuItem?.DataContext as Agent;
if (agent == null) return;
var lawyers = _viewModel.AllAgents.Where(a => a.Role == AgentRole.Lawyer && a.IsOccupied).ToList();
if (!lawyers.Any())
{
MessageBox.Show("No lawyers are seated. Please add a lawyer first.", "No Lawyer Available",
MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
var clientAgent = new Agent
{
Role = AgentRole.Client,
Name = $"Client (of {agent.Name.Split(' ').LastOrDefault() ?? agent.Name})",
IsOccupied = true
};
_viewModel.Gallery.Add(clientAgent);
MessageBox.Show($"Client assigned to {agent.Name}. Client added to gallery area.",
"Client Added", MessageBoxButton.OK, MessageBoxImage.Information);
}
private void AgentChat_Click(object sender, RoutedEventArgs e)
{
var menuItem = sender as FrameworkElement;
var agent = menuItem?.Tag as Agent;
if (agent == null || !agent.IsOccupied) return;
var window = new AgentChatWindow(_viewModel, agent) { Owner = this };
window.ShowDialog();
}
private void JurorReport_Click(object sender, RoutedEventArgs e)
{
var menuItem = sender as FrameworkElement;
var agent = menuItem?.Tag as Agent;
if (agent == null || !agent.IsOccupied) return;
var reportWindow = new JurorReportWindow(agent, _viewModel.CurrentCase?.Mode ?? Models.CaseMode.Civil) { Owner = this };
reportWindow.ShowDialog();
}
private void OpinionDrift_Click(object sender, RoutedEventArgs e)
{
var menuItem = sender as FrameworkElement;
var agent = menuItem?.Tag as Agent;
if (agent == null || !agent.IsOccupied) return;
if (agent.OpinionHistory.Count == 0)
{
MessageBox.Show($"{agent.Name} has no opinion history yet. Run a trial or deliberation to collect data.",
"No Data", MessageBoxButton.OK, MessageBoxImage.Information);
return;
}
var chartWindow = new JurorLeanChartWindow(new[] { agent }) { Owner = this, Title = $"Opinion Drift — {agent.Name}" };
chartWindow.ShowDialog();
}
private void OpinionChartAll_Click(object sender, RoutedEventArgs e)
{
var allJurors = _viewModel.AllAgents
.Where(a => a.IsOccupied && a.CanVote)
.ToList();
if (allJurors.All(j => j.OpinionHistory.Count == 0))
{
MessageBox.Show("No opinion history recorded yet. Run a trial or deliberation to collect data.",
"No Data", MessageBoxButton.OK, MessageBoxImage.Information);
return;
}
var chartWindow = new JurorLeanChartWindow(allJurors) { Owner = this };
chartWindow.ShowDialog();
}
}