feat(documents): add Recently deleted for deleted documents

Deleting a document only stamps a tombstone and the purge removes it
after 30 days, but the only way back was the undo toast, gone a few
seconds after the delete. Recently deleted lists the deleted documents
of the record with type, filing date, where an import came from, when
each was deleted and how long it has left, and offers Restore, Restore
all and Delete now.

GET /api/documents/inbound/deleted lists them (owner-only, capped at 200
with the list-cap meta). POST /api/documents/inbound/{id}/purge removes
one deleted document for good through the same function the nightly
purge runs, so its import keys and aliases still move into the ledger
and an importer re-sending it is still answered "deleted"; a live
document answers 409 documents.inbound.notDeleted. The usage read gains
deletedCount, 0 under a grant. The restore route and bulk restore
share one restore, which now also clears ledger entries for the
document's own keys.

The vault header shows a quiet "Recently deleted (n)" link only while
something is in it, and the delete toasts and confirmations say that
deleted documents stay there for 30 days. The purge's queue facts and
grace window move to document-purge-queue.ts so the worker registry
still loads none of the work.

Refs #1275
This commit is contained in:
Marc-André Bombeck committed 2026-10-24 20:51:35 +02:00
1 parent 1ea14e9100
commit 4752115d7d
44 files changed
+2277 -270

No files matched your search

+3
View File
@@ -50,6 +50,9 @@ export const DOCUMENT_LIST_DEFAULT_LIMIT = 50;
/** Max document ids one bulk request may touch. */
export const DOCUMENT_BULK_MAX_IDS = 100;
/** Days a deleted document stays in Recently deleted (see the purge queue). */
export { DOCUMENT_PURGE_GRACE_DAYS } from "@/lib/jobs/document-purge-queue";
/** Max documents attachable to one coach conversation. Bounds prompt size + the
* numeric-grounding union; five labelled documents is already past the point a
* chat answer stays useful. */
+226
View File
@@ -0,0 +1,226 @@
/**
* The two ways out of a deleted (tombstoned) vault document: back into the
* vault, or out of the database for good.
*
* Delete in the vault only stamps `deletedAt`. From there a document is either
* restored (the undo toast, Recently deleted, the bulk bar, the document
* picker) or purged (the daily job once the grace window has passed, or the
* person choosing "Delete now" in Recently deleted). Every one of those callers
* goes through this module, so a restore and a purge mean the same thing
* whoever asks:
*
* - a purge copies the document's import source keys (its own and every
* alias) into `DocumentImportKey` in the same transaction as the delete,
* so an importer re-sending the document is still answered "deleted" once
* the row is gone;
* - a restore removes any `DocumentImportKey` entry for those same keys in
* the same transaction as clearing the tombstone. The ledger says "the
* person deleted this"; once the document is back, that is no longer true,
* and a ledger entry left behind would outlive the document's next delete
* and restore with nothing to explain it.
*/
import type { InboundDocumentStatus, Prisma } from "@/generated/prisma/client";
import { prisma } from "@/lib/db";
import { DOCUMENT_PURGE_GRACE_DAYS } from "@/lib/documents/inbound-constants";
import { isP2002 } from "@/lib/prisma-errors";
const DAY_MS = 86_400_000;
/** The moment a document deleted at `deletedAt` becomes due for the purge. */
export function documentPurgeAt(deletedAt: Date): Date {
return new Date(deletedAt.getTime() + DOCUMENT_PURGE_GRACE_DAYS * DAY_MS);
}
interface ImportSourceKey {
userId: string;
sourceSystem: string;
sourceId: string;
sourceInstance: string | null;
}
/** The columns a row needs for {@link importKeysOf}. */
const SOURCE_KEY_SELECT = {
userId: true,
sourceSystem: true,
sourceId: true,
sourceInstance: true,
sourceAliases: {
select: { sourceSystem: true, sourceId: true, sourceInstance: true },
},
} as const;
interface KeyedRow {
userId: string;
sourceSystem: string | null;
sourceId: string | null;
sourceInstance: string | null;
sourceAliases: Array<{
sourceSystem: string;
sourceId: string;
sourceInstance: string | null;
}>;
}
/** Every import source key a document holds: its own, then its aliases. */
function importKeysOf(row: KeyedRow): ImportSourceKey[] {
return [
...(row.sourceSystem && row.sourceId
? [
{
userId: row.userId,
sourceSystem: row.sourceSystem,
sourceId: row.sourceId,
sourceInstance: row.sourceInstance,
},
]
: []),
...row.sourceAliases.map((alias) => ({
userId: row.userId,
sourceSystem: alias.sourceSystem,
sourceId: alias.sourceId,
sourceInstance: alias.sourceInstance,
})),
];
}
/**
* Hard-delete the tombstones `where` selects, carrying their import source
* keys into the ledger first. Only rows with `deletedAt` set are ever touched,
* whatever `where` says. Runs inside the caller's transaction, so a purge that
* fails halfway forgets nothing. Returns the number of rows removed.
*/
export async function purgeDocumentTombstones(
tx: Prisma.TransactionClient,
where: Prisma.InboundDocumentWhereInput,
): Promise<number> {
const tombstones: Prisma.InboundDocumentWhereInput = {
AND: [where, { deletedAt: { not: null } }],
};
const keyed = await tx.inboundDocument.findMany({
where: {
AND: [
tombstones,
{
OR: [
{ sourceSystem: { not: null }, sourceId: { not: null } },
{ sourceAliases: { some: {} } },
],
},
],
},
select: SOURCE_KEY_SELECT,
});
const keys = keyed.flatMap(importKeysOf);
if (keys.length > 0) {
await tx.documentImportKey.createMany({ data: keys, skipDuplicates: true });
}
const { count } = await tx.inboundDocument.deleteMany({ where: tombstones });
return count;
}
/**
* Purge one of the person's deleted documents now, ahead of the grace window.
* Returns false when there was no such tombstone (never existed, someone
* else's, still live, or already gone).
*/
export async function purgeDocumentTombstoneNow(
userId: string,
id: string,
): Promise<boolean> {
const count = await prisma.$transaction((tx) =>
purgeDocumentTombstones(tx, { id, userId }),
);
return count > 0;
}
export type TombstoneRestoreResult =
/** The tombstone was cleared. */
| { kind: "restored" }
/** The document was live already; restoring twice changes nothing. */
| { kind: "live" }
/** No such document for this person: purged, or never existed. */
| { kind: "gone" }
/** A live document with the same bytes holds the slot (null on a race). */
| { kind: "duplicate"; existingId: string | null };
/**
* Lifecycle status after a restore, derived from the staged facts: none →
* STORED, any PENDING → EXTRACTED, otherwise every fact was acted on →
* CONFIRMED. (Delete stamped DISCARDED; the status before it is not kept.)
*/
function restoredStatus(
facts: Array<{ status: string }>,
): InboundDocumentStatus {
if (facts.length === 0) return "STORED";
return facts.some((f) => f.status === "PENDING") ? "EXTRACTED" : "CONFIRMED";
}
/**
* Bring one of the person's deleted documents back into the vault, and forget
* any ledger entry that says its import keys were deleted. Owner-scoped: a
* foreign id is `gone`, exactly like a purged one.
*/
export async function restoreDocumentTombstone(
userId: string,
id: string,
): Promise<TombstoneRestoreResult> {
const row = await prisma.inboundDocument.findFirst({
where: { id, userId },
select: { id: true, deletedAt: true, contentSha256: true },
});
if (!row) return { kind: "gone" };
if (row.deletedAt === null) return { kind: "live" };
// A live duplicate of the same bytes blocks the restore (the partial unique
// index would reject it; checked first for a clean answer).
if (row.contentSha256) {
const conflict = await prisma.inboundDocument.findFirst({
where: {
userId,
contentSha256: row.contentSha256,
deletedAt: null,
id: { not: id },
},
select: { id: true },
});
if (conflict) return { kind: "duplicate", existingId: conflict.id };
}
const facts = await prisma.extractedFact.findMany({
where: { documentId: id, userId },
select: { status: true },
});
let restored: boolean;
try {
restored = await prisma.$transaction(async (tx) => {
// Guarded on the tombstone, so a purge or a restore that won the race
// is not undone or repeated here.
const { count } = await tx.inboundDocument.updateMany({
where: { id, userId, deletedAt: { not: null } },
data: { deletedAt: null, status: restoredStatus(facts) },
});
if (count === 0) return false;
const keyed = await tx.inboundDocument.findUniqueOrThrow({
where: { id },
select: SOURCE_KEY_SELECT,
});
const keys = importKeysOf(keyed);
if (keys.length > 0) {
await tx.documentImportKey.deleteMany({ where: { OR: keys } });
}
return true;
});
} catch (err) {
// Raced a concurrent identical upload into the partial unique index.
if (isP2002(err)) return { kind: "duplicate", existingId: null };
throw err;
}
if (restored) return { kind: "restored" };
const now = await prisma.inboundDocument.findFirst({
where: { id, userId },
select: { deletedAt: true },
});
return now && now.deletedAt === null ? { kind: "live" } : { kind: "gone" };
}
+94
View File
@@ -0,0 +1,94 @@
/**
* The payloads of the vault's side reads: the usage and limits the upload path
* pre-flights against (`GET /api/documents/inbound/usage`), and Recently
* deleted (`GET /api/documents/inbound/deleted`, `POST …/{id}/purge`).
* Re-exported from `@/lib/validations/inbound-documents`, where the other
* vault DTOs live. Types only.
*/
import type {
DocumentConditionLinkDto,
DocumentLinkedProcedureDto,
DocumentSourceSystemValue,
InboundDocumentKindValue,
} from "@/lib/validations/inbound-documents";
/** The usage endpoint payload the UI reads before offering an upload. */
export interface DocumentUsageDto {
usedBytes: number;
quotaBytes: number;
maxFileBytes: number;
acceptedExtensions: string[];
/**
* Episodes carrying at least one LIVE document link — the vault filter
* bar's condition chips. Sourced server-side so a chip exists even when
* every linked document sits pages deep in the timeline.
*/
linkedEpisodes: DocumentConditionLinkDto[];
/**
* Procedures and surgeries (visits of kind PROCEDURE) carrying at least one
* LIVE document link — the filter bar's procedure choices, sourced
* server-side for the same reason as `linkedEpisodes`. Empty when the
* caller's grant does not cover the visits section, because the label is
* the visit's own text.
*/
linkedProcedures: DocumentLinkedProcedureDto[];
/**
* Whether the AI "Suggest details" action can run for this caller — true when
* a provider (vision, or text + local OCR) is configured. The UI hides the
* action when false so it never offers what the endpoint would 422.
*/
assistAvailable: boolean;
/**
* Content-search index state: whether indexing is available to the caller
* (`enabled`, same provider precondition as assist), how many live documents
* are indexed, and the live-document total — so the UI can gauge coverage and
* offer the "index all documents" backfill.
*/
contentIndex: {
enabled: boolean;
indexedCount: number;
totalCount: number;
};
/**
* How many of the person's documents sit in Recently deleted (deleted, not
* yet purged). The vault shows its way into Recently deleted only when this
* is above zero. Always 0 while acting inside somebody else's record, where
* Recently deleted is not offered.
*/
deletedCount: number;
}
/** One document in Recently deleted (`GET /api/documents/inbound/deleted`). */
export interface DeletedDocumentDto {
id: string;
kind: InboundDocumentKindValue;
title: string | null;
filename: string | null;
mimeType: string;
byteSize: number;
/** User-set filing date (YYYY-MM-DD), or null. */
documentDate: string | null;
/** The system an imported document came from, or null. */
sourceSystem: DocumentSourceSystemValue | null;
/** When it was deleted (ISO 8601). */
deletedAt: string;
/**
* When the daily purge becomes due for it (ISO 8601): `deletedAt` plus the
* grace window. The purge runs once a day, so the row goes at the first run
* after this instant.
*/
purgeAt: string;
}
/** The Recently deleted list, newest deletion first. */
export interface DeletedDocumentListDto {
documents: DeletedDocumentDto[];
/** Days a deleted document stays restorable. */
graceDays: number;
}
/** Answer of `POST /api/documents/inbound/{id}/purge`. */
export interface DocumentPurgeDto {
id: string;
purged: true;
}
+17
View File
@@ -0,0 +1,17 @@
/**
* The queue facts of `document-purge.ts`: its name, its schedule and the grace
* window it enforces. They live apart from the handler so the worker registry
* can read them without loading the purge (and the document modules it shares
* with "Delete now"). Constants only: client code reads the grace window
* through `@/lib/documents/inbound-constants`.
*/
export const DOCUMENT_PURGE_QUEUE = "document-tombstone-purge";
/** Daily at 04:10 Europe/Berlin — after the med-notes backfill tick (04:05). */
export const DOCUMENT_PURGE_CRON = "10 4 * * *";
/**
* Days a deleted document stays in Recently deleted (restorable) before the
* daily purge removes it for good. The purge, the list of deleted documents
* and the copy that names the window all read this one value.
*/
export const DOCUMENT_PURGE_GRACE_DAYS = 30;
+16 -61
View File
@@ -8,20 +8,21 @@
* tombstoned document keeps counting against the quota until purged, so
* "deleted" bytes are never invisible backup weight). Staged facts cascade
* via the FK. Restore-after-purge answers 409 at the API. An imported
* document's source key is carried to `DocumentImportKey` on the way out.
* document's source key is carried to `DocumentImportKey` on the way out
* (`src/lib/documents/tombstones.ts`, shared with "Delete now").
*/
import { type Job } from "pg-boss";
import { DOCUMENT_PURGE_GRACE_DAYS } from "@/lib/jobs/document-purge-queue";
import { purgeDocumentTombstones } from "@/lib/documents/tombstones";
import { withBackgroundEvent } from "@/lib/logging/background";
import { jobDone, jobFailed, type JobOutcome } from "@/lib/jobs/job-outcome";
import { getWorkerPrisma } from "@/lib/jobs/reminder/shared";
import type { PrismaClient } from "@/generated/prisma/client";
export const DOCUMENT_PURGE_QUEUE = "document-tombstone-purge";
/** Daily at 04:10 Europe/Berlin — after the med-notes backfill tick (04:05). */
export const DOCUMENT_PURGE_CRON = "10 4 * * *";
/** Days a tombstoned document stays restorable before the purge claims it. */
export const DOCUMENT_PURGE_GRACE_DAYS = 30;
export {
DOCUMENT_PURGE_CRON,
DOCUMENT_PURGE_QUEUE,
} from "@/lib/jobs/document-purge-queue";
const DAY_MS = 86_400_000;
@@ -33,66 +34,20 @@ export interface DocumentPurgePayload {
* Hard-delete tombstoned `inbound_documents` rows whose `deletedAt` is older
* than the grace horizon. Returns the number of rows purged. Rows inside the
* grace window and live rows are never touched.
*
* v1.39.2 (#1038) — an imported document's source key outlives its row: the
* shared purge (`purgeDocumentTombstones`, the same one "Delete now" in
* Recently deleted runs) copies it into the ledger in the same transaction as
* the delete, so a re-run of the importer does not store the document again.
*/
export async function purgeExpiredDocumentTombstones(
prisma: PrismaClient,
now: Date = new Date(),
): Promise<number> {
const cutoff = new Date(now.getTime() - DOCUMENT_PURGE_GRACE_DAYS * DAY_MS);
const expired = { deletedAt: { not: null, lt: cutoff } };
return prisma.$transaction(async (tx) => {
// v1.39.2 (#1038) — an imported document's source key outlives its row.
// While the tombstone exists the key sits on it and the upload route
// answers "deleted"; once the row goes, this ledger is what keeps a re-run
// of the importer from storing the document again. Same transaction as the
// delete, so a purge that fails halfway forgets nothing.
const keyed = await tx.inboundDocument.findMany({
where: {
...expired,
OR: [
{ sourceSystem: { not: null }, sourceId: { not: null } },
{ sourceAliases: { some: {} } },
],
},
select: {
userId: true,
sourceSystem: true,
sourceId: true,
sourceInstance: true,
// Further keys the import answered with this document (same bytes).
// They cascade away with the row, so they are copied here first.
sourceAliases: {
select: { sourceSystem: true, sourceId: true, sourceInstance: true },
},
},
});
const keys = keyed.flatMap((row) => [
...(row.sourceSystem && row.sourceId
? [
{
userId: row.userId,
sourceSystem: row.sourceSystem,
sourceId: row.sourceId,
sourceInstance: row.sourceInstance,
},
]
: []),
...row.sourceAliases.map((alias) => ({
userId: row.userId,
sourceSystem: alias.sourceSystem,
sourceId: alias.sourceId,
sourceInstance: alias.sourceInstance,
})),
]);
if (keys.length > 0) {
await tx.documentImportKey.createMany({
data: keys,
skipDuplicates: true,
});
}
const { count } = await tx.inboundDocument.deleteMany({ where: expired });
return count;
});
return prisma.$transaction((tx) =>
purgeDocumentTombstones(tx, { deletedAt: { lt: cutoff } }),
);
}
export async function handleDocumentPurge(
+1 -1
View File
@@ -70,7 +70,7 @@ import {
import {
DOCUMENT_PURGE_CRON,
DOCUMENT_PURGE_QUEUE,
} from "@/lib/jobs/document-purge";
} from "@/lib/jobs/document-purge-queue";
import {
DOCUMENT_SUMMARY_CATCHUP_CONCURRENCY,
DOCUMENT_SUMMARY_CATCHUP_QUEUE,
+1 -1
View File
@@ -36,7 +36,7 @@
import type { PrismaClient } from "@/generated/prisma/client";
import { TOMBSTONE_RETENTION_DAYS } from "@/lib/auth/native-client";
import { getCoachMessageRetentionDays } from "@/lib/jobs/coach-message-cleanup";
import { DOCUMENT_PURGE_GRACE_DAYS } from "@/lib/jobs/document-purge";
import { DOCUMENT_PURGE_GRACE_DAYS } from "@/lib/jobs/document-purge-queue";
import {
purgeTombstonesByAccount,
type TombstonePurgeOutcome,
+1
View File
@@ -161,6 +161,7 @@ export const ERROR_CODE_CATALOGUE: Readonly<Record<string, readonly string[]>> =
"documents.inbound.invalidQuery",
"documents.inbound.invalidUpdate",
"documents.inbound.localOcrDisabled",
"documents.inbound.notDeleted",
"documents.inbound.notFound",
"documents.inbound.notIndexed",
"documents.inbound.outputLimit",
+105 -1
View File
@@ -44,6 +44,7 @@ import {
errorEnvelope,
idempotencyKeyParameter,
idempotentWrite,
listEnvelope,
recordRefusal,
stdResponses,
} from "./shared";
@@ -462,6 +463,47 @@ export const documentIndexResponse = z
})
.meta({ id: "DocumentIndexResponse" });
// ─── Recently deleted ──────────────────────────────────────────────────────
const deletedDocument = z
.object({
id: z.string(),
kind: kindEnum,
title: z.string().nullable(),
filename: z.string().nullable(),
mimeType: z.string(),
byteSize: z.number().int(),
documentDate: z
.string()
.nullable()
.describe("User-set filing date (YYYY-MM-DD), or null."),
sourceSystem: z
.enum(DOCUMENT_SOURCE_SYSTEMS)
.nullable()
.describe(
"The system an imported document came from, or null for one added in HealthLog.",
),
deletedAt: isoDateTime(),
purgeAt: isoDateTime().describe(
"When the daily purge becomes due for this document: `deletedAt` plus `graceDays`. The purge runs once a day, so the document is removed at the first run after this instant.",
),
})
.meta({ id: "DeletedDocument" });
const deletedDocumentList = z
.object({
documents: z.array(deletedDocument),
graceDays: z
.number()
.int()
.describe("Days a deleted document stays restorable."),
})
.meta({ id: "DeletedDocumentList" });
const documentPurgeResult = z
.object({ id: z.string(), purged: z.literal(true) })
.meta({ id: "DocumentPurgeResult" });
export const inboundDocumentPaths: NonNullable<ZodOpenApiObject["paths"]> = {
"/api/documents/inbound": {
get: {
@@ -837,6 +879,12 @@ export const inboundDocumentPaths: NonNullable<ZodOpenApiObject["paths"]> = {
indexedCount: z.number(),
totalCount: z.number(),
}),
deletedCount: z
.number()
.int()
.describe(
"How many of the caller's documents are deleted and not yet purged (Recently deleted, `GET /api/documents/inbound/deleted`). Always 0 while acting inside somebody else's record, where Recently deleted is not offered.",
),
})
.meta({ id: "DocumentUsage" }),
"DocumentUsageEnvelope",
@@ -1027,7 +1075,7 @@ export const inboundDocumentPaths: NonNullable<ZodOpenApiObject["paths"]> = {
tags: ["Documents"],
summary: "Restore a discarded document",
description:
'Clears the soft-delete tombstone within the 30-day undo grace. 409 when the tombstone is already purged (the undo window is over) or when an identical live document blocks the restore (`meta.reason = "duplicateExists"`). Restoring an already-live document is a no-op success.',
'Clears the soft-delete tombstone within the 30-day undo grace, and forgets any import-ledger entry for the document\'s source keys. 409 when the tombstone is already purged (the undo window is over, or the document was deleted for good) or when an identical live document blocks the restore (`meta.reason = "duplicateExists"`). Restoring an already-live document is a no-op success.',
parameters: [
{
name: "id",
@@ -1057,6 +1105,62 @@ export const inboundDocumentPaths: NonNullable<ZodOpenApiObject["paths"]> = {
},
},
},
"/api/documents/inbound/deleted": {
get: {
tags: ["Documents"],
summary: "List Recently deleted",
description:
"The caller's deleted documents that the purge has not removed yet, newest deletion first, metadata only. Each carries `purgeAt`, when the daily purge becomes due for it. Restore one with `POST /api/documents/inbound/{id}/restore` (or the bulk `restore` action); remove one for good ahead of time with `POST /api/documents/inbound/{id}/purge`. Capped at 200 rows (`meta.truncated`, `meta.limit`). Owner-only: refused while acting inside somebody else's record.",
responses: {
"200": {
description: "Recently deleted.",
content: {
"application/json": {
schema: listEnvelope(
deletedDocumentList,
"DeletedDocumentListEnvelope",
),
},
},
},
...stdResponses,
},
},
},
"/api/documents/inbound/{id}/purge": {
post: {
tags: ["Documents"],
summary: "Delete a deleted document for good",
description:
"Removes one deleted document now instead of when the grace window ends, through the same purge the daily job runs: the row and everything that cascades from it go, and an imported document's source keys are kept in the import ledger, so an importer re-sending it is still answered as deleted. Only a deleted document can be purged: a live one answers 409 `documents.inbound.notDeleted`. 404 `documents.inbound.notFound` when the caller has no such document. Owner-only.",
parameters: [
{
name: "id",
in: "path",
required: true,
schema: { type: "string" },
},
],
responses: {
"200": {
description: "Removed for good.",
content: {
"application/json": {
schema: dataEnvelope(
documentPurgeResult,
"DocumentPurgeResultEnvelope",
),
},
},
},
"409": {
description: "The document is not deleted.",
content: { "application/json": { schema: errorEnvelope } },
},
...stdResponses,
},
},
},
"/api/documents/inbound/{id}/original": {
get: {
tags: ["Documents"],
+6
View File
@@ -85,6 +85,12 @@ export const documentKeys = {
* delete so the quota bar tracks reality.
*/
inboundDocumentUsage: () => ["documents", "inbound", "usage"] as const,
/**
* Recently deleted (`GET /api/documents/inbound/deleted`). Under the
* `["documents"]` prefix on purpose: a delete, a restore or a purge anywhere
* in the vault repaints it. The literal segment never collides with a cuid.
*/
inboundDocumentsDeleted: () => ["documents", "inbound", "deleted"] as const,
/**
* Document-scoped AI capability probe
* (`GET /api/documents/inbound/capability`). Distinct from the labs
+8 -38
View File
@@ -878,44 +878,14 @@ export interface DocumentBulkResultDto {
error: string | null;
}
/** The usage endpoint payload the UI reads before offering an upload. */
export interface DocumentUsageDto {
usedBytes: number;
quotaBytes: number;
maxFileBytes: number;
acceptedExtensions: string[];
/**
* Episodes carrying at least one LIVE document link — the vault filter
* bar's condition chips. Sourced server-side so a chip exists even when
* every linked document sits pages deep in the timeline.
*/
linkedEpisodes: DocumentConditionLinkDto[];
/**
* Procedures and surgeries (visits of kind PROCEDURE) carrying at least one
* LIVE document link — the filter bar's procedure choices, sourced
* server-side for the same reason as `linkedEpisodes`. Empty when the
* caller's grant does not cover the visits section, because the label is
* the visit's own text.
*/
linkedProcedures: DocumentLinkedProcedureDto[];
/**
* Whether the AI "Suggest details" action can run for this caller — true when
* a provider (vision, or text + local OCR) is configured. The UI hides the
* action when false so it never offers what the endpoint would 422.
*/
assistAvailable: boolean;
/**
* Content-search index state: whether indexing is available to the caller
* (`enabled`, same provider precondition as assist), how many live documents
* are indexed, and the live-document total — so the UI can gauge coverage and
* offer the "index all documents" backfill.
*/
contentIndex: {
enabled: boolean;
indexedCount: number;
totalCount: number;
};
}
// The usage and Recently deleted payloads live in their own module; kept
// importable from here like every other vault DTO.
export type {
DeletedDocumentDto,
DeletedDocumentListDto,
DocumentPurgeDto,
DocumentUsageDto,
} from "@/lib/documents/vault-read-dtos";
/** Where a document read egresses, vendor-blind. */
export type DocumentEgressClass = "local" | "external";