feat: AI chat session conclusion + survey completion & management
AI Assistant - Conclude Session:
- 3-step modal: select outcome (resolved/escalated/paused), add notes, AI-generated summary
- AI generates structured ticket notes from conversation transcript (PSA-ready format)
- Copy to clipboard for pasting into ticketing systems
- "Resume in New Chat" for paused sessions (pre-loads context into new chat)
- Backend: POST /chats/{id}/conclude endpoint, conclusion_summary/outcome/concluded_at fields
- Migration 048: add conclusion fields to assistant_chats
Survey Completion Flow:
- Email-to-self option after submission (branded HTML email with formatted responses)
- Finish button navigates to /survey/thank-you page
- Thank you page with close-window message and feedback email callout
- Already-submitted state updated with same messaging
- Backend: POST /survey/email-copy public endpoint
Survey Admin Management:
- Read/unread indicators (cyan dot, bold name, auto-mark on expand)
- Unread count stat card
- Per-row context menu: mark read/unread, archive/unarchive, delete
- Bulk actions bar: select all, mark read/unread, archive, delete
- Show Archived toggle to filter archived responses
- Backend: 7 new admin endpoints (read, unread, archive, unarchive, delete, bulk)
- Migration 049: add is_read, archived_at to survey_responses
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -228,6 +228,117 @@ def _auto_title(message: str) -> str:
|
||||
return title
|
||||
|
||||
|
||||
CONCLUSION_SYSTEM_PROMPT = """\
|
||||
You are a ticket documentation specialist for MSP (Managed Service Provider) teams. \
|
||||
Your job is to transform an AI troubleshooting conversation into clean, professional \
|
||||
ticket notes that can be pasted directly into a PSA/ticketing system (ConnectWise, \
|
||||
Autotask, HaloPSA, etc.).
|
||||
|
||||
## Output Format
|
||||
|
||||
Generate a structured summary using this exact format:
|
||||
|
||||
**Subject:** [One-line summary of the issue]
|
||||
|
||||
**Outcome:** {outcome_label}
|
||||
|
||||
**Problem Description:**
|
||||
[2-3 sentence summary of the original problem]
|
||||
|
||||
**Steps Taken:**
|
||||
1. [Step] — [Result/finding]
|
||||
2. [Step] — [Result/finding]
|
||||
(list all troubleshooting steps from the conversation)
|
||||
|
||||
**Current Status:**
|
||||
[Where things stand now — what was resolved, what remains]
|
||||
|
||||
{notes_section}
|
||||
|
||||
**Key Findings:**
|
||||
- [Important discovery or configuration detail]
|
||||
- [Any relevant error codes, settings, or values identified]
|
||||
|
||||
{resume_section}
|
||||
|
||||
## Rules
|
||||
- Be concise but thorough — these notes will be read by another engineer
|
||||
- Include specific technical details (commands run, error messages, config values)
|
||||
- Use plain text formatting (no HTML) — bold with ** is fine
|
||||
- Do NOT include conversational filler, greetings, or meta-commentary
|
||||
- Extract ALL actionable steps from the conversation, in chronological order
|
||||
- If the conversation identified root cause, state it clearly
|
||||
"""
|
||||
|
||||
|
||||
async def generate_conclusion_summary(
|
||||
chat: "AssistantChat",
|
||||
outcome: str,
|
||||
notes: str | None = None,
|
||||
) -> str:
|
||||
"""Generate a ticket-ready summary from a concluded chat conversation."""
|
||||
outcome_labels = {
|
||||
"resolved": "Resolved",
|
||||
"escalated": "Escalated",
|
||||
"paused": "Paused — To Be Continued",
|
||||
}
|
||||
outcome_label = outcome_labels.get(outcome, outcome)
|
||||
|
||||
notes_section = ""
|
||||
if notes:
|
||||
notes_section = f"\n**Engineer Notes:**\n{notes}\n"
|
||||
|
||||
resume_section = ""
|
||||
if outcome == "paused":
|
||||
resume_section = (
|
||||
"\n**Next Steps (for resumption):**\n"
|
||||
"- [What needs to happen next]\n"
|
||||
"- [Any pending actions or follow-ups]\n"
|
||||
)
|
||||
elif outcome == "escalated":
|
||||
resume_section = (
|
||||
"\n**Escalation Details:**\n"
|
||||
"- [Reason for escalation]\n"
|
||||
"- [Recommended next steps for receiving team/tier]\n"
|
||||
)
|
||||
|
||||
# Build the conversation transcript for the AI
|
||||
transcript_lines = []
|
||||
for msg in chat.messages:
|
||||
role_label = "ENGINEER" if msg["role"] == "user" else "AI ASSISTANT"
|
||||
transcript_lines.append(f"[{role_label}]: {msg['content']}")
|
||||
|
||||
transcript = "\n\n".join(transcript_lines)
|
||||
|
||||
prompt = (
|
||||
f"Outcome: {outcome_label}\n\n"
|
||||
f"{'Engineer Notes: ' + notes if notes else '(No additional notes)'}\n\n"
|
||||
f"--- CONVERSATION TRANSCRIPT ---\n\n{transcript}\n\n"
|
||||
f"--- END TRANSCRIPT ---\n\n"
|
||||
f"Generate the ticket notes now. Replace all placeholder brackets with actual content from the conversation. "
|
||||
f"The notes_section placeholder should be: {notes_section or '(omit this section)'}\n"
|
||||
f"The resume_section placeholder should be filled based on the conversation context."
|
||||
)
|
||||
|
||||
system_with_vars = CONCLUSION_SYSTEM_PROMPT.replace(
|
||||
"{outcome_label}", outcome_label
|
||||
).replace(
|
||||
"{notes_section}", notes_section or ""
|
||||
).replace(
|
||||
"{resume_section}", resume_section
|
||||
)
|
||||
|
||||
content, _, _ = await _call_ai(
|
||||
system_base=system_with_vars,
|
||||
rag_context="",
|
||||
history=[],
|
||||
new_message=prompt,
|
||||
max_tokens=2048,
|
||||
)
|
||||
|
||||
return content
|
||||
|
||||
|
||||
async def create_chat(
|
||||
user_id: UUID,
|
||||
account_id: UUID,
|
||||
|
||||
Reference in New Issue
Block a user