@hef2024/llmasaservice-ui 0.16.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +162 -0
- package/dist/index.css +3239 -0
- package/dist/index.d.mts +521 -0
- package/dist/index.d.ts +521 -0
- package/dist/index.js +5885 -0
- package/dist/index.mjs +5851 -0
- package/index.ts +28 -0
- package/package.json +70 -0
- package/src/AIAgentPanel.css +1354 -0
- package/src/AIAgentPanel.tsx +1883 -0
- package/src/AIChatPanel.css +1618 -0
- package/src/AIChatPanel.tsx +1725 -0
- package/src/AgentPanel.tsx +323 -0
- package/src/ChatPanel.css +1093 -0
- package/src/ChatPanel.tsx +3583 -0
- package/src/ChatStatus.tsx +40 -0
- package/src/EmailModal.tsx +56 -0
- package/src/ToolInfoModal.tsx +49 -0
- package/src/components/ui/Button.tsx +57 -0
- package/src/components/ui/Dialog.tsx +153 -0
- package/src/components/ui/Input.tsx +33 -0
- package/src/components/ui/ScrollArea.tsx +29 -0
- package/src/components/ui/Select.tsx +156 -0
- package/src/components/ui/Tooltip.tsx +73 -0
- package/src/components/ui/index.ts +20 -0
- package/src/hooks/useAgentRegistry.ts +349 -0
- package/src/hooks/useConversationStore.ts +313 -0
- package/src/mcpClient.ts +107 -0
- package/tsconfig.json +108 -0
- package/types/declarations.d.ts +22 -0
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import React, { useEffect, useState } from "react";
|
|
2
|
+
import materialDark from "react-syntax-highlighter/dist/esm/styles/prism/material-dark.js";
|
|
3
|
+
import materialLight from "react-syntax-highlighter/dist/esm/styles/prism/material-light.js";
|
|
4
|
+
import ChatPanel from "./ChatPanel";
|
|
5
|
+
import { LLMAsAServiceCustomer } from "llmasaservice-client";
|
|
6
|
+
import PrismStyle from "react-syntax-highlighter";
|
|
7
|
+
|
|
8
|
+
export interface AgentPanelProps {
|
|
9
|
+
//project_id: string;
|
|
10
|
+
//initialPrompt?: string;
|
|
11
|
+
//initialMessage?: string;
|
|
12
|
+
//title?: string;
|
|
13
|
+
//placeholder?: string;
|
|
14
|
+
//hideInitialPrompt?: boolean;
|
|
15
|
+
customer?: LLMAsAServiceCustomer;
|
|
16
|
+
messages?: { role: "user" | "assistant"; content: string }[];
|
|
17
|
+
data?: { key: string; data: string }[];
|
|
18
|
+
thumbsUpClick?: (callId: string) => void;
|
|
19
|
+
thumbsDownClick?: (callId: string) => void;
|
|
20
|
+
theme?: "light" | "dark";
|
|
21
|
+
markdownClass?: string;
|
|
22
|
+
width?: string;
|
|
23
|
+
height?: string;
|
|
24
|
+
url?: string;
|
|
25
|
+
//scrollToEnd?: boolean;
|
|
26
|
+
prismStyle?: PrismStyle;
|
|
27
|
+
service?: string | null;
|
|
28
|
+
historyChangedCallback?: (history: {
|
|
29
|
+
[key: string]: { content: string; callId: string };
|
|
30
|
+
}) => void;
|
|
31
|
+
responseCompleteCallback?: (
|
|
32
|
+
callId: string,
|
|
33
|
+
prompt: string,
|
|
34
|
+
response: string
|
|
35
|
+
) => void;
|
|
36
|
+
//promptTemplate?: string;
|
|
37
|
+
actions?: {
|
|
38
|
+
pattern: string;
|
|
39
|
+
type?: string;
|
|
40
|
+
markdown?: string;
|
|
41
|
+
callback?: (match: string, groups: any[]) => void;
|
|
42
|
+
clickCode?: string;
|
|
43
|
+
style?: string;
|
|
44
|
+
}[];
|
|
45
|
+
//showSaveButton?: boolean;
|
|
46
|
+
//showEmailButton?: boolean;
|
|
47
|
+
followOnQuestions?: string[];
|
|
48
|
+
clearFollowOnQuestionsNextPrompt?: boolean;
|
|
49
|
+
followOnPrompt?: string;
|
|
50
|
+
showPoweredBy?: boolean;
|
|
51
|
+
agent: string;
|
|
52
|
+
conversation?: string | null;
|
|
53
|
+
//showCallToAction?: boolean;
|
|
54
|
+
//callToActionButtonText?: string;
|
|
55
|
+
//callToActionEmailAddress?: string;
|
|
56
|
+
//callToActionEmailSubject?: string;
|
|
57
|
+
//ragQueryLimit?: number;
|
|
58
|
+
//ragRankLimit?: number;
|
|
59
|
+
initialHistory?: { [key: string]: { content: string; callId: string } };
|
|
60
|
+
hideRagContextInPrompt?: boolean;
|
|
61
|
+
createConversationOnFirstChat?: boolean;
|
|
62
|
+
customerEmailCaptureMode?: "HIDE" | "OPTIONAL" | "REQUIRED";
|
|
63
|
+
customerEmailCapturePlaceholder?: string;
|
|
64
|
+
}
|
|
65
|
+
interface ExtraProps extends React.HTMLAttributes<HTMLElement> {
|
|
66
|
+
inline?: boolean;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const AgentPanel: React.FC<AgentPanelProps & ExtraProps> = ({
|
|
70
|
+
//project_id,
|
|
71
|
+
//initialPrompt = "",
|
|
72
|
+
//title = "Chat",
|
|
73
|
+
//placeholder = "Type a message",
|
|
74
|
+
//hideInitialPrompt = true,
|
|
75
|
+
customer = {} as LLMAsAServiceCustomer,
|
|
76
|
+
messages = [],
|
|
77
|
+
data = [],
|
|
78
|
+
thumbsUpClick,
|
|
79
|
+
thumbsDownClick,
|
|
80
|
+
theme,
|
|
81
|
+
markdownClass = null,
|
|
82
|
+
width,
|
|
83
|
+
height,
|
|
84
|
+
url = "https://chat.llmasaservice.io",
|
|
85
|
+
//url = "https://chat.llmasaservice.io/dev",
|
|
86
|
+
//scrollToEnd = false,
|
|
87
|
+
//initialMessage = "",
|
|
88
|
+
prismStyle = null,
|
|
89
|
+
service = null,
|
|
90
|
+
historyChangedCallback = undefined,
|
|
91
|
+
responseCompleteCallback = undefined,
|
|
92
|
+
//promptTemplate = "",
|
|
93
|
+
actions = [],
|
|
94
|
+
//showSaveButton = true,
|
|
95
|
+
//showEmailButton = true,
|
|
96
|
+
followOnQuestions = [],
|
|
97
|
+
clearFollowOnQuestionsNextPrompt = false,
|
|
98
|
+
followOnPrompt = "",
|
|
99
|
+
showPoweredBy = true,
|
|
100
|
+
agent,
|
|
101
|
+
conversation = null,
|
|
102
|
+
//showCallToAction = false,
|
|
103
|
+
//callToActionButtonText = "Submit",
|
|
104
|
+
//callToActionEmailAddress = "",
|
|
105
|
+
//callToActionEmailSubject = "Agent CTA submitted",
|
|
106
|
+
//ragQueryLimit = 10,
|
|
107
|
+
//ragRankLimit = 5,
|
|
108
|
+
initialHistory = {},
|
|
109
|
+
hideRagContextInPrompt = true,
|
|
110
|
+
}) => {
|
|
111
|
+
const searchParams = new URLSearchParams(location.search);
|
|
112
|
+
const customer_id = searchParams.get("customer_id") || null;
|
|
113
|
+
const customer_email = searchParams.get("customer_email") || null;
|
|
114
|
+
const customer_name = searchParams.get("customer_name") || null;
|
|
115
|
+
const customer_user_id = searchParams.get("customer_user_id") || null;
|
|
116
|
+
const [agentData, setAgentData] = useState<any>(null);
|
|
117
|
+
const [mcpData, setMCPData] = useState<any>(null);
|
|
118
|
+
|
|
119
|
+
// Create customer object only with values that exist
|
|
120
|
+
const createCustomerObject = (): LLMAsAServiceCustomer | undefined => {
|
|
121
|
+
const customerData: Partial<LLMAsAServiceCustomer> = {};
|
|
122
|
+
|
|
123
|
+
// Get customer_id from props or URL
|
|
124
|
+
const finalCustomerId = customer?.customer_id || customer_id;
|
|
125
|
+
if (finalCustomerId) {
|
|
126
|
+
customerData.customer_id = finalCustomerId;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Get customer_user_email from props or URL
|
|
130
|
+
const finalCustomerEmail = customer?.customer_user_email || customer_email;
|
|
131
|
+
if (finalCustomerEmail) {
|
|
132
|
+
customerData.customer_user_email = finalCustomerEmail;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Get customer_user_name from props or URL
|
|
136
|
+
const finalCustomerUserName = customer?.customer_user_name || customer_name;
|
|
137
|
+
if (finalCustomerUserName) {
|
|
138
|
+
customerData.customer_user_name = finalCustomerUserName;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Get customer_name from props or URL
|
|
142
|
+
const finalCustomerName = customer?.customer_name || customer_name;
|
|
143
|
+
if (finalCustomerName) {
|
|
144
|
+
customerData.customer_name = finalCustomerName;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Get customer_user_id from props or URL
|
|
148
|
+
const finalCustomerUserId = customer?.customer_user_id || customer_user_id;
|
|
149
|
+
if (finalCustomerUserId) {
|
|
150
|
+
customerData.customer_user_id = finalCustomerUserId;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Only return customer object if it has at least one property
|
|
154
|
+
return Object.keys(customerData).length > 0
|
|
155
|
+
? (customerData as LLMAsAServiceCustomer)
|
|
156
|
+
: undefined;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
useEffect(() => {
|
|
160
|
+
const fetchAgentData = async () => {
|
|
161
|
+
try {
|
|
162
|
+
const fetchUrl = url.endsWith("dev")
|
|
163
|
+
? `https://8ftw8droff.execute-api.us-east-1.amazonaws.com/dev/agents/${agent}`
|
|
164
|
+
: `https://api.llmasaservice.io/agents/${agent}`;
|
|
165
|
+
|
|
166
|
+
const response = await fetch(fetchUrl, {
|
|
167
|
+
method: "GET",
|
|
168
|
+
headers: {
|
|
169
|
+
"Content-Type": "application/json",
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
const data = await response.json();
|
|
174
|
+
if (data && data.length > 0) {
|
|
175
|
+
setAgentData(data[0]);
|
|
176
|
+
|
|
177
|
+
// get MCP servers
|
|
178
|
+
const response = await fetch(fetchUrl + "/mcp", {
|
|
179
|
+
method: "GET",
|
|
180
|
+
headers: {
|
|
181
|
+
"Content-Type": "application/json",
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
const mcpData = await response.json();
|
|
186
|
+
if (mcpData && mcpData.length > 0) {
|
|
187
|
+
// only active and NOT SERVER side mcp servers
|
|
188
|
+
setMCPData(
|
|
189
|
+
mcpData.filter(
|
|
190
|
+
(mcp: any) =>
|
|
191
|
+
mcp.status === "active" && mcp.executionMode !== "SERVER"
|
|
192
|
+
)
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
} catch (error) {
|
|
197
|
+
console.error("Error fetching agent data:", error);
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
if (agent && agent !== "") {
|
|
202
|
+
fetchAgentData();
|
|
203
|
+
}
|
|
204
|
+
}, [agent, url]);
|
|
205
|
+
|
|
206
|
+
const getActionsArraySafely = (actionsString: string) => {
|
|
207
|
+
console.log("AgentPanel getActionsArraySafely called with:", {
|
|
208
|
+
actionsString,
|
|
209
|
+
type: typeof actionsString
|
|
210
|
+
});
|
|
211
|
+
let actions: any[] = [];
|
|
212
|
+
if (actionsString && actionsString !== "") {
|
|
213
|
+
try {
|
|
214
|
+
actions = JSON.parse(actionsString);
|
|
215
|
+
if (!Array.isArray(actions)) {
|
|
216
|
+
throw new Error("Parsed actions is not an array");
|
|
217
|
+
}
|
|
218
|
+
console.log("AgentPanel parsed actions:", actions);
|
|
219
|
+
} catch (error) {
|
|
220
|
+
console.log("AgentPanel actions parsing error:", error);
|
|
221
|
+
actions = [];
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return actions;
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
return (
|
|
228
|
+
<>
|
|
229
|
+
{agentData && (
|
|
230
|
+
<ChatPanel
|
|
231
|
+
project_id={agentData?.projectId}
|
|
232
|
+
service={
|
|
233
|
+
service && service !== "" ? service : agentData?.groupId || null
|
|
234
|
+
}
|
|
235
|
+
url={url}
|
|
236
|
+
title={agentData?.displayTitle ?? ""}
|
|
237
|
+
theme={
|
|
238
|
+
theme
|
|
239
|
+
? theme
|
|
240
|
+
: agentData?.displayTheme === "light"
|
|
241
|
+
? "light"
|
|
242
|
+
: "dark"
|
|
243
|
+
}
|
|
244
|
+
markdownClass={markdownClass ?? undefined}
|
|
245
|
+
cssUrl={agentData?.cssUrl ?? ""}
|
|
246
|
+
height={height ? height : agentData?.displayHeight ?? "100vh"}
|
|
247
|
+
width={width ? width : agentData?.displayWidth ?? "100%"}
|
|
248
|
+
promptTemplate={agentData?.displayPromptTemplate ?? "{{prompt}}"}
|
|
249
|
+
initialMessage={
|
|
250
|
+
agentData?.displayStartMessageOrPrompt === "message"
|
|
251
|
+
? agentData?.displayInitialMessageOrPrompt ?? ""
|
|
252
|
+
: undefined
|
|
253
|
+
}
|
|
254
|
+
initialPrompt={
|
|
255
|
+
agentData?.displayStartMessageOrPrompt === "prompt"
|
|
256
|
+
? agentData?.displayInitialMessageOrPrompt ?? ""
|
|
257
|
+
: undefined
|
|
258
|
+
}
|
|
259
|
+
followOnQuestions={
|
|
260
|
+
followOnQuestions && followOnQuestions.length > 0
|
|
261
|
+
? followOnQuestions
|
|
262
|
+
: agentData?.displayFollowOnPrompts?.split("|") ?? []
|
|
263
|
+
}
|
|
264
|
+
clearFollowOnQuestionsNextPrompt={clearFollowOnQuestionsNextPrompt}
|
|
265
|
+
historyChangedCallback={historyChangedCallback}
|
|
266
|
+
responseCompleteCallback={responseCompleteCallback}
|
|
267
|
+
prismStyle={
|
|
268
|
+
prismStyle ??
|
|
269
|
+
(theme
|
|
270
|
+
? ((theme === "light" ? materialLight : materialDark) as any)
|
|
271
|
+
: ((agentData?.displayTheme === "light"
|
|
272
|
+
? materialLight
|
|
273
|
+
: materialDark) as any))
|
|
274
|
+
}
|
|
275
|
+
actions={[
|
|
276
|
+
...actions,
|
|
277
|
+
...getActionsArraySafely(agentData?.displayActions),
|
|
278
|
+
].map((action, index) => {
|
|
279
|
+
console.log(`AgentPanel action ${index}:`, action);
|
|
280
|
+
return action;
|
|
281
|
+
})}
|
|
282
|
+
followOnPrompt={followOnPrompt}
|
|
283
|
+
agent={agent}
|
|
284
|
+
placeholder={agentData?.displayPlaceholder ?? "Type a message"}
|
|
285
|
+
hideInitialPrompt={agentData?.displayHideInitialPrompt ?? true}
|
|
286
|
+
data={[...data, { key: "data", data: agentData?.data }]}
|
|
287
|
+
showEmailButton={agentData?.displayShowEmailButton ?? true}
|
|
288
|
+
showSaveButton={agentData?.displayShowSaveButton ?? true}
|
|
289
|
+
showCallToAction={agentData?.displayShowCallToAction ?? false}
|
|
290
|
+
callToActionButtonText={
|
|
291
|
+
agentData?.displayCallToActionButtonText ?? "Submit"
|
|
292
|
+
}
|
|
293
|
+
callToActionEmailAddress={
|
|
294
|
+
agentData?.displayCallToActionEmailAddress ?? ""
|
|
295
|
+
}
|
|
296
|
+
callToActionEmailSubject={
|
|
297
|
+
agentData?.displayCallToActionEmailSubject ?? "Agent CTA Submitted"
|
|
298
|
+
}
|
|
299
|
+
{...(createCustomerObject() && { customer: createCustomerObject() })}
|
|
300
|
+
scrollToEnd={agentData?.displayScrollToEnd ?? false}
|
|
301
|
+
showPoweredBy={showPoweredBy}
|
|
302
|
+
messages={messages}
|
|
303
|
+
conversation={conversation}
|
|
304
|
+
initialHistory={initialHistory}
|
|
305
|
+
hideRagContextInPrompt={hideRagContextInPrompt}
|
|
306
|
+
createConversationOnFirstChat={
|
|
307
|
+
agentData?.createConversationOnFirstChat ?? true
|
|
308
|
+
}
|
|
309
|
+
customerEmailCaptureMode={
|
|
310
|
+
agentData?.customerEmailCaptureMode ?? "HIDE"
|
|
311
|
+
}
|
|
312
|
+
customerEmailCapturePlaceholder={
|
|
313
|
+
agentData?.customerEmailCapturePlaceholder ??
|
|
314
|
+
"Please enter your email..."
|
|
315
|
+
}
|
|
316
|
+
mcpServers={mcpData}
|
|
317
|
+
/>
|
|
318
|
+
)}
|
|
319
|
+
</>
|
|
320
|
+
);
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
export default AgentPanel;
|