All checks were successful
Build & Deploy / build-and-deploy (push) Successful in 6s
The "על כן" pattern for block-yod-bet was too greedy and matched mid-discussion
transitional sentences (e.g. "על כן, במקום בו..."), which caused forward-scan
to skip block-yod-alef ("סוף דבר") via the pointer advance.
Tightened to require an operative subject (אנו / הערר / הוועדה / ועדת הערר)
so terminal "על כן, אנו מחליטים" still matches but mid-block transitions don't.
Added structural_fallback for cover blocks (alef/bet/gimel/dalet) — these are
template metadata not present in user-edited DOCX bodies. Inject zero-content
anchors so apply_user_edit can still target them later. The frontend toast
distinguishes real content gaps from fallback anchors.
Also expanded heading patterns based on training corpus inspection:
- block-vav: על המקרקעין חלות / במצב התכנוני / התכניות החלות
- block-zayin: טענות העוררת
- block-chet: עיקר תגובת המשיב
- block-tet: הדיון בוועדת הערר
For case 1130-25, this raises detection from 6/12 to 11/12 blocks — only
block-yod-bet remains missing (Daphna's edit ends at "סוף דבר" + numbered
ruling, no terminal "ההחלטה" or "על כן אנו מחליטים" paragraph).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
198 lines
5.7 KiB
TypeScript
198 lines
5.7 KiB
TypeScript
/**
|
|
* Exports domain hooks — draft DOCX files for a case.
|
|
*/
|
|
|
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
import { apiRequest } from "./client";
|
|
import { casesKeys } from "./cases";
|
|
|
|
export type ExportFile = {
|
|
filename: string;
|
|
size: number;
|
|
created_at: number;
|
|
is_final: boolean;
|
|
};
|
|
|
|
export type ActiveDraft = {
|
|
active_draft_path: string | null;
|
|
filename: string | null;
|
|
exists: boolean;
|
|
};
|
|
|
|
export type Revision = {
|
|
id: string;
|
|
type: "insert_after" | "insert_before" | "replace" | "delete";
|
|
anchor_bookmark: string;
|
|
content?: string;
|
|
style?: "body" | "heading" | "quote" | "bold";
|
|
reason?: string;
|
|
};
|
|
|
|
export type UploadResult = {
|
|
filename: string;
|
|
size: number;
|
|
version: number;
|
|
active_draft?: string;
|
|
bookmarks_added?: string[];
|
|
missing_blocks?: string[];
|
|
structural_fallback?: string[];
|
|
apply_status?: string;
|
|
};
|
|
|
|
export type ReviseResult = {
|
|
status: string;
|
|
output_path: string;
|
|
version: number;
|
|
applied: number;
|
|
failed: number;
|
|
results: { id: string; status: string; error?: string }[];
|
|
};
|
|
|
|
export const exportsKeys = {
|
|
all: ["exports"] as const,
|
|
list: (caseNumber: string) =>
|
|
[...exportsKeys.all, "list", caseNumber] as const,
|
|
activeDraft: (caseNumber: string) =>
|
|
[...exportsKeys.all, "active-draft", caseNumber] as const,
|
|
bookmarks: (caseNumber: string) =>
|
|
[...exportsKeys.all, "bookmarks", caseNumber] as const,
|
|
};
|
|
|
|
export function useExports(caseNumber: string | undefined) {
|
|
return useQuery({
|
|
queryKey: exportsKeys.list(caseNumber ?? ""),
|
|
queryFn: ({ signal }) =>
|
|
apiRequest<ExportFile[]>(`/api/cases/${caseNumber}/exports`, { signal }),
|
|
enabled: Boolean(caseNumber),
|
|
staleTime: 5_000,
|
|
refetchInterval: 5_000,
|
|
});
|
|
}
|
|
|
|
export function useExportDocx(caseNumber: string) {
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: () =>
|
|
apiRequest<{ status: string; path: string; message: string }>(
|
|
`/api/cases/${caseNumber}/export-docx`,
|
|
{ method: "POST" },
|
|
),
|
|
onSuccess: () => {
|
|
qc.invalidateQueries({ queryKey: exportsKeys.list(caseNumber) });
|
|
qc.invalidateQueries({ queryKey: casesKeys.detail(caseNumber) });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useUploadDraft(caseNumber: string) {
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: async (file: File): Promise<UploadResult> => {
|
|
const form = new FormData();
|
|
form.append("file", file);
|
|
const res = await fetch(`/api/cases/${caseNumber}/exports/upload`, {
|
|
method: "POST",
|
|
body: form,
|
|
});
|
|
if (!res.ok) {
|
|
const err = await res.json().catch(() => ({ detail: "שגיאה בהעלאה" }));
|
|
throw new Error(err.detail ?? "שגיאה בהעלאה");
|
|
}
|
|
return res.json() as Promise<UploadResult>;
|
|
},
|
|
onSuccess: () => {
|
|
qc.invalidateQueries({ queryKey: exportsKeys.list(caseNumber) });
|
|
qc.invalidateQueries({ queryKey: exportsKeys.activeDraft(caseNumber) });
|
|
qc.invalidateQueries({ queryKey: exportsKeys.bookmarks(caseNumber) });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useActiveDraft(caseNumber: string | undefined) {
|
|
return useQuery({
|
|
queryKey: exportsKeys.activeDraft(caseNumber ?? ""),
|
|
queryFn: ({ signal }) =>
|
|
apiRequest<ActiveDraft>(`/api/cases/${caseNumber}/active-draft`, { signal }),
|
|
enabled: Boolean(caseNumber),
|
|
staleTime: 5_000,
|
|
});
|
|
}
|
|
|
|
export function useBookmarks(caseNumber: string | undefined) {
|
|
return useQuery({
|
|
queryKey: exportsKeys.bookmarks(caseNumber ?? ""),
|
|
queryFn: ({ signal }) =>
|
|
apiRequest<{
|
|
status: string;
|
|
active_draft_path?: string;
|
|
bookmarks?: string[];
|
|
}>(`/api/cases/${caseNumber}/exports/bookmarks`, { signal }),
|
|
enabled: Boolean(caseNumber),
|
|
staleTime: 10_000,
|
|
});
|
|
}
|
|
|
|
export function useReviseDraft(caseNumber: string) {
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: (payload: { revisions: Revision[]; author?: string }) =>
|
|
apiRequest<ReviseResult>(`/api/cases/${caseNumber}/exports/revise`, {
|
|
method: "POST",
|
|
body: payload,
|
|
}),
|
|
onSuccess: () => {
|
|
qc.invalidateQueries({ queryKey: exportsKeys.list(caseNumber) });
|
|
qc.invalidateQueries({ queryKey: exportsKeys.activeDraft(caseNumber) });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useRetrofit(caseNumber: string) {
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: (filename: string) =>
|
|
apiRequest<{
|
|
status: string;
|
|
active_draft_path: string;
|
|
bookmarks_added: string[];
|
|
missing_blocks: string[];
|
|
structural_fallback?: string[];
|
|
}>(`/api/cases/${caseNumber}/exports/${filename}/retrofit`, {
|
|
method: "POST",
|
|
}),
|
|
onSuccess: () => {
|
|
qc.invalidateQueries({ queryKey: exportsKeys.activeDraft(caseNumber) });
|
|
qc.invalidateQueries({ queryKey: exportsKeys.bookmarks(caseNumber) });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useDeleteDraft(caseNumber: string) {
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: (filename: string) =>
|
|
apiRequest<{ deleted: boolean; filename: string }>(
|
|
`/api/cases/${caseNumber}/exports/${filename}`,
|
|
{ method: "DELETE" },
|
|
),
|
|
onSuccess: () => {
|
|
qc.invalidateQueries({ queryKey: exportsKeys.list(caseNumber) });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useMarkFinal(caseNumber: string) {
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: (filename: string) =>
|
|
apiRequest<{ final_filename: string; status: string }>(
|
|
`/api/cases/${caseNumber}/exports/${filename}/mark-final`,
|
|
{ method: "POST" },
|
|
),
|
|
onSuccess: () => {
|
|
qc.invalidateQueries({ queryKey: exportsKeys.list(caseNumber) });
|
|
qc.invalidateQueries({ queryKey: casesKeys.detail(caseNumber) });
|
|
},
|
|
});
|
|
}
|