Spaces:
Running
Running
File size: 11,775 Bytes
c2ea5ed |
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 |
import React, { useState } from "react";
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
import { Label } from "@/components/ui/label";
import { Input } from "@/components/ui/input";
import { Checkbox } from "@/components/ui/checkbox";
import { Separator } from "@/components/ui/separator";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import { Settings, Zap, RotateCcw } from "lucide-react";
interface PreprocessingOptions {
max_char: number | null;
topk: number;
raw: boolean;
hierarchy: boolean;
replace: boolean;
truncate_enabled: boolean;
}
interface PreprocessingMethodModalProps {
open: boolean;
onOpenChange: (open: boolean) => void;
onConfirm: (options: PreprocessingOptions) => void;
onCancel: () => void;
isLoading?: boolean;
}
export function PreprocessingMethodModal({
open,
onOpenChange,
onConfirm,
onCancel,
isLoading = false,
}: PreprocessingMethodModalProps) {
const [options, setOptions] = useState<PreprocessingOptions>({
max_char: 1000,
topk: 10,
raw: false,
hierarchy: true,
replace: true,
truncate_enabled: false,
});
const handleConfirm = () => {
// Set max_char to null if truncate is disabled
const processedOptions = {
...options,
max_char: options.truncate_enabled ? options.max_char : null
};
onConfirm(processedOptions);
};
const handleReset = () => {
setOptions({
max_char: 1000,
topk: 10,
raw: false,
hierarchy: true,
replace: true,
truncate_enabled: false,
});
};
const updateOption = <K extends keyof PreprocessingOptions>(
key: K,
value: PreprocessingOptions[K]
) => {
setOptions(prev => ({ ...prev, [key]: value }));
};
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="sm:max-w-2xl max-h-[90vh] overflow-y-auto">
<DialogHeader>
<DialogTitle className="flex items-center gap-2">
<Settings className="h-5 w-5" />
Preprocessing Configuration
</DialogTitle>
<DialogDescription>
Configure how traces will be processed before import. Adjust these settings to optimize trace analysis and storage.
</DialogDescription>
</DialogHeader>
<div className="space-y-6 py-4">
<Card>
<CardHeader className="pb-3">
<div className="flex items-center justify-between">
<div>
<CardTitle className="text-base flex items-center gap-2">
<Settings className="h-5 w-5" />
Preprocessing Configuration
</CardTitle>
<CardDescription>
Configure how traces will be processed before import
</CardDescription>
</div>
{/* Keep Raw Data Toggle - Top right */}
<div className="flex items-center space-x-2">
<Checkbox
id="raw"
checked={options.raw}
onCheckedChange={(checked: boolean) => updateOption('raw', checked)}
disabled={isLoading}
/>
<Label htmlFor="raw" className="text-sm font-medium text-muted-foreground">
Keep Raw Data
</Label>
</div>
</div>
</CardHeader>
<CardContent className="space-y-6">
{options.raw && (
<div className="p-4 bg-red-50 border border-red-200 rounded-md">
<div className="flex items-start gap-3">
<div className="flex-shrink-0">
<div className="w-5 h-5 bg-red-500 rounded-full flex items-center justify-center">
<span className="text-white text-xs font-bold">!</span>
</div>
</div>
<div className="text-sm text-red-800">
<div className="font-semibold text-red-900 mb-2">⚠️ Raw Data Mode Warning</div>
<ul className="space-y-1 text-red-700">
<li>• <strong>Large file sizes:</strong> No compression or truncation applied</li>
<li>• <strong>Unnecessary noise:</strong> Metadata and debug info will reduce analysis quality</li>
<li>• <strong>Agent Graph degradation:</strong> Unfiltered data may harm knowledge extraction</li>
<li>• <strong>Higher processing costs:</strong> Larger files require more resources</li>
</ul>
<div className="mt-2 text-xs text-red-600 italic">
Recommended: Use filtering options for better analysis results
</div>
</div>
</div>
</div>
)}
{/* Show processing options only when raw is false */}
{!options.raw && (
<>
<Separator />
{/* Compression Options */}
<div className="space-y-4">
<div className="flex items-center gap-2">
<Zap className="h-4 w-4" />
<h4 className="text-sm font-medium">Compression Options</h4>
</div>
<div className="space-y-4 pl-6">
{/* Hierarchical Structure */}
<div className="flex items-center space-x-2">
<Checkbox
id="hierarchy"
checked={options.hierarchy}
onCheckedChange={(checked: boolean) => updateOption('hierarchy', checked)}
disabled={isLoading}
/>
<div className="space-y-1">
<Label htmlFor="hierarchy" className="text-sm font-medium">
Hierarchical Structure
</Label>
<p className="text-xs text-muted-foreground">
Organize runs in parent-child hierarchy instead of flat list
</p>
</div>
</div>
{/* Extract Repeated Variables */}
<div className="flex items-center space-x-2">
<Checkbox
id="replace"
checked={options.replace}
onCheckedChange={(checked: boolean) => updateOption('replace', checked)}
disabled={isLoading}
/>
<div className="space-y-1">
<Label htmlFor="replace" className="text-sm font-medium">
Extract Repeated Variables
</Label>
<p className="text-xs text-muted-foreground">
Replace repeated strings with variables to reduce file size
</p>
</div>
</div>
{/* Repeated Variables Count - only when compression is enabled */}
{options.replace && (
<div className="space-y-2">
<Label htmlFor="topk" className="text-sm font-medium">
Repeated Variables Count
</Label>
<Input
id="topk"
type="number"
min="1"
max="50"
value={options.topk}
onChange={(e) => updateOption('topk', parseInt(e.target.value) || 10)}
disabled={isLoading}
/>
<p className="text-xs text-muted-foreground">
Number of repeated strings to extract as variables for compression (1-50)
</p>
</div>
)}
{/* Enable String Truncation */}
<div className="flex items-center space-x-2">
<Checkbox
id="truncate_enabled"
checked={options.truncate_enabled}
onCheckedChange={(checked: boolean) => updateOption('truncate_enabled', checked)}
disabled={isLoading}
/>
<div className="space-y-1">
<Label htmlFor="truncate_enabled" className="text-sm font-medium">
Enable String Truncation
</Label>
<p className="text-xs text-muted-foreground">
Limit the length of strings to manage file size and processing costs
</p>
</div>
</div>
{/* Maximum Characters - only when truncation is enabled */}
{options.truncate_enabled && (
<div className="space-y-2">
<Label htmlFor="max_char" className="text-sm font-medium">
Maximum Characters per String
</Label>
<Input
id="max_char"
type="number"
min="1000"
max="10000"
step="100"
value={options.max_char ?? 1000}
onChange={(e) => updateOption('max_char', parseInt(e.target.value) || 1000)}
disabled={isLoading}
/>
<p className="text-xs text-muted-foreground">
Longer text will be truncated to this length to manage processing costs (1000-10000 characters)
</p>
</div>
)}
</div>
</div>
</>
)}
</CardContent>
</Card>
</div>
<div className="flex justify-between items-center pt-4 border-t">
<Button
variant="outline"
onClick={handleReset}
disabled={isLoading}
className="flex items-center gap-2"
>
<RotateCcw className="h-4 w-4" />
Reset to Defaults
</Button>
<div className="flex gap-3">
<Button variant="outline" onClick={onCancel} disabled={isLoading}>
Cancel
</Button>
<Button onClick={handleConfirm} disabled={isLoading}>
{isLoading ? (
<>
<div className="w-4 h-4 border-2 border-primary border-t-transparent rounded-full animate-spin mr-2" />
Importing...
</>
) : (
<>
<Settings className="h-4 w-4 mr-2" />
Import with Configuration
</>
)}
</Button>
</div>
</div>
</DialogContent>
</Dialog>
);
}
|