feat: VRL AI conversational chat panel#96
Conversation
Greptile SummaryThis PR replaces the single-prompt VRL AI input with a full conversational chat panel, adding SSE streaming, structured suggestion cards, per-component conversation persistence, and apply/undo semantics. The implementation is well-structured and addresses several issues from the prior review round. What was fixed from previous review threads:
Remaining concerns:
Authorization model: The new REST endpoint ( Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant U as User
participant P as VrlAiPanel
participant H as useVrlAiConversation
participant API as /api/ai/vrl-chat
participant DB as PostgreSQL
participant tRPC as ai.getVrlConversation
U->>P: Open VRL Editor + AI Panel
P->>tRPC: getVrlConversation(pipelineId, componentKey)
tRPC-->>H: loadedConversation (history)
H->>H: Render-time sync → setMessages(history)
U->>P: Type prompt + Enter
P->>H: sendMessage(prompt)
H->>H: Add optimistic user msg (temp-user-*)
H->>API: POST {teamId, prompt, pipelineId, componentKey, conversationId}
API->>DB: findMember (auth check)
API->>DB: verify pipeline → team
API->>DB: findFirst or create AiConversation
API->>DB: create AiMessage (user)
API-->>H: SSE: {conversationId}
H->>H: setConversationId
API-->>H: SSE: {token} × N
H->>H: setStreamingContent (accumulate)
API->>DB: create AiMessage (assistant + suggestions JSON)
API-->>H: SSE: {done: true}
H->>H: Add temp assistant msg to messages
H->>tRPC: fetchQuery (staleTime: 0) → replace temp IDs with real IDs
H->>H: setIsStreaming(false)
U->>P: Click "Apply All"
P->>H: markSuggestionsApplied(messageId, ids)
H->>H: Optimistic: set appliedAt on suggestions
H->>tRPC: markVrlSuggestionsApplied (EDITOR + audit)
tRPC->>DB: update AiMessage suggestions JSON
|
304a515 to
664f8fe
Compare
Summary
componentKeyfield onAiConversationandvrlCodesnapshot onAiMessageChanges
Data Layer
prisma/schema.prisma— addcomponentKeytoAiConversation,vrlCodetoAiMessage, composite indexsrc/server/routers/ai.ts— addgetVrlConversationandmarkVrlSuggestionsAppliedtRPC procedures; filter existinggetConversationto exclude VRL conversationsAPI
src/app/api/ai/vrl-chat/route.ts— new SSE endpoint with auth, team/pipeline validation, conversation persistence, streaming viastreamCompletionsrc/lib/ai/prompts.ts— newbuildVrlChatSystemPrompt()that instructs the AI to return structured JSON{ summary, suggestions }Frontend
src/lib/ai/vrl-suggestion-types.ts— types, parser, status computation, apply logicsrc/hooks/use-vrl-ai-conversation.ts— React hook for state management, SSE streaming, optimistic messages, server syncsrc/components/vrl-editor/vrl-suggestion-card.tsx— suggestion card with checkbox, code preview, badgessrc/components/vrl-editor/vrl-ai-message.tsx— message bubble rendering user/assistant messages with suggestion cardssrc/components/vrl-editor/vrl-ai-panel.tsx— slide-out panel with header, message list, auto-growing inputsrc/components/vrl-editor/vrl-editor.tsx— integrate AI panel, dynamic dialog width, remove old AiInputsrc/components/flow/detail-panel.tsx— threadcomponentKeyprop to all VrlEditor usagessrc/components/vrl-editor/ai-input.tsx(deprecated)Test plan