aizek-chatbot 1.0.10 → 1.0.11
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 +1226 -229
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +112 -4
- package/dist/index.d.ts +112 -4
- package/dist/index.mjs +1226 -228
- package/dist/index.mjs.map +1 -1
- package/package.json +47 -47
package/dist/index.cjs
CHANGED
|
@@ -5,7 +5,6 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
5
5
|
var OpenAI = require('openai');
|
|
6
6
|
var ReactMarkdown = require('react-markdown');
|
|
7
7
|
var remarkGfm = require('remark-gfm');
|
|
8
|
-
var DOMPurify = require('dompurify');
|
|
9
8
|
|
|
10
9
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
10
|
|
|
@@ -31,7 +30,6 @@ var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
|
31
30
|
var OpenAI__default = /*#__PURE__*/_interopDefault(OpenAI);
|
|
32
31
|
var ReactMarkdown__default = /*#__PURE__*/_interopDefault(ReactMarkdown);
|
|
33
32
|
var remarkGfm__default = /*#__PURE__*/_interopDefault(remarkGfm);
|
|
34
|
-
var DOMPurify__default = /*#__PURE__*/_interopDefault(DOMPurify);
|
|
35
33
|
|
|
36
34
|
// src/utils/cx.ts
|
|
37
35
|
function cx(...args) {
|
|
@@ -133,210 +131,299 @@ var useChatbot = (options = {}) => {
|
|
|
133
131
|
const generateId = () => {
|
|
134
132
|
return Date.now().toString() + Math.random().toString(36).substr(2, 9);
|
|
135
133
|
};
|
|
136
|
-
const addMessage = (
|
|
134
|
+
const addMessage = (payload, role) => {
|
|
137
135
|
const newMessage = {
|
|
138
136
|
id: generateId(),
|
|
139
|
-
|
|
137
|
+
text: payload.text,
|
|
138
|
+
ui: payload.ui,
|
|
140
139
|
role,
|
|
141
140
|
timestamp: /* @__PURE__ */ new Date()
|
|
142
141
|
};
|
|
143
142
|
setMessages((prev) => [...prev, newMessage]);
|
|
144
143
|
return newMessage;
|
|
145
144
|
};
|
|
146
|
-
const
|
|
147
|
-
const
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
145
|
+
const extractUiComponents = (raw) => {
|
|
146
|
+
const regex = /```ui-component([\s\S]*?)```/g;
|
|
147
|
+
const components = [];
|
|
148
|
+
let cleaned = raw;
|
|
149
|
+
let match;
|
|
150
|
+
let componentIndex = 0;
|
|
151
|
+
while ((match = regex.exec(raw)) !== null) {
|
|
152
|
+
const block = match[1].trim();
|
|
153
|
+
try {
|
|
154
|
+
const json = JSON.parse(block);
|
|
155
|
+
if (json.type === "buttons" && json.data && typeof json.data === "object" && !Array.isArray(json.data)) {
|
|
156
|
+
if (json.data.options && Array.isArray(json.data.options)) {
|
|
157
|
+
json.data = json.data.options.map((opt) => {
|
|
158
|
+
if (opt.id && opt.label) {
|
|
159
|
+
return {
|
|
160
|
+
label: opt.label,
|
|
161
|
+
value: opt.id,
|
|
162
|
+
variant: opt.variant
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
return opt;
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (json.type === "table" && json.data) {
|
|
170
|
+
if (Array.isArray(json.data.columns) && json.data.columns.length > 0) {
|
|
171
|
+
const firstCol = json.data.columns[0];
|
|
172
|
+
if (typeof firstCol === "string") {
|
|
173
|
+
json.data.columns = json.data.columns.map(
|
|
174
|
+
(col, idx) => ({
|
|
175
|
+
id: `col-${idx}`,
|
|
176
|
+
label: col
|
|
177
|
+
})
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (Array.isArray(json.data.rows) && json.data.rows.length > 0) {
|
|
182
|
+
const firstRow = json.data.rows[0];
|
|
183
|
+
if (Array.isArray(firstRow) && typeof firstRow[0] === "string") {
|
|
184
|
+
json.data.rows = json.data.rows.map((row) => {
|
|
185
|
+
const rowObj = {};
|
|
186
|
+
json.data.columns.forEach((col, idx) => {
|
|
187
|
+
const colId = typeof col === "string" ? `col-${idx}` : col.id;
|
|
188
|
+
const cellValue = row[idx];
|
|
189
|
+
if (typeof cellValue === "string" && (cellValue.startsWith("http") || cellValue.startsWith("data:"))) {
|
|
190
|
+
rowObj[colId] = {
|
|
191
|
+
type: "image",
|
|
192
|
+
src: cellValue,
|
|
193
|
+
alt: ""
|
|
194
|
+
};
|
|
195
|
+
} else {
|
|
196
|
+
rowObj[colId] = {
|
|
197
|
+
type: "text",
|
|
198
|
+
value: cellValue || ""
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
return rowObj;
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (json.type === "form" && json.data) {
|
|
208
|
+
if (!json.data.id) {
|
|
209
|
+
json.data.id = json.id || `form-${componentIndex}`;
|
|
210
|
+
}
|
|
211
|
+
if (json.data.fields && Array.isArray(json.data.fields)) {
|
|
212
|
+
json.data.fields = json.data.fields.map((field) => {
|
|
213
|
+
if (field.optional !== void 0) {
|
|
214
|
+
field.required = !field.optional;
|
|
215
|
+
delete field.optional;
|
|
216
|
+
}
|
|
217
|
+
if (!field.type) {
|
|
218
|
+
field.type = "text";
|
|
219
|
+
}
|
|
220
|
+
if (field.options && Array.isArray(field.options)) {
|
|
221
|
+
const firstOption = field.options[0];
|
|
222
|
+
if (typeof firstOption === "string") {
|
|
223
|
+
field.options = field.options.map((opt) => ({
|
|
224
|
+
label: opt,
|
|
225
|
+
value: opt
|
|
226
|
+
}));
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return field;
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (json.id && typeof json.id !== "string") {
|
|
234
|
+
json.id = String(json.id);
|
|
235
|
+
}
|
|
236
|
+
if (!json.id || !json.id.trim()) {
|
|
237
|
+
json.id = `ui-comp-${componentIndex}-${Date.now()}`;
|
|
238
|
+
}
|
|
239
|
+
components.push(json);
|
|
240
|
+
componentIndex++;
|
|
241
|
+
} catch (e) {
|
|
242
|
+
console.error("Invalid ui-component JSON:", e, block);
|
|
243
|
+
}
|
|
244
|
+
cleaned = cleaned.replace(match[0], "").trim();
|
|
245
|
+
}
|
|
246
|
+
return { text: cleaned, components };
|
|
247
|
+
};
|
|
248
|
+
const instructions = `You are Aizek, an AI assistant running in an environment with Model Context Protocol (MCP) tools.
|
|
151
249
|
|
|
152
|
-
Your
|
|
153
|
-
|
|
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 colors from options.config (headerBackground, buttonBackground).
|
|
158
|
-
- Return ONLY raw HTML (no markdown, no backticks, no JSON, no explanations).
|
|
250
|
+
Your top priority is to USE MCP TOOLS whenever they can handle the user's request.
|
|
251
|
+
Do NOT bypass available tools to answer from generic knowledge, web browsing, or other external sources if a suitable MCP tool exists.
|
|
159
252
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
The chat widget configuration provides:
|
|
253
|
+
==================================================
|
|
254
|
+
1. GENERAL BEHAVIOR
|
|
255
|
+
==================================================
|
|
164
256
|
|
|
165
|
-
-
|
|
166
|
-
-
|
|
257
|
+
- Default language: reply in the same language as the user (Turkish/English).
|
|
258
|
+
- Be concise and task-focused. Avoid small talk, philosophy, or meta-chat unless the user explicitly asks.
|
|
259
|
+
- Do not invent capabilities or tools that are not actually defined in the MCP tool list.
|
|
260
|
+
- If a tool call fails or returns an error, explain briefly and either:
|
|
261
|
+
- try again with a corrected call, or
|
|
262
|
+
- ask the user for the minimal extra info required.
|
|
167
263
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
- Use a white or very light background for main surfaces.
|
|
172
|
-
- Text color should generally be dark (#111\u2013#333) for readability.
|
|
264
|
+
==================================================
|
|
265
|
+
2. MCP TOOL PRIORITY RULES
|
|
266
|
+
==================================================
|
|
173
267
|
|
|
174
|
-
|
|
175
|
-
ALLOWED / FORBIDDEN TAGS
|
|
176
|
-
====================
|
|
177
|
-
You may use ANY NON-INTERACTIVE HTML element, for example:
|
|
178
|
-
- Text and headings:
|
|
179
|
-
<h1>, <h2>, <h3>, <h4>, <h5>, <h6>,
|
|
180
|
-
<p>, <span>, <strong>, <em>, <small>, <blockquote>, <code>, <pre>
|
|
181
|
-
- Layout:
|
|
182
|
-
<div>, <section>, <article>, <header>, <footer>
|
|
183
|
-
- Lists:
|
|
184
|
-
<ul>, <ol>, <li>
|
|
185
|
-
- Tables:
|
|
186
|
-
<table>, <thead>, <tbody>, <tr>, <th>, <td>
|
|
187
|
-
- Media:
|
|
188
|
-
<img>, <figure>, <figcaption>
|
|
189
|
-
- Links (non-interactive navigation style only):
|
|
190
|
-
<a>
|
|
268
|
+
ALWAYS prefer MCP tools over any other strategy WHEN:
|
|
191
269
|
|
|
192
|
-
|
|
193
|
-
-
|
|
270
|
+
- The user asks for information that matches a tool's domain (weather, products, etc.).
|
|
271
|
+
- The user asks to perform an action (create/update/delete something) that an MCP tool can perform.
|
|
194
272
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
- <video> or <audio> with controls for user interaction
|
|
199
|
-
- Any inline event handlers like onclick, onmouseover, etc.
|
|
200
|
-
- <script> or any JavaScript code.
|
|
273
|
+
Only if NO provided MCP tool is relevant may you fall back to:
|
|
274
|
+
1) other tools such as web/browsing, or
|
|
275
|
+
2) your own internal knowledge.
|
|
201
276
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
277
|
+
When deciding whether a tool is relevant:
|
|
278
|
+
- Read the tool name, description, and parameters.
|
|
279
|
+
- If it is even moderately related to what the user wants, you SHOULD try using it.
|
|
280
|
+
- Do NOT choose external (e.g., MGM, random APIs) sources when a matching MCP tool exists.
|
|
206
281
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
282
|
+
If multiple tools could work:
|
|
283
|
+
- Choose the single BEST-FIT tool first.
|
|
284
|
+
- If the task clearly requires multiple tools (e.g., get weather then log it), you may call them sequentially.
|
|
210
285
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
(Do NOT render card + table together, or table + mini-table together.)
|
|
286
|
+
==================================================
|
|
287
|
+
3. ACTION TOOLS VS. DRAFTS (IKAS MCP, PRODUCT CREATION)
|
|
288
|
+
==================================================
|
|
215
289
|
|
|
216
|
-
|
|
217
|
-
- CARD (DEFAULT):
|
|
218
|
-
- Use this for normal answers, explanations, descriptions, welcome messages,
|
|
219
|
-
and any content that is mostly free text.
|
|
220
|
-
- TABLE:
|
|
221
|
-
- Use this ONLY when the content is clearly structured with multiple columns
|
|
222
|
-
(for example: comparisons, lists of items with several attributes).
|
|
223
|
-
- MINI TABLE:
|
|
224
|
-
- Use this for small, compact key-value style data
|
|
225
|
-
(for example: a few fields like "Token", "Price", "Network"),
|
|
226
|
-
or when a full table would be visually too heavy.
|
|
290
|
+
Some MCP tools can PERFORM REAL ACTIONS (e.g., create a product in an e-commerce system via ikas MCP).
|
|
227
291
|
|
|
228
|
-
|
|
229
|
-
you MUST
|
|
292
|
+
Critical rule:
|
|
293
|
+
- If the user's intent is to PERFORM an action, you MUST call the appropriate tool.
|
|
294
|
+
- Do NOT just "simulate" the action or write a draft object.
|
|
295
|
+
- Do NOT stop at: "Burada \u015F\xF6yle bir \xFCr\xFCn olu\u015Fturabilirim..." and then not call the tool.
|
|
296
|
+
- The goal is that the side effect actually happens through the tool.
|
|
230
297
|
|
|
231
|
-
|
|
232
|
-
STYLE RULES
|
|
233
|
-
====================
|
|
234
|
-
General style (CARD or container):
|
|
235
|
-
- Use a main wrapper <div> with styles similar to:
|
|
236
|
-
background: #ffffff;
|
|
237
|
-
color: #111111;
|
|
238
|
-
border: 1px solid #e5e5e5;
|
|
239
|
-
border-radius: 8px;
|
|
240
|
-
padding: 12px;
|
|
241
|
-
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
298
|
+
Examples (Turkish / ikas):
|
|
242
299
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
300
|
+
1) User:
|
|
301
|
+
"\u0130kas'ta yeni bir \xFCr\xFCn olu\u015Ftur:
|
|
302
|
+
isim: Siyah T-Shirt,
|
|
303
|
+
fiyat: 299 TL,
|
|
304
|
+
stok: 50,
|
|
305
|
+
kategori: Ti\u015F\xF6rtler."
|
|
246
306
|
|
|
247
|
-
|
|
248
|
-
-
|
|
249
|
-
-
|
|
250
|
-
-
|
|
307
|
+
\u2192 You MUST:
|
|
308
|
+
- Map these fields to the ikas product-creation tool schema.
|
|
309
|
+
- CALL the ikas MCP tool to actually create the product.
|
|
310
|
+
- Then answer with something like:
|
|
311
|
+
"\xDCr\xFCn ba\u015Far\u0131yla olu\u015Fturuldu. ID: <tool_output_id>, ad: Siyah T-Shirt, fiyat: 299 TL, stok: 50."
|
|
251
312
|
|
|
252
|
-
|
|
253
|
-
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
- Body rows background: #ffffff;
|
|
257
|
-
- Row borders: 1px solid #e5e5e5 (or a faint version of the border color).
|
|
313
|
+
\u2192 You MUST NOT:
|
|
314
|
+
- Only respond with a JSON draft or description like:
|
|
315
|
+
"\u015E\xF6yle bir taslak \xFCr\xFCn olu\u015Fturabilirsin: {...}"
|
|
316
|
+
without calling the tool.
|
|
258
317
|
|
|
259
|
-
|
|
260
|
-
-
|
|
261
|
-
-
|
|
318
|
+
2) If the tool requires fields that the user didn't provide (e.g. currency code, SKU):
|
|
319
|
+
- Ask ONLY the minimal clarifying question needed.
|
|
320
|
+
- Or, if the field is safely inferrable by convention (e.g. default currency for a given store), use the default.
|
|
262
321
|
|
|
263
|
-
|
|
264
|
-
-
|
|
265
|
-
-
|
|
266
|
-
|
|
322
|
+
3) If the tool response indicates "draft" vs. "published" status:
|
|
323
|
+
- Respect the user's explicit intention.
|
|
324
|
+
- If the user says "taslak olarak kaydet", then request draft=true.
|
|
325
|
+
- If the user says "direkt yay\u0131na al" or clearly wants the product live, then request published/active status.
|
|
326
|
+
- Do NOT downgrade a clear "publish" intent into just a draft.
|
|
267
327
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
Sometimes, during a workflow or tool usage, you may need the user to confirm an action
|
|
272
|
-
(e.g., deleting a workflow, sending a transaction, performing an irreversible change).
|
|
328
|
+
==================================================
|
|
329
|
+
4. INTERPRETING USER INTENT
|
|
330
|
+
==================================================
|
|
273
331
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
- They MUST be rendered with these exact data attributes:
|
|
332
|
+
- Treat verbs like "olu\u015Ftur", "yarat", "ekle", "sil", "g\xFCncelle", "publish et", "yay\u0131na al"
|
|
333
|
+
as strong indicators that an ACTION tool call is expected, not just text output.
|
|
277
334
|
|
|
278
|
-
|
|
279
|
-
|
|
335
|
+
- Treat questions like "nas\u0131l yap\u0131l\u0131r?", "bana g\xF6ster", "\xF6rnek ver", "JSON tasla\u011F\u0131 olu\u015Ftur"
|
|
336
|
+
as more educational; then you may provide drafts/examples without executing tools,
|
|
337
|
+
UNLESS the user explicitly says they want the real action too.
|
|
280
338
|
|
|
281
|
-
|
|
282
|
-
- Do NOT add onclick or any other JS event attributes.
|
|
283
|
-
- Do NOT add custom data attributes besides data-ai-action.
|
|
284
|
-
- The host application will detect these buttons by data-ai-action
|
|
285
|
-
and will send the following messages back to you:
|
|
286
|
-
"__APPROVE__" when the user clicks "Onayla"
|
|
287
|
-
"__CANCEL__" when the user clicks "Vazge\xE7"
|
|
339
|
+
Examples:
|
|
288
340
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
- When you receive "__CANCEL__", behave as if the user declined or cancelled.
|
|
292
|
-
- After that, go back to NORMAL mode and return standard HTML output again
|
|
293
|
-
(card, table, or mini table, WITHOUT <button>).
|
|
341
|
+
- "\u0130kas'ta \xFCr\xFCn olu\u015Fturmay\u0131 bana JSON \xF6rne\u011Fiyle anlat\u0131r m\u0131s\u0131n?"
|
|
342
|
+
\u2192 Explain the schema, show a draft, you may skip real tool call unless they also say "ve bunu benim i\xE7in \u015Fimdi olu\u015Ftur."
|
|
294
343
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
344
|
+
- "Benim ad\u0131ma bu \xFCr\xFCn\xFC ger\xE7ekten olu\u015Ftur ve yay\u0131na al."
|
|
345
|
+
\u2192 This MUST trigger the actual ikas MCP product-creation tool call.
|
|
346
|
+
|
|
347
|
+
==================================================
|
|
348
|
+
5. IRRELEVANT TOPICS & SCOPE
|
|
349
|
+
==================================================
|
|
350
|
+
|
|
351
|
+
- Aizek's primary job in this environment is:
|
|
352
|
+
- Using MCP tools effectively (weather, e-commerce, etc.).
|
|
353
|
+
- Providing concise, helpful answers strictly related to the user's requests.
|
|
354
|
+
|
|
355
|
+
- Avoid:
|
|
356
|
+
- Long off-topic chats.
|
|
357
|
+
- Unnecessary explanations of MCP internals or tool schemas unless the user specifically asks.
|
|
358
|
+
- Using random non-MCP APIs or external services when an MCP tool already exists in that domain.
|
|
359
|
+
|
|
360
|
+
==================================================
|
|
361
|
+
6. TOOL-CALLING STYLE
|
|
362
|
+
==================================================
|
|
363
|
+
|
|
364
|
+
When you decide to call a tool:
|
|
365
|
+
- Use the exact tool name and parameter schema given by the environment.
|
|
366
|
+
- Provide all required parameters; do NOT omit fields the schema marks as required.
|
|
367
|
+
- Prefer a single well-structured call over multiple fragmented ones whenever possible.
|
|
368
|
+
|
|
369
|
+
Once you receive tool results:
|
|
370
|
+
- Summarize them clearly for the user in natural language.
|
|
371
|
+
- If the user requested an action (e.g., create product, update something), confirm:
|
|
372
|
+
- What was done,
|
|
373
|
+
- Any IDs or references returned,
|
|
374
|
+
- Any next steps they might need.
|
|
298
375
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
Your final output MUST follow these rules:
|
|
303
|
-
- Output ONLY a single HTML snippet.
|
|
304
|
-
- Do NOT wrap it in backticks or markdown.
|
|
305
|
-
- Do NOT include any explanation text.
|
|
306
|
-
- Do NOT include JSON.
|
|
307
|
-
- Must use exactly ONE of: card, table, mini table.
|
|
308
|
-
- Must respect allowed/forbidden tags.
|
|
309
|
-
- Must use colors derived from:
|
|
310
|
-
- headerBackground
|
|
311
|
-
- buttonBackground
|
|
312
|
-
and otherwise a light theme.
|
|
376
|
+
==================================================
|
|
377
|
+
7. FALLBACK LOGIC
|
|
378
|
+
==================================================
|
|
313
379
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
-
|
|
320
|
-
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
380
|
+
In this order of priority:
|
|
381
|
+
|
|
382
|
+
1) If an MCP tool matches the user's request \u2192 USE IT.
|
|
383
|
+
2) If no tool fits, and the user just needs information \u2192 answer from your own knowledge or other allowed tools.
|
|
384
|
+
3) If the user asks something completely outside your domain/scope \u2192
|
|
385
|
+
- Briefly explain that it is outside Aizek's scope or that you have limited info,
|
|
386
|
+
- Offer to help only if you can still add value without contradicting previous rules.
|
|
387
|
+
|
|
388
|
+
Always keep in mind:
|
|
389
|
+
Your core value in this environment is to be an intelligent router and operator for MCP tools, not a generic, unconstrained chatbot.`;
|
|
390
|
+
const SYSTEM_PROMPT = `
|
|
391
|
+
You are a helpful assistant that can generate both natural language responses and UI components.
|
|
392
|
+
|
|
393
|
+
You MUST:
|
|
394
|
+
- Always respond with normal conversational text.
|
|
395
|
+
- Optionally include one or more UI components inside code blocks with language "ui-component".
|
|
396
|
+
|
|
397
|
+
When to use components:
|
|
398
|
+
- User needs to provide multiple structured values \u2192 generate a FORM
|
|
399
|
+
- User must choose among options \u2192 generate BUTTONS
|
|
400
|
+
- User must see structured data comparison \u2192 generate a TABLE
|
|
401
|
+
- User must see entity details/summary \u2192 generate a CARD
|
|
402
|
+
|
|
403
|
+
Format for each component (strictly):
|
|
404
|
+
|
|
405
|
+
\`\`\`ui-component
|
|
406
|
+
{
|
|
407
|
+
"type": "form" | "buttons" | "table" | "card",
|
|
408
|
+
"data": { ...component-specific fields... }
|
|
409
|
+
}
|
|
410
|
+
\`\`\`
|
|
411
|
+
|
|
412
|
+
IMPORTANT:
|
|
413
|
+
- Do NOT invent HTML. Only JSON as described.
|
|
414
|
+
- Keep JSON strictly valid.
|
|
415
|
+
- Text response should be outside of code blocks.
|
|
330
416
|
`;
|
|
331
|
-
|
|
332
|
-
const sendMessage = async (message) => {
|
|
417
|
+
const sendMessage = async (message, approval) => {
|
|
333
418
|
if (!message.trim() || isLoading) return;
|
|
334
|
-
|
|
419
|
+
if (approval) {
|
|
420
|
+
addMessage({ text: message }, "approval");
|
|
421
|
+
} else {
|
|
422
|
+
addMessage({ text: message }, "user");
|
|
423
|
+
}
|
|
335
424
|
setIsLoading(true);
|
|
336
|
-
console.log(options.config);
|
|
337
425
|
try {
|
|
338
426
|
let resp;
|
|
339
|
-
console.log(options.headers);
|
|
340
427
|
resp = await client.responses.create({
|
|
341
428
|
model: "gpt-5",
|
|
342
429
|
tools: [
|
|
@@ -348,38 +435,43 @@ BEHAVIOR SUMMARY
|
|
|
348
435
|
headers: options.headers || {}
|
|
349
436
|
}
|
|
350
437
|
],
|
|
351
|
-
input:
|
|
438
|
+
input: [
|
|
439
|
+
{ role: "system", content: SYSTEM_PROMPT },
|
|
440
|
+
{ role: "user", content: message }
|
|
441
|
+
],
|
|
352
442
|
previous_response_id: responseId || void 0,
|
|
353
|
-
instructions
|
|
443
|
+
instructions
|
|
354
444
|
});
|
|
445
|
+
console.log("Response:", resp);
|
|
355
446
|
setResponseId(resp.id);
|
|
356
|
-
let
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
447
|
+
let rawText = "";
|
|
448
|
+
const output = resp.output;
|
|
449
|
+
if (Array.isArray(output) && output.length > 0) {
|
|
450
|
+
const assistantMsg = output.find((o) => o.role === "assistant") ?? output[0];
|
|
451
|
+
if (assistantMsg && Array.isArray(assistantMsg.content)) {
|
|
452
|
+
const textItem = assistantMsg.content.find(
|
|
453
|
+
(c) => c.type === "output_text"
|
|
362
454
|
);
|
|
363
|
-
if (
|
|
364
|
-
|
|
455
|
+
if (textItem?.text?.value) {
|
|
456
|
+
rawText = textItem.text.value;
|
|
457
|
+
} else if (textItem?.text?.annotations?.[0]?.text) {
|
|
458
|
+
rawText = textItem.text.annotations[0].text;
|
|
365
459
|
}
|
|
366
460
|
}
|
|
367
|
-
} else {
|
|
368
|
-
if (resp && resp.output_text) {
|
|
369
|
-
responseText = resp.output_text;
|
|
370
|
-
} else if (typeof resp === "string") {
|
|
371
|
-
responseText = resp;
|
|
372
|
-
}
|
|
373
461
|
}
|
|
374
|
-
if (!
|
|
375
|
-
|
|
462
|
+
if (!rawText && resp.output_text) {
|
|
463
|
+
rawText = resp.output_text;
|
|
464
|
+
}
|
|
465
|
+
if (!rawText) {
|
|
466
|
+
rawText = `"${message}" mesaj\u0131n\u0131z\u0131 ald\u0131m. Size nas\u0131l yard\u0131mc\u0131 olabilirim?`;
|
|
376
467
|
}
|
|
377
|
-
|
|
468
|
+
const { text, components } = extractUiComponents(rawText);
|
|
469
|
+
addMessage({ text, ui: components }, "assistant");
|
|
378
470
|
setIsLoading(false);
|
|
379
471
|
} catch (error) {
|
|
380
472
|
console.error("Error sending message:", error);
|
|
381
473
|
addMessage(
|
|
382
|
-
"\xDCzg\xFCn\xFCm, bir hata olu\u015Ftu. L\xFCtfen tekrar deneyin.",
|
|
474
|
+
{ text: "\xDCzg\xFCn\xFCm, bir hata olu\u015Ftu. L\xFCtfen tekrar deneyin." },
|
|
383
475
|
"assistant"
|
|
384
476
|
);
|
|
385
477
|
setIsLoading(false);
|
|
@@ -394,7 +486,7 @@ BEHAVIOR SUMMARY
|
|
|
394
486
|
};
|
|
395
487
|
|
|
396
488
|
// src/services/chatWidgetApi.ts
|
|
397
|
-
var API_BASE_URL = "https://api.
|
|
489
|
+
var API_BASE_URL = "https://api-alpha.aizek.ai";
|
|
398
490
|
var fetchChatWidgetSettings = async (clientId) => {
|
|
399
491
|
try {
|
|
400
492
|
const response = await fetch(`${API_BASE_URL}/ChatWidgetSettings/GetByClientId?client_id=${clientId}`, {
|
|
@@ -407,7 +499,6 @@ var fetchChatWidgetSettings = async (clientId) => {
|
|
|
407
499
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
408
500
|
}
|
|
409
501
|
const data = await response.json();
|
|
410
|
-
console.log(data);
|
|
411
502
|
return data;
|
|
412
503
|
} catch (error) {
|
|
413
504
|
console.error("Error fetching chat widget settings:", error);
|
|
@@ -441,7 +532,6 @@ var mapApiSettingsToConfig = (apiSettings) => {
|
|
|
441
532
|
|
|
442
533
|
// src/styles/messageStyles.ts
|
|
443
534
|
var getMessageBubbleStyles = (isUser, isTyping) => ({
|
|
444
|
-
display: !isTyping && !isUser ? "none" : "block",
|
|
445
535
|
maxWidth: "80%",
|
|
446
536
|
padding: "12px 16px",
|
|
447
537
|
borderRadius: isUser ? "18px 18px 4px 18px" : "18px 18px 18px 4px",
|
|
@@ -470,7 +560,8 @@ var getTimeStyles = (isUser) => ({
|
|
|
470
560
|
textAlign: isUser ? "right" : "left"
|
|
471
561
|
});
|
|
472
562
|
var getMarkdownStyles = () => ({
|
|
473
|
-
lineHeight: 1.6
|
|
563
|
+
lineHeight: 1.6,
|
|
564
|
+
marginBottom: "6px"
|
|
474
565
|
});
|
|
475
566
|
var getMarkdownElementStyles = (isUser) => `
|
|
476
567
|
.markdown-content p {
|
|
@@ -917,6 +1008,901 @@ var getAlertAnimationStyles = () => `
|
|
|
917
1008
|
}
|
|
918
1009
|
}
|
|
919
1010
|
`;
|
|
1011
|
+
function UIRenderer({ components, onInteraction }) {
|
|
1012
|
+
console.log(components);
|
|
1013
|
+
if (!Array.isArray(components) || components.length === 0) {
|
|
1014
|
+
return null;
|
|
1015
|
+
}
|
|
1016
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1017
|
+
"div",
|
|
1018
|
+
{
|
|
1019
|
+
style: {
|
|
1020
|
+
display: "flex",
|
|
1021
|
+
flexDirection: "column",
|
|
1022
|
+
gap: "16px",
|
|
1023
|
+
width: "100%"
|
|
1024
|
+
},
|
|
1025
|
+
children: components.map((comp, idx) => {
|
|
1026
|
+
if (!comp || typeof comp !== "object" || !comp.type) {
|
|
1027
|
+
return null;
|
|
1028
|
+
}
|
|
1029
|
+
const key = typeof comp.id === "string" && comp.id.trim() ? comp.id : `${comp.type}-${idx}`;
|
|
1030
|
+
switch (comp.type) {
|
|
1031
|
+
case "form":
|
|
1032
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1033
|
+
FormComponent,
|
|
1034
|
+
{
|
|
1035
|
+
data: comp.data,
|
|
1036
|
+
onSubmit: (values) => onInteraction?.({
|
|
1037
|
+
type: "formSubmit",
|
|
1038
|
+
componentId: comp.data.id,
|
|
1039
|
+
values
|
|
1040
|
+
})
|
|
1041
|
+
},
|
|
1042
|
+
key
|
|
1043
|
+
);
|
|
1044
|
+
case "buttons":
|
|
1045
|
+
if (!comp.data || !Array.isArray(comp.data)) {
|
|
1046
|
+
return null;
|
|
1047
|
+
}
|
|
1048
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1049
|
+
ButtonsComponent,
|
|
1050
|
+
{
|
|
1051
|
+
data: comp.data,
|
|
1052
|
+
onClick: (value) => onInteraction?.({ type: "buttonClick", value })
|
|
1053
|
+
},
|
|
1054
|
+
key
|
|
1055
|
+
);
|
|
1056
|
+
case "table":
|
|
1057
|
+
return /* @__PURE__ */ jsxRuntime.jsx(TableComponent, { data: comp.data }, key);
|
|
1058
|
+
case "card":
|
|
1059
|
+
return /* @__PURE__ */ jsxRuntime.jsx(CardComponent, { data: comp.data }, key);
|
|
1060
|
+
default:
|
|
1061
|
+
return null;
|
|
1062
|
+
}
|
|
1063
|
+
})
|
|
1064
|
+
}
|
|
1065
|
+
);
|
|
1066
|
+
}
|
|
1067
|
+
function FormComponent({
|
|
1068
|
+
data,
|
|
1069
|
+
onSubmit
|
|
1070
|
+
}) {
|
|
1071
|
+
const handleSubmit = (e) => {
|
|
1072
|
+
e.preventDefault();
|
|
1073
|
+
console.log(e.currentTarget);
|
|
1074
|
+
const formData = new FormData(e.currentTarget);
|
|
1075
|
+
console.log(formData);
|
|
1076
|
+
const values = {};
|
|
1077
|
+
data.fields.forEach((f) => {
|
|
1078
|
+
values[f.id || f.name] = String(formData.get(f.id || f.name) ?? "");
|
|
1079
|
+
});
|
|
1080
|
+
onSubmit(values);
|
|
1081
|
+
};
|
|
1082
|
+
console.log("formdata", data);
|
|
1083
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1084
|
+
"form",
|
|
1085
|
+
{
|
|
1086
|
+
onSubmit: handleSubmit,
|
|
1087
|
+
style: {
|
|
1088
|
+
width: "100%",
|
|
1089
|
+
maxWidth: "500px",
|
|
1090
|
+
border: "1px solid #e0e0e0",
|
|
1091
|
+
borderRadius: "12px",
|
|
1092
|
+
padding: "24px",
|
|
1093
|
+
backgroundColor: "#ffffff",
|
|
1094
|
+
boxShadow: "0 2px 8px rgba(0, 0, 0, 0.08)",
|
|
1095
|
+
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif'
|
|
1096
|
+
},
|
|
1097
|
+
children: [
|
|
1098
|
+
data.title && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1099
|
+
"h3",
|
|
1100
|
+
{
|
|
1101
|
+
style: {
|
|
1102
|
+
fontWeight: 600,
|
|
1103
|
+
fontSize: "16px",
|
|
1104
|
+
marginBottom: "20px",
|
|
1105
|
+
color: "#1a1a1a",
|
|
1106
|
+
marginTop: 0
|
|
1107
|
+
},
|
|
1108
|
+
children: data.title
|
|
1109
|
+
}
|
|
1110
|
+
),
|
|
1111
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1112
|
+
"div",
|
|
1113
|
+
{
|
|
1114
|
+
style: {
|
|
1115
|
+
display: "flex",
|
|
1116
|
+
flexDirection: "column",
|
|
1117
|
+
gap: "20px"
|
|
1118
|
+
},
|
|
1119
|
+
children: data.fields.map((field, fieldIdx) => {
|
|
1120
|
+
const fieldKey = typeof field.id === "string" && field.id.trim() ? field.id : `field-${fieldIdx}`;
|
|
1121
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1122
|
+
"div",
|
|
1123
|
+
{
|
|
1124
|
+
style: {
|
|
1125
|
+
display: "flex",
|
|
1126
|
+
flexDirection: "column",
|
|
1127
|
+
gap: "8px"
|
|
1128
|
+
},
|
|
1129
|
+
children: [
|
|
1130
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1131
|
+
"label",
|
|
1132
|
+
{
|
|
1133
|
+
style: {
|
|
1134
|
+
fontWeight: 500,
|
|
1135
|
+
fontSize: "13px",
|
|
1136
|
+
color: "#374151",
|
|
1137
|
+
display: "flex",
|
|
1138
|
+
alignItems: "center",
|
|
1139
|
+
gap: "4px"
|
|
1140
|
+
},
|
|
1141
|
+
children: [
|
|
1142
|
+
field.label,
|
|
1143
|
+
field.required && /* @__PURE__ */ jsxRuntime.jsx("span", { style: { color: "#ef4444", fontSize: "14px" }, children: "*" })
|
|
1144
|
+
]
|
|
1145
|
+
}
|
|
1146
|
+
),
|
|
1147
|
+
field.type === "select" ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1148
|
+
"select",
|
|
1149
|
+
{
|
|
1150
|
+
name: field.id || field.name,
|
|
1151
|
+
required: field.required,
|
|
1152
|
+
defaultValue: field.value ? String(field.value) : "",
|
|
1153
|
+
style: {
|
|
1154
|
+
border: "1px solid #d1d5db",
|
|
1155
|
+
borderRadius: "8px",
|
|
1156
|
+
padding: "10px 12px",
|
|
1157
|
+
fontSize: "13px",
|
|
1158
|
+
color: "#1a1a1a",
|
|
1159
|
+
backgroundColor: "#ffffff",
|
|
1160
|
+
fontFamily: "inherit",
|
|
1161
|
+
outline: "none",
|
|
1162
|
+
transition: "border-color 0.15s ease, box-shadow 0.15s ease",
|
|
1163
|
+
cursor: "pointer"
|
|
1164
|
+
},
|
|
1165
|
+
onFocus: (e) => {
|
|
1166
|
+
e.currentTarget.style.borderColor = "#3b82f6";
|
|
1167
|
+
e.currentTarget.style.boxShadow = "0 0 0 3px rgba(59, 130, 246, 0.1)";
|
|
1168
|
+
},
|
|
1169
|
+
onBlur: (e) => {
|
|
1170
|
+
e.currentTarget.style.borderColor = "#d1d5db";
|
|
1171
|
+
e.currentTarget.style.boxShadow = "none";
|
|
1172
|
+
},
|
|
1173
|
+
children: [
|
|
1174
|
+
/* @__PURE__ */ jsxRuntime.jsx("option", { value: "", children: "Se\xE7iniz" }),
|
|
1175
|
+
field.options?.map((opt, optIdx) => {
|
|
1176
|
+
const optKey = typeof opt.value === "string" ? opt.value : `opt-${fieldIdx}-${optIdx}`;
|
|
1177
|
+
return /* @__PURE__ */ jsxRuntime.jsx("option", { value: opt.value, children: opt.label }, optKey);
|
|
1178
|
+
})
|
|
1179
|
+
]
|
|
1180
|
+
}
|
|
1181
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
1182
|
+
"input",
|
|
1183
|
+
{
|
|
1184
|
+
type: field.type === "number" ? "number" : "text",
|
|
1185
|
+
name: field.id || field.name,
|
|
1186
|
+
required: field.required,
|
|
1187
|
+
defaultValue: field.value ? String(field.value) : "",
|
|
1188
|
+
placeholder: field.placeholder || "",
|
|
1189
|
+
min: field.min,
|
|
1190
|
+
max: field.max,
|
|
1191
|
+
style: {
|
|
1192
|
+
border: "1px solid #d1d5db",
|
|
1193
|
+
borderRadius: "8px",
|
|
1194
|
+
padding: "10px 12px",
|
|
1195
|
+
fontSize: "13px",
|
|
1196
|
+
color: "#1a1a1a",
|
|
1197
|
+
backgroundColor: "#ffffff",
|
|
1198
|
+
fontFamily: "inherit",
|
|
1199
|
+
outline: "none",
|
|
1200
|
+
transition: "border-color 0.15s ease, box-shadow 0.15s ease"
|
|
1201
|
+
},
|
|
1202
|
+
onFocus: (e) => {
|
|
1203
|
+
e.currentTarget.style.borderColor = "#3b82f6";
|
|
1204
|
+
e.currentTarget.style.boxShadow = "0 0 0 3px rgba(59, 130, 246, 0.1)";
|
|
1205
|
+
},
|
|
1206
|
+
onBlur: (e) => {
|
|
1207
|
+
e.currentTarget.style.borderColor = "#d1d5db";
|
|
1208
|
+
e.currentTarget.style.boxShadow = "none";
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
)
|
|
1212
|
+
]
|
|
1213
|
+
},
|
|
1214
|
+
fieldKey
|
|
1215
|
+
);
|
|
1216
|
+
})
|
|
1217
|
+
}
|
|
1218
|
+
),
|
|
1219
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1220
|
+
"button",
|
|
1221
|
+
{
|
|
1222
|
+
type: "submit",
|
|
1223
|
+
style: {
|
|
1224
|
+
marginTop: "24px",
|
|
1225
|
+
display: "inline-flex",
|
|
1226
|
+
alignItems: "center",
|
|
1227
|
+
justifyContent: "center",
|
|
1228
|
+
borderRadius: "8px",
|
|
1229
|
+
padding: "12px 24px",
|
|
1230
|
+
fontSize: "13px",
|
|
1231
|
+
fontWeight: 500,
|
|
1232
|
+
backgroundColor: "#3b82f6",
|
|
1233
|
+
color: "#ffffff",
|
|
1234
|
+
border: "none",
|
|
1235
|
+
cursor: "pointer",
|
|
1236
|
+
transition: "background-color 0.15s ease, transform 0.1s ease",
|
|
1237
|
+
fontFamily: "inherit"
|
|
1238
|
+
},
|
|
1239
|
+
onMouseEnter: (e) => {
|
|
1240
|
+
e.currentTarget.style.backgroundColor = "#2563eb";
|
|
1241
|
+
},
|
|
1242
|
+
onMouseLeave: (e) => {
|
|
1243
|
+
e.currentTarget.style.backgroundColor = "#3b82f6";
|
|
1244
|
+
},
|
|
1245
|
+
onMouseDown: (e) => {
|
|
1246
|
+
e.currentTarget.style.transform = "scale(0.98)";
|
|
1247
|
+
},
|
|
1248
|
+
onMouseUp: (e) => {
|
|
1249
|
+
e.currentTarget.style.transform = "scale(1)";
|
|
1250
|
+
},
|
|
1251
|
+
children: data.submitLabel ?? "G\xF6nder"
|
|
1252
|
+
}
|
|
1253
|
+
)
|
|
1254
|
+
]
|
|
1255
|
+
}
|
|
1256
|
+
);
|
|
1257
|
+
}
|
|
1258
|
+
function ButtonsComponent({
|
|
1259
|
+
data,
|
|
1260
|
+
onClick
|
|
1261
|
+
}) {
|
|
1262
|
+
if (!Array.isArray(data) || data.length === 0) {
|
|
1263
|
+
return null;
|
|
1264
|
+
}
|
|
1265
|
+
const getButtonStyles = (variant) => {
|
|
1266
|
+
const baseStyles = {
|
|
1267
|
+
borderRadius: "8px",
|
|
1268
|
+
padding: "10px 20px",
|
|
1269
|
+
fontSize: "13px",
|
|
1270
|
+
fontWeight: 500,
|
|
1271
|
+
border: "1px solid #e0e0e0",
|
|
1272
|
+
backgroundColor: "#ffffff",
|
|
1273
|
+
color: "#374151",
|
|
1274
|
+
cursor: "pointer",
|
|
1275
|
+
transition: "all 0.15s ease",
|
|
1276
|
+
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',
|
|
1277
|
+
outline: "none"
|
|
1278
|
+
};
|
|
1279
|
+
if (variant === "primary") {
|
|
1280
|
+
return {
|
|
1281
|
+
...baseStyles,
|
|
1282
|
+
backgroundColor: "#3b82f6",
|
|
1283
|
+
color: "#ffffff",
|
|
1284
|
+
borderColor: "#3b82f6"
|
|
1285
|
+
};
|
|
1286
|
+
} else if (variant === "secondary") {
|
|
1287
|
+
return {
|
|
1288
|
+
...baseStyles,
|
|
1289
|
+
backgroundColor: "#f3f4f6",
|
|
1290
|
+
color: "#374151",
|
|
1291
|
+
borderColor: "#d1d5db"
|
|
1292
|
+
};
|
|
1293
|
+
} else if (variant === "danger") {
|
|
1294
|
+
return {
|
|
1295
|
+
...baseStyles,
|
|
1296
|
+
backgroundColor: "#ef4444",
|
|
1297
|
+
color: "#ffffff",
|
|
1298
|
+
borderColor: "#ef4444"
|
|
1299
|
+
};
|
|
1300
|
+
}
|
|
1301
|
+
return baseStyles;
|
|
1302
|
+
};
|
|
1303
|
+
const getHoverStyles = (variant) => {
|
|
1304
|
+
if (variant === "primary") {
|
|
1305
|
+
return { backgroundColor: "#2563eb", borderColor: "#2563eb" };
|
|
1306
|
+
} else if (variant === "secondary") {
|
|
1307
|
+
return { backgroundColor: "#e5e7eb", borderColor: "#9ca3af" };
|
|
1308
|
+
} else if (variant === "danger") {
|
|
1309
|
+
return { backgroundColor: "#dc2626", borderColor: "#dc2626" };
|
|
1310
|
+
}
|
|
1311
|
+
return { backgroundColor: "#f9fafb", borderColor: "#d1d5db" };
|
|
1312
|
+
};
|
|
1313
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1314
|
+
"div",
|
|
1315
|
+
{
|
|
1316
|
+
style: {
|
|
1317
|
+
display: "flex",
|
|
1318
|
+
gap: "12px",
|
|
1319
|
+
flexWrap: "wrap"
|
|
1320
|
+
},
|
|
1321
|
+
children: data.map((btn, idx) => {
|
|
1322
|
+
if (!btn || typeof btn !== "object") {
|
|
1323
|
+
return null;
|
|
1324
|
+
}
|
|
1325
|
+
const btnValue = typeof btn.value === "string" ? btn.value : typeof btn.value === "number" ? String(btn.value) : btn.value && typeof btn.value === "object" ? JSON.stringify(btn.value) : `btn-value-${idx}`;
|
|
1326
|
+
const btnKey = typeof btn.value === "string" && btn.value.trim() ? btn.value : `btn-${idx}`;
|
|
1327
|
+
const btnLabel = btn.label || `Button ${idx + 1}`;
|
|
1328
|
+
const buttonStyles = getButtonStyles(btn.variant);
|
|
1329
|
+
const hoverStyles = getHoverStyles(btn.variant);
|
|
1330
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1331
|
+
"button",
|
|
1332
|
+
{
|
|
1333
|
+
onClick: () => {
|
|
1334
|
+
try {
|
|
1335
|
+
onClick(btnValue);
|
|
1336
|
+
} catch (error) {
|
|
1337
|
+
console.error("Error in button onClick:", error);
|
|
1338
|
+
}
|
|
1339
|
+
},
|
|
1340
|
+
style: buttonStyles,
|
|
1341
|
+
onMouseEnter: (e) => {
|
|
1342
|
+
Object.assign(e.currentTarget.style, hoverStyles);
|
|
1343
|
+
},
|
|
1344
|
+
onMouseLeave: (e) => {
|
|
1345
|
+
Object.assign(e.currentTarget.style, buttonStyles);
|
|
1346
|
+
},
|
|
1347
|
+
onMouseDown: (e) => {
|
|
1348
|
+
e.currentTarget.style.transform = "scale(0.97)";
|
|
1349
|
+
},
|
|
1350
|
+
onMouseUp: (e) => {
|
|
1351
|
+
e.currentTarget.style.transform = "scale(1)";
|
|
1352
|
+
},
|
|
1353
|
+
children: btnLabel
|
|
1354
|
+
},
|
|
1355
|
+
btnKey
|
|
1356
|
+
);
|
|
1357
|
+
})
|
|
1358
|
+
}
|
|
1359
|
+
);
|
|
1360
|
+
}
|
|
1361
|
+
function TableComponent({ data }) {
|
|
1362
|
+
if (!data.columns || !Array.isArray(data.columns) || data.columns.length === 0) {
|
|
1363
|
+
return null;
|
|
1364
|
+
}
|
|
1365
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1366
|
+
"div",
|
|
1367
|
+
{
|
|
1368
|
+
style: {
|
|
1369
|
+
border: "1px solid #e0e0e0",
|
|
1370
|
+
borderRadius: "12px",
|
|
1371
|
+
overflow: "hidden",
|
|
1372
|
+
fontSize: "13px",
|
|
1373
|
+
backgroundColor: "#ffffff",
|
|
1374
|
+
boxShadow: "0 2px 8px rgba(0, 0, 0, 0.08)",
|
|
1375
|
+
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif'
|
|
1376
|
+
},
|
|
1377
|
+
children: [
|
|
1378
|
+
data.caption && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1379
|
+
"div",
|
|
1380
|
+
{
|
|
1381
|
+
style: {
|
|
1382
|
+
padding: "16px 20px",
|
|
1383
|
+
fontWeight: 600,
|
|
1384
|
+
fontSize: "14px",
|
|
1385
|
+
borderBottom: "1px solid #e0e0e0",
|
|
1386
|
+
backgroundColor: "#f8f9fa",
|
|
1387
|
+
color: "#1a1a1a"
|
|
1388
|
+
},
|
|
1389
|
+
children: data.caption
|
|
1390
|
+
}
|
|
1391
|
+
),
|
|
1392
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: { overflowX: "auto" }, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1393
|
+
"table",
|
|
1394
|
+
{
|
|
1395
|
+
style: {
|
|
1396
|
+
width: "100%",
|
|
1397
|
+
borderCollapse: "collapse",
|
|
1398
|
+
minWidth: "100%"
|
|
1399
|
+
},
|
|
1400
|
+
children: [
|
|
1401
|
+
/* @__PURE__ */ jsxRuntime.jsx("thead", { style: { backgroundColor: "#f8f9fa" }, children: /* @__PURE__ */ jsxRuntime.jsx("tr", { children: data.columns.map((col, i) => {
|
|
1402
|
+
const colKey = typeof col === "string" ? `col-${i}` : col.key || col.id || `col-${i}`;
|
|
1403
|
+
const colLabel = typeof col === "string" ? col : col.label || "";
|
|
1404
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1405
|
+
"th",
|
|
1406
|
+
{
|
|
1407
|
+
style: {
|
|
1408
|
+
borderBottom: "2px solid #e0e0e0",
|
|
1409
|
+
padding: "14px 20px",
|
|
1410
|
+
textAlign: "left",
|
|
1411
|
+
fontWeight: 600,
|
|
1412
|
+
fontSize: "12px",
|
|
1413
|
+
color: "#4a5568",
|
|
1414
|
+
textTransform: "uppercase",
|
|
1415
|
+
letterSpacing: "0.5px",
|
|
1416
|
+
whiteSpace: "nowrap"
|
|
1417
|
+
},
|
|
1418
|
+
children: colLabel
|
|
1419
|
+
},
|
|
1420
|
+
colKey
|
|
1421
|
+
);
|
|
1422
|
+
}) }) }),
|
|
1423
|
+
/* @__PURE__ */ jsxRuntime.jsx("tbody", { children: data.rows && data.rows.length > 0 ? data.rows.map((row, rowIdx) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1424
|
+
"tr",
|
|
1425
|
+
{
|
|
1426
|
+
style: {
|
|
1427
|
+
backgroundColor: rowIdx % 2 === 0 ? "#ffffff" : "#fafbfc",
|
|
1428
|
+
transition: "background-color 0.15s ease"
|
|
1429
|
+
},
|
|
1430
|
+
onMouseEnter: (e) => {
|
|
1431
|
+
e.currentTarget.style.backgroundColor = "#f0f4f8";
|
|
1432
|
+
},
|
|
1433
|
+
onMouseLeave: (e) => {
|
|
1434
|
+
e.currentTarget.style.backgroundColor = rowIdx % 2 === 0 ? "#ffffff" : "#fafbfc";
|
|
1435
|
+
},
|
|
1436
|
+
children: data.columns.map((col, colIdx) => {
|
|
1437
|
+
const colKey = typeof col === "string" ? `col-${colIdx}` : col.key || col.id || `col-${colIdx}`;
|
|
1438
|
+
const colType = typeof col === "object" ? col.type : void 0;
|
|
1439
|
+
const cellKey = `cell-${rowIdx}-${colIdx}`;
|
|
1440
|
+
let cellContent = null;
|
|
1441
|
+
if (typeof row === "object" && row !== null && !Array.isArray(row)) {
|
|
1442
|
+
const cellValue = row[colKey];
|
|
1443
|
+
if (cellValue !== void 0 && cellValue !== null) {
|
|
1444
|
+
if (typeof cellValue === "object" && "type" in cellValue) {
|
|
1445
|
+
cellContent = renderField(cellValue);
|
|
1446
|
+
} else {
|
|
1447
|
+
const stringValue = String(cellValue);
|
|
1448
|
+
const isImageUrl = typeof stringValue === "string" && (stringValue.startsWith("http") || stringValue.startsWith("data:") || stringValue.startsWith("/")) && (stringValue.match(
|
|
1449
|
+
/\.(jpg|jpeg|png|gif|webp|svg)$/i
|
|
1450
|
+
) || stringValue.includes("image") || stringValue.includes("avatar"));
|
|
1451
|
+
if (colType === "image" || !colType && isImageUrl) {
|
|
1452
|
+
cellContent = /* @__PURE__ */ jsxRuntime.jsx(
|
|
1453
|
+
"div",
|
|
1454
|
+
{
|
|
1455
|
+
style: {
|
|
1456
|
+
display: "flex",
|
|
1457
|
+
alignItems: "center"
|
|
1458
|
+
},
|
|
1459
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1460
|
+
"img",
|
|
1461
|
+
{
|
|
1462
|
+
src: stringValue,
|
|
1463
|
+
alt: "",
|
|
1464
|
+
style: {
|
|
1465
|
+
width: "40px",
|
|
1466
|
+
height: "40px",
|
|
1467
|
+
borderRadius: "8px",
|
|
1468
|
+
objectFit: "cover",
|
|
1469
|
+
border: "1px solid #e0e0e0"
|
|
1470
|
+
},
|
|
1471
|
+
onError: (e) => {
|
|
1472
|
+
e.target.style.display = "none";
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
)
|
|
1476
|
+
}
|
|
1477
|
+
);
|
|
1478
|
+
} else {
|
|
1479
|
+
cellContent = /* @__PURE__ */ jsxRuntime.jsx(
|
|
1480
|
+
"span",
|
|
1481
|
+
{
|
|
1482
|
+
style: {
|
|
1483
|
+
color: "#2d3748",
|
|
1484
|
+
lineHeight: "1.5"
|
|
1485
|
+
},
|
|
1486
|
+
children: stringValue
|
|
1487
|
+
}
|
|
1488
|
+
);
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
} else if (Array.isArray(row)) {
|
|
1493
|
+
const cellValue = row[colIdx];
|
|
1494
|
+
if (cellValue !== void 0 && cellValue !== null) {
|
|
1495
|
+
const stringValue = String(cellValue);
|
|
1496
|
+
const isImageUrl = typeof stringValue === "string" && (stringValue.startsWith("http") || stringValue.startsWith("data:") || stringValue.startsWith("/")) && (stringValue.match(
|
|
1497
|
+
/\.(jpg|jpeg|png|gif|webp|svg)$/i
|
|
1498
|
+
) || stringValue.includes("image") || stringValue.includes("avatar"));
|
|
1499
|
+
if (colType === "image" || !colType && isImageUrl) {
|
|
1500
|
+
cellContent = /* @__PURE__ */ jsxRuntime.jsx(
|
|
1501
|
+
"div",
|
|
1502
|
+
{
|
|
1503
|
+
style: { display: "flex", alignItems: "center" },
|
|
1504
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1505
|
+
"img",
|
|
1506
|
+
{
|
|
1507
|
+
src: stringValue,
|
|
1508
|
+
alt: "",
|
|
1509
|
+
style: {
|
|
1510
|
+
width: "40px",
|
|
1511
|
+
height: "40px",
|
|
1512
|
+
borderRadius: "8px",
|
|
1513
|
+
objectFit: "cover",
|
|
1514
|
+
border: "1px solid #e0e0e0"
|
|
1515
|
+
},
|
|
1516
|
+
onError: (e) => {
|
|
1517
|
+
e.target.style.display = "none";
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
)
|
|
1521
|
+
}
|
|
1522
|
+
);
|
|
1523
|
+
} else {
|
|
1524
|
+
cellContent = /* @__PURE__ */ jsxRuntime.jsx(
|
|
1525
|
+
"span",
|
|
1526
|
+
{
|
|
1527
|
+
style: {
|
|
1528
|
+
color: "#2d3748",
|
|
1529
|
+
lineHeight: "1.5"
|
|
1530
|
+
},
|
|
1531
|
+
children: stringValue
|
|
1532
|
+
}
|
|
1533
|
+
);
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1538
|
+
"td",
|
|
1539
|
+
{
|
|
1540
|
+
style: {
|
|
1541
|
+
borderBottom: "1px solid #e8e8e8",
|
|
1542
|
+
padding: "16px 20px",
|
|
1543
|
+
fontSize: "13px",
|
|
1544
|
+
verticalAlign: "middle"
|
|
1545
|
+
},
|
|
1546
|
+
children: cellContent || /* @__PURE__ */ jsxRuntime.jsx(
|
|
1547
|
+
"span",
|
|
1548
|
+
{
|
|
1549
|
+
style: { color: "#a0a0a0", fontStyle: "italic" },
|
|
1550
|
+
children: "\u2014"
|
|
1551
|
+
}
|
|
1552
|
+
)
|
|
1553
|
+
},
|
|
1554
|
+
cellKey
|
|
1555
|
+
);
|
|
1556
|
+
})
|
|
1557
|
+
},
|
|
1558
|
+
`row-${rowIdx}`
|
|
1559
|
+
)) : /* @__PURE__ */ jsxRuntime.jsx("tr", { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1560
|
+
"td",
|
|
1561
|
+
{
|
|
1562
|
+
colSpan: data.columns.length,
|
|
1563
|
+
style: {
|
|
1564
|
+
padding: "40px",
|
|
1565
|
+
textAlign: "center",
|
|
1566
|
+
color: "#9ca3af",
|
|
1567
|
+
fontSize: "13px"
|
|
1568
|
+
},
|
|
1569
|
+
children: "Veri bulunamad\u0131"
|
|
1570
|
+
}
|
|
1571
|
+
) }) })
|
|
1572
|
+
]
|
|
1573
|
+
}
|
|
1574
|
+
) })
|
|
1575
|
+
]
|
|
1576
|
+
}
|
|
1577
|
+
);
|
|
1578
|
+
}
|
|
1579
|
+
function CardComponent({ data }) {
|
|
1580
|
+
if (data.title) {
|
|
1581
|
+
const hasImage = data.image && typeof data.image === "string";
|
|
1582
|
+
const hasFields = data.fields && Array.isArray(data.fields) && data.fields.length > 0;
|
|
1583
|
+
const hasAttributes = data.attributes && Array.isArray(data.attributes) && data.attributes.length > 0;
|
|
1584
|
+
const hasStatus = data.status && typeof data.status === "string";
|
|
1585
|
+
const hasSubtitle = data.subtitle && typeof data.subtitle === "string";
|
|
1586
|
+
const displayFields = hasAttributes ? data.attributes : hasFields ? data.fields : [];
|
|
1587
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1588
|
+
"div",
|
|
1589
|
+
{
|
|
1590
|
+
style: {
|
|
1591
|
+
border: "1px solid #e5e7eb",
|
|
1592
|
+
borderRadius: "16px",
|
|
1593
|
+
padding: "16px",
|
|
1594
|
+
backgroundColor: "#ffffff",
|
|
1595
|
+
boxShadow: "0 1px 3px 0 rgba(0, 0, 0, 0.1)",
|
|
1596
|
+
overflow: "hidden",
|
|
1597
|
+
marginBottom: "12px"
|
|
1598
|
+
},
|
|
1599
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", gap: "12px" }, children: [
|
|
1600
|
+
hasImage && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1601
|
+
"img",
|
|
1602
|
+
{
|
|
1603
|
+
src: data.image,
|
|
1604
|
+
alt: data.title || "Card image",
|
|
1605
|
+
style: {
|
|
1606
|
+
width: "64px",
|
|
1607
|
+
height: "64px",
|
|
1608
|
+
borderRadius: "8px",
|
|
1609
|
+
objectFit: "cover",
|
|
1610
|
+
flexShrink: 0
|
|
1611
|
+
},
|
|
1612
|
+
onError: (e) => {
|
|
1613
|
+
e.target.style.display = "none";
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
),
|
|
1617
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { flex: 1, minWidth: 0 }, children: [
|
|
1618
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1619
|
+
"h4",
|
|
1620
|
+
{
|
|
1621
|
+
style: {
|
|
1622
|
+
fontWeight: 600,
|
|
1623
|
+
fontSize: "14px",
|
|
1624
|
+
marginBottom: "8px",
|
|
1625
|
+
overflow: "hidden",
|
|
1626
|
+
textOverflow: "ellipsis",
|
|
1627
|
+
whiteSpace: "nowrap"
|
|
1628
|
+
},
|
|
1629
|
+
children: data.title
|
|
1630
|
+
}
|
|
1631
|
+
),
|
|
1632
|
+
hasStatus && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1633
|
+
"div",
|
|
1634
|
+
{
|
|
1635
|
+
style: {
|
|
1636
|
+
display: "flex",
|
|
1637
|
+
gap: "8px",
|
|
1638
|
+
fontSize: "12px",
|
|
1639
|
+
marginBottom: "4px"
|
|
1640
|
+
},
|
|
1641
|
+
children: [
|
|
1642
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { style: { color: "#6b7280", fontWeight: 500 }, children: "Durum:" }),
|
|
1643
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { style: { color: "#374151" }, children: data.status })
|
|
1644
|
+
]
|
|
1645
|
+
}
|
|
1646
|
+
),
|
|
1647
|
+
hasSubtitle && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1648
|
+
"p",
|
|
1649
|
+
{
|
|
1650
|
+
style: {
|
|
1651
|
+
color: "#6b7280",
|
|
1652
|
+
fontSize: "12px",
|
|
1653
|
+
marginBottom: "4px",
|
|
1654
|
+
margin: 0
|
|
1655
|
+
},
|
|
1656
|
+
children: data.subtitle
|
|
1657
|
+
}
|
|
1658
|
+
),
|
|
1659
|
+
displayFields && displayFields.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1660
|
+
"div",
|
|
1661
|
+
{
|
|
1662
|
+
style: { display: "flex", flexDirection: "column", gap: "4px" },
|
|
1663
|
+
children: displayFields.map((field, i) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1664
|
+
"div",
|
|
1665
|
+
{
|
|
1666
|
+
style: { display: "flex", gap: "8px", fontSize: "12px" },
|
|
1667
|
+
children: [
|
|
1668
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { style: { color: "#6b7280", fontWeight: 500 }, children: [
|
|
1669
|
+
field.label,
|
|
1670
|
+
":"
|
|
1671
|
+
] }),
|
|
1672
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { style: { color: "#374151" }, children: field.value })
|
|
1673
|
+
]
|
|
1674
|
+
},
|
|
1675
|
+
i
|
|
1676
|
+
))
|
|
1677
|
+
}
|
|
1678
|
+
),
|
|
1679
|
+
data.description && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1680
|
+
"p",
|
|
1681
|
+
{
|
|
1682
|
+
style: {
|
|
1683
|
+
color: "#6b7280",
|
|
1684
|
+
fontSize: "12px",
|
|
1685
|
+
marginTop: "8px",
|
|
1686
|
+
margin: 0
|
|
1687
|
+
},
|
|
1688
|
+
children: data.description
|
|
1689
|
+
}
|
|
1690
|
+
)
|
|
1691
|
+
] })
|
|
1692
|
+
] })
|
|
1693
|
+
}
|
|
1694
|
+
);
|
|
1695
|
+
}
|
|
1696
|
+
if (!data.items || !Array.isArray(data.items) || data.items.length === 0) {
|
|
1697
|
+
return null;
|
|
1698
|
+
}
|
|
1699
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { width: "100%" }, children: [
|
|
1700
|
+
data.title && !data.items.some((item) => item.title) && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1701
|
+
"h3",
|
|
1702
|
+
{
|
|
1703
|
+
style: {
|
|
1704
|
+
fontWeight: 600,
|
|
1705
|
+
marginBottom: "12px",
|
|
1706
|
+
fontSize: "14px",
|
|
1707
|
+
color: "#1a1a1a",
|
|
1708
|
+
marginTop: 0
|
|
1709
|
+
},
|
|
1710
|
+
children: data.title
|
|
1711
|
+
}
|
|
1712
|
+
),
|
|
1713
|
+
data.description && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1714
|
+
"p",
|
|
1715
|
+
{
|
|
1716
|
+
style: {
|
|
1717
|
+
color: "#6b7280",
|
|
1718
|
+
marginBottom: "12px",
|
|
1719
|
+
fontSize: "12px",
|
|
1720
|
+
marginTop: 0
|
|
1721
|
+
},
|
|
1722
|
+
children: data.description
|
|
1723
|
+
}
|
|
1724
|
+
),
|
|
1725
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1726
|
+
"div",
|
|
1727
|
+
{
|
|
1728
|
+
style: {
|
|
1729
|
+
display: "grid",
|
|
1730
|
+
gridTemplateColumns: "repeat(auto-fit, minmax(250px, 1fr))",
|
|
1731
|
+
gap: "12px"
|
|
1732
|
+
},
|
|
1733
|
+
children: data.items.map((item, i) => {
|
|
1734
|
+
const itemKey = item.id || `card-item-${i}`;
|
|
1735
|
+
const hasImage = item.image && typeof item.image === "string";
|
|
1736
|
+
const hasTitle = item.title && typeof item.title === "string";
|
|
1737
|
+
const hasSubtitle = item.subtitle && typeof item.subtitle === "string";
|
|
1738
|
+
const isLegacyFormat = item.label && item.value;
|
|
1739
|
+
if (isLegacyFormat && !hasTitle) {
|
|
1740
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1741
|
+
"div",
|
|
1742
|
+
{
|
|
1743
|
+
style: {
|
|
1744
|
+
border: "1px solid #e0e0e0",
|
|
1745
|
+
borderRadius: "12px",
|
|
1746
|
+
padding: "16px",
|
|
1747
|
+
backgroundColor: "#ffffff",
|
|
1748
|
+
boxShadow: "0 2px 8px rgba(0, 0, 0, 0.08)",
|
|
1749
|
+
fontSize: "12px"
|
|
1750
|
+
},
|
|
1751
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1752
|
+
"div",
|
|
1753
|
+
{
|
|
1754
|
+
style: {
|
|
1755
|
+
display: "flex",
|
|
1756
|
+
justifyContent: "space-between",
|
|
1757
|
+
gap: "8px"
|
|
1758
|
+
},
|
|
1759
|
+
children: [
|
|
1760
|
+
/* @__PURE__ */ jsxRuntime.jsx("dt", { style: { color: "#6b7280", margin: 0 }, children: item.label }),
|
|
1761
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1762
|
+
"dd",
|
|
1763
|
+
{
|
|
1764
|
+
style: {
|
|
1765
|
+
fontWeight: 500,
|
|
1766
|
+
color: "#1a1a1a",
|
|
1767
|
+
margin: 0
|
|
1768
|
+
},
|
|
1769
|
+
children: item.value
|
|
1770
|
+
}
|
|
1771
|
+
)
|
|
1772
|
+
]
|
|
1773
|
+
}
|
|
1774
|
+
)
|
|
1775
|
+
},
|
|
1776
|
+
itemKey
|
|
1777
|
+
);
|
|
1778
|
+
}
|
|
1779
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1780
|
+
"div",
|
|
1781
|
+
{
|
|
1782
|
+
style: {
|
|
1783
|
+
border: "1px solid #e0e0e0",
|
|
1784
|
+
borderRadius: "12px",
|
|
1785
|
+
padding: "16px",
|
|
1786
|
+
backgroundColor: "#ffffff",
|
|
1787
|
+
boxShadow: "0 2px 8px rgba(0, 0, 0, 0.08)",
|
|
1788
|
+
overflow: "hidden"
|
|
1789
|
+
},
|
|
1790
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", gap: "12px" }, children: [
|
|
1791
|
+
hasImage && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1792
|
+
"img",
|
|
1793
|
+
{
|
|
1794
|
+
src: item.image,
|
|
1795
|
+
alt: item.title || `Card ${i + 1}`,
|
|
1796
|
+
style: {
|
|
1797
|
+
width: "64px",
|
|
1798
|
+
height: "64px",
|
|
1799
|
+
borderRadius: "8px",
|
|
1800
|
+
objectFit: "cover",
|
|
1801
|
+
flexShrink: 0
|
|
1802
|
+
},
|
|
1803
|
+
onError: (e) => {
|
|
1804
|
+
e.target.style.display = "none";
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
),
|
|
1808
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1809
|
+
"div",
|
|
1810
|
+
{
|
|
1811
|
+
style: {
|
|
1812
|
+
flex: 1,
|
|
1813
|
+
minWidth: 0
|
|
1814
|
+
},
|
|
1815
|
+
children: [
|
|
1816
|
+
hasTitle && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1817
|
+
"h4",
|
|
1818
|
+
{
|
|
1819
|
+
style: {
|
|
1820
|
+
fontWeight: 600,
|
|
1821
|
+
fontSize: "14px",
|
|
1822
|
+
marginBottom: "4px",
|
|
1823
|
+
overflow: "hidden",
|
|
1824
|
+
textOverflow: "ellipsis",
|
|
1825
|
+
whiteSpace: "nowrap",
|
|
1826
|
+
color: "#1a1a1a",
|
|
1827
|
+
marginTop: 0
|
|
1828
|
+
},
|
|
1829
|
+
children: item.title
|
|
1830
|
+
}
|
|
1831
|
+
),
|
|
1832
|
+
hasSubtitle && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1833
|
+
"p",
|
|
1834
|
+
{
|
|
1835
|
+
style: {
|
|
1836
|
+
color: "#6b7280",
|
|
1837
|
+
fontSize: "12px",
|
|
1838
|
+
margin: 0
|
|
1839
|
+
},
|
|
1840
|
+
children: item.subtitle
|
|
1841
|
+
}
|
|
1842
|
+
)
|
|
1843
|
+
]
|
|
1844
|
+
}
|
|
1845
|
+
)
|
|
1846
|
+
] })
|
|
1847
|
+
},
|
|
1848
|
+
itemKey
|
|
1849
|
+
);
|
|
1850
|
+
})
|
|
1851
|
+
}
|
|
1852
|
+
)
|
|
1853
|
+
] });
|
|
1854
|
+
}
|
|
1855
|
+
function renderField(field) {
|
|
1856
|
+
switch (field.type) {
|
|
1857
|
+
case "text":
|
|
1858
|
+
return /* @__PURE__ */ jsxRuntime.jsx("span", { children: field.value });
|
|
1859
|
+
case "image":
|
|
1860
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1861
|
+
"img",
|
|
1862
|
+
{
|
|
1863
|
+
src: field.src,
|
|
1864
|
+
alt: field.alt ?? "",
|
|
1865
|
+
style: {
|
|
1866
|
+
width: 24,
|
|
1867
|
+
height: 24,
|
|
1868
|
+
borderRadius: "999px",
|
|
1869
|
+
objectFit: "cover"
|
|
1870
|
+
}
|
|
1871
|
+
}
|
|
1872
|
+
);
|
|
1873
|
+
case "link":
|
|
1874
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1875
|
+
"a",
|
|
1876
|
+
{
|
|
1877
|
+
href: field.href,
|
|
1878
|
+
target: "_blank",
|
|
1879
|
+
rel: "noreferrer",
|
|
1880
|
+
style: { textDecoration: "underline" },
|
|
1881
|
+
children: field.label
|
|
1882
|
+
}
|
|
1883
|
+
);
|
|
1884
|
+
case "badge":
|
|
1885
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1886
|
+
"span",
|
|
1887
|
+
{
|
|
1888
|
+
style: {
|
|
1889
|
+
display: "inline-block",
|
|
1890
|
+
padding: "2px 6px",
|
|
1891
|
+
borderRadius: 999,
|
|
1892
|
+
fontSize: 10,
|
|
1893
|
+
fontWeight: 500,
|
|
1894
|
+
backgroundColor: field.tone === "success" ? "#e0fce5" : field.tone === "warning" ? "#fff7d6" : field.tone === "danger" ? "#ffe4e4" : "#f2f2f2",
|
|
1895
|
+
color: field.tone === "success" ? "#1a7f36" : field.tone === "warning" ? "#8a6a00" : field.tone === "danger" ? "#b42318" : "#333"
|
|
1896
|
+
},
|
|
1897
|
+
children: field.label
|
|
1898
|
+
}
|
|
1899
|
+
);
|
|
1900
|
+
case "list":
|
|
1901
|
+
return /* @__PURE__ */ jsxRuntime.jsx("ul", { style: { margin: 0, paddingLeft: 16 }, children: field.items.map((item, i) => /* @__PURE__ */ jsxRuntime.jsx("li", { children: renderField(item) }, i)) });
|
|
1902
|
+
default:
|
|
1903
|
+
return null;
|
|
1904
|
+
}
|
|
1905
|
+
}
|
|
920
1906
|
var AizekChatBot = ({
|
|
921
1907
|
clientId,
|
|
922
1908
|
headers
|
|
@@ -956,9 +1942,7 @@ var AizekChatBot = ({
|
|
|
956
1942
|
const [isOpen, setIsOpen] = React.useState(false);
|
|
957
1943
|
const [headerValidation, setHeaderValidation] = React.useState(null);
|
|
958
1944
|
const [showAlert, setShowAlert] = React.useState(true);
|
|
959
|
-
console.log("Component rendered");
|
|
960
1945
|
React.useEffect(() => {
|
|
961
|
-
console.log("use");
|
|
962
1946
|
const loadConfig = async () => {
|
|
963
1947
|
try {
|
|
964
1948
|
setIsConfigLoading(true);
|
|
@@ -972,7 +1956,6 @@ var AizekChatBot = ({
|
|
|
972
1956
|
caseSensitive: true
|
|
973
1957
|
}
|
|
974
1958
|
);
|
|
975
|
-
console.log(validationResult);
|
|
976
1959
|
setHeaderValidation(validationResult);
|
|
977
1960
|
}
|
|
978
1961
|
setFinalMcpUrl(apiResponse.data.mcp_url);
|
|
@@ -1014,41 +1997,54 @@ var AizekChatBot = ({
|
|
|
1014
1997
|
}, [messages]);
|
|
1015
1998
|
const MessageBubble = ({ message, onAction }) => {
|
|
1016
1999
|
const isUser = message.role === "user";
|
|
1017
|
-
const cleanContent = DOMPurify__default.default.sanitize(message.content);
|
|
1018
|
-
const htmlRef = React.useRef(null);
|
|
1019
|
-
React.useEffect(() => {
|
|
1020
|
-
if (!htmlRef.current || isUser) return;
|
|
1021
|
-
const root = htmlRef.current;
|
|
1022
|
-
const approveBtn = root.querySelector(
|
|
1023
|
-
'button[data-ai-action="approve"]'
|
|
1024
|
-
);
|
|
1025
|
-
const cancelBtn = root.querySelector(
|
|
1026
|
-
'button[data-ai-action="cancel"]'
|
|
1027
|
-
);
|
|
1028
|
-
const handleApprove = () => onAction("__APPROVE__");
|
|
1029
|
-
const handleCancel = () => onAction("__CANCEL__");
|
|
1030
|
-
if (approveBtn) approveBtn.addEventListener("click", handleApprove);
|
|
1031
|
-
if (cancelBtn) cancelBtn.addEventListener("click", handleCancel);
|
|
1032
|
-
return () => {
|
|
1033
|
-
if (approveBtn) approveBtn.removeEventListener("click", handleApprove);
|
|
1034
|
-
if (cancelBtn) cancelBtn.removeEventListener("click", handleCancel);
|
|
1035
|
-
};
|
|
1036
|
-
}, [message.content, isUser, onAction]);
|
|
1037
2000
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: getMessageContainerStyles(isUser), children: [
|
|
1038
2001
|
/* @__PURE__ */ jsxRuntime.jsx("style", { children: getMarkdownElementStyles(isUser) }),
|
|
1039
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
}, children: /* @__PURE__ */ jsxRuntime.jsx(TypingDots, {}) })
|
|
2002
|
+
isUser && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
2003
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: getMessageBubbleStyles(isUser), children: message.text && /* @__PURE__ */ jsxRuntime.jsx("div", { style: getMarkdownStyles(), children: message.text }) }),
|
|
2004
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: getTimeStyles(isUser), children: message.timestamp.toLocaleTimeString("tr-TR", {
|
|
2005
|
+
hour: "2-digit",
|
|
2006
|
+
minute: "2-digit"
|
|
2007
|
+
}) })
|
|
1046
2008
|
] }),
|
|
1047
|
-
!isUser && /* @__PURE__ */ jsxRuntime.
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
2009
|
+
!isUser && message.role !== "approval" && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
2010
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2011
|
+
"div",
|
|
2012
|
+
{
|
|
2013
|
+
style: getMessageBubbleStyles(isUser, message.isTyping ?? false),
|
|
2014
|
+
children: message.isTyping ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
2015
|
+
"div",
|
|
2016
|
+
{
|
|
2017
|
+
style: {
|
|
2018
|
+
display: "inline-flex",
|
|
2019
|
+
alignItems: "center",
|
|
2020
|
+
marginLeft: message.text ? "8px" : "0"
|
|
2021
|
+
},
|
|
2022
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(TypingDots, {})
|
|
2023
|
+
}
|
|
2024
|
+
) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
2025
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: getMarkdownStyles(), className: "markdown-content", children: /* @__PURE__ */ jsxRuntime.jsx(ReactMarkdown__default.default, { remarkPlugins: [remarkGfm__default.default], children: message.text }) }),
|
|
2026
|
+
message.ui && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2027
|
+
UIRenderer,
|
|
2028
|
+
{
|
|
2029
|
+
components: message.ui,
|
|
2030
|
+
onInteraction: (event) => {
|
|
2031
|
+
console.log(event);
|
|
2032
|
+
if (event.type === "buttonClick" && typeof event.value === "string") {
|
|
2033
|
+
onAction(event.value, true);
|
|
2034
|
+
} else if (event.type === "formSubmit") {
|
|
2035
|
+
onAction(JSON.stringify(event.values), true);
|
|
2036
|
+
}
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
)
|
|
2040
|
+
] })
|
|
2041
|
+
}
|
|
2042
|
+
),
|
|
2043
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: getTimeStyles(isUser), children: message.timestamp.toLocaleTimeString("tr-TR", {
|
|
2044
|
+
hour: "2-digit",
|
|
2045
|
+
minute: "2-digit"
|
|
2046
|
+
}) })
|
|
2047
|
+
] })
|
|
1052
2048
|
] });
|
|
1053
2049
|
};
|
|
1054
2050
|
const TypingDots = () => {
|
|
@@ -1332,14 +2328,15 @@ var AizekChatBot = ({
|
|
|
1332
2328
|
MessageBubble,
|
|
1333
2329
|
{
|
|
1334
2330
|
message: {
|
|
1335
|
-
id:
|
|
1336
|
-
|
|
2331
|
+
id: `typing-${messages.length}`,
|
|
2332
|
+
text: "",
|
|
1337
2333
|
role: "assistant",
|
|
1338
2334
|
timestamp: /* @__PURE__ */ new Date(),
|
|
1339
2335
|
isTyping: true
|
|
1340
2336
|
},
|
|
1341
2337
|
onAction: handleSendMessage
|
|
1342
|
-
}
|
|
2338
|
+
},
|
|
2339
|
+
`typing-${messages.length}`
|
|
1343
2340
|
),
|
|
1344
2341
|
/* @__PURE__ */ jsxRuntime.jsx("div", { ref: messagesEndRef })
|
|
1345
2342
|
] }),
|