feat(F): F-PROACTIVE consolidate proactive AI — trigger_dispatcher dispatches agents on context/UI events
Check Cross-Plugin Imports / check (push) Has been cancelled

This commit is contained in:
Agent Zero
2026-08-17 18:40:41 +02:00
parent 131d761936
commit 06b281ba74
7 changed files with 893 additions and 41 deletions
+58 -3
View File
@@ -4,8 +4,10 @@ from __future__ import annotations
import uuid
from datetime import datetime
from typing import Any
from sqlalchemy import DateTime, ForeignKey, Index, String, Text
from sqlalchemy import DateTime, ForeignKey, Index, Integer, String, Text
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.dialects.postgresql import UUID as PGUUID
from sqlalchemy.orm import Mapped, mapped_column
@@ -14,7 +16,13 @@ from app.models.owned_mixin import OwnedMixin
class Task(Base, TenantMixin, OwnedMixin):
"""Task entity — free activities (calls, notes, visits) linked to contacts."""
"""Task entity — free activities (calls, notes, visits) linked to entities.
Supports polymorphic assignment (user/agent/group), polymorphic entity
links (contact/company/...), subtasks, dependencies, goals/milestones and
agent subtasks. Legacy ``contact_id`` and ``assigned_to`` columns are kept
for backward compatibility and mirrored into the polymorphic fields.
"""
__tablename__ = "tasks"
__table_args__ = (
@@ -23,6 +31,10 @@ class Task(Base, TenantMixin, OwnedMixin):
Index("ix_tasks_tenant_assigned", "tenant_id", "assigned_to"),
Index("ix_tasks_tenant_due", "tenant_id", "due_date"),
Index("ix_tasks_contact", "contact_id"),
Index("ix_tasks_tenant_entity", "tenant_id", "entity_type", "entity_id"),
Index("ix_tasks_tenant_assignee", "tenant_id", "assignee_type", "assignee_id"),
Index("ix_tasks_tenant_parent", "tenant_id", "parent_task_id"),
Index("ix_tasks_tenant_type", "tenant_id", "task_type"),
)
id: Mapped[uuid.UUID] = mapped_column(
@@ -32,7 +44,7 @@ class Task(Base, TenantMixin, OwnedMixin):
description: Mapped[str | None] = mapped_column(Text, nullable=True)
status: Mapped[str] = mapped_column(
String(20), nullable=False, default="open"
) # open, in_progress, done
) # open, in_progress, review, blocked, done, cancelled
priority: Mapped[str] = mapped_column(
String(10), nullable=False, default="medium"
) # low, medium, high, urgent
@@ -49,3 +61,46 @@ class Task(Base, TenantMixin, OwnedMixin):
PGUUID(as_uuid=True), ForeignKey("users.id", ondelete="SET NULL"), nullable=True
)
deleted_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
# ── F.14 Unified Task System ────────────────────────────────────────────
# Polymorphic assignee (user/agent/group)
assignee_type: Mapped[str] = mapped_column(
String(20), nullable=False, default="user"
) # user, agent, group
assignee_id: Mapped[uuid.UUID | None] = mapped_column(
PGUUID(as_uuid=True), nullable=True
)
# Polymorphic entity link (contact/company/...)
entity_type: Mapped[str | None] = mapped_column(String(80), nullable=True)
entity_id: Mapped[uuid.UUID | None] = mapped_column(PGUUID(as_uuid=True), nullable=True)
# Polymorphic creator (user/agent/workflow/system)
creator_type: Mapped[str] = mapped_column(
String(20), nullable=False, default="user"
) # user, agent, workflow, system
creator_id: Mapped[uuid.UUID | None] = mapped_column(
PGUUID(as_uuid=True), nullable=True
)
# Subtasks (self-reference)
parent_task_id: Mapped[uuid.UUID | None] = mapped_column(
PGUUID(as_uuid=True),
ForeignKey("tasks.id", ondelete="CASCADE"),
nullable=True,
)
# Task dependencies (blocked-by task IDs)
depends_on: Mapped[list[Any]] = mapped_column(JSONB, nullable=False, default=list)
# Task type
task_type: Mapped[str] = mapped_column(
String(30), nullable=False, default="todo"
) # todo, approval, follow_up, review, goal, milestone, agent_subtask
# Goal / Milestone support
success_criteria: Mapped[dict[str, Any] | None] = mapped_column(JSONB, nullable=True)
target_date: Mapped[datetime | None] = mapped_column(
DateTime(timezone=True), nullable=True
)
progress: Mapped[int] = mapped_column(Integer, nullable=False, default=0) # 0-100