feat: add metadata timestamps to document processing and update frontend compatibility

- Add metadata field to doc_status storage with Unix timestamps for processing start/end times
- Update frontend API types: error -> error_msg, add track_id and metadata support
- Add getTrackStatus API method for document tracking functionality
- Fix frontend DocumentManager to use error_msg field for proper error display
- Ensure full compatibility between backend metadata changes and frontend UI
This commit is contained in:
yangdx 2025-07-30 00:04:27 +08:00
parent 93afa7d8a7
commit 6f958d5aee
4 changed files with 26 additions and 7 deletions

View file

@ -369,7 +369,7 @@ class DocStatusResponse(BaseModel):
chunks_count: Optional[int] = Field(
default=None, description="Number of chunks the document was split into"
)
error: Optional[str] = Field(
error_msg: Optional[str] = Field(
default=None, description="Error message if processing failed"
)
metadata: Optional[dict[str, Any]] = Field(
@ -1570,7 +1570,7 @@ def create_document_routes(
updated_at=format_datetime(doc_status.updated_at),
track_id=doc_status.track_id,
chunks_count=doc_status.chunks_count,
error=doc_status.error,
error_msg=doc_status.error_msg,
metadata=doc_status.metadata,
file_path=doc_status.file_path,
)
@ -1844,7 +1844,7 @@ def create_document_routes(
updated_at=format_datetime(doc_status.updated_at),
track_id=doc_status.track_id,
chunks_count=doc_status.chunks_count,
error=doc_status.error,
error_msg=doc_status.error_msg,
metadata=doc_status.metadata,
file_path=doc_status.file_path,
)

View file

@ -647,7 +647,7 @@ class DocProcessingStatus:
"""Number of chunks after splitting, used for processing"""
chunks_list: list[str] | None = field(default_factory=list)
"""List of chunk IDs associated with this document, used for deletion"""
error: str | None = None
error_msg: str | None = None
"""Error message if failed"""
metadata: dict[str, Any] = field(default_factory=dict)
"""Additional metadata"""

View file

@ -143,6 +143,7 @@ export type QueryResponse = {
export type DocActionResponse = {
status: 'success' | 'partial_success' | 'failure' | 'duplicated'
message: string
track_id?: string
}
export type DeleteDocResponse = {
@ -160,8 +161,9 @@ export type DocStatusResponse = {
status: DocStatus
created_at: string
updated_at: string
track_id?: string
chunks_count?: number
error?: string
error_msg?: string
metadata?: Record<string, any>
file_path: string
}
@ -170,6 +172,13 @@ export type DocsStatusesResponse = {
statuses: Record<DocStatus, DocStatusResponse[]>
}
export type TrackStatusResponse = {
track_id: string
documents: DocStatusResponse[]
total_count: number
status_summary: Record<string, number>
}
export type AuthStatusResponse = {
auth_configured: boolean
access_token?: string
@ -689,3 +698,13 @@ export const checkEntityNameExists = async (entityName: string): Promise<boolean
return false
}
}
/**
* Get the processing status of documents by tracking ID
* @param trackId The tracking ID returned from upload, text, or texts endpoints
* @returns Promise with the track status response containing documents and summary
*/
export const getTrackStatus = async (trackId: string): Promise<TrackStatusResponse> => {
const response = await axiosInstance.get(`/documents/track_status/${encodeURIComponent(trackId)}`)
return response.data
}

View file

@ -749,8 +749,8 @@ export default function DocumentManager() {
{doc.status === 'failed' && (
<span className="text-red-600">{t('documentPanel.documentManager.status.failed')}</span>
)}
{doc.error && (
<span className="ml-2 text-red-500" title={doc.error}>
{doc.error_msg && (
<span className="ml-2 text-red-500" title={doc.error_msg}>
</span>
)}