feat: F-PREBUILT + F-COMM + F-WORK + G-WORK — prebuilt agents registered, agent results posted to communication, workflow results posted to communication
Check Cross-Plugin Imports / check (push) Has been cancelled
Check Cross-Plugin Imports / check (push) Has been cancelled
This commit is contained in:
@@ -89,6 +89,63 @@ class WorkflowEngine:
|
||||
'initiated_by': str(instance.initiated_by) if instance.initiated_by else None,
|
||||
})
|
||||
|
||||
# Post workflow completion to Communication (G-WORK)
|
||||
try:
|
||||
from app.plugins.builtins.contracts import get_contract_registry
|
||||
from app.plugins.builtins.kommunikation.models import CommConversation
|
||||
from sqlalchemy import select as sa_select
|
||||
komm = get_contract_registry().get("kommunikation")
|
||||
if komm and instance.initiated_by:
|
||||
room_title = f"Workflow: {workflow.name if hasattr(workflow, 'name') else str(instance.workflow_id)}"
|
||||
existing = await self.db.execute(
|
||||
sa_select(CommConversation).where(
|
||||
CommConversation.tenant_id == self.tenant_id,
|
||||
CommConversation.title == room_title,
|
||||
CommConversation.is_locked.is_(True),
|
||||
CommConversation.locked_by == "workflow",
|
||||
CommConversation.deleted_at.is_(None),
|
||||
)
|
||||
)
|
||||
conv = existing.scalar_one_or_none()
|
||||
if not conv:
|
||||
room = await komm.create_plugin_room(
|
||||
db=self.db,
|
||||
tenant_id=self.tenant_id,
|
||||
user_id=instance.initiated_by,
|
||||
plugin_name="workflow",
|
||||
title=room_title,
|
||||
participant_type="workflow",
|
||||
)
|
||||
conv_id = uuid.UUID(room["conversation_id"])
|
||||
else:
|
||||
conv_id = conv.id
|
||||
await komm.send_message(
|
||||
db=self.db,
|
||||
tenant_id=self.tenant_id,
|
||||
conversation_id=conv_id,
|
||||
sender_id=instance.workflow_id,
|
||||
sender_type="system",
|
||||
content=f"Workflow completed: {instance.status}",
|
||||
content_format="text",
|
||||
blocks=[
|
||||
{
|
||||
"block_type": "action_card",
|
||||
"block_data": {
|
||||
"title": f"Workflow Result: {instance.status}",
|
||||
"description": f"Workflow instance {str(instance.id)[:8]} completed successfully",
|
||||
"actions": [
|
||||
{"label": "View Details", "action": "view_workflow_instance", "data": {"instance_id": str(instance.id)}},
|
||||
],
|
||||
},
|
||||
"sort_order": 0,
|
||||
}
|
||||
],
|
||||
metadata={"workflow_id": str(instance.workflow_id), "instance_id": str(instance.id), "status": instance.status},
|
||||
)
|
||||
await self.db.flush()
|
||||
except Exception:
|
||||
logger.warning("Failed to post workflow result to communication", exc_info=True)
|
||||
|
||||
return _instance_to_dict(instance)
|
||||
|
||||
step = steps[instance.current_step_index]
|
||||
|
||||
Reference in New Issue
Block a user