|
|
|
|
@@ -144,7 +144,8 @@ class AIKnowledgeSync(BaseSyncUtils):
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
collection_id = collection['id']
|
|
|
|
|
# XAI API returns 'collection_id' not 'id'
|
|
|
|
|
collection_id = collection.get('collection_id') or collection.get('id')
|
|
|
|
|
|
|
|
|
|
# Update EspoCRM: Set datenbankId + change status to 'active'
|
|
|
|
|
await espocrm.update_entity('CAIKnowledge', knowledge_id, {
|
|
|
|
|
@@ -154,8 +155,10 @@ class AIKnowledgeSync(BaseSyncUtils):
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
ctx.logger.info(f"✅ Collection created: {collection_id}")
|
|
|
|
|
ctx.logger.info(" Status changed to 'active', next webhook will sync documents")
|
|
|
|
|
return
|
|
|
|
|
ctx.logger.info(" Status changed to 'active', now syncing documents...")
|
|
|
|
|
|
|
|
|
|
# Continue to document sync immediately (don't return)
|
|
|
|
|
# Fall through to sync logic below
|
|
|
|
|
|
|
|
|
|
# ═══════════════════════════════════════════════════════════
|
|
|
|
|
# CASE 2: DEACTIVATED → Delete Collection from XAI
|
|
|
|
|
@@ -201,14 +204,15 @@ class AIKnowledgeSync(BaseSyncUtils):
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
# ═══════════════════════════════════════════════════════════
|
|
|
|
|
# CASE 4: ACTIVE → Normal Sync
|
|
|
|
|
# CASE 4: ACTIVE → Normal Sync (or just created from NEW)
|
|
|
|
|
# ═══════════════════════════════════════════════════════════
|
|
|
|
|
elif activation_status == AIKnowledgeActivationStatus.ACTIVE.value:
|
|
|
|
|
if activation_status in (AIKnowledgeActivationStatus.ACTIVE.value, AIKnowledgeActivationStatus.NEW.value):
|
|
|
|
|
if not collection_id:
|
|
|
|
|
ctx.logger.error("❌ Status 'active' but no datenbankId!")
|
|
|
|
|
raise RuntimeError("Active knowledge without collection ID")
|
|
|
|
|
|
|
|
|
|
ctx.logger.info(f"🔄 Status 'active' → Syncing documents to {collection_id}")
|
|
|
|
|
if activation_status == AIKnowledgeActivationStatus.ACTIVE.value:
|
|
|
|
|
ctx.logger.info(f"🔄 Status 'active' → Syncing documents to {collection_id}")
|
|
|
|
|
|
|
|
|
|
# Verify collection exists
|
|
|
|
|
collection = await xai.get_collection(collection_id)
|
|
|
|
|
@@ -226,10 +230,10 @@ class AIKnowledgeSync(BaseSyncUtils):
|
|
|
|
|
'datenbankId': collection_id
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
# Sync documents
|
|
|
|
|
# Sync documents (both for ACTIVE status and after NEW → ACTIVE transition)
|
|
|
|
|
await self._sync_knowledge_documents(knowledge_id, collection_id, ctx)
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
elif activation_status not in (AIKnowledgeActivationStatus.DEACTIVATED.value, AIKnowledgeActivationStatus.PAUSED.value):
|
|
|
|
|
ctx.logger.error(f"❌ Unknown aktivierungsstatus: {activation_status}")
|
|
|
|
|
raise ValueError(f"Invalid aktivierungsstatus: {activation_status}")
|
|
|
|
|
|
|
|
|
|
|