@ash-cloud/ash-ui 0.0.8 → 0.1.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/dist/index.cjs CHANGED
@@ -1315,6 +1315,56 @@ function LazyMarkdown({ children, fallback, className }) {
1315
1315
  }
1316
1316
  return /* @__PURE__ */ jsxRuntime.jsx(react.Suspense, { fallback: /* @__PURE__ */ jsxRuntime.jsx("span", { className, children: fallback ?? children }), children: /* @__PURE__ */ jsxRuntime.jsx(ReactMarkdown, { children }) });
1317
1317
  }
1318
+ function DefaultMentionBadge({ segment }) {
1319
+ const bgColor = segment.color ? `${segment.color}20` : "rgba(34, 197, 94, 0.2)";
1320
+ const textColor = segment.color || "#22c55e";
1321
+ const borderColor = segment.color ? `${segment.color}40` : "rgba(34, 197, 94, 0.4)";
1322
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1323
+ "span",
1324
+ {
1325
+ className: "inline-flex items-center px-2 py-0.5 rounded-md text-xs font-medium mx-0.5",
1326
+ style: {
1327
+ backgroundColor: bgColor,
1328
+ color: textColor,
1329
+ border: `1px solid ${borderColor}`
1330
+ },
1331
+ title: segment.id ? `ID: ${segment.id}` : void 0,
1332
+ children: [
1333
+ "@",
1334
+ segment.name
1335
+ ]
1336
+ }
1337
+ );
1338
+ }
1339
+ function RichContentRenderer({
1340
+ content,
1341
+ renderers,
1342
+ className
1343
+ }) {
1344
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("rich-content", className), children: content.map((segment, index) => {
1345
+ const key = `segment-${index}`;
1346
+ switch (segment.type) {
1347
+ case "text":
1348
+ return /* @__PURE__ */ jsxRuntime.jsx(react.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx(LazyMarkdown, { children: segment.content }) }, key);
1349
+ case "mention":
1350
+ if (renderers?.renderMention) {
1351
+ return /* @__PURE__ */ jsxRuntime.jsx(react.Fragment, { children: renderers.renderMention({ segment }) }, key);
1352
+ }
1353
+ return /* @__PURE__ */ jsxRuntime.jsx(DefaultMentionBadge, { segment }, key);
1354
+ case "component":
1355
+ if (renderers?.renderComponent) {
1356
+ return /* @__PURE__ */ jsxRuntime.jsx(react.Fragment, { children: renderers.renderComponent({ segment }) }, key);
1357
+ }
1358
+ return /* @__PURE__ */ jsxRuntime.jsxs("code", { className: "text-xs text-orange-400", children: [
1359
+ "[component: ",
1360
+ segment.componentType,
1361
+ "]"
1362
+ ] }, key);
1363
+ default:
1364
+ return null;
1365
+ }
1366
+ }) });
1367
+ }
1318
1368
  function OptionCards({ options, onSelect, className }) {
1319
1369
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("grid gap-2 mt-3", className), style: {
1320
1370
  gridTemplateColumns: "repeat(auto-fit, minmax(200px, 1fr))"
@@ -1399,18 +1449,35 @@ function UserMessage({ entry, className }) {
1399
1449
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-7 h-7 rounded-full bg-white/10 flex items-center justify-center shrink-0", children: /* @__PURE__ */ jsxRuntime.jsx(UserIcon, { className: "w-4 h-4 text-white/50" }) })
1400
1450
  ] });
1401
1451
  }
1402
- function AssistantMessage({ entry, onOptionSelect, className }) {
1403
- const parsedOptions = parseOptionsFromContent(entry.content);
1452
+ function AssistantMessage({
1453
+ entry,
1454
+ onOptionSelect,
1455
+ richContentRenderers,
1456
+ className
1457
+ }) {
1458
+ const parsedOptions = !entry.richContent ? parseOptionsFromContent(entry.content) : null;
1404
1459
  const handleOptionSelect = (option) => {
1405
1460
  if (onOptionSelect) {
1406
1461
  onOptionSelect(`Option ${option.id}: ${option.label}`);
1407
1462
  }
1408
1463
  };
1464
+ const renderContent = (textContent) => {
1465
+ if (entry.richContent && entry.richContent.length > 0) {
1466
+ return /* @__PURE__ */ jsxRuntime.jsx(
1467
+ RichContentRenderer,
1468
+ {
1469
+ content: entry.richContent,
1470
+ renderers: richContentRenderers
1471
+ }
1472
+ );
1473
+ }
1474
+ return /* @__PURE__ */ jsxRuntime.jsx(LazyMarkdown, { children: textContent || entry.content });
1475
+ };
1409
1476
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("flex gap-3 ash-animate-fade-in", className), children: [
1410
1477
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-7 h-7 rounded-full bg-[var(--ash-accent)]/20 flex items-center justify-center shrink-0", children: /* @__PURE__ */ jsxRuntime.jsx(BotIcon, { className: "w-4 h-4 text-[var(--ash-accent)]" }) }),
1411
1478
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-1 max-w-[85%]", children: [
1412
1479
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "ash-card-glass rounded-2xl p-4", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "ash-message-content prose prose-sm prose-invert max-w-none text-sm leading-relaxed", children: parsedOptions ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1413
- parsedOptions.preamble && /* @__PURE__ */ jsxRuntime.jsx(LazyMarkdown, { children: parsedOptions.preamble }),
1480
+ parsedOptions.preamble && renderContent(parsedOptions.preamble),
1414
1481
  /* @__PURE__ */ jsxRuntime.jsx(
1415
1482
  OptionCards,
1416
1483
  {
@@ -1418,7 +1485,7 @@ function AssistantMessage({ entry, onOptionSelect, className }) {
1418
1485
  onSelect: handleOptionSelect
1419
1486
  }
1420
1487
  )
1421
- ] }) : /* @__PURE__ */ jsxRuntime.jsx(LazyMarkdown, { children: entry.content }) }) }),
1488
+ ] }) : renderContent() }) }),
1422
1489
  entry.timestamp && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs text-white/40 mt-2", children: formatTimestamp(entry.timestamp) })
1423
1490
  ] })
1424
1491
  ] });
@@ -1453,12 +1520,26 @@ function ErrorMessage({ entry, className }) {
1453
1520
  ] }) })
1454
1521
  ] });
1455
1522
  }
1456
- function MessageEntry({ entry, onOptionSelect, defaultExpanded, className }) {
1523
+ function MessageEntry({
1524
+ entry,
1525
+ onOptionSelect,
1526
+ defaultExpanded,
1527
+ richContentRenderers,
1528
+ className
1529
+ }) {
1457
1530
  switch (entry.entryType.type) {
1458
1531
  case "user_message":
1459
1532
  return /* @__PURE__ */ jsxRuntime.jsx(UserMessage, { entry, className });
1460
1533
  case "assistant_message":
1461
- return /* @__PURE__ */ jsxRuntime.jsx(AssistantMessage, { entry, onOptionSelect, className });
1534
+ return /* @__PURE__ */ jsxRuntime.jsx(
1535
+ AssistantMessage,
1536
+ {
1537
+ entry,
1538
+ onOptionSelect,
1539
+ richContentRenderers,
1540
+ className
1541
+ }
1542
+ );
1462
1543
  case "thinking":
1463
1544
  return /* @__PURE__ */ jsxRuntime.jsx(ThinkingMessage, { entry, className });
1464
1545
  case "tool_call":
@@ -2135,6 +2216,7 @@ function MessageList({
2135
2216
  renderWidget,
2136
2217
  onWidgetAction,
2137
2218
  autoScroll = true,
2219
+ richContentRenderers,
2138
2220
  className
2139
2221
  }) {
2140
2222
  const contextConfig = useDisplayConfig();
@@ -2185,7 +2267,16 @@ function MessageList({
2185
2267
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "ash-animate-fade-in", children: widgetContent }, entry.id);
2186
2268
  }
2187
2269
  }
2188
- return /* @__PURE__ */ jsxRuntime.jsx(MessageEntry, { entry, onOptionSelect, defaultExpanded: config.defaultExpanded }, entry.id);
2270
+ return /* @__PURE__ */ jsxRuntime.jsx(
2271
+ MessageEntry,
2272
+ {
2273
+ entry,
2274
+ onOptionSelect,
2275
+ defaultExpanded: config.defaultExpanded,
2276
+ richContentRenderers
2277
+ },
2278
+ entry.id
2279
+ );
2189
2280
  }
2190
2281
  const toolCalls = extractToolCallsFromGroup(groupedEntry.entries);
2191
2282
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-3 ash-animate-fade-in", children: [
@@ -3747,6 +3838,7 @@ exports.MoonIcon = MoonIcon;
3747
3838
  exports.OptionCards = OptionCards;
3748
3839
  exports.PaperclipIcon = PaperclipIcon;
3749
3840
  exports.PlugIcon = PlugIcon;
3841
+ exports.RichContentRenderer = RichContentRenderer;
3750
3842
  exports.SearchIcon = SearchIcon;
3751
3843
  exports.SendIcon = SendIcon;
3752
3844
  exports.SparklesIcon = SparklesIcon;