@superinterface/react 2.22.3 → 2.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -391,6 +391,9 @@ __export(src_exports, {
391
391
  AssistantNameContext: function() {
392
392
  return AssistantNameContext;
393
393
  },
394
+ AssistantProvider: function() {
395
+ return AssistantProvider;
396
+ },
394
397
  AudioThread: function() {
395
398
  return AudioThread;
396
399
  },
@@ -1618,136 +1621,152 @@ var remarkAnnotation = function(param) {
1618
1621
  return function() {
1619
1622
  return function(tree) {
1620
1623
  (0, import_unist_util_flatmap.default)(tree, function(node) {
1621
- var _content_text_annotations, _content_text;
1622
- if (![
1623
- "text",
1624
- "link"
1625
- ].includes(node.type)) {
1626
- return [
1627
- node
1628
- ];
1629
- }
1630
- if (!((_content_text = content.text) === null || _content_text === void 0 ? void 0 : (_content_text_annotations = _content_text.annotations) === null || _content_text_annotations === void 0 ? void 0 : _content_text_annotations.length)) {
1631
- return [
1632
- node
1633
- ];
1634
- }
1635
- if (!node.position) {
1636
- return [
1637
- node
1638
- ];
1639
- }
1640
- var nodeStart = node.position.start.offset;
1641
- if (!(0, import_radash3.isNumber)(nodeStart)) {
1642
- return [
1643
- node
1644
- ];
1645
- }
1646
- var nodeEnd = node.position.end.offset;
1647
- if (!(0, import_radash3.isNumber)(nodeEnd)) {
1624
+ if (node.type === "text" || node.type === "link") {
1625
+ return processNodeWithAnnotations({
1626
+ node: node,
1627
+ content: content
1628
+ });
1629
+ } else {
1648
1630
  return [
1649
1631
  node
1650
1632
  ];
1651
1633
  }
1652
- var newNodes = [];
1653
- var lastProcessedIndex = nodeStart;
1654
- sortedAnnotations({
1655
- content: content
1656
- }).forEach(function(annotation) {
1657
- var annotationStart = annotation.start_index;
1658
- var annotationEnd = annotation.end_index;
1659
- if (nodeEnd < annotationStart || nodeStart > annotationEnd) {
1660
- return;
1661
- }
1662
- if (node.type === "link") {
1663
- if (annotation.type === "file_path") {
1664
- console.log({
1665
- annotation: annotation,
1666
- node: node
1667
- });
1668
- newNodes.push(_object_spread_props(_object_spread({}, node), {
1669
- type: "annotation",
1670
- // @ts-ignore-next-line
1671
- url: annotation.file_path.file_id,
1672
- data: {
1673
- hName: "annotation",
1674
- hProperties: {
1675
- annotation: annotation
1676
- }
1677
- }
1678
- }));
1679
- }
1680
- return;
1681
- }
1682
- var startIndex = Math.max(nodeStart, annotationStart);
1683
- var endIndex = Math.min(nodeEnd, annotationEnd);
1684
- if (lastProcessedIndex < startIndex) {
1685
- newNodes.push({
1686
- type: "text",
1687
- value: node.value.slice(lastProcessedIndex - nodeStart, startIndex - nodeStart),
1688
- position: {
1689
- start: {
1690
- line: node.position.start.line,
1691
- column: node.position.start.column,
1692
- offset: lastProcessedIndex
1693
- },
1694
- end: {
1695
- line: node.position.end.line,
1696
- column: node.position.end.column,
1697
- offset: startIndex
1698
- }
1699
- }
1700
- });
1701
- }
1702
- newNodes.push({
1703
- type: "annotation",
1704
- value: node.value.slice(startIndex - nodeStart, endIndex - nodeStart),
1705
- position: {
1706
- start: {
1707
- line: node.position.start.line,
1708
- column: node.position.start.column,
1709
- offset: startIndex
1710
- },
1711
- end: {
1712
- line: node.position.end.line,
1713
- column: node.position.end.column,
1714
- offset: endIndex
1715
- }
1716
- },
1717
- data: {
1718
- hName: "annotation",
1719
- hProperties: {
1720
- annotation: annotation
1721
- }
1722
- }
1723
- });
1724
- lastProcessedIndex = endIndex;
1725
- });
1726
- if (node.type === "text") {
1727
- if (lastProcessedIndex < nodeEnd) {
1728
- newNodes.push({
1729
- type: "text",
1730
- value: node.value.slice(lastProcessedIndex - nodeStart, nodeEnd - nodeStart),
1731
- position: {
1732
- start: {
1733
- line: node.position.start.line,
1734
- column: node.position.start.column,
1735
- offset: lastProcessedIndex
1736
- },
1737
- end: {
1738
- line: node.position.end.line,
1739
- column: node.position.end.column,
1740
- offset: nodeEnd
1741
- }
1742
- }
1743
- });
1744
- }
1745
- }
1746
- return newNodes;
1747
1634
  });
1748
1635
  };
1749
1636
  };
1750
1637
  };
1638
+ var processNodeWithAnnotations = function(param) {
1639
+ var node = param.node, content = param.content;
1640
+ var _content_text_annotations, _content_text;
1641
+ if (!((_content_text = content.text) === null || _content_text === void 0 ? void 0 : (_content_text_annotations = _content_text.annotations) === null || _content_text_annotations === void 0 ? void 0 : _content_text_annotations.length)) {
1642
+ return [
1643
+ node
1644
+ ];
1645
+ }
1646
+ if (!node.position) {
1647
+ return [
1648
+ node
1649
+ ];
1650
+ }
1651
+ var annotations = sortedAnnotations({
1652
+ content: content
1653
+ });
1654
+ if (node.type === "text") {
1655
+ return processTextNode({
1656
+ node: node,
1657
+ annotations: annotations
1658
+ });
1659
+ } else if (node.type === "link") {
1660
+ var linkNode = node;
1661
+ linkNode.children = (0, import_unist_util_flatmap.default)(linkNode.children, function(childNode) {
1662
+ if (childNode.type === "text") {
1663
+ return processTextNode({
1664
+ node: childNode,
1665
+ annotations: annotations
1666
+ });
1667
+ } else {
1668
+ return [
1669
+ childNode
1670
+ ];
1671
+ }
1672
+ });
1673
+ return [
1674
+ linkNode
1675
+ ];
1676
+ } else {
1677
+ return [
1678
+ node
1679
+ ];
1680
+ }
1681
+ };
1682
+ var processTextNode = function(param) {
1683
+ var node = param.node, annotations = param.annotations;
1684
+ if (!node.position || !node.value) {
1685
+ return [
1686
+ node
1687
+ ];
1688
+ }
1689
+ var nodeStart = node.position.start.offset;
1690
+ var nodeEnd = node.position.end.offset;
1691
+ if (!(0, import_radash3.isNumber)(nodeStart) || !(0, import_radash3.isNumber)(nodeEnd)) {
1692
+ return [
1693
+ node
1694
+ ];
1695
+ }
1696
+ var newNodes = [];
1697
+ var lastIndex = nodeStart;
1698
+ annotations.forEach(function(annotation) {
1699
+ var annotationStart = annotation.start_index;
1700
+ var annotationEnd = annotation.end_index;
1701
+ if (nodeEnd <= annotationStart || nodeStart >= annotationEnd) {
1702
+ return;
1703
+ }
1704
+ var start = Math.max(nodeStart, annotationStart);
1705
+ var end = Math.min(nodeEnd, annotationEnd);
1706
+ if (lastIndex < start) {
1707
+ newNodes.push(createTextNode({
1708
+ node: node,
1709
+ startOffset: lastIndex,
1710
+ endOffset: start
1711
+ }));
1712
+ }
1713
+ newNodes.push(createAnnotationNode({
1714
+ node: node,
1715
+ startOffset: start,
1716
+ endOffset: end,
1717
+ annotation: annotation
1718
+ }));
1719
+ lastIndex = end;
1720
+ });
1721
+ if (lastIndex < nodeEnd) {
1722
+ newNodes.push(createTextNode({
1723
+ node: node,
1724
+ startOffset: lastIndex,
1725
+ endOffset: nodeEnd
1726
+ }));
1727
+ }
1728
+ return newNodes;
1729
+ };
1730
+ var createTextNode = function(param) {
1731
+ var node = param.node, startOffset = param.startOffset, endOffset = param.endOffset;
1732
+ var valueStart = startOffset - node.position.start.offset;
1733
+ var valueEnd = endOffset - node.position.start.offset;
1734
+ return {
1735
+ type: "text",
1736
+ value: node.value.slice(valueStart, valueEnd),
1737
+ position: {
1738
+ start: _object_spread_props(_object_spread({}, node.position.start), {
1739
+ offset: startOffset
1740
+ }),
1741
+ end: _object_spread_props(_object_spread({}, node.position.end), {
1742
+ offset: endOffset
1743
+ })
1744
+ }
1745
+ };
1746
+ };
1747
+ var createAnnotationNode = function(param) {
1748
+ var node = param.node, startOffset = param.startOffset, endOffset = param.endOffset, annotation = param.annotation;
1749
+ var valueStart = startOffset - node.position.start.offset;
1750
+ var valueEnd = endOffset - node.position.start.offset;
1751
+ return {
1752
+ type: "annotation",
1753
+ value: node.value.slice(valueStart, valueEnd),
1754
+ position: {
1755
+ start: _object_spread_props(_object_spread({}, node.position.start), {
1756
+ offset: startOffset
1757
+ }),
1758
+ end: _object_spread_props(_object_spread({}, node.position.end), {
1759
+ offset: endOffset
1760
+ })
1761
+ },
1762
+ data: {
1763
+ hName: "annotation",
1764
+ hProperties: {
1765
+ annotation: annotation
1766
+ }
1767
+ }
1768
+ };
1769
+ };
1751
1770
  // src/contexts/markdown/MarkdownContext/lib/getRemarkPlugins.ts
1752
1771
  var getRemarkPlugins = function(param) {
1753
1772
  var content = param.content;
@@ -5316,10 +5335,82 @@ var ComponentsProvider = function(_param) {
5316
5335
  children: children
5317
5336
  });
5318
5337
  };
5338
+ // src/components/assistants/AssistantProvider/index.tsx
5339
+ var import_react61 = require("react");
5340
+ var import_themes59 = require("@radix-ui/themes");
5341
+ // src/components/assistants/AssistantProvider/Code.tsx
5342
+ var import_react60 = require("react");
5343
+ var import_jsx_runtime87 = require("react/jsx-runtime");
5344
+ var Code4 = function(param) {
5345
+ var children = param.children, className = param.className, markdownContext = param.markdownContext;
5346
+ var messageContext = useMessageContext();
5347
+ var isAssistantMessage = (0, import_react60.useMemo)(function() {
5348
+ var _messageContext_message;
5349
+ return ((_messageContext_message = messageContext.message) === null || _messageContext_message === void 0 ? void 0 : _messageContext_message.role) === "assistant";
5350
+ }, [
5351
+ messageContext
5352
+ ]);
5353
+ if (!isAssistantMessage || className !== "language-suggestions") {
5354
+ return markdownContext.components.code({
5355
+ children: children,
5356
+ className: className
5357
+ });
5358
+ }
5359
+ return /* @__PURE__ */ (0, import_jsx_runtime87.jsx)(Suggestions, {
5360
+ children: children
5361
+ });
5362
+ };
5363
+ // src/components/assistants/AssistantProvider/index.tsx
5364
+ var import_jsx_runtime88 = // @ts-ignore-next-line
5365
+ require("react/jsx-runtime");
5366
+ var AssistantProvider = function(param) {
5367
+ var children = param.children;
5368
+ var superinterfaceContext = useSuperinterfaceContext();
5369
+ var assistant = useAssistant({
5370
+ assistantId: superinterfaceContext.variables.assistantId
5371
+ }).assistant;
5372
+ var markdownContext = useMarkdownContext();
5373
+ var components2 = (0, import_react61.useMemo)(function() {
5374
+ return {
5375
+ code: function(props) {
5376
+ return /* @__PURE__ */ (0, import_jsx_runtime88.jsx)(Code4, _object_spread_props(_object_spread({}, props), {
5377
+ markdownContext: markdownContext
5378
+ }));
5379
+ }
5380
+ };
5381
+ }, [
5382
+ markdownContext
5383
+ ]);
5384
+ if (!assistant) {
5385
+ return null;
5386
+ }
5387
+ return /* @__PURE__ */ (0, import_jsx_runtime88.jsx)(import_themes59.Theme, {
5388
+ accentColor: assistant.theme.accentColor,
5389
+ grayColor: assistant.theme.grayColor,
5390
+ radius: assistant.theme.radius,
5391
+ appearance: assistant.theme.appearance,
5392
+ scaling: assistant.theme.scaling,
5393
+ panelBackground: "solid",
5394
+ hasBackground: false,
5395
+ children: /* @__PURE__ */ (0, import_jsx_runtime88.jsx)(AssistantNameContext.Provider, {
5396
+ value: assistant.name,
5397
+ children: /* @__PURE__ */ (0, import_jsx_runtime88.jsx)(AssistantAvatarContext.Provider, {
5398
+ value: /* @__PURE__ */ (0, import_jsx_runtime88.jsx)(Avatar6, {
5399
+ avatar: assistant.avatar
5400
+ }),
5401
+ children: /* @__PURE__ */ (0, import_jsx_runtime88.jsx)(MarkdownProvider, {
5402
+ components: components2,
5403
+ children: children
5404
+ })
5405
+ })
5406
+ })
5407
+ });
5408
+ };
5319
5409
  // Annotate the CommonJS export names for ESM import in node:
5320
5410
  0 && (module.exports = {
5321
5411
  AssistantAvatarContext: AssistantAvatarContext,
5322
5412
  AssistantNameContext: AssistantNameContext,
5413
+ AssistantProvider: AssistantProvider,
5323
5414
  AudioThread: AudioThread,
5324
5415
  AudioThreadDialog: AudioThreadDialog,
5325
5416
  Avatar: Avatar,