feat: Enhance AI Knowledge sync process with full sync mode and attachment handling

This commit is contained in:
bsiggel
2026-03-12 22:35:48 +00:00
parent 6bf2343a12
commit 8f1533337c
3 changed files with 27 additions and 9 deletions

View File

@@ -227,7 +227,7 @@ class AIKnowledgeSync(BaseSyncUtils):
})
# Sync documents
await self._sync_knowledge_documents(knowledge_id, collection_id, ctx)
await self._sync_knowledge_documents(knowledge_id, collection_id, ctx, full_sync=full_sync)
else:
ctx.logger.error(f"❌ Unknown activationStatus: {activation_status}")
@@ -327,14 +327,33 @@ class AIKnowledgeSync(BaseSyncUtils):
ctx.logger.info(f" 🔄 Syncing: {reason}")
# Get complete document entity with attachment info
doc_entity = await espocrm.get_entity('CDokumente', doc_id)
attachment_id = doc_entity.get('dokumentId')
if not attachment_id:
ctx.logger.error(f" ❌ No attachment ID found for document {doc_id}")
failed += 1
continue
# Get attachment details for MIME type
try:
attachment = await espocrm.get_entity('Attachment', attachment_id)
mime_type = attachment.get('type', 'application/octet-stream')
file_size = attachment.get('size', 0)
except Exception as e:
ctx.logger.warn(f" ⚠️ Failed to get attachment details: {e}, using defaults")
mime_type = 'application/octet-stream'
file_size = 0
ctx.logger.info(f" 📎 Attachment: {attachment_id} ({mime_type}, {file_size} bytes)")
# Download document
attachment_id = doc.get('documentId') # TODO: Get correct attachment ID from CDokumente
file_content = await espocrm.download_attachment(attachment_id)
ctx.logger.info(f" 📥 Downloaded {len(file_content)} bytes")
# Upload to XAI
filename = doc_name
mime_type = 'application/octet-stream' # TODO: Get from attachment
xai_file_id = await xai.upload_file(file_content, filename, mime_type)
ctx.logger.info(f" 📤 Uploaded to XAI: {xai_file_id}")