@trops/dash-core 0.1.709 → 0.1.710

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
@@ -79254,6 +79254,41 @@ function renderSafeMarkdown(text) {
79254
79254
  });
79255
79255
  }
79256
79256
 
79257
+ /**
79258
+ * collapseCodeBlocks — for ChatCore's `hideCodeBlocks` option.
79259
+ *
79260
+ * Replaces each fenced code block (and the `File: path` marker line that
79261
+ * labels it) with a one-line italic note, so a chat whose code is shown
79262
+ * elsewhere (the Widget Builder's Code tab) stays readable. Back-to-back
79263
+ * blocks share one note. A block that is still streaming (no closing
79264
+ * fence yet) becomes "Writing code…". Inline `code` is untouched.
79265
+ *
79266
+ * @param {string} text assistant Markdown
79267
+ * @param {string} note what a hidden block says
79268
+ * @param {{ plain?: boolean }} [opts] plain: no Markdown italics (for the
79269
+ * streaming view, which shows raw text)
79270
+ * @returns {string}
79271
+ */
79272
+ function collapseCodeBlocks(text, note) {
79273
+ var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
79274
+ _ref$plain = _ref.plain,
79275
+ plain = _ref$plain === void 0 ? false : _ref$plain;
79276
+ if (!text || typeof text !== "string" || !text.includes("```")) return text;
79277
+ var wrap = function wrap(t) {
79278
+ return plain ? t : "_".concat(t, "_");
79279
+ };
79280
+ var marker = wrap(note);
79281
+ var out = text
79282
+ // Complete blocks, with an optional "File: …" line just above.
79283
+ .replace(/(^|\n)(?:[ \t]*File:[^\n]*\n)?[ \t]*```[^\n]*\n[\s\S]*?\n[ \t]*```[ \t]*(?=\n|$)/g, "$1".concat(marker))
79284
+ // A block still being written: open fence with no close.
79285
+ .replace(/(^|\n)(?:[ \t]*File:[^\n]*\n)?[ \t]*```[^\n]*(?:\n[\s\S]*)?$/, "$1".concat(wrap("Writing code…")));
79286
+ // One note for back-to-back blocks.
79287
+ var escaped = marker.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
79288
+ out = out.replace(new RegExp("".concat(escaped, "(\\s*").concat(escaped, ")+"), "g"), marker);
79289
+ return out;
79290
+ }
79291
+
79257
79292
  function ownKeys$6(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
79258
79293
  function _objectSpread$6(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$6(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$6(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
79259
79294
  function _createForOfIteratorHelper$5(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray$5(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
@@ -79278,7 +79313,9 @@ var MessageBubble = function MessageBubble(_ref2) {
79278
79313
  isStreaming = _ref2.isStreaming,
79279
79314
  streamingText = _ref2.streamingText,
79280
79315
  _ref2$isLast = _ref2.isLast,
79281
- isLast = _ref2$isLast === void 0 ? false : _ref2$isLast;
79316
+ isLast = _ref2$isLast === void 0 ? false : _ref2$isLast,
79317
+ _ref2$codeNote = _ref2.codeNote,
79318
+ codeNote = _ref2$codeNote === void 0 ? null : _ref2$codeNote;
79282
79319
  var role = message.role,
79283
79320
  content = message.content,
79284
79321
  toolCalls = message.toolCalls,
@@ -79416,11 +79453,13 @@ var MessageBubble = function MessageBubble(_ref2) {
79416
79453
  className: "text-sm leading-relaxed px-3 py-2 rounded-lg ".concat(bubbleBg, " ").concat(bubbleText),
79417
79454
  children: [isStreaming && /*#__PURE__*/jsxRuntime.jsx("div", {
79418
79455
  children: /*#__PURE__*/jsxRuntime.jsx(StreamingText, {
79419
- text: streamingText,
79456
+ text: codeNote ? collapseCodeBlocks(streamingText, codeNote, {
79457
+ plain: true
79458
+ }) : streamingText,
79420
79459
  isStreaming: true
79421
79460
  })
79422
79461
  }), !isStreaming && _text && /*#__PURE__*/jsxRuntime.jsx(AssistantTextContent, {
79423
- text: _text
79462
+ text: codeNote ? collapseCodeBlocks(_text, codeNote) : _text
79424
79463
  }), toolBlocks.map(function (block) {
79425
79464
  return /*#__PURE__*/jsxRuntime.jsx(ToolCallBlock, {
79426
79465
  toolName: block.name,
@@ -79481,7 +79520,9 @@ var ChatMessages = function ChatMessages(_ref) {
79481
79520
  streamingRequestId = _ref.streamingRequestId,
79482
79521
  streamingText = _ref.streamingText,
79483
79522
  _ref$isLoading = _ref.isLoading,
79484
- isLoading = _ref$isLoading === void 0 ? false : _ref$isLoading;
79523
+ isLoading = _ref$isLoading === void 0 ? false : _ref$isLoading,
79524
+ _ref$codeNote = _ref.codeNote,
79525
+ codeNote = _ref$codeNote === void 0 ? null : _ref$codeNote;
79485
79526
  var scrollRef = React.useRef(null);
79486
79527
  var _ref2 = React.useContext(DashReact.ThemeContext) || {},
79487
79528
  currentTheme = _ref2.currentTheme;
@@ -79519,7 +79560,8 @@ var ChatMessages = function ChatMessages(_ref) {
79519
79560
  message: message,
79520
79561
  isStreaming: isStreaming,
79521
79562
  streamingText: isStreaming ? streamingText : "",
79522
- isLast: index === messages.length - 1
79563
+ isLast: index === messages.length - 1,
79564
+ codeNote: codeNote
79523
79565
  }, message.id || index);
79524
79566
  }), isLoading && !streamingRequestId && ((_messages = messages[messages.length - 1]) === null || _messages === void 0 ? void 0 : _messages.role) === "user" && /*#__PURE__*/jsxRuntime.jsxs("div", {
79525
79567
  className: "mb-4",
@@ -79974,6 +80016,8 @@ function ChatCore(_ref) {
79974
80016
  onPublishEvent = _ref$onPublishEvent === void 0 ? null : _ref$onPublishEvent,
79975
80017
  _ref$hideToolsBanner = _ref.hideToolsBanner,
79976
80018
  hideToolsBanner = _ref$hideToolsBanner === void 0 ? false : _ref$hideToolsBanner,
80019
+ _ref$hideCodeBlocks = _ref.hideCodeBlocks,
80020
+ hideCodeBlocks = _ref$hideCodeBlocks === void 0 ? false : _ref$hideCodeBlocks,
79977
80021
  _ref$cwd = _ref.cwd,
79978
80022
  cwd = _ref$cwd === void 0 ? null : _ref$cwd,
79979
80023
  _ref$initialMessage = _ref.initialMessage,
@@ -80771,7 +80815,8 @@ function ChatCore(_ref) {
80771
80815
  messages: messages,
80772
80816
  streamingRequestId: isLoading ? activeRequestId.current : null,
80773
80817
  streamingText: streamingText,
80774
- isLoading: isLoading
80818
+ isLoading: isLoading,
80819
+ codeNote: typeof hideCodeBlocks === "string" ? hideCodeBlocks : hideCodeBlocks ? "Code hidden." : null
80775
80820
  }), enableLeadRecipients && leadNotice && /*#__PURE__*/jsxRuntime.jsx("div", {
80776
80821
  className: "px-3 pt-2",
80777
80822
  children: /*#__PURE__*/jsxRuntime.jsx(DashReact.AlertBanner, {