diff --git a/ui/src/components/IssueChatThread.tsx b/ui/src/components/IssueChatThread.tsx index 760e8eae..32100637 100644 --- a/ui/src/components/IssueChatThread.tsx +++ b/ui/src/components/IssueChatThread.tsx @@ -7,7 +7,7 @@ import { useAui, useMessage, } from "@assistant-ui/react"; -import { useEffect, useMemo, useRef, useState, type ChangeEvent } from "react"; +import { createContext, useContext, useEffect, useMemo, useRef, useState, type ChangeEvent } from "react"; import { Link, useLocation } from "@/lib/router"; import type { Agent, @@ -45,6 +45,27 @@ import { timeAgo } from "../lib/timeAgo"; import { cn, formatDateTime } from "../lib/utils"; import { ArrowRight, Check, ChevronDown, Copy, Loader2, MoreHorizontal, Paperclip } from "lucide-react"; +interface IssueChatMessageContext { + feedbackVoteByTargetId: Map; + feedbackDataSharingPreference: FeedbackDataSharingPreference; + feedbackTermsUrl: string | null; + agentMap?: Map; + currentUserId?: string | null; + onVote?: ( + commentId: string, + vote: FeedbackVoteValue, + options?: { allowSharing?: boolean; reason?: string }, + ) => Promise; + onInterruptQueued?: (runId: string) => Promise; + interruptingQueuedRunId?: string | null; +} + +const IssueChatCtx = createContext({ + feedbackVoteByTargetId: new Map(), + feedbackDataSharingPreference: "prompt", + feedbackTermsUrl: null, +}); + interface CommentReassignment { assigneeAgentId: string | null; assigneeUserId: string | null; @@ -317,13 +338,8 @@ function IssueChatToolPart({ ); } -function IssueChatUserMessage({ - onInterruptQueued, - interruptingQueuedRunId, -}: { - onInterruptQueued?: (runId: string) => Promise; - interruptingQueuedRunId?: string | null; -}) { +function IssueChatUserMessage() { + const { onInterruptQueued, interruptingQueuedRunId } = useContext(IssueChatCtx); const message = useMessage(); const custom = message.metadata.custom as Record; const anchorId = typeof custom.anchorId === "string" ? custom.anchorId : undefined; @@ -383,25 +399,15 @@ function IssueChatUserMessage({ ); } -function IssueChatAssistantMessage({ - feedbackVoteByTargetId, - feedbackDataSharingPreference, - feedbackTermsUrl, - onVote, - agentMap, - currentUserId, -}: { - feedbackVoteByTargetId: Map; - feedbackDataSharingPreference?: FeedbackDataSharingPreference; - feedbackTermsUrl?: string | null; - agentMap?: Map; - currentUserId?: string | null; - onVote?: ( - commentId: string, - vote: FeedbackVoteValue, - options?: { allowSharing?: boolean; reason?: string }, - ) => Promise; -}) { +function IssueChatAssistantMessage() { + const { + feedbackVoteByTargetId, + feedbackDataSharingPreference, + feedbackTermsUrl, + onVote, + agentMap, + currentUserId, + } = useContext(IssueChatCtx); const message = useMessage(); const custom = message.metadata.custom as Record; const anchorId = typeof custom.anchorId === "string" ? custom.anchorId : undefined; @@ -519,13 +525,8 @@ function IssueChatAssistantMessage({ ); } -function IssueChatSystemMessage({ - agentMap, - currentUserId, -}: { - agentMap?: Map; - currentUserId?: string | null; -}) { +function IssueChatSystemMessage() { + const { agentMap, currentUserId } = useContext(IssueChatCtx); const message = useMessage(); const custom = message.metadata.custom as Record; const anchorId = typeof custom.anchorId === "string" ? custom.anchorId : undefined; @@ -979,40 +980,41 @@ export function IssueChatThread({ bottomAnchorRef.current?.scrollIntoView({ behavior: "smooth", block: "end" }); } - const components = useMemo( + const chatCtx = useMemo( () => ({ - UserMessage: () => ( - - ), - AssistantMessage: () => ( - - ), - SystemMessage: () => , - }), - [ - agentMap, - currentUserId, feedbackVoteByTargetId, feedbackDataSharingPreference, feedbackTermsUrl, + agentMap, + currentUserId, + onVote, + onInterruptQueued, + interruptingQueuedRunId, + }), + [ + feedbackVoteByTargetId, + feedbackDataSharingPreference, + feedbackTermsUrl, + agentMap, + currentUserId, onVote, onInterruptQueued, interruptingQueuedRunId, ], ); + const components = useMemo( + () => ({ + UserMessage: IssueChatUserMessage, + AssistantMessage: IssueChatAssistantMessage, + SystemMessage: IssueChatSystemMessage, + }), + [], + ); + return ( +
- +