Spaces:
Paused
Paused
dushyantsingh0 commited on
Commit ·
b0183db
1
Parent(s): f18057d
fix: support 8-character short ticket IDs in all support tools
Browse files- agents/tools/nexus_tools.py +35 -16
agents/tools/nexus_tools.py
CHANGED
|
@@ -40,6 +40,25 @@ def is_3sc_staff(role: str) -> bool:
|
|
| 40 |
r_lower = str(role).lower()
|
| 41 |
return any(s in r_lower for s in ["3sc_", "sc_agent", "sc_lead", "sc_admin"])
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
# --- SECURED READ-ONLY TOOLS ---
|
| 44 |
|
| 45 |
async def kb_search_tool(query: str, workspace_id: UUID, role: str = "customer_user") -> str:
|
|
@@ -167,10 +186,10 @@ async def add_ticket_comment_tool(ticket_id: str, comment: str, workspace_id: UU
|
|
| 167 |
Add a new message or comment to a ticket.
|
| 168 |
is_internal=True is ONLY permitted for 3SC Staff.
|
| 169 |
"""
|
| 170 |
-
t_id = safe_uuid(ticket_id)
|
| 171 |
-
if not t_id: return "Error: Invalid Ticket ID format."
|
| 172 |
-
|
| 173 |
async with async_session_factory() as db:
|
|
|
|
|
|
|
|
|
|
| 174 |
# 1. Verify existence
|
| 175 |
stmt = select(Ticket).where(Ticket.id == t_id, Ticket.workspace_id == workspace_id)
|
| 176 |
res = await db.execute(stmt)
|
|
@@ -201,10 +220,10 @@ async def change_ticket_status_tool(ticket_id: str, new_status: str, workspace_i
|
|
| 201 |
Update a ticket's status (e.g. to RESOLVED, CLOSED, IN_PROGRESS).
|
| 202 |
RESOLVED/CLOSED transitions require 3SC Staff authorization.
|
| 203 |
"""
|
| 204 |
-
t_id = safe_uuid(ticket_id)
|
| 205 |
-
if not t_id: return "Error: Invalid Ticket ID format."
|
| 206 |
-
|
| 207 |
async with async_session_factory() as db:
|
|
|
|
|
|
|
|
|
|
| 208 |
stmt = select(Ticket).where(Ticket.id == t_id, Ticket.workspace_id == workspace_id)
|
| 209 |
res = await db.execute(stmt)
|
| 210 |
ticket = res.scalar_one_or_none()
|
|
@@ -242,10 +261,10 @@ async def update_ticket_attributes_tool(ticket_id: str, workspace_id: UUID, prio
|
|
| 242 |
if not is_staff_role(role):
|
| 243 |
return "Permission Denied: Only 3SC Staff can modify core ticket attributes."
|
| 244 |
|
| 245 |
-
t_id = safe_uuid(ticket_id)
|
| 246 |
-
if not t_id: return "Error: Invalid Ticket ID format."
|
| 247 |
-
|
| 248 |
async with async_session_factory() as db:
|
|
|
|
|
|
|
|
|
|
| 249 |
stmt = select(Ticket).where(Ticket.id == t_id, Ticket.workspace_id == workspace_id)
|
| 250 |
res = await db.execute(stmt)
|
| 251 |
ticket = res.scalar_one_or_none()
|
|
@@ -426,10 +445,10 @@ async def get_ticket_details_tool(ticket_id: str, workspace_id: UUID, role: str
|
|
| 426 |
"""
|
| 427 |
Retrieve full context, message history, and AI summaries for a specific ticket.
|
| 428 |
"""
|
| 429 |
-
t_id = safe_uuid(ticket_id)
|
| 430 |
-
if not t_id: return "Error: Invalid Ticket ID format."
|
| 431 |
-
|
| 432 |
async with async_session_factory() as db:
|
|
|
|
|
|
|
|
|
|
| 433 |
# 1. Fetch Ticket
|
| 434 |
stmt = select(Ticket).where(Ticket.id == t_id, Ticket.workspace_id == workspace_id)
|
| 435 |
res = await db.execute(stmt)
|
|
@@ -669,7 +688,7 @@ async def sentiment_pulse_tool(ticket_id: UUID, workspace_id: UUID) -> str:
|
|
| 669 |
Retrieve message history for sentiment and pulse analysis.
|
| 670 |
"""
|
| 671 |
async with async_session_factory() as db:
|
| 672 |
-
t_id =
|
| 673 |
if not t_id: return "Invalid Ticket ID."
|
| 674 |
|
| 675 |
stmt = (
|
|
@@ -696,8 +715,8 @@ async def knowledge_drafting_tool(ticket_id: UUID, workspace_id: UUID) -> str:
|
|
| 696 |
Extract problem and resolution data to draft a KB article.
|
| 697 |
"""
|
| 698 |
async with async_session_factory() as db:
|
| 699 |
-
t_id =
|
| 700 |
-
if not t_id: return "
|
| 701 |
|
| 702 |
stmt = select(Ticket).where(
|
| 703 |
Ticket.id == t_id,
|
|
@@ -721,7 +740,7 @@ async def assign_ticket_tool(ticket_id: UUID, user_id: UUID, workspace_id: UUID)
|
|
| 721 |
Assign a ticket to a specific agent.
|
| 722 |
"""
|
| 723 |
async with async_session_factory() as db:
|
| 724 |
-
t_id =
|
| 725 |
u_id = safe_uuid(user_id)
|
| 726 |
if not t_id or not u_id: return "Invalid Ticket or User ID."
|
| 727 |
|
|
|
|
| 40 |
r_lower = str(role).lower()
|
| 41 |
return any(s in r_lower for s in ["3sc_", "sc_agent", "sc_lead", "sc_admin"])
|
| 42 |
|
| 43 |
+
async def resolve_ticket_id(db, ticket_id: str, workspace_id: UUID) -> Optional[UUID]:
|
| 44 |
+
"""Resolves full UUID or 8-char short ID to a full UUID within a workspace."""
|
| 45 |
+
if not ticket_id: return None
|
| 46 |
+
t_id = safe_uuid(ticket_id)
|
| 47 |
+
if t_id: return t_id
|
| 48 |
+
|
| 49 |
+
# Try short ID lookup (8+ chars)
|
| 50 |
+
s_id = str(ticket_id).lower().strip()
|
| 51 |
+
if len(s_id) >= 8:
|
| 52 |
+
stmt = select(Ticket.id).where(
|
| 53 |
+
Ticket.workspace_id == workspace_id,
|
| 54 |
+
cast(Ticket.id, String).ilike(f"{s_id}%")
|
| 55 |
+
).limit(2)
|
| 56 |
+
res = await db.execute(stmt)
|
| 57 |
+
matches = res.scalars().all()
|
| 58 |
+
if len(matches) == 1:
|
| 59 |
+
return matches[0]
|
| 60 |
+
return None
|
| 61 |
+
|
| 62 |
# --- SECURED READ-ONLY TOOLS ---
|
| 63 |
|
| 64 |
async def kb_search_tool(query: str, workspace_id: UUID, role: str = "customer_user") -> str:
|
|
|
|
| 186 |
Add a new message or comment to a ticket.
|
| 187 |
is_internal=True is ONLY permitted for 3SC Staff.
|
| 188 |
"""
|
|
|
|
|
|
|
|
|
|
| 189 |
async with async_session_factory() as db:
|
| 190 |
+
t_id = await resolve_ticket_id(db, ticket_id, workspace_id)
|
| 191 |
+
if not t_id: return f"Error: Ticket `{ticket_id}` not found or ID is ambiguous."
|
| 192 |
+
|
| 193 |
# 1. Verify existence
|
| 194 |
stmt = select(Ticket).where(Ticket.id == t_id, Ticket.workspace_id == workspace_id)
|
| 195 |
res = await db.execute(stmt)
|
|
|
|
| 220 |
Update a ticket's status (e.g. to RESOLVED, CLOSED, IN_PROGRESS).
|
| 221 |
RESOLVED/CLOSED transitions require 3SC Staff authorization.
|
| 222 |
"""
|
|
|
|
|
|
|
|
|
|
| 223 |
async with async_session_factory() as db:
|
| 224 |
+
t_id = await resolve_ticket_id(db, ticket_id, workspace_id)
|
| 225 |
+
if not t_id: return f"Error: Ticket `{ticket_id}` not found or ID is ambiguous."
|
| 226 |
+
|
| 227 |
stmt = select(Ticket).where(Ticket.id == t_id, Ticket.workspace_id == workspace_id)
|
| 228 |
res = await db.execute(stmt)
|
| 229 |
ticket = res.scalar_one_or_none()
|
|
|
|
| 261 |
if not is_staff_role(role):
|
| 262 |
return "Permission Denied: Only 3SC Staff can modify core ticket attributes."
|
| 263 |
|
|
|
|
|
|
|
|
|
|
| 264 |
async with async_session_factory() as db:
|
| 265 |
+
t_id = await resolve_ticket_id(db, ticket_id, workspace_id)
|
| 266 |
+
if not t_id: return f"Error: Ticket `{ticket_id}` not found or ID is ambiguous."
|
| 267 |
+
|
| 268 |
stmt = select(Ticket).where(Ticket.id == t_id, Ticket.workspace_id == workspace_id)
|
| 269 |
res = await db.execute(stmt)
|
| 270 |
ticket = res.scalar_one_or_none()
|
|
|
|
| 445 |
"""
|
| 446 |
Retrieve full context, message history, and AI summaries for a specific ticket.
|
| 447 |
"""
|
|
|
|
|
|
|
|
|
|
| 448 |
async with async_session_factory() as db:
|
| 449 |
+
t_id = await resolve_ticket_id(db, ticket_id, workspace_id)
|
| 450 |
+
if not t_id: return f"Error: Ticket `{ticket_id}` not found or ID is ambiguous."
|
| 451 |
+
|
| 452 |
# 1. Fetch Ticket
|
| 453 |
stmt = select(Ticket).where(Ticket.id == t_id, Ticket.workspace_id == workspace_id)
|
| 454 |
res = await db.execute(stmt)
|
|
|
|
| 688 |
Retrieve message history for sentiment and pulse analysis.
|
| 689 |
"""
|
| 690 |
async with async_session_factory() as db:
|
| 691 |
+
t_id = await resolve_ticket_id(db, ticket_id, workspace_id)
|
| 692 |
if not t_id: return "Invalid Ticket ID."
|
| 693 |
|
| 694 |
stmt = (
|
|
|
|
| 715 |
Extract problem and resolution data to draft a KB article.
|
| 716 |
"""
|
| 717 |
async with async_session_factory() as db:
|
| 718 |
+
t_id = await resolve_ticket_id(db, ticket_id, workspace_id)
|
| 719 |
+
if not t_id: return "Ticket not found or ID ambiguous."
|
| 720 |
|
| 721 |
stmt = select(Ticket).where(
|
| 722 |
Ticket.id == t_id,
|
|
|
|
| 740 |
Assign a ticket to a specific agent.
|
| 741 |
"""
|
| 742 |
async with async_session_factory() as db:
|
| 743 |
+
t_id = await resolve_ticket_id(db, ticket_id, workspace_id)
|
| 744 |
u_id = safe_uuid(user_id)
|
| 745 |
if not t_id or not u_id: return "Invalid Ticket or User ID."
|
| 746 |
|