Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cdf8ab18fc | |||
| 1c3cbd187b | |||
| c27cc505e1 | |||
| 5579deb433 |
@@ -52,9 +52,13 @@ async def process_file(file_path: str):
|
|||||||
# No new lines
|
# No new lines
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
# Process in batches for large files (max 200 lines at a time)
|
||||||
|
batch_size = 200
|
||||||
|
end_line = min(start_line + batch_size, total_lines)
|
||||||
|
|
||||||
# Parse new content
|
# Parse new content
|
||||||
logger.info(f"Processing {file_path} from line {start_line} to {total_lines}")
|
logger.info(f"Processing {file_path} from line {start_line} to {end_line} (total: {total_lines})")
|
||||||
conversation_data = parser.parse_conversation_file(file_path, start_line)
|
conversation_data = parser.parse_conversation_file(file_path, start_line, end_line)
|
||||||
|
|
||||||
if not conversation_data:
|
if not conversation_data:
|
||||||
logger.warning(f"No data extracted from {file_path}")
|
logger.warning(f"No data extracted from {file_path}")
|
||||||
@@ -87,10 +91,10 @@ async def process_file(file_path: str):
|
|||||||
for tool_call in conversation_data['tool_calls']:
|
for tool_call in conversation_data['tool_calls']:
|
||||||
await db.insert_tool_call(tool_call)
|
await db.insert_tool_call(tool_call)
|
||||||
|
|
||||||
# Update checkpoint
|
# Update checkpoint (use end_line instead of total_lines for batch processing)
|
||||||
await db.update_checkpoint(file_path, total_lines, file_mtime)
|
await db.update_checkpoint(file_path, end_line, file_mtime)
|
||||||
|
|
||||||
logger.info(f"Processed {len(conversation_data['messages'])} messages from {file_path}")
|
logger.info(f"Processed {len(conversation_data['messages'])} messages from {file_path} (batch {start_line}-{end_line}/{total_lines})")
|
||||||
return len(conversation_data['messages'])
|
return len(conversation_data['messages'])
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -6,14 +6,16 @@ from typing import Dict, List, Any, Optional
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def parse_jsonl_file(file_path: str, start_line: int = 0) -> List[Dict[str, Any]]:
|
def parse_jsonl_file(file_path: str, start_line: int = 0, end_line: int = None) -> List[Dict[str, Any]]:
|
||||||
"""Parse JSONL file from a specific line number"""
|
"""Parse JSONL file from a specific line number to end_line (or EOF if None)"""
|
||||||
messages = []
|
messages = []
|
||||||
try:
|
try:
|
||||||
with open(file_path, 'r', encoding='utf-8') as f:
|
with open(file_path, 'r', encoding='utf-8') as f:
|
||||||
for i, line in enumerate(f):
|
for i, line in enumerate(f):
|
||||||
if i < start_line:
|
if i < start_line:
|
||||||
continue
|
continue
|
||||||
|
if end_line is not None and i >= end_line:
|
||||||
|
break
|
||||||
if not line.strip():
|
if not line.strip():
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
@@ -169,9 +171,9 @@ def calculate_conversation_stats(messages: List[Dict[str, Any]]) -> Dict[str, An
|
|||||||
return stats
|
return stats
|
||||||
|
|
||||||
|
|
||||||
def parse_conversation_file(file_path: str, start_line: int = 0) -> Dict[str, Any]:
|
def parse_conversation_file(file_path: str, start_line: int = 0, end_line: int = None) -> Dict[str, Any]:
|
||||||
"""Parse a conversation file and extract all data"""
|
"""Parse a conversation file and extract all data"""
|
||||||
raw_messages = parse_jsonl_file(file_path, start_line)
|
raw_messages = parse_jsonl_file(file_path, start_line, end_line)
|
||||||
|
|
||||||
if not raw_messages:
|
if not raw_messages:
|
||||||
return None
|
return None
|
||||||
|
|||||||
@@ -202,20 +202,29 @@ export async function download(path, filename) {
|
|||||||
const headers = {};
|
const headers = {};
|
||||||
if (token) headers["Authorization"] = `Bearer ${token}`;
|
if (token) headers["Authorization"] = `Bearer ${token}`;
|
||||||
|
|
||||||
const r = await fetch(`${BASE}/files/download?path=${encodeURIComponent(path)}`, {
|
try {
|
||||||
method: "GET",
|
const r = await fetch(`${BASE}/files/download?path=${encodeURIComponent(path)}`, {
|
||||||
headers,
|
method: "GET",
|
||||||
});
|
headers,
|
||||||
|
});
|
||||||
|
|
||||||
if (!r.ok) throw new Error(`HTTP ${r.status}`);
|
if (!r.ok) {
|
||||||
|
const errorText = await r.text();
|
||||||
|
console.error(`Download failed: ${r.status} - ${errorText}`);
|
||||||
|
throw new Error(`Download failed: ${r.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
const blob = await r.blob();
|
const blob = await r.blob();
|
||||||
const url = window.URL.createObjectURL(blob);
|
const url = window.URL.createObjectURL(blob);
|
||||||
const a = document.createElement("a");
|
const a = document.createElement("a");
|
||||||
a.href = url;
|
a.href = url;
|
||||||
a.download = filename;
|
a.download = filename;
|
||||||
document.body.appendChild(a);
|
document.body.appendChild(a);
|
||||||
a.click();
|
a.click();
|
||||||
window.URL.revokeObjectURL(url);
|
window.URL.revokeObjectURL(url);
|
||||||
document.body.removeChild(a);
|
document.body.removeChild(a);
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Download error:", e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
let currentPath = $state("");
|
let currentPath = $state("");
|
||||||
let loading = $state(true);
|
let loading = $state(true);
|
||||||
let uploading = $state(false);
|
let uploading = $state(false);
|
||||||
|
let downloading = $state(false);
|
||||||
|
let error = $state("");
|
||||||
let fileInput;
|
let fileInput;
|
||||||
|
|
||||||
async function browse(path) {
|
async function browse(path) {
|
||||||
@@ -31,7 +33,16 @@
|
|||||||
|
|
||||||
async function handleDownload(name) {
|
async function handleDownload(name) {
|
||||||
const path = currentPath ? `${currentPath}/${name}` : name;
|
const path = currentPath ? `${currentPath}/${name}` : name;
|
||||||
await download(path, name);
|
downloading = true;
|
||||||
|
error = "";
|
||||||
|
try {
|
||||||
|
await download(path, name);
|
||||||
|
} catch (e) {
|
||||||
|
error = `Failed to download "${name}": ${e.message}`;
|
||||||
|
console.error("Download failed:", e);
|
||||||
|
} finally {
|
||||||
|
downloading = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleUpload() {
|
async function handleUpload() {
|
||||||
@@ -84,6 +95,23 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Error message -->
|
||||||
|
{#if error}
|
||||||
|
<div class="bg-rose-50 dark:bg-rose-900/20 border border-rose-200 dark:border-rose-800 rounded-lg px-4 py-3 flex items-start gap-3">
|
||||||
|
<svg class="w-5 h-5 text-rose-500 shrink-0 mt-0.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||||
|
</svg>
|
||||||
|
<div class="flex-1">
|
||||||
|
<p class="text-sm text-rose-700 dark:text-rose-300">{error}</p>
|
||||||
|
</div>
|
||||||
|
<button onclick={() => error = ""} class="text-rose-400 hover:text-rose-600 transition-colors">
|
||||||
|
<svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<!-- Breadcrumbs -->
|
<!-- Breadcrumbs -->
|
||||||
<div class="flex items-center gap-1 text-sm flex-wrap">
|
<div class="flex items-center gap-1 text-sm flex-wrap">
|
||||||
<button class="text-primary-600 hover:text-primary-700 font-medium transition-colors" onclick={() => browse("")}>volume1</button>
|
<button class="text-primary-600 hover:text-primary-700 font-medium transition-colors" onclick={() => browse("")}>volume1</button>
|
||||||
@@ -137,7 +165,9 @@
|
|||||||
<span class="text-xs text-surface-400 text-right">{e.is_dir ? "—" : formatSize(e.size)}</span>
|
<span class="text-xs text-surface-400 text-right">{e.is_dir ? "—" : formatSize(e.size)}</span>
|
||||||
<div class="flex items-center justify-end gap-1 opacity-100 md:opacity-0 md:group-hover:opacity-100 transition-opacity">
|
<div class="flex items-center justify-end gap-1 opacity-100 md:opacity-0 md:group-hover:opacity-100 transition-opacity">
|
||||||
{#if !e.is_dir}
|
{#if !e.is_dir}
|
||||||
<button onclick={() => handleDownload(e.name)} class="text-[11px] text-primary-500 hover:text-primary-700 font-medium transition-colors">DL</button>
|
<button onclick={() => handleDownload(e.name)} class="text-[11px] text-primary-500 hover:text-primary-700 font-medium transition-colors disabled:opacity-50" disabled={downloading}>
|
||||||
|
{downloading ? "..." : "DL"}
|
||||||
|
</button>
|
||||||
{/if}
|
{/if}
|
||||||
<button class="text-[11px] text-rose-400 hover:text-rose-600 font-medium transition-colors" onclick={() => remove(e.name)}>Del</button>
|
<button class="text-[11px] text-rose-400 hover:text-rose-600 font-medium transition-colors" onclick={() => remove(e.name)}>Del</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user