feat(ai-session): add Phase 2 PSA integration, escalation handoff, and session management

Phase 2 of the FlowPilot-First Pivot connecting AI sessions to ConnectWise PSA:

Slice 1 — PSA Ticket Intake:
- FlowPilotEngine accepts psa_ticket intake with graceful CW API fallback
- Ticket picker on intake screen (refactored TicketPickerModal for dual-mode)
- Ticket context card in session sidebar

Slice 2 — Auto Documentation Push:
- PSA documentation service with resolution/escalation note formatting
- Time entry creation via new ConnectWise provider method
- Automatic retry scheduler (APScheduler, 5min interval, 3 retries)
- PSA push status indicators in frontend with manual retry button
- Member mapping warning when CW member not mapped

Slice 3 — Session Pause/Resume & Escalation Handoff:
- Pause/resume endpoints for same-engineer session bookmarking
- Escalation flow: requesting_escalation status, self-escalation blocked
- Enhanced escalation package with LLM-generated hypotheses/suggestions
- Pickup endpoint with continue/fresh resume modes and briefing step
- Escalation queue (sidebar nav + dedicated page)
- SessionBriefing component with continue/fresh choice UI
- EscalateModal with PSA-aware button text

Slice 4 — Mid-Session Ticket Linking:
- Link ticket retroactively with context injection into system prompt
- Link Ticket button in session sidebar

Slice 5 — FlowPilot PSA Settings:
- Settings tab on IntegrationsPage with 7 configurable options
- Stored as flowpilot_settings JSONB on PsaConnection

Database: 2 migrations (flowpilot_settings, psa_post_log changes, status constraint)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-19 01:30:05 +00:00
parent 2063a799b0
commit bbe590bfec
37 changed files with 3698 additions and 121 deletions

View File

@@ -17,6 +17,7 @@ export interface AISessionCreateResponse {
matched_flow_name: string | null
match_score: number | null
first_step: AISessionStepResponse
psa_context_status: string | null // "loaded" | "unavailable" | null
}
// ── Step interaction ──
@@ -95,6 +96,9 @@ export interface SessionCloseResponse {
session_id: string
status: string
documentation: SessionDocumentation
psa_push_status: string // "sent" | "pending_retry" | "no_psa" | "failed"
psa_push_error: string | null
member_mapping_warning: string | null
}
export interface RateSessionRequest {
@@ -113,10 +117,17 @@ export interface AISessionSummary {
confidence_tier: string
step_count: number
session_rating: number | null
psa_ticket_id: string | null
escalation_reason: string | null
created_at: string
resolved_at: string | null
}
export interface PickupSessionRequest {
resume_mode: 'continue' | 'fresh'
additional_context?: string
}
export interface AISessionDetail extends AISessionSummary {
intake_content: Record<string, unknown>
matched_flow_id: string | null
@@ -125,5 +136,8 @@ export interface AISessionDetail extends AISessionSummary {
resolution_action: string | null
escalation_reason: string | null
session_feedback: string | null
psa_ticket_id: string | null
psa_connection_id: string | null
ticket_data: Record<string, unknown> | null
steps: AISessionStepResponse[]
}

View File

@@ -121,3 +121,13 @@ export interface AutoMatchResult {
matched: PsaMemberMappingResponse[]
unmatched_users: number
}
export interface FlowpilotSettings {
auto_push: boolean
auto_time_entry: boolean
time_rounding: string // "15min" | "30min" | "exact" | "none"
note_visibility: string // "internal" | "both"
include_diagnostic_steps: boolean
prompt_status_on_resolution: boolean
prompt_status_on_escalation: boolean
}