feat(digests): Phase 2 — API endpoints + /digests UI (X12)
משטחי-משתמש לקורפוס היומונים: endpoints ב-FastAPI + דף UI נפרד /digests (לדפדוף, חיפוש, העלאה, וקישור לפסק המקורי). היומון נשאר מקור-משני המצביע על הפסק — אינו מצוטט בהחלטה (INV-DIG1) ואינו מחלץ הלכות (INV-DIG2). Backend (container-safe + local split): - digest_library: פוצל ל-create_pending_digest (CONTAINER-SAFE: stage+ extract_text+create row 'pending', בלי LLM) ↔ enrich_digest/ process_pending_digests (local: LLM+embed+autolink). ingest_digest מאחד. - db.list_pending_digests; MCP digest_process_pending (tool+server) — חלופה ל-batch script לריקון התור. - web/app.py: 10 endpoints /api/digests/* (upload/list/search/queue-pending/ get/patch/delete/link/relink/unlink). upload=INSERT-only pending (ה-LLM רץ מקומית — claude_session local-only). כולם מחזירים dict בדפוס precedent. Frontend (Next 16, ללא api:types — hooks עם טיפוסים hand-written כמו precedent-library.ts): - lib/api/digests.ts — hooks (useDigests/useDigestSearch/useDigestPending/ useUploadDigest/useLink/Relink/Unlink/Delete/Update). - דף /digests נפרד (לא כרטיסייה ב-/precedents — לשמור גבול סמכותי/משני, INV-DIG1): טאבים יומונים/חיפוש + DigestCard (badge קישור-לפסק) + DigestUploadDialog + pending badge. nav + header-context. אומת: backend round-trip מלא (create_pending→list_pending→process_pending→ search→restore); web-ui מתקמפל (webpack/tsc נקי, route /digests נוצר). הערה: build דיפולטי (turbopack) נכשל ב-worktree עקב symlink ל-node_modules — ב-CI/Docker (node_modules אמיתי) עובד; אומת עם --webpack. Invariants: מקיים INV-DIG1/2 (upload לא מחלץ הלכות, UI מציג "מצביע לא מצוטט"), INV-DIG3 (link/relink/queue). G4 (אין בליעה — שגיאות→toast/HTTP), G2 (מסלול נפרד, לא מקביל). X6 (חוזה UI↔API — endpoints בדפוס precedent; hooks hand-written כמו שאר ה-domain modules). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
103
web-ui/src/components/digests/digest-card.tsx
Normal file
103
web-ui/src/components/digests/digest-card.tsx
Normal file
@@ -0,0 +1,103 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import type { ReactNode } from "react";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { practiceAreaLabel } from "@/components/precedents/practice-area";
|
||||
import type { Digest } from "@/lib/api/digests";
|
||||
|
||||
function formatDate(iso: string | null) {
|
||||
if (!iso) return "—";
|
||||
try {
|
||||
return new Date(iso).toLocaleDateString("he-IL");
|
||||
} catch {
|
||||
return iso;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Presentational card for a single digest ("כל יום" radar entry).
|
||||
*
|
||||
* A digest is a SECONDARY source that POINTS at a ruling — the card makes the
|
||||
* pointer-not-citation nature explicit: the underlying ruling's citation is
|
||||
* shown with a link-status badge (linked → the ruling is in the precedent
|
||||
* library; unlinked → an open knowledge gap, INV-DIG3).
|
||||
*/
|
||||
export function DigestCard({
|
||||
digest,
|
||||
score,
|
||||
actions,
|
||||
}: {
|
||||
digest: Digest;
|
||||
score?: number;
|
||||
actions?: ReactNode;
|
||||
}) {
|
||||
const linked = Boolean(digest.linked_case_law_id);
|
||||
return (
|
||||
<div className="rounded-lg border border-rule bg-surface p-4 space-y-2">
|
||||
<div className="flex items-center gap-2 text-[0.78rem] text-ink-muted flex-wrap">
|
||||
{digest.concept_tag && (
|
||||
<Badge className="bg-gold text-navy border-0">{digest.concept_tag}</Badge>
|
||||
)}
|
||||
{digest.yomon_number && (
|
||||
<span className="font-mono" dir="ltr">
|
||||
יומון {digest.yomon_number}
|
||||
</span>
|
||||
)}
|
||||
{digest.digest_date && <span>· {formatDate(digest.digest_date)}</span>}
|
||||
{digest.practice_area && (
|
||||
<span>· {practiceAreaLabel(digest.practice_area)}</span>
|
||||
)}
|
||||
{digest.extraction_status !== "completed" && (
|
||||
<Badge variant="outline" className="bg-rule-soft text-ink-muted text-[0.65rem]">
|
||||
{digest.extraction_status === "pending" ? "ממתין לעיבוד" : digest.extraction_status}
|
||||
</Badge>
|
||||
)}
|
||||
{typeof score === "number" && (
|
||||
<span className="ms-auto tabular-nums">דירוג {score.toFixed(2)}</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{digest.headline_holding && (
|
||||
<p className="text-navy font-medium text-[0.95rem]" dir="rtl">
|
||||
{digest.headline_holding}
|
||||
</p>
|
||||
)}
|
||||
{digest.summary && (
|
||||
<p className="text-ink-soft text-sm leading-relaxed" dir="rtl">
|
||||
{digest.summary}
|
||||
</p>
|
||||
)}
|
||||
|
||||
<div className="flex items-start gap-2 flex-wrap pt-1 border-t border-rule-soft mt-1">
|
||||
<span className="text-[0.72rem] text-ink-muted mt-1">פסק מקורי:</span>
|
||||
<span className="text-[0.82rem] text-ink font-mono flex-1 min-w-[200px]" dir="rtl">
|
||||
{digest.underlying_citation || "—"}
|
||||
</span>
|
||||
{linked ? (
|
||||
<Link href={`/precedents/${digest.linked_case_law_id}`}>
|
||||
<Badge className="bg-emerald-100 text-emerald-800 border-emerald-300 hover:bg-emerald-200">
|
||||
מקושר לפסק ↗
|
||||
</Badge>
|
||||
</Link>
|
||||
) : (
|
||||
<Badge variant="outline" className="bg-amber-50 text-amber-700 border-amber-300">
|
||||
הפסק טרם בקורפוס
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{digest.subject_tags?.length > 0 && (
|
||||
<div className="flex flex-wrap gap-1">
|
||||
{digest.subject_tags.map((t) => (
|
||||
<Badge key={t} variant="outline" className="text-[0.65rem] bg-surface">
|
||||
{t}
|
||||
</Badge>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{actions && <div className="flex items-center gap-2 pt-1">{actions}</div>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
136
web-ui/src/components/digests/digest-list-panel.tsx
Normal file
136
web-ui/src/components/digests/digest-list-panel.tsx
Normal file
@@ -0,0 +1,136 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { Link2, Trash2 } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import {
|
||||
Select, SelectContent, SelectItem, SelectTrigger, SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import {
|
||||
useDigests, useDeleteDigest, useRelinkDigest, type DigestListFilters,
|
||||
} from "@/lib/api/digests";
|
||||
import type { PracticeArea } from "@/lib/api/precedent-library";
|
||||
import { PRACTICE_AREAS } from "@/components/precedents/practice-area";
|
||||
import { DigestCard } from "./digest-card";
|
||||
import { DigestUploadDialog } from "./digest-upload-dialog";
|
||||
|
||||
type LinkedFilter = "all" | "linked" | "unlinked";
|
||||
|
||||
export function DigestListPanel() {
|
||||
const [practiceArea, setPracticeArea] = useState<PracticeArea>("");
|
||||
const [linked, setLinked] = useState<LinkedFilter>("all");
|
||||
|
||||
const filters: DigestListFilters = {
|
||||
practiceArea: practiceArea || undefined,
|
||||
linked: linked === "all" ? undefined : linked === "linked",
|
||||
limit: 200,
|
||||
};
|
||||
const { data, isLoading, error } = useDigests(filters);
|
||||
const del = useDeleteDigest();
|
||||
const relink = useRelinkDigest();
|
||||
|
||||
const onRelink = (id: string) =>
|
||||
relink.mutate(id, {
|
||||
onSuccess: (r) =>
|
||||
r.linked
|
||||
? toast.success("קושר לפסק המקורי")
|
||||
: toast.info("הפסק המקורי עדיין לא בקורפוס — העלה אותו לספריית הפסיקה"),
|
||||
onError: (e) => toast.error(e.message),
|
||||
});
|
||||
|
||||
const onDelete = (id: string) => {
|
||||
if (!confirm("למחוק את היומון מקורפוס-הגילוי?")) return;
|
||||
del.mutate(id, {
|
||||
onSuccess: () => toast.success("נמחק"),
|
||||
onError: (e) => toast.error(e.message),
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-end gap-3 flex-wrap">
|
||||
<div className="min-w-[180px]">
|
||||
<label className="text-[0.78rem] text-ink-muted">תחום</label>
|
||||
<Select
|
||||
value={practiceArea || "_all"}
|
||||
onValueChange={(v) => setPracticeArea(v === "_all" ? "" : (v as PracticeArea))}
|
||||
>
|
||||
<SelectTrigger><SelectValue /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="_all">הכל</SelectItem>
|
||||
{PRACTICE_AREAS.map((a) => (
|
||||
<SelectItem key={a.value} value={a.value}>{a.label}</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="min-w-[170px]">
|
||||
<label className="text-[0.78rem] text-ink-muted">קישור לפסק</label>
|
||||
<Select value={linked} onValueChange={(v) => setLinked(v as LinkedFilter)}>
|
||||
<SelectTrigger><SelectValue /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">הכל</SelectItem>
|
||||
<SelectItem value="linked">מקושרים</SelectItem>
|
||||
<SelectItem value="unlinked">לא מקושרים (פער)</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="ms-auto">
|
||||
<DigestUploadDialog />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{error ? (
|
||||
<div className="rounded bg-danger-bg border border-danger/40 px-6 py-5 text-danger text-center">
|
||||
{error.message}
|
||||
</div>
|
||||
) : isLoading ? (
|
||||
<div className="space-y-3">
|
||||
{[...Array(3)].map((_, i) => <Skeleton key={i} className="h-32 w-full" />)}
|
||||
</div>
|
||||
) : !data?.items.length ? (
|
||||
<div className="text-center text-ink-muted py-12">
|
||||
אין יומונים עדיין. העלה יומון "כל יום", או הרץ
|
||||
<span className="font-mono mx-1" dir="ltr">scripts/ingest_digests_batch.py</span>.
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-3">
|
||||
<p className="text-[0.78rem] text-ink-muted">{data.count} יומונים</p>
|
||||
{data.items.map((d) => (
|
||||
<DigestCard
|
||||
key={d.id}
|
||||
digest={d}
|
||||
actions={
|
||||
<>
|
||||
{!d.linked_case_law_id && (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => onRelink(d.id)}
|
||||
disabled={relink.isPending}
|
||||
>
|
||||
<Link2 className="w-3.5 h-3.5 me-1" />
|
||||
נסה לקשר
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="text-danger hover:bg-danger-bg"
|
||||
onClick={() => onDelete(d.id)}
|
||||
disabled={del.isPending}
|
||||
>
|
||||
<Trash2 className="w-3.5 h-3.5 me-1" />
|
||||
מחק
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
95
web-ui/src/components/digests/digest-search-panel.tsx
Normal file
95
web-ui/src/components/digests/digest-search-panel.tsx
Normal file
@@ -0,0 +1,95 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { Search } from "lucide-react";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import {
|
||||
Select, SelectContent, SelectItem, SelectTrigger, SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import { useDigestSearch } from "@/lib/api/digests";
|
||||
import type { PracticeArea } from "@/lib/api/precedent-library";
|
||||
import { PRACTICE_AREAS } from "@/components/precedents/practice-area";
|
||||
import { DigestCard } from "./digest-card";
|
||||
|
||||
export function DigestSearchPanel() {
|
||||
const [draft, setDraft] = useState("");
|
||||
const [query, setQuery] = useState("");
|
||||
const [practiceArea, setPracticeArea] = useState<PracticeArea>("");
|
||||
|
||||
const { data, isFetching, error } = useDigestSearch(query, {
|
||||
practiceArea: practiceArea || undefined,
|
||||
limit: 20,
|
||||
});
|
||||
|
||||
const onSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
setQuery(draft.trim());
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<form onSubmit={onSubmit} className="flex items-end gap-3 flex-wrap">
|
||||
<div className="flex-1 min-w-[300px]">
|
||||
<label className="text-[0.78rem] text-ink-muted">שאילתת חיפוש</label>
|
||||
<Input
|
||||
value={draft}
|
||||
onChange={(e) => setDraft(e.target.value)}
|
||||
placeholder="שיקול דעת הוועדה המחוזית בהקלה"
|
||||
dir="rtl"
|
||||
/>
|
||||
</div>
|
||||
<div className="min-w-[180px]">
|
||||
<label className="text-[0.78rem] text-ink-muted">תחום</label>
|
||||
<Select
|
||||
value={practiceArea || "_all"}
|
||||
onValueChange={(v) => setPracticeArea(v === "_all" ? "" : (v as PracticeArea))}
|
||||
>
|
||||
<SelectTrigger><SelectValue /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="_all">הכל</SelectItem>
|
||||
{PRACTICE_AREAS.map((a) => (
|
||||
<SelectItem key={a.value} value={a.value}>{a.label}</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<Button type="submit" className="bg-navy text-parchment hover:bg-navy-soft">
|
||||
<Search className="w-4 h-4 me-1" />
|
||||
חפש
|
||||
</Button>
|
||||
</form>
|
||||
|
||||
<p className="text-[0.78rem] text-ink-muted">
|
||||
חיפוש סמנטי ב-radar היומונים. כל תוצאה מצביעה על פסק דין מקורי —
|
||||
הצטט מהפסק עצמו (ספריית הפסיקה), לא מהיומון.
|
||||
</p>
|
||||
|
||||
{!query.trim() ? (
|
||||
<div className="text-center text-ink-muted py-12">
|
||||
הקלד שאילתא כדי לחפש ביומונים. החיפוש סמנטי — לא טקסטואלי.
|
||||
</div>
|
||||
) : error ? (
|
||||
<div className="rounded bg-danger-bg border border-danger/40 px-6 py-5 text-danger text-center">
|
||||
{error.message}
|
||||
</div>
|
||||
) : isFetching ? (
|
||||
<div className="space-y-3">
|
||||
{[...Array(3)].map((_, i) => <Skeleton key={i} className="h-32 w-full" />)}
|
||||
</div>
|
||||
) : !data?.items.length ? (
|
||||
<div className="text-center text-ink-muted py-12">
|
||||
לא נמצאו יומונים תואמים. נסה ניסוח אחר.
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-3">
|
||||
<p className="text-[0.78rem] text-ink-muted">{data.count} תוצאות</p>
|
||||
{data.items.map((hit) => (
|
||||
<DigestCard key={hit.id} digest={hit} score={hit.score} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
152
web-ui/src/components/digests/digest-upload-dialog.tsx
Normal file
152
web-ui/src/components/digests/digest-upload-dialog.tsx
Normal file
@@ -0,0 +1,152 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { Upload } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import {
|
||||
Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader,
|
||||
DialogTitle, DialogTrigger,
|
||||
} from "@/components/ui/dialog";
|
||||
import {
|
||||
Select, SelectContent, SelectItem, SelectTrigger, SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import { useUploadDigest, type DigestUploadInput } from "@/lib/api/digests";
|
||||
import type { PracticeArea } from "@/lib/api/precedent-library";
|
||||
import { PRACTICE_AREAS } from "@/components/precedents/practice-area";
|
||||
|
||||
/**
|
||||
* Upload a "כל יום" digest PDF. The endpoint is container-safe: it only
|
||||
* stages + extracts text, creating a row with status='pending'. The LLM
|
||||
* enrichment (concept/headline/citation + embedding + autolink) runs locally
|
||||
* via the MCP drainer ``digest_process_pending`` — so the toast tells the
|
||||
* user the digest is queued, not yet searchable.
|
||||
*/
|
||||
export function DigestUploadDialog() {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [file, setFile] = useState<File | null>(null);
|
||||
const [yomonNumber, setYomonNumber] = useState("");
|
||||
const [digestDate, setDigestDate] = useState("");
|
||||
const [practiceArea, setPracticeArea] = useState<PracticeArea>("");
|
||||
const upload = useUploadDigest();
|
||||
|
||||
const reset = () => {
|
||||
setFile(null);
|
||||
setYomonNumber("");
|
||||
setDigestDate("");
|
||||
setPracticeArea("");
|
||||
};
|
||||
|
||||
const onSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (!file) {
|
||||
toast.error("בחר קובץ יומון (PDF)");
|
||||
return;
|
||||
}
|
||||
const input: DigestUploadInput = { file };
|
||||
if (yomonNumber.trim()) input.yomon_number = yomonNumber.trim();
|
||||
if (digestDate) input.digest_date = digestDate;
|
||||
if (practiceArea) input.practice_area = practiceArea;
|
||||
upload.mutate(input, {
|
||||
onSuccess: (res) => {
|
||||
if (res.status === "exists") {
|
||||
toast.info("יומון זהה כבר קיים — לא נוצר כפל");
|
||||
} else {
|
||||
toast.success(
|
||||
"היומון נקלט וממתין לעיבוד מקומי (LLM). הרץ digest_process_pending " +
|
||||
"או scripts/ingest_digests_batch.py כדי להשלים חילוץ + חיפוש.",
|
||||
);
|
||||
}
|
||||
reset();
|
||||
setOpen(false);
|
||||
},
|
||||
onError: (err) => {
|
||||
toast.error(`שגיאה בהעלאה: ${err.message}`);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogTrigger asChild>
|
||||
<Button className="bg-navy text-parchment hover:bg-navy-soft">
|
||||
<Upload className="w-4 h-4 me-1" />
|
||||
העלאת יומון
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent dir="rtl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>העלאת יומון "כל יום"</DialogTitle>
|
||||
<DialogDescription>
|
||||
סיכום-עמוד של פסק דין. המערכת תחלץ אוטומטית את תג-המושג, ההלכה, ומראה-המקום
|
||||
של הפסק המקורי. היומון משמש כ-radar בלבד — אינו מצוטט בהחלטה.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<form onSubmit={onSubmit} className="space-y-4">
|
||||
<div>
|
||||
<Label htmlFor="digest-file">קובץ יומון (PDF)</Label>
|
||||
<Input
|
||||
id="digest-file"
|
||||
type="file"
|
||||
accept=".pdf,.docx,.doc,.rtf,.txt,.md"
|
||||
onChange={(e) => setFile(e.target.files?.[0] ?? null)}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div>
|
||||
<Label htmlFor="digest-num">מספר יומון (אופציונלי)</Label>
|
||||
<Input
|
||||
id="digest-num"
|
||||
value={yomonNumber}
|
||||
onChange={(e) => setYomonNumber(e.target.value)}
|
||||
placeholder="5163"
|
||||
dir="ltr"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label htmlFor="digest-date">תאריך גיליון (אופציונלי)</Label>
|
||||
<Input
|
||||
id="digest-date"
|
||||
type="date"
|
||||
value={digestDate}
|
||||
onChange={(e) => setDigestDate(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<Label>תחום (אופציונלי — יחולץ אם ריק)</Label>
|
||||
<Select
|
||||
value={practiceArea || "_auto"}
|
||||
onValueChange={(v) => setPracticeArea(v === "_auto" ? "" : (v as PracticeArea))}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="_auto">חילוץ אוטומטי</SelectItem>
|
||||
{PRACTICE_AREAS.map((a) => (
|
||||
<SelectItem key={a.value} value={a.value}>
|
||||
{a.label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<DialogFooter>
|
||||
<Button
|
||||
type="submit"
|
||||
disabled={upload.isPending}
|
||||
className="bg-navy text-parchment hover:bg-navy-soft"
|
||||
>
|
||||
{upload.isPending ? "מעלה…" : "העלה"}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user