Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f2b8c7d111 |
@@ -5,6 +5,16 @@ All notable changes to Library Desk will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [1.4.6] - 2025-12-25
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- **Paperless Webhook Payload Format** - Updated model to match Paperless `include_document=true` format
|
||||||
|
- Paperless sends `id` instead of `document_id`
|
||||||
|
- Paperless sends full document data including `content`, `title`, `tags`, etc.
|
||||||
|
- Webhook now uses content from payload, skipping extra Paperless API call
|
||||||
|
- Added `extra = "ignore"` to handle additional Paperless fields
|
||||||
|
|
||||||
## [1.4.5] - 2025-12-25
|
## [1.4.5] - 2025-12-25
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "library-desk"
|
name = "library-desk"
|
||||||
version = "1.4.5"
|
version = "1.4.6"
|
||||||
description = "Coordination service for The Library system - HybridRAG queries, document ingestion, entity extraction, and knowledge consolidation"
|
description = "Coordination service for The Library system - HybridRAG queries, document ingestion, entity extraction, and knowledge consolidation"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.12"
|
requires-python = ">=3.12"
|
||||||
|
|||||||
+12
-3
@@ -86,13 +86,22 @@ class DocumentUploadResponse(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class PaperlessWebhookPayload(BaseModel):
|
class PaperlessWebhookPayload(BaseModel):
|
||||||
"""Payload from Paperless-ngx webhook."""
|
"""Payload from Paperless-ngx webhook (include_document=true format)."""
|
||||||
document_id: int = Field(..., description="Paperless document ID")
|
id: int = Field(..., description="Paperless document ID")
|
||||||
event: str = Field(..., description="Event type (document_added, document_updated)")
|
|
||||||
title: Optional[str] = Field(None, description="Document title")
|
title: Optional[str] = Field(None, description="Document title")
|
||||||
|
content: Optional[str] = Field(None, description="Document text content")
|
||||||
correspondent: Optional[int] = Field(None, description="Correspondent ID")
|
correspondent: Optional[int] = Field(None, description="Correspondent ID")
|
||||||
document_type: Optional[int] = Field(None, description="Document type ID")
|
document_type: Optional[int] = Field(None, description="Document type ID")
|
||||||
tags: List[int] = Field(default_factory=list, description="Tag IDs")
|
tags: List[int] = Field(default_factory=list, description="Tag IDs")
|
||||||
|
created: Optional[str] = Field(None, description="Created date")
|
||||||
|
modified: Optional[str] = Field(None, description="Modified datetime")
|
||||||
|
added: Optional[str] = Field(None, description="Added datetime")
|
||||||
|
original_file_name: Optional[str] = Field(None, description="Original filename")
|
||||||
|
owner: Optional[int] = Field(None, description="Owner user ID")
|
||||||
|
custom_fields: List[Dict[str, Any]] = Field(default_factory=list, description="Custom fields")
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
extra = "ignore" # Ignore extra fields from Paperless
|
||||||
|
|
||||||
|
|
||||||
class WebhookResponse(BaseModel):
|
class WebhookResponse(BaseModel):
|
||||||
|
|||||||
@@ -64,12 +64,12 @@ async def receive_webhook(
|
|||||||
"""
|
"""
|
||||||
from src.services.document_sync_service import DocumentSyncService
|
from src.services.document_sync_service import DocumentSyncService
|
||||||
|
|
||||||
logger.info(f"Webhook received: document_id={payload.document_id}, event={payload.event}")
|
logger.info(f"Webhook received: document_id={payload.id}, title={payload.title}")
|
||||||
|
|
||||||
settings = get_settings()
|
settings = get_settings()
|
||||||
if not settings.document_store_enabled:
|
if not settings.document_store_enabled:
|
||||||
return WebhookResponse(
|
return WebhookResponse(
|
||||||
document_id=payload.document_id,
|
document_id=payload.id,
|
||||||
status="skipped",
|
status="skipped",
|
||||||
indexed=False,
|
indexed=False,
|
||||||
message="Document store is disabled"
|
message="Document store is disabled"
|
||||||
@@ -86,21 +86,23 @@ async def receive_webhook(
|
|||||||
)
|
)
|
||||||
|
|
||||||
result = await sync_service.index_document(
|
result = await sync_service.index_document(
|
||||||
document_id=payload.document_id,
|
document_id=payload.id,
|
||||||
user=user
|
user=user,
|
||||||
|
content=payload.content, # Use content from webhook payload
|
||||||
|
title=payload.title,
|
||||||
)
|
)
|
||||||
|
|
||||||
return WebhookResponse(
|
return WebhookResponse(
|
||||||
document_id=payload.document_id,
|
document_id=payload.id,
|
||||||
status="indexed" if result.success else "failed",
|
status="indexed" if result.success else "failed",
|
||||||
indexed=result.success,
|
indexed=result.success,
|
||||||
message=result.error if not result.success else f"Indexed: {result.title}"
|
message=result.error if not result.success else f"Indexed: {result.title}"
|
||||||
)
|
)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Webhook processing failed for document {payload.document_id}: {e}", exc_info=True)
|
logger.error(f"Webhook processing failed for document {payload.id}: {e}", exc_info=True)
|
||||||
return WebhookResponse(
|
return WebhookResponse(
|
||||||
document_id=payload.document_id,
|
document_id=payload.id,
|
||||||
status="error",
|
status="error",
|
||||||
indexed=False,
|
indexed=False,
|
||||||
message=str(e)
|
message=str(e)
|
||||||
|
|||||||
@@ -86,6 +86,8 @@ class DocumentSyncService:
|
|||||||
self,
|
self,
|
||||||
document_id: int,
|
document_id: int,
|
||||||
user: str,
|
user: str,
|
||||||
|
content: Optional[str] = None,
|
||||||
|
title: Optional[str] = None,
|
||||||
) -> IndexResult:
|
) -> IndexResult:
|
||||||
"""
|
"""
|
||||||
Index a single document from Paperless into vectors and graph.
|
Index a single document from Paperless into vectors and graph.
|
||||||
@@ -93,6 +95,8 @@ class DocumentSyncService:
|
|||||||
Args:
|
Args:
|
||||||
document_id: Paperless document ID
|
document_id: Paperless document ID
|
||||||
user: User identifier for multi-tenancy
|
user: User identifier for multi-tenancy
|
||||||
|
content: Optional document content (if provided, skip Paperless API call)
|
||||||
|
title: Optional document title (if provided, skip Paperless API call)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
IndexResult with success status and details
|
IndexResult with success status and details
|
||||||
@@ -100,24 +104,36 @@ class DocumentSyncService:
|
|||||||
logger.info(f"Indexing document {document_id} for user {user}")
|
logger.info(f"Indexing document {document_id} for user {user}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Fetch document from Paperless
|
# If content and title provided (from webhook), skip API call
|
||||||
doc = await self.paperless.get_document(document_id)
|
if content is not None and title is not None:
|
||||||
if not doc:
|
doc_title = title
|
||||||
return IndexResult(
|
doc_content = content
|
||||||
success=False,
|
original_filename = None
|
||||||
document_id=document_id,
|
correspondent = None
|
||||||
error="Document not found in Paperless"
|
document_type = None
|
||||||
)
|
tags = []
|
||||||
|
else:
|
||||||
|
# Fetch document from Paperless
|
||||||
|
doc = await self.paperless.get_document(document_id)
|
||||||
|
if not doc:
|
||||||
|
return IndexResult(
|
||||||
|
success=False,
|
||||||
|
document_id=document_id,
|
||||||
|
error="Document not found in Paperless"
|
||||||
|
)
|
||||||
|
doc_title = doc.title
|
||||||
|
doc_content = doc.content or ""
|
||||||
|
original_filename = doc.original_file_name
|
||||||
|
correspondent = doc.correspondent
|
||||||
|
document_type = doc.document_type
|
||||||
|
tags = doc.tags
|
||||||
|
|
||||||
title = doc.title
|
if not doc_content.strip():
|
||||||
content = doc.content or ""
|
|
||||||
|
|
||||||
if not content.strip():
|
|
||||||
logger.warning(f"Document {document_id} has no text content")
|
logger.warning(f"Document {document_id} has no text content")
|
||||||
return IndexResult(
|
return IndexResult(
|
||||||
success=True,
|
success=True,
|
||||||
document_id=document_id,
|
document_id=document_id,
|
||||||
title=title,
|
title=doc_title,
|
||||||
chunks_created=0,
|
chunks_created=0,
|
||||||
error="No text content (possibly image/video only)"
|
error="No text content (possibly image/video only)"
|
||||||
)
|
)
|
||||||
@@ -125,23 +141,23 @@ class DocumentSyncService:
|
|||||||
# Index vectors
|
# Index vectors
|
||||||
chunks_created = await self._index_vectors(
|
chunks_created = await self._index_vectors(
|
||||||
document_id=document_id,
|
document_id=document_id,
|
||||||
title=title,
|
title=doc_title,
|
||||||
content=content,
|
content=doc_content,
|
||||||
user=user,
|
user=user,
|
||||||
metadata={
|
metadata={
|
||||||
"paperless_id": document_id,
|
"paperless_id": document_id,
|
||||||
"original_filename": doc.original_file_name,
|
"original_filename": original_filename,
|
||||||
"correspondent": doc.correspondent,
|
"correspondent": correspondent,
|
||||||
"document_type": doc.document_type,
|
"document_type": document_type,
|
||||||
"tags": doc.tags,
|
"tags": tags,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
# Index graph node
|
# Index graph node
|
||||||
await self._index_graph(
|
await self._index_graph(
|
||||||
document_id=document_id,
|
document_id=document_id,
|
||||||
title=title,
|
title=doc_title,
|
||||||
content=content,
|
content=doc_content,
|
||||||
user=user,
|
user=user,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -156,7 +172,7 @@ class DocumentSyncService:
|
|||||||
return IndexResult(
|
return IndexResult(
|
||||||
success=True,
|
success=True,
|
||||||
document_id=document_id,
|
document_id=document_id,
|
||||||
title=title,
|
title=doc_title,
|
||||||
chunks_created=chunks_created
|
chunks_created=chunks_created
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user