@mjml-agent-editor/editor 0.1.3 → 0.1.5

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
@@ -1389,6 +1389,39 @@ var SECTION_ARG = {
1389
1389
  remove_section: "section_id",
1390
1390
  insert_section: "after_section_id"
1391
1391
  };
1392
+ function toBlocks(parts) {
1393
+ const blocks = [];
1394
+ for (const part of parts) {
1395
+ if (part.type.startsWith("tool-")) {
1396
+ const last = blocks[blocks.length - 1];
1397
+ if (last?.kind === "tools") last.tools.push(part);
1398
+ else blocks.push({ kind: "tools", tools: [part] });
1399
+ continue;
1400
+ }
1401
+ if (part.type === "reasoning") {
1402
+ const text = part.text;
1403
+ if (!text.trim()) continue;
1404
+ const last = blocks[blocks.length - 1];
1405
+ if (last?.kind === "reasoning")
1406
+ blocks[blocks.length - 1] = { kind: "reasoning", text: `${last.text}${text}` };
1407
+ else blocks.push({ kind: "reasoning", text });
1408
+ continue;
1409
+ }
1410
+ if (part.type === "text") {
1411
+ if (!part.text.trim()) continue;
1412
+ blocks.push({ kind: "text", text: part.text, narration: false });
1413
+ }
1414
+ }
1415
+ let seenTools = false;
1416
+ for (let i = blocks.length - 1; i >= 0; i--) {
1417
+ const block = blocks[i];
1418
+ if (block.kind === "tools") seenTools = true;
1419
+ else if (block.kind === "text" && seenTools) {
1420
+ blocks[i] = { kind: "text", text: block.text, narration: true };
1421
+ }
1422
+ }
1423
+ return blocks;
1424
+ }
1392
1425
  function ToolMarker({ tool }) {
1393
1426
  const name = tool.type.slice(5);
1394
1427
  const done = tool.state === "output-available";
@@ -1414,7 +1447,7 @@ function ToolActivity({ tools }) {
1414
1447
  );
1415
1448
  const failedCount = finished.filter((t) => t.state === "output-error").length;
1416
1449
  return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("div", { className: "space-y-1 rounded-lg border border-panel-border bg-panel-elevated/60 p-2", children: [
1417
- finished.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(Collapsible, { defaultOpen: true, children: [
1450
+ finished.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(Collapsible, { children: [
1418
1451
  /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(CollapsibleTrigger, { className: "group/col flex w-full items-center gap-1.5 text-left text-xs font-medium text-panel-fg hover:text-panel-fg", children: [
1419
1452
  /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(import_lucide_react5.ChevronRight, { className: "size-3.5 shrink-0 transition-transform group-data-[state=open]/col:rotate-90" }),
1420
1453
  /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("span", { children: failedCount > 0 ? `Completed steps (${finished.length}, ${failedCount} failed)` : `Completed steps (${finished.length})` })
@@ -1424,6 +1457,16 @@ function ToolActivity({ tools }) {
1424
1457
  running.map((t, i) => /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(ToolMarker, { tool: t }, `r${i}`))
1425
1458
  ] });
1426
1459
  }
1460
+ function ReasoningBlock({ text }) {
1461
+ return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("div", { className: "rounded-lg border border-panel-border bg-panel-elevated/60 p-2", children: /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(Collapsible, { children: [
1462
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(CollapsibleTrigger, { className: "group/col flex w-full items-center gap-1.5 text-left text-xs font-medium text-panel-muted-fg hover:text-panel-fg", children: [
1463
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(import_lucide_react5.ChevronRight, { className: "size-3.5 shrink-0 transition-transform group-data-[state=open]/col:rotate-90" }),
1464
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(import_lucide_react5.Brain, { className: "size-3.5 shrink-0" }),
1465
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("span", { children: "Reasoning" })
1466
+ ] }),
1467
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(CollapsibleContent, { className: "mt-1.5 pl-1 text-xs whitespace-pre-wrap text-panel-muted-fg", children: text })
1468
+ ] }) });
1469
+ }
1427
1470
  function ChatPanel({
1428
1471
  docId,
1429
1472
  initialMessages,
@@ -1523,12 +1566,8 @@ function ChatPanel({
1523
1566
  ] }) }) : messages.map((message, mi) => {
1524
1567
  const isUser = message.role === "user";
1525
1568
  const isLast = mi === messages.length - 1;
1526
- const toolParts = message.parts.filter(
1527
- (p) => p.type.startsWith("tool-")
1528
- );
1529
- const textParts = message.parts.filter(
1530
- (p) => p.type === "text" && p.text.trim() !== ""
1531
- );
1569
+ const blocks = toBlocks(message.parts);
1570
+ const hasText = blocks.some((block) => block.kind === "text");
1532
1571
  return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(MessageScrollerItem, { messageId: message.id, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("div", { className: cn("flex w-full gap-2", isUser && "flex-row-reverse"), children: [
1533
1572
  !isUser && /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("span", { className: "mt-0.5 flex size-7 shrink-0 items-center justify-center rounded-full bg-brand/15 text-brand", children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(import_lucide_react5.Sparkles, { className: "size-3.5" }) }),
1534
1573
  /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(
@@ -1540,28 +1579,46 @@ function ChatPanel({
1540
1579
  ),
1541
1580
  children: [
1542
1581
  /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(Message, { align: isUser ? "end" : "start", children: /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(MessageContent, { children: [
1543
- toolParts.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(ToolActivity, { tools: toolParts }),
1544
- textParts.map((part, i) => /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
1545
- Bubble,
1546
- {
1547
- variant: isUser ? "default" : "muted",
1548
- align: isUser ? "end" : "start",
1549
- className: cn(
1550
- isUser ? "[&_[data-slot=bubble-content]]:bg-brand [&_[data-slot=bubble-content]]:text-brand-fg" : "[&_[data-slot=bubble-content]]:border [&_[data-slot=bubble-content]]:border-panel-border [&_[data-slot=bubble-content]]:bg-panel-elevated [&_[data-slot=bubble-content]]:text-panel-fg [&_code]:!bg-white/12 [&_pre]:!bg-white/10 [&_a]:text-brand"
1551
- ),
1552
- children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
1553
- BubbleContent,
1582
+ blocks.map((block, i) => {
1583
+ if (block.kind === "tools") {
1584
+ return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(ToolActivity, { tools: block.tools }, i);
1585
+ }
1586
+ if (block.kind === "reasoning") {
1587
+ return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(ReasoningBlock, { text: block.text }, i);
1588
+ }
1589
+ if (block.narration && !isUser) {
1590
+ return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
1591
+ "div",
1554
1592
  {
1555
- className: isUser ? "whitespace-pre-wrap" : void 0,
1556
- children: isUser && part.type === "text" ? part.text : part.type === "text" ? /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(Markdown, { children: part.text }) : null
1557
- }
1558
- )
1559
- },
1560
- i
1561
- )),
1562
- isLast && !isUser && busy && !toolRunning && textParts.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(BusyMarker, {})
1593
+ "data-slot": "narration",
1594
+ className: "px-1 text-xs leading-relaxed text-panel-muted-fg [&_a]:text-brand [&_code]:!bg-white/10 [&_p]:my-0.5",
1595
+ children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(Markdown, { children: block.text })
1596
+ },
1597
+ i
1598
+ );
1599
+ }
1600
+ return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
1601
+ Bubble,
1602
+ {
1603
+ variant: isUser ? "default" : "muted",
1604
+ align: isUser ? "end" : "start",
1605
+ className: cn(
1606
+ isUser ? "[&_[data-slot=bubble-content]]:bg-brand [&_[data-slot=bubble-content]]:text-brand-fg" : "[&_[data-slot=bubble-content]]:border [&_[data-slot=bubble-content]]:border-panel-border [&_[data-slot=bubble-content]]:bg-panel-elevated [&_[data-slot=bubble-content]]:text-panel-fg [&_code]:!bg-white/12 [&_pre]:!bg-white/10 [&_a]:text-brand"
1607
+ ),
1608
+ children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
1609
+ BubbleContent,
1610
+ {
1611
+ className: isUser ? "whitespace-pre-wrap" : void 0,
1612
+ children: isUser ? block.text : /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(Markdown, { children: block.text })
1613
+ }
1614
+ )
1615
+ },
1616
+ i
1617
+ );
1618
+ }),
1619
+ isLast && !isUser && busy && !toolRunning && !hasText && /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(BusyMarker, {})
1563
1620
  ] }) }),
1564
- (textParts.length > 0 || toolParts.length > 0) && /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("span", { className: "px-1 text-[10px] text-panel-muted-fg", children: timeFor(message.id) })
1621
+ blocks.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("span", { className: "px-1 text-[10px] text-panel-muted-fg", children: timeFor(message.id) })
1565
1622
  ]
1566
1623
  }
1567
1624
  )