Compare commits
2 Commits
9a3e01d447
...
2292fd4762
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2292fd4762 | ||
|
|
9ada48d8c8 |
@@ -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'
|
# Update EspoCRM: Set datenbankId + change status to 'active'
|
||||||
await espocrm.update_entity('CAIKnowledge', knowledge_id, {
|
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(f"✅ Collection created: {collection_id}")
|
||||||
ctx.logger.info(" Status changed to 'active', next webhook will sync documents")
|
ctx.logger.info(" Status changed to 'active', now syncing documents...")
|
||||||
return
|
|
||||||
|
# Continue to document sync immediately (don't return)
|
||||||
|
# Fall through to sync logic below
|
||||||
|
|
||||||
# ═══════════════════════════════════════════════════════════
|
# ═══════════════════════════════════════════════════════════
|
||||||
# CASE 2: DEACTIVATED → Delete Collection from XAI
|
# CASE 2: DEACTIVATED → Delete Collection from XAI
|
||||||
@@ -201,14 +204,15 @@ class AIKnowledgeSync(BaseSyncUtils):
|
|||||||
return
|
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:
|
if not collection_id:
|
||||||
ctx.logger.error("❌ Status 'active' but no datenbankId!")
|
ctx.logger.error("❌ Status 'active' but no datenbankId!")
|
||||||
raise RuntimeError("Active knowledge without collection ID")
|
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
|
# Verify collection exists
|
||||||
collection = await xai.get_collection(collection_id)
|
collection = await xai.get_collection(collection_id)
|
||||||
@@ -226,10 +230,10 @@ class AIKnowledgeSync(BaseSyncUtils):
|
|||||||
'datenbankId': collection_id
|
'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)
|
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}")
|
ctx.logger.error(f"❌ Unknown aktivierungsstatus: {activation_status}")
|
||||||
raise ValueError(f"Invalid aktivierungsstatus: {activation_status}")
|
raise ValueError(f"Invalid aktivierungsstatus: {activation_status}")
|
||||||
|
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ async def handler(event_data: Dict[str, Any], ctx: FlowContext[Any]) -> None:
|
|||||||
ctx.logger.error("=" * 80)
|
ctx.logger.error("=" * 80)
|
||||||
ctx.logger.error("❌ AI KNOWLEDGE SYNC FAILED")
|
ctx.logger.error("❌ AI KNOWLEDGE SYNC FAILED")
|
||||||
ctx.logger.error("=" * 80)
|
ctx.logger.error("=" * 80)
|
||||||
ctx.logger.error(f"Error: {e}", exc_info=True)
|
ctx.logger.error(f"Error: {e}")
|
||||||
ctx.logger.error(f"Knowledge ID: {knowledge_id}")
|
ctx.logger.error(f"Knowledge ID: {knowledge_id}")
|
||||||
ctx.logger.error("=" * 80)
|
ctx.logger.error("=" * 80)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user