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