llmasaservice-ui 0.6.10 → 0.7.0
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/package.json +1 -1
- package/src/AgentPanel.tsx +229 -0
- package/src/stories/AgentPanel.stories.ts +24 -0
package/package.json
CHANGED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import React, { useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
materialDark,
|
|
5
|
+
materialLight,
|
|
6
|
+
} from "react-syntax-highlighter/dist/esm/styles/prism";
|
|
7
|
+
import ChatPanel from "./ChatPanel";
|
|
8
|
+
import { LLMAsAServiceCustomer } from "llmasaservice-client";
|
|
9
|
+
import PrismStyle from "react-syntax-highlighter";
|
|
10
|
+
|
|
11
|
+
export interface ChatPanelProps {
|
|
12
|
+
project_id: string;
|
|
13
|
+
//initialPrompt?: string;
|
|
14
|
+
//initialMessage?: string;
|
|
15
|
+
//title?: string;
|
|
16
|
+
//placeholder?: string;
|
|
17
|
+
//hideInitialPrompt?: boolean;
|
|
18
|
+
customer?: LLMAsAServiceCustomer;
|
|
19
|
+
messages?: { role: "user" | "assistant"; content: string }[];
|
|
20
|
+
data?: { key: string; data: string }[];
|
|
21
|
+
thumbsUpClick?: (callId: string) => void;
|
|
22
|
+
thumbsDownClick?: (callId: string) => void;
|
|
23
|
+
//theme?: "light" | "dark";
|
|
24
|
+
//markdownClass?: string;
|
|
25
|
+
//width?: string;
|
|
26
|
+
//height?: string;
|
|
27
|
+
url?: string;
|
|
28
|
+
//scrollToEnd?: boolean;
|
|
29
|
+
prismStyle?: PrismStyle;
|
|
30
|
+
service?: string | null;
|
|
31
|
+
historyChangedCallback?: (history: {
|
|
32
|
+
[key: string]: { content: string; callId: string };
|
|
33
|
+
}) => void;
|
|
34
|
+
//promptTemplate?: string;
|
|
35
|
+
actions?: {
|
|
36
|
+
pattern: string;
|
|
37
|
+
type?: string;
|
|
38
|
+
markdown?: string;
|
|
39
|
+
callback?: (match: string, groups: any[]) => void;
|
|
40
|
+
clickCode?: string;
|
|
41
|
+
}[];
|
|
42
|
+
//showSaveButton?: boolean;
|
|
43
|
+
//showEmailButton?: boolean;
|
|
44
|
+
//followOnQuestions?: string[];
|
|
45
|
+
//clearFollowOnQuestionsNextPrompt?: boolean;
|
|
46
|
+
followOnPrompt?: string;
|
|
47
|
+
//showPoweredBy?: boolean;
|
|
48
|
+
agent: string;
|
|
49
|
+
conversation?: string | null;
|
|
50
|
+
//showCallToAction?: boolean;
|
|
51
|
+
//callToActionButtonText?: string;
|
|
52
|
+
//callToActionEmailAddress?: string;
|
|
53
|
+
//callToActionEmailSubject?: string;
|
|
54
|
+
//callToActionMustSendEmail?: boolean;
|
|
55
|
+
//ragQueryLimit?: number;
|
|
56
|
+
//ragRankLimit?: number;
|
|
57
|
+
}
|
|
58
|
+
interface ExtraProps extends React.HTMLAttributes<HTMLElement> {
|
|
59
|
+
inline?: boolean;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const AgentPanel: React.FC<ChatPanelProps & ExtraProps> = ({
|
|
63
|
+
project_id,
|
|
64
|
+
//initialPrompt = "",
|
|
65
|
+
//title = "Chat",
|
|
66
|
+
//placeholder = "Type a message",
|
|
67
|
+
//hideInitialPrompt = true,
|
|
68
|
+
customer = {} as LLMAsAServiceCustomer,
|
|
69
|
+
messages = [],
|
|
70
|
+
data = [],
|
|
71
|
+
thumbsUpClick,
|
|
72
|
+
thumbsDownClick,
|
|
73
|
+
//theme = "light",
|
|
74
|
+
//markdownClass = null,
|
|
75
|
+
//width = "300px",
|
|
76
|
+
//height = "100vh",
|
|
77
|
+
url = "https://chat.llmasaservice.io/",
|
|
78
|
+
//scrollToEnd = false,
|
|
79
|
+
//initialMessage = "",
|
|
80
|
+
//prismStyle = theme === "light" ? materialLight : materialDark,
|
|
81
|
+
service = null,
|
|
82
|
+
historyChangedCallback = null,
|
|
83
|
+
//promptTemplate = "",
|
|
84
|
+
actions = [],
|
|
85
|
+
//showSaveButton = true,
|
|
86
|
+
//showEmailButton = true,
|
|
87
|
+
//followOnQuestions = [],
|
|
88
|
+
//clearFollowOnQuestionsNextPrompt = false,
|
|
89
|
+
//followOnPrompt = "",
|
|
90
|
+
//showPoweredBy = true,
|
|
91
|
+
agent,
|
|
92
|
+
conversation = null,
|
|
93
|
+
//showCallToAction = false,
|
|
94
|
+
//callToActionButtonText = "Submit",
|
|
95
|
+
//callToActionEmailAddress = "",
|
|
96
|
+
//callToActionEmailSubject = "Agent CTA submitted",
|
|
97
|
+
//callToActionMustSendEmail = false,
|
|
98
|
+
//ragQueryLimit = 10,
|
|
99
|
+
//ragRankLimit = 5,
|
|
100
|
+
}) => {
|
|
101
|
+
const [followOnPrompt, setFollowOnPrompt] = useState<string>("");
|
|
102
|
+
const [followOnQuestions, setFollowOnQuestions] = useState<string[] | null>(
|
|
103
|
+
null
|
|
104
|
+
);
|
|
105
|
+
const searchParams = new URLSearchParams(location.search);
|
|
106
|
+
//const id = searchParams.get("id") || "";
|
|
107
|
+
const customer_id = searchParams.get("customer_id") || "";
|
|
108
|
+
const customer_email = searchParams.get("customer_email") || "";
|
|
109
|
+
const [agentData, setAgentData] = useState<any>(null);
|
|
110
|
+
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
const fetchAgentData = async () => {
|
|
113
|
+
try {
|
|
114
|
+
const response = await fetch(
|
|
115
|
+
`https://api.llmasaservice.io/agents/${agent}`,
|
|
116
|
+
{
|
|
117
|
+
method: "GET",
|
|
118
|
+
headers: {
|
|
119
|
+
"Content-Type": "application/json",
|
|
120
|
+
},
|
|
121
|
+
}
|
|
122
|
+
);
|
|
123
|
+
const data = await response.json();
|
|
124
|
+
if (data && data.length > 0) {
|
|
125
|
+
//console.log("data", data);
|
|
126
|
+
setAgentData(data[0]);
|
|
127
|
+
}
|
|
128
|
+
} catch (error) {
|
|
129
|
+
console.error("Error fetching agent data:", error);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
if (agent && agent !== "") {
|
|
134
|
+
//console.log("fetching agent data", agent);
|
|
135
|
+
fetchAgentData();
|
|
136
|
+
}
|
|
137
|
+
}, [agent]);
|
|
138
|
+
|
|
139
|
+
// url = "https://chat.llmasaservice.io/";
|
|
140
|
+
// url = "https://chat.llmasaservice.io/dev";
|
|
141
|
+
|
|
142
|
+
const getActionsArraySafely = (actionsString: string) => {
|
|
143
|
+
let actions: any[] = [];
|
|
144
|
+
if (actionsString && actionsString !== "") {
|
|
145
|
+
try {
|
|
146
|
+
actions = JSON.parse(actionsString);
|
|
147
|
+
if (!Array.isArray(actions)) {
|
|
148
|
+
throw new Error("Parsed actions is not an array");
|
|
149
|
+
}
|
|
150
|
+
} catch (error) {
|
|
151
|
+
actions = [];
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return actions;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
return (
|
|
158
|
+
<>
|
|
159
|
+
<ChatPanel
|
|
160
|
+
project_id={agentData?.projectId}
|
|
161
|
+
service={agentData?.groupId || null}
|
|
162
|
+
url={url}
|
|
163
|
+
title={agentData?.displayTitle ?? "Chat Agent"}
|
|
164
|
+
theme={agentData?.displayTheme === "light" ? "light" : "dark"}
|
|
165
|
+
height={agentData?.displayHeight ?? "75vh"}
|
|
166
|
+
width={agentData?.displayWidth ?? "100%"}
|
|
167
|
+
promptTemplate={agentData?.displayPromptTemplate ?? "{{prompt}}"}
|
|
168
|
+
initialMessage={
|
|
169
|
+
agentData?.displayStartMessageOrPrompt === "message"
|
|
170
|
+
? agentData?.displayInitialMessageOrPrompt ?? ""
|
|
171
|
+
: undefined
|
|
172
|
+
}
|
|
173
|
+
initialPrompt={
|
|
174
|
+
agentData?.displayStartMessageOrPrompt === "prompt"
|
|
175
|
+
? agentData?.displayInitialMessageOrPrompt ?? ""
|
|
176
|
+
: undefined
|
|
177
|
+
}
|
|
178
|
+
followOnQuestions={
|
|
179
|
+
followOnQuestions
|
|
180
|
+
? followOnQuestions
|
|
181
|
+
: agentData?.displayFollowOnPrompts?.split("|") ?? []
|
|
182
|
+
}
|
|
183
|
+
historyChangedCallback={(history) => {
|
|
184
|
+
if (history) {
|
|
185
|
+
setFollowOnPrompt("");
|
|
186
|
+
}
|
|
187
|
+
}}
|
|
188
|
+
prismStyle={
|
|
189
|
+
(agentData?.displayTheme === "light"
|
|
190
|
+
? materialLight
|
|
191
|
+
: materialDark) as any
|
|
192
|
+
}
|
|
193
|
+
actions={[
|
|
194
|
+
...actions,
|
|
195
|
+
...getActionsArraySafely(agentData?.displayActions),
|
|
196
|
+
]}
|
|
197
|
+
followOnPrompt={followOnPrompt}
|
|
198
|
+
agent={agent}
|
|
199
|
+
placeholder={agentData?.displayPlaceholder ?? "Type a message"}
|
|
200
|
+
hideInitialPrompt={agentData?.displayHideInitialPrompt ?? true}
|
|
201
|
+
data={[...data, { key: "data", data: agentData?.data }]}
|
|
202
|
+
showEmailButton={agentData?.displayShowEmailButton ?? true}
|
|
203
|
+
showSaveButton={agentData?.displayShowSaveButton ?? true}
|
|
204
|
+
showCallToAction={agentData?.displayShowCallToAction ?? false}
|
|
205
|
+
callToActionButtonText={
|
|
206
|
+
agentData?.displayCallToActionButtonText ?? "Submit"
|
|
207
|
+
}
|
|
208
|
+
callToActionEmailAddress={
|
|
209
|
+
agentData?.displayCallToActionEmailAddress ?? ""
|
|
210
|
+
}
|
|
211
|
+
callToActionEmailSubject={
|
|
212
|
+
agentData?.displayCallToActionEmailSubject ?? "Agent CTA Submitted"
|
|
213
|
+
}
|
|
214
|
+
callToActionMustSendEmail={
|
|
215
|
+
agentData?.displayCallToActionMustSendEmail ?? false
|
|
216
|
+
}
|
|
217
|
+
customer={{
|
|
218
|
+
customer_id: customer_id ?? "default",
|
|
219
|
+
customer_user_email: customer_email ?? "",
|
|
220
|
+
}}
|
|
221
|
+
scrollToEnd={agentData?.displayScrollToEnd ?? false}
|
|
222
|
+
ragQueryLimit={agentData?.ragQueryLimit ?? 10}
|
|
223
|
+
ragRankLimit={agentData?.ragRankLimit ?? 5}
|
|
224
|
+
/>
|
|
225
|
+
</>
|
|
226
|
+
);
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
export default AgentPanel;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
|
+
import { LLMAsAServiceCustomer } from "llmasaservice-client";
|
|
3
|
+
import AgentPanel from "../AgentPanel";
|
|
4
|
+
|
|
5
|
+
const meta = {
|
|
6
|
+
title: "AgentPanel",
|
|
7
|
+
component: AgentPanel,
|
|
8
|
+
parameters: {
|
|
9
|
+
layout: "centered",
|
|
10
|
+
},
|
|
11
|
+
tags: ["autodocs"],
|
|
12
|
+
} satisfies Meta<typeof AgentPanel>;
|
|
13
|
+
|
|
14
|
+
export default meta;
|
|
15
|
+
type Story = StoryObj<typeof meta>;
|
|
16
|
+
|
|
17
|
+
export const AgentPanelStory: Story = {
|
|
18
|
+
args: {
|
|
19
|
+
title: "Test Title",
|
|
20
|
+
project_id: "[get this from your control panel]",
|
|
21
|
+
agent: "[your agent id]"
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|