PluginProbe
Extendify / 3.2.2
Extendify v3.2.2
3.2.2 3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 All 128 releases
extendify / src / Agent / components / messages / AgentMessage.jsx

AgentMessage.jsx in Extendify 3.2.2, at src/Agent/components/messages/AgentMessage.jsx

96 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { recordAgentActivity } from '@agent/api';
2 import { AnimateChunks } from '@agent/components/messages/AnimateChunks';
3 import { ReplyOptions } from '@agent/components/ReplyOptions';
4 import pageTours from '@agent/lib/page-tours';
5 import tours from '@agent/tours/tours';
6 import { SingleTour } from '@agent/workflows/misc/components/ToursList';
7 import { decodeEntities } from '@wordpress/html-entities';
8 import { __ } from '@wordpress/i18n';
9 import ReactMarkdown from 'react-markdown';
10
11 const availableTours = Object.values(tours);
12 const adminPages = window.extAgentData.agentContext?.availableAdminPages || [];
13 const agentSuggestions =
14 Object.fromEntries(
15 adminPages.map((page) => [
16 page,
17 {
18 label: __('Take me there', 'extendify-local'),
19 tour:
20 availableTours.find((tour) => tour.id === pageTours[page]) ?? null,
21 },
22 ]),
23 ) || {};
24
25 export const AgentMessage = ({ message, animate, active }) => {
26 const {
27 content,
28 role,
29 pageSuggestion,
30 qaSuggestions,
31 sessionId = 'not-set',
32 } = message.details;
33 const containsCodeBlock = /```[\s\S]*?```/.test(content);
34 const blocks = containsCodeBlock
35 ? [decodeEntities(content ?? '')]
36 : decodeEntities(content ?? '').split(/\n{2,}/);
37
38 // Check if the pageSuggestion matches any key in agentSuggestions
39 const agentSuggestionKey = Object.keys(agentSuggestions).find((k) =>
40 pageSuggestion?.startsWith(k),
41 );
42 const agentSuggestion = agentSuggestions[agentSuggestionKey] || {};
43
44 return (
45 <div
46 data-agent-message-role={role}
47 className="flex w-full items-start px-2.5 py-2"
48 >
49 <div className="flex min-w-0 flex-1 flex-col gap-4">
50 <div className="extendify-agent-markdown w-full">
51 {animate ? (
52 <AnimateChunks words={blocks} delay={0.1} duration={0.35} />
53 ) : (
54 <ReactMarkdown>{decodeEntities(content)}</ReactMarkdown>
55 )}
56 </div>
57 {agentSuggestion?.label ? (
58 <div>
59 <a
60 onClick={() => {
61 recordAgentActivity({
62 sessionId,
63 action: 'take_me_there_click',
64 value: { pageSuggestion },
65 });
66 }}
67 href={`${window.extSharedData.adminUrl}${pageSuggestion}`}
68 className="rounded-sm border border-design-main bg-design-main p-2 text-sm text-white no-underline hover:opacity-90"
69 >
70 {agentSuggestion.label}
71 </a>
72 </div>
73 ) : null}
74 {agentSuggestion?.tour && (
75 <div>
76 <SingleTour tour={agentSuggestion.tour} />
77 </div>
78 )}
79 {/* An empty array still renders — it's the agent asking with no drafts. */}
80 {active && Array.isArray(qaSuggestions) ? (
81 <ReplyOptions
82 options={qaSuggestions}
83 onSubmit={(message) =>
84 window.dispatchEvent(
85 new CustomEvent('extendify-agent:chat-submit', {
86 detail: { message },
87 }),
88 )
89 }
90 />
91 ) : null}
92 </div>
93 </div>
94 );
95 };
96