Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- frontend/court/court.js +76 -34
frontend/court/court.js
CHANGED
|
@@ -168,17 +168,6 @@ function enterCourtroom() {
|
|
| 168 |
|
| 169 |
async function createNewSession() {
|
| 170 |
try {
|
| 171 |
-
const briefingPhase = {
|
| 172 |
-
round: 0,
|
| 173 |
-
parties: {
|
| 174 |
-
user: { side: state.setupData.side, client: state.setupData.userClient },
|
| 175 |
-
opposing: { client: state.setupData.opposingParty }
|
| 176 |
-
},
|
| 177 |
-
legalIssues: state.setupData.issues,
|
| 178 |
-
jurisdiction: state.setupData.jurisdiction,
|
| 179 |
-
facts: state.setupData.facts
|
| 180 |
-
};
|
| 181 |
-
|
| 182 |
const requestBody = {
|
| 183 |
case_title: state.setupData.title,
|
| 184 |
jurisdiction: state.setupData.jurisdiction,
|
|
@@ -198,23 +187,30 @@ async function createNewSession() {
|
|
| 198 |
body: JSON.stringify(requestBody)
|
| 199 |
});
|
| 200 |
|
| 201 |
-
if (!response.ok)
|
|
|
|
|
|
|
|
|
|
| 202 |
|
| 203 |
const data = await response.json();
|
|
|
|
|
|
|
| 204 |
state.currentSession = data.session_id;
|
|
|
|
|
|
|
| 205 |
|
| 206 |
-
//
|
| 207 |
showScreen('courtroom');
|
| 208 |
await loadSessionData();
|
| 209 |
|
| 210 |
// Add opening statement to transcript
|
| 211 |
setTimeout(() => {
|
| 212 |
-
addTranscriptEntry('registrar', 'The court is now in session. ' + data.opening_statement || 'Proceedings begin.');
|
| 213 |
}, 300);
|
| 214 |
|
| 215 |
} catch (error) {
|
| 216 |
console.error('Error creating session:', error);
|
| 217 |
-
alert('Failed to create session
|
| 218 |
}
|
| 219 |
}
|
| 220 |
|
|
@@ -245,13 +241,27 @@ async function loadSessionData() {
|
|
| 245 |
}
|
| 246 |
|
| 247 |
async function submitArgument() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 248 |
const textarea = document.getElementById('argument-input');
|
| 249 |
const argument = textarea.value.trim();
|
| 250 |
|
| 251 |
-
if (!argument)
|
| 252 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
|
| 254 |
-
// Add user's argument to transcript
|
| 255 |
addTranscriptEntry('user', argument);
|
| 256 |
|
| 257 |
textarea.value = '';
|
|
@@ -272,7 +282,10 @@ async function submitArgument() {
|
|
| 272 |
})
|
| 273 |
});
|
| 274 |
|
| 275 |
-
if (!response.ok)
|
|
|
|
|
|
|
|
|
|
| 276 |
|
| 277 |
const data = await response.json();
|
| 278 |
|
|
@@ -327,15 +340,28 @@ async function submitArgument() {
|
|
| 327 |
}
|
| 328 |
|
| 329 |
async function submitObjection() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 330 |
const selectedType = document.querySelector('input[name="obj-type"]:checked');
|
| 331 |
-
if (!selectedType)
|
|
|
|
|
|
|
|
|
|
| 332 |
|
| 333 |
const objectionType = selectedType.value;
|
| 334 |
let objectionText = objectionType;
|
| 335 |
|
| 336 |
if (objectionType === 'custom') {
|
| 337 |
objectionText = document.getElementById('custom-objection').value.trim();
|
| 338 |
-
if (!objectionText)
|
|
|
|
|
|
|
|
|
|
| 339 |
}
|
| 340 |
|
| 341 |
try {
|
|
@@ -356,13 +382,24 @@ async function submitObjection() {
|
|
| 356 |
addTranscriptEntry('judge', data.judge_response);
|
| 357 |
}
|
| 358 |
closeModal('objection-modal');
|
|
|
|
|
|
|
|
|
|
| 359 |
}
|
| 360 |
} catch (error) {
|
| 361 |
console.error('Objection error:', error);
|
|
|
|
| 362 |
}
|
| 363 |
}
|
| 364 |
|
| 365 |
async function submitDocumentRequest() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 366 |
const docType = document.querySelector('input[name="doc-type"]:checked').value;
|
| 367 |
const docSide = document.querySelector('input[name="doc-side"]:checked').value;
|
| 368 |
|
|
@@ -378,22 +415,27 @@ async function submitDocumentRequest() {
|
|
| 378 |
})
|
| 379 |
});
|
| 380 |
|
| 381 |
-
if (response.ok) {
|
| 382 |
-
const
|
| 383 |
-
|
| 384 |
-
id: state.documents.length,
|
| 385 |
-
title: docType,
|
| 386 |
-
content: data.document_content,
|
| 387 |
-
filedBy: docSide,
|
| 388 |
-
timestamp: new Date()
|
| 389 |
-
});
|
| 390 |
-
|
| 391 |
-
addTranscriptEntry('user', `[DOCUMENT PRODUCED: ${docType}]`);
|
| 392 |
-
renderDocumentsList();
|
| 393 |
-
closeModal('document-modal');
|
| 394 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 395 |
} catch (error) {
|
| 396 |
console.error('Document error:', error);
|
|
|
|
| 397 |
} finally {
|
| 398 |
state.isWaitingForResponse = false;
|
| 399 |
}
|
|
|
|
| 168 |
|
| 169 |
async function createNewSession() {
|
| 170 |
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
const requestBody = {
|
| 172 |
case_title: state.setupData.title,
|
| 173 |
jurisdiction: state.setupData.jurisdiction,
|
|
|
|
| 187 |
body: JSON.stringify(requestBody)
|
| 188 |
});
|
| 189 |
|
| 190 |
+
if (!response.ok) {
|
| 191 |
+
const errorData = await response.json();
|
| 192 |
+
throw new Error(errorData.detail || 'Failed to create session');
|
| 193 |
+
}
|
| 194 |
|
| 195 |
const data = await response.json();
|
| 196 |
+
|
| 197 |
+
// CRITICAL: Set session state BEFORE initializing UI
|
| 198 |
state.currentSession = data.session_id;
|
| 199 |
+
state.currentRound = 0;
|
| 200 |
+
console.log("✓ Session ID stored:", state.currentSession);
|
| 201 |
|
| 202 |
+
// Only AFTER session state is set, initialize courtroom UI
|
| 203 |
showScreen('courtroom');
|
| 204 |
await loadSessionData();
|
| 205 |
|
| 206 |
// Add opening statement to transcript
|
| 207 |
setTimeout(() => {
|
| 208 |
+
addTranscriptEntry('registrar', 'The court is now in session. ' + (data.opening_statement || 'Proceedings begin.'));
|
| 209 |
}, 300);
|
| 210 |
|
| 211 |
} catch (error) {
|
| 212 |
console.error('Error creating session:', error);
|
| 213 |
+
alert('Failed to create session: ' + error.message);
|
| 214 |
}
|
| 215 |
}
|
| 216 |
|
|
|
|
| 241 |
}
|
| 242 |
|
| 243 |
async function submitArgument() {
|
| 244 |
+
// Validation: ensure session exists before proceeding
|
| 245 |
+
if (!state.currentSession) {
|
| 246 |
+
alert("Session not found. Please start a new case.");
|
| 247 |
+
showScreen('lobby');
|
| 248 |
+
return;
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
const textarea = document.getElementById('argument-input');
|
| 252 |
const argument = textarea.value.trim();
|
| 253 |
|
| 254 |
+
if (!argument || argument.length < 10) {
|
| 255 |
+
if (argument.length > 0) alert('Argument too short (minimum 10 characters)');
|
| 256 |
+
return;
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
if (state.isWaitingForResponse) {
|
| 260 |
+
alert('Waiting for court response. Please be patient.');
|
| 261 |
+
return;
|
| 262 |
+
}
|
| 263 |
|
| 264 |
+
// Add user's argument to transcript immediately
|
| 265 |
addTranscriptEntry('user', argument);
|
| 266 |
|
| 267 |
textarea.value = '';
|
|
|
|
| 282 |
})
|
| 283 |
});
|
| 284 |
|
| 285 |
+
if (!response.ok) {
|
| 286 |
+
const error = await response.json();
|
| 287 |
+
throw new Error(error.detail || 'Argument submission failed');
|
| 288 |
+
}
|
| 289 |
|
| 290 |
const data = await response.json();
|
| 291 |
|
|
|
|
| 340 |
}
|
| 341 |
|
| 342 |
async function submitObjection() {
|
| 343 |
+
console.log("Objection - Session ID:", state.currentSession); // DEBUG
|
| 344 |
+
|
| 345 |
+
if (!state.currentSession) {
|
| 346 |
+
alert("No active session. Cannot file objection.");
|
| 347 |
+
return;
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
const selectedType = document.querySelector('input[name="obj-type"]:checked');
|
| 351 |
+
if (!selectedType) {
|
| 352 |
+
alert("Please select an objection type.");
|
| 353 |
+
return;
|
| 354 |
+
}
|
| 355 |
|
| 356 |
const objectionType = selectedType.value;
|
| 357 |
let objectionText = objectionType;
|
| 358 |
|
| 359 |
if (objectionType === 'custom') {
|
| 360 |
objectionText = document.getElementById('custom-objection').value.trim();
|
| 361 |
+
if (!objectionText) {
|
| 362 |
+
alert("Please enter your objection.");
|
| 363 |
+
return;
|
| 364 |
+
}
|
| 365 |
}
|
| 366 |
|
| 367 |
try {
|
|
|
|
| 382 |
addTranscriptEntry('judge', data.judge_response);
|
| 383 |
}
|
| 384 |
closeModal('objection-modal');
|
| 385 |
+
} else {
|
| 386 |
+
const error = await response.json();
|
| 387 |
+
alert('Error filing objection: ' + (error.detail || 'Unknown error'));
|
| 388 |
}
|
| 389 |
} catch (error) {
|
| 390 |
console.error('Objection error:', error);
|
| 391 |
+
alert('Error filing objection: ' + error.message);
|
| 392 |
}
|
| 393 |
}
|
| 394 |
|
| 395 |
async function submitDocumentRequest() {
|
| 396 |
+
console.log("Document request - Session ID:", state.currentSession); // DEBUG
|
| 397 |
+
|
| 398 |
+
if (!state.currentSession) {
|
| 399 |
+
alert("No active session. Cannot produce document.");
|
| 400 |
+
return;
|
| 401 |
+
}
|
| 402 |
+
|
| 403 |
const docType = document.querySelector('input[name="doc-type"]:checked').value;
|
| 404 |
const docSide = document.querySelector('input[name="doc-side"]:checked').value;
|
| 405 |
|
|
|
|
| 415 |
})
|
| 416 |
});
|
| 417 |
|
| 418 |
+
if (!response.ok) {
|
| 419 |
+
const error = await response.json();
|
| 420 |
+
throw new Error(error.detail || 'Failed to produce document');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 421 |
}
|
| 422 |
+
|
| 423 |
+
const data = await response.json();
|
| 424 |
+
state.documents.push({
|
| 425 |
+
id: state.documents.length,
|
| 426 |
+
title: docType,
|
| 427 |
+
content: data.document_content,
|
| 428 |
+
filedBy: docSide,
|
| 429 |
+
timestamp: new Date()
|
| 430 |
+
});
|
| 431 |
+
|
| 432 |
+
addTranscriptEntry('user', `[DOCUMENT PRODUCED: ${docType}]`);
|
| 433 |
+
renderDocumentsList();
|
| 434 |
+
closeModal('document-modal');
|
| 435 |
+
alert('Document produced and filed successfully.');
|
| 436 |
} catch (error) {
|
| 437 |
console.error('Document error:', error);
|
| 438 |
+
alert('Error producing document: ' + error.message);
|
| 439 |
} finally {
|
| 440 |
state.isWaitingForResponse = false;
|
| 441 |
}
|