aizek-chatbot 1.0.8 → 1.0.9
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/dist/index.cjs +164 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +164 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/dist/index.mjs
CHANGED
|
@@ -97,7 +97,7 @@ var Button = React.forwardRef(
|
|
|
97
97
|
);
|
|
98
98
|
Button.displayName = "Button";
|
|
99
99
|
var useChatbot = (options = {}) => {
|
|
100
|
-
const { mcpUrl, apiKey } = options;
|
|
100
|
+
const { mcpUrl, apiKey, config } = options;
|
|
101
101
|
const client = new OpenAI({ apiKey, dangerouslyAllowBrowser: true });
|
|
102
102
|
const [responseId, setResponseId] = useState(null);
|
|
103
103
|
const [messages, setMessages] = useState([]);
|
|
@@ -115,10 +115,168 @@ var useChatbot = (options = {}) => {
|
|
|
115
115
|
setMessages((prev) => [...prev, newMessage]);
|
|
116
116
|
return newMessage;
|
|
117
117
|
};
|
|
118
|
+
const getHtmlUiInstructions = (config2) => {
|
|
119
|
+
const headerColor = config2?.headerBackground || "#f5f5f5";
|
|
120
|
+
const accentColor = config2?.buttonBackground || "#007bff";
|
|
121
|
+
const companyName = config2?.companyName || "AI Assistant";
|
|
122
|
+
const companyLogo = config2?.companyLogo || "\u{1F916}";
|
|
123
|
+
return `
|
|
124
|
+
You are a helpful assistant that creates UI using ONLY HTML tags.
|
|
125
|
+
|
|
126
|
+
Your task:
|
|
127
|
+
- Read the user message and respond.
|
|
128
|
+
- Render your response as a small HTML layout (card OR table OR mini-table).
|
|
129
|
+
- Use inline CSS styles.
|
|
130
|
+
- Use a clean, light (white-based) theme.
|
|
131
|
+
- Use branding and colors from options.config.
|
|
132
|
+
- Return ONLY raw HTML (no markdown, no backticks, no JSON, no explanations).
|
|
133
|
+
|
|
134
|
+
====================
|
|
135
|
+
THEME & BRANDING (from options.config)
|
|
136
|
+
====================
|
|
137
|
+
The chat widget configuration provides:
|
|
138
|
+
|
|
139
|
+
- Header Background Color: ${headerColor}
|
|
140
|
+
- Button / Accent Color: ${accentColor}
|
|
141
|
+
- Company Name: ${companyName}
|
|
142
|
+
- Company Logo: ${companyLogo}
|
|
143
|
+
|
|
144
|
+
How to use these:
|
|
145
|
+
- Use Header Background Color mainly for top headers, title strips, or main highlight areas.
|
|
146
|
+
- Use Button / Accent Color for important accents: borders, highlights, small badges, table headers, key text highlights, links, etc.
|
|
147
|
+
- Use a white or very light background for main surfaces.
|
|
148
|
+
- Text color should generally be dark (#111\u2013#333) for readability.
|
|
149
|
+
|
|
150
|
+
Do NOT create real interactive buttons. You can visually style elements using the accent color, but you must NOT use <button>.
|
|
151
|
+
|
|
152
|
+
====================
|
|
153
|
+
ALLOWED / FORBIDDEN TAGS
|
|
154
|
+
====================
|
|
155
|
+
You may use ANY NON-INTERACTIVE HTML element, for example:
|
|
156
|
+
- Text and headings:
|
|
157
|
+
<h1>, <h2>, <h3>, <h4>, <h5>, <h6>,
|
|
158
|
+
<p>, <span>, <strong>, <em>, <small>, <blockquote>, <code>, <pre>
|
|
159
|
+
- Layout:
|
|
160
|
+
<div>, <section>, <article>, <header>, <footer>
|
|
161
|
+
- Lists:
|
|
162
|
+
<ul>, <ol>, <li>
|
|
163
|
+
- Tables:
|
|
164
|
+
<table>, <thead>, <tbody>, <tr>, <th>, <td>
|
|
165
|
+
- Media:
|
|
166
|
+
<img>, <figure>, <figcaption>
|
|
167
|
+
- Links (non-interactive navigation style only):
|
|
168
|
+
<a>
|
|
169
|
+
|
|
170
|
+
FORBIDDEN (NEVER USE):
|
|
171
|
+
- <button>, <input>, <textarea>, <select>, <option>, <form>, <label>
|
|
172
|
+
- <details>, <summary>, <dialog>
|
|
173
|
+
- <video> or <audio> with controls for user interaction
|
|
174
|
+
- Any inline event handlers like onclick, onmouseover, etc.
|
|
175
|
+
- <script> or any JavaScript code.
|
|
176
|
+
|
|
177
|
+
====================
|
|
178
|
+
LAYOUT TYPE RULES
|
|
179
|
+
====================
|
|
180
|
+
You have exactly THREE layout types you can use:
|
|
181
|
+
|
|
182
|
+
1) CARD
|
|
183
|
+
2) TABLE
|
|
184
|
+
3) MINI TABLE
|
|
185
|
+
|
|
186
|
+
For EACH response:
|
|
187
|
+
- You MUST choose exactly ONE of these layout types.
|
|
188
|
+
- You MUST NOT mix layout types in the same response.
|
|
189
|
+
(Do NOT render card + table together, or table + mini-table together.)
|
|
190
|
+
|
|
191
|
+
Which layout to choose:
|
|
192
|
+
- CARD (DEFAULT):
|
|
193
|
+
- Use this for normal answers, explanations, descriptions, welcome messages,
|
|
194
|
+
and any content that is mostly free text.
|
|
195
|
+
- TABLE:
|
|
196
|
+
- Use this ONLY when the content is clearly structured with multiple columns
|
|
197
|
+
(for example: comparisons, lists of items with several attributes).
|
|
198
|
+
- MINI TABLE:
|
|
199
|
+
- Use this for small, compact key-value style data
|
|
200
|
+
(for example: a few fields like "Token", "Price", "Network"),
|
|
201
|
+
or when a full table would be visually too heavy.
|
|
202
|
+
|
|
203
|
+
If the user does NOT explicitly ask for a table or very structured data,
|
|
204
|
+
you MUST use the CARD layout.
|
|
205
|
+
|
|
206
|
+
====================
|
|
207
|
+
STYLE RULES
|
|
208
|
+
====================
|
|
209
|
+
General style (CARD or container):
|
|
210
|
+
- Use a main wrapper <div> with styles similar to:
|
|
211
|
+
background: #ffffff;
|
|
212
|
+
color: #111111;
|
|
213
|
+
border: 1px solid #e5e5e5;
|
|
214
|
+
border-radius: 8px;
|
|
215
|
+
padding: 12px;
|
|
216
|
+
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
217
|
+
- You may add a top header area using the header background color:
|
|
218
|
+
background: ${headerColor};
|
|
219
|
+
|
|
220
|
+
Use branding:
|
|
221
|
+
- Include the company logo and name in a subtle way when appropriate
|
|
222
|
+
(for example, in a small header bar):
|
|
223
|
+
- Logo (emoji or image) on the left,
|
|
224
|
+
- Company name text next to it.
|
|
225
|
+
|
|
226
|
+
Typography:
|
|
227
|
+
- Titles: 18\u201322px, bold.
|
|
228
|
+
- Body text: 12\u201316px, regular.
|
|
229
|
+
- Line-height should be comfortable (around 1.4\u20131.6).
|
|
230
|
+
|
|
231
|
+
Tables:
|
|
232
|
+
- Use <table> with <thead> and <tbody> where appropriate.
|
|
233
|
+
- Header row background: ${accentColor};
|
|
234
|
+
- Header row text color: #ffffff;
|
|
235
|
+
- Body rows background: #ffffff;
|
|
236
|
+
- Row borders: 1px solid #e5e5e5 (or a faint version of the border color).
|
|
237
|
+
|
|
238
|
+
Mini table:
|
|
239
|
+
- Can be a simple two-column table or stacked key-value pairs.
|
|
240
|
+
- Keep it compact (less padding, fewer rows).
|
|
241
|
+
|
|
242
|
+
Links:
|
|
243
|
+
- You can use <a> for styling or static URLs.
|
|
244
|
+
- Use the accent color for links:
|
|
245
|
+
color: ${accentColor};
|
|
246
|
+
|
|
247
|
+
====================
|
|
248
|
+
OUTPUT FORMAT
|
|
249
|
+
====================
|
|
250
|
+
Your final output MUST follow these rules:
|
|
251
|
+
- Output ONLY a single HTML snippet.
|
|
252
|
+
- Do NOT wrap it in backticks or markdown.
|
|
253
|
+
- Do NOT include any explanation text.
|
|
254
|
+
- Do NOT include JSON.
|
|
255
|
+
- Must use exactly ONE of: card, table, mini table.
|
|
256
|
+
- Must respect allowed/forbidden tags.
|
|
257
|
+
- Must use colors derived from:
|
|
258
|
+
- header_background
|
|
259
|
+
- button_background
|
|
260
|
+
and otherwise a light theme.
|
|
261
|
+
|
|
262
|
+
====================
|
|
263
|
+
BEHAVIOR SUMMARY
|
|
264
|
+
====================
|
|
265
|
+
1) Read the user message.
|
|
266
|
+
2) Decide whether CARD, TABLE, or MINI TABLE is most suitable.
|
|
267
|
+
3) Generate a single HTML layout using only allowed, non-interactive tags.
|
|
268
|
+
4) Style the layout with inline CSS using:
|
|
269
|
+
- ${headerColor} for header areas,
|
|
270
|
+
- ${accentColor} for accents,
|
|
271
|
+
- white/light backgrounds and dark text.
|
|
272
|
+
5) Return ONLY the HTML snippet.
|
|
273
|
+
`;
|
|
274
|
+
};
|
|
118
275
|
const sendMessage = async (message) => {
|
|
119
276
|
if (!message.trim() || isLoading) return;
|
|
120
277
|
addMessage(message, "user");
|
|
121
278
|
setIsLoading(true);
|
|
279
|
+
console.log(options.config);
|
|
122
280
|
try {
|
|
123
281
|
let resp;
|
|
124
282
|
console.log(options.headers);
|
|
@@ -134,7 +292,8 @@ var useChatbot = (options = {}) => {
|
|
|
134
292
|
}
|
|
135
293
|
],
|
|
136
294
|
input: message,
|
|
137
|
-
previous_response_id: responseId || void 0
|
|
295
|
+
previous_response_id: responseId || void 0,
|
|
296
|
+
instructions: getHtmlUiInstructions(options.config)
|
|
138
297
|
});
|
|
139
298
|
setResponseId(resp.id);
|
|
140
299
|
let responseText = "";
|
|
@@ -714,12 +873,12 @@ var AizekChatBot = ({ clientId, headers }) => {
|
|
|
714
873
|
const [isConfigLoading, setIsConfigLoading] = useState(true);
|
|
715
874
|
const [finalMcpUrl, setFinalMcpUrl] = useState("");
|
|
716
875
|
const [apiKey, setApiKey] = useState("");
|
|
717
|
-
const [validConfig, setValidConfig] = useState(false);
|
|
718
876
|
const { welcomeMessage, buttonBackground, placeholder, buttonPosition, buttonSize, chatWidth, chatHeight, showTypingIndicator, initialOpen, headerBackground, companyLogo, companyName } = config;
|
|
719
877
|
const [isOpen, setIsOpen] = useState(false);
|
|
720
878
|
const [headerValidation, setHeaderValidation] = useState(null);
|
|
721
879
|
const [showAlert, setShowAlert] = useState(true);
|
|
722
880
|
useEffect(() => {
|
|
881
|
+
console.log("render");
|
|
723
882
|
const loadConfig = async () => {
|
|
724
883
|
try {
|
|
725
884
|
setIsConfigLoading(true);
|
|
@@ -747,7 +906,7 @@ var AizekChatBot = ({ clientId, headers }) => {
|
|
|
747
906
|
};
|
|
748
907
|
loadConfig();
|
|
749
908
|
}, [clientId]);
|
|
750
|
-
const internalChatbot = useChatbot({ mcpUrl: finalMcpUrl, apiKey, headers });
|
|
909
|
+
const internalChatbot = useChatbot({ mcpUrl: finalMcpUrl, apiKey, headers, config });
|
|
751
910
|
const messages = internalChatbot.messages;
|
|
752
911
|
const isLoading = internalChatbot.isLoading;
|
|
753
912
|
const handleSendMessage = internalChatbot.sendMessage;
|
|
@@ -767,7 +926,7 @@ var AizekChatBot = ({ clientId, headers }) => {
|
|
|
767
926
|
return /* @__PURE__ */ jsxs("div", { style: getMessageContainerStyles(isUser), children: [
|
|
768
927
|
/* @__PURE__ */ jsx("style", { children: getMarkdownElementStyles(isUser) }),
|
|
769
928
|
/* @__PURE__ */ jsxs("div", { style: getMessageBubbleStyles(isUser), children: [
|
|
770
|
-
/* @__PURE__ */ jsx("div", { style: getMarkdownStyles(), className: "markdown-content", children: /* @__PURE__ */ jsx(ReactMarkdown, { remarkPlugins: [remarkGfm], children: message.content }) }),
|
|
929
|
+
isUser ? /* @__PURE__ */ jsx("div", { style: getMarkdownStyles(), className: "markdown-content", children: /* @__PURE__ */ jsx(ReactMarkdown, { remarkPlugins: [remarkGfm], children: message.content }) }) : /* @__PURE__ */ jsx("div", { dangerouslySetInnerHTML: { __html: message.content } }),
|
|
771
930
|
message.isTyping && /* @__PURE__ */ jsx("div", { style: {
|
|
772
931
|
display: "inline-flex",
|
|
773
932
|
alignItems: "center",
|