feat: AI-assisted flow builder with 4-stage wizard #87

Merged
chihlasm merged 25 commits from feat/ai-flow-builder into main 2026-02-23 05:03:54 +00:00
15 changed files with 45 additions and 33 deletions
Showing only changes of commit 339486f555 - Show all commits

View File

@@ -4,7 +4,7 @@
# Testing
pytest==7.4.3
pytest-asyncio==0.23.0
httpx==0.26.0
httpx>=0.27.0
pytest-cov==4.1.0
# Code quality

View File

@@ -1,2 +1 @@
export { EmptyState } from '@/components/common/EmptyState'
export { default } from '@/components/common/EmptyState'

View File

@@ -37,7 +37,9 @@ export function FlowAnalyticsPanel({ treeId }: FlowAnalyticsPanelProps) {
const [error, setError] = useState(false)
useEffect(() => {
// eslint-disable-next-line react-hooks/set-state-in-effect
setLoading(true)
// eslint-disable-next-line react-hooks/set-state-in-effect
setError(false)
analyticsApi
.getFlowAnalytics(treeId, period)

View File

@@ -29,7 +29,9 @@ export function Modal({ isOpen, onClose, title, children, footer, size = 'md', a
setIsFullScreen(next)
try {
localStorage.setItem('rf-editor-fullscreen', String(next))
} catch {}
} catch {
// localStorage unavailable — ignore
}
}
// Close on Escape key

View File

@@ -40,6 +40,7 @@ export function QuickLaunch({ open, onClose }: QuickLaunchProps) {
useEffect(() => {
if (open) {
// eslint-disable-next-line react-hooks/set-state-in-effect
setSelectedIndex(0)
treesApi.list({ sort_by: 'updated_at' })
.then(trees => setRecentTrees(trees.slice(0, 4)))

View File

@@ -3,6 +3,7 @@ import { Star } from 'lucide-react'
import { Modal } from '@/components/common/Modal'
import { analyticsApi } from '@/api'
import { cn } from '@/lib/utils'
import { markSessionRated } from './csatUtils'
interface CSATModalProps {
isOpen: boolean
@@ -10,26 +11,6 @@ interface CSATModalProps {
sessionId: string
}
const RATED_SESSIONS_KEY = 'rf-rated-sessions'
function getRatedSessions(): string[] {
try {
return JSON.parse(localStorage.getItem(RATED_SESSIONS_KEY) || '[]')
} catch {
return []
}
}
function markSessionRated(sessionId: string) {
const rated = getRatedSessions()
rated.push(sessionId)
localStorage.setItem(RATED_SESSIONS_KEY, JSON.stringify(rated.slice(-100)))
}
export function hasBeenRated(sessionId: string): boolean {
return getRatedSessions().includes(sessionId)
}
export function CSATModal({ isOpen, onClose, sessionId }: CSATModalProps) {
const [rating, setRating] = useState(0)
const [hoveredRating, setHoveredRating] = useState(0)

View File

@@ -0,0 +1,19 @@
const RATED_SESSIONS_KEY = 'rf-rated-sessions'
export function getRatedSessions(): string[] {
try {
return JSON.parse(localStorage.getItem(RATED_SESSIONS_KEY) || '[]')
} catch {
return []
}
}
export function markSessionRated(sessionId: string) {
const rated = getRatedSessions()
rated.push(sessionId)
localStorage.setItem(RATED_SESSIONS_KEY, JSON.stringify(rated.slice(-100)))
}
export function hasBeenRated(sessionId: string): boolean {
return getRatedSessions().includes(sessionId)
}

View File

@@ -21,6 +21,7 @@ const TYPE_CONFIG: Record<Exclude<NodeType, 'answer'>, { icon: typeof HelpCircle
}
function cloneWithoutChildren(node: TreeStructure): TreeStructure {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { children: _children, ...rest } = node
return structuredClone(rest) as TreeStructure
}
@@ -44,8 +45,11 @@ export function NodeEditorPanel({ nodeId, onClose, onSelectType }: NodeEditorPan
// (e.g., answer stub → decision/action/solution via type picker)
useEffect(() => {
if (node) {
// eslint-disable-next-line react-hooks/set-state-in-effect
setDraft(cloneWithoutChildren(node))
// eslint-disable-next-line react-hooks/set-state-in-effect
setIsDirty(false)
// eslint-disable-next-line react-hooks/set-state-in-effect
setShowDeleteConfirm(false)
}
}, [nodeId, node?.type]) // eslint-disable-line react-hooks/exhaustive-deps
@@ -57,6 +61,7 @@ export function NodeEditorPanel({ nodeId, onClose, onSelectType }: NodeEditorPan
const handleSave = useCallback(() => {
if (!draft || !node) return
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { children: _children, ...draftWithoutChildren } = draft
updateNode(nodeId, draftWithoutChildren)

View File

@@ -60,6 +60,7 @@ export function useTreeLayout(): UseTreeLayoutResult {
if (!treeStructure) return { rawNodes: nodes, rawEdges: edges }
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function walk(node: TreeStructure, _parentId?: string | null) {
const isCollapsed = collapsedNodeIds.has(node.id)
const hasChildren = (node.children?.length ?? 0) > 0

View File

@@ -16,7 +16,9 @@ export function useCachedQuota() {
useEffect(() => {
if (cachedResult && Date.now() - cachedResult.timestamp < CACHE_TTL_MS) {
// eslint-disable-next-line react-hooks/set-state-in-effect
setAiEnabled(cachedResult.aiEnabled)
// eslint-disable-next-line react-hooks/set-state-in-effect
setIsLoading(false)
return
}

View File

@@ -1,5 +1,5 @@
import { useSearchParams } from 'react-router-dom'
import { useCallback, useMemo, useRef } from 'react'
import { useCallback, useMemo } from 'react'
type PageSize = number | 'all'
@@ -13,10 +13,6 @@ const DEFAULT_ALLOWED: PageSize[] = [10, 25, 50, 'all']
export function usePaginationParams(options: UsePaginationParamsOptions = {}) {
const { defaultPageSize = 10, allowedPageSizes = DEFAULT_ALLOWED } = options
// Stabilize the array reference to avoid re-render loops
const allowedRef = useRef(allowedPageSizes)
allowedRef.current = allowedPageSizes
const [searchParams, setSearchParams] = useSearchParams()
const page = useMemo(() => {
@@ -27,11 +23,11 @@ export function usePaginationParams(options: UsePaginationParamsOptions = {}) {
const pageSize = useMemo((): PageSize => {
const raw = searchParams.get('size')
if (raw === 'all' && allowedRef.current.includes('all')) return 'all'
if (raw === 'all' && allowedPageSizes.includes('all')) return 'all'
const n = raw ? parseInt(raw, 10) : defaultPageSize
if (Number.isFinite(n) && allowedRef.current.includes(n)) return n
if (Number.isFinite(n) && allowedPageSizes.includes(n)) return n
return defaultPageSize
}, [searchParams, defaultPageSize])
}, [searchParams, defaultPageSize, allowedPageSizes])
const setPage = useCallback(
(newPage: number) => {

View File

@@ -35,6 +35,7 @@ export default function MyAnalyticsPage() {
const [loading, setLoading] = useState(true)
useEffect(() => {
// eslint-disable-next-line react-hooks/set-state-in-effect
setLoading(true)
analyticsApi
.getPersonalAnalytics(period)

View File

@@ -14,7 +14,8 @@ import { Spinner } from '@/components/common/Spinner'
import { cn } from '@/lib/utils'
import { toast } from '@/lib/toast'
import { StepFeedback } from '@/components/session/StepFeedback'
import { CSATModal, hasBeenRated } from '@/components/session/CSATModal'
import { CSATModal } from '@/components/session/CSATModal'
import { hasBeenRated } from '@/components/session/csatUtils'
interface StepState {
notes: string

View File

@@ -37,6 +37,7 @@ export default function TeamAnalyticsPage() {
useEffect(() => {
if (!isAccountOwner && !isSuperAdmin) return
// eslint-disable-next-line react-hooks/set-state-in-effect
setLoading(true)
analyticsApi
.getTeamAnalytics(period)

View File

@@ -15,7 +15,8 @@ import { Spinner } from '@/components/common/Spinner'
import { toast } from '@/lib/toast'
import { Modal } from '@/components/common/Modal'
import { ShareSessionModal } from '@/components/session/ShareSessionModal'
import { CSATModal, hasBeenRated } from '@/components/session/CSATModal'
import { CSATModal } from '@/components/session/CSATModal'
import { hasBeenRated } from '@/components/session/csatUtils'
import { StepFeedback } from '@/components/session/StepFeedback'
import { buildSessionShareUrl, getLatestActiveShareForSession } from '@/lib/sessionShare'