agentic-ui-libs 1.0.0-beta.4 → 1.0.0-beta.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.js CHANGED
@@ -1482,19 +1482,6 @@ const Minimize2 = createLucideIcon("Minimize2", [
1482
1482
  * See the LICENSE file in the root directory of this source tree.
1483
1483
  */
1484
1484
  const Minus = createLucideIcon("Minus", [["path", { d: "M5 12h14", key: "1ays0h" }]]);
1485
- /**
1486
- * @license lucide-react v0.294.0 - ISC
1487
- *
1488
- * This source code is licensed under the ISC license.
1489
- * See the LICENSE file in the root directory of this source tree.
1490
- */
1491
- const MousePointerClick = createLucideIcon("MousePointerClick", [
1492
- ["path", { d: "m9 9 5 12 1.8-5.2L21 14Z", key: "1b76lo" }],
1493
- ["path", { d: "M7.2 2.2 8 5.1", key: "1cfko1" }],
1494
- ["path", { d: "m5.1 8-2.9-.8", key: "1go3kf" }],
1495
- ["path", { d: "M14 4.1 12 6", key: "ita8i4" }],
1496
- ["path", { d: "m6 12-1.9 2", key: "mnht97" }]
1497
- ]);
1498
1485
  /**
1499
1486
  * @license lucide-react v0.294.0 - ISC
1500
1487
  *
@@ -69094,21 +69081,25 @@ const SlashMenu = forwardRef(
69094
69081
  agents: agents2 = [],
69095
69082
  tools: tools2 = [],
69096
69083
  knowledge: knowledge2 = [],
69097
- envVariables: _envVariables = [],
69098
- memoryVariables: _memoryVariables = [],
69099
- systemVariables: _systemVariables = [],
69084
+ envVariables: envVariables2 = [],
69085
+ memoryVariables = [],
69086
+ systemVariables: systemVariables2 = [],
69100
69087
  contentVariables = [],
69101
69088
  highlightMentions = false,
69102
69089
  // Default: plain text
69103
- range: range3
69090
+ range: range3,
69104
69091
  // The range of the slash command trigger (to delete it)
69092
+ hiddenCategories = []
69093
+ // Categories to hide
69105
69094
  }, ref) => {
69106
69095
  const [activeCategory, setActiveCategory] = useState(null);
69107
69096
  const [selectedIndex, setSelectedIndex] = useState(0);
69097
+ const [subcategorySearch, setSubcategorySearch] = useState("");
69108
69098
  const menuRef = useRef(null);
69109
69099
  const blockItemsRef = useRef(null);
69110
69100
  const categoryListRef = useRef(null);
69111
69101
  const itemRefs = useRef(/* @__PURE__ */ new Map());
69102
+ const searchInputRef = useRef(null);
69112
69103
  const allCategories = [
69113
69104
  {
69114
69105
  id: "agents",
@@ -69133,13 +69124,41 @@ const SlashMenu = forwardRef(
69133
69124
  hasSubmenu: true,
69134
69125
  disabled: knowledge2.length === 0,
69135
69126
  disabledReason: "No knowledge bases available"
69127
+ },
69128
+ {
69129
+ id: "env",
69130
+ label: "Environment Variables",
69131
+ type: "env",
69132
+ hasSubmenu: true,
69133
+ disabled: envVariables2.length === 0,
69134
+ disabledReason: "No environment variables available"
69135
+ },
69136
+ {
69137
+ id: "memory",
69138
+ label: "Memory Variables",
69139
+ type: "memory",
69140
+ hasSubmenu: true,
69141
+ disabled: memoryVariables.length === 0,
69142
+ disabledReason: "No memory variables available"
69143
+ },
69144
+ {
69145
+ id: "system",
69146
+ label: "System Variables",
69147
+ type: "system",
69148
+ hasSubmenu: true,
69149
+ disabled: systemVariables2.length === 0,
69150
+ disabledReason: "No system variables available"
69136
69151
  }
69137
69152
  ];
69153
+ const showBlocks = !hiddenCategories.includes("blocks");
69154
+ const visibleCategories = allCategories.filter((cat) => !hiddenCategories.includes(cat.id));
69138
69155
  const getCurrentItems = useCallback(() => {
69139
69156
  if (!activeCategory) {
69140
69157
  const result = [];
69141
- result.push(...BLOCK_ITEMS);
69142
- result.push(...allCategories);
69158
+ if (showBlocks) {
69159
+ result.push(...BLOCK_ITEMS);
69160
+ }
69161
+ result.push(...visibleCategories);
69143
69162
  if (query) {
69144
69163
  return result.filter((item) => {
69145
69164
  if ("label" in item) {
@@ -69166,29 +69185,43 @@ const SlashMenu = forwardRef(
69166
69185
  case "knowledge":
69167
69186
  items = knowledge2;
69168
69187
  break;
69188
+ case "env":
69189
+ items = envVariables2;
69190
+ break;
69191
+ case "memory":
69192
+ items = memoryVariables;
69193
+ break;
69194
+ case "system":
69195
+ items = systemVariables2;
69196
+ break;
69169
69197
  case "content":
69170
69198
  items = contentVariables;
69171
69199
  break;
69172
69200
  }
69173
- if (query) {
69201
+ const searchTerm = subcategorySearch.toLowerCase();
69202
+ if (searchTerm) {
69174
69203
  items = items.filter((item) => {
69175
69204
  var _a;
69176
69205
  if ("label" in item) {
69177
- return item.label.toLowerCase().includes(query.toLowerCase()) || ((_a = item.keywords) == null ? void 0 : _a.some(
69178
- (k3) => k3.toLowerCase().includes(query.toLowerCase())
69206
+ return item.label.toLowerCase().includes(searchTerm) || ((_a = item.keywords) == null ? void 0 : _a.some(
69207
+ (k3) => k3.toLowerCase().includes(searchTerm)
69179
69208
  ));
69180
69209
  }
69181
- return item.name.toLowerCase().includes(query.toLowerCase());
69210
+ const name = item.name.toLowerCase();
69211
+ const description = "description" in item ? (item.description || "").toLowerCase() : "";
69212
+ const path = "path" in item ? (item.path || "").toLowerCase() : "";
69213
+ return name.includes(searchTerm) || description.includes(searchTerm) || path.includes(searchTerm);
69182
69214
  });
69183
69215
  }
69184
69216
  return items;
69185
- }, [activeCategory, query, agents2, tools2, knowledge2, contentVariables, allCategories]);
69217
+ }, [activeCategory, subcategorySearch, agents2, tools2, knowledge2, envVariables2, memoryVariables, systemVariables2, contentVariables, allCategories]);
69186
69218
  const currentItems = getCurrentItems();
69187
69219
  const getAllNavigableItems = useCallback(() => {
69188
69220
  if (activeCategory) {
69189
69221
  return currentItems;
69190
69222
  }
69191
- const filteredBlocks = query ? BLOCK_ITEMS.filter((item) => {
69223
+ const blocksToShow = showBlocks ? BLOCK_ITEMS : [];
69224
+ const filteredBlocks = query ? blocksToShow.filter((item) => {
69192
69225
  const label = item.label.toLowerCase();
69193
69226
  const q2 = query.toLowerCase();
69194
69227
  if (label.includes(q2)) return true;
@@ -69196,14 +69229,14 @@ const SlashMenu = forwardRef(
69196
69229
  return item.keywords.some((k3) => k3.toLowerCase().includes(q2));
69197
69230
  }
69198
69231
  return false;
69199
- }) : BLOCK_ITEMS;
69200
- const filteredCats = query ? allCategories.filter((cat) => cat.label.toLowerCase().includes(query.toLowerCase())) : allCategories;
69232
+ }) : blocksToShow;
69233
+ const filteredCats = query ? visibleCategories.filter((cat) => cat.label.toLowerCase().includes(query.toLowerCase())) : visibleCategories;
69201
69234
  return [...filteredBlocks, ...filteredCats];
69202
- }, [activeCategory, currentItems, query, allCategories]);
69235
+ }, [activeCategory, currentItems, query, showBlocks, visibleCategories]);
69203
69236
  const navigableItems = getAllNavigableItems();
69204
69237
  useEffect(() => {
69205
69238
  setSelectedIndex(0);
69206
- }, [navigableItems.length, activeCategory, query]);
69239
+ }, [navigableItems.length, activeCategory, query, subcategorySearch]);
69207
69240
  useEffect(() => {
69208
69241
  const itemElement = itemRefs.current.get(selectedIndex);
69209
69242
  if (itemElement) {
@@ -69250,12 +69283,14 @@ const SlashMenu = forwardRef(
69250
69283
  if (event.key === "Escape") {
69251
69284
  if (activeCategory) {
69252
69285
  setActiveCategory(null);
69286
+ setSubcategorySearch("");
69253
69287
  return true;
69254
69288
  }
69255
69289
  return false;
69256
69290
  }
69257
- if (event.key === "Backspace" && !query && activeCategory) {
69291
+ if (event.key === "Backspace" && !query && !subcategorySearch && activeCategory) {
69258
69292
  setActiveCategory(null);
69293
+ setSubcategorySearch("");
69259
69294
  return true;
69260
69295
  }
69261
69296
  return false;
@@ -69277,6 +69312,7 @@ const SlashMenu = forwardRef(
69277
69312
  if ("hasSubmenu" in item && item.hasSubmenu) {
69278
69313
  setActiveCategory(item.id);
69279
69314
  setSelectedIndex(0);
69315
+ setSubcategorySearch("");
69280
69316
  return;
69281
69317
  }
69282
69318
  if ("action" in item && typeof item.action === "function") {
@@ -69301,11 +69337,25 @@ const SlashMenu = forwardRef(
69301
69337
  }
69302
69338
  return;
69303
69339
  }
69340
+ if ("path" in item && "type" in item) {
69341
+ const variable = item;
69342
+ deleteSlashTrigger();
69343
+ editor.chain().focus().insertContent({
69344
+ type: "variableChip",
69345
+ attrs: {
69346
+ variableType: variable.type,
69347
+ path: variable.path,
69348
+ displayName: variable.name
69349
+ }
69350
+ }).insertContent(" ").run();
69351
+ return;
69352
+ }
69304
69353
  command2(item);
69305
69354
  };
69306
69355
  const handleBack = () => {
69307
69356
  setActiveCategory(null);
69308
69357
  setSelectedIndex(0);
69358
+ setSubcategorySearch("");
69309
69359
  };
69310
69360
  const getIcon = (item) => {
69311
69361
  if ("action" in item && item.icon) {
@@ -69343,7 +69393,8 @@ const SlashMenu = forwardRef(
69343
69393
  const category = categories.find((c3) => c3.id === activeCategory);
69344
69394
  return (category == null ? void 0 : category.label) || activeCategory;
69345
69395
  };
69346
- const filteredBlockItems = query ? BLOCK_ITEMS.filter((item) => {
69396
+ const blocksSource = showBlocks ? BLOCK_ITEMS : [];
69397
+ const filteredBlockItems = query ? blocksSource.filter((item) => {
69347
69398
  const label = item.label.toLowerCase();
69348
69399
  const q2 = query.toLowerCase();
69349
69400
  if (label.includes(q2)) return true;
@@ -69351,8 +69402,8 @@ const SlashMenu = forwardRef(
69351
69402
  return item.keywords.some((k3) => k3.toLowerCase().includes(q2));
69352
69403
  }
69353
69404
  return false;
69354
- }) : BLOCK_ITEMS;
69355
- const filteredCategoryItems = query ? allCategories.filter((cat) => cat.label.toLowerCase().includes(query.toLowerCase())) : allCategories;
69405
+ }) : blocksSource;
69406
+ const filteredCategoryItems = query ? visibleCategories.filter((cat) => cat.label.toLowerCase().includes(query.toLowerCase())) : visibleCategories;
69356
69407
  const hasBlockItems = !activeCategory && filteredBlockItems.length > 0;
69357
69408
  const hasCategoryItems = !activeCategory && filteredCategoryItems.length > 0;
69358
69409
  if (!hasBlockItems && !hasCategoryItems && !activeCategory) {
@@ -69396,58 +69447,81 @@ const SlashMenu = forwardRef(
69396
69447
  )
69397
69448
  ] }),
69398
69449
  hasBlockItems && (hasCategoryItems || activeCategory) && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-px bg-gray-200 mx-2" }),
69399
- activeCategory && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "px-3 py-2 border-b border-gray-200 flex items-center gap-2", children: [
69400
- /* @__PURE__ */ jsxRuntimeExports.jsx(
69401
- "button",
69402
- {
69403
- type: "button",
69404
- onClick: handleBack,
69405
- className: "flex items-center justify-center w-6 h-6 p-0 border-0 bg-gray-100 rounded cursor-pointer text-gray-500 hover:bg-gray-200",
69406
- "aria-label": "Go back",
69407
- "data-id": "md-editor-slash-back-btn",
69408
- children: /* @__PURE__ */ jsxRuntimeExports.jsx(ChevronLeft, { size: 16 })
69409
- }
69410
- ),
69411
- /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-xs font-medium text-gray-500 flex-1", children: getTitle() })
69450
+ activeCategory && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "border-b border-gray-200", children: [
69451
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "px-3 py-2 flex items-center gap-2", children: [
69452
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
69453
+ "button",
69454
+ {
69455
+ type: "button",
69456
+ onClick: handleBack,
69457
+ className: "flex items-center justify-center w-6 h-6 p-0 border-0 bg-gray-100 rounded cursor-pointer text-gray-500 hover:bg-gray-200",
69458
+ "aria-label": "Go back",
69459
+ "data-id": "md-editor-slash-back-btn",
69460
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx(ChevronLeft, { size: 16 })
69461
+ }
69462
+ ),
69463
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-xs font-medium text-gray-500 flex-1", children: getTitle() })
69464
+ ] }),
69465
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "px-2 pb-2", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2 px-2.5 py-1.5 rounded-md bg-gray-50", children: [
69466
+ /* @__PURE__ */ jsxRuntimeExports.jsx(Search, { size: 14, className: "text-gray-400 shrink-0" }),
69467
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
69468
+ "input",
69469
+ {
69470
+ ref: searchInputRef,
69471
+ type: "text",
69472
+ value: subcategorySearch,
69473
+ onChange: (e3) => {
69474
+ setSubcategorySearch(e3.target.value);
69475
+ setSelectedIndex(0);
69476
+ },
69477
+ placeholder: "Search...",
69478
+ className: "flex-1 bg-transparent text-sm border-0 outline-none text-gray-700 placeholder:text-gray-400",
69479
+ "data-id": "md-editor-slash-search"
69480
+ }
69481
+ )
69482
+ ] }) })
69412
69483
  ] }),
69413
69484
  (hasCategoryItems || activeCategory) && /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
69414
69485
  !activeCategory && hasCategoryItems && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "px-2 pt-2 pb-1", children: /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-[11px] font-semibold text-gray-400 uppercase tracking-wide pl-1", children: "Insert" }) }),
69415
- /* @__PURE__ */ jsxRuntimeExports.jsx(
69486
+ /* @__PURE__ */ jsxRuntimeExports.jsxs(
69416
69487
  "div",
69417
69488
  {
69418
69489
  ref: categoryListRef,
69419
69490
  className: "flex-1 overflow-y-auto px-2 pb-2 pt-1",
69420
- children: (activeCategory ? currentItems : filteredCategoryItems).map((item, index) => {
69421
- var _a;
69422
- const adjustedIndex = activeCategory ? index : blockItemsCount + index;
69423
- const isCategory = "hasSubmenu" in item && item.hasSubmenu;
69424
- const hasSubmenu = isCategory || "children" in item && ((_a = item.children) == null ? void 0 : _a.length);
69425
- const label = "label" in item ? item.label : item.name;
69426
- const isSelected = selectedIndex === adjustedIndex;
69427
- const isDisabled = "disabled" in item && item.disabled;
69428
- const disabledReason = "disabledReason" in item ? item.disabledReason : void 0;
69429
- return /* @__PURE__ */ jsxRuntimeExports.jsxs(
69430
- "button",
69431
- {
69432
- ref: (el) => {
69433
- if (el) itemRefs.current.set(adjustedIndex, el);
69491
+ children: [
69492
+ activeCategory && currentItems.length === 0 && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "py-4 text-center text-gray-400 text-sm", children: subcategorySearch ? `No results for "${subcategorySearch}"` : "No items available" }),
69493
+ (activeCategory ? currentItems : filteredCategoryItems).map((item, index) => {
69494
+ var _a;
69495
+ const adjustedIndex = activeCategory ? index : blockItemsCount + index;
69496
+ const isCategory = "hasSubmenu" in item && item.hasSubmenu;
69497
+ const hasSubmenu = isCategory || "children" in item && ((_a = item.children) == null ? void 0 : _a.length);
69498
+ const label = "label" in item ? item.label : item.name;
69499
+ const isSelected = selectedIndex === adjustedIndex;
69500
+ const isDisabled = "disabled" in item && item.disabled;
69501
+ const disabledReason = "disabledReason" in item ? item.disabledReason : void 0;
69502
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs(
69503
+ "button",
69504
+ {
69505
+ ref: (el) => {
69506
+ if (el) itemRefs.current.set(adjustedIndex, el);
69507
+ },
69508
+ type: "button",
69509
+ onClick: () => handleItemClick(item),
69510
+ disabled: isDisabled,
69511
+ title: isDisabled ? disabledReason : void 0,
69512
+ className: `flex items-center gap-2.5 w-full py-2 px-2.5 border-0 rounded-md text-left transition-colors duration-100 ${isDisabled ? "cursor-not-allowed opacity-50" : "cursor-pointer"} ${isSelected && !isDisabled ? "bg-gray-100" : "bg-transparent hover:bg-gray-100"}`,
69513
+ onMouseEnter: () => !isDisabled && setSelectedIndex(adjustedIndex),
69514
+ "data-id": `md-editor-slash-item-${"id" in item ? item.id : label.toLowerCase().replace(/\s+/g, "-")}`,
69515
+ children: [
69516
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: `flex items-center justify-center w-7 h-7 rounded-md bg-gray-100 shrink-0 ${isDisabled ? "text-gray-300" : "text-gray-500"}`, children: getIcon(item) }),
69517
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-1 min-w-0", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `text-[13px] font-medium truncate ${isDisabled ? "text-gray-400" : "text-gray-800"}`, children: label }) }),
69518
+ hasSubmenu && /* @__PURE__ */ jsxRuntimeExports.jsx(ChevronRight, { size: 14, className: `shrink-0 ${isDisabled ? "text-gray-300" : "text-gray-400"}` })
69519
+ ]
69434
69520
  },
69435
- type: "button",
69436
- onClick: () => handleItemClick(item),
69437
- disabled: isDisabled,
69438
- title: isDisabled ? disabledReason : void 0,
69439
- className: `flex items-center gap-2.5 w-full py-2 px-2.5 border-0 rounded-md text-left transition-colors duration-100 ${isDisabled ? "cursor-not-allowed opacity-50" : "cursor-pointer"} ${isSelected && !isDisabled ? "bg-gray-100" : "bg-transparent hover:bg-gray-100"}`,
69440
- onMouseEnter: () => !isDisabled && setSelectedIndex(adjustedIndex),
69441
- "data-id": `md-editor-slash-item-${"id" in item ? item.id : label.toLowerCase().replace(/\s+/g, "-")}`,
69442
- children: [
69443
- /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: `flex items-center justify-center w-7 h-7 rounded-md bg-gray-100 shrink-0 ${isDisabled ? "text-gray-300" : "text-gray-500"}`, children: getIcon(item) }),
69444
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-1 min-w-0", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `text-[13px] font-medium truncate ${isDisabled ? "text-gray-400" : "text-gray-800"}`, children: label }) }),
69445
- hasSubmenu && /* @__PURE__ */ jsxRuntimeExports.jsx(ChevronRight, { size: 14, className: `shrink-0 ${isDisabled ? "text-gray-300" : "text-gray-400"}` })
69446
- ]
69447
- },
69448
- "id" in item ? item.id : index
69449
- );
69450
- })
69521
+ "id" in item ? item.id : index
69522
+ );
69523
+ })
69524
+ ]
69451
69525
  }
69452
69526
  )
69453
69527
  ] })
@@ -69457,6 +69531,7 @@ const SlashMenu = forwardRef(
69457
69531
  }
69458
69532
  );
69459
69533
  SlashMenu.displayName = "SlashMenu";
69534
+ const SlashSuggestionPluginKey = new PluginKey("slashSuggestion");
69460
69535
  const SlashCommandExtension = Extension.create({
69461
69536
  name: "slashCommand",
69462
69537
  addOptions() {
@@ -69485,7 +69560,7 @@ const SlashCommandExtension = Extension.create({
69485
69560
  editor: this.editor,
69486
69561
  char: this.options.suggestion.char || "/",
69487
69562
  startOfLine: this.options.suggestion.startOfLine ?? false,
69488
- pluginKey: this.options.suggestion.pluginKey,
69563
+ pluginKey: SlashSuggestionPluginKey,
69489
69564
  allow: ({ state, range: range3 }) => {
69490
69565
  const $from = state.doc.resolve(range3.from);
69491
69566
  const isInCode = $from.parent.type.name === "codeBlock";
@@ -69596,6 +69671,119 @@ function createSlashCommandSuggestion(categories, onCommand) {
69596
69671
  }
69597
69672
  };
69598
69673
  }
69674
+ const MentionSuggestionPluginKey = new PluginKey("mentionSuggestion");
69675
+ const MentionCommandExtension = Extension.create({
69676
+ name: "mentionCommand",
69677
+ addOptions() {
69678
+ return {
69679
+ agents: [],
69680
+ tools: [],
69681
+ knowledge: [],
69682
+ onSelectItem: void 0
69683
+ };
69684
+ },
69685
+ addProseMirrorPlugins() {
69686
+ return [
69687
+ Suggestion({
69688
+ editor: this.editor,
69689
+ char: "@",
69690
+ startOfLine: false,
69691
+ pluginKey: MentionSuggestionPluginKey,
69692
+ allow: ({ state, range: range3 }) => {
69693
+ const $from = state.doc.resolve(range3.from);
69694
+ const isInCode = $from.parent.type.name === "codeBlock";
69695
+ return !isInCode;
69696
+ },
69697
+ items: () => [],
69698
+ command: ({ editor, range: range3 }) => {
69699
+ editor.chain().focus().deleteRange(range3).run();
69700
+ },
69701
+ render: () => {
69702
+ let component = null;
69703
+ let popup = null;
69704
+ return {
69705
+ onStart: (props) => {
69706
+ component = new ReactRenderer(SlashMenu, {
69707
+ props: {
69708
+ ...props,
69709
+ agents: this.options.agents,
69710
+ tools: this.options.tools,
69711
+ knowledge: this.options.knowledge,
69712
+ // No variables or blocks for @ mentions
69713
+ envVariables: [],
69714
+ memoryVariables: [],
69715
+ systemVariables: [],
69716
+ contentVariables: [],
69717
+ highlightMentions: false,
69718
+ // Insert as plain bold text
69719
+ hiddenCategories: ["blocks"],
69720
+ // Hide blocks category
69721
+ range: props.range,
69722
+ command: (item) => {
69723
+ props.editor.chain().focus().deleteRange(props.range).run();
69724
+ props.editor.chain().focus().insertContent(`**@${item.name}** `).run();
69725
+ if (this.options.onSelectItem) {
69726
+ this.options.onSelectItem(item);
69727
+ }
69728
+ }
69729
+ },
69730
+ editor: props.editor
69731
+ });
69732
+ if (!props.clientRect) {
69733
+ return;
69734
+ }
69735
+ popup = tippy("body", {
69736
+ getReferenceClientRect: props.clientRect,
69737
+ appendTo: () => document.body,
69738
+ content: component.element,
69739
+ showOnCreate: true,
69740
+ interactive: true,
69741
+ trigger: "manual",
69742
+ placement: "bottom-start",
69743
+ maxWidth: "none"
69744
+ });
69745
+ },
69746
+ onUpdate: (props) => {
69747
+ var _a;
69748
+ component == null ? void 0 : component.updateProps({
69749
+ ...props,
69750
+ agents: this.options.agents,
69751
+ tools: this.options.tools,
69752
+ knowledge: this.options.knowledge,
69753
+ envVariables: [],
69754
+ memoryVariables: [],
69755
+ systemVariables: [],
69756
+ contentVariables: [],
69757
+ highlightMentions: false,
69758
+ hiddenCategories: ["blocks"],
69759
+ range: props.range
69760
+ });
69761
+ if (!props.clientRect) {
69762
+ return;
69763
+ }
69764
+ (_a = popup == null ? void 0 : popup[0]) == null ? void 0 : _a.setProps({
69765
+ getReferenceClientRect: props.clientRect
69766
+ });
69767
+ },
69768
+ onKeyDown: (props) => {
69769
+ var _a, _b;
69770
+ if (props.event.key === "Escape") {
69771
+ (_a = popup == null ? void 0 : popup[0]) == null ? void 0 : _a.hide();
69772
+ return true;
69773
+ }
69774
+ return ((_b = component == null ? void 0 : component.ref) == null ? void 0 : _b.onKeyDown(props.event)) ?? false;
69775
+ },
69776
+ onExit: () => {
69777
+ var _a;
69778
+ (_a = popup == null ? void 0 : popup[0]) == null ? void 0 : _a.destroy();
69779
+ component == null ? void 0 : component.destroy();
69780
+ }
69781
+ };
69782
+ }
69783
+ })
69784
+ ];
69785
+ }
69786
+ });
69599
69787
  const AIRefineExtension = Extension.create({
69600
69788
  name: "aiRefine",
69601
69789
  addOptions() {
@@ -69647,8 +69835,31 @@ const VariableMenu = ({
69647
69835
  const [activeCategory, setActiveCategory] = useState(null);
69648
69836
  const [selectedIndex, setSelectedIndex] = useState(0);
69649
69837
  const [currentPath, setCurrentPath] = useState([]);
69838
+ const [adjustedPosition, setAdjustedPosition] = useState(position);
69650
69839
  const menuRef = useRef(null);
69651
69840
  const inputRef = useRef(null);
69841
+ useEffect(() => {
69842
+ if (!menuRef.current) return;
69843
+ const menuRect = menuRef.current.getBoundingClientRect();
69844
+ const viewportWidth = window.innerWidth;
69845
+ const viewportHeight = window.innerHeight;
69846
+ const padding = 8;
69847
+ let newTop = position.top;
69848
+ let newLeft = position.left;
69849
+ if (position.left + menuRect.width > viewportWidth - padding) {
69850
+ newLeft = Math.max(padding, viewportWidth - menuRect.width - padding);
69851
+ }
69852
+ if (position.top + menuRect.height > viewportHeight - padding) {
69853
+ newTop = Math.max(padding, position.top - menuRect.height - 10);
69854
+ }
69855
+ if (newLeft < padding) {
69856
+ newLeft = padding;
69857
+ }
69858
+ if (newTop < padding) {
69859
+ newTop = padding;
69860
+ }
69861
+ setAdjustedPosition({ top: newTop, left: newLeft });
69862
+ }, [position]);
69652
69863
  const categories = [
69653
69864
  { id: "env", label: "Environment Variables", icon: Settings, variables: envVariables2 },
69654
69865
  { id: "memory", label: "Memory", icon: Database, variables: memoryVariables },
@@ -69787,7 +69998,7 @@ const VariableMenu = ({
69787
69998
  {
69788
69999
  ref: menuRef,
69789
70000
  className: "k-md-editor-variable-menu fixed w-[280px] max-h-[320px] bg-white rounded-lg shadow-lg z-[9999] overflow-hidden flex flex-col",
69790
- style: { top: position.top, left: position.left },
70001
+ style: { top: adjustedPosition.top, left: adjustedPosition.left },
69791
70002
  "data-id": "md-editor-variable-menu",
69792
70003
  children: [
69793
70004
  /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "px-3 py-2 border-b border-gray-200 flex items-center gap-2", children: [
@@ -70651,7 +70862,10 @@ const QUICK_ACTIONS = [
70651
70862
  { id: "make-longer", label: "Expand", instruction: "", icon: /* @__PURE__ */ jsxRuntimeExports.jsx(ArrowRight, { size: 14 }) },
70652
70863
  { id: "convert-to-yaml", label: "YAML", instruction: "", icon: /* @__PURE__ */ jsxRuntimeExports.jsx(FileText, { size: 14 }) }
70653
70864
  ];
70654
- const VARIABLE_CATEGORIES = [
70865
+ const MENTION_CATEGORIES = [
70866
+ { type: "agent", label: "Agents", icon: /* @__PURE__ */ jsxRuntimeExports.jsx(Bot, { size: 14 }), isMention: true },
70867
+ { type: "tool", label: "Tools", icon: /* @__PURE__ */ jsxRuntimeExports.jsx(Wrench, { size: 14 }), isMention: true },
70868
+ { type: "knowledge", label: "Knowledge", icon: /* @__PURE__ */ jsxRuntimeExports.jsx(BookOpen, { size: 14 }), isMention: true },
70655
70869
  { type: "env", label: "Environment", icon: /* @__PURE__ */ jsxRuntimeExports.jsx(Settings, { size: 14 }) },
70656
70870
  { type: "memory", label: "Memory", icon: /* @__PURE__ */ jsxRuntimeExports.jsx(Database, { size: 14 }) },
70657
70871
  { type: "system", label: "System", icon: /* @__PURE__ */ jsxRuntimeExports.jsx(Hash$2, { size: 14 }) },
@@ -70672,8 +70886,12 @@ const AIRefinePanel = ({
70672
70886
  envVariables: envVariables2 = [],
70673
70887
  memoryVariables = [],
70674
70888
  systemVariables: systemVariables2 = [],
70675
- contentVariables = []
70889
+ contentVariables = [],
70890
+ agents: agents2 = [],
70891
+ tools: tools2 = [],
70892
+ knowledge: knowledge2 = []
70676
70893
  }) => {
70894
+ var _a;
70677
70895
  const [messages, setMessages] = useState([]);
70678
70896
  const [inputValue, setInputValue] = useState("");
70679
70897
  const [isLoading, setIsLoading] = useState(false);
@@ -70689,13 +70907,16 @@ const AIRefinePanel = ({
70689
70907
  const [mentionCursorPos, setMentionCursorPos] = useState(null);
70690
70908
  const [selectedCategory, setSelectedCategory] = useState(null);
70691
70909
  const [selectedMentionIndex, setSelectedMentionIndex] = useState(0);
70910
+ const [mentionSearchQuery, setMentionSearchQuery] = useState("");
70692
70911
  const mentionMenuRef = useRef(null);
70912
+ const searchInputRef = useRef(null);
70693
70913
  const originalContextRef = useRef({ originalText: context.originalText, selectionRange: context.selectionRange });
70694
70914
  const previousContextRef = useRef(null);
70695
70915
  const messagesEndRef = useRef(null);
70696
70916
  const inputRef = useRef(null);
70697
70917
  const [showSelectionHighlight, setShowSelectionHighlight] = useState(false);
70698
70918
  const [isContentExpanded, setIsContentExpanded] = useState(false);
70919
+ const [isTipsExpanded, setIsTipsExpanded] = useState(true);
70699
70920
  const isDark = theme === "dark";
70700
70921
  const variablesByCategory = useMemo(() => ({
70701
70922
  env: envVariables2,
@@ -70703,38 +70924,67 @@ const AIRefinePanel = ({
70703
70924
  system: systemVariables2,
70704
70925
  content: contentVariables
70705
70926
  }), [envVariables2, memoryVariables, systemVariables2, contentVariables]);
70927
+ const mentionsByCategory = useMemo(() => ({
70928
+ agent: agents2,
70929
+ tool: tools2,
70930
+ knowledge: knowledge2
70931
+ }), [agents2, tools2, knowledge2]);
70706
70932
  const availableCategories = useMemo(
70707
- () => VARIABLE_CATEGORIES.filter((cat) => {
70708
- var _a;
70709
- return ((_a = variablesByCategory[cat.type]) == null ? void 0 : _a.length) > 0;
70933
+ () => MENTION_CATEGORIES.filter((cat) => {
70934
+ var _a2, _b;
70935
+ if (cat.isMention) {
70936
+ return ((_a2 = mentionsByCategory[cat.type]) == null ? void 0 : _a2.length) > 0;
70937
+ }
70938
+ return ((_b = variablesByCategory[cat.type]) == null ? void 0 : _b.length) > 0;
70710
70939
  }),
70711
- [variablesByCategory]
70940
+ [variablesByCategory, mentionsByCategory]
70712
70941
  );
70713
- const filteredVariables = useMemo(() => {
70714
- if (selectedCategory && selectedCategory !== "custom") {
70942
+ const isMentionCategory = useMemo(() => {
70943
+ if (!selectedCategory) return false;
70944
+ return ["agent", "tool", "knowledge"].includes(selectedCategory);
70945
+ }, [selectedCategory]);
70946
+ const filteredItems = useMemo(() => {
70947
+ if (!selectedCategory) return [];
70948
+ const searchQuery = mentionSearchQuery.toLowerCase();
70949
+ if (isMentionCategory) {
70950
+ const items = mentionsByCategory[selectedCategory] || [];
70951
+ if (!searchQuery) return items;
70952
+ return items.filter(
70953
+ (m3) => m3.name.toLowerCase().includes(searchQuery)
70954
+ );
70955
+ } else {
70715
70956
  const vars = variablesByCategory[selectedCategory] || [];
70716
- if (!mentionQuery) return vars;
70957
+ if (!searchQuery) return vars;
70717
70958
  return vars.filter(
70718
- (v) => v.name.toLowerCase().includes(mentionQuery.toLowerCase()) || v.path.toLowerCase().includes(mentionQuery.toLowerCase())
70959
+ (v) => v.name.toLowerCase().includes(searchQuery) || v.path.toLowerCase().includes(searchQuery)
70719
70960
  );
70720
70961
  }
70721
- return [];
70722
- }, [selectedCategory, variablesByCategory, mentionQuery]);
70723
- const allVariables = useMemo(() => {
70962
+ }, [selectedCategory, variablesByCategory, mentionsByCategory, mentionSearchQuery, isMentionCategory]);
70963
+ const allItems2 = useMemo(() => {
70724
70964
  const all = [];
70965
+ for (const [type, items] of Object.entries(mentionsByCategory)) {
70966
+ for (const m3 of items) {
70967
+ all.push({ ...m3, category: type });
70968
+ }
70969
+ }
70725
70970
  for (const [type, vars] of Object.entries(variablesByCategory)) {
70726
70971
  for (const v of vars) {
70727
70972
  all.push({ ...v, category: type });
70728
70973
  }
70729
70974
  }
70730
70975
  return all;
70731
- }, [variablesByCategory]);
70976
+ }, [variablesByCategory, mentionsByCategory]);
70732
70977
  const searchResults = useMemo(() => {
70733
70978
  if (!mentionQuery || selectedCategory) return [];
70734
- return allVariables.filter(
70735
- (v) => v.name.toLowerCase().includes(mentionQuery.toLowerCase()) || v.path.toLowerCase().includes(mentionQuery.toLowerCase())
70736
- ).slice(0, 10);
70737
- }, [allVariables, mentionQuery, selectedCategory]);
70979
+ const query = mentionQuery.toLowerCase();
70980
+ return allItems2.filter((item) => {
70981
+ if ("path" in item) {
70982
+ return item.name.toLowerCase().includes(query) || item.path.toLowerCase().includes(query);
70983
+ } else {
70984
+ return item.name.toLowerCase().includes(query);
70985
+ }
70986
+ }).slice(0, 10);
70987
+ }, [allItems2, mentionQuery, selectedCategory]);
70738
70988
  useEffect(() => {
70739
70989
  if (!isOpen) {
70740
70990
  setMessages([]);
@@ -70746,6 +70996,7 @@ const AIRefinePanel = ({
70746
70996
  setSessionActionType(void 0);
70747
70997
  setIsNewSelectionInSession(false);
70748
70998
  previousContextRef.current = null;
70999
+ setIsTipsExpanded(true);
70749
71000
  }
70750
71001
  }, [isOpen]);
70751
71002
  useEffect(() => {
@@ -70758,8 +71009,8 @@ const AIRefinePanel = ({
70758
71009
  setIsContentExpanded(false);
70759
71010
  setTimeout(() => setShowSelectionHighlight(false), 1500);
70760
71011
  setTimeout(() => {
70761
- var _a;
70762
- return (_a = inputRef.current) == null ? void 0 : _a.focus();
71012
+ var _a2;
71013
+ return (_a2 = inputRef.current) == null ? void 0 : _a2.focus();
70763
71014
  }, 150);
70764
71015
  if (messages.length > 0) {
70765
71016
  const systemMessage = {
@@ -70791,16 +71042,21 @@ const AIRefinePanel = ({
70791
71042
  setShowSelectionHighlight(true);
70792
71043
  setTimeout(() => setShowSelectionHighlight(false), 1500);
70793
71044
  setTimeout(() => {
70794
- var _a, _b;
70795
- (_a = inputRef.current) == null ? void 0 : _a.focus();
71045
+ var _a2, _b;
71046
+ (_a2 = inputRef.current) == null ? void 0 : _a2.focus();
70796
71047
  (_b = inputRef.current) == null ? void 0 : _b.scrollIntoView({ behavior: "smooth", block: "nearest" });
70797
71048
  }, 200);
70798
71049
  }
70799
71050
  }, [isOpen]);
70800
71051
  useEffect(() => {
70801
- var _a;
70802
- (_a = messagesEndRef.current) == null ? void 0 : _a.scrollIntoView({ behavior: "smooth" });
71052
+ var _a2;
71053
+ (_a2 = messagesEndRef.current) == null ? void 0 : _a2.scrollIntoView({ behavior: "smooth" });
70803
71054
  }, [messages]);
71055
+ useEffect(() => {
71056
+ if (messages.length > 0) {
71057
+ setIsTipsExpanded(false);
71058
+ }
71059
+ }, [messages.length]);
70804
71060
  const getCurrentTextToRefine = useCallback(() => {
70805
71061
  if (currentContentState) {
70806
71062
  return currentContentState.text;
@@ -70892,7 +71148,7 @@ const AIRefinePanel = ({
70892
71148
  handleRefine(action.instruction, action.id);
70893
71149
  };
70894
71150
  const handleInputChange = useCallback((e3) => {
70895
- var _a;
71151
+ var _a2;
70896
71152
  const value = e3.target.value;
70897
71153
  const cursorPos = e3.target.selectionStart;
70898
71154
  setInputValue(value);
@@ -70901,7 +71157,7 @@ const AIRefinePanel = ({
70901
71157
  if (atMatch && availableCategories.length > 0) {
70902
71158
  setShowMentionMenu(true);
70903
71159
  setMentionQuery(atMatch[1] || "");
70904
- setMentionCursorPos(cursorPos - (((_a = atMatch[1]) == null ? void 0 : _a.length) || 0) - 1);
71160
+ setMentionCursorPos(cursorPos - (((_a2 = atMatch[1]) == null ? void 0 : _a2.length) || 0) - 1);
70905
71161
  setSelectedMentionIndex(0);
70906
71162
  if (atMatch[1]) {
70907
71163
  setSelectedCategory(null);
@@ -70913,10 +71169,15 @@ const AIRefinePanel = ({
70913
71169
  setSelectedCategory(null);
70914
71170
  }
70915
71171
  }, [availableCategories.length]);
70916
- const insertMention = useCallback((variable, category) => {
71172
+ const insertMentionItem = useCallback((item, category) => {
70917
71173
  if (mentionCursorPos === null) return;
70918
- const varType = category || variable.type;
70919
- const mentionText = `{{${varType}.${variable.path}}}`;
71174
+ let mentionText;
71175
+ if ("path" in item) {
71176
+ const varType = category || item.type;
71177
+ mentionText = `{{${varType}.${item.path}}}`;
71178
+ } else {
71179
+ mentionText = `@${item.name}`;
71180
+ }
70920
71181
  const beforeMention = inputValue.slice(0, mentionCursorPos);
70921
71182
  const afterMention = inputValue.slice(mentionCursorPos + 1 + mentionQuery.length);
70922
71183
  const newValue = beforeMention + mentionText + " " + afterMention;
@@ -70926,6 +71187,7 @@ const AIRefinePanel = ({
70926
71187
  setMentionCursorPos(null);
70927
71188
  setSelectedCategory(null);
70928
71189
  setSelectedMentionIndex(0);
71190
+ setMentionSearchQuery("");
70929
71191
  setTimeout(() => {
70930
71192
  if (inputRef.current) {
70931
71193
  inputRef.current.focus();
@@ -70937,11 +71199,17 @@ const AIRefinePanel = ({
70937
71199
  const handleCategorySelect = useCallback((category) => {
70938
71200
  setSelectedCategory(category);
70939
71201
  setSelectedMentionIndex(0);
71202
+ setMentionSearchQuery("");
71203
+ setTimeout(() => {
71204
+ var _a2;
71205
+ return (_a2 = searchInputRef.current) == null ? void 0 : _a2.focus();
71206
+ }, 50);
70940
71207
  }, []);
70941
71208
  const handleBackToCategories = useCallback(() => {
70942
71209
  setSelectedCategory(null);
70943
71210
  setMentionQuery("");
70944
71211
  setSelectedMentionIndex(0);
71212
+ setMentionSearchQuery("");
70945
71213
  }, []);
70946
71214
  const closeMentionMenu = useCallback(() => {
70947
71215
  setShowMentionMenu(false);
@@ -70949,10 +71217,11 @@ const AIRefinePanel = ({
70949
71217
  setMentionCursorPos(null);
70950
71218
  setSelectedCategory(null);
70951
71219
  setSelectedMentionIndex(0);
71220
+ setMentionSearchQuery("");
70952
71221
  }, []);
70953
71222
  const handleKeyDown2 = (e3) => {
70954
71223
  if (showMentionMenu) {
70955
- const itemCount = selectedCategory ? filteredVariables.length : mentionQuery ? searchResults.length : availableCategories.length;
71224
+ const itemCount = selectedCategory ? filteredItems.length : mentionQuery ? searchResults.length : availableCategories.length;
70956
71225
  if (e3.key === "ArrowDown") {
70957
71226
  e3.preventDefault();
70958
71227
  setSelectedMentionIndex((prev) => (prev + 1) % Math.max(itemCount, 1));
@@ -70966,13 +71235,13 @@ const AIRefinePanel = ({
70966
71235
  if (e3.key === "Enter") {
70967
71236
  e3.preventDefault();
70968
71237
  if (selectedCategory) {
70969
- if (filteredVariables[selectedMentionIndex]) {
70970
- insertMention(filteredVariables[selectedMentionIndex], selectedCategory);
71238
+ if (filteredItems[selectedMentionIndex]) {
71239
+ insertMentionItem(filteredItems[selectedMentionIndex], selectedCategory);
70971
71240
  }
70972
71241
  } else if (mentionQuery && searchResults.length > 0) {
70973
71242
  const result = searchResults[selectedMentionIndex];
70974
71243
  if (result) {
70975
- insertMention(result, result.category);
71244
+ insertMentionItem(result, result.category);
70976
71245
  }
70977
71246
  } else if (availableCategories[selectedMentionIndex]) {
70978
71247
  handleCategorySelect(availableCategories[selectedMentionIndex].type);
@@ -70984,7 +71253,7 @@ const AIRefinePanel = ({
70984
71253
  closeMentionMenu();
70985
71254
  return;
70986
71255
  }
70987
- if (e3.key === "Backspace" && selectedCategory && !mentionQuery) {
71256
+ if (e3.key === "Backspace" && selectedCategory && !mentionSearchQuery) {
70988
71257
  e3.preventDefault();
70989
71258
  handleBackToCategories();
70990
71259
  return;
@@ -71028,7 +71297,7 @@ const AIRefinePanel = ({
71028
71297
  }
71029
71298
  };
71030
71299
  const handleReset = () => {
71031
- var _a;
71300
+ var _a2;
71032
71301
  setMessages([]);
71033
71302
  setConversationHistory([]);
71034
71303
  setCurrentRefinedText(null);
@@ -71040,21 +71309,72 @@ const AIRefinePanel = ({
71040
71309
  text: originalContextRef.current.originalText,
71041
71310
  selectionRange: originalContextRef.current.selectionRange
71042
71311
  });
71043
- (_a = inputRef.current) == null ? void 0 : _a.focus();
71312
+ (_a2 = inputRef.current) == null ? void 0 : _a2.focus();
71044
71313
  };
71045
71314
  if (!isOpen) return null;
71315
+ const tipsContent = /* @__PURE__ */ jsxRuntimeExports.jsxs(
71316
+ "div",
71317
+ {
71318
+ className: `shrink-0 rounded-xl mb-2 border overflow-hidden transition-all duration-300 ${isDark ? "bg-gray-800/80 border-white/10 backdrop-blur-sm" : "bg-white/90 border-black/[0.08] backdrop-blur-sm shadow-sm"}`,
71319
+ "data-id": "md-editor-ai-tips-section",
71320
+ children: [
71321
+ /* @__PURE__ */ jsxRuntimeExports.jsxs(
71322
+ "button",
71323
+ {
71324
+ type: "button",
71325
+ onClick: () => setIsTipsExpanded(!isTipsExpanded),
71326
+ className: `w-full flex items-center justify-between px-3.5 py-2 transition-colors ${isDark ? "hover:bg-white/5" : "hover:bg-black/[0.02]"}`,
71327
+ "data-id": "md-editor-ai-tips-toggle",
71328
+ children: [
71329
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2", children: [
71330
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `flex items-center justify-center w-5 h-5 rounded-md ${isDark ? "bg-amber-500/20 text-amber-400" : "bg-amber-500/15 text-amber-600"}`, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Zap, { size: 12 }) }),
71331
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: `text-xs font-semibold ${isDark ? "text-gray-300" : "text-gray-600"}`, children: "Tips & Shortcuts" })
71332
+ ] }),
71333
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
71334
+ ChevronDown,
71335
+ {
71336
+ size: 14,
71337
+ className: `transition-transform duration-200 ${isDark ? "text-gray-500" : "text-gray-400"} ${isTipsExpanded ? "rotate-180" : ""}`
71338
+ }
71339
+ )
71340
+ ]
71341
+ }
71342
+ ),
71343
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `overflow-hidden transition-all duration-300 ease-in-out ${isTipsExpanded ? "max-h-[180px] opacity-100" : "max-h-0 opacity-0"}`, children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: `px-3.5 pb-2.5 pt-0.5 flex flex-col gap-1 ${isDark ? "text-gray-400" : "text-gray-500"}`, children: [
71344
+ [
71345
+ { keys: ["⌘", "B"], desc: "Bold" },
71346
+ { keys: ["⌘", "I"], desc: "Italic" },
71347
+ { keys: ["/"], desc: "Slash menu" },
71348
+ { keys: ["{", "{"], desc: "Variable" },
71349
+ { keys: ["@"], desc: "Mention" },
71350
+ { keys: ["⌘", "Z"], desc: "Undo (+⇧ Redo)" }
71351
+ ].map((item, i2) => /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between gap-2 py-0.5", children: [
71352
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "flex items-center gap-1 text-[10px]", children: item.keys.map((k3, j) => /* @__PURE__ */ jsxRuntimeExports.jsxs(React__default.Fragment, { children: [
71353
+ /* @__PURE__ */ jsxRuntimeExports.jsx("kbd", { className: `inline-flex items-center justify-center min-w-[16px] h-[16px] px-1 text-[9px] font-medium rounded border ${isDark ? "text-gray-300 bg-white/5 border-white/10" : "text-gray-500 bg-black/[0.04] border-black/[0.08]"}`, children: k3 }),
71354
+ j < item.keys.length - 1 && /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-[9px] text-gray-400", children: "+" })
71355
+ ] }, j)) }),
71356
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-[10px] text-right", children: item.desc })
71357
+ ] }, i2)),
71358
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between gap-2 py-0.5", children: [
71359
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "flex items-center gap-1 text-[10px]", children: [
71360
+ /* @__PURE__ */ jsxRuntimeExports.jsx(Type, { size: 10 }),
71361
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: "Drag" })
71362
+ ] }),
71363
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-[10px] text-right", children: "Reorder" })
71364
+ ] })
71365
+ ] }) })
71366
+ ]
71367
+ }
71368
+ );
71046
71369
  const renderMessage = (message, index) => {
71047
71370
  if (message.isSystemMessage) {
71048
71371
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(
71049
71372
  "div",
71050
71373
  {
71051
- className: `flex flex-col gap-2 p-3 my-2 rounded-xl border animate-[ai-new-selection-in_0.3s_ease-out] ${isDark ? "bg-gradient-to-br from-violet-500/15 to-indigo-500/15 border-violet-500/30" : "bg-gradient-to-br from-violet-500/10 to-indigo-500/10 border-violet-500/20"}`,
71374
+ className: `flex items-start gap-2 p-2.5 my-2 rounded-lg border animate-[ai-new-selection-in_0.3s_ease-out] ${isDark ? "bg-white/5 border-white/10" : "bg-black/[0.03] border-black/5"}`,
71052
71375
  children: [
71053
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: `flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wide ${isDark ? "text-violet-400" : "text-violet-600"}`, children: [
71054
- /* @__PURE__ */ jsxRuntimeExports.jsx(MousePointerClick, { size: 14 }),
71055
- /* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: "New Selection" })
71056
- ] }),
71057
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `text-[13px] leading-relaxed p-2.5 rounded-lg border-l-[3px] border-violet-500 whitespace-pre-wrap break-words ${isDark ? "text-gray-300 bg-black/20" : "text-gray-600 bg-white/60"}`, children: message.newSelectionText })
71376
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: `shrink-0 px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wide rounded-md ${isDark ? "text-violet-400 bg-violet-500/20" : "text-violet-600 bg-violet-500/10"}`, children: "Selection" }),
71377
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: `text-xs leading-relaxed whitespace-pre-wrap break-words line-clamp-4 ${isDark ? "text-gray-300" : "text-gray-600"}`, children: message.newSelectionText })
71058
71378
  ]
71059
71379
  },
71060
71380
  index
@@ -71069,7 +71389,7 @@ const AIRefinePanel = ({
71069
71389
  children: [
71070
71390
  message.role === "assistant" && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center w-7 h-7 rounded-lg bg-gradient-to-br from-violet-500 to-indigo-500 text-white shrink-0", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Sparkles, { size: 14 }) }),
71071
71391
  /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: `max-w-[85%] px-4 py-3 rounded-2xl text-sm leading-relaxed ${message.role === "user" ? "bg-gradient-to-br from-blue-500 to-blue-600 text-white rounded-br-md" : isErrorMessage ? isDark ? "bg-red-900/30 text-red-200 border border-red-500/30 rounded-bl-md" : "bg-red-50 text-red-700 border border-red-200 rounded-bl-md" : isDark ? "bg-gray-700 text-gray-100 border border-white/5 rounded-bl-md" : "bg-gray-100 text-gray-800 border border-black/5 rounded-bl-md"}`, children: [
71072
- message.quotedText && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mb-2.5 p-2.5 bg-white/15 rounded-lg text-xs border-l-[3px] border-white/50", children: /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "opacity-95 line-clamp-3", children: message.quotedText }) }),
71392
+ message.quotedText && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mb-2.5 p-2.5 bg-white/20 rounded-lg text-xs border-l-[3px] border-white/60 backdrop-blur-sm", children: /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-white/90 line-clamp-3", children: message.quotedText }) }),
71073
71393
  /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "whitespace-pre-wrap break-words", children: message.content }),
71074
71394
  isLastAssistant && !isErrorMessage && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: `flex items-center gap-1.5 mt-2.5 pt-2.5 border-t ${isDark ? "border-white/10" : "border-black/5"}`, children: [
71075
71395
  /* @__PURE__ */ jsxRuntimeExports.jsxs(
@@ -71151,8 +71471,8 @@ const AIRefinePanel = ({
71151
71471
  "data-id": "md-editor-ai-selection-box",
71152
71472
  children: [
71153
71473
  /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: `shrink-0 px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wide rounded-md transition-all duration-300 ${showSelectionHighlight ? "text-white bg-gradient-to-r from-violet-500 to-indigo-500 scale-105 shadow-md" : isDark ? "text-violet-400 bg-violet-500/20" : "text-violet-600 bg-violet-500/10"}`, children: context.type === "selection" ? "Selection" : "Full" }),
71154
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-1 min-w-0", children: /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: `text-xs leading-snug break-words ${isDark ? "text-gray-400" : "text-gray-500"} ${isContentExpanded ? "" : "line-clamp-2"}`, children: isContentExpanded ? context.originalText.replace(/\n/g, " ") : context.originalText.length > 80 ? context.originalText.slice(0, 80).replace(/\n/g, " ") + "..." : context.originalText.replace(/\n/g, " ") }) }),
71155
- context.originalText.length > 80 && /* @__PURE__ */ jsxRuntimeExports.jsx(
71474
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-1 min-w-0", children: /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: `text-xs leading-snug break-words whitespace-pre-wrap ${isDark ? "text-gray-300" : "text-gray-600"} ${isContentExpanded ? "" : "line-clamp-4"}`, children: context.originalText || "(No content selected)" }) }),
71475
+ context.originalText && context.originalText.length > 100 && /* @__PURE__ */ jsxRuntimeExports.jsx(
71156
71476
  "button",
71157
71477
  {
71158
71478
  type: "button",
@@ -71171,32 +71491,7 @@ const AIRefinePanel = ({
71171
71491
  )
71172
71492
  ]
71173
71493
  }
71174
- ),
71175
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: `flex flex-col gap-3 w-full mt-3 px-4 py-3.5 rounded-lg border border-dashed text-left ${isDark ? "bg-white/[0.02] border-white/10" : "bg-black/[0.02] border-black/[0.08]"}`, children: [
71176
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `text-[10px] font-semibold uppercase tracking-wide mb-0.5 ${isDark ? "text-gray-500" : "text-gray-400"}`, children: "Tips & Shortcuts" }),
71177
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-col gap-1", children: [
71178
- [
71179
- { keys: ["⌘", "B"], desc: "Bold text" },
71180
- { keys: ["⌘", "I"], desc: "Italic text" },
71181
- { keys: ["/"], desc: "Add block / slash menu" },
71182
- { keys: ["{", "{"], desc: "Insert variable" },
71183
- { keys: ["⌘", "Z"], desc: "Undo / Redo (+⇧)" }
71184
- ].map((item, i2) => /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between gap-3", children: [
71185
- /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: `flex items-center gap-1 text-[11px] ${isDark ? "text-gray-500" : "text-gray-400"}`, children: item.keys.map((k3, j) => /* @__PURE__ */ jsxRuntimeExports.jsxs(React__default.Fragment, { children: [
71186
- /* @__PURE__ */ jsxRuntimeExports.jsx("kbd", { className: `inline-flex items-center justify-center min-w-[18px] h-[18px] px-1.5 text-[10px] font-medium rounded border ${isDark ? "text-gray-300 bg-white/5 border-white/10" : "text-gray-500 bg-black/[0.04] border-black/[0.08]"}`, children: k3 }),
71187
- j < item.keys.length - 1 && /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-[10px]", children: "+" })
71188
- ] }, j)) }),
71189
- /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: `text-[11px] text-right ${isDark ? "text-gray-500" : "text-gray-400"}`, children: item.desc })
71190
- ] }, i2)),
71191
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between gap-3", children: [
71192
- /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: `flex items-center gap-1 text-[11px] ${isDark ? "text-gray-500" : "text-gray-400"}`, children: [
71193
- /* @__PURE__ */ jsxRuntimeExports.jsx(Type, { size: 11 }),
71194
- /* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: "Drag handle" })
71195
- ] }),
71196
- /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: `text-[11px] text-right ${isDark ? "text-gray-500" : "text-gray-400"}`, children: "Reorder blocks" })
71197
- ] })
71198
- ] })
71199
- ] })
71494
+ )
71200
71495
  ] }),
71201
71496
  messages.map((message, index) => renderMessage(message, index)),
71202
71497
  isLoading && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex gap-2.5 max-w-full animate-[ai-message-in_0.3s_ease-out]", children: [
@@ -71227,35 +71522,39 @@ const AIRefinePanel = ({
71227
71522
  "div",
71228
71523
  {
71229
71524
  ref: mentionMenuRef,
71230
- className: `rounded-lg border shadow-lg overflow-hidden max-h-[200px] overflow-y-auto ${isDark ? "bg-gray-800 border-gray-600" : "bg-white border-gray-200"}`,
71525
+ className: `rounded-lg border shadow-lg overflow-hidden max-h-[280px] flex flex-col ${isDark ? "bg-gray-800 border-gray-600" : "bg-white border-gray-200"}`,
71231
71526
  "data-id": "md-editor-ai-mention-menu",
71232
71527
  children: [
71233
- mentionQuery && !selectedCategory && searchResults.length > 0 && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "py-1", children: [
71234
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `px-3 py-1.5 text-[10px] font-medium uppercase tracking-wide ${isDark ? "text-gray-500" : "text-gray-400"}`, children: "Variables" }),
71235
- searchResults.map((variable, index) => /* @__PURE__ */ jsxRuntimeExports.jsxs(
71236
- "button",
71237
- {
71238
- className: `w-full flex items-center gap-2 px-3 py-2 text-left transition-colors ${index === selectedMentionIndex ? isDark ? "bg-violet-500/20 text-violet-300" : "bg-violet-50 text-violet-700" : isDark ? "text-gray-300 hover:bg-white/5" : "text-gray-700 hover:bg-gray-50"}`,
71239
- onClick: () => insertMention(variable, variable.category),
71240
- "data-id": `md-editor-ai-mention-${variable.path}`,
71241
- children: [
71242
- /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: `text-xs px-1.5 py-0.5 rounded ${isDark ? "bg-gray-700 text-gray-400" : "bg-gray-100 text-gray-500"}`, children: variable.category }),
71243
- /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-sm font-medium truncate", children: variable.name }),
71244
- /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: `text-xs truncate ${isDark ? "text-gray-500" : "text-gray-400"}`, children: variable.path })
71245
- ]
71246
- },
71247
- `${variable.category}-${variable.path}`
71248
- ))
71528
+ mentionQuery && !selectedCategory && searchResults.length > 0 && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "py-1 overflow-y-auto", children: [
71529
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `px-3 py-1.5 text-[10px] font-medium uppercase tracking-wide ${isDark ? "text-gray-500" : "text-gray-400"}`, children: "Results" }),
71530
+ searchResults.map((item, index) => {
71531
+ const isVariable = "path" in item;
71532
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs(
71533
+ "button",
71534
+ {
71535
+ className: `w-full flex items-center gap-2 px-3 py-2 text-left transition-colors ${index === selectedMentionIndex ? isDark ? "bg-violet-500/20 text-violet-300" : "bg-violet-50 text-violet-700" : isDark ? "text-gray-300 hover:bg-white/5" : "text-gray-700 hover:bg-gray-50"}`,
71536
+ onClick: () => insertMentionItem(item, item.category),
71537
+ "data-id": `md-editor-ai-mention-${isVariable ? item.path : item.id}`,
71538
+ children: [
71539
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: `text-xs px-1.5 py-0.5 rounded ${isDark ? "bg-gray-700 text-gray-400" : "bg-gray-100 text-gray-500"}`, children: item.category }),
71540
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-sm font-medium truncate", children: item.name }),
71541
+ isVariable && /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: `text-xs truncate ${isDark ? "text-gray-500" : "text-gray-400"}`, children: item.path })
71542
+ ]
71543
+ },
71544
+ isVariable ? `${item.category}-${item.path}` : `${item.category}-${item.id}`
71545
+ );
71546
+ })
71249
71547
  ] }),
71250
71548
  mentionQuery && !selectedCategory && searchResults.length === 0 && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: `px-3 py-4 text-center text-sm ${isDark ? "text-gray-500" : "text-gray-400"}`, children: [
71251
- 'No variables found for "',
71549
+ 'No results found for "',
71252
71550
  mentionQuery,
71253
71551
  '"'
71254
71552
  ] }),
71255
- !mentionQuery && !selectedCategory && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "py-1", children: [
71256
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `px-3 py-1.5 text-[10px] font-medium uppercase tracking-wide ${isDark ? "text-gray-500" : "text-gray-400"}`, children: "Select category" }),
71553
+ !mentionQuery && !selectedCategory && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "py-1 overflow-y-auto", children: [
71554
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `px-3 py-1.5 text-[10px] font-medium uppercase tracking-wide ${isDark ? "text-gray-500" : "text-gray-400"}`, children: "Mention" }),
71257
71555
  availableCategories.map((category, index) => {
71258
- var _a;
71556
+ var _a2, _b;
71557
+ const count = category.isMention ? ((_a2 = mentionsByCategory[category.type]) == null ? void 0 : _a2.length) || 0 : ((_b = variablesByCategory[category.type]) == null ? void 0 : _b.length) || 0;
71259
71558
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(
71260
71559
  "button",
71261
71560
  {
@@ -71268,7 +71567,7 @@ const AIRefinePanel = ({
71268
71567
  /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-sm font-medium", children: category.label }),
71269
71568
  /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: `text-xs ${isDark ? "text-gray-500" : "text-gray-400"}`, children: [
71270
71569
  "(",
71271
- ((_a = variablesByCategory[category.type]) == null ? void 0 : _a.length) || 0,
71570
+ count,
71272
71571
  ")"
71273
71572
  ] })
71274
71573
  ] }),
@@ -71279,32 +71578,66 @@ const AIRefinePanel = ({
71279
71578
  );
71280
71579
  })
71281
71580
  ] }),
71282
- selectedCategory && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "py-1", children: [
71283
- /* @__PURE__ */ jsxRuntimeExports.jsxs(
71284
- "button",
71285
- {
71286
- className: `w-full flex items-center gap-2 px-3 py-1.5 text-left border-b transition-colors ${isDark ? "text-gray-400 hover:bg-white/5 border-gray-700" : "text-gray-500 hover:bg-gray-50 border-gray-100"}`,
71287
- onClick: handleBackToCategories,
71288
- "data-id": "md-editor-ai-mention-back",
71289
- children: [
71290
- /* @__PURE__ */ jsxRuntimeExports.jsx(ChevronRight, { size: 14, className: "rotate-180" }),
71291
- /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-xs", children: "Back" })
71292
- ]
71293
- }
71294
- ),
71295
- filteredVariables.length > 0 ? filteredVariables.map((variable, index) => /* @__PURE__ */ jsxRuntimeExports.jsxs(
71296
- "button",
71297
- {
71298
- className: `w-full flex flex-col gap-0.5 px-3 py-2 text-left transition-colors ${index === selectedMentionIndex ? isDark ? "bg-violet-500/20 text-violet-300" : "bg-violet-50 text-violet-700" : isDark ? "text-gray-300 hover:bg-white/5" : "text-gray-700 hover:bg-gray-50"}`,
71299
- onClick: () => insertMention(variable, selectedCategory || void 0),
71300
- "data-id": `md-editor-ai-mention-var-${variable.path}`,
71301
- children: [
71302
- /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-sm font-medium", children: variable.name }),
71303
- /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: `text-xs truncate ${isDark ? "text-gray-500" : "text-gray-400"}`, children: `{{${selectedCategory}.${variable.path}}}` })
71304
- ]
71305
- },
71306
- variable.path
71307
- )) : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `px-3 py-3 text-center text-sm ${isDark ? "text-gray-500" : "text-gray-400"}`, children: "No variables found" })
71581
+ selectedCategory && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-col h-full", children: [
71582
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: `flex items-center gap-2 px-3 py-1.5 border-b shrink-0 ${isDark ? "border-gray-700" : "border-gray-100"}`, children: [
71583
+ /* @__PURE__ */ jsxRuntimeExports.jsxs(
71584
+ "button",
71585
+ {
71586
+ className: `flex items-center gap-1 text-xs transition-colors ${isDark ? "text-gray-400 hover:text-gray-200" : "text-gray-500 hover:text-gray-700"}`,
71587
+ onClick: handleBackToCategories,
71588
+ "data-id": "md-editor-ai-mention-back",
71589
+ children: [
71590
+ /* @__PURE__ */ jsxRuntimeExports.jsx(ChevronRight, { size: 14, className: "rotate-180" }),
71591
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: "Back" })
71592
+ ]
71593
+ }
71594
+ ),
71595
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: `text-xs font-medium ${isDark ? "text-gray-300" : "text-gray-600"}`, children: (_a = MENTION_CATEGORIES.find((c3) => c3.type === selectedCategory)) == null ? void 0 : _a.label })
71596
+ ] }),
71597
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `px-2 py-1.5 border-b shrink-0 ${isDark ? "border-gray-700" : "border-gray-100"}`, children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: `flex items-center gap-2 px-2 py-1 rounded-md ${isDark ? "bg-gray-900" : "bg-gray-50"}`, children: [
71598
+ /* @__PURE__ */ jsxRuntimeExports.jsx(Search, { size: 14, className: isDark ? "text-gray-500" : "text-gray-400" }),
71599
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
71600
+ "input",
71601
+ {
71602
+ ref: searchInputRef,
71603
+ type: "text",
71604
+ value: mentionSearchQuery,
71605
+ onChange: (e3) => {
71606
+ setMentionSearchQuery(e3.target.value);
71607
+ setSelectedMentionIndex(0);
71608
+ },
71609
+ placeholder: "Search...",
71610
+ className: `flex-1 bg-transparent text-xs border-0 outline-none ${isDark ? "text-gray-200 placeholder:text-gray-500" : "text-gray-700 placeholder:text-gray-400"}`,
71611
+ onKeyDown: (e3) => {
71612
+ var _a2;
71613
+ if (e3.key === "Escape") {
71614
+ e3.stopPropagation();
71615
+ closeMentionMenu();
71616
+ } else if (e3.key === "ArrowDown" || e3.key === "ArrowUp" || e3.key === "Enter") {
71617
+ e3.preventDefault();
71618
+ (_a2 = inputRef.current) == null ? void 0 : _a2.dispatchEvent(new KeyboardEvent("keydown", { key: e3.key, bubbles: true }));
71619
+ }
71620
+ },
71621
+ "data-id": "md-editor-ai-mention-search"
71622
+ }
71623
+ )
71624
+ ] }) }),
71625
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "py-1 overflow-y-auto", children: filteredItems.length > 0 ? filteredItems.map((item, index) => {
71626
+ const isVariable = "path" in item;
71627
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs(
71628
+ "button",
71629
+ {
71630
+ className: `w-full flex flex-col gap-0.5 px-3 py-2 text-left transition-colors ${index === selectedMentionIndex ? isDark ? "bg-violet-500/20 text-violet-300" : "bg-violet-50 text-violet-700" : isDark ? "text-gray-300 hover:bg-white/5" : "text-gray-700 hover:bg-gray-50"}`,
71631
+ onClick: () => insertMentionItem(item, selectedCategory || void 0),
71632
+ "data-id": `md-editor-ai-mention-item-${isVariable ? item.path : item.id}`,
71633
+ children: [
71634
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-sm font-medium", children: item.name }),
71635
+ isVariable ? /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: `text-xs truncate ${isDark ? "text-gray-500" : "text-gray-400"}`, children: `{{${selectedCategory}.${item.path}}}` }) : item.description ? /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: `text-xs truncate ${isDark ? "text-gray-500" : "text-gray-400"}`, children: item.description }) : null
71636
+ ]
71637
+ },
71638
+ isVariable ? item.path : item.id
71639
+ );
71640
+ }) : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `px-3 py-3 text-center text-sm ${isDark ? "text-gray-500" : "text-gray-400"}`, children: mentionSearchQuery ? `No results for "${mentionSearchQuery}"` : "No items available" }) })
71308
71641
  ] })
71309
71642
  ]
71310
71643
  }
@@ -71315,7 +71648,7 @@ const AIRefinePanel = ({
71315
71648
  {
71316
71649
  ref: inputRef,
71317
71650
  className: `flex-1 min-h-[36px] max-h-[100px] px-2.5 py-2 border-0 bg-transparent text-sm resize-none outline-none ${isDark ? "text-gray-100 placeholder:text-gray-500" : "text-gray-800 placeholder:text-gray-400"}`,
71318
- placeholder: isNewSelectionInSession ? "Refine this new selection... (@ for variables)" : messages.length === 0 ? "Describe how to refine... (@ for variables)" : "Continue... (@ for variables)",
71651
+ placeholder: isNewSelectionInSession ? "Refine this new selection... (@ to mention)" : messages.length === 0 ? "Describe how to refine... (@ to mention)" : "Continue... (@ to mention)",
71319
71652
  value: inputValue,
71320
71653
  onChange: handleInputChange,
71321
71654
  onKeyDown: handleKeyDown2,
@@ -71340,12 +71673,15 @@ const AIRefinePanel = ({
71340
71673
  ] });
71341
71674
  switch (position) {
71342
71675
  case "side-panel":
71343
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
71676
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs(
71344
71677
  "div",
71345
71678
  {
71346
- className: `w-[400px] min-w-[340px] max-w-[500px] h-[calc(100%-24px)] m-3 mr-3 ml-0 border rounded-2xl shrink-0 overflow-hidden animate-[ai-panel-slide-in_0.3s_cubic-bezier(0.4,0,0.2,1)] ${isDark ? "border-white/10 shadow-[-4px_0_32px_rgba(0,0,0,0.4)]" : "border-black/[0.08] shadow-[-4px_0_32px_rgba(0,0,0,0.12)]"}`,
71679
+ className: "flex flex-col w-[400px] min-w-[340px] max-w-[500px] h-[calc(100%-24px)] m-3 mr-3 ml-0 shrink-0 animate-[ai-panel-slide-in_0.3s_cubic-bezier(0.4,0,0.2,1)]",
71347
71680
  "data-id": "md-editor-ai-panel-side",
71348
- children: panelContent
71681
+ children: [
71682
+ tipsContent,
71683
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `flex-1 min-h-0 border rounded-2xl overflow-hidden ${isDark ? "border-white/10 shadow-[-4px_0_32px_rgba(0,0,0,0.4)]" : "border-black/[0.08] shadow-[-4px_0_32px_rgba(0,0,0,0.12)]"}`, children: panelContent })
71684
+ ]
71349
71685
  }
71350
71686
  );
71351
71687
  case "inline-popup":
@@ -71358,7 +71694,10 @@ const AIRefinePanel = ({
71358
71694
  "data-id": "md-editor-ai-panel-backdrop"
71359
71695
  }
71360
71696
  ),
71361
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "relative w-[90%] max-w-[600px] max-h-[80vh] rounded-[20px] overflow-hidden shadow-[0_24px_48px_rgba(0,0,0,0.2)] animate-[ai-popup-scale-in_0.3s_cubic-bezier(0.4,0,0.2,1)]", children: panelContent })
71697
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "relative w-[90%] max-w-[600px] max-h-[80vh] flex flex-col gap-2 animate-[ai-popup-scale-in_0.3s_cubic-bezier(0.4,0,0.2,1)]", children: [
71698
+ tipsContent,
71699
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-1 min-h-0 rounded-[20px] overflow-hidden shadow-[0_24px_48px_rgba(0,0,0,0.2)]", children: panelContent })
71700
+ ] })
71362
71701
  ] });
71363
71702
  case "bottom-drawer":
71364
71703
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "fixed inset-0 z-[9999] flex flex-col justify-end", "data-id": "md-editor-ai-panel-drawer", children: [
@@ -71370,18 +71709,24 @@ const AIRefinePanel = ({
71370
71709
  "data-id": "md-editor-ai-panel-backdrop"
71371
71710
  }
71372
71711
  ),
71373
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "relative w-full max-h-[70vh] rounded-t-[24px] overflow-hidden shadow-[0_-10px_40px_rgba(0,0,0,0.2)] animate-[ai-drawer-slide-up_0.4s_cubic-bezier(0.4,0,0.2,1)]", children: [
71374
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `w-10 h-1 rounded-full mx-auto mt-3 mb-2 ${isDark ? "bg-white/20" : "bg-black/20"}`, "data-id": "md-editor-ai-panel-drawer-handle" }),
71375
- panelContent
71712
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "relative w-full max-h-[70vh] flex flex-col gap-2 px-4 pb-4 animate-[ai-drawer-slide-up_0.4s_cubic-bezier(0.4,0,0.2,1)]", children: [
71713
+ tipsContent,
71714
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex-1 min-h-0 rounded-t-[24px] overflow-hidden shadow-[0_-10px_40px_rgba(0,0,0,0.2)]", children: [
71715
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `w-10 h-1 rounded-full mx-auto mt-3 mb-2 ${isDark ? "bg-white/20" : "bg-black/20"}`, "data-id": "md-editor-ai-panel-drawer-handle" }),
71716
+ panelContent
71717
+ ] })
71376
71718
  ] })
71377
71719
  ] });
71378
71720
  default:
71379
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
71721
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs(
71380
71722
  "div",
71381
71723
  {
71382
- className: `w-[400px] min-w-[340px] max-w-[500px] h-[calc(100%-24px)] m-3 mr-3 ml-0 border rounded-2xl shrink-0 overflow-hidden animate-[ai-panel-slide-in_0.3s_cubic-bezier(0.4,0,0.2,1)] ${isDark ? "border-white/10 shadow-[-4px_0_32px_rgba(0,0,0,0.4)]" : "border-black/[0.08] shadow-[-4px_0_32px_rgba(0,0,0,0.12)]"}`,
71724
+ className: "flex flex-col w-[400px] min-w-[340px] max-w-[500px] h-[calc(100%-24px)] m-3 mr-3 ml-0 shrink-0 animate-[ai-panel-slide-in_0.3s_cubic-bezier(0.4,0,0.2,1)]",
71383
71725
  "data-id": "md-editor-ai-panel",
71384
- children: panelContent
71726
+ children: [
71727
+ tipsContent,
71728
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `flex-1 min-h-0 border rounded-2xl overflow-hidden ${isDark ? "border-white/10 shadow-[-4px_0_32px_rgba(0,0,0,0.4)]" : "border-black/[0.08] shadow-[-4px_0_32px_rgba(0,0,0,0.12)]"}`, children: panelContent })
71729
+ ]
71385
71730
  }
71386
71731
  );
71387
71732
  }
@@ -71583,6 +71928,8 @@ const MDEditor = forwardRef(
71583
71928
  const [aiPanelOpen, setAIPanelOpen] = useState(mergedAIConfig.alwaysShowPanel ?? false);
71584
71929
  const [aiRefineContext, setAIRefineContext] = useState(null);
71585
71930
  const variableTriggerPosRef = useRef(null);
71931
+ const [isRawMode, setIsRawMode] = useState(false);
71932
+ const [rawMarkdown, setRawMarkdown] = useState("");
71586
71933
  const defaultCategories = useMemo(() => {
71587
71934
  const categories = [];
71588
71935
  if (agents2.length > 0) {
@@ -71710,12 +72057,20 @@ const MDEditor = forwardRef(
71710
72057
  let originalText;
71711
72058
  let selectionRange;
71712
72059
  if (actualType === "selection" && hasSelection2) {
71713
- originalText = editor2.state.doc.textBetween(from2, to);
72060
+ const selectedSlice = editor2.state.doc.slice(from2, to);
72061
+ const selectedContent = { content: selectedSlice.content.toJSON() };
72062
+ originalText = editorJsonToMarkdown(selectedContent);
72063
+ if (!originalText || originalText.trim() === "") {
72064
+ originalText = editor2.state.doc.textBetween(from2, to, "\n");
72065
+ }
71714
72066
  selectionRange = { from: from2, to };
71715
72067
  } else {
71716
- originalText = editor2.getText();
72068
+ originalText = editorJsonToMarkdown(editor2.getJSON());
72069
+ if (!originalText || originalText.trim() === "") {
72070
+ originalText = editor2.getText();
72071
+ }
71717
72072
  }
71718
- const fullContent = editor2.getText();
72073
+ const fullContent = editorJsonToMarkdown(editor2.getJSON());
71719
72074
  setAIRefineContext({
71720
72075
  type: actualType,
71721
72076
  originalText,
@@ -71738,6 +72093,22 @@ const MDEditor = forwardRef(
71738
72093
  setAIPanelOpen(false);
71739
72094
  setAIRefineContext(null);
71740
72095
  }, [mergedAIConfig.alwaysShowPanel]);
72096
+ const toggleRawMode = useCallback(() => {
72097
+ if (!editorRef.current) return;
72098
+ if (isRawMode) {
72099
+ const parsedContent = markdownToEditorJson(rawMarkdown);
72100
+ editorRef.current.commands.setContent(parsedContent);
72101
+ lastEmittedMarkdownRef.current = rawMarkdown;
72102
+ } else {
72103
+ const json = editorRef.current.getJSON();
72104
+ const markdown = editorJsonToMarkdown(json);
72105
+ setRawMarkdown(markdown);
72106
+ }
72107
+ setIsRawMode(!isRawMode);
72108
+ }, [isRawMode, rawMarkdown]);
72109
+ const handleRawMarkdownChange = useCallback((newValue) => {
72110
+ setRawMarkdown(newValue);
72111
+ }, []);
71741
72112
  const handleAIRefineTrigger = useCallback(
71742
72113
  (type) => {
71743
72114
  openAIRefine(type);
@@ -71854,6 +72225,16 @@ const MDEditor = forwardRef(
71854
72225
  })
71855
72226
  );
71856
72227
  }
72228
+ if (mergedFeatures.mentions && (agents2.length > 0 || tools2.length > 0 || knowledge2.length > 0)) {
72229
+ exts.push(
72230
+ MentionCommandExtension.configure({
72231
+ agents: agents2,
72232
+ tools: tools2,
72233
+ knowledge: knowledge2,
72234
+ onSelectItem: handleSlashCommandSelect
72235
+ })
72236
+ );
72237
+ }
71857
72238
  if (mergedAIConfig.enabled && onAIRefine) {
71858
72239
  exts.push(
71859
72240
  AIRefineExtension.configure({
@@ -71956,6 +72337,28 @@ const MDEditor = forwardRef(
71956
72337
  });
71957
72338
  }
71958
72339
  }, [editor, mergedAIConfig.alwaysShowPanel, mergedAIConfig.enabled, onAIRefine, aiRefineContext]);
72340
+ useEffect(() => {
72341
+ if (!isRawMode) return;
72342
+ const timer = setTimeout(() => {
72343
+ if (rawMarkdown !== lastEmittedMarkdownRef.current) {
72344
+ lastEmittedMarkdownRef.current = rawMarkdown;
72345
+ if (onMarkdownChange) {
72346
+ onMarkdownChange(rawMarkdown);
72347
+ }
72348
+ if (onChange) {
72349
+ const parsedContent = markdownToEditorJson(rawMarkdown);
72350
+ const doc2 = editorJsonToDocument(parsedContent);
72351
+ onChange(doc2, rawMarkdown);
72352
+ }
72353
+ }
72354
+ }, 300);
72355
+ return () => clearTimeout(timer);
72356
+ }, [rawMarkdown, isRawMode, onMarkdownChange, onChange]);
72357
+ useEffect(() => {
72358
+ if (isRawMode && markdownValue !== void 0 && markdownValue !== lastEmittedMarkdownRef.current) {
72359
+ setRawMarkdown(markdownValue);
72360
+ }
72361
+ }, [markdownValue, isRawMode]);
71959
72362
  useImperativeHandle(
71960
72363
  ref,
71961
72364
  () => ({
@@ -72002,9 +72405,12 @@ const MDEditor = forwardRef(
72002
72405
  },
72003
72406
  // AI Refinement methods
72004
72407
  openAIRefine: (type) => openAIRefine(type),
72005
- closeAIRefine
72408
+ closeAIRefine,
72409
+ // Raw mode methods
72410
+ toggleRawMode,
72411
+ isRawMode: () => isRawMode
72006
72412
  }),
72007
- [editor, insertVariable, insertMention, openAIRefine, closeAIRefine]
72413
+ [editor, insertVariable, insertMention, openAIRefine, closeAIRefine, toggleRawMode, isRawMode]
72008
72414
  );
72009
72415
  if (!editor) {
72010
72416
  return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `k-md-editor k-md-editor--${theme} flex items-center justify-center min-h-[200px] ${className}`, "data-id": "md-editor-loading", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "w-full h-full min-h-[200px] rounded bg-gradient-to-r from-gray-200 via-gray-100 to-gray-200 dark:from-gray-700 dark:via-gray-600 dark:to-gray-700 bg-[length:200%_100%] animate-pulse" }) });
@@ -72112,16 +72518,51 @@ const MDEditor = forwardRef(
72112
72518
  children: /* @__PURE__ */ jsxRuntimeExports.jsx(TableToolbar, { editor, theme })
72113
72519
  }
72114
72520
  ),
72115
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "k-md-editor__wrapper relative w-full h-full", children: [
72116
- mergedFeatures.dragDrop && !readOnly && /* @__PURE__ */ jsxRuntimeExports.jsx(DragHandle, { editor }),
72521
+ !readOnly && /* @__PURE__ */ jsxRuntimeExports.jsx(
72522
+ "button",
72523
+ {
72524
+ onClick: toggleRawMode,
72525
+ className: "absolute top-2 right-2 p-1.5 rounded-md z-10 transition-all duration-200\n bg-white/80 dark:bg-gray-800/80 backdrop-blur-sm\n border border-gray-200 dark:border-gray-700\n hover:bg-gray-100 dark:hover:bg-gray-700\n hover:border-gray-300 dark:hover:border-gray-600\n text-gray-600 dark:text-gray-400\n hover:text-gray-900 dark:hover:text-gray-100\n shadow-sm hover:shadow",
72526
+ title: isRawMode ? "Switch to rich editor" : "Switch to raw markdown",
72527
+ "data-id": "md-editor-raw-toggle",
72528
+ children: isRawMode ? (
72529
+ // Eye icon (switch to rich/preview mode)
72530
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("svg", { className: "w-4 h-4", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", strokeWidth: 2, children: [
72531
+ /* @__PURE__ */ jsxRuntimeExports.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M15 12a3 3 0 11-6 0 3 3 0 016 0z" }),
72532
+ /* @__PURE__ */ jsxRuntimeExports.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z" })
72533
+ ] })
72534
+ ) : (
72535
+ // Code icon (switch to raw markdown)
72536
+ /* @__PURE__ */ jsxRuntimeExports.jsx("svg", { className: "w-4 h-4", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", strokeWidth: 2, children: /* @__PURE__ */ jsxRuntimeExports.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4" }) })
72537
+ )
72538
+ }
72539
+ ),
72540
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "k-md-editor__wrapper relative w-full h-full", children: isRawMode ? (
72541
+ // Raw Markdown Textarea
72117
72542
  /* @__PURE__ */ jsxRuntimeExports.jsx(
72118
- EditorContent,
72543
+ "textarea",
72119
72544
  {
72120
- editor,
72121
- className: "k-md-editor__content w-full h-full overflow-y-auto"
72545
+ value: rawMarkdown,
72546
+ onChange: (e3) => handleRawMarkdownChange(e3.target.value),
72547
+ className: "k-md-editor__raw-textarea w-full h-full min-h-[200px] p-4 pr-12\n font-mono text-sm leading-relaxed resize-none\n bg-gray-50 dark:bg-gray-900\n text-gray-900 dark:text-gray-100\n border-0 focus:outline-none focus:ring-0\n placeholder:text-gray-400 dark:placeholder:text-gray-600",
72548
+ placeholder: "Write your markdown here...\n\n# Heading\n## Subheading\n- Bullet point\n1. Numbered list\n**bold** _italic_ `code`",
72549
+ "data-id": "md-editor-raw-textarea",
72550
+ spellCheck: false
72122
72551
  }
72123
72552
  )
72124
- ] }),
72553
+ ) : (
72554
+ // Rich Editor
72555
+ /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
72556
+ mergedFeatures.dragDrop && !readOnly && /* @__PURE__ */ jsxRuntimeExports.jsx(DragHandle, { editor }),
72557
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
72558
+ EditorContent,
72559
+ {
72560
+ editor,
72561
+ className: "k-md-editor__content w-full h-full overflow-y-auto"
72562
+ }
72563
+ )
72564
+ ] })
72565
+ ) }),
72125
72566
  variableMenuOpen && /* @__PURE__ */ jsxRuntimeExports.jsx(
72126
72567
  VariableMenu,
72127
72568
  {
@@ -72165,7 +72606,10 @@ const MDEditor = forwardRef(
72165
72606
  envVariables: envVariables2,
72166
72607
  memoryVariables,
72167
72608
  systemVariables: systemVariables2,
72168
- contentVariables
72609
+ contentVariables,
72610
+ agents: agents2,
72611
+ tools: tools2,
72612
+ knowledge: knowledge2
72169
72613
  }
72170
72614
  )
72171
72615
  ]